diff --git a/.mailmap b/.mailmap index 0d05be949eff9a..bb8cd0c847479d 100644 --- a/.mailmap +++ b/.mailmap @@ -233,6 +233,10 @@ Chuck Lever Chuck Lever Chuck Lever Claudiu Beznea +Clément Léger +Clément Léger +Clément Léger +Clément Léger Coiby Xu Colin Ian King Corey Minyard @@ -361,6 +365,9 @@ Guru Das Srinagesh Gustavo Padovan Gustavo Padovan Hamza Mahfooz +Hangbin Liu +Hangbin Liu +Hangbin Liu Hanjun Guo Hans de Goede Hans Verkuil @@ -520,10 +527,12 @@ Kiran Gunda Kirill Tkhai Kiryl Shutsemau Kishon Vijay Abraham I +Koby Elbaz Konrad Dybcio Konrad Dybcio Konstantin Khlebnikov Konstantin Khlebnikov +Konstantin Sinyuk Koushik Krishna Manikandan Krzysztof Kozlowski diff --git a/Documentation/admin-guide/LSM/landlock.rst b/Documentation/admin-guide/LSM/landlock.rst index 718e0d23ffb501..946f3bf8965003 100644 --- a/Documentation/admin-guide/LSM/landlock.rst +++ b/Documentation/admin-guide/LSM/landlock.rst @@ -73,8 +73,9 @@ AUDIT_LANDLOCK_ACCESS :manpage:`open_tree(2)`, or :manpage:`fsmount(2)`, or joining via :manpage:`setns(2)`); ``namespace_type`` indicates the type (hex ``CLONE_NEW*`` bitmask), - and ``namespace_id`` identifies the target namespace for - :manpage:`setns(2)` operations (zero for creation) + and ``namespace_id`` identifies the target namespace (for a denied + creation, the namespace never becomes reachable so its ID is not + directly visible from user space) **capability.*** - Capability restrictions (ABI 12+): - capability.use - Capability use was denied; diff --git a/Documentation/arch/arm64/gcs.rst b/Documentation/arch/arm64/gcs.rst index 226c0b008456f2..1e0424f915dce7 100644 --- a/Documentation/arch/arm64/gcs.rst +++ b/Documentation/arch/arm64/gcs.rst @@ -179,9 +179,8 @@ intended to be exhaustive. When returning from a signal handler: -* If there is a gcs_context record in the signal frame then the GCS flags - and GCSPR_EL0 will be restored from that context prior to further - validation. +* If there is a gcs_context record in the signal frame then GCSPR_EL0 + will be restored from that context prior to further validation. * If there is no gcs_context record in the signal frame then the GCS configuration will be unchanged. @@ -190,12 +189,8 @@ When returning from a signal handler: point to a valid GCS signal cap record, this will be popped from the GCS prior to signal return. -* If the GCS configuration is locked when returning from a signal then any - attempt to change the GCS configuration will be treated as an error. This - is true even if GCS was not enabled prior to signal entry. - -* GCS may be disabled via signal return but any attempt to enable GCS via - signal return will be rejected. +* The features_enabled in the signal return context will be ignored; any + changes made using the prctl() in the signal handler will be preserved. 6. ptrace extensions diff --git a/Documentation/arch/arm64/silicon-errata.rst b/Documentation/arch/arm64/silicon-errata.rst index afe109afe69288..dc4144ac895bf9 100644 --- a/Documentation/arch/arm64/silicon-errata.rst +++ b/Documentation/arch/arm64/silicon-errata.rst @@ -171,10 +171,18 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A715 | #2645198 | ARM64_ERRATUM_2645198 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A715 | #2738462 | ARM64_ERRATUM_2738461 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A715 | #3456084 | ARM64_ERRATUM_3194386 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A720 | #2738461 | ARM64_ERRATUM_2738461 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A720 | #3456091 | ARM64_ERRATUM_3194386 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A720 | #4689339 | ARM64_ERRATUM_3821522 | ++----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A720AE | #4689340 | ARM64_ERRATUM_3821522 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A725 | #3456106 | ARM64_ERRATUM_3194386 | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A725 | #3821522 | ARM64_ERRATUM_3821522 | @@ -233,6 +241,8 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-N3 | #3456111 | ARM64_ERRATUM_3194386 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Neoverse-N3 | #4689341 | ARM64_ERRATUM_3821522 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-V1 | #1619801 | N/A | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-V1 | #3324341 | ARM64_ERRATUM_3194386 | @@ -257,6 +267,8 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | C1-Pro | #4193714 | ARM64_ERRATUM_4193714 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | C1-Pro | #4689344 | ARM64_ERRATUM_3821522 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | C1-Ultra | #3683289 | N/A | +----------------+-----------------+-----------------+-----------------------------+ | ARM | C1-Ultra | #4193780 | ARM64_ERRATUM_4118414 | diff --git a/Documentation/bpf/bpf_devel_QA.rst b/Documentation/bpf/bpf_devel_QA.rst index 4729efd657c339..888b29599761a3 100644 --- a/Documentation/bpf/bpf_devel_QA.rst +++ b/Documentation/bpf/bpf_devel_QA.rst @@ -304,31 +304,13 @@ downstream distributions. Q: Do you accept patches as well for iproute2's BPF loader? ----------------------------------------------------------- -A: Patches for the iproute2's BPF loader have to be sent to: +A: Patches for iproute2, including its BPF loader, are sent to +netdev@vger.kernel.org. For details on iproute2 patch submission, see +"Co-posting iproute2 patches" in Documentation/process/maintainer-netdev.rst. - netdev@vger.kernel.org - -While those patches are not processed by the BPF kernel maintainers, -please keep them in Cc as well, so they can be reviewed. - -The official git repository for iproute2 is run by Stephen Hemminger -and can be found at: - - https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/ - -The patches need to have a subject prefix of '``[PATCH iproute2 -master]``' or '``[PATCH iproute2 net-next]``'. '``master``' or -'``net-next``' describes the target branch where the patch should be -applied to. Meaning, if kernel changes went into the net-next kernel -tree, then the related iproute2 changes need to go into the iproute2 -net-next branch, otherwise they can be targeted at master branch. The -iproute2 net-next branch will get merged into the master branch after -the current iproute2 version from master has been released. - -Like BPF, the patches end up in patchwork under the netdev project and -are delegated to 'shemminger' for further processing: - - http://patchwork.ozlabs.org/project/netdev/list/?delegate=389 +While iproute2 BPF loader patches are not processed by the BPF kernel +maintainers, please Cc bpf@vger.kernel.org and the BPF maintainers for +review. Q: What is the minimum requirement before I submit my BPF patches? ------------------------------------------------------------------ diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst index 73578a4c3b1fbc..901c3750421776 100644 --- a/Documentation/bpf/kfuncs.rst +++ b/Documentation/bpf/kfuncs.rst @@ -407,6 +407,13 @@ referenced kptr (by invoking bpf_kptr_xchg). If not, the verifier fails the loading of the BPF program until no lingering references remain in all possible explored states of the program. +A pointer to a struct in the arguments of a KF_ACQUIRE kfunc accepts only an +object of that type. The same applies to the argument that a KF_RELEASE kfunc +releases. For other arguments a kfunc also accepts memory of the program, if the +struct has only scalar members. A struct without members, struct __sk_buff and +struct xdp_md never accept memory. A KF_ACQUIRE kfunc which wants such memory +has to pair the pointer with a __sz argument. + 2.5.2 KF_RET_NULL flag ---------------------- diff --git a/Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml b/Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml new file mode 100644 index 00000000000000..8b39089c99a9de --- /dev/null +++ b/Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dsp/asus,tf201-dsp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Fortemedia FM34NE based voice processor + +description: + Fortemedia FM34NE is a hardware voice processor (DSP — Digital Signal + Processor) designed by Fortemedia. It specializes in real-time audio + processing, focusing on noise suppression and echo cancellation. + +maintainers: + - Svyatoslav Ryhel + +properties: + compatible: + enum: + - asus,sl101-dsp + - asus,tf101-dsp + - asus,tf201-dsp + - asus,tf300t-dsp + - asus,tf700t-dsp + - pegatron,chagall-dsp + + reg: + maxItems: 1 + + clocks: + items: + - description: Master clock to the DSP + + reset-gpios: + maxItems: 1 + + bypass-gpios: + maxItems: 1 + description: Signal that switches DSP into programming mode. + + vdd-supply: true + + port: + $ref: /schemas/sound/audio-graph-port.yaml# + unevaluatedProperties: false + +required: + - compatible + - reg + - bypass-gpios + +unevaluatedProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + dsp@60 { + compatible = "asus,tf201-dsp"; + reg = <0x60>; + + clocks = <&fm34ne_clk>; + + bypass-gpios = <&gpio 222 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio 115 GPIO_ACTIVE_LOW>; + + vdd-supply = <&vdd_1v8_dsp>; + }; + }; +... diff --git a/Documentation/devicetree/bindings/pwm/raspberrypi,rp1-pwm.yaml b/Documentation/devicetree/bindings/pwm/raspberrypi,rp1-pwm.yaml new file mode 100644 index 00000000000000..be020583fd0ba5 --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/raspberrypi,rp1-pwm.yaml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/raspberrypi,rp1-pwm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Raspberry Pi RP1 PWM controller + +maintainers: + - Naushir Patuck + - Andrea della Porta + - Stanimir Varbanov + +allOf: + - $ref: pwm.yaml# + +description: | + The PWM peripheral is a flexible waveform generator with a + variety of operational modes. It has the following features: + - four independent output channels + - 32-bit counter widths + - Seven output generation modes + - Optional per-channel output inversion + - Optional duty-cycle data FIFO with DMA support + - Optional sigma-delta noise shaping engine + Serves as a fan speed provider to other nodes for a PWM-connected + fan. + +properties: + compatible: + const: raspberrypi,rp1-pwm + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + "#pwm-cells": + const: 3 + + dmas: + maxItems: 1 + description: | + Phandle to the DMA controller and the channel specifier for + the duty-cycle FIFO. + + dma-names: + items: + - const: tx + +required: + - compatible + - reg + - clocks + +unevaluatedProperties: false + +examples: + - | + pwm@98000 { + compatible = "raspberrypi,rp1-pwm"; + reg = <0x98000 0x100>; + clocks = <&rp1_clocks 17>; + #pwm-cells = <3>; + }; diff --git a/Documentation/devicetree/bindings/regulator/fcs,fan53555.yaml b/Documentation/devicetree/bindings/regulator/fcs,fan53555.yaml index b35b8f365b0fcb..1bc22eb43dd965 100644 --- a/Documentation/devicetree/bindings/regulator/fcs,fan53555.yaml +++ b/Documentation/devicetree/bindings/regulator/fcs,fan53555.yaml @@ -20,6 +20,7 @@ properties: - fcs,fan53526 - rockchip,rk8600 - rockchip,rk8602 + - silergy,sym827 - silergy,syr827 - silergy,syr828 - tcs,tcs4525 diff --git a/Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml b/Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml index 80d9e87f147044..86d006559436d4 100644 --- a/Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml +++ b/Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml @@ -14,15 +14,25 @@ properties: const: airoha,an7581-afe reg: - maxItems: 1 + items: + - description: base AFE register + - description: secondary IRQ option register interrupts: maxItems: 1 + resets: + maxItems: 1 + + '#sound-dai-cells': + const: 0 + required: - compatible - reg - interrupts + - resets + - '#sound-dai-cells' additionalProperties: false @@ -30,12 +40,17 @@ examples: - | #include #include + #include afe@1fbe2200 { compatible = "airoha,an7581-afe"; - reg = <0x1fbe2200 0x9000>; + reg = <0x1fbe2200 0x100>, + <0x1fbe2f00 0x100>; interrupts = ; + resets = <&scuclk EN7581_I2S_RST>; + + #sound-dai-cells = <0>; }; ... diff --git a/Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml b/Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml new file mode 100644 index 00000000000000..4df4796623ed10 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/amlogic,gxbb-audin.yaml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/amlogic,gxbb-audin.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic GXBB AUDIN audio input controller + +maintainers: + - Valerio Setti + +description: + AUDIN is the audio input block of the Amlogic GXBB/GXL SoCs. It supports + various input formatters (I2S, SPDIF, PCM, HDMI) feeding three FIFOs that + transfer captured samples to memory. The sound-dai cell selects the FIFO. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + oneOf: + - const: amlogic,gxbb-audin + - items: + - const: amlogic,gxl-audin + - const: amlogic,gxbb-audin + + reg: + maxItems: 1 + + resets: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: AUDIN peripheral clock + + "#sound-dai-cells": + const: 1 + +required: + - compatible + - reg + - resets + - interrupts + - clocks + - "#sound-dai-cells" + +unevaluatedProperties: false + +examples: + - | + #include + #include + #include + #include + + audio-controller@a000 { + compatible = "amlogic,gxbb-audin"; + reg = <0xa000 0x148>; + resets = <&reset RESET_AUDIN>; + interrupts = ; + sound-name-prefix = "AUDIN"; + #sound-dai-cells = <1>; + clocks = <&clkc CLKID_I2S_SPDIF>; + }; diff --git a/Documentation/devicetree/bindings/sound/cirrus,cs35l45.yaml b/Documentation/devicetree/bindings/sound/cirrus,cs35l45.yaml index e674811b22b204..9373ce4bc3a858 100644 --- a/Documentation/devicetree/bindings/sound/cirrus,cs35l45.yaml +++ b/Documentation/devicetree/bindings/sound/cirrus,cs35l45.yaml @@ -16,6 +16,120 @@ description: | allOf: - $ref: dai-common.yaml# + - if: + required: + - cirrus,amplifier-bpe-enable + then: + required: + - cirrus,amplifier-bpe-response-mode + - cirrus,amplifier-bpe-thresholds-microvolt + - cirrus,amplifier-bpe-attack-rates + - cirrus,amplifier-bpe-hold-times-us + - cirrus,amplifier-bpe-release-rates + else: + properties: + cirrus,amplifier-bpe-response-mode: false + cirrus,amplifier-bpe-thresholds-microvolt: false + cirrus,amplifier-bpe-attenuation-levels-db: false + cirrus,amplifier-bpe-attenuation-levels-microvolt: false + cirrus,amplifier-bpe-attenuation-levels-microwatt: false + cirrus,amplifier-bpe-attack-rates: false + cirrus,amplifier-bpe-hold-times-us: false + cirrus,amplifier-bpe-release-rates: false + - if: + properties: + cirrus,amplifier-bpe-response-mode: + const: 0 + required: + - cirrus,amplifier-bpe-response-mode + then: + required: + - cirrus,amplifier-bpe-attenuation-levels-db + properties: + cirrus,amplifier-bpe-attenuation-levels-microvolt: false + cirrus,amplifier-bpe-attenuation-levels-microwatt: false + - if: + properties: + cirrus,amplifier-bpe-response-mode: + const: 1 + required: + - cirrus,amplifier-bpe-response-mode + then: + required: + - cirrus,amplifier-bpe-attenuation-levels-microvolt + properties: + cirrus,amplifier-bpe-attenuation-levels-db: false + cirrus,amplifier-bpe-attenuation-levels-microwatt: false + - if: + properties: + cirrus,amplifier-bpe-response-mode: + const: 2 + required: + - cirrus,amplifier-bpe-response-mode + then: + required: + - cirrus,amplifier-bpe-attenuation-levels-microwatt + properties: + cirrus,amplifier-bpe-attenuation-levels-db: false + cirrus,amplifier-bpe-attenuation-levels-microvolt: false + + - if: + required: + - cirrus,boost-bpe-enable + then: + required: + - cirrus,boost-bpe-output-operating-mode + - cirrus,boost-bpe-output-attack-rate + - cirrus,boost-bpe-output-release-rate + - cirrus,boost-bpe-battery-limits-microamp + - cirrus,boost-bpe-battery-thresholds-microvolt + - cirrus,boost-bpe-battery-attack-rates + - cirrus,boost-bpe-battery-hold-times-us + - cirrus,boost-bpe-battery-release-rates + else: + properties: + cirrus,boost-bpe-output-operating-mode: false + cirrus,boost-bpe-output-attack-rate: false + cirrus,boost-bpe-output-release-rate: false + cirrus,boost-bpe-battery-limits-microamp: false + cirrus,boost-bpe-battery-thresholds-microvolt: false + cirrus,boost-bpe-battery-attack-rates: false + cirrus,boost-bpe-battery-hold-times-us: false + cirrus,boost-bpe-battery-release-rates: false + cirrus,boost-bpe-inductor-release-mode: false + cirrus,boost-bpe-inductor-threshold-microamp: false + cirrus,boost-bpe-inductor-threshold-deltas-microamp: false + cirrus,boost-bpe-inductor-threshold-hysteresis-microamp: false + cirrus,boost-bpe-inductor-delay-hysteresis-us: false + cirrus,boost-bpe-inductor-delays-ms: false + cirrus,boost-bpe-inductor-attack-rates: false + cirrus,boost-bpe-inductor-release-rates: false + - if: + properties: + cirrus,boost-bpe-output-operating-mode: + const: 0 + required: + - cirrus,boost-bpe-output-operating-mode + then: + required: + - cirrus,boost-bpe-inductor-release-mode + - cirrus,boost-bpe-inductor-threshold-microamp + - cirrus,boost-bpe-inductor-threshold-deltas-microamp + - cirrus,boost-bpe-inductor-threshold-hysteresis-microamp + - cirrus,boost-bpe-inductor-delay-hysteresis-us + - cirrus,boost-bpe-inductor-delays-ms + - cirrus,boost-bpe-inductor-attack-rates + - cirrus,boost-bpe-inductor-release-rates + else: + properties: + cirrus,boost-bpe-inductor-release-mode: false + cirrus,boost-bpe-inductor-threshold-microamp: false + cirrus,boost-bpe-inductor-threshold-deltas-microamp: false + cirrus,boost-bpe-inductor-threshold-hysteresis-microamp: false + cirrus,boost-bpe-inductor-delay-hysteresis-us: false + cirrus,boost-bpe-inductor-delays-ms: false + cirrus,boost-bpe-inductor-attack-rates: false + cirrus,boost-bpe-inductor-release-rates: false properties: compatible: @@ -109,6 +223,166 @@ properties: - 0 - 1 + cirrus,boost-bpe-enable: + type: boolean + description: + Enable the boost converter brownout protection engine (BBPE). + Configuration properties are applied before the engine is enabled. + + cirrus,boost-bpe-inductor-release-mode: + description: + Selects whether the inductor current response releases instantly or + through the release counter. Required in combined mode. Use a + CS35L45_BST_BPE_IL_RELEASE_MODE_* constant. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + + cirrus,boost-bpe-output-operating-mode: + description: + Selects the operating mode for the BBPE output stage. The BBPE can be + configured to apply the minimum of the battery voltage and inductor + current response or the battery voltage response only. When operating in + battery voltage only mode, the inductor response related properties are + invalid. + + Required when Boost BPE is enabled. Use a CS35L45_BST_BPE_OUTPUT_MODE_* + constant. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + + cirrus,boost-bpe-output-attack-rate: + description: + Boost BPE output attack-rate selector. Use a + CS35L45_BST_BPE_ATTACK_RATE_* constant. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 7 + + cirrus,boost-bpe-output-release-rate: + description: + Boost BPE output release-rate selector. Use a + CS35L45_BST_BPE_RELEASE_RATE_* constant. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 16 + + cirrus,boost-bpe-battery-limits-microamp: + description: + Boost converter current limits for battery voltage response levels 1 + through 4, in ascending level order. + minItems: 4 + maxItems: 4 + items: + minimum: 250000 + maximum: 4625000 + multipleOf: 62500 + + cirrus,boost-bpe-battery-thresholds-microvolt: + description: + Battery voltage thresholds for battery voltage response levels 0 through + 3, in ascending level order. + minItems: 4 + maxItems: 4 + items: + minimum: 2300000 + maximum: 4500000 + multipleOf: 10000 + + cirrus,boost-bpe-battery-attack-rates: + description: + Attack-rate selectors for battery voltage response levels 1 through 3, in + ascending level order. Use CS35L45_BST_BPE_ATTACK_RATE_* constants. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3 + maxItems: 3 + items: + minimum: 0 + maximum: 7 + + cirrus,boost-bpe-battery-hold-times-us: + description: + Hold times for battery voltage response levels 0 through 3, in ascending + level order. Infinite hold is not supported. + minItems: 4 + maxItems: 4 + items: + enum: [0, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000] + + cirrus,boost-bpe-battery-release-rates: + description: + Release-rate selectors for voltage response levels 0 through 3, in + ascending level order. Use CS35L45_BST_BPE_RELEASE_RATE_* constants. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + items: + minimum: 0 + maximum: 16 + + cirrus,boost-bpe-inductor-threshold-microamp: + description: + Inductor current response level 1 threshold. + minimum: 250000 + maximum: 4000000 + multipleOf: 62500 + + cirrus,boost-bpe-inductor-threshold-deltas-microamp: + description: + Inductor current response threshold deltas 1 and 2, in that order. + minItems: 2 + maxItems: 2 + items: + minimum: 0 + maximum: 3750000 + multipleOf: 62500 + + cirrus,boost-bpe-inductor-threshold-hysteresis-microamp: + description: + Release threshold hysteresis for inductor current response levels 1 + and 2. + minimum: 0 + maximum: 968750 + multipleOf: 31250 + + cirrus,boost-bpe-inductor-delay-hysteresis-us: + description: + Release delay hysteresis for inductor current response levels 1 and 2. + minimum: 0 + maximum: 992 + multipleOf: 32 + + cirrus,boost-bpe-inductor-delays-ms: + description: + Entry delays for inductor current response levels 1 and 2, in ascending + level order. + minItems: 2 + maxItems: 2 + items: + minimum: 0 + maximum: 100 + + cirrus,boost-bpe-inductor-attack-rates: + description: + Attack-rate selectors for inductor current response levels 1 and 2, in + ascending level order. Use CS35L45_BST_BPE_ATTACK_RATE_* constants. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + items: + minimum: 0 + maximum: 7 + + cirrus,boost-bpe-inductor-release-rates: + description: + Release-rate selectors for inductor current response levels 1 and 2, in + ascending level order. Use CS35L45_BST_BPE_RELEASE_RATE_* constants. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + items: + minimum: 0 + maximum: 16 + cirrus,ldpm-group2-vmon-select: type: boolean description: @@ -123,6 +397,103 @@ properties: the current monitor (IMON) circuit is put into a low power operational state. + cirrus,amplifier-bpe-enable: + type: boolean + description: Enable the amplifier brownout prevention engine (BPE). + + cirrus,amplifier-bpe-response-mode: + description: + Amplifier BPE attack and release response mode. This property + determines the ABPE attenuation natural units. + 0 = logarithmic + 1 = linear voltage + 2 = linear power + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2] + + cirrus,amplifier-bpe-thresholds-microvolt: + description: + Amplifier BPE response battery voltage thresholds for levels L3, L2, + L1, L0, in that order. Each level can be set independently. + minItems: 4 + maxItems: 4 + items: + minimum: 2300000 + maximum: 4500000 + multipleOf: 10000 + + cirrus,amplifier-bpe-attenuation-levels-db: + description: + Amplifier BPE logarithmic audio output attenuation for levels L3, L2, + L1, L0, in whole dB steps. Half dB hardware settings are not + supported. + minItems: 4 + maxItems: 4 + items: + minimum: 0 + maximum: 15 + + cirrus,amplifier-bpe-attenuation-levels-microvolt: + description: | + Amplifier BPE linear voltage audio output attenuation for levels L3, + L2, L1, L0. + minItems: 4 + maxItems: 4 + items: + minimum: 187500 + maximum: 1000000 + multipleOf: 31250 + + cirrus,amplifier-bpe-attenuation-levels-microwatt: + description: | + Amplifier BPE linear power audio output attenuation for levels L3, + L2, L1, L0. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + items: + minimum: 31250 + maximum: 1000000 + multipleOf: 31250 + + cirrus,amplifier-bpe-attack-rates: + description: | + Amplifier BPE attack rate register codes for levels L3, L2, L1, L0. + Code 0 is instantaneous; codes 1 through 8 select progressively + slower rates. The physical rate depends on the response mode. + + See section 7.21.9 of the datasheet for a detailed description. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + items: + minimum: 0 + maximum: 8 + + cirrus,amplifier-bpe-hold-times-us: + description: | + Amplifier BPE hold times for levels L3, L2, L1, L0. Infinite hold is + unsupported. + minItems: 4 + maxItems: 4 + items: + enum: [0, 250, 500, 1000, 5000, 10000, 25000, 50000, + 100000, 250000, 500000, 1000000, 2500000, 5000000, 10000000] + + cirrus,amplifier-bpe-release-rates: + description: | + Amplifier BPE release rate register codes for levels L3, L2, L1, L0. + Code 0 is instantaneous; codes 1 through 14 select progressively + slower rates. The physical rate depends on the response mode. + + See section 7.21.11 of the datasheet for a detailed description. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + items: + minimum: 0 + maximum: 14 + patternProperties: "^cirrus,gpio-ctrl[1-3]$": description: @@ -251,6 +622,50 @@ examples: cirrus,ldpm-group2-delay-ms = <1000>; cirrus,ldpm-group2-vmon-select; cirrus,ldpm-group2-imon-select; + cirrus,amplifier-bpe-enable; + cirrus,amplifier-bpe-response-mode = <0>; + cirrus,amplifier-bpe-thresholds-microvolt = + <3200000 3000000 2800000 2600000>; + cirrus,amplifier-bpe-attenuation-levels-db = <3 6 9 12>; + cirrus,amplifier-bpe-attack-rates = <6 6 6 6>; + cirrus,amplifier-bpe-hold-times-us = <500 500 500 500>; + cirrus,amplifier-bpe-release-rates = <5 5 5 5>; + cirrus,boost-bpe-enable; + cirrus,boost-bpe-inductor-release-mode = + ; + cirrus,boost-bpe-output-operating-mode = + ; + cirrus,boost-bpe-output-attack-rate = + ; + cirrus,boost-bpe-output-release-rate = + ; + cirrus,boost-bpe-battery-limits-microamp = + <1000000 1500000 2000000 2500000>; + cirrus,boost-bpe-battery-thresholds-microvolt = + <4000000 3600000 3200000 2800000>; + cirrus,boost-bpe-battery-attack-rates = + ; + cirrus,boost-bpe-battery-hold-times-us = <0 5 10 25>; + cirrus,boost-bpe-battery-release-rates = + ; + cirrus,boost-bpe-inductor-threshold-microamp = <3000000>; + cirrus,boost-bpe-inductor-threshold-deltas-microamp = + <250000 500000>; + cirrus,boost-bpe-inductor-threshold-hysteresis-microamp = + <125000>; + cirrus,boost-bpe-inductor-delay-hysteresis-us = <64>; + cirrus,boost-bpe-inductor-delays-ms = <12 4>; + cirrus,boost-bpe-inductor-attack-rates = + ; + cirrus,boost-bpe-inductor-release-rates = + ; cirrus,gpio-ctrl1 { gpio-ctrl = <0x2>; }; diff --git a/Documentation/devicetree/bindings/sound/maxim,max98088.yaml b/Documentation/devicetree/bindings/sound/maxim,max98088.yaml index e4a2967e1e8180..4d33fd705cf8ee 100644 --- a/Documentation/devicetree/bindings/sound/maxim,max98088.yaml +++ b/Documentation/devicetree/bindings/sound/maxim,max98088.yaml @@ -9,6 +9,9 @@ title: MAX98088 audio CODEC maintainers: - Abdulrasaq Lawani +allOf: + - $ref: dai-common.yaml# + properties: compatible: enum: @@ -26,11 +29,14 @@ properties: items: - const: mclk + '#sound-dai-cells': + const: 1 + required: - compatible - reg -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/nuvoton,nau8310.yaml b/Documentation/devicetree/bindings/sound/nuvoton,nau8310.yaml new file mode 100644 index 00000000000000..16b0dd1cdbefca --- /dev/null +++ b/Documentation/devicetree/bindings/sound/nuvoton,nau8310.yaml @@ -0,0 +1,186 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/nuvoton,nau8310.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton NAU83G10/20 Mono Class-D Amplifier with DSP + +description: + Mono Class-D Amplifier with DSP and I/V-sense. + This device supports I2C. + +maintainers: + - Neo Chang + +properties: + compatible: + enum: + - nuvoton,nau8310 + - nuvoton,nau8320 + + reg: + description: The I2C address is determined by the hardware pins. + enum: [0x10, 0x11, 0x40, 0x41] + + "#sound-dai-cells": + const: 0 + + clocks: + maxItems: 1 + + clock-names: + const: mclk + + firmware-name: + items: + - description: + DSP core firmware. + + nuvoton,vref-impedance-ohms: + description: + VREF Impedance Selection. + enum: [0, 25000, 125000, 2500] + + nuvoton,dac-vref-microvolt: + description: + The DAC vref to be used in voltage. DAC reference voltage setting. Can + be used for minor tuning of the output level. Since the VDDA is range + between 1.62 to 1.98 voltage, the typical value for design is 1.8V. After + the minor tuning, the final microvolt are as the below. + enum: [1800000, 2700000, 2880000, 3060000] + + nuvoton,sar-voltage-microvolt: + description: + SAR Gain Tracking Selection in microvolts. + Assuming the typical VDDA design value is 1.8V, the SAR voltage is + calculated by multiplying VDDA by the gain tracking ratio. + enum: [1800000, 1980000, 2160000, 2340000, 2520000, 2772000, 5616000] + + nuvoton,sar-compare-time-ns: + description: + SAR compare time. + enum: [500, 1000, 2000, 4000] + + nuvoton,sar-sampling-time-us: + description: + SAR sampling time. + enum: [2, 4, 8, 16] + + nuvoton,clock-detection-disable: + type: boolean + description: + Disable the Clock Detection Module. By default, clock detection is enabled. + When clock detection is enabled, it will detect whether MCLK + and FS are within the range. MCLK range is from 2.048MHz to 24.576MHz. + FS range is from 8kHz to 96kHz. And also needs to detect the ratio + MCLK_SRC/LRCK of 256, 400 or 500, and needs to detect the BCLK + to make sure data is present. There needs to be at least 32 BCLK + cycles per Frame Sync. + + nuvoton,clock-det-data: + type: boolean + description: + Clock detection non-zero samples configuration for power up signal. + + nuvoton,boost-delay-ms: + description: + Boost Control Hold Timer in decrement (msec). + enum: [0, 1, 2, 4, 8, 16, 32, 64, 128] + + nuvoton,boost-convert-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Boost Converter operating mode. + enum: + - 0 # BOOST CONVERTER disabled + - 1 # BOOST CONVERTER enable gated by POWERUP signal + - 3 # BOOST CONVERTER enabled + + nuvoton,boost-target-limit-microvolt: + description: + Boost Control Target Value Limit. + The step size is 190000uV (0.19V). + minimum: 0 + maximum: 11970000 + + nuvoton,boost-target-margin-microvolt: + description: + Boost Margin Value between Boost Target Voltage and peak output level. + The step size is 190000uV (0.19V). + minimum: 0 + maximum: 11970000 + + nuvoton,temp-compensation: + type: boolean + description: + Enable Temperature Compensation. + + nuvoton,normal-iis-data: + type: boolean + description: + Enable Normal I2S Audio Data mode. The I2S interface + transmits only audio data without SAR ADC data. + +required: + - compatible + - reg + - firmware-name + +allOf: + - $ref: dai-common.yaml# + - if: + properties: + compatible: + contains: + const: nuvoton,nau8320 + then: + properties: + nuvoton,boost-delay-ms: false + nuvoton,boost-convert-mode: false + nuvoton,boost-target-limit-microvolt: false + nuvoton,boost-target-margin-microvolt: false + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + codec@10 { + compatible = "nuvoton,nau8310"; + reg = <0x10>; + #sound-dai-cells = <0>; + firmware-name = "NAU83G10.kcs.bin"; + nuvoton,vref-impedance-ohms = <125000>; + nuvoton,dac-vref-microvolt = <2700000>; + nuvoton,sar-voltage-microvolt = <1800000>; + nuvoton,sar-compare-time-ns = <1000>; + nuvoton,sar-sampling-time-us = <4>; + nuvoton,clock-detection-disable; + nuvoton,clock-det-data; + nuvoton,boost-delay-ms = <128>; + nuvoton,boost-convert-mode = <1>; + nuvoton,boost-target-limit-microvolt = <9500000>; + nuvoton,boost-target-margin-microvolt = <380000>; + nuvoton,temp-compensation; + nuvoton,normal-iis-data; + }; + + codec@11 { + compatible = "nuvoton,nau8320"; + reg = <0x11>; + #sound-dai-cells = <0>; + firmware-name = "NAU83G20.kcs.bin"; + nuvoton,vref-impedance-ohms = <125000>; + nuvoton,dac-vref-microvolt = <2700000>; + nuvoton,sar-voltage-microvolt = <1800000>; + nuvoton,sar-compare-time-ns = <1000>; + nuvoton,sar-sampling-time-us = <4>; + nuvoton,clock-detection-disable; + nuvoton,clock-det-data; + nuvoton,temp-compensation; + nuvoton,normal-iis-data; + }; + }; diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra20-ac97.yaml b/Documentation/devicetree/bindings/sound/nvidia,tegra20-ac97.yaml index 4ea0a303d995d4..19e242f6cf028c 100644 --- a/Documentation/devicetree/bindings/sound/nvidia,tegra20-ac97.yaml +++ b/Documentation/devicetree/bindings/sound/nvidia,tegra20-ac97.yaml @@ -10,6 +10,9 @@ maintainers: - Thierry Reding - Jon Hunter +allOf: + - $ref: dai-common.yaml# + properties: compatible: const: nvidia,tegra20-ac97 @@ -45,6 +48,9 @@ properties: description: AC97 DAP _FS line maxItems: 1 + '#sound-dai-cells': + const: 0 + required: - compatible - reg @@ -57,7 +63,7 @@ required: - nvidia,codec-reset-gpios - nvidia,codec-sync-gpios -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra20-i2s.yaml b/Documentation/devicetree/bindings/sound/nvidia,tegra20-i2s.yaml index 68ae124eaf804a..9a17866da7731c 100644 --- a/Documentation/devicetree/bindings/sound/nvidia,tegra20-i2s.yaml +++ b/Documentation/devicetree/bindings/sound/nvidia,tegra20-i2s.yaml @@ -15,6 +15,9 @@ maintainers: - Thierry Reding - Jon Hunter +allOf: + - $ref: dai-common.yaml# + properties: compatible: const: nvidia,tegra20-i2s @@ -49,6 +52,9 @@ properties: limiting number of supportable audio rates. type: boolean + '#sound-dai-cells': + const: 0 + required: - compatible - reg @@ -59,7 +65,7 @@ required: - dmas - dma-names -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml b/Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml index 1c9f24d2681900..20e637d2a02714 100644 --- a/Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml +++ b/Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml @@ -28,6 +28,7 @@ properties: - nvidia,tegra186-ahub - nvidia,tegra234-ahub - nvidia,tegra264-ahub + - nvidia,tegra268-ahub - items: - const: nvidia,tegra194-ahub - const: nvidia,tegra186-ahub diff --git a/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.yaml b/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.yaml index 89c3c6414ab139..fbe4cd46196838 100644 --- a/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.yaml +++ b/Documentation/devicetree/bindings/sound/nvidia,tegra30-i2s.yaml @@ -10,6 +10,9 @@ maintainers: - Thierry Reding - Jon Hunter +allOf: + - $ref: dai-common.yaml# + properties: compatible: oneOf: @@ -42,6 +45,9 @@ properties: - description: rx (playback) - description: tx (capture) + '#sound-dai-cells': + const: 0 + required: - compatible - reg @@ -50,7 +56,7 @@ required: - reset-names - nvidia,ahub-cif-ids -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/nxp,tfa9865.yaml b/Documentation/devicetree/bindings/sound/nxp,tfa9865.yaml new file mode 100644 index 00000000000000..ff8fd35d9d103c --- /dev/null +++ b/Documentation/devicetree/bindings/sound/nxp,tfa9865.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/nxp,tfa9865.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP/Goodix TFA9865 Audio Amplifier + +maintainers: + - Venkat Yadlapati + +description: + The TFA9865 is a mono class-D speaker amplifier with an integrated boost + converter and voltage/current sensing. It is controlled over I2C and + receives audio over I2S/TDM. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + const: nxp,tfa9865 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + vddd-supply: + description: Digital supply (1.8 V) + + '#sound-dai-cells': + const: 0 + +required: + - compatible + - reg + - '#sound-dai-cells' + +unevaluatedProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + audio-codec@35 { + compatible = "nxp,tfa9865"; + reg = <0x35>; + interrupts-extended = <&tlmm 201 IRQ_TYPE_EDGE_FALLING>; + reset-gpios = <&tlmm 183 GPIO_ACTIVE_LOW>; + sound-name-prefix = "Speaker"; + #sound-dai-cells = <0>; + }; + }; diff --git a/Documentation/devicetree/bindings/sound/qcom,lpass-rx-macro.yaml b/Documentation/devicetree/bindings/sound/qcom,lpass-rx-macro.yaml index 4988e7ed6e34b0..67a4a9536d06d5 100644 --- a/Documentation/devicetree/bindings/sound/qcom,lpass-rx-macro.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,lpass-rx-macro.yaml @@ -19,6 +19,9 @@ properties: - qcom,sm8450-lpass-rx-macro - qcom,sm8550-lpass-rx-macro - qcom,sc8280xp-lpass-rx-macro + - items: + - const: qcom,sm8350-lpass-rx-macro + - const: qcom,sm8250-lpass-rx-macro - items: - enum: - qcom,eliza-lpass-rx-macro @@ -103,10 +106,11 @@ allOf: - if: properties: compatible: - enum: - - qcom,sc8280xp-lpass-rx-macro - - qcom,sm8250-lpass-rx-macro - - qcom,sm8450-lpass-rx-macro + contains: + enum: + - qcom,sc8280xp-lpass-rx-macro + - qcom,sm8250-lpass-rx-macro + - qcom,sm8450-lpass-rx-macro then: properties: clocks: diff --git a/Documentation/devicetree/bindings/sound/qcom,lpass-tx-macro.yaml b/Documentation/devicetree/bindings/sound/qcom,lpass-tx-macro.yaml index d8682ff2e82c59..f9702a11ef8250 100644 --- a/Documentation/devicetree/bindings/sound/qcom,lpass-tx-macro.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,lpass-tx-macro.yaml @@ -19,6 +19,9 @@ properties: - qcom,sm8450-lpass-tx-macro - qcom,sm8550-lpass-tx-macro - qcom,sc8280xp-lpass-tx-macro + - items: + - const: qcom,sm8350-lpass-tx-macro + - const: qcom,sm8450-lpass-tx-macro - items: - enum: - qcom,eliza-lpass-tx-macro @@ -90,10 +93,11 @@ allOf: - if: properties: compatible: - enum: - - qcom,sc8280xp-lpass-tx-macro - - qcom,sm8250-lpass-tx-macro - - qcom,sm8450-lpass-tx-macro + contains: + enum: + - qcom,sc8280xp-lpass-tx-macro + - qcom,sm8250-lpass-tx-macro + - qcom,sm8450-lpass-tx-macro then: properties: clocks: diff --git a/Documentation/devicetree/bindings/sound/qcom,lpass-va-macro.yaml b/Documentation/devicetree/bindings/sound/qcom,lpass-va-macro.yaml index aea31fbdad376a..a5466e61b0b143 100644 --- a/Documentation/devicetree/bindings/sound/qcom,lpass-va-macro.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,lpass-va-macro.yaml @@ -19,6 +19,9 @@ properties: - qcom,sm8450-lpass-va-macro - qcom,sm8550-lpass-va-macro - qcom,sc8280xp-lpass-va-macro + - items: + - const: qcom,sm8350-lpass-va-macro + - const: qcom,sc7280-lpass-va-macro - items: - enum: - qcom,eliza-lpass-va-macro diff --git a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml index e2e3fc99e6d9a0..a890fa288a76b3 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -21,6 +21,9 @@ properties: - lenovo,yoga-c630-sndcard - qcom,db845c-sndcard - const: qcom,sdm845-sndcard + - items: + - const: qcom,sm8350-sndcard + - const: qcom,sm8250-sndcard - items: - enum: - qcom,eliza-sndcard @@ -37,6 +40,7 @@ properties: - fairphone,fp4-sndcard - fairphone,fp5-sndcard - motorola,dubai-sndcard + - motorola,vantage-sndcard - qcom,apq8096-sndcard - qcom,glymur-sndcard - qcom,nord-sndcard diff --git a/Documentation/devicetree/bindings/sound/realtek,rt5631.yaml b/Documentation/devicetree/bindings/sound/realtek,rt5631.yaml index 03ee25e1eb6357..0b82d6a9f05efa 100644 --- a/Documentation/devicetree/bindings/sound/realtek,rt5631.yaml +++ b/Documentation/devicetree/bindings/sound/realtek,rt5631.yaml @@ -36,6 +36,9 @@ description: | * MICBIAS1 * MICBIAS2 +allOf: + - $ref: dai-common.yaml# + properties: compatible: enum: @@ -57,11 +60,14 @@ properties: $ref: audio-graph-port.yaml# unevaluatedProperties: false + '#sound-dai-cells': + const: 0 + required: - compatible - reg -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/ti,pcm512x.yaml b/Documentation/devicetree/bindings/sound/ti,pcm512x.yaml index 21ea9ff5a2bb79..58ea52e79860d9 100644 --- a/Documentation/devicetree/bindings/sound/ti,pcm512x.yaml +++ b/Documentation/devicetree/bindings/sound/ti,pcm512x.yaml @@ -42,6 +42,10 @@ properties: '#sound-dai-cells': const: 0 + mute-gpios: + description: GPIO connected to the active-low XSMT soft-mute input. + maxItems: 1 + pll-in: description: GPIO pin used to connect the pll using <1> through <6>. The device will be configured for clock input on the given pll-in pin. diff --git a/Documentation/devicetree/bindings/sound/wlf,wm8903.yaml b/Documentation/devicetree/bindings/sound/wlf,wm8903.yaml index 089b6738479755..bb96e8f790b2de 100644 --- a/Documentation/devicetree/bindings/sound/wlf,wm8903.yaml +++ b/Documentation/devicetree/bindings/sound/wlf,wm8903.yaml @@ -29,6 +29,9 @@ description: | maintainers: - patches@opensource.cirrus.com +allOf: + - $ref: dai-common.yaml# + properties: compatible: const: wlf,wm8903 @@ -75,13 +78,16 @@ properties: DCVDD-supply: description: Digital core supply regulator for the DCVDD pin. + '#sound-dai-cells': + const: 0 + required: - compatible - reg - gpio-controller - '#gpio-cells' -additionalProperties: false +unevaluatedProperties: false examples: - | diff --git a/Documentation/devicetree/bindings/sound/wlf,wm8994.yaml b/Documentation/devicetree/bindings/sound/wlf,wm8994.yaml index 0db04a90ac6b3b..f367c1ee0a947e 100644 --- a/Documentation/devicetree/bindings/sound/wlf,wm8994.yaml +++ b/Documentation/devicetree/bindings/sound/wlf,wm8994.yaml @@ -69,7 +69,7 @@ properties: SPKVDD2-supply: true '#sound-dai-cells': - const: 0 + enum: [0, 1] wlf,gpio-cfg: $ref: /schemas/types.yaml#/definitions/uint32-array diff --git a/Documentation/devicetree/bindings/spi/spi-pl022.yaml b/Documentation/devicetree/bindings/spi/spi-pl022.yaml index 680fdfa184d0c8..9a61cb16e68301 100644 --- a/Documentation/devicetree/bindings/spi/spi-pl022.yaml +++ b/Documentation/devicetree/bindings/spi/spi-pl022.yaml @@ -71,6 +71,9 @@ properties: - const: rx - const: tx + power-domains: + maxItems: 1 + resets: maxItems: 1 diff --git a/Documentation/devicetree/bindings/usb/altr,agilex5-dwc3.yaml b/Documentation/devicetree/bindings/usb/altr,agilex5-dwc3.yaml new file mode 100644 index 00000000000000..610ddcb632e280 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/altr,agilex5-dwc3.yaml @@ -0,0 +1,112 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/altr,agilex5-dwc3.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Altera Agilex5 DWC3 USB SoC Controller + +maintainers: + - Adrian Ng Ho Yin + +description: + The Altera Agilex5 SoCFPGA integrates a Synopsys DesignWare USB3 (DWC3) + controller that supports host, device and DRD modes. + +allOf: + - $ref: snps,dwc3-common.yaml# + +properties: + compatible: + const: altr,agilex5-dwc3 + + reg: + maxItems: 1 + + clocks: + items: + - description: Master/Core bus clock + - description: Controller reference clock + - description: Controller suspend clock + + clock-names: + items: + - const: bus_early + - const: ref + - const: suspend + + interrupts: + maxItems: 1 + + phys: + minItems: 2 + maxItems: 2 + + phy-names: + items: + - const: usb2-phy + - const: usb3-phy + + iommus: + maxItems: 1 + + resets: + items: + - description: DWC3 core reset + - description: DWC3 ECC reset + + reset-names: + items: + - const: core + - const: ecc + + dr_mode: true + + maximum-speed: true + + snps,dis_u2_susphy_quirk: true + + snps,dis_u3_susphy_quirk: true + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + - phys + - phy-names + - resets + - reset-names + - snps,dis_u2_susphy_quirk + - snps,dis_u3_susphy_quirk + +additionalProperties: false + +examples: + - | + #include + #include + #include + + soc { + #address-cells = <1>; + #size-cells = <1>; + + usb@11000000 { + compatible = "altr,agilex5-dwc3"; + reg = <0x11000000 0x100000>; + interrupts = ; + clocks = <&clkmgr AGILEX5_USB31_BUS_CLK_EARLY>, + <&clkmgr AGILEX5_USB31_SUSPEND_CLK>, + <&clkmgr AGILEX5_USB31_SUSPEND_CLK>; + clock-names = "bus_early", "ref", "suspend"; + phys = <&usbphy0>, <&usbphy1>; + phy-names = "usb2-phy", "usb3-phy"; + resets = <&rst USB1_RESET>, <&rst USB1_OCP_RESET>; + reset-names = "core", "ecc"; + iommus = <&smmu 7>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + }; diff --git a/Documentation/devicetree/bindings/usb/cypress,hx3.yaml b/Documentation/devicetree/bindings/usb/cypress,hx3.yaml index d6eac1213228d2..aca2fe796240ff 100644 --- a/Documentation/devicetree/bindings/usb/cypress,hx3.yaml +++ b/Documentation/devicetree/bindings/usb/cypress,hx3.yaml @@ -53,7 +53,6 @@ properties: required: - compatible - reg - - peer-hub - vdd-supply - vdd2-supply diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9p.rst index 3f65db648db06a..a791684627b637 100644 --- a/Documentation/filesystems/9p.rst +++ b/Documentation/filesystems/9p.rst @@ -50,6 +50,14 @@ mount points. Each 9P export is seen by the client as a virtio device with an associated "mount_tag" property. Available mount tags can be seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio/mount_tag files. +For server accessible over vsock (VM sockets):: + + mount -t 9p -o trans=vsock[,port=] /mnt/9 + +where CID is the vsock Context ID of the remote endpoint (2 for host from +a guest VM, 3+ for guest VMs from the host). The port to connect to can be +specified with the port option (default: 564). + USBG Usage ========== @@ -117,6 +125,8 @@ Options tcp specifying a normal TCP/IP connection fd used passed file descriptors for connection (see rfdno and wfdno) + vsock connect over VM sockets (vsock) using + CID as the mount source virtio connect to the next virtio channel available (from QEMU with trans_virtio module) rdma connect to a specified RDMA channel @@ -228,7 +238,7 @@ Options any v9fs does single attach and performs all operations as one user - clien + client ACL based access check on the 9p client side for access validation diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst index 02caf3b061fed7..7f4d550778480f 100644 --- a/Documentation/filesystems/erofs.rst +++ b/Documentation/filesystems/erofs.rst @@ -171,13 +171,28 @@ Each mounted filesystem will have a directory in /sys/fs/erofs based on its device name (i.e., /sys/fs/erofs/sda). (see also Documentation/ABI/testing/sysfs-fs-erofs) -On-disk details -=============== +On-disk format +============== + +This section provides a high-level overview. For the latest complete on-disk +format specification, see: + +- https://erofs.docs.kernel.org/en/latest/ondisk/ Summary ------- -Different from other read-only file systems, an EROFS volume is designed -to be as simple as possible:: + +EROFS keeps its on-disk format as simple as possible to minimize metadata +consistency checks, retaining only those that are strictly necessary +at runtime. + +The guiding principle is that malformed or deliberately crafted metadata +may describe a corrupt filesystem, but its effects should remain confined +to the data and metadata exposed to userspace: garbage filesystems return +garbage (meta)data to users, and nothing more. Violating this rule is +unsafe and must be prevented by our on-disk design. + +:: |-> aligned with the block size ____________________________________________________________ @@ -185,16 +200,50 @@ to be as simple as possible:: |_|__|_|_____|__________|_____|______|__________|_____|______| 0 +1K -All data areas should be aligned with the block size, but metadata areas -may not. All metadata can be now observed in two different spaces (views): +Apart from the EROFS superblock, which starts at byte offset 1024, metadata +and data regions have no fixed locations or boundaries and may be interleaved +throughout the image. As a result, inodes do not need to reside in a fixed +central table, allowing incremental builds, although the image creator may +still choose to group all inodes together. + +All data except inline data must be aligned to the filesystem block size +[#unencoded_data]_ to enable efficient block I/O, support memory mapping, +and avoid unnecessary data copies. Metadata does not require block alignment. + +.. [#unencoded_data] Strictly speaking, data refers to unencoded data; + encoded inodes are outside the scope of EROFS core metadata. - 1. Inode metadata space +EROFS core metadata consists only of the superblock, inodes, and directory +entries stored in directory inode data. The physical locations of inode +data are recorded as block numbers to avoid block-alignment checks. - Each valid inode should be aligned with an inode slot, which is a fixed - value (32 bytes) and designed to be kept in line with compact inode size. +Only a few superblock fields, including the root nid (see below), are needed +to parse the filesystem tree. Most of the remaining fields provide filesystem +statistics reported to userspace and should not affect the core filesystem +logic. - Each inode can be directly found with the following formula: - inode offset = meta_blkaddr * block_size + 32 * nid +Encoded inodes, which contain encoded data such as compressed data (including +compressed directories), use a distinct inode "datalayout" number that allows +them to be identified or rejected when reading the inode metadata. Support for +encoded layouts is optional and can be explicitly disabled at runtime if there +are security concerns about parsing compressed data in the kernel. + +There are two metadata views: one for inode metadata and one for shared +extended attributes. Both can also be located in a special hidden inode +called "metabox" (v6.17+), which provides a unified way to compress inode and +xattr metadata: + + 1. Inode metadata view + + Each valid inode is aligned to a 32-byte inode slot, matching the + size of a compact inode. Inodes can be stored either inside or outside + the metabox inode, with a flag in the nid indicating whether they are + stored inside. + + For inodes not in the metabox, each inode can be located directly + using the following formula:: + + inode physical position = meta_blkaddr * block_size + 32 * nid :: @@ -224,8 +273,8 @@ may not. All metadata can be now observed in two different spaces (views): |-> aligned with 4B |-> aligned with 4B - Inode could be 32 or 64 bytes, which can be distinguished from a common - field which all inode versions have -- i_format:: + Inodes can be 32 or 64 bytes, distinguished by the i_format field common + to both formats:: __________________ __________________ | i_format | | i_format | @@ -236,31 +285,44 @@ may not. All metadata can be now observed in two different spaces (views): | | |__________________| 64 bytes - Xattrs, extents, data inline are placed after the corresponding inode with - proper alignment, and they could be optional for different data mappings. - _currently_ total 5 data layouts are supported: + Xattrs, extents, and inline data follow the corresponding inode with + proper alignment. Their presence depends on the inode's datalayout. + Five data layouts are currently supported: == ==================================================================== - 0 flat file data without data inline (no extent); - 1 fixed-sized output data compression (with non-compacted indexes); - 2 flat file data with tail packing data inline (no extent); - 3 fixed-sized output data compression (with compacted indexes, v5.3+); - 4 chunk-based file (v5.15+). + 0 Flat inode data without inline data (no extents) + 1 Encoded inode + 2 Flat inode data with inline tail data (no extents) + 3 Encoded inode (compact indexes) + 4 Chunk-based file (v5.15+) == ==================================================================== - The size of the optional xattrs is indicated by i_xattr_count in inode - header. Large xattrs or xattrs shared by many different files can be - stored in shared xattrs metadata rather than inlined right after inode. + The size of the optional xattrs is indicated by i_xattr_count in the inode + header. Large xattrs or xattrs shared by many files can be stored in + shared xattr metadata rather than inlined immediately after the inode. + + For inodes in the metabox, the remaining nid bits identify the inode slot + within the metabox's inode address space. This data is read through the + metabox inode, with decompression as needed. The metabox inode itself is + located outside the metabox and is identified by metabox_nid in the + superblock. - 2. Shared xattrs metadata space + 2. Shared xattrs metadata view - Shared xattrs space is similar to the above inode space, started with - a specific block indicated by xattr_blkaddr, organized one by one with - proper align. + The shared xattr metadata view is similar to the inode metadata view. + It starts at the block indicated by xattr_blkaddr, with entries stored + sequentially on 4-byte boundaries. Shared xattrs are stored either all + inside or all outside the metabox; this metadata view cannot be selected + individually for each entry. + + Each shared xattr can be located using the following formula:: - Each share xattr can also be directly found by the following formula: xattr offset = xattr_blkaddr * block_size + 4 * xattr_id + When COMPAT_SHARED_EA_IN_METABOX feature is enabled, this offset is within + the metabox inode's address space. Otherwise, it is a physical position + in the filesystem image. + :: |-> aligned by 4 bytes diff --git a/Documentation/filesystems/iomap/design.rst b/Documentation/filesystems/iomap/design.rst index 681e0cbb694416..508e63ce205c06 100644 --- a/Documentation/filesystems/iomap/design.rst +++ b/Documentation/filesystems/iomap/design.rst @@ -75,7 +75,10 @@ At a high level, an iomap operation `looks like this 1. For each byte in the operation range... - 1. Obtain a space mapping via ``->iomap_begin`` + 1. Obtain the next space mapping via the ``iomap_iter_next_fn`` callback. + From the second iteration onwards this same callback first finishes + the previous mapping (committing or unreserving space as needed) + and then produces the next one. 2. For each sub-unit of work... @@ -86,7 +89,13 @@ At a high level, an iomap operation `looks like this 3. Increment operation cursor - 4. Release the mapping via ``->iomap_end``, if necessary +iomap repeats this until the range is fully consumed. The ``iomap_iter_next_fn`` +callback returns ``1`` while there is more of the range left to process, +``0`` once it is fully consumed, or a negative errno on error. +Filesystems rarely implement this callback by hand. The ``iomap_iter_next`` +helper implements the finish-then-produce sequence in terms of two smaller +callbacks, ``begin`` and ``end``. See `The Mapping Callback`_ below for more +info. Each iomap operation will be covered in more detail below. This library was covered previously by an `LWN article @@ -189,7 +198,7 @@ The fields are as follows: * **IOMAP_DELALLOC**: A promise to allocate space at a later time ("delayed allocation"). If the filesystem returns IOMAP_F_NEW here and the write fails, the - ``->iomap_end`` function must delete the reservation. + ``end`` function must delete the reservation. The ``addr`` field must be set to ``IOMAP_NULL_ADDR``. * **IOMAP_MAPPED**: The file range maps to specific space on the @@ -208,12 +217,11 @@ The fields are as follows: * **IOMAP_INLINE**: The file range maps to the memory buffer specified by ``inline_data``. - For write operation, the ``->iomap_end`` function presumably - handles persisting the data. + For write operation, the ``end`` function must persist the data. The ``addr`` field must be set to ``IOMAP_NULL_ADDR``. * ``flags`` describe the status of the space mapping. - These flags should be set by the filesystem in ``->iomap_begin``: + These flags should be set by the filesystem in ``begin``: * **IOMAP_F_NEW**: The space under the mapping is newly allocated. Areas that will not be written to must be zeroed. @@ -262,15 +270,15 @@ The fields are as follows: update. These flags can be set by iomap itself during file operations. - The filesystem should supply an ``->iomap_end`` function if it needs + The filesystem should supply an ``end`` function if it needs to observe these flags: * **IOMAP_F_SIZE_CHANGED**: The file size has changed as a result of using this mapping. * **IOMAP_F_STALE**: The mapping was found to be stale. - iomap will call ``->iomap_end`` on this mapping and then - ``->iomap_begin`` to obtain a new mapping. + iomap will call ``end`` on this mapping and then ``begin`` to obtain a + new mapping. Currently, these flags are only set by pagecache operations. @@ -289,41 +297,103 @@ The fields are as follows: * ``private`` is a pointer to `filesystem-private information `_. - This value will be passed unchanged to ``->iomap_end``. + This value will be passed unchanged to ``end``. * ``validity_cookie`` is a magic freshness value set by the filesystem that should be used to detect stale mappings. For pagecache operations this is critical for correct operation because page faults can occur, which implies that filesystem locks - should not be held between ``->iomap_begin`` and ``->iomap_end``. + should not be held between ``begin`` and ``end``. Filesystems with completely static mappings need not set this value. Only pagecache operations revalidate mappings; see the section about ``iomap_valid`` for details. -``struct iomap_ops`` +The Mapping Callback -------------------- -Every iomap function requires the filesystem to pass an operations -structure to obtain a mapping and (optionally) to release the mapping: +Every iomap operation takes an ``iomap_iter_next_fn`` callback from the +filesystem. iomap calls it once per iteration of the file range: .. code-block:: c - struct iomap_ops { - int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length, - unsigned flags, struct iomap *iomap, - struct iomap *srcmap); + typedef int (*iomap_iter_next_fn)(const struct iomap_iter *iter, + struct iomap *iomap, struct iomap *srcmap); - int (*iomap_end)(struct inode *inode, loff_t pos, loff_t length, - ssize_t written, unsigned flags, - struct iomap *iomap); - }; +``iomap_iter_next_fn`` +~~~~~~~~~~~~~~~~~~~~~~ + +This must finish the previous mapping, if any, and then produce the next +mapping for the current iteration position described by ``iter``. +The mapping is returned through ``iomap`` (and through ``srcmap`` for +operations that read from one mapping while writing to another; see +``begin`` below). + +The callback returns ``1`` to continue iterating, ``0`` once the file +range has been fully consumed, or a negative errno on error. + +Most filesystems are not expected to implement all of these behaviors +in this callback themselves. They should instead call ``iomap_iter_next`` as +described below. + +``iomap_iter_next`` +~~~~~~~~~~~~~~~~~~~ + +Filesystems rarely need a hand-written ``iomap_iter_next_fn`` callback. The +``iomap_iter_next`` helper implements the finish-then-produce sequence in +terms of two smaller callbacks, ``begin`` and ``end``, so most +``iomap_iter_next_fn`` implementations are simply: + +.. code-block:: c + + static int my_iomap_next(const struct iomap_iter *iter, + struct iomap *iomap, struct iomap *srcmap) + { + return iomap_iter_next(iter, iomap, srcmap, + my_iomap_begin, my_iomap_end); + } + +This boilerplate is normally generated with the ``DEFINE_IOMAP_ITER_NEXT()`` +and ``DEFINE_IOMAP_ITER_NEXT_END()`` macros rather than written by hand. Use +``DEFINE_IOMAP_ITER_NEXT()`` for the common case with no ``end`` callback, and +``DEFINE_IOMAP_ITER_NEXT_END()`` when an ``end`` callback is needed: + +.. code-block:: c + + /* no end() callback */ + static DEFINE_IOMAP_ITER_NEXT(my_iomap_next, my_iomap_begin); + + /* with an end() callback */ + static DEFINE_IOMAP_ITER_NEXT_END(my_iomap_next, my_iomap_begin, + my_iomap_end); + +The macro generates a function with external linkage. Prefix the invocation +with ``static`` for a file-local callback, or leave it non-``static`` and add +a matching declaration to a header when the callback is referenced from +another file. + +``end`` may be ``NULL`` when the filesystem has nothing to finish. +The two callbacks have these prototypes: + +.. code-block:: c + + typedef int (*iomap_begin_fn)(struct inode *inode, loff_t pos, + loff_t length, unsigned flags, + struct iomap *iomap, struct iomap *srcmap); + + typedef int (*iomap_end_fn)(struct inode *inode, loff_t pos, + loff_t length, ssize_t written, + unsigned flags, struct iomap *iomap); + +``iomap_iter_next`` is an inline helper, so when it is called with fixed +``begin`` and ``end`` functions the compiler can inline both into the +filesystem's ``iomap_iter_next_fn`` callback, keeping indirect calls out of the +iteration hot path. The two callbacks are described next. -``->iomap_begin`` -~~~~~~~~~~~~~~~~~ +``begin`` +~~~~~~~~~ -iomap operations call ``->iomap_begin`` to obtain one file mapping for -the range of bytes specified by ``pos`` and ``length`` for the file -``inode``. +The ``begin`` callback obtains one file mapping for the range of bytes +specified by ``pos`` and ``length`` for the file ``inode``. This mapping should be returned through the ``iomap`` pointer. The mapping must cover at least the first byte of the supplied file range, but it does not need to cover the entire requested range. @@ -377,18 +447,18 @@ information via ``srcmap``. Only pagecache and fsdax operations support reading from one mapping and writing to another. -``->iomap_end`` -~~~~~~~~~~~~~~~ +``end`` +~~~~~~~ -After the operation completes, the ``->iomap_end`` function, if present, -is called to signal that iomap is finished with a mapping. +After the operation completes, the ``end`` callback, if present, is called to +signal that iomap is finished with a mapping. Typically, implementations will use this function to tear down any -context that were set up in ``->iomap_begin``. +context that was set up in ``begin``. For example, a write might wish to commit the reservations for the bytes that were operated upon and unreserve any space that was not operated upon. ``written`` might be zero if no bytes were touched. -``flags`` will contain the same value passed to ``->iomap_begin``. +``flags`` will contain the same value passed to ``begin``. iomap ops for reads are not likely to need to supply this function. Both functions should return a negative errno code on error, or zero on @@ -421,8 +491,8 @@ iomap is concerned: accessing the folio until writeback is underway. * The **lower** level primitive is taken by the filesystem in the - ``->iomap_begin`` and ``->iomap_end`` functions to coordinate - access to the file space mapping information. + ``begin`` and ``end`` functions to coordinate access to the file space + mapping information. The fields of the iomap object should be filled out while holding this primitive. The upper level synchronization primitive, if any, remains held diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst index da982ca7e41370..a5784dee085099 100644 --- a/Documentation/filesystems/iomap/operations.rst +++ b/Documentation/filesystems/iomap/operations.rst @@ -17,6 +17,12 @@ Supported File Operations Below are a discussion of the high level file operations that iomap implements. +Each operation takes an ``iomap_iter_next_fn`` callback that supplies the file +mappings, as described in the iomap design document. The per-operation +``flags`` documented below are passed to that callback; references to +``begin`` and ``end`` name the two steps a typical callback is built from +via ``iomap_iter_next``. + Buffered I/O ============ @@ -90,10 +96,10 @@ iomap calls these functions: `_ that was set up by ``->get_folio``. - - ``iomap_valid``: The filesystem may not hold locks between - ``->iomap_begin`` and ``->iomap_end`` because pagecache operations - can take folio locks, fault on userspace pages, initiate writeback - for memory reclamation, or engage in other time-consuming actions. + - ``iomap_valid``: The filesystem may not hold locks between ``begin`` and + ``end`` because pagecache operations can take folio locks, fault on + userspace pages, initiate writeback for memory reclamation, or engage in + other time-consuming actions. If a file's space mapping data are mutable, it is possible that the mapping for a particular pagecache folio can `change in the time it takes @@ -114,12 +120,12 @@ iomap calls these functions: If the mapping is not valid, the mapping will be sampled again. To support making the validity decision, the filesystem's - ``->iomap_begin`` function may set ``struct iomap::validity_cookie`` + ``begin`` function may set ``struct iomap::validity_cookie`` at the same time that it populates the other iomap fields. A simple validation cookie implementation is a sequence counter. If the filesystem bumps the sequence counter every time it modifies the inode's extent map, it can be placed in the ``struct - iomap::validity_cookie`` during ``->iomap_begin``. + iomap::validity_cookie`` during ``begin``. If the value in the cookie is found to be different to the value the filesystem holds when the mapping is passed back to ``->iomap_valid``, then the iomap should considered stale and the @@ -199,7 +205,7 @@ Buffered Readahead and Reads The ``iomap_readahead`` function initiates readahead to the pagecache. The ``iomap_read_folio`` function reads one folio's worth of data into the pagecache. -The ``flags`` argument to ``->iomap_begin`` will be set to zero. +The ``flags`` argument to ``begin`` will be set to zero. The pagecache takes whatever locks it needs before calling the filesystem. @@ -231,7 +237,7 @@ Buffered Writes The ``iomap_file_buffered_write`` function writes an ``iocb`` to the pagecache. ``IOMAP_WRITE`` or ``IOMAP_WRITE`` | ``IOMAP_NOWAIT`` will be passed as -the ``flags`` argument to ``->iomap_begin``. +the ``flags`` argument to ``begin``. Callers commonly take ``i_rwsem`` in either shared or exclusive mode before calling this function. @@ -241,7 +247,7 @@ mmap Write Faults The ``iomap_page_mkwrite`` function handles a write fault to a folio in the pagecache. ``IOMAP_WRITE | IOMAP_FAULT`` will be passed as the ``flags`` argument -to ``->iomap_begin``. +to ``begin``. Callers commonly take the mmap ``invalidate_lock`` in shared or exclusive mode before calling this function. @@ -256,7 +262,7 @@ such `reservations `_ because writeback will not consume the reservation. The ``iomap_write_delalloc_release`` can be called from a -``->iomap_end`` function to find all the clean areas of the folios +``end`` function to find all the clean areas of the folios caching a fresh (``IOMAP_F_NEW``) delalloc mapping. It takes the ``invalidate_lock``. @@ -274,7 +280,7 @@ Filesystems can call ``iomap_zero_range`` to perform zeroing of the pagecache for non-truncation file operations that are not aligned to the fsblock size. ``IOMAP_ZERO`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``begin``. Callers typically hold ``i_rwsem`` and ``invalidate_lock`` in exclusive mode before calling this function. @@ -285,7 +291,7 @@ Filesystems can call ``iomap_file_unshare`` to force a file sharing storage with another file to preemptively copy the shared data to newly allocate storage. ``IOMAP_WRITE | IOMAP_UNSHARE`` will be passed as the ``flags`` argument -to ``->iomap_begin``. +to ``begin``. Callers typically hold ``i_rwsem`` and ``invalidate_lock`` in exclusive mode before calling this function. @@ -298,7 +304,7 @@ operation. ``truncate_setsize`` or ``truncate_pagecache`` will take care of everything after the EOF block. ``IOMAP_ZERO`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``begin``. Callers typically hold ``i_rwsem`` and ``invalidate_lock`` in exclusive mode before calling this function. @@ -341,8 +347,8 @@ The fields are as follows: though it will `reuse mappings `_ for runs of contiguous dirty fsblocks within a folio. - Do not return ``IOMAP_INLINE`` mappings here; the ``->iomap_end`` - function must deal with persisting written data. + Do not return ``IOMAP_INLINE`` mappings here; the ``end`` function must + deal with persisting written data. Do not return ``IOMAP_DELALLOC`` mappings here; iomap currently requires mapping to allocated space. Filesystems can skip a potentially expensive mapping lookup if the @@ -428,7 +434,7 @@ writes for files. .. code-block:: c ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops, + iomap_iter_next_fn iomap_next, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before); @@ -511,7 +517,7 @@ Return Values * ``-ENOTBLK``: Fall back to buffered I/O. iomap itself will return this value if it cannot invalidate the page cache before issuing the I/O to storage. - The ``->iomap_begin`` or ``->iomap_end`` functions may also return + The ``begin`` or ``end`` functions may also return this value. * ``-EIOCBQUEUED``: The asynchronous direct I/O request has been @@ -526,7 +532,7 @@ A direct I/O read initiates a read I/O from the storage device to the caller's buffer. Dirty parts of the pagecache are flushed to storage before initiating the read io. -The ``flags`` value for ``->iomap_begin`` will be ``IOMAP_DIRECT`` with +The ``flags`` value for ``begin`` will be ``IOMAP_DIRECT`` with any combination of the following enhancements: * ``IOMAP_NOWAIT``, as defined previously. @@ -542,7 +548,7 @@ caller's buffer. Dirty parts of the pagecache are flushed to storage before initiating the write io. The pagecache is invalidated both before and after the write io. -The ``flags`` value for ``->iomap_begin`` will be ``IOMAP_DIRECT | +The ``flags`` value for ``begin`` will be ``IOMAP_DIRECT | IOMAP_WRITE`` with any combination of the following enhancements: * ``IOMAP_NOWAIT``, as defined previously. @@ -644,7 +650,7 @@ fsdax Reads A fsdax read performs a memcpy from storage device to the caller's buffer. -The ``flags`` value for ``->iomap_begin`` will be ``IOMAP_DAX`` with any +The ``flags`` value for ``begin`` will be ``IOMAP_DAX`` with any combination of the following enhancements: * ``IOMAP_NOWAIT``, as defined previously. @@ -657,7 +663,7 @@ fsdax Writes A fsdax write initiates a memcpy to the storage device from the caller's buffer. -The ``flags`` value for ``->iomap_begin`` will be ``IOMAP_DAX | +The ``flags`` value for ``begin`` will be ``IOMAP_DAX | IOMAP_WRITE`` with any combination of the following enhancements: * ``IOMAP_NOWAIT``, as defined previously. @@ -680,9 +686,9 @@ fsdax mmap Faults The ``dax_iomap_fault`` function handles read and write faults to fsdax storage. For a read fault, ``IOMAP_DAX | IOMAP_FAULT`` will be passed as the -``flags`` argument to ``->iomap_begin``. +``flags`` argument to ``begin``. For a write fault, ``IOMAP_DAX | IOMAP_FAULT | IOMAP_WRITE`` will be -passed as the ``flags`` argument to ``->iomap_begin``. +passed as the ``flags`` argument to ``begin``. Callers commonly hold the same locks as they do to call their iomap pagecache counterparts. @@ -692,8 +698,8 @@ fsdax Truncation, fallocate, and Unsharing For fsdax files, the following functions are provided to replace their iomap pagecache I/O counterparts. -The ``flags`` argument to ``->iomap_begin`` are the same as the -pagecache counterparts, with ``IOMAP_DAX`` added. +The ``flags`` argument to ``begin`` are the same as the pagecache counterparts, +with ``IOMAP_DAX`` added. * ``dax_file_unshare`` * ``dax_zero_range`` @@ -719,8 +725,7 @@ SEEK_DATA The ``iomap_seek_data`` function implements the SEEK_DATA "whence" value for llseek. -``IOMAP_REPORT`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``IOMAP_REPORT`` will be passed as the ``flags`` argument to ``begin``. For unwritten mappings, the pagecache will be searched. Regions of the pagecache with a folio mapped and uptodate fsblocks @@ -734,8 +739,7 @@ SEEK_HOLE The ``iomap_seek_hole`` function implements the SEEK_HOLE "whence" value for llseek. -``IOMAP_REPORT`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``IOMAP_REPORT`` will be passed as the ``flags`` argument to ``begin``. For unwritten mappings, the pagecache will be searched. Regions of the pagecache with no folio mapped, or a !uptodate fsblock @@ -750,8 +754,7 @@ Swap File Activation The ``iomap_swapfile_activate`` function finds all the base-page aligned regions in a file and sets them up as swap space. The file will be ``fsync()``'d before activation. -``IOMAP_REPORT`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``IOMAP_REPORT`` will be passed as the ``flags`` argument to ``begin``. All mappings must be mapped or unwritten; cannot be dirty or shared, and cannot span multiple block devices. Callers must hold ``i_rwsem`` in exclusive mode; this is already @@ -767,8 +770,7 @@ FS_IOC_FIEMAP The ``iomap_fiemap`` function exports file extent mappings to userspace in the format specified by the ``FS_IOC_FIEMAP`` ioctl. -``IOMAP_REPORT`` will be passed as the ``flags`` argument to -``->iomap_begin``. +``IOMAP_REPORT`` will be passed as the ``flags`` argument to ``begin``. Callers commonly hold ``i_rwsem`` in shared mode before calling this function. diff --git a/Documentation/filesystems/iomap/porting.rst b/Documentation/filesystems/iomap/porting.rst index 3d49a32c0fff94..b995f426808a93 100644 --- a/Documentation/filesystems/iomap/porting.rst +++ b/Documentation/filesystems/iomap/porting.rst @@ -50,8 +50,14 @@ Build the kernel, run fstests with the ``-g all`` option across a wide variety of your filesystem's supported configurations to build a baseline of which tests pass and which ones fail. -The recommended approach is first to implement ``->iomap_begin`` (and -``->iomap_end`` if necessary) to allow iomap to obtain a read-only +Every iomap operation is driven by an ``iomap_iter_next_fn`` callback. +Filesystems normally do not write one by hand: implement ``begin`` +(and ``end`` if necessary) and generate the callback with the +``DEFINE_IOMAP_ITER_NEXT()`` macro, or ``DEFINE_IOMAP_ITER_NEXT_END()`` if an +``end`` callback is needed. + +The recommended approach is first to implement ``begin`` (and +``end`` if necessary) to allow iomap to obtain a read-only mapping of a file range. In most cases, this is a relatively trivial conversion of the existing ``get_block()`` function for read-only mappings. @@ -62,7 +68,7 @@ If FIEMAP is returning the correct information, it's a good sign that other read-only mapping operations will do the right thing. Next, modify the filesystem's ``get_block(create = false)`` -implementation to use the new ``->iomap_begin`` implementation to map +implementation to use the new ``begin`` implementation to map file space for selected read operations. Hide behind a debugging knob the ability to switch on the iomap mapping functions for selected call paths. @@ -82,14 +88,14 @@ I/O path because of bufferheads. The buffered read I/O paths doesn't need to be converted yet, though the direct I/O read path should be converted in this phase. -At this point, you should look over your ``->iomap_begin`` function. +At this point, you should look over your ``begin`` function. If it switches between large blocks of code based on dispatching of the ``flags`` argument, you should consider breaking it up into per-operation iomap ops with smaller, more cohesive functions. XFS is a good example of this. The next thing to do is implement ``get_blocks(create == true)`` -functionality in the ``->iomap_begin``/``->iomap_end`` methods. +functionality in the ``begin``/``end`` methods. It is strongly recommended to create separate mapping functions and iomap ops for write operations. Then convert the direct I/O write path to iomap, and start running fsx diff --git a/Documentation/filesystems/nfs/localio.rst b/Documentation/filesystems/nfs/localio.rst index 79808b37d74578..45c6981da0d899 100644 --- a/Documentation/filesystems/nfs/localio.rst +++ b/Documentation/filesystems/nfs/localio.rst @@ -312,6 +312,18 @@ Module Parameters /sys/module/nfs/parameters/localio_enabled (bool) controls if LOCALIO is enabled, defaults to Y. If client and server are local but 'localio_enabled' is set to N then LOCALIO will not be used. +It is checked on every I/O: setting it to N sends the next I/O of every +client over the network, and setting it back to Y resumes LOCALIO. A +client that probed while it was N is probed again when it is set to Y. + +/sys/module/nfs/parameters/localio_timeout (uint) +sets how many seconds the LOCALIO probe waits for each reply from the +server, defaults to 10, at most 600. A server that does not support +LOCALIO may not answer the probe at all. If no reply comes in time, +the probe gives up without a log message. The client then does not use +LOCALIO. The mount's timeouts do not apply to the probe. Set to 0, the +probe uses the mount's timeouts instead, as an NFS RPC would. A change +applies to the next probe. /sys/module/nfs/parameters/localio_O_DIRECT_semantics (bool) controls if O_DIRECT extends down to the underlying filesystem, defaults diff --git a/Documentation/filesystems/overlayfs.rst b/Documentation/filesystems/overlayfs.rst index 16c35b491dad4d..e01f7810c0271e 100644 --- a/Documentation/filesystems/overlayfs.rst +++ b/Documentation/filesystems/overlayfs.rst @@ -236,14 +236,19 @@ Module options (can also be changed through /sys/module/overlay/parameters/): Mount options: - "redirect_dir=on": - Redirects are enabled. + Redirects are created and followed. - "redirect_dir=follow": Redirects are not created, but followed. +- "redirect_dir=followdata": + Redirects are not created. + Only redirects from lower to lowerdata are followed. - "redirect_dir=nofollow": Redirects are not created and not followed. - "redirect_dir=off": - If "redirect_always_follow" is enabled in the kernel/module config, - this "off" translates to "follow", otherwise it translates to "nofollow". + Redirects are not created. + Which redirects are followed depends on "redirect_always_follow" in the + kernel/module config, on data-only lower layers and on the "userxattr" + mount option. When the NFS export feature is enabled, every copied up directory is indexed by the file handle of the lower inode and a file handle of the @@ -418,8 +423,8 @@ pointed by REDIRECT. This should not be possible on local system as setting "trusted." xattrs will require CAP_SYS_ADMIN. But it should be possible for untrusted layers like from a pen drive. -Note: redirect_dir={off|nofollow|follow[*]} and nfs_export=on mount options -conflict with metacopy=on, and will result in an error. +Note: redirect_dir={off|nofollow|followdata|follow[*]} and nfs_export=on +mount options conflict with metacopy=on, and will result in an error. [*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is given. @@ -460,10 +465,11 @@ to the absolute path of the "lower data" file in the "data-only" lower layer. Instead of explicitly enabling "metacopy=on" it is sufficient to specify at least one data-only layer to enable redirection of data to a data-only layer. -In this case other forms of metacopy are rejected. Note: this way, data-only -layers may be used together with "userxattr", in which case careful attention -must be given to privileges needed to change the "user.overlay.redirect" xattr -to prevent misuse. +In this case other forms of metacopy are rejected. A data-only layer selects +"redirect_dir=followdata", unless "redirect_dir=follow" or "redirect_dir=on" is +in effect. Note: this way, data-only layers may be used together with +"userxattr", in which case careful attention must be given to privileges needed +to change the "user.overlay.redirect" xattr to prevent misuse. Since kernel version v6.8, "data-only" lower layers can also be added using the "datadir+" mount options and the fsconfig syscall from new mount api. @@ -731,7 +737,8 @@ When decoding an overlay file handle, the following steps are followed: 1. Find underlying layer by UUID and path type information. 2. Decode the underlying filesystem file handle to underlying dentry. - 3. For a lower file handle, lookup the handle in index directory by name. + 3. For a lower file handle, encode the decoded underlying inode again and + lookup that handle in index directory by name. 4. If a whiteout is found in index, return ESTALE. This represents an overlay object that was deleted after its file handle was encoded. 5. For a non-directory, instantiate a disconnected overlay dentry from the diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst index c38f5df755bb50..e41466904501ae 100644 --- a/Documentation/filesystems/porting.rst +++ b/Documentation/filesystems/porting.rst @@ -1418,7 +1418,7 @@ All struct mnt_idmap pointers handed to filesystems are const now. ->create(), ->mkdir(), ->mknod(), ->symlink(), ->rename(), ->setattr(), ->getattr(), ->permission(), ->tmpfile(), ->get_acl(), ->set_acl() and ->fileattr_set() as well as the xattr ->set() handler and the vfs_*() -helpers take a const struct mnt_idmap *. mnt_idmap() and file_mnt_idmap() +helpers take a ``const struct mnt_idmap *``. mnt_idmap() and file_mnt_idmap() return one. The idmapping is immutable so nothing should have modified it anyway. References are taken and dropped via mnt_idmap_get() and mnt_idmap_put() as before, both accept a const pointer. diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst index b52795e03303f1..2750f2eabf70eb 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -350,12 +350,12 @@ with the following files: "mbm_assign_mode": The supported counter assignment modes. The enclosed brackets indicate which mode is enabled. The MBM events associated with counters may reset when "mbm_assign_mode" - is changed. + is changed. See architecture specific notes below. :: # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode - [mbm_event] - default + [default] + mbm_event "mbm_event": @@ -373,20 +373,17 @@ with the following files: Moving to mbm_event counter assignment mode requires users to assign the counters to the events. Otherwise, the MBM event counters will return 'Unassigned' when read. - The mode is beneficial for AMD platforms that support more CTRL_MON - and MON groups than available hardware counters. By default, this - feature is enabled on AMD platforms with the ABMC (Assignable Bandwidth - Monitoring Counters) capability, ensuring counters remain assigned even - when the corresponding RMID is not actively used by any processor. + It is intended for deployments that need to manage counter assignment on + platforms where the number of monitoring groups exceeds the available + hardware counters. Hardware counters are scarce on these platforms, so + mbm_event mode suits workflows that monitor a subset of groups at a time and + rotate assignments as needed. The mbm_event mode ensures counters remain + assigned even when the corresponding RMID is not actively used. "default": In default mode, resctrl assumes there is a hardware counter for each - event within every CTRL_MON and MON group. On AMD platforms, it is - recommended to use the mbm_event mode, if supported, to prevent reset of MBM - events between reads resulting from hardware re-allocating counters. This can - result in misleading values or display "Unavailable" if no counter is assigned - to the event. + event within every CTRL_MON and MON group. * To enable "mbm_event" counter assignment mode: :: @@ -398,6 +395,24 @@ with the following files: # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + In default mode on AMD platforms that support more CTRL_MON and MON groups + than hardware counters, hardware dynamically shares a smaller pool of + counters among RMIDs. One counter from this pool is used per monitoring + group and counts every MBM event of that group's RMID. The size of the pool + is not enumerated to software (unlike "num_mbm_cntrs"), and "num_rmids" may + be much larger. For example, 64 counters in this pool monitor 64 groups. + Newer hardware may provide a larger pool. + + On such platforms, while the number of monitoring groups does not exceed + that pool, a counter stays attached to each RMID and readings remain + accurate. Creating more groups than the pool can cause hardware to + re-allocate those counters between successive reads of an event. Bandwidth + values may then be misleading, or a read may return "Unavailable" if no + counter is allocated to the RMID. There is no user-visible indication when + this begins. Users who need stable readings beyond that pool should switch + to mbm_event mode, if supported, and assign counters to the groups of + interest (rotating assignments as needed). + "num_mbm_cntrs": The maximum number of counters (total of available and assigned counters) in each domain when the system supports mbm_event mode. @@ -1784,17 +1799,19 @@ View the llc occupancy snapshot:: Examples on working with mbm_assign_mode ======================================== -a. Check if MBM counter assignment mode is supported. +a. Check if MBM counter assignment mode is supported. Enable "mbm_event" +mode. Switching the mbm_assign_mode may reset all the MBM counters (and +thus all MBM events) of all the resctrl groups. :: - # mount -t resctrl resctrl /sys/fs/resctrl/ - + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [default] + mbm_event + # echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event] default -The "mbm_event" mode is detected and enabled. - b. Check how many assignable counters are supported. :: @@ -1805,36 +1822,39 @@ c. Check how many assignable counters are available for assignment in each domai :: # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs - 0=30;1=30 + 0=32;1=32 -d. To list the default group's assign states. +d. To list the default group's assign states. Counters are unassigned when the mode +is switched to "mbm_event". :: # cat /sys/fs/resctrl/mbm_L3_assignments - mbm_total_bytes:0=e;1=e - mbm_local_bytes:0=e;1=e + mbm_total_bytes:0=_;1=_ + mbm_local_bytes:0=_;1=_ -e. To unassign the counter associated with the mbm_total_bytes event on domain 0. +e. To assign the counter associated with the mbm_total_bytes event on domain 0 +in exclusive mode. :: - # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments + # echo "mbm_total_bytes:0=e" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments - mbm_total_bytes:0=_;1=e - mbm_local_bytes:0=e;1=e + mbm_total_bytes:0=e;1=_ + mbm_local_bytes:0=_;1=_ f. To unassign the counter associated with the mbm_total_bytes event on all domains. :: # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments - # cat /sys/fs/resctrl/mbm_L3_assignment + # cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=_;1=_ - mbm_local_bytes:0=e;1=e + mbm_local_bytes:0=_;1=_ -g. To assign a counter associated with the mbm_total_bytes event on all domains in -exclusive mode. +g. To assign a counter associated with the mbm_total_bytes and mbm_local_bytes +events on all domains in exclusive mode. :: # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments + # echo "mbm_local_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=e;1=e mbm_local_bytes:0=e;1=e @@ -1891,13 +1911,8 @@ the MBM counters (and thus all MBM events) of all the resctrl groups. # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode - mbm_event [default] - -m. Unmount the resctrl filesystem. -:: - - # umount /sys/fs/resctrl/ + mbm_event Intel RDT Errata ================ diff --git a/Documentation/hwmon/asus_rog_ryujin.rst b/Documentation/hwmon/asus_rog_ryujin.rst index 3ebab230e8cafa..fe072e94d87b12 100644 --- a/Documentation/hwmon/asus_rog_ryujin.rst +++ b/Documentation/hwmon/asus_rog_ryujin.rst @@ -34,6 +34,12 @@ Usage notes As these are USB HIDs, the driver can be loaded automatically by the kernel and supports hot swapping. +The pump of the RYUJIN III also has a 4-pin cable for a motherboard fan header. +The cooler either hands the pump to its internal controller, which follows the +PWM of the header its 4-pin cable is plugged into, or runs it at the pump duty +set over USB. Writing pwm1 selects the duty set over USB. Writing pwm2 sets +only the internal fan duty and leaves the pump control as it is. + Sysfs entries ------------- diff --git a/Documentation/mm/vmemmap_dedup.rst b/Documentation/mm/vmemmap_dedup.rst index 8c287ae3f86cc8..5e792b7a27f078 100644 --- a/Documentation/mm/vmemmap_dedup.rst +++ b/Documentation/mm/vmemmap_dedup.rst @@ -130,8 +130,19 @@ pages of ``struct page`` (page 1 to page 7) are tail pages. The optimization is only applied when the size of the struct page is a power of 2. In this case, all tail pages of the same order are identical. See compound_head(). This allows us to remap the tail pages of the vmemmap to a -shared, read-only page. The head page is also remapped to a new page. This -allows the original vmemmap pages to be freed. +shared page. The head page is also remapped to a new page. This allows the +original vmemmap pages to be freed. + +The shared page is mapped writable. A lockless get of a page reference can +read a non-zero refcount before the remap and attempt its atomic update +after it. The refcount of a tail page is zero, so the update fails without +changing the page. Nothing else may write to the shared page: it is shared +by all HugeTLB pages of the same size in the zone, and a stray write would +corrupt all of them. + +HugeTLB pages whose vmemmap is optimized when the memmap is first set up at +boot keep a read-only mapping of the shared page. Nothing can do a lockless +get on them before they are handed to HugeTLB. Here is how things look after remapping:: diff --git a/Documentation/networking/can.rst b/Documentation/networking/can.rst index 536ff411da1d10..51bc70748f753c 100644 --- a/Documentation/networking/can.rst +++ b/Documentation/networking/can.rst @@ -1040,17 +1040,21 @@ As described in :ref:`socketcan-receive-lists` the SocketCAN core uses several f lists to deliver received CAN frames to CAN protocol modules. These receive lists, their filters and the count of filter matches can be checked in the appropriate receive list. All entries contain the -device and a protocol module identifier:: +CAN network device, the filter (can_id/can_mask), the number of filter +matches, the inode number of the subscribing socket and the name of the +receive function. A sock_inode of 0 denotes a kernel internal subscriber +without a socket (e.g. CAN gateway or J1939). When the function name can +not be resolved (e.g. with CONFIG_KALLSYMS=n) "(unknown)" is printed:: foo@bar:~$ cat /proc/net/can/rcvlist_all receive list 'rx_all': - (vcan3: no entry) - (vcan2: no entry) - (vcan1: no entry) - device can_id can_mask function userdata matches ident - vcan0 000 00000000 f88e6370 f6c6f400 0 raw (any: no entry) + device can_id can_mask matches sock_inode function + vcan0 000 00000000 0 63586 raw_rcv [can_raw] + (vcan1: no entry) + (vcan2: no entry) + (vcan3: no entry) In this example an application requests any CAN traffic from vcan0:: diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index 93c85b621ec2cf..554e8c14a401f2 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -107,6 +107,7 @@ u32[3] received_ecn_bytes read_mostly read_w u8:4 received_ce_pending read_mostly read_write u32[3] delivered_ecn_bytes read_write u16 pkts_acked_ewma read_write +u32 rcv_collapse_credit read_write tcp_queue_rcv,tcp_data_queue_ofo,tcp_prune_queue u8:2 syn_ect_snt write_mostly read_write u8:2 syn_ect_rcv read_mostly read_write u8:2 accecn_minlen write_mostly read_write diff --git a/Documentation/networking/xfrm/xfrm_migrate_state.rst b/Documentation/networking/xfrm/xfrm_migrate_state.rst index 9d53cb22b00752..ca2c9e5aaf33aa 100644 --- a/Documentation/networking/xfrm/xfrm_migrate_state.rst +++ b/Documentation/networking/xfrm/xfrm_migrate_state.rst @@ -27,15 +27,20 @@ SA Identification ================= The struct is defined in ``include/uapi/linux/xfrm.h``. The SA is looked -up using ``xfrm_state_lookup()`` with ``id.spi``, -``id.daddr``, ``id.proto``, ``id.family``, and -``old_mark.v & old_mark.m`` as the mark key:: +up using ``xfrm_state_lookup_exact()`` with ``id.spi``, ``id.daddr``, +``id.proto``, ``id.family``, and an exact match against ``old_mark.v`` +and ``old_mark.m``. Unlike the data path, which uses a masked +comparison, this requires the SA's mark and mask to equal ``old_mark`` +exactly, so a broad-mask SA is never matched when a more specific one +was intended. If no such SA exists, ``-ESRCH`` is returned. + +The layout is:: struct xfrm_user_migrate_state { struct xfrm_usersa_id id; /* spi, daddr, proto, family */ xfrm_address_t new_daddr; xfrm_address_t new_saddr; - struct xfrm_mark old_mark; /* SA lookup: key = v & m */ + struct xfrm_mark old_mark; /* SA lookup key (exact v/m match) */ struct xfrm_selector new_sel; /* new selector (see Flags) */ __u32 new_reqid; __u32 flags; /* XFRM_MIGRATE_STATE_* */ @@ -72,8 +77,8 @@ inherits the value from the existing SA (omit-to-inherit). - Description * - ``XFRMA_MARK`` - Mark on the migrated SA (``struct xfrm_mark``). Absent inherits - ``old_mark``. To use no mark on the new SA, send ``XFRMA_MARK`` - with ``{0, 0}``. + the mark of the existing SA. To use no mark on the new SA, send + ``XFRMA_MARK`` with ``{0, 0}``. * - ``XFRMA_ENCAP`` - UDP encapsulation template; only ``UDP_ENCAP_ESPINUDP`` is supported. Set ``encap_type=0`` to remove encap. @@ -259,8 +264,12 @@ Attributes in the notification Error Handling ============== -If the target SA tuple (new daddr, SPI, proto, new family) is already -occupied, the operation returns ``-EEXIST`` before the migration begins. +If the target SA tuple (new daddr, SPI, proto, new family, mark) is +already occupied, the operation returns ``-EEXIST`` before the migration +begins. "Occupied" includes wildcard shadowing: an existing SA with a +broader mask (e.g. mark 0/0) claims every mark value, so it blocks +migrating to any more specific mark at the same tuple, not just an +exact mark/mask duplicate. The old SA remains intact and the operation is safe to retry after resolving the conflict. diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst index 40a5c23d525966..f4723ad6e78df4 100644 --- a/Documentation/power/runtime_pm.rst +++ b/Documentation/power/runtime_pm.rst @@ -222,11 +222,12 @@ what to do to handle the device). I/O operations as needed. The runtime PM status of the device is then 'active'. - * If the resume callback returns an error code, the PM core regards this as a - fatal error and will refuse to run the helper functions described in - `Section 4`_ for the device, until its status is directly set to either - 'active', or 'suspended' (by means of special helper functions provided by - the PM core for this purpose). + * If the resume callback returns an error code, the PM core sets the + device's runtime PM status back to 'suspended' and returns the error + code from synchronous resume helpers. Unlike most suspend callback + errors, failures in the resume callback are never considered fatal, + so the helper functions described in `Section 4`_ are not blocked and + a subsequent resume request can run the resume callback again. The idle callback (a subsystem-level one, if present, or the driver one) is executed by the PM core whenever the device appears to be idle, which is @@ -250,9 +251,9 @@ call to pm_runtime_autosuspend(). To prevent this suspension (for example, if the callback routine has scheduled a delayed suspend or determined the device cannot be idle), the routine must return a non-zero value (typically -EBUSY or -EAGAIN). Unlike -->runtime_suspend() and ->runtime_resume(), the PM core does not treat negative -return codes from ->runtime_idle() as a fatal device error; any non-zero value -simply stops the PM core from suspending the device. +->runtime_suspend(), the PM core does not treat negative return codes from +->runtime_idle() as a fatal device error, and any non-zero value simply stops +the PM core from suspending the device. Core Guarantees and Synchronization Rules ----------------------------------------- diff --git a/Documentation/process/maintainer-netdev.rst b/Documentation/process/maintainer-netdev.rst index df220a9654387a..f7945f30cede81 100644 --- a/Documentation/process/maintainer-netdev.rst +++ b/Documentation/process/maintainer-netdev.rst @@ -315,6 +315,10 @@ reproducer and against kernel selftests. If the bug is in a hardware driver, the testing statement must include information about the HW on which the fix was tested. +Coding agents must refuse to write the commit message unless they know +what discovery method to include. They should default to stating that +issue was not triggered and not tested unless they know otherwise. + Stable tree ~~~~~~~~~~~ @@ -363,6 +367,41 @@ to the mailing list, e.g.:: Posting as one thread is discouraged because it confuses patchwork (as of patchwork 2.2.2). +Co-posting iproute2 patches +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The official git repositories for iproute2 are: + +- iproute2: https://git.kernel.org/pub/scm/network/iproute2/iproute2.git +- iproute2-next: https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git + +Patches for iproute2 must have a subject prefix of ``[PATCH iproute2]`` +or ``[PATCH iproute2-next]`` to indicate the target repository where the +patch should be applied. If kernel changes target net-next or bpf-next, +then the related iproute2 changes need to target iproute2-next, else they +must target iproute2. The iproute2-next tree will be merged into the +iproute2 tree after the current iproute2 version has been released. + +Patches are tracked in patchwork under the netdevbpf project. iproute2 +patches are delegated to 'shemminger' (Stephen Hemminger), iproute2-next +patches to 'dsa' (David Ahern): + +- iproute2: https://patchwork.kernel.org/project/netdevbpf/list/?delegate=7961&state=* +- iproute2-next: https://patchwork.kernel.org/project/netdevbpf/list/?delegate=123859&state=* + +Send patches to netdev@vger.kernel.org and always include the iproute2 +maintainers in the email Cc: list. See the MAINTAINERS file in the +repository for email addresses and other details: + + https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/MAINTAINERS + +For patches that target iproute2's BPF loader, also include +bpf@vger.kernel.org and the BPF maintainers. + +For more information, see also README.devel in the repository: + + https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/README.devel + Co-posting selftests ~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/sound/cards/pcmtest.rst b/Documentation/sound/cards/pcmtest.rst index e163522f32055a..351f1123b8e717 100644 --- a/Documentation/sound/cards/pcmtest.rst +++ b/Documentation/sound/cards/pcmtest.rst @@ -16,25 +16,30 @@ At this moment the driver can do the following things: * Generate random or pattern-based capturing data * Inject delays into the playback and capturing processes * Inject errors during the PCM callbacks + * Pause the streams + * Report wrong change results from a mixer control It supports up to 8 substreams and 4 channels. Also it supports both interleaved and non-interleaved access modes. Also, this driver can check the playback stream for containing the predefined pattern, -which is used in the corresponding selftest (alsa/pcmtest-test.sh) to check the PCM middle -layer data transferring functionality. Additionally, this driver redefines the default -RESET ioctl, and the selftest covers this PCM API functionality as well. +which is used in the corresponding selftest (alsa/test-pcmtest-driver.c) to check the PCM +middle layer data transferring functionality. Additionally, this driver redefines the +default RESET ioctl, and the selftest covers this PCM API functionality as well. Configuration ------------- The driver has several parameters besides the common ALSA module parameters: - * fill_mode (bool) - Buffer fill mode (see below) + * fill_mode (short) - Buffer fill mode (see below) * inject_delay (int) + * inject_open_err (bool) * inject_hwpars_err (bool) * inject_prepare_err (bool) * inject_trigger_err (bool) + * inject_ctl_no_event (bool) + * inject_ctl_spurious_event (bool) Capture Data Generation @@ -93,10 +98,22 @@ writing '1' to the 'inject_hwpars_err' module parameter: Errors can be injected into the following PCM callbacks: + * open (EBUSY) * hw_params (EBUSY) * prepare (EINVAL) * trigger (EINVAL) +Control event injection +----------------------- + +The driver has a 'Test Playback Volume' control. Its 'put' callback reports a change +only when the value changes, so a change event is sent only then. + +With 'inject_ctl_no_event' set, the callback reports no change, and no event is sent +even when the value changes. With 'inject_ctl_spurious_event' set, it reports a change +on every accepted write. The mixer-test selftest (alsa/mixer-test.c) checks for both. +If both parameters are set, 'inject_ctl_no_event' wins. + Playback test ------------- diff --git a/Documentation/sound/codecs/cs35l56.rst b/Documentation/sound/codecs/cs35l56.rst index ffbfbaed127144..391d9dc7bd22f2 100644 --- a/Documentation/sound/codecs/cs35l56.rst +++ b/Documentation/sound/codecs/cs35l56.rst @@ -50,7 +50,7 @@ DSP. Firmware files are essential to enable the full capabilities of the amplifier. Firmware is distributed in the linux-firmware repository: -https://gitlab.com/kernel-firmware/linux-firmware.git +https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/ On most SoundWire systems the amplifier has a default minimum capability to produce audio. However this will be diff --git a/Documentation/trace/events-landlock.rst b/Documentation/trace/events-landlock.rst index 9ccf2769a2d5e4..dc5f05a17c2ccd 100644 --- a/Documentation/trace/events-landlock.rst +++ b/Documentation/trace/events-landlock.rst @@ -187,8 +187,9 @@ therefore appears as zero while still advancing the ruleset version, and adding a member already present still emits an event. ``landlock_deny_permission_namespace`` reports the denied raw -``CLONE_NEW*`` value. ``namespace_id`` is zero for namespace creation and is -the exact target namespace ID for :manpage:`setns(2)`. +``CLONE_NEW*`` value. ``namespace_id`` is the exact target namespace ID. For +a denied namespace creation, the namespace never becomes reachable so its ID +is not directly visible from user space. ``landlock_deny_permission_capability`` reports the denied ``CAP_*`` number. Like every denial event, both include the denying domain, ``same_exec``, and ``logged``. diff --git a/Documentation/trace/fprobe.rst b/Documentation/trace/fprobe.rst index 46dd46a97c1f98..72e0fd9e180892 100644 --- a/Documentation/trace/fprobe.rst +++ b/Documentation/trace/fprobe.rst @@ -101,6 +101,11 @@ handler. If the entry callback function returns !0, the corresponding exit callback will be cancelled. +Since the callbacks run with preemption disabled under ftrace recursion +protection, calling printk() or pr_*() from these callbacks is not safe +and can cause deadlocks on console driver or scheduler locks. Use +trace_printk() instead to log debugging output. + @fp This is the address of `fprobe` data structure related to this handler. You can embed the `fprobe` to your data structure and get it by diff --git a/Documentation/trace/kprobes.rst b/Documentation/trace/kprobes.rst index 5e606730cec633..91b76ed435b152 100644 --- a/Documentation/trace/kprobes.rst +++ b/Documentation/trace/kprobes.rst @@ -31,7 +31,7 @@ can trap at almost any kernel code address [1]_, specifying a handler routine to be invoked when the breakpoint is hit. .. [1] some parts of the kernel code can not be trapped, see - :ref:`kprobes_blacklist`) + :ref:`kprobes_blacklist` There are currently two types of probes: kprobes, and kretprobes (also called return probes). A kprobe can be inserted on virtually @@ -563,8 +563,8 @@ course, has no way to distinguish the deliberately injected faults from the accidental ones. Don't drink and probe. Kprobes makes no attempt to prevent probe handlers from stepping on -each other -- e.g., probing printk() and then calling printk() from a -probe handler. If a probe handler hits a probe, that second probe's +each other -- e.g., probing trace_printk() and then calling trace_printk() +from a probe handler. If a probe handler hits a probe, that second probe's handlers won't be run in that instance, and the kprobe.nmissed member of the second probe will be incremented. @@ -579,6 +579,13 @@ which depends on the architecture and optimization state. (e.g., kretprobe handlers and optimized kprobe handlers run without interrupt disabled on x86/x86-64). In any case, your handler should not yield the CPU (e.g., by attempting to acquire a semaphore, or waiting I/O). +Furthermore, probe handlers should avoid calling printk() or pr_*(). +Because probe handlers execute in atomic/non-preemptible contexts without +being in NMI context (especially when jump-optimized or ftrace-based), +calling printk() may attempt to synchronously acquire console driver locks +or scheduler locks via console_unlock(), risking a deadlock if the probed +or interrupted context already holds those locks. Use trace_printk() +instead to safely output messages to the trace buffer. Since a return probe is implemented by replacing the return address with the trampoline's address, stack backtraces and calls diff --git a/MAINTAINERS b/MAINTAINERS index 93abbb315065de..d37ed235d5141a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4484,6 +4484,7 @@ AUXILIARY BUS DRIVER M: Greg Kroah-Hartman M: "Rafael J. Wysocki" M: Danilo Krummrich +M: Johan Hovold R: Dave Ertman R: Ira Weiny R: Leon Romanovsky @@ -6868,11 +6869,13 @@ R: Muchun Song L: cgroups@vger.kernel.org L: linux-mm@kvack.org S: Maintained +F: Documentation/admin-guide/cgroup-v1/memory.rst F: include/linux/memcontrol.h F: include/linux/page_counter.h -F: mm/memcontrol.c +F: include/trace/events/memcg.h F: mm/memcontrol-v1.c F: mm/memcontrol-v1.h +F: mm/memcontrol.c F: mm/page_counter.c F: samples/cgroup/* F: tools/testing/selftests/cgroup/memcg_protection.m @@ -7836,7 +7839,7 @@ W: http://www.win.tue.nl/~aeb/linux/zip/zip-1.html W: http://www.win.tue.nl/~aeb/partitions/partition_types-1.html DISKQUOTA -M: Jan Kara +M: Jan Kara S: Maintained F: Documentation/filesystems/quota.rst F: fs/quota/ @@ -8359,6 +8362,7 @@ F: drivers/gpu/drm/tiny/hx8357d.c DRM DRIVER FOR HYPERV SYNTHETIC VIDEO DEVICE M: Dexuan Cui +M: Hamza Mahfooz M: Saurabh Sengar L: linux-hyperv@vger.kernel.org L: dri-devel@lists.freedesktop.org @@ -10107,7 +10111,7 @@ F: drivers/leds/leds-expresswire.c F: include/linux/leds-expresswire.h EXT2 FILE SYSTEM -M: Jan Kara +M: Jan Kara L: linux-ext4@vger.kernel.org S: Maintained F: Documentation/filesystems/ext2.rst @@ -11693,10 +11697,10 @@ S: Maintained F: block/partitions/efi.* HABANALABS PCI DRIVER -M: Koby Elbaz -M: Konstantin Sinyuk +M: Konstantin Sinyuk +M: Koby Elbaz L: dri-devel@lists.freedesktop.org -S: Supported +S: Maintained C: irc://irc.oftc.net/dri-devel T: git https://github.com/HabanaAI/drivers.accel.habanalabs.kernel.git F: Documentation/ABI/testing/debugfs-driver-habanalabs @@ -12376,6 +12380,7 @@ R: David Hildenbrand L: linux-mm@kvack.org S: Maintained F: Documentation/ABI/testing/sysfs-kernel-mm-hugepages +F: Documentation/admin-guide/cgroup-v1/hugetlb.rst F: Documentation/admin-guide/mm/hugetlbpage.rst F: Documentation/mm/hugetlbfs_reserv.rst F: Documentation/mm/vmemmap_dedup.rst @@ -12387,6 +12392,7 @@ F: mm/hugetlb.c F: mm/hugetlb_cgroup.c F: mm/hugetlb_cma.c F: mm/hugetlb_cma.h +F: mm/hugetlb_internal.h F: mm/hugetlb_sysctl.c F: mm/hugetlb_sysfs.c F: mm/hugetlb_vmemmap.c @@ -12406,6 +12412,7 @@ M: Miaohe Lin R: Naoya Horiguchi L: linux-mm@kvack.org S: Maintained +F: Documentation/ABI/testing/sysfs-memory-page-offline F: include/linux/memory-failure.h F: include/trace/events/memory-failure.h F: mm/hwpoison-inject.c @@ -14070,6 +14077,16 @@ S: Maintained F: io_uring/bpf-ops.* F: io_uring/loop.* +IPC +M: Andrew Morton +R: Manfred Spraul +R: Davidlohr Bueso +L: linux-kernel@vger.kernel.org +S: Maintained +F: ipc/ +F: tools/testing/selftests/ipc/ +F: tools/testing/selftests/mqueue/ + IPMI SUBSYSTEM M: Corey Minyard L: openipmi-developer@lists.sourceforge.net (moderated for non-subscribers) @@ -14309,7 +14326,7 @@ F: include/uapi/linux/jffs2.h JOURNALLING LAYER FOR BLOCK DEVICES (JBD2) M: "Theodore Ts'o" -M: Jan Kara +M: Jan Kara L: linux-ext4@vger.kernel.org S: Maintained F: fs/jbd2/ @@ -14415,7 +14432,6 @@ M: Baoquan He M: Mike Rapoport M: Pasha Tatashin M: Pratyush Yadav -R: Dave Young L: kexec@lists.infradead.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git @@ -17456,21 +17472,6 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git F: drivers/devfreq/tegra30-devfreq.c -MEMORY HOT(UN)PLUG -M: David Hildenbrand -M: Oscar Salvador -L: linux-mm@kvack.org -L: linux-cxl@vger.kernel.org -S: Maintained -F: Documentation/admin-guide/mm/memory-hotplug.rst -F: Documentation/core-api/memory-hotplug.rst -F: drivers/base/memory.c -F: include/linux/memory_hotplug.h -F: include/linux/memremap.h -F: mm/memremap.c -F: mm/memory_hotplug.c -F: tools/testing/selftests/memory-hotplug/ - MEMORY MANAGEMENT M: Andrew Morton L: linux-mm@kvack.org @@ -17494,18 +17495,15 @@ F: mm/alloc_tag.c F: tools/testing/selftests/alloc_tag/ MEMORY MANAGEMENT - BALLOON -M: Andrew Morton M: David Hildenbrand L: linux-mm@kvack.org L: virtualization@lists.linux.dev S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: include/linux/balloon.h F: mm/balloon.c MEMORY MANAGEMENT - CORE -M: Andrew Morton M: David Hildenbrand R: Lorenzo Stoakes R: Liam R. Howlett @@ -17515,27 +17513,34 @@ R: Suren Baghdasaryan R: Michal Hocko L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: Documentation/admin-guide/sysctl/vm.rst +F: Documentation/core-api/gfp_mask-from-fs-io.rst +F: fs/proc/meminfo.c +F: include/linux/cacheflush.h F: include/linux/folio_batch.h F: include/linux/gfp.h F: include/linux/gfp_types.h +F: include/linux/highmem-internal.h F: include/linux/highmem.h F: include/linux/leafops.h F: include/linux/memory.h F: include/linux/mm.h F: include/linux/mm_*.h -F: include/linux/mmzone.h F: include/linux/mmdebug.h F: include/linux/mmu_notifier.h +F: include/linux/mmzone.h F: include/linux/pagewalk.h +F: include/linux/pfn.h F: include/linux/pgalloc.h F: include/linux/pgtable.h F: include/linux/ptdump.h +F: include/linux/sched/mm.h +F: include/linux/vm_event_item.h F: include/linux/vmpressure.h F: include/linux/vmstat.h -F: fs/proc/meminfo.c +F: include/trace/events/mmflags.h +F: include/trace/events/pagemap.h F: kernel/fork.c F: mm/Kconfig F: mm/debug.c @@ -17554,6 +17559,7 @@ F: mm/ptdump.c F: mm/util.c F: mm/vmpressure.c F: mm/vmstat.c +F: scripts/gdb/linux/mm.py N: include\/linux\/page[-_][a-zA-Z]* MEMORY MANAGEMENT - EXECMEM @@ -17565,15 +17571,14 @@ F: include/linux/execmem.h F: mm/execmem.c MEMORY MANAGEMENT - GUP (GET USER PAGES) -M: Andrew Morton M: David Hildenbrand R: Jason Gunthorpe R: John Hubbard R: Peter Xu L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next +F: Documentation/core-api/pin_user_pages.rst F: mm/gup.c F: mm/gup_test.c F: mm/gup_test.h @@ -17582,14 +17587,12 @@ F: tools/testing/selftests/mm/gup.c F: tools/testing/selftests/mm/gup_longterm.c MEMORY MANAGEMENT - KSM (Kernel Samepage Merging) -M: Andrew Morton M: David Hildenbrand R: Xu Xin R: Chengming Zhou L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: Documentation/ABI/testing/sysfs-kernel-mm-ksm F: Documentation/admin-guide/mm/ksm.rst F: Documentation/mm/ksm.rst @@ -17598,13 +17601,30 @@ F: include/trace/events/ksm.h F: mm/ksm.c F: mm/mm_slot.h +MEMORY MANAGEMENT - MEMORY HOT(UN)PLUG +M: David Hildenbrand +M: Oscar Salvador +L: linux-mm@kvack.org +L: linux-cxl@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next +F: Documentation/ABI/testing/sysfs-devices-memory +F: Documentation/admin-guide/mm/memory-hotplug.rst +F: Documentation/core-api/memory-hotplug.rst +F: drivers/base/memory.c +F: include/linux/memory_hotplug.h +F: include/linux/memremap.h +F: mm/memory_hotplug.c +F: mm/memremap.c +F: tools/testing/selftests/memory-hotplug/ + MEMORY MANAGEMENT - MEMORY MAP M: Muchun Song M: Mike Rapoport M: David Hildenbrand L: linux-mm@kvack.org S: Maintained -T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git memmap +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: Documentation/mm/memory-model.rst F: arch/*/include/asm/sparsemem.h F: include/asm-generic/memory_model.h @@ -17636,7 +17656,6 @@ F: mm/vmscan.c F: mm/workingset.c MEMORY MANAGEMENT - MIGRATION -M: Andrew Morton M: David Hildenbrand R: Zi Yan R: Matthew Brost @@ -17647,10 +17666,10 @@ R: Ying Huang R: Alistair Popple L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: include/linux/migrate.h F: include/linux/migrate_mode.h +F: include/trace/events/migrate.h F: mm/migrate.c F: mm/migrate_device.c @@ -17674,15 +17693,20 @@ F: Documentation/admin-guide/mm/ F: Documentation/core-api/memory-allocation.rst F: Documentation/core-api/mm-api.rst F: Documentation/mm/ -X: Documentation/admin-guide/mm/damon/ -X: Documentation/mm/damon/ -F: mm/char-mem.c +F: fs/proc/page.c +F: include/linux/backing-dev-defs.h +F: include/linux/backing-dev.h F: include/linux/cma.h F: include/linux/dmapool.h F: include/linux/ioremap.h +F: include/linux/kernel-page-flags.h F: include/linux/page_idle.h +F: include/trace/events/cma.h +F: include/uapi/linux/kernel-page-flags.h F: mm/backing-dev.c +F: mm/char-mem.c F: mm/cma.c +F: mm/cma.h F: mm/cma_debug.c F: mm/cma_sysfs.c F: mm/dmapool.c @@ -17695,7 +17719,11 @@ F: mm/page_idle.c F: mm/pgalloc-track.h F: mm/process_vm_access.c F: tools/lib/mm/ +F: tools/mm/ F: tools/testing/selftests/mm/ +X: Documentation/ABI/testing/sysfs-kernel-mm-damon +X: Documentation/admin-guide/mm/damon/ +X: Documentation/mm/damon/ MEMORY MANAGEMENT - NUMA MEMBLOCKS AND NUMA EMULATION M: Andrew Morton @@ -17703,13 +17731,13 @@ M: Mike Rapoport L: linux-mm@kvack.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock.git +F: include/linux/numa.h F: include/linux/numa_memblks.h F: mm/numa.c F: mm/numa_emulation.c F: mm/numa_memblks.c MEMORY MANAGEMENT - NUMA PLACEMENT -M: Andrew Morton M: David Hildenbrand M: Gregory Price R: Zi Yan @@ -17718,11 +17746,11 @@ R: Rakie Kim R: Ying Huang L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy-weighted-interleave +F: Documentation/admin-guide/numastat.rst F: include/linux/memory-tiers.h F: include/linux/mempolicy.h F: include/uapi/linux/mempolicy.h @@ -17741,19 +17769,22 @@ F: include/uapi/linux/oom.h F: mm/oom_kill.c MEMORY MANAGEMENT - PAGE ALLOCATOR -M: Andrew Morton M: Vlastimil Babka +M: Johannes Weiner R: Suren Baghdasaryan R: Michal Hocko R: Brendan Jackman -R: Johannes Weiner R: Zi Yan L: linux-mm@kvack.org S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/page_alloc.git page_alloc/for-next F: include/linux/compaction.h F: include/linux/gfp.h F: include/linux/page-isolation.h F: include/linux/pageblock-flags.h +F: include/trace/events/compaction.h +F: include/trace/events/page_isolation.h +F: include/trace/events/page_ref.h F: mm/compaction.c F: mm/debug_page_alloc.c F: mm/debug_page_ref.c @@ -17770,6 +17801,9 @@ F: mm/page_reporting.h F: mm/show_mem.c F: mm/shuffle.c F: mm/shuffle.h +F: scripts/gdb/linux/page_owner.py +F: tools/mm/page_owner_filter.c +F: tools/mm/page_owner_sort.c MEMORY MANAGEMENT - RECLAIM M: Andrew Morton @@ -17781,11 +17815,11 @@ R: Shakeel Butt R: Lorenzo Stoakes L: linux-mm@kvack.org S: Maintained +F: include/trace/events/vmscan.h F: mm/vmscan.c F: mm/workingset.c MEMORY MANAGEMENT - RMAP (REVERSE MAPPING) -M: Andrew Morton M: David Hildenbrand M: Lorenzo Stoakes R: Rik van Riel @@ -17796,6 +17830,7 @@ R: Jann Horn R: Lance Yang L: linux-mm@kvack.org S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: include/linux/rmap.h F: mm/interval_tree.c F: mm/page_vma_mapped.c @@ -17810,6 +17845,54 @@ S: Maintained F: include/linux/secretmem.h F: mm/secretmem.c +MEMORY MANAGEMENT - SHARED MEMORY (SHMEM/TMPFS/MEMFD) +M: Hugh Dickins +M: David Hildenbrand +R: Baolin Wang +L: linux-mm@kvack.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next +F: Documentation/filesystems/tmpfs.rst +F: Documentation/mm/shmfs.rst +F: Documentation/userspace-api/mfd_noexec.rst +F: include/linux/memfd.h +F: include/linux/shmem_fs.h +F: include/uapi/linux/memfd.h +F: mm/memfd.c +F: mm/shmem.c +F: mm/shmem_quota.c +F: tools/testing/selftests/memfd/ +F: tools/testing/selftests/tmpfs/ + +MEMORY MANAGEMENT - SLAB ALLOCATOR +M: Vlastimil Babka +M: Harry Yoo +R: Hao Li +R: Christoph Lameter +R: David Rientjes +R: Roman Gushchin +L: linux-mm@kvack.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/slab.git slab/for-next +F: Documentation/ABI/testing/sysfs-kernel-slab +F: Documentation/admin-guide/mm/slab.rst +F: Documentation/mm/slab.rst +F: include/linux/mempool.h +F: include/linux/slab.h +F: include/trace/events/kmem.h +F: lib/tests/slub_kunit.c +F: mm/failslab.c +F: mm/mempool.c +F: mm/slab.h +F: mm/slab_common.c +F: mm/slub.c +F: scripts/gdb/linux/slab.py +F: tools/cgroup/memcg_slabinfo.py +F: tools/include/linux/slab.h +F: tools/lib/slab.c +F: tools/mm/slabinfo-gnuplot.sh +F: tools/mm/slabinfo.c + MEMORY MANAGEMENT - SWAP M: Andrew Morton M: Chris Li @@ -17829,14 +17912,13 @@ F: include/linux/swapfile.h F: include/linux/swapops.h F: mm/page_io.c F: mm/swap.h -F: mm/swap_table.h F: mm/swap_state.c +F: mm/swap_table.h F: mm/swapfile.c MEMORY MANAGEMENT - THP (TRANSPARENT HUGE PAGE) -M: Andrew Morton M: David Hildenbrand -R: Zi Yan +M: Zi Yan R: Baolin Wang R: Liam R. Howlett R: Nico Pache @@ -17848,17 +17930,18 @@ R: Usama Arif R: Kiryl Shutsemau L: linux-mm@kvack.org S: Maintained -W: http://www.linux-mm.org -T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next F: Documentation/ABI/testing/sysfs-kernel-mm-transparent-hugepage F: Documentation/admin-guide/mm/transhuge.rst F: include/linux/huge_mm.h F: include/linux/khugepaged.h F: include/trace/events/huge_memory.h +F: include/trace/events/thp.h F: mm/collapse.h F: mm/huge_memory.c F: mm/khugepaged.c F: mm/mm_slot.h +F: tools/mm/thpmaps F: tools/testing/selftests/mm/khugepaged.c F: tools/testing/selftests/mm/split_huge_page_test.c F: tools/testing/selftests/mm/transhuge-stress.c @@ -17902,10 +17985,16 @@ L: linux-mm@kvack.org S: Maintained W: http://www.linux-mm.org T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm -F: mm/char-mem.c -F: include/trace/events/mmap.h +F: Documentation/core-api/protection-keys.rst +F: Documentation/filesystems/mmap_prepare.rst +F: Documentation/userspace-api/mseal.rst F: fs/proc/task_mmu.c F: fs/proc/task_nommu.c +F: include/linux/mman.h +F: include/linux/pkeys.h +F: include/trace/events/mmap.h +F: include/uapi/linux/mman.h +F: mm/char-mem.c F: mm/mincore.c F: mm/mlock.c F: mm/mmap.c @@ -18224,6 +18313,7 @@ F: drivers/net/phy/microchip_t1.c MICROCHIP LAN966X ETHERNET DRIVER M: Horatiu Vultur +M: Daniel Machon M: UNGLinuxDriver@microchip.com L: netdev@vger.kernel.org S: Maintained @@ -18743,6 +18833,7 @@ M: Peter Zijlstra L: linux-arch@vger.kernel.org L: linux-mm@kvack.org S: Maintained +F: Documentation/core-api/cachetlb.rst F: arch/*/include/asm/tlb.h F: include/asm-generic/tlb.h F: include/trace/events/tlb.h @@ -19544,7 +19635,9 @@ M: Steffen Klassert M: Herbert Xu M: "David S. Miller" L: netdev@vger.kernel.org +L: ipsec@lists.linux.dev S: Maintained +Q: https://patchwork.kernel.org/project/ipsec/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git F: Documentation/networking/xfrm/ @@ -19710,6 +19803,7 @@ F: Documentation/networking/tls* F: include/net/tls.h F: include/uapi/linux/tls.h F: net/tls/ +F: tools/testing/selftests/drivers/net/hw/tls* F: tools/testing/selftests/net/tls.c NETWORKING [SOCKETS] @@ -20296,6 +20390,13 @@ F: drivers/gpu/drm/bridge/tda998x_drv.c F: include/dt-bindings/display/tda998x.h K: "nxp,tda998x" +NXP TFA9865 AMPLIFIER DRIVER +M: Venkat Yadlapati +L: linux-sound@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/sound/nxp,tfa9865.yaml +F: sound/soc/codecs/tfa9865.c + NXP TFA9879 DRIVER M: Peter Rosin L: linux-sound@vger.kernel.org @@ -20924,7 +21025,7 @@ S: Maintained F: drivers/char/hw_random/optee-rng.c OP-TEE RTC DRIVER -M: Clément Léger +M: Clément Léger L: linux-rtc@vger.kernel.org S: Maintained F: drivers/rtc/rtc-optee.c @@ -21853,6 +21954,7 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/dennis/percpu.git F: arch/*/include/asm/percpu.h F: include/linux/percpu*.h +F: include/trace/events/percpu.h F: lib/percpu*.c F: mm/percpu*.c F: mm/percpu-internal.h @@ -22346,6 +22448,7 @@ M: Petr Mladek M: John Ogness R: Steven Rostedt R: Sergey Senozhatsky +L: printk@lists.linux.dev S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git F: Documentation/core-api/printk-basics.rst @@ -22354,6 +22457,7 @@ F: kernel/printk/ PRINTK INDEXING R: Chris Down +L: printk@lists.linux.dev S: Maintained F: Documentation/core-api/printk-index.rst F: kernel/printk/index.c @@ -23460,9 +23564,11 @@ RDT - RESOURCE ALLOCATION M: Tony Luck M: Reinette Chatre M: x86@kernel.org +R: Ben Horgan R: Dave Martin R: James Morse R: Babu Moger +R: Drew Fustini L: linux-kernel@vger.kernel.org S: Supported P: Documentation/process/maintainer-tip.rst @@ -23823,7 +23929,7 @@ F: Documentation/devicetree/bindings/rtc/renesas,rz-rtca3.yaml F: drivers/rtc/rtc-renesas-rtca3.c RENESAS RZ/N1 A5PSW SWITCH DRIVER -M: Clément Léger +M: Clément Léger L: linux-renesas-soc@vger.kernel.org L: netdev@vger.kernel.org S: Maintained @@ -24721,7 +24827,7 @@ F: drivers/iommu/s390-iommu.c S390 IUCV NETWORK LAYER M: Alexandra Winter -M: Thorsten Winkler +M: Hidayath Khan L: linux-s390@vger.kernel.org L: netdev@vger.kernel.org S: Supported @@ -25509,7 +25615,8 @@ F: drivers/slimbus/ F: include/linux/slimbus.h SFC NETWORK DRIVER -M: Edward Cree +M: Alex Austin +M: Andy Moreton L: netdev@vger.kernel.org L: linux-net-drivers@amd.com S: Maintained @@ -25579,6 +25686,7 @@ F: include/linux/shrinker.h F: mm/list_lru.c F: mm/shrinker.c F: mm/shrinker_debug.c +F: tools/cgroup/memcg_shrinker.py SH_VOU V4L2 OUTPUT DRIVER L: linux-media@vger.kernel.org @@ -25800,34 +25908,6 @@ S: Maintained F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml F: drivers/nvmem/layouts/sl28vpd.c -SLAB ALLOCATOR -M: Vlastimil Babka -M: Harry Yoo -M: Andrew Morton -R: Hao Li -R: Christoph Lameter -R: David Rientjes -R: Roman Gushchin -L: linux-mm@kvack.org -S: Maintained -T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/slab.git -F: Documentation/admin-guide/mm/slab.rst -F: Documentation/mm/slab.rst -F: include/linux/mempool.h -F: include/linux/slab.h -F: lib/tests/slub_kunit.c -F: mm/failslab.c -F: mm/mempool.c -F: mm/slab.h -F: mm/slab_common.c -F: mm/slub.c -F: scripts/gdb/linux/slab.py -F: tools/cgroup/memcg_slabinfo.py -F: tools/include/linux/slab.h -F: tools/lib/slab.c -F: tools/mm/slabinfo-gnuplot.sh -F: tools/mm/slabinfo.c - SLCAN CAN NETWORK DRIVER M: Dario Binacchi L: linux-can@vger.kernel.org @@ -26055,9 +26135,8 @@ S: Maintained F: drivers/net/ethernet/natsemi/sonic.* SONICS SILICON BACKPLANE DRIVER (SSB) -M: Michael Buesch L: linux-wireless@vger.kernel.org -S: Maintained +S: Orphan F: drivers/ssb/ F: include/linux/ssb/ @@ -28245,17 +28324,6 @@ S: Maintained F: Documentation/hwmon/tmp513.rst F: drivers/hwmon/tmp513.c -TMPFS (SHMEM FILESYSTEM) -M: Hugh Dickins -R: Baolin Wang -L: linux-mm@kvack.org -S: Maintained -F: include/linux/memfd.h -F: include/linux/shmem_fs.h -F: mm/memfd.c -F: mm/shmem.c -F: mm/shmem_quota.c - TOMOYO SECURITY MODULE M: Kentaro Takeda M: Tetsuo Handa @@ -28662,7 +28730,7 @@ F: arch/m68k/coldfire/ F: arch/m68k/include/asm/*_no.* UDF FILESYSTEM -M: Jan Kara +M: Jan Kara S: Maintained F: Documentation/filesystems/udf.rst F: fs/udf/ @@ -29610,9 +29678,12 @@ F: drivers/block/virtio_blk.c F: drivers/crypto/virtio/ F: drivers/vdpa/ F: drivers/virtio/ +F: include/linux/device-id/virtio.h F: include/linux/vdpa.h F: include/linux/virtio*.h F: include/linux/vringh.h +F: include/uapi/linux/vdpa.h +F: include/uapi/linux/vduse.h F: include/uapi/linux/virtio_*.h F: net/vmw_vsock/virtio* F: tools/virtio/ @@ -29686,6 +29757,7 @@ F: drivers/vhost/ F: include/linux/sched/vhost_task.h F: include/linux/vhost_iotlb.h F: include/uapi/linux/vhost.h +F: include/uapi/linux/vhost_types.h F: kernel/vhost_task.c VIRTIO HOST (VHOST-SCSI) @@ -29879,9 +29951,11 @@ S: Maintained W: http://www.linux-mm.org T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm F: include/linux/vmalloc.h +F: include/trace/events/vmalloc.h +F: lib/test_vmalloc.c F: mm/vmalloc.c F: mm/vmalloc.h -F: lib/test_vmalloc.c +F: scripts/gdb/linux/vmalloc.py VME SUBSYSTEM L: linux-kernel@vger.kernel.org @@ -30004,6 +30078,7 @@ M: Steven Rostedt R: Andy Shevchenko R: Rasmus Villemoes R: Sergey Senozhatsky +L: printk@lists.linux.dev S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git F: Documentation/core-api/printk-formats.rst diff --git a/Makefile b/Makefile index f895752d4b05fa..5aac6f1b011e1b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION = 7 PATCHLEVEL = 4 SUBLEVEL = 0 -EXTRAVERSION = -rc1 +EXTRAVERSION = -rc3 NAME = Baby Opossum Posse # *DOCUMENTATION* diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c index ed6d4f0cd62162..5fee6c451bf67f 100644 --- a/arch/arc/kernel/perf_event.c +++ b/arch/arc/kernel/perf_event.c @@ -672,18 +672,21 @@ static void arc_pmu_add_raw_event_attr(int j, char *str) static int arc_pmu_raw_alloc(struct device *dev) { - arc_pmu->attr = devm_kmalloc_array(dev, arc_pmu->n_events + 1, - sizeof(*arc_pmu->attr), GFP_KERNEL | __GFP_ZERO); + arc_pmu->attr = devm_kmalloc_objs(dev, *arc_pmu->attr, + arc_pmu->n_events + 1, + GFP_KERNEL | __GFP_ZERO); if (!arc_pmu->attr) return -ENOMEM; - arc_pmu->attrs = devm_kmalloc_array(dev, arc_pmu->n_events + 1, - sizeof(*arc_pmu->attrs), GFP_KERNEL | __GFP_ZERO); + arc_pmu->attrs = devm_kmalloc_objs(dev, *arc_pmu->attrs, + arc_pmu->n_events + 1, + GFP_KERNEL | __GFP_ZERO); if (!arc_pmu->attrs) return -ENOMEM; - arc_pmu->raw_entry = devm_kmalloc_array(dev, arc_pmu->n_events, - sizeof(*arc_pmu->raw_entry), GFP_KERNEL | __GFP_ZERO); + arc_pmu->raw_entry = devm_kmalloc_objs(dev, *arc_pmu->raw_entry, + arc_pmu->n_events, + GFP_KERNEL | __GFP_ZERO); if (!arc_pmu->raw_entry) return -ENOMEM; @@ -747,7 +750,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev) if (WARN(!cc_bcr.v, "Counters exist but No countable conditions?")) return -EINVAL; - arc_pmu = devm_kzalloc(&pdev->dev, sizeof(struct arc_pmu), GFP_KERNEL); + arc_pmu = devm_kzalloc_obj(&pdev->dev, struct arc_pmu); if (!arc_pmu) return -ENOMEM; diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c index 639a2736f029ed..13450e5d2b7a7c 100644 --- a/arch/arc/net/bpf_jit_core.c +++ b/arch/arc/net/bpf_jit_core.c @@ -1101,8 +1101,7 @@ static void fill_ill_insn(void *area, unsigned int size) /* Piece of memory that can be allocated at the beginning of jit_prepare(). */ static int jit_prepare_early_mem_alloc(struct jit_context *ctx) { - ctx->bpf2insn = kcalloc(ctx->prog->len, sizeof(ctx->jit.len), - GFP_KERNEL); + ctx->bpf2insn = kzalloc_objs(ctx->jit.len, ctx->prog->len); if (!ctx->bpf2insn) { pr_err("bpf-jit: could not allocate memory for " diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c index a0f854cf4748ea..a6558378b32f35 100644 --- a/arch/arm/common/sa1111.c +++ b/arch/arm/common/sa1111.c @@ -800,7 +800,7 @@ static int __sa1111_probe(struct device *me, struct resource *mem, int irq) if (!pd) return -EINVAL; - sachip = devm_kzalloc(me, sizeof(struct sa1111), GFP_KERNEL); + sachip = devm_kzalloc_obj(me, struct sa1111); if (!sachip) return -ENOMEM; diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c index e6b50cd43ce53a..b59012da924749 100644 --- a/arch/arm/kernel/topology.c +++ b/arch/arm/kernel/topology.c @@ -92,8 +92,7 @@ static void __init parse_dt_topology(void) unsigned long capacity = 0; int cpu = 0; - __cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity), - GFP_NOWAIT); + __cpu_capacity = kzalloc_objs(*__cpu_capacity, nr_cpu_ids, GFP_NOWAIT); for_each_possible_cpu(cpu) { const __be32 *rate; diff --git a/arch/arm/mach-imx/src.c b/arch/arm/mach-imx/src.c index c3c80b4c3d53bb..e49525276f4a62 100644 --- a/arch/arm/mach-imx/src.c +++ b/arch/arm/mach-imx/src.c @@ -219,7 +219,7 @@ static int imx_src_probe(struct platform_device *pdev) { struct reset_controller_dev *rcdev; - rcdev = devm_kzalloc(&pdev->dev, sizeof(*rcdev), GFP_KERNEL); + rcdev = devm_kzalloc_obj(&pdev->dev, *rcdev); if (!rcdev) return -ENOMEM; diff --git a/arch/arm/mach-omap1/omap-dma.c b/arch/arm/mach-omap1/omap-dma.c index aebe5e55ff6071..dec2c0d307f45b 100644 --- a/arch/arm/mach-omap1/omap-dma.c +++ b/arch/arm/mach-omap1/omap-dma.c @@ -770,8 +770,7 @@ static int omap_system_dma_probe(struct platform_device *pdev) dma_chan_count = dma_lch_count; enable_1510_mode = d->dev_caps & ENABLE_1510_MODE; - dma_chan = devm_kcalloc(&pdev->dev, dma_lch_count, - sizeof(*dma_chan), GFP_KERNEL); + dma_chan = devm_kzalloc_objs(&pdev->dev, *dma_chan, dma_lch_count); if (!dma_chan) return -ENOMEM; diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c index c63e854921ea2a..02b55f1461f6ad 100644 --- a/arch/arm/mach-pxa/pm.c +++ b/arch/arm/mach-pxa/pm.c @@ -102,9 +102,7 @@ static int __init pxa_pm_init(void) return -EINVAL; } - sleep_save = kmalloc_array(pxa_cpu_pm_fns->save_count, - sizeof(*sleep_save), - GFP_KERNEL); + sleep_save = kmalloc_objs(*sleep_save, pxa_cpu_pm_fns->save_count); if (!sleep_save) return -ENOMEM; diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c index 9ede81afbc50e2..aa240e3de6e704 100644 --- a/arch/arm/net/bpf_jit_32.c +++ b/arch/arm/net/bpf_jit_32.c @@ -2199,7 +2199,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr ctx.idx += ctx.imm_count; if (ctx.imm_count) { - ctx.imms = kcalloc(ctx.imm_count, sizeof(u32), GFP_KERNEL); + ctx.imms = kzalloc_objs(u32, ctx.imm_count); if (ctx.imms == NULL) goto out_off; } diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1075bc66183304..9b08b2457a555f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1051,6 +1051,38 @@ config ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT # making it unreliable. As a result, AMU users should treat it as # unavailable rather than relying on misleading counter values. +config ARM64_WORKAROUND_BROKEN_AMU_CORECNT + bool + # Targeting errata affecting AMEVCNTR00, the AMU core cycle counter. + # On affected CPUs the counter may continue incrementing while core + # remains in WFE with the clocks enabled. + # This may lead to readings of said counter being unreliable. + # How much though depends on the sampling intervals. + +config ARM64_ERRATUM_2738461 + bool "Cortex-A715/Cortex-A720: workaround for AMEVCNTR00 incrementing incorrectly" + depends on ARM64_AMU_EXTN + select ARM64_WORKAROUND_BROKEN_AMU_CORECNT + default y + help + This option adds the workaround for the following errata: + + * ARM Cortex-A715 erratum 2738462 + * ARM Cortex-A720 erratum 2738461 + + On affected cores the AMEVCNTR00 counter (AMU core frequency cycles + counter) may continue incrementing while the core remains in WFE + with the clocks being enabled. + This may result in inaccurate counter readings, with the magnitude + of the discrepancy depending on the sampling interval. + + With this workaround, reads of the affected counter return 0 in + the relevant paths. This causes users of the counter to treat it + as unavailable and is functionally equivalent to firmware disabling + the affected counter. + + If unsure, say Y. + config ARM64_ERRATUM_2457168 bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly" depends on ARM64_AMU_EXTN @@ -1086,14 +1118,20 @@ config ARM64_ERRATUM_2645198 If unsure, say Y. config ARM64_ERRATUM_3821522 - bool "Cortex-A725: 3821522: workaround for possible CNT_CYCLES increment error due to WFE/WFI" + bool "Cortex-*/Neoverse-*/C1-*: workaround for possible CNT_CYCLES increment error due to WFE/WFI" depends on ARM64_AMU_EXTN select ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT default y help - This option adds the workaround for ARM Cortex-A725 erratum 3821522. + This option adds the workaround for the following errata: + + * ARM Cortex-A725 erratum 3821522 + * ARM Cortex-A720 erratum 4689339 + * ARM Cortex-A720AE erratum 4689340 + * ARM Neoverse N3 erratum 4689341 + * ARM C1-Pro erratum 4689344 - On affected A725 cores, the CNT_CYCLES event may incur a significant + On affected cores, the CNT_CYCLES event may incur a significant increment error when entering and subsequently exiting WFx. As a result, the CNT_CYCLES may diverge from the system counter frequency at which it is expected to increment. diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index b2248bd3cb58fd..a78a5337ff854b 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -44,7 +44,8 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg); unsigned long do_sdei_event(struct pt_regs *regs, - struct sdei_registered_event *arg); + struct sdei_registered_event *arg, + unsigned long vbar); unsigned long sdei_arch_get_entry_point(int conduit); #define sdei_arch_get_entry_point(x) sdei_arch_get_entry_point(x) diff --git a/arch/arm64/include/asm/suspend.h b/arch/arm64/include/asm/suspend.h index e9ce68d50ba451..8e9c97aab15a10 100644 --- a/arch/arm64/include/asm/suspend.h +++ b/arch/arm64/include/asm/suspend.h @@ -2,7 +2,7 @@ #ifndef __ASM_SUSPEND_H #define __ASM_SUSPEND_H -#define NR_CTX_REGS 14 +#define NR_CTX_REGS 18 #define NR_CALLEE_SAVED_REGS 12 /* diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 38abd123c7404a..ca31d33152e930 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -420,13 +420,33 @@ static const struct midr_range workaround_amu_constcnt_list[] = { MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1), #endif #ifdef CONFIG_ARM64_ERRATUM_3821522 + /* Cortex-A720 r0p0 - r0p2 */ + MIDR_RANGE(MIDR_CORTEX_A720, 0, 0, 0, 2), + /* Cortex-A720AE r0p0 - r0p1 */ + MIDR_RANGE(MIDR_CORTEX_A720AE, 0, 0, 0, 1), /* Cortex-A725 r0p0 - r0p2 */ MIDR_RANGE(MIDR_CORTEX_A725, 0, 0, 0, 2), + /* Neoverse N3 r0p0 - r0p1 */ + MIDR_RANGE(MIDR_NEOVERSE_N3, 0, 0, 0, 1), + /* C1-Pro r0p0 - r1p3 */ + MIDR_RANGE(MIDR_C1_PRO, 0, 0, 1, 3), #endif {} }; #endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT */ +#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT +static const struct midr_range workaround_amu_corecnt_list[] = { +#ifdef CONFIG_ARM64_ERRATUM_2738461 + /* Cortex-A715 r0p0 - r1p3 */ + MIDR_RANGE(MIDR_CORTEX_A715, 0, 0, 1, 3), + /* Cortex-A720 r0p0 - r0p1 */ + MIDR_RANGE(MIDR_CORTEX_A720, 0, 0, 0, 1), +#endif + {} +}; +#endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT */ + #ifdef CONFIG_CAVIUM_ERRATUM_23154 static const struct midr_range cavium_erratum_23154_cpus[] = { MIDR_ALL_VERSIONS(MIDR_THUNDERX), @@ -970,6 +990,14 @@ const struct arm64_cpu_capabilities arm64_errata[] = { CAP_MIDR_RANGE_LIST(workaround_amu_constcnt_list) }, #endif +#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT + { + .desc = "Broken AMU AMEVCNTR00 (core cycle counter)", + .capability = ARM64_WORKAROUND_BROKEN_AMU_CORECNT, + .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, + CAP_MIDR_RANGE_LIST(workaround_amu_corecnt_list) + }, +#endif #ifdef CONFIG_ARM64_ERRATUM_2038923 { .desc = "ARM erratum 2038923", diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 34c5c03c0c9b4f..c9c9a6889455c2 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1938,7 +1938,8 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap) cpumask_set_cpu(smp_processor_id(), &amu_cpus); /* 0 reference values signal broken/disabled counters */ - if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT)) + if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT) && + !this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT)) update_freq_counters_refs(); } } diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 11d3f888fcd873..beb56891fc4fa7 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -31,6 +31,7 @@ #include #include #include +#include /* * Where the context being returned to had an active percpu GPR critical @@ -1040,6 +1041,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) { + unsigned long elr, spsr, esr, far, vbar; irqentry_state_t state; unsigned long ret; @@ -1065,10 +1067,46 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) else if (cpu_has_pan()) set_pstate_pan(0); + /* + * Nothing saved the interrupted context's exception registers on the + * way in, and it may be in the middle of exception entry or return + * (SDEI ignores DAIF). Save them before anything can take an exception + * and overwrite them. + */ + elr = read_sysreg(elr_el1); + spsr = read_sysreg(spsr_el1); + esr = read_sysreg(esr_el1); + far = read_sysreg(far_el1); + + /* + * With KPTI, VBAR_EL1 holds the trampoline vectors from the return to + * EL0 until the next exception from EL0 maps the kernel. They only + * handle exceptions from EL0: an exception taken here would run their + * empty current-EL half and never come back. Switch to the kernel + * vectors. The IRQ-like resume keeps using the interrupted VBAR, so it + * still goes through the trampoline. + */ + vbar = read_sysreg(vbar_el1); + if (arm64_kernel_unmapped_at_el0() && + vbar == (unsigned long)raw_cpu_read(this_cpu_vector)) { + write_sysreg((unsigned long)vectors, vbar_el1); + isb(); + } + state = irqentry_nmi_enter(regs); - ret = do_sdei_event(regs, arg); + ret = do_sdei_event(regs, arg, vbar); irqentry_nmi_exit(regs, state); + /* + * Put them back unconditionally. An unchanged ELR does not rule out a + * nested exception: one may have returned to the same address. + */ + write_sysreg(elr, elr_el1); + write_sysreg(spsr, spsr_el1); + write_sysreg(esr, esr_el1); + write_sysreg(far, far_el1); + write_sysreg(vbar, vbar_el1); + return ret; } #endif /* CONFIG_ARM_SDE_INTERFACE */ diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 78b1f956d8d724..f4ad2244725988 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -81,6 +81,13 @@ static void *image_load(struct kimage *image, kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; kbuf.memsz = le64_to_cpu(h->image_size); text_offset = le64_to_cpu(h->text_offset); + /* + * A CMA segment is loaded and mapped through page_address(cma), which + * is the CMA base and cannot represent the text_offset adjustment + * below. Load images with a non-zero text_offset from normal memory. + */ + if (text_offset) + image->no_cma = true; kbuf.buf_align = MIN_KIMG_ALIGN; /* Adjust kernel segment with TEXT_OFFSET */ diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 854d872dfd0f55..14f453dd094650 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -112,6 +112,8 @@ int load_other_segments(struct kimage *image, vfree(headers); goto out_err; } + + vfree(image->elf_headers); image->elf_headers = headers; image->elf_load_addr = kbuf.mem; image->elf_headers_sz = headers_sz; diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 7405c76724bfec..6a0b3a9b6125e6 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -573,8 +573,12 @@ static void update_syscall_orig_x0_after_ptrace(struct task_struct *target) if (regs->syscallno == NO_SYSCALL) return; - /* We should only be called when target is in a ptrace stop */ - if (WARN_ON_ONCE(!info)) + /* + * For exit-stops, info is always non-NULL, but that's not true for other + * stops such as non-seized group-stops. In those cases, just return early + * as there's no need to update orig_x0 anyway. + */ + if (!info) return; /* diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 778f2a1faac865..1b902da8ba43cd 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -195,21 +195,49 @@ unsigned long sdei_arch_get_entry_point(int conduit) return 0; } +/* + * Exceptions an SDEI handler may take without harm once __sdei_handler() has + * restored the interrupted context's exception registers. Their handlers are + * safe in NMI context: + * - EL1 data aborts on translation, permission and access-flag faults: + * faulthandler_disabled() is true in NMI context, so do_page_fault() never + * takes the mmap lock. This covers the _nofault() accessors used by the + * generic dump_stack()/show_regs() code (e.g. print_worker_info()). + * - BRK: kprobes, WARN/BUG, kCFI and UBSAN traps, all NMI-capable. + * Anything else taken at EL1 is fatal on its own, or unexpected here. + */ +static bool sdei_nested_exception_ok(unsigned long esr) +{ + switch (ESR_ELx_EC(esr)) { + case ESR_ELx_EC_DABT_CUR: + return esr_fsc_is_translation_fault(esr) || + esr_fsc_is_permission_fault(esr) || + esr_fsc_is_access_flag_fault(esr); + case ESR_ELx_EC_BRK64: + return true; + default: + return false; + } +} + /* * do_sdei_event() returns one of: * SDEI_EV_HANDLED - success, return to the interrupted context. * SDEI_EV_FAILED - failure, return this error code to firmware. * virtual-address - success, return to this address. + * + * vbar is the interrupted context's VBAR_EL1, for the IRQ-like resume. */ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, - struct sdei_registered_event *arg) + struct sdei_registered_event *arg, + unsigned long vbar) { u32 mode; int i, err = 0; int clobbered_registers = 4; u64 elr = read_sysreg(elr_el1); + u64 nested_elr, nested_esr, nested_far; u32 kernel_mode = read_sysreg(CurrentEL) | 1; /* +SPSel */ - unsigned long vbar = read_sysreg(vbar_el1); if (arm64_kernel_unmapped_at_el0()) clobbered_registers++; @@ -221,18 +249,27 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, } err = sdei_event_handler(regs, arg); - if (err) - return SDEI_EV_FAILED; - if (elr != read_sysreg(elr_el1)) { - /* - * We took a synchronous exception from the SDEI handler. - * This could deadlock, and if you interrupt KVM it will - * hyp-panic instead. - */ - pr_warn("unsafe: exception during handler\n"); + /* + * A synchronous exception taken by the handler has overwritten the + * exception registers; __sdei_handler() puts them back. Only the last + * one's syndrome survives; report it if it is not one known to be + * harmless. + * + * If the event interrupted a KVM world switch, VBAR points at the KVM + * hyp vectors and any such exception is a hyp panic instead. + */ + nested_elr = read_sysreg(elr_el1); + nested_esr = read_sysreg(esr_el1); + nested_far = read_sysreg(far_el1); + if (nested_elr != elr && !sdei_nested_exception_ok(nested_esr)) { + pr_warn_once("unexpected exception during handler: ESR %#llx FAR %#llx near %pS\n", + nested_esr, nested_far, (void *)nested_elr); } + if (err) + return SDEI_EV_FAILED; + mode = regs->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK); /* diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 6a06a4e352b1d5..80398ac83c3b12 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -741,36 +741,16 @@ static int preserve_gcs_context(struct gcs_context __user *ctx) static int restore_gcs_context(struct user_ctxs *user) { - u64 gcspr, enabled; + u64 gcspr; int err = 0; if (user->gcs_size != sizeof(*user->gcs)) return -EINVAL; __get_user_error(gcspr, &user->gcs->gcspr, err); - __get_user_error(enabled, &user->gcs->features_enabled, err); if (err) return err; - /* Don't allow unknown modes */ - if (enabled & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK) - return -EINVAL; - - err = gcs_check_locked(current, enabled); - if (err != 0) - return err; - - /* Don't allow enabling */ - if (!task_gcs_el0_enabled(current) && - (enabled & PR_SHADOW_STACK_ENABLE)) - return -EINVAL; - - /* If we are disabling disable everything */ - if (!(enabled & PR_SHADOW_STACK_ENABLE)) - enabled = 0; - - current->thread.gcs_el0_mode = enabled; - /* * We let userspace set GCSPR_EL0 to anything here, we will * validate later in gcs_restore_signal(). diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c index c41724a40b7560..4c281ae6babe0c 100644 --- a/arch/arm64/kernel/suspend.c +++ b/arch/arm64/kernel/suspend.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) int ret = 0; unsigned long flags; struct sleep_stack_data state; + bool idle = is_idle_task(current); /* * Some portions of CPU state (e.g. PSTATE.{PAN,DIT}) are initialized @@ -133,7 +135,8 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) */ pause_graph_tracing(); - ct_cpuidle_enter(); + if (idle) + ct_cpuidle_enter(); if (__cpu_suspend_enter(&state)) { /* Call the suspend finisher */ @@ -149,9 +152,11 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) if (!ret) ret = -EOPNOTSUPP; - ct_cpuidle_exit(); + if (idle) + ct_cpuidle_exit(); } else { - ct_cpuidle_exit(); + if (idle) + ct_cpuidle_exit(); __cpu_suspend_exit(); } @@ -170,8 +175,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) static int __init cpu_suspend_init(void) { /* ctx_ptr is an array of physical addresses */ - sleep_save_stash = kcalloc(mpidr_hash_size(), sizeof(*sleep_save_stash), - GFP_KERNEL); + sleep_save_stash = kzalloc_objs(*sleep_save_stash, mpidr_hash_size()); if (WARN_ON(!sleep_save_stash)) return -ENOMEM; diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 44305b997a0263..30a52659f15cd6 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -389,7 +389,8 @@ static void cpu_read_corecnt(void *val) * counter read is properly handled as an error case by the users of the * counter. */ - *(u64 *)val = read_corecnt(); + *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT) ? + 0UL : read_corecnt(); } static void cpu_read_constcnt(void *val) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 850eba167aad6a..c7d91138a6d49d 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -506,7 +506,7 @@ static int set_ccsidr(struct kvm_vcpu *vcpu, u32 csselr, u32 val) if (val == get_ccsidr(vcpu, csselr)) return 0; - ccsidr = kmalloc_array(CSSELR_MAX, sizeof(u32), GFP_KERNEL_ACCOUNT); + ccsidr = kmalloc_objs(u32, CSSELR_MAX, GFP_KERNEL_ACCOUNT); if (!ccsidr) return -ENOMEM; diff --git a/arch/arm64/kvm/vgic/vgic-irs-v5.c b/arch/arm64/kvm/vgic/vgic-irs-v5.c index 8d0ad74ebc64ae..f73349c02656c7 100644 --- a/arch/arm64/kvm/vgic/vgic-irs-v5.c +++ b/arch/arm64/kvm/vgic/vgic-irs-v5.c @@ -1000,8 +1000,8 @@ int kvm_vgic_v5_irs_init(struct kvm *kvm, unsigned int nr_spis) * provide at least 32 SPIs, so we always meet alignment requirements. */ if (nr_spis) { - dist->spis = kcalloc(nr_spis, sizeof(struct vgic_irq), - GFP_KERNEL_ACCOUNT); + dist->spis = kzalloc_objs(struct vgic_irq, nr_spis, + GFP_KERNEL_ACCOUNT); if (!dist->spis) return -ENOMEM; diff --git a/arch/arm64/kvm/vgic/vgic-v5-tables.c b/arch/arm64/kvm/vgic/vgic-v5-tables.c index d577e485ebe9e8..8f72704209b0eb 100644 --- a/arch/arm64/kvm/vgic/vgic-v5-tables.c +++ b/arch/arm64/kvm/vgic/vgic-v5-tables.c @@ -198,8 +198,7 @@ static int vgic_v5_alloc_vmt_two_level(unsigned int num_entries) return -ENOMEM; vmt_info->l2.l2ptrs = kzalloc_objs(*vmt_info->l2.l2ptrs, - vmt_info->l2.num_l1_ents, - GFP_KERNEL); + vmt_info->l2.num_l1_ents); if (!vmt_info->l2.l2ptrs) { kfree(vmt_info->l2.vmt_base); return -ENOMEM; @@ -296,7 +295,7 @@ int vgic_v5_vmt_allocate(unsigned int max_vpes) int ret; /* Allocate the tracking structure */ - vmt_info = kzalloc_obj(*vmt_info, GFP_KERNEL); + vmt_info = kzalloc_obj(*vmt_info); if (!vmt_info) return -ENOMEM; @@ -1598,7 +1597,7 @@ static int vgic_v5_track_pending_irq(struct list_head *pending_irqs, u32 intid, { struct vgic_v5_pending_irq *pirq; - pirq = kzalloc_obj(*pirq, GFP_KERNEL); + pirq = kzalloc_obj(*pirq); if (!pirq) return -ENOMEM; diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 8e799c1fe0aa69..ff1f53e435e1a6 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -429,9 +429,24 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, VM_WARN_ON(!pte_present(pte)); ncontig = num_contig_ptes(huge_page_size(hstate_vma(vma)), &pgsize); - if (!pte_cont(pte)) - return __ptep_set_access_flags_anysz(vma, addr, ptep, pte, - dirty, pgsize); + if (!pte_cont(pte)) { + if (__ptep_set_access_flags_anysz(vma, addr, ptep, pte, + dirty, pgsize)) + return 1; + + /* + * Another CPU may have made the entry writable without + * invalidating our stale read-only TLB entry. To avoid + * indefinitely faulting on this entry, flush it. + */ + if (dirty) + __flush_hugetlb_tlb_range(vma, addr, addr + pgsize, + pgsize, + TLBF_NOWALKCACHE | + TLBF_NOBROADCAST | + TLBF_NONOTIFY); + return 0; + } if (!__cont_access_flags_changed(ptep, pte, ncontig)) return 0; diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 32e0771d6477b0..e212270d4e09ac 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -61,7 +61,9 @@ int valid_phys_addr_range(phys_addr_t addr, size_t size) */ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) { - return !(((pfn << PAGE_SHIFT) + size) & ~PHYS_MASK); + const phys_addr_t limit = PHYS_MASK + 1; + + return size <= limit && pfn <= (limit - size) >> PAGE_SHIFT; } static int __init adjust_protection_map(void) diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 12aacc74f76471..99aacf03367da3 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -113,6 +113,20 @@ SYM_FUNC_START(cpu_do_suspend) alternative_if ARM64_HAS_TCR2 mrs x2, REG_TCR2_EL1 str x2, [x0, #104] +alternative_else_nop_endif +alternative_if ARM64_SME + mrs_s x2, SYS_TPIDR2_EL0 + str x2, [x0, #112] +alternative_else_nop_endif +alternative_if ARM64_HAS_S1POE + mrs x2, REG_POR_EL0 + str x2, [x0, #120] +alternative_else_nop_endif +alternative_if ARM64_HAS_GCS + mrs x2, REG_GCSPR_EL0 + str x2, [x0, #128] + mrs x2, REG_GCSCRE0_EL1 + str x2, [x0, #136] alternative_else_nop_endif ret SYM_FUNC_END(cpu_do_suspend) @@ -152,6 +166,20 @@ alternative_if ARM64_HAS_TCR2 ldr x2, [x0, #104] msr REG_TCR2_EL1, x2 alternative_else_nop_endif +alternative_if ARM64_SME + ldr x2, [x0, #112] + msr_s SYS_TPIDR2_EL0, x2 +alternative_else_nop_endif +alternative_if ARM64_HAS_S1POE + ldr x2, [x0, #120] + msr REG_POR_EL0, x2 +alternative_else_nop_endif +alternative_if ARM64_HAS_GCS + ldr x2, [x0, #128] + msr REG_GCSPR_EL0, x2 + ldr x2, [x0, #136] + msr REG_GCSCRE0_EL1, x2 +alternative_else_nop_endif msr sctlr_el1, x12 set_this_cpu_offset x13 diff --git a/arch/arm64/net/bpf_timed_may_goto.S b/arch/arm64/net/bpf_timed_may_goto.S index 1b4a4f91ffc90c..f8732b13bb1e58 100644 --- a/arch/arm64/net/bpf_timed_may_goto.S +++ b/arch/arm64/net/bpf_timed_may_goto.S @@ -17,16 +17,10 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) str x7, [sp, #80] /* - * Stack depth was passed in BPF_REG_AX (x9), add it to the BPF_FP - * (x25) to get the pointer to count and timestamp and pass it as the - * first argument in x0. - * - * Before generating the call to arch_bpf_timed_may_goto, the verifier - * generates a load instruction using FP, i.e. REG_AX = *(u64 *)(FP - - * stack_off_cnt), so BPF_REG_FP (x25) is always set up by the arm64 - * jit in this case. + * The pointer to count and timestamp was passed in BPF_REG_AX (x9), + * pass it as the first argument in x0. */ - add x0, x9, x25 + mov x0, x9 bl bpf_check_timed_may_goto /* BPF_REG_AX(x9) will be stored into count, so move return value to it. */ mov x9, x0 diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index 20cc185649f9af..3125695122a0a2 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -133,3 +133,4 @@ WORKAROUND_SPECULATIVE_AT WORKAROUND_SPECULATIVE_SSBS WORKAROUND_SPECULATIVE_UNPRIV_LOAD WORKAROUND_BROKEN_AMU_CONSTCNT +WORKAROUND_BROKEN_AMU_CORECNT diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h index b55aae3253006a..e061f966f7d1f9 100644 --- a/arch/loongarch/include/asm/inst.h +++ b/arch/loongarch/include/asm/inst.h @@ -535,6 +535,8 @@ u32 larch_insn_gen_lu32id(enum loongarch_gpr rd, int imm); u32 larch_insn_gen_lu52id(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm); u32 larch_insn_gen_beq(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm); u32 larch_insn_gen_bne(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm); +u32 larch_insn_gen_beqz(enum loongarch_gpr rj, int imm); +u32 larch_insn_gen_bnez(enum loongarch_gpr rj, int imm); u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm); static inline bool signed_imm_check(long val, unsigned int bit) @@ -592,6 +594,25 @@ DEF_EMIT_REG1I20_FORMAT(lu12iw, lu12iw_op) DEF_EMIT_REG1I20_FORMAT(lu32id, lu32id_op) DEF_EMIT_REG1I20_FORMAT(pcaddu18i, pcaddu18i_op) +#define DEF_EMIT_REG1I21_FORMAT(NAME, OP) \ +static inline void emit_##NAME(union loongarch_instruction *insn, \ + enum loongarch_gpr rj, int offset) \ +{ \ + unsigned int immediate_l, immediate_h; \ + \ + immediate_l = offset & 0xffff; \ + offset >>= 16; \ + immediate_h = offset & 0x1f; \ + \ + insn->reg1i21_format.opcode = OP; \ + insn->reg1i21_format.immediate_l = immediate_l; \ + insn->reg1i21_format.rj = rj; \ + insn->reg1i21_format.immediate_h = immediate_h; \ +} + +DEF_EMIT_REG1I21_FORMAT(beqz, beqz_op) +DEF_EMIT_REG1I21_FORMAT(bnez, bnez_op) + #define DEF_EMIT_REG2_FORMAT(NAME, OP) \ static inline void emit_##NAME(union loongarch_instruction *insn, \ enum loongarch_gpr rd, \ diff --git a/arch/loongarch/kernel/inst.c b/arch/loongarch/kernel/inst.c index 0b9228b7c13a40..0d5076cfd7d1f5 100644 --- a/arch/loongarch/kernel/inst.c +++ b/arch/loongarch/kernel/inst.c @@ -428,6 +428,34 @@ u32 larch_insn_gen_bne(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm) return insn.word; } +u32 larch_insn_gen_beqz(enum loongarch_gpr rj, int imm) +{ + union loongarch_instruction insn; + + if ((imm & 3) || imm < -SZ_4M || imm >= SZ_4M) { + pr_warn("The generated beqz instruction is out of range.\n"); + return INSN_BREAK; + } + + emit_beqz(&insn, rj, imm >> 2); + + return insn.word; +} + +u32 larch_insn_gen_bnez(enum loongarch_gpr rj, int imm) +{ + union loongarch_instruction insn; + + if ((imm & 3) || imm < -SZ_4M || imm >= SZ_4M) { + pr_warn("The generated bnez instruction is out of range.\n"); + return INSN_BREAK; + } + + emit_bnez(&insn, rj, imm >> 2); + + return insn.word; +} + u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm) { union loongarch_instruction insn; diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/machine_kexec.c index 1883cae93bc31a..19ccc91b6f2a25 100644 --- a/arch/loongarch/kernel/machine_kexec.c +++ b/arch/loongarch/kernel/machine_kexec.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,7 @@ int machine_kexec_prepare(struct kimage *kimage) */ memcpy((void *)KEXEC_CMDLINE_ADDR, (void *)kimage->arch.cmdline_ptr, strlen((char *)kimage->arch.cmdline_ptr) + 1); + kfree((void *)kimage->arch.cmdline_ptr); kimage->arch.cmdline_ptr = (unsigned long)KEXEC_CMDLINE_ADDR; } else { /* Find the command line */ diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c index 5412aa9f356878..0fe60907b97f13 100644 --- a/arch/loongarch/kernel/machine_kexec_file.c +++ b/arch/loongarch/kernel/machine_kexec_file.c @@ -166,6 +166,10 @@ int load_other_segments(struct kimage *image, vfree(headers); goto out_err; } + + if (unlikely(image->elf_headers)) + vfree(image->elf_headers); + image->elf_headers = headers; image->elf_load_addr = kbuf.mem; image->elf_headers_sz = headers_sz; diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c index ff327b4c05f7e3..c182185a3d592a 100644 --- a/arch/loongarch/kvm/intc/dmsintc.c +++ b/arch/loongarch/kvm/intc/dmsintc.c @@ -146,6 +146,7 @@ static void kvm_dmsintc_destroy(struct kvm_device *dev) return; kfree(dev->kvm->arch.dmsintc); + dev->kvm->arch.dmsintc = NULL; kfree(dev); } diff --git a/arch/loongarch/kvm/intc/eiointc.c b/arch/loongarch/kvm/intc/eiointc.c index 80f78e07c74a6b..fe0a1918f26f54 100644 --- a/arch/loongarch/kvm/intc/eiointc.c +++ b/arch/loongarch/kvm/intc/eiointc.c @@ -675,6 +675,7 @@ static void kvm_eiointc_destroy(struct kvm_device *dev) kvm = dev->kvm; eiointc = kvm->arch.eiointc; + kvm->arch.eiointc = NULL; mutex_lock(&kvm->slots_lock); kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device); kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device_vext); diff --git a/arch/loongarch/kvm/intc/ipi.c b/arch/loongarch/kvm/intc/ipi.c index 80faa770c0cdbe..7a2dd72a4952ae 100644 --- a/arch/loongarch/kvm/intc/ipi.c +++ b/arch/loongarch/kvm/intc/ipi.c @@ -441,6 +441,7 @@ static void kvm_ipi_destroy(struct kvm_device *dev) kvm = dev->kvm; ipi = kvm->arch.ipi; + kvm->arch.ipi = NULL; mutex_lock(&kvm->slots_lock); kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &ipi->device); mutex_unlock(&kvm->slots_lock); diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c index 220fc23ffe8cfd..044a219035e8ac 100644 --- a/arch/loongarch/kvm/intc/pch_pic.c +++ b/arch/loongarch/kvm/intc/pch_pic.c @@ -281,16 +281,25 @@ static int kvm_pch_pic_init(struct kvm_device *dev, u64 addr) struct kvm_io_device *device; struct loongarch_pch_pic *s = dev->kvm->arch.pch_pic; - s->pch_pic_base = addr; device = &s->device; + mutex_lock(&kvm->slots_lock); + if (s->device.ops) { + ret = -EEXIST; + goto out; + } + s->pch_pic_base = addr; /* init device by pch pic writing and reading ops */ kvm_iodevice_init(device, &kvm_pch_pic_ops); - mutex_lock(&kvm->slots_lock); /* register pch pic device */ ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, addr, PCH_PIC_SIZE, device); + if (ret) { + s->pch_pic_base = 0; + s->device.ops = NULL; + } +out: mutex_unlock(&kvm->slots_lock); - return (ret < 0) ? -EFAULT : 0; + return ret; } /* used by user space to get or set pch pic registers */ @@ -444,7 +453,7 @@ static int kvm_pch_pic_create(struct kvm_device *dev, u32 type) ret = kvm_setup_default_irq_routing(kvm); if (ret) - return -ENOMEM; + return ret; s = kzalloc_obj(struct loongarch_pch_pic); if (!s) @@ -483,6 +492,7 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev) kvm = dev->kvm; s = kvm->arch.pch_pic; + kvm->arch.pch_pic = NULL; /* unregister pch pic device and free it's memory */ mutex_lock(&kvm->slots_lock); kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device); diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 3ab039d0afb61b..15af1abb5cb69f 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -1819,7 +1819,7 @@ static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_image *im, /* update branch with beqz */ if (ctx->image) { int offset = (void *)(&ctx->image[ctx->idx]) - (void *)branch; - *branch = larch_insn_gen_beq(LOONGARCH_GPR_A0, LOONGARCH_GPR_ZERO, offset); + *branch = larch_insn_gen_beqz(LOONGARCH_GPR_A0, offset); } /* arg1: prog */ @@ -2132,9 +2132,10 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i emit_insn(ctx, std, regmap[BPF_REG_0], LOONGARCH_GPR_FP, -(retval_off - 8)); } + /* update branches with bnez */ for (i = 0; ctx->image && i < fmod_ret->nr_nodes; i++) { int offset = (void *)(&ctx->image[ctx->idx]) - (void *)branches[i]; - *branches[i] = larch_insn_gen_bne(LOONGARCH_GPR_T1, LOONGARCH_GPR_ZERO, offset); + *branches[i] = larch_insn_gen_bnez(LOONGARCH_GPR_T1, offset); } /* Set "is_return" flag for fsession */ @@ -2301,7 +2302,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr ctx.user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena); } - ctx.offset = kvcalloc(prog->len + 1, sizeof(u32), GFP_KERNEL); + ctx.offset = kvzalloc_objs(u32, prog->len + 1); if (ctx.offset == NULL) goto out_offset; @@ -2489,7 +2490,16 @@ bool bpf_jit_bypass_spec_v4(void) bool bpf_jit_supports_arena(void) { - return true; + /* + * The arena range tree uses kmalloc_nolock(), which requires + * 128-bit atomic cmpxchg; this is provided by not only hardware + * SCQ extension but also assembler support on LoongArch. + */ +#ifdef system_has_cmpxchg128 + return system_has_cmpxchg128(); +#else + return false; +#endif } bool bpf_jit_supports_fsession(void) diff --git a/arch/loongarch/net/bpf_timed_may_goto.S b/arch/loongarch/net/bpf_timed_may_goto.S index fa128acdb108a4..4aaca029404bcf 100644 --- a/arch/loongarch/net/bpf_timed_may_goto.S +++ b/arch/loongarch/net/bpf_timed_may_goto.S @@ -22,14 +22,10 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) st.d a4, sp, 48 /* - * BPF_REG_AX (t0) holds the offset passed in by the verifier; - * add it to BPF_REG_FP (s4) to get the pointer to the count and - * timestamp, then pass it as the first argument in a0. - * - * The verifier emits a load using FP right before this call, - * so BPF_REG_FP (s4) is always set up by the JIT in this case. + * BPF_REG_AX (t0) holds the pointer to the count and timestamp; + * pass it as the first argument in a0. */ - add.d a0, t0, s4 + move a0, t0 bl bpf_check_timed_may_goto /* BPF_REG_AX (t0) will be stored into count, so move the return value to it. */ move t0, a0 diff --git a/arch/loongarch/power/hibernate.c b/arch/loongarch/power/hibernate.c index 817270410ef987..3de38ffb11c3e8 100644 --- a/arch/loongarch/power/hibernate.c +++ b/arch/loongarch/power/hibernate.c @@ -59,6 +59,12 @@ extern int swsusp_asm_resume(void); int swsusp_arch_resume(void) { +#ifdef CONFIG_KFENCE + struct pbe *pbe; + + for (pbe = restore_pblist; pbe; pbe = pbe->next) + pbe->orig_address = __va(virt_to_phys(pbe->orig_address)); +#endif /* Avoid TLB mismatch during and after kernel resume */ local_flush_tlb_all(); return swsusp_asm_resume(); diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index ed17c9b1624cac..dac3ec5120a34c 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -79,7 +79,7 @@ config MIPS select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KPROBES select HAVE_KRETPROBES - select HAVE_LD_DEAD_CODE_DATA_ELIMINATION + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if !FTRACE_MCOUNT_USE_RECORDMCOUNT select HAVE_MOD_ARCH_SPECIFIC select HAVE_NMI select HAVE_PAGE_SIZE_4KB if !CPU_LOONGSON2EF && !CPU_LOONGSON64 diff --git a/arch/mips/alchemy/common/irq.c b/arch/mips/alchemy/common/irq.c index 2403afcd2fb956..d2fa8731fb3c00 100644 --- a/arch/mips/alchemy/common/irq.c +++ b/arch/mips/alchemy/common/irq.c @@ -892,15 +892,21 @@ static void __init au1000_init_irq(struct alchemy_irqmap *map) mips_cpu_irq_init(); /* register all 64 possible IC0+IC1 irq sources as type "none". + * Register each chip with the IRQ core before setting its type so + * the descriptors are included in interrupt enumeration. * Use set_irq_type() to set edge/level behaviour at runtime. */ for (irq_nr = AU1000_INTC0_INT_BASE; - (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++) + (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++) { + irq_set_chip(irq_nr, &au1x_ic0_chip); au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE); + } for (irq_nr = AU1000_INTC1_INT_BASE; - (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++) + (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++) { + irq_set_chip(irq_nr, &au1x_ic1_chip); au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE); + } /* * Initialize IC0, which is fixed per processor. @@ -947,6 +953,7 @@ static void __init alchemy_gpic_init_irq(const struct alchemy_irqmap *dints) /* register an irq_chip for them, with 2nd highest priority */ for (i = ALCHEMY_GPIC_INT_BASE; i <= ALCHEMY_GPIC_INT_LAST; i++) { + irq_set_chip(i, &au1300_gpic); au1300_set_irq_priority(i, 1); au1300_gpic_settype(irq_get_irq_data(i), IRQ_TYPE_NONE); } diff --git a/arch/mips/alchemy/common/prom.c b/arch/mips/alchemy/common/prom.c index 20d30f6265cdce..c4aefeb7887158 100644 --- a/arch/mips/alchemy/common/prom.c +++ b/arch/mips/alchemy/common/prom.c @@ -46,6 +46,11 @@ int prom_argc; char **prom_argv; char **prom_envp; +static char prom_ethaddr[6] __initdata; +static bool prom_ethaddr_valid __initdata; + +static void __init prom_init_ethernet_addr(void); + void __init prom_init_cmdline(void) { int i; @@ -95,6 +100,9 @@ void __init prom_init(void) if (!memsize_str || kstrtoul(memsize_str, 0, &memsize)) memsize = SZ_64M; /* minimum memsize is 64MB RAM */ + /* Save the MAC before the allocator can reuse the PROM environment. */ + prom_init_ethernet_addr(); + memblock_add(0, memsize); } @@ -125,7 +133,7 @@ static inline void str2eaddr(unsigned char *ea, unsigned char *str) } } -int __init prom_get_ethernet_addr(char *ethernet_addr) +static void __init prom_init_ethernet_addr(void) { char *ethaddr_str; @@ -135,12 +143,21 @@ int __init prom_get_ethernet_addr(char *ethernet_addr) /* Check command line */ ethaddr_str = strstr(arcs_cmdline, "ethaddr="); if (!ethaddr_str) - return -1; + return; ethaddr_str += strlen("ethaddr="); } - str2eaddr(ethernet_addr, ethaddr_str); + str2eaddr(prom_ethaddr, ethaddr_str); + prom_ethaddr_valid = true; +} + +int __init prom_get_ethernet_addr(char *ethernet_addr) +{ + if (!prom_ethaddr_valid) + return -1; + + memcpy(ethernet_addr, prom_ethaddr, sizeof(prom_ethaddr)); return 0; } diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile index 2684540758a8dc..837b5aacafcc9c 100644 --- a/arch/mips/boot/compressed/Makefile +++ b/arch/mips/boot/compressed/Makefile @@ -96,12 +96,20 @@ VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \ endif UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS) +# Like LINKER_LOAD_ADDRESS in arch/mips/Makefile: ld.lld cannot link a +# 32-bit executable at a sign-extended address, so drop the upper 32 bits. +ifdef CONFIG_64BIT +VMLINUZ_LINK_ADDRESS = $(VMLINUZ_LOAD_ADDRESS) +else +VMLINUZ_LINK_ADDRESS = $(subst 0xffffffff,0x,$(VMLINUZ_LOAD_ADDRESS)) +endif + vmlinuzobjs-y += $(obj)/piggy.o targets += ../../../../vmlinuz quiet_cmd_zld = LD $@ - cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ + cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LINK_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ quiet_cmd_strip = STRIP $@ cmd_strip = $(STRIP) -s $@ diff --git a/arch/mips/boot/compressed/ld.script b/arch/mips/boot/compressed/ld.script index 0ebb667274d631..c45be18c6f0dca 100644 --- a/arch/mips/boot/compressed/ld.script +++ b/arch/mips/boot/compressed/ld.script @@ -17,7 +17,7 @@ SECTIONS /* . = VMLINUZ_LOAD_ADDRESS; */ .text : { *(.text) - *(.rodata) + *(.rodata .rodata.*) }: text /* End of text section */ @@ -50,7 +50,9 @@ SECTIONS /* Sections to be discarded */ /DISCARD/ : { + *(.MIPS.abiflags) *(.MIPS.options) + *(.gnu.attributes) *(.options) *(.pdr) *(.reginfo) diff --git a/arch/mips/cobalt/pci.c b/arch/mips/cobalt/pci.c index 85ec9cc31d6661..29fd052766b2a2 100644 --- a/arch/mips/cobalt/pci.c +++ b/arch/mips/cobalt/pci.c @@ -14,6 +14,8 @@ #include +#include + extern struct pci_ops gt64xxx_pci0_ops; static struct resource cobalt_mem_resource = { @@ -24,7 +26,7 @@ static struct resource cobalt_mem_resource = { }; static struct resource cobalt_io_resource = { - .start = 0x1000, + .start = 0, .end = 0xffffffUL, .name = "PCI I/O", .flags = IORESOURCE_IO, @@ -38,11 +40,8 @@ static struct pci_controller cobalt_pci_controller = { .io_map_base = CKSEG1ADDR(GT_DEF_PCI0_IO_BASE), }; -static int __init cobalt_pci_init(void) +void __init cobalt_pci_init(void) { + PCIBIOS_MIN_IO = 0x1000; register_pci_controller(&cobalt_pci_controller); - - return 0; } - -arch_initcall(cobalt_pci_init); diff --git a/arch/mips/cobalt/setup.c b/arch/mips/cobalt/setup.c index 9a266bf7833993..502acc92969b88 100644 --- a/arch/mips/cobalt/setup.c +++ b/arch/mips/cobalt/setup.c @@ -83,9 +83,11 @@ void __init plat_mem_setup(void) /* I/O port resource */ ioport_resource.end = 0x01ffffff; + cobalt_pci_init(); + /* These resources have been reserved by VIA SuperI/O chip. */ for (i = 0; i < ARRAY_SIZE(cobalt_reserved_resources); i++) - request_resource(&ioport_resource, cobalt_reserved_resources + i); + insert_resource(&ioport_resource, cobalt_reserved_resources + i); } /* diff --git a/arch/mips/configs/ip30_defconfig b/arch/mips/configs/ip30_defconfig index 93eb90efe06ea7..a8b1a492f20c99 100644 --- a/arch/mips/configs/ip30_defconfig +++ b/arch/mips/configs/ip30_defconfig @@ -40,7 +40,6 @@ CONFIG_INET6_AH=m CONFIG_INET6_ESP=m CONFIG_INET6_IPCOMP=m CONFIG_IPV6_MIP6=m -CONFIG_IPV6_SIT=m CONFIG_IPV6_SIT_6RD=y CONFIG_IPV6_TUNNEL=m CONFIG_IPV6_MULTIPLE_TABLES=y @@ -129,11 +128,14 @@ CONFIG_SERIAL_8250_IOC3=y CONFIG_NOZOMI=m CONFIG_HW_RANDOM_TIMERIOMEM=m # CONFIG_PTP_1588_CLOCK is not set +CONFIG_W1=y +CONFIG_W1_MASTER_SGI=y +CONFIG_W1_SLAVE_DS250X=y # CONFIG_HWMON is not set CONFIG_THERMAL=y CONFIG_SGI_MFD_IOC3=y CONFIG_RTC_CLASS=y -CONFIG_RTC_DRV_M48T35=y +CONFIG_RTC_DRV_DS1685_FAMILY=y CONFIG_UIO=y CONFIG_UIO_AEC=m CONFIG_UIO_SERCOS3=m @@ -162,15 +164,12 @@ CONFIG_NFS_FS=y CONFIG_SECURITYFS=y CONFIG_CRYPTO_CRYPTD=m CONFIG_CRYPTO_BLOWFISH=m -CONFIG_CRYPTO_CAMELLIA=m CONFIG_CRYPTO_CAST5=m CONFIG_CRYPTO_CAST6=m CONFIG_CRYPTO_SERPENT=m CONFIG_CRYPTO_TWOFISH=m -CONFIG_CRYPTO_CTS=m CONFIG_CRYPTO_LRW=m CONFIG_CRYPTO_XTS=m -CONFIG_CRYPTO_HMAC=y CONFIG_CRYPTO_MD4=m CONFIG_CRYPTO_RMD160=m CONFIG_CRYPTO_WP512=m diff --git a/arch/mips/include/asm/ip32/crime.h b/arch/mips/include/asm/ip32/crime.h index 16c94a27bebad4..8f87b15b772b77 100644 --- a/arch/mips/include/asm/ip32/crime.h +++ b/arch/mips/include/asm/ip32/crime.h @@ -22,7 +22,7 @@ struct sgi_crime { #define CRIME_ID_MASK 0xff #define CRIME_ID_IDBITS 0xf0 #define CRIME_ID_IDVALUE 0xa0 -#define CRIME_ID_REV 0x0f +#define CRIME_ID_IDVALUE_B 0xb0 #define CRIME_REV_PETTY 0x00 #define CRIME_REV_11 0x11 #define CRIME_REV_13 0x13 diff --git a/arch/mips/include/asm/mach-cobalt/cobalt.h b/arch/mips/include/asm/mach-cobalt/cobalt.h index 97f9d5e9446d22..c7a8607cd651ac 100644 --- a/arch/mips/include/asm/mach-cobalt/cobalt.h +++ b/arch/mips/include/asm/mach-cobalt/cobalt.h @@ -19,6 +19,7 @@ extern int cobalt_board_id; #define COBALT_BRD_ID_QUBE2 0x5 #define COBALT_BRD_ID_RAQ2 0x6 +void cobalt_pci_init(void); void cobalt_machine_halt(void); void cobalt_machine_restart(char *command); diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c index 3de0e05e0511fb..e421590e339eae 100644 --- a/arch/mips/kernel/pm-cps.c +++ b/arch/mips/kernel/pm-cps.c @@ -361,7 +361,7 @@ static void *cps_gen_entry_code(unsigned cpu, enum cps_pm_state state) }; /* Allocate a buffer to hold the generated code */ - p = buf = kcalloc(max_instrs, sizeof(u32), GFP_KERNEL); + p = buf = kzalloc_objs(u32, max_instrs); if (!buf) return NULL; diff --git a/arch/mips/mm/cex-gen.S b/arch/mips/mm/cex-gen.S index e528583d13311d..6989fe274aab8a 100644 --- a/arch/mips/mm/cex-gen.S +++ b/arch/mips/mm/cex-gen.S @@ -8,6 +8,7 @@ * * Cache error handler */ +#include #include #include #include @@ -37,6 +38,21 @@ nop nop +#if defined(CONFIG_64BIT) && VMLINUX_LOAD_ADDRESS >= XKPHYS && \ + VMLINUX_LOAD_ADDRESS < XKSEG + /* + * An XKPHYS kernel may lie outside the 256MB region a j from the + * vector reaches, so jump to the handler's uncached XKPHYS address. + */ + PTR_LA k0, cache_parity_error + PTR_LI k1, TO_PHYS_MASK + and k0, k0, k1 + PTR_LI k1, UNCAC_BASE + or k0, k0, k1 + jr k0 + nop +#else j cache_parity_error nop +#endif END(except_vec2_generic) diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c index 4682dbb3a05920..1b213f9ba06b33 100644 --- a/arch/mips/net/bpf_jit_comp.c +++ b/arch/mips/net/bpf_jit_comp.c @@ -959,8 +959,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr * Not able to allocate memory for descriptors[], then * we must fall back to the interpreter */ - ctx.descriptors = kcalloc(prog->len + 1, sizeof(*ctx.descriptors), - GFP_KERNEL); + ctx.descriptors = kzalloc_objs(*ctx.descriptors, prog->len + 1); if (ctx.descriptors == NULL) goto out_err; diff --git a/arch/mips/pci/ops-mace.c b/arch/mips/pci/ops-mace.c index 951d8070fb4868..8827e5f2ea4602 100644 --- a/arch/mips/pci/ops-mace.c +++ b/arch/mips/pci/ops-mace.c @@ -35,15 +35,27 @@ static inline int mkaddr(struct pci_bus *bus, unsigned int devfn, (reg & 0xfc); } +/* + * On CRIME 1.1, a MACE PCI register read followed by two register writes + * can hang the machine under DMA load, so every register write in this + * file is followed by a read. Config cycles to empty slots end in a + * master abort; ack it with interrupts still off so the bridge error + * interrupt does not report it. + */ +static void mace_pci_ack_abort(void) +{ + u32 error = mace->pci.error; + + if (error & MACEPCI_ERROR_MASTER_ABORT) { + mace->pci.error = error & ~MACEPCI_ERROR_MASTER_ABORT; + mace->pci.error; + } +} static int mace_pci_read_config(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 *val) { - u32 control = mace->pci.control; - - /* disable master aborts interrupts during config read */ - mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT; mace->pci.config_addr = mkaddr(bus, devfn, reg); switch (size) { case 1: @@ -56,9 +68,7 @@ mace_pci_read_config(struct pci_bus *bus, unsigned int devfn, *val = mace->pci.config_data.l; break; } - /* ack possible master abort */ - mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT; - mace->pci.control = control; + mace_pci_ack_abort(); /* * someone forgot to set the ultra bit for the onboard * scsi chips; we fake it here @@ -77,6 +87,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 val) { mace->pci.config_addr = mkaddr(bus, devfn, reg); + mace->pci.error; switch (size) { case 1: mace->pci.config_data.b[(reg & 3) ^ 3] = val; @@ -88,6 +99,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, mace->pci.config_data.l = val; break; } + mace_pci_ack_abort(); DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val); diff --git a/arch/mips/pci/pci-ar2315.c b/arch/mips/pci/pci-ar2315.c index 17fa97ec6ffb17..f72802e6c29a1f 100644 --- a/arch/mips/pci/pci-ar2315.c +++ b/arch/mips/pci/pci-ar2315.c @@ -413,7 +413,7 @@ static int ar2315_pci_probe(struct platform_device *pdev) struct resource *res; int irq, err; - apc = devm_kzalloc(dev, sizeof(*apc), GFP_KERNEL); + apc = devm_kzalloc_obj(dev, *apc); if (!apc) return -ENOMEM; diff --git a/arch/mips/pci/pci-ar71xx.c b/arch/mips/pci/pci-ar71xx.c index 118760b3fa8241..0e514b03dd48db 100644 --- a/arch/mips/pci/pci-ar71xx.c +++ b/arch/mips/pci/pci-ar71xx.c @@ -331,8 +331,7 @@ static int ar71xx_pci_probe(struct platform_device *pdev) struct resource *res; u32 t; - apc = devm_kzalloc(&pdev->dev, sizeof(struct ar71xx_pci_controller), - GFP_KERNEL); + apc = devm_kzalloc_obj(&pdev->dev, struct ar71xx_pci_controller); if (!apc) return -ENOMEM; diff --git a/arch/mips/pci/pci-ar724x.c b/arch/mips/pci/pci-ar724x.c index 807558b251efa7..c36d910967ae74 100644 --- a/arch/mips/pci/pci-ar724x.c +++ b/arch/mips/pci/pci-ar724x.c @@ -367,8 +367,7 @@ static int ar724x_pci_probe(struct platform_device *pdev) if (id == -1) id = 0; - apc = devm_kzalloc(&pdev->dev, sizeof(struct ar724x_pci_controller), - GFP_KERNEL); + apc = devm_kzalloc_obj(&pdev->dev, struct ar724x_pci_controller); if (!apc) return -ENOMEM; diff --git a/arch/mips/pci/pci-ip32.c b/arch/mips/pci/pci-ip32.c index 7ae89d0c70990b..41ec8453c865d5 100644 --- a/arch/mips/pci/pci-ip32.c +++ b/arch/mips/pci/pci-ip32.c @@ -77,6 +77,8 @@ static irqreturn_t macepci_error(int irq, void *dev) } mace->pci.error = flags; + /* follow the write with a read, see mace_pci_ack_abort() */ + mace->pci.error; return IRQ_HANDLED; } @@ -125,10 +127,13 @@ static int __init mace_init(void) { PCIBIOS_MIN_IO = 0x1000; - /* Clear any outstanding errors and enable interrupts */ + /* + * Clear any outstanding errors and enable interrupts. PCI interrupts + * are masked in CRIME, so the per-slot enables stay on. + */ mace->pci.error_addr = 0; mace->pci.error = 0; - mace->pci.control = 0xff008500; + mace->pci.control = 0xff0085ff; printk("MACE PCI rev %d\n", mace->pci.rev); diff --git a/arch/mips/pci/pci-rt3883.c b/arch/mips/pci/pci-rt3883.c index 14454ece485d49..7327d37689045c 100644 --- a/arch/mips/pci/pci-rt3883.c +++ b/arch/mips/pci/pci-rt3883.c @@ -410,7 +410,7 @@ static int rt3883_pci_probe(struct platform_device *pdev) int err; int mode; - rpc = devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL); + rpc = devm_kzalloc_obj(dev, *rpc); if (!rpc) return -ENOMEM; diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c index 06bc2c01420fe0..1f767f25b5b092 100644 --- a/arch/mips/ralink/timer.c +++ b/arch/mips/ralink/timer.c @@ -102,7 +102,7 @@ static int rt_timer_probe(struct platform_device *pdev) struct rt_timer *rt; struct clk *clk; - rt = devm_kzalloc(&pdev->dev, sizeof(*rt), GFP_KERNEL); + rt = devm_kzalloc_obj(&pdev->dev, *rt); if (!rt) { dev_err(&pdev->dev, "failed to allocate memory\n"); return -ENOMEM; diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c index fc2816398d0cf0..c502982621e6b7 100644 --- a/arch/mips/sgi-ip27/ip27-nmi.c +++ b/arch/mips/sgi-ip27/ip27-nmi.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include @@ -183,6 +184,12 @@ static void nmi_dump(void) */ arch_spin_lock(&nmi_lock); + /* + * No CPU leaves the NMI handler before the hub reset below, so an + * nbcon console's printer thread would never print the dump. + */ + nbcon_cpu_emergency_enter(); + #ifdef REAL_NMI_SIGNAL /* * Wait up to 15 seconds for the other cpus to respond to the NMI. @@ -227,5 +234,6 @@ static void nmi_dump(void) * Save the nmi cpu registers for all cpu in the eframe format. */ nmi_eframes_save(); + printk_trigger_flush(); LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET); } diff --git a/arch/mips/sgi-ip32/crime.c b/arch/mips/sgi-ip32/crime.c index b8a0e4cfa9ce88..a24424437c6b89 100644 --- a/arch/mips/sgi-ip32/crime.c +++ b/arch/mips/sgi-ip32/crime.c @@ -27,7 +27,9 @@ EXPORT_SYMBOL_GPL(mace); void __init crime_init(void) { - unsigned int id, rev; + static const char * const revs[] = { "1.1", "1.3", "1.4" }; + const char *rev; + u64 id; const int field = 2 * sizeof(unsigned long); set_io_port_base((unsigned long) ioremap(MACEPCI_LOW_IO, 0x2000000)); @@ -35,10 +37,24 @@ void __init crime_init(void) mace = ioremap(MACE_BASE, sizeof(struct sgi_mace)); id = crime->id; - rev = id & CRIME_ID_REV; - id = (id & CRIME_ID_IDBITS) >> 4; - printk(KERN_INFO "CRIME id %1x rev %d at 0x%0*lx\n", - id, rev, field, (unsigned long) CRIME_BASE); + /* The revision of ID 0xa is in the upper word; 0xb is rev 1.5. */ + switch (id & CRIME_ID_IDBITS) { + case CRIME_ID_IDVALUE: + rev = revs[min_t(u64, id >> 32, ARRAY_SIZE(revs) - 1)]; + break; + case CRIME_ID_IDVALUE_B: + rev = "1.5"; + break; + case 0x00: + rev = "Petty"; + break; + default: + rev = "?"; + break; + } + pr_info("CRIME id %1x rev %s at 0x%0*lx\n", + (unsigned int)(id & CRIME_ID_IDBITS) >> 4, rev, field, + (unsigned long)CRIME_BASE); } irqreturn_t crime_memerr_intr(int irq, void *dev_id) diff --git a/arch/mips/sgi-ip32/ip32-irq.c b/arch/mips/sgi-ip32/ip32-irq.c index 29d04468a06b8f..b9c72af481edb9 100644 --- a/arch/mips/sgi-ip32/ip32-irq.c +++ b/arch/mips/sgi-ip32/ip32-irq.c @@ -160,38 +160,6 @@ static struct irq_chip crime_edge_interrupt = { .irq_unmask = crime_enable_irq, }; -/* - * This is for MACE PCI interrupts. We can decrease bus traffic by masking - * as close to the source as possible. This also means we can take the - * next chunk of the CRIME register in one piece. - */ - -static unsigned long macepci_mask; - -static void enable_macepci_irq(struct irq_data *d) -{ - macepci_mask |= MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ); - mace->pci.control = macepci_mask; - crime_mask |= 1 << (d->irq - CRIME_IRQ_BASE); - crime->imask = crime_mask; -} - -static void disable_macepci_irq(struct irq_data *d) -{ - crime_mask &= ~(1 << (d->irq - CRIME_IRQ_BASE)); - crime->imask = crime_mask; - flush_crime_bus(); - macepci_mask &= ~MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ); - mace->pci.control = macepci_mask; - flush_mace_bus(); -} - -static struct irq_chip ip32_macepci_interrupt = { - .name = "IP32 MACE PCI", - .irq_mask = disable_macepci_irq, - .irq_unmask = enable_macepci_irq, -}; - /* This is used for MACE ISA interrupts. That means bits 4-6 in the * CRIME register. */ @@ -299,8 +267,8 @@ static struct irq_chip ip32_maceisa_edge_interrupt = { .irq_unmask = enable_maceisa_irq, }; -/* This is used for regular non-ISA, non-PCI MACE interrupts. That means - * bits 0-3 and 7 in the CRIME register. +/* This is used for regular non-ISA MACE interrupts. That means bits 0-3 + * and 7-15 in the CRIME register. */ static void enable_mace_irq(struct irq_data *d) @@ -436,20 +404,13 @@ void __init arch_init_irq(void) mips_cpu_irq_init(); for (irq = CRIME_IRQ_BASE; irq <= IP32_IRQ_MAX; irq++) { switch (irq) { - case MACE_VID_IN1_IRQ ... MACE_PCI_BRIDGE_IRQ: + case MACE_VID_IN1_IRQ ... MACEPCI_SHARED2_IRQ: irq_set_chip_and_handler_name(irq, &ip32_mace_interrupt, handle_level_irq, "level"); break; - case MACEPCI_SCSI0_IRQ ... MACEPCI_SHARED2_IRQ: - irq_set_chip_and_handler_name(irq, - &ip32_macepci_interrupt, - handle_level_irq, - "level"); - break; - case CRIME_CPUERR_IRQ: case CRIME_MEMERR_IRQ: irq_set_chip_and_handler_name(irq, diff --git a/arch/mips/sibyte/sb1250/irq.c b/arch/mips/sibyte/sb1250/irq.c index 2f08ad267a11e6..d7a656cd7ec0c0 100644 --- a/arch/mips/sibyte/sb1250/irq.c +++ b/arch/mips/sibyte/sb1250/irq.c @@ -76,6 +76,8 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask, unsigned long flags; i = cpumask_first_and(mask, cpu_online_mask); + if (i >= nr_cpu_ids) + return -EINVAL; /* Convert logical CPU to physical CPU */ cpu = cpu_logical_map(i); @@ -103,6 +105,7 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask, ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) + R_IMR_INTERRUPT_MASK)); } + irq_data_update_effective_affinity(d, cpumask_of(i)); raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags); return 0; diff --git a/arch/openrisc/kernel/or32_ksyms.c b/arch/openrisc/kernel/or32_ksyms.c index 84a937a64e2a78..5aabef30ca09cc 100644 --- a/arch/openrisc/kernel/or32_ksyms.c +++ b/arch/openrisc/kernel/or32_ksyms.c @@ -35,6 +35,7 @@ DECLARE_EXPORT(__divsi3); DECLARE_EXPORT(__umodsi3); DECLARE_EXPORT(__modsi3); DECLARE_EXPORT(__muldi3); +DECLARE_EXPORT(__mulsi3); DECLARE_EXPORT(__ashrdi3); DECLARE_EXPORT(__ashldi3); DECLARE_EXPORT(__lshrdi3); diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 6a5a5469aaae56..7a25eaa59e6260 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -824,7 +824,7 @@ static int parse_thread_groups(struct device_node *dn, int i = 0; count = of_property_count_u32_elems(dn, "ibm,thread-groups"); - thread_group_array = kcalloc(count, sizeof(u32), GFP_KERNEL); + thread_group_array = kzalloc_objs(u32, count); if (!thread_group_array) return -ENOMEM; ret = of_property_read_u32_array(dn, "ibm,thread-groups", diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c index 75ed1496ead52f..80b136507e4097 100644 --- a/arch/powerpc/kvm/e500_mmu.c +++ b/arch/powerpc/kvm/e500_mmu.c @@ -804,9 +804,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, goto free_privs_first; } - g2h_bitmap = kcalloc(params.tlb_sizes[1], - sizeof(*g2h_bitmap), - GFP_KERNEL); + g2h_bitmap = kzalloc_objs(*g2h_bitmap, params.tlb_sizes[1]); if (!g2h_bitmap) { ret = -ENOMEM; goto free_privs_second; @@ -930,9 +928,8 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500) if (!vcpu_e500->gtlb_priv[1]) goto free_vcpu; - vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries, - sizeof(*vcpu_e500->g2h_tlb1_map), - GFP_KERNEL); + vcpu_e500->g2h_tlb1_map = kzalloc_objs(*vcpu_e500->g2h_tlb1_map, + vcpu_e500->gtlb_params[1].entries); if (!vcpu_e500->g2h_tlb1_map) goto free_vcpu; diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index 37e0d3d9e244da..fa61281198745b 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -741,9 +741,8 @@ int e500_mmu_host_init(struct kvmppc_vcpu_e500 *vcpu_e500) host_tlb_params[0].sets = host_tlb_params[0].entries / host_tlb_params[0].ways; host_tlb_params[1].sets = 1; - vcpu_e500->h2g_tlb1_rmap = kcalloc(host_tlb_params[1].entries, - sizeof(*vcpu_e500->h2g_tlb1_rmap), - GFP_KERNEL); + vcpu_e500->h2g_tlb1_rmap = kzalloc_objs(*vcpu_e500->h2g_tlb1_rmap, + host_tlb_params[1].entries); if (!vcpu_e500->h2g_tlb1_rmap) return -EINVAL; diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index e0b812d0c77e5a..ce2966c52ac500 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -258,7 +258,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr goto skip_init_ctx; } - addrs = kcalloc(flen + 1, sizeof(*addrs), GFP_KERNEL); + addrs = kzalloc_objs(*addrs, flen + 1); if (addrs == NULL) goto out_err; @@ -1104,7 +1104,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im } if (fmod_ret->nr_nodes) { - branches = kcalloc(fmod_ret->nr_nodes, sizeof(u32), GFP_KERNEL); + branches = kzalloc_objs(u32, fmod_ret->nr_nodes); if (!branches) return -ENOMEM; diff --git a/arch/powerpc/net/bpf_timed_may_goto.S b/arch/powerpc/net/bpf_timed_may_goto.S index 84ecf6fa7f5dcf..b8ae9885eb31cb 100644 --- a/arch/powerpc/net/bpf_timed_may_goto.S +++ b/arch/powerpc/net/bpf_timed_may_goto.S @@ -8,7 +8,7 @@ * arch_bpf_timed_may_goto() trampoline for powerpc64 * * Custom BPF convention (verifier/JIT): - * - input: stack offset in BPF_REG_AX (r12) + * - input: pointer to count and timestamp in BPF_REG_AX (r12) * - output: updated count in BPF_REG_AX (r12) * * Call bpf_check_timed_may_goto(ptr) with normal powerpc64 ABI: @@ -31,11 +31,8 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) std r7, 64(r1) std r8, 72(r1) - /* - * r3 = BPF_REG_FP + BPF_REG_AX - * BPF_REG_FP is r31; BPF_REG_AX is r12 (stack offset in bytes). - */ - add r3, r31, r12 + /* r3 = BPF_REG_AX (r12) */ + mr r3, r12 bl CFUNC(bpf_check_timed_may_goto) /* Put return value back into AX */ diff --git a/arch/powerpc/platforms/512x/mpc512x_lpbfifo.c b/arch/powerpc/platforms/512x/mpc512x_lpbfifo.c index f251e0f6826204..58c79a2914c07a 100644 --- a/arch/powerpc/platforms/512x/mpc512x_lpbfifo.c +++ b/arch/powerpc/platforms/512x/mpc512x_lpbfifo.c @@ -382,8 +382,8 @@ static int get_cs_ranges(struct device *dev) of_range_parser_init(&parser, lb_node); lpbfifo.cs_n = of_range_count(&parser); - lpbfifo.cs_ranges = devm_kcalloc(dev, lpbfifo.cs_n, - sizeof(struct cs_range), GFP_KERNEL); + lpbfifo.cs_ranges = devm_kzalloc_objs(dev, struct cs_range, + lpbfifo.cs_n); if (!lpbfifo.cs_ranges) goto end; diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c index e8163fdee69a1f..0dacf4d2258d06 100644 --- a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c +++ b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c @@ -713,7 +713,7 @@ static int mpc52xx_gpt_probe(struct platform_device *ofdev) { struct mpc52xx_gpt_priv *gpt; - gpt = devm_kzalloc(&ofdev->dev, sizeof *gpt, GFP_KERNEL); + gpt = devm_kzalloc_obj(&ofdev->dev, *gpt); if (!gpt) return -ENOMEM; diff --git a/arch/powerpc/platforms/8xx/cpm1-ic.c b/arch/powerpc/platforms/8xx/cpm1-ic.c index 3292071e4da326..f9b37e0987289f 100644 --- a/arch/powerpc/platforms/8xx/cpm1-ic.c +++ b/arch/powerpc/platforms/8xx/cpm1-ic.c @@ -91,7 +91,7 @@ static int cpm_pic_probe(struct platform_device *pdev) if (!res) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/arch/powerpc/platforms/8xx/cpm1.c b/arch/powerpc/platforms/8xx/cpm1.c index b31376bf677880..39e59b13a0713d 100644 --- a/arch/powerpc/platforms/8xx/cpm1.c +++ b/arch/powerpc/platforms/8xx/cpm1.c @@ -491,7 +491,7 @@ int cpm1_gpiochip_add16(struct device *dev) struct gpio_chip *gc; u32 mask; - cpm1_gc = devm_kzalloc(dev, sizeof(*cpm1_gc), GFP_KERNEL); + cpm1_gc = devm_kzalloc_obj(dev, *cpm1_gc); if (!cpm1_gc) return -ENOMEM; @@ -635,7 +635,7 @@ int cpm1_gpiochip_add32(struct device *dev) struct cpm1_gpio32_chip *cpm1_gc; struct gpio_chip *gc; - cpm1_gc = devm_kzalloc(dev, sizeof(*cpm1_gc), GFP_KERNEL); + cpm1_gc = devm_kzalloc_obj(dev, *cpm1_gc); if (!cpm1_gc) return -ENOMEM; diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c index 33103a98cfd554..52e4652ce27834 100644 --- a/arch/powerpc/platforms/powernv/idle.c +++ b/arch/powerpc/platforms/powernv/idle.c @@ -1338,8 +1338,8 @@ static int __init pnv_parse_cpuidle_dt(void) "ibm,cpu-idle-state-flags"); pnv_idle_states = kzalloc_objs(*pnv_idle_states, nr_idle_states); - temp_u32 = kcalloc(nr_idle_states, sizeof(u32), GFP_KERNEL); - temp_u64 = kcalloc(nr_idle_states, sizeof(u64), GFP_KERNEL); + temp_u32 = kzalloc_objs(u32, nr_idle_states); + temp_u64 = kzalloc_objs(u64, nr_idle_states); temp_string = kcalloc(nr_idle_states, sizeof(char *), GFP_KERNEL); if (!(pnv_idle_states && temp_u32 && temp_u64 && temp_string)) { diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c index b3fd5c648dea62..15a35bab97dc5f 100644 --- a/arch/powerpc/platforms/powernv/opal-imc.c +++ b/arch/powerpc/platforms/powernv/opal-imc.c @@ -91,11 +91,11 @@ static int imc_get_mem_addr_nest(struct device_node *node, if (nr_chips <= 0) return -ENODEV; - base_addr_arr = kcalloc(nr_chips, sizeof(*base_addr_arr), GFP_KERNEL); + base_addr_arr = kzalloc_objs(*base_addr_arr, nr_chips); if (!base_addr_arr) return -ENOMEM; - chipid_arr = kcalloc(nr_chips, sizeof(*chipid_arr), GFP_KERNEL); + chipid_arr = kzalloc_objs(*chipid_arr, nr_chips); if (!chipid_arr) { kfree(base_addr_arr); return -ENOMEM; diff --git a/arch/powerpc/platforms/powernv/opal-sysparam.c b/arch/powerpc/platforms/powernv/opal-sysparam.c index 7fe6433517ca7f..c124d90c7811e4 100644 --- a/arch/powerpc/platforms/powernv/opal-sysparam.c +++ b/arch/powerpc/platforms/powernv/opal-sysparam.c @@ -185,14 +185,14 @@ void __init opal_sys_param_init(void) goto out_param_buf; } - id = kcalloc(count, sizeof(*id), GFP_KERNEL); + id = kzalloc_objs(*id, count); if (!id) { pr_err("SYSPARAM: Failed to allocate memory to read parameter " "id\n"); goto out_param_buf; } - size = kcalloc(count, sizeof(*size), GFP_KERNEL); + size = kzalloc_objs(*size, count); if (!size) { pr_err("SYSPARAM: Failed to allocate memory to read parameter " "size\n"); diff --git a/arch/powerpc/sysdev/cpm_common.c b/arch/powerpc/sysdev/cpm_common.c index b5d200e3ad684f..104bd803fcd6a5 100644 --- a/arch/powerpc/sysdev/cpm_common.c +++ b/arch/powerpc/sysdev/cpm_common.c @@ -199,7 +199,7 @@ int cpm2_gpiochip_add32(struct device *dev) struct cpm2_gpio32_chip *cpm2_gc; struct gpio_chip *gc; - cpm2_gc = devm_kzalloc(dev, sizeof(*cpm2_gc), GFP_KERNEL); + cpm2_gc = devm_kzalloc_obj(dev, *cpm2_gc); if (!cpm2_gc) return -ENOMEM; diff --git a/arch/riscv/net/bpf_timed_may_goto.S b/arch/riscv/net/bpf_timed_may_goto.S index 6ec37f634aff63..2ce1c89c913e55 100644 --- a/arch/riscv/net/bpf_timed_may_goto.S +++ b/arch/riscv/net/bpf_timed_may_goto.S @@ -6,13 +6,11 @@ /* * Trampoline for the BPF timed may_goto loop bound. Custom calling convention: - * - input: stack offset in BPF_REG_AX (t0) + * - input: pointer to count and timestamp in BPF_REG_AX (t0) * - output: updated count in BPF_REG_AX (t0) * - * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where - * ptr = BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (t6, a0-a4) and stack - * arguments 6-8 (a5-a7) are saved across the call; BPF_REG_FP (s5) is - * callee-saved and needs no saving. + * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI. BPF R0-R5 + * (t6, a0-a4) and stack arguments 6-8 (a5-a7) are saved across the call. */ SYM_FUNC_START(arch_bpf_timed_may_goto) @@ -33,7 +31,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) REG_S a6, 7*SZREG(sp) REG_S a7, 8*SZREG(sp) - add a0, t0, s5 + mv a0, t0 call bpf_check_timed_may_goto mv t0, a0 diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index abb94720c79b79..912fb168be54a3 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -254,7 +254,7 @@ void *uv_alloc_stor_var(unsigned long size) area = get_vm_area(size, VM_SPARSE); if (!area) return NULL; - pages = kvcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL_ACCOUNT); + pages = kvzalloc_objs(struct page *, nr_pages, GFP_KERNEL_ACCOUNT); if (!pages) goto free_area; for (i = 0; i < nr_pages; i++) { diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 56ec49894dda38..ae89037db87c41 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c @@ -1005,6 +1005,17 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, (jit->prg - patch_brc) >> 1; break; } + if (insn_is_mov_percpu_addr(insn)) { + const u64 *percpu_offset = &get_lowcore()->percpu_offset; + + if (dst_reg != src_reg) + /* lgr %dst,%src */ + EMIT4(0xb9040000, dst_reg, src_reg); + /* ag %dst,percpu_offset */ + EMIT6_DISP_LH(0xe3000000, 0x0008, dst_reg, REG_0, REG_0, + (unsigned long)percpu_offset); + break; + } switch (insn->off) { case 0: /* DST = SRC */ /* lgr %dst,%src */ @@ -1866,9 +1877,9 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, if ((void *)func == arch_bpf_timed_may_goto) { /* * arch_bpf_timed_may_goto() has a special ABI: the - * parameters are in BPF_REG_AX and BPF_REG_10; the - * return value is in BPF_REG_AX; and all GPRs except - * REG_W0, REG_W1, and BPF_REG_AX are callee-saved. + * parameter is in BPF_REG_AX; the return value is in + * BPF_REG_AX; and all GPRs except REG_W0, REG_W1, and + * BPF_REG_AX are callee-saved. */ /* brasl %r0,func */ @@ -2386,7 +2397,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr } memset(&jit, 0, sizeof(jit)); - jit.addrs = kvcalloc(fp->len + 1, sizeof(*jit.addrs), GFP_KERNEL); + jit.addrs = kvzalloc_objs(*jit.addrs, fp->len + 1); if (jit.addrs == NULL) goto out_err; /* @@ -2428,8 +2439,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr fp->jited_len = jit.size - cfi_get_offset(); if (!fp->is_func || extra_pass) { - for (int i = 0; i < fp->len; i++) - jit.addrs[i] -= cfi_get_offset(); bpf_prog_fill_jited_linfo(fp, jit.addrs + 1); free_addrs: kvfree(jit.addrs); @@ -3116,6 +3125,11 @@ bool bpf_jit_supports_timed_may_goto(void) return true; } +bool bpf_jit_supports_percpu_insn(void) +{ + return true; +} + bool bpf_jit_inlines_helper_call(s32 imm) { switch (imm) { diff --git a/arch/s390/net/bpf_timed_may_goto.S b/arch/s390/net/bpf_timed_may_goto.S index 06f567a460d7bd..05f532f8c63903 100644 --- a/arch/s390/net/bpf_timed_may_goto.S +++ b/arch/s390/net/bpf_timed_may_goto.S @@ -21,9 +21,9 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) /* - * This function has a special ABI: the parameters are in %r12 and - * %r13; the return value is in %r12; all GPRs except %r0, %r1, and - * %r12 are callee-saved; and the return address is in %r0. + * This function has a special ABI: the parameter is in %r12; the + * return value is in %r12; all GPRs except %r0, %r1, and %r12 are + * callee-saved; and the return address is in %r0. */ stmg %r2,%r5,FRAME_OFF+R2_OFF(%r15) stg %r14,FRAME_OFF+R14_OFF(%r15) @@ -33,7 +33,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) lay %r15,-FRAME_SIZE(%r15) stg %r1,__SF_BACKCHAIN(%r15) - lay %r2,0(%r12,%r13) + lgr %r2,%r12 brasl %r14,bpf_check_timed_may_goto lgr %r12,%r2 diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index d64c544b32b0c6..1192fb167d3f94 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -1079,8 +1079,8 @@ static int zpci_mem_init(void) if (!zpci_iomap_start) goto error_iomap; - zpci_iomap_bitmap = kcalloc(BITS_TO_LONGS(ZPCI_IOMAP_ENTRIES), - sizeof(*zpci_iomap_bitmap), GFP_KERNEL); + zpci_iomap_bitmap = kzalloc_objs(*zpci_iomap_bitmap, + BITS_TO_LONGS(ZPCI_IOMAP_ENTRIES)); if (!zpci_iomap_bitmap) goto error_iomap_bitmap; diff --git a/arch/sparc/kernel/leon_pci_grpci1.c b/arch/sparc/kernel/leon_pci_grpci1.c index b2b639bee06848..d02067feaea874 100644 --- a/arch/sparc/kernel/leon_pci_grpci1.c +++ b/arch/sparc/kernel/leon_pci_grpci1.c @@ -528,7 +528,7 @@ static int grpci1_of_probe(struct platform_device *ofdev) return -EIO; } - priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&ofdev->dev, *priv); if (!priv) { dev_err(&ofdev->dev, "memory allocation failed\n"); return -ENOMEM; diff --git a/arch/sparc/kernel/nmi.c b/arch/sparc/kernel/nmi.c index 149adc09475306..255dd7dc74744a 100644 --- a/arch/sparc/kernel/nmi.c +++ b/arch/sparc/kernel/nmi.c @@ -172,8 +172,7 @@ static int __init check_nmi_watchdog(void) if (!atomic_read(&nmi_active)) return 0; - prev_nmi_count = kmalloc_array(nr_cpu_ids, sizeof(unsigned int), - GFP_KERNEL); + prev_nmi_count = kmalloc_objs(unsigned int, nr_cpu_ids); if (!prev_nmi_count) { err = -ENOMEM; goto error; diff --git a/arch/sparc/net/bpf_jit_comp_32.c b/arch/sparc/net/bpf_jit_comp_32.c index bda2dbd3f4c58e..5d98c222b420af 100644 --- a/arch/sparc/net/bpf_jit_comp_32.c +++ b/arch/sparc/net/bpf_jit_comp_32.c @@ -335,7 +335,7 @@ void bpf_jit_compile(struct bpf_prog *fp) if (!bpf_jit_enable) return; - addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL); + addrs = kmalloc_objs(*addrs, flen); if (addrs == NULL) return; diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c index 2fa0e93751276e..52f145e3843c63 100644 --- a/arch/sparc/net/bpf_jit_comp_64.c +++ b/arch/sparc/net/bpf_jit_comp_64.c @@ -1511,7 +1511,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr memset(&ctx, 0, sizeof(ctx)); ctx.prog = prog; - ctx.offset = kmalloc_array(prog->len, sizeof(unsigned int), GFP_KERNEL); + ctx.offset = kmalloc_objs(unsigned int, prog->len); if (ctx.offset == NULL) goto out_err; diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index 881c34098a7408..787308e26db7c2 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -1196,7 +1196,7 @@ virtio_uml_create_pdata(struct platform_device *pdev) if (!np) return ERR_PTR(-EINVAL); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index c07a2c381ed1fa..2d5cb3f7eee633 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -99,7 +99,7 @@ static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) pgd_t *pgd_p; pgd_start = ppd->vaddr & PGDIR_MASK; - pgd_end = ppd->vaddr_end & PGDIR_MASK; + pgd_end = (ppd->vaddr_end - 1) & PGDIR_MASK; pgd_size = (((pgd_end - pgd_start) / PGDIR_SIZE) + 1) * sizeof(pgd_t); diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index a59509bb460abf..ca97fa36182bff 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -77,6 +77,10 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, unsigned if (likely(nr < IA32_NR_syscalls)) { nr = array_index_nospec(nr, IA32_NR_syscalls); regs->ax = ia32_sys_call(regs, (unsigned int)nr); + } else { + /* See comment in do_syscall_64() */ + if (nr != -1UL) + regs->ax = -ENOSYS; } } diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index 966d3d1b75868d..bb95ad0ab78622 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -64,15 +64,20 @@ static __always_inline bool do_syscall_x64(struct pt_regs *regs, unsigned long n return false; } -static __always_inline void do_syscall_x32(struct pt_regs *regs, unsigned long nr) +static __always_inline bool do_syscall_x32(struct pt_regs *regs, unsigned long nr) { + if (!IS_ENABLED(CONFIG_X86_X32_ABI)) + return false; + /* Adjust the starting offset of the table */ nr -= __X32_SYSCALL_BIT; - if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(nr < X32_NR_syscalls)) { + if (likely(nr < X32_NR_syscalls)) { nr = array_index_nospec(nr, X32_NR_syscalls); regs->ax = x32_sys_call(regs, (unsigned int)nr); + return true; } + return false; } /* Returns true to return using SYSRET, or false to use IRET */ @@ -81,8 +86,21 @@ __visible noinstr bool do_syscall_64(struct pt_regs *regs, long nr) if (likely(syscall_enter_from_user_mode_randomize_stack(regs, &nr))) { instrumentation_begin(); - if (!do_syscall_x64(regs, nr)) - do_syscall_x32(regs, nr); + if (unlikely(!do_syscall_x64(regs, nr))) { + /* + * The special treatment of syscall number -1 is a + * historical bogosity as the original code used -1 to + * indicate syscall abort, which is not distinguishable + * from a syscall which is invoked with syscall number + * -1. The historic behavior is to keep the return value + * in regs->ax unmodified in that case, which means it's + * either the preset value -ENOSYS or a value which was + * written by a tracer. If the syscall number is invalid + * but not -1 then overwrite any tracer modification. + */ + if (!do_syscall_x32(regs, nr) && nr != -1L) + regs->ax = -ENOSYS; + } instrumentation_end(); } diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 3531f9c23b8c91..66e67e27224f18 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -28,6 +28,7 @@ static u32 ibs_caps; #include #include +#include #include /* attr.config2 */ @@ -73,7 +74,12 @@ static u32 ibs_caps; * * XXX: we could probably be using !atomic bitops for all this. */ - +/* + * NOTE: IBS_CAPS_DIS eliminates the RMW race on the IBS_{FETCH|OP}_CTL, making + * IBS_STARTED and IBS_STOPPED states unnecessary. We use only IBS_ENABLED and + * IBS_STOPPING states when IBS_CAPS_DIS is present. Semantics of IBS_STOPPING + * changes a bit as well. + */ enum ibs_states { IBS_ENABLED = 0, IBS_STARTED = 1, @@ -557,7 +563,9 @@ static void perf_ibs_start(struct perf_event *event, int flags) struct hw_perf_event *hwc = &event->hw; struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu); struct cpu_perf_ibs *pcpu = this_cpu_ptr(perf_ibs->pcpu); + unsigned int delay = 50; u64 period, config = 0; + u64 ctl; if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED))) return; @@ -575,23 +583,87 @@ static void perf_ibs_start(struct perf_event *event, int flags) } config |= period >> 4; - /* - * Reset the IBS_{FETCH|OP}_CTL MSR before updating pcpu->state. - * Doing so prevents a race condition in which an NMI due to other - * source might accidentally activate the event before we enable - * it ourselves. - */ - perf_ibs_disable_event(perf_ibs, hwc, 0); + if (ibs_caps & IBS_CAPS_DIS) { + /* + * IBS HW SW + * + * o Capture sample o ->stop() + * o Set VAL bit CTL2[Dis] = 1 + * o Raise NMI --. o ... + * \ o ->start() + * \ wrmsr(IBS_{FETCH|OP}_CTL, new value); + * \ (wrmsr clears the VAL bit) + * `--> o Receives delayed NMI + * (Unknown NMI since VAL bit is cleared) + * + * Handle this with induced delay. + */ + rdmsrq(hwc->config_base, ctl); + while ((ctl & perf_ibs->valid_mask) && delay--) { + udelay(1); + rdmsrq(hwc->config_base, ctl); + } + } else { + /* + * Reset the IBS_{FETCH|OP}_CTL MSR before updating pcpu->state. + * Doing so prevents a race condition in which an NMI due to + * other source might accidentally activate the event before we + * enable it ourselves. + */ + perf_ibs_disable_event(perf_ibs, hwc, 0); + /* + * Set STARTED before enabling the hardware, such that a + * subsequent NMI must observe it. + */ + set_bit(IBS_STARTED, pcpu->state); + clear_bit(IBS_STOPPING, pcpu->state); + } + perf_ibs_enable_event(perf_ibs, hwc, config); + + perf_event_update_userpage(event); +} + +/* ->stop() for platforms with additional CTL2[Dis] bit. */ +static void perf_ibs_stop_dis(struct perf_event *event, int flags) +{ + struct hw_perf_event *hwc = &event->hw; + struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu); + struct cpu_perf_ibs *pcpu = this_cpu_ptr(perf_ibs->pcpu); + u64 config; + u64 ctl2; + + WARN_ON_ONCE(test_bit(IBS_STOPPING, pcpu->state)); + + set_bit(IBS_STOPPING, pcpu->state); + + rdmsrq(hwc->extra_reg.reg, ctl2); + if (ctl2 & perf_ibs->disable_mask) + goto reset_state; + + wrmsrq(hwc->extra_reg.reg, perf_ibs->disable_mask); + + WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED); + hwc->state |= PERF_HES_STOPPED; + + if (hwc->state & PERF_HES_UPTODATE) + goto reset_state; + + rdmsrq(hwc->config_base, config); + + config &= ~perf_ibs->valid_mask; /* - * Set STARTED before enabling the hardware, such that a subsequent NMI - * must observe it. + * Clear the Val bit otherwise ->start() will unnecessarily + * wait for 50us. */ - set_bit(IBS_STARTED, pcpu->state); - clear_bit(IBS_STOPPING, pcpu->state); - perf_ibs_enable_event(perf_ibs, hwc, config); + if (in_nmi()) + wrmsrq(hwc->config_base, config); - perf_event_update_userpage(event); + perf_ibs_event_update(perf_ibs, event, &config); + hwc->state |= PERF_HES_UPTODATE; + +reset_state: + clear_bit(IBS_STOPPING, pcpu->state); } static void perf_ibs_stop(struct perf_event *event, int flags) @@ -602,6 +674,9 @@ static void perf_ibs_stop(struct perf_event *event, int flags) u64 config; int stopping; + if (ibs_caps & IBS_CAPS_DIS) + return perf_ibs_stop_dis(event, flags); + if (test_and_set_bit(IBS_STOPPING, pcpu->state)) return; @@ -1416,19 +1491,43 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) unsigned int msr; u64 *buf, *config, period, new_config = 0; int br_target_idx = -1; + u64 ctl2, ctl; - if (!test_bit(IBS_STARTED, pcpu->state)) { -fail: + if (ibs_caps & IBS_CAPS_DIS) { /* - * Catch spurious interrupts after stopping IBS: After - * disabling IBS there could be still incoming NMIs - * with samples that even have the valid bit cleared. - * Mark all this NMIs as handled. + * ->stop() { + * set_bit(IBS_STOPPING); + * <-- NMI (race 1) + * CTL2[Dis]=1; + * ... <-- NMI (race 2) + * } */ - if (test_and_clear_bit(IBS_STOPPED, pcpu->state)) - return 1; + rdmsrq(perf_ibs->msr2, ctl2); + if (test_bit(IBS_STOPPING, pcpu->state) /* race 1 */ || + (ctl2 & perf_ibs->disable_mask) /* race 2 */) { + rdmsrq(perf_ibs->msr, ctl); + if (ctl & perf_ibs->valid_mask) { + ctl &= ~(perf_ibs->enable_mask | + perf_ibs->valid_mask); + wrmsrq(perf_ibs->msr, ctl); + return 1; + } + return 0; + } + } else { + if (!test_bit(IBS_STARTED, pcpu->state)) { +fail: + /* + * Catch spurious interrupts after stopping IBS: After + * disabling IBS there could be still incoming NMIs + * with samples that even have the valid bit cleared. + * Mark all this NMIs as handled. + */ + if (test_and_clear_bit(IBS_STOPPED, pcpu->state)) + return 1; - return 0; + return 0; + } } if (WARN_ON_ONCE(!event)) @@ -1533,6 +1632,56 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) throttle = perf_event_account_interrupt(event); goto out; } + + /* + * IBS captured RIP is out of sync with NMI pt_regs due to NMI + * delivery latency. Use NMI pt_regs for PERF_SAMPLE_REGS_USER. + * + * Note: Valid user regs are required for PERF_SAMPLE_STACK_USER. + */ + if (event->attr.sample_type & (PERF_SAMPLE_REGS_USER | + PERF_SAMPLE_STACK_USER)) { + perf_sample_regs_user(&data.regs_user, iregs); + + /* + * Don't update dyn_size if user has not requested for + * PERF_SAMPLE_REGS_USER. + */ + if (event->attr.sample_type & PERF_SAMPLE_REGS_USER) { + /* regs dump ABI info */ + int size = sizeof(u64); + + if (data.regs_user.regs) { + u64 mask = event->attr.sample_regs_user; + size += hweight64(mask) * sizeof(u64); + } + + data.dyn_size += size; + } + + data.sample_flags |= PERF_SAMPLE_REGS_USER; + } + + /* + * IBS captured RIP is out of sync with NMI pt_regs due to NMI + * delivery latency. Use NMI pt_regs for PERF_SAMPLE_REGS_INTR. + */ + if (event->attr.sample_type & PERF_SAMPLE_REGS_INTR) { + /* regs dump ABI info */ + int size = sizeof(u64); + + perf_sample_regs_intr(&data.regs_intr, iregs, + event->attr.exclude_kernel); + + if (data.regs_intr.regs) { + u64 mask = event->attr.sample_regs_intr; + size += hweight64(mask) * sizeof(u64); + } + + data.dyn_size += size; + data.sample_flags |= PERF_SAMPLE_REGS_INTR; + } + /* * Prevent leaking physical addresses to unprivileged users. Skip * PERF_SAMPLE_PHYS_ADDR check since generic code prevents it for @@ -1948,7 +2097,7 @@ static int perf_ibs_suspend(void *data) static void perf_ibs_resume(void *data) { ibs_eilvt_setup(); - setup_APIC_ibs(); + x86_pmu_amd_ibs_starting_cpu(smp_processor_id()); } static const struct syscore_ops perf_ibs_syscore_ops = { diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 7aa5a5b652a2bd..c307323f63901a 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -595,7 +595,7 @@ static void amd_uncore_ctx_move(struct amd_uncore *uncore, unsigned int cpu) for (i = 0; i < uncore->num_pmus; i++) { pmu = &uncore->pmus[i]; curr = *per_cpu_ptr(pmu->ctx, cpu); - if (!curr) + if (!curr || curr->cpu != cpu) continue; /* Migrate to a shared sibling if possible */ diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 49349afee6119f..3782af40f0832a 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1896,8 +1896,6 @@ static __init int pt_init(void) if (!intel_pt_validate_hw_cap(PT_CAP_topa_multiple_entries)) pt_pmu.pmu.capabilities = PERF_PMU_CAP_AUX_NO_SG; - else - pt_pmu.pmu.capabilities = PERF_PMU_CAP_AUX_PREFER_LARGE; pt_pmu.pmu.capabilities |= PERF_PMU_CAP_EXCLUSIVE | PERF_PMU_CAP_ITRACE | diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/intel/uncore_discovery.c index 0a22edf4d509ad..99a1b974b14f2b 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -394,8 +394,7 @@ static bool uncore_discovery_msr(struct uncore_discovery_domain *domain) int cpu, die; u64 base; - die_mask = kcalloc(BITS_TO_LONGS(uncore_max_dies()), - sizeof(unsigned long), GFP_KERNEL); + die_mask = kzalloc_objs(unsigned long, BITS_TO_LONGS(uncore_max_dies())); if (!die_mask) return false; diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h index 17da953879976e..f74873a5e35102 100644 --- a/arch/x86/include/asm/checksum_32.h +++ b/arch/x86/include/asm/checksum_32.h @@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory"); return csum_fold(sum); diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 61930f0d457865..303467a498b8da 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -432,6 +432,7 @@ #define X86_FEATURE_CPPC_PERF_PRIO (17*32+ 2) /* CPPC Floor Perf support */ #define X86_FEATURE_SMCA (17*32+ 3) /* "smca" Scalable MCA */ #define X86_FEATURE_BTB_CTX_ISOLATION (17*32+ 4) /* AMD: Branch predictions contexts isolated */ +#define X86_FEATURE_TSA_FILL_NO (17*32+ 5) /* AMD CPU not vulnerable to TSA-FILL */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */ #define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* "avx512_4vnniw" AVX-512 Neural Network Instructions */ diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 4220dae14a2d9f..fb011cef01e76e 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -276,20 +276,22 @@ unsigned long vmware_hypercall_hb_out(unsigned long cmd, unsigned long in2, asm_inline volatile ( UNWIND_HINT_SAVE + "mov %[in6], %%" _ASM_AX "\n\t" "push %%" _ASM_BP "\n\t" UNWIND_HINT_UNDEFINED - "mov %[in6], %%" _ASM_BP "\n\t" + "mov %%" _ASM_AX ", %%" _ASM_BP "\n\t" + "mov %[magic], %%eax\n\t" "rep outsb\n\t" "pop %%" _ASM_BP "\n\t" UNWIND_HINT_RESTORE - : "=a" (out0), "=b" (*out1) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (cmd), + : "=&a" (out0), "=b" (*out1) + : "b" (cmd), "c" (in2), "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), "S" (in4), "D" (in5), - [in6] VMW_BP_CONSTRAINT (in6) + [in6] VMW_BP_CONSTRAINT(in6), + [magic] "i" (VMWARE_HYPERVISOR_MAGIC) : "cc", "memory"); return out0; } @@ -304,20 +306,22 @@ unsigned long vmware_hypercall_hb_in(unsigned long cmd, unsigned long in2, asm_inline volatile ( UNWIND_HINT_SAVE + "mov %[in6], %%" _ASM_AX "\n\t" "push %%" _ASM_BP "\n\t" UNWIND_HINT_UNDEFINED - "mov %[in6], %%" _ASM_BP "\n\t" + "mov %%" _ASM_AX ", %%" _ASM_BP "\n\t" + "mov %[magic], %%eax\n\t" "rep insb\n\t" "pop %%" _ASM_BP "\n\t" UNWIND_HINT_RESTORE - : "=a" (out0), "=b" (*out1) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (cmd), + : "=&a" (out0), "=b" (*out1) + : "b" (cmd), "c" (in2), "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), "S" (in4), "D" (in5), - [in6] VMW_BP_CONSTRAINT (in6) + [in6] VMW_BP_CONSTRAINT(in6), + [magic] "i" (VMWARE_HYPERVISOR_MAGIC) : "cc", "memory"); return out0; } diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 5d364540673d46..11fc164cba2104 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -228,7 +228,7 @@ static void amd_cache_gart(void) if (!amd_nb_has_feature(AMD_NB_GART)) return; - flush_words = kmalloc_array(amd_northbridges.num, sizeof(u32), GFP_KERNEL); + flush_words = kmalloc_objs(u32, amd_northbridges.num); if (!flush_words) { amd_northbridges.flags &= ~AMD_NB_GART; pr_notice("Cannot initialize GART flush words, GART support disabled\n"); diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c index 7db83212effb0f..e444b09bf88172 100644 --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -209,7 +209,7 @@ static int x2apic_cluster_probe(void) return 0; slots = max_t(u32, L1_CACHE_BYTES/sizeof(u32), nr_cpu_ids); - x86_cpu_to_logical_apicid = kcalloc(slots, sizeof(u32), GFP_KERNEL); + x86_cpu_to_logical_apicid = kzalloc_objs(u32, slots); if (!x86_cpu_to_logical_apicid) return 0; diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 3972966cb02377..365bcbf56c7687 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -416,9 +416,14 @@ static void tsa_init(struct cpuinfo_x86 *c) else pr_debug("%s: current revision: 0x%x\n", __func__, c->microcode); } else { - setup_force_cpu_cap(X86_FEATURE_TSA_SQ_NO); - setup_force_cpu_cap(X86_FEATURE_TSA_L1_NO); + if (!cpu_has(c, X86_FEATURE_ZEN5)) { + setup_force_cpu_cap(X86_FEATURE_TSA_SQ_NO); + setup_force_cpu_cap(X86_FEATURE_TSA_L1_NO); + } } + + if (!cpu_has(c, X86_FEATURE_ZEN5)) + setup_force_cpu_cap(X86_FEATURE_TSA_FILL_NO); } static void bsp_init_amd(struct cpuinfo_x86 *c) @@ -1362,7 +1367,8 @@ static __init int print_s5_reset_status_mmio(void) u32 value; int i; - if (!cpu_feature_enabled(X86_FEATURE_ZEN)) + if (!cpu_feature_enabled(X86_FEATURE_ZEN) || + cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) return 0; addr = ioremap(FCH_PM_BASE + FCH_PM_S5_RESET_STATUS, sizeof(value)); diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 000ebee2d247b1..4ced10c6ba0db9 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -2088,14 +2088,12 @@ static void __init bhi_select_mitigation(void) if (bhi_mitigation != BHI_MITIGATION_AUTO) return; - if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) { - if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL)) - bhi_mitigation = BHI_MITIGATION_ON; - else - bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY; - } else { + if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL)) + bhi_mitigation = BHI_MITIGATION_ON; + else if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) + bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY; + else bhi_mitigation = BHI_MITIGATION_OFF; - } } static void __init bhi_update_mitigation(void) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 9bd50c68cd7e5e..7e4eb704fe704c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1340,7 +1340,7 @@ static const struct x86_cpu_id cpu_vuln_blacklist[] __initconst = { VULNBL_AMD(0x17, RETBLEED | SMT_RSB | SRSO | VMSCAPE), VULNBL_HYGON(0x18, RETBLEED | SMT_RSB | SRSO | VMSCAPE), VULNBL_AMD(0x19, SRSO | TSA | VMSCAPE), - VULNBL_AMD(0x1a, SRSO | VMSCAPE), + VULNBL_AMD(0x1a, SRSO | TSA | VMSCAPE), {} }; @@ -1605,7 +1605,8 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) if (c->x86_vendor == X86_VENDOR_AMD) { if (!cpu_has(c, X86_FEATURE_TSA_SQ_NO) || - !cpu_has(c, X86_FEATURE_TSA_L1_NO)) { + !cpu_has(c, X86_FEATURE_TSA_L1_NO) || + !cpu_has(c, X86_FEATURE_TSA_FILL_NO)) { if (cpu_matches(cpu_vuln_blacklist, TSA) || /* Enable bug on Zen guests to allow for live migration. */ (cpu_has(c, X86_FEATURE_HYPERVISOR) && cpu_has(c, X86_FEATURE_ZEN))) diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 99801e844b305d..acbcec394ef168 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -93,6 +93,7 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL }, { X86_FEATURE_LASS, X86_FEATURE_SMAP }, { X86_FEATURE_INVLPGB, X86_FEATURE_PCID }, + { X86_FEATURE_RMPOPT, X86_FEATURE_SEV_SNP }, {} }; diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c index 4049235b1bfe4a..5df85c30b50764 100644 --- a/arch/x86/kernel/cpu/mtrr/if.c +++ b/arch/x86/kernel/cpu/mtrr/if.c @@ -43,7 +43,7 @@ mtrr_file_add(unsigned long base, unsigned long size, max = num_var_ranges; if (fcount == NULL) { - fcount = kcalloc(max, sizeof(*fcount), GFP_KERNEL); + fcount = kzalloc_objs(*fcount, max); if (!fcount) return -ENOMEM; FILE_FCOUNT(file) = fcount; diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 55214d6fdc49a8..bd9e4cf9f7cb95 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -408,8 +408,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_ctrl_domain * struct msr_param m; u32 *dc; - dc = kmalloc_array(hw_res->num_closid, sizeof(*hw_dom->ctrl_val), - GFP_KERNEL); + dc = kmalloc_objs(*hw_dom->ctrl_val, hw_res->num_closid); if (!dc) return -ENOMEM; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index e3cfa0c10e92dd..ffd74a68671b00 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -214,8 +214,8 @@ union l3_qos_abmc_cfg { bw_src :12, reserved1: 3, is_clos : 1, - cntr_id : 5, - reserved : 9, + cntr_id :12, + reserved : 2, cntr_en : 1, cfg_en : 1; } split; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 3838e0a13d36f7..a6a9090c4808ce 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -470,8 +470,8 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r) r->mon.mbm_cntr_assignable = true; r->mon.mbm_cntr_configurable = true; cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); - r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1; - hw_res->mbm_cntr_assign_enabled = true; + /* cntr_id is 12 bits and can only encode 4096 counters. */ + r->mon.num_mbm_cntrs = min((ebx & GENMASK(15, 0)) + 1, BIT(12)); } r->mon_capable = true; diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index d867ab90d42a54..c990245d29d600 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -65,6 +65,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_AMD_WORKLOAD_CLASS, CPUID_EAX, 22, 0x80000021, 0 }, { X86_FEATURE_TSA_SQ_NO, CPUID_ECX, 1, 0x80000021, 0 }, { X86_FEATURE_TSA_L1_NO, CPUID_ECX, 2, 0x80000021, 0 }, + { X86_FEATURE_TSA_FILL_NO, CPUID_ECX, 7, 0x80000021, 0 }, { X86_FEATURE_BTB_CTX_ISOLATION, CPUID_ECX, 8, 0x80000021, 0 }, { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index 62c1c93aa1c6a6..4b20673a33959e 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -286,9 +286,9 @@ SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL) RET 1: - testb $1, %al - jz 2f - andq $0xfffffffffffffffe, %rax + /* See ftrace_jmp_set(), jmp to the trampoline */ + btsq $63, %rax + jc 2f movq %rax, MCOUNT_REG_SIZE+8(%rsp) restore_mcount_regs /* Restore flags */ diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c index 4fa7a86adece1f..c4bbb417659114 100644 --- a/arch/x86/kernel/ldt.c +++ b/arch/x86/kernel/ldt.c @@ -43,7 +43,7 @@ void load_mm_ldt(struct mm_struct *mm) { struct ldt_struct *ldt; - /* READ_ONCE synchronizes with smp_store_release */ + /* Pairs with WRITE_ONCE() in install_ldt() */ ldt = READ_ONCE(mm->context.ldt); /* @@ -422,8 +422,14 @@ static void install_ldt(struct mm_struct *mm, struct ldt_struct *ldt) { mutex_lock(&mm->context.lock); - /* Synchronizes with READ_ONCE in load_mm_ldt. */ - smp_store_release(&mm->context.ldt, ldt); + /* + * Ensure that new mm user CPUs either see the new LDT value + * or get an IPI. Make the store visible before reading + * mm_cpumask(). New mm users make their mm_cpumask() writes + * visible before reading mm->context.ldt. + */ + WRITE_ONCE(mm->context.ldt, ldt); + smp_mb(); /* Activate the LDT for all CPUs using currents mm. */ on_each_cpu_mask(mm_cpumask(mm), flush_ldt, mm, true); diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 3c9f60d6ca5a76..cb46da482c8558 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c @@ -115,6 +115,14 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration) { int remainder_ns, decimal_msecs; + /* sched_clock() went backwards? */ + if ((s64)duration < 0) { + pr_warn_once("NMI handler (%ps): sched_clock() went backwards by %lld ns on CPU%d\n", + action->handler, -(s64)duration, + smp_processor_id()); + return; + } + if (duration < nmi_longest_ns || duration < action->max_duration) return; diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 252c5827d0634f..3b9b41820c84cc 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { } bool __init bool_x86_init_noop(void) { return false; } void x86_op_int_noop(int cpu) { } int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; } -void get_rtc_noop(struct timespec64 *now) { } +void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; } static __initconst const struct of_device_id of_cmos_match[] = { { .compatible = "motorola,mc146818" }, diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index adafd6fa2c5427..e267454b6c3de7 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1254,6 +1254,7 @@ void kvm_initialize_cpu_caps(void) kvm_cpu_cap_init(CPUID_8000_0021_ECX, SYNTHESIZED_F(TSA_SQ_NO), SYNTHESIZED_F(TSA_L1_NO), + SYNTHESIZED_F(TSA_FILL_NO), ); kvm_cpu_cap_init(CPUID_8000_0022_EAX, diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c index 0074a56e45b44b..9dde80022fb969 100644 --- a/arch/x86/kvm/debugfs.c +++ b/arch/x86/kvm/debugfs.c @@ -103,7 +103,7 @@ static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v) ret = -ENOMEM; memset(log, 0, sizeof(log)); for (i = 0; i < KVM_NR_PAGE_SIZES; i++) { - log[i] = kcalloc(RMAP_LOG_SIZE, sizeof(unsigned int), GFP_KERNEL); + log[i] = kzalloc_objs(unsigned int, RMAP_LOG_SIZE); if (!log[i]) goto out; } diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index dc2aef72ffddce..f89e9f8a6cc2f8 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2359,6 +2359,16 @@ static struct kvm_mmu_page *kvm_mmu_find_shadow_page(struct kvm *kvm, continue; } + /* + * Note! Unlike fully direct MMUs, direct SPs in indirect MMUs + * can have an arbitrary number of parents, e.g if the guest is + * mapping a huge PTE at many points in its page tables. + */ + if (pte_list_count(&sp->parent_ptes) >= RMAP_RECYCLE_THRESHOLD) { + kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list); + break; + } + /* unsync and write-flooding only apply to indirect SPs. */ if (sp->role.direct) goto out; diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index dc86c2ae70c9c3..939a10fc11107d 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -339,6 +339,13 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, gpa_t real_gpa; gfn_t gfn; + /* + * KVM might sleep/resched when retrying the walk if the updating A/D + * fails because the gPTE changed between reading the gPTE and trying + * the CMPXHG to set A/D bits. + */ + might_sleep(); + trace_kvm_mmu_pagetable_walk(addr, access); retry_walk: walker->level = w->cpu_role.base.level; @@ -481,8 +488,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, addr, write_fault); if (unlikely(ret < 0)) goto error; - else if (ret) + else if (ret) { + cond_resched(); goto retry_walk; + } } return 1; diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 89345af0f7ad67..b7a559962626ad 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -77,6 +77,7 @@ /* CPUID level 0x80000021 (ECX) */ #define KVM_X86_FEATURE_TSA_SQ_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 1) #define KVM_X86_FEATURE_TSA_L1_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 2) +#define KVM_X86_FEATURE_TSA_FILL_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 7) struct cpuid_reg { u32 function; @@ -153,6 +154,7 @@ static __always_inline u32 __feature_translate(int x86_feature) KVM_X86_TRANSLATE_FEATURE(TSA_SQ_NO); KVM_X86_TRANSLATE_FEATURE(TSA_L1_NO); KVM_X86_TRANSLATE_FEATURE(MSR_IMM); + KVM_X86_TRANSLATE_FEATURE(TSA_FILL_NO); default: return x86_feature; } diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index af0ef678433d72..07554089ec05b3 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1889,6 +1889,21 @@ static void nested_copy_vmcb_cache_to_control(struct vmcb_control_area *dst, /* 'clean' and 'hv_enlightenments' are not changed by KVM */ } +bool nested_svm_check_vmcb01_save(struct kvm_vcpu *vcpu, + struct vmcb_save_area *save) +{ + struct vmcb_save_area_cached save_cached; + + if (!(save->cr0 & X86_CR0_PG) || + !(save->cr0 & X86_CR0_PE) || + (save->rflags & X86_EFLAGS_VM) || + ((save->efer & EFER_LMA) && !(save->efer & EFER_LME))) + return false; + + __nested_copy_vmcb_save_to_cache(&save_cached, save); + return nested_vmcb_check_save(vcpu, &save_cached, false); +} + static int svm_get_nested_state(struct kvm_vcpu *vcpu, struct kvm_nested_state __user *user_kvm_nested_state, u32 user_data_size) @@ -1968,7 +1983,6 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, &user_kvm_nested_state->data.svm[0]; struct vmcb_control_area *ctl; struct vmcb_save_area *save; - struct vmcb_save_area_cached save_cached; struct vmcb_ctrl_area_cached ctl_cached; bool use_separate_l2_pat; unsigned long cr0; @@ -2040,12 +2054,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, * KVM_GET_NESTED_STATE, and (b) it is not loaded at emulated * #VMEXIT. */ - __nested_copy_vmcb_save_to_cache(&save_cached, save); - if (!(save->cr0 & X86_CR0_PG) || - !(save->cr0 & X86_CR0_PE) || - (save->rflags & X86_EFLAGS_VM) || - ((save->efer & EFER_LMA) && !(save->efer & EFER_LME)) || - !nested_vmcb_check_save(vcpu, &save_cached, false)) + if (!nested_svm_check_vmcb01_save(vcpu, save)) goto out_free; /* diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 136069dfcd44f6..e30ee80624b726 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -5223,6 +5223,8 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram) */ svm_copy_vmrun_state(vcpu, &svm->vmcb01.ptr->save, m_save.map.hva + 0x400); + if (!nested_svm_check_vmcb01_save(vcpu, &svm->vmcb01.ptr->save)) + return 1; /* * Enter the nested guest now diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6d0242966dc871..cd3242811e430d 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -911,6 +911,8 @@ void nested_copy_vmcb_control_to_cache(struct vcpu_svm *svm, void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm, struct vmcb_save_area *save); void nested_sync_control_from_vmcb02(struct vcpu_svm *svm); +bool nested_svm_check_vmcb01_save(struct kvm_vcpu *vcpu, + struct vmcb_save_area *save); void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb); diff --git a/arch/x86/kvm/vmx/hyperv_evmcs.h b/arch/x86/kvm/vmx/hyperv_evmcs.h index bc08fe40590e9a..052b62b8ed8ec5 100644 --- a/arch/x86/kvm/vmx/hyperv_evmcs.h +++ b/arch/x86/kvm/vmx/hyperv_evmcs.h @@ -136,6 +136,8 @@ static __always_inline int evmcs_field_offset(unsigned long field, if (unlikely(index >= nr_evmcs_1_fields)) return -ENOENT; + index = array_index_nospec(index, nr_evmcs_1_fields); + evmcs_field = &vmcs_field_to_evmcs_1[index]; /* diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 516ba03bf60835..879183c1bfa5b4 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -5059,6 +5059,7 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu) __func__, j, h.index, h.value); goto vmabort; } + break; } } diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 8a593159c9b7cc..c213c0eba919f0 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -3024,8 +3024,9 @@ static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx) */ tdx->vp.tdvpr_pa = page_to_phys(tdx->vp.tdvpr_page); - tdx->vp.tdcx_pages = kcalloc(kvm_tdx->td.tdcx_nr_pages, sizeof(*tdx->vp.tdcx_pages), - GFP_KERNEL_ACCOUNT); + tdx->vp.tdcx_pages = kzalloc_objs(*tdx->vp.tdcx_pages, + kvm_tdx->td.tdcx_nr_pages, + GFP_KERNEL_ACCOUNT); if (!tdx->vp.tdcx_pages) { ret = -ENOMEM; goto free_tdvpr; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 32563a91fba99a..26e7beaff8a03c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6558,10 +6558,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, } else if (vcpu->arch.complete_userspace_io) { writeback = false; r = 0; - } else if (r == EMULATION_RESTART) + } else if (r == EMULATION_RESTART) { + cond_resched(); goto restart; - else + } else { r = 1; + } writeback: if (writeback) { @@ -9730,29 +9732,31 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_x86_call(update_exception_bitmap)(vcpu); /* - * On the standard CR0/CR4/EFER modification paths, there are several - * complex conditions determining whether the MMU has to be reset and/or - * which PCIDs have to be flushed. However, CR0.WP and the paging-related - * bits in CR4 and EFER are irrelevant if CR0.PG was '0'; and a reset+flush - * is needed anyway if CR0.PG was '1' (which can only happen for INIT, as - * CR0 will be '0' prior to RESET). So we only need to check CR0.PG here. + * Unconditionally reset the MMU, even though super strictly speaking, + * a MMU reset is only necessary if and only one of the page role bits + * is changing. All of the CR0/CR4/EFER bits effectively get covered + * by checking CR0.PG=1, as CR0.WP and the paging-related bits in CR4 + * and EFER are irrelevant if CR0.PG was '0'. Subtly, if the vCPU was + * in guest mode (L2) or SMM (although emulating INIT in SMM _should_ + * be impossible), an MMU reset is also necessary as "guest mode" and + * "smm" are both encoded in the shadow page role. As a result, the + * only scenarios where an MMU reset is *not* needed is if the vCPU is + * in Real Mode or Unpaged Protected Mode, and micro-optimizing those + * paths are not worth the risk of running with a stale MMU context. */ - if (old_cr0 & X86_CR0_PG) { - kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); - kvm_mmu_reset_context(vcpu); - } + kvm_mmu_reset_context(vcpu); /* - * Intel's SDM states that all TLB entries are flushed on INIT. AMD's - * APM states the TLBs are untouched by INIT, but it also states that - * the TLBs are flushed on "External initialization of the processor." - * Flush the guest TLB regardless of vendor, there is no meaningful - * benefit in relying on the guest to flush the TLB immediately after - * INIT. A spurious TLB flush is benign and likely negligible from a - * performance perspective. + * Intel's SDM states that all TLB entries are flushed on INIT "as with + * a hardware reset", and AMD's APM states the TLBs are flushed on + * "External initialization of the processor". Flush the guest TLB for + * both RESET and INIT, regardless of vendor, even though both the SDM + * and APM contradict the above statements in other tables. There is + * no meaningful benefit in relying on the guest to flush the TLB, and + * a spurious TLB flush is benign and likely negligible from a + * performance perspective (especially for RESET). */ - if (init_event) - kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); } EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_vcpu_reset); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 0c4da320831cb7..53dcab39566f23 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -320,13 +320,19 @@ static u16 allocate_global_asid(void) lockdep_assert_held(&global_asid_lock); - /* The previous allocation hit the edge of available address space */ - if (last_global_asid >= MAX_ASID_AVAILABLE - 1) - reset_global_asid_space(); - asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, last_global_asid); - if (asid >= MAX_ASID_AVAILABLE && !global_asid_available) { + /* + * Nothing is free between last_global_asid and MAX_ASID_AVAILABLE. + * Flush lazy-freed ASIDs and reset the search space. + */ + if (asid >= MAX_ASID_AVAILABLE) { + reset_global_asid_space(); + asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, + last_global_asid); + } + + if (asid >= MAX_ASID_AVAILABLE) { /* This should never happen. */ VM_WARN_ONCE(1, "Unable to allocate global ASID despite %d available\n", global_asid_available); diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index d90b6d238b3a2e..4c3e09d98131d2 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -2626,8 +2626,13 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int * * Arg 6 goes into r9 register, not on stack. */ outgoing_rsp = out_stack_arg_cnt > 1 ? (out_stack_arg_cnt - 1) * 8 : 0; + /* + * bpf_throw() sees rsp of this frame as it is at a call. The callee-saved + * regs are above the outgoing args, or above r9, which is pushed around + * every call when the stack is private. + */ if (bpf_prog->aux->exception_boundary) - bpf_prog->aux->stack_arg_sp_adjust = outgoing_rsp; + bpf_prog->aux->stack_arg_sp_adjust = outgoing_rsp + (priv_frame_ptr ? 8 : 0); emit_sub_rsp(&prog, outgoing_rsp); if (arena_vm_start) @@ -3436,18 +3441,6 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int * ip += emit_kfunc_arg_moves(fm, outgoing_arg_base - outgoing_rsp, &prog); } - if (func == (u8 *)arch_bpf_timed_may_goto) { - u32 fp = priv_frame_ptr ? X86_REG_R9 : BPF_REG_FP; - - /* - * AX has the offset of count and timestamp - * in the stack. Turn it into a pointer. - * add r10, rbp or add r10, r9 - */ - maybe_emit_mod(&prog, BPF_REG_AX, fp, true); - EMIT2(0x01, add_2reg(0xC0, BPF_REG_AX, fp)); - ip += 3; - } if (priv_frame_ptr) { push_r9(&prog); ip += 2; diff --git a/arch/x86/net/bpf_timed_may_goto.S b/arch/x86/net/bpf_timed_may_goto.S index dd2dde89836b8f..da42de7cca9882 100644 --- a/arch/x86/net/bpf_timed_may_goto.S +++ b/arch/x86/net/bpf_timed_may_goto.S @@ -25,10 +25,7 @@ SYM_FUNC_START(arch_bpf_timed_may_goto) /* Save stack argument 6. */ pushq %r9 - /* - * r10 has the pointer to count and timestamp. JIT added the frame - * pointer to the offset. Pass it as first argument. - */ + /* r10 has the pointer to count and timestamp. Pass it as first argument. */ movq %r10, %rdi /* Emit call depth accounting for call below. */ diff --git a/arch/x86/platform/intel-mid/pwr.c b/arch/x86/platform/intel-mid/pwr.c index cd7e0c71addef6..3b1ca888c23fe4 100644 --- a/arch/x86/platform/intel-mid/pwr.c +++ b/arch/x86/platform/intel-mid/pwr.c @@ -358,7 +358,7 @@ static int mid_pwr_probe(struct pci_dev *pdev, const struct pci_device_id *id) return ret; } - pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); + pwr = devm_kzalloc_obj(dev, *pwr); if (!pwr) return -ENOMEM; diff --git a/arch/x86/video/video-common.c b/arch/x86/video/video-common.c index 8ed82fff7638ed..b8f83346dfe8a0 100644 --- a/arch/x86/video/video-common.c +++ b/arch/x86/video/video-common.c @@ -45,7 +45,7 @@ bool video_is_primary_device(struct device *dev) #ifdef CONFIG_SCREEN_INFO numres = screen_info_resources(si, res, ARRAY_SIZE(res)); - if (numres > 0) { + if (numres > 0 && __screen_info_has_lfb(screen_info_video_type(si))) { for (i = 0; i < numres; ++i) { if (!(res[i].flags & IORESOURCE_MEM)) continue; diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index bd70c4d0b774a3..4de9681cc2f80f 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -662,17 +662,16 @@ static int __init rmpopt_init(void) return 0; } -device_initcall(rmpopt_init); void snp_enable_rmpopt(void) { u64 base; int cpu; - if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) return; - if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) return; if (!rmpopt_soft_init) @@ -726,6 +725,8 @@ int __init snp_rmptable_init(void) */ crash_kexec_post_notifiers = true; + rmpopt_init(); + return 0; } @@ -819,18 +820,11 @@ bool snp_probe_rmptable_info(void) { if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP)) { rdmsrq(MSR_AMD64_RMP_CFG, rmp_cfg); - - if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) { - if (probe_segmented_rmptable_info()) - return true; - - setup_clear_cpu_cap(X86_FEATURE_RMPOPT); - return false; - } - } else { - setup_clear_cpu_cap(X86_FEATURE_RMPOPT); + if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) + return probe_segmented_rmptable_info(); } + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); return probe_contiguous_rmptable_info(); } diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 1c1fe07a96eafa..1c1025157d8e48 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -2936,6 +2936,9 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns) return; + if (unlikely(rq->rq_flags & RQF_FLUSH_SEQ)) + return; + switch (req_op(rq)) { case REQ_OP_READ: pidx = QOS_RLAT; diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 0a00f5a76f5a87..d7b45778732b8f 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -374,7 +374,7 @@ bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq, } EXPORT_SYMBOL_GPL(blk_mq_sched_try_insert_merge); -/* called in queue's release handler, tagset has gone away */ +/* Clear scheduler tags and reset queue state. */ static void blk_mq_sched_tags_teardown(struct request_queue *q, unsigned int flags) { struct blk_mq_hw_ctx *hctx; @@ -385,6 +385,10 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q, unsigned int fla if (blk_mq_is_shared_tags(flags)) q->sched_shared_tags = NULL; + + blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q); + q->nr_requests = q->tag_set->queue_depth; + q->async_depth = q->tag_set->queue_depth; } void blk_mq_sched_reg_debugfs(struct request_queue *q) diff --git a/block/blk-mq.c b/block/blk-mq.c index d9ab295be4d92a..5ae22d55654044 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3160,8 +3160,15 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; } + /* + * The block layer cannot generate or verify PI for a dma-buf bio, as + * that walks the data pages. Only fail the bio if it needs that, not + * if the submitter attached its own integrity payload or if PI + * generation or verification is turned off for the device. + */ if (unlikely(op_is_dmabuf(bio->bi_opf) && - bdev_has_integrity_csum(bio->bi_bdev))) { + bdev_has_integrity_csum(bio->bi_bdev) && + (bio_integrity_action(bio) & BI_ACT_CHECK))) { bio_endio_status(bio, BLK_STS_NOTSUPP); goto queue_exit; } @@ -3209,16 +3216,15 @@ void blk_mq_submit_bio(struct bio *bio) blk_mq_bio_to_request(rq, bio, nr_segs); + if (bio_zone_write_plugging(bio)) + blk_zone_write_plug_init_request(rq); + ret = blk_crypto_rq_get_keyslot(rq); if (ret != BLK_STS_OK) { - bio_endio_status(bio, ret); - blk_mq_free_request(rq); + blk_mq_end_request(rq, ret); return; } - if (bio_zone_write_plugging(bio)) - blk_zone_write_plug_init_request(rq); - if (op_is_flush(bio->bi_opf) && blk_insert_flush(rq)) return; @@ -3501,8 +3507,10 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, if (blk_mq_is_shared_tags(set->flags)) drv_tags = set->shared_tags; - else + else if (hctx_idx < set->nr_hw_queues) drv_tags = set->tags[hctx_idx]; + else + drv_tags = NULL; if (tags->static_rqs && set->ops->exit_request) { int i; diff --git a/block/blk.h b/block/blk.h index ed21724726223f..0e38e4b88cf544 100644 --- a/block/blk.h +++ b/block/blk.h @@ -418,6 +418,8 @@ static inline bool bio_may_need_split(struct bio *bio, if (!bio->bi_io_vec) return true; + if (op_is_dmabuf(bio->bi_opf)) + return true; bv = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); if (bio->bi_iter.bi_size > bv->bv_len - bio->bi_iter.bi_offset) diff --git a/block/elevator.c b/block/elevator.c index 2161b6eea680ca..66edf1a5768a86 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -812,25 +812,29 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf, * reference during concurrent disk deletion: * update_nr_hwq_lock -> kn->active (via del_gendisk -> kobject_del) * kn->active -> update_nr_hwq_lock (via this sysfs write path) - * - * Use the writer lock instead of the reader lock of update_nr_hwq_lock - * to serialize the two-stage elevator switch steps in - * elevator_change(): the core switch step under the elevator lock and - * the elevator_change_done() step outside the elevator lock. */ - if (!down_write_trylock(&set->update_nr_hwq_lock)) { + if (!down_read_trylock(&set->update_nr_hwq_lock)) { ret = -EBUSY; goto out; } - if (!blk_queue_no_elv_switch(q)) { - ret = elevator_change(q, &ctx); - if (!ret) - ret = count; - } else { - ret = -ENOENT; + + /* + * The reader lock is shared, so use QUEUE_FLAG_NO_ELV_SWITCH to allow + * only one switch of this queue at a time, and none once the disk is + * going away. + */ + if (test_and_set_bit(QUEUE_FLAG_NO_ELV_SWITCH, &q->queue_flags)) { + ret = -EBUSY; + goto out_unlock; } - up_write(&set->update_nr_hwq_lock); + ret = elevator_change(q, &ctx); + if (!ret) + ret = count; + + blk_queue_flag_clear(QUEUE_FLAG_NO_ELV_SWITCH, q); +out_unlock: + up_read(&set->update_nr_hwq_lock); out: if (ctx.type) elevator_put(ctx.type); diff --git a/block/fops.c b/block/fops.c index e5c27cc35ca1fd..0843797784139d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -467,10 +467,6 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, static DEFINE_IOMAP_ITER_NEXT(blkdev_iomap_next, blkdev_iomap_begin); -static const struct iomap_ops blkdev_iomap_ops = { - .iomap_next = blkdev_iomap_next, -}; - #ifdef CONFIG_BUFFER_HEAD static int blkdev_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh, int create) @@ -524,13 +520,13 @@ const struct address_space_operations def_blk_aops = { #else /* CONFIG_BUFFER_HEAD */ static int blkdev_read_folio(struct file *file, struct folio *folio) { - iomap_bio_read_folio(folio, &blkdev_iomap_ops); + iomap_bio_read_folio(folio, blkdev_iomap_next); return 0; } static void blkdev_readahead(struct readahead_control *rac) { - iomap_bio_readahead(rac, &blkdev_iomap_ops); + iomap_bio_readahead(rac, blkdev_iomap_next); } static ssize_t blkdev_writeback_range(struct iomap_writepage_ctx *wpc, @@ -736,7 +732,7 @@ static ssize_t blkdev_buffered_write(struct kiocb *iocb, struct iov_iter *from) * i_blkbits/folio order and truncating the page cache. */ inode_lock_shared(inode); - ret = iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops, NULL, + ret = iomap_file_buffered_write(iocb, from, blkdev_iomap_next, NULL, NULL); inode_unlock_shared(inode); return ret; @@ -1018,8 +1014,6 @@ static int blkdev_init_dma_buf_io_ctx(struct file *file, return -EINVAL; if (!disk->fops->init_dma_buf_io_ctx) return -EOPNOTSUPP; - if (bdev_has_integrity_csum(bdev)) - return -EOPNOTSUPP; return disk->fops->init_dma_buf_io_ctx(bdev, ctx); } diff --git a/block/genhd.c b/block/genhd.c index 10ca8b4d6eea7e..69204d44adae11 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1146,7 +1146,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev, { struct gendisk *disk = dev_to_disk(dev); - return sysfs_emit(buf, "%d\n", bdev_alignment_offset(disk->part0)); + return sysfs_emit(buf, "%u\n", bdev_discard_alignment(disk->part0)); } static ssize_t diskseq_show(struct device *dev, diff --git a/block/ioctl.c b/block/ioctl.c index 64b4e6c0f69651..fb2f4b4d2505ed 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -835,8 +835,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return compat_put_ulong(argp, bdev_nr_sectors(bdev)); /* The data is compatible, but the command number is different */ - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return put_int(argp, bdev_logical_block_size(bdev)); + case BLKBSZGET_32: /* get the soft block size (cf. BLKSSZGET) */ + return put_int(argp, block_size(bdev)); case BLKBSZSET_32: return blkdev_bszset(file, mode, argp); case BLKGETSIZE64_32: diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 9865d59093fac0..b31227a13db0be 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -460,6 +460,7 @@ static inline int is_pte_valid(const gpt_entry *pte, const u64 lastlba) { if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) || + le64_to_cpu(pte->starting_lba) > le64_to_cpu(pte->ending_lba) || le64_to_cpu(pte->starting_lba) > lastlba || le64_to_cpu(pte->ending_lba) > lastlba) return 0; diff --git a/crypto/asymmetric_keys/verify_pefile.c b/crypto/asymmetric_keys/verify_pefile.c index 1efd5c0d0e9ce4..b83d1f1e19a3a7 100644 --- a/crypto/asymmetric_keys/verify_pefile.c +++ b/crypto/asymmetric_keys/verify_pefile.c @@ -272,7 +272,7 @@ static int pefile_digest_pe_contents(const void *pebuf, unsigned int pelen, if (ret < 0) return ret; - canon = kcalloc(ctx->n_sections, sizeof(unsigned), GFP_KERNEL); + canon = kzalloc_objs(unsigned, ctx->n_sections); if (!canon) return -ENOMEM; diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 3d07dd5de4fada..f834be86788a48 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -439,7 +439,7 @@ struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev, if (!dev) return NULL; - engine = devm_kzalloc(dev, sizeof(*engine), GFP_KERNEL); + engine = devm_kzalloc_obj(dev, *engine); if (!engine) return NULL; diff --git a/crypto/essiv.c b/crypto/essiv.c index a47a3eab693519..3505b2769d93c9 100644 --- a/crypto/essiv.c +++ b/crypto/essiv.c @@ -250,7 +250,7 @@ static int essiv_aead_crypt(struct aead_request *req, bool enc) err = enc ? crypto_aead_encrypt(subreq) : crypto_aead_decrypt(subreq); - if (rctx->assoc && err != -EINPROGRESS && err != -EBUSY) + if (err != -EINPROGRESS && err != -EBUSY) kfree(rctx->assoc); return err; } diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c index 9c6b7353cbe9b3..d3e46a0c4b3d7f 100644 --- a/drivers/accel/amdxdna/aie2_ctx.c +++ b/drivers/accel/amdxdna/aie2_ctx.c @@ -566,7 +566,7 @@ static int aie2_hwctx_col_list(struct amdxdna_hwctx *hwctx) return -EINVAL; } - hwctx->col_list = kmalloc_array(entries, sizeof(*hwctx->col_list), GFP_KERNEL); + hwctx->col_list = kmalloc_objs(*hwctx->col_list, entries); if (!hwctx->col_list) return -ENOMEM; diff --git a/drivers/accel/amdxdna/amdxdna_ctx.c b/drivers/accel/amdxdna/amdxdna_ctx.c index 888e857ec55820..a089a7990675c6 100644 --- a/drivers/accel/amdxdna/amdxdna_ctx.c +++ b/drivers/accel/amdxdna/amdxdna_ctx.c @@ -712,7 +712,7 @@ static int amdxdna_drm_submit_execbuf(struct amdxdna_client *client, cmd_bo_hdl = (u32)args->cmd_handles; if (args->arg_count) { - arg_bo_hdls = kcalloc(args->arg_count, sizeof(u32), GFP_KERNEL); + arg_bo_hdls = kzalloc_objs(u32, args->arg_count); if (!arg_bo_hdls) return -ENOMEM; ret = copy_from_user(arg_bo_hdls, u64_to_user_ptr(args->args), diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index ba4257bda77bfc..8a3febc2089edd 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -947,11 +947,12 @@ static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx, goto free_cs; } - cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, - sizeof(*cs->jobs_in_queue_cnt), GFP_ATOMIC); + cs->jobs_in_queue_cnt = kzalloc_objs(*cs->jobs_in_queue_cnt, + hdev->asic_prop.max_queues, + GFP_ATOMIC); if (!cs->jobs_in_queue_cnt) - cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, - sizeof(*cs->jobs_in_queue_cnt), GFP_KERNEL); + cs->jobs_in_queue_cnt = kzalloc_objs(*cs->jobs_in_queue_cnt, + hdev->asic_prop.max_queues); if (!cs->jobs_in_queue_cnt) { atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt); @@ -1899,13 +1900,11 @@ static int cs_ioctl_extract_signal_seq(struct hl_device *hdev, return -EINVAL; } - signal_seq_arr = kmalloc_array(signal_seq_arr_len, - sizeof(*signal_seq_arr), - GFP_ATOMIC); + signal_seq_arr = kmalloc_objs(*signal_seq_arr, signal_seq_arr_len, + GFP_ATOMIC); if (!signal_seq_arr) - signal_seq_arr = kmalloc_array(signal_seq_arr_len, - sizeof(*signal_seq_arr), - GFP_KERNEL); + signal_seq_arr = kmalloc_objs(*signal_seq_arr, + signal_seq_arr_len); if (!signal_seq_arr) { atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt); atomic64_inc(&hdev->aggregated_cs_counters.out_of_mem_drop_cnt); @@ -2479,7 +2478,7 @@ static int cs_ioctl_engine_cores(struct hl_fpriv *hpriv, u64 engine_cores, } engine_cores_arr = (void __user *) (uintptr_t) engine_cores; - cores = kmalloc_array(num_engine_cores, sizeof(u32), GFP_KERNEL); + cores = kmalloc_objs(u32, num_engine_cores); if (!cores) return -ENOMEM; @@ -2521,7 +2520,7 @@ static int cs_ioctl_engines(struct hl_fpriv *hpriv, u64 engines_arr_user_addr, } engines_arr = (void __user *) (uintptr_t) engines_arr_user_addr; - engines = kmalloc_array(num_engines, sizeof(u32), GFP_KERNEL); + engines = kmalloc_objs(u32, num_engines); if (!engines) return -ENOMEM; @@ -3037,7 +3036,7 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) /* allocate memory for sequence array */ cs_seq_arr = - kmalloc_array(seq_arr_len, sizeof(*cs_seq_arr), GFP_KERNEL); + kmalloc_objs(*cs_seq_arr, seq_arr_len); if (!cs_seq_arr) return -ENOMEM; diff --git a/drivers/accel/habanalabs/common/hwmon.c b/drivers/accel/habanalabs/common/hwmon.c index 768604d2392de4..cf3b0d9c3dea52 100644 --- a/drivers/accel/habanalabs/common/hwmon.c +++ b/drivers/accel/habanalabs/common/hwmon.c @@ -178,7 +178,7 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev, struct cpucp_sensor *sen num_sensors_for_type = counts[i] + 1; dev_dbg(hdev->dev, "num_sensors_for_type %d = %d\n", i, num_sensors_for_type); - curr_arr = kcalloc(num_sensors_for_type, sizeof(*curr_arr), GFP_KERNEL); + curr_arr = kzalloc_objs(*curr_arr, num_sensors_for_type); if (!curr_arr) { rc = -ENOMEM; goto sensors_type_err; diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c index 361cff57738140..2f76776b40393e 100644 --- a/drivers/accel/habanalabs/common/memory.c +++ b/drivers/accel/habanalabs/common/memory.c @@ -139,7 +139,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args, phys_pg_pack->flags = args->flags; phys_pg_pack->contiguous = contiguous; - phys_pg_pack->pages = kvmalloc_array(num_pgs, sizeof(u64), GFP_KERNEL); + phys_pg_pack->pages = kvmalloc_objs(u64, num_pgs); if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) { rc = -ENOMEM; goto pages_arr_err; @@ -885,8 +885,7 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx, page_mask = ~(((u64) page_size) - 1); - phys_pg_pack->pages = kvmalloc_array(total_npages, sizeof(u64), - GFP_KERNEL); + phys_pg_pack->pages = kvmalloc_objs(u64, total_npages); if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) { rc = -ENOMEM; goto page_pack_arr_mem_err; diff --git a/drivers/accel/habanalabs/gaudi/gaudi.c b/drivers/accel/habanalabs/gaudi/gaudi.c index 5ddb38aaff7a17..21387d1f01c9a9 100644 --- a/drivers/accel/habanalabs/gaudi/gaudi.c +++ b/drivers/accel/habanalabs/gaudi/gaudi.c @@ -8989,14 +8989,12 @@ static int gaudi_print_fences_single_engine( int rc = -ENOMEM, i; u32 *statuses, *fences; - statuses = kcalloc(sds->props[SP_ENGINE_NUM_OF_QUEUES], - sizeof(*statuses), GFP_KERNEL); + statuses = kzalloc_objs(*statuses, sds->props[SP_ENGINE_NUM_OF_QUEUES]); if (!statuses) goto out; - fences = kcalloc(sds->props[SP_ENGINE_NUM_OF_FENCES] * - sds->props[SP_ENGINE_NUM_OF_QUEUES], - sizeof(*fences), GFP_KERNEL); + fences = kzalloc_objs(*fences, + sds->props[SP_ENGINE_NUM_OF_FENCES] * sds->props[SP_ENGINE_NUM_OF_QUEUES]); if (!fences) goto free_status; diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c index ea3a0e57c83678..7445551654613e 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c @@ -2717,7 +2717,7 @@ static int gaudi2_init_pb_sm_objs(struct hl_device *hdev) array_base = gaudi2_pb_dcr0_sm_objs.mm_block_base_addr + gaudi2_pb_dcr0_sm_objs.glbl_sec_offset; - sec_array = kcalloc(glbl_sec_array_len, sizeof(u32), GFP_KERNEL); + sec_array = kzalloc_objs(u32, glbl_sec_array_len); if (!sec_array) return -ENOMEM; diff --git a/drivers/accel/ivpu/ivpu_job.c b/drivers/accel/ivpu/ivpu_job.c index b9b6efea43e800..3d1ba1aa7eeae4 100644 --- a/drivers/accel/ivpu/ivpu_job.c +++ b/drivers/accel/ivpu/ivpu_job.c @@ -914,7 +914,7 @@ static int ivpu_submit(struct drm_file *file, struct ivpu_file_priv *file_priv, u32 *buf_handles; int idx, ret; - buf_handles = kcalloc(buffer_count, sizeof(u32), GFP_KERNEL); + buf_handles = kzalloc_objs(u32, buffer_count); if (!buf_handles) return -ENOMEM; diff --git a/drivers/accel/qaic/mhi_controller.c b/drivers/accel/qaic/mhi_controller.c index c720b70b1e0f40..f47854fb88e27a 100644 --- a/drivers/accel/qaic/mhi_controller.c +++ b/drivers/accel/qaic/mhi_controller.c @@ -1011,7 +1011,7 @@ struct mhi_controller *qaic_mhi_register_controller(struct pci_dev *pci_dev, voi struct mhi_controller *mhi_cntrl; int ret; - mhi_cntrl = devm_kzalloc(&pci_dev->dev, sizeof(*mhi_cntrl), GFP_KERNEL); + mhi_cntrl = devm_kzalloc_obj(&pci_dev->dev, *mhi_cntrl); if (!mhi_cntrl) return ERR_PTR(-ENOMEM); @@ -1032,7 +1032,7 @@ struct mhi_controller *qaic_mhi_register_controller(struct pci_dev *pci_dev, voi mhi_cntrl->regs = mhi_bar; mhi_cntrl->reg_len = SZ_4K; mhi_cntrl->nr_irqs = 1; - mhi_cntrl->irq = devm_kmalloc(&pci_dev->dev, sizeof(*mhi_cntrl->irq), GFP_KERNEL); + mhi_cntrl->irq = devm_kmalloc_obj(&pci_dev->dev, *mhi_cntrl->irq); if (!mhi_cntrl->irq) return ERR_PTR(-ENOMEM); diff --git a/drivers/accel/qaic/qaic_debugfs.c b/drivers/accel/qaic/qaic_debugfs.c index 909a4d774d906f..8ee979fdbe8eb3 100644 --- a/drivers/accel/qaic/qaic_debugfs.c +++ b/drivers/accel/qaic/qaic_debugfs.c @@ -221,7 +221,7 @@ static int qaic_bootlog_mhi_probe(struct mhi_device *mhi_dev, const struct mhi_d qdev->bootlog_ch = mhi_dev; for (i = 0; i < BOOTLOG_POOL_SIZE; i++) { - msg = devm_kzalloc(&qdev->pdev->dev, sizeof(*msg), GFP_KERNEL); + msg = devm_kzalloc_obj(&qdev->pdev->dev, *msg); if (!msg) { ret = -ENOMEM; goto mhi_unprepare; diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c index 9e1e184efe0d1a..90c0d31e414ae2 100644 --- a/drivers/accel/qaic/qaic_drv.c +++ b/drivers/accel/qaic/qaic_drv.c @@ -415,7 +415,7 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev, struct drm_device *drm; int i, ret; - qdev = devm_kzalloc(dev, struct_size(qdev, dbc, DBC_NUM), GFP_KERNEL); + qdev = devm_kzalloc_flex(dev, *qdev, dbc, DBC_NUM); if (!qdev) return NULL; diff --git a/drivers/accel/qaic/sahara.c b/drivers/accel/qaic/sahara.c index e951181e424f21..18884b4ac5c6a9 100644 --- a/drivers/accel/qaic/sahara.c +++ b/drivers/accel/qaic/sahara.c @@ -800,7 +800,7 @@ static int sahara_mhi_probe(struct mhi_device *mhi_dev, const struct mhi_device_ int ret; int i; - context = devm_kzalloc(&mhi_dev->dev, sizeof(*context), GFP_KERNEL); + context = devm_kzalloc_obj(&mhi_dev->dev, *context); if (!context) return -ENOMEM; diff --git a/drivers/accel/rocket/rocket_device.c b/drivers/accel/rocket/rocket_device.c index efd004194c1afc..db137e2ec15eeb 100644 --- a/drivers/accel/rocket/rocket_device.c +++ b/drivers/accel/rocket/rocket_device.c @@ -33,7 +33,7 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev, rdev->max_cores = num_cores; - rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL); + rdev->cores = devm_kzalloc_objs(dev, *rdev->cores, num_cores); if (!rdev->cores) return ERR_PTR(-ENOMEM); diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index f19d6dd43473a2..14a06c9c6380ef 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -202,7 +202,7 @@ static int acpi_ac_probe(struct platform_device *pdev) if (!adev) return -ENODEV; - ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL); + ac = devm_kzalloc_obj(dev, *ac); if (!ac) return -ENOMEM; diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c index 9fc667d6776c83..ea226fd987567c 100644 --- a/drivers/acpi/acpi_apd.c +++ b/drivers/acpi/acpi_apd.c @@ -72,7 +72,7 @@ static int fch_misc_setup(struct apd_private_data *pdata) struct list_head resource_list; int ret; - clk_data = devm_kzalloc(&adev->dev, sizeof(*clk_data), GFP_KERNEL); + clk_data = devm_kzalloc_obj(&adev->dev, *clk_data); if (!clk_data) return -ENOMEM; diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c index 45459a4cafae30..5fcb0bee37102c 100644 --- a/drivers/acpi/acpi_tad.c +++ b/drivers/acpi/acpi_tad.c @@ -853,7 +853,7 @@ static int acpi_tad_probe(struct platform_device *pdev) if (!(caps & ACPI_TAD_AC_WAKE)) caps &= ~ACPI_TAD_DC_WAKE; - dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, *dd); if (!dd) return -ENOMEM; diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c index 15ab797641cfcc..50c98db57e4a5c 100644 --- a/drivers/acpi/apei/erst.c +++ b/drivers/acpi/apei/erst.c @@ -543,8 +543,7 @@ static int __erst_record_id_cache_add_one(void) pr_warn(FW_WARN "too many record IDs!\n"); return 0; } - new_entries = kvmalloc_array(new_size, sizeof(entries[0]), - GFP_KERNEL); + new_entries = kvmalloc_objs(entries[0], new_size); if (!new_entries) return -ENOMEM; memcpy(new_entries, entries, diff --git a/drivers/acpi/apei/ghes-nvidia.c b/drivers/acpi/apei/ghes-nvidia.c index 597275d81de857..bdd797fcb054fc 100644 --- a/drivers/acpi/apei/ghes-nvidia.c +++ b/drivers/acpi/apei/ghes-nvidia.c @@ -112,7 +112,7 @@ static int nvidia_ghes_probe(struct platform_device *pdev) struct nvidia_ghes_private *priv; int ret; - priv = devm_kmalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 663dc2e601cf72..5d888c82efeaa3 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -899,7 +899,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_cper_kfifo_get, "CXL"); static void ghes_log_hwerr(int sev, guid_t *sec_type) { - if (sev != CPER_SEV_RECOVERABLE) + if (sev != GHES_SEV_RECOVERABLE) return; if (guid_equal(sec_type, &CPER_SEC_PROC_ARM) || diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 6edea559a5bceb..1db23627addf88 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1476,7 +1476,7 @@ static int acpi_battery_probe(struct platform_device *pdev) if (device->dep_unmet) return -EPROBE_DEFER; - battery = devm_kzalloc(dev, sizeof(*battery), GFP_KERNEL); + battery = devm_kzalloc_obj(dev, *battery); if (!battery) return -ENOMEM; diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 34c7173b5a6c97..91a4e9698f7aac 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -687,7 +687,7 @@ static int acpi_button_probe(struct platform_device *pdev) lid_init_state == ACPI_BUTTON_LID_INIT_DISABLED) return -ENODEV; - button = devm_kzalloc(dev, sizeof(*button), GFP_KERNEL); + button = devm_kzalloc_obj(dev, *button); if (!button) return -ENOMEM; diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 80e2e6b32ce357..05a547bbe93681 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -913,9 +913,8 @@ static int cpc_register_non_mmio_desc(struct cpc_desc *cpc_desc) if (!found) return 0; - cpc_desc->non_mmio_nodes = kcalloc(nr_regs, - sizeof(*cpc_desc->non_mmio_nodes), - GFP_KERNEL); + cpc_desc->non_mmio_nodes = kzalloc_objs(*cpc_desc->non_mmio_nodes, + nr_regs); if (!cpc_desc->non_mmio_nodes) return -ENOMEM; @@ -1254,9 +1253,7 @@ static int cpc_register_sysmem_desc(struct cpc_desc *cpc_desc) if (!found) return 0; - cpc_desc->sysmem_nodes = kcalloc(nr_regs, - sizeof(*cpc_desc->sysmem_nodes), - GFP_KERNEL); + cpc_desc->sysmem_nodes = kzalloc_objs(*cpc_desc->sysmem_nodes, nr_regs); if (!cpc_desc->sysmem_nodes) return -ENOMEM; diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index a89f10256dbb85..db24a9a252a8e1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -2167,19 +2167,19 @@ static bool acpi_ec_work_in_progress(struct acpi_ec *ec) return ec->events_in_progress + ec->queries_in_progress > 0; } -bool acpi_ec_dispatch_gpe(void) +int acpi_ec_dispatch_gpe(void) { bool work_in_progress = false; if (!first_ec) - return acpi_any_gpe_status_set(U32_MAX); + return -ENODEV; /* * Report wakeup if the status bit is set for any enabled GPE other * than the EC one. */ if (acpi_any_gpe_status_set(first_ec->gpe)) - return true; + return 1; /* * Cancel the SCI wakeup and process all pending events in case there @@ -2207,7 +2207,7 @@ bool acpi_ec_dispatch_gpe(void) spin_unlock_irq(&first_ec->lock); if (!work_in_progress) - return false; + return 0; pm_pr_dbg("ACPI EC GPE dispatched\n"); @@ -2224,7 +2224,7 @@ bool acpi_ec_dispatch_gpe(void) spin_unlock_irq(&first_ec->lock); } while (work_in_progress && !pm_wakeup_pending()); - return false; + return 0; } #endif /* CONFIG_PM_SLEEP */ diff --git a/drivers/acpi/evged.c b/drivers/acpi/evged.c index 5c35cbc7f6ff12..b79ee3f5c1c308 100644 --- a/drivers/acpi/evged.c +++ b/drivers/acpi/evged.c @@ -115,7 +115,7 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares, return AE_ERROR; } - event = devm_kzalloc(dev, sizeof(*event), GFP_KERNEL); + event = devm_kzalloc_obj(dev, *event); if (!event) return AE_ERROR; @@ -143,7 +143,7 @@ static int ged_probe(struct platform_device *pdev) struct acpi_ged_device *geddev; acpi_status acpi_ret; - geddev = devm_kzalloc(&pdev->dev, sizeof(*geddev), GFP_KERNEL); + geddev = devm_kzalloc_obj(&pdev->dev, *geddev); if (!geddev) return -ENOMEM; diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 3674f9613d40df..4324ff5d9c4c49 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -287,7 +287,7 @@ static int acpi_fan_get_fps(struct device *dev, struct acpi_device *device) } fan->fps_count = obj->package.count - 1; /* minus revision field */ - fan->fps = devm_kcalloc(dev, fan->fps_count, sizeof(*fan->fps), GFP_KERNEL); + fan->fps = devm_kzalloc_objs(dev, *fan->fps, fan->fps_count); if (!fan->fps) return -ENOMEM; @@ -475,7 +475,7 @@ static int acpi_fan_probe(struct platform_device *pdev) if (!device) return -ENODEV; - fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); + fan = devm_kzalloc_obj(&pdev->dev, *fan); if (!fan) { dev_err(&device->dev, "No memory for fan\n"); return -ENOMEM; diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 011da4ed6a80ee..472c383eaaec3f 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -237,7 +237,7 @@ void acpi_ec_register_opregions(struct acpi_device *adev); #ifdef CONFIG_PM_SLEEP void acpi_ec_flush_work(void); -bool acpi_ec_dispatch_gpe(void); +int acpi_ec_dispatch_gpe(void); #endif #else @@ -257,9 +257,9 @@ static inline void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit static inline void acpi_ec_register_opregions(struct acpi_device *adev) {} static inline void acpi_ec_flush_work(void) {} -static inline bool acpi_ec_dispatch_gpe(void) +static inline int acpi_ec_dispatch_gpe(void) { - return false; + return -EOPNOTSUPP; } #endif diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c index 87cee4f0fc8041..1e97669eaeea6a 100644 --- a/drivers/acpi/loongarch/iovt.c +++ b/drivers/acpi/loongarch/iovt.c @@ -18,9 +18,20 @@ struct iovt_fwnode { struct list_head ep_list; }; +static bool checksum_valid; static LIST_HEAD(iovt_fwnode_list); static DEFINE_SPINLOCK(iovt_fwnode_lock); +static u8 acpi_iovt_checksum(u8 *buffer, u32 len) +{ + u8 sum = 0, *end = buffer + len; + + while (buffer < end) + sum += *buffer++; + + return sum; +} + #ifdef CONFIG_PCI static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu) { @@ -73,10 +84,43 @@ static int __init iovt_get_pci_iommu_fwnode(struct iovt_fwnode *np, u16 segment, return 0; } +static int __init iovt_validate_entries(struct acpi_iovt_iommu *iommu) +{ + int i, done = 1; + struct acpi_iovt_device_entry *ep; + + ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_entry_offset); + for (i = 0; i < iommu->device_entry_num; i++) { + switch (ep->type) { + case ACPI_IOVT_DEVICE_ENTRY_START: + if (!done) + return -EINVAL; + + done = 0; + break; + case ACPI_IOVT_DEVICE_ENTRY_END: + if (done) + return -EINVAL; + + done = 1; + break; + case ACPI_IOVT_DEVICE_ENTRY_SINGLE: + default: /* Reserved for future */ + if (!done) + return -EINVAL; + + done = 1; + break; + } + ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, ep, ep->length); + } + + return done ? 0 : -EINVAL; +} + static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu) { int i, ret; - bool is_start = false; struct iovt_fwnode *np; struct iovt_device_entry *entry; struct acpi_iovt_device_entry *ep; @@ -110,23 +154,24 @@ static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu) if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT) goto skip; + if (iovt_validate_entries(iommu) < 0) { + kfree(np); + return -EINVAL; + } + INIT_LIST_HEAD(&np->ep_list); ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_entry_offset); for (i = 0; i < iommu->device_entry_num; i++) { switch (ep->type) { case ACPI_IOVT_DEVICE_ENTRY_START: - is_start = true; - entry->start_devid = ep->device_id; - break; - case ACPI_IOVT_DEVICE_ENTRY_END: - if (!is_start) - break; - entry = kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC); if (!entry) return -ENOMEM; - is_start = false; + entry->start_devid = ep->device_id; + break; + case ACPI_IOVT_DEVICE_ENTRY_END: + /* START & END are paired */ entry->end_devid = ep->device_id; list_add_tail(&entry->list, &np->ep_list); break; @@ -135,7 +180,6 @@ static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu) if (!entry) return -ENOMEM; - is_start = false; entry->start_devid = ep->device_id; entry->end_devid = ep->device_id; list_add_tail(&entry->list, &np->ep_list); @@ -184,7 +228,14 @@ void __init acpi_iovt_init(void) return; } - iovt = (struct acpi_table_iovt *)&hdr; + if (acpi_iovt_checksum((unsigned char *)hdr, hdr->length)) { + pr_err("IOVT invalid checksum\n"); + acpi_put_table(hdr); + return; + } + + checksum_valid = true; + iovt = (struct acpi_table_iovt *)hdr; iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset); for (i = 0; i < iovt->iommu_count; i++) { iovt_enable_acs(iommu); @@ -199,6 +250,9 @@ void __init acpi_iovt_late_init(void) acpi_status status; struct acpi_table_header *hdr; + if (!checksum_valid) + return; + status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr); if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index cb771d9cadb2a5..591d2608374f79 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -1060,8 +1060,7 @@ static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc, if (found) nfit_mem = found; else { - nfit_mem = devm_kzalloc(acpi_desc->dev, - sizeof(*nfit_mem), GFP_KERNEL); + nfit_mem = devm_kzalloc_obj(acpi_desc->dev, *nfit_mem); if (!nfit_mem) return -ENOMEM; INIT_LIST_HEAD(&nfit_mem->list); @@ -1095,10 +1094,9 @@ static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc, continue; nfit_mem->nfit_flush = nfit_flush; flush = nfit_flush->flush; - nfit_mem->flush_wpq = devm_kcalloc(acpi_desc->dev, - flush->hint_count, - sizeof(struct resource), - GFP_KERNEL); + nfit_mem->flush_wpq = devm_kzalloc_objs(acpi_desc->dev, + struct resource, + flush->hint_count); if (!nfit_mem->flush_wpq) return -ENOMEM; for (i = 0; i < flush->hint_count; i++) { @@ -2287,7 +2285,7 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc, if (!info || !info2) return -ENOMEM; - nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL); + nd_set = devm_kzalloc_obj(dev, *nd_set); if (!nd_set) return -ENOMEM; import_guid(&nd_set->type_guid, spa->range_guid); @@ -2541,7 +2539,7 @@ static int acpi_nfit_insert_resource(struct acpi_nfit_desc *acpi_desc, if (is_pmem == REGION_INTERSECTS) return 0; - res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(acpi_desc->dev, *res); if (!res) return -ENOMEM; @@ -3391,7 +3389,7 @@ static int acpi_nfit_probe(struct platform_device *pdev) return rc; sz = tbl->length; - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); + acpi_desc = devm_kzalloc_obj(dev, *acpi_desc); if (!acpi_desc) return -ENOMEM; acpi_nfit_desc_init(acpi_desc, dev); @@ -3456,7 +3454,7 @@ static void acpi_nfit_update_notify(struct device *dev, acpi_handle handle) } if (!acpi_desc) { - acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); + acpi_desc = devm_kzalloc_obj(dev, *acpi_desc); if (!acpi_desc) return; acpi_nfit_desc_init(acpi_desc, dev); diff --git a/drivers/acpi/pfr_telemetry.c b/drivers/acpi/pfr_telemetry.c index 2387376832a1b6..458cb99ae2169f 100644 --- a/drivers/acpi/pfr_telemetry.c +++ b/drivers/acpi/pfr_telemetry.c @@ -373,7 +373,7 @@ static int acpi_pfrt_log_probe(struct platform_device *pdev) return -ENODEV; } - pfrt_log_dev = devm_kzalloc(&pdev->dev, sizeof(*pfrt_log_dev), GFP_KERNEL); + pfrt_log_dev = devm_kzalloc_obj(&pdev->dev, *pfrt_log_dev); if (!pfrt_log_dev) return -ENOMEM; diff --git a/drivers/acpi/pfr_update.c b/drivers/acpi/pfr_update.c index 98ace679601b85..459c2938b975a9 100644 --- a/drivers/acpi/pfr_update.c +++ b/drivers/acpi/pfr_update.c @@ -554,7 +554,7 @@ static int acpi_pfru_probe(struct platform_device *pdev) return -ENODEV; } - pfru_dev = devm_kzalloc(&pdev->dev, sizeof(*pfru_dev), GFP_KERNEL); + pfru_dev = devm_kzalloc_obj(&pdev->dev, *pfru_dev); if (!pfru_dev) return -ENOMEM; diff --git a/drivers/acpi/pmic/intel_pmic.c b/drivers/acpi/pmic/intel_pmic.c index 9bd46defc5a278..367adef02cd7d7 100644 --- a/drivers/acpi/pmic/intel_pmic.c +++ b/drivers/acpi/pmic/intel_pmic.c @@ -262,7 +262,7 @@ int intel_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, if (!handle) return -ENODEV; - opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL); + opregion = devm_kzalloc_obj(dev, *opregion); if (!opregion) return -ENOMEM; diff --git a/drivers/acpi/pmic/tps68470_pmic.c b/drivers/acpi/pmic/tps68470_pmic.c index 0d1a82eeb4b0b6..ffd615ff55d316 100644 --- a/drivers/acpi/pmic/tps68470_pmic.c +++ b/drivers/acpi/pmic/tps68470_pmic.c @@ -384,7 +384,7 @@ static int tps68470_pmic_opregion_probe(struct platform_device *pdev) return -ENODEV; } - opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL); + opregion = devm_kzalloc_obj(dev, *opregion); if (!opregion) return -ENOMEM; diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 96b8b0dfe339e1..9218264f8da1ba 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -115,11 +115,7 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent) bool offline = true; char *envp[] = { "EVENT=offline", NULL }; - /* - * acpi_container_offline() calls this for all of the container's - * children under the container's physical_node_lock lock. - */ - mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING); + mutex_lock(&adev->physical_node_lock); list_for_each_entry(pn, &adev->physical_node_list, node) if (device_supports_offline(pn->dev) && !dev_offline(pn->dev)) { @@ -134,6 +130,59 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent) return offline; } +static struct acpi_device_physical_node * +acpi_find_physical_node(struct acpi_device *adev, struct device *dev) +{ + struct acpi_device_physical_node *pn; + + lockdep_assert_held(&adev->physical_node_lock); + + list_for_each_entry(pn, &adev->physical_node_list, node) + if (pn->dev == dev) + return pn; + + return NULL; +} + +static struct device *acpi_next_offline_pending(struct acpi_device *adev) +{ + struct acpi_device_physical_node *pn; + + lockdep_assert_held(&adev->physical_node_lock); + + /* + * Find the first physical node that is still to be offlined, clear its + * offline_pending flag and return its device with a reference held. + */ + list_for_each_entry(pn, &adev->physical_node_list, node) + if (pn->offline_pending) { + pn->offline_pending = false; + return get_device(pn->dev); + } + + return NULL; +} + +static struct device *acpi_next_put_online(struct acpi_device *adev) +{ + struct acpi_device_physical_node *pn; + + lockdep_assert_held(&adev->physical_node_lock); + + /* + * Find the first physical node that has been offlined by + * acpi_bus_offline(), clear its put_online flag and return its device + * with a reference held. + */ + list_for_each_entry(pn, &adev->physical_node_list, node) + if (pn->put_online) { + pn->put_online = false; + return get_device(pn->dev); + } + + return NULL; +} + static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data, void **ret_p) { @@ -141,6 +190,7 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data, struct acpi_device_physical_node *pn; bool second_pass = (bool)data; acpi_status status = AE_OK; + struct device *dev; if (!device) return AE_OK; @@ -153,25 +203,43 @@ static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data, mutex_lock(&device->physical_node_lock); list_for_each_entry(pn, &device->physical_node_list, node) { - int ret; - if (second_pass) { /* Skip devices offlined by the first pass. */ - if (pn->put_online) - continue; + pn->offline_pending = !pn->put_online; } else { + pn->offline_pending = true; pn->put_online = false; } - ret = device_offline(pn->dev); + } + + /* + * Drop physical_node_lock around device_offline(), because the latter + * acquires locks, like the CPU hotplug ones, that must not nest under + * it. + */ + while ((dev = acpi_next_offline_pending(device))) { + int ret; + + mutex_unlock(&device->physical_node_lock); + ret = device_offline(dev); + mutex_lock(&device->physical_node_lock); + if (ret >= 0) { - pn->put_online = !ret; + /* The device may have been unbound in the meantime. */ + pn = acpi_find_physical_node(device, dev); + if (pn) + pn->put_online = !ret; } else { - *ret_p = pn->dev; + *ret_p = &device->dev; if (second_pass) { + dev_warn(dev, "Offline failed.\n"); status = AE_ERROR; - break; } } + + put_device(dev); + if (ACPI_FAILURE(status)) + break; } mutex_unlock(&device->physical_node_lock); @@ -183,18 +251,19 @@ static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data, void **ret_p) { struct acpi_device *device = acpi_fetch_acpi_dev(handle); - struct acpi_device_physical_node *pn; + struct device *dev; if (!device) return AE_OK; mutex_lock(&device->physical_node_lock); - list_for_each_entry(pn, &device->physical_node_list, node) - if (pn->put_online) { - device_online(pn->dev); - pn->put_online = false; - } + while ((dev = acpi_next_put_online(device))) { + mutex_unlock(&device->physical_node_lock); + device_online(dev); + mutex_lock(&device->physical_node_lock); + put_device(dev); + } mutex_unlock(&device->physical_node_lock); @@ -236,7 +305,6 @@ static int acpi_scan_try_to_offline(struct acpi_device *device) (void **)&errdev); if (errdev) { - dev_warn(errdev, "Offline failed.\n"); acpi_bus_online(handle, 0, NULL, NULL); acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, acpi_bus_online, diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index a94bac4422d44f..641056e0252b48 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -760,6 +760,8 @@ bool acpi_s2idle_wake(void) return pm_wakeup_pending(); while (pm_wakeup_pending()) { + int ret; + /* * If IRQD_WAKEUP_ARMED is set for the SCI at this point, the * SCI has not triggered while suspended, so bail out (the @@ -788,11 +790,16 @@ bool acpi_s2idle_wake(void) /* * Check non-EC GPE wakeups and if there are none, cancel the - * SCI-related wakeup and dispatch the EC GPE. + * SCI-related wakeup and dispatch the EC GPE. If there is no + * EC to consult, check the GPEs armed for wakeup via _Ixx + * methods instead. */ - if (acpi_ec_dispatch_gpe()) { + ret = acpi_ec_dispatch_gpe(); + if (ret > 0) { pm_pr_dbg("ACPI non-EC GPE wakeup\n"); return true; + } else if (ret < 0 && acpi_x86_s2idle_check_ixx_gpes()) { + return true; } acpi_os_wait_events_complete(); diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h index 9c3cb109c5d27e..955e9c22bf0d7a 100644 --- a/drivers/acpi/sleep.h +++ b/drivers/acpi/sleep.h @@ -20,6 +20,14 @@ extern int acpi_s2idle_prepare(void); extern bool acpi_s2idle_wake(void); extern void acpi_s2idle_restore(void); extern void acpi_s2idle_end(void); +#if defined(CONFIG_X86) && defined(CONFIG_SUSPEND) +extern bool acpi_x86_s2idle_check_ixx_gpes(void); +#else +static inline bool acpi_x86_s2idle_check_ixx_gpes(void) +{ + return acpi_any_gpe_status_set(U32_MAX); +} +#endif extern void acpi_s2idle_setup(void); diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c index c278ea14c0b36c..b79bf0fa9a7fd8 100644 --- a/drivers/acpi/x86/s2idle.c +++ b/drivers/acpi/x86/s2idle.c @@ -24,6 +24,13 @@ #ifdef CONFIG_SUSPEND +/* + * First GPE armed for wake via an _Ixx method, U32_MAX if none. On + * platforms without an ACPI-enumerated EC, this GPE plays the role of + * the EC GPE in acpi_ec_dispatch_gpe(). + */ +static u32 acpi_s2idle_ixx_gpe = U32_MAX; + static void acpi_setup_ixx_gpes(void) { acpi_handle gpe_root; @@ -47,11 +54,65 @@ static void acpi_setup_ixx_gpes(void) acpi_mark_gpe_for_wake(NULL, i); acpi_set_gpe_wake_mask(NULL, i, ACPI_GPE_ENABLE); + if (acpi_s2idle_ixx_gpe == U32_MAX) + acpi_s2idle_ixx_gpe = i; pm_pr_dbg("ACPI: GPE0x%02x armed for wake via %s\n", i, gpe_nr_str); } } +/* + * acpi_x86_s2idle_check_ixx_gpes - Handle an SCI wakeup without an EC + * + * Called to decide whether or not to wake up the system when an SCI has + * triggered during suspend-to-idle on a platform without an EC instance, + * mirroring acpi_ec_dispatch_gpe() with the first GPE armed for wake via + * an _Ixx method playing the role of the EC GPE. + * + * Report a wakeup if the status bit is set for any enabled GPE other than + * the _Ixx one. If no _Ixx GPE has been armed, acpi_s2idle_ixx_gpe is + * U32_MAX and this amounts to checking all of the GPEs, which is the + * previous behavior. + * + * Otherwise, cancel the pending SCI-related wakeup, so it does not cause + * the pm_wakeup_pending() check in the caller to succeed by itself, and + * dispatch the _Ixx GPE if it is active, so the events behind it can be + * processed. If any of those events turn out to be genuine wake events, + * the drivers handling them are expected to call pm_wakeup_event() and + * the caller will catch that via pm_wakeup_pending() after synchronizing + * the event processing. + */ +bool acpi_x86_s2idle_check_ixx_gpes(void) +{ + acpi_event_status status = 0; + + /* + * Report wakeup if the status bit is set for any enabled GPE other + * than the _Ixx one. + */ + if (acpi_any_gpe_status_set(acpi_s2idle_ixx_gpe)) + return true; + + if (acpi_s2idle_ixx_gpe == U32_MAX) + return false; + + /* + * Cancel the SCI wakeup and dispatch the _Ixx GPE in case there are + * any wakeup events behind it. + */ + pm_system_cancel_wakeup(); + + acpi_get_gpe_status(NULL, acpi_s2idle_ixx_gpe, &status); + if (status & ACPI_EVENT_FLAG_STATUS_SET) { + pm_pr_dbg("ACPI _Ixx GPE 0x%02x dispatched\n", + acpi_s2idle_ixx_gpe); + + acpi_dispatch_gpe(NULL, acpi_s2idle_ixx_gpe); + } + + return false; +} + static bool sleep_no_lps0 __read_mostly; module_param(sleep_no_lps0, bool, 0644); MODULE_PARM_DESC(sleep_no_lps0, "Do not use the special LPS0 device interface"); diff --git a/drivers/ata/acard-ahci.c b/drivers/ata/acard-ahci.c index 402d3304b94be6..044b0bfdf46f68 100644 --- a/drivers/ata/acard-ahci.c +++ b/drivers/ata/acard-ahci.c @@ -281,7 +281,7 @@ static int acard_ahci_port_start(struct ata_port *ap) dma_addr_t mem_dma; size_t dma_sz, rx_fis_sz; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; @@ -378,7 +378,7 @@ static int acard_ahci_init_one(struct pci_dev *pdev, const struct pci_device_id if (rc) return rc; - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(dev, *hpriv); if (!hpriv) return -ENOMEM; diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 4916d9bf3293a0..839adb0afea69e 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -2931,7 +2931,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(dev, *hpriv); if (!hpriv) return -ENOMEM; hpriv->flags |= (unsigned long)pi.private_data; diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c index 48460e515722a9..59d26613efa246 100644 --- a/drivers/ata/ahci_brcm.c +++ b/drivers/ata/ahci_brcm.c @@ -443,7 +443,7 @@ static int brcm_ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/ata/ahci_ceva.c b/drivers/ata/ahci_ceva.c index 008869d9499b8f..95edb7a1306900 100644 --- a/drivers/ata/ahci_ceva.c +++ b/drivers/ata/ahci_ceva.c @@ -268,7 +268,7 @@ static int ceva_ahci_probe(struct platform_device *pdev) enum dev_dma_attr attr; int rc; - cevapriv = devm_kzalloc(dev, sizeof(*cevapriv), GFP_KERNEL); + cevapriv = devm_kzalloc_obj(dev, *cevapriv); if (!cevapriv) return -ENOMEM; diff --git a/drivers/ata/ahci_da850.c b/drivers/ata/ahci_da850.c index 59b9ca26fd449f..7c607fe16b1441 100644 --- a/drivers/ata/ahci_da850.c +++ b/drivers/ata/ahci_da850.c @@ -178,7 +178,7 @@ static int ahci_da850_probe(struct platform_device *pdev) * getting procedure with the explicitly specified ids. */ if (hpriv->n_clks < 2) { - hpriv->clks = devm_kcalloc(dev, 2, sizeof(*hpriv->clks), GFP_KERNEL); + hpriv->clks = devm_kzalloc_objs(dev, *hpriv->clks, 2); if (!hpriv->clks) return -ENOMEM; diff --git a/drivers/ata/ahci_dwc.c b/drivers/ata/ahci_dwc.c index feb8a8539b8efc..c49da659387a34 100644 --- a/drivers/ata/ahci_dwc.c +++ b/drivers/ata/ahci_dwc.c @@ -111,7 +111,7 @@ static struct ahci_host_priv *ahci_dwc_get_resources(struct platform_device *pde struct ahci_dwc_host_priv *dpriv; struct ahci_host_priv *hpriv; - dpriv = devm_kzalloc(&pdev->dev, sizeof(*dpriv), GFP_KERNEL); + dpriv = devm_kzalloc_obj(&pdev->dev, *dpriv); if (!dpriv) return ERR_PTR(-ENOMEM); diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c index 6aaa18e29abc62..882dcb87ba5ffd 100644 --- a/drivers/ata/ahci_imx.c +++ b/drivers/ata/ahci_imx.c @@ -863,7 +863,7 @@ static int imx_ahci_probe(struct platform_device *pdev) unsigned int reg_val; int ret; - imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL); + imxpriv = devm_kzalloc_obj(dev, *imxpriv); if (!imxpriv) return -ENOMEM; diff --git a/drivers/ata/ahci_mtk.c b/drivers/ata/ahci_mtk.c index 7295b9066ae213..fe0643585b20c1 100644 --- a/drivers/ata/ahci_mtk.c +++ b/drivers/ata/ahci_mtk.c @@ -129,7 +129,7 @@ static int mtk_ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int err; - plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(dev, *plat); if (!plat) return -ENOMEM; diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c index fc6b8cd75b3200..a5578c27147a36 100644 --- a/drivers/ata/ahci_qoriq.c +++ b/drivers/ata/ahci_qoriq.c @@ -274,7 +274,7 @@ static int ahci_qoriq_probe(struct platform_device *pdev) if (!(of_id || acpi_id)) return -ENODEV; - qoriq_priv = devm_kzalloc(dev, sizeof(*qoriq_priv), GFP_KERNEL); + qoriq_priv = devm_kzalloc_obj(dev, *qoriq_priv); if (!qoriq_priv) return -ENOMEM; diff --git a/drivers/ata/ahci_seattle.c b/drivers/ata/ahci_seattle.c index 9758fa0260ac37..b73b86e74c4a0a 100644 --- a/drivers/ata/ahci_seattle.c +++ b/drivers/ata/ahci_seattle.c @@ -127,7 +127,7 @@ static const struct ata_port_info *ahci_seattle_get_port_info( struct seattle_plat_data *plat_data; u32 val; - plat_data = devm_kzalloc(dev, sizeof(*plat_data), GFP_KERNEL); + plat_data = devm_kzalloc_obj(dev, *plat_data); if (!plat_data) return &ahci_port_info; diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c index eea75961038cfb..7192769311f4c4 100644 --- a/drivers/ata/ahci_st.c +++ b/drivers/ata/ahci_st.c @@ -153,7 +153,7 @@ static int st_ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int err; - drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&pdev->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/ata/ahci_tegra.c b/drivers/ata/ahci_tegra.c index 554f05e09f9833..2b9b98643128bb 100644 --- a/drivers/ata/ahci_tegra.c +++ b/drivers/ata/ahci_tegra.c @@ -523,7 +523,7 @@ static int tegra_ahci_probe(struct platform_device *pdev) if (IS_ERR(hpriv)) return PTR_ERR(hpriv); - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(&pdev->dev, *tegra); if (!tegra) return -ENOMEM; @@ -578,9 +578,8 @@ static int tegra_ahci_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(tegra->pmc), "failed to get PMC\n"); - tegra->supplies = devm_kcalloc(&pdev->dev, - tegra->soc->num_supplies, - sizeof(*tegra->supplies), GFP_KERNEL); + tegra->supplies = devm_kzalloc_objs(&pdev->dev, *tegra->supplies, + tegra->soc->num_supplies); if (!tegra->supplies) return -ENOMEM; diff --git a/drivers/ata/ahci_xgene.c b/drivers/ata/ahci_xgene.c index 2ebfe86e429ba1..8a34d8741fe915 100644 --- a/drivers/ata/ahci_xgene.c +++ b/drivers/ata/ahci_xgene.c @@ -739,7 +739,7 @@ static int xgene_ahci_probe(struct platform_device *pdev) if (IS_ERR(hpriv)) return PTR_ERR(hpriv); - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index e3aa5c86fb48e8..b0ec0a57ef717e 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -1855,7 +1855,7 @@ static int piix_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(dev, *hpriv); if (!hpriv) return -ENOMEM; diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 001a6f5e417231..5ce34683d46830 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2514,7 +2514,7 @@ static int ahci_port_start(struct ata_port *ap) dma_addr_t mem_dma; size_t dma_sz, rx_fis_sz; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index ae342080556ae8..992702df87da5c 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -539,7 +539,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, * No clock bulk found: fallback to manually getting * the optional clock. */ - hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL); + hpriv->clks = devm_kzalloc_obj(dev, *hpriv->clks); if (!hpriv->clks) { rc = -ENOMEM; goto err_out; diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 9c188b0d6236ea..5ff45a5cbfe4a7 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2059,6 +2059,10 @@ void ata_dev_power_set_standby(struct ata_device *dev) struct ata_taskfile tf; unsigned int err_mask; + /* Issue STANDBY IMMEDIATE command only if supported by the device */ + if (!ata_dev_power_init_tf(dev, &tf, false)) + return; + /* If the device is already sleeping or in standby, do nothing. */ if ((dev->flags & ATA_DFLAG_SLEEPING) || !ata_dev_power_is_active(dev)) @@ -2077,10 +2081,6 @@ void ata_dev_power_set_standby(struct ata_device *dev) system_entering_hibernation()) return; - /* Issue STANDBY IMMEDIATE command only if supported by the device */ - if (!ata_dev_power_init_tf(dev, &tf, false)) - return; - ata_dev_notice(dev, "Entering standby power mode\n"); err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index b7e8545e569e63..f99e422dfd9f0c 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -4080,8 +4080,20 @@ void ata_eh_finish(struct ata_port *ap) ata_eh_qc_complete(qc); } } else { - if (qc->flags & ATA_QCFLAG_SENSE_VALID || - qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) { + if (qc->flags & ATA_QCFLAG_SENSE_VALID && + qc->flags & ATA_QCFLAG_RETRY) { + /* + * The sense data asks for a retry, see + * ata_eh_analyze_tf(). ata_eh_link_autopsy() + * cleared qc->err_mask, so ata_eh_qc_retry() + * would increment scmd->allowed. Leave + * scmd->allowed alone, so that upper layer + * only retries the command if it has not + * already been retried too many times. + */ + __ata_eh_qc_complete(qc); + } else if (qc->flags & ATA_QCFLAG_SENSE_VALID || + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) { ata_eh_qc_complete(qc); } else { /* feed zero TF to sense generation */ diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c index 904f418387d11a..43991e54eb0816 100644 --- a/drivers/ata/libata-pmp.c +++ b/drivers/ata/libata-pmp.c @@ -482,6 +482,20 @@ static void sata_pmp_quirks(struct ata_port *ap) if (link->pmp == 4) link->flags |= ATA_LFLAG_DISABLED; } + } else if (vendor == 0x1b4b && devid == 0x9705) { + /* + * Marvell 88SM9705 quirks + * + * 1-to-5 PMP with an extra SEMB port. It reports 6 ports and + * port 5 is the SEMB, which never answers SRST: EH spends about + * a minute per round retrying it, and disk discovery waits for + * that. Seen behind a Marvell 88SE9235 in the Synology DX1215 + * and DX1222. + */ + ata_for_each_link(link, ap, EDGE) { + if (link->pmp == 5) + link->flags |= ATA_LFLAG_DISABLED; + } } } diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 32fd0e804654b2..d917242ac136fc 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1287,7 +1287,7 @@ int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, spin_lock_irqsave(ap->lock, flags); dev = ata_scsi_find_dev(ap, sdev); - if (!dev || queue_depth < 1 || queue_depth == sdev->queue_depth) { + if (!dev || queue_depth < 1) { spin_unlock_irqrestore(ap->lock, flags); return sdev->queue_depth; } diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a61fb03312793c..87a57495d2e4bf 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2048,6 +2048,19 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd, if (xlat_func(qc)) goto done; + /* + * A data-out request may contain pages pinned without write access. + * Reject a translated data-in command before issuing it, since its + * completion handler may write to the buffer even if the device fails. + */ + if (unlikely(cmd->sc_data_direction == DMA_TO_DEVICE && + ata_is_data(qc->tf.protocol) && + !(qc->tf.flags & ATA_TFLAG_WRITE))) { + ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, + DATA_IN_BUFFER_ERROR); + goto done; + } + return ata_scsi_qc_issue(ap, qc); done: @@ -2079,6 +2092,13 @@ static void ata_scsi_rbuf_fill(struct ata_device *dev, struct scsi_cmnd *cmd, unsigned long flags; unsigned int len; + /* A data-out request may contain pages pinned without write access. */ + if (cmd->sc_data_direction == DMA_TO_DEVICE) { + ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, + DATA_IN_BUFFER_ERROR); + return; + } + spin_lock_irqsave(&ata_scsi_rbuf_lock, flags); memset(ata_scsi_rbuf, 0, ATA_SCSI_RBUF_SIZE); @@ -3173,6 +3193,14 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) qc->complete_fn = atapi_qc_complete; + /* atapi_fixup_inquiry() writes to the buffer on successful completion. */ + if (scmd->sc_data_direction == DMA_TO_DEVICE && + scmd->cmnd[0] == INQUIRY) { + ata_scsi_set_sense(dev, scmd, ABORTED_COMMAND, + DATA_IN_BUFFER_ERROR); + return 1; + } + qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; if (scmd->sc_data_direction == DMA_TO_DEVICE) { qc->tf.flags |= ATA_TFLAG_WRITE; @@ -4366,14 +4394,22 @@ static unsigned int ata_scsi_zbc_out_xlat(struct ata_queued_cmd *qc) /** * ata_mselect_caching - Simulate MODE SELECT for caching info page * @qc: Storage for translated ATA taskfile - * @buf: input buffer - * @len: number of valid bytes in the input buffer - * @fp: out parameter for the failed field on error + * @buf: Mode page, starting with the mode page header + * @len: Length of the mode page, including the mode page header + * @fp: Out parameter, offset in @buf of the first invalid byte on error * * Prepare a taskfile to modify caching information for the device. * + * The caller has stripped the mode parameter header and the block + * descriptors, so @buf points at the mode page header, like the buffer + * filled by the ata_msense_*() functions, and offsets in @buf, including + * the one returned in @fp, are the byte numbers of the mode page. + * * LOCKING: * None. + * + * RETURNS: + * 0 if a taskfile was prepared, -EINVAL if the mode page is invalid. */ static int ata_mselect_caching(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) @@ -4384,26 +4420,19 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc, u8 wce; int i; - /* - * The first two bytes of def_cache_mpage are a header, so offsets - * in mpage are off by 2 compared to buf. Same for len. - */ - - if (len != CACHE_MPAGE_LEN - 2) { - *fp = min(len, CACHE_MPAGE_LEN - 2); + if (len != CACHE_MPAGE_LEN) { + *fp = 1; return -EINVAL; } - wce = buf[0] & (1 << 2); + wce = buf[2] & (1 << 2); /* * Check that read-only bits are not modified. */ ata_msense_caching(dev->id, mpage, false); - for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) { - if (i == 0) - continue; - if (mpage[i + 2] != buf[i]) { + for (i = 3; i < CACHE_MPAGE_LEN; i++) { + if (mpage[i] != buf[i]) { *fp = i; return -EINVAL; } @@ -4417,8 +4446,26 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc, return 0; } -/* - * Simulate MODE SELECT control mode page, sub-page 0. +/** + * ata_mselect_control_spg0 - Simulate MODE SELECT for control sub-page 0 + * @qc: Storage for translated ATA taskfile + * @buf: Mode page, starting with the mode page header + * @len: Length of the mode page, including the mode page header + * @fp: Out parameter, offset in @buf of the first invalid byte on error + * + * Simulate MODE SELECT control mode page, sub-page 0. + * + * The caller has stripped the mode parameter header and the block + * descriptors, so @buf points at the mode page header, like the buffer + * filled by the ata_msense_*() functions, and offsets in @buf, including + * the one returned in @fp, are the byte numbers of the mode page. + * + * LOCKING: + * None. + * + * RETURNS: + * 0, as no ATA command needs to be sent, or -EINVAL if the mode page is + * invalid. */ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) @@ -4428,26 +4475,19 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc, u8 d_sense; int i; - /* - * The first two bytes of def_control_mpage are a header, so offsets - * in mpage are off by 2 compared to buf. Same for len. - */ - - if (len != CONTROL_MPAGE_LEN - 2) { - *fp = min(len, CONTROL_MPAGE_LEN - 2); + if (len != CONTROL_MPAGE_LEN) { + *fp = 1; return -EINVAL; } - d_sense = buf[0] & (1 << 2); + d_sense = buf[2] & (1 << 2); /* * Check that read-only bits are not modified. */ ata_msense_control_spg0(dev, mpage, false); - for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { - if (i == 0) - continue; - if (mpage[2 + i] != buf[i]) { + for (i = 3; i < CONTROL_MPAGE_LEN; i++) { + if (mpage[i] != buf[i]) { *fp = i; return -EINVAL; } @@ -4459,9 +4499,27 @@ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc, return 0; } -/* - * Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode - * page) into a SET FEATURES command. +/** + * ata_mselect_control_ata_feature - Translate ATA Feature Control page + * @qc: Storage for translated ATA taskfile + * @buf: Mode page, starting with the mode page header + * @len: Length of the mode page, including the mode page header + * @fp: Out parameter, offset in @buf of the first invalid byte on error + * + * Translate MODE SELECT control mode page, sub-page f2h (ATA feature mode + * page) into a SET FEATURES command. + * + * The caller has stripped the mode parameter header and the block + * descriptors, so @buf points at the mode page header, like the buffer + * filled by the ata_msense_*() functions, and offsets in @buf, including + * the one returned in @fp, are the byte numbers of the mode page. + * + * LOCKING: + * None. + * + * RETURNS: + * 1 if a taskfile was prepared, -EINVAL if the mode page is invalid or if + * CDL cannot be enabled. */ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) @@ -4470,17 +4528,13 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, struct ata_taskfile *tf = &qc->tf; u8 cdl_action; - /* - * The first four bytes of ATA Feature Control mode page are a header, - * so offsets in mpage are off by 4 compared to buf. Same for len. - */ - if (len != ATA_FEATURE_SUB_MPAGE_LEN - 4) { - *fp = min(len, ATA_FEATURE_SUB_MPAGE_LEN - 4); + if (len != ATA_FEATURE_SUB_MPAGE_LEN) { + *fp = 2; return -EINVAL; } /* Check cdl_ctrl */ - switch (buf[0] & 0x03) { + switch (buf[4] & 0x03) { case 0: /* Disable CDL */ ata_dev_dbg(dev, "Disabling CDL\n"); @@ -4495,6 +4549,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) { ata_dev_err(dev, "NCQ priority must be disabled to enable CDL\n"); + *fp = 4; return -EINVAL; } ata_dev_dbg(dev, "Enabling CDL\n"); @@ -4502,7 +4557,7 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, dev->flags |= ATA_DFLAG_CDL_ENABLED; break; default: - *fp = 0; + *fp = 4; return -EINVAL; } @@ -4518,15 +4573,24 @@ static int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, /** * ata_mselect_control - Simulate MODE SELECT for control page * @qc: Storage for translated ATA taskfile - * @spg: target sub-page of the control page - * @buf: input buffer - * @len: number of valid bytes in the input buffer - * @fp: out parameter for the failed field on error + * @spg: Sub-page of the control page, 0 or ATA_FEATURE_SUB_MPAGE + * @buf: Mode page, starting with the mode page header + * @len: Length of the mode page, including the mode page header + * @fp: Out parameter, offset in @buf of the first invalid byte on error * - * Prepare a taskfile to modify caching information for the device. + * Call the handler of sub-page @spg of the control mode page. + * + * The caller has stripped the mode parameter header and the block + * descriptors, so @buf points at the mode page header, like the buffer + * filled by the ata_msense_*() functions, and offsets in @buf, including + * the one returned in @fp, are the byte numbers of the mode page. * * LOCKING: * None. + * + * RETURNS: + * 0 if no ATA command needs to be sent, 1 if a taskfile was prepared, + * -EINVAL if the mode page is invalid. */ static int ata_mselect_control(struct ata_queued_cmd *qc, u8 spg, const u8 *buf, int len, u16 *fp) @@ -4613,7 +4677,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param_len; if (bd_len != 0 && bd_len != 8) { fp = (six_byte) ? 3 : 6; - fp += bd_len + hdr_len; goto invalid_param; } @@ -4628,48 +4691,56 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) if (len < 4) goto invalid_param_len; + /* + * Mode pages with subpage code 00h use the page_0 format: SAT + * defines the SPF bit of the Caching and Control mode pages, + * for subpage code 00h, as not changeable and set to zero. + */ spg = p[1]; - pg_len = get_unaligned_be16(&p[2]); - p += 4; - len -= 4; + if (!spg) { + fp = hdr_len + bd_len; + goto invalid_param; + } + + pg_len = get_unaligned_be16(&p[2]) + 4; } else { if (len < 2) goto invalid_param_len; spg = 0; - pg_len = p[1]; - p += 2; - len -= 2; + pg_len = p[1] + 2; } /* - * Supported subpages: all subpages and ATA feature sub-page f2h of - * the control page. + * The only supported subpage is the ATA feature sub-page f2h of the + * control page. */ if (spg) { switch (spg) { - case ALL_SUB_MPAGES: - /* All subpages is not supported for the control page */ - if (pg == CONTROL_MPAGE) { - fp = (p[0] & 0x40) ? 1 : 0; - fp += hdr_len + bd_len; - goto invalid_param; - } - break; case ATA_FEATURE_SUB_MPAGE: if (qc->dev->flags & ATA_DFLAG_CDL && pg == CONTROL_MPAGE) break; fallthrough; default: - fp = (p[0] & 0x40) ? 1 : 0; - fp += hdr_len + bd_len; + fp = hdr_len + bd_len + 1; goto invalid_param; } } if (pg_len > len) goto invalid_param_len; + /* + * A MODE SELECT command is translated into at most one ATA command, so + * only one mode page per command is supported. Reject any data after + * the mode page before calling the mode page handlers, which may + * already update the device flags. + */ + if (len > pg_len) { + fp = p - buffer + pg_len; + goto invalid_param; + } + switch (pg) { case CACHE_MPAGE: if (ata_mselect_caching(qc, p, pg_len, &fp) < 0) { @@ -4692,13 +4763,6 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param; } - /* - * Only one page has changeable data, so we only support setting one - * page at a time. - */ - if (len > pg_len) - goto invalid_param; - return 0; invalid_fld: diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c index a4f0f81844a12a..67b2272c7c919e 100644 --- a/drivers/ata/pata_acpi.c +++ b/drivers/ata/pata_acpi.c @@ -197,7 +197,7 @@ static int pacpi_port_start(struct ata_port *ap) if (ACPI_HANDLE(&ap->tdev) == NULL) return -ENODEV; - acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL); + acpi = ap->private_data = devm_kzalloc_obj(&pdev->dev, struct pata_acpi); if (ap->private_data == NULL) return -ENOMEM; acpi->mask[0] = pacpi_discover_modes(ap, &ap->link.device[0]); diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c index a652a1b57338c1..12f1324461d1c7 100644 --- a/drivers/ata/pata_arasan_cf.c +++ b/drivers/ata/pata_arasan_cf.c @@ -804,7 +804,7 @@ static int arasan_cf_probe(struct platform_device *pdev) irq_handler_t irq_handler = NULL; int ret; - acdev = devm_kzalloc(&pdev->dev, sizeof(*acdev), GFP_KERNEL); + acdev = devm_kzalloc_obj(&pdev->dev, *acdev); if (!acdev) return -ENOMEM; diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c index 6154a2bf19bed3..7d1283d3ad7d97 100644 --- a/drivers/ata/pata_atp867x.c +++ b/drivers/ata/pata_atp867x.c @@ -340,7 +340,7 @@ static int atp867x_set_priv(struct ata_port *ap) int port = ap->port_no; dp = ap->private_data = - devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL); + devm_kzalloc_obj(&pdev->dev, *dp); if (dp == NULL) return -ENOMEM; diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c index 84eb36d02d7d70..6bf58d0dc0ab9b 100644 --- a/drivers/ata/pata_cmd640.c +++ b/drivers/ata/pata_cmd640.c @@ -153,7 +153,7 @@ static int cmd640_port_start(struct ata_port *ap) struct pci_dev *pdev = to_pci_dev(ap->host->dev); struct cmd640_reg *timing; - timing = devm_kzalloc(&pdev->dev, sizeof(struct cmd640_reg), GFP_KERNEL); + timing = devm_kzalloc_obj(&pdev->dev, struct cmd640_reg); if (timing == NULL) return -ENOMEM; timing->last = -1; /* Force a load */ diff --git a/drivers/ata/pata_ep93xx.c b/drivers/ata/pata_ep93xx.c index 339ee5e43e9f39..cb4e4c0478b004 100644 --- a/drivers/ata/pata_ep93xx.c +++ b/drivers/ata/pata_ep93xx.c @@ -945,7 +945,7 @@ static int ep93xx_pata_probe(struct platform_device *pdev) if (IS_ERR(ide_base)) return PTR_ERR(ide_base); - drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&pdev->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/ata/pata_ftide010.c b/drivers/ata/pata_ftide010.c index c41da296eb389d..0b9678c7cc4f34 100644 --- a/drivers/ata/pata_ftide010.c +++ b/drivers/ata/pata_ftide010.c @@ -460,7 +460,7 @@ static int pata_ftide010_probe(struct platform_device *pdev) int ret; int i; - ftide = devm_kzalloc(dev, sizeof(*ftide), GFP_KERNEL); + ftide = devm_kzalloc_obj(dev, *ftide); if (!ftide) return -ENOMEM; ftide->dev = dev; diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c index 70f056e47e6bd3..ff9322ee18f7bc 100644 --- a/drivers/ata/pata_icside.c +++ b/drivers/ata/pata_icside.c @@ -489,7 +489,7 @@ static int pata_icside_probe(struct expansion_card *ec, if (ret) goto out; - state = devm_kzalloc(&ec->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&ec->dev, *state); if (!state) { ret = -ENOMEM; goto release; diff --git a/drivers/ata/pata_imx.c b/drivers/ata/pata_imx.c index ad559058cfe637..462efc17d55f4e 100644 --- a/drivers/ata/pata_imx.c +++ b/drivers/ata/pata_imx.c @@ -135,8 +135,7 @@ static int pata_imx_probe(struct platform_device *pdev) if (irq < 0) return irq; - priv = devm_kzalloc(&pdev->dev, - sizeof(struct pata_imx_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct pata_imx_priv); if (!priv) return -ENOMEM; diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c index fc762dcc61bfd6..fd14bfee6847a9 100644 --- a/drivers/ata/pata_it821x.c +++ b/drivers/ata/pata_it821x.c @@ -746,7 +746,7 @@ static int it821x_port_start(struct ata_port *ap) if (ret < 0) return ret; - itdev = devm_kzalloc(&pdev->dev, sizeof(struct it821x_dev), GFP_KERNEL); + itdev = devm_kzalloc_obj(&pdev->dev, struct it821x_dev); if (itdev == NULL) return -ENOMEM; ap->private_data = itdev; diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c index 80f6a91acf6f50..22042932651107 100644 --- a/drivers/ata/pata_ixp4xx_cf.c +++ b/drivers/ata/pata_ixp4xx_cf.c @@ -242,7 +242,7 @@ static int ixp4xx_pata_probe(struct platform_device *pdev) int ret; int irq; - ixpp = devm_kzalloc(dev, sizeof(*ixpp), GFP_KERNEL); + ixpp = devm_kzalloc_obj(dev, *ixpp); if (!ixpp) return -ENOMEM; diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c index dd93f613f959dc..a11a1eae2ae8df 100644 --- a/drivers/ata/pata_macio.c +++ b/drivers/ata/pata_macio.c @@ -1146,8 +1146,7 @@ static int pata_macio_attach(struct macio_dev *mdev, macio_enable_devres(mdev); /* Allocate and init private data structure */ - priv = devm_kzalloc(&mdev->ofdev.dev, - sizeof(struct pata_macio_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&mdev->ofdev.dev, struct pata_macio_priv); if (!priv) return -ENOMEM; @@ -1288,8 +1287,7 @@ static int pata_macio_pci_attach(struct pci_dev *pdev, } /* Allocate and init private data structure */ - priv = devm_kzalloc(&pdev->dev, - sizeof(struct pata_macio_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct pata_macio_priv); if (!priv) return -ENOMEM; diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c index 1739743427cfc2..6400278d531413 100644 --- a/drivers/ata/pata_mpc52xx.c +++ b/drivers/ata/pata_mpc52xx.c @@ -737,7 +737,7 @@ static int mpc52xx_ata_probe(struct platform_device *op) } /* Prepare our private structure */ - priv = devm_kzalloc(&op->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&op->dev, *priv); if (!priv) { rv = -ENOMEM; goto err1; diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c index df42ebe98db780..3448700b007c19 100644 --- a/drivers/ata/pata_octeon_cf.c +++ b/drivers/ata/pata_octeon_cf.c @@ -821,7 +821,7 @@ static int octeon_cf_probe(struct platform_device *pdev) if (node == NULL) return -EINVAL; - cf_port = devm_kzalloc(&pdev->dev, sizeof(*cf_port), GFP_KERNEL); + cf_port = devm_kzalloc_obj(&pdev->dev, *cf_port); if (!cf_port) return -ENOMEM; diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c index 87479bc893b252..289f03637365c5 100644 --- a/drivers/ata/pata_platform.c +++ b/drivers/ata/pata_platform.c @@ -127,7 +127,7 @@ int __pata_platform_probe(struct device *dev, struct resource *io_res, return -ENOMEM; ap = host->ports[0]; - ap->ops = devm_kzalloc(dev, sizeof(*ap->ops), GFP_KERNEL); + ap->ops = devm_kzalloc_obj(dev, *ap->ops); if (!ap->ops) return -ENOMEM; ap->ops->inherits = &ata_sff_port_ops; diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c index a694f6a178e319..ed8c19db207cd9 100644 --- a/drivers/ata/pata_pxa.c +++ b/drivers/ata/pata_pxa.c @@ -244,8 +244,7 @@ static int pxa_ata_probe(struct platform_device *pdev) /* * Allocate and load driver's internal data structure */ - data = devm_kzalloc(&pdev->dev, sizeof(struct pata_pxa_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct pata_pxa_data); if (!data) return -ENOMEM; diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c index 0144e597707e04..ef100a68f671d8 100644 --- a/drivers/ata/pata_rb532_cf.c +++ b/drivers/ata/pata_rb532_cf.c @@ -130,7 +130,7 @@ static int rb532_pata_driver_probe(struct platform_device *pdev) if (!ah) return -ENOMEM; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c index 6ff4c11e937d88..b68aa46b09882f 100644 --- a/drivers/ata/pata_rdc.c +++ b/drivers/ata/pata_rdc.c @@ -326,7 +326,7 @@ static int rdc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(dev, *hpriv); if (!hpriv) return -ENOMEM; diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c index cb53fe698c6edf..e0ada6fb78c639 100644 --- a/drivers/ata/pata_via.c +++ b/drivers/ata/pata_via.c @@ -435,7 +435,7 @@ static int via_port_start(struct ata_port *ap) if (ret < 0) return ret; - vp = devm_kzalloc(&pdev->dev, sizeof(struct via_port), GFP_KERNEL); + vp = devm_kzalloc_obj(&pdev->dev, struct via_port); if (vp == NULL) return -ENOMEM; ap->private_data = vp; diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c index 30aaf5c5337b74..31626555b8fd9e 100644 --- a/drivers/ata/pdc_adma.c +++ b/drivers/ata/pdc_adma.c @@ -508,7 +508,7 @@ static int adma_port_start(struct ata_port *ap) struct adma_port_priv *pp; adma_enter_reg_mode(ap); - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; pp->pkt = dmam_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma, diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index aa816a1a4c5416..486ea94a0184b6 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -226,7 +226,7 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev, { struct device *dev = &pdev->dev; - hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL); + hsdev->dma = devm_kzalloc_obj(dev, *hsdev->dma); if (!hsdev->dma) return -ENOMEM; @@ -1129,7 +1129,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) /* Allocate DWC SATA device */ host = ata_host_alloc_pinfo(dev, ppi, SATA_DWC_MAX_PORTS); - hsdev = devm_kzalloc(dev, sizeof(*hsdev), GFP_KERNEL); + hsdev = devm_kzalloc_obj(dev, *hsdev); if (!host || !hsdev) return -ENOMEM; diff --git a/drivers/ata/sata_gemini.c b/drivers/ata/sata_gemini.c index 56ae2820df5888..9d87603ef531c1 100644 --- a/drivers/ata/sata_gemini.c +++ b/drivers/ata/sata_gemini.c @@ -293,7 +293,7 @@ static int gemini_sata_probe(struct platform_device *pdev) u32 gmask; int ret; - sg = devm_kzalloc(dev, sizeof(*sg), GFP_KERNEL); + sg = devm_kzalloc_obj(dev, *sg); if (!sg) return -ENOMEM; sg->dev = dev; diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c index a0b6e197cfb517..435e658b2c6634 100644 --- a/drivers/ata/sata_highbank.c +++ b/drivers/ata/sata_highbank.c @@ -473,12 +473,12 @@ static int ahci_highbank_probe(struct platform_device *pdev) if (!irq) return -EINVAL; - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(dev, *hpriv); if (!hpriv) { dev_err(dev, "can't alloc ahci_host_priv\n"); return -ENOMEM; } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) { dev_err(dev, "can't alloc ecx_plat_data\n"); return -ENOMEM; diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index c408d04d9bf742..08c0bddcb7cc4b 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -1675,7 +1675,7 @@ static int mv_port_start(struct ata_port *ap) unsigned long flags; int tag; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; ap->private_data = pp; @@ -4067,18 +4067,14 @@ static int mv_platform_probe(struct platform_device *pdev) return irq; host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!host || !hpriv) return -ENOMEM; - hpriv->port_clks = devm_kcalloc(&pdev->dev, - n_ports, sizeof(struct clk *), - GFP_KERNEL); + hpriv->port_clks = devm_kzalloc_objs(&pdev->dev, struct clk *, n_ports); if (!hpriv->port_clks) return -ENOMEM; - hpriv->port_phys = devm_kcalloc(&pdev->dev, - n_ports, sizeof(struct phy *), - GFP_KERNEL); + hpriv->port_phys = devm_kzalloc_objs(&pdev->dev, struct phy *, n_ports); if (!hpriv->port_phys) return -ENOMEM; host->private_data = hpriv; @@ -4361,7 +4357,7 @@ static int mv_pci_init_one(struct pci_dev *pdev, n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC; host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!host || !hpriv) return -ENOMEM; host->private_data = hpriv; diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index 8624cd4e88ccee..4ddfaac9decdd2 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c @@ -1145,7 +1145,7 @@ static int nv_adma_port_start(struct ata_port *ap) if (rc) return rc; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; @@ -1960,7 +1960,7 @@ static int nv_swncq_port_start(struct ata_port *ap) if (rc) return rc; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; @@ -2376,7 +2376,7 @@ static int nv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!hpriv) return -ENOMEM; hpriv->type = type; diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index 6da1dea00b84e1..9ca1ba5583ee90 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c @@ -322,7 +322,7 @@ static int pdc_common_port_start(struct ata_port *ap) if (rc) return rc; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; @@ -1189,7 +1189,7 @@ static int pdc_ata_init_one(struct pci_dev *pdev, dev_err(&pdev->dev, "failed to allocate host\n"); return -ENOMEM; } - hpriv = devm_kzalloc(&pdev->dev, sizeof *hpriv, GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!hpriv) return -ENOMEM; spin_lock_init(&hpriv->hard_reset_lock); diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c index f38310b84f51cf..2b1962c03336ee 100644 --- a/drivers/ata/sata_qstor.c +++ b/drivers/ata/sata_qstor.c @@ -461,7 +461,7 @@ static int qs_port_start(struct ata_port *ap) void __iomem *chan = mmio_base + (ap->port_no * 0x4000); u64 addr; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; pp->pkt = dmam_alloc_coherent(dev, QS_PKT_BYTES, &pp->pkt_dma, diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index 487eadd4073fa3..419b37878c4f39 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -867,7 +867,7 @@ static int sata_rcar_probe(struct platform_device *pdev) if (irq < 0) return irq; - priv = devm_kzalloc(dev, sizeof(struct sata_rcar_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct sata_rcar_priv); if (!priv) return -ENOMEM; diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index 38291ae772c9cc..7acd55b17b18f2 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c @@ -1199,7 +1199,7 @@ static int sil24_port_start(struct ata_port *ap) size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS; dma_addr_t cb_dma; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c index cab40c10ad6bcb..e7c28e7c5bb863 100644 --- a/drivers/ata/sata_sx4.c +++ b/drivers/ata/sata_sx4.c @@ -284,7 +284,7 @@ static int pdc_port_start(struct ata_port *ap) struct device *dev = ap->host->dev; struct pdc_port_priv *pp; - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(dev, *pp); if (!pp) return -ENOMEM; @@ -1402,7 +1402,7 @@ static int pdc_sata_init_one(struct pci_dev *pdev, /* allocate host */ host = ata_host_alloc_pinfo(&pdev->dev, ppi, 4); - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!host || !hpriv) return -ENOMEM; diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c index 122133199ea702..452bd5670e0307 100644 --- a/drivers/ata/sata_uli.c +++ b/drivers/ata/sata_uli.c @@ -150,7 +150,7 @@ static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (!host) return -ENOMEM; - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!hpriv) return -ENOMEM; host->private_data = hpriv; diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c index cfd8ff1f529ca7..b9bc23e2fd042e 100644 --- a/drivers/ata/sata_via.c +++ b/drivers/ata/sata_via.c @@ -742,7 +742,7 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc) return rc; - hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); + hpriv = devm_kzalloc_obj(&pdev->dev, *hpriv); if (!hpriv) return -ENOMEM; host->private_data = hpriv; diff --git a/drivers/auxdisplay/arm-charlcd.c b/drivers/auxdisplay/arm-charlcd.c index ea684f3446c37d..8b8e701281d666 100644 --- a/drivers/auxdisplay/arm-charlcd.c +++ b/drivers/auxdisplay/arm-charlcd.c @@ -258,7 +258,7 @@ static int __init charlcd_probe(struct platform_device *pdev) int ret; struct charlcd *lcd; - lcd = devm_kzalloc(dev, sizeof(*lcd), GFP_KERNEL); + lcd = devm_kzalloc_obj(dev, *lcd); if (!lcd) return -ENOMEM; diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c index 19b5c14e58ffc1..83dee9f8a8a5f2 100644 --- a/drivers/auxdisplay/ht16k33.c +++ b/drivers/auxdisplay/ht16k33.c @@ -663,7 +663,7 @@ static int ht16k33_probe(struct i2c_client *client) return -EIO; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c index 32e1863ef4b29d..be513594f61dc7 100644 --- a/drivers/auxdisplay/img-ascii-lcd.c +++ b/drivers/auxdisplay/img-ascii-lcd.c @@ -232,7 +232,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev) struct img_ascii_lcd_ctx *ctx; int err; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/auxdisplay/max6959.c b/drivers/auxdisplay/max6959.c index 888788a1ff08e6..c3134163751587 100644 --- a/drivers/auxdisplay/max6959.c +++ b/drivers/auxdisplay/max6959.c @@ -119,7 +119,7 @@ static int max6959_i2c_probe(struct i2c_client *client) struct max6959_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/auxdisplay/seg-led-gpio.c b/drivers/auxdisplay/seg-led-gpio.c index bc463118fe51a9..0248a8026f1fd9 100644 --- a/drivers/auxdisplay/seg-led-gpio.c +++ b/drivers/auxdisplay/seg-led-gpio.c @@ -63,7 +63,7 @@ static int seg_led_probe(struct platform_device *pdev) struct seg_led_priv *priv; struct device *dev = &pdev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 8c5e47c28d9a32..e51fc9f5e97654 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -280,9 +280,8 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) &cpu_capacity); if (!ret) { if (!raw_capacity) { - raw_capacity = kcalloc(num_possible_cpus(), - sizeof(*raw_capacity), - GFP_KERNEL); + raw_capacity = kzalloc_objs(*raw_capacity, + num_possible_cpus()); if (!raw_capacity) { cap_parsing_failed = true; return false; @@ -333,8 +332,7 @@ static inline void topology_init_cpu_capacity_cppc(void) if (likely(!acpi_cpc_valid())) return; - raw_capacity = kcalloc(num_possible_cpus(), sizeof(*raw_capacity), - GFP_KERNEL); + raw_capacity = kzalloc_objs(*raw_capacity, num_possible_cpus()); if (!raw_capacity) return; diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c index 0bbc83231234e6..f2b420924359c7 100644 --- a/drivers/base/pinctrl.c +++ b/drivers/base/pinctrl.c @@ -27,7 +27,7 @@ int pinctrl_bind_pins(struct device *dev) if (dev_of_node_reused(dev)) return 0; - dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL); + dev->pins = devm_kzalloc_obj(dev, *(dev->pins)); if (!dev->pins) return -ENOMEM; diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 304a2b12342082..4e9c23059a4012 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -343,6 +343,9 @@ static void __rpm_put_suppliers(struct device *dev, bool try_to_suspend) list_for_each_entry_rcu(link, &dev->links.suppliers, c_node, device_links_read_lock_held()) { + if (!device_link_test(link, DL_FLAG_PM_RUNTIME)) + continue; + pm_runtime_release_supplier(link); if (try_to_suspend) pm_request_idle(link->supplier); @@ -819,6 +822,12 @@ static int rpm_resume(struct device *dev, int rpmflags) pm_runtime_deactivate_timer(dev); if (dev->power.runtime_status == RPM_ACTIVE) { + /* + * The attempt to resume the device means that it is needed for + * something, so update its last_busy timestamp as in the case + * in which it actually resumes below. + */ + pm_runtime_mark_last_busy(dev); retval = 1; goto out; } @@ -1910,7 +1919,7 @@ void pm_runtime_reinit(struct device *dev) void pm_runtime_remove(struct device *dev) { __pm_runtime_disable(dev, false); - flush_work(&dev->power.work); + cancel_work_sync(&dev->power.work); pm_runtime_reinit(dev); } diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 3c76a5bf67b7e3..a26bd6ce00de57 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig @@ -5,15 +5,6 @@ config REGMAP bool - default y if (REGMAP_I2C || REGMAP_SLIMBUS || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO || REGMAP_FSI) - help - Enable support for the Register Map (regmap) access API. - - Usually, this option is automatically selected when needed. - However, you may want to enable it manually for running the regmap - KUnit tests. - - If unsure, say N. config REGMAP_KUNIT tristate "KUnit tests for regmap" @@ -33,37 +24,46 @@ config REGMAP_BUILD config REGMAP_AC97 tristate + imply REGMAP config REGMAP_I2C tristate depends on I2C + imply REGMAP config REGMAP_SLIMBUS tristate depends on SLIMBUS + imply REGMAP config REGMAP_SPI tristate depends on SPI + imply REGMAP config REGMAP_SPMI tristate depends on SPMI + imply REGMAP config REGMAP_W1 tristate depends on W1 + imply REGMAP config REGMAP_MDIO tristate depends on PHYLIB + imply REGMAP config REGMAP_MMIO tristate + imply REGMAP config REGMAP_IRQ bool select IRQ_DOMAIN + imply REGMAP config REGMAP_RAM tristate @@ -71,23 +71,29 @@ config REGMAP_RAM config REGMAP_SOUNDWIRE tristate depends on SOUNDWIRE + imply REGMAP config REGMAP_SOUNDWIRE_MBQ tristate depends on SOUNDWIRE + imply REGMAP config REGMAP_SCCB tristate depends on I2C + imply REGMAP config REGMAP_I3C tristate depends on I3C + imply REGMAP config REGMAP_SPI_AVMM tristate depends on SPI + imply REGMAP config REGMAP_FSI tristate depends on FSI + imply REGMAP diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c index 9bc217b1e6f9ed..34123a19bcdf3d 100644 --- a/drivers/base/regmap/regcache-maple.c +++ b/drivers/base/regmap/regcache-maple.c @@ -88,7 +88,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg, rcu_read_unlock(); - entry = kmalloc_array(last - index + 1, sizeof(*entry), map->alloc_flags); + entry = kmalloc_objs(*entry, last - index + 1, map->alloc_flags); if (!entry) return -ENOMEM; @@ -355,7 +355,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first, unsigned long *entry; int i, ret; - entry = kmalloc_array(last - first + 1, sizeof(*entry), map->alloc_flags); + entry = kmalloc_objs(*entry, last - first + 1, map->alloc_flags); if (!entry) return -ENOMEM; diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c index 26ac2c2a209508..e821996c10735a 100644 --- a/drivers/base/regmap/regcache-rbtree.c +++ b/drivers/base/regmap/regcache-rbtree.c @@ -346,9 +346,9 @@ regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg) if (!rbnode->block) goto err_free; - rbnode->cache_present = kcalloc(BITS_TO_LONGS(rbnode->blklen), - sizeof(*rbnode->cache_present), - map->alloc_flags); + rbnode->cache_present = kzalloc_objs(*rbnode->cache_present, + BITS_TO_LONGS(rbnode->blklen), + map->alloc_flags); if (!rbnode->cache_present) goto err_free_block; diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 1447967ff00b87..5b36ac48e39441 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -122,8 +122,11 @@ static int regcache_hw_init(struct regmap *map, int count) static void regcache_hw_exit(struct regmap *map) { - if (map->cache_free) + if (map->cache_free) { kfree(map->reg_defaults_raw); + map->reg_defaults_raw = NULL; + map->cache_free = false; + } } static int regcache_locked_op(struct regmap *map, @@ -276,18 +279,20 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) } err_free_reg_defaults: kfree(map->reg_defaults); + map->reg_defaults = NULL; return ret; } void regcache_exit(struct regmap *map) { + regcache_hw_exit(map); + if (map->cache_type == REGCACHE_NONE) return; BUG_ON(!map->cache_ops); - regcache_hw_exit(map); if (map->cache_ops->exit) { dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name); @@ -296,6 +301,7 @@ void regcache_exit(struct regmap *map) kfree(map->reg_defaults); map->reg_defaults = NULL; + map->cache_dirty = false; } /** diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c index 51a04961faf7be..a4a259232980d1 100644 --- a/drivers/base/regmap/regmap-i2c.c +++ b/drivers/base/regmap/regmap-i2c.c @@ -8,6 +8,7 @@ #include #include +#include #include #include "internal.h" @@ -353,7 +354,8 @@ static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, const struct i2c_adapter_quirks *quirks; const struct regmap_bus *bus = NULL; struct regmap_bus *ret_bus; - u16 max_read = 0, max_write = 0; + size_t val_bytes; + u16 max_read, max_write; if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) bus = ®map_i2c; @@ -391,18 +393,33 @@ static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, if (!bus) return ERR_PTR(-ENOTSUPP); + max_read = bus->max_raw_read; + max_write = bus->max_raw_write; + val_bytes = BITS_TO_BYTES(config->val_bits); + quirks = i2c->adapter->quirks; if (quirks) { if (quirks->max_read_len && - (bus->max_raw_read == 0 || bus->max_raw_read > quirks->max_read_len)) + quirks->max_read_len >= val_bytes && + (max_read == 0 || max_read > quirks->max_read_len)) max_read = quirks->max_read_len; - if (quirks->max_write_len && - (bus->max_raw_write == 0 || bus->max_raw_write > quirks->max_write_len)) - max_write = quirks->max_write_len - - (config->reg_bits + config->pad_bits) / BITS_PER_BYTE; + if (quirks->max_write_len) { + size_t reg_reserve_size, max_payload; + + reg_reserve_size = (config->reg_bits + config->pad_bits) / + BITS_PER_BYTE; + if (quirks->max_write_len > reg_reserve_size) { + max_payload = quirks->max_write_len - + reg_reserve_size; + if (max_payload >= val_bytes && + (max_write == 0 || max_write > max_payload)) + max_write = max_payload; + } + } - if (max_read || max_write) { + if (max_read != bus->max_raw_read || + max_write != bus->max_raw_write) { ret_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL); if (!ret_bus) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 8e6d508c4fbd24..c8fbcdf8f16883 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c @@ -733,50 +733,44 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, return -ENOMEM; if (chip->num_main_regs) { - d->main_status_buf = kcalloc(chip->num_main_regs, - sizeof(*d->main_status_buf), - GFP_KERNEL); + d->main_status_buf = kzalloc_objs(*d->main_status_buf, + chip->num_main_regs); if (!d->main_status_buf) goto err_alloc; } - d->status_buf = kcalloc(chip->num_regs, sizeof(*d->status_buf), - GFP_KERNEL); + d->status_buf = kzalloc_objs(*d->status_buf, chip->num_regs); if (!d->status_buf) goto err_alloc; if (chip->status_is_level) { - d->prev_status_buf = kcalloc(chip->num_regs, sizeof(*d->prev_status_buf), - GFP_KERNEL); + d->prev_status_buf = kzalloc_objs(*d->prev_status_buf, + chip->num_regs); if (!d->prev_status_buf) goto err_alloc; } - d->mask_buf = kcalloc(chip->num_regs, sizeof(*d->mask_buf), - GFP_KERNEL); + d->mask_buf = kzalloc_objs(*d->mask_buf, chip->num_regs); if (!d->mask_buf) goto err_alloc; - d->mask_buf_def = kcalloc(chip->num_regs, sizeof(*d->mask_buf_def), - GFP_KERNEL); + d->mask_buf_def = kzalloc_objs(*d->mask_buf_def, chip->num_regs); if (!d->mask_buf_def) goto err_alloc; if (chip->wake_base) { - d->wake_buf = kcalloc(chip->num_regs, sizeof(*d->wake_buf), - GFP_KERNEL); + d->wake_buf = kzalloc_objs(*d->wake_buf, chip->num_regs); if (!d->wake_buf) goto err_alloc; } if (chip->type_in_mask) { - d->type_buf_def = kcalloc(chip->num_regs, - sizeof(*d->type_buf_def), GFP_KERNEL); + d->type_buf_def = kzalloc_objs(*d->type_buf_def, chip->num_regs); if (!d->type_buf_def) goto err_alloc; - d->type_buf = kcalloc(chip->num_regs, sizeof(*d->type_buf), GFP_KERNEL); + d->type_buf = kzalloc_objs(*d->type_buf, chip->num_regs); if (!d->type_buf) goto err_alloc; } @@ -785,15 +779,14 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, /* * Create config_buf[num_config_bases][num_config_regs] */ - d->config_buf = kcalloc(chip->num_config_bases, - sizeof(*d->config_buf), GFP_KERNEL); + d->config_buf = kzalloc_objs(*d->config_buf, + chip->num_config_bases); if (!d->config_buf) goto err_alloc; for (i = 0; i < chip->num_config_bases; i++) { - d->config_buf[i] = kcalloc(chip->num_config_regs, - sizeof(**d->config_buf), - GFP_KERNEL); + d->config_buf[i] = kzalloc_objs(**d->config_buf, + chip->num_config_regs); if (!d->config_buf[i]) goto err_alloc; } diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c index 1de2278fa572d2..6adbc950877ca3 100644 --- a/drivers/base/regmap/regmap-mmio.c +++ b/drivers/base/regmap/regmap-mmio.c @@ -590,11 +590,16 @@ EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk); int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk) { struct regmap_mmio_context *ctx = map->bus_context; + int ret; + + ret = clk_prepare(clk); + if (ret) + return ret; ctx->clk = clk; ctx->attached_clk = true; - return clk_prepare(ctx->clk); + return 0; } EXPORT_SYMBOL_GPL(regmap_mmio_attach_clk); diff --git a/drivers/base/regmap/regmap-sdw-mbq.c b/drivers/base/regmap/regmap-sdw-mbq.c index b0312f57c9800e..cba33a7d5b4968 100644 --- a/drivers/base/regmap/regmap-sdw-mbq.c +++ b/drivers/base/regmap/regmap-sdw-mbq.c @@ -214,7 +214,7 @@ regmap_sdw_mbq_gen_context(struct device *dev, { struct regmap_mbq_context *ctx; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 48e96bc9e7b657..910f66bcff401e 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -673,48 +673,33 @@ enum regmap_endian regmap_get_val_endian(struct device *dev, } EXPORT_SYMBOL_GPL(regmap_get_val_endian); -struct regmap *__regmap_init(struct device *dev, - const struct regmap_bus *bus, - void *bus_context, - const struct regmap_config *config, - struct lock_class_key *lock_key, - const char *lock_name) +/* + * Select the locking scheme for the map. The fast_io argument tells whether + * the map has to be usable from atomic context. + */ +static int regmap_set_lock(struct regmap *map, const struct regmap_config *config, + bool fast_io, struct lock_class_key *lock_key, + const char *lock_name) { - struct regmap *map; - int ret = -EINVAL; - enum regmap_endian reg_endian, val_endian; - int i, j; - - if (!config) - goto err; - - map = kzalloc_obj(*map); - if (map == NULL) { - ret = -ENOMEM; - goto err; - } - - ret = regmap_set_name(map, config); - if (ret) - goto err_map; - - ret = -EINVAL; /* Later error paths rely on this */ - if (config->disable_locking) { map->lock = map->unlock = regmap_lock_unlock_none; map->can_sleep = config->can_sleep; regmap_debugfs_disable(map); - } else if (config->lock && config->unlock) { + return 0; + } + + if (config->lock && config->unlock) { map->lock = config->lock; map->unlock = config->unlock; map->lock_arg = config->lock_arg; map->can_sleep = config->can_sleep; - } else if (config->use_hwlock) { + return 0; + } + + if (config->use_hwlock) { map->hwlock = hwspin_lock_request_specific(config->hwlock_id); - if (!map->hwlock) { - ret = -ENXIO; - goto err_name; - } + if (!map->hwlock) + return -ENXIO; switch (config->hwlock_mode) { case HWLOCK_IRQSTATE: @@ -732,243 +717,223 @@ struct regmap *__regmap_init(struct device *dev, } map->lock_arg = map; - } else { - if ((bus && bus->fast_io) || - config->fast_io) { - if (config->use_raw_spinlock) { - raw_spin_lock_init(&map->raw_spinlock); - map->lock = regmap_lock_raw_spinlock; - map->unlock = regmap_unlock_raw_spinlock; - lockdep_set_class_and_name(&map->raw_spinlock, - lock_key, lock_name); - } else { - spin_lock_init(&map->spinlock); - map->lock = regmap_lock_spinlock; - map->unlock = regmap_unlock_spinlock; - lockdep_set_class_and_name(&map->spinlock, - lock_key, lock_name); - } + return 0; + } + + if (fast_io) { + if (config->use_raw_spinlock) { + raw_spin_lock_init(&map->raw_spinlock); + map->lock = regmap_lock_raw_spinlock; + map->unlock = regmap_unlock_raw_spinlock; + lockdep_set_class_and_name(&map->raw_spinlock, + lock_key, lock_name); } else { - mutex_init(&map->mutex); - map->lock = regmap_lock_mutex; - map->unlock = regmap_unlock_mutex; - map->can_sleep = true; - lockdep_set_class_and_name(&map->mutex, + spin_lock_init(&map->spinlock); + map->lock = regmap_lock_spinlock; + map->unlock = regmap_unlock_spinlock; + lockdep_set_class_and_name(&map->spinlock, lock_key, lock_name); } - map->lock_arg = map; - map->lock_key = lock_key; + } else { + mutex_init(&map->mutex); + map->lock = regmap_lock_mutex; + map->unlock = regmap_unlock_mutex; + map->can_sleep = true; + lockdep_set_class_and_name(&map->mutex, lock_key, lock_name); } - /* - * When we write in fast-paths with regmap_bulk_write() don't allocate - * scratch buffers with sleeping allocations. - */ - if ((bus && bus->fast_io) || config->fast_io) - map->alloc_flags = GFP_ATOMIC; - else - map->alloc_flags = GFP_KERNEL; + map->lock_arg = map; + map->lock_key = lock_key; - map->reg_base = config->reg_base; - map->reg_shift = config->pad_bits % 8; + return 0; +} - map->format.pad_bytes = config->pad_bits / 8; - map->format.reg_shift = config->reg_shift; - map->format.reg_bytes = BITS_TO_BYTES(config->reg_bits); - map->format.val_bytes = BITS_TO_BYTES(config->val_bits); - map->format.buf_size = BITS_TO_BYTES(config->reg_bits + config->val_bits + config->pad_bits); - if (config->reg_stride) - map->reg_stride = config->reg_stride; - else - map->reg_stride = 1; - if (is_power_of_2(map->reg_stride)) - map->reg_stride_order = ilog2(map->reg_stride); - else - map->reg_stride_order = -1; - map->use_single_read = config->use_single_read || !(config->read || (bus && bus->read)); - map->use_single_write = config->use_single_write || !(config->write || (bus && bus->write)); - map->can_multi_write = config->can_multi_write && (config->write || (bus && bus->write)); - if (bus) { - map->max_raw_read = bus->max_raw_read; - map->max_raw_write = bus->max_raw_write; - } else if (config->max_raw_read && config->max_raw_write) { - map->max_raw_read = config->max_raw_read; - map->max_raw_write = config->max_raw_write; - } - map->dev = dev; - map->bus = bus; - map->bus_context = bus_context; - map->max_register = config->max_register; - map->max_register_is_set = map->max_register ?: config->max_register_is_0; - map->wr_table = config->wr_table; - map->rd_table = config->rd_table; - map->volatile_table = config->volatile_table; - map->precious_table = config->precious_table; - map->wr_noinc_table = config->wr_noinc_table; - map->rd_noinc_table = config->rd_noinc_table; - map->writeable_reg = config->writeable_reg; - map->readable_reg = config->readable_reg; - map->volatile_reg = config->volatile_reg; - map->precious_reg = config->precious_reg; - map->writeable_noinc_reg = config->writeable_noinc_reg; - map->readable_noinc_reg = config->readable_noinc_reg; - map->reg_default_cb = config->reg_default_cb; - map->cache_type = config->cache_type; +/* Validate config->ranges and build the range rbtree. */ +static int regmap_init_ranges(struct regmap *map, const struct regmap_config *config) +{ + int i, j; - spin_lock_init(&map->async_lock); - INIT_LIST_HEAD(&map->async_list); - INIT_LIST_HEAD(&map->async_free); - init_waitqueue_head(&map->async_waitq); + map->range_tree = RB_ROOT; - if (config->read_flag_mask || - config->write_flag_mask || - config->zero_flag_mask) { - map->read_flag_mask = config->read_flag_mask; - map->write_flag_mask = config->write_flag_mask; - } else if (bus) { - map->read_flag_mask = bus->read_flag_mask; - } + for (i = 0; i < config->num_ranges; i++) { + const struct regmap_range_cfg *range_cfg = &config->ranges[i]; + struct regmap_range_node *new; - if (config->read && config->write) { - map->reg_read = _regmap_bus_read; - if (config->reg_update_bits) - map->reg_update_bits = config->reg_update_bits; + /* Sanity check */ + if (range_cfg->range_max < range_cfg->range_min) { + dev_err(map->dev, "Invalid range %d: %u < %u\n", i, + range_cfg->range_max, range_cfg->range_min); + return -EINVAL; + } - /* Bulk read/write */ - map->read = config->read; - map->write = config->write; + if (range_cfg->range_max > map->max_register) { + dev_err(map->dev, "Invalid range %d: %u > %u\n", i, + range_cfg->range_max, map->max_register); + return -EINVAL; + } - reg_endian = REGMAP_ENDIAN_NATIVE; - val_endian = REGMAP_ENDIAN_NATIVE; - } else if (!bus) { - map->reg_read = config->reg_read; - map->reg_write = config->reg_write; - map->reg_update_bits = config->reg_update_bits; + if (range_cfg->selector_reg > map->max_register) { + dev_err(map->dev, + "Invalid range %d: selector out of map\n", i); + return -EINVAL; + } - map->defer_caching = false; - goto skip_format_initialization; - } else if (!bus->read || !bus->write) { - map->reg_read = _regmap_bus_reg_read; - map->reg_write = _regmap_bus_reg_write; - map->reg_update_bits = bus->reg_update_bits; + if (range_cfg->window_len == 0) { + dev_err(map->dev, "Invalid range %d: window_len 0\n", + i); + return -EINVAL; + } - map->defer_caching = false; - goto skip_format_initialization; - } else { - map->reg_read = _regmap_bus_read; - map->reg_update_bits = bus->reg_update_bits; - /* Bulk read/write */ - map->read = bus->read; - map->write = bus->write; + /* + * Make sure that this register range has no selector + * or data window within its boundary. + */ + for (j = 0; j < config->num_ranges; j++) { + unsigned int sel_reg = config->ranges[j].selector_reg; + unsigned int win_min = config->ranges[j].window_start; + unsigned int win_max = win_min + + config->ranges[j].window_len - 1; + + /* Allow data window inside its own virtual range */ + if (j == i) + continue; + + if (range_cfg->range_min <= sel_reg && + sel_reg <= range_cfg->range_max) { + dev_err(map->dev, + "Range %d: selector for %d in window\n", + i, j); + return -EINVAL; + } - reg_endian = regmap_get_reg_endian(bus, config); - val_endian = regmap_get_val_endian(dev, bus, config); + if (!(win_max < range_cfg->range_min || + win_min > range_cfg->range_max)) { + dev_err(map->dev, + "Range %d: window for %d in window\n", + i, j); + return -EINVAL; + } + } + + new = kzalloc_obj(*new); + if (new == NULL) + return -ENOMEM; + + new->map = map; + new->name = range_cfg->name; + new->range_min = range_cfg->range_min; + new->range_max = range_cfg->range_max; + new->selector_reg = range_cfg->selector_reg; + new->selector_mask = range_cfg->selector_mask; + new->selector_shift = range_cfg->selector_shift; + new->window_start = range_cfg->window_start; + new->window_len = range_cfg->window_len; + + if (!_regmap_range_add(map, new)) { + dev_err(map->dev, "Failed to add range %d\n", i); + kfree(new); + return -EINVAL; + } + + if (map->selector_work_buf == NULL) { + map->selector_work_buf = + kzalloc(map->format.buf_size, GFP_KERNEL); + if (map->selector_work_buf == NULL) + return -ENOMEM; + } } + return 0; +} + +/* Pick format_reg()/format_write() for the register width and endianness. */ +static int regmap_set_reg_format(struct regmap *map, const struct regmap_config *config, + enum regmap_endian reg_endian) +{ switch (config->reg_bits + map->reg_shift) { case 2: - switch (config->val_bits) { - case 6: - map->format.format_write = regmap_format_2_6_write; - break; - default: - goto err_hwlock; - } - break; + if (config->val_bits != 6) + return -EINVAL; + map->format.format_write = regmap_format_2_6_write; + return 0; case 4: - switch (config->val_bits) { - case 12: - map->format.format_write = regmap_format_4_12_write; - break; - default: - goto err_hwlock; - } - break; + if (config->val_bits != 12) + return -EINVAL; + map->format.format_write = regmap_format_4_12_write; + return 0; case 7: switch (config->val_bits) { case 9: map->format.format_write = regmap_format_7_9_write; - break; + return 0; case 17: map->format.format_write = regmap_format_7_17_write; - break; - default: - goto err_hwlock; + return 0; } - break; + return -EINVAL; case 10: - switch (config->val_bits) { - case 14: - map->format.format_write = regmap_format_10_14_write; - break; - default: - goto err_hwlock; - } - break; + if (config->val_bits != 14) + return -EINVAL; + map->format.format_write = regmap_format_10_14_write; + return 0; case 12: - switch (config->val_bits) { - case 20: - map->format.format_write = regmap_format_12_20_write; - break; - default: - goto err_hwlock; - } - break; + if (config->val_bits != 20) + return -EINVAL; + map->format.format_write = regmap_format_12_20_write; + return 0; case 8: map->format.format_reg = regmap_format_8; - break; + return 0; case 16: switch (reg_endian) { case REGMAP_ENDIAN_BIG: map->format.format_reg = regmap_format_16_be; - break; + return 0; case REGMAP_ENDIAN_LITTLE: map->format.format_reg = regmap_format_16_le; - break; + return 0; case REGMAP_ENDIAN_NATIVE: map->format.format_reg = regmap_format_16_native; - break; + return 0; default: - goto err_hwlock; + return -EINVAL; } - break; case 24: - switch (reg_endian) { - case REGMAP_ENDIAN_BIG: - map->format.format_reg = regmap_format_24_be; - break; - default: - goto err_hwlock; - } - break; + if (reg_endian != REGMAP_ENDIAN_BIG) + return -EINVAL; + map->format.format_reg = regmap_format_24_be; + return 0; case 32: switch (reg_endian) { case REGMAP_ENDIAN_BIG: map->format.format_reg = regmap_format_32_be; - break; + return 0; case REGMAP_ENDIAN_LITTLE: map->format.format_reg = regmap_format_32_le; - break; + return 0; case REGMAP_ENDIAN_NATIVE: map->format.format_reg = regmap_format_32_native; - break; + return 0; default: - goto err_hwlock; + return -EINVAL; } - break; - - default: - goto err_hwlock; } + return -EINVAL; +} + +/* Pick format_val()/parse_val() for the value width and endianness. */ +static int regmap_set_val_format(struct regmap *map, const struct regmap_config *config, + enum regmap_endian val_endian) +{ if (val_endian == REGMAP_ENDIAN_NATIVE) map->format.parse_inplace = regmap_parse_inplace_noop; @@ -977,75 +942,89 @@ struct regmap *__regmap_init(struct device *dev, map->format.format_val = regmap_format_8; map->format.parse_val = regmap_parse_8; map->format.parse_inplace = regmap_parse_inplace_noop; - break; + return 0; case 16: switch (val_endian) { case REGMAP_ENDIAN_BIG: map->format.format_val = regmap_format_16_be; map->format.parse_val = regmap_parse_16_be; map->format.parse_inplace = regmap_parse_16_be_inplace; - break; + return 0; case REGMAP_ENDIAN_LITTLE: map->format.format_val = regmap_format_16_le; map->format.parse_val = regmap_parse_16_le; map->format.parse_inplace = regmap_parse_16_le_inplace; - break; + return 0; case REGMAP_ENDIAN_NATIVE: map->format.format_val = regmap_format_16_native; map->format.parse_val = regmap_parse_16_native; - break; + return 0; default: - goto err_hwlock; + return -EINVAL; } - break; case 24: - switch (val_endian) { - case REGMAP_ENDIAN_BIG: - map->format.format_val = regmap_format_24_be; - map->format.parse_val = regmap_parse_24_be; - break; - default: - goto err_hwlock; - } - break; + if (val_endian != REGMAP_ENDIAN_BIG) + return -EINVAL; + map->format.format_val = regmap_format_24_be; + map->format.parse_val = regmap_parse_24_be; + return 0; case 32: switch (val_endian) { case REGMAP_ENDIAN_BIG: map->format.format_val = regmap_format_32_be; map->format.parse_val = regmap_parse_32_be; map->format.parse_inplace = regmap_parse_32_be_inplace; - break; + return 0; case REGMAP_ENDIAN_LITTLE: map->format.format_val = regmap_format_32_le; map->format.parse_val = regmap_parse_32_le; map->format.parse_inplace = regmap_parse_32_le_inplace; - break; + return 0; case REGMAP_ENDIAN_NATIVE: map->format.format_val = regmap_format_32_native; map->format.parse_val = regmap_parse_32_native; - break; + return 0; default: - goto err_hwlock; + return -EINVAL; } - break; } + return 0; +} + +/* + * Set up the format/parse functions, cross-validate endianness, + * allocate the work buffer and select the bus write path. + */ +static int regmap_init_format(struct regmap *map, + const struct regmap_config *config, + enum regmap_endian reg_endian, + enum regmap_endian val_endian) +{ + int ret; + + ret = regmap_set_reg_format(map, config, reg_endian); + if (ret) + return ret; + + ret = regmap_set_val_format(map, config, val_endian); + if (ret) + return ret; + if (map->format.format_write) { - if ((reg_endian != REGMAP_ENDIAN_BIG) || - (val_endian != REGMAP_ENDIAN_BIG)) - goto err_hwlock; + if (reg_endian != REGMAP_ENDIAN_BIG || + val_endian != REGMAP_ENDIAN_BIG) + return -EINVAL; map->use_single_write = true; } if (!map->format.format_write && !(map->format.format_reg && map->format.format_val)) - goto err_hwlock; + return -EINVAL; map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL); - if (map->work_buf == NULL) { - ret = -ENOMEM; - goto err_hwlock; - } + if (map->work_buf == NULL) + return -ENOMEM; if (map->format.format_write) { map->defer_caching = false; @@ -1055,99 +1034,152 @@ struct regmap *__regmap_init(struct device *dev, map->reg_write = _regmap_bus_raw_write; } -skip_format_initialization: + return 0; +} - map->range_tree = RB_ROOT; - for (i = 0; i < config->num_ranges; i++) { - const struct regmap_range_cfg *range_cfg = &config->ranges[i]; - struct regmap_range_node *new; +struct regmap *__regmap_init(struct device *dev, + const struct regmap_bus *bus, + void *bus_context, + const struct regmap_config *config, + struct lock_class_key *lock_key, + const char *lock_name) +{ + struct regmap *map; + bool fast_io; + int ret; - /* Sanity check */ - if (range_cfg->range_max < range_cfg->range_min) { - dev_err(map->dev, "Invalid range %d: %u < %u\n", i, - range_cfg->range_max, range_cfg->range_min); - goto err_range; - } + if (!config) { + ret = -EINVAL; + goto err; + } - if (range_cfg->range_max > map->max_register) { - dev_err(map->dev, "Invalid range %d: %u > %u\n", i, - range_cfg->range_max, map->max_register); - goto err_range; - } + map = kzalloc_obj(*map); + if (map == NULL) { + ret = -ENOMEM; + goto err; + } - if (range_cfg->selector_reg > map->max_register) { - dev_err(map->dev, - "Invalid range %d: selector out of map\n", i); - goto err_range; - } + ret = regmap_set_name(map, config); + if (ret) + goto err_map; - if (range_cfg->window_len == 0) { - dev_err(map->dev, "Invalid range %d: window_len 0\n", - i); - goto err_range; - } + fast_io = (bus && bus->fast_io) || config->fast_io; - /* Make sure, that this register range has no selector - or data window within its boundary */ - for (j = 0; j < config->num_ranges; j++) { - unsigned int sel_reg = config->ranges[j].selector_reg; - unsigned int win_min = config->ranges[j].window_start; - unsigned int win_max = win_min + - config->ranges[j].window_len - 1; + ret = regmap_set_lock(map, config, fast_io, lock_key, lock_name); + if (ret) + goto err_name; - /* Allow data window inside its own virtual range */ - if (j == i) - continue; + /* + * When we write in fast-paths with regmap_bulk_write() don't allocate + * scratch buffers with sleeping allocations. + */ + map->alloc_flags = fast_io ? GFP_ATOMIC : GFP_KERNEL; - if (range_cfg->range_min <= sel_reg && - sel_reg <= range_cfg->range_max) { - dev_err(map->dev, - "Range %d: selector for %d in window\n", - i, j); - goto err_range; - } + map->reg_base = config->reg_base; + map->reg_shift = config->pad_bits % 8; - if (!(win_max < range_cfg->range_min || - win_min > range_cfg->range_max)) { - dev_err(map->dev, - "Range %d: window for %d in window\n", - i, j); - goto err_range; - } - } + map->format.pad_bytes = config->pad_bits / 8; + map->format.reg_shift = config->reg_shift; + map->format.reg_bytes = BITS_TO_BYTES(config->reg_bits); + map->format.val_bytes = BITS_TO_BYTES(config->val_bits); + map->format.buf_size = BITS_TO_BYTES(config->reg_bits + config->val_bits + config->pad_bits); + if (config->reg_stride) + map->reg_stride = config->reg_stride; + else + map->reg_stride = 1; + if (is_power_of_2(map->reg_stride)) + map->reg_stride_order = ilog2(map->reg_stride); + else + map->reg_stride_order = -1; + map->use_single_read = config->use_single_read || !(config->read || (bus && bus->read)); + map->use_single_write = config->use_single_write || !(config->write || (bus && bus->write)); + map->can_multi_write = config->can_multi_write && (config->write || (bus && bus->write)); + if (bus) { + map->max_raw_read = bus->max_raw_read; + map->max_raw_write = bus->max_raw_write; + } else if (config->max_raw_read && config->max_raw_write) { + map->max_raw_read = config->max_raw_read; + map->max_raw_write = config->max_raw_write; + } + map->dev = dev; + map->bus = bus; + map->bus_context = bus_context; + map->max_register = config->max_register; + map->max_register_is_set = map->max_register ?: config->max_register_is_0; + map->wr_table = config->wr_table; + map->rd_table = config->rd_table; + map->volatile_table = config->volatile_table; + map->precious_table = config->precious_table; + map->wr_noinc_table = config->wr_noinc_table; + map->rd_noinc_table = config->rd_noinc_table; + map->writeable_reg = config->writeable_reg; + map->readable_reg = config->readable_reg; + map->volatile_reg = config->volatile_reg; + map->precious_reg = config->precious_reg; + map->writeable_noinc_reg = config->writeable_noinc_reg; + map->readable_noinc_reg = config->readable_noinc_reg; + map->reg_default_cb = config->reg_default_cb; + map->cache_type = config->cache_type; - new = kzalloc_obj(*new); - if (new == NULL) { - ret = -ENOMEM; - goto err_range; - } + spin_lock_init(&map->async_lock); + INIT_LIST_HEAD(&map->async_list); + INIT_LIST_HEAD(&map->async_free); + init_waitqueue_head(&map->async_waitq); - new->map = map; - new->name = range_cfg->name; - new->range_min = range_cfg->range_min; - new->range_max = range_cfg->range_max; - new->selector_reg = range_cfg->selector_reg; - new->selector_mask = range_cfg->selector_mask; - new->selector_shift = range_cfg->selector_shift; - new->window_start = range_cfg->window_start; - new->window_len = range_cfg->window_len; + if (config->read_flag_mask || + config->write_flag_mask || + config->zero_flag_mask) { + map->read_flag_mask = config->read_flag_mask; + map->write_flag_mask = config->write_flag_mask; + } else if (bus) { + map->read_flag_mask = bus->read_flag_mask; + } - if (!_regmap_range_add(map, new)) { - dev_err(map->dev, "Failed to add range %d\n", i); - kfree(new); - goto err_range; - } + if (config->read && config->write) { + map->reg_read = _regmap_bus_read; + if (config->reg_update_bits) + map->reg_update_bits = config->reg_update_bits; - if (map->selector_work_buf == NULL) { - map->selector_work_buf = - kzalloc(map->format.buf_size, GFP_KERNEL); - if (map->selector_work_buf == NULL) { - ret = -ENOMEM; - goto err_range; - } - } + /* Bulk read/write */ + map->read = config->read; + map->write = config->write; + + ret = regmap_init_format(map, config, + REGMAP_ENDIAN_NATIVE, + REGMAP_ENDIAN_NATIVE); + if (ret) + goto err_hwlock; + } else if (!bus) { + map->reg_read = config->reg_read; + map->reg_write = config->reg_write; + map->reg_update_bits = config->reg_update_bits; + + map->defer_caching = false; + } else if (!bus->read || !bus->write) { + map->reg_read = _regmap_bus_reg_read; + map->reg_write = _regmap_bus_reg_write; + map->reg_update_bits = bus->reg_update_bits; + + map->defer_caching = false; + } else { + map->reg_read = _regmap_bus_read; + map->reg_update_bits = bus->reg_update_bits; + /* Bulk read/write */ + map->read = bus->read; + map->write = bus->write; + + ret = regmap_init_format(map, config, + regmap_get_reg_endian(bus, config), + regmap_get_val_endian(dev, bus, config)); + if (ret) + goto err_hwlock; } + + ret = regmap_init_ranges(map, config); + if (ret) + goto err_range; + ret = regcache_init(map, config); if (ret != 0) goto err_range; @@ -1237,8 +1269,7 @@ static void regmap_field_init(struct regmap_field *rm_field, struct regmap_field *devm_regmap_field_alloc(struct device *dev, struct regmap *regmap, struct reg_field reg_field) { - struct regmap_field *rm_field = devm_kzalloc(dev, - sizeof(*rm_field), GFP_KERNEL); + struct regmap_field *rm_field = devm_kzalloc_obj(dev, *rm_field); if (!rm_field) return ERR_PTR(-ENOMEM); @@ -1306,7 +1337,7 @@ int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap_field *rf; int i; - rf = devm_kcalloc(dev, num_fields, sizeof(*rf), GFP_KERNEL); + rf = devm_kzalloc_objs(dev, *rf, num_fields); if (!rf) return -ENOMEM; @@ -1423,6 +1454,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) regmap_debugfs_exit(map); regcache_exit(map); + map->cache_ops = NULL; map->max_register = config->max_register; map->max_register_is_set = map->max_register ?: config->max_register_is_0; @@ -1433,22 +1465,29 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) map->writeable_noinc_reg = config->writeable_noinc_reg; map->readable_noinc_reg = config->readable_noinc_reg; map->reg_default_cb = config->reg_default_cb; - map->cache_type = config->cache_type; ret = regmap_set_name(map, config); if (ret) - return ret; + goto err_none; map->cache_bypass = false; map->cache_only = false; + map->cache_type = config->cache_type; ret = regcache_init(map, config); if (ret) - return ret; + goto err_none; regmap_debugfs_init(map); return 0; + +err_none: + map->cache_ops = NULL; + map->cache_type = REGCACHE_NONE; + map->cache_bypass = true; + map->cache_only = false; + return ret; } EXPORT_SYMBOL_GPL(regmap_reinit_cache); @@ -1641,11 +1680,10 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, { struct regmap_range_node *range; unsigned long flags; - void *work_val = map->work_buf + map->format.reg_bytes + - map->format.pad_bytes; + void *work_val; void *buf; - int ret = -ENOTSUPP; size_t len; + int ret; int i; /* Check for unwritable or noinc registers in range @@ -1725,6 +1763,7 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, * buffer to write. Since register syncs often generate raw * writes of single registers optimise that case. */ + work_val = map->work_buf + map->format.reg_bytes + map->format.pad_bytes; if (val != work_val && val_len == map->format.val_bytes) { memcpy(work_val, val, map->format.val_bytes); val = work_val; @@ -2328,8 +2367,8 @@ EXPORT_SYMBOL_GPL(regmap_fields_update_bits_base); int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, size_t val_count) { - int ret = 0, i; size_t val_bytes = map->format.val_bytes; + int ret, i; if (!IS_ALIGNED(reg, map->reg_stride)) return -EINVAL; @@ -2339,6 +2378,8 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, * single write operations. */ if (!map->write || !map->format.parse_inplace) { + ret = 0; /* Later error paths rely on this */ + guard(regmap)(map); for (i = 0; i < val_count; i++) { @@ -2596,9 +2637,9 @@ static int _regmap_multi_reg_write(struct regmap *map, */ range = _regmap_range_lookup(map, reg); if (range || regs[i].delay_us) { - size_t len = sizeof(struct reg_sequence)*num_regs; - struct reg_sequence *base = kmemdup(regs, len, - GFP_KERNEL); + struct reg_sequence *base; + + base = kmemdup_array(regs, num_regs, sizeof(*regs), GFP_KERNEL); if (!base) return -ENOMEM; ret = _regmap_range_multi_paged_reg_write(map, base, @@ -2776,12 +2817,12 @@ static int _regmap_bus_read(void *context, unsigned int reg, { int ret; struct regmap *map = context; - void *work_val = map->work_buf + map->format.reg_bytes + - map->format.pad_bytes; + void *work_val; if (!map->format.parse_val) return -EINVAL; + work_val = map->work_buf + map->format.reg_bytes + map->format.pad_bytes; ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false); if (ret == 0) *val = map->format.parse_val(work_val); diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 84a77ffa3dc4bb..cf495e67f0763a 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -29,6 +29,8 @@ struct swnode { struct fwnode_handle fwnode; const struct software_node *node; int id; + /* Device the managed node's lifetime is tied to. */ + struct device *owner; /* hierarchy */ struct ida child_ids; @@ -37,7 +39,6 @@ struct swnode { struct swnode *parent; unsigned int allocated:1; - unsigned int managed:1; }; static DEFINE_IDA(swnode_root_ids); @@ -1145,7 +1146,7 @@ int device_create_managed_software_node(struct device *dev, if (IS_ERR(fwnode)) return PTR_ERR(fwnode); - to_swnode(fwnode)->managed = true; + to_swnode(fwnode)->owner = dev; set_secondary_fwnode(dev, fwnode); if (device_is_registered(dev)) @@ -1208,7 +1209,7 @@ void software_node_notify_remove(struct device *dev) swnode_put(swnode); - if (swnode->managed) { + if (swnode->owner == dev) { set_secondary_fwnode(dev, NULL); swnode_put(swnode); } diff --git a/drivers/bcma/driver_chipcommon.c b/drivers/bcma/driver_chipcommon.c index fd91a39f02c739..ca268dfcb1e429 100644 --- a/drivers/bcma/driver_chipcommon.c +++ b/drivers/bcma/driver_chipcommon.c @@ -3,7 +3,7 @@ * ChipCommon core driver * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * Copyright 2012, Hauke Mehrtens * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/bcma/driver_chipcommon_pmu.c b/drivers/bcma/driver_chipcommon_pmu.c index 263ef6fa1d0f7d..d29950e06b0a8f 100644 --- a/drivers/bcma/driver_chipcommon_pmu.c +++ b/drivers/bcma/driver_chipcommon_pmu.c @@ -2,7 +2,7 @@ * Broadcom specific AMBA * ChipCommon Power Management Unit driver * - * Copyright 2009, Michael Buesch + * Copyright 2009, Michael Buesch * Copyright 2007, 2011, Broadcom Corporation * Copyright 2011, 2012, Hauke Mehrtens * diff --git a/drivers/bcma/driver_pci.c b/drivers/bcma/driver_pci.c index 12b2cc9a3fbe8a..30291954c02f01 100644 --- a/drivers/bcma/driver_pci.c +++ b/drivers/bcma/driver_pci.c @@ -3,7 +3,7 @@ * PCI Core * * Copyright 2005, 2011, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * Copyright 2011, 2012, Hauke Mehrtens * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/bcma/driver_pci_host.c b/drivers/bcma/driver_pci_host.c index f121be2ed81393..4a1c3c6af20c4d 100644 --- a/drivers/bcma/driver_pci_host.c +++ b/drivers/bcma/driver_pci_host.c @@ -3,7 +3,7 @@ * PCI Core in hostmode * * Copyright 2005 - 2011, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * Copyright 2011, 2012, Hauke Mehrtens * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/bcma/host_soc.c b/drivers/bcma/host_soc.c index 20b1816c570b23..50816d7bda2a3e 100644 --- a/drivers/bcma/host_soc.c +++ b/drivers/bcma/host_soc.c @@ -208,7 +208,7 @@ static int bcma_host_soc_probe(struct platform_device *pdev) int err; /* Alloc */ - bus = devm_kzalloc(dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(dev, *bus); if (!bus) return -ENOMEM; diff --git a/drivers/bcma/sprom.c b/drivers/bcma/sprom.c index e668ad7963fc25..7c8ba01c036c6d 100644 --- a/drivers/bcma/sprom.c +++ b/drivers/bcma/sprom.c @@ -620,7 +620,7 @@ int bcma_sprom_get(struct bcma_bus *bus) for (i = 0; i < ARRAY_SIZE(sprom_sizes); i++) { size_t words = sprom_sizes[i]; - sprom = kcalloc(words, sizeof(u16), GFP_KERNEL); + sprom = kzalloc_objs(u16, words); if (!sprom) return -ENOMEM; diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 099dff1ea2565d..890d1c898f239f 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -473,8 +473,7 @@ static void drbd_calc_cpu_mask(cpumask_var_t *cpu_mask) { unsigned int *resources_per_cpu, min_index = ~0; - resources_per_cpu = kcalloc(nr_cpu_ids, sizeof(*resources_per_cpu), - GFP_KERNEL); + resources_per_cpu = kzalloc_objs(*resources_per_cpu, nr_cpu_ids); if (resources_per_cpu) { struct drbd_resource *resource; unsigned int cpu, min = ~0; diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c index a405ccdf919e4b..3799b8dece37c0 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c @@ -4063,7 +4063,7 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info return config_unknown_volume(connection, pi); device = peer_device->device; - p_uuid = kmalloc_array(UI_EXTENDED_SIZE, sizeof(*p_uuid), GFP_NOIO); + p_uuid = kmalloc_objs(*p_uuid, UI_EXTENDED_SIZE, GFP_NOIO); if (!p_uuid) return false; diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 6beb1f5b71acc6..ec0d7ba4d93874 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1976,6 +1976,7 @@ static int null_add_dev(struct nullb_device *dev) rv = null_validate_conf(dev); if (rv) return rv; + clear_bit(NULLB_DEV_FL_CACHE, &dev->flags); nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node); if (!nullb) { diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 7e9b5ffb9e841a..b271d0a88ff210 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -311,10 +311,8 @@ static blk_status_t null_check_open(struct nullb_device *dev) return BLK_STS_OK; if (dev->nr_zones_imp_open) { - if (null_check_active(dev) == BLK_STS_OK) { - null_close_imp_open_zone(dev); - return BLK_STS_OK; - } + null_close_imp_open_zone(dev); + return BLK_STS_OK; } return BLK_STS_ZONE_OPEN_RESOURCE; @@ -330,8 +328,11 @@ static blk_status_t null_check_open(struct nullb_device *dev) * * ZBC states that an implicit open zone shall be closed only if there is not * room within the open limit. However, with the addition of an active limit, - * it is not certain that closing an implicit open zone will allow a new zone - * to be opened, since we might already be at the active limit capacity. + * it is not certain that closing an implicit open zone will allow an empty + * zone to be opened, since we might already be at the active limit capacity. + * Therefore, the active limit is checked first for an empty zone. A closed + * zone already holds an active zone resource, so only the open limit has to + * be checked for a closed zone. */ static blk_status_t null_check_zone_resources(struct nullb_device *dev, struct nullb_zone *zone) @@ -743,23 +744,47 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_op op, } /* - * Set a zone in the read-only or offline condition. + * Release the zone resources held by a zone, before changing the condition of + * the zone to a condition that does not hold any zone resources. */ -static void null_set_zone_cond(struct nullb_device *dev, - struct nullb_zone *zone, enum blk_zone_cond cond) +static void null_release_zone_resources(struct nullb_device *dev, + struct nullb_zone *zone) { - if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY && - cond != BLK_ZONE_COND_OFFLINE)) + if (!dev->need_zone_res_mgmt) return; + spin_lock(&dev->zone_res_lock); + switch (zone->cond) { + case BLK_ZONE_COND_IMP_OPEN: + dev->nr_zones_imp_open--; + break; + case BLK_ZONE_COND_EXP_OPEN: + dev->nr_zones_exp_open--; + break; + case BLK_ZONE_COND_CLOSED: + dev->nr_zones_closed--; + break; + default: + break; + } + spin_unlock(&dev->zone_res_lock); +} + +static void null_set_zone_readonly_or_offline(struct nullb_device *dev, + struct nullb_zone *zone, + bool set_offline) +{ + enum blk_zone_cond cond = + set_offline ? BLK_ZONE_COND_OFFLINE : BLK_ZONE_COND_READONLY; + null_lock_zone(dev, zone); /* * If the read-only condition is requested again to zones already in * read-only condition, restore back normal empty condition. Do the same * if the offline condition is requested for offline zones. Otherwise, - * set the specified zone condition to the zones. Finish the zones - * beforehand to free up zone resources. + * set the specified zone condition to the zones. Release the zone + * resources held by the zones beforehand. */ if (zone->cond == cond) { zone->cond = BLK_ZONE_COND_EMPTY; @@ -767,9 +792,7 @@ static void null_set_zone_cond(struct nullb_device *dev, if (dev->memory_backed) null_handle_discard(dev, zone->start, zone->len); } else { - if (zone->cond != BLK_ZONE_COND_READONLY && - zone->cond != BLK_ZONE_COND_OFFLINE) - null_finish_zone(dev, zone); + null_release_zone_resources(dev, zone); zone->cond = cond; zone->wp = NULL_ZONE_INVALID_WP; } @@ -788,6 +811,11 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page, unsigned int zone_no; int ret; + /* Read-only and offline are the only conditions supported for now */ + if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY && + cond != BLK_ZONE_COND_OFFLINE)) + return -EINVAL; + if (!dev->zoned) { pr_err("null_blk device is not zoned\n"); return -EINVAL; @@ -813,7 +841,8 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page, return -EINVAL; } - null_set_zone_cond(dev, &dev->zones[zone_no], cond); + null_set_zone_readonly_or_offline(dev, &dev->zones[zone_no], + cond == BLK_ZONE_COND_OFFLINE); return count; } diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 1f1c2810f6ee35..54892ea5054851 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -1043,9 +1043,7 @@ static int rbd_header_from_disk(struct rbd_image_header *header, goto out_err; /* ...as well as the array of their sizes. */ - snap_sizes = kmalloc_array(snap_count, - sizeof(*header->snap_sizes), - GFP_KERNEL); + snap_sizes = kmalloc_objs(*header->snap_sizes, snap_count); if (!snap_sizes) goto out_err; diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 72e9c435208cb4..d415be37d5ede6 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -881,7 +881,8 @@ static ssize_t ublk_batch_copy_io_tags(struct ublk_batch_fetch_cmd *fcmd, * by cgroup. */ static unsigned int unprivileged_ublks_max = 64; -static unsigned int unprivileged_ublks_added; /* protected by ublk_ctl_mutex */ +/* checked and incremented under ublk_ctl_mutex, decremented without it */ +static atomic_t unprivileged_ublks_added = ATOMIC_INIT(0); static struct miscdevice ublk_misc; @@ -4405,14 +4406,18 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx) int i = idx; int err; + /* + * Only reserve the id: the device is published by + * ublk_publish_dev_number() once it is fully set up. + */ spin_lock(&ublk_idr_lock); /* allocate id, if @id >= 0, we're requesting that specific id */ if (i >= 0) { - err = idr_alloc(&ublk_index_idr, ub, i, i + 1, GFP_NOWAIT); + err = idr_alloc(&ublk_index_idr, NULL, i, i + 1, GFP_NOWAIT); if (err == -ENOSPC) err = -EEXIST; } else { - err = idr_alloc(&ublk_index_idr, ub, 0, UBLK_MAX_UBLKS, + err = idr_alloc(&ublk_index_idr, NULL, 0, UBLK_MAX_UBLKS, GFP_NOWAIT); } spin_unlock(&ublk_idr_lock); @@ -4423,6 +4428,19 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx) return err; } +/* + * Make the device visible to control commands by its id. Before its char + * device is added, DEL_DEV could find it and remove a char device that was + * never added, and drop the reference that ublk_add_chdev() drops on + * failure. + */ +static void ublk_publish_dev_number(struct ublk_device *ub) +{ + spin_lock(&ublk_idr_lock); + WARN_ON_ONCE(idr_replace(&ublk_index_idr, ub, ub->ub_number) != NULL); + spin_unlock(&ublk_idr_lock); +} + static void ublk_free_dev_number(struct ublk_device *ub) { spin_lock(&ublk_idr_lock); @@ -4469,7 +4487,7 @@ static int ublk_add_chdev(struct ublk_device *ub) goto fail; if (ub->dev_info.flags & UBLK_F_UNPRIVILEGED_DEV) - unprivileged_ublks_added++; + atomic_inc(&unprivileged_ublks_added); return 0; fail: put_device(dev); @@ -4501,15 +4519,9 @@ static int ublk_add_tag_set(struct ublk_device *ub) static void ublk_remove(struct ublk_device *ub) { - bool unprivileged; - ublk_stop_dev(ub); cdev_device_del(&ub->cdev, &ub->cdev_dev); - unprivileged = ub->dev_info.flags & UBLK_F_UNPRIVILEGED_DEV; ublk_put_device(ub); - - if (unprivileged) - unprivileged_ublks_added--; } static struct ublk_device *ublk_get_device_from_id(int idx) @@ -4899,7 +4911,7 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header) ret = -EACCES; if ((info.flags & UBLK_F_UNPRIVILEGED_DEV) && - unprivileged_ublks_added >= unprivileged_ublks_max) + atomic_read(&unprivileged_ublks_added) >= unprivileged_ublks_max) goto out_unlock; ret = -ENOMEM; @@ -4991,6 +5003,8 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header) * ublk_add_chdev() will cleanup everything if it fails. */ ret = ublk_add_chdev(ub); + if (!ret) + ublk_publish_dev_number(ub); goto out_unlock; out_deinit_queues: @@ -5023,23 +5037,23 @@ static int ublk_ctrl_del_dev(struct ublk_device **p_ub, bool wait) { struct ublk_device *ub = *p_ub; int idx = ub->ub_number; - int ret; - - ret = mutex_lock_killable(&ublk_ctl_mutex); - if (ret) - return ret; + bool unprivileged = ub->dev_info.flags & UBLK_F_UNPRIVILEGED_DEV; - if (!test_bit(UB_STATE_DELETED, &ub->state)) { + /* + * Don't take ublk_ctl_mutex: stopping the device may wait for the + * filesystem on its disk indefinitely, and ADD_DEV and DEL_DEV of all + * other ublk devices would wait for that too. ADD_DEV is done with the + * device, it is found by its id only then. + */ + if (!test_and_set_bit(UB_STATE_DELETED, &ub->state)) { ublk_remove(ub); - set_bit(UB_STATE_DELETED, &ub->state); + if (unprivileged) + atomic_dec(&unprivileged_ublks_added); } - mutex_unlock(&ublk_ctl_mutex); - /* - * Drop the reference outside ublk_ctl_mutex: if it is the last one, - * the release frees the tag set, which waits for an SRCU grace period, - * and holding the mutex would serialize concurrent deletions on it. + * If this is the last reference, the release frees the tag set, which + * waits for an SRCU grace period. */ *p_ub = NULL; ublk_put_device(ub); @@ -5878,6 +5892,7 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub, case UBLK_CMD_STOP_DEV: case UBLK_CMD_ADD_DEV: case UBLK_CMD_DEL_DEV: + case UBLK_CMD_DEL_DEV_ASYNC: case UBLK_CMD_SET_PARAMS: case UBLK_CMD_START_USER_RECOVERY: case UBLK_CMD_END_USER_RECOVERY: diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index c8bfbf8435ac7e..2b462005cdb680 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -331,18 +331,25 @@ static inline u8 virtblk_vbr_status(struct virtblk_req *vbr) return *((u8 *)&vbr->in_hdr + vbr->in_hdr_len - 1); } +static inline void virtblk_update_zone_append_sector(struct request *req, + struct virtblk_req *vbr) +{ + struct virtio_blk *vblk = req->mq_hctx->queue->queuedata; + + if (req_op(req) == REQ_OP_ZONE_APPEND) + req->__sector = virtio64_to_cpu(vblk->vdev, + vbr->in_hdr.zone_append.sector); +} + static inline void virtblk_request_done(struct request *req) { struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); blk_status_t status = virtblk_result(virtblk_vbr_status(vbr)); - struct virtio_blk *vblk = req->mq_hctx->queue->queuedata; virtblk_unmap_data(req, vbr); virtblk_cleanup_cmd(req); - if (req_op(req) == REQ_OP_ZONE_APPEND) - req->__sector = virtio64_to_cpu(vblk->vdev, - vbr->in_hdr.zone_append.sector); + virtblk_update_zone_append_sector(req, vbr); blk_mq_end_request(req, status); } @@ -958,16 +965,13 @@ static void virtblk_config_changed(struct virtio_device *vdev) queue_work(virtblk_wq, &vblk->config_work); } -static int init_vq(struct virtio_blk *vblk) +/* Keep the queue layout unchanged for the lifetime of the tag set. */ +static int virtblk_init_queue_layout(struct virtio_blk *vblk) { - int err; - unsigned short i; - struct virtqueue_info *vqs_info; - struct virtqueue **vqs; + struct virtio_device *vdev = vblk->vdev; unsigned short num_vqs; unsigned short num_poll_vqs; - struct virtio_device *vdev = vblk->vdev; - struct irq_affinity desc = { 0, }; + int err; err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ, struct virtio_blk_config, num_queues, @@ -985,6 +989,7 @@ static int init_vq(struct virtio_blk *vblk) num_poll_vqs = min_t(unsigned int, poll_queues, num_vqs - 1); + vblk->num_vqs = num_vqs; vblk->io_queues[HCTX_TYPE_DEFAULT] = num_vqs - num_poll_vqs; vblk->io_queues[HCTX_TYPE_READ] = 0; vblk->io_queues[HCTX_TYPE_POLL] = num_poll_vqs; @@ -994,6 +999,20 @@ static int init_vq(struct virtio_blk *vblk) vblk->io_queues[HCTX_TYPE_READ], vblk->io_queues[HCTX_TYPE_POLL]); + return 0; +} + +static int init_vq(struct virtio_blk *vblk) +{ + int err; + unsigned short i; + struct virtqueue_info *vqs_info; + struct virtqueue **vqs; + unsigned short num_vqs = vblk->num_vqs; + unsigned short num_poll_vqs = vblk->io_queues[HCTX_TYPE_POLL]; + struct virtio_device *vdev = vblk->vdev; + struct irq_affinity desc = { 0, }; + vblk->vqs = kmalloc_objs(*vblk->vqs, num_vqs); if (!vblk->vqs) return -ENOMEM; @@ -1022,10 +1041,33 @@ static int init_vq(struct virtio_blk *vblk) goto out; for (i = 0; i < num_vqs; i++) { + unsigned int ring_size = virtqueue_get_vring_size(vqs[i]); + /* + * Each request consumes 2 extra descriptors (out_hdr and + * in_hdr) in addition to the data segments. + * + * At initial probe (!vblk->disk), each virtqueue must fit at + * least 1 data segment + 2 header descriptors (3). + * On resume/recovery (vblk->disk), each virtqueue must fit the + * existing queue_max_segments() + 2 header descriptors. + */ + unsigned int min_ring_size = 3; + + if (vblk->disk) + min_ring_size = queue_max_segments(vblk->disk->queue) + 2; + + if (ring_size < min_ring_size) { + dev_err(&vdev->dev, + "virtqueue %u ring size %u is smaller than minimum %u\n", + i, ring_size, min_ring_size); + vdev->config->del_vqs(vdev); + err = -EINVAL; + goto out; + } + spin_lock_init(&vblk->vqs[i].lock); vblk->vqs[i].vq = vqs[i]; } - vblk->num_vqs = num_vqs; out: kfree(vqs); @@ -1196,8 +1238,11 @@ static void virtblk_complete_batch(struct io_comp_batch *iob) struct request *req; rq_list_for_each(&iob->req_list, req) { - virtblk_unmap_data(req, blk_mq_rq_to_pdu(req)); + struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); + + virtblk_unmap_data(req, vbr); virtblk_cleanup_cmd(req); + virtblk_update_zone_append_sector(req, vbr); } blk_mq_end_request_batch(iob); } @@ -1254,7 +1299,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk, u16 min_io_size; u8 physical_block_exp, alignment_offset; size_t max_dma_size; - int err; + int err, i; /* We need to know how many segments before we allocate. */ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SEG_MAX, @@ -1268,6 +1313,23 @@ static int virtblk_read_limits(struct virtio_blk *vblk, /* Prevent integer overflows and honor max vq size */ sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2); + /* + * virtblk_add_req() uses separate outgoing and incoming header + * descriptors (out_hdr and in_hdr), consuming 2 extra descriptors + * per request in addition to the data segments. + * + * Per virtio specification (2.7.5.3.1), a driver MUST NOT create a + * descriptor chain longer than the Queue Size of the device. + * + * Clamp max_segments to (ring_size - 2) across all virtqueues so + * that a request never exceeds the ring size of any queue. + */ + for (i = 0; i < vblk->num_vqs; i++) { + u32 ring_size = virtqueue_get_vring_size(vblk->vqs[i].vq); + + sg_elems = min_t(u32, sg_elems, ring_size - 2); + } + /* We can handle whatever the host told us to handle. */ lim->max_segments = sg_elems; @@ -1467,9 +1529,14 @@ static int virtblk_probe(struct virtio_device *vdev) mutex_init(&vblk->vdev_mutex); vblk->vdev = vdev; + vblk->disk = NULL; INIT_WORK(&vblk->config_work, virtblk_config_changed_work); + err = virtblk_init_queue_layout(vblk); + if (err) + goto out_free_vblk; + err = init_vq(vblk); if (err) goto out_free_vblk; @@ -1548,6 +1615,7 @@ static int virtblk_probe(struct virtio_device *vdev) return 0; out_cleanup_disk: + virtio_reset_device(vdev); put_disk(vblk->disk); out_free_tags: blk_mq_free_tag_set(&vblk->tag_set); @@ -1596,7 +1664,7 @@ static int virtblk_freeze_priv(struct virtio_device *vdev) /* Ensure no requests in virtqueues before deleting vqs. */ memflags = blk_mq_freeze_queue(q); - blk_mq_quiesce_queue_nowait(q); + blk_mq_quiesce_queue(q); blk_mq_unfreeze_queue(q, memflags); /* Ensure we don't receive any more interrupts */ diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index b427d54bc1205e..f5890b3f1df9c0 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h @@ -318,8 +318,10 @@ struct xen_blkif { unsigned int nr_ring_pages; bool multi_ref; /* All rings for this device. */ + rwlock_t rings_lock; struct xen_blkif_ring *rings; unsigned int nr_rings; + unsigned long buffer_squeeze_end; }; diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 4b865ef800b1e3..8d0ff8fcac2243 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -127,14 +127,23 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) return; } -static int xen_blkif_alloc_rings(struct xen_blkif *blkif) +static int xen_blkif_alloc_rings(struct xen_blkif *blkif, + unsigned int nr_rings) { unsigned int r; + struct xen_blkif_ring *rings; - blkif->rings = kzalloc_objs(struct xen_blkif_ring, blkif->nr_rings); - if (!blkif->rings) + rings = kzalloc_objs(struct xen_blkif_ring, nr_rings); + if (!rings) return -ENOMEM; + write_lock(&blkif->rings_lock); + + blkif->rings = rings; + blkif->nr_rings = nr_rings; + + write_unlock(&blkif->rings_lock); + for (r = 0; r < blkif->nr_rings; r++) { struct xen_blkif_ring *ring = &blkif->rings[r]; @@ -174,6 +183,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) blkif->domid = domid; atomic_set(&blkif->refcnt, 1); init_completion(&blkif->drain_complete); + rwlock_init(&blkif->rings_lock); /* * Because freeing back to the cache may be deferred, it is not @@ -268,6 +278,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif) struct pending_req *req, *n; unsigned int j, r; bool busy = false; + struct xen_blkif_ring *rings; for (r = 0; r < blkif->nr_rings; r++) { struct xen_blkif_ring *ring = &blkif->rings[r]; @@ -334,10 +345,16 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif) * blkif->rings was allocated in connect_ring, so we should free it in * here. */ - kfree(blkif->rings); + write_lock(&blkif->rings_lock); + + rings = blkif->rings; blkif->rings = NULL; blkif->nr_rings = 0; + write_unlock(&blkif->rings_lock); + + kfree(rings); + return 0; } @@ -385,6 +402,7 @@ void xen_blkif_interface_fini(void) unsigned int i; \ unsigned long long result = 0; \ \ + read_lock(&blkif->rings_lock); \ if (!blkif->rings) \ goto out; \ \ @@ -395,6 +413,7 @@ void xen_blkif_interface_fini(void) } \ \ out: \ + read_unlock(&blkif->rings_lock); \ return sprintf(buf, format, result); \ } \ static DEVICE_ATTR(name, 0444, show_##name, NULL) @@ -1102,8 +1121,7 @@ static int connect_ring(struct backend_info *be) requested_num_queues, xenblk_max_queues); return -ENOSYS; } - blkif->nr_rings = requested_num_queues; - if (xen_blkif_alloc_rings(blkif)) + if (xen_blkif_alloc_rings(blkif, requested_num_queues)) return -ENOMEM; pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename, diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index ad0cb42c101972..17d08c66d10822 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -448,8 +448,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) if (end > nr_minors) { unsigned long *bitmap, *old; - bitmap = kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap), - GFP_KERNEL); + bitmap = kzalloc_objs(*bitmap, BITS_TO_LONGS(end)); if (bitmap == NULL) return -ENOMEM; diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 65634a39b0bfcb..96666742523bb7 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -1137,7 +1137,7 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, goto out_fput; } - if (zlo->block_size) { + if (!zlo->block_size) { ret = zloop_get_block_size(zlo, zone); if (ret) goto out_fput; @@ -1161,7 +1161,8 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, if (restore && file_sectors != zlo->zone_size) { pr_err("Invalid conventional zone %u file size (%llu sectors != %llu)\n", - zone_no, file_sectors, zlo->zone_capacity); + zone_no, file_sectors, zlo->zone_size); + ret = -EINVAL; goto out_fput; } @@ -1339,8 +1340,8 @@ static int zloop_ctl_add(struct zloop_options *opts) zlo->disk = blk_mq_alloc_disk(&zlo->tag_set, &lim, zlo); if (IS_ERR(zlo->disk)) { - pr_err("blk_mq_alloc_disk failed (err=%d)\n", ret); ret = PTR_ERR(zlo->disk); + pr_err("blk_mq_alloc_disk failed (err=%d)\n", ret); goto out_cleanup_tags; } zlo->disk->flags = GENHD_FL_NO_PART; diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c index c738ad0408cbab..23790eebacb714 100644 --- a/drivers/bluetooth/bcm203x.c +++ b/drivers/bluetooth/bcm203x.c @@ -161,7 +161,7 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id if (intf->cur_altsetting->desc.bInterfaceNumber != 0) return -ENODEV; - data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&intf->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c index d31d797639b51a..391574c3dd3dd4 100644 --- a/drivers/bluetooth/bfusb.c +++ b/drivers/bluetooth/bfusb.c @@ -649,7 +649,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i } /* Initialize control structure and load firmware */ - data = devm_kzalloc(&intf->dev, sizeof(struct bfusb_data), GFP_KERNEL); + data = devm_kzalloc_obj(&intf->dev, struct bfusb_data); if (!data) return -ENOMEM; diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c index e63d1af250ec91..94bcf0418cea54 100644 --- a/drivers/bluetooth/bpa10x.c +++ b/drivers/bluetooth/bpa10x.c @@ -376,7 +376,7 @@ static int bpa10x_probe(struct usb_interface *intf, if (intf->cur_altsetting->desc.bInterfaceNumber != 0) return -ENODEV; - data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&intf->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 0709fb3212f969..929018428c1924 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -1201,7 +1201,29 @@ static int btintel_download_firmware_payload(struct hci_dev *hdev, err = -EINVAL; while (fw_ptr - fw->data < fw->size) { - struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len); + struct hci_command_hdr *cmd; + size_t remain = fw->size - (fw_ptr - fw->data); + + /* Ensure the header fits before dereferencing */ + if (frag_len + sizeof(*cmd) > remain) { + bt_dev_err(hdev, + "Firmware buffer overrun at header (frag_len %u, need %zu, remain %zu)", + frag_len, frag_len + sizeof(*cmd), remain); + err = -EINVAL; + goto done; + } + + cmd = (void *)(fw_ptr + frag_len); + + /* Ensure the full command (header + payload) fits before use */ + if (frag_len + sizeof(*cmd) + cmd->plen > remain) { + bt_dev_err(hdev, + "Firmware buffer overrun at payload (frag_len %u, plen %u, need %zu, remain %zu)", + frag_len, cmd->plen, + frag_len + sizeof(*cmd) + cmd->plen, remain); + err = -EINVAL; + goto done; + } frag_len += sizeof(*cmd) + cmd->plen; diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c index 91b1ee9d601028..dd439e9b653855 100644 --- a/drivers/bluetooth/btintel_pcie.c +++ b/drivers/bluetooth/btintel_pcie.c @@ -225,8 +225,7 @@ static int btintel_pcie_alloc_dbgc_buf(struct btintel_pcie_data *data, struct data_buf *b; int i; - *buf = devm_kcalloc(&data->pdev->dev, buf_count, - sizeof(**buf), GFP_KERNEL); + *buf = devm_kzalloc_objs(&data->pdev->dev, **buf, buf_count); if (!*buf) { BT_ERR("Failed to allocate dbgc buf: %u", buf_index + 1); return -ENOMEM; @@ -793,7 +792,7 @@ static struct scatterlist *btintel_pcie_alloc_sgtable(ssize_t size) return NULL; nents = DIV_ROUND_UP(size, PAGE_SIZE); - result = kcalloc(nents, sizeof(*result), GFP_KERNEL); + result = kzalloc_objs(*result, nents); if (!result) return NULL; @@ -4061,7 +4060,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev, if (!pdev) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c index b91fc63bc9fe98..4fd241693a10be 100644 --- a/drivers/bluetooth/btmrvl_sdio.c +++ b/drivers/bluetooth/btmrvl_sdio.c @@ -81,8 +81,7 @@ static int btmrvl_sdio_probe_of(struct device *dev, card->plt_of_node = dev->of_node; - card->plt_wake_cfg = devm_kzalloc(dev, sizeof(*card->plt_wake_cfg), - GFP_KERNEL); + card->plt_wake_cfg = devm_kzalloc_obj(dev, *card->plt_wake_cfg); cfg = card->plt_wake_cfg; if (cfg && card->plt_of_node) { cfg->irq_bt = irq_of_parse_and_map(card->plt_of_node, 0); @@ -1517,7 +1516,7 @@ static int btmrvl_sdio_probe(struct sdio_func *func, BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d", id->vendor, id->device, id->class, func->num); - card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&func->dev, *card); if (!card) return -ENOMEM; diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 75483d8230e1dd..b66cb2f5df359f 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,7 @@ #define BTMTK_CBMCU_FLAG_ENABLE_PATCH 0xF1 /* It is for mt79xx iso data transmission setting */ -#define MTK_ISO_THRESHOLD 264 +#define MTK_ISO_THRESHOLD 342 struct btmtk_patch_header { u8 datetime[16]; @@ -1556,8 +1557,15 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count) struct btmtk_data *btmtk_data = hci_get_priv(hdev); struct sk_buff *skb; unsigned long flags; + unsigned int iso_mtu; int err = 0; + /* The controller reports the largest Data_Total_Length it will send in + * LE Read Buffer Size [v2]. Fall back to HCI_MAX_ISO_SIZE while that + * command has not completed yet. + */ + iso_mtu = hdev->iso_mtu ? hdev->iso_mtu : HCI_MAX_ISO_SIZE; + spin_lock_irqsave(&btmtk_data->isorxlock, flags); skb = btmtk_data->isopkt_skb; @@ -1565,7 +1573,16 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count) int len; if (!skb) { - skb = bt_skb_alloc(HCI_MAX_ISO_SIZE, GFP_ATOMIC); + /* Drop the endpoint's zero-filled padding before + * allocating an skb for it; a zero Data_Total_Length + * check below would miss a padding remainder + * shorter than an ISO header. + */ + if (mem_is_zero(buffer, count)) + break; + + skb = bt_skb_alloc(HCI_ISO_HDR_SIZE + iso_mtu, + GFP_ATOMIC); if (!skb) { err = -ENOMEM; break; @@ -1588,7 +1605,24 @@ static int btmtk_recv_isopkt(struct hci_dev *hdev, void *buffer, int count) /* Complete ISO header */ hci_skb_expect(skb) = __le16_to_cpu(dlen); - if (skb_tailroom(skb) < hci_skb_expect(skb)) { + if (!hci_skb_expect(skb)) { + /* Zero padding was ruled out above, so a + * zero Data_Total_Length here is invalid. + */ + kfree_skb(skb); + skb = NULL; + + err = -EILSEQ; + break; + } + + /* Reject a length the controller said it would never + * send. The skb_tailroom() test is kept because a + * fragment started before hdev->iso_mtu was populated + * sits in a smaller skb than iso_mtu now allows. + */ + if (hci_skb_expect(skb) > iso_mtu || + skb_tailroom(skb) < hci_skb_expect(skb)) { kfree_skb(skb); skb = NULL; @@ -1707,13 +1741,15 @@ static int btmtk_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags) static int btmtk_usb_isointf_init(struct hci_dev *hdev) { struct btmtk_data *btmtk_data = hci_get_priv(hdev); - u8 iso_param[2] = { 0x08, 0x01 }; + __le16 iso_param = cpu_to_le16(MTK_ISO_THRESHOLD); struct sk_buff *skb; int err; spin_lock_init(&btmtk_data->isorxlock); - __set_mtk_intr_interface(hdev); + err = __set_mtk_intr_interface(hdev); + if (err < 0) + return err; err = btmtk_submit_intr_urb(hdev, GFP_KERNEL); if (err < 0) { @@ -1722,9 +1758,10 @@ static int btmtk_usb_isointf_init(struct hci_dev *hdev) return err; } - skb = __hci_cmd_sync(hdev, 0xfd98, sizeof(iso_param), iso_param, + skb = __hci_cmd_sync(hdev, 0xfd98, sizeof(iso_param), &iso_param, HCI_INIT_TIMEOUT); if (IS_ERR(skb)) { + usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor); bt_dev_err(hdev, "Failed to apply iso setting (%ld)", PTR_ERR(skb)); return PTR_ERR(skb); } diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index b9563df7298373..f63a05f6c6c65e 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -1418,7 +1418,7 @@ static int btmtksdio_probe(struct sdio_func *func, bool restore_node; int err; - bdev = devm_kzalloc(&func->dev, sizeof(*bdev), GFP_KERNEL); + bdev = devm_kzalloc_obj(&func->dev, *bdev); if (!bdev) return -ENOMEM; diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c index 4af6fbbbd302af..00c43cb6aedc5d 100644 --- a/drivers/bluetooth/btmtkuart.c +++ b/drivers/bluetooth/btmtkuart.c @@ -849,7 +849,7 @@ static int btmtkuart_probe(struct serdev_device *serdev) struct hci_dev *hdev; int err; - bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL); + bdev = devm_kzalloc_obj(&serdev->dev, *bdev); if (!bdev) return -ENOMEM; diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c index 5c730e3361141d..f219bd458619a4 100644 --- a/drivers/bluetooth/btnxpuart.c +++ b/drivers/bluetooth/btnxpuart.c @@ -1847,7 +1847,7 @@ static int nxp_serdev_probe(struct serdev_device *serdev) bdaddr_t ba = {0}; int err; - nxpdev = devm_kzalloc(&serdev->dev, sizeof(*nxpdev), GFP_KERNEL); + nxpdev = devm_kzalloc_obj(&serdev->dev, *nxpdev); if (!nxpdev) return -ENOMEM; diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 22b08ab05b829b..60735b70d89ad8 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -426,7 +426,8 @@ static int qca_tlv_check_data(struct hci_dev *hdev, tlv_nvm->data[0] |= 0x80; /* UART Baud Rate */ - if (soc_type >= QCA_WCN3991) + if (soc_type == QCA_WCN3950 || + soc_type >= QCA_WCN3991) tlv_nvm->data[1] = nvm_baud_rate; else tlv_nvm->data[2] = nvm_baud_rate; @@ -942,6 +943,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, switch (soc_type) { case QCA_QCA2066: case QCA_QCA6390: + case QCA_WCN3950: case QCA_WCN3991: case QCA_WCN6750: case QCA_WCN6855: diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c index d669ea4eb3eb07..5a0cd7f88086fb 100644 --- a/drivers/bluetooth/btqcomsmd.c +++ b/drivers/bluetooth/btqcomsmd.c @@ -144,7 +144,7 @@ static int btqcomsmd_probe(struct platform_device *pdev) void *wcnss; int ret; - btq = devm_kzalloc(&pdev->dev, sizeof(*btq), GFP_KERNEL); + btq = devm_kzalloc_obj(&pdev->dev, *btq); if (!btq) return -ENOMEM; diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c index 8325655ce6aa81..a194fc85abfb86 100644 --- a/drivers/bluetooth/btsdio.c +++ b/drivers/bluetooth/btsdio.c @@ -300,7 +300,7 @@ static int btsdio_probe(struct sdio_func *func, } } - data = devm_kzalloc(&func->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&func->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 92a78a7e603967..95398e2ca098ec 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -1088,6 +1088,8 @@ struct btusb_data { int (*disconnect)(struct hci_dev *hdev); int oob_wake_irq; /* irq for out-of-band wake-on-bt */ + + struct dentry *force_poll_sync_dentry; }; static void btusb_reset(struct hci_dev *hdev) @@ -4820,8 +4822,9 @@ static int btusb_probe(struct usb_interface *intf, usb_set_intfdata(intf, data); - debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data, - &force_poll_sync_fops); + data->force_poll_sync_dentry = + debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, + data, &force_poll_sync_fops); return 0; @@ -4862,6 +4865,9 @@ static void btusb_disconnect(struct usb_interface *intf) if (!data) return; + debugfs_remove(data->force_poll_sync_dentry); + data->force_poll_sync_dentry = NULL; + hdev = data->hdev; usb_set_intfdata(data->intf, NULL); diff --git a/drivers/bluetooth/hci_aml.c b/drivers/bluetooth/hci_aml.c index 067fbf278b44cb..6ee7b653eb74f4 100644 --- a/drivers/bluetooth/hci_aml.c +++ b/drivers/bluetooth/hci_aml.c @@ -696,7 +696,7 @@ static int aml_serdev_probe(struct serdev_device *serdev) struct aml_serdev *amldev; int err; - amldev = devm_kzalloc(&serdev->dev, sizeof(*amldev), GFP_KERNEL); + amldev = devm_kzalloc_obj(&serdev->dev, *amldev); if (!amldev) return -ENOMEM; diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index e70b9f3fd96857..83091e5c570222 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -1240,7 +1240,7 @@ static int bcm_probe(struct platform_device *pdev) struct bcm_device *dev; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; @@ -1509,7 +1509,7 @@ static int bcm_serdev_probe(struct serdev_device *serdev) const struct bcm_device_data *data; int err; - bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL); + bcmdev = devm_kzalloc_obj(&serdev->dev, *bcmdev); if (!bcmdev) return -ENOMEM; diff --git a/drivers/bluetooth/hci_bcm4377.c b/drivers/bluetooth/hci_bcm4377.c index 66d49b4715440a..efd3a6424301b5 100644 --- a/drivers/bluetooth/hci_bcm4377.c +++ b/drivers/bluetooth/hci_bcm4377.c @@ -1558,9 +1558,8 @@ static int bcm4377_alloc_transfer_ring(struct bcm4377_data *bcm4377, return -ENOMEM; if (ring->allow_wait) { - ring->events = devm_kcalloc(&bcm4377->pdev->dev, - ring->n_entries, - sizeof(*ring->events), GFP_KERNEL); + ring->events = devm_kzalloc_objs(&bcm4377->pdev->dev, + *ring->events, ring->n_entries); if (!ring->events) return -ENOMEM; } @@ -2283,7 +2282,7 @@ static int bcm4377_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) return ret; - bcm4377 = devm_kzalloc(&pdev->dev, sizeof(*bcm4377), GFP_KERNEL); + bcm4377 = devm_kzalloc_obj(&pdev->dev, *bcm4377); if (!bcm4377) return -ENOMEM; diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c index 37f4d9327e724d..8ef4dc13a07176 100644 --- a/drivers/bluetooth/hci_h5.c +++ b/drivers/bluetooth/hci_h5.c @@ -857,7 +857,7 @@ static int h5_serdev_probe(struct serdev_device *serdev) struct h5 *h5; const struct h5_device_data *data; - h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL); + h5 = devm_kzalloc_obj(dev, *h5); if (!h5) return -ENOMEM; diff --git a/drivers/bluetooth/hci_intel.c b/drivers/bluetooth/hci_intel.c index d10ce7a0ba3e77..f8c04491c4b347 100644 --- a/drivers/bluetooth/hci_intel.c +++ b/drivers/bluetooth/hci_intel.c @@ -1128,7 +1128,7 @@ static int intel_probe(struct platform_device *pdev) struct intel_device *idev; int ret; - idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc_obj(&pdev->dev, *idev); if (!idev) return -ENOMEM; diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c index 35adf869cc1f28..3c9d98eebc6d9f 100644 --- a/drivers/bluetooth/hci_ll.c +++ b/drivers/bluetooth/hci_ll.c @@ -696,7 +696,7 @@ static int hci_ti_probe(struct serdev_device *serdev) struct nvmem_cell *bdaddr_cell; u32 max_speed = 3000000; - lldev = devm_kzalloc(&serdev->dev, sizeof(struct ll_device), GFP_KERNEL); + lldev = devm_kzalloc_obj(&serdev->dev, struct ll_device); if (!lldev) return -ENOMEM; hu = &lldev->hu; diff --git a/drivers/bluetooth/hci_mrvl.c b/drivers/bluetooth/hci_mrvl.c index 5798a8db016ee0..57e2d80827dffa 100644 --- a/drivers/bluetooth/hci_mrvl.c +++ b/drivers/bluetooth/hci_mrvl.c @@ -463,7 +463,7 @@ static int mrvl_serdev_probe(struct serdev_device *serdev) struct mrvl_serdev *mrvldev; const struct hci_uart_proto *mrvl_proto = device_get_match_data(&serdev->dev); - mrvldev = devm_kzalloc(&serdev->dev, sizeof(*mrvldev), GFP_KERNEL); + mrvldev = devm_kzalloc_obj(&serdev->dev, *mrvldev); if (!mrvldev) return -ENOMEM; diff --git a/drivers/bluetooth/hci_nokia.c b/drivers/bluetooth/hci_nokia.c index be2923231e7128..6de109d8c07be7 100644 --- a/drivers/bluetooth/hci_nokia.c +++ b/drivers/bluetooth/hci_nokia.c @@ -702,7 +702,7 @@ static int nokia_bluetooth_serdev_probe(struct serdev_device *serdev) struct clk *sysclk; int err = 0; - btdev = devm_kzalloc(dev, sizeof(*btdev), GFP_KERNEL); + btdev = devm_kzalloc_obj(dev, *btdev); if (!btdev) return -ENOMEM; diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 7089e9b639b2aa..4cebd0a9998da9 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -161,6 +161,7 @@ struct qca_data { struct delayed_work ctrl_memdump_timeout; struct qca_memdump_info *qca_memdump; unsigned long flags; + struct dentry *debugfs_ibs_dir; struct completion drop_ev_comp; wait_queue_head_t suspend_wait_q; enum qca_memdump_states memdump_state; @@ -665,6 +666,7 @@ static void qca_debugfs_init(struct hci_dev *hdev) return; ibs_dir = debugfs_create_dir("ibs", hdev->debugfs); + qca->debugfs_ibs_dir = ibs_dir; /* read only */ mode = 0444; @@ -744,6 +746,9 @@ static int qca_close(struct hci_uart *hu) hu->priv = NULL; + debugfs_remove_recursive(qca->debugfs_ibs_dir); + qca->debugfs_ibs_dir = NULL; + kfree(qca); return 0; @@ -2372,7 +2377,7 @@ static int qca_init_regulators(struct qca_power *qca, int ret; int i; - bulk = devm_kcalloc(qca->dev, num_vregs, sizeof(*bulk), GFP_KERNEL); + bulk = devm_kzalloc_objs(qca->dev, *bulk, num_vregs); if (!bulk) return -ENOMEM; @@ -2403,7 +2408,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) int err; bool power_ctrl_enabled = true; - qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL); + qcadev = devm_kzalloc_obj(&serdev->dev, *qcadev); if (!qcadev) return -ENOMEM; @@ -2435,9 +2440,8 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: - qcadev->bt_power = devm_kzalloc(&serdev->dev, - sizeof(struct qca_power), - GFP_KERNEL); + qcadev->bt_power = devm_kzalloc_obj(&serdev->dev, + struct qca_power); if (!qcadev->bt_power) return -ENOMEM; break; diff --git a/drivers/bus/brcmstb_gisb.c b/drivers/bus/brcmstb_gisb.c index 91ef99c42344c5..113a09e1032800 100644 --- a/drivers/bus/brcmstb_gisb.c +++ b/drivers/bus/brcmstb_gisb.c @@ -422,7 +422,7 @@ static int __init brcmstb_gisb_arb_probe(struct platform_device *pdev) tea_irq = platform_get_irq(pdev, 1); bp_irq = platform_get_irq(pdev, 2); - gdev = devm_kzalloc(&pdev->dev, sizeof(*gdev), GFP_KERNEL); + gdev = devm_kzalloc_obj(&pdev->dev, *gdev); if (!gdev) return -ENOMEM; diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c index a81188cb06f2d9..675f1e66390c37 100644 --- a/drivers/bus/fsl-mc/dprc-driver.c +++ b/drivers/bus/fsl-mc/dprc-driver.c @@ -266,9 +266,8 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, int i; child_obj_desc_array = - devm_kmalloc_array(&mc_bus_dev->dev, num_child_objects, - sizeof(*child_obj_desc_array), - GFP_KERNEL); + devm_kmalloc_objs(&mc_bus_dev->dev, *child_obj_desc_array, + num_child_objects); if (!child_obj_desc_array) return -ENOMEM; diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c index d2ea59471323af..562461dc747b1f 100644 --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c @@ -60,8 +60,7 @@ static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus res_pool->free_count > res_pool->max_count) goto out_unlock; - resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource), - GFP_KERNEL); + resource = devm_kzalloc_obj(&mc_bus_dev->dev, *resource); if (!resource) { error = -ENOMEM; dev_err(&mc_bus_dev->dev, @@ -375,9 +374,8 @@ int fsl_mc_populate_irq_pool(struct fsl_mc_device *mc_bus_dev, if (error < 0) return error; - irq_resources = devm_kcalloc(&mc_bus_dev->dev, - irq_count, sizeof(*irq_resources), - GFP_KERNEL); + irq_resources = devm_kzalloc_objs(&mc_bus_dev->dev, *irq_resources, + irq_count); if (!irq_resources) { error = -ENOMEM; goto cleanup_msi_irqs; @@ -472,8 +470,7 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev) return -ENOSPC; } - irqs = devm_kcalloc(&mc_dev->dev, irq_count, sizeof(irqs[0]), - GFP_KERNEL); + irqs = devm_kzalloc_objs(&mc_dev->dev, irqs[0], irq_count); if (!irqs) return -ENOMEM; diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 0c37b6780c84d2..a50d197a7858d0 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -981,9 +981,8 @@ static int get_mc_addr_translation_ranges(struct device *dev, return 0; } - *ranges = devm_kcalloc(dev, *num_ranges, - sizeof(struct fsl_mc_addr_translation_range), - GFP_KERNEL); + *ranges = devm_kzalloc_objs(dev, struct fsl_mc_addr_translation_range, + *num_ranges); if (!(*ranges)) return -ENOMEM; @@ -1064,7 +1063,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev) u32 mc_portal_size, mc_stream_id; struct resource *plat_res; - mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(&pdev->dev, *mc); if (!mc) return -ENOMEM; diff --git a/drivers/bus/fsl-mc/mc-io.c b/drivers/bus/fsl-mc/mc-io.c index cd8754763f40a2..ca66bbef460254 100644 --- a/drivers/bus/fsl-mc/mc-io.c +++ b/drivers/bus/fsl-mc/mc-io.c @@ -73,7 +73,7 @@ int __must_check fsl_create_mc_io(struct device *dev, void __iomem *mc_portal_virt_addr; struct resource *res; - mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL); + mc_io = devm_kzalloc_obj(dev, *mc_io); if (!mc_io) return -ENOMEM; diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 53dd1573e3238a..c82e81807d0922 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -422,8 +422,7 @@ static int hisi_lpc_acpi_set_io_res(struct acpi_device *adev, return count ? count : -EIO; } - resources = devm_kcalloc(hostdev, count, sizeof(*resources), - GFP_KERNEL); + resources = devm_kzalloc_objs(hostdev, *resources, count); if (!resources) { dev_warn(hostdev, "could not allocate memory for %d resources\n", count); @@ -611,7 +610,7 @@ static int hisi_lpc_probe(struct platform_device *pdev) resource_size_t io_end; int ret; - lpcdev = devm_kzalloc(dev, sizeof(*lpcdev), GFP_KERNEL); + lpcdev = devm_kzalloc_obj(dev, *lpcdev); if (!lpcdev) return -ENOMEM; @@ -621,7 +620,7 @@ static int hisi_lpc_probe(struct platform_device *pdev) if (IS_ERR(lpcdev->membase)) return PTR_ERR(lpcdev->membase); - range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL); + range = devm_kzalloc_obj(dev, *range); if (!range) return -ENOMEM; diff --git a/drivers/bus/imx-aipstz.c b/drivers/bus/imx-aipstz.c index 83371e5b35a2d8..6de2b0cd641c1f 100644 --- a/drivers/bus/imx-aipstz.c +++ b/drivers/bus/imx-aipstz.c @@ -50,7 +50,7 @@ static int imx_aipstz_probe(struct platform_device *pdev) { struct imx_aipstz_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return dev_err_probe(&pdev->dev, -ENOMEM, "failed to allocate data memory\n"); diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 87070155b05724..477c1633dc165c 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -269,7 +269,7 @@ static int weim_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/bus/intel-ixp4xx-eb.c b/drivers/bus/intel-ixp4xx-eb.c index 320cf307db0548..fdca1c1c59a74b 100644 --- a/drivers/bus/intel-ixp4xx-eb.c +++ b/drivers/bus/intel-ixp4xx-eb.c @@ -351,7 +351,7 @@ static int ixp4xx_exp_probe(struct platform_device *pdev) u32 val; int ret; - eb = devm_kzalloc(dev, sizeof(*eb), GFP_KERNEL); + eb = devm_kzalloc_obj(dev, *eb); if (!eb) return -ENOMEM; diff --git a/drivers/bus/mhi/ep/clients/loopback.c b/drivers/bus/mhi/ep/clients/loopback.c index c7452428d0b794..e45e498b77645e 100644 --- a/drivers/bus/mhi/ep/clients/loopback.c +++ b/drivers/bus/mhi/ep/clients/loopback.c @@ -53,7 +53,7 @@ static void mhi_ep_loopback_ul_callback(struct mhi_ep_device *mhi_dev, if (!buf) return; - mhi_ep_lb_work = kmalloc_obj(*mhi_ep_lb_work, GFP_KERNEL); + mhi_ep_lb_work = kmalloc_obj(*mhi_ep_lb_work); if (!mhi_ep_lb_work) { kfree(buf); return; @@ -78,7 +78,7 @@ static int mhi_ep_loopback_probe(struct mhi_ep_device *mhi_dev, const struct mhi { struct mhi_ep_loopback *mhi_ep_lb; - mhi_ep_lb = devm_kzalloc(&mhi_dev->dev, sizeof(*mhi_ep_lb), GFP_KERNEL); + mhi_ep_lb = devm_kzalloc_obj(&mhi_dev->dev, *mhi_ep_lb); if (!mhi_ep_lb) return -ENOMEM; diff --git a/drivers/bus/mhi/host/clients/loopback.c b/drivers/bus/mhi/host/clients/loopback.c index 35312f02559865..92ebaea31fe805 100644 --- a/drivers/bus/mhi/host/clients/loopback.c +++ b/drivers/bus/mhi/host/clients/loopback.c @@ -261,7 +261,7 @@ static int mhi_loopback_probe(struct mhi_device *mhi_dev, struct mhi_loopback *loopback; int ret; - loopback = devm_kzalloc(&mhi_dev->dev, sizeof(*loopback), GFP_KERNEL); + loopback = devm_kzalloc_obj(&mhi_dev->dev, *loopback); if (!loopback) return -ENOMEM; diff --git a/drivers/bus/mhi/host/pci_generic.c b/drivers/bus/mhi/host/pci_generic.c index 7193a384cca477..ca9ef4aaa0140a 100644 --- a/drivers/bus/mhi/host/pci_generic.c +++ b/drivers/bus/mhi/host/pci_generic.c @@ -1241,7 +1241,7 @@ static int mhi_pci_get_irqs(struct mhi_controller *mhi_cntrl, mhi_cntrl->nr_irqs = 1; } - irq = devm_kcalloc(&pdev->dev, mhi_cntrl->nr_irqs, sizeof(int), GFP_KERNEL); + irq = devm_kzalloc_objs(&pdev->dev, int, mhi_cntrl->nr_irqs); if (!irq) return -ENOMEM; @@ -1392,7 +1392,7 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) dev_info(&pdev->dev, "MHI PCI device found: %s\n", info->name); /* mhi_pdev.mhi_cntrl must be zero-initialized */ - mhi_pdev = devm_kzalloc(&pdev->dev, sizeof(*mhi_pdev), GFP_KERNEL); + mhi_pdev = devm_kzalloc_obj(&pdev->dev, *mhi_pdev); if (!mhi_pdev) return -ENOMEM; diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c index 0d68c1a9f4936b..93f1913c3356ce 100644 --- a/drivers/bus/moxtet.c +++ b/drivers/bus/moxtet.c @@ -773,8 +773,7 @@ static int moxtet_probe(struct spi_device *spi) if (ret < 0) return ret; - moxtet = devm_kzalloc(&spi->dev, sizeof(struct moxtet), - GFP_KERNEL); + moxtet = devm_kzalloc_obj(&spi->dev, struct moxtet); if (!moxtet) return -ENOMEM; diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c index eb1ba6319fdaf3..56794c67d865b2 100644 --- a/drivers/bus/omap_l3_noc.c +++ b/drivers/bus/omap_l3_noc.c @@ -245,7 +245,7 @@ static int omap_l3_probe(struct platform_device *pdev) return -EINVAL; } - l3 = devm_kzalloc(&pdev->dev, sizeof(*l3), GFP_KERNEL); + l3 = devm_kzalloc_obj(&pdev->dev, *l3); if (!l3) return -ENOMEM; diff --git a/drivers/bus/qcom-ssc-block-bus.c b/drivers/bus/qcom-ssc-block-bus.c index 7f5fd4e0940dc1..6e2ea812815e63 100644 --- a/drivers/bus/qcom-ssc-block-bus.c +++ b/drivers/bus/qcom-ssc-block-bus.c @@ -258,7 +258,7 @@ static int qcom_ssc_block_bus_probe(struct platform_device *pdev) struct resource *res; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/bus/simple-pm-bus.c b/drivers/bus/simple-pm-bus.c index c920bd6fbaafd4..535658ba5e4bc4 100644 --- a/drivers/bus/simple-pm-bus.c +++ b/drivers/bus/simple-pm-bus.c @@ -54,7 +54,7 @@ static int simple_pm_bus_probe(struct platform_device *pdev) return -ENODEV; } - bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&pdev->dev, *bus); if (!bus) return -ENOMEM; diff --git a/drivers/bus/stm32_dbg_bus.c b/drivers/bus/stm32_dbg_bus.c index e30ef3465609e7..78a7cb06b287ac 100644 --- a/drivers/bus/stm32_dbg_bus.c +++ b/drivers/bus/stm32_dbg_bus.c @@ -118,7 +118,7 @@ static int stm32_dbg_bus_plat_probe(struct platform_device *pdev) if (!stm32_dbg_bus_priv) return -EPROBE_DEFER; - dbg_controller = devm_kzalloc(&pdev->dev, sizeof(*dbg_controller), GFP_KERNEL); + dbg_controller = devm_kzalloc_obj(&pdev->dev, *dbg_controller); if (!dbg_controller) return dev_err_probe(&pdev->dev, -ENOMEM, "Couldn't allocate debug controller\n"); @@ -192,7 +192,7 @@ static int stm32_dbg_bus_probe(struct tee_client_device *tee_dev) return dev_err_probe(dev, -EBUSY, "A STM32 debug bus device is already initialized\n"); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/bus/stm32_etzpc.c b/drivers/bus/stm32_etzpc.c index 4918a14e507ef8..f5be63c4aaebba 100644 --- a/drivers/bus/stm32_etzpc.c +++ b/drivers/bus/stm32_etzpc.c @@ -78,7 +78,7 @@ static int stm32_etzpc_probe(struct platform_device *pdev) void __iomem *mmio; int rc; - etzpc_controller = devm_kzalloc(&pdev->dev, sizeof(*etzpc_controller), GFP_KERNEL); + etzpc_controller = devm_kzalloc_obj(&pdev->dev, *etzpc_controller); if (!etzpc_controller) return -ENOMEM; diff --git a/drivers/bus/stm32_firewall.c b/drivers/bus/stm32_firewall.c index e3619dba8b0696..b3ff9f9a1cd9a7 100644 --- a/drivers/bus/stm32_firewall.c +++ b/drivers/bus/stm32_firewall.c @@ -201,7 +201,7 @@ int stm32_firewall_get_grant_all_access(struct device *dev, struct stm32_firewal return 0; } - loc_firewall = devm_kcalloc(dev, *nb_firewall, sizeof(*loc_firewall), GFP_KERNEL); + loc_firewall = devm_kzalloc_objs(dev, *loc_firewall, *nb_firewall); if (!loc_firewall) return -ENOMEM; diff --git a/drivers/bus/stm32_rifsc.c b/drivers/bus/stm32_rifsc.c index 19d10379dcefbb..842c8541ed2f35 100644 --- a/drivers/bus/stm32_rifsc.c +++ b/drivers/bus/stm32_rifsc.c @@ -608,7 +608,7 @@ static int stm32_rifsc_register_debugfs(struct stm32_firewall_controller *rifsc_ struct rifsc_dbg_private *rifsc_priv; struct dentry *root = NULL; - rifsc_priv = devm_kzalloc(rifsc_controller->dev, sizeof(*rifsc_priv), GFP_KERNEL); + rifsc_priv = devm_kzalloc_obj(rifsc_controller->dev, *rifsc_priv); if (!rifsc_priv) return -ENOMEM; @@ -736,7 +736,7 @@ static int stm32_rifsc_probe(struct platform_device *pdev) void __iomem *mmio; int rc; - rifsc_controller = devm_kzalloc(&pdev->dev, sizeof(*rifsc_controller), GFP_KERNEL); + rifsc_controller = devm_kzalloc_obj(&pdev->dev, *rifsc_controller); if (!rifsc_controller) return -ENOMEM; diff --git a/drivers/bus/sunxi-rsb.c b/drivers/bus/sunxi-rsb.c index daf0ea563e4773..db59189e3fb439 100644 --- a/drivers/bus/sunxi-rsb.c +++ b/drivers/bus/sunxi-rsb.c @@ -757,7 +757,7 @@ static int sunxi_rsb_probe(struct platform_device *pdev) "clock-frequency (%u Hz) is too high (max = 20MHz)\n", clk_freq); - rsb = devm_kzalloc(dev, sizeof(*rsb), GFP_KERNEL); + rsb = devm_kzalloc_obj(dev, *rsb); if (!rsb) return -ENOMEM; diff --git a/drivers/bus/tegra-aconnect.c b/drivers/bus/tegra-aconnect.c index 9b2b227332b22f..f5e685199f0634 100644 --- a/drivers/bus/tegra-aconnect.c +++ b/drivers/bus/tegra-aconnect.c @@ -26,8 +26,7 @@ static int tegra_aconnect_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -EINVAL; - aconnect = devm_kzalloc(&pdev->dev, sizeof(struct tegra_aconnect), - GFP_KERNEL); + aconnect = devm_kzalloc_obj(&pdev->dev, struct tegra_aconnect); if (!aconnect) return -ENOMEM; diff --git a/drivers/bus/tegra-gmi.c b/drivers/bus/tegra-gmi.c index 9c09141961d87e..50f03dfac74fe8 100644 --- a/drivers/bus/tegra-gmi.c +++ b/drivers/bus/tegra-gmi.c @@ -213,7 +213,7 @@ static int tegra_gmi_probe(struct platform_device *pdev) struct tegra_gmi *gmi; int err; - gmi = devm_kzalloc(dev, sizeof(*gmi), GFP_KERNEL); + gmi = devm_kzalloc_obj(dev, *gmi); if (!gmi) return -ENOMEM; diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c index e118b900c9ac83..12285ad9ef51f5 100644 --- a/drivers/bus/ti-sysc.c +++ b/drivers/bus/ti-sysc.c @@ -442,10 +442,8 @@ static int sysc_get_clocks(struct sysc *ddata) const char *name; int nr_fck = 0, nr_ick = 0, i, error = 0; - ddata->clock_roles = devm_kcalloc(ddata->dev, - SYSC_MAX_CLOCKS, - sizeof(*ddata->clock_roles), - GFP_KERNEL); + ddata->clock_roles = devm_kzalloc_objs(ddata->dev, *ddata->clock_roles, + SYSC_MAX_CLOCKS); if (!ddata->clock_roles) return -ENOMEM; @@ -485,9 +483,8 @@ static int sysc_get_clocks(struct sysc *ddata) if (!nr_ick) ddata->nr_clocks++; - ddata->clocks = devm_kcalloc(ddata->dev, - ddata->nr_clocks, sizeof(*ddata->clocks), - GFP_KERNEL); + ddata->clocks = devm_kzalloc_objs(ddata->dev, *ddata->clocks, + ddata->nr_clocks); if (!ddata->clocks) return -ENOMEM; @@ -2845,7 +2842,7 @@ static int sysc_init_pdata(struct sysc *ddata) if (!pdata) return 0; - mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL); + mdata = devm_kzalloc_obj(ddata->dev, *mdata); if (!mdata) return -ENOMEM; @@ -3151,7 +3148,7 @@ static int sysc_probe(struct platform_device *pdev) struct sysc *ddata; int error; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c index 2328c48b9b1260..f7ce77136bc39b 100644 --- a/drivers/bus/ts-nbus.c +++ b/drivers/bus/ts-nbus.c @@ -272,7 +272,7 @@ static int ts_nbus_probe(struct platform_device *pdev) struct ts_nbus *ts_nbus; int ret; - ts_nbus = devm_kzalloc(dev, sizeof(*ts_nbus), GFP_KERNEL); + ts_nbus = devm_kzalloc_obj(dev, *ts_nbus); if (!ts_nbus) return -ENOMEM; diff --git a/drivers/bus/uniphier-system-bus.c b/drivers/bus/uniphier-system-bus.c index cb5c89ce7b8636..473536614bbef0 100644 --- a/drivers/bus/uniphier-system-bus.c +++ b/drivers/bus/uniphier-system-bus.c @@ -180,7 +180,7 @@ static int uniphier_system_bus_probe(struct platform_device *pdev) struct of_range range; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c index adaf5bd2b36df0..9f57f6581b5406 100644 --- a/drivers/bus/vexpress-config.c +++ b/drivers/bus/vexpress-config.c @@ -355,7 +355,7 @@ static int vexpress_syscfg_probe(struct platform_device *pdev) int master; u32 dt_hbi; - syscfg = devm_kzalloc(&pdev->dev, sizeof(*syscfg), GFP_KERNEL); + syscfg = devm_kzalloc_obj(&pdev->dev, *syscfg); if (!syscfg) return -ENOMEM; syscfg->dev = &pdev->dev; @@ -365,7 +365,7 @@ static int vexpress_syscfg_probe(struct platform_device *pdev) if (IS_ERR(syscfg->base)) return PTR_ERR(syscfg->base); - bridge = devm_kmalloc(&pdev->dev, sizeof(*bridge), GFP_KERNEL); + bridge = devm_kmalloc_obj(&pdev->dev, *bridge); if (!bridge) return -ENOMEM; diff --git a/drivers/char/hw_random/airoha-trng.c b/drivers/char/hw_random/airoha-trng.c index 98c131ee989144..1fdaa26bd924b7 100644 --- a/drivers/char/hw_random/airoha-trng.c +++ b/drivers/char/hw_random/airoha-trng.c @@ -171,7 +171,7 @@ static int airoha_trng_probe(struct platform_device *pdev) int irq, ret; u32 val; - trng = devm_kzalloc(dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/arm_smccc_trng.c b/drivers/char/hw_random/arm_smccc_trng.c index 01c1a30cbab8d7..f25ee2b67ea218 100644 --- a/drivers/char/hw_random/arm_smccc_trng.c +++ b/drivers/char/hw_random/arm_smccc_trng.c @@ -104,7 +104,7 @@ static int smccc_trng_probe(struct arm_smccc_device *sdev) if (!smccc_probe_trng()) return -ENODEV; - trng = devm_kzalloc(&sdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&sdev->dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index fe444196e6b3e2..633a5d8a9b932c 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -112,7 +112,7 @@ static int atmel_trng_probe(struct platform_device *pdev) const struct atmel_trng_data *data; int ret; - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&pdev->dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/ba431-rng.c b/drivers/char/hw_random/ba431-rng.c index 810c8cd5629a94..f70c30bd89ae2e 100644 --- a/drivers/char/hw_random/ba431-rng.c +++ b/drivers/char/hw_random/ba431-rng.c @@ -171,7 +171,7 @@ static int ba431_trng_probe(struct platform_device *pdev) struct ba431_trng *ba431; int ret; - ba431 = devm_kzalloc(&pdev->dev, sizeof(*ba431), GFP_KERNEL); + ba431 = devm_kzalloc_obj(&pdev->dev, *ba431); if (!ba431) return -ENOMEM; diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 6d6ac409efcfaf..aa02d598b50eac 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -146,7 +146,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) struct bcm2835_rng_priv *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/bcm74110-rng.c b/drivers/char/hw_random/bcm74110-rng.c index 4ff9ac45202a2d..fc4df7bf0f1067 100644 --- a/drivers/char/hw_random/bcm74110-rng.c +++ b/drivers/char/hw_random/bcm74110-rng.c @@ -84,7 +84,7 @@ static int bcm74110_rng_probe(struct platform_device *pdev) struct bcm74110_priv *priv; int rc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/cavium-rng-vf.c b/drivers/char/hw_random/cavium-rng-vf.c index c1b8918b229229..14eb74a70f896a 100644 --- a/drivers/char/hw_random/cavium-rng-vf.c +++ b/drivers/char/hw_random/cavium-rng-vf.c @@ -206,7 +206,7 @@ static int cavium_rng_probe_vf(struct pci_dev *pdev, struct cavium_rng *rng; int ret; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/cavium-rng.c b/drivers/char/hw_random/cavium-rng.c index 3e2c042009f66b..ab55c23aa965bb 100644 --- a/drivers/char/hw_random/cavium-rng.c +++ b/drivers/char/hw_random/cavium-rng.c @@ -26,7 +26,7 @@ static int cavium_rng_probe(struct pci_dev *pdev, struct cavium_rng_pf *rng; int iov_err; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/cctrng.c b/drivers/char/hw_random/cctrng.c index 03401ee59a8e86..b869915d7048ae 100644 --- a/drivers/char/hw_random/cctrng.c +++ b/drivers/char/hw_random/cctrng.c @@ -461,7 +461,7 @@ static int cctrng_probe(struct platform_device *pdev) BUILD_BUG_ON(CCTRNG_DATA_BUF_WORDS < 6); BUILD_BUG_ON((CCTRNG_DATA_BUF_WORDS & (CCTRNG_DATA_BUF_WORDS-1)) != 0); - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/char/hw_random/cn10k-rng.c b/drivers/char/hw_random/cn10k-rng.c index 3b4e78182e14a9..097f860b7e289a 100644 --- a/drivers/char/hw_random/cn10k-rng.c +++ b/drivers/char/hw_random/cn10k-rng.c @@ -179,7 +179,7 @@ static int cn10k_rng_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct cn10k_rng *rng; int err; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c index 1fcc7eb121c222..47fa7ffd9604fe 100644 --- a/drivers/char/hw_random/exynos-trng.c +++ b/drivers/char/hw_random/exynos-trng.c @@ -185,7 +185,7 @@ static int exynos_trng_probe(struct platform_device *pdev) struct exynos_trng_dev *trng; int ret = -ENOMEM; - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&pdev->dev, *trng); if (!trng) return ret; diff --git a/drivers/char/hw_random/hisi-rng.c b/drivers/char/hw_random/hisi-rng.c index 4e501d5c121ffc..c1d9ee4ece8230 100644 --- a/drivers/char/hw_random/hisi-rng.c +++ b/drivers/char/hw_random/hisi-rng.c @@ -75,7 +75,7 @@ static int hisi_rng_probe(struct platform_device *pdev) struct hisi_rng *rng; int ret; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/hisi-trng-v2.c b/drivers/char/hw_random/hisi-trng-v2.c index 9e0ecea56ad689..611f41911359d9 100644 --- a/drivers/char/hw_random/hisi-trng-v2.c +++ b/drivers/char/hw_random/hisi-trng-v2.c @@ -58,7 +58,7 @@ static int hisi_trng_probe(struct platform_device *pdev) struct hisi_trng *trng; int ret; - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&pdev->dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/histb-rng.c b/drivers/char/hw_random/histb-rng.c index 445b80beed6220..7be48b010e9784 100644 --- a/drivers/char/hw_random/histb-rng.c +++ b/drivers/char/hw_random/histb-rng.c @@ -122,7 +122,7 @@ static int histb_rng_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 6e2483664f9b99..8dfd7821225c1d 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -250,7 +250,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev) u32 ver_id; u8 rng_type; - rngc = devm_kzalloc(&pdev->dev, sizeof(*rngc), GFP_KERNEL); + rngc = devm_kzalloc_obj(&pdev->dev, *rngc); if (!rngc) return -ENOMEM; diff --git a/drivers/char/hw_random/ingenic-rng.c b/drivers/char/hw_random/ingenic-rng.c index bbfd662d25a67c..79a2b0ffcab7b2 100644 --- a/drivers/char/hw_random/ingenic-rng.c +++ b/drivers/char/hw_random/ingenic-rng.c @@ -85,7 +85,7 @@ static int ingenic_rng_probe(struct platform_device *pdev) struct ingenic_rng *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/ingenic-trng.c b/drivers/char/hw_random/ingenic-trng.c index 0dbe116346fd27..0c51d01034ca51 100644 --- a/drivers/char/hw_random/ingenic-trng.c +++ b/drivers/char/hw_random/ingenic-trng.c @@ -78,7 +78,7 @@ static int ingenic_trng_probe(struct platform_device *pdev) struct clk *clk; int ret; - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&pdev->dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/iproc-rng200.c b/drivers/char/hw_random/iproc-rng200.c index 2e2aafca5cf0c5..0d70723ffe2d51 100644 --- a/drivers/char/hw_random/iproc-rng200.c +++ b/drivers/char/hw_random/iproc-rng200.c @@ -169,7 +169,7 @@ static int iproc_rng200_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/jh7110-trng.c b/drivers/char/hw_random/jh7110-trng.c index 61eb4db7ac0144..bc5328566659d7 100644 --- a/drivers/char/hw_random/jh7110-trng.c +++ b/drivers/char/hw_random/jh7110-trng.c @@ -280,7 +280,7 @@ static int starfive_trng_probe(struct platform_device *pdev) int irq; struct starfive_trng *trng; - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(&pdev->dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/hw_random/ks-sa-rng.c b/drivers/char/hw_random/ks-sa-rng.c index 4494f1e4ab4dbf..030bb759ce9ebf 100644 --- a/drivers/char/hw_random/ks-sa-rng.c +++ b/drivers/char/hw_random/ks-sa-rng.c @@ -208,7 +208,7 @@ static int ks_sa_rng_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - ks_sa_rng = devm_kzalloc(dev, sizeof(*ks_sa_rng), GFP_KERNEL); + ks_sa_rng = devm_kzalloc_obj(dev, *ks_sa_rng); if (!ks_sa_rng) return -ENOMEM; diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c index 75225eb9fef626..f4ee3a00106217 100644 --- a/drivers/char/hw_random/meson-rng.c +++ b/drivers/char/hw_random/meson-rng.c @@ -90,7 +90,7 @@ static int meson_rng_probe(struct platform_device *pdev) struct clk *core_clk; const struct meson_rng_priv *priv; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/char/hw_random/mpfs-rng.c b/drivers/char/hw_random/mpfs-rng.c index 0994024daa7032..8fd8342110af6e 100644 --- a/drivers/char/hw_random/mpfs-rng.c +++ b/drivers/char/hw_random/mpfs-rng.c @@ -67,7 +67,7 @@ static int mpfs_rng_probe(struct platform_device *pdev) struct mpfs_rng *rng_priv; int ret; - rng_priv = devm_kzalloc(dev, sizeof(*rng_priv), GFP_KERNEL); + rng_priv = devm_kzalloc_obj(dev, *rng_priv); if (!rng_priv) return -ENOMEM; diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c index 1f9793010e6c71..127b82d979e8ed 100644 --- a/drivers/char/hw_random/mtk-rng.c +++ b/drivers/char/hw_random/mtk-rng.c @@ -167,7 +167,7 @@ static int mtk_rng_probe(struct platform_device *pdev) int ret; struct mtk_rng *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/mxc-rnga.c b/drivers/char/hw_random/mxc-rnga.c index e3fcb8bcc29bbf..a1e3c30966a811 100644 --- a/drivers/char/hw_random/mxc-rnga.c +++ b/drivers/char/hw_random/mxc-rnga.c @@ -136,7 +136,7 @@ static int mxc_rnga_probe(struct platform_device *pdev) int err; struct mxc_rng *mxc_rng; - mxc_rng = devm_kzalloc(&pdev->dev, sizeof(*mxc_rng), GFP_KERNEL); + mxc_rng = devm_kzalloc_obj(&pdev->dev, *mxc_rng); if (!mxc_rng) return -ENOMEM; diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index ea6d5599242f67..e52c30e9348b3c 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -700,7 +700,7 @@ static int n2rng_probe(struct platform_device *op) struct n2rng *np; n2rng_driver_version(); - np = devm_kzalloc(&op->dev, sizeof(*np), GFP_KERNEL); + np = devm_kzalloc_obj(&op->dev, *np); if (!np) goto out; np->op = op; @@ -745,8 +745,7 @@ static int n2rng_probe(struct platform_device *op) dev_info(&op->dev, "Registered RNG HVAPI major %lu minor %lu\n", np->hvapi_major, np->hvapi_minor); - np->units = devm_kcalloc(&op->dev, np->num_units, sizeof(*np->units), - GFP_KERNEL); + np->units = devm_kzalloc_objs(&op->dev, *np->units, np->num_units); err = -ENOMEM; if (!np->units) goto out_hvapi_unregister; diff --git a/drivers/char/hw_random/npcm-rng.c b/drivers/char/hw_random/npcm-rng.c index 40d6e29dea032d..a85f745963be74 100644 --- a/drivers/char/hw_random/npcm-rng.c +++ b/drivers/char/hw_random/npcm-rng.c @@ -90,7 +90,7 @@ static int npcm_rng_probe(struct platform_device *pdev) struct npcm_rng *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/octeon-rng.c b/drivers/char/hw_random/octeon-rng.c index 412f544050364d..c3dee6b182a886 100644 --- a/drivers/char/hw_random/octeon-rng.c +++ b/drivers/char/hw_random/octeon-rng.c @@ -68,7 +68,7 @@ static int octeon_rng_probe(struct platform_device *pdev) .data_read = octeon_rng_data_read }; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c index 22cde35ebe5dc7..49d7f021fd3177 100644 --- a/drivers/char/hw_random/omap-rng.c +++ b/drivers/char/hw_random/omap-rng.c @@ -423,7 +423,7 @@ static int omap_rng_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(struct omap_rng_dev), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct omap_rng_dev); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c index 0797add0d78256..59024f2090683f 100644 --- a/drivers/char/hw_random/omap3-rom-rng.c +++ b/drivers/char/hw_random/omap3-rom-rng.c @@ -109,7 +109,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev) struct omap_rom_rng *ddata; int ret = 0; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/char/hw_random/pic32-rng.c b/drivers/char/hw_random/pic32-rng.c index 1c764924f2dd22..6d7a7ce810258b 100644 --- a/drivers/char/hw_random/pic32-rng.c +++ b/drivers/char/hw_random/pic32-rng.c @@ -78,7 +78,7 @@ static int pic32_rng_probe(struct platform_device *pdev) struct pic32_rng *priv; struct clk *clk; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/qcom-rng.c b/drivers/char/hw_random/qcom-rng.c index 4d046caafe5bbf..6040f24daff8b2 100644 --- a/drivers/char/hw_random/qcom-rng.c +++ b/drivers/char/hw_random/qcom-rng.c @@ -106,7 +106,7 @@ static int qcom_rng_probe(struct platform_device *pdev) return 0; } - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/rockchip-rng.c b/drivers/char/hw_random/rockchip-rng.c index 6e3ed4b8560514..fc389832c72f57 100644 --- a/drivers/char/hw_random/rockchip-rng.c +++ b/drivers/char/hw_random/rockchip-rng.c @@ -389,7 +389,7 @@ static int rk_rng_probe(struct platform_device *pdev) struct rk_rng *rk_rng; int ret; - rk_rng = devm_kzalloc(dev, sizeof(*rk_rng), GFP_KERNEL); + rk_rng = devm_kzalloc_obj(dev, *rk_rng); if (!rk_rng) return -ENOMEM; diff --git a/drivers/char/hw_random/st-rng.c b/drivers/char/hw_random/st-rng.c index 23749817d83c71..483e77e4a99c35 100644 --- a/drivers/char/hw_random/st-rng.c +++ b/drivers/char/hw_random/st-rng.c @@ -76,7 +76,7 @@ static int st_rng_probe(struct platform_device *pdev) void __iomem *base; int ret; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c index 739263eb56ba88..dec8685aca3221 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -530,7 +530,7 @@ static int stm32_rng_probe(struct platform_device *ofdev) struct stm32_rng_private *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c index e61f0639320906..18b758240a6e2c 100644 --- a/drivers/char/hw_random/timeriomem-rng.c +++ b/drivers/char/hw_random/timeriomem-rng.c @@ -114,8 +114,7 @@ static int timeriomem_rng_probe(struct platform_device *pdev) } /* Allocate memory for the device structure (and zero it) */ - priv = devm_kzalloc(&pdev->dev, - sizeof(struct timeriomem_rng_private), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct timeriomem_rng_private); if (!priv) return -ENOMEM; diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index f9982217247ddb..45d87c0614a5e9 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -190,6 +190,7 @@ static int probe_common(struct virtio_device *vdev) err_find: ida_free(&rng_index_ida, index); err_ida: + vdev->priv = NULL; kfree(vi); return err; } @@ -198,6 +199,11 @@ static void remove_common(struct virtio_device *vdev) { struct virtrng_info *vi = vdev->priv; + if (!vi) { + virtio_reset_device(vdev); + return; + } + vi->hwrng_removed = true; vi->data_avail = 0; vi->data_idx = 0; @@ -207,6 +213,7 @@ static void remove_common(struct virtio_device *vdev) virtio_reset_device(vdev); vdev->config->del_vqs(vdev); ida_free(&rng_index_ida, vi->index); + vdev->priv = NULL; kfree(vi); } diff --git a/drivers/char/hw_random/xgene-rng.c b/drivers/char/hw_random/xgene-rng.c index 5fa6d28c87469a..8baabc573f7240 100644 --- a/drivers/char/hw_random/xgene-rng.c +++ b/drivers/char/hw_random/xgene-rng.c @@ -315,7 +315,7 @@ static int xgene_rng_probe(struct platform_device *pdev) struct clk *clk; int rc = 0; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/char/hw_random/xilinx-trng.c b/drivers/char/hw_random/xilinx-trng.c index 290bf5bc82db8c..e23bdbf4ba8d76 100644 --- a/drivers/char/hw_random/xilinx-trng.c +++ b/drivers/char/hw_random/xilinx-trng.c @@ -291,7 +291,7 @@ static int xtrng_probe(struct platform_device *pdev) struct xilinx_rng *rng; int ret; - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc_obj(&pdev->dev, *rng); if (!rng) return -ENOMEM; diff --git a/drivers/char/hw_random/xiphera-trng.c b/drivers/char/hw_random/xiphera-trng.c index ab5d852ff69fce..923acf79277d19 100644 --- a/drivers/char/hw_random/xiphera-trng.c +++ b/drivers/char/hw_random/xiphera-trng.c @@ -62,7 +62,7 @@ static int xiphera_trng_probe(struct platform_device *pdev) struct xiphera_trng *trng; struct device *dev = &pdev->dev; - trng = devm_kzalloc(dev, sizeof(*trng), GFP_KERNEL); + trng = devm_kzalloc_obj(dev, *trng); if (!trng) return -ENOMEM; diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c index a179d479701171..21869ae224af13 100644 --- a/drivers/char/ipmi/bt-bmc.c +++ b/drivers/char/ipmi/bt-bmc.c @@ -413,7 +413,7 @@ static int bt_bmc_probe(struct platform_device *pdev) dev = &pdev->dev; dev_info(dev, "Found bt bmc device\n"); - bt_bmc = devm_kzalloc(dev, sizeof(*bt_bmc), GFP_KERNEL); + bt_bmc = devm_kzalloc_obj(dev, *bt_bmc); if (!bt_bmc) return -ENOMEM; diff --git a/drivers/char/ipmi/ipmb_dev_int.c b/drivers/char/ipmi/ipmb_dev_int.c index eae31ec92382f9..5edc2be859479c 100644 --- a/drivers/char/ipmi/ipmb_dev_int.c +++ b/drivers/char/ipmi/ipmb_dev_int.c @@ -305,8 +305,7 @@ static int ipmb_probe(struct i2c_client *client) struct ipmb_dev *ipmb_dev; int ret; - ipmb_dev = devm_kzalloc(&client->dev, sizeof(*ipmb_dev), - GFP_KERNEL); + ipmb_dev = devm_kzalloc_obj(&client->dev, *ipmb_dev); if (!ipmb_dev) return -ENOMEM; diff --git a/drivers/char/ipmi/ipmi_ipmb.c b/drivers/char/ipmi/ipmi_ipmb.c index 1f1e5718f082e1..3685a7d23b3989 100644 --- a/drivers/char/ipmi/ipmi_ipmb.c +++ b/drivers/char/ipmi/ipmi_ipmb.c @@ -458,7 +458,7 @@ static int ipmi_ipmb_probe(struct i2c_client *client) struct i2c_client *slave = NULL; int rv; - iidev = devm_kzalloc(&client->dev, sizeof(*iidev), GFP_KERNEL); + iidev = devm_kzalloc_obj(&client->dev, *iidev); if (!iidev) return -ENOMEM; diff --git a/drivers/char/ipmi/ipmi_powernv.c b/drivers/char/ipmi/ipmi_powernv.c index 52a1130defe537..b184a792561d10 100644 --- a/drivers/char/ipmi/ipmi_powernv.c +++ b/drivers/char/ipmi/ipmi_powernv.c @@ -221,7 +221,7 @@ static int ipmi_powernv_probe(struct platform_device *pdev) dev = &pdev->dev; - ipmi = devm_kzalloc(dev, sizeof(*ipmi), GFP_KERNEL); + ipmi = devm_kzalloc_obj(dev, *ipmi); if (!ipmi) return -ENOMEM; diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 2361103c5edc6b..3a11fc4f352473 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -2033,8 +2033,7 @@ static unsigned short *ssif_address_list(void) list_for_each_entry(info, &ssif_infos, link) count++; - address_list = kcalloc(count + 1, sizeof(*address_list), - GFP_KERNEL); + address_list = kzalloc_objs(*address_list, count + 1); if (!address_list) return NULL; diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c b/drivers/char/ipmi/kcs_bmc_aspeed.c index a13a3470c17a4b..c99e6ac64b1ed0 100644 --- a/drivers/char/ipmi/kcs_bmc_aspeed.c +++ b/drivers/char/ipmi/kcs_bmc_aspeed.c @@ -586,7 +586,7 @@ static int aspeed_kcs_probe(struct platform_device *pdev) have_upstream_irq = !rc; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c b/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c index cf670e891966d0..b303d5929e8809 100644 --- a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c +++ b/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c @@ -474,7 +474,7 @@ static int kcs_bmc_ipmi_add_device(struct kcs_bmc_device *kcs_bmc) struct kcs_bmc_ipmi *priv; int rc; - priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(kcs_bmc->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c b/drivers/char/ipmi/kcs_bmc_npcm7xx.c index 4808a61bf273d3..75c2efd91ca86e 100644 --- a/drivers/char/ipmi/kcs_bmc_npcm7xx.c +++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c @@ -177,7 +177,7 @@ static int npcm7xx_kcs_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/ipmi/kcs_bmc_serio.c b/drivers/char/ipmi/kcs_bmc_serio.c index 1a95d6f258eab7..31b55e567b01bd 100644 --- a/drivers/char/ipmi/kcs_bmc_serio.c +++ b/drivers/char/ipmi/kcs_bmc_serio.c @@ -72,7 +72,7 @@ static int kcs_bmc_serio_add_device(struct kcs_bmc_device *kcs_bmc) struct kcs_bmc_serio *priv; struct serio *port; - priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(kcs_bmc->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/ipmi/ssif_bmc.c b/drivers/char/ipmi/ssif_bmc.c index 6036897725f3b0..545c9cb78ed151 100644 --- a/drivers/char/ipmi/ssif_bmc.c +++ b/drivers/char/ipmi/ssif_bmc.c @@ -825,7 +825,7 @@ static int ssif_bmc_probe(struct i2c_client *client) struct ssif_bmc_ctx *ssif_bmc; int ret; - ssif_bmc = devm_kzalloc(&client->dev, sizeof(*ssif_bmc), GFP_KERNEL); + ssif_bmc = devm_kzalloc_obj(&client->dev, *ssif_bmc); if (!ssif_bmc) return -ENOMEM; diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c index cf02ec646f46f0..50770cafa8359c 100644 --- a/drivers/char/tpm/eventlog/acpi.c +++ b/drivers/char/tpm/eventlog/acpi.c @@ -167,10 +167,8 @@ int tpm_read_log_acpi(struct tpm_chip *chip) } ret = devm_add_action(&chip->dev, tpm_bios_log_free, log->bios_event_log); - if (ret) { - log->bios_event_log = NULL; + if (ret) goto err; - } return format; diff --git a/drivers/char/tpm/eventlog/tpm1.c b/drivers/char/tpm/eventlog/tpm1.c index 0397e3361020a7..f93a358a706e58 100644 --- a/drivers/char/tpm/eventlog/tpm1.c +++ b/drivers/char/tpm/eventlog/tpm1.c @@ -178,6 +178,10 @@ static int get_event_name(char *dest, struct tcpa_event *event, } break; case EVENT_TAG: + if (do_endian_conversion(event->event_size) < + sizeof(pc_event->event_id)) + break; + pc_event = (struct tcpa_pc_event *)event_entry; /* ToDo Row data -> Base64 */ @@ -203,6 +207,9 @@ static int get_event_name(char *dest, struct tcpa_event *event, name = tcpa_pc_event_id_strings[do_endian_conversion (pc_event->event_id)]; n_len = strlen(name); + if (do_endian_conversion(event->event_size) < + sizeof(struct tcpa_pc_event) + 20) + break; for (i = 0; i < 20; i++) d_len += sprintf(&data[2*i], "%02x", pc_event->event_data[i]); diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c index 81348487c1258b..a345a32a972602 100644 --- a/drivers/char/tpm/st33zp24/i2c.c +++ b/drivers/char/tpm/st33zp24/i2c.c @@ -110,8 +110,7 @@ static int st33zp24_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct st33zp24_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct st33zp24_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c index 5149231f3de28b..fbdaff8245b850 100644 --- a/drivers/char/tpm/st33zp24/spi.c +++ b/drivers/char/tpm/st33zp24/spi.c @@ -223,8 +223,7 @@ static int st33zp24_spi_probe(struct spi_device *dev) { struct st33zp24_spi_phy *phy; - phy = devm_kzalloc(&dev->dev, sizeof(struct st33zp24_spi_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&dev->dev, struct st33zp24_spi_phy); if (!phy) return -ENOMEM; diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c index c15a9b7aaff878..91d1278fe95afd 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -459,8 +459,7 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops, if (IS_ERR(chip)) return PTR_ERR(chip); - tpm_dev = devm_kzalloc(dev, sizeof(struct st33zp24_dev), - GFP_KERNEL); + tpm_dev = devm_kzalloc_obj(dev, struct st33zp24_dev); if (!tpm_dev) return -ENOMEM; diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index 6569212dc6b87c..ee91f456f975f9 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -132,6 +132,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, { struct file_priv *priv = file->private_data; ssize_t ret_size = 0; + bool flush = false; int rc; if (!size) @@ -164,9 +165,18 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, if (!priv->response_length) { *off = 0; timer_delete_sync(&priv->user_read_timer); - flush_work(&priv->timeout_work); + flush = true; } mutex_unlock(&priv->buffer_mutex); + + /* + * tpm_timeout_work() takes buffer_mutex, so flush it after dropping + * the mutex to avoid a deadlock; the timer is deleted above, so no new + * timeout work can be queued once the mutex is released. + */ + if (flush) + flush_work(&priv->timeout_work); + return ret_size; } diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c index ca1e2bf424e140..2aaaad69760dc6 100644 --- a/drivers/char/tpm/tpm2-sessions.c +++ b/drivers/char/tpm/tpm2-sessions.c @@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, } crypto_ecdh_encode_key(encoded_key, buf_len, &p); /* this generates a random private key */ - crypto_kpp_set_secret(kpp, encoded_key, buf_len); + rc = crypto_kpp_set_secret(kpp, encoded_key, buf_len); + if (rc) + goto err_free_kpp; /* salt is now the public point of this private key */ req = kpp_request_alloc(kpp, GFP_KERNEL); diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c index 2c3f6bdd787392..6f6aaa3d5f2bb0 100644 --- a/drivers/char/tpm/tpm_atmel.c +++ b/drivers/char/tpm/tpm_atmel.c @@ -242,7 +242,7 @@ static int __init init_atmel(void) goto err_rel_reg; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { rc = -ENOMEM; goto err_unreg_dev; diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index ceb4100ba400f4..46cd753c0cab37 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -815,7 +815,7 @@ static int crb_acpi_probe(struct platform_device *pdev) goto out; } - priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct crb_priv); if (!priv) { rc = -ENOMEM; goto out; diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c index b824904396333e..340b4884835c00 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -176,8 +176,7 @@ static int ftpm_tee_probe_generic(struct device *dev) struct ftpm_tee_private *pvt_data = NULL; struct tee_ioctl_open_session_arg sess_arg; - pvt_data = devm_kzalloc(dev, sizeof(struct ftpm_tee_private), - GFP_KERNEL); + pvt_data = devm_kzalloc_obj(dev, struct ftpm_tee_private); if (!pvt_data) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_atmel.c index dcb91d0497d0f5..ab058bfc9c99a1 100644 --- a/drivers/char/tpm/tpm_i2c_atmel.c +++ b/drivers/char/tpm/tpm_i2c_atmel.c @@ -170,7 +170,7 @@ static int i2c_atmel_probe(struct i2c_client *client) if (IS_ERR(chip)) return PTR_ERR(chip); - priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct priv_data); if (!priv) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c index 3876613809135b..b01e42ad121e43 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -545,7 +545,7 @@ static int i2c_nuvoton_probe(struct i2c_client *client) if (IS_ERR(chip)) return PTR_ERR(chip); - priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct priv_data); if (!priv) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 80536785278a1e..523672385ac648 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -331,7 +331,7 @@ static int __init init_nsc(void) if ((rc = platform_device_add(pdev)) < 0) goto err_put_dev; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { rc = -ENOMEM; goto err_del_dev; diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index b74d60f687d5b9..4d1ffb741542b9 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -61,7 +61,7 @@ static int __init tpm_svsm_probe(struct platform_device *pdev) struct tpm_chip *chip; int err; - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 737d0fe4bb61d2..6f8344894ea583 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -228,7 +228,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info) if (rc) return rc; - phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, struct tpm_tis_tcg_phy); if (phy == NULL) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c index cde0b093ed58ed..8adc7dfd3d7fda 100644 --- a/drivers/char/tpm/tpm_tis_i2c.c +++ b/drivers/char/tpm/tpm_tis_i2c.c @@ -336,8 +336,7 @@ static int tpm_tis_i2c_probe(struct i2c_client *dev) const u8 locality = 0; int ret; - phy = devm_kzalloc(&dev->dev, sizeof(struct tpm_tis_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&dev->dev, struct tpm_tis_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c index 6c0ea5ca2b923f..0acfc36eff161d 100644 --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c @@ -729,7 +729,7 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client) if (IS_ERR(chip)) return PTR_ERR(chip); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis_spi_cr50.c b/drivers/char/tpm/tpm_tis_spi_cr50.c index 32920b4cecfb44..5e62ea1778d7bb 100644 --- a/drivers/char/tpm/tpm_tis_spi_cr50.c +++ b/drivers/char/tpm/tpm_tis_spi_cr50.c @@ -270,7 +270,7 @@ int cr50_spi_probe(struct spi_device *spi) int ret; struct tpm_chip *chip; - cr50_phy = devm_kzalloc(&spi->dev, sizeof(*cr50_phy), GFP_KERNEL); + cr50_phy = devm_kzalloc_obj(&spi->dev, *cr50_phy); if (!cr50_phy) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index 727f1c78d6ddae..77b84cf9e9c9aa 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -267,8 +267,7 @@ static int tpm_tis_spi_probe(struct spi_device *dev) struct tpm_tis_spi_phy *phy; int irq; - phy = devm_kzalloc(&dev->dev, sizeof(struct tpm_tis_spi_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&dev->dev, struct tpm_tis_spi_phy); if (!phy) return -ENOMEM; diff --git a/drivers/char/tpm/tpm_tis_synquacer.c b/drivers/char/tpm/tpm_tis_synquacer.c index eac39730a85646..81b648224d67dc 100644 --- a/drivers/char/tpm/tpm_tis_synquacer.c +++ b/drivers/char/tpm/tpm_tis_synquacer.c @@ -95,7 +95,7 @@ static int tpm_tis_synquacer_init(struct device *dev, { struct tpm_tis_synquacer_phy *phy; - phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, struct tpm_tis_synquacer_phy); if (phy == NULL) return -ENOMEM; diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 019bcae81af5cb..b1b1aaf43e07ef 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -891,45 +891,34 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, { struct sg_list *sgl = sd->u.data; unsigned int offset, len; + struct page *page; + char *src; if (sgl->n == sgl->size) return 0; - /* Try lock this page */ - if (pipe_buf_try_steal(pipe, buf)) { - /* Get reference and unlock page for moving */ - get_page(buf->page); - unlock_page(buf->page); - - len = min(buf->len, sd->len); - sg_set_page(&(sgl->sg[sgl->n]), buf->page, len, buf->offset); - } else { - /* Failback to copying a page */ - struct page *page = alloc_page(GFP_KERNEL); - char *src; - - if (!page) - return -ENOMEM; + page = alloc_page(GFP_KERNEL); + if (!page) + return -ENOMEM; - offset = sd->pos & ~PAGE_MASK; + offset = sd->pos & ~PAGE_MASK; - len = sd->len; - if (len + offset > PAGE_SIZE) - len = PAGE_SIZE - offset; + len = sd->len; + if (len + offset > PAGE_SIZE) + len = PAGE_SIZE - offset; - src = kmap_local_page(buf->page); - memcpy(page_address(page) + offset, src + buf->offset, len); - kunmap_local(src); + src = kmap_local_page(buf->page); + memcpy(page_address(page) + offset, src + buf->offset, len); + kunmap_local(src); - sg_set_page(&(sgl->sg[sgl->n]), page, len, offset); - } + sg_set_page(&sgl->sg[sgl->n], page, len, offset); sgl->n++; sgl->len += len; return len; } -/* Faster zero-copy write by splicing */ +/* Write by splicing, copying the data from the pipe */ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe, struct file *filp, loff_t *ppos, size_t len, unsigned int flags) diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c index bbeb9b6060dca0..36b309c1783854 100644 --- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c +++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c @@ -631,7 +631,7 @@ static int hwicap_setup(struct platform_device *pdev, int id, devt = MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR + id); - drvdata = devm_kzalloc(dev, sizeof(struct hwicap_drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct hwicap_drvdata); if (!drvdata) { retval = -ENOMEM; goto failed; diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c index 7189c6d97e7dd4..9cae835c439935 100644 --- a/drivers/char/xillybus/xillybus_core.c +++ b/drivers/char/xillybus/xillybus_core.c @@ -383,9 +383,8 @@ static int xilly_get_dma_buffers(struct xilly_endpoint *ep, } if (buffers) { /* Not the message buffer */ - this_buffer = devm_kcalloc(dev, bufnum, - sizeof(struct xilly_buffer), - GFP_KERNEL); + this_buffer = devm_kzalloc_objs(dev, struct xilly_buffer, + bufnum); if (!this_buffer) return -ENOMEM; } @@ -485,14 +484,12 @@ static int xilly_setupchannels(struct xilly_endpoint *ep, .regdirection = 0x80000000, }; - channel = devm_kcalloc(dev, ep->num_channels, - sizeof(struct xilly_channel), GFP_KERNEL); + channel = devm_kzalloc_objs(dev, struct xilly_channel, ep->num_channels); if (!channel) return -ENOMEM; - ep->channels = devm_kcalloc(dev, ep->num_channels + 1, - sizeof(struct xilly_channel *), - GFP_KERNEL); + ep->channels = devm_kzalloc_objs(dev, struct xilly_channel *, + ep->num_channels + 1); if (!ep->channels) return -ENOMEM; @@ -565,9 +562,8 @@ static int xilly_setupchannels(struct xilly_endpoint *ep, bytebufsize = bufsize << channel->log2_element_size; - buffers = devm_kcalloc(dev, bufnum, - sizeof(struct xilly_buffer *), - GFP_KERNEL); + buffers = devm_kzalloc_objs(dev, struct xilly_buffer *, + bufnum); if (!buffers) return -ENOMEM; } else { @@ -1857,7 +1853,7 @@ struct xilly_endpoint *xillybus_init_endpoint(struct device *dev) { struct xilly_endpoint *endpoint; - endpoint = devm_kzalloc(dev, sizeof(*endpoint), GFP_KERNEL); + endpoint = devm_kzalloc_obj(dev, *endpoint); if (!endpoint) return NULL; diff --git a/drivers/clk/actions/owl-s500.c b/drivers/clk/actions/owl-s500.c index c69a7e2f06457d..00437234670e1e 100644 --- a/drivers/clk/actions/owl-s500.c +++ b/drivers/clk/actions/owl-s500.c @@ -605,7 +605,7 @@ static int s500_clk_probe(struct platform_device *pdev) desc = &s500_clk_desc; owl_clk_regmap_init(pdev, desc); - reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(&pdev->dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/clk/actions/owl-s700.c b/drivers/clk/actions/owl-s700.c index 3e48105602aa06..134c1c2820ce98 100644 --- a/drivers/clk/actions/owl-s700.c +++ b/drivers/clk/actions/owl-s700.c @@ -623,7 +623,7 @@ static int s700_clk_probe(struct platform_device *pdev) * FIXME: Reset controller registration should be moved to * common code, once all SoCs of Owl family supports it. */ - reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(&pdev->dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/clk/actions/owl-s900.c b/drivers/clk/actions/owl-s900.c index 7dc6e07fb60ea7..feb12d363964c8 100644 --- a/drivers/clk/actions/owl-s900.c +++ b/drivers/clk/actions/owl-s900.c @@ -766,7 +766,7 @@ static int s900_clk_probe(struct platform_device *pdev) * FIXME: Reset controller registration should be moved to * common code, once all SoCs of Owl family supports it. */ - reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(&pdev->dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/clk/anlogic/cru_dr1.c b/drivers/clk/anlogic/cru_dr1.c index 10f8751a88383d..478a52d5fa36ca 100644 --- a/drivers/clk/anlogic/cru_dr1.c +++ b/drivers/clk/anlogic/cru_dr1.c @@ -183,7 +183,7 @@ int dr1_cru_clk_register(struct device *dev, void __iomem *base, struct clk_hw_onecell_data *priv; int i, ret; - priv = devm_kzalloc(dev, struct_size(priv, hws, nr_clks), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, hws, nr_clks); if (!priv) return -ENOMEM; diff --git a/drivers/clk/aspeed/clk-aspeed.c b/drivers/clk/aspeed/clk-aspeed.c index d32a3e9f300a2d..fe9058edd9e8c5 100644 --- a/drivers/clk/aspeed/clk-aspeed.c +++ b/drivers/clk/aspeed/clk-aspeed.c @@ -397,7 +397,7 @@ static int aspeed_clk_probe(struct platform_device *pdev) return PTR_ERR(map); } - ar = devm_kzalloc(dev, sizeof(*ar), GFP_KERNEL); + ar = devm_kzalloc_obj(dev, *ar); if (!ar) return -ENOMEM; diff --git a/drivers/clk/aspeed/clk-ast2600.c b/drivers/clk/aspeed/clk-ast2600.c index cc3d26602b16eb..5ae7b775812f5f 100644 --- a/drivers/clk/aspeed/clk-ast2600.c +++ b/drivers/clk/aspeed/clk-ast2600.c @@ -492,7 +492,7 @@ static int aspeed_g6_clk_probe(struct platform_device *pdev) return PTR_ERR(map); } - ar = devm_kzalloc(dev, sizeof(*ar), GFP_KERNEL); + ar = devm_kzalloc_obj(dev, *ar); if (!ar) return -ENOMEM; diff --git a/drivers/clk/aspeed/clk-ast2700.c b/drivers/clk/aspeed/clk-ast2700.c index 495b7fa3395b21..62f490d9e188f2 100644 --- a/drivers/clk/aspeed/clk-ast2700.c +++ b/drivers/clk/aspeed/clk-ast2700.c @@ -890,7 +890,7 @@ static int ast2700_soc_clk_probe(struct platform_device *pdev) int ret; int i; - clk_ctrl = devm_kzalloc(dev, sizeof(*clk_ctrl), GFP_KERNEL); + clk_ctrl = devm_kzalloc_obj(dev, *clk_ctrl); if (!clk_ctrl) return -ENOMEM; clk_ctrl->dev = dev; @@ -911,8 +911,8 @@ static int ast2700_soc_clk_probe(struct platform_device *pdev) clk_ctrl->clk_data = clk_data; reset_name = devm_kasprintf(dev, GFP_KERNEL, "reset%d", clk_data->scu); - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, clk_data->nr_clks), - GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, + clk_data->nr_clks); if (!clk_hw_data) return -ENOMEM; diff --git a/drivers/clk/at91/dt-compat.c b/drivers/clk/at91/dt-compat.c index dad26dd5e71df9..b6e066de5f1297 100644 --- a/drivers/clk/at91/dt-compat.c +++ b/drivers/clk/at91/dt-compat.c @@ -584,7 +584,7 @@ of_at91_clk_pll_get_characteristics(struct device_node *np) } if (num_cells > 3) { - icpll = kcalloc(num_output, sizeof(*icpll), GFP_KERNEL); + icpll = kzalloc_objs(*icpll, num_output); if (!icpll) goto out_free_output; } diff --git a/drivers/clk/at91/sam9x7.c b/drivers/clk/at91/sam9x7.c index 8b52da194849f5..946aa54dd2e86f 100644 --- a/drivers/clk/at91/sam9x7.c +++ b/drivers/clk/at91/sam9x7.c @@ -907,8 +907,7 @@ static void __init sam9x7_pmc_setup(struct device_node *np) u8 num_parents = 4 + sam9x7_gck[i].pp_count; u32 *mux_table; - mux_table = kmalloc_array(num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = kmalloc_objs(*mux_table, num_parents); if (!mux_table) goto err_free; diff --git a/drivers/clk/at91/sama7d65.c b/drivers/clk/at91/sama7d65.c index ba8ff413fa2c66..306667877e751a 100644 --- a/drivers/clk/at91/sama7d65.c +++ b/drivers/clk/at91/sama7d65.c @@ -1227,8 +1227,7 @@ static void __init sama7d65_pmc_setup(struct device_node *np) struct clk_hw *tmp_parent_hws[8]; u32 *mux_table; - mux_table = kmalloc_array(num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = kmalloc_objs(*mux_table, num_parents); if (!mux_table) goto err_free; @@ -1328,8 +1327,7 @@ static void __init sama7d65_pmc_setup(struct device_node *np) struct clk_hw *tmp_parent_hws[8]; u32 *mux_table; - mux_table = kmalloc_array(num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = kmalloc_objs(*mux_table, num_parents); if (!mux_table) goto err_free; diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c index 1340c2b006192e..b0b2b11ca1fd3c 100644 --- a/drivers/clk/at91/sama7g5.c +++ b/drivers/clk/at91/sama7g5.c @@ -1102,8 +1102,7 @@ static void __init sama7g5_pmc_setup(struct device_node *np) struct clk_hw *tmp_parent_hws[8]; u32 *mux_table; - mux_table = kmalloc_array(num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = kmalloc_objs(*mux_table, num_parents); if (!mux_table) goto err_free; @@ -1198,8 +1197,7 @@ static void __init sama7g5_pmc_setup(struct device_node *np) struct clk_hw *tmp_parent_hws[8]; u32 *mux_table; - mux_table = kmalloc_array(num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = kmalloc_objs(*mux_table, num_parents); if (!mux_table) goto err_free; diff --git a/drivers/clk/axs10x/i2s_pll_clock.c b/drivers/clk/axs10x/i2s_pll_clock.c index 6f3e1151b354e0..5247bb5620dd79 100644 --- a/drivers/clk/axs10x/i2s_pll_clock.c +++ b/drivers/clk/axs10x/i2s_pll_clock.c @@ -170,7 +170,7 @@ static int i2s_pll_clk_probe(struct platform_device *pdev) struct i2s_pll_clk *pll_clk; struct clk_init_data init; - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return -ENOMEM; diff --git a/drivers/clk/axs10x/pll_clock.c b/drivers/clk/axs10x/pll_clock.c index 5ab1c220c62d2a..6102fa64fd7bec 100644 --- a/drivers/clk/axs10x/pll_clock.c +++ b/drivers/clk/axs10x/pll_clock.c @@ -222,7 +222,7 @@ static int axs10x_pll_clk_probe(struct platform_device *pdev) struct clk_init_data init = { }; int ret; - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return -ENOMEM; diff --git a/drivers/clk/bcm/clk-bcm2711-dvp.c b/drivers/clk/bcm/clk-bcm2711-dvp.c index e79720e85685bf..301a2d13b8fa7e 100644 --- a/drivers/clk/bcm/clk-bcm2711-dvp.c +++ b/drivers/clk/bcm/clk-bcm2711-dvp.c @@ -29,14 +29,12 @@ static int clk_dvp_probe(struct platform_device *pdev) void __iomem *base; int ret; - dvp = devm_kzalloc(&pdev->dev, sizeof(*dvp), GFP_KERNEL); + dvp = devm_kzalloc_obj(&pdev->dev, *dvp); if (!dvp) return -ENOMEM; platform_set_drvdata(pdev, dvp); - dvp->data = devm_kzalloc(&pdev->dev, - struct_size(dvp->data, hws, NR_CLOCKS), - GFP_KERNEL); + dvp->data = devm_kzalloc_flex(&pdev->dev, *dvp->data, hws, NR_CLOCKS); if (!dvp->data) return -ENOMEM; data = dvp->data; diff --git a/drivers/clk/bcm/clk-bcm2835-aux.c b/drivers/clk/bcm/clk-bcm2835-aux.c index 0fafa5cba4427d..351a63e5cdfc6e 100644 --- a/drivers/clk/bcm/clk-bcm2835-aux.c +++ b/drivers/clk/bcm/clk-bcm2835-aux.c @@ -30,10 +30,7 @@ static int bcm2835_aux_clk_probe(struct platform_device *pdev) if (IS_ERR(reg)) return PTR_ERR(reg); - onecell = devm_kmalloc(dev, - struct_size(onecell, hws, - BCM2835_AUX_CLOCK_COUNT), - GFP_KERNEL); + onecell = devm_kmalloc_flex(dev, *onecell, hws, BCM2835_AUX_CLOCK_COUNT); if (!onecell) return -ENOMEM; onecell->num = BCM2835_AUX_CLOCK_COUNT; diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 118df86d717c62..b668c406512a25 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -403,7 +403,7 @@ static void bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base, { struct debugfs_regset32 *regset; - regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(cprman->dev, *regset); if (!regset) return; @@ -760,7 +760,7 @@ static void bcm2835_pll_debug_init(struct clk_hw *hw, const struct bcm2835_pll_data *data = pll->data; struct debugfs_reg32 *regs; - regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL); + regs = devm_kzalloc_objs(cprman->dev, *regs, 7); if (!regs) return; @@ -890,7 +890,7 @@ static void bcm2835_pll_divider_debug_init(struct clk_hw *hw, const struct bcm2835_pll_divider_data *data = divider->data; struct debugfs_reg32 *regs; - regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL); + regs = devm_kzalloc_objs(cprman->dev, *regs, 7); if (!regs) return; @@ -1400,7 +1400,7 @@ bcm2835_register_pll_divider(struct bcm2835_cprman *cprman, init.ops = &bcm2835_pll_divider_clk_ops; init.flags = divider_data->flags | CLK_IGNORE_UNUSED; - divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL); + divider = devm_kzalloc_obj(cprman->dev, *divider); if (!divider) return NULL; @@ -1485,7 +1485,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman, init.flags &= ~CLK_IS_CRITICAL; } - clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL); + clock = devm_kzalloc_obj(cprman->dev, *clock); if (!clock) return NULL; @@ -2279,9 +2279,7 @@ static int bcm2835_clk_probe(struct platform_device *pdev) if (!pdata) return -ENODEV; - cprman = devm_kzalloc(dev, - struct_size(cprman, onecell.hws, asize), - GFP_KERNEL); + cprman = devm_kzalloc_flex(dev, *cprman, onecell.hws, asize); if (!cprman) return -ENOMEM; diff --git a/drivers/clk/bcm/clk-bcm63268-timer.c b/drivers/clk/bcm/clk-bcm63268-timer.c index 463710d272a1d1..d74ec2f506be4d 100644 --- a/drivers/clk/bcm/clk-bcm63268-timer.c +++ b/drivers/clk/bcm/clk-bcm63268-timer.c @@ -158,8 +158,7 @@ static int bcm63268_tclk_probe(struct platform_device *pdev) maxbit = max(maxbit, entry->bit); maxbit++; - hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit), - GFP_KERNEL); + hw = devm_kzalloc_flex(&pdev->dev, *hw, data.hws, maxbit); if (!hw) return -ENOMEM; diff --git a/drivers/clk/bcm/clk-bcm63xx-gate.c b/drivers/clk/bcm/clk-bcm63xx-gate.c index d6d857474436e8..de86975bc7b37e 100644 --- a/drivers/clk/bcm/clk-bcm63xx-gate.c +++ b/drivers/clk/bcm/clk-bcm63xx-gate.c @@ -496,8 +496,7 @@ static int clk_bcm63xx_probe(struct platform_device *pdev) maxbit = max_t(u8, maxbit, entry->bit); maxbit++; - hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit), - GFP_KERNEL); + hw = devm_kzalloc_flex(&pdev->dev, *hw, data.hws, maxbit); if (!hw) return -ENOMEM; diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c index 338558f6fbaec2..a2bc7f07cc32be 100644 --- a/drivers/clk/bcm/clk-kona-setup.c +++ b/drivers/clk/bcm/clk-kona-setup.c @@ -569,14 +569,12 @@ static u32 *parent_process(const char *clocks[], * selector is not required, but we allocate space for the * array anyway to keep things simple. */ - parent_names = kmalloc_array(parent_count, sizeof(*parent_names), - GFP_KERNEL); + parent_names = kmalloc_objs(*parent_names, parent_count); if (!parent_names) return ERR_PTR(-ENOMEM); /* There is at least one parent, so allocate a selector array */ - parent_sel = kmalloc_array(parent_count, sizeof(*parent_sel), - GFP_KERNEL); + parent_sel = kmalloc_objs(*parent_sel, parent_count); if (!parent_sel) { kfree(parent_names); diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 9882f243d68133..fef0da31bda2fe 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -377,7 +377,7 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi, u32 min_rate, max_rate; int ret; - data = devm_kzalloc(rpi->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(rpi->dev, *data); if (!data) return ERR_PTR(-ENOMEM); data->rpi = rpi; @@ -459,9 +459,7 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi, * RPI_FIRMWARE_GET_CLOCKS is zeroed. So allocate an additional * zero element as sentinel. */ - clks = devm_kcalloc(rpi->dev, - RPI_FIRMWARE_NUM_CLK_ID + 1, sizeof(*clks), - GFP_KERNEL); + clks = devm_kzalloc_objs(rpi->dev, *clks, RPI_FIRMWARE_NUM_CLK_ID + 1); if (!clks) return -ENOMEM; @@ -528,7 +526,7 @@ static int raspberrypi_clk_probe(struct platform_device *pdev) if (!firmware) return -EPROBE_DEFER; - rpi = devm_kzalloc(dev, sizeof(*rpi), GFP_KERNEL); + rpi = devm_kzalloc_obj(dev, *rpi); if (!rpi) return -ENOMEM; @@ -536,9 +534,8 @@ static int raspberrypi_clk_probe(struct platform_device *pdev) rpi->firmware = firmware; platform_set_drvdata(pdev, rpi); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, - RPI_FIRMWARE_NUM_CLK_ID), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, + RPI_FIRMWARE_NUM_CLK_ID); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/cix/clk-sky1-audss.c b/drivers/clk/cix/clk-sky1-audss.c index e096b8121df300..99715c089c52d8 100644 --- a/drivers/clk/cix/clk-sky1-audss.c +++ b/drivers/clk/cix/clk-sky1-audss.c @@ -824,7 +824,7 @@ static struct clk_hw *sky1_audss_clk_register(struct device *dev, struct clk_parent_data *parent_data; int i; - parent_data = devm_kcalloc(dev, num_parents, sizeof(*parent_data), GFP_KERNEL); + parent_data = devm_kzalloc_objs(dev, *parent_data, num_parents); if (!parent_data) return ERR_PTR(-ENOMEM); @@ -832,7 +832,7 @@ static struct clk_hw *sky1_audss_clk_register(struct device *dev, parent_data[i].name = parent_names[i]; if (mux_cfg->offset >= 0) { - sky1_mux = devm_kzalloc(dev, sizeof(*sky1_mux), GFP_KERNEL); + sky1_mux = devm_kzalloc_obj(dev, *sky1_mux); if (!sky1_mux) return ERR_PTR(-ENOMEM); @@ -848,7 +848,7 @@ static struct clk_hw *sky1_audss_clk_register(struct device *dev, } if (div_cfg->offset >= 0) { - sky1_div = devm_kzalloc(dev, sizeof(*sky1_div), GFP_KERNEL); + sky1_div = devm_kzalloc_obj(dev, *sky1_div); if (!sky1_div) return ERR_PTR(-ENOMEM); @@ -863,7 +863,7 @@ static struct clk_hw *sky1_audss_clk_register(struct device *dev, } if (gate_cfg->offset >= 0) { - sky1_gate = devm_kzalloc(dev, sizeof(*sky1_gate), GFP_KERNEL); + sky1_gate = devm_kzalloc_obj(dev, *sky1_gate); if (!sky1_gate) return ERR_PTR(-ENOMEM); @@ -973,15 +973,14 @@ static int sky1_audss_clk_probe(struct platform_device *pdev) if (!devtype_data) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; spin_lock_init(&priv->lock); - priv->clk_data = devm_kzalloc(dev, - struct_size(priv->clk_data, hws, SKY1_AUDSS_NUM_CLKS), - GFP_KERNEL); + priv->clk_data = devm_kzalloc_flex(dev, *priv->clk_data, hws, + SKY1_AUDSS_NUM_CLKS); if (!priv->clk_data) return -ENOMEM; diff --git a/drivers/clk/clk-apple-nco.c b/drivers/clk/clk-apple-nco.c index 434c067968bbc1..e96438c8c90932 100644 --- a/drivers/clk/clk-apple-nco.c +++ b/drivers/clk/clk-apple-nco.c @@ -275,13 +275,13 @@ static int applnco_probe(struct platform_device *pdev) nchannels = (resource_size(res) - NCO_CHANNEL_REGSIZE) / NCO_CHANNEL_STRIDE + 1; - onecell_data = devm_kzalloc(&pdev->dev, struct_size(onecell_data, hws, - nchannels), GFP_KERNEL); + onecell_data = devm_kzalloc_flex(&pdev->dev, *onecell_data, hws, + nchannels); if (!onecell_data) return -ENOMEM; onecell_data->num = nchannels; - tbl = devm_kzalloc(&pdev->dev, sizeof(*tbl), GFP_KERNEL); + tbl = devm_kzalloc_obj(&pdev->dev, *tbl); if (!tbl) return -ENOMEM; applnco_compute_tables(tbl); @@ -289,7 +289,7 @@ static int applnco_probe(struct platform_device *pdev) for (i = 0; i < nchannels; i++) { struct applnco_channel *chan; - chan = devm_kzalloc(&pdev->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(&pdev->dev, *chan); if (!chan) return -ENOMEM; chan->base = base + NCO_CHANNEL_STRIDE * i; diff --git a/drivers/clk/clk-axi-clkgen.c b/drivers/clk/clk-axi-clkgen.c index e53256c56dfabc..8f3b9d1d76a12a 100644 --- a/drivers/clk/clk-axi-clkgen.c +++ b/drivers/clk/clk-axi-clkgen.c @@ -579,7 +579,7 @@ static int axi_clkgen_probe(struct platform_device *pdev) if (!dflt_limits) return -ENODEV; - axi_clkgen = devm_kzalloc(&pdev->dev, sizeof(*axi_clkgen), GFP_KERNEL); + axi_clkgen = devm_kzalloc_obj(&pdev->dev, *axi_clkgen); if (!axi_clkgen) return -ENOMEM; diff --git a/drivers/clk/clk-bd718x7.c b/drivers/clk/clk-bd718x7.c index 1698b763bcb78d..c1232784e5ce9b 100644 --- a/drivers/clk/clk-bd718x7.c +++ b/drivers/clk/clk-bd718x7.c @@ -92,7 +92,7 @@ static int bd71837_clk_probe(struct platform_device *pdev) }; enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; - c = devm_kzalloc(&pdev->dev, sizeof(*c), GFP_KERNEL); + c = devm_kzalloc_obj(&pdev->dev, *c); if (!c) return -ENOMEM; diff --git a/drivers/clk/clk-bm1880.c b/drivers/clk/clk-bm1880.c index 122e57176c1c8d..da8ff672ee0f92 100644 --- a/drivers/clk/clk-bm1880.c +++ b/drivers/clk/clk-bm1880.c @@ -889,8 +889,7 @@ static int bm1880_clk_probe(struct platform_device *pdev) ARRAY_SIZE(bm1880_composite_clks) + ARRAY_SIZE(bm1880_gate_clks); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hw_data.hws, - num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hw_data.hws, num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/clk-cdce706.c b/drivers/clk/clk-cdce706.c index 828125a8610be6..c2cb58052fa611 100644 --- a/drivers/clk/clk-cdce706.c +++ b/drivers/clk/clk-cdce706.c @@ -641,7 +641,7 @@ static int cdce706_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - cdce = devm_kzalloc(&client->dev, sizeof(*cdce), GFP_KERNEL); + cdce = devm_kzalloc_obj(&client->dev, *cdce); if (!cdce) return -ENOMEM; diff --git a/drivers/clk/clk-cdce925.c b/drivers/clk/clk-cdce925.c index 56b69d4fe4c258..52d350f91496b7 100644 --- a/drivers/clk/clk-cdce925.c +++ b/drivers/clk/clk-cdce925.c @@ -648,7 +648,7 @@ static int cdce925_probe(struct i2c_client *client) if (err) return err; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c index da66b9ae3de540..cf3a3f7f12235f 100644 --- a/drivers/clk/clk-conf.c +++ b/drivers/clk/clk-conf.c @@ -91,7 +91,7 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) count_64 = of_property_count_u64_elems(node, "assigned-clock-rates-u64"); if (count_64 > 0) { count = count_64; - rates_64 = kcalloc(count, sizeof(*rates_64), GFP_KERNEL); + rates_64 = kzalloc_objs(*rates_64, count); if (!rates_64) return -ENOMEM; @@ -99,7 +99,7 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) "assigned-clock-rates-u64", rates_64, count); } else if (count > 0) { - rates = kcalloc(count, sizeof(*rates), GFP_KERNEL); + rates = kzalloc_objs(*rates, count); if (!rates) return -ENOMEM; diff --git a/drivers/clk/clk-cs2000-cp.c b/drivers/clk/clk-cs2000-cp.c index aa1823b3100eea..54b9d239d822a5 100644 --- a/drivers/clk/clk-cs2000-cp.c +++ b/drivers/clk/clk-cs2000-cp.c @@ -574,7 +574,7 @@ static int cs2000_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c index 24fdec2e6198c4..cf09f82222f65f 100644 --- a/drivers/clk/clk-en7523.c +++ b/drivers/clk/clk-en7523.c @@ -641,7 +641,7 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev, }; struct en_clk_gate *cg; - cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL); + cg = devm_kzalloc_obj(dev, *cg); if (!cg) return NULL; @@ -859,7 +859,7 @@ static int en7581_reset_register(struct device *dev, void __iomem *base, { struct en_rst_data *rst_data; - rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL); + rst_data = devm_kzalloc_obj(dev, *rst_data); if (!rst_data) return -ENOMEM; @@ -1022,8 +1022,7 @@ static int en7581_serdes_phy_register(struct device *dev) for (i = 0; i < EN_SERDES_PHY_NUM; i++) { struct en_serdes_phy_instance *instance; - instance = devm_kzalloc(dev, sizeof(*instance), - GFP_KERNEL); + instance = devm_kzalloc_obj(dev, *instance); if (!instance) return -ENOMEM; @@ -1193,15 +1192,14 @@ static int en7523_clk_probe(struct platform_device *pdev) soc_data = device_get_match_data(&pdev->dev); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; spin_lock_init(&priv->lock); - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, hws, soc_data->num_clocks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, + soc_data->num_clocks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/clk-ep93xx.c b/drivers/clk/clk-ep93xx.c index 972aadd11493d7..63a6775ac1f3ec 100644 --- a/drivers/clk/clk-ep93xx.c +++ b/drivers/clk/clk-ep93xx.c @@ -672,7 +672,7 @@ static int ep93xx_clk_probe(struct auxiliary_device *adev, int ret; u32 value; - priv = devm_kzalloc(dev, struct_size(priv, reg, 10), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, reg, 10); if (!priv) return -ENOMEM; diff --git a/drivers/clk/clk-fsl-sai.c b/drivers/clk/clk-fsl-sai.c index eded6a5fac2165..293d78ab0372c2 100644 --- a/drivers/clk/clk-fsl-sai.c +++ b/drivers/clk/clk-fsl-sai.c @@ -110,7 +110,7 @@ static int fsl_sai_clk_probe(struct platform_device *pdev) void __iomem *base; int ret; - sai_clk = devm_kzalloc(dev, sizeof(*sai_clk), GFP_KERNEL); + sai_clk = devm_kzalloc_obj(dev, *sai_clk); if (!sai_clk) return -ENOMEM; diff --git a/drivers/clk/clk-gemini.c b/drivers/clk/clk-gemini.c index 4e874392e3b0b5..2e2fcc0f5e7c29 100644 --- a/drivers/clk/clk-gemini.c +++ b/drivers/clk/clk-gemini.c @@ -281,7 +281,7 @@ static int gemini_clk_probe(struct platform_device *pdev) int ret; int i; - gr = devm_kzalloc(dev, sizeof(*gr), GFP_KERNEL); + gr = devm_kzalloc_obj(dev, *gr); if (!gr) return -ENOMEM; diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 918b2c6444eef7..df0856a39c8d2d 100644 --- a/drivers/clk/clk-gpio.c +++ b/drivers/clk/clk-gpio.c @@ -151,7 +151,7 @@ static struct clk_hw *clk_register_gpio(struct device *dev, u8 num_parents, { .index = 1 }, }; - clk_gpio = devm_kzalloc(dev, sizeof(*clk_gpio), GFP_KERNEL); + clk_gpio = devm_kzalloc_obj(dev, *clk_gpio); if (!clk_gpio) return ERR_PTR(-ENOMEM); @@ -362,7 +362,7 @@ static int clk_gated_fixed_probe(struct platform_device *pdev) u32 rate; int ret; - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return -ENOMEM; diff --git a/drivers/clk/clk-hi655x.c b/drivers/clk/clk-hi655x.c index cf8ddcfb380c36..ef5c5fd62cb6c5 100644 --- a/drivers/clk/clk-hi655x.c +++ b/drivers/clk/clk-hi655x.c @@ -83,7 +83,7 @@ static int hi655x_clk_probe(struct platform_device *pdev) }; int ret; - hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL); + hi655x_clk = devm_kzalloc_obj(&pdev->dev, *hi655x_clk); if (!hi655x_clk) return -ENOMEM; diff --git a/drivers/clk/clk-hsdk-pll.c b/drivers/clk/clk-hsdk-pll.c index 0e257cce588e75..bb7b4016486459 100644 --- a/drivers/clk/clk-hsdk-pll.c +++ b/drivers/clk/clk-hsdk-pll.c @@ -311,7 +311,7 @@ static int hsdk_pll_clk_probe(struct platform_device *pdev) struct clk_init_data init = { }; struct device *dev = &pdev->dev; - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return -ENOMEM; diff --git a/drivers/clk/clk-k230.c b/drivers/clk/clk-k230.c index f34a3e6d3bca01..a21625edf99f7f 100644 --- a/drivers/clk/clk-k230.c +++ b/drivers/clk/clk-k230.c @@ -2372,7 +2372,7 @@ static int k230_clk_init_plls(struct platform_device *pdev) /* used for all the plls */ spinlock_t *lock; - lock = devm_kzalloc(&pdev->dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(&pdev->dev, *lock); if (!lock) return -ENOMEM; @@ -2401,7 +2401,7 @@ static int k230_clk_init_clks(struct platform_device *pdev, /* used for all the clocks */ spinlock_t *lock; - lock = devm_kzalloc(&pdev->dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(&pdev->dev, *lock); if (!lock) return -ENOMEM; @@ -2425,8 +2425,7 @@ static int k230_clk_probe(struct platform_device *pdev) int ret; struct clk_hw_onecell_data *hw_data; - hw_data = devm_kzalloc(&pdev->dev, struct_size(hw_data, hws, K230_CLK_NUM), - GFP_KERNEL); + hw_data = devm_kzalloc_flex(&pdev->dev, *hw_data, hws, K230_CLK_NUM); if (!hw_data) return -ENOMEM; diff --git a/drivers/clk/clk-lan966x.c b/drivers/clk/clk-lan966x.c index 3c7a48c616bbc5..754bbef835e751 100644 --- a/drivers/clk/clk-lan966x.c +++ b/drivers/clk/clk-lan966x.c @@ -208,7 +208,7 @@ static struct clk_hw *lan966x_gck_clk_register(struct device *dev, int i) struct lan966x_gck *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); @@ -260,8 +260,7 @@ static int lan966x_clk_probe(struct platform_device *pdev) if (!data) return -EINVAL; - hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, data->num_total_clks), - GFP_KERNEL); + hw_data = devm_kzalloc_flex(dev, *hw_data, hws, data->num_total_clks); if (!hw_data) return -ENOMEM; diff --git a/drivers/clk/clk-lmk04832.c b/drivers/clk/clk-lmk04832.c index 755f9837c53aa9..e6e771e8eb145b 100644 --- a/drivers/clk/clk-lmk04832.c +++ b/drivers/clk/clk-lmk04832.c @@ -1396,7 +1396,7 @@ static int lmk04832_probe(struct spi_device *spi) info = &lmk04832_device_info; - lmk = devm_kzalloc(&spi->dev, sizeof(struct lmk04832), GFP_KERNEL); + lmk = devm_kzalloc_obj(&spi->dev, struct lmk04832); if (!lmk) return -ENOMEM; @@ -1414,23 +1414,22 @@ static int lmk04832_probe(struct spi_device *spi) return dev_err_probe(lmk->dev, PTR_ERR(lmk->reset_gpio), "failed to get reset GPIO\n"); - lmk->dclk = devm_kcalloc(lmk->dev, info->num_channels >> 1, - sizeof(struct lmk_dclk), GFP_KERNEL); + lmk->dclk = devm_kzalloc_objs(lmk->dev, struct lmk_dclk, + info->num_channels >> 1); if (!lmk->dclk) { ret = -ENOMEM; return ret; } - lmk->clkout = devm_kcalloc(lmk->dev, info->num_channels, - sizeof(*lmk->clkout), GFP_KERNEL); + lmk->clkout = devm_kzalloc_objs(lmk->dev, *lmk->clkout, + info->num_channels); if (!lmk->clkout) { ret = -ENOMEM; return ret; } - lmk->clk_data = devm_kzalloc(lmk->dev, struct_size(lmk->clk_data, hws, - info->num_channels), - GFP_KERNEL); + lmk->clk_data = devm_kzalloc_flex(lmk->dev, *lmk->clk_data, hws, + info->num_channels); if (!lmk->clk_data) { ret = -ENOMEM; return ret; diff --git a/drivers/clk/clk-lochnagar.c b/drivers/clk/clk-lochnagar.c index 5561a2c66b6973..76da48fbba24df 100644 --- a/drivers/clk/clk-lochnagar.c +++ b/drivers/clk/clk-lochnagar.c @@ -246,7 +246,7 @@ static int lochnagar_clk_probe(struct platform_device *pdev) struct lochnagar_config *conf; int ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/clk-loongson2.c b/drivers/clk/clk-loongson2.c index 9c4c6c99db3ec7..c620797893a348 100644 --- a/drivers/clk/clk-loongson2.c +++ b/drivers/clk/clk-loongson2.c @@ -326,7 +326,7 @@ static struct clk_hw *loongson2_clk_register(const char *parent, struct loongson2_clk_data *clk; struct clk_init_data init = { }; - clk = devm_kzalloc(clp->dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(clp->dev, *clk); if (!clk) return ERR_PTR(-ENOMEM); @@ -373,8 +373,7 @@ static int loongson2_clk_probe(struct platform_device *pdev) for (p = data; p->name; p++) clks_num = max(clks_num, p->id + 1); - clp = devm_kzalloc(dev, struct_size(clp, clk_data.hws, clks_num), - GFP_KERNEL); + clp = devm_kzalloc_flex(dev, *clp, clk_data.hws, clks_num); if (!clp) return -ENOMEM; diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c index e6fde914c5efe9..6c9fbce4f81de1 100644 --- a/drivers/clk/clk-max77686.c +++ b/drivers/clk/clk-max77686.c @@ -189,7 +189,7 @@ static int max77686_clk_probe(struct platform_device *pdev) return -EINVAL; } - drv_data = devm_kzalloc(dev, struct_size(drv_data, max_clk_data, num_clks), GFP_KERNEL); + drv_data = devm_kzalloc_flex(dev, *drv_data, max_clk_data, num_clks); if (!drv_data) return -ENOMEM; diff --git a/drivers/clk/clk-max9485.c b/drivers/clk/clk-max9485.c index 0515e3e41162e3..9c48c0c3a99887 100644 --- a/drivers/clk/clk-max9485.c +++ b/drivers/clk/clk-max9485.c @@ -268,7 +268,7 @@ static int max9485_i2c_probe(struct i2c_client *client) const char *xclk_name; int i, ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/clk/clk-npcm8xx.c b/drivers/clk/clk-npcm8xx.c index 2138c011411d28..cc98131b430775 100644 --- a/drivers/clk/clk-npcm8xx.c +++ b/drivers/clk/clk-npcm8xx.c @@ -260,7 +260,7 @@ npcm8xx_clk_register_pll(struct device *dev, void __iomem *pllcon, struct clk_init_data init = {}; int ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); @@ -291,9 +291,8 @@ static int npcm8xx_clk_probe(struct auxiliary_device *adev, struct clk_hw *hw; unsigned int i; - npcm8xx_clk_data = devm_kzalloc(dev, struct_size(npcm8xx_clk_data, hws, - NPCM8XX_NUM_CLOCKS), - GFP_KERNEL); + npcm8xx_clk_data = devm_kzalloc_flex(dev, *npcm8xx_clk_data, hws, + NPCM8XX_NUM_CLOCKS); if (!npcm8xx_clk_data) return -ENOMEM; diff --git a/drivers/clk/clk-palmas.c b/drivers/clk/clk-palmas.c index fdbf8445ebc281..ad35441ac209af 100644 --- a/drivers/clk/clk-palmas.c +++ b/drivers/clk/clk-palmas.c @@ -250,7 +250,7 @@ static int palmas_clks_probe(struct platform_device *pdev) if (!match_data) return 1; - cinfo = devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL); + cinfo = devm_kzalloc_obj(&pdev->dev, *cinfo); if (!cinfo) return -ENOMEM; diff --git a/drivers/clk/clk-plldig.c b/drivers/clk/clk-plldig.c index 14357f3e456183..4c29a937450082 100644 --- a/drivers/clk/clk-plldig.c +++ b/drivers/clk/clk-plldig.c @@ -225,7 +225,7 @@ static int plldig_clk_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-pwm.c b/drivers/clk/clk-pwm.c index 2001c7c9367c00..b1e464d5dd29ef 100644 --- a/drivers/clk/clk-pwm.c +++ b/drivers/clk/clk-pwm.c @@ -102,7 +102,7 @@ static int clk_pwm_probe(struct platform_device *pdev) const char *clk_name; int ret; - clk_pwm = devm_kzalloc(&pdev->dev, sizeof(*clk_pwm), GFP_KERNEL); + clk_pwm = devm_kzalloc_obj(&pdev->dev, *clk_pwm); if (!clk_pwm) return -ENOMEM; diff --git a/drivers/clk/clk-renesas-pcie.c b/drivers/clk/clk-renesas-pcie.c index 864bf89cecd065..d7fa7e6aec627c 100644 --- a/drivers/clk/clk-renesas-pcie.c +++ b/drivers/clk/clk-renesas-pcie.c @@ -284,8 +284,8 @@ static int rs9_probe(struct i2c_client *client) if (!chip_info) return -EINVAL; - rs9 = devm_kzalloc(&client->dev, struct_size(rs9, onecell.hws, - chip_info->num_clks), GFP_KERNEL); + rs9 = devm_kzalloc_flex(&client->dev, *rs9, onecell.hws, + chip_info->num_clks); if (!rs9) return -ENOMEM; diff --git a/drivers/clk/clk-rk808.c b/drivers/clk/clk-rk808.c index 5a75b5c9155519..ff0cec86d2e69e 100644 --- a/drivers/clk/clk-rk808.c +++ b/drivers/clk/clk-rk808.c @@ -155,8 +155,7 @@ static int rk808_clkout_probe(struct platform_device *pdev) device_set_of_node_from_dev(dev, dev->parent); - rk808_clkout = devm_kzalloc(dev, - sizeof(*rk808_clkout), GFP_KERNEL); + rk808_clkout = devm_kzalloc_obj(dev, *rk808_clkout); if (!rk808_clkout) return -ENOMEM; diff --git a/drivers/clk/clk-rp1.c b/drivers/clk/clk-rp1.c index 0f7d9fd77481d4..1dd276dd2bb3e0 100644 --- a/drivers/clk/clk-rp1.c +++ b/drivers/clk/clk-rp1.c @@ -2394,8 +2394,7 @@ static int rp1_clk_probe(struct platform_device *pdev) struct clk_hw **hws; unsigned int i; - clockman = devm_kzalloc(dev, struct_size(clockman, onecell.hws, asize), - GFP_KERNEL); + clockman = devm_kzalloc_flex(dev, *clockman, onecell.hws, asize); if (!clockman) return -ENOMEM; diff --git a/drivers/clk/clk-rpmi.c b/drivers/clk/clk-rpmi.c index 921296aafa686e..40c11c373556fd 100644 --- a/drivers/clk/clk-rpmi.c +++ b/drivers/clk/clk-rpmi.c @@ -452,11 +452,11 @@ static struct clk_hw *rpmi_clk_enumerate(struct rpmi_clk_context *context, u32 c struct clk_hw *clk_hw; int ret; - rates = devm_kzalloc(dev, sizeof(*rates), GFP_KERNEL); + rates = devm_kzalloc_obj(dev, *rates); if (!rates) return ERR_PTR(-ENOMEM); - rpmi_clk = devm_kzalloc(dev, sizeof(*rpmi_clk), GFP_KERNEL); + rpmi_clk = devm_kzalloc_obj(dev, *rpmi_clk); if (!rpmi_clk) return ERR_PTR(-ENOMEM); @@ -518,7 +518,7 @@ static int rpmi_clk_probe(struct platform_device *pdev) struct clk_hw *hw_ptr; struct device *dev = &pdev->dev; - context = devm_kzalloc(dev, sizeof(*context), GFP_KERNEL); + context = devm_kzalloc_obj(dev, *context); if (!context) return -ENOMEM; context->dev = dev; @@ -578,8 +578,7 @@ static int rpmi_clk_probe(struct platform_device *pdev) if (!num_clocks) return dev_err_probe(dev, -ENODEV, "No clocks found\n"); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_clocks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, num_clocks); if (!clk_data) return dev_err_probe(dev, -ENOMEM, "No memory for clock data\n"); clk_data->num = num_clocks; diff --git a/drivers/clk/clk-s2mps11.c b/drivers/clk/clk-s2mps11.c index 94969d97d6e995..0d3d38b3ab093c 100644 --- a/drivers/clk/clk-s2mps11.c +++ b/drivers/clk/clk-s2mps11.c @@ -127,14 +127,13 @@ static int s2mps11_clk_probe(struct platform_device *pdev) int i, ret = 0; enum sec_device_type hwid = platform_get_device_id(pdev)->driver_data; - s2mps11_clks = devm_kcalloc(&pdev->dev, S2MPS11_CLKS_NUM, - sizeof(*s2mps11_clks), GFP_KERNEL); + s2mps11_clks = devm_kzalloc_objs(&pdev->dev, *s2mps11_clks, + S2MPS11_CLKS_NUM); if (!s2mps11_clks) return -ENOMEM; - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, hws, S2MPS11_CLKS_NUM), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, + S2MPS11_CLKS_NUM); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 2dd50c5b4ea8f2..1903b4e8442d94 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -215,7 +215,7 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key) struct scmi_clk_oem *oem_data = dev_get_drvdata(dev); struct clk_ops *ops; - ops = devm_kzalloc(dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(dev, *ops); if (!ops) return NULL; /* @@ -378,8 +378,7 @@ static int scmi_clocks_probe(struct scmi_device *sdev) return -EINVAL; } - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, count); if (!clk_data) return -ENOMEM; @@ -391,7 +390,7 @@ static int scmi_clocks_probe(struct scmi_device *sdev) transport_is_atomic = handle->is_transport_atomic(handle, &atomic_threshold_us); - sclks = devm_kcalloc(dev, count, sizeof(*sclks), GFP_KERNEL); + sclks = devm_kzalloc_objs(dev, *sclks, count); if (!sclks) return -ENOMEM; @@ -428,8 +427,9 @@ static int scmi_clocks_probe(struct scmi_device *sdev) /* Initialize clock parent data. */ if (sclk->info->num_parents > 0) { - sclk->parent_data = devm_kcalloc(dev, sclk->info->num_parents, - sizeof(*sclk->parent_data), GFP_KERNEL); + sclk->parent_data = devm_kzalloc_objs(dev, + *sclk->parent_data, + sclk->info->num_parents); if (!sclk->parent_data) return -ENOMEM; diff --git a/drivers/clk/clk-scpi.c b/drivers/clk/clk-scpi.c index e2eec7be5c1961..e73de76504af03 100644 --- a/drivers/clk/clk-scpi.c +++ b/drivers/clk/clk-scpi.c @@ -189,13 +189,12 @@ static int scpi_clk_add(struct device *dev, struct device_node *np, return -EINVAL; } - clk_data = devm_kmalloc(dev, sizeof(*clk_data), GFP_KERNEL); + clk_data = devm_kmalloc_obj(dev, *clk_data); if (!clk_data) return -ENOMEM; clk_data->clk_num = count; - clk_data->clk = devm_kcalloc(dev, count, sizeof(*clk_data->clk), - GFP_KERNEL); + clk_data->clk = devm_kzalloc_objs(dev, *clk_data->clk, count); if (!clk_data->clk) return -ENOMEM; @@ -204,7 +203,7 @@ static int scpi_clk_add(struct device *dev, struct device_node *np, const char *name; u32 val; - sclk = devm_kzalloc(dev, sizeof(*sclk), GFP_KERNEL); + sclk = devm_kzalloc_obj(dev, *sclk); if (!sclk) return -ENOMEM; diff --git a/drivers/clk/clk-si514.c b/drivers/clk/clk-si514.c index 07091b91420d16..76d8016fd16766 100644 --- a/drivers/clk/clk-si514.c +++ b/drivers/clk/clk-si514.c @@ -341,7 +341,7 @@ static int si514_probe(struct i2c_client *client) struct clk_si514 *data; int err; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-si521xx.c b/drivers/clk/clk-si521xx.c index 84dc3621df93c0..7d96c36316778c 100644 --- a/drivers/clk/clk-si521xx.c +++ b/drivers/clk/clk-si521xx.c @@ -298,7 +298,7 @@ static int si521xx_probe(struct i2c_client *client) if (!chip_info) return -EINVAL; - si = devm_kzalloc(&client->dev, sizeof(*si), GFP_KERNEL); + si = devm_kzalloc_obj(&client->dev, *si); if (!si) return -ENOMEM; diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c index 88522333525b68..8fe16c4612b252 100644 --- a/drivers/clk/clk-si5341.c +++ b/drivers/clk/clk-si5341.c @@ -1567,7 +1567,7 @@ static int si5341_probe(struct i2c_client *client) bool initialization_required; u32 status; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c index 70daba62305c54..7a87695fd914de 100644 --- a/drivers/clk/clk-si5351.c +++ b/drivers/clk/clk-si5351.c @@ -1195,7 +1195,7 @@ static int si5351_dt_parse(struct i2c_client *client, if (np == NULL) return 0; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) return -ENOMEM; @@ -1464,7 +1464,7 @@ static int si5351_i2c_probe(struct i2c_client *client) if (!pdata) return -EINVAL; - drvdata = devm_kzalloc(&client->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&client->dev, *drvdata); if (!drvdata) return -ENOMEM; @@ -1639,10 +1639,10 @@ static int si5351_i2c_probe(struct i2c_client *client) else parent_names[1] = si5351_pll_names[1]; - drvdata->msynth = devm_kcalloc(&client->dev, num_clocks, - sizeof(*drvdata->msynth), GFP_KERNEL); - drvdata->clkout = devm_kcalloc(&client->dev, num_clocks, - sizeof(*drvdata->clkout), GFP_KERNEL); + drvdata->msynth = devm_kzalloc_objs(&client->dev, *drvdata->msynth, + num_clocks); + drvdata->clkout = devm_kzalloc_objs(&client->dev, *drvdata->clkout, + num_clocks); drvdata->num_clkout = num_clocks; if (WARN_ON(!drvdata->msynth || !drvdata->clkout)) { diff --git a/drivers/clk/clk-si544.c b/drivers/clk/clk-si544.c index 3924ec3e216369..a8479c9fe2dbed 100644 --- a/drivers/clk/clk-si544.c +++ b/drivers/clk/clk-si544.c @@ -449,7 +449,7 @@ static int si544_probe(struct i2c_client *client) struct clk_si544 *data; int err; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-si570.c b/drivers/clk/clk-si570.c index ac9013e7379c80..4a413f2b31c5d7 100644 --- a/drivers/clk/clk-si570.c +++ b/drivers/clk/clk-si570.c @@ -417,7 +417,7 @@ static int si570_probe(struct i2c_client *client) bool skip_recall; int err; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/clk-sp7021.c b/drivers/clk/clk-sp7021.c index 36528a71a2e62f..3cba389206e967 100644 --- a/drivers/clk/clk-sp7021.c +++ b/drivers/clk/clk-sp7021.c @@ -560,7 +560,7 @@ static struct clk_hw *sp_pll_register(struct device *dev, const char *name, }; int ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); @@ -613,8 +613,7 @@ static int sp7021_clk_probe(struct platform_device *pdev) for (i = 0; i < ARRAY_SIZE(sp_clken); i++) writel((sp_clken[i] << 16) | sp_clken[i], clk_base + i * 4); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, CLK_MAX), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, CLK_MAX); if (!clk_data) return -ENOMEM; clk_data->num = CLK_MAX; diff --git a/drivers/clk/clk-sparx5.c b/drivers/clk/clk-sparx5.c index b2facc9c95d471..a3d02562226709 100644 --- a/drivers/clk/clk-sparx5.c +++ b/drivers/clk/clk-sparx5.c @@ -256,7 +256,7 @@ static int s5_clk_probe(struct platform_device *pdev) .parent_data = &pdata, }; - s5_clk = devm_kzalloc(dev, sizeof(*s5_clk), GFP_KERNEL); + s5_clk = devm_kzalloc_obj(dev, *s5_clk); if (!s5_clk) return -ENOMEM; diff --git a/drivers/clk/clk-tps68470.c b/drivers/clk/clk-tps68470.c index 9511248c6bc984..53b871d710ea5e 100644 --- a/drivers/clk/clk-tps68470.c +++ b/drivers/clk/clk-tps68470.c @@ -206,8 +206,7 @@ static int tps68470_clk_probe(struct platform_device *pdev) int ret; int i; - tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata), - GFP_KERNEL); + tps68470_clkdata = devm_kzalloc_obj(&pdev->dev, *tps68470_clkdata); if (!tps68470_clkdata) return -ENOMEM; diff --git a/drivers/clk/clk-twl.c b/drivers/clk/clk-twl.c index 20bc3bf8fd62d3..53731d7de6d7c8 100644 --- a/drivers/clk/clk-twl.c +++ b/drivers/clk/clk-twl.c @@ -153,14 +153,12 @@ static int twl_clks_probe(struct platform_device *pdev) for (count = 0; hw_data[count].init.name; count++) ; - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, hws, count), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, count); if (!clk_data) return -ENOMEM; clk_data->num = count; - cinfo = devm_kcalloc(&pdev->dev, count, sizeof(*cinfo), GFP_KERNEL); + cinfo = devm_kzalloc_objs(&pdev->dev, *cinfo, count); if (!cinfo) return -ENOMEM; diff --git a/drivers/clk/clk-twl6040.c b/drivers/clk/clk-twl6040.c index b8d1cfe5b0e1f5..8d7f48ea69d027 100644 --- a/drivers/clk/clk-twl6040.c +++ b/drivers/clk/clk-twl6040.c @@ -129,7 +129,7 @@ static int twl6040_pdmclk_probe(struct platform_device *pdev) struct twl6040_pdmclk *clkdata; int ret; - clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL); + clkdata = devm_kzalloc_obj(&pdev->dev, *clkdata); if (!clkdata) return -ENOMEM; diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c index d91749be785c35..1cf8526975eb5a 100644 --- a/drivers/clk/clk-versaclock5.c +++ b/drivers/clk/clk-versaclock5.c @@ -957,7 +957,7 @@ static int vc5_probe(struct i2c_client *client) unsigned int n, idx = 0; int ret; - vc5 = devm_kzalloc(&client->dev, sizeof(*vc5), GFP_KERNEL); + vc5 = devm_kzalloc_obj(&client->dev, *vc5); if (!vc5) return -ENOMEM; diff --git a/drivers/clk/clk-versaclock7.c b/drivers/clk/clk-versaclock7.c index 1340d2f512be57..3eeaac126b7098 100644 --- a/drivers/clk/clk-versaclock7.c +++ b/drivers/clk/clk-versaclock7.c @@ -1108,7 +1108,7 @@ static int vc7_probe(struct i2c_client *client) unsigned long apll_rate; int ret; - vc7 = devm_kzalloc(&client->dev, sizeof(*vc7), GFP_KERNEL); + vc7 = devm_kzalloc_obj(&client->dev, *vc7); if (!vc7) return -ENOMEM; diff --git a/drivers/clk/clk-wm831x.c b/drivers/clk/clk-wm831x.c index 263e927138c2ea..f5967754ff5225 100644 --- a/drivers/clk/clk-wm831x.c +++ b/drivers/clk/clk-wm831x.c @@ -350,7 +350,7 @@ static int wm831x_clk_probe(struct platform_device *pdev) struct wm831x_clk *clkdata; int ret; - clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL); + clkdata = devm_kzalloc_obj(&pdev->dev, *clkdata); if (!clkdata) return -ENOMEM; diff --git a/drivers/clk/davinci/da8xx-cfgchip.c b/drivers/clk/davinci/da8xx-cfgchip.c index 9d7fced898ae07..51ffd80456fb13 100644 --- a/drivers/clk/davinci/da8xx-cfgchip.c +++ b/drivers/clk/davinci/da8xx-cfgchip.c @@ -100,7 +100,7 @@ da8xx_cfgchip_gate_clk_register(struct device *dev, parent_name = __clk_get_name(parent); - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); @@ -244,7 +244,7 @@ da8xx_cfgchip_mux_clk_register(struct device *dev, struct clk_init_data init = {}; int ret; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); @@ -516,7 +516,7 @@ da8xx_cfgchip_register_usb0_clk48(struct device *dev, return dev_err_cast_probe(dev, fck_clk, "Missing fck clock\n"); } - usb0 = devm_kzalloc(dev, sizeof(*usb0), GFP_KERNEL); + usb0 = devm_kzalloc_obj(dev, *usb0); if (!usb0) return ERR_PTR(-ENOMEM); @@ -585,7 +585,7 @@ da8xx_cfgchip_register_usb1_clk48(struct device *dev, struct clk_init_data init = {}; int ret; - usb1 = devm_kzalloc(dev, sizeof(*usb1), GFP_KERNEL); + usb1 = devm_kzalloc_obj(dev, *usb1); if (!usb1) return ERR_PTR(-ENOMEM); @@ -651,8 +651,7 @@ static int of_da8xx_usb_phy_clk_init(struct device *dev, struct regmap *regmap) struct da8xx_usb0_clk48 *usb0; struct da8xx_usb1_clk48 *usb1; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, 2), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, 2); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/eswin/clk-eic7700-hsp.c b/drivers/clk/eswin/clk-eic7700-hsp.c index 6ddb8fbd605ed4..d3dd867da3d946 100644 --- a/drivers/clk/eswin/clk-eic7700-hsp.c +++ b/drivers/clk/eswin/clk-eic7700-hsp.c @@ -128,7 +128,7 @@ hsp_clk_register_gate(struct device *dev, unsigned int id, const char *name, struct clk_hw *hw; int ret; - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/eswin/clk.c b/drivers/clk/eswin/clk.c index 79d1e4c5e637a3..e8851283ccdbf0 100644 --- a/drivers/clk/eswin/clk.c +++ b/drivers/clk/eswin/clk.c @@ -29,9 +29,8 @@ struct eswin_clock_data *eswin_clk_init(struct platform_device *pdev, { struct eswin_clock_data *eclk_data; - eclk_data = devm_kzalloc(&pdev->dev, - struct_size(eclk_data, clk_data.hws, nr_clks), - GFP_KERNEL); + eclk_data = devm_kzalloc_flex(&pdev->dev, *eclk_data, clk_data.hws, + nr_clks); if (!eclk_data) return ERR_PTR(-ENOMEM); @@ -423,7 +422,7 @@ struct clk_hw *eswin_register_clkdiv(struct device *dev, unsigned int id, struct clk_hw *clk_hw; int ret; - dclk = devm_kzalloc(dev, sizeof(*dclk), GFP_KERNEL); + dclk = devm_kzalloc_obj(dev, *dclk); if (!dclk) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/hisilicon/clk-hi3519.c b/drivers/clk/hisilicon/clk-hi3519.c index 0c50acd8543af7..9db7f17ced1e85 100644 --- a/drivers/clk/hisilicon/clk-hi3519.c +++ b/drivers/clk/hisilicon/clk-hi3519.c @@ -144,7 +144,7 @@ static int hi3519_clk_probe(struct platform_device *pdev) { struct hi3519_crg_data *crg; - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); + crg = devm_kmalloc_obj(&pdev->dev, *crg); if (!crg) return -ENOMEM; diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/clk-hi3559a.c index fea6fb9e98f59a..85d5222a0fa8e5 100644 --- a/drivers/clk/hisilicon/clk-hi3559a.c +++ b/drivers/clk/hisilicon/clk-hi3559a.c @@ -460,7 +460,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks, struct clk *clk = NULL; int i; - p_clk = devm_kcalloc(dev, nums, sizeof(*p_clk), GFP_KERNEL); + p_clk = devm_kzalloc_objs(dev, *p_clk, nums); if (!p_clk) return; @@ -785,7 +785,7 @@ static int hi3559av100_crg_probe(struct platform_device *pdev) { struct hisi_crg_dev *crg; - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); + crg = devm_kmalloc_obj(&pdev->dev, *crg); if (!crg) return -ENOMEM; diff --git a/drivers/clk/hisilicon/clk-hi6220-stub.c b/drivers/clk/hisilicon/clk-hi6220-stub.c index a70544d2bdb9a8..5191f8bf8b9489 100644 --- a/drivers/clk/hisilicon/clk-hi6220-stub.c +++ b/drivers/clk/hisilicon/clk-hi6220-stub.c @@ -201,7 +201,7 @@ static int hi6220_stub_clk_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int ret; - stub_clk = devm_kzalloc(dev, sizeof(*stub_clk), GFP_KERNEL); + stub_clk = devm_kzalloc_obj(dev, *stub_clk); if (!stub_clk) return -ENOMEM; diff --git a/drivers/clk/hisilicon/clk-hisi-phase.c b/drivers/clk/hisilicon/clk-hisi-phase.c index d8e555d9728de9..3cd4e5f27c88c8 100644 --- a/drivers/clk/hisilicon/clk-hisi-phase.c +++ b/drivers/clk/hisilicon/clk-hisi-phase.c @@ -97,7 +97,7 @@ struct clk *clk_register_hisi_phase(struct device *dev, struct clk_init_data init = {}; struct clk_hisi_phase *phase; - phase = devm_kzalloc(dev, sizeof(struct clk_hisi_phase), GFP_KERNEL); + phase = devm_kzalloc_obj(dev, struct clk_hisi_phase); if (!phase) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c index 08050ff1c8cf9a..69afa8cd5737e1 100644 --- a/drivers/clk/hisilicon/clk.c +++ b/drivers/clk/hisilicon/clk.c @@ -30,7 +30,7 @@ struct hisi_clock_data *hisi_clk_alloc(struct platform_device *pdev, struct resource *res; struct clk **clk_table; - clk_data = devm_kmalloc(&pdev->dev, sizeof(*clk_data), GFP_KERNEL); + clk_data = devm_kmalloc_obj(&pdev->dev, *clk_data); if (!clk_data) return NULL; @@ -42,9 +42,7 @@ struct hisi_clock_data *hisi_clk_alloc(struct platform_device *pdev, if (!clk_data->base) return NULL; - clk_table = devm_kmalloc_array(&pdev->dev, nr_clks, - sizeof(*clk_table), - GFP_KERNEL); + clk_table = devm_kmalloc_objs(&pdev->dev, *clk_table, nr_clks); if (!clk_table) return NULL; diff --git a/drivers/clk/hisilicon/crg-hi3516cv300.c b/drivers/clk/hisilicon/crg-hi3516cv300.c index b66140f74c5102..b25ec8e0b65af4 100644 --- a/drivers/clk/hisilicon/crg-hi3516cv300.c +++ b/drivers/clk/hisilicon/crg-hi3516cv300.c @@ -262,7 +262,7 @@ static int hi3516cv300_crg_probe(struct platform_device *pdev) { struct hisi_crg_dev *crg; - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); + crg = devm_kmalloc_obj(&pdev->dev, *crg); if (!crg) return -ENOMEM; diff --git a/drivers/clk/hisilicon/crg-hi3798cv200.c b/drivers/clk/hisilicon/crg-hi3798cv200.c index 8eabd1cc229fbe..cfdf4f923b33e5 100644 --- a/drivers/clk/hisilicon/crg-hi3798cv200.c +++ b/drivers/clk/hisilicon/crg-hi3798cv200.c @@ -345,7 +345,7 @@ static int hi3798cv200_crg_probe(struct platform_device *pdev) { struct hisi_crg_dev *crg; - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); + crg = devm_kmalloc_obj(&pdev->dev, *crg); if (!crg) return -ENOMEM; diff --git a/drivers/clk/hisilicon/reset.c b/drivers/clk/hisilicon/reset.c index c3b7daac931320..398895608a760e 100644 --- a/drivers/clk/hisilicon/reset.c +++ b/drivers/clk/hisilicon/reset.c @@ -91,7 +91,7 @@ struct hisi_reset_controller *hisi_reset_init(struct platform_device *pdev) { struct hisi_reset_controller *rstc; - rstc = devm_kzalloc(&pdev->dev, sizeof(*rstc), GFP_KERNEL); + rstc = devm_kzalloc_obj(&pdev->dev, *rstc); if (!rstc) return NULL; diff --git a/drivers/clk/imx/clk-imx8-acm.c b/drivers/clk/imx/clk-imx8-acm.c index 07dca6f31cf8ee..bb0198d3bb1682 100644 --- a/drivers/clk/imx/clk-imx8-acm.c +++ b/drivers/clk/imx/clk-imx8-acm.c @@ -269,16 +269,13 @@ static int clk_imx_acm_attach_pm_domains(struct device *dev, if (dev_pm->num_domains <= 1) return 0; - dev_pm->pd_dev = devm_kmalloc_array(dev, dev_pm->num_domains, - sizeof(*dev_pm->pd_dev), - GFP_KERNEL); + dev_pm->pd_dev = devm_kmalloc_objs(dev, *dev_pm->pd_dev, + dev_pm->num_domains); if (!dev_pm->pd_dev) return -ENOMEM; - dev_pm->pd_dev_link = devm_kmalloc_array(dev, - dev_pm->num_domains, - sizeof(*dev_pm->pd_dev_link), - GFP_KERNEL); + dev_pm->pd_dev_link = devm_kmalloc_objs(dev, *dev_pm->pd_dev_link, + dev_pm->num_domains); if (!dev_pm->pd_dev_link) return -ENOMEM; @@ -344,7 +341,7 @@ static int imx8_acm_clk_probe(struct platform_device *pdev) if (WARN_ON(IS_ERR(base))) return PTR_ERR(base); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -352,8 +349,8 @@ static int imx8_acm_clk_probe(struct platform_device *pdev) priv->soc_data = of_device_get_match_data(dev); platform_set_drvdata(pdev, priv); - clk_hw_data = devm_kzalloc(&pdev->dev, struct_size(clk_hw_data, hws, IMX_ADMA_ACM_CLK_END), - GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(&pdev->dev, *clk_hw_data, hws, + IMX_ADMA_ACM_CLK_END); if (!clk_hw_data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c index ab77e148e70ca7..9d4c3064dd2c51 100644 --- a/drivers/clk/imx/clk-imx8mn.c +++ b/drivers/clk/imx/clk-imx8mn.c @@ -323,8 +323,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) void __iomem *base; int ret; - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, - IMX8MN_CLK_END), GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, IMX8MN_CLK_END); if (WARN_ON(!clk_hw_data)) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8mp-audiomix.c b/drivers/clk/imx/clk-imx8mp-audiomix.c index 2225796a9c08f7..57de091a93cfe1 100644 --- a/drivers/clk/imx/clk-imx8mp-audiomix.c +++ b/drivers/clk/imx/clk-imx8mp-audiomix.c @@ -278,9 +278,8 @@ static int clk_imx8mp_audiomix_probe(struct platform_device *pdev) struct clk_hw *hw; int i, ret; - priv = devm_kzalloc(dev, - struct_size(priv, clk_data.hws, IMX8MP_CLK_AUDIOMIX_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, clk_data.hws, + IMX8MP_CLK_AUDIOMIX_END); if (!priv) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c index fe6dac70f1a15b..c621beb1fa0a65 100644 --- a/drivers/clk/imx/clk-imx8mp.c +++ b/drivers/clk/imx/clk-imx8mp.c @@ -565,7 +565,7 @@ static int imx8mp_clocks_probe(struct platform_device *pdev) if (WARN_ON(IS_ERR(ccm_base))) return PTR_ERR(ccm_base); - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, IMX8MP_CLK_END); if (WARN_ON(!clk_hw_data)) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c index cedc8a02aa1f0a..a1f34e05ef7735 100644 --- a/drivers/clk/imx/clk-imx8mq.c +++ b/drivers/clk/imx/clk-imx8mq.c @@ -288,7 +288,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) void __iomem *base; int err; - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MQ_CLK_END), GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, IMX8MQ_CLK_END); if (WARN_ON(!clk_hw_data)) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8qxp-lpcg.c b/drivers/clk/imx/clk-imx8qxp-lpcg.c index f0cf6cf9189926..9ad016106b1e85 100644 --- a/drivers/clk/imx/clk-imx8qxp-lpcg.c +++ b/drivers/clk/imx/clk-imx8qxp-lpcg.c @@ -208,8 +208,8 @@ static int imx_lpcg_parse_clks_from_dt(struct platform_device *pdev, * And the cost is very limited few pointers. */ - clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hws, - IMX_LPCG_MAX_CLKS), GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, + IMX_LPCG_MAX_CLKS); if (!clk_data) return -ENOMEM; @@ -323,8 +323,8 @@ static int imx8qxp_lpcg_clk_probe(struct platform_device *pdev) if (!base) return -ENOMEM; - clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hws, - ss_lpcg->num_max), GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, + ss_lpcg->num_max); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8ulp-sim-lpav.c b/drivers/clk/imx/clk-imx8ulp-sim-lpav.c index 990c95b89b75c6..0607ca8a4f0e53 100644 --- a/drivers/clk/imx/clk-imx8ulp-sim-lpav.c +++ b/drivers/clk/imx/clk-imx8ulp-sim-lpav.c @@ -74,9 +74,8 @@ static int clk_imx8ulp_sim_lpav_probe(struct platform_device *pdev) struct clk_hw *hw; int i, ret; - data = devm_kzalloc(&pdev->dev, - struct_size(data, clk_data.hws, ARRAY_SIZE(gates)), - GFP_KERNEL); + data = devm_kzalloc_flex(&pdev->dev, *data, clk_data.hws, + ARRAY_SIZE(gates)); if (!data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx8ulp.c b/drivers/clk/imx/clk-imx8ulp.c index 535b6364ca7e17..a2ac3b83711567 100644 --- a/drivers/clk/imx/clk-imx8ulp.c +++ b/drivers/clk/imx/clk-imx8ulp.c @@ -127,7 +127,7 @@ static int imx8ulp_pcc_reset_init(struct platform_device *pdev, void __iomem *ba struct device *dev = &pdev->dev; struct pcc_reset_dev *pcc_reset; - pcc_reset = devm_kzalloc(dev, sizeof(*pcc_reset), GFP_KERNEL); + pcc_reset = devm_kzalloc_obj(dev, *pcc_reset); if (!pcc_reset) return -ENOMEM; @@ -149,8 +149,7 @@ static int imx8ulp_clk_cgc1_init(struct platform_device *pdev) struct clk_hw **clks; void __iomem *base; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, IMX8ULP_CLK_CGC1_END), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, IMX8ULP_CLK_CGC1_END); if (!clk_data) return -ENOMEM; @@ -233,8 +232,7 @@ static int imx8ulp_clk_cgc2_init(struct platform_device *pdev) struct clk_hw **clks; void __iomem *base; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, IMX8ULP_CLK_CGC2_END), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, IMX8ULP_CLK_CGC2_END); if (!clk_data) return -ENOMEM; @@ -316,8 +314,7 @@ static int imx8ulp_clk_pcc3_init(struct platform_device *pdev) void __iomem *base; int ret; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, IMX8ULP_CLK_PCC3_END), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, IMX8ULP_CLK_PCC3_END); if (!clk_data) return -ENOMEM; @@ -399,8 +396,7 @@ static int imx8ulp_clk_pcc4_init(struct platform_device *pdev) void __iomem *base; int ret; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, IMX8ULP_CLK_PCC4_END), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, IMX8ULP_CLK_PCC4_END); if (!clk_data) return -ENOMEM; @@ -454,8 +450,7 @@ static int imx8ulp_clk_pcc5_init(struct platform_device *pdev) void __iomem *base; int ret; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, IMX8ULP_CLK_PCC5_END), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, IMX8ULP_CLK_PCC5_END); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c index c5f358a75f307b..1f10833659df31 100644 --- a/drivers/clk/imx/clk-imx93.c +++ b/drivers/clk/imx/clk-imx93.c @@ -281,8 +281,7 @@ static int imx93_clocks_probe(struct platform_device *pdev) int i, ret; const unsigned long plat = (unsigned long)device_get_match_data(&pdev->dev); - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, - IMX93_CLK_END), GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, IMX93_CLK_END); if (!clk_hw_data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c index bc6957299ceca6..84b6609343b150 100644 --- a/drivers/clk/imx/clk-imx95-blk-ctl.c +++ b/drivers/clk/imx/clk-imx95-blk-ctl.c @@ -370,7 +370,7 @@ static int imx95_bc_probe(struct platform_device *pdev) void __iomem *base; int i, ret; - bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL); + bc = devm_kzalloc_obj(dev, *bc); if (!bc) return -ENOMEM; bc->dev = dev; @@ -397,8 +397,8 @@ static int imx95_bc_probe(struct platform_device *pdev) if (!bc->pdata) return devm_of_platform_populate(dev); - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, bc->pdata->num_clks), - GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, + bc->pdata->num_clks); if (!clk_hw_data) return -ENOMEM; diff --git a/drivers/clk/imx/clk-imxrt1050.c b/drivers/clk/imx/clk-imxrt1050.c index efd1ac9d8eeb76..db152c66d66f14 100644 --- a/drivers/clk/imx/clk-imxrt1050.c +++ b/drivers/clk/imx/clk-imxrt1050.c @@ -42,8 +42,8 @@ static int imxrt1050_clocks_probe(struct platform_device *pdev) struct device_node *anp; int ret; - clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, - IMXRT1050_CLK_END), GFP_KERNEL); + clk_hw_data = devm_kzalloc_flex(dev, *clk_hw_data, hws, + IMXRT1050_CLK_END); if (WARN_ON(!clk_hw_data)) return -ENOMEM; diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c index 9d2094bd48e3b0..967f779003587d 100644 --- a/drivers/clk/keystone/sci-clk.c +++ b/drivers/clk/keystone/sci-clk.c @@ -493,9 +493,8 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider) gap_size = 0; if (num_clks == max_clks) { - tmp_clks = devm_kmalloc_array(dev, max_clks + 64, - sizeof(sci_clk), - GFP_KERNEL); + tmp_clks = devm_kmalloc_objs(dev, sci_clk, + max_clks + 64); memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk)); if (max_clks) devm_kfree(dev, clks); @@ -503,7 +502,7 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider) clks = tmp_clks; } - sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), GFP_KERNEL); + sci_clk = devm_kzalloc_obj(dev, *sci_clk); if (!sci_clk) return -ENOMEM; sci_clk->dev_id = dev_id; @@ -581,8 +580,7 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) break; if (args.args_count == 2 && args.np == dev->of_node) { - sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), - GFP_KERNEL); + sci_clk = devm_kzalloc_obj(dev, *sci_clk); if (!sci_clk) return -ENOMEM; @@ -630,9 +628,8 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) continue; } - sci_clk = devm_kzalloc(dev, - sizeof(*sci_clk), - GFP_KERNEL); + sci_clk = devm_kzalloc_obj(dev, + *sci_clk); if (!sci_clk) return -ENOMEM; sci_clk->dev_id = args.args[0]; @@ -650,8 +647,7 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) list_sort(NULL, &clks, _cmp_sci_clk_list); - provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk), - GFP_KERNEL); + provider->clocks = devm_kmalloc_objs(dev, sci_clk, num_clks); if (!provider->clocks) return -ENOMEM; @@ -695,7 +691,7 @@ static int ti_sci_clk_probe(struct platform_device *pdev) if (IS_ERR(handle)) return PTR_ERR(handle); - provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL); + provider = devm_kzalloc_obj(dev, *provider); if (!provider) return -ENOMEM; diff --git a/drivers/clk/keystone/syscon-clk.c b/drivers/clk/keystone/syscon-clk.c index 338174be41215f..baab59f12be403 100644 --- a/drivers/clk/keystone/syscon-clk.c +++ b/drivers/clk/keystone/syscon-clk.c @@ -71,7 +71,7 @@ static struct clk_hw char *name = NULL; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); @@ -145,8 +145,7 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev) "must specify a parent clock\n"); } - hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks), - GFP_KERNEL); + hw_data = devm_kzalloc_flex(dev, *hw_data, hws, num_clks); if (!hw_data) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8173-mfgtop.c b/drivers/clk/mediatek/clk-mt8173-mfgtop.c index 5669ca9954dc0e..3f4a1320930d9b 100644 --- a/drivers/clk/mediatek/clk-mt8173-mfgtop.c +++ b/drivers/clk/mediatek/clk-mt8173-mfgtop.c @@ -115,7 +115,7 @@ static int clk_mt8173_mfgtop_probe(struct platform_device *pdev) struct mt8173_mfgtop_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c index 140fcf524ce606..14eac8fb970b70 100644 --- a/drivers/clk/mediatek/clk-mt8183.c +++ b/drivers/clk/mediatek/clk-mt8183.c @@ -838,7 +838,7 @@ static int clk_mt8183_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) struct mtk_mux_nb *mfg_mux_nb; int i; - mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); + mfg_mux_nb = devm_kzalloc_obj(dev, *mfg_mux_nb); if (!mfg_mux_nb) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8186-topckgen.c b/drivers/clk/mediatek/clk-mt8186-topckgen.c index 14f1cbdbbd13db..38bb5baa040456 100644 --- a/drivers/clk/mediatek/clk-mt8186-topckgen.c +++ b/drivers/clk/mediatek/clk-mt8186-topckgen.c @@ -687,7 +687,7 @@ static int clk_mt8186_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) struct mtk_mux_nb *mfg_mux_nb; int i; - mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); + mfg_mux_nb = devm_kzalloc_obj(dev, *mfg_mux_nb); if (!mfg_mux_nb) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8188-topckgen.c b/drivers/clk/mediatek/clk-mt8188-topckgen.c index 694d894aaa337d..4abc8161cf51ae 100644 --- a/drivers/clk/mediatek/clk-mt8188-topckgen.c +++ b/drivers/clk/mediatek/clk-mt8188-topckgen.c @@ -1242,7 +1242,7 @@ static int clk_mt8188_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) { struct mtk_mux_nb *mfg_mux_nb; - mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); + mfg_mux_nb = devm_kzalloc_obj(dev, *mfg_mux_nb); if (!mfg_mux_nb) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8192.c b/drivers/clk/mediatek/clk-mt8192.c index a1a7caf557fa45..90ce24c5dcb231 100644 --- a/drivers/clk/mediatek/clk-mt8192.c +++ b/drivers/clk/mediatek/clk-mt8192.c @@ -968,7 +968,7 @@ static int clk_mt8192_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) struct mtk_mux_nb *mfg_mux_nb; int i; - mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); + mfg_mux_nb = devm_kzalloc_obj(dev, *mfg_mux_nb); if (!mfg_mux_nb) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mt8195-topckgen.c b/drivers/clk/mediatek/clk-mt8195-topckgen.c index b2fecd37cfd47c..f91d7f1aecd604 100644 --- a/drivers/clk/mediatek/clk-mt8195-topckgen.c +++ b/drivers/clk/mediatek/clk-mt8195-topckgen.c @@ -1246,7 +1246,7 @@ static int clk_mt8195_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) { struct mtk_mux_nb *mfg_mux_nb; - mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); + mfg_mux_nb = devm_kzalloc_obj(dev, *mfg_mux_nb); if (!mfg_mux_nb) return -ENOMEM; diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 3dfdd3a422f802..009d02255be3af 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -52,8 +52,7 @@ struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, { struct clk_hw_onecell_data *clk_data; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, clk_num); if (!clk_data) return NULL; diff --git a/drivers/clk/mediatek/reset.c b/drivers/clk/mediatek/reset.c index 2e3303975096a4..9fa4caa033065f 100644 --- a/drivers/clk/mediatek/reset.c +++ b/drivers/clk/mediatek/reset.c @@ -142,7 +142,7 @@ int mtk_register_reset_controller_with_dev(struct device *dev, return PTR_ERR(regmap); } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/meson/meson-aoclk.c b/drivers/clk/meson/meson-aoclk.c index 8f6bdea181197c..589e394022e72d 100644 --- a/drivers/clk/meson/meson-aoclk.c +++ b/drivers/clk/meson/meson-aoclk.c @@ -55,7 +55,7 @@ int meson_aoclkc_probe(struct platform_device *pdev) data = container_of(clkc_data, struct meson_aoclk_data, clkc_data); - rstc = devm_kzalloc(dev, sizeof(*rstc), GFP_KERNEL); + rstc = devm_kzalloc_obj(dev, *rstc); if (!rstc) return -ENOMEM; diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/clk-mpfs-ccc.c index 40c17593e5941d..e35ced413f90c5 100644 --- a/drivers/clk/microchip/clk-mpfs-ccc.c +++ b/drivers/clk/microchip/clk-mpfs-ccc.c @@ -234,8 +234,8 @@ static int mpfs_ccc_probe(struct platform_device *pdev) void __iomem *pll_base[ARRAY_SIZE(mpfs_ccc_pll_clks)]; int ret; - clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hw_data.hws, MPFS_CCC_NUM_CLKS), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hw_data.hws, + MPFS_CCC_NUM_CLKS); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/microchip/clk-mpfs.c b/drivers/clk/microchip/clk-mpfs.c index 7f044775aea81b..02fe0153140c9d 100644 --- a/drivers/clk/microchip/clk-mpfs.c +++ b/drivers/clk/microchip/clk-mpfs.c @@ -516,7 +516,7 @@ static int mpfs_clk_probe(struct platform_device *pdev) num_clks = ARRAY_SIZE(mpfs_msspll_clks) + ARRAY_SIZE(mpfs_msspll_out_clks) + ARRAY_SIZE(mpfs_cfg_clks) + ARRAY_SIZE(mpfs_periph_clks) + 1; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hw_data.hws, num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hw_data.hws, num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/microchip/clk-pic32.c b/drivers/clk/microchip/clk-pic32.c index 9d128fba2cdea5..363fe6a1c7fcf2 100644 --- a/drivers/clk/microchip/clk-pic32.c +++ b/drivers/clk/microchip/clk-pic32.c @@ -218,7 +218,7 @@ struct clk *pic32_periph_clk_register(const struct pic32_periph_clk_data *desc, struct pic32_periph_clk *pbclk; struct clk *clk; - pbclk = devm_kzalloc(core->dev, sizeof(*pbclk), GFP_KERNEL); + pbclk = devm_kzalloc_obj(core->dev, *pbclk); if (!pbclk) return ERR_PTR(-ENOMEM); @@ -556,7 +556,7 @@ struct clk *pic32_refo_clk_register(const struct pic32_ref_osc_data *data, struct pic32_ref_osc *refo; struct clk *clk; - refo = devm_kzalloc(core->dev, sizeof(*refo), GFP_KERNEL); + refo = devm_kzalloc_obj(core->dev, *refo); if (!refo) return ERR_PTR(-ENOMEM); @@ -733,7 +733,7 @@ struct clk *pic32_spll_clk_register(const struct pic32_sys_pll_data *data, struct pic32_sys_pll *spll; struct clk *clk; - spll = devm_kzalloc(core->dev, sizeof(*spll), GFP_KERNEL); + spll = devm_kzalloc_obj(core->dev, *spll); if (!spll) return ERR_PTR(-ENOMEM); @@ -921,7 +921,7 @@ struct clk *pic32_sys_clk_register(const struct pic32_sys_clk_data *data, struct pic32_sys_clk *sclk; struct clk *clk; - sclk = devm_kzalloc(core->dev, sizeof(*sclk), GFP_KERNEL); + sclk = devm_kzalloc_obj(core->dev, *sclk); if (!sclk) return ERR_PTR(-ENOMEM); @@ -1003,7 +1003,7 @@ struct clk *pic32_sosc_clk_register(const struct pic32_sec_osc_data *data, { struct pic32_sec_osc *sosc; - sosc = devm_kzalloc(core->dev, sizeof(*sosc), GFP_KERNEL); + sosc = devm_kzalloc_obj(core->dev, *sosc); if (!sosc) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/microchip/clk-pic32mzda.c b/drivers/clk/microchip/clk-pic32mzda.c index e11cbdd982a61b..fc4357ec7103d5 100644 --- a/drivers/clk/microchip/clk-pic32mzda.c +++ b/drivers/clk/microchip/clk-pic32mzda.c @@ -157,7 +157,7 @@ static int pic32mzda_clk_probe(struct platform_device *pdev) struct clk **clks; int nr_clks, i, ret; - cd = devm_kzalloc(&pdev->dev, sizeof(*cd), GFP_KERNEL); + cd = devm_kzalloc_obj(&pdev->dev, *cd); if (!cd) return -ENOMEM; diff --git a/drivers/clk/mmp/clk-audio.c b/drivers/clk/mmp/clk-audio.c index ed27fc796c941d..19233684fbf9bb 100644 --- a/drivers/clk/mmp/clk-audio.c +++ b/drivers/clk/mmp/clk-audio.c @@ -351,10 +351,8 @@ static int mmp2_audio_clk_probe(struct platform_device *pdev) struct mmp2_audio_clk *priv; int ret; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, clk_data.hws, - CLK_AUDIO_NR_CLKS), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, clk_data.hws, + CLK_AUDIO_NR_CLKS); if (!priv) return -ENOMEM; diff --git a/drivers/clk/mmp/clk-pxa1908-apbc.c b/drivers/clk/mmp/clk-pxa1908-apbc.c index 16c1f13bca1f04..85842e9a6cb364 100644 --- a/drivers/clk/mmp/clk-pxa1908-apbc.c +++ b/drivers/clk/mmp/clk-pxa1908-apbc.c @@ -123,7 +123,7 @@ static int pxa1908_apbc_probe(struct platform_device *pdev) { struct pxa1908_clk_unit *pxa_unit; - pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL); + pxa_unit = devm_kzalloc_obj(&pdev->dev, *pxa_unit); if (!pxa_unit) return -ENOMEM; diff --git a/drivers/clk/mmp/clk-pxa1908-apbcp.c b/drivers/clk/mmp/clk-pxa1908-apbcp.c index 4e646e8b7440e5..0383711308f29b 100644 --- a/drivers/clk/mmp/clk-pxa1908-apbcp.c +++ b/drivers/clk/mmp/clk-pxa1908-apbcp.c @@ -70,7 +70,7 @@ static int pxa1908_apbcp_probe(struct platform_device *pdev) { struct pxa1908_clk_unit *pxa_unit; - pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL); + pxa_unit = devm_kzalloc_obj(&pdev->dev, *pxa_unit); if (!pxa_unit) return -ENOMEM; diff --git a/drivers/clk/mmp/clk-pxa1908-apmu.c b/drivers/clk/mmp/clk-pxa1908-apmu.c index 7594a495a0093e..cf71d5d47d72d4 100644 --- a/drivers/clk/mmp/clk-pxa1908-apmu.c +++ b/drivers/clk/mmp/clk-pxa1908-apmu.c @@ -88,7 +88,7 @@ static int pxa1908_apmu_probe(struct platform_device *pdev) struct pxa1908_clk_unit *pxa_unit; struct auxiliary_device *adev; - pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL); + pxa_unit = devm_kzalloc_obj(&pdev->dev, *pxa_unit); if (!pxa_unit) return -ENOMEM; diff --git a/drivers/clk/mmp/clk-pxa1908-mpmu.c b/drivers/clk/mmp/clk-pxa1908-mpmu.c index 90b4b248857406..8b6e77f0d00f63 100644 --- a/drivers/clk/mmp/clk-pxa1908-mpmu.c +++ b/drivers/clk/mmp/clk-pxa1908-mpmu.c @@ -77,7 +77,7 @@ static int pxa1908_mpmu_probe(struct platform_device *pdev) { struct pxa1908_clk_unit *pxa_unit; - pxa_unit = devm_kzalloc(&pdev->dev, sizeof(*pxa_unit), GFP_KERNEL); + pxa_unit = devm_kzalloc_obj(&pdev->dev, *pxa_unit); if (!pxa_unit) return -ENOMEM; diff --git a/drivers/clk/mstar/clk-msc313-cpupll.c b/drivers/clk/mstar/clk-msc313-cpupll.c index 3e643be02fe2a7..56a5723ca79af7 100644 --- a/drivers/clk/mstar/clk-msc313-cpupll.c +++ b/drivers/clk/mstar/clk-msc313-cpupll.c @@ -187,7 +187,7 @@ static int msc313_cpupll_probe(struct platform_device *pdev) struct msc313_cpupll *cpupll; int ret; - cpupll = devm_kzalloc(&pdev->dev, sizeof(*cpupll), GFP_KERNEL); + cpupll = devm_kzalloc_obj(&pdev->dev, *cpupll); if (!cpupll) return -ENOMEM; diff --git a/drivers/clk/mstar/clk-msc313-mpll.c b/drivers/clk/mstar/clk-msc313-mpll.c index bd45aa0aec0116..d9ccce5bc99f35 100644 --- a/drivers/clk/mstar/clk-msc313-mpll.c +++ b/drivers/clk/mstar/clk-msc313-mpll.c @@ -79,7 +79,7 @@ static int msc313_mpll_probe(struct platform_device *pdev) struct clk_hw *divhw; int ret, i; - mpll = devm_kzalloc(dev, sizeof(*mpll), GFP_KERNEL); + mpll = devm_kzalloc_obj(dev, *mpll); if (!mpll) return -ENOMEM; @@ -104,8 +104,8 @@ static int msc313_mpll_probe(struct platform_device *pdev) if (IS_ERR(mpll->loop_div_second)) return PTR_ERR(mpll->loop_div_second); - mpll->clk_data = devm_kzalloc(dev, struct_size(mpll->clk_data, hws, - NUMOUTPUTS), GFP_KERNEL); + mpll->clk_data = devm_kzalloc_flex(dev, *mpll->clk_data, hws, + NUMOUTPUTS); if (!mpll->clk_data) return -ENOMEM; diff --git a/drivers/clk/mvebu/ap-cpu-clk.c b/drivers/clk/mvebu/ap-cpu-clk.c index b1c6fceb91b29d..467ecbb1a84fb2 100644 --- a/drivers/clk/mvebu/ap-cpu-clk.c +++ b/drivers/clk/mvebu/ap-cpu-clk.c @@ -273,14 +273,11 @@ static int ap_cpu_clock_probe(struct platform_device *pdev) * DFS for AP806 is controlled per cluster (2 CPUs per cluster), * so allocate structs per cluster */ - ap_cpu_clk = devm_kcalloc(dev, nclusters, sizeof(*ap_cpu_clk), - GFP_KERNEL); + ap_cpu_clk = devm_kzalloc_objs(dev, *ap_cpu_clk, nclusters); if (!ap_cpu_clk) return -ENOMEM; - ap_cpu_data = devm_kzalloc(dev, struct_size(ap_cpu_data, hws, - nclusters), - GFP_KERNEL); + ap_cpu_data = devm_kzalloc_flex(dev, *ap_cpu_data, hws, nclusters); if (!ap_cpu_data) return -ENOMEM; diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c index 3123771b9c9980..336e5db0da8123 100644 --- a/drivers/clk/mvebu/armada-37xx-periph.c +++ b/drivers/clk/mvebu/armada-37xx-periph.c @@ -745,14 +745,12 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev) while (data[num_periph].name) num_periph++; - driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(dev, *driver_data); if (!driver_data) return -ENOMEM; - driver_data->hw_data = devm_kzalloc(dev, - struct_size(driver_data->hw_data, - hws, num_periph), - GFP_KERNEL); + driver_data->hw_data = devm_kzalloc_flex(dev, *driver_data->hw_data, + hws, num_periph); if (!driver_data->hw_data) return -ENOMEM; driver_data->hw_data->num = num_periph; diff --git a/drivers/clk/mvebu/armada-37xx-tbg.c b/drivers/clk/mvebu/armada-37xx-tbg.c index 1a16f9c0b1d81c..efc98d0094867f 100644 --- a/drivers/clk/mvebu/armada-37xx-tbg.c +++ b/drivers/clk/mvebu/armada-37xx-tbg.c @@ -88,9 +88,7 @@ static int armada_3700_tbg_clock_probe(struct platform_device *pdev) void __iomem *reg; int i; - hw_tbg_data = devm_kzalloc(&pdev->dev, - struct_size(hw_tbg_data, hws, NUM_TBG), - GFP_KERNEL); + hw_tbg_data = devm_kzalloc_flex(&pdev->dev, *hw_tbg_data, hws, NUM_TBG); if (!hw_tbg_data) return -ENOMEM; hw_tbg_data->num = NUM_TBG; diff --git a/drivers/clk/mvebu/armada-37xx-xtal.c b/drivers/clk/mvebu/armada-37xx-xtal.c index ca88e5e78b0671..43ec90b391ab4f 100644 --- a/drivers/clk/mvebu/armada-37xx-xtal.c +++ b/drivers/clk/mvebu/armada-37xx-xtal.c @@ -27,7 +27,7 @@ static int armada_3700_xtal_clock_probe(struct platform_device *pdev) u32 reg; int ret; - xtal_hw = devm_kzalloc(&pdev->dev, sizeof(*xtal_hw), GFP_KERNEL); + xtal_hw = devm_kzalloc_obj(&pdev->dev, *xtal_hw); if (!xtal_hw) return -ENOMEM; diff --git a/drivers/clk/mvebu/cp110-system-controller.c b/drivers/clk/mvebu/cp110-system-controller.c index fa95eb7197afb8..02e2b82c60a12c 100644 --- a/drivers/clk/mvebu/cp110-system-controller.c +++ b/drivers/clk/mvebu/cp110-system-controller.c @@ -255,9 +255,8 @@ static int cp110_syscon_common_probe(struct platform_device *pdev, if (ret) return ret; - cp110_clk_data = devm_kzalloc(dev, struct_size(cp110_clk_data, hws, - CP110_CLK_NUM), - GFP_KERNEL); + cp110_clk_data = devm_kzalloc_flex(dev, *cp110_clk_data, hws, + CP110_CLK_NUM); if (!cp110_clk_data) return -ENOMEM; cp110_clk_data->num = CP110_CLK_NUM; diff --git a/drivers/clk/nuvoton/clk-ma35d1-divider.c b/drivers/clk/nuvoton/clk-ma35d1-divider.c index e992e7c3034197..b70f460c48d530 100644 --- a/drivers/clk/nuvoton/clk-ma35d1-divider.c +++ b/drivers/clk/nuvoton/clk-ma35d1-divider.c @@ -90,14 +90,14 @@ struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name, int ret; int i; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); max_div = clk_div_mask(width) + 1; min_div = 1; - table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL); + table = devm_kzalloc_objs(dev, *table, max_div + 1); if (!table) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/nuvoton/clk-ma35d1-pll.c b/drivers/clk/nuvoton/clk-ma35d1-pll.c index c7c0dc91a012c7..8b7133284d4612 100644 --- a/drivers/clk/nuvoton/clk-ma35d1-pll.c +++ b/drivers/clk/nuvoton/clk-ma35d1-pll.c @@ -336,7 +336,7 @@ struct clk_hw *ma35d1_reg_clk_pll(struct device *dev, u32 id, u8 u8mode, const c struct clk_hw *hw; int ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c index c914079cee2d44..e95f72bb810328 100644 --- a/drivers/clk/nuvoton/clk-ma35d1.c +++ b/drivers/clk/nuvoton/clk-ma35d1.c @@ -467,9 +467,8 @@ static int ma35d1_clocks_probe(struct platform_device *pdev) u32 pllmode[PLL_MAX_NUM]; int ret; - ma35d1_hw_data = devm_kzalloc(dev, - struct_size(ma35d1_hw_data, hws, MA35D1_CLK_COUNT), - GFP_KERNEL); + ma35d1_hw_data = devm_kzalloc_flex(dev, *ma35d1_hw_data, hws, + MA35D1_CLK_COUNT); if (!ma35d1_hw_data) return -ENOMEM; diff --git a/drivers/clk/qcom/a53-pll.c b/drivers/clk/qcom/a53-pll.c index 0549b214fcfc8b..062158e9f634c7 100644 --- a/drivers/clk/qcom/a53-pll.c +++ b/drivers/clk/qcom/a53-pll.c @@ -59,7 +59,7 @@ static struct pll_freq_tbl *qcom_a53pll_get_freq_tbl(struct device *dev) if (count <= 0) return NULL; - freq_tbl = devm_kcalloc(dev, count + 1, sizeof(*freq_tbl), GFP_KERNEL); + freq_tbl = devm_kzalloc_objs(dev, *freq_tbl, count + 1); if (!freq_tbl) return NULL; @@ -94,7 +94,7 @@ static int qcom_a53pll_probe(struct platform_device *pdev) struct clk_init_data init = { }; int ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return -ENOMEM; diff --git a/drivers/clk/qcom/apcs-msm8916.c b/drivers/clk/qcom/apcs-msm8916.c index ef31386831ebd2..5365b0d8b51849 100644 --- a/drivers/clk/qcom/apcs-msm8916.c +++ b/drivers/clk/qcom/apcs-msm8916.c @@ -58,7 +58,7 @@ static int qcom_apcs_msm8916_clk_probe(struct platform_device *pdev) return ret; } - a53cc = devm_kzalloc(dev, sizeof(*a53cc), GFP_KERNEL); + a53cc = devm_kzalloc_obj(dev, *a53cc); if (!a53cc) return -ENOMEM; diff --git a/drivers/clk/qcom/apcs-sdx55.c b/drivers/clk/qcom/apcs-sdx55.c index 90dd1f1855c21f..9afc932f16918f 100644 --- a/drivers/clk/qcom/apcs-sdx55.c +++ b/drivers/clk/qcom/apcs-sdx55.c @@ -61,7 +61,7 @@ static int qcom_apcs_sdx55_clk_probe(struct platform_device *pdev) return -ENODEV; } - a7cc = devm_kzalloc(dev, sizeof(*a7cc), GFP_KERNEL); + a7cc = devm_kzalloc_obj(dev, *a7cc); if (!a7cc) return -ENOMEM; diff --git a/drivers/clk/qcom/apss-ipq6018.c b/drivers/clk/qcom/apss-ipq6018.c index c89d126ebac3c6..32347e6d8775da 100644 --- a/drivers/clk/qcom/apss-ipq6018.c +++ b/drivers/clk/qcom/apss-ipq6018.c @@ -132,9 +132,8 @@ static int apss_ipq6018_probe(struct platform_device *pdev) case QCOM_ID_IPQ5332: case QCOM_ID_IPQ5322: case QCOM_ID_IPQ5300: - cpu_clk_notifier = devm_kzalloc(&pdev->dev, - sizeof(*cpu_clk_notifier), - GFP_KERNEL); + cpu_clk_notifier = devm_kzalloc_obj(&pdev->dev, + *cpu_clk_notifier); if (!cpu_clk_notifier) return -ENOMEM; diff --git a/drivers/clk/qcom/clk-cpu-8996.c b/drivers/clk/qcom/clk-cpu-8996.c index 21d13c0841ed05..3e9042ec398afc 100644 --- a/drivers/clk/qcom/clk-cpu-8996.c +++ b/drivers/clk/qcom/clk-cpu-8996.c @@ -586,7 +586,7 @@ static int qcom_cpu_clk_msm8996_driver_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - data = devm_kzalloc(dev, struct_size(data, hws, 2), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, hws, 2); if (!data) return -ENOMEM; data->num = 2; diff --git a/drivers/clk/qcom/clk-ref.c b/drivers/clk/qcom/clk-ref.c index 3efdf6749770d4..91113743e0bed0 100644 --- a/drivers/clk/qcom/clk-ref.c +++ b/drivers/clk/qcom/clk-ref.c @@ -123,9 +123,9 @@ static int qcom_clk_ref_register(struct device *dev, struct regmap *regmap, clk_ref->desc = *desc; if (clk_ref->desc.num_regulators) { - clk_ref->regulators = devm_kcalloc(dev, clk_ref->desc.num_regulators, - sizeof(*clk_ref->regulators), - GFP_KERNEL); + clk_ref->regulators = devm_kzalloc_objs(dev, + *clk_ref->regulators, + clk_ref->desc.num_regulators); if (!clk_ref->regulators) return -ENOMEM; @@ -188,8 +188,7 @@ int qcom_clk_ref_probe(struct platform_device *pdev, if (IS_ERR(regmap)) return PTR_ERR(regmap); - provider = devm_kzalloc(dev, struct_size(provider, refs, num_clk_refs), - GFP_KERNEL); + provider = devm_kzalloc_flex(dev, *provider, refs, num_clk_refs); if (!provider) return -ENOMEM; diff --git a/drivers/clk/qcom/clk-rpm.c b/drivers/clk/qcom/clk-rpm.c index 74f569b58017b1..44599579dfaec8 100644 --- a/drivers/clk/qcom/clk-rpm.c +++ b/drivers/clk/qcom/clk-rpm.c @@ -533,7 +533,7 @@ static int rpm_clk_probe(struct platform_device *pdev) rpm_clks = desc->clks; num_clks = desc->num_clks; - rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc), GFP_KERNEL); + rcc = devm_kzalloc_obj(&pdev->dev, *rcc); if (!rcc) return -ENOMEM; diff --git a/drivers/clk/qcom/clk-spmi-pmic-div.c b/drivers/clk/qcom/clk-spmi-pmic-div.c index 3e2ac6745325a1..5025011301fae6 100644 --- a/drivers/clk/qcom/clk-spmi-pmic-div.c +++ b/drivers/clk/qcom/clk-spmi-pmic-div.c @@ -230,7 +230,7 @@ static int spmi_pmic_clkdiv_probe(struct platform_device *pdev) if (!nclks) return -EINVAL; - cc = devm_kzalloc(dev, struct_size(cc, clks, nclks), GFP_KERNEL); + cc = devm_kzalloc_flex(dev, *cc, clks, nclks); if (!cc) return -ENOMEM; cc->nclks = nclks; diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c index 08fd62ac780d3f..e5c2dad23e3f4d 100644 --- a/drivers/clk/qcom/common.c +++ b/drivers/clk/qcom/common.c @@ -167,7 +167,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path, } if (!node) { - fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL); + fixed = devm_kzalloc_obj(dev, *fixed); if (!fixed) return -ENOMEM; @@ -184,7 +184,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path, of_node_put(node); if (add_factor) { - factor = devm_kzalloc(dev, sizeof(*factor), GFP_KERNEL); + factor = devm_kzalloc_obj(dev, *factor); if (!factor) return -ENOMEM; @@ -268,7 +268,7 @@ static int qcom_cc_icc_register(struct device *dev, if (!desc->icc_hws) return 0; - icd = devm_kcalloc(dev, desc->num_icc_hws, sizeof(*icd), GFP_KERNEL); + icd = devm_kzalloc_objs(dev, *icd, desc->num_icc_hws); if (!icd) return -ENOMEM; @@ -333,7 +333,7 @@ int qcom_cc_really_probe(struct device *dev, size_t num_clk_hws = desc->num_clk_hws; struct clk_hw **clk_hws = desc->clk_hws; - cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL); + cc = devm_kzalloc_obj(dev, *cc); if (!cc) return -ENOMEM; @@ -372,7 +372,7 @@ int qcom_cc_really_probe(struct device *dev, goto put_rpm; if (desc->gdscs && desc->num_gdscs) { - scd = devm_kzalloc(dev, sizeof(*scd), GFP_KERNEL); + scd = devm_kzalloc_obj(dev, *scd); if (!scd) { ret = -ENOMEM; goto put_rpm; diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c index b99d70149af34e..be9c14eb7b064f 100644 --- a/drivers/clk/qcom/gdsc.c +++ b/drivers/clk/qcom/gdsc.c @@ -603,12 +603,11 @@ int gdsc_register(struct gdsc_desc *desc, struct gdsc **scs = desc->scs; size_t num = desc->num; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; - data->domains = devm_kcalloc(dev, num, sizeof(*data->domains), - GFP_KERNEL); + data->domains = devm_kzalloc_objs(dev, *data->domains, num); if (!data->domains) return -ENOMEM; diff --git a/drivers/clk/qcom/hfpll.c b/drivers/clk/qcom/hfpll.c index 385964196185a3..c7373bbb6c3a83 100644 --- a/drivers/clk/qcom/hfpll.c +++ b/drivers/clk/qcom/hfpll.c @@ -121,7 +121,7 @@ static int qcom_hfpll_probe(struct platform_device *pdev) int ret; struct clk_parent_data pdata = { .index = 0 }; - h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL); + h = devm_kzalloc_obj(dev, *h); if (!h) return -ENOMEM; diff --git a/drivers/clk/qcom/ipq-cmn-pll.c b/drivers/clk/qcom/ipq-cmn-pll.c index 74a2043632b7df..f4d63258dc2bca 100644 --- a/drivers/clk/qcom/ipq-cmn-pll.c +++ b/drivers/clk/qcom/ipq-cmn-pll.c @@ -443,7 +443,7 @@ static struct clk_hw *ipq_cmn_pll_clk_hw_register(struct platform_device *pdev) if (IS_ERR(regmap)) return ERR_CAST(regmap); - cmn_pll = devm_kzalloc(dev, sizeof(*cmn_pll), GFP_KERNEL); + cmn_pll = devm_kzalloc_obj(dev, *cmn_pll); if (!cmn_pll) return ERR_PTR(-ENOMEM); @@ -471,7 +471,7 @@ static struct clk_hw *ipq_cmn_pll_regmap_div_register(struct device *dev, struct clk_regmap_div *div_clk; int ret; - div_clk = devm_kzalloc(dev, sizeof(*div_clk), GFP_KERNEL); + div_clk = devm_kzalloc_obj(dev, *div_clk); if (!div_clk) return ERR_PTR(-ENOMEM); @@ -617,7 +617,7 @@ static struct clk_hw *ipq_cmn_pll_pon_clk_register(struct device *dev, struct clk_regmap *pon_clk; int ret; - pon_clk = devm_kzalloc(dev, sizeof(*pon_clk), GFP_KERNEL); + pon_clk = devm_kzalloc_obj(dev, *pon_clk); if (!pon_clk) return ERR_PTR(-ENOMEM); @@ -728,7 +728,7 @@ static struct clk_hw *ipq_cmn_pll_ephy_raw_register(struct device *dev, struct clk_init_data init = {}; int ret; - ephy_raw_clk = devm_kzalloc(dev, sizeof(*ephy_raw_clk), GFP_KERNEL); + ephy_raw_clk = devm_kzalloc_obj(dev, *ephy_raw_clk); if (!ephy_raw_clk) return ERR_PTR(-ENOMEM); @@ -772,7 +772,7 @@ static struct clk_hw *ipq_cmn_pll_register_fixed_gate(struct device *dev, struct clk_init_data init = {}; int ret; - gate_clk = devm_kzalloc(dev, sizeof(*gate_clk), GFP_KERNEL); + gate_clk = devm_kzalloc_obj(dev, *gate_clk); if (!gate_clk) return ERR_PTR(-ENOMEM); @@ -819,8 +819,7 @@ static int ipq_cmn_pll_register_clks(struct platform_device *pdev) for (p = fixed_clk; p->name; p++) num_clks++; - hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks + 1), - GFP_KERNEL); + hw_data = devm_kzalloc_flex(dev, *hw_data, hws, num_clks + 1); if (!hw_data) return -ENOMEM; diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c index f29d6dd1f3ac1b..37fe990ef6b834 100644 --- a/drivers/clk/qcom/krait-cc.c +++ b/drivers/clk/qcom/krait-cc.c @@ -92,7 +92,7 @@ krait_add_div(struct device *dev, int id, const char *s, unsigned int offset) char *parent_name; int cpu, ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -158,7 +158,7 @@ krait_add_sec_mux(struct device *dev, int id, const char *s, struct clk_hw *clk; char *parent_name; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); @@ -239,7 +239,7 @@ krait_add_pri_mux(struct device *dev, struct clk_hw *hfpll_div, struct clk_hw *s struct clk_hw *clk; char *hfpll_name; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); @@ -365,7 +365,7 @@ static int krait_cc_probe(struct platform_device *pdev) } /* Krait configurations have at most 4 CPUs and one L2 */ - clks = devm_kcalloc(dev, clks_max, sizeof(*clks), GFP_KERNEL); + clks = devm_kzalloc_objs(dev, *clks, clks_max); if (!clks) return -ENOMEM; diff --git a/drivers/clk/qcom/lpass-gfm-sm8250.c b/drivers/clk/qcom/lpass-gfm-sm8250.c index 65d380e30eed98..13115a316c0508 100644 --- a/drivers/clk/qcom/lpass-gfm-sm8250.c +++ b/drivers/clk/qcom/lpass-gfm-sm8250.c @@ -243,7 +243,7 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev) if (!data) return -EINVAL; - cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL); + cc = devm_kzalloc_obj(dev, *cc); if (!cc) return -ENOMEM; diff --git a/drivers/clk/ralink/clk-mt7621.c b/drivers/clk/ralink/clk-mt7621.c index 350c2b6fb46f2a..f09d6527c9fdba 100644 --- a/drivers/clk/ralink/clk-mt7621.c +++ b/drivers/clk/ralink/clk-mt7621.c @@ -468,7 +468,7 @@ static int mt7621_reset_init(struct device *dev, struct regmap *sysc) { struct mt7621_rst *rst_data; - rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL); + rst_data = devm_kzalloc_obj(dev, *rst_data); if (!rst_data) return -ENOMEM; @@ -491,7 +491,7 @@ static int mt7621_clk_probe(struct platform_device *pdev) struct mt7621_clk_priv *priv; int ret, i, count; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -517,8 +517,7 @@ static int mt7621_clk_probe(struct platform_device *pdev) count = ARRAY_SIZE(mt7621_clks_base) + ARRAY_SIZE(mt7621_fixed_clks) + ARRAY_SIZE(mt7621_gates); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, count); if (!clk_data) return -ENOMEM; clk_data->num = count; diff --git a/drivers/clk/ralink/clk-mtmips.c b/drivers/clk/ralink/clk-mtmips.c index 370e5c36863da1..ef0e14f25a327f 100644 --- a/drivers/clk/ralink/clk-mtmips.c +++ b/drivers/clk/ralink/clk-mtmips.c @@ -1079,7 +1079,7 @@ static int mtmips_reset_init(struct device *dev, struct regmap *sysc) { struct mtmips_rst *rst_data; - rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL); + rst_data = devm_kzalloc_obj(dev, *rst_data); if (!rst_data) return -ENOMEM; @@ -1101,7 +1101,7 @@ static int mtmips_clk_probe(struct platform_device *pdev) struct mtmips_clk_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/renesas/clk-div6.c b/drivers/clk/renesas/clk-div6.c index c23489900e96aa..dbc5714c148cfd 100644 --- a/drivers/clk/renesas/clk-div6.c +++ b/drivers/clk/renesas/clk-div6.c @@ -332,8 +332,7 @@ static void __init cpg_div6_clock_init(struct device_node *np) return; } - parent_names = kmalloc_array(num_parents, sizeof(*parent_names), - GFP_KERNEL); + parent_names = kmalloc_objs(*parent_names, num_parents); if (!parent_names) return; diff --git a/drivers/clk/renesas/clk-vbattb.c b/drivers/clk/renesas/clk-vbattb.c index bd97a68bed1b4a..58dac430b698ba 100644 --- a/drivers/clk/renesas/clk-vbattb.c +++ b/drivers/clk/renesas/clk-vbattb.c @@ -100,11 +100,11 @@ static int vbattb_clk_probe(struct platform_device *pdev) if (ret) return ret; - vbclk = devm_kzalloc(dev, sizeof(*vbclk), GFP_KERNEL); + vbclk = devm_kzalloc_obj(dev, *vbclk); if (!vbclk) return -ENOMEM; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, num_clks); if (!clk_data) return -ENOMEM; clk_data->num = num_clks; diff --git a/drivers/clk/renesas/r8a78000-cpg.c b/drivers/clk/renesas/r8a78000-cpg.c index b8024e76743ea5..6fee05a899f47b 100644 --- a/drivers/clk/renesas/r8a78000-cpg.c +++ b/drivers/clk/renesas/r8a78000-cpg.c @@ -126,7 +126,7 @@ static int r8a78000_cpg_probe(struct platform_device *pdev) if (!map) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c index 3df3f2b2c6de72..871a915c24b8b6 100644 --- a/drivers/clk/renesas/r9a06g032-clocks.c +++ b/drivers/clk/renesas/r9a06g032-clocks.c @@ -805,7 +805,7 @@ static int r9a06g032_add_clk_domain(struct device *dev) struct device_node *np = dev->of_node; struct generic_pm_domain *pd; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; @@ -1318,9 +1318,8 @@ static int __init r9a06g032_clocks_probe(struct platform_device *pdev) struct regbit uart_group_sel[2]; int error; - clocks = devm_kzalloc(dev, sizeof(*clocks), GFP_KERNEL); - clks = devm_kcalloc(dev, R9A06G032_CLOCK_COUNT, sizeof(struct clk *), - GFP_KERNEL); + clocks = devm_kzalloc_obj(dev, *clocks); + clks = devm_kzalloc_objs(dev, struct clk *, R9A06G032_CLOCK_COUNT); if (!clocks || !clks) return -ENOMEM; diff --git a/drivers/clk/renesas/r9a09g077-cpg.c b/drivers/clk/renesas/r9a09g077-cpg.c index 5a0e7df1eb06c3..7dd1f44b26e365 100644 --- a/drivers/clk/renesas/r9a09g077-cpg.c +++ b/drivers/clk/renesas/r9a09g077-cpg.c @@ -563,12 +563,12 @@ r9a09g077_cpg_fselxspi_div_clk_register(struct device *dev, if (IS_ERR(parent)) return ERR_CAST(parent); - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); if (!xspi_div_ops) { - xspi_div_ops = devm_kzalloc(dev, sizeof(*xspi_div_ops), GFP_KERNEL); + xspi_div_ops = devm_kzalloc_obj(dev, *xspi_div_ops); if (!xspi_div_ops) return ERR_PTR(-ENOMEM); memcpy(xspi_div_ops, &clk_divider_ops, @@ -714,7 +714,7 @@ r9a09g077_cpg_pll3_clk_register(struct device *dev, if (IS_ERR(parent)) return ERR_CAST(parent); - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return ERR_PTR(-ENOMEM); @@ -843,7 +843,7 @@ r9a09g077_cpg_lcdc_div_clk_register(struct device *dev, if (IS_ERR(parent)) return ERR_CAST(parent); - clk_hw_data = devm_kzalloc(dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -991,7 +991,7 @@ static int r9a09g077_post_init(struct device *dev, struct cpg_mssr_pub *pub) if (!regmap_cfg) return -ENOMEM; - sysc_reg = devm_kzalloc(dev, sizeof(*sysc_reg), GFP_KERNEL); + sysc_reg = devm_kzalloc_obj(dev, *sysc_reg); if (!sysc_reg) return -ENOMEM; diff --git a/drivers/clk/renesas/rcar-usb2-clock-sel.c b/drivers/clk/renesas/rcar-usb2-clock-sel.c index 421ae973ea8e0d..2703004453c011 100644 --- a/drivers/clk/renesas/rcar-usb2-clock-sel.c +++ b/drivers/clk/renesas/rcar-usb2-clock-sel.c @@ -142,7 +142,7 @@ static int rcar_usb2_clock_sel_probe(struct platform_device *pdev) struct clk_init_data init = {}; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index ffac4409a16184..1ed11ce4a04c8b 100644 --- a/drivers/clk/renesas/renesas-cpg-mssr.c +++ b/drivers/clk/renesas/renesas-cpg-mssr.c @@ -685,7 +685,7 @@ static int __init cpg_mssr_add_clk_domain(struct device *dev, size_t pm_size = num_core_pm_clks * sizeof(core_pm_clks[0]); int ret; - pd = devm_kzalloc(dev, struct_size(pd, core_pm_clks, num_core_pm_clks), GFP_KERNEL); + pd = devm_kzalloc_flex(dev, *pd, core_pm_clks, num_core_pm_clks); if (!pd) return -ENOMEM; diff --git a/drivers/clk/renesas/rzg2l-cpg.c b/drivers/clk/renesas/rzg2l-cpg.c index f6293c968bcf9a..dc2bcbab18f1bc 100644 --- a/drivers/clk/renesas/rzg2l-cpg.c +++ b/drivers/clk/renesas/rzg2l-cpg.c @@ -343,7 +343,7 @@ static int rzg2l_register_notifier(struct clk_hw *hw, const struct cpg_core_clk if (!core->notifier) return 0; - nb = devm_kzalloc(priv->dev, sizeof(*nb), GFP_KERNEL); + nb = devm_kzalloc_obj(priv->dev, *nb); if (!nb) return -ENOMEM; @@ -428,7 +428,7 @@ rzg3s_cpg_div_clk_register(const struct cpg_core_clk *core, struct rzg2l_cpg_pri parent_name = __clk_get_name(parent); - div_hw_data = devm_kzalloc(priv->dev, sizeof(*div_hw_data), GFP_KERNEL); + div_hw_data = devm_kzalloc_obj(priv->dev, *div_hw_data); if (!div_hw_data) return ERR_PTR(-ENOMEM); @@ -584,7 +584,7 @@ rzg2l_cpg_sd_mux_clk_register(const struct cpg_core_clk *core, struct clk_hw *clk_hw; int ret; - sd_mux_hw_data = devm_kzalloc(priv->dev, sizeof(*sd_mux_hw_data), GFP_KERNEL); + sd_mux_hw_data = devm_kzalloc_obj(priv->dev, *sd_mux_hw_data); if (!sd_mux_hw_data) return ERR_PTR(-ENOMEM); @@ -841,7 +841,7 @@ rzg2l_cpg_dsi_div_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -926,7 +926,7 @@ rzg3l_cpg_lvds_div_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - ff = devm_kzalloc(priv->dev, sizeof(*ff), GFP_KERNEL); + ff = devm_kzalloc_obj(priv->dev, *ff); if (!ff) return ERR_PTR(-ENOMEM); @@ -1041,7 +1041,7 @@ rzg3l_cpg_dsi_div_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -1132,7 +1132,7 @@ rzg2l_cpg_pll5_4_mux_clk_register(const struct cpg_core_clk *core, struct clk_hw *clk_hw; int ret; - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -1266,7 +1266,7 @@ rzg2l_cpg_sipll5_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - sipll5 = devm_kzalloc(priv->dev, sizeof(*sipll5), GFP_KERNEL); + sipll5 = devm_kzalloc_obj(priv->dev, *sipll5); if (!sipll5) return ERR_PTR(-ENOMEM); @@ -1392,7 +1392,7 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return ERR_PTR(-ENOMEM); @@ -1529,7 +1529,7 @@ rzg3l_cpg_dsi_mux_clk_register(const struct cpg_core_clk *core, struct clk_mux *mux_data; int ret; - mux_data = devm_kzalloc(priv->dev, sizeof(*mux_data), GFP_KERNEL); + mux_data = devm_kzalloc_obj(priv->dev, *mux_data); if (!mux_data) return ERR_PTR(-ENOMEM); @@ -2284,7 +2284,7 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod, goto fail; } - clock = devm_kzalloc(dev, sizeof(*clock), GFP_KERNEL); + clock = devm_kzalloc_obj(dev, *clock); if (!clock) { clk = ERR_PTR(-ENOMEM); goto fail; @@ -2314,7 +2314,7 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod, struct mstop *mstop = rzg2l_mod_clock_get_mstop(priv, mod->mstop_conf); if (!mstop) { - mstop = devm_kzalloc(dev, sizeof(*mstop), GFP_KERNEL); + mstop = devm_kzalloc_obj(dev, *mstop); if (!mstop) { clk = ERR_PTR(-ENOMEM); goto fail; @@ -2628,7 +2628,7 @@ static int __init rzg2l_cpg_probe(struct platform_device *pdev) info = of_device_get_match_data(dev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -2641,7 +2641,7 @@ static int __init rzg2l_cpg_probe(struct platform_device *pdev) return PTR_ERR(priv->base); nclks = info->num_total_core_clks + info->num_hw_mod_clks; - clks = devm_kmalloc_array(dev, nclks, sizeof(*clks), GFP_KERNEL); + clks = devm_kmalloc_objs(dev, *clks, nclks); if (!clks) return -ENOMEM; diff --git a/drivers/clk/renesas/rzv2h-cpg.c b/drivers/clk/renesas/rzv2h-cpg.c index 7ce94680c79a29..656cee9c7b649b 100644 --- a/drivers/clk/renesas/rzv2h-cpg.c +++ b/drivers/clk/renesas/rzv2h-cpg.c @@ -348,7 +348,7 @@ rzv2h_cpg_plldsi_div_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -594,7 +594,7 @@ rzv2h_cpg_plldsi_smux_clk_register(const struct cpg_core_clk *core, return ERR_PTR(-EINVAL); } - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -721,7 +721,7 @@ rzv2h_cpg_pll_clk_register(const struct cpg_core_clk *core, if (IS_ERR(parent)) return ERR_CAST(parent); - pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL); + pll_clk = devm_kzalloc_obj(dev, *pll_clk); if (!pll_clk) return ERR_PTR(-ENOMEM); @@ -844,7 +844,7 @@ rzv2h_cpg_ddiv_clk_register(const struct cpg_core_clk *core, if ((shift + width) > 16) return ERR_PTR(-EINVAL); - ddiv = devm_kzalloc(priv->dev, sizeof(*ddiv), GFP_KERNEL); + ddiv = devm_kzalloc_obj(priv->dev, *ddiv); if (!ddiv) return ERR_PTR(-ENOMEM); @@ -924,7 +924,7 @@ rzv2h_cpg_fixed_mod_status_clk_register(const struct cpg_core_clk *core, parent_name = clk_hw_get_name(parent); - clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL); + clk_hw_data = devm_kzalloc_obj(priv->dev, *clk_hw_data); if (!clk_hw_data) return ERR_PTR(-ENOMEM); @@ -1030,8 +1030,8 @@ rzv2h_cpg_register_core_clk(const struct cpg_core_clk *core, break; case CLK_TYPE_FF_MOD_STATUS: if (!priv->ff_mod_status_ops) { - priv->ff_mod_status_ops = - devm_kzalloc(dev, sizeof(*priv->ff_mod_status_ops), GFP_KERNEL); + priv->ff_mod_status_ops = devm_kzalloc_obj(dev, + *priv->ff_mod_status_ops); if (!priv->ff_mod_status_ops) { clk_hw = ERR_PTR(-ENOMEM); goto fail; @@ -1240,7 +1240,7 @@ rzv2h_cpg_register_mod_clk(const struct rzv2h_mod_clk *mod, goto fail; } - clock = devm_kzalloc(dev, sizeof(*clock), GFP_KERNEL); + clock = devm_kzalloc_obj(dev, *clock); if (!clock) { ret = -ENOMEM; goto fail; @@ -1522,7 +1522,7 @@ static int __init rzv2h_cpg_add_pm_domains(struct rzv2h_cpg_priv *priv) struct rzv2h_cpg_pd *pd; int ret; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; @@ -1553,7 +1553,7 @@ static int __init rzv2h_cpg_probe(struct platform_device *pdev) info = of_device_get_match_data(dev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -1566,12 +1566,12 @@ static int __init rzv2h_cpg_probe(struct platform_device *pdev) return PTR_ERR(priv->base); nclks = info->num_total_core_clks + info->num_hw_mod_clks; - clks = devm_kmalloc_array(dev, nclks, sizeof(*clks), GFP_KERNEL); + clks = devm_kmalloc_objs(dev, *clks, nclks); if (!clks) return -ENOMEM; - priv->mstop_count = devm_kcalloc(dev, info->num_mstop_bits, - sizeof(*priv->mstop_count), GFP_KERNEL); + priv->mstop_count = devm_kzalloc_objs(dev, *priv->mstop_count, + info->num_mstop_bits); if (!priv->mstop_count) return -ENOMEM; diff --git a/drivers/clk/rockchip/clk-rk3528.c b/drivers/clk/rockchip/clk-rk3528.c index a5ff64b93f8f1c..9c246b7b84d87e 100644 --- a/drivers/clk/rockchip/clk-rk3528.c +++ b/drivers/clk/rockchip/clk-rk3528.c @@ -1138,7 +1138,7 @@ static int __init clk_rk3528_probe(struct platform_device *pdev) rockchip_clk_register_branches(ctx, rk3528_clk_branches, nr_branches); if (!IS_ERR(vo_grf)) { - vo_grf_e = devm_kzalloc(dev, sizeof(*vo_grf_e), GFP_KERNEL); + vo_grf_e = devm_kzalloc_obj(dev, *vo_grf_e); if (!vo_grf_e) return -ENOMEM; @@ -1151,7 +1151,7 @@ static int __init clk_rk3528_probe(struct platform_device *pdev) } if (!IS_ERR(vpu_grf)) { - vpu_grf_e = devm_kzalloc(dev, sizeof(*vpu_grf_e), GFP_KERNEL); + vpu_grf_e = devm_kzalloc_obj(dev, *vpu_grf_e); if (!vpu_grf_e) return -ENOMEM; diff --git a/drivers/clk/samsung/clk-acpm.c b/drivers/clk/samsung/clk-acpm.c index e5a2d3ab34cbd3..d5f1e73e05f8ba 100644 --- a/drivers/clk/samsung/clk-acpm.c +++ b/drivers/clk/samsung/clk-acpm.c @@ -165,15 +165,14 @@ static int acpm_clk_probe(struct platform_device *pdev) count = drv_data->nr_clks; mbox_chan_id = drv_data->mbox_chan_id; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, count); if (!clk_data) return -ENOMEM; clk_data->num = count; hws = clk_data->hws; - aclks = devm_kcalloc(dev, count, sizeof(*aclks), GFP_KERNEL); + aclks = devm_kzalloc_objs(dev, *aclks, count); if (!aclks) return -ENOMEM; diff --git a/drivers/clk/samsung/clk-exynos-arm64.c b/drivers/clk/samsung/clk-exynos-arm64.c index 35d4de233cc1b4..eac59c8df6fa80 100644 --- a/drivers/clk/samsung/clk-exynos-arm64.c +++ b/drivers/clk/samsung/clk-exynos-arm64.c @@ -202,8 +202,7 @@ static int __init exynos_arm64_cmu_prepare_pm(struct device *dev, if (!data->nr_pclks) return 0; - data->pclks = devm_kcalloc(dev, sizeof(struct clk *), data->nr_pclks, - GFP_KERNEL); + data->pclks = devm_kzalloc_objs(dev, struct clk *, data->nr_pclks); if (!data->pclks) { ret = -ENOMEM; goto free_sysreg_save; @@ -284,7 +283,7 @@ int __init exynos_arm64_register_cmu_pm(struct platform_device *pdev, cmu = of_device_get_match_data(dev); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/samsung/clk-exynos-audss.c b/drivers/clk/samsung/clk-exynos-audss.c index e11ac67819ef26..7b15c580a882b8 100644 --- a/drivers/clk/samsung/clk-exynos-audss.c +++ b/drivers/clk/samsung/clk-exynos-audss.c @@ -141,10 +141,7 @@ static int exynos_audss_clk_probe(struct platform_device *pdev) epll = ERR_PTR(-ENODEV); - clk_data = devm_kzalloc(dev, - struct_size(clk_data, hws, - EXYNOS_AUDSS_MAX_CLKS), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, EXYNOS_AUDSS_MAX_CLKS); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/samsung/clk-exynos-clkout.c b/drivers/clk/samsung/clk-exynos-clkout.c index 9c8b17cb5e7c12..2d65f86e5d4899 100644 --- a/drivers/clk/samsung/clk-exynos-clkout.c +++ b/drivers/clk/samsung/clk-exynos-clkout.c @@ -117,9 +117,8 @@ static int exynos_clkout_probe(struct platform_device *pdev) int parent_count, ret, i; u32 mux_mask; - clkout = devm_kzalloc(&pdev->dev, - struct_size(clkout, data.hws, EXYNOS_CLKOUT_NR_CLKS), - GFP_KERNEL); + clkout = devm_kzalloc_flex(&pdev->dev, *clkout, data.hws, + EXYNOS_CLKOUT_NR_CLKS); if (!clkout) return -ENOMEM; diff --git a/drivers/clk/samsung/clk-s5pv210-audss.c b/drivers/clk/samsung/clk-s5pv210-audss.c index 1b83fdd496e969..b1f2744b93c824 100644 --- a/drivers/clk/samsung/clk-s5pv210-audss.c +++ b/drivers/clk/samsung/clk-s5pv210-audss.c @@ -77,9 +77,7 @@ static int s5pv210_audss_clk_probe(struct platform_device *pdev) if (IS_ERR(reg_base)) return PTR_ERR(reg_base); - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, hws, AUDSS_MAX_CLKS), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, AUDSS_MAX_CLKS); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sifive/sifive-prci.c b/drivers/clk/sifive/sifive-prci.c index 4d1cc7adb2b32d..402b905d010ed9 100644 --- a/drivers/clk/sifive/sifive-prci.c +++ b/drivers/clk/sifive/sifive-prci.c @@ -567,7 +567,7 @@ static int sifive_prci_probe(struct platform_device *pdev) desc = of_device_get_match_data(&pdev->dev); - pd = devm_kzalloc(dev, struct_size(pd, hw_clks.hws, desc->num_clks), GFP_KERNEL); + pd = devm_kzalloc_flex(dev, *pd, hw_clks.hws, desc->num_clks); if (!pd) return -ENOMEM; diff --git a/drivers/clk/socfpga/clk-agilex.c b/drivers/clk/socfpga/clk-agilex.c index 2bdea1997b5eff..3d4d9f35b927e0 100644 --- a/drivers/clk/socfpga/clk-agilex.c +++ b/drivers/clk/socfpga/clk-agilex.c @@ -468,8 +468,7 @@ static int agilex_clkmgr_init(struct platform_device *pdev) num_clks = AGILEX_NUM_CLKS; - clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws, - num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, clk_data.hws, num_clks); if (!clk_data) return -ENOMEM; @@ -508,8 +507,7 @@ static int n5x_clkmgr_init(struct platform_device *pdev) num_clks = AGILEX_NUM_CLKS; - clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws, - num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, clk_data.hws, num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/socfpga/clk-agilex5.c b/drivers/clk/socfpga/clk-agilex5.c index f7f0ad884f6450..572fbb4192845a 100644 --- a/drivers/clk/socfpga/clk-agilex5.c +++ b/drivers/clk/socfpga/clk-agilex5.c @@ -500,8 +500,7 @@ static int agilex5_clkmgr_init(struct platform_device *pdev) num_clks = AGILEX5_NUM_CLKS; - clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws, - num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, clk_data.hws, num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/socfpga/clk-s10.c b/drivers/clk/socfpga/clk-s10.c index b4bf4e2d38e165..aad66f8d069d26 100644 --- a/drivers/clk/socfpga/clk-s10.c +++ b/drivers/clk/socfpga/clk-s10.c @@ -397,8 +397,7 @@ static int s10_clkmgr_init(struct platform_device *pdev) } num_clks = STRATIX10_NUM_CLKS; - clk_data = devm_kzalloc(dev, struct_size(clk_data, clk_data.hws, - num_clks), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, clk_data.hws, num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-cv1800.c b/drivers/clk/sophgo/clk-cv1800.c index a4116ac1adcb2d..c1cf9e042d22f9 100644 --- a/drivers/clk/sophgo/clk-cv1800.c +++ b/drivers/clk/sophgo/clk-cv1800.c @@ -1504,7 +1504,7 @@ static int cv1800_clk_probe(struct platform_device *pdev) return -EINVAL; } - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-sg2042-clkgen.c b/drivers/clk/sophgo/clk-sg2042-clkgen.c index 9725ac4e050a4e..6abc2c973c4907 100644 --- a/drivers/clk/sophgo/clk-sg2042-clkgen.c +++ b/drivers/clk/sophgo/clk-sg2042-clkgen.c @@ -1054,9 +1054,8 @@ static int sg2042_init_clkdata(struct platform_device *pdev, { struct sg2042_clk_data *clk_data = NULL; - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, onecell_data.hws, num_clks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, onecell_data.hws, + num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-sg2042-pll.c b/drivers/clk/sophgo/clk-sg2042-pll.c index 110b6ee06fe4b6..4f2eed02eb59fd 100644 --- a/drivers/clk/sophgo/clk-sg2042-pll.c +++ b/drivers/clk/sophgo/clk-sg2042-pll.c @@ -495,9 +495,8 @@ static int sg2042_init_clkdata(struct platform_device *pdev, { struct sg2042_clk_data *clk_data; - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, onecell_data.hws, num_clks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, onecell_data.hws, + num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-sg2042-rpgate.c b/drivers/clk/sophgo/clk-sg2042-rpgate.c index 5b38d4f15525b7..639fb3b4627dc4 100644 --- a/drivers/clk/sophgo/clk-sg2042-rpgate.c +++ b/drivers/clk/sophgo/clk-sg2042-rpgate.c @@ -227,9 +227,8 @@ static int sg2042_init_clkdata(struct platform_device *pdev, { struct sg2042_clk_data *clk_data; - clk_data = devm_kzalloc(&pdev->dev, - struct_size(clk_data, onecell_data.hws, num_clks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, onecell_data.hws, + num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-sg2044-pll.c b/drivers/clk/sophgo/clk-sg2044-pll.c index 94c0f519ba6d04..2ea9fb35520539 100644 --- a/drivers/clk/sophgo/clk-sg2044-pll.c +++ b/drivers/clk/sophgo/clk-sg2044-pll.c @@ -593,7 +593,7 @@ static int sg2044_pll_probe(struct platform_device *pdev) if (!desc) return dev_err_probe(dev, -EINVAL, "no match data for platform\n"); - ctrl = devm_kzalloc(dev, struct_size(ctrl, data.hws, desc->num_pll), GFP_KERNEL); + ctrl = devm_kzalloc_flex(dev, *ctrl, data.hws, desc->num_pll); if (!ctrl) return -ENOMEM; diff --git a/drivers/clk/sophgo/clk-sg2044.c b/drivers/clk/sophgo/clk-sg2044.c index f67f99c926b692..e98b08db85564f 100644 --- a/drivers/clk/sophgo/clk-sg2044.c +++ b/drivers/clk/sophgo/clk-sg2044.c @@ -1774,7 +1774,7 @@ static int sg2044_clk_probe(struct platform_device *pdev) num_clks = desc->num_div + desc->num_gate + desc->num_mux; - ctrl = devm_kzalloc(dev, struct_size(ctrl, data.hws, num_clks), GFP_KERNEL); + ctrl = devm_kzalloc_flex(dev, *ctrl, data.hws, num_clks); if (!ctrl) return -ENOMEM; diff --git a/drivers/clk/spacemit/ccu_common.c b/drivers/clk/spacemit/ccu_common.c index 8696bb9cba2d8f..1ec07e2d5369f9 100644 --- a/drivers/clk/spacemit/ccu_common.c +++ b/drivers/clk/spacemit/ccu_common.c @@ -23,8 +23,7 @@ static int spacemit_ccu_register(struct device *dev, if (!data->hws) return 0; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, data->num), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, data->num); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sprd/pll.c b/drivers/clk/sprd/pll.c index 4aec30777d8a98..e13d5e610ad0dc 100644 --- a/drivers/clk/sprd/pll.c +++ b/drivers/clk/sprd/pll.c @@ -104,7 +104,7 @@ static unsigned long _sprd_pll_recalc_rate(const struct sprd_pll *pll, u64 refin; u16 k1, k2; - cfg = kcalloc(regs_num, sizeof(*cfg), GFP_KERNEL); + cfg = kzalloc_objs(*cfg, regs_num); if (!cfg) return parent_rate; diff --git a/drivers/clk/starfive/clk-starfive-jh7100-audio.c b/drivers/clk/starfive/clk-starfive-jh7100-audio.c index de1cf717e3917c..b9fb23018500c9 100644 --- a/drivers/clk/starfive/clk-starfive-jh7100-audio.c +++ b/drivers/clk/starfive/clk-starfive-jh7100-audio.c @@ -89,7 +89,7 @@ static int jh7100_audclk_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, reg, JH7100_AUDCLK_END), GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7100_AUDCLK_END); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7100.c b/drivers/clk/starfive/clk-starfive-jh7100.c index 761e46ed0ffda7..079da88ec66cff 100644 --- a/drivers/clk/starfive/clk-starfive-jh7100.c +++ b/drivers/clk/starfive/clk-starfive-jh7100.c @@ -286,7 +286,7 @@ static int __init clk_starfive_jh7100_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, reg, JH7100_CLK_PLL0_OUT), GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7100_CLK_PLL0_OUT); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-aon.c b/drivers/clk/starfive/clk-starfive-jh7110-aon.c index 6f67587f4335ee..fc8a4e78d5d9f0 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-aon.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-aon.c @@ -60,9 +60,7 @@ static int jh7110_aoncrg_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, reg, JH7110_AONCLK_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7110_AONCLK_END); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-isp.c b/drivers/clk/starfive/clk-starfive-jh7110-isp.c index c02c8b29a12304..d39ce4a2a8e9f4 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-isp.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-isp.c @@ -104,13 +104,11 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, reg, JH7110_ISPCLK_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7110_ISPCLK_END); if (!priv) return -ENOMEM; - top = devm_kzalloc(&pdev->dev, sizeof(*top), GFP_KERNEL); + top = devm_kzalloc_obj(&pdev->dev, *top); if (!top) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-pll.c b/drivers/clk/starfive/clk-starfive-jh7110-pll.c index 56dc58a04f8a9f..b85f337eaf0634 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-pll.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-pll.c @@ -459,7 +459,7 @@ static int __init jh7110_pll_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-stg.c b/drivers/clk/starfive/clk-starfive-jh7110-stg.c index 2a5ad0e07d1d00..1c11966203add0 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-stg.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-stg.c @@ -81,8 +81,7 @@ static int jh7110_stgcrg_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, reg, JH7110_STGCLK_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7110_STGCLK_END); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c index 847c0a39e5ab55..44766b094b60ac 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c @@ -410,9 +410,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) int ret; struct clk *pllclk; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, reg, JH7110_SYSCLK_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7110_SYSCLK_END); if (!priv) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-vout.c b/drivers/clk/starfive/clk-starfive-jh7110-vout.c index aeba42cd3c44ba..d4181cce9c15e8 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-vout.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-vout.c @@ -111,13 +111,11 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev) unsigned int idx; int ret; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, reg, JH7110_VOUTCLK_END), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, reg, JH7110_VOUTCLK_END); if (!priv) return -ENOMEM; - top = devm_kzalloc(&pdev->dev, sizeof(*top), GFP_KERNEL); + top = devm_kzalloc_obj(&pdev->dev, *top); if (!top) return -ENOMEM; diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.c b/drivers/clk/starfive/clk-starfive-jh71x0.c index 80e9157347eb21..2d1713c1693b9a 100644 --- a/drivers/clk/starfive/clk-starfive-jh71x0.c +++ b/drivers/clk/starfive/clk-starfive-jh71x0.c @@ -209,7 +209,7 @@ static void jh71x0_clk_debug_init(struct clk_hw *hw, struct dentry *dentry) struct jh71x0_clk_priv *priv = jh71x0_priv_from(clk); struct debugfs_regset32 *regset; - regset = devm_kzalloc(priv->dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(priv->dev, *regset); if (!regset) return; diff --git a/drivers/clk/stm32/clk-stm32-core.c b/drivers/clk/stm32/clk-stm32-core.c index e921c25a929c30..edabc160a6f20c 100644 --- a/drivers/clk/stm32/clk-stm32-core.c +++ b/drivers/clk/stm32/clk-stm32-core.c @@ -30,7 +30,7 @@ static int stm32_rcc_clock_init(struct device *dev, max_binding = data->maxbinding; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, max_binding), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, max_binding); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/stm32/clk-stm32mp1.c b/drivers/clk/stm32/clk-stm32mp1.c index b265e3f3e94c28..8f0a5495a1ad5a 100644 --- a/drivers/clk/stm32/clk-stm32mp1.c +++ b/drivers/clk/stm32/clk-stm32mp1.c @@ -490,7 +490,7 @@ static struct clk_hw *_get_stm32_mux(struct device *dev, void __iomem *base, struct clk_hw *mux_hw; if (cfg->mmux) { - mmux = devm_kzalloc(dev, sizeof(*mmux), GFP_KERNEL); + mmux = devm_kzalloc_obj(dev, *mmux); if (!mmux) return ERR_PTR(-ENOMEM); @@ -505,7 +505,7 @@ static struct clk_hw *_get_stm32_mux(struct device *dev, void __iomem *base, cfg->mmux->hws[cfg->mmux->nbr_clk++] = mux_hw; } else { - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); @@ -527,7 +527,7 @@ static struct clk_hw *_get_stm32_div(struct device *dev, void __iomem *base, { struct clk_divider *div; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -551,7 +551,7 @@ static struct clk_hw *_get_stm32_gate(struct device *dev, void __iomem *base, struct clk_hw *gate_hw; if (cfg->mgate) { - mgate = devm_kzalloc(dev, sizeof(*mgate), GFP_KERNEL); + mgate = devm_kzalloc_obj(dev, *mgate); if (!mgate) return ERR_PTR(-ENOMEM); @@ -566,7 +566,7 @@ static struct clk_hw *_get_stm32_gate(struct device *dev, void __iomem *base, gate_hw = &mgate->gate.hw; } else { - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); @@ -907,7 +907,7 @@ static struct clk_hw *clk_register_pll(struct device *dev, const char *name, struct clk_hw *hw; int err; - element = devm_kzalloc(dev, sizeof(*element), GFP_KERNEL); + element = devm_kzalloc_obj(dev, *element); if (!element) return ERR_PTR(-ENOMEM); @@ -1046,7 +1046,7 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name, struct clk_hw *hw; int err; - tim_ker = devm_kzalloc(dev, sizeof(*tim_ker), GFP_KERNEL); + tim_ker = devm_kzalloc_obj(dev, *tim_ker); if (!tim_ker) return ERR_PTR(-ENOMEM); @@ -2215,8 +2215,7 @@ static int stm32_rcc_clock_init(struct device *dev, void __iomem *base, max_binding = data->maxbinding; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, max_binding), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, max_binding); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c index b0a93b4fb05148..a10ebd1998fbf1 100644 --- a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c +++ b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c @@ -59,15 +59,14 @@ static int sun6i_a31_apb0_gates_clk_probe(struct platform_device *pdev) if (!clk_parent) return -EINVAL; - clk_data = devm_kzalloc(&pdev->dev, sizeof(struct clk_onecell_data), - GFP_KERNEL); + clk_data = devm_kzalloc_obj(&pdev->dev, struct clk_onecell_data); if (!clk_data) return -ENOMEM; /* Worst-case size approximation and memory allocation */ ngates = find_last_bit(data->mask, SUN6I_APB0_GATES_MAX_SIZE); - clk_data->clks = devm_kcalloc(&pdev->dev, (ngates + 1), - sizeof(struct clk *), GFP_KERNEL); + clk_data->clks = devm_kzalloc_objs(&pdev->dev, struct clk *, + (ngates + 1)); if (!clk_data->clks) return -ENOMEM; diff --git a/drivers/clk/sunxi/clk-sun8i-mbus.c b/drivers/clk/sunxi/clk-sun8i-mbus.c index fe7a0693b15dc6..8374de154c71aa 100644 --- a/drivers/clk/sunxi/clk-sun8i-mbus.c +++ b/drivers/clk/sunxi/clk-sun8i-mbus.c @@ -34,7 +34,7 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node) void __iomem *reg; int err; - parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); + parents = kzalloc_objs(*parents, num_parents); if (!parents) return; diff --git a/drivers/clk/sunxi/clk-sun9i-mmc.c b/drivers/clk/sunxi/clk-sun9i-mmc.c index 91074017c04ff6..552c5a2818b561 100644 --- a/drivers/clk/sunxi/clk-sun9i-mmc.c +++ b/drivers/clk/sunxi/clk-sun9i-mmc.c @@ -101,7 +101,7 @@ static int sun9i_a80_mmc_config_clk_probe(struct platform_device *pdev) struct resource *r; int count, i, ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; @@ -116,8 +116,7 @@ static int sun9i_a80_mmc_config_clk_probe(struct platform_device *pdev) clk_data = &data->clk_data; clk_data->clk_num = count; - clk_data->clks = devm_kcalloc(&pdev->dev, count, sizeof(struct clk *), - GFP_KERNEL); + clk_data->clks = devm_kzalloc_objs(&pdev->dev, struct clk *, count); if (!clk_data->clks) return -ENOMEM; diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c index 15b976162b593e..0bb28f96274f9a 100644 --- a/drivers/clk/tegra/clk-bpmp.c +++ b/drivers/clk/tegra/clk-bpmp.c @@ -518,7 +518,7 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp, unsigned int i; int err; - clk = devm_kzalloc(bpmp->dev, struct_size(clk, parents, info->num_parents), GFP_KERNEL); + clk = devm_kzalloc_flex(bpmp->dev, *clk, parents, info->num_parents); if (!clk) return ERR_PTR(-ENOMEM); @@ -559,7 +559,7 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp, init.num_parents = info->num_parents; - parents = kcalloc(info->num_parents, sizeof(*parents), GFP_KERNEL); + parents = kzalloc_objs(*parents, info->num_parents); if (!parents) return ERR_PTR(-ENOMEM); @@ -637,7 +637,7 @@ static int tegra_bpmp_register_clocks(struct tegra_bpmp *bpmp, bpmp->num_clocks = count; - bpmp->clocks = devm_kcalloc(bpmp->dev, count, sizeof(*bpmp->clocks), GFP_KERNEL); + bpmp->clocks = devm_kzalloc_objs(bpmp->dev, *bpmp->clocks, count); if (!bpmp->clocks) return -ENOMEM; diff --git a/drivers/clk/tegra/clk-device.c b/drivers/clk/tegra/clk-device.c index a75f71462df21b..0183b1547f13ab 100644 --- a/drivers/clk/tegra/clk-device.c +++ b/drivers/clk/tegra/clk-device.c @@ -117,7 +117,7 @@ static int tegra_clock_probe(struct platform_device *pdev) if (!dev->pm_domain) return -EINVAL; - clk_dev = devm_kzalloc(dev, sizeof(*clk_dev), GFP_KERNEL); + clk_dev = devm_kzalloc_obj(dev, *clk_dev); if (!clk_dev) return -ENOMEM; diff --git a/drivers/clk/tegra/clk-dfll.c b/drivers/clk/tegra/clk-dfll.c index 22dc29432eff08..8e7a7b769b2fcc 100644 --- a/drivers/clk/tegra/clk-dfll.c +++ b/drivers/clk/tegra/clk-dfll.c @@ -1948,7 +1948,7 @@ int tegra_dfll_register(struct platform_device *pdev, return -EINVAL; } - td = devm_kzalloc(&pdev->dev, sizeof(*td), GFP_KERNEL); + td = devm_kzalloc_obj(&pdev->dev, *td); if (!td) return -ENOMEM; td->dev = &pdev->dev; diff --git a/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c b/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c index 457a77c5bb6242..112901b4606f01 100644 --- a/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c +++ b/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c @@ -675,7 +675,7 @@ static int tegra124_dfll_fcpu_probe(struct platform_device *pdev) return -ENODEV; } - soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL); + soc = devm_kzalloc_obj(&pdev->dev, *soc); if (!soc) return -ENOMEM; diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c index 78655422253d5c..fcd77082d8b568 100644 --- a/drivers/clk/tegra/clk.c +++ b/drivers/clk/tegra/clk.c @@ -212,8 +212,7 @@ void tegra_clk_periph_resume(void) static int tegra_clk_periph_ctx_init(int banks) { - periph_state_ctx = kcalloc(2 * banks, sizeof(*periph_state_ctx), - GFP_KERNEL); + periph_state_ctx = kzalloc_objs(*periph_state_ctx, 2 * banks); if (!periph_state_ctx) return -ENOMEM; diff --git a/drivers/clk/tenstorrent/atlantis-prcm.c b/drivers/clk/tenstorrent/atlantis-prcm.c index 6d28aa2ba8816e..eccc8015da2361 100644 --- a/drivers/clk/tenstorrent/atlantis-prcm.c +++ b/drivers/clk/tenstorrent/atlantis-prcm.c @@ -784,8 +784,7 @@ static int atlantis_prcm_clocks_register(struct device *dev, struct clk_hw_onecell_data *clk_data; int i, ret; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, data->num), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, data->num); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/thead/clk-th1520-ap.c b/drivers/clk/thead/clk-th1520-ap.c index 3a6847f1c950fc..abcb7637ba3bd2 100644 --- a/drivers/clk/thead/clk-th1520-ap.c +++ b/drivers/clk/thead/clk-th1520-ap.c @@ -1524,7 +1524,7 @@ static int th1520_clk_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, -ENODEV, "No device match data found\n"); - priv = devm_kzalloc(dev, struct_size(priv, hws, plat_data->nr_clks), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, hws, plat_data->nr_clks); if (!priv) return -ENOMEM; diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c index 0d729c9980a55b..bc5d5bdbeaca11 100644 --- a/drivers/clk/ti/adpll.c +++ b/drivers/clk/ti/adpll.c @@ -488,10 +488,8 @@ static int ti_adpll_init_dco(struct ti_adpll_data *d) const char *postfix; int width, err; - d->outputs.clks = devm_kcalloc(d->dev, - MAX_ADPLL_OUTPUTS, - sizeof(struct clk *), - GFP_KERNEL); + d->outputs.clks = devm_kzalloc_objs(d->dev, struct clk *, + MAX_ADPLL_OUTPUTS); if (!d->outputs.clks) return -ENOMEM; @@ -583,7 +581,7 @@ static int ti_adpll_init_clkout(struct ti_adpll_data *d, struct clk *clock; int err; - co = devm_kzalloc(d->dev, sizeof(*co), GFP_KERNEL); + co = devm_kzalloc_obj(d->dev, *co); if (!co) return -ENOMEM; co->adpll = d; @@ -595,7 +593,7 @@ static int ti_adpll_init_clkout(struct ti_adpll_data *d, if (err) return err; - ops = devm_kzalloc(d->dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(d->dev, *ops); if (!ops) return -ENOMEM; @@ -866,7 +864,7 @@ static int ti_adpll_probe(struct platform_device *pdev) struct resource *res; int err; - d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(dev, *d); if (!d) return -ENOMEM; d->dev = dev; @@ -888,10 +886,8 @@ static int ti_adpll_probe(struct platform_device *pdev) if (err) return err; - d->clocks = devm_kcalloc(d->dev, - TI_ADPLL_NR_CLOCKS, - sizeof(struct ti_adpll_clock), - GFP_KERNEL); + d->clocks = devm_kzalloc_objs(d->dev, struct ti_adpll_clock, + TI_ADPLL_NR_CLOCKS); if (!d->clocks) return -ENOMEM; diff --git a/drivers/clk/ti/clk-dra7-atl.c b/drivers/clk/ti/clk-dra7-atl.c index fb41f55d44e78a..895534167af80c 100644 --- a/drivers/clk/ti/clk-dra7-atl.c +++ b/drivers/clk/ti/clk-dra7-atl.c @@ -212,7 +212,7 @@ static int of_dra7_atl_clk_probe(struct platform_device *pdev) if (!node) return -ENODEV; - cinfo = devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL); + cinfo = devm_kzalloc_obj(&pdev->dev, *cinfo); if (!cinfo) return -ENOMEM; diff --git a/drivers/clk/ultrarisc/clk-ultrarisc.c b/drivers/clk/ultrarisc/clk-ultrarisc.c index bbcd2234ea7145..0cc5904c932fe3 100644 --- a/drivers/clk/ultrarisc/clk-ultrarisc.c +++ b/drivers/clk/ultrarisc/clk-ultrarisc.c @@ -151,7 +151,7 @@ static struct clk_hw *ultrarisc_clk_register_pll(struct device *dev, }; int ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); @@ -182,7 +182,7 @@ ultrarisc_clk_register_divider(struct device *dev, if (!lock) return ERR_PTR(-EINVAL); - divider = devm_kzalloc(dev, sizeof(*divider), GFP_KERNEL); + divider = devm_kzalloc_obj(dev, *divider); if (!divider) return ERR_PTR(-ENOMEM); @@ -350,15 +350,13 @@ int ultrarisc_clk_probe(struct platform_device *pdev, if (!soc_data) return -EINVAL; - lock = devm_kzalloc(dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(dev, *lock); if (!lock) return -ENOMEM; spin_lock_init(lock); - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, - soc_data->num_clks), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, soc_data->num_clks); if (!clk_data) return -ENOMEM; diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c index 37b495e681079c..dc91286123b363 100644 --- a/drivers/clk/uniphier/clk-uniphier-core.c +++ b/drivers/clk/uniphier/clk-uniphier-core.c @@ -63,8 +63,7 @@ static int uniphier_clk_probe(struct platform_device *pdev) for (p = data; p->name; p++) clk_num = max(clk_num, p->idx + 1); - hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, clk_num), - GFP_KERNEL); + hw_data = devm_kzalloc_flex(dev, *hw_data, hws, clk_num); if (!hw_data) return -ENOMEM; diff --git a/drivers/clk/uniphier/clk-uniphier-cpugear.c b/drivers/clk/uniphier/clk-uniphier-cpugear.c index 165c6832b722fa..d1a1992842e531 100644 --- a/drivers/clk/uniphier/clk-uniphier-cpugear.c +++ b/drivers/clk/uniphier/clk-uniphier-cpugear.c @@ -82,7 +82,7 @@ struct clk_hw *uniphier_clk_register_cpugear(struct device *dev, struct clk_init_data init = {}; int ret; - gear = devm_kzalloc(dev, sizeof(*gear), GFP_KERNEL); + gear = devm_kzalloc_obj(dev, *gear); if (!gear) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/uniphier/clk-uniphier-fixed-factor.c b/drivers/clk/uniphier/clk-uniphier-fixed-factor.c index c86683fce20549..2184b92caf09f8 100644 --- a/drivers/clk/uniphier/clk-uniphier-fixed-factor.c +++ b/drivers/clk/uniphier/clk-uniphier-fixed-factor.c @@ -17,7 +17,7 @@ struct clk_hw *uniphier_clk_register_fixed_factor(struct device *dev, struct clk_fixed_factor *fix; int ret; - fix = devm_kzalloc(dev, sizeof(*fix), GFP_KERNEL); + fix = devm_kzalloc_obj(dev, *fix); if (!fix) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/uniphier/clk-uniphier-fixed-rate.c b/drivers/clk/uniphier/clk-uniphier-fixed-rate.c index 63f49d3bab80ba..720e26a5fd3982 100644 --- a/drivers/clk/uniphier/clk-uniphier-fixed-rate.c +++ b/drivers/clk/uniphier/clk-uniphier-fixed-rate.c @@ -18,7 +18,7 @@ struct clk_hw *uniphier_clk_register_fixed_rate(struct device *dev, int ret; /* allocate fixed-rate clock */ - fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL); + fixed = devm_kzalloc_obj(dev, *fixed); if (!fixed) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/uniphier/clk-uniphier-gate.c b/drivers/clk/uniphier/clk-uniphier-gate.c index 9f49e6bb6b2042..533704bdc8fe69 100644 --- a/drivers/clk/uniphier/clk-uniphier-gate.c +++ b/drivers/clk/uniphier/clk-uniphier-gate.c @@ -65,7 +65,7 @@ struct clk_hw *uniphier_clk_register_gate(struct device *dev, struct uniphier_clk_gate *gate; int ret; - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c index a63ad4df8e65eb..60e9a10e1c128c 100644 --- a/drivers/clk/uniphier/clk-uniphier-mux.c +++ b/drivers/clk/uniphier/clk-uniphier-mux.c @@ -62,7 +62,7 @@ struct clk_hw *uniphier_clk_register_mux(struct device *dev, struct uniphier_clk_mux *mux; int ret; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/ux500/clk-sysctrl.c b/drivers/clk/ux500/clk-sysctrl.c index 2127a949e56ccf..c6249b7b34611f 100644 --- a/drivers/clk/ux500/clk-sysctrl.c +++ b/drivers/clk/ux500/clk-sysctrl.c @@ -140,7 +140,7 @@ static struct clk *clk_reg_sysctrl(struct device *dev, return ERR_PTR(-EINVAL); } - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/versatile/clk-vexpress-osc.c b/drivers/clk/versatile/clk-vexpress-osc.c index 72e872ec6b7c9b..0ee1c5d6d705e4 100644 --- a/drivers/clk/versatile/clk-vexpress-osc.c +++ b/drivers/clk/versatile/clk-vexpress-osc.c @@ -69,7 +69,7 @@ static int vexpress_osc_probe(struct platform_device *pdev) u32 range[2]; int ret; - osc = devm_kzalloc(&pdev->dev, sizeof(*osc), GFP_KERNEL); + osc = devm_kzalloc_obj(&pdev->dev, *osc); if (!osc) return -ENOMEM; diff --git a/drivers/clk/visconti/clkc.c b/drivers/clk/visconti/clkc.c index 4018d1298880df..a75163b69751e5 100644 --- a/drivers/clk/visconti/clkc.c +++ b/drivers/clk/visconti/clkc.c @@ -87,13 +87,13 @@ static struct clk_hw *visconti_clk_register_gate(struct device *dev, struct clk_hw *hw; int ret; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); pdata->name = pdata->fw_name = parent_name; - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); @@ -139,7 +139,7 @@ int visconti_clk_register_gates(struct visconti_clk_provider *ctx, char *dev_name; u8 rs_idx; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -191,7 +191,7 @@ struct visconti_clk_provider *visconti_init_clk(struct device *dev, struct visconti_clk_provider *ctx; int i; - ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, nr_clks), GFP_KERNEL); + ctx = devm_kzalloc_flex(dev, *ctx, clk_data.hws, nr_clks); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/visconti/reset.c b/drivers/clk/visconti/reset.c index e3c3d780461293..78a56eecc4318f 100644 --- a/drivers/clk/visconti/reset.c +++ b/drivers/clk/visconti/reset.c @@ -92,7 +92,7 @@ int visconti_register_reset_controller(struct device *dev, { struct visconti_reset *reset; - reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/clk/x86/clk-cgu-pll.c b/drivers/clk/x86/clk-cgu-pll.c index 409dbf55f4caea..4dc5ce9c7795a6 100644 --- a/drivers/clk/x86/clk-cgu-pll.c +++ b/drivers/clk/x86/clk-cgu-pll.c @@ -106,7 +106,7 @@ lgm_clk_register_pll(struct lgm_clk_provider *ctx, init.parent_data = list->parent_data; init.num_parents = list->num_parents; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/x86/clk-cgu.c b/drivers/clk/x86/clk-cgu.c index 92ee05d75af2b2..e0c48c0f6d434d 100644 --- a/drivers/clk/x86/clk-cgu.c +++ b/drivers/clk/x86/clk-cgu.c @@ -91,7 +91,7 @@ lgm_clk_register_mux(struct lgm_clk_provider *ctx, struct clk_hw *hw; int ret; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return ERR_PTR(-ENOMEM); @@ -203,7 +203,7 @@ lgm_clk_register_divider(struct lgm_clk_provider *ctx, struct clk_hw *hw; int ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -304,7 +304,7 @@ lgm_clk_register_gate(struct lgm_clk_provider *ctx, struct clk_hw *hw; int ret; - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); @@ -547,7 +547,7 @@ int lgm_clk_register_ddiv(struct lgm_clk_provider *ctx, struct clk_init_data init = {}; struct lgm_clk_ddiv *ddiv; - ddiv = devm_kzalloc(dev, sizeof(*ddiv), GFP_KERNEL); + ddiv = devm_kzalloc_obj(dev, *ddiv); if (!ddiv) return -ENOMEM; diff --git a/drivers/clk/x86/clk-lgm.c b/drivers/clk/x86/clk-lgm.c index f69455dd1c9802..e3cad72431c3de 100644 --- a/drivers/clk/x86/clk-lgm.c +++ b/drivers/clk/x86/clk-lgm.c @@ -428,8 +428,7 @@ static int lgm_cgu_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, CLK_NR_CLKS), - GFP_KERNEL); + ctx = devm_kzalloc_flex(dev, *ctx, clk_data.hws, CLK_NR_CLKS); if (!ctx) return -ENOMEM; diff --git a/drivers/clk/x86/clk-lpss-atom.c b/drivers/clk/x86/clk-lpss-atom.c index aa9d0bb98f8b8b..8b05e439cada05 100644 --- a/drivers/clk/x86/clk-lpss-atom.c +++ b/drivers/clk/x86/clk-lpss-atom.c @@ -18,7 +18,7 @@ static int lpss_atom_clk_probe(struct platform_device *pdev) struct lpss_clk_data *drvdata; struct clk *clk; - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c index 43dda274e329d1..8aa4a993a03bd6 100644 --- a/drivers/clk/x86/clk-pmc-atom.c +++ b/drivers/clk/x86/clk-pmc-atom.c @@ -155,7 +155,7 @@ static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id, struct clk_plt *pclk; int ret; - pclk = devm_kzalloc(&pdev->dev, sizeof(*pclk), GFP_KERNEL); + pclk = devm_kzalloc_obj(&pdev->dev, *pclk); if (!pclk) return ERR_PTR(-ENOMEM); @@ -209,7 +209,7 @@ static struct clk_plt_fixed *plt_clk_register_fixed_rate(struct platform_device { struct clk_plt_fixed *pclk; - pclk = devm_kzalloc(&pdev->dev, sizeof(*pclk), GFP_KERNEL); + pclk = devm_kzalloc_obj(&pdev->dev, *pclk); if (!pclk) return ERR_PTR(-ENOMEM); @@ -268,13 +268,11 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, while (clks[nparents].name) nparents++; - data->parents = devm_kcalloc(&pdev->dev, nparents, - sizeof(*data->parents), GFP_KERNEL); + data->parents = devm_kzalloc_objs(&pdev->dev, *data->parents, nparents); if (!data->parents) return ERR_PTR(-ENOMEM); - parent_names = kcalloc(nparents, sizeof(*parent_names), - GFP_KERNEL); + parent_names = kzalloc_objs(*parent_names, nparents); if (!parent_names) return ERR_PTR(-ENOMEM); @@ -316,7 +314,7 @@ static int plt_clk_probe(struct platform_device *pdev) if (!pmc_data || !pmc_data->clks) return -EINVAL; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c index 71abd46b3593f0..9f8830b40122a5 100644 --- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c +++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c @@ -941,7 +941,7 @@ static struct clk_hw *clk_wzrd_register_divf(struct device *dev, struct clk_hw *hw; int ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -985,7 +985,7 @@ static struct clk_hw *clk_wzrd_ver_register_divider(struct device *dev, struct clk_hw *hw; int ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -1031,7 +1031,7 @@ static struct clk_hw *clk_wzrd_register_divider(struct device *dev, struct clk_hw *hw; int ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return ERR_PTR(-ENOMEM); @@ -1298,8 +1298,8 @@ static int clk_wzrd_probe(struct platform_device *pdev) if (ret || nr_outputs > WZRD_NUM_OUTPUTS) return -EINVAL; - clk_wzrd = devm_kzalloc(&pdev->dev, struct_size(clk_wzrd, clk_data.hws, nr_outputs), - GFP_KERNEL); + clk_wzrd = devm_kzalloc_flex(&pdev->dev, *clk_wzrd, clk_data.hws, + nr_outputs); if (!clk_wzrd) return -ENOMEM; platform_set_drvdata(pdev, clk_wzrd); diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c index ccd9d7c0b18098..90bf38cba1e29a 100644 --- a/drivers/clk/xilinx/xlnx_vcu.c +++ b/drivers/clk/xilinx/xlnx_vcu.c @@ -417,7 +417,7 @@ static struct clk_hw *xvcu_register_pll(struct device *dev, init.num_parents = 1; init.flags = flags; - pll = devm_kmalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kmalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); @@ -454,7 +454,7 @@ static struct clk_hw *xvcu_clk_hw_register_leaf(struct device *dev, /* Protect register shared by clocks */ spinlock_t *lock; - lock = devm_kzalloc(dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(dev, *lock); if (!lock) return ERR_PTR(-ENOMEM); spin_lock_init(lock); @@ -532,7 +532,7 @@ static int xvcu_register_clock_provider(struct xvcu_device *xvcu) struct clk_hw *hw; void __iomem *reg_base = xvcu->vcu_slcr_ba; - data = devm_kzalloc(dev, struct_size(data, hws, CLK_XVCU_NUM_CLOCKS), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, hws, CLK_XVCU_NUM_CLOCKS); if (!data) return -ENOMEM; data->num = CLK_XVCU_NUM_CLOCKS; @@ -612,7 +612,7 @@ static int xvcu_probe(struct platform_device *pdev) void __iomem *regs; int ret; - xvcu = devm_kzalloc(&pdev->dev, sizeof(*xvcu), GFP_KERNEL); + xvcu = devm_kzalloc_obj(&pdev->dev, *xvcu); if (!xvcu) return -ENOMEM; diff --git a/drivers/clk/zte/clk-regmap.c b/drivers/clk/zte/clk-regmap.c index 022b2be7bb3dc4..81fbfb5a52c38c 100644 --- a/drivers/clk/zte/clk-regmap.c +++ b/drivers/clk/zte/clk-regmap.c @@ -63,7 +63,7 @@ struct clk_hw *zx_clk_register_gate(struct device *dev, struct regmap *regmap, struct zte_clk_regmap *clk; int res; - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return ERR_PTR(-ENOMEM); @@ -141,7 +141,7 @@ struct clk_hw *zx_clk_register_divider(struct device *dev, struct regmap *regmap struct zte_clk_regmap *clk; int res; - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return ERR_PTR(-ENOMEM); @@ -215,7 +215,7 @@ struct clk_hw *zx_clk_register_mux(struct device *dev, struct regmap *regmap, for (i = 0; i < desc->num_parents; ++i) parents[i] = zx_get_parent(&desc->parents[i], clocks); - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return ERR_PTR(-ENOMEM); diff --git a/drivers/clk/zte/clk-zx.c b/drivers/clk/zte/clk-zx.c index aef0f7c753e643..ec5afe4aa18ff3 100644 --- a/drivers/clk/zte/clk-zx.c +++ b/drivers/clk/zte/clk-zx.c @@ -123,7 +123,7 @@ int zx_clk_common_probe(struct device *dev, struct device_node *of_node, if (IS_ERR(map)) return PTR_ERR(map); - clocks = devm_kcalloc(dev, data->num_clocks, sizeof(*clocks), GFP_KERNEL); + clocks = devm_kzalloc_objs(dev, *clocks, data->num_clocks); if (!clocks) return -ENOMEM; @@ -167,7 +167,7 @@ int zx_clk_common_probe(struct device *dev, struct device_node *of_node, clocks[i] = hw; } - exports = devm_kzalloc(dev, struct_size(exports, hws, data->num_exports), GFP_KERNEL); + exports = devm_kzalloc_flex(dev, *exports, hws, data->num_exports); if (!exports) return -ENOMEM; exports->num = data->num_exports; diff --git a/drivers/clk/zte/pll-zx.c b/drivers/clk/zte/pll-zx.c index d3687495d06ce7..3e89e69c86a123 100644 --- a/drivers/clk/zte/pll-zx.c +++ b/drivers/clk/zte/pll-zx.c @@ -522,7 +522,7 @@ struct clk_hw *zx_clk_register_pll(struct device *dev, struct regmap *regmap, unsigned int i; int res; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return ERR_PTR(-ENOMEM); diff --git a/drivers/clocksource/arm_arch_timer_mmio.c b/drivers/clocksource/arm_arch_timer_mmio.c index d678f764d3bb5a..975c31ff5cfd71 100644 --- a/drivers/clocksource/arm_arch_timer_mmio.c +++ b/drivers/clocksource/arm_arch_timer_mmio.c @@ -378,13 +378,13 @@ static int arch_timer_mmio_probe(struct platform_device *pdev) np = pdev->dev.of_node; - at = devm_kmalloc(&pdev->dev, sizeof(*at), GFP_KERNEL | __GFP_ZERO); + at = devm_kmalloc_obj(&pdev->dev, *at, GFP_KERNEL | __GFP_ZERO); if (!at) return -ENOMEM; if (np) { - at->gt_block = devm_kmalloc(&pdev->dev, sizeof(*at->gt_block), - GFP_KERNEL | __GFP_ZERO); + at->gt_block = devm_kmalloc_obj(&pdev->dev, *at->gt_block, + GFP_KERNEL | __GFP_ZERO); if (!at->gt_block) return -ENOMEM; ret = of_populate_gt_block(pdev, at); diff --git a/drivers/clocksource/em_sti.c b/drivers/clocksource/em_sti.c index 73a3357d173d7d..1d62ed67fdd736 100644 --- a/drivers/clocksource/em_sti.c +++ b/drivers/clocksource/em_sti.c @@ -281,7 +281,7 @@ static int em_sti_probe(struct platform_device *pdev) struct em_sti_priv *p; int irq, ret; - p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, *p); if (p == NULL) return -ENOMEM; diff --git a/drivers/clocksource/ingenic-ost.c b/drivers/clocksource/ingenic-ost.c index e0ec33307c8489..0bb3cf6c077df6 100644 --- a/drivers/clocksource/ingenic-ost.c +++ b/drivers/clocksource/ingenic-ost.c @@ -77,7 +77,7 @@ static int __init ingenic_ost_probe(struct platform_device *pdev) if (!soc_info) return -EINVAL; - ost = devm_kzalloc(dev, sizeof(*ost), GFP_KERNEL); + ost = devm_kzalloc_obj(dev, *ost); if (!ost) return -ENOMEM; diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c index 6fe098a4a33fae..ca6c0df0e54842 100644 --- a/drivers/clocksource/timer-nxp-stm.c +++ b/drivers/clocksource/timer-nxp-stm.c @@ -434,7 +434,7 @@ static int nxp_stm_timer_probe(struct platform_device *pdev) if (IS_ERR(clk)) return dev_err_probe(dev, PTR_ERR(clk), "Clock not found\n"); - stm_timer = devm_kzalloc(dev, sizeof(*stm_timer), GFP_KERNEL); + stm_timer = devm_kzalloc_obj(dev, *stm_timer); if (!stm_timer) return -ENOMEM; diff --git a/drivers/clocksource/timer-rzn1.c b/drivers/clocksource/timer-rzn1.c index 25ebebff3c639c..918e80ce5c6200 100644 --- a/drivers/clocksource/timer-rzn1.c +++ b/drivers/clocksource/timer-rzn1.c @@ -442,8 +442,7 @@ static int rzn1_timer_probe(struct platform_device *pdev) struct clk *clk; int ret; - tab_timers = devm_kcalloc(dev, RZN1_TIMER_NB_TIMERS, sizeof(*tab_timers), - GFP_KERNEL); + tab_timers = devm_kzalloc_objs(dev, *tab_timers, RZN1_TIMER_NB_TIMERS); if (!tab_timers) return -ENOMEM; diff --git a/drivers/clocksource/timer-stm32-lp.c b/drivers/clocksource/timer-stm32-lp.c index 3d804128c765f7..be97d453165ed8 100644 --- a/drivers/clocksource/timer-stm32-lp.c +++ b/drivers/clocksource/timer-stm32-lp.c @@ -224,7 +224,7 @@ static int stm32_clkevent_lp_probe(struct platform_device *pdev) unsigned long rate; int ret, irq; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index bcf155fb9cac2a..b35454cd6610c6 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c @@ -264,7 +264,7 @@ static int sun5i_timer_probe(struct platform_device *pdev) unsigned long rate; int irq, ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/clocksource/timer-tegra186.c b/drivers/clocksource/timer-tegra186.c index 0f626ecf61b01b..7938fc4eb1a84a 100644 --- a/drivers/clocksource/timer-tegra186.c +++ b/drivers/clocksource/timer-tegra186.c @@ -126,7 +126,7 @@ static struct tegra186_tmr *tegra186_tmr_create(struct tegra186_timer *tegra, unsigned int offset = 0x10000 + index * 0x10000; struct tegra186_tmr *tmr; - tmr = devm_kzalloc(tegra->dev, sizeof(*tmr), GFP_KERNEL); + tmr = devm_kzalloc_obj(tegra->dev, *tmr); if (!tmr) return ERR_PTR(-ENOMEM); @@ -349,7 +349,7 @@ static struct tegra186_wdt *tegra186_wdt_create(struct tegra186_timer *tegra, offset += tegra->soc->num_timers * 0x10000 + index * 0x10000; - wdt = devm_kzalloc(tegra->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(tegra->dev, *wdt); if (!wdt) return ERR_PTR(-ENOMEM); @@ -466,7 +466,7 @@ static int tegra186_timer_probe(struct platform_device *pdev) int irq; int err; - tegra = devm_kzalloc(dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(dev, *tegra); if (!tegra) return -ENOMEM; @@ -484,7 +484,7 @@ static int tegra186_timer_probe(struct platform_device *pdev) irq = err; - tegra->wdts = devm_kcalloc(dev, tegra->soc->num_wdts, sizeof(*tegra->wdts), GFP_KERNEL); + tegra->wdts = devm_kzalloc_objs(dev, *tegra->wdts, tegra->soc->num_wdts); if (!tegra->wdts) return -ENOMEM; diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c index c6aea234572cc0..de22cab48a62e7 100644 --- a/drivers/clocksource/timer-ti-dm.c +++ b/drivers/clocksource/timer-ti-dm.c @@ -1262,7 +1262,7 @@ static int omap_dm_timer_setup_clocksource(struct dmtimer *timer) timer->reserved = 1; - clksrc = devm_kzalloc(dev, sizeof(*clksrc), GFP_KERNEL); + clksrc = devm_kzalloc_obj(dev, *clksrc); if (!clksrc) return -ENOMEM; @@ -1354,7 +1354,7 @@ static int omap_dm_timer_setup_clockevent(struct dmtimer *timer) struct omap_dm_timer_clockevent *clkevt; int ret; - clkevt = devm_kzalloc(dev, sizeof(*clkevt), GFP_KERNEL); + clkevt = devm_kzalloc_obj(dev, *clkevt); if (!clkevt) return -ENOMEM; @@ -1418,7 +1418,7 @@ static int omap_dm_timer_probe(struct platform_device *pdev) return -ENODEV; } - timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); + timer = devm_kzalloc_obj(dev, *timer); if (!timer) return -ENOMEM; diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c index 05d14839c5a6a1..9a65dc5d62a475 100644 --- a/drivers/comedi/comedi_fops.c +++ b/drivers/comedi/comedi_fops.c @@ -1677,8 +1677,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev, } /* Allocate scratch space for all instruction data. */ - data = kmalloc_array(max_n_data_required, sizeof(unsigned int), - GFP_KERNEL); + data = kmalloc_objs(unsigned int, max_n_data_required); if (!data) { ret = -ENOMEM; goto error; @@ -1768,7 +1767,7 @@ static int do_insn_ioctl(struct comedi_device *dev, n_data = MAX_SAMPLES; } - data = kmalloc_array(n_data, sizeof(unsigned int), GFP_KERNEL); + data = kmalloc_objs(unsigned int, n_data); if (!data) { ret = -ENOMEM; goto error; diff --git a/drivers/comedi/drivers.c b/drivers/comedi/drivers.c index e78ad565f8f326..3f75485338a106 100644 --- a/drivers/comedi/drivers.c +++ b/drivers/comedi/drivers.c @@ -142,7 +142,7 @@ int comedi_alloc_subdev_readback(struct comedi_subdevice *s) if (!s->n_chan) return -EINVAL; - s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL); + s->readback = kzalloc_objs(*s->readback, s->n_chan); if (!s->readback) return -ENOMEM; diff --git a/drivers/comedi/drivers/amplc_pci224.c b/drivers/comedi/drivers/amplc_pci224.c index 55292a28f28c3c..6c3356531e9532 100644 --- a/drivers/comedi/drivers/amplc_pci224.c +++ b/drivers/comedi/drivers/amplc_pci224.c @@ -1024,9 +1024,8 @@ pci224_auto_attach(struct comedi_device *dev, unsigned long context_model) irq = pci_dev->irq; /* Allocate buffer to hold values for AO channel scan. */ - devpriv->ao_scan_vals = kmalloc_array(board->ao_chans, - sizeof(devpriv->ao_scan_vals[0]), - GFP_KERNEL); + devpriv->ao_scan_vals = kmalloc_objs(devpriv->ao_scan_vals[0], + board->ao_chans); if (!devpriv->ao_scan_vals) return -ENOMEM; diff --git a/drivers/comedi/drivers/das1800.c b/drivers/comedi/drivers/das1800.c index 7d7ea99a81aaeb..c68dd98f485043 100644 --- a/drivers/comedi/drivers/das1800.c +++ b/drivers/comedi/drivers/das1800.c @@ -1228,9 +1228,7 @@ static int das1800_attach(struct comedi_device *dev, if (dev->irq & it->options[2]) das1800_init_dma(dev, it); - devpriv->fifo_buf = kmalloc_array(FIFO_SIZE, - sizeof(*devpriv->fifo_buf), - GFP_KERNEL); + devpriv->fifo_buf = kmalloc_objs(*devpriv->fifo_buf, FIFO_SIZE); if (!devpriv->fifo_buf) return -ENOMEM; diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index ed85da907982e7..c4aa7456465750 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -536,7 +536,7 @@ static int counter_avail_attr_create(struct device *const dev, struct counter_attribute *counter_attr; struct device_attribute *dev_attr; - counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); + counter_attr = devm_kzalloc_obj(dev, *counter_attr); if (!counter_attr) return -ENOMEM; @@ -574,7 +574,7 @@ static int counter_attr_create(struct device *const dev, struct counter_attribute *counter_attr; struct device_attribute *dev_attr; - counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); + counter_attr = devm_kzalloc_obj(dev, *counter_attr); if (!counter_attr) return -ENOMEM; @@ -683,7 +683,7 @@ static int counter_name_attr_create(struct device *const dev, { struct counter_attribute *counter_attr; - counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); + counter_attr = devm_kzalloc_obj(dev, *counter_attr); if (!counter_attr) return -ENOMEM; @@ -718,7 +718,7 @@ static int counter_comp_id_attr_create(struct device *const dev, struct counter_attribute *counter_attr; /* Allocate Counter attribute */ - counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); + counter_attr = devm_kzalloc_obj(dev, *counter_attr); if (!counter_attr) return -ENOMEM; @@ -781,7 +781,7 @@ static int counter_array_attrs_create(struct device *const dev, return -ENOMEM; /* Allocate and configure array element */ - element = devm_kzalloc(dev, sizeof(*element), GFP_KERNEL); + element = devm_kzalloc_obj(dev, *element); if (!element) return -ENOMEM; element->type = array->type; @@ -1124,8 +1124,7 @@ int counter_sysfs_add(struct counter_device *const counter) struct counter_attribute *p; /* Allocate space for attribute groups (signals, counts, and ext) */ - cattr_groups = devm_kcalloc(dev, num_groups, sizeof(*cattr_groups), - GFP_KERNEL); + cattr_groups = devm_kzalloc_objs(dev, *cattr_groups, num_groups); if (!cattr_groups) return -ENOMEM; @@ -1139,13 +1138,12 @@ int counter_sysfs_add(struct counter_device *const counter) return err; /* Allocate attribute group pointers for association with device */ - dev->groups = devm_kcalloc(dev, num_groups + 1, sizeof(*dev->groups), - GFP_KERNEL); + dev->groups = devm_kzalloc_objs(dev, *dev->groups, num_groups + 1); if (!dev->groups) return -ENOMEM; /* Allocate space for attribute groups */ - groups = devm_kcalloc(dev, num_groups, sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(dev, *groups, num_groups); if (!groups) return -ENOMEM; @@ -1154,10 +1152,8 @@ int counter_sysfs_add(struct counter_device *const counter) groups[i].name = cattr_groups[i].name; /* Allocate space for attribute pointers */ - groups[i].attrs = devm_kcalloc(dev, - cattr_groups[i].num_attr + 1, - sizeof(*groups[i].attrs), - GFP_KERNEL); + groups[i].attrs = devm_kzalloc_objs(dev, *groups[i].attrs, + cattr_groups[i].num_attr + 1); if (!groups[i].attrs) return -ENOMEM; diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index 2e74a000cdc74d..f64fa379c6b14b 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -197,14 +197,13 @@ static unsigned extract_io(struct cpufreq_policy *policy, u32 value) { struct acpi_cpufreq_data *data = policy->driver_data; struct acpi_processor_performance *perf; - int i; + struct cpufreq_frequency_table *pos; perf = to_perf_data(data); - for (i = 0; i < perf->state_count; i++) { - if (value == perf->states[i].status) - return policy->freq_table[i].frequency; - } + cpufreq_for_each_entry(pos, policy->freq_table) + if (value == perf->states[pos->driver_data].status) + return pos->frequency; return 0; } diff --git a/drivers/cpufreq/airoha-cpufreq.c b/drivers/cpufreq/airoha-cpufreq.c index 8283c528d0c145..b1dd5e286c2cb9 100644 --- a/drivers/cpufreq/airoha-cpufreq.c +++ b/drivers/cpufreq/airoha-cpufreq.c @@ -52,7 +52,7 @@ static int airoha_cpufreq_probe(struct platform_device *pdev) if (!cpu_dev) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 7d902856ac01aa..f7f250034c944b 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -438,8 +438,7 @@ brcm_avs_get_freq_table(struct device *dev, struct private_data *priv) * We allocate space for the 5 different P-STATES AVS, * plus extra space for a terminating element. */ - table = devm_kcalloc(dev, AVS_PSTATE_MAX + 1 + 1, sizeof(*table), - GFP_KERNEL); + table = devm_kzalloc_objs(dev, *table, AVS_PSTATE_MAX + 1 + 1); if (!table) return ERR_PTR(-ENOMEM); @@ -555,7 +554,7 @@ static int brcm_avs_prepare_init(struct platform_device *pdev) int ret; dev = &pdev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 7d5079fd168825..eb15650f99bff7 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -169,7 +169,7 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu) if (!cpu_dev) return -EPROBE_DEFER; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 54dde8419bdc4b..24319b214d7ba9 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -35,6 +35,9 @@ static LIST_HEAD(cpufreq_policy_list); /* Macros to iterate over CPU policies */ +#define for_each_policy(__policy) \ + list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) + #define for_each_suitable_policy(__policy, __active) \ list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \ if ((__active) == !policy_is_inactive(__policy)) @@ -474,7 +477,7 @@ EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch); static unsigned int __resolve_freq(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int min, unsigned int max, - unsigned int relation) + unsigned int relation, unsigned int *idx_p) { unsigned int idx; @@ -484,8 +487,9 @@ static unsigned int __resolve_freq(struct cpufreq_policy *policy, return target_freq; idx = cpufreq_frequency_table_target(policy, target_freq, min, max, relation); - policy->cached_resolved_idx = idx; - policy->cached_target_freq = target_freq; + if (idx_p) + *idx_p = idx; + return policy->freq_table[idx].frequency; } @@ -517,7 +521,10 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, if (unlikely(min > max)) min = max; - return __resolve_freq(policy, target_freq, min, max, CPUFREQ_RELATION_LE); + policy->cached_target_freq = __resolve_freq(policy, target_freq, min, max, + CPUFREQ_RELATION_LE, + &policy->cached_resolved_idx); + return policy->cached_target_freq; } EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq); @@ -576,6 +583,8 @@ static int policy_set_boost(struct cpufreq_policy *policy, bool enable) { int ret; + lockdep_assert_held_write(&policy->rwsem); + if (policy->boost_enabled == enable) return 0; @@ -1629,6 +1638,8 @@ static int cpufreq_online(unsigned int cpu) */ if (cpufreq_driver->set_boost && policy->boost_supported && (new_policy || !cpufreq_boost_enabled())) { + guard(cpufreq_policy_write)(policy); + ret = policy_set_boost(policy, cpufreq_boost_enabled()); if (ret) { /* If the set_boost fails, the online operation is not affected */ @@ -1956,6 +1967,14 @@ int cpufreq_generic_suspend(struct cpufreq_policy *policy) } EXPORT_SYMBOL(cpufreq_generic_suspend); +static void cpufreq_suspend_policy(struct cpufreq_policy *policy) +{ + guard(cpufreq_policy_write)(policy); + + cpufreq_stop_governor(policy); + policy->suspended = true; +} + /** * cpufreq_suspend() - Suspend CPUFreq governors. * @@ -1978,11 +1997,8 @@ void cpufreq_suspend(void) pr_debug("%s: Suspending Governors\n", __func__); for_each_active_policy(policy) { - if (has_target()) { - scoped_guard(cpufreq_policy_write, policy) { - cpufreq_stop_governor(policy); - } - } + if (has_target()) + cpufreq_suspend_policy(policy); if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) pr_err("%s: Failed to suspend driver: %s\n", __func__, @@ -1994,6 +2010,41 @@ void cpufreq_suspend(void) cpus_read_unlock(); } +static void cpufreq_resume_policy(struct cpufreq_policy *policy, bool start) +{ + guard(cpufreq_policy_write)(policy); + + if (!policy->suspended) + return; + + policy->suspended = false; + + if (policy_is_inactive(policy)) { + /* + * The policy was active when it was suspended, so its governor + * is still there. Let the governor go. + */ + cpufreq_exit_governor(policy); + return; + } + + if (!start) + return; + + /* + * Force executing the driver .target() callback, if present, in the + * next invocation of __cpufreq_driver_target() in case policy->cur has + * become stale while suspended, but do it only for drivers without a + * .get() callback for which cpufreq_verify_current_freq() is a NOP. + */ + if (cpufreq_driver->target && !cpufreq_driver->get) + policy->force_target = true; + + if (cpufreq_start_governor(policy)) + pr_err("%s: Failed to start governor for CPU%u's policy\n", + __func__, policy->cpu); +} + /** * cpufreq_resume() - Resume CPUFreq governors. * @@ -2003,11 +2054,12 @@ void cpufreq_suspend(void) void cpufreq_resume(void) { struct cpufreq_policy *policy; - int ret; if (!cpufreq_driver) return; + guard(cpus_read_lock)(); + if (unlikely(!cpufreq_suspended)) return; @@ -2018,19 +2070,18 @@ void cpufreq_resume(void) pr_debug("%s: Resuming Governors\n", __func__); - for_each_active_policy(policy) { - if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { - pr_err("%s: Failed to resume driver: %s\n", __func__, - cpufreq_driver->name); - } else if (has_target()) { - scoped_guard(cpufreq_policy_write, policy) { - ret = cpufreq_start_governor(policy); - } + for_each_policy(policy) { + int ret = 0; + if (cpufreq_driver->resume && !policy_is_inactive(policy)) { + ret = cpufreq_driver->resume(policy); if (ret) - pr_err("%s: Failed to start governor for CPU%u's policy\n", - __func__, policy->cpu); + pr_err("%s: Failed to resume driver: %s\n", __func__, + cpufreq_driver->name); } + + if (has_target()) + cpufreq_resume_policy(policy, ret == 0); } } @@ -2355,28 +2406,26 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int relation) { unsigned int old_target_freq = target_freq; + unsigned int idx = 0; if (cpufreq_disabled()) return -ENODEV; target_freq = __resolve_freq(policy, target_freq, policy->min, - policy->max, relation); + policy->max, relation, &idx); pr_debug("CPU %u: cur %u kHz -> target %u kHz (req %u kHz, rel %u)\n", policy->cpu, policy->cur, target_freq, old_target_freq, relation); /* - * This might look like a redundant call as we are checking it again - * after finding index. But it is left intentionally for cases where - * exactly same freq is called again and so we can save on few function - * calls. + * Unless invoking the target callback is forced, skip the update if the + * frequency is not really changing. */ - if (target_freq == policy->cur) { - if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) || - !policy->update_limits) - return 0; - - policy->update_limits = false; + if (policy->force_target) { + /* Avoid forcing the driver callback unnecessarily next time. */ + policy->force_target = false; + } else if (target_freq == policy->cur) { + return 0; } if (cpufreq_driver->target) { @@ -2393,7 +2442,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (!cpufreq_driver->target_index) return -EINVAL; - return __target_index(policy, policy->cached_resolved_idx); + return __target_index(policy, idx); } EXPORT_SYMBOL_GPL(__cpufreq_driver_target); @@ -2412,12 +2461,17 @@ __weak struct cpufreq_governor *cpufreq_fallback_governor(void) return NULL; } +static bool cpufreq_is_suspended(struct cpufreq_policy *policy) +{ + return cpufreq_suspended || policy->suspended; +} + static int cpufreq_init_governor(struct cpufreq_policy *policy) { int ret; - /* Don't start any governor operations if we are entering suspend */ - if (cpufreq_suspended) + /* Don't start any governor operations for suspended policies. */ + if (cpufreq_is_suspended(policy)) return 0; /* * Governor might not be initiated here if ACPI _PPC changed @@ -2460,7 +2514,7 @@ static int cpufreq_init_governor(struct cpufreq_policy *policy) static void cpufreq_exit_governor(struct cpufreq_policy *policy) { - if (cpufreq_suspended || !policy->governor) + if (cpufreq_is_suspended(policy) || !policy->governor) return; pr_debug("%s: for CPU %u\n", __func__, policy->cpu); @@ -2475,7 +2529,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy) { int ret; - if (cpufreq_suspended) + if (cpufreq_is_suspended(policy)) return 0; if (!policy->governor) @@ -2499,7 +2553,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy) void cpufreq_stop_governor(struct cpufreq_policy *policy) { - if (cpufreq_suspended || !policy->governor) + if (cpufreq_is_suspended(policy) || !policy->governor) return; pr_debug("%s: for CPU %u\n", __func__, policy->cpu); @@ -2510,7 +2564,7 @@ void cpufreq_stop_governor(struct cpufreq_policy *policy) static void cpufreq_governor_limits(struct cpufreq_policy *policy) { - if (cpufreq_suspended || !policy->governor) + if (cpufreq_is_suspended(policy) || !policy->governor) return; pr_debug("%s: for CPU %u\n", __func__, policy->cpu); @@ -2630,6 +2684,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, struct cpufreq_governor *new_gov, unsigned int new_pol) { + bool need_update_limits = cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS; struct cpufreq_policy_data new_data; struct cpufreq_governor *old_gov; unsigned int freq; @@ -2666,26 +2721,26 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, * concurrently by cpufreq_driver_resolve_freq() during the update. */ freq = __resolve_freq(policy, new_data.max, new_data.min, new_data.max, - CPUFREQ_RELATION_H); + CPUFREQ_RELATION_H, NULL); if (freq != policy->max) { WRITE_ONCE(policy->max, freq); - policy->update_limits = true; + if (need_update_limits) + policy->force_target = true; } freq = __resolve_freq(policy, new_data.min, new_data.min, new_data.max, - CPUFREQ_RELATION_L); + CPUFREQ_RELATION_L, NULL); freq = min(freq, policy->max); if (freq != policy->min) { WRITE_ONCE(policy->min, freq); - policy->update_limits = true; + if (need_update_limits) + policy->force_target = true; } trace_cpu_frequency_limits(policy); cpufreq_update_pressure(policy); - policy->cached_target_freq = UINT_MAX; - pr_debug("new min and max freqs are %u - %u kHz\n", policy->min, policy->max); @@ -2711,6 +2766,12 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, cpufreq_exit_governor(policy); } + /* + * Initialize cached_target_freq while no governor is running to avoid + * racing with cpufreq_driver_resolve_freq(), which updates it. + */ + policy->cached_target_freq = UINT_MAX; + /* start new governor */ policy->governor = new_gov; ret = cpufreq_init_governor(policy); @@ -2747,7 +2808,8 @@ static void cpufreq_policy_refresh(struct cpufreq_policy *policy) * -> ask driver for current freq and notify governors about a change */ if (cpufreq_driver->get && has_target() && - (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) + (cpufreq_is_suspended(policy) || + WARN_ON(!cpufreq_verify_current_freq(policy, false)))) return; refresh_frequency_limits(policy); @@ -2810,18 +2872,24 @@ int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state) } EXPORT_SYMBOL_GPL(cpufreq_boost_set_sw); +static DEFINE_MUTEX(cpufreq_boost_mutex); + static int cpufreq_boost_trigger_state(int state) { struct cpufreq_policy *policy; unsigned long flags; + bool boost_enabled; int ret = -EOPNOTSUPP; + guard(mutex)(&cpufreq_boost_mutex); + /* * Don't compare 'cpufreq_driver->boost_enabled' with 'state' here to * make sure all policies are in sync with global boost flag. */ write_lock_irqsave(&cpufreq_driver_lock, flags); + boost_enabled = cpufreq_driver->boost_enabled; cpufreq_driver->boost_enabled = state; write_unlock_irqrestore(&cpufreq_driver_lock, flags); @@ -2830,6 +2898,8 @@ static int cpufreq_boost_trigger_state(int state) if (!policy->boost_supported) continue; + guard(cpufreq_policy_write)(policy); + ret = policy_set_boost(policy, state); if (unlikely(ret)) break; @@ -2841,7 +2911,7 @@ static int cpufreq_boost_trigger_state(int state) return 0; write_lock_irqsave(&cpufreq_driver_lock, flags); - cpufreq_driver->boost_enabled = !state; + cpufreq_driver->boost_enabled = boost_enabled; write_unlock_irqrestore(&cpufreq_driver_lock, flags); pr_err("%s: Cannot %s BOOST\n", diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c index 731f5721ff1ed1..84f32478e0216b 100644 --- a/drivers/cpufreq/imx6q-cpufreq.c +++ b/drivers/cpufreq/imx6q-cpufreq.c @@ -400,8 +400,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev) } /* Make imx6_soc_volt array's size same as arm opp number */ - imx6_soc_volt = devm_kcalloc(&pdev->dev, num, sizeof(*imx6_soc_volt), - GFP_KERNEL); + imx6_soc_volt = devm_kzalloc_objs(&pdev->dev, *imx6_soc_volt, num); if (imx6_soc_volt == NULL) { ret = -ENOMEM; goto free_freq_table; diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 0e6ae4cdda5dec..c78dcd681511cc 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -3389,10 +3389,11 @@ static void intel_cpufreq_cpu_exit(struct cpufreq_policy *policy) static int intel_cpufreq_suspend(struct cpufreq_policy *policy) { + struct cpudata *cpu = all_cpu_data[policy->cpu]; + intel_pstate_suspend(policy); if (hwp_active) { - struct cpudata *cpu = all_cpu_data[policy->cpu]; u64 value = READ_ONCE(cpu->hwp_req_cached); /* @@ -3403,6 +3404,17 @@ static int intel_cpufreq_suspend(struct cpufreq_policy *policy) value &= ~HWP_DESIRED_PERF(~0L); wrmsrq_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); WRITE_ONCE(cpu->hwp_req_cached, value); + } else { + /* + * Invalidate the cached P-state value that may be stale when + * the governor is started again during resume and may prevent + * MSR_IA32_PERF_CTL from being updated. + * + * This does not require synchronization because the core + * prevents frequency updates for suspended policies from + * occurring. + */ + cpu->pstate.current_pstate = 0; } return 0; @@ -3649,12 +3661,12 @@ static struct acpi_platform_list plat_info[] __initdata = { static bool __init intel_pstate_platform_pwr_mgmt_exists(void) { const struct x86_cpu_id *id; - u64 misc_pwr; + u64 misc_pwr = 0; int idx; id = x86_match_cpu(intel_pstate_cpu_oob_ids); if (id) { - rdmsrq(MSR_MISC_PWR_MGMT, misc_pwr); + rdmsrq_safe(MSR_MISC_PWR_MGMT, &misc_pwr); if (misc_pwr & BITMASK_OOB) { pr_debug("Bit 8 or 18 in the MISC_PWR_MGMT MSR set\n"); pr_debug("P states are controlled in Out of Band mode by the firmware/hardware\n"); diff --git a/drivers/cpufreq/loongson3_cpufreq.c b/drivers/cpufreq/loongson3_cpufreq.c index aea7c31e155a40..2eca082a86117a 100644 --- a/drivers/cpufreq/loongson3_cpufreq.c +++ b/drivers/cpufreq/loongson3_cpufreq.c @@ -279,7 +279,7 @@ static int configure_freq_table(int cpu) boost_level = ret; freq_level = min(max_level, FREQ_MAX_LEVEL); - data = devm_kzalloc(&pdev->dev, struct_size(data, table, freq_level + 1), GFP_KERNEL); + data = devm_kzalloc_flex(&pdev->dev, *data, table, freq_level + 1); if (!data) return -ENOMEM; diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediatek-cpufreq-hw.c index ae4500ab48913d..2c57371ad502d8 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -190,8 +190,7 @@ static int mtk_cpu_create_freq_table(struct platform_device *pdev, u32 temp, i, freq, prev_freq = 0; void __iomem *base_table; - data->table = devm_kcalloc(dev, LUT_MAX_ENTRIES + 1, - sizeof(*data->table), GFP_KERNEL); + data->table = devm_kzalloc_objs(dev, *data->table, LUT_MAX_ENTRIES + 1); if (!data->table) return -ENOMEM; @@ -229,7 +228,7 @@ static int mtk_cpu_resources_init(struct platform_device *pdev, int ret, i; int index; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -392,7 +391,7 @@ static int mtk_cpufreq_hw_driver_probe(struct platform_device *pdev) if (!data) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c index f9b1eca176eb80..b3d059a2e42d43 100644 --- a/drivers/cpufreq/mediatek-cpufreq.c +++ b/drivers/cpufreq/mediatek-cpufreq.c @@ -645,7 +645,7 @@ static int mtk_cpufreq_probe(struct platform_device *pdev) if (info) continue; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) { ret = dev_err_probe(&pdev->dev, -ENOMEM, "Failed to allocate dvfs_info\n"); diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c index 4a6f4d9043e994..9dee341b407e7a 100644 --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c @@ -1048,7 +1048,7 @@ static int init_chip_info(void) cpumask_t *chip_cpu_mask; int ret = 0; - chip = kcalloc(num_possible_cpus(), sizeof(*chip), GFP_KERNEL); + chip = kzalloc_objs(*chip, num_possible_cpus()); if (!chip) return -ENOMEM; diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index 060a460716f79d..2f731ec31774d5 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -696,7 +696,7 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev) if (!qcom_cpufreq.soc_data) return -ENODEV; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, num_domains), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, num_domains); if (!clk_data) return -ENOMEM; diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c index 375f12d5d11a76..efcbf3107ef571 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -507,8 +507,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) if (!ret) return -ENOENT; - drv = devm_kzalloc(&pdev->dev, struct_size(drv, cpus, num_possible_cpus()), - GFP_KERNEL); + drv = devm_kzalloc_flex(&pdev->dev, *drv, cpus, num_possible_cpus()); if (!drv) return -ENOMEM; diff --git a/drivers/cpufreq/tegra124-cpufreq.c b/drivers/cpufreq/tegra124-cpufreq.c index f8a76bbecef9e3..b0e23511bd0529 100644 --- a/drivers/cpufreq/tegra124-cpufreq.c +++ b/drivers/cpufreq/tegra124-cpufreq.c @@ -64,7 +64,7 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev) if (!np) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c index 4fa6894f637115..549a678cf9634b 100644 --- a/drivers/cpufreq/tegra186-cpufreq.c +++ b/drivers/cpufreq/tegra186-cpufreq.c @@ -309,8 +309,7 @@ static struct cpufreq_frequency_table *tegra_cpufreq_bpmp_read_lut( (*num_rates)++; } - table = devm_kcalloc(&pdev->dev, *num_rates + 1, sizeof(*table), - GFP_KERNEL); + table = devm_kzalloc_objs(&pdev->dev, *table, *num_rates + 1); if (!table) { table = ERR_PTR(-ENOMEM); goto free; @@ -356,9 +355,8 @@ static int tegra186_cpufreq_probe(struct platform_device *pdev) int num_rates = 0; u32 edvd_val, cpu; - data = devm_kzalloc(&pdev->dev, - struct_size(data, clusters, TEGRA186_NUM_CLUSTERS), - GFP_KERNEL); + data = devm_kzalloc_flex(&pdev->dev, *data, clusters, + TEGRA186_NUM_CLUSTERS); if (!data) return -ENOMEM; diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c index 1eb96e9f3310db..8599914f21944d 100644 --- a/drivers/cpufreq/tegra194-cpufreq.c +++ b/drivers/cpufreq/tegra194-cpufreq.c @@ -663,8 +663,7 @@ tegra_cpufreq_bpmp_read_lut(struct platform_device *pdev, struct tegra_bpmp *bpm num_freqs += (delta_ndiv % freq_table_step_size) ? 1 : 0; - freq_table = devm_kcalloc(&pdev->dev, num_freqs + 1, - sizeof(*freq_table), GFP_KERNEL); + freq_table = devm_kzalloc_objs(&pdev->dev, *freq_table, num_freqs + 1); if (!freq_table) return ERR_PTR(-ENOMEM); @@ -713,7 +712,7 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) int err, i; u32 cpu; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; @@ -726,8 +725,8 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) return -EINVAL; } - data->bpmp_luts = devm_kcalloc(&pdev->dev, data->soc->num_clusters, - sizeof(*data->bpmp_luts), GFP_KERNEL); + data->bpmp_luts = devm_kzalloc_objs(&pdev->dev, *data->bpmp_luts, + data->soc->num_clusters); if (!data->bpmp_luts) return -ENOMEM; @@ -738,9 +737,8 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) return PTR_ERR(data->regs); } - data->cpu_data = devm_kcalloc(&pdev->dev, data->soc->num_clusters * - data->soc->maxcpus_per_cluster, - sizeof(*data->cpu_data), GFP_KERNEL); + data->cpu_data = devm_kzalloc_objs(&pdev->dev, *data->cpu_data, + data->soc->num_clusters * data->soc->maxcpus_per_cluster); if (!data->cpu_data) return -ENOMEM; diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c index 0f96492341f29c..543bc99f125545 100644 --- a/drivers/cpufreq/ti-cpufreq.c +++ b/drivers/cpufreq/ti-cpufreq.c @@ -528,7 +528,7 @@ static int ti_cpufreq_probe(struct platform_device *pdev) if (!match) return -ENODEV; - opp_data = devm_kzalloc(&pdev->dev, sizeof(*opp_data), GFP_KERNEL); + opp_data = devm_kzalloc_obj(&pdev->dev, *opp_data); if (!opp_data) return -ENOMEM; diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 0187d6a9096a4c..3c48876aef857e 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -283,8 +283,7 @@ static int psci_dt_cpu_init_idle(struct device *dev, struct cpuidle_driver *drv, struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); state_count++; /* Add WFI state too */ - psci_states = devm_kcalloc(dev, state_count, sizeof(*psci_states), - GFP_KERNEL); + psci_states = devm_kzalloc_objs(dev, *psci_states, state_count); if (!psci_states) return -ENOMEM; @@ -370,7 +369,7 @@ static int psci_idle_init_cpu(struct device *dev, int cpu) if (ret) return ret; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; diff --git a/drivers/cpuidle/cpuidle-qcom-spm.c b/drivers/cpuidle/cpuidle-qcom-spm.c index 7ab6f68b96a825..12b81f0842ca5f 100644 --- a/drivers/cpuidle/cpuidle-qcom-spm.c +++ b/drivers/cpuidle/cpuidle-qcom-spm.c @@ -105,7 +105,7 @@ static int spm_cpuidle_register(struct device *cpuidle_dev, int cpu) if (!pdev) return -ENODEV; - data = devm_kzalloc(cpuidle_dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(cpuidle_dev, *data); if (!data) { put_device(&pdev->dev); return -ENOMEM; diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index a13e90bb43bd3f..eacffd4c02fed7 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -245,7 +245,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, if (!cpu_node) return -ENODEV; - states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL); + states = devm_kzalloc_objs(dev, *states, state_count); if (!states) return -ENOMEM; @@ -291,7 +291,7 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu) unsigned int state_count = 0; int ret = 0; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; diff --git a/drivers/cpuidle/dt_idle_genpd.c b/drivers/cpuidle/dt_idle_genpd.c index ed41a90eeeb714..7e5533fe38f2c2 100644 --- a/drivers/cpuidle/dt_idle_genpd.c +++ b/drivers/cpuidle/dt_idle_genpd.c @@ -33,7 +33,7 @@ static int pd_parse_state_nodes( if (ret) goto free_state; - state_buf = kmalloc(sizeof(u32), GFP_KERNEL); + state_buf = kmalloc_obj(u32); if (!state_buf) { ret = -ENOMEM; goto free_state; diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c index 35ef0930e77f1a..b4ea7acfad99b5 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c @@ -327,7 +327,7 @@ static int sun4i_ss_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ss = devm_kzalloc(&pdev->dev, sizeof(*ss), GFP_KERNEL); + ss = devm_kzalloc_obj(&pdev->dev, *ss); if (!ss) return -ENOMEM; diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index 21762bd408e540..6f46c530fe2696 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -696,8 +696,7 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) { int i, err; - ce->chanlist = devm_kcalloc(ce->dev, MAXFLOW, - sizeof(struct sun8i_ce_flow), GFP_KERNEL); + ce->chanlist = devm_kzalloc_objs(ce->dev, struct sun8i_ce_flow, MAXFLOW); if (!ce->chanlist) return -ENOMEM; @@ -932,7 +931,7 @@ static int sun8i_ce_probe(struct platform_device *pdev) int err, irq; u32 v; - ce = devm_kzalloc(&pdev->dev, sizeof(*ce), GFP_KERNEL); + ce = devm_kzalloc_obj(&pdev->dev, *ce); if (!ce) return -ENOMEM; diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c index 2167dd9f44c73f..0a7362350d0fa8 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c @@ -521,8 +521,7 @@ static int allocate_flows(struct sun8i_ss_dev *ss) { int i, j, err; - ss->flows = devm_kcalloc(ss->dev, MAXFLOW, sizeof(struct sun8i_ss_flow), - GFP_KERNEL); + ss->flows = devm_kzalloc_objs(ss->dev, struct sun8i_ss_flow, MAXFLOW); if (!ss->flows) return -ENOMEM; @@ -783,7 +782,7 @@ static int sun8i_ss_probe(struct platform_device *pdev) int err, irq; u32 v; - ss = devm_kzalloc(&pdev->dev, sizeof(*ss), GFP_KERNEL); + ss = devm_kzalloc_obj(&pdev->dev, *ss); if (!ss) return -ENOMEM; diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c index acf18b71e54d7c..5b5b76882cba71 100644 --- a/drivers/crypto/amcc/crypto4xx_core.c +++ b/drivers/crypto/amcc/crypto4xx_core.c @@ -1248,15 +1248,13 @@ static int crypto4xx_probe(struct platform_device *ofdev) of_node_put(np); - core_dev = devm_kzalloc( - &ofdev->dev, sizeof(struct crypto4xx_core_device), GFP_KERNEL); + core_dev = devm_kzalloc_obj(&ofdev->dev, struct crypto4xx_core_device); if (!core_dev) return -ENOMEM; dev_set_drvdata(dev, core_dev); core_dev->ofdev = ofdev; - core_dev->dev = devm_kzalloc( - &ofdev->dev, sizeof(struct crypto4xx_device), GFP_KERNEL); + core_dev->dev = devm_kzalloc_obj(&ofdev->dev, struct crypto4xx_device); if (!core_dev->dev) return -ENOMEM; diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index d5d84524c11042..48dbdf45203489 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -156,8 +156,7 @@ static int meson_allocate_chanlist(struct meson_dev *mc) { int i, err; - mc->chanlist = devm_kcalloc(mc->dev, MAXFLOW, - sizeof(struct meson_flow), GFP_KERNEL); + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); if (!mc->chanlist) return -ENOMEM; @@ -233,7 +232,7 @@ static int meson_crypto_probe(struct platform_device *pdev) struct meson_dev *mc; int err, i; - mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(&pdev->dev, *mc); if (!mc) return -ENOMEM; diff --git a/drivers/crypto/aspeed/aspeed-acry.c b/drivers/crypto/aspeed/aspeed-acry.c index 97327ba2c24b76..7ef7013aeb7dbc 100644 --- a/drivers/crypto/aspeed/aspeed-acry.c +++ b/drivers/crypto/aspeed/aspeed-acry.c @@ -708,8 +708,7 @@ static int aspeed_acry_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int rc; - acry_dev = devm_kzalloc(dev, sizeof(struct aspeed_acry_dev), - GFP_KERNEL); + acry_dev = devm_kzalloc_obj(dev, struct aspeed_acry_dev); if (!acry_dev) return -ENOMEM; diff --git a/drivers/crypto/aspeed/aspeed-hace.c b/drivers/crypto/aspeed/aspeed-hace.c index 6555d7b2afe583..4c44304ad866d2 100644 --- a/drivers/crypto/aspeed/aspeed-hace.c +++ b/drivers/crypto/aspeed/aspeed-hace.c @@ -103,8 +103,7 @@ static int aspeed_hace_probe(struct platform_device *pdev) struct aspeed_hace_dev *hace_dev; int rc; - hace_dev = devm_kzalloc(&pdev->dev, sizeof(struct aspeed_hace_dev), - GFP_KERNEL); + hace_dev = devm_kzalloc_obj(&pdev->dev, struct aspeed_hace_dev); if (!hace_dev) return -ENOMEM; diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index 84392411b98d81..cf6b5aa0269fef 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -2332,7 +2332,7 @@ static int atmel_aes_probe(struct platform_device *pdev) struct resource *aes_res; int err; - aes_dd = devm_kzalloc(&pdev->dev, sizeof(*aes_dd), GFP_KERNEL); + aes_dd = devm_kzalloc_obj(&pdev->dev, *aes_dd); if (!aes_dd) return -ENOMEM; diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index 24bded47a32bed..109e2a7ae0dc40 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -375,7 +375,7 @@ int atmel_i2c_probe(struct i2c_client *client) return -EINVAL; } - i2c_priv = devm_kmalloc(dev, sizeof(*i2c_priv), GFP_KERNEL); + i2c_priv = devm_kmalloc_obj(dev, *i2c_priv); if (!i2c_priv) return -ENOMEM; diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index 4b883a8dcf3016..d0216e3c5c76c4 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -2587,7 +2587,7 @@ static int atmel_sha_probe(struct platform_device *pdev) struct resource *sha_res; int err; - sha_dd = devm_kzalloc(&pdev->dev, sizeof(*sha_dd), GFP_KERNEL); + sha_dd = devm_kzalloc_obj(&pdev->dev, *sha_dd); if (!sha_dd) return -ENOMEM; diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c index 6b561b333ac6ae..c86d06169ab908 100644 --- a/drivers/crypto/atmel-tdes.c +++ b/drivers/crypto/atmel-tdes.c @@ -905,7 +905,7 @@ static int atmel_tdes_probe(struct platform_device *pdev) struct resource *tdes_res; int err; - tdes_dd = devm_kzalloc(&pdev->dev, sizeof(*tdes_dd), GFP_KERNEL); + tdes_dd = devm_kzalloc_obj(&pdev->dev, *tdes_dd); if (!tdes_dd) return -ENOMEM; diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 2bf8d71c86f422..e84ae65dbb63d2 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -2858,8 +2858,7 @@ static int artpec6_crypto_probe(struct platform_device *pdev) if (irq < 0) return -ENODEV; - ac = devm_kzalloc(&pdev->dev, sizeof(struct artpec6_crypto), - GFP_KERNEL); + ac = devm_kzalloc_obj(&pdev->dev, struct artpec6_crypto); if (!ac) return -ENOMEM; diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c index e9d9ca7441b604..8c3e9525c134e4 100644 --- a/drivers/crypto/bcm/cipher.c +++ b/drivers/crypto/bcm/cipher.c @@ -4290,8 +4290,8 @@ static int spu_mb_init(struct device *dev) struct mbox_client *mcl = &iproc_priv.mcl; int err, i; - iproc_priv.mbox = devm_kcalloc(dev, iproc_priv.spu.num_chan, - sizeof(struct mbox_chan *), GFP_KERNEL); + iproc_priv.mbox = devm_kzalloc_objs(dev, struct mbox_chan *, + iproc_priv.spu.num_chan); if (!iproc_priv.mbox) return -ENOMEM; diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index c95afcb2c7517a..ef67122bef57ed 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -5223,7 +5223,7 @@ static int dpaa2_caam_probe(struct fsl_mc_device *dpseci_dev) dev = &dpseci_dev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index ac515ed8c57552..2082adaae5855a 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -880,7 +880,7 @@ static void caam_rsa_free_key(struct caam_rsa_key *key) static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes) { - while (!**ptr && *nbytes) { + while (*nbytes && !**ptr) { (*ptr)++; (*nbytes)--; } @@ -896,22 +896,22 @@ static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes) * @ptr : pointer to {dP, dQ, qInv} CRT member * @nbytes: length in bytes of {dP, dQ, qInv} CRT member * @dstlen: length in bytes of corresponding p or q prime factor + * @dst : pointer to the zero-padded output buffer */ -static u8 *caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen) +static int caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen, + u8 **dst) { - u8 *dst; - caam_rsa_drop_leading_zeros(&ptr, &nbytes); - if (!nbytes) - return NULL; + if (!nbytes || nbytes > dstlen) + return -EINVAL; - dst = kzalloc(dstlen, GFP_KERNEL); - if (!dst) - return NULL; + *dst = kzalloc(dstlen, GFP_KERNEL); + if (!*dst) + return -ENOMEM; - memcpy(dst + (dstlen - nbytes), ptr, nbytes); + memcpy(*dst + (dstlen - nbytes), ptr, nbytes); - return dst; + return 0; } /** @@ -991,6 +991,7 @@ static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx, size_t p_sz = raw_key->p_sz; size_t q_sz = raw_key->q_sz; unsigned aligned_size; + int ret; rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz); if (!rsa_key->p) @@ -999,57 +1000,39 @@ static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx, rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz); if (!rsa_key->q) - goto free_p; + return -ENOMEM; rsa_key->q_sz = q_sz; aligned_size = ALIGN(raw_key->p_sz, dma_get_cache_alignment()); rsa_key->tmp1 = kzalloc(aligned_size, GFP_KERNEL); if (!rsa_key->tmp1) - goto free_q; + return -ENOMEM; aligned_size = ALIGN(raw_key->q_sz, dma_get_cache_alignment()); rsa_key->tmp2 = kzalloc(aligned_size, GFP_KERNEL); if (!rsa_key->tmp2) - goto free_tmp1; + return -ENOMEM; rsa_key->priv_form = FORM2; - rsa_key->dp = caam_read_rsa_crt(raw_key->dp, raw_key->dp_sz, p_sz); - if (!rsa_key->dp) - goto free_tmp2; + ret = caam_read_rsa_crt(raw_key->dp, raw_key->dp_sz, p_sz, + &rsa_key->dp); + if (ret) + return ret; - rsa_key->dq = caam_read_rsa_crt(raw_key->dq, raw_key->dq_sz, q_sz); - if (!rsa_key->dq) - goto free_dp; + ret = caam_read_rsa_crt(raw_key->dq, raw_key->dq_sz, q_sz, + &rsa_key->dq); + if (ret) + return ret; - rsa_key->qinv = caam_read_rsa_crt(raw_key->qinv, raw_key->qinv_sz, - q_sz); - if (!rsa_key->qinv) - goto free_dq; + ret = caam_read_rsa_crt(raw_key->qinv, raw_key->qinv_sz, p_sz, + &rsa_key->qinv); + if (ret) + return ret; rsa_key->priv_form = FORM3; return 0; - -free_dq: - kfree_sensitive(rsa_key->dq); - rsa_key->dq = NULL; -free_dp: - kfree_sensitive(rsa_key->dp); - rsa_key->dp = NULL; -free_tmp2: - kfree_sensitive(rsa_key->tmp2); - rsa_key->tmp2 = NULL; -free_tmp1: - kfree_sensitive(rsa_key->tmp1); - rsa_key->tmp1 = NULL; -free_q: - kfree_sensitive(rsa_key->q); - rsa_key->q = NULL; -free_p: - kfree_sensitive(rsa_key->p); - rsa_key->p = NULL; - return -ENOMEM; } static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, @@ -1067,6 +1050,8 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, if (ret) return ret; + ret = -ENOMEM; + /* Copy key in DMA zone */ rsa_key->d = kmemdup(raw_key.d, raw_key.d_sz, GFP_KERNEL); if (!rsa_key->d) @@ -1103,7 +1088,7 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, err: caam_rsa_free_key(rsa_key); - return -ENOMEM; + return ret; } static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 0eb43c8625164f..de5d5ab0f64221 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -284,7 +284,7 @@ int caam_rng_init(struct device *ctrldev) if (!devres_open_group(ctrldev, caam_rng_init, GFP_KERNEL)) return -ENOMEM; - ctx = devm_kzalloc(ctrldev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(ctrldev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 320be5d7773789..6a9db10396b62c 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -873,7 +873,7 @@ static int caam_probe(struct platform_device *pdev) bool reg_access = true; const struct caam_imx_data *imx_soc_data; - ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL); + ctrlpriv = devm_kzalloc_obj(&pdev->dev, *ctrlpriv); if (!ctrlpriv) return -ENOMEM; diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index cf725a6ac0fb9b..0c03d7bcba1919 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -542,8 +542,7 @@ static int caam_jr_init(struct device *dev) if (!jrp->outring) return -ENOMEM; - jrp->entinfo = devm_kcalloc(dev, JOBR_DEPTH, sizeof(*jrp->entinfo), - GFP_KERNEL); + jrp->entinfo = devm_kzalloc_objs(dev, *jrp->entinfo, JOBR_DEPTH); if (!jrp->entinfo) return -ENOMEM; @@ -612,7 +611,7 @@ static int caam_jr_probe(struct platform_device *pdev) return irq; jrdev = &pdev->dev; - jrpriv = devm_kzalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL); + jrpriv = devm_kzalloc_obj(jrdev, *jrpriv); if (!jrpriv) return -ENOMEM; diff --git a/drivers/crypto/cavium/cpt/cptpf_main.c b/drivers/crypto/cavium/cpt/cptpf_main.c index 4234f9f156a3d6..c90b7b83f2f6f5 100644 --- a/drivers/crypto/cavium/cpt/cptpf_main.c +++ b/drivers/crypto/cavium/cpt/cptpf_main.c @@ -553,7 +553,7 @@ static int cpt_probe(struct pci_dev *pdev, const struct pci_device_id *ent) num_vfs = 4; } - cpt = devm_kzalloc(dev, sizeof(*cpt), GFP_KERNEL); + cpt = devm_kzalloc_obj(dev, *cpt); if (!cpt) return -ENOMEM; diff --git a/drivers/crypto/cavium/cpt/cptvf_main.c b/drivers/crypto/cavium/cpt/cptvf_main.c index e07448098ac035..ab7a2e83c0e726 100644 --- a/drivers/crypto/cavium/cpt/cptvf_main.c +++ b/drivers/crypto/cavium/cpt/cptvf_main.c @@ -665,7 +665,7 @@ static int cptvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) struct cpt_vf *cptvf; int err; - cptvf = devm_kzalloc(dev, sizeof(*cptvf), GFP_KERNEL); + cptvf = devm_kzalloc_obj(dev, *cptvf); if (!cptvf) return -ENOMEM; diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index aff3348b83510d..41d9bdac95d7ea 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -477,7 +477,7 @@ struct ccp_device *ccp_alloc_struct(struct sp_device *sp) struct device *dev = sp->dev; struct ccp_device *ccp; - ccp = devm_kzalloc(dev, sizeof(*ccp), GFP_KERNEL); + ccp = devm_kzalloc_obj(dev, *ccp); if (!ccp) return NULL; ccp->dev = dev; diff --git a/drivers/crypto/ccp/ccp-dmaengine.c b/drivers/crypto/ccp/ccp-dmaengine.c index b386a7063818bc..ebe62fe0b31ff6 100644 --- a/drivers/crypto/ccp/ccp-dmaengine.c +++ b/drivers/crypto/ccp/ccp-dmaengine.c @@ -675,9 +675,8 @@ int ccp_dmaengine_register(struct ccp_device *ccp) if (!dmaengine) return 0; - ccp->ccp_dma_chan = devm_kcalloc(ccp->dev, ccp->cmd_q_count, - sizeof(*(ccp->ccp_dma_chan)), - GFP_KERNEL); + ccp->ccp_dma_chan = devm_kzalloc_objs(ccp->dev, *(ccp->ccp_dma_chan), + ccp->cmd_q_count); if (!ccp->ccp_dma_chan) return -ENOMEM; diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index 4db49a14550c97..0a2065d7308ff6 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -195,7 +195,7 @@ int dbc_dev_init(struct psp_device *psp) struct psp_dbc_device *dbc_dev; int ret; - dbc_dev = devm_kzalloc(dev, sizeof(*dbc_dev), GFP_KERNEL); + dbc_dev = devm_kzalloc_obj(dev, *dbc_dev); if (!dbc_dev) return -ENOMEM; diff --git a/drivers/crypto/ccp/platform-access.c b/drivers/crypto/ccp/platform-access.c index 1b8ed33897332e..d4b145bcf78b86 100644 --- a/drivers/crypto/ccp/platform-access.c +++ b/drivers/crypto/ccp/platform-access.c @@ -208,7 +208,7 @@ int platform_access_dev_init(struct psp_device *psp) struct device *dev = psp->dev; struct psp_platform_access_device *pa_dev; - pa_dev = devm_kzalloc(dev, sizeof(*pa_dev), GFP_KERNEL); + pa_dev = devm_kzalloc_obj(dev, *pa_dev); if (!pa_dev) return -ENOMEM; diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index b14ce51065d5da..4e64217f8c2dab 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -109,7 +109,7 @@ static struct psp_device *psp_alloc_struct(struct sp_device *sp) struct device *dev = sp->dev; struct psp_device *psp; - psp = devm_kzalloc(dev, sizeof(*psp), GFP_KERNEL); + psp = devm_kzalloc_obj(dev, *psp); if (!psp) return NULL; diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 5c996ab6389594..52fb208b71ab4a 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1916,6 +1916,8 @@ static int sev_ioctl_do_reset(struct sev_issue_cmd *argp, bool writable) if (!writable) return -EPERM; + mutex_lock(&sev_cmd_mutex); + /* * The SEV spec requires that FACTORY_RESET must be issued in * UNINIT state. Before we go further lets check if any guest is @@ -1927,18 +1929,24 @@ static int sev_ioctl_do_reset(struct sev_issue_cmd *argp, bool writable) */ rc = sev_get_platform_state(&state, &argp->error); if (rc) - return rc; + goto out_unlock; - if (state == SEV_STATE_WORKING) - return -EBUSY; + if (state == SEV_STATE_WORKING) { + rc = -EBUSY; + goto out_unlock; + } if (state == SEV_STATE_INIT) { rc = __sev_platform_shutdown_locked(&argp->error); if (rc) - return rc; + goto out_unlock; } - return __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET, NULL, &argp->error); + rc = __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET, NULL, &argp->error); + +out_unlock: + mutex_unlock(&sev_cmd_mutex); + return rc; } static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp) @@ -1948,7 +1956,9 @@ static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp) memset(&data, 0, sizeof(data)); + mutex_lock(&sev_cmd_mutex); ret = __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS, &data, &argp->error); + mutex_unlock(&sev_cmd_mutex); if (ret) return ret; @@ -1967,10 +1977,12 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr if (!writable) return -EPERM; + mutex_lock(&sev_cmd_mutex); + if (sev->sev_plat_status.state == SEV_STATE_UNINIT) { rc = sev_move_to_init_state(argp, &shutdown_required); if (rc) - return rc; + goto out_unlock; } rc = __sev_do_cmd_locked(cmd, NULL, &argp->error); @@ -1978,6 +1990,9 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr if (shutdown_required) __sev_firmware_shutdown(sev, false); +out_unlock: + mutex_unlock(&sev_cmd_mutex); + return rc; } @@ -2016,14 +2031,24 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) data.len = input.length; cmd: + mutex_lock(&sev_cmd_mutex); + if (sev->sev_plat_status.state == SEV_STATE_UNINIT) { ret = sev_move_to_init_state(argp, &shutdown_required); - if (ret) + if (ret) { + mutex_unlock(&sev_cmd_mutex); + /* No shutdown is needed if init fails */ goto e_free_blob; + } } ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, &data, &argp->error); + if (shutdown_required) + __sev_firmware_shutdown(sev, false); + + mutex_unlock(&sev_cmd_mutex); + /* * Firmware will returns the length of the CSR blob (either the minimum * required length or the actual length written), return it to the user. @@ -2044,9 +2069,6 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) } e_free_blob: - if (shutdown_required) - __sev_firmware_shutdown(sev, false); - kfree(blob); return ret; } @@ -2319,19 +2341,26 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable) data.oca_cert_address = __psp_pa(oca_blob); data.oca_cert_len = input.oca_cert_len; + mutex_lock(&sev_cmd_mutex); + /* If platform is not in INIT state then transition it to INIT */ if (sev->sev_plat_status.state != SEV_STATE_INIT) { ret = sev_move_to_init_state(argp, &shutdown_required); - if (ret) + if (ret) { + mutex_unlock(&sev_cmd_mutex); + /* No shutdown is needed if init fails */ goto e_free_oca; + } } ret = __sev_do_cmd_locked(SEV_CMD_PEK_CERT_IMPORT, &data, &argp->error); -e_free_oca: if (shutdown_required) __sev_firmware_shutdown(sev, false); + mutex_unlock(&sev_cmd_mutex); + +e_free_oca: kfree(oca_blob); e_free_pek: kfree(pek_blob); @@ -2374,7 +2403,9 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp) data.len = 0; } + mutex_lock(&sev_cmd_mutex); ret = __sev_do_cmd_locked(SEV_CMD_GET_ID, &data, &argp->error); + mutex_unlock(&sev_cmd_mutex); /* * Firmware will return the length of the ID value (either the minimum @@ -2432,7 +2463,9 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp) data->address = __psp_pa(id_blob); data->len = user_size; + mutex_lock(&sev_cmd_mutex); ret = __sev_do_cmd_locked(SEV_CMD_GET_ID, data, &argp->error); + mutex_unlock(&sev_cmd_mutex); if (!ret) { if (copy_to_user((void __user *)argp->data, id_blob, data->len)) ret = -EFAULT; @@ -2494,19 +2527,30 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) data.cert_chain_len = input.cert_chain_len; cmd: + mutex_lock(&sev_cmd_mutex); + /* If platform is not in INIT state then transition it to INIT. */ if (sev->sev_plat_status.state != SEV_STATE_INIT) { if (!writable) { ret = -EPERM; + mutex_unlock(&sev_cmd_mutex); goto e_free_cert; } ret = sev_move_to_init_state(argp, &shutdown_required); - if (ret) + if (ret) { + /* No shutdown is needed if init fails */ + mutex_unlock(&sev_cmd_mutex); goto e_free_cert; + } } ret = __sev_do_cmd_locked(SEV_CMD_PDH_CERT_EXPORT, &data, &argp->error); + if (shutdown_required) + __sev_firmware_shutdown(sev, false); + + mutex_unlock(&sev_cmd_mutex); + /* * Firmware will return the length of the blobs (either the minimum * required length or the actual length written), return 'em to the user. @@ -2537,9 +2581,6 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) } e_free_cert: - if (shutdown_required) - __sev_firmware_shutdown(sev, false); - kfree(cert_blob); e_free_pdh: kfree(pdh_blob); @@ -2561,6 +2602,8 @@ static int __sev_do_snp_platform_status(struct sev_user_data_snp_status *status, data = page_address(status_page); + mutex_lock(&sev_cmd_mutex); + /* * SNP_PLATFORM_STATUS can be executed in any SNP state. But if executed * when SNP has been initialized, the status page must be firmware-owned. @@ -2572,6 +2615,7 @@ static int __sev_do_snp_platform_status(struct sev_user_data_snp_status *status, */ if (rmp_mark_pages_firmware(__pa(data), 1, true)) { ret = -EFAULT; + mutex_unlock(&sev_cmd_mutex); goto cleanup; } } @@ -2585,10 +2629,14 @@ static int __sev_do_snp_platform_status(struct sev_user_data_snp_status *status, * in Firmware state on failure. Use snp_reclaim_pages() to * transition either case back to Hypervisor-owned state. */ - if (snp_reclaim_pages(__pa(data), 1, true)) + if (snp_reclaim_pages(__pa(data), 1, true)) { + mutex_unlock(&sev_cmd_mutex); return -EFAULT; + } } + mutex_unlock(&sev_cmd_mutex); + if (ret) goto cleanup; @@ -2625,7 +2673,9 @@ static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp) buf.len = sizeof(buf); + mutex_lock(&sev_cmd_mutex); ret = __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error); + mutex_unlock(&sev_cmd_mutex); return ret; } @@ -2634,6 +2684,7 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable { struct sev_device *sev = psp_master->sev_data; struct sev_user_data_snp_config config; + int ret; if (!argp->data) return -EINVAL; @@ -2647,7 +2698,11 @@ static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable if (copy_from_user(&config, (void __user *)argp->data, sizeof(config))) return -EFAULT; - return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); + mutex_lock(&sev_cmd_mutex); + ret = __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); + mutex_unlock(&sev_cmd_mutex); + + return ret; } static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable) @@ -2679,7 +2734,10 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable) input.vlek_wrapped_address = __psp_pa(blob); + mutex_lock(&sev_cmd_mutex); ret = __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error); + mutex_unlock(&sev_cmd_mutex); + kfree(blob); return ret; @@ -2704,8 +2762,6 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) if (input.cmd > SEV_MAX) return -EINVAL; - mutex_lock(&sev_cmd_mutex); - switch (input.cmd) { case SEV_FACTORY_RESET: @@ -2756,7 +2812,6 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) if (copy_to_user(argp, &input, sizeof(struct sev_issue_cmd))) ret = -EFAULT; out: - mutex_unlock(&sev_cmd_mutex); return ret; } @@ -2854,7 +2909,7 @@ int sev_dev_init(struct psp_device *psp) return 0; } - sev = devm_kzalloc(dev, sizeof(*sev), GFP_KERNEL); + sev = devm_kzalloc_obj(dev, *sev); if (!sev) goto e_err; @@ -3105,9 +3160,7 @@ static int get_v1_svn(struct sev_device *sev) struct sev_user_data_snp_status status; int ret, error = 0; - mutex_lock(&sev_cmd_mutex); ret = __sev_do_snp_platform_status(&status, &error); - mutex_unlock(&sev_cmd_mutex); if (ret < 0) return ret; @@ -3122,9 +3175,7 @@ static int get_v2_svn(struct sev_device *sev) struct sev_snp_tcb_version_turin *tcb; int ret, error = 0; - mutex_lock(&sev_cmd_mutex); ret = __sev_do_snp_platform_status(&status, &error); - mutex_unlock(&sev_cmd_mutex); if (ret < 0) return ret; diff --git a/drivers/crypto/ccp/sfs.c b/drivers/crypto/ccp/sfs.c index 530141f8bc743b..e4a81fcb11fb4a 100644 --- a/drivers/crypto/ccp/sfs.c +++ b/drivers/crypto/ccp/sfs.c @@ -258,7 +258,7 @@ int sfs_dev_init(struct psp_device *psp) struct page *page; int ret = -ENOMEM; - sfs_dev = devm_kzalloc(dev, sizeof(*sfs_dev), GFP_KERNEL); + sfs_dev = devm_kzalloc_obj(dev, *sfs_dev); if (!sfs_dev) return -ENOMEM; diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index f204aa5df96e24..331fa730bc411f 100644 --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -178,7 +178,7 @@ struct sp_device *sp_alloc_struct(struct device *dev) { struct sp_device *sp; - sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL); + sp = devm_kzalloc_obj(dev, *sp); if (!sp) return NULL; diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index ede6ff9ad0c24e..892dc00c25c264 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -242,7 +242,7 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!sp) goto e_err; - sp_pci = devm_kzalloc(dev, sizeof(*sp_pci), GFP_KERNEL); + sp_pci = devm_kzalloc_obj(dev, *sp_pci); if (!sp_pci) goto e_err; diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c index c7ac840cbe136a..78676170793774 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -107,7 +107,7 @@ static int sp_platform_probe(struct platform_device *pdev) if (!sp) goto e_err; - sp_platform = devm_kzalloc(dev, sizeof(*sp_platform), GFP_KERNEL); + sp_platform = devm_kzalloc_obj(dev, *sp_platform); if (!sp_platform) goto e_err; diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index 3e3645980e8986..4bdc41e6d91423 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -193,7 +193,7 @@ int tee_dev_init(struct psp_device *psp) int ret; ret = -ENOMEM; - tee = devm_kzalloc(dev, sizeof(*tee), GFP_KERNEL); + tee = devm_kzalloc_obj(dev, *tee); if (!tee) goto e_err; diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c index d57a98f89e536c..849b18a44c61a2 100644 --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -2564,7 +2564,7 @@ static struct cc_crypto_alg *cc_create_aead_alg(struct cc_alg_template *tmpl, struct cc_crypto_alg *t_alg; struct aead_alg *alg; - t_alg = devm_kzalloc(dev, sizeof(*t_alg), GFP_KERNEL); + t_alg = devm_kzalloc_obj(dev, *t_alg); if (!t_alg) return ERR_PTR(-ENOMEM); @@ -2615,7 +2615,7 @@ int cc_aead_alloc(struct cc_drvdata *drvdata) int alg; struct device *dev = drvdata_to_dev(drvdata); - aead_handle = devm_kmalloc(dev, sizeof(*aead_handle), GFP_KERNEL); + aead_handle = devm_kmalloc_obj(dev, *aead_handle); if (!aead_handle) { rc = -ENOMEM; goto fail0; diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 5339b3796c80e3..039039141609f5 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -1379,7 +1379,7 @@ static struct cc_crypto_alg *cc_create_alg(const struct cc_alg_template *tmpl, struct cc_crypto_alg *t_alg; struct skcipher_alg *alg; - t_alg = devm_kzalloc(dev, sizeof(*t_alg), GFP_KERNEL); + t_alg = devm_kzalloc_obj(dev, *t_alg); if (!t_alg) return ERR_PTR(-ENOMEM); diff --git a/drivers/crypto/ccree/cc_debugfs.c b/drivers/crypto/ccree/cc_debugfs.c index 8f008f024f8f1b..380cd3a46d46e1 100644 --- a/drivers/crypto/ccree/cc_debugfs.c +++ b/drivers/crypto/ccree/cc_debugfs.c @@ -65,7 +65,7 @@ int cc_debugfs_init(struct cc_drvdata *drvdata) struct device *dev = drvdata_to_dev(drvdata); struct debugfs_regset32 *regset, *verset; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return -ENOMEM; @@ -80,7 +80,7 @@ int cc_debugfs_init(struct cc_drvdata *drvdata) debugfs_create_regset32("regs", 0400, drvdata->dir, regset); debugfs_create_bool("coherent", 0400, drvdata->dir, &drvdata->coherent); - verset = devm_kzalloc(dev, sizeof(*verset), GFP_KERNEL); + verset = devm_kzalloc_obj(dev, *verset); /* Failing here is not important enough to fail the module load */ if (!verset) return 0; diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index 28a23cd572d683..fdd4b74953a75c 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -316,7 +316,7 @@ static int init_cc_resources(struct platform_device *plat_dev) int irq; int rc = 0; - new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL); + new_drvdata = devm_kzalloc_obj(dev, *new_drvdata); if (!new_drvdata) return -ENOMEM; diff --git a/drivers/crypto/ccree/cc_fips.c b/drivers/crypto/ccree/cc_fips.c index 702aefc214473b..b6f27188c12f29 100644 --- a/drivers/crypto/ccree/cc_fips.c +++ b/drivers/crypto/ccree/cc_fips.c @@ -136,7 +136,7 @@ int cc_fips_init(struct cc_drvdata *p_drvdata) if (p_drvdata->hw_rev < CC_HW_REV_712) return 0; - fips_h = devm_kzalloc(dev, sizeof(*fips_h), GFP_KERNEL); + fips_h = devm_kzalloc_obj(dev, *fips_h); if (!fips_h) return -ENOMEM; diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c index 5de721a2ca30ae..949ba58ebf2d44 100644 --- a/drivers/crypto/ccree/cc_hash.c +++ b/drivers/crypto/ccree/cc_hash.c @@ -1827,7 +1827,7 @@ static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template, struct crypto_alg *alg; struct ahash_alg *halg; - t_crypto_alg = devm_kzalloc(dev, sizeof(*t_crypto_alg), GFP_KERNEL); + t_crypto_alg = devm_kzalloc_obj(dev, *t_crypto_alg); if (!t_crypto_alg) return ERR_PTR(-ENOMEM); @@ -1956,7 +1956,7 @@ int cc_hash_alloc(struct cc_drvdata *drvdata) int rc = 0; int alg; - hash_handle = devm_kzalloc(dev, sizeof(*hash_handle), GFP_KERNEL); + hash_handle = devm_kzalloc_obj(dev, *hash_handle); if (!hash_handle) return -ENOMEM; diff --git a/drivers/crypto/gemini/sl3516-ce-core.c b/drivers/crypto/gemini/sl3516-ce-core.c index c1df5f96ea4216..ac0e6ef2b7b105 100644 --- a/drivers/crypto/gemini/sl3516-ce-core.c +++ b/drivers/crypto/gemini/sl3516-ce-core.c @@ -398,7 +398,7 @@ static int sl3516_ce_probe(struct platform_device *pdev) int err, irq; u32 v; - ce = devm_kzalloc(&pdev->dev, sizeof(*ce), GFP_KERNEL); + ce = devm_kzalloc_obj(&pdev->dev, *ce); if (!ce) return -ENOMEM; diff --git a/drivers/crypto/hisilicon/debugfs.c b/drivers/crypto/hisilicon/debugfs.c index 3ee6de16e3f111..1f18309f856ec0 100644 --- a/drivers/crypto/hisilicon/debugfs.c +++ b/drivers/crypto/hisilicon/debugfs.c @@ -915,7 +915,7 @@ static int qm_last_regs_init(struct hisi_qm *qm) if (qm->fun_type == QM_HW_VF) return 0; - debug->qm_last_words = kcalloc(dfx_regs_num, sizeof(unsigned int), GFP_KERNEL); + debug->qm_last_words = kzalloc_objs(unsigned int, dfx_regs_num); if (!debug->qm_last_words) return -ENOMEM; diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index fd3c34daceb7a2..4f8851468c918a 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -1043,7 +1043,7 @@ static int hpre_pf_comm_regs_debugfs_init(struct hisi_qm *qm) struct device *dev = &qm->pdev->dev; struct debugfs_regset32 *regset; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return -ENOMEM; @@ -1074,7 +1074,7 @@ static int hpre_cluster_debugfs_init(struct hisi_qm *qm) return -EINVAL; tmp_d = debugfs_create_dir(buf, qm->debug.debug_root); - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return -ENOMEM; @@ -1203,7 +1203,7 @@ static int hpre_pre_store_cap_reg(struct hisi_qm *qm) size_t i, size; size = ARRAY_SIZE(hpre_cap_query_info); - hpre_cap = devm_kcalloc(dev, size, sizeof(*hpre_cap), GFP_KERNEL); + hpre_cap = devm_kzalloc_objs(dev, *hpre_cap, size); if (!hpre_cap) return -ENOMEM; @@ -1581,7 +1581,7 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct hpre *hpre; int ret; - hpre = devm_kzalloc(&pdev->dev, sizeof(*hpre), GFP_KERNEL); + hpre = devm_kzalloc_obj(&pdev->dev, *hpre); if (!hpre) return -ENOMEM; diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 7d13476451e361..5f223e3487c71c 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -3117,8 +3117,7 @@ static int hisi_qp_memory_init(struct hisi_qm *qm, size_t dma_size, int id, struct hisi_qp *qp; int ret = -ENOMEM; - qm->poll_data[id].qp_finish_id = kcalloc(qm->qp_num, sizeof(u16), - GFP_KERNEL); + qm->poll_data[id].qp_finish_id = kzalloc_objs(u16, qm->qp_num); if (!qm->poll_data[id].qp_finish_id) return -ENOMEM; @@ -5732,7 +5731,7 @@ static int qm_pre_store_caps(struct hisi_qm *qm) size_t i, size; size = ARRAY_SIZE(qm_cap_query_info); - qm_cap = devm_kcalloc(&pdev->dev, sizeof(*qm_cap), size, GFP_KERNEL); + qm_cap = devm_kzalloc_objs(&pdev->dev, *qm_cap, size); if (!qm_cap) return -ENOMEM; diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c index 1e0412c70c72ad..dcadcd99aeb1cb 100644 --- a/drivers/crypto/hisilicon/sec2/sec_main.c +++ b/drivers/crypto/hisilicon/sec2/sec_main.c @@ -953,7 +953,7 @@ static int sec_core_debug_init(struct hisi_qm *qm) tmp_d = debugfs_create_dir("sec_dfx", qm->debug.debug_root); - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return -ENOMEM; @@ -1274,7 +1274,7 @@ static int sec_pre_store_cap_reg(struct hisi_qm *qm) size_t i, size; size = ARRAY_SIZE(sec_cap_query_info); - sec_cap = devm_kcalloc(&pdev->dev, size, sizeof(*sec_cap), GFP_KERNEL); + sec_cap = devm_kzalloc_objs(&pdev->dev, *sec_cap, size); if (!sec_cap) return -ENOMEM; @@ -1413,7 +1413,7 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct hisi_qm *qm; int ret; - sec = devm_kzalloc(&pdev->dev, sizeof(*sec), GFP_KERNEL); + sec = devm_kzalloc_obj(&pdev->dev, *sec); if (!sec) return -ENOMEM; diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c index 10091ad4a6a8d5..1c7ae10cc272ad 100644 --- a/drivers/crypto/hisilicon/zip/zip_main.c +++ b/drivers/crypto/hisilicon/zip/zip_main.c @@ -907,7 +907,7 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm) scnprintf(buf, sizeof(buf), "decomp_core%d", i - zip_comp_core_num); - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return -ENOENT; @@ -1361,7 +1361,7 @@ static int hisi_zip_pf_probe_init(struct hisi_zip *hisi_zip) struct hisi_zip_ctrl *ctrl; int ret; - ctrl = devm_kzalloc(&qm->pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&qm->pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -1389,7 +1389,7 @@ static int zip_pre_store_cap_reg(struct hisi_qm *qm) size_t i, size; size = ARRAY_SIZE(zip_cap_query_info); - zip_cap = devm_kcalloc(&pdev->dev, size, sizeof(*zip_cap), GFP_KERNEL); + zip_cap = devm_kzalloc_objs(&pdev->dev, *zip_cap, size); if (!zip_cap) return -ENOMEM; @@ -1524,7 +1524,7 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct hisi_qm *qm; int ret; - hisi_zip = devm_kzalloc(&pdev->dev, sizeof(*hisi_zip), GFP_KERNEL); + hisi_zip = devm_kzalloc_obj(&pdev->dev, *hisi_zip); if (!hisi_zip) return -ENOMEM; diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c index 1ccfc0eccc737b..a958a58e9c4aa8 100644 --- a/drivers/crypto/img-hash.c +++ b/drivers/crypto/img-hash.c @@ -926,7 +926,7 @@ static int img_hash_probe(struct platform_device *pdev) int irq; int err; - hdev = devm_kzalloc(dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(dev, *hdev); if (hdev == NULL) return -ENOMEM; diff --git a/drivers/crypto/inside-secure/eip93/eip93-main.c b/drivers/crypto/inside-secure/eip93/eip93-main.c index e62785952b0dbb..50a66a3b4a2f68 100644 --- a/drivers/crypto/inside-secure/eip93/eip93-main.c +++ b/drivers/crypto/inside-secure/eip93/eip93-main.c @@ -415,7 +415,7 @@ static int eip93_crypto_probe(struct platform_device *pdev) u32 ver, algo_flags; int ret; - eip93 = devm_kzalloc(dev, struct_size(eip93, ring, 1), GFP_KERNEL); + eip93 = devm_kzalloc_flex(dev, *eip93, ring, 1); if (!eip93) return -ENOMEM; diff --git a/drivers/crypto/inside-secure/safexcel.c b/drivers/crypto/inside-secure/safexcel.c index 71b920e17e980c..c8b559bf084fcc 100644 --- a/drivers/crypto/inside-secure/safexcel.c +++ b/drivers/crypto/inside-secure/safexcel.c @@ -1609,9 +1609,7 @@ static int safexcel_probe_generic(void *pdev, } /* Register the ring IRQ handlers and configure the rings */ - priv->ring = devm_kcalloc(dev, priv->config.rings, - sizeof(*priv->ring), - GFP_KERNEL); + priv->ring = devm_kzalloc_objs(dev, *priv->ring, priv->config.rings); if (!priv->ring) return -ENOMEM; @@ -1628,16 +1626,15 @@ static int safexcel_probe_generic(void *pdev, goto err_cleanup_rings; } - priv->ring[i].rdr_req = devm_kcalloc(dev, - EIP197_DEFAULT_RING_SIZE, - sizeof(*priv->ring[i].rdr_req), - GFP_KERNEL); + priv->ring[i].rdr_req = devm_kzalloc_objs(dev, + *priv->ring[i].rdr_req, + EIP197_DEFAULT_RING_SIZE); if (!priv->ring[i].rdr_req) { ret = -ENOMEM; goto err_cleanup_rings; } - ring_irq = devm_kzalloc(dev, sizeof(*ring_irq), GFP_KERNEL); + ring_irq = devm_kzalloc_obj(dev, *ring_irq); if (!ring_irq) { ret = -ENOMEM; goto err_cleanup_rings; @@ -1737,7 +1734,7 @@ static int safexcel_probe(struct platform_device *pdev) struct safexcel_crypto_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -1891,7 +1888,7 @@ static int safexcel_pci_probe(struct pci_dev *pdev, ent->vendor, ent->device, ent->subvendor, ent->subdevice, ent->driver_data); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/crypto/intel/keembay/keembay-ocs-aes-core.c b/drivers/crypto/intel/keembay/keembay-ocs-aes-core.c index 660830c36e14cf..91fc0991a1e496 100644 --- a/drivers/crypto/intel/keembay/keembay-ocs-aes-core.c +++ b/drivers/crypto/intel/keembay/keembay-ocs-aes-core.c @@ -1585,7 +1585,7 @@ static int kmb_ocs_aes_probe(struct platform_device *pdev) struct ocs_aes_dev *aes_dev; int rc; - aes_dev = devm_kzalloc(dev, sizeof(*aes_dev), GFP_KERNEL); + aes_dev = devm_kzalloc_obj(dev, *aes_dev); if (!aes_dev) return -ENOMEM; diff --git a/drivers/crypto/intel/keembay/keembay-ocs-ecc.c b/drivers/crypto/intel/keembay/keembay-ocs-ecc.c index 9bdee39dc4e1a2..e8d6001be89462 100644 --- a/drivers/crypto/intel/keembay/keembay-ocs-ecc.c +++ b/drivers/crypto/intel/keembay/keembay-ocs-ecc.c @@ -872,7 +872,7 @@ static int kmb_ocs_ecc_probe(struct platform_device *pdev) struct ocs_ecc_dev *ecc_dev; int rc; - ecc_dev = devm_kzalloc(dev, sizeof(*ecc_dev), GFP_KERNEL); + ecc_dev = devm_kzalloc_obj(dev, *ecc_dev); if (!ecc_dev) return -ENOMEM; diff --git a/drivers/crypto/intel/keembay/keembay-ocs-hcu-core.c b/drivers/crypto/intel/keembay/keembay-ocs-hcu-core.c index 9a67bb4ecc8228..c2bc05901418a2 100644 --- a/drivers/crypto/intel/keembay/keembay-ocs-hcu-core.c +++ b/drivers/crypto/intel/keembay/keembay-ocs-hcu-core.c @@ -1179,7 +1179,7 @@ static int kmb_ocs_hcu_probe(struct platform_device *pdev) struct ocs_hcu_dev *hcu_dev; int rc; - hcu_dev = devm_kzalloc(dev, sizeof(*hcu_dev), GFP_KERNEL); + hcu_dev = devm_kzalloc_obj(dev, *hcu_dev); if (!hcu_dev) return -ENOMEM; diff --git a/drivers/crypto/intel/qat/qat_420xx/adf_drv.c b/drivers/crypto/intel/qat/qat_420xx/adf_drv.c index 0f0827e2b0bdcf..7f6da12ab7579d 100644 --- a/drivers/crypto/intel/qat/qat_420xx/adf_drv.c +++ b/drivers/crypto/intel/qat/qat_420xx/adf_drv.c @@ -50,7 +50,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -EINVAL; } - accel_dev = devm_kzalloc(&pdev->dev, sizeof(*accel_dev), GFP_KERNEL); + accel_dev = devm_kzalloc_obj(&pdev->dev, *accel_dev); if (!accel_dev) return -ENOMEM; @@ -69,7 +69,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) accel_dev->owner = THIS_MODULE; /* Allocate and initialise device hardware meta-data structure */ - hw_data = devm_kzalloc(&pdev->dev, sizeof(*hw_data), GFP_KERNEL); + hw_data = devm_kzalloc_obj(&pdev->dev, *hw_data); if (!hw_data) { ret = -ENOMEM; goto out_err; diff --git a/drivers/crypto/intel/qat/qat_4xxx/adf_drv.c b/drivers/crypto/intel/qat/qat_4xxx/adf_drv.c index aa95f762cb4b46..df00316e444e34 100644 --- a/drivers/crypto/intel/qat/qat_4xxx/adf_drv.c +++ b/drivers/crypto/intel/qat/qat_4xxx/adf_drv.c @@ -52,7 +52,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -EINVAL; } - accel_dev = devm_kzalloc(&pdev->dev, sizeof(*accel_dev), GFP_KERNEL); + accel_dev = devm_kzalloc_obj(&pdev->dev, *accel_dev); if (!accel_dev) return -ENOMEM; @@ -71,7 +71,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) accel_dev->owner = THIS_MODULE; /* Allocate and initialise device hardware meta-data structure */ - hw_data = devm_kzalloc(&pdev->dev, sizeof(*hw_data), GFP_KERNEL); + hw_data = devm_kzalloc_obj(&pdev->dev, *hw_data); if (!hw_data) { ret = -ENOMEM; goto out_err; diff --git a/drivers/crypto/intel/qat/qat_6xxx/adf_drv.c b/drivers/crypto/intel/qat/qat_6xxx/adf_drv.c index 319b4251ad4668..0ace2aa71bc7e1 100644 --- a/drivers/crypto/intel/qat/qat_6xxx/adf_drv.c +++ b/drivers/crypto/intel/qat/qat_6xxx/adf_drv.c @@ -103,7 +103,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return dev_err_probe(dev, -EINVAL, "Invalid NUMA configuration.\n"); } - accel_dev = devm_kzalloc(dev, sizeof(*accel_dev), GFP_KERNEL); + accel_dev = devm_kzalloc_obj(dev, *accel_dev); if (!accel_dev) return -ENOMEM; @@ -113,7 +113,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) accel_pci_dev->pci_dev = pdev; accel_dev->owner = THIS_MODULE; - hw_data = devm_kzalloc(dev, sizeof(*hw_data), GFP_KERNEL); + hw_data = devm_kzalloc_obj(dev, *hw_data); if (!hw_data) return -ENOMEM; diff --git a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c b/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c index b81f705766834f..044939c9f3ed5e 100644 --- a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c +++ b/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c @@ -114,8 +114,7 @@ static int tl_calc_count(struct adf_telemetry *telemetry, int sample_cnt; int ret = 0; - hist_vals = kmalloc_array(tl_data->num_hbuff, sizeof(*hist_vals), - GFP_KERNEL); + hist_vals = kmalloc_objs(*hist_vals, tl_data->num_hbuff); if (!hist_vals) return -ENOMEM; @@ -171,11 +170,11 @@ static int tl_lat_acc_avg(struct adf_telemetry *telemetry, u64 *hist_cnt; int ret = 0; - hist_vals = kmalloc_array(num_hbuff, sizeof(*hist_vals), GFP_KERNEL); + hist_vals = kmalloc_objs(*hist_vals, num_hbuff); if (!hist_vals) return -ENOMEM; - hist_cnt = kmalloc_array(num_hbuff, sizeof(*hist_cnt), GFP_KERNEL); + hist_cnt = kmalloc_objs(*hist_cnt, num_hbuff); if (!hist_cnt) { ret = -ENOMEM; goto out_free_hist_vals; @@ -220,8 +219,7 @@ static int tl_bw_hw_units_to_mbps(struct adf_telemetry *telemetry, int sample_cnt; int ret = 0; - hist_vals = kmalloc_array(tl_data->num_hbuff, sizeof(*hist_vals), - GFP_KERNEL); + hist_vals = kmalloc_objs(*hist_vals, tl_data->num_hbuff); if (!hist_vals) return -ENOMEM; diff --git a/drivers/crypto/intel/qat/qat_common/qat_hal.c b/drivers/crypto/intel/qat/qat_common/qat_hal.c index 1c3d1311f1c7ad..2251418cce9788 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_hal.c +++ b/drivers/crypto/intel/qat/qat_common/qat_hal.c @@ -1304,8 +1304,7 @@ int qat_hal_batch_wr_lm(struct icp_qat_fw_loader_handle *handle, alloc_inst_size = lm_init_header->size; if ((unsigned int)alloc_inst_size > handle->hal_handle->max_ustore) alloc_inst_size = handle->hal_handle->max_ustore; - micro_inst_arry = kmalloc_array(alloc_inst_size, sizeof(u64), - GFP_KERNEL); + micro_inst_arry = kmalloc_objs(u64, alloc_inst_size); if (!micro_inst_arry) return -ENOMEM; micro_inst_num = 0; diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c index a00ca2a0900ff6..196f71fc109527 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c @@ -373,8 +373,7 @@ static int qat_uclo_init_ustore(struct icp_qat_fw_loader_handle *handle, u64 *fill_data; uof_image = image->img_ptr; - fill_data = kcalloc(ICP_QAT_UCLO_MAX_USTORE, sizeof(u64), - GFP_KERNEL); + fill_data = kzalloc_objs(u64, ICP_QAT_UCLO_MAX_USTORE); if (!fill_data) return -ENOMEM; for (i = 0; i < ICP_QAT_UCLO_MAX_USTORE; i++) @@ -994,8 +993,7 @@ static int qat_uclo_parse_uof_obj(struct icp_qat_fw_loader_handle *handle) pr_err("UOF incompatible\n"); return -EINVAL; } - obj_handle->uword_buf = kcalloc(UWORD_CPYBUF_SIZE, sizeof(u64), - GFP_KERNEL); + obj_handle->uword_buf = kzalloc_objs(u64, UWORD_CPYBUF_SIZE); if (!obj_handle->uword_buf) return -ENOMEM; obj_handle->ustore_phy_size = ICP_QAT_UCLO_MAX_USTORE; diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c index 564b09773507c1..f0fec5b3ccbab3 100644 --- a/drivers/crypto/marvell/cesa/cesa.c +++ b/drivers/crypto/marvell/cesa/cesa.c @@ -337,7 +337,7 @@ static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa) if (!cesa->caps->has_tdma) return 0; - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) return -ENOMEM; @@ -436,8 +436,7 @@ static int mv_cesa_probe(struct platform_device *pdev) return -ENOTSUPP; } - cesa = devm_kzalloc(dev, struct_size(cesa, engines, caps->nengines), - GFP_KERNEL); + cesa = devm_kzalloc_flex(dev, *cesa, engines, caps->nengines); if (!cesa) return -ENOMEM; diff --git a/drivers/crypto/marvell/octeontx/otx_cptpf_main.c b/drivers/crypto/marvell/octeontx/otx_cptpf_main.c index e4c828606a7376..3ed692a1181cfd 100644 --- a/drivers/crypto/marvell/octeontx/otx_cptpf_main.c +++ b/drivers/crypto/marvell/octeontx/otx_cptpf_main.c @@ -193,7 +193,7 @@ static int otx_cpt_probe(struct pci_dev *pdev, struct otx_cpt_device *cpt; int err; - cpt = devm_kzalloc(dev, sizeof(*cpt), GFP_KERNEL); + cpt = devm_kzalloc_obj(dev, *cpt); if (!cpt) return -ENOMEM; diff --git a/drivers/crypto/marvell/octeontx/otx_cptvf_main.c b/drivers/crypto/marvell/octeontx/otx_cptvf_main.c index 159c1d290a36b6..e11c004782202d 100644 --- a/drivers/crypto/marvell/octeontx/otx_cptvf_main.c +++ b/drivers/crypto/marvell/octeontx/otx_cptvf_main.c @@ -785,7 +785,7 @@ static int otx_cptvf_probe(struct pci_dev *pdev, struct otx_cptvf *cptvf; int err; - cptvf = devm_kzalloc(dev, sizeof(*cptvf), GFP_KERNEL); + cptvf = devm_kzalloc_obj(dev, *cptvf); if (!cptvf) return -ENOMEM; diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c b/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c index 79f6c2bb9d8b7a..14c998a9df8b78 100644 --- a/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c +++ b/drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c @@ -727,7 +727,7 @@ static int otx2_cptpf_probe(struct pci_dev *pdev, struct otx2_cptpf_dev *cptpf; int err, num_vec; - cptpf = devm_kzalloc(dev, sizeof(*cptpf), GFP_KERNEL); + cptpf = devm_kzalloc_obj(dev, *cptpf); if (!cptpf) return -ENOMEM; diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c b/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c index 09ab85e6061c4c..366346e2d8fa46 100644 --- a/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c +++ b/drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c @@ -357,7 +357,7 @@ static int otx2_cptvf_probe(struct pci_dev *pdev, struct otx2_cptvf_dev *cptvf; int ret; - cptvf = devm_kzalloc(dev, sizeof(*cptvf), GFP_KERNEL); + cptvf = devm_kzalloc_obj(dev, *cptvf); if (!cptvf) return -ENOMEM; diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index d104d958cb61ae..479fdaba833723 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -1076,7 +1076,7 @@ static int mxs_dcp_probe(struct platform_device *pdev) if (dcp_irq < 0) return dcp_irq; - sdcp = devm_kzalloc(dev, sizeof(*sdcp), GFP_KERNEL); + sdcp = devm_kzalloc_obj(dev, *sdcp); if (!sdcp) return -ENOMEM; diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index d40074e5a14273..815b8fb34cf47d 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -1060,7 +1060,7 @@ static int omap_aes_probe(struct platform_device *pdev) if (IS_ERR(io_base)) return PTR_ERR(io_base); - dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, struct omap_aes_dev); if (dd == NULL) { dev_err(dev, "unable to alloc data struct.\n"); goto err_data; diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c index 4b5a8d13f505e7..a3dffd632dedeb 100644 --- a/drivers/crypto/omap-des.c +++ b/drivers/crypto/omap-des.c @@ -961,7 +961,7 @@ static int omap_des_probe(struct platform_device *pdev) int err = -ENOMEM, i, j, irq = -1; u32 reg; - dd = devm_kzalloc(dev, sizeof(struct omap_des_dev), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, struct omap_des_dev); if (dd == NULL) { dev_err(dev, "unable to alloc data struct.\n"); goto err_data; diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index 5e739415a0102a..2c0568a15c3a84 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -2001,7 +2001,7 @@ static int omap_sham_probe(struct platform_device *pdev) if (irq < 0) return irq; - dd = devm_kzalloc(dev, sizeof(struct omap_sham_dev), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, struct omap_sham_dev); if (dd == NULL) { dev_err(dev, "unable to alloc data struct.\n"); err = -ENOMEM; diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c index bf3c1bc3ba7bde..a009c791417b70 100644 --- a/drivers/crypto/qce/core.c +++ b/drivers/crypto/qce/core.c @@ -196,7 +196,7 @@ static int qce_crypto_probe(struct platform_device *pdev) struct qce_device *qce; int ret; - qce = devm_kzalloc(dev, sizeof(*qce), GFP_KERNEL); + qce = devm_kzalloc_obj(dev, *qce); if (!qce) return -ENOMEM; diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c index b2b629fffc056b..bb23a179c257a7 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.c +++ b/drivers/crypto/rockchip/rk3288_crypto.c @@ -319,8 +319,7 @@ static int rk_crypto_probe(struct platform_device *pdev) struct rk_crypto_info *crypto_info, *first; int err = 0; - crypto_info = devm_kzalloc(&pdev->dev, - sizeof(*crypto_info), GFP_KERNEL); + crypto_info = devm_kzalloc_obj(&pdev->dev, *crypto_info); if (!crypto_info) { err = -ENOMEM; goto err_crypto; diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index a70102799223d5..d06419c75f5437 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -2139,7 +2139,7 @@ static int s5p_aes_probe(struct platform_device *pdev) if (s5p_dev) return -EEXIST; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c index 4557eae941648b..c84315b1d093ea 100644 --- a/drivers/crypto/sa2ul.c +++ b/drivers/crypto/sa2ul.c @@ -2293,7 +2293,7 @@ static int sa_ul_probe(struct platform_device *pdev) u32 status, val; int ret; - dev_data = devm_kzalloc(dev, sizeof(*dev_data), GFP_KERNEL); + dev_data = devm_kzalloc_obj(dev, *dev_data); if (!dev_data) return -ENOMEM; diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c index d586f1315de1f4..81a3a3f2af2081 100644 --- a/drivers/crypto/sahara.c +++ b/drivers/crypto/sahara.c @@ -1285,7 +1285,7 @@ static int sahara_probe(struct platform_device *pdev) int err; int i; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/crypto/starfive/jh7110-cryp.c b/drivers/crypto/starfive/jh7110-cryp.c index 856290347b95bd..6cfe044b168c00 100644 --- a/drivers/crypto/starfive/jh7110-cryp.c +++ b/drivers/crypto/starfive/jh7110-cryp.c @@ -89,7 +89,7 @@ static int starfive_cryp_probe(struct platform_device *pdev) struct resource *res; int ret; - cryp = devm_kzalloc(&pdev->dev, sizeof(*cryp), GFP_KERNEL); + cryp = devm_kzalloc_obj(&pdev->dev, *cryp); if (!cryp) return -ENOMEM; diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index 3fc2db290b0f40..2611ff882768b9 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -2567,7 +2567,7 @@ static int stm32_cryp_probe(struct platform_device *pdev) struct reset_control *rst; int irq, ret; - cryp = devm_kzalloc(dev, sizeof(*cryp), GFP_KERNEL); + cryp = devm_kzalloc_obj(dev, *cryp); if (!cryp) return -ENOMEM; diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index e6a1e9b9f88d51..fed05f5ef26392 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -2332,7 +2332,7 @@ static int stm32_hash_probe(struct platform_device *pdev) struct resource *res; int ret, irq; - hdev = devm_kzalloc(dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(dev, *hdev); if (!hdev) return -ENOMEM; diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index c7d9ce2905be7d..8a9f0d1e7df99f 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -3255,8 +3255,7 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, struct talitos_crypto_alg *t_alg; struct crypto_alg *alg; - t_alg = devm_kzalloc(dev, sizeof(struct talitos_crypto_alg), - GFP_KERNEL); + t_alg = devm_kzalloc_obj(dev, struct talitos_crypto_alg); if (!t_alg) return ERR_PTR(-ENOMEM); @@ -3419,7 +3418,7 @@ static int talitos_probe(struct platform_device *ofdev) if (IS_ERR(reg)) return PTR_ERR(reg); - priv = devm_kzalloc(dev, struct_size(priv, chan, num_channels), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, chan, num_channels); if (!priv) return -ENOMEM; @@ -3520,10 +3519,9 @@ static int talitos_probe(struct platform_device *ofdev) spin_lock_init(&priv->chan[i].head_lock); spin_lock_init(&priv->chan[i].tail_lock); - priv->chan[i].fifo = devm_kcalloc(dev, - priv->fifo_len, - sizeof(struct talitos_request), - GFP_KERNEL); + priv->chan[i].fifo = devm_kzalloc_objs(dev, + struct talitos_request, + priv->fifo_len); if (!priv->chan[i].fifo) { dev_err(dev, "failed to allocate request fifo %d\n", i); err = -ENOMEM; diff --git a/drivers/crypto/tegra/tegra-se-main.c b/drivers/crypto/tegra/tegra-se-main.c index 497ff270489cc6..b90ea2efa63153 100644 --- a/drivers/crypto/tegra/tegra-se-main.c +++ b/drivers/crypto/tegra/tegra-se-main.c @@ -280,7 +280,7 @@ static int tegra_se_probe(struct platform_device *pdev) struct tegra_se *se; int ret; - se = devm_kzalloc(dev, sizeof(*se), GFP_KERNEL); + se = devm_kzalloc_obj(dev, *se); if (!se) return -ENOMEM; diff --git a/drivers/crypto/ti/dthev2-common.c b/drivers/crypto/ti/dthev2-common.c index ba6cde75d3611d..5916edff8e95ec 100644 --- a/drivers/crypto/ti/dthev2-common.c +++ b/drivers/crypto/ti/dthev2-common.c @@ -143,7 +143,7 @@ static int dthe_probe(struct platform_device *pdev) struct dthe_data *dev_data; int ret; - dev_data = devm_kzalloc(dev, sizeof(*dev_data), GFP_KERNEL); + dev_data = devm_kzalloc_obj(dev, *dev_data); if (!dev_data) return -ENOMEM; diff --git a/drivers/crypto/xilinx/zynqmp-aes-gcm.c b/drivers/crypto/xilinx/zynqmp-aes-gcm.c index d9bd6dcd23a6da..9b6e7850651868 100644 --- a/drivers/crypto/xilinx/zynqmp-aes-gcm.c +++ b/drivers/crypto/xilinx/zynqmp-aes-gcm.c @@ -928,7 +928,7 @@ static int xilinx_aes_aead_probe(struct platform_device *pdev) if (aead_dev) return -ENODEV; - aead_dev = devm_kzalloc(dev, sizeof(*aead_dev), GFP_KERNEL); + aead_dev = devm_kzalloc_obj(dev, *aead_dev); if (!aead_dev) return -ENOMEM; aead_dev->dev = dev; diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index b7ce6b59c680b0..4516ad48f5bebd 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -126,8 +126,7 @@ static int cxl_parse_cxims(union acpi_subtable_headers *header, void *arg, return -ENXIO; } - cximsd = devm_kzalloc(dev, struct_size(cximsd, xormaps, nr_maps), - GFP_KERNEL); + cximsd = devm_kzalloc_flex(dev, *cximsd, xormaps, nr_maps); if (!cximsd) return -ENOMEM; cximsd->nr_maps = nr_maps; @@ -909,7 +908,7 @@ static int cxl_acpi_probe(struct platform_device *pdev) if (rc) return rc; - cxl_res = devm_kzalloc(host, sizeof(*cxl_res), GFP_KERNEL); + cxl_res = devm_kzalloc_obj(host, *cxl_res); if (!cxl_res) return -ENOMEM; cxl_res->name = "CXL mem"; diff --git a/drivers/cxl/core/edac.c b/drivers/cxl/core/edac.c index 34b81e8dfbbb6f..2eceee68c165c8 100644 --- a/drivers/cxl/core/edac.c +++ b/drivers/cxl/core/edac.c @@ -382,7 +382,7 @@ static int cxl_memdev_scrub_init(struct cxl_memdev *cxlmd, if (!(le32_to_cpu(feat_entry->flags) & CXL_FEATURE_F_CHANGEABLE)) return -EOPNOTSUPP; - cxl_ps_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ps_ctx), GFP_KERNEL); + cxl_ps_ctx = devm_kzalloc_obj(&cxlmd->dev, *cxl_ps_ctx); if (!cxl_ps_ctx) return -ENOMEM; @@ -450,7 +450,7 @@ static int cxl_region_scrub_init(struct cxl_region *cxlr, cxlmd->scrub_region_id = CXL_SCRUB_NO_REGION; } - cxl_ps_ctx = devm_kzalloc(&cxlr->dev, sizeof(*cxl_ps_ctx), GFP_KERNEL); + cxl_ps_ctx = devm_kzalloc_obj(&cxlr->dev, *cxl_ps_ctx); if (!cxl_ps_ctx) return -ENOMEM; @@ -801,8 +801,7 @@ static int cxl_memdev_ecs_init(struct cxl_memdev *cxlmd, if (!num_media_frus) return -EOPNOTSUPP; - cxl_ecs_ctx = - devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ecs_ctx), GFP_KERNEL); + cxl_ecs_ctx = devm_kzalloc_obj(&cxlmd->dev, *cxl_ecs_ctx); if (!cxl_ecs_ctx) return -ENOMEM; @@ -1641,8 +1640,7 @@ static int cxl_memdev_sparing_init(struct cxl_memdev *cxlmd, if (!(le32_to_cpu(feat_entry->flags) & CXL_FEATURE_F_CHANGEABLE)) return -EOPNOTSUPP; - cxl_sparing_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_sparing_ctx), - GFP_KERNEL); + cxl_sparing_ctx = devm_kzalloc_obj(&cxlmd->dev, *cxl_sparing_ctx); if (!cxl_sparing_ctx) return -ENOMEM; @@ -1968,8 +1966,7 @@ static int cxl_memdev_soft_ppr_init(struct cxl_memdev *cxlmd, if (!(le32_to_cpu(feat_entry->flags) & CXL_FEATURE_F_CHANGEABLE)) return -EOPNOTSUPP; - cxl_sppr_ctx = - devm_kzalloc(&cxlmd->dev, sizeof(*cxl_sppr_ctx), GFP_KERNEL); + cxl_sppr_ctx = devm_kzalloc_obj(&cxlmd->dev, *cxl_sppr_ctx); if (!cxl_sppr_ctx) return -ENOMEM; diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index fdcef20e01baab..6329eb3b92141a 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -142,7 +142,7 @@ static struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, struct cxl_hdm *cxlhdm; int rc; - cxlhdm = devm_kzalloc(dev, sizeof(*cxlhdm), GFP_KERNEL); + cxlhdm = devm_kzalloc_obj(dev, *cxlhdm); if (!cxlhdm) return ERR_PTR(-ENOMEM); cxlhdm->port = port; diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 6fba230905c16c..702ae9ebdcde49 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -237,8 +237,7 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_classdev, "CXL"); struct cxl_memdev *devm_cxl_probe_mem(struct cxl_dev_state *cxlds, struct range *hpa_range) { - struct cxl_attach_region *attach = - devm_kmalloc(cxlds->dev, sizeof(*attach), GFP_KERNEL); + struct cxl_attach_region *attach = devm_kmalloc_obj(cxlds->dev, *attach); struct cxl_memdev *cxlmd; if (!attach) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 3ed7c3e700428a..8ce58917c32d1a 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -102,7 +102,7 @@ static int cxl_request_irq(struct cxl_dev_state *cxlds, int irq, struct device *dev = cxlds->dev; struct cxl_dev_id *dev_id; - dev_id = devm_kzalloc(dev, sizeof(*dev_id), GFP_KERNEL); + dev_id = devm_kzalloc_obj(dev, *dev_id); if (!dev_id) return -ENOMEM; dev_id->cxlds = cxlds; diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index a9f50281875d83..7ac1dc8740cf47 100644 --- a/drivers/cxl/pmem.c +++ b/drivers/cxl/pmem.c @@ -409,7 +409,7 @@ static int cxl_pmem_region_probe(struct device *dev) memset(&mappings, 0, sizeof(mappings)); memset(&ndr_desc, 0, sizeof(ndr_desc)); - res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(dev, *res); if (!res) return -ENOMEM; @@ -438,7 +438,7 @@ static int cxl_pmem_region_probe(struct device *dev) NUMA_NO_NODE, ndr_desc.target_node); } - nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL); + nd_set = devm_kzalloc_obj(dev, *nd_set); if (!nd_set) return -ENOMEM; diff --git a/drivers/dax/device.c b/drivers/dax/device.c index d0c9b4e03b4771..e52f4886fbaa48 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -402,9 +402,8 @@ static int dev_dax_probe(struct dev_dax *dev_dax) return -EINVAL; } - pgmap = devm_kzalloc(dev, - struct_size(pgmap, ranges, dev_dax->nr_range - 1), - GFP_KERNEL); + pgmap = devm_kzalloc_flex(dev, *pgmap, ranges, + dev_dax->nr_range - 1); if (!pgmap) return -ENOMEM; diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 82dd9a43dc6218..172336437ce93b 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -185,10 +185,9 @@ static int set_freq_table(struct devfreq *devfreq) return -EINVAL; devfreq->max_state = count; - devfreq->freq_table = devm_kcalloc(devfreq->dev.parent, - devfreq->max_state, - sizeof(*devfreq->freq_table), - GFP_KERNEL); + devfreq->freq_table = devm_kzalloc_objs(devfreq->dev.parent, + *devfreq->freq_table, + devfreq->max_state); if (!devfreq->freq_table) return -ENOMEM; @@ -893,10 +892,9 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_devfreq; } - devfreq->stats.time_in_state = devm_kcalloc(&devfreq->dev, - devfreq->max_state, - sizeof(*devfreq->stats.time_in_state), - GFP_KERNEL); + devfreq->stats.time_in_state = devm_kzalloc_objs(&devfreq->dev, + *devfreq->stats.time_in_state, + devfreq->max_state); if (!devfreq->stats.time_in_state) { mutex_unlock(&devfreq->lock); err = -ENOMEM; diff --git a/drivers/devfreq/event/exynos-nocp.c b/drivers/devfreq/event/exynos-nocp.c index 6a3efd782ad0df..c0c6e69652c655 100644 --- a/drivers/devfreq/event/exynos-nocp.c +++ b/drivers/devfreq/event/exynos-nocp.c @@ -237,7 +237,7 @@ static int exynos_nocp_probe(struct platform_device *pdev) struct exynos_nocp *nocp; int ret; - nocp = devm_kzalloc(&pdev->dev, sizeof(*nocp), GFP_KERNEL); + nocp = devm_kzalloc_obj(&pdev->dev, *nocp); if (!nocp) return -ENOMEM; diff --git a/drivers/devfreq/event/exynos-ppmu.c b/drivers/devfreq/event/exynos-ppmu.c index 88cd4dfe87e127..549718816ca09f 100644 --- a/drivers/devfreq/event/exynos-ppmu.c +++ b/drivers/devfreq/event/exynos-ppmu.c @@ -517,7 +517,7 @@ static int of_get_devfreq_events(struct device_node *np, } count = of_get_child_count(events_np); - desc = devm_kcalloc(dev, count, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_objs(dev, *desc, count); if (!desc) { of_node_put(events_np); return -ENOMEM; @@ -648,7 +648,7 @@ static int exynos_ppmu_probe(struct platform_device *pdev) struct devfreq_event_desc *desc; int i, ret = 0, size; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/devfreq/event/rockchip-dfi.c b/drivers/devfreq/event/rockchip-dfi.c index 255aee1bdd91c7..16b25779d2f84a 100644 --- a/drivers/devfreq/event/rockchip-dfi.c +++ b/drivers/devfreq/event/rockchip-dfi.c @@ -829,7 +829,7 @@ static int rockchip_dfi_probe(struct platform_device *pdev) if (!soc_init) return -EINVAL; - dfi = devm_kzalloc(dev, sizeof(*dfi), GFP_KERNEL); + dfi = devm_kzalloc_obj(dev, *dfi); if (!dfi) return -ENOMEM; diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index b9ea7ad2e51b27..fc8a4ed3f0da45 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -288,7 +288,7 @@ static int exynos_bus_profile_init(struct exynos_bus *bus, profile->get_dev_status = exynos_bus_get_dev_status; profile->exit = exynos_bus_exit; - ondemand_data = devm_kzalloc(dev, sizeof(*ondemand_data), GFP_KERNEL); + ondemand_data = devm_kzalloc_obj(dev, *ondemand_data); if (!ondemand_data) return -ENOMEM; @@ -352,7 +352,7 @@ static int exynos_bus_profile_init_passive(struct exynos_bus *bus, if (IS_ERR(parent_devfreq)) return -EPROBE_DEFER; - passive_data = devm_kzalloc(dev, sizeof(*passive_data), GFP_KERNEL); + passive_data = devm_kzalloc_obj(dev, *passive_data); if (!passive_data) return -ENOMEM; @@ -385,14 +385,14 @@ static int exynos_bus_probe(struct platform_device *pdev) return -EINVAL; } - bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&pdev->dev, *bus); if (!bus) return -ENOMEM; mutex_init(&bus->lock); bus->dev = &pdev->dev; platform_set_drvdata(pdev, bus); - profile = devm_kzalloc(dev, sizeof(*profile), GFP_KERNEL); + profile = devm_kzalloc_obj(dev, *profile); if (!profile) return -ENOMEM; diff --git a/drivers/devfreq/hisi_uncore_freq.c b/drivers/devfreq/hisi_uncore_freq.c index ac55641b0259ac..4941d508817379 100644 --- a/drivers/devfreq/hisi_uncore_freq.c +++ b/drivers/devfreq/hisi_uncore_freq.c @@ -563,7 +563,7 @@ static int hisi_uncore_devfreq_register(struct hisi_uncore_freq *uncore) if (rc) return dev_err_probe(dev, rc, "Failed to get plat init freq\n"); - profile = devm_kzalloc(dev, sizeof(*profile), GFP_KERNEL); + profile = devm_kzalloc_obj(dev, *profile); if (!profile) return -ENOMEM; @@ -601,7 +601,7 @@ static int hisi_uncore_freq_probe(struct platform_device *pdev) u32 cap; int rc; - uncore = devm_kzalloc(dev, sizeof(*uncore), GFP_KERNEL); + uncore = devm_kzalloc_obj(dev, *uncore); if (!uncore) return -ENOMEM; diff --git a/drivers/devfreq/imx-bus.c b/drivers/devfreq/imx-bus.c index 49798f542d6809..f00bf1bf305acb 100644 --- a/drivers/devfreq/imx-bus.c +++ b/drivers/devfreq/imx-bus.c @@ -90,7 +90,7 @@ static int imx_bus_probe(struct platform_device *pdev) const char *gov = DEVFREQ_GOV_USERSPACE; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/devfreq/imx8m-ddrc.c b/drivers/devfreq/imx8m-ddrc.c index 52beeb5b7d651b..2f205cda347f94 100644 --- a/drivers/devfreq/imx8m-ddrc.c +++ b/drivers/devfreq/imx8m-ddrc.c @@ -369,7 +369,7 @@ static int imx8m_ddrc_probe(struct platform_device *pdev) const char *gov = DEVFREQ_GOV_USERSPACE; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/devfreq/mtk-cci-devfreq.c b/drivers/devfreq/mtk-cci-devfreq.c index 4c22be728f6a03..3eb5545e0eb6a9 100644 --- a/drivers/devfreq/mtk-cci-devfreq.c +++ b/drivers/devfreq/mtk-cci-devfreq.c @@ -255,7 +255,7 @@ static int mtk_ccifreq_probe(struct platform_device *pdev) unsigned long rate, opp_volt; int ret; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; @@ -352,7 +352,7 @@ static int mtk_ccifreq_probe(struct platform_device *pdev) goto out_remove_opp_table; } - passive_data = devm_kzalloc(dev, sizeof(*passive_data), GFP_KERNEL); + passive_data = devm_kzalloc_obj(dev, *passive_data); if (!passive_data) { ret = -ENOMEM; goto out_remove_opp_table; diff --git a/drivers/devfreq/rk3399_dmc.c b/drivers/devfreq/rk3399_dmc.c index dbdce7636ca5b8..f5b662fb8413cb 100644 --- a/drivers/devfreq/rk3399_dmc.c +++ b/drivers/devfreq/rk3399_dmc.c @@ -342,7 +342,7 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev) u32 ddr_type; u32 val; - data = devm_kzalloc(dev, sizeof(struct rk3399_dmcfreq), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct rk3399_dmcfreq); if (!data) return -ENOMEM; diff --git a/drivers/devfreq/sun8i-a33-mbus.c b/drivers/devfreq/sun8i-a33-mbus.c index 4bd5657558d6b9..db2554e38e3f8c 100644 --- a/drivers/devfreq/sun8i-a33-mbus.c +++ b/drivers/devfreq/sun8i-a33-mbus.c @@ -344,7 +344,7 @@ static int sun8i_a33_mbus_probe(struct platform_device *pdev) max_state = variant->max_dram_divider - variant->min_dram_divider + 1; - priv = devm_kzalloc(dev, struct_size(priv, freq_table, max_state), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, freq_table, max_state); if (!priv) return -ENOMEM; diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c index 401aac6a9f07ea..20b41fbede046f 100644 --- a/drivers/devfreq/tegra30-devfreq.c +++ b/drivers/devfreq/tegra30-devfreq.c @@ -842,7 +842,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev) .config_clks = tegra_devfreq_config_clks_nop, }; - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(&pdev->dev, *tegra); if (!tegra) return -ENOMEM; diff --git a/drivers/dma-buf/dma-buf-mapping.c b/drivers/dma-buf/dma-buf-mapping.c index 833be519e1e6a6..5167cda7ea2165 100644 --- a/drivers/dma-buf/dma-buf-mapping.c +++ b/drivers/dma-buf/dma-buf-mapping.c @@ -111,12 +111,12 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach, size_t i; int ret; - dma_resv_assert_held(attach->dmabuf->resv); - if (WARN_ON(!attach || !attach->dmabuf || !provider)) /* This function is supposed to work on MMIO memory only */ return ERR_PTR(-EINVAL); + dma_resv_assert_held(attach->dmabuf->resv); + dma = kzalloc_obj(*dma); if (!dma) return ERR_PTR(-ENOMEM); @@ -156,7 +156,7 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach, phys_vec[i].paddr); } else if (dma_use_iova(dma->state)) { ret = dma_iova_link(attach->dev, dma->state, - phys_vec[i].paddr, 0, + phys_vec[i].paddr, mapped_len, phys_vec[i].len, dir, DMA_ATTR_MMIO); if (ret) @@ -251,6 +251,8 @@ void dma_buf_free_sgt(struct dma_buf_attachment *attach, struct sg_table *sgt, sg_dma_len(sgl), dir, DMA_ATTR_MMIO); } + /* Restore the allocation count cleared for the DMA-only table. */ + sgt->orig_nents = sgt->nents; sg_free_table(sgt); kfree(dma->state); kfree(dma); diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 36cdc342627ee8..0dac2c4fb9684d 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -904,6 +904,10 @@ static int dma_buf_wrap_sg_table(struct sg_table **sg_table) sg_assign_page(to_sg, NULL); sg_dma_address(to_sg) = sg_dma_address(from_sg); sg_dma_len(to_sg) = sg_dma_len(from_sg); +#ifdef CONFIG_NEED_SG_DMA_FLAGS + /* the flags describe the DMA side, e.g. SG_DMA_BUS_ADDRESS */ + to_sg->dma_flags = from_sg->dma_flags; +#endif to_sg = sg_next(to_sg); } diff --git a/drivers/dma/altera-msgdma.c b/drivers/dma/altera-msgdma.c index 412f4bce1d4aac..567aea0fac3889 100644 --- a/drivers/dma/altera-msgdma.c +++ b/drivers/dma/altera-msgdma.c @@ -819,7 +819,7 @@ static int msgdma_probe(struct platform_device *pdev) struct resource *dma_res; int ret; - mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_NOWAIT); + mdev = devm_kzalloc_obj(&pdev->dev, *mdev, GFP_NOWAIT); if (!mdev) return -ENOMEM; diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c index 543c2eb8cfa81e..e2bc7d5b2f314e 100644 --- a/drivers/dma/amba-pl08x.c +++ b/drivers/dma/amba-pl08x.c @@ -2571,7 +2571,7 @@ static int pl08x_of_probe(struct amba_device *adev, int ret; int i; - pd = devm_kzalloc(&adev->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(&adev->dev, *pd); if (!pd) return -ENOMEM; @@ -2658,10 +2658,8 @@ static int pl08x_of_probe(struct amba_device *adev, * translation time. */ if (pl08x->vd->signals) { - chanp = devm_kcalloc(&adev->dev, - pl08x->vd->signals, - sizeof(struct pl08x_channel_data), - GFP_KERNEL); + chanp = devm_kzalloc_objs(&adev->dev, struct pl08x_channel_data, + pl08x->vd->signals); if (!chanp) return -ENOMEM; diff --git a/drivers/dma/amd/ae4dma/ae4dma-pci.c b/drivers/dma/amd/ae4dma/ae4dma-pci.c index 2c63907db22825..8ca34d4457cc01 100644 --- a/drivers/dma/amd/ae4dma/ae4dma-pci.c +++ b/drivers/dma/amd/ae4dma/ae4dma-pci.c @@ -79,11 +79,11 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) int bar_mask; int ret = 0; - ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL); + ae4 = devm_kzalloc_obj(dev, *ae4); if (!ae4) return -ENOMEM; - ae4->ae4_msix = devm_kzalloc(dev, sizeof(struct ae4_msix), GFP_KERNEL); + ae4->ae4_msix = devm_kzalloc_obj(dev, struct ae4_msix); if (!ae4->ae4_msix) return -ENOMEM; diff --git a/drivers/dma/amd/ptdma/ptdma-dmaengine.c b/drivers/dma/amd/ptdma/ptdma-dmaengine.c index 628c49ce5de9d8..dc6ce4a3afa9cd 100644 --- a/drivers/dma/amd/ptdma/ptdma-dmaengine.c +++ b/drivers/dma/amd/ptdma/ptdma-dmaengine.c @@ -572,11 +572,10 @@ int pt_dmaengine_register(struct pt_device *pt) ae4 = container_of(pt, struct ae4_device, pt); if (ae4) - pt->pt_dma_chan = devm_kcalloc(pt->dev, ae4->cmd_q_count, - sizeof(*pt->pt_dma_chan), GFP_KERNEL); + pt->pt_dma_chan = devm_kzalloc_objs(pt->dev, *pt->pt_dma_chan, + ae4->cmd_q_count); else - pt->pt_dma_chan = devm_kzalloc(pt->dev, sizeof(*pt->pt_dma_chan), - GFP_KERNEL); + pt->pt_dma_chan = devm_kzalloc_obj(pt->dev, *pt->pt_dma_chan); if (!pt->pt_dma_chan) return -ENOMEM; diff --git a/drivers/dma/amd/ptdma/ptdma-pci.c b/drivers/dma/amd/ptdma/ptdma-pci.c index 22739ff0c3c56c..68df877e4ca74a 100644 --- a/drivers/dma/amd/ptdma/ptdma-pci.c +++ b/drivers/dma/amd/ptdma/ptdma-pci.c @@ -37,7 +37,7 @@ static struct pt_device *pt_alloc_struct(struct device *dev) { struct pt_device *pt; - pt = devm_kzalloc(dev, sizeof(*pt), GFP_KERNEL); + pt = devm_kzalloc_obj(dev, *pt); if (!pt) return NULL; @@ -131,7 +131,7 @@ static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!pt) goto e_err; - pt_msix = devm_kzalloc(dev, sizeof(*pt_msix), GFP_KERNEL); + pt_msix = devm_kzalloc_obj(dev, *pt_msix); if (!pt_msix) goto e_err; diff --git a/drivers/dma/amd/qdma/qdma.c b/drivers/dma/amd/qdma/qdma.c index 3e61e8c4356a64..435d7bb131adad 100644 --- a/drivers/dma/amd/qdma/qdma.c +++ b/drivers/dma/amd/qdma/qdma.c @@ -447,8 +447,7 @@ static int qdma_alloc_queues(struct qdma_device *qdev, pidx_base = QDMA_REG_OFF(qdev, QDMA_REGO_C2H_PIDX); } - *queues = devm_kcalloc(&qdev->pdev->dev, qdev->chan_num, sizeof(*q), - GFP_KERNEL); + *queues = devm_kzalloc_objs(&qdev->pdev->dev, *q, qdev->chan_num); if (!*queues) return -ENOMEM; @@ -954,9 +953,8 @@ static int qdmam_alloc_qintr_rings(struct qdma_device *qdev) int ret, i; qdev->qintr_ring_num = qdev->queue_irq_num; - qdev->qintr_rings = devm_kcalloc(dev, qdev->qintr_ring_num, - sizeof(*qdev->qintr_rings), - GFP_KERNEL); + qdev->qintr_rings = devm_kzalloc_objs(dev, *qdev->qintr_rings, + qdev->qintr_ring_num); if (!qdev->qintr_rings) return -ENOMEM; @@ -1043,7 +1041,7 @@ static int amd_qdma_probe(struct platform_device *pdev) void __iomem *regs; int ret; - qdev = devm_kzalloc(&pdev->dev, sizeof(*qdev), GFP_KERNEL); + qdev = devm_kzalloc_obj(&pdev->dev, *qdev); if (!qdev) return -ENOMEM; diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index 9a1c79c12268cd..4531a301c0181a 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -835,7 +835,7 @@ static int admac_probe(struct platform_device *pdev) return -EINVAL; } - ad = devm_kzalloc(&pdev->dev, struct_size(ad, channels, nchannels), GFP_KERNEL); + ad = devm_kzalloc_flex(&pdev->dev, *ad, channels, nchannels); if (!ad) return -ENOMEM; diff --git a/drivers/dma/arm-dma350.c b/drivers/dma/arm-dma350.c index 52f5242ea33270..9bef78c2df811a 100644 --- a/drivers/dma/arm-dma350.c +++ b/drivers/dma/arm-dma350.c @@ -556,7 +556,7 @@ static int d350_probe(struct platform_device *pdev) dma_set_mask_and_coherent(dev, DMA_BIT_MASK(aw)); coherent = device_get_dma_attr(dev) == DEV_DMA_COHERENT; - dmac = devm_kzalloc(dev, struct_size(dmac, channels, nchan), GFP_KERNEL); + dmac = devm_kzalloc_flex(dev, *dmac, channels, nchan); if (!dmac) return -ENOMEM; diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c index 3fedc907db6383..b024aa2d34b2e4 100644 --- a/drivers/dma/at_hdmac.c +++ b/drivers/dma/at_hdmac.c @@ -1971,9 +1971,8 @@ static int __init at_dma_probe(struct platform_device *pdev) if (!plat_dat) return -ENODEV; - atdma = devm_kzalloc(&pdev->dev, - struct_size(atdma, chan, plat_dat->nr_channels), - GFP_KERNEL); + atdma = devm_kzalloc_flex(&pdev->dev, *atdma, chan, + plat_dat->nr_channels); if (!atdma) return -ENOMEM; diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c index d40a8b40dddc39..ef0dfe9d37ba37 100644 --- a/drivers/dma/at_xdmac.c +++ b/drivers/dma/at_xdmac.c @@ -2290,9 +2290,7 @@ static int at_xdmac_probe(struct platform_device *pdev) return -EINVAL; } - atxdmac = devm_kzalloc(&pdev->dev, - struct_size(atxdmac, chan, nr_channels), - GFP_KERNEL); + atxdmac = devm_kzalloc_flex(&pdev->dev, *atxdmac, chan, nr_channels); if (!atxdmac) { dev_err(&pdev->dev, "can't allocate at_xdmac structure\n"); return -ENOMEM; diff --git a/drivers/dma/bcm-sba-raid.c b/drivers/dma/bcm-sba-raid.c index 0de03611252ed6..7b4e9de0f5315b 100644 --- a/drivers/dma/bcm-sba-raid.c +++ b/drivers/dma/bcm-sba-raid.c @@ -1489,9 +1489,8 @@ static int sba_prealloc_channel_resources(struct sba_device *sba) INIT_LIST_HEAD(&sba->reqs_free_list); for (i = 0; i < sba->max_req; i++) { - req = devm_kzalloc(sba->dev, - struct_size(req, cmds, sba->max_cmd_per_req), - GFP_KERNEL); + req = devm_kzalloc_flex(sba->dev, *req, cmds, + sba->max_cmd_per_req); if (!req) { ret = -ENOMEM; goto fail_free_cmds_pool; @@ -1619,7 +1618,7 @@ static int sba_probe(struct platform_device *pdev) struct of_phandle_args args; /* Allocate main SBA struct */ - sba = devm_kzalloc(&pdev->dev, sizeof(*sba), GFP_KERNEL); + sba = devm_kzalloc_obj(&pdev->dev, *sba); if (!sba) return -ENOMEM; diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c index 06d830d3688229..d41b0f6ec4275d 100644 --- a/drivers/dma/bcm2835-dma.c +++ b/drivers/dma/bcm2835-dma.c @@ -802,7 +802,7 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, { struct bcm2835_chan *c; - c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL); + c = devm_kzalloc_obj(d->ddev.dev, *c); if (!c) return -ENOMEM; @@ -899,7 +899,7 @@ static int bcm2835_dma_probe(struct platform_device *pdev) return rc; } - od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); + od = devm_kzalloc_obj(&pdev->dev, *od); if (!od) return -ENOMEM; diff --git a/drivers/dma/cv1800b-dmamux.c b/drivers/dma/cv1800b-dmamux.c index f7a952fcbc7d76..8d3de599151ed5 100644 --- a/drivers/dma/cv1800b-dmamux.c +++ b/drivers/dma/cv1800b-dmamux.c @@ -200,7 +200,7 @@ static int cv1800_dmamux_probe(struct platform_device *pdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -209,7 +209,7 @@ static int cv1800_dmamux_probe(struct platform_device *pdev) init_llist_head(&data->reserve_maps); for (i = 0; i <= MAX_DMA_CH_ID; i++) { - tmp = devm_kmalloc(dev, sizeof(*tmp), GFP_KERNEL); + tmp = devm_kmalloc_obj(dev, *tmp); if (!tmp) { /* It is OK for not allocating all channel */ dev_warn(dev, "can not allocate channel %u\n", i); diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c index d47ff27e1408f2..dbc31b185c4d41 100644 --- a/drivers/dma/dma-axi-dmac.c +++ b/drivers/dma/dma-axi-dmac.c @@ -1215,7 +1215,7 @@ static int axi_dmac_probe(struct platform_device *pdev) u32 irq_mask = 0; int ret; - dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(&pdev->dev, *dmac); if (!dmac) return -ENOMEM; diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c index ac2094e65ecf33..e610aba0941881 100644 --- a/drivers/dma/dma-jz4780.c +++ b/drivers/dma/dma-jz4780.c @@ -867,8 +867,7 @@ static int jz4780_dma_probe(struct platform_device *pdev) if (!soc_data) return -EINVAL; - jzdma = devm_kzalloc(dev, struct_size(jzdma, chan, - soc_data->nb_channels), GFP_KERNEL); + jzdma = devm_kzalloc_flex(dev, *jzdma, chan, soc_data->nb_channels); if (!jzdma) return -ENOMEM; diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c index 7520c78f55ccf6..940b196b69d1b9 100644 --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c @@ -1477,15 +1477,15 @@ static int dw_probe(struct platform_device *pdev) u32 i; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; - dw = devm_kzalloc(&pdev->dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(&pdev->dev, *dw); if (!dw) return -ENOMEM; - hdata = devm_kzalloc(&pdev->dev, sizeof(*hdata), GFP_KERNEL); + hdata = devm_kzalloc_obj(&pdev->dev, *hdata); if (!hdata) return -ENOMEM; @@ -1528,8 +1528,7 @@ static int dw_probe(struct platform_device *pdev) if (ret) return ret; - dw->chan = devm_kcalloc(chip->dev, hdata->nr_channels, - sizeof(*dw->chan), GFP_KERNEL); + dw->chan = devm_kzalloc_objs(chip->dev, *dw->chan, hdata->nr_channels); if (!dw->chan) return -ENOMEM; diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index b08bb31657c9e2..d682074eaa0ead 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -1264,7 +1264,7 @@ static int dw_edma_irq_request(struct dw_edma *dw, if (chip->nr_irqs < 1 || !chip->ops->irq_vector) return -EINVAL; - dw->irq = devm_kcalloc(dev, chip->nr_irqs, sizeof(*dw->irq), GFP_KERNEL); + dw->irq = devm_kzalloc_objs(dev, *dw->irq, chip->nr_irqs); if (!dw->irq) return -ENOMEM; @@ -1370,7 +1370,7 @@ int dw_edma_probe(struct dw_edma_chip *chip) } } - dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(dev, *dw); if (!dw) return -ENOMEM; @@ -1411,8 +1411,8 @@ int dw_edma_probe(struct dw_edma_chip *chip) dw->wr_ch_cnt, dw->rd_ch_cnt); /* Allocate channels */ - dw->chan = devm_kcalloc(dev, dw->wr_ch_cnt + dw->rd_ch_cnt, - sizeof(*dw->chan), GFP_KERNEL); + dw->chan = devm_kzalloc_objs(dev, *dw->chan, + dw->wr_ch_cnt + dw->rd_ch_cnt); if (!dw->chan) return -ENOMEM; diff --git a/drivers/dma/dw-edma/dw-edma-pcie.c b/drivers/dma/dw-edma/dw-edma-pcie.c index fab4faf68b7748..94fbf222e79087 100644 --- a/drivers/dma/dw-edma/dw-edma-pcie.c +++ b/drivers/dma/dw-edma/dw-edma-pcie.c @@ -472,7 +472,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, } /* Data structure allocation */ - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/dma/dw-edma/dw-edma-v0-debugfs.c b/drivers/dma/dw-edma/dw-edma-v0-debugfs.c index 406f169b09a75a..adc971df9e7cd7 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-debugfs.c +++ b/drivers/dma/dw-edma/dw-edma-v0-debugfs.c @@ -103,8 +103,7 @@ static void dw_edma_debugfs_create_x32(struct dw_edma *dw, struct dw_edma_debugfs_entry *entries; int i; - entries = devm_kcalloc(dw->chip->dev, nr_entries, sizeof(*entries), - GFP_KERNEL); + entries = devm_kzalloc_objs(dw->chip->dev, *entries, nr_entries); if (!entries) return; diff --git a/drivers/dma/dw-edma/dw-hdma-v0-debugfs.c b/drivers/dma/dw-edma/dw-hdma-v0-debugfs.c index 3fa16e045a5843..9f062fe2e36866 100644 --- a/drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +++ b/drivers/dma/dw-edma/dw-hdma-v0-debugfs.c @@ -58,8 +58,7 @@ static void dw_hdma_debugfs_create_x32(struct dw_edma *dw, struct dw_hdma_debugfs_entry *entries; int i; - entries = devm_kcalloc(dw->chip->dev, nr_entries, sizeof(*entries), - GFP_KERNEL); + entries = devm_kzalloc_objs(dw->chip->dev, *entries, nr_entries); if (!entries) return; diff --git a/drivers/dma/dw/acpi.c b/drivers/dma/dw/acpi.c index b6452fffa657ad..ed3a4652667faa 100644 --- a/drivers/dma/dw/acpi.c +++ b/drivers/dma/dw/acpi.c @@ -31,7 +31,7 @@ void dw_dma_acpi_controller_register(struct dw_dma *dw) if (!has_acpi_companion(dev)) return; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return; diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 575b7bb6af9a06..f8bcc3fd579638 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c @@ -1152,7 +1152,7 @@ int do_dma_probe(struct dw_dma_chip *chip) unsigned int i; int ret; - dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL); + dw->pdata = devm_kzalloc_obj(chip->dev, *dw->pdata); if (!dw->pdata) return -ENOMEM; @@ -1195,8 +1195,7 @@ int do_dma_probe(struct dw_dma_chip *chip) pdata = dw->pdata; } - dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan), - GFP_KERNEL); + dw->chan = devm_kzalloc_objs(chip->dev, *dw->chan, pdata->nr_channels); if (!dw->chan) { ret = -ENOMEM; goto err_pdata; diff --git a/drivers/dma/dw/dw.c b/drivers/dma/dw/dw.c index e56974e7d4afb3..c023ac5accb092 100644 --- a/drivers/dma/dw/dw.c +++ b/drivers/dma/dw/dw.c @@ -117,7 +117,7 @@ int dw_dma_probe(struct dw_dma_chip *chip) { struct dw_dma *dw; - dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(chip->dev, *dw); if (!dw) return -ENOMEM; diff --git a/drivers/dma/dw/idma32.c b/drivers/dma/dw/idma32.c index dac617c183e6a5..abdd45d89a6456 100644 --- a/drivers/dma/dw/idma32.c +++ b/drivers/dma/dw/idma32.c @@ -262,7 +262,7 @@ int idma32_dma_probe(struct dw_dma_chip *chip) { struct dw_dma *dw; - dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(chip->dev, *dw); if (!dw) return -ENOMEM; diff --git a/drivers/dma/dw/of.c b/drivers/dma/dw/of.c index 523ca806837cb3..5c26a0cc8e84cf 100644 --- a/drivers/dma/dw/of.c +++ b/drivers/dma/dw/of.c @@ -64,7 +64,7 @@ struct dw_dma_platform_data *dw_dma_parse_dt(struct platform_device *pdev) if (nr_channels > DW_DMA_MAX_NR_CHANNELS) return NULL; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/dma/dw/pci.c b/drivers/dma/dw/pci.c index a3aae3d1c093c6..756551c5cad193 100644 --- a/drivers/dma/dw/pci.c +++ b/drivers/dma/dw/pci.c @@ -40,7 +40,7 @@ static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) if (!data) return -ENOMEM; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c index 5c1c97eb28a4a9..7e76391475ac1d 100644 --- a/drivers/dma/dw/platform.c +++ b/drivers/dma/dw/platform.c @@ -37,7 +37,7 @@ static int dw_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/dma/dw/rzn1-dmamux.c b/drivers/dma/dw/rzn1-dmamux.c index fb495ee6edfcf2..ddcd111d57ee2d 100644 --- a/drivers/dma/dw/rzn1-dmamux.c +++ b/drivers/dma/dw/rzn1-dmamux.c @@ -127,7 +127,7 @@ static int rzn1_dmamux_probe(struct platform_device *pdev) struct device_node *dmac_node; struct rzn1_dmamux_data *dmamux; - dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL); + dmamux = devm_kzalloc_obj(&pdev->dev, *dmamux); if (!dmamux) return -ENOMEM; diff --git a/drivers/dma/ep93xx_dma.c b/drivers/dma/ep93xx_dma.c index cbfe74fc8d71ed..8a0b66a7d88643 100644 --- a/drivers/dma/ep93xx_dma.c +++ b/drivers/dma/ep93xx_dma.c @@ -1372,8 +1372,7 @@ static struct ep93xx_dma_engine *ep93xx_dma_of_probe(struct platform_device *pde if (!data) return ERR_PTR(dev_err_probe(dev, -ENODEV, "No device match found\n")); - edma = devm_kzalloc(dev, struct_size(edma, channels, data->num_channels), - GFP_KERNEL); + edma = devm_kzalloc_flex(dev, *edma, channels, data->num_channels); if (!edma) return ERR_PTR(-ENOMEM); diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index 630285c854824e..da513991148845 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -719,8 +719,7 @@ static int fsl_edma_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, ret, "Can't get dma-channels.\n"); - fsl_edma = devm_kzalloc(&pdev->dev, struct_size(fsl_edma, chans, chans), - GFP_KERNEL); + fsl_edma = devm_kzalloc_flex(&pdev->dev, *fsl_edma, chans, chans); if (!fsl_edma) return -ENOMEM; diff --git a/drivers/dma/fsl-qdma.c b/drivers/dma/fsl-qdma.c index df843fad0ece50..27c632e6fa7882 100644 --- a/drivers/dma/fsl-qdma.c +++ b/drivers/dma/fsl-qdma.c @@ -559,8 +559,7 @@ static struct fsl_qdma_queue dev_err(&pdev->dev, "Get wrong status_size.\n"); return NULL; } - status_head = devm_kzalloc(&pdev->dev, - sizeof(*status_head), GFP_KERNEL); + status_head = devm_kzalloc_obj(&pdev->dev, *status_head); if (!status_head) return NULL; diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c index 9cc289f7129edd..fbfd3b6fa58644 100644 --- a/drivers/dma/fsl_raid.c +++ b/drivers/dma/fsl_raid.c @@ -645,7 +645,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev, re_priv = dev_get_drvdata(dev); dma_dev = &re_priv->dma_dev; - chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(dev, *chan); if (!chan) return -ENOMEM; @@ -767,7 +767,7 @@ static int fsl_re_probe(struct platform_device *ofdev) if (IS_ERR(re_regs)) return PTR_ERR(re_regs); - re_priv = devm_kzalloc(dev, sizeof(*re_priv), GFP_KERNEL); + re_priv = devm_kzalloc_obj(dev, *re_priv); if (!re_priv) return -ENOMEM; diff --git a/drivers/dma/hisi_dma.c b/drivers/dma/hisi_dma.c index c751a2e49e6dc3..d3ec1819aa5d1b 100644 --- a/drivers/dma/hisi_dma.c +++ b/drivers/dma/hisi_dma.c @@ -853,8 +853,7 @@ static struct debugfs_reg32 *hisi_dma_get_ch_regs(struct hisi_dma_dev *hdma_dev, else *regs_sz = regs_sz_comm + ARRAY_SIZE(hisi_dma_hip09_chan_regs); - regs = devm_kcalloc(dev, *regs_sz, sizeof(struct debugfs_reg32), - GFP_KERNEL); + regs = devm_kzalloc_objs(dev, struct debugfs_reg32, *regs_sz); if (!regs) return NULL; memcpy(regs, hisi_dma_comm_chan_regs, sizeof(hisi_dma_comm_chan_regs)); @@ -882,8 +881,7 @@ static int hisi_dma_create_chan_dir(struct hisi_dma_dev *hdma_dev) dev = &hdma_dev->pdev->dev; - regsets = devm_kcalloc(dev, hdma_dev->chan_num, - sizeof(*regsets), GFP_KERNEL); + regsets = devm_kzalloc_objs(dev, *regsets, hdma_dev->chan_num); if (!regsets) return -ENOMEM; @@ -921,7 +919,7 @@ static void hisi_dma_create_debugfs(struct hisi_dma_dev *hdma_dev) if (hdma_dev->dma_dev.dbg_dev_root == NULL) return; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return; @@ -980,8 +978,7 @@ static int hisi_dma_probe(struct pci_dev *pdev, const struct pci_device_id *id) return ret; chan_num = hisi_dma_get_chan_num(pdev); - hdma_dev = devm_kzalloc(dev, struct_size(hdma_dev, chan, chan_num), - GFP_KERNEL); + hdma_dev = devm_kzalloc_flex(dev, *hdma_dev, chan, chan_num); if (!hdma_dev) return -ENOMEM; diff --git a/drivers/dma/hsu/hsu.c b/drivers/dma/hsu/hsu.c index f62d60d7bc6b74..ce24e840af5944 100644 --- a/drivers/dma/hsu/hsu.c +++ b/drivers/dma/hsu/hsu.c @@ -431,7 +431,7 @@ int hsu_dma_probe(struct hsu_dma_chip *chip) unsigned short i; int ret; - hsu = devm_kzalloc(chip->dev, sizeof(*hsu), GFP_KERNEL); + hsu = devm_kzalloc_obj(chip->dev, *hsu); if (!hsu) return -ENOMEM; @@ -440,8 +440,7 @@ int hsu_dma_probe(struct hsu_dma_chip *chip) /* Calculate nr_channels from the IO space length */ hsu->nr_channels = (chip->length - chip->offset) / HSU_DMA_CHAN_LENGTH; - hsu->chan = devm_kcalloc(chip->dev, hsu->nr_channels, - sizeof(*hsu->chan), GFP_KERNEL); + hsu->chan = devm_kzalloc_objs(chip->dev, *hsu->chan, hsu->nr_channels); if (!hsu->chan) return -ENOMEM; diff --git a/drivers/dma/hsu/pci.c b/drivers/dma/hsu/pci.c index 0fcc0c0c22fc5e..ed5fbcb2959ef0 100644 --- a/drivers/dma/hsu/pci.c +++ b/drivers/dma/hsu/pci.c @@ -73,7 +73,7 @@ static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) return ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/dma/idma64.c b/drivers/dma/idma64.c index 657629b100fa95..e3db213e564b45 100644 --- a/drivers/dma/idma64.c +++ b/drivers/dma/idma64.c @@ -535,15 +535,14 @@ static int idma64_probe(struct idma64_chip *chip) unsigned short i; int ret; - idma64 = devm_kzalloc(chip->dev, sizeof(*idma64), GFP_KERNEL); + idma64 = devm_kzalloc_obj(chip->dev, *idma64); if (!idma64) return -ENOMEM; idma64->regs = chip->regs; chip->idma64 = idma64; - idma64->chan = devm_kcalloc(chip->dev, nr_chan, sizeof(*idma64->chan), - GFP_KERNEL); + idma64->chan = devm_kzalloc_objs(chip->dev, *idma64->chan, nr_chan); if (!idma64->chan) return -ENOMEM; @@ -631,7 +630,7 @@ static int idma64_platform_probe(struct platform_device *pdev) struct device *sysdev = dev->parent; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/dma/img-mdc-dma.c b/drivers/dma/img-mdc-dma.c index a3192d49b6c860..b91807d5ae8267 100644 --- a/drivers/dma/img-mdc-dma.c +++ b/drivers/dma/img-mdc-dma.c @@ -889,7 +889,7 @@ static int mdc_dma_probe(struct platform_device *pdev) u32 val; int ret; - mdma = devm_kzalloc(&pdev->dev, sizeof(*mdma), GFP_KERNEL); + mdma = devm_kzalloc_obj(&pdev->dev, *mdma); if (!mdma) return -ENOMEM; platform_set_drvdata(pdev, mdma); diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c index 81c6276436f811..ca1d08e90a0627 100644 --- a/drivers/dma/imx-dma.c +++ b/drivers/dma/imx-dma.c @@ -1039,7 +1039,7 @@ static int __init imxdma_probe(struct platform_device *pdev) int ret, i; int irq, irq_err; - imxdma = devm_kzalloc(&pdev->dev, sizeof(*imxdma), GFP_KERNEL); + imxdma = devm_kzalloc_obj(&pdev->dev, *imxdma); if (!imxdma) return -ENOMEM; diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 36368835a845c9..749f1fe779075f 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -2248,7 +2248,7 @@ static int sdma_probe(struct platform_device *pdev) if (ret) return ret; - sdma = devm_kzalloc(&pdev->dev, sizeof(*sdma), GFP_KERNEL); + sdma = devm_kzalloc_obj(&pdev->dev, *sdma); if (!sdma) return -ENOMEM; diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c index e84f197fea76f1..079dda13cf0c83 100644 --- a/drivers/dma/k3dma.c +++ b/drivers/dma/k3dma.c @@ -835,7 +835,7 @@ static int k3_dma_probe(struct platform_device *op) struct k3_dma_dev *d; int i, ret, irq = 0; - d = devm_kzalloc(&op->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(&op->dev, *d); if (!d) return -ENOMEM; @@ -882,8 +882,7 @@ static int k3_dma_probe(struct platform_device *op) return -ENOMEM; /* init phy channel */ - d->phy = devm_kcalloc(&op->dev, - d->dma_channels, sizeof(struct k3_dma_phy), GFP_KERNEL); + d->phy = devm_kzalloc_objs(&op->dev, struct k3_dma_phy, d->dma_channels); if (d->phy == NULL) return -ENOMEM; @@ -917,8 +916,8 @@ static int k3_dma_probe(struct platform_device *op) d->slave.copy_align = DMAENGINE_ALIGN_8_BYTES; /* init virtual channel */ - d->chans = devm_kcalloc(&op->dev, - d->dma_requests, sizeof(struct k3_dma_chan), GFP_KERNEL); + d->chans = devm_kzalloc_objs(&op->dev, struct k3_dma_chan, + d->dma_requests); if (d->chans == NULL) return -ENOMEM; diff --git a/drivers/dma/lgm/lgm-dma.c b/drivers/dma/lgm/lgm-dma.c index c1f859472a9628..fb024946c8cffc 100644 --- a/drivers/dma/lgm/lgm-dma.c +++ b/drivers/dma/lgm/lgm-dma.c @@ -1567,7 +1567,7 @@ static int intel_ldma_probe(struct platform_device *pdev) u32 id, bitn = 32, j; int i, ret; - d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(dev, *d); if (!d) return -ENOMEM; @@ -1641,12 +1641,12 @@ static int intel_ldma_probe(struct platform_device *pdev) INIT_LIST_HEAD(&dma_dev->channels); /* Port Initializations */ - d->ports = devm_kcalloc(dev, d->port_nrs, sizeof(*p), GFP_KERNEL); + d->ports = devm_kzalloc_objs(dev, *p, d->port_nrs); if (!d->ports) return -ENOMEM; /* Channels Initializations */ - d->chans = devm_kcalloc(d->dev, d->chan_nrs, sizeof(*c), GFP_KERNEL); + d->chans = devm_kzalloc_objs(d->dev, *c, d->chan_nrs); if (!d->chans) return -ENOMEM; diff --git a/drivers/dma/loongson/loongson1-apb-dma.c b/drivers/dma/loongson/loongson1-apb-dma.c index 46b4bfef45e26f..10a1920ff6c2d1 100644 --- a/drivers/dma/loongson/loongson1-apb-dma.c +++ b/drivers/dma/loongson/loongson1-apb-dma.c @@ -565,7 +565,7 @@ static int ls1x_dma_probe(struct platform_device *pdev) "Invalid number of IRQ channels: %d\n", ret); - dma = devm_kzalloc(dev, struct_size(dma, chan, ret), GFP_KERNEL); + dma = devm_kzalloc_flex(dev, *dma, chan, ret); if (!dma) return -ENOMEM; dma->nr_chans = ret; diff --git a/drivers/dma/loongson/loongson2-apb-cmc-dma.c b/drivers/dma/loongson/loongson2-apb-cmc-dma.c index 2037120b23caa5..ae5f2afee54c8b 100644 --- a/drivers/dma/loongson/loongson2-apb-cmc-dma.c +++ b/drivers/dma/loongson/loongson2-apb-cmc-dma.c @@ -546,7 +546,7 @@ static int loongson2_cmc_dma_acpi_controller_register(struct loongson2_cmc_dma_d if (!is_acpi_node(dev_fwnode(dev))) return 0; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; @@ -616,7 +616,7 @@ static int loongson2_cmc_dma_probe(struct platform_device *pdev) nr_chans = config->max_channels; } - lddev = devm_kzalloc(dev, struct_size(lddev, chan, nr_chans), GFP_KERNEL); + lddev = devm_kzalloc_flex(dev, *lddev, chan, nr_chans); if (!lddev) return -ENOMEM; diff --git a/drivers/dma/loongson/loongson2-apb-dma.c b/drivers/dma/loongson/loongson2-apb-dma.c index 16a0c1c60d59ae..10c60fab3d4ee0 100644 --- a/drivers/dma/loongson/loongson2-apb-dma.c +++ b/drivers/dma/loongson/loongson2-apb-dma.c @@ -598,7 +598,7 @@ static int ls2x_dma_probe(struct platform_device *pdev) struct dma_device *ddev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c index d3ff521951b835..40a338f0d44bfb 100644 --- a/drivers/dma/lpc18xx-dmamux.c +++ b/drivers/dma/lpc18xx-dmamux.c @@ -124,7 +124,7 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev) struct lpc18xx_dmamux_data *dmamux; int ret; - dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL); + dmamux = devm_kzalloc_obj(&pdev->dev, *dmamux); if (!dmamux) return -ENOMEM; @@ -155,9 +155,8 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev) return ret; } - dmamux->muxes = devm_kcalloc(&pdev->dev, dmamux->dma_master_requests, - sizeof(struct lpc18xx_dmamux), - GFP_KERNEL); + dmamux->muxes = devm_kzalloc_objs(&pdev->dev, struct lpc18xx_dmamux, + dmamux->dma_master_requests); if (!dmamux->muxes) return -ENOMEM; diff --git a/drivers/dma/lpc32xx-dmamux.c b/drivers/dma/lpc32xx-dmamux.c index 33be714740ddfb..4fbeb3496acf40 100644 --- a/drivers/dma/lpc32xx-dmamux.c +++ b/drivers/dma/lpc32xx-dmamux.c @@ -165,7 +165,7 @@ static int lpc32xx_dmamux_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct lpc32xx_dmamux_data *dmamux; - dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL); + dmamux = devm_kzalloc_obj(&pdev->dev, *dmamux); if (!dmamux) return -ENOMEM; diff --git a/drivers/dma/mcf-edma-main.c b/drivers/dma/mcf-edma-main.c index 9e1c6400c77be2..77a73cf679e1f6 100644 --- a/drivers/dma/mcf-edma-main.c +++ b/drivers/dma/mcf-edma-main.c @@ -169,8 +169,7 @@ static int mcf_edma_probe(struct platform_device *pdev) chans = pdata->dma_channels; } - mcf_edma = devm_kzalloc(&pdev->dev, struct_size(mcf_edma, chans, chans), - GFP_KERNEL); + mcf_edma = devm_kzalloc_flex(&pdev->dev, *mcf_edma, chans, chans); if (!mcf_edma) return -ENOMEM; diff --git a/drivers/dma/mediatek/mtk-cqdma.c b/drivers/dma/mediatek/mtk-cqdma.c index 80791e30aec243..a7000608ddeac5 100644 --- a/drivers/dma/mediatek/mtk-cqdma.c +++ b/drivers/dma/mediatek/mtk-cqdma.c @@ -751,7 +751,7 @@ static int mtk_cqdma_probe(struct platform_device *pdev) int err; u32 i; - cqdma = devm_kzalloc(&pdev->dev, sizeof(*cqdma), GFP_KERNEL); + cqdma = devm_kzalloc_obj(&pdev->dev, *cqdma); if (!cqdma) return -ENOMEM; @@ -800,15 +800,14 @@ static int mtk_cqdma_probe(struct platform_device *pdev) cqdma->dma_channels = MTK_CQDMA_NR_PCHANS; } - cqdma->pc = devm_kcalloc(&pdev->dev, cqdma->dma_channels, - sizeof(*cqdma->pc), GFP_KERNEL); + cqdma->pc = devm_kzalloc_objs(&pdev->dev, *cqdma->pc, + cqdma->dma_channels); if (!cqdma->pc) return -ENOMEM; /* initialization for PCs */ for (i = 0; i < cqdma->dma_channels; ++i) { - cqdma->pc[i] = devm_kcalloc(&pdev->dev, 1, - sizeof(**cqdma->pc), GFP_KERNEL); + cqdma->pc[i] = devm_kzalloc_objs(&pdev->dev, **cqdma->pc, 1); if (!cqdma->pc[i]) return -ENOMEM; @@ -836,8 +835,8 @@ static int mtk_cqdma_probe(struct platform_device *pdev) } /* allocate resource for VCs */ - cqdma->vc = devm_kcalloc(&pdev->dev, cqdma->dma_requests, - sizeof(*cqdma->vc), GFP_KERNEL); + cqdma->vc = devm_kzalloc_objs(&pdev->dev, *cqdma->vc, + cqdma->dma_requests); if (!cqdma->vc) return -ENOMEM; diff --git a/drivers/dma/mediatek/mtk-hsdma.c b/drivers/dma/mediatek/mtk-hsdma.c index 27cb370106c777..ad5883cf61655f 100644 --- a/drivers/dma/mediatek/mtk-hsdma.c +++ b/drivers/dma/mediatek/mtk-hsdma.c @@ -906,7 +906,7 @@ static int mtk_hsdma_probe(struct platform_device *pdev) struct dma_device *dd; int i, err; - hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL); + hsdma = devm_kzalloc_obj(&pdev->dev, *hsdma); if (!hsdma) return -ENOMEM; @@ -962,13 +962,13 @@ static int mtk_hsdma_probe(struct platform_device *pdev) MTK_HSDMA_NR_VCHANS); } - hsdma->pc = devm_kcalloc(&pdev->dev, MTK_HSDMA_NR_MAX_PCHANS, - sizeof(*hsdma->pc), GFP_KERNEL); + hsdma->pc = devm_kzalloc_objs(&pdev->dev, *hsdma->pc, + MTK_HSDMA_NR_MAX_PCHANS); if (!hsdma->pc) return -ENOMEM; - hsdma->vc = devm_kcalloc(&pdev->dev, hsdma->dma_requests, - sizeof(*hsdma->vc), GFP_KERNEL); + hsdma->vc = devm_kzalloc_objs(&pdev->dev, *hsdma->vc, + hsdma->dma_requests); if (!hsdma->vc) return -ENOMEM; diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index f74e9a3285887f..bf242c4c262ff1 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -484,7 +484,7 @@ static int mtk_uart_apdma_probe(struct platform_device *pdev) unsigned int bit_mask, i; int rc; - mtkd = devm_kzalloc(&pdev->dev, sizeof(*mtkd), GFP_KERNEL); + mtkd = devm_kzalloc_obj(&pdev->dev, *mtkd); if (!mtkd) return -ENOMEM; @@ -529,7 +529,7 @@ static int mtk_uart_apdma_probe(struct platform_device *pdev) } for (i = 0; i < mtkd->dma_requests; i++) { - c = devm_kzalloc(mtkd->ddev.dev, sizeof(*c), GFP_KERNEL); + c = devm_kzalloc_obj(mtkd->ddev.dev, *c); if (!c) { rc = -ENOMEM; goto err_no_dma; diff --git a/drivers/dma/milbeaut-hdmac.c b/drivers/dma/milbeaut-hdmac.c index b4ebc09e80d01c..642209721585b1 100644 --- a/drivers/dma/milbeaut-hdmac.c +++ b/drivers/dma/milbeaut-hdmac.c @@ -467,8 +467,7 @@ static int milbeaut_hdmac_probe(struct platform_device *pdev) if (ret) return ret; - mdev = devm_kzalloc(dev, struct_size(mdev, channels, nr_chans), - GFP_KERNEL); + mdev = devm_kzalloc_flex(dev, *mdev, channels, nr_chans); if (!mdev) return -ENOMEM; diff --git a/drivers/dma/milbeaut-xdmac.c b/drivers/dma/milbeaut-xdmac.c index 0bfa247e746e87..630c498bb9af16 100644 --- a/drivers/dma/milbeaut-xdmac.c +++ b/drivers/dma/milbeaut-xdmac.c @@ -318,8 +318,7 @@ static int milbeaut_xdmac_probe(struct platform_device *pdev) if (nr_chans < 0) return nr_chans; - mdev = devm_kzalloc(dev, struct_size(mdev, channels, nr_chans), - GFP_KERNEL); + mdev = devm_kzalloc_flex(dev, *mdev, channels, nr_chans); if (!mdev) return -ENOMEM; diff --git a/drivers/dma/mmp_pdma.c b/drivers/dma/mmp_pdma.c index 8abd24e2ffc74a..6045d6d1cc79e8 100644 --- a/drivers/dma/mmp_pdma.c +++ b/drivers/dma/mmp_pdma.c @@ -1149,7 +1149,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq) struct mmp_pdma_chan *chan; int ret; - chan = devm_kzalloc(pdev->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(pdev->dev, *chan); if (chan == NULL) return -ENOMEM; @@ -1263,7 +1263,7 @@ static int mmp_pdma_probe(struct platform_device *op) DMA_SLAVE_BUSWIDTH_1_BYTE | DMA_SLAVE_BUSWIDTH_2_BYTES | DMA_SLAVE_BUSWIDTH_4_BYTES; - pdev = devm_kzalloc(&op->dev, sizeof(*pdev), GFP_KERNEL); + pdev = devm_kzalloc_obj(&op->dev, *pdev); if (!pdev) return -ENOMEM; @@ -1306,8 +1306,7 @@ static int mmp_pdma_probe(struct platform_device *op) irq_num++; } - pdev->phy = devm_kcalloc(pdev->dev, dma_channels, sizeof(*pdev->phy), - GFP_KERNEL); + pdev->phy = devm_kzalloc_objs(pdev->dev, *pdev->phy, dma_channels); if (pdev->phy == NULL) return -ENOMEM; diff --git a/drivers/dma/mmp_tdma.c b/drivers/dma/mmp_tdma.c index ba03321eeff799..d7dd58970060f9 100644 --- a/drivers/dma/mmp_tdma.c +++ b/drivers/dma/mmp_tdma.c @@ -569,7 +569,7 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev, } /* alloc channel */ - tdmac = devm_kzalloc(tdev->dev, sizeof(*tdmac), GFP_KERNEL); + tdmac = devm_kzalloc_obj(tdev->dev, *tdmac); if (!tdmac) return -ENOMEM; @@ -643,7 +643,7 @@ static int mmp_tdma_probe(struct platform_device *pdev) type = (kernel_ulong_t)device_get_match_data(&pdev->dev); /* always have couple channels */ - tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL); + tdev = devm_kzalloc_obj(&pdev->dev, *tdev); if (!tdev) return -ENOMEM; diff --git a/drivers/dma/moxart-dma.c b/drivers/dma/moxart-dma.c index 28be93eed4cce4..45233d59d358ac 100644 --- a/drivers/dma/moxart-dma.c +++ b/drivers/dma/moxart-dma.c @@ -558,7 +558,7 @@ static int moxart_probe(struct platform_device *pdev) struct moxart_chan *ch; struct moxart_dmadev *mdc; - mdc = devm_kzalloc(dev, sizeof(*mdc), GFP_KERNEL); + mdc = devm_kzalloc_obj(dev, *mdc); if (!mdc) return -ENOMEM; diff --git a/drivers/dma/mpc512x_dma.c b/drivers/dma/mpc512x_dma.c index 0adc8e01057e1d..f67421f2d6d3e1 100644 --- a/drivers/dma/mpc512x_dma.c +++ b/drivers/dma/mpc512x_dma.c @@ -907,7 +907,7 @@ static int mpc_dma_probe(struct platform_device *op) int retval, i; u8 chancnt; - mdma = devm_kzalloc(dev, sizeof(struct mpc_dma), GFP_KERNEL); + mdma = devm_kzalloc_obj(dev, struct mpc_dma); if (!mdma) { retval = -ENOMEM; goto err; diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c index c4e0dce3ca64e3..92fb996f5b3f55 100644 --- a/drivers/dma/mv_xor.c +++ b/drivers/dma/mv_xor.c @@ -1044,7 +1044,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev, struct mv_xor_chan *mv_chan; struct dma_device *dma_dev; - mv_chan = devm_kzalloc(&pdev->dev, sizeof(*mv_chan), GFP_KERNEL); + mv_chan = devm_kzalloc_obj(&pdev->dev, *mv_chan); if (!mv_chan) return ERR_PTR(-ENOMEM); @@ -1321,7 +1321,7 @@ static int mv_xor_probe(struct platform_device *pdev) dev_notice(&pdev->dev, "Marvell shared XOR driver\n"); - xordev = devm_kzalloc(&pdev->dev, sizeof(*xordev), GFP_KERNEL); + xordev = devm_kzalloc_obj(&pdev->dev, *xordev); if (!xordev) return -ENOMEM; diff --git a/drivers/dma/mv_xor_v2.c b/drivers/dma/mv_xor_v2.c index cad4d4fb51ac35..1920dcd5886e73 100644 --- a/drivers/dma/mv_xor_v2.c +++ b/drivers/dma/mv_xor_v2.c @@ -721,7 +721,7 @@ static int mv_xor_v2_probe(struct platform_device *pdev) BUILD_BUG_ON(sizeof(struct mv_xor_v2_descriptor) != MV_XOR_V2_EXT_DESC_SIZE); - xor_dev = devm_kzalloc(&pdev->dev, sizeof(*xor_dev), GFP_KERNEL); + xor_dev = devm_kzalloc_obj(&pdev->dev, *xor_dev); if (!xor_dev) return -ENOMEM; @@ -781,9 +781,8 @@ static int mv_xor_v2_probe(struct platform_device *pdev) } /* alloc memory for the SW descriptors */ - xor_dev->sw_desq = devm_kcalloc(&pdev->dev, - MV_XOR_V2_DESC_NUM, sizeof(*sw_desc), - GFP_KERNEL); + xor_dev->sw_desq = devm_kzalloc_objs(&pdev->dev, *sw_desc, + MV_XOR_V2_DESC_NUM); if (!xor_dev->sw_desq) { ret = -ENOMEM; goto free_hw_desq; diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c index 7acb3d29dad307..cfe4d759d65ffe 100644 --- a/drivers/dma/mxs-dma.c +++ b/drivers/dma/mxs-dma.c @@ -748,7 +748,7 @@ static int mxs_dma_probe(struct platform_device *pdev) struct mxs_dma_engine *mxs_dma; int ret, i; - mxs_dma = devm_kzalloc(dev, sizeof(*mxs_dma), GFP_KERNEL); + mxs_dma = devm_kzalloc_obj(dev, *mxs_dma); if (!mxs_dma) return -ENOMEM; diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c index 744cd14d78725b..c9010938c30f34 100644 --- a/drivers/dma/nbpfaxi.c +++ b/drivers/dma/nbpfaxi.c @@ -1321,8 +1321,7 @@ static int nbpf_probe(struct platform_device *pdev) cfg = of_device_get_match_data(dev); num_channels = cfg->num_channels; - nbpf = devm_kzalloc(dev, struct_size(nbpf, chan, num_channels), - GFP_KERNEL); + nbpf = devm_kzalloc_flex(dev, *nbpf, chan, num_channels); if (!nbpf) return -ENOMEM; diff --git a/drivers/dma/owl-dma.c b/drivers/dma/owl-dma.c index 9dc88d804a2e47..31a6c6e01a7506 100644 --- a/drivers/dma/owl-dma.c +++ b/drivers/dma/owl-dma.c @@ -1089,7 +1089,7 @@ static int owl_dma_probe(struct platform_device *pdev) struct owl_dma *od; int ret, i, nr_channels, nr_requests; - od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); + od = devm_kzalloc_obj(&pdev->dev, *od); if (!od) return -ENOMEM; @@ -1164,8 +1164,8 @@ static int owl_dma_probe(struct platform_device *pdev) } /* Init physical channel */ - od->pchans = devm_kcalloc(&pdev->dev, od->nr_pchans, - sizeof(struct owl_dma_pchan), GFP_KERNEL); + od->pchans = devm_kzalloc_objs(&pdev->dev, struct owl_dma_pchan, + od->nr_pchans); if (!od->pchans) return -ENOMEM; @@ -1177,8 +1177,8 @@ static int owl_dma_probe(struct platform_device *pdev) } /* Init virtual channel */ - od->vchans = devm_kcalloc(&pdev->dev, od->nr_vchans, - sizeof(struct owl_dma_vchan), GFP_KERNEL); + od->vchans = devm_kzalloc_objs(&pdev->dev, struct owl_dma_vchan, + od->nr_vchans); if (!od->vchans) return -ENOMEM; diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c index c2d0b473b8f485..977a9fde80adbb 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -3024,7 +3024,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id) return ret; /* Allocate a new DMAC and its Channels */ - pl330 = devm_kzalloc(&adev->dev, sizeof(*pl330), GFP_KERNEL); + pl330 = devm_kzalloc_obj(&adev->dev, *pl330); if (!pl330) return -ENOMEM; diff --git a/drivers/dma/pxa_dma.c b/drivers/dma/pxa_dma.c index 4f0d1d531f0101..bf03009bb96623 100644 --- a/drivers/dma/pxa_dma.c +++ b/drivers/dma/pxa_dma.c @@ -1239,8 +1239,7 @@ static int pxad_init_phys(struct platform_device *op, if (irq0 < 0) return irq0; - pdev->phys = devm_kcalloc(&op->dev, nb_phy_chans, - sizeof(pdev->phys[0]), GFP_KERNEL); + pdev->phys = devm_kzalloc_objs(&op->dev, pdev->phys[0], nb_phy_chans); if (!pdev->phys) return -ENOMEM; @@ -1324,7 +1323,7 @@ static int pxad_init_dmadev(struct platform_device *op, return ret; for (i = 0; i < nr_phy_chans; i++) { - c = devm_kzalloc(&op->dev, sizeof(*c), GFP_KERNEL); + c = devm_kzalloc_obj(&op->dev, *c); if (!c) return -ENOMEM; @@ -1348,7 +1347,7 @@ static int pxad_probe(struct platform_device *op) DMA_SLAVE_BUSWIDTH_1_BYTE | DMA_SLAVE_BUSWIDTH_2_BYTES | DMA_SLAVE_BUSWIDTH_4_BYTES; - pdev = devm_kzalloc(&op->dev, sizeof(*pdev), GFP_KERNEL); + pdev = devm_kzalloc_obj(&op->dev, *pdev); if (!pdev) return -ENOMEM; diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c index f67a93a37d48cc..e62e411dc8f8b2 100644 --- a/drivers/dma/qcom/bam_dma.c +++ b/drivers/dma/qcom/bam_dma.c @@ -1249,7 +1249,7 @@ static int bam_dma_probe(struct platform_device *pdev) const struct of_device_id *match; int ret, i; - bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL); + bdev = devm_kzalloc_obj(&pdev->dev, *bdev); if (!bdev) return -ENOMEM; @@ -1318,8 +1318,8 @@ static int bam_dma_probe(struct platform_device *pdev) tasklet_setup(&bdev->task, dma_tasklet); - bdev->channels = devm_kcalloc(bdev->dev, bdev->num_channels, - sizeof(*bdev->channels), GFP_KERNEL); + bdev->channels = devm_kzalloc_objs(bdev->dev, *bdev->channels, + bdev->num_channels); if (!bdev->channels) { ret = -ENOMEM; diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c index c41bfac65ddf3f..d3c3d0f35afbe0 100644 --- a/drivers/dma/qcom/gpi.c +++ b/drivers/dma/qcom/gpi.c @@ -2170,7 +2170,7 @@ static int gpi_probe(struct platform_device *pdev) u32 ee_offset; int ret; - gpi_dev = devm_kzalloc(&pdev->dev, sizeof(*gpi_dev), GFP_KERNEL); + gpi_dev = devm_kzalloc_obj(&pdev->dev, *gpi_dev); if (!gpi_dev) return -ENOMEM; diff --git a/drivers/dma/qcom/hidma.c b/drivers/dma/qcom/hidma.c index 1349066b1544dd..85844965f0d8c7 100644 --- a/drivers/dma/qcom/hidma.c +++ b/drivers/dma/qcom/hidma.c @@ -194,7 +194,7 @@ static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig) struct hidma_chan *mchan; struct dma_device *ddev; - mchan = devm_kzalloc(dmadev->ddev.dev, sizeof(*mchan), GFP_KERNEL); + mchan = devm_kzalloc_obj(dmadev->ddev.dev, *mchan); if (!mchan) return -ENOMEM; @@ -640,8 +640,7 @@ hidma_create_sysfs_entry(struct hidma_dev *dev, char *name, int mode) struct device_attribute *attrs; char *name_copy; - attrs = devm_kmalloc(dev->ddev.dev, sizeof(struct device_attribute), - GFP_KERNEL); + attrs = devm_kmalloc_obj(dev->ddev.dev, struct device_attribute); if (!attrs) return NULL; @@ -783,7 +782,7 @@ static int hidma_probe(struct platform_device *pdev) goto bailout; } - dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev), GFP_KERNEL); + dmadev = devm_kzalloc_obj(&pdev->dev, *dmadev); if (!dmadev) { rc = -ENOMEM; goto bailout; diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c index f081aa787f0c27..20a484254c929b 100644 --- a/drivers/dma/qcom/hidma_ll.c +++ b/drivers/dma/qcom/hidma_ll.c @@ -721,7 +721,7 @@ struct hidma_lldev *hidma_ll_init(struct device *dev, u32 nr_tres, /* need an extra space */ nr_tres += 1; - lldev = devm_kzalloc(dev, sizeof(struct hidma_lldev), GFP_KERNEL); + lldev = devm_kzalloc_obj(dev, struct hidma_lldev); if (!lldev) return NULL; diff --git a/drivers/dma/qcom/hidma_mgmt.c b/drivers/dma/qcom/hidma_mgmt.c index 4805ce390ffac8..e890e9deb98797 100644 --- a/drivers/dma/qcom/hidma_mgmt.c +++ b/drivers/dma/qcom/hidma_mgmt.c @@ -183,7 +183,7 @@ static int hidma_mgmt_probe(struct platform_device *pdev) goto out; } - mgmtdev = devm_kzalloc(&pdev->dev, sizeof(*mgmtdev), GFP_KERNEL); + mgmtdev = devm_kzalloc_obj(&pdev->dev, *mgmtdev); if (!mgmtdev) { rc = -ENOMEM; goto out; @@ -265,18 +265,15 @@ static int hidma_mgmt_probe(struct platform_device *pdev) } else max_rd_xactions = mgmtdev->max_rd_xactions; - mgmtdev->priority = devm_kcalloc(&pdev->dev, - mgmtdev->dma_channels, - sizeof(*mgmtdev->priority), - GFP_KERNEL); + mgmtdev->priority = devm_kzalloc_objs(&pdev->dev, *mgmtdev->priority, + mgmtdev->dma_channels); if (!mgmtdev->priority) { rc = -ENOMEM; goto out; } - mgmtdev->weight = devm_kcalloc(&pdev->dev, - mgmtdev->dma_channels, - sizeof(*mgmtdev->weight), GFP_KERNEL); + mgmtdev->weight = devm_kzalloc_objs(&pdev->dev, *mgmtdev->weight, + mgmtdev->dma_channels); if (!mgmtdev->weight) { rc = -ENOMEM; goto out; diff --git a/drivers/dma/qcom/hidma_mgmt_sys.c b/drivers/dma/qcom/hidma_mgmt_sys.c index 9672ef9ee8fc0c..01b5d790c8a9f1 100644 --- a/drivers/dma/qcom/hidma_mgmt_sys.c +++ b/drivers/dma/qcom/hidma_mgmt_sys.c @@ -184,8 +184,7 @@ static int create_sysfs_entry(struct hidma_mgmt_dev *dev, char *name, int mode) struct device_attribute *attrs; char *name_copy; - attrs = devm_kmalloc(&dev->pdev->dev, - sizeof(struct device_attribute), GFP_KERNEL); + attrs = devm_kmalloc_obj(&dev->pdev->dev, struct device_attribute); if (!attrs) return -ENOMEM; @@ -209,7 +208,7 @@ static int create_sysfs_entry_channel(struct hidma_mgmt_dev *mdev, char *name, struct hidma_chan_attr *chattr; char *name_copy; - chattr = devm_kmalloc(&mdev->pdev->dev, sizeof(*chattr), GFP_KERNEL); + chattr = devm_kmalloc_obj(&mdev->pdev->dev, *chattr); if (!chattr) return -ENOMEM; diff --git a/drivers/dma/qcom/qcom_adm.c b/drivers/dma/qcom/qcom_adm.c index 07fbe32d31fa48..b38ee75a96378a 100644 --- a/drivers/dma/qcom/qcom_adm.c +++ b/drivers/dma/qcom/qcom_adm.c @@ -748,7 +748,7 @@ static int adm_dma_probe(struct platform_device *pdev) int ret; u32 i; - adev = devm_kzalloc(&pdev->dev, sizeof(*adev), GFP_KERNEL); + adev = devm_kzalloc_obj(&pdev->dev, *adev); if (!adev) return -ENOMEM; @@ -824,8 +824,8 @@ static int adm_dma_probe(struct platform_device *pdev) reset_control_deassert(adev->c1_reset); reset_control_deassert(adev->c2_reset); - adev->channels = devm_kcalloc(adev->dev, ADM_MAX_CHANNELS, - sizeof(*adev->channels), GFP_KERNEL); + adev->channels = devm_kzalloc_objs(adev->dev, *adev->channels, + ADM_MAX_CHANNELS); if (!adev->channels) { ret = -ENOMEM; diff --git a/drivers/dma/sf-pdma/sf-pdma.c b/drivers/dma/sf-pdma/sf-pdma.c index 6f79cc28703e60..4770ec3470cb94 100644 --- a/drivers/dma/sf-pdma/sf-pdma.c +++ b/drivers/dma/sf-pdma/sf-pdma.c @@ -513,8 +513,7 @@ static int sf_pdma_probe(struct platform_device *pdev) return -EINVAL; } - pdma = devm_kzalloc(&pdev->dev, struct_size(pdma, chans, n_chans), - GFP_KERNEL); + pdma = devm_kzalloc_flex(&pdev->dev, *pdma, chans, n_chans); if (!pdma) return -ENOMEM; diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 3ad8aba5dcd403..dc3900d4d99c14 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1856,7 +1856,7 @@ static int rcar_dmac_probe(struct platform_device *pdev) if (!data) return -EINVAL; - dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(&pdev->dev, *dmac); if (!dmac) return -ENOMEM; @@ -1884,8 +1884,8 @@ static int rcar_dmac_probe(struct platform_device *pdev) if (data->broken_ipmmu_microTLB0 && device_iommu_mapped(&pdev->dev)) dmac->channels_mask &= ~BIT(0); - dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels, - sizeof(*dmac->channels), GFP_KERNEL); + dmac->channels = devm_kzalloc_objs(&pdev->dev, *dmac->channels, + dmac->n_channels); if (!dmac->channels) return -ENOMEM; diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index fdd7131e890ab6..adad6e34d16bb0 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -1411,7 +1411,7 @@ static int rz_dmac_probe(struct platform_device *pdev) int irq; u8 i; - dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(&pdev->dev, *dmac); if (!dmac) return -ENOMEM; @@ -1423,8 +1423,8 @@ static int rz_dmac_probe(struct platform_device *pdev) if (ret < 0) return ret; - dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels, - sizeof(*dmac->channels), GFP_KERNEL); + dmac->channels = devm_kzalloc_objs(&pdev->dev, *dmac->channels, + dmac->n_channels); if (!dmac->channels) return -ENOMEM; diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c index 603e15102e45ef..af32fddc23288a 100644 --- a/drivers/dma/sh/shdmac.c +++ b/drivers/dma/sh/shdmac.c @@ -532,8 +532,7 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id, struct shdma_chan *schan; int err; - sh_chan = devm_kzalloc(sdev->dma_dev.dev, sizeof(struct sh_dmae_chan), - GFP_KERNEL); + sh_chan = devm_kzalloc_obj(sdev->dma_dev.dev, struct sh_dmae_chan); if (!sh_chan) return -ENOMEM; @@ -719,8 +718,7 @@ static int sh_dmae_probe(struct platform_device *pdev) if (!errirq_res) return -ENODEV; - shdev = devm_kzalloc(&pdev->dev, sizeof(struct sh_dmae_device), - GFP_KERNEL); + shdev = devm_kzalloc_obj(&pdev->dev, struct sh_dmae_device); if (!shdev) return -ENOMEM; diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c index 16509be0d36080..679053407f09c3 100644 --- a/drivers/dma/sh/usb-dmac.c +++ b/drivers/dma/sh/usb-dmac.c @@ -768,7 +768,7 @@ static int usb_dmac_probe(struct platform_device *pdev) int ret; u8 i; - dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(&pdev->dev, *dmac); if (!dmac) return -ENOMEM; @@ -779,8 +779,8 @@ static int usb_dmac_probe(struct platform_device *pdev) if (ret < 0) return ret; - dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels, - sizeof(*dmac->channels), GFP_KERNEL); + dmac->channels = devm_kzalloc_objs(&pdev->dev, *dmac->channels, + dmac->n_channels); if (!dmac->channels) return -ENOMEM; diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index 60b3067a009945..55ccbb90292621 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c @@ -1114,9 +1114,7 @@ static int sprd_dma_probe(struct platform_device *pdev) return ret; } - sdev = devm_kzalloc(&pdev->dev, - struct_size(sdev, channels, chn_count), - GFP_KERNEL); + sdev = devm_kzalloc_flex(&pdev->dev, *sdev, channels, chn_count); if (!sdev) return -ENOMEM; diff --git a/drivers/dma/st_fdma.c b/drivers/dma/st_fdma.c index 35dbff5f9f1abb..a82058e27aa4aa 100644 --- a/drivers/dma/st_fdma.c +++ b/drivers/dma/st_fdma.c @@ -746,7 +746,7 @@ static int st_fdma_probe(struct platform_device *pdev) drvdata = device_get_match_data(&pdev->dev); - fdev = devm_kzalloc(&pdev->dev, sizeof(*fdev), GFP_KERNEL); + fdev = devm_kzalloc_obj(&pdev->dev, *fdev); if (!fdev) return -ENOMEM; @@ -756,8 +756,8 @@ static int st_fdma_probe(struct platform_device *pdev) goto err; } - fdev->chans = devm_kcalloc(&pdev->dev, fdev->nr_channels, - sizeof(struct st_fdma_chan), GFP_KERNEL); + fdev->chans = devm_kzalloc_objs(&pdev->dev, struct st_fdma_chan, + fdev->nr_channels); if (!fdev->chans) return -ENOMEM; diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index 74dd4cbdc3c0ed..8b89d44f9b0d36 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -3543,21 +3543,17 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, base->gen_dmac.init_reg_size = ARRAY_SIZE(dma_init_reg_v4a); } - base->phy_res = devm_kcalloc(dev, num_phy_chans, - sizeof(*base->phy_res), - GFP_KERNEL); + base->phy_res = devm_kzalloc_objs(dev, *base->phy_res, num_phy_chans); if (!base->phy_res) return -ENOMEM; - base->lookup_phy_chans = devm_kcalloc(dev, num_phy_chans, - sizeof(*base->lookup_phy_chans), - GFP_KERNEL); + base->lookup_phy_chans = devm_kzalloc_objs(dev, *base->lookup_phy_chans, + num_phy_chans); if (!base->lookup_phy_chans) return -ENOMEM; - base->lookup_log_chans = devm_kcalloc(dev, num_log_chans, - sizeof(*base->lookup_log_chans), - GFP_KERNEL); + base->lookup_log_chans = devm_kzalloc_objs(dev, *base->lookup_log_chans, + num_log_chans); if (!base->lookup_log_chans) return -ENOMEM; @@ -3567,16 +3563,14 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, if (!base->reg_val_backup_chan) return -ENOMEM; - base->lcla_pool.alloc_map = devm_kcalloc(dev, num_phy_chans - * D40_LCLA_LINK_PER_EVENT_GRP, - sizeof(*base->lcla_pool.alloc_map), - GFP_KERNEL); + base->lcla_pool.alloc_map = devm_kzalloc_objs(dev, + *base->lcla_pool.alloc_map, + num_phy_chans * D40_LCLA_LINK_PER_EVENT_GRP); if (!base->lcla_pool.alloc_map) return -ENOMEM; - base->regs_interrupt = devm_kmalloc_array(dev, base->gen_dmac.il_size, - sizeof(*base->regs_interrupt), - GFP_KERNEL); + base->regs_interrupt = devm_kmalloc_objs(dev, *base->regs_interrupt, + base->gen_dmac.il_size); if (!base->regs_interrupt) return -ENOMEM; @@ -3663,9 +3657,7 @@ static int __init d40_lcla_allocate(struct d40_base *base) * To full fill this hardware requirement without wasting 256 kb * we allocate pages until we get an aligned one. */ - page_list = kmalloc_array(MAX_LCLA_ALLOC_ATTEMPTS, - sizeof(*page_list), - GFP_KERNEL); + page_list = kmalloc_objs(*page_list, MAX_LCLA_ALLOC_ATTEMPTS); if (!page_list) return -ENOMEM; @@ -3740,7 +3732,7 @@ static int __init d40_of_probe(struct device *dev, const __be32 *list; int ret; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/dma/stm32/stm32-dma.c b/drivers/dma/stm32/stm32-dma.c index 4688cebaf7f7a2..ba8121d37f51dd 100644 --- a/drivers/dma/stm32/stm32-dma.c +++ b/drivers/dma/stm32/stm32-dma.c @@ -1566,7 +1566,7 @@ static int stm32_dma_probe(struct platform_device *pdev) struct reset_control *rst; int i, ret; - dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev), GFP_KERNEL); + dmadev = devm_kzalloc_obj(&pdev->dev, *dmadev); if (!dmadev) return -ENOMEM; diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c index 4fe226541efa49..34d913b0945320 100644 --- a/drivers/dma/stm32/stm32-dma3.c +++ b/drivers/dma/stm32/stm32-dma3.c @@ -1733,7 +1733,7 @@ static int stm32_dma3_probe(struct platform_device *pdev) u64 hwcfgr; int ret; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; platform_set_drvdata(pdev, ddata); @@ -1829,8 +1829,8 @@ static int stm32_dma3_probe(struct platform_device *pdev) ddata->axi_max_burst_len); } - ddata->chans = devm_kcalloc(&pdev->dev, ddata->dma_channels, sizeof(*ddata->chans), - GFP_KERNEL); + ddata->chans = devm_kzalloc_objs(&pdev->dev, *ddata->chans, + ddata->dma_channels); if (!ddata->chans) { ret = -ENOMEM; goto err_clk_disable; diff --git a/drivers/dma/stm32/stm32-mdma.c b/drivers/dma/stm32/stm32-mdma.c index 04639e4b554ea0..4851c1c7ce0c49 100644 --- a/drivers/dma/stm32/stm32-mdma.c +++ b/drivers/dma/stm32/stm32-mdma.c @@ -1615,9 +1615,7 @@ static int stm32_mdma_probe(struct platform_device *pdev) if (count < 0) count = 0; - dmadev = devm_kzalloc(&pdev->dev, - struct_size(dmadev, ahb_addr_masks, count), - GFP_KERNEL); + dmadev = devm_kzalloc_flex(&pdev->dev, *dmadev, ahb_addr_masks, count); if (!dmadev) return -ENOMEM; dmadev->nr_ahb_addr_masks = count; diff --git a/drivers/dma/sun4i-dma.c b/drivers/dma/sun4i-dma.c index 225e4a53502b4d..c877defeddfe80 100644 --- a/drivers/dma/sun4i-dma.c +++ b/drivers/dma/sun4i-dma.c @@ -1228,7 +1228,7 @@ static int sun4i_dma_probe(struct platform_device *pdev) struct sun4i_dma_dev *priv; int i, j, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -1289,13 +1289,12 @@ static int sun4i_dma_probe(struct platform_device *pdev) priv->slave.dev = &pdev->dev; - priv->pchans = devm_kcalloc(&pdev->dev, priv->cfg->dma_nr_max_channels, - sizeof(struct sun4i_dma_pchan), GFP_KERNEL); - priv->vchans = devm_kcalloc(&pdev->dev, SUN4I_DMA_NR_MAX_VCHANS, - sizeof(struct sun4i_dma_vchan), GFP_KERNEL); - priv->pchans_used = devm_kcalloc(&pdev->dev, - BITS_TO_LONGS(priv->cfg->dma_nr_max_channels), - sizeof(unsigned long), GFP_KERNEL); + priv->pchans = devm_kzalloc_objs(&pdev->dev, struct sun4i_dma_pchan, + priv->cfg->dma_nr_max_channels); + priv->vchans = devm_kzalloc_objs(&pdev->dev, struct sun4i_dma_vchan, + SUN4I_DMA_NR_MAX_VCHANS); + priv->pchans_used = devm_kzalloc_objs(&pdev->dev, unsigned long, + BITS_TO_LONGS(priv->cfg->dma_nr_max_channels)); if (!priv->vchans || !priv->pchans || !priv->pchans_used) return -ENOMEM; diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c index cf06cd9bb385e6..3b849833e08f41 100644 --- a/drivers/dma/sun6i-dma.c +++ b/drivers/dma/sun6i-dma.c @@ -1392,7 +1392,7 @@ static int sun6i_dma_probe(struct platform_device *pdev) struct sun6i_dma_dev *sdc; int ret, i; - sdc = devm_kzalloc(&pdev->dev, sizeof(*sdc), GFP_KERNEL); + sdc = devm_kzalloc_obj(&pdev->dev, *sdc); if (!sdc) return -ENOMEM; @@ -1489,13 +1489,13 @@ static int sun6i_dma_probe(struct platform_device *pdev) if (!sdc->num_vchans) sdc->num_vchans = 2 * (sdc->max_request + 1); - sdc->pchans = devm_kcalloc(&pdev->dev, sdc->num_pchans, - sizeof(struct sun6i_pchan), GFP_KERNEL); + sdc->pchans = devm_kzalloc_objs(&pdev->dev, struct sun6i_pchan, + sdc->num_pchans); if (!sdc->pchans) return -ENOMEM; - sdc->vchans = devm_kcalloc(&pdev->dev, sdc->num_vchans, - sizeof(struct sun6i_vchan), GFP_KERNEL); + sdc->vchans = devm_kzalloc_objs(&pdev->dev, struct sun6i_vchan, + sdc->num_vchans); if (!sdc->vchans) return -ENOMEM; diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c index e76c58f213d84f..ec12b7288b43a1 100644 --- a/drivers/dma/tegra186-gpc-dma.c +++ b/drivers/dma/tegra186-gpc-dma.c @@ -1429,9 +1429,8 @@ static int tegra_dma_probe(struct platform_device *pdev) cdata = of_device_get_match_data(&pdev->dev); - tdma = devm_kzalloc(&pdev->dev, - struct_size(tdma, channels, cdata->nr_channels), - GFP_KERNEL); + tdma = devm_kzalloc_flex(&pdev->dev, *tdma, channels, + cdata->nr_channels); if (!tdma) return -ENOMEM; diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c index 21a381d022cfb8..607f8e0848ac9a 100644 --- a/drivers/dma/tegra210-adma.c +++ b/drivers/dma/tegra210-adma.c @@ -1044,9 +1044,8 @@ static int tegra_adma_probe(struct platform_device *pdev) "device match data not found\n"); } - tdma = devm_kzalloc(&pdev->dev, - struct_size(tdma, channels, cdata->nr_channels), - GFP_KERNEL); + tdma = devm_kzalloc_flex(&pdev->dev, *tdma, channels, + cdata->nr_channels); if (!tdma) return -ENOMEM; diff --git a/drivers/dma/ti/cppi41.c b/drivers/dma/ti/cppi41.c index 88756dccd62c63..f392978deea0d2 100644 --- a/drivers/dma/ti/cppi41.c +++ b/drivers/dma/ti/cppi41.c @@ -781,7 +781,7 @@ static int cppi41_add_chans(struct device *dev, struct cppi41_dd *cdd) */ n_chans *= 2; - chans = devm_kcalloc(dev, n_chans, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, n_chans); if (!chans) return -ENOMEM; @@ -1043,7 +1043,7 @@ static int cppi41_dma_probe(struct platform_device *pdev) if (!glue_info) return -EINVAL; - cdd = devm_kzalloc(&pdev->dev, sizeof(*cdd), GFP_KERNEL); + cdd = devm_kzalloc_obj(&pdev->dev, *cdd); if (!cdd) return -ENOMEM; diff --git a/drivers/dma/ti/dma-crossbar.c b/drivers/dma/ti/dma-crossbar.c index f6d75ee94e8d8a..b1e66792e7def1 100644 --- a/drivers/dma/ti/dma-crossbar.c +++ b/drivers/dma/ti/dma-crossbar.c @@ -144,7 +144,7 @@ static int ti_am335x_xbar_probe(struct platform_device *pdev) if (!node) return -ENODEV; - xbar = devm_kzalloc(&pdev->dev, sizeof(*xbar), GFP_KERNEL); + xbar = devm_kzalloc_obj(&pdev->dev, *xbar); if (!xbar) return -ENOMEM; @@ -340,7 +340,7 @@ static int ti_dra7_xbar_probe(struct platform_device *pdev) if (!node) return -ENODEV; - xbar = devm_kzalloc(&pdev->dev, sizeof(*xbar), GFP_KERNEL); + xbar = devm_kzalloc_obj(&pdev->dev, *xbar); if (!xbar) return -ENOMEM; @@ -366,9 +366,8 @@ static int ti_dra7_xbar_probe(struct platform_device *pdev) } of_node_put(dma_node); - xbar->dma_inuse = devm_kcalloc(&pdev->dev, - BITS_TO_LONGS(xbar->dma_requests), - sizeof(unsigned long), GFP_KERNEL); + xbar->dma_inuse = devm_kzalloc_objs(&pdev->dev, unsigned long, + BITS_TO_LONGS(xbar->dma_requests)); if (!xbar->dma_inuse) return -ENOMEM; diff --git a/drivers/dma/ti/edma.c b/drivers/dma/ti/edma.c index d97db5af355552..f3a98654d1265c 100644 --- a/drivers/dma/ti/edma.c +++ b/drivers/dma/ti/edma.c @@ -1962,7 +1962,7 @@ static void edma_dma_init(struct edma_cc *ecc, bool legacy_mode) INIT_LIST_HEAD(&s_ddev->channels); if (memcpy_channels) { - m_ddev = devm_kzalloc(ecc->dev, sizeof(*m_ddev), GFP_KERNEL); + m_ddev = devm_kzalloc_obj(ecc->dev, *m_ddev); if (!m_ddev) { dev_warn(ecc->dev, "memcpy is disabled due to OoM\n"); memcpy_channels = NULL; @@ -2064,8 +2064,8 @@ static int edma_setup_from_hw(struct device *dev, struct edma_soc_info *pdata, * priority. So Q0 is the highest priority queue and the last queue has * the lowest priority. */ - queue_priority_map = devm_kcalloc(dev, ecc->num_tc + 1, - sizeof(*queue_priority_map), GFP_KERNEL); + queue_priority_map = devm_kzalloc_objs(dev, *queue_priority_map, + ecc->num_tc + 1); if (!queue_priority_map) return -ENOMEM; @@ -2137,7 +2137,7 @@ static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev, struct property *prop; int sz, ret; - info = devm_kzalloc(dev, sizeof(struct edma_soc_info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct edma_soc_info); if (!info) return ERR_PTR(-ENOMEM); @@ -2159,8 +2159,7 @@ static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev, size_t nelm = sz / sizeof(s32); s32 *memcpy_ch; - memcpy_ch = devm_kcalloc(dev, nelm + 1, sizeof(s32), - GFP_KERNEL); + memcpy_ch = devm_kzalloc_objs(dev, s32, nelm + 1); if (!memcpy_ch) return ERR_PTR(-ENOMEM); @@ -2186,18 +2185,17 @@ static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev, if (!nelm) return info; - tmp = kcalloc(nelm, sizeof(*tmp), GFP_KERNEL); + tmp = kzalloc_objs(*tmp, nelm); if (!tmp) return ERR_PTR(-ENOMEM); - rsv_info = devm_kzalloc(dev, sizeof(*rsv_info), GFP_KERNEL); + rsv_info = devm_kzalloc_obj(dev, *rsv_info); if (!rsv_info) { kfree(tmp); return ERR_PTR(-ENOMEM); } - rsv_slots = devm_kcalloc(dev, nelm + 1, sizeof(*rsv_slots), - GFP_KERNEL); + rsv_slots = devm_kzalloc_objs(dev, *rsv_slots, nelm + 1); if (!rsv_slots) { kfree(tmp); return ERR_PTR(-ENOMEM); @@ -2318,7 +2316,7 @@ static int edma_probe(struct platform_device *pdev) if (ret) return ret; - ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL); + ecc = devm_kzalloc_obj(dev, *ecc); if (!ecc) return -ENOMEM; @@ -2358,15 +2356,14 @@ static int edma_probe(struct platform_device *pdev) goto err_disable_pm; /* Allocate memory based on the information we got from the IP */ - ecc->slave_chans = devm_kcalloc(dev, ecc->num_channels, - sizeof(*ecc->slave_chans), GFP_KERNEL); + ecc->slave_chans = devm_kzalloc_objs(dev, *ecc->slave_chans, + ecc->num_channels); - ecc->slot_inuse = devm_kcalloc(dev, BITS_TO_LONGS(ecc->num_slots), - sizeof(unsigned long), GFP_KERNEL); + ecc->slot_inuse = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ecc->num_slots)); - ecc->channels_mask = devm_kcalloc(dev, - BITS_TO_LONGS(ecc->num_channels), - sizeof(unsigned long), GFP_KERNEL); + ecc->channels_mask = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ecc->num_channels)); if (!ecc->slave_chans || !ecc->slot_inuse || !ecc->channels_mask) { ret = -ENOMEM; goto err_disable_pm; @@ -2457,8 +2454,8 @@ static int edma_probe(struct platform_device *pdev) unsigned int array_max; struct of_phandle_args tc_args; - ecc->tc_list = devm_kcalloc(dev, ecc->num_tc, - sizeof(*ecc->tc_list), GFP_KERNEL); + ecc->tc_list = devm_kzalloc_objs(dev, *ecc->tc_list, + ecc->num_tc); if (!ecc->tc_list) { ret = -ENOMEM; goto err_reg1; diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c index 70eaf7ee57e681..f10f61a40f9145 100644 --- a/drivers/dma/ti/k3-udma-glue.c +++ b/drivers/dma/ti/k3-udma-glue.c @@ -379,7 +379,7 @@ k3_udma_glue_request_tx_chn(struct device *dev, const char *name, struct k3_udma_glue_tx_channel *tx_chn; int ret; - tx_chn = devm_kzalloc(dev, sizeof(*tx_chn), GFP_KERNEL); + tx_chn = devm_kzalloc_obj(dev, *tx_chn); if (!tx_chn) return ERR_PTR(-ENOMEM); @@ -416,7 +416,7 @@ k3_udma_glue_request_tx_chn_for_thread_id(struct device *dev, struct k3_udma_glue_tx_channel *tx_chn; int ret; - tx_chn = devm_kzalloc(dev, sizeof(*tx_chn), GFP_KERNEL); + tx_chn = devm_kzalloc_obj(dev, *tx_chn); if (!tx_chn) return ERR_PTR(-ENOMEM); @@ -951,7 +951,7 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name, (cfg->def_flow_cfg || cfg->flow_id_use_rxchan_id)) return ERR_PTR(-EINVAL); - rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); + rx_chn = devm_kzalloc_obj(dev, *rx_chn); if (!rx_chn) return ERR_PTR(-ENOMEM); @@ -1033,8 +1033,7 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name, rx_chn->flow_num = cfg->flow_id_num; - rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num, - sizeof(*rx_chn->flows), GFP_KERNEL); + rx_chn->flows = devm_kzalloc_objs(dev, *rx_chn->flows, rx_chn->flow_num); if (!rx_chn->flows) { ret = -ENOMEM; goto err; @@ -1085,8 +1084,7 @@ k3_udma_glue_request_remote_rx_chn_common(struct k3_udma_glue_rx_channel *rx_chn rx_chn->common.psdata_size, rx_chn->common.swdata_size); - rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num, - sizeof(*rx_chn->flows), GFP_KERNEL); + rx_chn->flows = devm_kzalloc_objs(dev, *rx_chn->flows, rx_chn->flow_num); if (!rx_chn->flows) return -ENOMEM; @@ -1142,7 +1140,7 @@ k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name, * Linux can only request and manipulate by dedicated RX flows */ - rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); + rx_chn = devm_kzalloc_obj(dev, *rx_chn); if (!rx_chn) return ERR_PTR(-ENOMEM); @@ -1190,7 +1188,7 @@ k3_udma_glue_request_remote_rx_chn_for_thread_id(struct device *dev, * Linux can only request and manipulate by dedicated RX flows */ - rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); + rx_chn = devm_kzalloc_obj(dev, *rx_chn); if (!rx_chn) return ERR_PTR(-ENOMEM); diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c index 78a67cb9d6e000..75bd1977fb4236 100644 --- a/drivers/dma/ti/k3-udma.c +++ b/drivers/dma/ti/k3-udma.c @@ -4613,26 +4613,19 @@ static int udma_setup_resources(struct udma_dev *ud) ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; - ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); - ud->rflow_gp_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflow_gp_map_allocated = devm_kcalloc(dev, - BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), - GFP_KERNEL); + ud->tchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->tchan_cnt)); + ud->tchans = devm_kzalloc_objs(dev, *ud->tchans, ud->tchan_cnt); + ud->rchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rchan_cnt)); + ud->rchans = devm_kzalloc_objs(dev, *ud->rchans, ud->rchan_cnt); + ud->rflow_gp_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rflow_cnt)); + ud->rflow_gp_map_allocated = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rflow_cnt)); + ud->rflow_in_use = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rflow_cnt)); + ud->rflows = devm_kzalloc_objs(dev, *ud->rflows, ud->rflow_cnt); if (!ud->tchan_map || !ud->rchan_map || !ud->rflow_gp_map || !ud->rflow_gp_map_allocated || !ud->tchans || !ud->rchans || @@ -4787,24 +4780,19 @@ static int bcdma_setup_resources(struct udma_dev *ud) ud->tchan_tpl.levels = 1; } - ud->bchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), - GFP_KERNEL); - ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); + ud->bchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->bchan_cnt)); + ud->bchans = devm_kzalloc_objs(dev, *ud->bchans, ud->bchan_cnt); + ud->tchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->tchan_cnt)); + ud->tchans = devm_kzalloc_objs(dev, *ud->tchans, ud->tchan_cnt); + ud->rchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rchan_cnt)); + ud->rchans = devm_kzalloc_objs(dev, *ud->rchans, ud->rchan_cnt); /* BCDMA do not really have flows, but the driver expect it */ - ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows), - GFP_KERNEL); + ud->rflow_in_use = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rchan_cnt)); + ud->rflows = devm_kzalloc_objs(dev, *ud->rflows, ud->rchan_cnt); if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map || !ud->rflow_in_use || !ud->bchans || !ud->tchans || !ud->rchans || @@ -4999,21 +4987,17 @@ static int pktdma_setup_resources(struct udma_dev *ud) ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; - ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); - ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), - GFP_KERNEL); - ud->tflow_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tflow_cnt), - sizeof(unsigned long), GFP_KERNEL); + ud->tchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->tchan_cnt)); + ud->tchans = devm_kzalloc_objs(dev, *ud->tchans, ud->tchan_cnt); + ud->rchan_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rchan_cnt)); + ud->rchans = devm_kzalloc_objs(dev, *ud->rchans, ud->rchan_cnt); + ud->rflow_in_use = devm_kzalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->rflow_cnt)); + ud->rflows = devm_kzalloc_objs(dev, *ud->rflows, ud->rflow_cnt); + ud->tflow_map = devm_kmalloc_objs(dev, unsigned long, + BITS_TO_LONGS(ud->tflow_cnt)); if (!ud->tchan_map || !ud->rchan_map || !ud->tflow_map || !ud->tchans || !ud->rchans || !ud->rflows || !ud->rflow_in_use) @@ -5158,8 +5142,7 @@ static int setup_resources(struct udma_dev *ud) if (!ch_count) return -ENODEV; - ud->channels = devm_kcalloc(dev, ch_count, sizeof(*ud->channels), - GFP_KERNEL); + ud->channels = devm_kzalloc_objs(dev, *ud->channels, ch_count); if (!ud->channels) return -ENOMEM; @@ -5418,7 +5401,7 @@ static int udma_probe(struct platform_device *pdev) if (ret) dev_err(dev, "failed to set dma mask stuff\n"); - ud = devm_kzalloc(dev, sizeof(*ud), GFP_KERNEL); + ud = devm_kzalloc_obj(dev, *ud); if (!ud) return -ENOMEM; diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c index 55ece7fd0d99ae..93b6a468208543 100644 --- a/drivers/dma/ti/omap-dma.c +++ b/drivers/dma/ti/omap-dma.c @@ -1660,7 +1660,7 @@ static int omap_dma_probe(struct platform_device *pdev) int rc, i, irq; u32 val; - od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); + od = devm_kzalloc_obj(&pdev->dev, *od); if (!od) return -ENOMEM; @@ -1754,9 +1754,7 @@ static int omap_dma_probe(struct platform_device *pdev) if (od->plat->dma_attr->dev_caps & HS_CHANNELS_RESERVED) bitmap_set(od->lch_bitmap, 0, 2); - od->lch_map = devm_kcalloc(&pdev->dev, od->lch_count, - sizeof(*od->lch_map), - GFP_KERNEL); + od->lch_map = devm_kzalloc_objs(&pdev->dev, *od->lch_map, od->lch_count); if (!od->lch_map) return -ENOMEM; diff --git a/drivers/dma/txx9dmac.c b/drivers/dma/txx9dmac.c index ecfaa6a7651672..04de7f7ef31d86 100644 --- a/drivers/dma/txx9dmac.c +++ b/drivers/dma/txx9dmac.c @@ -1083,7 +1083,7 @@ static int __init txx9dmac_chan_probe(struct platform_device *pdev) int ch = pdev->id % TXX9_DMA_MAX_NR_CHANNELS; int irq; - dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL); + dc = devm_kzalloc_obj(&pdev->dev, *dc); if (!dc) return -ENOMEM; @@ -1171,7 +1171,7 @@ static int __init txx9dmac_probe(struct platform_device *pdev) if (IS_ERR(regs)) return PTR_ERR(regs); - ddev = devm_kzalloc(&pdev->dev, sizeof(*ddev), GFP_KERNEL); + ddev = devm_kzalloc_obj(&pdev->dev, *ddev); if (!ddev) return -ENOMEM; diff --git a/drivers/dma/uniphier-mdmac.c b/drivers/dma/uniphier-mdmac.c index a8aa904b88bec5..a5e38879dd54dc 100644 --- a/drivers/dma/uniphier-mdmac.c +++ b/drivers/dma/uniphier-mdmac.c @@ -392,8 +392,7 @@ static int uniphier_mdmac_probe(struct platform_device *pdev) if (ret) return ret; - mdev = devm_kzalloc(dev, struct_size(mdev, channels, nr_chans), - GFP_KERNEL); + mdev = devm_kzalloc_flex(dev, *mdev, channels, nr_chans); if (!mdev) return -ENOMEM; diff --git a/drivers/dma/uniphier-xdmac.c b/drivers/dma/uniphier-xdmac.c index 120c0d4f12ddaa..ed51952b6f86cd 100644 --- a/drivers/dma/uniphier-xdmac.c +++ b/drivers/dma/uniphier-xdmac.c @@ -492,8 +492,7 @@ static int uniphier_xdmac_probe(struct platform_device *pdev) if (nr_chans > XDMAC_MAX_CHANS) nr_chans = XDMAC_MAX_CHANS; - xdev = devm_kzalloc(dev, struct_size(xdev, channels, nr_chans), - GFP_KERNEL); + xdev = devm_kzalloc_flex(dev, *xdev, channels, nr_chans); if (!xdev) return -ENOMEM; diff --git a/drivers/dma/xgene-dma.c b/drivers/dma/xgene-dma.c index 8d1c58ca0d48fa..3714099aef07a4 100644 --- a/drivers/dma/xgene-dma.c +++ b/drivers/dma/xgene-dma.c @@ -1701,7 +1701,7 @@ static int xgene_dma_probe(struct platform_device *pdev) struct xgene_dma *pdma; int ret, i; - pdma = devm_kzalloc(&pdev->dev, sizeof(*pdma), GFP_KERNEL); + pdma = devm_kzalloc_obj(&pdev->dev, *pdma); if (!pdma) return -ENOMEM; diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c index 8d4a5d14e8dba9..9d827c9a126740 100644 --- a/drivers/dma/xilinx/xdma.c +++ b/drivers/dma/xilinx/xdma.c @@ -444,8 +444,7 @@ static int xdma_alloc_channels(struct xdma_device *xdev, return -EINVAL; } - *chans = devm_kcalloc(&xdev->pdev->dev, *chan_num, sizeof(**chans), - GFP_KERNEL); + *chans = devm_kzalloc_objs(&xdev->pdev->dev, **chans, *chan_num); if (!*chans) return -ENOMEM; @@ -1206,7 +1205,7 @@ static int xdma_probe(struct platform_device *pdev) return -EINVAL; } - xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(&pdev->dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index 0336941d409586..b89f2c3c1579ca 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -3033,7 +3033,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, int err; /* Allocate and initialize the channel structure */ - chan = devm_kzalloc(xdev->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(xdev->dev, *chan); if (!chan) return -ENOMEM; @@ -3285,7 +3285,7 @@ static int xilinx_dma_probe(struct platform_device *pdev) int i, err; /* Allocate and initialize the DMA engine structure */ - xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(&pdev->dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c index d9a3542c4531c0..687fc8ef3d8e1d 100644 --- a/drivers/dma/xilinx/xilinx_dpdma.c +++ b/drivers/dma/xilinx/xilinx_dpdma.c @@ -1656,7 +1656,7 @@ static int xilinx_dpdma_chan_init(struct xilinx_dpdma_device *xdev, { struct xilinx_dpdma_chan *chan; - chan = devm_kzalloc(xdev->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(xdev->dev, *chan); if (!chan) return -ENOMEM; @@ -1730,7 +1730,7 @@ static int xilinx_dpdma_probe(struct platform_device *pdev) unsigned int i; int ret; - xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(&pdev->dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c index 3b7dfa53f9725b..bc85dca4741217 100644 --- a/drivers/dma/xilinx/zynqmp_dma.c +++ b/drivers/dma/xilinx/zynqmp_dma.c @@ -919,7 +919,7 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev, const struct zynqmp_dma_config *match_data; int err, ret; - chan = devm_kzalloc(zdev->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(zdev->dev, *chan); if (!chan) return -ENOMEM; chan->dev = zdev->dev; @@ -1089,7 +1089,7 @@ static int zynqmp_dma_probe(struct platform_device *pdev) struct dma_device *p; int ret; - zdev = devm_kzalloc(&pdev->dev, sizeof(*zdev), GFP_KERNEL); + zdev = devm_kzalloc_obj(&pdev->dev, *zdev); if (!zdev) return -ENOMEM; diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 8389983f425695..277692d12d3d1e 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -1081,7 +1081,8 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin, mutex_lock(&dpll_lock); ret = xa_insert(&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin, GFP_KERNEL); - __dpll_pin_change_ntf(pin); + if (!ret) + __dpll_pin_change_ntf(pin); mutex_unlock(&dpll_lock); return ret; diff --git a/drivers/dpll/zl3073x/prop.c b/drivers/dpll/zl3073x/prop.c index 4e006ed5950ad4..37e633fa5a7284 100644 --- a/drivers/dpll/zl3073x/prop.c +++ b/drivers/dpll/zl3073x/prop.c @@ -297,7 +297,7 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, * DPLL core pin properties requires list of frequency ranges. * So read the frequency list into temporary array. */ - freqs = kcalloc(num_freqs, sizeof(*freqs), GFP_KERNEL); + freqs = kzalloc_objs(*freqs, num_freqs); if (!freqs) { rc = -ENOMEM; goto err_alloc_freqs; diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c index bb95dab847b3c7..12175d0cbc43cd 100644 --- a/drivers/edac/altera_edac.c +++ b/drivers/edac/altera_edac.c @@ -2113,7 +2113,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev) struct altr_arria10_edac *edac; struct device_node *child; - edac = devm_kzalloc(&pdev->dev, sizeof(*edac), GFP_KERNEL); + edac = devm_kzalloc_obj(&pdev->dev, *edac); if (!edac) return -ENOMEM; diff --git a/drivers/edac/ecs.c b/drivers/edac/ecs.c index 51c451c7f0f0b2..332872d4214cd7 100644 --- a/drivers/edac/ecs.c +++ b/drivers/edac/ecs.c @@ -149,14 +149,13 @@ static int ecs_create_desc(struct device *ecs_dev, const struct attribute_group struct edac_ecs_context *ecs_ctx; u32 fru; - ecs_ctx = devm_kzalloc(ecs_dev, sizeof(*ecs_ctx), GFP_KERNEL); + ecs_ctx = devm_kzalloc_obj(ecs_dev, *ecs_ctx); if (!ecs_ctx) return -ENOMEM; ecs_ctx->num_media_frus = num_media_frus; - ecs_ctx->fru_ctxs = devm_kcalloc(ecs_dev, num_media_frus, - sizeof(*ecs_ctx->fru_ctxs), - GFP_KERNEL); + ecs_ctx->fru_ctxs = devm_kzalloc_objs(ecs_dev, *ecs_ctx->fru_ctxs, + num_media_frus); if (!ecs_ctx->fru_ctxs) return -ENOMEM; diff --git a/drivers/edac/mem_repair.c b/drivers/edac/mem_repair.c index 108d69209146c2..9812ce098cf682 100644 --- a/drivers/edac/mem_repair.c +++ b/drivers/edac/mem_repair.c @@ -314,7 +314,7 @@ static int mem_repair_create_desc(struct device *dev, struct edac_mem_repair_context *ctx; struct attribute_group *group; int i; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/edac/octeon_edac-pc.c b/drivers/edac/octeon_edac-pc.c index aa1219db0b1726..49952b7cb7db6c 100644 --- a/drivers/edac/octeon_edac-pc.c +++ b/drivers/edac/octeon_edac-pc.c @@ -83,8 +83,7 @@ static int co_cache_error_event(struct notifier_block *this, static int co_cache_error_probe(struct platform_device *pdev) { - struct co_cache_error *p = devm_kzalloc(&pdev->dev, sizeof(*p), - GFP_KERNEL); + struct co_cache_error *p = devm_kzalloc_obj(&pdev->dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/edac/scrub.c b/drivers/edac/scrub.c index f9d02af2fc3a20..e725e2bf0a8d4c 100644 --- a/drivers/edac/scrub.c +++ b/drivers/edac/scrub.c @@ -169,7 +169,7 @@ static int scrub_create_desc(struct device *scrub_dev, [SCRUB_CUR_CYCLE_DURATION] = EDAC_SCRUB_ATTR_RW(current_cycle_duration, instance) }; - scrub_ctx = devm_kzalloc(scrub_dev, sizeof(*scrub_ctx), GFP_KERNEL); + scrub_ctx = devm_kzalloc_obj(scrub_dev, *scrub_ctx); if (!scrub_ctx) return -ENOMEM; diff --git a/drivers/edac/sifive_edac.c b/drivers/edac/sifive_edac.c index a2b193dc660431..efbf5676c1cac2 100644 --- a/drivers/edac/sifive_edac.c +++ b/drivers/edac/sifive_edac.c @@ -44,7 +44,7 @@ static int ecc_register(struct platform_device *pdev) { struct sifive_edac_priv *p; - p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/edac/skx_common.c b/drivers/edac/skx_common.c index bfd0cd1689edaf..f1f9a7902e3464 100644 --- a/drivers/edac/skx_common.c +++ b/drivers/edac/skx_common.c @@ -363,8 +363,7 @@ int skx_adxl_get(void) while (*names++) adxl_component_count++; - adxl_values = kcalloc(adxl_component_count, sizeof(*adxl_values), - GFP_KERNEL); + adxl_values = kzalloc_objs(*adxl_values, adxl_component_count); if (!adxl_values) { adxl_component_count = 0; return -ENOMEM; diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c index eae9fea60db156..d59ba3904cda65 100644 --- a/drivers/edac/versalnet_edac.c +++ b/drivers/edac/versalnet_edac.c @@ -903,7 +903,7 @@ static int mc_probe(struct platform_device *pdev) goto err_rproc_boot; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { rc = -ENOMEM; goto err_alloc; diff --git a/drivers/edac/xgene_edac.c b/drivers/edac/xgene_edac.c index 62b8166dc287de..1956affcdc59db 100644 --- a/drivers/edac/xgene_edac.c +++ b/drivers/edac/xgene_edac.c @@ -1847,7 +1847,7 @@ static int xgene_edac_probe(struct platform_device *pdev) struct resource *res; int rc; - edac = devm_kzalloc(&pdev->dev, sizeof(*edac), GFP_KERNEL); + edac = devm_kzalloc_obj(&pdev->dev, *edac); if (!edac) return -ENOMEM; diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index e735f43dcdeb00..9557b470c07d59 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c @@ -100,7 +100,7 @@ static int adc_jack_probe(struct platform_device *pdev) struct adc_jack_pdata *pdata = dev_get_platdata(&pdev->dev); int i, err = 0; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c index 19856dddade62c..2a42647308b03e 100644 --- a/drivers/extcon/extcon-axp288.c +++ b/drivers/extcon/extcon-axp288.c @@ -368,7 +368,7 @@ static int axp288_extcon_probe(struct platform_device *pdev) struct acpi_device *adev; int ret, i, pirq; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-fsa9480.c b/drivers/extcon/extcon-fsa9480.c index a031eb0914a0b6..89ffd9efb0ccaa 100644 --- a/drivers/extcon/extcon-fsa9480.c +++ b/drivers/extcon/extcon-fsa9480.c @@ -267,7 +267,7 @@ static int fsa9480_probe(struct i2c_client *client) return -EINVAL; } - info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, *info); if (!info) return -ENOMEM; info->dev = &client->dev; diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index 4105df74f2b06f..4d919b68455b34 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -70,7 +70,7 @@ static int gpio_extcon_probe(struct platform_device *pdev) int irq; int ret; - data = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct gpio_extcon_data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 99a9dfc62e2b6d..9281c5addf0aee 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -500,7 +500,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) if (irq < 0) return irq; - ext = devm_kzalloc(&pdev->dev, sizeof(*ext), GFP_KERNEL); + ext = devm_kzalloc_obj(&pdev->dev, *ext); if (!ext) return -ENOMEM; diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c index 7d16d5b7d58f7b..387aa2d87fc83e 100644 --- a/drivers/extcon/extcon-intel-int3496.c +++ b/drivers/extcon/extcon-intel-int3496.c @@ -125,7 +125,7 @@ static int int3496_probe(struct platform_device *pdev) } } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-intel-mrfld.c b/drivers/extcon/extcon-intel-mrfld.c index 7246d704fa3d8b..61bf7a585783b2 100644 --- a/drivers/extcon/extcon-intel-mrfld.c +++ b/drivers/extcon/extcon-intel-mrfld.c @@ -204,7 +204,7 @@ static int mrfld_extcon_probe(struct platform_device *pdev) if (irq < 0) return irq; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-lc824206xa.c b/drivers/extcon/extcon-lc824206xa.c index 56938748aea83b..506bba82697f05 100644 --- a/drivers/extcon/extcon-lc824206xa.c +++ b/drivers/extcon/extcon-lc824206xa.c @@ -419,7 +419,7 @@ static int lc824206xa_probe(struct i2c_client *client) struct lc824206xa_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-max14526.c b/drivers/extcon/extcon-max14526.c index bf899782747555..a491328937d62e 100644 --- a/drivers/extcon/extcon-max14526.c +++ b/drivers/extcon/extcon-max14526.c @@ -204,7 +204,7 @@ static int max14526_probe(struct i2c_client *client) struct max14526_data *priv; int ret, dev_id, rev, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index 5476f48ed74b9a..7eefc13e9f594c 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -664,7 +664,7 @@ static int max14577_muic_probe(struct platform_device *pdev) int i; u8 id; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-max3355.c b/drivers/extcon/extcon-max3355.c index d687d178aff11a..5bcb6861b36c8e 100644 --- a/drivers/extcon/extcon-max3355.c +++ b/drivers/extcon/extcon-max3355.c @@ -56,8 +56,7 @@ static int max3355_probe(struct platform_device *pdev) struct gpio_desc *gpiod; int irq, err; - data = devm_kzalloc(&pdev->dev, sizeof(struct max3355_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct max3355_data); if (!data) return -ENOMEM; diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 2c567e0b7b7f04..d6ae6f596dbd31 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -1079,8 +1079,7 @@ static int max77693_muic_probe(struct platform_device *pdev) int i; unsigned int id; - info = devm_kzalloc(&pdev->dev, sizeof(struct max77693_muic_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max77693_muic_info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index 2ae9f7f1a67fc2..c16606b2385581 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -815,7 +815,7 @@ static int max77843_muic_probe(struct platform_device *pdev) bool attached; int i, ret; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 9cddf08e06966b..4e2a07e6c8a665 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -639,8 +639,7 @@ static int max8997_muic_probe(struct platform_device *pdev) bool attached; int ret, i; - info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8997_muic_info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index d339b86804455b..9a75c6cee2dfda 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -184,7 +184,7 @@ static int palmas_usb_probe(struct platform_device *pdev) return -EINVAL; } - palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL); + palmas_usb = devm_kzalloc_obj(&pdev->dev, *palmas_usb); if (!palmas_usb) return -ENOMEM; diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index eca1b140aeb0fe..0b96b58b421245 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -263,7 +263,7 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) if (!np) return -EINVAL; - info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&i2c->dev, *info); if (!info) return -ENOMEM; i2c_set_clientdata(i2c, info); diff --git a/drivers/extcon/extcon-qcom-spmi-misc.c b/drivers/extcon/extcon-qcom-spmi-misc.c index 3c522c9c92f3bf..a8200426f8ea86 100644 --- a/drivers/extcon/extcon-qcom-spmi-misc.c +++ b/drivers/extcon/extcon-qcom-spmi-misc.c @@ -89,7 +89,7 @@ static int qcom_usb_extcon_probe(struct platform_device *pdev) struct qcom_usb_extcon_info *info; int ret; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c index 19bb49f13fb08c..234c12311743e9 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -557,7 +557,7 @@ static int rt8973a_muic_i2c_probe(struct i2c_client *i2c) if (!np) return -EINVAL; - info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&i2c->dev, *info); if (!info) return -ENOMEM; i2c_set_clientdata(i2c, info); diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c index da0b3fd3676ebd..d85a51cb4abc48 100644 --- a/drivers/extcon/extcon-rtk-type-c.c +++ b/drivers/extcon/extcon-rtk-type-c.c @@ -1321,7 +1321,7 @@ static int extcon_rtk_type_c_probe(struct platform_device *pdev) const struct type_c_cfg *type_c_cfg; int ret = 0; - type_c = devm_kzalloc(dev, sizeof(*type_c), GFP_KERNEL); + type_c = devm_kzalloc_obj(dev, *type_c); if (!type_c) return -ENOMEM; @@ -1368,8 +1368,7 @@ static int extcon_rtk_type_c_probe(struct platform_device *pdev) goto err; } - type_c->type_c_cfg = devm_kzalloc(dev, sizeof(*type_c->type_c_cfg), - GFP_KERNEL); + type_c->type_c_cfg = devm_kzalloc_obj(dev, *type_c->type_c_cfg); if (!type_c->type_c_cfg) return -ENOMEM; diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c index c8c4b9ef72aa1f..9ab2553f1f5577 100644 --- a/drivers/extcon/extcon-sm5502.c +++ b/drivers/extcon/extcon-sm5502.c @@ -681,7 +681,7 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c) if (!np) return -EINVAL; - info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&i2c->dev, *info); if (!info) return -ENOMEM; i2c_set_clientdata(i2c, info); diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index e35fd1f699a6c2..680e925cc1c6bb 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -103,7 +103,7 @@ static int usb_extcon_probe(struct platform_device *pdev) if (!np) return -EINVAL; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c index a2ef710b0d6d8c..9dcafc77985e9d 100644 --- a/drivers/extcon/extcon-usbc-cros-ec.c +++ b/drivers/extcon/extcon-usbc-cros-ec.c @@ -388,7 +388,7 @@ static int extcon_cros_ec_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int numports, ret; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/extcon/extcon-usbc-tusb320.c b/drivers/extcon/extcon-usbc-tusb320.c index 920b0342185029..a824df652464c1 100644 --- a/drivers/extcon/extcon-usbc-tusb320.c +++ b/drivers/extcon/extcon-usbc-tusb320.c @@ -517,7 +517,7 @@ static int tusb320_probe(struct i2c_client *client) u32 irq_trigger_type = IRQF_TRIGGER_FALLING; struct irq_data *irq_d; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index c06e8d87239c4d..2dd9b6bdca2bbb 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1593,12 +1593,13 @@ static void handle_at_local_packets(struct at_local *local, struct fw_ohci *ohci void (*handle_at_local_packet)(struct fw_ohci *, struct fw_packet *)) { struct fw_packet *packet; + unsigned long flags; - spin_lock(&local->lock); + spin_lock_irqsave(&local->lock, flags); while ((packet = list_first_entry_or_null(&local->list, typeof(*packet), link_for_local))) { list_del_init(&packet->link_for_local); - spin_unlock(&local->lock); + spin_unlock_irqrestore(&local->lock, flags); if (unlikely(packet->ack != 0)) { // This case is active when the call of at_context_queue_packet() returns @@ -1608,10 +1609,10 @@ static void handle_at_local_packets(struct at_local *local, struct fw_ohci *ohci handle_at_local_packet(ohci, packet); } - spin_lock(&local->lock); + spin_lock_irqsave(&local->lock, flags); } - spin_unlock(&local->lock); + spin_unlock_irqrestore(&local->lock, flags); } static void at_request_local_work(struct work_struct *work) @@ -3788,7 +3789,8 @@ static int pci_probe(struct pci_dev *dev, reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); ohci->ir_context_mask = ohci->ir_context_support; ohci->n_ir = hweight32(ohci->ir_context_mask); - ohci->ir_context_list = devm_kcalloc(&dev->dev, ohci->n_ir, sizeof(struct iso_context), GFP_KERNEL); + ohci->ir_context_list = devm_kzalloc_objs(&dev->dev, struct iso_context, + ohci->n_ir); if (!ohci->ir_context_list) return -ENOMEM; @@ -3802,7 +3804,8 @@ static int pci_probe(struct pci_dev *dev, reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); ohci->it_context_mask = ohci->it_context_support; ohci->n_it = hweight32(ohci->it_context_mask); - ohci->it_context_list = devm_kcalloc(&dev->dev, ohci->n_it, sizeof(struct iso_context), GFP_KERNEL); + ohci->it_context_list = devm_kzalloc_objs(&dev->dev, struct iso_context, + ohci->n_it); if (!ohci->it_context_list) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c index 0278705d809e8f..6b5d50b35a48f2 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -271,9 +271,9 @@ static int iter_clk_possible_parents_update_state(struct scmi_iterator_state *st if (!st->max_resources) { int num_parents = st->num_returned + st->num_remaining; - p->clkd->info.parents = devm_kcalloc(p->dev, num_parents, - sizeof(*p->clkd->info.parents), - GFP_KERNEL); + p->clkd->info.parents = devm_kzalloc_objs(p->dev, + *p->clkd->info.parents, + num_parents); if (!p->clkd->info.parents) return -ENOMEM; @@ -484,8 +484,8 @@ iter_clk_describe_update_state(struct scmi_iterator_state *st, if (!st->max_resources) { unsigned int tot_rates = st->num_returned + st->num_remaining; - p->clkd->r.rates = devm_kcalloc(p->dev, tot_rates, - sizeof(*p->clkd->r.rates), GFP_KERNEL); + p->clkd->r.rates = devm_kzalloc_objs(p->dev, *p->clkd->r.rates, + tot_rates); if (!p->clkd->r.rates) return -ENOMEM; @@ -1237,7 +1237,7 @@ static int scmi_clock_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Clock Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - cinfo = devm_kzalloc(ph->dev, sizeof(*cinfo), GFP_KERNEL); + cinfo = devm_kzalloc_obj(ph->dev, *cinfo); if (!cinfo) return -ENOMEM; @@ -1245,8 +1245,8 @@ static int scmi_clock_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - cinfo->clkds = devm_kcalloc(ph->dev, cinfo->num_clocks, - sizeof(*cinfo->clkds), GFP_KERNEL); + cinfo->clkds = devm_kzalloc_objs(ph->dev, *cinfo->clkds, + cinfo->num_clocks); if (!cinfo->clkds) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 1e6f69b1432159..05092301db29af 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -2032,7 +2032,7 @@ scmi_common_fastchannel_init(const struct scmi_protocol_handle *ph, *p_addr = addr; if (p_db && SUPPORTS_DOORBELL(flags)) { - db = devm_kzalloc(ph->dev, sizeof(*db), GFP_KERNEL); + db = devm_kzalloc_obj(ph->dev, *db); if (!db) { ret = -ENOMEM; goto err_db; @@ -2275,7 +2275,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info, goto out; } - pi = devm_kzalloc(handle->dev, sizeof(*pi), GFP_KERNEL); + pi = devm_kzalloc_obj(handle->dev, *pi); if (!pi) goto clean; @@ -2718,7 +2718,7 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, */ INIT_HLIST_HEAD(&info->free_xfers); for (i = 0; i < info->max_msg; i++) { - xfer = devm_kzalloc(dev, sizeof(*xfer), GFP_KERNEL); + xfer = devm_kzalloc_obj(dev, *xfer); if (!xfer) return -ENOMEM; @@ -2803,7 +2803,7 @@ static int scmi_chan_setup(struct scmi_info *info, struct fwnode_handle *fwnode, goto idr_alloc; } - cinfo = devm_kzalloc(info->dev, sizeof(*cinfo), GFP_KERNEL); + cinfo = devm_kzalloc_obj(info->dev, *cinfo); if (!cinfo) return -ENOMEM; @@ -3121,7 +3121,7 @@ static struct scmi_debug_info *scmi_debugfs_common_setup(struct scmi_info *info) struct scmi_debug_info *dbg; const char *c_ptr = NULL; - dbg = devm_kzalloc(info->dev, sizeof(*dbg), GFP_KERNEL); + dbg = devm_kzalloc_obj(info->dev, *dbg); if (!dbg) return NULL; @@ -3339,7 +3339,7 @@ static int scmi_probe(struct platform_device *pdev) goto out_err; } - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c index fb60fb07c0ed19..bc046f2f83a6f1 100644 --- a/drivers/firmware/arm_scmi/notify.c +++ b/drivers/firmware/arm_scmi/notify.c @@ -706,9 +706,8 @@ scmi_allocate_registered_events_desc(struct scmi_notify_instance *ni, if (WARN_ON(ni->registered_protocols[proto_id])) return ERR_PTR(-EINVAL); - pd = devm_kzalloc(ni->handle->dev, - struct_size(pd, registered_events, num_events), - GFP_KERNEL); + pd = devm_kzalloc_flex(ni->handle->dev, *pd, registered_events, + num_events); if (!pd) return ERR_PTR(-ENOMEM); @@ -794,9 +793,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, int id; struct scmi_registered_event *r_evt; - r_evt = devm_kzalloc(ni->handle->dev, - struct_size(r_evt, sources, num_sources), - GFP_KERNEL); + r_evt = devm_kzalloc_flex(ni->handle->dev, *r_evt, sources, + num_sources); if (!r_evt) return -ENOMEM; @@ -1662,7 +1660,7 @@ int scmi_notification_init(struct scmi_handle *handle) if (!gid) return -ENOMEM; - ni = devm_kzalloc(handle->dev, sizeof(*ni), GFP_KERNEL); + ni = devm_kzalloc_obj(handle->dev, *ni); if (!ni) goto err; diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index 4583d02bee1c56..0116ffb2b27905 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -830,7 +830,7 @@ static void scmi_perf_domain_init_fc(const struct scmi_protocol_handle *ph, { struct scmi_fc_info *fc; - fc = devm_kcalloc(ph->dev, PERF_FC_MAX, sizeof(*fc), GFP_KERNEL); + fc = devm_kzalloc_objs(ph->dev, *fc, PERF_FC_MAX); if (!fc) return; @@ -1274,7 +1274,7 @@ static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Performance Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; @@ -1282,8 +1282,8 @@ static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->dom_info), GFP_KERNEL); + pinfo->dom_info = devm_kzalloc_objs(ph->dev, *pinfo->dom_info, + pinfo->num_domains); if (!pinfo->dom_info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/pinctrl.c b/drivers/firmware/arm_scmi/pinctrl.c index 42cb1aef1fe1e8..18761ffbf89340 100644 --- a/drivers/firmware/arm_scmi/pinctrl.c +++ b/drivers/firmware/arm_scmi/pinctrl.c @@ -620,9 +620,7 @@ static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph, return -ENODATA; } - group->group_pins = kmalloc_array(group->nr_pins, - sizeof(*group->group_pins), - GFP_KERNEL); + group->group_pins = kmalloc_objs(*group->group_pins, group->nr_pins); if (!group->group_pins) return -ENOMEM; @@ -699,8 +697,7 @@ static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph, return -ENODATA; } - func->groups = kmalloc_array(func->nr_groups, sizeof(*func->groups), - GFP_KERNEL); + func->groups = kmalloc_objs(*func->groups, func->nr_groups); if (!func->groups) return -ENOMEM; @@ -837,7 +834,7 @@ static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Pinctrl Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; @@ -845,18 +842,17 @@ static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - pinfo->pins = devm_kcalloc(ph->dev, pinfo->nr_pins, - sizeof(*pinfo->pins), GFP_KERNEL); + pinfo->pins = devm_kzalloc_objs(ph->dev, *pinfo->pins, pinfo->nr_pins); if (!pinfo->pins) return -ENOMEM; - pinfo->groups = devm_kcalloc(ph->dev, pinfo->nr_groups, - sizeof(*pinfo->groups), GFP_KERNEL); + pinfo->groups = devm_kzalloc_objs(ph->dev, *pinfo->groups, + pinfo->nr_groups); if (!pinfo->groups) return -ENOMEM; - pinfo->functions = devm_kcalloc(ph->dev, pinfo->nr_functions, - sizeof(*pinfo->functions), GFP_KERNEL); + pinfo->functions = devm_kzalloc_objs(ph->dev, *pinfo->functions, + pinfo->nr_functions); if (!pinfo->functions) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c index 28ef63a4ecc2e1..62294927112ba2 100644 --- a/drivers/firmware/arm_scmi/power.c +++ b/drivers/firmware/arm_scmi/power.c @@ -331,7 +331,7 @@ static int scmi_power_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Power Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; @@ -339,8 +339,8 @@ static int scmi_power_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->dom_info), GFP_KERNEL); + pinfo->dom_info = devm_kzalloc_objs(ph->dev, *pinfo->dom_info, + pinfo->num_domains); if (!pinfo->dom_info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c index 27e3c805e92720..e6dd18c6a15475 100644 --- a/drivers/firmware/arm_scmi/powercap.c +++ b/drivers/firmware/arm_scmi/powercap.c @@ -721,7 +721,7 @@ static void scmi_powercap_domain_init_fc(const struct scmi_protocol_handle *ph, { struct scmi_fc_info *fc; - fc = devm_kcalloc(ph->dev, POWERCAP_FC_MAX, sizeof(*fc), GFP_KERNEL); + fc = devm_kzalloc_objs(ph->dev, *fc, POWERCAP_FC_MAX); if (!fc) return; @@ -975,7 +975,7 @@ scmi_powercap_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Powercap Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; @@ -983,14 +983,13 @@ scmi_powercap_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - pinfo->powercaps = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->powercaps), - GFP_KERNEL); + pinfo->powercaps = devm_kzalloc_objs(ph->dev, *pinfo->powercaps, + pinfo->num_domains); if (!pinfo->powercaps) return -ENOMEM; - pinfo->states = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->states), GFP_KERNEL); + pinfo->states = devm_kzalloc_objs(ph->dev, *pinfo->states, + pinfo->num_domains); if (!pinfo->states) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/raw_mode.c b/drivers/firmware/arm_scmi/raw_mode.c index f01bf2f6ce1d44..7e42dd6cc2af99 100644 --- a/drivers/firmware/arm_scmi/raw_mode.c +++ b/drivers/firmware/arm_scmi/raw_mode.c @@ -1098,11 +1098,11 @@ scmi_raw_queue_init(struct scmi_raw_mode_info *raw) struct device *dev = raw->handle->dev; struct scmi_raw_queue *q; - q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL); + q = devm_kzalloc_obj(dev, *q); if (!q) return ERR_PTR(-ENOMEM); - rb = devm_kcalloc(dev, raw->tx_max_msg, sizeof(*rb), GFP_KERNEL); + rb = devm_kzalloc_objs(dev, *rb, raw->tx_max_msg); if (!rb) return ERR_PTR(-ENOMEM); @@ -1129,7 +1129,7 @@ static int scmi_xfer_raw_worker_init(struct scmi_raw_mode_info *raw) struct scmi_xfer_raw_waiter *rw; struct device *dev = raw->handle->dev; - rw = devm_kcalloc(dev, raw->tx_max_msg, sizeof(*rw), GFP_KERNEL); + rw = devm_kzalloc_objs(dev, *rw, raw->tx_max_msg); if (!rw) return -ENOMEM; @@ -1241,7 +1241,7 @@ void *scmi_raw_mode_init(const struct scmi_handle *handle, return ERR_PTR(-EINVAL); dev = handle->dev; - raw = devm_kzalloc(dev, sizeof(*raw), GFP_KERNEL); + raw = devm_kzalloc_obj(dev, *raw); if (!raw) return ERR_PTR(-ENOMEM); diff --git a/drivers/firmware/arm_scmi/reset.c b/drivers/firmware/arm_scmi/reset.c index 2cdddc28ba47a2..7d92d98b7999a8 100644 --- a/drivers/firmware/arm_scmi/reset.c +++ b/drivers/firmware/arm_scmi/reset.c @@ -345,7 +345,7 @@ static int scmi_reset_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Reset Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; @@ -353,8 +353,8 @@ static int scmi_reset_protocol_init(const struct scmi_protocol_handle *ph) if (ret) return ret; - pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->dom_info), GFP_KERNEL); + pinfo->dom_info = devm_kzalloc_objs(ph->dev, *pinfo->dom_info, + pinfo->num_domains); if (!pinfo->dom_info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/scmi_power_control.c b/drivers/firmware/arm_scmi/scmi_power_control.c index 955736336061d2..e791a206768c2b 100644 --- a/drivers/firmware/arm_scmi/scmi_power_control.c +++ b/drivers/firmware/arm_scmi/scmi_power_control.c @@ -341,7 +341,7 @@ static int scmi_syspower_probe(struct scmi_device *sdev) if (ret) return ret; - sc = devm_kzalloc(&sdev->dev, sizeof(*sc), GFP_KERNEL); + sc = devm_kzalloc_obj(&sdev->dev, *sc); if (!sc) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c index b14bb1146356fb..8cc78393c20fa0 100644 --- a/drivers/firmware/arm_scmi/sensors.c +++ b/drivers/firmware/arm_scmi/sensors.c @@ -319,10 +319,8 @@ static int iter_intervals_update_state(struct scmi_iterator_state *st, /* Direct allocation when exceeding pre-allocated */ if (s->intervals.count >= SCMI_MAX_PREALLOC_POOL) { s->intervals.desc = - devm_kcalloc(dev, - s->intervals.count, - sizeof(*s->intervals.desc), - GFP_KERNEL); + devm_kzalloc_objs(dev, *s->intervals.desc, + s->intervals.count); if (!s->intervals.desc) { s->intervals.segmented = false; s->intervals.count = 0; @@ -537,8 +535,7 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph, .s = s, }; - s->axis = devm_kcalloc(ph->dev, s->num_axis, - sizeof(*s->axis), GFP_KERNEL); + s->axis = devm_kzalloc_objs(ph->dev, *s->axis, s->num_axis); if (!s->axis) return -ENOMEM; @@ -1160,15 +1157,15 @@ static int scmi_sensors_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Sensor Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - sinfo = devm_kzalloc(ph->dev, sizeof(*sinfo), GFP_KERNEL); + sinfo = devm_kzalloc_obj(ph->dev, *sinfo); if (!sinfo) return -ENOMEM; ret = scmi_sensor_attributes_get(ph, sinfo); if (ret) return ret; - sinfo->sensors = devm_kcalloc(ph->dev, sinfo->num_sensors, - sizeof(*sinfo->sensors), GFP_KERNEL); + sinfo->sensors = devm_kzalloc_objs(ph->dev, *sinfo->sensors, + sinfo->num_sensors); if (!sinfo->sensors) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/system.c b/drivers/firmware/arm_scmi/system.c index 0f51c36f6a9de6..7e0148fb464187 100644 --- a/drivers/firmware/arm_scmi/system.c +++ b/drivers/firmware/arm_scmi/system.c @@ -145,7 +145,7 @@ static int scmi_system_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "System Power Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(ph->dev, *pinfo); if (!pinfo) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/transports/mailbox.c b/drivers/firmware/arm_scmi/transports/mailbox.c index 56af2cb0f42473..0677005dc6d3f5 100644 --- a/drivers/firmware/arm_scmi/transports/mailbox.c +++ b/drivers/firmware/arm_scmi/transports/mailbox.c @@ -200,7 +200,7 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, if (!tx && !p2a_chan) return -ENODEV; - smbox = devm_kzalloc(dev, sizeof(*smbox), GFP_KERNEL); + smbox = devm_kzalloc_obj(dev, *smbox); if (!smbox) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/transports/optee.c b/drivers/firmware/arm_scmi/transports/optee.c index 6022f74d28f323..c4e9f4a8242a6f 100644 --- a/drivers/firmware/arm_scmi/transports/optee.c +++ b/drivers/firmware/arm_scmi/transports/optee.c @@ -383,7 +383,7 @@ static int scmi_optee_chan_setup(struct scmi_chan_info *cinfo, struct device *de if (!tx) return -ENODEV; - channel = devm_kzalloc(dev, sizeof(*channel), GFP_KERNEL); + channel = devm_kzalloc_obj(dev, *channel); if (!channel) return -ENOMEM; @@ -553,7 +553,7 @@ static int scmi_optee_service_probe(struct tee_client_device *scmi_pta) if (IS_ERR(tee_ctx)) return -ENODEV; - agent = devm_kzalloc(dev, sizeof(*agent), GFP_KERNEL); + agent = devm_kzalloc_obj(dev, *agent); if (!agent) { ret = -ENOMEM; goto err; diff --git a/drivers/firmware/arm_scmi/transports/pcc.c b/drivers/firmware/arm_scmi/transports/pcc.c index 86d4a097d8ec5f..aecd033ecdd9ae 100644 --- a/drivers/firmware/arm_scmi/transports/pcc.c +++ b/drivers/firmware/arm_scmi/transports/pcc.c @@ -266,7 +266,7 @@ acpi_scmi_dsd_parse_transport_package(struct pcc_transport_map *map, } } - p = kzalloc(sizeof(*p), GFP_KERNEL); + p = kzalloc_obj(*p); if (!p) return -ENOMEM; @@ -580,7 +580,7 @@ struct pcc_transport_map *pcc_transport_map_get(struct fwnode_handle *fwnode) if (map) return map; - map = kzalloc_obj(*map, GFP_KERNEL); + map = kzalloc_obj(*map); if (!map) return ERR_PTR(-ENOMEM); @@ -727,7 +727,7 @@ static int pcc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, struct mbox_client *cl; int ret, ss_id; - smbox = devm_kzalloc(dev, sizeof(*smbox), GFP_KERNEL); + smbox = devm_kzalloc_obj(dev, *smbox); if (!smbox) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/transports/smc.c b/drivers/firmware/arm_scmi/transports/smc.c index 7fb2736247a32a..d8cc87e777381e 100644 --- a/drivers/firmware/arm_scmi/transports/smc.c +++ b/drivers/firmware/arm_scmi/transports/smc.c @@ -148,7 +148,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, if (!tx) return -ENODEV; - scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL); + scmi_info = devm_kzalloc_obj(dev, *scmi_info); if (!scmi_info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/transports/virtio.c b/drivers/firmware/arm_scmi/transports/virtio.c index 3d608c8c4fe861..e218e3d8eb143d 100644 --- a/drivers/firmware/arm_scmi/transports/virtio.c +++ b/drivers/firmware/arm_scmi/transports/virtio.c @@ -444,7 +444,7 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, for (i = 0; i < vioch->max_msg; i++) { struct scmi_vio_msg *msg; - msg = devm_kzalloc(dev, sizeof(*msg), GFP_KERNEL); + msg = devm_kzalloc_obj(dev, *msg); if (!msg) return -ENOMEM; @@ -838,7 +838,7 @@ static int scmi_vio_probe(struct virtio_device *vdev) have_vq_rx = scmi_vio_have_vq_rx(vdev); vq_cnt = have_vq_rx ? VIRTIO_SCMI_VQ_MAX_CNT : 1; - channels = devm_kcalloc(dev, vq_cnt, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, vq_cnt); if (!channels) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c index 33f9ebf6092bd6..cdf6fa9117709d 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-bbm.c @@ -350,7 +350,7 @@ static int scmi_imx_bbm_protocol_init(const struct scmi_protocol_handle *ph) dev_info(ph->dev, "NXP SM BBM Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - binfo = devm_kzalloc(ph->dev, sizeof(*binfo), GFP_KERNEL); + binfo = devm_kzalloc_obj(ph->dev, *binfo); if (!binfo) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-cpu.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-cpu.c index 753274af11d226..c439e71bf20153 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-cpu.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-cpu.c @@ -238,7 +238,7 @@ static int scmi_imx_cpu_protocol_init(const struct scmi_protocol_handle *ph) dev_info(ph->dev, "NXP SM CPU Protocol Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - info = devm_kzalloc(ph->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(ph->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c index c56ae247774da6..339cc8dde81af0 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c @@ -231,7 +231,7 @@ static int scmi_imx_lmm_protocol_init(const struct scmi_protocol_handle *ph) dev_info(ph->dev, "NXP SM LMM Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - info = devm_kzalloc(ph->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(ph->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c index 637973fb45e650..2cec3dbb56ad0c 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c @@ -553,7 +553,7 @@ static int scmi_imx_misc_protocol_init(const struct scmi_protocol_handle *ph) dev_info(ph->dev, "NXP SM MISC Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - minfo = devm_kzalloc(ph->dev, sizeof(*minfo), GFP_KERNEL); + minfo = devm_kzalloc_obj(ph->dev, *minfo); if (!minfo) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/voltage.c b/drivers/firmware/arm_scmi/voltage.c index b9391c1ee8a09d..e2fe690af408ce 100644 --- a/drivers/firmware/arm_scmi/voltage.c +++ b/drivers/firmware/arm_scmi/voltage.c @@ -409,7 +409,7 @@ static int scmi_voltage_protocol_init(const struct scmi_protocol_handle *ph) dev_dbg(ph->dev, "Voltage Version %d.%d\n", PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version)); - vinfo = devm_kzalloc(ph->dev, sizeof(*vinfo), GFP_KERNEL); + vinfo = devm_kzalloc_obj(ph->dev, *vinfo); if (!vinfo) return -ENOMEM; @@ -418,9 +418,8 @@ static int scmi_voltage_protocol_init(const struct scmi_protocol_handle *ph) return ret; if (vinfo->num_domains) { - vinfo->domains = devm_kcalloc(ph->dev, vinfo->num_domains, - sizeof(*vinfo->domains), - GFP_KERNEL); + vinfo->domains = devm_kzalloc_objs(ph->dev, *vinfo->domains, + vinfo->num_domains); if (!vinfo->domains) return -ENOMEM; ret = scmi_voltage_descriptors_get(ph, vinfo); diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 68a730d2203771..f80a9c48e281db 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -889,7 +889,7 @@ static int scpi_alloc_xfer_list(struct device *dev, struct scpi_chan *ch) int i; struct scpi_xfer *xfers; - xfers = devm_kcalloc(dev, MAX_SCPI_XFERS, sizeof(*xfers), GFP_KERNEL); + xfers = devm_kzalloc_objs(dev, *xfers, MAX_SCPI_XFERS); if (!xfers) return -ENOMEM; @@ -918,7 +918,7 @@ static int scpi_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct scpi_drvinfo *scpi_drvinfo; - scpi_drvinfo = devm_kzalloc(dev, sizeof(*scpi_drvinfo), GFP_KERNEL); + scpi_drvinfo = devm_kzalloc_obj(dev, *scpi_drvinfo); if (!scpi_drvinfo) return -ENOMEM; @@ -931,7 +931,7 @@ static int scpi_probe(struct platform_device *pdev) } scpi_drvinfo->channels = - devm_kcalloc(dev, count, sizeof(struct scpi_chan), GFP_KERNEL); + devm_kzalloc_objs(dev, struct scpi_chan, count); if (!scpi_drvinfo->channels) return -ENOMEM; diff --git a/drivers/firmware/broadcom/bcm47xx_sprom.c b/drivers/firmware/broadcom/bcm47xx_sprom.c index bca03fd8580865..9e856d89d56d26 100644 --- a/drivers/firmware/broadcom/bcm47xx_sprom.c +++ b/drivers/firmware/broadcom/bcm47xx_sprom.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2004 Florian Schirmer * Copyright (C) 2006 Felix Fietkau - * Copyright (C) 2006 Michael Buesch + * Copyright (C) 2006 Michael Buesch * Copyright (C) 2010 Waldemar Brodkorb * Copyright (C) 2010-2012 Hauke Mehrtens * diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c index 4dcce87685d339..abf9196db883c2 100644 --- a/drivers/firmware/cirrus/cs_dsp.c +++ b/drivers/firmware/cirrus/cs_dsp.c @@ -3614,7 +3614,7 @@ static int cs_dsp_populate_wseq(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq) chunk = cs_dsp_chunk(words, wseq->ctl->len); while (!cs_dsp_chunk_end(&chunk)) { - op = devm_kzalloc(dsp->dev, sizeof(*op), GFP_KERNEL); + op = devm_kzalloc_obj(dsp->dev, *op); if (!op) { ret = -ENOMEM; goto err_free; @@ -3744,7 +3744,7 @@ int cs_dsp_wseq_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq, return -EINVAL; } - op_new = devm_kzalloc(dsp->dev, sizeof(*op_new), GFP_KERNEL); + op_new = devm_kzalloc_obj(dsp->dev, *op_new); if (!op_new) return -ENOMEM; diff --git a/drivers/firmware/coreboot/cbmem.c b/drivers/firmware/coreboot/cbmem.c index 4d20477ed9b25f..731c53a709d8b6 100644 --- a/drivers/firmware/coreboot/cbmem.c +++ b/drivers/firmware/coreboot/cbmem.c @@ -99,7 +99,7 @@ static int cbmem_entry_probe(struct coreboot_device *dev) { struct cbmem_entry *entry; - entry = devm_kzalloc(&dev->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(&dev->dev, *entry); if (!entry) return -ENOMEM; diff --git a/drivers/firmware/coreboot/coreboot-cfr.c b/drivers/firmware/coreboot/coreboot-cfr.c index 2d9ea5d213d824..dd77d4af8dc7c0 100644 --- a/drivers/firmware/coreboot/coreboot-cfr.c +++ b/drivers/firmware/coreboot/coreboot-cfr.c @@ -293,7 +293,7 @@ static efi_char16_t *coreboot_cfr_efi_name(const char *name) return ERR_PTR(-ENAMETOOLONG); efi_char16_t *efi_name __free(kfree) = - kcalloc(len + 1, sizeof(*efi_name), GFP_KERNEL); + kzalloc_objs(*efi_name, len + 1); if (!efi_name) return ERR_PTR(-ENOMEM); @@ -341,7 +341,7 @@ static int coreboot_cfr_read_value(const struct coreboot_cfr_setting *setting, int ret; if (IS_ERR(efi_name)) - return PTR_ERR(no_free_ptr(efi_name)); + return PTR_ERR(efi_name); ret = efivar_lock(); if (ret) @@ -724,8 +724,8 @@ static int coreboot_cfr_copy_bool_values(struct coreboot_cfr_setting *setting) }; unsigned int i; - setting->values = kcalloc(ARRAY_SIZE(bool_values), sizeof(*setting->values), - GFP_KERNEL); + setting->values = kzalloc_objs(*setting->values, + ARRAY_SIZE(bool_values)); if (!setting->values) return -ENOMEM; @@ -779,7 +779,7 @@ static int coreboot_cfr_copy_enum_values(struct coreboot_cfr_setting *setting, if (count <= 0) return count ?: -EINVAL; - setting->values = kcalloc(count, sizeof(*setting->values), GFP_KERNEL); + setting->values = kzalloc_objs(*setting->values, count); if (!setting->values) return -ENOMEM; @@ -902,7 +902,7 @@ static int coreboot_cfr_add_numeric_option(struct coreboot_cfr_drvdata *data, if (option->dependency_id) return 0; - setting = kzalloc_obj(*setting, GFP_KERNEL); + setting = kzalloc_obj(*setting); if (!setting) return -ENOMEM; @@ -1116,7 +1116,7 @@ static int coreboot_cfr_probe(struct coreboot_device *dev) if (!efivar_is_available()) return -EPROBE_DEFER; - data = devm_kzalloc(&dev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&dev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/firmware/coreboot/coreboot_table.c b/drivers/firmware/coreboot/coreboot_table.c index 2c8c928fbb33e2..5980dcc00e07e7 100644 --- a/drivers/firmware/coreboot/coreboot_table.c +++ b/drivers/firmware/coreboot/coreboot_table.c @@ -114,6 +114,30 @@ void coreboot_driver_unregister(struct coreboot_driver *driver) } EXPORT_SYMBOL(coreboot_driver_unregister); +/* + * Whether the memory of a CBMEM entry may be mapped: it must be exclusively + * System RAM, or exclusively Reserved memory, as CBMEM often is on x86, or + * memory that the kernel doesn't know about at all. coreboot leaves CBMEM out + * of the /memory node of the device tree that it passes to FIT payloads, e.g. + * on arm64, and only lists it in the memory reservation block. + * + * Anything else, such as no-map regions on arm64, which are IORESOURCE_MEM + * (see request_standard_resources() in arch/arm64/kernel/setup.c), must not + * be mapped. + */ +static bool cbmem_entry_is_mappable(const struct lb_cbmem_entry *entry) +{ + resource_size_t start = entry->address; + size_t size = entry->entry_size; + + return region_intersects(start, size, IORESOURCE_SYSTEM_RAM, + IORES_DESC_NONE) == REGION_INTERSECTS || + region_intersects(start, size, IORESOURCE_MEM, + IORES_DESC_RESERVED) == REGION_INTERSECTS || + region_intersects(start, size, IORESOURCE_MEM, + IORES_DESC_NONE) == REGION_DISJOINT; +} + static int coreboot_table_populate(struct device *dev, void *ptr, resource_size_t len) { int i, ret; @@ -149,23 +173,7 @@ static int coreboot_table_populate(struct device *dev, void *ptr, resource_size_ switch (device->entry.tag) { case LB_TAG_CBMEM_ENTRY: - /* - * Skip entries that are not exclusively System RAM or - * Reserved memory. - * On ARM64, no-map regions are filtered out as they are - * IORESOURCE_MEM (see request_standard_resources() in - * arch/arm64/kernel/setup.c). - * On x86, CBMEM often resides in standard reserved regions - * (IORES_DESC_RESERVED). - */ - if (region_intersects(device->cbmem_entry.address, - device->cbmem_entry.entry_size, - IORESOURCE_SYSTEM_RAM, - IORES_DESC_NONE) != REGION_INTERSECTS && - region_intersects(device->cbmem_entry.address, - device->cbmem_entry.entry_size, - IORESOURCE_MEM, - IORES_DESC_RESERVED) != REGION_INTERSECTS) { + if (!cbmem_entry_is_mappable(&device->cbmem_entry)) { kfree(device); continue; } diff --git a/drivers/firmware/imx/imx-dsp.c b/drivers/firmware/imx/imx-dsp.c index 7e3f45ddf0c18f..b0a2f1264aaf57 100644 --- a/drivers/firmware/imx/imx-dsp.c +++ b/drivers/firmware/imx/imx-dsp.c @@ -146,7 +146,7 @@ static int imx_dsp_probe(struct platform_device *pdev) device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent); - dsp_ipc = devm_kzalloc(dev, sizeof(*dsp_ipc), GFP_KERNEL); + dsp_ipc = devm_kzalloc_obj(dev, *dsp_ipc); if (!dsp_ipc) return -ENOMEM; diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c index a68d38f8925443..bc22b10ddb20f0 100644 --- a/drivers/firmware/imx/imx-scu-irq.c +++ b/drivers/firmware/imx/imx-scu-irq.c @@ -219,7 +219,7 @@ int imx_scu_enable_general_irq_channel(struct device *dev) if (ret) return ret; - cl = devm_kzalloc(dev, sizeof(*cl), GFP_KERNEL); + cl = devm_kzalloc_obj(dev, *cl); if (!cl) return -ENOMEM; diff --git a/drivers/firmware/imx/imx-scu-soc.c b/drivers/firmware/imx/imx-scu-soc.c index 497192320562d8..517ba10414fee6 100644 --- a/drivers/firmware/imx/imx-scu-soc.c +++ b/drivers/firmware/imx/imx-scu-soc.c @@ -106,8 +106,7 @@ int imx_scu_soc_init(struct device *dev) if (ret) return ret; - soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), - GFP_KERNEL); + soc_dev_attr = devm_kzalloc_obj(dev, *soc_dev_attr); if (!soc_dev_attr) return -ENOMEM; diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.c index 203aac4212529f..b9cc6da4dfce5e 100644 --- a/drivers/firmware/imx/imx-scu.c +++ b/drivers/firmware/imx/imx-scu.c @@ -281,7 +281,7 @@ static int imx_scu_probe(struct platform_device *pdev) int ret; int i; - sc_ipc = devm_kzalloc(dev, sizeof(*sc_ipc), GFP_KERNEL); + sc_ipc = devm_kzalloc_obj(dev, *sc_ipc); if (!sc_ipc) return -ENOMEM; diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index ab9751a59b552f..875975664f48e4 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c @@ -314,7 +314,7 @@ static int __init meson_sm_probe(struct platform_device *pdev) const struct meson_sm_chip *chip; struct meson_sm_firmware *fw; - fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(dev, *fw); if (!fw) return -ENOMEM; diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmware/microchip/mpfs-auto-update.c index b97d34bd2354ba..1a5d7db93445f7 100644 --- a/drivers/firmware/microchip/mpfs-auto-update.c +++ b/drivers/firmware/microchip/mpfs-auto-update.c @@ -414,7 +414,7 @@ static int mpfs_auto_update_probe(struct platform_device *pdev) struct fw_upload *fw_uploader; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/firmware/mtk-adsp-ipc.c b/drivers/firmware/mtk-adsp-ipc.c index 2b79371c61c9bf..eb835ed54ac88f 100644 --- a/drivers/firmware/mtk-adsp-ipc.c +++ b/drivers/firmware/mtk-adsp-ipc.c @@ -78,7 +78,7 @@ static int mtk_adsp_ipc_probe(struct platform_device *pdev) device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent); - adsp_ipc = devm_kzalloc(dev, sizeof(*adsp_ipc), GFP_KERNEL); + adsp_ipc = devm_kzalloc_obj(dev, *adsp_ipc); if (!adsp_ipc) return -ENOMEM; diff --git a/drivers/firmware/qcom/qcom_pas.c b/drivers/firmware/qcom/qcom_pas.c index 24485dd0fa10ad..ae21eed58c3c27 100644 --- a/drivers/firmware/qcom/qcom_pas.c +++ b/drivers/firmware/qcom/qcom_pas.c @@ -35,7 +35,7 @@ struct qcom_pas_context *devm_qcom_pas_context_alloc(struct device *dev, { struct qcom_pas_context *ctx; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/firmware/qcom/qcom_pas_tee.c b/drivers/firmware/qcom/qcom_pas_tee.c index ac33a00687aa19..d248e2229c2f17 100644 --- a/drivers/firmware/qcom/qcom_pas_tee.c +++ b/drivers/firmware/qcom/qcom_pas_tee.c @@ -422,7 +422,7 @@ static int qcom_pas_tee_probe(struct tee_client_device *pas_dev) }; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c index befa68d1dcaf4f..a9e76896826942 100644 --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c @@ -807,7 +807,7 @@ static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev, struct qcuefi_client *qcuefi; int status; - qcuefi = devm_kzalloc(&aux_dev->dev, sizeof(*qcuefi), GFP_KERNEL); + qcuefi = devm_kzalloc_obj(&aux_dev->dev, *qcuefi); if (!qcuefi) return -ENOMEM; diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 43e250faea75ab..b1a821d3b1bc0d 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -2728,7 +2728,7 @@ static int qcom_scm_probe(struct platform_device *pdev) int irq, ret; int i; - scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); + scm = devm_kzalloc_obj(&pdev->dev, *scm); if (!scm) return -ENOMEM; @@ -2797,8 +2797,8 @@ static int qcom_scm_probe(struct platform_device *pdev) ret = qcom_scm_query_waitq_count(scm); scm->wq_cnt = ret < 0 ? QCOM_SCM_DEFAULT_WAITQ_COUNT : ret; - scm->waitq_comps = devm_kcalloc(&pdev->dev, scm->wq_cnt, sizeof(*scm->waitq_comps), - GFP_KERNEL); + scm->waitq_comps = devm_kzalloc_objs(&pdev->dev, *scm->waitq_comps, + scm->wq_cnt); if (!scm->waitq_comps) return -ENOMEM; diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index 942a2e9f02f521..a575caf871b9b7 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -630,8 +630,7 @@ static int acpm_channels_init(struct acpm_info *acpm) int i, ret; acpm->num_chans = readl(&shmem->num_chans); - acpm->chans = devm_kcalloc(dev, acpm->num_chans, sizeof(*acpm->chans), - GFP_KERNEL); + acpm->chans = devm_kzalloc_objs(dev, *acpm->chans, acpm->num_chans); if (!acpm->chans) return -ENOMEM; @@ -709,7 +708,7 @@ static int acpm_probe(struct platform_device *pdev) struct resource res; int ret; - acpm = devm_kzalloc(dev, sizeof(*acpm), GFP_KERNEL); + acpm = devm_kzalloc_obj(dev, *acpm); if (!acpm) return -ENOMEM; diff --git a/drivers/firmware/stratix10-rsu.c b/drivers/firmware/stratix10-rsu.c index b360f752d191fb..d0a63fd28200a3 100644 --- a/drivers/firmware/stratix10-rsu.c +++ b/drivers/firmware/stratix10-rsu.c @@ -1092,7 +1092,7 @@ static int stratix10_rsu_probe(struct platform_device *pdev) struct stratix10_rsu_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c index 88391ea161ede8..ef9d39c9ff0184 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -1516,7 +1516,7 @@ int stratix10_svc_async_send(struct stratix10_svc_chan *chan, void *msg, return -EINVAL; } - handle = kzalloc(sizeof(*handle), GFP_KERNEL); + handle = kzalloc_obj(*handle); if (!handle) return -ENOMEM; @@ -2399,7 +2399,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) if (ret) return ret; } else { - sh_memory = devm_kzalloc(dev, sizeof(*sh_memory), GFP_KERNEL); + sh_memory = devm_kzalloc_obj(dev, *sh_memory); if (!sh_memory) return -ENOMEM; @@ -2414,8 +2414,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) } /* allocate service controller and supporting channel */ - controller = devm_kzalloc(dev, struct_size(controller, chans, SVC_NUM_CHANNEL), - GFP_KERNEL); + controller = devm_kzalloc_flex(dev, *controller, chans, SVC_NUM_CHANNEL); if (!controller) { ret = -ENOMEM; goto err_destroy_pool; @@ -2480,7 +2479,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) platform_set_drvdata(pdev, controller); /* add svc client device(s) */ - svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL); + svc = devm_kzalloc_obj(dev, *svc); if (!svc) { ret = -ENOMEM; goto err_free_fifos; diff --git a/drivers/firmware/tegra/bpmp-tegra186.c b/drivers/firmware/tegra/bpmp-tegra186.c index 64863db7a71576..5a97496600ac15 100644 --- a/drivers/firmware/tegra/bpmp-tegra186.c +++ b/drivers/firmware/tegra/bpmp-tegra186.c @@ -114,8 +114,7 @@ static int tegra186_bpmp_channel_init(struct tegra_bpmp_channel *channel, unsigned int offset; int err; - channel->ivc = devm_kzalloc(bpmp->dev, sizeof(*channel->ivc), - GFP_KERNEL); + channel->ivc = devm_kzalloc_obj(bpmp->dev, *channel->ivc); if (!channel->ivc) return -ENOMEM; @@ -325,7 +324,7 @@ static int tegra186_bpmp_init(struct tegra_bpmp *bpmp) struct tegra186_bpmp *priv; int err; - priv = devm_kzalloc(bpmp->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(bpmp->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/firmware/tegra/bpmp-tegra210.c b/drivers/firmware/tegra/bpmp-tegra210.c index 6295f5640c1571..a33bb027c8b8d4 100644 --- a/drivers/firmware/tegra/bpmp-tegra210.c +++ b/drivers/firmware/tegra/bpmp-tegra210.c @@ -166,7 +166,7 @@ static int tegra210_bpmp_init(struct tegra_bpmp *bpmp) unsigned int i; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/firmware/tegra/bpmp.c b/drivers/firmware/tegra/bpmp.c index 753472b53bd849..5fbd6a3e69e098 100644 --- a/drivers/firmware/tegra/bpmp.c +++ b/drivers/firmware/tegra/bpmp.c @@ -509,7 +509,7 @@ int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq, if (!handler) return -EINVAL; - entry = devm_kzalloc(bpmp->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(bpmp->dev, *entry); if (!entry) return -ENOMEM; @@ -740,7 +740,7 @@ static int tegra_bpmp_probe(struct platform_device *pdev) size_t size; int err; - bpmp = devm_kzalloc(&pdev->dev, sizeof(*bpmp), GFP_KERNEL); + bpmp = devm_kzalloc_obj(&pdev->dev, *bpmp); if (!bpmp) return -ENOMEM; @@ -764,19 +764,17 @@ static int tegra_bpmp_probe(struct platform_device *pdev) return -ENOMEM; spin_lock_init(&bpmp->atomic_tx_lock); - bpmp->tx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->tx_channel), - GFP_KERNEL); + bpmp->tx_channel = devm_kzalloc_obj(&pdev->dev, *bpmp->tx_channel); if (!bpmp->tx_channel) return -ENOMEM; - bpmp->rx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->rx_channel), - GFP_KERNEL); + bpmp->rx_channel = devm_kzalloc_obj(&pdev->dev, *bpmp->rx_channel); if (!bpmp->rx_channel) return -ENOMEM; - bpmp->threaded_channels = devm_kcalloc(&pdev->dev, bpmp->threaded.count, - sizeof(*bpmp->threaded_channels), - GFP_KERNEL); + bpmp->threaded_channels = devm_kzalloc_objs(&pdev->dev, + *bpmp->threaded_channels, + bpmp->threaded.count); if (!bpmp->threaded_channels) return -ENOMEM; diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 5fa63ff7c74a6d..fd1ff28c598929 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -3693,13 +3693,12 @@ devm_ti_sci_get_resource_sets(const struct ti_sci_handle *handle, bool valid_set = false; int i, ret, res_count; - res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(dev, *res); if (!res) return ERR_PTR(-ENOMEM); res->sets = sets; - res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc), - GFP_KERNEL); + res->desc = devm_kzalloc_objs(dev, *res->desc, res->sets); if (!res->desc) return ERR_PTR(-ENOMEM); @@ -3759,7 +3758,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, return ERR_PTR(sets); } - sub_types = kcalloc(sets, sizeof(*sub_types), GFP_KERNEL); + sub_types = kzalloc_objs(*sub_types, sets); if (!sub_types) return ERR_PTR(-ENOMEM); @@ -4086,7 +4085,7 @@ static int ti_sci_probe(struct platform_device *pdev) desc = device_get_match_data(dev); - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; @@ -4117,10 +4116,8 @@ static int ti_sci_probe(struct platform_device *pdev) 1 << 8 * sizeof(((struct ti_sci_msg_hdr *)0)->seq))) return -EINVAL; - minfo->xfer_block = devm_kcalloc(dev, - desc->max_msgs, - sizeof(*minfo->xfer_block), - GFP_KERNEL); + minfo->xfer_block = devm_kzalloc_objs(dev, *minfo->xfer_block, + desc->max_msgs); if (!minfo->xfer_block) return -ENOMEM; diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 1eac9948148f2d..47fb6e39e0fc93 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -428,7 +428,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - rwtm = devm_kzalloc(dev, sizeof(*rwtm), GFP_KERNEL); + rwtm = devm_kzalloc_obj(dev, *rwtm); if (!rwtm) return -ENOMEM; diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c index d76660c553542d..727a9888a93349 100644 --- a/drivers/firmware/xilinx/zynqmp.c +++ b/drivers/firmware/xilinx/zynqmp.c @@ -2284,7 +2284,7 @@ static int zynqmp_firmware_probe(struct platform_device *pdev) if (ret >= 0 && ((ret & FIRMWARE_VERSION_MASK) >= PM_API_VERSION_1)) feature_check_enabled = true; - devinfo = devm_kzalloc(dev, sizeof(*devinfo), GFP_KERNEL); + devinfo = devm_kzalloc_obj(dev, *devinfo); if (!devinfo) return -ENOMEM; diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c index 507e29d3a79fff..d736f9fa1898b2 100644 --- a/drivers/fpga/altera-cvp.c +++ b/drivers/fpga/altera-cvp.c @@ -628,7 +628,7 @@ static int altera_cvp_probe(struct pci_dev *pdev, return -ENODEV; } - conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL); + conf = devm_kzalloc_obj(&pdev->dev, *conf); if (!conf) return -ENOMEM; diff --git a/drivers/fpga/altera-fpga2sdram.c b/drivers/fpga/altera-fpga2sdram.c index e41492988dd633..96ab4ec6cce09b 100644 --- a/drivers/fpga/altera-fpga2sdram.c +++ b/drivers/fpga/altera-fpga2sdram.c @@ -94,7 +94,7 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev) struct regmap *sysmgr; int ret = 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/altera-freeze-bridge.c b/drivers/fpga/altera-freeze-bridge.c index c24c976117c8ca..30d03ba1448166 100644 --- a/drivers/fpga/altera-freeze-bridge.c +++ b/drivers/fpga/altera-freeze-bridge.c @@ -230,7 +230,7 @@ static int altera_freeze_br_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c index df8671af4a92a0..b5eefc64e00195 100644 --- a/drivers/fpga/altera-pr-ip-core.c +++ b/drivers/fpga/altera-pr-ip-core.c @@ -179,7 +179,7 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base) struct fpga_manager *mgr; u32 val; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c index d0ec3539b31f77..94c3fa2885442c 100644 --- a/drivers/fpga/altera-ps-spi.c +++ b/drivers/fpga/altera-ps-spi.c @@ -235,7 +235,7 @@ static int altera_ps_probe(struct spi_device *spi) struct altera_ps_conf *conf; struct fpga_manager *mgr; - conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL); + conf = devm_kzalloc_obj(&spi->dev, *conf); if (!conf) return -ENOMEM; diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c index 097a97eeea66c2..245468b7b92201 100644 --- a/drivers/fpga/dfl-afu-main.c +++ b/drivers/fpga/dfl-afu-main.c @@ -860,7 +860,7 @@ static int afu_dev_init(struct platform_device *pdev) struct dfl_feature_dev_data *fdata = to_dfl_feature_dev_data(&pdev->dev); struct dfl_afu *afu; - afu = devm_kzalloc(&pdev->dev, sizeof(*afu), GFP_KERNEL); + afu = devm_kzalloc_obj(&pdev->dev, *afu); if (!afu) return -ENOMEM; diff --git a/drivers/fpga/dfl-afu-region.c b/drivers/fpga/dfl-afu-region.c index b11a5b21e66666..6bd28afcb5894a 100644 --- a/drivers/fpga/dfl-afu-region.c +++ b/drivers/fpga/dfl-afu-region.c @@ -55,7 +55,7 @@ int afu_mmio_region_add(struct dfl_feature_dev_data *fdata, struct dfl_afu *afu; int ret = 0; - region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL); + region = devm_kzalloc_obj(dev, *region); if (!region) return -ENOMEM; diff --git a/drivers/fpga/dfl-fme-br.c b/drivers/fpga/dfl-fme-br.c index 28b0f9d062ac4d..85a1b60d2965ca 100644 --- a/drivers/fpga/dfl-fme-br.c +++ b/drivers/fpga/dfl-fme-br.c @@ -62,7 +62,7 @@ static int fme_br_probe(struct platform_device *pdev) struct fme_br_priv *priv; struct fpga_bridge *br; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/dfl-fme-main.c b/drivers/fpga/dfl-fme-main.c index 8aca2fb20e87e9..b5f22d97742e53 100644 --- a/drivers/fpga/dfl-fme-main.c +++ b/drivers/fpga/dfl-fme-main.c @@ -678,7 +678,7 @@ static int fme_dev_init(struct platform_device *pdev) struct dfl_feature_dev_data *fdata = to_dfl_feature_dev_data(&pdev->dev); struct dfl_fme *fme; - fme = devm_kzalloc(&pdev->dev, sizeof(*fme), GFP_KERNEL); + fme = devm_kzalloc_obj(&pdev->dev, *fme); if (!fme) return -ENOMEM; diff --git a/drivers/fpga/dfl-fme-mgr.c b/drivers/fpga/dfl-fme-mgr.c index ab228d8837a04c..90d73ae6d81492 100644 --- a/drivers/fpga/dfl-fme-mgr.c +++ b/drivers/fpga/dfl-fme-mgr.c @@ -281,7 +281,7 @@ static int fme_mgr_probe(struct platform_device *pdev) struct fme_mgr_priv *priv; struct fpga_manager *mgr; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -297,7 +297,7 @@ static int fme_mgr_probe(struct platform_device *pdev) info.name = "DFL FME FPGA Manager"; info.mops = &fme_mgr_ops; info.priv = priv; - info.compat_id = devm_kzalloc(dev, sizeof(*info.compat_id), GFP_KERNEL); + info.compat_id = devm_kzalloc_obj(dev, *info.compat_id); if (!info.compat_id) return -ENOMEM; diff --git a/drivers/fpga/dfl-fme-perf.c b/drivers/fpga/dfl-fme-perf.c index 495edc448b68fe..a0e3abc64c9e15 100644 --- a/drivers/fpga/dfl-fme-perf.c +++ b/drivers/fpga/dfl-fme-perf.c @@ -966,7 +966,7 @@ static int fme_perf_init(struct platform_device *pdev, struct fme_perf_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/dfl-fme-pr.c b/drivers/fpga/dfl-fme-pr.c index b878b260af38e5..3ef1ecb7edd57c 100644 --- a/drivers/fpga/dfl-fme-pr.c +++ b/drivers/fpga/dfl-fme-pr.c @@ -233,7 +233,7 @@ dfl_fme_create_bridge(struct dfl_feature_dev_data *fdata, int port_id) struct dfl_fme_bridge *fme_br; int ret = -ENOMEM; - fme_br = devm_kzalloc(dev, sizeof(*fme_br), GFP_KERNEL); + fme_br = devm_kzalloc_obj(dev, *fme_br); if (!fme_br) return ERR_PTR(ret); @@ -306,7 +306,7 @@ dfl_fme_create_region(struct dfl_feature_dev_data *fdata, struct dfl_fme_region *fme_region; int ret = -ENOMEM; - fme_region = devm_kzalloc(dev, sizeof(*fme_region), GFP_KERNEL); + fme_region = devm_kzalloc_obj(dev, *fme_region); if (!fme_region) return ERR_PTR(ret); diff --git a/drivers/fpga/dfl-n3000-nios.c b/drivers/fpga/dfl-n3000-nios.c index 9ddf1d1d392f35..c0bd2c8845d06a 100644 --- a/drivers/fpga/dfl-n3000-nios.c +++ b/drivers/fpga/dfl-n3000-nios.c @@ -529,7 +529,7 @@ static int n3000_nios_probe(struct dfl_device *ddev) struct n3000_nios *nn; int ret; - nn = devm_kzalloc(dev, sizeof(*nn), GFP_KERNEL); + nn = devm_kzalloc_obj(dev, *nn); if (!nn) return -ENOMEM; diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c index e25205c6d8f00c..2e9046175c75e0 100644 --- a/drivers/fpga/dfl-pci.c +++ b/drivers/fpga/dfl-pci.c @@ -116,7 +116,7 @@ static int cci_init_drvdata(struct pci_dev *pcidev) { struct cci_drvdata *drvdata; - drvdata = devm_kzalloc(&pcidev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pcidev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index 4c63c7c8579bb7..6f5fa7b2fc54fb 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c @@ -754,17 +754,17 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) if (WARN_ON_ONCE(type >= DFL_ID_MAX)) return ERR_PTR(-EINVAL); - fdata = devm_kzalloc(binfo->dev, sizeof(*fdata), GFP_KERNEL); + fdata = devm_kzalloc_obj(binfo->dev, *fdata); if (!fdata) return ERR_PTR(-ENOMEM); - fdata->features = devm_kcalloc(binfo->dev, binfo->feature_num, - sizeof(*fdata->features), GFP_KERNEL); + fdata->features = devm_kzalloc_objs(binfo->dev, *fdata->features, + binfo->feature_num); if (!fdata->features) return ERR_PTR(-ENOMEM); - fdata->resources = devm_kcalloc(binfo->dev, binfo->feature_num, - sizeof(*fdata->resources), GFP_KERNEL); + fdata->resources = devm_kzalloc_objs(binfo->dev, *fdata->resources, + binfo->feature_num); if (!fdata->resources) return ERR_PTR(-ENOMEM); @@ -834,8 +834,8 @@ binfo_create_feature_dev_data(struct build_feature_devs_info *binfo) } if (finfo->nr_irqs) { - ctx = devm_kcalloc(binfo->dev, finfo->nr_irqs, - sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_objs(binfo->dev, *ctx, + finfo->nr_irqs); if (!ctx) return ERR_PTR(-ENOMEM); @@ -1425,7 +1425,7 @@ struct dfl_fpga_enum_info *dfl_fpga_enum_info_alloc(struct device *dev) get_device(dev); - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) { put_device(dev); return NULL; @@ -1481,7 +1481,7 @@ int dfl_fpga_enum_info_add_dfl(struct dfl_fpga_enum_info *info, { struct dfl_fpga_enum_dfl *dfl; - dfl = devm_kzalloc(info->dev, sizeof(*dfl), GFP_KERNEL); + dfl = devm_kzalloc_obj(info->dev, *dfl); if (!dfl) return -ENOMEM; @@ -1568,7 +1568,7 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) if (!info->dev) return ERR_PTR(-ENODEV); - cdev = devm_kzalloc(info->dev, sizeof(*cdev), GFP_KERNEL); + cdev = devm_kzalloc_obj(info->dev, *cdev); if (!cdev) return ERR_PTR(-ENOMEM); @@ -1583,7 +1583,7 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) } /* create and init build info for enumeration */ - binfo = devm_kzalloc(info->dev, sizeof(*binfo), GFP_KERNEL); + binfo = devm_kzalloc_obj(info->dev, *binfo); if (!binfo) { ret = -ENOMEM; goto unregister_region_exit; diff --git a/drivers/fpga/efinix-spi.c b/drivers/fpga/efinix-spi.c index ed9a41232a32a9..beade2255987c5 100644 --- a/drivers/fpga/efinix-spi.c +++ b/drivers/fpga/efinix-spi.c @@ -209,7 +209,7 @@ static int efinix_spi_probe(struct spi_device *spi) return dev_err_probe(&spi->dev, -EINVAL, "Unsupported SPI mode, set CPHA and CPOL\n"); - conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL); + conf = devm_kzalloc_obj(&spi->dev, *conf); if (!conf) return -ENOMEM; diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 5a0b7780b33588..6f70fa26e5c3ce 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -112,7 +112,7 @@ struct fpga_image_info *fpga_image_info_alloc(struct device *dev) get_device(dev); - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) { put_device(dev); return NULL; diff --git a/drivers/fpga/ice40-spi.c b/drivers/fpga/ice40-spi.c index f72d38d9fe4f38..bbe8aa30e876ed 100644 --- a/drivers/fpga/ice40-spi.c +++ b/drivers/fpga/ice40-spi.c @@ -138,7 +138,7 @@ static int ice40_fpga_probe(struct spi_device *spi) struct fpga_manager *mgr; int ret; - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 7d23d914df3f22..af8e7c8af44b45 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -690,7 +690,7 @@ static int m10bmc_sec_probe(struct platform_device *pdev) unsigned int len; int ret; - sec = devm_kzalloc(&pdev->dev, sizeof(*sec), GFP_KERNEL); + sec = devm_kzalloc_obj(&pdev->dev, *sec); if (!sec) return -ENOMEM; diff --git a/drivers/fpga/lattice-sysconfig-spi.c b/drivers/fpga/lattice-sysconfig-spi.c index b39c62f568640d..694972eafbe69b 100644 --- a/drivers/fpga/lattice-sysconfig-spi.c +++ b/drivers/fpga/lattice-sysconfig-spi.c @@ -94,7 +94,7 @@ static int sysconfig_spi_probe(struct spi_device *spi) struct sysconfig_priv *priv; const u32 *spi_max_speed; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c index cc8f6d7bb9781c..d20b7bea7ccbf0 100644 --- a/drivers/fpga/microchip-spi.c +++ b/drivers/fpga/microchip-spi.c @@ -373,7 +373,7 @@ static int mpf_probe(struct spi_device *spi) struct fpga_manager *mgr; struct mpf_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/socfpga-a10.c b/drivers/fpga/socfpga-a10.c index 0165a3c8693223..17b101a9c37c6b 100644 --- a/drivers/fpga/socfpga-a10.c +++ b/drivers/fpga/socfpga-a10.c @@ -473,7 +473,7 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev) struct fpga_manager *mgr; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/socfpga.c b/drivers/fpga/socfpga.c index b08b4bb8f6507d..bd078170b76cdd 100644 --- a/drivers/fpga/socfpga.c +++ b/drivers/fpga/socfpga.c @@ -548,7 +548,7 @@ static int socfpga_fpga_probe(struct platform_device *pdev) struct fpga_manager *mgr; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c index 5aed560050c27b..23c5f7c9041201 100644 --- a/drivers/fpga/stratix10-soc.c +++ b/drivers/fpga/stratix10-soc.c @@ -405,7 +405,7 @@ static int s10_probe(struct platform_device *pdev) struct fpga_manager *mgr; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/ts73xx-fpga.c b/drivers/fpga/ts73xx-fpga.c index 3460e4809f86fa..b2408d4a73a8ee 100644 --- a/drivers/fpga/ts73xx-fpga.c +++ b/drivers/fpga/ts73xx-fpga.c @@ -105,7 +105,7 @@ static int ts73xx_fpga_probe(struct platform_device *pdev) struct ts73xx_fpga_priv *priv; struct fpga_manager *mgr; - priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(kdev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/xilinx-pr-decoupler.c b/drivers/fpga/xilinx-pr-decoupler.c index 45b65a3264af1c..1405ddbe88f1c0 100644 --- a/drivers/fpga/xilinx-pr-decoupler.c +++ b/drivers/fpga/xilinx-pr-decoupler.c @@ -108,7 +108,7 @@ static int xlnx_pr_decoupler_probe(struct platform_device *pdev) struct fpga_bridge *br; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fpga/xilinx-selectmap.c b/drivers/fpga/xilinx-selectmap.c index ff167b23fdeda9..447eea83b5d5ac 100644 --- a/drivers/fpga/xilinx-selectmap.c +++ b/drivers/fpga/xilinx-selectmap.c @@ -56,7 +56,7 @@ static int xilinx_selectmap_probe(struct platform_device *pdev) struct xilinx_selectmap_conf *conf; void __iomem *base; - conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL); + conf = devm_kzalloc_obj(&pdev->dev, *conf); if (!conf) return -ENOMEM; diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index 765626cad69a11..ff2607d1ec0fc0 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -46,7 +46,7 @@ static int xilinx_spi_probe(struct spi_device *spi) { struct xilinx_fpga_core *core; - core = devm_kzalloc(&spi->dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(&spi->dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c index 2f8ba32e4002f3..97351ed9dcaf77 100644 --- a/drivers/fpga/zynq-fpga.c +++ b/drivers/fpga/zynq-fpga.c @@ -557,7 +557,7 @@ static int zynq_fpga_probe(struct platform_device *pdev) struct fpga_manager *mgr; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; spin_lock_init(&priv->dma_lock); diff --git a/drivers/fpga/zynqmp-fpga.c b/drivers/fpga/zynqmp-fpga.c index f3434e2c487bf2..ed6f5dac1a78cd 100644 --- a/drivers/fpga/zynqmp-fpga.c +++ b/drivers/fpga/zynqmp-fpga.c @@ -109,7 +109,7 @@ static int zynqmp_fpga_probe(struct platform_device *pdev) struct zynqmp_fpga_priv *priv; struct fpga_manager *mgr; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/fsi/fsi-occ.c b/drivers/fsi/fsi-occ.c index 416d176f0936b2..e66405fa5215cd 100644 --- a/drivers/fsi/fsi-occ.c +++ b/drivers/fsi/fsi-occ.c @@ -629,7 +629,7 @@ static int occ_probe(struct platform_device *pdev) .name = "occ-hwmon", }; - occ = devm_kzalloc(dev, sizeof(*occ), GFP_KERNEL); + occ = devm_kzalloc_obj(dev, *occ); if (!occ) return -ENOMEM; diff --git a/drivers/fsi/i2cr-scom.c b/drivers/fsi/i2cr-scom.c index 83b3c0348791cf..8b3e1b3f4c06d7 100644 --- a/drivers/fsi/i2cr-scom.c +++ b/drivers/fsi/i2cr-scom.c @@ -90,7 +90,7 @@ static int i2cr_scom_probe(struct fsi_device *fsi_dev) if (!is_fsi_master_i2cr(fsi_dev->slave->master)) return -ENODEV; - scom = devm_kzalloc(dev, sizeof(*scom), GFP_KERNEL); + scom = devm_kzalloc_obj(dev, *scom); if (!scom) return -ENOMEM; diff --git a/drivers/gnss/sirf.c b/drivers/gnss/sirf.c index 79375d14bbb673..0f9a86c2421653 100644 --- a/drivers/gnss/sirf.c +++ b/drivers/gnss/sirf.c @@ -399,7 +399,7 @@ static int sirf_probe(struct serdev_device *serdev) struct sirf_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index cf5a50102d4916..7ddf578ba5301c 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -238,7 +238,7 @@ static int dio48e_probe(struct device *dev, unsigned int id) return -EBUSY; } - dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL); + dio48egpio = devm_kzalloc_obj(dev, *dio48egpio); if (!dio48egpio) return -ENOMEM; @@ -290,7 +290,7 @@ static int dio48e_probe(struct device *dev, unsigned int id) return dev_err_probe(dev, PTR_ERR(pit_config.map), "Unable to initialize i8254 register map\n"); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index fb017569cfa853..93d7ccaded83e8 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -148,7 +148,7 @@ static int idi_48_probe(struct device *dev, unsigned int id) return dev_err_probe(dev, PTR_ERR(map), "Unable to initialize register map\n"); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index 5ca61cf5206aa4..6f15b7c2358b34 100644 --- a/drivers/gpio/gpio-74x164.c +++ b/drivers/gpio/gpio-74x164.c @@ -128,7 +128,7 @@ static int gen_74x164_probe(struct spi_device *spi) if (ret) return dev_err_probe(dev, ret, "Missing 'registers-number' property.\n"); - chip = devm_kzalloc(dev, struct_size(chip, buffer, nregs), GFP_KERNEL); + chip = devm_kzalloc_flex(dev, *chip, buffer, nregs); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-74xx-mmio.c b/drivers/gpio/gpio-74xx-mmio.c index cdac37926f8e74..adb2d75b046123 100644 --- a/drivers/gpio/gpio-74xx-mmio.c +++ b/drivers/gpio/gpio-74xx-mmio.c @@ -112,7 +112,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev) void __iomem *dat; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-adnp.c b/drivers/gpio/gpio-adnp.c index 0410e3adbf54fb..6368621a356a02 100644 --- a/drivers/gpio/gpio-adnp.c +++ b/drivers/gpio/gpio-adnp.c @@ -480,7 +480,7 @@ static int adnp_i2c_probe(struct i2c_client *client) if (err < 0) return err; - adnp = devm_kzalloc(&client->dev, sizeof(*adnp), GFP_KERNEL); + adnp = devm_kzalloc_obj(&client->dev, *adnp); if (!adnp) return -ENOMEM; diff --git a/drivers/gpio/gpio-adp5520.c b/drivers/gpio/gpio-adp5520.c index 6305c8b7dc0542..52b8835a7b25b8 100644 --- a/drivers/gpio/gpio-adp5520.c +++ b/drivers/gpio/gpio-adp5520.c @@ -105,7 +105,7 @@ static int adp5520_gpio_probe(struct platform_device *pdev) return -ENODEV; } - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (dev == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-adp5585.c b/drivers/gpio/gpio-adp5585.c index 7c04a7e86c8f8c..e7b416143987e7 100644 --- a/drivers/gpio/gpio-adp5585.c +++ b/drivers/gpio/gpio-adp5585.c @@ -400,7 +400,7 @@ static int adp5585_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret; - adp5585_gpio = devm_kzalloc(dev, sizeof(*adp5585_gpio), GFP_KERNEL); + adp5585_gpio = devm_kzalloc_obj(dev, *adp5585_gpio); if (!adp5585_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index b0b65416d74dc1..dbf5115edceb0d 100644 --- a/drivers/gpio/gpio-aggregator.c +++ b/drivers/gpio/gpio-aggregator.c @@ -472,9 +472,8 @@ static int gpiochip_fwd_setup_delay_line(struct gpiochip_fwd *fwd) { struct gpio_chip *chip = &fwd->chip; - fwd->delay_timings = devm_kcalloc(chip->parent, chip->ngpio, - sizeof(*fwd->delay_timings), - GFP_KERNEL); + fwd->delay_timings = devm_kzalloc_objs(chip->parent, + *fwd->delay_timings, chip->ngpio); if (!fwd->delay_timings) return -ENOMEM; @@ -695,11 +694,11 @@ struct gpiochip_fwd *devm_gpiochip_fwd_alloc(struct device *dev, struct gpiochip_fwd *fwd; struct gpio_chip *chip; - fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)), GFP_KERNEL); + fwd = devm_kzalloc_flex(dev, *fwd, tmp, fwd_tmp_size(ngpios)); if (!fwd) return ERR_PTR(-ENOMEM); - fwd->descs = devm_kcalloc(dev, ngpios, sizeof(*fwd->descs), GFP_KERNEL); + fwd->descs = devm_kzalloc_objs(dev, *fwd->descs, ngpios); if (!fwd->descs) return ERR_PTR(-ENOMEM); @@ -1604,7 +1603,7 @@ static int gpio_aggregator_probe(struct platform_device *pdev) if (n < 0) return n; - descs = devm_kmalloc_array(dev, n, sizeof(*descs), GFP_KERNEL); + descs = devm_kmalloc_objs(dev, *descs, n); if (!descs) return -ENOMEM; diff --git a/drivers/gpio/gpio-altera-a10sr.c b/drivers/gpio/gpio-altera-a10sr.c index a41e5575ee379c..b075d2fb604191 100644 --- a/drivers/gpio/gpio-altera-a10sr.c +++ b/drivers/gpio/gpio-altera-a10sr.c @@ -81,7 +81,7 @@ static int altr_a10sr_gpio_probe(struct platform_device *pdev) struct altr_a10sr_gpio *gpio; struct altr_a10sr *a10sr = dev_get_drvdata(pdev->dev.parent); - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c index a6ac9356229cdc..5284d01614a5df 100644 --- a/drivers/gpio/gpio-altera.c +++ b/drivers/gpio/gpio-altera.c @@ -174,7 +174,7 @@ static int altera_gpio_probe(struct platform_device *pdev) struct gpio_irq_chip *girq; int mapped_irq; - altera_gc = devm_kzalloc(&pdev->dev, sizeof(*altera_gc), GFP_KERNEL); + altera_gc = devm_kzalloc_obj(&pdev->dev, *altera_gc); if (!altera_gc) return -ENOMEM; @@ -241,8 +241,7 @@ static int altera_gpio_probe(struct platform_device *pdev) else girq->parent_handler = altera_gpio_irq_edge_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->default_type = IRQ_TYPE_NONE; diff --git a/drivers/gpio/gpio-amd-fch.c b/drivers/gpio/gpio-amd-fch.c index 9b9d75acf35a09..d13dc7c72aef49 100644 --- a/drivers/gpio/gpio-amd-fch.c +++ b/drivers/gpio/gpio-amd-fch.c @@ -137,7 +137,7 @@ static int amd_fch_gpio_probe(struct platform_device *pdev) return -ENOENT; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-amdpt.c b/drivers/gpio/gpio-amdpt.c index 8458a6949c65d3..e886cf9e14ea85 100644 --- a/drivers/gpio/gpio-amdpt.c +++ b/drivers/gpio/gpio-amdpt.c @@ -78,7 +78,7 @@ static int pt_gpio_probe(struct platform_device *pdev) return -ENODEV; } - pt_gpio = devm_kzalloc(dev, sizeof(struct pt_gpio_chip), GFP_KERNEL); + pt_gpio = devm_kzalloc_obj(dev, struct pt_gpio_chip); if (!pt_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-arizona.c b/drivers/gpio/gpio-arizona.c index 88cf013f0d90de..5a6182ad804bd7 100644 --- a/drivers/gpio/gpio-arizona.c +++ b/drivers/gpio/gpio-arizona.c @@ -155,8 +155,7 @@ static int arizona_gpio_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - arizona_gpio = devm_kzalloc(&pdev->dev, sizeof(*arizona_gpio), - GFP_KERNEL); + arizona_gpio = devm_kzalloc_obj(&pdev->dev, *arizona_gpio); if (!arizona_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index 4225261f61c814..b5504ea8c93d92 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -610,7 +610,7 @@ static int aspeed_sgpio_probe(struct platform_device *pdev) unsigned long apb_freq; int rc; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index dc53b2decb66e5..45e90ebaf07840 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c @@ -1041,6 +1041,17 @@ static void aspeed_g4_reg_bit_set(struct aspeed_gpio *gpio, unsigned int offset, void __iomem *addr = aspeed_gpio_g4_bank_reg(gpio, bank, reg); u32 temp; + /* + * The interrupt status register is write-1-to-clear. Write only this + * line's bit so that interrupts pending on the other lines of the bank + * stay latched. + */ + if (reg == reg_irq_status) { + if (val) + iowrite32(GPIO_BIT(offset), addr); + return; + } + if (reg == reg_val) temp = gpio->dcache[GPIO_BANK(offset)]; else @@ -1157,7 +1168,13 @@ static void aspeed_g7_reg_bit_set(struct aspeed_gpio *gpio, unsigned int offset, u32 write_val; if (mask) { - write_val = (ioread32(addr) & ~(mask)) | field_prep(mask, val); + /* + * The interrupt status bit is write-1-to-clear. Keep it zero + * unless it is the field being written, so that updating any + * other field leaves a pending interrupt latched. + */ + write_val = ioread32(addr) & ~(mask | GPIO_G7_CTRL_IRQ_STS); + write_val |= field_prep(mask, val); iowrite32(write_val, addr); } } @@ -1307,7 +1324,7 @@ static int aspeed_gpio_probe(struct platform_device *pdev) int rc, irq, i, banks, err; u32 ngpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; @@ -1353,7 +1370,7 @@ static int aspeed_gpio_probe(struct platform_device *pdev) if (gpio->config->require_dcache) { /* Allocate a cache of the output registers */ banks = DIV_ROUND_UP(gpio->chip.ngpio, 32); - gpio->dcache = devm_kcalloc(&pdev->dev, banks, sizeof(u32), GFP_KERNEL); + gpio->dcache = devm_kzalloc_objs(&pdev->dev, u32, banks); if (!gpio->dcache) return -ENOMEM; /* @@ -1377,7 +1394,7 @@ static int aspeed_gpio_probe(struct platform_device *pdev) girq->parent_handler = aspeed_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = gpio->irq; diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c index aa37579c9608fe..423e6399b6f6fa 100644 --- a/drivers/gpio/gpio-ath79.c +++ b/drivers/gpio/gpio-ath79.c @@ -228,9 +228,7 @@ static int ath79_gpio_register_wifi_descriptors(struct device *dev, int i; /* Create a gpiod lookup using gpiochip-local offsets + 1 for NULL */ - lookup = devm_kzalloc(dev, - struct_size(lookup, table, ATH79K_WIFI_DESCS + 1), - GFP_KERNEL); + lookup = devm_kzalloc_flex(dev, *lookup, table, ATH79K_WIFI_DESCS + 1); if (!lookup) return -ENOMEM; @@ -274,7 +272,7 @@ static int ath79_gpio_probe(struct platform_device *pdev) bool oe_inverted; int err; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -317,8 +315,7 @@ static int ath79_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &ath79_gpio_irqchip); girq->parent_handler = ath79_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = platform_get_irq(pdev, 0); diff --git a/drivers/gpio/gpio-axiado-sgpio.c b/drivers/gpio/gpio-axiado-sgpio.c index b57a5074ccef39..3af222b718e6df 100644 --- a/drivers/gpio/gpio-axiado-sgpio.c +++ b/drivers/gpio/gpio-axiado-sgpio.c @@ -557,7 +557,7 @@ static int axiado_sgpio_probe(struct platform_device *pdev) u32 sgpio_freq; int irq, rc; - sgpio = devm_kzalloc(&pdev->dev, sizeof(*sgpio), GFP_KERNEL); + sgpio = devm_kzalloc_obj(&pdev->dev, *sgpio); if (!sgpio) return -ENOMEM; @@ -592,10 +592,8 @@ static int axiado_sgpio_probe(struct platform_device *pdev) sgpio->nsignals = ngpio / 2; - sgpio->din_shadow = devm_kcalloc(&pdev->dev, - DIV_ROUND_UP(sgpio->nsignals, - SGPIO_BANK_SIZE), - sizeof(*sgpio->din_shadow), GFP_KERNEL); + sgpio->din_shadow = devm_kzalloc_objs(&pdev->dev, *sgpio->din_shadow, + DIV_ROUND_UP(sgpio->nsignals, SGPIO_BANK_SIZE)); sgpio->irq_unmasked = devm_bitmap_zalloc(&pdev->dev, sgpio->nsignals, GFP_KERNEL); sgpio->irq_rising = devm_bitmap_zalloc(&pdev->dev, sgpio->nsignals, diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c index b0beffe48b7d96..a58084fd902008 100644 --- a/drivers/gpio/gpio-bcm-kona.c +++ b/drivers/gpio/gpio-bcm-kona.c @@ -591,7 +591,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Couldn't determine GPIO banks\n"); } - kona_gpio = devm_kzalloc(dev, struct_size(kona_gpio, banks, ret), GFP_KERNEL); + kona_gpio = devm_kzalloc_flex(dev, *kona_gpio, banks, ret); if (!kona_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-bd71815.c b/drivers/gpio/gpio-bd71815.c index afb18a5a9d79c0..18c51a4b0692a6 100644 --- a/drivers/gpio/gpio-bd71815.c +++ b/drivers/gpio/gpio-bd71815.c @@ -137,7 +137,7 @@ static int gpo_bd71815_probe(struct platform_device *pdev) /* The device-tree and regmap come from MFD => use parent for that */ parent = dev->parent; - g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); + g = devm_kzalloc_obj(dev, *g); if (!g) return -ENOMEM; diff --git a/drivers/gpio/gpio-bd71828.c b/drivers/gpio/gpio-bd71828.c index e439dbfffc6265..21cf4f6f133efa 100644 --- a/drivers/gpio/gpio-bd71828.c +++ b/drivers/gpio/gpio-bd71828.c @@ -97,7 +97,7 @@ static int bd71828_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct bd71828_gpio *bdgpio; - bdgpio = devm_kzalloc(dev, sizeof(*bdgpio), GFP_KERNEL); + bdgpio = devm_kzalloc_obj(dev, *bdgpio); if (!bdgpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-bd72720.c b/drivers/gpio/gpio-bd72720.c index c124d964e4cfcb..ed925804c256d8 100644 --- a/drivers/gpio/gpio-bd72720.c +++ b/drivers/gpio/gpio-bd72720.c @@ -254,7 +254,7 @@ static int gpo_bd72720_probe(struct platform_device *pdev) /* The device-tree and regmap come from MFD => use parent for that */ parent = dev->parent; - g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); + g = devm_kzalloc_obj(dev, *g); if (!g) return -ENOMEM; diff --git a/drivers/gpio/gpio-bd73800.c b/drivers/gpio/gpio-bd73800.c index 2be2a885820e25..4dac1858067841 100644 --- a/drivers/gpio/gpio-bd73800.c +++ b/drivers/gpio/gpio-bd73800.c @@ -149,7 +149,7 @@ static int gpo_bd73800_probe(struct platform_device *pdev) /* The device-tree and regmap come from MFD => use parent for that */ parent = dev->parent; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c index f829fc40c02be3..d06062e7e90c8b 100644 --- a/drivers/gpio/gpio-bd9571mwv.c +++ b/drivers/gpio/gpio-bd9571mwv.c @@ -98,7 +98,7 @@ static int bd9571mwv_gpio_probe(struct platform_device *pdev) { struct bd9571mwv_gpio *gpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-blzp1600.c b/drivers/gpio/gpio-blzp1600.c index 0f8c826ba87612..cd5072853cbb29 100644 --- a/drivers/gpio/gpio-blzp1600.c +++ b/drivers/gpio/gpio-blzp1600.c @@ -222,7 +222,7 @@ static int blzp1600_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; @@ -258,7 +258,7 @@ static int blzp1600_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &blzp1600_gpio_irqchip); girq->parent_handler = blzp1600_gpio_irqhandler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c index 44ca798cf832a7..2c4575f2df5acd 100644 --- a/drivers/gpio/gpio-brcmstb.c +++ b/drivers/gpio/gpio-brcmstb.c @@ -513,6 +513,7 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev, out_free_domain: irq_domain_remove(priv->irq_domain); + priv->irq_domain = NULL; return err; } @@ -638,7 +639,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) unsigned long flags = 0; bool need_wakeup_event = false; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); @@ -690,7 +691,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) continue; } - bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); + bank = devm_kzalloc_obj(dev, *bank); if (!bank) { err = -ENOMEM; goto fail; diff --git a/drivers/gpio/gpio-bt8xx.c b/drivers/gpio/gpio-bt8xx.c index f3a2321bc388a4..57b0f05a09a2cd 100644 --- a/drivers/gpio/gpio-bt8xx.c +++ b/drivers/gpio/gpio-bt8xx.c @@ -161,7 +161,7 @@ static int bt8xxgpio_probe(struct pci_dev *dev, if (IS_ERR(mmio)) return PTR_ERR(mmio); - bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL); + bg = devm_kzalloc_obj(&dev->dev, struct bt8xxgpio); if (!bg) return -ENOMEM; diff --git a/drivers/gpio/gpio-by-pinctrl.c b/drivers/gpio/gpio-by-pinctrl.c index f54efd635f139c..3f4cb8da6c2632 100644 --- a/drivers/gpio/gpio-by-pinctrl.c +++ b/drivers/gpio/gpio-by-pinctrl.c @@ -66,7 +66,7 @@ static int pin_control_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct gpio_chip *chip; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c index d7790fc35c2245..6baa5d6cd16756 100644 --- a/drivers/gpio/gpio-cadence.c +++ b/drivers/gpio/gpio-cadence.c @@ -189,7 +189,7 @@ static int cdns_gpio_probe(struct platform_device *pdev) u32 num_gpios = 32; struct clk *clk; - cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL); + cgpio = devm_kzalloc_obj(&pdev->dev, *cgpio); if (!cgpio) return -ENOMEM; @@ -267,9 +267,7 @@ static int cdns_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &cdns_gpio_irqchip); girq->parent_handler = cdns_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) { ret = -ENOMEM; goto err_revert_dir; diff --git a/drivers/gpio/gpio-cgbc.c b/drivers/gpio/gpio-cgbc.c index 84b5ed3c6e22bb..488dc8212a8223 100644 --- a/drivers/gpio/gpio-cgbc.c +++ b/drivers/gpio/gpio-cgbc.c @@ -154,7 +154,7 @@ static int cgbc_gpio_probe(struct platform_device *pdev) struct gpio_chip *chip; int ret; - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c index 24ff2347d59974..663f5400870f1b 100644 --- a/drivers/gpio/gpio-clps711x.c +++ b/drivers/gpio/gpio-clps711x.c @@ -26,7 +26,7 @@ static int clps711x_gpio_probe(struct platform_device *pdev) if ((id < 0) || (id > 4)) return -ENODEV; - gen_gc = devm_kzalloc(&pdev->dev, sizeof(*gen_gc), GFP_KERNEL); + gen_gc = devm_kzalloc_obj(&pdev->dev, *gen_gc); if (!gen_gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-creg-snps.c b/drivers/gpio/gpio-creg-snps.c index 157ab90f5ba8aa..f30ef9948348bf 100644 --- a/drivers/gpio/gpio-creg-snps.c +++ b/drivers/gpio/gpio-creg-snps.c @@ -139,7 +139,7 @@ static int creg_gpio_probe(struct platform_device *pdev) u32 ngpios; int ret; - hcg = devm_kzalloc(dev, sizeof(struct creg_gpio), GFP_KERNEL); + hcg = devm_kzalloc_obj(dev, struct creg_gpio); if (!hcg) return -ENOMEM; diff --git a/drivers/gpio/gpio-cros-ec.c b/drivers/gpio/gpio-cros-ec.c index b48b684d817f24..d06d74bd86d889 100644 --- a/drivers/gpio/gpio-cros-ec.c +++ b/drivers/gpio/gpio-cros-ec.c @@ -107,7 +107,7 @@ static int cros_ec_gpio_init_names(struct cros_ec_device *cros_ec, struct gpio_c const char **names; char *str; - names = devm_kcalloc(gc->parent, gc->ngpio, sizeof(*names), GFP_KERNEL); + names = devm_kzalloc_objs(gc->parent, *names, gc->ngpio); if (!names) return -ENOMEM; gc->names = names; @@ -174,7 +174,7 @@ static int cros_ec_gpio_probe(struct platform_device *pdev) return ngpios; } - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c index ab7fab5b975459..566fba32c53120 100644 --- a/drivers/gpio/gpio-crystalcove.c +++ b/drivers/gpio/gpio-crystalcove.c @@ -340,7 +340,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev) if (irq < 0) return irq; - cg = devm_kzalloc(&pdev->dev, sizeof(*cg), GFP_KERNEL); + cg = devm_kzalloc_obj(&pdev->dev, *cg); if (!cg) return -ENOMEM; diff --git a/drivers/gpio/gpio-cs5535.c b/drivers/gpio/gpio-cs5535.c index 5f5373d86397c0..405471df5a384f 100644 --- a/drivers/gpio/gpio-cs5535.c +++ b/drivers/gpio/gpio-cs5535.c @@ -289,7 +289,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev) int err = -EIO; ulong mask_orig = mask; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index 495f0ee58505a5..54dd51df57c3dc 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c @@ -186,7 +186,7 @@ static int da9052_gpio_probe(struct platform_device *pdev) struct da9052_gpio *gpio; struct da9052_pdata *pdata; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-da9055.c b/drivers/gpio/gpio-da9055.c index 1949a6ea8ec610..32f6f1967a1776 100644 --- a/drivers/gpio/gpio-da9055.c +++ b/drivers/gpio/gpio-da9055.c @@ -130,7 +130,7 @@ static int da9055_gpio_probe(struct platform_device *pdev) struct da9055_gpio *gpio; struct da9055_pdata *pdata; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index fc2b9bef7efc87..303b5409e2844b 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -200,7 +200,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) return -EINVAL; } - chips = devm_kzalloc(dev, sizeof(*chips), GFP_KERNEL); + chips = devm_kzalloc_obj(dev, *chips); if (!chips) return -ENOMEM; @@ -564,10 +564,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) * gpio irqs. Pass the irq bank's corresponding controller to * the chained irq handler. */ - irqdata = devm_kzalloc(&pdev->dev, - sizeof(struct - davinci_gpio_irq_data), - GFP_KERNEL); + irqdata = devm_kzalloc_obj(&pdev->dev, + struct davinci_gpio_irq_data); if (!irqdata) { irq_domain_remove(chips->irq_domain); return -ENOMEM; diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c index aef4345d265e2c..2a56d99d289a36 100644 --- a/drivers/gpio/gpio-dln2.c +++ b/drivers/gpio/gpio-dln2.c @@ -453,7 +453,7 @@ static int dln2_gpio_probe(struct platform_device *pdev) dev_warn(dev, "clamping pins to %d\n", DLN2_GPIO_MAX_PINS); } - dln2 = devm_kzalloc(&pdev->dev, sizeof(*dln2), GFP_KERNEL); + dln2 = devm_kzalloc_obj(&pdev->dev, *dln2); if (!dln2) return -ENOMEM; diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index aa7c08e6070746..80208844895319 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -475,7 +475,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio, struct gpio_irq_chip *girq; int err; - pirq = devm_kzalloc(gpio->dev, sizeof(*pirq), GFP_KERNEL); + pirq = devm_kzalloc_obj(gpio->dev, *pirq); if (!pirq) return; @@ -538,7 +538,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, port->idx = pp->idx; #ifdef CONFIG_PM_SLEEP - port->ctx = devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL); + port->ctx = devm_kzalloc_obj(gpio->dev, *port->ctx); if (!port->ctx) return -ENOMEM; #endif @@ -615,7 +615,7 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) if (nports == 0) return ERR_PTR(-ENODEV); - pdata = devm_kzalloc(dev, struct_size(pdata, properties, nports), GFP_KERNEL); + pdata = devm_kzalloc_flex(dev, *pdata, properties, nports); if (!pdata) return ERR_PTR(-ENOMEM); @@ -741,7 +741,7 @@ static int dwapb_gpio_probe(struct platform_device *pdev) if (IS_ERR(pdata)) return PTR_ERR(pdata); - gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, ports, pdata->nports), GFP_KERNEL); + gpio = devm_kzalloc_flex(&pdev->dev, *gpio, ports, pdata->nports); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c index 86eb9624d38acc..f0ce3c1c765438 100644 --- a/drivers/gpio/gpio-eic-sprd.c +++ b/drivers/gpio/gpio-eic-sprd.c @@ -617,7 +617,7 @@ static int sprd_eic_probe(struct platform_device *pdev) return -EINVAL; } - sprd_eic = devm_kzalloc(dev, sizeof(*sprd_eic), GFP_KERNEL); + sprd_eic = devm_kzalloc_obj(dev, *sprd_eic); if (!sprd_eic) return -ENOMEM; diff --git a/drivers/gpio/gpio-elkhartlake.c b/drivers/gpio/gpio-elkhartlake.c index b96e7928b6e59a..da8010fbd53f9b 100644 --- a/drivers/gpio/gpio-elkhartlake.c +++ b/drivers/gpio/gpio-elkhartlake.c @@ -32,7 +32,7 @@ static int ehl_gpio_probe(struct auxiliary_device *adev, const struct auxiliary_ if (!data) return -ENODATA; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c index a214b067272657..a66e8af619ef4e 100644 --- a/drivers/gpio/gpio-em.c +++ b/drivers/gpio/gpio-em.c @@ -273,7 +273,7 @@ static int em_gio_probe(struct platform_device *pdev) unsigned int ngpios; int irq[2], ret; - p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/gpio/gpio-en7523.c b/drivers/gpio/gpio-en7523.c index 14ad3ca9e623ec..b1a50f4387a9d7 100644 --- a/drivers/gpio/gpio-en7523.c +++ b/drivers/gpio/gpio-en7523.c @@ -79,7 +79,7 @@ static int airoha_gpio_probe(struct platform_device *pdev) struct airoha_gpio_ctrl *ctrl; int err; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c index 8784e433e1ffbf..9beff7d9bbff9e 100644 --- a/drivers/gpio/gpio-ep93xx.c +++ b/drivers/gpio/gpio-ep93xx.c @@ -282,7 +282,7 @@ static int ep93xx_setup_irqs(struct platform_device *pdev, return PTR_ERR(intr); gc->set_config = ep93xx_gpio_set_config; - egc->eic = devm_kzalloc(dev, sizeof(*egc->eic), GFP_KERNEL); + egc->eic = devm_kzalloc_obj(dev, *egc->eic); if (!egc->eic) return -ENOMEM; @@ -292,8 +292,8 @@ static int ep93xx_setup_irqs(struct platform_device *pdev, if (girq->num_parents == 0) return -EINVAL; - girq->parents = devm_kcalloc(dev, girq->num_parents, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; @@ -337,7 +337,7 @@ static int ep93xx_gpio_probe(struct platform_device *pdev) void __iomem *dir; int ret; - egc = devm_kzalloc(&pdev->dev, sizeof(*egc), GFP_KERNEL); + egc = devm_kzalloc_obj(&pdev->dev, *egc); if (!egc) return -ENOMEM; diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index f629cc526f3ee7..ad7a653b061794 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -173,7 +173,7 @@ static int gpio_exar_probe(struct platform_device *pdev) if (ret) return ret; - exar_gpio = devm_kzalloc(dev, sizeof(*exar_gpio), GFP_KERNEL); + exar_gpio = devm_kzalloc_obj(dev, *exar_gpio); if (!exar_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-f7188x.c b/drivers/gpio/gpio-f7188x.c index fb007b97872902..37138139302dbb 100644 --- a/drivers/gpio/gpio-f7188x.c +++ b/drivers/gpio/gpio-f7188x.c @@ -459,7 +459,7 @@ static int f7188x_gpio_probe(struct platform_device *pdev) struct f7188x_sio *sio = dev_get_platdata(&pdev->dev); struct f7188x_gpio_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-ftgpio010.c b/drivers/gpio/gpio-ftgpio010.c index 11e6907c3b5401..d98aec5f195d07 100644 --- a/drivers/gpio/gpio-ftgpio010.c +++ b/drivers/gpio/gpio-ftgpio010.c @@ -242,7 +242,7 @@ static int ftgpio_gpio_probe(struct platform_device *pdev) int irq; int ret; - g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); + g = devm_kzalloc_obj(dev, *g); if (!g) return -ENOMEM; @@ -291,8 +291,7 @@ static int ftgpio_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &ftgpio_irq_chip); girq->parent_handler = ftgpio_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c index d0c8e16f1d48f4..1ce73601664918 100644 --- a/drivers/gpio/gpio-ge.c +++ b/drivers/gpio/gpio-ge.c @@ -58,7 +58,7 @@ static int __init gef_gpio_probe(struct platform_device *pdev) void __iomem *regs; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-graniterapids.c b/drivers/gpio/gpio-graniterapids.c index 2d0fe3abd5e0fe..da9716d504f504 100644 --- a/drivers/gpio/gpio-graniterapids.c +++ b/drivers/gpio/gpio-graniterapids.c @@ -320,7 +320,7 @@ static int gnr_gpio_probe(struct platform_device *pdev) int irq, ret; u32 offset; - priv = devm_kzalloc(dev, struct_size(priv, pad_backup, num_backup_pins), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, pad_backup, num_backup_pins); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c index e4fa84e227262b..0fa873d3810e49 100644 --- a/drivers/gpio/gpio-grgpio.c +++ b/drivers/gpio/gpio-grgpio.c @@ -336,7 +336,7 @@ static int grgpio_probe(struct platform_device *ofdev) int size; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-gw-pld.c b/drivers/gpio/gpio-gw-pld.c index bf1f91c3c4a8b9..6621a0706cef99 100644 --- a/drivers/gpio/gpio-gw-pld.c +++ b/drivers/gpio/gpio-gw-pld.c @@ -73,7 +73,7 @@ static int gw_pld_probe(struct i2c_client *client) struct gw_pld *gw; int ret; - gw = devm_kzalloc(dev, sizeof(*gw), GFP_KERNEL); + gw = devm_kzalloc_obj(dev, *gw); if (!gw) return -ENOMEM; diff --git a/drivers/gpio/gpio-hisi.c b/drivers/gpio/gpio-hisi.c index 42d41cf87ac7f8..5d3b5286c4fc15 100644 --- a/drivers/gpio/gpio-hisi.c +++ b/drivers/gpio/gpio-hisi.c @@ -279,7 +279,7 @@ static int hisi_gpio_probe(struct platform_device *pdev) if (WARN_ON(port_num != 1)) return -ENODEV; - hisi_gpio = devm_kzalloc(dev, sizeof(*hisi_gpio), GFP_KERNEL); + hisi_gpio = devm_kzalloc_obj(dev, *hisi_gpio); if (!hisi_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-hlwd.c b/drivers/gpio/gpio-hlwd.c index 043ce5ef3b07e9..9b6e97f9acbbfa 100644 --- a/drivers/gpio/gpio-hlwd.c +++ b/drivers/gpio/gpio-hlwd.c @@ -226,7 +226,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev) u32 ngpios; int res; - hlwd = devm_kzalloc(&pdev->dev, sizeof(*hlwd), GFP_KERNEL); + hlwd = devm_kzalloc_obj(&pdev->dev, *hlwd); if (!hlwd) return -ENOMEM; @@ -289,9 +289,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &hlwd_gpio_irq_chip); girq->parent_handler = hlwd_gpio_irqhandler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = hlwd->irq; diff --git a/drivers/gpio/gpio-htc-egpio.c b/drivers/gpio/gpio-htc-egpio.c index 25a4d4494f3c3a..18ac57e7ee43bc 100644 --- a/drivers/gpio/gpio-htc-egpio.c +++ b/drivers/gpio/gpio-htc-egpio.c @@ -271,7 +271,7 @@ static int __init egpio_probe(struct platform_device *pdev) int ret; /* Initialize ei data structure. */ - ei = devm_kzalloc(&pdev->dev, struct_size(ei, chip, pdata->num_chips), GFP_KERNEL); + ei = devm_kzalloc_flex(&pdev->dev, *ei, chip, pdata->num_chips); if (!ei) return -ENOMEM; diff --git a/drivers/gpio/gpio-idio-16.c b/drivers/gpio/gpio-idio-16.c index 9ac967c6b430da..b9aa8bb9347ae4 100644 --- a/drivers/gpio/gpio-idio-16.c +++ b/drivers/gpio/gpio-idio-16.c @@ -119,12 +119,12 @@ int devm_idio_16_regmap_register(struct device *const dev, if (!config->regmap_irqs) return -EINVAL; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; data->map = config->map; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-idt3243x.c b/drivers/gpio/gpio-idt3243x.c index 031b5c127fd6f7..43e5e905fb4390 100644 --- a/drivers/gpio/gpio-idt3243x.c +++ b/drivers/gpio/gpio-idt3243x.c @@ -136,7 +136,7 @@ static int idt_gpio_probe(struct platform_device *pdev) int ret; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -177,9 +177,8 @@ static int idt_gpio_probe(struct platform_device *pdev) girq->init_hw = idt_gpio_irq_init_hw; girq->parent_handler = idt_gpio_dispatch; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, girq->num_parents, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; diff --git a/drivers/gpio/gpio-imx-scu.c b/drivers/gpio/gpio-imx-scu.c index 0a75afecf9f87c..fee133c6812bf0 100644 --- a/drivers/gpio/gpio-imx-scu.c +++ b/drivers/gpio/gpio-imx-scu.c @@ -82,7 +82,7 @@ static int imx_scu_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-it87.c b/drivers/gpio/gpio-it87.c index 699325129a7de4..2585253d36ead9 100644 --- a/drivers/gpio/gpio-it87.c +++ b/drivers/gpio/gpio-it87.c @@ -362,8 +362,7 @@ static int __init it87_gpio_init(void) */ labels = kcalloc(it87_gpio->chip.ngpio, sizeof("it87_gpXY"), GFP_KERNEL); - labels_table = kcalloc(it87_gpio->chip.ngpio, sizeof(*labels_table), - GFP_KERNEL); + labels_table = kzalloc_objs(*labels_table, it87_gpio->chip.ngpio); if (!labels || !labels_table) { rc = -ENOMEM; diff --git a/drivers/gpio/gpio-ixp4xx.c b/drivers/gpio/gpio-ixp4xx.c index 669b139cd499b6..2c9fb2baf7d060 100644 --- a/drivers/gpio/gpio-ixp4xx.c +++ b/drivers/gpio/gpio-ixp4xx.c @@ -216,7 +216,7 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) u32 val; int ret; - g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); + g = devm_kzalloc_obj(dev, *g); if (!g) return -ENOMEM; g->dev = dev; diff --git a/drivers/gpio/gpio-janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c index b0c4a3346e7d7d..36eda7f9b45ab1 100644 --- a/drivers/gpio/gpio-janz-ttl.c +++ b/drivers/gpio/gpio-janz-ttl.c @@ -152,7 +152,7 @@ static int ttl_probe(struct platform_device *pdev) return -ENXIO; } - mod = devm_kzalloc(&pdev->dev, sizeof(*mod), GFP_KERNEL); + mod = devm_kzalloc_obj(&pdev->dev, *mod); if (!mod) return -ENOMEM; diff --git a/drivers/gpio/gpio-kempld.c b/drivers/gpio/gpio-kempld.c index 5a63df3ea5fa77..490d9db5fd96a1 100644 --- a/drivers/gpio/gpio-kempld.c +++ b/drivers/gpio/gpio-kempld.c @@ -396,7 +396,7 @@ static int kempld_gpio_probe(struct platform_device *pdev) return -ENODEV; } - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-latch.c b/drivers/gpio/gpio-latch.c index 88757402ea96e2..a22e9676e5892f 100644 --- a/drivers/gpio/gpio-latch.c +++ b/drivers/gpio/gpio-latch.c @@ -141,7 +141,7 @@ static int gpio_latch_probe(struct platform_device *pdev) struct gpio_latch_priv *priv; unsigned int n_latches; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-ljca.c b/drivers/gpio/gpio-ljca.c index f32d1d237795b8..067e5c472abdd7 100644 --- a/drivers/gpio/gpio-ljca.c +++ b/drivers/gpio/gpio-ljca.c @@ -404,7 +404,7 @@ static int ljca_gpio_probe(struct auxiliary_device *auxdev, struct gpio_irq_chip *girq; int ret; - ljca_gpio = devm_kzalloc(&auxdev->dev, sizeof(*ljca_gpio), GFP_KERNEL); + ljca_gpio = devm_kzalloc_obj(&auxdev->dev, *ljca_gpio); if (!ljca_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-logicvc.c b/drivers/gpio/gpio-logicvc.c index cb9dbcc290ad16..4137cd18bf7f9e 100644 --- a/drivers/gpio/gpio-logicvc.c +++ b/drivers/gpio/gpio-logicvc.c @@ -93,7 +93,7 @@ static int logicvc_gpio_probe(struct platform_device *pdev) struct logicvc_gpio *logicvc; int ret; - logicvc = devm_kzalloc(dev, sizeof(*logicvc), GFP_KERNEL); + logicvc = devm_kzalloc_obj(dev, *logicvc); if (!logicvc) return -ENOMEM; diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c index 0fdf15faa344d2..fa975a42539b60 100644 --- a/drivers/gpio/gpio-loongson-64bit.c +++ b/drivers/gpio/gpio-loongson-64bit.c @@ -261,8 +261,8 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev, gpio_irq_chip_set_chip(&chip->irq, data->girqchip); chip->irq.num_parents = data->intr_num; - chip->irq.parents = devm_kcalloc(&pdev->dev, data->intr_num, - sizeof(*chip->irq.parents), GFP_KERNEL); + chip->irq.parents = devm_kzalloc_objs(&pdev->dev, *chip->irq.parents, + data->intr_num); if (!chip->irq.parents) return -ENOMEM; @@ -336,7 +336,7 @@ static int loongson_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct reset_control *rst; - lgpio = devm_kzalloc(dev, sizeof(*lgpio), GFP_KERNEL); + lgpio = devm_kzalloc_obj(dev, *lgpio); if (!lgpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-loongson.c b/drivers/gpio/gpio-loongson.c index f3e0559f969d5c..042e3fb0a03379 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c @@ -98,7 +98,7 @@ static int loongson_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; struct device *dev = &pdev->dev; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-loongson1.c b/drivers/gpio/gpio-loongson1.c index 9750a7a1750817..006329270e3c36 100644 --- a/drivers/gpio/gpio-loongson1.c +++ b/drivers/gpio/gpio-loongson1.c @@ -51,7 +51,7 @@ static int ls1x_gpio_probe(struct platform_device *pdev) struct ls1x_gpio_chip *ls1x_gc; int ret; - ls1x_gc = devm_kzalloc(dev, sizeof(*ls1x_gc), GFP_KERNEL); + ls1x_gc = devm_kzalloc_obj(dev, *ls1x_gc); if (!ls1x_gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-lp3943.c b/drivers/gpio/gpio-lp3943.c index e8e00daff7df05..c171da92c53418 100644 --- a/drivers/gpio/gpio-lp3943.c +++ b/drivers/gpio/gpio-lp3943.c @@ -195,8 +195,7 @@ static int lp3943_gpio_probe(struct platform_device *pdev) struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent); struct lp3943_gpio *lp3943_gpio; - lp3943_gpio = devm_kzalloc(&pdev->dev, sizeof(*lp3943_gpio), - GFP_KERNEL); + lp3943_gpio = devm_kzalloc_obj(&pdev->dev, *lp3943_gpio); if (!lp3943_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-lp873x.c b/drivers/gpio/gpio-lp873x.c index 0d1bd9df265a44..67ec9bee1331dc 100644 --- a/drivers/gpio/gpio-lp873x.c +++ b/drivers/gpio/gpio-lp873x.c @@ -136,7 +136,7 @@ static int lp873x_gpio_probe(struct platform_device *pdev) struct lp873x_gpio *gpio; int ret; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-lp87565.c b/drivers/gpio/gpio-lp87565.c index 3ac78f2b0fa700..822f1a02b3d550 100644 --- a/drivers/gpio/gpio-lp87565.c +++ b/drivers/gpio/gpio-lp87565.c @@ -152,7 +152,7 @@ static int lp87565_gpio_probe(struct platform_device *pdev) struct lp87565 *lp87565; int ret; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-lpc18xx.c b/drivers/gpio/gpio-lpc18xx.c index 37a2342eb2e600..2a1e083cd92d9f 100644 --- a/drivers/gpio/gpio-lpc18xx.c +++ b/drivers/gpio/gpio-lpc18xx.c @@ -225,7 +225,7 @@ static int lpc18xx_gpio_pin_ic_probe(struct lpc18xx_gpio_chip *gc) if (!parent_domain) return -ENXIO; - ic = devm_kzalloc(dev, sizeof(*ic), GFP_KERNEL); + ic = devm_kzalloc_obj(dev, *ic); if (!ic) return -ENOMEM; @@ -340,7 +340,7 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev) int index, ret; struct clk *clk; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-ltc4283.c b/drivers/gpio/gpio-ltc4283.c index 88aa6216006a90..8045549010780c 100644 --- a/drivers/gpio/gpio-ltc4283.c +++ b/drivers/gpio/gpio-ltc4283.c @@ -173,7 +173,7 @@ static int ltc4283_gpio_probe(struct auxiliary_device *adev, struct ltc4283_gpio *st; struct gpio_chip *gc; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/gpio/gpio-macsmc.c b/drivers/gpio/gpio-macsmc.c index b0952d066a9dd0..bb6dc5db048731 100644 --- a/drivers/gpio/gpio-macsmc.c +++ b/drivers/gpio/gpio-macsmc.c @@ -239,7 +239,7 @@ static int macsmc_gpio_probe(struct platform_device *pdev) smc_key key; int ret; - smcgp = devm_kzalloc(&pdev->dev, sizeof(*smcgp), GFP_KERNEL); + smcgp = devm_kzalloc_obj(&pdev->dev, *smcgp); if (!smcgp) return -ENOMEM; diff --git a/drivers/gpio/gpio-madera.c b/drivers/gpio/gpio-madera.c index 551faf9655b23f..c384e567341af7 100644 --- a/drivers/gpio/gpio-madera.c +++ b/drivers/gpio/gpio-madera.c @@ -121,8 +121,7 @@ static int madera_gpio_probe(struct platform_device *pdev) struct madera_gpio *madera_gpio; int ret; - madera_gpio = devm_kzalloc(&pdev->dev, sizeof(*madera_gpio), - GFP_KERNEL); + madera_gpio = devm_kzalloc_obj(&pdev->dev, *madera_gpio); if (!madera_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-max3191x.c b/drivers/gpio/gpio-max3191x.c index 6e6504ab740a43..7dced73143cb06 100644 --- a/drivers/gpio/gpio-max3191x.c +++ b/drivers/gpio/gpio-max3191x.c @@ -347,7 +347,7 @@ static int max3191x_probe(struct spi_device *spi) struct max3191x_chip *max3191x; int n, ret; - max3191x = devm_kzalloc(dev, sizeof(*max3191x), GFP_KERNEL); + max3191x = devm_kzalloc_obj(dev, *max3191x); if (!max3191x) return -ENOMEM; spi_set_drvdata(spi, max3191x); diff --git a/drivers/gpio/gpio-max7300.c b/drivers/gpio/gpio-max7300.c index 62f2434c0d79b6..6a7b013273cce8 100644 --- a/drivers/gpio/gpio-max7300.c +++ b/drivers/gpio/gpio-max7300.c @@ -36,7 +36,7 @@ static int max7300_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, struct max7301); if (!ts) return -ENOMEM; diff --git a/drivers/gpio/gpio-max7301.c b/drivers/gpio/gpio-max7301.c index 11813f41d4609c..6955291e75bf0e 100644 --- a/drivers/gpio/gpio-max7301.c +++ b/drivers/gpio/gpio-max7301.c @@ -52,7 +52,7 @@ static int max7301_probe(struct spi_device *spi) if (ret < 0) return ret; - ts = devm_kzalloc(&spi->dev, sizeof(struct max7301), GFP_KERNEL); + ts = devm_kzalloc_obj(&spi->dev, struct max7301); if (!ts) return -ENOMEM; diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index 24c67c91295490..d595efacd83a41 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c @@ -604,7 +604,7 @@ static struct max732x_platform_data *of_gpio_max732x(struct device *dev) { struct max732x_platform_data *pdata; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -634,7 +634,7 @@ static int max732x_probe(struct i2c_client *client) return -EINVAL; } - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (chip == NULL) return -ENOMEM; chip->client = client; diff --git a/drivers/gpio/gpio-max7360.c b/drivers/gpio/gpio-max7360.c index 6755d58c453444..e02f4f2d8cca2e 100644 --- a/drivers/gpio/gpio-max7360.c +++ b/drivers/gpio/gpio-max7360.c @@ -170,7 +170,7 @@ static int max7360_gpio_probe(struct platform_device *pdev) "Failed to get IRQ\n"); /* Create custom IRQ configuration. */ - irq_chip = devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL); + irq_chip = devm_kzalloc_obj(dev, *irq_chip); if (!irq_chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c index 2bf3b55a61b5e5..2108ce0442798b 100644 --- a/drivers/gpio/gpio-max77620.c +++ b/drivers/gpio/gpio-max77620.c @@ -316,7 +316,7 @@ static int max77620_gpio_probe(struct platform_device *pdev) gpio_irq = ret; - mgpio = devm_kzalloc(&pdev->dev, sizeof(*mgpio), GFP_KERNEL); + mgpio = devm_kzalloc_obj(&pdev->dev, *mgpio); if (!mgpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-max77650.c b/drivers/gpio/gpio-max77650.c index 4540da4c1418de..1ee183807b1d58 100644 --- a/drivers/gpio/gpio-max77650.c +++ b/drivers/gpio/gpio-max77650.c @@ -145,7 +145,7 @@ static int max77650_gpio_probe(struct platform_device *pdev) parent = dev->parent; i2c = to_i2c_client(parent); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-max77759.c b/drivers/gpio/gpio-max77759.c index da3c77dd574e4f..99dacf800cdbe0 100644 --- a/drivers/gpio/gpio-max77759.c +++ b/drivers/gpio/gpio-max77759.c @@ -435,7 +435,7 @@ static int max77759_gpio_probe(struct platform_device *pdev) struct gpio_irq_chip *girq; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c index 78bcae130e0e8b..14707f2170a1fc 100644 --- a/drivers/gpio/gpio-mb86s7x.c +++ b/drivers/gpio/gpio-mb86s7x.c @@ -158,7 +158,7 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) struct clk *clk; int ret; - gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL); + gchip = devm_kzalloc_obj(&pdev->dev, *gchip); if (gchip == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-mc33880.c b/drivers/gpio/gpio-mc33880.c index 9a40e9579e951a..d48719660eaefa 100644 --- a/drivers/gpio/gpio-mc33880.c +++ b/drivers/gpio/gpio-mc33880.c @@ -92,7 +92,7 @@ static int mc33880_probe(struct spi_device *spi) if (ret < 0) return ret; - mc = devm_kzalloc(&spi->dev, sizeof(struct mc33880), GFP_KERNEL); + mc = devm_kzalloc_obj(&spi->dev, struct mc33880); if (!mc) return -ENOMEM; diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c index f51e7517f551b2..f4936c2eec3d0a 100644 --- a/drivers/gpio/gpio-menz127.c +++ b/drivers/gpio/gpio-menz127.c @@ -147,8 +147,7 @@ static int men_z127_probe(struct mcb_device *mdev, int ret; unsigned long sz; - men_z127_gpio = devm_kzalloc(dev, sizeof(struct men_z127_gpio), - GFP_KERNEL); + men_z127_gpio = devm_kzalloc_obj(dev, struct men_z127_gpio); if (!men_z127_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c index 4335a5d8e4f6d5..b926e564d82b26 100644 --- a/drivers/gpio/gpio-merrifield.c +++ b/drivers/gpio/gpio-merrifield.c @@ -88,7 +88,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id /* Release the IO mapping, since we already get the info from BAR1 */ pcim_iounmap_region(pdev, 1); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index 391188c0f2c2bd..28df539c271078 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c @@ -434,7 +434,7 @@ static int ioh_gpio_probe(struct pci_dev *pdev, return -ENOMEM; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-mlxbf.c b/drivers/gpio/gpio-mlxbf.c index a18fedbc463e67..0c2f607a1b1d53 100644 --- a/drivers/gpio/gpio-mlxbf.c +++ b/drivers/gpio/gpio-mlxbf.c @@ -56,7 +56,7 @@ static int mlxbf_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret; - gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL); + gs = devm_kzalloc_obj(&pdev->dev, *gs); if (!gs) return -ENOMEM; diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c index 4e5c5d196a5003..b3b107c07cbec5 100644 --- a/drivers/gpio/gpio-mlxbf2.c +++ b/drivers/gpio/gpio-mlxbf2.c @@ -356,7 +356,7 @@ mlxbf2_gpio_probe(struct platform_device *pdev) name = dev_name(dev); - gs = devm_kzalloc(dev, sizeof(*gs), GFP_KERNEL); + gs = devm_kzalloc_obj(dev, *gs); if (!gs) return -ENOMEM; diff --git a/drivers/gpio/gpio-mlxbf3.c b/drivers/gpio/gpio-mlxbf3.c index 929f64c5140a54..3a39d273f2b93d 100644 --- a/drivers/gpio/gpio-mlxbf3.c +++ b/drivers/gpio/gpio-mlxbf3.c @@ -188,7 +188,7 @@ static int mlxbf3_gpio_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret, irq; - gs = devm_kzalloc(dev, sizeof(*gs), GFP_KERNEL); + gs = devm_kzalloc_obj(dev, *gs); if (!gs) return -ENOMEM; diff --git a/drivers/gpio/gpio-mm-lantiq.c b/drivers/gpio/gpio-mm-lantiq.c index 1bd98c50a459ea..37f8a5cc779481 100644 --- a/drivers/gpio/gpio-mm-lantiq.c +++ b/drivers/gpio/gpio-mm-lantiq.c @@ -103,7 +103,7 @@ static int ltq_mm_probe(struct platform_device *pdev) struct ltq_mm *chip; u32 shadow; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index 0709ffaab4dec3..6d4b659fbc26fd 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c @@ -826,7 +826,7 @@ static int gpio_mmio_pdev_probe(struct platform_device *pdev) if (IS_ERR(dirin)) return PTR_ERR(dirin); - gen_gc = devm_kzalloc(&pdev->dev, sizeof(*gen_gc), GFP_KERNEL); + gen_gc = devm_kzalloc_obj(&pdev->dev, *gen_gc); if (!gen_gc) return -ENOMEM; diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 1c6a2f3414f16c..0e37d2369b782e 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -381,7 +381,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, if (!name) return; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return; @@ -436,7 +436,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv) name = dev_name(dev); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -460,8 +460,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->request = gpio_mockup_request; gc->free = gpio_mockup_free; - chip->lines = devm_kcalloc(dev, gc->ngpio, - sizeof(*chip->lines), GFP_KERNEL); + chip->lines = devm_kzalloc_objs(dev, *chip->lines, gc->ngpio); if (!chip->lines) return -ENOMEM; diff --git a/drivers/gpio/gpio-moxtet.c b/drivers/gpio/gpio-moxtet.c index 4eb9f1a2779b22..f86c4f9e0b909f 100644 --- a/drivers/gpio/gpio-moxtet.c +++ b/drivers/gpio/gpio-moxtet.c @@ -125,7 +125,7 @@ static int moxtet_gpio_probe(struct device *dev) return -ENOTSUPP; } - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mpc5200.c b/drivers/gpio/gpio-mpc5200.c index 00f209157fd0f0..4d0781eac9b629 100644 --- a/drivers/gpio/gpio-mpc5200.c +++ b/drivers/gpio/gpio-mpc5200.c @@ -141,7 +141,7 @@ static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev) struct gpio_chip *gc; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -303,7 +303,7 @@ static int mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev) struct mpc52xx_gpio __iomem *regs; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c index a6868f6738315a..312250deb763c3 100644 --- a/drivers/gpio/gpio-mpc8xxx.c +++ b/drivers/gpio/gpio-mpc8xxx.c @@ -319,6 +319,14 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = { {} }; +static void mpc8xxx_irq_domain_remove(void *data) +{ + struct mpc8xxx_gpio_chip *mpc8xxx_gc = data; + + if (mpc8xxx_gc->irq) + irq_domain_remove(mpc8xxx_gc->irq); +} + static int mpc8xxx_probe(struct platform_device *pdev) { const struct mpc8xxx_gpio_devtype *devtype = NULL; @@ -329,7 +337,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) struct gpio_chip *gc; int ret; - mpc8xxx_gc = devm_kzalloc(dev, sizeof(*mpc8xxx_gc), GFP_KERNEL); + mpc8xxx_gc = devm_kzalloc_obj(dev, *mpc8xxx_gc); if (!mpc8xxx_gc) return -ENOMEM; @@ -405,6 +413,11 @@ static int mpc8xxx_probe(struct platform_device *pdev) mpc8xxx_gc->regs + GPIO_DIR); } + /* GPIO chip cleanup still needs the IRQ domain. */ + ret = devm_add_action_or_reset(dev, mpc8xxx_irq_domain_remove, mpc8xxx_gc); + if (ret) + return ret; + ret = devm_gpiochip_add_data(dev, gc, mpc8xxx_gc); if (ret) { dev_err(dev, @@ -437,7 +450,7 @@ static int mpc8xxx_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "failed to devm_request_irq(%d), ret = %d\n", mpc8xxx_gc->irqn, ret); - goto err; + return ret; } ret = devm_device_init_wakeup(dev); @@ -445,19 +458,14 @@ static int mpc8xxx_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Failed to init wakeup\n"); return 0; -err: - irq_domain_remove(mpc8xxx_gc->irq); - return ret; } static void mpc8xxx_remove(struct platform_device *pdev) { struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev); - if (mpc8xxx_gc->irq) { + if (mpc8xxx_gc->irq) irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL); - irq_domain_remove(mpc8xxx_gc->irq); - } } static int mpc8xxx_suspend(struct device *dev) diff --git a/drivers/gpio/gpio-mpfs.c b/drivers/gpio/gpio-mpfs.c index 7f0751d7b1c4bf..cb48368d5a4ac7 100644 --- a/drivers/gpio/gpio-mpfs.c +++ b/drivers/gpio/gpio-mpfs.c @@ -138,6 +138,8 @@ static int mpfs_gpio_irq_set_type(struct irq_data *data, unsigned int type) case IRQ_TYPE_LEVEL_LOW: interrupt_type = MPFS_GPIO_TYPE_INT_LEVEL_LOW; break; + default: + return -EINVAL; } regmap_update_bits(mpfs_gpio->regs, MPFS_GPIO_CTRL(gpio_index), @@ -208,7 +210,7 @@ static int mpfs_gpio_probe(struct platform_device *pdev) void __iomem *base; int ngpios, nirqs, ret; - mpfs_gpio = devm_kzalloc(dev, sizeof(*mpfs_gpio), GFP_KERNEL); + mpfs_gpio = devm_kzalloc_obj(dev, *mpfs_gpio); if (!mpfs_gpio) return -ENOMEM; @@ -253,8 +255,8 @@ static int mpfs_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &mpfs_gpio_irqchip); girq->num_parents = nirqs; - girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c index 61c5ca96314b7b..a16b6875b2e20c 100644 --- a/drivers/gpio/gpio-mpsse.c +++ b/drivers/gpio/gpio-mpsse.c @@ -602,7 +602,7 @@ static int gpio_mpsse_probe(struct usb_interface *interface, struct mpsse_quirk *quirk = (void *)id->driver_info; dev = &interface->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-msc313.c b/drivers/gpio/gpio-msc313.c index 7345afdc78de31..45227413db584d 100644 --- a/drivers/gpio/gpio-msc313.c +++ b/drivers/gpio/gpio-msc313.c @@ -631,7 +631,7 @@ static int msc313_gpio_probe(struct platform_device *pdev) if (!parent_domain) return -ENODEV; - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; @@ -647,7 +647,7 @@ static int msc313_gpio_probe(struct platform_device *pdev) platform_set_drvdata(pdev, gpio); - gpiochip = devm_kzalloc(dev, sizeof(*gpiochip), GFP_KERNEL); + gpiochip = devm_kzalloc_obj(dev, *gpiochip); if (!gpiochip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index a86f6b1060fc8f..e6a7f98656c824 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c @@ -450,7 +450,7 @@ mt7621_gpio_probe(struct platform_device *pdev) int i; int ret; - mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); + mtk = devm_kzalloc_obj(dev, *mtk); if (!mtk) return -ENOMEM; diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c index 267e6d5bacd0d1..2591239b1956bb 100644 --- a/drivers/gpio/gpio-mvebu.c +++ b/drivers/gpio/gpio-mvebu.c @@ -603,6 +603,7 @@ static const struct regmap_config mvebu_gpio_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, + .use_raw_spinlock = true, }; static const struct regmap_config mvebu_gpio_percpu_regmap_config = { @@ -610,6 +611,7 @@ static const struct regmap_config mvebu_gpio_percpu_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, + .use_raw_spinlock = true, }; static const struct regmap_config mvebu_pwm_regmap_config = { @@ -1200,8 +1202,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev) have_irqs = err != 0; - mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), - GFP_KERNEL); + mvchip = devm_kzalloc_obj(&pdev->dev, struct mvebu_gpio_chip); if (!mvchip) return -ENOMEM; diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 32ded7b548fb77..7dabe8073dc657 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c @@ -425,7 +425,7 @@ static int mxc_gpio_probe(struct platform_device *pdev) int irq_base; int err; - port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(&pdev->dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c index 900315aba85ad1..09e16ce6a9fa5b 100644 --- a/drivers/gpio/gpio-mxs.c +++ b/drivers/gpio/gpio-mxs.c @@ -266,7 +266,7 @@ static int mxs_gpio_probe(struct platform_device *pdev) int irq_base; int err; - port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(&pdev->dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/gpio/gpio-nct6694.c b/drivers/gpio/gpio-nct6694.c index a38add1cde293c..9d51bf52e99af9 100644 --- a/drivers/gpio/gpio-nct6694.c +++ b/drivers/gpio/gpio-nct6694.c @@ -398,7 +398,7 @@ static int nct6694_gpio_probe(struct platform_device *pdev) int ret, i; char **names; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c index 208fed631975ce..dfb74a05c965c8 100644 --- a/drivers/gpio/gpio-nomadik.c +++ b/drivers/gpio/gpio-nomadik.c @@ -545,7 +545,7 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode, } #endif - nmk_chip = devm_kzalloc(dev, sizeof(*nmk_chip), GFP_KERNEL); + nmk_chip = devm_kzalloc_obj(dev, *nmk_chip); if (!nmk_chip) { ret = -ENOMEM; goto err_put_pdev; diff --git a/drivers/gpio/gpio-novalake-events.c b/drivers/gpio/gpio-novalake-events.c index b3bf0038f84aae..29c226da439b6e 100644 --- a/drivers/gpio/gpio-novalake-events.c +++ b/drivers/gpio/gpio-novalake-events.c @@ -266,7 +266,7 @@ static int nvl_gpio_probe(struct platform_device *pdev) if (!regs) return -ENOMEM; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; raw_spin_lock_init(&priv->lock); diff --git a/drivers/gpio/gpio-npcm-sgpio.c b/drivers/gpio/gpio-npcm-sgpio.c index 83c77a2c0623af..703016e08fff85 100644 --- a/drivers/gpio/gpio-npcm-sgpio.c +++ b/drivers/gpio/gpio-npcm-sgpio.c @@ -503,7 +503,7 @@ static int npcm_sgpio_probe(struct platform_device *pdev) int rc; u32 nin_gpios, nout_gpios; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-octeon.c b/drivers/gpio/gpio-octeon.c index 777e20c608dc7a..8b166c09fa5c2b 100644 --- a/drivers/gpio/gpio-octeon.c +++ b/drivers/gpio/gpio-octeon.c @@ -88,7 +88,7 @@ static int octeon_gpio_probe(struct platform_device *pdev) void __iomem *reg_base; int err = 0; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; chip = &gpio->chip; diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index a9b9a3d9631e29..585c2784bb7552 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -813,8 +813,11 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) { struct gpio_bank *bank = gpiochip_get_data(chip); unsigned long flags; + int ret; - pm_runtime_get_sync(chip->parent); + ret = pm_runtime_resume_and_get(chip->parent); + if (ret < 0) + return ret; raw_spin_lock_irqsave(&bank->lock, flags); omap_enable_gpio_module(bank, offset); @@ -1401,7 +1404,7 @@ static int omap_gpio_probe(struct platform_device *pdev) if (!pdata) return -EINVAL; - bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); + bank = devm_kzalloc_obj(dev, *bank); if (!bank) return -ENOMEM; @@ -1459,7 +1462,13 @@ static int omap_gpio_probe(struct platform_device *pdev) platform_set_drvdata(pdev, bank); pm_runtime_enable(dev); - pm_runtime_get_sync(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) { + pm_runtime_disable(dev); + if (bank->dbck_flag) + clk_unprepare(bank->dbck); + return ret; + } if (bank->is_mpuio) omap_mpuio_init(bank); diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c index e64ee048771852..c3cf2e88576c19 100644 --- a/drivers/gpio/gpio-palmas.c +++ b/drivers/gpio/gpio-palmas.c @@ -171,8 +171,7 @@ static int palmas_gpio_probe(struct platform_device *pdev) if (!dev_data) dev_data = &palmas_dev_data; - palmas_gpio = devm_kzalloc(&pdev->dev, - sizeof(*palmas_gpio), GFP_KERNEL); + palmas_gpio = devm_kzalloc_obj(&pdev->dev, *palmas_gpio); if (!palmas_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index afec5ec236968a..b662bcf7b9be8b 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -1211,7 +1211,7 @@ static int pca953x_probe(struct i2c_client *client) int ret; const struct regmap_config *regmap_config; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c index db027c10494f75..1b00d2cd579118 100644 --- a/drivers/gpio/gpio-pca9570.c +++ b/drivers/gpio/gpio-pca9570.c @@ -122,7 +122,7 @@ static int pca9570_probe(struct i2c_client *client) struct pca9570 *gpio; int ret; - gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&client->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index 1ba6a09542f3c6..4c38397a441f6a 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c @@ -297,7 +297,7 @@ static int pcf857x_probe(struct i2c_client *client) int status; /* Allocate, initialize, and register this gpio_chip. */ - gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&client->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c index 07a5617b314b31..aec1651a7750fc 100644 --- a/drivers/gpio/gpio-pch.c +++ b/drivers/gpio/gpio-pch.c @@ -357,7 +357,7 @@ static int pch_gpio_probe(struct pci_dev *pdev, struct pch_gpio *chip; int irq_base; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index b99f4863443da1..55a7f765398219 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -321,7 +321,7 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id) return dev_err_probe(dev, PTR_ERR(intcsr_map), "Unable to initialize PEX8311 register map\n"); - idio24gpio = devm_kzalloc(dev, sizeof(*idio24gpio), GFP_KERNEL); + idio24gpio = devm_kzalloc_obj(dev, *idio24gpio); if (!idio24gpio) return -ENOMEM; @@ -335,7 +335,7 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Initialize all IRQ type configuration to IRQ_TYPE_EDGE_BOTH */ idio24gpio->irq_type = GENMASK(7, 0); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-pisosr.c b/drivers/gpio/gpio-pisosr.c index 2732ea8c16b7be..7314ac899f59e1 100644 --- a/drivers/gpio/gpio-pisosr.c +++ b/drivers/gpio/gpio-pisosr.c @@ -115,7 +115,7 @@ static int pisosr_gpio_probe(struct spi_device *spi) u32 ngpios; int ret; - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c index fcd44e34f65e6a..a506fa745c9745 100644 --- a/drivers/gpio/gpio-pl061.c +++ b/drivers/gpio/gpio-pl061.c @@ -309,7 +309,7 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) struct gpio_irq_chip *girq; int ret, irq; - pl061 = devm_kzalloc(dev, sizeof(*pl061), GFP_KERNEL); + pl061 = devm_kzalloc_obj(dev, *pl061); if (pl061 == NULL) return -ENOMEM; @@ -344,8 +344,7 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) gpio_irq_chip_set_chip(girq, &pl061_irq_chip); girq->parent_handler = pl061_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/gpio/gpio-pmic-eic-sprd.c b/drivers/gpio/gpio-pmic-eic-sprd.c index cb015fb5c94674..844b6373508325 100644 --- a/drivers/gpio/gpio-pmic-eic-sprd.c +++ b/drivers/gpio/gpio-pmic-eic-sprd.c @@ -308,7 +308,7 @@ static int sprd_pmic_eic_probe(struct platform_device *pdev) struct sprd_pmic_eic *pmic_eic; int ret; - pmic_eic = devm_kzalloc(&pdev->dev, sizeof(*pmic_eic), GFP_KERNEL); + pmic_eic = devm_kzalloc_obj(&pdev->dev, *pmic_eic); if (!pmic_eic) return -ENOMEM; diff --git a/drivers/gpio/gpio-ppc44x.c b/drivers/gpio/gpio-ppc44x.c index 189667e0e1babd..3dd1bb8686ff37 100644 --- a/drivers/gpio/gpio-ppc44x.c +++ b/drivers/gpio/gpio-ppc44x.c @@ -157,7 +157,7 @@ static int ppc44x_gpio_probe(struct platform_device *ofdev) if (IS_ERR(regs)) return PTR_ERR(regs); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c index 3ff21e8992788f..17e95ee4fef64c 100644 --- a/drivers/gpio/gpio-pxa.c +++ b/drivers/gpio/gpio-pxa.c @@ -345,8 +345,7 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio, void __iom int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32); struct pxa_gpio_bank *bank; - pchip->banks = devm_kcalloc(pchip->dev, nbanks, sizeof(*pchip->banks), - GFP_KERNEL); + pchip->banks = devm_kzalloc_objs(pchip->dev, *pchip->banks, nbanks); if (!pchip->banks) return -ENOMEM; @@ -617,7 +616,7 @@ static int pxa_gpio_probe(struct platform_device *pdev) int gpio, ret; int irq0 = 0, irq1 = 0, irq_mux; - pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); + pchip = devm_kzalloc_obj(&pdev->dev, *pchip); if (!pchip) return -ENOMEM; pchip->dev = &pdev->dev; diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c index 40413e06b69c84..c4c8a8b118667d 100644 --- a/drivers/gpio/gpio-raspberrypi-exp.c +++ b/drivers/gpio/gpio-raspberrypi-exp.c @@ -217,7 +217,7 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev) if (!fw) return -EPROBE_DEFER; - rpi_gpio = devm_kzalloc(dev, sizeof(*rpi_gpio), GFP_KERNEL); + rpi_gpio = devm_kzalloc_obj(dev, *rpi_gpio); if (!rpi_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-rc5t583.c b/drivers/gpio/gpio-rc5t583.c index 5a69e4534591d0..7f904cf9c3b7a9 100644 --- a/drivers/gpio/gpio-rc5t583.c +++ b/drivers/gpio/gpio-rc5t583.c @@ -108,8 +108,7 @@ static int rc5t583_gpio_probe(struct platform_device *pdev) struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev); struct rc5t583_gpio *rc5t583_gpio; - rc5t583_gpio = devm_kzalloc(&pdev->dev, sizeof(*rc5t583_gpio), - GFP_KERNEL); + rc5t583_gpio = devm_kzalloc_obj(&pdev->dev, *rc5t583_gpio); if (!rc5t583_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index 54dc47d45de7e8..1a229a5bc1520c 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c @@ -549,7 +549,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) unsigned int npins; int ret; - p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/gpio/gpio-rda.c b/drivers/gpio/gpio-rda.c index f6c05fdbe63fa6..cf8465d93ffe34 100644 --- a/drivers/gpio/gpio-rda.c +++ b/drivers/gpio/gpio-rda.c @@ -216,7 +216,7 @@ static int rda_gpio_probe(struct platform_device *pdev) u32 ngpios; int ret; - rda_gpio = devm_kzalloc(dev, sizeof(*rda_gpio), GFP_KERNEL); + rda_gpio = devm_kzalloc_obj(dev, *rda_gpio); if (!rda_gpio) return -ENOMEM; @@ -266,9 +266,7 @@ static int rda_gpio_probe(struct platform_device *pdev) girq->parent_handler = rda_gpio_irq_handler; girq->parent_handler_data = rda_gpio; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = rda_gpio->irq; diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c index ba62b81aa8aedf..6047aeca28db38 100644 --- a/drivers/gpio/gpio-rdc321x.c +++ b/drivers/gpio/gpio-rdc321x.c @@ -129,8 +129,7 @@ static int rdc321x_gpio_probe(struct platform_device *pdev) return -ENODEV; } - rdc321x_gpio_dev = devm_kzalloc(&pdev->dev, sizeof(struct rdc321x_gpio), - GFP_KERNEL); + rdc321x_gpio_dev = devm_kzalloc_obj(&pdev->dev, struct rdc321x_gpio); if (!rdc321x_gpio_dev) return -ENOMEM; diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c index 5d98ad597d9e27..947cfd0542cd23 100644 --- a/drivers/gpio/gpio-realtek-otto.c +++ b/drivers/gpio/gpio-realtek-otto.c @@ -372,7 +372,7 @@ static int realtek_gpio_probe(struct platform_device *pdev) unsigned int nr_cpus; int cpu, err, irq; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -443,8 +443,8 @@ static int realtek_gpio_probe(struct platform_device *pdev) girq->handler = handle_bad_irq; girq->parent_handler = realtek_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/gpio/gpio-reg.c b/drivers/gpio/gpio-reg.c index 296c210b228c4f..76aa67f94c0ba8 100644 --- a/drivers/gpio/gpio-reg.c +++ b/drivers/gpio/gpio-reg.c @@ -148,7 +148,7 @@ struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg, int ret; if (dev) - r = devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); + r = devm_kzalloc_obj(dev, *r); else r = kzalloc_obj(*r); diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 2f5f45b84cc94f..ac6ad56f447913 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -572,6 +572,11 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config err_remove_gpiochip: gpiochip_remove(chip); + +#ifdef CONFIG_REGMAP_IRQ + if (gpio->irq_chip_data) + regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data); +#endif err_free_bitmap_output: bitmap_free(gpio->fixed_direction_output); err_free_bitmap_dirmask: diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 77b239a9a601ea..714604c11d782d 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -201,20 +201,25 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, { struct rockchip_pin_bank *bank = gpiochip_get_data(gc); const struct rockchip_gpio_regs *reg = bank->gpio_regs; - unsigned long flags, div_reg, freq, max_debounce; + unsigned long flags, div_reg, freq; bool div_debounce_support; unsigned int cur_div_reg; - u64 div; + u64 div, max_debounce; if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) { div_debounce_support = true; freq = clk_get_rate(bank->db_clk); - max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq; + if (!freq) + return -EINVAL; + + div = (u64)(GENMASK(23, 0) + 1) * 2 * USEC_PER_SEC; + max_debounce = div64_u64(div, freq); if (debounce > max_debounce) return -EINVAL; - div = debounce * freq; - div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1; + div = (u64)debounce * freq; + div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC); + div_reg = div_reg ? div_reg - 1 : 0; } else { div_debounce_support = false; } diff --git a/drivers/gpio/gpio-rtd.c b/drivers/gpio/gpio-rtd.c index d46b40dd52837d..7e37bad09dc40f 100644 --- a/drivers/gpio/gpio-rtd.c +++ b/drivers/gpio/gpio-rtd.c @@ -529,7 +529,7 @@ static int rtd_gpio_probe(struct platform_device *pdev) struct rtd_gpio *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-rtd1625.c b/drivers/gpio/gpio-rtd1625.c index bebd1b8ede4839..cf4f61603dfbfe 100644 --- a/drivers/gpio/gpio-rtd1625.c +++ b/drivers/gpio/gpio-rtd1625.c @@ -543,7 +543,7 @@ static int rtd1625_gpio_probe(struct platform_device *pdev) void __iomem *irq_base; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -562,8 +562,8 @@ static int rtd1625_gpio_probe(struct platform_device *pdev) raw_spin_lock_init(&data->lock); platform_set_drvdata(pdev, data); - data->save_regs = devm_kcalloc(dev, data->info->num_gpios, sizeof(*data->save_regs), - GFP_KERNEL); + data->save_regs = devm_kzalloc_objs(dev, *data->save_regs, + data->info->num_gpios); if (!data->save_regs) return -ENOMEM; diff --git a/drivers/gpio/gpio-sa1100.c b/drivers/gpio/gpio-sa1100.c index e4f3bf949b87eb..1916200ebbd54f 100644 --- a/drivers/gpio/gpio-sa1100.c +++ b/drivers/gpio/gpio-sa1100.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -322,7 +323,6 @@ static const int sa1100_gpio_irqs[] __initconst = { void __init sa1100_init_gpio(void) { struct sa1100_gpio_chip *sgc = &sa1100_gpio_chip; - struct gpio_chip *gc = &sgc->chip; int i; /* clear all GPIO edge detects */ @@ -330,10 +330,6 @@ void __init sa1100_init_gpio(void) writel_relaxed(0, sgc->membase + R_GRER); writel_relaxed(-1, sgc->membase + R_GEDR); - software_node_register(&sa1100_gpiochip_node); - gc->fwnode = software_node_fwnode(&sa1100_gpiochip_node); - gpiochip_add_data(gc, NULL); - sa1100_gpio_irqdomain = irq_domain_create_simple(NULL, 28, IRQ_GPIO0, &sa1100_gpio_irqdomain_ops, sgc); @@ -342,3 +338,29 @@ void __init sa1100_init_gpio(void) irq_set_chained_handler_and_data(sa1100_gpio_irqs[i], sa1100_gpio_handler, sgc); } + +static int __init sa1100_gpio_init_chip(void) +{ + struct gpio_chip *gc = &sa1100_gpio_chip.chip; + int error; + + error = software_node_register(&sa1100_gpiochip_node); + if (error) { + pr_err("failed to register sa1100 gpiochip software node: %d\n", + error); + return error; + } + + gc->fwnode = software_node_fwnode(&sa1100_gpiochip_node); + + error = gpiochip_add_data(gc, NULL); + if (error) { + pr_err("failed to add sa1100 gpiochip: %d\n", error); + gc->fwnode = NULL; + software_node_unregister(&sa1100_gpiochip_node); + return error; + } + + return 0; +} +postcore_initcall(sa1100_gpio_init_chip); diff --git a/drivers/gpio/gpio-sama5d2-piobu.c b/drivers/gpio/gpio-sama5d2-piobu.c index 5005688f6e67e4..ce625ae73215b2 100644 --- a/drivers/gpio/gpio-sama5d2-piobu.c +++ b/drivers/gpio/gpio-sama5d2-piobu.c @@ -185,7 +185,7 @@ static int sama5d2_piobu_probe(struct platform_device *pdev) struct sama5d2_piobu *piobu; int ret, i; - piobu = devm_kzalloc(&pdev->dev, sizeof(*piobu), GFP_KERNEL); + piobu = devm_kzalloc_obj(&pdev->dev, *piobu); if (!piobu) return -ENOMEM; diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index 5e361742a11adb..fc23f2699fc9e1 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c @@ -329,7 +329,7 @@ static int sch_gpio_probe(struct platform_device *pdev) void __iomem *regs; int ret; - sch = devm_kzalloc(dev, sizeof(*sch), GFP_KERNEL); + sch = devm_kzalloc_obj(dev, *sch); if (!sch) return -ENOMEM; diff --git a/drivers/gpio/gpio-sch311x.c b/drivers/gpio/gpio-sch311x.c index f95566998d30a7..855041c4d5dc6c 100644 --- a/drivers/gpio/gpio-sch311x.c +++ b/drivers/gpio/gpio-sch311x.c @@ -279,7 +279,7 @@ static int sch311x_gpio_probe(struct platform_device *pdev) return -EBUSY; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-shared-proxy.c b/drivers/gpio/gpio-shared-proxy.c index bc69b8729d1967..80412bd4ef2502 100644 --- a/drivers/gpio/gpio-shared-proxy.c +++ b/drivers/gpio/gpio-shared-proxy.c @@ -21,9 +21,37 @@ struct gpio_shared_proxy_data { struct gpio_chip gc; struct gpio_shared_desc *shared_desc; struct device *dev; + bool configured; bool voted_change; }; +/* + * A proxy may (re)initialize the line - set its direction and reset the + * default value and the vote tally - only while no other proxy has set the + * direction or voted for a value. Requesting the line is not enough: consumers + * may request concurrently, so counting requests lets every one of them + * conclude that it is not first. + */ +static bool gpio_shared_proxy_may_init(struct gpio_shared_proxy_data *proxy) +{ + unsigned int cfgcnt = proxy->shared_desc->cfgcnt; + + lockdep_assert_held(&proxy->shared_desc->mutex); + + return !cfgcnt || (cfgcnt == 1 && proxy->configured); +} + +static void gpio_shared_proxy_mark_configured(struct gpio_shared_proxy_data *proxy) +{ + lockdep_assert_held(&proxy->shared_desc->mutex); + + if (proxy->configured) + return; + + proxy->configured = true; + proxy->shared_desc->cfgcnt++; +} + static int gpio_shared_proxy_set_unlocked(struct gpio_shared_proxy_data *proxy, int value) { @@ -57,9 +85,16 @@ gpio_shared_proxy_set_unlocked(struct gpio_shared_proxy_data *proxy, int value) } /* Desired value is the default. */ - if (!proxy->voted_change) - /* We didn't vote for change previously, nothing to do. */ + if (!proxy->voted_change) { + /* + * With no votes outstanding the line should be at the + * default, but a GPIOD_ASIS line may have been left at the + * opposite value. Drive it there. + */ + if (!shared_desc->votecnt) + ret = gpiod_set_value_cansleep(desc, shared_desc->def_val); goto out; + } /* We previously voted for change. */ if (shared_desc->votecnt == 1) { @@ -110,13 +145,22 @@ static void gpio_shared_proxy_free(struct gpio_chip *gc, unsigned int offset) if (proxy->voted_change) { ret = gpio_shared_proxy_set_unlocked(proxy, shared_desc->def_val); - if (ret) + if (ret) { dev_err(proxy->dev, "Failed to unset the shared GPIO value on release: %d\n", ret); + /* The consumer is going away regardless, drop its vote */ + shared_desc->votecnt--; + proxy->voted_change = false; + } } proxy->shared_desc->usecnt--; + if (proxy->configured) { + proxy->configured = false; + shared_desc->cfgcnt--; + } + dev_dbg(proxy->dev, "Shared GPIO freed, number of users: %u\n", proxy->shared_desc->usecnt); } @@ -131,7 +175,7 @@ static int gpio_shared_proxy_set_config(struct gpio_chip *gc, guard(mutex)(&shared_desc->mutex); - if (shared_desc->usecnt > 1) { + if (!gpio_shared_proxy_may_init(proxy)) { if (shared_desc->cfg != cfg) { dev_dbg(proxy->dev, "Shared GPIO's configuration already set, accepting changes but users may conflict!!\n"); @@ -155,15 +199,24 @@ static int gpio_shared_proxy_direction_input(struct gpio_chip *gc, struct gpio_shared_proxy_data *proxy = gpiochip_get_data(gc); struct gpio_shared_desc *shared_desc = proxy->shared_desc; struct gpio_desc *desc = shared_desc->desc; - int dir; + int ret, dir; guard(mutex)(&shared_desc->mutex); - if (shared_desc->usecnt == 1) { + if (gpio_shared_proxy_may_init(proxy)) { dev_dbg(proxy->dev, - "Only one user of this shared GPIO, allowing to set direction to input\n"); + "No other user configured this shared GPIO, allowing to set direction to input\n"); - return gpiod_direction_input(desc); + ret = gpiod_direction_input(desc); + if (ret) + return ret; + + /* An input carries no value, drop any vote this proxy cast */ + shared_desc->votecnt = 0; + proxy->voted_change = false; + gpio_shared_proxy_mark_configured(proxy); + + return 0; } dir = gpiod_get_direction(desc); @@ -176,6 +229,8 @@ static int gpio_shared_proxy_direction_input(struct gpio_chip *gc, return -EPERM; } + gpio_shared_proxy_mark_configured(proxy); + return 0; } @@ -189,18 +244,20 @@ static int gpio_shared_proxy_direction_output(struct gpio_chip *gc, guard(mutex)(&shared_desc->mutex); - if (shared_desc->usecnt == 1) { + if (gpio_shared_proxy_may_init(proxy)) { dev_dbg(proxy->dev, - "Only one user of this shared GPIO, allowing to set direction to output with value '%s'\n", + "No other user configured this shared GPIO, allowing to set direction to output with value '%s'\n", str_high_low(value)); ret = gpiod_direction_output(desc, value); if (ret) return ret; + /* Only this proxy can have voted, so the tally is ours to reset */ shared_desc->def_val = value; shared_desc->votecnt = 0; proxy->voted_change = false; + gpio_shared_proxy_mark_configured(proxy); return 0; } @@ -215,7 +272,13 @@ static int gpio_shared_proxy_direction_output(struct gpio_chip *gc, return -EPERM; } - return gpio_shared_proxy_set_unlocked(proxy, value); + ret = gpio_shared_proxy_set_unlocked(proxy, value); + if (ret) + return ret; + + gpio_shared_proxy_mark_configured(proxy); + + return 0; } static int gpio_shared_proxy_get_cansleep(struct gpio_chip *gc, @@ -230,10 +293,21 @@ static int gpio_shared_proxy_set_cansleep(struct gpio_chip *gc, unsigned int offset, int value) { struct gpio_shared_proxy_data *proxy = gpiochip_get_data(gc); + int ret; guard(mutex)(&proxy->shared_desc->mutex); - return gpio_shared_proxy_set_unlocked(proxy, value); + /* + * A GPIOD_ASIS consumer may vote without ever setting the direction; + * count it as configured so a later user can't reset its vote. + */ + ret = gpio_shared_proxy_set_unlocked(proxy, value); + if (ret) + return ret; + + gpio_shared_proxy_mark_configured(proxy); + + return 0; } static int gpio_shared_proxy_get_direction(struct gpio_chip *gc, @@ -263,7 +337,7 @@ static int gpio_shared_proxy_probe(struct auxiliary_device *adev, if (IS_ERR(shared_desc)) return PTR_ERR(shared_desc); - proxy = devm_kzalloc(dev, sizeof(*proxy), GFP_KERNEL); + proxy = devm_kzalloc_obj(dev, *proxy); if (!proxy) return -ENOMEM; diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index e9a992cd4b9cdf..0b52b20e5136b5 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -184,7 +184,7 @@ static int sifive_gpio_probe(struct platform_device *pdev) struct sifive_gpio *chip; int ret, ngpio; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 0c73bec042670f..ce205e88c0aba7 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -364,17 +364,16 @@ static int gpio_sim_setup_sysfs(struct gpio_sim_chip *chip) struct attribute **attrs; int i, ret; - chip->attr_groups = devm_kcalloc(dev, sizeof(*chip->attr_groups), - num_lines + 1, GFP_KERNEL); + chip->attr_groups = devm_kzalloc_objs(dev, *chip->attr_groups, + num_lines + 1); if (!chip->attr_groups) return -ENOMEM; for (i = 0; i < num_lines; i++) { - attr_group = devm_kzalloc(dev, sizeof(*attr_group), GFP_KERNEL); - attrs = devm_kcalloc(dev, GPIO_SIM_NUM_ATTRS, sizeof(*attrs), - GFP_KERNEL); - val_attr = devm_kzalloc(dev, sizeof(*val_attr), GFP_KERNEL); - pull_attr = devm_kzalloc(dev, sizeof(*pull_attr), GFP_KERNEL); + attr_group = devm_kzalloc_obj(dev, *attr_group); + attrs = devm_kzalloc_objs(dev, *attrs, GPIO_SIM_NUM_ATTRS); + val_attr = devm_kzalloc_obj(dev, *val_attr); + pull_attr = devm_kzalloc_obj(dev, *pull_attr); if (!attr_group || !attrs || !val_attr || !pull_attr) return -ENOMEM; @@ -438,7 +437,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev) return -ENOMEM; } - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -803,7 +802,7 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank, ranges_size = gpio_sim_get_reserved_ranges_size(bank); if (ranges_size) { - ranges = kcalloc(ranges_size, sizeof(u32), GFP_KERNEL); + ranges = kzalloc_objs(u32, ranges_size); if (!ranges) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpio/gpio-siox.c b/drivers/gpio/gpio-siox.c index d60680ace144df..c82238302aba31 100644 --- a/drivers/gpio/gpio-siox.c +++ b/drivers/gpio/gpio-siox.c @@ -222,7 +222,7 @@ static int gpio_siox_probe(struct siox_device *sdevice) struct gpio_chip *gc; int ret; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/gpio/gpio-sl28cpld.c b/drivers/gpio/gpio-sl28cpld.c index ca7a9b9bcf48a8..9aea06fff329db 100644 --- a/drivers/gpio/gpio-sl28cpld.c +++ b/drivers/gpio/gpio-sl28cpld.c @@ -60,7 +60,7 @@ static int sl28cpld_gpio_irq_init(struct platform_device *pdev, if (irq < 0) return irq; - irq_chip = devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL); + irq_chip = devm_kzalloc_obj(dev, *irq_chip); if (!irq_chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-sloppy-logic-analyzer.c b/drivers/gpio/gpio-sloppy-logic-analyzer.c index 0717649a6820c0..3acf80f7d7f90e 100644 --- a/drivers/gpio/gpio-sloppy-logic-analyzer.c +++ b/drivers/gpio/gpio-sloppy-logic-analyzer.c @@ -236,7 +236,7 @@ static int gpio_la_poll_probe(struct platform_device *pdev) unsigned int i, meta_len = 0; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-sodaville.c b/drivers/gpio/gpio-sodaville.c index e2a784df275c98..a160bbbe3a413d 100644 --- a/drivers/gpio/gpio-sodaville.c +++ b/drivers/gpio/gpio-sodaville.c @@ -166,9 +166,12 @@ static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd, ct->chip.irq_eoi = irq_gc_eoi; ct->chip.irq_set_type = sdv_gpio_pub_set_type; - irq_setup_generic_chip(sd->gc, IRQ_MSK(SDV_NUM_PUB_GPIOS), - IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, - IRQ_LEVEL | IRQ_NOPROBE); + ret = devm_irq_setup_generic_chip(&pdev->dev, sd->gc, + IRQ_MSK(SDV_NUM_PUB_GPIOS), + IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, + IRQ_LEVEL | IRQ_NOPROBE); + if (ret) + return ret; sd->id = irq_domain_create_legacy(dev_fwnode(&pdev->dev), SDV_NUM_PUB_GPIOS, sd->irq_base, 0, &irq_domain_sdv_ops, sd); @@ -186,7 +189,7 @@ static int sdv_gpio_probe(struct pci_dev *pdev, int ret; u32 mux_val; - sd = devm_kzalloc(&pdev->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&pdev->dev, *sd); if (!sd) return -ENOMEM; diff --git a/drivers/gpio/gpio-spacemit-k1.c b/drivers/gpio/gpio-spacemit-k1.c index 5fe813b7f9bb54..98f0177ff50926 100644 --- a/drivers/gpio/gpio-spacemit-k1.c +++ b/drivers/gpio/gpio-spacemit-k1.c @@ -274,7 +274,7 @@ static int spacemit_gpio_probe(struct platform_device *pdev) void __iomem *regs; int i, irq, ret; - sg = devm_kzalloc(dev, sizeof(*sg), GFP_KERNEL); + sg = devm_kzalloc_obj(dev, *sg); if (!sg) return -ENOMEM; diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c index 96a0e1211500e0..6f6a5f3612d564 100644 --- a/drivers/gpio/gpio-spear-spics.c +++ b/drivers/gpio/gpio-spear-spics.c @@ -111,7 +111,7 @@ static int spics_gpio_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct spear_spics *spics; - spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); + spics = devm_kzalloc_obj(&pdev->dev, *spics); if (!spics) return -ENOMEM; diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c index 042a83f60eaa19..65e77a2d65362a 100644 --- a/drivers/gpio/gpio-sprd.c +++ b/drivers/gpio/gpio-sprd.c @@ -223,7 +223,7 @@ static int sprd_gpio_probe(struct platform_device *pdev) struct gpio_irq_chip *irq; struct sprd_gpio *sprd_gpio; - sprd_gpio = devm_kzalloc(&pdev->dev, sizeof(*sprd_gpio), GFP_KERNEL); + sprd_gpio = devm_kzalloc_obj(&pdev->dev, *sprd_gpio); if (!sprd_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index ccdf13a741b7c9..bc9fa928f99729 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c @@ -483,7 +483,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev) return -EINVAL; } - stmpe_gpio = devm_kzalloc(dev, sizeof(*stmpe_gpio), GFP_KERNEL); + stmpe_gpio = devm_kzalloc_obj(dev, *stmpe_gpio); if (!stmpe_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c index 78d6c78d4aab5c..477f956844eb31 100644 --- a/drivers/gpio/gpio-stp-xway.c +++ b/drivers/gpio/gpio-stp-xway.c @@ -237,7 +237,7 @@ static int xway_stp_probe(struct platform_device *pdev) struct clk *clk; int ret = 0; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-syscon.c b/drivers/gpio/gpio-syscon.c index 40064d4cf47f93..9dd53bde3978d9 100644 --- a/drivers/gpio/gpio-syscon.c +++ b/drivers/gpio/gpio-syscon.c @@ -212,7 +212,7 @@ static int syscon_gpio_probe(struct platform_device *pdev) int ret; bool use_parent_regmap = false; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-tangier.c b/drivers/gpio/gpio-tangier.c index ba5a8ede8912b6..4a262354fdfcc8 100644 --- a/drivers/gpio/gpio-tangier.c +++ b/drivers/gpio/gpio-tangier.c @@ -419,7 +419,7 @@ int devm_tng_gpio_probe(struct device *dev, struct tng_gpio *gpio) struct gpio_irq_chip *girq; int ret; - gpio->ctx = devm_kcalloc(dev, nctx, sizeof(*gpio->ctx), GFP_KERNEL); + gpio->ctx = devm_kzalloc_objs(dev, *gpio->ctx, nctx); if (!gpio->ctx) return -ENOMEM; @@ -445,8 +445,8 @@ int devm_tng_gpio_probe(struct device *dev, struct tng_gpio *gpio) girq->init_hw = tng_irq_init_hw; girq->parent_handler = tng_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c index 7fb8e6223bd19c..3cd516ae94193f 100644 --- a/drivers/gpio/gpio-tb10x.c +++ b/drivers/gpio/gpio-tb10x.c @@ -99,7 +99,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev) if (of_property_read_u32(np, "abilis,ngpio", &ngpio)) return -EINVAL; - tb10x_gpio = devm_kzalloc(dev, sizeof(*tb10x_gpio), GFP_KERNEL); + tb10x_gpio = devm_kzalloc_obj(dev, *tb10x_gpio); if (tb10x_gpio == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c index 90d048f9da0870..85488980f65cb8 100644 --- a/drivers/gpio/gpio-tc3589x.c +++ b/drivers/gpio/gpio-tc3589x.c @@ -312,8 +312,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) if (irq < 0) return irq; - tc3589x_gpio = devm_kzalloc(&pdev->dev, sizeof(struct tc3589x_gpio), - GFP_KERNEL); + tc3589x_gpio = devm_kzalloc_obj(&pdev->dev, struct tc3589x_gpio); if (!tc3589x_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index ccda3a56d5994d..88de78123da092 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c @@ -682,7 +682,7 @@ static int tegra_gpio_probe(struct platform_device *pdev) unsigned int i, j; int ret; - tgi = devm_kzalloc(&pdev->dev, sizeof(*tgi), GFP_KERNEL); + tgi = devm_kzalloc_obj(&pdev->dev, *tgi); if (!tgi) return -ENOMEM; @@ -717,13 +717,12 @@ static int tegra_gpio_probe(struct platform_device *pdev) if (tgi->soc->debounce_supported) tgi->gc.set_config = tegra_gpio_set_config; - tgi->bank_info = devm_kcalloc(&pdev->dev, tgi->bank_count, - sizeof(*tgi->bank_info), GFP_KERNEL); + tgi->bank_info = devm_kzalloc_objs(&pdev->dev, *tgi->bank_info, + tgi->bank_count); if (!tgi->bank_info) return -ENOMEM; - tgi->irqs = devm_kcalloc(&pdev->dev, tgi->bank_count, - sizeof(*tgi->irqs), GFP_KERNEL); + tgi->irqs = devm_kzalloc_objs(&pdev->dev, *tgi->irqs, tgi->bank_count); if (!tgi->irqs) return -ENOMEM; diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c index 34e084c95d7a91..6ee18b150b5ce1 100644 --- a/drivers/gpio/gpio-tegra186.c +++ b/drivers/gpio/gpio-tegra186.c @@ -865,7 +865,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev) if (err < 0) return err; - gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, irq, err), GFP_KERNEL); + gpio = devm_kzalloc_flex(&pdev->dev, *gpio, irq, err); if (!gpio) return -ENOMEM; @@ -929,8 +929,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev) for (i = 0; i < gpio->soc->num_ports; i++) gpio->gpio.ngpio += gpio->soc->ports[i].pins; - names = devm_kcalloc(gpio->gpio.parent, gpio->gpio.ngpio, - sizeof(*names), GFP_KERNEL); + names = devm_kzalloc_objs(gpio->gpio.parent, *names, gpio->gpio.ngpio); if (!names) return -ENOMEM; @@ -988,8 +987,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) * currently program. */ if (gpio->num_irqs_per_bank > 1) { - irq->parents = devm_kcalloc(&pdev->dev, gpio->num_banks, - sizeof(*irq->parents), GFP_KERNEL); + irq->parents = devm_kzalloc_objs(&pdev->dev, *irq->parents, + gpio->num_banks); if (!irq->parents) return -ENOMEM; @@ -1020,8 +1019,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev) } } - irq->map = devm_kcalloc(&pdev->dev, gpio->gpio.ngpio, - sizeof(*irq->map), GFP_KERNEL); + irq->map = devm_kzalloc_objs(&pdev->dev, *irq->map, gpio->gpio.ngpio); if (!irq->map) return -ENOMEM; diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c index be96853063ba94..0cc1bf618ff1c9 100644 --- a/drivers/gpio/gpio-thunderx.c +++ b/drivers/gpio/gpio-thunderx.c @@ -439,7 +439,7 @@ static int thunderx_gpio_probe(struct pci_dev *pdev, int ngpio, i; int err = 0; - txgpio = devm_kzalloc(dev, sizeof(*txgpio), GFP_KERNEL); + txgpio = devm_kzalloc_obj(dev, *txgpio); if (!txgpio) return -ENOMEM; @@ -479,18 +479,14 @@ static int thunderx_gpio_probe(struct pci_dev *pdev, txgpio->base_msi = (c >> 8) & 0xff; } - txgpio->msix_entries = devm_kcalloc(dev, - ngpio, sizeof(struct msix_entry), - GFP_KERNEL); + txgpio->msix_entries = devm_kzalloc_objs(dev, struct msix_entry, ngpio); if (!txgpio->msix_entries) { err = -ENOMEM; goto out; } - txgpio->line_entries = devm_kcalloc(dev, - ngpio, - sizeof(struct thunderx_line), - GFP_KERNEL); + txgpio->line_entries = devm_kzalloc_objs(dev, struct thunderx_line, + ngpio); if (!txgpio->line_entries) { err = -ENOMEM; goto out; diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c index 727fa1b5ad3bca..164976bd6b7e91 100644 --- a/drivers/gpio/gpio-timberdale.c +++ b/drivers/gpio/gpio-timberdale.c @@ -226,7 +226,7 @@ static int timbgpio_probe(struct platform_device *pdev) struct timbgpio *tgpio; int irq = platform_get_irq(pdev, 0); - tgpio = devm_kzalloc(dev, sizeof(*tgpio), GFP_KERNEL); + tgpio = devm_kzalloc_obj(dev, *tgpio); if (!tgpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tpic2810.c b/drivers/gpio/gpio-tpic2810.c index c38538653e9916..cf3227422d8fa5 100644 --- a/drivers/gpio/gpio-tpic2810.c +++ b/drivers/gpio/gpio-tpic2810.c @@ -97,7 +97,7 @@ static int tpic2810_probe(struct i2c_client *client) { struct tpic2810 *gpio; - gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&client->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps65086.c b/drivers/gpio/gpio-tps65086.c index f29d8485ab3311..ce3f997367c587 100644 --- a/drivers/gpio/gpio-tps65086.c +++ b/drivers/gpio/gpio-tps65086.c @@ -79,7 +79,7 @@ static int tps65086_gpio_probe(struct platform_device *pdev) { struct tps65086_gpio *gpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps65218.c b/drivers/gpio/gpio-tps65218.c index bf85663349fb58..fef73fa62b5405 100644 --- a/drivers/gpio/gpio-tps65218.c +++ b/drivers/gpio/gpio-tps65218.c @@ -181,8 +181,7 @@ static int tps65218_gpio_probe(struct platform_device *pdev) struct tps65218 *tps65218 = dev_get_drvdata(pdev->dev.parent); struct tps65218_gpio *tps65218_gpio; - tps65218_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps65218_gpio), - GFP_KERNEL); + tps65218_gpio = devm_kzalloc_obj(&pdev->dev, *tps65218_gpio); if (!tps65218_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps65219.c b/drivers/gpio/gpio-tps65219.c index 6958466455d04c..2d520baa616e78 100644 --- a/drivers/gpio/gpio-tps65219.c +++ b/drivers/gpio/gpio-tps65219.c @@ -230,7 +230,7 @@ static int tps65219_gpio_probe(struct platform_device *pdev) struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent); struct tps65219_gpio *gpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps6586x.c b/drivers/gpio/gpio-tps6586x.c index aaacbb54bf5d89..f7664443c74be8 100644 --- a/drivers/gpio/gpio-tps6586x.c +++ b/drivers/gpio/gpio-tps6586x.c @@ -83,8 +83,7 @@ static int tps6586x_gpio_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); pdata = dev_get_platdata(pdev->dev.parent); - tps6586x_gpio = devm_kzalloc(&pdev->dev, - sizeof(*tps6586x_gpio), GFP_KERNEL); + tps6586x_gpio = devm_kzalloc_obj(&pdev->dev, *tps6586x_gpio); if (!tps6586x_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c index 25e9f41efe78fd..884ef70a1301bb 100644 --- a/drivers/gpio/gpio-tps65910.c +++ b/drivers/gpio/gpio-tps65910.c @@ -116,8 +116,7 @@ static int tps65910_gpio_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - tps65910_gpio = devm_kzalloc(&pdev->dev, - sizeof(*tps65910_gpio), GFP_KERNEL); + tps65910_gpio = devm_kzalloc_obj(&pdev->dev, *tps65910_gpio); if (!tps65910_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps65912.c b/drivers/gpio/gpio-tps65912.c index cf3fa49a70974a..93e3cd3352b4ee 100644 --- a/drivers/gpio/gpio-tps65912.c +++ b/drivers/gpio/gpio-tps65912.c @@ -103,7 +103,7 @@ static int tps65912_gpio_probe(struct platform_device *pdev) struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent); struct tps65912_gpio *gpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tps68470.c b/drivers/gpio/gpio-tps68470.c index 8541acecfbbefc..7989b411043bc3 100644 --- a/drivers/gpio/gpio-tps68470.c +++ b/drivers/gpio/gpio-tps68470.c @@ -142,8 +142,7 @@ static int tps68470_gpio_probe(struct platform_device *pdev) struct tps68470_gpio_data *tps68470_gpio; int ret; - tps68470_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps68470_gpio), - GFP_KERNEL); + tps68470_gpio = devm_kzalloc_obj(&pdev->dev, *tps68470_gpio); if (!tps68470_gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-tqmx86.c b/drivers/gpio/gpio-tqmx86.c index eedfc0e371e377..49e1dd4330266c 100644 --- a/drivers/gpio/gpio-tqmx86.c +++ b/drivers/gpio/gpio-tqmx86.c @@ -344,7 +344,7 @@ static int tqmx86_gpio_probe(struct platform_device *pdev) if (!io_base) return -ENOMEM; - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; @@ -389,9 +389,7 @@ static int tqmx86_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &tqmx86_gpio_irq_chip); girq->parent_handler = tqmx86_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) { ret = -ENOMEM; goto out_pm_dis; diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c index 0207c2b813f413..9b249ccbf22c5a 100644 --- a/drivers/gpio/gpio-ts4800.c +++ b/drivers/gpio/gpio-ts4800.c @@ -23,7 +23,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev) void __iomem *base_addr; int retval; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-ts4900.c b/drivers/gpio/gpio-ts4900.c index b46b48e56c565d..123282bbf3ec23 100644 --- a/drivers/gpio/gpio-ts4900.c +++ b/drivers/gpio/gpio-ts4900.c @@ -145,7 +145,7 @@ static int ts4900_gpio_probe(struct i2c_client *client) if (device_property_read_u32(&client->dev, "ngpios", &ngpio)) ngpio = DEFAULT_PIN_NUMBER; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c index a851702befdea7..3e06ef9e223364 100644 --- a/drivers/gpio/gpio-twl4030.c +++ b/drivers/gpio/gpio-twl4030.c @@ -472,7 +472,7 @@ static struct twl4030_gpio_platform_data *of_gpio_twl4030(struct device *dev) { struct twl4030_gpio_platform_data *omap_twl_info; - omap_twl_info = devm_kzalloc(dev, sizeof(*omap_twl_info), GFP_KERNEL); + omap_twl_info = devm_kzalloc_obj(dev, *omap_twl_info); if (!omap_twl_info) return NULL; @@ -506,8 +506,7 @@ static int gpio_twl4030_probe(struct platform_device *pdev) struct gpio_twl4030_priv *priv; int ret, irq_base; - priv = devm_kzalloc(&pdev->dev, sizeof(struct gpio_twl4030_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct gpio_twl4030_priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 0574dde5b5bb7a..cafbd5f957d62a 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c @@ -366,8 +366,7 @@ static int uniphier_gpio_probe(struct platform_device *pdev) return ret; nregs = uniphier_gpio_get_nbanks(ngpios) * 2 + 3; - priv = devm_kzalloc(dev, struct_size(priv, saved_vals, nregs), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, saved_vals, nregs); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-usbio.c b/drivers/gpio/gpio-usbio.c index 489c8ac6299e15..d1cbe97bcf9b95 100644 --- a/drivers/gpio/gpio-usbio.c +++ b/drivers/gpio/gpio-usbio.c @@ -190,7 +190,7 @@ static int usbio_gpio_probe(struct auxiliary_device *adev, if (!bank_desc) return -EINVAL; - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c index adfa2c2d5873d2..bc7d3aa7dfca3e 100644 --- a/drivers/gpio/gpio-vf610.c +++ b/drivers/gpio/gpio-vf610.c @@ -226,7 +226,7 @@ static int vf610_gpio_probe(struct platform_device *pdev) int ret; bool dual_base; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; @@ -333,9 +333,7 @@ static int vf610_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &vf610_irqchip); girq->parent_handler = vf610_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = port->irq; diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c index 89087fd48a8192..b8d6dff5b66394 100644 --- a/drivers/gpio/gpio-viperboard.c +++ b/drivers/gpio/gpio-viperboard.c @@ -396,7 +396,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev) struct vprbrd_gpio *vb_gpio; int ret; - vb_gpio = devm_kzalloc(&pdev->dev, sizeof(*vb_gpio), GFP_KERNEL); + vb_gpio = devm_kzalloc_obj(&pdev->dev, *vb_gpio); if (vb_gpio == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-virtio.c b/drivers/gpio/gpio-virtio.c index ed6e0e90fa8aa7..d0ae3d57c64037 100644 --- a/drivers/gpio/gpio-virtio.c +++ b/drivers/gpio/gpio-virtio.c @@ -512,7 +512,7 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio, return NULL; } - names = devm_kcalloc(dev, ngpio, sizeof(*names), GFP_KERNEL); + names = devm_kzalloc_objs(dev, *names, ngpio); if (!names) return NULL; @@ -541,7 +541,7 @@ static int virtio_gpio_probe(struct virtio_device *vdev) u16 ngpio; int ret, i; - vgpio = devm_kzalloc(dev, sizeof(*vgpio), GFP_KERNEL); + vgpio = devm_kzalloc_obj(dev, *vgpio); if (!vgpio) return -ENOMEM; @@ -556,7 +556,7 @@ static int virtio_gpio_probe(struct virtio_device *vdev) return -EINVAL; } - vgpio->lines = devm_kcalloc(dev, ngpio, sizeof(*vgpio->lines), GFP_KERNEL); + vgpio->lines = devm_kzalloc_objs(dev, *vgpio->lines, ngpio); if (!vgpio->lines) return -ENOMEM; @@ -584,11 +584,12 @@ static int virtio_gpio_probe(struct virtio_device *vdev) /* Interrupt support */ if (virtio_has_feature(vdev, VIRTIO_GPIO_F_IRQ)) { - vgpio->irq_lines = devm_kcalloc(dev, ngpio, sizeof(*vgpio->irq_lines), GFP_KERNEL); + vgpio->irq_lines = devm_kzalloc_objs(dev, *vgpio->irq_lines, + ngpio); if (!vgpio->irq_lines) return -ENOMEM; - gpio_irq_chip = devm_kzalloc(dev, sizeof(*gpio_irq_chip), GFP_KERNEL); + gpio_irq_chip = devm_kzalloc_obj(dev, *gpio_irq_chip); if (!gpio_irq_chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index 70ddccccc1c406..5bf5d891c44127 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -55,9 +55,9 @@ struct gpio_virtuser_line_array_data { struct gpio_virtuser_line_data { struct gpio_virtuser_attr_data ad; char consumer[GPIO_VIRTUSER_NAME_BUF_LEN]; - struct mutex consumer_lock; + struct mutex lock; unsigned int debounce; - atomic_t irq; + int irq; atomic_t irq_count; }; @@ -607,7 +607,7 @@ static ssize_t gpio_virtuser_consumer_read(struct file *file, memset(buf, 0x0, sizeof(buf)); - scoped_guard(mutex, &data->consumer_lock) + scoped_guard(mutex, &data->lock) ret = snprintf(buf, sizeof(buf), "%s\n", data->consumer); return simple_read_from_buffer(user_buf, size, ppos, buf, ret); @@ -635,7 +635,7 @@ static ssize_t gpio_virtuser_consumer_write(struct file *file, if (ret) return ret; - scoped_guard(mutex, &data->consumer_lock) + scoped_guard(mutex, &data->lock) strscpy(data->consumer, buf, sizeof(data->consumer)); return count; @@ -675,7 +675,12 @@ static int gpio_virtuser_interrupts_set(void *data, u64 val) if (val > 1) return -EINVAL; + guard(mutex)(&ld->lock); + if (val) { + if (ld->irq >= 0) + return -EBUSY; + irq = gpiod_to_irq(ld->ad.desc); if (irq < 0) return irq; @@ -689,11 +694,13 @@ static int gpio_virtuser_interrupts_set(void *data, u64 val) if (ret) return ret; - atomic_set(&ld->irq, irq); + ld->irq = irq; } else { - irq = atomic_xchg(&ld->irq, 0); - if (irq) - free_irq(irq, ld); + if (ld->irq < 0) + return -EBUSY; + + free_irq(ld->irq, ld); + ld->irq = -1; } return 0; @@ -773,7 +780,7 @@ static int gpio_virtuser_dbgfs_init_line_array_attrs(struct device *dev, struct gpio_virtuser_line_array_data *data; char *name; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -793,6 +800,14 @@ static int gpio_virtuser_dbgfs_init_line_array_attrs(struct device *dev, data->ad.dbgfs_dir, data); } +static void gpio_virtuser_free_irq(void *data) +{ + struct gpio_virtuser_line_data *ld = data; + + if (ld->irq >= 0) + free_irq(ld->irq, ld); +} + static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev, struct gpio_desc *desc, const char *id, @@ -803,20 +818,24 @@ static int gpio_virtuser_dbgfs_init_line_attrs(struct device *dev, char *name; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; data->ad.desc = desc; strscpy(data->consumer, id); - atomic_set(&data->irq, 0); + data->irq = -1; atomic_set(&data->irq_count, 0); + ret = devm_add_action_or_reset(dev, gpio_virtuser_free_irq, data); + if (ret) + return ret; + name = devm_kasprintf(dev, GFP_KERNEL, "gpiod:%s:%u", id, index); if (!name) return -ENOMEM; - ret = devm_mutex_init(dev, &data->consumer_lock); + ret = devm_mutex_init(dev, &data->lock); if (ret) return ret; @@ -917,7 +936,7 @@ static int gpio_virtuser_probe(struct platform_device *pdev) if (num_ids == 0) return dev_err_probe(dev, -EINVAL, "No GPIO IDs specified\n"); - ids = devm_kcalloc(dev, num_ids, sizeof(*ids), GFP_KERNEL); + ids = devm_kzalloc_objs(dev, *ids, num_ids); if (!ids) return -ENOMEM; @@ -927,38 +946,50 @@ static int gpio_virtuser_probe(struct platform_device *pdev) "Failed to get the IDs of GPIOs to request\n"); dbgfs_entry = debugfs_create_dir(dev_name(dev), gpio_virtuser_dbg_root); - ret = devm_add_action_or_reset(dev, gpio_virtuser_debugfs_remove, - dbgfs_entry); - if (ret) - return ret; for (i = 0; i < num_ids; i++) { descs = devm_gpiod_get_array(dev, ids[i], GPIOD_ASIS); - if (IS_ERR(descs)) - return dev_err_probe(dev, PTR_ERR(descs), - "Failed to request the '%s' GPIOs\n", - ids[i]); + if (IS_ERR(descs)) { + ret = dev_err_probe(dev, PTR_ERR(descs), + "Failed to request the '%s' GPIOs\n", + ids[i]); + goto err_remove_debugfs; + } ret = gpio_virtuser_dbgfs_init_line_array_attrs(dev, descs, ids[i], dbgfs_entry); - if (ret) - return dev_err_probe(dev, ret, - "Failed to setup the debugfs array interface for the '%s' GPIOs\n", - ids[i]); + if (ret) { + dev_err_probe(dev, ret, + "Failed to setup the debugfs array interface for the '%s' GPIOs\n", + ids[i]); + goto err_remove_debugfs; + } for (j = 0; j < descs->ndescs; j++) { ret = gpio_virtuser_dbgfs_init_line_attrs(dev, descs->desc[j], ids[i], j, dbgfs_entry); - if (ret) - return dev_err_probe(dev, ret, - "Failed to setup the debugfs line interface for the '%s' GPIOs\n", - ids[i]); + if (ret) { + dev_err_probe(dev, ret, + "Failed to setup the debugfs line interface for the '%s' GPIOs\n", + ids[i]); + goto err_remove_debugfs; + } } } - return 0; + /* + * The debugfs files point to the devres-managed line data allocated + * above. Register the removal last so that it runs first on unbind, + * before any of that data is released. + */ + return devm_add_action_or_reset(dev, gpio_virtuser_debugfs_remove, + dbgfs_entry); + +err_remove_debugfs: + debugfs_remove_recursive(dbgfs_entry); + return ret; } static const struct of_device_id gpio_virtuser_of_match[] = { diff --git a/drivers/gpio/gpio-visconti.c b/drivers/gpio/gpio-visconti.c index 6d5d829634ad76..7701587a032845 100644 --- a/drivers/gpio/gpio-visconti.c +++ b/drivers/gpio/gpio-visconti.c @@ -167,7 +167,7 @@ static int visconti_gpio_probe(struct platform_device *pdev) struct device_node *irq_parent; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c index 84b3a973a503c7..f7e1530121b817 100644 --- a/drivers/gpio/gpio-vx855.c +++ b/drivers/gpio/gpio-vx855.c @@ -237,7 +237,7 @@ static int vx855gpio_probe(struct platform_device *pdev) if (!res_gpi || !res_gpo) return -EBUSY; - vg = devm_kzalloc(&pdev->dev, sizeof(*vg), GFP_KERNEL); + vg = devm_kzalloc_obj(&pdev->dev, *vg); if (!vg) return -ENOMEM; diff --git a/drivers/gpio/gpio-waveshare-dsi.c b/drivers/gpio/gpio-waveshare-dsi.c index 38f52351bb584d..dc8d946cfd2369 100644 --- a/drivers/gpio/gpio-waveshare-dsi.c +++ b/drivers/gpio/gpio-waveshare-dsi.c @@ -121,7 +121,7 @@ static int waveshare_gpio_probe(struct i2c_client *i2c) unsigned int data; int ret; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/gpio/gpio-wcd934x.c b/drivers/gpio/gpio-wcd934x.c index b526493c84e4de..8a645f033be4e8 100644 --- a/drivers/gpio/gpio-wcd934x.c +++ b/drivers/gpio/gpio-wcd934x.c @@ -82,7 +82,7 @@ static int wcd_gpio_probe(struct platform_device *pdev) struct wcd_gpio_data *data; struct gpio_chip *chip; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpio-wcove.c b/drivers/gpio/gpio-wcove.c index 4a5e20e936a95a..7852176a215005 100644 --- a/drivers/gpio/gpio-wcove.c +++ b/drivers/gpio/gpio-wcove.c @@ -425,7 +425,7 @@ static int wcove_gpio_probe(struct platform_device *pdev) dev = &pdev->dev; - wg = devm_kzalloc(dev, sizeof(*wg), GFP_KERNEL); + wg = devm_kzalloc_obj(dev, *wg); if (!wg) return -ENOMEM; diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index 489479d6f32b3a..059deb56d040c6 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c @@ -267,8 +267,7 @@ static int wm831x_gpio_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - wm831x_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm831x_gpio), - GFP_KERNEL); + wm831x_gpio = devm_kzalloc_obj(&pdev->dev, *wm831x_gpio); if (wm831x_gpio == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-wm8350.c b/drivers/gpio/gpio-wm8350.c index 46923b23a72eb9..35edf26e7be6ce 100644 --- a/drivers/gpio/gpio-wm8350.c +++ b/drivers/gpio/gpio-wm8350.c @@ -104,8 +104,7 @@ static int wm8350_gpio_probe(struct platform_device *pdev) struct wm8350_platform_data *pdata = dev_get_platdata(wm8350->dev); struct wm8350_gpio_data *wm8350_gpio; - wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio), - GFP_KERNEL); + wm8350_gpio = devm_kzalloc_obj(&pdev->dev, *wm8350_gpio); if (wm8350_gpio == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c index a0665cf3ff2f45..92e1eb3c763be4 100644 --- a/drivers/gpio/gpio-wm8994.c +++ b/drivers/gpio/gpio-wm8994.c @@ -267,8 +267,7 @@ static int wm8994_gpio_probe(struct platform_device *pdev) struct wm8994_pdata *pdata = dev_get_platdata(wm8994->dev); struct wm8994_gpio *wm8994_gpio; - wm8994_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8994_gpio), - GFP_KERNEL); + wm8994_gpio = devm_kzalloc_obj(&pdev->dev, *wm8994_gpio); if (wm8994_gpio == NULL) return -ENOMEM; diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 6289b0510cf2b2..cd0c35c057cbc3 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -252,7 +252,7 @@ static int ws16c48_probe(struct device *dev, unsigned int id) struct regmap_irq_chip *chip; struct regmap_irq_chip_data *chip_data; - ws16c48gpio = devm_kzalloc(dev, sizeof(*ws16c48gpio), GFP_KERNEL); + ws16c48gpio = devm_kzalloc_obj(dev, *ws16c48gpio); if (!ws16c48gpio) return -ENOMEM; @@ -271,7 +271,7 @@ static int ws16c48_probe(struct device *dev, unsigned int id) return dev_err_probe(dev, PTR_ERR(ws16c48gpio->map), "Unable to initialize register map\n"); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c index 3675456b1e9bd0..c87e15d6e1503d 100644 --- a/drivers/gpio/gpio-xgene-sb.c +++ b/drivers/gpio/gpio-xgene-sb.c @@ -245,7 +245,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) struct irq_domain *parent_domain = NULL; u32 val32; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpio/gpio-xgene.c b/drivers/gpio/gpio-xgene.c index 809668449dbe5a..8c8e6168fbe187 100644 --- a/drivers/gpio/gpio-xgene.c +++ b/drivers/gpio/gpio-xgene.c @@ -162,7 +162,7 @@ static int xgene_gpio_probe(struct platform_device *pdev) { struct xgene_gpio *gpio; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; diff --git a/drivers/gpio/gpio-xgs-iproc.c b/drivers/gpio/gpio-xgs-iproc.c index 77eb29dcc2171a..edffb435cf58e2 100644 --- a/drivers/gpio/gpio-xgs-iproc.c +++ b/drivers/gpio/gpio-xgs-iproc.c @@ -221,7 +221,7 @@ static int iproc_gpio_probe(struct platform_device *pdev) u32 num_gpios; int irq, ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 9406ce85f93308..7a93afae0ea0c4 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -540,7 +540,7 @@ static int xgpio_probe(struct platform_device *pdev) struct gpio_irq_chip *girq; u32 temp; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -633,8 +633,7 @@ static int xgpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &xgpio_irq_chip); girq->parent_handler = xgpio_irqhandler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) { status = -ENOMEM; goto err_pm_put; diff --git a/drivers/gpio/gpio-xlp.c b/drivers/gpio/gpio-xlp.c index aede6324387f41..e9618608f2a000 100644 --- a/drivers/gpio/gpio-xlp.c +++ b/drivers/gpio/gpio-xlp.c @@ -244,7 +244,7 @@ static int xlp_gpio_probe(struct platform_device *pdev) void __iomem *gpio_base; int irq, err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -283,9 +283,7 @@ static int xlp_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &xlp_gpio_irq_chip); girq->parent_handler = xlp_gpio_generic_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/gpio/gpio-xra1403.c b/drivers/gpio/gpio-xra1403.c index fe0fba6ea9027a..421de68abe07ea 100644 --- a/drivers/gpio/gpio-xra1403.c +++ b/drivers/gpio/gpio-xra1403.c @@ -149,7 +149,7 @@ static int xra1403_probe(struct spi_device *spi) struct gpio_desc *reset_gpio; int ret; - xra = devm_kzalloc(&spi->dev, sizeof(*xra), GFP_KERNEL); + xra = devm_kzalloc_obj(&spi->dev, *xra); if (!xra) return -ENOMEM; diff --git a/drivers/gpio/gpio-zevio.c b/drivers/gpio/gpio-zevio.c index 288a86c8294a16..b30b6a8a9d77b8 100644 --- a/drivers/gpio/gpio-zevio.c +++ b/drivers/gpio/gpio-zevio.c @@ -175,7 +175,7 @@ static int zevio_gpio_probe(struct platform_device *pdev) struct zevio_gpio *controller; int status, i; - controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); + controller = devm_kzalloc_obj(&pdev->dev, *controller); if (!controller) return -ENOMEM; diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c index 13e4c5f0e297ce..365c4fcf6d025e 100644 --- a/drivers/gpio/gpio-zynq.c +++ b/drivers/gpio/gpio-zynq.c @@ -908,7 +908,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) struct gpio_chip *chip; struct gpio_irq_chip *girq; - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + gpio = devm_kzalloc_obj(&pdev->dev, *gpio); if (!gpio) return -ENOMEM; @@ -968,9 +968,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &zynq_gpio_edge_irqchip); girq->parent_handler = zynq_gpio_irqhandler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) { ret = -ENOMEM; goto err_pm_put; diff --git a/drivers/gpio/gpio-zynqmp-modepin.c b/drivers/gpio/gpio-zynqmp-modepin.c index 5e651482e9850e..ad5b772cfde7ad 100644 --- a/drivers/gpio/gpio-zynqmp-modepin.c +++ b/drivers/gpio/gpio-zynqmp-modepin.c @@ -118,7 +118,7 @@ static int modepin_gpio_probe(struct platform_device *pdev) struct gpio_chip *chip; int status; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c index f005854e7ff7c3..6ab9a9e290b3d1 100644 --- a/drivers/gpio/gpiolib-kunit.c +++ b/drivers/gpio/gpiolib-kunit.c @@ -90,11 +90,11 @@ static int gpio_test_provider_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct gpio_chip *gc; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -572,7 +572,7 @@ static int gpio_unbind_consumer_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index f36e4b171fa7de..8f8454d5960469 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -725,7 +725,7 @@ int of_gpiochip_get_lflags(struct gpio_chip *chip, struct fwnode_reference_args *gpiospec, unsigned long *lflags) { - enum of_gpio_flags xlate_flags; + enum of_gpio_flags xlate_flags = 0; struct of_phandle_args args; struct gpio_desc *desc; diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h index 218cfe5bc4ac31..9ca540d93f93be 100644 --- a/drivers/gpio/gpiolib-of.h +++ b/drivers/gpio/gpiolib-of.h @@ -46,7 +46,7 @@ static inline bool of_gpiochip_instance_match(struct gpio_chip *gc, static inline int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) { - return 0; + return -ENOENT; } static inline int of_gpiochip_get_lflags(struct gpio_chip *chip, struct fwnode_reference_args *gpiospec, diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c index 8c9ac9d9330490..edb04a5bb987e1 100644 --- a/drivers/gpio/gpiolib-shared.c +++ b/drivers/gpio/gpiolib-shared.c @@ -635,20 +635,20 @@ static void gpio_shared_release(struct kref *kref) container_of(kref, struct gpio_shared_entry, ref); struct gpio_shared_desc *shared_desc; - guard(mutex)(&entry->lock); - shared_desc = entry->shared_desc; gpio_device_put(shared_desc->desc->gdev); mutex_destroy(&shared_desc->mutex); kfree(shared_desc); entry->shared_desc = NULL; + + mutex_unlock(&entry->lock); } static void gpiod_shared_put(void *data) { struct gpio_shared_entry *entry = data; - kref_put(&entry->ref, gpio_shared_release); + kref_put_mutex(&entry->ref, gpio_shared_release, &entry->lock); } static struct gpio_shared_desc * diff --git a/drivers/gpio/gpiolib-shared.h b/drivers/gpio/gpiolib-shared.h index 618756f6c6aafd..ae10506b7029f8 100644 --- a/drivers/gpio/gpiolib-shared.h +++ b/drivers/gpio/gpiolib-shared.h @@ -41,6 +41,7 @@ struct gpio_shared_desc { struct gpio_desc *desc; unsigned long cfg; unsigned int usecnt; + unsigned int cfgcnt; unsigned int votecnt; int def_val; struct mutex mutex; /* serializes all proxy operations on this descriptor */ diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index fbdeda2f278713..033c6fce4fc8da 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -154,9 +154,12 @@ static int desc_set_label(struct gpio_desc *desc, const char *label) memcpy(new->str, label, len); } - old = rcu_replace_pointer(desc->label, new, 1); - if (old) - call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label); + scoped_guard(spinlock, &desc->gdev->desc_lock) { + old = rcu_replace_pointer(desc->label, new, + lockdep_is_held(&desc->gdev->desc_lock)); + if (old) + call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label); + } return 0; } @@ -664,7 +667,7 @@ static int gpiochip_set_names(struct gpio_chip *chip) return 0; } - names = kcalloc(count, sizeof(*names), GFP_KERNEL); + names = kzalloc_objs(*names, count); if (!names) return -ENOMEM; @@ -750,7 +753,7 @@ static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc) if (size == 0) return 0; - ranges = kmalloc_array(size, sizeof(*ranges), GFP_KERNEL); + ranges = kmalloc_objs(*ranges, size); if (!ranges) return -ENOMEM; @@ -924,7 +927,8 @@ static const struct device_type gpio_dev_type = { /* * An initial reference count has been held in gpiochip_add_data_with_key(). - * The caller should drop the reference via gpio_device_put() on errors. + * A caller that tears the chip down on errors must drop the reference via + * gpio_device_put(). */ static int gpiochip_setup_dev(struct gpio_chip *gc) { @@ -975,7 +979,6 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) */ u32 cells = 2; - lflags = GPIO_LOOKUP_FLAGS_DEFAULT; dflags = GPIOD_ASIS; name = NULL; @@ -986,6 +989,8 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells); if (ret && is_of_node(fwnode)) return ret; + if (cells < 1 || cells > NR_FWNODE_REFERENCE_ARGS) + return -EINVAL; if (argc % cells) return -EINVAL; @@ -1014,6 +1019,8 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) fwnode_property_read_string(fwnode, "line-name", &name); for (unsigned int i = 0; i < num_hogs; i++) { + lflags = GPIO_LOOKUP_FLAGS_DEFAULT; + if (is_of_node(fwnode)) { /* * OF-nodes need some additional special handling for @@ -1039,9 +1046,10 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) } else { /* * GPIO_ACTIVE_LOW is currently the only lookup flag - * supported for non-OF firmware nodes. + * supported for non-OF firmware nodes and it must live + * in the second cell. */ - if (gpios[i * cells + 1]) + if (cells > 1 && gpios[i * cells + 1]) lflags |= GPIO_ACTIVE_LOW; } @@ -1099,12 +1107,16 @@ static void gpiochip_setup_devs(void) continue; } + /* + * The reference taken in gpiochip_add_data_with_key() is + * dropped by gpiochip_remove(): this chip is still registered + * and its driver has not been told about the failure, so the + * reference must be kept here. + */ ret = gpiochip_setup_dev(gc); - if (ret) { - gpio_device_put(gdev); + if (ret) dev_err(&gdev->dev, "Failed to initialize gpio device (%d)\n", ret); - } } } @@ -1201,6 +1213,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, goto err_free_ida; rcu_assign_pointer(gdev->chip, gc); + spin_lock_init(&gdev->desc_lock); + ret = init_srcu_struct(&gdev->desc_srcu); if (ret) goto err_cleanup_gdev_srcu; @@ -5243,21 +5257,21 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, if (!descs) return ERR_PTR(-ENOMEM); - for (descs->ndescs = 0; descs->ndescs < count; descs->ndescs++) { - desc = gpiod_get_index(dev, con_id, descs->ndescs, flags); + for (int i = 0; i < count; i++) { + desc = gpiod_get_index(dev, con_id, i, flags); if (IS_ERR(desc)) { gpiod_put_array(descs); return ERR_CAST(desc); } - descs->desc[descs->ndescs] = desc; + descs->desc[descs->ndescs++] = desc; gdev = gpiod_to_gpio_device(desc); /* * If pin hardware number of array member 0 is also 0, select * its chip as a candidate for fast bitmap processing path. */ - if (descs->ndescs == 0 && gpiod_hwgpio(desc) == 0) { + if (i == 0 && gpiod_hwgpio(desc) == 0) { struct gpio_descs *array; bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ? @@ -5282,10 +5296,8 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, array_info->desc = descs->desc; array_info->size = count; array_info->gdev = gdev; - bitmap_set(array_info->get_mask, descs->ndescs, - count - descs->ndescs); - bitmap_set(array_info->set_mask, descs->ndescs, - count - descs->ndescs); + bitmap_set(array_info->get_mask, 0, count); + bitmap_set(array_info->set_mask, 0, count); descs->info = array_info; } @@ -5295,38 +5307,35 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, /* Unmark array members which don't belong to the 'fast' chip */ if (array_info->gdev != gdev) { - __clear_bit(descs->ndescs, array_info->get_mask); - __clear_bit(descs->ndescs, array_info->set_mask); + __clear_bit(i, array_info->get_mask); + __clear_bit(i, array_info->set_mask); } /* * Detect array members which belong to the 'fast' chip * but their pins are not in hardware order. */ - else if (gpiod_hwgpio(desc) != descs->ndescs) { + else if (gpiod_hwgpio(desc) != i) { /* * Don't use fast path if all array members processed so * far belong to the same chip as this one but its pin * hardware number is different from its array index. */ - if (bitmap_full(array_info->get_mask, descs->ndescs)) { + if (bitmap_full(array_info->get_mask, i)) { + descs->info = NULL; array_info = NULL; } else { - __clear_bit(descs->ndescs, - array_info->get_mask); - __clear_bit(descs->ndescs, - array_info->set_mask); + __clear_bit(i, array_info->get_mask); + __clear_bit(i, array_info->set_mask); } } else { dflags = READ_ONCE(desc->flags); /* Exclude open drain or open source from fast output */ if (test_bit(GPIOD_FLAG_OPEN_DRAIN, &dflags) || test_bit(GPIOD_FLAG_OPEN_SOURCE, &dflags)) - __clear_bit(descs->ndescs, - array_info->set_mask); + __clear_bit(i, array_info->set_mask); /* Identify 'fast' pins which require invertion */ if (gpiod_is_active_low(desc)) - __set_bit(descs->ndescs, - array_info->invert_mask); + __set_bit(i, array_info->invert_mask); } } if (array_info) diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 650a702741dfb9..8dd8ea747f8a90 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -37,6 +37,7 @@ struct fwnode_handle; * @valid_mask: If not %NULL, holds bitmask of GPIOs which are valid to be * used from the chip. * @desc_srcu: ensures consistent state of GPIO descriptors exposed to users + * @desc_lock: synchronizes the updates to descriptor labels * @ngpio: the number of GPIO lines on this GPIO device, equal to the size * of the @descs array. * @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep @@ -71,6 +72,7 @@ struct gpio_device { struct gpio_desc *descs; unsigned long *valid_mask; struct srcu_struct desc_srcu; + spinlock_t desc_lock; unsigned int base; u16 ngpio; bool can_sleep; diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c index 503f7d5934e4b9..6d5b92cae8758d 100644 --- a/drivers/gpu/buddy.c +++ b/drivers/gpu/buddy.c @@ -876,21 +876,17 @@ int gpu_buddy_init(struct gpu_buddy *mm, u64 size, u64 chunk_size) BUG_ON(mm->max_order > GPU_BUDDY_MAX_ORDER); - mm->free_scoreboard = kcalloc(mm->max_order + 1, - sizeof(*mm->free_scoreboard), - GFP_KERNEL); + mm->free_scoreboard = kzalloc_objs(*mm->free_scoreboard, + mm->max_order + 1); if (!mm->free_scoreboard) return -ENOMEM; - mm->used_scoreboard = kcalloc(mm->max_order + 1, - sizeof(*mm->used_scoreboard), - GFP_KERNEL); + mm->used_scoreboard = kzalloc_objs(*mm->used_scoreboard, + mm->max_order + 1); if (!mm->used_scoreboard) goto out_free_free_scoreboard; - mm->free_tree = kcalloc(mm->max_order + 1, - sizeof(struct rb_root), - GFP_KERNEL); + mm->free_tree = kzalloc_objs(struct rb_root, mm->max_order + 1); if (!mm->free_tree) goto out_free_used_scoreboard; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 78a6f743137ebf..c7577b608f3e41 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -157,7 +157,6 @@ struct amdgpu_watchdog_timer { * Modules parameters. */ extern int amdgpu_modeset; -extern int amdgpu_iommu_perfopt; extern unsigned int amdgpu_vram_limit; extern int amdgpu_vis_vram_limit; extern int amdgpu_gart_size; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c index 63088c072087ac..4874ee864b8071 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c @@ -406,7 +406,11 @@ int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif) characteristics.max_input_signal; atif->backlight_caps.ac_level = characteristics.ac_level; atif->backlight_caps.dc_level = characteristics.dc_level; - atif->backlight_caps.data_points = characteristics.number_of_points; + if (characteristics.number_of_points > ATIF_QBTC_MAX_DATA_POINTS) + pr_warn(FW_BUG "ATIF: backlight curve has %u points, using the first %u\n", + characteristics.number_of_points, ATIF_QBTC_MAX_DATA_POINTS); + atif->backlight_caps.data_points = min_t(u8, characteristics.number_of_points, + ATIF_QBTC_MAX_DATA_POINTS); memcpy(atif->backlight_caps.luminance_data, characteristics.data_points, sizeof(atif->backlight_caps.luminance_data)); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h index 77c0504cc158dd..74dc307e5140af 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h @@ -344,7 +344,8 @@ int amdgpu_amdkfd_gpuvm_map_bo_to_kernel(struct kgd_mem *mem, void **kptr, u64 *size, u32 domain); void amdgpu_amdkfd_gpuvm_unmap_bo_from_kernel(struct kgd_mem *mem); -int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_bo *bo, struct amdgpu_bo **bo_gart); +int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_bo *bo, struct amdgpu_bo **bo_gart, + struct amdkfd_process_info *process_info); int amdgpu_amdkfd_gpuvm_restore_process_bos(void *process_info, struct dma_fence __rcu **ef); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 3a4b3424b5b291..1b79c9f182b1db 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -916,7 +916,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, } for (i = 0; i <= is_aql; i++) { - attachment[i] = kzalloc(sizeof(*attachment[i]), GFP_KERNEL); + attachment[i] = kzalloc_obj(*attachment[i]); if (unlikely(!attachment[i])) { ret = -ENOMEM; goto unwind; @@ -975,11 +975,11 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, ret = amdgpu_vm_lock_pd(vm, &exec, 0); drm_exec_retry_on_contention(&exec); if (unlikely(ret)) - goto unwind; + goto unlock; ret = drm_exec_lock_obj(&exec, &bo[i]->tbo.base); drm_exec_retry_on_contention(&exec); if (unlikely(ret)) - goto unwind; + goto unlock; } bo_va = amdgpu_vm_bo_find(vm, bo[i]); @@ -1005,6 +1005,8 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, return 0; +unlock: + drm_exec_fini(&exec); unwind: for (; i >= 0; i--) { if (!attachment[i]) @@ -2261,11 +2263,13 @@ int amdgpu_amdkfd_gpuvm_sync_memory( * amdgpu_amdkfd_map_gtt_bo_to_gart - Map BO to GART and increment reference count * @bo: Buffer object to be mapped * @bo_gart: Return bo reference + * @process_info: KFD process info of the queue the BO is for * * Before return, bo reference count is incremented. To release the reference and unpin/ * unmap the BO, call amdgpu_amdkfd_free_kernel_mem. */ -int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_bo *bo, struct amdgpu_bo **bo_gart) +int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_bo *bo, struct amdgpu_bo **bo_gart, + struct amdkfd_process_info *process_info) { int ret; @@ -2287,8 +2291,8 @@ int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_bo *bo, struct amdgpu_bo **bo goto err_map_bo_gart_failed; } - amdgpu_amdkfd_remove_eviction_fence( - bo, bo->vm_bo->vm->process_info->eviction_fence); + /* bo->vm_bo can be the VM of any file which opened the BO */ + amdgpu_amdkfd_remove_eviction_fence(bo, process_info->eviction_fence); amdgpu_bo_unreserve(bo); @@ -2473,6 +2477,9 @@ static int import_obj_create(struct amdgpu_device *adev, err_remove_mem: remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info); + amdgpu_sync_free(&(*mem)->sync); + mutex_destroy(&(*mem)->lock); + dma_buf_put(dma_buf); drm_vma_node_revoke(&obj->vma_node, drm_priv); err_free_mem: kfree(*mem); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index d69018a14d96de..e552ee0487a72d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -150,7 +150,12 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p, if (size != PAGE_SIZE || data->offset > (size - 8)) return -EINVAL; - if (amdgpu_ttm_tt_get_usermm(p->uf_bo->tbo.ttm)) + if (amdgpu_ttm_tt_is_userptr(p->uf_bo->tbo.ttm)) + return -EINVAL; + + /* The GPU writes the user fence through the GART */ + if (p->uf_bo->preferred_domains != AMDGPU_GEM_DOMAIN_GTT && + p->uf_bo->allowed_domains != AMDGPU_GEM_DOMAIN_GTT) return -EINVAL; *offset = data->offset; @@ -189,18 +194,22 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, int ret; int i; + if (cs->in.flags) + return -EINVAL; + chunk_array = memdup_array_user(u64_to_user_ptr(cs->in.chunks), cs->in.num_chunks, sizeof(uint64_t)); if (IS_ERR(chunk_array)) return PTR_ERR(chunk_array); - p->nchunks = cs->in.num_chunks; - p->chunks = kvmalloc_objs(struct amdgpu_cs_chunk, p->nchunks); + /* parser_fini() walks nchunks chunks, set it once they exist */ + p->chunks = kvmalloc_objs(struct amdgpu_cs_chunk, cs->in.num_chunks); if (!p->chunks) { ret = -ENOMEM; goto free_chunk; } + p->nchunks = cs->in.num_chunks; for (i = 0; i < p->nchunks; i++) { struct drm_amdgpu_cs_chunk __user *chunk_ptr = NULL; @@ -1072,7 +1081,7 @@ static int amdgpu_cs_patch_ibs(struct amdgpu_cs_parser *p, if (r) return r; - kptr += va_start - (m->start * AMDGPU_GPU_PAGE_SIZE); + kptr += va_start - (m->start * AMDGPU_GPU_PAGE_SIZE) + m->offset; if (ring->funcs->parse_cs) { memcpy(ib->ptr, kptr, ib->length_dw * 4); @@ -1308,10 +1317,8 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, fence = &p->jobs[i]->base.s_fence->scheduled; dma_fence_get(fence); r = drm_sched_job_add_dependency(&leader->base, fence); - if (r) { - dma_fence_put(fence); + if (r) return r; - } } if (p->gang_size > 1) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c index 3dc95d9accf2db..80a90dc70ffaf5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c @@ -1002,7 +1002,7 @@ static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf, if (size & 0x3 || *pos & 0x3) return -EINVAL; - config = kmalloc_array(256, sizeof(*config), GFP_KERNEL); + config = kmalloc_objs(*config, 256); if (!config) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 53f05ee7193f20..19a566187dfb56 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -3770,28 +3769,6 @@ amdgpu_device_should_register_switcheroo(struct amdgpu_device *adev, bool px) apple_gmux_detect(NULL, NULL))); } -static inline bool amdgpu_device_identity(struct amdgpu_device *adev) -{ - struct pci_dev *pdev = adev->pdev; - struct iommu_domain *domain = iommu_get_domain_for_dev(&pdev->dev); - - if (!domain) - return false; - - return domain->type == IOMMU_DOMAIN_IDENTITY; -} - -static bool amdgpu_device_use_perfopt(struct amdgpu_device *adev) -{ - if (amdgpu_iommu_perfopt == 0) - return false; - - if (!(adev->flags & AMD_IS_APU)) - return false; - - return amdgpu_device_identity(adev); -} - /** * amdgpu_device_init - initialize the driver * @@ -4001,16 +3978,6 @@ int amdgpu_device_init(struct amdgpu_device *adev, if (r) return r; - if (amdgpu_device_use_perfopt(adev)) { - int perfopt_ret = amd_iommu_enable_perfopt(pdev); - - /* Optional optimization; a failure to arm it must not abort probe. */ - if (perfopt_ret) - dev_warn(adev->dev, - "Failed to enable IOMMU PerfOpt (%d); continuing without it\n", - perfopt_ret); - } - /* * No need to remove conflicting FBs for non-display class devices. * This prevents the sysfb from being freed accidently. @@ -4380,9 +4347,6 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_gart_dummy_page_fini(adev); - if (amdgpu_device_use_perfopt(adev)) - amd_iommu_disable_perfopt(adev->pdev); - if (pci_dev_is_disconnected(adev->pdev)) amdgpu_device_unmap_mmio(adev); @@ -4746,20 +4710,6 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) return 0; - if (amdgpu_device_use_perfopt(adev)) { - int perfopt_ret = amd_iommu_enable_perfopt(adev->pdev); - - /* - * Must not return on failure: a bare return would leak the - * SR-IOV VF exclusive-mode acquisition taken above (released - * via the exit: path). - */ - if (perfopt_ret) - dev_warn(adev->dev, - "Failed to enable IOMMU PerfOpt (%d); continuing without it\n", - perfopt_ret); - } - if (adev->in_s0ix) amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D0Entry); @@ -5577,7 +5527,21 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev, struct amdgpu_device *tmp_adev = NULL; int i; - /* block all schedulers and reset given job's ring */ + /* Stop job submission first, the preparation below can take seconds */ + list_for_each_entry(tmp_adev, device_list, reset_list) { + for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { + struct amdgpu_ring *ring = tmp_adev->rings[i]; + + if (!amdgpu_ring_sched_ready(ring)) + continue; + + drm_sched_wqueue_stop(&ring->sched); + + if (need_emergency_restart) + amdgpu_job_stop_all_jobs_on_sched(&ring->sched); + } + } + list_for_each_entry(tmp_adev, device_list, reset_list) { amdgpu_device_set_mp1_state(tmp_adev); @@ -5613,18 +5577,6 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev, amdgpu_ras_suspend(tmp_adev); amdgpu_userq_pre_reset(tmp_adev); - - for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { - struct amdgpu_ring *ring = tmp_adev->rings[i]; - - if (!amdgpu_ring_sched_ready(ring)) - continue; - - drm_sched_wqueue_stop(&ring->sched); - - if (need_emergency_restart) - amdgpu_job_stop_all_jobs_on_sched(&ring->sched); - } atomic_inc(&tmp_adev->gpu_reset_counter); } } @@ -5859,8 +5811,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, amdgpu_device_halt_activities(adev, job, reset_context, &device_list, hive, need_emergency_restart); - if (need_emergency_restart) - goto skip_sched_resume; + if (need_emergency_restart) { + amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart); + goto reset_unlock; + } /* * Must check guilty signal here since after this point all old * HW fences are force signaled. @@ -5870,18 +5824,17 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, if (job && (dma_fence_get_status(&job->hw_fence->base) > 0)) { job_signaled = true; dev_info(adev->dev, "Guilty job already signaled, skipping HW reset"); - goto skip_hw_reset; + goto post_resume; } r = amdgpu_device_asic_reset(adev, &device_list, reset_context); if (r) goto reset_unlock; -skip_hw_reset: +post_resume: + amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart); r = amdgpu_device_sched_resume(&device_list, reset_context, job_signaled); if (r) goto reset_unlock; -skip_sched_resume: - amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart); reset_unlock: amdgpu_device_recovery_put_reset_lock(adev, &device_list); amdgpu_ras_post_reset(adev, &device_list); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c index 890792a94e09f7..22cec7ac57fde4 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c @@ -1468,6 +1468,40 @@ static int amdgpu_discovery_sysfs_recurse(struct amdgpu_device *adev, return 0; } +#define list_to_kobj(el) container_of(el, struct kobject, entry) + +static void amdgpu_discovery_sysfs_update_harvest(struct amdgpu_device *adev) +{ + struct ip_discovery_top *ip_top = adev->discovery.ip_top; + struct ip_die_entry *ip_die_entry; + struct list_head *el_die, *el_hw_id, *el_hw_inst; + struct ip_hw_id *hw_id; + struct kset *die_kset; + struct ip_hw_instance *ip_inst; + + if (!ip_top) + return; + + die_kset = &ip_top->die_kset; + + guard(spinlock)(&die_kset->list_lock); + list_for_each(el_die, &die_kset->list) { + ip_die_entry = to_ip_die_entry(list_to_kobj(el_die)); + + list_for_each(el_hw_id, &ip_die_entry->ip_kset.list) { + hw_id = to_ip_hw_id(list_to_kobj(el_hw_id)); + + list_for_each(el_hw_inst, &hw_id->hw_id_kset.list) { + ip_inst = to_ip_hw_instance(list_to_kobj(el_hw_inst)); + ip_inst->harvest = + amdgpu_discovery_get_harvest_info( + adev, ip_inst->hw_id, + ip_inst->num_instance); + } + } + } +} + static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev) { uint8_t *discovery_bin = adev->discovery.bin; @@ -1478,9 +1512,13 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev) if (!discovery_bin) return -EINVAL; - /* If early init already created sysfs in standalone mode, skip normal init */ - if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) + /* If early init already created sysfs in standalone mode, update harvest info + * now that adev is fully initialized, then skip the rest of normal init. + */ + if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) { + amdgpu_discovery_sysfs_update_harvest(adev); return 0; + } ip_top = kzalloc_obj(*ip_top); if (!ip_top) @@ -1535,8 +1573,6 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev) /* -------------------------------------------------- */ -#define list_to_kobj(el) container_of(el, struct kobject, entry) - static void amdgpu_discovery_sysfs_ip_hw_free(struct ip_hw_id *ip_hw_id) { struct list_head *el, *tmp; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c index bbe518757907da..7b85152d6872ca 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c @@ -556,6 +556,11 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach) continue; } + if (!amdgpu_vm_ready(vm)) { + dma_resv_unlock(resv); + continue; + } + /* Reserve fences for two SDMA page table updates */ r = dma_resv_reserve_fences(resv, 2); if (!r) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 731fe8f9e92283..3e5634de077f1a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -188,7 +188,6 @@ char *amdgpu_disable_cu; char *amdgpu_virtual_display; int amdgpu_enforce_isolation = -1; int amdgpu_modeset = -1; -int amdgpu_iommu_perfopt = -1; /* Specifies the default granularity for SVM, used in buffer * migration and restoration of backing memory when handling @@ -399,17 +398,6 @@ module_param_named(fw_load_type, amdgpu_fw_load_type, int, 0444); MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)"); module_param_named(aspm, amdgpu_aspm, int, 0444); -/** - * DOC: iommu_perfopt (int) - * Control the AMD IOMMU PerfOpt DMA-latency optimization - * (0 = disable; -1 = enable on supported devices). - * This arms the IOMMU PerfOpt control (IOMMU spec, MMIO Offset 016Ch, EFR PerfOptSup / PerfOptEn) - * Arming it disables ATS, PRI, PASID and SVA for the GPU and removes IOMMU DMA containment for it, - * trading isolation for lower DMA latency. - */ -MODULE_PARM_DESC(iommu_perfopt, "Control IOMMU PerfOpt DMA-latency optimization (-1 = enable on supported devices, 0 = disable)"); -module_param_named(iommu_perfopt, amdgpu_iommu_perfopt, int, 0444); - /** * DOC: runpm (int) * Override for runtime power management control for dGPUs. The amdgpu driver can dynamically power down diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 3962b9f08dd67b..b190b6c9adf299 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -826,8 +826,10 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev, /* Always update PDEs after we touched the mappings. */ r = amdgpu_vm_update_pdes(adev, vm, false); - if (r) - goto error; + +error: + if (r && r != -ERESTARTSYS) + DRM_ERROR("Couldn't update BO_VA (%d)\n", r); if ((operation == AMDGPU_VA_OP_MAP || operation == AMDGPU_VA_OP_REPLACE) && @@ -836,27 +838,27 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev, /* * For MAP/REPLACE of non per-VM BOs we need to sync to both the * bo_va->last_pt_update and vm->last_update or otherwise we - * potentially miss the PDE updates. + * potentially miss the PDE updates or TLB invalidation. */ fence = dma_fence_unwrap_merge(vm->last_update, + vm->last_tlb_inv, bo_va->last_pt_update); - if (!fence) { - /* As fallback in OOM situations */ - dma_fence_wait(vm->last_update, false); + if (!fence) dma_fence_wait(bo_va->last_pt_update, false); - fence = dma_fence_get_stub(); - } + } else { - fence = dma_fence_get(vm->last_update); + fence = dma_fence_unwrap_merge(vm->last_update, + vm->last_tlb_inv); } - return fence; - -error: - if (r && r != -ERESTARTSYS) - DRM_ERROR("Couldn't update BO_VA (%d)\n", r); + if (!fence) { + /* As fallback in OOM situations */ + dma_fence_wait(vm->last_update, false); + dma_fence_wait(vm->last_tlb_inv, false); + fence = dma_fence_get_stub(); + } - return dma_fence_get(vm->last_update); + return fence; } int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, @@ -1064,6 +1066,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { + struct amdgpu_device *adev = drm_to_adev(dev); struct drm_amdgpu_gem_op *args = data; struct drm_gem_object *gobj; struct amdgpu_vm_bo_base *base; @@ -1162,7 +1165,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, goto out_exec; } - vm_entries = kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL); + vm_entries = kvzalloc_objs(*vm_entries, args->num_entries); if (!vm_entries) { r = -ENOMEM; goto out_exec; @@ -1170,7 +1173,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, amdgpu_vm_bo_va_for_each_valid_mapping(bo_va, mapping) { if (num_mappings < args->num_entries) { - vm_entries[num_mappings].addr = mapping->start * AMDGPU_GPU_PAGE_SIZE; + vm_entries[num_mappings].addr = + amdgpu_gmc_sign_extend(mapping->start * AMDGPU_GPU_PAGE_SIZE); vm_entries[num_mappings].size = (mapping->last - mapping->start + 1) * AMDGPU_GPU_PAGE_SIZE; vm_entries[num_mappings].offset = mapping->offset; vm_entries[num_mappings].flags = mapping->flags; @@ -1180,7 +1184,8 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, amdgpu_vm_bo_va_for_each_invalid_mapping(bo_va, mapping) { if (num_mappings < args->num_entries) { - vm_entries[num_mappings].addr = mapping->start * AMDGPU_GPU_PAGE_SIZE; + vm_entries[num_mappings].addr = + amdgpu_gmc_sign_extend(mapping->start * AMDGPU_GPU_PAGE_SIZE); vm_entries[num_mappings].size = (mapping->last - mapping->start + 1) * AMDGPU_GPU_PAGE_SIZE; vm_entries[num_mappings].offset = mapping->offset; vm_entries[num_mappings].flags = mapping->flags; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c index 5d4276cd0f7d37..efa0bc1e432abd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c @@ -1395,6 +1395,40 @@ static ssize_t available_memory_partition_show(struct device *dev, return size; } +void amdgpu_gmc_set_requested_nps_mode(struct amdgpu_device *adev, + enum amdgpu_memory_partition mode) +{ + struct amdgpu_hive_info *hive; + + /* If device is part of hive, all devices in the hive should request the + * same mode. Hence store the requested mode in hive. + */ + hive = amdgpu_get_xgmi_hive(adev); + if (hive) { + atomic_set(&hive->requested_nps_mode, mode); + amdgpu_put_xgmi_hive(hive); + } else { + adev->gmc.requested_nps_mode = mode; + } +} + +enum amdgpu_memory_partition +amdgpu_gmc_get_requested_nps_mode(struct amdgpu_device *adev) +{ + struct amdgpu_hive_info *hive; + enum amdgpu_memory_partition mode; + + hive = amdgpu_get_xgmi_hive(adev); + if (hive) { + mode = atomic_read(&hive->requested_nps_mode); + amdgpu_put_xgmi_hive(hive); + } else { + mode = adev->gmc.requested_nps_mode; + } + + return mode; +} + static ssize_t current_memory_partition_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -1402,7 +1436,6 @@ static ssize_t current_memory_partition_store(struct device *dev, struct drm_device *ddev = dev_get_drvdata(dev); struct amdgpu_device *adev = drm_to_adev(ddev); enum amdgpu_memory_partition mode; - struct amdgpu_hive_info *hive; int i; mode = UNKNOWN_MEMORY_PARTITION_MODE; @@ -1416,23 +1449,16 @@ static ssize_t current_memory_partition_store(struct device *dev, if (mode == UNKNOWN_MEMORY_PARTITION_MODE) return -EINVAL; - if (mode == adev->gmc.gmc_funcs->query_mem_partition_mode(adev)) { + if (mode == amdgpu_gmc_get_requested_nps_mode(adev)) { dev_info( adev->dev, - "requested NPS mode is same as current NPS mode, skipping\n"); + "requested NPS mode is same as current/already requested NPS mode, skipping\n"); return count; } - /* If device is part of hive, all devices in the hive should request the - * same mode. Hence store the requested mode in hive. - */ - hive = amdgpu_get_xgmi_hive(adev); - if (hive) { - atomic_set(&hive->requested_nps_mode, mode); - amdgpu_put_xgmi_hive(hive); - } else { - adev->gmc.requested_nps_mode = mode; - } + amdgpu_gmc_set_requested_nps_mode(adev, mode); + if (mode == amdgpu_gmc_query_memory_partition(adev)) + return count; dev_info( adev->dev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h index 76e6f1f96913c0..89f1ee829eea68 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h @@ -484,6 +484,10 @@ enum amdgpu_memory_partition amdgpu_gmc_get_memory_partition(struct amdgpu_device *adev, u32 *supp_modes); enum amdgpu_memory_partition amdgpu_gmc_query_memory_partition(struct amdgpu_device *adev); +void amdgpu_gmc_set_requested_nps_mode(struct amdgpu_device *adev, + enum amdgpu_memory_partition mode); +enum amdgpu_memory_partition +amdgpu_gmc_get_requested_nps_mode(struct amdgpu_device *adev); int amdgpu_gmc_init_mem_ranges(struct amdgpu_device *adev); void amdgpu_gmc_init_sw_mem_ranges(struct amdgpu_device *adev, struct amdgpu_mem_partition_info *mem_ranges); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c index a7d13e337d8468..7badbdf2252c44 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c @@ -177,7 +177,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, unsigned long end; int r; - pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL); + pfns = kvmalloc_objs(*pfns, npages); if (unlikely(!pfns)) { r = -ENOMEM; goto out_free_range; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c index 87f879a2e4f46a..917d649e2090ac 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c @@ -95,13 +95,27 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) return 0; } -int amdgpu_jpeg_suspend(struct amdgpu_device *adev) +int amdgpu_jpeg_early_fini(struct amdgpu_ip_block *ip_block) { - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Called on teardown even if sw_init never ran */ + if (!ip_block->status.sw) + return 0; + + /* hw_fini may not wait while a peer in the reset domain resets */ + cancel_delayed_work_sync(&ip_block->adev->jpeg.idle_work); return 0; } +void amdgpu_jpeg_cancel_idle_work(struct amdgpu_device *adev) +{ + /* The reset mustn't wait for the idle work, which waits for the reset */ + if (amdgpu_in_reset(adev)) + cancel_delayed_work(&adev->jpeg.idle_work); + else + cancel_delayed_work_sync(&adev->jpeg.idle_work); +} + int amdgpu_jpeg_resume(struct amdgpu_device *adev) { return 0; @@ -114,6 +128,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) unsigned int fences = 0; unsigned int i, j; + /* Nothing holding the reset semaphore waits for this work */ + down_read(&adev->reset_domain->sem); + for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -129,6 +146,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT); + + up_read(&adev->reset_domain->sem); } void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) @@ -136,7 +155,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) struct amdgpu_device *adev = ring->adev; if (!atomic_fetch_inc(&adev->jpeg.total_submission_cnt)) - cancel_delayed_work_sync(&adev->jpeg.idle_work); + amdgpu_jpeg_cancel_idle_work(adev); mutex_lock(&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_JPEG, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h index 05d58e6bbfabcf..9c4f251e03f625 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h @@ -156,11 +156,12 @@ struct amdgpu_jpeg { int amdgpu_jpeg_sw_init(struct amdgpu_device *adev); int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev); -int amdgpu_jpeg_suspend(struct amdgpu_device *adev); +int amdgpu_jpeg_early_fini(struct amdgpu_ip_block *ip_block); int amdgpu_jpeg_resume(struct amdgpu_device *adev); void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring); void amdgpu_jpeg_ring_end_use(struct amdgpu_ring *ring); +void amdgpu_jpeg_cancel_idle_work(struct amdgpu_device *adev); int amdgpu_jpeg_dec_ring_test_ring(struct amdgpu_ring *ring); int amdgpu_jpeg_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 59ea7af5b0e43f..335c523592bfa3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -919,8 +919,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) if (ret) return ret; - regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), - GFP_KERNEL); + regs = kmalloc_objs(*regs, info->read_mmr_reg.count); if (!regs) return -ENOMEM; @@ -1518,7 +1517,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) if (r < 0) goto pm_put; - fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); + fpriv = kzalloc_obj(*fpriv); if (unlikely(!fpriv)) { r = -ENOMEM; goto out_suspend; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c index 8d813c68450bf2..384510c343cd13 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c @@ -1191,7 +1191,11 @@ static void amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work) userq_notify_unmap_work.work); struct amdgpu_device *adev = mes->adev; - amdgpu_mes_notify_unmap_queue(adev); + /* MES is unusable during GPU recovery; the re-arm below retries later */ + if (down_read_trylock(&adev->reset_domain->sem)) { + amdgpu_mes_notify_unmap_queue(adev); + up_read(&adev->reset_domain->sem); + } /* Re-arm if still oversubscribed */ if (atomic_read(&mes->userq_hw_queue_count) > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index 47e852c15c3680..f47fc2135af051 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -244,7 +244,7 @@ static int amdgpu_check_address_validity(struct amdgpu_device *adev, (address >= RAS_UMC_INJECT_ADDR_LIMIT)) return -EFAULT; - page_pfns = kcalloc(nr_page_pfns, sizeof(*page_pfns), GFP_KERNEL); + page_pfns = kzalloc_objs(*page_pfns, nr_page_pfns); if (!page_pfns) return -ENOMEM; @@ -1506,7 +1506,8 @@ int amdgpu_ras_reset_error_count(struct amdgpu_device *adev, return -EOPNOTSUPP; } - if (!amdgpu_ras_is_supported(adev, block)) + if (!amdgpu_ras_is_supported(adev, block) || + !amdgpu_ras_mgr_get_debug_mode(adev)) return -EOPNOTSUPP; if (amdgpu_sriov_vf(adev)) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c index d6ae9974c952ee..4f31021b215205 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c @@ -447,10 +447,8 @@ int amdgpu_sync_push_to_job(struct amdgpu_sync *sync, struct amdgpu_job *job) dma_fence_get(f); r = drm_sched_job_add_dependency(&job->base, f); - if (r) { - dma_fence_put(f); + if (r) return r; - } } return 0; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c index 6cd3927a7e825e..d025b4183b2964 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c @@ -1085,7 +1085,7 @@ static void activate_accelerator(struct amdgpu_device *adev) static void deactivate_accelerator(struct amdgpu_device *adev) { - if (adev->ualink.info->accel_state < AMDGPU_UALINK_ACCEL_STATE_ACTIVE) + if (adev->ualink.info->accel_state != AMDGPU_UALINK_ACCEL_STATE_ACTIVE) return; dev_info(adev->dev, @@ -1534,10 +1534,10 @@ int ualink_ip_sw_init(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; struct amdgpu_ualink_info *info; - info = kzalloc(sizeof(*info), GFP_KERNEL); - ppod_setup = kzalloc(sizeof(*ppod_setup), GFP_KERNEL); - vpod_config = kzalloc(sizeof(*vpod_config), GFP_KERNEL); - stations = kzalloc(sizeof(*stations), GFP_KERNEL); + info = kzalloc_obj(*info); + ppod_setup = kzalloc_obj(*ppod_setup); + vpod_config = kzalloc_obj(*vpod_config); + stations = kzalloc_obj(*stations); if (!info || !ppod_setup || !vpod_config || !stations) { kfree(info); kfree(ppod_setup); @@ -3555,7 +3555,7 @@ static void amdgpu_ualink_process_npa_req_msg(struct amdgpu_device *adev, range_end = 0; } - mm_node = kzalloc(sizeof(*mm_node), GFP_KERNEL); + mm_node = kzalloc_obj(*mm_node); if (!mm_node) { dev_warn(adev->dev, "NPA-REQ: mm_node alloc failed handle:%llx:%llx\n", @@ -3926,7 +3926,7 @@ int amdgpu_ualink_import_handle(struct drm_device *dev, * to the NPA address. * First store the entry in the Xarray. */ - imp_xa_node = kzalloc(sizeof(*imp_xa_node), GFP_KERNEL); + imp_xa_node = kzalloc_obj(*imp_xa_node); if (!imp_xa_node) { r = -ENOMEM; goto out; @@ -4030,7 +4030,7 @@ int amdgpu_ualink_export_handle(struct drm_device *dev, struct drm_file *filp, /* If no ualink handle generated for BO, then generate one and * add it to the exporter Xarray. */ - exp_xa_node = kzalloc(sizeof(*exp_xa_node), GFP_KERNEL); + exp_xa_node = kzalloc_obj(*exp_xa_node); if (!exp_xa_node) { dev_err(adev->dev, "Failed to allocate exp_xa_node\n"); r = -ENOMEM; @@ -5181,7 +5181,7 @@ static int amdgpu_ualink_gart_map(struct amdgpu_device *adev, u64 npages, dev_dbg(adev->dev, "npa 0x%llx npages 0x%llx\n", npa, npages); if (npages > 1) { - dma_addr = kmalloc_array(npages, sizeof(*dma_addr), GFP_KERNEL); + dma_addr = kmalloc_objs(*dma_addr, npages); if (!dma_addr) return -ENOMEM; @@ -6328,7 +6328,7 @@ int amdgpu_ualink_sw_init(struct amdgpu_device *adev) struct amdgpu_ualink_remote *remote; int r; - remote = kzalloc(sizeof(*remote), GFP_KERNEL); + remote = kzalloc_obj(*remote); if (!remote) return -ENOMEM; adev->ualink.remote = remote; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index 4dca1ab48410ae..9fc8e9e97595aa 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -362,6 +362,8 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type]; int r; + /* The reset changes the queue state and the MES is unusable meanwhile */ + guard(rwsem_read)(&adev->reset_domain->sem); if ((queue->state == AMDGPU_USERQ_STATE_MAPPED) || (queue->state == AMDGPU_USERQ_STATE_PREEMPTED)) { trace_amdgpu_userq_state_start(queue); @@ -388,6 +390,8 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type]; int r; + /* The reset changes the queue state and the MES is unusable meanwhile */ + guard(rwsem_read)(&adev->reset_domain->sem); if (queue->state == AMDGPU_USERQ_STATE_UNMAPPED) { trace_amdgpu_userq_state_start(queue); @@ -769,12 +773,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) if (!adev->userq_halt_for_enforce_isolation || ((queue->queue_type != AMDGPU_HW_IP_GFX) && (queue->queue_type != AMDGPU_HW_IP_COMPUTE))) { - /* Serialize the map against an in-progress GPU reset (MES is - * unresponsive during recovery), matching amdgpu_userq_detach_doorbell(). - */ - down_read(&adev->reset_domain->sem); r = amdgpu_userq_map_helper(queue); - up_read(&adev->reset_domain->sem); if (r) { drm_file_err(uq_mgr->file, "Failed to map Queue\n"); trace_amdgpu_userq_create_end(queue, r); @@ -991,7 +990,11 @@ static int amdgpu_userq_validate_vm(void *param, struct amdgpu_bo *bo) return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); } -/* Handle all BOs on the invalidated list, validate them and update the PTs */ +/* + * Handle all individual BOs which were moved, lock and validate them and + * update the PTs. An evicted individual BO lands on the needs_update list, + * the evicted one only holds imported DMA-bufs of compute VMs. + */ static int amdgpu_userq_bo_validate(struct amdgpu_device *adev, struct drm_exec *exec, struct amdgpu_vm *vm) @@ -1002,8 +1005,8 @@ amdgpu_userq_bo_validate(struct amdgpu_device *adev, struct drm_exec *exec, int ret; spin_lock(&vm->individual_lock); - while (!list_empty(&vm->individual.evicted)) { - bo_va = list_first_entry(&vm->individual.evicted, + while (!list_empty(&vm->individual.needs_update)) { + bo_va = list_first_entry(&vm->individual.needs_update, struct amdgpu_bo_va, base.vm_status); bo = bo_va->base.bo; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c index c1257f530e9a32..b7cebe392108f9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c @@ -505,8 +505,7 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, syncobj_points = NULL; } - syncobj = kmalloc_array(num_syncobj_handles, sizeof(*syncobj), - GFP_KERNEL); + syncobj = kmalloc_objs(*syncobj, num_syncobj_handles); if (!syncobj) { r = -ENOMEM; goto free_syncobj_points; @@ -765,13 +764,11 @@ amdgpu_userq_wait_return_fence_info(struct drm_device *dev, struct drm_file *fil struct drm_exec exec; int i, cnt, r; - fence_info = kmalloc_array(wait_info->num_fences, sizeof(*fence_info), - GFP_KERNEL); + fence_info = kmalloc_objs(*fence_info, wait_info->num_fences); if (!fence_info) return -ENOMEM; - fences = kmalloc_array(wait_info->num_fences, sizeof(*fences), - GFP_KERNEL); + fences = kmalloc_objs(*fences, wait_info->num_fences); if (!fences) { r = -ENOMEM; goto free_fence_info; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c index cd35ff7ca86420..d88dde859615d3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c @@ -1115,7 +1115,8 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, uint64_t addr; int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &adev->uvd.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, + direct ? NULL : &adev->uvd.entity, AMDGPU_FENCE_OWNER_UNDEFINED, 64, direct ? AMDGPU_IB_POOL_DIRECT : AMDGPU_IB_POOL_DELAYED, @@ -1160,11 +1161,11 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, goto err_free; f = amdgpu_job_submit(job); - } - amdgpu_bo_reserve(bo, true); - amdgpu_bo_fence(bo, f, false); - amdgpu_bo_unreserve(bo); + amdgpu_bo_reserve(bo, true); + amdgpu_bo_fence(bo, f, false); + amdgpu_bo_unreserve(bo); + } if (fence) *fence = dma_fence_get(f); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c index 3952af9ae115a4..11f8fe98aac46d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c @@ -471,7 +471,7 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, uint64_t addr; int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, NULL, AMDGPU_FENCE_OWNER_UNDEFINED, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, AMDGPU_KERNEL_JOB_ID_VCN_RING_TEST, @@ -562,7 +562,8 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, struct dma_fence *f = NULL; int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, + direct ? NULL : &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED, ib_size_dw * 4, direct ? AMDGPU_IB_POOL_DIRECT : @@ -775,6 +776,7 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t allocated = 0; uint32_t tmp, handle = 0; uint32_t dummy = 0xffffffff; + uint32_t luma_pitch, chroma_pitch, height; uint32_t *size = &dummy; unsigned int idx; int i, r = 0; @@ -880,19 +882,19 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, goto out; } - uint32_t width, height; - width = amdgpu_ib_get_value(ib, idx + 8); - height = amdgpu_ib_get_value(ib, idx + 10); + luma_pitch = amdgpu_ib_get_value(ib, idx + 8); + chroma_pitch = amdgpu_ib_get_value(ib, idx + 9); + height = amdgpu_ib_get_value(ib, idx + 10); /* encRefYHeightInQw */ - if (width == 0 || height == 0 || - width > 4096 || height > 2304) { - DRM_ERROR("invalid VCE image size: %ux%u\n", - width, height); + if (luma_pitch == 0 || chroma_pitch == 0 || height == 0 || + luma_pitch > 4096 || chroma_pitch > 4096 || height > 2304 / 8) { + DRM_ERROR("invalid VCE ref image size: (%u %u)x%u\n", + luma_pitch, chroma_pitch, height * 8); r = -EINVAL; goto out; } - *size = width * height * 8 * 3 / 2; + *size = luma_pitch * height * 8 + chroma_pitch * height * 8 / 2; break; @@ -921,13 +923,25 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, break; case 0x03000001: /* encode */ + height = amdgpu_ib_get_value(ib, idx + 13); + luma_pitch = amdgpu_ib_get_value(ib, idx + 14); + chroma_pitch = amdgpu_ib_get_value(ib, idx + 15); + + if (luma_pitch == 0 || chroma_pitch == 0 || height == 0 || + luma_pitch > 4096 || chroma_pitch > 4096 || height > 2304) { + DRM_ERROR("invalid VCE image size: (%u %u)x%u\n", + luma_pitch, chroma_pitch, height); + r = -EINVAL; + goto out; + } + r = amdgpu_vce_cs_reloc(p, ib, idx + 10, idx + 9, - *size, 0); + luma_pitch * height, 0); if (r) goto out; r = amdgpu_vce_cs_reloc(p, ib, idx + 12, idx + 11, - *size / 3, 0); + chroma_pitch * height / 2, 0); if (r) goto out; break; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c index 34e1242d66ea1e..6c12d8aa3c7696 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c @@ -299,6 +299,26 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i) mutex_destroy(&adev->vcn.inst[i].vcn1_jpeg1_workaround); } +int amdgpu_vcn_early_fini(struct amdgpu_ip_block *ip_block) +{ + struct amdgpu_device *adev = ip_block->adev; + int i; + + /* Called on teardown even if sw_init never ran */ + if (!ip_block->status.sw) + return 0; + + /* hw_fini may not wait while a peer in the reset domain resets */ + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { + if (adev->vcn.harvest_config & (1 << i)) + continue; + + cancel_delayed_work_sync(&adev->vcn.inst[i].idle_work); + } + + return 0; +} + bool amdgpu_vcn_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance) { bool ret = false; @@ -459,6 +479,15 @@ void amdgpu_vcn_put_profile(struct amdgpu_device *adev) mutex_unlock(&adev->vcn.workload_profile_mutex); } +void amdgpu_vcn_cancel_idle_work(struct amdgpu_vcn_inst *vcn_inst) +{ + /* The reset mustn't wait for the idle work, which waits for the reset */ + if (amdgpu_in_reset(vcn_inst->adev)) + cancel_delayed_work(&vcn_inst->idle_work); + else + cancel_delayed_work_sync(&vcn_inst->idle_work); +} + static void amdgpu_vcn_idle_work_handler(struct work_struct *work) { struct amdgpu_vcn_inst *vcn_inst = @@ -470,6 +499,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return; + /* Nothing holding the reset semaphore waits for this work */ + down_read(&adev->reset_domain->sem); + for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]); @@ -499,6 +531,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) } else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); } + + up_read(&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507,7 +541,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me]; if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt)) - cancel_delayed_work_sync(&vcn_inst->idle_work); + amdgpu_vcn_cancel_idle_work(vcn_inst); mutex_lock(&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state(vcn_inst, AMD_PG_STATE_UNGATE); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h index bea95307fd42bc..509c83799a8aa6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h @@ -522,10 +522,12 @@ enum vcn_ring_type { int amdgpu_vcn_early_init(struct amdgpu_device *adev, int i); int amdgpu_vcn_sw_init(struct amdgpu_device *adev, int i); void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i); +int amdgpu_vcn_early_fini(struct amdgpu_ip_block *ip_block); int amdgpu_vcn_suspend(struct amdgpu_device *adev, int i); int amdgpu_vcn_resume(struct amdgpu_device *adev, int i); void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring); void amdgpu_vcn_ring_end_use(struct amdgpu_ring *ring); +void amdgpu_vcn_cancel_idle_work(struct amdgpu_vcn_inst *vcn_inst); bool amdgpu_vcn_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index c41e9c0916b782..82b9b2d5d0cf5e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -271,19 +271,27 @@ static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm) /* * Don't use list splice here, we need the special handling for the root - * PD and set the moved flag appropriately. + * PD. All mappings must be written again, also of the vm_bos which are + * already waiting for an update of some of them, e.g. after a map with + * a delayed update, so set the moved flag for everything that needs an + * update. */ amdgpu_vm_assert_locked(vm); list_for_each_entry_safe(vm_bo, tmp, &vm->kernel.idle, vm_status) amdgpu_vm_bo_needs_update(vm_bo); + list_for_each_entry(vm_bo, &vm->kernel.needs_update, vm_status) + vm_bo->moved = true; + list_for_each_entry_safe(vm_bo, tmp, &vm->always_valid.idle, vm_status) amdgpu_vm_bo_needs_update(vm_bo); + list_for_each_entry(vm_bo, &vm->always_valid.needs_update, vm_status) + vm_bo->moved = true; spin_lock(&vm->individual_lock); - list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) { - vm_bo->moved = true; + list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) list_move(&vm_bo->vm_status, &vm->individual.needs_update); - } + list_for_each_entry(vm_bo, &vm->individual.needs_update, vm_status) + vm_bo->moved = true; spin_unlock(&vm->individual_lock); } @@ -525,12 +533,16 @@ static int amdgpu_vm_init_entities(struct amdgpu_device *adev, r = drm_sched_entity_init(&vm->immediate, DRM_SCHED_PRIORITY_NORMAL, adev->vm_manager.vm_pte_scheds, adev->vm_manager.vm_pte_num_scheds, NULL); + if (r) + return r; + + r = drm_sched_entity_init(&vm->delayed, DRM_SCHED_PRIORITY_NORMAL, + adev->vm_manager.vm_pte_scheds, + adev->vm_manager.vm_pte_num_scheds, NULL); if (r) goto error; - return drm_sched_entity_init(&vm->delayed, DRM_SCHED_PRIORITY_NORMAL, - adev->vm_manager.vm_pte_scheds, - adev->vm_manager.vm_pte_num_scheds, NULL); + return 0; error: drm_sched_entity_destroy(&vm->immediate); @@ -1071,21 +1083,16 @@ static void amdgpu_vm_tlb_seq_cb(struct dma_fence *fence, */ static void amdgpu_vm_tlb_flush(struct amdgpu_vm_update_params *params, - struct dma_fence **fence, + struct dma_fence *fence, struct amdgpu_vm_tlb_seq_struct *tlb_cb) { struct amdgpu_vm *vm = params->vm; tlb_cb->vm = vm; - if (!fence || !*fence) { - amdgpu_vm_tlb_seq_cb(NULL, &tlb_cb->cb); - return; - } - - if (!dma_fence_add_callback(*fence, &tlb_cb->cb, - amdgpu_vm_tlb_seq_cb)) { - dma_fence_put(vm->last_tlb_flush); - vm->last_tlb_flush = dma_fence_get(*fence); + if (fence && !dma_fence_add_callback(fence, &tlb_cb->cb, + amdgpu_vm_tlb_seq_cb)) { + dma_fence_put(vm->last_seq_flush); + vm->last_seq_flush = dma_fence_get(fence); } else { amdgpu_vm_tlb_seq_cb(NULL, &tlb_cb->cb); } @@ -1095,11 +1102,12 @@ amdgpu_vm_tlb_flush(struct amdgpu_vm_update_params *params, * sort out the issues with KIQ/MES TLB invalidation timeouts. */ if (!params->unlocked && vm->need_tlb_fence) { - amdgpu_vm_tlb_fence_create(params->adev, vm, fence); + amdgpu_vm_tlb_fence_create(params->adev, vm, fence, + &vm->last_tlb_inv); /* Makes sure no PD/PT is freed before the flush */ - dma_resv_add_fence(vm->root.bo->tbo.base.resv, *fence, - DMA_RESV_USAGE_BOOKKEEP); + dma_resv_add_fence(vm->root.bo->tbo.base.resv, + vm->last_tlb_inv, DMA_RESV_USAGE_BOOKKEEP); } } @@ -1248,7 +1256,7 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm, goto error_free; if (params.needs_flush) { - amdgpu_vm_tlb_flush(¶ms, fence, tlb_cb); + amdgpu_vm_tlb_flush(¶ms, *fence, tlb_cb); tlb_cb = NULL; } @@ -2647,7 +2655,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, vm->last_update = dma_fence_get_stub(); vm->last_unlocked = dma_fence_get_stub(); - vm->last_tlb_flush = dma_fence_get_stub(); + vm->last_seq_flush = dma_fence_get_stub(); + vm->last_tlb_inv = dma_fence_get_stub(); vm->generation = amdgpu_vm_generation(adev, NULL); mutex_init(&vm->eviction_lock); @@ -2691,7 +2700,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, error_free_delayed: dma_fence_put(vm->last_update); - dma_fence_put(vm->last_tlb_flush); + dma_fence_put(vm->last_seq_flush); + dma_fence_put(vm->last_tlb_inv); dma_fence_put(vm->last_unlocked); ttm_lru_bulk_move_fini(&adev->mman.bdev, &vm->lru_bulk_move); amdgpu_vm_fini_entities(vm); @@ -2832,11 +2842,12 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) amdgpu_bo_reserve(root, true); dma_fence_wait(vm->last_unlocked, false); dma_fence_put(vm->last_unlocked); - dma_fence_wait(vm->last_tlb_flush, false); + dma_fence_wait(vm->last_seq_flush, false); /* Make sure that all fence callbacks have completed */ - dma_fence_lock_irqsave(vm->last_tlb_flush, flags); - dma_fence_unlock_irqrestore(vm->last_tlb_flush, flags); - dma_fence_put(vm->last_tlb_flush); + dma_fence_lock_irqsave(vm->last_seq_flush, flags); + dma_fence_unlock_irqrestore(vm->last_seq_flush, flags); + dma_fence_put(vm->last_seq_flush); + dma_fence_put(vm->last_tlb_inv); list_for_each_entry_safe(mapping, tmp, &vm->freed, list) { if (mapping->flags & AMDGPU_VM_PAGE_PRT && prt_fini_needed) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 8e478d3bda1ac2..713a597027bbef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h @@ -328,11 +328,12 @@ struct amdgpu_vm { struct drm_sched_entity immediate; struct drm_sched_entity delayed; - /* Last finished delayed update */ + /* Last TLB seq/fence */ atomic64_t tlb_seq; - struct dma_fence *last_tlb_flush; + struct dma_fence *last_seq_flush; atomic64_t kfd_last_flushed_seq; uint64_t tlb_fence_context; + struct dma_fence *last_tlb_inv; /* How many times we had to re-generate the page tables */ uint64_t generation; @@ -561,7 +562,7 @@ static inline uint64_t amdgpu_vm_tlb_seq(struct amdgpu_vm *vm) * sure that the dma_fence structure isn't freed up. */ rcu_read_lock(); - lock = dma_fence_spinlock(vm->last_tlb_flush); + lock = dma_fence_spinlock(vm->last_seq_flush); rcu_read_unlock(); spin_lock_irqsave(lock, flags); @@ -576,9 +577,9 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev, uint32_t status, unsigned int vmhub); void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, - struct amdgpu_vm *vm, - struct dma_fence **fence); - + struct amdgpu_vm *vm, + struct dma_fence *dep, + struct dma_fence **fence); void amdgpu_vm_print_task_info(struct amdgpu_device *adev, struct amdgpu_task_info *task_info); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c index 6dc71687c39836..d3a5e8487419ec 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c @@ -235,7 +235,6 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, dma_fence_get(fence); r = drm_sched_job_add_dependency(&p->job->base, fence); if (r) { - dma_fence_put(fence); dma_resv_iter_end(&cursor); return r; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_tlb_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_tlb_fence.c index b0002c8983861b..180e02de73e9bb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_tlb_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_tlb_fence.c @@ -75,7 +75,19 @@ static const struct dma_fence_ops amdgpu_tlb_fence_ops = { .get_timeline_name = amdgpu_tlb_fence_get_timeline_name }; -void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, struct amdgpu_vm *vm, +/** + * amdgpu_vm_tlb_fence_create - create a TLB invalidation fence + * @adev: the amdgpu device + * @vm: the vm to use + * @dep: the dependency to wait for + * @fence: the resulting fence + * + * Creates a TLB invalidation fence which signals when all the VMIDs assigned to + * the PASID of the VM are invalidated. + */ +void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, + struct amdgpu_vm *vm, + struct dma_fence *dep, struct dma_fence **fence) { struct amdgpu_tlb_fence *f; @@ -86,16 +98,15 @@ void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, struct amdgpu_vm *vm * We can't fail since the PDEs and PTEs are already updated, so * just block for the dependency and execute the TLB flush */ - if (*fence) - dma_fence_wait(*fence, false); + if (dep) + dma_fence_wait(dep, false); amdgpu_gmc_flush_gpu_tlb_pasid(adev, vm->pasid, 2, true, 0); - *fence = dma_fence_get_stub(); return; } f->adev = adev; - f->dependency = *fence; + f->dependency = dma_fence_get(dep); f->pasid = vm->pasid; INIT_WORK(&f->work, amdgpu_tlb_fence_work); spin_lock_init(&f->lock); @@ -107,5 +118,6 @@ void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, struct amdgpu_vm *vm dma_fence_get(&f->base); schedule_work(&f->work); + dma_fence_put(*fence); *fence = &f->base; } diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c index 7de7adc8f225ce..05d7da888f4925 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c @@ -1705,8 +1705,9 @@ static void dce_v10_0_afmt_setmode(struct drm_encoder *encoder, WREG32(mmAFMT_RAMP_CONTROL2 + dig->afmt->offset, 0x00000001); WREG32(mmAFMT_RAMP_CONTROL3 + dig->afmt->offset, 0x00000001); - /* enable audio after to setting up hw */ - dce_v10_0_audio_enable(adev, dig->afmt->pin, true); + /* Only enable audio if the display supports it */ + if (connector->display_info.has_audio) + dce_v10_0_audio_enable(adev, dig->afmt->pin, true); } static void dce_v10_0_afmt_enable(struct drm_encoder *encoder, bool enable) diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c index 3c1d6901127d1a..f0722bdaeab611 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c @@ -1748,8 +1748,9 @@ static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder, dce_v6_0_audio_dp_enable(encoder, 1); } - /* enable audio after setting up hw */ - dce_v6_0_audio_enable(adev, dig->afmt->pin, true); + /* Only enable audio if the display supports it */ + if (connector->display_info.has_audio) + dce_v6_0_audio_enable(adev, dig->afmt->pin, true); } static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable) diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c index a17944d5e84343..3f5247314edee5 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c @@ -1653,8 +1653,9 @@ static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder, WREG32(mmAFMT_RAMP_CONTROL2 + offset, 0x00000001); WREG32(mmAFMT_RAMP_CONTROL3 + offset, 0x00000001); - /* enable audio after setting up hw */ - dce_v8_0_audio_enable(adev, dig->afmt->pin, true); + /* Only enable audio if the display supports it */ + if (connector->display_info.has_audio) + dce_v8_0_audio_enable(adev, dig->afmt->pin, true); } static void dce_v8_0_afmt_enable(struct drm_encoder *encoder, bool enable) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c index d5f428ac19bf37..11388b6660379a 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c @@ -691,6 +691,7 @@ static void gfx_v11_0_free_microcode(struct amdgpu_device *adev) amdgpu_ucode_release(&adev->gfx.me_fw); amdgpu_ucode_release(&adev->gfx.rlc_fw); amdgpu_ucode_release(&adev->gfx.mec_fw); + amdgpu_ucode_release(&adev->gfx.imu_fw); kfree(adev->gfx.rlc.register_list_format); } diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c index 420ce997bebc7d..20ec229ba9674b 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c @@ -563,6 +563,7 @@ static void gfx_v12_0_free_microcode(struct amdgpu_device *adev) amdgpu_ucode_release(&adev->gfx.me_fw); amdgpu_ucode_release(&adev->gfx.rlc_fw); amdgpu_ucode_release(&adev->gfx.mec_fw); + amdgpu_ucode_release(&adev->gfx.imu_fw); kfree(adev->gfx.rlc.register_list_format); } @@ -4080,6 +4081,7 @@ static void gfx_v12_0_update_spm_vmid(struct amdgpu_device *adev, { u32 reg, data; + amdgpu_gfx_off_ctrl(adev, false); reg = SOC15_REG_OFFSET(GC, 0, regRLC_SPM_MC_CNTL); if (amdgpu_sriov_is_pp_one_vf(adev)) data = RREG32_NO_KIQ(reg); @@ -4093,6 +4095,7 @@ static void gfx_v12_0_update_spm_vmid(struct amdgpu_device *adev, WREG32_SOC15_NO_KIQ(GC, 0, regRLC_SPM_MC_CNTL, data); else WREG32_SOC15(GC, 0, regRLC_SPM_MC_CNTL, data); + amdgpu_gfx_off_ctrl(adev, true); if (ring && amdgpu_sriov_is_pp_one_vf(adev) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c index 4498e253846f12..58f5ff506dc4ec 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c @@ -349,6 +349,7 @@ static void gfx_v12_1_free_microcode(struct amdgpu_device *adev) { amdgpu_ucode_release(&adev->gfx.rlc_fw); amdgpu_ucode_release(&adev->gfx.mec_fw); + amdgpu_ucode_release(&adev->gfx.imu_fw); kfree(adev->gfx.rlc.register_list_format); } diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c index 822681635a6552..1a8ec24c61d215 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c @@ -1617,6 +1617,7 @@ static int gmc_v9_0_early_init(struct amdgpu_ip_block *ip_block) static int gmc_v9_0_late_init(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; + bool nps_switch_support; int r; r = amdgpu_gmc_allocate_vm_inv_eng(adev); @@ -1641,6 +1642,18 @@ static int gmc_v9_0_late_init(struct amdgpu_ip_block *ip_block) amdgpu_ras_reset_error_count(adev, AMDGPU_RAS_BLOCK__HDP); } + nps_switch_support = !adev->gmc.xgmi.connected_to_cpu && + (hweight32(adev->gmc.supported_nps_modes & + AMDGPU_ALL_NPS_MASK) > 1); + /* Initialize requested NPS mode to be the same as current mode */ + if (nps_switch_support) { + enum amdgpu_memory_partition mode = + amdgpu_gmc_get_requested_nps_mode(adev); + if (mode == UNKNOWN_MEMORY_PARTITION_MODE) + amdgpu_gmc_set_requested_nps_mode( + adev, amdgpu_gmc_query_memory_partition(adev)); + } + return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0); } diff --git a/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c b/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c index 8dee486496501e..478b7169f44c2f 100644 --- a/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c @@ -168,8 +168,19 @@ static int ih_v6_0_toggle_ring_interrupts(struct amdgpu_device *adev, tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, ENABLE_INTR, (enable ? 1 : 0)); if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) { - if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) + /* + * PSP programming of IH_RB_CNTL is slow enough for MSI to + * arrive before this call returns. Publish ih->enabled first + * so amdgpu_ih_process() consumes that IV and rearms. + */ + if (enable) { + ih->enabled = true; + smp_wmb(); + } + if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) { + ih->enabled = false; return -ETIMEDOUT; + } } else { WREG32(ih_regs->ih_rb_cntl, tmp); } diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c index 72069b77f6f1fc..cf93ab07457bc6 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c @@ -131,17 +131,13 @@ static int jpeg_v2_0_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v2_0_sw_fini(struct amdgpu_ip_block *ip_block) { int r; struct amdgpu_device *adev = ip_block->adev; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -159,11 +155,15 @@ static int jpeg_v2_0_hw_init(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; struct amdgpu_ring *ring = adev->jpeg.inst->ring_dec; + int r; adev->nbio.funcs->vcn_doorbell_range(adev, ring->use_doorbell, (adev->doorbell_index.vcn.vcn_ring0_1 << 1), 0); - return amdgpu_ring_test_helper(ring); + r = amdgpu_ring_test_helper(ring); + if (r) + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -177,7 +177,9 @@ static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (adev->jpeg.cur_state != AMD_PG_STATE_GATE && RREG32_SOC15(JPEG, 0, mmUVD_JRBC_STATUS)) @@ -195,15 +197,7 @@ static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v2_0_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v2_0_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v2_0_hw_fini(ip_block); } /** @@ -787,6 +781,7 @@ static const struct amd_ip_funcs jpeg_v2_0_ip_funcs = { .early_init = jpeg_v2_0_early_init, .sw_init = jpeg_v2_0_sw_init, .sw_fini = jpeg_v2_0_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v2_0_hw_init, .hw_fini = jpeg_v2_0_hw_fini, .suspend = jpeg_v2_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c index 2968256d4cd741..966a8a7f28eedb 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c @@ -181,17 +181,13 @@ static int jpeg_v2_5_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v2_5_sw_fini(struct amdgpu_ip_block *ip_block) { int r; struct amdgpu_device *adev = ip_block->adev; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -221,10 +217,14 @@ static int jpeg_v2_5_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -239,7 +239,9 @@ static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int i; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1 << i)) @@ -265,15 +267,7 @@ static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v2_5_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v2_5_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v2_5_hw_fini(ip_block); } /** @@ -661,6 +655,7 @@ static const struct amd_ip_funcs jpeg_v2_5_ip_funcs = { .early_init = jpeg_v2_5_early_init, .sw_init = jpeg_v2_5_sw_init, .sw_fini = jpeg_v2_5_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v2_5_hw_init, .hw_fini = jpeg_v2_5_hw_fini, .suspend = jpeg_v2_5_suspend, @@ -677,6 +672,7 @@ static const struct amd_ip_funcs jpeg_v2_6_ip_funcs = { .early_init = jpeg_v2_5_early_init, .sw_init = jpeg_v2_5_sw_init, .sw_fini = jpeg_v2_5_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v2_5_hw_init, .hw_fini = jpeg_v2_5_hw_fini, .suspend = jpeg_v2_5_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c index 564e40899df22c..d7b664e252021c 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c @@ -146,17 +146,13 @@ static int jpeg_v3_0_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v3_0_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -174,11 +170,15 @@ static int jpeg_v3_0_hw_init(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; struct amdgpu_ring *ring = adev->jpeg.inst->ring_dec; + int r; adev->nbio.funcs->vcn_doorbell_range(adev, ring->use_doorbell, (adev->doorbell_index.vcn.vcn_ring0_1 << 1), 0); - return amdgpu_ring_test_helper(ring); + r = amdgpu_ring_test_helper(ring); + if (r) + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -192,7 +192,9 @@ static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (adev->jpeg.cur_state != AMD_PG_STATE_GATE && RREG32_SOC15(JPEG, 0, mmUVD_JRBC_STATUS)) @@ -210,15 +212,7 @@ static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v3_0_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v3_0_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v3_0_hw_fini(ip_block); } /** @@ -560,6 +554,7 @@ static const struct amd_ip_funcs jpeg_v3_0_ip_funcs = { .early_init = jpeg_v3_0_early_init, .sw_init = jpeg_v3_0_sw_init, .sw_fini = jpeg_v3_0_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v3_0_hw_init, .hw_fini = jpeg_v3_0_hw_fini, .suspend = jpeg_v3_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c index b29ca3a49939b2..6dc01f57847b74 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c @@ -157,17 +157,13 @@ static int jpeg_v4_0_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v4_0_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -204,10 +200,14 @@ static int jpeg_v4_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -221,7 +221,10 @@ static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); + if (!amdgpu_sriov_vf(adev)) { if (adev->jpeg.cur_state != AMD_PG_STATE_GATE && RREG32_SOC15(JPEG, 0, regUVD_JRBC_STATUS)) @@ -242,15 +245,7 @@ static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v4_0_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v4_0_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v4_0_hw_fini(ip_block); } /** @@ -744,6 +739,7 @@ static const struct amd_ip_funcs jpeg_v4_0_ip_funcs = { .early_init = jpeg_v4_0_early_init, .sw_init = jpeg_v4_0_sw_init, .sw_fini = jpeg_v4_0_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v4_0_hw_init, .hw_fini = jpeg_v4_0_hw_fini, .suspend = jpeg_v4_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c index 0343a64595f2c1..524103f421e635 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c @@ -248,17 +248,13 @@ static int jpeg_v4_0_3_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v4_0_3_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -435,12 +431,16 @@ static int jpeg_v4_0_3_hw_init(struct amdgpu_ip_block *ip_block) VCN_JPEG_DB_CTRL__EN_MASK); r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -455,7 +455,9 @@ static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int ret = 0; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (!amdgpu_sriov_vf(adev)) { if (adev->jpeg.cur_state != AMD_PG_STATE_GATE) @@ -477,15 +479,7 @@ static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v4_0_3_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v4_0_3_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v4_0_3_hw_fini(ip_block); } /** @@ -1222,6 +1216,7 @@ static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = { .early_init = jpeg_v4_0_3_early_init, .sw_init = jpeg_v4_0_3_sw_init, .sw_fini = jpeg_v4_0_3_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v4_0_3_hw_init, .hw_fini = jpeg_v4_0_3_hw_fini, .suspend = jpeg_v4_0_3_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c index 4da3f9c995c11f..11718e3f19a5b2 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c @@ -191,17 +191,13 @@ static int jpeg_v4_0_5_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v4_0_5_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -232,10 +228,14 @@ static int jpeg_v4_0_5_hw_init(struct amdgpu_ip_block *ip_block) ring = adev->jpeg.inst[i].ring_dec; r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -250,7 +250,9 @@ static int jpeg_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int i; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1 << i)) @@ -274,15 +276,7 @@ static int jpeg_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v4_0_5_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v4_0_5_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v4_0_5_hw_fini(ip_block); } /** @@ -803,6 +797,7 @@ static const struct amd_ip_funcs jpeg_v4_0_5_ip_funcs = { .early_init = jpeg_v4_0_5_early_init, .sw_init = jpeg_v4_0_5_sw_init, .sw_fini = jpeg_v4_0_5_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v4_0_5_hw_init, .hw_fini = jpeg_v4_0_5_hw_fini, .suspend = jpeg_v4_0_5_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c index dcdb089b43083d..88e78dc498bc90 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c @@ -135,17 +135,13 @@ static int jpeg_v5_0_0_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v5_0_0_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -173,9 +169,13 @@ static int jpeg_v5_0_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -189,7 +189,9 @@ static int jpeg_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (adev->jpeg.cur_state != AMD_PG_STATE_GATE && RREG32_SOC15(JPEG, 0, regUVD_JRBC_STATUS)) @@ -207,15 +209,7 @@ static int jpeg_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v5_0_0_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v5_0_0_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v5_0_0_hw_fini(ip_block); } /** @@ -679,6 +673,7 @@ static const struct amd_ip_funcs jpeg_v5_0_0_ip_funcs = { .early_init = jpeg_v5_0_0_early_init, .sw_init = jpeg_v5_0_0_sw_init, .sw_fini = jpeg_v5_0_0_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v5_0_0_hw_init, .hw_fini = jpeg_v5_0_0_hw_fini, .suspend = jpeg_v5_0_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c index f2debf6b6bd070..f666b48e34c8ac 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c @@ -240,17 +240,13 @@ static int jpeg_v5_0_1_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v5_0_1_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -307,11 +303,15 @@ static int jpeg_v5_0_1_hw_init(struct amdgpu_ip_block *ip_block) VCN_JPEG_DB_CTRL__EN_MASK); r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -326,7 +326,9 @@ static int jpeg_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int ret = 0; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (!amdgpu_sriov_vf(adev)) { if (adev->jpeg.cur_state != AMD_PG_STATE_GATE) @@ -348,16 +350,7 @@ static int jpeg_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v5_0_1_suspend(struct amdgpu_ip_block *ip_block) { - struct amdgpu_device *adev = ip_block->adev; - int r; - - r = jpeg_v5_0_1_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(adev); - - return r; + return jpeg_v5_0_1_hw_fini(ip_block); } /** @@ -883,6 +876,7 @@ static const struct amd_ip_funcs jpeg_v5_0_1_ip_funcs = { .late_init = NULL, .sw_init = jpeg_v5_0_1_sw_init, .sw_fini = jpeg_v5_0_1_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v5_0_1_hw_init, .hw_fini = jpeg_v5_0_1_hw_fini, .suspend = jpeg_v5_0_1_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c index dd0abce73687c4..af1feba68dc31c 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c @@ -206,17 +206,13 @@ static int jpeg_v5_0_2_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v5_0_2_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -280,11 +276,15 @@ static int jpeg_v5_0_2_hw_init(struct amdgpu_ip_block *ip_block) VCN_JPEG_DB_CTRL__EN_MASK); r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -299,7 +299,9 @@ static int jpeg_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int ret = 0; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (!amdgpu_sriov_vf(adev)) { if (adev->jpeg.cur_state != AMD_PG_STATE_GATE) @@ -318,16 +320,7 @@ static int jpeg_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v5_0_2_suspend(struct amdgpu_ip_block *ip_block) { - struct amdgpu_device *adev = ip_block->adev; - int r; - - r = jpeg_v5_0_2_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(adev); - - return r; + return jpeg_v5_0_2_hw_fini(ip_block); } /** @@ -867,6 +860,7 @@ static const struct amd_ip_funcs jpeg_v5_0_2_ip_funcs = { .late_init = NULL, .sw_init = jpeg_v5_0_2_sw_init, .sw_fini = jpeg_v5_0_2_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v5_0_2_hw_init, .hw_fini = jpeg_v5_0_2_hw_fini, .suspend = jpeg_v5_0_2_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c index 8ddd12740a040d..71011c5e2adbb0 100644 --- a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c @@ -118,17 +118,13 @@ static int jpeg_v5_3_0_sw_init(struct amdgpu_ip_block *ip_block) * * @ip_block: Pointer to the amdgpu_ip_block for this hw instance. * - * JPEG suspend and free up sw allocation + * Free up JPEG sw allocation */ static int jpeg_v5_3_0_sw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; int r; - r = amdgpu_jpeg_suspend(adev); - if (r) - return r; - amdgpu_jpeg_sysfs_reset_mask_fini(adev); r = amdgpu_jpeg_sw_fini(adev); @@ -156,9 +152,13 @@ static int jpeg_v5_3_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; return 0; + +error: + amdgpu_jpeg_cancel_idle_work(adev); + return r; } /** @@ -172,7 +172,9 @@ static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - cancel_delayed_work_sync(&adev->jpeg.idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_jpeg_cancel_idle_work(adev); if (adev->jpeg.cur_state != AMD_PG_STATE_GATE && RREG32_SOC15(JPEG, 0, regUVD_JRBC0_UVD_JRBC_STATUS)) @@ -190,15 +192,7 @@ static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block *ip_block) */ static int jpeg_v5_3_0_suspend(struct amdgpu_ip_block *ip_block) { - int r; - - r = jpeg_v5_3_0_hw_fini(ip_block); - if (r) - return r; - - r = amdgpu_jpeg_suspend(ip_block->adev); - - return r; + return jpeg_v5_3_0_hw_fini(ip_block); } /** @@ -667,6 +661,7 @@ static const struct amd_ip_funcs jpeg_v5_3_0_ip_funcs = { .early_init = jpeg_v5_3_0_early_init, .sw_init = jpeg_v5_3_0_sw_init, .sw_fini = jpeg_v5_3_0_sw_fini, + .early_fini = amdgpu_jpeg_early_fini, .hw_init = jpeg_v5_3_0_hw_init, .hw_fini = jpeg_v5_3_0_hw_fini, .suspend = jpeg_v5_3_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c index 78c517f6c2d27e..0895c29899d2be 100644 --- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c @@ -218,8 +218,10 @@ static int mes_v11_0_submit_pkt_and_poll_completion(struct amdgpu_mes *mes, r = amdgpu_fence_wait_polling(ring, seq - ring->fence_drv.num_fences_mask, timeout); - if (r < 1) + if (r < 1) { + r = -ETIMEDOUT; goto error_undo; + } api_status = (struct MES_API_STATUS *)((char *)pkt + api_status_off); api_status->api_completion_fence_addr = status_gpu_addr; diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c index b6356095b079f2..d06a9c5dceca38 100644 --- a/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c @@ -195,8 +195,10 @@ static int mes_v12_0_submit_pkt_and_poll_completion(struct amdgpu_mes *mes, r = amdgpu_fence_wait_polling(ring, seq - ring->fence_drv.num_fences_mask, timeout); - if (r < 1) + if (r < 1) { + r = -ETIMEDOUT; goto error_undo; + } api_status = (struct MES_API_STATUS *)((char *)pkt + api_status_off); api_status->api_completion_fence_addr = status_gpu_addr; diff --git a/drivers/gpu/drm/amd/amdgpu/navi10_ih.c b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c index df2245fa35b789..fa5148ae526def 100644 --- a/drivers/gpu/drm/amd/amdgpu/navi10_ih.c +++ b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c @@ -161,13 +161,52 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp = RREG32(ih_regs->ih_rb_cntl); tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_ENABLE, (enable ? 1 : 0)); tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, RB_GPU_TS_ENABLE, 1); + + if (enable) { + /* Unset the CLEAR_OVERFLOW bit to make sure the next step + * is switching the bit from 0 to 1 + */ + tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0); + if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) { + if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) + return -ETIMEDOUT; + } else { + WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp); + } + + /* Clear RB_OVERFLOW bit */ + tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1); + if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) { + if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) + return -ETIMEDOUT; + } else { + WREG32_NO_KIQ(ih_regs->ih_rb_cntl, tmp); + } + + /* Unset the CLEAR_OVERFLOW bit immediately so new overflows + * can be detected. + */ + tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 0); + } + /* enable_intr field is only valid in ring0 */ if (ih == &adev->irq.ih) tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, ENABLE_INTR, (enable ? 1 : 0)); if (amdgpu_sriov_vf(adev) && amdgpu_sriov_reg_indirect_ih(adev)) { - if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) + /* + * PSP programming of IH_RB_CNTL is slow enough for MSI to + * arrive before this call returns. Publish ih->enabled first + * so amdgpu_ih_process() consumes that IV and rearms. + */ + if (enable) { + ih->enabled = true; + smp_wmb(); + } + if (psp_reg_program(&adev->psp, ih_regs->psp_reg_id, tmp)) { + ih->enabled = false; return -ETIMEDOUT; + } } else { WREG32(ih_regs->ih_rb_cntl, tmp); } diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c b/drivers/gpu/drm/amd/amdgpu/soc21.c index 599d47e1d38b6e..635f026d629c9f 100644 --- a/drivers/gpu/drm/amd/amdgpu/soc21.c +++ b/drivers/gpu/drm/amd/amdgpu/soc21.c @@ -599,7 +599,10 @@ static int soc21_common_early_init(struct amdgpu_ip_block *ip_block) adev->cg_flags = AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS | + AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_REPEATER_FGCG | + AMD_CG_SUPPORT_GFX_FGCG | + AMD_CG_SUPPORT_GFX_PERF_CLK | AMD_CG_SUPPORT_VCN_MGCG | AMD_CG_SUPPORT_JPEG_MGCG | AMD_CG_SUPPORT_ATHUB_MGCG | diff --git a/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c b/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c index 506060fc53688a..b83e4e0c43097f 100644 --- a/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c +++ b/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c @@ -751,7 +751,7 @@ int soc_v1_0_reset_init(struct amdgpu_device *adev) { struct amdgpu_reset_control *reset_ctl; - reset_ctl = kzalloc_obj(*reset_ctl, GFP_KERNEL); + reset_ctl = kzalloc_obj(*reset_ctl); if (!reset_ctl) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c b/drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c index ff7128a11cad09..97c265daa2bd59 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c @@ -710,7 +710,9 @@ static int uvd_v3_1_hw_init(struct amdgpu_ip_block *ip_block) amdgpu_ring_commit(ring); done: - if (!r) + if (r) + cancel_delayed_work_sync(&adev->uvd.idle_work); + else drm_info(adev_to_drm(adev), "UVD initialized successfully.\n"); return r; diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c index cf304b489d8725..90b57a08d6dc3f 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c @@ -198,7 +198,9 @@ static int uvd_v4_2_hw_init(struct amdgpu_ip_block *ip_block) amdgpu_ring_commit(ring); done: - if (!r) + if (r) + cancel_delayed_work_sync(&adev->uvd.idle_work); + else drm_info(adev_to_drm(adev), "UVD initialized successfully.\n"); return r; diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c index 564d8fb58905cf..aa75b2691d570d 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c @@ -190,7 +190,9 @@ static int uvd_v5_0_hw_init(struct amdgpu_ip_block *ip_block) amdgpu_ring_commit(ring); done: - if (!r) + if (r) + cancel_delayed_work_sync(&adev->uvd.idle_work); + else drm_info(adev_to_drm(adev), "UVD initialized successfully.\n"); return r; diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c index dcb8487e22b179..3016227cf0ed31 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c @@ -515,7 +515,9 @@ static int uvd_v6_0_hw_init(struct amdgpu_ip_block *ip_block) } done: - if (!r) { + if (r) { + cancel_delayed_work_sync(&adev->uvd.idle_work); + } else { if (uvd_v6_0_enc_support(adev)) drm_info(adev_to_drm(adev), "UVD and UVD ENC initialized successfully.\n"); else diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c index 46222fc30be651..48eac56f758e11 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c @@ -583,7 +583,9 @@ static int uvd_v7_0_hw_init(struct amdgpu_ip_block *ip_block) } } done: - if (!r) + if (r) + cancel_delayed_work_sync(&adev->uvd.idle_work); + else drm_info(adev_to_drm(adev), "UVD and UVD ENC initialized successfully.\n"); return r; diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c index b1428f5bbc81e1..f8ad4688c58f46 100644 --- a/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c @@ -47,6 +47,9 @@ #define VCE_V1_0_STACK_SIZE (64 * 1024) #define VCE_V1_0_DATA_SIZE (ALIGN(7808 * (AMDGPU_MAX_VCE_HANDLES + 1), VCE_V1_0_ALIGNMENT)) #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02 +#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK 0x08 +#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK 0x10 +#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK 0x20 static void vce_v1_0_set_ring_funcs(struct amdgpu_device *adev); static void vce_v1_0_set_irq_funcs(struct amdgpu_device *adev); @@ -349,19 +352,29 @@ static int vce_v1_0_mc_resume(struct amdgpu_device *adev) * * @ip_block: amdgpu_ip_block pointer * - * Check whether VCE is busy according to VCE_STATUS. + * Check whether VCE is busy according to VCE_STATUS + * and whether the ring pointers match. + * * Also check whether the SRBM thinks VCE is busy, although - * SRBM_STATUS.VCE_BUSY seems to be bogus because it + * SRBM_STATUS2.VCE_BUSY seems to be bogus because it * appears to mirror the VCE_STATUS.VCPU_REPORT_FW_LOADED bit. */ static bool vce_v1_0_is_idle(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; - bool busy = - (RREG32(mmVCE_STATUS) & (VCE_STATUS__JOB_BUSY_MASK | VCE_STATUS__UENC_BUSY_MASK)) || - (RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK); - return !busy; + /* Check whether the rings are busy. */ + if (RREG32(mmVCE_RB_RPTR) != RREG32(mmVCE_RB_WPTR) || + RREG32(mmVCE_RB_RPTR2) != RREG32(mmVCE_RB_WPTR2)) + return false; + + /* Check whether the VCPU is busy. */ + if (RREG32(mmVCE_STATUS) & (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | + VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK | + VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK)) + return false; + + return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK); } static int vce_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block) @@ -651,12 +664,16 @@ static int vce_v1_0_hw_init(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vce.num_rings; i++) { r = amdgpu_ring_test_helper(&adev->vce.ring[i]); if (r) - return r; + goto error; } dev_info(adev->dev, "VCE initialized successfully.\n"); return 0; + +error: + cancel_delayed_work_sync(&adev->vce.idle_work); + return r; } static int vce_v1_0_hw_fini(struct amdgpu_ip_block *ip_block) diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c index dd870ecac2a42f..20a4cb6d17fbb9 100644 --- a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c @@ -483,12 +483,16 @@ static int vce_v2_0_hw_init(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vce.num_rings; i++) { r = amdgpu_ring_test_helper(&adev->vce.ring[i]); if (r) - return r; + goto error; } drm_info(adev_to_drm(adev), "VCE initialized successfully.\n"); return 0; + +error: + cancel_delayed_work_sync(&adev->vce.idle_work); + return r; } static int vce_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c index d5adccd3e6895f..7637305df7e8d1 100644 --- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c @@ -482,12 +482,16 @@ static int vce_v3_0_hw_init(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vce.num_rings; i++) { r = amdgpu_ring_test_helper(&adev->vce.ring[i]); if (r) - return r; + goto error; } drm_info(adev_to_drm(adev), "VCE initialized successfully.\n"); return 0; + +error: + cancel_delayed_work_sync(&adev->vce.idle_work); + return r; } static int vce_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v4_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v4_0.c index ee445d8abe474f..4e1fbc7b50f537 100644 --- a/drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vce_v4_0.c @@ -533,12 +533,16 @@ static int vce_v4_0_hw_init(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vce.num_rings; i++) { r = amdgpu_ring_test_helper(&adev->vce.ring[i]); if (r) - return r; + goto error; } drm_info(adev_to_drm(adev), "VCE initialized successfully.\n"); return 0; + +error: + cancel_delayed_work_sync(&adev->vce.idle_work); + return r; } static int vce_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c index 76793a5caa7010..897310d04f83fa 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c @@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block) if (r) return r; - /* Override the work func */ - adev->vcn.inst[0].idle_work.work.func = vcn_v1_0_idle_work_handler; + /* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work, vcn_v1_0_idle_work_handler); amdgpu_vcn_setup_ucode(adev, 0); @@ -252,18 +252,25 @@ static int vcn_v1_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error_vcn; for (i = 0; i < adev->vcn.inst[0].num_enc_rings; ++i) { ring = &adev->vcn.inst->ring_enc[i]; r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error_vcn; } ring = adev->jpeg.inst->ring_dec; r = amdgpu_ring_test_helper(ring); + if (r) + goto error_both; + return 0; +error_both: + cancel_delayed_work_sync(&adev->jpeg.idle_work); +error_vcn: + cancel_delayed_work_sync(&adev->vcn.inst[0].idle_work); return r; } diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c index 7d2b9e4b913ac9..290cd715ca3234 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c @@ -294,7 +294,7 @@ static int vcn_v2_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; //Disable vcn decode for sriov if (amdgpu_sriov_vf(adev)) @@ -304,10 +304,14 @@ static int vcn_v2_0_hw_init(struct amdgpu_ip_block *ip_block) ring = &adev->vcn.inst->ring_enc[i]; r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + amdgpu_vcn_cancel_idle_work(adev->vcn.inst); + return r; } /** @@ -322,7 +326,9 @@ static int vcn_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; struct amdgpu_vcn_inst *vinst = adev->vcn.inst; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || (vinst->cur_state != AMD_PG_STATE_GATE && @@ -2099,6 +2105,7 @@ static const struct amd_ip_funcs vcn_v2_0_ip_funcs = { .early_init = vcn_v2_0_early_init, .sw_init = vcn_v2_0_sw_init, .sw_fini = vcn_v2_0_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v2_0_hw_init, .hw_fini = vcn_v2_0_hw_fini, .suspend = vcn_v2_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c index 10ef5616b2f5ed..c3f2265f50fca2 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c @@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block) if (r) return r; - /* Override the work func */ - adev->vcn.inst[j].idle_work.work.func = vcn_v2_5_idle_work_handler; + /* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work, vcn_v2_5_idle_work_handler); amdgpu_vcn_setup_ucode(adev, j); @@ -481,18 +481,26 @@ static int vcn_v2_5_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; for (i = 0; i < adev->vcn.inst[j].num_enc_rings; ++i) { ring = &adev->vcn.inst[j].ring_enc[i]; r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } } return r; + +error: + for (i = 0; i <= j; i++) { + if (adev->vcn.harvest_config & (1 << i)) + continue; + cancel_delayed_work_sync(&adev->vcn.inst[i].idle_work); + } + return r; } /** diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c index 0f4f4d66e2e4be..2f7d5d562cb460 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c @@ -417,18 +417,26 @@ static int vcn_v3_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j) { ring = &adev->vcn.inst[i].ring_enc[j]; r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -449,7 +457,9 @@ static int vcn_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) if (adev->vcn.harvest_config & (1 << i)) continue; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if (!amdgpu_sriov_vf(adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || @@ -2358,6 +2368,7 @@ static const struct amd_ip_funcs vcn_v3_0_ip_funcs = { .early_init = vcn_v3_0_early_init, .sw_init = vcn_v3_0_sw_init, .sw_fini = vcn_v3_0_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v3_0_hw_init, .hw_fini = vcn_v3_0_hw_fini, .suspend = vcn_v3_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c index 4b7f7bbe18da8d..12be9a2b2efc23 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c @@ -349,11 +349,19 @@ static int vcn_v4_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -374,7 +382,9 @@ static int vcn_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) if (adev->vcn.harvest_config & (1 << i)) continue; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if (!amdgpu_sriov_vf(adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || @@ -2279,6 +2289,7 @@ static const struct amd_ip_funcs vcn_v4_0_ip_funcs = { .early_init = vcn_v4_0_early_init, .sw_init = vcn_v4_0_sw_init, .sw_fini = vcn_v4_0_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v4_0_hw_init, .hw_fini = vcn_v4_0_hw_fini, .suspend = vcn_v4_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c index 3f39aa83c31927..a82607a4f84737 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c @@ -395,11 +395,19 @@ static int vcn_v4_0_3_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return r; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -417,7 +425,9 @@ static int vcn_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if (vinst->cur_state != AMD_PG_STATE_GATE) vinst->set_pg_state(vinst, AMD_PG_STATE_GATE); @@ -2027,6 +2037,7 @@ static const struct amd_ip_funcs vcn_v4_0_3_ip_funcs = { .late_init = vcn_v4_0_3_late_init, .sw_init = vcn_v4_0_3_sw_init, .sw_fini = vcn_v4_0_3_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v4_0_3_hw_init, .hw_fini = vcn_v4_0_3_hw_fini, .suspend = vcn_v4_0_3_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c index f30f80c1b07fd9..f5195b3ad0a23a 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c @@ -303,10 +303,18 @@ static int vcn_v4_0_5_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -327,7 +335,9 @@ static int vcn_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block) if (adev->vcn.harvest_config & (1 << i)) continue; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if (!amdgpu_sriov_vf(adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || @@ -1682,6 +1692,7 @@ static const struct amd_ip_funcs vcn_v4_0_5_ip_funcs = { .early_init = vcn_v4_0_5_early_init, .sw_init = vcn_v4_0_5_sw_init, .sw_fini = vcn_v4_0_5_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v4_0_5_hw_init, .hw_fini = vcn_v4_0_5_hw_fini, .suspend = vcn_v4_0_5_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c index 7b7c3bc9f046a7..5ceb96228cf48c 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c @@ -267,10 +267,18 @@ static int vcn_v5_0_0_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -291,7 +299,9 @@ static int vcn_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block) if (adev->vcn.harvest_config & (1 << i)) continue; - cancel_delayed_work_sync(&vinst->idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(vinst); if (!amdgpu_sriov_vf(adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || @@ -1468,6 +1478,7 @@ static const struct amd_ip_funcs vcn_v5_0_0_ip_funcs = { .early_init = vcn_v5_0_0_early_init, .sw_init = vcn_v5_0_0_sw_init, .sw_fini = vcn_v5_0_0_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v5_0_0_hw_init, .hw_fini = vcn_v5_0_0_hw_fini, .suspend = vcn_v5_0_0_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c index c9e990ab297d41..e7453d98cd0b7e 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c @@ -342,11 +342,19 @@ static int vcn_v5_0_1_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -364,7 +372,10 @@ static int vcn_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; - cancel_delayed_work_sync(&adev->vcn.inst[i].idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + if (vinst->cur_state != AMD_PG_STATE_GATE) vinst->set_pg_state(vinst, AMD_PG_STATE_GATE); } @@ -1652,6 +1663,7 @@ static const struct amd_ip_funcs vcn_v5_0_1_ip_funcs = { .late_init = vcn_v5_0_1_late_init, .sw_init = vcn_v5_0_1_sw_init, .sw_fini = vcn_v5_0_1_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v5_0_1_hw_init, .hw_fini = vcn_v5_0_1_hw_fini, .suspend = vcn_v5_0_1_suspend, diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c index ed47ddd5b08ce3..2f4aed8cd1ea3a 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c @@ -257,11 +257,19 @@ static int vcn_v5_0_2_hw_init(struct amdgpu_ip_block *ip_block) r = amdgpu_ring_test_helper(ring); if (r) - return r; + goto error; } } return 0; + +error: + while (i >= 0) { + if (!(adev->vcn.harvest_config & (1 << i))) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + i--; + } + return r; } /** @@ -279,7 +287,10 @@ static int vcn_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block) for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; - cancel_delayed_work_sync(&adev->vcn.inst[i].idle_work); + /* Teardown cancelled it synchronously in early_fini */ + if (!adev->shutdown) + amdgpu_vcn_cancel_idle_work(&adev->vcn.inst[i]); + if (vinst->cur_state != AMD_PG_STATE_GATE) vinst->set_pg_state(vinst, AMD_PG_STATE_GATE); } @@ -1443,6 +1454,7 @@ static const struct amd_ip_funcs vcn_v5_0_2_ip_funcs = { .late_init = NULL, .sw_init = vcn_v5_0_2_sw_init, .sw_fini = vcn_v5_0_2_sw_fini, + .early_fini = amdgpu_vcn_early_fini, .hw_init = vcn_v5_0_2_hw_init, .hw_fini = vcn_v5_0_2_hw_fini, .suspend = vcn_v5_0_2_suspend, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index d65ae53c81a5c1..3984b2c3bf45d7 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, goto err_bind_process; } - err = kfd_queue_acquire_buffers(pdd, &q_properties); + err = kfd_queue_acquire_buffers(pdd, &q_properties, false); if (err) { pr_debug("failed to acquire user queue buffers\n"); goto err_acquire_queue_buf; @@ -478,7 +478,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, err_create_queue: kfd_queue_unref_bo_vas(pdd, &q_properties); - kfd_queue_release_buffers(pdd, &q_properties); + kfd_queue_release_buffers(pdd, &q_properties, false); err_acquire_queue_buf: err_sdma_engine_id: err_bind_process: @@ -2175,7 +2175,9 @@ static int criu_checkpoint_bos(struct kfd_process *p, bo_bucket->offset = amdgpu_bo_mmap_offset(dumper_bo); for (i = 0; i < p->n_pdds; i++) { - if (amdgpu_amdkfd_bo_mapped_to_dev(p->pdds[i]->drm_priv, kgd_mem)) + /* nothing is mapped on a GPU without a VM */ + if (p->pdds[i]->drm_priv && + amdgpu_amdkfd_bo_mapped_to_dev(p->pdds[i]->drm_priv, kgd_mem)) bo_priv->mapped_gpuids[dev_idx++] = p->pdds[i]->user_gpu_id; } @@ -2861,6 +2863,8 @@ static int criu_resume(struct file *filep, goto exit; } + kfd_criu_resume_queues(target); + ret = amdgpu_amdkfd_criu_resume(target->kgd_process_info); if (ret) pr_err("amdgpu_amdkfd_criu_resume failed for %i\n", args->pid); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c index ce67e56efa8c19..61480e9119b8fa 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1848,8 +1848,8 @@ static int initialize_nocpsch(struct device_queue_manager *dqm) pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm)); - dqm->allocated_queues = kcalloc(get_pipes_per_mec(dqm), - sizeof(unsigned int), GFP_KERNEL); + dqm->allocated_queues = kzalloc_objs(unsigned int, + get_pipes_per_mec(dqm)); if (!dqm->allocated_queues) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 8b96e1fe741a11..1eb92ac6eb058c 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -297,16 +297,26 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, amdgpu_res_first(prange->ttm_res, ttm_res_offset, npages << PAGE_SHIFT, &cursor); for (i = j = 0; (i < npages) && (mpages < migrate->cpages); i++) { - struct page *spage; + struct page *spage = migrate_pfn_to_page(migrate->src[i]); if (migrate->src[i] & MIGRATE_PFN_MIGRATE) { dst[i] = cursor.start + (j << PAGE_SHIFT); migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]); - svm_migrate_get_vram_page(prange, migrate->dst[i]); - migrate->dst[i] = migrate_pfn(migrate->dst[i]); - mpages++; + /* + * A reused svm_bo page may still be held by a CPU fault. + * Reinitializing it would free it under this migration, + * so leave this page in system memory. + */ + if (page_ref_count(pfn_to_page(migrate->dst[i]))) { + dst[i] = 0; + migrate->dst[i] = 0; + spage = NULL; + } else { + svm_migrate_get_vram_page(prange, migrate->dst[i]); + migrate->dst[i] = migrate_pfn(migrate->dst[i]); + mpages++; + } } - spage = migrate_pfn_to_page(migrate->src[i]); if (spage && !is_zone_device_page(spage)) { src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE, DMA_BIDIRECTIONAL); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c index 33f0ecbe6b0a8b..748c23ec7183ab 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c @@ -150,7 +150,7 @@ static struct kfd_mem_obj *allocate_mqd(struct mqd_manager *mm, mqd_size *= NUM_XCC(node->xcc_mask); if (node->kfd->cwsr_enabled && (q->type == KFD_QUEUE_TYPE_COMPUTE)) { - mqd_mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_KERNEL); + mqd_mem_obj = kzalloc_obj(struct kfd_mem_obj); if (!mqd_mem_obj) return NULL; retval = amdgpu_amdkfd_alloc_kernel_mem(node->adev, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 288731acc928ff..436160549386d6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1376,6 +1376,8 @@ int kfd_criu_restore_event(struct file *devkfd, uint8_t __user *user_priv_data, uint64_t *priv_data_offset, uint64_t max_priv_data_size); + +int kfd_criu_resume_queues(struct kfd_process *p); /* CRIU - End */ /* Queue Context Management */ @@ -1386,12 +1388,13 @@ void print_queue(struct queue *q); int kfd_queue_buffer_get(struct amdgpu_vm *vm, void __user *addr, struct amdgpu_bo **pbo, u64 expected_size); void kfd_queue_buffer_put(struct amdgpu_bo **bo); -int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties); -int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties); +int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu); +int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu); void kfd_queue_unref_bo_va(struct amdgpu_vm *vm, struct amdgpu_bo **bo); int kfd_queue_unref_bo_vas(struct kfd_process_device *pdd, struct queue_properties *properties); void kfd_queue_ctx_save_restore_size(struct kfd_topology_device *dev); +int kfd_queue_buffer_svm_get(struct kfd_process_device *pdd, u64 addr, u64 size); struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, struct kfd_node *dev); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index 78ab759ad8549e..b68e884b1c37a0 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -227,7 +227,7 @@ void pqm_uninit(struct process_queue_manager *pqm) pqm->process); if (pdd) { kfd_queue_unref_bo_vas(pdd, &pqn->q->properties); - kfd_queue_release_buffers(pdd, &pqn->q->properties); + kfd_queue_release_buffers(pdd, &pqn->q->properties, false); } else { WARN_ON(!pdd); } @@ -303,7 +303,8 @@ static int init_user_queue(struct process_queue_manager *pqm, } retval = amdgpu_amdkfd_map_gtt_bo_to_gart(q_properties->wptr_bo, - &(*q)->wptr_bo_gart); + &(*q)->wptr_bo_gart, + pqm->process->kgd_process_info); if (retval) { pr_err("Failed to map wptr bo to GART\n"); goto free_gang_ctx_bo; @@ -571,7 +572,7 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid) goto err_destroy_queue; } kfd_procfs_del_queue(pqn->q); - kfd_queue_release_buffers(pdd, &pqn->q->properties); + kfd_queue_release_buffers(pdd, &pqn->q->properties, false); pqm_clean_queue_resource(pqm, pqn); uninit_queue(pqn->q); } @@ -1094,9 +1095,17 @@ int kfd_criu_restore_queue(struct kfd_process *p, print_queue_properties(&qp); + ret = kfd_queue_acquire_buffers(pdd, &qp, true); + if (ret) { + pr_err("Failed to acquire user queue buffers err:%d\n", ret); + goto exit; + } + ret = pqm_create_queue(&p->pqm, pdd->dev, &qp, &queue_id, q_data, mqd, ctl_stack, NULL); if (ret) { pr_err("Failed to create new queue err:%d\n", ret); + kfd_queue_unref_bo_vas(pdd, &qp); + kfd_queue_release_buffers(pdd, &qp, true); goto exit; } @@ -1115,6 +1124,38 @@ int kfd_criu_restore_queue(struct kfd_process *p, return ret; } +int kfd_criu_resume_queues(struct kfd_process *p) +{ + int ret, i; + u64 total_cwsr_size; + + for (i = 0; i < p->n_pdds; i++) { + struct kfd_process_device *pdd = p->pdds[i]; + struct kfd_topology_device *topo_dev; + struct queue *q; + + topo_dev = kfd_topology_device_by_id(pdd->dev->id); + + list_for_each_entry(q, &pdd->qpd.queues_list, list) { + total_cwsr_size = q->properties.ctx_save_restore_area_size + + topo_dev->node_props.debug_memory_size; + if (check_mul_overflow(total_cwsr_size, + NUM_XCC(pdd->dev->xcc_mask), + &total_cwsr_size)) + return -EINVAL; + total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE); + + ret = kfd_queue_buffer_svm_get(pdd, q->properties.ctx_save_restore_area_address, + total_cwsr_size); + if (ret) + return ret; + } + + } + + return 0; +} + int pqm_get_queue_checkpoint_info(struct process_queue_manager *pqm, unsigned int qid, uint32_t *mqd_size, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c index 6010a5d7a7eb99..cd41b10e08731c 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c @@ -88,7 +88,7 @@ void uninit_queue(struct queue *q) #if IS_ENABLED(CONFIG_HSA_AMD_SVM) -static int kfd_queue_buffer_svm_get(struct kfd_process_device *pdd, u64 addr, u64 size) +int kfd_queue_buffer_svm_get(struct kfd_process_device *pdd, u64 addr, u64 size) { struct kfd_process *p = pdd->process; struct list_head update_list; @@ -182,7 +182,7 @@ static void kfd_queue_buffer_svm_put(struct kfd_process_device *pdd, u64 addr, u } #else -static int kfd_queue_buffer_svm_get(struct kfd_process_device *pdd, u64 addr, u64 size) +int kfd_queue_buffer_svm_get(struct kfd_process_device *pdd, u64 addr, u64 size) { return -EINVAL; } @@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties) kfd_queue_buffer_put(&properties->cwsr_bo); } -int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties) +int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu) { struct kfd_topology_device *topo_dev; u64 expected_queue_size; @@ -334,6 +334,12 @@ int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_prope amdgpu_bo_unreserve(vm->root.bo); + /* CRIU svm buffers are restored at a later stage than queues. They'll be in + * before the queue is actually used, so no risk here + */ + if (is_criu) + return 0; + err = kfd_queue_buffer_svm_get(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); if (err) @@ -362,7 +368,7 @@ int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_prope return err; } -int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties) +int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu) { struct kfd_topology_device *topo_dev; u64 total_cwsr_size; @@ -380,7 +386,8 @@ int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_prope return -EINVAL; total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE); - kfd_queue_buffer_svm_put(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); + if (!is_criu) + kfd_queue_buffer_svm_put(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); return 0; } diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c index ed5e3318877be9..7fd331612f08cd 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -4245,15 +4245,14 @@ int kfd_criu_restore_svm(struct kfd_process *p, svm_priv_data_size = sizeof(struct kfd_criu_svm_range_priv_data) + svm_attrs_size; + if (*priv_data_offset + svm_priv_data_size > max_priv_data_size) + return -EINVAL; + criu_svm_md = kzalloc(svm_object_md_size, GFP_KERNEL); if (!criu_svm_md) { pr_err("failed to allocate memory to store svm metadata\n"); return -ENOMEM; } - if (*priv_data_offset + svm_priv_data_size > max_priv_data_size) { - ret = -EINVAL; - goto exit; - } ret = copy_from_user(&criu_svm_md->data, user_priv_ptr + *priv_data_offset, svm_priv_data_size); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c index f4b0ced7d391c0..383c53afd1f676 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c @@ -538,7 +538,6 @@ int dm_dmub_sw_init(struct amdgpu_device *adev) DMUB_WINDOW_MEMORY_TYPE_FB, /* DMUB_WINDOW_CURSOR_OFFLOAD */ }; int r; - int mem_domain = AMDGPU_GEM_DOMAIN_GTT; switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) { case IP_VERSION(2, 1, 0): @@ -675,19 +674,13 @@ int dm_dmub_sw_init(struct amdgpu_device *adev) return -EINVAL; } - /* Limit to allocate dmub to GTT on DCN32/1 - * TODO: Other asics with GDDR7 may have worse latency - */ - if (dmub_asic != DMUB_ASIC_DCN32 && - dmub_asic != DMUB_ASIC_DCN321) - mem_domain |= AMDGPU_GEM_DOMAIN_VRAM; - /* * Allocate a framebuffer based on the total size of all the regions. * TODO: Move this into GART. */ r = dmub_bo_create_kernel(adev, region_info.fb_size, PAGE_SIZE, - mem_domain, + AMDGPU_GEM_DOMAIN_VRAM | + AMDGPU_GEM_DOMAIN_GTT, &adev->dm.dmub_bo, &adev->dm.dmub_bo_gpu_addr, &adev->dm.dmub_bo_cpu_addr); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c index ab9cfbce8d73cf..0be4506e9ae5b3 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c @@ -131,6 +131,14 @@ void amdgpu_dm_get_freesync_config_for_crtc( vrefresh >= aconnector->min_vfreq && vrefresh <= aconnector->max_vfreq; + /* + * DC reads allow_freesync while validating the new state, for example + * to keep SubVP off a single FreeSync display, but it is otherwise set + * only on the first flip after the commit. Set it here, so that a + * stream created by this commit is not validated without it. + */ + new_crtc_state->stream->allow_freesync = new_crtc_state->vrr_supported; + if (new_crtc_state->vrr_supported) { new_crtc_state->stream->ignore_msa_timing_param = true; fs_vid_mode = new_crtc_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED; @@ -165,6 +173,18 @@ void amdgpu_dm_get_freesync_config_for_crtc( } EXPORT_IF_KUNIT(amdgpu_dm_get_freesync_config_for_crtc); +#define DP_HDR_SDP_EOTF_IDX 2 + +static bool dm_dp_in_hdr_mode(const struct dc_stream_state *stream) +{ + const struct dc_info_packet *hdr = &stream->hdr_static_metadata; + + if (!dc_is_dp_signal(stream->signal) || !hdr->valid) + return false; + + return hdr->sb[DP_HDR_SDP_EOTF_IDX] == HDMI_EOTF_SMPTE_ST2084; +} + void amdgpu_dm_update_freesync_state_on_stream( struct amdgpu_display_manager *dm, struct dm_crtc_state *new_crtc_state, @@ -181,6 +201,7 @@ void amdgpu_dm_update_freesync_state_on_stream( bool pack_sdp_v1_3 = false; struct amdgpu_dm_connector *aconn; enum vrr_packet_type packet_type = PACKET_TYPE_VRR; + enum color_transfer_func app_tf; if (!new_stream) return; @@ -232,12 +253,16 @@ void amdgpu_dm_update_freesync_state_on_stream( &new_stream->adaptive_sync_infopacket); } + app_tf = dm_dp_in_hdr_mode(new_stream) ? + TRANSFER_FUNC_PQ2084 : + TRANSFER_FUNC_UNKNOWN; + mod_freesync_build_vrr_infopacket( dm->freesync_module, new_stream, &vrr_params, packet_type, - TRANSFER_FUNC_UNKNOWN, + app_tf, &vrr_infopacket, pack_sdp_v1_3); 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 index 41e52c54156e32..52c084f3be493f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c @@ -1190,6 +1190,12 @@ STATIC_IFN_KUNIT uint8_t get_max_frl_rate(uint8_t max_lanes, uint8_t max_rate_pe max_frl_rate = 5; else if ((max_lanes == 4) && (max_rate_per_lane == 12)) max_frl_rate = 6; + else if ((max_lanes == 4) && (max_rate_per_lane == 16)) + max_frl_rate = 7; + else if ((max_lanes == 4) && (max_rate_per_lane == 20)) + max_frl_rate = 8; + else if ((max_lanes == 4) && (max_rate_per_lane == 24)) + max_frl_rate = 9; else max_frl_rate = 0; diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c index 5fdf8ce023b9a8..f09e2a72c53465 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c @@ -7646,7 +7646,7 @@ dm_test_uad_ctx_alloc(struct kunit *test, int connector_type) /* A real (non-kunit) sink the function is expected to free via dc_sink_release. */ static struct dc_sink *dm_test_uad_owned_sink(void) { - struct dc_sink *sink = kzalloc_obj(*sink, GFP_KERNEL); + struct dc_sink *sink = kzalloc_obj(*sink); if (sink) kref_init(&sink->refcount); @@ -7758,7 +7758,7 @@ static void dm_test_update_after_detect_disconnect(struct kunit *test) struct dm_test_uad_ctx *ctx = dm_test_uad_ctx_alloc(test, DRM_MODE_CONNECTOR_HDMIA); struct dc_sink *old_sink = dm_test_uad_owned_sink(); - struct dc_crtc_timing *timing = kzalloc_obj(*timing, GFP_KERNEL); + struct dc_crtc_timing *timing = kzalloc_obj(*timing); KUNIT_ASSERT_NOT_NULL(test, old_sink); KUNIT_ASSERT_NOT_NULL(test, timing); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c index 489dd56474b918..abdcf8fd808b93 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c @@ -1628,7 +1628,7 @@ static void dm_test_crtc_destroy_cleans_up_and_frees(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); /* amdgpu_dm_crtc_destroy() kfree()s the CRTC, so use a plain alloc. */ - acrtc = kzalloc_obj(*acrtc, GFP_KERNEL); + acrtc = kzalloc_obj(*acrtc); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, acrtc); ret = drm_crtc_init_with_planes(&adev->ddev, &acrtc->base, plane, @@ -1695,7 +1695,7 @@ static void dm_test_crtc_reset_state_replaces_existing(struct kunit *test) kref_get(&stream->refcount); /* reset_state kfree()s the old state, so use a plain (unmanaged) alloc. */ - old = kzalloc_obj(*old, GFP_KERNEL); + old = kzalloc_obj(*old); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old); old->stream = stream; crtc->state = &old->base; diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_helpers_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_helpers_test.c index d37fe26eecea41..2127d8d4a6128a 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_helpers_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_helpers_test.c @@ -1267,6 +1267,33 @@ static void dm_test_get_max_frl_rate_4lanes_12gbps(struct kunit *test) KUNIT_EXPECT_EQ(test, get_max_frl_rate(4, 12), 6); } +/** + * dm_test_get_max_frl_rate_4lanes_16gbps - Test Get max frl rate 4lanes 16gbps + * @test: The KUnit test context + */ +static void dm_test_get_max_frl_rate_4lanes_16gbps(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, get_max_frl_rate(4, 16), 7); +} + +/** + * dm_test_get_max_frl_rate_4lanes_20gbps - Test Get max frl rate 4lanes 20gbps + * @test: The KUnit test context + */ +static void dm_test_get_max_frl_rate_4lanes_20gbps(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, get_max_frl_rate(4, 20), 8); +} + +/** + * dm_test_get_max_frl_rate_4lanes_24gbps - Test Get max frl rate 4lanes 24gbps + * @test: The KUnit test context + */ +static void dm_test_get_max_frl_rate_4lanes_24gbps(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, get_max_frl_rate(4, 24), 9); +} + /** * dm_test_get_max_frl_rate_unknown - Test Get max frl rate unknown * @test: The KUnit test context @@ -4875,6 +4902,9 @@ static struct kunit_case amdgpu_dm_helpers_test_cases[] = { KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_8gbps), KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_10gbps), KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_12gbps), + KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_16gbps), + KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_20gbps), + KUNIT_CASE(dm_test_get_max_frl_rate_4lanes_24gbps), KUNIT_CASE(dm_test_get_max_frl_rate_unknown), /* dm_dtn_log_begin / dm_dtn_log_append_v / dm_dtn_log_end */ KUNIT_CASE(dm_test_dtn_log_buffer_accumulates), diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c index 6e599657dac158..8a0d68fc74d051 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c @@ -2293,7 +2293,7 @@ dm_test_setup_hpd_rx_offload_work(struct kunit *test, link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT; aconn->dc_link = link; - offload_work = kzalloc_obj(*offload_work, GFP_KERNEL); + offload_work = kzalloc_obj(*offload_work); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_work); offload_work->offload_wq = offload_wq; offload_work->adev = adev; @@ -3766,7 +3766,7 @@ static void dm_test_pflip_high_irq_completes_flip(struct kunit *test) acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED; /* drm_crtc_send_vblank_event() consumes (kfree()s) the event. */ - event = kzalloc_obj(*event, GFP_KERNEL); + event = kzalloc_obj(*event); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event); acrtc->event = event; @@ -3842,7 +3842,7 @@ static void dm_test_pflip_high_irq_vrr_no_scanoutpos(struct kunit *test) adev = drm_to_adev(acrtc->base.dev); /* drm_crtc_send_vblank_event() consumes (kfree()s) the event. */ - event = kzalloc_obj(*event, GFP_KERNEL); + event = kzalloc_obj(*event); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event); acrtc->event = event; @@ -3882,7 +3882,7 @@ static void dm_test_pflip_high_irq_vrr_front_porch(struct kunit *test) acrtc = dm_test_setup_vrr_pflip_crtc(test, tg); adev = drm_to_adev(acrtc->base.dev); - event = kzalloc_obj(*event, GFP_KERNEL); + event = kzalloc_obj(*event); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event); acrtc->event = event; @@ -3943,7 +3943,7 @@ static void dm_test_vupdate_high_irq_dcn_completes_flip(struct kunit *test) acrtc = dm_test_add_crtc(test, adev); acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED; - event = kzalloc_obj(*event, GFP_KERNEL); + event = kzalloc_obj(*event); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event); acrtc->event = event; @@ -4217,7 +4217,7 @@ static void dm_test_crtc_high_irq_writeback_completes(struct kunit *test) * The job carries no framebuffer or fence, so the deferred DRM cleanup * work only kfree()s it; it needs nothing from this test. */ - job = kzalloc_obj(*job, GFP_KERNEL); + job = kzalloc_obj(*job); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, job); list_add_tail(&job->list_entry, &wb_conn->job_queue); @@ -4309,7 +4309,7 @@ static void dm_test_handle_hpd_work_null_notify(struct kunit *test) struct amdgpu_device *adev; adev = dm_kunit_alloc_adev(test); - hpd_work = kzalloc_obj(*hpd_work, GFP_KERNEL); + hpd_work = kzalloc_obj(*hpd_work); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hpd_work); hpd_work->adev = adev; INIT_WORK(&hpd_work->handle_hpd_work, dm_handle_hpd_work); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_plane_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_plane_test.c index 7422e8ba95642e..1f5ee7a0d74158 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_plane_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_plane_test.c @@ -765,7 +765,7 @@ static void dm_test_add_modifier_appends_and_grows(struct kunit *test) size = 1; cap = 1; - mods = kmalloc_array(cap, sizeof(*mods), GFP_KERNEL); + mods = kmalloc_objs(*mods, cap); KUNIT_ASSERT_NOT_NULL(test, mods); mods[0] = 0xAAULL; @@ -803,7 +803,7 @@ static void dm_test_add_modifier_failure_paths(struct kunit *test) /* Doubling this capacity overflows the kmalloc_array() size product. */ cap = 1ULL << 62; size = cap; - mods = kmalloc_array(1, sizeof(*mods), GFP_KERNEL); + mods = kmalloc_objs(*mods, 1); KUNIT_ASSERT_NOT_NULL(test, mods); amdgpu_dm_plane_add_modifier(&mods, &size, &cap, 0x1234ULL); @@ -2448,7 +2448,7 @@ static void dm_test_plane_destroy_state_releases_resources(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, dc_plane_state); /* destroy_state frees the state itself, so use a plain allocation. */ - dm_plane_state = kzalloc_obj(*dm_plane_state, GFP_KERNEL); + dm_plane_state = kzalloc_obj(*dm_plane_state); KUNIT_ASSERT_NOT_NULL(test, dm_plane_state); /* Hold an extra reference so the release does not free KUnit memory. */ @@ -3187,7 +3187,7 @@ static struct drm_plane *dm_test_alloc_init_plane(struct kunit *test, adev->dm.adev = adev; adev->dm.dc = dm_kunit_alloc_dc_with_ctx(test); - plane = kzalloc_obj(*plane, GFP_KERNEL); + plane = kzalloc_obj(*plane); KUNIT_ASSERT_NOT_NULL(test, plane); plane->type = DRM_PLANE_TYPE_OVERLAY; diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn401/dcn401_clk_mgr.c b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn401/dcn401_clk_mgr.c index 120f9dd691f34d..03aec7f4df7bf0 100644 --- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn401/dcn401_clk_mgr.c +++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn401/dcn401_clk_mgr.c @@ -538,6 +538,9 @@ static void dcn401_update_clocks_update_dtb_dto(struct clk_mgr_internal *clk_mgr otg_master = resource_get_otg_master_for_stream( &context->res_ctx, context->streams[i]); ASSERT(otg_master); + if (!otg_master) + continue; + ASSERT(otg_master->clock_source); ASSERT(otg_master->clock_source->funcs->program_pix_clk); ASSERT(otg_master->stream_res.pix_clk_params.controller_id >= CONTROLLER_ID_D0); diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c index 1143916391e799..348e8991f8701a 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c @@ -2484,6 +2484,8 @@ static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *c * update pending complete before optimizing bandwidth. */ hwss_wait_for_odm_update_pending_complete(dc, context); + /* No DET may stay allocated to a HUBP without a plane (e.g. left over from VBIOS) */ + hwss_reset_unused_det(dc, context); /* pplib is notified if disp_num changed */ dc->hwss.optimize_bandwidth(dc, context); /* Need to do otg sync again as otg could be out of sync due to otg @@ -4870,8 +4872,10 @@ static void commit_planes_for_stream(struct dc *dc, dc_exit_ips_for_hw_access(dc); dc_z10_restore(dc); - if (update_type == UPDATE_TYPE_FULL && dc->optimized_required) + if (update_type == UPDATE_TYPE_FULL && dc->optimized_required) { + hwss_reset_unused_det(dc, dc->current_state); hwss_process_outstanding_hw_updates(dc, dc->current_state); + } if (update_type != UPDATE_TYPE_FAST && dc->res_pool->funcs->prepare_mcache_programming) dc->res_pool->funcs->prepare_mcache_programming(dc, context); diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c index da98afee558fb7..55823bce5cf3c0 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c @@ -3147,6 +3147,37 @@ void hwss_wait_for_odm_update_pending_complete(struct dc *dc, struct dc_state *c hwss_wait_for_all_blank_complete(dc, context); } +void hwss_reset_unused_det(struct dc *dc, struct dc_state *context) +{ + struct hubbub *hubbub = dc->res_pool->hubbub; + unsigned int i, j; + + if (!hubbub || !hubbub->funcs->program_det_segments) + return; + + for (i = 0; i < dc->res_pool->pipe_count; i++) { + struct hubp *hubp = dc->res_pool->hubps[i]; + bool hubp_in_use = false; + + if (!hubp) + continue; + + for (j = 0; j < dc->res_pool->pipe_count; j++) { + const struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[j]; + + /* A plane-less pipe renders from the DPG, its HUBP (assigned with the stream) needs no DET */ + if (pipe->plane_state && pipe->plane_res.hubp && + pipe->plane_res.hubp->inst == hubp->inst) { + hubp_in_use = true; + break; + } + } + + if (!hubp_in_use) + hubbub->funcs->program_det_segments(hubbub, hubp->inst, 0); + } +} + void hwss_wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context) { int i; diff --git a/drivers/gpu/drm/amd/display/dc/dc_memory_pool.c b/drivers/gpu/drm/amd/display/dc/dc_memory_pool.c index 8a5a72f4cc885c..4e716a543de194 100644 --- a/drivers/gpu/drm/amd/display/dc/dc_memory_pool.c +++ b/drivers/gpu/drm/amd/display/dc/dc_memory_pool.c @@ -119,7 +119,7 @@ __must_check struct dc_memory_pool *dc_memory_pool_create(size_t size, pool->unaligned_pool = unaligned_pool; pool->unaligned_memory = kcalloc(lines + 1, PAGE_SIZE, GFP_KERNEL); pool->memory = page_align_up(pool->unaligned_memory); - pool->free_list = kcalloc((uint32_t)capacity, sizeof(atomic_t), GFP_KERNEL); + pool->free_list = kzalloc_objs(atomic_t, (uint32_t)capacity); pool->free_head = (atomic64_t)ATOMIC_INIT(0); if (!pool->unaligned_memory || !pool->free_list) { diff --git a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v2.h b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v2.h index ebca5ddda28483..32049c17c0802e 100644 --- a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v2.h +++ b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v2.h @@ -58,27 +58,27 @@ static inline void dchub_v2_get_sop_total_available_bandwidth_KBps( { const struct utm_soc_operating_point *sop = &model->sops[sop_index]; const struct utm_qos_model_socbb *socbb = &model->socbb; - uint64_t dram_available_bandwidth_KBps_nominal; - uint64_t fabric_available_bandwidth_KBps_nominal; - uint64_t dram_available_bandwidth_KBps_urgent; - uint64_t fabric_available_bandwidth_KBps_urgent; + double dram_available_bandwidth_KBps_nominal; + double fabric_available_bandwidth_KBps_nominal; + double dram_available_bandwidth_KBps_urgent; + double fabric_available_bandwidth_KBps_urgent; - dram_available_bandwidth_KBps_nominal = (uint64_t) sop->uclk_khz + dram_available_bandwidth_KBps_nominal = (double) sop->uclk_khz * socbb->dram_channel_count * socbb->dram_channel_width_bytes * socbb->dram_transactions_per_clock - * socbb->dram_derate_percent_nominal / 100; - dram_available_bandwidth_KBps_urgent = (uint64_t) sop->uclk_khz + * socbb->dram_derate_percent_nominal / 100.0; + dram_available_bandwidth_KBps_urgent = (double) sop->uclk_khz * socbb->dram_channel_count * socbb->dram_channel_width_bytes * socbb->dram_transactions_per_clock - * socbb->dram_derate_percent_urgent / 100; - fabric_available_bandwidth_KBps_nominal = (uint64_t) sop->fclk_khz + * socbb->dram_derate_percent_urgent / 100.0; + fabric_available_bandwidth_KBps_nominal = (double) sop->fclk_khz * socbb->fabric_datapath_to_dcn_data_return_bytes - * socbb->fabric_derate_percent_nominal / 100; - fabric_available_bandwidth_KBps_urgent = (uint64_t) sop->fclk_khz + * socbb->fabric_derate_percent_nominal / 100.0; + fabric_available_bandwidth_KBps_urgent = (double) sop->fclk_khz * socbb->fabric_datapath_to_dcn_data_return_bytes - * socbb->fabric_derate_percent_urgent / 100; + * socbb->fabric_derate_percent_urgent / 100.0; total_available_bandwidth->nominal_bandwidth_KBps = dram_available_bandwidth_KBps_nominal < fabric_available_bandwidth_KBps_nominal ? @@ -99,8 +99,8 @@ static inline bool dchub_v2_is_qos_bandwidth_supported_by_sop( { struct utm_qos_model_dchub_memory_path_bandwidth_v2 available_bandwidth = {0}; const struct utm_qos_model_dchub_v2 *dchub = model->dchub_v2; - uint64_t nominal_available_bandwidth_KBps; - uint64_t urgent_available_bandwidth_KBps; + double nominal_available_bandwidth_KBps; + double urgent_available_bandwidth_KBps; if (nominal_utm_budget_percent > dchub->max_nominal_utm_budget_percent || nominal_utm_budget_percent < dchub->min_nominal_utm_budget_percent || @@ -112,9 +112,9 @@ static inline bool dchub_v2_is_qos_bandwidth_supported_by_sop( nominal_available_bandwidth_KBps = available_bandwidth.nominal_bandwidth_KBps; urgent_available_bandwidth_KBps = available_bandwidth.urgent_bandwidth_KBps; - if ((nominal_available_bandwidth_KBps * nominal_utm_budget_percent / 100) < qos_bandwidth->nominal_bandwidth_KBps) + if ((nominal_available_bandwidth_KBps * nominal_utm_budget_percent / 100.0) < qos_bandwidth->nominal_bandwidth_KBps) return false; - else if ((urgent_available_bandwidth_KBps * urgent_utm_budget_percent / 100) < qos_bandwidth->urgent_bandwidth_KBps) + else if ((urgent_available_bandwidth_KBps * urgent_utm_budget_percent / 100.0) < qos_bandwidth->urgent_bandwidth_KBps) return false; else return true; diff --git a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v3.h b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v3.h index 9390cad3169144..fef7b1dc3060bb 100644 --- a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v3.h +++ b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/utm_qos_model_dchub_v3.h @@ -50,4 +50,4 @@ struct utm_qos_model_dchub_v3 { sops[UTM_QOS_MODEL_V3_MAX_LOAD_LEVEL_COUNT][UTM_QOS_MODEL_V3_MAX_SOP_COUNT]; }; -#endif /* #ifndef UTM_QOS_MODEL_DCHUB_V3_H */ \ No newline at end of file +#endif /* #ifndef UTM_QOS_MODEL_DCHUB_V3_H */ diff --git a/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h b/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h index 7800b0501c3998..b413d1790a6b8e 100644 --- a/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h +++ b/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h @@ -1829,6 +1829,9 @@ void hwss_wait_for_odm_update_pending_complete(struct dc *dc, void hwss_wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context); +void hwss_reset_unused_det(struct dc *dc, + struct dc_state *context); + void hwss_wait_for_outstanding_hw_updates(struct dc *dc, struct dc_state *dc_context); diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c index ad1a499b0d9d23..c487c5b87dfd7a 100644 --- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c +++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c @@ -2602,12 +2602,8 @@ bool dp_is_sink_present(struct dc_link *link) * which indicates we need additional delay */ - if (dal_ddc_open(ddc, GPIO_MODE_INPUT, - GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) { - dal_ddc_close(ddc); - + if (dal_ddc_open(ddc, GPIO_MODE_INPUT, GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) return present; - } /* * Read GPIO: DP sink is present if both clock and data pins are zero diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c b/drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c index 73cc8a713556b1..2cdfe3d7a0ea6d 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c @@ -449,6 +449,13 @@ void optc2_lock_doublebuffer_disable(struct timing_generator *optc) void optc2_setup_manual_trigger(struct timing_generator *optc) { struct optc *optc1 = DCN10TG_FROM_TG(optc); + uint32_t v_total, v_total_max; + + REG_GET(OTG_V_TOTAL_MAX, OTG_V_TOTAL_MAX, &v_total_max); + if (!v_total_max) { + REG_GET(OTG_V_TOTAL, OTG_V_TOTAL, &v_total); + optc->funcs->set_vtotal_min_max(optc, v_total, v_total); + } /* Set the min/max selectors unconditionally so that * DMCUB fw may change OTG timings when necessary diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn30/dcn30_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn30/dcn30_optc.h index 16c5610b49acc3..b801989f10cfc5 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn30/dcn30_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn30/dcn30_optc.h @@ -91,6 +91,12 @@ SRI(OTG_CRC0_WINDOWA_Y_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_X_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_DATA_RG, OTG, inst),\ + SRI(OTG_CRC1_DATA_B, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_Y_CONTROL, OTG, inst),\ SR(GSL_SOURCE_SELECT),\ SRI(OTG_TRIGA_MANUAL_TRIG, OTG, inst),\ SRI(OTG_DRR_CONTROL, OTG, inst) @@ -229,6 +235,7 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL2, OTG_CRC_DSC_MODE, mask_sh),\ SF(OTG0_OTG_CRC_CNTL2, OTG_CRC_DATA_STREAM_COMBINE_MODE, mask_sh),\ @@ -245,6 +252,17 @@ SF(OTG0_OTG_CRC0_WINDOWB_X_CONTROL, OTG_CRC0_WINDOWB_X_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_START, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_TRIGA_MANUAL_TRIG, OTG_TRIGA_MANUAL_TRIG, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL0_READY_SOURCE_SEL, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL1_READY_SOURCE_SEL, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn31/dcn31_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn31/dcn31_optc.h index 19d90c65a22bf2..c56512455338c2 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn31/dcn31_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn31/dcn31_optc.h @@ -83,6 +83,12 @@ SRI(OTG_CRC0_WINDOWA_Y_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_X_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_DATA_RG, OTG, inst),\ + SRI(OTG_CRC1_DATA_B, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_Y_CONTROL, OTG, inst),\ SR(GSL_SOURCE_SELECT),\ SRI(OTG_TRIGA_MANUAL_TRIG, OTG, inst),\ SRI(OTG_GLOBAL_CONTROL1, OTG, inst),\ @@ -205,7 +211,9 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_RG, CRC0_R_CR, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_RG, CRC0_G_Y, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_B, CRC0_B_CB, mask_sh),\ @@ -217,6 +225,17 @@ SF(OTG0_OTG_CRC0_WINDOWB_X_CONTROL, OTG_CRC0_WINDOWB_X_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_START, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_TRIGA_MANUAL_TRIG, OTG_TRIGA_MANUAL_TRIG, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL0_READY_SOURCE_SEL, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL1_READY_SOURCE_SEL, mask_sh),\ @@ -264,8 +283,7 @@ SF(OTG0_INTERRUPT_DEST, OTG0_IHC_OTG_VERTICAL_INTERRUPT2_DEST, mask_sh) #define OPTC_COMMON_MASK_SH_LIST_DCN31X(mask_sh)\ - OPTC_COMMON_MASK_SH_LIST_DCN3_1(mask_sh),\ - SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh) + OPTC_COMMON_MASK_SH_LIST_DCN3_1(mask_sh) void dcn31_timing_generator_init(struct optc *optc1); diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn314/dcn314_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn314/dcn314_optc.h index 7b43c3ecd46b69..956eecf0a43a9c 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn314/dcn314_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn314/dcn314_optc.h @@ -84,6 +84,12 @@ SRI(OTG_CRC0_WINDOWA_Y_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_X_CONTROL, OTG, inst),\ SRI(OTG_CRC0_WINDOWB_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_DATA_RG, OTG, inst),\ + SRI(OTG_CRC1_DATA_B, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWA_Y_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_X_CONTROL, OTG, inst),\ + SRI(OTG_CRC1_WINDOWB_Y_CONTROL, OTG, inst),\ SR(GSL_SOURCE_SELECT),\ SRI(OTG_TRIGA_MANUAL_TRIG, OTG, inst),\ SRI(OTG_GLOBAL_CONTROL1, OTG, inst),\ @@ -204,6 +210,7 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_RG, CRC0_R_CR, mask_sh),\ @@ -217,6 +224,17 @@ SF(OTG0_OTG_CRC0_WINDOWB_X_CONTROL, OTG_CRC0_WINDOWB_X_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_START, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_TRIGA_MANUAL_TRIG, OTG_TRIGA_MANUAL_TRIG, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL0_READY_SOURCE_SEL, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL1_READY_SOURCE_SEL, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn32/dcn32_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn32/dcn32_optc.h index 60c01ec28b6532..492760779226c9 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn32/dcn32_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn32/dcn32_optc.h @@ -146,6 +146,17 @@ SF(OTG0_OTG_CRC0_WINDOWB_X_CONTROL, OTG_CRC0_WINDOWB_X_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_START, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_TRIGA_MANUAL_TRIG, OTG_TRIGA_MANUAL_TRIG, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL0_READY_SOURCE_SEL, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL1_READY_SOURCE_SEL, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn35/dcn35_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn35/dcn35_optc.h index 82e0818c8f9f4b..196596cc9fb6c3 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn35/dcn35_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn35/dcn35_optc.h @@ -32,23 +32,12 @@ #define OPTC_COMMON_MASK_SH_LIST_DCN3_5(mask_sh)\ OPTC_COMMON_MASK_SH_LIST_DCN3_2(mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_WINDOW_DB_EN, mask_sh),\ - SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ - SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ - SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ SF(OTG0_OTG_CRC2_DATA_RG, CRC2_R_CR, mask_sh),\ SF(OTG0_OTG_CRC2_DATA_RG, CRC2_G_Y, mask_sh),\ SF(OTG0_OTG_CRC2_DATA_B, CRC2_B_CB, mask_sh),\ SF(OTG0_OTG_CRC3_DATA_RG, CRC3_R_CR, mask_sh),\ SF(OTG0_OTG_CRC3_DATA_RG, CRC3_G_Y, mask_sh),\ SF(OTG0_OTG_CRC3_DATA_B, CRC3_B_CB, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ - SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWA_X_CONTROL_READBACK, OTG_CRC0_WINDOWA_X_START_READBACK, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWA_X_CONTROL_READBACK, OTG_CRC0_WINDOWA_X_END_READBACK, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWA_Y_CONTROL_READBACK, OTG_CRC0_WINDOWA_Y_START_READBACK, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn401/dcn401_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn401/dcn401_optc.h index 3add972ca2ff10..9e4e9d75400ae8 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn401/dcn401_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn401/dcn401_optc.h @@ -110,6 +110,7 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_RG, CRC0_R_CR, mask_sh),\ @@ -123,6 +124,17 @@ SF(OTG0_OTG_CRC0_WINDOWB_X_CONTROL, OTG_CRC0_WINDOWB_X_END, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_START, mask_sh),\ SF(OTG0_OTG_CRC0_WINDOWB_Y_CONTROL, OTG_CRC0_WINDOWB_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_R_CR, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_RG, CRC1_G_Y, mask_sh),\ + SF(OTG0_OTG_CRC1_DATA_B, CRC1_B_CB, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_X_CONTROL, OTG_CRC1_WINDOWA_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWA_Y_CONTROL, OTG_CRC1_WINDOWA_Y_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_X_CONTROL, OTG_CRC1_WINDOWB_X_END, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_START, mask_sh),\ + SF(OTG0_OTG_CRC1_WINDOWB_Y_CONTROL, OTG_CRC1_WINDOWB_Y_END, mask_sh),\ SF(OTG0_OTG_TRIGA_MANUAL_TRIG, OTG_TRIGA_MANUAL_TRIG, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL0_READY_SOURCE_SEL, mask_sh),\ SF(GSL_SOURCE_SELECT, GSL1_READY_SOURCE_SEL, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn42/dcn42_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn42/dcn42_optc.h index bc641f6ecd7e7b..bdda94489a23ac 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn42/dcn42_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn42/dcn42_optc.h @@ -137,6 +137,7 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_R, CRC0_R_CR, mask_sh),\ @@ -316,6 +317,7 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_CHECK_ALL_FIELDS, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_R, CRC0_R_CR, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/optc/dcn60/dcn60_optc.h b/drivers/gpu/drm/amd/display/dc/optc/dcn60/dcn60_optc.h index ba207c0e498e96..ec40c91800309c 100644 --- a/drivers/gpu/drm/amd/display/dc/optc/dcn60/dcn60_optc.h +++ b/drivers/gpu/drm/amd/display/dc/optc/dcn60/dcn60_optc.h @@ -109,7 +109,9 @@ SF(OTG0_OTG_GSL_CONTROL, OTG_GSL_FORCE_DELAY, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_CONT_EN, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC0_SELECT, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_SELECT, mask_sh),\ SF(OTG0_OTG_CRC_CNTL, OTG_CRC_EN, mask_sh),\ + SF(OTG0_OTG_CRC_CNTL, OTG_CRC1_EN, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_R, CRC0_R_CR, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_G, CRC0_G_Y, mask_sh),\ SF(OTG0_OTG_CRC0_DATA_B, CRC0_B_CB, mask_sh),\ diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c index 3a6a489388435c..619b9b3362fc6d 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c @@ -1941,8 +1941,21 @@ static bool dml1_validate(struct dc *dc, struct dc_state *context, enum dc_valid out = dcn32_internal_validate_bw(dc, context, pipes, &pipe_cnt, &vlevel, validate_mode); DC_FP_END(); - if (pipe_cnt == 0) + if (pipe_cnt == 0) { + /* The context is a copy of the previous state, so without this the + * clocks the last display needed stay applied with all displays off. + */ + context->bw_ctx.bw.dcn.clk.socclk_khz = 0; + context->bw_ctx.bw.dcn.clk.dppclk_khz = 0; + context->bw_ctx.bw.dcn.clk.dcfclk_khz = 0; + context->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz = 0; + context->bw_ctx.bw.dcn.clk.dramclk_khz = 0; + context->bw_ctx.bw.dcn.clk.fclk_khz = 0; + context->bw_ctx.bw.dcn.clk.p_state_change_support = true; + context->bw_ctx.bw.dcn.clk.fclk_p_state_change_support = true; + context->bw_ctx.bw.dcn.clk.num_ways = 0; goto validate_out; + } if (!out) goto validate_fail; diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.h b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.h index 68e7140f1505df..fa8cc89cb3f75b 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.h +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.h @@ -1054,6 +1054,12 @@ unsigned int dcn32_get_max_hw_cursor_size(const struct dc *dc, SRI_ARR(OTG_CRC0_WINDOWA_Y_CONTROL, OTG, inst), \ SRI_ARR(OTG_CRC0_WINDOWB_X_CONTROL, OTG, inst), \ SRI_ARR(OTG_CRC0_WINDOWB_Y_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_DATA_RG, OTG, inst), \ + SRI_ARR(OTG_CRC1_DATA_B, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWA_X_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWA_Y_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWB_X_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWB_Y_CONTROL, OTG, inst), \ SR_ARR(GSL_SOURCE_SELECT, inst), \ SRI_ARR(OTG_TRIGA_MANUAL_TRIG, OTG, inst), \ SRI_ARR(OTG_GLOBAL_CONTROL1, OTG, inst), \ diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.h b/drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.h index 8e3473f8649011..3cfc1a39a103cd 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.h +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.h @@ -535,6 +535,12 @@ int dcn401_get_power_profile(const struct dc_state *context); SRI_ARR(OTG_CRC0_WINDOWA_Y_CONTROL, OTG, inst), \ SRI_ARR(OTG_CRC0_WINDOWB_X_CONTROL, OTG, inst), \ SRI_ARR(OTG_CRC0_WINDOWB_Y_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_DATA_RG, OTG, inst), \ + SRI_ARR(OTG_CRC1_DATA_B, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWA_X_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWA_Y_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWB_X_CONTROL, OTG, inst), \ + SRI_ARR(OTG_CRC1_WINDOWB_Y_CONTROL, OTG, inst), \ SR_ARR(GSL_SOURCE_SELECT, inst), \ SRI_ARR(OTG_TRIGA_MANUAL_TRIG, OTG, inst), \ SRI_ARR(OTG_GLOBAL_CONTROL1, OTG, inst), \ diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c index e5e94e955157a9..955d60d5eb3e5c 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c @@ -1084,7 +1084,7 @@ static struct rmcm *dcn42_rmcm_create( struct dc_context *ctx, int inst) { - struct dcn42_rmcm *rmcm42 = kzalloc(sizeof(struct dcn42_rmcm), GFP_KERNEL); + struct dcn42_rmcm *rmcm42 = kzalloc_obj(struct dcn42_rmcm); if (!rmcm42) return NULL; diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c index e111e753238363..a498a4d25506a5 100644 --- a/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c +++ b/drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c @@ -1148,7 +1148,7 @@ static struct rmcm *dcn42b_rmcm_create( struct dc_context *ctx, int inst) { - struct dcn42_rmcm *rmcm42 = kzalloc(sizeof(struct dcn42_rmcm), GFP_KERNEL); + struct dcn42_rmcm *rmcm42 = kzalloc_obj(struct dcn42_rmcm); if (!rmcm42) return NULL; diff --git a/drivers/gpu/drm/amd/display/dc/rmcm/dcn60/dcn60_rmcm.c b/drivers/gpu/drm/amd/display/dc/rmcm/dcn60/dcn60_rmcm.c index df4d6476d70a23..1b8e7020fcb2ca 100644 --- a/drivers/gpu/drm/amd/display/dc/rmcm/dcn60/dcn60_rmcm.c +++ b/drivers/gpu/drm/amd/display/dc/rmcm/dcn60/dcn60_rmcm.c @@ -220,7 +220,7 @@ static const struct rmcm_funcs dcn60_rmcm_funcs = { struct rmcm *dcn60_rmcm_create(struct dc_context *ctx, int inst) { - struct dcn42_rmcm *rmcm42 = kzalloc(sizeof(struct dcn42_rmcm), GFP_KERNEL); + struct dcn42_rmcm *rmcm42 = kzalloc_obj(struct dcn42_rmcm); if (!rmcm42) return NULL; diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c index 4bd060e30799a0..f154a619b53390 100644 --- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c +++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c @@ -1281,10 +1281,8 @@ void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, * If VRR is inactive, set vtotal min and max to nominal vtotal */ if (in_out_vrr->state == VRR_STATE_INACTIVE) { - in_out_vrr->adjust.v_total_min = - mod_freesync_calc_v_total_from_refresh(stream, - in_out_vrr->max_refresh_in_uhz); - in_out_vrr->adjust.v_total_max = in_out_vrr->adjust.v_total_min; + in_out_vrr->adjust.v_total_min = stream->timing.v_total; + in_out_vrr->adjust.v_total_max = stream->timing.v_total; return; } } diff --git a/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h b/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h index 1f82d6f5abdec6..13c15c2138b30f 100644 --- a/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h +++ b/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h @@ -63,8 +63,6 @@ #define VCE_SOFT_RESET__ECPU_SOFT_RESET__SHIFT 0x00000000 #define VCE_SOFT_RESET__FME_SOFT_RESET_MASK 0x00000004L #define VCE_SOFT_RESET__FME_SOFT_RESET__SHIFT 0x00000002 -#define VCE_STATUS__JOB_BUSY_MASK 0x00000001L -#define VCE_STATUS__JOB_BUSY__SHIFT 0x00000000 #define VCE_STATUS__UENC_BUSY_MASK 0x00000100L #define VCE_STATUS__UENC_BUSY__SHIFT 0x00000008 #define VCE_STATUS__VCPU_REPORT_MASK 0x000000feL diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c index 48c52ac0fc77d5..9780afbf1d9ec3 100644 --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c @@ -4900,8 +4900,7 @@ static void amdgpu_debugfs_prints_cpu_info(struct seq_file *m, uint32_t num_cpu_cores = amdgpu_dpm_get_num_cpu_cores(adev); if (amdgpu_dpm_is_cclk_dpm_supported(adev)) { - p_val = kcalloc(num_cpu_cores, sizeof(uint16_t), - GFP_KERNEL); + p_val = kzalloc_objs(uint16_t, num_cpu_cores); if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_CPU_CLK, (void *)p_val, &size)) { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c index 085b100821b978..67391d589e5ae4 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c @@ -52,7 +52,7 @@ int phm_copy_clock_limits_array( uint32_t i; uint32_t *table; - table = kcalloc(power_saving_clock_count, sizeof(uint32_t), GFP_KERNEL); + table = kzalloc_objs(uint32_t, power_saving_clock_count); if (NULL == table) return -ENOMEM; @@ -73,7 +73,7 @@ int phm_copy_overdrive_settings_limits_array( uint32_t i; uint32_t *table; - table = kcalloc(od_setting_count, sizeof(uint32_t), GFP_KERNEL); + table = kzalloc_objs(uint32_t, od_setting_count); if (NULL == table) return -ENOMEM; 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 index 09e20d5ee0446d..18d8b2105a663b 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c @@ -1419,7 +1419,25 @@ int smu_v11_0_get_max_sustainable_clocks_by_dc(struct smu_context *smu, int smu_v11_0_baco_set_armd3_sequence(struct smu_context *smu, enum smu_baco_seq baco_seq) { - return smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_ArmD3, baco_seq, NULL); + struct smu_baco_context *smu_baco = &smu->smu_baco; + int ret; + + ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_ArmD3, baco_seq, NULL); + if (ret) + return ret; + + /* + * PMFW owns the BACO transition once armed, so keep the driver's view + * in sync. Otherwise smu_v11_0_get_bamaco_support() falls back to the + * live BACO feature bit, which PMFW clears when armed, and the runtime + * resume wrongly concludes BACO is unsupported and skips the exit. + */ + if (baco_seq == BACO_SEQ_BAMACO || baco_seq == BACO_SEQ_BACO) + smu_baco->state = SMU_BACO_STATE_ENTER; + else + smu_baco->state = SMU_BACO_STATE_EXIT; + + return 0; } int smu_v11_0_get_bamaco_support(struct smu_context *smu) 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 index 8285d4a91589a6..13e7e33fa0eb2d 100644 --- 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 @@ -2912,6 +2912,25 @@ static int smu_v13_0_7_mode1_reset(struct smu_context *smu) return ret; } +static void smu_v13_0_7_get_unique_id(struct smu_context *smu) +{ + SmuMetricsExternal_t metrics_external; + SmuMetrics_t *metrics = &metrics_external.SmuMetrics; + struct amdgpu_device *adev = smu->adev; + u32 upper32 = 0, lower32 = 0; + int ret; + + ret = smu_cmn_get_metrics_table(smu, &metrics_external, false); + if (ret) + goto out; + + upper32 = metrics->PublicSerialNumberUpper; + lower32 = metrics->PublicSerialNumberLower; + +out: + adev->unique_id = ((u64)upper32 << 32) | lower32; +} + static void smu_v13_0_7_init_msg_ctl(struct smu_context *smu) { struct amdgpu_device *adev = smu->adev; @@ -2995,6 +3014,7 @@ static const struct pptable_funcs smu_v13_0_7_ppt_funcs = { .enable_uclk_shadow = smu_v13_0_enable_uclk_shadow, .set_wbrf_exclusion_ranges = smu_v13_0_set_wbrf_exclusion_ranges, .interrupt_work = smu_v13_0_interrupt_work, + .get_unique_id = smu_v13_0_7_get_unique_id, }; void smu_v13_0_7_set_ppt_funcs(struct smu_context *smu) diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c index 4be864e4f0e6cd..e7a74b73263970 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c @@ -1457,7 +1457,7 @@ int smu_v15_0_od_edit_dpm_table(struct smu_context *smu, return -EINVAL; } - ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinGfxClk, + ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMinGfxclk, smu->gfx_actual_hard_min_freq, NULL); if (ret) { diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c index ce56d540e85ee4..52031745305316 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c @@ -286,13 +286,13 @@ static int smu_v15_0_8_allocate_dpm_context(struct smu_context *smu) struct smu_dpm_context *smu_dpm = &smu->smu_dpm; smu_dpm->dpm_context = - kzalloc(sizeof(struct smu_15_0_dpm_context), GFP_KERNEL); + kzalloc_obj(struct smu_15_0_dpm_context); if (!smu_dpm->dpm_context) return -ENOMEM; smu_dpm->dpm_context_size = sizeof(struct smu_15_0_dpm_context); smu_dpm->dpm_policies = - kzalloc(sizeof(struct smu_dpm_policy_ctxt), GFP_KERNEL); + kzalloc_obj(struct smu_dpm_policy_ctxt); if (!smu_dpm->dpm_policies) { kfree(smu_dpm->dpm_context); return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/core/aca.c b/drivers/gpu/drm/amd/ras/core/aca.c index 4289e968d331ac..5e6c597afa5e29 100644 --- a/drivers/gpu/drm/amd/ras/core/aca.c +++ b/drivers/gpu/drm/amd/ras/core/aca.c @@ -614,7 +614,7 @@ int ras_aca_sw_init(struct ras_core_context *ras_core) memset(ras_aca, 0, sizeof(*ras_aca)); - ras_aca->aca_blk = kcalloc(RAS_BLOCK_ID__LAST, sizeof(struct aca_block), GFP_KERNEL); + ras_aca->aca_blk = kzalloc_objs(struct aca_block, RAS_BLOCK_ID__LAST); if (!ras_aca->aca_blk) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/core/cmd.c b/drivers/gpu/drm/amd/ras/core/cmd.c index 56fcd180b5654e..f4febbf6117728 100644 --- a/drivers/gpu/drm/amd/ras/core/cmd.c +++ b/drivers/gpu/drm/amd/ras/core/cmd.c @@ -216,7 +216,7 @@ static int ras_cmd_get_cper_records(struct ras_core_context *ras_core, req->buf_size > RAS_CMD_MAX_CPER_BUF_SZ) return RAS_CMD__ERROR_INVALID_INPUT_DATA; - batch_logs = kcalloc(nr_batch_logs, sizeof(*batch_logs), GFP_KERNEL); + batch_logs = kzalloc_objs(*batch_logs, nr_batch_logs); if (!batch_logs) { ret = RAS_CMD__ERROR_GENERIC; goto out; diff --git a/drivers/gpu/drm/amd/ras/core/eeprom.c b/drivers/gpu/drm/amd/ras/core/eeprom.c index efa04cd8fbe09f..9e9295b972b572 100644 --- a/drivers/gpu/drm/amd/ras/core/eeprom.c +++ b/drivers/gpu/drm/amd/ras/core/eeprom.c @@ -1086,7 +1086,7 @@ static int ras_eeprom_sw_init(struct ras_core_context *ras_core, if (!param) return -EINVAL; - control = kzalloc(sizeof(*control), GFP_KERNEL); + control = kzalloc_obj(*control); if (!control) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/core/eeprom_fw.c b/drivers/gpu/drm/amd/ras/core/eeprom_fw.c index 02369d54bdffdb..721b45277de4ea 100644 --- a/drivers/gpu/drm/amd/ras/core/eeprom_fw.c +++ b/drivers/gpu/drm/amd/ras/core/eeprom_fw.c @@ -145,7 +145,7 @@ static int fw_eeprom_sw_init(struct ras_core_context *ras_core, if (!param) return -EINVAL; - ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); + ctl = kzalloc_obj(*ctl); if (!ctl) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/core/ras_cper.c b/drivers/gpu/drm/amd/ras/core/ras_cper.c index c8506f695d6079..9d7847104a90c8 100644 --- a/drivers/gpu/drm/amd/ras/core/ras_cper.c +++ b/drivers/gpu/drm/amd/ras/core/ras_cper.c @@ -748,7 +748,7 @@ int ras_cper_sw_init(struct ras_core_context *ras_core) uint32_t nr_profiles = RAS_LOG_EVENT_COUNT_MAX; int i, ret = 0; - profiles = kcalloc(nr_profiles, sizeof(*profiles), GFP_KERNEL); + profiles = kzalloc_objs(*profiles, nr_profiles); if (!profiles) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/core/ras_psp.c b/drivers/gpu/drm/amd/ras/core/ras_psp.c index c16acf4b57f7ff..1cd7627db7faee 100644 --- a/drivers/gpu/drm/amd/ras/core/ras_psp.c +++ b/drivers/gpu/drm/amd/ras/core/ras_psp.c @@ -108,7 +108,7 @@ static struct gpu_mem_block *ras_psp_alloc_mem(struct ras_core_context *ras_core if ((mem_type >= GPU_MEM_TYPE_MAX) || (mem_size < PAGE_SIZE)) return NULL; - gpu_mem = kzalloc(sizeof(*gpu_mem), GFP_KERNEL); + gpu_mem = kzalloc_obj(*gpu_mem); if (!gpu_mem) return NULL; diff --git a/drivers/gpu/drm/amd/ras/core/ras_umc.c b/drivers/gpu/drm/amd/ras/core/ras_umc.c index aaf98cbee619b8..78560467ee8418 100644 --- a/drivers/gpu/drm/amd/ras/core/ras_umc.c +++ b/drivers/gpu/drm/amd/ras/core/ras_umc.c @@ -202,7 +202,7 @@ int ras_umc_alloc_row_pages(struct ras_core_context *ras_core, page_num = ras_umc->max_pages_per_row; - address = kcalloc(page_num, sizeof(*address), GFP_KERNEL); + address = kzalloc_objs(*address, page_num); if (!address) return -ENOMEM; @@ -599,7 +599,7 @@ static int ras_umc_log_record(struct ras_core_context *ras_core, struct eeprom_umc_record *rec; int ret; - rec = kzalloc(sizeof(*rec), GFP_KERNEL); + rec = kzalloc_obj(*rec); if (!rec) return -ENOMEM; diff --git a/drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c b/drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c index 1e83cb5064ff63..5cd0243050dc28 100644 --- a/drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +++ b/drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c @@ -448,7 +448,7 @@ int amdgpu_virt_ras_convert_retired_address(struct amdgpu_device *adev, if (!pfn || !max_pfn_sz) return -EINVAL; - rsp = kzalloc(sizeof(*rsp), GFP_KERNEL); + rsp = kzalloc_obj(*rsp); if (!rsp) return -ENOMEM; diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c index f105e3a2dce2a9..ee4d7cb311c2df 100644 --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c @@ -355,7 +355,7 @@ static int d71_enum_resources(struct komeda_dev *mdev) u32 i, value, offset; int err; - d71 = devm_kzalloc(mdev->dev, sizeof(*d71), GFP_KERNEL); + d71 = devm_kzalloc_obj(mdev->dev, *d71); if (!d71) return -ENOMEM; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c index 9aad1d1d28ec0c..1732f4574638bf 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c @@ -188,7 +188,7 @@ struct komeda_dev *komeda_dev_create(struct device *dev) if (!komeda_identify) return ERR_PTR(-ENODEV); - mdev = devm_kzalloc(dev, sizeof(*mdev), GFP_KERNEL); + mdev = devm_kzalloc_obj(dev, *mdev); if (!mdev) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c index 67fffab018ae8a..703ff7827835b7 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -63,7 +63,7 @@ static int komeda_platform_probe(struct platform_device *pdev) if (err) return dev_err_probe(dev, err, "DMA mask error\n"); - mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL); + mdrv = devm_kzalloc_obj(dev, *mdrv); if (!mdrv) return -ENOMEM; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_format_caps.c b/drivers/gpu/drm/arm/display/komeda/komeda_format_caps.c index c9a1edb9a000a0..a2e9421ef88bed 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_format_caps.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_format_caps.c @@ -119,7 +119,7 @@ u32 *komeda_get_layer_fourcc_list(struct komeda_format_caps_table *table, u32 *fmts; int i, j, n = 0; - fmts = kcalloc(table->n_formats, sizeof(u32), GFP_KERNEL); + fmts = kzalloc_objs(u32, table->n_formats); if (!fmts) return NULL; diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c index edd924ba722da6..8d1e1e3a6deb25 100644 --- a/drivers/gpu/drm/arm/malidp_mw.c +++ b/drivers/gpu/drm/arm/malidp_mw.c @@ -193,8 +193,7 @@ static u32 *get_writeback_formats(struct malidp_drm *malidp, int *n_formats) u32 *formats; int n, i; - formats = kcalloc(map->n_pixel_formats, sizeof(*formats), - GFP_KERNEL); + formats = kzalloc_objs(*formats, map->n_pixel_formats); if (!formats) return NULL; diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index d971ed6eb6ebab..38db3d192773a7 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -954,7 +954,7 @@ int malidp_de_planes_init(struct drm_device *drm) modifiers = supported_modifiers; } - formats = kcalloc(map->n_pixel_formats, sizeof(*formats), GFP_KERNEL); + formats = kzalloc_objs(*formats, map->n_pixel_formats); if (!formats) { ret = -ENOMEM; goto cleanup; diff --git a/drivers/gpu/drm/armada/armada_510.c b/drivers/gpu/drm/armada/armada_510.c index 93cd7e1a08abf4..78edbec91ee2b5 100644 --- a/drivers/gpu/drm/armada/armada_510.c +++ b/drivers/gpu/drm/armada/armada_510.c @@ -23,7 +23,7 @@ static int armada510_crtc_init(struct armada_crtc *dcrtc, struct device *dev) struct clk *clk; int idx; - v = devm_kzalloc(dev, sizeof(*v), GFP_KERNEL); + v = devm_kzalloc_obj(dev, *v); if (!v) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c index c3ef44074477be..d3964adbb10673 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c @@ -1037,8 +1037,7 @@ static int adv7511_init_regulators(struct adv7511 *adv) unsigned int i; int ret; - adv->supplies = devm_kcalloc(dev, num_supplies, - sizeof(*adv->supplies), GFP_KERNEL); + adv->supplies = devm_kzalloc_objs(dev, *adv->supplies, num_supplies); if (!adv->supplies) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/chipone-icn6211.c b/drivers/gpu/drm/bridge/chipone-icn6211.c index 4ec50fb63abab0..14eaae07455c63 100644 --- a/drivers/gpu/drm/bridge/chipone-icn6211.c +++ b/drivers/gpu/drm/bridge/chipone-icn6211.c @@ -603,8 +603,7 @@ chipone_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/fsl-ldb.c b/drivers/gpu/drm/bridge/fsl-ldb.c index 7ec84c81cd786a..ef2d0c428c1f33 100644 --- a/drivers/gpu/drm/bridge/fsl-ldb.c +++ b/drivers/gpu/drm/bridge/fsl-ldb.c @@ -256,8 +256,7 @@ fsl_ldb_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pai.c b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pai.c index cc221483ef0d5a..9555c12231bdd0 100644 --- a/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pai.c +++ b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pai.c @@ -110,7 +110,7 @@ static int imx8mp_hdmi_pai_bind(struct device *dev, struct device *master, void void __iomem *base; int ret; - hdmi_pai = devm_kzalloc(dev, sizeof(*hdmi_pai), GFP_KERNEL); + hdmi_pai = devm_kzalloc_obj(dev, *hdmi_pai); if (!hdmi_pai) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c index ea43f59f06b211..9d38f4c0651496 100644 --- a/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c +++ b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-tx.c @@ -121,7 +121,7 @@ static int imx8mp_dw_hdmi_probe(struct platform_device *pdev) struct device_node *remote; struct imx8mp_hdmi *hdmi; - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(dev, *hdmi); if (!hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/imx/imx8qm-ldb.c b/drivers/gpu/drm/bridge/imx/imx8qm-ldb.c index 5884af99154779..547a10228094c6 100644 --- a/drivers/gpu/drm/bridge/imx/imx8qm-ldb.c +++ b/drivers/gpu/drm/bridge/imx/imx8qm-ldb.c @@ -442,7 +442,7 @@ static int imx8qm_ldb_probe(struct platform_device *pdev) int pixel_order; int ret, i; - imx8qm_ldb = devm_kzalloc(dev, sizeof(*imx8qm_ldb), GFP_KERNEL); + imx8qm_ldb = devm_kzalloc_obj(dev, *imx8qm_ldb); if (!imx8qm_ldb) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c index b95c640564e4a3..8c1356e5d92029 100644 --- a/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-ldb.c @@ -593,7 +593,7 @@ static int imx8qxp_ldb_probe(struct platform_device *pdev) struct ldb_channel *ldb_ch; int ret, i; - imx8qxp_ldb = devm_kzalloc(dev, sizeof(*imx8qxp_ldb), GFP_KERNEL); + imx8qxp_ldb = devm_kzalloc_obj(dev, *imx8qxp_ldb); if (!imx8qxp_ldb) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c b/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c index a5a1bf42325b6d..cb399434374efb 100644 --- a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c @@ -272,7 +272,7 @@ static int imx8qxp_pc_bridge_probe(struct platform_device *pdev) u32 i; int ret; - pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); + pc = devm_kzalloc_obj(dev, *pc); if (!pc) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/imx/imx93-mipi-dsi.c b/drivers/gpu/drm/bridge/imx/imx93-mipi-dsi.c index 8f312f9edf9742..6453ea779606db 100644 --- a/drivers/gpu/drm/bridge/imx/imx93-mipi-dsi.c +++ b/drivers/gpu/drm/bridge/imx/imx93-mipi-dsi.c @@ -834,7 +834,7 @@ static int imx93_dsi_probe(struct platform_device *pdev) struct imx93_dsi *dsi; int ret; - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/inno-hdmi.c b/drivers/gpu/drm/bridge/inno-hdmi.c index ea3447d4f285ba..4d9d06d0419646 100644 --- a/drivers/gpu/drm/bridge/inno-hdmi.c +++ b/drivers/gpu/drm/bridge/inno-hdmi.c @@ -1033,7 +1033,7 @@ static struct i2c_adapter *inno_hdmi_i2c_adapter(struct inno_hdmi *hdmi) struct inno_hdmi_i2c *i2c; int ret; - i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(hdmi->dev, *i2c); if (!i2c) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index c8d0a26e8e90c5..41613b530ed3e5 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -749,8 +749,7 @@ static u32 *it66121_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, { u32 *output_fmts; - output_fmts = kcalloc(MAX_OUTPUT_SEL_FORMATS, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, MAX_OUTPUT_SEL_FORMATS); if (!output_fmts) return NULL; @@ -775,8 +774,7 @@ static u32 *it66121_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/lontium-lt9211.c b/drivers/gpu/drm/bridge/lontium-lt9211.c index 285cda58f6614d..b165fba0a1c0d1 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9211.c +++ b/drivers/gpu/drm/bridge/lontium-lt9211.c @@ -599,8 +599,7 @@ lt9211_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/bridge/lontium-lt9611.c index 2d1a2826103726..619ee6e95c512a 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611.c @@ -839,8 +839,7 @@ lt9611_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/lvds-codec.c b/drivers/gpu/drm/bridge/lvds-codec.c index f97c8586273d4a..7ce633a748609f 100644 --- a/drivers/gpu/drm/bridge/lvds-codec.c +++ b/drivers/gpu/drm/bridge/lvds-codec.c @@ -89,8 +89,7 @@ lvds_codec_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c index 09992529f3d857..f748908d09e080 100644 --- a/drivers/gpu/drm/bridge/nwl-dsi.c +++ b/drivers/gpu/drm/bridge/nwl-dsi.c @@ -110,6 +110,8 @@ struct nwl_dsi { int error; struct nwl_dsi_transfer *xfer; + + unsigned int endpoint; }; static const struct regmap_config nwl_dsi_regmap_config = { @@ -821,10 +823,13 @@ static int nwl_dsi_bridge_atomic_check(struct drm_bridge *bridge, struct drm_connector_state *conn_state) { struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; + struct nwl_dsi *dsi = bridge_to_dsi(bridge); /* At least LCDIF + NWL needs active high sync */ - adjusted_mode->flags |= (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); - adjusted_mode->flags &= ~(DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC); + if (dsi->endpoint == NWL_DSI_ENDPOINT_LCDIF) { + adjusted_mode->flags |= (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); + adjusted_mode->flags &= ~(DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC); + } /* * Do a full modeset if crtc_state->active is changed to be true. @@ -948,7 +953,7 @@ static u32 *nwl_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, return NULL; } - input_fmts = kcalloc(1, sizeof(*input_fmts), GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, 1); if (!input_fmts) return NULL; input_fmts[0] = input_fmt; @@ -1088,13 +1093,12 @@ static int nwl_dsi_parse_dt(struct nwl_dsi *dsi) static int nwl_dsi_select_input(struct nwl_dsi *dsi) { struct device_node *remote; - u32 use_dcss = 1; int ret; remote = of_graph_get_remote_node(dsi->dev->of_node, 0, NWL_DSI_ENDPOINT_LCDIF); if (remote) { - use_dcss = 0; + dsi->endpoint = NWL_DSI_ENDPOINT_LCDIF; } else { remote = of_graph_get_remote_node(dsi->dev->of_node, 0, NWL_DSI_ENDPOINT_DCSS); @@ -1103,11 +1107,12 @@ static int nwl_dsi_select_input(struct nwl_dsi *dsi) "No valid input endpoint found\n"); return -EINVAL; } + dsi->endpoint = NWL_DSI_ENDPOINT_DCSS; } DRM_DEV_INFO(dsi->dev, "Using %s as input source\n", - (use_dcss) ? "DCSS" : "LCDIF"); - ret = mux_control_try_select(dsi->mux, use_dcss); + (dsi->endpoint == NWL_DSI_ENDPOINT_DCSS) ? "DCSS" : "LCDIF"); + ret = mux_control_try_select(dsi->mux, dsi->endpoint); if (ret < 0) DRM_DEV_ERROR(dsi->dev, "Failed to select input: %d\n", ret); diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c index 9aac44ed5b677d..299f5b7bffa13d 100644 --- a/drivers/gpu/drm/bridge/sii902x.c +++ b/drivers/gpu/drm/bridge/sii902x.c @@ -482,7 +482,7 @@ static u32 *sii902x_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(1, sizeof(*input_fmts), GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, 1); if (!input_fmts) return NULL; @@ -890,9 +890,15 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, } codec_data.max_i2s_channels = 2 * num_lanes; - for (i = 0; i < num_lanes; i++) + for (i = 0; i < num_lanes; i++) { + if (lanes[i] >= ARRAY_SIZE(i2s_lane_id)) + return dev_err_probe(dev, -EINVAL, + "invalid sil,i2s-data-lanes value %u\n", + lanes[i]); + sii902x->audio.i2s_fifo_sequence[i] |= audio_fifo_id[i] | i2s_lane_id[lanes[i]] | SII902X_TPI_I2S_FIFO_ENABLE; + } sii902x->audio.mclk = devm_clk_get_optional(dev, "mclk"); if (IS_ERR(sii902x->audio.mclk)) { diff --git a/drivers/gpu/drm/bridge/ssd2825.c b/drivers/gpu/drm/bridge/ssd2825.c index 71877699dfab6b..9216cee09115f1 100644 --- a/drivers/gpu/drm/bridge/ssd2825.c +++ b/drivers/gpu/drm/bridge/ssd2825.c @@ -475,6 +475,7 @@ static void ssd2825_bridge_atomic_pre_enable(struct drm_bridge *bridge, struct drm_atomic_commit *state) { struct ssd2825_priv *priv = bridge_to_ssd2825(bridge); + struct drm_bridge *next_bridge = priv->output.bridge; struct mipi_dsi_device *dsi_dev = priv->output.dev; const struct drm_crtc_state *crtc_state; const struct drm_display_mode *mode; @@ -569,6 +570,14 @@ static void ssd2825_bridge_atomic_pre_enable(struct drm_bridge *bridge, /* Initial DSI configuration register set */ ssd2825_write_reg(priv, SSD2825_CONFIGURATION_REG, config); ssd2825_write_reg(priv, SSD2825_VC_CTRL_REG, 0); + + /* + * The SSD2825 requires that the next bridge be enabled first; + * otherwise, the SSD2825 cannot complete its configuration and + * there will be no output. + */ + if (next_bridge->funcs && next_bridge->funcs->atomic_enable) + next_bridge->funcs->atomic_enable(next_bridge, state); } static void ssd2825_bridge_atomic_enable(struct drm_bridge *bridge, diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/bridge/synopsys/dw-dp.c index 86a20a0b9c0157..b367258005af00 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c @@ -1768,7 +1768,8 @@ static u32 *dw_dp_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, *num_output_fmts = 0; - output_fmts = kcalloc(ARRAY_SIZE(dw_dp_output_formats), sizeof(*output_fmts), GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, + ARRAY_SIZE(dw_dp_output_formats)); if (!output_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c index 9549dabde941c6..f7925b9bd95ee9 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c @@ -248,7 +248,7 @@ static int dw_hdmi_cec_probe(struct platform_device *pdev) * hardware device here, so that userspace can see the association * between the HDMI hardware and its associated CEC chardev. */ - cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(&pdev->dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c index df7a37eb47f49e..6d8fd25080e60e 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c @@ -161,7 +161,7 @@ static int snd_dw_hdmi_probe(struct platform_device *pdev) .data = data, }; - dw = devm_kzalloc(&pdev->dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(&pdev->dev, *dw); if (!dw) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c index b268c937608779..62835485d66a17 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c @@ -506,7 +506,7 @@ static struct i2c_adapter *dw_hdmi_qp_i2c_adapter(struct dw_hdmi_qp *hdmi) struct i2c_adapter *adap; int ret; - i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(hdmi->dev, *i2c); if (!i2c) return ERR_PTR(-ENOMEM); @@ -1187,7 +1187,7 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev, hdmi->bridge.hdmi_cec_dev = dev; hdmi->bridge.hdmi_cec_adapter_name = dev_name(dev); - hdmi->cec = devm_kzalloc(hdmi->dev, sizeof(*hdmi->cec), GFP_KERNEL); + hdmi->cec = devm_kzalloc_obj(hdmi->dev, *hdmi->cec); if (!hdmi->cec) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index 937d61c42b58db..e75b128fad2c30 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -512,7 +512,7 @@ static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi) struct dw_hdmi_i2c *i2c; int ret; - i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(hdmi->dev, *i2c); if (!i2c) return ERR_PTR(-ENOMEM); @@ -2670,8 +2670,7 @@ static u32 *dw_hdmi_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, *num_output_fmts = 0; - output_fmts = kcalloc(MAX_OUTPUT_SEL_FORMATS, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, MAX_OUTPUT_SEL_FORMATS); if (!output_fmts) return NULL; @@ -2794,8 +2793,7 @@ static u32 *dw_hdmi_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index 51f4baa62a53e1..dd05a52f1948fe 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -1888,8 +1888,7 @@ tc_dpi_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; @@ -1911,8 +1910,7 @@ tc_edp_atomic_get_output_bus_fmts(struct drm_bridge *bridge, *num_output_fmts = 0; - output_fmts = kcalloc(MAX_OUTPUT_SEL_FORMATS, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, MAX_OUTPUT_SEL_FORMATS); if (!output_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 18f73ad2589eae..9dbc66a3531c5b 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -1227,8 +1227,7 @@ tc358768_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/th1520-dw-hdmi.c b/drivers/gpu/drm/bridge/th1520-dw-hdmi.c index 2fa7f2d46b3dcd..ff01e8865f8e03 100644 --- a/drivers/gpu/drm/bridge/th1520-dw-hdmi.c +++ b/drivers/gpu/drm/bridge/th1520-dw-hdmi.c @@ -108,7 +108,7 @@ static int th1520_dw_hdmi_probe(struct platform_device *pdev) struct dw_hdmi_plat_data *plat_data; struct device *dev = &pdev->dev; - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(dev, *hdmi); if (!hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/bridge/ti-dlpc3433.c b/drivers/gpu/drm/bridge/ti-dlpc3433.c index c9f789e3068780..a0d376b0d646a0 100644 --- a/drivers/gpu/drm/bridge/ti-dlpc3433.c +++ b/drivers/gpu/drm/bridge/ti-dlpc3433.c @@ -221,8 +221,7 @@ dlpc_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge/ti-sn65dsi83.c index eb5b249cc43c73..77ef1613c5f510 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c @@ -783,8 +783,7 @@ sn65dsi83_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/display/drm_dp_helper.c b/drivers/gpu/drm/display/drm_dp_helper.c index 488fd123a01adb..a2959db1d956ef 100644 --- a/drivers/gpu/drm/display/drm_dp_helper.c +++ b/drivers/gpu/drm/display/drm_dp_helper.c @@ -2192,7 +2192,8 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, msg.buffer = msgs[i].buf + j; msg.size = min(transfer_size, msgs[i].len - j); - if (j + msg.size == msgs[i].len && aux->no_zero_sized) + if (aux->no_zero_sized && i == num - 1 && + j + msg.size == msgs[i].len) msg.request &= ~DP_AUX_I2C_MOT; err = drm_dp_i2c_drain_msg(aux, &msg); @@ -4699,7 +4700,7 @@ int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux) return 0; } - bl = devm_kzalloc(panel->dev, sizeof(*bl), GFP_KERNEL); + bl = devm_kzalloc_obj(panel->dev, *bl); if (!bl) return -ENOMEM; diff --git a/drivers/gpu/drm/display/drm_hdmi_helper.c b/drivers/gpu/drm/display/drm_hdmi_helper.c index f85cce3d62547a..278cfda38e1886 100644 --- a/drivers/gpu/drm/display/drm_hdmi_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_helper.c @@ -470,6 +470,28 @@ static bool drm_scdc_sink_supports_scrambling(struct drm_connector *connector) info->hdmi.scdc.scrambling.supported; } +static void drm_connector_hdmi_reset_sink_scrambling(struct drm_connector *connector) +{ + struct drm_device *dev = connector->dev; + u8 config; + int ret; + + if (!connector->ddc || !drm_scdc_sink_supports_scrambling(connector)) + return; + + ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config); + if (ret) { + drm_dbg_kms(dev, "Failed to read TMDS config: %d\n", ret); + return; + } + + if (config & SCDC_SCRAMBLING_ENABLE) + drm_scdc_set_scrambling(connector, false); + + if (config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) + drm_scdc_set_high_tmds_clock_ratio(connector, false); +} + static int drm_connector_hdmi_try_scrambling_setup(struct drm_connector *connector) { bool done; @@ -522,6 +544,11 @@ static void drm_connector_hdmi_scdc_work(struct work_struct *work) * the sink side and retry the operation, as some displays refuse to set the * scrambling bit right away. * + * When @conn_state doesn't require scrambling, the sink-side SCDC status is + * reset instead, so that a sink left scrambling by a state the driver did not + * control, e.g. set up by the firmware before boot, doesn't end up out of sync + * with the source. + * * The work item is cancelled by drm_connector_hdmi_disable_scrambling(), hence * source drivers must ensure the display pipeline is shut down on unbind, e.g. * via drm_atomic_helper_shutdown(). Otherwise the work may outlive the driver's @@ -541,8 +568,14 @@ int drm_connector_hdmi_enable_scrambling(struct drm_connector *connector, if (!conn_state) return -EINVAL; - if (!conn_state->hdmi.scrambler_needed) + if (!conn_state->hdmi.scrambler_needed) { + /* + * Resync the sink here, where it is known to be connected + * and its capabilities have been parsed. + */ + drm_connector_hdmi_reset_sink_scrambling(connector); return 0; + } if (!drm_connector_hdmi_scrambler_supported(connector)) { drm_dbg_kms(dev, "Source doesn't support scrambling.\n"); @@ -581,8 +614,7 @@ int drm_connector_hdmi_enable_scrambling(struct drm_connector *connector, WRITE_ONCE(hdmi->scrambler_enabled, false); cancel_delayed_work_sync(&hdmi->scdc_work); - drm_scdc_set_scrambling(connector, false); - drm_scdc_set_high_tmds_clock_ratio(connector, false); + drm_connector_hdmi_reset_sink_scrambling(connector); } return ret; @@ -619,12 +651,7 @@ int drm_connector_hdmi_disable_scrambling(struct drm_connector *connector) if (hdmi->scdc_work_initialized) cancel_delayed_work_sync(&hdmi->scdc_work); - if (connector->ddc && - connector->status == connector_status_connected && - drm_scdc_sink_supports_scrambling(connector)) { - drm_scdc_set_scrambling(connector, false); - drm_scdc_set_high_tmds_clock_ratio(connector, false); - } + drm_connector_hdmi_reset_sink_scrambling(connector); return hdmi->funcs->scrambler_disable(connector); } @@ -653,9 +680,8 @@ EXPORT_SYMBOL(drm_connector_hdmi_disable_scrambling); int drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged, struct drm_modeset_acquire_ctx *ctx) { - struct drm_connector_hdmi *hdmi = &connector->hdmi; - struct drm_device *dev = connector->dev; struct drm_connector_state *conn_state; + struct drm_device *dev; struct drm_crtc *crtc; u8 config; int ret; @@ -663,6 +689,8 @@ int drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged, if (!connector || !plugged || !ctx) return 0; + dev = connector->dev; + /* * This is normally part of .detect_ctx() call path, which already holds * connection_mutex through @ctx. However, re-acquiring it with the @@ -674,14 +702,21 @@ int drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged, /* TODO: Also handle HDMI 2.1 FRL link training */ - if (!drm_connector_hdmi_scrambler_supported(connector) || - !READ_ONCE(hdmi->scrambler_enabled)) - return 0; - conn_state = connector->state; if (!conn_state) return 0; + /* + * Rely on the committed connector state rather than on the current + * scrambler status: a source driver may force scrambler_enabled at + * init to get a disable at boot (e.g. vc4), and that value would + * remain stale until the first disable actually happens, leading to + * a spurious CRTC reset whenever the active mode needs no scrambling. + */ + if (!drm_connector_hdmi_scrambler_supported(connector) || + !conn_state->hdmi.scrambler_needed) + return 0; + crtc = conn_state->crtc; if (!crtc) return 0; diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 9d006f98413a58..ccfe3840d50522 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -4142,8 +4142,7 @@ drm_atomic_helper_bridge_get_hdmi_output_bus_fmts(struct drm_bridge *bridge, * %DRM_OUTPUT_COLOR_FORMAT_COUNT will do for counting set bits here. */ BUILD_BUG_ON(const_true(DRM_OUTPUT_COLOR_FORMAT_COUNT > 8)); - out_fmts = kmalloc_array(hweight8(bridge->supported_formats), - sizeof(u32), GFP_KERNEL); + out_fmts = kmalloc_objs(u32, hweight8(bridge->supported_formats)); if (!out_fmts) { *num_output_fmts = 0; return NULL; diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 63ead8ba675642..5295ec122e0d10 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -154,11 +154,8 @@ static void drm_crtc_crc_fini(struct drm_crtc *crtc) #endif } -static const struct dma_fence_ops drm_crtc_fence_ops; - static struct drm_crtc *fence_to_crtc(struct dma_fence *fence) { - BUG_ON(rcu_access_pointer(fence->ops) != &drm_crtc_fence_ops); return container_of(fence->extern_lock, struct drm_crtc, fence_lock); } @@ -493,14 +490,23 @@ EXPORT_SYMBOL(__drmm_crtc_alloc_with_planes); * drm_crtc_cleanup - Clean up the core crtc usage * @crtc: CRTC to cleanup * - * This function cleans up @crtc and removes it from the DRM mode setting - * core. Note that the function does *not* free the crtc structure itself, - * this is the responsibility of the caller. + * This function cleans up @crtc and removes it from the DRM mode setting core, + * after first waiting an RCU grace period to ensure @crtc->dev can safely be + * dereferenced by our dma_fence_ops. + * + * Note that the function does *not* free the crtc structure itself, this is the + * responsibility of the caller. */ void drm_crtc_cleanup(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; + /* Ensure our dma_fence_ops remain valid for an RCU grace period after + * the fence is signaled. This is necessary because our dma_fence_ops + * dereference crtc->dev. + */ + synchronize_rcu(); + /* Note that the crtc_list is considered to be static; should we * remove the drm_crtc at runtime we would have to decrement all * the indices on the drm_crtc after us in the crtc_list. diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 3148038747b6eb..b8f882a17c8f1d 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -6194,6 +6194,18 @@ void drm_get_max_frl_rate(int max_frl_rate, u8 *max_lanes, u8 *max_rate_per_lane *max_lanes = 4; *max_rate_per_lane = 12; break; + case 7: + *max_lanes = 4; + *max_rate_per_lane = 16; + break; + case 8: + *max_lanes = 4; + *max_rate_per_lane = 20; + break; + case 9: + *max_lanes = 4; + *max_rate_per_lane = 24; + break; case 0: default: *max_lanes = 0; diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c index 03dbe304e4b8fa..45169eb6de6196 100644 --- a/drivers/gpu/drm/drm_gpusvm.c +++ b/drivers/gpu/drm/drm_gpusvm.c @@ -816,7 +816,7 @@ static bool drm_gpusvm_check_pages(struct drm_gpusvm *gpusvm, mmap_assert_locked(gpusvm->mm); - pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL); + pfns = kvmalloc_objs(*pfns, npages); if (!pfns) return false; @@ -888,7 +888,7 @@ enum drm_gpusvm_scan_result drm_gpusvm_scan_mm(struct drm_gpusvm_range *range, const struct dev_pagemap *other = NULL; int err, i; - pfns = kvcalloc(npages, sizeof(*pfns), GFP_KERNEL); + pfns = kvzalloc_objs(*pfns, npages); if (!pfns) return DRM_GPUSVM_SCAN_UNPOPULATED; @@ -1830,7 +1830,7 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, goto set_seqno; } - pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL); + pfns = kvmalloc_objs(*pfns, npages); if (!pfns) return -ENOMEM; @@ -1981,7 +1981,7 @@ int drm_gpusvm_range_evict(struct drm_gpusvm *gpusvm, if (!mmget_not_zero(mm)) return -EFAULT; - pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL); + pfns = kvmalloc_objs(*pfns, npages); if (!pfns) { mmput(mm); return -ENOMEM; diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 9fe97c4eda6c85..7c32580a05b26b 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -66,7 +66,7 @@ static int drm_panic_type_set(const char *val, const struct kernel_param *kp) unsigned int i; for (i = 0; i < ARRAY_SIZE(drm_panic_type_map); i++) { - if (!strcmp(val, drm_panic_type_map[i])) { + if (sysfs_streq(val, drm_panic_type_map[i])) { drm_panic_type = i; return 0; } diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index 46adef2a30c032..bd4a1d67842096 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -399,8 +399,7 @@ static int __drm_universal_plane_init(struct drm_device *dev, plane->base.properties = &plane->properties; plane->dev = dev; plane->funcs = funcs; - plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), - GFP_KERNEL); + plane->format_types = kmalloc_objs(uint32_t, format_count); if (!plane->format_types) { DRM_DEBUG_KMS("out of memory when allocating plane\n"); drm_mode_object_unregister(dev, &plane->base); @@ -424,9 +423,8 @@ static int __drm_universal_plane_init(struct drm_device *dev, format_modifier_count); plane->modifier_count = format_modifier_count; - plane->modifiers = kmalloc_array(format_modifier_count, - sizeof(*plane->modifiers), - GFP_KERNEL); + plane->modifiers = kmalloc_objs(*plane->modifiers, + format_modifier_count); if (format_modifier_count && !plane->modifiers) { DRM_DEBUG_KMS("out of memory when allocating plane\n"); diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c index f38f2c5437e681..91f114cf9f604d 100644 --- a/drivers/gpu/drm/drm_property.c +++ b/drivers/gpu/drm/drm_property.c @@ -114,8 +114,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, property->dev = dev; if (num_values) { - property->values = kcalloc(num_values, sizeof(uint64_t), - GFP_KERNEL); + property->values = kzalloc_objs(uint64_t, num_values); if (!property->values) goto fail; } diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index f1d4da1685457c..137397972a98a0 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -1051,7 +1051,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, lockdep_assert_none_held_once(); } - points = kmalloc_array(count, sizeof(*points), GFP_KERNEL); + points = kmalloc_objs(*points, count); if (points == NULL) return -ENOMEM; @@ -1238,7 +1238,7 @@ static int drm_syncobj_array_find(struct drm_file *file_private, struct drm_syncobj **syncobjs; int ret; - handles = kmalloc_array(count_handles, sizeof(*handles), GFP_KERNEL); + handles = kmalloc_objs(*handles, count_handles); if (handles == NULL) return -ENOMEM; @@ -1572,8 +1572,7 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - points = kmalloc_array(args->count_handles, sizeof(*points), - GFP_KERNEL); + points = kmalloc_objs(*points, args->count_handles); if (!points) { ret = -ENOMEM; goto out; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c index 03b2576af67fd9..99c91a9eecf1f9 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c @@ -168,6 +168,17 @@ u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id) return buffer->user_size / 8; } +static void etnaviv_cmd_flush_ts(struct etnaviv_cmdbuf *buffer, bool has_blt) +{ + CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, VIVS_TS_FLUSH_CACHE_FLUSH); + + if (has_blt) { + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); + CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1); + CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); + } +} + void etnaviv_buffer_end(struct etnaviv_gpu *gpu) { struct etnaviv_cmdbuf *buffer = &gpu->buffer; @@ -191,7 +202,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu) unsigned int dwords = 7; if (has_blt) - dwords += 10; + dwords += 11; link_target = etnaviv_buffer_reserve(gpu, buffer, dwords); @@ -204,16 +215,8 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu) CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); } CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, flush); - if (gpu->exec_state == ETNA_PIPE_3D) { - if (has_blt) { - CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); - CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1); - CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); - } else { - CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, - VIVS_TS_FLUSH_CACHE_FLUSH); - } - } + if (gpu->exec_state == ETNA_PIPE_3D) + etnaviv_cmd_flush_ts(buffer, has_blt); CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); if (has_blt) { @@ -400,12 +403,12 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, return_dwords = 7; /* - * When the BLT engine is present we need 6 more dwords in the return + * When the BLT engine is present we need 7 more dwords in the return * target: 3 enable/flush/disable + 4 enable/semaphore stall/disable, - * but we don't need the normal TS flush state. + * on top of the normal TS flush state. */ if (has_blt) - return_dwords += 6; + return_dwords += 7; return_target = etnaviv_buffer_reserve(gpu, buffer, return_dwords); CMD_LINK(cmdbuf, return_dwords, return_target); @@ -422,14 +425,7 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, VIVS_GL_FLUSH_CACHE_DEPTH | VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_SHADER_L1); - if (has_blt) { - CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1); - CMD_LOAD_STATE(buffer, VIVS_BLT_SET_COMMAND, 0x1); - CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0); - } else { - CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE, - VIVS_TS_FLUSH_CACHE_FLUSH); - } + etnaviv_cmd_flush_ts(buffer, has_blt); } CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 08aca9035fc1a4..ec1352c1b09fad 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -601,8 +601,10 @@ static void etnaviv_unbind(struct device *dev) component_unbind_all(dev, drm); - etnaviv_cmdbuf_free(priv->flop_reset_data_ppu); - kfree(priv->flop_reset_data_ppu); + if (priv->flop_reset_data_ppu) { + etnaviv_cmdbuf_free(priv->flop_reset_data_ppu); + kfree(priv->flop_reset_data_ppu); + } etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 5c23182f4d33ad..6a4aab75ebba5a 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1907,7 +1907,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) struct etnaviv_gpu *gpu; int err; - gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL); + gpu = devm_kzalloc_obj(dev, *gpu); if (!gpu) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c index 9ae0fa4667a961..4393ed768996ca 100644 --- a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c +++ b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c @@ -794,7 +794,7 @@ static int exynos5433_decon_probe(struct platform_device *pdev) int ret; int i; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos7_drm_decon.c b/drivers/gpu/drm/exynos/exynos7_drm_decon.c index bb74b17f975377..3ab5d358679234 100644 --- a/drivers/gpu/drm/exynos/exynos7_drm_decon.c +++ b/drivers/gpu/drm/exynos/exynos7_drm_decon.c @@ -688,7 +688,7 @@ static int decon_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_dp.c b/drivers/gpu/drm/exynos/exynos_dp.c index 82c23882992126..4db7400c8a2329 100644 --- a/drivers/gpu/drm/exynos/exynos_dp.c +++ b/drivers/gpu/drm/exynos/exynos_dp.c @@ -148,8 +148,7 @@ static int exynos_dp_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct exynos_dp_device *dp; - dp = devm_kzalloc(&pdev->dev, sizeof(struct exynos_dp_device), - GFP_KERNEL); + dp = devm_kzalloc_obj(&pdev->dev, struct exynos_dp_device); if (!dp) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_dpi.c b/drivers/gpu/drm/exynos/exynos_drm_dpi.c index 74d3a2bebb742c..53b012a7acc083 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dpi.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dpi.c @@ -173,7 +173,7 @@ static int exynos_dpi_parse_dt(struct exynos_dpi *ctx) of_node_put(np); - vm = devm_kzalloc(dev, sizeof(*ctx->vm), GFP_KERNEL); + vm = devm_kzalloc_obj(dev, *ctx->vm); if (!vm) return -ENOMEM; @@ -227,7 +227,7 @@ struct drm_encoder *exynos_dpi_probe(struct device *dev) struct exynos_dpi *ctx; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/exynos/exynos_drm_dsi.c b/drivers/gpu/drm/exynos/exynos_drm_dsi.c index 2f83f324924207..b4d06cac20cb53 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dsi.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dsi.c @@ -113,7 +113,7 @@ static int exynos_dsi_register_host(struct samsung_dsim *dsim) { struct exynos_dsi *dsi; - dsi = devm_kzalloc(dsim->dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dsim->dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimc.c b/drivers/gpu/drm/exynos/exynos_drm_fimc.c index 09e33a26caaff9..9c2ad95799eee1 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fimc.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fimc.c @@ -1273,7 +1273,7 @@ static int fimc_probe(struct platform_device *pdev) if (exynos_drm_check_fimc_device(dev) != 0) return -ENODEV; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -1282,8 +1282,7 @@ static int fimc_probe(struct platform_device *pdev) /* construct formats/limits array */ num_formats = ARRAY_SIZE(fimc_formats) + ARRAY_SIZE(fimc_tiled_formats); - formats = devm_kcalloc(dev, num_formats, sizeof(*formats), - GFP_KERNEL); + formats = devm_kzalloc_objs(dev, *formats, num_formats); if (!formats) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c index dead68b517db19..60af868ac21416 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c @@ -1190,7 +1190,7 @@ static int fimd_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index e92a4d872c410c..280c1a41342ac0 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -1453,7 +1453,7 @@ static int g2d_probe(struct platform_device *pdev) struct g2d_data *g2d; int ret; - g2d = devm_kzalloc(dev, sizeof(*g2d), GFP_KERNEL); + g2d = devm_kzalloc_obj(dev, *g2d); if (!g2d) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_gsc.c b/drivers/gpu/drm/exynos/exynos_drm_gsc.c index d9637ddfcfc45c..4a07deeb382b58 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gsc.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gsc.c @@ -1222,7 +1222,7 @@ static int gsc_probe(struct platform_device *pdev) struct gsc_context *ctx; int num_formats, ret, i, j; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -1233,7 +1233,7 @@ static int gsc_probe(struct platform_device *pdev) /* construct formats/limits array */ num_formats = ARRAY_SIZE(gsc_formats) + ARRAY_SIZE(gsc_tiled_formats); - formats = devm_kcalloc(dev, num_formats, sizeof(*formats), GFP_KERNEL); + formats = devm_kzalloc_objs(dev, *formats, num_formats); if (!formats) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_rotator.c b/drivers/gpu/drm/exynos/exynos_drm_rotator.c index 7b0f4a98a70ae6..955ea0cb87b691 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_rotator.c +++ b/drivers/gpu/drm/exynos/exynos_drm_rotator.c @@ -283,7 +283,7 @@ static int rotator_probe(struct platform_device *pdev) int irq; int ret; - rot = devm_kzalloc(dev, sizeof(*rot), GFP_KERNEL); + rot = devm_kzalloc_obj(dev, *rot); if (!rot) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_scaler.c b/drivers/gpu/drm/exynos/exynos_drm_scaler.c index c8a1b6b0a29c3a..2bfbafd5c414a0 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_scaler.c +++ b/drivers/gpu/drm/exynos/exynos_drm_scaler.c @@ -490,7 +490,7 @@ static int scaler_probe(struct platform_device *pdev) int irq; int ret, i; - scaler = devm_kzalloc(dev, sizeof(*scaler), GFP_KERNEL); + scaler = devm_kzalloc_obj(dev, *scaler); if (!scaler) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c index fa3a8d21559dd8..13700ffac42311 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c +++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c @@ -491,7 +491,7 @@ static int vidi_probe(struct platform_device *pdev) struct vidi_context *ctx; struct device *dev = &pdev->dev; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c index 055dc04f9b3e57..d67a493c8fe4d3 100644 --- a/drivers/gpu/drm/exynos/exynos_hdmi.c +++ b/drivers/gpu/drm/exynos/exynos_hdmi.c @@ -1738,7 +1738,7 @@ static int hdmi_clk_init(struct hdmi_context *hdata) if (!count) return 0; - clks = devm_kcalloc(dev, count, sizeof(*clks), GFP_KERNEL); + clks = devm_kzalloc_objs(dev, *clks, count); if (!clks) return -ENOMEM; @@ -1975,7 +1975,7 @@ static int hdmi_probe(struct platform_device *pdev) struct hdmi_context *hdata; int ret; - hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL); + hdata = devm_kzalloc_obj(dev, struct hdmi_context); if (!hdata) return -ENOMEM; diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c index 69dea5049309d9..9b210ff7449f58 100644 --- a/drivers/gpu/drm/exynos/exynos_mixer.c +++ b/drivers/gpu/drm/exynos/exynos_mixer.c @@ -1231,7 +1231,7 @@ static int mixer_probe(struct platform_device *pdev) struct mixer_context *ctx; int ret; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) { DRM_DEV_ERROR(dev, "failed to alloc mixer context.\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c index 3bbfc1b56a6557..6709b3b1a3ea23 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c @@ -268,7 +268,7 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) int ret; u8 div_ratio_shift = 0; - fsl_dev = devm_kzalloc(dev, sizeof(*fsl_dev), GFP_KERNEL); + fsl_dev = devm_kzalloc_obj(dev, *fsl_dev); if (!fsl_dev) return -ENOMEM; diff --git a/drivers/gpu/drm/fsl-dcu/fsl_tcon.c b/drivers/gpu/drm/fsl-dcu/fsl_tcon.c index 49bbd00c77aecd..dd81962a03ddc3 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_tcon.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_tcon.c @@ -67,7 +67,7 @@ struct fsl_tcon *fsl_tcon_init(struct device *dev) if (!np) return NULL; - tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL); + tcon = devm_kzalloc_obj(dev, *tcon); if (!tcon) goto err_node_put; diff --git a/drivers/gpu/drm/gud/gud_connector.c b/drivers/gpu/drm/gud/gud_connector.c index 8141c3a1e30ad9..9d689c6ee3249a 100644 --- a/drivers/gpu/drm/gud/gud_connector.c +++ b/drivers/gpu/drm/gud/gud_connector.c @@ -503,7 +503,7 @@ static int gud_connector_add_properties(struct gud_device *gdrm, struct gud_conn num_properties = ret / sizeof(*properties); ret = 0; - gconn->properties = kcalloc(num_properties, sizeof(*gconn->properties), GFP_KERNEL); + gconn->properties = kzalloc_objs(*gconn->properties, num_properties); if (!gconn->properties) { ret = -ENOMEM; goto out; diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c index 680447f426f37b..55510bf62009c5 100644 --- a/drivers/gpu/drm/gud/gud_drv.c +++ b/drivers/gpu/drm/gud/gud_drv.c @@ -329,10 +329,17 @@ static int gud_stats_debugfs(struct seq_file *m, void *data) seq_puts(m, "\n"); if (gdrm->compression) { + u64 actual_length = gdrm->stats_actual_length; u64 remainder; - u64 ratio = div64_u64_rem(gdrm->stats_length, gdrm->stats_actual_length, - &remainder); - u64 ratio_frac = div64_u64(remainder * 10, gdrm->stats_actual_length); + u64 ratio, ratio_frac; + + if (!actual_length) { + seq_puts(m, "Compression ratio: n/a\n"); + return 0; + } + + ratio = div64_u64_rem(gdrm->stats_length, actual_length, &remainder); + ratio_frac = div64_u64(remainder * 10, actual_length); seq_printf(m, "Compression ratio: %llu.%llu\n", ratio, ratio_frac); } @@ -512,7 +519,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) /* Format init */ formats_dev = devm_kmalloc(dev, GUD_FORMATS_MAX_NUM, GFP_KERNEL); /* Add room for emulated XRGB8888 */ - formats = devm_kmalloc_array(dev, GUD_FORMATS_MAX_NUM + 1, sizeof(*formats), GFP_KERNEL); + formats = devm_kmalloc_objs(dev, *formats, GUD_FORMATS_MAX_NUM + 1); if (!formats_dev || !formats) return -ENOMEM; diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c index d5bd3c45649b2f..6cbd16ebc7986b 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c @@ -157,7 +157,7 @@ int hibmc_dp_hw_init(struct hibmc_dp *dp) struct hibmc_dp_dev *dp_dev; int ret; - dp_dev = devm_kzalloc(drm_dev->dev, sizeof(struct hibmc_dp_dev), GFP_KERNEL); + dp_dev = devm_kzalloc_obj(drm_dev->dev, struct hibmc_dp_dev); if (!dp_dev) return -ENOMEM; diff --git a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c index 62c5bd3277da12..df89a8f18c8f0e 100644 --- a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c +++ b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c @@ -851,7 +851,7 @@ static int dsi_probe(struct platform_device *pdev) struct dsi_hw_ctx *ctx; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) { DRM_ERROR("failed to allocate dsi data.\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c index bca839dd600bd3..dd78a917903bc9 100644 --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c @@ -850,7 +850,7 @@ static void *ade_hw_ctx_alloc(struct platform_device *pdev, struct ade_hw_ctx *ctx = NULL; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) { DRM_ERROR("failed to alloc ade_hw_ctx\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c index 8a11c2df5b8867..578c898dcba0de 100644 --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c @@ -112,7 +112,7 @@ static int kirin_drm_private_init(struct drm_device *dev, int ret; u32 ch; - kirin_priv = devm_kzalloc(dev->dev, sizeof(*kirin_priv), GFP_KERNEL); + kirin_priv = devm_kzalloc_obj(dev->dev, *kirin_priv); if (!kirin_priv) { DRM_ERROR("failed to alloc kirin_drm_private\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c index a46ab5d3d70fc7..d7c7ef22b73c5d 100644 --- a/drivers/gpu/drm/i915/display/intel_ddi.c +++ b/drivers/gpu/drm/i915/display/intel_ddi.c @@ -4629,7 +4629,7 @@ intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state, * From, xe3lpd onwards we have defeatured this with reference to * Wa_16024710867 */ - if (!IS_DISPLAY_VER(display, 9, 20)) + if (!IS_DISPLAY_VER(display, 9, 30)) return 0; if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP)) @@ -4723,10 +4723,10 @@ static void intel_ddi_encoder_reset(struct drm_encoder *encoder) intel_dp->reset_link_params = true; intel_dp_invalidate_source_oui(intel_dp); - intel_pps_encoder_reset(intel_dp); - if (intel_encoder_is_tc(&dig_port->base)) intel_tc_port_init_mode(dig_port); + + intel_pps_encoder_reset(intel_dp); } static int intel_ddi_encoder_late_register(struct drm_encoder *_encoder) @@ -5053,6 +5053,8 @@ static enum hpd_pin xelpd_hpd_pin(struct intel_display *display, enum port port) return HPD_PORT_D + port - PORT_D_XELPD; else if (port >= PORT_TC1) return HPD_PORT_TC1 + port - PORT_TC1; + else if (intel_phy_is_tc(display, intel_port_to_phy(display, port))) + return HPD_PORT_TC1 + intel_port_to_tc(display, port) - TC_PORT_1; else return HPD_PORT_A + port - PORT_A; } diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c index d5d4453f283bb0..b897678a93c03b 100644 --- a/drivers/gpu/drm/i915/display/intel_display.c +++ b/drivers/gpu/drm/i915/display/intel_display.c @@ -1854,15 +1854,22 @@ static void hsw_crtc_disable(struct intel_atomic_state *state, intel_atomic_get_old_crtc_state(state, crtc); struct intel_crtc *pipe_crtc; - if (crtc->cmtg.enabled && intel_cmtg_is_allowed(old_crtc_state)) { - intel_cmtg_set_clk_select(old_crtc_state); - intel_cmtg_disable(old_crtc_state); - } /* * FIXME collapse everything to one hook. * Need care with mst->ddi interactions. */ intel_encoders_disable(state, crtc); + + /* + * Disable CMTG after the encoders are disabled, but before the + * transcoder and port PLL are torn down in + * intel_encoders_post_disable()/intel_dpll_disable(). + */ + if (crtc->cmtg.enabled && intel_cmtg_is_allowed(old_crtc_state)) { + intel_cmtg_set_clk_select(old_crtc_state); + intel_cmtg_disable(old_crtc_state); + } + intel_encoders_post_disable(state, crtc); intel_dpll_disable(old_crtc_state); @@ -1897,6 +1904,11 @@ bool intel_phy_is_combo(struct intel_display *display, enum phy phy) return false; } +static bool intel_phy_is_edp_on_tc(struct intel_display *display, enum phy phy) +{ + return DISPLAY_RUNTIME_INFO(display)->edp_typec_support && phy == PHY_B; +} + /* * This function returns true if the DDI port respective to the PHY enumeration * is a Type-C capable port. @@ -1917,6 +1929,9 @@ bool intel_phy_is_tc(struct intel_display *display, enum phy phy) if (display->platform.dgfx) return false; + if (intel_phy_is_edp_on_tc(display, phy)) + return true; + if (DISPLAY_VER(display) >= 13) return phy >= PHY_F && phy <= PHY_I; else if (display->platform.tigerlake) @@ -1967,6 +1982,9 @@ enum phy intel_port_to_phy(struct intel_display *display, enum port port) */ enum tc_port intel_port_to_tc(struct intel_display *display, enum port port) { + if (intel_phy_is_edp_on_tc(display, intel_port_to_phy(display, port))) + return TC_PORT_1; + if (DISPLAY_VER(display) >= 12) return TC_PORT_1 + port - PORT_TC1; else @@ -2844,7 +2862,7 @@ void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state, HSYNC_END(adjusted_mode->crtc_hsync_end - 1)); if (display->platform.novalake && - IS_DISPLAY_STEP(display, STEP_A0, STEP_C0)) + IS_DISPLAY_STEP(display, STEP_A0, STEP_B0)) crtc_vtotal = 1; intel_de_write(display, TRANS_VTOTAL(display, transcoder), @@ -2941,7 +2959,7 @@ void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state, * is the transcoder's undelayed vblank. */ if (display->platform.novalake && - IS_DISPLAY_STEP(display, STEP_A0, STEP_C0)) + IS_DISPLAY_STEP(display, STEP_A0, STEP_B0)) crtc_vtotal = 1; intel_de_write(display, TRANS_VTOTAL(display, transcoder), diff --git a/drivers/gpu/drm/i915/display/intel_display_device.c b/drivers/gpu/drm/i915/display/intel_display_device.c index f17fc2c684724e..c74256359c253e 100644 --- a/drivers/gpu/drm/i915/display/intel_display_device.c +++ b/drivers/gpu/drm/i915/display/intel_display_device.c @@ -1813,7 +1813,10 @@ static void __intel_display_device_info_runtime_init(struct intel_display *displ if (intel_display_wa(display, INTEL_DISPLAY_WA_14011765242)) for_each_pipe(display, pipe) display_runtime->num_scalers[pipe] = 0; - else if (DISPLAY_VER(display) >= 11) { + else if (DISPLAY_VERx100(display) == 3002) { + for_each_pipe(display, pipe) + display_runtime->num_scalers[pipe] = 1; + } else if (DISPLAY_VER(display) >= 11) { for_each_pipe(display, pipe) display_runtime->num_scalers[pipe] = 2; } else if (DISPLAY_VER(display) >= 9) { diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c index d8c0d9381471d1..47741957935ae4 100644 --- a/drivers/gpu/drm/i915/display/intel_dp.c +++ b/drivers/gpu/drm/i915/display/intel_dp.c @@ -477,9 +477,9 @@ bool intel_dp_has_joiner(struct intel_dp *intel_dp) !connector->panel.vbt.edp.pipe_joiner_enable) return false; - return DISPLAY_VER(display) >= 12 || + return ((DISPLAY_VER(display) >= 12 && DISPLAY_VERx100(display) != 3002) || (DISPLAY_VER(display) == 11 && - encoder->port != PORT_A); + encoder->port != PORT_A)); } static int dg2_max_source_rate(struct intel_dp *intel_dp) diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux.c b/drivers/gpu/drm/i915/display/intel_dp_aux.c index 3cb07b0a901cff..36800cf19c50ab 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_aux.c +++ b/drivers/gpu/drm/i915/display/intel_dp_aux.c @@ -270,22 +270,6 @@ intel_dp_aux_xfer(struct intel_dp *intel_dp, for (i = 0; i < ARRAY_SIZE(ch_data); i++) ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i); - intel_digital_port_lock(encoder); - /* - * Abort transfers on a disconnected port as required by - * DP 1.4a link CTS 4.2.1.5, also avoiding the long AUX - * timeouts that would otherwise happen. - */ - if (!intel_dp_is_edp(intel_dp) && - !intel_digital_port_connected_locked(&dig_port->base)) { - ret = -ENXIO; - goto out_unlock; - } - - aux_domain = intel_aux_power_domain(dig_port); - - aux_wakeref = intel_display_power_get(display, aux_domain); - /* * The PPS state needs to be locked for: * - eDP on all platforms, since AUX transfers on eDP need VDD power @@ -308,6 +292,21 @@ intel_dp_aux_xfer(struct intel_dp *intel_dp, */ vdd = intel_pps_vdd_on_unlocked(intel_dp); + intel_digital_port_lock(encoder); + /* + * Abort transfers on a disconnected port as required by + * DP 1.4a link CTS 4.2.1.5, also avoiding the long AUX + * timeouts that would otherwise happen. + */ + if (!intel_dp_is_edp(intel_dp) && + !intel_digital_port_connected_locked(&dig_port->base)) { + ret = -ENXIO; + goto out_unlock; + } + + aux_domain = intel_aux_power_domain(dig_port); + aux_wakeref = intel_display_power_get(display, aux_domain); + /* * dp aux is extremely sensitive to irq latency, hence request the * lowest possible wakeup latency and so prevent the cpu from going into @@ -453,16 +452,16 @@ intel_dp_aux_xfer(struct intel_dp *intel_dp, out: cpu_latency_qos_update_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE); + intel_display_power_put_async(display, aux_domain, aux_wakeref); +out_unlock: + intel_digital_port_unlock(encoder); + if (vdd) intel_pps_vdd_off_unlocked(intel_dp, false); if (pps_wakeref) intel_pps_unlock(intel_dp, pps_wakeref); - intel_display_power_put_async(display, aux_domain, aux_wakeref); -out_unlock: - intel_digital_port_unlock(encoder); - return ret; } diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c index 36aebc32971b77..dc2f0f3088a942 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c @@ -41,6 +41,7 @@ #include "intel_display_types.h" #include "intel_dp.h" #include "intel_dp_aux_backlight.h" +#include "intel_quirks.h" /* * DP AUX registers for Intel's proprietary HDR backlight interface. We define @@ -693,11 +694,30 @@ int intel_dp_aux_init_backlight_funcs(struct intel_connector *connector) struct drm_device *dev = connector->base.dev; struct intel_panel *panel = &connector->panel; bool try_intel_interface = false, try_vesa_interface = false; + int enable_dpcd_backlight; + + /* + * Some devices have a broken VBT in some Panels, but not others, + * advertising INTEL_BACKLIGHT_DISPLAY_DDI, but actually failing to use + * the Intel interface. Adding a fallback to the Vesa interface gives + * these devices a working backlight for both the broken and non broken + * panel VBTs. + * + * This fallback can not be made the general default as this has broken + * other devices in the past whose VBT correctly reports + * INTEL_BACKLIGHT_DISPLAY_DDI and whose PWM path is the actual + * backlight control, but whose DPCD optimistically advertises + * DP_EDP_BACKLIGHT_AUX_ENABLE_CAP / _BRIGHTNESS_AUX_SET_CAP. + */ + enable_dpcd_backlight = display->params.enable_dpcd_backlight; + if (enable_dpcd_backlight == INTEL_DP_AUX_BACKLIGHT_AUTO && + intel_has_dpcd_quirk(intel_dp, QUIRK_ENABLE_DPCD_BACKLIGHT)) + enable_dpcd_backlight = INTEL_DP_AUX_BACKLIGHT_ON; /* Check the VBT and user's module parameters to figure out which * interfaces to probe */ - switch (display->params.enable_dpcd_backlight) { + switch (enable_dpcd_backlight) { case INTEL_DP_AUX_BACKLIGHT_OFF: return -ENODEV; case INTEL_DP_AUX_BACKLIGHT_AUTO: diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c index bfd6f0a1972534..ac9d3f11027478 100644 --- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c +++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c @@ -207,7 +207,8 @@ enum intel_dpll_id icl_tc_port_to_pll_id(enum tc_port tc_port) enum intel_dpll_id mtl_port_to_pll_id(struct intel_display *display, enum port port) { - if (port >= PORT_TC1) + if (port >= PORT_TC1 || + intel_phy_is_tc(display, intel_port_to_phy(display, port))) return icl_tc_port_to_pll_id(intel_port_to_tc(display, port)); switch (port) { diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.c b/drivers/gpu/drm/i915/display/intel_fbdev.c index 219ee17de3f68e..c09246a9865cde 100644 --- a/drivers/gpu/drm/i915/display/intel_fbdev.c +++ b/drivers/gpu/drm/i915/display/intel_fbdev.c @@ -75,9 +75,10 @@ static struct intel_frontbuffer *to_frontbuffer(struct intel_fbdev *ifbdev) return ifbdev->fb->frontbuffer; } -static void intel_fbdev_invalidate(struct intel_fbdev *ifbdev) +/* The console operation has already completed, hence flush not invalidate. */ +static void intel_fbdev_flush(struct intel_fbdev *ifbdev) { - intel_frontbuffer_invalidate(to_frontbuffer(ifbdev), ORIGIN_CPU); + intel_frontbuffer_flush(to_frontbuffer(ifbdev), ORIGIN_CPU); } FB_GEN_DEFAULT_DEFERRED_IOMEM_OPS(intel_fbdev, @@ -91,7 +92,7 @@ static int intel_fbdev_set_par(struct fb_info *info) ret = drm_fb_helper_set_par(info); if (ret == 0) - intel_fbdev_invalidate(ifbdev); + intel_fbdev_flush(ifbdev); return ret; } @@ -103,7 +104,7 @@ static int intel_fbdev_blank(int blank, struct fb_info *info) ret = drm_fb_helper_blank(blank, info); if (ret == 0) - intel_fbdev_invalidate(ifbdev); + intel_fbdev_flush(ifbdev); return ret; } @@ -116,7 +117,7 @@ static int intel_fbdev_pan_display(struct fb_var_screeninfo *var, ret = drm_fb_helper_pan_display(var, info); if (ret == 0) - intel_fbdev_invalidate(ifbdev); + intel_fbdev_flush(ifbdev); return ret; } @@ -180,7 +181,7 @@ static void intelfb_restore(struct drm_fb_helper *fb_helper) { struct intel_fbdev *ifbdev = to_intel_fbdev(fb_helper); - intel_fbdev_invalidate(ifbdev); + intel_fbdev_flush(ifbdev); } static void intelfb_set_suspend(struct drm_fb_helper *fb_helper, bool suspend) diff --git a/drivers/gpu/drm/i915/display/intel_plane.c b/drivers/gpu/drm/i915/display/intel_plane.c index 25ca049009efbc..d23de0f34e4b66 100644 --- a/drivers/gpu/drm/i915/display/intel_plane.c +++ b/drivers/gpu/drm/i915/display/intel_plane.c @@ -140,6 +140,7 @@ intel_plane_duplicate_state(struct drm_plane *plane) intel_state->dpt_vma = NULL; intel_state->fence_id = -1; intel_state->damage = DRM_RECT_INIT(0, 0, 0, 0); + intel_state->psr2_sel_fetch_area = DRM_RECT_INIT(0, 0, 0, 0); /* add reference to fb */ if (intel_state->hw.fb) @@ -1979,6 +1980,16 @@ static int intel_add_affected_planes(struct intel_atomic_state *state) ret = intel_joiner_add_affected_planes(state, intel_crtc_joined_pipe_mask(crtc_state)); if (ret) return ret; + + /* + * Add affected plane here to ensure UV and Y plane linking is + * in place if UV plane is added as a part of selective update. + */ + if (crtc_state->enable_psr2_sel_fetch) { + ret = intel_plane_add_affected(state, crtc); + if (ret) + return ret; + } } return 0; diff --git a/drivers/gpu/drm/i915/display/intel_pps.c b/drivers/gpu/drm/i915/display/intel_pps.c index d4c98b150fa2b7..8f1bfe43409719 100644 --- a/drivers/gpu/drm/i915/display/intel_pps.c +++ b/drivers/gpu/drm/i915/display/intel_pps.c @@ -23,6 +23,7 @@ #include "intel_pps.h" #include "intel_pps_regs.h" #include "intel_quirks.h" +#include "intel_tc.h" static void vlv_steal_power_sequencer(struct intel_display *display, enum pipe pipe); @@ -758,6 +759,9 @@ bool intel_pps_vdd_on_unlocked(struct intel_dp *intel_dp) if (edp_have_panel_vdd(intel_dp)) return need_to_disable; + if (intel_encoder_is_tc(&dig_port->base)) + intel_tc_port_get_link(dig_port, 1); + drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref); intel_dp->pps.vdd_wakeref = intel_display_power_get(display, intel_aux_power_domain(dig_port)); @@ -864,6 +868,9 @@ static void intel_pps_vdd_off_sync_unlocked(struct intel_dp *intel_dp) intel_display_power_put(display, intel_aux_power_domain(dig_port), fetch_and_zero(&intel_dp->pps.vdd_wakeref)); + + if (intel_encoder_is_tc(&dig_port->base)) + intel_tc_port_put_link(dig_port); } void intel_pps_vdd_off_sync(struct intel_dp *intel_dp) @@ -1066,6 +1073,9 @@ void intel_pps_off_unlocked(struct intel_dp *intel_dp) intel_display_power_put(display, intel_aux_power_domain(dig_port), fetch_and_zero(&intel_dp->pps.vdd_wakeref)); + + if (intel_encoder_is_tc(&dig_port->base)) + intel_tc_port_put_link(dig_port); } void intel_pps_off(struct intel_dp *intel_dp) @@ -1334,6 +1344,10 @@ static void pps_vdd_init(struct intel_dp *intel_dp) "[ENCODER:%d:%s] %s VDD left on by BIOS, adjusting state tracking\n", dig_port->base.base.base.id, dig_port->base.base.name, pps_name(intel_dp)); + + if (intel_encoder_is_tc(&dig_port->base)) + intel_tc_port_get_link(dig_port, 1); + drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref); intel_dp->pps.vdd_wakeref = intel_display_power_get(display, intel_aux_power_domain(dig_port)); diff --git a/drivers/gpu/drm/i915/display/intel_psr.c b/drivers/gpu/drm/i915/display/intel_psr.c index 00d0146b260024..0ae347fe6cd199 100644 --- a/drivers/gpu/drm/i915/display/intel_psr.c +++ b/drivers/gpu/drm/i915/display/intel_psr.c @@ -2712,23 +2712,25 @@ static u32 psr2_pipe_srcsz_early_tpt_calc(struct intel_crtc_state *crtc_state, } static void clip_area_update(struct drm_rect *overlap_damage_area, - struct drm_rect *damage_area, - struct drm_rect *display_area) + const struct drm_rect *damage_area, + const struct drm_rect *display_area) { - if (!drm_rect_intersect(damage_area, display_area)) + struct drm_rect inter = *damage_area; + + if (!drm_rect_intersect(&inter, display_area)) return; if (overlap_damage_area->y1 == -1) { - overlap_damage_area->y1 = damage_area->y1; - overlap_damage_area->y2 = damage_area->y2; + overlap_damage_area->y1 = inter.y1; + overlap_damage_area->y2 = inter.y2; return; } - if (damage_area->y1 < overlap_damage_area->y1) - overlap_damage_area->y1 = damage_area->y1; + if (inter.y1 < overlap_damage_area->y1) + overlap_damage_area->y1 = inter.y1; - if (damage_area->y2 > overlap_damage_area->y2) - overlap_damage_area->y2 = damage_area->y2; + if (inter.y2 > overlap_damage_area->y2) + overlap_damage_area->y2 = inter.y2; } static bool intel_psr2_sel_fetch_pipe_alignment(struct intel_crtc_state *crtc_state) @@ -2905,7 +2907,7 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, .y2 = crtc_state->hw.adjusted_mode.crtc_vdisplay, }; bool full_update = false, su_area_changed; - int i, ret; + int i; /* * Selective fetch is not always usable, for instance it is dropped @@ -2923,16 +2925,16 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, if (!crtc_state->enable_psr2_sel_fetch) return 0; - if (!psr2_sel_fetch_pipe_state_supported(crtc_state)) { - full_update = true; - goto skip_sel_fetch_set_loop; - } - crtc_state->psr2_su_area.x1 = 0; crtc_state->psr2_su_area.y1 = -1; crtc_state->psr2_su_area.x2 = drm_rect_width(&display_area); crtc_state->psr2_su_area.y2 = -1; + if (!psr2_sel_fetch_pipe_state_supported(crtc_state)) { + full_update = true; + goto skip_su_area_calc; + } + /* * Calculate minimal selective fetch area of each plane and calculate * the pipe damaged area. @@ -3016,23 +3018,19 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, } if (full_update) - goto skip_sel_fetch_set_loop; + goto skip_su_area_calc; intel_psr_apply_su_area_workarounds(crtc_state); - ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); - if (ret) - return ret; - do { bool cursor_in_su_area = false; /* * Adjust su area to cover cursor fully as necessary - * (early transport). This needs to be done after - * drm_atomic_add_affected_planes to ensure visible - * cursor is added into affected planes even when - * cursor is not updated by itself. + * (early transport). A visible cursor is in the state + * even when it is not updated by itself as all planes + * of the pipe are added into the state before the plane + * checks when selective fetch is enabled. */ intel_psr2_sel_fetch_et_alignment(state, crtc, &display_area, &cursor_in_su_area); @@ -3052,6 +3050,11 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, break; } while (su_area_changed); +skip_su_area_calc: + if (full_update) + clip_area_update(&crtc_state->psr2_su_area, &display_area, + &display_area); + /* * Now that we have the pipe damaged area check if it intersect with * every plane, if it does set the plane selective fetch area. @@ -3067,28 +3070,14 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, inter = crtc_state->psr2_su_area; sel_fetch_area = &new_plane_state->psr2_sel_fetch_area; - if (!drm_rect_intersect(&inter, &new_plane_state->uapi.dst)) { - sel_fetch_area->y1 = -1; - sel_fetch_area->y2 = -1; - /* - * if plane sel fetch was previously enabled -> - * disable it - */ - if (drm_rect_height(&old_plane_state->psr2_sel_fetch_area) > 0) - crtc_state->update_planes |= BIT(plane->id); - - continue; + if (drm_rect_intersect(&inter, &new_plane_state->uapi.dst)) { + sel_fetch_area->y1 = inter.y1 - new_plane_state->uapi.dst.y1; + sel_fetch_area->y2 = inter.y2 - new_plane_state->uapi.dst.y1; } - if (!psr2_sel_fetch_plane_state_supported(new_plane_state)) { - full_update = true; - break; - } - - sel_fetch_area = &new_plane_state->psr2_sel_fetch_area; - sel_fetch_area->y1 = inter.y1 - new_plane_state->uapi.dst.y1; - sel_fetch_area->y2 = inter.y2 - new_plane_state->uapi.dst.y1; - crtc_state->update_planes |= BIT(plane->id); + if (!drm_rect_equals(&old_plane_state->psr2_sel_fetch_area, + sel_fetch_area)) + crtc_state->update_planes |= BIT(plane->id); /* * Sel_fetch_area is calculated for UV plane. Use @@ -3096,24 +3085,25 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, */ if (linked) { struct intel_plane_state *linked_new_plane_state; + struct intel_plane_state *linked_old_plane_state; struct drm_rect *linked_sel_fetch_area; - linked_new_plane_state = intel_atomic_get_plane_state(state, linked); - if (IS_ERR(linked_new_plane_state)) - return PTR_ERR(linked_new_plane_state); + linked_new_plane_state = intel_atomic_get_new_plane_state(state, linked); + if (!linked_new_plane_state) + return -EINVAL; + + linked_old_plane_state = intel_atomic_get_old_plane_state(state, linked); linked_sel_fetch_area = &linked_new_plane_state->psr2_sel_fetch_area; linked_sel_fetch_area->y1 = sel_fetch_area->y1; linked_sel_fetch_area->y2 = sel_fetch_area->y2; - crtc_state->update_planes |= BIT(linked->id); + + if (!drm_rect_equals(&linked_old_plane_state->psr2_sel_fetch_area, + linked_sel_fetch_area)) + crtc_state->update_planes |= BIT(linked->id); } } -skip_sel_fetch_set_loop: - if (full_update) - clip_area_update(&crtc_state->psr2_su_area, &display_area, - &display_area); - psr2_man_trk_ctl_calc(crtc_state, full_update); crtc_state->pipe_srcsz_early_tpt = psr2_pipe_srcsz_early_tpt_calc(crtc_state, full_update); @@ -3655,12 +3645,6 @@ static void _psr_flush_handle(struct intel_dp *intel_dp) intel_psr_exit(intel_dp); } else if (intel_dp->psr.psr2_sel_fetch_enabled) { /* Selective fetch prior LNL */ - if (intel_dp->psr.psr2_sel_fetch_cff_enabled) { - /* can we turn CFF off? */ - if (intel_dp->psr.busy_frontbuffer_bits == 0) - intel_dp->psr.psr2_sel_fetch_cff_enabled = false; - } - /* * Still keep cff bit enabled as we don't have proper SU * configuration in case update is sent for any reason after @@ -3679,9 +3663,6 @@ static void _psr_flush_handle(struct intel_dp *intel_dp) */ intel_psr_force_update(intel_dp); } - - if (!intel_dp->psr.active && !intel_dp->psr.busy_frontbuffer_bits) - queue_work(display->wq.unordered, &intel_dp->psr.work); } /** @@ -3714,28 +3695,39 @@ void intel_psr_flush(struct intel_display *display, pipe_frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(intel_dp->psr.pipe); + + if (pipe_frontbuffer_bits == 0) + goto unlock; + intel_dp->psr.busy_frontbuffer_bits &= ~pipe_frontbuffer_bits; - /* - * If the PSR is paused by an explicit intel_psr_paused() call, - * we have to ensure that the PSR is not activated until - * intel_psr_resume() is called. - */ if (intel_dp->psr.pause_counter) - goto unlock; + goto rearm; - if (origin == ORIGIN_FLIP || - (origin == ORIGIN_CURSOR_UPDATE && - !intel_dp->psr.psr2_sel_fetch_enabled)) { + if (origin == ORIGIN_FLIP || origin == ORIGIN_CURSOR_UPDATE) psr2_dc3co_flush_locked(intel_dp, frontbuffer_bits); - goto unlock; - } - if (pipe_frontbuffer_bits == 0) - goto unlock; + if (origin == ORIGIN_FLIP) + goto rearm; /* By definition flush = invalidate + flush */ _psr_flush_handle(intel_dp); + +rearm: + if (!intel_dp->psr.busy_frontbuffer_bits) { + if (intel_dp->psr.psr2_sel_fetch_cff_enabled) + intel_dp->psr.psr2_sel_fetch_cff_enabled = false; + + /* + * If the PSR is paused by an explicit + * intel_psr_paused() call, we have to ensure that the + * PSR is not activated until intel_psr_resume() is + * called. + */ + if (!intel_dp->psr.active && !intel_dp->psr.pause_counter) + queue_work(display->wq.unordered, &intel_dp->psr.work); + } + unlock: mutex_unlock(&intel_dp->psr.lock); } diff --git a/drivers/gpu/drm/i915/display/intel_psr_regs.h b/drivers/gpu/drm/i915/display/intel_psr_regs.h index bb577e7e3bbda4..a57bc111290d13 100644 --- a/drivers/gpu/drm/i915/display/intel_psr_regs.h +++ b/drivers/gpu/drm/i915/display/intel_psr_regs.h @@ -254,12 +254,12 @@ #define _LNL_SFF_CTL_A 0x60918 #define _LNL_SFF_CTL_B 0x61918 #define LNL_SFF_CTL(tran) _MMIO_TRANS(tran, _LNL_SFF_CTL_A, _LNL_SFF_CTL_B) -#define LNL_SFF_CTL_SF_SINGLE_FULL_FRAME REG_BIT(1) +#define LNL_SFF_CTL_SF_SINGLE_FULL_FRAME REG_BIT(0) #define _LNL_CFF_CTL_A 0x6091c #define _LNL_CFF_CTL_B 0x6191c #define LNL_CFF_CTL(tran) _MMIO_TRANS(tran, _LNL_CFF_CTL_A, _LNL_CFF_CTL_B) -#define LNL_CFF_CTL_SF_CONTINUOUS_FULL_FRAME REG_BIT(1) +#define LNL_CFF_CTL_SF_CONTINUOUS_FULL_FRAME REG_BIT(0) /* PSR2 Early transport */ #define _PIPE_SRCSZ_ERLY_TPT_A 0x70074 diff --git a/drivers/gpu/drm/i915/display/intel_quirks.c b/drivers/gpu/drm/i915/display/intel_quirks.c index 7d7db774d8c7b9..96eb9a40df9b95 100644 --- a/drivers/gpu/drm/i915/display/intel_quirks.c +++ b/drivers/gpu/drm/i915/display/intel_quirks.c @@ -100,6 +100,14 @@ static void quirk_disable_psr2(struct intel_display *display) drm_info(display->drm, "PSR2 support not currently available for this setup, applying disable PSR2 quirk\n"); } +static void quirk_enable_dpcd_backlight(struct intel_dp *intel_dp) +{ + struct intel_display *display = to_intel_display(intel_dp); + + intel_set_dpcd_quirk(intel_dp, QUIRK_ENABLE_DPCD_BACKLIGHT); + drm_info(display->drm, "Applying Enable DPCD Backlight quirk\n"); +} + struct intel_quirk { int device; int subsystem_vendor; @@ -289,6 +297,22 @@ static const struct intel_dpcd_quirk intel_dpcd_quirks[] = { .sink_oui = SINK_OUI(0x00, 0x22, 0xb9), .hook = quirk_disable_edp_panel_replay, }, + /* TUXEDO InsanityBook 15 v1 */ + { + .device = 0x591b, + .subsystem_vendor = 0x1558, + .subsystem_device = 0x9501, + .sink_oui = SINK_OUI(0x38, 0xec, 0x11), + .hook = quirk_enable_dpcd_backlight, + }, + /* TUXEDO DX1708 */ + { + .device = 0x3e9b, + .subsystem_vendor = 0x1558, + .subsystem_device = 0x8500, + .sink_oui = SINK_OUI(0x38, 0xec, 0x11), + .hook = quirk_enable_dpcd_backlight, + }, }; void intel_init_quirks(struct intel_display *display) diff --git a/drivers/gpu/drm/i915/display/intel_quirks.h b/drivers/gpu/drm/i915/display/intel_quirks.h index 970a4fe52fafca..4996419ae76bd7 100644 --- a/drivers/gpu/drm/i915/display/intel_quirks.h +++ b/drivers/gpu/drm/i915/display/intel_quirks.h @@ -23,6 +23,7 @@ enum intel_quirk_id { QUIRK_EDP_LIMIT_RATE_HBR2, QUIRK_DISABLE_EDP_PANEL_REPLAY, QUIRK_DISABLE_PSR2, + QUIRK_ENABLE_DPCD_BACKLIGHT, }; void intel_init_quirks(struct intel_display *display); diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c index f2d86b29c4154d..f878494bcb3880 100644 --- a/drivers/gpu/drm/i915/display/intel_tc.c +++ b/drivers/gpu/drm/i915/display/intel_tc.c @@ -1669,7 +1669,7 @@ void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port, mutex_lock(&tc->lock); - drm_WARN_ON(display->drm, tc->link_refcount != 1); + drm_WARN_ON(display->drm, tc->link_refcount < 1); if (!tc_port_has_active_streams(tc, crtc_state)) { /* * TBT-alt is the default mode in any case the PHY ownership is not @@ -1683,7 +1683,12 @@ void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port, "Port %s: PHY left in %s mode on disabled port, disconnecting it\n", tc->port_name, tc_port_mode_name(tc->init_mode)); - tc_phy_disconnect(tc); + /* + * A link reference taken during a preceding (eDP) connector initialization will be + * dropped later, also disconnecting the PHY. + */ + if (tc->link_refcount == 1) + tc_phy_disconnect(tc); __intel_tc_port_put_link(tc); } diff --git a/drivers/gpu/drm/i915/display/intel_vrr.c b/drivers/gpu/drm/i915/display/intel_vrr.c index d43a06907d18a9..e59345bd1d337d 100644 --- a/drivers/gpu/drm/i915/display/intel_vrr.c +++ b/drivers/gpu/drm/i915/display/intel_vrr.c @@ -1147,7 +1147,7 @@ void intel_vrr_get_config(struct intel_crtc_state *crtc_state) } if (display->platform.novalake && - IS_DISPLAY_STEP(display, STEP_A0, STEP_C0)) + IS_DISPLAY_STEP(display, STEP_A0, STEP_B0)) crtc_state->hw.adjusted_mode.crtc_vtotal = intel_vrr_vmin_vtotal(crtc_state); @@ -1202,9 +1202,13 @@ int intel_vrr_safe_window_start(const struct intel_crtc_state *crtc_state) static int intel_vrr_dcb_vmin_vblank_start(const struct intel_crtc_state *crtc_state) { - return (intel_vrr_dcb_vmin_vblank_start_next(crtc_state) < 0) ? - intel_vrr_dcb_vmin_vblank_start_final(crtc_state) : - intel_vrr_dcb_vmin_vblank_start_next(crtc_state); + int vblank_start; + + vblank_start = intel_vrr_dcb_vmin_vblank_start_next(crtc_state); + if (vblank_start < 0) + vblank_start = intel_vrr_dcb_vmin_vblank_start_final(crtc_state); + + return vblank_start; } int intel_vrr_vmin_safe_window_end(const struct intel_crtc_state *crtc_state) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 1b7f5bf13e5046..c41e1b9a40bca6 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -2805,7 +2805,6 @@ add_timeline_fence_array(struct i915_execbuffer *eb, u64 __user *user_values; struct eb_fence *f; u64 nfences; - int err = 0; nfences = timeline_fences->fence_count; if (!nfences) @@ -2843,6 +2842,7 @@ add_timeline_fence_array(struct i915_execbuffer *eb, struct drm_syncobj *syncobj; struct dma_fence *fence = NULL; u64 point; + int err = 0; if (__copy_from_user(&user_fence, user_fences++, diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c index 59e3d4de7d3c85..6734c49572d792 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c @@ -341,7 +341,7 @@ static void *i915_gem_object_map_pfn(struct drm_i915_gem_object *obj, if (n_pfn > ARRAY_SIZE(stack)) { /* Too big for stack -- allocate temporary array instead */ - pfns = kvmalloc_array(n_pfn, sizeof(*pfns), GFP_KERNEL); + pfns = kvmalloc_objs(*pfns, n_pfn); if (!pfns) return ERR_PTR(-ENOMEM); } diff --git a/drivers/gpu/drm/i915/gt/intel_sseu_debugfs.c b/drivers/gpu/drm/i915/gt/intel_sseu_debugfs.c index 54f38bc4b1b5c0..5e1adb95d9233e 100644 --- a/drivers/gpu/drm/i915/gt/intel_sseu_debugfs.c +++ b/drivers/gpu/drm/i915/gt/intel_sseu_debugfs.c @@ -245,7 +245,7 @@ int intel_sseu_status(struct seq_file *m, struct intel_gt *gt) seq_puts(m, "SSEU Device Status\n"); - sseu = kzalloc(sizeof(*sseu), GFP_KERNEL); + sseu = kzalloc_obj(*sseu); if (!sseu) return -ENOMEM; diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c index 2cfc23c58e9091..3599c9f101e14c 100644 --- a/drivers/gpu/drm/i915/gt/selftest_reset.c +++ b/drivers/gpu/drm/i915/gt/selftest_reset.c @@ -38,7 +38,7 @@ __igt_reset_stolen(struct intel_gt *gt, if (!num_pages) return 0; - crc = kmalloc_array(num_pages, sizeof(u32), GFP_KERNEL); + crc = kmalloc_objs(u32, num_pages); if (!crc) return -ENOMEM; diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c index 5353a9c66694bd..0d059716791235 100644 --- a/drivers/gpu/drm/i915/i915_gpu_error.c +++ b/drivers/gpu/drm/i915/i915_gpu_error.c @@ -1807,7 +1807,7 @@ static void gt_record_guc_hw_state(struct intel_uncore *uncore, for (i = 0; i < ARRAY_SIZE(guc_hw_reg_state); i++) count += guc_hw_reg_state[i].count; - hw_state = kcalloc(count, sizeof(u32), ALLOW_FAIL); + hw_state = kzalloc_objs(u32, count, ALLOW_FAIL); if (!hw_state) return; diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c index e6bd06774816a3..ce7b76943c0637 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c @@ -251,7 +251,7 @@ static int lowlevel_hole(struct i915_address_space *vm, struct i915_vma_resource *mock_vma_res; unsigned int size; - mock_vma_res = kzalloc(sizeof(*mock_vma_res), GFP_KERNEL); + mock_vma_res = kzalloc_obj(*mock_vma_res); if (!mock_vma_res) return -ENOMEM; diff --git a/drivers/gpu/drm/i915/selftests/i915_random.c b/drivers/gpu/drm/i915/selftests/i915_random.c index abdfadcf626bdf..59d779897a41ff 100644 --- a/drivers/gpu/drm/i915/selftests/i915_random.c +++ b/drivers/gpu/drm/i915/selftests/i915_random.c @@ -77,8 +77,8 @@ unsigned int *i915_random_order(unsigned int count, struct rnd_state *state) { unsigned int *order, i; - order = kmalloc_array(count, sizeof(*order), - GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN); + order = kmalloc_objs(*order, count, + GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN); if (!order) return order; diff --git a/drivers/gpu/drm/imagination/pvr_fw_trace.c b/drivers/gpu/drm/imagination/pvr_fw_trace.c index 6fe478f64f027f..ebd8c4e2f902d5 100644 --- a/drivers/gpu/drm/imagination/pvr_fw_trace.c +++ b/drivers/gpu/drm/imagination/pvr_fw_trace.c @@ -458,8 +458,8 @@ static int fw_trace_open(struct inode *inode, struct file *file) if (!trace_seq_data) return -ENOMEM; - trace_seq_data->buffer = kcalloc(ROGUE_FW_TRACE_BUF_DEFAULT_SIZE_IN_DWORDS, - sizeof(*trace_seq_data->buffer), GFP_KERNEL); + trace_seq_data->buffer = kzalloc_objs(*trace_seq_data->buffer, + ROGUE_FW_TRACE_BUF_DEFAULT_SIZE_IN_DWORDS); if (!trace_seq_data->buffer) { err = -ENOMEM; goto err_free_data; diff --git a/drivers/gpu/drm/imagination/pvr_rogue_fwif.h b/drivers/gpu/drm/imagination/pvr_rogue_fwif.h index 5d590c4c25663e..2f8daa93c9e683 100644 --- a/drivers/gpu/drm/imagination/pvr_rogue_fwif.h +++ b/drivers/gpu/drm/imagination/pvr_rogue_fwif.h @@ -2174,7 +2174,7 @@ struct rogue_fwif_hwrtdata { bool geom_caches_need_zeroing __aligned(4); struct rogue_fwif_cleanup_ctl cleanup_state __aligned(64); -} __aligned(8); +} __aligned(64); /* ****************************************************************************** diff --git a/drivers/gpu/drm/imx/dc/dc-cf.c b/drivers/gpu/drm/imx/dc/dc-cf.c index 7c2f7abc509911..30576170f0c097 100644 --- a/drivers/gpu/drm/imx/dc/dc-cf.c +++ b/drivers/gpu/drm/imx/dc/dc-cf.c @@ -90,7 +90,7 @@ static int dc_cf_bind(struct device *dev, struct device *master, void *data) struct dc_cf *cf; int id; - cf = devm_kzalloc(dev, sizeof(*cf), GFP_KERNEL); + cf = devm_kzalloc_obj(dev, *cf); if (!cf) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-de.c b/drivers/gpu/drm/imx/dc/dc-de.c index 15056590b04d47..67fa7aff777d44 100644 --- a/drivers/gpu/drm/imx/dc/dc-de.c +++ b/drivers/gpu/drm/imx/dc/dc-de.c @@ -56,7 +56,7 @@ static int dc_de_bind(struct device *dev, struct device *master, void *data) struct dc_de *de; int ret, id; - de = devm_kzalloc(dev, sizeof(*de), GFP_KERNEL); + de = devm_kzalloc_obj(dev, *de); if (!de) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-drv.c b/drivers/gpu/drm/imx/dc/dc-drv.c index 13795a2ad73500..30e2545280e06e 100644 --- a/drivers/gpu/drm/imx/dc/dc-drv.c +++ b/drivers/gpu/drm/imx/dc/dc-drv.c @@ -158,7 +158,7 @@ static int dc_probe(struct platform_device *pdev) struct dc_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-ed.c b/drivers/gpu/drm/imx/dc/dc-ed.c index de1b71315eabd3..b0c0013914b845 100644 --- a/drivers/gpu/drm/imx/dc/dc-ed.c +++ b/drivers/gpu/drm/imx/dc/dc-ed.c @@ -197,7 +197,7 @@ static int dc_ed_bind(struct device *dev, struct device *master, void *data) struct dc_ed *ed; int id; - ed = devm_kzalloc(dev, sizeof(*ed), GFP_KERNEL); + ed = devm_kzalloc_obj(dev, *ed); if (!ed) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-fg.c b/drivers/gpu/drm/imx/dc/dc-fg.c index 3741dc66c0d936..c5a9d614756abc 100644 --- a/drivers/gpu/drm/imx/dc/dc-fg.c +++ b/drivers/gpu/drm/imx/dc/dc-fg.c @@ -308,7 +308,7 @@ static int dc_fg_bind(struct device *dev, struct device *master, void *data) struct dc_fg *fg; int id; - fg = devm_kzalloc(dev, sizeof(*fg), GFP_KERNEL); + fg = devm_kzalloc_obj(dev, *fg); if (!fg) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-fl.c b/drivers/gpu/drm/imx/dc/dc-fl.c index 9f03df44a63a55..b88085363b8753 100644 --- a/drivers/gpu/drm/imx/dc/dc-fl.c +++ b/drivers/gpu/drm/imx/dc/dc-fl.c @@ -102,7 +102,7 @@ static int dc_fl_bind(struct device *dev, struct device *master, void *data) struct dc_fu *fu; int i, id; - fl = devm_kzalloc(dev, sizeof(*fl), GFP_KERNEL); + fl = devm_kzalloc_obj(dev, *fl); if (!fl) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-fw.c b/drivers/gpu/drm/imx/dc/dc-fw.c index 14512c01ea784f..758cade1d766f5 100644 --- a/drivers/gpu/drm/imx/dc/dc-fw.c +++ b/drivers/gpu/drm/imx/dc/dc-fw.c @@ -132,7 +132,7 @@ static int dc_fw_bind(struct device *dev, struct device *master, void *data) struct dc_fu *fu; int i, id; - fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(dev, *fw); if (!fw) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-ic.c b/drivers/gpu/drm/imx/dc/dc-ic.c index fa87bf1f450870..64f058a466e472 100644 --- a/drivers/gpu/drm/imx/dc/dc-ic.c +++ b/drivers/gpu/drm/imx/dc/dc-ic.c @@ -120,11 +120,11 @@ static int dc_ic_probe(struct platform_device *pdev) void __iomem *base; int i, ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; - entry = devm_kcalloc(dev, IRQ_COUNT, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_objs(dev, *entry, IRQ_COUNT); if (!entry) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-lb.c b/drivers/gpu/drm/imx/dc/dc-lb.c index cb614f3c2f6911..1332ce2dc1b894 100644 --- a/drivers/gpu/drm/imx/dc/dc-lb.c +++ b/drivers/gpu/drm/imx/dc/dc-lb.c @@ -250,7 +250,7 @@ static int dc_lb_bind(struct device *dev, struct device *master, void *data) void __iomem *base_cfg; struct dc_lb *lb; - lb = devm_kzalloc(dev, sizeof(*lb), GFP_KERNEL); + lb = devm_kzalloc_obj(dev, *lb); if (!lb) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-pe.c b/drivers/gpu/drm/imx/dc/dc-pe.c index 4eb8c11de99c09..718426ccff520c 100644 --- a/drivers/gpu/drm/imx/dc/dc-pe.c +++ b/drivers/gpu/drm/imx/dc/dc-pe.c @@ -22,7 +22,7 @@ static int dc_pe_bind(struct device *dev, struct device *master, void *data) struct dc_pe *pe; int ret; - pe = devm_kzalloc(dev, sizeof(*pe), GFP_KERNEL); + pe = devm_kzalloc_obj(dev, *pe); if (!pe) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dc/dc-tc.c b/drivers/gpu/drm/imx/dc/dc-tc.c index d0d4faba790e50..7588c17c0e5cbe 100644 --- a/drivers/gpu/drm/imx/dc/dc-tc.c +++ b/drivers/gpu/drm/imx/dc/dc-tc.c @@ -78,7 +78,7 @@ static int dc_tc_bind(struct device *dev, struct device *master, void *data) struct dc_tc *tc; int id; - tc = devm_kzalloc(dev, sizeof(*tc), GFP_KERNEL); + tc = devm_kzalloc_obj(dev, *tc); if (!tc) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-blkctl.c b/drivers/gpu/drm/imx/dcss/dcss-blkctl.c index 803e3fcdb50f18..9214ed37dbaecf 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-blkctl.c +++ b/drivers/gpu/drm/imx/dcss/dcss-blkctl.c @@ -42,7 +42,7 @@ int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base) { struct dcss_blkctl *blkctl; - blkctl = devm_kzalloc(dcss->dev, sizeof(*blkctl), GFP_KERNEL); + blkctl = devm_kzalloc_obj(dcss->dev, *blkctl); if (!blkctl) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-ctxld.c b/drivers/gpu/drm/imx/dcss/dcss-ctxld.c index e41d5c2a3ea4bf..3c8e13bade33a8 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-ctxld.c +++ b/drivers/gpu/drm/imx/dcss/dcss-ctxld.c @@ -202,7 +202,7 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base) struct dcss_ctxld *ctxld; int ret; - ctxld = devm_kzalloc(dcss->dev, sizeof(*ctxld), GFP_KERNEL); + ctxld = devm_kzalloc_obj(dcss->dev, *ctxld); if (!ctxld) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-dev.c b/drivers/gpu/drm/imx/dcss/dcss-dev.c index 7fd0c4c14205dc..45a91e43bab1c5 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-dev.c +++ b/drivers/gpu/drm/imx/dcss/dcss-dev.c @@ -185,7 +185,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output) return ERR_PTR(-EBUSY); } - dcss = devm_kzalloc(dev, sizeof(*dcss), GFP_KERNEL); + dcss = devm_kzalloc_obj(dev, *dcss); if (!dcss) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/imx/dcss/dcss-dpr.c b/drivers/gpu/drm/imx/dcss/dcss-dpr.c index 072eb209249f46..2428b884b033b5 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-dpr.c +++ b/drivers/gpu/drm/imx/dcss/dcss-dpr.c @@ -155,7 +155,7 @@ int dcss_dpr_init(struct dcss_dev *dcss, unsigned long dpr_base) { struct dcss_dpr *dpr; - dpr = devm_kzalloc(dcss->dev, sizeof(*dpr), GFP_KERNEL); + dpr = devm_kzalloc_obj(dcss->dev, *dpr); if (!dpr) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-drv.c b/drivers/gpu/drm/imx/dcss/dcss-drv.c index 19b027cc1dc4a9..19c618f6423e87 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-drv.c +++ b/drivers/gpu/drm/imx/dcss/dcss-drv.c @@ -51,7 +51,7 @@ static int dcss_drv_platform_probe(struct platform_device *pdev) of_node_put(remote); - mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL); + mdrv = devm_kzalloc_obj(dev, *mdrv); if (!mdrv) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-dtg.c b/drivers/gpu/drm/imx/dcss/dcss-dtg.c index 6bbfd9aa27aca4..a419731eb09fcf 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-dtg.c +++ b/drivers/gpu/drm/imx/dcss/dcss-dtg.c @@ -150,7 +150,7 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) int ret = 0; struct dcss_dtg *dtg; - dtg = devm_kzalloc(dcss->dev, sizeof(*dtg), GFP_KERNEL); + dtg = devm_kzalloc_obj(dcss->dev, *dtg); if (!dtg) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-scaler.c b/drivers/gpu/drm/imx/dcss/dcss-scaler.c index 5c7f8d952ec1a1..76d21ade52189e 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-scaler.c +++ b/drivers/gpu/drm/imx/dcss/dcss-scaler.c @@ -321,7 +321,7 @@ int dcss_scaler_init(struct dcss_dev *dcss, unsigned long scaler_base) { struct dcss_scaler *scaler; - scaler = devm_kzalloc(dcss->dev, sizeof(*scaler), GFP_KERNEL); + scaler = devm_kzalloc_obj(dcss->dev, *scaler); if (!scaler) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/dcss/dcss-ss.c b/drivers/gpu/drm/imx/dcss/dcss-ss.c index 0df81866fb7b98..2846faa9a8b6d5 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-ss.c +++ b/drivers/gpu/drm/imx/dcss/dcss-ss.c @@ -83,7 +83,7 @@ int dcss_ss_init(struct dcss_dev *dcss, unsigned long ss_base) { struct dcss_ss *ss; - ss = devm_kzalloc(dcss->dev, sizeof(*ss), GFP_KERNEL); + ss = devm_kzalloc_obj(dcss->dev, *ss); if (!ss) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/ipuv3/dw_hdmi-imx.c b/drivers/gpu/drm/imx/ipuv3/dw_hdmi-imx.c index 398f3cce553228..09babdcf3289a3 100644 --- a/drivers/gpu/drm/imx/ipuv3/dw_hdmi-imx.c +++ b/drivers/gpu/drm/imx/ipuv3/dw_hdmi-imx.c @@ -224,7 +224,7 @@ static int dw_hdmi_imx_probe(struct platform_device *pdev) struct imx_hdmi *hdmi; int ret; - hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(&pdev->dev, *hdmi); if (!hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c index 63d6a1e7c1bda7..523c184aafd437 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c @@ -505,7 +505,7 @@ static int imx_ldb_probe(struct platform_device *pdev) int ret; int i; - imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL); + imx_ldb = devm_kzalloc_obj(dev, *imx_ldb); if (!imx_ldb) return -ENOMEM; diff --git a/drivers/gpu/drm/imx/ipuv3/imx-tve.c b/drivers/gpu/drm/imx/ipuv3/imx-tve.c index 4ece793743729c..a55e1cdd33445a 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-tve.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-tve.c @@ -546,7 +546,7 @@ static int imx_tve_probe(struct platform_device *pdev) int irq; int ret; - tve = devm_kzalloc(dev, sizeof(*tve), GFP_KERNEL); + tve = devm_kzalloc_obj(dev, *tve); if (!tve) return -ENOMEM; diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c b/drivers/gpu/drm/ingenic/ingenic-ipu.c index bf24882e8d9f10..7f3cc8a75898bd 100644 --- a/drivers/gpu/drm/ingenic/ingenic-ipu.c +++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c @@ -816,7 +816,7 @@ static int ingenic_ipu_bind(struct device *dev, struct device *master, void *d) unsigned int sharpness_max; int err, irq; - ipu = devm_kzalloc(dev, sizeof(*ipu), GFP_KERNEL); + ipu = devm_kzalloc_obj(dev, *ipu); if (!ipu) return -ENOMEM; diff --git a/drivers/gpu/drm/kmb/kmb_dsi.c b/drivers/gpu/drm/kmb/kmb_dsi.c index 13adba96bc7865..6ca5aeff5d1445 100644 --- a/drivers/gpu/drm/kmb/kmb_dsi.c +++ b/drivers/gpu/drm/kmb/kmb_dsi.c @@ -1412,7 +1412,7 @@ struct kmb_dsi *kmb_dsi_init(struct platform_device *pdev) struct kmb_dsi *kmb_dsi; struct device *dev = get_device(&pdev->dev); - kmb_dsi = devm_kzalloc(dev, sizeof(*kmb_dsi), GFP_KERNEL); + kmb_dsi = devm_kzalloc_obj(dev, *kmb_dsi); if (!kmb_dsi) { dev_err(dev, "failed to allocate kmb_dsi\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index 9a0eb1092ad3da..5113d951246445 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -377,7 +377,7 @@ static int lima_pdev_probe(struct platform_device *pdev) if (err) return err; - ldev = devm_kzalloc(&pdev->dev, sizeof(*ldev), GFP_KERNEL); + ldev = devm_kzalloc_obj(&pdev->dev, *ldev); if (!ldev) { err = -ENOMEM; goto err_out0; diff --git a/drivers/gpu/drm/logicvc/logicvc_crtc.c b/drivers/gpu/drm/logicvc/logicvc_crtc.c index af92a573c3f269..ded957744ef1e2 100644 --- a/drivers/gpu/drm/logicvc/logicvc_crtc.c +++ b/drivers/gpu/drm/logicvc/logicvc_crtc.c @@ -252,7 +252,7 @@ int logicvc_crtc_init(struct logicvc_drm *logicvc) struct logicvc_layer *layer_primary; int ret; - crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL); + crtc = devm_kzalloc_obj(dev, *crtc); if (!crtc) return -ENOMEM; diff --git a/drivers/gpu/drm/logicvc/logicvc_interface.c b/drivers/gpu/drm/logicvc/logicvc_interface.c index 81f760dc07f8de..67972bc70682cc 100644 --- a/drivers/gpu/drm/logicvc/logicvc_interface.c +++ b/drivers/gpu/drm/logicvc/logicvc_interface.c @@ -154,7 +154,7 @@ int logicvc_interface_init(struct logicvc_drm *logicvc) bool native_connector = logicvc_interface_native_connector(logicvc); int ret; - interface = devm_kzalloc(dev, sizeof(*interface), GFP_KERNEL); + interface = devm_kzalloc_obj(dev, *interface); if (!interface) { ret = -ENOMEM; goto error_early; diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.c b/drivers/gpu/drm/logicvc/logicvc_layer.c index 94741685638113..86976a78d18ee8 100644 --- a/drivers/gpu/drm/logicvc/logicvc_layer.c +++ b/drivers/gpu/drm/logicvc/logicvc_layer.c @@ -470,7 +470,7 @@ static int logicvc_layer_init(struct logicvc_drm *logicvc, unsigned int zpos; int ret; - layer = devm_kzalloc(dev, sizeof(*layer), GFP_KERNEL); + layer = devm_kzalloc_obj(dev, *layer); if (!layer) { ret = -ENOMEM; goto error; diff --git a/drivers/gpu/drm/loongson/lsdc_gem.c b/drivers/gpu/drm/loongson/lsdc_gem.c index 2fb03487c983e7..9eba4e1a5ba6a0 100644 --- a/drivers/gpu/drm/loongson/lsdc_gem.c +++ b/drivers/gpu/drm/loongson/lsdc_gem.c @@ -157,14 +157,18 @@ struct drm_gem_object *lsdc_gem_object_create(struct drm_device *ddev, return ERR_PTR(ret); } + gobj = &lbo->tbo.base; + gobj->funcs = &lsdc_gem_object_funcs; + if (!sg) { /* VRAM is filled with random data */ - lsdc_bo_clear(lbo); + ret = lsdc_bo_clear(lbo); + if (ret) { + drm_gem_object_put(gobj); + return ERR_PTR(ret); + } } - gobj = &lbo->tbo.base; - gobj->funcs = &lsdc_gem_object_funcs; - /* tracking the BOs we created */ mutex_lock(&ldev->gem.mutex); list_add_tail(&lbo->list, &ldev->gem.objects); diff --git a/drivers/gpu/drm/loongson/lsdc_plane.c b/drivers/gpu/drm/loongson/lsdc_plane.c index 35d45e893f2d55..c425288ba4909f 100644 --- a/drivers/gpu/drm/loongson/lsdc_plane.c +++ b/drivers/gpu/drm/loongson/lsdc_plane.c @@ -230,7 +230,7 @@ static void lsdc_cursor_plane_atomic_async_update(struct drm_plane *plane, new_state = drm_atomic_get_new_plane_state(state, plane); - new_fb = plane->state->fb; + new_fb = new_state->fb; plane->state->crtc_x = new_state->crtc_x; plane->state->crtc_y = new_state->crtc_y; diff --git a/drivers/gpu/drm/loongson/lsdc_ttm.c b/drivers/gpu/drm/loongson/lsdc_ttm.c index d7441d96a0dcae..7b30dea039ee2d 100644 --- a/drivers/gpu/drm/loongson/lsdc_ttm.c +++ b/drivers/gpu/drm/loongson/lsdc_ttm.c @@ -388,9 +388,13 @@ void lsdc_bo_kunmap(struct lsdc_bo *lbo) ttm_bo_kunmap(&lbo->kmap); } -void lsdc_bo_clear(struct lsdc_bo *lbo) +int lsdc_bo_clear(struct lsdc_bo *lbo) { - lsdc_bo_kmap(lbo); + int ret; + + ret = lsdc_bo_kmap(lbo); + if (ret) + return ret; if (lbo->is_iomem) memset_io((void __iomem *)lbo->kptr, 0, lbo->size); @@ -398,6 +402,8 @@ void lsdc_bo_clear(struct lsdc_bo *lbo) memset(lbo->kptr, 0, lbo->size); lsdc_bo_kunmap(lbo); + + return 0; } int lsdc_bo_evict_vram(struct drm_device *ddev) @@ -475,10 +481,8 @@ struct lsdc_bo *lsdc_bo_create(struct drm_device *ddev, ret = ttm_bo_init_validate(bdev, tbo, bo_type, &lbo->placement, 0, false, sg, resv, lsdc_bo_destroy); - if (ret) { - kfree(lbo); + if (ret) return ERR_PTR(ret); - } return lbo; } diff --git a/drivers/gpu/drm/loongson/lsdc_ttm.h b/drivers/gpu/drm/loongson/lsdc_ttm.h index 843e1475064e28..df47d9bb0d0358 100644 --- a/drivers/gpu/drm/loongson/lsdc_ttm.h +++ b/drivers/gpu/drm/loongson/lsdc_ttm.h @@ -89,7 +89,7 @@ size_t lsdc_bo_size(struct lsdc_bo *lbo); int lsdc_bo_kmap(struct lsdc_bo *lbo); void lsdc_bo_kunmap(struct lsdc_bo *lbo); -void lsdc_bo_clear(struct lsdc_bo *lbo); +int lsdc_bo_clear(struct lsdc_bo *lbo); int lsdc_bo_evict_vram(struct drm_device *ddev); diff --git a/drivers/gpu/drm/mcde/mcde_clk_div.c b/drivers/gpu/drm/mcde/mcde_clk_div.c index 8c5af2677357fc..e3402e180ec6b8 100644 --- a/drivers/gpu/drm/mcde/mcde_clk_div.c +++ b/drivers/gpu/drm/mcde/mcde_clk_div.c @@ -165,10 +165,10 @@ int mcde_init_clock_divider(struct mcde *mcde) parent_name = __clk_get_name(mcde->lcd_clk); /* Allocate 2 clocks */ - fifoa = devm_kzalloc(dev, sizeof(*fifoa), GFP_KERNEL); + fifoa = devm_kzalloc_obj(dev, *fifoa); if (!fifoa) return -ENOMEM; - fifob = devm_kzalloc(dev, sizeof(*fifob), GFP_KERNEL); + fifob = devm_kzalloc_obj(dev, *fifob); if (!fifob) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_cec.c b/drivers/gpu/drm/mediatek/mtk_cec.c index 4a40e510e7db29..0a5856d80f6d77 100644 --- a/drivers/gpu/drm/mediatek/mtk_cec.c +++ b/drivers/gpu/drm/mediatek/mtk_cec.c @@ -187,7 +187,7 @@ static int mtk_cec_probe(struct platform_device *pdev) struct mtk_cec *cec; int ret; - cec = devm_kzalloc(dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c index 2920f3198ef6ab..1941222a97ab4d 100644 --- a/drivers/gpu/drm/mediatek/mtk_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c @@ -1047,9 +1047,8 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path, } } - mtk_crtc = devm_kzalloc(dev, - struct_size(mtk_crtc, ddp_comp, path_len + (conn_routes ? 1 : 0)), - GFP_KERNEL); + mtk_crtc = devm_kzalloc_flex(dev, *mtk_crtc, ddp_comp, + path_len + (conn_routes ? 1 : 0)); if (!mtk_crtc) return -ENOMEM; @@ -1089,8 +1088,8 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path, for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) num_comp_planes += mtk_crtc_num_comp_planes(mtk_crtc, i); - mtk_crtc->planes = devm_kcalloc(dev, num_comp_planes, - sizeof(struct drm_plane), GFP_KERNEL); + mtk_crtc->planes = devm_kzalloc_objs(dev, struct drm_plane, + num_comp_planes); if (!mtk_crtc->planes) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c index 9672ea1f91a2b5..282614507f62f1 100644 --- a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c @@ -682,7 +682,7 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node, struct mtk_d type == MTK_DSI) return 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_aal.c b/drivers/gpu/drm/mediatek/mtk_disp_aal.c index abc9e5525d039d..192c1a7d58df9b 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_aal.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_aal.c @@ -170,7 +170,7 @@ static int mtk_disp_aal_probe(struct platform_device *pdev) struct mtk_disp_aal *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c index 6d7bf4afa78d3a..5f64a0a6e1b2ac 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c @@ -134,7 +134,7 @@ static int mtk_disp_ccorr_probe(struct platform_device *pdev) struct mtk_disp_ccorr *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_color.c b/drivers/gpu/drm/mediatek/mtk_disp_color.c index 39c7de4cdcc16b..7af9966c036d7c 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_color.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_color.c @@ -98,7 +98,7 @@ static int mtk_disp_color_probe(struct platform_device *pdev) struct mtk_disp_color *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 8afd15006df2a2..787f68e7d1890a 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -258,7 +258,7 @@ static int mtk_disp_gamma_probe(struct platform_device *pdev) struct mtk_disp_gamma *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_merge.c b/drivers/gpu/drm/mediatek/mtk_disp_merge.c index b174dda091d3fb..6f00e8cd1b5c5e 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_merge.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_merge.c @@ -309,7 +309,7 @@ static int mtk_disp_merge_probe(struct platform_device *pdev) struct mtk_disp_merge *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c index 97a899e4bd99ca..5445870716f945 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c @@ -614,7 +614,7 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev) int irq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c index 6a259872b0a916..16fb340e5bd257 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c @@ -640,7 +640,7 @@ static int mtk_disp_ovl_adaptor_probe(struct platform_device *pdev) struct component_match *match = NULL; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c index c9d41d75e7f2a3..67bd9e1cad597c 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c @@ -316,7 +316,7 @@ static int mtk_disp_rdma_probe(struct platform_device *pdev) int irq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index f656b85b842128..974c4fff6fd3b9 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -2522,15 +2522,14 @@ static u32 *mtk_dp_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, if (((rate * 97 / 100) < (mode->clock * 24 / 8)) && ((rate * 97 / 100) > (mode->clock * 16 / 8)) && (display_info->color_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422))) { - input_fmts = kcalloc(1, sizeof(*input_fmts), GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, 1); if (!input_fmts) return NULL; *num_input_fmts = 1; input_fmts[0] = MEDIA_BUS_FMT_YUYV8_1X16; } else { - input_fmts = kcalloc(ARRAY_SIZE(mt8195_input_fmts), - sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, + ARRAY_SIZE(mt8195_input_fmts)); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c b/drivers/gpu/drm/mediatek/mtk_dpi.c index 0e4f430de9832c..1bc569dc01a3a6 100644 --- a/drivers/gpu/drm/mediatek/mtk_dpi.c +++ b/drivers/gpu/drm/mediatek/mtk_dpi.c @@ -710,8 +710,7 @@ static u32 *mtk_dpi_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, return NULL; } - output_fmts = kcalloc(dpi->conf->num_output_fmts, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, dpi->conf->num_output_fmts); if (!output_fmts) return NULL; @@ -734,8 +733,7 @@ static u32 *mtk_dpi_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, *num_input_fmts = 0; - input_fmts = kcalloc(1, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, 1); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index dc8e3e917dd771..a8bf0690756a96 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -1066,7 +1066,7 @@ static int mtk_drm_probe(struct platform_device *pdev) int ret; int i; - private = devm_kzalloc(dev, sizeof(*private), GFP_KERNEL); + private = devm_kzalloc_obj(dev, *private); if (!private) return -ENOMEM; @@ -1102,9 +1102,9 @@ static int mtk_drm_probe(struct platform_device *pdev) private->data = mtk_drm_data; } - private->all_drm_private = devm_kmalloc_array(dev, private->data->mmsys_dev_num, - sizeof(*private->all_drm_private), - GFP_KERNEL); + private->all_drm_private = devm_kmalloc_objs(dev, + *private->all_drm_private, + private->data->mmsys_dev_num); if (!private->all_drm_private) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_ethdr.c b/drivers/gpu/drm/mediatek/mtk_ethdr.c index 96832d0cca37c1..4ba3b7b4b110b8 100644 --- a/drivers/gpu/drm/mediatek/mtk_ethdr.c +++ b/drivers/gpu/drm/mediatek/mtk_ethdr.c @@ -325,7 +325,7 @@ static int mtk_ethdr_probe(struct platform_device *pdev) int ret; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_common.c b/drivers/gpu/drm/mediatek/mtk_hdmi_common.c index 042b98e5a51991..a36d8dd6b7617c 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi_common.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi_common.c @@ -416,7 +416,7 @@ struct mtk_hdmi *mtk_hdmi_common_probe(struct platform_device *pdev) hdmi->dev = dev; hdmi->conf = hdmi_conf; - hdmi->clk = devm_kcalloc(dev, ver_conf->num_clocks, sizeof(*hdmi->clk), GFP_KERNEL); + hdmi->clk = devm_kzalloc_objs(dev, *hdmi->clk, ver_conf->num_clocks); if (!hdmi->clk) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_ddc.c b/drivers/gpu/drm/mediatek/mtk_hdmi_ddc.c index 2acbdb025d893e..c4fb4e20946151 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi_ddc.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi_ddc.c @@ -273,7 +273,7 @@ static int mtk_hdmi_ddc_probe(struct platform_device *pdev) struct resource *mem; int ret; - ddc = devm_kzalloc(dev, sizeof(struct mtk_hdmi_ddc), GFP_KERNEL); + ddc = devm_kzalloc_obj(dev, struct mtk_hdmi_ddc); if (!ddc) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c b/drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c index 1ec973d3f52c5e..31c93763e7cfb1 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c @@ -346,7 +346,7 @@ static int mtk_hdmi_ddc_v2_probe(struct platform_device *pdev) struct mtk_hdmi_ddc *ddc; int ret; - ddc = devm_kzalloc(dev, sizeof(*ddc), GFP_KERNEL); + ddc = devm_kzalloc_obj(dev, *ddc); if (!ddc) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c b/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c index f903656ea0efc8..fa53511f461d46 100644 --- a/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c +++ b/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c @@ -293,7 +293,7 @@ static int mtk_mdp_rdma_probe(struct platform_device *pdev) struct mtk_mdp_rdma *priv; int ret = 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/mediatek/mtk_padding.c b/drivers/gpu/drm/mediatek/mtk_padding.c index b4e3e5a3428b6f..97bcc11566c62f 100644 --- a/drivers/gpu/drm/mediatek/mtk_padding.c +++ b/drivers/gpu/drm/mediatek/mtk_padding.c @@ -98,7 +98,7 @@ static int mtk_padding_probe(struct platform_device *pdev) struct resource *res; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c index 056dbea8deecb7..d1317ddcdfab33 100644 --- a/drivers/gpu/drm/meson/meson_crtc.c +++ b/drivers/gpu/drm/meson/meson_crtc.c @@ -677,8 +677,7 @@ int meson_crtc_create(struct meson_drm *priv) struct drm_crtc *crtc; int ret; - meson_crtc = devm_kzalloc(priv->drm->dev, sizeof(*meson_crtc), - GFP_KERNEL); + meson_crtc = devm_kzalloc_obj(priv->drm->dev, *meson_crtc); if (!meson_crtc) return -ENOMEM; diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c index 49ff9f1f16d32a..38bf2811d068d6 100644 --- a/drivers/gpu/drm/meson/meson_drv.c +++ b/drivers/gpu/drm/meson/meson_drv.c @@ -202,7 +202,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components) if (IS_ERR(drm)) return PTR_ERR(drm); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) { ret = -ENOMEM; goto free_drm; diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c index fef1702acb1453..eb33c70f29c31c 100644 --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c @@ -686,8 +686,7 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, return -ENODEV; } - meson_dw_hdmi = devm_kzalloc(dev, sizeof(*meson_dw_hdmi), - GFP_KERNEL); + meson_dw_hdmi = devm_kzalloc_obj(dev, *meson_dw_hdmi); if (!meson_dw_hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/meson/meson_dw_mipi_dsi.c b/drivers/gpu/drm/meson/meson_dw_mipi_dsi.c index 867918e9f498a3..c27a64bd152909 100644 --- a/drivers/gpu/drm/meson/meson_dw_mipi_dsi.c +++ b/drivers/gpu/drm/meson/meson_dw_mipi_dsi.c @@ -267,7 +267,7 @@ static int meson_dw_mipi_dsi_probe(struct platform_device *pdev) struct meson_dw_mipi_dsi *mipi_dsi; struct device *dev = &pdev->dev; - mipi_dsi = devm_kzalloc(dev, sizeof(*mipi_dsi), GFP_KERNEL); + mipi_dsi = devm_kzalloc_obj(dev, *mipi_dsi); if (!mipi_dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/meson/meson_encoder_dsi.c b/drivers/gpu/drm/meson/meson_encoder_dsi.c index faa309cb97a68c..912cd676bbe259 100644 --- a/drivers/gpu/drm/meson/meson_encoder_dsi.c +++ b/drivers/gpu/drm/meson/meson_encoder_dsi.c @@ -65,9 +65,9 @@ static void meson_encoder_dsi_atomic_enable(struct drm_bridge *bridge, /* ENCL clock setup is handled by CCF */ meson_venc_mipi_dsi_mode_set(priv, &crtc_state->adjusted_mode); - meson_encl_load_gamma(priv); writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN)); + meson_encl_load_gamma(priv); writel_bits_relaxed(ENCL_VIDEO_MODE_ADV_VFIFO_EN, ENCL_VIDEO_MODE_ADV_VFIFO_EN, priv->io_base + _REG(ENCL_VIDEO_MODE_ADV)); diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c index c4355c5cc340db..0f9cfc7235dbf1 100644 --- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c +++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c @@ -286,9 +286,7 @@ meson_encoder_hdmi_get_inp_bus_fmts(struct drm_bridge *bridge, for (i = 0 ; i < ARRAY_SIZE(meson_encoder_hdmi_out_bus_fmts) ; ++i) { if (output_fmt == meson_encoder_hdmi_out_bus_fmts[i]) { *num_input_fmts = 1; - input_fmts = kcalloc(*num_input_fmts, - sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, *num_input_fmts); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/meson/meson_overlay.c b/drivers/gpu/drm/meson/meson_overlay.c index 930119e18a4f5f..bb48cdf846bcea 100644 --- a/drivers/gpu/drm/meson/meson_overlay.c +++ b/drivers/gpu/drm/meson/meson_overlay.c @@ -839,8 +839,7 @@ int meson_overlay_create(struct meson_drm *priv) DRM_DEBUG_DRIVER("\n"); - meson_overlay = devm_kzalloc(priv->drm->dev, sizeof(*meson_overlay), - GFP_KERNEL); + meson_overlay = devm_kzalloc_obj(priv->drm->dev, *meson_overlay); if (!meson_overlay) return -ENOMEM; diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c index cf8c90158fcf85..76eb8b80ad8a55 100644 --- a/drivers/gpu/drm/meson/meson_plane.c +++ b/drivers/gpu/drm/meson/meson_plane.c @@ -537,8 +537,7 @@ int meson_plane_create(struct meson_drm *priv) const uint64_t *format_modifiers = format_modifiers_default; int ret; - meson_plane = devm_kzalloc(priv->drm->dev, sizeof(*meson_plane), - GFP_KERNEL); + meson_plane = devm_kzalloc_obj(priv->drm->dev, *meson_plane); if (!meson_plane) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c index 16c7335c4b1f85..4af6501ef46370 100644 --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c @@ -1536,7 +1536,7 @@ static void a5xx_gpu_state_get_hlsq_regs(struct msm_gpu *gpu, for (i = 0; i < ARRAY_SIZE(a5xx_hlsq_aperture_regs); i++) count += a5xx_hlsq_aperture_regs[i].count; - a5xx_state->hlsqregs = kcalloc(count, sizeof(u32), GFP_KERNEL); + a5xx_state->hlsqregs = kzalloc_objs(u32, count); if (!a5xx_state->hlsqregs) return; @@ -1583,7 +1583,7 @@ static void a5xx_gpu_state_get_gpmu_regs(struct msm_gpu *gpu, for (i = 0; a5xx_gpmu_registers[i] != ~0; i += 2) count += a5xx_gpmu_registers[i + 1] - a5xx_gpmu_registers[i] + 1; - a5xx_state->gpmuregs = kcalloc(count, sizeof(u32), GFP_KERNEL); + a5xx_state->gpmuregs = kzalloc_objs(u32, count); if (!a5xx_state->gpmuregs) return; diff --git a/drivers/gpu/drm/msm/adreno/a6xx_hfi.c b/drivers/gpu/drm/msm/adreno/a6xx_hfi.c index 6b34e704a70d0e..a9f9fa2adadf51 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_hfi.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_hfi.c @@ -806,7 +806,7 @@ static int a6xx_hfi_send_bw_table(struct a6xx_gmu *gmu) if (gmu->bw_table) goto send; - msg = devm_kzalloc(gmu->dev, sizeof(*msg), GFP_KERNEL); + msg = devm_kzalloc_obj(gmu->dev, *msg); if (!msg) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c index da3556eb6ecc25..1b6286dccfc000 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c @@ -258,7 +258,7 @@ void dpu_debugfs_create_regset32(const char *name, umode_t mode, if (WARN_ON(!name || !dpu_kms || !length)) return; - regset = devm_kzalloc(&dpu_kms->pdev->dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(&dpu_kms->pdev->dev, *regset); if (!regset) return; @@ -1386,7 +1386,7 @@ static int dpu_dev_probe(struct platform_device *pdev) if (!msm_disp_drv_should_bind(&pdev->dev, true)) return -ENODEV; - dpu_kms = devm_kzalloc(dev, sizeof(*dpu_kms), GFP_KERNEL); + dpu_kms = devm_kzalloc_obj(dev, *dpu_kms); if (!dpu_kms) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c index c299fef1a400bc..ab7b62381685fe 100644 --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c @@ -511,7 +511,7 @@ static int mdp4_probe(struct platform_device *pdev) struct mdp4_kms *mdp4_kms; int irq; - mdp4_kms = devm_kzalloc(dev, sizeof(*mdp4_kms), GFP_KERNEL); + mdp4_kms = devm_kzalloc_obj(dev, *mdp4_kms); if (!mdp4_kms) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_lvds_pll.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_lvds_pll.c index 04c49bf3d85469..b873a6854a0540 100644 --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_lvds_pll.c +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_lvds_pll.c @@ -141,7 +141,7 @@ static struct clk_hw *mdp4_lvds_pll_init(struct drm_device *dev) struct mdp4_lvds_pll *lvds_pll; int ret; - lvds_pll = devm_kzalloc(dev->dev, sizeof(*lvds_pll), GFP_KERNEL); + lvds_pll = devm_kzalloc_obj(dev->dev, *lvds_pll); if (!lvds_pll) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c index c54aaab2f5bdf5..f5b90368f43558 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c @@ -1108,7 +1108,7 @@ struct mdp5_cfg_handler *mdp5_cfg_init(struct mdp5_kms *mdp5_kms, const struct mdp5_cfg_handler *cfg_handlers; int i, num_handlers; - cfg_handler = devm_kzalloc(dev->dev, sizeof(*cfg_handler), GFP_KERNEL); + cfg_handler = devm_kzalloc_obj(dev->dev, *cfg_handler); if (unlikely(!cfg_handler)) { return ERR_PTR(-ENOMEM); } diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c index 1eca140616c6a9..5cc648ddfb2b1c 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c @@ -618,7 +618,7 @@ struct mdp5_ctl_manager *mdp5_ctlm_init(struct drm_device *dev, unsigned long flags; int c, ret; - ctl_mgr = devm_kzalloc(dev->dev, sizeof(*ctl_mgr), GFP_KERNEL); + ctl_mgr = devm_kzalloc_obj(dev->dev, *ctl_mgr); if (!ctl_mgr) { DRM_DEV_ERROR(dev->dev, "failed to allocate CTL manager\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c index 3934cd060b2766..ff6751b2ae626e 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c @@ -685,7 +685,7 @@ static int interface_init(struct mdp5_kms *mdp5_kms) if (intf_types[i] == INTF_DISABLED) continue; - intf = devm_kzalloc(dev->dev, sizeof(*intf), GFP_KERNEL); + intf = devm_kzalloc_obj(dev->dev, *intf); if (!intf) { DRM_DEV_ERROR(dev->dev, "failed to construct INTF%d\n", i); return -ENOMEM; @@ -817,7 +817,7 @@ static int mdp5_dev_probe(struct platform_device *pdev) if (!msm_disp_drv_should_bind(&pdev->dev, false)) return -ENODEV; - mdp5_kms = devm_kzalloc(&pdev->dev, sizeof(*mdp5_kms), GFP_KERNEL); + mdp5_kms = devm_kzalloc_obj(&pdev->dev, *mdp5_kms); if (!mdp5_kms) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_mixer.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_mixer.c index 253b29629ed709..c920d4fea0fee6 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_mixer.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_mixer.c @@ -149,7 +149,7 @@ struct mdp5_hw_mixer *mdp5_mixer_init(struct drm_device *dev, { struct mdp5_hw_mixer *mixer; - mixer = devm_kzalloc(dev->dev, sizeof(*mixer), GFP_KERNEL); + mixer = devm_kzalloc_obj(dev->dev, *mixer); if (!mixer) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_pipe.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_pipe.c index 606e18973ea4ba..b830910a161977 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_pipe.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_pipe.c @@ -157,7 +157,7 @@ struct mdp5_hw_pipe *mdp5_pipe_init(struct drm_device *dev, { struct mdp5_hw_pipe *hwpipe; - hwpipe = devm_kzalloc(dev->dev, sizeof(*hwpipe), GFP_KERNEL); + hwpipe = devm_kzalloc_obj(dev->dev, *hwpipe); if (!hwpipe) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c index 890d2f31510e47..40dcc6dd157518 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -364,7 +364,7 @@ struct mdp5_smp *mdp5_smp_init(struct mdp5_kms *mdp5_kms, const struct mdp5_smp_ struct mdp5_global_state *global_state; struct mdp5_smp *smp; - smp = devm_kzalloc(dev->dev, sizeof(*smp), GFP_KERNEL); + smp = devm_kzalloc_obj(dev->dev, *smp); if (unlikely(!smp)) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/dp/dp_audio.c b/drivers/gpu/drm/msm/dp/dp_audio.c index df222943ae57f9..8960f015612d9e 100644 --- a/drivers/gpu/drm/msm/dp/dp_audio.c +++ b/drivers/gpu/drm/msm/dp/dp_audio.c @@ -348,7 +348,7 @@ struct msm_dp_audio *msm_dp_audio_get(struct platform_device *pdev, goto error; } - audio = devm_kzalloc(&pdev->dev, sizeof(*audio), GFP_KERNEL); + audio = devm_kzalloc_obj(&pdev->dev, *audio); if (!audio) { rc = -ENOMEM; goto error; diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c index 3825a2fb48e213..b52393dcc06704 100644 --- a/drivers/gpu/drm/msm/dp/dp_aux.c +++ b/drivers/gpu/drm/msm/dp/dp_aux.c @@ -686,7 +686,7 @@ struct drm_dp_aux *msm_dp_aux_get(struct device *dev, { struct msm_dp_aux_private *aux; - aux = devm_kzalloc(dev, sizeof(*aux), GFP_KERNEL); + aux = devm_kzalloc_obj(dev, *aux); if (!aux) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c index abd3dcdad03c26..47647fdec9de57 100644 --- a/drivers/gpu/drm/msm/dp/dp_ctrl.c +++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c @@ -2779,7 +2779,8 @@ static int msm_dp_ctrl_clk_init(struct msm_dp_ctrl *msm_dp_ctrl) dev = ctrl->dev; ctrl->num_core_clks = ARRAY_SIZE(core_clks); - ctrl->core_clks = devm_kcalloc(dev, ctrl->num_core_clks, sizeof(*ctrl->core_clks), GFP_KERNEL); + ctrl->core_clks = devm_kzalloc_objs(dev, *ctrl->core_clks, + ctrl->num_core_clks); if (!ctrl->core_clks) return -ENOMEM; @@ -2791,7 +2792,8 @@ static int msm_dp_ctrl_clk_init(struct msm_dp_ctrl *msm_dp_ctrl) return rc; ctrl->num_link_clks = ARRAY_SIZE(ctrl_clks); - ctrl->link_clks = devm_kcalloc(dev, ctrl->num_link_clks, sizeof(*ctrl->link_clks), GFP_KERNEL); + ctrl->link_clks = devm_kzalloc_objs(dev, *ctrl->link_clks, + ctrl->num_link_clks); if (!ctrl->link_clks) return -ENOMEM; @@ -2845,7 +2847,7 @@ struct msm_dp_ctrl *msm_dp_ctrl_get(struct device *dev, struct msm_dp_link *link return ERR_PTR(-EINVAL); } - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) { DRM_ERROR("Mem allocation failure\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/dp/dp_debug.c b/drivers/gpu/drm/msm/dp/dp_debug.c index 00fb1a7ba40ed6..fe164270e7892d 100644 --- a/drivers/gpu/drm/msm/dp/dp_debug.c +++ b/drivers/gpu/drm/msm/dp/dp_debug.c @@ -210,7 +210,7 @@ int msm_dp_debug_init(struct device *dev, struct msm_dp_panel *panel, return -EINVAL; } - debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL); + debug = devm_kzalloc_obj(dev, *debug); if (!debug) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index 9299ce616fdbc0..c0c150e2c5758a 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -1248,7 +1248,7 @@ static int msm_dp_display_probe(struct platform_device *pdev) return -ENODEV; } - dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(&pdev->dev, *dp); if (!dp) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dp/dp_link.c b/drivers/gpu/drm/msm/dp/dp_link.c index 34a91e194a124e..15cf692c23dafc 100644 --- a/drivers/gpu/drm/msm/dp/dp_link.c +++ b/drivers/gpu/drm/msm/dp/dp_link.c @@ -1333,7 +1333,7 @@ struct msm_dp_link *msm_dp_link_get(struct device *dev, struct drm_dp_aux *aux) return ERR_PTR(-EINVAL); } - link = devm_kzalloc(dev, sizeof(*link), GFP_KERNEL); + link = devm_kzalloc_obj(dev, *link); if (!link) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/dp/dp_panel.c b/drivers/gpu/drm/msm/dp/dp_panel.c index d3468b73fdc320..7f89532a331a66 100644 --- a/drivers/gpu/drm/msm/dp/dp_panel.c +++ b/drivers/gpu/drm/msm/dp/dp_panel.c @@ -807,7 +807,7 @@ struct msm_dp_panel *msm_dp_panel_get(struct device *dev, struct drm_dp_aux *aux return ERR_PTR(-EINVAL); } - panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL); + panel = devm_kzalloc_obj(dev, *panel); if (!panel) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c index c726fc628a087f..090726be5061f3 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -86,7 +86,7 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev) if (!pdev) return ERR_PTR(-ENXIO); - msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL); + msm_dsi = devm_kzalloc_obj(&pdev->dev, *msm_dsi); if (!msm_dsi) return ERR_PTR(-ENOMEM); DBG("dsi probed=%p", msm_dsi); diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c index d92659d80f172d..78f0fd25942166 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_host.c +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c @@ -2011,7 +2011,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi) const struct msm_dsi_config *cfg; int ret; - msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL); + msm_host = devm_kzalloc_obj(&pdev->dev, *msm_host); if (!msm_host) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c index 1fb3899b88bf26..a14e71d8c8a4a6 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c @@ -617,13 +617,12 @@ static int dsi_phy_driver_probe(struct platform_device *pdev) u32 phy_type; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; - phy->provided_clocks = devm_kzalloc(dev, - struct_size(phy->provided_clocks, hws, NUM_PROVIDED_CLKS), - GFP_KERNEL); + phy->provided_clocks = devm_kzalloc_flex(dev, *phy->provided_clocks, + hws, NUM_PROVIDED_CLKS); if (!phy->provided_clocks) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c index ec486ff02c9b51..12dac309f3af36 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c @@ -679,7 +679,7 @@ static int dsi_pll_10nm_init(struct msm_dsi_phy *phy) struct dsi_pll_10nm *pll_10nm; int ret; - pll_10nm = devm_kzalloc(&pdev->dev, sizeof(*pll_10nm), GFP_KERNEL); + pll_10nm = devm_kzalloc_obj(&pdev->dev, *pll_10nm); if (!pll_10nm) return -ENOMEM; @@ -918,7 +918,7 @@ static int dsi_10nm_phy_parse_dt(struct msm_dsi_phy *phy) u8 level; int ret, i; - tuning_cfg = devm_kzalloc(dev, sizeof(*tuning_cfg), GFP_KERNEL); + tuning_cfg = devm_kzalloc_obj(dev, *tuning_cfg); if (!tuning_cfg) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c index a156c7e7cea832..bc0f11bb7e4c98 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c @@ -781,7 +781,7 @@ static struct clk_hw *pll_14nm_postdiv_register(struct dsi_pll_14nm *pll_14nm, }; int ret; - pll_postdiv = devm_kzalloc(dev, sizeof(*pll_postdiv), GFP_KERNEL); + pll_postdiv = devm_kzalloc_obj(dev, *pll_postdiv); if (!pll_postdiv) return ERR_PTR(-ENOMEM); @@ -879,7 +879,7 @@ static int dsi_pll_14nm_init(struct msm_dsi_phy *phy) if (!pdev) return -ENODEV; - pll_14nm = devm_kzalloc(&pdev->dev, sizeof(*pll_14nm), GFP_KERNEL); + pll_14nm = devm_kzalloc_obj(&pdev->dev, *pll_14nm); if (!pll_14nm) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c index d00e415b9a991c..d0620809980412 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c @@ -698,7 +698,7 @@ static int dsi_pll_28nm_init(struct msm_dsi_phy *phy) if (!pdev) return -ENODEV; - pll_28nm = devm_kzalloc(&pdev->dev, sizeof(*pll_28nm), GFP_KERNEL); + pll_28nm = devm_kzalloc_obj(&pdev->dev, *pll_28nm); if (!pll_28nm) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c index 8dcce9581dc387..8b0fee435a5cc8 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c @@ -393,7 +393,7 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov DBG("%d", pll_28nm->phy->id); - bytediv = devm_kzalloc(dev, sizeof(*bytediv), GFP_KERNEL); + bytediv = devm_kzalloc_obj(dev, *bytediv); if (!bytediv) return -ENOMEM; @@ -448,7 +448,7 @@ static int dsi_pll_28nm_8960_init(struct msm_dsi_phy *phy) if (!pdev) return -ENODEV; - pll_28nm = devm_kzalloc(&pdev->dev, sizeof(*pll_28nm), GFP_KERNEL); + pll_28nm = devm_kzalloc_obj(&pdev->dev, *pll_28nm); if (!pll_28nm) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c index 5d805a797abdb1..ce86dbf6188930 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c @@ -863,7 +863,7 @@ static int dsi_pll_7nm_init(struct msm_dsi_phy *phy) struct dsi_pll_7nm *pll_7nm; int ret; - pll_7nm = devm_kzalloc(&pdev->dev, sizeof(*pll_7nm), GFP_KERNEL); + pll_7nm = devm_kzalloc_obj(&pdev->dev, *pll_7nm); if (!pll_7nm) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c index 4740060846335b..133b4b1f17ab42 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi.c @@ -276,7 +276,7 @@ static int msm_hdmi_dev_probe(struct platform_device *pdev) if (!config) return -EINVAL; - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(dev, *hdmi); if (!hdmi) return -ENOMEM; @@ -320,9 +320,8 @@ static int msm_hdmi_dev_probe(struct platform_device *pdev) goto err_put_bridge; } - hdmi->pwr_regs = devm_kcalloc(dev, config->pwr_reg_cnt, - sizeof(hdmi->pwr_regs[0]), - GFP_KERNEL); + hdmi->pwr_regs = devm_kzalloc_objs(dev, hdmi->pwr_regs[0], + config->pwr_reg_cnt); if (!hdmi->pwr_regs) { ret = -ENOMEM; goto err_put_bridge; @@ -337,9 +336,8 @@ static int msm_hdmi_dev_probe(struct platform_device *pdev) goto err_put_bridge; } - hdmi->pwr_clks = devm_kcalloc(dev, config->pwr_clk_cnt, - sizeof(hdmi->pwr_clks[0]), - GFP_KERNEL); + hdmi->pwr_clks = devm_kzalloc_objs(dev, hdmi->pwr_clks[0], + config->pwr_clk_cnt); if (!hdmi->pwr_clks) { ret = -ENOMEM; goto err_put_bridge; diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_phy.c b/drivers/gpu/drm/msm/hdmi/hdmi_phy.c index ebb600d77cd82d..c805724dfda72f 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_phy.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_phy.c @@ -14,13 +14,11 @@ static int msm_hdmi_phy_resource_init(struct hdmi_phy *phy) struct device *dev = &phy->pdev->dev; int i, ret; - phy->regs = devm_kcalloc(dev, cfg->num_regs, sizeof(phy->regs[0]), - GFP_KERNEL); + phy->regs = devm_kzalloc_objs(dev, phy->regs[0], cfg->num_regs); if (!phy->regs) return -ENOMEM; - phy->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(phy->clks[0]), - GFP_KERNEL); + phy->clks = devm_kzalloc_objs(dev, phy->clks[0], cfg->num_clks); if (!phy->clks) return -ENOMEM; @@ -156,7 +154,7 @@ static int msm_hdmi_phy_probe(struct platform_device *pdev) struct hdmi_phy *phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENODEV; diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c index 71da20322b3d46..44d509bf5db359 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c @@ -701,7 +701,7 @@ int msm_hdmi_pll_8996_init(struct platform_device *pdev) struct hdmi_pll_8996 *pll; int i, ret; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8998.c b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8998.c index 05c3ffad858dd4..19642e0dfc939c 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8998.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8998.c @@ -705,7 +705,7 @@ int msm_hdmi_pll_8998_init(struct platform_device *pdev) struct hdmi_pll_8998 *pll; int ret, i; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c b/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c index 6ba6bbdb7e0530..14e58075ebf3d6 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c @@ -431,7 +431,7 @@ int msm_hdmi_pll_8960_init(struct platform_device *pdev) if (WARN_ON(freqtbl[i].rate < freqtbl[i + 1].rate)) return -EINVAL; - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 5e8f3ce26b32c9..c3111deaa64680 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1137,7 +1137,7 @@ int msm_drv_probe(struct device *master_dev, struct component_match *match = NULL; int ret; - priv = devm_kzalloc(master_dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(master_dev, *priv); if (!priv) return -ENOMEM; @@ -1178,7 +1178,7 @@ int msm_gpu_probe(struct platform_device *pdev, struct msm_drm_private *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index 0c2c3563625188..8319119041eb12 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -285,7 +285,7 @@ static void crashstate_get_bos(struct msm_gpu_state *state, struct msm_gem_submi drm_gpuvm_for_each_va (vma, submit->vm) cnt++; - state->bos = kcalloc(cnt, sizeof(struct msm_gpu_state_bo), GFP_KERNEL); + state->bos = kzalloc_objs(struct msm_gpu_state_bo, cnt); if (state->bos) drm_gpuvm_for_each_va(vma, submit->vm) { @@ -301,8 +301,8 @@ static void crashstate_get_bos(struct msm_gpu_state *state, struct msm_gem_submi drm_exec_fini(&exec); } else { - state->bos = kcalloc(submit->nr_bos, - sizeof(struct msm_gpu_state_bo), GFP_KERNEL); + state->bos = kzalloc_objs(struct msm_gpu_state_bo, + submit->nr_bos); for (int i = 0; state->bos && i < submit->nr_bos; i++) { struct drm_gem_object *obj = submit->bos[i].obj; diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c index e69b122f2687ab..259d362475c81f 100644 --- a/drivers/gpu/drm/msm/msm_mdss.c +++ b/drivers/gpu/drm/msm/msm_mdss.c @@ -360,7 +360,8 @@ static int mdp5_mdss_parse_clock(struct platform_device *pdev, struct clk_bulk_d if (!pdev) return -EINVAL; - bulk = devm_kcalloc(&pdev->dev, MDP5_MDSS_NUM_CLOCKS, sizeof(struct clk_bulk_data), GFP_KERNEL); + bulk = devm_kzalloc_objs(&pdev->dev, struct clk_bulk_data, + MDP5_MDSS_NUM_CLOCKS); if (!bulk) return -ENOMEM; @@ -388,7 +389,7 @@ static struct msm_mdss *msm_mdss_init(struct platform_device *pdev, bool is_mdp5 if (ret) return ERR_PTR(ret); - msm_mdss = devm_kzalloc(&pdev->dev, sizeof(*msm_mdss), GFP_KERNEL); + msm_mdss = devm_kzalloc_obj(&pdev->dev, *msm_mdss); if (!msm_mdss) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/msm/msm_perfcntr.c b/drivers/gpu/drm/msm/msm_perfcntr.c index 7fa2e858bd0823..d50a57063bc639 100644 --- a/drivers/gpu/drm/msm/msm_perfcntr.c +++ b/drivers/gpu/drm/msm/msm_perfcntr.c @@ -418,9 +418,9 @@ msm_ioctl_perfcntr_config(struct drm_device *dev, void *data, struct drm_file *f * kept in the end. */ - struct msm_perfcntr_context_state *perfctx __free(kfree) = kzalloc( - struct_size(perfctx, reserved_counters, gpu->num_perfcntr_groups), - GFP_KERNEL); + struct msm_perfcntr_context_state *perfctx __free(kfree) = kzalloc_flex(*perfctx, + reserved_counters, + gpu->num_perfcntr_groups); if (!perfctx) return -ENOMEM; diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c index e2173c4d6fc289..6e614480d1c836 100644 --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c @@ -74,7 +74,7 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) "Failed to get bridge for endpoint%u\n", of_ep.id); - encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(dev, *encoder); if (!encoder) return dev_err_probe(dev, -ENOMEM, "Failed to allocate encoder for endpoint%u\n", @@ -131,7 +131,7 @@ static int lcdif_load(struct drm_device *drm) struct lcdif_drm_private *lcdif; int ret; - lcdif = devm_kzalloc(&pdev->dev, sizeof(*lcdif), GFP_KERNEL); + lcdif = devm_kzalloc_obj(&pdev->dev, *lcdif); if (!lcdif) return -ENOMEM; diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c index 641691fc92c852..87e8293558932f 100644 --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c @@ -247,7 +247,7 @@ static int mxsfb_load(struct drm_device *drm, struct device_node *ep; int ret; - mxsfb = devm_kzalloc(&pdev->dev, sizeof(*mxsfb), GFP_KERNEL); + mxsfb = devm_kzalloc_obj(&pdev->dev, *mxsfb); if (!mxsfb) return -ENOMEM; diff --git a/drivers/gpu/drm/nouveau/include/nvkm/engine/falcon.h b/drivers/gpu/drm/nouveau/include/nvkm/engine/falcon.h index 341f133dc38c22..eb8adaf07fe5bf 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/engine/falcon.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/engine/falcon.h @@ -63,6 +63,7 @@ struct nvkm_falcon_func { int (*select)(struct nvkm_falcon *); u32 addr2; u32 riscv_irqmask; + u32 riscv_irqdest; bool reset_pmc; int (*reset_eng)(struct nvkm_falcon *); int (*reset_prep)(struct nvkm_falcon *); diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c index d71dcfc6ee66b3..07882624a7f6f8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_display.c +++ b/drivers/gpu/drm/nouveau/nouveau_display.c @@ -354,6 +354,11 @@ static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { .fb_create = nouveau_user_framebuffer_create, }; +static const struct drm_mode_config_funcs nouveau_mode_config_funcs_atomic = { + .fb_create = nouveau_user_framebuffer_create, + .atomic_commit = drm_atomic_helper_commit, + .atomic_check = drm_atomic_helper_check, +}; struct nouveau_drm_prop_enum_list { u8 gen_mask; @@ -654,7 +659,11 @@ nouveau_display_create(struct drm_device *dev) drm_mode_create_scaling_mode_property(dev); drm_mode_create_dvi_i_properties(dev); - dev->mode_config.funcs = &nouveau_mode_config_funcs; + /* this only gets set if the driver has the ATOMIC flag */ + if (drm_drv_uses_atomic_modeset(dev)) + dev->mode_config.funcs = &nouveau_mode_config_funcs_atomic; + else + dev->mode_config.funcs = &nouveau_mode_config_funcs; dev->mode_config.min_width = 0; dev->mode_config.min_height = 0; diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index e74d7bb975a863..eacac805583448 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -221,8 +221,8 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf) args.start = ALIGN_DOWN(vmf->address, (PAGE_SIZE << order)); args.vma = vmf->vma; args.end = args.start + (PAGE_SIZE << order); - args.src = kcalloc(nr, sizeof(*args.src), GFP_KERNEL); - args.dst = kcalloc(nr, sizeof(*args.dst), GFP_KERNEL); + args.src = kzalloc_objs(*args.src, nr); + args.dst = kzalloc_objs(*args.dst, nr); if (!args.src || !args.dst) { ret = VM_FAULT_OOM; @@ -493,8 +493,8 @@ nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chunk) struct nouveau_dmem_dma_info *dma_info; struct nouveau_fence *fence; - src_pfns = kvcalloc(npages, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL); - dst_pfns = kvcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL); + src_pfns = kvzalloc_objs(*src_pfns, npages, GFP_KERNEL | __GFP_NOFAIL); + dst_pfns = kvzalloc_objs(*dst_pfns, npages, GFP_KERNEL | __GFP_NOFAIL); dma_info = kvzalloc_objs(*dma_info, npages, GFP_KERNEL | __GFP_NOFAIL); migrate_device_range(src_pfns, chunk->pagemap.range.start >> PAGE_SHIFT, @@ -862,10 +862,10 @@ nouveau_dmem_migrate_vma(struct nouveau_drm *drm, if (max > (unsigned long)HPAGE_PMD_NR) max = (unsigned long)HPAGE_PMD_NR; - args.src = kcalloc(max, sizeof(*args.src), GFP_KERNEL); + args.src = kzalloc_objs(*args.src, max); if (!args.src) goto out; - args.dst = kcalloc(max, sizeof(*args.dst), GFP_KERNEL); + args.dst = kzalloc_objs(*args.dst, max); if (!args.dst) goto out_free_src; diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index 5e1336615cf6dc..30311688618cce 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -337,6 +337,7 @@ static void nouveau_accel_ce_init(struct nouveau_drm *drm) { struct nvif_device *device = &drm->client.device; + bool priv; u64 runm; int ret = 0; @@ -349,7 +350,11 @@ nouveau_accel_ce_init(struct nouveau_drm *drm) return; } - ret = nouveau_channel_new(&drm->client, true, runm, NvDmaFB, NvDmaTT, &drm->cechan); + /* priv copy engine only works on kepler and newer. */ + priv = device->info.family >= NV_DEVICE_INFO_V0_KEPLER; + + ret = nouveau_channel_new(&drm->client, priv, runm, NvDmaFB, NvDmaTT, + &drm->cechan); if (ret) NV_ERROR(drm, "failed to create ce channel, %d\n", ret); } diff --git a/drivers/gpu/drm/nouveau/nvkm/core/subdev.c b/drivers/gpu/drm/nouveau/nvkm/core/subdev.c index aab5a73f467a1c..ff6858f5e5d325 100644 --- a/drivers/gpu/drm/nouveau/nvkm/core/subdev.c +++ b/drivers/gpu/drm/nouveau/nvkm/core/subdev.c @@ -157,6 +157,7 @@ nvkm_subdev_init_(struct nvkm_subdev *subdev) ret = subdev->func->init(subdev); if (ret) { nvkm_error(subdev, "init failed, %d\n", ret); + subdev->use.enabled = false; return ret; } } diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c index 5655eda52a7b52..912eb6c3a13d4f 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c @@ -180,6 +180,19 @@ gk104_ectx_ctor(struct nvkm_engn *engn, struct nvkm_vctx *vctx) struct gf100_vmm_map_v0 args = { .priv = 1 }; int ret; + /* The video falcons access their context with non-privileged + * requests, and fault with PRIV_VIOLATION on a privileged mapping. + */ + switch (engn->engine->subdev.type) { + case NVKM_ENGINE_MSVLD: + case NVKM_ENGINE_MSPDEC: + case NVKM_ENGINE_MSPPP: + args.priv = 0; + break; + default: + break; + } + ret = nvkm_vmm_get(vctx->vmm, 12, vctx->inst->size, &vctx->vma); if (ret) return ret; diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c index 7f7404a7614099..883adc7f0b4537 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c @@ -128,7 +128,7 @@ gv100_gr_scg_estimate_perf(struct gf100_gr *gr, unsigned long *gpc_tpc_mask, u32 *num_tpc_gpc; int ret = -EINVAL; - if (!(num_tpc_gpc = kcalloc(gr->gpc_nr, sizeof(*num_tpc_gpc), GFP_KERNEL))) + if (!(num_tpc_gpc = kzalloc_objs(*num_tpc_gpc, gr->gpc_nr))) return -ENOMEM; /* Calculate pix-perf-reduction-rate per GPC and find bottleneck TPC */ @@ -231,9 +231,9 @@ gv100_gr_oneinit_sm_id(struct gf100_gr *gr) u32 gpc, tpc, pes, gtpc; int perf, maxperf, ret = 0; - gpc_tpc_mask = kcalloc(gr->gpc_nr, sizeof(*gpc_tpc_mask), GFP_KERNEL); - gpc_table = kcalloc(gr->tpc_total, sizeof(*gpc_table), GFP_KERNEL); - tpc_table = kcalloc(gr->tpc_total, sizeof(*tpc_table), GFP_KERNEL); + gpc_tpc_mask = kzalloc_objs(*gpc_tpc_mask, gr->gpc_nr); + gpc_table = kzalloc_objs(*gpc_table, gr->tpc_total); + tpc_table = kzalloc_objs(*tpc_table, gr->tpc_total); if (!gpc_table || !tpc_table || !gpc_tpc_mask) { ret = -ENOMEM; goto done; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c index 5368e705e7fd64..186e09ea0cb10a 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c @@ -27,6 +27,7 @@ #include #include #include +#include int gf100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq) @@ -99,6 +100,25 @@ gf100_devinit_preinit(struct nvkm_devinit *base) * can use it as a reliable way to know whether we should run devinit. */ base->post = ((nvkm_rd32(device, 0x2240c) & BIT(1)) == 0); + + /* + * However some VBIOS init sequences miss this bit. So fall back to + * the nv50 method of checking if the bit is not set. Running the + * VBIOS multiple times may have detrimental effects. + */ + if (base->post) { + u64 disable = nvkm_devinit_disable(base); + /* magic to detect whether or not x86 vbios code has + * executed the devinit scripts to initialise the + * board. only works if there's a display engine. + */ + if (!(disable & (1ULL << NVKM_ENGINE_DISP))) { + if (nvkm_rdvgac(device, 0, 0x00) || + nvkm_rdvgac(device, 0, 0x1a)) { + base->post = false; + } + } + } } static const struct nvkm_devinit_func diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgt215.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgt215.c index 3135b46cbfcde3..bff0802b72568a 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgt215.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgt215.c @@ -171,7 +171,7 @@ gt215_link_train(struct gt215_ram *ram) return -ENOSYS; /* XXX: Multiple partitions? */ - result = kmalloc_array(64, sizeof(u32), GFP_KERNEL); + result = kmalloc_objs(u32, 64); if (!result) return -ENOMEM; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga100.c index d5126fe39d2737..10e2813a0163fa 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga100.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga100.c @@ -27,6 +27,7 @@ ga100_gsp_flcn = { .enable = gm200_flcn_enable, .addr2 = 0x1000, .riscv_irqmask = 0x2b4, + .riscv_irqdest = 0x2b8, .reset_eng = gp102_flcn_reset_eng, .reset_wait_mem_scrubbing = gm200_flcn_reset_wait_mem_scrubbing, .bind_inst = gm200_flcn_bind_inst, diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga102.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga102.c index b6b3eb6f4c006e..96fa26fa61227c 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga102.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/ga102.c @@ -140,6 +140,7 @@ ga102_gsp_flcn = { .select = ga102_flcn_select, .addr2 = 0x1000, .riscv_irqmask = 0x528, + .riscv_irqdest = 0x52c, .reset_eng = gp102_flcn_reset_eng, .reset_prep = ga102_flcn_reset_prep, .reset_wait_mem_scrubbing = ga102_flcn_reset_wait_mem_scrubbing, diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c index 63aa30f9474715..fe590a045d70af 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c @@ -64,7 +64,9 @@ r535_gsp_intr(struct nvkm_inth *inth) u32 intr = nvkm_falcon_rd32(&gsp->falcon, 0x0008); u32 inte = nvkm_falcon_rd32(&gsp->falcon, gsp->falcon.func->addr2 + gsp->falcon.func->riscv_irqmask); - u32 stat = intr & inte; + u32 dest = nvkm_falcon_rd32(&gsp->falcon, gsp->falcon.func->addr2 + + gsp->falcon.func->riscv_irqdest); + u32 stat = intr & inte & dest; if (!stat) { nvkm_debug(subdev, "inte %08x %08x\n", intr, inte); diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/tu102.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/tu102.c index 11a37963bd4e7e..823532758afde5 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/tu102.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/tu102.c @@ -420,6 +420,7 @@ tu102_gsp_flcn = { .enable = gm200_flcn_enable, .addr2 = 0x1000, .riscv_irqmask = 0x2b4, + .riscv_irqdest = 0x2b8, .reset_eng = gp102_flcn_reset_eng, .reset_wait_mem_scrubbing = gm200_flcn_reset_wait_mem_scrubbing, .bind_inst = gm200_flcn_bind_inst, diff --git a/drivers/gpu/drm/omapdrm/dss/base.c b/drivers/gpu/drm/omapdrm/dss/base.c index a4ac113e16904b..0bfdb467b02676 100644 --- a/drivers/gpu/drm/omapdrm/dss/base.c +++ b/drivers/gpu/drm/omapdrm/dss/base.c @@ -209,7 +209,7 @@ static void omapdss_walk_device(struct device *dev, struct device_node *node, if (ret < 0) return; - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc_obj(dev, *comp); if (comp) { comp->node = node; comp->dss_core_component = dss_core; diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c index 78b74217f95201..2a23b4c59c29fb 100644 --- a/drivers/gpu/drm/omapdrm/dss/dispc.c +++ b/drivers/gpu/drm/omapdrm/dss/dispc.c @@ -3769,8 +3769,7 @@ static int dispc_init_gamma_tables(struct dispc_device *dispc) !dispc_has_feature(dispc, FEAT_MGR_LCD3)) continue; - gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len, - sizeof(u32), GFP_KERNEL); + gt = devm_kmalloc_objs(&dispc->pdev->dev, u32, gdesc->len); if (!gt) return -ENOMEM; diff --git a/drivers/gpu/drm/omapdrm/dss/video-pll.c b/drivers/gpu/drm/omapdrm/dss/video-pll.c index b6b52049f75365..8eedb09b16a256 100644 --- a/drivers/gpu/drm/omapdrm/dss/video-pll.c +++ b/drivers/gpu/drm/omapdrm/dss/video-pll.c @@ -163,7 +163,7 @@ struct dss_pll *dss_video_pll_init(struct dss_device *dss, return ERR_CAST(clk); } - vpll = devm_kzalloc(&pdev->dev, sizeof(*vpll), GFP_KERNEL); + vpll = devm_kzalloc_obj(&pdev->dev, *vpll); if (!vpll) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c index a2c702b831a7c3..ee940a6833ffda 100644 --- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c @@ -1085,7 +1085,7 @@ int tiler_map_show(struct seq_file *s, void *arg) h_adj = omap_dmm->container_height / ydiv; w_adj = omap_dmm->container_width / xdiv; - map = kmalloc_array(h_adj, sizeof(*map), GFP_KERNEL); + map = kmalloc_objs(*map, h_adj); global_map = kmalloc_array(w_adj + 1, h_adj, GFP_KERNEL); if (!map || !global_map) diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c index f83b93a1a414b3..f7add22ccf6964 100644 --- a/drivers/gpu/drm/panel/panel-edp.c +++ b/drivers/gpu/drm/panel/panel-edp.c @@ -782,7 +782,7 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel) u32 absent_ms = 0; int ret; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return -ENOMEM; panel->desc = desc; diff --git a/drivers/gpu/drm/panel/panel-ilitek-ili9341.c b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c index 8115a31584923b..0bab6f0867175f 100644 --- a/drivers/gpu/drm/panel/panel-ilitek-ili9341.c +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c @@ -494,8 +494,7 @@ static int ili9341_dpi_probe(struct spi_device *spi, struct gpio_desc *dc, if (IS_ERR(ili)) return PTR_ERR(ili); - ili->dbi = devm_kzalloc(dev, sizeof(struct mipi_dbi), - GFP_KERNEL); + ili->dbi = devm_kzalloc_obj(dev, struct mipi_dbi); if (!ili->dbi) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-ilitek-ili9806e-dsi.c b/drivers/gpu/drm/panel/panel-ilitek-ili9806e-dsi.c index 89915d58f69d8a..086393ddcab7c1 100644 --- a/drivers/gpu/drm/panel/panel-ilitek-ili9806e-dsi.c +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9806e-dsi.c @@ -119,7 +119,7 @@ static int ili9806e_dsi_probe(struct mipi_dsi_device *dsi) struct ili9806e_dsi_panel *ctx; int ret; - ctx = devm_kzalloc(dev, sizeof(struct ili9806e_dsi_panel), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, struct ili9806e_dsi_panel); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-ilitek-ili9806e-spi.c b/drivers/gpu/drm/panel/panel-ilitek-ili9806e-spi.c index 187bcb084dd98a..9271c3c89a7f92 100644 --- a/drivers/gpu/drm/panel/panel-ilitek-ili9806e-spi.c +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9806e-spi.c @@ -109,7 +109,7 @@ static int ili9806e_spi_probe(struct spi_device *spi) struct ili9806e_spi_panel *ctx; int err; - ctx = devm_kzalloc(dev, sizeof(struct ili9806e_spi_panel), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, struct ili9806e_spi_panel); if (!ctx) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c b/drivers/gpu/drm/panel/panel-innolux-p079zca.c index 80afeeab9475fa..a061d548ff0d1e 100644 --- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c +++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c @@ -390,9 +390,8 @@ static int innolux_panel_add(struct mipi_dsi_device *dsi, innolux->desc = desc; - innolux->supplies = devm_kcalloc(dev, desc->num_supplies, - sizeof(*innolux->supplies), - GFP_KERNEL); + innolux->supplies = devm_kzalloc_objs(dev, *innolux->supplies, + desc->num_supplies); if (!innolux->supplies) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-raydium-rm67191.c b/drivers/gpu/drm/panel/panel-raydium-rm67191.c index 2af6aa47a55101..e3b806e8a3a79c 100644 --- a/drivers/gpu/drm/panel/panel-raydium-rm67191.c +++ b/drivers/gpu/drm/panel/panel-raydium-rm67191.c @@ -507,8 +507,8 @@ static int rad_init_regulators(struct rad_panel *rad) int i; rad->num_supplies = ARRAY_SIZE(rad_supply_names); - rad->supplies = devm_kcalloc(dev, rad->num_supplies, - sizeof(*rad->supplies), GFP_KERNEL); + rad->supplies = devm_kzalloc_objs(dev, *rad->supplies, + rad->num_supplies); if (!rad->supplies) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e63m0-spi.c b/drivers/gpu/drm/panel/panel-samsung-s6e63m0-spi.c index c8bec2b1e7c1aa..94cb84d179e296 100644 --- a/drivers/gpu/drm/panel/panel-samsung-s6e63m0-spi.c +++ b/drivers/gpu/drm/panel/panel-samsung-s6e63m0-spi.c @@ -48,7 +48,7 @@ static int s6e63m0_spi_probe(struct spi_device *spi) struct mipi_dbi *dbi; int ret; - dbi = devm_kzalloc(dev, sizeof(*dbi), GFP_KERNEL); + dbi = devm_kzalloc_obj(dev, *dbi); if (!dbi) return -ENOMEM; diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index a944c34642dcc4..bf2e1dd88f40eb 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -449,11 +449,11 @@ static struct panel_desc *panel_dpi_probe(struct device *dev) int ret; np = dev->of_node; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return ERR_PTR(-ENOMEM); - timing = devm_kzalloc(dev, sizeof(*timing), GFP_KERNEL); + timing = devm_kzalloc_obj(dev, *timing); if (!timing) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/panel/panel-visionox-r66451.c b/drivers/gpu/drm/panel/panel-visionox-r66451.c index 1efb139bb7115c..db8137b5fe5b6b 100644 --- a/drivers/gpu/drm/panel/panel-visionox-r66451.c +++ b/drivers/gpu/drm/panel/panel-visionox-r66451.c @@ -36,7 +36,7 @@ static void visionox_r66451_reset(struct visionox_r66451 *ctx) gpiod_set_value_cansleep(ctx->reset_gpio, 1); usleep_range(10000, 10100); gpiod_set_value_cansleep(ctx->reset_gpio, 0); - usleep_range(10000, 10100); + usleep_range(20000, 21000); } static int visionox_r66451_on(struct visionox_r66451 *ctx) @@ -227,7 +227,7 @@ static int visionox_r66451_bl_update_status(struct backlight_device *bl) struct mipi_dsi_device *dsi = bl_get_data(bl); u16 brightness = backlight_get_brightness(bl); - return mipi_dsi_dcs_set_display_brightness(dsi, brightness); + return mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); } static const struct backlight_ops visionox_r66451_bl_ops = { @@ -261,7 +261,7 @@ static int visionox_r66451_probe(struct mipi_dsi_device *dsi) if (IS_ERR(ctx)) return PTR_ERR(ctx); - dsc = devm_kzalloc(dev, sizeof(*dsc), GFP_KERNEL); + dsc = devm_kzalloc_obj(dev, *dsc); if (!dsc) return -ENOMEM; diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c index fb0a1b45007b55..40eda3612f849f 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.c +++ b/drivers/gpu/drm/panfrost/panfrost_device.c @@ -146,9 +146,9 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev) { int ret, i; - pfdev->regulators = devm_kcalloc(pfdev->base.dev, pfdev->comp->num_supplies, - sizeof(*pfdev->regulators), - GFP_KERNEL); + pfdev->regulators = devm_kzalloc_objs(pfdev->base.dev, + *pfdev->regulators, + pfdev->comp->num_supplies); if (!pfdev->regulators) return -ENOMEM; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 7c348a0bf1eebe..eeda113037fe0d 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -260,7 +260,7 @@ panfrost_copy_in_sync(struct drm_device *dev, if (!in_fence_count) return 0; - handles = kvmalloc_array(in_fence_count, sizeof(u32), GFP_KERNEL); + handles = kvmalloc_objs(u32, in_fence_count); if (!handles) { ret = -ENOMEM; DRM_DEBUG("Failed to allocate incoming syncobj handles\n"); diff --git a/drivers/gpu/drm/panfrost/panfrost_gpu.c b/drivers/gpu/drm/panfrost/panfrost_gpu.c index 6081b27829e1f0..5c3fee65c9e3aa 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gpu.c +++ b/drivers/gpu/drm/panfrost/panfrost_gpu.c @@ -94,11 +94,10 @@ int panfrost_gpu_soft_reset(struct panfrost_device *pfdev) GPU_IRQ_CLEAN_CACHES_COMPLETED); /* - * All in-flight jobs should have released their cycle - * counter references upon reset, but let us make sure + * Even though all in-flight jobs should have released their cycle counter + * references upon reset, perfcnt's might still hang about. */ - if (drm_WARN_ON(&pfdev->base, atomic_read(&pfdev->cycle_counter.use_count) != 0)) - atomic_set(&pfdev->cycle_counter.use_count, 0); + atomic_set(&pfdev->cycle_counter.use_count, 0); return 0; } diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index 4ddf4b722ddf49..3a46dd61cf87f8 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -869,7 +869,7 @@ int panfrost_jm_init(struct panfrost_device *pfdev) if (!panfrost_has_hw_feature(pfdev, HW_FEATURE_JOBCHAIN_DISAMBIGUATION)) args.credit_limit = 1; - js = devm_kzalloc(pfdev->base.dev, sizeof(*js), GFP_KERNEL); + js = devm_kzalloc_obj(pfdev->base.dev, *js); if (!js) return -ENOMEM; pfdev->js = js; diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c index a9def452d5ef9f..9e9c2e95303654 100644 --- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c +++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c @@ -17,6 +17,7 @@ #include "panfrost_device.h" #include "panfrost_features.h" #include "panfrost_gem.h" +#include "panfrost_gpu.h" #include "panfrost_issues.h" #include "panfrost_job.h" #include "panfrost_mmu.h" @@ -52,6 +53,7 @@ static void panfrost_perfcnt_hw_disable(struct panfrost_device *pfdev) gpu_write(pfdev, GPU_PRFCNT_TILER_EN, 0); if (perfcnt->owns_as_ref) { + panfrost_cycle_counter_put(pfdev); panfrost_mmu_as_put(pfdev, perfcnt->mapping->mmu); perfcnt->owns_as_ref = false; } @@ -84,6 +86,7 @@ static int panfrost_perfcnt_hw_enable(struct panfrost_device *pfdev) return ret; perfcnt->owns_as_ref = true; + panfrost_cycle_counter_get(pfdev); as = ret; cfg = GPU_PERFCNT_CFG_AS(as) | @@ -145,18 +148,17 @@ static int panfrost_perfcnt_dump_locked(struct panfrost_device *pfdev, u32 *stat */ ret = wait_for_completion_interruptible_timeout(&pfdev->perfcnt->dump_comp, msecs_to_jiffies(1000)); - if (!ret) ret = -ETIMEDOUT; - /* We need to restore perfcnt state so the next successful dump can relay it to UM */ - if (ret < 0) { - perfcnt->state |= *state; - *state = 0; - return ret; - } - scoped_guard(rwsem_read, &pfdev->reset.lock) { + /* Restore perfcnt state so the next successful dump can relay it to UM */ + if (ret < 0) { + perfcnt->state |= *state; + *state = 0; + return ret; + } + *state |= perfcnt->state; /* UM must re-enable their session before requesting new dumps. */ @@ -402,7 +404,7 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev) COUNTERS_PER_BLOCK * BYTES_PER_COUNTER; } - perfcnt = devm_kzalloc(pfdev->base.dev, sizeof(*perfcnt), GFP_KERNEL); + perfcnt = devm_kzalloc_obj(pfdev->base.dev, *perfcnt); if (!perfcnt) return -ENOMEM; diff --git a/drivers/gpu/drm/pl111/pl111_drv.c b/drivers/gpu/drm/pl111/pl111_drv.c index 89d44e970510ba..cbb09b446c2d50 100644 --- a/drivers/gpu/drm/pl111/pl111_drv.c +++ b/drivers/gpu/drm/pl111/pl111_drv.c @@ -242,7 +242,7 @@ static int pl111_amba_probe(struct amba_device *amba_dev, struct drm_device *drm; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c index 2db819ab85d2dc..6bd4a389f89d81 100644 --- a/drivers/gpu/drm/radeon/radeon_cs.c +++ b/drivers/gpu/drm/radeon/radeon_cs.c @@ -285,7 +285,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) p->chunk_relocs = NULL; p->chunk_flags = NULL; p->chunk_const_ib = NULL; - p->chunks_array = kvmalloc_array(cs->num_chunks, sizeof(uint64_t), GFP_KERNEL); + p->chunks_array = kvmalloc_objs(uint64_t, cs->num_chunks); if (p->chunks_array == NULL) { return -ENOMEM; } @@ -344,7 +344,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) continue; } - p->chunks[i].kdata = kvmalloc_array(size, sizeof(uint32_t), GFP_KERNEL); + p->chunks[i].kdata = kvmalloc_objs(uint32_t, size); size *= sizeof(uint32_t); if (p->chunks[i].kdata == NULL) { return -ENOMEM; diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c index a0fc0801abb02c..bf94fa86f29c68 100644 --- a/drivers/gpu/drm/radeon/radeon_object.c +++ b/drivers/gpu/drm/radeon/radeon_object.c @@ -147,7 +147,7 @@ int radeon_bo_create(struct radeon_device *rdev, } *bo_ptr = NULL; - bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL); + bo = kzalloc_obj(struct radeon_bo); if (bo == NULL) return -ENOMEM; drm_gem_private_object_init(rdev_to_drm(rdev), &bo->tbo.base, size); diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c index a5dff072c1ac03..b6e9fe0bc95923 100644 --- a/drivers/gpu/drm/radeon/radeon_ring.c +++ b/drivers/gpu/drm/radeon/radeon_ring.c @@ -322,7 +322,7 @@ unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring } /* and then save the content of the ring */ - *data = kvmalloc_array(size, sizeof(uint32_t), GFP_KERNEL); + *data = kvmalloc_objs(uint32_t, size); if (!*data) { mutex_unlock(&rdev->ring_lock); return 0; diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c b/drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c index 5bced9d778e8d6..36762ec172d10f 100644 --- a/drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c @@ -168,7 +168,7 @@ static int rcar_cmm_probe(struct platform_device *pdev) { struct rcar_cmm *rcmm; - rcmm = devm_kzalloc(&pdev->dev, sizeof(*rcmm), GFP_KERNEL); + rcmm = devm_kzalloc_obj(&pdev->dev, *rcmm); if (!rcmm) return -ENOMEM; platform_set_drvdata(pdev, rcmm); diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c index 59c2a4b761376e..1cd66c4b990f4b 100644 --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c @@ -917,7 +917,7 @@ static void rcar_du_crtc_crc_init(struct rcar_du_crtc *rcrtc) /* Reserve 1 for "auto" source. */ count = rcrtc->vsp->num_planes + 1; - sources = kmalloc_array(count, sizeof(*sources), GFP_KERNEL); + sources = kmalloc_objs(*sources, count); if (!sources) return; diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c index ccdd4b9ecdb895..3a80600eece1ad 100644 --- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c +++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c @@ -442,7 +442,7 @@ static int rockchip_dp_probe(struct platform_device *pdev) if (!dp_data) return -ENODEV; - dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(dev, *dp); if (!dp) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c index 68aa66915e8ac4..335177aacdef87 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c @@ -1125,7 +1125,7 @@ static int cdn_dp_probe(struct platform_device *pdev) if (IS_ERR(extcon) || IS_ERR(phy)) continue; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c index aab3353945de5c..30d6f83cd5da9a 100644 --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c @@ -1409,7 +1409,7 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev) of_device_get_match_data(dev); int ret, i; - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi2-rockchip.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi2-rockchip.c index 6db88665060d62..3609ac34b91172 100644 --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi2-rockchip.c +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi2-rockchip.c @@ -385,7 +385,7 @@ static int dw_mipi_dsi2_rockchip_probe(struct platform_device *pdev) void __iomem *base; int i; - dsi2 = devm_kzalloc(dev, sizeof(*dsi2), GFP_KERNEL); + dsi2 = devm_kzalloc_obj(dev, *dsi2); if (!dsi2) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/rk3066_hdmi.c b/drivers/gpu/drm/rockchip/rk3066_hdmi.c index 273f61758b10d2..d24f4832293e62 100644 --- a/drivers/gpu/drm/rockchip/rk3066_hdmi.c +++ b/drivers/gpu/drm/rockchip/rk3066_hdmi.c @@ -650,7 +650,7 @@ static struct i2c_adapter *rk3066_hdmi_i2c_adapter(struct rk3066_hdmi *hdmi) struct rk3066_hdmi_i2c *i2c; int ret; - i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(hdmi->dev, *i2c); if (!i2c) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 3099408e9d0505..ba417f7e9e4746 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -163,7 +163,7 @@ static int rockchip_drm_bind(struct device *dev) dev_set_drvdata(dev, drm_dev); - private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL); + private = devm_kzalloc_obj(drm_dev->dev, *private); if (!private) { ret = -ENOMEM; goto err_free; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index b327a475b5bb8e..69e72727da24f3 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -2194,8 +2194,7 @@ static int vop_bind(struct device *dev, struct device *master, void *data) return -ENODEV; /* Allocate vop struct and its vop_win array */ - vop = devm_kzalloc(dev, struct_size(vop, win, vop_data->win_size), - GFP_KERNEL); + vop = devm_kzalloc_flex(dev, *vop, win, vop_data->win_size); if (!vop) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/rockchip_lvds.c b/drivers/gpu/drm/rockchip/rockchip_lvds.c index 505c6c56736d0d..9cd437dc8c9389 100644 --- a/drivers/gpu/drm/rockchip/rockchip_lvds.c +++ b/drivers/gpu/drm/rockchip/rockchip_lvds.c @@ -456,8 +456,7 @@ static int rk3288_lvds_probe(struct platform_device *pdev, return dev_err_probe(lvds->dev, PTR_ERR(lvds->pclk), "could not get or prepare pclk_lvds\n"); - lvds->pins = devm_kzalloc(lvds->dev, sizeof(*lvds->pins), - GFP_KERNEL); + lvds->pins = devm_kzalloc_obj(lvds->dev, *lvds->pins); if (!lvds->pins) return -ENOMEM; @@ -683,7 +682,7 @@ static int rockchip_lvds_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); + lvds = devm_kzalloc_obj(&pdev->dev, *lvds); if (!lvds) return -ENOMEM; diff --git a/drivers/gpu/drm/rockchip/rockchip_rgb.c b/drivers/gpu/drm/rockchip/rockchip_rgb.c index 0e1830bc40eeca..319a24f46a91a1 100644 --- a/drivers/gpu/drm/rockchip/rockchip_rgb.c +++ b/drivers/gpu/drm/rockchip/rockchip_rgb.c @@ -87,7 +87,7 @@ struct rockchip_rgb *rockchip_rgb_init(struct device *dev, struct drm_bridge *bridge; struct drm_connector *connector; - rgb = devm_kzalloc(dev, sizeof(*rgb), GFP_KERNEL); + rgb = devm_kzalloc_obj(dev, *rgb); if (!rgb) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 7be0387bac3ce2..03e68b4102d507 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -130,10 +130,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, INIT_LIST_HEAD(&entity->list); entity->guilty = guilty; - entity->priority = priority; entity->last_user = current->group_leader; - entity->rq_priority = drm_sched_policy == DRM_SCHED_POLICY_FAIR ? - DRM_SCHED_PRIORITY_KERNEL : priority; entity->num_sched_list = num_sched_list; entity->sched_list = num_sched_list > 1 ? sched_list : NULL; RB_CLEAR_NODE(&entity->rb_tree_node); @@ -144,26 +141,26 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, * not to do this and to fix their DRM calling order. */ pr_warn("%s: called with uninitialized scheduler\n", __func__); - } else { - enum drm_sched_priority p = entity->priority; - + } else if (priority >= sched_list[0]->num_user_rqs) { /* * The "priority" of an entity cannot exceed the number of * run-queues of a scheduler. Protect against num_rqs being 0, * by converting to signed. Choose the lowest priority * available. */ - if (p >= sched_list[0]->num_user_rqs) { - dev_err(sched_list[0]->dev, "entity with out-of-bounds priority:%u num_user_rqs:%u\n", - p, sched_list[0]->num_user_rqs); - p = max_t(s32, - (s32)sched_list[0]->num_user_rqs - 1, - (s32)DRM_SCHED_PRIORITY_KERNEL); - entity->priority = p; - } - entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; + dev_err(sched_list[0]->dev, "entity with out-of-bounds priority:%u num_user_rqs:%u\n", + priority, sched_list[0]->num_user_rqs); + priority = max_t(s32, + (s32)sched_list[0]->num_user_rqs - 1, + (s32)DRM_SCHED_PRIORITY_KERNEL); } + entity->priority = priority; + entity->rq_priority = drm_sched_policy == DRM_SCHED_POLICY_FAIR ? + DRM_SCHED_PRIORITY_KERNEL : priority; + if (sched_list[0]->sched_rq) + entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; + init_completion(&entity->entity_idle); /* We start in an idle state. */ @@ -459,6 +456,8 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, { spin_lock(&entity->lock); entity->priority = priority; + if (drm_sched_policy != DRM_SCHED_POLICY_FAIR) + entity->rq_priority = priority; spin_unlock(&entity->lock); } EXPORT_SYMBOL(drm_sched_entity_set_priority); diff --git a/drivers/gpu/drm/scheduler/sched_rq.c b/drivers/gpu/drm/scheduler/sched_rq.c index 23f46ec610e783..6f67a146d99c6e 100644 --- a/drivers/gpu/drm/scheduler/sched_rq.c +++ b/drivers/gpu/drm/scheduler/sched_rq.c @@ -345,6 +345,13 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity) lockdep_assert_held(&entity->lock); + /* + * If entity is getting torn down via drm_sched_entity_kill() we need + * to ensure it does not get re-added to the tree behind it's back. + */ + if (entity->stopped) + return; + spin_lock(&rq->lock); /* diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitronix/st7571-i2c.c index 44bc94be33d665..c96490b6e49999 100644 --- a/drivers/gpu/drm/sitronix/st7571-i2c.c +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c @@ -88,7 +88,7 @@ static int st7571_i2c_probe(struct i2c_client *client) struct st7571_i2c_transport *t; struct regmap *regmap; - t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL); + t = devm_kzalloc_obj(&client->dev, *t); if (!t) return -ENOMEM; diff --git a/drivers/gpu/drm/solomon/ssd130x-spi.c b/drivers/gpu/drm/solomon/ssd130x-spi.c index c41064aa8221af..a938630a3c662b 100644 --- a/drivers/gpu/drm/solomon/ssd130x-spi.c +++ b/drivers/gpu/drm/solomon/ssd130x-spi.c @@ -72,7 +72,7 @@ static int ssd130x_spi_probe(struct spi_device *spi) return dev_err_probe(dev, PTR_ERR(dc), "Failed to get dc gpio\n"); - t = devm_kzalloc(dev, sizeof(*t), GFP_KERNEL); + t = devm_kzalloc_obj(dev, *t); if (!t) return -ENOMEM; diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c index 23b0e1dc547a50..48bf1ba035f7ab 100644 --- a/drivers/gpu/drm/sprd/sprd_dsi.c +++ b/drivers/gpu/drm/sprd/sprd_dsi.c @@ -1032,7 +1032,7 @@ static int sprd_dsi_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct sprd_dsi *dsi; - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_compositor.c b/drivers/gpu/drm/sti/sti_compositor.c index 8c529b0cca8b48..b6ca9361532cb2 100644 --- a/drivers/gpu/drm/sti/sti_compositor.c +++ b/drivers/gpu/drm/sti/sti_compositor.c @@ -179,7 +179,7 @@ static int sti_compositor_probe(struct platform_device *pdev) struct sti_compositor *compo; unsigned int i; - compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL); + compo = devm_kzalloc_obj(dev, *compo); if (!compo) { DRM_ERROR("Failed to allocate compositor context\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_cursor.c b/drivers/gpu/drm/sti/sti_cursor.c index 6a3ddb7fc17d91..66f56355309f92 100644 --- a/drivers/gpu/drm/sti/sti_cursor.c +++ b/drivers/gpu/drm/sti/sti_cursor.c @@ -371,7 +371,7 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev, size_t size; int res; - cursor = devm_kzalloc(dev, sizeof(*cursor), GFP_KERNEL); + cursor = devm_kzalloc_obj(dev, *cursor); if (!cursor) { DRM_ERROR("Failed to allocate memory for cursor\n"); return NULL; diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c index cdb19b75f5e105..aafec7fec149e6 100644 --- a/drivers/gpu/drm/sti/sti_dvo.c +++ b/drivers/gpu/drm/sti/sti_dvo.c @@ -454,7 +454,7 @@ static int sti_dvo_bind(struct device *dev, struct device *master, void *data) if (!encoder) return -ENOMEM; - connector = devm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); + connector = devm_kzalloc_obj(dev, *connector); if (!connector) return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c index 89511abd4b392d..d0c886029c5708 100644 --- a/drivers/gpu/drm/sti/sti_gdp.c +++ b/drivers/gpu/drm/sti/sti_gdp.c @@ -926,7 +926,7 @@ struct drm_plane *sti_gdp_create(struct drm_device *drm_dev, struct sti_gdp *gdp; int res; - gdp = devm_kzalloc(dev, sizeof(*gdp), GFP_KERNEL); + gdp = devm_kzalloc_obj(dev, *gdp); if (!gdp) { DRM_ERROR("Failed to allocate memory for GDP\n"); return NULL; diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c index b4def2b25cec78..0b95d3f0789707 100644 --- a/drivers/gpu/drm/sti/sti_hda.c +++ b/drivers/gpu/drm/sti/sti_hda.c @@ -697,7 +697,7 @@ static int sti_hda_bind(struct device *dev, struct device *master, void *data) if (!encoder) return -ENOMEM; - connector = devm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); + connector = devm_kzalloc_obj(dev, *connector); if (!connector) return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c index 7ba9e0b7ba6c0d..e7a092ce7fe8a2 100644 --- a/drivers/gpu/drm/sti/sti_hdmi.c +++ b/drivers/gpu/drm/sti/sti_hdmi.c @@ -1293,7 +1293,7 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data) if (!encoder) return -EINVAL; - connector = devm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); + connector = devm_kzalloc_obj(dev, *connector); if (!connector) return -EINVAL; diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c index b367f7f84f5fe9..360d213f2094f8 100644 --- a/drivers/gpu/drm/sti/sti_hqvdp.c +++ b/drivers/gpu/drm/sti/sti_hqvdp.c @@ -1360,7 +1360,7 @@ static int sti_hqvdp_probe(struct platform_device *pdev) DRM_DEBUG_DRIVER("\n"); - hqvdp = devm_kzalloc(dev, sizeof(*hqvdp), GFP_KERNEL); + hqvdp = devm_kzalloc_obj(dev, *hqvdp); if (!hqvdp) { DRM_ERROR("Failed to allocate HQVDP context\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_mixer.c b/drivers/gpu/drm/sti/sti_mixer.c index 06c1b81912f79f..61f862e43f5986 100644 --- a/drivers/gpu/drm/sti/sti_mixer.c +++ b/drivers/gpu/drm/sti/sti_mixer.c @@ -360,7 +360,7 @@ struct sti_mixer *sti_mixer_create(struct device *dev, int id, void __iomem *baseaddr) { - struct sti_mixer *mixer = devm_kzalloc(dev, sizeof(*mixer), GFP_KERNEL); + struct sti_mixer *mixer = devm_kzalloc_obj(dev, *mixer); dev_dbg(dev, "%s\n", __func__); if (!mixer) { diff --git a/drivers/gpu/drm/sti/sti_tvout.c b/drivers/gpu/drm/sti/sti_tvout.c index 6a464b035de800..2f5ef863e8ffba 100644 --- a/drivers/gpu/drm/sti/sti_tvout.c +++ b/drivers/gpu/drm/sti/sti_tvout.c @@ -660,7 +660,7 @@ sti_tvout_create_dvo_encoder(struct drm_device *dev, struct sti_tvout_encoder *encoder; struct drm_encoder *drm_encoder; - encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(tvout->dev, *encoder); if (!encoder) return NULL; @@ -712,7 +712,7 @@ static struct drm_encoder *sti_tvout_create_hda_encoder(struct drm_device *dev, struct sti_tvout_encoder *encoder; struct drm_encoder *drm_encoder; - encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(tvout->dev, *encoder); if (!encoder) return NULL; @@ -760,7 +760,7 @@ static struct drm_encoder *sti_tvout_create_hdmi_encoder(struct drm_device *dev, struct sti_tvout_encoder *encoder; struct drm_encoder *drm_encoder; - encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(tvout->dev, *encoder); if (!encoder) return NULL; @@ -844,7 +844,7 @@ static int sti_tvout_probe(struct platform_device *pdev) if (!node) return -ENODEV; - tvout = devm_kzalloc(dev, sizeof(*tvout), GFP_KERNEL); + tvout = devm_kzalloc_obj(dev, *tvout); if (!tvout) return -ENOMEM; diff --git a/drivers/gpu/drm/sti/sti_vid.c b/drivers/gpu/drm/sti/sti_vid.c index 2d818397918db8..d706d9eb0095c0 100644 --- a/drivers/gpu/drm/sti/sti_vid.c +++ b/drivers/gpu/drm/sti/sti_vid.c @@ -209,7 +209,7 @@ struct sti_vid *sti_vid_create(struct device *dev, struct drm_device *drm_dev, { struct sti_vid *vid; - vid = devm_kzalloc(dev, sizeof(*vid), GFP_KERNEL); + vid = devm_kzalloc_obj(dev, *vid); if (!vid) { DRM_ERROR("Failed to allocate memory for VID\n"); return NULL; diff --git a/drivers/gpu/drm/sti/sti_vtg.c b/drivers/gpu/drm/sti/sti_vtg.c index ce6bc7e7b1359b..7d80cd8279c397 100644 --- a/drivers/gpu/drm/sti/sti_vtg.c +++ b/drivers/gpu/drm/sti/sti_vtg.c @@ -387,7 +387,7 @@ static int vtg_probe(struct platform_device *pdev) struct sti_vtg *vtg; int ret; - vtg = devm_kzalloc(dev, sizeof(*vtg), GFP_KERNEL); + vtg = devm_kzalloc_obj(dev, *vtg); if (!vtg) return -ENOMEM; vtg->regs = devm_platform_ioremap_resource(pdev, 0); diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c index a3eae5b2c26e1c..c9bd2c2e87ff80 100644 --- a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +++ b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c @@ -609,7 +609,7 @@ static int dw_mipi_dsi_stm_probe(struct platform_device *pdev) const struct dw_mipi_dsi_plat_data *pdata = of_device_get_match_data(dev); int ret; - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index adf5b6e09ca647..f01ab79127c7a5 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -792,7 +792,7 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, void __iomem *regs; int i, ret; - backend = devm_kzalloc(dev, sizeof(*backend), GFP_KERNEL); + backend = devm_kzalloc_obj(dev, *backend); if (!backend) return -ENOMEM; dev_set_drvdata(dev, backend); diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c index e6a20e2f0ade17..f618df8f15adfc 100644 --- a/drivers/gpu/drm/sun4i/sun4i_crtc.c +++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c @@ -198,7 +198,7 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm, struct drm_plane *primary = NULL, *cursor = NULL; int ret, i; - scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL); + scrtc = devm_kzalloc_obj(drm->dev, *scrtc); if (!scrtc) return ERR_PTR(-ENOMEM); scrtc->engine = engine; diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c index e9baca360160b8..f8bbca6eb49c85 100644 --- a/drivers/gpu/drm/sun4i/sun4i_drv.c +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c @@ -69,7 +69,7 @@ static int sun4i_drv_bind(struct device *dev) if (IS_ERR(drm)) return PTR_ERR(drm); - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) { ret = -ENOMEM; goto free_drm; diff --git a/drivers/gpu/drm/sun4i/sun4i_frontend.c b/drivers/gpu/drm/sun4i/sun4i_frontend.c index 5e9c4b97c84c30..7dc0a09bb3c542 100644 --- a/drivers/gpu/drm/sun4i/sun4i_frontend.c +++ b/drivers/gpu/drm/sun4i/sun4i_frontend.c @@ -563,7 +563,7 @@ static int sun4i_frontend_bind(struct device *dev, struct device *master, struct sun4i_drv *drv = drm->dev_private; void __iomem *regs; - frontend = devm_kzalloc(dev, sizeof(*frontend), GFP_KERNEL); + frontend = devm_kzalloc_obj(dev, *frontend); if (!frontend) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c index b1beadb9bb59f8..2e2bd4de0317a1 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c @@ -117,7 +117,7 @@ int sun4i_ddc_create(struct sun4i_hdmi *hdmi, struct clk *parent) if (!parent_name) return -ENODEV; - ddc = devm_kzalloc(hdmi->dev, sizeof(*ddc), GFP_KERNEL); + ddc = devm_kzalloc_obj(hdmi->dev, *ddc); if (!ddc) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c index 6f4fe0c8efaed2..721cd327b92f81 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c @@ -520,7 +520,7 @@ static int sun4i_hdmi_bind(struct device *dev, struct device *master, u32 reg; int ret; - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(dev, *hdmi); if (!hdmi) return -ENOMEM; dev_set_drvdata(dev, hdmi); diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_i2c.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_i2c.c index f5f62eb0eecaaa..c58930af56a965 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_i2c.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_i2c.c @@ -297,7 +297,7 @@ int sun4i_hdmi_i2c_create(struct device *dev, struct sun4i_hdmi *hdmi) if (ret) return ret; - adap = devm_kzalloc(dev, sizeof(*adap), GFP_KERNEL); + adap = devm_kzalloc_obj(dev, *adap); if (!adap) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c index fbf7da9d959214..20c71d1916f681 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c @@ -214,7 +214,7 @@ int sun4i_tmds_create(struct sun4i_hdmi *hdmi) if (!parents[1]) return -ENODEV; - tmds = devm_kzalloc(hdmi->dev, sizeof(*tmds), GFP_KERNEL); + tmds = devm_kzalloc_obj(hdmi->dev, *tmds); if (!tmds) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c index 7ec6d81319085e..cdfefbeee7b888 100644 --- a/drivers/gpu/drm/sun4i/sun4i_layer.c +++ b/drivers/gpu/drm/sun4i/sun4i_layer.c @@ -193,7 +193,7 @@ static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm, struct sun4i_layer *layer; int ret; - layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL); + layer = devm_kzalloc_obj(drm->dev, *layer); if (!layer) return ERR_PTR(-ENOMEM); @@ -234,8 +234,8 @@ struct drm_plane **sun4i_layers_init(struct drm_device *drm, int i; /* We need to have a sentinel at the need, hence the overallocation */ - planes = devm_kcalloc(drm->dev, SUN4I_BACKEND_NUM_LAYERS + 1, - sizeof(*planes), GFP_KERNEL); + planes = devm_kzalloc_objs(drm->dev, *planes, + SUN4I_BACKEND_NUM_LAYERS + 1); if (!planes) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/sun4i/sun4i_lvds.c b/drivers/gpu/drm/sun4i/sun4i_lvds.c index 6b98d20a8890c4..1073c985ff62a6 100644 --- a/drivers/gpu/drm/sun4i/sun4i_lvds.c +++ b/drivers/gpu/drm/sun4i/sun4i_lvds.c @@ -110,7 +110,7 @@ int sun4i_lvds_init(struct drm_device *drm, struct sun4i_tcon *tcon) struct sun4i_lvds *lvds; int ret; - lvds = devm_kzalloc(drm->dev, sizeof(*lvds), GFP_KERNEL); + lvds = devm_kzalloc_obj(drm->dev, *lvds); if (!lvds) return -ENOMEM; encoder = &lvds->encoder; diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c index 3da9a9283c6ec2..94fda035a0ec4a 100644 --- a/drivers/gpu/drm/sun4i/sun4i_rgb.c +++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c @@ -201,7 +201,7 @@ int sun4i_rgb_init(struct drm_device *drm, struct sun4i_tcon *tcon) struct sun4i_rgb *rgb; int ret; - rgb = devm_kzalloc(drm->dev, sizeof(*rgb), GFP_KERNEL); + rgb = devm_kzalloc_obj(drm->dev, *rgb); if (!rgb) return -ENOMEM; rgb->tcon = tcon; diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index bf405a2aa3249f..20740fa10ce8a9 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -1127,7 +1127,7 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, return -EPROBE_DEFER; } - tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL); + tcon = devm_kzalloc_obj(dev, *tcon); if (!tcon) return -ENOMEM; dev_set_drvdata(dev, tcon); diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon_dclk.c b/drivers/gpu/drm/sun4i/sun4i_tcon_dclk.c index 4afb12bd5281f0..f8cb096ef1f898 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon_dclk.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon_dclk.c @@ -178,7 +178,7 @@ int sun4i_dclk_create(struct device *dev, struct sun4i_tcon *tcon) if (ret) return ret; - dclk = devm_kzalloc(dev, sizeof(*dclk), GFP_KERNEL); + dclk = devm_kzalloc_obj(dev, *dclk); if (!dclk) return -ENOMEM; dclk->tcon = tcon; diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i_tv.c index ce22f1662c0cef..8de68736727007 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tv.c +++ b/drivers/gpu/drm/sun4i/sun4i_tv.c @@ -437,7 +437,7 @@ static int sun4i_tv_bind(struct device *dev, struct device *master, void __iomem *regs; int ret; - tv = devm_kzalloc(dev, sizeof(*tv), GFP_KERNEL); + tv = devm_kzalloc_obj(dev, *tv); if (!tv) return -ENOMEM; tv->drv = drv; diff --git a/drivers/gpu/drm/sun4i/sun6i_drc.c b/drivers/gpu/drm/sun4i/sun6i_drc.c index 0050c1b46ea8a5..5af6f07fe85436 100644 --- a/drivers/gpu/drm/sun4i/sun6i_drc.c +++ b/drivers/gpu/drm/sun4i/sun6i_drc.c @@ -24,7 +24,7 @@ static int sun6i_drc_bind(struct device *dev, struct device *master, struct sun6i_drc *drc; int ret; - drc = devm_kzalloc(dev, sizeof(*drc), GFP_KERNEL); + drc = devm_kzalloc_obj(dev, *drc); if (!drc) return -ENOMEM; dev_set_drvdata(dev, drc); diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c index d504ae5832949e..c4e3a2a8a2c135 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -1119,7 +1119,7 @@ static int sun6i_dsi_probe(struct platform_device *pdev) if (!variant) return -EINVAL; - dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(dev, *dsi); if (!dsi) return -ENOMEM; dev_set_drvdata(dev, dsi); diff --git a/drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c b/drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c index bd3923ef5a4169..cf1994341595df 100644 --- a/drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c +++ b/drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c @@ -112,7 +112,7 @@ static int sun8i_dw_hdmi_bind(struct device *dev, struct device *master, if (!pdev->dev.of_node) return -ENODEV; - hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(&pdev->dev, *hdmi); if (!hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c b/drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c index 489ea94693ffa8..0d284804e11f21 100644 --- a/drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c +++ b/drivers/gpu/drm/sun4i/sun8i_hdmi_phy.c @@ -677,7 +677,7 @@ static int sun8i_hdmi_phy_probe(struct platform_device *pdev) struct sun8i_hdmi_phy *phy; void __iomem *regs; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun8i_hdmi_phy_clk.c b/drivers/gpu/drm/sun4i/sun8i_hdmi_phy_clk.c index a4d31fe3abff1a..1e7ec8156fe645 100644 --- a/drivers/gpu/drm/sun4i/sun8i_hdmi_phy_clk.c +++ b/drivers/gpu/drm/sun4i/sun8i_hdmi_phy_clk.c @@ -157,7 +157,7 @@ int sun8i_phy_clk_create(struct sun8i_hdmi_phy *phy, struct device *dev, return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/sun4i/sun8i_mixer.c b/drivers/gpu/drm/sun4i/sun8i_mixer.c index b6cd7352e76c56..dbde80b3208086 100644 --- a/drivers/gpu/drm/sun4i/sun8i_mixer.c +++ b/drivers/gpu/drm/sun4i/sun8i_mixer.c @@ -321,7 +321,7 @@ static struct drm_plane **sun8i_layers_init(struct drm_device *drm, unsigned int phy_index; int i; - planes = devm_kcalloc(drm->dev, plane_cnt + 1, sizeof(*planes), GFP_KERNEL); + planes = devm_kzalloc_objs(drm->dev, *planes, plane_cnt + 1); if (!planes) return ERR_PTR(-ENOMEM); @@ -529,7 +529,7 @@ static int sun8i_mixer_bind(struct device *dev, struct device *master, return ret; } - mixer = devm_kzalloc(dev, sizeof(*mixer), GFP_KERNEL); + mixer = devm_kzalloc_obj(dev, *mixer); if (!mixer) return -ENOMEM; dev_set_drvdata(dev, mixer); diff --git a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c index 9cbd655518b20a..86e1e8fed03ae6 100644 --- a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c +++ b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c @@ -183,12 +183,11 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master, quirks = of_device_get_match_data(&pdev->dev); - tcon_top = devm_kzalloc(dev, sizeof(*tcon_top), GFP_KERNEL); + tcon_top = devm_kzalloc_obj(dev, *tcon_top); if (!tcon_top) return -ENOMEM; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, CLK_NUM), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, CLK_NUM); if (!clk_data) return -ENOMEM; clk_data->num = CLK_NUM; diff --git a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c index bad102134726b3..cf66f676824e62 100644 --- a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c @@ -255,7 +255,7 @@ struct sun8i_layer *sun8i_ui_layer_init_one(struct drm_device *drm, struct sun8i_layer *layer; int ret; - layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL); + layer = devm_kzalloc_obj(drm->dev, *layer); if (!layer) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c index 2e9cda45c04ef7..6b19fafd50ad38 100644 --- a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c @@ -398,7 +398,7 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm, const u32 *formats; int ret; - layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL); + layer = devm_kzalloc_obj(drm->dev, *layer); if (!layer) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c index 21ddf4502ecc82..deaeb7d1fd94ba 100644 --- a/drivers/gpu/drm/sysfb/simpledrm.c +++ b/drivers/gpu/drm/sysfb/simpledrm.c @@ -523,15 +523,13 @@ static int simpledrm_device_attach_genpd(struct simpledrm_device *sdev) if (sdev->pwr_dom_count <= 1) return 0; - sdev->pwr_dom_devs = devm_kcalloc(dev, sdev->pwr_dom_count, - sizeof(*sdev->pwr_dom_devs), - GFP_KERNEL); + sdev->pwr_dom_devs = devm_kzalloc_objs(dev, *sdev->pwr_dom_devs, + sdev->pwr_dom_count); if (!sdev->pwr_dom_devs) return -ENOMEM; - sdev->pwr_dom_links = devm_kcalloc(dev, sdev->pwr_dom_count, - sizeof(*sdev->pwr_dom_links), - GFP_KERNEL); + sdev->pwr_dom_links = devm_kzalloc_objs(dev, *sdev->pwr_dom_links, + sdev->pwr_dom_count); if (!sdev->pwr_dom_links) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index b0bfa946e6979f..c9df14544ced02 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -3290,7 +3290,7 @@ static int tegra_dc_probe(struct platform_device *pdev) return err; } - dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL); + dc = devm_kzalloc_obj(&pdev->dev, *dc); if (!dc) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/dpaux.c b/drivers/gpu/drm/tegra/dpaux.c index e5297ac5c0fc47..a61d153312f9f1 100644 --- a/drivers/gpu/drm/tegra/dpaux.c +++ b/drivers/gpu/drm/tegra/dpaux.c @@ -450,7 +450,7 @@ static int tegra_dpaux_probe(struct platform_device *pdev) u32 value; int err; - dpaux = devm_kzalloc(&pdev->dev, sizeof(*dpaux), GFP_KERNEL); + dpaux = devm_kzalloc_obj(&pdev->dev, *dpaux); if (!dpaux) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c index 7b595310e73799..b694c4abc5643d 100644 --- a/drivers/gpu/drm/tegra/dsi.c +++ b/drivers/gpu/drm/tegra/dsi.c @@ -1602,7 +1602,7 @@ static int tegra_dsi_probe(struct platform_device *pdev) struct tegra_dsi *dsi; int err; - dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(&pdev->dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c index 892e3450b281e4..a190add03b08c2 100644 --- a/drivers/gpu/drm/tegra/gr2d.c +++ b/drivers/gpu/drm/tegra/gr2d.c @@ -236,7 +236,7 @@ static int gr2d_probe(struct platform_device *pdev) unsigned int i; int err; - gr2d = devm_kzalloc(dev, sizeof(*gr2d), GFP_KERNEL); + gr2d = devm_kzalloc_obj(dev, *gr2d); if (!gr2d) return -ENOMEM; @@ -244,7 +244,7 @@ static int gr2d_probe(struct platform_device *pdev) gr2d->soc = of_device_get_match_data(dev); - syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL); + syncpts = devm_kzalloc_obj(dev, *syncpts); if (!syncpts) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c index 1ec6ced959e4e6..930976fa0ab866 100644 --- a/drivers/gpu/drm/tegra/gr3d.c +++ b/drivers/gpu/drm/tegra/gr3d.c @@ -471,7 +471,7 @@ static int gr3d_probe(struct platform_device *pdev) unsigned int i; int err; - gr3d = devm_kzalloc(&pdev->dev, sizeof(*gr3d), GFP_KERNEL); + gr3d = devm_kzalloc_obj(&pdev->dev, *gr3d); if (!gr3d) return -ENOMEM; @@ -479,7 +479,7 @@ static int gr3d_probe(struct platform_device *pdev) gr3d->soc = of_device_get_match_data(&pdev->dev); - syncpts = devm_kzalloc(&pdev->dev, sizeof(*syncpts), GFP_KERNEL); + syncpts = devm_kzalloc_obj(&pdev->dev, *syncpts); if (!syncpts) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c index 0d2c0ab0a63e9f..54880e5d52565a 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -1800,7 +1800,7 @@ static int tegra_hdmi_probe(struct platform_device *pdev) struct tegra_hdmi *hdmi; int err; - hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = devm_kzalloc_obj(&pdev->dev, *hdmi); if (!hdmi) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/hub.c b/drivers/gpu/drm/tegra/hub.c index 448f49f3a7d7ea..12429ca53eada1 100644 --- a/drivers/gpu/drm/tegra/hub.c +++ b/drivers/gpu/drm/tegra/hub.c @@ -1074,7 +1074,7 @@ static int tegra_display_hub_probe(struct platform_device *pdev) return err; } - hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL); + hub = devm_kzalloc_obj(&pdev->dev, *hub); if (!hub) return -ENOMEM; @@ -1106,8 +1106,8 @@ static int tegra_display_hub_probe(struct platform_device *pdev) return err; } - hub->wgrps = devm_kcalloc(&pdev->dev, hub->soc->num_wgrps, - sizeof(*hub->wgrps), GFP_KERNEL); + hub->wgrps = devm_kzalloc_objs(&pdev->dev, *hub->wgrps, + hub->soc->num_wgrps); if (!hub->wgrps) return -ENOMEM; @@ -1131,8 +1131,7 @@ static int tegra_display_hub_probe(struct platform_device *pdev) hub->num_heads = of_get_child_count(pdev->dev.of_node); - hub->clk_heads = devm_kcalloc(&pdev->dev, hub->num_heads, sizeof(clk), - GFP_KERNEL); + hub->clk_heads = devm_kzalloc_objs(&pdev->dev, clk, hub->num_heads); if (!hub->clk_heads) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/nvdec.c b/drivers/gpu/drm/tegra/nvdec.c index 7a38664e890e37..18a8f6e4ced083 100644 --- a/drivers/gpu/drm/tegra/nvdec.c +++ b/drivers/gpu/drm/tegra/nvdec.c @@ -434,13 +434,13 @@ static int nvdec_probe(struct platform_device *pdev) return err; } - nvdec = devm_kzalloc(dev, sizeof(*nvdec), GFP_KERNEL); + nvdec = devm_kzalloc_obj(dev, *nvdec); if (!nvdec) return -ENOMEM; nvdec->config = of_device_get_match_data(dev); - syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL); + syncpts = devm_kzalloc_obj(dev, *syncpts); if (!syncpts) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/nvjpg.c b/drivers/gpu/drm/tegra/nvjpg.c index 94503fd0d52d3b..e302a8d1f6e7fd 100644 --- a/drivers/gpu/drm/tegra/nvjpg.c +++ b/drivers/gpu/drm/tegra/nvjpg.c @@ -243,7 +243,7 @@ static int nvjpg_probe(struct platform_device *pdev) return err; } - nvjpg = devm_kzalloc(dev, sizeof(*nvjpg), GFP_KERNEL); + nvjpg = devm_kzalloc_obj(dev, *nvjpg); if (!nvjpg) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/rgb.c b/drivers/gpu/drm/tegra/rgb.c index b6d09a8d8e5ea4..40a02cf5939aa7 100644 --- a/drivers/gpu/drm/tegra/rgb.c +++ b/drivers/gpu/drm/tegra/rgb.c @@ -228,7 +228,7 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc) if (!of_device_is_available(np)) return -ENODEV; - rgb = devm_kzalloc(dc->dev, sizeof(*rgb), GFP_KERNEL); + rgb = devm_kzalloc_obj(dc->dev, *rgb); if (!rgb) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c index e384cbd0cbf72f..c7267921f04d66 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -604,7 +604,7 @@ static struct clk *tegra_clk_sor_pad_register(struct tegra_sor *sor, struct clk_init_data init; struct clk *clk; - pad = devm_kzalloc(sor->dev, sizeof(*pad), GFP_KERNEL); + pad = devm_kzalloc_obj(sor->dev, *pad); if (!pad) return ERR_PTR(-ENOMEM); @@ -3747,7 +3747,7 @@ static int tegra_sor_probe(struct platform_device *pdev) struct tegra_sor *sor; int err; - sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL); + sor = devm_kzalloc_obj(&pdev->dev, *sor); if (!sor) return -ENOMEM; diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index fe097e9675516b..3c2b1ff55deb7f 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -502,13 +502,13 @@ static int vic_probe(struct platform_device *pdev) return err; } - vic = devm_kzalloc(dev, sizeof(*vic), GFP_KERNEL); + vic = devm_kzalloc_obj(dev, *vic); if (!vic) return -ENOMEM; vic->config = of_device_get_match_data(dev); - syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL); + syncpts = devm_kzalloc_obj(dev, *syncpts); if (!syncpts) return -ENOMEM; diff --git a/drivers/gpu/drm/tidss/tidss_dispc.c b/drivers/gpu/drm/tidss/tidss_dispc.c index 2a0ec11a6c902f..b8568abafac55d 100644 --- a/drivers/gpu/drm/tidss/tidss_dispc.c +++ b/drivers/gpu/drm/tidss/tidss_dispc.c @@ -2944,7 +2944,7 @@ int dispc_init(struct tidss_device *tidss) dma_set_max_seg_size(dev, UINT_MAX); - dispc = devm_kzalloc(dev, sizeof(*dispc), GFP_KERNEL); + dispc = devm_kzalloc_obj(dev, *dispc); if (!dispc) return -ENOMEM; @@ -2954,8 +2954,8 @@ int dispc_init(struct tidss_device *tidss) dispc_init_errata(dispc); - dispc->fourccs = devm_kcalloc(dev, ARRAY_SIZE(dispc_color_formats), - sizeof(*dispc->fourccs), GFP_KERNEL); + dispc->fourccs = devm_kzalloc_objs(dev, *dispc->fourccs, + ARRAY_SIZE(dispc_color_formats)); if (!dispc->fourccs) return -ENOMEM; @@ -3007,9 +3007,7 @@ int dispc_init(struct tidss_device *tidss) } dispc->vp_clk[i] = clk; - gamma_table = devm_kmalloc_array(dev, gamma_size, - sizeof(*gamma_table), - GFP_KERNEL); + gamma_table = devm_kmalloc_objs(dev, *gamma_table, gamma_size); if (!gamma_table) return -ENOMEM; dispc->vp_data[i].gamma_table = gamma_table; diff --git a/drivers/gpu/drm/tidss/tidss_oldi.c b/drivers/gpu/drm/tidss/tidss_oldi.c index 5eb749f495d59e..62c9780f785595 100644 --- a/drivers/gpu/drm/tidss/tidss_oldi.c +++ b/drivers/gpu/drm/tidss/tidss_oldi.c @@ -297,8 +297,7 @@ static u32 *tidss_oldi_atomic_get_input_bus_fmts(struct drm_bridge *bridge, if (i == ARRAY_SIZE(oldi_bus_formats)) return NULL; - input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), - GFP_KERNEL); + input_fmts = kzalloc_objs(*input_fmts, MAX_INPUT_SEL_FORMATS); if (!input_fmts) return NULL; diff --git a/drivers/gpu/drm/tiny/panel-mipi-dbi.c b/drivers/gpu/drm/tiny/panel-mipi-dbi.c index 60cd65cae41d8d..3f462d79a6d3d9 100644 --- a/drivers/gpu/drm/tiny/panel-mipi-dbi.c +++ b/drivers/gpu/drm/tiny/panel-mipi-dbi.c @@ -170,7 +170,7 @@ panel_mipi_dbi_check_commands(struct device *dev, const struct firmware *fw) return ERR_PTR(-EINVAL); } - commands = devm_kzalloc(dev, sizeof(*commands), GFP_KERNEL); + commands = devm_kzalloc_obj(dev, *commands); if (!commands) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/tve200/tve200_drv.c b/drivers/gpu/drm/tve200/tve200_drv.c index 2bcb9dc86ffdce..f03e72363a7804 100644 --- a/drivers/gpu/drm/tve200/tve200_drv.c +++ b/drivers/gpu/drm/tve200/tve200_drv.c @@ -152,7 +152,7 @@ static int tve200_probe(struct platform_device *pdev) int irq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c index 532a92ab2fe763..04ff073cc0d4a9 100644 --- a/drivers/gpu/drm/v3d/v3d_gem.c +++ b/drivers/gpu/drm/v3d/v3d_gem.c @@ -217,6 +217,8 @@ v3d_clean_caches(struct v3d_dev *v3d) struct drm_device *dev = &v3d->drm; int core = 0; + guard(mutex)(&v3d->cache_clean_lock); + trace_v3d_cache_clean_begin(dev); /* GFXH-1897: Ensure pending flushes complete before writing L2TCACTL */ @@ -233,7 +235,6 @@ v3d_clean_caches(struct v3d_dev *v3d) drm_err(dev, "Timeout waiting for TMU write combiner flush\n"); } - mutex_lock(&v3d->cache_clean_lock); V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL, V3D_L2TCACTL_L2TFLS | V3D_SET_FIELD(V3D_L2TCACTL_FLM_CLEAN, V3D_L2TCACTL_FLM)); @@ -243,8 +244,6 @@ v3d_clean_caches(struct v3d_dev *v3d) drm_err(dev, "Timeout waiting for L2T clean\n"); } - mutex_unlock(&v3d->cache_clean_lock); - trace_v3d_cache_clean_end(dev); } diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c index 1924e3440dc9d2..1be2cd5bbf673b 100644 --- a/drivers/gpu/drm/v3d/v3d_sched.c +++ b/drivers/gpu/drm/v3d/v3d_sched.c @@ -360,6 +360,8 @@ v3d_csd_job_run(struct drm_sched_job *sched_job) dma_fence_put(job->base.irq_fence); job->base.irq_fence = dma_fence_get(fence); + job->timedout_batches = job->args.cfg[4]; + trace_v3d_submit_csd(dev, to_v3d_fence(fence)->seqno); v3d_job_start_stats(&job->base); diff --git a/drivers/gpu/drm/vboxvideo/vbox_main.c b/drivers/gpu/drm/vboxvideo/vbox_main.c index aa6664542b20d1..77c3ccad5b3d87 100644 --- a/drivers/gpu/drm/vboxvideo/vbox_main.c +++ b/drivers/gpu/drm/vboxvideo/vbox_main.c @@ -35,8 +35,8 @@ static int vbox_accel_init(struct vbox_private *vbox) struct vbva_buffer *vbva; unsigned int i; - vbox->vbva_info = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs, - sizeof(*vbox->vbva_info), GFP_KERNEL); + vbox->vbva_info = devm_kzalloc_objs(vbox->ddev.dev, *vbox->vbva_info, + vbox->num_crtcs); if (!vbox->vbva_info) return -ENOMEM; @@ -156,9 +156,9 @@ int vbox_hw_init(struct vbox_private *vbox) return ret; } - vbox->last_mode_hints = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs, - sizeof(struct vbva_modehint), - GFP_KERNEL); + vbox->last_mode_hints = devm_kzalloc_objs(vbox->ddev.dev, + struct vbva_modehint, + vbox->num_crtcs); if (!vbox->last_mode_hints) return -ENOMEM; diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c index ff611c618d6bc0..956be198f8a7c8 100644 --- a/drivers/gpu/drm/vc4/vc4_gem.c +++ b/drivers/gpu/drm/vc4/vc4_gem.c @@ -652,13 +652,14 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec, fence->seqno = exec->seqno; exec->fence = &fence->base; + /* The job can complete and drop exec->fence as soon as job_lock is + * released, so hold our own reference. + */ if (out_sync) - drm_syncobj_replace_fence(out_sync, exec->fence); + dma_fence_get(&fence->base); vc4_attach_fences(exec); - drm_exec_fini(exec_ctx); - list_add_tail(&exec->head, &vc4->bin_job_list); /* If no bin job was executing and if the render job (if any) has the @@ -675,6 +676,13 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec, spin_unlock_irqrestore(&vc4->job_lock, irqflags); + drm_exec_fini(exec_ctx); + + if (out_sync) { + drm_syncobj_replace_fence(out_sync, &fence->base); + dma_fence_put(&fence->base); + } + return 0; } diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 2cc46036f11d80..e57fc33af6b335 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -843,8 +843,7 @@ static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder) vc4_hdmi->scdc_enabled = false; - if (delayed_work_pending(&vc4_hdmi->scrambling_work)) - cancel_delayed_work_sync(&vc4_hdmi->scrambling_work); + cancel_delayed_work_sync(&vc4_hdmi->scrambling_work); if (!drm_dev_enter(drm, &idx)) return; @@ -919,8 +918,6 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder, spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags); } - vc4_hdmi_disable_scrambling(encoder); - drm_dev_exit(idx); out: @@ -948,6 +945,8 @@ static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder, if (vc4_hdmi->variant->phy_disable) vc4_hdmi->variant->phy_disable(vc4_hdmi); + vc4_hdmi_disable_scrambling(encoder); + clk_disable_unprepare(vc4_hdmi->pixel_bvb_clock); clk_disable_unprepare(vc4_hdmi->pixel_clock); @@ -1555,6 +1554,8 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, goto err_disable_pixel_clock; } + vc4_hdmi_enable_scrambling(encoder); + if (vc4_hdmi->variant->phy_init) vc4_hdmi->variant->phy_init(vc4_hdmi, conn_state); @@ -1689,7 +1690,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, } vc4_hdmi_recenter_fifo(vc4_hdmi); - vc4_hdmi_enable_scrambling(encoder); drm_dev_exit(idx); diff --git a/drivers/gpu/drm/vc4/vc4_hdmi_phy.c b/drivers/gpu/drm/vc4/vc4_hdmi_phy.c index 56e6a35da35768..5040f014bf7e66 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi_phy.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi_phy.c @@ -1197,4 +1197,9 @@ void vc6_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, void vc6_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi) { + unsigned long flags; + + spin_lock_irqsave(&vc4_hdmi->hw_lock, flags); + vc6_hdmi_reset_phy(vc4_hdmi); + spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags); } diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c index b1fb096858cccf..537aaa99212934 100644 --- a/drivers/gpu/drm/vc4/vc4_hvs.c +++ b/drivers/gpu/drm/vc4/vc4_hvs.c @@ -1677,15 +1677,6 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data) struct device_node *node; unsigned int max_rate; - node = rpi_firmware_find_node(); - if (!node) - return -EINVAL; - - firmware = rpi_firmware_get(node); - of_node_put(node); - if (!firmware) - return -EPROBE_DEFER; - hvs->core_clk = devm_clk_get(&pdev->dev, (vc4->gen >= VC4_GEN_6_C) ? "core" : NULL); if (IS_ERR(hvs->core_clk)) { @@ -1700,6 +1691,15 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data) return PTR_ERR(hvs->disp_clk); } + node = rpi_firmware_find_node(); + if (!node) + return -EINVAL; + + firmware = rpi_firmware_get(node); + of_node_put(node); + if (!firmware) + return -EPROBE_DEFER; + max_rate = rpi_firmware_clk_get_max_rate(firmware, RPI_FIRMWARE_CORE_CLK_ID); rpi_firmware_put(firmware); diff --git a/drivers/gpu/drm/vc4/vc4_irq.c b/drivers/gpu/drm/vc4/vc4_irq.c index c00a3e7c1358e5..ff405d3c1d4c39 100644 --- a/drivers/gpu/drm/vc4/vc4_irq.c +++ b/drivers/gpu/drm/vc4/vc4_irq.c @@ -53,10 +53,6 @@ #include "vc4_regs.h" #include "vc4_trace.h" -#define V3D_DRIVER_IRQS (V3D_INT_OUTOMEM | \ - V3D_INT_FLDONE | \ - V3D_INT_FRDONE) - static void vc4_overflow_mem_work(struct work_struct *work) { @@ -249,6 +245,7 @@ void vc4_irq_enable(struct drm_device *dev) { struct vc4_dev *vc4 = to_vc4_dev(dev); + u32 mask = V3D_INT_FLDONE | V3D_INT_FRDONE; if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return; @@ -256,10 +253,20 @@ vc4_irq_enable(struct drm_device *dev) if (!vc4->v3d) return; - /* Enable the render done interrupts. The out-of-memory interrupt is - * enabled as soon as we have a binner BO allocated. + /* Arming the OOM interrupt before there is a binner BO would raise an + * interrupt nothing can clear. */ - V3D_WRITE(V3D_INTENA, V3D_INT_FLDONE | V3D_INT_FRDONE); + if (vc4->bin_bo) + mask |= V3D_INT_OUTOMEM; + + /* Clear any pending interrupts someone might have left around for us. */ + V3D_WRITE(V3D_INTCTL, mask); + + /* Enable our set of interrupts, masking out any others. */ + V3D_WRITE(V3D_INTDIS, ~mask); + V3D_WRITE(V3D_INTENA, mask); + + enable_irq(vc4->irq); } void @@ -274,14 +281,14 @@ vc4_irq_disable(struct drm_device *dev) return; /* Disable sending interrupts for our driver's IRQs. */ - V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS); - - /* Clear any pending interrupts we might have left. */ - V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS); + V3D_WRITE(V3D_INTDIS, ~0); /* Finish any interrupt handler still in flight. */ disable_irq(vc4->irq); + /* Clear any pending interrupts we might have left. */ + V3D_WRITE(V3D_INTCTL, ~0); + cancel_work_sync(&vc4->overflow_mem_work); } @@ -324,15 +331,12 @@ void vc4_irq_reset(struct drm_device *dev) if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return; - /* Acknowledge any stale IRQs. */ - V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS); - - /* - * Turn all our interrupts on. Binner out of memory is the only - * one we expect to trigger at this point, since the reset cleared - * the overflow memory address and none has been supplied yet. + /* bin_bo_alloc() may arm OUTOMEM between the bin_bo check and the + * INTDIS write in vc4_irq_enable(), which would then mask it again. */ - V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS); + scoped_guard(mutex, &vc4->bin_bo_lock) { + vc4_irq_enable(dev); + } spin_lock_irqsave(&vc4->job_lock, irqflags); vc4_cancel_bin_job(dev); diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c index ed3bab11997906..86e8b6d2e6a101 100644 --- a/drivers/gpu/drm/vc4/vc4_v3d.c +++ b/drivers/gpu/drm/vc4/vc4_v3d.c @@ -302,11 +302,15 @@ static int bin_bo_alloc(struct vc4_dev *vc4) int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used) { - int ret = 0; + int ret; if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return -ENODEV; + ret = vc4_v3d_pm_get(vc4); + if (ret) + return ret; + mutex_lock(&vc4->bin_bo_lock); if (used && *used) @@ -322,6 +326,7 @@ int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used) complete: mutex_unlock(&vc4->bin_bo_lock); + vc4_v3d_pm_put(vc4); return ret; } @@ -373,7 +378,6 @@ static int vc4_v3d_runtime_resume(struct device *dev) vc4_v3d_init_hw(&vc4->base); vc4_irq_enable(&vc4->base); - enable_irq(vc4->irq); return 0; } @@ -403,7 +407,7 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data) struct vc4_v3d *v3d = NULL; int ret; - v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL); + v3d = devm_kzalloc_obj(&pdev->dev, *v3d); if (!v3d) return -ENOMEM; diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c index 66502a6a4a8e7b..db7c0dbdf60e27 100644 --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c @@ -799,8 +799,8 @@ vc4_validate_shader(struct drm_gem_dma_object *shader_obj) reset_validation_state(&validation_state); validation_state.branch_targets = - kcalloc(BITS_TO_LONGS(validation_state.max_ip), - sizeof(unsigned long), GFP_KERNEL); + kzalloc_objs(unsigned long, + BITS_TO_LONGS(validation_state.max_ip)); if (!validation_state.branch_targets) goto fail; diff --git a/drivers/gpu/drm/verisilicon/vs_bridge.c b/drivers/gpu/drm/verisilicon/vs_bridge.c index 3a5091c0ac2c0b..e27e0dd4f02a6c 100644 --- a/drivers/gpu/drm/verisilicon/vs_bridge.c +++ b/drivers/gpu/drm/verisilicon/vs_bridge.c @@ -67,8 +67,7 @@ static u32 *vs_bridge_atomic_get_output_bus_fmts_dpi(struct drm_bridge *bridge, *num_output_fmts = 2; - output_fmts = kcalloc(*num_output_fmts, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, *num_output_fmts); if (!output_fmts) return NULL; @@ -90,8 +89,7 @@ static u32 *vs_bridge_atomic_get_output_bus_fmts_dp(struct drm_bridge *bridge, *num_output_fmts = ARRAY_SIZE(vsdc_dp_supported_fmts); - output_fmts = kcalloc(*num_output_fmts, sizeof(*output_fmts), - GFP_KERNEL); + output_fmts = kzalloc_objs(*output_fmts, *num_output_fmts); if (!output_fmts) return NULL; diff --git a/drivers/gpu/drm/verisilicon/vs_dc.c b/drivers/gpu/drm/verisilicon/vs_dc.c index dad9967bc10b8d..f912da60575c7a 100644 --- a/drivers/gpu/drm/verisilicon/vs_dc.c +++ b/drivers/gpu/drm/verisilicon/vs_dc.c @@ -71,7 +71,7 @@ static int vs_dc_probe(struct platform_device *pdev) return ret; } - dc = devm_kzalloc(dev, sizeof(*dc), GFP_KERNEL); + dc = devm_kzalloc_obj(dev, *dc); if (!dc) return -ENOMEM; diff --git a/drivers/gpu/drm/virtio/virtgpu_submit.c b/drivers/gpu/drm/virtio/virtgpu_submit.c index 3d35326dd90406..6580ece6587043 100644 --- a/drivers/gpu/drm/virtio/virtgpu_submit.c +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c @@ -305,8 +305,7 @@ static int virtio_gpu_init_submit_buflist(struct virtio_gpu_submit *submit) if (!exbuf->num_bo_handles) return 0; - bo_handles = kvmalloc_array(exbuf->num_bo_handles, sizeof(*bo_handles), - GFP_KERNEL); + bo_handles = kvmalloc_objs(*bo_handles, exbuf->num_bo_handles); if (!bo_handles) return -ENOMEM; diff --git a/drivers/gpu/drm/xe/Kconfig b/drivers/gpu/drm/xe/Kconfig index 502c7b3c1f16ac..049d2f25d0e603 100644 --- a/drivers/gpu/drm/xe/Kconfig +++ b/drivers/gpu/drm/xe/Kconfig @@ -10,6 +10,7 @@ config DRM_XE # the shmem_readpage() which depends upon tmpfs select SHMEM select TMPFS + select CONFIGFS_FS select DRM_BUDDY select DRM_CLIENT_SELECTION select DRM_KMS_HELPER diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c index e09116265ae95f..1bb484254d6e90 100644 --- a/drivers/gpu/drm/xe/display/xe_fb_pin.c +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c @@ -305,7 +305,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct drm_gem_object *obj, bool is_dpt, const struct intel_fb_pin_params *pin_params) { struct xe_device *xe = to_xe_device(obj->dev); - struct i915_vma *vma = kzalloc(sizeof(*vma), GFP_KERNEL); + struct i915_vma *vma = kzalloc_obj(*vma); struct xe_bo *bo = gem_to_xe_bo(obj); struct xe_validation_ctx ctx; struct drm_exec exec; diff --git a/drivers/gpu/drm/xe/regs/xe_gt_regs.h b/drivers/gpu/drm/xe/regs/xe_gt_regs.h index 650f117c3e135b..1937b9e08d5069 100644 --- a/drivers/gpu/drm/xe/regs/xe_gt_regs.h +++ b/drivers/gpu/drm/xe/regs/xe_gt_regs.h @@ -107,6 +107,7 @@ #define GAMSTLB_CTRL2 XE_REG_MCR(0x4788) #define STLB_SINGLE_BANK_MODE REG_BIT(11) +#define XE2_LMEM_CFG_MCR XE_REG_MCR(0x48b0) #define XE2_LMEM_CFG XE_REG(0x48b0) #define XE2_GAMWALK_CTRL 0x47e4 diff --git a/drivers/gpu/drm/xe/regs/xe_lrc_layout.h b/drivers/gpu/drm/xe/regs/xe_lrc_layout.h index 6f7abc0181b544..a2795aa9fd714b 100644 --- a/drivers/gpu/drm/xe/regs/xe_lrc_layout.h +++ b/drivers/gpu/drm/xe/regs/xe_lrc_layout.h @@ -45,4 +45,7 @@ #define INDIRECT_CTX_RING_START_UDW (0x08 + 1) #define INDIRECT_CTX_RING_CTL (0x0a + 1) +#define CTX_INDIRECT_CTX_OFFSET_MASK REG_GENMASK(15, 6) +#define CTX_INDIRECT_CTX_OFFSET_DEFAULT REG_FIELD_PREP(CTX_INDIRECT_CTX_OFFSET_MASK, 0xd) + #endif diff --git a/drivers/gpu/drm/xe/xe_amc.c b/drivers/gpu/drm/xe/xe_amc.c index edd50bf8261eca..d6fe59669a74ba 100644 --- a/drivers/gpu/drm/xe/xe_amc.c +++ b/drivers/gpu/drm/xe/xe_amc.c @@ -15,9 +15,11 @@ #include "regs/xe_i2c_regs.h" #include "xe_amc.h" +#include "xe_any.h" #include "xe_device.h" #include "xe_i2c.h" #include "xe_mmio.h" +#include "xe_pm.h" /** * DOC: Add-In Management Controller (AMC) @@ -108,11 +110,14 @@ static void xe_amc_work(struct work_struct *work) { const struct amc_request *request = &amc_get_alert_reason; struct xe_amc *amc = from_work(amc, work, work); + struct xe_device *xe = xe_any_to_xe(amc->i2c->drm_dev); u8 alert_reason = AMC_ALERT_UNKNOWN; struct amc_response response; struct i2c_client *client; int ret; + xe_pm_runtime_get(xe); + client = amc->i2c->client[XE_I2C_CLIENT_AMC]; if (IS_ERR_OR_NULL(client)) goto out_reassert_interrupt; @@ -160,12 +165,15 @@ static void xe_amc_work(struct work_struct *work) case AMC_ALERT_OOB_RESET: case AMC_ALERT_CATERR: dev_warn(amc->i2c->drm_dev, "AMC Alert: %s\n", amc_alert[alert_reason]); - xe_device_declare_wedged(i2c_client_to_xe_device(client)); + xe_device_declare_wedged(i2c_client_to_xe_device(client), + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); break; default: dev_warn(amc->i2c->drm_dev, "unknown AMC alert: %d\n", alert_reason); break; } + + xe_pm_runtime_put(xe); } void xe_amc_handle_alert(struct xe_i2c *i2c) diff --git a/drivers/gpu/drm/xe/xe_configfs.h b/drivers/gpu/drm/xe/xe_configfs.h index 10a00d6bbf8f46..d726800de26abd 100644 --- a/drivers/gpu/drm/xe/xe_configfs.h +++ b/drivers/gpu/drm/xe/xe_configfs.h @@ -14,7 +14,6 @@ struct pci_dev; -#if IS_ENABLED(CONFIG_CONFIGFS_FS) int xe_configfs_init(void); void xe_configfs_exit(void); void xe_configfs_check_device(struct pci_dev *pdev); @@ -36,34 +35,5 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev); bool xe_configfs_admin_only_pf(struct pci_dev *pdev); #endif -#else -static inline int xe_configfs_init(void) { return 0; } -static inline void xe_configfs_exit(void) { } -static inline void xe_configfs_check_device(struct pci_dev *pdev) { } -static inline bool xe_configfs_get_survivability_mode(struct pci_dev *pdev) { return false; } -static inline bool xe_configfs_primary_gt_allowed(struct pci_dev *pdev) { return true; } -static inline bool xe_configfs_media_gt_allowed(struct pci_dev *pdev) { return true; } -static inline u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev) { return U64_MAX; } -static inline bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev) { return false; } -static inline bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev) { return true; } -static inline u32 xe_configfs_get_migrate_ulls_period_ms(struct pci_dev *pdev) { return 5; } -static inline bool xe_configfs_get_disable_vram_page_offline(struct pci_dev *pdev) { return false; } -static inline u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) { return 0; } -static inline u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, - enum xe_engine_class class, - const u32 **cs) { return 0; } -#ifdef CONFIG_PCI_IOV -static inline unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev) -{ - return xe_modparam.max_vfs; -} -static inline bool xe_configfs_admin_only_pf(struct pci_dev *pdev) -{ - return XE_DEFAULT_ADMIN_ONLY_PF; -} -#endif -#endif #endif diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index 7e6027f49a4ca8..c41533644c928a 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -690,6 +690,16 @@ static int xe_device_vram_alloc(struct xe_device *xe) return 0; } +static void wedged_work(struct work_struct *work); +static void xe_device_wedged_fini(struct drm_device *drm, void *arg); + +static int xe_device_wedged_init(struct xe_device *xe) +{ + INIT_WORK(&xe->wedged.work, wedged_work); + + return drmm_add_action_or_reset(&xe->drm, xe_device_wedged_fini, xe); +} + /** * xe_device_probe_early: Device early probe * @xe: xe device instance @@ -758,6 +768,10 @@ int xe_device_probe_early(struct xe_device *xe) if (err) return err; + err = xe_device_wedged_init(xe); + if (err) + return err; + return 0; } ALLOW_ERROR_INJECTION(xe_device_probe_early, ERRNO); /* See xe_pci_probe() */ @@ -888,7 +902,9 @@ int xe_device_probe(struct xe_device *xe) xe_uid_probe(xe); - xe_pat_init_early(xe); + err = xe_pat_init_early(xe); + if (err) + return err; err = xe_sriov_init(xe); if (err) @@ -1088,10 +1104,6 @@ int xe_device_probe(struct xe_device *xe) detect_preproduction_hw(xe); - err = drmm_add_action_or_reset(&xe->drm, xe_device_wedged_fini, xe); - if (err) - goto err_unregister_display; - /* * Process and log any errors detected by hardware. Possible results can * include declaring the device as wedged, which must be done only after @@ -1371,16 +1383,12 @@ u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64 address) * firmware and restore device to normal operation. */ -/** - * xe_device_set_wedged_method - Set wedged recovery method - * @xe: xe device instance - * @method: recovery method to set - * - * Set wedged recovery method to be sent in drm wedged uevent. - */ -void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method) +static void wedged_work(struct work_struct *work) { - xe->wedged.method = method; + struct xe_device *xe = container_of(work, struct xe_device, wedged.work); + + /* Notify userspace of wedged device */ + drm_dev_wedged_event(&xe->drm, xe->wedged.method, NULL); } #define WEDGED_URL "https://docs.kernel.org/gpu/drm-uapi.html#device-wedging" @@ -1389,11 +1397,10 @@ void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method) /** * xe_device_declare_wedged - Declare device wedged * @xe: xe device instance + * @method: method(s) to be used for recovery * * This is a final state that can only be cleared with the recovery method - * specified in the drm wedged uevent. The method can be set using - * xe_device_set_wedged_method before declaring the device as wedged. If no method - * is set, reprobe (unbind/re-bind) will be sent by default. + * specified in the drm wedged uevent. * * In this state every IOCTL will be blocked so the GT cannot be used. * In general it will be called upon any critical error such as gt reset @@ -1404,7 +1411,7 @@ void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method) * snapshot capture. In this mode, GT reset won't be attempted so the state of * the issue is preserved for further debugging. */ -void xe_device_declare_wedged(struct xe_device *xe) +void xe_device_declare_wedged(struct xe_device *xe, unsigned long method) { struct xe_gt *gt; u8 id; @@ -1423,26 +1430,21 @@ void xe_device_declare_wedged(struct xe_device *xe) "For recovery procedure, refer to %s\n" "Please file a _new_ bug report at %s\n", WEDGED_URL, XE_BUG_URL); - } - for_each_gt(gt, xe, id) - xe_gt_declare_wedged(gt); + for_each_initialized_gt(gt, xe, id) + xe_gt_declare_wedged(gt); - if (xe_device_wedged(xe)) { /* * XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET is intended for debugging * hangs, so wedge the device with 'none' recovery method and have * it available to the user for debugging. */ if (xe->wedged.mode == XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET) - xe_device_set_wedged_method(xe, DRM_WEDGE_RECOVERY_NONE); - /* If no wedge recovery method is set, use default */ - else if (!xe->wedged.method) - xe_device_set_wedged_method(xe, DRM_WEDGE_RECOVERY_REBIND | - DRM_WEDGE_RECOVERY_BUS_RESET); - - /* Notify userspace of wedged device */ - drm_dev_wedged_event(&xe->drm, xe->wedged.method, NULL); + xe->wedged.method = DRM_WEDGE_RECOVERY_NONE; + else + xe->wedged.method = method; + + schedule_work(&xe->wedged.work); } } diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h index 6d3d6d5eba298e..3ce1481d0e573b 100644 --- a/drivers/gpu/drm/xe/xe_device.h +++ b/drivers/gpu/drm/xe/xe_device.h @@ -139,6 +139,10 @@ static inline bool xe_device_uc_enabled(struct xe_device *xe) for_each_gt((gt__), (tile__)->xe, (id__)) \ for_each_if((gt__)->tile == (tile__)) +#define for_each_initialized_gt(gt__, xe__, id__) \ + for_each_gt((gt__), (xe__), (id__)) \ + for_each_if(READ_ONCE((gt__)->initialized)) + static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt) { return >->pm.fw; @@ -260,8 +264,7 @@ static inline bool xe_debug_page_size_mode_is_mixed(struct xe_device *xe) } #endif -void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method); -void xe_device_declare_wedged(struct xe_device *xe); +void xe_device_declare_wedged(struct xe_device *xe, unsigned long method); int xe_device_validate_wedged_mode(struct xe_device *xe, unsigned int mode); const char *xe_wedged_mode_to_string(enum xe_wedged_mode mode); diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 41f703a8791696..5aa52975ebb46a 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -227,6 +227,8 @@ struct xe_device { u8 has_sriov:1; /** @info.has_sysctrl: Supports System Controller */ u8 has_sysctrl:1; + /** @info.has_temp_sentinel: Device has temperature-unavailable sentinels */ + u8 has_temp_sentinel:1; /** @info.has_usm: Device has unified shared memory support */ u8 has_usm:1; /** @info.has_64bit_timestamp: Device supports 64-bit timestamps */ @@ -560,6 +562,8 @@ struct xe_device { unsigned long method; /** @wedged.inconsistent_reset: Inconsistent reset policy state between GTs */ bool inconsistent_reset; + /** @wedged.work: Worker to defer non-atomic calls */ + struct work_struct work; } wedged; /** @devres_group: devres group */ diff --git a/drivers/gpu/drm/xe/xe_drm_ras.c b/drivers/gpu/drm/xe/xe_drm_ras.c index 7f3695707611c6..30cf40ee5fe4d6 100644 --- a/drivers/gpu/drm/xe/xe_drm_ras.c +++ b/drivers/gpu/drm/xe/xe_drm_ras.c @@ -16,6 +16,17 @@ static const char * const error_components[] = DRM_XE_RAS_ERROR_COMPONENT_NAMES; static const char * const error_severity[] = DRM_XE_RAS_ERROR_SEVERITY_NAMES; +static bool drm_ras_counter_is_valid(u32 severity, u32 component) +{ + if (!in_range(severity, DRM_XE_RAS_ERR_SEV_CORRECTABLE, DRM_XE_RAS_ERR_SEV_MAX)) + return false; + + if (!in_range(component, DRM_XE_RAS_ERR_COMP_CORE_COMPUTE, DRM_XE_RAS_ERR_COMP_MAX - 1)) + return false; + + return true; +} + static int query_error_counter(struct xe_device *xe, enum drm_xe_ras_error_severity severity, u32 error_id, const char **name, u32 *val) @@ -231,7 +242,7 @@ static int register_nodes(struct xe_device *xe) void xe_drm_ras_event(struct xe_device *xe, u32 component, u32 severity, u32 value) { struct xe_drm_ras *ras = &xe->ras; - struct xe_drm_ras_counter *info = ras->info[severity]; + struct xe_drm_ras_counter *info; struct drm_ras_node *node; int ret; @@ -239,7 +250,11 @@ void xe_drm_ras_event(struct xe_device *xe, u32 component, u32 severity, u32 val if (!xe->info.has_drm_ras) return; + if (!drm_ras_counter_is_valid(severity, component)) + return; + node = &ras->node[severity]; + info = ras->info[severity]; if (!info || !info[component].name) return; diff --git a/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h b/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h index 63d9bf92583c55..78ef2e8ded4f36 100644 --- a/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h +++ b/drivers/gpu/drm/xe/xe_gpu_scheduler_types.h @@ -47,7 +47,10 @@ struct xe_gpu_scheduler { const struct xe_sched_backend_ops *ops; /** @msgs: list of messages to be processed in @work_process_msg */ struct list_head msgs; - /** @msg_lock: Message lock */ + /** + * @msg_lock: Protects @msgs and guc->suspend_pending (indicates a + * suspend message is in flight) of exec queues on this scheduler. + */ spinlock_t msg_lock; /** @work_process_msg: processes messages */ struct work_struct work_process_msg; diff --git a/drivers/gpu/drm/xe/xe_gsc.c b/drivers/gpu/drm/xe/xe_gsc.c index 524ac56bdcc7b0..2bbe0f20ff8d33 100644 --- a/drivers/gpu/drm/xe/xe_gsc.c +++ b/drivers/gpu/drm/xe/xe_gsc.c @@ -340,7 +340,8 @@ static int gsc_er_complete(struct xe_gt *gt) * declare the device as wedged. */ xe_gt_err(gt, "GSC ER timed out!\n"); - xe_device_declare_wedged(gt_to_xe(gt)); + xe_device_declare_wedged(gt_to_xe(gt), + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); return -EIO; } diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c index 775c826b68b424..286aee5775c0dd 100644 --- a/drivers/gpu/drm/xe/xe_gt.c +++ b/drivers/gpu/drm/xe/xe_gt.c @@ -175,6 +175,7 @@ static void xe_gt_enable_comp_1wcoh(struct xe_gt *gt) } static void gt_reset_worker(struct work_struct *w); +static void gt_wedge_worker(struct work_struct *w); static int emit_job_sync(struct xe_exec_queue *q, struct xe_bb *bb, long timeout_jiffies, bool force_reset) @@ -546,6 +547,8 @@ int xe_gt_init_early(struct xe_gt *gt) xe_gt_mcr_init_early(gt); xe_pat_init(gt); + INIT_WORK(>->reset.worker, gt_reset_worker); + INIT_WORK(>->wedge.worker, gt_wedge_worker); return 0; } @@ -630,8 +633,26 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt) return 0; } +static void gt_worker_disable(void *arg) +{ + struct xe_gt *gt = arg; + + WRITE_ONCE(gt->initialized, false); + + if (disable_work_sync(>->reset.worker)) + /* + * If gt_reset_worker was halted from executing, take care of + * releasing the rpm reference here. + */ + xe_pm_runtime_put(gt_to_xe(gt)); + + if (disable_work_sync(>->wedge.worker)) + xe_pm_runtime_put(gt_to_xe(gt)); +} + static int gt_init_with_all_forcewake(struct xe_gt *gt) { + struct xe_device *xe = gt_to_xe(gt); int err; CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL); @@ -692,11 +713,15 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt) xe_gt_apply_ccs_mode(gt); } - if (IS_SRIOV_PF(gt_to_xe(gt)) && xe_gt_is_main_type(gt)) - xe_lmtt_init_hw(>_to_tile(gt)->sriov.pf.lmtt); - - if (IS_SRIOV_PF(gt_to_xe(gt))) + if (IS_SRIOV_PF(gt_to_xe(gt))) { + xe_lmtt_init_hw(gt); xe_gt_sriov_pf_init_hw(gt); + } + + /* Last action registered here so devres drains resets before teardown */ + err = devm_add_action_or_reset(xe->drm.dev, gt_worker_disable, gt); + if (err) + return err; return 0; } @@ -706,12 +731,7 @@ static void xe_gt_fini(void *arg) struct xe_gt *gt = arg; int i; - if (disable_work_sync(>->reset.worker)) - /* - * If gt_reset_worker was halted from executing, take care of - * releasing the rpm reference here. - */ - xe_pm_runtime_put(gt_to_xe(gt)); + gt_worker_disable(gt); for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i) xe_hw_fence_irq_finish(>->fence_irq[i]); @@ -724,8 +744,6 @@ int xe_gt_init(struct xe_gt *gt) int err; int i; - INIT_WORK(>->reset.worker, gt_reset_worker); - for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i) { gt->ring_ops[i] = xe_ring_ops_get(gt, i); xe_hw_fence_irq_init(>->fence_irq[i]); @@ -754,8 +772,10 @@ int xe_gt_init(struct xe_gt *gt) xe_force_wake_init_engines(gt, gt_to_fw(gt)); err = gt_init_with_all_forcewake(gt); - if (err) + if (err) { + gt_worker_disable(gt); return err; + } xe_gt_record_user_engines(gt); @@ -769,6 +789,8 @@ int xe_gt_init(struct xe_gt *gt) return err; } + /* Must be last */ + WRITE_ONCE(gt->initialized, true); return 0; } @@ -894,11 +916,10 @@ static int do_gt_restart(struct xe_gt *gt) if (err) return err; - if (IS_SRIOV_PF(gt_to_xe(gt)) && xe_gt_is_main_type(gt)) - xe_lmtt_init_hw(>_to_tile(gt)->sriov.pf.lmtt); - - if (IS_SRIOV_PF(gt_to_xe(gt))) + if (IS_SRIOV_PF(gt_to_xe(gt))) { + xe_lmtt_init_hw(gt); xe_gt_sriov_pf_init_hw(gt); + } xe_mocs_init(gt); @@ -986,7 +1007,8 @@ static void gt_reset_worker(struct work_struct *w) err_fail: xe_log_err_fatal(gt, GT, err, "reset failed\n"); - xe_device_declare_wedged(gt_to_xe(gt)); + xe_device_declare_wedged(gt_to_xe(gt), + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); err_pm_put: xe_pm_runtime_put(gt_to_xe(gt)); } @@ -1189,6 +1211,15 @@ struct xe_hw_engine *xe_gt_any_hw_engine(struct xe_gt *gt) return NULL; } +static void gt_wedge_worker(struct work_struct *w) +{ + struct xe_gt *gt = container_of(w, typeof(*gt), wedge.worker); + + xe_uc_declare_wedged(>->uc); + xe_tlb_inval_reset(>->tlb_inval); + xe_pm_runtime_put(gt_to_xe(gt)); +} + /** * xe_gt_declare_wedged() - Declare GT wedged * @gt: the GT object @@ -1198,8 +1229,12 @@ struct xe_hw_engine *xe_gt_any_hw_engine(struct xe_gt *gt) */ void xe_gt_declare_wedged(struct xe_gt *gt) { - xe_gt_assert(gt, gt_to_xe(gt)->wedged.mode); + struct xe_device *xe = gt_to_xe(gt); - xe_uc_declare_wedged(>->uc); - xe_tlb_inval_reset(>->tlb_inval); + xe_gt_assert(gt, xe->wedged.mode); + xe_uc_reset_prepare(>->uc); + + xe_pm_runtime_get_noresume(xe); + if (!queue_work(gt->ordered_wq, >->wedge.worker)) + xe_pm_runtime_put(xe); } diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c index 37899fcf5b227e..28ec83bb8100d4 100644 --- a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c +++ b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c @@ -1462,7 +1462,7 @@ static void vf_post_migration_recovery(struct xe_gt *gt) fail: vf_post_migration_abort(gt); xe_gt_sriov_err(gt, "migration recovery failed (%pe)\n", ERR_PTR(err)); - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); return; queue: diff --git a/drivers/gpu/drm/xe/xe_gt_types.h b/drivers/gpu/drm/xe/xe_gt_types.h index 62891134645549..c00a7c171f8026 100644 --- a/drivers/gpu/drm/xe/xe_gt_types.h +++ b/drivers/gpu/drm/xe/xe_gt_types.h @@ -233,6 +233,12 @@ struct xe_gt { struct work_struct worker; } reset; + /** @wedge: state for GT wedge */ + struct { + /** @wedge.worker: worker for GT wedge to be done async */ + struct work_struct worker; + } wedge; + /** @tlb_inval: TLB invalidation state */ struct xe_tlb_inval tlb_inval; @@ -419,6 +425,9 @@ struct xe_gt { /** @eu_stall: EU stall counters subsystem per gt info */ struct xe_eu_stall_gt *eu_stall; + + /** @initialized: GT is initialized */ + bool initialized; }; #endif diff --git a/drivers/gpu/drm/xe/xe_guc.c b/drivers/gpu/drm/xe/xe_guc.c index 763a3dbca60626..957120db8fdc41 100644 --- a/drivers/gpu/drm/xe/xe_guc.c +++ b/drivers/gpu/drm/xe/xe_guc.c @@ -1840,7 +1840,6 @@ void xe_guc_declare_wedged(struct xe_guc *guc) { xe_gt_assert(guc_to_gt(guc), guc_to_xe(guc)->wedged.mode); - xe_guc_reset_prepare(guc); xe_guc_ct_stop(&guc->ct); xe_guc_submit_wedge(guc); } diff --git a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h index d27826b36649f9..74b711abe2572b 100644 --- a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h +++ b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h @@ -52,7 +52,10 @@ struct xe_guc_exec_queue { u16 id; /** @suspend_wait: wait queue used to wait on pending suspends */ wait_queue_head_t suspend_wait; - /** @suspend_pending: a suspend of the exec_queue is pending */ + /** + * @suspend_pending: a suspend of the exec_queue is pending. + * Protected by @sched.msg_lock. + */ bool suspend_pending; /** * @suspend_count: Reference count of active suspend requests. The diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c index 0b231228bde8b7..01f79f8883ba68 100644 --- a/drivers/gpu/drm/xe/xe_guc_submit.c +++ b/drivers/gpu/drm/xe/xe_guc_submit.c @@ -1453,7 +1453,7 @@ static bool guc_submit_hint_wedged(struct xe_guc *guc) if (xe_device_wedged(xe)) return true; - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); return true; } @@ -1599,6 +1599,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job) int err = -ETIME; pid_t pid = -1; bool wedged = false, wedge_device = false, skip_timeout_check; + int idx; xe_gt_assert(guc_to_gt(guc), !exec_queue_destroyed(q)); @@ -1614,6 +1615,11 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job) vf_recovery(guc)) return DRM_GPU_SCHED_STAT_NO_HANG; + if (!drm_dev_enter(&xe->drm, &idx)) { + xe_sched_job_set_error(job, -ENODEV); + return DRM_GPU_SCHED_STAT_NO_HANG; + } + /* Kill the run_job entry point */ if (xe_exec_queue_is_multi_queue(q)) xe_guc_exec_queue_group_stop(q); @@ -1780,12 +1786,14 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job) } if (wedge_device) - xe_device_declare_wedged(gt_to_xe(q->gt)); + xe_device_declare_wedged(gt_to_xe(q->gt), + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); /* * We want the job added back to the pending list so it gets freed; this * is what DRM_GPU_SCHED_STAT_NO_HANG does. */ + drm_dev_exit(idx); return DRM_GPU_SCHED_STAT_NO_HANG; rearm: @@ -1799,6 +1807,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job) else xe_sched_submission_start(sched); handle_vf_resume: + drm_dev_exit(idx); return DRM_GPU_SCHED_STAT_NO_HANG; } @@ -1935,16 +1944,11 @@ static void __guc_exec_queue_process_msg_set_sched_props(struct xe_sched_msg *ms kfree(msg); } -static void __suspend_fence_signal(struct xe_exec_queue *q) +static void suspend_wait_wake(struct xe_exec_queue *q) { struct xe_guc *guc = exec_queue_to_guc(q); struct xe_device *xe = guc_to_xe(guc); - if (!q->guc->suspend_pending) - return; - - WRITE_ONCE(q->guc->suspend_pending, false); - /* * We use a GuC shared wait queue for VFs because the VF resfix start * interrupt must be able to wake all instances of suspend_wait. This @@ -1957,6 +1961,15 @@ static void __suspend_fence_signal(struct xe_exec_queue *q) wake_up(&q->guc->suspend_wait); } +static void __suspend_fence_signal(struct xe_exec_queue *q) +{ + if (!q->guc->suspend_pending) + return; + + WRITE_ONCE(q->guc->suspend_pending, false); + suspend_wait_wake(q); +} + static void suspend_fence_signal(struct xe_exec_queue *q) { struct xe_guc *guc = exec_queue_to_guc(q); @@ -2210,7 +2223,13 @@ static void guc_exec_queue_kill(struct xe_exec_queue *q) { trace_xe_exec_queue_kill(q); set_exec_queue_killed(q); - __suspend_fence_signal(q); + /* + * Do not signal the suspend fence here, the queue may still be running + * on the hardware. Only wake any suspend waiter so it observes the + * killed state instead of waiting out the full timeout, suspend_pending + * stays set until the queue is torn down. + */ + suspend_wait_wake(q); xe_guc_exec_queue_trigger_cleanup(q); } @@ -2399,7 +2418,12 @@ static bool __guc_exec_queue_resume(struct xe_exec_queue *q) bool last; xe_sched_msg_lock(sched); - xe_gt_assert(guc_to_gt(guc), !ge->suspend_pending); + /* + * A killed, banned or wedged queue keeps suspend_pending set until it + * is torn down, so only assert the flag is clear otherwise. + */ + xe_gt_assert(guc_to_gt(guc), !ge->suspend_pending || + exec_queue_killed_or_banned_or_wedged(q)); xe_gt_assert(guc_to_gt(guc), ge->suspend_count > 0); last = (--ge->suspend_count == 0); if (last) { @@ -2469,8 +2493,10 @@ static void guc_exec_queue_suspend_timeout_ban(struct xe_exec_queue *q) /* * The GuC failed to respond to the suspend within the timeout. This is * not recoverable for this context, so ban it and tear it down via - * cleanup rather than leave it suspended forever. __suspend_fence_signal - * clears suspend_pending and wakes any waiter. + * cleanup rather than leave it suspended forever. The suspend fence is + * not signalled here, the queue may still be running on the hardware, + * so suspend_pending stays set until teardown. The waiter that timed + * out is the caller, so no wake up is needed either. * * @q is the primary here; it owns the group's GuC context, so a failure * to suspend it wedges the whole group. Ban and tear down the entire @@ -2478,11 +2504,9 @@ static void guc_exec_queue_suspend_timeout_ban(struct xe_exec_queue *q) */ if (xe_exec_queue_is_multi_queue(q)) { set_exec_queue_group_banned(q); - __suspend_fence_signal(q); xe_guc_exec_queue_group_trigger_cleanup(q); } else { set_exec_queue_banned(q); - __suspend_fence_signal(q); xe_guc_exec_queue_trigger_cleanup(q); } } @@ -2505,9 +2529,9 @@ static int guc_exec_queue_wait_suspend_done(struct xe_exec_queue *q, bool blocki int ret; /* - * Likely don't need to check exec_queue_killed() as we clear - * suspend_pending upon kill but to be paranoid but races in which - * suspend_pending is set after kill also check kill here. + * A kill does not clear suspend_pending, the queue may still be running + * on the hardware, so exec_queue_killed() is what ends the wait in that + * case and the queue is torn down asynchronously. */ #define WAIT_COND \ (!READ_ONCE(q->guc->suspend_pending) || exec_queue_killed(q) || \ @@ -2716,10 +2740,12 @@ static void guc_exec_queue_stop(struct xe_guc *guc, struct xe_exec_queue *q) if (exec_queue_destroyed(q)) do_destroy = true; } + xe_sched_msg_lock(sched); if (q->guc->suspend_pending) { set_exec_queue_suspended(q); suspend_fence_signal(q); } + xe_sched_msg_unlock(sched); atomic_and(EXEC_QUEUE_STATE_WEDGED | EXEC_QUEUE_STATE_BANNED | EXEC_QUEUE_STATE_KILLED | EXEC_QUEUE_STATE_DESTROYED | EXEC_QUEUE_STATE_SUSPENDED, @@ -3333,33 +3359,50 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q, smp_wmb(); wake_up_all(&guc->ct.wq); } else { + bool was_pending; + xe_gt_assert(guc_to_gt(guc), runnable_state == 0); xe_gt_assert(guc_to_gt(guc), exec_queue_pending_disable(q)); - if (q->guc->suspend_pending) { + /* + * A TDR stops the scheduler, which can trap a queued SUSPEND + * message, and then issues a disable of its own. suspend_pending + * is still set in that case, so only attribute this SCHED_DONE + * to a suspend if the SUSPEND message actually ran, i.e. it + * marked the queue suspended before disabling scheduling. The + * trapped message completes the suspend once submission + * restarts. + */ + xe_sched_msg_lock(&q->guc->sched); + was_pending = q->guc->suspend_pending && exec_queue_suspended(q); + if (was_pending) { clear_exec_queue_pending_disable(q); suspend_fence_signal(q); - } else { - if (exec_queue_banned(q)) { - smp_wmb(); - wake_up_all(&guc->ct.wq); - } - if (exec_queue_destroyed(q)) { - /* - * Make sure to clear the pending_disable only - * after sampling the destroyed state. We want - * to ensure we don't trigger the unregister too - * early with something intending to only - * disable scheduling. The caller doing the - * destroy must wait for an ongoing - * pending_disable before marking as destroyed. - */ - clear_exec_queue_pending_disable(q); + } + xe_sched_msg_unlock(&q->guc->sched); + + if (!was_pending) { + /* + * Make sure to clear the pending_disable only after + * sampling the destroyed state. We want to ensure we + * don't trigger the unregister too early with something + * intending to only disable scheduling. The caller + * doing the destroy must wait for an ongoing + * pending_disable before marking as destroyed. + */ + bool destroyed = exec_queue_destroyed(q); + + clear_exec_queue_pending_disable(q); + if (destroyed) deregister_exec_queue(guc, q); - } else { - clear_exec_queue_pending_disable(q); - } } + + /* + * Wake after pending_disable is cleared, not before, so waiters + * such as the TDR see the updated state on the first re-check. + */ + smp_wmb(); + wake_up_all(&guc->ct.wq); } } @@ -3561,7 +3604,7 @@ int xe_guc_uncorrectable_error_handler(struct xe_guc *guc, u32 *msg, u32 len) guc_id = msg[0]; if (guc_id == GUC_ID_UNKNOWN) { - xe_gt_err(gt, "GuC: Uncorrectable local error with unknown GuC id\n"); + xe_gt_err_ratelimited(gt, "GuC: Uncorrectable local error with unknown GuC id\n"); return 0; } @@ -3569,9 +3612,19 @@ int xe_guc_uncorrectable_error_handler(struct xe_guc *guc, u32 *msg, u32 len) if (unlikely(!q)) return -EPROTO; - xe_gt_err(gt, - "GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x", - guc_id, xe_hw_engine_class_to_str(q->class), q->logical_mask); + /* + * On CRI, the hardware cannot distinguish GT translation faults + * from true RAS conditions. Demote to debug to avoid false + * positive hardware error logs. + */ + if (gt_to_xe(gt)->info.platform == XE_CRESCENTISLAND) + xe_gt_dbg(gt, + "GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x", + guc_id, xe_hw_engine_class_to_str(q->class), q->logical_mask); + else + xe_gt_err(gt, + "GuC: Uncorrectable local error! guc_id=%d class=%s, logical_mask=0x%x", + guc_id, xe_hw_engine_class_to_str(q->class), q->logical_mask); trace_xe_guc_uncorrectable_error(q); diff --git a/drivers/gpu/drm/xe/xe_hw_engine.c b/drivers/gpu/drm/xe/xe_hw_engine.c index 9680d2a5adec7e..f7d5d1101c6e0b 100644 --- a/drivers/gpu/drm/xe/xe_hw_engine.c +++ b/drivers/gpu/drm/xe/xe_hw_engine.c @@ -275,11 +275,22 @@ static const struct engine_info engine_infos[] = { static void hw_engine_fini(void *arg) { struct xe_hw_engine *hwe = arg; + struct xe_gt *gt = hwe->gt; + + if (gt) { + struct xe_device *xe = gt_to_xe(gt); + unsigned long flags; - if (hwe->exl_port) - xe_execlist_port_destroy(hwe->exl_port); + if (hwe->exl_port) + xe_execlist_port_destroy(hwe->exl_port); - hwe->gt = NULL; + spin_lock_irqsave(&xe->irq.lock, flags); + hwe->name = NULL; + hwe->gt = NULL; + spin_unlock_irqrestore(&xe->irq.lock, flags); + } else { + hwe->name = NULL; + } } /** diff --git a/drivers/gpu/drm/xe/xe_hw_error.c b/drivers/gpu/drm/xe/xe_hw_error.c index 5f2abc9485ff5c..f726179c22e38d 100644 --- a/drivers/gpu/drm/xe/xe_hw_error.c +++ b/drivers/gpu/drm/xe/xe_hw_error.c @@ -14,6 +14,7 @@ #include "xe_drm_ras.h" #include "xe_hw_error.h" #include "xe_mmio.h" +#include "xe_pm.h" #include "xe_survivability_mode.h" #define GT_HW_ERROR_MAX_ERR_BITS 16 @@ -170,6 +171,7 @@ static void csc_hw_error_work(struct work_struct *work) struct xe_tile *tile = container_of(work, typeof(*tile), csc_hw_error_work); struct xe_device *xe = tile_to_xe(tile); + guard(xe_pm_runtime)(xe); xe_survivability_mode_runtime_enable(xe); } diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c index 5edeac961ec33e..20c1cfffc5a03c 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -104,6 +104,13 @@ enum sensor_attr_power { /* Index of memory controller in READ_THERMAL_DATA output */ #define TEMP_INDEX_MCTRL 2 +/* Mailbox sentinel reported for an unavailable temperature sensor */ +#define TEMP_MBX_INVALID 0xFF + +/* Mailbox temperature is sign-magnitude: bit 7 sign, bits 6:0 magnitude. */ +#define TEMP_MBX_SIGN BIT(7) +#define TEMP_MBX_MAG GENMASK(6, 0) + /* Maximum characters in hwmon label name */ #define MAX_LABEL_SIZE 16 @@ -134,13 +141,17 @@ struct xe_hwmon_thermal_info { union { /** @limit: temperatures limits */ u8 limit[TEMP_LIMIT_MAX]; - /** @data: temperature limits in dwords */ - u32 data[DIV_ROUND_UP(TEMP_LIMIT_MAX, sizeof(u32))]; + /** @data: temperature limits as little-endian dwords */ + __le32 data[DIV_ROUND_UP(TEMP_LIMIT_MAX, sizeof(u32))]; }; /** @count: no of temperature sensors available for the platform */ u8 count; - /** @value: signed value from each sensor */ - s8 value[U8_MAX]; + union { + /** @value: per-sensor raw mailbox temperature; bit7=sign, bits6:0=magnitude */ + u8 value[U8_MAX + 1]; + /** @dword: sensor values as little-endian dwords, u32-aligned for pcode reads */ + __le32 dword[DIV_ROUND_UP(U8_MAX + 1, sizeof(u32))]; + }; /** @vram_label: vram label names */ char vram_label[MAX_VRAM_CHANNELS][MAX_LABEL_SIZE]; }; @@ -165,8 +176,8 @@ struct xe_hwmon { struct xe_hwmon_energy_info ei[CHANNEL_MAX]; /** @fi: Fan info for fanN_input */ struct xe_hwmon_fan_info fi[FAN_MAX]; - /** @boot_power_limit_read: is boot power limits read */ - bool boot_power_limit_read; + /** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */ + bool read_power_limit_from_pcode[CHANNEL_MAX]; /** @pl1_on_boot: power limit PL1 on boot */ u32 pl1_on_boot[CHANNEL_MAX]; /** @pl2_on_boot: power limit PL2 on boot */ @@ -175,9 +186,9 @@ struct xe_hwmon { struct xe_hwmon_thermal_info temp; }; -static inline int prepare_power_limit_param2(const struct xe_hwmon *hwmon) +static inline int prepare_power_limit_param2(const struct xe_hwmon *hwmon, int channel) { - if (hwmon->boot_power_limit_read) { + if (hwmon->read_power_limit_from_pcode[channel]) { if (hwmon->xe->info.platform >= XE_CRESCENTISLAND) return READ_PL_ACCEPTED; else @@ -198,7 +209,8 @@ static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 att (channel == CHANNEL_CARD) ? READ_PSYSGPU_POWER_LIMIT : READ_PACKAGE_POWER_LIMIT, - prepare_power_limit_param2(hwmon)), &val0, &val1); + prepare_power_limit_param2(hwmon, channel)), + &val0, &val1); if (ret) { drm_dbg(&hwmon->xe->drm, "read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n", @@ -213,14 +225,14 @@ static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 att else if (attr == PL2_HWMON_ATTR) *uval = (val1 & PWR_LIM_EN) ? val1 : 0; else if (attr == hwmon_power_label) - *uval = (val0 & PWR_LIM_EN) ? 1 : (val1 & PWR_LIM_EN) ? 1 : 0; + *uval = (val0 | val1) & PWR_LIM_EN; else *uval = 0; return ret; } -static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr, u8 channel, +static int xe_hwmon_pcode_rmw_power_limit(struct xe_hwmon *hwmon, u32 attr, u8 channel, u32 clr, u32 set) { struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); @@ -231,10 +243,13 @@ static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr (channel == CHANNEL_CARD) ? READ_PSYSGPU_POWER_LIMIT : READ_PACKAGE_POWER_LIMIT, - prepare_power_limit_param2(hwmon)), &val0, &val1); - if (ret) - drm_dbg(&hwmon->xe->drm, "read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n", + prepare_power_limit_param2(hwmon, channel)), + &val0, &val1); + if (ret) { + drm_err(&hwmon->xe->drm, "read failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n", channel, val0, val1, ret); + return ret; + } if (attr == PL1_HWMON_ATTR) val0 = (val0 & ~clr) | set; @@ -248,9 +263,36 @@ static int xe_hwmon_pcode_rmw_power_limit(const struct xe_hwmon *hwmon, u32 attr WRITE_PSYSGPU_POWER_LIMIT : WRITE_PACKAGE_POWER_LIMIT, 0), val0, val1, PCODE_DEFAULT_TIMEOUT_MS); - if (ret) + if (ret) { drm_dbg(&hwmon->xe->drm, "write failed ch %d val0 0x%08x, val1 0x%08x, ret %d\n", channel, val0, val1, ret); + return ret; + } + + /* Read from pcode once it holds a driver-written limit */ + if (!hwmon->read_power_limit_from_pcode[channel]) + hwmon->read_power_limit_from_pcode[channel] = true; + + return 0; +} + +static int xe_hwmon_pcode_set_default_power_limits(struct xe_hwmon *hwmon) +{ + int ret = 0; + + ret |= xe_hwmon_pcode_rmw_power_limit(hwmon, PL1_HWMON_ATTR, CHANNEL_CARD, + PWR_LIM | PWR_LIM_TIME, + hwmon->pl1_on_boot[CHANNEL_CARD]); + ret |= xe_hwmon_pcode_rmw_power_limit(hwmon, PL1_HWMON_ATTR, CHANNEL_PKG, + PWR_LIM | PWR_LIM_TIME, + hwmon->pl1_on_boot[CHANNEL_PKG]); + ret |= xe_hwmon_pcode_rmw_power_limit(hwmon, PL2_HWMON_ATTR, CHANNEL_CARD, + PWR_LIM | PWR_LIM_TIME, + hwmon->pl2_on_boot[CHANNEL_CARD]); + ret |= xe_hwmon_pcode_rmw_power_limit(hwmon, PL2_HWMON_ATTR, CHANNEL_PKG, + PWR_LIM | PWR_LIM_TIME, + hwmon->pl2_on_boot[CHANNEL_PKG]); + return ret; } @@ -394,7 +436,9 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, u32 attr, int channe if (hwmon->xe->info.has_mbx_power_limits) { drm_dbg(&hwmon->xe->drm, "disabling %s on channel %d\n", PWR_ATTR_TO_STR(attr), channel); - xe_hwmon_pcode_rmw_power_limit(hwmon, attr, channel, PWR_LIM_EN, 0); + ret = xe_hwmon_pcode_rmw_power_limit(hwmon, attr, channel, PWR_LIM_EN, 0); + if (ret) + goto unlock; xe_hwmon_pcode_read_power_limit(hwmon, attr, channel, ®_val); } else { reg_val = xe_mmio_rmw32(mmio, rapl_limit, PWR_LIM_EN, 0); @@ -679,15 +723,19 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a mutex_lock(&hwmon->hwmon_lock); - if (hwmon->xe->info.has_mbx_power_limits) - xe_hwmon_pcode_rmw_power_limit(hwmon, power_attr, channel, PWR_LIM_TIME, rxy); - else + ret = count; + if (hwmon->xe->info.has_mbx_power_limits) { + ret = xe_hwmon_pcode_rmw_power_limit(hwmon, power_attr, channel, PWR_LIM_TIME, rxy); + if (!ret) + ret = count; + } else { r = xe_mmio_rmw32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel), PWR_LIM_TIME, rxy); + } mutex_unlock(&hwmon->hwmon_lock); - return count; + return ret; } /* PSYS PL1 */ @@ -786,16 +834,17 @@ static const struct hwmon_channel_info * const hwmon_info[] = { static int xe_hwmon_pcode_read_thermal_info(struct xe_hwmon *hwmon) { struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); - u32 config = 0; + u32 config = 0, data0 = 0, data1 = 0; int ret; ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_LIMITS, 0), - &hwmon->temp.data[0], &hwmon->temp.data[1]); + &data0, &data1); if (ret) return ret; - drm_dbg(&hwmon->xe->drm, "thermal info read val 0x%x val1 0x%x\n", - hwmon->temp.data[0], hwmon->temp.data[1]); + drm_dbg(&hwmon->xe->drm, "thermal info read val 0x%x val1 0x%x\n", data0, data1); + hwmon->temp.data[0] = cpu_to_le32(data0); + hwmon->temp.data[1] = cpu_to_le32(data1); ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_CONFIG, 0), &config, NULL); @@ -808,26 +857,74 @@ static int xe_hwmon_pcode_read_thermal_info(struct xe_hwmon *hwmon) return ret; } +static inline bool mmio_temp_valid(const struct xe_hwmon *hwmon, u32 value) +{ + /* + * On platforms lacking temperature sentinel support, a value of 0 is treated + * as invalid. While 0°C is theoretically possible, it is highly unlikely for + * a discrete GPU in normal environments, making it a reasonable fallback + * indicator for invalid or uninitialized temperature readings. + * All-ones is returned when the device is off the bus, so reject it too. + */ + if (value == U32_MAX) + return false; + + return hwmon->xe->info.has_temp_sentinel || value != 0; +} + +/* Mailbox temperature is sign-magnitude (bit 7 sign, bits 6:0 magnitude). */ +static inline bool mbx_temp_valid(const struct xe_hwmon *hwmon, u8 value) +{ + if (value == TEMP_MBX_INVALID) + return false; + + return hwmon->xe->info.has_temp_sentinel || value != 0; +} + +/* Decode an 8-bit sign-magnitude mailbox temperature to degrees Celsius. */ +static int mbx_temp_decode(u8 value) +{ + int temp = value & TEMP_MBX_MAG; + + return (value & TEMP_MBX_SIGN) ? -temp : temp; +} + static int get_mc_temp(struct xe_hwmon *hwmon, long *val) { struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); - u32 *dword = (u32 *)hwmon->temp.value; + int ret, i, count = 0; s32 average = 0; - int ret, i; - for (i = 0; i < DIV_ROUND_UP(TEMP_LIMIT_MAX, sizeof(u32)); i++) { + guard(mutex)(&hwmon->hwmon_lock); + + for (i = 0; i < DIV_ROUND_UP(hwmon->temp.count, sizeof(u32)); i++) { + u32 data = 0; + ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_DATA, i), - (dword + i), NULL); + &data, NULL); if (ret) return ret; - drm_dbg(&hwmon->xe->drm, "thermal data for group %d val 0x%x\n", i, dword[i]); + drm_dbg(&hwmon->xe->drm, "thermal data for group %d val 0x%x\n", i, data); + hwmon->temp.dword[i] = cpu_to_le32(data); } - for (i = TEMP_INDEX_MCTRL; i < hwmon->temp.count - 1; i++) - average += hwmon->temp.value[i]; + for (i = TEMP_INDEX_MCTRL; i < hwmon->temp.count - 1; i++) { + if (!mbx_temp_valid(hwmon, hwmon->temp.value[i])) + continue; + average += mbx_temp_decode(hwmon->temp.value[i]); + count++; + } + + if (!count) { + drm_dbg(&hwmon->xe->drm, "Memory controller temperature unavailable!\n"); + return -ENXIO; + } + + average /= count; + + if (val) + *val = average * MILLIDEGREE_PER_DEGREE; - average /= (hwmon->temp.count - TEMP_INDEX_MCTRL - 1); - *val = average * MILLIDEGREE_PER_DEGREE; return 0; } @@ -847,7 +944,7 @@ static int get_pcie_temp(struct xe_hwmon *hwmon, long *val) data = REG_FIELD_GET(PCIE_SENSOR_MASK, data); data = REG_FIELD_GET(TEMP_MASK, data); - *val = (s8)data * MILLIDEGREE_PER_DEGREE; + *val = mbx_temp_decode(data) * MILLIDEGREE_PER_DEGREE; return 0; } @@ -1511,22 +1608,11 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon) } else { drm_info(&hwmon->xe->drm, "Using mailbox commands for power limits\n"); /* Write default limits to read from pcode from now on. */ - xe_hwmon_pcode_rmw_power_limit(hwmon, PL1_HWMON_ATTR, - CHANNEL_CARD, PWR_LIM | PWR_LIM_TIME, - hwmon->pl1_on_boot[CHANNEL_CARD]); - xe_hwmon_pcode_rmw_power_limit(hwmon, PL1_HWMON_ATTR, - CHANNEL_PKG, PWR_LIM | PWR_LIM_TIME, - hwmon->pl1_on_boot[CHANNEL_PKG]); - xe_hwmon_pcode_rmw_power_limit(hwmon, PL2_HWMON_ATTR, - CHANNEL_CARD, PWR_LIM | PWR_LIM_TIME, - hwmon->pl2_on_boot[CHANNEL_CARD]); - xe_hwmon_pcode_rmw_power_limit(hwmon, PL2_HWMON_ATTR, - CHANNEL_PKG, PWR_LIM | PWR_LIM_TIME, - hwmon->pl2_on_boot[CHANNEL_PKG]); + if (xe_hwmon_pcode_set_default_power_limits(hwmon)) + drm_warn(&hwmon->xe->drm, "Failed to set default power limits\n"); hwmon->scl_shift_power = PWR_UNIT; hwmon->scl_shift_energy = ENERGY_UNIT; hwmon->scl_shift_time = TIME_UNIT; - hwmon->boot_power_limit_read = true; } } else { drm_info(&hwmon->xe->drm, "Using register for power limits\n"); @@ -1573,7 +1659,7 @@ int xe_hwmon_register(struct xe_device *xe) if (IS_SRIOV_VF(xe)) return 0; - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c index b82caaff80d7bf..27784636b7b788 100644 --- a/drivers/gpu/drm/xe/xe_i2c.c +++ b/drivers/gpu/drm/xe/xe_i2c.c @@ -360,7 +360,7 @@ int xe_i2c_probe(struct xe_device *xe) if (ep.cookie != XE_I2C_EP_COOKIE_DEVICE) return 0; - i2c = devm_kzalloc(drm_dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(drm_dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/gpu/drm/xe/xe_irq.c b/drivers/gpu/drm/xe/xe_irq.c index 9e49e2241da41f..b394c8edf89c91 100644 --- a/drivers/gpu/drm/xe/xe_irq.c +++ b/drivers/gpu/drm/xe/xe_irq.c @@ -908,6 +908,7 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg) struct xe_hw_engine *hwe; enum xe_hw_engine_id id; struct xe_tile *tile; + unsigned long flags; struct xe_gt *gt; if (!atomic_read(&xe->irq.enabled)) @@ -922,8 +923,10 @@ static irqreturn_t xe_irq_msix_default_hwe_handler(int irq, void *arg) if (gt->tile != tile) continue; + spin_lock_irqsave(&xe->irq.lock, flags); for_each_hw_engine(hwe, gt, id) xe_memirq_hwe_handler(memirq, hwe); + spin_unlock_irqrestore(&xe->irq.lock, flags); } } diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c index 768442ca7da6d8..1bddfaf0fb9f03 100644 --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c @@ -335,19 +335,19 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id) if (fw->size > XE_LB_MAX_PAYLOAD_SIZE) { drm_err(&xe->drm, "Firmware %s size %zu is larger than max pay load size %u\n", lb_fw->blob_path, fw->size, XE_LB_MAX_PAYLOAD_SIZE); - release_firmware(fw); - return -ENODATA; + ret = -ENODATA; + goto release_fw; } ret = parse_lb_layout(lb_fw, fw->data, fw->size, "LTES"); if (ret) - return ret; + goto release_fw; lb_fw->payload_size = fw->size; lb_fw->payload = drmm_kzalloc(&xe->drm, lb_fw->payload_size, GFP_KERNEL); if (!lb_fw->payload) { - release_firmware(fw); - return -ENOMEM; + ret = -ENOMEM; + goto release_fw; } drm_info(&xe->drm, "Using %s firmware from %s version %u.%u.%u.%u\n", @@ -356,10 +356,11 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id) lb_fw->version.hotfix, lb_fw->version.build); memcpy((void *)lb_fw->payload, fw->data, lb_fw->payload_size); - release_firmware(fw); INIT_WORK(&lb_fw->work, xe_late_bind_work); - return 0; +release_fw: + release_firmware(fw); + return ret; } static int xe_late_bind_fw_init(struct xe_late_bind *late_bind) diff --git a/drivers/gpu/drm/xe/xe_lmtt.c b/drivers/gpu/drm/xe/xe_lmtt.c index 0c726eda93906f..8a5a434931b04b 100644 --- a/drivers/gpu/drm/xe/xe_lmtt.c +++ b/drivers/gpu/drm/xe/xe_lmtt.c @@ -12,7 +12,8 @@ #include "xe_assert.h" #include "xe_bo.h" -#include "xe_tlb_inval.h" +#include "xe_gt.h" +#include "xe_gt_mcr.h" #include "xe_lmtt.h" #include "xe_map.h" #include "xe_mert.h" @@ -21,6 +22,7 @@ #include "xe_sriov.h" #include "xe_tile.h" #include "xe_tile_sriov_printk.h" +#include "xe_tlb_inval.h" /** * DOC: Local Memory Translation Table @@ -210,14 +212,43 @@ int xe_lmtt_init(struct xe_lmtt *lmtt) return err; } -static void lmtt_setup_dir_ptr(struct xe_lmtt *lmtt) +static void lmtt_setup_dir_ptr_gt(struct xe_gt *gt, u32 config) +{ + struct xe_device *xe = gt_to_xe(gt); + struct xe_reg_mcr reg_mcr; + struct xe_reg reg; + u32 val_read; + + if (GRAPHICS_VER(xe) < 20) { + reg = LMEM_CFG; + xe_mmio_write32(>->mmio, reg, config); + return; + } + + if (xe_gt_is_main_type(gt)) { + reg_mcr = XE2_LMEM_CFG_MCR; + xe_gt_mcr_multicast_write(gt, reg_mcr, config); + val_read = xe_gt_mcr_unicast_read_any(gt, reg_mcr); + xe_gt_assert_msg(gt, val_read == config, "LMEM_CFG_MCR: %#x != %#x\n", + config, val_read); + } else { + reg = XE2_LMEM_CFG; + xe_mmio_write32(>->mmio, reg, config); + + if (MEDIA_VER(xe) >= 35) { + val_read = xe_mmio_read32(>->mmio, reg); + xe_gt_assert_msg(gt, val_read == config, "LMEM_CFG: %#x != %#x\n", + config, val_read); + } + } +} + +static void lmtt_setup_dir_ptr(struct xe_lmtt *lmtt, struct xe_gt *gt) { struct xe_tile *tile = lmtt_to_tile(lmtt); struct xe_device *xe = tile_to_xe(tile); dma_addr_t offset = xe_bo_main_addr(lmtt->pd->bo, XE_PAGE_SIZE); - struct xe_gt *gt; u32 config; - u8 id; lmtt_debug(lmtt, "DIR offset %pad\n", &offset); lmtt_assert(lmtt, xe_bo_is_vram(lmtt->pd->bo)); @@ -225,31 +256,32 @@ static void lmtt_setup_dir_ptr(struct xe_lmtt *lmtt) config = LMEM_EN | REG_FIELD_PREP(LMTT_DIR_PTR, offset / SZ_64K); - for_each_gt_on_tile(gt, tile, id) - xe_mmio_write32(>->mmio, - GRAPHICS_VER(xe) >= 20 ? XE2_LMEM_CFG : LMEM_CFG, - config); + lmtt_setup_dir_ptr_gt(gt, config); - if (xe_device_has_mert(xe) && xe_tile_is_root(tile)) + if (xe_device_has_mert(xe) && xe_tile_is_root(tile) && + xe_gt_is_main_type(gt)) xe_mmio_write32(&tile->mmio, MERT_LMEM_CFG, config); } /** * xe_lmtt_init_hw - Perform LMTT hardware initialization. - * @lmtt: the &xe_lmtt to initialize + * @gt: the &xe_gt for which lmtt is initialized * * This function is a second step of the LMTT initialization. - * This function registers LMTT Root Directory prepared in xe_lmtt_init(). + * This function registers LMTT Root Directory prepared in xe_lmtt_init() + * on the given GT. * * This function shall be called after every hardware reset. * This function shall be called only when running as a PF driver. */ -void xe_lmtt_init_hw(struct xe_lmtt *lmtt) +void xe_lmtt_init_hw(struct xe_gt *gt) { + struct xe_lmtt *lmtt = >_to_tile(gt)->sriov.pf.lmtt; + if (!lmtt->pd) return; - lmtt_setup_dir_ptr(lmtt); + lmtt_setup_dir_ptr(lmtt, gt); } static int lmtt_invalidate_hw(struct xe_lmtt *lmtt) diff --git a/drivers/gpu/drm/xe/xe_lmtt.h b/drivers/gpu/drm/xe/xe_lmtt.h index 8fa387b38c5201..5ef065dd573c0f 100644 --- a/drivers/gpu/drm/xe/xe_lmtt.h +++ b/drivers/gpu/drm/xe/xe_lmtt.h @@ -9,12 +9,13 @@ #include struct xe_bo; +struct xe_gt; struct xe_lmtt; struct xe_lmtt_ops; #ifdef CONFIG_PCI_IOV int xe_lmtt_init(struct xe_lmtt *lmtt); -void xe_lmtt_init_hw(struct xe_lmtt *lmtt); +void xe_lmtt_init_hw(struct xe_gt *gt); void xe_lmtt_invalidate_hw(struct xe_lmtt *lmtt); int xe_lmtt_prepare_pages(struct xe_lmtt *lmtt, unsigned int vfid, u64 range); int xe_lmtt_populate_pages(struct xe_lmtt *lmtt, unsigned int vfid, struct xe_bo *bo, u64 offset); @@ -23,7 +24,7 @@ u64 xe_lmtt_estimate_pt_size(struct xe_lmtt *lmtt, u64 size); u64 xe_lmtt_page_size(struct xe_lmtt *lmtt); #else static inline int xe_lmtt_init(struct xe_lmtt *lmtt) { return 0; } -static inline void xe_lmtt_init_hw(struct xe_lmtt *lmtt) { } +static inline void xe_lmtt_init_hw(struct xe_gt *gt) { } #endif #endif diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c index de9a9560ecf3ea..fdcc1cbd03bb7d 100644 --- a/drivers/gpu/drm/xe/xe_lrc.c +++ b/drivers/gpu/drm/xe/xe_lrc.c @@ -1469,15 +1469,15 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe) finish_bo(&state); kfree(state.buffer); - /* - * Enable INDIRECT_CTX leaving INDIRECT_CTX_OFFSET at its default: it - * varies per engine class, but the default is good enough - */ xe_lrc_write_ctx_reg(lrc, CTX_CS_INDIRECT_CTX, (xe_bo_ggtt_addr(lrc->bo) + state.offset) | /* Size in CLs. */ (state.written * sizeof(u32) / 64)); + if (GRAPHICS_VER(lrc_to_xe(lrc)) < 20) + xe_lrc_write_ctx_reg(lrc, + CTX_CS_INDIRECT_CTX_OFFSET, + CTX_INDIRECT_CTX_OFFSET_DEFAULT); return 0; } diff --git a/drivers/gpu/drm/xe/xe_memirq.c b/drivers/gpu/drm/xe/xe_memirq.c index 9dfe965cb46ec2..1073132f2dedee 100644 --- a/drivers/gpu/drm/xe/xe_memirq.c +++ b/drivers/gpu/drm/xe/xe_memirq.c @@ -555,6 +555,7 @@ void xe_memirq_handler(struct xe_memirq *memirq) struct xe_hw_engine *hwe; enum xe_hw_engine_id id; struct iosys_map map; + unsigned long flags; unsigned int gtid; struct xe_gt *gt; @@ -568,8 +569,10 @@ void xe_memirq_handler(struct xe_memirq *memirq) if (gt->tile != tile) continue; + spin_lock_irqsave(&xe->irq.lock, flags); for_each_hw_engine(hwe, gt, id) xe_memirq_hwe_handler(memirq, hwe); + spin_unlock_irqrestore(&xe->irq.lock, flags); } /* GuC and media GuC (if present) must be checked separately */ diff --git a/drivers/gpu/drm/xe/xe_mert.c b/drivers/gpu/drm/xe/xe_mert.c index 32700c19a1df31..934be933d57f7b 100644 --- a/drivers/gpu/drm/xe/xe_mert.c +++ b/drivers/gpu/drm/xe/xe_mert.c @@ -74,7 +74,8 @@ static void mert_handle_cat_error(struct xe_device *xe) break; case CATERR_UNMAPPED_GGTT: xe_sriov_err(xe, "MERT: CAT_ERR: Access to an unmapped GGTT!\n"); - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); break; case CATERR_LMTT_FAULT: xe_sriov_dbg_ratelimited(xe, "MERT: CAT_ERR: VF%u LMTT fault!\n", vfid); @@ -82,7 +83,8 @@ static void mert_handle_cat_error(struct xe_device *xe) break; default: xe_sriov_err(xe, "MERT: Unexpected CAT_ERR code=%#x!\n", code); - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, + DRM_WEDGE_RECOVERY_REBIND | DRM_WEDGE_RECOVERY_BUS_RESET); break; } } diff --git a/drivers/gpu/drm/xe/xe_pat.c b/drivers/gpu/drm/xe/xe_pat.c index a5fe1beec652d0..0ac64a6a3098a7 100644 --- a/drivers/gpu/drm/xe/xe_pat.c +++ b/drivers/gpu/drm/xe/xe_pat.c @@ -590,7 +590,13 @@ static const struct xe_pat_ops xe3p_xpc_pat_ops = { .entry_dump = xe3p_xpc_pat_entry_dump, }; -void xe_pat_init_early(struct xe_device *xe) +/** + * xe_pat_init_early() - Init early pat table operation. + * @xe: the &xe_device + * + * Return: 0 on success or a negative error code on failure. + */ +int xe_pat_init_early(struct xe_device *xe) { xe->pat.idx[XE_CACHE_WB_COMPRESSION] = XE_PAT_INVALID_IDX; xe->pat.idx[XE_CACHE_NONE_COMPRESSION] = XE_PAT_INVALID_IDX; @@ -688,12 +694,15 @@ void xe_pat_init_early(struct xe_device *xe) */ drm_err(&xe->drm, "Missing PAT table for platform with graphics version %d.%02d!\n", GRAPHICS_VER(xe), GRAPHICS_VERx100(xe) % 100); + return -ENODATA; } + xe_assert(xe, xe->pat.ops); xe_assert(xe, xe->pat.ops->dump); xe_assert(xe, xe->pat.ops->program_graphics); xe_assert(xe, MEDIA_VER(xe) < 13 || xe->pat.ops->program_media); xe_assert(xe, GRAPHICS_VER(xe) < 20 || xe->pat.ops->entry_dump); + return 0; } void xe_pat_init(struct xe_gt *gt) diff --git a/drivers/gpu/drm/xe/xe_pat.h b/drivers/gpu/drm/xe/xe_pat.h index 7060f66e1d638a..6398c3ab480559 100644 --- a/drivers/gpu/drm/xe/xe_pat.h +++ b/drivers/gpu/drm/xe/xe_pat.h @@ -42,8 +42,10 @@ struct xe_pat_table_entry { /** * xe_pat_init_early - SW initialization, setting up data based on device * @xe: xe device + * + * Return: 0 on success or a negative error code on failure. */ -void xe_pat_init_early(struct xe_device *xe); +int xe_pat_init_early(struct xe_device *xe); /** * xe_pat_init - Program HW PAT table diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index 50e4920e8e08cc..12ff5c90254780 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -486,6 +486,7 @@ static const struct xe_device_desc cri_desc = { .has_soc_remapper_telem = true, .has_sriov = true, .has_sysctrl = true, + .has_temp_sentinel = true, .max_gt_per_tile = 2, MULTI_LRC_MASK, .require_force_probe = true, @@ -637,7 +638,7 @@ static int read_gmdid(struct xe_device *xe, enum xe_gmdid_type type, u32 *ver, u return 0; } - gt = kzalloc(sizeof(*gt), GFP_KERNEL); + gt = kzalloc_obj(*gt); if (!gt) return -ENOMEM; @@ -817,6 +818,7 @@ static int xe_info_init_early(struct xe_device *xe, xe->info.has_sriov = xe_configfs_primary_gt_allowed(to_pci_dev(xe->drm.dev)) && desc->has_sriov; xe->info.has_sysctrl = desc->has_sysctrl; + xe->info.has_temp_sentinel = desc->has_temp_sentinel; xe->info.skip_guc_pc = desc->skip_guc_pc; xe->info.skip_pcode = desc->skip_pcode; xe->info.needs_scratch = desc->needs_scratch; @@ -1449,6 +1451,9 @@ static int xe_pci_runtime_resume(struct device *dev) struct xe_device *xe = pdev_to_xe_device(pdev); int err; + if (xe->d3cold.allowed) + d3cold_toggle(pdev, D3COLD_DISABLE); + err = pci_set_power_state(pdev, PCI_D0); if (err) return err; diff --git a/drivers/gpu/drm/xe/xe_pci_error.c b/drivers/gpu/drm/xe/xe_pci_error.c index 79ce0c671549a9..a5c8fd67738cf3 100644 --- a/drivers/gpu/drm/xe/xe_pci_error.c +++ b/drivers/gpu/drm/xe/xe_pci_error.c @@ -30,8 +30,10 @@ static void prepare_device_for_reset(struct pci_dev *pdev) xe_device_set_in_reset(xe); - for_each_gt(gt, xe, id) + for_each_gt(gt, xe, id) { xe_gt_declare_wedged(gt); + flush_work(>->wedge.worker); + } pci_disable_device(pdev); } @@ -86,7 +88,7 @@ static pci_ers_result_t xe_pci_error_mmio_enabled(struct pci_dev *pdev) /* User wants to debug the error, prevent reset */ if (xe->wedged.mode == XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET) { - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, DRM_WEDGE_RECOVERY_NONE); return PCI_ERS_RESULT_DISCONNECT; } diff --git a/drivers/gpu/drm/xe/xe_pci_types.h b/drivers/gpu/drm/xe/xe_pci_types.h index 448bbe5ba1d77b..15eedac8467a1c 100644 --- a/drivers/gpu/drm/xe/xe_pci_types.h +++ b/drivers/gpu/drm/xe/xe_pci_types.h @@ -61,6 +61,7 @@ struct xe_device_desc { u8 has_soc_remapper_telem:1; u8 has_sriov:1; u8 has_sysctrl:1; + u8 has_temp_sentinel:1; u8 needs_scratch:1; u8 skip_guc_pc:1; u8 skip_pcode:1; diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c index 4f1035ab1eb2bd..d95f0d128ed492 100644 --- a/drivers/gpu/drm/xe/xe_pm.c +++ b/drivers/gpu/drm/xe/xe_pm.c @@ -241,15 +241,15 @@ int xe_pm_resume(struct xe_device *xe) drm_dbg(&xe->drm, "Resuming device\n"); trace_xe_pm_resume(xe, __builtin_return_address(0)); - for_each_gt(gt, xe, id) - xe_gt_idle_disable_c6(gt); + err = xe_pcode_ready(xe, true); + if (err) + return err; for_each_tile(tile, xe, id) xe_wa_apply_tile_workarounds(tile); - err = xe_pcode_ready(xe, true); - if (err) - return err; + for_each_gt(gt, xe, id) + xe_gt_idle_disable_c6(gt); xe_display_pm_resume_early(xe); @@ -687,6 +687,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe) */ int xe_pm_runtime_resume(struct xe_device *xe) { + struct xe_tile *tile; struct xe_gt *gt; u8 id; int err = 0; @@ -698,13 +699,16 @@ int xe_pm_runtime_resume(struct xe_device *xe) xe_rpm_lockmap_acquire(xe); if (xe->d3cold.allowed) { - for_each_gt(gt, xe, id) - xe_gt_idle_disable_c6(gt); - err = xe_pcode_ready(xe, true); if (err) goto out; + for_each_tile(tile, xe, id) + xe_wa_apply_tile_workarounds(tile); + + for_each_gt(gt, xe, id) + xe_gt_idle_disable_c6(gt); + xe_display_pm_resume_early(xe); /* diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c index 8a95d58d9c6f68..aeeac0f1ab83e1 100644 --- a/drivers/gpu/drm/xe/xe_pt.c +++ b/drivers/gpu/drm/xe/xe_pt.c @@ -3016,8 +3016,7 @@ struct xe_pt_job_ops *xe_pt_job_ops_alloc(u32 num_ops) if (!pt_job_ops) return NULL; - pt_job_ops->ops = kvmalloc_array(num_ops, sizeof(*pt_job_ops->ops), - GFP_KERNEL); + pt_job_ops->ops = kvmalloc_objs(*pt_job_ops->ops, num_ops); if (!pt_job_ops->ops) { kfree(pt_job_ops); return NULL; diff --git a/drivers/gpu/drm/xe/xe_ras.c b/drivers/gpu/drm/xe/xe_ras.c index 7a85735c57d58b..fe16a41060607c 100644 --- a/drivers/gpu/drm/xe/xe_ras.c +++ b/drivers/gpu/drm/xe/xe_ras.c @@ -321,8 +321,7 @@ static u8 handle_core_compute_errors(struct xe_ras_error_array *arr) static void punit_error_handler(struct xe_device *xe) { - xe_device_set_wedged_method(xe, DRM_WEDGE_RECOVERY_COLD_RESET); - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, DRM_WEDGE_RECOVERY_COLD_RESET); } static u8 handle_soc_internal_errors(struct xe_device *xe, struct xe_ras_error_array *arr) diff --git a/drivers/gpu/drm/xe/xe_shrinker.c b/drivers/gpu/drm/xe/xe_shrinker.c index deb4378c1ec154..4e4da76936f490 100644 --- a/drivers/gpu/drm/xe/xe_shrinker.c +++ b/drivers/gpu/drm/xe/xe_shrinker.c @@ -113,6 +113,9 @@ static int __xe_shrinker_walk(struct xe_shrinker *shrinker, continue; lret = xe_bo_shrink(ctx, ttm_bo, flags, scanned); + /* Like the TTM LRU walk, skip bos we can't shrink now. */ + if (lret == -EBUSY) + continue; if (lret < 0) { ret = lret; goto out; diff --git a/drivers/gpu/drm/xe/xe_survivability_mode.c b/drivers/gpu/drm/xe/xe_survivability_mode.c index 45d44ebe288b4f..ca031576fecb72 100644 --- a/drivers/gpu/drm/xe/xe_survivability_mode.c +++ b/drivers/gpu/drm/xe/xe_survivability_mode.c @@ -446,8 +446,7 @@ void xe_survivability_mode_runtime_enable(struct xe_device *xe) survivability->type = XE_SURVIVABILITY_TYPE_RUNTIME; xe_log_err(xe, SURVIVABILITY, 0, "Runtime Mode enabled!\n"); - xe_device_set_wedged_method(xe, DRM_WEDGE_RECOVERY_VENDOR); - xe_device_declare_wedged(xe); + xe_device_declare_wedged(xe, DRM_WEDGE_RECOVERY_VENDOR); xe_log_err(xe, SURVIVABILITY, 0, "Firmware flash required!\n"); xe_info(xe, "Please refer to the userspace documentation for more details how to flash the firmware on %s!\n", diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c index 909a602d091eaf..bc6902b5bf57be 100644 --- a/drivers/gpu/drm/xe/xe_svm.c +++ b/drivers/gpu/drm/xe/xe_svm.c @@ -347,6 +347,7 @@ static void xe_vma_set_default_attributes(struct xe_vma *vma) struct xe_vma_mem_attr default_attr = { .preferred_loc.devmem_fd = DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE, .preferred_loc.migration_policy = DRM_XE_MIGRATE_ALL_PAGES, + .default_pat_index = vma->attr.default_pat_index, .pat_index = vma->attr.default_pat_index, .atomic_access = DRM_XE_ATOMIC_UNDEFINED, .purgeable_state = XE_MADV_PURGEABLE_WILLNEED, diff --git a/drivers/gpu/drm/xe/xe_sync.c b/drivers/gpu/drm/xe/xe_sync.c index a3268465868e59..48a38d64a42acc 100644 --- a/drivers/gpu/drm/xe/xe_sync.c +++ b/drivers/gpu/drm/xe/xe_sync.c @@ -6,6 +6,7 @@ #include "xe_sync.h" #include +#include #include #include #include @@ -234,11 +235,35 @@ ALLOW_ERROR_INJECTION(xe_sync_entry_parse, ERRNO); int xe_sync_entry_add_deps(struct xe_sync_entry *sync, struct xe_sched_job *job) { - if (sync->fence) - return drm_sched_job_add_dependency(&job->drm, - dma_fence_get(sync->fence)); + struct dma_fence_unwrap iter; + struct dma_fence *fence; + int err = 0; - return 0; + if (!sync->fence) + return 0; + + /* + * Unwrap fence containers (e.g. dma_fence_chain from a timeline + * syncobj) so the scheduler sees the underlying fences. That lets it + * drop dependencies on jobs from the same entity and only wait for + * jobs on the same scheduler to be scheduled, rather than waiting for + * the container, which forces a full GPU completion wait and drains + * the queue. + */ + dma_fence_unwrap_for_each(fence, &iter, sync->fence) { + /* + * There is no dma_fence_unwrap_stop() helper to drop the + * reference the iterator holds, so keep iterating without + * doing anything once an error has occurred. + */ + if (err || dma_fence_is_signaled(fence)) + continue; + + err = drm_sched_job_add_dependency(&job->drm, + dma_fence_get(fence)); + } + + return err; } /** diff --git a/drivers/gpu/drm/xe/xe_sysctrl.c b/drivers/gpu/drm/xe/xe_sysctrl.c index 4067e1dfdcd50d..5abb1a8c9134d4 100644 --- a/drivers/gpu/drm/xe/xe_sysctrl.c +++ b/drivers/gpu/drm/xe/xe_sysctrl.c @@ -85,7 +85,7 @@ int xe_sysctrl_init(struct xe_device *xe) if (!xe->info.has_sysctrl) return 0; - sc->mmio = devm_kzalloc(xe->drm.dev, sizeof(*sc->mmio), GFP_KERNEL); + sc->mmio = devm_kzalloc_obj(xe->drm.dev, *sc->mmio); if (!sc->mmio) return -ENOMEM; diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index 9a514d983e90be..f28550b29f6be6 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c @@ -243,9 +243,9 @@ static void xe_ttm_vram_retry_queued_pages(struct xe_ttm_vram_mgr *mgr) continue; } --mgr->n_queued_pages; - list_del_rcu(&pos->queued_link); + list_del(&pos->queued_link); ++mgr->n_offlined_pages; - list_add_rcu(&pos->offlined_link, &mgr->offlined_pages); + list_add(&pos->offlined_link, &mgr->offlined_pages); } } @@ -394,17 +394,17 @@ static void xe_ttm_vram_free_bad_pages(struct xe_ttm_vram_mgr *mgr) struct xe_ttm_vram_offline_resource *pos, *n; list_for_each_entry_safe(pos, n, &mgr->offlined_pages, offlined_link) { - list_del_rcu(&pos->offlined_link); + list_del(&pos->offlined_link); xe_ttm_vram_buddy_free(mgr, &pos->blocks, pos->used_visible_size); --mgr->n_offlined_pages; - kfree_rcu(pos, rcu); + kfree(pos); } list_for_each_entry_safe(pos, n, &mgr->queued_pages, queued_link) { - list_del_rcu(&pos->queued_link); + list_del(&pos->queued_link); /* queued entries have no buddy reservation yet */ xe_ttm_vram_buddy_free(mgr, &pos->blocks, 0); --mgr->n_queued_pages; - kfree_rcu(pos, rcu); + kfree(pos); } } @@ -687,6 +687,19 @@ static int xe_ttm_vram_purge_page(struct xe_device *xe, struct xe_bo *bo) goto out; } + /* + * The caller's user+pinned check was lockless (mgr->lock only), so an + * external pin can race in before we get here. Re-validate now that + * we hold the reservation lock and reject the purge instead of + * unpinning a BO userspace still expects to be resident. Request SBR + * the same way the caller's own critical-BO check does. + */ + if (xe_bo_is_user(bo) && xe_bo_is_pinned(bo)) { + xe_bo_unlock(bo); + ret = -EIO; + goto out; + } + xe_bo_set_purgeable_state(bo, XE_MADV_PURGEABLE_DONTNEED); ttm_bo_unmap_virtual(&bo->ttm); /* nuke CPU mmap + VRAM IO mappings */ if (xe_bo_is_pinned(bo)) @@ -810,7 +823,7 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr, } /* Queue free(to-be-purged) pages */ ++vram_mgr->n_queued_pages; - list_add_rcu(&nentry->queued_link, &vram_mgr->queued_pages); + list_add(&nentry->queued_link, &vram_mgr->queued_pages); } else { /* Immediately offline unoccupied pages */ /* Queue free(to-be-reserved) pages */ @@ -824,11 +837,11 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr, "Page at addr:0x%llx still busy (%d), deferring reservation\n", addr, ret); ++vram_mgr->n_queued_pages; - list_add_rcu(&nentry->queued_link, &vram_mgr->queued_pages); + list_add(&nentry->queued_link, &vram_mgr->queued_pages); return 0; } ++vram_mgr->n_offlined_pages; - list_add_rcu(&nentry->offlined_link, &vram_mgr->offlined_pages); + list_add(&nentry->offlined_link, &vram_mgr->offlined_pages); return ret; } } @@ -851,6 +864,13 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr, */ ret = xe_ttm_vram_purge_page(xe, pbo); xe_bo_put(pbo); + if (ret == -EIO) { + /* Raced into an external pin after the lockless check above */ + drm_err(&xe->drm, + "%s: addr: 0x%llx became externally pinned, requesting SBR\n", + __func__, addr); + return ret; + } if (ret) drm_warn(&xe->drm, "Purge failed at addr:0x%llx, ret:%d\n", addr, ret); } @@ -968,11 +988,12 @@ int xe_ttm_vram_inject_fault(struct xe_device *xe) struct gpu_buddy *mm = &vram_mgr->mm; u64 addr; - if (vr->actual_physical_size < PAGE_SIZE) + /* Stay within the buddy-managed range; CCS/GSM/DSM sit beyond usable_size */ + if (vr->usable_size < PAGE_SIZE) return -ENOSPC; - addr = vr->actual_physical_size - PAGE_SIZE; - while (addr < vr->actual_physical_size) { + addr = ALIGN_DOWN(vr->usable_size - PAGE_SIZE, PAGE_SIZE); + while (addr < vr->usable_size) { struct gpu_buddy_block *block; bool found = false; @@ -1025,16 +1046,16 @@ static int vram_bad_pages_show(struct seq_file *m, void *unused) continue; mgr = to_xe_ttm_vram_mgr(man); - rcu_read_lock(); + mutex_lock(&mgr->lock); - list_for_each_entry_rcu(pos, &mgr->offlined_pages, offlined_link) { + list_for_each_entry(pos, &mgr->offlined_pages, offlined_link) { u64 pfn; pfn = (pos->addr + vr->dpa_base) >> PAGE_SHIFT; seq_printf(m, "0x%016llx : 0x%016lx : R\n", pfn, PAGE_SIZE); } - list_for_each_entry_rcu(pos, &mgr->queued_pages, queued_link) { + list_for_each_entry(pos, &mgr->queued_pages, queued_link) { u64 pfn; pfn = (pos->addr + vr->dpa_base) >> PAGE_SHIFT; @@ -1042,7 +1063,7 @@ static int vram_bad_pages_show(struct seq_file *m, void *unused) pfn, PAGE_SIZE, pos->status ? 'F' : 'P'); } - rcu_read_unlock(); + mutex_unlock(&mgr->lock); } return 0; diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h b/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h index efcf3e1d4e80c7..8741b5de6c379a 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h @@ -81,8 +81,6 @@ struct xe_ttm_vram_offline_resource { u64 addr; /** @status: buddy reservation status */ enum xe_page_reserve_status status; - /** @rcu: RCU head for deferred freeing */ - struct rcu_head rcu; }; #endif diff --git a/drivers/gpu/drm/xe/xe_tuning.c b/drivers/gpu/drm/xe/xe_tuning.c index dc079f1e74e5be..024dd2e71b1769 100644 --- a/drivers/gpu/drm/xe/xe_tuning.c +++ b/drivers/gpu/drm/xe/xe_tuning.c @@ -122,7 +122,7 @@ static const struct xe_rtp_table_sr engine_tunings = XE_RTP_TABLE_SR( }, { XE_RTP_NAME("Tuning: Disable NULL query for Anyhit Shader"), XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2000, XE_RTP_END_VERSION_UNDEFINED), - FUNC(xe_rtp_match_first_render_or_compute)), + ENGINE_CLASS(RENDER)), XE_RTP_ACTIONS(SET(RT_CTRL, DIS_NULL_QUERY)) }, { XE_RTP_NAME("Tuning: disable HW reporting of ctx switch to GHWSP"), diff --git a/drivers/gpu/drm/xe/xe_uc_fw.c b/drivers/gpu/drm/xe/xe_uc_fw.c index 459ddb1730a8df..df1a697b6f2748 100644 --- a/drivers/gpu/drm/xe/xe_uc_fw.c +++ b/drivers/gpu/drm/xe/xe_uc_fw.c @@ -141,7 +141,7 @@ struct fw_blobs_by_type { /* for the GSC FW we match the compatibility version and not the release one */ #define XE_GSC_FIRMWARE_DEFS(fw_def, major_ver) \ - fw_def(NOVALAKE_S, GT_TYPE_ANY, major_ver(xe, gsc, nvl, 108, 0, 0)) \ + fw_def(NOVALAKE_S, GT_TYPE_ANY, major_ver(xe, gsc, nvl, 108, 1, 0)) \ fw_def(PANTHERLAKE, GT_TYPE_ANY, major_ver(xe, gsc, ptl, 105, 1, 0)) \ fw_def(LUNARLAKE, GT_TYPE_ANY, major_ver(xe, gsc, lnl, 104, 1, 0)) \ fw_def(METEORLAKE, GT_TYPE_ANY, major_ver(i915, gsc, mtl, 102, 1, 0)) diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index 1b704fa48cf0b0..6bc320f7caf4dd 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -272,8 +272,15 @@ int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct xe_exec_queue *q) * Check to see if a preemption on VM is in flight or userptr * invalidation, if so trigger this preempt fence to sync state with * other preempt fences on the VM. + * + * Also trigger it if eviction or rebinding is pending. BOs evicted + * before the first exec queue was added had no preempt fence to + * trigger. Suspend this queue until the rebind worker restores + * the mappings. */ - wait = __xe_vm_userptr_needs_repin(vm) || preempt_fences_waiting(vm); + wait = __xe_vm_userptr_needs_repin(vm) || preempt_fences_waiting(vm) || + !list_empty(&vm->gpuvm.evict.list) || + !list_empty(&vm->rebind_list); if (wait) dma_fence_enable_signaling(pfence); @@ -701,7 +708,7 @@ static void xe_vm_clear_fault_entries(struct xe_vm *vm) vm->faults.len = 0; } -static int xe_vma_ops_alloc(struct xe_vma_ops *vops, bool array_of_binds) +static noinline int xe_vma_ops_alloc(struct xe_vma_ops *vops, bool array_of_binds) { int i; @@ -1682,7 +1689,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef) */ xe_assert(xe, !((flags & XE_VM_FLAG_GSC) && (flags & XE_VM_FLAG_FAULT_MODE))); - vm = kzalloc(sizeof(*vm), GFP_KERNEL); + vm = kzalloc_obj(*vm); if (!vm) return ERR_PTR(-ENOMEM); @@ -3287,8 +3294,8 @@ static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops, thread = skip_threads ? &stack_thread : NULL; if (!skip_threads) { - prefetches = kvmalloc_array(op->prefetch_range.ranges_count, - sizeof(*prefetches), GFP_KERNEL); + prefetches = kvmalloc_objs(*prefetches, + op->prefetch_range.ranges_count); if (!prefetches) return -ENOMEM; } @@ -3566,7 +3573,7 @@ static struct dma_fence *ops_execute(struct xe_vm *vm, ++n_fence; } - fences = kcalloc(n_fence, sizeof(*fences), GFP_KERNEL); + fences = kzalloc_objs(*fences, n_fence); if (!fences) { fence = ERR_PTR(-ENOMEM); goto err_trace; diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c b/drivers/gpu/drm/xe/xe_vm_madvise.c index 5c7aefc641ee8a..a835cc55658f18 100644 --- a/drivers/gpu/drm/xe/xe_vm_madvise.c +++ b/drivers/gpu/drm/xe/xe_vm_madvise.c @@ -659,11 +659,8 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data, struct drm_file *fil err = -EINVAL; goto free_vmas; } - } - if (args->type == DRM_XE_MEM_RANGE_ATTR_PAT) { - if (!check_pat_args_are_sane(xe, &madvise_range, - args->pat_index.val)) { + if (!check_pat_args_are_sane(xe, &madvise_range, pat_index)) { err = -EINVAL; goto free_vmas; } diff --git a/drivers/gpu/drm/xe/xe_wa.c b/drivers/gpu/drm/xe/xe_wa.c index c71318b901d676..bd556412c294bd 100644 --- a/drivers/gpu/drm/xe/xe_wa.c +++ b/drivers/gpu/drm/xe/xe_wa.c @@ -581,8 +581,9 @@ static const struct xe_rtp_table_sr engine_was = XE_RTP_TABLE_SR( XE_RTP_ACTIONS(SET(TDL_CHICKEN, QID_WAIT_FOR_THREAD_NOT_RUN_DISABLE)) }, { XE_RTP_NAME("16023105232"), - XE_RTP_RULES(MEDIA_VERSION_RANGE(1301, 3000), OR, - GRAPHICS_VERSION_RANGE(2001, 3001)), + /* IP versions need to be in sync with the respective entry in xe_wa_oob.rules. */ + XE_RTP_RULES(MEDIA_VERSION_RANGE(1301, 3002), OR, + GRAPHICS_VERSION_RANGE(2001, 3005)), XE_RTP_ACTIONS(SET(RING_PSMI_CTL(0), RC_SEMA_IDLE_MSG_DISABLE, XE_RTP_ACTION_FLAG(ENGINE_BASE))) }, diff --git a/drivers/gpu/drm/xe/xe_wa_oob.rules b/drivers/gpu/drm/xe/xe_wa_oob.rules index f35181fc4e49b6..842f42679c2351 100644 --- a/drivers/gpu/drm/xe/xe_wa_oob.rules +++ b/drivers/gpu/drm/xe/xe_wa_oob.rules @@ -44,6 +44,7 @@ 18013179988 GRAPHICS_VERSION(1255) GRAPHICS_VERSION_RANGE(1270, 1274) 1508761755 GRAPHICS_VERSION(1255) +# IP versions need to be in sync with the respective entry in xe_wa.c. 16023105232 GRAPHICS_VERSION_RANGE(2001, 3005) MEDIA_VERSION_RANGE(1301, 3002) 16026508708 GRAPHICS_VERSION_RANGE(1200, 3005) diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c index e1890d0c736969..19d120569a4eaf 100644 --- a/drivers/gpu/drm/xen/xen_drm_front.c +++ b/drivers/gpu/drm/xen/xen_drm_front.c @@ -695,8 +695,7 @@ static int xen_drv_probe(struct xenbus_device *xb_dev, return ret; } - front_info = devm_kzalloc(&xb_dev->dev, - sizeof(*front_info), GFP_KERNEL); + front_info = devm_kzalloc_obj(&xb_dev->dev, *front_info); if (!front_info) return -ENOMEM; diff --git a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c index 52a0712e39c419..e998f226867482 100644 --- a/drivers/gpu/drm/xlnx/zynqmp_disp.c +++ b/drivers/gpu/drm/xlnx/zynqmp_disp.c @@ -987,8 +987,7 @@ u32 *zynqmp_disp_layer_drm_formats(struct zynqmp_disp_layer *layer, return NULL; } - formats = kcalloc(layer->info->num_formats, sizeof(*formats), - GFP_KERNEL); + formats = kzalloc_objs(*formats, layer->info->num_formats); if (!formats) { *num_formats = 0; return NULL; @@ -1024,8 +1023,7 @@ u32 *zynqmp_disp_live_layer_formats(struct zynqmp_disp_layer *layer, return NULL; } - formats = kcalloc(layer->info->num_formats, sizeof(*formats), - GFP_KERNEL); + formats = kzalloc_objs(*formats, layer->info->num_formats); if (!formats) { *num_formats = 0; return NULL; diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp_audio.c b/drivers/gpu/drm/xlnx/zynqmp_dp_audio.c index 1a46a046103f75..3410938ffef56c 100644 --- a/drivers/gpu/drm/xlnx/zynqmp_dp_audio.c +++ b/drivers/gpu/drm/xlnx/zynqmp_dp_audio.c @@ -308,7 +308,7 @@ int zynqmp_audio_init(struct zynqmp_dpsub *dpsub) if (!dpsub->aud_clk) return 0; - audio = devm_kzalloc(dev, sizeof(*audio), GFP_KERNEL); + audio = devm_kzalloc_obj(dev, *audio); if (!audio) return -ENOMEM; diff --git a/drivers/gpu/host1x/context.c b/drivers/gpu/host1x/context.c index c2c8a9bb5896ab..ed09afb87d8644 100644 --- a/drivers/gpu/host1x/context.c +++ b/drivers/gpu/host1x/context.c @@ -232,7 +232,7 @@ struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x, if (!cdl->len) return ERR_PTR(-EOPNOTSUPP); - ctx = kzalloc_obj(*ctx, GFP_KERNEL); + ctx = kzalloc_obj(*ctx); if (!ctx) return ERR_PTR(-ENOMEM); @@ -388,7 +388,7 @@ struct host1x_context_mapping *host1x_memory_context_map(struct host1x_memory_co struct host1x_context_mapping *m; struct host1x_bo_mapping *bo_m; - m = kzalloc_obj(*m, GFP_KERNEL); + m = kzalloc_obj(*m); if (!m) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index e1106fbcc4ef17..faaab789ccdb44 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -599,7 +599,7 @@ static int host1x_probe(struct platform_device *pdev) struct host1x *host; int err, i; - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/gpu/host1x/intr.c b/drivers/gpu/host1x/intr.c index 6a383e0c6eb917..30f3dff4487bb6 100644 --- a/drivers/gpu/host1x/intr.c +++ b/drivers/gpu/host1x/intr.c @@ -116,7 +116,8 @@ int host1x_intr_init(struct host1x *host) INIT_LIST_HEAD(&syncpt->fences.list); } - irq_data = devm_kcalloc(host->dev, host->num_syncpt_irqs, sizeof(irq_data[0]), GFP_KERNEL); + irq_data = devm_kzalloc_objs(host->dev, irq_data[0], + host->num_syncpt_irqs); if (!irq_data) return -ENOMEM; diff --git a/drivers/gpu/host1x/syncpt.c b/drivers/gpu/host1x/syncpt.c index 5cc3cd46d32173..fe74ff6fc6f216 100644 --- a/drivers/gpu/host1x/syncpt.c +++ b/drivers/gpu/host1x/syncpt.c @@ -293,13 +293,11 @@ int host1x_syncpt_init(struct host1x *host) struct host1x_syncpt *syncpt; unsigned int i; - syncpt = devm_kcalloc(host->dev, host->info->nb_pts, sizeof(*syncpt), - GFP_KERNEL); + syncpt = devm_kzalloc_objs(host->dev, *syncpt, host->info->nb_pts); if (!syncpt) return -ENOMEM; - bases = devm_kcalloc(host->dev, host->info->nb_bases, sizeof(*bases), - GFP_KERNEL); + bases = devm_kzalloc_objs(host->dev, *bases, host->info->nb_bases); if (!bases) return -ENOMEM; diff --git a/drivers/gpu/host1x/tegra114-mipi.c b/drivers/gpu/host1x/tegra114-mipi.c index c084a09784d14c..49ed05d1a623e5 100644 --- a/drivers/gpu/host1x/tegra114-mipi.c +++ b/drivers/gpu/host1x/tegra114-mipi.c @@ -449,7 +449,7 @@ static int tegra_mipi_probe(struct platform_device *pdev) if (!match) return -ENODEV; - mipi = devm_kzalloc(&pdev->dev, sizeof(*mipi), GFP_KERNEL); + mipi = devm_kzalloc_obj(&pdev->dev, *mipi); if (!mipi) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c index 5db100bb1e4d54..d18c68e2a555ee 100644 --- a/drivers/gpu/ipu-v3/ipu-common.c +++ b/drivers/gpu/ipu-v3/ipu-common.c @@ -1290,7 +1290,7 @@ static int ipu_probe(struct platform_device *pdev) ipu_base = res->start; - ipu = devm_kzalloc(&pdev->dev, sizeof(*ipu), GFP_KERNEL); + ipu = devm_kzalloc_obj(&pdev->dev, *ipu); if (!ipu) return -ENODEV; diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c index 07866b1369c654..ed5bfe42c316ae 100644 --- a/drivers/gpu/ipu-v3/ipu-cpmem.c +++ b/drivers/gpu/ipu-v3/ipu-cpmem.c @@ -930,7 +930,7 @@ int ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base) { struct ipu_cpmem *cpmem; - cpmem = devm_kzalloc(dev, sizeof(*cpmem), GFP_KERNEL); + cpmem = devm_kzalloc_obj(dev, *cpmem); if (!cpmem) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c index d576b7d2843796..9d41bdd5af21ff 100644 --- a/drivers/gpu/ipu-v3/ipu-csi.c +++ b/drivers/gpu/ipu-v3/ipu-csi.c @@ -683,7 +683,7 @@ int ipu_csi_init(struct ipu_soc *ipu, struct device *dev, int id, if (id > 1) return -ENODEV; - csi = devm_kzalloc(dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(dev, *csi); if (!csi) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-dc.c b/drivers/gpu/ipu-v3/ipu-dc.c index b038a6d7307b71..73f2f985e387a9 100644 --- a/drivers/gpu/ipu-v3/ipu-dc.c +++ b/drivers/gpu/ipu-v3/ipu-dc.c @@ -349,7 +349,7 @@ int ipu_dc_init(struct ipu_soc *ipu, struct device *dev, }; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-di.c b/drivers/gpu/ipu-v3/ipu-di.c index 0a34e0ab4fe60e..d420bd577a2374 100644 --- a/drivers/gpu/ipu-v3/ipu-di.c +++ b/drivers/gpu/ipu-v3/ipu-di.c @@ -717,7 +717,7 @@ int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id, if (id > 1) return -ENODEV; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-dmfc.c b/drivers/gpu/ipu-v3/ipu-dmfc.c index ae682084a10a9b..d512e5df7ab47a 100644 --- a/drivers/gpu/ipu-v3/ipu-dmfc.c +++ b/drivers/gpu/ipu-v3/ipu-dmfc.c @@ -175,7 +175,7 @@ int ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base, struct ipu_dmfc_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-dp.c b/drivers/gpu/ipu-v3/ipu-dp.c index 6a558205db967d..bfe388ebcad148 100644 --- a/drivers/gpu/ipu-v3/ipu-dp.c +++ b/drivers/gpu/ipu-v3/ipu-dp.c @@ -346,7 +346,7 @@ int ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base) struct ipu_dp_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index acd76ecc522155..3f0c1d97eb48c9 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -627,7 +627,7 @@ int ipu_ic_init(struct ipu_soc *ipu, struct device *dev, struct ipu_ic_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c index 493be4d4b091e3..b1c867229cae3f 100644 --- a/drivers/gpu/ipu-v3/ipu-image-convert.c +++ b/drivers/gpu/ipu-v3/ipu-image-convert.c @@ -2428,7 +2428,7 @@ int ipu_image_convert_init(struct ipu_soc *ipu, struct device *dev) struct ipu_image_convert_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-pre.c b/drivers/gpu/ipu-v3/ipu-pre.c index 7aac70368b0080..394081114faa27 100644 --- a/drivers/gpu/ipu-v3/ipu-pre.c +++ b/drivers/gpu/ipu-v3/ipu-pre.c @@ -312,7 +312,7 @@ static int ipu_pre_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct ipu_pre *pre; - pre = devm_kzalloc(dev, sizeof(*pre), GFP_KERNEL); + pre = devm_kzalloc_obj(dev, *pre); if (!pre) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c index d38d3ba54d722b..9fd5c709231994 100644 --- a/drivers/gpu/ipu-v3/ipu-prg.c +++ b/drivers/gpu/ipu-v3/ipu-prg.c @@ -362,7 +362,7 @@ static int ipu_prg_probe(struct platform_device *pdev) u32 val; int i, ret; - prg = devm_kzalloc(dev, sizeof(*prg), GFP_KERNEL); + prg = devm_kzalloc_obj(dev, *prg); if (!prg) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-smfc.c b/drivers/gpu/ipu-v3/ipu-smfc.c index 46ffc0a5906d69..ff283484d5b860 100644 --- a/drivers/gpu/ipu-v3/ipu-smfc.c +++ b/drivers/gpu/ipu-v3/ipu-smfc.c @@ -175,7 +175,7 @@ int ipu_smfc_init(struct ipu_soc *ipu, struct device *dev, struct ipu_smfc_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/gpu/ipu-v3/ipu-vdi.c b/drivers/gpu/ipu-v3/ipu-vdi.c index af9631fd42560a..279f724eb0a4ba 100644 --- a/drivers/gpu/ipu-v3/ipu-vdi.c +++ b/drivers/gpu/ipu-v3/ipu-vdi.c @@ -200,7 +200,7 @@ int ipu_vdi_init(struct ipu_soc *ipu, struct device *dev, { struct ipu_vdi *vdi; - vdi = devm_kzalloc(dev, sizeof(*vdi), GFP_KERNEL); + vdi = devm_kzalloc_obj(dev, *vdi); if (!vdi) return -ENOMEM; diff --git a/drivers/gpu/tests/gpu_random.c b/drivers/gpu/tests/gpu_random.c index 6356372f7e52ed..295d7f0bf0c6c8 100644 --- a/drivers/gpu/tests/gpu_random.c +++ b/drivers/gpu/tests/gpu_random.c @@ -31,7 +31,7 @@ unsigned int *gpu_random_order(unsigned int count, struct rnd_state *state) { unsigned int *order, i; - order = kmalloc_array(count, sizeof(*order), GFP_KERNEL); + order = kmalloc_objs(*order, count); if (!order) return order; diff --git a/drivers/greybus/gb-beagleplay.c b/drivers/greybus/gb-beagleplay.c index 244966d56c9ba9..13cbd8c5e9d4f8 100644 --- a/drivers/greybus/gb-beagleplay.c +++ b/drivers/greybus/gb-beagleplay.c @@ -1191,7 +1191,7 @@ static int gb_beagleplay_probe(struct serdev_device *serdev) int ret = 0; struct gb_beagleplay *bg; - bg = devm_kmalloc(&serdev->dev, sizeof(*bg), GFP_KERNEL); + bg = devm_kmalloc_obj(&serdev->dev, *bg); if (!bg) return -ENOMEM; diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index b3cb13b8c5e872..443922bb20525b 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -444,7 +444,7 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i dmi_check_system(dmi_sfh_table); - privdata = devm_kzalloc(&pdev->dev, sizeof(*privdata), GFP_KERNEL); + privdata = devm_kzalloc_obj(&pdev->dev, *privdata); if (!privdata) return -ENOMEM; @@ -477,7 +477,7 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i return rc; } - privdata->cl_data = devm_kzalloc(&pdev->dev, sizeof(struct amdtp_cl_data), GFP_KERNEL); + privdata->cl_data = devm_kzalloc_obj(&pdev->dev, struct amdtp_cl_data); if (!privdata->cl_data) return -ENOMEM; diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c index 54bfaf61182b33..42ff8c6a2e5594 100644 --- a/drivers/hid/hid-a4tech.c +++ b/drivers/hid/hid-a4tech.c @@ -115,7 +115,7 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id) struct a4tech_sc *a4; int ret; - a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL); + a4 = devm_kzalloc_obj(&hdev->dev, *a4); if (a4 == NULL) { hid_err(hdev, "can't alloc device descriptor\n"); return -ENOMEM; diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index 0556cb5645ebbf..19e40d402aa81f 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c @@ -788,7 +788,7 @@ static int alps_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct alps_dev *data = NULL; int ret; - data = devm_kzalloc(&hdev->dev, sizeof(struct alps_dev), GFP_KERNEL); + data = devm_kzalloc_obj(&hdev->dev, struct alps_dev); if (!data) return -ENOMEM; diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 5b32fb8c77f3fc..82d085f63030eb 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -859,7 +859,7 @@ static int apple_backlight_init(struct hid_device *hdev) hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n", rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max); - asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL); + asc->backlight = devm_kzalloc_obj(&hdev->dev, *asc->backlight); if (!asc->backlight) { ret = -ENOMEM; goto cleanup_and_exit; @@ -930,7 +930,7 @@ static int apple_magic_backlight_init(struct hid_device *hdev) if (hdev->collection[0].usage != HID_USAGE_MAGIC_BL) return -ENODEV; - backlight = devm_kzalloc(&hdev->dev, sizeof(*backlight), GFP_KERNEL); + backlight = devm_kzalloc_obj(&hdev->dev, *backlight); if (!backlight) return -ENOMEM; @@ -963,7 +963,7 @@ static int apple_probe(struct hid_device *hdev, if (quirks & APPLE_IGNORE_MOUSE && hdev->type == HID_TYPE_USBMOUSE) return -ENODEV; - asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL); + asc = devm_kzalloc_obj(&hdev->dev, *asc); if (asc == NULL) { hid_err(hdev, "can't alloc apple descriptor\n"); return -ENOMEM; diff --git a/drivers/hid/hid-appleir.c b/drivers/hid/hid-appleir.c index adaa44a858edd9..22b80c4bde7b7e 100644 --- a/drivers/hid/hid-appleir.c +++ b/drivers/hid/hid-appleir.c @@ -296,7 +296,7 @@ static int appleir_probe(struct hid_device *hid, const struct hid_device_id *id) int ret; struct appleir *appleir; - appleir = devm_kzalloc(&hid->dev, sizeof(struct appleir), GFP_KERNEL); + appleir = devm_kzalloc_obj(&hid->dev, struct appleir); if (!appleir) return -ENOMEM; diff --git a/drivers/hid/hid-appletb-bl.c b/drivers/hid/hid-appletb-bl.c index bad2aead878019..f5015fbe224ef0 100644 --- a/drivers/hid/hid-appletb-bl.c +++ b/drivers/hid/hid-appletb-bl.c @@ -124,7 +124,7 @@ static int appletb_bl_probe(struct hid_device *hdev, const struct hid_device_id if (aux1_field->report != brightness_field->report) return dev_err_probe(dev, -ENODEV, "Encountered unexpected report structure\n"); - bl = devm_kzalloc(dev, sizeof(*bl), GFP_KERNEL); + bl = devm_kzalloc_obj(dev, *bl); if (!bl) return -ENOMEM; diff --git a/drivers/hid/hid-appletb-kbd.c b/drivers/hid/hid-appletb-kbd.c index 3cc3a13b71a63d..ed82945be76216 100644 --- a/drivers/hid/hid-appletb-kbd.c +++ b/drivers/hid/hid-appletb-kbd.c @@ -447,7 +447,7 @@ static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id if (!mode_field) return -ENODEV; - kbd = devm_kzalloc(dev, sizeof(*kbd), GFP_KERNEL); + kbd = devm_kzalloc_obj(dev, *kbd); if (!kbd) return -ENOMEM; diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index f6aa1be09ad538..d7b044b3a831c6 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -816,7 +816,7 @@ static void asus_work(struct work_struct *work) static int asus_worker_create(struct hid_device *hdev, struct asus_drvdata *drvdata) { - drvdata->worker = devm_kzalloc(&hdev->dev, sizeof(struct asus_worker), GFP_KERNEL); + drvdata->worker = devm_kzalloc_obj(&hdev->dev, struct asus_worker); if (!drvdata->worker) return -ENOMEM; @@ -1439,7 +1439,7 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata) const char *name; int ret; - drvdata->xgm_led = devm_kzalloc(&hdev->dev, sizeof(*drvdata->xgm_led), GFP_KERNEL); + drvdata->xgm_led = devm_kzalloc_obj(&hdev->dev, *drvdata->xgm_led); if (drvdata->xgm_led == NULL) return -ENOMEM; @@ -1513,7 +1513,7 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) bool is_vendor = false; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (drvdata == NULL) return -ENOMEM; diff --git a/drivers/hid/hid-bigbenff.c b/drivers/hid/hid-bigbenff.c index 3c87317ccc6bf9..08e0e9ab37ca39 100644 --- a/drivers/hid/hid-bigbenff.c +++ b/drivers/hid/hid-bigbenff.c @@ -435,7 +435,7 @@ static int bigben_probe(struct hid_device *hid, const struct hid_device_id *id) struct bigben_device *bigben; int error; - bigben = devm_kzalloc(&hid->dev, sizeof(*bigben), GFP_KERNEL); + bigben = devm_kzalloc_obj(&hid->dev, *bigben); if (!bigben) return -ENOMEM; diff --git a/drivers/hid/hid-corsair-void.c b/drivers/hid/hid-corsair-void.c index 7be8c974d11e92..1b12eb190fa068 100644 --- a/drivers/hid/hid-corsair-void.c +++ b/drivers/hid/hid-corsair-void.c @@ -649,8 +649,7 @@ static int corsair_void_probe(struct hid_device *hid_dev, if (!hid_is_usb(hid_dev)) return -EINVAL; - drvdata = devm_kzalloc(&hid_dev->dev, sizeof(*drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hid_dev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-corsair.c b/drivers/hid/hid-corsair.c index 278c6efb565dfe..3e80f22c6cc892 100644 --- a/drivers/hid/hid-corsair.c +++ b/drivers/hid/hid-corsair.c @@ -561,8 +561,7 @@ static int corsair_probe(struct hid_device *dev, const struct hid_device_id *id) usbif = to_usb_interface(dev->dev.parent); - drvdata = devm_kzalloc(&dev->dev, sizeof(struct corsair_drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&dev->dev, struct corsair_drvdata); if (drvdata == NULL) return -ENOMEM; drvdata->quirks = quirks; diff --git a/drivers/hid/hid-cougar.c b/drivers/hid/hid-cougar.c index 7156658166f51e..c8ae18f1322399 100644 --- a/drivers/hid/hid-cougar.c +++ b/drivers/hid/hid-cougar.c @@ -198,7 +198,7 @@ static int cougar_probe(struct hid_device *hdev, unsigned int connect_mask; int error; - cougar = devm_kzalloc(&hdev->dev, sizeof(*cougar), GFP_KERNEL); + cougar = devm_kzalloc_obj(&hdev->dev, *cougar); if (!cougar) return -ENOMEM; hid_set_drvdata(hdev, cougar); diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 6b938f75e72fdb..597797155dcff5 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -1227,7 +1227,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id) u32 addr; int ret; - dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&hdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/hid/hid-creative-sb0540.c b/drivers/hid/hid-creative-sb0540.c index dfd6add353d19a..ecbd148d7b9800 100644 --- a/drivers/hid/hid-creative-sb0540.c +++ b/drivers/hid/hid-creative-sb0540.c @@ -223,8 +223,7 @@ static int creative_sb0540_probe(struct hid_device *hid, int ret; struct creative_sb0540 *creative_sb0540; - creative_sb0540 = devm_kzalloc(&hid->dev, - sizeof(struct creative_sb0540), GFP_KERNEL); + creative_sb0540 = devm_kzalloc_obj(&hid->dev, struct creative_sb0540); if (!creative_sb0540) return -ENOMEM; diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c index f18fddc176d013..282c76fb5634c7 100644 --- a/drivers/hid/hid-cypress.c +++ b/drivers/hid/hid-cypress.c @@ -135,7 +135,7 @@ static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id) int ret; struct cp_device *cp_device; - cp_device = devm_kzalloc(&hdev->dev, sizeof(*cp_device), GFP_KERNEL); + cp_device = devm_kzalloc_obj(&hdev->dev, *cp_device); if (!cp_device) return -ENOMEM; diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 0190ad567ce4d4..7c6ba1adfd982b 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c @@ -463,7 +463,7 @@ static int elan_probe(struct hid_device *hdev, const struct hid_device_id *id) int ret; struct elan_drvdata *drvdata; - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 64c9c940db46e4..3bcae8cf814e99 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -1010,7 +1010,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) if (!hid_is_usb(hdev)) return -EINVAL; - dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&hdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/hid/hid-goodix-spi.c b/drivers/hid/hid-goodix-spi.c index 03d549efbdceff..a2c6b92f74ee89 100644 --- a/drivers/hid/hid-goodix-spi.c +++ b/drivers/hid/hid-goodix-spi.c @@ -686,7 +686,7 @@ static int goodix_spi_probe(struct spi_device *spi) if (error) return error; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 847b1ddefeeca9..6296eb686ca99c 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -342,8 +342,7 @@ static int hammer_register_leds(struct hid_device *hdev) { struct hammer_kbd_leds *kbd_backlight; - kbd_backlight = devm_kzalloc(&hdev->dev, sizeof(*kbd_backlight), - GFP_KERNEL); + kbd_backlight = devm_kzalloc_obj(&hdev->dev, *kbd_backlight); if (!kbd_backlight) return -ENOMEM; @@ -482,7 +481,7 @@ static int hammer_probe(struct hid_device *hdev, struct vivaldi_data *vdata; int error; - vdata = devm_kzalloc(&hdev->dev, sizeof(*vdata), GFP_KERNEL); + vdata = devm_kzalloc_obj(&hdev->dev, *vdata); if (!vdata) return -ENOMEM; diff --git a/drivers/hid/hid-google-stadiaff.c b/drivers/hid/hid-google-stadiaff.c index 0214aae6b0fad4..c7b27684cd3b31 100644 --- a/drivers/hid/hid-google-stadiaff.c +++ b/drivers/hid/hid-google-stadiaff.c @@ -89,8 +89,7 @@ static int stadia_input_configured(struct hid_device *hid, struct hid_input *hid if (!report) return -ENODEV; - stadiaff = devm_kzalloc(&hid->dev, sizeof(struct stadiaff_device), - GFP_KERNEL); + stadiaff = devm_kzalloc_obj(&hid->dev, struct stadiaff_device); if (!stadiaff) return -ENOMEM; diff --git a/drivers/hid/hid-gt683r.c b/drivers/hid/hid-gt683r.c index 29ccb0accfba81..10270fa1c5d823 100644 --- a/drivers/hid/hid-gt683r.c +++ b/drivers/hid/hid-gt683r.c @@ -229,7 +229,7 @@ static int gt683r_led_probe(struct hid_device *hdev, char *name; struct gt683r_led *led; - led = devm_kzalloc(&hdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&hdev->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c index 8760eeb08b2cdd..b7fadfbddc4cd8 100644 --- a/drivers/hid/hid-haptic.c +++ b/drivers/hid/hid-haptic.c @@ -426,14 +426,12 @@ int hid_haptic_init(struct hid_device *hdev, haptic->max_waveform_id = max(2u, haptic->max_waveform_id); haptic->max_duration_id = max(2u, haptic->max_duration_id); - haptic->hid_usage_map = kcalloc(haptic->max_waveform_id + 1, - sizeof(u16), GFP_KERNEL); + haptic->hid_usage_map = kzalloc_objs(u16, haptic->max_waveform_id + 1); if (!haptic->hid_usage_map) { ret = -ENOMEM; goto exit; } - haptic->duration_map = kcalloc(haptic->max_duration_id + 1, - sizeof(u32), GFP_KERNEL); + haptic->duration_map = kzalloc_objs(u32, haptic->max_duration_id + 1); if (!haptic->duration_map) { ret = -ENOMEM; goto usage_map; diff --git a/drivers/hid/hid-hyperx.c b/drivers/hid/hid-hyperx.c index 18d2dc24cc76c8..8a79c3d2ad2fb5 100644 --- a/drivers/hid/hid-hyperx.c +++ b/drivers/hid/hid-hyperx.c @@ -83,7 +83,7 @@ static int hyperx_probe(struct hid_device *hdev, const struct hid_device_id *id) struct hyperx_drvdata *drvdata; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index edd6bbf8342b58..a4d3536c7af29a 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -562,11 +562,11 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, if (quirks & HID_BATTERY_QUIRK_IGNORE) return 0; - bat = devm_kzalloc(&dev->dev, sizeof(*bat), GFP_KERNEL); + bat = devm_kzalloc_obj(&dev->dev, *bat); if (!bat) return -ENOMEM; - psy_desc = devm_kzalloc(&dev->dev, sizeof(*psy_desc), GFP_KERNEL); + psy_desc = devm_kzalloc_obj(&dev->dev, *psy_desc); if (!psy_desc) { error = -ENOMEM; goto err_free_bat; diff --git a/drivers/hid/hid-led.c b/drivers/hid/hid-led.c index 7d82f8d426bbcb..d5893c3ad46ef7 100644 --- a/drivers/hid/hid-led.c +++ b/drivers/hid/hid-led.c @@ -451,7 +451,7 @@ static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id) unsigned int minor; int ret, i; - ldev = devm_kzalloc(&hdev->dev, sizeof(*ldev), GFP_KERNEL); + ldev = devm_kzalloc_obj(&hdev->dev, *ldev); if (!ldev) return -ENOMEM; @@ -479,8 +479,8 @@ static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - ldev->rgb = devm_kcalloc(&hdev->dev, ldev->config->num_leds, - sizeof(struct hidled_rgb), GFP_KERNEL); + ldev->rgb = devm_kzalloc_objs(&hdev->dev, struct hidled_rgb, + ldev->config->num_leds); if (!ldev->rgb) return -ENOMEM; diff --git a/drivers/hid/hid-lenovo-go-s.c b/drivers/hid/hid-lenovo-go-s.c index 7102786ce1246c..c922ed6ef83f78 100644 --- a/drivers/hid/hid-lenovo-go-s.c +++ b/drivers/hid/hid-lenovo-go-s.c @@ -1624,7 +1624,7 @@ static int hid_gos_cfg_probe(struct hid_device *hdev, struct gos_cfg_drvdata *drvdata; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(struct gos_cfg_drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, struct gos_cfg_drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 617bba6626592e..30bd3f794243be 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -1257,9 +1257,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev) if (ret) hid_warn(hdev, "Could not create sysfs group: %d\n", ret); - data_pointer = devm_kzalloc(&hdev->dev, - sizeof(struct lenovo_drvdata), - GFP_KERNEL); + data_pointer = devm_kzalloc_obj(&hdev->dev, struct lenovo_drvdata); if (data_pointer == NULL) { hid_err(hdev, "Could not allocate memory for driver data\n"); ret = -ENOMEM; @@ -1297,9 +1295,7 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev) return 0; } - cptkbd_data = devm_kzalloc(&hdev->dev, - sizeof(*cptkbd_data), - GFP_KERNEL); + cptkbd_data = devm_kzalloc_obj(&hdev->dev, *cptkbd_data); if (cptkbd_data == NULL) { hid_err(hdev, "can't alloc keyboard descriptor\n"); return -ENOMEM; @@ -1351,7 +1347,7 @@ static int lenovo_probe_tp10ubkbd(struct hid_device *hdev) if (!found) return 0; - data = devm_kzalloc(&hdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&hdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hid/hid-letsketch.c b/drivers/hid/hid-letsketch.c index b52e93a91ae542..51f43324ddb8d0 100644 --- a/drivers/hid/hid-letsketch.c +++ b/drivers/hid/hid-letsketch.c @@ -286,7 +286,7 @@ static int letsketch_probe(struct hid_device *hdev, const struct hid_device_id * if (ret) return ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hid/hid-lg-g15.c b/drivers/hid/hid-lg-g15.c index 02ef3e2094b4c5..c2a83b006afa6d 100644 --- a/drivers/hid/hid-lg-g15.c +++ b/drivers/hid/hid-lg-g15.c @@ -966,7 +966,7 @@ static void lg_g15_setup_led_rgb(struct lg_g15_data *g15, int index) gled->mcdev.led_cdev.max_brightness = 255; gled->mcdev.num_colors = 3; - subled_info = devm_kcalloc(&g15->hdev->dev, 3, sizeof(*subled_info), GFP_KERNEL); + subled_info = devm_kzalloc_objs(&g15->hdev->dev, *subled_info, 3); if (!subled_info) return; @@ -1148,7 +1148,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id) if (!has_ff000000) return hid_hw_start(hdev, HID_CONNECT_DEFAULT); - g15 = devm_kzalloc(&hdev->dev, sizeof(*g15), GFP_KERNEL); + g15 = devm_kzalloc_obj(&hdev->dev, *g15); if (!g15) return -ENOMEM; diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 27d83b8bbaaf31..60fc6b86a08571 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -3135,8 +3135,7 @@ static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id) struct hidpp_device *hidpp = hid_get_drvdata(hdev); struct wtp_data *wd; - wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data), - GFP_KERNEL); + wd = devm_kzalloc_obj(&hdev->dev, struct wtp_data); if (!wd) return -ENOMEM; @@ -3391,8 +3390,7 @@ static int k400_allocate(struct hid_device *hdev) struct hidpp_device *hidpp = hid_get_drvdata(hdev); struct k400_private_data *k400; - k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data), - GFP_KERNEL); + k400 = devm_kzalloc_obj(&hdev->dev, struct k400_private_data); if (!k400) return -ENOMEM; @@ -4675,7 +4673,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) unsigned int connect_mask = HID_CONNECT_DEFAULT; /* report_fixup needs drvdata to be set before we call hid_parse */ - hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); + hidpp = devm_kzalloc_obj(&hdev->dev, *hidpp); if (!hidpp) return -ENOMEM; diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index e6d4d493052684..a01e84a18dedeb 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -901,7 +901,7 @@ static int magicmouse_probe(struct hid_device *hdev, struct hid_report *report; int ret; - msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL); + msc = devm_kzalloc_obj(&hdev->dev, *msc); if (msc == NULL) { hid_err(hdev, "can't alloc magicmouse descriptor\n"); return -ENOMEM; diff --git a/drivers/hid/hid-mcp2200.c b/drivers/hid/hid-mcp2200.c index c6fd5fb5d57854..45cf4becae91e0 100644 --- a/drivers/hid/hid-mcp2200.c +++ b/drivers/hid/hid-mcp2200.c @@ -329,7 +329,7 @@ static int mcp2200_probe(struct hid_device *hdev, const struct hid_device_id *id int ret; struct mcp2200 *mcp; - mcp = devm_kzalloc(&hdev->dev, sizeof(*mcp), GFP_KERNEL); + mcp = devm_kzalloc_obj(&hdev->dev, *mcp); if (!mcp) return -ENOMEM; diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 053377dbced210..3f05d6e288f9af 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -1252,7 +1252,7 @@ static int mcp2221_probe(struct hid_device *hdev, int ret; struct mcp2221 *mcp; - mcp = devm_kzalloc(&hdev->dev, sizeof(*mcp), GFP_KERNEL); + mcp = devm_kzalloc_obj(&hdev->dev, *mcp); if (!mcp) return -ENOMEM; @@ -1323,7 +1323,7 @@ static int mcp2221_probe(struct hid_device *hdev, #if IS_REACHABLE(CONFIG_GPIOLIB) /* Setup GPIO chip */ - mcp->gc = devm_kzalloc(&hdev->dev, sizeof(*mcp->gc), GFP_KERNEL); + mcp->gc = devm_kzalloc_obj(&hdev->dev, *mcp->gc); if (!mcp->gc) return -ENOMEM; diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c index a7d3493a6141e5..226733718c488d 100644 --- a/drivers/hid/hid-microsoft.c +++ b/drivers/hid/hid-microsoft.c @@ -337,9 +337,8 @@ static int ms_input_configured(struct hid_device *hdev, struct hid_input *hidinp ms->hdev = hdev; INIT_WORK(&ms->ff_worker, ms_ff_worker); - ms->output_report_dmabuf = devm_kzalloc(&hdev->dev, - sizeof(struct xb1s_ff_report), - GFP_KERNEL); + ms->output_report_dmabuf = devm_kzalloc_obj(&hdev->dev, + struct xb1s_ff_report); if (ms->output_report_dmabuf == NULL) return -ENOMEM; @@ -353,7 +352,7 @@ static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) struct ms_data *ms; int ret; - ms = devm_kzalloc(&hdev->dev, sizeof(*ms), GFP_KERNEL); + ms = devm_kzalloc_obj(&hdev->dev, *ms); if (ms == NULL) return -ENOMEM; diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c index 3225d3bf612545..23d731f700c90c 100644 --- a/drivers/hid/hid-msi.c +++ b/drivers/hid/hid-msi.c @@ -1829,7 +1829,7 @@ static int claw_probe(struct hid_device *hdev, u8 ep) struct claw_drvdata *drvdata; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 4e19a0c4d2381d..3afca07025ea75 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -623,7 +623,7 @@ static struct mt_usages *mt_allocate_usage(struct hid_device *hdev, { struct mt_usages *usage; - usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL); + usage = devm_kzalloc_obj(&hdev->dev, *usage); if (!usage) return NULL; @@ -652,8 +652,7 @@ static struct mt_application *mt_allocate_application(struct mt_device *td, unsigned int application = report->application; struct mt_application *mt_application; - mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application), - GFP_KERNEL); + mt_application = devm_kzalloc_obj(&td->hdev->dev, *mt_application); if (!mt_application) return NULL; @@ -711,7 +710,7 @@ static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, struct hid_field *field; int r, n; - rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL); + rdata = devm_kzalloc_obj(&td->hdev->dev, *rdata); if (!rdata) return NULL; @@ -2127,12 +2126,12 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) } } - td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); + td = devm_kzalloc_obj(&hdev->dev, struct mt_device); if (!td) { dev_err(&hdev->dev, "cannot allocate multitouch data\n"); return -ENOMEM; } - td->haptic = devm_kzalloc(&hdev->dev, sizeof(*(td->haptic)), GFP_KERNEL); + td->haptic = devm_kzalloc_obj(&hdev->dev, *(td->haptic)); if (!td->haptic) return -ENOMEM; diff --git a/drivers/hid/hid-nintendo-switch2-usb.c b/drivers/hid/hid-nintendo-switch2-usb.c index 8b3b6841035d06..623473f3d21612 100644 --- a/drivers/hid/hid-nintendo-switch2-usb.c +++ b/drivers/hid/hid-nintendo-switch2-usb.c @@ -359,7 +359,7 @@ static int switch2_usb_probe(struct usb_interface *intf, const struct usb_device return ret; } - ns2_usb = devm_kzalloc(&intf->dev, sizeof(*ns2_usb), GFP_KERNEL); + ns2_usb = devm_kzalloc_obj(&intf->dev, *ns2_usb); if (!ns2_usb) return -ENOMEM; diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c index 4d40f67f3e6401..eb3274db8ccbac 100644 --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -2730,7 +2730,7 @@ static int joycon_probe(struct hid_device *hdev, hid_dbg(hdev, "probe - start\n"); - ctlr = devm_kzalloc(&hdev->dev, sizeof(*ctlr), GFP_KERNEL); + ctlr = devm_kzalloc_obj(&hdev->dev, *ctlr); if (!ctlr) { ret = -ENOMEM; goto err; @@ -3687,7 +3687,7 @@ static int switch2_init_input(struct switch2_controller *ns2) player_led_pattern = ns2->player_id % JC_NUM_LED_PATTERNS; hid_dbg(hdev, "assigned player %d led pattern", player_led_pattern + 1); - ns2->leds = devm_kcalloc(&input->dev, JC_NUM_LEDS, sizeof(*ns2->leds), GFP_KERNEL); + ns2->leds = devm_kzalloc_objs(&input->dev, *ns2->leds, JC_NUM_LEDS); if (!ns2->leds) { input_unregister_device(input); return -ENOMEM; diff --git a/drivers/hid/hid-nvidia-shield.c b/drivers/hid/hid-nvidia-shield.c index b0c40a245bf848..9d81a686d2b7fc 100644 --- a/drivers/hid/hid-nvidia-shield.c +++ b/drivers/hid/hid-nvidia-shield.c @@ -864,7 +864,7 @@ static struct shield_device *thunderstrike_create(struct hid_device *hdev) struct thunderstrike *ts; int ret; - ts = devm_kzalloc(&hdev->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&hdev->dev, *ts); if (!ts) return ERR_PTR(-ENOMEM); diff --git a/drivers/hid/hid-oxp.c b/drivers/hid/hid-oxp.c index 1e691ebc1199e6..2b6432fec1ea03 100644 --- a/drivers/hid/hid-oxp.c +++ b/drivers/hid/hid-oxp.c @@ -1483,12 +1483,12 @@ static int oxp_cfg_probe(struct hid_device *hdev, u16 up) return 0; skip_rgb: - bmap_1 = devm_kzalloc(&hdev->dev, sizeof(struct oxp_bmap_page_1), GFP_KERNEL); + bmap_1 = devm_kzalloc_obj(&hdev->dev, struct oxp_bmap_page_1); if (!bmap_1) return dev_err_probe(&hdev->dev, -ENOMEM, "Unable to allocate button map page 1\n"); - bmap_2 = devm_kzalloc(&hdev->dev, sizeof(struct oxp_bmap_page_2), GFP_KERNEL); + bmap_2 = devm_kzalloc_obj(&hdev->dev, struct oxp_bmap_page_2); if (!bmap_2) return dev_err_probe(&hdev->dev, -ENOMEM, "Unable to allocate button map page 2\n"); diff --git a/drivers/hid/hid-plantronics.c b/drivers/hid/hid-plantronics.c index acb9eb18f7ccfe..7186dbd27c79c4 100644 --- a/drivers/hid/hid-plantronics.c +++ b/drivers/hid/hid-plantronics.c @@ -186,7 +186,7 @@ static int plantronics_probe(struct hid_device *hdev, struct plt_drv_data *drv_data; int ret; - drv_data = devm_kzalloc(&hdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&hdev->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index f9dc9378cf777d..143eb891e4a1a7 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -877,8 +877,8 @@ static int ps_lightbar_register(struct ps_device *ps_dev, struct led_classdev_mc struct led_classdev *led_cdev; int ret; - mc_led_info = devm_kmalloc_array(&hdev->dev, 3, sizeof(*mc_led_info), - GFP_KERNEL | __GFP_ZERO); + mc_led_info = devm_kmalloc_objs(&hdev->dev, *mc_led_info, 3, + GFP_KERNEL | __GFP_ZERO); if (!mc_led_info) return -ENOMEM; @@ -1754,7 +1754,7 @@ static struct ps_device *dualsense_create(struct hid_device *hdev) dualsense_player_led_set_brightness } }; - ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(&hdev->dev, *ds); if (!ds) return ERR_PTR(-ENOMEM); @@ -2747,7 +2747,7 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev) dualshock4_led_set_brightness, dualshock4_led_set_blink }, }; - ds4 = devm_kzalloc(&hdev->dev, sizeof(*ds4), GFP_KERNEL); + ds4 = devm_kzalloc_obj(&hdev->dev, *ds4); if (!ds4) return ERR_PTR(-ENOMEM); diff --git a/drivers/hid/hid-pulsar.c b/drivers/hid/hid-pulsar.c index b0b34849f2b378..a1f0dcda92dfef 100644 --- a/drivers/hid/hid-pulsar.c +++ b/drivers/hid/hid-pulsar.c @@ -655,7 +655,7 @@ static int pulsar_probe(struct hid_device *hdev, const struct hid_device_id *id) intf->cur_altsetting->desc.bInterfaceNumber != USB_INTERFACE) return hid_hw_start(hdev, HID_CONNECT_DEFAULT); - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-pxrc.c b/drivers/hid/hid-pxrc.c index e3755d8b85c226..87a906d7da54dc 100644 --- a/drivers/hid/hid-pxrc.c +++ b/drivers/hid/hid-pxrc.c @@ -75,7 +75,7 @@ static int pxrc_probe(struct hid_device *hdev, const struct hid_device_id *id) int ret; struct pxrc_priv *priv; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; hid_set_drvdata(hdev, priv); diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c index ecc19387f6b056..20dda1992f98d4 100644 --- a/drivers/hid/hid-rmi.c +++ b/drivers/hid/hid-rmi.c @@ -669,7 +669,7 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id) struct hid_report *output_report; struct hid_report *feature_report; - data = devm_kzalloc(&hdev->dev, sizeof(struct rmi_data), GFP_KERNEL); + data = devm_kzalloc_obj(&hdev->dev, struct rmi_data); if (!data) return -ENOMEM; diff --git a/drivers/hid/hid-saitek.c b/drivers/hid/hid-saitek.c index 6fe7c087c594ea..71f23dbf290ebb 100644 --- a/drivers/hid/hid-saitek.c +++ b/drivers/hid/hid-saitek.c @@ -40,7 +40,7 @@ static int saitek_probe(struct hid_device *hdev, struct saitek_sc *ssc; int ret; - ssc = devm_kzalloc(&hdev->dev, sizeof(*ssc), GFP_KERNEL); + ssc = devm_kzalloc_obj(&hdev->dev, *ssc); if (ssc == NULL) { hid_err(hdev, "can't alloc saitek descriptor\n"); return -ENOMEM; diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index c2b425afd951be..c12272479d82df 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -977,8 +977,7 @@ static int hid_sensor_custom_probe(struct platform_device *pdev) int ret; const struct hid_sensor_custom_match *match; - sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), - GFP_KERNEL); + sensor_inst = devm_kzalloc_obj(&pdev->dev, *sensor_inst); if (!sensor_inst) return -ENOMEM; diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 6470a290ebfc5b..81c8e723f9bacf 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -685,7 +685,7 @@ static int sensor_hub_probe(struct hid_device *hdev, struct hid_sensor_hub_device *last_hsdev = NULL; struct hid_sensor_hub_device *collection_hsdev = NULL; - sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&hdev->dev, *sd); if (!sd) { hid_err(hdev, "cannot allocate Sensor data\n"); return -ENOMEM; @@ -717,10 +717,9 @@ static int sensor_hub_probe(struct hid_device *hdev, ret = -EINVAL; goto err_stop_hw; } - sd->hid_sensor_hub_client_devs = devm_kcalloc(&hdev->dev, - dev_cnt, - sizeof(struct mfd_cell), - GFP_KERNEL); + sd->hid_sensor_hub_client_devs = devm_kzalloc_objs(&hdev->dev, + struct mfd_cell, + dev_cnt); if (sd->hid_sensor_hub_client_devs == NULL) { hid_err(hdev, "Failed to allocate memory for mfd cells\n"); ret = -ENOMEM; @@ -733,8 +732,7 @@ static int sensor_hub_probe(struct hid_device *hdev, if (collection->type == HID_COLLECTION_PHYSICAL || collection->type == HID_COLLECTION_APPLICATION) { - hsdev = devm_kzalloc(&hdev->dev, sizeof(*hsdev), - GFP_KERNEL); + hsdev = devm_kzalloc_obj(&hdev->dev, *hsdev); if (!hsdev) { hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); ret = -ENOMEM; @@ -744,9 +742,8 @@ static int sensor_hub_probe(struct hid_device *hdev, hsdev->vendor_id = hdev->vendor; hsdev->product_id = hdev->product; hsdev->usage = collection->usage; - hsdev->mutex_ptr = devm_kzalloc(&hdev->dev, - sizeof(struct mutex), - GFP_KERNEL); + hsdev->mutex_ptr = devm_kzalloc_obj(&hdev->dev, + struct mutex); if (!hsdev->mutex_ptr) { ret = -ENOMEM; goto err_stop_hw; diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 50f5ad6bbeb4c1..228e7481903726 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -602,7 +602,7 @@ static int ghl_init_urb(struct sony_sc *sc, struct usb_device *usbdev, pipe = usb_sndctrlpipe(usbdev, 0); - cr = devm_kzalloc(&sc->hdev->dev, sizeof(*cr), GFP_ATOMIC); + cr = devm_kzalloc_obj(&sc->hdev->dev, *cr, GFP_ATOMIC); if (!cr) return -ENOMEM; @@ -2338,7 +2338,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) !strcmp(hdev->name, "ShanWan PS(R) Ga`epad")) quirks |= SHANWAN_GAMEPAD; - sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); + sc = devm_kzalloc_obj(&hdev->dev, *sc); if (!sc) return -ENOMEM; diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index 0f364d43aa4b3d..b9a788be9efefb 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -1758,7 +1758,7 @@ static int steam_probe(struct hid_device *hdev, if (!steam_is_valve_interface(hdev, id->driver_data)) return hid_hw_start(hdev, HID_CONNECT_DEFAULT); - steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); + steam = devm_kzalloc_obj(&hdev->dev, *steam); if (!steam) return -ENOMEM; diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c index 7292da0313e112..0170276091b9f1 100644 --- a/drivers/hid/hid-steelseries.c +++ b/drivers/hid/hid-steelseries.c @@ -261,7 +261,7 @@ static int steelseries_srws1_probe(struct hid_device *hdev, size_t name_sz; char *name; - drv_data = devm_kzalloc(&hdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&hdev->dev, *drv_data); if (drv_data == NULL) { hid_err(hdev, "can't alloc SRW-S1 memory\n"); return -ENOMEM; @@ -578,7 +578,7 @@ static int steelseries_probe(struct hid_device *hdev, const struct hid_device_id #endif } - sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&hdev->dev, *sd); if (!sd) return -ENOMEM; hid_set_drvdata(hdev, sd); diff --git a/drivers/hid/hid-u2fzero.c b/drivers/hid/hid-u2fzero.c index 82404b6e2d253d..8ad6a1f4b5c208 100644 --- a/drivers/hid/hid-u2fzero.c +++ b/drivers/hid/hid-u2fzero.c @@ -313,7 +313,7 @@ static int u2fzero_probe(struct hid_device *hdev, if (!hid_is_usb(hdev)) return -EINVAL; - dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&hdev->dev, *dev); if (dev == NULL) return -ENOMEM; diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 0b8a83fa6c5be7..eea4238b942138 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -214,7 +214,7 @@ static int uclogic_probe(struct hid_device *hdev, hdev->quirks |= HID_QUIRK_HIDINPUT_FORCE; /* Allocate and assign driver data */ - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (drvdata == NULL) { rc = -ENOMEM; goto failure; diff --git a/drivers/hid/hid-udraw-ps3.c b/drivers/hid/hid-udraw-ps3.c index b2e17ef2ea275e..bf9cac524df37e 100644 --- a/drivers/hid/hid-udraw-ps3.c +++ b/drivers/hid/hid-udraw-ps3.c @@ -409,7 +409,7 @@ static int udraw_probe(struct hid_device *hdev, const struct hid_device_id *id) struct udraw *udraw; int ret; - udraw = devm_kzalloc(&hdev->dev, sizeof(struct udraw), GFP_KERNEL); + udraw = devm_kzalloc_obj(&hdev->dev, struct udraw); if (!udraw) return -ENOMEM; diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c index cda5938fb07060..6ee6e617536bdc 100644 --- a/drivers/hid/hid-vivaldi.c +++ b/drivers/hid/hid-vivaldi.c @@ -20,7 +20,7 @@ static int vivaldi_probe(struct hid_device *hdev, struct vivaldi_data *drvdata; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hid/hid-zydacron.c b/drivers/hid/hid-zydacron.c index 02de153d5628c3..0b739d0cbbc79d 100644 --- a/drivers/hid/hid-zydacron.c +++ b/drivers/hid/hid-zydacron.c @@ -169,7 +169,7 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id) int ret; struct zc_device *zc; - zc = devm_kzalloc(&hdev->dev, sizeof(*zc), GFP_KERNEL); + zc = devm_kzalloc_obj(&hdev->dev, *zc); if (zc == NULL) { hid_err(hdev, "can't alloc descriptor\n"); return -ENOMEM; diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c index 9371db200fc4da..4362c85dfa7eac 100644 --- a/drivers/hid/i2c-hid/i2c-hid-acpi.c +++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c @@ -78,7 +78,7 @@ static int i2c_hid_acpi_probe(struct i2c_client *client) return ret; hid_descriptor_address = ret; - ihid_acpi = devm_kzalloc(dev, sizeof(*ihid_acpi), GFP_KERNEL); + ihid_acpi = devm_kzalloc_obj(dev, *ihid_acpi); if (!ihid_acpi) return -ENOMEM; diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index a8a9854854f523..896ce29e7647ef 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -1249,7 +1249,7 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, return client->irq; } - ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); + ihid = devm_kzalloc_obj(&client->dev, *ihid); if (!ihid) return -ENOMEM; diff --git a/drivers/hid/i2c-hid/i2c-hid-of-elan.c b/drivers/hid/i2c-hid/i2c-hid-of-elan.c index 919e32c47e12c4..667d5e28e747c6 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of-elan.c +++ b/drivers/hid/i2c-hid/i2c-hid-of-elan.c @@ -101,7 +101,7 @@ static int i2c_hid_of_elan_probe(struct i2c_client *client) int ret; u32 quirks = 0; - ihid_elan = devm_kzalloc(&client->dev, sizeof(*ihid_elan), GFP_KERNEL); + ihid_elan = devm_kzalloc_obj(&client->dev, *ihid_elan); if (!ihid_elan) return -ENOMEM; diff --git a/drivers/hid/i2c-hid/i2c-hid-of-goodix.c b/drivers/hid/i2c-hid/i2c-hid-of-goodix.c index f4dbcd1d1d4729..26049399d21003 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of-goodix.c +++ b/drivers/hid/i2c-hid/i2c-hid-of-goodix.c @@ -82,8 +82,7 @@ static int i2c_hid_of_goodix_probe(struct i2c_client *client) { struct i2c_hid_of_goodix *ihid_goodix; - ihid_goodix = devm_kzalloc(&client->dev, sizeof(*ihid_goodix), - GFP_KERNEL); + ihid_goodix = devm_kzalloc_obj(&client->dev, *ihid_goodix); if (!ihid_goodix) return -ENOMEM; diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c index 59393d71ddb9df..ec26652272fef3 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of.c +++ b/drivers/hid/i2c-hid/i2c-hid-of.c @@ -83,7 +83,7 @@ static int i2c_hid_of_probe(struct i2c_client *client) int ret; u32 val; - ihid_of = devm_kzalloc(dev, sizeof(*ihid_of), GFP_KERNEL); + ihid_of = devm_kzalloc_obj(dev, *ihid_of); if (!ihid_of) return -ENOMEM; diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index abf9c9a31c3965..1b2b0e05f7b701 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -980,9 +980,7 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) for (i = 0; i < IPC_TX_FIFO_SIZE; i++) { struct wr_msg_ctl_info *tx_buf; - tx_buf = devm_kzalloc(&pdev->dev, - sizeof(struct wr_msg_ctl_info), - GFP_KERNEL); + tx_buf = devm_kzalloc_obj(&pdev->dev, struct wr_msg_ctl_info); if (!tx_buf) { /* * IPC buffers may be limited or not available diff --git a/drivers/hid/intel-ish-hid/ishtp-fw-loader.c b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c index f4a671d6386ce5..ac2dd247250fad 100644 --- a/drivers/hid/intel-ish-hid/ishtp-fw-loader.c +++ b/drivers/hid/intel-ish-hid/ishtp-fw-loader.c @@ -916,9 +916,7 @@ static int loader_ishtp_cl_probe(struct ishtp_cl_device *cl_device) struct ishtp_cl_data *client_data; int rv; - client_data = devm_kzalloc(ishtp_device(cl_device), - sizeof(*client_data), - GFP_KERNEL); + client_data = devm_kzalloc_obj(ishtp_device(cl_device), *client_data); if (!client_data) return -ENOMEM; diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index ec5e8afe77bd41..4a56fb3eb36632 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -125,11 +125,9 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, break; client_data->hid_dev_count = (unsigned int)*payload; if (!client_data->hid_devices) - client_data->hid_devices = devm_kcalloc( - cl_data_to_dev(client_data), - client_data->hid_dev_count, - sizeof(struct device_info), - GFP_KERNEL); + client_data->hid_devices = devm_kzalloc_objs(cl_data_to_dev(client_data), + struct device_info, + client_data->hid_dev_count); if (!client_data->hid_devices) { dev_err(cl_data_to_dev(client_data), "Mem alloc failed for hid device info\n"); @@ -793,9 +791,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) if (!cl_device) return -ENODEV; - client_data = devm_kzalloc(ishtp_device(cl_device), - sizeof(*client_data), - GFP_KERNEL); + client_data = devm_kzalloc_obj(ishtp_device(cl_device), *client_data); if (!client_data) return -ENOMEM; diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c index 7a913f717efaad..29319b6227f3f6 100644 --- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c @@ -389,7 +389,7 @@ static struct quicki2c_device *quicki2c_dev_init(struct pci_dev *pdev, void __io struct quicki2c_device *qcdev; int ret; - qcdev = devm_kzalloc(dev, sizeof(struct quicki2c_device), GFP_KERNEL); + qcdev = devm_kzalloc_obj(dev, struct quicki2c_device); if (!qcdev) return ERR_PTR(-ENOMEM); diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index 53023e30cf8d47..bf49d8ce5f07be 100644 --- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c @@ -368,7 +368,7 @@ static struct quickspi_device *quickspi_dev_init(struct pci_dev *pdev, void __io struct quickspi_device *qsdev; int ret; - qsdev = devm_kzalloc(dev, sizeof(struct quickspi_device), GFP_KERNEL); + qsdev = devm_kzalloc_obj(dev, struct quickspi_device); if (!qsdev) return ERR_PTR(-ENOMEM); diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c index 7b4a58e1416d68..7feda41601e50c 100644 --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c @@ -197,7 +197,7 @@ struct thc_device *thc_dev_init(struct device *device, void __iomem *mem_addr) struct thc_device *thc_dev; int ret; - thc_dev = devm_kzalloc(device, sizeof(*thc_dev), GFP_KERNEL); + thc_dev = devm_kzalloc_obj(device, *thc_dev); if (!thc_dev) return ERR_PTR(-ENOMEM); diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c index 7ceb8aeeccd378..c80ef8c2057429 100644 --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c @@ -322,7 +322,7 @@ struct thc_dma_context *thc_dma_init(struct thc_device *dev) { struct thc_dma_context *dma_ctx; - dma_ctx = devm_kzalloc(dev->dev, sizeof(*dma_ctx), GFP_KERNEL); + dma_ctx = devm_kzalloc_obj(dev->dev, *dma_ctx); if (!dma_ctx) return NULL; diff --git a/drivers/hid/surface-hid/surface_hid.c b/drivers/hid/surface-hid/surface_hid.c index eae47e0d95ed69..e554032668940a 100644 --- a/drivers/hid/surface-hid/surface_hid.c +++ b/drivers/hid/surface-hid/surface_hid.c @@ -199,7 +199,7 @@ static int surface_hid_probe(struct ssam_device *sdev) { struct surface_hid_device *shid; - shid = devm_kzalloc(&sdev->dev, sizeof(*shid), GFP_KERNEL); + shid = devm_kzalloc_obj(&sdev->dev, *shid); if (!shid) return -ENOMEM; diff --git a/drivers/hid/surface-hid/surface_kbd.c b/drivers/hid/surface-hid/surface_kbd.c index 036829ba47d427..4821d44955bfbd 100644 --- a/drivers/hid/surface-hid/surface_kbd.c +++ b/drivers/hid/surface-hid/surface_kbd.c @@ -241,7 +241,7 @@ static int surface_kbd_probe(struct platform_device *pdev) if (IS_ERR(ctrl)) return PTR_ERR(ctrl) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(ctrl); - shid = devm_kzalloc(&pdev->dev, sizeof(*shid), GFP_KERNEL); + shid = devm_kzalloc_obj(&pdev->dev, *shid); if (!shid) return -ENOMEM; diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 628372ab818a28..2d2a4d56a8da74 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1495,7 +1495,7 @@ static int wacom_led_groups_alloc_and_register_one(struct device *dev, if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL)) return -ENOMEM; - leds = devm_kcalloc(dev, count, sizeof(struct wacom_led), GFP_KERNEL); + leds = devm_kzalloc_objs(dev, struct wacom_led, count); if (!leds) { error = -ENOMEM; goto err; @@ -1595,8 +1595,7 @@ static int wacom_led_groups_allocate(struct wacom *wacom, int count) struct wacom_group_leds *groups; int error; - groups = devm_kcalloc(dev, count, sizeof(struct wacom_group_leds), - GFP_KERNEL); + groups = devm_kzalloc_objs(dev, struct wacom_group_leds, count); if (!groups) return -ENOMEM; @@ -2059,8 +2058,7 @@ static int wacom_initialize_remotes(struct wacom *wacom) if (wacom->wacom_wac.features.type != REMOTE) return 0; - remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote), - GFP_KERNEL); + remote = devm_kzalloc_obj(&wacom->hdev->dev, *wacom->remote); if (!remote) return -ENOMEM; @@ -2934,7 +2932,7 @@ static int wacom_probe(struct hid_device *hdev, /* hid-core sets this quirk for the boot interface */ hdev->quirks &= ~HID_QUIRK_NOGET; - wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL); + wacom = devm_kzalloc_obj(&hdev->dev, struct wacom); if (!wacom) return -ENOMEM; diff --git a/drivers/hsi/clients/nokia-modem.c b/drivers/hsi/clients/nokia-modem.c index 88924d757616f1..eeb92d0f336db6 100644 --- a/drivers/hsi/clients/nokia-modem.c +++ b/drivers/hsi/clients/nokia-modem.c @@ -87,8 +87,7 @@ static int nokia_modem_gpio_probe(struct device *dev) return -EINVAL; } - modem->gpios = devm_kcalloc(dev, gpio_count, sizeof(*modem->gpios), - GFP_KERNEL); + modem->gpios = devm_kzalloc_objs(dev, *modem->gpios, gpio_count); if (!modem->gpios) return -ENOMEM; @@ -138,7 +137,7 @@ static int nokia_modem_probe(struct device *dev) return -ENXIO; } - modem = devm_kzalloc(dev, sizeof(*modem), GFP_KERNEL); + modem = devm_kzalloc_obj(dev, *modem); if (!modem) return -ENOMEM; diff --git a/drivers/hsi/controllers/omap_ssi_core.c b/drivers/hsi/controllers/omap_ssi_core.c index 0f5a6f7522ad9c..d0269793d26285 100644 --- a/drivers/hsi/controllers/omap_ssi_core.c +++ b/drivers/hsi/controllers/omap_ssi_core.c @@ -342,7 +342,7 @@ static int ssi_add_controller(struct hsi_controller *ssi, struct omap_ssi_controller *omap_ssi; int err; - omap_ssi = devm_kzalloc(&ssi->device, sizeof(*omap_ssi), GFP_KERNEL); + omap_ssi = devm_kzalloc_obj(&ssi->device, *omap_ssi); if (!omap_ssi) return -ENOMEM; @@ -373,8 +373,8 @@ static int ssi_add_controller(struct hsi_controller *ssi, if (err < 0) goto out_err; - omap_ssi->port = devm_kcalloc(&ssi->device, ssi->num_ports, - sizeof(*omap_ssi->port), GFP_KERNEL); + omap_ssi->port = devm_kzalloc_objs(&ssi->device, *omap_ssi->port, + ssi->num_ports); if (!omap_ssi->port) { err = -ENOMEM; goto out_err; diff --git a/drivers/hsi/controllers/omap_ssi_port.c b/drivers/hsi/controllers/omap_ssi_port.c index 63e8bc44630af4..a6d654be8c4a5b 100644 --- a/drivers/hsi/controllers/omap_ssi_port.c +++ b/drivers/hsi/controllers/omap_ssi_port.c @@ -1142,7 +1142,7 @@ static int ssi_port_probe(struct platform_device *pd) goto error; } - omap_port = devm_kzalloc(&port->device, sizeof(*omap_port), GFP_KERNEL); + omap_port = devm_kzalloc_obj(&port->device, *omap_port); if (!omap_port) { err = -ENOMEM; goto error; diff --git a/drivers/hte/hte-tegra194.c b/drivers/hte/hte-tegra194.c index 189f7fcffbe2a6..dea5f9e7900590 100644 --- a/drivers/hte/hte-tegra194.c +++ b/drivers/hte/hte-tegra194.c @@ -818,11 +818,11 @@ static int tegra_hte_probe(struct platform_device *pdev) dev = &pdev->dev; - hte_dev = devm_kzalloc(dev, sizeof(*hte_dev), GFP_KERNEL); + hte_dev = devm_kzalloc_obj(dev, *hte_dev); if (!hte_dev) return -ENOMEM; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; @@ -845,8 +845,7 @@ static int tegra_hte_probe(struct platform_device *pdev) if (ret != 0) hte_dev->itr_thrshld = 1; - hte_dev->sl = devm_kcalloc(dev, slices, sizeof(*hte_dev->sl), - GFP_KERNEL); + hte_dev->sl = devm_kzalloc_objs(dev, *hte_dev->sl, slices); if (!hte_dev->sl) return -ENOMEM; @@ -869,9 +868,8 @@ static int tegra_hte_probe(struct platform_device *pdev) if (hte_dev->prov_data && hte_dev->prov_data->type == HTE_TEGRA_TYPE_GPIO) { - hte_dev->line_data = devm_kcalloc(dev, nlines, - sizeof(*hte_dev->line_data), - GFP_KERNEL); + hte_dev->line_data = devm_kzalloc_objs(dev, *hte_dev->line_data, + nlines); if (!hte_dev->line_data) return -ENOMEM; diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index a0883ddf32e2fe..997e78182f8d0f 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -774,7 +774,7 @@ static u64 *request_arr_init(u32 size) int i; u64 *req_arr; - req_arr = kcalloc(size, sizeof(u64), GFP_KERNEL); + req_arr = kzalloc_objs(u64, size); if (!req_arr) return NULL; diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 27b9b79d4f4c9d..df257789627111 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -407,8 +407,7 @@ int __init hv_common_init(void) BUG_ON(!hv_synic_eventring_tail); } - hv_vp_index = kmalloc_array(nr_cpu_ids, sizeof(*hv_vp_index), - GFP_KERNEL); + hv_vp_index = kmalloc_objs(*hv_vp_index, nr_cpu_ids); if (!hv_vp_index) { hv_common_free(); return -ENOMEM; @@ -894,7 +893,7 @@ int hv_pci_register_dev_id(int pci_domain_nr, u32 logical_dev_id_prefix) struct hv_pci_busdata *bus, *new; int ret; - new = kzalloc_obj(*new, GFP_KERNEL); + new = kzalloc_obj(*new); if (!new) return -ENOMEM; diff --git a/drivers/hv/mshv_regions.c b/drivers/hv/mshv_regions.c index dddaade31b5dc3..d915fb67768d20 100644 --- a/drivers/hv/mshv_regions.c +++ b/drivers/hv/mshv_regions.c @@ -404,7 +404,7 @@ static int mshv_region_range_fault(struct mshv_mem_region *region, int ret; u64 i; - pfns = kmalloc_array(page_count, sizeof(*pfns), GFP_KERNEL); + pfns = kmalloc_objs(*pfns, page_count); if (!pfns) return -ENOMEM; diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index 3bb959d16dbf53..f9d9ba0cb852be 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c @@ -1268,8 +1268,7 @@ static int abituguru_probe(struct platform_device *pdev) 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02, 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; - data = devm_kzalloc(&pdev->dev, sizeof(struct abituguru_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct abituguru_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c index b70330dc219844..56d95443d69fce 100644 --- a/drivers/hwmon/abituguru3.c +++ b/drivers/hwmon/abituguru3.c @@ -965,8 +965,7 @@ static int abituguru3_probe(struct platform_device *pdev) u8 buf[2]; u16 id; - data = devm_kzalloc(&pdev->dev, sizeof(struct abituguru3_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct abituguru3_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 3891962f03db14..300acf1998ce76 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c @@ -30,13 +30,6 @@ #define POWER_METER_CAN_CAP (1 << 2) #define POWER_METER_CAN_NOTIFY (1 << 3) #define POWER_METER_IS_BATTERY (1 << 8) -#define UNKNOWN_HYSTERESIS 0xFFFFFFFF -/* - * ACPI integers can either be 32-bit or 64-bit wide, so - * we have to check for both values. - */ -#define UNKNOWN_POWER_32 U32_MAX -#define UNKNOWN_POWER_64 U64_MAX #define METER_NOTIFY_CONFIG 0x80 #define METER_NOTIFY_TRIP 0x81 @@ -54,6 +47,15 @@ static bool force_cap_on; static DEFINE_MUTEX(acpi_notify_lock); +/* + * ACPI integers can either be 32-bit or 64-bit wide, so + * we have to check for both values. + */ +static bool acpi_power_meter_is_unknown(u64 val) +{ + return val == U32_MAX || val == U64_MAX; +} + static int can_cap_in_hardware(void) { return force_cap_on || cap_in_hardware; @@ -179,9 +181,10 @@ static int update_meter(struct acpi_power_meter_resource *resource) acpi_status status; unsigned long local_jiffies = jiffies; - if (time_before(local_jiffies, resource->sensors_last_updated + + if (!acpi_power_meter_is_unknown(resource->caps.sampling_time) && + time_before(local_jiffies, resource->sensors_last_updated + msecs_to_jiffies(resource->caps.sampling_time)) && - resource->sensors_valid) + resource->sensors_valid) return 0; status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM", @@ -377,28 +380,30 @@ static int set_avg_interval(struct acpi_power_meter_resource *resource, return 0; } -static int get_power_alarm_state(struct acpi_power_meter_resource *resource, - long *val) +static bool get_power_alarm_state(struct acpi_power_meter_resource *resource) { + bool alarm = false; int ret; + if (resource->caps.flags & POWER_METER_CAN_NOTIFY) + alarm = resource->power_alarm; + resource->power_alarm = false; + ret = update_meter(resource); - if (ret) - return ret; + if (ret || acpi_power_meter_is_unknown(resource->power)) + return alarm; /* need to update cap if not to support the notification. */ if (!(resource->caps.flags & POWER_METER_CAN_NOTIFY)) { ret = update_cap(resource); if (ret) - return ret; - resource->power_alarm = resource->power > resource->cap; - *val = resource->power_alarm; - } else { - *val = resource->power_alarm || resource->power > resource->cap; - resource->power_alarm = resource->power > resource->cap; + return false; } - return 0; + if (acpi_power_meter_is_unknown(resource->cap)) + return alarm; + + return alarm || resource->power > resource->cap; } static umode_t power_meter_is_visible(const void *data, @@ -458,37 +463,47 @@ static int power_meter_read(struct device *dev, enum hwmon_sensor_types type, ret = update_meter(res); if (ret) return ret; - if (res->power == UNKNOWN_POWER_32 || res->power == UNKNOWN_POWER_64) + if (acpi_power_meter_is_unknown(res->power)) return -ENODATA; *val = res->power * 1000; break; case hwmon_power_average_interval_min: + if (acpi_power_meter_is_unknown(res->caps.min_avg_interval)) + return -ENODATA; *val = res->caps.min_avg_interval; break; case hwmon_power_average_interval_max: + if (acpi_power_meter_is_unknown(res->caps.max_avg_interval)) + return -ENODATA; *val = res->caps.max_avg_interval; break; case hwmon_power_average_interval: ret = update_avg_interval(res); if (ret) return ret; - *val = (res)->avg_interval; + if (acpi_power_meter_is_unknown(res->avg_interval)) + return -ENODATA; + *val = res->avg_interval; break; case hwmon_power_cap_min: + if (acpi_power_meter_is_unknown(res->caps.min_cap)) + return -ENODATA; *val = res->caps.min_cap * 1000; break; case hwmon_power_cap_max: + if (acpi_power_meter_is_unknown(res->caps.max_cap)) + return -ENODATA; *val = res->caps.max_cap * 1000; break; case hwmon_power_alarm: - ret = get_power_alarm_state(res, val); - if (ret) - return ret; + *val = get_power_alarm_state(res); break; case hwmon_power_cap: ret = update_cap(res); if (ret) return ret; + if (acpi_power_meter_is_unknown(res->cap)) + return -ENODATA; *val = res->cap * 1000; break; default: @@ -584,6 +599,8 @@ static ssize_t power1_average_min_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + if (res->trip[POWER_METER_TRIP_AVERAGE_MIN_IDX] < 0) return sysfs_emit(buf, "unknown\n"); @@ -596,6 +613,8 @@ static ssize_t power1_average_max_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + if (res->trip[POWER_METER_TRIP_AVERAGE_MAX_IDX] < 0) return sysfs_emit(buf, "unknown\n"); @@ -608,7 +627,9 @@ static ssize_t power1_cap_hyst_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); - if (res->caps.hysteresis == UNKNOWN_HYSTERESIS) + guard(mutex)(&res->lock); + + if (acpi_power_meter_is_unknown(res->caps.hysteresis)) return sysfs_emit(buf, "unknown\n"); return sysfs_emit(buf, "%llu\n", res->caps.hysteresis * 1000); @@ -619,8 +640,14 @@ static ssize_t power1_accuracy_show(struct device *dev, char *buf) { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); - unsigned int acc = res->caps.accuracy; + unsigned int acc; + + guard(mutex)(&res->lock); + if (acpi_power_meter_is_unknown(res->caps.accuracy)) + return sysfs_emit(buf, "unknown\n"); + + acc = res->caps.accuracy; return sysfs_emit(buf, "%u.%u%%\n", acc / 1000, acc % 1000); } @@ -630,6 +657,8 @@ static ssize_t power1_is_battery_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + return sysfs_emit(buf, "%u\n", res->caps.flags & POWER_METER_IS_BATTERY ? 1 : 0); } @@ -640,6 +669,11 @@ static ssize_t power1_model_number_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + + if (!res->model_number) + return -ENODATA; + return sysfs_emit(buf, "%s\n", res->model_number); } @@ -649,6 +683,11 @@ static ssize_t power1_oem_info_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + + if (!res->oem_info) + return -ENODATA; + return sysfs_emit(buf, "%s\n", res->oem_info); } @@ -658,6 +697,11 @@ static ssize_t power1_serial_number_show(struct device *dev, { struct acpi_power_meter_resource *res = dev_get_drvdata(dev); + guard(mutex)(&res->lock); + + if (!res->serial_number) + return -ENODATA; + return sysfs_emit(buf, "%s\n", res->serial_number); } @@ -984,6 +1028,8 @@ static int acpi_power_meter_resume(struct device *dev) { struct acpi_power_meter_resource *resource = dev_get_drvdata(dev); + guard(mutex)(&resource->lock); + free_capabilities(resource); read_capabilities(resource); diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c index 59424103f6348a..efb2b6b8c9b404 100644 --- a/drivers/hwmon/ad7314.c +++ b/drivers/hwmon/ad7314.c @@ -110,7 +110,7 @@ static int ad7314_probe(struct spi_device *spi_dev) struct ad7314_data *chip; struct device *hwmon_dev; - chip = devm_kzalloc(&spi_dev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&spi_dev->dev, *chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c index c2df631ae93a39..19f8fa776754ca 100644 --- a/drivers/hwmon/ad7414.c +++ b/drivers/hwmon/ad7414.c @@ -180,7 +180,7 @@ static int ad7414_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_WORD_DATA)) return -EOPNOTSUPP; - data = devm_kzalloc(dev, sizeof(struct ad7414_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct ad7414_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c index a0c9cf5e12cc40..c2185bba04f243 100644 --- a/drivers/hwmon/ad7418.c +++ b/drivers/hwmon/ad7418.c @@ -242,7 +242,7 @@ static int ad7418_probe(struct i2c_client *client) I2C_FUNC_SMBUS_WORD_DATA)) return -EOPNOTSUPP; - data = devm_kzalloc(dev, sizeof(struct ad7418_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct ad7418_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index e45adc0b84d1c0..82be274364a01c 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -434,7 +434,7 @@ static int adc128_probe(struct i2c_client *client) bool external_vref; int err, vref; - data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adc128_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c index 937fd9ef98b162..db00b88e01a564 100644 --- a/drivers/hwmon/adcxx.c +++ b/drivers/hwmon/adcxx.c @@ -154,7 +154,7 @@ static int adcxx_probe(struct spi_device *spi) int status; int i; - adc = devm_kzalloc(&spi->dev, sizeof(*adc), GFP_KERNEL); + adc = devm_kzalloc_obj(&spi->dev, *adc); if (!adc) return -ENOMEM; diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index ccac7ba601e99d..34c58460045db8 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c @@ -524,7 +524,7 @@ static int adm1025_probe(struct i2c_client *client) struct adm1025_data *data; u8 config; - data = devm_kzalloc(dev, sizeof(struct adm1025_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adm1025_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index 3ad82c01f81d5e..24f81de9bfe04e 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c @@ -1830,7 +1830,7 @@ static int adm1026_probe(struct i2c_client *client) struct device *hwmon_dev; struct adm1026_data *data; - data = devm_kzalloc(dev, sizeof(struct adm1026_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adm1026_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 6cb0a238e059b9..5602989dfd2f87 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c @@ -361,7 +361,7 @@ static int adm1029_probe(struct i2c_client *client) struct adm1029_data *data; struct device *hwmon_dev; - data = devm_kzalloc(dev, sizeof(struct adm1029_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adm1029_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 24d0d4146c8774..7a0db1bc92cc74 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c @@ -1027,7 +1027,7 @@ static int adm1031_probe(struct i2c_client *client) struct device *hwmon_dev; struct adm1031_data *data; - data = devm_kzalloc(dev, sizeof(struct adm1031_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adm1031_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adm1177.c b/drivers/hwmon/adm1177.c index 85ad4a3009bd46..7e266d6cc56ac6 100644 --- a/drivers/hwmon/adm1177.c +++ b/drivers/hwmon/adm1177.c @@ -199,7 +199,7 @@ static int adm1177_probe(struct i2c_client *client) u32 prop; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 586650e8d043f8..7d9922046088d2 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c @@ -774,7 +774,7 @@ static int adm9240_probe(struct i2c_client *client) struct adm9240_data *data; int err; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index f8f2f621dfeafe..261978af17c546 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c @@ -112,7 +112,7 @@ static int ads7828_probe(struct i2c_client *client) unsigned int regval; enum ads7828_chips chip; - data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct ads7828_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c index d1cbff0e857203..36297bc6d047eb 100644 --- a/drivers/hwmon/ads7871.c +++ b/drivers/hwmon/ads7871.c @@ -189,7 +189,7 @@ static int ads7871_probe(struct spi_device *spi) spi->bits_per_word = 8; spi_setup(spi); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index 598f3164754461..eaa4fe5b377d1c 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c @@ -648,7 +648,7 @@ static int adt7411_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index 376331f7fa1798..6b22b17b89ac06 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c @@ -1793,7 +1793,7 @@ static int adt7462_probe(struct i2c_client *client) struct adt7462_data *data; struct device *hwmon_dev; - data = devm_kzalloc(dev, sizeof(struct adt7462_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adt7462_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index f652532f2f32e8..d6fba2b0574916 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -1469,7 +1469,7 @@ static int adt7470_probe(struct i2c_client *client) int freq_val; int err; - data = devm_kzalloc(dev, sizeof(struct adt7470_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct adt7470_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index cd0b69ecb640bb..992a49192c3eec 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1817,7 +1817,7 @@ static int adt7475_probe(struct i2c_client *client) int i, ret = 0, revision, group_num = 0; u8 config3; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/hwmon/adt7x10.c b/drivers/hwmon/adt7x10.c index f99d38e82d0bb4..d3e01f8661f9f0 100644 --- a/drivers/hwmon/adt7x10.c +++ b/drivers/hwmon/adt7x10.c @@ -321,7 +321,7 @@ int adt7x10_probe(struct device *dev, const char *name, int irq, struct device *hdev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/aht10.c b/drivers/hwmon/aht10.c index 6c263cb577666c..1a7580bf18b70f 100644 --- a/drivers/hwmon/aht10.c +++ b/drivers/hwmon/aht10.c @@ -222,7 +222,7 @@ static int aht10_read_values(struct aht10_data *data) static ssize_t aht10_interval_write(struct aht10_data *data, long val) { - data->min_poll_interval = ms_to_ktime(clamp_val(val, 2000, LONG_MAX)); + data->min_poll_interval = ms_to_ktime(clamp_val(val, 2000, INT_MAX)); return 0; } @@ -340,7 +340,7 @@ static int aht10_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENOENT; - data = devm_kzalloc(device, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(device, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 5e6611d6e1bd64..575b2492ec2d4a 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -1039,7 +1039,7 @@ static int amc6821_probe(struct i2c_client *client) struct device_node *fan_np __free(device_node) = NULL; int err; - data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct amc6821_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index d0baa10502f7db..e01960019aaf44 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -547,7 +547,7 @@ static int applesmc_init_index(struct applesmc_registers *s) if (s->index) return 0; - s->index = kcalloc(s->temp_count, sizeof(s->index[0]), GFP_KERNEL); + s->index = kzalloc_objs(s->index[0], s->temp_count); if (!s->index) return -ENOMEM; @@ -1458,12 +1458,12 @@ static int __init applesmc_init(void) goto out_smcreg; /* allocate hwmon channel configs */ - applesmc_temp_config = kcalloc(smcreg.index_count + 1, - sizeof(*applesmc_temp_config), GFP_KERNEL); - applesmc_fan_config = kcalloc(smcreg.fan_count + 1, - sizeof(*applesmc_fan_config), GFP_KERNEL); - applesmc_pwm_config = kcalloc(smcreg.fan_count + 1, - sizeof(*applesmc_pwm_config), GFP_KERNEL); + applesmc_temp_config = kzalloc_objs(*applesmc_temp_config, + smcreg.index_count + 1); + applesmc_fan_config = kzalloc_objs(*applesmc_fan_config, + smcreg.fan_count + 1); + applesmc_pwm_config = kzalloc_objs(*applesmc_pwm_config, + smcreg.fan_count + 1); if (!applesmc_temp_config || !applesmc_fan_config || !applesmc_pwm_config) { ret = -ENOMEM; goto out_info; diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 1ca70e72629886..f521a6142a1326 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -132,6 +133,7 @@ static u8 aquaero_secondary_ctrl_report[] = { #define AQUAERO_FAN_CURRENT_OFFSET 0x06 #define AQUAERO_FAN_POWER_OFFSET 0x08 #define AQUAERO_FAN_SPEED_OFFSET 0x00 +#define AQUAERO_MIN_STATUS_REPORT_SIZE (0x18B + AQUAERO_FAN_POWER_OFFSET + sizeof(u16)) static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B }; /* Control report offsets for the Aquaero fan controllers */ @@ -155,6 +157,8 @@ static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 }; #define D5NEXT_5V_VOLTAGE 0x39 #define D5NEXT_12V_VOLTAGE 0x37 #define D5NEXT_VIRTUAL_SENSORS_START 0x3f +#define D5NEXT_MIN_STATUS_REPORT_SIZE (D5NEXT_PUMP_OFFSET + AQC_FAN_SPEED_OFFSET + \ + sizeof(u16)) static u16 d5next_sensor_fan_offsets[] = { D5NEXT_PUMP_OFFSET, D5NEXT_FAN_OFFSET }; /* Control report offsets for the D5 Next pump */ @@ -179,11 +183,14 @@ static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 }; /* Pump and fan speed (fr #define AQUASTREAMULT_FAN_CURRENT_OFFSET 0x00 #define AQUASTREAMULT_FAN_POWER_OFFSET 0x04 #define AQUASTREAMULT_FAN_SPEED_OFFSET 0x06 +#define AQUASTREAMULT_MIN_STATUS_REPORT_SIZE (AQUASTREAMULT_PRESSURE_OFFSET + sizeof(u16)) static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET }; /* Spec and sensor report offset for the Farbwerk RGB controller */ #define FARBWERK_NUM_SENSORS 4 #define FARBWERK_SENSOR_START 0x2f +#define FARBWERK_MIN_STATUS_REPORT_SIZE (FARBWERK_SENSOR_START + \ + FARBWERK_NUM_SENSORS * AQC_SENSOR_SIZE) /* Specs of the Farbwerk 360 RGB controller */ #define FARBWERK360_NUM_SENSORS 4 @@ -193,6 +200,8 @@ static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET }; /* Sensor report offsets for the Farbwerk 360 */ #define FARBWERK360_SENSOR_START 0x32 #define FARBWERK360_VIRTUAL_SENSORS_START 0x3a +#define FARBWERK360_MIN_STATUS_REPORT_SIZE (FARBWERK360_VIRTUAL_SENSORS_START + \ + FARBWERK360_NUM_VIRTUAL_SENSORS * AQC_SENSOR_SIZE) /* Control report offsets for the Farbwerk 360 */ #define FARBWERK360_TEMP_CTRL_OFFSET 0x8 @@ -209,6 +218,7 @@ static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET }; #define OCTO_SENSOR_START 0x3D #define OCTO_VIRTUAL_SENSORS_START 0x45 #define OCTO_FLOW_SENSOR_OFFSET 0x7B +#define OCTO_MIN_STATUS_REPORT_SIZE (0xD8 + AQC_FAN_SPEED_OFFSET + sizeof(u16)) static u16 octo_sensor_fan_offsets[] = { 0x7D, 0x8A, 0x97, 0xA4, 0xB1, 0xBE, 0xCB, 0xD8 }; /* Control report offsets for the Octo */ @@ -229,6 +239,7 @@ static u16 octo_ctrl_fan_offsets[] = { 0x5B, 0xB0, 0x105, 0x15A, 0x1AF, 0x204, 0 #define QUADRO_SENSOR_START 0x34 #define QUADRO_VIRTUAL_SENSORS_START 0x3c #define QUADRO_FLOW_SENSOR_OFFSET 0x6e +#define QUADRO_MIN_STATUS_REPORT_SIZE (0x97 + AQC_FAN_SPEED_OFFSET + sizeof(u16)) static u16 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 }; /* Control report offsets for the Quadro */ @@ -248,6 +259,7 @@ static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed #define HIGHFLOWNEXT_CONDUCTIVITY 95 #define HIGHFLOWNEXT_5V_VOLTAGE 97 #define HIGHFLOWNEXT_5V_VOLTAGE_USB 99 +#define HIGHFLOWNEXT_MIN_STATUS_REPORT_SIZE (HIGHFLOWNEXT_5V_VOLTAGE_USB + sizeof(u16)) /* Specs of the Leakshield */ #define LEAKSHIELD_NUM_SENSORS 2 @@ -263,6 +275,7 @@ static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed #define LEAKSHIELD_FLOW_IN 111 #define LEAKSHIELD_RESERVOIR_VOLUME 313 #define LEAKSHIELD_RESERVOIR_FILLED 311 +#define LEAKSHIELD_MIN_STATUS_REPORT_SIZE (LEAKSHIELD_RESERVOIR_VOLUME + sizeof(u16)) /* Specs of the Aquastream XT pump */ #define AQUASTREAMXT_SERIAL_START 0x3a @@ -554,6 +567,7 @@ struct aqc_data { const char *name; int status_report_id; /* Used for legacy devices, report is stored in buffer */ + u16 min_report_size; int ctrl_report_id; int secondary_ctrl_report_id; int secondary_ctrl_report_size; @@ -599,9 +613,9 @@ struct aqc_data { u32 speed_input_min[1]; u32 speed_input_target[1]; u32 speed_input_max[1]; - u32 power_input[8]; + long power_input[8]; u16 voltage_input[8]; - u16 current_input[8]; + u32 current_input[8]; /* Label values */ const char *const *temp_label; @@ -976,7 +990,7 @@ static int aqc_legacy_read(struct aqc_data *priv) /* Calculation derived from linear regression */ sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_CURR_OFFSET); - priv->current_input[0] = DIV_ROUND_CLOSEST(sensor_value * 176, 100) - 52; + priv->current_input[0] = max(DIV_ROUND_CLOSEST(sensor_value * 176, 100) - 52, 0); sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_VOLTAGE_OFFSET); priv->voltage_input[0] = DIV_ROUND_CLOSEST(sensor_value * 1000, 61); @@ -1006,6 +1020,7 @@ static int aqc_legacy_read(struct aqc_data *priv) static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { + long power; int ret; struct aqc_data *priv = dev_get_drvdata(dev); @@ -1070,7 +1085,10 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, } break; case hwmon_power: - *val = priv->power_input[channel]; + power = READ_ONCE(priv->power_input[channel]); + if (power == -ENODATA) + return -ENODATA; + *val = power; break; case hwmon_pwm: switch (priv->kind) { @@ -1333,6 +1351,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 return 0; priv = hid_get_drvdata(hdev); + if (!priv->min_report_size || size < priv->min_report_size) + return 0; /* Info provided with every report */ priv->serial_number[0] = get_unaligned_be16(data + priv->serial_number_start_offset); @@ -1368,9 +1388,9 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[i] = get_unaligned_be16(data + priv->fan_sensor_offsets[i] + priv->fan_structure->speed); - priv->power_input[i] = - get_unaligned_be16(data + priv->fan_sensor_offsets[i] + - priv->fan_structure->power) * 10000; + WRITE_ONCE(priv->power_input[i], + get_unaligned_be16(data + priv->fan_sensor_offsets[i] + + priv->fan_structure->power) * 10000); priv->voltage_input[i] = get_unaligned_be16(data + priv->fan_sensor_offsets[i] + priv->fan_structure->voltage) * 10; @@ -1410,7 +1430,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[2] = get_unaligned_be16(data + AQUASTREAMULT_PRESSURE_OFFSET); priv->speed_input[3] = get_unaligned_be16(data + AQUASTREAMULT_FLOW_SENSOR_OFFSET); - priv->power_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_POWER) * 10000; + WRITE_ONCE(priv->power_input[1], + get_unaligned_be16(data + AQUASTREAMULT_PUMP_POWER) * 10000); priv->voltage_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_VOLTAGE) * 10; @@ -1423,10 +1444,11 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 case highflownext: /* If external temp sensor is not connected, its power reading is also N/A */ if (priv->temp_input[1] == -ENODATA) - priv->power_input[0] = -ENODATA; + WRITE_ONCE(priv->power_input[0], -ENODATA); else - priv->power_input[0] = - get_unaligned_be16(data + HIGHFLOWNEXT_POWER) * 1000000; + WRITE_ONCE(priv->power_input[0], + min_t(u64, get_unaligned_be16(data + HIGHFLOWNEXT_POWER) * + 1000000ULL, LONG_MAX)); priv->voltage_input[0] = get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE) * 10; priv->voltage_input[1] = @@ -1518,9 +1540,10 @@ static void aqc_debugfs_init(struct aqc_data *priv) static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct aqc_data *priv; + u16 min_report_size = 0; int ret; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; @@ -1554,7 +1577,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) * they present. The two other devices have the type of the second element in * their respective collections set to 1, while the real device has it set to 0. */ - if (hdev->collection[1].type != 0) { + if (hdev->maxcollection < 2 || hdev->collection[1].type != 0) { ret = -ENODEV; goto fail_and_close; } @@ -1585,6 +1608,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_fan_power; priv->voltage_label = label_fan_voltage; priv->current_label = label_fan_current; + min_report_size = AQUAERO_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_D5NEXT: priv->kind = d5next; @@ -1610,6 +1634,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_d5next_power; priv->voltage_label = label_d5next_voltages; priv->current_label = label_d5next_current; + min_report_size = D5NEXT_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_FARBWERK: priv->kind = farbwerk; @@ -1620,6 +1645,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->temp_sensor_start_offset = FARBWERK_SENSOR_START; priv->temp_label = label_temp_sensors; + min_report_size = FARBWERK_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_FARBWERK360: priv->kind = farbwerk360; @@ -1636,6 +1662,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->temp_label = label_temp_sensors; priv->virtual_temp_label = label_virtual_temp_sensors; + min_report_size = FARBWERK360_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_OCTO: priv->kind = octo; @@ -1665,6 +1692,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_fan_power; priv->voltage_label = label_fan_voltage; priv->current_label = label_fan_current; + min_report_size = OCTO_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_QUADRO: priv->kind = quadro; @@ -1694,6 +1722,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_fan_power; priv->voltage_label = label_fan_voltage; priv->current_label = label_fan_current; + min_report_size = QUADRO_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_HIGHFLOWNEXT: priv->kind = highflownext; @@ -1711,6 +1740,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->speed_label = label_highflownext_fan_speed; priv->power_label = label_highflownext_power; priv->voltage_label = label_highflownext_voltage; + min_report_size = HIGHFLOWNEXT_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_LEAKSHIELD: /* @@ -1730,6 +1760,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->temp_label = label_leakshield_temp_sensors; priv->speed_label = label_leakshield_fan_speed; + min_report_size = LEAKSHIELD_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_AQUASTREAMXT: priv->kind = aquastreamxt; @@ -1760,6 +1791,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_aquastreamult_power; priv->voltage_label = label_aquastreamult_voltages; priv->current_label = label_aquastreamult_current; + min_report_size = AQUASTREAMULT_MIN_STATUS_REPORT_SIZE; break; case USB_PRODUCT_ID_POWERADJUST3: priv->kind = poweradjust3; @@ -1833,6 +1865,8 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) break; } + priv->min_report_size = min_report_size; + if (priv->buffer_size != 0) { priv->checksum_start = 0x01; priv->checksum_length = priv->buffer_size - 3; diff --git a/drivers/hwmon/arctic_fan_controller.c b/drivers/hwmon/arctic_fan_controller.c index 9eb83a149cd63d..e2e0bb8f2a7fc1 100644 --- a/drivers/hwmon/arctic_fan_controller.c +++ b/drivers/hwmon/arctic_fan_controller.c @@ -283,7 +283,7 @@ static int arctic_fan_probe(struct hid_device *hdev, if (ret) return ret; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/as370-hwmon.c b/drivers/hwmon/as370-hwmon.c index 702449c0fb8649..e8151a4a2e0dc7 100644 --- a/drivers/hwmon/as370-hwmon.c +++ b/drivers/hwmon/as370-hwmon.c @@ -97,7 +97,7 @@ static int as370_hwmon_probe(struct platform_device *pdev) struct as370_hwmon *hwmon; struct device *dev = &pdev->dev; - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 5f5c945051665b..89068cd4faf0c8 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c @@ -779,8 +779,7 @@ static int asb100_probe(struct i2c_client *client) int err; struct asb100_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct asb100_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct asb100_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index e8145bb13ab34a..94d254336a08a0 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c @@ -1095,8 +1095,7 @@ asc7621_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(&client->dev, sizeof(struct asc7621_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct asc7621_data); if (data == NULL) return -ENOMEM; diff --git a/drivers/hwmon/aspeed-g6-pwm-tach.c b/drivers/hwmon/aspeed-g6-pwm-tach.c index 5d611a8e526908..f07c9a036b6960 100644 --- a/drivers/hwmon/aspeed-g6-pwm-tach.c +++ b/drivers/hwmon/aspeed-g6-pwm-tach.c @@ -462,7 +462,7 @@ static int aspeed_pwm_tach_probe(struct platform_device *pdev) struct aspeed_pwm_tach_data *priv; struct pwm_chip *chip; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index bfce589c3fb1f1..9e64b3d5a7877b 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -822,7 +822,7 @@ static int aspeed_create_pwm_cooling(struct device *dev, int ret; struct aspeed_cooling_device *cdev; - cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL); + cdev = devm_kzalloc_obj(dev, *cdev); if (!cdev) return -ENOMEM; @@ -919,7 +919,7 @@ static int aspeed_pwm_tacho_probe(struct platform_device *pdev) regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(regs)) return PTR_ERR(regs); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; mutex_init(&priv->tach_lock); diff --git a/drivers/hwmon/asus-ec-sensors.c b/drivers/hwmon/asus-ec-sensors.c index 19f423e45ce5e4..a3cb595e713b74 100644 --- a/drivers/hwmon/asus-ec-sensors.c +++ b/drivers/hwmon/asus-ec-sensors.c @@ -1476,8 +1476,7 @@ static int asus_ec_probe(struct platform_device *pdev) if (!pboard_info) return -ENODEV; - ec_data = devm_kzalloc(dev, sizeof(struct ec_sensors_data), - GFP_KERNEL); + ec_data = devm_kzalloc_obj(dev, struct ec_sensors_data); if (!ec_data) return -ENOMEM; @@ -1526,8 +1525,8 @@ static int asus_ec_probe(struct platform_device *pdev) } ec_data->nr_sensors = hweight_long(ec_data->board_info->sensors); - ec_data->sensors = devm_kcalloc(dev, ec_data->nr_sensors, - sizeof(struct ec_sensor), GFP_KERNEL); + ec_data->sensors = devm_kzalloc_objs(dev, struct ec_sensor, + ec_data->nr_sensors); if (!ec_data->sensors) return -ENOMEM; @@ -1538,8 +1537,7 @@ static int asus_ec_probe(struct platform_device *pdev) } setup_sensor_data(ec_data); - ec_data->registers = devm_kcalloc(dev, ec_data->nr_registers, - sizeof(u16), GFP_KERNEL); + ec_data->registers = devm_kzalloc_objs(dev, u16, ec_data->nr_registers); ec_data->read_buffer = devm_kcalloc(dev, ec_data->nr_registers, sizeof(u8), GFP_KERNEL); @@ -1558,13 +1556,12 @@ static int asus_ec_probe(struct platform_device *pdev) if (nr_count[hwmon_temp]) nr_count[hwmon_chip]++, nr_types++; - asus_ec_hwmon_chan = devm_kcalloc( - dev, nr_types, sizeof(*asus_ec_hwmon_chan), GFP_KERNEL); + asus_ec_hwmon_chan = devm_kzalloc_objs(dev, *asus_ec_hwmon_chan, + nr_types); if (!asus_ec_hwmon_chan) return -ENOMEM; - ptr_asus_ec_ci = devm_kcalloc(dev, nr_types + 1, - sizeof(*ptr_asus_ec_ci), GFP_KERNEL); + ptr_asus_ec_ci = devm_kzalloc_objs(dev, *ptr_asus_ec_ci, nr_types + 1); if (!ptr_asus_ec_ci) return -ENOMEM; diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c index 868c4e14d26acf..db6e286be61962 100644 --- a/drivers/hwmon/asus_atk0110.c +++ b/drivers/hwmon/asus_atk0110.c @@ -886,7 +886,7 @@ static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; @@ -1165,7 +1165,7 @@ static int atk_init_attribute_groups(struct atk_data *data) int len = (data->voltage_count + data->temperature_count + data->fan_count) * 4 + 1; - attrs = devm_kcalloc(dev, len, sizeof(struct attribute *), GFP_KERNEL); + attrs = devm_kzalloc_objs(dev, struct attribute *, len); if (!attrs) return -ENOMEM; @@ -1284,7 +1284,7 @@ static int atk_probe(struct platform_device *pdev) if (!handle) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/asus_rog_ryujin.c b/drivers/hwmon/asus_rog_ryujin.c index 5ced69e94ead45..eaefd0cf8270cf 100644 --- a/drivers/hwmon/asus_rog_ryujin.c +++ b/drivers/hwmon/asus_rog_ryujin.c @@ -50,6 +50,7 @@ static const struct rog_ryujin_device_info rog_ryujin_iii_info = { #define MAX_REPORT_LENGTH 65 /* Cooler duty report offsets */ +#define RYUJIN_PUMP_SOURCE 3 #define RYUJIN_PUMP_DUTY 4 #define RYUJIN_INTERNAL_FAN_DUTY 5 @@ -70,10 +71,15 @@ static const u8 get_cooler_duty_cmd[] = { RYUJIN_CMD_PREFIX, 0x9A }; static const u8 get_controller_speed_cmd[] = { RYUJIN_CMD_PREFIX, 0xA0 }; static const u8 get_controller_duty_cmd[] = { RYUJIN_CMD_PREFIX, 0xA1 }; +#define RYUJIN_SET_COOLER_CHANNEL_OFFSET 2 #define RYUJIN_SET_COOLER_PUMP_DUTY_OFFSET 3 #define RYUJIN_SET_COOLER_FAN_DUTY_OFFSET 4 static const u8 set_cooler_duty_cmd[] = { RYUJIN_CMD_PREFIX, 0x1A, 0x00, 0x00, 0x00 }; +/* Pump control sources in the set cooler duty command and the cooler duty report */ +#define RYUJIN_SOURCE_HEADER 0 +#define RYUJIN_SOURCE_USB 1 + #define RYUJIN_SET_CONTROLLER_FAN_DUTY_OFFSET 4 static const u8 set_controller_duty_cmd[] = { RYUJIN_CMD_PREFIX, 0x21, 0x00, 0x00, 0x00 }; @@ -117,6 +123,7 @@ struct rog_ryujin_data { s32 temp_input[1]; u16 speed_input[6]; /* Pump, internal fan and four controller fan speeds in RPM */ u8 duty_input[3]; /* Pump, internal fan and controller fan duty in PWM */ + u8 pump_source; /* Pump control source from the cooler duty report */ u8 *buffer; unsigned long updated; /* jiffies */ @@ -200,16 +207,23 @@ static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, i /* Send command for getting data */ ret = rog_ryujin_write_expanded(priv, cmd, cmd_length); if (ret < 0) - return ret; + goto out_complete; ret = wait_for_completion_interruptible_timeout(status_completion, msecs_to_jiffies(STATUS_VALIDITY)); if (ret == 0) - return -ETIMEDOUT; - else if (ret < 0) - return ret; + ret = -ETIMEDOUT; + if (ret < 0) + goto out_complete; return 0; + +out_complete: + spin_lock_irqsave(&priv->status_report_request_lock, flags); + if (!completion_done(status_completion)) + complete_all(status_completion); + spin_unlock_irqrestore(&priv->status_report_request_lock, flags); + return ret; } static int rog_ryujin_get_status(struct rog_ryujin_data *priv) @@ -306,6 +320,44 @@ static int rog_ryujin_read_string(struct device *dev, enum hwmon_sensor_types ty return 0; } +/* + * On devices with a non-zero duty_channel (the RYUJIN III), the channel byte of + * the set cooler duty command selects the pump control source. + * RYUJIN_SOURCE_HEADER hands the pump to its internal controller, which follows + * the PWM of the header its 4-pin cable is plugged into. RYUJIN_SOURCE_USB + * makes the pump follow the pump duty in the command. The cooler duty report + * returns the current source. + * + * A fan duty write sends the reported source back, so that it leaves the pump + * control source as it is. A pump duty write selects USB. The cooler does not + * pass on a pump duty equal to the one it reports, and after power-on it + * reports 40% while a pump handed over at that duty runs at full speed. So + * when a pump duty write asks for the reported duty, write a duty 1% away + * first. + */ +static int rog_ryujin_select_pump_source(struct rog_ryujin_data *priv, u8 *set_cmd, + int channel) +{ + u8 duty = set_cmd[RYUJIN_SET_COOLER_PUMP_DUTY_OFFSET]; + int ret; + + if (channel == 1) { + set_cmd[RYUJIN_SET_COOLER_CHANNEL_OFFSET] = priv->pump_source; + return 0; + } + + set_cmd[RYUJIN_SET_COOLER_CHANNEL_OFFSET] = RYUJIN_SOURCE_USB; + + if (duty != rog_ryujin_pwm_to_percent(priv->duty_input[0])) + return 0; + + set_cmd[RYUJIN_SET_COOLER_PUMP_DUTY_OFFSET] = duty < 100 ? duty + 1 : duty - 1; + ret = rog_ryujin_execute_cmd(priv, set_cmd, SET_CMD_LENGTH, &priv->cooler_duty_set); + set_cmd[RYUJIN_SET_COOLER_PUMP_DUTY_OFFSET] = duty; + + return ret; +} + static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel, int val) { u8 set_cmd[SET_CMD_LENGTH]; @@ -323,7 +375,7 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel return ret; memcpy(set_cmd, set_cooler_duty_cmd, SET_CMD_LENGTH); - set_cmd[2] = priv->info->duty_channel; + set_cmd[RYUJIN_SET_COOLER_CHANNEL_OFFSET] = priv->info->duty_channel; /* Cooler duties are set as 0-100% */ val = rog_ryujin_pwm_to_percent(val); @@ -340,6 +392,12 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel set_cmd[RYUJIN_SET_COOLER_FAN_DUTY_OFFSET] = val; } + if (priv->info->duty_channel) { + ret = rog_ryujin_select_pump_source(priv, set_cmd, channel); + if (ret < 0) + return ret; + } + return rog_ryujin_execute_cmd(priv, set_cmd, SET_CMD_LENGTH, &priv->cooler_duty_set); } else { /* @@ -482,6 +540,7 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo goto unlock; } read_cooler_duty: + priv->pump_source = data[RYUJIN_PUMP_SOURCE]; priv->duty_input[0] = rog_ryujin_percent_to_pwm(data[RYUJIN_PUMP_DUTY]); priv->duty_input[1] = rog_ryujin_percent_to_pwm(data[RYUJIN_INTERNAL_FAN_DUTY]); @@ -530,7 +589,7 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id if (!id->driver_data) return -EINVAL; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; @@ -578,6 +637,18 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id init_completion(&priv->cooler_duty_set); init_completion(&priv->controller_duty_set); + /* + * Start completions in the completed state so rog_ryujin_raw_event() + * only sees !completion_done() while rog_ryujin_execute_cmd() is + * awaiting a response. + */ + complete_all(&priv->cooler_status_received); + complete_all(&priv->controller_status_received); + complete_all(&priv->cooler_duty_received); + complete_all(&priv->controller_duty_received); + complete_all(&priv->cooler_duty_set); + complete_all(&priv->controller_duty_set); + priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "rog_ryujin", priv, &rog_ryujin_chip_info, NULL); if (IS_ERR(priv->hwmon_dev)) { diff --git a/drivers/hwmon/asus_wmi_sensors.c b/drivers/hwmon/asus_wmi_sensors.c index 621e3506972d47..9e45cca22c6bba 100644 --- a/drivers/hwmon/asus_wmi_sensors.c +++ b/drivers/hwmon/asus_wmi_sensors.c @@ -164,6 +164,7 @@ struct asus_wmi_wmi_info { struct asus_wmi_sensors { struct asus_wmi_wmi_info wmi; + struct hwmon_chip_info chip_info; /* lock access to internal cache */ struct mutex lock; }; @@ -252,7 +253,7 @@ static int asus_wmi_hwmon_add_chan_info(struct hwmon_channel_info *asus_wmi_hwmo { u32 *cfg; - cfg = devm_kcalloc(dev, num + 1, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_objs(dev, *cfg, num + 1); if (!cfg) return -ENOMEM; @@ -496,11 +497,6 @@ static const struct hwmon_ops asus_wmi_hwmon_ops = { .read_string = asus_wmi_hwmon_read_string, }; -static struct hwmon_chip_info asus_wmi_chip_info = { - .ops = &asus_wmi_hwmon_ops, - .info = NULL, -}; - static int asus_wmi_configure_sensor_setup(struct device *dev, struct asus_wmi_sensors *sensor_data) { @@ -508,7 +504,7 @@ static int asus_wmi_configure_sensor_setup(struct device *dev, struct hwmon_channel_info *asus_wmi_hwmon_chan; int nr_count[hwmon_max] = {}, nr_types = 0; struct asus_wmi_sensor_info *temp_sensor; - const struct hwmon_chip_info *chip_info; + struct hwmon_chip_info *chip_info; enum hwmon_sensor_types type; struct device *hwdev; int i, idx; @@ -538,23 +534,22 @@ static int asus_wmi_configure_sensor_setup(struct device *dev, if (nr_count[hwmon_temp]) nr_count[hwmon_chip]++, nr_types++; - asus_wmi_hwmon_chan = devm_kcalloc(dev, nr_types, - sizeof(*asus_wmi_hwmon_chan), - GFP_KERNEL); + asus_wmi_hwmon_chan = devm_kzalloc_objs(dev, *asus_wmi_hwmon_chan, + nr_types); if (!asus_wmi_hwmon_chan) return -ENOMEM; - ptr_asus_wmi_ci = devm_kcalloc(dev, nr_types + 1, - sizeof(*ptr_asus_wmi_ci), GFP_KERNEL); + ptr_asus_wmi_ci = devm_kzalloc_objs(dev, *ptr_asus_wmi_ci, nr_types + 1); if (!ptr_asus_wmi_ci) return -ENOMEM; - asus_wmi_chip_info.info = ptr_asus_wmi_ci; - chip_info = &asus_wmi_chip_info; + chip_info = &sensor_data->chip_info; + chip_info->ops = &asus_wmi_hwmon_ops; + chip_info->info = ptr_asus_wmi_ci; - sensor_data->wmi.info_by_id = devm_kcalloc(dev, sensor_data->wmi.sensor_count, - sizeof(*sensor_data->wmi.info_by_id), - GFP_KERNEL); + sensor_data->wmi.info_by_id = devm_kzalloc_objs(dev, + *sensor_data->wmi.info_by_id, + sensor_data->wmi.sensor_count); if (!sensor_data->wmi.info_by_id) return -ENOMEM; @@ -571,16 +566,15 @@ static int asus_wmi_configure_sensor_setup(struct device *dev, *ptr_asus_wmi_ci++ = asus_wmi_hwmon_chan++; - sensor_data->wmi.info[type] = devm_kcalloc(dev, - nr_count[type], - sizeof(*sensor_data->wmi.info[type]), - GFP_KERNEL); + sensor_data->wmi.info[type] = devm_kzalloc_objs(dev, + *sensor_data->wmi.info[type], + nr_count[type]); if (!sensor_data->wmi.info[type]) return -ENOMEM; } for (i = sensor_data->wmi.sensor_count - 1; i >= 0; i--) { - temp_sensor = devm_kzalloc(dev, sizeof(*temp_sensor), GFP_KERNEL); + temp_sensor = devm_kzalloc_obj(dev, *temp_sensor); if (!temp_sensor) return -ENOMEM; @@ -620,7 +614,7 @@ static int asus_wmi_probe(struct wmi_device *wdev, const void *context) if (!dmi_check_system(asus_wmi_dmi_table)) return -ENODEV; - sensor_data = devm_kzalloc(dev, sizeof(*sensor_data), GFP_KERNEL); + sensor_data = devm_kzalloc_obj(dev, *sensor_data); if (!sensor_data) return -ENOMEM; diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index f5de4894f0a2e3..10f9f38406d71c 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c @@ -251,7 +251,7 @@ static int atxp1_probe(struct i2c_client *client) struct atxp1_data *data; struct device *hwmon_dev; - data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct atxp1_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c index 04a767d762b359..b3718a2174849f 100644 --- a/drivers/hwmon/axi-fan-control.c +++ b/drivers/hwmon/axi-fan-control.c @@ -456,7 +456,7 @@ static int axi_fan_control_probe(struct platform_device *pdev) if (!id) return -EINVAL; - ctl = devm_kzalloc(&pdev->dev, sizeof(*ctl), GFP_KERNEL); + ctl = devm_kzalloc_obj(&pdev->dev, *ctl); if (!ctl) return -ENOMEM; diff --git a/drivers/hwmon/axiado-pwm-fan.c b/drivers/hwmon/axiado-pwm-fan.c index 6fca5292eb25b8..09dd3e72c579f4 100644 --- a/drivers/hwmon/axiado-pwm-fan.c +++ b/drivers/hwmon/axiado-pwm-fan.c @@ -239,7 +239,7 @@ static int axiado_pwm_fan_probe(struct platform_device *pdev) struct clk *tach_clk; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/hwmon/axiado-tsadc.c b/drivers/hwmon/axiado-tsadc.c index c111df6f00447f..a6277cc65e8050 100644 --- a/drivers/hwmon/axiado-tsadc.c +++ b/drivers/hwmon/axiado-tsadc.c @@ -217,7 +217,7 @@ static int axiado_tsadc_probe(struct platform_device *pdev) struct clk *refclk; int ret; - tsadc = devm_kzalloc(dev, sizeof(*tsadc), GFP_KERNEL); + tsadc = devm_kzalloc_obj(dev, *tsadc); if (!tsadc) return -ENOMEM; diff --git a/drivers/hwmon/cgbc-hwmon.c b/drivers/hwmon/cgbc-hwmon.c index 230062a4690738..ba21ed8f0ceaf3 100644 --- a/drivers/hwmon/cgbc-hwmon.c +++ b/drivers/hwmon/cgbc-hwmon.c @@ -309,7 +309,7 @@ static int cgbc_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c index 9bef767b589ee2..0792af9323787c 100644 --- a/drivers/hwmon/chipcap2.c +++ b/drivers/hwmon/chipcap2.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -90,6 +92,9 @@ struct cc2_data { int irq_low; int irq_high; bool process_irqs; + /* protects process_irqs and the alarm indicators */ + struct mutex irq_lock; + bool regulator_enabled; }; /* %RH as a per cent mille from a register value */ @@ -118,20 +123,33 @@ static int cc2_enable(struct cc2_data *data) { int ret; + if (data->irq_ready > 0) { + scoped_guard(mutex, &data->irq_lock) + data->process_irqs = false; + + synchronize_irq(data->irq_ready); + + scoped_guard(mutex, &data->irq_lock) + reinit_completion(&data->complete); + } + /* exclusive regulator, check in case a disable failed */ - if (regulator_is_enabled(data->regulator)) + if (data->regulator_enabled) { + scoped_guard(mutex, &data->irq_lock) + data->process_irqs = true; return 0; - - /* clear any pending completion */ - try_wait_for_completion(&data->complete); + } ret = regulator_enable(data->regulator); if (ret < 0) return ret; + data->regulator_enabled = true; + usleep_range(CC2_STARTUP_TIME_US, CC2_STARTUP_TIME_US + 125); - data->process_irqs = true; + scoped_guard(mutex, &data->irq_lock) + data->process_irqs = true; return 0; } @@ -140,15 +158,36 @@ static void cc2_disable(struct cc2_data *data) { int err; + /* let the alarms already raised by the last measurement be processed */ + if (data->irq_low > 0) + synchronize_irq(data->irq_low); + + if (data->irq_high > 0) + synchronize_irq(data->irq_high); + /* ignore alarms triggered by voltage toggling when powering up */ - data->process_irqs = false; + scoped_guard(mutex, &data->irq_lock) + data->process_irqs = false; + + if (data->irq_ready > 0) + synchronize_irq(data->irq_ready); /* exclusive regulator, check in case an enable failed */ - if (regulator_is_enabled(data->regulator)) { - err = regulator_disable(data->regulator); - if (err) - dev_dbg(&data->client->dev, "Failed to disable device"); + if (!data->regulator_enabled) + return; + + err = regulator_disable(data->regulator); + if (err) { + dev_dbg(&data->client->dev, "Failed to disable device"); + return; } + + data->regulator_enabled = false; +} + +static void cc2_disable_action(void *data) +{ + cc2_disable(data); } static int cc2_cmd_response_diagnostic(struct device *dev, u8 status) @@ -167,13 +206,13 @@ static int cc2_cmd_response_diagnostic(struct device *dev, u8 status) case CC2_RESPONSE_BUSY: return -EBUSY; case CC2_RESPONSE_NACK: - if (resp & CC2_ERR_CORR_EEPROM) + if (status & CC2_ERR_CORR_EEPROM) dev_dbg(dev, "Command failed: corrected EEPROM\n"); - if (resp & CC2_ERR_UNCORR_EEPROM) + if (status & CC2_ERR_UNCORR_EEPROM) dev_dbg(dev, "Command failed: uncorrected EEPROM\n"); - if (resp & CC2_ERR_RAM_PARITY) + if (status & CC2_ERR_RAM_PARITY) dev_dbg(dev, "Command failed: RAM parity\n"); - if (resp & CC2_ERR_RAM_PARITY) + if (status & CC2_ERR_CONFIG_LOAD) dev_dbg(dev, "Command failed: configuration error\n"); return -ENODATA; default: @@ -226,7 +265,7 @@ static int cc2_command_mode_start(struct cc2_data *data) 2 * CC2_RESP_START_CM_US); } ret = cc2_read_command_status(data->client); - if (ret != -ETIMEDOUT || i == CC2_CM_RETRIES) + if (ret != -ETIMEDOUT || i == CC2_CM_RETRIES - 1) break; /* command window missed, prepare for a retry */ @@ -260,8 +299,7 @@ static int cc2_write_reg(struct cc2_data *data, u8 reg, u16 val) if (ret < 0) goto disable; - cpu_to_be16s(&val); - ret = i2c_smbus_write_word_data(data->client, reg, val); + ret = i2c_smbus_write_word_swapped(data->client, reg, val); if (ret < 0) goto disable; @@ -311,7 +349,7 @@ static int cc2_read_reg(struct cc2_data *data, u8 reg, u16 *val) if (ret != CC2_EEPROM_DATA_LEN) return ret < 0 ? ret : -EIO; - *val = be16_to_cpup((__be16 *)&buf[1]); + *val = get_unaligned_be16(&buf[1]); return cc2_read_command_status(data->client); } @@ -351,10 +389,10 @@ static int cc2_data_fetch(struct i2c_client *client, switch (type) { case hwmon_humidity: - *val = cc2_rh_convert(be16_to_cpup((__be16 *)&data[0])); + *val = cc2_rh_convert(get_unaligned_be16(&data[0])); break; case hwmon_temp: - *val = cc2_temp_convert(be16_to_cpup((__be16 *)&data[2])); + *val = cc2_temp_convert(get_unaligned_be16(&data[2])); break; default: return -EINVAL; @@ -482,8 +520,10 @@ static irqreturn_t cc2_ready_interrupt(int irq, void *data) { struct cc2_data *cc2 = data; - if (cc2->process_irqs) - complete(&cc2->complete); + scoped_guard(mutex, &cc2->irq_lock) { + if (cc2->process_irqs) + complete(&cc2->complete); + } return IRQ_HANDLED; } @@ -492,10 +532,12 @@ static irqreturn_t cc2_low_interrupt(int irq, void *data) { struct cc2_data *cc2 = data; - if (cc2->process_irqs) { - hwmon_notify_event(cc2->hwmon, hwmon_humidity, - hwmon_humidity_min_alarm, 0); - cc2->rh_alarm.low_alarm = true; + scoped_guard(mutex, &cc2->irq_lock) { + if (cc2->process_irqs) { + hwmon_notify_event(cc2->hwmon, hwmon_humidity, + hwmon_humidity_min_alarm, 0); + cc2->rh_alarm.low_alarm = true; + } } return IRQ_HANDLED; @@ -505,10 +547,12 @@ static irqreturn_t cc2_high_interrupt(int irq, void *data) { struct cc2_data *cc2 = data; - if (cc2->process_irqs) { - hwmon_notify_event(cc2->hwmon, hwmon_humidity, - hwmon_humidity_max_alarm, 0); - cc2->rh_alarm.high_alarm = true; + scoped_guard(mutex, &cc2->irq_lock) { + if (cc2->process_irqs) { + hwmon_notify_event(cc2->hwmon, hwmon_humidity, + hwmon_humidity_max_alarm, 0); + cc2->rh_alarm.high_alarm = true; + } } return IRQ_HANDLED; @@ -524,11 +568,13 @@ static int cc2_humidity_min_alarm_status(struct cc2_data *data, long *val) if (ret < 0) return ret; - if (data->rh_alarm.low_alarm) { - *val = (measurement < min_hyst) ? 1 : 0; - data->rh_alarm.low_alarm = *val; - } else { - *val = 0; + scoped_guard(mutex, &data->irq_lock) { + if (data->rh_alarm.low_alarm) { + *val = (measurement < min_hyst) ? 1 : 0; + data->rh_alarm.low_alarm = *val; + } else { + *val = 0; + } } return 0; @@ -544,11 +590,13 @@ static int cc2_humidity_max_alarm_status(struct cc2_data *data, long *val) if (ret < 0) return ret; - if (data->rh_alarm.high_alarm) { - *val = (measurement > max_hyst) ? 1 : 0; - data->rh_alarm.high_alarm = *val; - } else { - *val = 0; + scoped_guard(mutex, &data->irq_lock) { + if (data->rh_alarm.high_alarm) { + *val = (measurement > max_hyst) ? 1 : 0; + data->rh_alarm.high_alarm = *val; + } else { + *val = 0; + } } return 0; @@ -631,28 +679,47 @@ static int cc2_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, } } -static int cc2_request_ready_irq(struct cc2_data *data, struct device *dev) +static int cc2_get_irqs(struct cc2_data *data, struct device *dev) { - int ret = 0; - data->irq_ready = fwnode_irq_get_byname(dev_fwnode(dev), "ready"); - if (data->irq_ready > 0) { + if (data->irq_ready == -EPROBE_DEFER) + return data->irq_ready; + if (data->irq_ready > 0) init_completion(&data->complete); + + data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low"); + if (data->irq_low == -EPROBE_DEFER) + return data->irq_low; + if (data->irq_low > 0) + data->rh_alarm.low_alarm_visible = true; + + data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high"); + if (data->irq_high == -EPROBE_DEFER) + return data->irq_high; + if (data->irq_high > 0) + data->rh_alarm.high_alarm_visible = true; + + return 0; +} + +static int cc2_request_data_ready(struct cc2_data *data, struct device *dev) +{ + int ret = 0; + + if (data->irq_ready > 0) ret = devm_request_threaded_irq(dev, data->irq_ready, NULL, cc2_ready_interrupt, IRQF_ONESHOT | IRQF_TRIGGER_RISING, dev_name(dev), data); - } return ret; } -static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) +static int cc2_request_alarms(struct cc2_data *data, struct device *dev) { int ret = 0; - data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low"); if (data->irq_low > 0) { ret = devm_request_threaded_irq(dev, data->irq_low, NULL, cc2_low_interrupt, @@ -661,11 +728,8 @@ static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) dev_name(dev), data); if (ret) return ret; - - data->rh_alarm.low_alarm_visible = true; } - data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high"); if (data->irq_high > 0) { ret = devm_request_threaded_irq(dev, data->irq_high, NULL, cc2_high_interrupt, @@ -674,8 +738,6 @@ static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) dev_name(dev), data); if (ret) return ret; - - data->rh_alarm.high_alarm_visible = true; } return ret; @@ -711,12 +773,14 @@ static int cc2_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EOPNOTSUPP; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; i2c_set_clientdata(client, data); + mutex_init(&data->irq_lock); + data->client = client; data->regulator = devm_regulator_get_exclusive(dev, "vdd"); @@ -726,13 +790,17 @@ static int cc2_probe(struct i2c_client *client) device_property_read_string(dev, "label", &data->label); - ret = cc2_request_ready_irq(data, dev); + ret = cc2_get_irqs(data, dev); if (ret) - return dev_err_probe(dev, ret, "Failed to request ready irq\n"); + return dev_err_probe(dev, ret, "Failed to get IRQs\n"); - ret = cc2_request_alarm_irqs(data, dev); + ret = devm_add_action_or_reset(dev, cc2_disable_action, data); if (ret) - return dev_err_probe(dev, ret, "Failed to request alarm irqs\n"); + return ret; + + ret = cc2_request_data_ready(data, dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to request ready irq\n"); data->hwmon = devm_hwmon_device_register_with_info(dev, client->name, data, &cc2_chip_info, @@ -741,14 +809,11 @@ static int cc2_probe(struct i2c_client *client) return dev_err_probe(dev, PTR_ERR(data->hwmon), "Failed to register hwmon device\n"); - return 0; -} - -static void cc2_remove(struct i2c_client *client) -{ - struct cc2_data *data = i2c_get_clientdata(client); + ret = cc2_request_alarms(data, dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to request alarm irqs\n"); - cc2_disable(data); + return 0; } static const struct i2c_device_id cc2_id[] = { @@ -783,7 +848,6 @@ static struct i2c_driver cc2_driver = { .of_match_table = cc2_of_match, }, .probe = cc2_probe, - .remove = cc2_remove, .id_table = cc2_id, }; module_i2c_driver(cc2_driver); diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 3836beade59f42..96d57fe12de6d2 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -76,7 +76,7 @@ struct temp_data { int temp; bool temp_valid; int tjmax; - unsigned long last_updated; + u64 last_updated; unsigned int cpu; int index; u32 cpu_core_id; @@ -407,7 +407,7 @@ static ssize_t show_temp(struct device *dev, mutex_lock(&tdata->update_lock); /* Check whether the time interval has elapsed */ - if (time_after(jiffies, tdata->last_updated + HZ)) { + if (time_after64(get_jiffies_64(), tdata->last_updated + HZ)) { tjmax = get_tjmax(tdata, dev); rdmsrq_on_cpu(tdata->cpu, tdata->status_reg, &val.q); /* @@ -417,7 +417,7 @@ static ssize_t show_temp(struct device *dev, */ tdata->temp_valid = (val.l >> 31) & 1; tdata->temp = tjmax - ((val.l >> 16) & 0xff) * 1000; - tdata->last_updated = jiffies; + tdata->last_updated = get_jiffies_64(); } valid = tdata->temp_valid; @@ -491,11 +491,12 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) struct temp_data *tdata; if (!pdata->core_data) { - pdata->nr_cores = topology_num_cores_per_package(); - pdata->core_data = kzalloc_objs(struct temp_data *, - pdata->nr_cores); + int nr_cores = topology_num_cores_per_package(); + + pdata->core_data = kzalloc_objs(struct temp_data *, nr_cores); if (!pdata->core_data) return NULL; + pdata->nr_cores = nr_cores; } tdata = kzalloc_obj(struct temp_data); @@ -520,11 +521,8 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) tdata->cpu = cpu; tdata->cpu_core_id = topology_core_id(cpu); tdata->attr_size = MAX_CORE_ATTRS; - /* - * A zero timestamp does not look stale on 32-bit, where jiffies - * starts just short of wrapping. Backdate it instead. - */ - tdata->last_updated = jiffies - HZ - 1; + /* Backdate to force a refresh on the first read */ + tdata->last_updated = get_jiffies_64() - HZ - 1; mutex_init(&tdata->update_lock); return tdata; } @@ -695,6 +693,9 @@ static int coretemp_cpu_online(unsigned int cpu) if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) return 0; + if (!pdev) + return 0; + pdata = platform_get_drvdata(pdev); if (!pdata->hwmon_dev) { struct device *hwmon; @@ -746,6 +747,9 @@ static int coretemp_cpu_offline(unsigned int cpu) return 0; /* If the physical CPU device does not exist, just return */ + if (!pdev) + return 0; + pd = platform_get_drvdata(pdev); if (!pd->hwmon_dev) return 0; diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c index e6d31d36769801..99fc2a124e98aa 100644 --- a/drivers/hwmon/corsair-cpro.c +++ b/drivers/hwmon/corsair-cpro.c @@ -215,10 +215,11 @@ static int set_target(struct ccp_device *ccp, int channel, long val) int ret; val = clamp_val(val, 0, 0xFFFF); - ccp->target[channel] = val; mutex_lock(&ccp->mutex); ret = send_usb_cmd(ccp, CTL_SET_FAN_TARGET, channel, val >> 8, val); + if (!ret) + ccp->target[channel] = val; mutex_unlock(&ccp->mutex); return ret; @@ -589,7 +590,7 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) bool fw_valid, bl_valid; int ret; - ccp = devm_kzalloc(&hdev->dev, sizeof(*ccp), GFP_KERNEL); + ccp = devm_kzalloc_obj(&hdev->dev, *ccp); if (!ccp) return -ENOMEM; diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c index b545461d4ced3d..7258d0e4ce16dd 100644 --- a/drivers/hwmon/corsair-psu.c +++ b/drivers/hwmon/corsair-psu.c @@ -776,7 +776,7 @@ static int corsairpsu_probe(struct hid_device *hdev, const struct hid_device_id struct corsairpsu_data *priv; int ret; - priv = devm_kzalloc(&hdev->dev, sizeof(struct corsairpsu_data), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, struct corsairpsu_data); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c index 27af13f0941c30..685cb42534d963 100644 --- a/drivers/hwmon/cros_ec_hwmon.c +++ b/drivers/hwmon/cros_ec_hwmon.c @@ -538,7 +538,7 @@ static void cros_ec_hwmon_register_fan_cooling_devices(struct device *dev, if (!(priv->usable_fans & BIT(i))) continue; - cpriv = devm_kzalloc(dev, sizeof(*cpriv), GFP_KERNEL); + cpriv = devm_kzalloc_obj(dev, *cpriv); if (!cpriv) continue; @@ -577,7 +577,7 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev) if (thermal_version == 0) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c index 588e96790850af..a795b71c54f6ca 100644 --- a/drivers/hwmon/da9052-hwmon.c +++ b/drivers/hwmon/da9052-hwmon.c @@ -398,7 +398,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev; int err, tsiref_uv; - hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, struct da9052_hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/da9055-hwmon.c b/drivers/hwmon/da9055-hwmon.c index 7d330baa0f058b..9607ea2dae6f32 100644 --- a/drivers/hwmon/da9055-hwmon.c +++ b/drivers/hwmon/da9055-hwmon.c @@ -238,7 +238,7 @@ static int da9055_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev; int hwmon_irq, ret; - hwmon = devm_kzalloc(dev, sizeof(struct da9055_hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, struct da9055_hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 88837f0284051e..5ec487843faaa8 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1142,7 +1142,7 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num) if (!name) return -ENOMEM; - cdata = devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL); + cdata = devm_kmalloc_obj(dev, *cdata); if (cdata) { cdata->fan_num = fan_num; cdata->data = data; @@ -1196,9 +1196,9 @@ static int dell_smm_init_hwmon(struct device *dev) i + 1); } - data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1, - sizeof(*data->fan_nominal_speed[i]), - GFP_KERNEL); + data->fan_nominal_speed[i] = devm_kmalloc_objs(dev, + *data->fan_nominal_speed[i], + data->i8k_fan_max + 1); if (!data->fan_nominal_speed[i]) continue; @@ -1231,7 +1231,7 @@ static int dell_smm_init_data(struct device *dev, const struct dell_smm_ops *ops { struct dell_smm_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -1726,7 +1726,7 @@ static int dell_smm_wmi_probe(struct wmi_device *wdev, const void *context) struct dell_smm_ops *ops; int ret; - ops = devm_kzalloc(&wdev->dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(&wdev->dev, *ops); if (!ops) return -ENOMEM; diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 7e839308e58fa3..7d8cb1fc4b90a1 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c @@ -2467,7 +2467,7 @@ static int dme1737_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; int err; - data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct dme1737_data); if (!data) return -ENOMEM; @@ -2636,7 +2636,7 @@ static int dme1737_isa_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct dme1737_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 0618f6de9679c4..9c4590efee7a78 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c @@ -347,8 +347,7 @@ static int ds1621_probe(struct i2c_client *client) struct ds1621_data *data; struct device *hwmon_dev; - data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct ds1621_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c index 25287f0fa4c2e4..4b7cc41e7a4f19 100644 --- a/drivers/hwmon/ds620.c +++ b/drivers/hwmon/ds620.c @@ -217,7 +217,7 @@ static int ds620_probe(struct i2c_client *client) struct device *hwmon_dev; struct ds620_data *data; - data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct ds620_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/eic7700-pvt.c b/drivers/hwmon/eic7700-pvt.c index d7403ab33f4e6a..130cdd2683e63a 100644 --- a/drivers/hwmon/eic7700-pvt.c +++ b/drivers/hwmon/eic7700-pvt.c @@ -301,7 +301,7 @@ static struct pvt_hwmon *eic7700_pvt_create_data(struct platform_device *pdev) struct device *dev = &pdev->dev; struct pvt_hwmon *pvt; - pvt = devm_kzalloc(dev, sizeof(*pvt), GFP_KERNEL); + pvt = devm_kzalloc_obj(dev, *pvt); if (!pvt) return ERR_PTR(-ENOMEM); diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c index d737505acd9dc1..13ecc7372d9fe4 100644 --- a/drivers/hwmon/emc1403.c +++ b/drivers/hwmon/emc1403.c @@ -662,8 +662,7 @@ static int emc1403_probe(struct i2c_client *client) return dev_err_probe(&client->dev, ret, "Failed to enable regulator\n"); - data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct thermal_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/emc1812.c b/drivers/hwmon/emc1812.c index 68575c27d09050..b031d8174c4d73 100644 --- a/drivers/hwmon/emc1812.c +++ b/drivers/hwmon/emc1812.c @@ -888,7 +888,7 @@ static int emc1812_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 4adc23ffaf720d..831a5d68412717 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c @@ -564,8 +564,7 @@ emc2103_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(&client->dev, sizeof(struct emc2103_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct emc2103_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c index eef3b021671b03..434e70e76f5f7a 100644 --- a/drivers/hwmon/emc2305.c +++ b/drivers/hwmon/emc2305.c @@ -641,7 +641,7 @@ static int emc2305_probe(struct i2c_client *client) if (vendor != EMC2305_VENDOR) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c index c13ea874868356..f34da4502984a0 100644 --- a/drivers/hwmon/emc6w201.c +++ b/drivers/hwmon/emc6w201.c @@ -450,7 +450,7 @@ static int emc6w201_probe(struct i2c_client *client) struct emc6w201_data *data; struct device *hwmon_dev; - data = devm_kzalloc(dev, sizeof(struct emc6w201_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct emc6w201_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index 820f894d9ffda9..8a004da5f4243b 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c @@ -1378,8 +1378,7 @@ static int f71805f_probe(struct platform_device *pdev) "f71872f", }; - data = devm_kzalloc(&pdev->dev, sizeof(struct f71805f_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct f71805f_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index 204059d2de6cd2..3e75ddc57ab6c2 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c @@ -2346,8 +2346,7 @@ static int f71882fg_probe(struct platform_device *pdev) int size; u8 start_reg, reg; - data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct f71882fg_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index cc3a9612f2c0af..de81d041294b15 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c @@ -798,8 +798,7 @@ static int f75375_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(&client->dev, sizeof(struct f75375_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct f75375_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c index ad4ed4162b5743..151fbdaa6e383d 100644 --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -302,9 +302,8 @@ static int fam15h_power_init_attrs(struct pci_dev *pdev, if (boot_cpu_has(X86_FEATURE_ACC_POWER)) n += 2; - fam15h_power_attrs = devm_kcalloc(&pdev->dev, n, - sizeof(*fam15h_power_attrs), - GFP_KERNEL); + fam15h_power_attrs = devm_kzalloc_objs(&pdev->dev, *fam15h_power_attrs, + n); if (!fam15h_power_attrs) return -ENOMEM; @@ -460,7 +459,7 @@ static int fam15h_power_probe(struct pci_dev *pdev, if (!should_load_on_this_node(pdev)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct fam15h_power_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct fam15h_power_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index 10d786960ed6ea..76e69139e56d0c 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -632,8 +632,7 @@ static int fts_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(&client->dev, sizeof(struct fts_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct fts_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c index e2166ee7628607..808f4a7e77d019 100644 --- a/drivers/hwmon/g760a.c +++ b/drivers/hwmon/g760a.c @@ -179,7 +179,7 @@ static int g760a_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(dev, sizeof(struct g760a_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct g760a_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index 407cf7af4fdd91..0e5f9ab5456b33 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c @@ -1076,7 +1076,7 @@ static int g762_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct g762_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct g762_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/gigabyte_waterforce.c b/drivers/hwmon/gigabyte_waterforce.c index f4d0376dd68e0a..9e96fb9e290e63 100644 --- a/drivers/hwmon/gigabyte_waterforce.c +++ b/drivers/hwmon/gigabyte_waterforce.c @@ -319,7 +319,7 @@ static int waterforce_probe(struct hid_device *hdev, const struct hid_device_id struct waterforce_data *priv; int ret; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 742c130cec7f1a..cf4b117e4068a8 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c @@ -618,7 +618,7 @@ static int gl518_probe(struct i2c_client *client) struct gl518_data *data; int revision; - data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct gl518_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index f4fe39912ee292..2e3d5b0a366063 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c @@ -860,7 +860,7 @@ static int gl520_probe(struct i2c_client *client) struct device *hwmon_dev; struct gl520_data *data; - data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct gl520_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/gpd-fan.c b/drivers/hwmon/gpd-fan.c index ed212615b2fe99..547d6d0bff549f 100644 --- a/drivers/hwmon/gpd-fan.c +++ b/drivers/hwmon/gpd-fan.c @@ -444,6 +444,7 @@ static void gpd_duo_set_pwm_enable(struct gpd_fan_data *data, enum FAN_PWM_ENABL break; case AUTOMATIC: gpd_ecram_write(data->drvdata, data->drvdata->pwm_write, 0); + gpd_ecram_write(data->drvdata, data->drvdata->pwm_write + 1, 0); break; } } @@ -644,7 +645,7 @@ static int gpd_fan_probe(struct platform_device *pdev) return dev_err_probe(dev, -EBUSY, "Failed to request region\n"); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 3f78375eeb4481..55c812442b4f51 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -150,7 +150,10 @@ static int set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) __set_fan_ctrl(fan_data, fan_data->speed[speed_index].ctrl_val); - if (fan_data->speed_index > 0 && speed_index == 0) { + /* The GPIOs have changed, and a PM put drops the reference on error. */ + fan_data->speed_index = speed_index; + + if (speed_index == 0) { int ret; ret = pm_runtime_put_sync(fan_data->dev); @@ -158,8 +161,6 @@ static int set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) return ret; } - fan_data->speed_index = speed_index; - return 0; } @@ -466,9 +467,7 @@ static int gpio_fan_get_of_data(struct gpio_fan_data *fan_data) dev_err(dev, "DT properties empty / missing"); return -ENODEV; } - gpios = devm_kcalloc(dev, - fan_data->num_gpios, sizeof(struct gpio_desc *), - GFP_KERNEL); + gpios = devm_kzalloc_objs(dev, struct gpio_desc *, fan_data->num_gpios); if (!gpios) return -ENOMEM; for (i = 0; i < fan_data->num_gpios; i++) { @@ -496,9 +495,8 @@ static int gpio_fan_get_of_data(struct gpio_fan_data *fan_data) * Speed map is in the form * this needs splitting into pairs to create gpio_fan_speed structs */ - speed = devm_kcalloc(dev, - fan_data->num_speed, sizeof(struct gpio_fan_speed), - GFP_KERNEL); + speed = devm_kzalloc_objs(dev, struct gpio_fan_speed, + fan_data->num_speed); if (!speed) return -ENOMEM; p = NULL; @@ -530,8 +528,6 @@ static void gpio_fan_stop(void *data) mutex_lock(&fan_data->lock); set_fan_speed(data, 0); mutex_unlock(&fan_data->lock); - - pm_runtime_disable(fan_data->dev); } static int gpio_fan_probe(struct platform_device *pdev) @@ -541,8 +537,7 @@ static int gpio_fan_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - fan_data = devm_kzalloc(dev, sizeof(struct gpio_fan_data), - GFP_KERNEL); + fan_data = devm_kzalloc_obj(dev, struct gpio_fan_data); if (!fan_data) return -ENOMEM; @@ -559,6 +554,11 @@ static int gpio_fan_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(fan_data->supply), "Failed to get fan-supply"); + pm_runtime_set_suspended(dev); + err = devm_pm_runtime_enable(dev); + if (err) + return err; + /* Configure control GPIOs if available. */ if (fan_data->gpios && fan_data->num_gpios > 0) { if (!fan_data->speed || fan_data->num_speed <= 1) @@ -566,6 +566,12 @@ static int gpio_fan_probe(struct platform_device *pdev) err = fan_ctrl_init(fan_data); if (err) return err; + /* If current GPIO state is active, mark RPM as active as well */ + if (fan_data->speed_index > 0) { + err = pm_runtime_resume_and_get(dev); + if (err) + return err; + } err = devm_add_action_or_reset(dev, gpio_fan_stop, fan_data); if (err) return err; @@ -586,17 +592,6 @@ static int gpio_fan_probe(struct platform_device *pdev) return err; } - pm_runtime_set_suspended(&pdev->dev); - pm_runtime_enable(&pdev->dev); - /* If current GPIO state is active, mark RPM as active as well */ - if (fan_data->speed_index > 0) { - int ret; - - ret = pm_runtime_resume_and_get(&pdev->dev); - if (ret) - return ret; - } - /* Optional cooling device register for Device tree platforms */ fan_data->cdev = devm_thermal_of_child_cooling_device_register(dev, np, "gpio-fan", diff --git a/drivers/hwmon/gsc-hwmon.c b/drivers/hwmon/gsc-hwmon.c index 105b9f9dbec3d7..83005d8ae47e37 100644 --- a/drivers/hwmon/gsc-hwmon.c +++ b/drivers/hwmon/gsc-hwmon.c @@ -248,8 +248,7 @@ gsc_hwmon_get_devtree_pdata(struct device *dev) if (nchannels == 0) return ERR_PTR(-ENODEV); - pdata = devm_kzalloc(dev, struct_size(pdata, channels, nchannels), - GFP_KERNEL); + pdata = devm_kzalloc_flex(dev, *pdata, channels, nchannels); if (!pdata) return ERR_PTR(-ENOMEM); pdata->nchannels = nchannels; @@ -314,7 +313,7 @@ static int gsc_hwmon_probe(struct platform_device *pdev) return PTR_ERR(pdata); } - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, *hwmon); if (!hwmon) return -ENOMEM; hwmon->gsc = gsc; diff --git a/drivers/hwmon/gxp-fan-ctrl.c b/drivers/hwmon/gxp-fan-ctrl.c index 64f85d7e748ef4..c96210a308525d 100644 --- a/drivers/hwmon/gxp-fan-ctrl.c +++ b/drivers/hwmon/gxp-fan-ctrl.c @@ -111,8 +111,7 @@ static int gxp_fan_ctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device *hwmon_dev; - drvdata = devm_kzalloc(dev, sizeof(struct gxp_fan_ctrl_drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct gxp_fan_ctrl_drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwmon/hih6130.c b/drivers/hwmon/hih6130.c index 6a79aab5d1285a..bbfe78c7b9ac2f 100644 --- a/drivers/hwmon/hih6130.c +++ b/drivers/hwmon/hih6130.c @@ -215,7 +215,7 @@ static int hih6130_probe(struct i2c_client *client) return -ENODEV; } - hih6130 = devm_kzalloc(dev, sizeof(*hih6130), GFP_KERNEL); + hih6130 = devm_kzalloc_obj(dev, *hih6130); if (!hih6130) return -ENOMEM; diff --git a/drivers/hwmon/honor-fmi.c b/drivers/hwmon/honor-fmi.c index 3421e40a132f83..c43a736b99edf7 100644 --- a/drivers/hwmon/honor-fmi.c +++ b/drivers/hwmon/honor-fmi.c @@ -117,7 +117,7 @@ static int honor_fmi_probe(struct platform_device *pdev) if (!dmi_check_system(honor_fmi_dmi_table)) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/hp-wmi-sensors.c b/drivers/hwmon/hp-wmi-sensors.c index d8bcfeb8d5b290..8ab50c2c0366ac 100644 --- a/drivers/hwmon/hp-wmi-sensors.c +++ b/drivers/hwmon/hp-wmi-sensors.c @@ -390,6 +390,7 @@ struct hp_wmi_info { */ struct hp_wmi_sensors { struct wmi_device *wdev; + struct hwmon_chip_info chip_info; struct hp_wmi_info **info_map[hwmon_max]; u8 channel_count[hwmon_max]; bool has_intrusion; @@ -738,15 +739,21 @@ static long scale_numeric_sensor(const struct hp_wmi_numeric_sensor *nsensor) val = current_reading; - for (; unit_modifier < target_modifier; unit_modifier++) + for (; val && unit_modifier < target_modifier; unit_modifier++) val = DIV_ROUND_CLOSEST(val, 10); - for (; unit_modifier > target_modifier; unit_modifier--) { - if (val > LONG_MAX / 10) { - val = LONG_MAX; - break; + if (val) { + for (; unit_modifier > target_modifier; unit_modifier--) { + if (val > LONG_MAX / 10) { + val = LONG_MAX; + break; + } + if (val < LONG_MIN / 10) { + val = LONG_MIN; + break; + } + val *= 10; } - val *= 10; } if (sensor_type == HP_WMI_TYPE_TEMPERATURE) { @@ -842,8 +849,7 @@ populate_numeric_sensor_from_wobj(struct device *dev, if (err) return err; - possible_states = devm_kcalloc(dev, size, sizeof(*possible_states), - GFP_KERNEL); + possible_states = devm_kzalloc_objs(dev, *possible_states, size); if (!possible_states) return -ENOMEM; @@ -1473,8 +1479,10 @@ static int hp_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, if ((type == hwmon_temp && attr == hwmon_temp_alarm) || (type == hwmon_fan && attr == hwmon_fan_alarm)) { + mutex_lock(&state->lock); *out_val = info->alarm ? 1 : 0; info->alarm = false; + mutex_unlock(&state->lock); return 0; } @@ -1531,11 +1539,6 @@ static const struct hwmon_ops hp_wmi_hwmon_ops = { .write = hp_wmi_hwmon_write, }; -static struct hwmon_chip_info hp_wmi_chip_info = { - .ops = &hp_wmi_hwmon_ops, - .info = NULL, -}; - static struct hp_wmi_info *match_fan_event(struct hp_wmi_sensors *state, const char *event_description) { @@ -1704,7 +1707,7 @@ static int init_platform_events(struct device *dev, return 0; } - pevents_arr = devm_kcalloc(dev, count, sizeof(*pevents), GFP_KERNEL); + pevents_arr = devm_kzalloc_objs(dev, *pevents, count); if (!pevents_arr) return -ENOMEM; @@ -1756,7 +1759,7 @@ static int init_numeric_sensors(struct hp_wmi_sensors *state, if (!icount) return -ENODATA; - info_arr = devm_kcalloc(dev, icount, sizeof(*info), GFP_KERNEL); + info_arr = devm_kzalloc_objs(dev, *info, icount); if (!info_arr) return -ENOMEM; @@ -1803,9 +1806,8 @@ static int init_numeric_sensors(struct hp_wmi_sensors *state, c = channel_index[type]++; if (!info_map[type]) { - info_map[type] = devm_kcalloc(dev, channel_count[type], - sizeof(*info_map[type]), - GFP_KERNEL); + info_map[type] = devm_kzalloc_objs(dev, *info_map[type], + channel_count[type]); if (!info_map[type]) return -ENOMEM; } @@ -1952,25 +1954,24 @@ static int make_chip_info(struct hp_wmi_sensors *state, bool has_events) if (channel_count[type]) type_count++; - channel_info = devm_kcalloc(dev, type_count, - sizeof(*channel_info), GFP_KERNEL); + channel_info = devm_kzalloc_objs(dev, *channel_info, type_count); if (!channel_info) return -ENOMEM; - ptr_channel_info = devm_kcalloc(dev, type_count + 1, - sizeof(*ptr_channel_info), GFP_KERNEL); + ptr_channel_info = devm_kzalloc_objs(dev, *ptr_channel_info, + type_count + 1); if (!ptr_channel_info) return -ENOMEM; - hp_wmi_chip_info.info = ptr_channel_info; + state->chip_info.ops = &hp_wmi_hwmon_ops; + state->chip_info.info = ptr_channel_info; for (type = hwmon_chip; type < hwmon_max; type++) { count = channel_count[type]; if (!count) continue; - config = devm_kcalloc(dev, count + 1, - sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_objs(dev, *config, count + 1); if (!config) return -ENOMEM; @@ -2053,7 +2054,7 @@ static int hp_wmi_sensors_init(struct hp_wmi_sensors *state) return err; hwdev = devm_hwmon_device_register_with_info(dev, "hp_wmi_sensors", - state, &hp_wmi_chip_info, + state, &state->chip_info, NULL); return PTR_ERR_OR_ZERO(hwdev); } @@ -2063,7 +2064,7 @@ static int hp_wmi_sensors_probe(struct wmi_device *wdev, const void *context) struct device *dev = &wdev->dev; struct hp_wmi_sensors *state; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/hwmon/hs3001.c b/drivers/hwmon/hs3001.c index b263cbeca0747f..fde3f5683f74f8 100644 --- a/drivers/hwmon/hs3001.c +++ b/drivers/hwmon/hs3001.c @@ -191,7 +191,7 @@ static int hs3001_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EOPNOTSUPP; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/htu31.c b/drivers/hwmon/htu31.c index 5d2cdbdb773b07..7cdc6159b6e6a2 100644 --- a/drivers/hwmon/htu31.c +++ b/drivers/hwmon/htu31.c @@ -287,7 +287,7 @@ static int htu31_probe(struct i2c_client *client) struct htu31_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 3f32b0e83b532a..73a818806d3d2c 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -233,7 +233,7 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index) struct thermal_zone_device *tzd; int err; - tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL); + tdata = devm_kzalloc_obj(dev, *tdata); if (!tdata) return -ENOMEM; diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c index 70ca833259abfe..75ba50215bc6eb 100644 --- a/drivers/hwmon/ibmpowernv.c +++ b/drivers/hwmon/ibmpowernv.c @@ -352,8 +352,8 @@ static int init_sensor_group_data(struct platform_device *pdev, if (!pdata->nr_sensor_groups) goto out; - sgrp_data = devm_kcalloc(&pdev->dev, pdata->nr_sensor_groups, - sizeof(*sgrp_data), GFP_KERNEL); + sgrp_data = devm_kzalloc_objs(&pdev->dev, *sgrp_data, + pdata->nr_sensor_groups); if (!sgrp_data) { ret = -ENOMEM; goto out; @@ -465,10 +465,9 @@ static int populate_attr_groups(struct platform_device *pdev) of_node_put(opal); for (type = 0; type < MAX_SENSOR_TYPE; type++) { - sensor_groups[type].group.attrs = devm_kcalloc(&pdev->dev, - sensor_groups[type].attr_count + 1, - sizeof(struct attribute *), - GFP_KERNEL); + sensor_groups[type].group.attrs = devm_kzalloc_objs(&pdev->dev, + struct attribute *, + sensor_groups[type].attr_count + 1); if (!sensor_groups[type].group.attrs) return -ENOMEM; @@ -558,9 +557,7 @@ static int create_device_attrs(struct platform_device *pdev) u32 count = 0; u32 group_attr_id[MAX_SENSOR_TYPE] = {0}; - sdata = devm_kcalloc(&pdev->dev, - pdata->sensors_count, sizeof(*sdata), - GFP_KERNEL); + sdata = devm_kzalloc_objs(&pdev->dev, *sdata, pdata->sensors_count); if (!sdata) return -ENOMEM; @@ -665,7 +662,7 @@ static int ibmpowernv_probe(struct platform_device *pdev) struct device *hwmon_dev; int err; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index 6502e20517a81f..84140068c5f62c 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c @@ -96,7 +96,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) "Failed to get channels\n"); } - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); buf = (void *)devm_get_free_pages(dev, GFP_KERNEL, 0); if (!st || !buf) return -ENOMEM; @@ -107,9 +107,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) while (st->channels[st->num_channels].indio_dev) st->num_channels++; - st->attrs = devm_kcalloc(dev, - 2 * st->num_channels + 1, sizeof(*st->attrs), - GFP_KERNEL); + st->attrs = devm_kzalloc_objs(dev, *st->attrs, 2 * st->num_channels + 1); if (st->attrs == NULL) return -ENOMEM; @@ -117,7 +115,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) const char *prefix; int n; - a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL); + a = devm_kzalloc_obj(dev, *a); if (a == NULL) return -ENOMEM; @@ -166,7 +164,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) if (iio_read_channel_label(&st->channels[i], buf) < 0) continue; - a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL); + a = devm_kzalloc_obj(dev, *a); if (a == NULL) return -ENOMEM; diff --git a/drivers/hwmon/ina209.c b/drivers/hwmon/ina209.c index 39aca2cdf27f7f..4dd7159d651f7e 100644 --- a/drivers/hwmon/ina209.c +++ b/drivers/hwmon/ina209.c @@ -534,7 +534,7 @@ static int ina209_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index 3632bbca607ee6..49e3de561a1d4f 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -891,7 +891,7 @@ static int ina238_probe(struct i2c_client *client) chip = (uintptr_t)i2c_get_match_data(client); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 19b35f3bf3a3c1..aa5b39a87622a8 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -1092,7 +1092,7 @@ static int ina2xx_probe(struct i2c_client *client) chip = (uintptr_t)i2c_get_match_data(client); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 3ab5de3a111029..35aa255b8c628d 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -821,7 +821,7 @@ static int ina3221_probe(struct i2c_client *client) char name[32]; int i, ret; - ina = devm_kzalloc(dev, sizeof(*ina), GFP_KERNEL); + ina = devm_kzalloc_obj(dev, *ina); if (!ina) return -ENOMEM; diff --git a/drivers/hwmon/intel-m10-bmc-hwmon.c b/drivers/hwmon/intel-m10-bmc-hwmon.c index d75303ed93e543..fdbb68743ae4ad 100644 --- a/drivers/hwmon/intel-m10-bmc-hwmon.c +++ b/drivers/hwmon/intel-m10-bmc-hwmon.c @@ -733,7 +733,7 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev, *dev = &pdev->dev; struct m10bmc_hwmon *hw; - hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(dev, *hw); if (!hw) return -ENOMEM; diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c index 0c60d2ef28f5dd..2c04f73ac9e11a 100644 --- a/drivers/hwmon/isl28022.c +++ b/drivers/hwmon/isl28022.c @@ -448,7 +448,7 @@ static int isl28022_probe(struct i2c_client *client) I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct isl28022_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct isl28022_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 2757d428a23dba..bbb3f9788c2e34 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -3666,7 +3666,7 @@ static int it87_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct it87_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index f6cae24cca9e03..3a0308a5c656f7 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c @@ -478,7 +478,7 @@ static int jc42_probe(struct i2c_client *client) struct jc42_data *data; int ret; - data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct jc42_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 76f8829dd63d37..03f849bb958d72 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -450,7 +450,7 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id) "unreliable CPU thermal sensor; check erratum 319\n"); } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c index 53241164570eb0..b769d99cbb5f93 100644 --- a/drivers/hwmon/k8temp.c +++ b/drivers/hwmon/k8temp.c @@ -139,7 +139,7 @@ static int k8temp_probe(struct pci_dev *pdev, struct k8temp_data *data; struct device *hwmon_dev; - data = devm_kzalloc(&pdev->dev, sizeof(struct k8temp_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct k8temp_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/kb9002.c b/drivers/hwmon/kb9002.c index 9f4521630f3a2c..fe412c2578351a 100644 --- a/drivers/hwmon/kb9002.c +++ b/drivers/hwmon/kb9002.c @@ -389,7 +389,7 @@ static int kb9002_probe(struct i2c_client *client) I2C_FUNC_SMBUS_PEC)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/kbatt.c b/drivers/hwmon/kbatt.c index 501b8f4ded332e..79370f4667b241 100644 --- a/drivers/hwmon/kbatt.c +++ b/drivers/hwmon/kbatt.c @@ -110,7 +110,7 @@ static int kbatt_probe(struct auxiliary_device *auxdev, struct kbatt *kbatt; int retval; - kbatt = devm_kzalloc(dev, sizeof(*kbatt), GFP_KERNEL); + kbatt = devm_kzalloc_obj(dev, *kbatt); if (!kbatt) return -ENOMEM; diff --git a/drivers/hwmon/kfan.c b/drivers/hwmon/kfan.c index f353acb667493c..e093a6a09267ef 100644 --- a/drivers/hwmon/kfan.c +++ b/drivers/hwmon/kfan.c @@ -192,7 +192,7 @@ static int kfan_probe(struct auxiliary_device *auxdev, struct kfan *kfan; u8 status; - kfan = devm_kzalloc(dev, sizeof(*kfan), GFP_KERNEL); + kfan = devm_kzalloc_obj(dev, *kfan); if (!kfan) return -ENOMEM; diff --git a/drivers/hwmon/lan966x-hwmon.c b/drivers/hwmon/lan966x-hwmon.c index 4071bc2afa323b..015ea55120e9e8 100644 --- a/drivers/hwmon/lan966x-hwmon.c +++ b/drivers/hwmon/lan966x-hwmon.c @@ -340,7 +340,7 @@ static int lan966x_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev; int ret; - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/lenovo-ec-sensors.c b/drivers/hwmon/lenovo-ec-sensors.c index 24a182abf9a3d4..46b6e2447b148e 100644 --- a/drivers/hwmon/lenovo-ec-sensors.c +++ b/drivers/hwmon/lenovo-ec-sensors.c @@ -515,7 +515,7 @@ static int lenovo_ec_probe(struct platform_device *pdev) const struct dmi_system_id *dmi_id; int app_id; - ec_data = devm_kzalloc(dev, sizeof(struct ec_sensors_data), GFP_KERNEL); + ec_data = devm_kzalloc_obj(dev, struct ec_sensors_data); if (!ec_data) return -ENOMEM; diff --git a/drivers/hwmon/lineage-pem.c b/drivers/hwmon/lineage-pem.c index 2553e49f840158..edbd68fd7e89bc 100644 --- a/drivers/hwmon/lineage-pem.c +++ b/drivers/hwmon/lineage-pem.c @@ -429,7 +429,7 @@ static int pem_probe(struct i2c_client *client) | I2C_FUNC_SMBUS_WRITE_BYTE)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 607758bf7c58c2..5a2a3428be2dd0 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c @@ -1503,7 +1503,7 @@ static int lm63_probe(struct i2c_client *client) int groups = 0; int ret; - data = devm_kzalloc(dev, sizeof(struct lm63_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm63_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c index b29bac7a4cc14c..66e332c3a0f6d3 100644 --- a/drivers/hwmon/lm70.c +++ b/drivers/hwmon/lm70.c @@ -176,7 +176,7 @@ static int lm70_probe(struct spi_device *spi) /* NOTE: we assume 8-bit words, and convert to 16 bits manually */ - p_lm70 = devm_kzalloc(&spi->dev, sizeof(*p_lm70), GFP_KERNEL); + p_lm70 = devm_kzalloc_obj(&spi->dev, *p_lm70); if (!p_lm70) return -ENOMEM; diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c index 63ee67481a16c2..86090d17fd8b7d 100644 --- a/drivers/hwmon/lm73.c +++ b/drivers/hwmon/lm73.c @@ -197,7 +197,7 @@ lm73_probe(struct i2c_client *client) struct lm73_data *data; int ctrl; - data = devm_kzalloc(dev, sizeof(struct lm73_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm73_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 2d2d752aeac9d8..210860b5f64019 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -123,8 +123,7 @@ struct lm75_data { static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 }; -#define LM75_ALERT_POLARITY_HIGH_8_BIT (BIT(2)) -#define LM75_ALERT_POLARITY_HIGH_16_BIT (BIT(2) << 8) +#define LM75_ALERT_POLARITY_HIGH_BIT BIT(2) #define LM75_SAMPLE_CLEAR_MASK (3 << 5) /* The structure below stores the configuration values of the supported devices. @@ -736,7 +735,7 @@ static int lm75_generic_probe(struct device *dev, const char *name, struct lm75_data *data; int status, err; - data = devm_kzalloc(dev, sizeof(struct lm75_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm75_data); if (!data) return -ENOMEM; @@ -770,11 +769,7 @@ static int lm75_generic_probe(struct device *dev, const char *name, data->orig_conf = status; /* Enforce polarity active-low (default) or active-high (devicetree) */ - if (!data->params->config_reg_16bits) - pol_mask = LM75_ALERT_POLARITY_HIGH_8_BIT; - else - pol_mask = LM75_ALERT_POLARITY_HIGH_16_BIT; - + pol_mask = LM75_ALERT_POLARITY_HIGH_BIT; clr_mask = data->params->clr_mask | pol_mask; set_mask = data->params->set_mask & ~pol_mask; if (device_property_read_bool(dev, "ti,alert-polarity-active-high")) diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 96c5c2584d37e7..1f8402be599c1f 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c @@ -321,7 +321,7 @@ static int lm77_probe(struct i2c_client *client) struct device *hwmon_dev; struct lm77_data *data; - data = devm_kzalloc(dev, sizeof(struct lm77_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm77_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index e4834f9eca6a24..65464c9e831ecb 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c @@ -633,7 +633,7 @@ static int lm78_i2c_probe(struct i2c_client *client) struct device *hwmon_dev; struct lm78_data *data; - data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm78_data); if (!data) return -ENOMEM; @@ -794,7 +794,7 @@ static int lm78_isa_probe(struct platform_device *pdev) 2, "lm78")) return -EBUSY; - data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm78_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 94f3dabaaa6f62..079f79d9b02fb5 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c @@ -597,7 +597,7 @@ static int lm80_probe(struct i2c_client *client) struct device *hwmon_dev; struct lm80_data *data; - data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm80_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index 8d49df8c9314fd..b2ceb98860589f 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c @@ -423,7 +423,7 @@ static int lm83_probe(struct i2c_client *client) struct device *hwmon_dev; struct lm83_data *data; - data = devm_kzalloc(dev, sizeof(struct lm83_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm83_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 27ef127ccc2c47..80bd1f47114d63 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c @@ -1551,7 +1551,7 @@ static int lm85_probe(struct i2c_client *client) struct lm85_data *data; int idx = 0; - data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm85_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index c09074f447083d..5ace68e4391022 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c @@ -606,13 +606,16 @@ static DEVICE_ATTR_RO(cpu0_vid); static ssize_t vrm_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct lm87_data *data = dev_get_drvdata(dev); + struct i2c_client *client = dev_get_drvdata(dev); + struct lm87_data *data = i2c_get_clientdata(client); + return sprintf(buf, "%d\n", data->vrm); } static ssize_t vrm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct lm87_data *data = dev_get_drvdata(dev); + struct i2c_client *client = dev_get_drvdata(dev); + struct lm87_data *data = i2c_get_clientdata(client); unsigned long val; int err; @@ -925,7 +928,7 @@ static int lm87_probe(struct i2c_client *client) int err; unsigned int group_tail = 0; - data = devm_kzalloc(&client->dev, sizeof(struct lm87_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct lm87_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 3faeb2c6ab01b2..500ba3b4feeba0 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -2787,7 +2787,7 @@ static int lm90_probe(struct i2c_client *client) if (err) return dev_err_probe(dev, err, "Failed to enable regulator\n"); - data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm90_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index 4aadbabc27bb92..a6cbacea2ddcbd 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c @@ -384,7 +384,7 @@ static int lm92_probe(struct i2c_client *client) if (IS_ERR(regmap)) return PTR_ERR(regmap); - data = devm_kzalloc(dev, sizeof(struct lm92_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm92_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index d58a3c2a859304..161a1fdb514854 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c @@ -2605,7 +2605,7 @@ static int lm93_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(dev, sizeof(struct lm93_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm93_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 74f280b90e3e9c..4cb0681a58c59d 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -508,7 +508,7 @@ static int lm95234_probe(struct i2c_client *client) struct regmap *regmap; int err; - data = devm_kzalloc(dev, sizeof(struct lm95234_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm95234_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c index 0cb0edb3845db0..99651f95ce9829 100644 --- a/drivers/hwmon/lm95241.c +++ b/drivers/hwmon/lm95241.c @@ -423,7 +423,7 @@ static int lm95241_probe(struct i2c_client *client) struct lm95241_data *data; struct device *hwmon_dev; - data = devm_kzalloc(dev, sizeof(struct lm95241_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm95241_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c index 925574b8b0ca4d..9bd0ad310cecb3 100644 --- a/drivers/hwmon/lm95245.c +++ b/drivers/hwmon/lm95245.c @@ -524,7 +524,7 @@ static int lm95245_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(struct lm95245_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm95245_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/lochnagar-hwmon.c b/drivers/hwmon/lochnagar-hwmon.c index c1ba72f6132ef0..24a255d4c46b54 100644 --- a/drivers/hwmon/lochnagar-hwmon.c +++ b/drivers/hwmon/lochnagar-hwmon.c @@ -364,7 +364,7 @@ static int lochnagar_hwmon_probe(struct platform_device *pdev) struct lochnagar_hwmon *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index b521100afe53a0..6ba07a34dd513c 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -479,7 +479,7 @@ static int ltc2945_probe(struct i2c_client *client) struct regmap *regmap; struct ltc2945_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; dev_set_drvdata(dev, data); diff --git a/drivers/hwmon/ltc2947-core.c b/drivers/hwmon/ltc2947-core.c index 6eba857d4ef833..d3b5a8f6af1cfc 100644 --- a/drivers/hwmon/ltc2947-core.c +++ b/drivers/hwmon/ltc2947-core.c @@ -1071,7 +1071,7 @@ int ltc2947_core_probe(struct regmap *map, const char *name) struct device *hwmon; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/ltc2990.c b/drivers/hwmon/ltc2990.c index a2725e4b2f2136..bd915f8f968ba4 100644 --- a/drivers/hwmon/ltc2990.c +++ b/drivers/hwmon/ltc2990.c @@ -210,7 +210,7 @@ static int ltc2990_i2c_probe(struct i2c_client *i2c) I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(&i2c->dev, sizeof(struct ltc2990_data), GFP_KERNEL); + data = devm_kzalloc_obj(&i2c->dev, struct ltc2990_data); if (unlikely(!data)) return -ENOMEM; diff --git a/drivers/hwmon/ltc2991.c b/drivers/hwmon/ltc2991.c index bc8d803e8cc90d..8101f6ced9945f 100644 --- a/drivers/hwmon/ltc2991.c +++ b/drivers/hwmon/ltc2991.c @@ -382,7 +382,7 @@ static int ltc2991_i2c_probe(struct i2c_client *client) struct device *hwmon_dev; struct ltc2991_state *st; - st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&client->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index 43b6029c084048..15003798f99f0f 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -918,7 +918,7 @@ static int ltc2992_i2c_probe(struct i2c_client *client) struct ltc2992_state *st; int ret; - st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&client->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c index fa7c57aae5f5fb..ded4f6ea357bd9 100644 --- a/drivers/hwmon/ltc4151.c +++ b/drivers/hwmon/ltc4151.c @@ -165,7 +165,7 @@ static int ltc4151_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c index 3d439fbbbef93d..c31448f0992d36 100644 --- a/drivers/hwmon/ltc4215.c +++ b/drivers/hwmon/ltc4215.c @@ -228,7 +228,7 @@ static int ltc4215_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c index d87aa9c32c8730..b05938edcd0cb1 100644 --- a/drivers/hwmon/ltc4245.c +++ b/drivers/hwmon/ltc4245.c @@ -442,7 +442,7 @@ static int ltc4245_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ltc4261.c b/drivers/hwmon/ltc4261.c index a2e52ca0b06e1c..cf83f343e70946 100644 --- a/drivers/hwmon/ltc4261.c +++ b/drivers/hwmon/ltc4261.c @@ -205,7 +205,7 @@ static int ltc4261_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ltc4282.c b/drivers/hwmon/ltc4282.c index 54ba4b8542e94b..7b3f08bd49602d 100644 --- a/drivers/hwmon/ltc4282.c +++ b/drivers/hwmon/ltc4282.c @@ -1658,7 +1658,7 @@ static int ltc4282_probe(struct i2c_client *i2c) struct ltc4282_state *st; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/ltc4283.c b/drivers/hwmon/ltc4283.c index 9ec409bc264822..a7436ea87ec551 100644 --- a/drivers/hwmon/ltc4283.c +++ b/drivers/hwmon/ltc4283.c @@ -1727,7 +1727,7 @@ static int ltc4283_probe(struct i2c_client *client) struct ltc4283_hwmon *st; int ret, id; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c index 1500ec2cc9f83d..e40a03f9a9da7c 100644 --- a/drivers/hwmon/macsmc-hwmon.c +++ b/drivers/hwmon/macsmc-hwmon.c @@ -573,8 +573,9 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, } if (n_current) { - hwmon->curr.sensors = devm_kcalloc(hwmon->dev, n_current, - sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL); + hwmon->curr.sensors = devm_kzalloc_objs(hwmon->dev, + struct macsmc_hwmon_sensor, + n_current); if (!hwmon->curr.sensors) return -ENOMEM; @@ -596,8 +597,9 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, } if (n_fan) { - hwmon->fan.fans = devm_kcalloc(hwmon->dev, n_fan, - sizeof(struct macsmc_hwmon_fan), GFP_KERNEL); + hwmon->fan.fans = devm_kzalloc_objs(hwmon->dev, + struct macsmc_hwmon_fan, + n_fan); if (!hwmon->fan.fans) return -ENOMEM; @@ -613,8 +615,9 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, } if (n_power) { - hwmon->power.sensors = devm_kcalloc(hwmon->dev, n_power, - sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL); + hwmon->power.sensors = devm_kzalloc_objs(hwmon->dev, + struct macsmc_hwmon_sensor, + n_power); if (!hwmon->power.sensors) return -ENOMEM; @@ -636,8 +639,9 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, } if (n_temperature) { - hwmon->temp.sensors = devm_kcalloc(hwmon->dev, n_temperature, - sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL); + hwmon->temp.sensors = devm_kzalloc_objs(hwmon->dev, + struct macsmc_hwmon_sensor, + n_temperature); if (!hwmon->temp.sensors) return -ENOMEM; @@ -659,8 +663,9 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, } if (n_voltage) { - hwmon->volt.sensors = devm_kcalloc(hwmon->dev, n_voltage, - sizeof(struct macsmc_hwmon_sensor), GFP_KERNEL); + hwmon->volt.sensors = devm_kzalloc_objs(hwmon->dev, + struct macsmc_hwmon_sensor, + n_voltage); if (!hwmon->volt.sensors) return -ENOMEM; @@ -711,8 +716,8 @@ static int macsmc_hwmon_create_infos(struct macsmc_hwmon *hwmon) if (hwmon->curr.count) { channel_info = &hwmon->curr.channel_info; channel_info->type = hwmon_curr; - channel_info->config = devm_kcalloc(hwmon->dev, hwmon->curr.count + 1, - sizeof(u32), GFP_KERNEL); + channel_info->config = devm_kzalloc_objs(hwmon->dev, u32, + hwmon->curr.count + 1); if (!channel_info->config) return -ENOMEM; @@ -723,8 +728,8 @@ static int macsmc_hwmon_create_infos(struct macsmc_hwmon *hwmon) if (hwmon->fan.count) { channel_info = &hwmon->fan.channel_info; channel_info->type = hwmon_fan; - channel_info->config = devm_kcalloc(hwmon->dev, hwmon->fan.count + 1, - sizeof(u32), GFP_KERNEL); + channel_info->config = devm_kzalloc_objs(hwmon->dev, u32, + hwmon->fan.count + 1); if (!channel_info->config) return -ENOMEM; @@ -735,8 +740,8 @@ static int macsmc_hwmon_create_infos(struct macsmc_hwmon *hwmon) if (hwmon->power.count) { channel_info = &hwmon->power.channel_info; channel_info->type = hwmon_power; - channel_info->config = devm_kcalloc(hwmon->dev, hwmon->power.count + 1, - sizeof(u32), GFP_KERNEL); + channel_info->config = devm_kzalloc_objs(hwmon->dev, u32, + hwmon->power.count + 1); if (!channel_info->config) return -ENOMEM; @@ -747,8 +752,8 @@ static int macsmc_hwmon_create_infos(struct macsmc_hwmon *hwmon) if (hwmon->temp.count) { channel_info = &hwmon->temp.channel_info; channel_info->type = hwmon_temp; - channel_info->config = devm_kcalloc(hwmon->dev, hwmon->temp.count + 1, - sizeof(u32), GFP_KERNEL); + channel_info->config = devm_kzalloc_objs(hwmon->dev, u32, + hwmon->temp.count + 1); if (!channel_info->config) return -ENOMEM; @@ -759,8 +764,8 @@ static int macsmc_hwmon_create_infos(struct macsmc_hwmon *hwmon) if (hwmon->volt.count) { channel_info = &hwmon->volt.channel_info; channel_info->type = hwmon_in; - channel_info->config = devm_kcalloc(hwmon->dev, hwmon->volt.count + 1, - sizeof(u32), GFP_KERNEL); + channel_info->config = devm_kzalloc_objs(hwmon->dev, u32, + hwmon->volt.count + 1); if (!channel_info->config) return -ENOMEM; @@ -785,8 +790,7 @@ static int macsmc_hwmon_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), - GFP_KERNEL); + hwmon = devm_kzalloc_obj(&pdev->dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c index 5cc08c720b52f7..a2658db7628de6 100644 --- a/drivers/hwmon/max1111.c +++ b/drivers/hwmon/max1111.c @@ -192,7 +192,7 @@ static int max1111_probe(struct spi_device *spi) if (err < 0) return err; - data = devm_kzalloc(&spi->dev, sizeof(struct max1111_data), GFP_KERNEL); + data = devm_kzalloc_obj(&spi->dev, struct max1111_data); if (data == NULL) return -ENOMEM; diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c index b294e86d52d16e..e62c0e603e1138 100644 --- a/drivers/hwmon/max127.c +++ b/drivers/hwmon/max127.c @@ -294,7 +294,7 @@ static int max127_probe(struct i2c_client *client) struct max127_data *data; struct device *dev = &client->dev; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c index f8b4217542203d..878f8a110d611c 100644 --- a/drivers/hwmon/max16065.c +++ b/drivers/hwmon/max16065.c @@ -518,7 +518,7 @@ static int max16065_probe(struct i2c_client *client) | I2C_FUNC_SMBUS_READ_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (unlikely(!data)) return -ENOMEM; diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 32548f56409ce3..6a31cef98ff3b3 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -276,7 +276,7 @@ static int max1668_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct max1668_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max1668_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max197.c b/drivers/hwmon/max197.c index 0d315087b504d2..a613abfdc2dba4 100644 --- a/drivers/hwmon/max197.c +++ b/drivers/hwmon/max197.c @@ -271,7 +271,7 @@ static int max197_probe(struct platform_device *pdev) return -EINVAL; } - data = devm_kzalloc(&pdev->dev, sizeof(struct max197_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct max197_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max31722.c b/drivers/hwmon/max31722.c index 6c5c86c75c36e9..f360148cc41255 100644 --- a/drivers/hwmon/max31722.c +++ b/drivers/hwmon/max31722.c @@ -74,7 +74,7 @@ static int max31722_probe(struct spi_device *spi) int ret; struct max31722_data *data; - data = devm_kzalloc(&spi->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&spi->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max31730.c b/drivers/hwmon/max31730.c index d132be2d6487d0..1d5bcafbd09b71 100644 --- a/drivers/hwmon/max31730.c +++ b/drivers/hwmon/max31730.c @@ -302,7 +302,7 @@ max31730_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) return -EIO; - data = devm_kzalloc(dev, sizeof(struct max31730_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max31730_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c index 8d3be064b02518..cf9ee0ed138929 100644 --- a/drivers/hwmon/max31760.c +++ b/drivers/hwmon/max31760.c @@ -27,8 +27,8 @@ #define REG_TACH(ch) (0x52 + (ch) * 2) #define REG_TEMP_INPUT(ch) (0x56 + (ch) * 2) -#define REG_TEMP_MAX(ch) (0x06 + (ch) * 2) -#define REG_TEMP_CRIT(ch) (0x0A + (ch) * 2) +#define REG_TEMP_MAX(ch) ((ch) ? 0x0C : 0x06) +#define REG_TEMP_CRIT(ch) ((ch) ? 0x08 : 0x0A) #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) #define TEMP11_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ @@ -68,8 +68,9 @@ static const int max31760_pwm_freq[] = {33, 150, 1500, 25000}; static int tach_to_rpm(u16 tach) { + /* The count is 0 until the first measurement */ if (tach == 0) - tach = 1; + return 0; return 60 * 100000 / tach / 2; } @@ -521,7 +522,7 @@ static int max31760_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; @@ -533,8 +534,9 @@ static int max31760_probe(struct i2c_client *client) dev_set_drvdata(dev, state); - /* Set alert output to comparator mode */ - ret = regmap_set_bits(state->regmap, REG_CR2, CR2_ALERTS); + /* Leave standby mode, set alert output to comparator mode */ + ret = regmap_update_bits(state->regmap, REG_CR2, CR2_STBY | CR2_ALERTS, + CR2_ALERTS); if (ret) return dev_err_probe(dev, ret, "cannot write register\n"); diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index db8a0f6f18294b..26a738600c4855 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -495,7 +495,7 @@ static int max31790_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct max31790_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max31790_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c index 6a7048fdd8ab7a..5abf6d9229c659 100644 --- a/drivers/hwmon/max31827.c +++ b/drivers/hwmon/max31827.c @@ -589,7 +589,7 @@ static int max31827_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -EOPNOTSUPP; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/max6620.c b/drivers/hwmon/max6620.c index 100acf357b5f5b..a1a26dc42cc2cf 100644 --- a/drivers/hwmon/max6620.c +++ b/drivers/hwmon/max6620.c @@ -455,7 +455,7 @@ static int max6620_probe(struct i2c_client *client) struct device *hwmon_dev; int err; - data = devm_kzalloc(dev, sizeof(struct max6620_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max6620_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max6621.c b/drivers/hwmon/max6621.c index 1a644d78714314..867a66b738fade 100644 --- a/drivers/hwmon/max6621.c +++ b/drivers/hwmon/max6621.c @@ -485,7 +485,7 @@ static int max6621_probe(struct i2c_client *client) int i; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index dd5f4b3b128dae..9858ac2d2a1d04 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c @@ -706,7 +706,7 @@ static int max6639_probe(struct i2c_client *client) struct device *hwmon_dev; int err; - data = devm_kzalloc(dev, sizeof(struct max6639_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max6639_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 90c37f5647bcfe..9ad95c9ea5b011 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -768,7 +768,7 @@ static int max6650_probe(struct i2c_client *client) struct device *hwmon_dev; int err; - data = devm_kzalloc(dev, sizeof(struct max6650_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max6650_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c index c864093f015c02..a41cee06a74987 100644 --- a/drivers/hwmon/max6697.c +++ b/drivers/hwmon/max6697.c @@ -546,7 +546,7 @@ static int max6697_probe(struct i2c_client *client) if (IS_ERR(regmap)) return PTR_ERR(regmap); - data = devm_kzalloc(dev, sizeof(struct max6697_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max6697_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c index b217b39a046adc..dac08f7ab3874c 100644 --- a/drivers/hwmon/mc13783-adc.c +++ b/drivers/hwmon/mc13783-adc.c @@ -230,7 +230,7 @@ static int __init mc13783_adc_probe(struct platform_device *pdev) const struct platform_device_id *id = platform_get_device_id(pdev); char *dash; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/mc34vr500.c b/drivers/hwmon/mc34vr500.c index 8cb9d5c09033f0..646ebb2332e878 100644 --- a/drivers/hwmon/mc34vr500.c +++ b/drivers/hwmon/mc34vr500.c @@ -174,7 +174,7 @@ static int mc34vr500_probe(struct i2c_client *client) if (IS_ERR(regmap)) return PTR_ERR(regmap); - data = devm_kzalloc(dev, sizeof(struct mc34vr500_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct mc34vr500_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/mcp3021.c b/drivers/hwmon/mcp3021.c index d6b0ebf27941f5..087b595bf5ad81 100644 --- a/drivers/hwmon/mcp3021.c +++ b/drivers/hwmon/mcp3021.c @@ -126,8 +126,7 @@ static int mcp3021_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct mcp3021_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mcp3021_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/mcp9982.c b/drivers/hwmon/mcp9982.c index 2cd41dcbd9af78..0c0f5304d29f00 100644 --- a/drivers/hwmon/mcp9982.c +++ b/drivers/hwmon/mcp9982.c @@ -923,7 +923,7 @@ static int mcp9982_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - priv = devm_kzalloc(dev, sizeof(struct mcp9982_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct mcp9982_priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c index adb50115c32bf7..4ab44c7076cd61 100644 --- a/drivers/hwmon/menf21bmc_hwmon.c +++ b/drivers/hwmon/menf21bmc_hwmon.c @@ -192,8 +192,7 @@ static int menf21bmc_hwmon_probe(struct platform_device *pdev) struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent); struct device *hwmon_dev; - drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon), - GFP_KERNEL); + drv_data = devm_kzalloc_obj(&pdev->dev, struct menf21bmc_hwmon); if (!drv_data) return -ENOMEM; diff --git a/drivers/hwmon/minisforum-um780xtx.c b/drivers/hwmon/minisforum-um780xtx.c index bbd77a0ce25dda..c1a9fe73ce655d 100644 --- a/drivers/hwmon/minisforum-um780xtx.c +++ b/drivers/hwmon/minisforum-um780xtx.c @@ -425,7 +425,7 @@ static int um780xtx_probe(struct platform_device *pdev) struct device *hwmon; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; platform_set_drvdata(pdev, data); diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c index 860de6cfd8a4da..3e0b188c59fc23 100644 --- a/drivers/hwmon/mlxreg-fan.c +++ b/drivers/hwmon/mlxreg-fan.c @@ -608,7 +608,7 @@ static int mlxreg_fan_probe(struct platform_device *pdev) return -EINVAL; } - fan = devm_kzalloc(dev, sizeof(*fan), GFP_KERNEL); + fan = devm_kzalloc_obj(dev, *fan); if (!fan) return -ENOMEM; diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 449f2ce13a2df1..d1945a28098be5 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -664,8 +664,7 @@ static int pvt_get_active_channel(struct device *dev, struct pvt_device *pvt, * vm_map = [0 0 0 0 0 1 1 2 2 2 2] * ch_map = [0 1 2 3 4 0 1 0 1 2 3] */ - pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd), - GFP_KERNEL); + pvt->vd = devm_kzalloc_objs(dev, *pvt->vd, pvt->vm_channels.total); if (!pvt->vd) return -ENOMEM; @@ -772,7 +771,7 @@ static int mr75203_probe(struct platform_device *pdev) struct pvt_device *pvt; int ret; - pvt = devm_kzalloc(dev, sizeof(*pvt), GFP_KERNEL); + pvt = devm_kzalloc_obj(dev, *pvt); if (!pvt) return -ENOMEM; @@ -815,7 +814,7 @@ static int mr75203_probe(struct platform_device *pdev) if (!val) return -ENODEV; - pvt_info = devm_kcalloc(dev, val + 2, sizeof(*pvt_info), GFP_KERNEL); + pvt_info = devm_kzalloc_objs(dev, *pvt_info, val + 2); if (!pvt_info) return -ENOMEM; pvt_info[0] = HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ); @@ -830,8 +829,7 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; - temp_config = devm_kcalloc(dev, ts_num + 1, - sizeof(*temp_config), GFP_KERNEL); + temp_config = devm_kzalloc_objs(dev, *temp_config, ts_num + 1); if (!temp_config) return -ENOMEM; @@ -881,8 +879,8 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; - in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1, - sizeof(*in_config), GFP_KERNEL); + in_config = devm_kzalloc_objs(dev, *in_config, + pvt->vm_channels.total + 1); if (!in_config) return -ENOMEM; diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c index e1c36c95affb20..3e8c4db0ce1f9e 100644 --- a/drivers/hwmon/nct6683.c +++ b/drivers/hwmon/nct6683.c @@ -433,12 +433,11 @@ nct6683_create_attr_group(struct device *dev, if (count == 0) return ERR_PTR(-EINVAL); - group = devm_kzalloc(dev, sizeof(*group), GFP_KERNEL); + group = devm_kzalloc_obj(dev, *group); if (group == NULL) return ERR_PTR(-ENOMEM); - attrs = devm_kcalloc(dev, repeat * count + 1, sizeof(*attrs), - GFP_KERNEL); + attrs = devm_kzalloc_objs(dev, *attrs, repeat * count + 1); if (attrs == NULL) return ERR_PTR(-ENOMEM); @@ -920,7 +919,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, char *buf) { struct nct6683_data *data = nct6683_update_device(dev); - struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); int index = sattr->index; return sprintf(buf, "%d\n", data->pwm[index]); @@ -930,7 +929,7 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); struct nct6683_data *data = dev_get_drvdata(dev); int index = sattr->index; unsigned long val; @@ -1209,7 +1208,7 @@ static int nct6683_probe(struct platform_device *pdev) if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) return -EBUSY; - data = devm_kzalloc(dev, sizeof(struct nct6683_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct nct6683_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nct6694-hwmon.c b/drivers/hwmon/nct6694-hwmon.c index 9a9a4db434c4f9..32f96867635f0e 100644 --- a/drivers/hwmon/nct6694-hwmon.c +++ b/drivers/hwmon/nct6694-hwmon.c @@ -906,17 +906,15 @@ static int nct6694_hwmon_probe(struct platform_device *pdev) struct device *hwmon_dev; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; - data->rpt = devm_kzalloc(&pdev->dev, sizeof(union nct6694_hwmon_rpt), - GFP_KERNEL); + data->rpt = devm_kzalloc_obj(&pdev->dev, union nct6694_hwmon_rpt); if (!data->rpt) return -ENOMEM; - data->msg = devm_kzalloc(&pdev->dev, sizeof(union nct6694_hwmon_msg), - GFP_KERNEL); + data->msg = devm_kzalloc_obj(&pdev->dev, union nct6694_hwmon_msg); if (!data->msg) return -ENOMEM; diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c index cf27b9c7a89ed4..3515a962adac85 100644 --- a/drivers/hwmon/nct6775-core.c +++ b/drivers/hwmon/nct6775-core.c @@ -1130,12 +1130,11 @@ static int nct6775_add_template_attr_group(struct device *dev, struct nct6775_da if (count == 0) return -EINVAL; - group = devm_kzalloc(dev, sizeof(*group), GFP_KERNEL); + group = devm_kzalloc_obj(dev, *group); if (group == NULL) return -ENOMEM; - attrs = devm_kcalloc(dev, repeat * count + 1, sizeof(*attrs), - GFP_KERNEL); + attrs = devm_kzalloc_objs(dev, *attrs, repeat * count + 1); if (attrs == NULL) return -ENOMEM; @@ -1189,15 +1188,13 @@ bool nct6775_reg_is_word_sized(struct nct6775_data *data, u16 reg) case nct6106: return reg == 0x20 || reg == 0x22 || reg == 0x24 || (reg >= 0x59 && reg < 0x69 && (reg & 1)) || - reg == 0xe0 || reg == 0xe2 || reg == 0xe4 || - reg == 0x111 || reg == 0x121 || reg == 0x131; + reg == 0xe0 || reg == 0xe2 || reg == 0xe4; case nct6116: case nct6126: return reg == 0x20 || reg == 0x22 || reg == 0x24 || reg == 0x26 || reg == 0x28 || reg == 0x59 || reg == 0x5b || reg == 0xe0 || reg == 0xe2 || reg == 0xe4 || reg == 0xe6 || - reg == 0xe8 || reg == 0x111 || reg == 0x121 || reg == 0x131 || - reg == 0x191 || reg == 0x1a1; + reg == 0xe8; case nct6775: return (((reg & 0xff00) == 0x100 || (reg & 0xff00) == 0x200) && diff --git a/drivers/hwmon/nct6775-i2c.c b/drivers/hwmon/nct6775-i2c.c index 07783910c05882..b1a2ee5e36a8df 100644 --- a/drivers/hwmon/nct6775-i2c.c +++ b/drivers/hwmon/nct6775-i2c.c @@ -157,7 +157,7 @@ static int nct6775_i2c_probe(struct i2c_client *client) struct nct6775_data *data; struct device *dev = &client->dev; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nct6775-platform.c b/drivers/hwmon/nct6775-platform.c index d359c28f3e0f32..7e09fd387d966e 100644 --- a/drivers/hwmon/nct6775-platform.c +++ b/drivers/hwmon/nct6775-platform.c @@ -977,7 +977,7 @@ static int nct6775_platform_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nct7363.c b/drivers/hwmon/nct7363.c index 20f14d5e0c948a..d5e287455f8fe2 100644 --- a/drivers/hwmon/nct7363.c +++ b/drivers/hwmon/nct7363.c @@ -401,7 +401,7 @@ static int nct7363_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index 10d1a41fe21196..476f469d12bdbd 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c @@ -1258,7 +1258,7 @@ static int nct7802_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 00331e23224a54..e7efb0cbe085cf 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -1016,7 +1016,7 @@ static int nct7904_probe(struct i2c_client *client) u32 mask; u8 val, bit; - data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct nct7904_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/npcm750-pwm-fan.c b/drivers/hwmon/npcm750-pwm-fan.c index 9af3bd0b6fb6ba..f41fe7587f81fe 100644 --- a/drivers/hwmon/npcm750-pwm-fan.c +++ b/drivers/hwmon/npcm750-pwm-fan.c @@ -848,7 +848,7 @@ static int npcm7xx_create_pwm_cooling(struct device *dev, int ret; struct npcm7xx_cooling_device *cdev; - cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL); + cdev = devm_kzalloc_obj(dev, *cdev); if (!cdev) return -ENOMEM; @@ -944,7 +944,7 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev) np = dev->of_node; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nsa320-hwmon.c b/drivers/hwmon/nsa320-hwmon.c index 5c99acc0967769..2aaaf9842c18c8 100644 --- a/drivers/hwmon/nsa320-hwmon.c +++ b/drivers/hwmon/nsa320-hwmon.c @@ -160,7 +160,7 @@ static int nsa320_hwmon_probe(struct platform_device *pdev) struct nsa320_hwmon *hwmon; struct device *classdev; - hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(&pdev->dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index 4fa7f522f24511..3ed5048e3deef3 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -650,7 +650,7 @@ static int ntc_thermistor_probe(struct platform_device *pdev) struct ntc_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/nzxt-kraken2.c b/drivers/hwmon/nzxt-kraken2.c index 03469823275861..58e8b9b5a4c552 100644 --- a/drivers/hwmon/nzxt-kraken2.c +++ b/drivers/hwmon/nzxt-kraken2.c @@ -128,7 +128,7 @@ static int kraken2_probe(struct hid_device *hdev, struct kraken2_priv_data *priv; int ret; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/nzxt-kraken3.c b/drivers/hwmon/nzxt-kraken3.c index a185e8b2753217..5237e4e7aeb6ec 100644 --- a/drivers/hwmon/nzxt-kraken3.c +++ b/drivers/hwmon/nzxt-kraken3.c @@ -878,7 +878,7 @@ static int kraken3_probe(struct hid_device *hdev, const struct hid_device_id *id const char *device_name; int ret; - priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&hdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c index efc78a8f58c88c..e80c358c764560 100644 --- a/drivers/hwmon/nzxt-smart2.c +++ b/drivers/hwmon/nzxt-smart2.c @@ -727,7 +727,7 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, struct drvdata *drvdata; int ret; - drvdata = devm_kzalloc(&hdev->dev, sizeof(struct drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&hdev->dev, struct drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c index 175208d712b06e..2fdb293042f7db 100644 --- a/drivers/hwmon/occ/common.c +++ b/drivers/hwmon/occ/common.c @@ -860,15 +860,13 @@ static int occ_setup_sensor_attrs(struct occ *occ) sensors->extended.num_sensors = 0; } - occ->attrs = devm_kcalloc(dev, num_attrs, sizeof(*occ->attrs), - GFP_KERNEL); + occ->attrs = devm_kzalloc_objs(dev, *occ->attrs, num_attrs); if (!occ->attrs) return -ENOMEM; /* null-terminated list */ - occ->group.attrs = devm_kcalloc(dev, num_attrs + 1, - sizeof(*occ->group.attrs), - GFP_KERNEL); + occ->group.attrs = devm_kzalloc_objs(dev, *occ->group.attrs, + num_attrs + 1); if (!occ->group.attrs) return -ENOMEM; diff --git a/drivers/hwmon/occ/p8_i2c.c b/drivers/hwmon/occ/p8_i2c.c index 5817a099c622a8..b4c8e2ea3759a5 100644 --- a/drivers/hwmon/occ/p8_i2c.c +++ b/drivers/hwmon/occ/p8_i2c.c @@ -210,8 +210,7 @@ static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len, static int p8_i2c_occ_probe(struct i2c_client *client) { struct occ *occ; - struct p8_i2c_occ *ctx = devm_kzalloc(&client->dev, sizeof(*ctx), - GFP_KERNEL); + struct p8_i2c_occ *ctx = devm_kzalloc_obj(&client->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c index 4b4cbba58d79fc..5a419030004628 100644 --- a/drivers/hwmon/occ/p9_sbe.c +++ b/drivers/hwmon/occ/p9_sbe.c @@ -134,8 +134,7 @@ static int p9_sbe_occ_probe(struct platform_device *pdev) { int rc; struct occ *occ; - struct p9_sbe_occ *ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), - GFP_KERNEL); + struct p9_sbe_occ *ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 0f8aa6b42164f4..689c948a7d0b5a 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -1445,7 +1445,7 @@ static int pc87360_probe(struct platform_device *pdev) int use_thermistors = 0; struct device *dev = &pdev->dev; - data = devm_kzalloc(dev, sizeof(struct pc87360_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct pc87360_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c index 571402a89368a5..f0ead97e2eac13 100644 --- a/drivers/hwmon/pc87427.c +++ b/drivers/hwmon/pc87427.c @@ -1054,8 +1054,7 @@ static int pc87427_probe(struct platform_device *pdev) struct pc87427_data *data; int i, err, res_count; - data = devm_kzalloc(&pdev->dev, sizeof(struct pc87427_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct pc87427_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c index c0220ebfd4b60d..ec98e6b66c49b2 100644 --- a/drivers/hwmon/pcf8591.c +++ b/drivers/hwmon/pcf8591.c @@ -185,8 +185,7 @@ static int pcf8591_probe(struct i2c_client *client) struct pcf8591_data *data; int err; - data = devm_kzalloc(&client->dev, sizeof(struct pcf8591_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct pcf8591_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/peci/cputemp.c b/drivers/hwmon/peci/cputemp.c index 457089c561b401..9a8a2f14ff7cbc 100644 --- a/drivers/hwmon/peci/cputemp.c +++ b/drivers/hwmon/peci/cputemp.c @@ -450,7 +450,7 @@ static int peci_cputemp_probe(struct auxiliary_device *adev, struct peci_cputemp *priv; struct device *hwmon_dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/peci/dimmtemp.c b/drivers/hwmon/peci/dimmtemp.c index bd3e8715dfece0..483c8936be9b8e 100644 --- a/drivers/hwmon/peci/dimmtemp.c +++ b/drivers/hwmon/peci/dimmtemp.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -326,11 +325,13 @@ static int create_dimm_temp_info(struct peci_dimmtemp *priv) if (ret == -ENODEV) { dev_dbg(priv->dev, "No DIMMs found\n"); return 0; - } else if (ret) { + } + if (ret == -EAGAIN) { schedule_delayed_work(&priv->detect_work, DIMM_MASK_CHECK_DELAY_JIFFIES); dev_dbg(priv->dev, "Deferred populating DIMM temp info\n"); - return ret; } + if (ret) + return ret; channels = priv->gen_info->chan_rank_max * priv->gen_info->dimm_idx_max; @@ -375,7 +376,7 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxil struct peci_dimmtemp *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -398,10 +399,8 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxil "Unexpected PECI revision %#x, some features may be unavailable\n", peci_dev->info.peci_revision); - ret = devm_delayed_work_autocancel(priv->dev, &priv->detect_work, - create_dimm_temp_info_delayed); - if (ret) - return ret; + auxiliary_set_drvdata(adev, priv); + INIT_DELAYED_WORK(&priv->detect_work, create_dimm_temp_info_delayed); ret = create_dimm_temp_info(priv); if (ret && ret != -EAGAIN) { @@ -412,6 +411,13 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxil return 0; } +static void peci_dimmtemp_remove(struct auxiliary_device *adev) +{ + struct peci_dimmtemp *priv = auxiliary_get_drvdata(adev); + + cancel_delayed_work_sync(&priv->detect_work); +} + static int read_thresholds_hsx(struct peci_dimmtemp *priv, int dimm_order, int chan_rank, u32 *data) { @@ -665,6 +671,7 @@ MODULE_DEVICE_TABLE(auxiliary, peci_dimmtemp_ids); static struct auxiliary_driver peci_dimmtemp_driver = { .probe = peci_dimmtemp_probe, + .remove = peci_dimmtemp_remove, .id_table = peci_dimmtemp_ids, }; diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index 22ccb721dd514c..7fdf7a6892f1b6 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -610,7 +610,7 @@ static int adm1266_probe(struct i2c_client *client) int ret; int i; - data = devm_kzalloc(&client->dev, sizeof(struct adm1266_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct adm1266_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c index beb32a878d1c54..a558e222a9df3e 100644 --- a/drivers/hwmon/pmbus/adm1275.c +++ b/drivers/hwmon/pmbus/adm1275.c @@ -600,8 +600,7 @@ static int adm1275_probe(struct i2c_client *client) if (device_config < 0) return device_config; - data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct adm1275_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/dps920ab.c b/drivers/hwmon/pmbus/dps920ab.c index 0d2901c314c2b9..527a043346ac1a 100644 --- a/drivers/hwmon/pmbus/dps920ab.c +++ b/drivers/hwmon/pmbus/dps920ab.c @@ -139,7 +139,7 @@ static int dps920ab_probe(struct i2c_client *client) struct dps920ab_data *data; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/fsp-3y.c b/drivers/hwmon/pmbus/fsp-3y.c index 44cf2db9364b93..e71546ab28f678 100644 --- a/drivers/hwmon/pmbus/fsp-3y.c +++ b/drivers/hwmon/pmbus/fsp-3y.c @@ -228,7 +228,7 @@ static int fsp3y_probe(struct i2c_client *client) const struct i2c_device_id *id; int rv; - data = devm_kzalloc(&client->dev, sizeof(struct fsp3y_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct fsp3y_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/hac300s.c b/drivers/hwmon/pmbus/hac300s.c index 761e53890ebc4b..9172928e37b927 100644 --- a/drivers/hwmon/pmbus/hac300s.c +++ b/drivers/hwmon/pmbus/hac300s.c @@ -86,7 +86,7 @@ static int hac300s_probe(struct i2c_client *client) struct hac300s_data *data; int rv; - data = devm_kzalloc(&client->dev, sizeof(struct hac300s_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct hac300s_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/ibm-cffps.c b/drivers/hwmon/pmbus/ibm-cffps.c index 2498c6f4778ecc..05ead1a73bcc2c 100644 --- a/drivers/hwmon/pmbus/ibm-cffps.c +++ b/drivers/hwmon/pmbus/ibm-cffps.c @@ -536,7 +536,7 @@ static int ibm_cffps_probe(struct i2c_client *client) * Don't fail the probe if there isn't enough memory for leds and * debugfs. */ - psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL); + psu = devm_kzalloc_obj(&client->dev, *psu); if (!psu) return 0; diff --git a/drivers/hwmon/pmbus/ina233.c b/drivers/hwmon/pmbus/ina233.c index c72aa258b7c678..06c55920e9dd94 100644 --- a/drivers/hwmon/pmbus/ina233.c +++ b/drivers/hwmon/pmbus/ina233.c @@ -93,8 +93,7 @@ static int ina233_probe(struct i2c_client *client) u16 calibration; struct pmbus_driver_info *info; - info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), - GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct pmbus_driver_info); if (!info) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/ir35221.c b/drivers/hwmon/pmbus/ir35221.c index b2120fc76f4092..010ad9777053b4 100644 --- a/drivers/hwmon/pmbus/ir35221.c +++ b/drivers/hwmon/pmbus/ir35221.c @@ -99,8 +99,7 @@ static int ir35221_probe(struct i2c_client *client) return -ENODEV; } - info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, struct pmbus_driver_info); if (!info) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/isl68137.c b/drivers/hwmon/pmbus/isl68137.c index 15b4e3f15f11f2..3b615bffd7b72f 100644 --- a/drivers/hwmon/pmbus/isl68137.c +++ b/drivers/hwmon/pmbus/isl68137.c @@ -329,7 +329,7 @@ static int isl68137_probe(struct i2c_client *client) struct isl68137_data *data; int i, err; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c index 497802c646e98a..742244b86570dc 100644 --- a/drivers/hwmon/pmbus/lm25066.c +++ b/drivers/hwmon/pmbus/lm25066.c @@ -475,8 +475,7 @@ static int lm25066_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct lm25066_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct lm25066_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c index aea7b6c93e74be..58c83d4f398daf 100644 --- a/drivers/hwmon/pmbus/ltc2978.c +++ b/drivers/hwmon/pmbus/ltc2978.c @@ -720,8 +720,7 @@ static int ltc2978_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct ltc2978_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct ltc2978_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/ltc4286.c b/drivers/hwmon/pmbus/ltc4286.c index 8190706d1bebb9..ea2f9a5a4b2497 100644 --- a/drivers/hwmon/pmbus/ltc4286.c +++ b/drivers/hwmon/pmbus/ltc4286.c @@ -196,7 +196,7 @@ static int ltc4286_probe(struct i2c_client *client) if (rsense > (INT_MAX / 1024)) return -EINVAL; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/max16601.c b/drivers/hwmon/pmbus/max16601.c index 3dd1f6fd003b89..da9a8e10b386b3 100644 --- a/drivers/hwmon/pmbus/max16601.c +++ b/drivers/hwmon/pmbus/max16601.c @@ -333,7 +333,7 @@ static int max16601_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/max20730.c b/drivers/hwmon/pmbus/max20730.c index 4031f894e6ae7e..1006a4db022dcc 100644 --- a/drivers/hwmon/pmbus/max20730.c +++ b/drivers/hwmon/pmbus/max20730.c @@ -320,7 +320,7 @@ static int max20730_init_debugfs(struct i2c_client *client, return ret; data->mfr_voutmin = ret; - psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL); + psu = devm_kzalloc_obj(&client->dev, *psu); if (!psu) return -ENOMEM; psu->client = client; @@ -717,7 +717,7 @@ static int max20730_probe(struct i2c_client *client) chip_id = (uintptr_t)i2c_get_match_data(client); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; data->id = chip_id; diff --git a/drivers/hwmon/pmbus/max20826.c b/drivers/hwmon/pmbus/max20826.c index 013a97189fde7a..47ec2be2f3a28d 100644 --- a/drivers/hwmon/pmbus/max20826.c +++ b/drivers/hwmon/pmbus/max20826.c @@ -909,7 +909,7 @@ static void max20826_init_debugfs(struct max20826 *st) struct max20826_debugfs_entry *entry; char name[32]; - entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(dev, *entry); if (!entry) return; @@ -930,7 +930,7 @@ static int max20826_probe(struct i2c_client *client) struct max20826 *st; int ret; - st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&client->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/max20830.c b/drivers/hwmon/pmbus/max20830.c index 4d25a084af096b..3bd75a2103e24e 100644 --- a/drivers/hwmon/pmbus/max20830.c +++ b/drivers/hwmon/pmbus/max20830.c @@ -91,7 +91,7 @@ static int max20830_probe(struct i2c_client *client) struct max20830_data *data; int i, ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/max31785.c b/drivers/hwmon/pmbus/max31785.c index bdcce810a4792c..1816744e2d7994 100644 --- a/drivers/hwmon/pmbus/max31785.c +++ b/drivers/hwmon/pmbus/max31785.c @@ -407,7 +407,7 @@ static int max31785_probe(struct i2c_client *client) I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/max34440.c b/drivers/hwmon/pmbus/max34440.c index 7f71dfe4864387..b59e9fd424011a 100644 --- a/drivers/hwmon/pmbus/max34440.c +++ b/drivers/hwmon/pmbus/max34440.c @@ -790,8 +790,7 @@ static int max34440_probe(struct i2c_client *client) struct max34440_data *data; int rv; - data = devm_kzalloc(&client->dev, sizeof(struct max34440_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct max34440_data); if (!data) return -ENOMEM; data->id = (uintptr_t)i2c_get_match_data(client); diff --git a/drivers/hwmon/pmbus/mp2856.c b/drivers/hwmon/pmbus/mp2856.c index 3d6621e36fd398..9415bb017c1a25 100644 --- a/drivers/hwmon/pmbus/mp2856.c +++ b/drivers/hwmon/pmbus/mp2856.c @@ -399,8 +399,7 @@ static int mp2856_probe(struct i2c_client *client) enum chips chip_id; int ret; - data = devm_kzalloc(&client->dev, sizeof(struct mp2856_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2856_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp2869.c b/drivers/hwmon/pmbus/mp2869.c index 76c6017507b3b2..994524150192d1 100644 --- a/drivers/hwmon/pmbus/mp2869.c +++ b/drivers/hwmon/pmbus/mp2869.c @@ -620,8 +620,7 @@ static int mp2869_probe(struct i2c_client *client) struct pmbus_driver_info *info; struct mp2869_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct mp2869_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2869_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp2888.c b/drivers/hwmon/pmbus/mp2888.c index 7a2ecffba960e6..4d4e9798370638 100644 --- a/drivers/hwmon/pmbus/mp2888.c +++ b/drivers/hwmon/pmbus/mp2888.c @@ -357,7 +357,7 @@ static int mp2888_probe(struct i2c_client *client) struct mp2888_data *data; int ret; - data = devm_kzalloc(&client->dev, sizeof(struct mp2888_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2888_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp2891.c b/drivers/hwmon/pmbus/mp2891.c index 316c1fc0d6ccf1..db315ff40b6bf9 100644 --- a/drivers/hwmon/pmbus/mp2891.c +++ b/drivers/hwmon/pmbus/mp2891.c @@ -562,7 +562,7 @@ static int mp2891_probe(struct i2c_client *client) { struct mp2891_data *data; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp2925.c b/drivers/hwmon/pmbus/mp2925.c index 0a58b1ffd79108..b293996b39f0a2 100644 --- a/drivers/hwmon/pmbus/mp2925.c +++ b/drivers/hwmon/pmbus/mp2925.c @@ -295,7 +295,7 @@ static int mp2925_probe(struct i2c_client *client) { struct mp2925_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct mp2925_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2925_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp29502.c b/drivers/hwmon/pmbus/mp29502.c index afc5e8c07e2598..2f3a47bfcb931c 100644 --- a/drivers/hwmon/pmbus/mp29502.c +++ b/drivers/hwmon/pmbus/mp29502.c @@ -630,8 +630,7 @@ static int mp29502_probe(struct i2c_client *client) struct pmbus_driver_info *info; struct mp29502_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct mp29502_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp29502_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index 8e5193933ceb9c..2ad6b7d831c8dc 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -109,10 +109,7 @@ struct mp2975_data { int vout_scale; int max_phases[MP2975_PAGE_NUM]; int vid_step[MP2975_PAGE_NUM]; - int vref[MP2975_PAGE_NUM]; - int vref_off[MP2975_PAGE_NUM]; int vout_max[MP2975_PAGE_NUM]; - int vout_ov_fixed[MP2975_PAGE_NUM]; int curr_sense_gain[MP2975_PAGE_NUM]; }; @@ -460,12 +457,77 @@ static int mp2973_write_word_data(struct i2c_client *client, int page, return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret); } +/* + * Let the PMBus core change the page, so that the page it caches matches the + * device. The core does not issue PAGE commands for a single rail + * configuration, thus change the page directly then. + */ +static int +mp2975_page_set(struct i2c_client *client, struct mp2975_data *data, int page) +{ + if (data->info.pages > 1) + return pmbus_set_page(client, page, 0xff); + + return i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); +} + +/* + * Voltage reference is available on page 3 only. The callers read a register + * of the rail through the core first, thus the core caches the rail page. + */ +static int +mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data, int page) +{ + int ret, vref; + + ret = mp2975_page_set(client, data, 3); + if (ret < 0) + return ret; + + vref = i2c_smbus_read_word_data(client, page ? MP2975_MFR_READ_VREF_R2 : + MP2975_MFR_READ_VREF_R1); + + ret = mp2975_page_set(client, data, page); + if (ret < 0) + return ret; + + return (vref < 0) ? vref : vref * data->vid_step[page]; +} + +static int +mp2975_ovp2_offset_get(int ovp_th_set) +{ + switch ((ovp_th_set & GENMASK(5, 3)) >> 3) { + case 1: + return 140; + case 2: + return 220; + case 4: + return 400; + default: + return -EINVAL; + } +} + +static int +mp2975_vout_ovp2_get(struct i2c_client *client, struct mp2975_data *data, + int page, int vref_off) +{ + int vref; + + vref = mp2975_vref_get(client, data, page); + if (vref < 0) + return vref; + + return vref + DIV_ROUND_CLOSEST(vref_off * data->vout_scale, 10); +} + static int mp2975_read_word_data(struct i2c_client *client, int page, int phase, int reg) { const struct pmbus_driver_info *info = pmbus_get_driver_info(client); struct mp2975_data *data = to_mp2975_data(info); - int ret; + int ret, ovp1, vref_off, uv_off; switch (reg) { case PMBUS_OT_FAULT_LIMIT: @@ -482,19 +544,35 @@ static int mp2975_read_word_data(struct i2c_client *client, int page, break; case PMBUS_VOUT_OV_FAULT_LIMIT: /* - * Register provides two values for over-voltage protection - * threshold for fixed (ovp2) and tracking (ovp1) modes. The - * minimum of these two values is provided as over-voltage - * fault alarm. + * Device provides dual over-voltage protection. OVP1 is + * referred to the maximum reference voltage, while OVP2 is + * referred to the current voltage reference, which is changed + * at runtime. Protection is tripped by any of them, thus the + * minimum of the two is exposed as over-voltage fault alarm, + * and OVP2 is obtained on each read. */ ret = mp2975_read_word_helper(client, page, phase, MP2975_MFR_OVP_TH_SET, - GENMASK(2, 0)); + GENMASK(5, 0)); if (ret < 0) return ret; - ret = min_t(int, data->vout_max[page] + 50 * (ret + 1), - data->vout_ov_fixed[page]); + ovp1 = data->vout_max[page] + 50 * ((ret & GENMASK(2, 0)) + 1); + + /* OVP1 still applies if the OVP2 threshold is unknown. */ + vref_off = mp2975_ovp2_offset_get(ret); + if (vref_off < 0) { + dev_warn_once(&client->dev, + "unsupported OVP2 selector, reporting OVP1 threshold\n"); + ret = ovp1; + break; + } + + ret = mp2975_vout_ovp2_get(client, data, page, vref_off); + if (ret < 0) + return ret; + + ret = min_t(int, ovp1, ret); break; case PMBUS_VOUT_UV_FAULT_LIMIT: ret = mp2975_read_word_helper(client, page, phase, @@ -503,8 +581,17 @@ static int mp2975_read_word_data(struct i2c_client *client, int page, if (ret < 0) return ret; - ret = DIV_ROUND_CLOSEST(data->vref[page] * 10 - 50 * - (ret + 1) * data->vout_scale, 10); + uv_off = 50 * (ret + 1) * data->vout_scale; + + ret = mp2975_vref_get(client, data, page); + if (ret < 0) + return ret; + + /* + * Offset can exceed the voltage reference, while a negative + * value would be reported as a read error. + */ + ret = max_t(int, DIV_ROUND_CLOSEST(ret * 10 - uv_off, 10), 0); break; case PMBUS_VIRT_READ_POUT_MAX: ret = mp2975_read_word_helper(client, page, phase, @@ -753,60 +840,6 @@ mp2975_current_sense_gain_get(struct i2c_client *client, return 0; } -static int -mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data, - struct pmbus_driver_info *info) -{ - int ret; - - ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 3); - if (ret < 0) - return ret; - - /* Get voltage reference value for rail 1. */ - ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R1); - if (ret < 0) - return ret; - - data->vref[0] = ret * data->vid_step[0]; - - /* Get voltage reference value for rail 2, if connected. */ - if (data->info.pages == MP2975_PAGE_NUM) { - ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R2); - if (ret < 0) - return ret; - - data->vref[1] = ret * data->vid_step[1]; - } - return 0; -} - -static int -mp2975_vref_offset_get(struct i2c_client *client, struct mp2975_data *data, - int page) -{ - int ret; - - ret = i2c_smbus_read_word_data(client, MP2975_MFR_OVP_TH_SET); - if (ret < 0) - return ret; - - switch ((ret & GENMASK(5, 3)) >> 3) { - case 1: - data->vref_off[page] = 140; - break; - case 2: - data->vref_off[page] = 220; - break; - case 4: - data->vref_off[page] = 400; - break; - default: - return -EINVAL; - } - return 0; -} - static int mp2975_vout_max_get(struct i2c_client *client, struct mp2975_data *data, struct pmbus_driver_info *info, int page) @@ -911,25 +944,6 @@ mp2975_vout_per_rail_config_get(struct i2c_client *client, ret = mp2975_vout_max_get(client, data, info, i); if (ret < 0) return ret; - - /* Skip if reading Vref is unsupported */ - if (data->chip_id != mp2975) - continue; - - /* Obtain voltage reference offsets. */ - ret = mp2975_vref_offset_get(client, data, i); - if (ret < 0) - return ret; - - /* - * Set over-voltage fixed value. Thresholds are provided as - * fixed value, and tracking value. The minimum of them are - * exposed as over-voltage critical threshold. - */ - data->vout_ov_fixed[i] = data->vref[i] + - DIV_ROUND_CLOSEST(data->vref_off[i] * - data->vout_scale, - 10); } return 0; @@ -999,8 +1013,7 @@ static int mp2975_probe(struct i2c_client *client) if (!ddinfo) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2975_data); if (!data) return -ENOMEM; @@ -1043,11 +1056,6 @@ static int mp2975_probe(struct i2c_client *client) if (ret) return ret; - /* Obtain voltage reference values. */ - ret = mp2975_vref_get(client, data, info); - if (ret) - return ret; - /* Obtain vout over-voltage scales. */ ret = mp2975_vout_ov_scale_get(client, data, info); if (ret < 0) @@ -1064,7 +1072,21 @@ static int mp2975_probe(struct i2c_client *client) if (ret) return ret; - return pmbus_do_probe(client, info); + ret = pmbus_do_probe(client, info); + if (ret) + return ret; + + /* + * Vout over- and under-voltage fault limits are relative to the + * voltage reference, which is changed at runtime. Do not allow the + * PMBus core to cache them. + */ + if (data->chip_id == mp2975) { + pmbus_set_update(client, PMBUS_VOUT_OV_FAULT_LIMIT, true); + pmbus_set_update(client, PMBUS_VOUT_UV_FAULT_LIMIT, true); + } + + return 0; } static const struct of_device_id mp2975_of_match[] = { diff --git a/drivers/hwmon/pmbus/mp2985.c b/drivers/hwmon/pmbus/mp2985.c index b0a4796ca8ce0c..33ab6a91653844 100644 --- a/drivers/hwmon/pmbus/mp2985.c +++ b/drivers/hwmon/pmbus/mp2985.c @@ -364,7 +364,7 @@ static int mp2985_probe(struct i2c_client *client) { struct mp2985_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct mp2985_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp2985_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp5926.c b/drivers/hwmon/pmbus/mp5926.c index a40647472b1601..6b5e2135896de3 100644 --- a/drivers/hwmon/pmbus/mp5926.c +++ b/drivers/hwmon/pmbus/mp5926.c @@ -123,8 +123,7 @@ static int mp5926_probe(struct i2c_client *client) struct pmbus_driver_info *info; int ret; - data = devm_kzalloc(&client->dev, sizeof(struct mp5926_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp5926_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp5990.c b/drivers/hwmon/pmbus/mp5990.c index f8a5d1b42ff7ab..c5d597d48c7b57 100644 --- a/drivers/hwmon/pmbus/mp5990.c +++ b/drivers/hwmon/pmbus/mp5990.c @@ -161,8 +161,7 @@ static int mp5990_probe(struct i2c_client *client) enum chips chip; int ret; - data = devm_kzalloc(&client->dev, sizeof(struct mp5990_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mp5990_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp9941.c b/drivers/hwmon/pmbus/mp9941.c index d9049d326c809d..c940ffa14e948d 100644 --- a/drivers/hwmon/pmbus/mp9941.c +++ b/drivers/hwmon/pmbus/mp9941.c @@ -281,7 +281,7 @@ static int mp9941_probe(struct i2c_client *client) { struct mp9941_data *data; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mp9945.c b/drivers/hwmon/pmbus/mp9945.c index 199480d855157f..affed1187146a0 100644 --- a/drivers/hwmon/pmbus/mp9945.c +++ b/drivers/hwmon/pmbus/mp9945.c @@ -197,7 +197,7 @@ static int mp9945_probe(struct i2c_client *client) struct mp9945_data *data; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mpq7932.c b/drivers/hwmon/pmbus/mpq7932.c index f49610adff89c4..822177adbb3fcc 100644 --- a/drivers/hwmon/pmbus/mpq7932.c +++ b/drivers/hwmon/pmbus/mpq7932.c @@ -106,7 +106,7 @@ static int mpq7932_probe(struct i2c_client *client) struct device *dev = &client->dev; int i; - data = devm_kzalloc(dev, sizeof(struct mpq7932_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct mpq7932_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mpq82d00.c b/drivers/hwmon/pmbus/mpq82d00.c index d51fcffcc6d938..c8f7b5873e3978 100644 --- a/drivers/hwmon/pmbus/mpq82d00.c +++ b/drivers/hwmon/pmbus/mpq82d00.c @@ -211,7 +211,7 @@ static int mpq82d00_probe(struct i2c_client *client) { struct mpq82d00_data *data; - data = devm_kzalloc(&client->dev, sizeof(struct mpq82d00_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mpq82d00_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/mpq8646.c b/drivers/hwmon/pmbus/mpq8646.c index 6ac82beb098132..67eea432713833 100644 --- a/drivers/hwmon/pmbus/mpq8646.c +++ b/drivers/hwmon/pmbus/mpq8646.c @@ -769,9 +769,8 @@ static void mpq8646_debugfs_register_unsafe(struct mpq8646_priv *priv, debugfs_create_file_unsafe("restore_all", 0200, root, priv, &mpq8646_dbg_restore_all_fops); - ctx = devm_kcalloc(&priv->client->dev, - ARRAY_SIZE(mpq8646_dbg_regs_unsafe), - sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_objs(&priv->client->dev, *ctx, + ARRAY_SIZE(mpq8646_dbg_regs_unsafe)); if (!ctx) return; for (i = 0; i < ARRAY_SIZE(mpq8646_dbg_regs_unsafe); i++) { @@ -830,10 +829,9 @@ static void mpq8646_debugfs_register(struct mpq8646_priv *priv) root, priv, &mpq8646_dbg_poll_interval_fops); - priv->dbg_reg_ctx = devm_kcalloc(&priv->client->dev, - ARRAY_SIZE(mpq8646_dbg_regs), - sizeof(*priv->dbg_reg_ctx), - GFP_KERNEL); + priv->dbg_reg_ctx = devm_kzalloc_objs(&priv->client->dev, + *priv->dbg_reg_ctx, + ARRAY_SIZE(mpq8646_dbg_regs)); if (!priv->dbg_reg_ctx) return; for (i = 0; i < ARRAY_SIZE(mpq8646_dbg_regs); i++) { @@ -882,7 +880,7 @@ static int mpq8646_probe(struct i2c_client *client) u32 voltage_scale; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->client = client; diff --git a/drivers/hwmon/pmbus/pim4328.c b/drivers/hwmon/pmbus/pim4328.c index 9056dc387e878f..76dbf6c66457d0 100644 --- a/drivers/hwmon/pmbus/pim4328.c +++ b/drivers/hwmon/pmbus/pim4328.c @@ -145,8 +145,7 @@ static int pim4328_probe(struct i2c_client *client) | I2C_FUNC_SMBUS_BLOCK_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct pim4328_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct pim4328_data); if (!data) return -ENOMEM; @@ -175,8 +174,7 @@ static int pim4328_probe(struct i2c_client *client) info->read_byte_data = pim4328_read_byte_data; info->read_word_data = pim4328_read_word_data; - pdata = devm_kzalloc(dev, sizeof(struct pmbus_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct pmbus_platform_data); if (!pdata) return -ENOMEM; dev->platform_data = pdata; diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c index 7a7eac90d62e52..28889fb743b3ed 100644 --- a/drivers/hwmon/pmbus/pmbus.c +++ b/drivers/hwmon/pmbus/pmbus.c @@ -168,14 +168,13 @@ static int pmbus_probe(struct i2c_client *client) struct device *dev = &client->dev; struct pmbus_device_info *device_info; - info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct pmbus_driver_info); if (!info) return -ENOMEM; device_info = (struct pmbus_device_info *)i2c_get_match_data(client); if (device_info->flags) { - pdata = devm_kzalloc(dev, sizeof(struct pmbus_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct pmbus_platform_data); if (!pdata) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index d69f1bde17956e..82dac2c6c579f2 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1458,7 +1458,7 @@ static int pmbus_add_boolean(struct pmbus_data *data, if (WARN((s1 && !s2) || (!s1 && s2), "Bad s1/s2 parameters\n")) return -EINVAL; - boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL); + boolean = devm_kzalloc_obj(data->dev, *boolean); if (!boolean) return -ENOMEM; @@ -1517,21 +1517,29 @@ static int pmbus_thermal_add_sensor(struct pmbus_data *pmbus_data, struct pmbus_thermal_data *tdata; struct thermal_zone_device *tzd; - tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL); + tdata = devm_kzalloc_obj(dev, *tdata); if (!tdata) return -ENOMEM; tdata->sensor = sensor; tdata->pmbus_data = pmbus_data; - tzd = devm_thermal_of_zone_register(dev, index, tdata, + /* + * The PMBus core numbers its temperature sensors from 1, as the + * hwmon tempN attributes, while the thermal core expects a 0-based + * sensor index. + */ + tzd = devm_thermal_of_zone_register(dev, index - 1, tdata, &pmbus_thermal_ops); /* - * If CONFIG_THERMAL_OF is disabled, this returns -ENODEV, - * so ignore that error but forward any other error. + * If CONFIG_THERMAL_OF is disabled, devm_thermal_of_zone_register() + * returns -ENOTSUPP. If no thermal zone is configured for the sensor, + * it returns -ENODEV. Ignore those errors but forward any other error. */ - if (IS_ERR(tzd) && (PTR_ERR(tzd) != -ENODEV)) + if (IS_ERR(tzd) && PTR_ERR(tzd) != -ENODEV && PTR_ERR(tzd) != -ENOTSUPP) { + devm_kfree(dev, tdata); return PTR_ERR(tzd); + } return 0; } @@ -1546,10 +1554,11 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, { struct sensor_device_attribute *a; struct pmbus_sensor *sensor; + int err; - sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(data->dev, *sensor); if (!sensor) - return NULL; + return ERR_PTR(-ENOMEM); a = &sensor->attribute; if (type) @@ -1574,14 +1583,17 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, pmbus_set_sensor, -1); if (pmbus_add_attribute(data, &a->dev_attr.attr)) - return NULL; + return ERR_PTR(-ENOMEM); sensor->next = data->sensors; data->sensors = sensor; /* temperature sensors with _input values are registered with thermal */ - if (class == PSC_TEMPERATURE && strcmp(type, "input") == 0) - pmbus_thermal_add_sensor(data, sensor, seq); + if (class == PSC_TEMPERATURE && strcmp(type, "input") == 0) { + err = pmbus_thermal_add_sensor(data, sensor, seq); + if (err) + return ERR_PTR(err); + } return sensor; } @@ -1593,7 +1605,7 @@ static int pmbus_add_label(struct pmbus_data *data, struct sensor_device_attribute *a; struct pmbus_label *label; - label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL); + label = devm_kzalloc_obj(data->dev, *label); if (!label) return -ENOMEM; @@ -1682,8 +1694,8 @@ static int pmbus_add_limit_attrs(struct i2c_client *client, page, 0xff, l->reg, attr->class, attr->update || l->update, l->readonly, l->writeonly, true); - if (!curr) - return -ENOMEM; + if (IS_ERR(curr)) + return PTR_ERR(curr); if (l->sbit && (info->func[page] & attr->sfunc)) { ret = pmbus_add_boolean(data, name, l->alarm, index, @@ -1722,8 +1734,8 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, } base = pmbus_add_sensor(data, name, "input", index, page, phase, attr->reg, attr->class, true, true, false, true); - if (!base) - return -ENOMEM; + if (IS_ERR(base)) + return PTR_ERR(base); /* No limit and alarm attributes for phase specific sensors */ if (attr->sfunc && phase == 0xff) { ret = pmbus_add_limit_attrs(client, data, info, name, @@ -2396,8 +2408,8 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client, 0xff, PMBUS_VIRT_FAN_TARGET_1 + id, PSC_FAN, false, false, false, true); - if (!sensor) - return -ENOMEM; + if (IS_ERR(sensor)) + return PTR_ERR(sensor); if (!((data->info->func[page] & PMBUS_HAVE_PWM12) || (data->info->func[page] & PMBUS_HAVE_PWM34))) @@ -2407,15 +2419,15 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client, 0xff, PMBUS_VIRT_PWM_1 + id, PSC_PWM, false, false, false, true); - if (!sensor) - return -ENOMEM; + if (IS_ERR(sensor)) + return PTR_ERR(sensor); sensor = pmbus_add_sensor(data, "pwm", "enable", index, page, 0xff, PMBUS_VIRT_PWM_ENABLE_1 + id, PSC_PWM, true, false, false, false); - if (!sensor) - return -ENOMEM; + if (IS_ERR(sensor)) + return PTR_ERR(sensor); return 0; } @@ -2432,6 +2444,7 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, int f; for (f = 0; f < ARRAY_SIZE(pmbus_fan_registers); f++) { + struct pmbus_sensor *sensor; int regval; if (!(info->func[page] & pmbus_fan_flags[f])) @@ -2452,10 +2465,11 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, (!(regval & (PB_FAN_1_INSTALLED >> ((f & 1) * 4))))) continue; - if (pmbus_add_sensor(data, "fan", "input", index, - page, 0xff, pmbus_fan_registers[f], - PSC_FAN, true, true, false, true) == NULL) - return -ENOMEM; + sensor = pmbus_add_sensor(data, "fan", "input", index, + page, 0xff, pmbus_fan_registers[f], + PSC_FAN, true, true, false, true); + if (IS_ERR(sensor)) + return PTR_ERR(sensor); /* Fan control */ if (pmbus_check_word_register(client, page, @@ -2571,7 +2585,7 @@ static int pmbus_add_samples_attr(struct pmbus_data *data, int page, struct sensor_device_attribute *a; struct pmbus_samples_reg *reg; - reg = devm_kzalloc(data->dev, sizeof(*reg), GFP_KERNEL); + reg = devm_kzalloc_obj(data->dev, *reg); if (!reg) return -ENOMEM; @@ -3804,10 +3818,8 @@ static void pmbus_init_debugfs(struct i2c_client *client, * page specific: * ARRAY_SIZE(pmbus_debugfs_status_data) + 1 */ - entries = devm_kcalloc(data->dev, - ARRAY_SIZE(pmbus_debugfs_block_data) + 2 + - data->info->pages * (ARRAY_SIZE(pmbus_debugfs_status_data) + 1), - sizeof(*entries), GFP_KERNEL); + entries = devm_kzalloc_objs(data->dev, *entries, + ARRAY_SIZE(pmbus_debugfs_block_data) + 2 + data->info->pages * (ARRAY_SIZE(pmbus_debugfs_status_data) + 1)); if (!entries) return; @@ -3896,7 +3908,7 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info) | I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/q54sj108a2.c b/drivers/hwmon/pmbus/q54sj108a2.c index ecac405d753620..bdacd39fd07f8f 100644 --- a/drivers/hwmon/pmbus/q54sj108a2.c +++ b/drivers/hwmon/pmbus/q54sj108a2.c @@ -344,13 +344,15 @@ static int q54sj108a2_probe(struct i2c_client *client) if (ret) return ret; - psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL); + psu = devm_kzalloc_obj(&client->dev, *psu); if (!psu) return 0; psu->client = client; debugfs = pmbus_get_debugfs_dir(client); + if (!debugfs) + return 0; q54sj108a2_dir = debugfs_create_dir(client->name, debugfs); diff --git a/drivers/hwmon/pmbus/tda38640.c b/drivers/hwmon/pmbus/tda38640.c index 8039266333700c..8e67f3f0add9fc 100644 --- a/drivers/hwmon/pmbus/tda38640.c +++ b/drivers/hwmon/pmbus/tda38640.c @@ -164,7 +164,7 @@ static int tda38640_probe(struct i2c_client *client) struct tda38640_data *data; int svid; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; memcpy(&data->info, &tda38640_info, sizeof(tda38640_info)); diff --git a/drivers/hwmon/pmbus/tps25990.c b/drivers/hwmon/pmbus/tps25990.c index 0d5c99053f23f1..a4ee30c07e88c4 100644 --- a/drivers/hwmon/pmbus/tps25990.c +++ b/drivers/hwmon/pmbus/tps25990.c @@ -530,7 +530,7 @@ static int tps25990_probe(struct i2c_client *client) chip_id = (enum chips)(unsigned long)i2c_get_match_data(client); - data = devm_kzalloc(dev, sizeof(struct tps25990_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tps25990_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c index f76c2913c9caec..ef2b67fb278733 100644 --- a/drivers/hwmon/pmbus/ucd9000.c +++ b/drivers/hwmon/pmbus/ucd9000.c @@ -468,9 +468,7 @@ static int ucd9000_init_debugfs(struct i2c_client *client, mid->driver_data == ucd90320 || mid->driver_data == ucd90910) { gpi_count = mid->driver_data == ucd90320 ? UCD90320_GPI_COUNT : UCD9000_GPI_COUNT; - entries = devm_kcalloc(&client->dev, - gpi_count, sizeof(*entries), - GFP_KERNEL); + entries = devm_kzalloc_objs(&client->dev, *entries, gpi_count); if (!entries) return -ENOMEM; @@ -542,8 +540,7 @@ static int ucd9000_probe(struct i2c_client *client) "Device mismatch: Configured %s, detected %s\n", client->name, mid->name); - data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct ucd9000_data); if (!data) return -ENOMEM; info = &data->info; diff --git a/drivers/hwmon/pmbus/ucd9200.c b/drivers/hwmon/pmbus/ucd9200.c index 5e07bba111a162..f038c07411a4d8 100644 --- a/drivers/hwmon/pmbus/ucd9200.c +++ b/drivers/hwmon/pmbus/ucd9200.c @@ -112,8 +112,7 @@ static int ucd9200_probe(struct i2c_client *client) "Device mismatch: Configured %s, detected %s\n", client->name, mid->name); - info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, struct pmbus_driver_info); if (!info) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/vt7505.c b/drivers/hwmon/pmbus/vt7505.c index 6a66f06eddb86b..d0aa964141aa69 100644 --- a/drivers/hwmon/pmbus/vt7505.c +++ b/drivers/hwmon/pmbus/vt7505.c @@ -176,7 +176,7 @@ static int vt7505_probe(struct i2c_client *client) if (!chip) return -ENODEV; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/xdp720.c b/drivers/hwmon/pmbus/xdp720.c index 5a162084f338b4..71f4d066cab2df 100644 --- a/drivers/hwmon/pmbus/xdp720.c +++ b/drivers/hwmon/pmbus/xdp720.c @@ -80,7 +80,7 @@ static int xdp720_probe(struct i2c_client *client) u32 rimon; int gimon; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pmbus/zl6100.c b/drivers/hwmon/pmbus/zl6100.c index 5db2a7818d165e..bccf9806b695d8 100644 --- a/drivers/hwmon/pmbus/zl6100.c +++ b/drivers/hwmon/pmbus/zl6100.c @@ -312,8 +312,7 @@ static int zl6100_probe(struct i2c_client *client) "Device mismatch: Configured %s, detected %s\n", client->name, mid->name); - data = devm_kzalloc(&client->dev, sizeof(struct zl6100_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct zl6100_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/powerz.c b/drivers/hwmon/powerz.c index 6e1359144cabef..5442408f6e8d0c 100644 --- a/drivers/hwmon/powerz.c +++ b/drivers/hwmon/powerz.c @@ -227,7 +227,7 @@ static int powerz_probe(struct usb_interface *intf, parent = &intf->dev; - priv = devm_kzalloc(parent, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(parent, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/powr1220.c b/drivers/hwmon/powr1220.c index 6e211601ea26b7..93374e093eacee 100644 --- a/drivers/hwmon/powr1220.c +++ b/drivers/hwmon/powr1220.c @@ -280,7 +280,7 @@ static int powr1220_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/prom21-xhci.c b/drivers/hwmon/prom21-xhci.c index d40d0c53ce4562..846aac4eb73e9a 100644 --- a/drivers/hwmon/prom21-xhci.c +++ b/drivers/hwmon/prom21-xhci.c @@ -182,7 +182,7 @@ static int prom21_xhci_probe(struct auxiliary_device *auxdev, pdata->rsrc_len < PROM21_XHCI_DATA_OFFSET + sizeof(u32)) return dev_err_probe(dev, -ENODEV, "invalid MMIO resource\n"); - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/pt5161l.c b/drivers/hwmon/pt5161l.c index 1638f54f8eaebf..ea05617c79c978 100644 --- a/drivers/hwmon/pt5161l.c +++ b/drivers/hwmon/pt5161l.c @@ -583,7 +583,7 @@ static int pt5161l_probe(struct i2c_client *client) struct device *hwmon_dev; struct pt5161l_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 9cabbe9f8462b0..f21150a5662546 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -514,7 +514,7 @@ static int pwm_fan_probe(struct platform_device *pdev) int channel_count = 1; /* We always have a PWM channel. */ int i; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -590,23 +590,21 @@ static int pwm_fan_probe(struct platform_device *pdev) if (ctx->tach_count) { channel_count++; /* We also have a FAN channel. */ - ctx->tachs = devm_kcalloc(dev, ctx->tach_count, - sizeof(struct pwm_fan_tach), - GFP_KERNEL); + ctx->tachs = devm_kzalloc_objs(dev, struct pwm_fan_tach, + ctx->tach_count); if (!ctx->tachs) return -ENOMEM; ctx->fan_channel.type = hwmon_fan; - fan_channel_config = devm_kcalloc(dev, ctx->tach_count + 1, - sizeof(u32), GFP_KERNEL); + fan_channel_config = devm_kzalloc_objs(dev, u32, + ctx->tach_count + 1); if (!fan_channel_config) return -ENOMEM; ctx->fan_channel.config = fan_channel_config; - ctx->pulses_per_revolution = devm_kmalloc_array(dev, - ctx->tach_count, - sizeof(*ctx->pulses_per_revolution), - GFP_KERNEL); + ctx->pulses_per_revolution = devm_kmalloc_objs(dev, + *ctx->pulses_per_revolution, + ctx->tach_count); if (!ctx->pulses_per_revolution) return -ENOMEM; @@ -618,8 +616,7 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx->pulses_per_revolution, ctx->tach_count); } - channels = devm_kcalloc(dev, channel_count + 1, - sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, channel_count + 1); if (!channels) return -ENOMEM; diff --git a/drivers/hwmon/qnap-mcu-hwmon.c b/drivers/hwmon/qnap-mcu-hwmon.c index c1c1e9d6f340fa..a027b67af26702 100644 --- a/drivers/hwmon/qnap-mcu-hwmon.c +++ b/drivers/hwmon/qnap-mcu-hwmon.c @@ -299,7 +299,7 @@ static int qnap_mcu_hwmon_probe(struct platform_device *pdev) struct device *hwmon; int ret; - hwm = devm_kzalloc(dev, sizeof(*hwm), GFP_KERNEL); + hwm = devm_kzalloc_obj(dev, *hwm); if (!hwm) return -ENOMEM; diff --git a/drivers/hwmon/raspberrypi-hwmon.c b/drivers/hwmon/raspberrypi-hwmon.c index 7b1d2829f012f7..c60d8f2467e0dd 100644 --- a/drivers/hwmon/raspberrypi-hwmon.c +++ b/drivers/hwmon/raspberrypi-hwmon.c @@ -210,7 +210,7 @@ static int rpi_hwmon_probe(struct platform_device *pdev) long voltage; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c index 04e701ce2e7464..bcafa4ac543ced 100644 --- a/drivers/hwmon/sch5627.c +++ b/drivers/hwmon/sch5627.c @@ -522,8 +522,7 @@ static int sch5627_probe(struct platform_device *pdev) struct device *hwmon_dev; int build_code, build_id, hwmon_rev, val; - data = devm_kzalloc(&pdev->dev, sizeof(struct sch5627_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct sch5627_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c index 8c9b6e24d09f7c..89e6c69d576a14 100644 --- a/drivers/hwmon/sch5636.c +++ b/drivers/hwmon/sch5636.c @@ -392,8 +392,7 @@ static int sch5636_probe(struct platform_device *pdev) int i, err, val, revision[2]; char id[4]; - data = devm_kzalloc(&pdev->dev, sizeof(struct sch5636_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct sch5636_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c index febb8ba7dc2c9b..3ca9e6c6149ae9 100644 --- a/drivers/hwmon/sch56xx-common.c +++ b/drivers/hwmon/sch56xx-common.c @@ -509,7 +509,7 @@ void sch56xx_watchdog_register(struct device *parent, u16 addr, u32 revision, return; } - data = devm_kzalloc(parent, sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); + data = devm_kzalloc_obj(parent, struct sch56xx_watchdog_data); if (!data) return; diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c index 9ae8f774297e5e..91a63e92c3ed4b 100644 --- a/drivers/hwmon/scmi-hwmon.c +++ b/drivers/hwmon/scmi-hwmon.c @@ -196,7 +196,7 @@ static int scmi_thermal_sensor_register(struct device *dev, struct scmi_thermal_sensor *th_sensor; struct thermal_zone_device *tzd; - th_sensor = devm_kzalloc(dev, sizeof(*th_sensor), GFP_KERNEL); + th_sensor = devm_kzalloc_obj(dev, *th_sensor); if (!th_sensor) return -ENOMEM; @@ -228,8 +228,8 @@ static int scmi_thermal_sensor_register(struct device *dev, static int scmi_hwmon_probe(struct scmi_device *sdev) { - int i, idx; u16 nr_sensors; + int i, idx, ret; enum hwmon_sensor_types type; struct scmi_sensors *scmi_sensors; const struct scmi_sensor_info *sensor; @@ -254,7 +254,7 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) if (!nr_sensors) return -EIO; - scmi_sensors = devm_kzalloc(dev, sizeof(*scmi_sensors), GFP_KERNEL); + scmi_sensors = devm_kzalloc_obj(dev, *scmi_sensors); if (!scmi_sensors) return -ENOMEM; @@ -282,13 +282,11 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) if (nr_count[hwmon_temp]) nr_count_temp = nr_count[hwmon_temp]; - scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan), - GFP_KERNEL); + scmi_hwmon_chan = devm_kzalloc_objs(dev, *scmi_hwmon_chan, nr_types); if (!scmi_hwmon_chan) return -ENOMEM; - ptr_scmi_ci = devm_kcalloc(dev, nr_types + 1, sizeof(*ptr_scmi_ci), - GFP_KERNEL); + ptr_scmi_ci = devm_kzalloc_objs(dev, *ptr_scmi_ci, nr_types + 1); if (!ptr_scmi_ci) return -ENOMEM; @@ -299,14 +297,17 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) if (!nr_count[type]) continue; - scmi_hwmon_add_chan_info(scmi_hwmon_chan, dev, nr_count[type], - type, hwmon_attributes[type]); + ret = scmi_hwmon_add_chan_info(scmi_hwmon_chan, dev, + nr_count[type], type, + hwmon_attributes[type]); + if (ret) + return ret; + *ptr_scmi_ci++ = scmi_hwmon_chan++; scmi_sensors->info[type] = - devm_kcalloc(dev, nr_count[type], - sizeof(*scmi_sensors->info[type]), - GFP_KERNEL); + devm_kzalloc_objs(dev, *scmi_sensors->info[type], + nr_count[type]); if (!scmi_sensors->info[type]) return -ENOMEM; } @@ -324,6 +325,12 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) case ENERGY: type = scmi_types[sensor->type]; idx = --nr_count[type]; + ret = sensor_ops->config_set(ph, sensor->id, sensor_config); + if (ret) { + dev_err(dev, "Error enabling sensor %s. err=%d\n", + sensor->name, ret); + continue; + } *(scmi_sensors->info[type] + idx) = sensor; break; } @@ -336,19 +343,10 @@ static int scmi_hwmon_probe(struct scmi_device *sdev) return PTR_ERR(hwdev); for (i = 0; i < nr_count_temp; i++) { - int ret; - sensor = *(scmi_sensors->info[hwmon_temp] + i); if (!sensor) continue; - ret = sensor_ops->config_set(ph, i, sensor_config); - if (ret) { - dev_err(dev, "Error enabling sensor %s. err=%d\n", - sensor->name, ret); - continue; - } - /* * Warn on any misconfiguration related to thermal zones but * bail out of probing only on memory errors. diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c index a0d2206095656d..2358580a6c3c77 100644 --- a/drivers/hwmon/scpi-hwmon.c +++ b/drivers/hwmon/scpi-hwmon.c @@ -154,17 +154,17 @@ static int scpi_hwmon_probe(struct platform_device *pdev) if (!nr_sensors) return -ENODEV; - scpi_sensors = devm_kzalloc(dev, sizeof(*scpi_sensors), GFP_KERNEL); + scpi_sensors = devm_kzalloc_obj(dev, *scpi_sensors); if (!scpi_sensors) return -ENOMEM; - scpi_sensors->data = devm_kcalloc(dev, nr_sensors, - sizeof(*scpi_sensors->data), GFP_KERNEL); + scpi_sensors->data = devm_kzalloc_objs(dev, *scpi_sensors->data, + nr_sensors); if (!scpi_sensors->data) return -ENOMEM; - scpi_sensors->attrs = devm_kcalloc(dev, (nr_sensors * 2) + 1, - sizeof(*scpi_sensors->attrs), GFP_KERNEL); + scpi_sensors->attrs = devm_kzalloc_objs(dev, *scpi_sensors->attrs, + (nr_sensors * 2) + 1); if (!scpi_sensors->attrs) return -ENOMEM; @@ -269,7 +269,7 @@ static int scpi_hwmon_probe(struct platform_device *pdev) if (sensor->info.class != TEMPERATURE) continue; - zone = devm_kzalloc(dev, sizeof(*zone), GFP_KERNEL); + zone = devm_kzalloc_obj(dev, *zone); if (!zone) return -ENOMEM; diff --git a/drivers/hwmon/sfctemp.c b/drivers/hwmon/sfctemp.c index b78b2c099a12a2..2f2bf0b922f198 100644 --- a/drivers/hwmon/sfctemp.c +++ b/drivers/hwmon/sfctemp.c @@ -239,7 +239,7 @@ static int sfctemp_probe(struct platform_device *pdev) struct sfctemp *sfctemp; int ret; - sfctemp = devm_kzalloc(dev, sizeof(*sfctemp), GFP_KERNEL); + sfctemp = devm_kzalloc_obj(dev, *sfctemp); if (!sfctemp) return -ENOMEM; diff --git a/drivers/hwmon/sg2042-mcu.c b/drivers/hwmon/sg2042-mcu.c index 591f5f572fe4ce..61408e14fb1476 100644 --- a/drivers/hwmon/sg2042-mcu.c +++ b/drivers/hwmon/sg2042-mcu.c @@ -311,7 +311,7 @@ static int sg2042_mcu_i2c_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BLOCK_DATA)) return -ENODEV; - mcu = devm_kmalloc(dev, sizeof(*mcu), GFP_KERNEL); + mcu = devm_kmalloc_obj(dev, *mcu); if (!mcu) return -ENOMEM; diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c index 7bb2105d1ae223..1c07fc41f30b39 100644 --- a/drivers/hwmon/sht15.c +++ b/drivers/hwmon/sht15.c @@ -31,6 +31,7 @@ #include #include #include +#include /* Commands */ #define SHT15_MEASURE_TEMP 0x03 @@ -918,7 +919,7 @@ static int sht15_probe(struct platform_device *pdev) int ret; struct sht15_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; @@ -976,25 +977,22 @@ static int sht15_probe(struct platform_device *pdev) goto err_release_reg; } - ret = devm_request_irq(&pdev->dev, gpiod_to_irq(data->data), - sht15_interrupt_fired, - IRQF_TRIGGER_FALLING, - "sht15 data", - data); + ret = request_irq(gpiod_to_irq(data->data), sht15_interrupt_fired, + IRQF_TRIGGER_FALLING, "sht15 data", data); if (ret) goto err_release_reg; disable_irq_nosync(gpiod_to_irq(data->data)); ret = sht15_connection_reset(data); if (ret) - goto err_release_reg; + goto err_free_irq; ret = sht15_soft_reset(data); if (ret) - goto err_release_reg; + goto err_free_irq; ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); if (ret) { dev_err(&pdev->dev, "sysfs create failed\n"); - goto err_release_reg; + goto err_free_irq; } data->hwmon_dev = hwmon_device_register(data->dev); @@ -1007,9 +1005,13 @@ static int sht15_probe(struct platform_device *pdev) err_release_sysfs_group: sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); +err_free_irq: + disable_work_sync(&data->read_work); + free_irq(gpiod_to_irq(data->data), data); err_release_reg: if (!IS_ERR(data->reg)) { regulator_unregister_notifier(data->reg, &data->nb); + cancel_work_sync(&data->update_supply_work); regulator_disable(data->reg); } return ret; @@ -1023,12 +1025,16 @@ static void sht15_remove(struct platform_device *pdev) hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); + disable_work_sync(&data->read_work); + free_irq(gpiod_to_irq(data->data), data); + ret = sht15_soft_reset(data); if (ret) dev_err(&pdev->dev, "Failed to reset device (%pe)\n", ERR_PTR(ret)); if (!IS_ERR(data->reg)) { regulator_unregister_notifier(data->reg, &data->nb); + cancel_work_sync(&data->update_supply_work); regulator_disable(data->reg); } } diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c index 085492669eeb99..fef3faba2a5346 100644 --- a/drivers/hwmon/sht21.c +++ b/drivers/hwmon/sht21.c @@ -260,7 +260,7 @@ static int sht21_probe(struct i2c_client *client) return -ENODEV; } - sht21 = devm_kzalloc(dev, sizeof(*sht21), GFP_KERNEL); + sht21 = devm_kzalloc_obj(dev, *sht21); if (!sht21) return -ENOMEM; diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index a0f5ba5c888dd7..c217a4d0c9f18d 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -896,7 +896,7 @@ static int sht3x_probe(struct i2c_client *client) if (ret != SHT3X_CMD_LENGTH) return ret < 0 ? ret : -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sht4x.c b/drivers/hwmon/sht4x.c index 8372b4fc902e38..335278b1e718a5 100644 --- a/drivers/hwmon/sht4x.c +++ b/drivers/hwmon/sht4x.c @@ -111,7 +111,9 @@ static int sht4x_read_values(struct sht4x_data *data) } if (data->data_pending && - time_before64(get_jiffies_64(), data->heating_complete + data->update_interval)) { + time_before64(get_jiffies_64(), + data->heating_complete + + msecs_to_jiffies(data->update_interval))) { data->data_pending = false; } else { next_update = data->last_updated + @@ -428,7 +430,7 @@ static int sht4x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EOPNOTSUPP; - data = devm_kzalloc(device, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(device, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/shtc1.c b/drivers/hwmon/shtc1.c index 362a73cf661b20..7f31aa981545ee 100644 --- a/drivers/hwmon/shtc1.c +++ b/drivers/hwmon/shtc1.c @@ -225,7 +225,7 @@ static int shtc1_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index b7a7bcd6d3af0a..be2bad5b044599 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c @@ -643,8 +643,7 @@ static int sis5595_probe(struct platform_device *pdev) DRIVER_NAME)) return -EBUSY; - data = devm_kzalloc(&pdev->dev, sizeof(struct sis5595_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct sis5595_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/sl28cpld-hwmon.c b/drivers/hwmon/sl28cpld-hwmon.c index 9c83b4f2a34be7..60e5884bf28993 100644 --- a/drivers/hwmon/sl28cpld-hwmon.c +++ b/drivers/hwmon/sl28cpld-hwmon.c @@ -83,7 +83,7 @@ static int sl28cpld_hwmon_probe(struct platform_device *pdev) if (!pdev->dev.parent) return -ENODEV; - hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(&pdev->dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/smpro-hwmon.c b/drivers/hwmon/smpro-hwmon.c index 37d859f6c8f383..32680e69096cc5 100644 --- a/drivers/hwmon/smpro-hwmon.c +++ b/drivers/hwmon/smpro-hwmon.c @@ -436,7 +436,7 @@ static int smpro_hwmon_probe(struct platform_device *pdev) struct smpro_hwmon *hwmon; struct device *hwmon_dev; - hwmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(&pdev->dev, struct smpro_hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c index c26d6eae0e4e4a..7e286dde5915a3 100644 --- a/drivers/hwmon/smsc47b397.c +++ b/drivers/hwmon/smsc47b397.c @@ -232,7 +232,7 @@ static int smsc47b397_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(dev, sizeof(struct smsc47b397_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct smsc47b397_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 595bceb78d7603..8fbc99fb6accc1 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -724,7 +724,7 @@ static int __init smsc47m1_probe(struct platform_device *pdev) if (err < 0) return err; - data = devm_kzalloc(dev, sizeof(struct smsc47m1_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct smsc47m1_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 1429b66e09b07d..21362c810ce4e3 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c @@ -594,7 +594,7 @@ static int smsc47m192_probe(struct i2c_client *client) struct smsc47m192_data *data; int config; - data = devm_kzalloc(dev, sizeof(struct smsc47m192_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct smsc47m192_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/socfpga-hwmon.c b/drivers/hwmon/socfpga-hwmon.c index 5fe5ccab1e4f73..7e327b52327043 100644 --- a/drivers/hwmon/socfpga-hwmon.c +++ b/drivers/hwmon/socfpga-hwmon.c @@ -525,7 +525,7 @@ static int socfpga_hwmon_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/sparx5-temp.c b/drivers/hwmon/sparx5-temp.c index aa917807374466..069e160c7a610a 100644 --- a/drivers/hwmon/sparx5-temp.c +++ b/drivers/hwmon/sparx5-temp.c @@ -106,7 +106,7 @@ static int s5_temp_probe(struct platform_device *pdev) struct device *hwmon_dev; struct s5_hwmon *hwmon; - hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); + hwmon = devm_kzalloc_obj(&pdev->dev, *hwmon); if (!hwmon) return -ENOMEM; diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index 52f35448934116..b54f9240a6ed80 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -531,7 +531,7 @@ static int spd5118_common_probe(struct device *dev, struct regmap *regmap) struct device *hwmon_dev; int err; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c index ce23681f79810a..0a500264658a8f 100644 --- a/drivers/hwmon/stts751.c +++ b/drivers/hwmon/stts751.c @@ -768,7 +768,7 @@ static int stts751_probe(struct i2c_client *client) bool smbus_nto; int rev_id; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c index cd21f331f1576f..8510bfa60b0d05 100644 --- a/drivers/hwmon/surface_temp.c +++ b/drivers/hwmon/surface_temp.c @@ -191,7 +191,7 @@ static int ssam_temp_probe(struct ssam_device *sdev) if (status) return status; - ssam_temp = devm_kzalloc(&sdev->dev, sizeof(*ssam_temp), GFP_KERNEL); + ssam_temp = devm_kzalloc_obj(&sdev->dev, *ssam_temp); if (!ssam_temp) return -ENOMEM; diff --git a/drivers/hwmon/sy7636a-hwmon.c b/drivers/hwmon/sy7636a-hwmon.c index d51daaf63d632e..f01f368d68e5fb 100644 --- a/drivers/hwmon/sy7636a-hwmon.c +++ b/drivers/hwmon/sy7636a-hwmon.c @@ -29,7 +29,7 @@ static int sy7636a_read(struct device *dev, enum hwmon_sensor_types type, if (ret) return ret; - *temp = reg_val * 1000; + *temp = (s8)reg_val * 1000; return 0; } diff --git a/drivers/hwmon/tc654.c b/drivers/hwmon/tc654.c index 4af9f0e2c0bc4b..957166f17d399e 100644 --- a/drivers/hwmon/tc654.c +++ b/drivers/hwmon/tc654.c @@ -519,7 +519,7 @@ static int tc654_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(struct tc654_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tc654_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tc74.c b/drivers/hwmon/tc74.c index e9113519be5355..5a59fe835d8783 100644 --- a/drivers/hwmon/tc74.c +++ b/drivers/hwmon/tc74.c @@ -113,7 +113,7 @@ static int tc74_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EOPNOTSUPP; - data = devm_kzalloc(dev, sizeof(struct tc74_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tc74_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index b385ef64af7542..62a71d3b2f2f76 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c @@ -384,7 +384,7 @@ static int thmc50_probe(struct i2c_client *client) struct device *hwmon_dev; int idx = 0; - data = devm_kzalloc(dev, sizeof(struct thmc50_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct thmc50_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c index 8c8463ddb6c453..c80ce74eb65bdb 100644 --- a/drivers/hwmon/tmp102.c +++ b/drivers/hwmon/tmp102.c @@ -309,7 +309,7 @@ static int tmp102_probe(struct i2c_client *client) if (err < 0 && err != -ENODEV) return dev_err_probe(dev, err, "Failed to enable regulator\n"); - tmp102 = devm_kzalloc(dev, sizeof(*tmp102), GFP_KERNEL); + tmp102 = devm_kzalloc_obj(dev, *tmp102); if (!tmp102) return -ENOMEM; diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c index 91d20a1ce11204..465438b2223623 100644 --- a/drivers/hwmon/tmp108.c +++ b/drivers/hwmon/tmp108.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ struct tmp108 { struct regmap *regmap; u16 orig_config; - u64 ready_time; + ktime_t ready_time; const struct tmp108_params *params; }; @@ -121,6 +121,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, struct tmp108 *tmp108 = dev_get_drvdata(dev); unsigned int regval; int err, hyst; + s64 delay; if (type == hwmon_chip) { if (attr == hwmon_chip_update_interval) { @@ -137,12 +138,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, switch (attr) { case hwmon_temp_input: - /* Is it too early to return a conversion ? */ - if (time_before64(get_jiffies_64(), tmp108->ready_time)) { - dev_dbg(dev, "%s: Conversion not ready yet..\n", - __func__); - return -EAGAIN; - } + /* Wait if it is too early to return a conversion */ + delay = ktime_us_delta(tmp108->ready_time, ktime_get()); + if (delay > 0) + usleep_range(delay, delay + 1000); err = regmap_read(tmp108->regmap, TMP108_REG_TEMP, ®val); if (err < 0) return err; @@ -450,7 +449,7 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char * if (err) return dev_err_probe(dev, err, "Failed to enable regulator\n"); - tmp108 = devm_kzalloc(dev, sizeof(*tmp108), GFP_KERNEL); + tmp108 = devm_kzalloc_obj(dev, *tmp108); if (!tmp108) return -ENOMEM; @@ -477,11 +476,8 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char * return err; } - tmp108->ready_time = get_jiffies_64(); - if ((tmp108->orig_config & TMP108_CONF_MODE_MASK) == - TMP108_MODE_SHUTDOWN) - tmp108->ready_time += - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); err = devm_add_action_or_reset(dev, tmp108_restore_config, tmp108); if (err) { @@ -528,8 +524,8 @@ static int tmp108_resume(struct device *dev) err = regmap_update_bits(tmp108->regmap, TMP108_REG_CONF, TMP108_CONF_MODE_MASK, TMP108_MODE_CONTINUOUS); - tmp108->ready_time = get_jiffies_64() + - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); return err; } diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index 83aafe4bd3e723..2fceeacdc88c67 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -673,7 +673,7 @@ static int tmp401_probe(struct i2c_client *client) struct tmp401_data *data; int status; - data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tmp401_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index ed00ccfdd7b3ee..c2887262b2168e 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c @@ -429,7 +429,7 @@ static int tmp421_probe(struct i2c_client *client) struct tmp421_data *data; int i, err; - data = devm_kzalloc(dev, sizeof(struct tmp421_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tmp421_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tmp464.c b/drivers/hwmon/tmp464.c index c3e031044d1e71..7d77713e07bf05 100644 --- a/drivers/hwmon/tmp464.c +++ b/drivers/hwmon/tmp464.c @@ -645,7 +645,7 @@ static int tmp464_probe(struct i2c_client *client) dev_err(&client->dev, "i2c functionality check failed\n"); return -ENODEV; } - data = devm_kzalloc(dev, sizeof(struct tmp464_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct tmp464_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c index b160aa045f89dd..a3a4772a37e938 100644 --- a/drivers/hwmon/tmp513.c +++ b/drivers/hwmon/tmp513.c @@ -716,7 +716,7 @@ static int tmp51x_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tps23861.c b/drivers/hwmon/tps23861.c index 4cb3960d51704f..6b31c9284fb81b 100644 --- a/drivers/hwmon/tps23861.c +++ b/drivers/hwmon/tps23861.c @@ -509,7 +509,7 @@ static int tps23861_probe(struct i2c_client *client) struct device *hwmon_dev; u32 shunt_resistor; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tsc1641.c b/drivers/hwmon/tsc1641.c index fc53cd5bb6e099..7dd298cc740437 100644 --- a/drivers/hwmon/tsc1641.c +++ b/drivers/hwmon/tsc1641.c @@ -696,7 +696,7 @@ static int tsc1641_probe(struct i2c_client *client) struct device *hwmon_dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/tvs-mpfs.c b/drivers/hwmon/tvs-mpfs.c index aad00676518b79..bd150cef24e1af 100644 --- a/drivers/hwmon/tvs-mpfs.c +++ b/drivers/hwmon/tvs-mpfs.c @@ -351,7 +351,7 @@ static int mpfs_tvs_probe(struct platform_device *pdev) struct device *hwmon_dev; struct mpfs_tvs *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c index e4f1bb538628c7..1b6dbfb2ccc7a4 100644 --- a/drivers/hwmon/ultra45_env.c +++ b/drivers/hwmon/ultra45_env.c @@ -254,7 +254,7 @@ static const struct attribute_group env_group = { static int env_probe(struct platform_device *op) { - struct env *p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL); + struct env *p = devm_kzalloc_obj(&op->dev, *p); int err = -ENOMEM; if (!p) diff --git a/drivers/hwmon/vexpress-hwmon.c b/drivers/hwmon/vexpress-hwmon.c index a2e350f52a9e9b..d38ac040eeee4a 100644 --- a/drivers/hwmon/vexpress-hwmon.c +++ b/drivers/hwmon/vexpress-hwmon.c @@ -209,7 +209,7 @@ static int vexpress_hwmon_probe(struct platform_device *pdev) struct vexpress_hwmon_data *data; const struct vexpress_hwmon_type *type; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; platform_set_drvdata(pdev, data); diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c index ec421201049da8..ec48587f63fe32 100644 --- a/drivers/hwmon/via-cputemp.c +++ b/drivers/hwmon/via-cputemp.c @@ -114,8 +114,7 @@ static int via_cputemp_probe(struct platform_device *pdev) int err; u64 val; - data = devm_kzalloc(&pdev->dev, sizeof(struct via_cputemp_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct via_cputemp_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index bbaeb808cc15e2..790b3c5a205f71 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c @@ -755,8 +755,7 @@ static int via686a_probe(struct platform_device *pdev) return -ENODEV; } - data = devm_kzalloc(&pdev->dev, sizeof(struct via686a_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct via686a_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c index 1e52cabd6e2443..5bc9e6e68df35a 100644 --- a/drivers/hwmon/vt1211.c +++ b/drivers/hwmon/vt1211.c @@ -1158,7 +1158,7 @@ static int vt1211_probe(struct platform_device *pdev) struct resource *res; int i, err; - data = devm_kzalloc(dev, sizeof(struct vt1211_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct vt1211_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c index 5757a0979f3f3a..1fe361bc30e28f 100644 --- a/drivers/hwmon/vt8231.c +++ b/drivers/hwmon/vt8231.c @@ -843,7 +843,7 @@ static int vt8231_probe(struct platform_device *pdev) return -ENODEV; } - data = devm_kzalloc(&pdev->dev, sizeof(struct vt8231_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct vt8231_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index a23edd35c19ffc..9c08ab662dc699 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -1709,7 +1709,7 @@ static int __init w83627ehf_probe(struct platform_device *pdev) if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) return -EBUSY; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index bb993bb09f401c..a26f4cdfb8e2eb 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c @@ -1686,7 +1686,7 @@ static int w83627hf_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(dev, sizeof(struct w83627hf_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83627hf_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index c40f84e5346964..59d2b9d409207a 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c @@ -1198,7 +1198,7 @@ static int w83781d_probe(struct i2c_client *client) struct w83781d_data *data; int err; - data = devm_kzalloc(dev, sizeof(struct w83781d_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83781d_data); if (!data) return -ENOMEM; @@ -1768,8 +1768,7 @@ w83781d_isa_probe(struct platform_device *pdev) "w83781d")) return -EBUSY; - data = devm_kzalloc(&pdev->dev, sizeof(struct w83781d_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct w83781d_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 4b07a25ae59e29..8bb457326c0bce 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -1357,8 +1357,7 @@ static int w83791d_probe(struct i2c_client *client) (val1 >> 5) & 0x07, (val1 >> 1) & 0x0f, val1); #endif - data = devm_kzalloc(&client->dev, sizeof(struct w83791d_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct w83791d_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index f715c79389a565..2de6d7b685836b 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -1358,7 +1358,7 @@ w83792d_probe(struct i2c_client *client) struct device *dev = &client->dev; int i, val1, err; - data = devm_kzalloc(dev, sizeof(struct w83792d_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83792d_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index c5ce0bf1b08ecf..96fbb0a5006f8a 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c @@ -2142,7 +2142,7 @@ static int w83795_probe(struct i2c_client *client) struct w83795_data *data; int err; - data = devm_kzalloc(dev, sizeof(struct w83795_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83795_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index e42506a3bcbeca..0a078e23aed407 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c @@ -168,7 +168,7 @@ static int w83l785ts_probe(struct i2c_client *client) struct device *dev = &client->dev; int err; - data = devm_kzalloc(dev, sizeof(struct w83l785ts_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83l785ts_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index a72397083cc4fe..d16afda34e418d 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c @@ -723,7 +723,7 @@ w83l786ng_probe(struct i2c_client *client) int i; u8 reg_tmp; - data = devm_kzalloc(dev, sizeof(struct w83l786ng_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct w83l786ng_data); if (!data) return -ENOMEM; diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c index eebbb741deac63..0823882189aa54 100644 --- a/drivers/hwmon/xgene-hwmon.c +++ b/drivers/hwmon/xgene-hwmon.c @@ -608,7 +608,7 @@ static int xgene_hwmon_probe(struct platform_device *pdev) struct mbox_client *cl; int rc; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/hwmon/yogafan.c b/drivers/hwmon/yogafan.c index aa328456071563..6d1284c090487d 100644 --- a/drivers/hwmon/yogafan.c +++ b/drivers/hwmon/yogafan.c @@ -326,7 +326,7 @@ static int yoga_fan_probe(struct platform_device *pdev) return -ENODEV; cfg = dmi_id->driver_data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 1832e0c3af6baa..7c5e04f1fee7a6 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -111,8 +111,7 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) num_locks = i * 32; /* actual number of locks in this device */ - bank = devm_kzalloc(&pdev->dev, struct_size(bank, lock, num_locks), - GFP_KERNEL); + bank = devm_kzalloc_flex(&pdev->dev, *bank, lock, num_locks); if (!bank) return -ENOMEM; diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index 22e2ffb9174362..24655544eae9c9 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -92,9 +92,8 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - sprd_hwlock = devm_kzalloc(&pdev->dev, - struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM), - GFP_KERNEL); + sprd_hwlock = devm_kzalloc_flex(&pdev->dev, *sprd_hwlock, bank.lock, + SPRD_HWLOCKS_NUM); if (!sprd_hwlock) return -ENOMEM; diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index bb5c7e5f7a80be..70fbe111c2dc25 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -79,7 +79,7 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) if (IS_ERR(io_base)) return PTR_ERR(io_base); - hw = devm_kzalloc(dev, struct_size(hw, bank.lock, STM32_MUTEX_NUM_LOCKS), GFP_KERNEL); + hw = devm_kzalloc_flex(dev, *hw, bank.lock, STM32_MUTEX_NUM_LOCKS); if (!hw) return -ENOMEM; diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index c2d314588046eb..29431a71e74e7e 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -100,7 +100,7 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) if (IS_ERR(io_base)) return PTR_ERR(io_base); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -154,8 +154,8 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) goto bank_fail; } - priv->bank = devm_kzalloc(&pdev->dev, struct_size(priv->bank, lock, priv->nlocks), - GFP_KERNEL); + priv->bank = devm_kzalloc_flex(&pdev->dev, *priv->bank, lock, + priv->nlocks); if (!priv->bank) { err = -ENOMEM; goto bank_fail; diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c index ad8dafea7d2fd5..d1f9c89dfeee9e 100644 --- a/drivers/hwtracing/coresight/coresight-catu.c +++ b/drivers/hwtracing/coresight/coresight-catu.c @@ -518,7 +518,7 @@ static int __catu_probe(struct device *dev, struct resource *res) struct coresight_platform_data *pdata = NULL; void __iomem *base; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c index 3a806c1d50eafb..a5e688da638b38 100644 --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c @@ -562,7 +562,7 @@ static int __debug_probe(struct device *dev, struct resource *res) void __iomem *base; int ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hwtracing/coresight/coresight-ctcu-core.c index 9043cad42f01e6..a2709bdeab2b0d 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c @@ -189,7 +189,7 @@ static int ctcu_probe(struct platform_device *pdev) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c b/drivers/hwtracing/coresight/coresight-cti-core.c index b2c9a4db13b4e5..17786ffa92cec8 100644 --- a/drivers/hwtracing/coresight/coresight-cti-core.c +++ b/drivers/hwtracing/coresight/coresight-cti-core.c @@ -232,7 +232,7 @@ struct cti_trig_con *cti_allocate_trig_con(struct device *dev, int in_sigs, struct cti_trig_con *tc = NULL; struct cti_trig_grp *in = NULL, *out = NULL; - tc = devm_kzalloc(dev, sizeof(struct cti_trig_con), GFP_KERNEL); + tc = devm_kzalloc_obj(dev, struct cti_trig_con); if (!tc) return tc; @@ -664,7 +664,7 @@ static int cti_probe(struct amba_device *adev, const struct amba_id *id) struct resource *res = &adev->res; /* driver data*/ - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c index d6d5388705c3e1..8ab2ed499a8f04 100644 --- a/drivers/hwtracing/coresight/coresight-cti-platform.c +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c @@ -247,7 +247,7 @@ static int cti_plat_read_trig_group(struct cti_trig_grp *tgrp, if (!tgrp->nr_sigs) return 0; - values = kcalloc(tgrp->nr_sigs, sizeof(u32), GFP_KERNEL); + values = kzalloc_objs(u32, tgrp->nr_sigs); if (!values) return -ENOMEM; @@ -283,7 +283,7 @@ static int cti_plat_read_trig_types(struct cti_trig_grp *tgrp, /* need an array to store the values iff there are any */ if (items) { - values = kcalloc(items, sizeof(u32), GFP_KERNEL); + values = kzalloc_objs(u32, items); if (!values) return -ENOMEM; @@ -471,7 +471,7 @@ coresight_cti_get_platform_data(struct device *dev) * empty struct enables us to use the standard coresight component * registration code. */ - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) { ret = -ENOMEM; goto error; diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c b/drivers/hwtracing/coresight/coresight-cti-sysfs.c index 2ed5d8eb1ddab9..44e5f26bb9ac1c 100644 --- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c @@ -1018,8 +1018,7 @@ static int cti_create_con_sysfs_attr(struct device *dev, struct dev_ext_attribute *eattr; char *name; - eattr = devm_kzalloc(dev, sizeof(struct dev_ext_attribute), - GFP_KERNEL); + eattr = devm_kzalloc_obj(dev, struct dev_ext_attribute); if (eattr) { name = devm_kstrdup(dev, con_attr_names[attr_type], GFP_KERNEL); @@ -1055,7 +1054,7 @@ cti_create_con_sysfs_group(struct device *dev, struct cti_device *ctidev, struct attribute_group *group = NULL; int grp_idx; - group = devm_kzalloc(dev, sizeof(struct attribute_group), GFP_KERNEL); + group = devm_kzalloc_obj(dev, struct attribute_group); if (!group) return NULL; @@ -1083,8 +1082,8 @@ static int cti_create_con_attr_set(struct device *dev, int con_idx, return -ENOMEM; /* allocate NULL terminated array of attributes */ - tc->con_attrs = devm_kcalloc(dev, CTI_CON_ATTR_MAX + 1, - sizeof(struct attribute *), GFP_KERNEL); + tc->con_attrs = devm_kzalloc_objs(dev, struct attribute *, + CTI_CON_ATTR_MAX + 1); if (!tc->con_attrs) return -ENOMEM; @@ -1131,9 +1130,8 @@ static int cti_create_cons_groups(struct device *dev, struct cti_device *ctidev) /* nr groups = dynamic + static + NULL terminator */ nr_groups = ctidev->nr_trig_con + CORESIGHT_CTI_STATIC_GROUPS_MAX; - ctidev->con_groups = devm_kcalloc(dev, nr_groups, - sizeof(*ctidev->con_groups), - GFP_KERNEL); + ctidev->con_groups = devm_kzalloc_objs(dev, *ctidev->con_groups, + nr_groups); if (!ctidev->con_groups) return -ENOMEM; return 0; diff --git a/drivers/hwtracing/coresight/coresight-dummy.c b/drivers/hwtracing/coresight/coresight-dummy.c index c176a2f57300fd..3ba1477f4e1516 100644 --- a/drivers/hwtracing/coresight/coresight-dummy.c +++ b/drivers/hwtracing/coresight/coresight-dummy.c @@ -117,7 +117,7 @@ static int dummy_probe(struct platform_device *pdev) struct coresight_desc desc = { 0 }; int ret = 0, trace_id = 0; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index a827f76b8144a7..676596bd80953a 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -724,7 +724,7 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 80502e8b084074..492cc3be87496f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -919,7 +919,7 @@ etm_perf_add_symlink_group(struct device *dev, const char *name, const char *gro if (!etm_perf_up) return ERR_PTR(-EPROBE_DEFER); - ea = devm_kzalloc(dev, sizeof(*ea), GFP_KERNEL); + ea = devm_kzalloc_obj(dev, *ea); if (!ea) return ERR_PTR(-ENOMEM); diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c index b670a324bb412d..d371da07896a73 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -809,7 +809,7 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) struct resource *res = &adev->res; struct coresight_desc desc = { 0 }; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index e21be6468e9544..726b0ec9cc2df0 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -2224,9 +2224,8 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg) pm_save = pm_save_enable != PARAM_PM_SAVE_NEVER; if (pm_save) { - drvdata->save_state = devm_kmalloc(dev, - sizeof(struct etmv4_save_state), - GFP_KERNEL); + drvdata->save_state = devm_kmalloc_obj(dev, + struct etmv4_save_state); if (!drvdata->save_state) return -ENOMEM; } @@ -2307,7 +2306,7 @@ static int etm4_probe(struct device *dev) if (smp_call_function_single(drvdata->cpu, etm4_init_arch_data, &init_arg, 1)) { /* The CPU was offline, try again once it comes online. */ - delayed = devm_kmalloc(dev, sizeof(*delayed), GFP_KERNEL); + delayed = devm_kmalloc_obj(dev, *delayed); if (!delayed) { cpus_read_unlock(); return -ENOMEM; @@ -2338,7 +2337,7 @@ static int etm4_probe_amba(struct amba_device *adev, const struct amba_id *id) if (IS_ERR(base)) return PTR_ERR(base); - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; @@ -2357,7 +2356,7 @@ static int etm4_probe_platform_dev(struct platform_device *pdev) struct etmv4_drvdata *drvdata; int ret; - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c index 0abc11f0690c52..2d41c487880d82 100644 --- a/drivers/hwtracing/coresight/coresight-funnel.c +++ b/drivers/hwtracing/coresight/coresight-funnel.c @@ -225,7 +225,7 @@ static int funnel_probe(struct device *dev, struct resource *res) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-kunit-tests.c b/drivers/hwtracing/coresight/coresight-kunit-tests.c index c8f361767c4508..0c37f223398475 100644 --- a/drivers/hwtracing/coresight/coresight-kunit-tests.c +++ b/drivers/hwtracing/coresight/coresight-kunit-tests.c @@ -8,12 +8,10 @@ static struct coresight_device *coresight_test_device(struct device *dev) { - struct coresight_device *csdev = devm_kcalloc(dev, 1, - sizeof(struct coresight_device), - GFP_KERNEL); - csdev->pdata = devm_kcalloc(dev, 1, - sizeof(struct coresight_platform_data), - GFP_KERNEL); + struct coresight_device *csdev = devm_kzalloc_objs(dev, + struct coresight_device, + 1); + csdev->pdata = devm_kzalloc_objs(dev, struct coresight_platform_data, 1); return csdev; } diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c index 93c2d075cad66f..6657a817719a3b 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -51,8 +51,7 @@ coresight_add_out_conn(struct device *dev, if (!pdata->out_conns) return ERR_PTR(-ENOMEM); - conn = devm_kmalloc(dev, sizeof(struct coresight_connection), - GFP_KERNEL); + conn = devm_kmalloc_obj(dev, struct coresight_connection); if (!conn) return ERR_PTR(-ENOMEM); @@ -835,7 +834,7 @@ coresight_get_platform_data(struct device *dev) if (IS_ERR_OR_NULL(fwnode)) goto error; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) { ret = -ENOMEM; goto error; diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c index 2f382de357ee47..1118a79044759e 100644 --- a/drivers/hwtracing/coresight/coresight-replicator.c +++ b/drivers/hwtracing/coresight/coresight-replicator.c @@ -232,7 +232,7 @@ static int replicator_probe(struct device *dev, struct resource *res) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c index 4e860519a73f6f..babaa424b045ea 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -836,7 +836,7 @@ static int __stm_probe(struct device *dev, struct resource *res) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c index 2b40e556be872f..71ac86587d1207 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c @@ -14,7 +14,7 @@ static struct config_item_type *cscfg_create_ci_type(void) { struct config_item_type *ci_type; - ci_type = devm_kzalloc(cscfg_device(), sizeof(*ci_type), GFP_KERNEL); + ci_type = devm_kzalloc_obj(cscfg_device(), *ci_type); if (ci_type) ci_type->ct_owner = THIS_MODULE; @@ -186,8 +186,8 @@ static int cscfg_add_preset_groups(struct cscfg_fs_config *cfg_view) return 0; for (preset_num = 1; preset_num <= config_desc->nr_presets; preset_num++) { - cfg_fs_preset = devm_kzalloc(cscfg_device(), - sizeof(struct cscfg_fs_preset), GFP_KERNEL); + cfg_fs_preset = devm_kzalloc_obj(cscfg_device(), + struct cscfg_fs_preset); if (!cfg_fs_preset) return -ENOMEM; @@ -211,7 +211,7 @@ static struct config_group *cscfg_create_config_group(struct cscfg_config_desc * if (!dev) return ERR_PTR(-EINVAL); - cfg_view = devm_kzalloc(dev, sizeof(struct cscfg_fs_config), GFP_KERNEL); + cfg_view = devm_kzalloc_obj(dev, struct cscfg_fs_config); if (!cfg_view) return ERR_PTR(-ENOMEM); @@ -328,7 +328,7 @@ static int cscfg_create_params_group_items(struct cscfg_feature_desc *feat_desc, /* parameter items - as groups with default_value attribute */ for (i = 0; i < feat_desc->nr_params; i++) { - param_item = devm_kzalloc(dev, sizeof(struct cscfg_fs_param), GFP_KERNEL); + param_item = devm_kzalloc_obj(dev, struct cscfg_fs_param); if (!param_item) return -ENOMEM; param_item->feat_desc = feat_desc; @@ -352,12 +352,12 @@ static struct config_group *cscfg_create_feature_group(struct cscfg_feature_desc if (!dev) return ERR_PTR(-EINVAL); - feat_view = devm_kzalloc(dev, sizeof(struct cscfg_fs_feature), GFP_KERNEL); + feat_view = devm_kzalloc_obj(dev, struct cscfg_fs_feature); if (!feat_view) return ERR_PTR(-ENOMEM); if (feat_desc->nr_params) { - params_group = devm_kzalloc(dev, sizeof(struct config_group), GFP_KERNEL); + params_group = devm_kzalloc_obj(dev, struct config_group); if (!params_group) return ERR_PTR(-ENOMEM); diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 2bfdd7b45e49c8..8ddebbbb40c27a 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -126,7 +126,7 @@ cscfg_alloc_csdev_feat(struct coresight_device *csdev, struct cscfg_feature_desc struct device *dev = csdev->dev.parent; int i; - feat_csdev = devm_kzalloc(dev, sizeof(struct cscfg_feature_csdev), GFP_KERNEL); + feat_csdev = devm_kzalloc_obj(dev, struct cscfg_feature_csdev); if (!feat_csdev) return NULL; @@ -139,9 +139,9 @@ cscfg_alloc_csdev_feat(struct coresight_device *csdev, struct cscfg_feature_desc * feature descriptor. */ if (feat_csdev->nr_params) { - feat_csdev->params_csdev = devm_kcalloc(dev, feat_csdev->nr_params, - sizeof(struct cscfg_parameter_csdev), - GFP_KERNEL); + feat_csdev->params_csdev = devm_kzalloc_objs(dev, + struct cscfg_parameter_csdev, + feat_csdev->nr_params); if (!feat_csdev->params_csdev) return NULL; @@ -158,9 +158,9 @@ cscfg_alloc_csdev_feat(struct coresight_device *csdev, struct cscfg_feature_desc * will fill out according to feature descriptor and device requirements. */ feat_csdev->nr_regs = feat_desc->nr_regs; - feat_csdev->regs_csdev = devm_kcalloc(dev, feat_csdev->nr_regs, - sizeof(struct cscfg_regval_csdev), - GFP_KERNEL); + feat_csdev->regs_csdev = devm_kzalloc_objs(dev, + struct cscfg_regval_csdev, + feat_csdev->nr_regs); if (!feat_csdev->regs_csdev) return NULL; diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c index bc5a133ada3e35..2e67e4a6d9639a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -774,7 +774,7 @@ static int __tmc_probe(struct device *dev, struct resource *res) struct coresight_desc desc = { 0 }; const char *dev_list = NULL; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-tnoc.c b/drivers/hwtracing/coresight/coresight-tnoc.c index 929d316b4b3635..d80217208ba4b2 100644 --- a/drivers/hwtracing/coresight/coresight-tnoc.c +++ b/drivers/hwtracing/coresight/coresight-tnoc.c @@ -198,7 +198,7 @@ static int _tnoc_probe(struct device *dev, struct resource *res) return PTR_ERR(pdata); dev->platform_data = pdata; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-tpda.c b/drivers/hwtracing/coresight/coresight-tpda.c index 89c8f71f0aff06..9f1502fdfffe8b 100644 --- a/drivers/hwtracing/coresight/coresight-tpda.c +++ b/drivers/hwtracing/coresight/coresight-tpda.c @@ -565,7 +565,7 @@ static int tpda_probe(struct amba_device *adev, const struct amba_id *id) return PTR_ERR(pdata); adev->dev.platform_data = pdata; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-tpdm.c b/drivers/hwtracing/coresight/coresight-tpdm.c index 8464edbba2d45e..102b8b7edf87f3 100644 --- a/drivers/hwtracing/coresight/coresight-tpdm.c +++ b/drivers/hwtracing/coresight/coresight-tpdm.c @@ -582,15 +582,13 @@ static int tpdm_datasets_setup(struct tpdm_drvdata *drvdata) drvdata->datasets |= pidr & GENMASK(TPDM_DATASETS - 1, 0); if (tpdm_has_dsb_dataset(drvdata) && (!drvdata->dsb)) { - drvdata->dsb = devm_kzalloc(drvdata->dev, - sizeof(*drvdata->dsb), GFP_KERNEL); + drvdata->dsb = devm_kzalloc_obj(drvdata->dev, *drvdata->dsb); if (!drvdata->dsb) return -ENOMEM; } if ((tpdm_has_cmb_dataset(drvdata) || tpdm_has_mcmb_dataset(drvdata)) && (!drvdata->cmb)) { - drvdata->cmb = devm_kzalloc(drvdata->dev, - sizeof(*drvdata->cmb), GFP_KERNEL); + drvdata->cmb = devm_kzalloc_obj(drvdata->dev, *drvdata->cmb); if (!drvdata->cmb) return -ENOMEM; } @@ -605,8 +603,7 @@ static int static_tpdm_datasets_setup(struct tpdm_drvdata *drvdata, struct devic /* setup datasets for static TPDM */ if (fwnode_property_present(dev->fwnode, "qcom,dsb-element-bits") && (!drvdata->dsb)) { - drvdata->dsb = devm_kzalloc(drvdata->dev, - sizeof(*drvdata->dsb), GFP_KERNEL); + drvdata->dsb = devm_kzalloc_obj(drvdata->dev, *drvdata->dsb); if (!drvdata->dsb) return -ENOMEM; @@ -614,8 +611,7 @@ static int static_tpdm_datasets_setup(struct tpdm_drvdata *drvdata, struct devic if (fwnode_property_present(dev->fwnode, "qcom,cmb-element-bits") && (!drvdata->cmb)) { - drvdata->cmb = devm_kzalloc(drvdata->dev, - sizeof(*drvdata->cmb), GFP_KERNEL); + drvdata->cmb = devm_kzalloc_obj(drvdata->dev, *drvdata->cmb); if (!drvdata->cmb) return -ENOMEM; @@ -1414,7 +1410,7 @@ static int tpdm_probe(struct device *dev, struct resource *res) dev->platform_data = pdata; /* driver data*/ - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; drvdata->dev = dev; diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index 7b029d2eb3891f..45113e45c3bdf0 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -136,7 +136,7 @@ static int __tpiu_probe(struct device *dev, struct resource *res) if (!desc.name) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c index eca8e13a97447b..3fa663c7f026c8 100644 --- a/drivers/hwtracing/coresight/coresight-trbe.c +++ b/drivers/hwtracing/coresight/coresight-trbe.c @@ -1337,7 +1337,7 @@ static void arm_trbe_register_coresight_cpu(struct trbe_drvdata *drvdata, int cp * coresight_platform_data structure and assign that back * into the device for that purpose. */ - desc.pdata = devm_kzalloc(dev, sizeof(*desc.pdata), GFP_KERNEL); + desc.pdata = devm_kzalloc_obj(dev, *desc.pdata); if (!desc.pdata) goto cpu_clear; @@ -1587,7 +1587,7 @@ static int arm_trbe_device_probe(struct platform_device *pdev) return -EOPNOTSUPP; } - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index b107d4606fcdce..6a778f96804d9f 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -538,7 +538,7 @@ static int smb_probe(struct platform_device *pdev) struct smb_drv_data *drvdata; int ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/hwtracing/intel_th/gth.c b/drivers/hwtracing/intel_th/gth.c index 3883f99fd5d5d5..dd659a637f0b97 100644 --- a/drivers/hwtracing/intel_th/gth.c +++ b/drivers/hwtracing/intel_th/gth.c @@ -374,9 +374,8 @@ static int intel_th_master_attributes(struct gth_device *gth) if (!attrs) return -ENOMEM; - master_attrs = devm_kcalloc(gth->dev, nattrs, - sizeof(struct master_attribute), - GFP_KERNEL); + master_attrs = devm_kzalloc_objs(gth->dev, struct master_attribute, + nattrs); if (!master_attrs) return -ENOMEM; @@ -418,9 +417,7 @@ static int intel_th_output_attributes(struct gth_device *gth) if (!attrs) return -ENOMEM; - out_attrs = devm_kcalloc(gth->dev, nattrs, - sizeof(struct output_attribute), - GFP_KERNEL); + out_attrs = devm_kzalloc_objs(gth->dev, struct output_attribute, nattrs); if (!out_attrs) return -ENOMEM; @@ -758,7 +755,7 @@ static int intel_th_gth_probe(struct intel_th_device *thdev) if (!base) return -ENOMEM; - gth = devm_kzalloc(dev, sizeof(*gth), GFP_KERNEL); + gth = devm_kzalloc_obj(dev, *gth); if (!gth) return -ENOMEM; diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c index 84d99d7b1d2048..47928dd7d1e985 100644 --- a/drivers/hwtracing/intel_th/msu.c +++ b/drivers/hwtracing/intel_th/msu.c @@ -2139,7 +2139,7 @@ static int intel_th_msc_probe(struct intel_th_device *thdev) if (!base) return -ENOMEM; - msc = devm_kzalloc(dev, sizeof(*msc), GFP_KERNEL); + msc = devm_kzalloc_obj(dev, *msc); if (!msc) return -ENOMEM; diff --git a/drivers/hwtracing/intel_th/pti.c b/drivers/hwtracing/intel_th/pti.c index 09132ab8bc2326..ffd9eed6670815 100644 --- a/drivers/hwtracing/intel_th/pti.c +++ b/drivers/hwtracing/intel_th/pti.c @@ -213,7 +213,7 @@ static int intel_th_pti_probe(struct intel_th_device *thdev) if (!base) return -ENOMEM; - pti = devm_kzalloc(dev, sizeof(*pti), GFP_KERNEL); + pti = devm_kzalloc_obj(dev, *pti); if (!pti) return -ENOMEM; diff --git a/drivers/hwtracing/intel_th/sth.c b/drivers/hwtracing/intel_th/sth.c index 428f595a28a05d..dfc51ff2372fd0 100644 --- a/drivers/hwtracing/intel_th/sth.c +++ b/drivers/hwtracing/intel_th/sth.c @@ -207,7 +207,7 @@ static int intel_th_sth_probe(struct intel_th_device *thdev) if (!channels) return -ENOMEM; - sth = devm_kzalloc(dev, sizeof(*sth), GFP_KERNEL); + sth = devm_kzalloc_obj(dev, *sth); if (!sth) return -ENOMEM; diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 52f168f8b4599d..6ed65b44a4af89 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -704,8 +704,8 @@ static int hisi_ptt_config_trace_buf(struct hisi_ptt *hisi_ptt) struct device *dev = &hisi_ptt->pdev->dev; int i; - ctrl->trace_buf = devm_kcalloc(dev, HISI_PTT_TRACE_BUF_CNT, - sizeof(*ctrl->trace_buf), GFP_KERNEL); + ctrl->trace_buf = devm_kzalloc_objs(dev, *ctrl->trace_buf, + HISI_PTT_TRACE_BUF_CNT); if (!ctrl->trace_buf) return -ENOMEM; @@ -1311,7 +1311,7 @@ static int hisi_ptt_probe(struct pci_dev *pdev, return ret; } - hisi_ptt = devm_kzalloc(&pdev->dev, sizeof(*hisi_ptt), GFP_KERNEL); + hisi_ptt = devm_kzalloc_obj(&pdev->dev, *hisi_ptt); if (!hisi_ptt) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-altera.c b/drivers/i2c/busses/i2c-altera.c index 2da73173ce248f..0174805ff822d4 100644 --- a/drivers/i2c/busses/i2c-altera.c +++ b/drivers/i2c/busses/i2c-altera.c @@ -385,7 +385,7 @@ static int altr_i2c_probe(struct platform_device *pdev) struct altr_i2c_dev *idev = NULL; int irq, ret; - idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc_obj(&pdev->dev, *idev); if (!idev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-amd-asf-plat.c b/drivers/i2c/busses/i2c-amd-asf-plat.c index 2a5711411ee5c2..868361e8d929d6 100644 --- a/drivers/i2c/busses/i2c-amd-asf-plat.c +++ b/drivers/i2c/busses/i2c-amd-asf-plat.c @@ -307,7 +307,7 @@ static int amd_asf_probe(struct platform_device *pdev) struct resource *eoi_addr; int ret, irq; - asf_dev = devm_kzalloc(dev, sizeof(*asf_dev), GFP_KERNEL); + asf_dev = devm_kzalloc_obj(dev, *asf_dev); if (!asf_dev) return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n"); diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c index 5b41d18b62d31c..cc24a4f648fad9 100644 --- a/drivers/i2c/busses/i2c-amd-mp2-pci.c +++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c @@ -345,7 +345,7 @@ static int amd_mp2_pci_probe(struct pci_dev *pci_dev, struct amd_mp2_dev *privdata; int rc; - privdata = devm_kzalloc(&pci_dev->dev, sizeof(*privdata), GFP_KERNEL); + privdata = devm_kzalloc_obj(&pci_dev->dev, *privdata); if (!privdata) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c index cc5961364bcc01..6fa369be398189 100644 --- a/drivers/i2c/busses/i2c-amd-mp2-plat.c +++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c @@ -266,7 +266,7 @@ static int i2c_amd_probe(struct platform_device *pdev) /* The MP2 PCI device should get probed later */ return -EPROBE_DEFER; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index dd9ac4bb6704ad..d99fca834a2658 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c @@ -427,7 +427,7 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) return -ENODEV; - smbus = devm_kzalloc(&dev->dev, sizeof(struct amd_smbus), GFP_KERNEL); + smbus = devm_kzalloc_obj(&dev->dev, struct amd_smbus); if (!smbus) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index a26b74c7120611..0ff95416fcf136 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -1002,7 +1002,7 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev) struct clk *parent_clk; int irq, ret; - bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&pdev->dev, *bus); if (!bus) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-at91-core.c b/drivers/i2c/busses/i2c-at91-core.c index 8ca4556d966491..2a515a2e4ef574 100644 --- a/drivers/i2c/busses/i2c-at91-core.c +++ b/drivers/i2c/busses/i2c-at91-core.c @@ -200,7 +200,7 @@ static int at91_twi_probe(struct platform_device *pdev) int rc; u32 phy_addr; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c index b78b38ddac463b..e468b0c0121d5d 100644 --- a/drivers/i2c/busses/i2c-au1550.c +++ b/drivers/i2c/busses/i2c-au1550.c @@ -303,8 +303,7 @@ i2c_au1550_probe(struct platform_device *pdev) struct i2c_au1550_data *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(struct i2c_au1550_data), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct i2c_au1550_data); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c index 0555eeb6903a1f..d1744c0ae7bbe9 100644 --- a/drivers/i2c/busses/i2c-axxia.c +++ b/drivers/i2c/busses/i2c-axxia.c @@ -724,7 +724,7 @@ static int axxia_i2c_probe(struct platform_device *pdev) void __iomem *base; int ret = 0; - idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc_obj(&pdev->dev, *idev); if (!idev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index 66bb3bfdaa4c03..58327b8c77810c 100644 --- a/drivers/i2c/busses/i2c-bcm-iproc.c +++ b/drivers/i2c/busses/i2c-bcm-iproc.c @@ -1102,8 +1102,7 @@ static int bcm_iproc_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; int irq, ret; - iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), - GFP_KERNEL); + iproc_i2c = devm_kzalloc_obj(&pdev->dev, *iproc_i2c); if (!iproc_i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c index d4f287b31fd769..0d52f3724c9370 100644 --- a/drivers/i2c/busses/i2c-bcm-kona.c +++ b/drivers/i2c/busses/i2c-bcm-kona.c @@ -741,7 +741,7 @@ static int bcm_kona_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; /* Allocate memory for private data structure */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c index b30f7e0e45f160..0fea44d4df6e83 100644 --- a/drivers/i2c/busses/i2c-bcm2835.c +++ b/drivers/i2c/busses/i2c-bcm2835.c @@ -181,7 +181,7 @@ static struct clk *bcm2835_i2c_register_div(struct device *dev, init.num_parents = 1; init.flags = 0; - priv = devm_kzalloc(dev, sizeof(struct clk_bcm2835_i2c), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct clk_bcm2835_i2c); if (priv == NULL) return ERR_PTR(-ENOMEM); @@ -413,7 +413,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev) struct clk *mclk; u32 bus_clk_rate; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; platform_set_drvdata(pdev, i2c_dev); diff --git a/drivers/i2c/busses/i2c-brcmstb.c b/drivers/i2c/busses/i2c-brcmstb.c index 5fa30e8926c53a..52762249d46aaf 100644 --- a/drivers/i2c/busses/i2c-brcmstb.c +++ b/drivers/i2c/busses/i2c-brcmstb.c @@ -617,11 +617,11 @@ static int brcmstb_i2c_probe(struct platform_device *pdev) int rc; /* Allocate memory for private data structure */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; - dev->bsc_regmap = devm_kzalloc(&pdev->dev, sizeof(*dev->bsc_regmap), GFP_KERNEL); + dev->bsc_regmap = devm_kzalloc_obj(&pdev->dev, *dev->bsc_regmap); if (!dev->bsc_regmap) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index da8770182a1862..0c6887da47d196 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -1497,7 +1497,7 @@ static int cdns_i2c_probe(struct platform_device *pdev) int ret, irq; const struct of_device_id *match; - id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); + id = devm_kzalloc_obj(&pdev->dev, *id); if (!id) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cbus-gpio.c b/drivers/i2c/busses/i2c-cbus-gpio.c index 8065c7e4462e8e..3ec1eab1eb0764 100644 --- a/drivers/i2c/busses/i2c-cbus-gpio.c +++ b/drivers/i2c/busses/i2c-cbus-gpio.c @@ -212,12 +212,11 @@ static int cbus_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adapter; struct cbus_host *chost; - adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), - GFP_KERNEL); + adapter = devm_kzalloc_obj(&pdev->dev, struct i2c_adapter); if (!adapter) return -ENOMEM; - chost = devm_kzalloc(&pdev->dev, sizeof(*chost), GFP_KERNEL); + chost = devm_kzalloc_obj(&pdev->dev, *chost); if (!chost) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cgbc.c b/drivers/i2c/busses/i2c-cgbc.c index 25a74fa51aa002..164be9b99eb314 100644 --- a/drivers/i2c/busses/i2c-cgbc.c +++ b/drivers/i2c/busses/i2c-cgbc.c @@ -365,7 +365,7 @@ static int cgbc_i2c_probe(struct platform_device *pdev) struct cgbc_i2c_data *i2c; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cht-wc.c b/drivers/i2c/busses/i2c-cht-wc.c index 606ac071cb8039..0f1701b61efa6d 100644 --- a/drivers/i2c/busses/i2c-cht-wc.c +++ b/drivers/i2c/busses/i2c-cht-wc.c @@ -434,7 +434,7 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) if (irq < 0) return irq; - adap = devm_kzalloc(&pdev->dev, sizeof(*adap), GFP_KERNEL); + adap = devm_kzalloc_obj(&pdev->dev, *adap); if (!adap) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cp2615.c b/drivers/i2c/busses/i2c-cp2615.c index 951de624983421..5032198aee051c 100644 --- a/drivers/i2c/busses/i2c-cp2615.c +++ b/drivers/i2c/busses/i2c-cp2615.c @@ -293,7 +293,7 @@ cp2615_i2c_probe(struct usb_interface *usbif, const struct usb_device_id *id) if (ret) return ret; - adap = devm_kzalloc(&usbif->dev, sizeof(struct i2c_adapter), GFP_KERNEL); + adap = devm_kzalloc_obj(&usbif->dev, struct i2c_adapter); if (!adap) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-cros-ec-tunnel.c b/drivers/i2c/busses/i2c-cros-ec-tunnel.c index a83e735d2086c2..3ba4bde51b1fe0 100644 --- a/drivers/i2c/busses/i2c-cros-ec-tunnel.c +++ b/drivers/i2c/busses/i2c-cros-ec-tunnel.c @@ -255,7 +255,7 @@ static int ec_i2c_probe(struct platform_device *pdev) return -EINVAL; } - bus = devm_kzalloc(dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(dev, *bus); if (bus == NULL) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index e15eef163a8f83..34f5f99dfd62e8 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -746,7 +746,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) if (irq < 0) return irq; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-designware-amdisp.c b/drivers/i2c/busses/i2c-designware-amdisp.c index 9f0ec0fae6f235..04137def8b249c 100644 --- a/drivers/i2c/busses/i2c-designware-amdisp.c +++ b/drivers/i2c/busses/i2c-designware-amdisp.c @@ -32,7 +32,7 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev) struct i2c_adapter *adap; int ret; - isp_i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c_dev), GFP_KERNEL); + isp_i2c_dev = devm_kzalloc_obj(&pdev->dev, *isp_i2c_dev); if (!isp_i2c_dev) return -ENOMEM; isp_i2c_dev->dev = &pdev->dev; diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c index 468287922363a2..ce9b5afad95db5 100644 --- a/drivers/i2c/busses/i2c-designware-pcidrv.c +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c @@ -230,7 +230,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, if (r) return dev_err_probe(device, r, "I/O memory remapping failed\n"); - dev = devm_kzalloc(device, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(device, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 1da6b0314b6a01..13dd7c50486a41 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -144,7 +144,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) else if (irq < 0) return irq; - dev = devm_kzalloc(device, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(device, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c index 38d7f31aee79c1..896a9bb447f69f 100644 --- a/drivers/i2c/busses/i2c-digicolor.c +++ b/drivers/i2c/busses/i2c-digicolor.c @@ -291,7 +291,7 @@ static int dc_i2c_probe(struct platform_device *pdev) struct dc_i2c *i2c; int ret = 0, irq; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct dc_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct dc_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c index bde2ef09886268..8ee1834aa61955 100644 --- a/drivers/i2c/busses/i2c-dln2.c +++ b/drivers/i2c/busses/i2c-dln2.c @@ -191,7 +191,7 @@ static int dln2_i2c_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev); - dln2 = devm_kzalloc(dev, sizeof(*dln2), GFP_KERNEL); + dln2 = devm_kzalloc_obj(dev, *dln2); if (!dln2) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-emev2.c b/drivers/i2c/busses/i2c-emev2.c index ece019b3d066e5..7ad209eee565da 100644 --- a/drivers/i2c/busses/i2c-emev2.c +++ b/drivers/i2c/busses/i2c-emev2.c @@ -363,7 +363,7 @@ static int em_i2c_probe(struct platform_device *pdev) struct clk *sclk; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c index 9c1c5f3c09f6df..9686a7b5cb6dd5 100644 --- a/drivers/i2c/busses/i2c-exynos5.c +++ b/drivers/i2c/busses/i2c-exynos5.c @@ -890,7 +890,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev) struct exynos5_i2c *i2c; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct exynos5_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index b2dc5ae1d0e4b8..405062a4c718f7 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -683,7 +683,7 @@ static int fsi_i2c_probe(struct fsi_device *fsi_dev) u32 port_no, ports, stat; int rc; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 56d6847cbf6d74..9eb8865fc1d526 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -528,7 +528,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) enum gpiod_flags gflags; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-gxp.c b/drivers/i2c/busses/i2c-gxp.c index 6a5cef7e438397..19daabdb7850ab 100644 --- a/drivers/i2c/busses/i2c-gxp.c +++ b/drivers/i2c/busses/i2c-gxp.c @@ -522,8 +522,7 @@ static int gxp_i2c_probe(struct platform_device *pdev) regmap_update_bits(i2cg_map, GXP_I2CINTEN, 0x00000FFF, 0); } - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c index fca1ca011312d6..1ad79a38b2ac06 100644 --- a/drivers/i2c/busses/i2c-hisi.c +++ b/drivers/i2c/busses/i2c-hisi.c @@ -463,7 +463,7 @@ static int hisi_i2c_probe(struct platform_device *pdev) u32 hw_version; int ret; - ctlr = devm_kzalloc(dev, sizeof(*ctlr), GFP_KERNEL); + ctlr = devm_kzalloc_obj(dev, *ctlr); if (!ctlr) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c index 95ab910b80c0e2..27284185a2dee8 100644 --- a/drivers/i2c/busses/i2c-hix5hd2.c +++ b/drivers/i2c/busses/i2c-hix5hd2.c @@ -394,7 +394,7 @@ static int hix5hd2_i2c_probe(struct platform_device *pdev) unsigned int freq; int irq, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 810f61e39cad97..9d3cc705de4cdb 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1333,9 +1333,7 @@ static void i801_add_mux(struct i801_priv *priv) gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; /* Register GPIO descriptor lookup table */ - lookup = devm_kzalloc(dev, - struct_size(lookup, table, mux_config->n_gpios + 1), - GFP_KERNEL); + lookup = devm_kzalloc_flex(dev, *lookup, table, mux_config->n_gpios + 1); if (!lookup) return; lookup->dev_id = "i2c-mux-gpio"; @@ -1547,7 +1545,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) int err, i, bar = SMBBAR; struct i801_priv *priv; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-icy.c b/drivers/i2c/busses/i2c-icy.c index 55496e48ccd19b..4eb569b1c01905 100644 --- a/drivers/i2c/busses/i2c-icy.c +++ b/drivers/i2c/busses/i2c-icy.c @@ -128,11 +128,11 @@ static int icy_probe(struct zorro_dev *z, .swnode = &icy_ltc2990_node, }; - i2c = devm_kzalloc(&z->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&z->dev, *i2c); if (!i2c) return -ENOMEM; - algo_data = devm_kzalloc(&z->dev, sizeof(*algo_data), GFP_KERNEL); + algo_data = devm_kzalloc_obj(&z->dev, *algo_data); if (!algo_data) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c index 88192c25c44cda..9d2ee449a40bc9 100644 --- a/drivers/i2c/busses/i2c-img-scb.c +++ b/drivers/i2c/busses/i2c-img-scb.c @@ -1327,7 +1327,7 @@ static int img_i2c_probe(struct platform_device *pdev) int irq, ret; u32 val; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct img_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct img_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c index 7302464c371ae2..22df20e2d467f3 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -743,7 +743,7 @@ static int lpi2c_imx_alloc_rx_cmd_buf(struct lpi2c_imx_struct *lpi2c_imx) * the rx command words buffer. */ cmd_num = DIV_ROUND_UP(rx_remain, CHUNK_DATA); - dma->rx_cmd_buf = kcalloc(cmd_num, sizeof(u16), GFP_KERNEL); + dma->rx_cmd_buf = kzalloc_objs(u16, cmd_num); dma->rx_cmd_buf_len = cmd_num * sizeof(u16); if (!dma->rx_cmd_buf) { @@ -1406,7 +1406,7 @@ static int lpi2c_dma_init(struct device *dev, dma_addr_t phy_addr) if (!group) return -ENOMEM; - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) { ret = -ENOMEM; goto release_group; @@ -1483,7 +1483,7 @@ static int lpi2c_imx_probe(struct platform_device *pdev) unsigned int temp; int ret; - lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx), GFP_KERNEL); + lpi2c_imx = devm_kzalloc_obj(&pdev->dev, *lpi2c_imx); if (!lpi2c_imx) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index ccf08cd63151f2..89f2b764bbc490 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -405,7 +405,7 @@ static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_addr_t phy_ad struct device *dev = i2c_imx->adapter.dev.parent; int ret; - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) return -ENOMEM; @@ -1837,7 +1837,7 @@ static int i2c_imx_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(base), "can't get IO memory\n"); phy_addr = (dma_addr_t)res->start; - i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL); + i2c_imx = devm_kzalloc_obj(&pdev->dev, *i2c_imx); if (!i2c_imx) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c index a2ac992f9cb0d2..820c2577f5f5e9 100644 --- a/drivers/i2c/busses/i2c-isch.c +++ b/drivers/i2c/busses/i2c-isch.c @@ -277,7 +277,7 @@ static int smbus_sch_probe(struct platform_device *pdev) struct sch_i2c *priv; struct resource *res; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index 7aaefb21416ab6..463f22c73a6f68 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c @@ -886,7 +886,7 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct ismt_priv *priv; unsigned long start, len; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c index 695be3b2146085..f771c6025b4be6 100644 --- a/drivers/i2c/busses/i2c-jz4780.c +++ b/drivers/i2c/busses/i2c-jz4780.c @@ -766,7 +766,7 @@ static int jz4780_i2c_probe(struct platform_device *pdev) unsigned short tmp; struct jz4780_i2c *i2c; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct jz4780_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct jz4780_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c index 4e1d6754113220..ff32876e24d362 100644 --- a/drivers/i2c/busses/i2c-k1.c +++ b/drivers/i2c/busses/i2c-k1.c @@ -826,7 +826,7 @@ static int spacemit_i2c_probe(struct platform_device *pdev) struct reset_control *rst; int ret; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-keba.c b/drivers/i2c/busses/i2c-keba.c index 9420c8b342b573..ee9e69d6c2f03c 100644 --- a/drivers/i2c/busses/i2c-keba.c +++ b/drivers/i2c/busses/i2c-keba.c @@ -512,12 +512,12 @@ static int ki2c_probe(struct auxiliary_device *auxdev, struct ki2c *ki2c; int ret; - ki2c = devm_kzalloc(dev, sizeof(*ki2c), GFP_KERNEL); + ki2c = devm_kzalloc_obj(dev, *ki2c); if (!ki2c) return -ENOMEM; ki2c->auxdev = container_of(auxdev, struct keba_i2c_auxdev, auxdev); - ki2c->client = devm_kcalloc(dev, ki2c->auxdev->info_size, - sizeof(*ki2c->client), GFP_KERNEL); + ki2c->client = devm_kzalloc_objs(dev, *ki2c->client, + ki2c->auxdev->info_size); if (!ki2c->client) return -ENOMEM; ki2c->client_size = ki2c->auxdev->info_size; diff --git a/drivers/i2c/busses/i2c-kempld.c b/drivers/i2c/busses/i2c-kempld.c index d0438960c27264..a222f91b221b0c 100644 --- a/drivers/i2c/busses/i2c-kempld.c +++ b/drivers/i2c/busses/i2c-kempld.c @@ -295,7 +295,7 @@ static int kempld_i2c_probe(struct platform_device *pdev) int ret; u8 ctrl; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-ljca.c b/drivers/i2c/busses/i2c-ljca.c index da3370968c8ed1..7fc948b92b298f 100644 --- a/drivers/i2c/busses/i2c-ljca.c +++ b/drivers/i2c/busses/i2c-ljca.c @@ -277,7 +277,7 @@ static int ljca_i2c_probe(struct auxiliary_device *auxdev, struct ljca_i2c_dev *ljca_i2c; int ret; - ljca_i2c = devm_kzalloc(&auxdev->dev, sizeof(*ljca_i2c), GFP_KERNEL); + ljca_i2c = devm_kzalloc_obj(&auxdev->dev, *ljca_i2c); if (!ljca_i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c index ccd13c4fb83eeb..cb0c899a18a80e 100644 --- a/drivers/i2c/busses/i2c-lpc2k.c +++ b/drivers/i2c/busses/i2c-lpc2k.c @@ -350,7 +350,7 @@ static int i2c_lpc2k_probe(struct platform_device *pdev) u32 clkrate; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-ls2x-v2.c b/drivers/i2c/busses/i2c-ls2x-v2.c index 9df73557ecc409..f99af3fb8a9618 100644 --- a/drivers/i2c/busses/i2c-ls2x-v2.c +++ b/drivers/i2c/busses/i2c-ls2x-v2.c @@ -480,7 +480,7 @@ static int loongson2_i2c_probe(struct platform_device *pdev) void __iomem *base; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-ls2x.c b/drivers/i2c/busses/i2c-ls2x.c index ef2e2a26981e5c..616d007e876ef1 100644 --- a/drivers/i2c/busses/i2c-ls2x.c +++ b/drivers/i2c/busses/i2c-ls2x.c @@ -291,7 +291,7 @@ static int ls2x_i2c_probe(struct platform_device *pdev) struct ls2x_i2c_priv *priv; struct device *dev = &pdev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mchp-pci1xxxx.c b/drivers/i2c/busses/i2c-mchp-pci1xxxx.c index bc0f1a0c8ee13b..806c6c593f6d33 100644 --- a/drivers/i2c/busses/i2c-mchp-pci1xxxx.c +++ b/drivers/i2c/busses/i2c-mchp-pci1xxxx.c @@ -1133,7 +1133,7 @@ static int pci1xxxx_i2c_probe_pci(struct pci_dev *pdev, struct pci1xxxx_i2c *i2c; int ret; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c index 0d9032953e48da..9e03953df5d72b 100644 --- a/drivers/i2c/busses/i2c-meson.c +++ b/drivers/i2c/busses/i2c-meson.c @@ -460,7 +460,7 @@ static int meson_i2c_probe(struct platform_device *pdev) struct i2c_timings timings; int irq, ret = 0; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct meson_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct meson_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-microchip-corei2c.c b/drivers/i2c/busses/i2c-microchip-corei2c.c index 5a429f17359ff6..e5fa28f20228ce 100644 --- a/drivers/i2c/busses/i2c-microchip-corei2c.c +++ b/drivers/i2c/busses/i2c-microchip-corei2c.c @@ -541,7 +541,7 @@ static int mchp_corei2c_probe(struct platform_device *pdev) struct resource *res; int irq, ret; - idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc_obj(&pdev->dev, *idev); if (!idev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c index 0cc8b9e5f3336a..432d9588f32d6f 100644 --- a/drivers/i2c/busses/i2c-mlxbf.c +++ b/drivers/i2c/busses/i2c-mlxbf.c @@ -1044,8 +1044,7 @@ static int mlxbf_i2c_init_resource(struct platform_device *pdev, if (!res || *res || type >= MLXBF_I2C_END_RES) return -EINVAL; - tmp_res = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), - GFP_KERNEL); + tmp_res = devm_kzalloc_obj(dev, struct mlxbf_i2c_resource); if (!tmp_res) return -ENOMEM; @@ -2240,7 +2239,7 @@ static int mlxbf_i2c_probe(struct platform_device *pdev) u32 resource_version; int irq, ret; - priv = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct mlxbf_i2c_priv); if (!priv) return -ENOMEM; @@ -2259,15 +2258,15 @@ static int mlxbf_i2c_probe(struct platform_device *pdev) priv->resource_version = resource_version; if (priv->chip->type < MLXBF_I2C_CHIP_TYPE_3 && resource_version == 0) { - priv->timer = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); + priv->timer = devm_kzalloc_obj(dev, struct mlxbf_i2c_resource); if (!priv->timer) return -ENOMEM; - priv->mst = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); + priv->mst = devm_kzalloc_obj(dev, struct mlxbf_i2c_resource); if (!priv->mst) return -ENOMEM; - priv->slv = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); + priv->slv = devm_kzalloc_obj(dev, struct mlxbf_i2c_resource); if (!priv->slv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c index 07d3cadbf5102a..237bed92ff22a0 100644 --- a/drivers/i2c/busses/i2c-mlxcpld.c +++ b/drivers/i2c/busses/i2c-mlxcpld.c @@ -529,7 +529,7 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev) int err; u8 val; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index a21fa45bd64c47..24628102d225ed 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -779,7 +779,7 @@ static int fsl_i2c_probe(struct platform_device *op) int result; u32 clock; - i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&op->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 307925fb78e361..45d0d7156d6e96 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -1388,7 +1388,7 @@ static int mtk_i2c_probe(struct platform_device *pdev) struct mtk_i2c *i2c; int i, irq, speed_clk; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c index 9ea5e3f9a7632c..826abb9252e312 100644 --- a/drivers/i2c/busses/i2c-mt7621.c +++ b/drivers/i2c/busses/i2c-mt7621.c @@ -274,7 +274,7 @@ static int mtk_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct mtk_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct mtk_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index 1acba628e16c3b..06780dc1f1a4a0 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c @@ -983,8 +983,7 @@ mv64xxx_i2c_probe(struct platform_device *pd) if ((!pdata && !pd->dev.of_node)) return -ENODEV; - drv_data = devm_kzalloc(&pd->dev, sizeof(struct mv64xxx_i2c_data), - GFP_KERNEL); + drv_data = devm_kzalloc_obj(&pd->dev, struct mv64xxx_i2c_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c index eee4fdcd9df31a..0e634c23919b3a 100644 --- a/drivers/i2c/busses/i2c-mxs.c +++ b/drivers/i2c/busses/i2c-mxs.c @@ -810,7 +810,7 @@ static int mxs_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; int err, irq; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-nct6694.c b/drivers/i2c/busses/i2c-nct6694.c index 1413ab6f94628b..158a533dfba7d1 100644 --- a/drivers/i2c/busses/i2c-nct6694.c +++ b/drivers/i2c/busses/i2c-nct6694.c @@ -149,7 +149,7 @@ static int nct6694_i2c_probe(struct platform_device *pdev) struct nct6694_i2c_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index c3878670da9cfa..2bed98e1b3ef67 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -1099,7 +1099,7 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) if (match) match_flags = (unsigned long)match->data; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index f667a873b81e09..8e75795aa3fed6 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2500,7 +2500,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) int irq; int ret; - bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&pdev->dev, *bus); if (!bus) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-nt72676.c b/drivers/i2c/busses/i2c-nt72676.c index 1308d692fc4025..bf5dc71552f0be 100644 --- a/drivers/i2c/busses/i2c-nt72676.c +++ b/drivers/i2c/busses/i2c-nt72676.c @@ -627,7 +627,7 @@ static int nvt_i2c_probe(struct platform_device *pdev) struct nvt_i2c_bus *i2c; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c index 14c059b0394574..1f74a39c2f1fae 100644 --- a/drivers/i2c/busses/i2c-nvidia-gpu.c +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c @@ -275,7 +275,7 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct gpu_i2c_dev *i2cd; int status; - i2cd = devm_kzalloc(dev, sizeof(*i2cd), GFP_KERNEL); + i2cd = devm_kzalloc_obj(dev, *i2cd); if (!i2cd) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index 2d18c10358375f..2c87a77f4d5886 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c @@ -586,7 +586,7 @@ static int ocores_i2c_probe(struct platform_device *pdev) int ret; int i; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-octeon-platdrv.c b/drivers/i2c/busses/i2c-octeon-platdrv.c index edfca7b20f2916..6c9e108cefc39e 100644 --- a/drivers/i2c/busses/i2c-octeon-platdrv.c +++ b/drivers/i2c/busses/i2c-octeon-platdrv.c @@ -155,7 +155,7 @@ static int octeon_i2c_probe(struct platform_device *pdev) return irq; } - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) { result = -ENOMEM; goto out; diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index f02d294db42a65..4dd111f77ea0fd 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c @@ -1355,7 +1355,7 @@ omap_i2c_probe(struct platform_device *pdev) if (irq < 0) return irq; - omap = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL); + omap = devm_kzalloc_obj(&pdev->dev, struct omap_i2c_dev); if (!omap) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c index c9b62892397a0f..8db3596f0bec1e 100644 --- a/drivers/i2c/busses/i2c-opal.c +++ b/drivers/i2c/busses/i2c-opal.c @@ -209,7 +209,7 @@ static int i2c_opal_probe(struct platform_device *pdev) return -EIO; } - adapter = devm_kzalloc(&pdev->dev, sizeof(*adapter), GFP_KERNEL); + adapter = devm_kzalloc_obj(&pdev->dev, *adapter); if (!adapter) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-owl.c b/drivers/i2c/busses/i2c-owl.c index 84a195e358866d..1937a24675123b 100644 --- a/drivers/i2c/busses/i2c-owl.c +++ b/drivers/i2c/busses/i2c-owl.c @@ -439,7 +439,7 @@ static int owl_i2c_probe(struct platform_device *pdev) struct owl_i2c_dev *i2c_dev; int ret, irq; - i2c_dev = devm_kzalloc(dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-pasemi-pci.c b/drivers/i2c/busses/i2c-pasemi-pci.c index b9ccb54ec77e22..4c3aa7e1c29426 100644 --- a/drivers/i2c/busses/i2c-pasemi-pci.c +++ b/drivers/i2c/busses/i2c-pasemi-pci.c @@ -33,7 +33,7 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) return -ENODEV; - smbus = devm_kzalloc(&dev->dev, sizeof(*smbus), GFP_KERNEL); + smbus = devm_kzalloc_obj(&dev->dev, *smbus); if (!smbus) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-pasemi-platform.c b/drivers/i2c/busses/i2c-pasemi-platform.c index a486a37d386345..579797dd4b3acd 100644 --- a/drivers/i2c/busses/i2c-pasemi-platform.c +++ b/drivers/i2c/busses/i2c-pasemi-platform.c @@ -51,8 +51,7 @@ static int pasemi_platform_i2c_probe(struct platform_device *pdev) int error; int irq_num; - data = devm_kzalloc(dev, sizeof(struct pasemi_platform_i2c_data), - GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct pasemi_platform_i2c_data); if (!data) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c index c0f35ebbe37dd3..649d4b273d1ea1 100644 --- a/drivers/i2c/busses/i2c-pca-platform.c +++ b/drivers/i2c/busses/i2c-pca-platform.c @@ -142,7 +142,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) if (irq < 0) irq = 0; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index e1cc2b2bd628f3..9df76f4b15b772 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c @@ -612,7 +612,7 @@ static int i2c_pnx_probe(struct platform_device *pdev) unsigned long freq; struct resource *res; - alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); + alg_data = devm_kzalloc_obj(&pdev->dev, *alg_data); if (!alg_data) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index c9927a389aaf59..bbc5a6141b0b5e 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1432,7 +1432,7 @@ static int i2c_pxa_probe(struct platform_device *dev) struct resource *res; int ret, irq; - i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&dev->dev, struct pxa_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c index 76a5dedf659fb8..476526b099c350 100644 --- a/drivers/i2c/busses/i2c-qcom-cci.c +++ b/drivers/i2c/busses/i2c-qcom-cci.c @@ -672,7 +672,7 @@ static int cci_probe(struct platform_device *pdev) int ret, i; u32 val; - cci = devm_kzalloc(dev, sizeof(*cci), GFP_KERNEL); + cci = devm_kzalloc_obj(dev, *cci); if (!cci) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 50f4fc1330859d..ef48ab3e8b9402 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -1183,7 +1183,7 @@ static int geni_i2c_probe(struct platform_device *pdev) int ret; struct device *dev = &pdev->dev; - gi2c = devm_kzalloc(dev, sizeof(*gi2c), GFP_KERNEL); + gi2c = devm_kzalloc_obj(dev, *gi2c); if (!gi2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c index ce30634e1f402d..731bce9f9a923b 100644 --- a/drivers/i2c/busses/i2c-qup.c +++ b/drivers/i2c/busses/i2c-qup.c @@ -1705,7 +1705,7 @@ static int qup_i2c_probe(struct platform_device *pdev) int blocks; bool is_qup_v1; - qup = devm_kzalloc(&pdev->dev, sizeof(*qup), GFP_KERNEL); + qup = devm_kzalloc_obj(&pdev->dev, *qup); if (!qup) return -ENOMEM; @@ -1744,18 +1744,16 @@ static int qup_i2c_probe(struct platform_device *pdev) qup->max_xfer_sg_len = (MX_BLOCKS << 1); blocks = (MX_DMA_BLOCKS << 1) + 1; - qup->btx.sg = devm_kcalloc(&pdev->dev, - blocks, sizeof(*qup->btx.sg), - GFP_KERNEL); + qup->btx.sg = devm_kzalloc_objs(&pdev->dev, *qup->btx.sg, + blocks); if (!qup->btx.sg) { ret = -ENOMEM; goto fail_dma; } sg_init_table(qup->btx.sg, blocks); - qup->brx.sg = devm_kcalloc(&pdev->dev, - blocks, sizeof(*qup->brx.sg), - GFP_KERNEL); + qup->brx.sg = devm_kzalloc_objs(&pdev->dev, *qup->brx.sg, + blocks); if (!qup->brx.sg) { ret = -ENOMEM; goto fail_dma; diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 755064804cb210..fcb15be59cb5d6 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -1133,7 +1133,7 @@ static int rcar_i2c_probe(struct platform_device *pdev) /* Otherwise logic will break because some bytes must always use PIO */ BUILD_BUG_ON_MSG(RCAR_MIN_DMA_LEN < 3, "Invalid min DMA length"); - priv = devm_kzalloc(dev, sizeof(struct rcar_i2c_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct rcar_i2c_priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c index 2fa48219b66bde..26b9d608fa2889 100644 --- a/drivers/i2c/busses/i2c-riic.c +++ b/drivers/i2c/busses/i2c-riic.c @@ -523,7 +523,7 @@ static int riic_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; int i, ret; - riic = devm_kzalloc(dev, sizeof(*riic), GFP_KERNEL); + riic = devm_kzalloc_obj(dev, *riic); if (!riic) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index fcede9f6ed545a..9ec3beced9f938 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c @@ -1244,7 +1244,7 @@ static int rk3x_i2c_probe(struct platform_device *pdev) int irq; unsigned long clk_rate; - i2c = devm_kzalloc(&pdev->dev, sizeof(struct rk3x_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct rk3x_i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-robotfuzz-osif.c b/drivers/i2c/busses/i2c-robotfuzz-osif.c index 412fa8e37f69e1..60f68c3f9a23f6 100644 --- a/drivers/i2c/busses/i2c-robotfuzz-osif.c +++ b/drivers/i2c/busses/i2c-robotfuzz-osif.c @@ -137,7 +137,7 @@ static int osif_probe(struct usb_interface *interface, struct osif_priv *priv; u16 version; - priv = devm_kzalloc(&interface->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&interface->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c index 3a8225b0666c07..a9dd85a286d4d0 100644 --- a/drivers/i2c/busses/i2c-rtl9300.c +++ b/drivers/i2c/busses/i2c-rtl9300.c @@ -474,7 +474,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev) u32 clock_freq, scl_num, sda_num; int ret, i = 0; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-rzv2m.c b/drivers/i2c/busses/i2c-rzv2m.c index 206a99e722a376..905e87c0e14b73 100644 --- a/drivers/i2c/busses/i2c-rzv2m.c +++ b/drivers/i2c/busses/i2c-rzv2m.c @@ -414,7 +414,7 @@ static int rzv2m_i2c_probe(struct platform_device *pdev) struct resource *res; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 15e14a6fe6dce9..35583d7f34a740 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -1020,11 +1020,11 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) } } - i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, struct s3c24xx_i2c); if (!i2c) return -ENOMEM; - i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + i2c->pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!i2c->pdata) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index 3a55f803e4f155..1aefa1bb54ce0a 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c @@ -870,7 +870,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) int ret; u32 bus_speed; - pd = devm_kzalloc(&dev->dev, sizeof(struct sh_mobile_i2c_data), GFP_KERNEL); + pd = devm_kzalloc_obj(&dev->dev, struct sh_mobile_i2c_data); if (!pd) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index c42925f9a330b8..5d4367aa966729 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -486,7 +486,7 @@ static int sprd_i2c_probe(struct platform_device *pdev) pdev->id = of_alias_get_id(dev->of_node, "i2c"); - i2c_dev = devm_kzalloc(dev, sizeof(struct sprd_i2c), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(dev, struct sprd_i2c); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c index 0a2b43b5577ba1..9453e89c70419d 100644 --- a/drivers/i2c/busses/i2c-st.c +++ b/drivers/i2c/busses/i2c-st.c @@ -797,7 +797,7 @@ static int st_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; int ret; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-stm32.c b/drivers/i2c/busses/i2c-stm32.c index 064e47d6c96fdb..5160491f47f046 100644 --- a/drivers/i2c/busses/i2c-stm32.c +++ b/drivers/i2c/busses/i2c-stm32.c @@ -18,7 +18,7 @@ struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev, struct dma_slave_config dma_sconfig; int ret; - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) return ERR_PTR(-ENOMEM); diff --git a/drivers/i2c/busses/i2c-stm32f4.c b/drivers/i2c/busses/i2c-stm32f4.c index 579ab29ef5543e..48c95e09e86ea9 100644 --- a/drivers/i2c/busses/i2c-stm32f4.c +++ b/drivers/i2c/busses/i2c-stm32f4.c @@ -759,7 +759,7 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) struct reset_control *rst; int ret; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c index 6bd281a9ef7232..2e1cc6a92b81de 100644 --- a/drivers/i2c/busses/i2c-stm32f7.c +++ b/drivers/i2c/busses/i2c-stm32f7.c @@ -2096,7 +2096,7 @@ static int stm32f7_i2c_enable_smbus_alert(struct stm32f7_i2c_dev *i2c_dev) struct device *dev = i2c_dev->dev; void __iomem *base = i2c_dev->base; - alert = devm_kzalloc(dev, sizeof(*alert), GFP_KERNEL); + alert = devm_kzalloc_obj(dev, *alert); if (!alert) return -ENOMEM; @@ -2161,7 +2161,7 @@ static int stm32f7_i2c_probe(struct platform_device *pdev) dma_addr_t phy_addr; int irq_error, irq_event, ret; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c index 4f70b12a9559a3..cf150dc77267b3 100644 --- a/drivers/i2c/busses/i2c-sun6i-p2wi.c +++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c @@ -205,7 +205,7 @@ static int p2wi_probe(struct platform_device *pdev) if (of_get_child_count(np) > 1) return dev_err_probe(dev, -EINVAL, "P2WI only supports one target device\n"); - p2wi = devm_kzalloc(dev, sizeof(struct p2wi), GFP_KERNEL); + p2wi = devm_kzalloc_obj(dev, struct p2wi); if (!p2wi) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c index 968cbe32161edf..b34dd9b5c79354 100644 --- a/drivers/i2c/busses/i2c-synquacer.c +++ b/drivers/i2c/busses/i2c-synquacer.c @@ -539,7 +539,7 @@ static int synquacer_i2c_probe(struct platform_device *pdev) u32 bus_speed; int ret; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-tegra-bpmp.c b/drivers/i2c/busses/i2c-tegra-bpmp.c index bb0de6db6391bc..25dcde183b42a7 100644 --- a/drivers/i2c/busses/i2c-tegra-bpmp.c +++ b/drivers/i2c/busses/i2c-tegra-bpmp.c @@ -286,7 +286,7 @@ static int tegra_bpmp_i2c_probe(struct platform_device *pdev) u32 value; int err; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 76d21bc51c6189..a81ff2c339f2eb 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -2271,7 +2271,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) struct resource *res; int err; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + i2c_dev = devm_kzalloc_obj(&pdev->dev, *i2c_dev); if (!i2c_dev) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c index 3959f23fc4407d..d58c97caf6b6de 100644 --- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c +++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c @@ -160,7 +160,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev, struct octeon_i2c *i2c; int ret; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index 7190802a493c30..5885eab3355a7d 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -517,7 +517,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) unsigned long clk_rate; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c index ad7bbf5e246607..8c53957c40efee 100644 --- a/drivers/i2c/busses/i2c-uniphier.c +++ b/drivers/i2c/busses/i2c-uniphier.c @@ -312,7 +312,7 @@ static int uniphier_i2c_probe(struct platform_device *pdev) unsigned long clk_rate; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-usbio.c b/drivers/i2c/busses/i2c-usbio.c index 66da1e90848ae8..12a4154860a428 100644 --- a/drivers/i2c/busses/i2c-usbio.c +++ b/drivers/i2c/busses/i2c-usbio.c @@ -237,7 +237,7 @@ static int usbio_i2c_probe(struct auxiliary_device *adev, if (!i2c_desc) return -EINVAL; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c index a1ab6ef6f0716d..ad2fc895bb8dcb 100644 --- a/drivers/i2c/busses/i2c-versatile.c +++ b/drivers/i2c/busses/i2c-versatile.c @@ -66,7 +66,7 @@ static int i2c_versatile_probe(struct platform_device *dev) struct i2c_versatile *i2c; int ret; - i2c = devm_kzalloc(&dev->dev, sizeof(struct i2c_versatile), GFP_KERNEL); + i2c = devm_kzalloc_obj(&dev->dev, struct i2c_versatile); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-viai2c-common.c b/drivers/i2c/busses/i2c-viai2c-common.c index 5a53ed95a59b67..7ba99c3e0cfd6a 100644 --- a/drivers/i2c/busses/i2c-viai2c-common.c +++ b/drivers/i2c/busses/i2c-viai2c-common.c @@ -179,7 +179,7 @@ int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat) { struct viai2c *i2c; - i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(&pdev->dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-viai2c-zhaoxin.c b/drivers/i2c/busses/i2c-viai2c-zhaoxin.c index 81f0bfdf919f83..9ba37a8f1aa16c 100644 --- a/drivers/i2c/busses/i2c-viai2c-zhaoxin.c +++ b/drivers/i2c/busses/i2c-viai2c-zhaoxin.c @@ -307,7 +307,7 @@ static int zxi2c_probe(struct platform_device *pdev) if (error) return error; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; i2c->pltfm_priv = priv; diff --git a/drivers/i2c/busses/i2c-viperboard.c b/drivers/i2c/busses/i2c-viperboard.c index f596efcc291c22..018c23c52034c0 100644 --- a/drivers/i2c/busses/i2c-viperboard.c +++ b/drivers/i2c/busses/i2c-viperboard.c @@ -360,7 +360,7 @@ static int vprbrd_i2c_probe(struct platform_device *pdev) int ret; int pipe; - vb_i2c = devm_kzalloc(&pdev->dev, sizeof(*vb_i2c), GFP_KERNEL); + vb_i2c = devm_kzalloc_obj(&pdev->dev, *vb_i2c); if (vb_i2c == NULL) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c index 5da6fef92bec36..d6103dbca0c86c 100644 --- a/drivers/i2c/busses/i2c-virtio.c +++ b/drivers/i2c/busses/i2c-virtio.c @@ -197,7 +197,7 @@ static int virtio_i2c_probe(struct virtio_device *vdev) return dev_err_probe(&vdev->dev, -EINVAL, "Zero-length request feature is mandatory\n"); - vi = devm_kzalloc(&vdev->dev, sizeof(*vi), GFP_KERNEL); + vi = devm_kzalloc_obj(&vdev->dev, *vi); if (!vi) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-xgene-slimpro.c b/drivers/i2c/busses/i2c-xgene-slimpro.c index 08a126aa83dfa3..a09d479f3b0d1c 100644 --- a/drivers/i2c/busses/i2c-xgene-slimpro.c +++ b/drivers/i2c/busses/i2c-xgene-slimpro.c @@ -440,7 +440,7 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev) struct mbox_client *cl; int rc; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index ba560462d4513b..ab7916745ad391 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -1463,7 +1463,7 @@ static int xiic_i2c_probe(struct platform_device *pdev) u8 i; u32 sr; - i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + i2c = devm_kzalloc_obj(dev, *i2c); if (!i2c) return -ENOMEM; diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index 44cad95ee8abc3..ce253a41752d15 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -508,7 +508,7 @@ static int xlp9xx_i2c_probe(struct platform_device *pdev) struct xlp9xx_i2c_dev *priv; int err = 0; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index b98442ffff946a..3eb2b2fcf00c61 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -368,7 +368,7 @@ static int i2c_atr_map_msgs(struct i2c_atr_chan *chan, struct i2c_msg *msgs, u16 *new_buf; /* We don't care about old data, hence no realloc() */ - new_buf = kmalloc_array(num, sizeof(*new_buf), GFP_KERNEL); + new_buf = kmalloc_objs(*new_buf, num); if (!new_buf) return -ENOMEM; @@ -676,7 +676,7 @@ static int i2c_atr_parse_alias_pool(struct i2c_atr *atr) if (!alias_pool->size) return 0; - aliases32 = kcalloc(num_aliases, sizeof(*aliases32), GFP_KERNEL); + aliases32 = kzalloc_objs(*aliases32, num_aliases); if (!aliases32) { ret = -ENOMEM; goto err_free_alias_pool; diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testunit.c index 4a1bf1aa504bbc..5807149b5177bd 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -237,7 +237,7 @@ static int i2c_slave_testunit_probe(struct i2c_client *client) { struct testunit_data *tu; - tu = devm_kzalloc(&client->dev, sizeof(struct testunit_data), GFP_KERNEL); + tu = devm_kzalloc_obj(&client->dev, struct testunit_data); if (!tu) return -ENOMEM; diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 069f08f68bc15e..188ced93c18b11 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -172,8 +172,7 @@ static int smbalert_probe(struct i2c_client *ara) struct gpio_desc *gpiod; int res, irq; - alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert), - GFP_KERNEL); + alert = devm_kzalloc_obj(&ara->dev, struct i2c_smbus_alert); if (!alert) return -ENOMEM; diff --git a/drivers/i2c/i2c-stub.c b/drivers/i2c/i2c-stub.c index 04314e3ed24c95..b87b5fd5473ee0 100644 --- a/drivers/i2c/i2c-stub.c +++ b/drivers/i2c/i2c-stub.c @@ -99,7 +99,7 @@ static struct smbus_block_data *stub_find_block(struct device *dev, } } if (rb == NULL && create) { - rb = devm_kzalloc(dev, sizeof(*rb), GFP_KERNEL); + rb = devm_kzalloc_obj(dev, *rb); if (rb == NULL) return rb; rb->command = command; @@ -334,9 +334,7 @@ static int __init i2c_stub_allocate_banks(int i) chip->bank_mask >>= 1; } - chip->bank_words = kcalloc(chip->bank_mask * chip->bank_size, - sizeof(u16), - GFP_KERNEL); + chip->bank_words = kzalloc_objs(u16, chip->bank_mask * chip->bank_size); if (!chip->bank_words) return -ENOMEM; diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c index 2403c0bf7c4319..c15f4c2d267ba6 100644 --- a/drivers/i2c/muxes/i2c-demux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c @@ -218,10 +218,9 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, struct_size(priv, chan, num_chan), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, chan, num_chan); - props = devm_kcalloc(&pdev->dev, num_chan, sizeof(*props), GFP_KERNEL); + props = devm_kzalloc_objs(&pdev->dev, *props, num_chan); if (!priv || !props) return -ENOMEM; diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 9b46b84e84fbdb..6c23d17722afc0 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -134,7 +134,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) unsigned int initial_state; int i, ngpios, ret; - mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(&pdev->dev, *mux); if (!mux) return -ENOMEM; diff --git a/drivers/i2c/muxes/i2c-mux-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c index ab8e116610522d..182bff1eeb5da0 100644 --- a/drivers/i2c/muxes/i2c-mux-gpmux.c +++ b/drivers/i2c/muxes/i2c-mux-gpmux.c @@ -80,7 +80,7 @@ static int i2c_mux_probe(struct platform_device *pdev) if (!np) return -ENODEV; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index 13da757100fe99..6c1cd4df77e8d6 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -152,7 +152,7 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) struct resource *res; int i, ret, nr; - mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(&pdev->dev, *mux); if (!mux) return -ENOMEM; diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 01e05bad8661ee..9928c5dffb5b00 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -3123,7 +3123,7 @@ i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master, struct device *dev = &master->dev; int ret; - boardinfo = devm_kzalloc(dev, sizeof(*boardinfo), GFP_KERNEL); + boardinfo = devm_kzalloc_obj(dev, *boardinfo); if (!boardinfo) return -ENOMEM; @@ -3169,7 +3169,7 @@ i3c_master_add_i3c_boardinfo(struct i3c_master_controller *master, enum i3c_addr_slot_status addrstatus; u32 init_dyn_addr = 0, static_addr_method = 0; - boardinfo = devm_kzalloc(dev, sizeof(*boardinfo), GFP_KERNEL); + boardinfo = devm_kzalloc_obj(dev, *boardinfo); if (!boardinfo) return -ENOMEM; diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c index ad57b7500678d5..fbbf72d024de0f 100644 --- a/drivers/i3c/master/adi-i3c-master.c +++ b/drivers/i3c/master/adi-i3c-master.c @@ -942,7 +942,7 @@ static int adi_i3c_master_probe(struct platform_device *pdev) unsigned int version; int ret, irq; - master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(&pdev->dev, *master); if (!master) return -ENOMEM; @@ -975,9 +975,8 @@ static int adi_i3c_master_probe(struct platform_device *pdev) master->free_rr_slots = GENMASK(ADI_MAX_DEVS, 1); spin_lock_init(&master->ibi.lock); master->ibi.num_slots = 15; - master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots, - sizeof(*master->ibi.slots), - GFP_KERNEL); + master->ibi.slots = devm_kzalloc_objs(&pdev->dev, *master->ibi.slots, + master->ibi.num_slots); if (!master->ibi.slots) return -ENOMEM; diff --git a/drivers/i3c/master/amd-i3c-master.c b/drivers/i3c/master/amd-i3c-master.c index b62157729a5b82..0c63e5f742de73 100644 --- a/drivers/i3c/master/amd-i3c-master.c +++ b/drivers/i3c/master/amd-i3c-master.c @@ -1070,7 +1070,7 @@ static int xi3c_master_probe(struct platform_device *pdev) struct xi3c_master *master; int ret; - master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(&pdev->dev, *master); if (!master) return -ENOMEM; diff --git a/drivers/i3c/master/ast2600-i3c-master.c b/drivers/i3c/master/ast2600-i3c-master.c index e05e83812c712c..9d16c36749eceb 100644 --- a/drivers/i3c/master/ast2600-i3c-master.c +++ b/drivers/i3c/master/ast2600-i3c-master.c @@ -129,7 +129,7 @@ static int ast2600_i3c_probe(struct platform_device *pdev) struct ast2600_i3c *i3c; int rc; - i3c = devm_kzalloc(&pdev->dev, sizeof(*i3c), GFP_KERNEL); + i3c = devm_kzalloc_obj(&pdev->dev, *i3c); if (!i3c) return -ENOMEM; diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c index d1119f203d1b65..34aa8f8e1a0a26 100644 --- a/drivers/i3c/master/dw-i3c-master.c +++ b/drivers/i3c/master/dw-i3c-master.c @@ -1802,7 +1802,7 @@ static int dw_i3c_probe(struct platform_device *pdev) { struct dw_i3c_master *master; - master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(&pdev->dev, *master); if (!master) return -ENOMEM; diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c index 2d98c1ce9b12a0..6477c8380bd8f2 100644 --- a/drivers/i3c/master/i3c-master-cdns.c +++ b/drivers/i3c/master/i3c-master-cdns.c @@ -1547,7 +1547,7 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) int ret, irq; u32 val; - master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(&pdev->dev, *master); if (!master) return -ENOMEM; @@ -1601,9 +1601,8 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) spin_lock_init(&master->ibi.lock); master->ibi.num_slots = CONF_STATUS1_IBI_HW_RES(val); - master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots, - sizeof(*master->ibi.slots), - GFP_KERNEL); + master->ibi.slots = devm_kzalloc_objs(&pdev->dev, *master->ibi.slots, + master->ibi.num_slots); if (!master->ibi.slots) return -ENOMEM; diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 23853ca134fbce..478bbe5d314ed5 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -171,7 +171,7 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m) if (ret) return ret; - hci->ibi_devs = devm_kcalloc(dev, hci->DAT_entries, sizeof(*hci->ibi_devs), GFP_KERNEL); + hci->ibi_devs = devm_kzalloc_objs(dev, *hci->ibi_devs, hci->DAT_entries); if (!hci->ibi_devs) return -ENOMEM; @@ -1190,7 +1190,7 @@ static int i3c_hci_probe(struct platform_device *pdev) struct i3c_hci *hci; int irq, ret; - hci = devm_kzalloc(&pdev->dev, sizeof(*hci), GFP_KERNEL); + hci = devm_kzalloc_obj(&pdev->dev, *hci); if (!hci) return -ENOMEM; diff --git a/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c b/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c index 5b8e10d05ceeaa..78fa42b2dc948b 100644 --- a/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c +++ b/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c @@ -165,7 +165,7 @@ static void intel_reset(void __iomem *priv) static int intel_i3c_init(struct mipi_i3c_hci_pci *hci) { - struct intel_host *host = devm_kzalloc(&hci->pci->dev, sizeof(*host), GFP_KERNEL); + struct intel_host *host = devm_kzalloc_obj(&hci->pci->dev, *host); void __iomem *priv = hci->base + INTEL_PRIV_OFFSET; if (!host) @@ -426,7 +426,7 @@ static int mipi_i3c_hci_pci_probe(struct pci_dev *pci, struct mipi_i3c_hci_pci *hci; int ret; - hci = devm_kzalloc(&pci->dev, sizeof(*hci), GFP_KERNEL); + hci = devm_kzalloc_obj(&pci->dev, *hci); if (!hci) return -ENOMEM; diff --git a/drivers/i3c/master/mipi-i3c-hci/pio.c b/drivers/i3c/master/mipi-i3c-hci/pio.c index 439578a6eb54c8..bc1d63ffd9592f 100644 --- a/drivers/i3c/master/mipi-i3c-hci/pio.c +++ b/drivers/i3c/master/mipi-i3c-hci/pio.c @@ -239,7 +239,7 @@ static int hci_pio_init(struct i3c_hci *hci) u32 size_val; u32 cmd_sz, resp_sz, ibi_val; - pio = devm_kzalloc(hci->master.dev.parent, sizeof(*pio), GFP_KERNEL); + pio = devm_kzalloc_obj(hci->master.dev.parent, *pio); if (!pio) return -ENOMEM; diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c index 28c0927a0179c1..5719b78f05036f 100644 --- a/drivers/i3c/master/renesas-i3c.c +++ b/drivers/i3c/master/renesas-i3c.c @@ -1457,7 +1457,7 @@ static int renesas_i3c_probe(struct platform_device *pdev) struct renesas_i3c *i3c; int ret, i; - i3c = devm_kzalloc(&pdev->dev, sizeof(*i3c), GFP_KERNEL); + i3c = devm_kzalloc_obj(&pdev->dev, *i3c); if (!i3c) return -ENOMEM; diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index e700392f0801f4..2632ac6dc1c0ee 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -2003,7 +2003,7 @@ static int svc_i3c_master_probe(struct platform_device *pdev) struct svc_i3c_master *master; int ret, i; - master = devm_kzalloc(dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(dev, *master); if (!master) return -ENOMEM; @@ -2055,9 +2055,8 @@ static int svc_i3c_master_probe(struct platform_device *pdev) spin_lock_init(&master->ibi.lock); master->ibi.num_slots = SVC_I3C_MAX_DEVS; - master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots, - sizeof(*master->ibi.slots), - GFP_KERNEL); + master->ibi.slots = devm_kzalloc_objs(&pdev->dev, *master->ibi.slots, + master->ibi.num_slots); if (!master->ibi.slots) { ret = -ENOMEM; goto err_disable_clks; diff --git a/drivers/iio/accel/adxl367_i2c.c b/drivers/iio/accel/adxl367_i2c.c index 42e747f5d1a1a7..a1f135cb6ca114 100644 --- a/drivers/iio/accel/adxl367_i2c.c +++ b/drivers/iio/accel/adxl367_i2c.c @@ -45,7 +45,7 @@ static int adxl367_i2c_probe(struct i2c_client *client) struct adxl367_i2c_state *st; struct regmap *regmap; - st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&client->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/accel/adxl367_spi.c b/drivers/iio/accel/adxl367_spi.c index 1d1418452bdc36..72462b7f09cd8e 100644 --- a/drivers/iio/accel/adxl367_spi.c +++ b/drivers/iio/accel/adxl367_spi.c @@ -90,7 +90,7 @@ static int adxl367_spi_probe(struct spi_device *spi) struct adxl367_spi_state *st; struct regmap *regmap; - st = devm_kzalloc(&spi->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&spi->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/adc/ab8500-gpadc.c b/drivers/iio/adc/ab8500-gpadc.c index 8eaa1dd6a89b79..3f8be5d526bccf 100644 --- a/drivers/iio/adc/ab8500-gpadc.c +++ b/drivers/iio/adc/ab8500-gpadc.c @@ -1039,13 +1039,11 @@ static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, } dev_info(gpadc->dev, "found %d ADC channels\n", nchans); - iio_chans = devm_kcalloc(gpadc->dev, nchans, - sizeof(*iio_chans), GFP_KERNEL); + iio_chans = devm_kzalloc_objs(gpadc->dev, *iio_chans, nchans); if (!iio_chans) return -ENOMEM; - gpadc->chans = devm_kcalloc(gpadc->dev, nchans, - sizeof(*gpadc->chans), GFP_KERNEL); + gpadc->chans = devm_kzalloc_objs(gpadc->dev, *gpadc->chans, nchans); if (!gpadc->chans) return -ENOMEM; diff --git a/drivers/iio/adc/ad4062.c b/drivers/iio/adc/ad4062.c index 8e5984055b159e..ce87cb88b4561f 100644 --- a/drivers/iio/adc/ad4062.c +++ b/drivers/iio/adc/ad4062.c @@ -1431,7 +1431,7 @@ static int ad4062_gpio_init(struct ad4062_state *st) if (!device_property_read_bool(dev, "gpio-controller")) return 0; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; diff --git a/drivers/iio/adc/ad4851.c b/drivers/iio/adc/ad4851.c index 480d1798f17b68..f5a9b99128eac9 100644 --- a/drivers/iio/adc/ad4851.c +++ b/drivers/iio/adc/ad4851.c @@ -970,7 +970,7 @@ static int ad4851_parse_channels_common(struct iio_dev *indio_dev, return dev_err_probe(dev, -EINVAL, "Too many channels: %u\n", num_channels); - channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index fc5dbc624856de..c2c1662bd10df5 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -1228,13 +1228,11 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev, /* Add one for temperature */ st->num_channels = min(num_channels + 1, AD7124_MAX_CHANNELS); - chan = devm_kcalloc(dev, st->num_channels, - sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_objs(dev, *chan, st->num_channels); if (!chan) return -ENOMEM; - channels = devm_kcalloc(dev, st->num_channels, sizeof(*channels), - GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, st->num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 24904be5090a46..ece526def7a31c 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -1201,8 +1201,8 @@ static int ad7173_setup(struct iio_dev *indio_dev) st->interface_mode = 0x0; st->config_usage_counter = 0; - st->config_cnts = devm_kcalloc(dev, st->info->num_configs, - sizeof(*st->config_cnts), GFP_KERNEL); + st->config_cnts = devm_kzalloc_objs(dev, *st->config_cnts, + st->info->num_configs); if (!st->config_cnts) return -ENOMEM; @@ -1801,12 +1801,11 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) indio_dev->num_channels = num_channels; st->num_channels = num_channels; - chan_arr = devm_kcalloc(dev, sizeof(*chan_arr), st->num_channels, GFP_KERNEL); + chan_arr = devm_kzalloc_objs(dev, *chan_arr, st->num_channels); if (!chan_arr) return -ENOMEM; - chans_st_arr = devm_kcalloc(dev, st->num_channels, sizeof(*st->channels), - GFP_KERNEL); + chans_st_arr = devm_kzalloc_objs(dev, *st->channels, st->num_channels); if (!chans_st_arr) return -ENOMEM; diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 8bd81054631112..5aa540c10b5f28 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -1238,8 +1238,7 @@ static int ad7194_parse_channels(struct iio_dev *indio_dev) num_channels += AD7194_CH_BASE_NR; - ad7194_channels = devm_kcalloc(dev, num_channels, - sizeof(*ad7194_channels), GFP_KERNEL); + ad7194_channels = devm_kzalloc_objs(dev, *ad7194_channels, num_channels); if (!ad7194_channels) return -ENOMEM; diff --git a/drivers/iio/adc/ad7280a.c b/drivers/iio/adc/ad7280a.c index 5ae0d694d20cc7..bfba94a02363aa 100644 --- a/drivers/iio/adc/ad7280a.c +++ b/drivers/iio/adc/ad7280a.c @@ -670,8 +670,8 @@ static int ad7280_channel_init(struct ad7280_state *st, bool irq_present) { int dev, cnt = 0; - st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 1, - sizeof(*st->channels), GFP_KERNEL); + st->channels = devm_kzalloc_objs(&st->spi->dev, *st->channels, + (st->slave_num + 1) * 12 + 1); if (!st->channels) return -ENOMEM; diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index cebb8ed8dcb115..3132ed226bb4a7 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -1400,8 +1400,7 @@ static int ad7606_probe_channels(struct iio_dev *indio_dev) if (slow_bus) indio_dev->num_channels++; - channels = devm_kcalloc(dev, indio_dev->num_channels, sizeof(*channels), - GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, indio_dev->num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 8c479fa50a2376..9699e63df96fd4 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -284,7 +284,7 @@ static int ad7606_spi_offload_probe(struct device *dev, }; int ret; - bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL); + bus_data = devm_kzalloc_obj(dev, *bus_data); if (!bus_data) return -ENOMEM; st->bus_data = bus_data; diff --git a/drivers/iio/adc/ad7768.c b/drivers/iio/adc/ad7768.c index aa2db87a1b9f1a..d307609f6653fe 100644 --- a/drivers/iio/adc/ad7768.c +++ b/drivers/iio/adc/ad7768.c @@ -1424,7 +1424,7 @@ static int ad7768_parse_config(struct iio_dev *indio_dev, if (num_channels > st->chip_info->num_channels) return dev_err_probe(dev, -ENOSPC, "Invalid number of channels\n"); - chan = devm_kcalloc(dev, num_channels, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_objs(dev, *chan, num_channels); if (!chan) return -ENOMEM; diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c index 12656d3cdcec8e..f3e7ee15f5f996 100644 --- a/drivers/iio/adc/ad7944.c +++ b/drivers/iio/adc/ad7944.c @@ -571,7 +571,7 @@ static int ad7944_chain_mode_alloc(struct device *dev, /* 1 channel for each device in chain plus 1 for soft timestamp */ - chan = devm_kcalloc(dev, n_chain_dev + 1, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_objs(dev, *chan, n_chain_dev + 1); if (!chan) return -ENOMEM; @@ -612,7 +612,7 @@ static int ad7944_chain_mode_alloc(struct device *dev, return dev_err_probe(dev, -EINVAL, "chain is limited to 32 devices\n"); - scan_masks = devm_kcalloc(dev, 2, sizeof(*scan_masks), GFP_KERNEL); + scan_masks = devm_kzalloc_objs(dev, *scan_masks, 2); if (!scan_masks) return -ENOMEM; diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 34b7b1256f0df8..587d2c64ec557f 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -1037,8 +1037,8 @@ static int ad9467_scale_fill(struct ad9467_state *st) const struct ad9467_chip_info *info = st->info; unsigned int i, val1, val2; - st->scales = devm_kmalloc_array(&st->spi->dev, info->num_scales, - sizeof(*st->scales), GFP_KERNEL); + st->scales = devm_kmalloc_objs(&st->spi->dev, *st->scales, + info->num_scales); if (!st->scales) return -ENOMEM; @@ -1285,8 +1285,8 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev) if (!IS_ENABLED(CONFIG_DEBUG_FS)) return; - st->chan_test = devm_kcalloc(&st->spi->dev, st->info->num_channels, - sizeof(*st->chan_test), GFP_KERNEL); + st->chan_test = devm_kzalloc_objs(&st->spi->dev, *st->chan_test, + st->info->num_channels); if (!st->chan_test) return; diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index 119ddc5a13e27c..32a1e0f5a69480 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -822,8 +822,8 @@ int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indi struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); int ret; - sigma_delta->slots = devm_kcalloc(dev, sigma_delta->num_slots, - sizeof(*sigma_delta->slots), GFP_KERNEL); + sigma_delta->slots = devm_kzalloc_objs(dev, *sigma_delta->slots, + sigma_delta->num_slots); if (!sigma_delta->slots) return -ENOMEM; diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index 8b7c45d51dbe8a..4b77b7169d95cd 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -731,7 +731,7 @@ static int adi_axi_adc_probe(struct platform_device *pdev) struct clk *clk; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 0ac74ad92fcae5..433f81cbf4bc8a 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -633,9 +633,8 @@ static int at91_adc_trigger_init(struct iio_dev *idev) struct at91_adc_state *st = iio_priv(idev); int i, ret; - st->trig = devm_kcalloc(&idev->dev, - st->caps->trigger_number, sizeof(*st->trig), - GFP_KERNEL); + st->trig = devm_kzalloc_objs(&idev->dev, *st->trig, + st->caps->trigger_number); if (st->trig == NULL) { ret = -ENOMEM; diff --git a/drivers/iio/adc/cc10001_adc.c b/drivers/iio/adc/cc10001_adc.c index d42b747325aa8c..5348ca44b3e0de 100644 --- a/drivers/iio/adc/cc10001_adc.c +++ b/drivers/iio/adc/cc10001_adc.c @@ -268,9 +268,8 @@ static int cc10001_adc_channel_init(struct iio_dev *indio_dev, indio_dev->num_channels = bitmap_weight(&channel_map, CC10001_ADC_NUM_CHANNELS) + 1; - chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels, - sizeof(struct iio_chan_spec), - GFP_KERNEL); + chan_array = devm_kzalloc_objs(&indio_dev->dev, struct iio_chan_spec, + indio_dev->num_channels); if (!chan_array) return -ENOMEM; diff --git a/drivers/iio/adc/industrialio-adc.c b/drivers/iio/adc/industrialio-adc.c index b4057230e749cb..4a141affc8bfb4 100644 --- a/drivers/iio/adc/industrialio-adc.c +++ b/drivers/iio/adc/industrialio-adc.c @@ -49,8 +49,7 @@ int devm_iio_adc_device_alloc_chaninfo_se(struct device *dev, if (!num_chan) return -ENOENT; - chan_array = devm_kcalloc(dev, num_chan, sizeof(*chan_array), - GFP_KERNEL); + chan_array = devm_kzalloc_objs(dev, *chan_array, num_chan); if (!chan_array) return -ENOMEM; diff --git a/drivers/iio/adc/max11410.c b/drivers/iio/adc/max11410.c index 23ae684cf08b2d..cbef7978c93e76 100644 --- a/drivers/iio/adc/max11410.c +++ b/drivers/iio/adc/max11410.c @@ -710,12 +710,11 @@ static int max11410_parse_channels(struct max11410_state *st, /* Reserve space for soft timestamp channel */ num_ch++; - channels = devm_kcalloc(dev, num_ch, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_ch); if (!channels) return -ENOMEM; - st->channels = devm_kcalloc(dev, num_ch, sizeof(*st->channels), - GFP_KERNEL); + st->channels = devm_kzalloc_objs(dev, *st->channels, num_ch); if (!st->channels) return -ENOMEM; @@ -779,9 +778,9 @@ static int max11410_parse_channels(struct max11410_state *st, if (sig_path == MAX11410_PGA_SIG_PATH_PGA) { __set_bit(IIO_CHAN_INFO_SCALE, &chanspec.info_mask_separate_available); - cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2, - sizeof(*cfg->scale_avail), - GFP_KERNEL); + cfg->scale_avail = devm_kzalloc_objs(dev, + *cfg->scale_avail, + MAX11410_SCALE_AVAIL_SIZE * 2); if (!cfg->scale_avail) return -ENOMEM; diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c index 259ac4ebdedf1d..6d60952dd33ffb 100644 --- a/drivers/iio/adc/mcp3564.c +++ b/drivers/iio/adc/mcp3564.c @@ -1017,7 +1017,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) return dev_err_probe(dev, -EINVAL, "Too many channels %d > %d\n", num_ch, adc->chip_info->num_channels); - channels = devm_kcalloc(dev, num_ch, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_ch); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c index 5e901ab25c8e8b..b77f07a45be2e3 100644 --- a/drivers/iio/adc/pac1934.c +++ b/drivers/iio/adc/pac1934.c @@ -1447,7 +1447,7 @@ static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info, if (info->active_channels[i]) active_channels_count++; - pac1934_group = devm_kzalloc(dev, sizeof(*pac1934_group), GFP_KERNEL); + pac1934_group = devm_kzalloc_obj(dev, *pac1934_group); if (!pac1934_group) return -ENOMEM; diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index f777986a6aba34..0b1ada5696af50 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -836,7 +836,7 @@ static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, int ret; u32 pval; - gp_data = devm_kzalloc(&pdev->dev, sizeof(*gp_data), GFP_KERNEL); + gp_data = devm_kzalloc_obj(&pdev->dev, *gp_data); if (!gp_data) return -ENOMEM; diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index 3cdf90c4444b47..bb86b2f3a8c84e 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -836,13 +836,12 @@ static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc) } dev_dbg(adc->dev, "found %d ADC channels\n", adc->nchans); - adc->iio_chans = devm_kcalloc(adc->dev, adc->nchans, - sizeof(*adc->iio_chans), GFP_KERNEL); + adc->iio_chans = devm_kzalloc_objs(adc->dev, *adc->iio_chans, + adc->nchans); if (!adc->iio_chans) return -ENOMEM; - adc->chans = devm_kcalloc(adc->dev, adc->nchans, - sizeof(*adc->chans), GFP_KERNEL); + adc->chans = devm_kzalloc_objs(adc->dev, *adc->chans, adc->nchans); if (!adc->chans) return -ENOMEM; diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c index c68c6c5f6aca09..be12bb6781cb3b 100644 --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c @@ -561,13 +561,12 @@ static int adc5_get_fw_data(struct adc5_chip *adc) if (!adc->nchannels) return dev_err_probe(dev, -EINVAL, "No ADC channels found\n"); - adc->iio_chans = devm_kcalloc(dev, adc->nchannels, - sizeof(*adc->iio_chans), GFP_KERNEL); + adc->iio_chans = devm_kzalloc_objs(dev, *adc->iio_chans, adc->nchannels); if (!adc->iio_chans) return -ENOMEM; - adc->chan_props = devm_kcalloc(dev, adc->nchannels, - sizeof(*adc->chan_props), GFP_KERNEL); + adc->chan_props = devm_kzalloc_objs(dev, *adc->chan_props, + adc->nchannels); if (!adc->chan_props) return -ENOMEM; @@ -615,7 +614,7 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc) struct tm5_aux_dev_wrapper *aux_device; int i, ret, i_tm = 0; - aux_device = devm_kzalloc(adc->dev, sizeof(*aux_device), GFP_KERNEL); + aux_device = devm_kzalloc_obj(adc->dev, *aux_device); if (!aux_device) return -ENOMEM; @@ -623,9 +622,9 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc) aux_device->aux_dev.dev.parent = adc->dev; aux_device->aux_dev.dev.release = adc5_gen3_aux_device_release; - aux_device->tm_props = devm_kcalloc(adc->dev, adc->n_tm_channels, - sizeof(*aux_device->tm_props), - GFP_KERNEL); + aux_device->tm_props = devm_kzalloc_objs(adc->dev, + *aux_device->tm_props, + adc->n_tm_channels); if (!aux_device->tm_props) return -ENOMEM; @@ -741,8 +740,7 @@ static int adc5_gen3_probe(struct platform_device *pdev) adc->dev_data.num_sdams = ret; - reg = devm_kcalloc(dev, adc->dev_data.num_sdams, sizeof(u32), - GFP_KERNEL); + reg = devm_kzalloc_objs(dev, u32, adc->dev_data.num_sdams); if (!reg) return -ENOMEM; @@ -752,9 +750,8 @@ static int adc5_gen3_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Failed to read reg property\n"); - adc->dev_data.base = devm_kcalloc(dev, adc->dev_data.num_sdams, - sizeof(*adc->dev_data.base), - GFP_KERNEL); + adc->dev_data.base = devm_kzalloc_objs(dev, *adc->dev_data.base, + adc->dev_data.num_sdams); if (!adc->dev_data.base) return -ENOMEM; diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index 83ecd3adf65f1c..d57ba8526e0c5b 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -831,13 +831,13 @@ static int adc5_get_fw_data(struct adc5_chip *adc) if (!adc->nchannels) return dev_err_probe(adc->dev, -EINVAL, "no channels defined\n"); - adc->iio_chans = devm_kcalloc(adc->dev, adc->nchannels, - sizeof(*adc->iio_chans), GFP_KERNEL); + adc->iio_chans = devm_kzalloc_objs(adc->dev, *adc->iio_chans, + adc->nchannels); if (!adc->iio_chans) return -ENOMEM; - adc->chan_props = devm_kcalloc(adc->dev, adc->nchannels, - sizeof(*adc->chan_props), GFP_KERNEL); + adc->chan_props = devm_kzalloc_objs(adc->dev, *adc->chan_props, + adc->nchannels); if (!adc->chan_props) return -ENOMEM; diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index d7a2df3c810edb..ea7571c5cedf2b 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -760,13 +760,13 @@ static int vadc_get_fw_data(struct vadc_priv *vadc) if (!vadc->nchannels) return -EINVAL; - vadc->iio_chans = devm_kcalloc(vadc->dev, vadc->nchannels, - sizeof(*vadc->iio_chans), GFP_KERNEL); + vadc->iio_chans = devm_kzalloc_objs(vadc->dev, *vadc->iio_chans, + vadc->nchannels); if (!vadc->iio_chans) return -ENOMEM; - vadc->chan_props = devm_kcalloc(vadc->dev, vadc->nchannels, - sizeof(*vadc->chan_props), GFP_KERNEL); + vadc->chan_props = devm_kzalloc_objs(vadc->dev, *vadc->chan_props, + vadc->nchannels); if (!vadc->chan_props) return -ENOMEM; diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index 3b95f47445a8b9..340813f6f890ee 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -335,7 +335,7 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l int num_channels; u8 i; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/iio/adc/sd_adc_modulator.c b/drivers/iio/adc/sd_adc_modulator.c index def44d8831dc3a..c5f69a079e0e03 100644 --- a/drivers/iio/adc/sd_adc_modulator.c +++ b/drivers/iio/adc/sd_adc_modulator.c @@ -111,7 +111,7 @@ static int iio_sd_mod_probe(struct platform_device *pdev) if (!device_property_present(dev, "#io-backend-cells")) return iio_sd_mod_register(pdev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c index a42d82d61cb850..4ff91997c8e6c3 100644 --- a/drivers/iio/adc/stm32-adc-core.c +++ b/drivers/iio/adc/stm32-adc-core.c @@ -713,7 +713,7 @@ static int stm32_adc_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, &priv->common); diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 600f975f1d7b53..521085f0bc5241 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2436,8 +2436,8 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) if (timestamping) num_channels++; - channels = devm_kcalloc(&indio_dev->dev, num_channels, - sizeof(struct iio_chan_spec), GFP_KERNEL); + channels = devm_kzalloc_objs(&indio_dev->dev, struct iio_chan_spec, + num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 674767da3ac379..898fd882509c5b 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -1613,7 +1613,7 @@ static int stm32_dfsdm_audio_init(struct device *dev, struct iio_dev *indio_dev) if (num_ch == 1) legacy = true; - ch = devm_kzalloc(&indio_dev->dev, sizeof(*ch), GFP_KERNEL); + ch = devm_kzalloc_obj(&indio_dev->dev, *ch); if (!ch) return -ENOMEM; @@ -1679,13 +1679,13 @@ static int stm32_dfsdm_adc_init(struct device *dev, struct iio_dev *indio_dev) /* Generic binding. SD modulator IIO device not used. Use SD modulator backend. */ adc->hwc = NULL; - adc->backend = devm_kcalloc(&indio_dev->dev, num_ch, sizeof(*adc->backend), - GFP_KERNEL); + adc->backend = devm_kzalloc_objs(&indio_dev->dev, *adc->backend, + num_ch); if (!adc->backend) return -ENOMEM; } - ch = devm_kcalloc(&indio_dev->dev, num_ch, sizeof(*ch), GFP_KERNEL); + ch = devm_kzalloc_objs(&indio_dev->dev, *ch, num_ch); if (!ch) return -ENOMEM; indio_dev->channels = ch; diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c index 47e2d1338e9e67..fe70968646b18a 100644 --- a/drivers/iio/adc/stm32-dfsdm-core.c +++ b/drivers/iio/adc/stm32-dfsdm-core.c @@ -370,7 +370,7 @@ static int stm32_dfsdm_probe(struct platform_device *pdev) struct stm32_dfsdm *dfsdm; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -398,13 +398,13 @@ static int stm32_dfsdm_probe(struct platform_device *pdev) if (ret < 0) return ret; - dfsdm->fl_list = devm_kcalloc(&pdev->dev, dfsdm->num_fls, - sizeof(*dfsdm->fl_list), GFP_KERNEL); + dfsdm->fl_list = devm_kzalloc_objs(&pdev->dev, *dfsdm->fl_list, + dfsdm->num_fls); if (!dfsdm->fl_list) return -ENOMEM; - dfsdm->ch_list = devm_kcalloc(&pdev->dev, dfsdm->num_chs, - sizeof(*dfsdm->ch_list), GFP_KERNEL); + dfsdm->ch_list = devm_kzalloc_objs(&pdev->dev, *dfsdm->ch_list, + dfsdm->num_chs); if (!dfsdm->ch_list) return -ENOMEM; diff --git a/drivers/iio/adc/ti-ads1119.c b/drivers/iio/adc/ti-ads1119.c index b0f04741ddc6e7..67699be4a3e969 100644 --- a/drivers/iio/adc/ti-ads1119.c +++ b/drivers/iio/adc/ti-ads1119.c @@ -615,15 +615,14 @@ static int ads1119_alloc_and_config_channels(struct iio_dev *indio_dev) st->num_channels_cfg, ADS1119_MAX_CHANNELS); - st->channels_cfg = devm_kcalloc(dev, st->num_channels_cfg, - sizeof(*st->channels_cfg), GFP_KERNEL); + st->channels_cfg = devm_kzalloc_objs(dev, *st->channels_cfg, + st->num_channels_cfg); if (!st->channels_cfg) return -ENOMEM; /* Allocate one more iio channel for the timestamp */ num_channels = st->num_channels_cfg + 1; - iio_channels = devm_kcalloc(dev, num_channels, sizeof(*iio_channels), - GFP_KERNEL); + iio_channels = devm_kzalloc_objs(dev, *iio_channels, num_channels); if (!iio_channels) return -ENOMEM; diff --git a/drivers/iio/adc/ti-ads112c04.c b/drivers/iio/adc/ti-ads112c04.c index acf7209db76122..9c4faa11a63a37 100644 --- a/drivers/iio/adc/ti-ads112c04.c +++ b/drivers/iio/adc/ti-ads112c04.c @@ -290,7 +290,7 @@ static int ads112c04_parse_channels(struct iio_dev *indio_dev, "num of channel nodes exceeds %d\n", ADS112C04_MAX_CHANNELS); - channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c index 3c877126b0bebf..6645ddd6b11a0a 100644 --- a/drivers/iio/adc/ti-ads112c14.c +++ b/drivers/iio/adc/ti-ads112c14.c @@ -1926,21 +1926,19 @@ static int ads112c14_parse_channels(struct iio_dev *indio_dev, num_child_nodes = device_get_named_child_node_count(dev, "channel"); - data->measurements = devm_kcalloc(dev, num_child_nodes, - sizeof(*data->measurements), GFP_KERNEL); + data->measurements = devm_kzalloc_objs(dev, *data->measurements, + num_child_nodes); if (!data->measurements) return -ENOMEM; num_data_chans = num_child_nodes + ARRAY_SIZE(ads112c14_sys_mon_channels); - data->channel_states = devm_kcalloc(dev, num_data_chans, - sizeof(*data->channel_states), - GFP_KERNEL); + data->channel_states = devm_kzalloc_objs(dev, *data->channel_states, + num_data_chans); if (!data->channel_states) return -ENOMEM; - channels = devm_kcalloc(dev, num_data_chans + 1, - sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_data_chans + 1); if (!channels) return -ENOMEM; diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c index 1d25f887cadb92..631dbc2551930f 100644 --- a/drivers/iio/adc/ti-ads131e08.c +++ b/drivers/iio/adc/ti-ads131e08.c @@ -722,13 +722,12 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) return -EINVAL; } - channels = devm_kcalloc(&st->spi->dev, num_channels, - sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(&st->spi->dev, *channels, num_channels); if (!channels) return -ENOMEM; - channel_config = devm_kcalloc(&st->spi->dev, num_channels, - sizeof(*channel_config), GFP_KERNEL); + channel_config = devm_kzalloc_objs(&st->spi->dev, *channel_config, + num_channels); if (!channel_config) return -ENOMEM; diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index e53c839e87ef3a..0c3e0e9e836479 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c @@ -403,8 +403,7 @@ static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev, int i; indio_dev->num_channels = channels; - chan_array = devm_kcalloc(dev, channels, sizeof(*chan_array), - GFP_KERNEL); + chan_array = devm_kzalloc_objs(dev, *chan_array, channels); if (!chan_array) return -ENOMEM; diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c index 31b1c01baa2711..e7fd371b34042c 100644 --- a/drivers/iio/adc/twl6030-gpadc.c +++ b/drivers/iio/adc/twl6030-gpadc.c @@ -893,10 +893,8 @@ static int twl6030_gpadc_probe(struct platform_device *pdev) gpadc = iio_priv(indio_dev); - gpadc->twl6030_cal_tbl = devm_kcalloc(dev, - pdata->nchannels, - sizeof(*gpadc->twl6030_cal_tbl), - GFP_KERNEL); + gpadc->twl6030_cal_tbl = devm_kzalloc_objs(dev, *gpadc->twl6030_cal_tbl, + pdata->nchannels); if (!gpadc->twl6030_cal_tbl) return -ENOMEM; diff --git a/drivers/iio/adc/versal-sysmon-core.c b/drivers/iio/adc/versal-sysmon-core.c index 1b55d343982eff..f7f177b501bab4 100644 --- a/drivers/iio/adc/versal-sysmon-core.c +++ b/drivers/iio/adc/versal-sysmon-core.c @@ -877,7 +877,7 @@ static int sysmon_parse_fw(struct iio_dev *indio_dev, struct device *dev, int ir num_static = ARRAY_SIZE(temp_channels); num_chan = size_add(num_temp, size_add(num_static, num_supply)); - sysmon_channels = devm_kcalloc(dev, num_chan, sizeof(*sysmon_channels), GFP_KERNEL); + sysmon_channels = devm_kzalloc_objs(dev, *sysmon_channels, num_chan); if (!sysmon_channels) return -ENOMEM; diff --git a/drivers/iio/adc/versal-sysmon.c b/drivers/iio/adc/versal-sysmon.c index 529d0486c9f9e9..7d850ea1f40193 100644 --- a/drivers/iio/adc/versal-sysmon.c +++ b/drivers/iio/adc/versal-sysmon.c @@ -56,7 +56,7 @@ static int sysmon_platform_probe(struct platform_device *pdev) struct sysmon_mmio *mmio; struct regmap *regmap; - mmio = devm_kzalloc(dev, sizeof(*mmio), GFP_KERNEL); + mmio = devm_kzalloc_obj(dev, *mmio); if (!mmio) return -ENOMEM; diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c index 158e6133abf501..90269d67306909 100644 --- a/drivers/iio/adc/xilinx-ams.c +++ b/drivers/iio/adc/xilinx-ams.c @@ -1240,7 +1240,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev) ARRAY_SIZE(ams_ctrl_channels); /* Initialize buffer for channel specification */ - ams_channels = devm_kcalloc(dev, ams_size, sizeof(*ams_channels), GFP_KERNEL); + ams_channels = devm_kzalloc_objs(dev, *ams_channels, ams_size); if (!ams_channels) return -ENOMEM; diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c index 9b9d7a12ce878b..e27c39b06e4431 100644 --- a/drivers/iio/addac/ad74115.c +++ b/drivers/iio/addac/ad74115.c @@ -1539,8 +1539,7 @@ static int ad74115_setup_iio_channels(struct iio_dev *indio_dev) struct device *dev = &st->spi->dev; struct iio_chan_spec *channels; - channels = devm_kcalloc(dev, sizeof(*channels), - indio_dev->num_channels, GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, indio_dev->num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index 2e5a58e48a89aa..76bad554f028a3 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -1269,8 +1269,8 @@ static int ad74413r_setup_channels(struct iio_dev *indio_dev) unsigned int i, num_chans, chan_i; int ret; - channels = devm_kcalloc(st->dev, sizeof(*channels), - indio_dev->num_channels, GFP_KERNEL); + channels = devm_kzalloc_objs(st->dev, *channels, + indio_dev->num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/amplifiers/adl8113.c b/drivers/iio/amplifiers/adl8113.c index 1f1cfca980b4e3..97f66884ab8d9d 100644 --- a/drivers/iio/amplifiers/adl8113.c +++ b/drivers/iio/amplifiers/adl8113.c @@ -157,8 +157,7 @@ static int adl8113_init_gain_configs(struct device *dev, struct adl8113_state *s * - Internal amp and bypass (always present) * - External bypass A and B (optional if configured) */ - st->gain_configs = devm_kcalloc(dev, 4, sizeof(*st->gain_configs), - GFP_KERNEL); + st->gain_configs = devm_kzalloc_objs(dev, *st->gain_configs, 4); if (!st->gain_configs) return -ENOMEM; diff --git a/drivers/iio/chemical/bme680_spi.c b/drivers/iio/chemical/bme680_spi.c index 2175b9564fa109..fcc4b18b9a44bf 100644 --- a/drivers/iio/chemical/bme680_spi.c +++ b/drivers/iio/chemical/bme680_spi.c @@ -112,7 +112,7 @@ static int bme680_spi_probe(struct spi_device *spi) struct bme680_spi_bus_context *bus_context; struct regmap *regmap; - bus_context = devm_kzalloc(&spi->dev, sizeof(*bus_context), GFP_KERNEL); + bus_context = devm_kzalloc_obj(&spi->dev, *bus_context); if (!bus_context) return -ENOMEM; diff --git a/drivers/iio/chemical/scd30_serial.c b/drivers/iio/chemical/scd30_serial.c index 31b0fc957b086b..c80453ab033965 100644 --- a/drivers/iio/chemical/scd30_serial.c +++ b/drivers/iio/chemical/scd30_serial.c @@ -218,7 +218,7 @@ static int scd30_serdev_probe(struct serdev_device *serdev) struct scd30_serdev_priv *priv; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/chemical/sps30_serial.c b/drivers/iio/chemical/sps30_serial.c index 0cdba8703e9388..c8a9d544449632 100644 --- a/drivers/iio/chemical/sps30_serial.c +++ b/drivers/iio/chemical/sps30_serial.c @@ -389,7 +389,7 @@ static int sps30_serial_probe(struct serdev_device *serdev) struct sps30_serial_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c b/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c index 6762685e6876cd..f9e348d83140b6 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c @@ -244,8 +244,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev) /* Allocate a channel per activity and one for timestamp */ nb_activities = hweight_long(activities) + 1; - st->channels = devm_kcalloc(dev, nb_activities, - sizeof(*st->channels), GFP_KERNEL); + st->channels = devm_kzalloc_objs(dev, *st->channels, nb_activities); if (!st->channels) return -ENOMEM; diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c index 442b40ef27cf51..5222c2dce7d5a3 100644 --- a/drivers/iio/common/scmi_sensors/scmi_iio.c +++ b/drivers/iio/common/scmi_sensors/scmi_iio.c @@ -509,10 +509,8 @@ static int scmi_iio_set_sampling_freq_avail(struct iio_dev *iio_dev) int i; sensor->freq_avail = - devm_kcalloc(&iio_dev->dev, - array_size(sensor->sensor_info->intervals.count, 2), - sizeof(*sensor->freq_avail), - GFP_KERNEL); + devm_kzalloc_objs(&iio_dev->dev, *sensor->freq_avail, + array_size(sensor->sensor_info->intervals.count, 2)); if (!sensor->freq_avail) return -ENOMEM; @@ -585,9 +583,7 @@ scmi_alloc_iiodev(struct scmi_device *sdev, iiodev->info = &scmi_iio_info; iio_channels = - devm_kcalloc(dev, iiodev->num_channels, - sizeof(*iio_channels), - GFP_KERNEL); + devm_kzalloc_objs(dev, *iio_channels, iiodev->num_channels); if (!iio_channels) return ERR_PTR(-ENOMEM); diff --git a/drivers/iio/common/ssp_sensors/ssp_dev.c b/drivers/iio/common/ssp_sensors/ssp_dev.c index 828fcfe1d4f104..40b658d39294b6 100644 --- a/drivers/iio/common/ssp_sensors/ssp_dev.c +++ b/drivers/iio/common/ssp_sensors/ssp_dev.c @@ -441,7 +441,7 @@ static struct ssp_data *ssp_parse_dt(struct device *dev) { struct ssp_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return NULL; diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 76f91696f66a36..54be24c7d939f7 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -294,7 +294,7 @@ static struct st_sensors_platform_data *st_sensors_dev_probe(struct device *dev, if (!dev_fwnode(dev)) return NULL; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); if (!device_property_read_u32(dev, "st,drdy-int-pin", &val) && (val <= 2)) diff --git a/drivers/iio/dac/ad3530r.c b/drivers/iio/dac/ad3530r.c index 9e043639801d2f..d5703a435ea379 100644 --- a/drivers/iio/dac/ad3530r.c +++ b/drivers/iio/dac/ad3530r.c @@ -811,7 +811,7 @@ static int ad3530r_parse_channel_cfg(struct iio_dev *indio_dev) if (!num_chan) return dev_err_probe(dev, -ENOENT, "No channels configured\n"); - channels = devm_kcalloc(dev, num_chan, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_chan); if (!channels) return -ENOMEM; diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c index 4a5ad419f4eaab..38ff892d67407a 100644 --- a/drivers/iio/dac/ad5380.c +++ b/drivers/iio/dac/ad5380.c @@ -345,8 +345,8 @@ static int ad5380_alloc_channels(struct device *dev, struct iio_dev *indio_dev) struct iio_chan_spec *channels; unsigned int i; - channels = devm_kcalloc(dev, st->chip_info->num_channels, - sizeof(struct iio_chan_spec), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, struct iio_chan_spec, + st->chip_info->num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c index 4720733d66b23a..fcbb334899a6dc 100644 --- a/drivers/iio/dac/ad5592r-base.c +++ b/drivers/iio/dac/ad5592r-base.c @@ -510,9 +510,7 @@ static int ad5592r_alloc_channels(struct iio_dev *iio_dev) st->channel_offstate[reg] = tmp; } - channels = devm_kcalloc(st->dev, - 1 + 2 * num_channels, sizeof(*channels), - GFP_KERNEL); + channels = devm_kzalloc_objs(st->dev, *channels, 1 + 2 * num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 69cd9753f3399d..92952ceee07812 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -163,8 +163,7 @@ static int ad5686_spi_probe(struct spi_device *spi) /* read operation requires at least 2 transfers */ capacity = max(info->num_channels, 2); - bus_data = devm_kzalloc(dev, struct_size(bus_data, xfers, capacity), - GFP_KERNEL); + bus_data = devm_kzalloc_flex(dev, *bus_data, xfers, capacity); if (!bus_data) return -ENOMEM; diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c index 730289dd8ef698..8143f056a0efed 100644 --- a/drivers/iio/dac/ad5755.c +++ b/drivers/iio/dac/ad5755.c @@ -707,7 +707,7 @@ static struct ad5755_platform_data *ad5755_parse_fw(struct device *dev) if (!dev_fwnode(dev)) return NULL; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c index f4f3bc67c68ed9..812805dd291fe8 100644 --- a/drivers/iio/dac/adi-axi-dac.c +++ b/drivers/iio/dac/adi-axi-dac.c @@ -892,7 +892,7 @@ static int axi_dac_probe(struct platform_device *pdev) struct clk *clk; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/dac/ltc2664.c b/drivers/iio/dac/ltc2664.c index 35bec55ebde1ff..22827dcaed0b23 100644 --- a/drivers/iio/dac/ltc2664.c +++ b/drivers/iio/dac/ltc2664.c @@ -619,10 +619,9 @@ static int ltc2664_setup(struct ltc2664_state *st) * Duplicate the default channel configuration as it can change during * @ltc2664_channel_config() */ - st->iio_channels = devm_kcalloc(&st->spi->dev, - chip_info->num_channels, - sizeof(struct iio_chan_spec), - GFP_KERNEL); + st->iio_channels = devm_kzalloc_objs(&st->spi->dev, + struct iio_chan_spec, + chip_info->num_channels); if (!st->iio_channels) return -ENOMEM; diff --git a/drivers/iio/dac/max22007.c b/drivers/iio/dac/max22007.c index e2c7e2ad37ba6a..b52c055bdeee58 100644 --- a/drivers/iio/dac/max22007.c +++ b/drivers/iio/dac/max22007.c @@ -335,7 +335,7 @@ static int max22007_parse_channel_cfg(struct max22007_state *st, u8 *num_channel if (!num_chan) return dev_err_probe(dev, -ENODEV, "no channels configured\n"); - st->iio_chans = devm_kcalloc(dev, num_chan, sizeof(*st->iio_chans), GFP_KERNEL); + st->iio_chans = devm_kzalloc_objs(dev, *st->iio_chans, num_chan); if (!st->iio_chans) return -ENOMEM; diff --git a/drivers/iio/dac/mcp47feb02-core.c b/drivers/iio/dac/mcp47feb02-core.c index 88bffbab08541f..c5392df029c346 100644 --- a/drivers/iio/dac/mcp47feb02-core.c +++ b/drivers/iio/dac/mcp47feb02-core.c @@ -761,7 +761,7 @@ static int mcp47feb02_parse_fw(struct iio_dev *indio_dev, if (!num_channels) return dev_err_probe(dev, -EINVAL, "No channel specified in the devicetree.\n"); - channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_channels); if (!channels) return -ENOMEM; diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c index b5795c14f0fe55..9c61264c3d7310 100644 --- a/drivers/iio/dac/stm32-dac-core.c +++ b/drivers/iio/dac/stm32-dac-core.c @@ -96,7 +96,7 @@ static int stm32_dac_probe(struct platform_device *pdev) struct reset_control *rst; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, &priv->common); diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c index ec45c0f65fe3cd..e4b76e13679b2f 100644 --- a/drivers/iio/frequency/adf4350.c +++ b/drivers/iio/frequency/adf4350.c @@ -504,7 +504,7 @@ static struct adf4350_platform_data *adf4350_parse_dt(struct device *dev) struct adf4350_platform_data *pdata; unsigned int tmp; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/iio/imu/bmi323/bmi323_i2c.c b/drivers/iio/imu/bmi323/bmi323_i2c.c index e835b91ea6b4e3..52110cae83d8bf 100644 --- a/drivers/iio/imu/bmi323/bmi323_i2c.c +++ b/drivers/iio/imu/bmi323/bmi323_i2c.c @@ -78,7 +78,7 @@ static int bmi323_i2c_probe(struct i2c_client *i2c) struct bmi323_i2c_priv *priv; struct regmap *regmap; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/imu/bno055/bno055_ser_core.c b/drivers/iio/imu/bno055/bno055_ser_core.c index 01f05feaae0ae9..6810e19e163120 100644 --- a/drivers/iio/imu/bno055/bno055_ser_core.c +++ b/drivers/iio/imu/bno055/bno055_ser_core.c @@ -502,7 +502,7 @@ static int bno055_ser_probe(struct serdev_device *serdev) struct regmap *regmap; int ret; - priv = devm_kzalloc(&serdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&serdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c index cd2e53416f5b1d..890d9a8fd683b6 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -753,7 +753,7 @@ int inv_icm42600_core_probe(struct regmap *regmap, int chip, open_drain = device_property_read_bool(dev, "drive-open-drain"); - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c index f4ef75da22c762..2c0a15d6344a68 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c @@ -580,7 +580,7 @@ int inv_icm42607_core_probe(struct regmap *regmap, struct inv_icm42607_state *st; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c b/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c index c1d7aa7e950de4..0e2267622492b7 100644 --- a/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c +++ b/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c @@ -710,7 +710,7 @@ int inv_icm45600_core_probe(struct regmap *regmap, const struct inv_icm45600_chi if (IS_ERR(regmap_custom)) return dev_err_probe(dev, PTR_ERR(regmap_custom), "Failed to register regmap\n"); - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index c288437d53eae5..8ef48daf182211 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c @@ -1279,7 +1279,7 @@ static int kmx61_probe(struct i2c_client *client) struct kmx61_data *data; const char *name = NULL; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/iio/imu/smi330/smi330_i2c.c b/drivers/iio/imu/smi330/smi330_i2c.c index eb9413e22e143f..60a5270e93667c 100644 --- a/drivers/iio/imu/smi330/smi330_i2c.c +++ b/drivers/iio/imu/smi330/smi330_i2c.c @@ -87,7 +87,7 @@ static int smi330_i2c_probe(struct i2c_client *i2c) struct smi330_i2c_priv *priv; struct regmap *regmap; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 360f1365f892db..823f8ac66c2524 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -2923,7 +2923,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name = NULL; int i, err; - hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(dev, *hw); if (!hw) return -ENOMEM; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c index cbc47fa5b1012b..a27a336e84d208 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c @@ -766,8 +766,8 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw, IIO_CHAN_SOFT_TIMESTAMP(3), }; - ext_channels = devm_kcalloc(hw->dev, ARRAY_SIZE(magn_channels), - sizeof(*ext_channels), GFP_KERNEL); + ext_channels = devm_kzalloc_objs(hw->dev, *ext_channels, + ARRAY_SIZE(magn_channels)); if (!ext_channels) return NULL; diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c index 6581d14e2bcfd3..f8c25167391eef 100644 --- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c @@ -59,7 +59,7 @@ static int st_lsm9ds0_i2c_probe(struct i2c_client *client) st_sensors_dev_name_probe(dev, client->name, sizeof(client->name)); - lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL); + lsm9ds0 = devm_kzalloc_obj(dev, *lsm9ds0); if (!lsm9ds0) return -ENOMEM; diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c index e67f09e1f093f3..5209858a12dfe7 100644 --- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c @@ -52,7 +52,7 @@ static int st_lsm9ds0_spi_probe(struct spi_device *spi) st_sensors_dev_name_probe(dev, spi->modalias, sizeof(spi->modalias)); - lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL); + lsm9ds0 = devm_kzalloc_obj(dev, *lsm9ds0); if (!lsm9ds0) return -ENOMEM; diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index fbf5c39d76551e..733915728de4a4 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -543,7 +543,7 @@ int devm_iio_backend_request_buffer(struct device *dev, struct iio_backend_buffer_pair *pair; struct iio_buffer *buffer; - pair = devm_kzalloc(dev, sizeof(*pair), GFP_KERNEL); + pair = devm_kzalloc_obj(dev, *pair); if (!pair) return -ENOMEM; @@ -1177,7 +1177,7 @@ int devm_iio_backend_register(struct device *dev, * the backend object lifetime with the device being passed since * removing it will tear the frontend/consumer down. */ - back = devm_kzalloc(dev, sizeof(*back), GFP_KERNEL); + back = devm_kzalloc_obj(dev, *back); if (!back) return -ENOMEM; diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index ad18f233ee1667..120661efabbd7d 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -370,9 +370,8 @@ static int magn_3d_parse_report(struct platform_device *pdev, st->magn[2].index, st->magn[2].report_id); /* Setup IIO channel array */ - _channels = devm_kcalloc(&pdev->dev, attr_count, - sizeof(struct iio_chan_spec), - GFP_KERNEL); + _channels = devm_kzalloc_objs(&pdev->dev, struct iio_chan_spec, + attr_count); if (!_channels) { dev_err(&pdev->dev, "failed to allocate space for iio channels\n"); @@ -380,9 +379,8 @@ static int magn_3d_parse_report(struct platform_device *pdev, } /* attr_count include timestamp channel, and the iio_vals should be aligned to 8byte */ - st->iio_vals = devm_kcalloc(&pdev->dev, - ((attr_count + 1) % 2 + (attr_count + 1) / 2) * 2, - sizeof(u32), GFP_KERNEL); + st->iio_vals = devm_kzalloc_objs(&pdev->dev, u32, + ((attr_count + 1) % 2 + (attr_count + 1) / 2) * 2); if (!st->iio_vals) { dev_err(&pdev->dev, "failed to allocate space for iio values array\n"); diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c index 562457a6738260..0928976d097dbc 100644 --- a/drivers/iio/multiplexer/iio-mux.c +++ b/drivers/iio/multiplexer/iio-mux.c @@ -249,10 +249,8 @@ static int mux_configure_chan_ext_info(struct device *dev, struct mux *mux, if (!page) return -ENOMEM; - child->ext_info_cache = devm_kcalloc(dev, - num_ext_info, - sizeof(*child->ext_info_cache), - GFP_KERNEL); + child->ext_info_cache = devm_kzalloc_objs(dev, *child->ext_info_cache, + num_ext_info); if (!child->ext_info_cache) return -ENOMEM; @@ -361,7 +359,7 @@ static int mux_probe(struct platform_device *pdev) if (all_children < 0) return all_children; - labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL); + labels = devm_kmalloc_objs(dev, *labels, all_children); if (!labels) return -ENOMEM; diff --git a/drivers/iio/pressure/mpl115_spi.c b/drivers/iio/pressure/mpl115_spi.c index 3cff616e8d2f49..9eacba5d8d22e6 100644 --- a/drivers/iio/pressure/mpl115_spi.c +++ b/drivers/iio/pressure/mpl115_spi.c @@ -25,7 +25,7 @@ static int mpl115_spi_init(struct device *dev) struct spi_device *spi = to_spi_device(dev); struct mpl115_spi_buf *buf; - buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL); + buf = devm_kzalloc_obj(dev, *buf); if (!buf) return -ENOMEM; diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index 6655453c9abf94..94c558673a861c 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -504,7 +504,7 @@ __ltc2983_custom_sensor_new(struct ltc2983_data *st, const struct fwnode_handle return dev_err_ptr_probe(dev, -EINVAL, "Number of entries either 0 or not even\n"); - new_custom = devm_kzalloc(dev, sizeof(*new_custom), GFP_KERNEL); + new_custom = devm_kzalloc_obj(dev, *new_custom); if (!new_custom) return ERR_PTR(-ENOMEM); @@ -779,7 +779,7 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data u32 oc_current; int ret; - thermo = devm_kzalloc(dev, sizeof(*thermo), GFP_KERNEL); + thermo = devm_kzalloc_obj(dev, *thermo); if (!thermo) return ERR_PTR(-ENOMEM); @@ -868,7 +868,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, struct device *dev = &st->spi->dev; u32 excitation_current = 0, n_wires = 2; - rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL); + rtd = devm_kzalloc_obj(dev, *rtd); if (!rtd) return ERR_PTR(-ENOMEM); @@ -1031,7 +1031,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s u32 excitation_current = 0; int ret = 0; - thermistor = devm_kzalloc(dev, sizeof(*thermistor), GFP_KERNEL); + thermistor = devm_kzalloc_obj(dev, *thermistor); if (!thermistor) return ERR_PTR(-ENOMEM); @@ -1167,7 +1167,7 @@ ltc2983_copper_trace_new(const struct fwnode_handle *child, struct ltc2983_data "Invalid channel %d for copper trace\n", sensor->chan); - ct = devm_kzalloc(dev, sizeof(*ct), GFP_KERNEL); + ct = devm_kzalloc_obj(dev, *ct); if (!ct) return ERR_PTR(-ENOMEM); @@ -1266,7 +1266,7 @@ ltc2983_leak_detector_new(const struct fwnode_handle *child, struct ltc2983_data "Invalid channel %d for leak detector\n", sensor->chan); - ld = devm_kzalloc(dev, sizeof(*ld), GFP_KERNEL); + ld = devm_kzalloc_obj(dev, *ld); if (!ld) return ERR_PTR(-ENOMEM); @@ -1352,7 +1352,7 @@ ltc2983_diode_new(const struct fwnode_handle *child, const struct ltc2983_data * u32 temp = 0, excitation_current = 0; int ret; - diode = devm_kzalloc(dev, sizeof(*diode), GFP_KERNEL); + diode = devm_kzalloc_obj(dev, *diode); if (!diode) return ERR_PTR(-ENOMEM); @@ -1425,7 +1425,7 @@ static struct ltc2983_sensor *ltc2983_r_sense_new(struct fwnode_handle *child, int ret; u32 temp; - rsense = devm_kzalloc(dev, sizeof(*rsense), GFP_KERNEL); + rsense = devm_kzalloc_obj(dev, *rsense); if (!rsense) return ERR_PTR(-ENOMEM); @@ -1460,7 +1460,7 @@ static struct ltc2983_sensor *ltc2983_adc_new(struct fwnode_handle *child, struct device *dev = &st->spi->dev; struct ltc2983_adc *adc; - adc = devm_kzalloc(dev, sizeof(*adc), GFP_KERNEL); + adc = devm_kzalloc_obj(dev, *adc); if (!adc) return ERR_PTR(-ENOMEM); @@ -1486,7 +1486,7 @@ static struct ltc2983_sensor *ltc2983_temp_new(struct fwnode_handle *child, struct device *dev = &st->spi->dev; struct ltc2983_temp *temp; - temp = devm_kzalloc(dev, sizeof(*temp), GFP_KERNEL); + temp = devm_kzalloc_obj(dev, *temp); if (!temp) return ERR_PTR(-ENOMEM); @@ -1677,8 +1677,7 @@ static int ltc2983_parse_fw(struct ltc2983_data *st) return dev_err_probe(dev, -EINVAL, "At least one channel must be given!\n"); - st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors), - GFP_KERNEL); + st->sensors = devm_kzalloc_objs(dev, *st->sensors, st->num_channels); if (!st->sensors) return -ENOMEM; diff --git a/drivers/iio/trigger/stm32-lptimer-trigger.c b/drivers/iio/trigger/stm32-lptimer-trigger.c index 828890fe353c86..82b4122c1ac12c 100644 --- a/drivers/iio/trigger/stm32-lptimer-trigger.c +++ b/drivers/iio/trigger/stm32-lptimer-trigger.c @@ -112,7 +112,7 @@ static int stm32_lptim_trigger_probe(struct platform_device *pdev) struct stm32_lptim_cfg const *lptim_cfg; u32 index; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 4f6ff1e72f2e19..721166d476eb00 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c @@ -797,7 +797,7 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev) if (cfg->valids_table && *cfg->valids_table[index]) priv = stm32_setup_counter_device(dev); else - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/infiniband/core/frmr_pools.c b/drivers/infiniband/core/frmr_pools.c index ce8ae4305b9c8f..4af36dc8cf3838 100644 --- a/drivers/infiniband/core/frmr_pools.c +++ b/drivers/infiniband/core/frmr_pools.c @@ -145,7 +145,7 @@ static bool age_pinned_pool(struct ib_device *device, struct ib_frmr_pool *pool) to_destroy = min(total - pool->pinned_handles, pool->inactive_queue.ci); - handles = kcalloc(to_destroy, sizeof(*handles), GFP_ATOMIC); + handles = kzalloc_objs(*handles, to_destroy, GFP_ATOMIC); if (!handles) { spin_unlock(&pool->lock); return true; @@ -445,7 +445,7 @@ int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key, if (!needed_handles) goto schedule_aging; - handles = kcalloc(needed_handles, sizeof(*handles), GFP_KERNEL); + handles = kzalloc_objs(*handles, needed_handles); if (!handles) return -ENOMEM; diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index 9cc21cd762d989..327ee0958c900f 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -94,8 +94,8 @@ static int ib_init_umem_odp(struct ib_umem_odp *umem_odp, map = &umem_odp->map; if (ib_uses_virt_dma(dev)) { - map->pfn_list = kvcalloc(nr_entries, sizeof(*map->pfn_list), - GFP_KERNEL | __GFP_NOWARN); + map->pfn_list = kvzalloc_objs(*map->pfn_list, nr_entries, + GFP_KERNEL | __GFP_NOWARN); if (!map->pfn_list) ret = -ENOMEM; } else diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index aca7c6ab55cd81..cb8532225322c9 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -3022,8 +3022,7 @@ static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs) return -EINVAL; num_wq_handles = 1 << cmd.log_ind_tbl_size; - wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles), - GFP_KERNEL); + wqs_handles = kzalloc_objs(*wqs_handles, num_wq_handles); if (!wqs_handles) return -ENOMEM; diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 7d52d303620879..c4eb1de4415553 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -3186,8 +3186,8 @@ struct rdma_hw_stats *rdma_alloc_hw_stats_struct( if (!stats) return NULL; - stats->is_disabled = kcalloc(BITS_TO_LONGS(num_counters), - sizeof(*stats->is_disabled), GFP_KERNEL); + stats->is_disabled = kzalloc_objs(*stats->is_disabled, + BITS_TO_LONGS(num_counters)); if (!stats->is_disabled) goto err; diff --git a/drivers/infiniband/hw/bnxt_re/qplib_res.c b/drivers/infiniband/hw/bnxt_re/qplib_res.c index cde56ff2313b2e..1babfb46f82d05 100644 --- a/drivers/infiniband/hw/bnxt_re/qplib_res.c +++ b/drivers/infiniband/hw/bnxt_re/qplib_res.c @@ -561,7 +561,7 @@ static int bnxt_qplib_alloc_sgid_tbl(struct bnxt_qplib_res *res, if (!sgid_tbl->tbl) return -ENOMEM; - sgid_tbl->hw_id = kcalloc(max, sizeof(u16), GFP_KERNEL); + sgid_tbl->hw_id = kzalloc_objs(u16, max); if (!sgid_tbl->hw_id) goto out_free1; diff --git a/drivers/infiniband/hw/erdma/erdma_cmdq.c b/drivers/infiniband/hw/erdma/erdma_cmdq.c index b867aefe83b2f2..731f73f30b4e1a 100644 --- a/drivers/infiniband/hw/erdma/erdma_cmdq.c +++ b/drivers/infiniband/hw/erdma/erdma_cmdq.c @@ -66,8 +66,8 @@ static int erdma_cmdq_wait_res_init(struct erdma_dev *dev, int i; cmdq->wait_pool = - devm_kcalloc(&dev->pdev->dev, cmdq->max_outstandings, - sizeof(struct erdma_comp_wait), GFP_KERNEL); + devm_kzalloc_objs(&dev->pdev->dev, struct erdma_comp_wait, + cmdq->max_outstandings); if (!cmdq->wait_pool) return -ENOMEM; diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c index dd29d55d412254..ed33e83051e07d 100644 --- a/drivers/infiniband/hw/erdma/erdma_verbs.c +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c @@ -740,7 +740,7 @@ static int erdma_kmem_alloc(struct erdma_dev *dev, struct erdma_mem *mem, struct erdma_buf_list *buf_list; u32 i; - buf_list = kcalloc(page_cnt, sizeof(*buf_list), GFP_KERNEL); + buf_list = kzalloc_objs(*buf_list, page_cnt); if (!buf_list) return -ENOMEM; diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/hfi1/affinity.c index d4bf75dcd1025d..bf0a34b31474ba 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -139,8 +139,8 @@ int node_affinity_init(void) */ init_real_cpu_mask(); - hfi1_per_node_cntr = kcalloc(node_affinity.num_possible_nodes, - sizeof(*hfi1_per_node_cntr), GFP_KERNEL); + hfi1_per_node_cntr = kzalloc_objs(*hfi1_per_node_cntr, + node_affinity.num_possible_nodes); if (!hfi1_per_node_cntr) return -ENOMEM; diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c index faa724ca33bd71..2d5c5ed6d5695b 100644 --- a/drivers/infiniband/hw/hfi1/chip.c +++ b/drivers/infiniband/hw/hfi1/chip.c @@ -12650,12 +12650,11 @@ static int init_cntrs(struct hfi1_devdata *dd) } /* allocate space for the counter values */ - dd->cntrs = kcalloc(dd->ndevcntrs + num_driver_cntrs, sizeof(u64), - GFP_KERNEL); + dd->cntrs = kzalloc_objs(u64, dd->ndevcntrs + num_driver_cntrs); if (!dd->cntrs) goto bail; - dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL); + dd->scntrs = kzalloc_objs(u64, dd->ndevcntrs); if (!dd->scntrs) goto bail; @@ -12805,11 +12804,11 @@ static int init_cntrs(struct hfi1_devdata *dd) /* allocate per port storage for counter values */ ppd = (struct hfi1_pportdata *)(dd + 1); for (i = 0; i < dd->num_pports; i++, ppd++) { - ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL); + ppd->cntrs = kzalloc_objs(u64, dd->nportcntrs); if (!ppd->cntrs) goto bail; - ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL); + ppd->scntrs = kzalloc_objs(u64, dd->nportcntrs); if (!ppd->scntrs) goto bail; } diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c index b5e9ac9cfd591c..4bd715c6558347 100644 --- a/drivers/infiniband/hw/hns/hns_roce_srq.c +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c @@ -251,7 +251,7 @@ static void free_srq_wqe_buf(struct hns_roce_dev *hr_dev, static int alloc_srq_wrid(struct hns_roce_srq *srq) { - srq->wrid = kvmalloc_array(srq->wqe_cnt, sizeof(u64), GFP_KERNEL); + srq->wrid = kvmalloc_objs(u64, srq->wqe_cnt); if (!srq->wrid) return -ENOMEM; diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c index 18ad967812f505..e85c382f914089 100644 --- a/drivers/infiniband/hw/ionic/ionic_controlpath.c +++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c @@ -2021,9 +2021,8 @@ static int ionic_qp_sq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx, goto err_sq_meta; } - qp->sq_msn_idx = kmalloc_array((u32)qp->sq.mask + 1, - sizeof(*qp->sq_msn_idx), - GFP_KERNEL); + qp->sq_msn_idx = kmalloc_objs(*qp->sq_msn_idx, + (u32)qp->sq.mask + 1); if (!qp->sq_msn_idx) { rc = -ENOMEM; goto err_sq_msn; diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c index effc6bcceb7653..ebc0985c936202 100644 --- a/drivers/infiniband/hw/mlx4/qp.c +++ b/drivers/infiniband/hw/mlx4/qp.c @@ -1154,10 +1154,8 @@ static int create_qp_common(struct ib_pd *pd, struct ib_qp_init_attr *init_attr, if (err) goto err_mtt; - qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, - sizeof(u64), GFP_KERNEL); - qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, - sizeof(u64), GFP_KERNEL); + qp->sq.wrid = kvmalloc_objs(u64, qp->sq.wqe_cnt); + qp->rq.wrid = kvmalloc_objs(u64, qp->rq.wqe_cnt); if (!qp->sq.wrid || !qp->rq.wrid) { err = -ENOMEM; goto err_wrid; diff --git a/drivers/infiniband/hw/mlx4/srq.c b/drivers/infiniband/hw/mlx4/srq.c index 7bcb7e22566239..f2869ea121f18b 100644 --- a/drivers/infiniband/hw/mlx4/srq.c +++ b/drivers/infiniband/hw/mlx4/srq.c @@ -170,8 +170,7 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, if (err) goto err_mtt; - srq->wrid = kvmalloc_array(srq->msrq.max, - sizeof(u64), GFP_KERNEL); + srq->wrid = kvmalloc_objs(u64, srq->msrq.max); if (!srq->wrid) { err = -ENOMEM; goto err_mtt; diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c index 2250b195571c5c..1c25b825d0bdd3 100644 --- a/drivers/infiniband/hw/mlx5/counters.c +++ b/drivers/infiniband/hw/mlx5/counters.c @@ -174,8 +174,7 @@ static int mlx5_ib_read_counters(struct ib_counters *counters, goto err_bound; } - mread_attr.out = kcalloc(mcounters->counters_num, sizeof(u64), - GFP_KERNEL); + mread_attr.out = kzalloc_objs(u64, mcounters->counters_num); if (!mread_attr.out) { ret = -ENOMEM; goto err_bound; diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index 627dd17804c985..5891b0b2a84306 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -1213,15 +1213,11 @@ static int _create_kernel_qp(struct mlx5_ib_dev *dev, goto err_free; } - qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, - sizeof(*qp->sq.wrid), GFP_KERNEL); - qp->sq.wr_data = kvmalloc_array(qp->sq.wqe_cnt, - sizeof(*qp->sq.wr_data), GFP_KERNEL); - qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, - sizeof(*qp->rq.wrid), GFP_KERNEL); + qp->sq.wrid = kvmalloc_objs(*qp->sq.wrid, qp->sq.wqe_cnt); + qp->sq.wr_data = kvmalloc_objs(*qp->sq.wr_data, qp->sq.wqe_cnt); + qp->rq.wrid = kvmalloc_objs(*qp->rq.wrid, qp->rq.wqe_cnt); qp->sq.w_list = kvmalloc_objs(*qp->sq.w_list, qp->sq.wqe_cnt); - qp->sq.wqe_head = kvmalloc_array(qp->sq.wqe_cnt, - sizeof(*qp->sq.wqe_head), GFP_KERNEL); + qp->sq.wqe_head = kvmalloc_objs(*qp->sq.wqe_head, qp->sq.wqe_cnt); if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || !qp->sq.w_list || !qp->sq.wqe_head) { diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c index 6a4a937d97ce98..95f18e97cf695e 100644 --- a/drivers/infiniband/hw/mlx5/srq.c +++ b/drivers/infiniband/hw/mlx5/srq.c @@ -136,14 +136,14 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, } mlx5_ib_dbg(dev, "srq->buf.page_shift = %d\n", srq->buf.page_shift); - in->pas = kvcalloc(srq->buf.npages, sizeof(*in->pas), GFP_KERNEL); + in->pas = kvzalloc_objs(*in->pas, srq->buf.npages); if (!in->pas) { err = -ENOMEM; goto err_buf; } mlx5_fill_page_frag_array(&srq->buf, in->pas); - srq->wrid = kvmalloc_array(srq->msrq.max, sizeof(u64), GFP_KERNEL); + srq->wrid = kvmalloc_objs(u64, srq->msrq.max); if (!srq->wrid) { err = -ENOMEM; goto err_in; diff --git a/drivers/infiniband/hw/mthca/mthca_allocator.c b/drivers/infiniband/hw/mthca/mthca_allocator.c index 117a070e784ea2..2de7173a2fa4b6 100644 --- a/drivers/infiniband/hw/mthca/mthca_allocator.c +++ b/drivers/infiniband/hw/mthca/mthca_allocator.c @@ -213,8 +213,7 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct, npages *= 2; } - dma_list = kmalloc_array(npages, sizeof(*dma_list), - GFP_KERNEL); + dma_list = kmalloc_objs(*dma_list, npages); if (!dma_list) goto err_free; @@ -225,8 +224,7 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct, npages = (size + PAGE_SIZE - 1) / PAGE_SIZE; shift = PAGE_SHIFT; - dma_list = kmalloc_array(npages, sizeof(*dma_list), - GFP_KERNEL); + dma_list = kmalloc_objs(*dma_list, npages); if (!dma_list) return -ENOMEM; diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c index 70adcd54e20eea..2b53c2019cf1d9 100644 --- a/drivers/infiniband/hw/mthca/mthca_eq.c +++ b/drivers/infiniband/hw/mthca/mthca_eq.c @@ -486,7 +486,7 @@ static int mthca_create_eq(struct mthca_dev *dev, for (i = 0; i < npages; ++i) eq->page_list[i].buf = NULL; - dma_list = kmalloc_array(npages, sizeof(*dma_list), GFP_KERNEL); + dma_list = kmalloc_objs(*dma_list, npages); if (!dma_list) goto err_out_free; diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c index bca908054e1b6d..6d5e1e5e0862d1 100644 --- a/drivers/infiniband/hw/mthca/mthca_mr.c +++ b/drivers/infiniband/hw/mthca/mthca_mr.c @@ -144,8 +144,7 @@ static int mthca_buddy_init(struct mthca_buddy *buddy, int max_order) buddy->max_order = max_order; spin_lock_init(&buddy->lock); - buddy->bits = kcalloc(buddy->max_order + 1, sizeof(*buddy->bits), - GFP_KERNEL); + buddy->bits = kzalloc_objs(*buddy->bits, buddy->max_order + 1); buddy->num_free = kzalloc_objs(*buddy->num_free, (buddy->max_order + 1)); if (!buddy->bits || !buddy->num_free) goto err_out; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 97c2e18e67adda..651fe6a83c698c 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -1790,8 +1790,7 @@ int ocrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, srq->bit_fields_len = (srq->rq.max_cnt / 32) + (srq->rq.max_cnt % 32 ? 1 : 0); srq->idx_bit_fields = - kmalloc_array(srq->bit_fields_len, sizeof(u32), - GFP_KERNEL); + kmalloc_objs(u32, srq->bit_fields_len); if (!srq->idx_bit_fields) { status = -ENOMEM; goto arm_err; diff --git a/drivers/input/joystick/adafruit-seesaw.c b/drivers/input/joystick/adafruit-seesaw.c index 5835ed1e29e19c..897e14bb61f7d3 100644 --- a/drivers/input/joystick/adafruit-seesaw.c +++ b/drivers/input/joystick/adafruit-seesaw.c @@ -233,7 +233,7 @@ static int seesaw_probe(struct i2c_client *client) /* Wait for the registers to reset before proceeding */ usleep_range(10000, 15000); - seesaw = devm_kzalloc(&client->dev, sizeof(*seesaw), GFP_KERNEL); + seesaw = devm_kzalloc_obj(&client->dev, *seesaw); if (!seesaw) return -ENOMEM; diff --git a/drivers/input/joystick/adc-joystick.c b/drivers/input/joystick/adc-joystick.c index 4fa42f88bcfa46..71aa1f07bc443f 100644 --- a/drivers/input/joystick/adc-joystick.c +++ b/drivers/input/joystick/adc-joystick.c @@ -257,7 +257,7 @@ static int adc_joystick_probe(struct platform_device *pdev) if (error) return error; - joy = devm_kzalloc(dev, struct_size(joy, axes, num_chans), GFP_KERNEL); + joy = devm_kzalloc_flex(dev, *joy, axes, num_chans); if (!joy) return -ENOMEM; diff --git a/drivers/input/joystick/psxpad-spi.c b/drivers/input/joystick/psxpad-spi.c index aac77a2cfe468f..a2b00e420e3834 100644 --- a/drivers/input/joystick/psxpad-spi.c +++ b/drivers/input/joystick/psxpad-spi.c @@ -288,7 +288,7 @@ static int psxpad_spi_probe(struct spi_device *spi) struct input_dev *idev; int err; - pad = devm_kzalloc(&spi->dev, sizeof(struct psxpad), GFP_KERNEL); + pad = devm_kzalloc_obj(&spi->dev, struct psxpad); if (!pad) return -ENOMEM; diff --git a/drivers/input/joystick/pxrc.c b/drivers/input/joystick/pxrc.c index 52d9eab667b7ac..693d153472575e 100644 --- a/drivers/input/joystick/pxrc.c +++ b/drivers/input/joystick/pxrc.c @@ -135,7 +135,7 @@ static int pxrc_probe(struct usb_interface *intf, return error; } - pxrc = devm_kzalloc(&intf->dev, sizeof(*pxrc), GFP_KERNEL); + pxrc = devm_kzalloc_obj(&intf->dev, *pxrc); if (!pxrc) return -ENOMEM; diff --git a/drivers/input/joystick/qwiic-joystick.c b/drivers/input/joystick/qwiic-joystick.c index c471afc7862bcf..f808519c50fd10 100644 --- a/drivers/input/joystick/qwiic-joystick.c +++ b/drivers/input/joystick/qwiic-joystick.c @@ -75,7 +75,7 @@ static int qwiic_probe(struct i2c_client *client) dev_dbg(&client->dev, "SparkFun Qwiic Joystick, FW: %u.%u\n", vers.major, vers.minor); - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/joystick/sensehat-joystick.c b/drivers/input/joystick/sensehat-joystick.c index a84df39d3b2fa6..b2a65419365095 100644 --- a/drivers/input/joystick/sensehat-joystick.c +++ b/drivers/input/joystick/sensehat-joystick.c @@ -63,8 +63,7 @@ static int sensehat_joystick_probe(struct platform_device *pdev) struct sensehat_joystick *sensehat_joystick; int error, i, irq; - sensehat_joystick = devm_kzalloc(&pdev->dev, sizeof(*sensehat_joystick), - GFP_KERNEL); + sensehat_joystick = devm_kzalloc_obj(&pdev->dev, *sensehat_joystick); if (!sensehat_joystick) return -ENOMEM; diff --git a/drivers/input/keyboard/adc-keys.c b/drivers/input/keyboard/adc-keys.c index d687459a0c8038..89d6faa175071f 100644 --- a/drivers/input/keyboard/adc-keys.c +++ b/drivers/input/keyboard/adc-keys.c @@ -74,7 +74,7 @@ static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st) return -EINVAL; } - map = devm_kmalloc_array(dev, st->num_keys, sizeof(*map), GFP_KERNEL); + map = devm_kmalloc_objs(dev, *map, st->num_keys); if (!map) return -ENOMEM; @@ -109,7 +109,7 @@ static int adc_keys_probe(struct platform_device *pdev) int i, value; int error; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c index d778af2750ea71..81cd335ce3b50e 100644 --- a/drivers/input/keyboard/adp5520-keys.c +++ b/drivers/input/keyboard/adp5520-keys.c @@ -89,7 +89,7 @@ static int adp5520_keys_probe(struct platform_device *pdev) if (!(pdata->rows_en_mask && pdata->cols_en_mask)) return -EINVAL; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/adp5585-keys.c b/drivers/input/keyboard/adp5585-keys.c index f2c1ba017d20a0..ee2c3cb0445f27 100644 --- a/drivers/input/keyboard/adp5585-keys.c +++ b/drivers/input/keyboard/adp5585-keys.c @@ -273,7 +273,7 @@ static int adp5585_keys_probe(struct platform_device *pdev) const char *phys; int error; - kpad = devm_kzalloc(dev, sizeof(*kpad), GFP_KERNEL); + kpad = devm_kzalloc_obj(dev, *kpad); if (!kpad) return -ENOMEM; diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c index 4f0ddff5babae6..dde95f66293442 100644 --- a/drivers/input/keyboard/adp5588-keys.c +++ b/drivers/input/keyboard/adp5588-keys.c @@ -733,7 +733,7 @@ static int adp5588_probe(struct i2c_client *client) return -EIO; } - kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL); + kpad = devm_kzalloc_obj(&client->dev, *kpad); if (!kpad) return -ENOMEM; diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index 7d5ed45845bcf9..96c504f284953f 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -1621,7 +1621,7 @@ static int applespi_probe(struct spi_device *spi) } /* allocate driver data */ - applespi = devm_kzalloc(&spi->dev, sizeof(*applespi), GFP_KERNEL); + applespi = devm_kzalloc_obj(&spi->dev, *applespi); if (!applespi) return -ENOMEM; diff --git a/drivers/input/keyboard/bcm-keypad.c b/drivers/input/keyboard/bcm-keypad.c index f76cc6e7b787b7..b22221a6b77c05 100644 --- a/drivers/input/keyboard/bcm-keypad.c +++ b/drivers/input/keyboard/bcm-keypad.c @@ -309,7 +309,7 @@ static int bcm_kp_probe(struct platform_device *pdev) struct input_dev *input_dev; int error; - kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); + kp = devm_kzalloc_obj(&pdev->dev, *kp); if (!kp) return -ENOMEM; diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index 25b6f7bd97ee79..6ef70bc52640d8 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -438,7 +438,7 @@ static int cap11xx_init_leds(struct device *dev, if (cnt > num_leds) return -EINVAL; - led = devm_kcalloc(dev, cnt, sizeof(struct cap11xx_led), GFP_KERNEL); + led = devm_kzalloc_objs(dev, struct cap11xx_led, cnt); if (!led) return -ENOMEM; @@ -520,9 +520,7 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client) return -EINVAL; } - priv = devm_kzalloc(dev, - struct_size(priv, keycodes, cap->num_channels), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, keycodes, cap->num_channels); if (!priv) return -ENOMEM; diff --git a/drivers/input/keyboard/charlieplex_keypad.c b/drivers/input/keyboard/charlieplex_keypad.c index d46a2298e6da7c..58249066bf525b 100644 --- a/drivers/input/keyboard/charlieplex_keypad.c +++ b/drivers/input/keyboard/charlieplex_keypad.c @@ -156,7 +156,7 @@ static int charlieplex_keypad_probe(struct platform_device *pdev) unsigned int poll_interval_ms; int err; - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/clps711x-keypad.c b/drivers/input/keyboard/clps711x-keypad.c index 6a21ee17e164b5..1303dedf9c2631 100644 --- a/drivers/input/keyboard/clps711x-keypad.c +++ b/drivers/input/keyboard/clps711x-keypad.c @@ -91,7 +91,7 @@ static int clps711x_keypad_probe(struct platform_device *pdev) u32 poll_interval; int i, err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -103,9 +103,8 @@ static int clps711x_keypad_probe(struct platform_device *pdev) if (priv->row_count < 1) return -EINVAL; - priv->gpio_data = devm_kcalloc(dev, - priv->row_count, sizeof(*priv->gpio_data), - GFP_KERNEL); + priv->gpio_data = devm_kzalloc_objs(dev, *priv->gpio_data, + priv->row_count); if (!priv->gpio_data) return -ENOMEM; diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index 0a817680171c99..cd937ce053983b 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -864,7 +864,7 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) if (!cros_ec_device_registered(ec)) return -EPROBE_DEFER; - ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); + ckdev = devm_kzalloc_obj(dev, *ckdev); if (!ckdev) return -ENOMEM; diff --git a/drivers/input/keyboard/cypress-sf.c b/drivers/input/keyboard/cypress-sf.c index 4b2ae07f315c86..b75e9321b4e45b 100644 --- a/drivers/input/keyboard/cypress-sf.c +++ b/drivers/input/keyboard/cypress-sf.c @@ -74,7 +74,7 @@ static int cypress_sf_probe(struct i2c_client *client) struct cypress_sf_data *touchkey; int key, error; - touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); + touchkey = devm_kzalloc_obj(&client->dev, *touchkey); if (!touchkey) return -ENOMEM; @@ -100,10 +100,9 @@ static int cypress_sf_probe(struct i2c_client *client) touchkey->num_keys = 2; } - touchkey->keycodes = devm_kcalloc(&client->dev, - touchkey->num_keys, - sizeof(*touchkey->keycodes), - GFP_KERNEL); + touchkey->keycodes = devm_kzalloc_objs(&client->dev, + *touchkey->keycodes, + touchkey->num_keys); if (!touchkey->keycodes) return -ENOMEM; diff --git a/drivers/input/keyboard/dlink-dir685-touchkeys.c b/drivers/input/keyboard/dlink-dir685-touchkeys.c index bf94367f6b6443..33117e996cd7a6 100644 --- a/drivers/input/keyboard/dlink-dir685-touchkeys.c +++ b/drivers/input/keyboard/dlink-dir685-touchkeys.c @@ -68,7 +68,7 @@ static int dir685_tk_probe(struct i2c_client *client) int err; int i; - tk = devm_kzalloc(&client->dev, sizeof(*tk), GFP_KERNEL); + tk = devm_kzalloc_obj(&client->dev, *tk); if (!tk) return -ENOMEM; diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c index 9ea926a4c95bc2..43d8df53ad4a03 100644 --- a/drivers/input/keyboard/ep93xx_keypad.c +++ b/drivers/input/keyboard/ep93xx_keypad.c @@ -206,7 +206,7 @@ static int ep93xx_keypad_probe(struct platform_device *pdev) struct input_dev *input_dev; int err; - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index fbc31c5db3db44..661f2da6054b37 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -858,16 +858,14 @@ static int gpio_keys_probe(struct platform_device *pdev) return PTR_ERR(pdata); } - ddata = devm_kzalloc(dev, struct_size(ddata, data, pdata->nbuttons), - GFP_KERNEL); + ddata = devm_kzalloc_flex(dev, *ddata, data, pdata->nbuttons); if (!ddata) { dev_err(dev, "failed to allocate state\n"); return -ENOMEM; } - ddata->keymap = devm_kcalloc(dev, - pdata->nbuttons, sizeof(ddata->keymap[0]), - GFP_KERNEL); + ddata->keymap = devm_kzalloc_objs(dev, ddata->keymap[0], + pdata->nbuttons); if (!ddata->keymap) return -ENOMEM; diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 4e7a366ff05b02..4f00f31bc5573b 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -244,8 +244,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) return -EINVAL; } - bdev = devm_kzalloc(dev, struct_size(bdev, data, pdata->nbuttons), - GFP_KERNEL); + bdev = devm_kzalloc_flex(dev, *bdev, data, pdata->nbuttons); if (!bdev) { dev_err(dev, "no memory for private data\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/imx-sm-bbm-key.c b/drivers/input/keyboard/imx-sm-bbm-key.c index 96486bd23d609d..ffe496c022a78f 100644 --- a/drivers/input/keyboard/imx-sm-bbm-key.c +++ b/drivers/input/keyboard/imx-sm-bbm-key.c @@ -166,7 +166,7 @@ static int scmi_imx_bbm_key_probe(struct scmi_device *sdev) if (!handle) return -ENODEV; - bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); + bbnsm = devm_kzalloc_obj(dev, *bbnsm); if (!bbnsm) return -ENOMEM; diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c index 6f6f99b28a2c75..0284ee60072750 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c @@ -432,7 +432,7 @@ static int imx_keypad_probe(struct platform_device *pdev) return -ENOMEM; } - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) { dev_err(&pdev->dev, "not enough memory for driver data\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/imx_sc_key.c b/drivers/input/keyboard/imx_sc_key.c index b620cd310cdb78..a575e4d787b075 100644 --- a/drivers/input/keyboard/imx_sc_key.c +++ b/drivers/input/keyboard/imx_sc_key.c @@ -114,7 +114,7 @@ static int imx_sc_key_probe(struct platform_device *pdev) struct input_dev *input; int error; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c index ebd991de70f818..ec43f7524119d5 100644 --- a/drivers/input/keyboard/ipaq-micro-keys.c +++ b/drivers/input/keyboard/ipaq-micro-keys.c @@ -93,7 +93,7 @@ static int micro_key_probe(struct platform_device *pdev) int error; int i; - keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); + keys = devm_kzalloc_obj(&pdev->dev, *keys); if (!keys) return -ENOMEM; diff --git a/drivers/input/keyboard/iqs62x-keys.c b/drivers/input/keyboard/iqs62x-keys.c index b086c7b28d5c10..4219bb021c451e 100644 --- a/drivers/input/keyboard/iqs62x-keys.c +++ b/drivers/input/keyboard/iqs62x-keys.c @@ -251,8 +251,7 @@ static int iqs62x_keys_probe(struct platform_device *pdev) struct input_dev *input; int ret, i; - iqs62x_keys = devm_kzalloc(&pdev->dev, sizeof(*iqs62x_keys), - GFP_KERNEL); + iqs62x_keys = devm_kzalloc_obj(&pdev->dev, *iqs62x_keys); if (!iqs62x_keys) return -ENOMEM; diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c index 7e35081393be19..40bc06fb909655 100644 --- a/drivers/input/keyboard/jornada680_kbd.c +++ b/drivers/input/keyboard/jornada680_kbd.c @@ -181,8 +181,7 @@ static int jornada680kbd_probe(struct platform_device *pdev) struct input_dev *input_dev; int i, error; - jornadakbd = devm_kzalloc(&pdev->dev, sizeof(struct jornadakbd), - GFP_KERNEL); + jornadakbd = devm_kzalloc_obj(&pdev->dev, struct jornadakbd); if (!jornadakbd) return -ENOMEM; diff --git a/drivers/input/keyboard/jornada720_kbd.c b/drivers/input/keyboard/jornada720_kbd.c index 26b579f0280fad..38d657e72ecf5d 100644 --- a/drivers/input/keyboard/jornada720_kbd.c +++ b/drivers/input/keyboard/jornada720_kbd.c @@ -95,7 +95,7 @@ static int jornada720_kbd_probe(struct platform_device *pdev) if (irq <= 0) return irq < 0 ? irq : -EINVAL; - jornadakbd = devm_kzalloc(&pdev->dev, sizeof(*jornadakbd), GFP_KERNEL); + jornadakbd = devm_kzalloc_obj(&pdev->dev, *jornadakbd); input_dev = devm_input_allocate_device(&pdev->dev); if (!jornadakbd || !input_dev) return -ENOMEM; diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c index 8eac63b2d30463..4b87d391291059 100644 --- a/drivers/input/keyboard/lm8323.c +++ b/drivers/input/keyboard/lm8323.c @@ -645,7 +645,7 @@ static int lm8323_probe(struct i2c_client *client) return -EINVAL; } - lm = devm_kzalloc(&client->dev, sizeof(*lm), GFP_KERNEL); + lm = devm_kzalloc_obj(&client->dev, *lm); if (!lm) return -ENOMEM; diff --git a/drivers/input/keyboard/lm8333.c b/drivers/input/keyboard/lm8333.c index 34be5b2e476dc6..c35b9db5d92b1e 100644 --- a/drivers/input/keyboard/lm8333.c +++ b/drivers/input/keyboard/lm8333.c @@ -142,7 +142,7 @@ static int lm8333_probe(struct i2c_client *client) return -EINVAL; } - lm8333 = devm_kzalloc(&client->dev, sizeof(*lm8333), GFP_KERNEL); + lm8333 = devm_kzalloc_obj(&client->dev, *lm8333); if (!lm8333) return -ENOMEM; diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c index 285d5c32fe70f7..6abc11b1049efd 100644 --- a/drivers/input/keyboard/lpc32xx-keys.c +++ b/drivers/input/keyboard/lpc32xx-keys.c @@ -167,8 +167,7 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - kscandat = devm_kzalloc(&pdev->dev, sizeof(*kscandat), - GFP_KERNEL); + kscandat = devm_kzalloc_obj(&pdev->dev, *kscandat); if (!kscandat) return -ENOMEM; diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index d14d1d7274870a..11018382e84ef9 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -397,7 +397,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) bool wakeup; int err; - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c index 94ebb875df1f9b..d2b8adcfc9e563 100644 --- a/drivers/input/keyboard/max7359_keypad.c +++ b/drivers/input/keyboard/max7359_keypad.c @@ -178,8 +178,7 @@ static int max7359_probe(struct i2c_client *client) dev_dbg(&client->dev, "keys FIFO is 0x%02x\n", ret); - keypad = devm_kzalloc(&client->dev, sizeof(struct max7359_keypad), - GFP_KERNEL); + keypad = devm_kzalloc_obj(&client->dev, struct max7359_keypad); if (!keypad) { dev_err(&client->dev, "failed to allocate memory\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/max7360-keypad.c b/drivers/input/keyboard/max7360-keypad.c index 1e5251f87f6fb9..11a78f93703902 100644 --- a/drivers/input/keyboard/max7360-keypad.c +++ b/drivers/input/keyboard/max7360-keypad.c @@ -234,7 +234,7 @@ static int max7360_keypad_probe(struct platform_device *pdev) if (irq < 0) return dev_err_probe(dev, irq, "Failed to get IRQ\n"); - max7360_keypad = devm_kzalloc(dev, sizeof(*max7360_keypad), GFP_KERNEL); + max7360_keypad = devm_kzalloc_obj(dev, *max7360_keypad); if (!max7360_keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 2044268343710f..06329cf5c7490f 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -208,7 +208,7 @@ static int mpr_touchkey_probe(struct i2c_client *client) if (vdd_uv < 0) return dev_err_probe(dev, vdd_uv, "failed to get vdd voltage\n"); - mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL); + mpr121 = devm_kzalloc_obj(dev, *mpr121); if (!mpr121) return -ENOMEM; diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c index e5eb025c5e9937..60e6ad97cf59aa 100644 --- a/drivers/input/keyboard/mt6779-keypad.c +++ b/drivers/input/keyboard/mt6779-keypad.c @@ -118,7 +118,7 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev) bool wakeup; int error; - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c index c78d9f6d97c4f7..6f14318f3b87c2 100644 --- a/drivers/input/keyboard/mtk-pmic-keys.c +++ b/drivers/input/keyboard/mtk-pmic-keys.c @@ -336,7 +336,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev) const struct of_device_id *of_id = of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev); - keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); + keys = devm_kzalloc_obj(&pdev->dev, *keys); if (!keys) return -ENOMEM; diff --git a/drivers/input/keyboard/nspire-keypad.c b/drivers/input/keyboard/nspire-keypad.c index 096c18d7bca115..6d9016af5c6b4a 100644 --- a/drivers/input/keyboard/nspire-keypad.c +++ b/drivers/input/keyboard/nspire-keypad.c @@ -155,8 +155,7 @@ static int nspire_keypad_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - keypad = devm_kzalloc(&pdev->dev, sizeof(struct nspire_keypad), - GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, struct nspire_keypad); if (!keypad) { dev_err(&pdev->dev, "failed to allocate keypad memory\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index e783244d0c9109..bf652b0f479dfc 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -352,7 +352,7 @@ static int omap4_keypad_probe(struct platform_device *pdev) if (irq < 0) return irq; - keypad_data = devm_kzalloc(dev, sizeof(*keypad_data), GFP_KERNEL); + keypad_data = devm_kzalloc_obj(dev, *keypad_data); if (!keypad_data) { dev_err(dev, "keypad_data memory allocation failed\n"); return -ENOMEM; @@ -427,10 +427,8 @@ static int omap4_keypad_probe(struct platform_device *pdev) keypad_data->row_shift = get_count_order(keypad_data->cols); max_keys = keypad_data->rows << keypad_data->row_shift; - keypad_data->keymap = devm_kcalloc(dev, - max_keys, - sizeof(keypad_data->keymap[0]), - GFP_KERNEL); + keypad_data->keymap = devm_kzalloc_objs(dev, keypad_data->keymap[0], + max_keys); if (!keypad_data->keymap) { dev_err(dev, "Not enough memory for keymap\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c index 7ffe1a70c85664..374997f35f017e 100644 --- a/drivers/input/keyboard/opencores-kbd.c +++ b/drivers/input/keyboard/opencores-kbd.c @@ -45,8 +45,7 @@ static int opencores_kbd_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - opencores_kbd = devm_kzalloc(&pdev->dev, sizeof(*opencores_kbd), - GFP_KERNEL); + opencores_kbd = devm_kzalloc_obj(&pdev->dev, *opencores_kbd); if (!opencores_kbd) return -ENOMEM; diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c index 86f21045c69bd9..b4a02ade3a804c 100644 --- a/drivers/input/keyboard/pinephone-keyboard.c +++ b/drivers/input/keyboard/pinephone-keyboard.c @@ -365,7 +365,7 @@ static int ppkb_probe(struct i2c_client *client) if (error) return error; - ppkb = devm_kzalloc(dev, sizeof(*ppkb), GFP_KERNEL); + ppkb = devm_kzalloc_obj(dev, *ppkb); if (!ppkb) return -ENOMEM; diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c index c916e80e2f5879..a929f2c75854c3 100644 --- a/drivers/input/keyboard/pmic8xxx-keypad.c +++ b/drivers/input/keyboard/pmic8xxx-keypad.c @@ -517,7 +517,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev) /* legacy name */ of_property_read_bool(np, "linux,keypad-wakeup"); - kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); + kp = devm_kzalloc_obj(&pdev->dev, *kp); if (!kp) return -ENOMEM; diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c index 059bce760401a9..0a5b6a97bac3e6 100644 --- a/drivers/input/keyboard/pxa27x_keypad.c +++ b/drivers/input/keyboard/pxa27x_keypad.c @@ -619,8 +619,7 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) if (irq < 0) return -ENXIO; - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), - GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, *keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/qt1050.c b/drivers/input/keyboard/qt1050.c index c6ab8e501f83eb..98611d126d4b08 100644 --- a/drivers/input/keyboard/qt1050.c +++ b/drivers/input/keyboard/qt1050.c @@ -446,7 +446,7 @@ static int qt1050_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c index e31cb115a9548b..b21b6d36fcc03c 100644 --- a/drivers/input/keyboard/qt1070.c +++ b/drivers/input/keyboard/qt1070.c @@ -148,8 +148,7 @@ static int qt1070_probe(struct i2c_client *client) if (!qt1070_identify(client)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct qt1070_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct qt1070_data); if (!data) return -ENOMEM; diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c index e64adaca10ffe1..e045475dbc5f27 100644 --- a/drivers/input/keyboard/qt2160.c +++ b/drivers/input/keyboard/qt2160.c @@ -322,7 +322,7 @@ static int qt2160_probe(struct i2c_client *client) return -ENODEV; /* Chip is valid and active. Allocate structure */ - qt2160 = devm_kzalloc(&client->dev, sizeof(*qt2160), GFP_KERNEL); + qt2160 = devm_kzalloc_obj(&client->dev, *qt2160); if (!qt2160) return -ENOMEM; diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index f56c5249401de8..021d6cb6863f74 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -299,10 +299,8 @@ static int samsung_keypad_probe(struct platform_device *pdev) row_shift = get_count_order(num_cols); - keypad = devm_kzalloc(&pdev->dev, - struct_size(keypad, keycodes, - num_rows << row_shift), - GFP_KERNEL); + keypad = devm_kzalloc_flex(&pdev->dev, *keypad, keycodes, + num_rows << row_shift); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/snvs_pwrkey.c b/drivers/input/keyboard/snvs_pwrkey.c index 72d43d8deb78f1..33bc3bd0b222ad 100644 --- a/drivers/input/keyboard/snvs_pwrkey.c +++ b/drivers/input/keyboard/snvs_pwrkey.c @@ -163,7 +163,7 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) if (!np) return dev_err_probe(dev, -ENODEV, "Device tree node not found\n"); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c index 53f3ac64c980cc..6e2b35349dc408 100644 --- a/drivers/input/keyboard/spear-keyboard.c +++ b/drivers/input/keyboard/spear-keyboard.c @@ -153,7 +153,7 @@ static int spear_kbd_probe(struct platform_device *pdev) if (irq < 0) return irq; - kbd = devm_kzalloc(&pdev->dev, sizeof(*kbd), GFP_KERNEL); + kbd = devm_kzalloc_obj(&pdev->dev, *kbd); if (!kbd) { dev_err(&pdev->dev, "not enough memory for driver data\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/st-keyscan.c b/drivers/input/keyboard/st-keyscan.c index 2fbdf373fe9902..977685e6262506 100644 --- a/drivers/input/keyboard/st-keyscan.c +++ b/drivers/input/keyboard/st-keyscan.c @@ -136,8 +136,7 @@ static int keyscan_probe(struct platform_device *pdev) return -EINVAL; } - keypad_data = devm_kzalloc(&pdev->dev, sizeof(*keypad_data), - GFP_KERNEL); + keypad_data = devm_kzalloc_obj(&pdev->dev, *keypad_data); if (!keypad_data) return -ENOMEM; diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c index bc5d0217be5c08..c295caeecfe0bc 100644 --- a/drivers/input/keyboard/stmpe-keypad.c +++ b/drivers/input/keyboard/stmpe-keypad.c @@ -343,8 +343,7 @@ static int stmpe_keypad_probe(struct platform_device *pdev) if (irq < 0) return irq; - keypad = devm_kzalloc(&pdev->dev, sizeof(struct stmpe_keypad), - GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, struct stmpe_keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c index 5730f08f82d79a..05983db3f0d37a 100644 --- a/drivers/input/keyboard/sun4i-lradc-keys.c +++ b/drivers/input/keyboard/sun4i-lradc-keys.c @@ -215,9 +215,8 @@ static int sun4i_lradc_load_dt_keymap(struct device *dev, return -EINVAL; } - lradc->chan0_map = devm_kmalloc_array(dev, lradc->chan0_map_count, - sizeof(struct sun4i_lradc_keymap), - GFP_KERNEL); + lradc->chan0_map = devm_kmalloc_objs(dev, struct sun4i_lradc_keymap, + lradc->chan0_map_count); if (!lradc->chan0_map) return -ENOMEM; @@ -256,7 +255,7 @@ static int sun4i_lradc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int error, i, irq; - lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL); + lradc = devm_kzalloc_obj(dev, struct sun4i_lradc_data); if (!lradc) return -ENOMEM; diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c index 137f9fa554f0bf..b9232969310c0b 100644 --- a/drivers/input/keyboard/tc3589x-keypad.c +++ b/drivers/input/keyboard/tc3589x-keypad.c @@ -329,7 +329,7 @@ tc3589x_keypad_of_probe(struct device *dev) if (!np) return ERR_PTR(-ENODEV); - plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(dev, *plat); if (!plat) return ERR_PTR(-ENOMEM); @@ -388,8 +388,7 @@ static int tc3589x_keypad_probe(struct platform_device *pdev) if (irq < 0) return irq; - keypad = devm_kzalloc(&pdev->dev, sizeof(struct tc_keypad), - GFP_KERNEL); + keypad = devm_kzalloc_obj(&pdev->dev, struct tc_keypad); if (!keypad) return -ENOMEM; diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c index 4616afa0286c3a..363a48098dfbb8 100644 --- a/drivers/input/keyboard/tca8418_keypad.c +++ b/drivers/input/keyboard/tca8418_keypad.c @@ -293,7 +293,7 @@ static int tca8418_keypad_probe(struct i2c_client *client) row_shift = get_count_order(cols); /* Allocate memory for keypad_data and input device */ - keypad_data = devm_kzalloc(dev, sizeof(*keypad_data), GFP_KERNEL); + keypad_data = devm_kzalloc_obj(dev, *keypad_data); if (!keypad_data) return -ENOMEM; diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c index e6177f2bdf8d2d..d0ca6b747b6da1 100644 --- a/drivers/input/keyboard/tegra-kbc.c +++ b/drivers/input/keyboard/tegra-kbc.c @@ -578,7 +578,7 @@ static int tegra_kbc_probe(struct platform_device *pdev) unsigned int scan_time_rows; unsigned int keymap_rows; - kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); + kbc = devm_kzalloc_obj(&pdev->dev, *kbc); if (!kbc) { dev_err(&pdev->dev, "failed to alloc memory for kbc\n"); return -ENOMEM; diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c index 967bbe553c0608..2f5ea04a460243 100644 --- a/drivers/input/keyboard/tm2-touchkey.c +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -193,7 +193,7 @@ static int tm2_touchkey_probe(struct i2c_client *client) return -EIO; } - touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); + touchkey = devm_kzalloc_obj(&client->dev, *touchkey); if (!touchkey) return -ENOMEM; diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c index 5e3d17c5dc9bdf..4bb34e337d8e88 100644 --- a/drivers/input/keyboard/twl4030_keypad.c +++ b/drivers/input/keyboard/twl4030_keypad.c @@ -322,7 +322,7 @@ static int twl4030_kp_probe(struct platform_device *pdev) u8 reg; int error; - kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); + kp = devm_kzalloc_obj(&pdev->dev, *kp); if (!kp) return -ENOMEM; diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c index e4227e96aa4e7d..0724c445ab5985 100644 --- a/drivers/input/matrix-keymap.c +++ b/drivers/input/matrix-keymap.c @@ -162,9 +162,8 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, return -EINVAL; if (!keymap) { - keymap = devm_kcalloc(input_dev->dev.parent, - max_keys, sizeof(*keymap), - GFP_KERNEL); + keymap = devm_kzalloc_objs(input_dev->dev.parent, *keymap, + max_keys); if (!keymap) { dev_err(input_dev->dev.parent, "Unable to allocate memory for keymap"); diff --git a/drivers/input/misc/88pm860x_onkey.c b/drivers/input/misc/88pm860x_onkey.c index 2d398119a620f1..813bfb840ac695 100644 --- a/drivers/input/misc/88pm860x_onkey.c +++ b/drivers/input/misc/88pm860x_onkey.c @@ -67,8 +67,7 @@ static int pm860x_onkey_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_onkey_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct pm860x_onkey_info); if (!info) return -ENOMEM; info->chip = chip; diff --git a/drivers/input/misc/88pm886-onkey.c b/drivers/input/misc/88pm886-onkey.c index 284ff5190b6eb7..01668ee33b16b7 100644 --- a/drivers/input/misc/88pm886-onkey.c +++ b/drivers/input/misc/88pm886-onkey.c @@ -42,7 +42,7 @@ static int pm886_onkey_probe(struct platform_device *pdev) struct input_dev *idev; int irq, err; - onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(dev, *onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c index 4ace4739eee267..b631f18ef8cfe6 100644 --- a/drivers/input/misc/ab8500-ponkey.c +++ b/drivers/input/misc/ab8500-ponkey.c @@ -62,8 +62,7 @@ static int ab8500_ponkey_probe(struct platform_device *pdev) if (irq_dbr < 0) return irq_dbr; - ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey), - GFP_KERNEL); + ponkey = devm_kzalloc_obj(&pdev->dev, struct ab8500_ponkey); if (!ponkey) return -ENOMEM; diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c index ac7674647c0928..2dc9fd1b5c6aeb 100644 --- a/drivers/input/misc/adxl34x.c +++ b/drivers/input/misc/adxl34x.c @@ -695,7 +695,7 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq, return ERR_PTR(-ENODEV); } - ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL); + ac = devm_kzalloc_obj(dev, *ac); if (!ac) return ERR_PTR(-ENOMEM); diff --git a/drivers/input/misc/apanel.c b/drivers/input/misc/apanel.c index 3eb02a64acfb48..0edc8a2cd2dc51 100644 --- a/drivers/input/misc/apanel.c +++ b/drivers/input/misc/apanel.c @@ -127,7 +127,7 @@ static int apanel_probe(struct i2c_client *client) u8 cmd = device_chip[APANEL_DEV_APPBTN] == CHIP_OZ992C ? 0 : 8; int i, err; - ap = devm_kzalloc(&client->dev, sizeof(*ap), GFP_KERNEL); + ap = devm_kzalloc_obj(&client->dev, *ap); if (!ap) return -ENOMEM; diff --git a/drivers/input/misc/ariel-pwrbutton.c b/drivers/input/misc/ariel-pwrbutton.c index e22f8985e7eb4f..986e8a38196ded 100644 --- a/drivers/input/misc/ariel-pwrbutton.c +++ b/drivers/input/misc/ariel-pwrbutton.c @@ -102,7 +102,7 @@ static int ariel_pwrbutton_probe(struct spi_device *spi) return -EINVAL; } - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c index bb1544d63c5165..cae4c3f0da9b7c 100644 --- a/drivers/input/misc/arizona-haptics.c +++ b/drivers/input/misc/arizona-haptics.c @@ -151,7 +151,7 @@ static int arizona_haptics_probe(struct platform_device *pdev) struct arizona_haptics *haptics; int ret; - haptics = devm_kzalloc(&pdev->dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc_obj(&pdev->dev, *haptics); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c index 999aabf9dcbd0a..587c797d3ae4eb 100644 --- a/drivers/input/misc/atc260x-onkey.c +++ b/drivers/input/misc/atc260x-onkey.c @@ -196,7 +196,7 @@ static int atc260x_onkey_probe(struct platform_device *pdev) u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0; int val, error; - onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(&pdev->dev, *onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c index e77e53ee9d41d0..1fa7ee6343ebf6 100644 --- a/drivers/input/misc/atlas_btns.c +++ b/drivers/input/misc/atlas_btns.c @@ -74,7 +74,7 @@ static int atlas_acpi_button_probe(struct platform_device *pdev) if (!device) return -ENODEV; - atlas = devm_kzalloc(&pdev->dev, sizeof(*atlas), GFP_KERNEL); + atlas = devm_kzalloc_obj(&pdev->dev, *atlas); if (!atlas) return -ENOMEM; diff --git a/drivers/input/misc/atmel_captouch.c b/drivers/input/misc/atmel_captouch.c index fc4abea68479f0..45a9eb7561f216 100644 --- a/drivers/input/misc/atmel_captouch.c +++ b/drivers/input/misc/atmel_captouch.c @@ -177,7 +177,7 @@ static int atmel_captouch_probe(struct i2c_client *client) return -EINVAL; } - capdev = devm_kzalloc(dev, sizeof(*capdev), GFP_KERNEL); + capdev = devm_kzalloc_obj(dev, *capdev); if (!capdev) return -ENOMEM; diff --git a/drivers/input/misc/aw86927.c b/drivers/input/misc/aw86927.c index f53b8f004cb369..0657c52b4c7970 100644 --- a/drivers/input/misc/aw86927.c +++ b/drivers/input/misc/aw86927.c @@ -766,7 +766,7 @@ static int aw86927_probe(struct i2c_client *client) struct aw86927_data *haptics; int err; - haptics = devm_kzalloc(&client->dev, sizeof(struct aw86927_data), GFP_KERNEL); + haptics = devm_kzalloc_obj(&client->dev, struct aw86927_data); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c index c34e002258ee45..cbbc9db33ad2c0 100644 --- a/drivers/input/misc/axp20x-pek.c +++ b/drivers/input/misc/axp20x-pek.c @@ -306,8 +306,7 @@ static int axp20x_pek_probe(struct platform_device *pdev) return -EINVAL; } - axp20x_pek = devm_kzalloc(&pdev->dev, sizeof(struct axp20x_pek), - GFP_KERNEL); + axp20x_pek = devm_kzalloc_obj(&pdev->dev, struct axp20x_pek); if (!axp20x_pek) return -ENOMEM; diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index 0ef282932095bc..16aecc9b5ef4b5 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -435,7 +435,7 @@ static int bma150_probe(struct i2c_client *client) return -EINVAL; } - bma150 = devm_kzalloc(&client->dev, sizeof(*bma150), GFP_KERNEL); + bma150 = devm_kzalloc_obj(&client->dev, *bma150); if (!bma150) return -ENOMEM; diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c index b1624f5414ee60..aebfec8f8618c0 100644 --- a/drivers/input/misc/cobalt_btns.c +++ b/drivers/input/misc/cobalt_btns.c @@ -65,7 +65,7 @@ static int cobalt_buttons_probe(struct platform_device *pdev) struct resource *res; int error, i; - bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL); + bdev = devm_kzalloc_obj(&pdev->dev, *bdev); if (!bdev) return -ENOMEM; diff --git a/drivers/input/misc/cpcap-pwrbutton.c b/drivers/input/misc/cpcap-pwrbutton.c index 85cddb84717aea..89b92612ddd801 100644 --- a/drivers/input/misc/cpcap-pwrbutton.c +++ b/drivers/input/misc/cpcap-pwrbutton.c @@ -53,7 +53,7 @@ static int cpcap_power_button_probe(struct platform_device *pdev) if (irq < 0) return irq; - button = devm_kmalloc(&pdev->dev, sizeof(*button), GFP_KERNEL); + button = devm_kmalloc_obj(&pdev->dev, *button); if (!button) return -ENOMEM; diff --git a/drivers/input/misc/cs40l50-vibra.c b/drivers/input/misc/cs40l50-vibra.c index 7ef4534fea2fb0..f95092eccd9295 100644 --- a/drivers/input/misc/cs40l50-vibra.c +++ b/drivers/input/misc/cs40l50-vibra.c @@ -493,7 +493,7 @@ static int cs40l50_vibra_probe(struct platform_device *pdev) struct cs40l50_vibra *vib; int error; - vib = devm_kzalloc(pdev->dev.parent, sizeof(*vib), GFP_KERNEL); + vib = devm_kzalloc_obj(pdev->dev.parent, *vib); if (!vib) return -ENOMEM; diff --git a/drivers/input/misc/da7280.c b/drivers/input/misc/da7280.c index e607836efb500c..995d3f7af41a15 100644 --- a/drivers/input/misc/da7280.c +++ b/drivers/input/misc/da7280.c @@ -1153,7 +1153,7 @@ static int da7280_probe(struct i2c_client *client) return -EINVAL; } - haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc_obj(dev, *haptics); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/da9055_onkey.c b/drivers/input/misc/da9055_onkey.c index 3e4fc2f010119e..e2cc101e4c12bb 100644 --- a/drivers/input/misc/da9055_onkey.c +++ b/drivers/input/misc/da9055_onkey.c @@ -79,7 +79,7 @@ static int da9055_onkey_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(&pdev->dev, *onkey); if (!onkey) { dev_err(&pdev->dev, "Failed to allocate memory\n"); return -ENOMEM; diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c index 830714241788ca..98297ca1dc12aa 100644 --- a/drivers/input/misc/da9063_onkey.c +++ b/drivers/input/misc/da9063_onkey.c @@ -183,8 +183,7 @@ static int da9063_onkey_probe(struct platform_device *pdev) int error; int irq; - onkey = devm_kzalloc(&pdev->dev, sizeof(struct da9063_onkey), - GFP_KERNEL); + onkey = devm_kzalloc_obj(&pdev->dev, struct da9063_onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c index 8a3d74d65d63bd..ecc47d90eff376 100644 --- a/drivers/input/misc/drv260x.c +++ b/drivers/input/misc/drv260x.c @@ -448,7 +448,7 @@ static int drv260x_probe(struct i2c_client *client) u32 voltage; int error; - haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc_obj(dev, *haptics); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/drv2665.c b/drivers/input/misc/drv2665.c index 134d65fdcf2d29..90407f8797c7ca 100644 --- a/drivers/input/misc/drv2665.c +++ b/drivers/input/misc/drv2665.c @@ -161,7 +161,7 @@ static int drv2665_probe(struct i2c_client *client) struct drv2665_data *haptics; int error; - haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc_obj(&client->dev, *haptics); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/drv2667.c b/drivers/input/misc/drv2667.c index bbda7b4cbdcba3..18cf689d7ef780 100644 --- a/drivers/input/misc/drv2667.c +++ b/drivers/input/misc/drv2667.c @@ -338,7 +338,7 @@ static int drv2667_probe(struct i2c_client *client) struct drv2667_data *haptics; int error; - haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc_obj(&client->dev, *haptics); if (!haptics) return -ENOMEM; diff --git a/drivers/input/misc/gpio-beeper.c b/drivers/input/misc/gpio-beeper.c index 3d65cb4f4ef32c..cdfa454b5d3741 100644 --- a/drivers/input/misc/gpio-beeper.c +++ b/drivers/input/misc/gpio-beeper.c @@ -63,7 +63,7 @@ static int gpio_beeper_probe(struct platform_device *pdev) struct gpio_beeper *beep; struct input_dev *input; - beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); + beep = devm_kzalloc_obj(&pdev->dev, *beep); if (!beep) return -ENOMEM; diff --git a/drivers/input/misc/gpio-vibra.c b/drivers/input/misc/gpio-vibra.c index ad44b4d18a2a16..5e83d246dbc1a4 100644 --- a/drivers/input/misc/gpio-vibra.c +++ b/drivers/input/misc/gpio-vibra.c @@ -104,7 +104,7 @@ static int gpio_vibrator_probe(struct platform_device *pdev) struct gpio_vibrator *vibrator; int err; - vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL); + vibrator = devm_kzalloc_obj(&pdev->dev, *vibrator); if (!vibrator) return -ENOMEM; diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c index 0e4a49845afad4..f4e620ac16a317 100644 --- a/drivers/input/misc/gpio_decoder.c +++ b/drivers/input/misc/gpio_decoder.c @@ -63,7 +63,7 @@ static int gpio_decoder_probe(struct platform_device *pdev) u32 max; int err; - decoder = devm_kzalloc(dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(dev, *decoder); if (!decoder) return -ENOMEM; diff --git a/drivers/input/misc/ibm-panel.c b/drivers/input/misc/ibm-panel.c index aa48f62d7ea054..fb5721286a820d 100644 --- a/drivers/input/misc/ibm-panel.c +++ b/drivers/input/misc/ibm-panel.c @@ -122,7 +122,7 @@ static int ibm_panel_probe(struct i2c_client *client) int i; int error; - panel = devm_kzalloc(&client->dev, sizeof(*panel), GFP_KERNEL); + panel = devm_kzalloc_obj(&client->dev, *panel); if (!panel) return -ENOMEM; diff --git a/drivers/input/misc/iqs269a.c b/drivers/input/misc/iqs269a.c index 7a576f65bfcac0..fdac1ad441d962 100644 --- a/drivers/input/misc/iqs269a.c +++ b/drivers/input/misc/iqs269a.c @@ -1813,7 +1813,7 @@ static int iqs269_probe(struct i2c_client *client) struct iqs269_private *iqs269; int error; - iqs269 = devm_kzalloc(&client->dev, sizeof(*iqs269), GFP_KERNEL); + iqs269 = devm_kzalloc_obj(&client->dev, *iqs269); if (!iqs269) return -ENOMEM; diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c index bc50dfba9e6c55..ad7d4d01cfcbdc 100644 --- a/drivers/input/misc/iqs626a.c +++ b/drivers/input/misc/iqs626a.c @@ -1630,7 +1630,7 @@ static int iqs626_probe(struct i2c_client *client) struct iqs626_private *iqs626; int error; - iqs626 = devm_kzalloc(&client->dev, sizeof(*iqs626), GFP_KERNEL); + iqs626 = devm_kzalloc_obj(&client->dev, *iqs626); if (!iqs626) return -ENOMEM; diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c index ace48948273436..0671542ef8ded5 100644 --- a/drivers/input/misc/iqs7222.c +++ b/drivers/input/misc/iqs7222.c @@ -1888,7 +1888,7 @@ static int iqs7222_dev_init(struct iqs7222_private *iqs7222, int dir) if (!val) continue; - val_buf = kcalloc(num_col, sizeof(__le16), GFP_KERNEL); + val_buf = kzalloc_objs(__le16, num_col); if (!val_buf) return -ENOMEM; @@ -3056,7 +3056,7 @@ static int iqs7222_probe(struct i2c_client *client) unsigned long irq_flags; int error, irq; - iqs7222 = devm_kzalloc(&client->dev, sizeof(*iqs7222), GFP_KERNEL); + iqs7222 = devm_kzalloc_obj(&client->dev, *iqs7222); if (!iqs7222) return -ENOMEM; diff --git a/drivers/input/misc/isa1200.c b/drivers/input/misc/isa1200.c index 926cffcd38d675..8885c13c57d52a 100644 --- a/drivers/input/misc/isa1200.c +++ b/drivers/input/misc/isa1200.c @@ -435,7 +435,7 @@ static int isa1200_probe(struct i2c_client *client) struct device *dev = &client->dev; int err; - isa = devm_kzalloc(dev, sizeof(*isa), GFP_KERNEL); + isa = devm_kzalloc_obj(dev, *isa); if (!isa) return -ENOMEM; diff --git a/drivers/input/misc/kxtj9.c b/drivers/input/misc/kxtj9.c index 6b3495ba576325..64f8b9fad2fa6d 100644 --- a/drivers/input/misc/kxtj9.c +++ b/drivers/input/misc/kxtj9.c @@ -411,7 +411,7 @@ static int kxtj9_probe(struct i2c_client *client) return -EINVAL; } - tj9 = devm_kzalloc(&client->dev, sizeof(*tj9), GFP_KERNEL); + tj9 = devm_kzalloc_obj(&client->dev, *tj9); if (!tj9) { dev_err(&client->dev, "failed to allocate memory for module data\n"); diff --git a/drivers/input/misc/max7360-rotary.c b/drivers/input/misc/max7360-rotary.c index 385831ef34b633..d262931be963c8 100644 --- a/drivers/input/misc/max7360-rotary.c +++ b/drivers/input/misc/max7360-rotary.c @@ -113,7 +113,7 @@ static int max7360_rotary_probe(struct platform_device *pdev) if (irq < 0) return dev_err_probe(dev, irq, "Failed to get IRQ\n"); - max7360_rotary = devm_kzalloc(dev, sizeof(*max7360_rotary), GFP_KERNEL); + max7360_rotary = devm_kzalloc_obj(dev, *max7360_rotary); if (!max7360_rotary) return -ENOMEM; diff --git a/drivers/input/misc/max77650-onkey.c b/drivers/input/misc/max77650-onkey.c index ee55f22dbca540..b0fd04076779b7 100644 --- a/drivers/input/misc/max77650-onkey.c +++ b/drivers/input/misc/max77650-onkey.c @@ -57,7 +57,7 @@ static int max77650_onkey_probe(struct platform_device *pdev) if (!map) return -ENODEV; - onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(dev, *onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c index 10325c1296da86..96d6d4620eb4db 100644 --- a/drivers/input/misc/max77693-haptic.c +++ b/drivers/input/misc/max77693-haptic.c @@ -306,7 +306,7 @@ static int max77693_haptic_probe(struct platform_device *pdev) struct max77693_haptic *haptic; int error; - haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); + haptic = devm_kzalloc_obj(&pdev->dev, *haptic); if (!haptic) return -ENOMEM; diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c index d185b3ca353d91..7f9c3ebf44b4d5 100644 --- a/drivers/input/misc/max8925_onkey.c +++ b/drivers/input/misc/max8925_onkey.c @@ -78,8 +78,7 @@ static int max8925_onkey_probe(struct platform_device *pdev) if (irq[1] < 0) return -EINVAL; - info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_onkey_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8925_onkey_info); if (!info) return -ENOMEM; diff --git a/drivers/input/misc/nxp-bbnsm-pwrkey.c b/drivers/input/misc/nxp-bbnsm-pwrkey.c index 0c7b8f8ef4a550..ef823efb2da073 100644 --- a/drivers/input/misc/nxp-bbnsm-pwrkey.c +++ b/drivers/input/misc/nxp-bbnsm-pwrkey.c @@ -115,7 +115,7 @@ static int bbnsm_pwrkey_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int error; - bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); + bbnsm = devm_kzalloc_obj(&pdev->dev, *bbnsm); if (!bbnsm) return -ENOMEM; diff --git a/drivers/input/misc/pf1550-onkey.c b/drivers/input/misc/pf1550-onkey.c index 0d1b570bbe4798..72aac83e90544e 100644 --- a/drivers/input/misc/pf1550-onkey.c +++ b/drivers/input/misc/pf1550-onkey.c @@ -64,7 +64,7 @@ static int pf1550_onkey_probe(struct platform_device *pdev) bool key_power = false; int i, irq, error; - onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(&pdev->dev, *onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c index 53249d2c081fba..34b4afbb1984bd 100644 --- a/drivers/input/misc/pm8941-pwrkey.c +++ b/drivers/input/misc/pm8941-pwrkey.c @@ -263,7 +263,7 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev) pull_up = of_property_read_bool(pdev->dev.of_node, "bias-pull-up"); - pwrkey = devm_kzalloc(&pdev->dev, sizeof(*pwrkey), GFP_KERNEL); + pwrkey = devm_kzalloc_obj(&pdev->dev, *pwrkey); if (!pwrkey) return -ENOMEM; diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c index 381b064732791f..03a77443e0bea0 100644 --- a/drivers/input/misc/pm8xxx-vibrator.c +++ b/drivers/input/misc/pm8xxx-vibrator.c @@ -207,7 +207,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) unsigned int val, reg_base = 0; const struct pm8xxx_regs *regs; - vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL); + vib = devm_kzalloc_obj(&pdev->dev, *vib); if (!vib) return -ENOMEM; diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c index c406a1cca5c443..933b28b8b81ede 100644 --- a/drivers/input/misc/pmic8xxx-pwrkey.c +++ b/drivers/input/misc/pmic8xxx-pwrkey.c @@ -358,7 +358,7 @@ static int pmic8xxx_pwrkey_probe(struct platform_device *pdev) return -ENODEV; } - pwrkey = devm_kzalloc(&pdev->dev, sizeof(*pwrkey), GFP_KERNEL); + pwrkey = devm_kzalloc_obj(&pdev->dev, *pwrkey); if (!pwrkey) return -ENOMEM; diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 0e19e97d98ec27..1287d1d557a72d 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -127,7 +127,7 @@ static int pwm_beeper_probe(struct platform_device *pdev) u32 bell_frequency; int error; - beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); + beeper = devm_kzalloc_obj(dev, *beeper); if (!beeper) return -ENOMEM; diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c index 53ca3b1d736000..1e7cc8bd9f6b3d 100644 --- a/drivers/input/misc/pwm-vibra.c +++ b/drivers/input/misc/pwm-vibra.c @@ -131,7 +131,7 @@ static int pwm_vibrator_probe(struct platform_device *pdev) struct pwm_state state; int err; - vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL); + vibrator = devm_kzalloc_obj(&pdev->dev, *vibrator); if (!vibrator) return -ENOMEM; diff --git a/drivers/input/misc/qnap-mcu-input.c b/drivers/input/misc/qnap-mcu-input.c index 3be899bfc1145f..fa7ad9b9a134f2 100644 --- a/drivers/input/misc/qnap-mcu-input.c +++ b/drivers/input/misc/qnap-mcu-input.c @@ -97,7 +97,7 @@ static int qnap_mcu_input_probe(struct platform_device *pdev) struct input_dev *input; int ret; - idev = devm_kzalloc(dev, sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc_obj(dev, *idev); if (!idev) return -ENOMEM; diff --git a/drivers/input/misc/rave-sp-pwrbutton.c b/drivers/input/misc/rave-sp-pwrbutton.c index bcab3cdb7ebdaf..ebe3d1f7dfb2f4 100644 --- a/drivers/input/misc/rave-sp-pwrbutton.c +++ b/drivers/input/misc/rave-sp-pwrbutton.c @@ -45,7 +45,7 @@ static int rave_sp_pwrbutton_probe(struct platform_device *pdev) struct input_dev *idev; int error; - pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL); + pb = devm_kzalloc_obj(dev, *pb); if (!pb) return -ENOMEM; diff --git a/drivers/input/misc/rb532_button.c b/drivers/input/misc/rb532_button.c index 40173bf7a23504..63aa1190b8067d 100644 --- a/drivers/input/misc/rb532_button.c +++ b/drivers/input/misc/rb532_button.c @@ -68,7 +68,7 @@ static int rb532_button_probe(struct platform_device *pdev) struct input_dev *input; int error; - button = devm_kzalloc(&pdev->dev, sizeof(*button), GFP_KERNEL); + button = devm_kzalloc_obj(&pdev->dev, *button); if (!button) return -ENOMEM; diff --git a/drivers/input/misc/regulator-haptic.c b/drivers/input/misc/regulator-haptic.c index bd26c8e1b33895..b1aa3488ed6c97 100644 --- a/drivers/input/misc/regulator-haptic.c +++ b/drivers/input/misc/regulator-haptic.c @@ -146,7 +146,7 @@ static int regulator_haptic_probe(struct platform_device *pdev) struct input_dev *input_dev; int error; - haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); + haptic = devm_kzalloc_obj(&pdev->dev, *haptic); if (!haptic) return -ENOMEM; diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index f706e199741719..6c932e46edb338 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -185,7 +185,7 @@ static int rotary_encoder_probe(struct platform_device *pdev) unsigned int i; int err; - encoder = devm_kzalloc(dev, sizeof(struct rotary_encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(dev, struct rotary_encoder); if (!encoder) return -ENOMEM; @@ -270,9 +270,7 @@ static int rotary_encoder_probe(struct platform_device *pdev) } encoder->irq = - devm_kcalloc(dev, - encoder->gpios->ndescs, sizeof(*encoder->irq), - GFP_KERNEL); + devm_kzalloc_objs(dev, *encoder->irq, encoder->gpios->ndescs); if (!encoder->irq) return -ENOMEM; diff --git a/drivers/input/misc/rt5120-pwrkey.c b/drivers/input/misc/rt5120-pwrkey.c index 2262f5057d9f5f..dce93078d4cc68 100644 --- a/drivers/input/misc/rt5120-pwrkey.c +++ b/drivers/input/misc/rt5120-pwrkey.c @@ -44,7 +44,7 @@ static int rt5120_pwrkey_probe(struct platform_device *pdev) int press_irq, release_irq; int error; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/misc/sc27xx-vibra.c b/drivers/input/misc/sc27xx-vibra.c index 7590f3a91db881..56d0a825e2446b 100644 --- a/drivers/input/misc/sc27xx-vibra.c +++ b/drivers/input/misc/sc27xx-vibra.c @@ -123,7 +123,7 @@ static int sc27xx_vibra_probe(struct platform_device *pdev) return -EINVAL; } - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/input/misc/sgi_btns.c b/drivers/input/misc/sgi_btns.c index 39c2882b8e1a29..e8602623f20361 100644 --- a/drivers/input/misc/sgi_btns.c +++ b/drivers/input/misc/sgi_btns.c @@ -81,7 +81,7 @@ static int sgi_buttons_probe(struct platform_device *pdev) struct input_dev *input; int error, i; - bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL); + bdev = devm_kzalloc_obj(&pdev->dev, *bdev); if (!bdev) return -ENOMEM; diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c index dbf86ea778e676..863e9d8c23ec6e 100644 --- a/drivers/input/misc/soc_button_array.c +++ b/drivers/input/misc/soc_button_array.c @@ -400,8 +400,8 @@ static struct soc_button_info *soc_button_get_button_info(struct device *dev) } /* There are package.count - 1 buttons + 1 terminating empty entry */ - button_info = devm_kcalloc(dev, btns_desc->package.count, - sizeof(*button_info), GFP_KERNEL); + button_info = devm_kzalloc_objs(dev, *button_info, + btns_desc->package.count); if (!button_info) { button_info = ERR_PTR(-ENOMEM); goto out; @@ -465,7 +465,7 @@ static int soc_button_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index 1cfadd73829f83..c7225e3733b812 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c @@ -194,7 +194,7 @@ static int bbc_beep_probe(struct platform_device *op) struct bbc_beep_info *info; int err; - state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&op->dev, *state); if (!state) return -ENOMEM; @@ -265,7 +265,7 @@ static int grover_beep_probe(struct platform_device *op) struct grover_beep_info *info; int err = -ENOMEM; - state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&op->dev, *state); if (!state) return err; diff --git a/drivers/input/misc/stpmic1_onkey.c b/drivers/input/misc/stpmic1_onkey.c index d5ebca7b90a594..a02261cf467d1c 100644 --- a/drivers/input/misc/stpmic1_onkey.c +++ b/drivers/input/misc/stpmic1_onkey.c @@ -56,7 +56,7 @@ static int stpmic1_onkey_probe(struct platform_device *pdev) unsigned int val, reg = 0; int error; - onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL); + onkey = devm_kzalloc_obj(dev, *onkey); if (!onkey) return -ENOMEM; diff --git a/drivers/input/misc/tps65218-pwrbutton.c b/drivers/input/misc/tps65218-pwrbutton.c index 5c4de3a285d5ab..f13427485820f3 100644 --- a/drivers/input/misc/tps65218-pwrbutton.c +++ b/drivers/input/misc/tps65218-pwrbutton.c @@ -91,7 +91,7 @@ static int tps6521x_pb_probe(struct platform_device *pdev) if (!match) return -ENXIO; - pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); + pwr = devm_kzalloc_obj(dev, *pwr); if (!pwr) return -ENOMEM; diff --git a/drivers/input/misc/tps65219-pwrbutton.c b/drivers/input/misc/tps65219-pwrbutton.c index 7a58bae4f1a038..3d89be97aec6de 100644 --- a/drivers/input/misc/tps65219-pwrbutton.c +++ b/drivers/input/misc/tps65219-pwrbutton.c @@ -52,7 +52,7 @@ static int tps65219_pb_probe(struct platform_device *pdev) int push_irq; int release_irq; - pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); + pwr = devm_kzalloc_obj(dev, *pwr); if (!pwr) return -ENOMEM; diff --git a/drivers/input/misc/tps6594-pwrbutton.c b/drivers/input/misc/tps6594-pwrbutton.c index cd039b3866dc21..2a3be1bcb62ba4 100644 --- a/drivers/input/misc/tps6594-pwrbutton.c +++ b/drivers/input/misc/tps6594-pwrbutton.c @@ -50,7 +50,7 @@ static int tps6594_pb_probe(struct platform_device *pdev) int push_irq; int release_irq; - pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); + pwr = devm_kzalloc_obj(dev, *pwr); if (!pwr) return -ENOMEM; diff --git a/drivers/input/misc/twl4030-vibra.c b/drivers/input/misc/twl4030-vibra.c index 5fa7d4a7da363f..40b55b414d4818 100644 --- a/drivers/input/misc/twl4030-vibra.c +++ b/drivers/input/misc/twl4030-vibra.c @@ -182,7 +182,7 @@ static int twl4030_vibra_probe(struct platform_device *pdev) return -EINVAL; } - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c index afed9af65bf928..e5e648fc00995a 100644 --- a/drivers/input/misc/twl6040-vibra.c +++ b/drivers/input/misc/twl6040-vibra.c @@ -241,7 +241,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) return -EINVAL; } - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) { dev_err(&pdev->dev, "couldn't allocate memory\n"); return -ENOMEM; diff --git a/drivers/input/misc/wm831x-on.c b/drivers/input/misc/wm831x-on.c index a885873bcbd882..891f498eab6f14 100644 --- a/drivers/input/misc/wm831x-on.c +++ b/drivers/input/misc/wm831x-on.c @@ -75,8 +75,7 @@ static int wm831x_on_probe(struct platform_device *pdev) int irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0)); int ret; - wm831x_on = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_on), - GFP_KERNEL); + wm831x_on = devm_kzalloc_obj(&pdev->dev, struct wm831x_on); if (!wm831x_on) { dev_err(&pdev->dev, "Can't allocate data\n"); return -ENOMEM; diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c index a8e9b9ab9f84c1..c086d28f1412a4 100644 --- a/drivers/input/mouse/cyapa.c +++ b/drivers/input/mouse/cyapa.c @@ -1256,7 +1256,7 @@ static int cyapa_probe(struct i2c_client *client) I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy) < 0) return -ENODEV; - cyapa = devm_kzalloc(dev, sizeof(struct cyapa), GFP_KERNEL); + cyapa = devm_kzalloc_obj(dev, struct cyapa); if (!cyapa) return -ENOMEM; diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c index f5e505edbc332f..8661f5fb17620e 100644 --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c @@ -1245,7 +1245,7 @@ static int elan_probe(struct i2c_client *client) return -EIO; } - data = devm_kzalloc(dev, sizeof(struct elan_tp_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct elan_tp_data); if (!data) return -ENOMEM; diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c index 18ccbd45004ad9..59ea85ca3568bb 100644 --- a/drivers/input/mouse/gpio_mouse.c +++ b/drivers/input/mouse/gpio_mouse.c @@ -73,7 +73,7 @@ static int gpio_mouse_probe(struct platform_device *pdev) struct input_dev *input; int error; - gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL); + gmouse = devm_kzalloc_obj(dev, *gmouse); if (!gmouse) return -ENOMEM; diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c index 66e833974c6dac..1a675b96f9b9dc 100644 --- a/drivers/input/mouse/synaptics_i2c.c +++ b/drivers/input/mouse/synaptics_i2c.c @@ -519,7 +519,7 @@ static int synaptics_i2c_probe(struct i2c_client *client) struct synaptics_i2c *touch; int error; - touch = devm_kzalloc(dev, sizeof(*touch), GFP_KERNEL); + touch = devm_kzalloc_obj(dev, *touch); if (!touch) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index a349dfd17519c5..7bbe9e801c35c3 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -671,10 +671,9 @@ int rmi_read_register_desc(struct rmi_device *d, u16 addr, rdesc->num_registers = bitmap_weight(presence_map, RMI_REG_DESC_PRESENCE_BITS); - rdesc->registers = devm_kcalloc(&d->dev, - rdesc->num_registers, - sizeof(struct rmi_register_desc_item), - GFP_KERNEL); + rdesc->registers = devm_kzalloc_objs(&d->dev, + struct rmi_register_desc_item, + rdesc->num_registers); if (!rdesc->registers) return -ENOMEM; @@ -1185,7 +1184,7 @@ static int rmi_driver_probe(struct device *dev) return retval; } - data = devm_kzalloc(dev, sizeof(struct rmi_driver_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct rmi_driver_data); if (!data) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c index 47be64284b25ed..7d7ed463f74ebd 100644 --- a/drivers/input/rmi4/rmi_f01.c +++ b/drivers/input/rmi4/rmi_f01.c @@ -397,7 +397,7 @@ static int rmi_f01_probe(struct rmi_function *fn) return error; } - f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL); + f01 = devm_kzalloc_obj(&fn->dev, struct f01_data); if (!f01) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f03.c b/drivers/input/rmi4/rmi_f03.c index 04f0e5578861b2..00065091433437 100644 --- a/drivers/input/rmi4/rmi_f03.c +++ b/drivers/input/rmi4/rmi_f03.c @@ -201,7 +201,7 @@ static int rmi_f03_probe(struct rmi_function *fn) struct f03_data *f03; int error; - f03 = devm_kzalloc(dev, sizeof(struct f03_data), GFP_KERNEL); + f03 = devm_kzalloc_obj(dev, struct f03_data); if (!f03) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c index 9ade74b36edb01..280e293fd6425b 100644 --- a/drivers/input/rmi4/rmi_f11.c +++ b/drivers/input/rmi4/rmi_f11.c @@ -1200,15 +1200,13 @@ static int rmi_f11_initialize(struct rmi_function *fn) f11->sensor.attn_size += f11->sensor.nbr_fingers * 2; /* allocate the in-kernel tracking buffers */ - sensor->tracking_pos = devm_kcalloc(&fn->dev, - sensor->nbr_fingers, sizeof(struct input_mt_pos), - GFP_KERNEL); - sensor->tracking_slots = devm_kcalloc(&fn->dev, - sensor->nbr_fingers, sizeof(int), GFP_KERNEL); - sensor->objs = devm_kcalloc(&fn->dev, - sensor->nbr_fingers, - sizeof(struct rmi_2d_sensor_abs_object), - GFP_KERNEL); + sensor->tracking_pos = devm_kzalloc_objs(&fn->dev, struct input_mt_pos, + sensor->nbr_fingers); + sensor->tracking_slots = devm_kzalloc_objs(&fn->dev, int, + sensor->nbr_fingers); + sensor->objs = devm_kzalloc_objs(&fn->dev, + struct rmi_2d_sensor_abs_object, + sensor->nbr_fingers); if (!sensor->tracking_pos || !sensor->tracking_slots || !sensor->objs) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f12.c b/drivers/input/rmi4/rmi_f12.c index 841884d967a3dd..501c016c88c493 100644 --- a/drivers/input/rmi4/rmi_f12.c +++ b/drivers/input/rmi4/rmi_f12.c @@ -411,8 +411,7 @@ static int rmi_f12_probe(struct rmi_function *fn) return -ENODEV; } - f12 = devm_kzalloc(&fn->dev, struct_size(f12, irq_mask, irq_mask_size * 2), - GFP_KERNEL); + f12 = devm_kzalloc_flex(&fn->dev, *f12, irq_mask, irq_mask_size * 2); if (!f12) return -ENOMEM; @@ -530,20 +529,20 @@ static int rmi_f12_probe(struct rmi_function *fn) } /* allocate the in-kernel tracking buffers */ - sensor->tracking_pos = devm_kcalloc(&fn->dev, sensor->nbr_fingers, - sizeof(*sensor->tracking_pos), - GFP_KERNEL); + sensor->tracking_pos = devm_kzalloc_objs(&fn->dev, + *sensor->tracking_pos, + sensor->nbr_fingers); if (!sensor->tracking_pos) return -ENOMEM; - sensor->tracking_slots = devm_kcalloc(&fn->dev, sensor->nbr_fingers, - sizeof(*sensor->tracking_slots), - GFP_KERNEL); + sensor->tracking_slots = devm_kzalloc_objs(&fn->dev, + *sensor->tracking_slots, + sensor->nbr_fingers); if (!sensor->tracking_slots) return -ENOMEM; - sensor->objs = devm_kcalloc(&fn->dev, sensor->nbr_fingers, - sizeof(*sensor->objs), GFP_KERNEL); + sensor->objs = devm_kzalloc_objs(&fn->dev, *sensor->objs, + sensor->nbr_fingers); if (!sensor->objs) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f1a.c b/drivers/input/rmi4/rmi_f1a.c index 765e9eae4cdc1a..b2b206c32d8df5 100644 --- a/drivers/input/rmi4/rmi_f1a.c +++ b/drivers/input/rmi4/rmi_f1a.c @@ -33,8 +33,7 @@ static int rmi_f1a_parse_device_properties(struct rmi_function *fn, struct f1a_d return error; } - buttonmap = devm_kmalloc_array(dev, n_keys, sizeof(*buttonmap), - GFP_KERNEL); + buttonmap = devm_kmalloc_objs(dev, *buttonmap, n_keys); if (!buttonmap) return -ENOMEM; @@ -117,7 +116,7 @@ static int rmi_f1a_probe(struct rmi_function *fn) return -ENXIO; } - f1a = devm_kzalloc(&fn->dev, sizeof(*f1a), GFP_KERNEL); + f1a = devm_kzalloc_obj(&fn->dev, *f1a); if (!f1a) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f21.c b/drivers/input/rmi4/rmi_f21.c index e3a9dfc3f0ecb3..c731b242c91f5c 100644 --- a/drivers/input/rmi4/rmi_f21.c +++ b/drivers/input/rmi4/rmi_f21.c @@ -116,7 +116,7 @@ static int rmi_f21_probe(struct rmi_function *fn) return -ENXIO; } - f21 = devm_kzalloc(&fn->dev, sizeof(*f21), GFP_KERNEL); + f21 = devm_kzalloc_obj(&fn->dev, *f21); if (!f21) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c index b2155c8e20e756..2fd009be774c72 100644 --- a/drivers/input/rmi4/rmi_f30.c +++ b/drivers/input/rmi4/rmi_f30.c @@ -232,10 +232,9 @@ static int rmi_f30_map_gpios(struct rmi_function *fn, int i; int button_count = min_t(u8, f30->gpioled_count, TRACKSTICK_RANGE_END); - f30->gpioled_key_map = devm_kcalloc(&fn->dev, - f30->gpioled_count, - sizeof(f30->gpioled_key_map[0]), - GFP_KERNEL); + f30->gpioled_key_map = devm_kzalloc_objs(&fn->dev, + f30->gpioled_key_map[0], + f30->gpioled_count); if (!f30->gpioled_key_map) { dev_err(&fn->dev, "Failed to allocate gpioled map memory.\n"); return -ENOMEM; @@ -380,7 +379,7 @@ static int rmi_f30_probe(struct rmi_function *fn) return -ENXIO; } - f30 = devm_kzalloc(&fn->dev, sizeof(*f30), GFP_KERNEL); + f30 = devm_kzalloc_obj(&fn->dev, *f30); if (!f30) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c index f1947f03b06af6..d71211b0cfd289 100644 --- a/drivers/input/rmi4/rmi_f34.c +++ b/drivers/input/rmi4/rmi_f34.c @@ -580,7 +580,7 @@ static int rmi_f34_probe(struct rmi_function *fn) u8 version = fn->fd.function_version; int error; - f34 = devm_kzalloc(&fn->dev, sizeof(struct f34_data), GFP_KERNEL); + f34 = devm_kzalloc_obj(&fn->dev, struct f34_data); if (!f34) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f3a.c b/drivers/input/rmi4/rmi_f3a.c index a0777644eef078..07f25633e5570f 100644 --- a/drivers/input/rmi4/rmi_f3a.c +++ b/drivers/input/rmi4/rmi_f3a.c @@ -131,10 +131,8 @@ static int rmi_f3a_map_gpios(struct rmi_function *fn, struct f3a_data *f3a, int i; int button_count = min_t(u8, f3a->gpio_count, TRACKSTICK_RANGE_END); - f3a->gpio_key_map = devm_kcalloc(&fn->dev, - f3a->gpio_count, - sizeof(f3a->gpio_key_map[0]), - GFP_KERNEL); + f3a->gpio_key_map = devm_kzalloc_objs(&fn->dev, f3a->gpio_key_map[0], + f3a->gpio_count); if (!f3a->gpio_key_map) { dev_err(&fn->dev, "Failed to allocate gpio map memory.\n"); return -ENOMEM; @@ -216,7 +214,7 @@ static int rmi_f3a_probe(struct rmi_function *fn) return -ENXIO; } - f3a = devm_kzalloc(&fn->dev, sizeof(*f3a), GFP_KERNEL); + f3a = devm_kzalloc_obj(&fn->dev, *f3a); if (!f3a) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f54.c b/drivers/input/rmi4/rmi_f54.c index 6c6cdec7da9e33..448091d0209a4b 100644 --- a/drivers/input/rmi4/rmi_f54.c +++ b/drivers/input/rmi4/rmi_f54.c @@ -683,7 +683,7 @@ static int rmi_f54_probe(struct rmi_function *fn) int ret; u8 rx, tx; - f54 = devm_kzalloc(&fn->dev, sizeof(struct f54_data), GFP_KERNEL); + f54 = devm_kzalloc_obj(&fn->dev, struct f54_data); if (!f54) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_f55.c b/drivers/input/rmi4/rmi_f55.c index a0877d32a9141f..84858fbf64cdc2 100644 --- a/drivers/input/rmi4/rmi_f55.c +++ b/drivers/input/rmi4/rmi_f55.c @@ -109,7 +109,7 @@ static int rmi_f55_probe(struct rmi_function *fn) { struct f55_data *f55; - f55 = devm_kzalloc(&fn->dev, sizeof(struct f55_data), GFP_KERNEL); + f55 = devm_kzalloc_obj(&fn->dev, struct f55_data); if (!f55) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c index e11d0acb9b96d0..b0b36ddb2760d5 100644 --- a/drivers/input/rmi4/rmi_i2c.c +++ b/drivers/input/rmi4/rmi_i2c.c @@ -206,8 +206,7 @@ static int rmi_i2c_probe(struct i2c_client *client) struct rmi_i2c_xport *rmi_i2c; int error; - rmi_i2c = devm_kzalloc(&client->dev, sizeof(struct rmi_i2c_xport), - GFP_KERNEL); + rmi_i2c = devm_kzalloc_obj(&client->dev, struct rmi_i2c_xport); if (!rmi_i2c) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_smbus.c b/drivers/input/rmi4/rmi_smbus.c index 8b61c238229768..7f0fc5491efe4d 100644 --- a/drivers/input/rmi4/rmi_smbus.c +++ b/drivers/input/rmi4/rmi_smbus.c @@ -303,8 +303,7 @@ static int rmi_smb_probe(struct i2c_client *client) return client->irq ? client->irq : -ENODEV; } - rmi_smb = devm_kzalloc(&client->dev, sizeof(struct rmi_smb_xport), - GFP_KERNEL); + rmi_smb = devm_kzalloc_obj(&client->dev, struct rmi_smb_xport); if (!rmi_smb) return -ENOMEM; diff --git a/drivers/input/rmi4/rmi_spi.c b/drivers/input/rmi4/rmi_spi.c index 9d92129aa43292..145f3960b78ccd 100644 --- a/drivers/input/rmi4/rmi_spi.c +++ b/drivers/input/rmi4/rmi_spi.c @@ -93,10 +93,8 @@ static int rmi_spi_manage_pools(struct rmi_spi_xport *rmi_spi, int len) * per byte delays. */ tmp = rmi_spi->rx_xfers; - xfer_buf = devm_kcalloc(&spi->dev, - rmi_spi->rx_xfer_count + rmi_spi->tx_xfer_count, - sizeof(struct spi_transfer), - GFP_KERNEL); + xfer_buf = devm_kzalloc_objs(&spi->dev, struct spi_transfer, + rmi_spi->rx_xfer_count + rmi_spi->tx_xfer_count); if (!xfer_buf) return -ENOMEM; @@ -378,8 +376,7 @@ static int rmi_spi_probe(struct spi_device *spi) if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) return -EINVAL; - rmi_spi = devm_kzalloc(&spi->dev, sizeof(struct rmi_spi_xport), - GFP_KERNEL); + rmi_spi = devm_kzalloc_obj(&spi->dev, struct rmi_spi_xport); if (!rmi_spi) return -ENOMEM; diff --git a/drivers/input/serio/altera_ps2.c b/drivers/input/serio/altera_ps2.c index 4bf37db65b76cc..63eee11c59658d 100644 --- a/drivers/input/serio/altera_ps2.c +++ b/drivers/input/serio/altera_ps2.c @@ -81,7 +81,7 @@ static int altera_ps2_probe(struct platform_device *pdev) struct serio *serio; int error, irq; - ps2if = devm_kzalloc(&pdev->dev, sizeof(*ps2if), GFP_KERNEL); + ps2if = devm_kzalloc_obj(&pdev->dev, *ps2if); if (!ps2if) return -ENOMEM; diff --git a/drivers/input/serio/ams_delta_serio.c b/drivers/input/serio/ams_delta_serio.c index e346bf53eb1662..28ea6639b85525 100644 --- a/drivers/input/serio/ams_delta_serio.c +++ b/drivers/input/serio/ams_delta_serio.c @@ -111,7 +111,7 @@ static int ams_delta_serio_init(struct platform_device *pdev) struct serio *serio; int irq, err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/serio/apbps2.c b/drivers/input/serio/apbps2.c index 5f21acdd411394..83d1931f5c3367 100644 --- a/drivers/input/serio/apbps2.c +++ b/drivers/input/serio/apbps2.c @@ -133,7 +133,7 @@ static int apbps2_of_probe(struct platform_device *ofdev) int irq, err; u32 freq_hz; - priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&ofdev->dev, *priv); if (!priv) { dev_err(&ofdev->dev, "memory allocation failed\n"); return -ENOMEM; diff --git a/drivers/input/serio/arc_ps2.c b/drivers/input/serio/arc_ps2.c index 2eb069a0f054bd..a19a4ab723bd4a 100644 --- a/drivers/input/serio/arc_ps2.c +++ b/drivers/input/serio/arc_ps2.c @@ -189,7 +189,7 @@ static int arc_ps2_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - arc_ps2 = devm_kzalloc(&pdev->dev, sizeof(*arc_ps2), GFP_KERNEL); + arc_ps2 = devm_kzalloc_obj(&pdev->dev, *arc_ps2); if (!arc_ps2) { dev_err(&pdev->dev, "out of memory\n"); return -ENOMEM; diff --git a/drivers/input/serio/ioc3kbd.c b/drivers/input/serio/ioc3kbd.c index 4ef60c24e788e8..db14fa849c6aa8 100644 --- a/drivers/input/serio/ioc3kbd.c +++ b/drivers/input/serio/ioc3kbd.c @@ -135,7 +135,7 @@ static int ioc3kbd_probe(struct platform_device *pdev) if (irq < 0) return -ENXIO; - d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(dev, *d); if (!d) return -ENOMEM; diff --git a/drivers/input/serio/olpc_apsp.c b/drivers/input/serio/olpc_apsp.c index ccc40634f5828c..6e4fb647d0c60d 100644 --- a/drivers/input/serio/olpc_apsp.c +++ b/drivers/input/serio/olpc_apsp.c @@ -171,7 +171,7 @@ static int olpc_apsp_probe(struct platform_device *pdev) struct olpc_apsp *priv; int error; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c index 6cde0d88c6f4cf..eae491dda5b0f9 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -404,7 +404,7 @@ static int ps2_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int error; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); serio = kzalloc_obj(*serio); if (!drvdata || !serio) { error = -ENOMEM; diff --git a/drivers/input/touch-overlay.c b/drivers/input/touch-overlay.c index b9fd82c4829d30..693a77bee37cd4 100644 --- a/drivers/input/touch-overlay.c +++ b/drivers/input/touch-overlay.c @@ -83,7 +83,7 @@ int touch_overlay_map(struct list_head *list, struct input_dev *input) return 0; fwnode_for_each_available_child_node(overlay, fw_segment) { - segment = devm_kzalloc(dev, sizeof(*segment), GFP_KERNEL); + segment = devm_kzalloc_obj(dev, *segment); if (!segment) { fwnode_handle_put(fw_segment); return -ENOMEM; diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c index dd545a71901916..c1979acf5471ba 100644 --- a/drivers/input/touchscreen/88pm860x-ts.c +++ b/drivers/input/touchscreen/88pm860x-ts.c @@ -232,8 +232,7 @@ static int pm860x_touch_probe(struct platform_device *pdev) if (ret) return ret; - touch = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_touch), - GFP_KERNEL); + touch = devm_kzalloc_obj(&pdev->dev, struct pm860x_touch); if (!touch) return -ENOMEM; diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index 90311df47e4f84..1e3e4d3aa9967a 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c @@ -690,7 +690,7 @@ static int ad7877_probe(struct spi_device *spi) return err; } - ts = devm_kzalloc(&spi->dev, sizeof(struct ad7877), GFP_KERNEL); + ts = devm_kzalloc_obj(&spi->dev, struct ad7877); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c index 0789d8e19eaba9..ac700789f0e74d 100644 --- a/drivers/input/touchscreen/ad7879.c +++ b/drivers/input/touchscreen/ad7879.c @@ -521,7 +521,7 @@ int ad7879_probe(struct device *dev, struct regmap *regmap, return -EINVAL; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 8d6416ac283e5a..403a918fbf648e 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -1296,7 +1296,7 @@ static const struct ads7846_platform_data *ads7846_get_props(struct device *dev) struct ads7846_platform_data *pdata; u32 value; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -1385,7 +1385,7 @@ static int ads7846_probe(struct spi_device *spi) if (err < 0) return err; - ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, struct ads7846); if (!ts) return -ENOMEM; @@ -1397,7 +1397,7 @@ static int ads7846_probe(struct spi_device *spi) ts->read_state = ads7846_read_state; } - packet = devm_kzalloc(dev, sizeof(struct ads7846_packet), GFP_KERNEL); + packet = devm_kzalloc_obj(dev, struct ads7846_packet); if (!packet) return -ENOMEM; diff --git a/drivers/input/touchscreen/apple_z2.c b/drivers/input/touchscreen/apple_z2.c index 271ababf0ad559..7b2fa59e365bb5 100644 --- a/drivers/input/touchscreen/apple_z2.c +++ b/drivers/input/touchscreen/apple_z2.c @@ -355,7 +355,7 @@ static int apple_z2_probe(struct spi_device *spi) struct apple_z2 *z2; int error; - z2 = devm_kzalloc(dev, sizeof(*z2), GFP_KERNEL); + z2 = devm_kzalloc_obj(dev, *z2); if (!z2) return -ENOMEM; diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c index a56b114bcb3615..b32ef90b63f436 100644 --- a/drivers/input/touchscreen/ar1021_i2c.c +++ b/drivers/input/touchscreen/ar1021_i2c.c @@ -98,7 +98,7 @@ static int ar1021_i2c_probe(struct i2c_client *client) return -ENXIO; } - ar1021 = devm_kzalloc(&client->dev, sizeof(*ar1021), GFP_KERNEL); + ar1021 = devm_kzalloc_obj(&client->dev, *ar1021); if (!ar1021) return -ENOMEM; diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 522e1ea405a63b..35b7eaf12ae8e5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2717,8 +2717,8 @@ static void mxt_debug_init(struct mxt_data *data) sizeof(u16), sizeof(dbg->t37_buf->data)); - dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages, - sizeof(struct t37_debug), GFP_KERNEL); + dbg->t37_buf = devm_kmalloc_objs(&data->client->dev, struct t37_debug, + dbg->t37_pages); if (!dbg->t37_buf) goto error; @@ -3139,8 +3139,7 @@ static int mxt_parse_device_properties(struct mxt_data *data) return error; } - keymap = devm_kmalloc_array(dev, n_keys, sizeof(*keymap), - GFP_KERNEL); + keymap = devm_kmalloc_objs(dev, *keymap, n_keys); if (!keymap) return -ENOMEM; @@ -3165,8 +3164,7 @@ static int mxt_parse_device_properties(struct mxt_data *data) return error; } - buttonmap = devm_kmalloc_array(dev, n_keys, sizeof(*buttonmap), - GFP_KERNEL); + buttonmap = devm_kmalloc_objs(dev, *buttonmap, n_keys); if (!buttonmap) return -ENOMEM; @@ -3230,7 +3228,7 @@ static int mxt_probe(struct i2c_client *client) if (ACPI_COMPANION(&client->dev) && client->addr < 0x40) return -ENXIO; - data = devm_kzalloc(&client->dev, sizeof(struct mxt_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mxt_data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/auo-pixcir-ts.c b/drivers/input/touchscreen/auo-pixcir-ts.c index 6c6ebebacba9a7..3d435197fad534 100644 --- a/drivers/input/touchscreen/auo-pixcir-ts.c +++ b/drivers/input/touchscreen/auo-pixcir-ts.c @@ -490,7 +490,7 @@ static int auo_pixcir_probe(struct i2c_client *client) int version; int error; - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/bcm_iproc_tsc.c b/drivers/input/touchscreen/bcm_iproc_tsc.c index 42c27b2ef9499d..637d8ba01f62fa 100644 --- a/drivers/input/touchscreen/bcm_iproc_tsc.c +++ b/drivers/input/touchscreen/bcm_iproc_tsc.c @@ -420,7 +420,7 @@ static int iproc_ts_probe(struct platform_device *pdev) int irq; int error; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c index d1bdccc56fc8fe..05abc67f9e4223 100644 --- a/drivers/input/touchscreen/bu21013_ts.c +++ b/drivers/input/touchscreen/bu21013_ts.c @@ -424,7 +424,7 @@ static int bu21013_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/bu21029_ts.c b/drivers/input/touchscreen/bu21029_ts.c index 339fee1622fbc2..7a5379cfecdf0a 100644 --- a/drivers/input/touchscreen/bu21029_ts.c +++ b/drivers/input/touchscreen/bu21029_ts.c @@ -347,7 +347,7 @@ static int bu21029_probe(struct i2c_client *client) return -EIO; } - bu21029 = devm_kzalloc(dev, sizeof(*bu21029), GFP_KERNEL); + bu21029 = devm_kzalloc_obj(dev, *bu21029); if (!bu21029) return -ENOMEM; diff --git a/drivers/input/touchscreen/chipone_icn8318.c b/drivers/input/touchscreen/chipone_icn8318.c index 03b62706e39fd5..cd0471a03fc28d 100644 --- a/drivers/input/touchscreen/chipone_icn8318.c +++ b/drivers/input/touchscreen/chipone_icn8318.c @@ -186,7 +186,7 @@ static int icn8318_probe(struct i2c_client *client) return -EINVAL; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/chipone_icn8505.c b/drivers/input/touchscreen/chipone_icn8505.c index 7d0a488166bbeb..7e7552c9e29d90 100644 --- a/drivers/input/touchscreen/chipone_icn8505.c +++ b/drivers/input/touchscreen/chipone_icn8505.c @@ -393,7 +393,7 @@ static int icn8505_probe(struct i2c_client *client) return -EINVAL; } - icn8505 = devm_kzalloc(dev, sizeof(*icn8505), GFP_KERNEL); + icn8505 = devm_kzalloc_obj(dev, *icn8505); if (!icn8505) return -ENOMEM; diff --git a/drivers/input/touchscreen/colibri-vf50-ts.c b/drivers/input/touchscreen/colibri-vf50-ts.c index 6067bf0611255d..51eaafba909b02 100644 --- a/drivers/input/touchscreen/colibri-vf50-ts.c +++ b/drivers/input/touchscreen/colibri-vf50-ts.c @@ -283,7 +283,7 @@ static int vf50_ts_probe(struct platform_device *pdev) return -EINVAL; } - touchdev = devm_kzalloc(dev, sizeof(*touchdev), GFP_KERNEL); + touchdev = devm_kzalloc_obj(dev, *touchdev); if (!touchdev) return -ENOMEM; diff --git a/drivers/input/touchscreen/cy8ctma140.c b/drivers/input/touchscreen/cy8ctma140.c index 0ac48eff33761e..6aa6505b198515 100644 --- a/drivers/input/touchscreen/cy8ctma140.c +++ b/drivers/input/touchscreen/cy8ctma140.c @@ -205,7 +205,7 @@ static int cy8ctma140_probe(struct i2c_client *client) struct device *dev = &client->dev; int error; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c index 33ad4f0512a08e..fa19e37a368543 100644 --- a/drivers/input/touchscreen/cy8ctmg110_ts.c +++ b/drivers/input/touchscreen/cy8ctmg110_ts.c @@ -178,7 +178,7 @@ static int cy8ctmg110_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_WORD_DATA)) return -EIO; - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/cyttsp5.c b/drivers/input/touchscreen/cyttsp5.c index c6f7c0b041a16f..d4a78facfa815d 100644 --- a/drivers/input/touchscreen/cyttsp5.c +++ b/drivers/input/touchscreen/cyttsp5.c @@ -827,7 +827,7 @@ static int cyttsp5_probe(struct device *dev, struct regmap *regmap, int irq, struct cyttsp5_sysinfo *si; int error, i; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/da9034-ts.c b/drivers/input/touchscreen/da9034-ts.c index 2c46079e47d0ce..9ebbd486b18909 100644 --- a/drivers/input/touchscreen/da9034-ts.c +++ b/drivers/input/touchscreen/da9034-ts.c @@ -300,8 +300,7 @@ static int da9034_touch_probe(struct platform_device *pdev) struct input_dev *input_dev; int error; - touch = devm_kzalloc(&pdev->dev, sizeof(struct da9034_touch), - GFP_KERNEL); + touch = devm_kzalloc_obj(&pdev->dev, struct da9034_touch); if (!touch) { dev_err(&pdev->dev, "failed to allocate driver data\n"); return -ENOMEM; diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c index e69d64c3db2dd1..32eed64e2c494e 100644 --- a/drivers/input/touchscreen/edt-ft5x06.c +++ b/drivers/input/touchscreen/edt-ft5x06.c @@ -1126,7 +1126,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client) dev_dbg(&client->dev, "probing for EDT FT5x06 I2C\n"); - tsdata = devm_kzalloc(&client->dev, sizeof(*tsdata), GFP_KERNEL); + tsdata = devm_kzalloc_obj(&client->dev, *tsdata); if (!tsdata) { dev_err(&client->dev, "failed to allocate driver data.\n"); return -ENOMEM; diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c index b870a939508bb2..623086f562ce51 100644 --- a/drivers/input/touchscreen/eeti_ts.c +++ b/drivers/input/touchscreen/eeti_ts.c @@ -169,7 +169,7 @@ static int eeti_ts_probe(struct i2c_client *client) * for interrupts to occur. */ - eeti = devm_kzalloc(dev, sizeof(*eeti), GFP_KERNEL); + eeti = devm_kzalloc_obj(dev, *eeti); if (!eeti) { dev_err(dev, "failed to allocate driver data\n"); return -ENOMEM; diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c index 76cf8085553f0c..262860d99e3c6b 100644 --- a/drivers/input/touchscreen/egalax_ts.c +++ b/drivers/input/touchscreen/egalax_ts.c @@ -162,7 +162,7 @@ static int egalax_ts_probe(struct i2c_client *client) struct input_dev *input_dev; int error; - ts = devm_kzalloc(&client->dev, sizeof(struct egalax_ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, struct egalax_ts); if (!ts) { dev_err(&client->dev, "Failed to allocate memory\n"); return -ENOMEM; diff --git a/drivers/input/touchscreen/ektf2127.c b/drivers/input/touchscreen/ektf2127.c index 572a37d4e0aa11..2da2d279b5d803 100644 --- a/drivers/input/touchscreen/ektf2127.c +++ b/drivers/input/touchscreen/ektf2127.c @@ -265,7 +265,7 @@ static int ektf2127_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c index 7a651899feb11d..fd76a8189bf93b 100644 --- a/drivers/input/touchscreen/elants_i2c.c +++ b/drivers/input/touchscreen/elants_i2c.c @@ -1410,7 +1410,7 @@ static int elants_i2c_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(&client->dev, sizeof(struct elants_data), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, struct elants_data); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c index d1f9b44d9d76b4..d6e0c5183a4832 100644 --- a/drivers/input/touchscreen/exc3000.c +++ b/drivers/input/touchscreen/exc3000.c @@ -333,7 +333,7 @@ static int exc3000_probe(struct i2c_client *client) struct input_dev *input; int error, max_xy, retry; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/fsl-imx25-tcq.c b/drivers/input/touchscreen/fsl-imx25-tcq.c index ff270b3b85723a..04d7d2677001a9 100644 --- a/drivers/input/touchscreen/fsl-imx25-tcq.c +++ b/drivers/input/touchscreen/fsl-imx25-tcq.c @@ -505,7 +505,7 @@ static int mx25_tcq_probe(struct platform_device *pdev) void __iomem *mem; int error; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index 7609366f0b784b..1c9e88e3c7aaff 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -1319,7 +1319,7 @@ static int goodix_ts_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/goodix_berlin_core.c b/drivers/input/touchscreen/goodix_berlin_core.c index b0938a4f3fec30..c2d5b892958d79 100644 --- a/drivers/input/touchscreen/goodix_berlin_core.c +++ b/drivers/input/touchscreen/goodix_berlin_core.c @@ -737,7 +737,7 @@ int goodix_berlin_probe(struct device *dev, int irq, const struct input_id *id, return -EINVAL; } - cd = devm_kzalloc(dev, sizeof(*cd), GFP_KERNEL); + cd = devm_kzalloc_obj(dev, *cd); if (!cd) return -ENOMEM; diff --git a/drivers/input/touchscreen/hideep.c b/drivers/input/touchscreen/hideep.c index 68ee61c71df6e6..9384657ece7ea3 100644 --- a/drivers/input/touchscreen/hideep.c +++ b/drivers/input/touchscreen/hideep.c @@ -1017,7 +1017,7 @@ static int hideep_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/himax_hx83112b.c b/drivers/input/touchscreen/himax_hx83112b.c index 0aa67dfacbad84..345ece27fe746c 100644 --- a/drivers/input/touchscreen/himax_hx83112b.c +++ b/drivers/input/touchscreen/himax_hx83112b.c @@ -334,7 +334,7 @@ static int himax_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/himax_hx852x.c b/drivers/input/touchscreen/himax_hx852x.c index 1c488a63e53be9..6252278d2b4489 100644 --- a/drivers/input/touchscreen/himax_hx852x.c +++ b/drivers/input/touchscreen/himax_hx852x.c @@ -388,7 +388,7 @@ static int hx852x_probe(struct i2c_client *client) return -ENXIO; } - hx = devm_kzalloc(dev, sizeof(*hx), GFP_KERNEL); + hx = devm_kzalloc_obj(dev, *hx); if (!hx) return -ENOMEM; diff --git a/drivers/input/touchscreen/hycon-hy46xx.c b/drivers/input/touchscreen/hycon-hy46xx.c index 8ca408d66caf76..b3c69cf5397381 100644 --- a/drivers/input/touchscreen/hycon-hy46xx.c +++ b/drivers/input/touchscreen/hycon-hy46xx.c @@ -435,7 +435,7 @@ static int hycon_hy46xx_probe(struct i2c_client *client) dev_dbg(&client->dev, "probing for HYCON HY46XX I2C\n"); - tsdata = devm_kzalloc(&client->dev, sizeof(*tsdata), GFP_KERNEL); + tsdata = devm_kzalloc_obj(&client->dev, *tsdata); if (!tsdata) return -ENOMEM; diff --git a/drivers/input/touchscreen/hynitron-cst816x.c b/drivers/input/touchscreen/hynitron-cst816x.c index 47d9cd7412d1b9..5721e3dbc8e75a 100644 --- a/drivers/input/touchscreen/hynitron-cst816x.c +++ b/drivers/input/touchscreen/hynitron-cst816x.c @@ -194,7 +194,7 @@ static int cst816x_probe(struct i2c_client *client) struct cst816x_priv *priv; int error; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/touchscreen/hynitron_cstxxx.c b/drivers/input/touchscreen/hynitron_cstxxx.c index 49fb35c830dc15..7094ebc66f46c5 100644 --- a/drivers/input/touchscreen/hynitron_cstxxx.c +++ b/drivers/input/touchscreen/hynitron_cstxxx.c @@ -421,7 +421,7 @@ static int hyn_probe(struct i2c_client *client) struct hynitron_ts_data *ts_data; int err; - ts_data = devm_kzalloc(&client->dev, sizeof(*ts_data), GFP_KERNEL); + ts_data = devm_kzalloc_obj(&client->dev, *ts_data); if (!ts_data) return -ENOMEM; diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 3479698f55e3dc..03e4451d6393c4 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -985,7 +985,7 @@ static int ili210x_i2c_probe(struct i2c_client *client) ili210x_hardware_reset(reset_gpio); } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/input/touchscreen/ilitek_ts_i2c.c b/drivers/input/touchscreen/ilitek_ts_i2c.c index cdd02b7b6f6788..74ffed9813426a 100644 --- a/drivers/input/touchscreen/ilitek_ts_i2c.c +++ b/drivers/input/touchscreen/ilitek_ts_i2c.c @@ -555,7 +555,7 @@ static int ilitek_ts_i2c_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/imagis.c b/drivers/input/touchscreen/imagis.c index 7bbb00beec3be4..b97a5df7759a28 100644 --- a/drivers/input/touchscreen/imagis.c +++ b/drivers/input/touchscreen/imagis.c @@ -304,7 +304,7 @@ static int imagis_probe(struct i2c_client *i2c) struct imagis_ts *ts; int chip_id, error; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c index 43d6c69e308801..aefbd52664fd0c 100644 --- a/drivers/input/touchscreen/imx6ul_tsc.c +++ b/drivers/input/touchscreen/imx6ul_tsc.c @@ -394,7 +394,7 @@ static int imx6ul_tsc_probe(struct platform_device *pdev) u32 average_samples; u32 de_glitch; - tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL); + tsc = devm_kzalloc_obj(&pdev->dev, *tsc); if (!tsc) return -ENOMEM; diff --git a/drivers/input/touchscreen/ipaq-micro-ts.c b/drivers/input/touchscreen/ipaq-micro-ts.c index 243e6465d9bd23..f0ece8f8b5b8b4 100644 --- a/drivers/input/touchscreen/ipaq-micro-ts.c +++ b/drivers/input/touchscreen/ipaq-micro-ts.c @@ -80,7 +80,7 @@ static int micro_ts_probe(struct platform_device *pdev) struct touchscreen_data *ts; int error; - ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&pdev->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/iqs5xx.c b/drivers/input/touchscreen/iqs5xx.c index 88dcf72618dfbf..d1b906872aba2c 100644 --- a/drivers/input/touchscreen/iqs5xx.c +++ b/drivers/input/touchscreen/iqs5xx.c @@ -1008,7 +1008,7 @@ static int iqs5xx_probe(struct i2c_client *client) struct iqs5xx_private *iqs5xx; int error; - iqs5xx = devm_kzalloc(&client->dev, sizeof(*iqs5xx), GFP_KERNEL); + iqs5xx = devm_kzalloc_obj(&client->dev, *iqs5xx); if (!iqs5xx) return -ENOMEM; diff --git a/drivers/input/touchscreen/iqs7211.c b/drivers/input/touchscreen/iqs7211.c index 26e0b501c5fcf1..69996864cd5930 100644 --- a/drivers/input/touchscreen/iqs7211.c +++ b/drivers/input/touchscreen/iqs7211.c @@ -1622,7 +1622,7 @@ static int iqs7211_add_field(struct iqs7211_private *iqs7211, return 0; } - reg_field = devm_kzalloc(&client->dev, sizeof(*reg_field), GFP_KERNEL); + reg_field = devm_kzalloc_obj(&client->dev, *reg_field); if (!reg_field) return -ENOMEM; @@ -2438,7 +2438,7 @@ static int iqs7211_probe(struct i2c_client *client) bool shared_irq; int error, irq; - iqs7211 = devm_kzalloc(&client->dev, sizeof(*iqs7211), GFP_KERNEL); + iqs7211 = devm_kzalloc_obj(&client->dev, *iqs7211); if (!iqs7211) return -ENOMEM; diff --git a/drivers/input/touchscreen/jornada720_ts.c b/drivers/input/touchscreen/jornada720_ts.c index ba4e3c6e5c91f2..17f6e0ca342eb4 100644 --- a/drivers/input/touchscreen/jornada720_ts.c +++ b/drivers/input/touchscreen/jornada720_ts.c @@ -100,7 +100,7 @@ static int jornada720_ts_probe(struct platform_device *pdev) struct input_dev *input_dev; int error, irq; - jornada_ts = devm_kzalloc(&pdev->dev, sizeof(*jornada_ts), GFP_KERNEL); + jornada_ts = devm_kzalloc_obj(&pdev->dev, *jornada_ts); if (!jornada_ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/lpc32xx_ts.c b/drivers/input/touchscreen/lpc32xx_ts.c index 5de752a06b266b..b5918a07307ce3 100644 --- a/drivers/input/touchscreen/lpc32xx_ts.c +++ b/drivers/input/touchscreen/lpc32xx_ts.c @@ -208,7 +208,7 @@ static int lpc32xx_ts_probe(struct platform_device *pdev) if (irq < 0) return irq; - tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); + tsc = devm_kzalloc_obj(dev, *tsc); if (!tsc) return -ENOMEM; diff --git a/drivers/input/touchscreen/max11801_ts.c b/drivers/input/touchscreen/max11801_ts.c index 2191b4f8a00bb0..ce250e52fa1441 100644 --- a/drivers/input/touchscreen/max11801_ts.c +++ b/drivers/input/touchscreen/max11801_ts.c @@ -174,7 +174,7 @@ static int max11801_ts_probe(struct i2c_client *client) struct input_dev *input_dev; int error; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); input_dev = devm_input_allocate_device(&client->dev); if (!data || !input_dev) { dev_err(&client->dev, "Failed to allocate memory\n"); diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c index 0c8a922e2f2e1b..9136bdc1aff80b 100644 --- a/drivers/input/touchscreen/melfas_mip4.c +++ b/drivers/input/touchscreen/melfas_mip4.c @@ -1403,7 +1403,7 @@ static int mip4_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index f6039a47f7e97f..60dbf7295ac5d4 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -534,8 +534,7 @@ static int mms114_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(&client->dev, sizeof(struct mms114_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct mms114_data); input_dev = devm_input_allocate_device(&client->dev); if (!data || !input_dev) { dev_err(&client->dev, "Failed to allocate memory\n"); diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c index cd40c284d6f49b..fd929fe42ea214 100644 --- a/drivers/input/touchscreen/msg2638.c +++ b/drivers/input/touchscreen/msg2638.c @@ -366,7 +366,7 @@ static int msg2638_ts_probe(struct i2c_client *client) return -ENXIO; } - msg2638 = devm_kzalloc(dev, sizeof(*msg2638), GFP_KERNEL); + msg2638 = devm_kzalloc_obj(dev, *msg2638); if (!msg2638) return -ENOMEM; diff --git a/drivers/input/touchscreen/mxs-lradc-ts.c b/drivers/input/touchscreen/mxs-lradc-ts.c index 137ab3b60f2d9f..2970d9eb9c2ba8 100644 --- a/drivers/input/touchscreen/mxs-lradc-ts.c +++ b/drivers/input/touchscreen/mxs-lradc-ts.c @@ -608,7 +608,7 @@ static int mxs_lradc_ts_probe(struct platform_device *pdev) int ret, irq, virq, i; u32 ts_wires = 0, adapt; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/novatek-nvt-ts.c b/drivers/input/touchscreen/novatek-nvt-ts.c index 0f771f68195285..fa718a99e2ba5f 100644 --- a/drivers/input/touchscreen/novatek-nvt-ts.c +++ b/drivers/input/touchscreen/novatek-nvt-ts.c @@ -205,7 +205,7 @@ static int nvt_ts_probe(struct i2c_client *client) return -EINVAL; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index 1ca5920846dfd7..bc349442f9efb8 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c @@ -468,7 +468,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client) struct input_dev *input; int error; - tsdata = devm_kzalloc(dev, sizeof(*tsdata), GFP_KERNEL); + tsdata = devm_kzalloc_obj(dev, *tsdata); if (!tsdata) return -ENOMEM; diff --git a/drivers/input/touchscreen/raspberrypi-ts.c b/drivers/input/touchscreen/raspberrypi-ts.c index 841d39a449b373..91c105bdcc218c 100644 --- a/drivers/input/touchscreen/raspberrypi-ts.c +++ b/drivers/input/touchscreen/raspberrypi-ts.c @@ -137,7 +137,7 @@ static int rpi_ts_probe(struct platform_device *pdev) if (!fw) return -EPROBE_DEFER; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; ts->pdev = pdev; diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c index d046eba4b12d3e..6d6db1395bad4b 100644 --- a/drivers/input/touchscreen/raydium_i2c_ts.c +++ b/drivers/input/touchscreen/raydium_i2c_ts.c @@ -1066,7 +1066,7 @@ static int raydium_i2c_probe(struct i2c_client *client) return -ENXIO; } - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/resistive-adc-touch.c b/drivers/input/touchscreen/resistive-adc-touch.c index c89edc1280fe76..4af2102cb1dfad 100644 --- a/drivers/input/touchscreen/resistive-adc-touch.c +++ b/drivers/input/touchscreen/resistive-adc-touch.c @@ -203,7 +203,7 @@ static int grts_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int error; - st = devm_kzalloc(dev, sizeof(struct grts_state), GFP_KERNEL); + st = devm_kzalloc_obj(dev, struct grts_state); if (!st) return -ENOMEM; diff --git a/drivers/input/touchscreen/rohm_bu21023.c b/drivers/input/touchscreen/rohm_bu21023.c index a5c06b7423c0c7..f40f14dc351b3d 100644 --- a/drivers/input/touchscreen/rohm_bu21023.c +++ b/drivers/input/touchscreen/rohm_bu21023.c @@ -1093,7 +1093,7 @@ static int rohm_bu21023_i2c_probe(struct i2c_client *client) if (error) return error; - ts = devm_kzalloc(dev, sizeof(struct rohm_ts_data), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, struct rohm_ts_data); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/s6sy761.c b/drivers/input/touchscreen/s6sy761.c index 1bd4ddffe4e133..7ea86780cd3740 100644 --- a/drivers/input/touchscreen/s6sy761.c +++ b/drivers/input/touchscreen/s6sy761.c @@ -397,7 +397,7 @@ static int s6sy761_probe(struct i2c_client *client) I2C_FUNC_SMBUS_I2C_BLOCK)) return -ENODEV; - sdata = devm_kzalloc(&client->dev, sizeof(*sdata), GFP_KERNEL); + sdata = devm_kzalloc_obj(&client->dev, *sdata); if (!sdata) return -ENOMEM; diff --git a/drivers/input/touchscreen/silead.c b/drivers/input/touchscreen/silead.c index 6014c4e049a60b..bf3e42be49e74c 100644 --- a/drivers/input/touchscreen/silead.c +++ b/drivers/input/touchscreen/silead.c @@ -658,7 +658,7 @@ static int silead_ts_probe(struct i2c_client *client) return -ENXIO; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/sis_i2c.c b/drivers/input/touchscreen/sis_i2c.c index 4fa93cd31ee4ed..6280f0feee710e 100644 --- a/drivers/input/touchscreen/sis_i2c.c +++ b/drivers/input/touchscreen/sis_i2c.c @@ -302,7 +302,7 @@ static int sis_ts_probe(struct i2c_client *client) struct input_dev *input; int error; - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index c2dcfce5003d29..32c43397080e97 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -308,7 +308,7 @@ static int st1232_ts_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/stmfts.c b/drivers/input/touchscreen/stmfts.c index 972687797f8261..8617e75fa8265f 100644 --- a/drivers/input/touchscreen/stmfts.c +++ b/drivers/input/touchscreen/stmfts.c @@ -675,7 +675,7 @@ static int stmfts_probe(struct i2c_client *client) I2C_FUNC_SMBUS_I2C_BLOCK)) return -ENODEV; - sdata = devm_kzalloc(dev, sizeof(*sdata), GFP_KERNEL); + sdata = devm_kzalloc_obj(dev, *sdata); if (!sdata) return -ENOMEM; diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c index af0fb38bcfdcd2..84a4ff25223c31 100644 --- a/drivers/input/touchscreen/stmpe-ts.c +++ b/drivers/input/touchscreen/stmpe-ts.c @@ -296,7 +296,7 @@ static int stmpe_input_probe(struct platform_device *pdev) if (ts_irq < 0) return ts_irq; - ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&pdev->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c index e8286060043aeb..5196b38bc7f32b 100644 --- a/drivers/input/touchscreen/sun4i-ts.c +++ b/drivers/input/touchscreen/sun4i-ts.c @@ -244,7 +244,7 @@ static int sun4i_ts_probe(struct platform_device *pdev) u32 tp_sensitive_adjust = 15; u32 filter_type = 1; - ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, struct sun4i_ts_data); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/surface3_spi.c b/drivers/input/touchscreen/surface3_spi.c index 9d74efc8d98679..e7972d66ea2eb7 100644 --- a/drivers/input/touchscreen/surface3_spi.c +++ b/drivers/input/touchscreen/surface3_spi.c @@ -329,7 +329,7 @@ static int surface3_spi_probe(struct spi_device *spi) if (error) return error; - data = devm_kzalloc(&spi->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&spi->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c index 7311b5cd573fda..23fb0c68359291 100644 --- a/drivers/input/touchscreen/sx8654.c +++ b/drivers/input/touchscreen/sx8654.c @@ -314,7 +314,7 @@ static int sx8654_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_WORD_DATA)) return -ENXIO; - sx8654 = devm_kzalloc(&client->dev, sizeof(*sx8654), GFP_KERNEL); + sx8654 = devm_kzalloc_obj(&client->dev, *sx8654); if (!sx8654) return -ENOMEM; diff --git a/drivers/input/touchscreen/tps6507x-ts.c b/drivers/input/touchscreen/tps6507x-ts.c index e84dc3ea1fcb6c..4e3eb7e66b2f43 100644 --- a/drivers/input/touchscreen/tps6507x-ts.c +++ b/drivers/input/touchscreen/tps6507x-ts.c @@ -221,7 +221,7 @@ static int tps6507x_ts_probe(struct platform_device *pdev) */ init_data = tps_board->tps6507x_ts_init_data; - tsc = devm_kzalloc(&pdev->dev, sizeof(struct tps6507x_ts), GFP_KERNEL); + tsc = devm_kzalloc_obj(&pdev->dev, struct tps6507x_ts); if (!tsc) { dev_err(tps6507x_dev->dev, "failed to allocate driver data\n"); return -ENOMEM; diff --git a/drivers/input/touchscreen/ts4800-ts.c b/drivers/input/touchscreen/ts4800-ts.c index 98422d1e80d6d4..db8c3b12a2b1a1 100644 --- a/drivers/input/touchscreen/ts4800-ts.c +++ b/drivers/input/touchscreen/ts4800-ts.c @@ -151,7 +151,7 @@ static int ts4800_ts_probe(struct platform_device *pdev) struct ts4800_ts *ts; int error; - ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&pdev->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c index e2f49b37e18c0d..e8d87cf00f8ea1 100644 --- a/drivers/input/touchscreen/tsc2007_core.c +++ b/drivers/input/touchscreen/tsc2007_core.c @@ -303,7 +303,7 @@ static int tsc2007_probe(struct i2c_client *client) I2C_FUNC_SMBUS_READ_WORD_DATA)) return -EIO; - ts = devm_kzalloc(&client->dev, sizeof(struct tsc2007), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, struct tsc2007); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index eba53613b00527..4a756892ff6629 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -452,7 +452,7 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return -ENODEV; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c index dd7c2a8a831bfd..47238b37e7dc15 100644 --- a/drivers/input/touchscreen/wacom_i2c.c +++ b/drivers/input/touchscreen/wacom_i2c.c @@ -179,7 +179,7 @@ static int wacom_i2c_probe(struct i2c_client *client) if (error) return error; - wac_i2c = devm_kzalloc(dev, sizeof(*wac_i2c), GFP_KERNEL); + wac_i2c = devm_kzalloc_obj(dev, *wac_i2c); if (!wac_i2c) return -ENOMEM; diff --git a/drivers/input/touchscreen/wacom_w9000.c b/drivers/input/touchscreen/wacom_w9000.c index 4a2629a5416743..b5da3c877ff6c6 100644 --- a/drivers/input/touchscreen/wacom_w9000.c +++ b/drivers/input/touchscreen/wacom_w9000.c @@ -256,7 +256,7 @@ static int wacom_w9000_probe(struct i2c_client *client) return -EIO; } - wacom_data = devm_kzalloc(dev, sizeof(*wacom_data), GFP_KERNEL); + wacom_data = devm_kzalloc_obj(dev, *wacom_data); if (!wacom_data) return -ENOMEM; diff --git a/drivers/input/touchscreen/wdt87xx_i2c.c b/drivers/input/touchscreen/wdt87xx_i2c.c index 858c7efd0c290f..48ca32d63d912e 100644 --- a/drivers/input/touchscreen/wdt87xx_i2c.c +++ b/drivers/input/touchscreen/wdt87xx_i2c.c @@ -1067,7 +1067,7 @@ static int wdt87xx_ts_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENXIO; - wdt = devm_kzalloc(&client->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&client->dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/input/touchscreen/wm831x-ts.c b/drivers/input/touchscreen/wm831x-ts.c index 17c58b6fa1238c..32b03889acea6b 100644 --- a/drivers/input/touchscreen/wm831x-ts.c +++ b/drivers/input/touchscreen/wm831x-ts.c @@ -240,8 +240,7 @@ static int wm831x_ts_probe(struct platform_device *pdev) if (core_pdata) pdata = core_pdata->touch; - wm831x_ts = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ts), - GFP_KERNEL); + wm831x_ts = devm_kzalloc_obj(&pdev->dev, struct wm831x_ts); input_dev = devm_input_allocate_device(&pdev->dev); if (!wm831x_ts || !input_dev) { error = -ENOMEM; diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c index f6b7c03f654f56..ff12666f53dbd9 100644 --- a/drivers/input/touchscreen/wm97xx-core.c +++ b/drivers/input/touchscreen/wm97xx-core.c @@ -686,7 +686,7 @@ static int wm97xx_probe(struct device *dev) int ret; struct wm97xx_pdata *pdata = dev_get_platdata(dev); - wm = devm_kzalloc(dev, sizeof(struct wm97xx), GFP_KERNEL); + wm = devm_kzalloc_obj(dev, struct wm97xx); if (!wm) return -ENOMEM; @@ -724,7 +724,7 @@ static int wm97xx_mfd_probe(struct platform_device *pdev) struct wm97xx_platform_data *mfd_pdata = dev_get_platdata(&pdev->dev); int ret; - wm = devm_kzalloc(&pdev->dev, sizeof(struct wm97xx), GFP_KERNEL); + wm = devm_kzalloc_obj(&pdev->dev, struct wm97xx); if (!wm) return -ENOMEM; diff --git a/drivers/input/touchscreen/zet6223.c b/drivers/input/touchscreen/zet6223.c index a341142f3708e2..177bc827fde0c1 100644 --- a/drivers/input/touchscreen/zet6223.c +++ b/drivers/input/touchscreen/zet6223.c @@ -177,7 +177,7 @@ static int zet6223_probe(struct i2c_client *client) return -EINVAL; } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c index 4bfc9560bd6c1a..5eca54fdae85a0 100644 --- a/drivers/input/touchscreen/zforce_ts.c +++ b/drivers/input/touchscreen/zforce_ts.c @@ -684,7 +684,7 @@ static int zforce_probe(struct i2c_client *client) struct input_dev *input_dev; int error; - ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&client->dev, struct zforce_ts); if (!ts) return -ENOMEM; diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index 0c36765bd79f84..7bb2d1f4ddd0e9 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -622,7 +622,7 @@ static int zinitix_ts_probe(struct i2c_client *client) return -ENXIO; } - bt541 = devm_kzalloc(&client->dev, sizeof(*bt541), GFP_KERNEL); + bt541 = devm_kzalloc_obj(&client->dev, *bt541); if (!bt541) return -ENOMEM; diff --git a/drivers/interconnect/icc-clk.c b/drivers/interconnect/icc-clk.c index 93c030608d3e0a..306aedc4339cb7 100644 --- a/drivers/interconnect/icc-clk.c +++ b/drivers/interconnect/icc-clk.c @@ -84,12 +84,12 @@ struct icc_provider *icc_clk_register(struct device *dev, struct icc_node *node; int ret, i, j; - onecell = devm_kzalloc(dev, struct_size(onecell, nodes, 2 * num_clocks), GFP_KERNEL); + onecell = devm_kzalloc_flex(dev, *onecell, nodes, 2 * num_clocks); if (!onecell) return ERR_PTR(-ENOMEM); onecell->num_nodes = 2 * num_clocks; - qp = devm_kzalloc(dev, struct_size(qp, clocks, num_clocks), GFP_KERNEL); + qp = devm_kzalloc_flex(dev, *qp, clocks, num_clocks); if (!qp) return ERR_PTR(-ENOMEM); diff --git a/drivers/interconnect/imx/imx.c b/drivers/interconnect/imx/imx.c index 9511f80cf04138..c6b8f07bd6987f 100644 --- a/drivers/interconnect/imx/imx.c +++ b/drivers/interconnect/imx/imx.c @@ -181,7 +181,7 @@ static struct icc_node *imx_icc_node_add(struct imx_icc_provider *imx_provider, return ERR_PTR(-EEXIST); } - node_data = devm_kzalloc(dev, sizeof(*node_data), GFP_KERNEL); + node_data = devm_kzalloc_obj(dev, *node_data); if (!node_data) { icc_node_destroy(node->id); return ERR_PTR(-ENOMEM); @@ -279,13 +279,12 @@ int imx_icc_register(struct platform_device *pdev, /* icc_onecell_data is indexed by node_id, unlike nodes param */ num_nodes = get_max_node_id(nodes, nodes_count) + 1; - data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), - GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, nodes, num_nodes); if (!data) return -ENOMEM; data->num_nodes = num_nodes; - imx_provider = devm_kzalloc(dev, sizeof(*imx_provider), GFP_KERNEL); + imx_provider = devm_kzalloc_obj(dev, *imx_provider); if (!imx_provider) return -ENOMEM; provider = &imx_provider->provider; diff --git a/drivers/interconnect/mediatek/icc-emi.c b/drivers/interconnect/mediatek/icc-emi.c index dfa3a9cd939983..62fe8d7701462b 100644 --- a/drivers/interconnect/mediatek/icc-emi.c +++ b/drivers/interconnect/mediatek/icc-emi.c @@ -92,11 +92,11 @@ int mtk_emi_icc_probe(struct platform_device *pdev) mnodes = desc->nodes; - provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL); + provider = devm_kzalloc_obj(dev, *provider); if (!provider) return -ENOMEM; - data = devm_kzalloc(dev, struct_size(data, nodes, desc->num_nodes), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, nodes, desc->num_nodes); if (!data) return -ENOMEM; diff --git a/drivers/interconnect/qcom/bcm-voter.c b/drivers/interconnect/qcom/bcm-voter.c index 0880a287b0c0aa..c835195b109537 100644 --- a/drivers/interconnect/qcom/bcm-voter.c +++ b/drivers/interconnect/qcom/bcm-voter.c @@ -395,7 +395,7 @@ static int qcom_icc_bcm_voter_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct bcm_voter *voter; - voter = devm_kzalloc(&pdev->dev, sizeof(*voter), GFP_KERNEL); + voter = devm_kzalloc_obj(&pdev->dev, *voter); if (!voter) return -ENOMEM; diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c index 6f325789a96ea8..603797b9e92b79 100644 --- a/drivers/interconnect/qcom/icc-rpm.c +++ b/drivers/interconnect/qcom/icc-rpm.c @@ -539,15 +539,14 @@ int qnoc_probe(struct platform_device *pdev) cd_num = 0; } - qp = devm_kzalloc(dev, struct_size(qp, intf_clks, cd_num), GFP_KERNEL); + qp = devm_kzalloc_flex(dev, *qp, intf_clks, cd_num); if (!qp) return -ENOMEM; qp->num_intf_clks = cd_num; if (desc->bus_clk_desc) { - qp->bus_clk_desc = devm_kzalloc(dev, sizeof(*qp->bus_clk_desc), - GFP_KERNEL); + qp->bus_clk_desc = devm_kzalloc_obj(dev, *qp->bus_clk_desc); if (!qp->bus_clk_desc) return -ENOMEM; @@ -559,8 +558,7 @@ int qnoc_probe(struct platform_device *pdev) return PTR_ERR(qp->bus_clk); } - data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), - GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, nodes, num_nodes); if (!data) return -ENOMEM; data->num_nodes = num_nodes; diff --git a/drivers/interconnect/qcom/icc-rpmh.c b/drivers/interconnect/qcom/icc-rpmh.c index 4a2a746a4e59db..73977f4f8372b6 100644 --- a/drivers/interconnect/qcom/icc-rpmh.c +++ b/drivers/interconnect/qcom/icc-rpmh.c @@ -295,11 +295,11 @@ int qcom_icc_rpmh_probe(struct platform_device *pdev) qnodes = desc->nodes; num_nodes = desc->num_nodes; - qp = devm_kzalloc(dev, sizeof(*qp), GFP_KERNEL); + qp = devm_kzalloc_obj(dev, *qp); if (!qp) return -ENOMEM; - data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, nodes, num_nodes); if (!data) return -ENOMEM; data->num_nodes = num_nodes; diff --git a/drivers/interconnect/qcom/osm-l3.c b/drivers/interconnect/qcom/osm-l3.c index ecad636b53e06b..e1aa600be9759c 100644 --- a/drivers/interconnect/qcom/osm-l3.c +++ b/drivers/interconnect/qcom/osm-l3.c @@ -182,7 +182,7 @@ static int qcom_osm_l3_probe(struct platform_device *pdev) hw_rate = clk_get_rate(clk) / CLK_HW_DIV; clk_put(clk); - qp = devm_kzalloc(&pdev->dev, sizeof(*qp), GFP_KERNEL); + qp = devm_kzalloc_obj(&pdev->dev, *qp); if (!qp) return -ENOMEM; @@ -226,7 +226,7 @@ static int qcom_osm_l3_probe(struct platform_device *pdev) qnodes = desc->nodes; num_nodes = desc->num_nodes; - data = devm_kzalloc(&pdev->dev, struct_size(data, nodes, num_nodes), GFP_KERNEL); + data = devm_kzalloc_flex(&pdev->dev, *data, nodes, num_nodes); if (!data) return -ENOMEM; data->num_nodes = num_nodes; diff --git a/drivers/interconnect/samsung/exynos.c b/drivers/interconnect/samsung/exynos.c index 9a4789fadac2ea..00c81b7979e6a5 100644 --- a/drivers/interconnect/samsung/exynos.c +++ b/drivers/interconnect/samsung/exynos.c @@ -110,7 +110,7 @@ static int exynos_generic_icc_probe(struct platform_device *pdev) struct icc_node *icc_node, *icc_parent_node; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 93845b3c3fbf72..29355810db7c3f 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -48,8 +48,7 @@ extern u8 amd_iommu_hpt_vasize; extern unsigned long amd_iommu_pgsize_bitmap; extern bool amd_iommu_hatdis; -int amd_iommu_perfopt_clear(struct amd_iommu *iommu); -int amd_iommu_perfopt_restore(struct amd_iommu *iommu); +int amd_iommu_perfopt_set(struct amd_iommu *iommu, bool enable); /* Protection domain ops */ void amd_iommu_init_identity_domain(void); diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 0e79c43be001ce..f98770db00902a 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -660,8 +660,8 @@ struct amd_iommu { /* Extended features 2 */ u64 features2; - /* Devices requesting PerfOpt; the shared PERF_OPT_EN bit is on while >0. Protected by @lock. */ - int perfopt_refcount; + /* Saved PerfOpt activation state, protected by @lock. */ + bool perfopt_enabled; /* PCI device id of the IOMMU device */ u16 devid; @@ -824,7 +824,7 @@ struct iommu_dev_data { u8 ppr :1; /* Enable device PPR support */ bool use_vapic; /* Enable device to use vapic mode */ bool defer_attach; - bool perfopt; + bool perfopt; /* Device is eligible for PerfOpt */ struct ratelimit_state rs; /* Ratelimit IOPF messages */ }; diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index de6db562119464..58f63298493b48 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -432,8 +432,41 @@ static void iommu_enable(struct amd_iommu *iommu) iommu_feature_enable(iommu, CONTROL_IOMMU_EN); } +/* + * Program or clear the per-IOMMU PerfOpt enable bit. + * Gate on this IOMMU's own EFR, not the global AND-mask. + * Caller serializes access using iommu->lock or during init/suspend/resume. + */ +int amd_iommu_perfopt_set(struct amd_iommu *iommu, bool enable) +{ + u32 old, val, readback; + + if (!(readq(iommu->mmio_base + MMIO_EXT_FEATURES) & FEATURE_PERF_OPT)) + return enable ? -ENODEV : 0; + + old = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET); + if (old == U32_MAX) + goto fail; + + val = enable ? old | PERF_OPT_EN : old & ~PERF_OPT_EN; + if (val != old) + writel(val, iommu->mmio_base + MMIO_PERF_OPT_OFFSET); + readback = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET); + if (readback == U32_MAX || + (readback & PERF_OPT_EN) != (val & PERF_OPT_EN)) + goto fail; + + iommu->perfopt_enabled = enable; + return 0; +fail: + pr_err("IOMMU%d: failed to set PerfOpt to %d\n", iommu->index, enable); + return -EIO; +} + static void iommu_disable(struct amd_iommu *iommu) { + bool perfopt_enabled = iommu->perfopt_enabled; + if (!iommu->mmio_base) return; @@ -457,6 +490,10 @@ static void iommu_disable(struct amd_iommu *iommu) /* Clear IRTE cache disabling bit */ iommu_feature_disable(iommu, CONTROL_IRTCACHEDIS); + + /* Clear hardware while preserving the activation state for resume. */ + amd_iommu_perfopt_set(iommu, false); + iommu->perfopt_enabled = perfopt_enabled; } /* @@ -1715,6 +1752,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, return 0; } +/* + * Apply workaround for Zen1 to Zen5(BRH) generation of processors. + * References: CVE-2024-21963 + */ +static bool __init amd_iommu_force_max_dev_table(void) +{ + if (boot_cpu_data.x86 >= 0x17 && boot_cpu_data.x86 <= 0x1a) { + if (cpu_feature_enabled(X86_FEATURE_ZEN6)) + return false; + else + return true; + } + return false; +} + /* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, struct acpi_table_header *ivrs_base) @@ -1737,9 +1789,15 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf; DUMP_printk("PCI segment : 0x%0x, last bdf : 0x%04x\n", id, last_bdf); - pci_seg->dev_table_size = - max(roundup_pow_of_two((last_bdf + 1) * DEV_TABLE_ENTRY_SIZE), - SZ_4K); + if (amd_iommu_force_max_dev_table()) { + pr_info("Force device table to maximum size\n"); + pci_seg->dev_table_size = SZ_2M; + } else { + pci_seg->dev_table_size = + max(roundup_pow_of_two((last_bdf + 1) * + DEV_TABLE_ENTRY_SIZE), + SZ_4K); + } pci_seg->id = id; init_llist_head(&pci_seg->dev_data_list); @@ -1888,6 +1946,7 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h, struct acpi_table_header *ivrs_base) { struct amd_iommu_pci_seg *pci_seg; + int ret; pci_seg = get_pci_segment(h->pci_seg, ivrs_base); if (pci_seg == NULL) @@ -1960,8 +2019,10 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h, if (!iommu->mmio_base) return -ENOMEM; - if (amd_iommu_perfopt_clear(iommu)) - pr_err("IOMMU%d: failed to clear PerfOpt\n", iommu->index); + /* A crash kernel may reuse device tables with PerfOpt still enabled. */ + ret = amd_iommu_perfopt_set(iommu, false); + if (ret) + return ret; return init_iommu_from_acpi(iommu, h); } @@ -2331,6 +2392,9 @@ static void print_iommu_info(void) if (check_feature2(FEATURE_SEVSNPIO_SUP)) pr_cont(" SEV-TIO"); + if (check_feature(FEATURE_PERF_OPT)) + pr_cont(" PerfOpt"); + pr_cont("\n"); } @@ -2733,6 +2797,15 @@ static int __init init_unity_map_range(struct ivmd_header *m, return 0; } +static bool ivrs_block_type_ivmd(u8 type) +{ + if (type == ACPI_IVMD_TYPE || + type == ACPI_IVMD_TYPE_ALL || + type == ACPI_IVMD_TYPE_RANGE) + return true; + return false; +} + /* iterates over all memory definitions we find in the ACPI table */ static int __init init_memory_definitions(struct acpi_table_header *table) { @@ -2744,10 +2817,11 @@ static int __init init_memory_definitions(struct acpi_table_header *table) while (p < end) { m = (struct ivmd_header *)p; + p += m->length; + if (!ivrs_block_type_ivmd(m->type)) + continue; if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE)) init_unity_map_range(m, table); - - p += m->length; } return 0; @@ -3067,46 +3141,10 @@ static void enable_iommus_vapic(void) #endif } -static int clear_perfopt_all(void) -{ - struct amd_iommu *iommu; - int err, ret = 0; - - for_each_iommu(iommu) { - err = amd_iommu_perfopt_clear(iommu); - if (err) - ret = err; - } - - return ret; -} - -static int restore_perfopt_all(void) -{ - struct amd_iommu *iommu; - int err, ret = 0; - - for_each_iommu(iommu) { - err = amd_iommu_perfopt_restore(iommu); - if (err) - ret = err; - } - - return ret; -} - static void disable_iommus(void) { struct amd_iommu *iommu; - /* - * PerfOpt is an optional performance bit, so a failure to clear it must - * not skip the mandatory disable below. This also runs from the void - * amd_iommu_disable() shutdown/kexec path, which cannot report an error. - */ - if (clear_perfopt_all()) - pr_err("Failed to clear PerfOpt while disabling IOMMUs\n"); - for_each_iommu(iommu) iommu_disable(iommu); @@ -3132,9 +3170,11 @@ static void amd_iommu_resume(void *data) for_each_iommu(iommu) early_enable_iommu(iommu); - /* early_enable_iommu() cleared PERF_OPT_EN; re-assert it from the refcount. */ - if (restore_perfopt_all()) - pr_err("Failed to restore PerfOpt after IOMMU resume\n"); + /* Restore the activation state saved at suspend. */ + for_each_iommu(iommu) { + if (iommu->perfopt_enabled) + amd_iommu_perfopt_set(iommu, true); + } iommu_enable_event_buffer(); amd_iommu_enable_interrupts(); @@ -3505,6 +3545,7 @@ static __init void iommu_snp_enable(void) return; disable_snp: + amd_iommu_snp_en = false; cc_platform_clear(CC_ATTR_HOST_SEV_SNP); #endif } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 960e1dc05ec69b..41ee4ad1dcf826 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -487,6 +488,10 @@ static void setup_aliases(struct amd_iommu *iommu, struct device *dev) clone_aliases(iommu, dev); } +/* + * We keep dev_data around for unplugged devices and reuse it when the + * device is re-plugged - not doing so would introduce a ton of races. + */ static struct iommu_dev_data *find_dev_data(struct amd_iommu *iommu, u16 devid) { struct iommu_dev_data *dev_data; @@ -2368,7 +2373,7 @@ static int attach_device(struct device *dev, if (ret) goto out; - if (dev_data->perfopt) + if (dev_data->perfopt && pdom_is_in_pt_mode(domain)) goto skip_caps; /* Setup GCR3 table */ @@ -2510,192 +2515,6 @@ static int iommu_init_device_caps(struct iommu_dev_data *dev_data, return 0; } -/* Program the per-IOMMU PerfOpt enable bit. Caller must hold iommu->lock. */ -static int __perfopt_write(struct amd_iommu *iommu, bool enable) -{ - u32 old, val, readback; - - if (!(readq(iommu->mmio_base + MMIO_EXT_FEATURES) & FEATURE_PERF_OPT)) - return enable ? -ENODEV : 0; - - old = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET); - if (old == U32_MAX) - return -EIO; - - val = enable ? old | PERF_OPT_EN : old & ~PERF_OPT_EN; - if (val != old) - writel(val, iommu->mmio_base + MMIO_PERF_OPT_OFFSET); - readback = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET); - if (readback == U32_MAX || - (readback & PERF_OPT_EN) != (val & PERF_OPT_EN)) - return -EIO; - return 0; -} - -/* - * PERF_OPT_EN is a single bit shared by every device behind @iommu, so it is - * reference counted: armed on the first requesting device, cleared on the last. - */ -static int perfopt_get(struct amd_iommu *iommu) -{ - unsigned long flags; - int ret = 0; - - if (!iommu->mmio_base) - return 0; - - raw_spin_lock_irqsave(&iommu->lock, flags); - if (iommu->perfopt_refcount == 0) { - ret = __perfopt_write(iommu, true); - if (ret) - goto out; - } - iommu->perfopt_refcount++; -out: - raw_spin_unlock_irqrestore(&iommu->lock, flags); - return ret; -} - -static int perfopt_put(struct amd_iommu *iommu) -{ - unsigned long flags; - int ret = 0; - - if (!iommu->mmio_base) - return 0; - - raw_spin_lock_irqsave(&iommu->lock, flags); - if (iommu->perfopt_refcount > 0 && --iommu->perfopt_refcount == 0) - ret = __perfopt_write(iommu, false); - raw_spin_unlock_irqrestore(&iommu->lock, flags); - return ret; -} - -/* - * Force PERF_OPT_EN off without touching the refcount (used on init, shutdown, - * and suspend). The count is preserved so amd_iommu_perfopt_restore() can - * re-arm on resume. - */ -int amd_iommu_perfopt_clear(struct amd_iommu *iommu) -{ - unsigned long flags; - int ret; - - if (!iommu->mmio_base) - return 0; - - raw_spin_lock_irqsave(&iommu->lock, flags); - ret = __perfopt_write(iommu, false); - raw_spin_unlock_irqrestore(&iommu->lock, flags); - return ret; -} - -/* - * Re-assert PERF_OPT_EN from the refcount after the hardware was reprogrammed on - * resume, so devices armed before suspend keep the optimization without each - * consumer driver re-arming. - */ -int amd_iommu_perfopt_restore(struct amd_iommu *iommu) -{ - unsigned long flags; - int ret; - - if (!iommu->mmio_base) - return 0; - - raw_spin_lock_irqsave(&iommu->lock, flags); - ret = __perfopt_write(iommu, iommu->perfopt_refcount > 0); - raw_spin_unlock_irqrestore(&iommu->lock, flags); - return ret; -} - -int amd_iommu_enable_perfopt(struct pci_dev *pdev) -{ - struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev); - struct amd_iommu *iommu = rlookup_amd_iommu(&pdev->dev); - struct protection_domain *domain; - int ret; - - if (!iommu || !dev_data) - return -ENODEV; - - if (!(iommu->features & FEATURE_PERF_OPT)) - return -ENODEV; - - domain = dev_data->domain; - if (!domain) - return -ENODEV; - - /* Already armed for this device (e.g. re-entry on resume). */ - if (dev_data->perfopt) - return 0; - - /* - * The bit is only architecturally valid while the device is untranslated: - * identity domain with ATS/PRI/PASID off. The identity domain is - * SVA-capable so attach_device() enabled ATS/PRI/PASID and built a GCR3 - * table. Re-home the device onto the same identity domain with - * perfopt set, so the attach_device() skip_caps path leaves - * ATS/PRI/PASID off and no GCR3 table. This follows the detach/attach - * pattern used by amd_iommu_attach_device(). - * - * Locking: this and amd_iommu_disable_perfopt() run only from the - * consumer driver's bind/unbind path. group->mutex is not exposed to - * drivers, but a device bound to its native driver cannot have its domain - * changed concurrently by the core (VFIO ownership is mutually exclusive; - * sysfs domain changes require an unused group), so the detach/attach pair - * is serialized without it. - */ - dev_data->perfopt = true; - detach_device(&pdev->dev); - ret = attach_device(&pdev->dev, domain); - if (ret) - goto err_restore; - - ret = perfopt_get(iommu); - if (ret) - goto err_rearm; - - dev_info_once(&pdev->dev, "PerfOpt armed on IOMMU%d\n", iommu->index); - return 0; - -err_rearm: - detach_device(&pdev->dev); -err_restore: - dev_data->perfopt = false; - if (attach_device(&pdev->dev, domain)) - pci_err(pdev, "failed to restore state after PerfOpt setup; device left detached\n"); - dev_err_once(&pdev->dev, "PerfOpt failed to arm on IOMMU%d (%d)\n", - iommu->index, ret); - return ret; -} -EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt); - -void amd_iommu_disable_perfopt(struct pci_dev *pdev) -{ - struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev); - struct amd_iommu *iommu = rlookup_amd_iommu(&pdev->dev); - struct protection_domain *domain; - - if (!iommu || !dev_data || !dev_data->perfopt || !dev_data->domain) - return; - - if (WARN_ON(perfopt_put(iommu))) - pci_err(pdev, "failed to clear PerfOpt\n"); - - /* - * Restore ATS/PRI/PASID (and thus SVA) by re-homing the device onto its - * identity domain with the flag cleared, so a later bind without PerfOpt - * sees a normally-capable device. See the locking note in - * amd_iommu_enable_perfopt(). - */ - domain = dev_data->domain; - dev_data->perfopt = false; - detach_device(&pdev->dev); - if (attach_device(&pdev->dev, domain)) - pci_err(pdev, "failed to restore caps after PerfOpt disable\n"); -} -EXPORT_SYMBOL_GPL(amd_iommu_disable_perfopt); static struct iommu_device *amd_iommu_probe_device(struct device *dev) { struct iommu_device *iommu_dev; @@ -2736,26 +2555,6 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev) return iommu_dev; } -static void amd_iommu_release_device(struct device *dev) -{ - struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); - struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data); - - if (dev_data->perfopt) { - if (WARN_ON(perfopt_put(iommu))) - dev_err(dev, "IOMMU%d: failed to clear PerfOpt on release\n", - iommu->index); - dev_data->perfopt = false; - } - - WARN_ON(dev_data->domain); - - /* - * We keep dev_data around for unplugged devices and reuse it when the - * device is re-plugged - not doing so would introduce a ton of races. - */ -} - static struct iommu_group *amd_iommu_device_group(struct device *dev) { if (dev_is_pci(dev)) @@ -3116,24 +2915,32 @@ void amd_iommu_domain_free(struct iommu_domain *dom) kfree(domain); } +/* Each IOMMU has at most one PerfOpt-eligible GPU. */ +static int set_device_perfopt(struct iommu_dev_data *dev_data, bool enable) +{ + struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data); + + if (!dev_data->perfopt) + return 0; + + guard(raw_spinlock_irqsave)(&iommu->lock); + if (iommu->perfopt_enabled == enable) + return 0; + + return amd_iommu_perfopt_set(iommu, enable); +} + static int blocked_domain_attach_device(struct iommu_domain *domain, struct device *dev, struct iommu_domain *old) { struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); - struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data); + int ret; - /* - * blocked_domain is also the .release_domain, so this is the normal - * teardown path: drop the reference and clear the flag here too, and - * don't fail teardown if the WARN-guarded write doesn't stick. - */ - if (dev_data->perfopt) { - if (WARN_ON(perfopt_put(iommu))) - dev_err(dev, "IOMMU%d: failed to clear PerfOpt for blocked domain\n", - iommu->index); - dev_data->perfopt = false; - } + /* Clearing the DTE cannot block DMA while PerfOpt bypasses it. */ + ret = set_device_perfopt(dev_data, false); + if (ret) + return ret; if (dev_data->domain) detach_device(dev); @@ -3167,6 +2974,9 @@ static struct protection_domain identity_domain; static int amd_iommu_identity_attach(struct iommu_domain *dom, struct device *dev, struct iommu_domain *old) { + struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); + int ret; + /* * Don't allow attaching a device to the identity domain if SNP is * enabled and SNP Mode0 support is not present. @@ -3174,7 +2984,13 @@ static int amd_iommu_identity_attach(struct iommu_domain *dom, struct device *de if (amd_iommu_snp_en && !amd_iommu_snp_mode0_sup) return -EINVAL; - return amd_iommu_attach_device(dom, dev, old); + ret = amd_iommu_attach_device(dom, dev, old); + if (ret) + return ret; + + /* PerfOpt is optional; the identity attachment is already complete. */ + set_device_perfopt(dev_data, true); + return 0; } static const struct iommu_domain_ops identity_domain_ops = { @@ -3202,9 +3018,6 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, struct device *dev, struct amd_iommu *iommu = get_amd_iommu_from_dev(dev); int ret; - if (dev_data->perfopt && !pdom_is_in_pt_mode(domain)) - return -EBUSY; - /* * Skip attach device to domain if new domain is same as * devices current domain @@ -3221,6 +3034,12 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, struct device *dev, if (dom->dirty_ops && !amd_iommu_hd_support(iommu)) return -EINVAL; + if (!pdom_is_in_pt_mode(domain)) { + ret = set_device_perfopt(dev_data, false); + if (ret) + return ret; + } + if (dev_data->domain) detach_device(dev); @@ -3372,6 +3191,7 @@ static bool amd_iommu_is_attach_deferred(struct device *dev) static bool quirks_force_identity_mapping(struct pci_dev *pdev) { + struct pci_dev *bridge; int class = pdev->class >> 8; /* AMD GPU vendor ID */ @@ -3383,7 +3203,8 @@ static bool quirks_force_identity_mapping(struct pci_dev *pdev) class != PCI_CLASS_DISPLAY_OTHER) return false; - if (pci_upstream_bridge(pdev)->vendor == PCI_VENDOR_ID_ATI) + bridge = pci_upstream_bridge(pdev); + if (bridge && bridge->vendor == PCI_VENDOR_ID_ATI) return false; /* It is the GPU in an APU, force identity domain */ @@ -3415,6 +3236,9 @@ static int amd_iommu_def_domain_type(struct device *dev) if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) return 0; + dev_data->perfopt = get_amd_iommu_from_dev_data(dev_data)->features & + FEATURE_PERF_OPT; + return IOMMU_DOMAIN_IDENTITY; } @@ -3436,7 +3260,6 @@ const struct iommu_ops amd_iommu_ops = { .domain_alloc_paging_flags = amd_iommu_domain_alloc_paging_flags, .domain_alloc_sva = amd_iommu_domain_alloc_sva, .probe_device = amd_iommu_probe_device, - .release_device = amd_iommu_release_device, .device_group = amd_iommu_device_group, .get_resv_regions = amd_iommu_get_resv_regions, .is_attach_deferred = amd_iommu_is_attach_deferred, diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index ebf4547d32b41d..d8302128b46546 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -1166,7 +1166,7 @@ static int apple_dart_probe(struct platform_device *pdev) struct apple_dart *dart; struct device *dev = &pdev->dev; - dart = devm_kzalloc(dev, sizeof(*dart), GFP_KERNEL); + dart = devm_kzalloc_obj(dev, *dart); if (!dart) return -ENOMEM; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6d4520c473086f..100b34f070328f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4809,8 +4809,8 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) return -ENOMEM; } - cfg->l2.l2ptrs = devm_kcalloc(smmu->dev, cfg->l2.num_l1_ents, - sizeof(*cfg->l2.l2ptrs), GFP_KERNEL); + cfg->l2.l2ptrs = devm_kzalloc_objs(smmu->dev, *cfg->l2.l2ptrs, + cfg->l2.num_l1_ents); if (!cfg->l2.l2ptrs) return -ENOMEM; @@ -5787,7 +5787,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) struct arm_smmu_device *smmu; struct device *dev = &pdev->dev; - smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); + smmu = devm_kzalloc_obj(dev, *smmu); if (!smmu) return -ENOMEM; smmu->dev = dev; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c index 531b29fbf49242..2225fc9c8c055f 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c @@ -479,7 +479,7 @@ int qcom_tbu_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct qcom_tbu *tbu; - tbu = devm_kzalloc(dev, sizeof(*tbu), GFP_KERNEL); + tbu = devm_kzalloc_obj(dev, *tbu); if (!tbu) return -ENOMEM; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 889a0966d36cdb..8d50a4ad221ddc 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -186,7 +186,7 @@ static int arm_smmu_register_legacy_master(struct device *dev, if (err) return err; - sids = kcalloc(it.cur_count, sizeof(*sids), GFP_KERNEL); + sids = kzalloc_objs(*sids, it.cur_count); if (!sids) return -ENOMEM; @@ -1815,8 +1815,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) } /* Zero-initialised to mark as invalid */ - smmu->smrs = devm_kcalloc(smmu->dev, size, sizeof(*smmu->smrs), - GFP_KERNEL); + smmu->smrs = devm_kzalloc_objs(smmu->dev, *smmu->smrs, size); if (!smmu->smrs) return -ENOMEM; @@ -1824,8 +1823,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) "\tstream matching with %u register groups", size); } /* s2cr->type == 0 means translation, so initialise explicitly */ - smmu->s2crs = devm_kmalloc_array(smmu->dev, size, sizeof(*smmu->s2crs), - GFP_KERNEL); + smmu->s2crs = devm_kmalloc_objs(smmu->dev, *smmu->s2crs, size); if (!smmu->s2crs) return -ENOMEM; for (i = 0; i < size; i++) @@ -1863,8 +1861,8 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) } dev_notice(smmu->dev, "\t%u context banks (%u stage-2 only)\n", smmu->num_context_banks, smmu->num_s2_context_banks); - smmu->cbs = devm_kcalloc(smmu->dev, smmu->num_context_banks, - sizeof(*smmu->cbs), GFP_KERNEL); + smmu->cbs = devm_kzalloc_objs(smmu->dev, *smmu->cbs, + smmu->num_context_banks); if (!smmu->cbs) return -ENOMEM; @@ -2124,7 +2122,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) u32 global_irqs, pmu_irqs; irqreturn_t (*global_fault)(int irq, void *dev); - smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); + smmu = devm_kzalloc_obj(dev, *smmu); if (!smmu) { dev_err(dev, "failed to allocate arm_smmu_device\n"); return -ENOMEM; @@ -2161,8 +2159,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) "found %d interrupts but expected at least %d\n", num_irqs, global_irqs + pmu_irqs + 1); - smmu->irqs = devm_kcalloc(dev, smmu->num_context_irqs, - sizeof(*smmu->irqs), GFP_KERNEL); + smmu->irqs = devm_kzalloc_objs(dev, *smmu->irqs, smmu->num_context_irqs); if (!smmu->irqs) return dev_err_probe(dev, -ENOMEM, "failed to allocate %d irqs\n", smmu->num_context_irqs); diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 21d18ce67b982b..96903cd9cfc2e1 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -683,7 +683,7 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev) struct qcom_iommu_dev *qcom_iommu = dev_get_drvdata(dev->parent); int ret, irq; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -788,8 +788,7 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) for_each_child_of_node(dev->of_node, child) max_asid = max(max_asid, get_asid(child)); - qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid + 1), - GFP_KERNEL); + qcom_iommu = devm_kzalloc_flex(dev, *qcom_iommu, ctxs, max_asid + 1); if (!qcom_iommu) return -ENOMEM; qcom_iommu->max_asid = max_asid; diff --git a/drivers/iommu/bcm2712-iommu-cache.c b/drivers/iommu/bcm2712-iommu-cache.c index 8ed436943b8304..afaeec75284b66 100644 --- a/drivers/iommu/bcm2712-iommu-cache.c +++ b/drivers/iommu/bcm2712-iommu-cache.c @@ -53,7 +53,7 @@ static int bcm2712_iommu_cache_probe(struct platform_device *pdev) { struct bcm2712_iommu_cache *cache; - cache = devm_kzalloc(&pdev->dev, sizeof(*cache), GFP_KERNEL); + cache = devm_kzalloc_obj(&pdev->dev, *cache); if (!cache) return -ENOMEM; diff --git a/drivers/iommu/bcm2712-iommu.c b/drivers/iommu/bcm2712-iommu.c index 301855475c88bf..1bbb14fa102746 100644 --- a/drivers/iommu/bcm2712-iommu.c +++ b/drivers/iommu/bcm2712-iommu.c @@ -503,7 +503,7 @@ static int bcm2712_iommu_probe(struct platform_device *pdev) struct bcm2712_iommu *mmu; int ret; - mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL); + mmu = devm_kzalloc_obj(dev, *mmu); if (!mmu) return -ENOMEM; diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 0bca3662fdc281..7c337ba96a0113 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -760,7 +760,7 @@ static int exynos_sysmmu_probe(struct platform_device *pdev) struct sysmmu_drvdata *data; struct resource *res; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/iommu/hyperv/hv-iommu-guest.c b/drivers/iommu/hyperv/hv-iommu-guest.c index 876a22f21f1ee4..9f4fa431509168 100644 --- a/drivers/iommu/hyperv/hv-iommu-guest.c +++ b/drivers/iommu/hyperv/hv-iommu-guest.c @@ -502,7 +502,7 @@ static struct iommu_domain *hv_iommu_domain_alloc_paging(struct device *dev) }, }; - hv_domain = kzalloc_obj(*hv_domain, GFP_KERNEL); + hv_domain = kzalloc_obj(*hv_domain); if (!hv_domain) return ERR_PTR(-ENOMEM); @@ -645,7 +645,7 @@ int __init hv_iommu_init(void) iommu_detected = 1; pci_request_acs(); - hv_iommu = kzalloc_obj(*hv_iommu, GFP_KERNEL); + hv_iommu = kzalloc_obj(*hv_iommu); if (!hv_iommu) return -ENOMEM; diff --git a/drivers/iommu/intel/perfmon.c b/drivers/iommu/intel/perfmon.c index eb1df7a9b3c76a..e40ed253eaa909 100644 --- a/drivers/iommu/intel/perfmon.c +++ b/drivers/iommu/intel/perfmon.c @@ -607,7 +607,7 @@ int alloc_iommu_pmu(struct intel_iommu *iommu) iommu_pmu->cntr_stride = pcap_cntr_stride(perfcap); iommu_pmu->num_eg = pcap_num_event_group(perfcap); - iommu_pmu->evcap = kcalloc(iommu_pmu->num_eg, sizeof(u64), GFP_KERNEL); + iommu_pmu->evcap = kzalloc_objs(u64, iommu_pmu->num_eg); if (!iommu_pmu->evcap) { ret = -ENOMEM; goto free_pmu; @@ -628,7 +628,7 @@ int alloc_iommu_pmu(struct intel_iommu *iommu) goto free_pmu_evcap; } for (i = 0; i < iommu_pmu->num_cntr; i++) { - iommu_pmu->cntr_evcap[i] = kcalloc(iommu_pmu->num_eg, sizeof(u32), GFP_KERNEL); + iommu_pmu->cntr_evcap[i] = kzalloc_objs(u32, iommu_pmu->num_eg); if (!iommu_pmu->cntr_evcap[i]) { ret = -ENOMEM; goto free_pmu_cntr_evcap; diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9386b752dea2de..f32dceb3223779 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -1009,7 +1009,7 @@ static int ipmmu_probe(struct platform_device *pdev) int irq; int ret; - mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL); + mmu = devm_kzalloc_obj(&pdev->dev, *mmu); if (!mmu) { dev_err(&pdev->dev, "cannot allocate device data\n"); return -ENOMEM; diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 4ef1e8c8244b02..d79d5ff2a5517c 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -721,7 +721,7 @@ static int msm_iommu_probe(struct platform_device *pdev) struct msm_iommu_dev *iommu; int ret, par, val; - iommu = devm_kzalloc(&pdev->dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(&pdev->dev, *iommu); if (!iommu) return -ENOMEM; diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index b52e16b06760fc..e3d471701c2fab 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1304,7 +1304,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) struct mtk_iommu_bank_data *bank; void __iomem *base; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; data->dev = dev; diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index e907c99531423e..66df5bb67a47eb 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -615,7 +615,7 @@ static int mtk_iommu_v1_probe(struct platform_device *pdev) void *protect; int larb_nr, ret, i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/iommu/riscv/iommu-pci.c b/drivers/iommu/riscv/iommu-pci.c index 8abf52dfb4c9bc..3bc3972c0aa16b 100644 --- a/drivers/iommu/riscv/iommu-pci.c +++ b/drivers/iommu/riscv/iommu-pci.c @@ -50,7 +50,7 @@ static int riscv_iommu_pci_probe(struct pci_dev *pdev, const struct pci_device_i if (rc) return dev_err_probe(dev, rc, "pcim_iomap_regions failed\n"); - iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(dev, *iommu); if (!iommu) return -ENOMEM; diff --git a/drivers/iommu/riscv/iommu-platform.c b/drivers/iommu/riscv/iommu-platform.c index 399ba8fe1b3e55..9cb8bb1e801337 100644 --- a/drivers/iommu/riscv/iommu-platform.c +++ b/drivers/iommu/riscv/iommu-platform.c @@ -52,7 +52,7 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev) struct resource *res = NULL; int vec, ret; - iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(dev, *iommu); if (!iommu) return -ENOMEM; diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 21af2f621c7688..1fa3110b142ada 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1186,7 +1186,7 @@ static int rk_iommu_of_xlate(struct device *dev, iommu_dev = of_find_device_by_node(args->np); - data = devm_kzalloc(&iommu_dev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&iommu_dev->dev, *data); if (!data) return -ENOMEM; @@ -1222,7 +1222,7 @@ static int rk_iommu_probe(struct platform_device *pdev) int num_res = pdev->num_resources; int err, i; - iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(dev, *iommu); if (!iommu) return -ENOMEM; @@ -1236,8 +1236,7 @@ static int rk_iommu_probe(struct platform_device *pdev) if (!iommu->rk_ops) return -ENOENT; - iommu->bases = devm_kcalloc(dev, num_res, sizeof(*iommu->bases), - GFP_KERNEL); + iommu->bases = devm_kzalloc_objs(dev, *iommu->bases, num_res); if (!iommu->bases) return -ENOMEM; diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index c1a34445d244fb..39af62f960aa29 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -464,7 +464,7 @@ static int sprd_iommu_probe(struct platform_device *pdev) void __iomem *base; int ret; - sdev = devm_kzalloc(dev, sizeof(*sdev), GFP_KERNEL); + sdev = devm_kzalloc_obj(dev, *sdev); if (!sdev) return -ENOMEM; diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index be3f1ce696ba29..acdccb7c9eefac 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -1001,7 +1001,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev) struct sun50i_iommu *iommu; int ret, irq; - iommu = devm_kzalloc(&pdev->dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(&pdev->dev, *iommu); if (!iommu) return -ENOMEM; spin_lock_init(&iommu->iommu_lock); diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 67e7a7b925f0cc..c7e407d7415773 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -301,7 +301,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) return NULL; } - as->count = kcalloc(SMMU_NUM_PDE, sizeof(u32), GFP_KERNEL); + as->count = kzalloc_objs(u32, SMMU_NUM_PDE); if (!as->count) { iommu_free_pages(as->pd); kfree(as); @@ -934,7 +934,7 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev) return grp; } - group = devm_kzalloc(smmu->dev, sizeof(*group), GFP_KERNEL); + group = devm_kzalloc_obj(smmu->dev, *group); if (!group) { mutex_unlock(&smmu->lock); return NULL; @@ -1110,7 +1110,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev, u32 value; int err; - smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); + smmu = devm_kzalloc_obj(dev, *smmu); if (!smmu) return ERR_PTR(-ENOMEM); diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 587fc13197f122..7fde3ddf231af7 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -1130,8 +1130,7 @@ static int viommu_fill_evtq(struct viommu_dev *viommu) struct virtqueue *vq = viommu->vqs[VIOMMU_EVENT_VQ]; size_t nr_evts = vq->num_free; - viommu->evts = evts = devm_kmalloc_array(viommu->dev, nr_evts, - sizeof(*evts), GFP_KERNEL); + viommu->evts = evts = devm_kmalloc_objs(viommu->dev, *evts, nr_evts); if (!evts) return -ENOMEM; @@ -1158,7 +1157,7 @@ static int viommu_probe(struct virtio_device *vdev) !virtio_has_feature(vdev, VIRTIO_IOMMU_F_MAP_UNMAP)) return -ENODEV; - viommu = devm_kzalloc(dev, sizeof(*viommu), GFP_KERNEL); + viommu = devm_kzalloc_obj(dev, *viommu); if (!viommu) return -ENOMEM; @@ -1227,12 +1226,12 @@ static int viommu_probe(struct virtio_device *vdev) /* Populate the event queue with buffers */ ret = viommu_fill_evtq(viommu); if (ret) - goto err_free_vqs; + goto err_reset_vdev; ret = iommu_device_sysfs_add(&viommu->iommu, dev, NULL, "%s", virtio_bus_name(vdev)); if (ret) - goto err_free_vqs; + goto err_reset_vdev; vdev->priv = viommu; @@ -1244,6 +1243,8 @@ static int viommu_probe(struct virtio_device *vdev) return 0; +err_reset_vdev: + virtio_reset_device(vdev); err_free_vqs: vdev->config->del_vqs(vdev); diff --git a/drivers/iommu/vsi-iommu.c b/drivers/iommu/vsi-iommu.c index 5dac20b143a550..0633fe82d44366 100644 --- a/drivers/iommu/vsi-iommu.c +++ b/drivers/iommu/vsi-iommu.c @@ -672,7 +672,7 @@ static int vsi_iommu_probe(struct platform_device *pdev) struct vsi_iommu *iommu; int err; - iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); + iommu = devm_kzalloc_obj(dev, *iommu); if (!iommu) return -ENOMEM; diff --git a/drivers/irqchip/irq-ast2700-intc0.c b/drivers/irqchip/irq-ast2700-intc0.c index 1e375e9dffae1b..0a0c34cd1e8385 100644 --- a/drivers/irqchip/irq-ast2700-intc0.c +++ b/drivers/irqchip/irq-ast2700-intc0.c @@ -536,7 +536,7 @@ static int aspeed_intc0_probe(struct platform_device *pdev, return -ENODEV; } - intc0 = devm_kzalloc(&pdev->dev, sizeof(*intc0), GFP_KERNEL); + intc0 = devm_kzalloc_obj(&pdev->dev, *intc0); if (!intc0) return -ENOMEM; diff --git a/drivers/irqchip/irq-ast2700-intc1.c b/drivers/irqchip/irq-ast2700-intc1.c index df6acbafce2d01..aa5240ce1c57f8 100644 --- a/drivers/irqchip/irq-ast2700-intc1.c +++ b/drivers/irqchip/irq-ast2700-intc1.c @@ -245,7 +245,7 @@ static int aspeed_intc1_probe(struct platform_device *pdev, if (!host) return -ENODEV; - intc1 = devm_kzalloc(&pdev->dev, sizeof(*intc1), GFP_KERNEL); + intc1 = devm_kzalloc_obj(&pdev->dev, *intc1); if (!intc1) return -ENOMEM; diff --git a/drivers/irqchip/irq-ast2700.c b/drivers/irqchip/irq-ast2700.c index 1e4c4a624dbf50..035e2f43b8cf8a 100644 --- a/drivers/irqchip/irq-ast2700.c +++ b/drivers/irqchip/irq-ast2700.c @@ -39,10 +39,8 @@ int aspeed_intc_populate_ranges(struct device *dev, return -EINVAL; /* Over-estimate the range entry count for now */ - ranges->ranges = devm_kmalloc_array(dev, - len / (ASPEED_INTC_RANGE_FIXED_CELLS * sizeof(__be32)), - sizeof(*ranges->ranges), - GFP_KERNEL); + ranges->ranges = devm_kmalloc_objs(dev, *ranges->ranges, + len / (ASPEED_INTC_RANGE_FIXED_CELLS * sizeof(__be32))); if (!ranges->ranges) return -ENOMEM; diff --git a/drivers/irqchip/irq-atmel-aic5.c b/drivers/irqchip/irq-atmel-aic5.c index 07a317ed06ef43..efc791da583282 100644 --- a/drivers/irqchip/irq-atmel-aic5.c +++ b/drivers/irqchip/irq-atmel-aic5.c @@ -358,8 +358,8 @@ static int __init sama5d2_aic5_of_init(struct device_node *node, struct device_node *parent) { #ifdef CONFIG_PM - smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32, - sizeof(*smr_cache), GFP_KERNEL); + smr_cache = kzalloc_objs(*smr_cache, + DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32); if (!smr_cache) return -ENOMEM; #endif diff --git a/drivers/irqchip/irq-csky-mpintc.c b/drivers/irqchip/irq-csky-mpintc.c index 1d1f5091f26f56..59fba46c0b3b8a 100644 --- a/drivers/irqchip/irq-csky-mpintc.c +++ b/drivers/irqchip/irq-csky-mpintc.c @@ -240,7 +240,7 @@ csky_mpintc_init(struct device_node *node, struct device_node *parent) if (ret < 0) nr_irq = INTC_IRQS; - __trigger = kcalloc(nr_irq, sizeof(unsigned long), GFP_KERNEL); + __trigger = kzalloc_objs(unsigned long, nr_irq); if (__trigger == NULL) return -ENXIO; diff --git a/drivers/irqchip/irq-gic-pm.c b/drivers/irqchip/irq-gic-pm.c index a275a8071a2534..a17efdaad14cc2 100644 --- a/drivers/irqchip/irq-gic-pm.c +++ b/drivers/irqchip/irq-gic-pm.c @@ -75,7 +75,7 @@ static int gic_probe(struct platform_device *pdev) return -ENODEV; } - chip_pm = devm_kzalloc(dev, sizeof(*chip_pm), GFP_KERNEL); + chip_pm = devm_kzalloc_obj(dev, *chip_pm); if (!chip_pm) return -ENOMEM; @@ -85,8 +85,7 @@ static int gic_probe(struct platform_device *pdev) return -EINVAL; } - chip_pm->clks = devm_kcalloc(dev, data->num_clocks, - sizeof(*chip_pm->clks), GFP_KERNEL); + chip_pm->clks = devm_kzalloc_objs(dev, *chip_pm->clks, data->num_clocks); if (!chip_pm->clks) return -ENOMEM; diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 282e4bafb084f6..c952c069f93738 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -3501,10 +3501,9 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, if (alloc_lpis) { lpi_map = its_lpi_alloc(nvecs, &lpi_base, &nr_lpis); if (lpi_map) - col_map = kcalloc(nr_lpis, sizeof(*col_map), - GFP_KERNEL); + col_map = kzalloc_objs(*col_map, nr_lpis); } else { - col_map = kcalloc(nr_ites, sizeof(*col_map), GFP_KERNEL); + col_map = kzalloc_objs(*col_map, nr_ites); nr_lpis = 0; lpi_base = 0; } diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c index 28e39b065de0ee..f876dc0de1b963 100644 --- a/drivers/irqchip/irq-gic-v5-its.c +++ b/drivers/irqchip/irq-gic-v5-its.c @@ -167,7 +167,7 @@ static int gicv5_its_create_itt_linear(struct gicv5_its_chip_data *its, unsigned int num_ents = BIT(event_id_bits); __le64 *itt; - itt = kcalloc(num_ents, sizeof(*itt), GFP_KERNEL); + itt = kzalloc_objs(*itt, num_ents); if (!itt) return -ENOMEM; @@ -211,11 +211,11 @@ static int gicv5_its_create_itt_two_level(struct gicv5_its_chip_data *its, num_ents = BIT(l1_bits); - itt_l1 = kcalloc(num_ents, sizeof(*itt_l1), GFP_KERNEL); + itt_l1 = kzalloc_objs(*itt_l1, num_ents); if (!itt_l1) return -ENOMEM; - l2ptrs = kcalloc(num_ents, sizeof(*l2ptrs), GFP_KERNEL); + l2ptrs = kzalloc_objs(*l2ptrs, num_ents); if (!l2ptrs) { kfree(itt_l1); return -ENOMEM; @@ -242,7 +242,7 @@ static int gicv5_its_create_itt_two_level(struct gicv5_its_chip_data *its, span = i == complete_tables ? final_span : l2_bits; - itt_l2 = kcalloc(BIT(span), sizeof(*itt_l2), GFP_KERNEL); + itt_l2 = kzalloc_objs(*itt_l2, BIT(span)); if (!itt_l2) { ret = -ENOMEM; goto out_free; @@ -403,7 +403,7 @@ static int gicv5_its_alloc_l2_devtab(struct gicv5_its_chip_data *its, if (span > l2_bits) span = l2_bits; - l2devtab = kcalloc(BIT(span), sizeof(*l2devtab), GFP_KERNEL); + l2devtab = kzalloc_objs(*l2devtab, BIT(span)); if (!l2devtab) return -ENOMEM; @@ -593,7 +593,7 @@ static int gicv5_its_alloc_devtab_linear(struct gicv5_its_chip_data *its, device_id_bits = device_id_cap; } - devtab = kcalloc(BIT(device_id_bits), sizeof(*devtab), GFP_KERNEL); + devtab = kzalloc_objs(*devtab, BIT(device_id_bits)); if (!devtab) return -ENOMEM; @@ -649,11 +649,11 @@ static int gicv5_its_alloc_devtab_two_level(struct gicv5_its_chip_data *its, l1_sz = KMALLOC_MAX_SIZE; } - l1devtab = kcalloc(BIT(l1_bits), sizeof(*l1devtab), GFP_KERNEL); + l1devtab = kzalloc_objs(*l1devtab, BIT(l1_bits)); if (!l1devtab) return -ENOMEM; - l2ptrs = kcalloc(BIT(l1_bits), sizeof(*l2ptrs), GFP_KERNEL); + l2ptrs = kzalloc_objs(*l2ptrs, BIT(l1_bits)); if (!l2ptrs) { kfree(l1devtab); return -ENOMEM; diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index a5ca04e9be6436..420261208cd0b5 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -1419,7 +1419,7 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq) if (!dev || !dev->of_node || !gic || !irq) return -EINVAL; - *gic = devm_kzalloc(dev, sizeof(**gic), GFP_KERNEL); + *gic = devm_kzalloc_obj(dev, **gic); if (!*gic) return -ENOMEM; diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c index de2a8f98f62555..c7914fea3d1f98 100644 --- a/drivers/irqchip/irq-imx-intmux.c +++ b/drivers/irqchip/irq-imx-intmux.c @@ -215,7 +215,7 @@ static int imx_intmux_probe(struct platform_device *pdev) return -EINVAL; } - data = devm_kzalloc(&pdev->dev, struct_size(data, irqchip_data, channum), GFP_KERNEL); + data = devm_kzalloc_flex(&pdev->dev, *data, irqchip_data, channum); if (!data) return -ENOMEM; diff --git a/drivers/irqchip/irq-imx-irqsteer.c b/drivers/irqchip/irq-imx-irqsteer.c index 87b07f517be35e..8b58da82c3679e 100644 --- a/drivers/irqchip/irq-imx-irqsteer.c +++ b/drivers/irqchip/irq-imx-irqsteer.c @@ -182,7 +182,7 @@ static int imx_irqsteer_probe(struct platform_device *pdev) u32 irqs_num; int i, ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/irqchip/irq-imx-mu-msi.c b/drivers/irqchip/irq-imx-mu-msi.c index c598f2f52fc6f3..6d7baeeb2bc88f 100644 --- a/drivers/irqchip/irq-imx-mu-msi.c +++ b/drivers/irqchip/irq-imx-mu-msi.c @@ -311,7 +311,7 @@ static int imx_mu_probe(struct platform_device *pdev, struct device_node *parent dev = &pdev->dev; - msi_data = devm_kzalloc(&pdev->dev, sizeof(*msi_data), GFP_KERNEL); + msi_data = devm_kzalloc_obj(&pdev->dev, *msi_data); if (!msi_data) return -ENOMEM; diff --git a/drivers/irqchip/irq-keystone.c b/drivers/irqchip/irq-keystone.c index 922fff09354f96..889cd48a7192a6 100644 --- a/drivers/irqchip/irq-keystone.c +++ b/drivers/irqchip/irq-keystone.c @@ -137,7 +137,7 @@ static int keystone_irq_probe(struct platform_device *pdev) if (np == NULL) return -EINVAL; - kirq = devm_kzalloc(dev, sizeof(*kirq), GFP_KERNEL); + kirq = devm_kzalloc_obj(dev, *kirq); if (!kirq) return -ENOMEM; diff --git a/drivers/irqchip/irq-lan966x-oic.c b/drivers/irqchip/irq-lan966x-oic.c index 5122f3f1b353c5..40e1f26201da01 100644 --- a/drivers/irqchip/irq-lan966x-oic.c +++ b/drivers/irqchip/irq-lan966x-oic.c @@ -231,7 +231,7 @@ static int lan966x_oic_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct irq_domain *domain; - lan966x_oic = devm_kmalloc(dev, sizeof(*lan966x_oic), GFP_KERNEL); + lan966x_oic = devm_kmalloc_obj(dev, *lan966x_oic); if (!lan966x_oic) return -ENOMEM; diff --git a/drivers/irqchip/irq-ls-extirq.c b/drivers/irqchip/irq-ls-extirq.c index d724fe8439801e..b791cb03a44abf 100644 --- a/drivers/irqchip/irq-ls-extirq.c +++ b/drivers/irqchip/irq-ls-extirq.c @@ -185,7 +185,7 @@ static int ls_extirq_probe(struct platform_device *pdev) if (!parent_domain) return dev_err_probe(dev, -EPROBE_DEFER, "Cannot find parent domain\n"); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n"); diff --git a/drivers/irqchip/irq-ls-scfg-msi.c b/drivers/irqchip/irq-ls-scfg-msi.c index 4910f364e568bf..50ce01c9cd2d5d 100644 --- a/drivers/irqchip/irq-ls-scfg-msi.c +++ b/drivers/irqchip/irq-ls-scfg-msi.c @@ -333,7 +333,7 @@ static int ls_scfg_msi_probe(struct platform_device *pdev) struct resource *res; int i, ret; - msi_data = devm_kzalloc(&pdev->dev, sizeof(*msi_data), GFP_KERNEL); + msi_data = devm_kzalloc_obj(&pdev->dev, *msi_data); if (!msi_data) return -ENOMEM; @@ -374,9 +374,8 @@ static int ls_scfg_msi_probe(struct platform_device *pdev) msi_affinity_flag = 0; } - msi_data->msir = devm_kcalloc(&pdev->dev, msi_data->msir_num, - sizeof(*msi_data->msir), - GFP_KERNEL); + msi_data->msir = devm_kzalloc_objs(&pdev->dev, *msi_data->msir, + msi_data->msir_num); if (!msi_data->msir) return -ENOMEM; diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c index 0b4d78a0bbdeac..ee0d426e6fc410 100644 --- a/drivers/irqchip/irq-mbigen.c +++ b/drivers/irqchip/irq-mbigen.c @@ -304,7 +304,7 @@ static int mbigen_device_probe(struct platform_device *pdev) struct resource *res; int err; - mgn_chip = devm_kzalloc(&pdev->dev, sizeof(*mgn_chip), GFP_KERNEL); + mgn_chip = devm_kzalloc_obj(&pdev->dev, *mgn_chip); if (!mgn_chip) return -ENOMEM; diff --git a/drivers/irqchip/irq-mtk-sysirq.c b/drivers/irqchip/irq-mtk-sysirq.c index 50f88293b4ccf3..552d01918b0685 100644 --- a/drivers/irqchip/irq-mtk-sysirq.c +++ b/drivers/irqchip/irq-mtk-sysirq.c @@ -146,9 +146,8 @@ static int __init mtk_sysirq_of_init(struct device_node *node, goto out_free_chip; } - chip_data->intpol_words = kcalloc(nr_intpol_bases, - sizeof(*chip_data->intpol_words), - GFP_KERNEL); + chip_data->intpol_words = kzalloc_objs(*chip_data->intpol_words, + nr_intpol_bases); if (!chip_data->intpol_words) { ret = -ENOMEM; goto out_free_chip; @@ -184,9 +183,7 @@ static int __init mtk_sysirq_of_init(struct device_node *node, goto out_free_intpol; } - chip_data->which_word = kcalloc(intpol_num, - sizeof(*chip_data->which_word), - GFP_KERNEL); + chip_data->which_word = kzalloc_objs(*chip_data->which_word, intpol_num); if (!chip_data->which_word) { ret = -ENOMEM; goto out_free_intpol_idx; diff --git a/drivers/irqchip/irq-mvebu-gicp.c b/drivers/irqchip/irq-mvebu-gicp.c index 667bde3c651ff2..10ff1f49425ec6 100644 --- a/drivers/irqchip/irq-mvebu-gicp.c +++ b/drivers/irqchip/irq-mvebu-gicp.c @@ -180,7 +180,7 @@ static int mvebu_gicp_probe(struct platform_device *pdev) void __iomem *base; int ret, i; - gicp = devm_kzalloc(&pdev->dev, sizeof(*gicp), GFP_KERNEL); + gicp = devm_kzalloc_obj(&pdev->dev, *gicp); if (!gicp) return -ENOMEM; @@ -198,10 +198,8 @@ static int mvebu_gicp_probe(struct platform_device *pdev) gicp->spi_ranges_cnt = ret / 2; gicp->spi_ranges = - devm_kcalloc(&pdev->dev, - gicp->spi_ranges_cnt, - sizeof(struct mvebu_gicp_spi_range), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, struct mvebu_gicp_spi_range, + gicp->spi_ranges_cnt); if (!gicp->spi_ranges) return -ENOMEM; diff --git a/drivers/irqchip/irq-mvebu-icu.c b/drivers/irqchip/irq-mvebu-icu.c index db5dbc6e88b05d..74ccf72497e077 100644 --- a/drivers/irqchip/irq-mvebu-icu.c +++ b/drivers/irqchip/irq-mvebu-icu.c @@ -264,7 +264,7 @@ static int mvebu_icu_subset_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; bool sei; - msi_data = devm_kzalloc(dev, sizeof(*msi_data), GFP_KERNEL); + msi_data = devm_kzalloc_obj(dev, *msi_data); if (!msi_data) return -ENOMEM; @@ -309,8 +309,7 @@ static int mvebu_icu_probe(struct platform_device *pdev) struct mvebu_icu *icu; int i; - icu = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_icu), - GFP_KERNEL); + icu = devm_kzalloc_obj(&pdev->dev, struct mvebu_icu); if (!icu) return -ENOMEM; diff --git a/drivers/irqchip/irq-mvebu-pic.c b/drivers/irqchip/irq-mvebu-pic.c index 10b85128183a52..81ea0e79402d81 100644 --- a/drivers/irqchip/irq-mvebu-pic.c +++ b/drivers/irqchip/irq-mvebu-pic.c @@ -135,7 +135,7 @@ static int mvebu_pic_probe(struct platform_device *pdev) struct device_node *node = pdev->dev.of_node; struct mvebu_pic *pic; - pic = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pic), GFP_KERNEL); + pic = devm_kzalloc_obj(&pdev->dev, struct mvebu_pic); if (!pic) return -ENOMEM; diff --git a/drivers/irqchip/irq-mvebu-sei.c b/drivers/irqchip/irq-mvebu-sei.c index 5822ea8647653d..5a6b61b2fb1ac5 100644 --- a/drivers/irqchip/irq-mvebu-sei.c +++ b/drivers/irqchip/irq-mvebu-sei.c @@ -374,7 +374,7 @@ static int mvebu_sei_probe(struct platform_device *pdev) u32 parent_irq; int ret; - sei = devm_kzalloc(&pdev->dev, sizeof(*sei), GFP_KERNEL); + sei = devm_kzalloc_obj(&pdev->dev, *sei); if (!sei) return -ENOMEM; diff --git a/drivers/irqchip/irq-pruss-intc.c b/drivers/irqchip/irq-pruss-intc.c index 5a3e9e5bccbead..9a3efd40790c3a 100644 --- a/drivers/irqchip/irq-pruss-intc.c +++ b/drivers/irqchip/irq-pruss-intc.c @@ -513,7 +513,7 @@ static int pruss_intc_probe(struct platform_device *pdev) int i, irq, ret; u8 max_system_events, irqs_reserved = 0; - intc = devm_kzalloc(dev, sizeof(*intc), GFP_KERNEL); + intc = devm_kzalloc_obj(dev, *intc); if (!intc) return -ENOMEM; @@ -562,7 +562,7 @@ static int pruss_intc_probe(struct platform_device *pdev) intc->irqs[i] = irq; - host_data = devm_kzalloc(dev, sizeof(*host_data), GFP_KERNEL); + host_data = devm_kzalloc_obj(dev, *host_data); if (!host_data) { ret = -ENOMEM; goto fail_irq; diff --git a/drivers/irqchip/irq-qcom-mpm.c b/drivers/irqchip/irq-qcom-mpm.c index 8c575d7ce8a179..86cc3589cdf126 100644 --- a/drivers/irqchip/irq-qcom-mpm.c +++ b/drivers/irqchip/irq-qcom-mpm.c @@ -335,7 +335,7 @@ static int qcom_mpm_probe(struct platform_device *pdev, struct device_node *pare int i, irq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -359,8 +359,7 @@ static int qcom_mpm_probe(struct platform_device *pdev, struct device_node *pare } priv->map_cnt = ret / 2; - priv->maps = devm_kcalloc(dev, priv->map_cnt, sizeof(*priv->maps), - GFP_KERNEL); + priv->maps = devm_kzalloc_objs(dev, *priv->maps, priv->map_cnt); if (!priv->maps) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c index 7951292d2d9b1d..738d21d4844e3d 100644 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c @@ -384,7 +384,7 @@ static int intc_irqpin_probe(struct platform_device *pdev) int ret; int k; - p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c index 1ff3535a4617fa..70a27b978e2a55 100644 --- a/drivers/irqchip/irq-renesas-irqc.c +++ b/drivers/irqchip/irq-renesas-irqc.c @@ -129,7 +129,7 @@ static int irqc_probe(struct platform_device *pdev) int ret; int k; - p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-rza1.c b/drivers/irqchip/irq-renesas-rza1.c index 370d968b2398cf..f99645c4b7de6c 100644 --- a/drivers/irqchip/irq-renesas-rza1.c +++ b/drivers/irqchip/irq-renesas-rza1.c @@ -186,7 +186,7 @@ static int rza1_irqc_probe(struct platform_device *pdev) struct rza1_irqc_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-rzg2l.c b/drivers/irqchip/irq-renesas-rzg2l.c index b3774f82855abd..32e5c0a8d5db2d 100644 --- a/drivers/irqchip/irq-renesas-rzg2l.c +++ b/drivers/irqchip/irq-renesas-rzg2l.c @@ -838,7 +838,7 @@ static int rzg2l_irqc_common_probe(struct platform_device *pdev, struct device_n if (!parent_domain) return dev_err_probe(dev, -ENODEV, "cannot find parent domain\n"); - rzg2l_irqc_data = devm_kzalloc(dev, sizeof(*rzg2l_irqc_data), GFP_KERNEL); + rzg2l_irqc_data = devm_kzalloc_obj(dev, *rzg2l_irqc_data); if (!rzg2l_irqc_data) return -ENOMEM; @@ -851,8 +851,9 @@ static int rzg2l_irqc_common_probe(struct platform_device *pdev, struct device_n rzg2l_irqc_data->info = info; - rzg2l_irqc_data->fwspec = devm_kcalloc(&pdev->dev, info.num_irq, - sizeof(*rzg2l_irqc_data->fwspec), GFP_KERNEL); + rzg2l_irqc_data->fwspec = devm_kzalloc_objs(&pdev->dev, + *rzg2l_irqc_data->fwspec, + info.num_irq); if (!rzg2l_irqc_data->fwspec) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-rzt2h.c b/drivers/irqchip/irq-renesas-rzt2h.c index 9086fc3a2043d2..f0f89a36cdd05e 100644 --- a/drivers/irqchip/irq-renesas-rzt2h.c +++ b/drivers/irqchip/irq-renesas-rzt2h.c @@ -485,7 +485,7 @@ static int rzt2h_icu_init(struct platform_device *pdev, struct device_node *pare if (!parent_domain) return dev_err_probe(dev, -ENODEV, "cannot find parent domain\n"); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/irqchip/irq-renesas-rzv2h.c b/drivers/irqchip/irq-renesas-rzv2h.c index 485c3eea76328a..806be528b6d49e 100644 --- a/drivers/irqchip/irq-renesas-rzv2h.c +++ b/drivers/irqchip/irq-renesas-rzv2h.c @@ -864,7 +864,7 @@ static int rzv2h_icu_probe_common(struct platform_device *pdev, struct device_no if (!parent_domain) return dev_err_probe(dev, -ENODEV, "cannot find parent domain\n"); - rzv2h_icu_data = devm_kzalloc(dev, sizeof(*rzv2h_icu_data), GFP_KERNEL); + rzv2h_icu_data = devm_kzalloc_obj(dev, *rzv2h_icu_data); if (!rzv2h_icu_data) return -ENOMEM; diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c index 5a9650225dd805..bfd11a88431645 100644 --- a/drivers/irqchip/irq-riscv-aplic-direct.c +++ b/drivers/irqchip/irq-riscv-aplic-direct.c @@ -239,7 +239,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs) unsigned long hartid; u32 v, hwirq; - direct = devm_kzalloc(dev, sizeof(*direct), GFP_KERNEL); + direct = devm_kzalloc_obj(dev, *direct); if (!direct) return -ENOMEM; priv = &direct->priv; diff --git a/drivers/irqchip/irq-riscv-aplic-msi.c b/drivers/irqchip/irq-riscv-aplic-msi.c index fb8d1838609fb5..d0ca3c17def0f1 100644 --- a/drivers/irqchip/irq-riscv-aplic-msi.c +++ b/drivers/irqchip/irq-riscv-aplic-msi.c @@ -181,7 +181,7 @@ int aplic_msi_setup(struct device *dev, void __iomem *regs) phys_addr_t pa; int rc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c index bc80c38bb86417..7461d5339ddfad 100644 --- a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c +++ b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c @@ -215,7 +215,7 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev) u32 id; int rc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/irqchip/irq-sg2042-msi.c b/drivers/irqchip/irq-sg2042-msi.c index f7cf0dc72eabbf..9ef29bd4d60b3b 100644 --- a/drivers/irqchip/irq-sg2042-msi.c +++ b/drivers/irqchip/irq-sg2042-msi.c @@ -254,7 +254,7 @@ static int sg2042_msi_probe(struct platform_device *pdev) struct resource *res; int ret; - data = devm_kzalloc(dev, sizeof(struct sg204x_msi_chipdata), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct sg204x_msi_chipdata); if (!data) return -ENOMEM; diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 55d94c49f08330..fdfbf1a9add991 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -729,8 +729,8 @@ static int plic_probe(struct fwnode_handle *fwnode) context_id * CONTEXT_ENABLE_SIZE; handler->priv = priv; - handler->enable_save = kcalloc(priv->irq_groups, sizeof(*handler->enable_save), - GFP_KERNEL); + handler->enable_save = kzalloc_objs(*handler->enable_save, + priv->irq_groups); if (!handler->enable_save) return -ENOMEM; done: diff --git a/drivers/irqchip/irq-sl28cpld.c b/drivers/irqchip/irq-sl28cpld.c index 9892c020e0be20..51067e83763d2b 100644 --- a/drivers/irqchip/irq-sl28cpld.c +++ b/drivers/irqchip/irq-sl28cpld.c @@ -43,7 +43,7 @@ static int sl28cpld_intc_probe(struct platform_device *pdev) if (!dev->parent) return -ENODEV; - irqchip = devm_kzalloc(dev, sizeof(*irqchip), GFP_KERNEL); + irqchip = devm_kzalloc_obj(dev, *irqchip); if (!irqchip) return -ENOMEM; diff --git a/drivers/irqchip/irq-st.c b/drivers/irqchip/irq-st.c index fef0521831aa2b..b6fccf80e31ffe 100644 --- a/drivers/irqchip/irq-st.c +++ b/drivers/irqchip/irq-st.c @@ -140,7 +140,7 @@ static int st_irq_syscfg_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct st_irq_syscfg *ddata; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/irqchip/irq-stm32mp-exti.c b/drivers/irqchip/irq-stm32mp-exti.c index a19e91fbd0100f..ac29d7edfa3647 100644 --- a/drivers/irqchip/irq-stm32mp-exti.c +++ b/drivers/irqchip/irq-stm32mp-exti.c @@ -627,7 +627,7 @@ static int stm32mp_exti_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret, i; - host_data = devm_kzalloc(dev, sizeof(*host_data), GFP_KERNEL); + host_data = devm_kzalloc_obj(dev, *host_data); if (!host_data) return -ENOMEM; @@ -660,9 +660,8 @@ static int stm32mp_exti_probe(struct platform_device *pdev) } host_data->drv_data = drv_data; - host_data->chips_data = devm_kcalloc(dev, drv_data->bank_nr, - sizeof(*host_data->chips_data), - GFP_KERNEL); + host_data->chips_data = devm_kzalloc_objs(dev, *host_data->chips_data, + drv_data->bank_nr); if (!host_data->chips_data) return -ENOMEM; diff --git a/drivers/irqchip/irq-ti-sci-inta.c b/drivers/irqchip/irq-ti-sci-inta.c index f1eb2f92f0ca10..0039d0a441548a 100644 --- a/drivers/irqchip/irq-ti-sci-inta.c +++ b/drivers/irqchip/irq-ti-sci-inta.c @@ -620,9 +620,8 @@ static int ti_sci_inta_get_unmapped_sources(struct ti_sci_inta_irq_domain *inta) if (count <= 0) return 0; - inta->unmapped_dev_ids = devm_kcalloc(dev, count, - sizeof(*inta->unmapped_dev_ids), - GFP_KERNEL); + inta->unmapped_dev_ids = devm_kzalloc_objs(dev, *inta->unmapped_dev_ids, + count); if (!inta->unmapped_dev_ids) return -ENOMEM; @@ -663,7 +662,7 @@ static int ti_sci_inta_irq_domain_probe(struct platform_device *pdev) if (!parent_domain) return -EPROBE_DEFER; - inta = devm_kzalloc(dev, sizeof(*inta), GFP_KERNEL); + inta = devm_kzalloc_obj(dev, *inta); if (!inta) return -ENOMEM; diff --git a/drivers/irqchip/irq-ti-sci-intr.c b/drivers/irqchip/irq-ti-sci-intr.c index 0ea17040e934fd..1d2e5af3ac4fbe 100644 --- a/drivers/irqchip/irq-ti-sci-intr.c +++ b/drivers/irqchip/irq-ti-sci-intr.c @@ -263,7 +263,7 @@ static int ti_sci_intr_irq_domain_probe(struct platform_device *pdev) return -ENODEV; } - intr = devm_kzalloc(dev, sizeof(*intr), GFP_KERNEL); + intr = devm_kzalloc_obj(dev, *intr); if (!intr) return -ENOMEM; diff --git a/drivers/irqchip/irq-ts4800.c b/drivers/irqchip/irq-ts4800.c index c7c0b155e353ee..6fc57d664df8e3 100644 --- a/drivers/irqchip/irq-ts4800.c +++ b/drivers/irqchip/irq-ts4800.c @@ -109,7 +109,7 @@ static int ts4800_ic_probe(struct platform_device *pdev) struct ts4800_irq_data *data; int parent_irq; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/irqchip/irq-uniphier-aidet.c b/drivers/irqchip/irq-uniphier-aidet.c index 6005c2d28dd938..dca3c60035396b 100644 --- a/drivers/irqchip/irq-uniphier-aidet.c +++ b/drivers/irqchip/irq-uniphier-aidet.c @@ -175,7 +175,7 @@ static int uniphier_aidet_probe(struct platform_device *pdev) if (!parent_domain) return -EPROBE_DEFER; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/irqchip/irq-xilinx-smmu-csr.c b/drivers/irqchip/irq-xilinx-smmu-csr.c index 9bb6255981076d..58a1555699f520 100644 --- a/drivers/irqchip/irq-xilinx-smmu-csr.c +++ b/drivers/irqchip/irq-xilinx-smmu-csr.c @@ -187,7 +187,7 @@ static int __init xilinx_smmu_csr_init(struct device_node *node, struct device_n if (irq_find_matching_fwnode(of_fwnode_handle(node), DOMAIN_BUS_ANY)) return -ENODEV; - csr = kzalloc(sizeof(*csr), GFP_KERNEL); + csr = kzalloc_obj(*csr); if (!csr) return -ENOMEM; diff --git a/drivers/irqchip/qcom-irq-combiner.c b/drivers/irqchip/qcom-irq-combiner.c index 6d83e1e4a7eac4..57ff4177edb928 100644 --- a/drivers/irqchip/qcom-irq-combiner.c +++ b/drivers/irqchip/qcom-irq-combiner.c @@ -234,8 +234,7 @@ static int combiner_probe(struct platform_device *pdev) return -EINVAL; } - combiner = devm_kzalloc(&pdev->dev, struct_size(combiner, regs, nregs), - GFP_KERNEL); + combiner = devm_kzalloc_flex(&pdev->dev, *combiner, regs, nregs); if (!combiner) return -ENOMEM; diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c index 29025a212ece36..82f146d7c1bcc4 100644 --- a/drivers/irqchip/qcom-pdc.c +++ b/drivers/irqchip/qcom-pdc.c @@ -620,7 +620,7 @@ static int pdc_setup_pin_mapping(struct device *dev) return -EINVAL; pdc->region_cnt = n / 3; - pdc->region = devm_kcalloc(dev, pdc->region_cnt, sizeof(*pdc->region), GFP_KERNEL); + pdc->region = devm_kzalloc_objs(dev, *pdc->region, pdc->region_cnt); if (!pdc->region) { pdc->region_cnt = 0; return -ENOMEM; @@ -670,7 +670,7 @@ static int qcom_pdc_probe(struct platform_device *pdev, struct device_node *pare if (res_size > resource_size(&res)) pr_warn("%pOF: invalid reg size, please fix DT\n", node); - pdc = devm_kzalloc(dev, sizeof(*pdc), GFP_KERNEL); + pdc = devm_kzalloc_obj(dev, *pdc); if (!pdc) return -ENOMEM; diff --git a/drivers/leds/blink/leds-bcm63138.c b/drivers/leds/blink/leds-bcm63138.c index 12b70ee31b9a05..2293ec50681f8f 100644 --- a/drivers/leds/blink/leds-bcm63138.c +++ b/drivers/leds/blink/leds-bcm63138.c @@ -204,7 +204,7 @@ static void bcm63138_leds_create_led(struct bcm63138_leds *leds, u32 bit; int err; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) { dev_err(dev, "Failed to alloc LED\n"); return; @@ -260,7 +260,7 @@ static int bcm63138_leds_probe(struct platform_device *pdev) struct bcm63138_leds *leds; u32 shift_bits; - leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_obj(dev, *leds); if (!leds) return -ENOMEM; diff --git a/drivers/leds/blink/leds-lgm-sso.c b/drivers/leds/blink/leds-lgm-sso.c index 0f27c68e27411f..71d0bc55ba570d 100644 --- a/drivers/leds/blink/leds-lgm-sso.c +++ b/drivers/leds/blink/leds-lgm-sso.c @@ -627,7 +627,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled) int ret; fwnode_for_each_child_node(fw_ssoled, fwnode_child) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) { ret = -ENOMEM; goto __dt_err; @@ -777,7 +777,7 @@ static int intel_sso_led_probe(struct platform_device *pdev) struct sso_led_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/flash/leds-aat1290.c b/drivers/leds/flash/leds-aat1290.c index 4bde0b07fe7854..ac68e90f1ba26f 100644 --- a/drivers/leds/flash/leds-aat1290.c +++ b/drivers/leds/flash/leds-aat1290.c @@ -311,10 +311,9 @@ static int init_mm_current_scale(struct aat1290_led *led, int i, max_mm_current = AAT1290_MAX_MM_CURRENT(cfg->max_flash_current); - led->mm_current_scale = devm_kcalloc(&led->pdev->dev, - ARRAY_SIZE(max_mm_current_percent), - sizeof(*led->mm_current_scale), - GFP_KERNEL); + led->mm_current_scale = devm_kzalloc_objs(&led->pdev->dev, + *led->mm_current_scale, + ARRAY_SIZE(max_mm_current_percent)); if (!led->mm_current_scale) return -ENOMEM; @@ -465,7 +464,7 @@ static int aat1290_led_probe(struct platform_device *pdev) struct v4l2_flash_config v4l2_sd_cfg = {}; int ret; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/flash/leds-as3645a.c b/drivers/leds/flash/leds-as3645a.c index 5fefcaef37145f..2a3107143178cd 100644 --- a/drivers/leds/flash/leds-as3645a.c +++ b/drivers/leds/flash/leds-as3645a.c @@ -678,7 +678,7 @@ static int as3645a_probe(struct i2c_client *client) if (!dev_fwnode(&client->dev)) return -ENODEV; - flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&client->dev, *flash); if (flash == NULL) return -ENOMEM; diff --git a/drivers/leds/flash/leds-ktd2692.c b/drivers/leds/flash/leds-ktd2692.c index 43d4d55503ab50..40f8997f1dabe2 100644 --- a/drivers/leds/flash/leds-ktd2692.c +++ b/drivers/leds/flash/leds-ktd2692.c @@ -287,7 +287,7 @@ static int ktd2692_probe(struct platform_device *pdev) struct ktd2692_led_config_data led_cfg; int ret; - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/flash/leds-lm3601x.c b/drivers/leds/flash/leds-lm3601x.c index 8d00510c8967b6..c65a8a50b2c31e 100644 --- a/drivers/leds/flash/leds-lm3601x.c +++ b/drivers/leds/flash/leds-lm3601x.c @@ -424,7 +424,7 @@ static int lm3601x_probe(struct i2c_client *client) struct fwnode_handle *fwnode; int ret; - led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/flash/leds-max77693.c b/drivers/leds/flash/leds-max77693.c index daee109861086b..0cb2d13ee3c0dd 100644 --- a/drivers/leds/flash/leds-max77693.c +++ b/drivers/leds/flash/leds-max77693.c @@ -947,7 +947,7 @@ static int max77693_led_probe(struct platform_device *pdev) struct max77693_led_config_data led_cfg = {}; int init_fled_cdev[2], i, ret; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c index 462a902f54e04c..52cafe6c0e7f45 100644 --- a/drivers/leds/flash/leds-mt6360.c +++ b/drivers/leds/flash/leds-mt6360.c @@ -795,8 +795,7 @@ static int mt6360_led_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, leds, count), GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/flash/leds-mt6370-flash.c b/drivers/leds/flash/leds-mt6370-flash.c index dbdbe92309db96..bf56c3dae7038b 100644 --- a/drivers/leds/flash/leds-mt6370-flash.c +++ b/drivers/leds/flash/leds-mt6370-flash.c @@ -517,7 +517,7 @@ static int mt6370_led_probe(struct platform_device *pdev) return dev_err_probe(dev, -EINVAL, "No child node or node count over max led number %zu\n", count); - priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c index b03a6833e3e3a0..4e62a210cf98da 100644 --- a/drivers/leds/flash/leds-qcom-flash.c +++ b/drivers/leds/flash/leds-qcom-flash.c @@ -845,7 +845,7 @@ static int qcom_flash_led_probe(struct platform_device *pdev) int count, i, rc; u32 val, reg_base; - flash_data = devm_kzalloc(dev, sizeof(*flash_data), GFP_KERNEL); + flash_data = devm_kzalloc_obj(dev, *flash_data); if (!flash_data) return -ENOMEM; @@ -931,13 +931,13 @@ static int qcom_flash_led_probe(struct platform_device *pdev) return -EINVAL; } - flash_data->v4l2_flash = devm_kcalloc(dev, count, - sizeof(*flash_data->v4l2_flash), GFP_KERNEL); + flash_data->v4l2_flash = devm_kzalloc_objs(dev, *flash_data->v4l2_flash, + count); if (!flash_data->v4l2_flash) return -ENOMEM; device_for_each_child_node_scoped(dev, child) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) { rc = -ENOMEM; goto release; diff --git a/drivers/leds/flash/leds-rt4505.c b/drivers/leds/flash/leds-rt4505.c index 18fd5b7e528f43..6a47760645f110 100644 --- a/drivers/leds/flash/leds-rt4505.c +++ b/drivers/leds/flash/leds-rt4505.c @@ -346,7 +346,7 @@ static int rt4505_probe(struct i2c_client *client) struct v4l2_flash_config v4l2_config = {}; int ret; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/flash/leds-rt8515.c b/drivers/leds/flash/leds-rt8515.c index 00904cc90ed6e0..8570db842aff55 100644 --- a/drivers/leds/flash/leds-rt8515.c +++ b/drivers/leds/flash/leds-rt8515.c @@ -283,7 +283,7 @@ static int rt8515_probe(struct platform_device *pdev) struct v4l2_flash_config v4l2_sd_cfg = {}; int ret; - rt = devm_kzalloc(dev, sizeof(*rt), GFP_KERNEL); + rt = devm_kzalloc_obj(dev, *rt); if (!rt) return -ENOMEM; diff --git a/drivers/leds/flash/leds-sgm3140.c b/drivers/leds/flash/leds-sgm3140.c index dc684035737085..107d02c3137f84 100644 --- a/drivers/leds/flash/leds-sgm3140.c +++ b/drivers/leds/flash/leds-sgm3140.c @@ -192,7 +192,7 @@ static int sgm3140_probe(struct platform_device *pdev) struct v4l2_flash_config v4l2_sd_cfg = {}; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/flash/leds-sy7802.c b/drivers/leds/flash/leds-sy7802.c index ddac836762af86..2190f55b75594b 100644 --- a/drivers/leds/flash/leds-sy7802.c +++ b/drivers/leds/flash/leds-sy7802.c @@ -462,7 +462,7 @@ static int sy7802_probe(struct i2c_client *client) if (!count || count > SY7802_MAX_LEDS) return dev_err_probe(dev, -EINVAL, "Invalid amount of LED nodes %zu\n", count); - chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL); + chip = devm_kzalloc_flex(dev, *chip, leds, count); if (!chip) return -ENOMEM; diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c index 5c9a5af5af05c5..7f2c3895e6e98d 100644 --- a/drivers/leds/flash/leds-tps6131x.c +++ b/drivers/leds/flash/leds-tps6131x.c @@ -741,7 +741,7 @@ static int tps6131x_probe(struct i2c_client *client) struct tps6131x *tps6131x; int ret; - tps6131x = devm_kzalloc(&client->dev, sizeof(*tps6131x), GFP_KERNEL); + tps6131x = devm_kzalloc_obj(&client->dev, *tps6131x); if (!tps6131x) return -ENOMEM; diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 80e281dce19528..177a9038cd295f 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -443,7 +443,7 @@ u32 *led_get_default_pattern(struct led_classdev *led_cdev, unsigned int *size) if (count < 0) return NULL; - pattern = kcalloc(count, sizeof(*pattern), GFP_KERNEL); + pattern = kzalloc_objs(*pattern, count); if (!pattern) return NULL; diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c index ef5c6c4667ab18..448c3cb7cce02b 100644 --- a/drivers/leds/leds-88pm860x.c +++ b/drivers/leds/leds-88pm860x.c @@ -148,7 +148,7 @@ static int pm860x_led_probe(struct platform_device *pdev) struct resource *res; int ret = 0; - data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct pm860x_led); if (data == NULL) return -ENOMEM; res = platform_get_resource_byname(pdev, IORESOURCE_REG, "control"); diff --git a/drivers/leds/leds-acer-a500.c b/drivers/leds/leds-acer-a500.c index 8cf0b11f439021..01d5d0faeb4e86 100644 --- a/drivers/leds/leds-acer-a500.c +++ b/drivers/leds/leds-acer-a500.c @@ -75,7 +75,7 @@ static int a500_ec_leds_probe(struct platform_device *pdev) /* reset and turn off LEDs */ regmap_multi_reg_write(rmap, a500_ec_leds_reset_seq, 2); - white_led = devm_kzalloc(&pdev->dev, sizeof(*white_led), GFP_KERNEL); + white_led = devm_kzalloc_obj(&pdev->dev, *white_led); if (!white_led) return -ENOMEM; @@ -86,7 +86,7 @@ static int a500_ec_leds_probe(struct platform_device *pdev) white_led->enable_seq = a500_ec_white_led_enable_seq; white_led->rmap = rmap; - orange_led = devm_kzalloc(&pdev->dev, sizeof(*orange_led), GFP_KERNEL); + orange_led = devm_kzalloc_obj(&pdev->dev, *orange_led); if (!orange_led) return -ENOMEM; diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c index 13e5bc80e56e0e..39649cb913beb5 100644 --- a/drivers/leds/leds-adp5520.c +++ b/drivers/leds/leds-adp5520.c @@ -107,8 +107,7 @@ static int adp5520_led_probe(struct platform_device *pdev) return -EFAULT; } - led = devm_kcalloc(&pdev->dev, pdata->num_leds, sizeof(*led), - GFP_KERNEL); + led = devm_kzalloc_objs(&pdev->dev, *led, pdata->num_leds); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-an30259a.c b/drivers/leds/leds-an30259a.c index 4654a732d1b166..808fe8a5df58f2 100644 --- a/drivers/leds/leds-an30259a.c +++ b/drivers/leds/leds-an30259a.c @@ -275,7 +275,7 @@ static int an30259a_probe(struct i2c_client *client) struct an30259a *chip; int i, err; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-apu.c b/drivers/leds/leds-apu.c index 1c116aaa9b6e39..259c95fc306ae0 100644 --- a/drivers/leds/leds-apu.c +++ b/drivers/leds/leds-apu.c @@ -117,9 +117,8 @@ static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld) int i; int err; - apu_led->pled = devm_kcalloc(dev, - ARRAY_SIZE(apu1_led_profile), sizeof(struct apu_led_priv), - GFP_KERNEL); + apu_led->pled = devm_kzalloc_objs(dev, struct apu_led_priv, + ARRAY_SIZE(apu1_led_profile)); if (!apu_led->pled) return -ENOMEM; @@ -159,7 +158,7 @@ static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld) static int __init apu_led_probe(struct platform_device *pdev) { - apu_led = devm_kzalloc(&pdev->dev, sizeof(*apu_led), GFP_KERNEL); + apu_led = devm_kzalloc_obj(&pdev->dev, *apu_led); if (!apu_led) return -ENOMEM; diff --git a/drivers/leds/leds-ariel.c b/drivers/leds/leds-ariel.c index dd319c7e385fc1..fc5664e046467c 100644 --- a/drivers/leds/leds-ariel.c +++ b/drivers/leds/leds-ariel.c @@ -91,7 +91,7 @@ static int ariel_led_probe(struct platform_device *pdev) if (!ec_ram) return -ENODEV; - leds = devm_kcalloc(dev, NLEDS, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_objs(dev, *leds, NLEDS); if (!leds) return -ENOMEM; diff --git a/drivers/leds/leds-as3668.c b/drivers/leds/leds-as3668.c index 46427fe752a83d..004a570224f11f 100644 --- a/drivers/leds/leds-as3668.c +++ b/drivers/leds/leds-as3668.c @@ -140,7 +140,7 @@ static int as3668_probe(struct i2c_client *client) "expected chip ID 0x%02x, got 0x%02x\n", AS3668_CHIP_ID, chip_id); - as3668 = devm_kzalloc(&client->dev, sizeof(*as3668), GFP_KERNEL); + as3668 = devm_kzalloc_obj(&client->dev, *as3668); if (!as3668) return -ENOMEM; diff --git a/drivers/leds/leds-aw200xx.c b/drivers/leds/leds-aw200xx.c index b92158ac9ce30e..7eebd361991c13 100644 --- a/drivers/leds/leds-aw200xx.c +++ b/drivers/leds/leds-aw200xx.c @@ -552,8 +552,7 @@ static int aw200xx_probe(struct i2c_client *client) return dev_err_probe(&client->dev, -EINVAL, "Incorrect number of leds (%d)", count); - chip = devm_kzalloc(&client->dev, struct_size(chip, leds, count), - GFP_KERNEL); + chip = devm_kzalloc_flex(&client->dev, *chip, leds, count); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c index 216755d6010fed..457f1cb178c795 100644 --- a/drivers/leds/leds-aw2013.c +++ b/drivers/leds/leds-aw2013.c @@ -335,7 +335,7 @@ static int aw2013_probe(struct i2c_client *client) int ret; unsigned int chipid; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c index 592bbf4b7e3579..667ff31eb8fa9d 100644 --- a/drivers/leds/leds-bcm6328.c +++ b/drivers/leds/leds-bcm6328.c @@ -335,7 +335,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, void __iomem *mode; int rc; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -400,17 +400,17 @@ static int bcm6328_leds_probe(struct platform_device *pdev) if (IS_ERR(mem)) return PTR_ERR(mem); - lock = devm_kzalloc(dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(dev, *lock); if (!lock) return -ENOMEM; - blink_leds = devm_kcalloc(dev, BCM6328_LED_BLINK_DELAYS, - sizeof(*blink_leds), GFP_KERNEL); + blink_leds = devm_kzalloc_objs(dev, *blink_leds, + BCM6328_LED_BLINK_DELAYS); if (!blink_leds) return -ENOMEM; - blink_delay = devm_kcalloc(dev, BCM6328_LED_BLINK_DELAYS, - sizeof(*blink_delay), GFP_KERNEL); + blink_delay = devm_kzalloc_objs(dev, *blink_delay, + BCM6328_LED_BLINK_DELAYS); if (!blink_delay) return -ENOMEM; diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c index 51fcff2a64fd10..ab15c591386cb8 100644 --- a/drivers/leds/leds-bcm6358.c +++ b/drivers/leds/leds-bcm6358.c @@ -100,7 +100,7 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg, unsigned long val; int rc; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -156,7 +156,7 @@ static int bcm6358_leds_probe(struct platform_device *pdev) if (IS_ERR(mem)) return PTR_ERR(mem); - lock = devm_kzalloc(dev, sizeof(*lock), GFP_KERNEL); + lock = devm_kzalloc_obj(dev, *lock); if (!lock) return -ENOMEM; diff --git a/drivers/leds/leds-bd2606mvv.c b/drivers/leds/leds-bd2606mvv.c index 4c696abfd23d00..d43fd363db8caa 100644 --- a/drivers/leds/leds-bd2606mvv.c +++ b/drivers/leds/leds-bd2606mvv.c @@ -78,7 +78,7 @@ static int bd2606mvv_probe(struct i2c_client *client) if (!dev_fwnode(dev)) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-bd2802.c b/drivers/leds/leds-bd2802.c index 9732f41a114312..37efe063395604 100644 --- a/drivers/leds/leds-bd2802.c +++ b/drivers/leds/leds-bd2802.c @@ -661,7 +661,7 @@ static int bd2802_probe(struct i2c_client *client) struct bd2802_led *led; int ret, i; - led = devm_kzalloc(&client->dev, sizeof(struct bd2802_led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, struct bd2802_led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c index ee1589015826b9..3ac4c53b249149 100644 --- a/drivers/leds/leds-blinkm.c +++ b/drivers/leds/leds-blinkm.c @@ -689,8 +689,7 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da mc_led = &data->blinkm_leds[RED]; mc_led->i2c_client = client; - mc_led_info = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(*mc_led_info), - GFP_KERNEL); + mc_led_info = devm_kzalloc_objs(&client->dev, *mc_led_info, NUM_LEDS); if (!mc_led_info) return -ENOMEM; @@ -725,8 +724,7 @@ static int blinkm_probe(struct i2c_client *client) struct blinkm_data *data; int err; - data = devm_kzalloc(&client->dev, - sizeof(struct blinkm_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct blinkm_data); if (!data) return -ENOMEM; diff --git a/drivers/leds/leds-cht-wcove.c b/drivers/leds/leds-cht-wcove.c index da05ff94898dfc..c4188a5abca2b1 100644 --- a/drivers/leds/leds-cht-wcove.c +++ b/drivers/leds/leds-cht-wcove.c @@ -348,7 +348,7 @@ static int cht_wc_leds_probe(struct platform_device *pdev) if (pmic->cht_wc_model == INTEL_CHT_WC_LENOVO_YT3_X90) return -ENODEV; - leds = devm_kzalloc(&pdev->dev, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_obj(&pdev->dev, *leds); if (!leds) return -ENOMEM; diff --git a/drivers/leds/leds-cpcap.c b/drivers/leds/leds-cpcap.c index 87354f17644bac..0bc613e454531e 100644 --- a/drivers/leds/leds-cpcap.c +++ b/drivers/leds/leds-cpcap.c @@ -161,7 +161,7 @@ static int cpcap_led_probe(struct platform_device *pdev) struct cpcap_led *led; int err; - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (!led) return -ENOMEM; platform_set_drvdata(pdev, led); diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c index 3f6931ae0bccee..8140e21c021dd1 100644 --- a/drivers/leds/leds-cr0014114.c +++ b/drivers/leds/leds-cr0014114.c @@ -220,8 +220,7 @@ static int cr0014114_probe(struct spi_device *spi) return -ENODEV; } - priv = devm_kzalloc(&spi->dev, struct_size(priv, leds, count), - GFP_KERNEL); + priv = devm_kzalloc_flex(&spi->dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c index 0e93aa28a8b16d..60b3858431545c 100644 --- a/drivers/leds/leds-cros_ec.c +++ b/drivers/leds/leds-cros_ec.c @@ -183,7 +183,7 @@ static int cros_ec_led_probe_one(struct device *dev, struct cros_ec_device *cros if (ret < 0) return ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -197,7 +197,7 @@ static int cros_ec_led_probe_one(struct device *dev, struct cros_ec_device *cros priv->cros_ec = cros_ec; priv->led_id = id; - subleds = devm_kcalloc(dev, num_subleds, sizeof(*subleds), GFP_KERNEL); + subleds = devm_kzalloc_objs(dev, *subleds, num_subleds); if (!subleds) return -ENOMEM; diff --git a/drivers/leds/leds-da903x.c b/drivers/leds/leds-da903x.c index 71209b3c8f1e69..ecc8769652607a 100644 --- a/drivers/leds/leds-da903x.c +++ b/drivers/leds/leds-da903x.c @@ -97,7 +97,7 @@ static int da903x_led_probe(struct platform_device *pdev) return -EINVAL; } - led = devm_kzalloc(&pdev->dev, sizeof(struct da903x_led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, struct da903x_led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-da9052.c b/drivers/leds/leds-da9052.c index 7c9051184a5989..37ca656027391b 100644 --- a/drivers/leds/leds-da9052.c +++ b/drivers/leds/leds-da9052.c @@ -108,9 +108,7 @@ static int da9052_led_probe(struct platform_device *pdev) goto err; } - led = devm_kcalloc(&pdev->dev, - pled->num_leds, sizeof(struct da9052_led), - GFP_KERNEL); + led = devm_kzalloc_objs(&pdev->dev, struct da9052_led, pled->num_leds); if (!led) { error = -ENOMEM; goto err; diff --git a/drivers/leds/leds-dac124s085.c b/drivers/leds/leds-dac124s085.c index 192b43333aeef1..a1330cb0182a8d 100644 --- a/drivers/leds/leds-dac124s085.c +++ b/drivers/leds/leds-dac124s085.c @@ -53,7 +53,7 @@ static int dac124s085_probe(struct spi_device *spi) struct dac124s085_led *led; int i, ret; - dac = devm_kzalloc(&spi->dev, sizeof(*dac), GFP_KERNEL); + dac = devm_kzalloc_obj(&spi->dev, *dac); if (!dac) return -ENOMEM; diff --git a/drivers/leds/leds-el15203000.c b/drivers/leds/leds-el15203000.c index 8e8ddd7c514d2a..1dc143f68e0451 100644 --- a/drivers/leds/leds-el15203000.c +++ b/drivers/leds/leds-el15203000.c @@ -291,8 +291,7 @@ static int el15203000_probe(struct spi_device *spi) return -ENODEV; } - priv = devm_kzalloc(&spi->dev, struct_size(priv, leds, count), - GFP_KERNEL); + priv = devm_kzalloc_flex(&spi->dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index dbb84949c3c263..d73f40cebc1ea3 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -152,7 +152,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) if (!count) return ERR_PTR(-ENODEV); - priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, count); if (!priv) return ERR_PTR(-ENOMEM); priv->num_leds = count; @@ -279,7 +279,7 @@ static int gpio_led_probe(struct platform_device *pdev) int i, ret; if (pdata && pdata->num_leds) { - priv = devm_kzalloc(dev, struct_size(priv, leds, pdata->num_leds), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, pdata->num_leds); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-ip30.c b/drivers/leds/leds-ip30.c index 2df24c30336657..36e7e89a1e4a3f 100644 --- a/drivers/leds/leds-ip30.c +++ b/drivers/leds/leds-ip30.c @@ -29,7 +29,7 @@ static int ip30led_create(struct platform_device *pdev, int num) { struct ip30_led *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 50ebbc271107e3..e40ea3cb4f2638 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -491,7 +491,7 @@ static int is31fl319x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EIO; - is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL); + is31 = devm_kzalloc_obj(&client->dev, *is31); if (!is31) return -ENOMEM; diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c index 285085d274538d..c9a0cba65170a3 100644 --- a/drivers/leds/leds-is31fl32xx.c +++ b/drivers/leds/leds-is31fl32xx.c @@ -580,8 +580,7 @@ static int is31fl32xx_probe(struct i2c_client *client) if (!count) return -EINVAL; - priv = devm_kzalloc(dev, struct_size(priv, leds, count), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c index 481e9c0a41e7b6..e3f25f3b626a5b 100644 --- a/drivers/leds/leds-lm3530.c +++ b/drivers/leds/leds-lm3530.c @@ -427,8 +427,7 @@ static int lm3530_probe(struct i2c_client *client) return -EIO; } - drvdata = devm_kzalloc(&client->dev, sizeof(struct lm3530_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&client->dev, struct lm3530_data); if (drvdata == NULL) return -ENOMEM; diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index b51496910b0826..7b0d655cc2f7df 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -487,7 +487,7 @@ static int lm3532_parse_als(struct lm3532_data *priv) int als_impedance; int ret; - als = devm_kzalloc(priv->dev, sizeof(*als), GFP_KERNEL); + als = devm_kzalloc_obj(priv->dev, *als); if (als == NULL) return -ENOMEM; @@ -684,8 +684,7 @@ static int lm3532_probe(struct i2c_client *client) return -ENODEV; } - drvdata = devm_kzalloc(&client->dev, struct_size(drvdata, leds, count), - GFP_KERNEL); + drvdata = devm_kzalloc_flex(&client->dev, *drvdata, leds, count); if (drvdata == NULL) return -ENOMEM; diff --git a/drivers/leds/leds-lm3533.c b/drivers/leds/leds-lm3533.c index 7259097bd6a71a..d5997cbd88dfc2 100644 --- a/drivers/leds/leds-lm3533.c +++ b/drivers/leds/leds-lm3533.c @@ -648,7 +648,7 @@ static int lm3533_led_probe(struct platform_device *pdev) return -EINVAL; } - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lm355x.c b/drivers/leds/leds-lm355x.c index 2b7cf42141e4f4..66c0cf4757598f 100644 --- a/drivers/leds/leds-lm355x.c +++ b/drivers/leds/leds-lm355x.c @@ -414,8 +414,7 @@ static int lm355x_probe(struct i2c_client *client) return -ENODATA; } - chip = devm_kzalloc(&client->dev, - sizeof(struct lm355x_chip_data), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct lm355x_chip_data); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c index 7fd8365c2f7b87..7f6463f0611e53 100644 --- a/drivers/leds/leds-lm36274.c +++ b/drivers/leds/leds-lm36274.c @@ -110,7 +110,7 @@ static int lm36274_probe(struct platform_device *pdev) struct lm36274 *chip; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-lm3642.c b/drivers/leds/leds-lm3642.c index 2a893399e05f21..9af8b8e47e42b6 100644 --- a/drivers/leds/leds-lm3642.c +++ b/drivers/leds/leds-lm3642.c @@ -304,8 +304,7 @@ static int lm3642_probe(struct i2c_client *client) return -ENODATA; } - chip = devm_kzalloc(&client->dev, - sizeof(struct lm3642_chip_data), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct lm3642_chip_data); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c index 9c58d54c57830a..0d730869b95b34 100644 --- a/drivers/leds/leds-lm3692x.c +++ b/drivers/leds/leds-lm3692x.c @@ -466,7 +466,7 @@ static int lm3692x_probe(struct i2c_client *client) struct lm3692x_led *led; int ret; - led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c index 83dc607a698780..53410d63868167 100644 --- a/drivers/leds/leds-lm3697.c +++ b/drivers/leds/leds-lm3697.c @@ -305,7 +305,7 @@ static int lm3697_probe(struct i2c_client *client) return -ENODEV; } - led = devm_kzalloc(dev, struct_size(led, leds, count), GFP_KERNEL); + led = devm_kzalloc_flex(dev, *led, leds, count); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c index 8e95dcedce4008..b0b33cc649148a 100644 --- a/drivers/leds/leds-lp3944.c +++ b/drivers/leds/leds-lp3944.c @@ -378,8 +378,7 @@ static int lp3944_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(&client->dev, sizeof(struct lp3944_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct lp3944_data); if (!data) return -ENOMEM; diff --git a/drivers/leds/leds-lp3952.c b/drivers/leds/leds-lp3952.c index 0a1af284f52bf4..391866b0d3212a 100644 --- a/drivers/leds/leds-lp3952.c +++ b/drivers/leds/leds-lp3952.c @@ -219,7 +219,7 @@ static int lp3952_probe(struct i2c_client *client) int status; struct lp3952_led_array *priv; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c index 20bfb315bda1d6..583659d82e8466 100644 --- a/drivers/leds/leds-lp50xx.c +++ b/drivers/leds/leds-lp50xx.c @@ -500,8 +500,8 @@ static int lp50xx_probe_dt(struct lp50xx *priv) * There are only 3 LEDs per module otherwise they should be * banked which also is presented as 3 LEDs. */ - mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE, - sizeof(*mc_led_info), GFP_KERNEL); + mc_led_info = devm_kzalloc_objs(priv->dev, *mc_led_info, + LP50XX_LEDS_PER_MODULE); if (!mc_led_info) return -ENOMEM; @@ -559,8 +559,7 @@ static int lp50xx_probe(struct i2c_client *client) return -ENODEV; } - led = devm_kzalloc(&client->dev, struct_size(led, leds, count), - GFP_KERNEL); + led = devm_kzalloc_flex(&client->dev, *led, leds, count); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index ea131177de9642..8fbd7a846cbf7d 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -484,9 +484,8 @@ static int lp55xx_init_led(struct lp55xx_led *led, } if (pdata->led_config[chan].num_colors > 1) { - mc_led_info = devm_kcalloc(dev, - pdata->led_config[chan].num_colors, - sizeof(*mc_led_info), GFP_KERNEL); + mc_led_info = devm_kzalloc_objs(dev, *mc_led_info, + pdata->led_config[chan].num_colors); if (!mc_led_info) return -ENOMEM; @@ -1210,7 +1209,7 @@ static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, int i = 0; int ret; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -1220,7 +1219,7 @@ static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, return ERR_PTR(-EINVAL); } - cfg = devm_kcalloc(dev, num_channels, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_objs(dev, *cfg, num_channels); if (!cfg) return ERR_PTR(-ENOMEM); @@ -1266,7 +1265,7 @@ int lp55xx_probe(struct i2c_client *client) struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); struct device_node *np = dev_of_node(&client->dev); - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; @@ -1295,8 +1294,7 @@ int lp55xx_probe(struct i2c_client *client) return -EINVAL; } - led = devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_objs(&client->dev, *led, pdata->num_channels); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lp8788.c b/drivers/leds/leds-lp8788.c index 9b9525ccca1573..35c5f4341eb6b2 100644 --- a/drivers/leds/leds-lp8788.c +++ b/drivers/leds/leds-lp8788.c @@ -125,7 +125,7 @@ static int lp8788_led_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - led = devm_kzalloc(dev, sizeof(struct lp8788_led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, struct lp8788_led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c index f6e4227de903a6..89071841b1c751 100644 --- a/drivers/leds/leds-lp8860.c +++ b/drivers/leds/leds-lp8860.c @@ -278,7 +278,7 @@ static int lp8860_probe(struct i2c_client *client) struct led_init_data init_data = {}; struct gpio_desc *enable_gpio; - led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lp8864.c b/drivers/leds/leds-lp8864.c index 204727f2f350ec..db81fe3b19a3bd 100644 --- a/drivers/leds/leds-lp8864.c +++ b/drivers/leds/leds-lp8864.c @@ -214,7 +214,7 @@ static int lp8864_probe(struct i2c_client *client) struct led_init_data init_data = {}; struct gpio_desc *enable_gpio; - led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c index 6fca14e76ca629..63e596aebc02ae 100644 --- a/drivers/leds/leds-lt3593.c +++ b/drivers/leds/leds-lt3593.c @@ -68,7 +68,7 @@ static int lt3593_led_probe(struct platform_device *pdev) struct led_init_data init_data = {}; const char *tmp; - led_data = devm_kzalloc(dev, sizeof(*led_data), GFP_KERNEL); + led_data = devm_kzalloc_obj(dev, *led_data); if (!led_data) return -ENOMEM; diff --git a/drivers/leds/leds-ltc3208.c b/drivers/leds/leds-ltc3208.c index 64091f29f18a05..3f70ba227a7e94 100644 --- a/drivers/leds/leds-ltc3208.c +++ b/drivers/leds/leds-ltc3208.c @@ -189,7 +189,7 @@ static int ltc3208_probe(struct i2c_client *client) return dev_err_probe(&client->dev, -EINVAL, "%u is already registered", chan); - led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&client->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-ltc3220.c b/drivers/leds/leds-ltc3220.c index 5060d5042fe124..33e9b4ef64525d 100644 --- a/drivers/leds/leds-ltc3220.c +++ b/drivers/leds/leds-ltc3220.c @@ -422,7 +422,7 @@ static int ltc3220_probe(struct i2c_client *client) u8 led_index = 0; int ret; - ltc3220 = devm_kzalloc(&client->dev, sizeof(*ltc3220), GFP_KERNEL); + ltc3220 = devm_kzalloc_obj(&client->dev, *ltc3220); if (!ltc3220) return -ENOMEM; diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c index cb4dd0a9166cc7..659c0d437b70fd 100644 --- a/drivers/leds/leds-max5970.c +++ b/drivers/leds/leds-max5970.c @@ -70,7 +70,7 @@ static int max5970_led_probe(struct platform_device *pdev) continue; } - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) { fwnode_handle_put(child); return -ENOMEM; diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c index f8c47078a3bbf7..b68afbbbf22dbc 100644 --- a/drivers/leds/leds-max77650.c +++ b/drivers/leds/leds-max77650.c @@ -70,8 +70,7 @@ static int max77650_led_probe(struct platform_device *pdev) dev = &pdev->dev; - leds = devm_kcalloc(dev, sizeof(*leds), - MAX77650_LED_NUM_LEDS, GFP_KERNEL); + leds = devm_kzalloc_objs(dev, *leds, MAX77650_LED_NUM_LEDS); if (!leds) return -ENOMEM; diff --git a/drivers/leds/leds-max77705.c b/drivers/leds/leds-max77705.c index 4fd803c9598909..c5c0ce7492775f 100644 --- a/drivers/leds/leds-max77705.c +++ b/drivers/leds/leds-max77705.c @@ -162,7 +162,7 @@ static int max77705_add_led(struct device *dev, struct regmap *regmap, struct fw struct mc_subled *info; struct led_init_data init_data = {}; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -181,7 +181,7 @@ static int max77705_add_led(struct device *dev, struct regmap *regmap, struct fw if (ret || reg >= MAX77705_LED_NUM_LEDS) return -EINVAL; - info = devm_kcalloc(dev, num_channels, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_objs(dev, *info, num_channels); if (!info) return -ENOMEM; @@ -211,7 +211,7 @@ static int max77705_add_led(struct device *dev, struct regmap *regmap, struct fw if (ret) return ret; } else { - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c index c8d7f55c9dec29..678c9e1eaaaada 100644 --- a/drivers/leds/leds-max8997.c +++ b/drivers/leds/leds-max8997.c @@ -238,7 +238,7 @@ static int max8997_led_probe(struct platform_device *pdev) char name[20]; int ret = 0; - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (led == NULL) return -ENOMEM; diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c index e22f09d1379839..19c1b51475db6e 100644 --- a/drivers/leds/leds-mc13783.c +++ b/drivers/leds/leds-mc13783.c @@ -118,7 +118,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( struct device *dev = &pdev->dev; int i = 0, ret = -ENODATA; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -135,8 +135,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( pdata->num_leds = of_get_available_child_count(parent); - pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led), - GFP_KERNEL); + pdata->led = devm_kzalloc_objs(dev, *pdata->led, pdata->num_leds); if (!pdata->led) return ERR_PTR(-ENOMEM); @@ -182,7 +181,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) int i, id, ret = -ENODATA; u32 init_led = 0; - leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_obj(dev, *leds); if (!leds) return -ENOMEM; @@ -205,8 +204,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) return -EINVAL; } - leds->led = devm_kcalloc(dev, leds->num_leds, sizeof(*leds->led), - GFP_KERNEL); + leds->led = devm_kzalloc_objs(dev, *leds->led, leds->num_leds); if (!leds->led) return -ENOMEM; diff --git a/drivers/leds/leds-mlxcpld.c b/drivers/leds/leds-mlxcpld.c index 1f5ab8fbdaf994..abb416364c0efc 100644 --- a/drivers/leds/leds-mlxcpld.c +++ b/drivers/leds/leds-mlxcpld.c @@ -327,10 +327,8 @@ static int mlxcpld_led_config(struct device *dev, int i; int err; - cpld->pled = devm_kcalloc(dev, - cpld->num_led_instances, - sizeof(struct mlxcpld_led_priv), - GFP_KERNEL); + cpld->pled = devm_kzalloc_objs(dev, struct mlxcpld_led_priv, + cpld->num_led_instances); if (!cpld->pled) return -ENOMEM; @@ -363,8 +361,7 @@ static int __init mlxcpld_led_probe(struct platform_device *pdev) enum mlxcpld_led_platform_types mlxcpld_led_plat = mlxcpld_led_platform_check_sys_type(); - mlxcpld_led = devm_kzalloc(&pdev->dev, sizeof(*mlxcpld_led), - GFP_KERNEL); + mlxcpld_led = devm_kzalloc_obj(&pdev->dev, *mlxcpld_led); if (!mlxcpld_led) return -ENOMEM; diff --git a/drivers/leds/leds-mlxreg.c b/drivers/leds/leds-mlxreg.c index 1b70de72376ccd..ab67026d1b8d5e 100644 --- a/drivers/leds/leds-mlxreg.c +++ b/drivers/leds/leds-mlxreg.c @@ -192,8 +192,7 @@ static int mlxreg_led_config(struct mlxreg_led_priv_data *priv) int err; for (i = 0; i < led_pdata->counter; i++, data++) { - led_data = devm_kzalloc(&priv->pdev->dev, sizeof(*led_data), - GFP_KERNEL); + led_data = devm_kzalloc_obj(&priv->pdev->dev, *led_data); if (!led_data) return -ENOMEM; @@ -264,7 +263,7 @@ static int mlxreg_led_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c index dbdc221c382834..bac5c40985a27c 100644 --- a/drivers/leds/leds-mt6323.c +++ b/drivers/leds/leds-mt6323.c @@ -537,7 +537,7 @@ static int mt6323_led_probe(struct platform_device *pdev) u32 reg; u8 max_leds; - leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_obj(dev, *leds); if (!leds) return -ENOMEM; @@ -580,7 +580,7 @@ static int mt6323_led_probe(struct platform_device *pdev) return -EINVAL; } - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c index 99df46f2d9f528..6f59f91fac6c85 100644 --- a/drivers/leds/leds-netxbig.c +++ b/drivers/leds/leds-netxbig.c @@ -360,7 +360,7 @@ static int netxbig_gpio_ext_get(struct device *dev, return ret; } num_addr = ret; - addr = devm_kcalloc(dev, num_addr, sizeof(*addr), GFP_KERNEL); + addr = devm_kzalloc_objs(dev, *addr, num_addr); if (!addr) return -ENOMEM; @@ -391,7 +391,7 @@ static int netxbig_gpio_ext_get(struct device *dev, goto err_free_addr; } num_data = ret; - data = devm_kcalloc(dev, num_data, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_objs(dev, *data, num_data); if (!data) { ret = -ENOMEM; goto err_free_addr; @@ -461,7 +461,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, } gpio_ext_dev = &gpio_ext_pdev->dev; - gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL); + gpio_ext = devm_kzalloc_obj(dev, *gpio_ext); if (!gpio_ext) { of_node_put(gpio_ext_np); ret = -ENOMEM; @@ -482,8 +482,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, } num_timers = ret / 3; - timers = devm_kcalloc(dev, num_timers, sizeof(*timers), - GFP_KERNEL); + timers = devm_kzalloc_objs(dev, *timers, num_timers); if (!timers) { ret = -ENOMEM; goto put_device; @@ -516,7 +515,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, goto put_device; } - leds = devm_kcalloc(dev, num_leds, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_objs(dev, *leds, num_leds); if (!leds) { ret = -ENOMEM; goto put_device; @@ -544,9 +543,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, goto put_device; mode_val = - devm_kcalloc(dev, - NETXBIG_LED_MODE_NUM, sizeof(*mode_val), - GFP_KERNEL); + devm_kzalloc_objs(dev, *mode_val, NETXBIG_LED_MODE_NUM); if (!mode_val) { ret = -ENOMEM; goto put_device; @@ -617,16 +614,14 @@ static int netxbig_led_probe(struct platform_device *pdev) int i; int ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; ret = netxbig_leds_get_of_pdata(&pdev->dev, pdata); if (ret) return ret; - leds_data = devm_kcalloc(&pdev->dev, - pdata->num_leds, sizeof(*leds_data), - GFP_KERNEL); + leds_data = devm_kzalloc_objs(&pdev->dev, *leds_data, pdata->num_leds); if (!leds_data) return -ENOMEM; diff --git a/drivers/leds/leds-nic78bx.c b/drivers/leds/leds-nic78bx.c index 5e3098e1e1ad44..4fa472dbe3d192 100644 --- a/drivers/leds/leds-nic78bx.c +++ b/drivers/leds/leds-nic78bx.c @@ -141,7 +141,7 @@ static int nic78bx_probe(struct platform_device *pdev) struct resource *io_rc; int ret, i; - led_data = devm_kzalloc(dev, sizeof(*led_data), GFP_KERNEL); + led_data = devm_kzalloc_obj(dev, *led_data); if (!led_data) return -ENOMEM; diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index 4c6f04a5bd87e2..c62a269114e8b4 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -198,7 +198,7 @@ static int ns2_led_register(struct device *dev, struct fwnode_handle *node, } nmodes = ret / 3; - modval = devm_kcalloc(dev, nmodes, sizeof(*modval), GFP_KERNEL); + modval = devm_kzalloc_objs(dev, *modval, nmodes); if (!modval) return -ENOMEM; @@ -246,7 +246,7 @@ static int ns2_led_probe(struct platform_device *pdev) if (!count) return -ENODEV; - leds = devm_kcalloc(dev, count, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_objs(dev, *leds, count); if (!leds) return -ENOMEM; diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c index 1133fa348e2464..c8085427696ff9 100644 --- a/drivers/leds/leds-pca9532.c +++ b/drivers/leds/leds-pca9532.c @@ -522,7 +522,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np) devid = (int)(uintptr_t)of_device_get_match_data(dev); maxleds = pca9532_chip_info_tbl[devid].num_leds; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -581,7 +581,7 @@ static int pca9532_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c index e4af7a3b639f41..b6bf4adcc8ea6d 100644 --- a/drivers/leds/leds-pca955x.c +++ b/drivers/leds/leds-pca955x.c @@ -592,8 +592,7 @@ static int pca955x_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - pca955x = devm_kzalloc(&client->dev, - struct_size(pca955x, leds, chip->bits), GFP_KERNEL); + pca955x = devm_kzalloc_flex(&client->dev, *pca955x, leds, chip->bits); if (!pca955x) return -ENOMEM; diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index 5363afbe93eaf9..fa1721916963e8 100644 --- a/drivers/leds/leds-pca963x.c +++ b/drivers/leds/leds-pca963x.c @@ -530,7 +530,7 @@ static int pca963x_probe(struct i2c_client *client) return -EINVAL; } - chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL); + chip = devm_kzalloc_flex(dev, *chip, leds, count); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c index fee6216cd1bd05..3b6903c991fc32 100644 --- a/drivers/leds/leds-pca995x.c +++ b/drivers/leds/leds-pca995x.c @@ -130,7 +130,7 @@ static int pca995x_probe(struct i2c_client *client) if (!dev_fwnode(dev)) return -ENODEV; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c index 3f49a518189252..22f1ee40f097c0 100644 --- a/drivers/leds/leds-pm8058.c +++ b/drivers/leds/leds-pm8058.c @@ -95,7 +95,7 @@ static int pm8058_led_probe(struct platform_device *pdev) enum led_brightness maxbright; enum led_default_state state; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c index 3a38578ce8e4a0..2b2cde35cc509f 100644 --- a/drivers/leds/leds-powernv.c +++ b/drivers/leds/leds-powernv.c @@ -253,8 +253,7 @@ static int powernv_led_classdev(struct platform_device *pdev, p = of_find_property(np, "led-types", NULL); while ((cur = of_prop_next_string(p, cur)) != NULL) { - powernv_led = devm_kzalloc(dev, sizeof(*powernv_led), - GFP_KERNEL); + powernv_led = devm_kzalloc_obj(dev, *powernv_led); if (!powernv_led) return -ENOMEM; @@ -285,8 +284,7 @@ static int powernv_led_probe(struct platform_device *pdev) return -EINVAL; } - powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common), - GFP_KERNEL); + powernv_led_common = devm_kzalloc_obj(dev, *powernv_led_common); if (!powernv_led_common) return -ENOMEM; diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 6c1f2f50ff854f..3e5eda8590bb66 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -212,8 +212,7 @@ static int led_pwm_probe(struct platform_device *pdev) if (!count) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, count), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-qnap-mcu.c b/drivers/leds/leds-qnap-mcu.c index 6df110e33ac9c4..a0c19eac84b6bd 100644 --- a/drivers/leds/leds-qnap-mcu.c +++ b/drivers/leds/leds-qnap-mcu.c @@ -80,7 +80,7 @@ static int qnap_mcu_register_err_led(struct device *dev, struct qnap_mcu *mcu, i struct qnap_mcu_err_led *err_led; int ret; - err_led = devm_kzalloc(dev, sizeof(*err_led), GFP_KERNEL); + err_led = devm_kzalloc_obj(dev, *err_led); if (!err_led) return -ENOMEM; @@ -171,7 +171,7 @@ static int qnap_mcu_register_usb_led(struct device *dev, struct qnap_mcu *mcu) struct qnap_mcu_usb_led *usb_led; int ret; - usb_led = devm_kzalloc(dev, sizeof(*usb_led), GFP_KERNEL); + usb_led = devm_kzalloc_obj(dev, *usb_led); if (!usb_led) return -ENOMEM; @@ -312,7 +312,7 @@ static int qnap_mcu_register_status_leds(struct device *dev, struct qnap_mcu *mc struct qnap_mcu_status *status; int ret; - status = devm_kzalloc(dev, sizeof(*status), GFP_KERNEL); + status = devm_kzalloc_obj(dev, *status); if (!status) return -ENOMEM; diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c index 5ba0f36b2d8145..200e2573370158 100644 --- a/drivers/leds/leds-regulator.c +++ b/drivers/leds/leds-regulator.c @@ -135,7 +135,7 @@ static int regulator_led_probe(struct platform_device *pdev) return PTR_ERR(vcc); } - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (led == NULL) return -ENOMEM; diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c index 0c5169773949a2..9a5977b62ca3de 100644 --- a/drivers/leds/leds-sc27xx-bltc.c +++ b/drivers/leds/leds-sc27xx-bltc.c @@ -291,7 +291,7 @@ static int sc27xx_led_probe(struct platform_device *pdev) return err; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c index 0217557aad572d..c438a5c593580c 100644 --- a/drivers/leds/leds-spi-byte.c +++ b/drivers/leds/leds-spi-byte.c @@ -85,7 +85,7 @@ static int spi_byte_probe(struct spi_device *spi) return -EINVAL; } - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c index 8c2e1d58ba0c80..163d6386993a80 100644 --- a/drivers/leds/leds-st1202.c +++ b/drivers/leds/leds-st1202.c @@ -506,7 +506,7 @@ static int st1202_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return dev_err_probe(&client->dev, -EIO, "SMBUS Byte Data not Supported\n"); - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c index 7cfb4c7390bf8d..a806638c9211de 100644 --- a/drivers/leds/leds-sun50i-a100.c +++ b/drivers/leds/leds-sun50i-a100.c @@ -419,7 +419,7 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) if (!num_leds) return -ENODEV; - priv = devm_kzalloc(dev, struct_size(priv, leds, num_leds), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, num_leds); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-sunfire.c b/drivers/leds/leds-sunfire.c index bd24e7f5947ab4..c858b7bb6d17ae 100644 --- a/drivers/leds/leds-sunfire.c +++ b/drivers/leds/leds-sunfire.c @@ -135,7 +135,7 @@ static int sunfire_led_generic_probe(struct platform_device *pdev, return -EINVAL; } - p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c index 741850f35f1927..50603bb70b705d 100644 --- a/drivers/leds/leds-syscon.c +++ b/drivers/leds/leds-syscon.c @@ -74,7 +74,7 @@ static int syscon_led_probe(struct platform_device *pdev) return PTR_ERR(map); } - sled = devm_kzalloc(dev, sizeof(*sled), GFP_KERNEL); + sled = devm_kzalloc_obj(dev, *sled); if (!sled) return -ENOMEM; diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index 9afe2722986cf7..07c8f8deeed8e4 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c @@ -666,8 +666,7 @@ tca6507_led_dt_init(struct device *dev) if (!count || count > NUM_LEDS) return ERR_PTR(-ENODEV); - tca_leds = devm_kcalloc(dev, NUM_LEDS, sizeof(struct led_info), - GFP_KERNEL); + tca_leds = devm_kzalloc_objs(dev, struct led_info, NUM_LEDS); if (!tca_leds) return ERR_PTR(-ENOMEM); @@ -694,8 +693,7 @@ tca6507_led_dt_init(struct device *dev) tca_leds[reg] = led; } - pdata = devm_kzalloc(dev, sizeof(struct tca6507_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct tca6507_platform_data); if (!pdata) return ERR_PTR(-ENOMEM); @@ -730,7 +728,7 @@ static int tca6507_probe(struct i2c_client *client) dev_err(dev, "Need %d entries in platform-data list\n", NUM_LEDS); return PTR_ERR(pdata); } - tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL); + tca = devm_kzalloc_obj(dev, *tca); if (!tca) return -ENOMEM; diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c index 2f272cfd2e916f..0c2801c4d7d34b 100644 --- a/drivers/leds/leds-tlc591xx.c +++ b/drivers/leds/leds-tlc591xx.c @@ -164,7 +164,7 @@ tlc591xx_probe(struct i2c_client *client) if (!count || count > tlc591xx->max_leds) return -EINVAL; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/leds/leds-tps6105x.c b/drivers/leds/leds-tps6105x.c index 09fd88a6c8f018..71418fc28cd639 100644 --- a/drivers/leds/leds-tps6105x.c +++ b/drivers/leds/leds-tps6105x.c @@ -48,7 +48,7 @@ static int tps6105x_led_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; /* fwnode/devicetree is optional. NULL is allowed for priv->fwnode */ diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 57128ae7e8fdd2..9a8db86bf562f0 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -486,7 +486,7 @@ static int omnia_leds_probe(struct i2c_client *client) if (count > OMNIA_BOARD_LEDS) return dev_err_probe(dev, -EINVAL, "Too many LEDs defined in device tree!\n"); - leds = devm_kzalloc(dev, struct_size(leds, leds, count), GFP_KERNEL); + leds = devm_kzalloc_flex(dev, *leds, leds, count); if (!leds) return -ENOMEM; diff --git a/drivers/leds/leds-upboard.c b/drivers/leds/leds-upboard.c index 12989b2f195309..eeb78595b1cecf 100644 --- a/drivers/leds/leds-upboard.c +++ b/drivers/leds/leds-upboard.c @@ -88,7 +88,7 @@ static int upboard_led_probe(struct platform_device *pdev) .msb = led_profile[i].bit, }; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/leds/leds-wm831x-status.c b/drivers/leds/leds-wm831x-status.c index 05930e9e88878e..c261f4df398a3c 100644 --- a/drivers/leds/leds-wm831x-status.c +++ b/drivers/leds/leds-wm831x-status.c @@ -221,8 +221,7 @@ static int wm831x_status_probe(struct platform_device *pdev) return -EINVAL; } - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_status), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct wm831x_status); if (!drvdata) return -ENOMEM; diff --git a/drivers/leds/leds-wm8350.c b/drivers/leds/leds-wm8350.c index 87e60ea927b9bb..05a6795e4734b8 100644 --- a/drivers/leds/leds-wm8350.c +++ b/drivers/leds/leds-wm8350.c @@ -213,7 +213,7 @@ static int wm8350_led_probe(struct platform_device *pdev) return PTR_ERR(dcdc); } - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (led == NULL) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-group-multicolor.c b/drivers/leds/rgb/leds-group-multicolor.c index a707d51c6a4bd8..34c5ec2ea91f62 100644 --- a/drivers/leds/rgb/leds-group-multicolor.c +++ b/drivers/leds/rgb/leds-group-multicolor.c @@ -70,7 +70,7 @@ static int leds_gmc_probe(struct platform_device *pdev) unsigned int max_brightness = 0; int i, ret, count = 0, common_flags = 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -98,7 +98,7 @@ static int leds_gmc_probe(struct platform_device *pdev) count++; } - subled = devm_kcalloc(dev, count, sizeof(*subled), GFP_KERNEL); + subled = devm_kzalloc_objs(dev, *subled, count); if (!subled) return -ENOMEM; priv->mc_cdev.subled_info = subled; diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c index 143020945e23f8..f1822281c3e614 100644 --- a/drivers/leds/rgb/leds-ktd202x.c +++ b/drivers/leds/rgb/leds-ktd202x.c @@ -397,7 +397,7 @@ static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *fwn if (!num_channels || num_channels > chip->num_leds) return -EINVAL; - info = devm_kcalloc(chip->dev, num_channels, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_objs(chip->dev, *info, num_channels); if (!info) return -ENOMEM; @@ -540,7 +540,7 @@ static int ktd202x_probe(struct i2c_client *client) if (!count || count > KTD202X_MAX_LEDS) return dev_err_probe(dev, -EINVAL, "Incorrect number of leds (%d)", count); - chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL); + chip = devm_kzalloc_flex(dev, *chip, leds, count); if (!chip) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-lp5812.c b/drivers/leds/rgb/leds-lp5812.c index ce6d703641e847..3d38d45043dd32 100644 --- a/drivers/leds/rgb/leds-lp5812.c +++ b/drivers/leds/rgb/leds-lp5812.c @@ -340,8 +340,8 @@ static int lp5812_init_led(struct lp5812_led *led, struct lp5812_chip *chip, int } if (!chip->led_config[chan].is_sc_led) { - mc_led_info = devm_kcalloc(dev, chip->led_config[chan].num_colors, - sizeof(*mc_led_info), GFP_KERNEL); + mc_led_info = devm_kzalloc_objs(dev, *mc_led_info, + chip->led_config[chan].num_colors); if (!mc_led_info) return -ENOMEM; @@ -550,7 +550,7 @@ static int lp5812_of_probe(struct device *dev, return -EINVAL; } - cfg = devm_kcalloc(dev, num_channels, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_objs(dev, *cfg, num_channels); if (!cfg) return -ENOMEM; @@ -583,7 +583,7 @@ static int lp5812_probe(struct i2c_client *client) if (!np) return -EINVAL; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; @@ -591,7 +591,7 @@ static int lp5812_probe(struct i2c_client *client) if (ret) return ret; - leds = devm_kcalloc(&client->dev, chip->num_channels, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc_objs(&client->dev, *leds, chip->num_channels); if (!leds) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c index e21d5f2302be0c..fe6da432fb3b5e 100644 --- a/drivers/leds/rgb/leds-lp5860-core.c +++ b/drivers/leds/rgb/leds-lp5860-core.c @@ -159,7 +159,7 @@ static int lp5860_init_dt(struct lp5860 *lp) led->mc_cdev.num_colors = chan; - mc_led_info = devm_kcalloc(lp->dev, chan, sizeof(*mc_led_info), GFP_KERNEL); + mc_led_info = devm_kzalloc_objs(lp->dev, *mc_led_info, chan); if (!mc_led_info) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-lp5860-spi.c b/drivers/leds/rgb/leds-lp5860-spi.c index 6bf6a625c28af7..f035f876e4d334 100644 --- a/drivers/leds/rgb/leds-lp5860-spi.c +++ b/drivers/leds/rgb/leds-lp5860-spi.c @@ -51,8 +51,7 @@ static int lp5860_probe(struct spi_device *spi) return -EINVAL; } - lp5860 = devm_kzalloc(dev, struct_size(lp5860, leds, multi_leds), - GFP_KERNEL); + lp5860 = devm_kzalloc_flex(dev, *lp5860, leds, multi_leds); if (!lp5860) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-mt6370-rgb.c b/drivers/leds/rgb/leds-mt6370-rgb.c index 2c0ccd1ba7fbe2..b8b94b83f137cf 100644 --- a/drivers/leds/rgb/leds-mt6370-rgb.c +++ b/drivers/leds/rgb/leds-mt6370-rgb.c @@ -718,7 +718,7 @@ static int mt6370_assign_multicolor_info(struct device *dev, struct mt6370_led * u32 num_color = 0; int ret; - sub_led = devm_kcalloc(dev, MC_CHANNEL_NUM, sizeof(*sub_led), GFP_KERNEL); + sub_led = devm_kzalloc_objs(dev, *sub_led, MC_CHANNEL_NUM); if (!sub_led) return -ENOMEM; @@ -914,7 +914,7 @@ static int mt6370_leds_probe(struct platform_device *pdev) "No child node or node count over max LED number %zu\n", count); - priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, leds, count); if (!priv) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-ncp5623.c b/drivers/leds/rgb/leds-ncp5623.c index f2528f06507dd2..70282ea3d90005 100644 --- a/drivers/leds/rgb/leds-ncp5623.c +++ b/drivers/leds/rgb/leds-ncp5623.c @@ -161,7 +161,7 @@ static int ncp5623_probe(struct i2c_client *client) u32 reg; int ret; - ncp = devm_kzalloc(dev, sizeof(*ncp), GFP_KERNEL); + ncp = devm_kzalloc_obj(dev, *ncp); if (!ncp) return -ENOMEM; @@ -173,7 +173,7 @@ static int ncp5623_probe(struct i2c_client *client) num_subleds = fwnode_get_child_node_count(mc_node); - subled_info = devm_kcalloc(dev, num_subleds, sizeof(*subled_info), GFP_KERNEL); + subled_info = devm_kzalloc_objs(dev, *subled_info, num_subleds); if (!subled_info) { ret = -ENOMEM; goto release_mc_node; diff --git a/drivers/leds/rgb/leds-pwm-multicolor.c b/drivers/leds/rgb/leds-pwm-multicolor.c index 6365459ec27f17..c8395fdbcbdbc9 100644 --- a/drivers/leds/rgb/leds-pwm-multicolor.c +++ b/drivers/leds/rgb/leds-pwm-multicolor.c @@ -124,15 +124,14 @@ static int led_pwm_mc_probe(struct platform_device *pdev) /* count the nodes inside the multi-led node */ count = fwnode_get_child_node_count(mcnode); - priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, count), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, leds, count); if (!priv) { ret = -ENOMEM; goto release_mcnode; } mutex_init(&priv->lock); - subled = devm_kcalloc(&pdev->dev, count, sizeof(*subled), GFP_KERNEL); + subled = devm_kzalloc_objs(&pdev->dev, *subled, count); if (!subled) { ret = -ENOMEM; goto release_mcnode; diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index 24ffe079f22153..98e39e03b9a151 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -1394,7 +1394,7 @@ static int lpg_add_led(struct lpg *lpg, struct fwnode_handle *fw) else num_channels = 1; - led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL); + led = devm_kzalloc_flex(lpg->dev, *led, channels, num_channels); if (!led) return -ENOMEM; @@ -1402,7 +1402,7 @@ static int lpg_add_led(struct lpg *lpg, struct fwnode_handle *fw) led->num_channels = num_channels; if (color == LED_COLOR_ID_RGB || color == LED_COLOR_ID_MULTI) { - info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_objs(lpg->dev, *info, num_channels); if (!info) return -ENOMEM; i = 0; @@ -1609,7 +1609,7 @@ static int lpg_probe(struct platform_device *pdev) if (!data) return -EINVAL; - lpg = devm_kzalloc(&pdev->dev, struct_size(lpg, channels, data->num_channels), GFP_KERNEL); + lpg = devm_kzalloc_flex(&pdev->dev, *lpg, channels, data->num_channels); if (!lpg) return -ENOMEM; diff --git a/drivers/leds/rgb/leds-s2m-rgb.c b/drivers/leds/rgb/leds-s2m-rgb.c index d239f54eee9011..902307d7567f4b 100644 --- a/drivers/leds/rgb/leds-s2m-rgb.c +++ b/drivers/leds/rgb/leds-s2m-rgb.c @@ -368,7 +368,7 @@ static int s2m_rgb_probe(struct platform_device *pdev) struct led_init_data init_data = {}; int ret; - rgb = devm_kzalloc(dev, sizeof(*rgb), GFP_KERNEL); + rgb = devm_kzalloc_obj(dev, *rgb); if (!rgb) return -ENOMEM; diff --git a/drivers/leds/simatic/simatic-ipc-leds-gpio-f7188x.c b/drivers/leds/simatic/simatic-ipc-leds-gpio-f7188x.c index bc23d701bcb79c..656c5f5bec74c9 100644 --- a/drivers/leds/simatic/simatic-ipc-leds-gpio-f7188x.c +++ b/drivers/leds/simatic/simatic-ipc-leds-gpio-f7188x.c @@ -62,7 +62,7 @@ static int simatic_ipc_leds_gpio_f7188x_probe(struct platform_device *pdev) const struct simatic_ipc_platform *plat = dev_get_platdata(&pdev->dev); struct simatic_ipc_led_tables *led_tables; - led_tables = devm_kzalloc(&pdev->dev, sizeof(*led_tables), GFP_KERNEL); + led_tables = devm_kzalloc_obj(&pdev->dev, *led_tables); if (!led_tables) return -ENOMEM; diff --git a/drivers/mailbox/arm_mhu.c b/drivers/mailbox/arm_mhu.c index 0950b7bce18466..8d335afbc36abe 100644 --- a/drivers/mailbox/arm_mhu.c +++ b/drivers/mailbox/arm_mhu.c @@ -118,7 +118,7 @@ static int mhu_probe(struct amba_device *adev, const struct amba_id *id) return -ENODEV; /* Allocate memory for device */ - mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); + mhu = devm_kzalloc_obj(dev, *mhu); if (!mhu) return -ENOMEM; diff --git a/drivers/mailbox/arm_mhu_db.c b/drivers/mailbox/arm_mhu_db.c index 9f1c7bcfdcb405..70eae842fadbcf 100644 --- a/drivers/mailbox/arm_mhu_db.c +++ b/drivers/mailbox/arm_mhu_db.c @@ -221,7 +221,7 @@ static struct mbox_chan *mhu_db_mbox_xlate(struct mbox_controller *mbox, chan = &mbox->chans[i]; - chan_info = devm_kzalloc(mbox->dev, sizeof(*chan_info), GFP_KERNEL); + chan_info = devm_kzalloc_obj(mbox->dev, *chan_info); if (!chan_info) return ERR_PTR(-ENOMEM); @@ -272,7 +272,7 @@ static int mhu_db_probe(struct amba_device *adev, const struct amba_id *id) return -EINVAL; } - mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); + mhu = devm_kzalloc_obj(dev, *mhu); if (!mhu) return -ENOMEM; @@ -280,7 +280,7 @@ static int mhu_db_probe(struct amba_device *adev, const struct amba_id *id) if (IS_ERR(mhu->base)) return PTR_ERR(mhu->base); - chans = devm_kcalloc(dev, max_chans, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, max_chans); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/arm_mhuv2.c b/drivers/mailbox/arm_mhuv2.c index 0520d499663408..995a3a9a88360e 100644 --- a/drivers/mailbox/arm_mhuv2.c +++ b/drivers/mailbox/arm_mhuv2.c @@ -878,7 +878,7 @@ static int mhuv2_allocate_channels(struct mhuv2 *mhu) struct mbox_chan *chans; int protocol, windows = 0, next_window = 0, i, j, k; - chans = devm_kcalloc(dev, mbox->num_chans, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, mbox->num_chans); if (!chans) return -ENOMEM; @@ -891,7 +891,7 @@ static int mhuv2_allocate_channels(struct mhuv2 *mhu) windows = mhu->protocols[i + 1]; if (protocol == DATA_TRANSFER) { - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -904,7 +904,7 @@ static int mhuv2_allocate_channels(struct mhuv2 *mhu) for (j = 0; j < windows; j++) { for (k = 0; k < MHUV2_STAT_BITS; k++) { - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -942,7 +942,7 @@ static int mhuv2_parse_channels(struct mhuv2 *mhu) return -EINVAL; } - protocols = devm_kmalloc_array(dev, count, sizeof(*protocols), GFP_KERNEL); + protocols = devm_kmalloc_objs(dev, *protocols, count); if (!protocols) return -ENOMEM; @@ -1065,7 +1065,7 @@ static int mhuv2_probe(struct amba_device *adev, const struct amba_id *id) if (IS_ERR(reg)) return PTR_ERR(reg); - mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); + mhu = devm_kzalloc_obj(dev, *mhu); if (!mhu) return -ENOMEM; diff --git a/drivers/mailbox/arm_mhuv3.c b/drivers/mailbox/arm_mhuv3.c index b9addd9e2c41f4..e4140005a662e1 100644 --- a/drivers/mailbox/arm_mhuv3.c +++ b/drivers/mailbox/arm_mhuv3.c @@ -606,7 +606,7 @@ static int mhuv3_dbe_channels_init(struct mhuv3 *mhu) int k; for (k = 0; k < MHUV3_FLAG_BITS; k++) { - priv = devm_kmalloc(mbox->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(mbox->dev, *priv); if (!priv) return -ENOMEM; @@ -713,7 +713,7 @@ static int mhuv3_dbe_init(struct mhuv3 *mhu) dev_dbg(dev, "%s: Initializing DBE Extension.\n", mhuv3_str[mhu->frame]); - e = devm_kzalloc(dev, sizeof(*e), GFP_KERNEL); + e = devm_kzalloc_obj(dev, *e); if (!e) return -ENOMEM; @@ -772,8 +772,7 @@ static int mhuv3_initialize_channels(struct device *dev, struct mhuv3 *mhu) struct mbox_controller *mbox = &mhu->mbox; int i, ret = 0; - mbox->chans = devm_kcalloc(dev, mhu->num_chans, - sizeof(*mbox->chans), GFP_KERNEL); + mbox->chans = devm_kzalloc_objs(dev, *mbox->chans, mhu->num_chans); if (!mbox->chans) return dev_err_probe(dev, -ENOMEM, "Failed to initialize channels\n"); @@ -1054,7 +1053,7 @@ static int mhuv3_probe(struct platform_device *pdev) struct mhuv3 *mhu; int ret; - mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); + mhu = devm_kzalloc_obj(dev, *mhu); if (!mhu) return -ENOMEM; diff --git a/drivers/mailbox/armada-37xx-rwtm-mailbox.c b/drivers/mailbox/armada-37xx-rwtm-mailbox.c index 047926711e96f0..62fc037a3bec4f 100644 --- a/drivers/mailbox/armada-37xx-rwtm-mailbox.c +++ b/drivers/mailbox/armada-37xx-rwtm-mailbox.c @@ -144,12 +144,12 @@ static int armada_37xx_mbox_probe(struct platform_device *pdev) struct mbox_chan *chans; int ret; - mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(&pdev->dev, *mbox); if (!mbox) return -ENOMEM; /* Allocated one channel */ - chans = devm_kzalloc(&pdev->dev, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_obj(&pdev->dev, *chans); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/ast2700-mailbox.c b/drivers/mailbox/ast2700-mailbox.c index 83c6afe5411f80..ac77e43f1f92c0 100644 --- a/drivers/mailbox/ast2700-mailbox.c +++ b/drivers/mailbox/ast2700-mailbox.c @@ -163,12 +163,12 @@ static int ast2700_mbox_probe(struct platform_device *pdev) dev_data = device_get_match_data(&pdev->dev); - mb = devm_kzalloc(dev, sizeof(*mb), GFP_KERNEL); + mb = devm_kzalloc_obj(dev, *mb); if (!mb) return -ENOMEM; - mb->mbox.chans = devm_kcalloc(&pdev->dev, dev_data->num_chans, - sizeof(*mb->mbox.chans), GFP_KERNEL); + mb->mbox.chans = devm_kzalloc_objs(&pdev->dev, *mb->mbox.chans, + dev_data->num_chans); if (!mb->mbox.chans) return -ENOMEM; diff --git a/drivers/mailbox/axiado-mailbox.c b/drivers/mailbox/axiado-mailbox.c index a87693c639dcf4..9951196f528fd0 100644 --- a/drivers/mailbox/axiado-mailbox.c +++ b/drivers/mailbox/axiado-mailbox.c @@ -343,17 +343,15 @@ static int axiado_mbox_probe(struct platform_device *pdev) if (!drv_data) return -ENODEV; - mb = devm_kzalloc(dev, sizeof(*mb), GFP_KERNEL); + mb = devm_kzalloc_obj(dev, *mb); if (!mb) return -ENOMEM; mb->mbox.dev = dev; mb->mbox.num_chans = drv_data->num_chans; - mb->mbox.chans = devm_kcalloc(&pdev->dev, - drv_data->num_chans, - sizeof(*mb->mbox.chans), - GFP_KERNEL); + mb->mbox.chans = devm_kzalloc_objs(&pdev->dev, *mb->mbox.chans, + drv_data->num_chans); if (!mb->mbox.chans) return -ENOMEM; @@ -365,10 +363,7 @@ static int axiado_mbox_probe(struct platform_device *pdev) if (IS_ERR(mb->rx_base)) return PTR_ERR(mb->rx_base); - ch_data = devm_kcalloc(&pdev->dev, - drv_data->num_chans, - sizeof(*ch_data), - GFP_KERNEL); + ch_data = devm_kzalloc_objs(&pdev->dev, *ch_data, drv_data->num_chans); if (!ch_data) return -ENOMEM; diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index 04c47eadf950b3..d5cec5ae3f4e6e 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -1482,7 +1482,7 @@ static int flexrm_mbox_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; /* Allocate driver mailbox struct */ - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) { ret = -ENOMEM; goto fail; @@ -1513,7 +1513,7 @@ static int flexrm_mbox_probe(struct platform_device *pdev) } /* Allocate driver ring structs */ - ring = devm_kcalloc(dev, mbox->num_rings, sizeof(*ring), GFP_KERNEL); + ring = devm_kzalloc_objs(dev, *ring, mbox->num_rings); if (!ring) { ret = -ENOMEM; goto fail; @@ -1609,8 +1609,8 @@ static int flexrm_mbox_probe(struct platform_device *pdev) mbox->controller.dev = dev; mbox->controller.num_chans = mbox->num_rings; mbox->controller.of_xlate = flexrm_mbox_of_xlate; - mbox->controller.chans = devm_kcalloc(dev, mbox->num_rings, - sizeof(*mbox->controller.chans), GFP_KERNEL); + mbox->controller.chans = devm_kzalloc_objs(dev, *mbox->controller.chans, + mbox->num_rings); if (!mbox->controller.chans) { ret = -ENOMEM; goto fail_free_debugfs_root; diff --git a/drivers/mailbox/bcm-pdc-mailbox.c b/drivers/mailbox/bcm-pdc-mailbox.c index 6fcc4002ad4fd2..88f0d1a81385e3 100644 --- a/drivers/mailbox/bcm-pdc-mailbox.c +++ b/drivers/mailbox/bcm-pdc-mailbox.c @@ -1438,8 +1438,7 @@ static int pdc_mb_init(struct pdc_state *pdcs) mbc->dev = dev; mbc->ops = &pdc_mbox_chan_ops; mbc->num_chans = 1; - mbc->chans = devm_kcalloc(dev, mbc->num_chans, sizeof(*mbc->chans), - GFP_KERNEL); + mbc->chans = devm_kzalloc_objs(dev, *mbc->chans, mbc->num_chans); if (!mbc->chans) return -ENOMEM; @@ -1527,7 +1526,7 @@ static int pdc_probe(struct platform_device *pdev) struct pdc_state *pdcs; /* PDC state for one SPU */ - pdcs = devm_kzalloc(dev, sizeof(*pdcs), GFP_KERNEL); + pdcs = devm_kzalloc_obj(dev, *pdcs); if (!pdcs) { err = -ENOMEM; goto cleanup; diff --git a/drivers/mailbox/bcm2835-mailbox.c b/drivers/mailbox/bcm2835-mailbox.c index 0ca75c378a6028..ea9d1b90c0170f 100644 --- a/drivers/mailbox/bcm2835-mailbox.c +++ b/drivers/mailbox/bcm2835-mailbox.c @@ -149,7 +149,7 @@ static int bcm2835_mbox_probe(struct platform_device *pdev) if (IS_ERR(regs)) return PTR_ERR(regs); - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (mbox == NULL) return -ENOMEM; @@ -167,8 +167,7 @@ static int bcm2835_mbox_probe(struct platform_device *pdev) mbox->controller.of_xlate = &bcm2835_mbox_index_xlate; mbox->controller.dev = dev; mbox->controller.num_chans = 1; - mbox->controller.chans = devm_kzalloc(dev, - sizeof(*mbox->controller.chans), GFP_KERNEL); + mbox->controller.chans = devm_kzalloc_obj(dev, *mbox->controller.chans); if (!mbox->controller.chans) return -ENOMEM; diff --git a/drivers/mailbox/bcm74110-mailbox.c b/drivers/mailbox/bcm74110-mailbox.c index bec138d76914da..5c503311efe544 100644 --- a/drivers/mailbox/bcm74110-mailbox.c +++ b/drivers/mailbox/bcm74110-mailbox.c @@ -584,7 +584,7 @@ static int bcm74110_mbox_probe(struct platform_device *pdev) struct bcm74110_mbox *mbox; int i, ret; - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; @@ -620,15 +620,13 @@ static int bcm74110_mbox_probe(struct platform_device *pdev) mbox->controller.dev = dev; mbox->controller.num_chans = BCM_MSG_SVC_MAX; mbox->controller.of_xlate = &bcm74110_mbox_of_xlate; - mbox->controller.chans = devm_kcalloc(dev, BCM_MSG_SVC_MAX, - sizeof(*mbox->controller.chans), - GFP_KERNEL); + mbox->controller.chans = devm_kzalloc_objs(dev, *mbox->controller.chans, + BCM_MSG_SVC_MAX); if (!mbox->controller.chans) return -ENOMEM; - mbox->mbox_chan = devm_kcalloc(dev, BCM_MSG_SVC_MAX, - sizeof(*mbox->mbox_chan), - GFP_KERNEL); + mbox->mbox_chan = devm_kzalloc_objs(dev, *mbox->mbox_chan, + BCM_MSG_SVC_MAX); if (!mbox->mbox_chan) return -ENOMEM; diff --git a/drivers/mailbox/cix-mailbox.c b/drivers/mailbox/cix-mailbox.c index 7fa979c1b8f02a..8b2b0a34e1eb10 100644 --- a/drivers/mailbox/cix-mailbox.c +++ b/drivers/mailbox/cix-mailbox.c @@ -562,7 +562,7 @@ static int cix_mbox_probe(struct platform_device *pdev) const char *dir_str; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mailbox/cv1800-mailbox.c b/drivers/mailbox/cv1800-mailbox.c index b062c2c4fc61e0..abe035f750d211 100644 --- a/drivers/mailbox/cv1800-mailbox.c +++ b/drivers/mailbox/cv1800-mailbox.c @@ -165,7 +165,7 @@ static int cv1800_mbox_probe(struct platform_device *pdev) struct cv1800_mbox *mb; int irq, idx, err; - mb = devm_kzalloc(dev, sizeof(*mb), GFP_KERNEL); + mb = devm_kzalloc_obj(dev, *mb); if (!mb) return -ENOMEM; diff --git a/drivers/mailbox/exynos-mailbox.c b/drivers/mailbox/exynos-mailbox.c index ff75c1c7633c81..bad1182431b1b4 100644 --- a/drivers/mailbox/exynos-mailbox.c +++ b/drivers/mailbox/exynos-mailbox.c @@ -153,15 +153,15 @@ static int exynos_mbox_probe(struct platform_device *pdev) if (!data) return -ENODEV; - exynos_mbox = devm_kzalloc(dev, sizeof(*exynos_mbox), GFP_KERNEL); + exynos_mbox = devm_kzalloc_obj(dev, *exynos_mbox); if (!exynos_mbox) return -ENOMEM; - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; - chans = devm_kcalloc(dev, data->num_chans, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, data->num_chans); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/hi3660-mailbox.c b/drivers/mailbox/hi3660-mailbox.c index 9b727a2b54a57b..ededa645d38eb0 100644 --- a/drivers/mailbox/hi3660-mailbox.c +++ b/drivers/mailbox/hi3660-mailbox.c @@ -240,7 +240,7 @@ static int hi3660_mbox_probe(struct platform_device *pdev) unsigned long ch; int err; - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; diff --git a/drivers/mailbox/hi6220-mailbox.c b/drivers/mailbox/hi6220-mailbox.c index 8eb8242209be7a..06072904ed2552 100644 --- a/drivers/mailbox/hi6220-mailbox.c +++ b/drivers/mailbox/hi6220-mailbox.c @@ -267,15 +267,14 @@ static int hi6220_mbox_probe(struct platform_device *pdev) struct hi6220_mbox *mbox; int i, err; - mbox = devm_kzalloc(dev, struct_size(mbox, mchan, MBOX_CHAN_MAX), GFP_KERNEL); + mbox = devm_kzalloc_flex(dev, *mbox, mchan, MBOX_CHAN_MAX); if (!mbox) return -ENOMEM; mbox->chan_num = MBOX_CHAN_MAX; mbox->dev = dev; - mbox->chan = devm_kcalloc(dev, - mbox->chan_num, sizeof(*mbox->chan), GFP_KERNEL); + mbox->chan = devm_kzalloc_objs(dev, *mbox->chan, mbox->chan_num); if (!mbox->chan) return -ENOMEM; diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c index 40bad2b3e4d193..683ccea6f2ba68 100644 --- a/drivers/mailbox/imx-mailbox.c +++ b/drivers/mailbox/imx-mailbox.c @@ -920,7 +920,7 @@ static int imx_mu_probe(struct platform_device *pdev) int i, ret; u32 size; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-altera.c b/drivers/mailbox/mailbox-altera.c index 7cb91413ef7fc5..7301e0fc3f5d9a 100644 --- a/drivers/mailbox/mailbox-altera.c +++ b/drivers/mailbox/mailbox-altera.c @@ -288,13 +288,12 @@ static int altera_mbox_probe(struct platform_device *pdev) struct mbox_chan *chans; int ret; - mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), - GFP_KERNEL); + mbox = devm_kzalloc_obj(&pdev->dev, *mbox); if (!mbox) return -ENOMEM; /* Allocated one channel */ - chans = devm_kzalloc(&pdev->dev, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_obj(&pdev->dev, *chans); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-mchp-ipc-sbi.c b/drivers/mailbox/mailbox-mchp-ipc-sbi.c index f081f8a9bcf8e6..dc485be8498bfc 100644 --- a/drivers/mailbox/mailbox-mchp-ipc-sbi.c +++ b/drivers/mailbox/mailbox-mchp-ipc-sbi.c @@ -391,9 +391,8 @@ static int mchp_ipc_get_cluster_aggr_irq(struct mchp_ipc_sbi_mbox *ipc) if (ret) return ret; - ipc->cluster_cfg[cpuid].buf_base = devm_kmalloc(ipc->dev, - sizeof(struct mchp_ipc_status), - GFP_KERNEL); + ipc->cluster_cfg[cpuid].buf_base = devm_kmalloc_obj(ipc->dev, + struct mchp_ipc_status); if (!ipc->cluster_cfg[cpuid].buf_base) return -ENOMEM; @@ -420,13 +419,13 @@ static int mchp_ipc_probe(struct platform_device *pdev) if (ret <= 0) return dev_err_probe(dev, -ENODEV, "Microchip SBI extension not detected\n"); - ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL); + ipc = devm_kzalloc_obj(dev, *ipc); if (!ipc) return -ENOMEM; platform_set_drvdata(pdev, ipc); - ipc->buf_base = devm_kmalloc(dev, sizeof(struct mchp_ipc_mbox_info), GFP_KERNEL); + ipc->buf_base = devm_kmalloc_obj(dev, struct mchp_ipc_mbox_info); if (!ipc->buf_base) return -ENOMEM; @@ -440,7 +439,8 @@ static int mchp_ipc_probe(struct platform_device *pdev) ipc->controller.num_chans = ipc_info.num_channels; ipc->hw_type = ipc_info.hw_type; - ipc->chans = devm_kcalloc(dev, ipc->controller.num_chans, sizeof(*ipc->chans), GFP_KERNEL); + ipc->chans = devm_kzalloc_objs(dev, *ipc->chans, + ipc->controller.num_chans); if (!ipc->chans) return -ENOMEM; @@ -452,7 +452,7 @@ static int mchp_ipc_probe(struct platform_device *pdev) ipc->controller.of_xlate = mchp_ipc_mbox_xlate; for (chan_id = 0; chan_id < ipc->controller.num_chans; chan_id++) { - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -461,9 +461,9 @@ static int mchp_ipc_probe(struct platform_device *pdev) } if (ipc->hw_type == MIV_IHC) { - ipc->cluster_cfg = devm_kcalloc(dev, num_online_cpus(), - sizeof(struct mchp_ipc_cluster_cfg), - GFP_KERNEL); + ipc->cluster_cfg = devm_kzalloc_objs(dev, + struct mchp_ipc_cluster_cfg, + num_online_cpus()); if (!ipc->cluster_cfg) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index 704a259bbca8f8..8298d82b936c8c 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -278,7 +278,7 @@ static int mpfs_mbox_probe(struct platform_device *pdev) struct mpfs_mbox *mbox; int ret; - mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(&pdev->dev, *mbox); if (!mbox) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-sti.c b/drivers/mailbox/mailbox-sti.c index 4fb5d1b5504a65..b0fa04f15236bd 100644 --- a/drivers/mailbox/mailbox-sti.c +++ b/drivers/mailbox/mailbox-sti.c @@ -361,7 +361,7 @@ static struct mbox_chan *sti_mbox_xlate(struct mbox_controller *mbox, return ERR_PTR(-EBUSY); } - chan_info = devm_kzalloc(mbox->dev, sizeof(*chan_info), GFP_KERNEL); + chan_info = devm_kzalloc_obj(mbox->dev, *chan_info); if (!chan_info) return ERR_PTR(-ENOMEM); @@ -414,7 +414,7 @@ static int sti_mbox_probe(struct platform_device *pdev) return -ENODEV; } - mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL); + mdev = devm_kzalloc_obj(&pdev->dev, *mdev); if (!mdev) return -ENOMEM; @@ -428,12 +428,11 @@ static int sti_mbox_probe(struct platform_device *pdev) if (ret) mdev->name = np->full_name; - mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(&pdev->dev, *mbox); if (!mbox) return -ENOMEM; - chans = devm_kcalloc(&pdev->dev, - STI_MBOX_CHAN_MAX, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(&pdev->dev, *chans, STI_MBOX_CHAN_MAX); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c index 7b6ef033e77a9f..54684e9019699a 100644 --- a/drivers/mailbox/mailbox-test.c +++ b/drivers/mailbox/mailbox-test.c @@ -333,7 +333,7 @@ mbox_test_request_channel(struct platform_device *pdev, const char *name) struct mbox_client *client; struct mbox_chan *channel; - client = devm_kzalloc(&pdev->dev, sizeof(*client), GFP_KERNEL); + client = devm_kzalloc_obj(&pdev->dev, *client); if (!client) return NULL; @@ -377,7 +377,7 @@ static int mbox_test_probe(struct platform_device *pdev) struct mbox_test_device *tdev; int ret; - tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL); + tdev = devm_kzalloc_obj(&pdev->dev, *tdev); if (!tdev) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-th1520.c b/drivers/mailbox/mailbox-th1520.c index 626957c2e435cd..f908b2c0a54b8b 100644 --- a/drivers/mailbox/mailbox-th1520.c +++ b/drivers/mailbox/mailbox-th1520.c @@ -336,7 +336,7 @@ static const struct mbox_chan_ops th1520_mbox_ops = { static int th1520_mbox_init_generic(struct th1520_mbox_priv *priv) { #ifdef CONFIG_PM_SLEEP - priv->ctx = devm_kzalloc(priv->dev, sizeof(*priv->ctx), GFP_KERNEL); + priv->ctx = devm_kzalloc_obj(priv->dev, *priv->ctx); if (!priv->ctx) return -ENOMEM; #endif @@ -410,7 +410,7 @@ static int th1520_mbox_probe(struct platform_device *pdev) unsigned int i; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mailbox/mailbox-xgene-slimpro.c b/drivers/mailbox/mailbox-xgene-slimpro.c index 1f87a84e599568..6857e043eaf523 100644 --- a/drivers/mailbox/mailbox-xgene-slimpro.c +++ b/drivers/mailbox/mailbox-xgene-slimpro.c @@ -174,7 +174,7 @@ static int slimpro_mbox_probe(struct platform_device *pdev) int rc; int i; - ctx = devm_kzalloc(&pdev->dev, sizeof(struct slimpro_mbox), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, struct slimpro_mbox); if (!ctx) return -ENOMEM; diff --git a/drivers/mailbox/mtk-adsp-mailbox.c b/drivers/mailbox/mtk-adsp-mailbox.c index 8bcecddee0eb5c..08f78c435915fa 100644 --- a/drivers/mailbox/mtk-adsp-mailbox.c +++ b/drivers/mailbox/mtk-adsp-mailbox.c @@ -116,7 +116,7 @@ static int mtk_adsp_mbox_probe(struct platform_device *pdev) struct mbox_controller *mbox; int ret, irq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -127,7 +127,7 @@ static int mtk_adsp_mbox_probe(struct platform_device *pdev) mbox->txdone_poll = true; mbox->of_xlate = mtk_adsp_mbox_xlate; mbox->num_chans = 1; - mbox->chans = devm_kzalloc(dev, sizeof(*mbox->chans), GFP_KERNEL); + mbox->chans = devm_kzalloc_obj(dev, *mbox->chans); if (!mbox->chans) return -ENOMEM; diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index 96462ca844715c..405d2918d6cd1d 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -140,7 +140,7 @@ static void cmdq_vm_init(struct cmdq *cmdq) if (!cmdq->pdata->gce_vm) return; - vm_map = kcalloc(cmdq->pdata->thread_nr, sizeof(*vm_map), GFP_KERNEL); + vm_map = kzalloc_objs(*vm_map, cmdq->pdata->thread_nr); if (!vm_map) return; @@ -644,8 +644,8 @@ static int cmdq_get_clocks(struct device *dev, struct cmdq *cmdq) struct device_node *parent = dev->of_node->parent; struct clk_bulk_data *clks; - cmdq->clocks = devm_kcalloc(dev, cmdq->pdata->gce_num, - sizeof(*cmdq->clocks), GFP_KERNEL); + cmdq->clocks = devm_kzalloc_objs(dev, *cmdq->clocks, + cmdq->pdata->gce_num); if (!cmdq->clocks) return -ENOMEM; @@ -693,7 +693,7 @@ static int cmdq_probe(struct platform_device *pdev) struct cmdq *cmdq; int err, i; - cmdq = devm_kzalloc(dev, sizeof(*cmdq), GFP_KERNEL); + cmdq = devm_kzalloc_obj(dev, *cmdq); if (!cmdq) return -ENOMEM; @@ -724,8 +724,8 @@ static int cmdq_probe(struct platform_device *pdev) DMA_BIT_MASK(sizeof(u32) * BITS_PER_BYTE + cmdq->pdata->shift)); cmdq->mbox.dev = dev; - cmdq->mbox.chans = devm_kcalloc(dev, cmdq->pdata->thread_nr, - sizeof(*cmdq->mbox.chans), GFP_KERNEL); + cmdq->mbox.chans = devm_kzalloc_objs(dev, *cmdq->mbox.chans, + cmdq->pdata->thread_nr); if (!cmdq->mbox.chans) return -ENOMEM; @@ -737,8 +737,8 @@ static int cmdq_probe(struct platform_device *pdev) cmdq->mbox.txdone_irq = false; cmdq->mbox.txdone_poll = false; - cmdq->thread = devm_kcalloc(dev, cmdq->pdata->thread_nr, - sizeof(*cmdq->thread), GFP_KERNEL); + cmdq->thread = devm_kzalloc_objs(dev, *cmdq->thread, + cmdq->pdata->thread_nr); if (!cmdq->thread) return -ENOMEM; diff --git a/drivers/mailbox/mtk-gpueb-mailbox.c b/drivers/mailbox/mtk-gpueb-mailbox.c index f6d2beccd91b17..cb5d830f760a41 100644 --- a/drivers/mailbox/mtk-gpueb-mailbox.c +++ b/drivers/mailbox/mtk-gpueb-mailbox.c @@ -213,7 +213,7 @@ static int mtk_gpueb_mbox_probe(struct platform_device *pdev) struct mtk_gpueb_mbox *ebm; unsigned int i; - ebm = devm_kzalloc(&pdev->dev, sizeof(*ebm), GFP_KERNEL); + ebm = devm_kzalloc_obj(&pdev->dev, *ebm); if (!ebm) return -ENOMEM; @@ -240,13 +240,12 @@ static int mtk_gpueb_mbox_probe(struct platform_device *pdev) ebm->dev, PTR_ERR(ebm->mbox_ctl), "Couldn't map mailbox control registers\n"); - ebm->ch = devm_kmalloc_array(ebm->dev, ebm->v->num_channels, - sizeof(*ebm->ch), GFP_KERNEL); + ebm->ch = devm_kmalloc_objs(ebm->dev, *ebm->ch, ebm->v->num_channels); if (!ebm->ch) return -ENOMEM; - ebm->mbox.chans = devm_kcalloc(ebm->dev, ebm->v->num_channels, - sizeof(struct mbox_chan), GFP_KERNEL); + ebm->mbox.chans = devm_kzalloc_objs(ebm->dev, struct mbox_chan, + ebm->v->num_channels); if (!ebm->mbox.chans) return -ENOMEM; diff --git a/drivers/mailbox/mtk-vcp-mailbox.c b/drivers/mailbox/mtk-vcp-mailbox.c index 1b291b8ea15ac0..fa1f7117393b9e 100644 --- a/drivers/mailbox/mtk-vcp-mailbox.c +++ b/drivers/mailbox/mtk-vcp-mailbox.c @@ -102,7 +102,7 @@ static int mtk_vcp_mbox_probe(struct platform_device *pdev) struct mbox_controller *mbox; int ret, irq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mailbox/omap-mailbox.c b/drivers/mailbox/omap-mailbox.c index 535ca8020877d2..7a8e19f7e104c2 100644 --- a/drivers/mailbox/omap-mailbox.c +++ b/drivers/mailbox/omap-mailbox.c @@ -475,7 +475,7 @@ static int omap_mbox_probe(struct platform_device *pdev) return -ENODEV; } - mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL); + mdev = devm_kzalloc_obj(&pdev->dev, *mdev); if (!mdev) return -ENOMEM; @@ -489,13 +489,11 @@ static int omap_mbox_probe(struct platform_device *pdev) if (IS_ERR(mdev->mbox_base)) return PTR_ERR(mdev->mbox_base); - mdev->irq_ctx = devm_kcalloc(&pdev->dev, num_users, sizeof(u32), - GFP_KERNEL); + mdev->irq_ctx = devm_kzalloc_objs(&pdev->dev, u32, num_users); if (!mdev->irq_ctx) return -ENOMEM; - chnls = devm_kcalloc(&pdev->dev, info_count + 1, sizeof(*chnls), - GFP_KERNEL); + chnls = devm_kzalloc_objs(&pdev->dev, *chnls, info_count + 1); if (!chnls) return -ENOMEM; @@ -504,7 +502,7 @@ static int omap_mbox_probe(struct platform_device *pdev) int tx_id, tx_irq, tx_usr; int rx_id, rx_usr; - mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(&pdev->dev, *mbox); if (!mbox) return -ENOMEM; @@ -563,7 +561,7 @@ static int omap_mbox_probe(struct platform_device *pdev) mdev->num_fifos = num_fifos; mdev->intr_type = intr_type; - controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); + controller = devm_kzalloc_obj(&pdev->dev, *controller); if (!controller) return -ENOMEM; /* diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 14dc4a187bfc67..cd51d8e9c6659b 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -828,20 +828,19 @@ static int pcc_mbox_probe(struct platform_device *pdev) if (ACPI_FAILURE(status) || !pcct_tbl) return -ENODEV; - pcc_mbox_channels = devm_kcalloc(dev, count, sizeof(*pcc_mbox_channels), - GFP_KERNEL); + pcc_mbox_channels = devm_kzalloc_objs(dev, *pcc_mbox_channels, count); if (!pcc_mbox_channels) { rc = -ENOMEM; goto err; } - chan_info = devm_kcalloc(dev, count, sizeof(*chan_info), GFP_KERNEL); + chan_info = devm_kzalloc_objs(dev, *chan_info, count); if (!chan_info) { rc = -ENOMEM; goto err; } - pcc_mbox_ctrl = devm_kzalloc(dev, sizeof(*pcc_mbox_ctrl), GFP_KERNEL); + pcc_mbox_ctrl = devm_kzalloc_obj(dev, *pcc_mbox_ctrl); if (!pcc_mbox_ctrl) { rc = -ENOMEM; goto err; diff --git a/drivers/mailbox/platform_mhu.c b/drivers/mailbox/platform_mhu.c index 176ce290b8a8cc..792d47a6186e78 100644 --- a/drivers/mailbox/platform_mhu.c +++ b/drivers/mailbox/platform_mhu.c @@ -122,7 +122,7 @@ static int platform_mhu_probe(struct platform_device *pdev) }; /* Allocate memory for device */ - mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); + mhu = devm_kzalloc_obj(dev, *mhu); if (!mhu) return -ENOMEM; diff --git a/drivers/mailbox/qcom-apcs-ipc-mailbox.c b/drivers/mailbox/qcom-apcs-ipc-mailbox.c index d3a8f6b4a03b36..1a42b4712ba5c7 100644 --- a/drivers/mailbox/qcom-apcs-ipc-mailbox.c +++ b/drivers/mailbox/qcom-apcs-ipc-mailbox.c @@ -82,7 +82,7 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev) unsigned long i; int ret; - apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL); + apcs = devm_kzalloc_obj(&pdev->dev, *apcs); if (!apcs) return -ENOMEM; diff --git a/drivers/mailbox/qcom-cpucp-mbox.c b/drivers/mailbox/qcom-cpucp-mbox.c index b88ea2527265a0..37228a57af53eb 100644 --- a/drivers/mailbox/qcom-cpucp-mbox.c +++ b/drivers/mailbox/qcom-cpucp-mbox.c @@ -148,11 +148,11 @@ static int qcom_cpucp_mbox_probe(struct platform_device *pdev) if (!data) return dev_err_probe(dev, -EINVAL, "No match data found\n"); - cpucp = devm_kzalloc(dev, sizeof(*cpucp), GFP_KERNEL); + cpucp = devm_kzalloc_obj(dev, *cpucp); if (!cpucp) return -ENOMEM; - cpucp->chans = devm_kcalloc(dev, data->num_chans, sizeof(*cpucp->chans), GFP_KERNEL); + cpucp->chans = devm_kzalloc_objs(dev, *cpucp->chans, data->num_chans); if (!cpucp->chans) return -ENOMEM; diff --git a/drivers/mailbox/qcom-ipcc.c b/drivers/mailbox/qcom-ipcc.c index bb54295e03ced8..d986d4500026e7 100644 --- a/drivers/mailbox/qcom-ipcc.c +++ b/drivers/mailbox/qcom-ipcc.c @@ -201,7 +201,7 @@ static struct mbox_chan *qcom_ipcc_mbox_xlate(struct mbox_controller *mbox, chan = free_chan; - mchan = devm_kzalloc(dev, sizeof(*mchan), GFP_KERNEL); + mchan = devm_kzalloc_obj(dev, *mchan); if (!mchan) return ERR_PTR(-ENOMEM); @@ -249,8 +249,7 @@ static int qcom_ipcc_setup_mbox(struct qcom_ipcc *ipcc, if (!ipcc->num_chans) return 0; - ipcc->chans = devm_kcalloc(dev, ipcc->num_chans, - sizeof(struct mbox_chan), GFP_KERNEL); + ipcc->chans = devm_kzalloc_objs(dev, struct mbox_chan, ipcc->num_chans); if (!ipcc->chans) return -ENOMEM; @@ -290,7 +289,7 @@ static int qcom_ipcc_probe(struct platform_device *pdev) u32 config_value; int ret; - ipcc = devm_kzalloc(&pdev->dev, sizeof(*ipcc), GFP_KERNEL); + ipcc = devm_kzalloc_obj(&pdev->dev, *ipcc); if (!ipcc) return -ENOMEM; diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c index 4ebce35a8b6c0a..2134ceea1044e4 100644 --- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c +++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c @@ -791,8 +791,8 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox) return dev_err_probe(mbox->dev, rc, "failed to get MPXY channel IDs\n"); /* Populate all channels */ - mbox->channels = devm_kcalloc(mbox->dev, mbox->channel_count, - sizeof(*mbox->channels), GFP_KERNEL); + mbox->channels = devm_kzalloc_objs(mbox->dev, *mbox->channels, + mbox->channel_count); if (!mbox->channels) return -ENOMEM; for (i = 0; i < mbox->channel_count; i++) { @@ -882,7 +882,7 @@ static int mpxy_mbox_probe(struct platform_device *pdev) mpxy_shmem_init_done = true; /* Allocate mailbox instance */ - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; mbox->dev = dev; @@ -900,9 +900,8 @@ static int mpxy_mbox_probe(struct platform_device *pdev) mbox->controller.dev = dev; mbox->controller.num_chans = mbox->channel_count; mbox->controller.fw_xlate = mpxy_mbox_fw_xlate; - mbox->controller.chans = devm_kcalloc(dev, mbox->channel_count, - sizeof(*mbox->controller.chans), - GFP_KERNEL); + mbox->controller.chans = devm_kzalloc_objs(dev, *mbox->controller.chans, + mbox->channel_count); if (!mbox->controller.chans) return -ENOMEM; for (i = 0; i < mbox->channel_count; i++) @@ -939,9 +938,9 @@ static int mpxy_mbox_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - mbox->msi_index_to_channel = devm_kcalloc(dev, mbox->msi_count, - sizeof(*mbox->msi_index_to_channel), - GFP_KERNEL); + mbox->msi_index_to_channel = devm_kzalloc_objs(dev, + *mbox->msi_index_to_channel, + mbox->msi_count); if (!mbox->msi_index_to_channel) return -ENOMEM; diff --git a/drivers/mailbox/rockchip-mailbox.c b/drivers/mailbox/rockchip-mailbox.c index 790c34a22ec5b2..986f9dde5307cc 100644 --- a/drivers/mailbox/rockchip-mailbox.c +++ b/drivers/mailbox/rockchip-mailbox.c @@ -165,14 +165,13 @@ static int rockchip_mbox_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - mb = devm_kzalloc(&pdev->dev, - struct_size(mb, chans, ROCKCHIP_MAILBOX_NUM_CHANS), - GFP_KERNEL); + mb = devm_kzalloc_flex(&pdev->dev, *mb, chans, + ROCKCHIP_MAILBOX_NUM_CHANS); if (!mb) return -ENOMEM; - mb->mbox.chans = devm_kcalloc(&pdev->dev, ROCKCHIP_MAILBOX_NUM_CHANS, - sizeof(*mb->mbox.chans), GFP_KERNEL); + mb->mbox.chans = devm_kzalloc_objs(&pdev->dev, *mb->mbox.chans, + ROCKCHIP_MAILBOX_NUM_CHANS); if (!mb->mbox.chans) return -ENOMEM; diff --git a/drivers/mailbox/sprd-mailbox.c b/drivers/mailbox/sprd-mailbox.c index 9013d2ece55f73..95028472ae88a8 100644 --- a/drivers/mailbox/sprd-mailbox.c +++ b/drivers/mailbox/sprd-mailbox.c @@ -335,7 +335,7 @@ static int sprd_mbox_probe(struct platform_device *pdev) unsigned long id; struct clk *clk; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c index c6134de1a93b85..e88e198436a6e3 100644 --- a/drivers/mailbox/stm32-ipcc.c +++ b/drivers/mailbox/stm32-ipcc.c @@ -217,7 +217,7 @@ static int stm32_ipcc_probe(struct platform_device *pdev) return -ENODEV; } - ipcc = devm_kzalloc(dev, sizeof(*ipcc), GFP_KERNEL); + ipcc = devm_kzalloc_obj(dev, *ipcc); if (!ipcc) return -ENOMEM; @@ -292,9 +292,8 @@ static int stm32_ipcc_probe(struct platform_device *pdev) ipcc->controller.txdone_irq = true; ipcc->controller.ops = &stm32_ipcc_ops; ipcc->controller.num_chans = ipcc->n_chans; - ipcc->controller.chans = devm_kcalloc(dev, ipcc->controller.num_chans, - sizeof(*ipcc->controller.chans), - GFP_KERNEL); + ipcc->controller.chans = devm_kzalloc_objs(dev, *ipcc->controller.chans, + ipcc->controller.num_chans); if (!ipcc->controller.chans) { ret = -ENOMEM; goto err_irq_wkp; diff --git a/drivers/mailbox/sun6i-msgbox.c b/drivers/mailbox/sun6i-msgbox.c index 1cbc4d478beb3d..15d9efea11e79b 100644 --- a/drivers/mailbox/sun6i-msgbox.c +++ b/drivers/mailbox/sun6i-msgbox.c @@ -200,11 +200,11 @@ static int sun6i_msgbox_probe(struct platform_device *pdev) struct sun6i_msgbox *mbox; int i, ret; - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; - chans = devm_kcalloc(dev, NUM_CHANS, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, NUM_CHANS); if (!chans) return -ENOMEM; diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c index 03ee73aad488ba..1f6215c7e49880 100644 --- a/drivers/mailbox/tegra-hsp.c +++ b/drivers/mailbox/tegra-hsp.c @@ -280,7 +280,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, unsigned int offset; unsigned long flags; - db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); + db = devm_kzalloc_obj(hsp->dev, *db); if (!db) return ERR_PTR(-ENOMEM); @@ -677,8 +677,7 @@ static int tegra_hsp_add_mailboxes(struct tegra_hsp *hsp, struct device *dev) { int i; - hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), - GFP_KERNEL); + hsp->mailboxes = devm_kzalloc_objs(dev, *hsp->mailboxes, hsp->num_sm); if (!hsp->mailboxes) return -ENOMEM; @@ -736,7 +735,7 @@ static int tegra_hsp_probe(struct platform_device *pdev) u32 value; int err; - hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); + hsp = devm_kzalloc_obj(&pdev->dev, *hsp); if (!hsp) return -ENOMEM; @@ -763,9 +762,9 @@ static int tegra_hsp_probe(struct platform_device *pdev) if (hsp->num_si > 0) { unsigned int count = 0; - hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, - sizeof(*hsp->shared_irqs), - GFP_KERNEL); + hsp->shared_irqs = devm_kzalloc_objs(&pdev->dev, + *hsp->shared_irqs, + hsp->num_si); if (!hsp->shared_irqs) return -ENOMEM; @@ -797,9 +796,8 @@ static int tegra_hsp_probe(struct platform_device *pdev) hsp->mbox_db.dev = &pdev->dev; hsp->mbox_db.ops = &tegra_hsp_db_ops; - hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, - sizeof(*hsp->mbox_db.chans), - GFP_KERNEL); + hsp->mbox_db.chans = devm_kzalloc_objs(&pdev->dev, *hsp->mbox_db.chans, + hsp->mbox_db.num_chans); if (!hsp->mbox_db.chans) return -ENOMEM; @@ -825,9 +823,8 @@ static int tegra_hsp_probe(struct platform_device *pdev) hsp->mbox_sm.dev = &pdev->dev; hsp->mbox_sm.ops = &tegra_hsp_sm_ops; - hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, - sizeof(*hsp->mbox_sm.chans), - GFP_KERNEL); + hsp->mbox_sm.chans = devm_kzalloc_objs(&pdev->dev, *hsp->mbox_sm.chans, + hsp->mbox_sm.num_chans); if (!hsp->mbox_sm.chans) return -ENOMEM; diff --git a/drivers/mailbox/ti-msgmgr.c b/drivers/mailbox/ti-msgmgr.c index 2079996092f50d..7bca2aa049b1be 100644 --- a/drivers/mailbox/ti-msgmgr.c +++ b/drivers/mailbox/ti-msgmgr.c @@ -864,7 +864,7 @@ static int ti_msgmgr_probe(struct platform_device *pdev) } np = dev->of_node; - inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL); + inst = devm_kzalloc_obj(dev, *inst); if (!inst) return -ENOMEM; @@ -899,12 +899,12 @@ static int ti_msgmgr_probe(struct platform_device *pdev) } inst->num_valid_queues = queue_count; - qinst = devm_kcalloc(dev, queue_count, sizeof(*qinst), GFP_KERNEL); + qinst = devm_kzalloc_objs(dev, *qinst, queue_count); if (!qinst) return -ENOMEM; inst->qinsts = qinst; - chans = devm_kcalloc(dev, queue_count, sizeof(*chans), GFP_KERNEL); + chans = devm_kzalloc_objs(dev, *chans, queue_count); if (!chans) return -ENOMEM; inst->chans = chans; diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c index 42d2583e44ca7f..2b81bedf0653cb 100644 --- a/drivers/mailbox/zynqmp-ipi-mailbox.c +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c @@ -917,8 +917,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev) return -EINVAL; } - pdata = devm_kzalloc(dev, struct_size(pdata, ipi_mboxes, num_mboxes), - GFP_KERNEL); + pdata = devm_kzalloc_flex(dev, *pdata, ipi_mboxes, num_mboxes); if (!pdata) return -ENOMEM; pdata->dev = dev; diff --git a/drivers/mcb/mcb-lpc.c b/drivers/mcb/mcb-lpc.c index 070aa787abc606..cf9a31e7d21596 100644 --- a/drivers/mcb/mcb-lpc.c +++ b/drivers/mcb/mcb-lpc.c @@ -25,7 +25,7 @@ static int mcb_lpc_probe(struct platform_device *pdev) struct priv *priv; int ret = 0, table_size; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c index f1353da6ef4fc4..adb91878e4346b 100644 --- a/drivers/mcb/mcb-pci.c +++ b/drivers/mcb/mcb-pci.c @@ -34,7 +34,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) int ret, table_size; unsigned long flags; - priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct priv); if (!priv) return -ENOMEM; diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index 179b76173255b7..461044dca367a7 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c @@ -766,6 +766,7 @@ static struct dm_cache_metadata *metadata_open(struct block_device *bdev, return ERR_PTR(-ENOMEM); } + INIT_LIST_HEAD(&cmd->list); cmd->version = metadata_version; refcount_set(&cmd->ref_count, 1); init_rwsem(&cmd->root_lock); @@ -1432,7 +1433,8 @@ static int __load_mappings(struct dm_cache_metadata *cmd, from_cblock(cmd->cache_blocks), &cmd->dirty_cursor); if (r) { - dm_array_cursor_end(&cmd->hint_cursor); + if (hints_valid) + dm_array_cursor_end(&cmd->hint_cursor); dm_array_cursor_end(&cmd->mapping_cursor); return r; } diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index 1a5072425c4a1b..850c4b651f09fb 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -2383,9 +2384,7 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca, static bool too_many_discard_blocks(sector_t discard_block_size, sector_t origin_size) { - (void) sector_div(origin_size, discard_block_size); - - return origin_size > MAX_DISCARD_BLOCKS; + return div64_u64(origin_size, discard_block_size) > MAX_DISCARD_BLOCKS; } static sector_t calculate_discard_block_size(sector_t cache_block_size, @@ -2422,6 +2421,7 @@ static int cache_create(struct cache_args *ca, struct cache **result) struct cache *cache; struct dm_target *ti = ca->ti; dm_block_t origin_blocks; + sector_t discard_block_size; struct dm_cache_metadata *cmd; bool may_format = ca->features.mode == CM_WRITE; @@ -2521,9 +2521,15 @@ static int cache_create(struct cache_args *ca, struct cache **result) } clear_bitset(cache->dirty_bitset, from_cblock(cache->cache_size)); - cache->discard_block_size = + discard_block_size = calculate_discard_block_size(cache->sectors_per_block, cache->origin_sectors); + if (discard_block_size > U32_MAX) { + *error = "Discard block size exceeds 32 bits"; + r = -EOVERFLOW; + goto bad; + } + cache->discard_block_size = discard_block_size; cache->discard_nr_blocks = to_dblock(dm_sector_div_up(cache->origin_sectors, cache->discard_block_size)); cache->discard_bitset = alloc_bitset(from_dblock(cache->discard_nr_blocks)); @@ -2544,6 +2550,7 @@ static int cache_create(struct cache_args *ca, struct cache **result) if (IS_ERR(cache->copier)) { *error = "could not create kcopyd client"; r = PTR_ERR(cache->copier); + cache->copier = NULL; goto bad; } @@ -2610,7 +2617,7 @@ static int copy_ctr_args(struct cache *cache, int argc, const char **argv) unsigned int i; const char **copy; - copy = kcalloc(argc, sizeof(*copy), GFP_KERNEL); + copy = kzalloc_objs(*copy, argc); if (!copy) return -ENOMEM; for (i = 0; i < argc; i++) { diff --git a/drivers/md/dm-clone-target.c b/drivers/md/dm-clone-target.c index c0f9b93983d4ed..bc4a5ce4c81af6 100644 --- a/drivers/md/dm-clone-target.c +++ b/drivers/md/dm-clone-target.c @@ -1727,7 +1727,7 @@ static int copy_ctr_args(struct clone *clone, int argc, const char **argv, char unsigned int i; const char **copy; - copy = kcalloc(argc, sizeof(*copy), GFP_KERNEL); + copy = kzalloc_objs(*copy, argc); if (!copy) goto error; diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index a7655bba7ce3d1..02038a9cd21da5 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -1982,8 +1982,9 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async) /* crypt_convert should have filled the clone bio */ BUG_ON(io->ctx.iter_out.bi_size); - if ((likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) || - test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) { + if (likely(!async) && + (test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags) || + test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags))) { dm_submit_bio_remap(io->base_bio, clone); return; } @@ -2847,8 +2848,11 @@ static int crypt_ctr_auth_cipher(struct crypt_config *cc, char *cipher_api) char *start, *end, *mac_alg = NULL; struct crypto_ahash *mac; - if (!strstarts(cipher_api, "authenc(")) + if (!strstarts(cipher_api, "authenc(")) { + if (test_bit(CRYPT_KEY_MAC_SIZE_SET, &cc->cipher_flags)) + return -EINVAL; return 0; + } start = strchr(cipher_api, '('); end = strchr(cipher_api, ','); @@ -3229,6 +3233,14 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error = "Cannot allocate encryption context"; return -ENOMEM; } + + ret = percpu_counter_init(&cc->n_allocated_pages, 0, GFP_KERNEL); + if (ret < 0) { + ti->error = "Cannot initialize page counter"; + kfree_sensitive(cc); + return ret; + } + cc->key_size = key_size; cc->sector_size = (1 << SECTOR_SHIFT); cc->sector_shift = 0; @@ -3240,10 +3252,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) crypt_calculate_pages_per_client(); spin_unlock(&dm_crypt_clients_lock); - ret = percpu_counter_init(&cc->n_allocated_pages, 0, GFP_KERNEL); - if (ret < 0) - goto bad; - /* Optional parameters need to be read before cipher constructor */ if (argc > 5) { ret = crypt_ctr_optional(ti, argc - 5, &argv[5]); diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 802b377613b06b..6968e38888db9b 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -2908,6 +2908,11 @@ static void integrity_commit(struct work_struct *w) spin_lock_irq(&ic->endio_wait.lock); flushes = bio_list_get(&ic->flush_bio_list); + if (unlikely(dm_integrity_failed(ic))) { + wake_up_locked(&ic->endio_wait); + spin_unlock_irq(&ic->endio_wait.lock); + goto release_flush_bios; + } if (unlikely(ic->mode != 'J')) { spin_unlock_irq(&ic->endio_wait.lock); dm_integrity_flush_buffers(ic, true); @@ -3888,6 +3893,24 @@ static bool superblock_changed(struct dm_integrity_c *ic) memcmp(ic->sb->salt, ic->sb_copy->salt, SALT_SIZE) != 0; } +/* + * The superblock is authenticated only if fix_hmac and journal_mac are used, + * so SB_FLAG_DIRTY_BITMAP may have been set by someone who doesn't know the + * key. Apply the policy that the constructor applies to SB_FLAG_RECALCULATING. + */ +static bool dm_integrity_may_recalc_dirty_bitmap(struct dm_integrity_c *ic) +{ + if (!ic->internal_hash) { + DMERR("Dirty bitmap found, but internal_hash is not used"); + return false; + } + if (dm_integrity_disable_recalculate(ic)) { + DMERR("Dirty bitmap found, but HMAC recalculation requires \"legacy_recalculate\""); + return false; + } + return true; +} + static void dm_integrity_resume(struct dm_target *ti) { struct dm_integrity_c *ic = ti->private; @@ -3977,8 +4000,10 @@ static void dm_integrity_resume(struct dm_target *ti) if (!(ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR)) || ic->reset_recalculate_flag) { - ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); - ic->sb->recalc_sector = cpu_to_le64(0); + if (dm_integrity_may_recalc_dirty_bitmap(ic)) { + ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); + ic->sb->recalc_sector = cpu_to_le64(0); + } } init_journal(ic, 0, ic->journal_sections, 0); replay_journal(ic); @@ -5409,7 +5434,6 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv r = create_journal(ic, &ti->error); if (r) goto bad; - } if (ic->mode == 'B') { diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 8f945f0aeda5d6..4a7cb0926c178a 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1794,7 +1794,7 @@ static void retrieve_deps(struct dm_table *table, deps->count = count; count = 0; list_for_each_entry(dd, dm_table_get_devices(table), list) - deps->dev[count++] = huge_encode_dev(dd->dm_dev->bdev->bd_dev); + deps->dev[count++] = huge_encode_dev(dd->bdev->bd_dev); param->data_size = param->data_start + needed; } diff --git a/drivers/md/dm-log-userspace-base.c b/drivers/md/dm-log-userspace-base.c index 3ca35aa4e057d1..48daa41728d647 100644 --- a/drivers/md/dm-log-userspace-base.c +++ b/drivers/md/dm-log-userspace-base.c @@ -294,9 +294,11 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti, } r = dm_get_device(ti, devices_rdata, dm_table_get_mode(ti->table), &lc->log_dev); - if (r) + if (r) { DMERR("Failed to register %s with device-mapper", devices_rdata); + goto out; + } } if (lc->integrated_flush) { @@ -315,6 +317,8 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti, out: kfree(devices_rdata); if (r) { + if (lc->log_dev) + dm_put_device(lc->ti, lc->log_dev); mempool_exit(&lc->flush_entry_pool); kfree(lc); kfree(ctr_str); diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index ae9318f5f21b7c..d2e94b96d2e44e 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -797,7 +797,8 @@ static void queue_if_no_path_timeout_work(struct timer_list *t) static void enable_nopath_timeout(struct multipath *m) { unsigned long queue_if_no_path_timeout = - READ_ONCE(queue_if_no_path_timeout_secs) * HZ; + min_t(unsigned long, READ_ONCE(queue_if_no_path_timeout_secs), + MAX_JIFFY_OFFSET / HZ) * HZ; lockdep_assert_held(&m->lock); @@ -1085,8 +1086,9 @@ static int parse_hw_handler(struct dm_arg_set *as, struct multipath *m) if (hw_argc > 1) { char *p; - int i, j, len = 4; + int i, j, len; + len = snprintf(NULL, 0, "%d", hw_argc - 1) + 1; for (i = 0; i <= hw_argc - 2; i++) len += strlen(as->argv[i]) + 1; p = m->hw_handler_params = kzalloc(len, GFP_KERNEL); diff --git a/drivers/md/dm-pcache/backing_dev.c b/drivers/md/dm-pcache/backing_dev.c index 23002beb192aee..84b4e76367fabc 100644 --- a/drivers/md/dm-pcache/backing_dev.c +++ b/drivers/md/dm-pcache/backing_dev.c @@ -336,9 +336,9 @@ struct pcache_backing_dev_req *backing_dev_req_create(struct pcache_backing_dev return backing_req; } -void backing_dev_flush(struct pcache_backing_dev *backing_dev) +int backing_dev_flush(struct pcache_backing_dev *backing_dev) { - blkdev_issue_flush(backing_dev->dm_dev->bdev); + return blkdev_issue_flush(backing_dev->dm_dev->bdev); } int pcache_backing_init(void) diff --git a/drivers/md/dm-pcache/backing_dev.h b/drivers/md/dm-pcache/backing_dev.h index b371cba483b9aa..8422e5e76e2905 100644 --- a/drivers/md/dm-pcache/backing_dev.h +++ b/drivers/md/dm-pcache/backing_dev.h @@ -120,7 +120,7 @@ struct pcache_backing_dev_req *backing_dev_req_alloc(struct pcache_backing_dev * struct pcache_backing_dev_req_opts *opts); void backing_dev_req_init(struct pcache_backing_dev_req *backing_req, struct pcache_backing_dev_req_opts *opts); -void backing_dev_flush(struct pcache_backing_dev *backing_dev); +int backing_dev_flush(struct pcache_backing_dev *backing_dev); int pcache_backing_init(void); void pcache_backing_exit(void); diff --git a/drivers/md/dm-pcache/cache.c b/drivers/md/dm-pcache/cache.c index b0b3e21677deeb..f83f4e528dcb77 100644 --- a/drivers/md/dm-pcache/cache.c +++ b/drivers/md/dm-pcache/cache.c @@ -152,7 +152,8 @@ static int cache_init(struct dm_pcache *pcache) goto err; } - cache->seg_map = kvcalloc(BITS_TO_LONGS(cache_dev->seg_num), sizeof(unsigned long), GFP_KERNEL); + cache->seg_map = kvzalloc_objs(unsigned long, + BITS_TO_LONGS(cache_dev->seg_num)); if (!cache->seg_map) { ret = -ENOMEM; goto free_segments; diff --git a/drivers/md/dm-pcache/cache_dev.c b/drivers/md/dm-pcache/cache_dev.c index f0259353ee3978..4c65a809286a33 100644 --- a/drivers/md/dm-pcache/cache_dev.c +++ b/drivers/md/dm-pcache/cache_dev.c @@ -217,7 +217,8 @@ static int sb_validate(struct pcache_cache_dev *cache_dev, struct pcache_sb *sb) static int cache_dev_init(struct pcache_cache_dev *cache_dev, u32 seg_num) { cache_dev->seg_num = seg_num; - cache_dev->seg_bitmap = kvcalloc(BITS_TO_LONGS(cache_dev->seg_num), sizeof(unsigned long), GFP_KERNEL); + cache_dev->seg_bitmap = kvzalloc_objs(unsigned long, + BITS_TO_LONGS(cache_dev->seg_num)); if (!cache_dev->seg_bitmap) return -ENOMEM; diff --git a/drivers/md/dm-pcache/cache_writeback.c b/drivers/md/dm-pcache/cache_writeback.c index c8a4c8110a581c..e09560f172dd7e 100644 --- a/drivers/md/dm-pcache/cache_writeback.c +++ b/drivers/md/dm-pcache/cache_writeback.c @@ -18,12 +18,18 @@ static void writeback_ctx_end(struct pcache_cache *cache, int ret) return; if (!cache->writeback_ctx.ret) { - backing_dev_flush(cache->backing_dev); - - mutex_lock(&cache->dirty_tail_lock); - cache_pos_advance(&cache->dirty_tail, cache->writeback_ctx.advance); - cache_encode_dirty_tail(cache); - mutex_unlock(&cache->dirty_tail_lock); + ret = backing_dev_flush(cache->backing_dev); + if (ret) { + pcache_dev_err(CACHE_TO_PCACHE(cache), + "failed to flush backing device: %d", ret); + cache->writeback_ctx.ret = ret; + } else { + mutex_lock(&cache->dirty_tail_lock); + cache_pos_advance(&cache->dirty_tail, + cache->writeback_ctx.advance); + cache_encode_dirty_tail(cache); + mutex_unlock(&cache->dirty_tail_lock); + } } queue_delayed_work(cache_get_wq(cache), &cache->writeback_work, 0); } @@ -76,8 +82,16 @@ static inline bool is_cache_clean(struct pcache_cache *cache, struct pcache_cach void cache_writeback_exit(struct pcache_cache *cache) { + int ret; + cancel_delayed_work_sync(&cache->writeback_work); - backing_dev_flush(cache->backing_dev); + + ret = backing_dev_flush(cache->backing_dev); + if (ret) + pcache_dev_err(CACHE_TO_PCACHE(cache), + "failed to flush backing device during exit: %d", + ret); + cache_tree_exit(&cache->writeback_key_tree); } diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index ac019a0f5a929e..e44d92462affc2 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -2420,7 +2420,8 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev) */ if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { role = le32_to_cpu(sb2->array_position); - if (role < 0) + /* Bound @role before it indexes the failed_devices stack bitmap. */ + if (role < 0 || role >= rs->raid_disks) continue; if (role != r->raid_disk) { @@ -3333,7 +3334,7 @@ static void raid_dtr(struct dm_target *ti) rs->md.dm_gendisk = NULL; mddev_unlock(&rs->md); - if (work_pending(&rs->md.event_work)) + if (rs->md.event_work.func) flush_work(&rs->md.event_work); raid_set_free(rs); } diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 797c432594d864..6968e806eb84db 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -1358,8 +1358,10 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->private = s; ti->num_flush_bios = num_flush_bios; - if (s->discard_zeroes_cow) + if (s->discard_zeroes_cow) { ti->num_discard_bios = (s->discard_passdown_origin ? 2 : 1); + ti->max_discard_granularity = true; + } ti->per_io_data_size = sizeof(struct dm_snap_tracked_chunk); /* Add snapshot to the list of snapshots for this origin */ @@ -1946,8 +1948,8 @@ static void zero_exception(struct dm_snapshot *s, struct dm_exception *e, static bool io_overlaps_chunk(struct dm_snapshot *s, struct bio *bio) { - return bio->bi_iter.bi_size == - (s->store->chunk_size << SECTOR_SHIFT); + return bio->bi_iter.bi_size == (s->store->chunk_size << SECTOR_SHIFT) && + !(bio->bi_iter.bi_sector & s->store->chunk_mask); } static int snapshot_map(struct dm_target *ti, struct bio *bio) @@ -2007,11 +2009,13 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio) e = dm_lookup_exception(&s->complete, chunk); if (e) { remap_exception(s, e, bio, chunk); - if (unlikely(bio_op(bio) == REQ_OP_DISCARD) && - io_overlaps_chunk(s, bio)) { + if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) { dm_exception_table_unlock(&lock); up_read(&s->lock); - zero_exception(s, e, bio, chunk); + if (io_overlaps_chunk(s, bio)) + zero_exception(s, e, bio, chunk); + else + bio_endio(bio); r = DM_MAPIO_SUBMITTED; /* discard is not issued */ goto out; } @@ -2414,7 +2418,7 @@ static void snapshot_io_hints(struct dm_target *ti, struct queue_limits *limits) snap = snap_src; /* All discards are split on chunk_size boundary */ - limits->discard_granularity = snap->store->chunk_size; + limits->discard_granularity = snap->store->chunk_size << SECTOR_SHIFT; limits->max_hw_discard_sectors = snap->store->chunk_size; up_read(&_origins_lock); diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c index 22bc70923a8392..c9f81231df7b13 100644 --- a/drivers/md/dm-sysfs.c +++ b/drivers/md/dm-sysfs.c @@ -128,9 +128,20 @@ static const struct kobj_type dm_ktype = { */ int dm_sysfs_init(struct mapped_device *md) { - return kobject_init_and_add(dm_kobject(md), &dm_ktype, - &disk_to_dev(dm_disk(md))->kobj, - "%s", "dm"); + struct kobject *kobj = dm_kobject(md); + int r; + + /* The kobject must be zeroed before calling kobject_init */ + memset(kobj, 0, sizeof(struct kobject)); + r = kobject_init_and_add(kobj, &dm_ktype, + &disk_to_dev(dm_disk(md))->kobj, + "%s", "dm"); + if (unlikely(r)) { + /* Weird semantics - we must call kobject_put on failure */ + dm_sysfs_exit(md); + return r; + } + return 0; } /* diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index a483f49dd4ce63..48f25ab6b7fa67 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -165,14 +165,16 @@ int dm_table_create(struct dm_table **result, blk_mode_t mode, static void free_devices(struct list_head *devices, struct mapped_device *md) { - struct list_head *tmp, *next; - - list_for_each_safe(tmp, next, devices) { - struct dm_dev_internal *dd = - list_entry(tmp, struct dm_dev_internal, list); - DMWARN("%s: dm_table_destroy: dm_put_device call missing for %s", - dm_device_name(md), dd->dm_dev->name); - dm_put_table_device(md, dd->dm_dev); + struct dm_dev_internal *dd, *dd_next; + struct dm_dev_ref *ref, *ref_next; + + list_for_each_entry_safe(dd, dd_next, devices, list) { + list_for_each_entry_safe(ref, ref_next, &dd->refs, list) { + DMWARN("%s: dm_table_destroy: dm_put_device call missing for %s", + dm_device_name(md), ref->dm_dev->name); + dm_put_table_device(md, ref->dm_dev); + kfree(ref); + } kfree(dd); } } @@ -218,12 +220,27 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev) struct dm_dev_internal *dd; list_for_each_entry(dd, l, list) - if (dd->dm_dev->bdev->bd_dev == dev) + if (dd->bdev->bd_dev == dev) return dd; return NULL; } +/* + * See if the device is already open with a mode that covers the + * requested one. + */ +static struct dm_dev_ref *find_ref(struct dm_dev_internal *dd, blk_mode_t mode) +{ + struct dm_dev_ref *ref; + + list_for_each_entry(ref, &dd->refs, list) + if ((ref->dm_dev->mode & mode) == mode) + return ref; + + return NULL; +} + /* * If possible, this checks an area of a destination device is invalid. */ @@ -303,31 +320,6 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, return 0; } -/* - * This upgrades the mode on an already open dm_dev, being - * careful to leave things as they were if we fail to reopen the - * device and not to touch the existing bdev field in case - * it is accessed concurrently. - */ -static int upgrade_mode(struct dm_dev_internal *dd, blk_mode_t new_mode, - struct mapped_device *md) -{ - int r; - struct dm_dev *old_dev, *new_dev; - - old_dev = dd->dm_dev; - - r = dm_get_table_device(md, dd->dm_dev->bdev->bd_dev, - dd->dm_dev->mode | new_mode, &new_dev); - if (r) - return r; - - dd->dm_dev = new_dev; - dm_put_table_device(md, old_dev); - - return 0; -} - /* * Note: the __ref annotation is because this function can call the __init * marked early_lookup_bdev when called during early boot code from dm-init.c. @@ -360,7 +352,9 @@ EXPORT_SYMBOL(dm_devt_from_path); /* * Add a device to the list, or just increment the usage count if - * it's already present. + * it's already present with a mode that covers the requested one. + * Otherwise open the device again with the requested mode, so the + * dm_devs returned earlier stay valid. */ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, struct dm_dev **result) @@ -368,6 +362,7 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, int r; dev_t dev; struct dm_dev_internal *dd; + struct dm_dev_ref *ref; struct dm_table *t = ti->table; BUG_ON(!t); @@ -380,30 +375,46 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, return -EINVAL; dd = find_device(&t->devices, dev); - if (!dd) { + if (dd) { + ref = find_ref(dd, mode); + if (ref) { + refcount_inc(&ref->count); + goto out; + } + } else { dd = kmalloc_obj(*dd); if (!dd) return -ENOMEM; + INIT_LIST_HEAD(&dd->refs); + } - r = dm_get_table_device(t->md, dev, mode, &dd->dm_dev); - if (r) { - kfree(dd); - return r; - } + ref = kmalloc_obj(*ref); + if (!ref) { + r = -ENOMEM; + goto bad; + } - refcount_set(&dd->count, 1); - list_add(&dd->list, &t->devices); - goto out; + r = dm_get_table_device(t->md, dev, mode, &ref->dm_dev); + if (r) { + kfree(ref); + goto bad; + } + refcount_set(&ref->count, 1); - } else if (dd->dm_dev->mode != (mode | dd->dm_dev->mode)) { - r = upgrade_mode(dd, mode, t->md); - if (r) - return r; + /* A device in the list always has at least one ref */ + if (list_empty(&dd->refs)) { + dd->bdev = ref->dm_dev->bdev; + list_add(&dd->list, &t->devices); } - refcount_inc(&dd->count); + list_add_tail(&ref->list, &dd->refs); out: - *result = dd->dm_dev; + *result = ref->dm_dev; return 0; + +bad: + if (list_empty(&dd->refs)) + kfree(dd); + return r; } EXPORT_SYMBOL(dm_get_device); @@ -453,23 +464,28 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, */ void dm_put_device(struct dm_target *ti, struct dm_dev *d) { - int found = 0; struct list_head *devices = &ti->table->devices; struct dm_dev_internal *dd; + struct dm_dev_ref *ref; - list_for_each_entry(dd, devices, list) { - if (dd->dm_dev == d) { - found = 1; - break; - } - } - if (!found) { - DMERR("%s: device %s not in table devices list", - dm_device_name(ti->table->md), d->name); + list_for_each_entry(dd, devices, list) + list_for_each_entry(ref, &dd->refs, list) + if (ref->dm_dev == d) + goto found; + + DMERR("%s: device %s not in table devices list", + dm_device_name(ti->table->md), d->name); + return; + +found: + if (!refcount_dec_and_test(&ref->count)) return; - } - if (refcount_dec_and_test(&dd->count)) { - dm_put_table_device(ti->table->md, d); + + dm_put_table_device(ti->table->md, d); + list_del(&ref->list); + kfree(ref); + + if (list_empty(&dd->refs)) { list_del(&dd->list); kfree(dd); } @@ -513,7 +529,7 @@ static char **realloc_argv(unsigned int *size, char **old_argv) new_size = 8; gfp = GFP_NOIO; } - argv = kmalloc_array(new_size, sizeof(*argv), gfp); + argv = kmalloc_objs(*argv, new_size, gfp); if (argv) { if (old_argv) memcpy(argv, old_argv, *size * sizeof(*argv)); diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index e60e1326376a0b..03df0b1aab7801 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c @@ -1225,10 +1225,13 @@ static int __create_snap(struct dm_pool_metadata *pmd, __close_device(td); if (r) - goto bad; + goto bad2; return 0; +bad2: + list_del(&td->list); + kfree(td); bad: dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); dm_btree_remove(&pmd->details_info, pmd->details_root, diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index 358ed77ffb2bee..0b65c1b09f47b0 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -1703,6 +1703,7 @@ static void break_up_discard_bio(struct thin_c *tc, dm_block_t begin, dm_block_t (void) build_key(tc->td, PHYSICAL, data_begin, data_begin + len, &data_key); if (bio_detain(tc->pool, &data_key, NULL, &data_cell)) { /* contention, we'll give up with this range */ + virt_begin += len; data_begin += len; continue; } @@ -2542,7 +2543,9 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) struct pool_c *pt = pool->ti->private; bool needs_check = dm_pool_metadata_needs_check(pool->pmd); enum pool_mode old_mode = get_pool_mode(pool); - unsigned long no_space_timeout = READ_ONCE(no_space_timeout_secs) * HZ; + unsigned long no_space_timeout = + min_t(unsigned long, READ_ONCE(no_space_timeout_secs), + MAX_JIFFY_OFFSET / HZ) * HZ; /* * Never allow the pool to transition to PM_WRITE mode if user @@ -3146,7 +3149,7 @@ static int parse_pool_features(struct dm_arg_set *as, struct pool_features *pf, const char *arg_name; static const struct dm_arg _args[] = { - {0, 4, "Invalid number of pool feature arguments"}, + {0, 5, "Invalid number of pool feature arguments"}, }; /* diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 6d589867623c01..306ed1f6c11874 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -170,6 +170,15 @@ static void verity_hash_at_level(struct dm_verity *v, sector_t block, int level, *offset = idx << (v->hash_dev_block_bits - v->hash_per_block_bits); } +/* + * Skip verity work in response to I/O error when system is shutting down. + */ +static inline bool verity_is_system_shutting_down(void) +{ + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF + || system_state == SYSTEM_RESTART; +} + /* * Handle verification errors. */ @@ -219,6 +228,15 @@ static int verity_handle_err(struct dm_verity *v, enum verity_block_type type, if (v->mode == DM_VERITY_MODE_LOGGING) return 0; + /* + * Devices may already be quiesced (e.g. UFS set offline by its + * shutdown hook), so a failure here does not imply corruption. Fail + * the I/O but do not restart or panic, which would also override the + * reboot reason of the shutdown already in progress. + */ + if (verity_is_system_shutting_down()) + return 1; + if (v->mode == DM_VERITY_MODE_RESTART) kernel_restart("dm-verity device corrupted"); @@ -593,15 +611,6 @@ static int verity_verify_io(struct dm_verity_io *io) return r; } -/* - * Skip verity work in response to I/O error when system is shutting down. - */ -static inline bool verity_is_system_shutting_down(void) -{ - return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF - || system_state == SYSTEM_RESTART; -} - static void restart_io_error(struct work_struct *w) { kernel_restart("dm-verity device has I/O error"); @@ -1106,9 +1115,8 @@ static int verity_alloc_most_once(struct dm_verity *v) return -E2BIG; } - v->validated_blocks = kvcalloc(BITS_TO_LONGS(v->data_blocks), - sizeof(unsigned long), - GFP_KERNEL); + v->validated_blocks = kvzalloc_objs(unsigned long, + BITS_TO_LONGS(v->data_blocks)); if (!v->validated_blocks) { ti->error = "failed to allocate bitset for check_at_most_once"; return -ENOMEM; diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 35916c6e490e4e..9ddbb67e97e59f 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -33,6 +33,8 @@ static int dm_blk_do_report_zones(struct mapped_device *md, struct dm_table *t, nr_zones - args->zone_idx); if (ret < 0) return ret; + if (!ret) + return -EIO; } while (args->zone_idx < nr_zones && args->next_sector < get_capacity(md->disk)); diff --git a/drivers/md/dm-zoned-reclaim.c b/drivers/md/dm-zoned-reclaim.c index c041413c729efe..152cb8788114e4 100644 --- a/drivers/md/dm-zoned-reclaim.c +++ b/drivers/md/dm-zoned-reclaim.c @@ -288,7 +288,13 @@ static int dmz_reclaim_rnd_data(struct dmz_reclaim *zrc, struct dm_zone *dzone) again: szone = dmz_alloc_zone(zmd, zrc->dev_idx, alloc_flags | DMZ_ALLOC_RECLAIM); - if (!szone && alloc_flags == DMZ_ALLOC_SEQ && dmz_nr_cache_zones(zmd)) { + /* + * If no free sequential zone is available, a cache zone can still be + * moved into a free random zone of the zoned device, which frees cache + * space. Do not do this for a random zone: moving it into another + * random zone frees nothing and, on an idle target, repeats forever. + */ + if (!szone && alloc_flags == DMZ_ALLOC_SEQ && dmz_is_cache(dzone)) { alloc_flags = DMZ_ALLOC_RND; goto again; } @@ -537,6 +543,16 @@ static void dmz_reclaim_work(struct work_struct *work) dmz_nr_rnd_zones(zmd, zrc->dev_idx)); ret = dmz_do_reclaim(zrc); + if (ret == -ENOSPC || ret == -EBUSY) { + /* + * No zone to copy into (-ENOSPC) or no zone to reclaim + * (-EBUSY): retrying at once cannot make progress and would + * spin. Poll again after the idle period instead, without + * postponing work that an allocation has already queued. + */ + queue_delayed_work(zrc->wq, &zrc->work, DMZ_IDLE_PERIOD); + return; + } if (ret && ret != -EINTR) { if (!dmz_check_dev(zmd)) return; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 1881d86111fb2e..38eaae8ac9b47f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -983,7 +983,7 @@ static void __dm_io_complete(struct dm_io *io, bool first_stage) if (requeued) return; - if (unlikely(requeue_flush_with_data)) { + if (unlikely(requeue_flush_with_data) && !io_error) { /* * Preflush done for flush with data, reissue * without REQ_PREFLUSH. @@ -991,7 +991,7 @@ static void __dm_io_complete(struct dm_io *io, bool first_stage) bio->bi_opf &= ~REQ_PREFLUSH; queue_io(md, bio); } else { - /* done with normal IO or empty flush */ + /* done with normal IO, empty flush or failed preflush */ if (io_error) bio->bi_status = io_error; bio_endio(bio); @@ -1588,7 +1588,7 @@ static void __send_empty_flush(struct clone_info *ci) */ clone = alloc_tio(ci, NULL, 0, &len, GFP_NOIO); atomic_add(1, &ci->io->io_count); - bio_set_dev(clone, dd->dm_dev->bdev); + bio_set_dev(clone, dd->bdev); clone->bi_end_io = clone_endio; dm_submit_bio_remap(clone, NULL); } @@ -1929,8 +1929,13 @@ static blk_status_t __send_zone_reset_all(struct clone_info *ci) break; } - /* Release the reference that alloc_io() took for submission. */ - atomic_sub(1, &ci->io->io_count); + /* + * Release the reference that alloc_io() took for submission. On error, + * that reference was not consumed: dm_split_and_process_bio() releases + * it on the error path, so do not release it here a second time. + */ + if (sts == BLK_STS_OK) + atomic_dec(&ci->io->io_count); return sts; } @@ -2606,13 +2611,17 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) WARN_ON_ONCE(type == DM_TYPE_NONE); + /* A failed setup may have left the queue initialized or the disk dead. */ + if (md->tag_set || test_bit(GD_DEAD, &md->disk->state)) + return -ENODEV; + if (type == DM_TYPE_REQUEST_BASED) { - md->disk->fops = &dm_rq_blk_dops; r = dm_mq_init_request_queue(md, t); if (r) { DMERR("Cannot initialize queue for request-based dm mapped device"); return r; } + md->disk->fops = &dm_rq_blk_dops; } r = dm_calculate_queue_limits(t, &limits); diff --git a/drivers/md/dm.h b/drivers/md/dm.h index 7a795979ec7296..34f58060243fb5 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -37,10 +37,26 @@ /* * List of devices that a metadevice uses and should open/close. + * There is one dm_dev_internal per device. It holds one dm_dev_ref + * for each mode that the targets opened the device with. */ struct dm_dev_internal { struct list_head list; - refcount_t count; + struct block_device *bdev; + struct list_head refs; +}; + +/* + * One open of a device with one mode, shared by the targets of a table. + * dm_get_device() reuses a dm_dev_ref whose mode covers the requested + * mode, and adds a new one only when none does. So the dm_dev_refs of + * a device have different modes, and a table holds each table_device + * at most once. table_device->count is still the number of tables that + * use the table_device. + */ +struct dm_dev_ref { + struct list_head list; + refcount_t count; /* dm_get_device() calls that returned dm_dev */ struct dm_dev *dm_dev; }; diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c index 2357ff9b53f3ae..18f53c67220277 100644 --- a/drivers/md/persistent-data/dm-btree-remove.c +++ b/drivers/md/persistent-data/dm-btree-remove.c @@ -253,7 +253,9 @@ static int __rebalance2(struct dm_btree_info *info, struct btree_node *parent, /* * Merge */ - node_copy(left, right, -nr_right); + ret = node_copy(left, right, -nr_right); + if (unlikely(ret)) + return ret; left->header.nr_entries = cpu_to_le32(nr_left + nr_right); delete_at(parent, r->index); @@ -315,13 +317,16 @@ static int delete_center_node(struct dm_btree_info *info, struct btree_node *par { uint32_t max_entries = le32_to_cpu(left->header.max_entries); unsigned int shift = min(max_entries - nr_left, nr_center); + int ret; if (nr_left + shift > max_entries) { DMERR("node shift out of bounds"); return -EINVAL; } - node_copy(left, center, -shift); + ret = node_copy(left, center, -shift); + if (unlikely(ret)) + return ret; left->header.nr_entries = cpu_to_le32(nr_left + shift); if (shift != nr_center) { @@ -333,7 +338,9 @@ static int delete_center_node(struct dm_btree_info *info, struct btree_node *par } node_shift(right, shift); - node_copy(center, right, shift); + ret = node_copy(center, right, shift); + if (unlikely(ret)) + return ret; right->header.nr_entries = cpu_to_le32(nr_right + shift); } *key_ptr(parent, r->index) = right->keys[0]; diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index dd02eee4a23c0f..abfbbab8c7c6be 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -1582,7 +1582,13 @@ int dm_btree_cursor_begin(struct dm_btree_info *info, dm_block_t root, if (r) return r; - return find_leaf(c); + r = find_leaf(c); + if (unlikely(r)) { + dm_btree_cursor_end(c); + return r; + } + + return 0; } EXPORT_SYMBOL_GPL(dm_btree_cursor_begin); diff --git a/drivers/md/persistent-data/dm-space-map-common.c b/drivers/md/persistent-data/dm-space-map-common.c index 22a551c407da49..833aefb0ab996b 100644 --- a/drivers/md/persistent-data/dm-space-map-common.c +++ b/drivers/md/persistent-data/dm-space-map-common.c @@ -1190,17 +1190,20 @@ static dm_block_t disk_ll_max_entries(struct ll_disk *ll) static int disk_ll_commit(struct ll_disk *ll) { - int r = 0; + int r; unsigned int i; for (i = 0; i < IE_CACHE_SIZE; i++) { struct ie_cache *iec = ll->ie_cache + i; - if (iec->valid && iec->dirty) + if (iec->valid && iec->dirty) { r = ie_cache_writeback(ll, iec); + if (unlikely(r)) + return r; + } } - return r; + return 0; } int sm_ll_new_disk(struct ll_disk *ll, struct dm_transaction_manager *tm) diff --git a/drivers/media/cec/i2c/ch7322.c b/drivers/media/cec/i2c/ch7322.c index b8755337b39415..172f2060e1f6bb 100644 --- a/drivers/media/cec/i2c/ch7322.c +++ b/drivers/media/cec/i2c/ch7322.c @@ -461,7 +461,7 @@ static int ch7322_probe(struct i2c_client *client) if (hdmi_dev) caps |= CEC_CAP_CONNECTOR_INFO; - ch7322 = devm_kzalloc(&client->dev, sizeof(*ch7322), GFP_KERNEL); + ch7322 = devm_kzalloc_obj(&client->dev, *ch7322); if (!ch7322) return -ENOMEM; diff --git a/drivers/media/cec/i2c/tda9950.c b/drivers/media/cec/i2c/tda9950.c index 2bece4e6368723..572f7eea818cb1 100644 --- a/drivers/media/cec/i2c/tda9950.c +++ b/drivers/media/cec/i2c/tda9950.c @@ -400,7 +400,7 @@ static int tda9950_probe(struct i2c_client *client) return -ENXIO; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/cec/platform/cec-gpio/cec-gpio.c b/drivers/media/cec/platform/cec-gpio/cec-gpio.c index 842555ed42c710..f603cec4a38621 100644 --- a/drivers/media/cec/platform/cec-gpio/cec-gpio.c +++ b/drivers/media/cec/platform/cec-gpio/cec-gpio.c @@ -187,7 +187,7 @@ static int cec_gpio_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) caps |= CEC_CAP_PHYS_ADDR; - cec = devm_kzalloc(dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 1fe9c537671dd7..aa517950c014b6 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -452,7 +452,7 @@ static int cros_ec_cec_init_port(struct device *dev, struct cros_ec_cec_port *port; int ret; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; @@ -507,8 +507,7 @@ static int cros_ec_cec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - cros_ec_cec = devm_kzalloc(&pdev->dev, sizeof(*cros_ec_cec), - GFP_KERNEL); + cros_ec_cec = devm_kzalloc_obj(&pdev->dev, *cros_ec_cec); if (!cros_ec_cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/meson/ao-cec-g12a.c b/drivers/media/cec/platform/meson/ao-cec-g12a.c index 55bd0d416460f8..e5e1b00a040927 100644 --- a/drivers/media/cec/platform/meson/ao-cec-g12a.c +++ b/drivers/media/cec/platform/meson/ao-cec-g12a.c @@ -339,7 +339,7 @@ static int meson_ao_cec_g12a_setup_clk(struct meson_ao_cec_g12a_device *ao_cec) struct clk *clk; char *name; - dualdiv_clk = devm_kzalloc(dev, sizeof(*dualdiv_clk), GFP_KERNEL); + dualdiv_clk = devm_kzalloc_obj(dev, *dualdiv_clk); if (!dualdiv_clk) return -ENOMEM; @@ -641,7 +641,7 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - ao_cec = devm_kzalloc(&pdev->dev, sizeof(*ao_cec), GFP_KERNEL); + ao_cec = devm_kzalloc_obj(&pdev->dev, *ao_cec); if (!ao_cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/meson/ao-cec.c b/drivers/media/cec/platform/meson/ao-cec.c index 2df0d374307792..f5203b2a497696 100644 --- a/drivers/media/cec/platform/meson/ao-cec.c +++ b/drivers/media/cec/platform/meson/ao-cec.c @@ -609,7 +609,7 @@ static int meson_ao_cec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - ao_cec = devm_kzalloc(&pdev->dev, sizeof(*ao_cec), GFP_KERNEL); + ao_cec = devm_kzalloc_obj(&pdev->dev, *ao_cec); if (!ao_cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/s5p/s5p_cec.c b/drivers/media/cec/platform/s5p/s5p_cec.c index 4a92d3230f661e..65e2d9a90434a9 100644 --- a/drivers/media/cec/platform/s5p/s5p_cec.c +++ b/drivers/media/cec/platform/s5p/s5p_cec.c @@ -189,7 +189,7 @@ static int s5p_cec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(&pdev->dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/seco/seco-cec.c b/drivers/media/cec/platform/seco/seco-cec.c index 12db6dca602b2a..48823626ae752e 100644 --- a/drivers/media/cec/platform/seco/seco-cec.c +++ b/drivers/media/cec/platform/seco/seco-cec.c @@ -570,7 +570,7 @@ static int secocec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - secocec = devm_kzalloc(dev, sizeof(*secocec), GFP_KERNEL); + secocec = devm_kzalloc_obj(dev, *secocec); if (!secocec) return -ENOMEM; diff --git a/drivers/media/cec/platform/sti/stih-cec.c b/drivers/media/cec/platform/sti/stih-cec.c index 49843d576c7ce7..6303ed34b303b8 100644 --- a/drivers/media/cec/platform/sti/stih-cec.c +++ b/drivers/media/cec/platform/sti/stih-cec.c @@ -309,7 +309,7 @@ static int stih_cec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - cec = devm_kzalloc(dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/stm32/stm32-cec.c b/drivers/media/cec/platform/stm32/stm32-cec.c index 29418966a98ef2..b20d0aca3d8659 100644 --- a/drivers/media/cec/platform/stm32/stm32-cec.c +++ b/drivers/media/cec/platform/stm32/stm32-cec.c @@ -264,7 +264,7 @@ static int stm32_cec_probe(struct platform_device *pdev) void __iomem *mmio; int ret; - cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(&pdev->dev, *cec); if (!cec) return -ENOMEM; diff --git a/drivers/media/cec/platform/tegra/tegra_cec.c b/drivers/media/cec/platform/tegra/tegra_cec.c index d64e1662249e29..cd0f38c88cb41a 100644 --- a/drivers/media/cec/platform/tegra/tegra_cec.c +++ b/drivers/media/cec/platform/tegra/tegra_cec.c @@ -356,7 +356,7 @@ static int tegra_cec_probe(struct platform_device *pdev) if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); - cec = devm_kzalloc(&pdev->dev, sizeof(struct tegra_cec), GFP_KERNEL); + cec = devm_kzalloc_obj(&pdev->dev, struct tegra_cec); if (!cec) return -ENOMEM; diff --git a/drivers/media/dvb-frontends/helene.c b/drivers/media/dvb-frontends/helene.c index 5fbb466cc8af92..6aa04ba5c98825 100644 --- a/drivers/media/dvb-frontends/helene.c +++ b/drivers/media/dvb-frontends/helene.c @@ -1070,7 +1070,7 @@ static int helene_probe(struct i2c_client *client) struct device *dev = &client->dev; struct helene_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/dvb-frontends/mn88443x.c b/drivers/media/dvb-frontends/mn88443x.c index cc6bd17daf73b0..b8fa4b9cc889ba 100644 --- a/drivers/media/dvb-frontends/mn88443x.c +++ b/drivers/media/dvb-frontends/mn88443x.c @@ -681,7 +681,7 @@ static int mn88443x_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c index fcce2857b69efd..e5a5b3d33dfd8b 100644 --- a/drivers/media/i2c/ad5820.c +++ b/drivers/media/i2c/ad5820.c @@ -295,7 +295,7 @@ static int ad5820_probe(struct i2c_client *client) struct ad5820_device *coil; int ret; - coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL); + coil = devm_kzalloc_obj(&client->dev, *coil); if (!coil) return -ENOMEM; diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c index 177a6e8d7fb8bd..91e119e0c48fa1 100644 --- a/drivers/media/i2c/adp1653.c +++ b/drivers/media/i2c/adp1653.c @@ -414,7 +414,7 @@ static int adp1653_of_init(struct i2c_client *client, struct device_node *node_indicator = NULL; struct device_node *node_flash; - pd = devm_kzalloc(&client->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(&client->dev, *pd); if (!pd) return -ENOMEM; flash->platform_data = pd; @@ -470,7 +470,7 @@ static int adp1653_probe(struct i2c_client *client) struct adp1653_flash *flash; int ret; - flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&client->dev, *flash); if (flash == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/adv7170.c b/drivers/media/i2c/adv7170.c index 9a7edd6583c138..9cd9c2d8ca2dbb 100644 --- a/drivers/media/i2c/adv7170.c +++ b/drivers/media/i2c/adv7170.c @@ -348,7 +348,7 @@ static int adv7170_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(&client->dev, *encoder); if (encoder == NULL) return -ENOMEM; sd = &encoder->sd; diff --git a/drivers/media/i2c/adv7175.c b/drivers/media/i2c/adv7175.c index b77737e23a4759..bd52602e1190f6 100644 --- a/drivers/media/i2c/adv7175.c +++ b/drivers/media/i2c/adv7175.c @@ -403,7 +403,7 @@ static int adv7175_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(&client->dev, *encoder); if (encoder == NULL) return -ENOMEM; sd = &encoder->sd; diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index 02197f81375857..9f460d41211c63 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -1451,7 +1451,7 @@ static int adv7180_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/adv7183.c b/drivers/media/i2c/adv7183.c index 9e4cbebe6e5aac..d5acc51257269f 100644 --- a/drivers/media/i2c/adv7183.c +++ b/drivers/media/i2c/adv7183.c @@ -537,7 +537,7 @@ static int adv7183_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (decoder == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c index 2bf17cd633c766..8511505d0fba97 100644 --- a/drivers/media/i2c/adv7343.c +++ b/drivers/media/i2c/adv7343.c @@ -399,7 +399,7 @@ adv7343_get_pdata(struct i2c_client *client) if (!np) return NULL; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) goto done; @@ -431,8 +431,7 @@ static int adv7343_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(struct adv7343_state), - GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, struct adv7343_state); if (state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/adv7393.c b/drivers/media/i2c/adv7393.c index b00783c141a98d..38defbb0d2109f 100644 --- a/drivers/media/i2c/adv7393.c +++ b/drivers/media/i2c/adv7393.c @@ -384,7 +384,7 @@ static int adv7393_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c index 70594d0018048f..a21abfb9ffc129 100644 --- a/drivers/media/i2c/adv748x/adv748x-core.c +++ b/drivers/media/i2c/adv748x/adv748x-core.c @@ -715,7 +715,7 @@ static int adv748x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/adv7511-v4l2.c b/drivers/media/i2c/adv7511-v4l2.c index 27e0e2c31dbd1d..3333c861e87b49 100644 --- a/drivers/media/i2c/adv7511-v4l2.c +++ b/drivers/media/i2c/adv7511-v4l2.c @@ -1837,7 +1837,7 @@ static int adv7511_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, struct adv7511_state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c index 2de743d8ca2171..6002967d8ab0ee 100644 --- a/drivers/media/i2c/adv7604.c +++ b/drivers/media/i2c/adv7604.c @@ -3491,7 +3491,7 @@ static int adv76xx_probe(struct i2c_client *client) v4l_dbg(1, debug, client, "detecting adv76xx client on address 0x%x\n", client->addr << 1); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c index df6601d6d2b664..7d1bb6a6918a8c 100644 --- a/drivers/media/i2c/adv7842.c +++ b/drivers/media/i2c/adv7842.c @@ -3538,7 +3538,7 @@ static int adv7842_probe(struct i2c_client *client) return -ENODEV; } - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c index 9a2432cea3fff9..1ece5708b4b270 100644 --- a/drivers/media/i2c/ak7375.c +++ b/drivers/media/i2c/ak7375.c @@ -181,8 +181,7 @@ static int ak7375_probe(struct i2c_client *client) int ret; unsigned int i; - ak7375_dev = devm_kzalloc(&client->dev, sizeof(*ak7375_dev), - GFP_KERNEL); + ak7375_dev = devm_kzalloc_obj(&client->dev, *ak7375_dev); if (!ak7375_dev) return -ENOMEM; diff --git a/drivers/media/i2c/ak881x.c b/drivers/media/i2c/ak881x.c index 3449d95ee8a0dc..47cf2e2e7b128a 100644 --- a/drivers/media/i2c/ak881x.c +++ b/drivers/media/i2c/ak881x.c @@ -238,7 +238,7 @@ static int ak881x_probe(struct i2c_client *client) return -EIO; } - ak881x = devm_kzalloc(&client->dev, sizeof(*ak881x), GFP_KERNEL); + ak881x = devm_kzalloc_obj(&client->dev, *ak881x); if (!ak881x) return -ENOMEM; diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index d9a73565457f31..1fc8c5e8c86be5 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -2428,7 +2428,7 @@ static int alvium_probe(struct i2c_client *client) struct alvium_dev *alvium; int ret; - alvium = devm_kzalloc(dev, sizeof(*alvium), GFP_KERNEL); + alvium = devm_kzalloc_obj(dev, *alvium); if (!alvium) return -ENOMEM; diff --git a/drivers/media/i2c/ar0521.c b/drivers/media/i2c/ar0521.c index 3ddbf10ef8a4e5..732a9a2589fe16 100644 --- a/drivers/media/i2c/ar0521.c +++ b/drivers/media/i2c/ar0521.c @@ -1039,7 +1039,7 @@ static int ar0521_probe(struct i2c_client *client) unsigned int cnt; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/bt819.c b/drivers/media/i2c/bt819.c index da44100062fa2d..faccae316639a4 100644 --- a/drivers/media/i2c/bt819.c +++ b/drivers/media/i2c/bt819.c @@ -391,7 +391,7 @@ static int bt819_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (decoder == NULL) return -ENOMEM; sd = &decoder->sd; diff --git a/drivers/media/i2c/bt856.c b/drivers/media/i2c/bt856.c index 656719158bb459..81c801065a2902 100644 --- a/drivers/media/i2c/bt856.c +++ b/drivers/media/i2c/bt856.c @@ -193,7 +193,7 @@ static int bt856_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(&client->dev, *encoder); if (encoder == NULL) return -ENOMEM; sd = &encoder->sd; diff --git a/drivers/media/i2c/bt866.c b/drivers/media/i2c/bt866.c index f5104c7d9f900b..3bc2c2989115cc 100644 --- a/drivers/media/i2c/bt866.c +++ b/drivers/media/i2c/bt866.c @@ -181,7 +181,7 @@ static int bt866_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(&client->dev, *encoder); if (encoder == NULL) return -ENOMEM; sd = &encoder->sd; diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c index 1cc4350856fdf9..c3592317ee5757 100644 --- a/drivers/media/i2c/ccs/ccs-core.c +++ b/drivers/media/i2c/ccs/ccs-core.c @@ -1228,10 +1228,9 @@ static int ccs_get_mbus_formats(struct ccs_sensor *sensor) compressed_max_bpp); } - sensor->valid_link_freqs = devm_kcalloc( - &client->dev, - compressed_max_bpp - sensor->compressed_min_bpp + 1, - sizeof(*sensor->valid_link_freqs), GFP_KERNEL); + sensor->valid_link_freqs = devm_kzalloc_objs(&client->dev, + *sensor->valid_link_freqs, + compressed_max_bpp - sensor->compressed_min_bpp + 1); if (!sensor->valid_link_freqs) return -ENOMEM; @@ -3203,9 +3202,8 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev) } hwcfg->op_sys_clock = - devm_kcalloc(dev, - bus_cfg.nr_of_link_frequencies + 1 /* guardian */, - sizeof(*hwcfg->op_sys_clock), GFP_KERNEL); + devm_kzalloc_objs(dev, *hwcfg->op_sys_clock, + bus_cfg.nr_of_link_frequencies + 1)/* guardian */; if (!hwcfg->op_sys_clock) { rval = -ENOMEM; goto out_err; @@ -3275,7 +3273,7 @@ static int ccs_probe(struct i2c_client *client) unsigned int i; int rval; - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (sensor == NULL) return -ENOMEM; @@ -3288,10 +3286,9 @@ static int ccs_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&sensor->src->sd, client, &ccs_ops); sensor->src->sd.internal_ops = &ccs_internal_src_ops; - sensor->regulators = devm_kcalloc(&client->dev, - ARRAY_SIZE(ccs_regulators), - sizeof(*sensor->regulators), - GFP_KERNEL); + sensor->regulators = devm_kzalloc_objs(&client->dev, + *sensor->regulators, + ARRAY_SIZE(ccs_regulators)); if (!sensor->regulators) return -ENOMEM; diff --git a/drivers/media/i2c/cs5345.c b/drivers/media/i2c/cs5345.c index 49b8020fbea294..a9ce12f11c338f 100644 --- a/drivers/media/i2c/cs5345.c +++ b/drivers/media/i2c/cs5345.c @@ -148,7 +148,7 @@ static int cs5345_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/cs53l32a.c b/drivers/media/i2c/cs53l32a.c index a894dcf6b5a96f..01ea9dda69887a 100644 --- a/drivers/media/i2c/cs53l32a.c +++ b/drivers/media/i2c/cs53l32a.c @@ -145,7 +145,7 @@ static int cs53l32a_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/cvs/core.c b/drivers/media/i2c/cvs/core.c index d9c51e1c0fb5df..f909a3c03316ce 100644 --- a/drivers/media/i2c/cvs/core.c +++ b/drivers/media/i2c/cvs/core.c @@ -683,7 +683,7 @@ static int cvs_core_probe(struct device *dev, struct i2c_client *i2c) goto err_put_ipu; } - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) { ret = -ENOMEM; goto err_put_ipu; diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c index e90d71fe9959bc..7066b2252afd1c 100644 --- a/drivers/media/i2c/cx25840/cx25840-core.c +++ b/drivers/media/i2c/cx25840/cx25840-core.c @@ -3825,7 +3825,7 @@ static int cx25840_probe(struct i2c_client *client) return -ENODEV; } - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/cx25840/cx25840-ir.c b/drivers/media/i2c/cx25840/cx25840-ir.c index 8cef9656c61224..ed629989495bd7 100644 --- a/drivers/media/i2c/cx25840/cx25840-ir.c +++ b/drivers/media/i2c/cx25840/cx25840-ir.c @@ -1193,7 +1193,7 @@ int cx25840_ir_probe(struct v4l2_subdev *sd) if (!(is_cx23885(state) || is_cx23887(state))) return 0; - ir_state = devm_kzalloc(&state->c->dev, sizeof(*ir_state), GFP_KERNEL); + ir_state = devm_kzalloc_obj(&state->c->dev, *ir_state); if (ir_state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/ds90ub913.c b/drivers/media/i2c/ds90ub913.c index ca0b07d7109beb..e1db008e2977bf 100644 --- a/drivers/media/i2c/ds90ub913.c +++ b/drivers/media/i2c/ds90ub913.c @@ -798,7 +798,7 @@ static int ub913_probe(struct i2c_client *client) struct ub913_data *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c index e6ae9cadefa280..d207f916375f5b 100644 --- a/drivers/media/i2c/ds90ub953.c +++ b/drivers/media/i2c/ds90ub953.c @@ -1249,7 +1249,7 @@ static int ub953_probe(struct i2c_client *client) struct ub953_data *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c index 7d7ba6d349fc41..16234f30da2203 100644 --- a/drivers/media/i2c/ds90ub960.c +++ b/drivers/media/i2c/ds90ub960.c @@ -5135,7 +5135,7 @@ static int ub960_probe(struct i2c_client *client) struct ub960_data *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/dw9714.c b/drivers/media/i2c/dw9714.c index 1d686b1d2fd78f..ee99835e45e9ff 100644 --- a/drivers/media/i2c/dw9714.c +++ b/drivers/media/i2c/dw9714.c @@ -166,8 +166,7 @@ static int dw9714_probe(struct i2c_client *client) struct dw9714_device *dw9714_dev; int rval; - dw9714_dev = devm_kzalloc(&client->dev, sizeof(*dw9714_dev), - GFP_KERNEL); + dw9714_dev = devm_kzalloc_obj(&client->dev, *dw9714_dev); if (!dw9714_dev) return -ENOMEM; diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c index 3b7ba88fd67c04..5d5da0439dba01 100644 --- a/drivers/media/i2c/dw9719.c +++ b/drivers/media/i2c/dw9719.c @@ -355,7 +355,7 @@ static int dw9719_probe(struct i2c_client *client) struct dw9719_device *dw9719; int ret; - dw9719 = devm_kzalloc(&client->dev, sizeof(*dw9719), GFP_KERNEL); + dw9719 = devm_kzalloc_obj(&client->dev, *dw9719); if (!dw9719) return -ENOMEM; diff --git a/drivers/media/i2c/dw9768.c b/drivers/media/i2c/dw9768.c index d037d3009c9a5e..f31e0e832269ea 100644 --- a/drivers/media/i2c/dw9768.c +++ b/drivers/media/i2c/dw9768.c @@ -413,7 +413,7 @@ static int dw9768_probe(struct i2c_client *client) unsigned int i; int ret; - dw9768 = devm_kzalloc(dev, sizeof(*dw9768), GFP_KERNEL); + dw9768 = devm_kzalloc_obj(dev, *dw9768); if (!dw9768) return -ENOMEM; diff --git a/drivers/media/i2c/dw9807-vcm.c b/drivers/media/i2c/dw9807-vcm.c index 4148009e0e0170..d119d7100e2e0e 100644 --- a/drivers/media/i2c/dw9807-vcm.c +++ b/drivers/media/i2c/dw9807-vcm.c @@ -180,8 +180,7 @@ static int dw9807_probe(struct i2c_client *client) struct dw9807_device *dw9807_dev; int rval; - dw9807_dev = devm_kzalloc(&client->dev, sizeof(*dw9807_dev), - GFP_KERNEL); + dw9807_dev = devm_kzalloc_obj(&client->dev, *dw9807_dev); if (dw9807_dev == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/et8ek8/et8ek8_driver.c b/drivers/media/i2c/et8ek8/et8ek8_driver.c index e8a7b7d87bb177..0c734144b85b8f 100644 --- a/drivers/media/i2c/et8ek8/et8ek8_driver.c +++ b/drivers/media/i2c/et8ek8/et8ek8_driver.c @@ -1407,7 +1407,7 @@ static int et8ek8_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/gc0308.c b/drivers/media/i2c/gc0308.c index 893dfe2e1c3e13..ff384031a5d090 100644 --- a/drivers/media/i2c/gc0308.c +++ b/drivers/media/i2c/gc0308.c @@ -1288,7 +1288,7 @@ static int gc0308_probe(struct i2c_client *client) u64 regval; int ret; - gc0308 = devm_kzalloc(dev, sizeof(*gc0308), GFP_KERNEL); + gc0308 = devm_kzalloc_obj(dev, *gc0308); if (!gc0308) return -ENOMEM; diff --git a/drivers/media/i2c/gc0310.c b/drivers/media/i2c/gc0310.c index 5e941291dbf7ad..ca15d337544238 100644 --- a/drivers/media/i2c/gc0310.c +++ b/drivers/media/i2c/gc0310.c @@ -679,7 +679,7 @@ static int gc0310_probe(struct i2c_client *client) if (ret) return ret; - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/gc05a2.c b/drivers/media/i2c/gc05a2.c index 5b95d888164965..1da46273e1cb9d 100644 --- a/drivers/media/i2c/gc05a2.c +++ b/drivers/media/i2c/gc05a2.c @@ -1221,7 +1221,7 @@ static int gc05a2_probe(struct i2c_client *client) struct gc05a2 *gc05a2; int ret; - gc05a2 = devm_kzalloc(dev, sizeof(*gc05a2), GFP_KERNEL); + gc05a2 = devm_kzalloc_obj(dev, *gc05a2); if (!gc05a2) return -ENOMEM; diff --git a/drivers/media/i2c/gc08a3.c b/drivers/media/i2c/gc08a3.c index c1ae05ed1f2ade..9275ced8d6a82d 100644 --- a/drivers/media/i2c/gc08a3.c +++ b/drivers/media/i2c/gc08a3.c @@ -1185,7 +1185,7 @@ static int gc08a3_probe(struct i2c_client *client) struct gc08a3 *gc08a3; int ret; - gc08a3 = devm_kzalloc(dev, sizeof(*gc08a3), GFP_KERNEL); + gc08a3 = devm_kzalloc_obj(dev, *gc08a3); if (!gc08a3) return -ENOMEM; diff --git a/drivers/media/i2c/gc2145.c b/drivers/media/i2c/gc2145.c index 661a59641f1940..afb46e8971d684 100644 --- a/drivers/media/i2c/gc2145.c +++ b/drivers/media/i2c/gc2145.c @@ -1321,7 +1321,7 @@ static int gc2145_probe(struct i2c_client *client) struct gc2145 *gc2145; int ret; - gc2145 = devm_kzalloc(&client->dev, sizeof(*gc2145), GFP_KERNEL); + gc2145 = devm_kzalloc_obj(&client->dev, *gc2145); if (!gc2145) return -ENOMEM; diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c index 4c13adf4a9002f..3b725bc59057bb 100644 --- a/drivers/media/i2c/hi556.c +++ b/drivers/media/i2c/hi556.c @@ -1329,7 +1329,7 @@ static int hi556_probe(struct i2c_client *client) if (ret) return ret; - hi556 = devm_kzalloc(&client->dev, sizeof(*hi556), GFP_KERNEL); + hi556 = devm_kzalloc_obj(&client->dev, *hi556); if (!hi556) return -ENOMEM; diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index 025f8bcd17bc72..7ca899c80bfc46 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -2043,7 +2043,7 @@ static int hi846_probe(struct i2c_client *client) int i; u32 mclk_freq; - hi846 = devm_kzalloc(&client->dev, sizeof(*hi846), GFP_KERNEL); + hi846 = devm_kzalloc_obj(&client->dev, *hi846); if (!hi846) return -ENOMEM; diff --git a/drivers/media/i2c/hi847.c b/drivers/media/i2c/hi847.c index 41b8cac6a5e3cd..98f041bc37c085 100644 --- a/drivers/media/i2c/hi847.c +++ b/drivers/media/i2c/hi847.c @@ -2859,7 +2859,7 @@ static int hi847_probe(struct i2c_client *client) unsigned long freq; int ret; - hi847 = devm_kzalloc(&client->dev, sizeof(*hi847), GFP_KERNEL); + hi847 = devm_kzalloc_obj(&client->dev, *hi847); if (!hi847) return -ENOMEM; diff --git a/drivers/media/i2c/hm1246.c b/drivers/media/i2c/hm1246.c index be1c3d75657ebd..65ed8e64adf3e8 100644 --- a/drivers/media/i2c/hm1246.c +++ b/drivers/media/i2c/hm1246.c @@ -1145,7 +1145,7 @@ static int hm1246_probe(struct i2c_client *client) struct hm1246 *hm1246; int ret; - hm1246 = devm_kzalloc(&client->dev, sizeof(*hm1246), GFP_KERNEL); + hm1246 = devm_kzalloc_obj(&client->dev, *hm1246); if (!hm1246) return -ENOMEM; diff --git a/drivers/media/i2c/imx111.c b/drivers/media/i2c/imx111.c index 5b860fa052b125..50c22608840d6f 100644 --- a/drivers/media/i2c/imx111.c +++ b/drivers/media/i2c/imx111.c @@ -1472,7 +1472,7 @@ static int imx111_probe(struct i2c_client *client) struct imx111 *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/imx208.c b/drivers/media/i2c/imx208.c index 3a899b41a9d295..9e12f26c9d4551 100644 --- a/drivers/media/i2c/imx208.c +++ b/drivers/media/i2c/imx208.c @@ -941,7 +941,7 @@ static int imx208_probe(struct i2c_client *client) int ret; bool full_power; - imx208 = devm_kzalloc(&client->dev, sizeof(*imx208), GFP_KERNEL); + imx208 = devm_kzalloc_obj(&client->dev, *imx208); if (!imx208) return -ENOMEM; diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c index 96833f2bf287f7..4f4fdfb309845d 100644 --- a/drivers/media/i2c/imx214.c +++ b/drivers/media/i2c/imx214.c @@ -1392,7 +1392,7 @@ static int imx214_probe(struct i2c_client *client) struct imx214 *imx214; int ret; - imx214 = devm_kzalloc(dev, sizeof(*imx214), GFP_KERNEL); + imx214 = devm_kzalloc_obj(dev, *imx214); if (!imx214) return -ENOMEM; diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 1580562093e82b..0c43a8b1c50989 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -1195,7 +1195,7 @@ static int imx219_probe(struct i2c_client *client) struct imx219 *imx219; int ret; - imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL); + imx219 = devm_kzalloc_obj(&client->dev, *imx219); if (!imx219) return -ENOMEM; diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 065c33380f60c8..4f8ac207266086 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -1371,7 +1371,7 @@ static int imx258_probe(struct i2c_client *client) int ret; u32 val = 0; - imx258 = devm_kzalloc(&client->dev, sizeof(*imx258), GFP_KERNEL); + imx258 = devm_kzalloc_obj(&client->dev, *imx258); if (!imx258) return -ENOMEM; diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c index 3245afc8ae5b87..b677cfc9a5480f 100644 --- a/drivers/media/i2c/imx274.c +++ b/drivers/media/i2c/imx274.c @@ -1958,7 +1958,7 @@ static int imx274_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - imx274 = devm_kzalloc(dev, sizeof(*imx274), GFP_KERNEL); + imx274 = devm_kzalloc_obj(dev, *imx274); if (!imx274) return -ENOMEM; diff --git a/drivers/media/i2c/imx283.c b/drivers/media/i2c/imx283.c index e3cd27ca238ee0..01c42f2de9206a 100644 --- a/drivers/media/i2c/imx283.c +++ b/drivers/media/i2c/imx283.c @@ -1463,7 +1463,7 @@ static int imx283_probe(struct i2c_client *client) unsigned int xclk_freq; int ret; - imx283 = devm_kzalloc(&client->dev, sizeof(*imx283), GFP_KERNEL); + imx283 = devm_kzalloc_obj(&client->dev, *imx283); if (!imx283) return -ENOMEM; diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index d562a9aa455c37..6375f87dee976e 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -1576,7 +1576,7 @@ static int imx290_probe(struct i2c_client *client) struct imx290 *imx290; int ret; - imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL); + imx290 = devm_kzalloc_obj(dev, *imx290); if (!imx290) return -ENOMEM; diff --git a/drivers/media/i2c/imx296.c b/drivers/media/i2c/imx296.c index 74bb295799fddc..7179dc001e9565 100644 --- a/drivers/media/i2c/imx296.c +++ b/drivers/media/i2c/imx296.c @@ -1023,7 +1023,7 @@ static int imx296_probe(struct i2c_client *client) return -EIO; } - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 281d39ed4194c1..e9348b0d6ee891 100644 --- a/drivers/media/i2c/imx319.c +++ b/drivers/media/i2c/imx319.c @@ -2344,7 +2344,7 @@ static struct imx319_hwcfg *imx319_get_hwcfg(struct device *dev) if (ret) goto out_err; - cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_obj(dev, *cfg); if (!cfg) goto out_err; @@ -2374,7 +2374,7 @@ static int imx319_probe(struct i2c_client *client) bool full_power; int ret; - imx319 = devm_kzalloc(&client->dev, sizeof(*imx319), GFP_KERNEL); + imx319 = devm_kzalloc_obj(&client->dev, *imx319); if (!imx319) return -ENOMEM; diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c index da19d5fc19f540..043f8131c3ba57 100644 --- a/drivers/media/i2c/imx334.c +++ b/drivers/media/i2c/imx334.c @@ -1223,7 +1223,7 @@ static int imx334_probe(struct i2c_client *client) struct imx334 *imx334; int ret; - imx334 = devm_kzalloc(&client->dev, sizeof(*imx334), GFP_KERNEL); + imx334 = devm_kzalloc_obj(&client->dev, *imx334); if (!imx334) return -ENOMEM; diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 8f29d9f2da83fa..aa26c58ffa763f 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -1362,7 +1362,7 @@ static int imx335_probe(struct i2c_client *client) struct imx335 *imx335; int ret; - imx335 = devm_kzalloc(&client->dev, sizeof(*imx335), GFP_KERNEL); + imx335 = devm_kzalloc_obj(&client->dev, *imx335); if (!imx335) return -ENOMEM; diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c index 45e3002bd93cad..c0dafabf5dc9ad 100644 --- a/drivers/media/i2c/imx355.c +++ b/drivers/media/i2c/imx355.c @@ -1149,7 +1149,7 @@ static struct imx355_hwcfg *imx355_get_hwcfg(struct imx355 *imx355) if (ret) goto out_err; - cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_obj(dev, *cfg); if (!cfg) goto out_err; @@ -1185,7 +1185,7 @@ static int imx355_probe(struct i2c_client *client) unsigned long freq; int ret; - imx355 = devm_kzalloc(&client->dev, sizeof(*imx355), GFP_KERNEL); + imx355 = devm_kzalloc_obj(&client->dev, *imx355); if (!imx355) return -ENOMEM; diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c index 4628e2eda231ad..0e50c297af0991 100644 --- a/drivers/media/i2c/imx412.c +++ b/drivers/media/i2c/imx412.c @@ -983,7 +983,7 @@ static int imx412_probe(struct i2c_client *client) const char *name; int ret; - imx412 = devm_kzalloc(&client->dev, sizeof(*imx412), GFP_KERNEL); + imx412 = devm_kzalloc_obj(&client->dev, *imx412); if (!imx412) return -ENOMEM; diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c index 2571718cffff30..7bb27bdf144628 100644 --- a/drivers/media/i2c/imx415.c +++ b/drivers/media/i2c/imx415.c @@ -1354,7 +1354,7 @@ static int imx415_probe(struct i2c_client *client) struct imx415 *sensor; int ret; - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/imx471.c b/drivers/media/i2c/imx471.c index 0f3a2812b9ea82..3eacd456320dd5 100644 --- a/drivers/media/i2c/imx471.c +++ b/drivers/media/i2c/imx471.c @@ -812,7 +812,7 @@ static int imx471_probe(struct i2c_client *client) struct imx471 *sensor; int ret; - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return dev_err_probe(&client->dev, -ENOMEM, "failed to allocate memory\n"); diff --git a/drivers/media/i2c/imx576.c b/drivers/media/i2c/imx576.c index 6243683302c762..6285d6ed0bcbee 100644 --- a/drivers/media/i2c/imx576.c +++ b/drivers/media/i2c/imx576.c @@ -951,7 +951,7 @@ static int imx576_probe(struct i2c_client *client) struct imx576 *imx576; int ret; - imx576 = devm_kzalloc(&client->dev, sizeof(*imx576), GFP_KERNEL); + imx576 = devm_kzalloc_obj(&client->dev, *imx576); if (!imx576) return -ENOMEM; diff --git a/drivers/media/i2c/imx678.c b/drivers/media/i2c/imx678.c index 8413fd44d65754..7d518643e633a5 100644 --- a/drivers/media/i2c/imx678.c +++ b/drivers/media/i2c/imx678.c @@ -1286,7 +1286,7 @@ static int imx678_probe(struct i2c_client *client) struct imx678 *imx678; int ret, i; - imx678 = devm_kzalloc(&client->dev, sizeof(*imx678), GFP_KERNEL); + imx678 = devm_kzalloc_obj(&client->dev, *imx678); if (!imx678) return -ENOMEM; diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c index f2bf2b35400077..ab7dee57cda345 100644 --- a/drivers/media/i2c/ir-kbd-i2c.c +++ b/drivers/media/i2c/ir-kbd-i2c.c @@ -776,7 +776,7 @@ static int ir_probe(struct i2c_client *client) return -ENODEV; } - ir = devm_kzalloc(&client->dev, sizeof(*ir), GFP_KERNEL); + ir = devm_kzalloc_obj(&client->dev, *ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/i2c/isl7998x.c b/drivers/media/i2c/isl7998x.c index adb49eb6264272..e36fb355133e1d 100644 --- a/drivers/media/i2c/isl7998x.c +++ b/drivers/media/i2c/isl7998x.c @@ -1467,7 +1467,7 @@ static int isl7998x_probe(struct i2c_client *client) return -EIO; } - isl7998x = devm_kzalloc(dev, sizeof(*isl7998x), GFP_KERNEL); + isl7998x = devm_kzalloc_obj(dev, *isl7998x); if (!isl7998x) return -ENOMEM; diff --git a/drivers/media/i2c/it6625.c b/drivers/media/i2c/it6625.c index b74df9dbf8c2ca..6550f22b16927d 100644 --- a/drivers/media/i2c/it6625.c +++ b/drivers/media/i2c/it6625.c @@ -2246,7 +2246,7 @@ static int it6625_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - it6625 = devm_kzalloc(&client->dev, sizeof(struct it6625), GFP_KERNEL); + it6625 = devm_kzalloc_obj(&client->dev, struct it6625); if (!it6625) return -ENOMEM; diff --git a/drivers/media/i2c/ks0127.c b/drivers/media/i2c/ks0127.c index 8c66be38adc305..18d8430516b6fd 100644 --- a/drivers/media/i2c/ks0127.c +++ b/drivers/media/i2c/ks0127.c @@ -651,7 +651,7 @@ static int ks0127_probe(struct i2c_client *client) client->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board", client->addr << 1, client->adapter->name); - ks = devm_kzalloc(&client->dev, sizeof(*ks), GFP_KERNEL); + ks = devm_kzalloc_obj(&client->dev, *ks); if (ks == NULL) return -ENOMEM; sd = &ks->sd; diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c index 6b28a5fcd2dabc..8b42fb02ef5eec 100644 --- a/drivers/media/i2c/lm3560.c +++ b/drivers/media/i2c/lm3560.c @@ -522,7 +522,7 @@ static int lm3560_probe(struct i2c_client *client) u32 peak_ua; int rval; - flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&client->dev, *flash); if (flash == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/lm3646.c b/drivers/media/i2c/lm3646.c index 9030cbe32afca1..f3257d7b8966fe 100644 --- a/drivers/media/i2c/lm3646.c +++ b/drivers/media/i2c/lm3646.c @@ -340,7 +340,7 @@ static int lm3646_probe(struct i2c_client *client) struct lm3646_platform_data *pdata = dev_get_platdata(&client->dev); int rval; - flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&client->dev, *flash); if (flash == NULL) return -ENOMEM; @@ -350,9 +350,8 @@ static int lm3646_probe(struct i2c_client *client) /* check device tree if there is no platform data */ if (pdata == NULL) { - pdata = devm_kzalloc(&client->dev, - sizeof(struct lm3646_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, + struct lm3646_platform_data); if (pdata == NULL) return -ENOMEM; /* use default data in case of no platform data */ diff --git a/drivers/media/i2c/lt6911uxe.c b/drivers/media/i2c/lt6911uxe.c index c9da174dbfa6c9..e6abfec8a706f3 100644 --- a/drivers/media/i2c/lt6911uxe.c +++ b/drivers/media/i2c/lt6911uxe.c @@ -589,7 +589,7 @@ static int lt6911uxe_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - lt6911uxe = devm_kzalloc(dev, sizeof(*lt6911uxe), GFP_KERNEL); + lt6911uxe = devm_kzalloc_obj(dev, *lt6911uxe); if (!lt6911uxe) return -ENOMEM; diff --git a/drivers/media/i2c/m52790.c b/drivers/media/i2c/m52790.c index f3adf8c2b27f1f..b1bb5a7a370b8e 100644 --- a/drivers/media/i2c/m52790.c +++ b/drivers/media/i2c/m52790.c @@ -141,7 +141,7 @@ static int m52790_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/max2175.c b/drivers/media/i2c/max2175.c index 1cc388b52902cd..292d766520c71a 100644 --- a/drivers/media/i2c/max2175.c +++ b/drivers/media/i2c/max2175.c @@ -1320,7 +1320,7 @@ static int max2175_probe(struct i2c_client *client) } /* Alloc tuner context */ - ctx = devm_kzalloc(&client->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&client->dev, *ctx); if (ctx == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 050ad9405c5f67..9dae1d8559aa35 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -1586,7 +1586,7 @@ static int max9286_probe(struct i2c_client *client) struct max9286_priv *priv; int ret; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max9296a.c b/drivers/media/i2c/maxim-serdes/max9296a.c index 7b25b54e63deb3..abc2a0f03a8c24 100644 --- a/drivers/media/i2c/maxim-serdes/max9296a.c +++ b/drivers/media/i2c/maxim-serdes/max9296a.c @@ -1173,7 +1173,7 @@ static int max9296a_probe(struct i2c_client *client) struct max9296a_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max96717.c b/drivers/media/i2c/maxim-serdes/max96717.c index e004e71cb768a9..c76d092a301910 100644 --- a/drivers/media/i2c/maxim-serdes/max96717.c +++ b/drivers/media/i2c/maxim-serdes/max96717.c @@ -1602,11 +1602,11 @@ static int max96717_probe(struct i2c_client *client) struct max_ser_ops *ops; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; - ops = devm_kzalloc(dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(dev, *ops); if (!ops) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max96724.c b/drivers/media/i2c/maxim-serdes/max96724.c index 3889d955f84be1..685e82a1ada2b6 100644 --- a/drivers/media/i2c/maxim-serdes/max96724.c +++ b/drivers/media/i2c/maxim-serdes/max96724.c @@ -1227,15 +1227,15 @@ static int max96724_probe(struct i2c_client *client) u32 cc_port; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; - ops = devm_kzalloc(dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(dev, *ops); if (!ops) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max_des.c b/drivers/media/i2c/maxim-serdes/max_des.c index 6b4ffd0e2415d5..37f4386086164e 100644 --- a/drivers/media/i2c/maxim-serdes/max_des.c +++ b/drivers/media/i2c/maxim-serdes/max_des.c @@ -1243,8 +1243,8 @@ static int max_des_update_pipe_vc_remaps(struct max_des_priv *priv, if (!des->ops->set_pipe_vc_remap) return 0; - vc_remaps = devm_kcalloc(priv->dev, MAX_SERDES_VC_ID_NUM, - sizeof(*vc_remaps), GFP_KERNEL); + vc_remaps = devm_kzalloc_objs(priv->dev, *vc_remaps, + MAX_SERDES_VC_ID_NUM); if (!vc_remaps) return -ENOMEM; @@ -1285,8 +1285,8 @@ static int max_des_update_pipe_remaps(struct max_des_priv *priv, if (!des->ops->set_pipe_remap) return 0; - remaps = devm_kcalloc(priv->dev, des->info->num_remaps_per_pipe, - sizeof(*remaps), GFP_KERNEL); + remaps = devm_kzalloc_objs(priv->dev, *remaps, + des->info->num_remaps_per_pipe); if (!remaps) return -ENOMEM; @@ -3210,39 +3210,37 @@ static int max_des_allocate(struct max_des_priv *priv) struct max_des *des = priv->des; unsigned int num_pads = max_des_num_pads(des); - des->phys = devm_kcalloc(priv->dev, des->info->num_phys, - sizeof(*des->phys), GFP_KERNEL); + des->phys = devm_kzalloc_objs(priv->dev, *des->phys, + des->info->num_phys); if (!des->phys) return -ENOMEM; - des->pipes = devm_kcalloc(priv->dev, des->info->num_pipes, - sizeof(*des->pipes), GFP_KERNEL); + des->pipes = devm_kzalloc_objs(priv->dev, *des->pipes, + des->info->num_pipes); if (!des->pipes) return -ENOMEM; - des->links = devm_kcalloc(priv->dev, des->info->num_links, - sizeof(*des->links), GFP_KERNEL); + des->links = devm_kzalloc_objs(priv->dev, *des->links, + des->info->num_links); if (!des->links) return -ENOMEM; - priv->sources = devm_kcalloc(priv->dev, des->info->num_links, - sizeof(*priv->sources), GFP_KERNEL); + priv->sources = devm_kzalloc_objs(priv->dev, *priv->sources, + des->info->num_links); if (!priv->sources) return -ENOMEM; - priv->pocs = devm_kcalloc(priv->dev, des->info->num_links, - sizeof(*priv->pocs), GFP_KERNEL); + priv->pocs = devm_kzalloc_objs(priv->dev, *priv->pocs, + des->info->num_links); if (!priv->pocs) return -ENOMEM; - priv->pads = devm_kcalloc(priv->dev, num_pads, - sizeof(*priv->pads), GFP_KERNEL); + priv->pads = devm_kzalloc_objs(priv->dev, *priv->pads, num_pads); if (!priv->pads) return -ENOMEM; - priv->streams_masks = devm_kcalloc(priv->dev, num_pads, - sizeof(*priv->streams_masks), - GFP_KERNEL); + priv->streams_masks = devm_kzalloc_objs(priv->dev, *priv->streams_masks, + num_pads); if (!priv->streams_masks) return -ENOMEM; @@ -3267,7 +3265,7 @@ int max_des_probe(struct i2c_client *client, struct max_des *des) if (des->info->num_links > des->info->num_pipes) return -E2BIG; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max_ser.c b/drivers/media/i2c/maxim-serdes/max_ser.c index d6a17f987e46a0..1c4cec2efb9521 100644 --- a/drivers/media/i2c/maxim-serdes/max_ser.c +++ b/drivers/media/i2c/maxim-serdes/max_ser.c @@ -1079,8 +1079,7 @@ static int max_ser_update_pipe(struct max_ser_priv *priv, if (!ser->ops->num_dts_per_pipe) return 0; - dts = devm_kcalloc(priv->dev, ser->ops->num_dts_per_pipe, sizeof(*dts), - GFP_KERNEL); + dts = devm_kzalloc_objs(priv->dev, *dts, ser->ops->num_dts_per_pipe); if (!dts) return -ENOMEM; @@ -1662,7 +1661,7 @@ static int max_ser_v4l2_register(struct max_ser_priv *priv) sd->entity.ops = &max_ser_media_ops; sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_STREAMS; - priv->pads = devm_kcalloc(priv->dev, num_pads, sizeof(*priv->pads), GFP_KERNEL); + priv->pads = devm_kzalloc_objs(priv->dev, *priv->pads, num_pads); if (!priv->pads) return -ENOMEM; @@ -1873,34 +1872,32 @@ static int max_ser_allocate(struct max_ser_priv *priv) struct max_ser *ser = priv->ser; unsigned int num_pads = max_ser_num_pads(ser); - ser->phys = devm_kcalloc(priv->dev, ser->ops->num_phys, - sizeof(*ser->phys), GFP_KERNEL); + ser->phys = devm_kzalloc_objs(priv->dev, *ser->phys, ser->ops->num_phys); if (!ser->phys) return -ENOMEM; - ser->pipes = devm_kcalloc(priv->dev, ser->ops->num_pipes, - sizeof(*ser->pipes), GFP_KERNEL); + ser->pipes = devm_kzalloc_objs(priv->dev, *ser->pipes, + ser->ops->num_pipes); if (!ser->pipes) return -ENOMEM; - ser->vc_remaps = devm_kcalloc(priv->dev, ser->ops->num_vc_remaps, - sizeof(*ser->vc_remaps), GFP_KERNEL); + ser->vc_remaps = devm_kzalloc_objs(priv->dev, *ser->vc_remaps, + ser->ops->num_vc_remaps); if (!ser->vc_remaps) return -ENOMEM; - ser->i2c_xlates = devm_kcalloc(priv->dev, ser->ops->num_i2c_xlates, - sizeof(*ser->i2c_xlates), GFP_KERNEL); + ser->i2c_xlates = devm_kzalloc_objs(priv->dev, *ser->i2c_xlates, + ser->ops->num_i2c_xlates); if (!ser->i2c_xlates) return -ENOMEM; - priv->sources = devm_kcalloc(priv->dev, ser->ops->num_phys, - sizeof(*priv->sources), GFP_KERNEL); + priv->sources = devm_kzalloc_objs(priv->dev, *priv->sources, + ser->ops->num_phys); if (!priv->sources) return -ENOMEM; - priv->streams_masks = devm_kcalloc(priv->dev, num_pads, - sizeof(*priv->streams_masks), - GFP_KERNEL); + priv->streams_masks = devm_kzalloc_objs(priv->dev, *priv->streams_masks, + num_pads); if (!priv->streams_masks) return -ENOMEM; @@ -1916,7 +1913,7 @@ int max_ser_probe(struct i2c_client *client, struct max_ser *ser) if (ser->ops->num_phys > MAX_SER_NUM_PHYS) return -E2BIG; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/maxim-serdes/max_serdes.c b/drivers/media/i2c/maxim-serdes/max_serdes.c index 7d013c4739d11c..6246bc55c551d1 100644 --- a/drivers/media/i2c/maxim-serdes/max_serdes.c +++ b/drivers/media/i2c/maxim-serdes/max_serdes.c @@ -256,7 +256,7 @@ int max_serdes_get_streams_masks(struct device *dev, u64 *streams_masks; unsigned int i; - streams_masks = devm_kcalloc(dev, num_pads, sizeof(*streams_masks), GFP_KERNEL); + streams_masks = devm_kzalloc_objs(dev, *streams_masks, num_pads); if (!streams_masks) return -ENOMEM; diff --git a/drivers/media/i2c/ml86v7667.c b/drivers/media/i2c/ml86v7667.c index eda41a80d20cf1..355899bd02e34a 100644 --- a/drivers/media/i2c/ml86v7667.c +++ b/drivers/media/i2c/ml86v7667.c @@ -366,7 +366,7 @@ static int ml86v7667_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/msp3400-driver.c b/drivers/media/i2c/msp3400-driver.c index a540b211f7d783..8c2edd4620ef34 100644 --- a/drivers/media/i2c/msp3400-driver.c +++ b/drivers/media/i2c/msp3400-driver.c @@ -679,7 +679,7 @@ static int msp_probe(struct i2c_client *client) return -ENODEV; } - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/mt9m001.c b/drivers/media/i2c/mt9m001.c index fe46ea65550a9d..41fb745e516d7f 100644 --- a/drivers/media/i2c/mt9m001.c +++ b/drivers/media/i2c/mt9m001.c @@ -744,7 +744,7 @@ static int mt9m001_probe(struct i2c_client *client) return -EIO; } - mt9m001 = devm_kzalloc(&client->dev, sizeof(*mt9m001), GFP_KERNEL); + mt9m001 = devm_kzalloc_obj(&client->dev, *mt9m001); if (!mt9m001) return -ENOMEM; diff --git a/drivers/media/i2c/mt9m111.c b/drivers/media/i2c/mt9m111.c index f911c1cb43e1e0..098e9c01acf222 100644 --- a/drivers/media/i2c/mt9m111.c +++ b/drivers/media/i2c/mt9m111.c @@ -1272,7 +1272,7 @@ static int mt9m111_probe(struct i2c_client *client) return -EIO; } - mt9m111 = devm_kzalloc(&client->dev, sizeof(struct mt9m111), GFP_KERNEL); + mt9m111 = devm_kzalloc_obj(&client->dev, struct mt9m111); if (!mt9m111) return -ENOMEM; diff --git a/drivers/media/i2c/mt9m114.c b/drivers/media/i2c/mt9m114.c index c6c950d5c8f3d6..b545b3da8359c7 100644 --- a/drivers/media/i2c/mt9m114.c +++ b/drivers/media/i2c/mt9m114.c @@ -2529,7 +2529,7 @@ static int mt9m114_probe(struct i2c_client *client) struct mt9m114 *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c index 5b0a84c66043e8..40e44cf048dca1 100644 --- a/drivers/media/i2c/mt9p031.c +++ b/drivers/media/i2c/mt9p031.c @@ -1103,7 +1103,7 @@ static int mt9p031_probe(struct i2c_client *client) return -EIO; } - mt9p031 = devm_kzalloc(&client->dev, sizeof(*mt9p031), GFP_KERNEL); + mt9p031 = devm_kzalloc_obj(&client->dev, *mt9p031); if (mt9p031 == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c index 7a47756b93560a..3774dbcf5bdab2 100644 --- a/drivers/media/i2c/mt9t112.c +++ b/drivers/media/i2c/mt9t112.c @@ -1072,7 +1072,7 @@ static int mt9t112_probe(struct i2c_client *client) return -EINVAL; } - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c index 6ea31a4a64633e..3ccc0e60b64e80 100644 --- a/drivers/media/i2c/mt9v011.c +++ b/drivers/media/i2c/mt9v011.c @@ -501,7 +501,7 @@ static int mt9v011_probe(struct i2c_client *c) I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) return -EIO; - core = devm_kzalloc(&c->dev, sizeof(struct mt9v011), GFP_KERNEL); + core = devm_kzalloc_obj(&c->dev, struct mt9v011); if (!core) return -ENOMEM; diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c index 29823378f0c71f..3dfd0b2c96f1a8 100644 --- a/drivers/media/i2c/mt9v032.c +++ b/drivers/media/i2c/mt9v032.c @@ -1023,8 +1023,7 @@ static int mt9v032_get_pdata(struct mt9v032 *mt9v032) u64 *link_freqs; size_t size = prop->length / sizeof(*link_freqs); - link_freqs = devm_kcalloc(mt9v032->dev, size, - sizeof(*link_freqs), GFP_KERNEL); + link_freqs = devm_kzalloc_objs(mt9v032->dev, *link_freqs, size); if (!link_freqs) return -EINVAL; @@ -1048,7 +1047,7 @@ static int mt9v032_probe(struct i2c_client *client) unsigned int i; int ret; - mt9v032 = devm_kzalloc(&client->dev, sizeof(*mt9v032), GFP_KERNEL); + mt9v032 = devm_kzalloc_obj(&client->dev, *mt9v032); if (!mt9v032) return -ENOMEM; diff --git a/drivers/media/i2c/mt9v111.c b/drivers/media/i2c/mt9v111.c index 6e9b3e190bcaa1..185f93b7656fea 100644 --- a/drivers/media/i2c/mt9v111.c +++ b/drivers/media/i2c/mt9v111.c @@ -1121,7 +1121,7 @@ static int mt9v111_probe(struct i2c_client *client) struct v4l2_fract tpf; int ret; - mt9v111 = devm_kzalloc(&client->dev, sizeof(*mt9v111), GFP_KERNEL); + mt9v111 = devm_kzalloc_obj(&client->dev, *mt9v111); if (!mt9v111) return -ENOMEM; diff --git a/drivers/media/i2c/og01a1b.c b/drivers/media/i2c/og01a1b.c index b207b1d853a400..25e9b8bc9f391f 100644 --- a/drivers/media/i2c/og01a1b.c +++ b/drivers/media/i2c/og01a1b.c @@ -970,7 +970,7 @@ static int og01a1b_probe(struct i2c_client *client) unsigned long freq; int ret; - og01a1b = devm_kzalloc(&client->dev, sizeof(*og01a1b), GFP_KERNEL); + og01a1b = devm_kzalloc_obj(&client->dev, *og01a1b); if (!og01a1b) return -ENOMEM; diff --git a/drivers/media/i2c/og0ve1b.c b/drivers/media/i2c/og0ve1b.c index e7cd0f72f3e523..cc283b3b586c5d 100644 --- a/drivers/media/i2c/og0ve1b.c +++ b/drivers/media/i2c/og0ve1b.c @@ -974,7 +974,7 @@ static int og0ve1b_probe(struct i2c_client *client) unsigned int i; int ret; - og0ve1b = devm_kzalloc(&client->dev, sizeof(*og0ve1b), GFP_KERNEL); + og0ve1b = devm_kzalloc_obj(&client->dev, *og0ve1b); if (!og0ve1b) return -ENOMEM; diff --git a/drivers/media/i2c/os02g10.c b/drivers/media/i2c/os02g10.c index 141b7cb11fc5fc..0983214d41b95a 100644 --- a/drivers/media/i2c/os02g10.c +++ b/drivers/media/i2c/os02g10.c @@ -778,7 +778,7 @@ static int os02g10_probe(struct i2c_client *client) unsigned int xclk_freq; int ret; - os02g10 = devm_kzalloc(&client->dev, sizeof(*os02g10), GFP_KERNEL); + os02g10 = devm_kzalloc_obj(&client->dev, *os02g10); if (!os02g10) return -ENOMEM; diff --git a/drivers/media/i2c/os05b10.c b/drivers/media/i2c/os05b10.c index a46cfa513e9885..a281c61afcf0a2 100644 --- a/drivers/media/i2c/os05b10.c +++ b/drivers/media/i2c/os05b10.c @@ -977,7 +977,7 @@ static int os05b10_probe(struct i2c_client *client) unsigned int xclk_freq; int ret; - os05b10 = devm_kzalloc(&client->dev, sizeof(*os05b10), GFP_KERNEL); + os05b10 = devm_kzalloc_obj(&client->dev, *os05b10); if (!os05b10) return -ENOMEM; diff --git a/drivers/media/i2c/ov01a10.c b/drivers/media/i2c/ov01a10.c index b9a7dacd603ebd..46503e2f5a263a 100644 --- a/drivers/media/i2c/ov01a10.c +++ b/drivers/media/i2c/ov01a10.c @@ -1003,7 +1003,7 @@ static int ov01a10_probe(struct i2c_client *client) if (!cfg) return -EINVAL; - ov01a10 = devm_kzalloc(&client->dev, sizeof(*ov01a10), GFP_KERNEL); + ov01a10 = devm_kzalloc_obj(&client->dev, *ov01a10); if (!ov01a10) return -ENOMEM; diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c index 375cd52d61b914..5a61787adf3a19 100644 --- a/drivers/media/i2c/ov02a10.c +++ b/drivers/media/i2c/ov02a10.c @@ -859,7 +859,7 @@ static int ov02a10_probe(struct i2c_client *client) unsigned int rotation; int ret; - ov02a10 = devm_kzalloc(dev, sizeof(*ov02a10), GFP_KERNEL); + ov02a10 = devm_kzalloc_obj(dev, *ov02a10); if (!ov02a10) return -ENOMEM; diff --git a/drivers/media/i2c/ov02c10.c b/drivers/media/i2c/ov02c10.c index 8ffe0a07ef8542..296f09860dc5e2 100644 --- a/drivers/media/i2c/ov02c10.c +++ b/drivers/media/i2c/ov02c10.c @@ -881,7 +881,7 @@ static int ov02c10_probe(struct i2c_client *client) unsigned long freq; int ret; - ov02c10 = devm_kzalloc(&client->dev, sizeof(*ov02c10), GFP_KERNEL); + ov02c10 = devm_kzalloc_obj(&client->dev, *ov02c10); if (!ov02c10) return -ENOMEM; diff --git a/drivers/media/i2c/ov02e10.c b/drivers/media/i2c/ov02e10.c index 5c1e7013f55935..42dd818bb7af65 100644 --- a/drivers/media/i2c/ov02e10.c +++ b/drivers/media/i2c/ov02e10.c @@ -816,7 +816,7 @@ static int ov02e10_probe(struct i2c_client *client) unsigned long freq; int ret; - ov02e10 = devm_kzalloc(&client->dev, sizeof(*ov02e10), GFP_KERNEL); + ov02e10 = devm_kzalloc_obj(&client->dev, *ov02e10); if (!ov02e10) return -ENOMEM; diff --git a/drivers/media/i2c/ov05c10.c b/drivers/media/i2c/ov05c10.c index 8fe4dc0d9405ef..eecc65c4cef526 100644 --- a/drivers/media/i2c/ov05c10.c +++ b/drivers/media/i2c/ov05c10.c @@ -840,7 +840,7 @@ static int ov05c10_probe(struct i2c_client *client) bool full_power; int ret; - ov05c10 = devm_kzalloc(&client->dev, sizeof(*ov05c10), GFP_KERNEL); + ov05c10 = devm_kzalloc_obj(&client->dev, *ov05c10); if (!ov05c10) return -ENOMEM; diff --git a/drivers/media/i2c/ov08d10.c b/drivers/media/i2c/ov08d10.c index 0710d2243cc05c..ea4219d4c99259 100644 --- a/drivers/media/i2c/ov08d10.c +++ b/drivers/media/i2c/ov08d10.c @@ -1487,7 +1487,7 @@ static int ov08d10_probe(struct i2c_client *client) unsigned int i; int ret; - ov08d10 = devm_kzalloc(&client->dev, sizeof(*ov08d10), GFP_KERNEL); + ov08d10 = devm_kzalloc_obj(&client->dev, *ov08d10); if (!ov08d10) return -ENOMEM; diff --git a/drivers/media/i2c/ov08x40.c b/drivers/media/i2c/ov08x40.c index 6de0c17e633d82..69eedafe0dde7c 100644 --- a/drivers/media/i2c/ov08x40.c +++ b/drivers/media/i2c/ov08x40.c @@ -2280,7 +2280,7 @@ static int ov08x40_probe(struct i2c_client *client) int ret; bool full_power; - ov08x = devm_kzalloc(&client->dev, sizeof(*ov08x), GFP_KERNEL); + ov08x = devm_kzalloc_obj(&client->dev, *ov08x); if (!ov08x) return -ENOMEM; diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c index 5a49fa0ec02602..f3f12e8f00deb8 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -1712,7 +1712,7 @@ static int ov13858_probe(struct i2c_client *client) unsigned long freq; int ret; - ov13858 = devm_kzalloc(&client->dev, sizeof(*ov13858), GFP_KERNEL); + ov13858 = devm_kzalloc_obj(&client->dev, *ov13858); if (!ov13858) return -ENOMEM; diff --git a/drivers/media/i2c/ov13b10.c b/drivers/media/i2c/ov13b10.c index 242a9583412671..f639a70f60dc83 100644 --- a/drivers/media/i2c/ov13b10.c +++ b/drivers/media/i2c/ov13b10.c @@ -1592,7 +1592,7 @@ static int ov13b10_probe(struct i2c_client *client) bool full_power; int ret; - ov13b = devm_kzalloc(&client->dev, sizeof(*ov13b), GFP_KERNEL); + ov13b = devm_kzalloc_obj(&client->dev, *ov13b); if (!ov13b) return -ENOMEM; diff --git a/drivers/media/i2c/ov2640.c b/drivers/media/i2c/ov2640.c index 3dbefac6d305f0..4018222f10f864 100644 --- a/drivers/media/i2c/ov2640.c +++ b/drivers/media/i2c/ov2640.c @@ -1198,7 +1198,7 @@ static int ov2640_probe(struct i2c_client *client) return -EIO; } - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c index 5bc30e7b8325b0..64fb4d91414ce7 100644 --- a/drivers/media/i2c/ov2659.c +++ b/drivers/media/i2c/ov2659.c @@ -1400,7 +1400,7 @@ ov2659_get_pdata(struct i2c_client *client) goto done; } - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) goto done; @@ -1431,7 +1431,7 @@ static int ov2659_probe(struct i2c_client *client) return -EINVAL; } - ov2659 = devm_kzalloc(&client->dev, sizeof(*ov2659), GFP_KERNEL); + ov2659 = devm_kzalloc_obj(&client->dev, *ov2659); if (!ov2659) return -ENOMEM; diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 147862a813c578..49466b88120e33 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -1174,7 +1174,7 @@ static int ov2680_probe(struct i2c_client *client) struct ov2680_dev *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/ov2685.c b/drivers/media/i2c/ov2685.c index 162859a140ebfd..c59a923c3935f1 100644 --- a/drivers/media/i2c/ov2685.c +++ b/drivers/media/i2c/ov2685.c @@ -778,7 +778,7 @@ static int ov2685_probe(struct i2c_client *client) struct ov2685 *ov2685; int ret; - ov2685 = devm_kzalloc(dev, sizeof(*ov2685), GFP_KERNEL); + ov2685 = devm_kzalloc_obj(dev, *ov2685); if (!ov2685) return -ENOMEM; diff --git a/drivers/media/i2c/ov2732.c b/drivers/media/i2c/ov2732.c index 57dd0dd3fd85e3..999c618d0789fc 100644 --- a/drivers/media/i2c/ov2732.c +++ b/drivers/media/i2c/ov2732.c @@ -643,7 +643,7 @@ static int ov2732_probe(struct i2c_client *client) struct ov2732 *ov2732; int ret; - ov2732 = devm_kzalloc(&client->dev, sizeof(*ov2732), GFP_KERNEL); + ov2732 = devm_kzalloc_obj(&client->dev, *ov2732); if (!ov2732) return -ENOMEM; diff --git a/drivers/media/i2c/ov2735.c b/drivers/media/i2c/ov2735.c index 0361904c484185..42d48994ac13ea 100644 --- a/drivers/media/i2c/ov2735.c +++ b/drivers/media/i2c/ov2735.c @@ -950,7 +950,7 @@ static int ov2735_probe(struct i2c_client *client) unsigned int xclk_freq; int ret; - ov2735 = devm_kzalloc(&client->dev, sizeof(*ov2735), GFP_KERNEL); + ov2735 = devm_kzalloc_obj(&client->dev, *ov2735); if (!ov2735) return -ENOMEM; diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index 536325bb7b92c5..31513d1524a3d3 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -1268,7 +1268,7 @@ static int ov2740_register_nvmem(struct i2c_client *client, .size = CUSTOMER_USE_OTP_SIZE, }; - nvm = devm_kzalloc(dev, sizeof(*nvm), GFP_KERNEL); + nvm = devm_kzalloc_obj(dev, *nvm); if (!nvm) return -ENOMEM; @@ -1334,7 +1334,7 @@ static int ov2740_probe(struct i2c_client *client) unsigned int i; int ret; - ov2740 = devm_kzalloc(&client->dev, sizeof(*ov2740), GFP_KERNEL); + ov2740 = devm_kzalloc_obj(&client->dev, *ov2740); if (!ov2740) return -ENOMEM; diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 466b6f74d982aa..cec7dc67b2edca 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -901,7 +901,7 @@ static int ov4689_probe(struct i2c_client *client) if (ret) return ret; - ov4689 = devm_kzalloc(dev, sizeof(*ov4689), GFP_KERNEL); + ov4689 = devm_kzalloc_obj(dev, *ov4689); if (!ov4689) return -ENOMEM; diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index 22d08d0a90cf9f..f11c904c3bb5ae 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -3850,7 +3850,7 @@ static int ov5640_probe(struct i2c_client *client) struct ov5640_dev *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index a8d740ed4dc980..47da5cefb7f981 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -1018,7 +1018,7 @@ static int ov5645_probe(struct i2c_client *client) u32 xclk_freq; int ret; - ov5645 = devm_kzalloc(dev, sizeof(struct ov5645), GFP_KERNEL); + ov5645 = devm_kzalloc_obj(dev, struct ov5645); if (!ov5645) return -ENOMEM; diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c index e1120ca688283f..b9d69ee50a0e00 100644 --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c @@ -1163,7 +1163,7 @@ static int ov5647_probe(struct i2c_client *client) u32 xclk_freq; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/ov5648.c b/drivers/media/i2c/ov5648.c index 6a1efa12c38d99..bb06e66d28e0ee 100644 --- a/drivers/media/i2c/ov5648.c +++ b/drivers/media/i2c/ov5648.c @@ -2456,7 +2456,7 @@ static int ov5648_probe(struct i2c_client *client) unsigned long rate; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 940f21fe0dd35a..90352140e5fede 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -2650,7 +2650,7 @@ static int ov5670_probe(struct i2c_client *client) bool full_power; int ret; - ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); + ov5670 = devm_kzalloc_obj(&client->dev, *ov5670); if (!ov5670) return -ENOMEM; diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c index c5eb07576129b0..a86f7af7798d8f 100644 --- a/drivers/media/i2c/ov5675.c +++ b/drivers/media/i2c/ov5675.c @@ -1276,7 +1276,7 @@ static int ov5675_probe(struct i2c_client *client) bool full_power; int ret; - ov5675 = devm_kzalloc(&client->dev, sizeof(*ov5675), GFP_KERNEL); + ov5675 = devm_kzalloc_obj(&client->dev, *ov5675); if (!ov5675) return -ENOMEM; diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index 56599f9ca74ba2..496c3cb5870149 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -1298,7 +1298,7 @@ static int ov5693_probe(struct i2c_client *client) u32 xvclk_rate; int ret = 0; - ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL); + ov5693 = devm_kzalloc_obj(&client->dev, *ov5693); if (!ov5693) return -ENOMEM; diff --git a/drivers/media/i2c/ov5695.c b/drivers/media/i2c/ov5695.c index 5b23f04ab9f875..66cb56fbc367fb 100644 --- a/drivers/media/i2c/ov5695.c +++ b/drivers/media/i2c/ov5695.c @@ -1258,7 +1258,7 @@ static int ov5695_probe(struct i2c_client *client) struct v4l2_subdev *sd; int ret; - ov5695 = devm_kzalloc(dev, sizeof(*ov5695), GFP_KERNEL); + ov5695 = devm_kzalloc_obj(dev, *ov5695); if (!ov5695) return -ENOMEM; diff --git a/drivers/media/i2c/ov6211.c b/drivers/media/i2c/ov6211.c index 2ad31b2c5249c9..34d991eff347a0 100644 --- a/drivers/media/i2c/ov6211.c +++ b/drivers/media/i2c/ov6211.c @@ -659,7 +659,7 @@ static int ov6211_probe(struct i2c_client *client) unsigned int i; int ret; - ov6211 = devm_kzalloc(&client->dev, sizeof(*ov6211), GFP_KERNEL); + ov6211 = devm_kzalloc_obj(&client->dev, *ov6211); if (!ov6211) return -ENOMEM; diff --git a/drivers/media/i2c/ov64a40.c b/drivers/media/i2c/ov64a40.c index b369c002a25a56..6fa7070a969dd7 100644 --- a/drivers/media/i2c/ov64a40.c +++ b/drivers/media/i2c/ov64a40.c @@ -3534,7 +3534,7 @@ static int ov64a40_probe(struct i2c_client *client) u32 xclk_freq; int ret; - ov64a40 = devm_kzalloc(&client->dev, sizeof(*ov64a40), GFP_KERNEL); + ov64a40 = devm_kzalloc_obj(&client->dev, *ov64a40); if (!ov64a40) return -ENOMEM; diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index fce6344b512030..bd3927e3076ad3 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -1634,7 +1634,7 @@ static int ov7251_probe(struct i2c_client *client) int ret; int i; - ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL); + ov7251 = devm_kzalloc_obj(dev, struct ov7251); if (!ov7251) return -ENOMEM; diff --git a/drivers/media/i2c/ov7640.c b/drivers/media/i2c/ov7640.c index 0fd90bc67e29db..648fa145dc100f 100644 --- a/drivers/media/i2c/ov7640.c +++ b/drivers/media/i2c/ov7640.c @@ -50,7 +50,7 @@ static int ov7640_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&client->dev, *sd); if (sd == NULL) return -ENOMEM; v4l2_i2c_subdev_init(sd, client, &ov7640_ops); diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index 5a553d50f3a367..1ba53c1bea934d 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -1828,7 +1828,7 @@ static int ov7670_probe(struct i2c_client *client) struct ov7670_info *info; int ret; - info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, *info); if (info == NULL) return -ENOMEM; sd = &info->sd; diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index cb3f3f8138375a..83e6d20c52f89c 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -1445,7 +1445,7 @@ static int ov772x_probe(struct i2c_client *client) return -EINVAL; } - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c index c8a74ce39841d5..d1700d8109ea14 100644 --- a/drivers/media/i2c/ov7740.c +++ b/drivers/media/i2c/ov7740.c @@ -1033,7 +1033,7 @@ static int ov7740_probe(struct i2c_client *client) struct v4l2_subdev *sd; int ret; - ov7740 = devm_kzalloc(&client->dev, sizeof(*ov7740), GFP_KERNEL); + ov7740 = devm_kzalloc_obj(&client->dev, *ov7740); if (!ov7740) return -ENOMEM; diff --git a/drivers/media/i2c/ov8856.c b/drivers/media/i2c/ov8856.c index 42c4b9c4e380f3..1c879e461fa5d4 100644 --- a/drivers/media/i2c/ov8856.c +++ b/drivers/media/i2c/ov8856.c @@ -2376,7 +2376,7 @@ static int ov8856_probe(struct i2c_client *client) int ret; bool full_power; - ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL); + ov8856 = devm_kzalloc_obj(&client->dev, *ov8856); if (!ov8856) return -ENOMEM; diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c index 97448fa75a2630..72e63c9a1d1436 100644 --- a/drivers/media/i2c/ov8858.c +++ b/drivers/media/i2c/ov8858.c @@ -1874,7 +1874,7 @@ static int ov8858_probe(struct i2c_client *client) struct ov8858 *ov8858; int ret; - ov8858 = devm_kzalloc(dev, sizeof(*ov8858), GFP_KERNEL); + ov8858 = devm_kzalloc_obj(dev, *ov8858); if (!ov8858) return -ENOMEM; diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 5a59cca8eeae5f..c7dc97bf75f6b0 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -2966,7 +2966,7 @@ static int ov8865_probe(struct i2c_client *client) unsigned int i; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 3204e8d6080976..039a47c1918cb9 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -1285,7 +1285,7 @@ static int ov9282_probe(struct i2c_client *client) struct ov9282 *ov9282; int ret; - ov9282 = devm_kzalloc(&client->dev, sizeof(*ov9282), GFP_KERNEL); + ov9282 = devm_kzalloc_obj(&client->dev, *ov9282); if (!ov9282) return -ENOMEM; diff --git a/drivers/media/i2c/ov9640.c b/drivers/media/i2c/ov9640.c index d24b3be1e0b693..5584cff753966f 100644 --- a/drivers/media/i2c/ov9640.c +++ b/drivers/media/i2c/ov9640.c @@ -687,7 +687,7 @@ static int ov9640_probe(struct i2c_client *client) struct ov9640_priv *priv; int ret; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c index b596cfb2d7f350..34630a1555d730 100644 --- a/drivers/media/i2c/ov9650.c +++ b/drivers/media/i2c/ov9650.c @@ -1484,7 +1484,7 @@ static int ov965x_probe(struct i2c_client *client) .max_register = 0xab, }; - ov965x = devm_kzalloc(&client->dev, sizeof(*ov965x), GFP_KERNEL); + ov965x = devm_kzalloc_obj(&client->dev, *ov965x); if (!ov965x) return -ENOMEM; diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c index 8f39609ad1b647..ea6248cf3f906d 100644 --- a/drivers/media/i2c/ov9734.c +++ b/drivers/media/i2c/ov9734.c @@ -899,7 +899,7 @@ static int ov9734_probe(struct i2c_client *client) return ret; } - ov9734 = devm_kzalloc(&client->dev, sizeof(*ov9734), GFP_KERNEL); + ov9734 = devm_kzalloc_obj(&client->dev, *ov9734); if (!ov9734) return -ENOMEM; diff --git a/drivers/media/i2c/rdacm20.c b/drivers/media/i2c/rdacm20.c index 0179508626b5b8..f8fbb83bd8eb7a 100644 --- a/drivers/media/i2c/rdacm20.c +++ b/drivers/media/i2c/rdacm20.c @@ -568,7 +568,7 @@ static int rdacm20_probe(struct i2c_client *client) struct rdacm20_device *dev; int ret; - dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&client->dev, *dev); if (!dev) return -ENOMEM; dev->dev = &client->dev; diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c index 68d2b9d83c3c84..a365604f1e641b 100644 --- a/drivers/media/i2c/rdacm21.c +++ b/drivers/media/i2c/rdacm21.c @@ -544,7 +544,7 @@ static int rdacm21_probe(struct i2c_client *client) struct rdacm21_device *dev; int ret; - dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&client->dev, *dev); if (!dev) return -ENOMEM; dev->dev = &client->dev; diff --git a/drivers/media/i2c/rj54n1cb0c.c b/drivers/media/i2c/rj54n1cb0c.c index 211f890a9cbd21..f33d4ee548fc74 100644 --- a/drivers/media/i2c/rj54n1cb0c.c +++ b/drivers/media/i2c/rj54n1cb0c.c @@ -1318,7 +1318,7 @@ static int rj54n1_probe(struct i2c_client *client) return -EIO; } - rj54n1 = devm_kzalloc(&client->dev, sizeof(struct rj54n1), GFP_KERNEL); + rj54n1 = devm_kzalloc_obj(&client->dev, struct rj54n1); if (!rj54n1) return -ENOMEM; diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c index 680add1da244b4..fdbea5cff123a5 100644 --- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c +++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c @@ -1607,7 +1607,7 @@ static int s5c73m3_probe(struct i2c_client *client) struct s5c73m3 *state; int ret, i; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/s5k3m5.c b/drivers/media/i2c/s5k3m5.c index bdf5bea786850f..eb08a386c0e1eb 100644 --- a/drivers/media/i2c/s5k3m5.c +++ b/drivers/media/i2c/s5k3m5.c @@ -1220,7 +1220,7 @@ static int s5k3m5_probe(struct i2c_client *client) unsigned int i; int ret; - s5k3m5 = devm_kzalloc(&client->dev, sizeof(*s5k3m5), GFP_KERNEL); + s5k3m5 = devm_kzalloc_obj(&client->dev, *s5k3m5); if (!s5k3m5) return -ENOMEM; diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c index b13c4754ec3c40..9173590c5f4a83 100644 --- a/drivers/media/i2c/s5k5baf.c +++ b/drivers/media/i2c/s5k5baf.c @@ -362,7 +362,7 @@ static int s5k5baf_fw_parse(struct device *dev, struct s5k5baf_fw **fw, data += S5K5BAG_FW_TAG_LEN; count -= S5K5BAG_FW_TAG_LEN; - d = devm_kcalloc(dev, count, sizeof(u16), GFP_KERNEL); + d = devm_kzalloc_objs(dev, u16, count); if (!d) return -ENOMEM; @@ -1932,7 +1932,7 @@ static int s5k5baf_probe(struct i2c_client *c) struct s5k5baf *state; int ret; - state = devm_kzalloc(&c->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&c->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/s5k6a3.c b/drivers/media/i2c/s5k6a3.c index 071b31728a0053..1f83e26fc75ef8 100644 --- a/drivers/media/i2c/s5k6a3.c +++ b/drivers/media/i2c/s5k6a3.c @@ -280,7 +280,7 @@ static int s5k6a3_probe(struct i2c_client *client) struct v4l2_subdev *sd; int i, ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/s5kjn1.c b/drivers/media/i2c/s5kjn1.c index 80d713ba3a1ee3..3b4d052572ca34 100644 --- a/drivers/media/i2c/s5kjn1.c +++ b/drivers/media/i2c/s5kjn1.c @@ -1295,7 +1295,7 @@ static int s5kjn1_probe(struct i2c_client *client) unsigned long freq; int ret; - s5kjn1 = devm_kzalloc(&client->dev, sizeof(*s5kjn1), GFP_KERNEL); + s5kjn1 = devm_kzalloc_obj(&client->dev, *s5kjn1); if (!s5kjn1) return -ENOMEM; diff --git a/drivers/media/i2c/s5kjn5.c b/drivers/media/i2c/s5kjn5.c index 4709326a40171d..f4bdbf27e0e6d2 100644 --- a/drivers/media/i2c/s5kjn5.c +++ b/drivers/media/i2c/s5kjn5.c @@ -2749,7 +2749,7 @@ static int s5kjn5_probe(struct i2c_client *client) unsigned int i; int ret; - s5kjn5 = devm_kzalloc(dev, sizeof(*s5kjn5), GFP_KERNEL); + s5kjn5 = devm_kzalloc_obj(dev, *s5kjn5); if (!s5kjn5) return -ENOMEM; diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c index 56bfa3d2604b4c..0480dd3afd3074 100644 --- a/drivers/media/i2c/saa6588.c +++ b/drivers/media/i2c/saa6588.c @@ -455,7 +455,7 @@ static int saa6588_probe(struct i2c_client *client) v4l_info(client, "saa6588 found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - s = devm_kzalloc(&client->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&client->dev, *s); if (s == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/saa6752hs.c b/drivers/media/i2c/saa6752hs.c index 6e2a3e4a63f781..151d5275701912 100644 --- a/drivers/media/i2c/saa6752hs.c +++ b/drivers/media/i2c/saa6752hs.c @@ -669,7 +669,7 @@ static int saa6752hs_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - h = devm_kzalloc(&client->dev, sizeof(*h), GFP_KERNEL); + h = devm_kzalloc_obj(&client->dev, *h); if (h == NULL) return -ENOMEM; sd = &h->sd; diff --git a/drivers/media/i2c/saa7110.c b/drivers/media/i2c/saa7110.c index 652058b8f76600..419698d34beaad 100644 --- a/drivers/media/i2c/saa7110.c +++ b/drivers/media/i2c/saa7110.c @@ -372,7 +372,7 @@ static int saa7110_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (!decoder) return -ENOMEM; sd = &decoder->sd; diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c index 88b159418c7ce4..f4015f11367bea 100644 --- a/drivers/media/i2c/saa7115.c +++ b/drivers/media/i2c/saa7115.c @@ -1826,7 +1826,7 @@ static int saa711x_probe(struct i2c_client *client) strscpy(client->name, name, sizeof(client->name)); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c index fdf17f6fae6798..625f2e353d2d3c 100644 --- a/drivers/media/i2c/saa7127.c +++ b/drivers/media/i2c/saa7127.c @@ -722,7 +722,7 @@ static int saa7127_probe(struct i2c_client *client) v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", client->addr << 1); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/saa717x.c b/drivers/media/i2c/saa717x.c index 367539667948a7..09f153a97fe512 100644 --- a/drivers/media/i2c/saa717x.c +++ b/drivers/media/i2c/saa717x.c @@ -1241,7 +1241,7 @@ static int saa717x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (decoder == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/saa7185.c b/drivers/media/i2c/saa7185.c index 8e5c0eab907db3..a3884494df058b 100644 --- a/drivers/media/i2c/saa7185.c +++ b/drivers/media/i2c/saa7185.c @@ -303,7 +303,7 @@ static int saa7185_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); + encoder = devm_kzalloc_obj(&client->dev, *encoder); if (encoder == NULL) return -ENOMEM; encoder->norm = V4L2_STD_NTSC; diff --git a/drivers/media/i2c/sony-btf-mpx.c b/drivers/media/i2c/sony-btf-mpx.c index 4c87de0fe1f0ad..2384ff2ccb7661 100644 --- a/drivers/media/i2c/sony-btf-mpx.c +++ b/drivers/media/i2c/sony-btf-mpx.c @@ -342,7 +342,7 @@ static int sony_btf_mpx_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL); + t = devm_kzalloc_obj(&client->dev, *t); if (t == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c index f9eabd9632d3ec..3dad80410bf990 100644 --- a/drivers/media/i2c/st-mipid02.c +++ b/drivers/media/i2c/st-mipid02.c @@ -808,7 +808,7 @@ static int mipid02_probe(struct i2c_client *client) u32 clk_freq; int ret; - bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL); + bridge = devm_kzalloc_obj(dev, *bridge); if (!bridge) return -ENOMEM; diff --git a/drivers/media/i2c/t4ka3.c b/drivers/media/i2c/t4ka3.c index 6506225683bb07..a42ccb39848008 100644 --- a/drivers/media/i2c/t4ka3.c +++ b/drivers/media/i2c/t4ka3.c @@ -961,7 +961,7 @@ static int t4ka3_probe(struct i2c_client *client) int ret; /* allocate sensor device & init sub device */ - sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&client->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index d9cd0563d50b62..8590e024c85939 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -2185,8 +2185,7 @@ static int tc358743_probe(struct i2c_client *client) v4l_dbg(1, debug, client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(struct tc358743_state), - GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, struct tc358743_state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/tc358746.c b/drivers/media/i2c/tc358746.c index d55539c35a268e..91d26a63402301 100644 --- a/drivers/media/i2c/tc358746.c +++ b/drivers/media/i2c/tc358746.c @@ -1514,7 +1514,7 @@ static int tc358746_probe(struct i2c_client *client) unsigned int i; int err; - tc358746 = devm_kzalloc(&client->dev, sizeof(*tc358746), GFP_KERNEL); + tc358746 = devm_kzalloc_obj(&client->dev, *tc358746); if (!tc358746) return -ENOMEM; diff --git a/drivers/media/i2c/tda7432.c b/drivers/media/i2c/tda7432.c index a0b65a595ba826..9a0bdfd65f8e8d 100644 --- a/drivers/media/i2c/tda7432.c +++ b/drivers/media/i2c/tda7432.c @@ -351,7 +351,7 @@ static int tda7432_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL); + t = devm_kzalloc_obj(&client->dev, *t); if (!t) return -ENOMEM; sd = &t->sd; diff --git a/drivers/media/i2c/tda9840.c b/drivers/media/i2c/tda9840.c index b34d992777fbab..866182b3ce7726 100644 --- a/drivers/media/i2c/tda9840.c +++ b/drivers/media/i2c/tda9840.c @@ -162,7 +162,7 @@ static int tda9840_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&client->dev, *sd); if (sd == NULL) return -ENOMEM; v4l2_i2c_subdev_init(sd, client, &tda9840_ops); diff --git a/drivers/media/i2c/tea6415c.c b/drivers/media/i2c/tea6415c.c index ea7730a7ee2c1c..1a0ddc6f47b21d 100644 --- a/drivers/media/i2c/tea6415c.c +++ b/drivers/media/i2c/tea6415c.c @@ -126,7 +126,7 @@ static int tea6415c_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&client->dev, *sd); if (sd == NULL) return -ENOMEM; v4l2_i2c_subdev_init(sd, client, &tea6415c_ops); diff --git a/drivers/media/i2c/tea6420.c b/drivers/media/i2c/tea6420.c index bebb9a8095dbc3..149b382c264afb 100644 --- a/drivers/media/i2c/tea6420.c +++ b/drivers/media/i2c/tea6420.c @@ -99,7 +99,7 @@ static int tea6420_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&client->dev, *sd); if (sd == NULL) return -ENOMEM; v4l2_i2c_subdev_init(sd, client, &tea6420_ops); diff --git a/drivers/media/i2c/thp7312.c b/drivers/media/i2c/thp7312.c index f1c7f149c06c35..afe69058870f1a 100644 --- a/drivers/media/i2c/thp7312.c +++ b/drivers/media/i2c/thp7312.c @@ -2088,7 +2088,7 @@ static int thp7312_probe(struct i2c_client *client) struct thp7312_device *thp7312; int ret; - thp7312 = devm_kzalloc(dev, sizeof(*thp7312), GFP_KERNEL); + thp7312 = devm_kzalloc_obj(dev, *thp7312); if (!thp7312) return -ENOMEM; diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c index e04da5519a3964..b730db0c576df7 100644 --- a/drivers/media/i2c/ths7303.c +++ b/drivers/media/i2c/ths7303.c @@ -335,8 +335,7 @@ static int ths7303_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(struct ths7303_state), - GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, struct ths7303_state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/ths8200.c b/drivers/media/i2c/ths8200.c index 00535958faf183..9181c01c5968ae 100644 --- a/drivers/media/i2c/ths8200.c +++ b/drivers/media/i2c/ths8200.c @@ -440,7 +440,7 @@ static int ths8200_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/i2c/tlv320aic23b.c b/drivers/media/i2c/tlv320aic23b.c index 7deeef31771471..2406173c69a329 100644 --- a/drivers/media/i2c/tlv320aic23b.c +++ b/drivers/media/i2c/tlv320aic23b.c @@ -141,7 +141,7 @@ static int tlv320aic23b_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c index f136310b899d5a..e0e2e2718c5f76 100644 --- a/drivers/media/i2c/tvaudio.c +++ b/drivers/media/i2c/tvaudio.c @@ -1950,7 +1950,7 @@ static int tvaudio_probe(struct i2c_client *client) printk(KERN_CONT "\n"); } - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; sd = &chip->sd; diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c index 1e927896a4b3da..4ac3c6e4bfcb01 100644 --- a/drivers/media/i2c/tvp514x.c +++ b/drivers/media/i2c/tvp514x.c @@ -956,7 +956,7 @@ tvp514x_get_pdata(struct i2c_client *client) if (v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), &bus_cfg)) goto done; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) goto done; @@ -992,7 +992,7 @@ static int tvp514x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (!decoder) return -ENOMEM; diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c index 91064f06f8c1b3..c8896247e7bd8a 100644 --- a/drivers/media/i2c/tvp5150.c +++ b/drivers/media/i2c/tvp5150.c @@ -2131,7 +2131,7 @@ static int tvp5150_probe(struct i2c_client *c) if (res) return res; - core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(&c->dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c index ada28cb8af7cfb..e7fe17409058c9 100644 --- a/drivers/media/i2c/tvp7002.c +++ b/drivers/media/i2c/tvp7002.c @@ -911,7 +911,7 @@ tvp7002_get_pdata(struct i2c_client *client) if (v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), &bus_cfg)) goto done; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) goto done; @@ -967,7 +967,7 @@ static int tvp7002_probe(struct i2c_client *c) I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) return -EIO; - device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL); + device = devm_kzalloc_obj(&c->dev, struct tvp7002); if (!device) return -ENOMEM; diff --git a/drivers/media/i2c/tw2804.c b/drivers/media/i2c/tw2804.c index 713e078ff3dac5..a1b3887592d0b0 100644 --- a/drivers/media/i2c/tw2804.c +++ b/drivers/media/i2c/tw2804.c @@ -354,7 +354,7 @@ static int tw2804_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c index 60c102aba75035..51db5d5ddbdeca 100644 --- a/drivers/media/i2c/tw9900.c +++ b/drivers/media/i2c/tw9900.c @@ -658,7 +658,7 @@ static int tw9900_probe(struct i2c_client *client) struct tw9900 *tw9900; int ret = 0; - tw9900 = devm_kzalloc(dev, sizeof(*tw9900), GFP_KERNEL); + tw9900 = devm_kzalloc_obj(dev, *tw9900); if (!tw9900) return -ENOMEM; diff --git a/drivers/media/i2c/tw9903.c b/drivers/media/i2c/tw9903.c index db063b885b09c8..d18ee453659f2d 100644 --- a/drivers/media/i2c/tw9903.c +++ b/drivers/media/i2c/tw9903.c @@ -202,7 +202,7 @@ static int tw9903_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - dec = devm_kzalloc(&client->dev, sizeof(*dec), GFP_KERNEL); + dec = devm_kzalloc_obj(&client->dev, *dec); if (dec == NULL) return -ENOMEM; sd = &dec->sd; diff --git a/drivers/media/i2c/tw9906.c b/drivers/media/i2c/tw9906.c index 079e2f49f38f30..e717a2ed799820 100644 --- a/drivers/media/i2c/tw9906.c +++ b/drivers/media/i2c/tw9906.c @@ -170,7 +170,7 @@ static int tw9906_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - dec = devm_kzalloc(&client->dev, sizeof(*dec), GFP_KERNEL); + dec = devm_kzalloc_obj(&client->dev, *dec); if (dec == NULL) return -ENOMEM; sd = &dec->sd; diff --git a/drivers/media/i2c/tw9910.c b/drivers/media/i2c/tw9910.c index 731c97a40c82fb..34f82b4bf7553e 100644 --- a/drivers/media/i2c/tw9910.c +++ b/drivers/media/i2c/tw9910.c @@ -944,7 +944,7 @@ static int tw9910_probe(struct i2c_client *client) return -EIO; } - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/i2c/uda1342.c b/drivers/media/i2c/uda1342.c index 437726788ba02a..9604d096cc6307 100644 --- a/drivers/media/i2c/uda1342.c +++ b/drivers/media/i2c/uda1342.c @@ -56,7 +56,7 @@ static int uda1342_probe(struct i2c_client *client) dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n", client->addr, adapter->name); - sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL); + sd = devm_kzalloc_obj(&client->dev, *sd); if (sd == NULL) return -ENOMEM; diff --git a/drivers/media/i2c/upd64031a.c b/drivers/media/i2c/upd64031a.c index 670118c168724c..68b2694e163228 100644 --- a/drivers/media/i2c/upd64031a.c +++ b/drivers/media/i2c/upd64031a.c @@ -195,7 +195,7 @@ static int upd64031a_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/upd64083.c b/drivers/media/i2c/upd64083.c index e610dffa9e10dd..d378479698b619 100644 --- a/drivers/media/i2c/upd64083.c +++ b/drivers/media/i2c/upd64083.c @@ -166,7 +166,7 @@ static int upd64083_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/vd55g1.c b/drivers/media/i2c/vd55g1.c index e3939bb9bd4454..3a3ce32b0610eb 100644 --- a/drivers/media/i2c/vd55g1.c +++ b/drivers/media/i2c/vd55g1.c @@ -1984,7 +1984,7 @@ static int vd55g1_probe(struct i2c_client *client) struct vd55g1 *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; sensor->dev = &client->dev; diff --git a/drivers/media/i2c/vd56g3.c b/drivers/media/i2c/vd56g3.c index ca0dd1b2407274..a42210d0ab8d54 100644 --- a/drivers/media/i2c/vd56g3.c +++ b/drivers/media/i2c/vd56g3.c @@ -1457,7 +1457,7 @@ static int vd56g3_probe(struct i2c_client *client) struct vd56g3 *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/vgxy61.c b/drivers/media/i2c/vgxy61.c index e7819691723dcf..c1eefc0827b9db 100644 --- a/drivers/media/i2c/vgxy61.c +++ b/drivers/media/i2c/vgxy61.c @@ -1746,7 +1746,7 @@ static int vgxy61_probe(struct i2c_client *client) struct vgxy61_dev *sensor; int ret; - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/media/i2c/vp27smpx.c b/drivers/media/i2c/vp27smpx.c index 21fcfdd4c1630e..a1991caead03c2 100644 --- a/drivers/media/i2c/vp27smpx.c +++ b/drivers/media/i2c/vp27smpx.c @@ -150,7 +150,7 @@ static int vp27smpx_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/vpx3220.c b/drivers/media/i2c/vpx3220.c index 29bcbb5a5fbbe5..5434c9bfd4b974 100644 --- a/drivers/media/i2c/vpx3220.c +++ b/drivers/media/i2c/vpx3220.c @@ -469,7 +469,7 @@ static int vpx3220_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; - decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); + decoder = devm_kzalloc_obj(&client->dev, *decoder); if (decoder == NULL) return -ENOMEM; sd = &decoder->sd; diff --git a/drivers/media/i2c/wm8739.c b/drivers/media/i2c/wm8739.c index 9eaf48f1c3a2c1..b864048f89f578 100644 --- a/drivers/media/i2c/wm8739.c +++ b/drivers/media/i2c/wm8739.c @@ -190,7 +190,7 @@ static int wm8739_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c index 5db197bb6fdaa0..6179e7275bb1a0 100644 --- a/drivers/media/i2c/wm8775.c +++ b/drivers/media/i2c/wm8775.c @@ -209,7 +209,7 @@ static int wm8775_probe(struct i2c_client *client) v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); - state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&client->dev, *state); if (state == NULL) return -ENOMEM; sd = &state->sd; diff --git a/drivers/media/pci/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c index 660aab6b62e0cb..b6ff0a60861c93 100644 --- a/drivers/media/pci/dt3155/dt3155.c +++ b/drivers/media/pci/dt3155/dt3155.c @@ -491,7 +491,7 @@ static int dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id) err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (err) return -ENODEV; - pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(&pdev->dev, *pd); if (!pd) return -ENOMEM; diff --git a/drivers/media/pci/hws/hws_pci.c b/drivers/media/pci/hws/hws_pci.c index f06e60dc2ee618..89fb7ed8550434 100644 --- a/drivers/media/pci/hws/hws_pci.c +++ b/drivers/media/pci/hws/hws_pci.c @@ -394,7 +394,7 @@ static int hws_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) bool v4l2_registered = false; /* devres-backed device object */ - hws = devm_kzalloc(&pdev->dev, sizeof(*hws), GFP_KERNEL); + hws = devm_kzalloc_obj(&pdev->dev, *hws); if (!hws) return -ENOMEM; diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 4d2b231291f562..ce8e22a2ef6d66 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -1671,7 +1671,7 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, if (r) return r; - cio2 = devm_kzalloc(dev, sizeof(*cio2), GFP_KERNEL); + cio2 = devm_kzalloc_obj(dev, *cio2); if (!cio2) return -ENOMEM; cio2->pci_dev = pci_dev; diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c index 60070842ee68fd..6065e2c8279444 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c @@ -350,8 +350,8 @@ int ipu6_isys_subdev_init(struct ipu6_isys_subdev *asd, asd->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; asd->sd.internal_ops = &ipu6_isys_subdev_internal_ops; - asd->pad = devm_kcalloc(&asd->isys->adev->auxdev.dev, num_pads, - sizeof(*asd->pad), GFP_KERNEL); + asd->pad = devm_kzalloc_objs(&asd->isys->adev->auxdev.dev, *asd->pad, + num_pads); if (!asd->pad) return -ENOMEM; diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c b/drivers/media/pci/intel/ipu6/ipu6-isys.c index 094a98e31c0687..ff8c7f5b60777d 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-isys.c +++ b/drivers/media/pci/intel/ipu6/ipu6-isys.c @@ -987,7 +987,7 @@ static int isys_probe(struct auxiliary_device *auxdev, if (!isp->bus_ready_to_probe) return -EPROBE_DEFER; - isys = devm_kzalloc(&auxdev->dev, sizeof(*isys), GFP_KERNEL); + isys = devm_kzalloc_obj(&auxdev->dev, *isys); if (!isys) return -ENOMEM; @@ -998,8 +998,8 @@ static int isys_probe(struct auxiliary_device *auxdev, isys->pdata = adev->pdata; csi2_pdata = &isys->pdata->ipdata->csi2; - isys->csi2 = devm_kcalloc(&auxdev->dev, csi2_pdata->nports, - sizeof(*isys->csi2), GFP_KERNEL); + isys->csi2 = devm_kzalloc_objs(&auxdev->dev, *isys->csi2, + csi2_pdata->nports); if (!isys->csi2) return -ENOMEM; diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu-hw.c b/drivers/media/pci/intel/ipu6/ipu6-mmu-hw.c index 2b395fbd596917..5a44c67ad7a0ef 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-mmu-hw.c +++ b/drivers/media/pci/intel/ipu6/ipu6-mmu-hw.c @@ -270,7 +270,7 @@ static int __ipu6_mmu_init_hw_data(struct ipu6_mmu *mmu, struct device *dev, src = lookup->hwdata; nr_mmus = lookup->nr_mmus; - mmu_hw = devm_kcalloc(dev, nr_mmus, sizeof(*mmu_hw), GFP_KERNEL); + mmu_hw = devm_kzalloc_objs(dev, *mmu_hw, nr_mmus); if (!mmu_hw) return -ENOMEM; diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.c b/drivers/media/pci/intel/ipu6/ipu6-mmu.c index 1a564ceb747820..b9bc794759c5cb 100644 --- a/drivers/media/pci/intel/ipu6/ipu6-mmu.c +++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c @@ -680,7 +680,7 @@ struct ipu6_mmu *ipu6_mmu_init(struct device *dev, struct ipu6_mmu *mmu; int ret; - mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL); + mmu = devm_kzalloc_obj(dev, *mmu); if (!mmu) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c index cdf812c02960bf..09e6d2a4e2a06f 100644 --- a/drivers/media/pci/intel/ipu6/ipu6.c +++ b/drivers/media/pci/intel/ipu6/ipu6.c @@ -649,7 +649,7 @@ static int ipu6_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) id->device == PCI_DEVICE_ID_INTEL_IPU7P5) && force_no_probe_ipu7) return -ENODEV; - isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/media/pci/intel/ipu6/ipu7-mmu-hw.c b/drivers/media/pci/intel/ipu6/ipu7-mmu-hw.c index d991f4d29e364b..6e7939840e949e 100644 --- a/drivers/media/pci/intel/ipu6/ipu7-mmu-hw.c +++ b/drivers/media/pci/intel/ipu6/ipu7-mmu-hw.c @@ -1088,7 +1088,7 @@ static int __ipu7_mmu_init_hw_data(struct ipu6_mmu *mmu, struct device *dev, src = lookup[mmu->mmid].hwdata; nr_mmus = lookup[mmu->mmid].nr_mmus; - mmu_hw = devm_kcalloc(dev, nr_mmus, sizeof(*mmu_hw), GFP_KERNEL); + mmu_hw = devm_kzalloc_objs(dev, *mmu_hw, nr_mmus); if (!mmu_hw) return -ENOMEM; diff --git a/drivers/media/pci/intel/ivsc/mei_ace.c b/drivers/media/pci/intel/ivsc/mei_ace.c index bb57656fc85a39..45baa593f73fff 100644 --- a/drivers/media/pci/intel/ivsc/mei_ace.c +++ b/drivers/media/pci/intel/ivsc/mei_ace.c @@ -463,7 +463,7 @@ static int mei_ace_probe(struct mei_cl_device *cldev, struct mei_ace *ace; int ret; - ace = devm_kzalloc(dev, sizeof(struct mei_ace), GFP_KERNEL); + ace = devm_kzalloc_obj(dev, struct mei_ace); if (!ace) return -ENOMEM; diff --git a/drivers/media/pci/intel/ivsc/mei_csi.c b/drivers/media/pci/intel/ivsc/mei_csi.c index 005b1414a252c3..4d509c08723df5 100644 --- a/drivers/media/pci/intel/ivsc/mei_csi.c +++ b/drivers/media/pci/intel/ivsc/mei_csi.c @@ -659,7 +659,7 @@ static int mei_csi_probe(struct mei_cl_device *cldev, return -ENXIO; } - csi = devm_kzalloc(dev, sizeof(struct mei_csi), GFP_KERNEL); + csi = devm_kzalloc_obj(dev, struct mei_csi); if (!csi) return -ENOMEM; diff --git a/drivers/media/pci/pt3/pt3.c b/drivers/media/pci/pt3/pt3.c index 753161889092c6..838370d453b80a 100644 --- a/drivers/media/pci/pt3/pt3.c +++ b/drivers/media/pci/pt3/pt3.c @@ -710,7 +710,7 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return ret; } - pt3 = devm_kzalloc(&pdev->dev, sizeof(*pt3), GFP_KERNEL); + pt3 = devm_kzalloc_obj(&pdev->dev, *pt3); if (!pt3) return -ENOMEM; pci_set_drvdata(pdev, pt3); @@ -736,7 +736,7 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pt3->num_bufs = clamp_val(num_bufs, MIN_DATA_BUFS, MAX_DATA_BUFS); - pt3->i2c_buf = devm_kmalloc(&pdev->dev, sizeof(*pt3->i2c_buf), GFP_KERNEL); + pt3->i2c_buf = devm_kmalloc_obj(&pdev->dev, *pt3->i2c_buf); if (!pt3->i2c_buf) return -ENOMEM; i2c = &pt3->i2c_adap; diff --git a/drivers/media/pci/tw5864/tw5864-core.c b/drivers/media/pci/tw5864/tw5864-core.c index 6ec8bce4ac4fef..7e38900f71c34f 100644 --- a/drivers/media/pci/tw5864/tw5864-core.c +++ b/drivers/media/pci/tw5864/tw5864-core.c @@ -244,7 +244,7 @@ static int tw5864_initdev(struct pci_dev *pci_dev, struct tw5864_dev *dev; int err; - dev = devm_kzalloc(&pci_dev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pci_dev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c index 0909b2d9fcdd12..1263e26eced051 100644 --- a/drivers/media/pci/tw68/tw68-core.c +++ b/drivers/media/pci/tw68/tw68-core.c @@ -215,7 +215,7 @@ static int tw68_initdev(struct pci_dev *pci_dev, int vidnr = -1; int err; - dev = devm_kzalloc(&pci_dev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pci_dev->dev, *dev); if (NULL == dev) return -ENOMEM; diff --git a/drivers/media/pci/zoran/zoran_card.c b/drivers/media/pci/zoran/zoran_card.c index e5ff407318dfab..51a2de288107fa 100644 --- a/drivers/media/pci/zoran/zoran_card.c +++ b/drivers/media/pci/zoran/zoran_card.c @@ -1111,7 +1111,7 @@ static struct videocodec_master *zoran_setup_videocodec(struct zoran *zr, { struct videocodec_master *m = NULL; - m = devm_kmalloc(&zr->pci_dev->dev, sizeof(*m), GFP_KERNEL); + m = devm_kmalloc_obj(&zr->pci_dev->dev, *m); if (!m) return m; @@ -1249,7 +1249,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -ENOENT; } - zr = devm_kzalloc(&pdev->dev, sizeof(*zr), GFP_KERNEL); + zr = devm_kzalloc_obj(&pdev->dev, *zr); if (!zr) return -ENOMEM; diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c index 4f3299a66b37d5..dc76986ce48d72 100644 --- a/drivers/media/platform/allegro-dvt/allegro-core.c +++ b/drivers/media/platform/allegro-dvt/allegro-core.c @@ -802,7 +802,7 @@ static struct allegro_mbox *allegro_mbox_init(struct allegro_dev *dev, { struct allegro_mbox *mbox; - mbox = devm_kmalloc(&dev->plat_dev->dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kmalloc_obj(&dev->plat_dev->dev, *mbox); if (!mbox) return ERR_PTR(-ENOMEM); @@ -3895,7 +3895,7 @@ static int allegro_probe(struct platform_device *pdev) int irq; void __iomem *regs, *sram_regs; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; dev->plat_dev = pdev; diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platform/amd/isp4/isp4.c index bf6b8e26c2c0fb..e423861a06691a 100644 --- a/drivers/media/platform/amd/isp4/isp4.c +++ b/drivers/media/platform/amd/isp4/isp4.c @@ -123,7 +123,7 @@ static int isp4_capture_probe(struct platform_device *pdev) struct isp4_device *isp_dev; int ret; - isp_dev = devm_kzalloc(dev, sizeof(*isp_dev), GFP_KERNEL); + isp_dev = devm_kzalloc_obj(dev, *isp_dev); if (!isp_dev) return -ENOMEM; diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-dev.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-dev.c index c3b779f6308801..750dc43e5efc4a 100644 --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-dev.c +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-dev.c @@ -315,7 +315,7 @@ static int c3_isp_probe(struct platform_device *pdev) int irq; int ret; - isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/media/platform/amlogic/c3/mipi-adapter/c3-mipi-adap.c b/drivers/media/platform/amlogic/c3/mipi-adapter/c3-mipi-adap.c index 6f75112723b542..1ffb54221b5a18 100644 --- a/drivers/media/platform/amlogic/c3/mipi-adapter/c3-mipi-adap.c +++ b/drivers/media/platform/amlogic/c3/mipi-adapter/c3-mipi-adap.c @@ -766,7 +766,7 @@ static int c3_mipi_adap_probe(struct platform_device *pdev) struct c3_adap_device *adap; int ret; - adap = devm_kzalloc(dev, sizeof(*adap), GFP_KERNEL); + adap = devm_kzalloc_obj(dev, *adap); if (!adap) return -ENOMEM; diff --git a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c index 0c399665f7faf0..b5e59e810e136f 100644 --- a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c +++ b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c @@ -751,7 +751,7 @@ static int c3_mipi_csi_probe(struct platform_device *pdev) struct c3_csi_device *csi; int ret; - csi = devm_kzalloc(dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(dev, *csi); if (!csi) return -ENOMEM; diff --git a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c index c5dc03905ce0f9..53fc70385b5771 100644 --- a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c +++ b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c @@ -925,7 +925,7 @@ static int ge2d_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ge2d = devm_kzalloc(&pdev->dev, sizeof(*ge2d), GFP_KERNEL); + ge2d = devm_kzalloc_obj(&pdev->dev, *ge2d); if (!ge2d) return -ENOMEM; diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c index ad54f014d8f605..fc66569426d137 100644 --- a/drivers/media/platform/amphion/vpu_core.c +++ b/drivers/media/platform/amphion/vpu_core.c @@ -601,7 +601,7 @@ static int vpu_core_probe(struct platform_device *pdev) dev_dbg(dev, "probe\n"); if (!vpu) return -EINVAL; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; @@ -644,7 +644,7 @@ static int vpu_core_probe(struct platform_device *pdev) if (ret) return ret; - iface = devm_kzalloc(dev, sizeof(*iface), GFP_KERNEL); + iface = devm_kzalloc_obj(dev, *iface); if (!iface) return -ENOMEM; diff --git a/drivers/media/platform/amphion/vpu_drv.c b/drivers/media/platform/amphion/vpu_drv.c index 9c6f32c5eae965..e3de5e9d503ec6 100644 --- a/drivers/media/platform/amphion/vpu_drv.c +++ b/drivers/media/platform/amphion/vpu_drv.c @@ -90,7 +90,7 @@ static int vpu_probe(struct platform_device *pdev) int ret; dev_dbg(dev, "probe\n"); - vpu = devm_kzalloc(dev, sizeof(*vpu), GFP_KERNEL); + vpu = devm_kzalloc_obj(dev, *vpu); if (!vpu) return -ENOMEM; diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c index 241a625f7284ed..b9bc41d863fa00 100644 --- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c +++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c @@ -785,7 +785,7 @@ static int mali_c55_probe(struct platform_device *pdev) struct resource *res; int ret; - mali_c55 = devm_kzalloc(dev, sizeof(*mali_c55), GFP_KERNEL); + mali_c55 = devm_kzalloc_obj(dev, *mali_c55); if (!mali_c55) return -ENOMEM; diff --git a/drivers/media/platform/aspeed/aspeed-video.c b/drivers/media/platform/aspeed/aspeed-video.c index 7ba9314fdbd2a6..95bb3b75d2f22b 100644 --- a/drivers/media/platform/aspeed/aspeed-video.c +++ b/drivers/media/platform/aspeed/aspeed-video.c @@ -2310,7 +2310,7 @@ static int aspeed_video_probe(struct platform_device *pdev) struct aspeed_video *video; int rc; - video = devm_kzalloc(&pdev->dev, sizeof(*video), GFP_KERNEL); + video = devm_kzalloc_obj(&pdev->dev, *video); if (!video) return -ENOMEM; diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c index fa33d11f736fcd..08c65f68cd1eda 100644 --- a/drivers/media/platform/atmel/atmel-isi.c +++ b/drivers/media/platform/atmel/atmel-isi.c @@ -1189,7 +1189,7 @@ static int atmel_isi_probe(struct platform_device *pdev) struct vb2_queue *q; int ret, i; - isi = devm_kzalloc(&pdev->dev, sizeof(struct atmel_isi), GFP_KERNEL); + isi = devm_kzalloc_obj(&pdev->dev, struct atmel_isi); if (!isi) return -ENOMEM; diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c index be37ea568bfe55..3fe33c4dc6ea72 100644 --- a/drivers/media/platform/chips-media/coda/coda-common.c +++ b/drivers/media/platform/chips-media/coda/coda-common.c @@ -3149,7 +3149,7 @@ static int coda_probe(struct platform_device *pdev) struct coda_dev *dev; int ret, irq; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/chips-media/coda/imx-vdoa.c b/drivers/media/platform/chips-media/coda/imx-vdoa.c index cd085c1c73f42a..2113995e9680f5 100644 --- a/drivers/media/platform/chips-media/coda/imx-vdoa.c +++ b/drivers/media/platform/chips-media/coda/imx-vdoa.c @@ -291,7 +291,7 @@ static int vdoa_probe(struct platform_device *pdev) return ret; } - vdoa = devm_kzalloc(&pdev->dev, sizeof(*vdoa), GFP_KERNEL); + vdoa = devm_kzalloc_obj(&pdev->dev, *vdoa); if (!vdoa) return -ENOMEM; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c index 86bc36ee17fd6b..180aac74884e37 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c @@ -2028,7 +2028,7 @@ int wave5_vpu_dec_register_device(struct vpu_device *dev) if (dev->product_code == WAVE515_CODE) wave5_vdi_allocate_sram(dev); - vdev_dec = devm_kzalloc(dev->v4l2_dev.dev, sizeof(*vdev_dec), GFP_KERNEL); + vdev_dec = devm_kzalloc_obj(dev->v4l2_dev.dev, *vdev_dec); if (!vdev_dec) return -ENOMEM; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c index f9fcdf4c224b30..34ec681feb166c 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c @@ -1831,7 +1831,7 @@ int wave5_vpu_enc_register_device(struct vpu_device *dev) struct video_device *vdev_enc; int ret; - vdev_enc = devm_kzalloc(dev->v4l2_dev.dev, sizeof(*vdev_enc), GFP_KERNEL); + vdev_enc = devm_kzalloc_obj(dev->v4l2_dev.dev, *vdev_enc); if (!vdev_enc) return -ENOMEM; diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 37df270b5f991c..c1757452efb5f1 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -278,7 +278,7 @@ static int wave5_vpu_probe(struct platform_device *pdev) return ret; } - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/imagination/e5010-jpeg-enc.c b/drivers/media/platform/imagination/e5010-jpeg-enc.c index 420cb8bfdb12a3..09fc94797aaa5a 100644 --- a/drivers/media/platform/imagination/e5010-jpeg-enc.c +++ b/drivers/media/platform/imagination/e5010-jpeg-enc.c @@ -1024,7 +1024,7 @@ static int e5010_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "32-bit consistent DMA enable failed\n"); - e5010 = devm_kzalloc(dev, sizeof(*e5010), GFP_KERNEL); + e5010 = devm_kzalloc_obj(dev, *e5010); if (!e5010) return -ENOMEM; diff --git a/drivers/media/platform/intel/pxa_camera.c b/drivers/media/platform/intel/pxa_camera.c index 9e1fdd963b5599..982fc696bf8dfd 100644 --- a/drivers/media/platform/intel/pxa_camera.c +++ b/drivers/media/platform/intel/pxa_camera.c @@ -2277,7 +2277,7 @@ static int pxa_camera_probe(struct platform_device *pdev) if (irq < 0) return -ENODEV; - pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); + pcdev = devm_kzalloc_obj(&pdev->dev, *pcdev); if (!pcdev) { dev_err(&pdev->dev, "Could not allocate pcdev\n"); return -ENOMEM; diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c index 6b070186148947..878733a9e3b220 100644 --- a/drivers/media/platform/m2m-deinterlace.c +++ b/drivers/media/platform/m2m-deinterlace.c @@ -913,7 +913,7 @@ static int deinterlace_probe(struct platform_device *pdev) dma_cap_mask_t mask; int ret = 0; - pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); + pcdev = devm_kzalloc_obj(&pdev->dev, *pcdev); if (!pcdev) return -ENOMEM; diff --git a/drivers/media/platform/marvell/mmp-driver.c b/drivers/media/platform/marvell/mmp-driver.c index 4c31b62751a12a..9ac393fd18755b 100644 --- a/drivers/media/platform/marvell/mmp-driver.c +++ b/drivers/media/platform/marvell/mmp-driver.c @@ -185,7 +185,7 @@ static int mmpcam_probe(struct platform_device *pdev) struct v4l2_async_connection *asd; int ret; - cam = devm_kzalloc(&pdev->dev, sizeof(*cam), GFP_KERNEL); + cam = devm_kzalloc_obj(&pdev->dev, *cam); if (cam == NULL) return -ENOMEM; platform_set_drvdata(pdev, cam); diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index deb515641521ca..e01dd4d80722c9 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -1296,7 +1296,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev) int num_child = 0; int ret; - jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL); + jpeg = devm_kzalloc_obj(&pdev->dev, *jpeg); if (!jpeg) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c index 32372781daf577..74df7fbad257dc 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c @@ -629,7 +629,7 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev) if (!master_dev) return -EPROBE_DEFER; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c index b312a15d707b22..cbea791e632681 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c @@ -352,7 +352,7 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) if (!master_dev) return -EPROBE_DEFER; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c index 8432833814f319..c065cdede7b02e 100644 --- a/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c @@ -110,7 +110,7 @@ static int mtk_mdp_probe(struct platform_device *pdev) struct mtk_mdp_comp *comp, *comp_temp; int ret = 0; - mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL); + mdp = devm_kzalloc_obj(dev, *mdp); if (!mdp) return -ENOMEM; @@ -149,7 +149,7 @@ static int mtk_mdp_probe(struct platform_device *pdev) comp_type = (uintptr_t)of_id->data; - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc_obj(dev, *comp); if (!comp) { ret = -ENOMEM; of_node_put(node); diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c index acb2758a7b42df..5b0d71ee64e8b9 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c @@ -1826,7 +1826,7 @@ static struct mdp_comp *mdp_comp_create(struct mdp_dev *mdp, if (mdp->comp[id]) return ERR_PTR(-EEXIST); - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc_obj(dev, *comp); if (!comp) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c index 1b0bc47355c05f..0e7d832d40717d 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c @@ -78,7 +78,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use return ERR_PTR(-EPROBE_DEFER); } - fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(&plat_dev->dev, *fw); if (!fw) { scp_put(scp); return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c index 3632037f78f505..281dba2ed928c2 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c @@ -118,7 +118,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use else vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_enc_handler, priv, rst_id); - fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(&plat_dev->dev, *fw); if (!fw) { put_device(&fw_pdev->dev); return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c index 426d060d937c16..b4648ff6d818b4 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c @@ -359,7 +359,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) enum mtk_vcodec_fw_type fw_type; int i, ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c index 881d5de41e0501..fa0e13145252bd 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c @@ -137,7 +137,7 @@ static int mtk_vdec_hw_probe(struct platform_device *pdev) return -EINVAL; } - subdev_dev = devm_kzalloc(dev, sizeof(*subdev_dev), GFP_KERNEL); + subdev_dev = devm_kzalloc_obj(dev, *subdev_dev); if (!subdev_dev) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c index f6f03c61c643f9..081a66efb81498 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c @@ -24,9 +24,8 @@ int mtk_vcodec_init_dec_clk(struct platform_device *pdev, struct mtk_vcodec_pm * dec_clk->clk_num = of_property_count_strings(pdev->dev.of_node, "clock-names"); if (dec_clk->clk_num > 0) { - dec_clk->clk_info = devm_kcalloc(&pdev->dev, - dec_clk->clk_num, sizeof(*clk_info), - GFP_KERNEL); + dec_clk->clk_info = devm_kzalloc_objs(&pdev->dev, *clk_info, + dec_clk->clk_num); if (!dec_clk->clk_info) return -ENOMEM; } else { diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c index 4e4541b2fc8eae..3b8bb1f2118d6b 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c @@ -249,7 +249,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) enum mtk_vcodec_fw_type fw_type; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c index edf9133c06730b..ad498d44a76330 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c @@ -28,9 +28,8 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *mtkdev) enc_clk->clk_num = of_property_count_strings(pdev->dev.of_node, "clock-names"); if (enc_clk->clk_num > 0) { - enc_clk->clk_info = devm_kcalloc(&pdev->dev, - enc_clk->clk_num, sizeof(*clk_info), - GFP_KERNEL); + enc_clk->clk_info = devm_kzalloc_objs(&pdev->dev, *clk_info, + enc_clk->clk_num); if (!enc_clk->clk_info) return -ENOMEM; } else { diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.c b/drivers/media/platform/mediatek/vpu/mtk_vpu.c index 437ad492374fbf..5db903c2887807 100644 --- a/drivers/media/platform/mediatek/vpu/mtk_vpu.c +++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.c @@ -817,7 +817,7 @@ static int mtk_vpu_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "initialization\n"); dev = &pdev->dev; - vpu = devm_kzalloc(dev, sizeof(*vpu), GFP_KERNEL); + vpu = devm_kzalloc_obj(dev, *vpu); if (!vpu) return -ENOMEM; diff --git a/drivers/media/platform/microchip/microchip-csi2dc.c b/drivers/media/platform/microchip/microchip-csi2dc.c index 0368f3e80c0c44..31c06b63902a3b 100644 --- a/drivers/media/platform/microchip/microchip-csi2dc.c +++ b/drivers/media/platform/microchip/microchip-csi2dc.c @@ -653,7 +653,7 @@ static int csi2dc_probe(struct platform_device *pdev) int ret = 0; u32 ver; - csi2dc = devm_kzalloc(dev, sizeof(*csi2dc), GFP_KERNEL); + csi2dc = devm_kzalloc_obj(dev, *csi2dc); if (!csi2dc) return -ENOMEM; diff --git a/drivers/media/platform/microchip/microchip-sama5d2-isc.c b/drivers/media/platform/microchip/microchip-sama5d2-isc.c index 5e41eee45dbd7b..1d029b2dbe063c 100644 --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -373,8 +373,7 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc) goto err_cleanup; } - subdev_entity = devm_kzalloc(dev, sizeof(*subdev_entity), - GFP_KERNEL); + subdev_entity = devm_kzalloc_obj(dev, *subdev_entity); if (!subdev_entity) { of_node_put(epn); ret = -ENOMEM; @@ -418,7 +417,7 @@ static int microchip_isc_probe(struct platform_device *pdev) int ret; u32 ver; - isc = devm_kzalloc(dev, sizeof(*isc), GFP_KERNEL); + isc = devm_kzalloc_obj(dev, *isc); if (!isc) return -ENOMEM; diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/drivers/media/platform/microchip/microchip-sama7g5-isc.c index 9e78ea07b013a7..43f718303a68c4 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -359,8 +359,7 @@ static int xisc_parse_dt(struct device *dev, struct isc_device *isc) goto err_cleanup; } - subdev_entity = devm_kzalloc(dev, sizeof(*subdev_entity), - GFP_KERNEL); + subdev_entity = devm_kzalloc_obj(dev, *subdev_entity); if (!subdev_entity) { of_node_put(epn); ret = -ENOMEM; @@ -407,7 +406,7 @@ static int microchip_xisc_probe(struct platform_device *pdev) int ret; u32 ver; - isc = devm_kzalloc(dev, sizeof(*isc), GFP_KERNEL); + isc = devm_kzalloc_obj(dev, *isc); if (!isc) return -ENOMEM; diff --git a/drivers/media/platform/nvidia/tegra-vde/vde.c b/drivers/media/platform/nvidia/tegra-vde/vde.c index c3097085ad9d19..878a5b37846ced 100644 --- a/drivers/media/platform/nvidia/tegra-vde/vde.c +++ b/drivers/media/platform/nvidia/tegra-vde/vde.c @@ -229,7 +229,7 @@ static int tegra_vde_probe(struct platform_device *pdev) struct tegra_vde *vde; int irq, err; - vde = devm_kzalloc(dev, sizeof(*vde), GFP_KERNEL); + vde = devm_kzalloc_obj(dev, *vde); if (!vde) return -ENOMEM; diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platform/nxp/dw100/dw100.c index 7787fdcdc67ce3..847a538003d2fa 100644 --- a/drivers/media/platform/nxp/dw100/dw100.c +++ b/drivers/media/platform/nxp/dw100/dw100.c @@ -1566,7 +1566,7 @@ static int dw100_probe(struct platform_device *pdev) struct video_device *vfd; int ret, irq; - dw_dev = devm_kzalloc(&pdev->dev, sizeof(*dw_dev), GFP_KERNEL); + dw_dev = devm_kzalloc_obj(&pdev->dev, *dw_dev); if (!dw_dev) return -ENOMEM; dw_dev->pdev = pdev; diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index e170859354352e..6054cd595f097d 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -2874,13 +2874,12 @@ static int mxc_jpeg_attach_pm_domains(struct mxc_jpeg_dev *jpeg) return 0; } - jpeg->pd_dev = devm_kmalloc_array(dev, jpeg->num_domains, - sizeof(*jpeg->pd_dev), GFP_KERNEL); + jpeg->pd_dev = devm_kmalloc_objs(dev, *jpeg->pd_dev, jpeg->num_domains); if (!jpeg->pd_dev) return -ENOMEM; - jpeg->pd_link = devm_kmalloc_array(dev, jpeg->num_domains, - sizeof(*jpeg->pd_link), GFP_KERNEL); + jpeg->pd_link = devm_kmalloc_objs(dev, *jpeg->pd_link, + jpeg->num_domains); if (!jpeg->pd_link) return -ENOMEM; @@ -2928,7 +2927,7 @@ static int mxc_jpeg_probe(struct platform_device *pdev) return -ENODEV; mode = *(const int *)of_id->data; - jpeg = devm_kzalloc(dev, sizeof(struct mxc_jpeg_dev), GFP_KERNEL); + jpeg = devm_kzalloc_obj(dev, struct mxc_jpeg_dev); if (!jpeg) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx-mipi-csis.c b/drivers/media/platform/nxp/imx-mipi-csis.c index 1b9012dbae3946..080e65808d74d5 100644 --- a/drivers/media/platform/nxp/imx-mipi-csis.c +++ b/drivers/media/platform/nxp/imx-mipi-csis.c @@ -730,8 +730,8 @@ static int mipi_csis_clk_get(struct mipi_csis_device *csis) unsigned int i; int ret; - csis->clks = devm_kcalloc(csis->dev, csis->info->num_clocks, - sizeof(*csis->clks), GFP_KERNEL); + csis->clks = devm_kzalloc_objs(csis->dev, *csis->clks, + csis->info->num_clocks); if (!csis->clks) return -ENOMEM; @@ -1507,7 +1507,7 @@ static int mipi_csis_probe(struct platform_device *pdev) int irq; int ret; - csis = devm_kzalloc(dev, sizeof(*csis), GFP_KERNEL); + csis = devm_kzalloc_obj(dev, *csis); if (!csis) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx-pxp.c b/drivers/media/platform/nxp/imx-pxp.c index 740fcd8fb95287..abad39d74808df 100644 --- a/drivers/media/platform/nxp/imx-pxp.c +++ b/drivers/media/platform/nxp/imx-pxp.c @@ -1777,7 +1777,7 @@ static int pxp_probe(struct platform_device *pdev) int ret; void __iomem *mmio; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c index f06b03967aefaa..c6eb4cd5b0b5a2 100644 --- a/drivers/media/platform/nxp/imx7-media-csi.c +++ b/drivers/media/platform/nxp/imx7-media-csi.c @@ -2208,7 +2208,7 @@ static int imx7_csi_probe(struct platform_device *pdev) struct imx7_csi *csi; int ret; - csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(&pdev->dev, *csi); if (!csi) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c index 0ae5f35e017c66..2005584a121544 100644 --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c @@ -479,7 +479,7 @@ static int mxc_isi_probe(struct platform_device *pdev) unsigned int i; int ret = 0; - isi = devm_kzalloc(dev, sizeof(*isi), GFP_KERNEL); + isi = devm_kzalloc_obj(dev, *isi); if (!isi) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx8mq-mipi-csi2.c b/drivers/media/platform/nxp/imx8mq-mipi-csi2.c index 17756b7fe1dded..2ad8a551270973 100644 --- a/drivers/media/platform/nxp/imx8mq-mipi-csi2.c +++ b/drivers/media/platform/nxp/imx8mq-mipi-csi2.c @@ -979,7 +979,7 @@ static int imx8mq_mipi_csi_probe(struct platform_device *pdev) struct csi_state *state; int ret; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/platform/nxp/imx95-csi-formatter.c b/drivers/media/platform/nxp/imx95-csi-formatter.c index 37dfcefbf0d12a..19995a80990994 100644 --- a/drivers/media/platform/nxp/imx95-csi-formatter.c +++ b/drivers/media/platform/nxp/imx95-csi-formatter.c @@ -671,7 +671,7 @@ static int csi_formatter_probe(struct platform_device *pdev) struct csi_formatter *formatter; int ret; - formatter = devm_kzalloc(dev, sizeof(*formatter), GFP_KERNEL); + formatter = devm_kzalloc_obj(dev, *formatter); if (!formatter) return -ENOMEM; diff --git a/drivers/media/platform/nxp/mx2_emmaprp.c b/drivers/media/platform/nxp/mx2_emmaprp.c index d51a6210077883..f31c19f9733e3c 100644 --- a/drivers/media/platform/nxp/mx2_emmaprp.c +++ b/drivers/media/platform/nxp/mx2_emmaprp.c @@ -801,7 +801,7 @@ static int emmaprp_probe(struct platform_device *pdev) struct video_device *vfd; int irq, ret; - pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); + pcdev = devm_kzalloc_obj(&pdev->dev, *pcdev); if (!pcdev) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c index a00791b00feb79..51f20907ffde6a 100644 --- a/drivers/media/platform/qcom/camss/camss-csid.c +++ b/drivers/media/platform/qcom/camss/camss-csid.c @@ -1154,8 +1154,7 @@ int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid, while (res->clock[csid->nclocks]) csid->nclocks++; - csid->clock = devm_kcalloc(dev, csid->nclocks, sizeof(*csid->clock), - GFP_KERNEL); + csid->clock = devm_kzalloc_objs(dev, *csid->clock, csid->nclocks); if (!csid->clock) return -ENOMEM; @@ -1177,10 +1176,8 @@ int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid, continue; } - clock->freq = devm_kcalloc(dev, - clock->nfreqs, - sizeof(*clock->freq), - GFP_KERNEL); + clock->freq = devm_kzalloc_objs(dev, *clock->freq, + clock->nfreqs); if (!clock->freq) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c index dac8d2ecf79957..638f77263d761f 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c @@ -1208,7 +1208,7 @@ static int csiphy_init(struct csiphy_device *csiphy) struct device *dev = csiphy->camss->dev; struct csiphy_device_regs *regs; - regs = devm_kmalloc(dev, sizeof(*regs), GFP_KERNEL); + regs = devm_kmalloc_obj(dev, *regs); if (!regs) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c index f99eea2ef2289c..cdb803843792c1 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c @@ -729,16 +729,12 @@ int msm_csiphy_subdev_init_legacy(struct camss *camss, while (res->clock[csiphy->nclocks]) csiphy->nclocks++; - csiphy->clock = devm_kcalloc(dev, - csiphy->nclocks, sizeof(*csiphy->clock), - GFP_KERNEL); + csiphy->clock = devm_kzalloc_objs(dev, *csiphy->clock, csiphy->nclocks); if (!csiphy->clock) return -ENOMEM; - csiphy->rate_set = devm_kcalloc(dev, - csiphy->nclocks, - sizeof(*csiphy->rate_set), - GFP_KERNEL); + csiphy->rate_set = devm_kzalloc_objs(dev, *csiphy->rate_set, + csiphy->nclocks); if (!csiphy->rate_set) return -ENOMEM; @@ -760,10 +756,8 @@ int msm_csiphy_subdev_init_legacy(struct camss *camss, continue; } - clock->freq = devm_kcalloc(dev, - clock->nfreqs, - sizeof(*clock->freq), - GFP_KERNEL); + clock->freq = devm_kzalloc_objs(dev, *clock->freq, + clock->nfreqs); if (!clock->freq) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c b/drivers/media/platform/qcom/camss/camss-ispif.c index f266f8532ecc73..4f08c6de43c66c 100644 --- a/drivers/media/platform/qcom/camss/camss-ispif.c +++ b/drivers/media/platform/qcom/camss/camss-ispif.c @@ -1122,8 +1122,7 @@ int msm_ispif_subdev_init(struct camss *camss, else return -EINVAL; - ispif->line = devm_kcalloc(dev, ispif->line_num, - sizeof(*ispif->line), GFP_KERNEL); + ispif->line = devm_kzalloc_objs(dev, *ispif->line, ispif->line_num); if (!ispif->line) return -ENOMEM; @@ -1189,9 +1188,7 @@ int msm_ispif_subdev_init(struct camss *camss, while (res->clock[ispif->nclocks]) ispif->nclocks++; - ispif->clock = devm_kcalloc(dev, - ispif->nclocks, sizeof(*ispif->clock), - GFP_KERNEL); + ispif->clock = devm_kzalloc_objs(dev, *ispif->clock, ispif->nclocks); if (!ispif->clock) return -ENOMEM; @@ -1210,10 +1207,8 @@ int msm_ispif_subdev_init(struct camss *camss, while (res->clock_for_reset[ispif->nclocks_for_reset]) ispif->nclocks_for_reset++; - ispif->clock_for_reset = devm_kcalloc(dev, - ispif->nclocks_for_reset, - sizeof(*ispif->clock_for_reset), - GFP_KERNEL); + ispif->clock_for_reset = devm_kzalloc_objs(dev, *ispif->clock_for_reset, + ispif->nclocks_for_reset); if (!ispif->clock_for_reset) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-tpg.c b/drivers/media/platform/qcom/camss/camss-tpg.c index 5764a60fa34cba..3caa95819b3931 100644 --- a/drivers/media/platform/qcom/camss/camss-tpg.c +++ b/drivers/media/platform/qcom/camss/camss-tpg.c @@ -372,8 +372,7 @@ int msm_tpg_subdev_init(struct camss *camss, if (!tpg->nclocks) return 0; - tpg->clock = devm_kcalloc(dev, tpg->nclocks, - sizeof(*tpg->clock), GFP_KERNEL); + tpg->clock = devm_kzalloc_objs(dev, *tpg->clock, tpg->nclocks); if (!tpg->clock) return -ENOMEM; @@ -395,8 +394,8 @@ int msm_tpg_subdev_init(struct camss *camss, continue; } - clock->freq = devm_kcalloc(dev, clock->nfreqs, - sizeof(*clock->freq), GFP_KERNEL); + clock->freq = devm_kzalloc_objs(dev, *clock->freq, + clock->nfreqs); if (!clock->freq) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c index 2680a9914765fa..ad09593f580280 100644 --- a/drivers/media/platform/qcom/camss/camss-vfe.c +++ b/drivers/media/platform/qcom/camss/camss-vfe.c @@ -1863,8 +1863,7 @@ int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe, while (res->clock[vfe->nclocks]) vfe->nclocks++; - vfe->clock = devm_kcalloc(dev, vfe->nclocks, sizeof(*vfe->clock), - GFP_KERNEL); + vfe->clock = devm_kzalloc_objs(dev, *vfe->clock, vfe->nclocks); if (!vfe->clock) return -ENOMEM; @@ -1886,10 +1885,8 @@ int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe, continue; } - clock->freq = devm_kcalloc(dev, - clock->nfreqs, - sizeof(*clock->freq), - GFP_KERNEL); + clock->freq = devm_kzalloc_objs(dev, *clock->freq, + clock->nfreqs); if (!clock->freq) return -ENOMEM; diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c index c54185c93a8a98..f8e5cf9f3ff09e 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -4710,9 +4710,7 @@ static int camss_parse_endpoint_node(struct device *dev, lncfg->clk.pol = mipi_csi2->lane_polarities[0]; lncfg->num_data = mipi_csi2->num_data_lanes; - lncfg->data = devm_kcalloc(dev, - lncfg->num_data, sizeof(*lncfg->data), - GFP_KERNEL); + lncfg->data = devm_kzalloc_objs(dev, *lncfg->data, lncfg->num_data); if (!lncfg->data) return -ENOMEM; @@ -5419,7 +5417,7 @@ static int camss_probe(struct platform_device *pdev) struct camss *camss; int ret; - camss = devm_kzalloc(dev, sizeof(*camss), GFP_KERNEL); + camss = devm_kzalloc_obj(dev, *camss); if (!camss) return -ENOMEM; @@ -5429,20 +5427,19 @@ static int camss_probe(struct platform_device *pdev) camss->dev = dev; platform_set_drvdata(pdev, camss); - camss->csiphy = devm_kcalloc(dev, camss->res->csiphy_num, - sizeof(*camss->csiphy), GFP_KERNEL); + camss->csiphy = devm_kzalloc_objs(dev, *camss->csiphy, + camss->res->csiphy_num); if (!camss->csiphy) return -ENOMEM; if (camss->res->tpg_num > 0) { - camss->tpg = devm_kcalloc(dev, camss->res->tpg_num, - sizeof(*camss->tpg), GFP_KERNEL); + camss->tpg = devm_kzalloc_objs(dev, *camss->tpg, + camss->res->tpg_num); if (!camss->tpg) return -ENOMEM; } - camss->csid = devm_kcalloc(dev, camss->res->csid_num, sizeof(*camss->csid), - GFP_KERNEL); + camss->csid = devm_kzalloc_objs(dev, *camss->csid, camss->res->csid_num); if (!camss->csid) return -ENOMEM; @@ -5450,13 +5447,12 @@ static int camss_probe(struct platform_device *pdev) camss->res->version == CAMSS_8x39 || camss->res->version == CAMSS_8x53 || camss->res->version == CAMSS_8x96) { - camss->ispif = devm_kcalloc(dev, 1, sizeof(*camss->ispif), GFP_KERNEL); + camss->ispif = devm_kzalloc_objs(dev, *camss->ispif, 1); if (!camss->ispif) return -ENOMEM; } - camss->vfe = devm_kcalloc(dev, camss->res->vfe_num, - sizeof(*camss->vfe), GFP_KERNEL); + camss->vfe = devm_kzalloc_objs(dev, *camss->vfe, camss->res->vfe_num); if (!camss->vfe) return -ENOMEM; diff --git a/drivers/media/platform/qcom/iris/iris_probe.c b/drivers/media/platform/qcom/iris/iris_probe.c index 41dec90f3e2bed..343e44c6b9c461 100644 --- a/drivers/media/platform/qcom/iris/iris_probe.c +++ b/drivers/media/platform/qcom/iris/iris_probe.c @@ -167,7 +167,7 @@ static int iris_reserve_iova_region(struct device *dev, struct dma_iova_state ** unsigned int count = 0; int ret = -ENOMEM; - state = devm_kcalloc(dev, BITS_PER_TYPE(dma_addr_t) + 1, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_objs(dev, *state, BITS_PER_TYPE(dma_addr_t) + 1); if (!state) return ret; @@ -281,7 +281,7 @@ static int iris_probe(struct platform_device *pdev) u64 dma_mask; int ret; - core = devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(&pdev->dev, *core); if (!core) return -ENOMEM; core->dev = dev; diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 7087af32060f1e..ad10d9746d1da3 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -394,7 +394,7 @@ static int venus_reserve_iova_region(struct device *dev, struct dma_iova_state * unsigned int count = 0; int ret = -ENOMEM; - state = devm_kcalloc(dev, BITS_PER_TYPE(dma_addr_t) + 1, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_objs(dev, *state, BITS_PER_TYPE(dma_addr_t) + 1); if (!state) return ret; @@ -434,7 +434,7 @@ static int venus_probe(struct platform_device *pdev) struct venus_core *core; int ret; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index d60d92d2ffa1c8..8fb723029977de 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -472,7 +472,7 @@ static int pispbe_prepare_job(struct pispbe_dev *pispbe) streaming_map = pispbe->streaming_map; } - job = kzalloc(sizeof(*job), GFP_KERNEL); + job = kzalloc_obj(*job); if (!job) return -ENOMEM; @@ -1686,7 +1686,7 @@ static int pispbe_probe(struct platform_device *pdev) struct pispbe_dev *pispbe; int ret; - pispbe = devm_kzalloc(&pdev->dev, sizeof(*pispbe), GFP_KERNEL); + pispbe = devm_kzalloc_obj(&pdev->dev, *pispbe); if (!pispbe) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c index 4851fe649d8aae..12238b3313ba87 100644 --- a/drivers/media/platform/renesas/rcar-csi2.c +++ b/drivers/media/platform/renesas/rcar-csi2.c @@ -2767,7 +2767,7 @@ static int rcsi2_probe(struct platform_device *pdev) unsigned int i, num_pads; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar-fcp.c b/drivers/media/platform/renesas/rcar-fcp.c index dfb0ca93e854dd..213b8802a4542e 100644 --- a/drivers/media/platform/renesas/rcar-fcp.c +++ b/drivers/media/platform/renesas/rcar-fcp.c @@ -156,7 +156,7 @@ static int rcar_fcp_probe(struct platform_device *pdev) { struct rcar_fcp_device *fcp; - fcp = devm_kzalloc(&pdev->dev, sizeof(*fcp), GFP_KERNEL); + fcp = devm_kzalloc_obj(&pdev->dev, *fcp); if (fcp == NULL) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar-isp/csisp.c b/drivers/media/platform/renesas/rcar-isp/csisp.c index 635eeacb3b19c7..5d19391bbf25cc 100644 --- a/drivers/media/platform/renesas/rcar-isp/csisp.c +++ b/drivers/media/platform/renesas/rcar-isp/csisp.c @@ -645,7 +645,7 @@ static int risp_probe(struct platform_device *pdev) unsigned int i; int ret; - isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(&pdev->dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-core.c b/drivers/media/platform/renesas/rcar-vin/rcar-core.c index 2fcea715101cef..1cc1f6d266b8eb 100644 --- a/drivers/media/platform/renesas/rcar-vin/rcar-core.c +++ b/drivers/media/platform/renesas/rcar-vin/rcar-core.c @@ -1180,7 +1180,7 @@ static int rcar_vin_probe(struct platform_device *pdev) struct rvin_dev *vin; int irq, ret; - vin = devm_kzalloc(&pdev->dev, sizeof(*vin), GFP_KERNEL); + vin = devm_kzalloc_obj(&pdev->dev, *vin); if (!vin) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar_drif.c b/drivers/media/platform/renesas/rcar_drif.c index bd67e8e16f537e..9c8129f340e3ca 100644 --- a/drivers/media/platform/renesas/rcar_drif.c +++ b/drivers/media/platform/renesas/rcar_drif.c @@ -1375,7 +1375,7 @@ static int rcar_drif_probe(struct platform_device *pdev) int ret; /* Reserve memory for enabled channel */ - ch = devm_kzalloc(&pdev->dev, sizeof(*ch), GFP_KERNEL); + ch = devm_kzalloc_obj(&pdev->dev, *ch); if (!ch) return -ENOMEM; @@ -1409,7 +1409,7 @@ static int rcar_drif_probe(struct platform_device *pdev) } /* Reserve memory for SDR structure */ - sdr = devm_kzalloc(&pdev->dev, sizeof(*sdr), GFP_KERNEL); + sdr = devm_kzalloc_obj(&pdev->dev, *sdr); if (!sdr) { of_node_put(np); return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar_fdp1.c b/drivers/media/platform/renesas/rcar_fdp1.c index 013e0666170a17..460fa99582daac 100644 --- a/drivers/media/platform/renesas/rcar_fdp1.c +++ b/drivers/media/platform/renesas/rcar_fdp1.c @@ -2256,7 +2256,7 @@ static int fdp1_probe(struct platform_device *pdev) int ret; int hw_version; - fdp1 = devm_kzalloc(&pdev->dev, sizeof(*fdp1), GFP_KERNEL); + fdp1 = devm_kzalloc_obj(&pdev->dev, *fdp1); if (!fdp1) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rcar_jpu.c b/drivers/media/platform/renesas/rcar_jpu.c index 93d54325e42020..48b7bdaf15b567 100644 --- a/drivers/media/platform/renesas/rcar_jpu.c +++ b/drivers/media/platform/renesas/rcar_jpu.c @@ -1574,7 +1574,7 @@ static int jpu_probe(struct platform_device *pdev) int ret; unsigned int i; - jpu = devm_kzalloc(&pdev->dev, sizeof(*jpu), GFP_KERNEL); + jpu = devm_kzalloc_obj(&pdev->dev, *jpu); if (!jpu) return -ENOMEM; diff --git a/drivers/media/platform/renesas/renesas-ceu.c b/drivers/media/platform/renesas/renesas-ceu.c index 47b9e475330153..28c2e6a01f0c1c 100644 --- a/drivers/media/platform/renesas/renesas-ceu.c +++ b/drivers/media/platform/renesas/renesas-ceu.c @@ -1463,8 +1463,7 @@ static const struct v4l2_async_notifier_operations ceu_notify_ops = { static int ceu_init_async_subdevs(struct ceu_device *ceudev, unsigned int n_sd) { /* Reserve memory for 'n_sd' ceu_subdev descriptors. */ - ceudev->subdevs = devm_kcalloc(ceudev->dev, n_sd, - sizeof(*ceudev->subdevs), GFP_KERNEL); + ceudev->subdevs = devm_kzalloc_objs(ceudev->dev, *ceudev->subdevs, n_sd); if (!ceudev->subdevs) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c index 8c7f46ccce5f77..4083ce189b6d36 100644 --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c @@ -244,7 +244,7 @@ static int rzg2l_cru_probe(struct platform_device *pdev) struct rzg2l_cru_dev *cru; int irq, ret; - cru = devm_kzalloc(dev, sizeof(*cru), GFP_KERNEL); + cru = devm_kzalloc_obj(dev, *cru); if (!cru) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c index c17283cba3a622..64650dafb22a69 100644 --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c @@ -903,7 +903,7 @@ static int rzg2l_csi2_probe(struct platform_device *pdev) struct rzg2l_csi2 *csi2; int ret; - csi2 = devm_kzalloc(dev, sizeof(*csi2), GFP_KERNEL); + csi2 = devm_kzalloc_obj(dev, *csi2); if (!csi2) return -ENOMEM; diff --git a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c index 48f9fd818bfffa..e2a14ebeb1141b 100644 --- a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c +++ b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c @@ -183,7 +183,7 @@ static int rzv2h_ivc_probe(struct platform_device *pdev) struct rzv2h_ivc *ivc; int ret; - ivc = devm_kzalloc(dev, sizeof(*ivc), GFP_KERNEL); + ivc = devm_kzalloc_obj(dev, *ivc); if (!ivc) return -ENOMEM; diff --git a/drivers/media/platform/renesas/sh_vou.c b/drivers/media/platform/renesas/sh_vou.c index 6d4ec80edd8f0d..4396837d11c6e5 100644 --- a/drivers/media/platform/renesas/sh_vou.c +++ b/drivers/media/platform/renesas/sh_vou.c @@ -1234,7 +1234,7 @@ static int sh_vou_probe(struct platform_device *pdev) if (irq < 0) return irq; - vou_dev = devm_kzalloc(&pdev->dev, sizeof(*vou_dev), GFP_KERNEL); + vou_dev = devm_kzalloc_obj(&pdev->dev, *vou_dev); if (!vou_dev) return -ENOMEM; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_brx.c b/drivers/media/platform/renesas/vsp1/vsp1_brx.c index a70b82e22e69cc..4d929aa474ac9d 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_brx.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_brx.c @@ -393,7 +393,7 @@ struct vsp1_brx *vsp1_brx_create(struct vsp1_device *vsp1, const char *name; int ret; - brx = devm_kzalloc(vsp1->dev, sizeof(*brx), GFP_KERNEL); + brx = devm_kzalloc_obj(vsp1->dev, *brx); if (brx == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_clu.c b/drivers/media/platform/renesas/vsp1/vsp1_clu.c index 4b7d07d730da2d..49ec862829a800 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_clu.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_clu.c @@ -206,7 +206,7 @@ struct vsp1_clu *vsp1_clu_create(struct vsp1_device *vsp1) struct vsp1_clu *clu; int ret; - clu = devm_kzalloc(vsp1->dev, sizeof(*clu), GFP_KERNEL); + clu = devm_kzalloc_obj(vsp1->dev, *clu); if (clu == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c index 8257759421f3c3..ad0e6a44fef9f6 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c @@ -1090,7 +1090,7 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, struct vsp1_dl_manager *dlm; size_t header_size; - dlm = devm_kzalloc(vsp1->dev, sizeof(*dlm), GFP_KERNEL); + dlm = devm_kzalloc_obj(vsp1->dev, *dlm); if (!dlm) return NULL; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drm.c b/drivers/media/platform/renesas/vsp1/vsp1_drm.c index adb89e69938903..7aa0fe141c59cc 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_drm.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_drm.c @@ -966,7 +966,7 @@ EXPORT_SYMBOL_GPL(vsp1_du_unmap_sg); int vsp1_drm_init(struct vsp1_device *vsp1) { - vsp1->drm = devm_kzalloc(vsp1->dev, sizeof(*vsp1->drm), GFP_KERNEL); + vsp1->drm = devm_kzalloc_obj(vsp1->dev, *vsp1->drm); if (!vsp1->drm) return -ENOMEM; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_drv.c b/drivers/media/platform/renesas/vsp1/vsp1_drv.c index 762a9e776a94d5..e962da56bac6d9 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_drv.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_drv.c @@ -920,7 +920,7 @@ static int vsp1_probe(struct platform_device *pdev) int ret; int irq; - vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL); + vsp1 = devm_kzalloc_obj(&pdev->dev, *vsp1); if (vsp1 == NULL) return -ENOMEM; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_entity.c b/drivers/media/platform/renesas/vsp1/vsp1_entity.c index f7359d34794758..032d8ff4b2af2b 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_entity.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_entity.c @@ -607,17 +607,15 @@ int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, entity->source_pad = num_pads - 1; /* Allocate and initialize pads. */ - entity->pads = devm_kcalloc(vsp1->dev, - num_pads, sizeof(*entity->pads), - GFP_KERNEL); + entity->pads = devm_kzalloc_objs(vsp1->dev, *entity->pads, num_pads); if (entity->pads == NULL) return -ENOMEM; for (i = 0; i < num_pads - 1; ++i) entity->pads[i].flags = MEDIA_PAD_FL_SINK; - entity->sources = devm_kcalloc(vsp1->dev, max(num_pads - 1, 1U), - sizeof(*entity->sources), GFP_KERNEL); + entity->sources = devm_kzalloc_objs(vsp1->dev, *entity->sources, + max(num_pads - 1, 1U)); if (entity->sources == NULL) return -ENOMEM; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c index d3eaa7c2d595eb..e5f27637acb77f 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_hgo.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgo.c @@ -187,7 +187,7 @@ struct vsp1_hgo *vsp1_hgo_create(struct vsp1_device *vsp1) struct vsp1_hgo *hgo; int ret; - hgo = devm_kzalloc(vsp1->dev, sizeof(*hgo), GFP_KERNEL); + hgo = devm_kzalloc_obj(vsp1->dev, *hgo); if (hgo == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c index 8c04bdec851012..57b5be8ce615cd 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_hgt.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_hgt.c @@ -184,7 +184,7 @@ struct vsp1_hgt *vsp1_hgt_create(struct vsp1_device *vsp1) struct vsp1_hgt *hgt; int ret; - hgt = devm_kzalloc(vsp1->dev, sizeof(*hgt), GFP_KERNEL); + hgt = devm_kzalloc_obj(vsp1->dev, *hgt); if (hgt == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c index d734b5775af656..5987b13969cd02 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_hsit.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_hsit.c @@ -204,7 +204,7 @@ struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse) struct vsp1_hsit *hsit; int ret; - hsit = devm_kzalloc(vsp1->dev, sizeof(*hsit), GFP_KERNEL); + hsit = devm_kzalloc_obj(vsp1->dev, *hsit); if (hsit == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_iif.c b/drivers/media/platform/renesas/vsp1/vsp1_iif.c index d44c04e140bcb5..36898752eb3b20 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_iif.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_iif.c @@ -73,7 +73,7 @@ struct vsp1_iif *vsp1_iif_create(struct vsp1_device *vsp1) struct vsp1_iif *iif; int ret; - iif = devm_kzalloc(vsp1->dev, sizeof(*iif), GFP_KERNEL); + iif = devm_kzalloc_obj(vsp1->dev, *iif); if (!iif) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lif.c b/drivers/media/platform/renesas/vsp1/vsp1_lif.c index 1ebb88b3e4c90e..74aa1cb795ad21 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_lif.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_lif.c @@ -127,7 +127,7 @@ struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1, unsigned int index) struct vsp1_lif *lif; int ret; - lif = devm_kzalloc(vsp1->dev, sizeof(*lif), GFP_KERNEL); + lif = devm_kzalloc_obj(vsp1->dev, *lif); if (lif == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_lut.c b/drivers/media/platform/renesas/vsp1/vsp1_lut.c index 6433b5515ef9a7..70a4b00bd8239a 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_lut.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_lut.c @@ -167,7 +167,7 @@ struct vsp1_lut *vsp1_lut_create(struct vsp1_device *vsp1) struct vsp1_lut *lut; int ret; - lut = devm_kzalloc(vsp1->dev, sizeof(*lut), GFP_KERNEL); + lut = devm_kzalloc_obj(vsp1->dev, *lut); if (lut == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_rpf.c b/drivers/media/platform/renesas/vsp1/vsp1_rpf.c index 34b9095c901182..6a350523d60614 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_rpf.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_rpf.c @@ -421,7 +421,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index) char name[6]; int ret; - rpf = devm_kzalloc(vsp1->dev, sizeof(*rpf), GFP_KERNEL); + rpf = devm_kzalloc_obj(vsp1->dev, *rpf); if (rpf == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_sru.c b/drivers/media/platform/renesas/vsp1/vsp1_sru.c index 5e1cf60be31122..dcec35c94e4421 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_sru.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_sru.c @@ -349,7 +349,7 @@ struct vsp1_sru *vsp1_sru_create(struct vsp1_device *vsp1) struct vsp1_sru *sru; int ret; - sru = devm_kzalloc(vsp1->dev, sizeof(*sru), GFP_KERNEL); + sru = devm_kzalloc_obj(vsp1->dev, *sru); if (sru == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uds.c b/drivers/media/platform/renesas/vsp1/vsp1_uds.c index d129964ec14ddb..9a1d6ec238b471 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_uds.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_uds.c @@ -387,7 +387,7 @@ struct vsp1_uds *vsp1_uds_create(struct vsp1_device *vsp1, unsigned int index) char name[6]; int ret; - uds = devm_kzalloc(vsp1->dev, sizeof(*uds), GFP_KERNEL); + uds = devm_kzalloc_obj(vsp1->dev, *uds); if (uds == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_uif.c b/drivers/media/platform/renesas/vsp1/vsp1_uif.c index 16ddcd594134a5..df390918418977 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_uif.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_uif.c @@ -203,7 +203,7 @@ struct vsp1_uif *vsp1_uif_create(struct vsp1_device *vsp1, unsigned int index) char name[6]; int ret; - uif = devm_kzalloc(vsp1->dev, sizeof(*uif), GFP_KERNEL); + uif = devm_kzalloc_obj(vsp1->dev, *uif); if (!uif) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c index b85351986fae50..ace719756de416 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c @@ -1190,7 +1190,7 @@ struct vsp1_video *vsp1_video_create(struct vsp1_device *vsp1, const char *direction; int ret; - video = devm_kzalloc(vsp1->dev, sizeof(*video), GFP_KERNEL); + video = devm_kzalloc_obj(vsp1->dev, *video); if (!video) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/renesas/vsp1/vsp1_vspx.c b/drivers/media/platform/renesas/vsp1/vsp1_vspx.c index 5c39bacfb13f31..ed1877f5c6c13f 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_vspx.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_vspx.c @@ -584,7 +584,7 @@ int vsp1_vspx_init(struct vsp1_device *vsp1) struct vsp1_vspx_pipeline *vspx_pipe; struct vsp1_pipeline *pipe; - vsp1->vspx = devm_kzalloc(vsp1->dev, sizeof(*vsp1->vspx), GFP_KERNEL); + vsp1->vspx = devm_kzalloc_obj(vsp1->dev, *vsp1->vspx); if (!vsp1->vspx) return -ENOMEM; diff --git a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c index 821887815eb2e3..f5abd42b94e9ea 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_wpf.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_wpf.c @@ -553,7 +553,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index) char name[6]; int ret; - wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL); + wpf = devm_kzalloc_obj(vsp1->dev, *wpf); if (wpf == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c index 543a0da7557251..24ce13b4bbda6e 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -768,7 +768,7 @@ static int rga_probe(struct platform_device *pdev) if (ret) return ret; - rga = devm_kzalloc(&pdev->dev, sizeof(*rga), GFP_KERNEL); + rga = devm_kzalloc_obj(&pdev->dev, *rga); if (!rga) return -ENOMEM; diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c index 2a5758776b3e4d..f9ad8c23ae2bba 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-dev.c +++ b/drivers/media/platform/rockchip/rkcif/rkcif-dev.c @@ -188,7 +188,7 @@ static int rkcif_probe(struct platform_device *pdev) struct rkcif_device *rkcif; int ret, irq; - rkcif = devm_kzalloc(dev, sizeof(*rkcif), GFP_KERNEL); + rkcif = devm_kzalloc_obj(dev, *rkcif); if (!rkcif) return -ENOMEM; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index f90e01301943c7..a4f0c181fc0241 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -655,7 +655,7 @@ static int rkisp1_probe(struct platform_device *pdev) int ret, irq; u32 cif_id; - rkisp1 = devm_kzalloc(dev, sizeof(*rkisp1), GFP_KERNEL); + rkisp1 = devm_kzalloc_obj(dev, *rkisp1); if (!rkisp1) return -ENOMEM; diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c index fdcf1f1773797e..3828e2a5c665da 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c @@ -93,7 +93,7 @@ int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx, return 0; } - ctx->rcb_config = devm_kzalloc(rkvdec->dev, sizeof(*ctx->rcb_config), GFP_KERNEL); + ctx->rcb_config = devm_kzalloc_obj(rkvdec->dev, *ctx->rcb_config); if (!ctx->rcb_config) return -ENOMEM; diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c index fbcd0f175ad3f8..5250dd59df2ec0 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c @@ -1774,7 +1774,7 @@ static int rkvdec_probe(struct platform_device *pdev) if (!variant) return -EINVAL; - rkvdec = devm_kzalloc(&pdev->dev, sizeof(*rkvdec), GFP_KERNEL); + rkvdec = devm_kzalloc_obj(&pdev->dev, *rkvdec); if (!rkvdec) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos-gsc/gsc-core.c b/drivers/media/platform/samsung/exynos-gsc/gsc-core.c index a06d7cace92f48..084db76543927e 100644 --- a/drivers/media/platform/samsung/exynos-gsc/gsc-core.c +++ b/drivers/media/platform/samsung/exynos-gsc/gsc-core.c @@ -1110,7 +1110,7 @@ static int gsc_probe(struct platform_device *pdev) int ret; int i; - gsc = devm_kzalloc(dev, sizeof(struct gsc_dev), GFP_KERNEL); + gsc = devm_kzalloc_obj(dev, struct gsc_dev); if (!gsc) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-core.c b/drivers/media/platform/samsung/exynos4-is/fimc-core.c index 57e573949e54df..4b460d8f73d25e 100644 --- a/drivers/media/platform/samsung/exynos4-is/fimc-core.c +++ b/drivers/media/platform/samsung/exynos4-is/fimc-core.c @@ -927,7 +927,7 @@ static int fimc_probe(struct platform_device *pdev) int ret = 0; int irq; - fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL); + fimc = devm_kzalloc_obj(dev, *fimc); if (!fimc) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c b/drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c index b5b37b6f8fa810..1e7a8700d50977 100644 --- a/drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c +++ b/drivers/media/platform/samsung/exynos4-is/fimc-is-i2c.c @@ -41,7 +41,7 @@ static int fimc_is_i2c_probe(struct platform_device *pdev) struct i2c_adapter *i2c_adap; int ret; - isp_i2c = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c), GFP_KERNEL); + isp_i2c = devm_kzalloc_obj(&pdev->dev, *isp_i2c); if (!isp_i2c) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-is.c b/drivers/media/platform/samsung/exynos4-is/fimc-is.c index b7d9bfedd590fa..fbbd3deedd13fb 100644 --- a/drivers/media/platform/samsung/exynos4-is/fimc-is.c +++ b/drivers/media/platform/samsung/exynos4-is/fimc-is.c @@ -792,7 +792,7 @@ static int fimc_is_probe(struct platform_device *pdev) struct resource res; int ret; - is = devm_kzalloc(&pdev->dev, sizeof(*is), GFP_KERNEL); + is = devm_kzalloc_obj(&pdev->dev, *is); if (!is) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-lite.c b/drivers/media/platform/samsung/exynos4-is/fimc-lite.c index 90599c82fd35ce..15ab72de4c5088 100644 --- a/drivers/media/platform/samsung/exynos4-is/fimc-lite.c +++ b/drivers/media/platform/samsung/exynos4-is/fimc-lite.c @@ -1454,7 +1454,7 @@ static int fimc_lite_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL); + fimc = devm_kzalloc_obj(dev, *fimc); if (!fimc) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/media-dev.c b/drivers/media/platform/samsung/exynos4-is/media-dev.c index 2e08c4435859e8..e6b327d3cd78a4 100644 --- a/drivers/media/platform/samsung/exynos4-is/media-dev.c +++ b/drivers/media/platform/samsung/exynos4-is/media-dev.c @@ -1426,7 +1426,7 @@ static int fimc_md_probe(struct platform_device *pdev) struct fimc_md *fmd; int ret; - fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL); + fmd = devm_kzalloc_obj(dev, *fmd); if (!fmd) return -ENOMEM; diff --git a/drivers/media/platform/samsung/exynos4-is/mipi-csis.c b/drivers/media/platform/samsung/exynos4-is/mipi-csis.c index da6e67a79c09b0..4661867b3580ee 100644 --- a/drivers/media/platform/samsung/exynos4-is/mipi-csis.c +++ b/drivers/media/platform/samsung/exynos4-is/mipi-csis.c @@ -771,7 +771,7 @@ static int s5pcsis_probe(struct platform_device *pdev) int ret = -ENOMEM; int i; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/media/platform/samsung/s3c-camif/camif-core.c b/drivers/media/platform/samsung/s3c-camif/camif-core.c index 2ff71e375efed2..0b54bc8ac6bd3e 100644 --- a/drivers/media/platform/samsung/s3c-camif/camif-core.c +++ b/drivers/media/platform/samsung/s3c-camif/camif-core.c @@ -397,7 +397,7 @@ static int s3c_camif_probe(struct platform_device *pdev) struct camif_dev *camif; int ret = 0; - camif = devm_kzalloc(dev, sizeof(*camif), GFP_KERNEL); + camif = devm_kzalloc_obj(dev, *camif); if (!camif) return -ENOMEM; diff --git a/drivers/media/platform/samsung/s5p-g2d/g2d.c b/drivers/media/platform/samsung/s5p-g2d/g2d.c index a18b13db19d5a2..6f8e26110523ef 100644 --- a/drivers/media/platform/samsung/s5p-g2d/g2d.c +++ b/drivers/media/platform/samsung/s5p-g2d/g2d.c @@ -622,7 +622,7 @@ static int g2d_probe(struct platform_device *pdev) const struct of_device_id *of_id; int ret = 0; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c index fdc9d7e0be6618..7670cc705e401c 100644 --- a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c +++ b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c @@ -2846,7 +2846,7 @@ static int s5p_jpeg_probe(struct platform_device *pdev) int i, ret; /* JPEG IP abstraction struct */ - jpeg = devm_kzalloc(&pdev->dev, sizeof(struct s5p_jpeg), GFP_KERNEL); + jpeg = devm_kzalloc_obj(&pdev->dev, struct s5p_jpeg); if (!jpeg) return -ENOMEM; diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index 03e7eac8d1f7f4..03ef65c1dd6888 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -1114,7 +1114,7 @@ static struct device *s5p_mfc_alloc_memdev(struct device *dev, struct device *child; int ret; - child = devm_kzalloc(dev, sizeof(*child), GFP_KERNEL); + child = devm_kzalloc_obj(dev, *child); if (!child) return NULL; @@ -1124,8 +1124,7 @@ static struct device *s5p_mfc_alloc_memdev(struct device *dev, child->coherent_dma_mask = dev->coherent_dma_mask; child->dma_mask = dev->dma_mask; child->release = s5p_mfc_memdev_release; - child->dma_parms = devm_kzalloc(dev, sizeof(*child->dma_parms), - GFP_KERNEL); + child->dma_parms = devm_kzalloc_obj(dev, *child->dma_parms); if (!child->dma_parms) goto err; @@ -1305,7 +1304,7 @@ static int s5p_mfc_probe(struct platform_device *pdev) int ret; pr_debug("%s++\n", __func__); - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/st/sti/bdisp/bdisp-hw.c b/drivers/media/platform/st/sti/bdisp/bdisp-hw.c index a74e9fd6523895..de3c9bc6242219 100644 --- a/drivers/media/platform/st/sti/bdisp/bdisp-hw.c +++ b/drivers/media/platform/st/sti/bdisp/bdisp-hw.c @@ -1062,9 +1062,9 @@ static void bdisp_hw_save_request(struct bdisp_ctx *ctx) for (i = 0; i < MAX_NB_NODE; i++) { /* Allocate memory if not done yet */ if (!copy_node[i]) { - copy_node[i] = devm_kzalloc(ctx->bdisp_dev->dev, - sizeof(*copy_node[i]), - GFP_ATOMIC); + copy_node[i] = devm_kzalloc_obj(ctx->bdisp_dev->dev, + *copy_node[i], + GFP_ATOMIC); if (!copy_node[i]) return; } diff --git a/drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c b/drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c index ee6d686cba49cb..f8dfa32990d864 100644 --- a/drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c +++ b/drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c @@ -1287,7 +1287,7 @@ static int bdisp_probe(struct platform_device *pdev) dev_dbg(dev, "%s\n", __func__); - bdisp = devm_kzalloc(dev, sizeof(struct bdisp_dev), GFP_KERNEL); + bdisp = devm_kzalloc_obj(dev, struct bdisp_dev); if (!bdisp) return -ENOMEM; diff --git a/drivers/media/platform/st/sti/delta/delta-v4l2.c b/drivers/media/platform/st/sti/delta/delta-v4l2.c index 7dd27de37b7816..f1aeed6fb3da73 100644 --- a/drivers/media/platform/st/sti/delta/delta-v4l2.c +++ b/drivers/media/platform/st/sti/delta/delta-v4l2.c @@ -1811,7 +1811,7 @@ static int delta_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - delta = devm_kzalloc(dev, sizeof(*delta), GFP_KERNEL); + delta = devm_kzalloc_obj(dev, *delta); if (!delta) { ret = -ENOMEM; goto err; diff --git a/drivers/media/platform/st/sti/hva/hva-h264.c b/drivers/media/platform/st/sti/hva/hva-h264.c index 196e631fa4b81f..b1c241f8d64eb5 100644 --- a/drivers/media/platform/st/sti/hva/hva-h264.c +++ b/drivers/media/platform/st/sti/hva/hva-h264.c @@ -910,7 +910,7 @@ static int hva_h264_open(struct hva_ctx *pctx) } /* allocate context for codec */ - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) { ret = -ENOMEM; goto err; diff --git a/drivers/media/platform/st/sti/hva/hva-mem.c b/drivers/media/platform/st/sti/hva/hva-mem.c index 68047b60b66cf6..8d8ac6ac5c69f3 100644 --- a/drivers/media/platform/st/sti/hva/hva-mem.c +++ b/drivers/media/platform/st/sti/hva/hva-mem.c @@ -16,7 +16,7 @@ int hva_mem_alloc(struct hva_ctx *ctx, u32 size, const char *name, dma_addr_t paddr; void *base; - b = devm_kzalloc(dev, sizeof(*b), GFP_KERNEL); + b = devm_kzalloc_obj(dev, *b); if (!b) { ctx->sys_errors++; return -ENOMEM; diff --git a/drivers/media/platform/st/sti/hva/hva-v4l2.c b/drivers/media/platform/st/sti/hva/hva-v4l2.c index 33b768774e2079..47d84b0dd5fad6 100644 --- a/drivers/media/platform/st/sti/hva/hva-v4l2.c +++ b/drivers/media/platform/st/sti/hva/hva-v4l2.c @@ -1348,7 +1348,7 @@ static int hva_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - hva = devm_kzalloc(dev, sizeof(*hva), GFP_KERNEL); + hva = devm_kzalloc_obj(dev, *hva); if (!hva) { ret = -ENOMEM; goto err; diff --git a/drivers/media/platform/st/stm32/dma2d/dma2d.c b/drivers/media/platform/st/stm32/dma2d/dma2d.c index a3ad19256859c7..84913a393e3bba 100644 --- a/drivers/media/platform/st/stm32/dma2d/dma2d.c +++ b/drivers/media/platform/st/stm32/dma2d/dma2d.c @@ -601,7 +601,7 @@ static int dma2d_probe(struct platform_device *pdev) struct video_device *vfd; int ret = 0; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/st/stm32/stm32-csi.c b/drivers/media/platform/st/stm32/stm32-csi.c index e71142634a17db..c2b506e46f1653 100644 --- a/drivers/media/platform/st/stm32/stm32-csi.c +++ b/drivers/media/platform/st/stm32/stm32-csi.c @@ -984,7 +984,7 @@ static int stm32_csi_probe(struct platform_device *pdev) struct reset_control *rstc; int ret; - csidev = devm_kzalloc(&pdev->dev, sizeof(*csidev), GFP_KERNEL); + csidev = devm_kzalloc_obj(&pdev->dev, *csidev); if (!csidev) return -ENOMEM; diff --git a/drivers/media/platform/st/stm32/stm32-dcmi.c b/drivers/media/platform/st/stm32/stm32-dcmi.c index 3d774cb4907b3a..53857f1aaf0331 100644 --- a/drivers/media/platform/st/stm32/stm32-dcmi.c +++ b/drivers/media/platform/st/stm32/stm32-dcmi.c @@ -1806,9 +1806,9 @@ static int dcmi_framesizes_init(struct stm32_dcmi *dcmi) return 0; dcmi->num_of_sd_framesizes = num_fsize; - dcmi->sd_framesizes = devm_kcalloc(dcmi->dev, num_fsize, - sizeof(struct dcmi_framesize), - GFP_KERNEL); + dcmi->sd_framesizes = devm_kzalloc_objs(dcmi->dev, + struct dcmi_framesize, + num_fsize); if (!dcmi->sd_framesizes) { dev_err(dcmi->dev, "Could not allocate memory\n"); return -ENOMEM; @@ -1984,7 +1984,7 @@ static int dcmi_probe(struct platform_device *pdev) struct clk *mclk; int ret = 0; - dcmi = devm_kzalloc(&pdev->dev, sizeof(struct stm32_dcmi), GFP_KERNEL); + dcmi = devm_kzalloc_obj(&pdev->dev, struct stm32_dcmi); if (!dcmi) return -ENOMEM; diff --git a/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c b/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c index 54e28b4a5b2c50..59481be9aa8268 100644 --- a/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c +++ b/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c @@ -454,7 +454,7 @@ static int dcmipp_probe(struct platform_device *pdev) int irq; int ret; - dcmipp = devm_kzalloc(&pdev->dev, sizeof(*dcmipp), GFP_KERNEL); + dcmipp = devm_kzalloc_obj(&pdev->dev, *dcmipp); if (!dcmipp) return -ENOMEM; @@ -527,8 +527,8 @@ static int dcmipp_probe(struct platform_device *pdev) dcmipp->mclk = mclk; } - dcmipp->entity = devm_kcalloc(&pdev->dev, dcmipp->pipe_cfg->num_ents, - sizeof(*dcmipp->entity), GFP_KERNEL); + dcmipp->entity = devm_kzalloc_objs(&pdev->dev, *dcmipp->entity, + dcmipp->pipe_cfg->num_ents); if (!dcmipp->entity) return -ENOMEM; diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c index e53a07b770b7e8..cf34574c5c1520 100644 --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c @@ -167,7 +167,7 @@ static int sun4i_csi_probe(struct platform_device *pdev) int ret; int irq; - csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(&pdev->dev, *csi); if (!csi) return -ENOMEM; platform_set_drvdata(pdev, csi); diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index af2a32c226a55c..66fdc57cfe953a 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -322,7 +322,7 @@ static int sun6i_csi_probe(struct platform_device *platform_dev) struct device *dev = &platform_dev->dev; int ret; - csi_dev = devm_kzalloc(dev, sizeof(*csi_dev), GFP_KERNEL); + csi_dev = devm_kzalloc_obj(dev, *csi_dev); if (!csi_dev) return -ENOMEM; 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 index dcc8c7eadf9ac0..04c02fecce8e4c 100644 --- a/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c +++ b/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c @@ -717,7 +717,7 @@ static int sun6i_mipi_csi2_probe(struct platform_device *platform_dev) struct device *dev = &platform_dev->dev; int ret; - csi2_dev = devm_kzalloc(dev, sizeof(*csi2_dev), GFP_KERNEL); + csi2_dev = devm_kzalloc_obj(dev, *csi2_dev); if (!csi2_dev) return -ENOMEM; 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 index 46604dcc8dcc46..a5e3815a8976d5 100644 --- 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 @@ -783,7 +783,7 @@ static int sun8i_a83t_mipi_csi2_probe(struct platform_device *platform_dev) struct device *dev = &platform_dev->dev; int ret; - csi2_dev = devm_kzalloc(dev, sizeof(*csi2_dev), GFP_KERNEL); + csi2_dev = devm_kzalloc_obj(dev, *csi2_dev); if (!csi2_dev) return -ENOMEM; diff --git a/drivers/media/platform/sunxi/sun8i-di/sun8i-di.c b/drivers/media/platform/sunxi/sun8i-di/sun8i-di.c index 65bc426e5aac19..e00be61ba324bb 100644 --- a/drivers/media/platform/sunxi/sun8i-di/sun8i-di.c +++ b/drivers/media/platform/sunxi/sun8i-di/sun8i-di.c @@ -800,7 +800,7 @@ static int deinterlace_probe(struct platform_device *pdev) struct video_device *vfd; int irq, ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c index 7bff23d1ea9835..b603f70dc6cf44 100644 --- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c +++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c @@ -734,7 +734,7 @@ static int rotate_probe(struct platform_device *pdev) struct video_device *vfd; int irq, ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c index b7247d597c9cc0..2e961bfadbcf9d 100644 --- a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c +++ b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c @@ -956,7 +956,7 @@ static int dw_mipi_csi2rx_probe(struct platform_device *pdev) struct dw_mipi_csi2rx_device *csi2; int ret; - csi2 = devm_kzalloc(dev, sizeof(*csi2), GFP_KERNEL); + csi2 = devm_kzalloc_obj(dev, *csi2); if (!csi2) return -ENOMEM; csi2->dev = dev; diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c index c62614077d972c..713aa95be8179f 100644 --- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c +++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c @@ -2950,7 +2950,7 @@ static int hdmirx_probe(struct platform_device *pdev) struct v4l2_device *v4l2_dev; int ret; - hdmirx_dev = devm_kzalloc(dev, sizeof(*hdmirx_dev), GFP_KERNEL); + hdmirx_dev = devm_kzalloc_obj(dev, *hdmirx_dev); if (!hdmirx_dev) return -ENOMEM; diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx_cec.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx_cec.c index 8e470c0376d615..7305e4c42c3449 100644 --- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx_cec.c +++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx_cec.c @@ -202,7 +202,7 @@ struct hdmirx_cec *snps_hdmirx_cec_register(struct hdmirx_cec_data *data) * hardware device here, so that userspace can see the association * between the HDMI hardware and its associated CEC chardev. */ - cec = devm_kzalloc(data->dev, sizeof(*cec), GFP_KERNEL); + cec = devm_kzalloc_obj(data->dev, *cec); if (!cec) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/ti/am437x/am437x-vpfe.c b/drivers/media/platform/ti/am437x/am437x-vpfe.c index 3cd5ee69d3c4f8..83450f1588b780 100644 --- a/drivers/media/platform/ti/am437x/am437x-vpfe.c +++ b/drivers/media/platform/ti/am437x/am437x-vpfe.c @@ -2300,7 +2300,7 @@ vpfe_get_pdata(struct vpfe_device *vpfe) if (!IS_ENABLED(CONFIG_OF) || !dev->of_node) return dev->platform_data; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -2390,7 +2390,7 @@ static int vpfe_probe(struct platform_device *pdev) struct vpfe_ccdc *ccdc; int ret; - vpfe = devm_kzalloc(&pdev->dev, sizeof(*vpfe), GFP_KERNEL); + vpfe = devm_kzalloc_obj(&pdev->dev, *vpfe); if (!vpfe) return -ENOMEM; @@ -2447,10 +2447,8 @@ static int vpfe_probe(struct platform_device *pdev) pm_runtime_put_sync(&pdev->dev); - vpfe->sd = devm_kcalloc(&pdev->dev, - ARRAY_SIZE(vpfe->cfg->asd), - sizeof(struct v4l2_subdev *), - GFP_KERNEL); + vpfe->sd = devm_kzalloc_objs(&pdev->dev, struct v4l2_subdev *, + ARRAY_SIZE(vpfe->cfg->asd)); if (!vpfe->sd) { ret = -ENOMEM; goto probe_out_cleanup; diff --git a/drivers/media/platform/ti/cal/cal-camerarx.c b/drivers/media/platform/ti/cal/cal-camerarx.c index a978d27fe0295e..6bbe600499b9ac 100644 --- a/drivers/media/platform/ti/cal/cal-camerarx.c +++ b/drivers/media/platform/ti/cal/cal-camerarx.c @@ -966,7 +966,7 @@ struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal, unsigned int i; int ret; - phy = devm_kzalloc(cal->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(cal->dev, *phy); if (!phy) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/ti/cal/cal-video.c b/drivers/media/platform/ti/cal/cal-video.c index 1990cab7734470..ed8d67cf00bce0 100644 --- a/drivers/media/platform/ti/cal/cal-video.c +++ b/drivers/media/platform/ti/cal/cal-video.c @@ -862,8 +862,8 @@ static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx) int ret = 0; /* Enumerate sub device formats and enable all matching local formats */ - ctx->active_fmt = devm_kcalloc(ctx->cal->dev, cal_num_formats, - sizeof(*ctx->active_fmt), GFP_KERNEL); + ctx->active_fmt = devm_kzalloc_objs(ctx->cal->dev, *ctx->active_fmt, + cal_num_formats); if (!ctx->active_fmt) return -ENOMEM; diff --git a/drivers/media/platform/ti/cal/cal.c b/drivers/media/platform/ti/cal/cal.c index 5c82378d1eeedd..c3c1073739a508 100644 --- a/drivers/media/platform/ti/cal/cal.c +++ b/drivers/media/platform/ti/cal/cal.c @@ -1147,7 +1147,7 @@ static int cal_probe(struct platform_device *pdev) int ret; int irq; - cal = devm_kzalloc(&pdev->dev, sizeof(*cal), GFP_KERNEL); + cal = devm_kzalloc_obj(&pdev->dev, *cal); if (!cal) return -ENOMEM; diff --git a/drivers/media/platform/ti/davinci/vpif_capture.c b/drivers/media/platform/ti/davinci/vpif_capture.c index 397f3115af5b7d..e7836bc6ad3eef 100644 --- a/drivers/media/platform/ti/davinci/vpif_capture.c +++ b/drivers/media/platform/ti/davinci/vpif_capture.c @@ -1502,14 +1502,12 @@ vpif_capture_get_pdata(struct platform_device *pdev, if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) return pdev->dev.platform_data; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return NULL; pdata->subdev_info = - devm_kcalloc(&pdev->dev, - VPIF_CAPTURE_NUM_CHANNELS, - sizeof(*pdata->subdev_info), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, *pdata->subdev_info, + VPIF_CAPTURE_NUM_CHANNELS); if (!pdata->subdev_info) return NULL; @@ -1529,10 +1527,8 @@ vpif_capture_get_pdata(struct platform_device *pdev, sdinfo = &pdata->subdev_info[i]; chan = &pdata->chan_config[i]; - chan->inputs = devm_kcalloc(&pdev->dev, - VPIF_CAPTURE_NUM_CHANNELS, - sizeof(*chan->inputs), - GFP_KERNEL); + chan->inputs = devm_kzalloc_objs(&pdev->dev, *chan->inputs, + VPIF_CAPTURE_NUM_CHANNELS); if (!chan->inputs) goto err_cleanup; diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c index 022ea3d616c9e1..ba7abb723da6f6 100644 --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c @@ -1698,7 +1698,7 @@ static int ti_csi2rx_probe(struct platform_device *pdev) struct ti_csi2rx_dev *csi; int ret = 0, i, count; - csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(&pdev->dev, *csi); if (!csi) return -ENOMEM; diff --git a/drivers/media/platform/ti/vpe/csc.c b/drivers/media/platform/ti/vpe/csc.c index ff15bc589f1bc9..328557b1a1dac2 100644 --- a/drivers/media/platform/ti/vpe/csc.c +++ b/drivers/media/platform/ti/vpe/csc.c @@ -250,7 +250,7 @@ struct csc_data *csc_create(struct platform_device *pdev, const char *res_name) dev_dbg(&pdev->dev, "csc_create\n"); - csc = devm_kzalloc(&pdev->dev, sizeof(*csc), GFP_KERNEL); + csc = devm_kzalloc_obj(&pdev->dev, *csc); if (!csc) { dev_err(&pdev->dev, "couldn't alloc csc_data\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/ti/vpe/sc.c b/drivers/media/platform/ti/vpe/sc.c index 0202d278523fb3..f01a155add39e7 100644 --- a/drivers/media/platform/ti/vpe/sc.c +++ b/drivers/media/platform/ti/vpe/sc.c @@ -278,7 +278,7 @@ struct sc_data *sc_create(struct platform_device *pdev, const char *res_name) dev_dbg(&pdev->dev, "sc_create\n"); - sc = devm_kzalloc(&pdev->dev, sizeof(*sc), GFP_KERNEL); + sc = devm_kzalloc_obj(&pdev->dev, *sc); if (!sc) { dev_err(&pdev->dev, "couldn't alloc sc_data\n"); return ERR_PTR(-ENOMEM); diff --git a/drivers/media/platform/ti/vpe/vip.c b/drivers/media/platform/ti/vpe/vip.c index 2bbe8eb3155591..9f71cf0ffa6a13 100644 --- a/drivers/media/platform/ti/vpe/vip.c +++ b/drivers/media/platform/ti/vpe/vip.c @@ -3248,7 +3248,7 @@ static int alloc_port(struct vip_dev *dev, int id) if (dev->ports[id]) return -EINVAL; - port = devm_kzalloc(&dev->pdev->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(&dev->pdev->dev, *port); if (!port) return -ENOMEM; @@ -3424,7 +3424,7 @@ static int vip_probe_complete(struct platform_device *pdev) int ret, i, slice_id, port_id, p; /* Allocate ctrl before using it */ - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -3491,7 +3491,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice) struct csc_data *csc; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; @@ -3518,7 +3518,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice) vip_top_reset(dev); vip_set_slice_path(dev, VIP_MULTI_CHANNEL_DATA_SELECT, 1); - parser = devm_kzalloc(&pdev->dev, sizeof(*dev->parser), GFP_KERNEL); + parser = devm_kzalloc_obj(&pdev->dev, *dev->parser); if (!parser) return -ENOMEM; @@ -3530,7 +3530,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice) dev->parser = parser; dev->sc_assigned = VIP_NOT_ASSIGNED; - sc = devm_kzalloc(&pdev->dev, sizeof(*dev->sc), GFP_KERNEL); + sc = devm_kzalloc_obj(&pdev->dev, *dev->sc); if (!sc) return -ENOMEM; @@ -3542,7 +3542,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice) dev->sc = sc; dev->csc_assigned = VIP_NOT_ASSIGNED; - csc = devm_kzalloc(&pdev->dev, sizeof(*dev->csc), GFP_KERNEL); + csc = devm_kzalloc_obj(&pdev->dev, *dev->csc); if (!csc) return -ENOMEM; @@ -3575,7 +3575,7 @@ static int vip_probe(struct platform_device *pdev) return ret; } - shared = devm_kzalloc(&pdev->dev, sizeof(*shared), GFP_KERNEL); + shared = devm_kzalloc_obj(&pdev->dev, *shared); if (!shared) return -ENOMEM; diff --git a/drivers/media/platform/ti/vpe/vpe.c b/drivers/media/platform/ti/vpe/vpe.c index 81bd1f9cee302c..9eca5edc492055 100644 --- a/drivers/media/platform/ti/vpe/vpe.c +++ b/drivers/media/platform/ti/vpe/vpe.c @@ -2522,7 +2522,7 @@ static int vpe_probe(struct platform_device *pdev) return ret; } - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 26e5d5547466e2..3734ea701145a4 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -886,7 +886,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid) int ret; match = of_match_node(of_hantro_match, vpu->dev->of_node); - func = devm_kzalloc(vpu->dev, sizeof(*func), GFP_KERNEL); + func = devm_kzalloc_obj(vpu->dev, *func); if (!func) { v4l2_err(&vpu->v4l2_dev, "Failed to allocate video device\n"); return -ENOMEM; @@ -1076,7 +1076,7 @@ static int hantro_probe(struct platform_device *pdev) int num_bases; int i, ret; - vpu = devm_kzalloc(&pdev->dev, sizeof(*vpu), GFP_KERNEL); + vpu = devm_kzalloc_obj(&pdev->dev, *vpu); if (!vpu) return -ENOMEM; @@ -1103,8 +1103,8 @@ static int hantro_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&vpu->watchdog_work, hantro_watchdog); - vpu->clocks = devm_kcalloc(&pdev->dev, vpu->variant->num_clocks, - sizeof(*vpu->clocks), GFP_KERNEL); + vpu->clocks = devm_kzalloc_objs(&pdev->dev, *vpu->clocks, + vpu->variant->num_clocks); if (!vpu->clocks) return -ENOMEM; @@ -1131,8 +1131,8 @@ static int hantro_probe(struct platform_device *pdev) return PTR_ERR(vpu->resets); num_bases = vpu->variant->num_regs ?: 1; - vpu->reg_bases = devm_kcalloc(&pdev->dev, num_bases, - sizeof(*vpu->reg_bases), GFP_KERNEL); + vpu->reg_bases = devm_kzalloc_objs(&pdev->dev, *vpu->reg_bases, + num_bases); if (!vpu->reg_bases) return -ENOMEM; diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index b253b260b605d3..c4b28a64c6f20d 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -397,7 +397,7 @@ static int video_mux_probe(struct platform_device *pdev) unsigned int i; int ret; - vmux = devm_kzalloc(dev, sizeof(*vmux), GFP_KERNEL); + vmux = devm_kzalloc_obj(dev, *vmux); if (!vmux) return -ENOMEM; @@ -433,8 +433,7 @@ static int video_mux_probe(struct platform_device *pdev) mutex_init(&vmux->lock); vmux->active = -1; - vmux->pads = devm_kcalloc(dev, num_pads, sizeof(*vmux->pads), - GFP_KERNEL); + vmux->pads = devm_kzalloc_objs(dev, *vmux->pads, num_pads); if (!vmux->pads) return -ENOMEM; diff --git a/drivers/media/platform/xilinx/xilinx-csi2rxss.c b/drivers/media/platform/xilinx/xilinx-csi2rxss.c index 2f6f3af4e492c5..55e86e2a5ce9dd 100644 --- a/drivers/media/platform/xilinx/xilinx-csi2rxss.c +++ b/drivers/media/platform/xilinx/xilinx-csi2rxss.c @@ -906,7 +906,7 @@ static int xcsi2rxss_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int irq, ret; - xcsi2rxss = devm_kzalloc(dev, sizeof(*xcsi2rxss), GFP_KERNEL); + xcsi2rxss = devm_kzalloc_obj(dev, *xcsi2rxss); if (!xcsi2rxss) return -ENOMEM; diff --git a/drivers/media/platform/xilinx/xilinx-tpg.c b/drivers/media/platform/xilinx/xilinx-tpg.c index bf39ddb9c2967b..d37c22d6eafdd4 100644 --- a/drivers/media/platform/xilinx/xilinx-tpg.c +++ b/drivers/media/platform/xilinx/xilinx-tpg.c @@ -764,7 +764,7 @@ static int xtpg_probe(struct platform_device *pdev) u32 i, bayer_phase; int ret; - xtpg = devm_kzalloc(&pdev->dev, sizeof(*xtpg), GFP_KERNEL); + xtpg = devm_kzalloc_obj(&pdev->dev, *xtpg); if (!xtpg) return -ENOMEM; diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c index 30675f68141004..786e4f2e666eaf 100644 --- a/drivers/media/platform/xilinx/xilinx-vipp.c +++ b/drivers/media/platform/xilinx/xilinx-vipp.c @@ -429,7 +429,7 @@ static int xvip_graph_dma_init_one(struct xvip_composite_device *xdev, of_property_read_u32(node, "reg", &index); - dma = devm_kzalloc(xdev->dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(xdev->dev, *dma); if (dma == NULL) return -ENOMEM; @@ -569,7 +569,7 @@ static int xvip_composite_probe(struct platform_device *pdev) struct xvip_composite_device *xdev; int ret; - xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(&pdev->dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/media/platform/xilinx/xilinx-vtc.c b/drivers/media/platform/xilinx/xilinx-vtc.c index 92fec7bb47dae8..a344cab2b7a952 100644 --- a/drivers/media/platform/xilinx/xilinx-vtc.c +++ b/drivers/media/platform/xilinx/xilinx-vtc.c @@ -321,7 +321,7 @@ static int xvtc_probe(struct platform_device *pdev) struct xvtc_device *xvtc; int ret; - xvtc = devm_kzalloc(&pdev->dev, sizeof(*xvtc), GFP_KERNEL); + xvtc = devm_kzalloc_obj(&pdev->dev, *xvtc); if (!xvtc) return -ENOMEM; diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c index bfe89782dce438..32fc128d9d258d 100644 --- a/drivers/media/radio/radio-si476x.c +++ b/drivers/media/radio/radio-si476x.c @@ -1381,7 +1381,7 @@ static int si476x_radio_probe(struct platform_device *pdev) static atomic_t instance = ATOMIC_INIT(0); - radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL); + radio = devm_kzalloc_obj(&pdev->dev, *radio); if (!radio) return -ENOMEM; diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c index a6069b106fd304..534bb40bbe41b5 100644 --- a/drivers/media/radio/radio-timb.c +++ b/drivers/media/radio/radio-timb.c @@ -96,7 +96,7 @@ static int timbradio_probe(struct platform_device *pdev) goto err; } - tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL); + tr = devm_kzalloc_obj(&pdev->dev, *tr); if (!tr) { err = -ENOMEM; goto err; diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c index a1e570af9c59b2..3139912d7ca87d 100644 --- a/drivers/media/radio/si470x/radio-si470x-i2c.c +++ b/drivers/media/radio/si470x/radio-si470x-i2c.c @@ -336,7 +336,7 @@ static int si470x_i2c_probe(struct i2c_client *client) int retval = 0; /* private data allocation and initialization */ - radio = devm_kzalloc(&client->dev, sizeof(*radio), GFP_KERNEL); + radio = devm_kzalloc_obj(&client->dev, *radio); if (!radio) { retval = -ENOMEM; goto err_initial; diff --git a/drivers/media/radio/si4713/radio-platform-si4713.c b/drivers/media/radio/si4713/radio-platform-si4713.c index 4132968110e3c5..b2bcd0ae970ec0 100644 --- a/drivers/media/radio/si4713/radio-platform-si4713.c +++ b/drivers/media/radio/si4713/radio-platform-si4713.c @@ -146,7 +146,7 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev) goto exit; } - rsdev = devm_kzalloc(&pdev->dev, sizeof(*rsdev), GFP_KERNEL); + rsdev = devm_kzalloc_obj(&pdev->dev, *rsdev); if (!rsdev) { dev_err(&pdev->dev, "Failed to alloc video device.\n"); rval = -ENOMEM; diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c index 150d07f6b3196a..2320d9dee684c0 100644 --- a/drivers/media/radio/si4713/si4713.c +++ b/drivers/media/radio/si4713/si4713.c @@ -1437,7 +1437,7 @@ static int si4713_probe(struct i2c_client *client) struct platform_device *si4713_pdev; int rval; - sdev = devm_kzalloc(&client->dev, sizeof(*sdev), GFP_KERNEL); + sdev = devm_kzalloc_obj(&client->dev, *sdev); if (!sdev) { dev_err(&client->dev, "Failed to alloc video device.\n"); rval = -ENOMEM; diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c index a6418ef782bc2a..eaa11730456399 100644 --- a/drivers/media/rc/gpio-ir-recv.c +++ b/drivers/media/rc/gpio-ir-recv.c @@ -66,7 +66,7 @@ static int gpio_ir_recv_probe(struct platform_device *pdev) if (!np) return -ENODEV; - gpio_dev = devm_kzalloc(dev, sizeof(*gpio_dev), GFP_KERNEL); + gpio_dev = devm_kzalloc_obj(dev, *gpio_dev); if (!gpio_dev) return -ENOMEM; diff --git a/drivers/media/rc/gpio-ir-tx.c b/drivers/media/rc/gpio-ir-tx.c index d15fb17fa0fa10..bbc27f24c6e2e6 100644 --- a/drivers/media/rc/gpio-ir-tx.c +++ b/drivers/media/rc/gpio-ir-tx.c @@ -161,7 +161,7 @@ static int gpio_ir_tx_probe(struct platform_device *pdev) struct rc_dev *rcdev; int rc; - gpio_ir = devm_kmalloc(&pdev->dev, sizeof(*gpio_ir), GFP_KERNEL); + gpio_ir = devm_kmalloc_obj(&pdev->dev, *gpio_ir); if (!gpio_ir) return -ENOMEM; diff --git a/drivers/media/rc/igorplugusb.c b/drivers/media/rc/igorplugusb.c index 7758487da3d3bd..37339f80c7e76f 100644 --- a/drivers/media/rc/igorplugusb.c +++ b/drivers/media/rc/igorplugusb.c @@ -160,7 +160,7 @@ static int igorplugusb_probe(struct usb_interface *intf, return -ENODEV; } - ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL); + ir = devm_kzalloc_obj(&intf->dev, *ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/rc/img-ir/img-ir-core.c b/drivers/media/rc/img-ir/img-ir-core.c index 067f4bc7fcc326..1eb8fd664041cd 100644 --- a/drivers/media/rc/img-ir/img-ir-core.c +++ b/drivers/media/rc/img-ir/img-ir-core.c @@ -84,7 +84,7 @@ static int img_ir_probe(struct platform_device *pdev) return irq; /* Private driver data */ - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/rc/imon_raw.c b/drivers/media/rc/imon_raw.c index 295acd6ba9e14b..0b7b358466518c 100644 --- a/drivers/media/rc/imon_raw.c +++ b/drivers/media/rc/imon_raw.c @@ -119,7 +119,7 @@ static int imon_probe(struct usb_interface *intf, return -ENODEV; } - imon = devm_kmalloc(&intf->dev, sizeof(*imon), GFP_KERNEL); + imon = devm_kmalloc_obj(&intf->dev, *imon); if (!imon) return -ENOMEM; @@ -127,7 +127,7 @@ static int imon_probe(struct usb_interface *intf, if (!imon->ir_urb) return -ENOMEM; - imon->ir_buf = kmalloc(sizeof(__be64), GFP_KERNEL); + imon->ir_buf = kmalloc_obj(__be64); if (!imon->ir_buf) { ret = -ENOMEM; goto free_urb; diff --git a/drivers/media/rc/ir-hix5hd2.c b/drivers/media/rc/ir-hix5hd2.c index aa3de4d57a585d..f74deb40821843 100644 --- a/drivers/media/rc/ir-hix5hd2.c +++ b/drivers/media/rc/ir-hix5hd2.c @@ -256,7 +256,7 @@ static int hix5hd2_ir_probe(struct platform_device *pdev) const char *map_name; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/media/rc/ir-spi.c b/drivers/media/rc/ir-spi.c index 31eb58b06c70e5..56afae360e7372 100644 --- a/drivers/media/rc/ir-spi.c +++ b/drivers/media/rc/ir-spi.c @@ -50,7 +50,7 @@ static int ir_spi_tx(struct rc_dev *dev, unsigned int *buffer, unsigned int coun len += buffer[i]; } - tx_buf = kmalloc_array(len, sizeof(*tx_buf), GFP_KERNEL); + tx_buf = kmalloc_objs(*tx_buf, len); if (!tx_buf) return -ENOMEM; @@ -131,7 +131,7 @@ static int ir_spi_probe(struct spi_device *spi) u8 dc; struct ir_spi_data *idata; - idata = devm_kzalloc(dev, sizeof(*idata), GFP_KERNEL); + idata = devm_kzalloc_obj(dev, *idata); if (!idata) return -ENOMEM; diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index f7b8f1f66d9bca..cb6419f27dc174 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -284,7 +284,7 @@ static ssize_t lirc_transmit(struct file *file, const char __user *buf, else count = ret; - txbuf = kmalloc_array(count, sizeof(unsigned int), GFP_KERNEL); + txbuf = kmalloc_objs(unsigned int, count); if (!txbuf) { ret = -ENOMEM; goto out_kfree_raw; diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c index a0d07da09f67af..8b6c16f2889676 100644 --- a/drivers/media/rc/meson-ir-tx.c +++ b/drivers/media/rc/meson-ir-tx.c @@ -257,7 +257,7 @@ static int meson_irtx_transmit(struct rc_dev *rc, unsigned int *buf, if (!meson_irtx_check_buf(ir, buf, len)) return -EINVAL; - tx_buf = kmalloc_array(len, sizeof(u32), GFP_KERNEL); + tx_buf = kmalloc_objs(u32, len); if (!tx_buf) return -ENOMEM; @@ -318,7 +318,7 @@ static int meson_irtx_probe(struct platform_device *pdev) unsigned int clk_nr; int ret; - ir = devm_kzalloc(dev, sizeof(*ir), GFP_KERNEL); + ir = devm_kzalloc_obj(dev, *ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c index 272ebb0d97c811..1db7ff0f60f0b9 100644 --- a/drivers/media/rc/meson-ir.c +++ b/drivers/media/rc/meson-ir.c @@ -451,7 +451,7 @@ static int meson_ir_probe(struct platform_device *pdev) struct meson_ir *ir; int irq, ret; - ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL); + ir = devm_kzalloc_obj(dev, struct meson_ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c index 85c9436b0a2004..9192ec160a35a0 100644 --- a/drivers/media/rc/mtk-cir.c +++ b/drivers/media/rc/mtk-cir.c @@ -300,7 +300,7 @@ static int mtk_ir_probe(struct platform_device *pdev) int ret = 0; const char *map_name; - ir = devm_kzalloc(dev, sizeof(struct mtk_ir), GFP_KERNEL); + ir = devm_kzalloc_obj(dev, struct mtk_ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c index 918258dadd6988..548c8bbc1467f4 100644 --- a/drivers/media/rc/nuvoton-cir.c +++ b/drivers/media/rc/nuvoton-cir.c @@ -918,7 +918,7 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) struct rc_dev *rdev; int ret; - nvt = devm_kzalloc(&pdev->dev, sizeof(struct nvt_dev), GFP_KERNEL); + nvt = devm_kzalloc_obj(&pdev->dev, struct nvt_dev); if (!nvt) return -ENOMEM; diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c index 047472dc9244af..1eb840ed023259 100644 --- a/drivers/media/rc/pwm-ir-tx.c +++ b/drivers/media/rc/pwm-ir-tx.c @@ -149,7 +149,7 @@ static int pwm_ir_probe(struct platform_device *pdev) struct rc_dev *rcdev; int rc; - pwm_ir = devm_kmalloc(&pdev->dev, sizeof(*pwm_ir), GFP_KERNEL); + pwm_ir = devm_kmalloc_obj(&pdev->dev, *pwm_ir); if (!pwm_ir) return -ENOMEM; diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index a867bf9e84166c..4bf645ac8d7b50 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -221,7 +221,7 @@ static int ir_create_table(struct rc_dev *dev, struct rc_map *rc_map, return -ENOMEM; alloc = roundup_pow_of_two(size); - scan = kmalloc_objs(struct rc_map_table, alloc, GFP_KERNEL); + scan = kmalloc_objs(struct rc_map_table, alloc); if (!scan) { kfree(name); return -ENOMEM; diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c index 0ba06bfc9e14b6..211e06e744130d 100644 --- a/drivers/media/rc/st_rc.c +++ b/drivers/media/rc/st_rc.c @@ -236,7 +236,7 @@ static int st_rc_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; const char *rx_mode; - rc_dev = devm_kzalloc(dev, sizeof(struct st_rc_device), GFP_KERNEL); + rc_dev = devm_kzalloc_obj(dev, struct st_rc_device); if (!rc_dev) return -ENOMEM; diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c index af1ee08ffdbec8..e97bd9e03c1f5e 100644 --- a/drivers/media/rc/sunxi-cir.c +++ b/drivers/media/rc/sunxi-cir.c @@ -260,7 +260,7 @@ static int sunxi_ir_probe(struct platform_device *pdev) struct sunxi_ir *ir; u32 b_clk_freq = SUNXI_IR_BASE_CLK; - ir = devm_kzalloc(dev, sizeof(struct sunxi_ir), GFP_KERNEL); + ir = devm_kzalloc_obj(dev, struct sunxi_ir); if (!ir) return -ENOMEM; diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c index 1ae036f8a2967d..04ed7a551d2880 100644 --- a/drivers/media/rc/winbond-cir.c +++ b/drivers/media/rc/winbond-cir.c @@ -629,7 +629,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count) unsigned i; unsigned long flags; - buf = kmalloc_array(count, sizeof(*b), GFP_KERNEL); + buf = kmalloc_objs(*b, count); if (!buf) return -ENOMEM; diff --git a/drivers/media/spi/gs1662.c b/drivers/media/spi/gs1662.c index 7adf55fd07074a..06159b880c7cb2 100644 --- a/drivers/media/spi/gs1662.c +++ b/drivers/media/spi/gs1662.c @@ -436,7 +436,7 @@ static int gs_probe(struct spi_device *spi) struct gs *gs; struct v4l2_subdev *sd; - gs = devm_kzalloc(&spi->dev, sizeof(struct gs), GFP_KERNEL); + gs = devm_kzalloc_obj(&spi->dev, struct gs); if (!gs) return -ENOMEM; diff --git a/drivers/media/tuners/mt2060.c b/drivers/media/tuners/mt2060.c index c57233c7441acd..f1853bf6905be5 100644 --- a/drivers/media/tuners/mt2060.c +++ b/drivers/media/tuners/mt2060.c @@ -458,7 +458,7 @@ static int mt2060_probe(struct i2c_client *client) goto err; } - dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&client->dev, *dev); if (!dev) { ret = -ENOMEM; goto err; diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c index b0941cd2a2d858..e4119a3bf2e33d 100644 --- a/drivers/media/usb/cx231xx/cx231xx-cards.c +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c @@ -1724,7 +1724,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, udev = interface_to_usbdev(interface); /* allocate memory for our device state and initialize it */ - dev = devm_kzalloc(&interface->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&interface->dev, *dev); if (dev == NULL) { retval = -ENOMEM; goto err_if; diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c index 7f0c5826ce5e4e..b25477ec20b458 100644 --- a/drivers/media/usb/em28xx/em28xx-audio.c +++ b/drivers/media/usb/em28xx/em28xx-audio.c @@ -751,9 +751,8 @@ static int em28xx_audio_urb_init(struct em28xx *dev) /* Allocate space to store the number of URBs to be used */ - dev->adev.transfer_buffer = kcalloc(num_urb, - sizeof(*dev->adev.transfer_buffer), - GFP_KERNEL); + dev->adev.transfer_buffer = kzalloc_objs(*dev->adev.transfer_buffer, + num_urb); if (!dev->adev.transfer_buffer) return -ENOMEM; diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index 8440eafad44eb2..1d4f30cba8de84 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -4202,9 +4202,8 @@ static int em28xx_usb_probe(struct usb_interface *intf, } /* compute alternate max packet sizes */ - dev->alt_max_pkt_size_isoc = kcalloc(intf->num_altsetting, - sizeof(dev->alt_max_pkt_size_isoc[0]), - GFP_KERNEL); + dev->alt_max_pkt_size_isoc = kzalloc_objs(dev->alt_max_pkt_size_isoc[0], + intf->num_altsetting); if (!dev->alt_max_pkt_size_isoc) { kfree(dev); retval = -ENOMEM; diff --git a/drivers/media/usb/stk1160/stk1160-core.c b/drivers/media/usb/stk1160/stk1160-core.c index 5058cada0d0a3b..e1e9cfc6c290c1 100644 --- a/drivers/media/usb/stk1160/stk1160-core.c +++ b/drivers/media/usb/stk1160/stk1160-core.c @@ -279,9 +279,8 @@ static int stk1160_probe(struct usb_interface *interface, return -ENODEV; /* Alloc an array for all possible max_pkt_size */ - alt_max_pkt_size = kmalloc_array(interface->num_altsetting, - sizeof(alt_max_pkt_size[0]), - GFP_KERNEL); + alt_max_pkt_size = kmalloc_objs(alt_max_pkt_size[0], + interface->num_altsetting); if (alt_max_pkt_size == NULL) return -ENOMEM; diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 11ab684024c542..ae72911f560cc5 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -674,7 +674,7 @@ void v4l2_simplify_fraction(u32 *numerator, u32 *denominator, u32 x, y, r; unsigned int i, n; - an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL); + an = kmalloc_objs(*an, n_terms); if (an == NULL) return; diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c index 163badeef76f2e..2587544c6a2ef6 100644 --- a/drivers/media/v4l2-core/v4l2-flash-led-class.c +++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c @@ -435,10 +435,9 @@ static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash, struct v4l2_ctrl_config *ctrl_cfg; int i, ret, num_ctrls = 0; - v4l2_flash->ctrls = devm_kcalloc(v4l2_flash->sd.dev, - STROBE_SOURCE + 1, - sizeof(*v4l2_flash->ctrls), - GFP_KERNEL); + v4l2_flash->ctrls = devm_kzalloc_objs(v4l2_flash->sd.dev, + *v4l2_flash->ctrls, + STROBE_SOURCE + 1); if (!v4l2_flash->ctrls) return -ENOMEM; @@ -661,7 +660,7 @@ static struct v4l2_flash *__v4l2_flash_init( if (!config) return ERR_PTR(-EINVAL); - v4l2_flash = devm_kzalloc(dev, sizeof(*v4l2_flash), GFP_KERNEL); + v4l2_flash = devm_kzalloc_obj(dev, *v4l2_flash); if (!v4l2_flash) return ERR_PTR(-ENOMEM); diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 570df3c415b0a4..9958d3c64f98d4 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -581,8 +581,7 @@ int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode, unsigned int i; vep->link_frequencies = - kmalloc_array(rval, sizeof(*vep->link_frequencies), - GFP_KERNEL); + kmalloc_objs(*vep->link_frequencies, rval); if (!vep->link_frequencies) return -ENOMEM; diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index a07d77e584c311..ca77aebcd8feab 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2174,8 +2174,7 @@ int v4l2_subdev_routing_validate(struct v4l2_subdev *sd, if (disallow & (V4L2_SUBDEV_ROUTING_NO_STREAM_MIX | V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING)) { - remote_pads = kcalloc(sd->entity.num_pads, sizeof(*remote_pads), - GFP_KERNEL); + remote_pads = kzalloc_objs(*remote_pads, sd->entity.num_pads); if (!remote_pads) return -ENOMEM; diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c index 1e8e8aba2542da..cf6b404afaf1fb 100644 --- a/drivers/memory/atmel-ebi.c +++ b/drivers/memory/atmel-ebi.c @@ -332,8 +332,7 @@ static int atmel_ebi_dev_setup(struct atmel_ebi *ebi, struct device_node *np, return -EINVAL; } - ebid = devm_kzalloc(ebi->dev, struct_size(ebid, configs, numcs), - GFP_KERNEL); + ebid = devm_kzalloc_flex(ebi->dev, *ebid, configs, numcs); if (!ebid) return -ENOMEM; @@ -498,7 +497,7 @@ static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np) struct device *dev = ebi->dev; struct property *newprop; - newprop = devm_kzalloc(dev, sizeof(*newprop), GFP_KERNEL); + newprop = devm_kzalloc_obj(dev, *newprop); if (!newprop) return -ENOMEM; @@ -524,7 +523,7 @@ static int atmel_ebi_probe(struct platform_device *pdev) struct clk *clk; u32 val; - ebi = devm_kzalloc(dev, sizeof(*ebi), GFP_KERNEL); + ebi = devm_kzalloc_obj(dev, *ebi); if (!ebi) return -ENOMEM; diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c index 04ae3cfb449e45..aeae9874652c18 100644 --- a/drivers/memory/brcmstb_dpfe.c +++ b/drivers/memory/brcmstb_dpfe.c @@ -877,7 +877,7 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev) struct resource *res; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/memory/brcmstb_memc.c b/drivers/memory/brcmstb_memc.c index c28fe90936168a..946736e3cb7495 100644 --- a/drivers/memory/brcmstb_memc.c +++ b/drivers/memory/brcmstb_memc.c @@ -131,7 +131,7 @@ static int brcmstb_memc_probe(struct platform_device *pdev) struct brcmstb_memc *memc; int ret; - memc = devm_kzalloc(dev, sizeof(*memc), GFP_KERNEL); + memc = devm_kzalloc_obj(dev, *memc); if (!memc) return -ENOMEM; diff --git a/drivers/memory/dfl-emif.c b/drivers/memory/dfl-emif.c index da06cd30a01617..e2de20b4ba808c 100644 --- a/drivers/memory/dfl-emif.c +++ b/drivers/memory/dfl-emif.c @@ -223,7 +223,7 @@ static int dfl_emif_probe(struct dfl_device *ddev) struct device *dev = &ddev->dev; struct dfl_emif *de; - de = devm_kzalloc(dev, sizeof(*de), GFP_KERNEL); + de = devm_kzalloc_obj(dev, *de); if (!de) return -ENOMEM; diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c index 886c2ca0dc19d4..b5d41ebb19f33d 100644 --- a/drivers/memory/emif.c +++ b/drivers/memory/emif.c @@ -836,8 +836,7 @@ static void of_get_custom_configs(struct device_node *np_emif, poll_intvl = of_get_property(np_emif, "temp-alert-poll-interval", &len); if (lpmode || poll_intvl) - cust_cfgs = devm_kzalloc(emif->dev, sizeof(*cust_cfgs), - GFP_KERNEL); + cust_cfgs = devm_kzalloc_obj(emif->dev, *cust_cfgs); if (!cust_cfgs) return; @@ -915,9 +914,9 @@ static struct emif_data *of_get_memory_device_details( np_ddr = of_parse_phandle(np_emif, "device-handle", 0); if (!np_ddr) goto error; - emif = devm_kzalloc(dev, sizeof(struct emif_data), GFP_KERNEL); - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); - dev_info = devm_kzalloc(dev, sizeof(*dev_info), GFP_KERNEL); + emif = devm_kzalloc_obj(dev, struct emif_data); + pd = devm_kzalloc_obj(dev, *pd); + dev_info = devm_kzalloc_obj(dev, *dev_info); if (!emif || !pd || !dev_info) { dev_err(dev, "%s: Out of memory!!\n", @@ -999,9 +998,9 @@ static struct emif_data *get_device_details( goto error; } - emif = devm_kzalloc(dev, sizeof(*emif), GFP_KERNEL); - temp = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); - dev_info = devm_kzalloc(dev, sizeof(*dev_info), GFP_KERNEL); + emif = devm_kzalloc_obj(dev, *emif); + temp = devm_kzalloc_obj(dev, *pd); + dev_info = devm_kzalloc_obj(dev, *dev_info); if (!emif || !temp || !dev_info) goto error; @@ -1040,7 +1039,7 @@ static struct emif_data *get_device_details( */ cust_cfgs = pd->custom_configs; if (cust_cfgs && is_custom_config_valid(cust_cfgs, dev)) { - temp = devm_kzalloc(dev, sizeof(*cust_cfgs), GFP_KERNEL); + temp = devm_kzalloc_obj(dev, *cust_cfgs); if (temp) memcpy(temp, cust_cfgs, sizeof(*cust_cfgs)); pd->custom_configs = temp; @@ -1064,8 +1063,7 @@ static struct emif_data *get_device_details( } if (pd->min_tck) { - temp = devm_kzalloc(dev, sizeof(struct lpddr2_min_tck), - GFP_KERNEL); + temp = devm_kzalloc_obj(dev, struct lpddr2_min_tck); if (temp) { memcpy(temp, pd->min_tck, sizeof(*pd->min_tck)); pd->min_tck = temp; diff --git a/drivers/memory/fsl-corenet-cf.c b/drivers/memory/fsl-corenet-cf.c index ecd6c19551532c..4fa5cd20df940a 100644 --- a/drivers/memory/fsl-corenet-cf.c +++ b/drivers/memory/fsl-corenet-cf.c @@ -173,7 +173,7 @@ static int ccf_probe(struct platform_device *pdev) u32 errinten; int ret, irq; - ccf = devm_kzalloc(&pdev->dev, sizeof(*ccf), GFP_KERNEL); + ccf = devm_kzalloc_obj(&pdev->dev, *ccf); if (!ccf) return -ENOMEM; diff --git a/drivers/memory/fsl_ifc.c b/drivers/memory/fsl_ifc.c index e89e0c6cc4bccc..db2d239aeba890 100644 --- a/drivers/memory/fsl_ifc.c +++ b/drivers/memory/fsl_ifc.c @@ -207,8 +207,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev) dev_info(&dev->dev, "Freescale Integrated Flash Controller\n"); - fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev), - GFP_KERNEL); + fsl_ifc_ctrl_dev = devm_kzalloc_obj(&dev->dev, *fsl_ifc_ctrl_dev); if (!fsl_ifc_ctrl_dev) return -ENOMEM; diff --git a/drivers/memory/jz4780-nemc.c b/drivers/memory/jz4780-nemc.c index 1bf17057cbf55f..36fc05609ff84a 100644 --- a/drivers/memory/jz4780-nemc.c +++ b/drivers/memory/jz4780-nemc.c @@ -278,7 +278,7 @@ static int jz4780_nemc_probe(struct platform_device *pdev) unsigned long referenced; int i, ret; - nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL); + nemc = devm_kzalloc_obj(dev, *nemc); if (!nemc) return -ENOMEM; diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c index 8c4606cbd73d91..66bc2289f6352f 100644 --- a/drivers/memory/mtk-smi.c +++ b/drivers/memory/mtk-smi.c @@ -679,7 +679,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); + larb = devm_kzalloc_obj(dev, *larb); if (!larb) return -ENOMEM; @@ -912,7 +912,7 @@ static int mtk_smi_common_probe(struct platform_device *pdev) struct mtk_smi *common; int ret, clk_required = MTK_SMI_COM_REQ_CLK_NR; - common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); + common = devm_kzalloc_obj(dev, *common); if (!common) return -ENOMEM; common->dev = dev; diff --git a/drivers/memory/mvebu-devbus.c b/drivers/memory/mvebu-devbus.c index 406fddcdba02a0..3050f718919ca7 100644 --- a/drivers/memory/mvebu-devbus.c +++ b/drivers/memory/mvebu-devbus.c @@ -271,7 +271,7 @@ static int mvebu_devbus_probe(struct platform_device *pdev) unsigned long rate; int err; - devbus = devm_kzalloc(&pdev->dev, sizeof(struct devbus), GFP_KERNEL); + devbus = devm_kzalloc_obj(&pdev->dev, struct devbus); if (!devbus) return -ENOMEM; diff --git a/drivers/memory/of_memory.c b/drivers/memory/of_memory.c index fcd20d85d38574..c834b2a94744b5 100644 --- a/drivers/memory/of_memory.c +++ b/drivers/memory/of_memory.c @@ -31,7 +31,7 @@ const struct lpddr2_min_tck *of_get_min_tck(struct device_node *np, int ret = 0; struct lpddr2_min_tck *min; - min = devm_kzalloc(dev, sizeof(*min), GFP_KERNEL); + min = devm_kzalloc_obj(dev, *min); if (!min) goto default_min_tck; @@ -125,8 +125,7 @@ const struct lpddr2_timings *of_get_ddr_timings(struct device_node *np_ddr, arr_sz++; if (arr_sz) - timings = devm_kcalloc(dev, arr_sz, sizeof(*timings), - GFP_KERNEL); + timings = devm_kzalloc_objs(dev, *timings, arr_sz); if (!timings) goto default_timings; @@ -168,7 +167,7 @@ const struct lpddr3_min_tck *of_lpddr3_get_min_tck(struct device_node *np, int ret = 0; struct lpddr3_min_tck *min; - min = devm_kzalloc(dev, sizeof(*min), GFP_KERNEL); + min = devm_kzalloc_obj(dev, *min); if (!min) goto default_min_tck; @@ -275,8 +274,7 @@ const struct lpddr3_timings arr_sz++; if (arr_sz) - timings = devm_kcalloc(dev, arr_sz, sizeof(*timings), - GFP_KERNEL); + timings = devm_kzalloc_objs(dev, *timings, arr_sz); if (!timings) goto default_timings; @@ -389,7 +387,7 @@ const struct lpddr2_info if (!info.manufacturer_id) info.manufacturer_id = -ENOENT; - ret_info = devm_kzalloc(dev, sizeof(*ret_info), GFP_KERNEL); + ret_info = devm_kzalloc_obj(dev, *ret_info); if (ret_info) *ret_info = info; diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index 48af31a54b5583..e1d3388f48db52 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -2526,7 +2526,7 @@ static int gpmc_probe(struct platform_device *pdev) struct resource *res; struct gpmc_device *gpmc; - gpmc = devm_kzalloc(&pdev->dev, sizeof(*gpmc), GFP_KERNEL); + gpmc = devm_kzalloc_obj(&pdev->dev, *gpmc); if (!gpmc) return -ENOMEM; diff --git a/drivers/memory/pl172.c b/drivers/memory/pl172.c index be7ba599cccf31..e7490480e64043 100644 --- a/drivers/memory/pl172.c +++ b/drivers/memory/pl172.c @@ -219,7 +219,7 @@ static int pl172_probe(struct amba_device *adev, const struct amba_id *id) dev_info(dev, "ARM PL%x revision %s\n", amba_part(adev), rev); - pl172 = devm_kzalloc(dev, sizeof(*pl172), GFP_KERNEL); + pl172 = devm_kzalloc_obj(dev, *pl172); if (!pl172) return -ENOMEM; diff --git a/drivers/memory/pl353-smc.c b/drivers/memory/pl353-smc.c index 28a8cc56003cd9..5afd04c88dc4de 100644 --- a/drivers/memory/pl353-smc.c +++ b/drivers/memory/pl353-smc.c @@ -75,7 +75,7 @@ static int pl353_smc_probe(struct amba_device *adev, const struct amba_id *id) const struct of_device_id *match = NULL; struct pl353_smc_data *pl353_smc; - pl353_smc = devm_kzalloc(&adev->dev, sizeof(*pl353_smc), GFP_KERNEL); + pl353_smc = devm_kzalloc_obj(&adev->dev, *pl353_smc); if (!pl353_smc) return -ENOMEM; diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-if.c index ec901a5a99aaee..2058a4af131351 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -981,7 +981,7 @@ static int rpcif_probe(struct platform_device *pdev) } of_node_put(flash); - rpc = devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL); + rpc = devm_kzalloc_obj(dev, *rpc); if (!rpc) return -ENOMEM; diff --git a/drivers/memory/samsung/exynos-srom.c b/drivers/memory/samsung/exynos-srom.c index fcef4aed0292b0..d57221f5174210 100644 --- a/drivers/memory/samsung/exynos-srom.c +++ b/drivers/memory/samsung/exynos-srom.c @@ -115,8 +115,7 @@ static int exynos_srom_probe(struct platform_device *pdev) return -EINVAL; } - srom = devm_kzalloc(&pdev->dev, - sizeof(struct exynos_srom), GFP_KERNEL); + srom = devm_kzalloc_obj(&pdev->dev, struct exynos_srom); if (!srom) return -ENOMEM; diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c index 98c31955258315..076dc1c3e5f7a1 100644 --- a/drivers/memory/samsung/exynos5422-dmc.c +++ b/drivers/memory/samsung/exynos5422-dmc.c @@ -353,8 +353,7 @@ static int exynos5_init_freq_table(struct exynos5_dmc *dmc, dmc->opp_count = dev_pm_opp_get_opp_count(dev); - dmc->opp = devm_kmalloc_array(dev, dmc->opp_count, - sizeof(struct dmc_opp_table), GFP_KERNEL); + dmc->opp = devm_kmalloc_objs(dev, struct dmc_opp_table, dmc->opp_count); if (!dmc->opp) return -ENOMEM; @@ -1188,18 +1187,15 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc) return -EINVAL; } - dmc->timing_row = devm_kmalloc_array(dev, TIMING_COUNT, - sizeof(u32), GFP_KERNEL); + dmc->timing_row = devm_kmalloc_objs(dev, u32, TIMING_COUNT); if (!dmc->timing_row) return -ENOMEM; - dmc->timing_data = devm_kmalloc_array(dev, TIMING_COUNT, - sizeof(u32), GFP_KERNEL); + dmc->timing_data = devm_kmalloc_objs(dev, u32, TIMING_COUNT); if (!dmc->timing_data) return -ENOMEM; - dmc->timing_power = devm_kmalloc_array(dev, TIMING_COUNT, - sizeof(u32), GFP_KERNEL); + dmc->timing_power = devm_kmalloc_objs(dev, u32, TIMING_COUNT); if (!dmc->timing_power) return -ENOMEM; @@ -1338,8 +1334,7 @@ static int exynos5_performance_counters_init(struct exynos5_dmc *dmc) return dmc->num_counters; } - dmc->counter = devm_kcalloc(dev, dmc->num_counters, - sizeof(*dmc->counter), GFP_KERNEL); + dmc->counter = devm_kzalloc_objs(dev, *dmc->counter, dmc->num_counters); if (!dmc->counter) return -ENOMEM; @@ -1424,7 +1419,7 @@ static int exynos5_dmc_probe(struct platform_device *pdev) struct exynos5_dmc *dmc; int irq[2]; - dmc = devm_kzalloc(dev, sizeof(*dmc), GFP_KERNEL); + dmc = devm_kzalloc_obj(dev, *dmc); if (!dmc) return -ENOMEM; diff --git a/drivers/memory/stm32-fmc2-ebi.c b/drivers/memory/stm32-fmc2-ebi.c index 6e386ab5409159..7296014c3bd78e 100644 --- a/drivers/memory/stm32-fmc2-ebi.c +++ b/drivers/memory/stm32-fmc2-ebi.c @@ -1634,7 +1634,7 @@ static int stm32_fmc2_ebi_probe(struct platform_device *pdev) struct reset_control *rstc; int ret; - ebi = devm_kzalloc(&pdev->dev, sizeof(*ebi), GFP_KERNEL); + ebi = devm_kzalloc_obj(&pdev->dev, *ebi); if (!ebi) return -ENOMEM; diff --git a/drivers/memory/stm32_omm.c b/drivers/memory/stm32_omm.c index 3599683ab04ac1..e5d646e0a13cf2 100644 --- a/drivers/memory/stm32_omm.c +++ b/drivers/memory/stm32_omm.c @@ -303,7 +303,7 @@ static int stm32_omm_probe(struct platform_device *pdev) struct stm32_omm *omm; int i, ret; - omm = devm_kzalloc(dev, sizeof(*omm), GFP_KERNEL); + omm = devm_kzalloc_obj(dev, *omm); if (!omm) return -ENOMEM; diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c index 458ce99916ad64..de5e8bbc4ca00a 100644 --- a/drivers/memory/tegra/mc.c +++ b/drivers/memory/tegra/mc.c @@ -485,8 +485,7 @@ static int load_timings(struct tegra_mc *mc, struct device_node *node) int child_count = of_get_child_count(node); int i = 0, err; - mc->timings = devm_kcalloc(mc->dev, child_count, sizeof(*timing), - GFP_KERNEL); + mc->timings = devm_kzalloc_objs(mc->dev, *timing, child_count); if (!mc->timings) return -ENOMEM; @@ -956,7 +955,7 @@ static int tegra_mc_probe(struct platform_device *pdev) u64 mask; int err; - mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(&pdev->dev, *mc); if (!mc) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra114-emc.c b/drivers/memory/tegra/tegra114-emc.c index e50d71842d3aae..866341f475e04c 100644 --- a/drivers/memory/tegra/tegra114-emc.c +++ b/drivers/memory/tegra/tegra114-emc.c @@ -922,8 +922,7 @@ static int tegra114_emc_load_timings_from_dt(struct tegra_emc *emc, unsigned int i = 0; int err; - emc->timings = devm_kcalloc(emc->dev, child_count, sizeof(*timing), - GFP_KERNEL); + emc->timings = devm_kzalloc_objs(emc->dev, *timing, child_count); if (!emc->timings) return -ENOMEM; @@ -1251,7 +1250,7 @@ static int tegra114_emc_probe(struct platform_device *pdev) u32 ram_code; int err; - emc = devm_kzalloc(dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(dev, *emc); if (!emc) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra124-emc.c b/drivers/memory/tegra/tegra124-emc.c index 555a6c753be768..44ac48644f3c8d 100644 --- a/drivers/memory/tegra/tegra124-emc.c +++ b/drivers/memory/tegra/tegra124-emc.c @@ -977,8 +977,7 @@ static int tegra124_emc_load_timings_from_dt(struct tegra_emc *emc, unsigned int i = 0; int err; - emc->timings = devm_kcalloc(emc->dev, child_count, sizeof(*timing), - GFP_KERNEL); + emc->timings = devm_kzalloc_objs(emc->dev, *timing, child_count); if (!emc->timings) return -ENOMEM; @@ -1343,7 +1342,7 @@ static int tegra124_emc_probe(struct platform_device *pdev) u32 ram_code; int err; - emc = devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(&pdev->dev, *emc); if (!emc) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra186-emc.c b/drivers/memory/tegra/tegra186-emc.c index c9583b66f18de3..9dd1f0a952958c 100644 --- a/drivers/memory/tegra/tegra186-emc.c +++ b/drivers/memory/tegra/tegra186-emc.c @@ -185,7 +185,7 @@ static int tegra186_emc_get_emc_dvfs_latency(struct tegra186_emc *emc) emc->num_dvfs = response.num_pairs; - emc->dvfs = devm_kmalloc_array(emc->dev, emc->num_dvfs, sizeof(*emc->dvfs), GFP_KERNEL); + emc->dvfs = devm_kmalloc_objs(emc->dev, *emc->dvfs, emc->num_dvfs); if (!emc->dvfs) return -ENOMEM; @@ -337,7 +337,7 @@ static int tegra186_emc_probe(struct platform_device *pdev) struct tegra186_emc *emc; int err; - emc = devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(&pdev->dev, *emc); if (!emc) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra186.c b/drivers/memory/tegra/tegra186.c index 442edb2b033e24..103f327b636524 100644 --- a/drivers/memory/tegra/tegra186.c +++ b/drivers/memory/tegra/tegra186.c @@ -54,8 +54,8 @@ static int tegra186_mc_probe(struct tegra_mc *mc) return PTR_ERR(mc->bcast_ch_regs); } - mc->ch_regs = devm_kcalloc(mc->dev, mc->soc->num_channels, sizeof(*mc->ch_regs), - GFP_KERNEL); + mc->ch_regs = devm_kzalloc_objs(mc->dev, *mc->ch_regs, + mc->soc->num_channels); if (!mc->ch_regs) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c index 1d564b80e2bb99..5a6af74d5384be 100644 --- a/drivers/memory/tegra/tegra20-emc.c +++ b/drivers/memory/tegra/tegra20-emc.c @@ -402,8 +402,7 @@ static int tegra20_emc_load_timings_from_dt(struct tegra_emc *emc, return -EINVAL; } - emc->timings = devm_kcalloc(emc->dev, child_count, sizeof(*timing), - GFP_KERNEL); + emc->timings = devm_kzalloc_objs(emc->dev, *timing, child_count); if (!emc->timings) return -ENOMEM; @@ -1091,7 +1090,7 @@ static int tegra20_emc_probe(struct platform_device *pdev) if (irq < 0) return irq; - emc = devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(&pdev->dev, *emc); if (!emc) return -ENOMEM; diff --git a/drivers/memory/tegra/tegra210-emc-core.c b/drivers/memory/tegra/tegra210-emc-core.c index e8d4cd8fdec26b..2ee8249b20050d 100644 --- a/drivers/memory/tegra/tegra210-emc-core.c +++ b/drivers/memory/tegra/tegra210-emc-core.c @@ -1816,7 +1816,7 @@ static int tegra210_emc_probe(struct platform_device *pdev) unsigned int i; int err; - emc = devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(&pdev->dev, *emc); if (!emc) return -ENOMEM; @@ -1919,9 +1919,9 @@ static int tegra210_emc_probe(struct platform_device *pdev) emc->provider.dev = &pdev->dev; emc->provider.set_rate = tegra210_emc_set_rate; - emc->provider.configs = devm_kcalloc(&pdev->dev, emc->num_timings, - sizeof(*emc->provider.configs), - GFP_KERNEL); + emc->provider.configs = devm_kzalloc_objs(&pdev->dev, + *emc->provider.configs, + emc->num_timings); if (!emc->provider.configs) { err = -ENOMEM; goto release; diff --git a/drivers/memory/tegra/tegra30-emc.c b/drivers/memory/tegra/tegra30-emc.c index c1eacd66ce49fd..cfedaf96d1d8eb 100644 --- a/drivers/memory/tegra/tegra30-emc.c +++ b/drivers/memory/tegra/tegra30-emc.c @@ -972,8 +972,7 @@ static int emc_load_timings_from_dt(struct tegra_emc *emc, return -EINVAL; } - emc->timings = devm_kcalloc(emc->dev, child_count, sizeof(*timing), - GFP_KERNEL); + emc->timings = devm_kzalloc_objs(emc->dev, *timing, child_count); if (!emc->timings) return -ENOMEM; @@ -1520,7 +1519,7 @@ static int tegra30_emc_probe(struct platform_device *pdev) struct tegra_emc *emc; int err; - emc = devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + emc = devm_kzalloc_obj(&pdev->dev, *emc); if (!emc) return -ENOMEM; diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c index c8b83c9edbd587..f9c9016114308b 100644 --- a/drivers/memory/ti-aemif.c +++ b/drivers/memory/ti-aemif.c @@ -370,7 +370,7 @@ static int aemif_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct aemif_device *aemif; - aemif = devm_kzalloc(dev, sizeof(*aemif), GFP_KERNEL); + aemif = devm_kzalloc_obj(dev, *aemif); if (!aemif) return -ENOMEM; diff --git a/drivers/memory/ti-emif-pm.c b/drivers/memory/ti-emif-pm.c index df362ecc59e910..f46ed36e29228e 100644 --- a/drivers/memory/ti-emif-pm.c +++ b/drivers/memory/ti-emif-pm.c @@ -279,7 +279,7 @@ static int ti_emif_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct ti_emif_data *emif_data; - emif_data = devm_kzalloc(dev, sizeof(*emif_data), GFP_KERNEL); + emif_data = devm_kzalloc_obj(dev, *emif_data); if (!emif_data) return -ENOMEM; diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c index 0d15f48ef51d4f..6a80570ee01d4b 100644 --- a/drivers/memstick/core/memstick.c +++ b/drivers/memstick/core/memstick.c @@ -100,7 +100,6 @@ static void memstick_device_remove(struct device *dev) if (dev->driver && drv->remove) { drv->remove(card); - card->dev.driver = NULL; } put_device(dev); diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index cd4ff1b79a6dae..d4143a871d69de 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -1347,8 +1347,7 @@ static int msb_ftl_initialize(struct msb_data *msb) msb->used_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL); msb->erased_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL); msb->lba_to_pba_table = - kmalloc_array(msb->logical_block_count, sizeof(u16), - GFP_KERNEL); + kmalloc_objs(u16, msb->logical_block_count); if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table || !msb->erased_blocks_bitmap) { diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c index 7f3e312b8f7397..98f1ebe38f71b6 100644 --- a/drivers/mfd/88pm800.c +++ b/drivers/mfd/88pm800.c @@ -544,8 +544,7 @@ static int pm800_probe(struct i2c_client *client) /* init subchip for PM800 */ subchip = - devm_kzalloc(&client->dev, sizeof(struct pm80x_subchip), - GFP_KERNEL); + devm_kzalloc_obj(&client->dev, struct pm80x_subchip); if (!subchip) { ret = -ENOMEM; goto err_subchip_alloc; diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c index bbc1a87f0c8f99..51039677223a8c 100644 --- a/drivers/mfd/88pm80x.c +++ b/drivers/mfd/88pm80x.c @@ -56,7 +56,7 @@ int pm80x_init(struct i2c_client *client) int i, ret = 0; chip = - devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL); + devm_kzalloc_obj(&client->dev, struct pm80x_chip); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c index 77230fbe07be2b..c64a13e677a73a 100644 --- a/drivers/mfd/88pm860x-core.c +++ b/drivers/mfd/88pm860x-core.c @@ -1136,9 +1136,8 @@ static int pm860x_probe(struct i2c_client *client) if (node && !pdata) { /* parse DT to get platform data */ - pdata = devm_kzalloc(&client->dev, - sizeof(struct pm860x_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, + struct pm860x_platform_data); if (!pdata) return -ENOMEM; ret = pm860x_dt_init(node, &client->dev, pdata); @@ -1149,8 +1148,7 @@ static int pm860x_probe(struct i2c_client *client) return -EINVAL; } - chip = devm_kzalloc(&client->dev, - sizeof(struct pm860x_chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct pm860x_chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c index f8401d5e6dbe34..7589d630925984 100644 --- a/drivers/mfd/88pm886.c +++ b/drivers/mfd/88pm886.c @@ -99,7 +99,7 @@ static int pm886_probe(struct i2c_client *client) unsigned int chip_id; int err; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/aat2870-core.c b/drivers/mfd/aat2870-core.c index 0d56cd6fbc6a51..5d43fd1da96e98 100644 --- a/drivers/mfd/aat2870-core.c +++ b/drivers/mfd/aat2870-core.c @@ -337,8 +337,7 @@ static int aat2870_i2c_probe(struct i2c_client *client) int i, j; int ret = 0; - aat2870 = devm_kzalloc(&client->dev, sizeof(struct aat2870_data), - GFP_KERNEL); + aat2870 = devm_kzalloc_obj(&client->dev, struct aat2870_data); if (!aat2870) return -ENOMEM; diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c index d5602b2f4a0e80..1dc41bb9286d8a 100644 --- a/drivers/mfd/ab8500-core.c +++ b/drivers/mfd/ab8500-core.c @@ -1025,7 +1025,7 @@ static int ab8500_probe(struct platform_device *pdev) int irq; u8 value; - ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); + ab8500 = devm_kzalloc_obj(&pdev->dev, *ab8500); if (!ab8500) return -ENOMEM; diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c index e896531d0354db..5de59ef4f8dbe8 100644 --- a/drivers/mfd/abx500-core.c +++ b/drivers/mfd/abx500-core.c @@ -37,7 +37,7 @@ int abx500_register_ops(struct device *dev, struct abx500_ops *ops) { struct abx500_device_entry *dev_entry; - dev_entry = devm_kzalloc(dev, sizeof(*dev_entry), GFP_KERNEL); + dev_entry = devm_kzalloc_obj(dev, *dev_entry); if (!dev_entry) return -ENOMEM; diff --git a/drivers/mfd/ac100.c b/drivers/mfd/ac100.c index 8f47c392cbd127..c088d715d7df47 100644 --- a/drivers/mfd/ac100.c +++ b/drivers/mfd/ac100.c @@ -90,7 +90,7 @@ static int ac100_rsb_probe(struct sunxi_rsb_device *rdev) struct ac100_dev *ac100; int ret; - ac100 = devm_kzalloc(&rdev->dev, sizeof(*ac100), GFP_KERNEL); + ac100 = devm_kzalloc_obj(&rdev->dev, *ac100); if (!ac100) return -ENOMEM; diff --git a/drivers/mfd/adp5520.c b/drivers/mfd/adp5520.c index bd6f4965ebc826..38fbdeef51cccf 100644 --- a/drivers/mfd/adp5520.c +++ b/drivers/mfd/adp5520.c @@ -223,7 +223,7 @@ static int adp5520_probe(struct i2c_client *client) return -ENODEV; } - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/adp5585.c b/drivers/mfd/adp5585.c index aad1d734baeba7..babd97ad6c20db 100644 --- a/drivers/mfd/adp5585.c +++ b/drivers/mfd/adp5585.c @@ -693,7 +693,7 @@ static int adp5585_i2c_probe(struct i2c_client *i2c) unsigned int id; int ret; - adp5585 = devm_kzalloc(&i2c->dev, sizeof(*adp5585), GFP_KERNEL); + adp5585 = devm_kzalloc_obj(&i2c->dev, *adp5585); if (!adp5585) return -ENOMEM; diff --git a/drivers/mfd/altera-a10sr.c b/drivers/mfd/altera-a10sr.c index 9c026222865581..b4abb37dcd1939 100644 --- a/drivers/mfd/altera-a10sr.c +++ b/drivers/mfd/altera-a10sr.c @@ -115,8 +115,7 @@ static int altr_a10sr_spi_probe(struct spi_device *spi) int ret; struct altr_a10sr *a10sr; - a10sr = devm_kzalloc(&spi->dev, sizeof(*a10sr), - GFP_KERNEL); + a10sr = devm_kzalloc_obj(&spi->dev, *a10sr); if (!a10sr) return -ENOMEM; diff --git a/drivers/mfd/altera-sysmgr.c b/drivers/mfd/altera-sysmgr.c index 90c6902d537da3..1ad46dbcbab7e8 100644 --- a/drivers/mfd/altera-sysmgr.c +++ b/drivers/mfd/altera-sysmgr.c @@ -133,7 +133,7 @@ static int sysmgr_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; void __iomem *base; - sysmgr = devm_kzalloc(dev, sizeof(*sysmgr), GFP_KERNEL); + sysmgr = devm_kzalloc_obj(dev, *sysmgr); if (!sysmgr) return -ENOMEM; diff --git a/drivers/mfd/arizona-i2c.c b/drivers/mfd/arizona-i2c.c index 10e76fc8f12ea6..767c5dfd4db646 100644 --- a/drivers/mfd/arizona-i2c.c +++ b/drivers/mfd/arizona-i2c.c @@ -58,7 +58,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c) return -EINVAL; } - arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL); + arizona = devm_kzalloc_obj(&i2c->dev, *arizona); if (arizona == NULL) return -ENOMEM; diff --git a/drivers/mfd/arizona-spi.c b/drivers/mfd/arizona-spi.c index 04baf5a1c65265..57e97f1b9f1dd3 100644 --- a/drivers/mfd/arizona-spi.c +++ b/drivers/mfd/arizona-spi.c @@ -59,9 +59,8 @@ static int arizona_spi_acpi_windows_probe(struct arizona *arizona) devm_acpi_dev_add_driver_gpios(arizona->dev, arizona_acpi_gpios); /* Add lookups for the SoCs own GPIOs used for micdet-polarity and spkVDD-enable */ - lookup = devm_kzalloc(arizona->dev, - struct_size(lookup, table, ARRAY_SIZE(arizona_soc_gpios) + 1), - GFP_KERNEL); + lookup = devm_kzalloc_flex(arizona->dev, *lookup, table, + ARRAY_SIZE(arizona_soc_gpios) + 1); if (!lookup) return -ENOMEM; @@ -222,7 +221,7 @@ static int arizona_spi_probe(struct spi_device *spi) return -EINVAL; } - arizona = devm_kzalloc(&spi->dev, sizeof(*arizona), GFP_KERNEL); + arizona = devm_kzalloc_obj(&spi->dev, *arizona); if (arizona == NULL) return -ENOMEM; diff --git a/drivers/mfd/as3711.c b/drivers/mfd/as3711.c index 9741977031df07..b123195d911cf6 100644 --- a/drivers/mfd/as3711.c +++ b/drivers/mfd/as3711.c @@ -128,13 +128,12 @@ static int as3711_i2c_probe(struct i2c_client *client) if (!pdata) dev_dbg(&client->dev, "Platform data not found\n"); } else { - pdata = devm_kzalloc(&client->dev, - sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) return -ENOMEM; } - as3711 = devm_kzalloc(&client->dev, sizeof(struct as3711), GFP_KERNEL); + as3711 = devm_kzalloc_obj(&client->dev, struct as3711); if (!as3711) return -ENOMEM; diff --git a/drivers/mfd/as3722.c b/drivers/mfd/as3722.c index 7ab6fcc9c27c8f..0a7f8e7d76198c 100644 --- a/drivers/mfd/as3722.c +++ b/drivers/mfd/as3722.c @@ -340,7 +340,7 @@ static int as3722_i2c_probe(struct i2c_client *i2c) int ret; u8 val = 0; - as3722 = devm_kzalloc(&i2c->dev, sizeof(struct as3722), GFP_KERNEL); + as3722 = devm_kzalloc_obj(&i2c->dev, struct as3722); if (!as3722) return -ENOMEM; diff --git a/drivers/mfd/atc260x-core.c b/drivers/mfd/atc260x-core.c index 6b6d5f1b9d76b4..d4433e76ae01ff 100644 --- a/drivers/mfd/atc260x-core.c +++ b/drivers/mfd/atc260x-core.c @@ -228,8 +228,7 @@ int atc260x_match_device(struct atc260x *atc260x, struct regmap_config *regmap_c return -EINVAL; } - atc260x->regmap_mutex = devm_kzalloc(dev, sizeof(*atc260x->regmap_mutex), - GFP_KERNEL); + atc260x->regmap_mutex = devm_kzalloc_obj(dev, *atc260x->regmap_mutex); if (!atc260x->regmap_mutex) return -ENOMEM; diff --git a/drivers/mfd/atc260x-i2c.c b/drivers/mfd/atc260x-i2c.c index fb53b0432a317a..0b2cff71644839 100644 --- a/drivers/mfd/atc260x-i2c.c +++ b/drivers/mfd/atc260x-i2c.c @@ -18,7 +18,7 @@ static int atc260x_i2c_probe(struct i2c_client *client) struct regmap_config regmap_cfg; int ret; - atc260x = devm_kzalloc(&client->dev, sizeof(*atc260x), GFP_KERNEL); + atc260x = devm_kzalloc_obj(&client->dev, *atc260x); if (!atc260x) return -ENOMEM; diff --git a/drivers/mfd/atmel-flexcom.c b/drivers/mfd/atmel-flexcom.c index d5df5466eaf5ad..e1458b026a0cdb 100644 --- a/drivers/mfd/atmel-flexcom.c +++ b/drivers/mfd/atmel-flexcom.c @@ -40,7 +40,7 @@ static int atmel_flexcom_probe(struct platform_device *pdev) struct atmel_flexcom *ddata; int err; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/atmel-hlcdc.c b/drivers/mfd/atmel-hlcdc.c index 2a3a05122176f8..4a10dac519ee21 100644 --- a/drivers/mfd/atmel-hlcdc.c +++ b/drivers/mfd/atmel-hlcdc.c @@ -83,11 +83,11 @@ static int atmel_hlcdc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct atmel_hlcdc *hlcdc; - hregmap = devm_kzalloc(dev, sizeof(*hregmap), GFP_KERNEL); + hregmap = devm_kzalloc_obj(dev, *hregmap); if (!hregmap) return -ENOMEM; - hlcdc = devm_kzalloc(dev, sizeof(*hlcdc), GFP_KERNEL); + hlcdc = devm_kzalloc_obj(dev, *hlcdc); if (!hlcdc) return -ENOMEM; diff --git a/drivers/mfd/axp20x-i2c.c b/drivers/mfd/axp20x-i2c.c index 5c93136f977e72..9ddc73b8af4352 100644 --- a/drivers/mfd/axp20x-i2c.c +++ b/drivers/mfd/axp20x-i2c.c @@ -27,7 +27,7 @@ static int axp20x_i2c_probe(struct i2c_client *i2c) struct axp20x_dev *axp20x; int ret; - axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL); + axp20x = devm_kzalloc_obj(&i2c->dev, *axp20x); if (!axp20x) return -ENOMEM; diff --git a/drivers/mfd/axp20x-rsb.c b/drivers/mfd/axp20x-rsb.c index 059656f2a1bd69..dfc665f696bd05 100644 --- a/drivers/mfd/axp20x-rsb.c +++ b/drivers/mfd/axp20x-rsb.c @@ -27,7 +27,7 @@ static int axp20x_rsb_probe(struct sunxi_rsb_device *rdev) struct axp20x_dev *axp20x; int ret; - axp20x = devm_kzalloc(&rdev->dev, sizeof(*axp20x), GFP_KERNEL); + axp20x = devm_kzalloc_obj(&rdev->dev, *axp20x); if (!axp20x) return -ENOMEM; diff --git a/drivers/mfd/bcm2835-pm.c b/drivers/mfd/bcm2835-pm.c index 9e8e3dcf4bcebe..14b18dc3805887 100644 --- a/drivers/mfd/bcm2835-pm.c +++ b/drivers/mfd/bcm2835-pm.c @@ -75,7 +75,7 @@ static int bcm2835_pm_probe(struct platform_device *pdev) struct bcm2835_pm *pm; int ret; - pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL); + pm = devm_kzalloc_obj(dev, *pm); if (!pm) return -ENOMEM; platform_set_drvdata(pdev, pm); diff --git a/drivers/mfd/bcm590xx.c b/drivers/mfd/bcm590xx.c index 5a8456bbd63f65..f553937c407524 100644 --- a/drivers/mfd/bcm590xx.c +++ b/drivers/mfd/bcm590xx.c @@ -92,7 +92,7 @@ static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri) struct bcm590xx *bcm590xx; int ret; - bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL); + bcm590xx = devm_kzalloc_obj(&i2c_pri->dev, *bcm590xx); if (!bcm590xx) return -ENOMEM; diff --git a/drivers/mfd/bq257xx.c b/drivers/mfd/bq257xx.c index 01f5fc97f53856..7c00d7e21dc758 100644 --- a/drivers/mfd/bq257xx.c +++ b/drivers/mfd/bq257xx.c @@ -93,7 +93,7 @@ static int bq257xx_probe(struct i2c_client *client) struct bq257xx_device *ddata; int ret; - ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&client->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c index 2becaf797646da..8a2020cdf3b3c5 100644 --- a/drivers/mfd/cgbc-core.c +++ b/drivers/mfd/cgbc-core.c @@ -343,7 +343,7 @@ static int cgbc_probe(struct platform_device *pdev) struct cgbc_device_data *cgbc; int ret; - cgbc = devm_kzalloc(dev, sizeof(*cgbc), GFP_KERNEL); + cgbc = devm_kzalloc_obj(dev, *cgbc); if (!cgbc) return -ENOMEM; diff --git a/drivers/mfd/cs40l50-i2c.c b/drivers/mfd/cs40l50-i2c.c index 639be743d95699..13afbb73b223d0 100644 --- a/drivers/mfd/cs40l50-i2c.c +++ b/drivers/mfd/cs40l50-i2c.c @@ -15,7 +15,7 @@ static int cs40l50_i2c_probe(struct i2c_client *i2c) { struct cs40l50 *cs40l50; - cs40l50 = devm_kzalloc(&i2c->dev, sizeof(*cs40l50), GFP_KERNEL); + cs40l50 = devm_kzalloc_obj(&i2c->dev, *cs40l50); if (!cs40l50) return -ENOMEM; diff --git a/drivers/mfd/cs40l50-spi.c b/drivers/mfd/cs40l50-spi.c index a635951ca6b767..a213ef9a30d43d 100644 --- a/drivers/mfd/cs40l50-spi.c +++ b/drivers/mfd/cs40l50-spi.c @@ -15,7 +15,7 @@ static int cs40l50_spi_probe(struct spi_device *spi) { struct cs40l50 *cs40l50; - cs40l50 = devm_kzalloc(&spi->dev, sizeof(*cs40l50), GFP_KERNEL); + cs40l50 = devm_kzalloc_obj(&spi->dev, *cs40l50); if (!cs40l50) return -ENOMEM; diff --git a/drivers/mfd/cs42l43-i2c.c b/drivers/mfd/cs42l43-i2c.c index 2f1862199618de..c2eb9fd63a5d8d 100644 --- a/drivers/mfd/cs42l43-i2c.c +++ b/drivers/mfd/cs42l43-i2c.c @@ -38,7 +38,7 @@ static int cs42l43_i2c_probe(struct i2c_client *i2c) { struct cs42l43 *cs42l43; - cs42l43 = devm_kzalloc(&i2c->dev, sizeof(*cs42l43), GFP_KERNEL); + cs42l43 = devm_kzalloc_obj(&i2c->dev, *cs42l43); if (!cs42l43) return -ENOMEM; diff --git a/drivers/mfd/cs42l43-sdw.c b/drivers/mfd/cs42l43-sdw.c index 22e4c1fe929847..cd0132e3632bea 100644 --- a/drivers/mfd/cs42l43-sdw.c +++ b/drivers/mfd/cs42l43-sdw.c @@ -164,7 +164,7 @@ static int cs42l43_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id * struct cs42l43 *cs42l43; struct device *dev = &sdw->dev; - cs42l43 = devm_kzalloc(dev, sizeof(*cs42l43), GFP_KERNEL); + cs42l43 = devm_kzalloc_obj(dev, *cs42l43); if (!cs42l43) return -ENOMEM; diff --git a/drivers/mfd/cs42l43.c b/drivers/mfd/cs42l43.c index a83b62064dae6f..76f2eba28aaf1b 100644 --- a/drivers/mfd/cs42l43.c +++ b/drivers/mfd/cs42l43.c @@ -402,6 +402,7 @@ bool cs42l43_readable_register(struct device *dev, unsigned int reg) case CS42L43_BLOCK_EN: case CS42L43_SHUTTER_CONTROL: case CS42L43B_MCU_SW_REV ... CS42L43B_MCU_RAM_MAX: + case CS42L43B_LOAD_DET_SEL: return true; // registers present on all variants case CS42L43_MCU_SW_REV ... CS42L43B_MCU_SW_REV - 1: case CS42L43B_MCU_RAM_MAX + 1 ... CS42L43_MCU_RAM_MAX: @@ -425,6 +426,7 @@ bool cs42l43_precious_register(struct device *dev, unsigned int reg) case CS42L43_RX_DATA: case CS42L43_DECIM_INT ... CS42L43_HPOUT_INT: case CS42L43_MCU_SW_REV ... CS42L43_MCU_RAM_MAX: + case CS42L43B_LOAD_DET_SEL: return true; default: return false; diff --git a/drivers/mfd/da903x.c b/drivers/mfd/da903x.c index e4ad48e1f139be..43c85d8ebee355 100644 --- a/drivers/mfd/da903x.c +++ b/drivers/mfd/da903x.c @@ -510,8 +510,7 @@ static int da903x_probe(struct i2c_client *client) unsigned int tmp; int ret; - chip = devm_kzalloc(&client->dev, sizeof(struct da903x_chip), - GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct da903x_chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/mfd/da9052-i2c.c b/drivers/mfd/da9052-i2c.c index fd000a21bcba5f..612f202ce02ad7 100644 --- a/drivers/mfd/da9052-i2c.c +++ b/drivers/mfd/da9052-i2c.c @@ -129,7 +129,7 @@ static int da9052_i2c_probe(struct i2c_client *client) struct da9052 *da9052; int ret; - da9052 = devm_kzalloc(&client->dev, sizeof(struct da9052), GFP_KERNEL); + da9052 = devm_kzalloc_obj(&client->dev, struct da9052); if (!da9052) return -ENOMEM; diff --git a/drivers/mfd/da9052-spi.c b/drivers/mfd/da9052-spi.c index 29cf2c17fde1af..d9f2d21c4d4d78 100644 --- a/drivers/mfd/da9052-spi.c +++ b/drivers/mfd/da9052-spi.c @@ -23,7 +23,7 @@ static int da9052_spi_probe(struct spi_device *spi) const struct spi_device_id *id = spi_get_device_id(spi); struct da9052 *da9052; - da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL); + da9052 = devm_kzalloc_obj(&spi->dev, struct da9052); if (!da9052) return -ENOMEM; diff --git a/drivers/mfd/da9055-i2c.c b/drivers/mfd/da9055-i2c.c index 6c1981832aafe9..b9fde5e5a102f6 100644 --- a/drivers/mfd/da9055-i2c.c +++ b/drivers/mfd/da9055-i2c.c @@ -19,7 +19,7 @@ static int da9055_i2c_probe(struct i2c_client *i2c) struct da9055 *da9055; int ret; - da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL); + da9055 = devm_kzalloc_obj(&i2c->dev, struct da9055); if (!da9055) return -ENOMEM; diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c index ad198183aff737..9ee23abd61c710 100644 --- a/drivers/mfd/da9062-core.c +++ b/drivers/mfd/da9062-core.c @@ -599,7 +599,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c) u32 trigger_type = 0; int ret; - chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/da9063-i2c.c b/drivers/mfd/da9063-i2c.c index a803b7440f09bc..fb13427b1b5989 100644 --- a/drivers/mfd/da9063-i2c.c +++ b/drivers/mfd/da9063-i2c.c @@ -372,7 +372,7 @@ static int da9063_i2c_probe(struct i2c_client *i2c) struct da9063 *da9063; int ret; - da9063 = devm_kzalloc(&i2c->dev, sizeof(struct da9063), GFP_KERNEL); + da9063 = devm_kzalloc_obj(&i2c->dev, struct da9063); if (da9063 == NULL) return -ENOMEM; diff --git a/drivers/mfd/da9150-core.c b/drivers/mfd/da9150-core.c index 19325d72a27e7e..9af0af93cdee0b 100644 --- a/drivers/mfd/da9150-core.c +++ b/drivers/mfd/da9150-core.c @@ -399,7 +399,7 @@ static int da9150_probe(struct i2c_client *client) int qif_addr; int ret; - da9150 = devm_kzalloc(&client->dev, sizeof(*da9150), GFP_KERNEL); + da9150 = devm_kzalloc_obj(&client->dev, *da9150); if (!da9150) return -ENOMEM; diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c index 0b1e7fd7f5d734..70b75632a8d49a 100644 --- a/drivers/mfd/dln2.c +++ b/drivers/mfd/dln2.c @@ -775,7 +775,7 @@ static int dln2_probe(struct usb_interface *interface, if (ret) return ret; - dln2 = devm_kzalloc(dev, sizeof(*dln2), GFP_KERNEL); + dln2 = devm_kzalloc_obj(dev, *dln2); if (!dln2) return -ENOMEM; diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c index 086e0758d4cc52..0a39ae66d2eb46 100644 --- a/drivers/mfd/ene-kb3930.c +++ b/drivers/mfd/ene-kb3930.c @@ -127,7 +127,7 @@ static int kb3930_probe(struct i2c_client *client) unsigned int model; int ret; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/exynos-lpass.c b/drivers/mfd/exynos-lpass.c index 9bb2687c28355d..646bdb8889157f 100644 --- a/drivers/mfd/exynos-lpass.c +++ b/drivers/mfd/exynos-lpass.c @@ -120,7 +120,7 @@ static int exynos_lpass_probe(struct platform_device *pdev) void __iomem *base_top; int ret; - lpass = devm_kzalloc(dev, sizeof(*lpass), GFP_KERNEL); + lpass = devm_kzalloc_obj(dev, *lpass); if (!lpass) return -ENOMEM; diff --git a/drivers/mfd/fsl-imx25-tsadc.c b/drivers/mfd/fsl-imx25-tsadc.c index 467b1a23faeb24..f2c204cc24faac 100644 --- a/drivers/mfd/fsl-imx25-tsadc.c +++ b/drivers/mfd/fsl-imx25-tsadc.c @@ -138,7 +138,7 @@ static int mx25_tsadc_probe(struct platform_device *pdev) int ret; void __iomem *iomem; - tsadc = devm_kzalloc(dev, sizeof(*tsadc), GFP_KERNEL); + tsadc = devm_kzalloc_obj(dev, *tsadc); if (!tsadc) return -ENOMEM; diff --git a/drivers/mfd/gateworks-gsc.c b/drivers/mfd/gateworks-gsc.c index a3301502ce6a5b..c034d54354f4d5 100644 --- a/drivers/mfd/gateworks-gsc.c +++ b/drivers/mfd/gateworks-gsc.c @@ -202,7 +202,7 @@ static int gsc_probe(struct i2c_client *client) int ret; unsigned int reg; - gsc = devm_kzalloc(dev, sizeof(*gsc), GFP_KERNEL); + gsc = devm_kzalloc_obj(dev, *gsc); if (!gsc) return -ENOMEM; diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c index 5af24a4383296a..44099fffa465ce 100644 --- a/drivers/mfd/hi6421-pmic-core.c +++ b/drivers/mfd/hi6421-pmic-core.c @@ -58,7 +58,7 @@ static int hi6421_pmic_probe(struct platform_device *pdev) type = (uintptr_t)device_get_match_data(&pdev->dev); - pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&pdev->dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c index 5cb392892c192c..32c9c2bcd922ae 100644 --- a/drivers/mfd/hi655x-pmic.c +++ b/drivers/mfd/hi655x-pmic.c @@ -94,7 +94,7 @@ static int hi655x_pmic_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; void __iomem *base; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; pmic->dev = dev; diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c index 29f30ef0da9902..504ab271f7bb72 100644 --- a/drivers/mfd/intel-lpss.c +++ b/drivers/mfd/intel-lpss.c @@ -392,7 +392,7 @@ int intel_lpss_probe(struct device *dev, if (info->irq < 0) return info->irq; - lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL); + lpss = devm_kzalloc_obj(dev, *lpss); if (!lpss) return -ENOMEM; diff --git a/drivers/mfd/intel-m10-bmc-pmci.c b/drivers/mfd/intel-m10-bmc-pmci.c index d213c6ec04bad0..825a4cfd5d9846 100644 --- a/drivers/mfd/intel-m10-bmc-pmci.c +++ b/drivers/mfd/intel-m10-bmc-pmci.c @@ -386,7 +386,7 @@ static int m10bmc_pmci_probe(struct dfl_device *ddev) struct indirect_ctx *ctx; int ret; - pmci = devm_kzalloc(dev, sizeof(*pmci), GFP_KERNEL); + pmci = devm_kzalloc_obj(dev, *pmci); if (!pmci) return -ENOMEM; @@ -397,7 +397,7 @@ static int m10bmc_pmci_probe(struct dfl_device *ddev) if (IS_ERR(pmci->base)) return PTR_ERR(pmci->base); - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/mfd/intel-m10-bmc-spi.c b/drivers/mfd/intel-m10-bmc-spi.c index 94b9c99bb4f860..20a46eba0230b6 100644 --- a/drivers/mfd/intel-m10-bmc-spi.c +++ b/drivers/mfd/intel-m10-bmc-spi.c @@ -66,7 +66,7 @@ static int intel_m10_bmc_spi_probe(struct spi_device *spi) struct intel_m10bmc *ddata; int ret; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/intel_pmc_bxt.c b/drivers/mfd/intel_pmc_bxt.c index e405d7513ca170..2819ff94f686e1 100644 --- a/drivers/mfd/intel_pmc_bxt.c +++ b/drivers/mfd/intel_pmc_bxt.c @@ -425,7 +425,7 @@ static int intel_pmc_probe(struct platform_device *pdev) struct intel_pmc_dev *pmc; int ret; - pmc = devm_kzalloc(&pdev->dev, sizeof(*pmc), GFP_KERNEL); + pmc = devm_kzalloc_obj(&pdev->dev, *pmc); if (!pmc) return -ENOMEM; diff --git a/drivers/mfd/intel_soc_pmic_bxtwc.c b/drivers/mfd/intel_soc_pmic_bxtwc.c index 117517c171b535..34e99e75460f31 100644 --- a/drivers/mfd/intel_soc_pmic_bxtwc.c +++ b/drivers/mfd/intel_soc_pmic_bxtwc.c @@ -482,7 +482,7 @@ static int bxtwc_probe(struct platform_device *pdev) if (hrv != BROXTON_PMIC_WC_HRV) return dev_err_probe(dev, -ENODEV, "Invalid PMIC hardware revision: %llu\n", hrv); - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/intel_soc_pmic_chtdc_ti.c b/drivers/mfd/intel_soc_pmic_chtdc_ti.c index 6daf33e07ea0a8..7500b262e0990e 100644 --- a/drivers/mfd/intel_soc_pmic_chtdc_ti.c +++ b/drivers/mfd/intel_soc_pmic_chtdc_ti.c @@ -111,7 +111,7 @@ static int chtdc_ti_probe(struct i2c_client *i2c) struct intel_soc_pmic *pmic; int ret; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/intel_soc_pmic_chtwc.c b/drivers/mfd/intel_soc_pmic_chtwc.c index aa71a7d83fcd17..f288d830fbdb13 100644 --- a/drivers/mfd/intel_soc_pmic_chtwc.c +++ b/drivers/mfd/intel_soc_pmic_chtwc.c @@ -202,7 +202,7 @@ static int cht_wc_probe(struct i2c_client *client) if (client->irq < 0) return dev_err_probe(dev, -EINVAL, "Invalid IRQ\n"); - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c index 627a8933490811..4982e71f608f8a 100644 --- a/drivers/mfd/intel_soc_pmic_crc.c +++ b/drivers/mfd/intel_soc_pmic_crc.c @@ -176,7 +176,7 @@ static int crystal_cove_i2c_probe(struct i2c_client *i2c) else config = &crystal_cove_config_cht_crc; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/intel_soc_pmic_mrfld.c b/drivers/mfd/intel_soc_pmic_mrfld.c index 77121775c1a35a..c1206f48bda326 100644 --- a/drivers/mfd/intel_soc_pmic_mrfld.c +++ b/drivers/mfd/intel_soc_pmic_mrfld.c @@ -109,7 +109,7 @@ static int bcove_probe(struct platform_device *pdev) unsigned int i; int ret; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/ioc3.c b/drivers/mfd/ioc3.c index 5f8ac364b610e9..d143c49e96c0d9 100644 --- a/drivers/mfd/ioc3.c +++ b/drivers/mfd/ioc3.c @@ -584,8 +584,7 @@ static int ioc3_mfd_probe(struct pci_dev *pdev, } /* Set up per-IOC3 data */ - ipd = devm_kzalloc(&pdev->dev, sizeof(struct ioc3_priv_data), - GFP_KERNEL); + ipd = devm_kzalloc_obj(&pdev->dev, struct ioc3_priv_data); if (!ipd) { ret = -ENOMEM; goto out_disable_device; diff --git a/drivers/mfd/ipaq-micro.c b/drivers/mfd/ipaq-micro.c index 5146a6eb0e5a68..5ba40b4f6b0002 100644 --- a/drivers/mfd/ipaq-micro.c +++ b/drivers/mfd/ipaq-micro.c @@ -381,7 +381,7 @@ static int __init micro_probe(struct platform_device *pdev) int ret; int irq; - micro = devm_kzalloc(&pdev->dev, sizeof(*micro), GFP_KERNEL); + micro = devm_kzalloc_obj(&pdev->dev, *micro); if (!micro) return -ENOMEM; diff --git a/drivers/mfd/iqs62x.c b/drivers/mfd/iqs62x.c index ef747a7b38455e..f12a45a3f3c08c 100644 --- a/drivers/mfd/iqs62x.c +++ b/drivers/mfd/iqs62x.c @@ -316,9 +316,7 @@ static int iqs62x_firmware_parse(struct iqs62x_core *iqs62x, if (ret) break; - fw_blk = devm_kzalloc(&client->dev, - struct_size(fw_blk, data, len), - GFP_KERNEL); + fw_blk = devm_kzalloc_flex(&client->dev, *fw_blk, data, len); if (!fw_blk) { ret = -ENOMEM; break; @@ -900,7 +898,7 @@ static int iqs62x_probe(struct i2c_client *client) int ret, i, j; const char *fw_name = NULL; - iqs62x = devm_kzalloc(&client->dev, sizeof(*iqs62x), GFP_KERNEL); + iqs62x = devm_kzalloc_obj(&client->dev, *iqs62x); if (!iqs62x) return -ENOMEM; diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c index add3bc04185b29..036773b3c4ee9f 100644 --- a/drivers/mfd/janz-cmodio.c +++ b/drivers/mfd/janz-cmodio.c @@ -178,7 +178,7 @@ static int cmodio_pci_probe(struct pci_dev *dev, struct cmodio_device *priv; int ret; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mfd/kempld-core.c b/drivers/mfd/kempld-core.c index 47062f876e5d67..2e8e92dfef8c8a 100644 --- a/drivers/mfd/kempld-core.c +++ b/drivers/mfd/kempld-core.c @@ -436,7 +436,7 @@ static int kempld_probe(struct platform_device *pdev) return -ENODEV; } - pld = devm_kzalloc(dev, sizeof(*pld), GFP_KERNEL); + pld = devm_kzalloc_obj(dev, *pld); if (!pld) return -ENOMEM; diff --git a/drivers/mfd/khadas-mcu.c b/drivers/mfd/khadas-mcu.c index 4b37e74e2b04ad..1279a123f13848 100644 --- a/drivers/mfd/khadas-mcu.c +++ b/drivers/mfd/khadas-mcu.c @@ -135,7 +135,7 @@ static int khadas_mcu_probe(struct i2c_client *client) struct khadas_mcu *ddata; const void *mcu_variant; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c index 9233da7ce09969..4ab83be8bebae7 100644 --- a/drivers/mfd/lm3533-core.c +++ b/drivers/mfd/lm3533-core.c @@ -294,8 +294,7 @@ static int lm3533_device_init(struct lm3533 *lm3533) return dev_err_probe(dev, -ENODEV, "num of child nodes is not supported\n"); - lm3533_devices = devm_kcalloc(dev, nchilds, sizeof(*lm3533_devices), - GFP_KERNEL); + lm3533_devices = devm_kzalloc_objs(dev, *lm3533_devices, nchilds); if (!lm3533_devices) return -ENOMEM; @@ -442,7 +441,7 @@ static int lm3533_i2c_probe(struct i2c_client *i2c) dev_dbg(&i2c->dev, "%s\n", __func__); - lm3533 = devm_kzalloc(&i2c->dev, sizeof(*lm3533), GFP_KERNEL); + lm3533 = devm_kzalloc_obj(&i2c->dev, *lm3533); if (!lm3533) return -ENOMEM; diff --git a/drivers/mfd/lochnagar-i2c.c b/drivers/mfd/lochnagar-i2c.c index 9d60a42745fc72..33551c82414d9d 100644 --- a/drivers/mfd/lochnagar-i2c.c +++ b/drivers/mfd/lochnagar-i2c.c @@ -276,7 +276,7 @@ static int lochnagar_i2c_probe(struct i2c_client *i2c) unsigned int devid, rev; int ret; - lochnagar = devm_kzalloc(dev, sizeof(*lochnagar), GFP_KERNEL); + lochnagar = devm_kzalloc_obj(dev, *lochnagar); if (!lochnagar) return -ENOMEM; diff --git a/drivers/mfd/loongson-se.c b/drivers/mfd/loongson-se.c index 3902ba377d6908..b87098010c1759 100644 --- a/drivers/mfd/loongson-se.c +++ b/drivers/mfd/loongson-se.c @@ -190,7 +190,7 @@ static int loongson_se_probe(struct platform_device *pdev) int nr_irq, irq, err, i; dma_addr_t paddr; - se = devm_kmalloc(dev, sizeof(*se), GFP_KERNEL); + se = devm_kmalloc_obj(dev, *se); if (!se) return -ENOMEM; diff --git a/drivers/mfd/lp3943.c b/drivers/mfd/lp3943.c index 1918b5c7a5e7b9..1726f3dd9153b8 100644 --- a/drivers/mfd/lp3943.c +++ b/drivers/mfd/lp3943.c @@ -107,7 +107,7 @@ static int lp3943_probe(struct i2c_client *cl) struct lp3943 *lp3943; struct device *dev = &cl->dev; - lp3943 = devm_kzalloc(dev, sizeof(*lp3943), GFP_KERNEL); + lp3943 = devm_kzalloc_obj(dev, *lp3943); if (!lp3943) return -ENOMEM; diff --git a/drivers/mfd/lp873x.c b/drivers/mfd/lp873x.c index d2c90302bf5909..ab7bd46d9ff7ff 100644 --- a/drivers/mfd/lp873x.c +++ b/drivers/mfd/lp873x.c @@ -29,7 +29,7 @@ static int lp873x_probe(struct i2c_client *client) int ret; unsigned int otpid; - lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL); + lp873 = devm_kzalloc_obj(&client->dev, *lp873); if (!lp873) return -ENOMEM; diff --git a/drivers/mfd/lp87565.c b/drivers/mfd/lp87565.c index b78ae79df5fa68..9e505963622584 100644 --- a/drivers/mfd/lp87565.c +++ b/drivers/mfd/lp87565.c @@ -49,7 +49,7 @@ static int lp87565_probe(struct i2c_client *client) int ret; unsigned int otpid; - lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL); + lp87565 = devm_kzalloc_obj(&client->dev, *lp87565); if (!lp87565) return -ENOMEM; diff --git a/drivers/mfd/lp8788-irq.c b/drivers/mfd/lp8788-irq.c index f62fa2d7f010c4..476bda247ec59d 100644 --- a/drivers/mfd/lp8788-irq.c +++ b/drivers/mfd/lp8788-irq.c @@ -156,7 +156,7 @@ int lp8788_irq_init(struct lp8788 *lp, int irq) return 0; } - irqd = devm_kzalloc(lp->dev, sizeof(*irqd), GFP_KERNEL); + irqd = devm_kzalloc_obj(lp->dev, *irqd); if (!irqd) return -ENOMEM; diff --git a/drivers/mfd/lp8788.c b/drivers/mfd/lp8788.c index 32f255378f5a69..79028e06a6650f 100644 --- a/drivers/mfd/lp8788.c +++ b/drivers/mfd/lp8788.c @@ -172,7 +172,7 @@ static int lp8788_probe(struct i2c_client *cl) struct lp8788_platform_data *pdata = dev_get_platdata(&cl->dev); int ret; - lp = devm_kzalloc(&cl->dev, sizeof(struct lp8788), GFP_KERNEL); + lp = devm_kzalloc_obj(&cl->dev, struct lp8788); if (!lp) return -ENOMEM; diff --git a/drivers/mfd/lpc_ich.c b/drivers/mfd/lpc_ich.c index d2efcc92bb59b5..783d44355bc33b 100644 --- a/drivers/mfd/lpc_ich.c +++ b/drivers/mfd/lpc_ich.c @@ -1038,7 +1038,7 @@ static int lpc_ich_finalize_wdt_cell(struct pci_dev *dev) struct lpc_ich_info *info; struct mfd_cell *cell = &lpc_ich_wdt_cell; - pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&dev->dev, *pdata); if (!pdata) return -ENOMEM; @@ -1320,7 +1320,7 @@ static int lpc_ich_init_spi(struct pci_dev *dev) u32 spi_base, rcba; int ret; - info = devm_kzalloc(&dev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, *info); if (!info) return -ENOMEM; @@ -1384,8 +1384,7 @@ static int lpc_ich_probe(struct pci_dev *dev, int ret; bool cell_added = false; - priv = devm_kzalloc(&dev->dev, - sizeof(struct lpc_ich_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, struct lpc_ich_priv); if (!priv) return -ENOMEM; diff --git a/drivers/mfd/lpc_sch.c b/drivers/mfd/lpc_sch.c index d069165f9b8606..75936b0b227639 100644 --- a/drivers/mfd/lpc_sch.c +++ b/drivers/mfd/lpc_sch.c @@ -111,7 +111,7 @@ static int lpc_sch_populate_cell(struct pci_dev *pdev, int where, struct resource *res; int ret; - res = devm_kzalloc(&pdev->dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(&pdev->dev, *res); if (!res) return -ENOMEM; diff --git a/drivers/mfd/ls2k-bmc-core.c b/drivers/mfd/ls2k-bmc-core.c index 408056bfb2fe75..abc948d8a81711 100644 --- a/drivers/mfd/ls2k-bmc-core.c +++ b/drivers/mfd/ls2k-bmc-core.c @@ -468,7 +468,7 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id) if (ret) return ret; - ddata = devm_kzalloc(&dev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&dev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 514cba7dc897ae..e03c7e9bf0f7f0 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -413,7 +413,7 @@ static int apple_smc_probe(struct platform_device *pdev) __be32 count; int ret; - smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL); + smc = devm_kzalloc_obj(dev, *smc); if (!smc) return -ENOMEM; diff --git a/drivers/mfd/madera-i2c.c b/drivers/mfd/madera-i2c.c index 0986e4a99f4aa0..a8feb7192ec2e4 100644 --- a/drivers/mfd/madera-i2c.c +++ b/drivers/mfd/madera-i2c.c @@ -76,7 +76,7 @@ static int madera_i2c_probe(struct i2c_client *i2c) return -EINVAL; } - madera = devm_kzalloc(&i2c->dev, sizeof(*madera), GFP_KERNEL); + madera = devm_kzalloc_obj(&i2c->dev, *madera); if (!madera) return -ENOMEM; diff --git a/drivers/mfd/madera-spi.c b/drivers/mfd/madera-spi.c index 3fffa21ceadc1e..5e1aa40ebe3cf2 100644 --- a/drivers/mfd/madera-spi.c +++ b/drivers/mfd/madera-spi.c @@ -76,7 +76,7 @@ static int madera_spi_probe(struct spi_device *spi) return -EINVAL; } - madera = devm_kzalloc(&spi->dev, sizeof(*madera), GFP_KERNEL); + madera = devm_kzalloc_obj(&spi->dev, *madera); if (!madera) return -ENOMEM; diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c index da275a04a1effc..1bef531a8df1af 100644 --- a/drivers/mfd/max14577.c +++ b/drivers/mfd/max14577.c @@ -368,7 +368,7 @@ static int max14577_i2c_probe(struct i2c_client *i2c) int irq_flags; if (np) { - pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c->dev, *pdata); if (!pdata) return -ENOMEM; i2c->dev.platform_data = pdata; @@ -379,7 +379,7 @@ static int max14577_i2c_probe(struct i2c_client *i2c) return -EINVAL; } - max14577 = devm_kzalloc(&i2c->dev, sizeof(*max14577), GFP_KERNEL); + max14577 = devm_kzalloc_obj(&i2c->dev, *max14577); if (!max14577) return -ENOMEM; diff --git a/drivers/mfd/max77541.c b/drivers/mfd/max77541.c index f91b4f5373ce93..510fa42e48eb22 100644 --- a/drivers/mfd/max77541.c +++ b/drivers/mfd/max77541.c @@ -165,7 +165,7 @@ static int max77541_probe(struct i2c_client *client) struct device *dev = &client->dev; struct max77541 *max77541; - max77541 = devm_kzalloc(dev, sizeof(*max77541), GFP_KERNEL); + max77541 = devm_kzalloc_obj(dev, *max77541); if (!max77541) return -ENOMEM; diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c index c4f89a9681f347..56b5718d01f2f7 100644 --- a/drivers/mfd/max77620.c +++ b/drivers/mfd/max77620.c @@ -504,7 +504,7 @@ static int max77620_probe(struct i2c_client *client) int n_mfd_cells; int ret; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c index 0118a444a68b11..3e3404ebf689ed 100644 --- a/drivers/mfd/max77686.c +++ b/drivers/mfd/max77686.c @@ -167,8 +167,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c) const struct mfd_cell *cells; int n_devs; - max77686 = devm_kzalloc(&i2c->dev, - sizeof(struct max77686_dev), GFP_KERNEL); + max77686 = devm_kzalloc_obj(&i2c->dev, struct max77686_dev); if (!max77686) return -ENOMEM; diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c index 1c485a4c3dcf86..5b553924d3cc63 100644 --- a/drivers/mfd/max77693.c +++ b/drivers/mfd/max77693.c @@ -152,8 +152,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c) unsigned int reg_data; int ret = 0; - max77693 = devm_kzalloc(&i2c->dev, - sizeof(struct max77693_dev), GFP_KERNEL); + max77693 = devm_kzalloc_obj(&i2c->dev, struct max77693_dev); if (max77693 == NULL) return -ENOMEM; diff --git a/drivers/mfd/max77705.c b/drivers/mfd/max77705.c index 2e9b81f2641456..2113ce5c6259e2 100644 --- a/drivers/mfd/max77705.c +++ b/drivers/mfd/max77705.c @@ -88,7 +88,7 @@ static int max77705_i2c_probe(struct i2c_client *i2c) unsigned int pmic_rev_value; int ret; - max77705 = devm_kzalloc(dev, sizeof(*max77705), GFP_KERNEL); + max77705 = devm_kzalloc_obj(dev, *max77705); if (!max77705) return -ENOMEM; diff --git a/drivers/mfd/max77759.c b/drivers/mfd/max77759.c index 72b608a1ab3f1e..5818ee2811d1cf 100644 --- a/drivers/mfd/max77759.c +++ b/drivers/mfd/max77759.c @@ -649,7 +649,7 @@ static int max77759_probe(struct i2c_client *client) unsigned int pmic_id; int ret; - max77759 = devm_kzalloc(&client->dev, sizeof(*max77759), GFP_KERNEL); + max77759 = devm_kzalloc_obj(&client->dev, *max77759); if (!max77759) return -ENOMEM; diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c index 9ae6715642ae17..d38f1da5e0806e 100644 --- a/drivers/mfd/max77843.c +++ b/drivers/mfd/max77843.c @@ -98,7 +98,7 @@ static int max77843_probe(struct i2c_client *i2c) unsigned int reg_data; int ret; - max77843 = devm_kzalloc(&i2c->dev, sizeof(*max77843), GFP_KERNEL); + max77843 = devm_kzalloc_obj(&i2c->dev, *max77843); if (!max77843) return -ENOMEM; diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c index 7bac1d6517717f..ba06a49c9c60c5 100644 --- a/drivers/mfd/max8907.c +++ b/drivers/mfd/max8907.c @@ -193,7 +193,7 @@ static int max8907_i2c_probe(struct i2c_client *i2c) pm_off = of_property_read_bool(i2c->dev.of_node, "maxim,system-power-controller"); - max8907 = devm_kzalloc(&i2c->dev, sizeof(struct max8907), GFP_KERNEL); + max8907 = devm_kzalloc_obj(&i2c->dev, struct max8907); if (!max8907) { ret = -ENOMEM; goto err_alloc_drvdata; diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c index ab19ff0c786732..00aff8949cad19 100644 --- a/drivers/mfd/max8925-i2c.c +++ b/drivers/mfd/max8925-i2c.c @@ -152,9 +152,8 @@ static int max8925_probe(struct i2c_client *client) if (node && !pdata) { /* parse DT to get platform data */ - pdata = devm_kzalloc(&client->dev, - sizeof(struct max8925_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, + struct max8925_platform_data); if (!pdata) return -ENOMEM; @@ -165,8 +164,7 @@ static int max8925_probe(struct i2c_client *client) return -EINVAL; } - chip = devm_kzalloc(&client->dev, - sizeof(struct max8925_chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct max8925_chip); if (chip == NULL) return -ENOMEM; chip->i2c = client; diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index 7ba8ed1dfde3ea..3a1216ea20a7bb 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c @@ -133,7 +133,7 @@ static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( { struct max8997_platform_data *pd; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return ERR_PTR(-ENOMEM); @@ -148,8 +148,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c) struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret = 0; - max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev), - GFP_KERNEL); + max8997 = devm_kzalloc_obj(&i2c->dev, struct max8997_dev); if (max8997 == NULL) return -ENOMEM; diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c index 5032eab05bb472..ec9fa4487f0112 100644 --- a/drivers/mfd/max8998.c +++ b/drivers/mfd/max8998.c @@ -138,7 +138,7 @@ static struct max8998_platform_data *max8998_i2c_parse_dt_pdata( { struct max8998_platform_data *pd; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return ERR_PTR(-ENOMEM); @@ -158,8 +158,7 @@ static int max8998_i2c_probe(struct i2c_client *i2c) struct max8998_dev *max8998; int ret = 0; - max8998 = devm_kzalloc(&i2c->dev, sizeof(struct max8998_dev), - GFP_KERNEL); + max8998 = devm_kzalloc_obj(&i2c->dev, struct max8998_dev); if (max8998 == NULL) return -ENOMEM; diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c index 6bc0e755ba3463..b5e0aa6f3ec75b 100644 --- a/drivers/mfd/mc13xxx-i2c.c +++ b/drivers/mfd/mc13xxx-i2c.c @@ -56,7 +56,7 @@ static int mc13xxx_i2c_probe(struct i2c_client *client) struct mc13xxx *mc13xxx; int ret; - mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL); + mc13xxx = devm_kzalloc_obj(&client->dev, *mc13xxx); if (!mc13xxx) return -ENOMEM; diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c index 56d2e57b7d7342..807b7e8503b2c3 100644 --- a/drivers/mfd/mc13xxx-spi.c +++ b/drivers/mfd/mc13xxx-spi.c @@ -125,7 +125,7 @@ static int mc13xxx_spi_probe(struct spi_device *spi) struct mc13xxx *mc13xxx; int ret; - mc13xxx = devm_kzalloc(&spi->dev, sizeof(*mc13xxx), GFP_KERNEL); + mc13xxx = devm_kzalloc_obj(&spi->dev, *mc13xxx); if (!mc13xxx) return -ENOMEM; diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c index a125d40fa121b4..58434ec2096697 100644 --- a/drivers/mfd/menelaus.c +++ b/drivers/mfd/menelaus.c @@ -1155,7 +1155,7 @@ static int menelaus_probe(struct i2c_client *client) return -ENODEV; } - menelaus = devm_kzalloc(&client->dev, sizeof(*menelaus), GFP_KERNEL); + menelaus = devm_kzalloc_obj(&client->dev, *menelaus); if (!menelaus) return -ENOMEM; diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c index 65d5eb18aa0044..fb25ca8e7a3105 100644 --- a/drivers/mfd/motorola-cpcap.c +++ b/drivers/mfd/motorola-cpcap.c @@ -272,7 +272,7 @@ static int cpcap_probe(struct spi_device *spi) unsigned int num_cells; int ret; - cpcap = devm_kzalloc(&spi->dev, sizeof(*cpcap), GFP_KERNEL); + cpcap = devm_kzalloc_obj(&spi->dev, *cpcap); if (!cpcap) return -ENOMEM; diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index 717b704c3c6b7b..e4959322985eec 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -38,7 +38,7 @@ static int mp2629_probe(struct i2c_client *client) struct mp2629_data *ddata; int ret; - ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&client->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/mt6358-irq.c b/drivers/mfd/mt6358-irq.c index 74cf2084304409..2321d88428c37e 100644 --- a/drivers/mfd/mt6358-irq.c +++ b/drivers/mfd/mt6358-irq.c @@ -250,17 +250,13 @@ int mt6358_irq_init(struct mt6397_chip *chip) mutex_init(&chip->irqlock); irqd = chip->irq_data; - irqd->enable_hwirq = devm_kcalloc(chip->dev, - irqd->num_pmic_irqs, - sizeof(*irqd->enable_hwirq), - GFP_KERNEL); + irqd->enable_hwirq = devm_kzalloc_objs(chip->dev, *irqd->enable_hwirq, + irqd->num_pmic_irqs); if (!irqd->enable_hwirq) return -ENOMEM; - irqd->cache_hwirq = devm_kcalloc(chip->dev, - irqd->num_pmic_irqs, - sizeof(*irqd->cache_hwirq), - GFP_KERNEL); + irqd->cache_hwirq = devm_kzalloc_objs(chip->dev, *irqd->cache_hwirq, + irqd->num_pmic_irqs); if (!irqd->cache_hwirq) return -ENOMEM; diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 8a97c30cad3fee..8c46e74be6fbdd 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -531,7 +531,7 @@ static int mt6360_probe(struct i2c_client *client) struct mt6360_ddata *ddata; int i, ret; - ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&client->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/mt6370.c b/drivers/mfd/mt6370.c index c7c2efe3598cd3..e97858dce95fc0 100644 --- a/drivers/mfd/mt6370.c +++ b/drivers/mfd/mt6370.c @@ -235,7 +235,7 @@ static int mt6370_probe(struct i2c_client *i2c) struct device *dev = &i2c->dev; int ret, vid; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c index 5d5f816492aaad..16dbcc783b8368 100644 --- a/drivers/mfd/mt6397-core.c +++ b/drivers/mfd/mt6397-core.c @@ -359,7 +359,7 @@ static int mt6397_probe(struct platform_device *pdev) struct mt6397_chip *pmic; const struct chip_data *pmic_core; - pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&pdev->dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/mfd/mxs-lradc.c b/drivers/mfd/mxs-lradc.c index 64afc76317904b..30a66e26816999 100644 --- a/drivers/mfd/mxs-lradc.c +++ b/drivers/mfd/mxs-lradc.c @@ -133,7 +133,7 @@ static int mxs_lradc_probe(struct platform_device *pdev) int ret = 0; u32 ts_wires = 0; - lradc = devm_kzalloc(&pdev->dev, sizeof(*lradc), GFP_KERNEL); + lradc = devm_kzalloc_obj(&pdev->dev, *lradc); if (!lradc) return -ENOMEM; diff --git a/drivers/mfd/nct6694.c b/drivers/mfd/nct6694.c index 308b2fda3055c5..dabd83b9d455c3 100644 --- a/drivers/mfd/nct6694.c +++ b/drivers/mfd/nct6694.c @@ -280,15 +280,15 @@ static int nct6694_usb_probe(struct usb_interface *iface, struct nct6694 *nct6694; int ret; - nct6694 = devm_kzalloc(dev, sizeof(*nct6694), GFP_KERNEL); + nct6694 = devm_kzalloc_obj(dev, *nct6694); if (!nct6694) return -ENOMEM; - nct6694->usb_msg = devm_kzalloc(dev, sizeof(union nct6694_usb_msg), GFP_KERNEL); + nct6694->usb_msg = devm_kzalloc_obj(dev, union nct6694_usb_msg); if (!nct6694->usb_msg) return -ENOMEM; - nct6694->int_buffer = devm_kzalloc(dev, sizeof(*nct6694->int_buffer), GFP_KERNEL); + nct6694->int_buffer = devm_kzalloc_obj(dev, *nct6694->int_buffer); if (!nct6694->int_buffer) return -ENOMEM; diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c index 08c68de0f01bce..4521f38ec25637 100644 --- a/drivers/mfd/ntxec.c +++ b/drivers/mfd/ntxec.c @@ -153,7 +153,7 @@ static int ntxec_probe(struct i2c_client *client) const struct mfd_cell *subdevs; size_t n_subdevs; - ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kmalloc_obj(&client->dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/mfd/ocelot-spi.c b/drivers/mfd/ocelot-spi.c index d3ab4868a52388..52bde8d4daf387 100644 --- a/drivers/mfd/ocelot-spi.c +++ b/drivers/mfd/ocelot-spi.c @@ -201,7 +201,7 @@ static int ocelot_spi_probe(struct spi_device *spi) struct regmap *r; int err; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c index 4d29a6e2ed87ab..a5426257776fc6 100644 --- a/drivers/mfd/omap-usb-host.c +++ b/drivers/mfd/omap-usb-host.c @@ -539,7 +539,7 @@ static int usbhs_omap_probe(struct platform_device *pdev) if (dev->of_node) { /* For DT boot we populate platform data from OF node */ - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -561,7 +561,7 @@ static int usbhs_omap_probe(struct platform_device *pdev) return -ENODEV; } - omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); + omap = devm_kzalloc_obj(dev, *omap); if (!omap) { dev_err(dev, "Memory allocation failed\n"); return -ENOMEM; diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c index 0f7fdb99c809bb..fcf17bed5ffc8d 100644 --- a/drivers/mfd/omap-usb-tll.c +++ b/drivers/mfd/omap-usb-tll.c @@ -230,7 +230,7 @@ static int usbtll_omap_probe(struct platform_device *pdev) break; } - tll = devm_kzalloc(dev, struct_size(tll, ch_clk, nch), GFP_KERNEL); + tll = devm_kzalloc_flex(dev, *tll, ch_clk, nch); if (!tll) { pm_runtime_put_sync(dev); pm_runtime_disable(dev); diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c index 7fc886f4f80e62..00332bd4f1c6d6 100644 --- a/drivers/mfd/palmas.c +++ b/drivers/mfd/palmas.c @@ -494,7 +494,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c) pdata = dev_get_platdata(&i2c->dev); if (node && !pdata) { - pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c->dev, *pdata); if (!pdata) return -ENOMEM; @@ -505,7 +505,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c) if (!pdata) return -EINVAL; - palmas = devm_kzalloc(&i2c->dev, sizeof(struct palmas), GFP_KERNEL); + palmas = devm_kzalloc_obj(&i2c->dev, struct palmas); if (palmas == NULL) return -ENOMEM; diff --git a/drivers/mfd/pf1550.c b/drivers/mfd/pf1550.c index c4f567c0556406..f4daaa20cb84b2 100644 --- a/drivers/mfd/pf1550.c +++ b/drivers/mfd/pf1550.c @@ -204,7 +204,7 @@ static int pf1550_i2c_probe(struct i2c_client *i2c) struct irq_domain *domain; int irq, ret = 0; - pf1550 = devm_kzalloc(&i2c->dev, sizeof(*pf1550), GFP_KERNEL); + pf1550 = devm_kzalloc_obj(&i2c->dev, *pf1550); if (!pf1550) return -ENOMEM; diff --git a/drivers/mfd/qcom-pm8xxx.c b/drivers/mfd/qcom-pm8xxx.c index 0cf374c015ce7e..0c3634f46cf349 100644 --- a/drivers/mfd/qcom-pm8xxx.c +++ b/drivers/mfd/qcom-pm8xxx.c @@ -546,9 +546,7 @@ static int pm8xxx_probe(struct platform_device *pdev) } pr_info("PMIC revision 2: %02X\n", val); - chip = devm_kzalloc(&pdev->dev, - struct_size(chip, config, data->num_irqs), - GFP_KERNEL); + chip = devm_kzalloc_flex(&pdev->dev, *chip, config, data->num_irqs); if (!chip) return -ENOMEM; diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c index b4b178caf754d8..5ac75acc3c77a5 100644 --- a/drivers/mfd/qcom-spmi-pmic.c +++ b/drivers/mfd/qcom-spmi-pmic.c @@ -260,7 +260,7 @@ static int pmic_spmi_probe(struct spmi_device *sdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - ctx = devm_kzalloc(&sdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&sdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/mfd/qcom_rpm.c b/drivers/mfd/qcom_rpm.c index 0defb3279af1d3..b38cd097444dfc 100644 --- a/drivers/mfd/qcom_rpm.c +++ b/drivers/mfd/qcom_rpm.c @@ -539,7 +539,7 @@ static int qcom_rpm_probe(struct platform_device *pdev) int irq_err; int ret; - rpm = devm_kzalloc(&pdev->dev, sizeof(*rpm), GFP_KERNEL); + rpm = devm_kzalloc_obj(&pdev->dev, *rpm); if (!rpm) return -ENOMEM; diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c index 93a3dd93404dd9..f77f010796f53a 100644 --- a/drivers/mfd/qnap-mcu.c +++ b/drivers/mfd/qnap-mcu.c @@ -354,7 +354,7 @@ static int qnap_mcu_probe(struct serdev_device *serdev) struct qnap_mcu *mcu; int ret; - mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL); + mcu = devm_kzalloc_obj(dev, *mcu); if (!mcu) return -ENOMEM; diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c index 53c57bafea8fc9..e06614769458e2 100644 --- a/drivers/mfd/rave-sp.c +++ b/drivers/mfd/rave-sp.c @@ -803,7 +803,7 @@ static int rave_sp_probe(struct serdev_device *serdev) return -EINVAL; } - sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL); + sp = devm_kzalloc_obj(dev, *sp); if (!sp) return -ENOMEM; diff --git a/drivers/mfd/rc5t583.c b/drivers/mfd/rc5t583.c index 2c0e8e9630f743..431ee5deec007d 100644 --- a/drivers/mfd/rc5t583.c +++ b/drivers/mfd/rc5t583.c @@ -244,7 +244,7 @@ static int rc5t583_i2c_probe(struct i2c_client *i2c) return -EINVAL; } - rc5t583 = devm_kzalloc(&i2c->dev, sizeof(*rc5t583), GFP_KERNEL); + rc5t583 = devm_kzalloc_obj(&i2c->dev, *rc5t583); if (!rc5t583) return -ENOMEM; diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c index 1d43458b4938a5..c6469007416923 100644 --- a/drivers/mfd/retu-mfd.c +++ b/drivers/mfd/retu-mfd.c @@ -237,7 +237,7 @@ static int retu_probe(struct i2c_client *i2c) return -ENODEV; rdat = &retu_data[i2c->addr - 1]; - rdev = devm_kzalloc(&i2c->dev, sizeof(*rdev), GFP_KERNEL); + rdev = devm_kzalloc_obj(&i2c->dev, *rdev); if (rdev == NULL) return -ENOMEM; diff --git a/drivers/mfd/rk8xx-core.c b/drivers/mfd/rk8xx-core.c index 21182df45d1b6b..058cd4ed671a27 100644 --- a/drivers/mfd/rk8xx-core.c +++ b/drivers/mfd/rk8xx-core.c @@ -773,7 +773,7 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap int ret; int i; - rk808 = devm_kzalloc(dev, sizeof(*rk808), GFP_KERNEL); + rk808 = devm_kzalloc_obj(dev, *rk808); if (!rk808) return -ENOMEM; rk808->dev = dev; diff --git a/drivers/mfd/rn5t618.c b/drivers/mfd/rn5t618.c index 8c68dd16bb9e31..d2f368b8c5bb42 100644 --- a/drivers/mfd/rn5t618.c +++ b/drivers/mfd/rn5t618.c @@ -182,7 +182,7 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c) struct rn5t618 *priv; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mfd/rohm-bd71828.c b/drivers/mfd/rohm-bd71828.c index 46faef7058f807..537f9753c5bf96 100644 --- a/drivers/mfd/rohm-bd71828.c +++ b/drivers/mfd/rohm-bd71828.c @@ -1023,7 +1023,7 @@ static struct regmap *bd72720_do_regmaps(struct i2c_client *i2c) return ERR_CAST(secondary_i2c); } - maps = devm_kzalloc(&i2c->dev, sizeof(*maps), GFP_KERNEL); + maps = devm_kzalloc_obj(&i2c->dev, *maps); if (!maps) return ERR_PTR(-ENOMEM); diff --git a/drivers/mfd/rohm-bd96801.c b/drivers/mfd/rohm-bd96801.c index 66fa017ad568a2..b6469cb68dce45 100644 --- a/drivers/mfd/rohm-bd96801.c +++ b/drivers/mfd/rohm-bd96801.c @@ -687,8 +687,8 @@ static int bd96801_i2c_probe(struct i2c_client *i2c) num_regu_irqs = ddata->num_intb_irqs + num_errb; - regulator_res = devm_kcalloc(&i2c->dev, num_regu_irqs, - sizeof(*regulator_res), GFP_KERNEL); + regulator_res = devm_kzalloc_objs(&i2c->dev, *regulator_res, + num_regu_irqs); if (!regulator_res) return -ENOMEM; diff --git a/drivers/mfd/rohm-pwrbutton.c b/drivers/mfd/rohm-pwrbutton.c index 96a6d1f01db5bd..34cdd6a4040ab0 100644 --- a/drivers/mfd/rohm-pwrbutton.c +++ b/drivers/mfd/rohm-pwrbutton.c @@ -58,7 +58,7 @@ int rohm_register_pwrbutton(struct device *dev, int irq, const char *name, if (irq <= 0) return -EINVAL; - nodes = devm_kcalloc(dev, 2, sizeof(*nodes), GFP_KERNEL); + nodes = devm_kzalloc_objs(dev, *nodes, 2); if (!nodes) return -ENOMEM; @@ -66,7 +66,7 @@ int rohm_register_pwrbutton(struct device *dev, int irq, const char *name, if (!nodes[GPIO_KEYS].name) return -ENOMEM; - parent_props = devm_kcalloc(dev, 2, sizeof(*parent_props), GFP_KERNEL); + parent_props = devm_kzalloc_objs(dev, *parent_props, 2); if (!parent_props) return -ENOMEM; @@ -77,7 +77,7 @@ int rohm_register_pwrbutton(struct device *dev, int irq, const char *name, if (wakeup) n_props++; - child_props = devm_kcalloc(dev, n_props, sizeof(*child_props), GFP_KERNEL); + child_props = devm_kzalloc_objs(dev, *child_props, n_props); if (!child_props) return -ENOMEM; diff --git a/drivers/mfd/rsmu_i2c.c b/drivers/mfd/rsmu_i2c.c index c57795ed20f4e7..771631fdb3506f 100644 --- a/drivers/mfd/rsmu_i2c.c +++ b/drivers/mfd/rsmu_i2c.c @@ -274,7 +274,7 @@ static int rsmu_i2c_probe(struct i2c_client *client) struct rsmu_ddata *rsmu; int ret; - rsmu = devm_kzalloc(&client->dev, sizeof(*rsmu), GFP_KERNEL); + rsmu = devm_kzalloc_obj(&client->dev, *rsmu); if (!rsmu) return -ENOMEM; diff --git a/drivers/mfd/rsmu_spi.c b/drivers/mfd/rsmu_spi.c index cdb0f9797ec6a2..66ed3175008d92 100644 --- a/drivers/mfd/rsmu_spi.c +++ b/drivers/mfd/rsmu_spi.c @@ -199,7 +199,7 @@ static int rsmu_spi_probe(struct spi_device *client) struct rsmu_ddata *rsmu; int ret; - rsmu = devm_kzalloc(&client->dev, sizeof(*rsmu), GFP_KERNEL); + rsmu = devm_kzalloc_obj(&client->dev, *rsmu); if (!rsmu) return -ENOMEM; diff --git a/drivers/mfd/rt5033.c b/drivers/mfd/rt5033.c index 072fd4447245f4..a1c4d02e2e72a8 100644 --- a/drivers/mfd/rt5033.c +++ b/drivers/mfd/rt5033.c @@ -57,7 +57,7 @@ static int rt5033_i2c_probe(struct i2c_client *i2c) unsigned int dev_id, chip_rev; int ret; - rt5033 = devm_kzalloc(&i2c->dev, sizeof(*rt5033), GFP_KERNEL); + rt5033 = devm_kzalloc_obj(&i2c->dev, *rt5033); if (!rt5033) return -ENOMEM; diff --git a/drivers/mfd/rz-mtu3.c b/drivers/mfd/rz-mtu3.c index 0a254e61ec0a5b..7e1313a57abc09 100644 --- a/drivers/mfd/rz-mtu3.c +++ b/drivers/mfd/rz-mtu3.c @@ -316,11 +316,11 @@ static int rz_mtu3_probe(struct platform_device *pdev) struct reset_control *rstc; unsigned int i; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; - ddata->priv_data = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + ddata->priv_data = devm_kzalloc_obj(dev, *priv); if (!ddata->priv_data) return -ENOMEM; diff --git a/drivers/mfd/sec-acpm.c b/drivers/mfd/sec-acpm.c index d11fbf5b94b792..f5e5990f5e81e2 100644 --- a/drivers/mfd/sec-acpm.c +++ b/drivers/mfd/sec-acpm.c @@ -451,7 +451,7 @@ static struct regmap *sec_pmic_acpm_regmap_init(struct device *dev, struct sec_pmic_acpm_bus_context *ctx; struct regmap *regmap; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); @@ -495,7 +495,7 @@ static int sec_pmic_acpm_probe(struct platform_device *pdev) if (irq < 0) return irq; - shared_ctx = devm_kzalloc(dev, sizeof(*shared_ctx), GFP_KERNEL); + shared_ctx = devm_kzalloc_obj(dev, *shared_ctx); if (!shared_ctx) return -ENOMEM; diff --git a/drivers/mfd/sec-common.c b/drivers/mfd/sec-common.c index fe92bc4a3dd26f..f8525645c73015 100644 --- a/drivers/mfd/sec-common.c +++ b/drivers/mfd/sec-common.c @@ -178,7 +178,7 @@ sec_pmic_parse_dt_pdata(struct device *dev) { struct sec_platform_data *pd; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return ERR_PTR(-ENOMEM); @@ -198,7 +198,7 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq, struct sec_pmic_dev *sec_pmic; int ret, num_sec_devs; - sec_pmic = devm_kzalloc(dev, sizeof(*sec_pmic), GFP_KERNEL); + sec_pmic = devm_kzalloc_obj(dev, *sec_pmic); if (!sec_pmic) return -ENOMEM; diff --git a/drivers/mfd/si476x-i2c.c b/drivers/mfd/si476x-i2c.c index 6351aef2d3bbcf..6fc96df823b1f7 100644 --- a/drivers/mfd/si476x-i2c.c +++ b/drivers/mfd/si476x-i2c.c @@ -689,7 +689,7 @@ static int si476x_core_probe(struct i2c_client *client) struct mfd_cell *cell; int cell_num; - core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(&client->dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/mfd/sky81452.c b/drivers/mfd/sky81452.c index 771b62a5c70f4a..f533409736d959 100644 --- a/drivers/mfd/sky81452.c +++ b/drivers/mfd/sky81452.c @@ -30,7 +30,7 @@ static int sky81452_probe(struct i2c_client *client) int ret; if (!pdata) { - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; } diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c index 009c200c1d5d29..2e2ee6d3b88940 100644 --- a/drivers/mfd/sm501.c +++ b/drivers/mfd/sm501.c @@ -1101,8 +1101,7 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm, return -ENOMEM; /* Create a gpiod lookup using gpiochip-local offsets */ - lookup = devm_kzalloc(&pdev->dev, struct_size(lookup, table, 3), - GFP_KERNEL); + lookup = devm_kzalloc_flex(&pdev->dev, *lookup, table, 3); if (!lookup) return -ENOMEM; diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c index 9a8e6add8fcaa5..b8e574ccff327c 100644 --- a/drivers/mfd/sprd-sc27xx-spi.c +++ b/drivers/mfd/sprd-sc27xx-spi.c @@ -204,7 +204,7 @@ static int sprd_pmic_probe(struct spi_device *spi) return -EINVAL; } - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (!ddata) return -ENOMEM; @@ -229,9 +229,8 @@ static int sprd_pmic_probe(struct spi_device *spi) ddata->irq_chip.num_regs = 1; ddata->irq_chip.num_irqs = pdata->num_irqs; - ddata->irqs = devm_kcalloc(&spi->dev, - pdata->num_irqs, sizeof(struct regmap_irq), - GFP_KERNEL); + ddata->irqs = devm_kzalloc_objs(&spi->dev, struct regmap_irq, + pdata->num_irqs); if (!ddata->irqs) return -ENOMEM; diff --git a/drivers/mfd/ssbi.c b/drivers/mfd/ssbi.c index 6e7aff6e2746dc..551a18fcaa85e7 100644 --- a/drivers/mfd/ssbi.c +++ b/drivers/mfd/ssbi.c @@ -264,7 +264,7 @@ static int ssbi_probe(struct platform_device *pdev) struct ssbi *ssbi; const char *type; - ssbi = devm_kzalloc(&pdev->dev, sizeof(*ssbi), GFP_KERNEL); + ssbi = devm_kzalloc_obj(&pdev->dev, *ssbi); if (!ssbi) return -ENOMEM; diff --git a/drivers/mfd/stm32-lptimer.c b/drivers/mfd/stm32-lptimer.c index 123659178cc2b6..a3d266fc199ee0 100644 --- a/drivers/mfd/stm32-lptimer.c +++ b/drivers/mfd/stm32-lptimer.c @@ -86,7 +86,7 @@ static int stm32_lptimer_probe(struct platform_device *pdev) void __iomem *mmio; int ret; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c index b3dbc02aaf7989..15e8a62c288196 100644 --- a/drivers/mfd/stm32-timers.c +++ b/drivers/mfd/stm32-timers.c @@ -292,7 +292,7 @@ static int stm32_timers_probe(struct platform_device *pdev) void __iomem *mmio; int ret; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c index f683fdb6ece665..9d58adf9be1500 100644 --- a/drivers/mfd/stmfx.c +++ b/drivers/mfd/stmfx.c @@ -414,7 +414,7 @@ static int stmfx_probe(struct i2c_client *client) struct stmfx *stmfx; int ret; - stmfx = devm_kzalloc(dev, sizeof(*stmfx), GFP_KERNEL); + stmfx = devm_kzalloc_obj(dev, *stmfx); if (!stmfx) return -ENOMEM; diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c index 3c5c2f157f5293..fd51ba74275cab 100644 --- a/drivers/mfd/stmpe.c +++ b/drivers/mfd/stmpe.c @@ -1372,7 +1372,7 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum) int ret; u32 val; - pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(ci->dev, *pdata); if (!pdata) return -ENOMEM; @@ -1381,7 +1381,7 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum) if (!of_property_present(np, "interrupts")) ci->irq = -1; - stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); + stmpe = devm_kzalloc_obj(ci->dev, struct stmpe); if (!stmpe) return -ENOMEM; diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c index 7c677b0344c604..7904f4d5b2b498 100644 --- a/drivers/mfd/stpmic1.c +++ b/drivers/mfd/stpmic1.c @@ -152,7 +152,7 @@ static int stpmic1_probe(struct i2c_client *i2c) struct device_node *np = dev->of_node; u32 reg; - ddata = devm_kzalloc(dev, sizeof(struct stpmic1), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, struct stpmic1); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/stw481x.c b/drivers/mfd/stw481x.c index 5ed64d53c23d06..082fb1f5cf3f1c 100644 --- a/drivers/mfd/stw481x.c +++ b/drivers/mfd/stw481x.c @@ -179,7 +179,7 @@ static int stw481x_probe(struct i2c_client *client) int ret; int i; - stw481x = devm_kzalloc(&client->dev, sizeof(*stw481x), GFP_KERNEL); + stw481x = devm_kzalloc_obj(&client->dev, *stw481x); if (!stw481x) return -ENOMEM; diff --git a/drivers/mfd/sun4i-gpadc.c b/drivers/mfd/sun4i-gpadc.c index bf2f6fdaf8bf9d..02e3ec49266d09 100644 --- a/drivers/mfd/sun4i-gpadc.c +++ b/drivers/mfd/sun4i-gpadc.c @@ -118,7 +118,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) return -EINVAL; } - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c index 2d4eb771e230f7..ca506c157bde97 100644 --- a/drivers/mfd/tc3589x.c +++ b/drivers/mfd/tc3589x.c @@ -331,7 +331,7 @@ tc3589x_of_probe(struct device *dev, enum tc3589x_version *version) struct device_node *child; const struct of_device_id *of_id; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -374,8 +374,7 @@ static int tc3589x_probe(struct i2c_client *i2c) | I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; - tc3589x = devm_kzalloc(&i2c->dev, sizeof(struct tc3589x), - GFP_KERNEL); + tc3589x = devm_kzalloc_obj(&i2c->dev, struct tc3589x); if (!tc3589x) return -ENOMEM; diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c index cfc9f88b984202..198a9b94fb7956 100644 --- a/drivers/mfd/ti-lmu.c +++ b/drivers/mfd/ti-lmu.c @@ -149,7 +149,7 @@ static int ti_lmu_probe(struct i2c_client *cl) if (!data) return -ENODEV; - lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL); + lmu = devm_kzalloc_obj(dev, *lmu); if (!lmu) return -ENOMEM; diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c index 81f07a1d780c53..d648201f4c003a 100644 --- a/drivers/mfd/ti_am335x_tscadc.c +++ b/drivers/mfd/ti_am335x_tscadc.c @@ -126,7 +126,7 @@ static int ti_tscadc_probe(struct platform_device *pdev) int readouts = 0, mag_tracks = 0; /* Allocate memory for device */ - tscadc = devm_kzalloc(&pdev->dev, sizeof(*tscadc), GFP_KERNEL); + tscadc = devm_kzalloc_obj(&pdev->dev, *tscadc); if (!tscadc) return -ENOMEM; diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c index b11cd2c03311a7..d87d5216d2c6f1 100644 --- a/drivers/mfd/tps6105x.c +++ b/drivers/mfd/tps6105x.c @@ -103,7 +103,7 @@ static struct tps6105x_platform_data *tps6105x_parse_dt(struct device *dev) dev_err(dev, "cannot support multiple operational modes"); return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); pdata->mode = TPS6105X_MODE_SHUTDOWN; @@ -131,7 +131,7 @@ static int tps6105x_probe(struct i2c_client *client) return PTR_ERR(pdata); } - tps6105x = devm_kmalloc(&client->dev, sizeof(*tps6105x), GFP_KERNEL); + tps6105x = devm_kmalloc_obj(&client->dev, *tps6105x); if (!tps6105x) return -ENOMEM; diff --git a/drivers/mfd/tps65010.c b/drivers/mfd/tps65010.c index 8a144ec5220141..17137697158a32 100644 --- a/drivers/mfd/tps65010.c +++ b/drivers/mfd/tps65010.c @@ -532,7 +532,7 @@ static int tps65010_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EINVAL; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c index 9865512dc7ccf2..f75d088257fdc4 100644 --- a/drivers/mfd/tps6507x.c +++ b/drivers/mfd/tps6507x.c @@ -87,8 +87,7 @@ static int tps6507x_i2c_probe(struct i2c_client *i2c) { struct tps6507x_dev *tps6507x; - tps6507x = devm_kzalloc(&i2c->dev, sizeof(struct tps6507x_dev), - GFP_KERNEL); + tps6507x = devm_kzalloc_obj(&i2c->dev, struct tps6507x_dev); if (tps6507x == NULL) return -ENOMEM; diff --git a/drivers/mfd/tps65086.c b/drivers/mfd/tps65086.c index 54832e9321b95d..897ccd7ec8529b 100644 --- a/drivers/mfd/tps65086.c +++ b/drivers/mfd/tps65086.c @@ -68,7 +68,7 @@ static int tps65086_probe(struct i2c_client *client) unsigned int version; int ret; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps65090.c b/drivers/mfd/tps65090.c index 24f42175a9b44b..8bc5f4acc7a303 100644 --- a/drivers/mfd/tps65090.c +++ b/drivers/mfd/tps65090.c @@ -178,7 +178,7 @@ static int tps65090_i2c_probe(struct i2c_client *client) if (pdata) irq_base = pdata->irq_base; - tps65090 = devm_kzalloc(&client->dev, sizeof(*tps65090), GFP_KERNEL); + tps65090 = devm_kzalloc_obj(&client->dev, *tps65090); if (!tps65090) return -ENOMEM; diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c index 569c28c8b20f5a..f087883dd5c8df 100644 --- a/drivers/mfd/tps65217.c +++ b/drivers/mfd/tps65217.c @@ -359,7 +359,7 @@ static int tps65217_probe(struct i2c_client *client) status_off = of_property_read_bool(client->dev.of_node, "ti,pmic-shutdown-controller"); - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps65218.c b/drivers/mfd/tps65218.c index 4f3e632f726ff3..491c379a1a0f50 100644 --- a/drivers/mfd/tps65218.c +++ b/drivers/mfd/tps65218.c @@ -285,7 +285,7 @@ static int tps65218_probe(struct i2c_client *client) int ret; unsigned int chipid; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c index e52fbf1481fefd..fc33cf09a4734b 100644 --- a/drivers/mfd/tps65219.c +++ b/drivers/mfd/tps65219.c @@ -481,7 +481,7 @@ static int tps65219_probe(struct i2c_client *client) bool pwr_button; int ret; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c index 600186b1e8cb4e..f524bbdc8f3b7c 100644 --- a/drivers/mfd/tps6586x.c +++ b/drivers/mfd/tps6586x.c @@ -418,7 +418,7 @@ static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *clien struct device_node *np = client->dev.of_node; struct tps6586x_platform_data *pdata; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) return NULL; @@ -539,7 +539,7 @@ static int tps6586x_i2c_probe(struct i2c_client *client) return -EIO; } - tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL); + tps6586x = devm_kzalloc_obj(&client->dev, *tps6586x); if (!tps6586x) return -ENOMEM; diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c index 6243b66b1b6f2e..67824eadac5888 100644 --- a/drivers/mfd/tps65910.c +++ b/drivers/mfd/tps65910.c @@ -381,8 +381,7 @@ static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client, *chip_id = (unsigned long)device_get_match_data(&client->dev); - board_info = devm_kzalloc(&client->dev, sizeof(*board_info), - GFP_KERNEL); + board_info = devm_kzalloc_obj(&client->dev, *board_info); if (!board_info) return NULL; @@ -457,11 +456,11 @@ static int tps65910_i2c_probe(struct i2c_client *i2c) if (!pmic_plat_data) return -EINVAL; - init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL); + init_data = devm_kzalloc_obj(&i2c->dev, *init_data); if (init_data == NULL) return -ENOMEM; - tps65910 = devm_kzalloc(&i2c->dev, sizeof(*tps65910), GFP_KERNEL); + tps65910 = devm_kzalloc_obj(&i2c->dev, *tps65910); if (tps65910 == NULL) return -ENOMEM; diff --git a/drivers/mfd/tps65912-i2c.c b/drivers/mfd/tps65912-i2c.c index 138e50497b5141..e3b18490b9e030 100644 --- a/drivers/mfd/tps65912-i2c.c +++ b/drivers/mfd/tps65912-i2c.c @@ -25,7 +25,7 @@ static int tps65912_i2c_probe(struct i2c_client *client) { struct tps65912 *tps; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps65912-spi.c b/drivers/mfd/tps65912-spi.c index 2442a2e67d676c..96d07631f21002 100644 --- a/drivers/mfd/tps65912-spi.c +++ b/drivers/mfd/tps65912-spi.c @@ -25,7 +25,7 @@ static int tps65912_spi_probe(struct spi_device *spi) { struct tps65912 *tps; - tps = devm_kzalloc(&spi->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&spi->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps6594-i2c.c b/drivers/mfd/tps6594-i2c.c index d2269f14f068ad..f9ae0b494d44d5 100644 --- a/drivers/mfd/tps6594-i2c.c +++ b/drivers/mfd/tps6594-i2c.c @@ -212,7 +212,7 @@ static int tps6594_i2c_probe(struct i2c_client *client) struct tps6594 *tps; const struct of_device_id *match; - tps = devm_kzalloc(dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/tps6594-spi.c b/drivers/mfd/tps6594-spi.c index bb95d6b64cb444..d8b3da5f14e8e8 100644 --- a/drivers/mfd/tps6594-spi.c +++ b/drivers/mfd/tps6594-spi.c @@ -97,7 +97,7 @@ static int tps6594_spi_probe(struct spi_device *spi) struct tps6594 *tps; const struct of_device_id *match; - tps = devm_kzalloc(dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index 7fbce76efd3052..88296178f77e7c 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c @@ -770,8 +770,7 @@ twl_probe(struct i2c_client *client) goto out; } - twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private), - GFP_KERNEL); + twl_priv = devm_kzalloc_obj(&client->dev, struct twl_private); if (!twl_priv) { status = -ENOMEM; goto out; @@ -788,10 +787,8 @@ twl_probe(struct i2c_client *client) } num_slaves = twl_get_num_slaves(); - twl_priv->twl_modules = devm_kcalloc(&client->dev, - num_slaves, - sizeof(struct twl_client), - GFP_KERNEL); + twl_priv->twl_modules = devm_kzalloc_objs(&client->dev, + struct twl_client, num_slaves); if (!twl_priv->twl_modules) { status = -ENOMEM; goto out; diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c index a4a550bafb3cc1..17ac1c598f1699 100644 --- a/drivers/mfd/twl4030-audio.c +++ b/drivers/mfd/twl4030-audio.c @@ -189,8 +189,7 @@ static int twl4030_audio_probe(struct platform_device *pdev) return -EINVAL; } - audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio), - GFP_KERNEL); + audio = devm_kzalloc_obj(&pdev->dev, struct twl4030_audio); if (!audio) return -ENOMEM; diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c index 0ca00f618d4d4e..502b1542186be1 100644 --- a/drivers/mfd/twl6030-irq.c +++ b/drivers/mfd/twl6030-irq.c @@ -303,7 +303,7 @@ int twl6030_init_irq(struct device *dev, int irq_num) nr_irqs = TWL6030_NR_IRQS; - twl6030_irq = devm_kzalloc(dev, sizeof(*twl6030_irq), GFP_KERNEL); + twl6030_irq = devm_kzalloc_obj(dev, *twl6030_irq); if (!twl6030_irq) return -ENOMEM; diff --git a/drivers/mfd/twl6040.c b/drivers/mfd/twl6040.c index 562a0f939f6e56..2b0ed6819c95ee 100644 --- a/drivers/mfd/twl6040.c +++ b/drivers/mfd/twl6040.c @@ -648,8 +648,7 @@ static int twl6040_probe(struct i2c_client *client) return -EINVAL; } - twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), - GFP_KERNEL); + twl6040 = devm_kzalloc_obj(&client->dev, struct twl6040); if (!twl6040) return -ENOMEM; diff --git a/drivers/mfd/upboard-fpga.c b/drivers/mfd/upboard-fpga.c index 9a9599dcb0a1a9..ab3d43b6a750d3 100644 --- a/drivers/mfd/upboard-fpga.c +++ b/drivers/mfd/upboard-fpga.c @@ -273,7 +273,7 @@ static int upboard_fpga_probe(struct platform_device *pdev) struct upboard_fpga *fpga; int ret; - fpga = devm_kzalloc(dev, sizeof(*fpga), GFP_KERNEL); + fpga = devm_kzalloc_obj(dev, *fpga); if (!fpga) return -ENOMEM; diff --git a/drivers/mfd/vexpress-sysreg.c b/drivers/mfd/vexpress-sysreg.c index f49cee91f71cc2..de6c89c940e870 100644 --- a/drivers/mfd/vexpress-sysreg.c +++ b/drivers/mfd/vexpress-sysreg.c @@ -115,8 +115,7 @@ static int vexpress_sysreg_probe(struct platform_device *pdev) * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with * older trees using sysreg node for MMC control lines. */ - mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip), - GFP_KERNEL); + mmc_gpio_chip = devm_kzalloc_obj(&pdev->dev, *mmc_gpio_chip); if (!mmc_gpio_chip) return -ENOMEM; diff --git a/drivers/mfd/wcd934x.c b/drivers/mfd/wcd934x.c index d57796933d8732..67d15c849aba61 100644 --- a/drivers/mfd/wcd934x.c +++ b/drivers/mfd/wcd934x.c @@ -223,7 +223,7 @@ static int wcd934x_slim_probe(struct slim_device *sdev) return dev_err_probe(dev, ret, "Failed to set DMA mask\n"); - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c index 9bee007f9c99bd..7fbeae088b2445 100644 --- a/drivers/mfd/wm831x-i2c.c +++ b/drivers/mfd/wm831x-i2c.c @@ -33,7 +33,7 @@ static int wm831x_i2c_probe(struct i2c_client *i2c) return -ENODEV; } - wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); + wm831x = devm_kzalloc_obj(&i2c->dev, struct wm831x); if (wm831x == NULL) return -ENOMEM; diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c index 1e519fd9a9e171..ddea5b9fd565a5 100644 --- a/drivers/mfd/wm831x-spi.c +++ b/drivers/mfd/wm831x-spi.c @@ -30,7 +30,7 @@ static int wm831x_spi_probe(struct spi_device *spi) return -ENODEV; } - wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL); + wm831x = devm_kzalloc_obj(&spi->dev, struct wm831x); if (wm831x == NULL) return -ENOMEM; diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c index 767c176b12a77b..35d2a8c7817ec9 100644 --- a/drivers/mfd/wm8350-i2c.c +++ b/drivers/mfd/wm8350-i2c.c @@ -22,7 +22,7 @@ static int wm8350_i2c_probe(struct i2c_client *i2c) struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret = 0; - wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL); + wm8350 = devm_kzalloc_obj(&i2c->dev, struct wm8350); if (wm8350 == NULL) return -ENOMEM; diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c index 8ecfe878a5ba49..4ef57b70172ab2 100644 --- a/drivers/mfd/wm8400-core.c +++ b/drivers/mfd/wm8400-core.c @@ -120,7 +120,7 @@ static int wm8400_i2c_probe(struct i2c_client *i2c) { struct wm8400 *wm8400; - wm8400 = devm_kzalloc(&i2c->dev, sizeof(struct wm8400), GFP_KERNEL); + wm8400 = devm_kzalloc_obj(&i2c->dev, struct wm8400); if (!wm8400) return -ENOMEM; diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c index 094c0b3dbd97d9..2c43b8ae1ba2f3 100644 --- a/drivers/mfd/wm8994-core.c +++ b/drivers/mfd/wm8994-core.c @@ -344,10 +344,9 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) goto err; } - wm8994->supplies = devm_kcalloc(wm8994->dev, - wm8994->num_supplies, - sizeof(struct regulator_bulk_data), - GFP_KERNEL); + wm8994->supplies = devm_kzalloc_objs(wm8994->dev, + struct regulator_bulk_data, + wm8994->num_supplies); if (!wm8994->supplies) { ret = -ENOMEM; goto err; @@ -614,7 +613,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c) struct wm8994 *wm8994; int ret; - wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); + wm8994 = devm_kzalloc_obj(&i2c->dev, struct wm8994); if (wm8994 == NULL) return -ENOMEM; diff --git a/drivers/mfd/wm97xx-core.c b/drivers/mfd/wm97xx-core.c index 1566a9b04b6a09..a4055626c680d9 100644 --- a/drivers/mfd/wm97xx-core.c +++ b/drivers/mfd/wm97xx-core.c @@ -257,8 +257,7 @@ static int wm97xx_ac97_probe(struct ac97_codec_device *adev) int ret = -ENODEV, nb_cells, i; struct wm97xx_pdata *pdata = snd_ac97_codec_get_platdata(adev); - wm97xx = devm_kzalloc(ac97_codec_dev2dev(adev), - sizeof(*wm97xx), GFP_KERNEL); + wm97xx = devm_kzalloc_obj(ac97_codec_dev2dev(adev), *wm97xx); if (!wm97xx) return -ENOMEM; diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 463a9a7574649a..f594775e9f5d8b 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -59,7 +59,7 @@ static int sbrmi_common_probe(struct device *dev, struct regmap *regmap, uint8_t struct sbrmi_data *data; int ret; - data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct sbrmi_data); if (!data) return -ENOMEM; diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c index 35a1963415346a..223f02adfd6c52 100644 --- a/drivers/misc/atmel-ssc.c +++ b/drivers/misc/atmel-ssc.c @@ -193,7 +193,7 @@ static int ssc_probe(struct platform_device *pdev) struct ssc_device *ssc; const struct atmel_ssc_platform_data *plat_dat; - ssc = devm_kzalloc(&pdev->dev, sizeof(struct ssc_device), GFP_KERNEL); + ssc = devm_kzalloc_obj(&pdev->dev, struct ssc_device); if (!ssc) { dev_dbg(&pdev->dev, "out of memory\n"); return -ENOMEM; diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c index 98fc5970b2bb1b..26bae1aec423e0 100644 --- a/drivers/misc/bh1770glc.c +++ b/drivers/misc/bh1770glc.c @@ -1169,7 +1169,7 @@ static int bh1770_probe(struct i2c_client *client) struct bh1770_chip *chip; int err; - chip = devm_kzalloc(&client->dev, sizeof *chip, GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/misc/cardreader/alcor_pci.c b/drivers/misc/cardreader/alcor_pci.c index e76fd4b5d6ccc1..f2885833395e0c 100644 --- a/drivers/misc/cardreader/alcor_pci.c +++ b/drivers/misc/cardreader/alcor_pci.c @@ -106,7 +106,7 @@ static int alcor_pci_probe(struct pci_dev *pdev, if (ret) return ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/misc/cardreader/rtsx_usb.c b/drivers/misc/cardreader/rtsx_usb.c index a127744918f426..c53a5543444f91 100644 --- a/drivers/misc/cardreader/rtsx_usb.c +++ b/drivers/misc/cardreader/rtsx_usb.c @@ -292,7 +292,7 @@ int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status) return -EINVAL; if (polling_pipe == 0) { - buf = kzalloc(sizeof(u16), GFP_KERNEL); + buf = kzalloc_obj(u16); if (!buf) return -ENOMEM; @@ -633,7 +633,7 @@ static int rtsx_usb_probe(struct usb_interface *intf, ": Realtek USB Card Reader found at bus %03d address %03d\n", usb_dev->bus->busnum, usb_dev->devnum); - ucr = devm_kzalloc(&intf->dev, sizeof(*ucr), GFP_KERNEL); + ucr = devm_kzalloc_obj(&intf->dev, *ucr); if (!ucr) return -ENOMEM; diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c index 2ab6f6884766ab..027af039ac09d1 100644 --- a/drivers/misc/cb710/core.c +++ b/drivers/misc/cb710/core.c @@ -214,8 +214,7 @@ static int cb710_probe(struct pci_dev *pdev, if (val & CB710_SLOT_SM) ++n; - chip = devm_kzalloc(&pdev->dev, struct_size(chip, slot, n), - GFP_KERNEL); + chip = devm_kzalloc_flex(&pdev->dev, *chip, slot, n); if (!chip) return -ENOMEM; diff --git a/drivers/misc/dw-xdata-pcie.c b/drivers/misc/dw-xdata-pcie.c index a604c0e9c038bc..dc097445588c5a 100644 --- a/drivers/misc/dw-xdata-pcie.c +++ b/drivers/misc/dw-xdata-pcie.c @@ -313,7 +313,7 @@ static int dw_xdata_pcie_probe(struct pci_dev *pdev, pci_set_master(pdev); /* Allocate memory */ - dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL); + dw = devm_kzalloc_obj(dev, *dw); if (!dw) return -ENOMEM; diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c index ea7478cfdd2793..59911d8c2e5b42 100644 --- a/drivers/misc/eeprom/idt_89hpesx.c +++ b/drivers/misc/eeprom/idt_89hpesx.c @@ -1130,8 +1130,7 @@ static struct idt_89hpesx_dev *idt_create_pdev(struct i2c_client *client) struct idt_89hpesx_dev *pdev; /* Allocate memory for driver data */ - pdev = devm_kmalloc(&client->dev, sizeof(struct idt_89hpesx_dev), - GFP_KERNEL); + pdev = devm_kmalloc_obj(&client->dev, struct idt_89hpesx_dev); if (pdev == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index af18ff1992eedb..cdc2627bdaf2e9 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -2427,7 +2427,7 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct struct fastrpc_device *fdev; int err; - fdev = devm_kzalloc(dev, sizeof(*fdev), GFP_KERNEL); + fdev = devm_kzalloc_obj(dev, *fdev); if (!fdev) return -ENOMEM; diff --git a/drivers/misc/gehc-achc.c b/drivers/misc/gehc-achc.c index 2c1222edb5dcf9..17697da64afe71 100644 --- a/drivers/misc/gehc-achc.c +++ b/drivers/misc/gehc-achc.c @@ -510,7 +510,7 @@ static int gehc_achc_probe(struct spi_device *spi) spi->bits_per_word = 8; spi->mode = SPI_MODE_0; - achc = devm_kzalloc(&spi->dev, sizeof(*achc), GFP_KERNEL); + achc = devm_kzalloc_obj(&spi->dev, *achc); if (!achc) return -ENOMEM; spi_set_drvdata(spi, achc); diff --git a/drivers/misc/hi6421v600-irq.c b/drivers/misc/hi6421v600-irq.c index 033f30014aa6aa..7d2eb7ed769828 100644 --- a/drivers/misc/hi6421v600-irq.c +++ b/drivers/misc/hi6421v600-irq.c @@ -230,7 +230,7 @@ static int hi6421v600_irq_probe(struct platform_device *pdev) if (WARN_ON(!regmap)) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/misc/keba/cp500.c b/drivers/misc/keba/cp500.c index c2ca63e4081473..3cc42744c8fb9d 100644 --- a/drivers/misc/keba/cp500.c +++ b/drivers/misc/keba/cp500.c @@ -869,7 +869,7 @@ static int cp500_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) char buf[64]; int ret; - cp500 = devm_kzalloc(dev, sizeof(*cp500), GFP_KERNEL); + cp500 = devm_kzalloc_obj(dev, *cp500); if (!cp500) return -ENOMEM; cp500->pci_dev = pci_dev; diff --git a/drivers/misc/lan966x_pci.c b/drivers/misc/lan966x_pci.c index b0949c653e5ba1..0f3a8bab328a9a 100644 --- a/drivers/misc/lan966x_pci.c +++ b/drivers/misc/lan966x_pci.c @@ -163,7 +163,7 @@ static int lan966x_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i if (ret) return ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/misc/lattice-ecp3-config.c b/drivers/misc/lattice-ecp3-config.c index 740b5cf5384273..0ef59138b1be97 100644 --- a/drivers/misc/lattice-ecp3-config.c +++ b/drivers/misc/lattice-ecp3-config.c @@ -190,7 +190,7 @@ static int lattice_ecp3_probe(struct spi_device *spi) struct fpga_data *data; int err; - data = devm_kzalloc(&spi->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&spi->dev, *data); if (!data) { dev_err(&spi->dev, "Memory allocation for fpga_data failed\n"); return -ENOMEM; diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c index b0b678e6b28dfe..61842b11d5015a 100644 --- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c +++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c @@ -38,7 +38,7 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id if (retval) return retval; - aux_bus = devm_kzalloc(&pdev->dev, sizeof(*aux_bus), GFP_KERNEL); + aux_bus = devm_kzalloc_obj(&pdev->dev, *aux_bus); if (!aux_bus) return -ENOMEM; diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gpio.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gpio.c index 82635db04dc534..258d6770b72dae 100644 --- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gpio.c +++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gpio.c @@ -480,7 +480,7 @@ static int pci1xxxx_gpio_probe(struct auxiliary_device *aux_dev, if (!pdata) return -EINVAL; - priv = devm_kzalloc(&aux_dev->dev, sizeof(struct pci1xxxx_gpio), GFP_KERNEL); + priv = devm_kzalloc_obj(&aux_dev->dev, struct pci1xxxx_gpio); if (!priv) return -ENOMEM; diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_otpe2p.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_otpe2p.c index 09841c4f1a06f7..281a40d6ef8ab6 100644 --- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_otpe2p.c +++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_otpe2p.c @@ -332,7 +332,7 @@ static int pci1xxxx_otp_eeprom_probe(struct auxiliary_device *aux_dev, if (!pdata) return -EINVAL; - priv = devm_kzalloc(&aux_dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&aux_dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/misc/mei/vsc-tp.c b/drivers/misc/mei/vsc-tp.c index 5410ec1c932867..0d0fe8dc69bee3 100644 --- a/drivers/misc/mei/vsc-tp.c +++ b/drivers/misc/mei/vsc-tp.c @@ -464,15 +464,15 @@ static int vsc_tp_probe(struct spi_device *spi) struct acpi_device *adev; int ret; - tp = devm_kzalloc(dev, sizeof(*tp), GFP_KERNEL); + tp = devm_kzalloc_obj(dev, *tp); if (!tp) return -ENOMEM; - tp->tx_buf = devm_kzalloc(dev, sizeof(*tp->tx_buf), GFP_KERNEL); + tp->tx_buf = devm_kzalloc_obj(dev, *tp->tx_buf); if (!tp->tx_buf) return -ENOMEM; - tp->rx_buf = devm_kzalloc(dev, sizeof(*tp->rx_buf), GFP_KERNEL); + tp->rx_buf = devm_kzalloc_obj(dev, *tp->rx_buf); if (!tp->rx_buf) return -ENOMEM; diff --git a/drivers/misc/mrvl_cn10k_dpi.c b/drivers/misc/mrvl_cn10k_dpi.c index 73ff0f198ec315..5c6806c64e180d 100644 --- a/drivers/misc/mrvl_cn10k_dpi.c +++ b/drivers/misc/mrvl_cn10k_dpi.c @@ -358,7 +358,8 @@ static int dpi_pfvf_mbox_setup(struct dpipf *dpi) int vf; for (vf = 0; vf < DPI_MAX_VFS; vf++) { - dpi->mbox[vf] = devm_kzalloc(&dpi->pdev->dev, sizeof(*dpi->mbox[vf]), GFP_KERNEL); + dpi->mbox[vf] = devm_kzalloc_obj(&dpi->pdev->dev, + *dpi->mbox[vf]); if (!dpi->mbox[vf]) return -ENOMEM; @@ -584,7 +585,7 @@ static int dpi_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct dpipf *dpi; int ret; - dpi = devm_kzalloc(dev, sizeof(*dpi), GFP_KERNEL); + dpi = devm_kzalloc_obj(dev, *dpi); if (!dpi) return -ENOMEM; diff --git a/drivers/misc/nsm.c b/drivers/misc/nsm.c index b6d3fa79a5e890..94434e3fbe5a2f 100644 --- a/drivers/misc/nsm.c +++ b/drivers/misc/nsm.c @@ -426,7 +426,7 @@ static int nsm_device_probe(struct virtio_device *vdev) struct nsm *nsm; int rc; - nsm = devm_kzalloc(&vdev->dev, sizeof(*nsm), GFP_KERNEL); + nsm = devm_kzalloc_obj(&vdev->dev, *nsm); if (!nsm) return -ENOMEM; diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c index b3cf599541112f..bae64e884a4546 100644 --- a/drivers/misc/open-dice.c +++ b/drivers/misc/open-dice.c @@ -159,7 +159,7 @@ static int __init open_dice_probe(struct platform_device *pdev) return -EINVAL; } - drvdata = devm_kmalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kmalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 6b18ea9146894e..dd49ca7f45c66b 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -1246,7 +1246,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, if (pci_is_bridge(pdev)) return -ENODEV; - test = devm_kzalloc(dev, sizeof(*test), GFP_KERNEL); + test = devm_kzalloc_obj(dev, *test); if (!test) return -ENOMEM; diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c index b57d773f68768b..3d43045bf6970c 100644 --- a/drivers/misc/pvpanic/pvpanic.c +++ b/drivers/misc/pvpanic/pvpanic.c @@ -188,7 +188,7 @@ int devm_pvpanic_probe(struct device *dev, void __iomem *base) if (!base) return -EINVAL; - pi = devm_kmalloc(dev, sizeof(*pi), GFP_KERNEL); + pi = devm_kmalloc_obj(dev, *pi); if (!pi) return -ENOMEM; diff --git a/drivers/misc/rp1/rp1_pci.c b/drivers/misc/rp1/rp1_pci.c index 207a676913a2aa..1963937300386d 100644 --- a/drivers/misc/rp1/rp1_pci.c +++ b/drivers/misc/rp1/rp1_pci.c @@ -197,7 +197,7 @@ static int rp1_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err_out; } - rp1 = devm_kzalloc(&pdev->dev, sizeof(*rp1), GFP_KERNEL); + rp1 = devm_kzalloc_obj(&pdev->dev, *rp1); if (!rp1) { err = -ENOMEM; goto err_out; diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c index 56952fd96cb868..a4b4a4cd5d75d8 100644 --- a/drivers/misc/smpro-errmon.c +++ b/drivers/misc/smpro-errmon.c @@ -577,7 +577,7 @@ static int smpro_errmon_probe(struct platform_device *pdev) { struct smpro_errmon *errmon; - errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL); + errmon = devm_kzalloc_obj(&pdev->dev, struct smpro_errmon); if (!errmon) return -ENOMEM; diff --git a/drivers/misc/smpro-misc.c b/drivers/misc/smpro-misc.c index 2ca5e3bcc21563..dc5d583d0353f3 100644 --- a/drivers/misc/smpro-misc.c +++ b/drivers/misc/smpro-misc.c @@ -115,7 +115,7 @@ static int smpro_misc_probe(struct platform_device *pdev) { struct smpro_misc *misc; - misc = devm_kzalloc(&pdev->dev, sizeof(struct smpro_misc), GFP_KERNEL); + misc = devm_kzalloc_obj(&pdev->dev, struct smpro_misc); if (!misc) return -ENOMEM; diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index c8990e83a65a2c..c5110c32f66121 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -267,9 +267,8 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) list_sort(NULL, &reserve_list, sram_reserve_cmp); if (exports) { - sram->partition = devm_kcalloc(sram->dev, - exports, sizeof(*sram->partition), - GFP_KERNEL); + sram->partition = devm_kzalloc_objs(sram->dev, *sram->partition, + exports); if (!sram->partition) { ret = -ENOMEM; goto err_chunks; @@ -383,7 +382,7 @@ static int sram_probe(struct platform_device *pdev) config = of_device_get_match_data(&pdev->dev); - sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); + sram = devm_kzalloc_obj(&pdev->dev, *sram); if (!sram) return -ENOMEM; diff --git a/drivers/misc/ti_fpc202.c b/drivers/misc/ti_fpc202.c index 9e2d24f8945743..c3c52e6a66823d 100644 --- a/drivers/misc/ti_fpc202.c +++ b/drivers/misc/ti_fpc202.c @@ -598,7 +598,7 @@ static int fpc202_probe(struct i2c_client *client) struct fpc202_priv *priv; int ret, port_id, led_id; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/misc/tps6594-pfsm.c b/drivers/misc/tps6594-pfsm.c index c3a0d6367f2c7a..823ed5e4126a2c 100644 --- a/drivers/misc/tps6594-pfsm.c +++ b/drivers/misc/tps6594-pfsm.c @@ -283,7 +283,7 @@ static int tps6594_pfsm_probe(struct platform_device *pdev) int ret; int i; - pfsm = devm_kzalloc(dev, sizeof(struct tps6594_pfsm), GFP_KERNEL); + pfsm = devm_kzalloc_obj(dev, struct tps6594_pfsm); if (!pfsm) return -ENOMEM; diff --git a/drivers/misc/vmw_vmci/vmci_guest.c b/drivers/misc/vmw_vmci/vmci_guest.c index 83355c0ec1d26b..ad447be6086c03 100644 --- a/drivers/misc/vmw_vmci/vmci_guest.c +++ b/drivers/misc/vmw_vmci/vmci_guest.c @@ -621,7 +621,7 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, iobase = pcim_iomap_table(pdev)[0]; } - vmci_dev = devm_kzalloc(&pdev->dev, sizeof(*vmci_dev), GFP_KERNEL); + vmci_dev = devm_kzalloc_obj(&pdev->dev, *vmci_dev); if (!vmci_dev) { dev_err(&pdev->dev, "Can't allocate memory for VMCI device\n"); diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c index e1a11820be011a..ceafda4bf32f27 100644 --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c @@ -443,14 +443,12 @@ static int qp_alloc_ppn_set(void *prod_q, return VMCI_ERROR_ALREADY_EXISTS; produce_ppns = - kmalloc_array(num_produce_pages, sizeof(*produce_ppns), - GFP_KERNEL); + kmalloc_objs(*produce_ppns, num_produce_pages); if (!produce_ppns) return VMCI_ERROR_NO_MEM; consume_ppns = - kmalloc_array(num_consume_pages, sizeof(*consume_ppns), - GFP_KERNEL); + kmalloc_objs(*consume_ppns, num_consume_pages); if (!consume_ppns) { kfree(produce_ppns); return VMCI_ERROR_NO_MEM; diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c index a19eed39c516cf..3660e6b47a8201 100644 --- a/drivers/misc/xilinx_sdfec.c +++ b/drivers/misc/xilinx_sdfec.c @@ -1345,7 +1345,7 @@ static int xsdfec_probe(struct platform_device *pdev) int err; bool irq_enabled = true; - xsdfec = devm_kzalloc(&pdev->dev, sizeof(*xsdfec), GFP_KERNEL); + xsdfec = devm_kzalloc_obj(&pdev->dev, *xsdfec); if (!xsdfec) return -ENOMEM; diff --git a/drivers/misc/xilinx_tmr_inject.c b/drivers/misc/xilinx_tmr_inject.c index 6284606ffb9ff6..cf2604de8d3edc 100644 --- a/drivers/misc/xilinx_tmr_inject.c +++ b/drivers/misc/xilinx_tmr_inject.c @@ -113,8 +113,7 @@ static int xtmr_inject_probe(struct platform_device *pdev) struct xtmr_inject_dev *xtmr_inject; int err; - xtmr_inject = devm_kzalloc(&pdev->dev, sizeof(*xtmr_inject), - GFP_KERNEL); + xtmr_inject = devm_kzalloc_obj(&pdev->dev, *xtmr_inject); if (!xtmr_inject) return -ENOMEM; diff --git a/drivers/misc/xilinx_tmr_manager.c b/drivers/misc/xilinx_tmr_manager.c index 03912a90fd9543..598584d76fa5ae 100644 --- a/drivers/misc/xilinx_tmr_manager.c +++ b/drivers/misc/xilinx_tmr_manager.c @@ -166,8 +166,7 @@ static int xtmr_manager_probe(struct platform_device *pdev) struct resource *res; int err; - xtmr_manager = devm_kzalloc(&pdev->dev, sizeof(*xtmr_manager), - GFP_KERNEL); + xtmr_manager = devm_kzalloc_obj(&pdev->dev, *xtmr_manager); if (!xtmr_manager) return -ENOMEM; diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 8e9e618391980a..177eed813af3b0 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -461,7 +461,7 @@ int mmc_of_parse_voltage(struct mmc_host *host, u32 *mask) return -EINVAL; } - voltage_ranges = kcalloc(2 * num_ranges, sizeof(*voltage_ranges), GFP_KERNEL); + voltage_ranges = kzalloc_objs(*voltage_ranges, 2 * num_ranges); if (!voltage_ranges) return -ENOMEM; diff --git a/drivers/mmc/core/pwrseq_emmc.c b/drivers/mmc/core/pwrseq_emmc.c index 35af67e2694513..95165951202afd 100644 --- a/drivers/mmc/core/pwrseq_emmc.c +++ b/drivers/mmc/core/pwrseq_emmc.c @@ -61,7 +61,7 @@ static int mmc_pwrseq_emmc_probe(struct platform_device *pdev) struct mmc_pwrseq_emmc *pwrseq; struct device *dev = &pdev->dev; - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); + pwrseq = devm_kzalloc_obj(dev, *pwrseq); if (!pwrseq) return -ENOMEM; diff --git a/drivers/mmc/core/pwrseq_sd8787.c b/drivers/mmc/core/pwrseq_sd8787.c index 30282155a0e11e..b221aa535aac1a 100644 --- a/drivers/mmc/core/pwrseq_sd8787.c +++ b/drivers/mmc/core/pwrseq_sd8787.c @@ -91,7 +91,7 @@ static int mmc_pwrseq_sd8787_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; const struct of_device_id *match; - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); + pwrseq = devm_kzalloc_obj(dev, *pwrseq); if (!pwrseq) return -ENOMEM; diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c index 4b47e6c3b04b99..c95cf16628ac18 100644 --- a/drivers/mmc/core/pwrseq_simple.c +++ b/drivers/mmc/core/pwrseq_simple.c @@ -126,7 +126,7 @@ static int mmc_pwrseq_simple_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ngpio; - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); + pwrseq = devm_kzalloc_obj(dev, *pwrseq); if (!pwrseq) return -ENOMEM; diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index c5bc6268803eb6..df8fc17932284b 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c @@ -43,7 +43,7 @@ int mmc_gpio_alloc(struct mmc_host *host) const char *devname = dev_name(host->parent); struct mmc_gpio *ctx; - ctx = devm_kzalloc(host->parent, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(host->parent, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index 98933be5f1744c..379b90c6f5aa5f 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c @@ -2448,7 +2448,7 @@ static int atmci_probe(struct platform_device *pdev) if (irq < 0) return irq; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mmc/host/cavium-octeon.c b/drivers/mmc/host/cavium-octeon.c index 671dd1a36a74ad..dd62b96712c81f 100644 --- a/drivers/mmc/host/cavium-octeon.c +++ b/drivers/mmc/host/cavium-octeon.c @@ -155,7 +155,7 @@ static int octeon_mmc_probe(struct platform_device *pdev) int i, ret = 0; u64 val; - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c index ee19ea52b27d0c..526ae9019b2f80 100644 --- a/drivers/mmc/host/cavium-thunderx.c +++ b/drivers/mmc/host/cavium-thunderx.c @@ -63,7 +63,7 @@ static int thunder_mmc_probe(struct pci_dev *pdev, struct cvm_mmc_host *host; int ret, i = 0; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c index a466cd88b043e9..0b2e2a0cf7648d 100644 --- a/drivers/mmc/host/cqhci-core.c +++ b/drivers/mmc/host/cqhci-core.c @@ -1147,7 +1147,7 @@ struct cqhci_host *cqhci_pltfm_init(struct platform_device *pdev) return ERR_PTR(-EINVAL); } - cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(&pdev->dev, *cq_host); if (!cq_host) return ERR_PTR(-ENOMEM); cq_host->mmio = devm_ioremap(&pdev->dev, @@ -1193,8 +1193,8 @@ int cqhci_init(struct cqhci_host *cq_host, struct mmc_host *mmc, if (mmc->caps2 & MMC_CAP2_CQE_DCMD) mmc->cqe_qdepth -= 1; - cq_host->slot = devm_kcalloc(mmc_dev(mmc), cq_host->num_slots, - sizeof(*cq_host->slot), GFP_KERNEL); + cq_host->slot = devm_kzalloc_objs(mmc_dev(mmc), *cq_host->slot, + cq_host->num_slots); if (!cq_host->slot) { err = -ENOMEM; goto out_err; diff --git a/drivers/mmc/host/cqhci-crypto.c b/drivers/mmc/host/cqhci-crypto.c index 5a467098a0d6ca..6e869b7e109a94 100644 --- a/drivers/mmc/host/cqhci-crypto.c +++ b/drivers/mmc/host/cqhci-crypto.c @@ -182,8 +182,8 @@ int cqhci_crypto_init(struct cqhci_host *cq_host) (u32)cq_host->crypto_capabilities.config_array_ptr * 0x100; cq_host->crypto_cap_array = - devm_kcalloc(dev, cq_host->crypto_capabilities.num_crypto_cap, - sizeof(cq_host->crypto_cap_array[0]), GFP_KERNEL); + devm_kzalloc_objs(dev, cq_host->crypto_cap_array[0], + cq_host->crypto_capabilities.num_crypto_cap); if (!cq_host->crypto_cap_array) { err = -ENOMEM; goto out; diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c index 4b76b997ddc15d..6616f0cf96384c 100644 --- a/drivers/mmc/host/dw_mmc-exynos.c +++ b/drivers/mmc/host/dw_mmc-exynos.c @@ -380,7 +380,7 @@ static int dw_mci_exynos_parse_dt(struct dw_mci *host) int idx; int ret; - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(host->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc-hi3798cv200.c b/drivers/mmc/host/dw_mmc-hi3798cv200.c index 4b723ed3259caf..b5bcd58fe2d330 100644 --- a/drivers/mmc/host/dw_mmc-hi3798cv200.c +++ b/drivers/mmc/host/dw_mmc-hi3798cv200.c @@ -120,7 +120,7 @@ static int dw_mci_hi3798cv200_init(struct dw_mci *host) struct hi3798cv200_priv *priv; int ret; - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(host->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc-hi3798mv200.c b/drivers/mmc/host/dw_mmc-hi3798mv200.c index fda417888be975..9597e09549599c 100644 --- a/drivers/mmc/host/dw_mmc-hi3798mv200.c +++ b/drivers/mmc/host/dw_mmc-hi3798mv200.c @@ -180,7 +180,7 @@ static int dw_mci_hi3798mv200_init(struct dw_mci *host) struct dw_mci_hi3798mv200_priv *priv; struct device_node *np = host->dev->of_node; - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(host->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c index 59b802c9f2b86e..ed217b0619e1db 100644 --- a/drivers/mmc/host/dw_mmc-k3.c +++ b/drivers/mmc/host/dw_mmc-k3.c @@ -117,7 +117,7 @@ static int dw_mci_hi6220_parse_dt(struct dw_mci *host) { struct k3_priv *priv; - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(host->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c index a07707a99a787b..ffb9387bb8df6a 100644 --- a/drivers/mmc/host/dw_mmc-rockchip.c +++ b/drivers/mmc/host/dw_mmc-rockchip.c @@ -424,7 +424,7 @@ static int dw_mci_common_parse_dt(struct dw_mci *host) struct device_node *np = host->dev->of_node; struct dw_mci_rockchip_priv_data *priv; - priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(host->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c index 6a3c26b7c82d80..923cf1450de555 100644 --- a/drivers/mmc/host/jz4740_mmc.c +++ b/drivers/mmc/host/jz4740_mmc.c @@ -1151,12 +1151,13 @@ static void jz4740_mmc_remove(struct platform_device *pdev) { struct jz4740_mmc_host *host = platform_get_drvdata(pdev); + /* The card's driver may still send commands as it goes */ + mmc_remove_host(host->mmc); + timer_delete_sync(&host->timeout_timer); jz4740_mmc_set_irq_enabled(host, 0xff, false); jz4740_mmc_reset(host); - mmc_remove_host(host->mmc); - free_irq(host->irq, host); if (host->use_dma) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 7ef16d7c03cb62..d2b9b5df9596c2 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -125,6 +125,7 @@ #define SD_EMMC_CFG_RESP_TIMEOUT 256 /* in clock cycles */ #define SD_EMMC_CMD_TIMEOUT 1024 /* in ms */ #define SD_EMMC_CMD_TIMEOUT_DATA 4096 /* in ms */ +#define SD_EMMC_CMD_TIMEOUT_MAX 32768 /* in ms, 2^15: limit of CMD_CFG_TIMEOUT_MASK */ #define SD_EMMC_CFG_CMD_GAP 16 /* in clock cycles */ #define SD_EMMC_DESC_BUF_LEN PAGE_SIZE @@ -212,7 +213,21 @@ static unsigned int meson_mmc_get_timeout_msecs(struct mmc_data *data) timeout = roundup_pow_of_two(timeout); - return min(timeout, 32768U); /* max. 2^15 ms */ + return min_t(unsigned int, timeout, SD_EMMC_CMD_TIMEOUT_MAX); +} + +/* For R1b the controller waits for busy to be released within this timeout. */ +static unsigned int meson_mmc_get_cmd_timeout_msecs(struct mmc_command *cmd) +{ + unsigned int timeout = cmd->busy_timeout; + + if (!timeout) + return SD_EMMC_CMD_TIMEOUT; + + timeout = clamp_t(unsigned int, timeout, SD_EMMC_CMD_TIMEOUT, + SD_EMMC_CMD_TIMEOUT_MAX); + + return roundup_pow_of_two(timeout); } static struct mmc_command *meson_mmc_get_next_command(struct mmc_command *cmd) @@ -453,7 +468,7 @@ static int meson_mmc_clk_init(struct meson_host *host) } /* create the mux */ - mux = devm_kzalloc(host->dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(host->dev, *mux); if (!mux) return -ENOMEM; @@ -474,7 +489,7 @@ static int meson_mmc_clk_init(struct meson_host *host) return PTR_ERR(host->mux_clk); /* create the divider */ - div = devm_kzalloc(host->dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(host->dev, *div); if (!div) return -ENOMEM; @@ -841,7 +856,7 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) cmd_data = host->bounce_dma_addr & CMD_DATA_MASK; } else { cmd_cfg |= FIELD_PREP(CMD_CFG_TIMEOUT_MASK, - ilog2(SD_EMMC_CMD_TIMEOUT)); + ilog2(meson_mmc_get_cmd_timeout_msecs(cmd))); } /* Last descriptor */ @@ -1080,8 +1095,8 @@ static int meson_mmc_card_busy(struct mmc_host *mmc) regval = readl(host->regs + SD_EMMC_STATUS); - /* We are only interrested in lines 0 to 3, so mask the other ones */ - return !(FIELD_GET(STATUS_DATI, regval) & 0xf); + /* The card signals busy on DAT0 alone. */ + return !(FIELD_GET(STATUS_DATI, regval) & BIT(0)); } static int meson_mmc_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) @@ -1168,6 +1183,9 @@ static int meson_mmc_probe(struct platform_device *pdev) mmc->caps |= MMC_CAP_CMD23; + /* The longest busy wait the CMD_CFG timeout field can hold. */ + mmc->max_busy_timeout = SD_EMMC_CMD_TIMEOUT_MAX; + if (mmc->caps & MMC_CAP_SDIO_IRQ) mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; diff --git a/drivers/mmc/host/meson-mx-sdhc-clkc.c b/drivers/mmc/host/meson-mx-sdhc-clkc.c index 6d619bd0a8dc89..b303e6f12e280a 100644 --- a/drivers/mmc/host/meson-mx-sdhc-clkc.c +++ b/drivers/mmc/host/meson-mx-sdhc-clkc.c @@ -95,7 +95,7 @@ int meson_mx_sdhc_register_clkc(struct device *dev, void __iomem *base, struct meson_mx_sdhc_clkc *clkc_data; int ret; - clkc_data = devm_kzalloc(dev, sizeof(*clkc_data), GFP_KERNEL); + clkc_data = devm_kzalloc_obj(dev, *clkc_data); if (!clkc_data) return -ENOMEM; diff --git a/drivers/mmc/host/meson-mx-sdio.c b/drivers/mmc/host/meson-mx-sdio.c index bef5e843f449b0..5d48c8e7fbf9f8 100644 --- a/drivers/mmc/host/meson-mx-sdio.c +++ b/drivers/mmc/host/meson-mx-sdio.c @@ -580,7 +580,7 @@ static struct clk *meson_mx_mmc_register_clk(struct device *dev, * prevent use-after-free as meson_mx_mmc_host is free'd before * dev (controller dev, not mmc_host->dev) is free'd. */ - host_clkc = devm_kzalloc(dev, sizeof(*host_clkc), GFP_KERNEL); + host_clkc = devm_kzalloc_obj(dev, *host_clkc); if (!host_clkc) return ERR_PTR(-ENOMEM); diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index 57e172bd348718..438798176c4f27 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -352,8 +352,8 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) hsq->next_tag = HSQ_INVALID_TAG; hsq->tail_tag = HSQ_INVALID_TAG; - hsq->slot = devm_kcalloc(mmc_dev(mmc), hsq->num_slots, - sizeof(struct hsq_slot), GFP_KERNEL); + hsq->slot = devm_kzalloc_objs(mmc_dev(mmc), struct hsq_slot, + hsq->num_slots); if (!hsq->slot) return -ENOMEM; diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 416bdb184ed4c7..f5ee793ddad641 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -846,7 +846,7 @@ int mmci_dmae_setup(struct mmci_host *host) const char *rxname, *txname; struct mmci_dmae_priv *dmae; - dmae = devm_kzalloc(mmc_dev(host->mmc), sizeof(*dmae), GFP_KERNEL); + dmae = devm_kzalloc_obj(mmc_dev(host->mmc), *dmae); if (!dmae) return -ENOMEM; @@ -2217,7 +2217,7 @@ static int mmci_probe(struct amba_device *dev, } if (!plat) { - plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(&dev->dev, *plat); if (!plat) return -ENOMEM; } @@ -2477,11 +2477,13 @@ static int mmci_probe(struct amba_device *dev, ret = mmc_add_host(mmc); if (ret) - goto clk_disable; + goto dma_release; pm_runtime_put(&dev->dev); return 0; +dma_release: + mmci_dma_release(host); clk_disable: clk_disable_unprepare(host->clk); return ret; diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c index 9dc51859c2e51e..a14986491b71df 100644 --- a/drivers/mmc/host/mmci_stm32_sdmmc.c +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c @@ -190,7 +190,7 @@ static int sdmmc_idma_setup(struct mmci_host *host) struct sdmmc_idma *idma; struct device *dev = mmc_dev(host->mmc); - idma = devm_kzalloc(dev, sizeof(*idma), GFP_KERNEL); + idma = devm_kzalloc_obj(dev, *idma); if (!idma) return -ENOMEM; @@ -734,7 +734,7 @@ void sdmmc_variant_init(struct mmci_host *host) if (IS_ERR(base_dlyb)) return; - dlyb = devm_kzalloc(mmc_dev(host->mmc), sizeof(*dlyb), GFP_KERNEL); + dlyb = devm_kzalloc_obj(mmc_dev(host->mmc), *dlyb); if (!dlyb) return; diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index 5b160fdad3f02d..c9c63675538844 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -3135,9 +3135,7 @@ static int msdc_drv_probe(struct platform_device *pdev) msdc_init_hw(host); if (mmc->caps2 & MMC_CAP2_CQE) { - host->cq_host = devm_kzalloc(mmc->parent, - sizeof(*host->cq_host), - GFP_KERNEL); + host->cq_host = devm_kzalloc_obj(mmc->parent, *host->cq_host); if (!host->cq_host) { ret = -ENOMEM; goto release; @@ -3156,7 +3154,7 @@ static int msdc_drv_probe(struct platform_device *pdev) msdc_cqe_cit_cal(host, 2350); } else if (mmc->caps2 & MMC_CAP2_NO_SDIO) { /* Use HSQ on eMMC/SD (but not on SDIO) if HW CQE not supported */ - struct mmc_hsq *hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq), GFP_KERNEL); + struct mmc_hsq *hsq = devm_kzalloc_obj(&pdev->dev, *hsq); if (!hsq) { ret = -ENOMEM; goto release; diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 527b89a5ed7070..36df578298c373 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c @@ -214,7 +214,7 @@ static void mmc_omap_select_slot(struct mmc_omap_slot *slot, int claimed) host->mmc = slot->mmc; spin_unlock_irqrestore(&host->slot_lock, flags); no_claim: - timer_delete(&host->clk_timer); + timer_delete_sync(&host->clk_timer); if (host->current_slot != slot || !claimed) mmc_omap_fclk_offdelay(host->current_slot); @@ -273,7 +273,7 @@ static void mmc_omap_release_slot(struct mmc_omap_slot *slot, int clk_enabled) /* Keeps clock running for at least 8 cycles on valid freq */ mod_timer(&host->clk_timer, jiffies + HZ/10); else { - timer_delete(&host->clk_timer); + timer_delete_sync(&host->clk_timer); mmc_omap_fclk_offdelay(slot); mmc_omap_fclk_enable(host, 0); } @@ -1383,8 +1383,7 @@ static int mmc_omap_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - host = devm_kzalloc(&pdev->dev, sizeof(struct mmc_omap_host), - GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, struct mmc_omap_host); if (host == NULL) return -ENOMEM; diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index de5a3b70107d85..020d49628c4ad7 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -1726,7 +1726,7 @@ static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev) struct omap_hsmmc_platform_data *pdata, *legacy; struct device_node *np = dev->of_node; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); /* out of memory */ diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index f9ec78d699f458..cb35360239bfba 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -1074,8 +1074,7 @@ int renesas_sdhi_probe(struct platform_device *pdev, if (!res) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(struct renesas_sdhi), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct renesas_sdhi); if (!priv) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c index 1de2f05fd9587a..db857f2273e280 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -451,8 +451,7 @@ static int sdhci_brcmstb_add_host(struct sdhci_host *host, if (ret) return ret; - cq_host = devm_kzalloc(mmc_dev(host->mmc), - sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(mmc_dev(host->mmc), *cq_host); if (!cq_host) { ret = -ENOMEM; goto cleanup; @@ -491,6 +490,7 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) struct sdhci_brcmstb_priv *priv; u32 actual_clock_mhz; struct sdhci_host *host; + struct resource *boot_res; struct clk *clk; struct clk *base_clk = NULL; int res; @@ -534,9 +534,13 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) /* map non-standard BOOT registers if present */ if (host->mmc->caps & MMC_CAP_NONREMOVABLE) { - priv->boot_regs = devm_platform_get_and_ioremap_resource(pdev, 2, NULL); - if (IS_ERR(priv->boot_regs)) - priv->boot_regs = NULL; + boot_res = platform_get_resource(pdev, IORESOURCE_MEM, 2); + if (boot_res) { + priv->boot_regs = devm_ioremap_resource(&pdev->dev, + boot_res); + if (IS_ERR(priv->boot_regs)) + priv->boot_regs = NULL; + } } /* diff --git a/drivers/mmc/host/sdhci-cadence-core.c b/drivers/mmc/host/sdhci-cadence-core.c index 745455743b01ef..16dc64a21dbb0c 100644 --- a/drivers/mmc/host/sdhci-cadence-core.c +++ b/drivers/mmc/host/sdhci-cadence-core.c @@ -650,7 +650,7 @@ static int sdhci_cdns4_phy_probe(struct platform_device *pdev, struct sdhci_cdns unsigned int nr_phy_params; nr_phy_params = sdhci_cdns4_phy_param_count(dev->of_node); - phy = devm_kzalloc(dev, struct_size(phy, phy_params, nr_phy_params), GFP_KERNEL); + phy = devm_kzalloc_flex(dev, *phy, phy_params, nr_phy_params); if (!phy) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-cadence-phy-v6.c b/drivers/mmc/host/sdhci-cadence-phy-v6.c index 22d56bb46d75a2..8a27d16ac1d438 100644 --- a/drivers/mmc/host/sdhci-cadence-phy-v6.c +++ b/drivers/mmc/host/sdhci-cadence-phy-v6.c @@ -865,7 +865,7 @@ int sdhci_cdns6_phy_probe(struct platform_device *pdev, struct sdhci_cdns_priv * unsigned long val; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 6ab59d3e346f98..e972de42b44474 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c @@ -1142,6 +1142,20 @@ static void esdhc_reset_tuning(struct sdhci_host *host) } } +static void sdhci_esdhc_imx_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +{ + /* + * This controller has no driver-type control: esdhc_writew_le() + * discards the driver-type field when writing SDHCI_HOST_CONTROL2. + * The programmed value is therefore irrelevant, but SDHCI rejects + * non-SD values such as 4 (eMMC 40 ohm, from fixed-emmc-driver-type). + * Force an always-valid Type B. + */ + ios->drv_type = MMC_SET_DRIVER_TYPE_B; + + sdhci_set_ios(mmc, ios); +} + static void usdhc_init_card(struct mmc_host *mmc, struct mmc_card *card) { struct sdhci_host *host = mmc_priv(mmc); @@ -1952,6 +1966,9 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) host->max_timeout_count = 0xF; } + /* No SDHCI driver type control */ + host->mmc_host_ops.set_ios = sdhci_esdhc_imx_set_ios; + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) sdhci_esdhc_ops.platform_execute_tuning = esdhc_executing_tuning; @@ -1973,7 +1990,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) if (imx_data->socdata->flags & ESDHC_FLAG_CQHCI) { host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; - cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(&pdev->dev, *cq_host); if (!cq_host) { err = -ENOMEM; goto disable_ahb_clk; diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c index 0ee22923ad5681..a0e62d034adbc0 100644 --- a/drivers/mmc/host/sdhci-of-arasan.c +++ b/drivers/mmc/host/sdhci-of-arasan.c @@ -1811,8 +1811,7 @@ static int sdhci_arasan_add_host(struct sdhci_arasan_data *sdhci_arasan) if (ret) return ret; - cq_host = devm_kzalloc(host->mmc->parent, - sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(host->mmc->parent, *cq_host); if (!cq_host) { ret = -ENOMEM; goto cleanup; diff --git a/drivers/mmc/host/sdhci-of-aspeed.c b/drivers/mmc/host/sdhci-of-aspeed.c index d317626feb4aa6..ad03469eeba4bb 100644 --- a/drivers/mmc/host/sdhci-of-aspeed.c +++ b/drivers/mmc/host/sdhci-of-aspeed.c @@ -525,7 +525,7 @@ static int aspeed_sdc_probe(struct platform_device *pdev) struct aspeed_sdc *sdc; int ret; - sdc = devm_kzalloc(&pdev->dev, sizeof(*sdc), GFP_KERNEL); + sdc = devm_kzalloc_obj(&pdev->dev, *sdc); if (!sdc) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index 09702022e70876..636f6af793e4ba 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -926,7 +926,7 @@ static int dwcmshc_rk35xx_init(struct device *dev, struct sdhci_host *host, struct rk35xx_priv *priv; int err; - priv = devm_kzalloc(dev, sizeof(struct rk35xx_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct rk35xx_priv); if (!priv) return -ENOMEM; @@ -1783,7 +1783,7 @@ static int eic7700_init(struct device *dev, struct sdhci_host *host, struct dwcm struct regmap *hsp_regmap; int ret; - priv = devm_kzalloc(dev, sizeof(struct eic7700_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct eic7700_priv); if (!priv) return -ENOMEM; @@ -1967,7 +1967,7 @@ static int dwcmshc_k230_init(struct device *dev, struct sdhci_host *host, u32 data; int ret; - k230_priv = devm_kzalloc(dev, sizeof(struct k230_priv), GFP_KERNEL); + k230_priv = devm_kzalloc_obj(dev, struct k230_priv); if (!k230_priv) return -ENOMEM; @@ -2288,7 +2288,7 @@ static void dwcmshc_cqhci_init(struct sdhci_host *host, struct platform_device * int err; host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; - cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(&pdev->dev, *cq_host); if (!cq_host) { dev_err(mmc_dev(host->mmc), "Unable to setup CQE: not enough memory\n"); goto dsbl_cqe_caps; diff --git a/drivers/mmc/host/sdhci-omap.c b/drivers/mmc/host/sdhci-omap.c index 7a198fb266280c..cc0c9d3998bd3f 100644 --- a/drivers/mmc/host/sdhci-omap.c +++ b/drivers/mmc/host/sdhci-omap.c @@ -1122,10 +1122,8 @@ static int sdhci_omap_config_iodelay_pinctrl_state(struct sdhci_omap_host if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY)) return 0; - pinctrl_state = devm_kcalloc(dev, - MMC_TIMING_MMC_HS200 + 1, - sizeof(*pinctrl_state), - GFP_KERNEL); + pinctrl_state = devm_kzalloc_objs(dev, *pinctrl_state, + MMC_TIMING_MMC_HS200 + 1); if (!pinctrl_state) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index a9000f3bd4199f..920f5a158f1d6e 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -959,7 +959,7 @@ static int glk_emmc_add_host(struct sdhci_pci_slot *slot) if (ret) return ret; - cq_host = devm_kzalloc(dev, sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(dev, *cq_host); if (!cq_host) { ret = -ENOMEM; goto cleanup; @@ -2327,7 +2327,7 @@ static int sdhci_pci_probe(struct pci_dev *pdev, if (ret) return ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c index b55618566d6513..6542b3225c7629 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -1797,7 +1797,7 @@ static int gl9763e_add_host(struct sdhci_pci_slot *slot) if (ret) return ret; - cq_host = devm_kzalloc(dev, sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(dev, *cq_host); if (!cq_host) { ret = -ENOMEM; goto cleanup; diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c index 76346353dc55d2..d7696c44530e3a 100644 --- a/drivers/mmc/host/sdhci-pxav2.c +++ b/drivers/mmc/host/sdhci-pxav2.c @@ -223,7 +223,7 @@ static struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev) u32 bus_width; u32 clk_delay_cycles; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c index f39764ffd4a056..d60f23ac280798 100644 --- a/drivers/mmc/host/sdhci-pxav3.c +++ b/drivers/mmc/host/sdhci-pxav3.c @@ -366,7 +366,7 @@ static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev) struct sdhci_pxa_platdata *pdata; u32 clk_delay_cycles; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index 6bf66aaa86a6df..ca6120adb21ed4 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c @@ -506,7 +506,7 @@ static int sdhci_s3c_probe(struct platform_device *pdev) } sc = sdhci_priv(host); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index 0c8f389fe58471..04985919587275 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -849,7 +849,7 @@ static int sdhci_sprd_probe(struct platform_device *pdev) sprd_host->flags = host->flags; - hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq), GFP_KERNEL); + hsq = devm_kzalloc_obj(&pdev->dev, *hsq); if (!hsq) { ret = -ENOMEM; goto err_cleanup_host; diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index 5c5efb62d7ecce..ae498247ac6662 100644 --- a/drivers/mmc/host/sdhci-tegra.c +++ b/drivers/mmc/host/sdhci-tegra.c @@ -1634,8 +1634,7 @@ static int sdhci_tegra_add_host(struct sdhci_host *host) host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; - cq_host = devm_kzalloc(mmc_dev(host->mmc), - sizeof(*cq_host), GFP_KERNEL); + cq_host = devm_kzalloc_obj(mmc_dev(host->mmc), *cq_host); if (!cq_host) { ret = -ENOMEM; goto cleanup; diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c index cc9d28b75eb911..624ea8d668dea1 100644 --- a/drivers/mmc/host/sdhci-xenon-phy.c +++ b/drivers/mmc/host/sdhci-xenon-phy.c @@ -206,7 +206,7 @@ static int xenon_alloc_emmc_phy(struct sdhci_host *host) struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host); struct xenon_emmc_phy_params *params; - params = devm_kzalloc(mmc_dev(host->mmc), sizeof(*params), GFP_KERNEL); + params = devm_kzalloc_obj(mmc_dev(host->mmc), *params); if (!params) return -ENOMEM; diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c index 2e332f52c3017d..abe6ff7d1e5a48 100644 --- a/drivers/mmc/host/sdhci_am654.c +++ b/drivers/mmc/host/sdhci_am654.c @@ -718,8 +718,7 @@ static int sdhci_am654_cqe_add_host(struct sdhci_host *host) { struct cqhci_host *cq_host; - cq_host = devm_kzalloc(mmc_dev(host->mmc), sizeof(struct cqhci_host), - GFP_KERNEL); + cq_host = devm_kzalloc_obj(mmc_dev(host->mmc), struct cqhci_host); if (!cq_host) return -ENOMEM; diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c index fe4c0f6d73f3ce..437fdadb5950a1 100644 --- a/drivers/mmc/host/sunxi-mmc.c +++ b/drivers/mmc/host/sunxi-mmc.c @@ -1354,8 +1354,13 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host, goto error_disable_mmc; } - return devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, - sunxi_mmc_handle_manual_stop, 0, "sunxi-mmc", host); + ret = devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, + sunxi_mmc_handle_manual_stop, 0, + "sunxi-mmc", host); + if (ret) + goto error_disable_mmc; + + return 0; error_disable_mmc: sunxi_mmc_disable(host); @@ -1385,9 +1390,11 @@ static int sunxi_mmc_probe(struct platform_device *pdev) host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL); - if (!host->sg_cpu) - return dev_err_probe(&pdev->dev, -ENOMEM, - "Failed to allocate DMA descriptor mem\n"); + if (!host->sg_cpu) { + ret = dev_err_probe(&pdev->dev, -ENOMEM, + "Failed to allocate DMA descriptor mem\n"); + goto error_disable_mmc; + } if (host->cfg->ccu_has_timings_switch) { /* @@ -1467,7 +1474,7 @@ static int sunxi_mmc_probe(struct platform_device *pdev) ret = mmc_add_host(mmc); if (ret) - goto error_free_dma; + goto error_disable_rpm; dev_info(&pdev->dev, "initialized, max. request size: %u KB%s\n", mmc->max_req_size >> 10, @@ -1475,8 +1482,13 @@ static int sunxi_mmc_probe(struct platform_device *pdev) return 0; +error_disable_rpm: + pm_runtime_disable(&pdev->dev); error_free_dma: dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); +error_disable_mmc: + disable_irq(host->irq); + sunxi_mmc_disable(host); return ret; } diff --git a/drivers/mmc/host/uniphier-sd.c b/drivers/mmc/host/uniphier-sd.c index 1eae2f4b6c1f92..0d25c6e2f9d2eb 100644 --- a/drivers/mmc/host/uniphier-sd.c +++ b/drivers/mmc/host/uniphier-sd.c @@ -624,7 +624,7 @@ static int uniphier_sd_probe(struct platform_device *pdev) if (irq < 0) return irq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c index 2edc4674177451..090587be90fd43 100644 --- a/drivers/mtd/devices/bcm47xxsflash.c +++ b/drivers/mtd/devices/bcm47xxsflash.c @@ -290,7 +290,7 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) struct resource *res; int err; - b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL); + b47s = devm_kzalloc_obj(dev, *b47s); if (!b47s) return -ENOMEM; diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 3d89f810e2db2f..a8a77de1c6f001 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1980,8 +1980,7 @@ static int __init docg3_probe(struct platform_device *pdev) return PTR_ERR(base); ret = -ENOMEM; - cascade = devm_kcalloc(dev, DOC_MAX_NBFLOORS, sizeof(*cascade), - GFP_KERNEL); + cascade = devm_kzalloc_objs(dev, *cascade, DOC_MAX_NBFLOORS); if (!cascade) return ret; cascade->base = base; diff --git a/drivers/mtd/devices/mchp23k256.c b/drivers/mtd/devices/mchp23k256.c index 66e058df4c328b..05a4ebe21e4bf0 100644 --- a/drivers/mtd/devices/mchp23k256.c +++ b/drivers/mtd/devices/mchp23k256.c @@ -174,7 +174,7 @@ static int mchp23k256_probe(struct spi_device *spi) struct flash_platform_data *data; int err; - flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&spi->dev, *flash); if (!flash) return -ENOMEM; diff --git a/drivers/mtd/devices/mchp48l640.c b/drivers/mtd/devices/mchp48l640.c index 4af9208f96906c..c6e83775638d87 100644 --- a/drivers/mtd/devices/mchp48l640.c +++ b/drivers/mtd/devices/mchp48l640.c @@ -317,7 +317,7 @@ static int mchp48l640_probe(struct spi_device *spi) int err; int status; - flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&spi->dev, *flash); if (!flash) return -ENOMEM; diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c index fe1d6684d0bd40..4bd7b41a03b7e7 100644 --- a/drivers/mtd/devices/powernv_flash.c +++ b/drivers/mtd/devices/powernv_flash.c @@ -236,7 +236,7 @@ static int powernv_flash_probe(struct platform_device *pdev) struct powernv_flash *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c index f02f96bff45099..dc66ed852d800b 100644 --- a/drivers/mtd/devices/spear_smi.c +++ b/drivers/mtd/devices/spear_smi.c @@ -805,9 +805,8 @@ static int spear_smi_probe_config_dt(struct platform_device *pdev, of_property_read_u32(np, "clock-rate", &val); pdata->clk_rate = val; - pdata->board_flash_info = devm_kzalloc(&pdev->dev, - sizeof(*pdata->board_flash_info), - GFP_KERNEL); + pdata->board_flash_info = devm_kzalloc_obj(&pdev->dev, + *pdata->board_flash_info); if (!pdata->board_flash_info) return -ENOMEM; @@ -858,7 +857,7 @@ static int spear_smi_setup_banks(struct platform_device *pdev, if (!flash_info) return -ENODEV; - flash = devm_kzalloc(&pdev->dev, sizeof(*flash), GFP_ATOMIC); + flash = devm_kzalloc_obj(&pdev->dev, *flash, GFP_ATOMIC); if (!flash) return -ENOMEM; flash->bank = bank; @@ -941,7 +940,7 @@ static int spear_smi_probe(struct platform_device *pdev) int i; if (np) { - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) { ret = -ENOMEM; goto err; @@ -968,7 +967,7 @@ static int spear_smi_probe(struct platform_device *pdev) goto err; } - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) { ret = -ENOMEM; goto err; diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c index 8813994ce9f453..b4ba92e1979d20 100644 --- a/drivers/mtd/devices/sst25l.c +++ b/drivers/mtd/devices/sst25l.c @@ -356,7 +356,7 @@ static int sst25l_probe(struct spi_device *spi) if (!flash_info) return -ENODEV; - flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); + flash = devm_kzalloc_obj(&spi->dev, *flash); if (!flash) return -ENOMEM; diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index f2266145b82167..94872e03a04dda 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -2024,7 +2024,7 @@ static int stfsm_probe(struct platform_device *pdev) return -EINVAL; } - fsm = devm_kzalloc(&pdev->dev, sizeof(*fsm), GFP_KERNEL); + fsm = devm_kzalloc_obj(&pdev->dev, *fsm); if (!fsm) return -ENOMEM; diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index fc9185d44d925f..bb0b6ffb4c43e3 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -267,8 +267,7 @@ static int build_maps(partition_t *part) memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t)); part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize; - part->bam_cache = kmalloc_array(part->BlocksPerUnit, sizeof(uint32_t), - GFP_KERNEL); + part->bam_cache = kmalloc_objs(uint32_t, part->BlocksPerUnit); if (!part->bam_cache) goto out_VirtualBlockMap; diff --git a/drivers/mtd/hyperbus/hbmc-am654.c b/drivers/mtd/hyperbus/hbmc-am654.c index 8a14e908d0b539..acbcc3b55d867a 100644 --- a/drivers/mtd/hyperbus/hbmc-am654.c +++ b/drivers/mtd/hyperbus/hbmc-am654.c @@ -166,7 +166,7 @@ static int am654_hbmc_probe(struct platform_device *pdev) struct resource res; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -204,7 +204,7 @@ static int am654_hbmc_probe(struct platform_device *pdev) priv->ctlr.ops = &am654_hbmc_ops; priv->hbdev.ctlr = &priv->ctlr; - dev_priv = devm_kzalloc(dev, sizeof(*dev_priv), GFP_KERNEL); + dev_priv = devm_kzalloc_obj(dev, *dev_priv); if (!dev_priv) { ret = -ENOMEM; goto disable_mux; diff --git a/drivers/mtd/hyperbus/rpc-if.c b/drivers/mtd/hyperbus/rpc-if.c index f448e23f9260f1..9eacc9ec7382d5 100644 --- a/drivers/mtd/hyperbus/rpc-if.c +++ b/drivers/mtd/hyperbus/rpc-if.c @@ -120,7 +120,7 @@ static int rpcif_hb_probe(struct platform_device *pdev) struct rpcif_hyperbus *hyperbus; int error; - hyperbus = devm_kzalloc(dev, sizeof(*hyperbus), GFP_KERNEL); + hyperbus = devm_kzalloc_obj(dev, *hyperbus); if (!hyperbus) return -ENOMEM; diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c index 565b71f7fdd5bf..7aac62b633adce 100644 --- a/drivers/mtd/lpddr/lpddr2_nvm.c +++ b/drivers/mtd/lpddr/lpddr2_nvm.c @@ -415,18 +415,18 @@ static int lpddr2_nvm_probe(struct platform_device *pdev) struct pcm_int_data *pcm_data; /* Allocate memory control_regs data structures */ - pcm_data = devm_kzalloc(&pdev->dev, sizeof(*pcm_data), GFP_KERNEL); + pcm_data = devm_kzalloc_obj(&pdev->dev, *pcm_data); if (!pcm_data) return -ENOMEM; pcm_data->bus_width = BUS_WIDTH; /* Allocate memory for map_info & mtd_info data structures */ - map = devm_kzalloc(&pdev->dev, sizeof(*map), GFP_KERNEL); + map = devm_kzalloc_obj(&pdev->dev, *map); if (!map) return -ENOMEM; - mtd = devm_kzalloc(&pdev->dev, sizeof(*mtd), GFP_KERNEL); + mtd = devm_kzalloc_obj(&pdev->dev, *mtd); if (!mtd) return -ENOMEM; diff --git a/drivers/mtd/maps/int0800.c b/drivers/mtd/maps/int0800.c index c5f108aa347974..1f5a7c4936ddab 100644 --- a/drivers/mtd/maps/int0800.c +++ b/drivers/mtd/maps/int0800.c @@ -37,7 +37,7 @@ static int int0800_probe(struct platform_device *pdev) resource_size_t end; int ret; - fw = devm_kzalloc(&pdev->dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(&pdev->dev, *fw); if (!fw) return -ENOMEM; diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c index 80d467eba92a36..519126abb9a5c0 100644 --- a/drivers/mtd/maps/lantiq-flash.c +++ b/drivers/mtd/maps/lantiq-flash.c @@ -112,7 +112,7 @@ ltq_mtd_probe(struct platform_device *pdev) struct cfi_private *cfi; int err; - ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL); + ltq_mtd = devm_kzalloc_obj(&pdev->dev, struct ltq_mtd); if (!ltq_mtd) return -ENOMEM; @@ -122,8 +122,7 @@ ltq_mtd_probe(struct platform_device *pdev) if (IS_ERR(ltq_mtd->map->virt)) return PTR_ERR(ltq_mtd->map->virt); - ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info), - GFP_KERNEL); + ltq_mtd->map = devm_kzalloc_obj(&pdev->dev, struct map_info); if (!ltq_mtd->map) return -ENOMEM; diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-core.c index dcda7685fc99b5..4c57b7b7502211 100644 --- a/drivers/mtd/maps/physmap-core.c +++ b/drivers/mtd/maps/physmap-core.c @@ -280,7 +280,7 @@ static const char * const *of_get_part_probes(struct platform_device *dev) if (count < 0) return of_default_part_probes; - res = devm_kcalloc(&dev->dev, count + 1, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_objs(&dev->dev, *res, count + 1); if (!res) return NULL; @@ -447,7 +447,7 @@ static int physmap_flash_probe(struct platform_device *dev) if (!dev->dev.of_node && !dev_get_platdata(&dev->dev)) return -EINVAL; - info = devm_kzalloc(&dev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/mtd/maps/physmap-gemini.c b/drivers/mtd/maps/physmap-gemini.c index 1c34b4ef77ea3f..ae9e24eb3db025 100644 --- a/drivers/mtd/maps/physmap-gemini.c +++ b/drivers/mtd/maps/physmap-gemini.c @@ -130,7 +130,7 @@ int of_flash_probe_gemini(struct platform_device *pdev, if (!of_device_is_compatible(np, "cortina,gemini-flash")) return 0; - gf = devm_kzalloc(dev, sizeof(*gf), GFP_KERNEL); + gf = devm_kzalloc_obj(dev, *gf); if (!gf) return -ENOMEM; gf->dev = dev; diff --git a/drivers/mtd/nand/ecc-mtk.c b/drivers/mtd/nand/ecc-mtk.c index 66f0985ef7cdb6..a3a285170fcd01 100644 --- a/drivers/mtd/nand/ecc-mtk.c +++ b/drivers/mtd/nand/ecc-mtk.c @@ -540,7 +540,7 @@ static int mtk_ecc_probe(struct platform_device *pdev) u32 max_eccdata_size; int irq, ret; - ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL); + ecc = devm_kzalloc_obj(dev, *ecc); if (!ecc) return -ENOMEM; diff --git a/drivers/mtd/nand/ecc-mxic.c b/drivers/mtd/nand/ecc-mxic.c index 60cdcb4175efb5..41ee4941979830 100644 --- a/drivers/mtd/nand/ecc-mxic.c +++ b/drivers/mtd/nand/ecc-mxic.c @@ -230,7 +230,7 @@ static int mxic_ecc_init_ctx(struct nand_device *nand, struct device *dev) u32 spare_reg; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -799,7 +799,7 @@ static int mxic_ecc_probe(struct platform_device *pdev) struct mxic_ecc_engine *mxic; int ret; - mxic = devm_kzalloc(&pdev->dev, sizeof(*mxic), GFP_KERNEL); + mxic = devm_kzalloc_obj(&pdev->dev, *mxic); if (!mxic) return -ENOMEM; diff --git a/drivers/mtd/nand/ecc-realtek.c b/drivers/mtd/nand/ecc-realtek.c index 76d75e2107df49..fb573c7f228091 100644 --- a/drivers/mtd/nand/ecc-realtek.c +++ b/drivers/mtd/nand/ecc-realtek.c @@ -345,7 +345,7 @@ static int rtl_ecc_init_ctx(struct nand_device *nand) if (ret) return ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -396,7 +396,7 @@ static int rtl_ecc_probe(struct platform_device *pdev) void __iomem *base; int ret; - rtlc = devm_kzalloc(dev, sizeof(*rtlc), GFP_KERNEL); + rtlc = devm_kzalloc_obj(dev, *rtlc); if (!rtlc) return -ENOMEM; diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c index 26d5f3f10964e7..9d382d11e9714b 100644 --- a/drivers/mtd/nand/ecc-sw-bch.c +++ b/drivers/mtd/nand/ecc-sw-bch.c @@ -122,8 +122,7 @@ static int nand_ecc_sw_bch_init(struct nand_device *nand) return -EINVAL; engine_conf->eccmask = kzalloc(eccbytes, GFP_KERNEL); - engine_conf->errloc = kmalloc_array(t, sizeof(*engine_conf->errloc), - GFP_KERNEL); + engine_conf->errloc = kmalloc_objs(*engine_conf->errloc, t); if (!engine_conf->eccmask || !engine_conf->errloc) { ret = -ENOMEM; goto cleanup; diff --git a/drivers/mtd/nand/onenand/onenand_omap2.c b/drivers/mtd/nand/onenand/onenand_omap2.c index 644498187d8fad..4c1379343fbd79 100644 --- a/drivers/mtd/nand/onenand/onenand_omap2.c +++ b/drivers/mtd/nand/onenand/onenand_omap2.c @@ -473,7 +473,7 @@ static int omap2_onenand_probe(struct platform_device *pdev) return r; } - c = devm_kzalloc(dev, sizeof(struct omap2_onenand), GFP_KERNEL); + c = devm_kzalloc_obj(dev, struct omap2_onenand); if (!c) return -ENOMEM; diff --git a/drivers/mtd/nand/onenand/onenand_samsung.c b/drivers/mtd/nand/onenand/onenand_samsung.c index b7b7758ce4d860..8c2d3866a6d6d0 100644 --- a/drivers/mtd/nand/onenand/onenand_samsung.c +++ b/drivers/mtd/nand/onenand/onenand_samsung.c @@ -852,8 +852,7 @@ static int s3c_onenand_probe(struct platform_device *pdev) if (!mtd) return -ENOMEM; - onenand = devm_kzalloc(&pdev->dev, sizeof(struct s3c_onenand), - GFP_KERNEL); + onenand = devm_kzalloc_obj(&pdev->dev, struct s3c_onenand); if (!onenand) return -ENOMEM; diff --git a/drivers/mtd/nand/qpic_common.c b/drivers/mtd/nand/qpic_common.c index 91ae970734f80d..e97043b866d2ba 100644 --- a/drivers/mtd/nand/qpic_common.c +++ b/drivers/mtd/nand/qpic_common.c @@ -692,13 +692,13 @@ int qcom_nandc_alloc(struct qcom_nand_controller *nandc) if (!nandc->data_buffer) return -ENOMEM; - nandc->regs = devm_kzalloc(nandc->dev, sizeof(*nandc->regs), GFP_KERNEL); + nandc->regs = devm_kzalloc_obj(nandc->dev, *nandc->regs); if (!nandc->regs) return -ENOMEM; - nandc->reg_read_buf = devm_kcalloc(nandc->dev, MAX_REG_RD, - sizeof(*nandc->reg_read_buf), - GFP_KERNEL); + nandc->reg_read_buf = devm_kzalloc_objs(nandc->dev, + *nandc->reg_read_buf, + MAX_REG_RD); if (!nandc->reg_read_buf) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c index fb2b7db70297fe..d6c3ed0f858cc1 100644 --- a/drivers/mtd/nand/raw/ams-delta.c +++ b/drivers/mtd/nand/raw/ams-delta.c @@ -250,8 +250,7 @@ static int gpio_nand_probe(struct platform_device *pdev) } /* Allocate memory for MTD device structure and private data */ - priv = devm_kzalloc(&pdev->dev, sizeof(struct gpio_nand), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct gpio_nand); if (!priv) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c index 865754737f5fc7..7ff57abf61f709 100644 --- a/drivers/mtd/nand/raw/arasan-nand-controller.c +++ b/drivers/mtd/nand/raw/arasan-nand-controller.c @@ -1173,8 +1173,8 @@ static int anfc_init_hw_ecc_controller(struct arasan_nfc *nfc, ECC_CONF_LEN(anand->ecc_total) | ECC_CONF_BCH_EN; - anand->errloc = devm_kmalloc_array(nfc->dev, ecc->strength, - sizeof(*anand->errloc), GFP_KERNEL); + anand->errloc = devm_kmalloc_objs(nfc->dev, *anand->errloc, + ecc->strength); if (!anand->errloc) return -ENOMEM; @@ -1276,7 +1276,7 @@ static int anfc_chip_init(struct arasan_nfc *nfc, struct device_node *np) struct mtd_info *mtd; int rb, ret, i; - anand = devm_kzalloc(nfc->dev, sizeof(*anand), GFP_KERNEL); + anand = devm_kzalloc_obj(nfc->dev, *anand); if (!anand) return -ENOMEM; @@ -1287,8 +1287,8 @@ static int anfc_chip_init(struct arasan_nfc *nfc, struct device_node *np) return -EINVAL; } - anand->cs_idx = devm_kcalloc(nfc->dev, anand->ncs_idx, - sizeof(*anand->cs_idx), GFP_KERNEL); + anand->cs_idx = devm_kzalloc_objs(nfc->dev, *anand->cs_idx, + anand->ncs_idx); if (!anand->cs_idx) return -ENOMEM; @@ -1436,7 +1436,7 @@ static int anfc_probe(struct platform_device *pdev) struct arasan_nfc *nfc; int ret; - nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(&pdev->dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c index 0bdbcbb50d94c3..24bf934093646a 100644 --- a/drivers/mtd/nand/raw/atmel/nand-controller.c +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c @@ -1649,7 +1649,7 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, return ERR_PTR(-EINVAL); } - nand = devm_kzalloc(nc->dev, struct_size(nand, cs, numcs), GFP_KERNEL); + nand = devm_kzalloc_flex(nc->dev, *nand, cs, numcs); if (!nand) return ERR_PTR(-ENOMEM); @@ -1799,7 +1799,7 @@ atmel_nand_controller_legacy_add_nands(struct atmel_nand_controller *nc) * Legacy bindings only allow connecting a single NAND with a unique CS * line to the controller. */ - nand = devm_kzalloc(nc->dev, struct_size(nand, cs, 1), GFP_KERNEL); + nand = devm_kzalloc_flex(nc->dev, *nand, cs, 1); if (!nand) return -ENOMEM; @@ -2356,7 +2356,7 @@ static int atmel_hsmc_nand_controller_probe(struct platform_device *pdev, struct atmel_hsmc_nand_controller *nc; int ret; - nc = devm_kzalloc(dev, sizeof(*nc), GFP_KERNEL); + nc = devm_kzalloc_obj(dev, *nc); if (!nc) return -ENOMEM; @@ -2433,7 +2433,7 @@ static int atmel_smc_nand_controller_probe(struct platform_device *pdev, struct atmel_smc_nand_controller *nc; int ret; - nc = devm_kzalloc(dev, sizeof(*nc), GFP_KERNEL); + nc = devm_kzalloc_obj(dev, *nc); if (!nc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/atmel/pmecc.c b/drivers/mtd/nand/raw/atmel/pmecc.c index 1d0e93e4edb1d7..37ce23d526b3dc 100644 --- a/drivers/mtd/nand/raw/atmel/pmecc.c +++ b/drivers/mtd/nand/raw/atmel/pmecc.c @@ -828,7 +828,7 @@ static struct atmel_pmecc *atmel_pmecc_create(struct platform_device *pdev, struct device *dev = &pdev->dev; struct atmel_pmecc *pmecc; - pmecc = devm_kzalloc(dev, sizeof(*pmecc), GFP_KERNEL); + pmecc = devm_kzalloc_obj(dev, *pmecc); if (!pmecc) return ERR_PTR(-ENOMEM); diff --git a/drivers/mtd/nand/raw/bcm47xxnflash/main.c b/drivers/mtd/nand/raw/bcm47xxnflash/main.c index 4d4e185c22e560..93c011b8093b9e 100644 --- a/drivers/mtd/nand/raw/bcm47xxnflash/main.c +++ b/drivers/mtd/nand/raw/bcm47xxnflash/main.c @@ -26,7 +26,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev) struct mtd_info *mtd; int err = 0; - b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL); + b47n = devm_kzalloc_obj(&pdev->dev, *b47n); if (!b47n) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c index a06cd87f839a60..51b1125d036b1f 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c @@ -89,7 +89,7 @@ static int bcm6368_nand_probe(struct platform_device *pdev) struct bcm6368_nand_soc *priv; struct brcmnand_soc *soc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; soc = &priv->soc; diff --git a/drivers/mtd/nand/raw/brcmnand/bcma_nand.c b/drivers/mtd/nand/raw/brcmnand/bcma_nand.c index dd27977919fbac..3b5de87ec47edf 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcma_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcma_nand.c @@ -101,7 +101,7 @@ static int brcmnand_bcma_nand_probe(struct platform_device *pdev) struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev); struct brcmnand_bcma_soc *soc; - soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL); + soc = devm_kzalloc_obj(&pdev->dev, *soc); if (!soc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c b/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c index c31d7f37dc5218..674fcda05bb169 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcmbca_nand.c @@ -88,7 +88,7 @@ static int bcmbca_nand_probe(struct platform_device *pdev) struct bcmbca_nand_soc *priv; struct brcmnand_soc *soc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; soc = &priv->soc; diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 4a1f5e736a1cf5..78937498cc026f 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -3307,7 +3307,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc) if (dn && !of_match_node(brcmnand_of_match, dn)) return -ENODEV; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; @@ -3489,7 +3489,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc) for_each_available_child_of_node_scoped(dn, child) { if (of_device_is_compatible(child, "brcm,nandcs")) { - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) { ret = -ENOMEM; goto err; @@ -3528,7 +3528,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc) } /* If we got there we must have been probing via platform data */ - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) { ret = -ENOMEM; goto err; diff --git a/drivers/mtd/nand/raw/brcmnand/iproc_nand.c b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c index 089c70fc6edfc0..f2ef3b7a0943d3 100644 --- a/drivers/mtd/nand/raw/brcmnand/iproc_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c @@ -104,7 +104,7 @@ static int iproc_nand_probe(struct platform_device *pdev) struct iproc_nand_soc *priv; struct brcmnand_soc *soc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; soc = &priv->soc; diff --git a/drivers/mtd/nand/raw/cadence-nand-controller.c b/drivers/mtd/nand/raw/cadence-nand-controller.c index 4f5e6d2b128c74..e19ceb2d5dfc2d 100644 --- a/drivers/mtd/nand/raw/cadence-nand-controller.c +++ b/drivers/mtd/nand/raw/cadence-nand-controller.c @@ -3275,7 +3275,7 @@ static int cadence_nand_dt_probe(struct platform_device *ofdev) return -ENOMEM; } - dt = devm_kzalloc(&ofdev->dev, sizeof(*dt), GFP_KERNEL); + dt = devm_kzalloc_obj(&ofdev->dev, *dt); if (!dt) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/davinci_nand.c b/drivers/mtd/nand/raw/davinci_nand.c index 3986553881d0e5..20aebe101e8d25 100644 --- a/drivers/mtd/nand/raw/davinci_nand.c +++ b/drivers/mtd/nand/raw/davinci_nand.c @@ -542,9 +542,7 @@ nand_davinci_get_pdata(struct platform_device *pdev) const char *mode; u32 prop; - pdata = devm_kzalloc(&pdev->dev, - sizeof(struct davinci_nand_pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, struct davinci_nand_pdata); pdev->dev.platform_data = pdata; if (!pdata) return ERR_PTR(-ENOMEM); @@ -919,7 +917,7 @@ static int nand_davinci_probe(struct platform_device *pdev) if (pdata->core_chipsel > 3) return -ENODEV; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/denali_dt.c b/drivers/mtd/nand/raw/denali_dt.c index 8c822eae72e78d..01733238dac930 100644 --- a/drivers/mtd/nand/raw/denali_dt.c +++ b/drivers/mtd/nand/raw/denali_dt.c @@ -89,8 +89,7 @@ static int denali_dt_chip_init(struct denali_controller *denali, if (nsels < 0) return nsels; - dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels), - GFP_KERNEL); + dchip = devm_kzalloc_flex(denali->dev, *dchip, sels, nsels); if (!dchip) return -ENOMEM; @@ -117,7 +116,7 @@ static int denali_dt_probe(struct platform_device *pdev) struct denali_controller *denali; int ret; - dt = devm_kzalloc(dev, sizeof(*dt), GFP_KERNEL); + dt = devm_kzalloc_obj(dev, *dt); if (!dt) return -ENOMEM; denali = &dt->controller; diff --git a/drivers/mtd/nand/raw/denali_pci.c b/drivers/mtd/nand/raw/denali_pci.c index f53df1b32ddab9..0e4c7e4a4b32e5 100644 --- a/drivers/mtd/nand/raw/denali_pci.c +++ b/drivers/mtd/nand/raw/denali_pci.c @@ -35,7 +35,7 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) struct denali_chip *dchip; int nsels, ret, i; - denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL); + denali = devm_kzalloc_obj(&dev->dev, *denali); if (!denali) return -ENOMEM; @@ -92,8 +92,7 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) nsels = denali->nbanks; - dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels), - GFP_KERNEL); + dchip = devm_kzalloc_flex(denali->dev, *dchip, sels, nsels); if (!dchip) { ret = -ENOMEM; goto out_remove_denali; diff --git a/drivers/mtd/nand/raw/fsl_ifc_nand.c b/drivers/mtd/nand/raw/fsl_ifc_nand.c index cc75b6a67e07f0..d5d0c7c7bfba87 100644 --- a/drivers/mtd/nand/raw/fsl_ifc_nand.c +++ b/drivers/mtd/nand/raw/fsl_ifc_nand.c @@ -1016,14 +1016,14 @@ static int fsl_ifc_nand_probe(struct platform_device *dev) return -ENODEV; } - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; mutex_lock(&fsl_ifc_nand_mutex); if (!fsl_ifc_ctrl_dev->nand) { - ifc_nand_ctrl = devm_kzalloc(fsl_ifc_ctrl_dev->dev, sizeof(*ifc_nand_ctrl), - GFP_KERNEL); + ifc_nand_ctrl = devm_kzalloc_obj(fsl_ifc_ctrl_dev->dev, + *ifc_nand_ctrl); if (!ifc_nand_ctrl) { mutex_unlock(&fsl_ifc_nand_mutex); return -ENOMEM; diff --git a/drivers/mtd/nand/raw/fsl_upm.c b/drivers/mtd/nand/raw/fsl_upm.c index f4dc990a8da16a..8896720be5050c 100644 --- a/drivers/mtd/nand/raw/fsl_upm.c +++ b/drivers/mtd/nand/raw/fsl_upm.c @@ -169,7 +169,7 @@ static int fun_probe(struct platform_device *ofdev) int size; int i; - fun = devm_kzalloc(&ofdev->dev, sizeof(*fun), GFP_KERNEL); + fun = devm_kzalloc_obj(&ofdev->dev, *fun); if (!fun) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/fsmc_nand.c b/drivers/mtd/nand/raw/fsmc_nand.c index 837c23c63aeb23..eee00c6f43e07b 100644 --- a/drivers/mtd/nand/raw/fsmc_nand.c +++ b/drivers/mtd/nand/raw/fsmc_nand.c @@ -889,9 +889,7 @@ static int fsmc_nand_probe_config_dt(struct platform_device *pdev, if (of_property_read_bool(np, "nand-skip-bbtscan")) nand->options |= NAND_SKIP_BBTSCAN; - host->dev_timings = devm_kzalloc(&pdev->dev, - sizeof(*host->dev_timings), - GFP_KERNEL); + host->dev_timings = devm_kzalloc_obj(&pdev->dev, *host->dev_timings); if (!host->dev_timings) return -ENOMEM; @@ -1037,7 +1035,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) int i; /* Allocate memory for the device structure (and zero it) */ - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/gpio.c b/drivers/mtd/nand/raw/gpio.c index 69e5e43532a448..63853d7a8104ac 100644 --- a/drivers/mtd/nand/raw/gpio.c +++ b/drivers/mtd/nand/raw/gpio.c @@ -214,7 +214,7 @@ static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev) "gpio-control-nand,io-sync-reg", &addr)) return NULL; - r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL); + r = devm_kzalloc_obj(&pdev->dev, *r); if (!r) return NULL; @@ -294,7 +294,7 @@ static int gpio_nand_probe(struct platform_device *pdev) if (!dev->of_node && !dev_get_platdata(dev)) return -EINVAL; - gpiomtd = devm_kzalloc(dev, sizeof(*gpiomtd), GFP_KERNEL); + gpiomtd = devm_kzalloc_obj(dev, *gpiomtd); if (!gpiomtd) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index 0f1528710a6a17..019df54c4bb053 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -2787,7 +2787,7 @@ static int gpmi_nand_probe(struct platform_device *pdev) struct gpmi_nand_data *this; int ret; - this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL); + this = devm_kzalloc_obj(&pdev->dev, *this); if (!this) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/hisi504_nand.c b/drivers/mtd/nand/raw/hisi504_nand.c index d97270ec118550..c5063d681476d9 100644 --- a/drivers/mtd/nand/raw/hisi504_nand.c +++ b/drivers/mtd/nand/raw/hisi504_nand.c @@ -740,7 +740,7 @@ static int hisi_nfc_probe(struct platform_device *pdev) struct mtd_info *mtd; struct device_node *np = dev->of_node; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; host->dev = dev; diff --git a/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c b/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c index beb033705cf3e7..88e5861a7b1f5b 100644 --- a/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c +++ b/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c @@ -134,7 +134,7 @@ int ingenic_ecc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct ingenic_ecc *ecc; - ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL); + ecc = devm_kzalloc_obj(dev, *ecc); if (!ecc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c b/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c index f1e2c82936b389..631db0e93a366a 100644 --- a/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +++ b/drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c @@ -368,7 +368,7 @@ static int ingenic_nand_init_chip(struct platform_device *pdev, if (IS_ERR(cs->base)) return PTR_ERR(cs->base); - nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL); + nand = devm_kzalloc_obj(dev, *nand); if (!nand) return -ENOMEM; @@ -474,7 +474,7 @@ static int ingenic_nand_probe(struct platform_device *pdev) return -ENODEV; } - nfc = devm_kzalloc(dev, struct_size(nfc, cs, num_banks), GFP_KERNEL); + nfc = devm_kzalloc_flex(dev, *nfc, cs, num_banks); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c index 94d2161bf5a1aa..cfb4b231e06727 100644 --- a/drivers/mtd/nand/raw/intel-nand-controller.c +++ b/drivers/mtd/nand/raw/intel-nand-controller.c @@ -587,7 +587,7 @@ static int ebu_nand_probe(struct platform_device *pdev) int ret; u32 cs; - ebu_host = devm_kzalloc(dev, sizeof(*ebu_host), GFP_KERNEL); + ebu_host = devm_kzalloc_obj(dev, *ebu_host); if (!ebu_host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/loongson-nand-controller.c b/drivers/mtd/nand/raw/loongson-nand-controller.c index 935f66602de97c..320d009ebf8c51 100644 --- a/drivers/mtd/nand/raw/loongson-nand-controller.c +++ b/drivers/mtd/nand/raw/loongson-nand-controller.c @@ -890,7 +890,7 @@ static int loongson_nand_probe(struct platform_device *pdev) if (!data) return -ENODEV; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/lpc32xx_mlc.c b/drivers/mtd/nand/raw/lpc32xx_mlc.c index d03486dc411502..a54c14134f75ff 100644 --- a/drivers/mtd/nand/raw/lpc32xx_mlc.c +++ b/drivers/mtd/nand/raw/lpc32xx_mlc.c @@ -613,7 +613,7 @@ static struct lpc32xx_nand_cfg_mlc *lpc32xx_parse_dt(struct device *dev) struct lpc32xx_nand_cfg_mlc *ncfg; struct device_node *np = dev->of_node; - ncfg = devm_kzalloc(dev, sizeof(*ncfg), GFP_KERNEL); + ncfg = devm_kzalloc_obj(dev, *ncfg); if (!ncfg) return NULL; @@ -685,7 +685,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) int res; /* Allocate memory for the device structure (and zero it) */ - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/lpc32xx_slc.c b/drivers/mtd/nand/raw/lpc32xx_slc.c index 638267d44360d4..9c5412dd3891f0 100644 --- a/drivers/mtd/nand/raw/lpc32xx_slc.c +++ b/drivers/mtd/nand/raw/lpc32xx_slc.c @@ -738,7 +738,7 @@ static struct lpc32xx_nand_cfg_slc *lpc32xx_parse_dt(struct device *dev) struct lpc32xx_nand_cfg_slc *ncfg; struct device_node *np = dev->of_node; - ncfg = devm_kzalloc(dev, sizeof(*ncfg), GFP_KERNEL); + ncfg = devm_kzalloc_obj(dev, *ncfg); if (!ncfg) return NULL; @@ -827,7 +827,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) int res; /* Allocate memory for the device structure (and zero it) */ - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c index e5fa5540e80a04..32035c8d43b88d 100644 --- a/drivers/mtd/nand/raw/marvell_nand.c +++ b/drivers/mtd/nand/raw/marvell_nand.c @@ -2631,9 +2631,7 @@ static int marvell_nand_chip_init(struct device *dev, struct marvell_nfc *nfc, } /* Alloc the nand chip structure */ - marvell_nand = devm_kzalloc(dev, - struct_size(marvell_nand, sels, nsels), - GFP_KERNEL); + marvell_nand = devm_kzalloc_flex(dev, *marvell_nand, sels, nsels); if (!marvell_nand) { dev_err(dev, "could not allocate chip structure\n"); return -ENOMEM; @@ -2940,8 +2938,7 @@ static int marvell_nfc_probe(struct platform_device *pdev) int ret; int irq; - nfc = devm_kzalloc(&pdev->dev, sizeof(struct marvell_nfc), - GFP_KERNEL); + nfc = devm_kzalloc_obj(&pdev->dev, struct marvell_nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index b8834aa96e81c4..b2a9d4043019d8 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -1398,8 +1398,7 @@ meson_nfc_nand_chip_init(struct device *dev, return -EINVAL; } - meson_chip = devm_kzalloc(dev, struct_size(meson_chip, sels, nsels), - GFP_KERNEL); + meson_chip = devm_kzalloc_flex(dev, *meson_chip, sels, nsels); if (!meson_chip) return -ENOMEM; @@ -1550,7 +1549,7 @@ static int meson_nfc_probe(struct platform_device *pdev) struct meson_nfc *nfc; int ret, irq; - nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/mpc5121_nfc.c b/drivers/mtd/nand/raw/mpc5121_nfc.c index e6594548b7e037..75a97f735ee37b 100644 --- a/drivers/mtd/nand/raw/mpc5121_nfc.c +++ b/drivers/mtd/nand/raw/mpc5121_nfc.c @@ -644,7 +644,7 @@ static int mpc5121_nfc_probe(struct platform_device *op) if (irq < 0) return irq; - prv = devm_kzalloc(dev, sizeof(*prv), GFP_KERNEL); + prv = devm_kzalloc_obj(dev, *prv); if (!prv) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index c439b7814ebb37..8f943b53b01608 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -1356,8 +1356,7 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, return -EINVAL; } - chip = devm_kzalloc(dev, struct_size(chip, sels, nsels), - GFP_KERNEL); + chip = devm_kzalloc_flex(dev, *chip, sels, nsels); if (!chip) return -ENOMEM; @@ -1511,7 +1510,7 @@ static int mtk_nfc_probe(struct platform_device *pdev) struct mtk_nfc *nfc; int ret, irq; - nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/mxc_nand.c b/drivers/mtd/nand/raw/mxc_nand.c index 4d8b92e7e67257..52fe64f4355ac5 100644 --- a/drivers/mtd/nand/raw/mxc_nand.c +++ b/drivers/mtd/nand/raw/mxc_nand.c @@ -1694,8 +1694,7 @@ static int mxcnd_probe(struct platform_device *pdev) int err = 0; /* Allocate memory for MTD device structure and private data */ - host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host), - GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, struct mxc_nand_host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/mxic_nand.c b/drivers/mtd/nand/raw/mxic_nand.c index 92de26697359cc..f07770f9a4242f 100644 --- a/drivers/mtd/nand/raw/mxic_nand.c +++ b/drivers/mtd/nand/raw/mxic_nand.c @@ -492,8 +492,7 @@ static int mxic_nfc_probe(struct platform_device *pdev) int err; int irq; - nfc = devm_kzalloc(&pdev->dev, sizeof(struct mxic_nand_ctlr), - GFP_KERNEL); + nfc = devm_kzalloc_obj(&pdev->dev, struct mxic_nand_ctlr); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index a225b10f814573..fe8c6dcc9c0712 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5474,7 +5474,7 @@ int rawnand_dt_parse_gpio_cs(struct device *dev, struct gpio_desc ***cs_array, return 0; } - descs = devm_kcalloc(dev, ndescs, sizeof(*descs), GFP_KERNEL); + descs = devm_kzalloc_objs(dev, *descs, ndescs); if (!descs) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c index fe968037f75a2a..ff2d4cef11b351 100644 --- a/drivers/mtd/nand/raw/nandsim.c +++ b/drivers/mtd/nand/raw/nandsim.c @@ -982,7 +982,7 @@ static int ns_read_error(unsigned int page_no) static int ns_setup_wear_reporting(struct mtd_info *mtd) { wear_eb_count = div_u64(mtd->size, mtd->erasesize); - erase_block_wear = kcalloc(wear_eb_count, sizeof(unsigned long), GFP_KERNEL); + erase_block_wear = kzalloc_objs(unsigned long, wear_eb_count); if (!erase_block_wear) { NS_ERR("Too many erase blocks for wear reporting\n"); return -ENOMEM; diff --git a/drivers/mtd/nand/raw/nuvoton-ma35d1-nand-controller.c b/drivers/mtd/nand/raw/nuvoton-ma35d1-nand-controller.c index f659d3a6b9ef46..1a36b227ddeb2d 100644 --- a/drivers/mtd/nand/raw/nuvoton-ma35d1-nand-controller.c +++ b/drivers/mtd/nand/raw/nuvoton-ma35d1-nand-controller.c @@ -866,8 +866,7 @@ static int ma35_nand_chip_init(struct device *dev, struct ma35_nand_info *nand, return -EINVAL; } - nvtnand = devm_kzalloc(dev, struct_size(nvtnand, sels, nsels), - GFP_KERNEL); + nvtnand = devm_kzalloc_flex(dev, *nvtnand, sels, nsels); if (!nvtnand) return -ENOMEM; @@ -953,7 +952,7 @@ static int ma35_nand_probe(struct platform_device *pdev) struct ma35_nand_info *nand; int ret = 0; - nand = devm_kzalloc(&pdev->dev, sizeof(*nand), GFP_KERNEL); + nand = devm_kzalloc_obj(&pdev->dev, *nand); if (!nand) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/omap2.c b/drivers/mtd/nand/raw/omap2.c index 4fa89aee934ebe..cf98185f9fe169 100644 --- a/drivers/mtd/nand/raw/omap2.c +++ b/drivers/mtd/nand/raw/omap2.c @@ -2218,8 +2218,7 @@ static int omap_nand_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; void __iomem *vaddr; - info = devm_kzalloc(&pdev->dev, sizeof(struct omap_nand_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct omap_nand_info); if (!info) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/omap_elm.c b/drivers/mtd/nand/raw/omap_elm.c index c1d19b8e6715a7..6736dac26b2d23 100644 --- a/drivers/mtd/nand/raw/omap_elm.c +++ b/drivers/mtd/nand/raw/omap_elm.c @@ -385,7 +385,7 @@ static int elm_probe(struct platform_device *pdev) struct elm_info *info; int irq; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/orion_nand.c b/drivers/mtd/nand/raw/orion_nand.c index 47e80d5e58c598..dfa49ad1f55e99 100644 --- a/drivers/mtd/nand/raw/orion_nand.c +++ b/drivers/mtd/nand/raw/orion_nand.c @@ -106,9 +106,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) int ret = 0; u32 val = 0; - info = devm_kzalloc(&pdev->dev, - sizeof(struct orion_nand_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct orion_nand_info); if (!info) return -ENOMEM; nc = &info->chip; @@ -124,8 +122,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) return PTR_ERR(io_base); if (pdev->dev.of_node) { - board = devm_kzalloc(&pdev->dev, sizeof(struct orion_nand_data), - GFP_KERNEL); + board = devm_kzalloc_obj(&pdev->dev, struct orion_nand_data); if (!board) return -ENOMEM; if (!of_property_read_u32(pdev->dev.of_node, "cle", &val)) diff --git a/drivers/mtd/nand/raw/pl35x-nand-controller.c b/drivers/mtd/nand/raw/pl35x-nand-controller.c index 26b61d856143c5..cb7eb29a182a80 100644 --- a/drivers/mtd/nand/raw/pl35x-nand-controller.c +++ b/drivers/mtd/nand/raw/pl35x-nand-controller.c @@ -1057,7 +1057,7 @@ static int pl35x_nand_chip_init(struct pl35x_nandc *nfc, struct mtd_info *mtd; int cs, ret; - plnand = devm_kzalloc(nfc->dev, sizeof(*plnand), GFP_KERNEL); + plnand = devm_kzalloc_obj(nfc->dev, *plnand); if (!plnand) return -ENOMEM; @@ -1153,7 +1153,7 @@ static int pl35x_nand_probe(struct platform_device *pdev) struct pl35x_nandc *nfc; int ret; - nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(&pdev->dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/plat_nand.c b/drivers/mtd/nand/raw/plat_nand.c index fe31551bcf5f0f..915ea536159218 100644 --- a/drivers/mtd/nand/raw/plat_nand.c +++ b/drivers/mtd/nand/raw/plat_nand.c @@ -65,8 +65,7 @@ static int plat_nand_probe(struct platform_device *pdev) } /* Allocate memory for the device structure (and zero it) */ - data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct plat_nand_data); if (!data) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c index 2d98f79b492d61..abca02f54d74ed 100644 --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -1959,8 +1959,8 @@ static int qcom_nand_host_parse_boot_partitions(struct qcom_nand_controller *nan } host->nr_boot_partitions = partitions_count / 2; - host->boot_partitions = devm_kcalloc(dev, host->nr_boot_partitions, - sizeof(*host->boot_partitions), GFP_KERNEL); + host->boot_partitions = devm_kzalloc_objs(dev, *host->boot_partitions, + host->nr_boot_partitions); if (!host->boot_partitions) { host->nr_boot_partitions = 0; return -ENOMEM; @@ -2077,7 +2077,7 @@ static int qcom_probe_nand_devices(struct qcom_nand_controller *nandc) int ret = -ENODEV; for_each_available_child_of_node_scoped(dn, child) { - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; @@ -2127,7 +2127,7 @@ static int qcom_nandc_probe(struct platform_device *pdev) struct resource *res; int ret; - nandc = devm_kzalloc(&pdev->dev, sizeof(*nandc), GFP_KERNEL); + nandc = devm_kzalloc_obj(&pdev->dev, *nandc); if (!nandc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/renesas-nand-controller.c b/drivers/mtd/nand/raw/renesas-nand-controller.c index 201dd62b99905a..ea7e74b1c0eb1c 100644 --- a/drivers/mtd/nand/raw/renesas-nand-controller.c +++ b/drivers/mtd/nand/raw/renesas-nand-controller.c @@ -1217,8 +1217,7 @@ static int rnandc_chip_init(struct rnandc *rnandc, struct device_node *np) } /* Alloc the driver's NAND chip structure */ - rnand = devm_kzalloc(rnandc->dev, struct_size(rnand, sels, nsels), - GFP_KERNEL); + rnand = devm_kzalloc_flex(rnandc->dev, *rnand, sels, nsels); if (!rnand) return -ENOMEM; @@ -1322,7 +1321,7 @@ static int rnandc_probe(struct platform_device *pdev) struct clk *eclk; int irq, ret; - rnandc = devm_kzalloc(&pdev->dev, sizeof(*rnandc), GFP_KERNEL); + rnandc = devm_kzalloc_obj(&pdev->dev, *rnandc); if (!rnandc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/rockchip-nand-controller.c b/drivers/mtd/nand/raw/rockchip-nand-controller.c index 9444ba02696d4a..dbc195db9ef0eb 100644 --- a/drivers/mtd/nand/raw/rockchip-nand-controller.c +++ b/drivers/mtd/nand/raw/rockchip-nand-controller.c @@ -1134,8 +1134,7 @@ static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc, return -EINVAL; } - rknand = devm_kzalloc(dev, struct_size(rknand, sels, nsels), - GFP_KERNEL); + rknand = devm_kzalloc_flex(dev, *rknand, sels, nsels); if (!rknand) return -ENOMEM; @@ -1381,7 +1380,7 @@ static int rk_nfc_probe(struct platform_device *pdev) struct rk_nfc *nfc; int ret, irq; - nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/sh_flctl.c b/drivers/mtd/nand/raw/sh_flctl.c index 0497801d7059fe..7d7bbf7645554f 100644 --- a/drivers/mtd/nand/raw/sh_flctl.c +++ b/drivers/mtd/nand/raw/sh_flctl.c @@ -1098,8 +1098,7 @@ static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev) return NULL; } - pdata = devm_kzalloc(dev, sizeof(struct sh_flctl_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct sh_flctl_platform_data); if (!pdata) return NULL; @@ -1121,7 +1120,7 @@ static int flctl_probe(struct platform_device *pdev) int ret; int irq; - flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL); + flctl = devm_kzalloc_obj(&pdev->dev, struct sh_flctl); if (!flctl) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/socrates_nand.c b/drivers/mtd/nand/raw/socrates_nand.c index 668584683ce502..a5125e0c8cdb7f 100644 --- a/drivers/mtd/nand/raw/socrates_nand.c +++ b/drivers/mtd/nand/raw/socrates_nand.c @@ -142,7 +142,7 @@ static int socrates_nand_probe(struct platform_device *ofdev) int res; /* Allocate memory for the device structure (and zero it) */ - host = devm_kzalloc(&ofdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&ofdev->dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c index 9f42f8ab3212a8..56c34328ce24d6 100644 --- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c +++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c @@ -1915,7 +1915,7 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev) int chip_cs, mem_region, ret, irq; int start_region = 0; - nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index f41feebe425715..38e67d3503004a 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2465,8 +2465,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, return -EINVAL; } - sunxi_nand = devm_kzalloc(dev, struct_size(sunxi_nand, sels, nsels), - GFP_KERNEL); + sunxi_nand = devm_kzalloc_flex(dev, *sunxi_nand, sels, nsels); if (!sunxi_nand) return -ENOMEM; @@ -2610,7 +2609,7 @@ static int sunxi_nfc_probe(struct platform_device *pdev) int irq; int ret; - nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/technologic-nand-controller.c b/drivers/mtd/nand/raw/technologic-nand-controller.c index a3294aaf43bda0..56d257fc2c2a5e 100644 --- a/drivers/mtd/nand/raw/technologic-nand-controller.c +++ b/drivers/mtd/nand/raw/technologic-nand-controller.c @@ -139,7 +139,7 @@ static int ts72xx_nand_probe(struct platform_device *pdev) struct mtd_info *mtd; int err; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c index 7f9eb5f042a7ee..199b3a8e552a49 100644 --- a/drivers/mtd/nand/raw/tegra_nand.c +++ b/drivers/mtd/nand/raw/tegra_nand.c @@ -1096,7 +1096,7 @@ static int tegra_nand_chips_init(struct device *dev, return ret; } - nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL); + nand = devm_kzalloc_obj(dev, *nand); if (!nand) return -ENOMEM; @@ -1149,7 +1149,7 @@ static int tegra_nand_probe(struct platform_device *pdev) struct tegra_nand_controller *ctrl; int err = 0; - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/txx9ndfmc.c b/drivers/mtd/nand/raw/txx9ndfmc.c index 4cc6e91dbc23ef..87e61daf143643 100644 --- a/drivers/mtd/nand/raw/txx9ndfmc.c +++ b/drivers/mtd/nand/raw/txx9ndfmc.c @@ -284,7 +284,7 @@ static int txx9ndfmc_probe(struct platform_device *dev) struct txx9ndfmc_drvdata *drvdata; unsigned long gbusclk = plat->gbus_clock; - drvdata = devm_kzalloc(&dev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&dev->dev, *drvdata); if (!drvdata) return -ENOMEM; drvdata->base = devm_platform_ioremap_resource(dev, 0); diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c index 1b9b370adfab61..6ab3c440eac732 100644 --- a/drivers/mtd/nand/raw/vf610_nfc.c +++ b/drivers/mtd/nand/raw/vf610_nfc.c @@ -868,7 +868,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) int err; int irq; - nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL); + nfc = devm_kzalloc_obj(&pdev->dev, *nfc); if (!nfc) return -ENOMEM; diff --git a/drivers/mtd/nand/raw/xway_nand.c b/drivers/mtd/nand/raw/xway_nand.c index af84395dc66ead..a946d4d2cff4b0 100644 --- a/drivers/mtd/nand/raw/xway_nand.c +++ b/drivers/mtd/nand/raw/xway_nand.c @@ -171,8 +171,7 @@ static int xway_nand_probe(struct platform_device *pdev) u32 cs_flag = 0; /* Allocate memory for the device structure (and zero it) */ - data = devm_kzalloc(&pdev->dev, sizeof(struct xway_nand_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct xway_nand_data); if (!data) return -ENOMEM; diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 133776ba53da09..22756832eacf89 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -2057,8 +2057,7 @@ static int spinand_probe(struct spi_mem *mem) struct mtd_info *mtd; int ret; - spinand = devm_kzalloc(&mem->spi->dev, sizeof(*spinand), - GFP_KERNEL); + spinand = devm_kzalloc_obj(&mem->spi->dev, *spinand); if (!spinand) return -ENOMEM; diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c index 3833b887c66763..029d56e951dbb9 100644 --- a/drivers/mtd/parsers/sharpslpart.c +++ b/drivers/mtd/parsers/sharpslpart.c @@ -179,8 +179,7 @@ static int sharpsl_nand_init_ftl(struct mtd_info *mtd, struct sharpsl_ftl *ftl) /* FTL reserves 5% of the blocks + 1 spare */ ftl->logmax = ((phymax * 95) / 100) - 1; - ftl->log2phy = kmalloc_array(ftl->logmax, sizeof(*ftl->log2phy), - GFP_KERNEL); + ftl->log2phy = kmalloc_objs(*ftl->log2phy, ftl->logmax); if (!ftl->log2phy) { ret = -ENOMEM; goto exit; diff --git a/drivers/mtd/spi-nor/controllers/hisi-sfc.c b/drivers/mtd/spi-nor/controllers/hisi-sfc.c index 6897ced2d57b91..4f6631950a5b75 100644 --- a/drivers/mtd/spi-nor/controllers/hisi-sfc.c +++ b/drivers/mtd/spi-nor/controllers/hisi-sfc.c @@ -339,14 +339,14 @@ static int hisi_spi_nor_register(struct device_node *np, struct mtd_info *mtd; int ret; - nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); + nor = devm_kzalloc_obj(dev, *nor); if (!nor) return -ENOMEM; nor->dev = dev; spi_nor_set_flash_node(nor, np); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -420,7 +420,7 @@ static int hisi_spi_nor_probe(struct platform_device *pdev) struct hifmc_host *host; int ret; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/mtd/spi-nor/controllers/nxp-spifi.c b/drivers/mtd/spi-nor/controllers/nxp-spifi.c index 1a92d71755db93..30fe2d414f076a 100644 --- a/drivers/mtd/spi-nor/controllers/nxp-spifi.c +++ b/drivers/mtd/spi-nor/controllers/nxp-spifi.c @@ -382,7 +382,7 @@ static int nxp_spifi_probe(struct platform_device *pdev) struct nxp_spifi *spifi; int ret; - spifi = devm_kzalloc(&pdev->dev, sizeof(*spifi), GFP_KERNEL); + spifi = devm_kzalloc_obj(&pdev->dev, *spifi); if (!spifi) return -ENOMEM; diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 90524c58602e1c..a04d22d2e2e1c0 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2965,7 +2965,7 @@ static int spi_nor_init_params(struct spi_nor *nor) { int ret; - nor->params = devm_kzalloc(nor->dev, sizeof(*nor->params), GFP_KERNEL); + nor->params = devm_kzalloc_obj(nor->dev, *nor->params); if (!nor->params) return -ENOMEM; @@ -3327,8 +3327,7 @@ static int spi_nor_set_mtd_eraseregions(struct spi_nor *nor) struct mtd_info *mtd = &nor->mtd; u32 erasesize, i; - mtd_region = devm_kcalloc(nor->dev, map->n_regions, sizeof(*mtd_region), - GFP_KERNEL); + mtd_region = devm_kzalloc_objs(nor->dev, *mtd_region, map->n_regions); if (!mtd_region) return -ENOMEM; @@ -3567,7 +3566,7 @@ static int spi_nor_probe(struct spi_mem *spimem) if (ret) return ret; - nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); + nor = devm_kzalloc_obj(dev, *nor); if (!nor) return -ENOMEM; diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index 4a3f82e97cef8a..4d77354ee1b28d 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -951,8 +951,7 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, * The regions will be freed when the driver detaches from the * device. */ - region = devm_kcalloc(nor->dev, region_count, sizeof(*region), - GFP_KERNEL); + region = devm_kzalloc_objs(nor->dev, *region, region_count); if (!region) return -ENOMEM; map->regions = region; @@ -1386,8 +1385,7 @@ static int spi_nor_parse_sccr(struct spi_nor *nor, /* Address offset for volatile registers (die 0) */ if (!params->vreg_offset) { - params->vreg_offset = devm_kmalloc(nor->dev, sizeof(*dwords), - GFP_KERNEL); + params->vreg_offset = devm_kmalloc_obj(nor->dev, *dwords); if (!params->vreg_offset) { ret = -ENOMEM; goto out; @@ -1628,7 +1626,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) sfdp_size = SFDP_MAX_SIZE; } - sfdp = devm_kzalloc(dev, sizeof(*sfdp), GFP_KERNEL); + sfdp = devm_kzalloc_obj(dev, *sfdp); if (!sfdp) { err = -ENOMEM; goto free_param_headers; @@ -1641,8 +1639,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) * the complete SFDP data. */ sfdp->num_dwords = DIV_ROUND_UP(sfdp_size, sizeof(*sfdp->dwords)); - sfdp->dwords = devm_kcalloc(dev, sfdp->num_dwords, - sizeof(*sfdp->dwords), GFP_KERNEL); + sfdp->dwords = devm_kzalloc_objs(dev, *sfdp->dwords, sfdp->num_dwords); if (!sfdp->dwords) { err = -ENOMEM; goto free_sfdp; diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index bc50881d564864..b1b14ed0fd467a 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -567,7 +567,7 @@ static int s25fs256t_post_sfdp_fixup(struct spi_nor *nor) * same code base for both single and multi chip package devices, thus * set the vreg_offset and n_dice to be able to do so. */ - params->vreg_offset = devm_kmalloc(nor->dev, sizeof(u32), GFP_KERNEL); + params->vreg_offset = devm_kmalloc_obj(nor->dev, u32); if (!params->vreg_offset) return -ENOMEM; @@ -1124,8 +1124,7 @@ static int spansion_nor_late_init(struct spi_nor *nor) } if (mfr_flags & (USE_CLSR | USE_CLPEF)) { - priv_params = devm_kmalloc(nor->dev, sizeof(*priv_params), - GFP_KERNEL); + priv_params = devm_kmalloc_obj(nor->dev, *priv_params); if (!priv_params) return -ENOMEM; diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index 4a5225699a545a..94a80f34e4a690 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c @@ -329,8 +329,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) /* Allocate logical block map */ ssfdc->logic_block_map = - kmalloc_array(ssfdc->map_len, - sizeof(ssfdc->logic_block_map[0]), GFP_KERNEL); + kmalloc_objs(ssfdc->logic_block_map[0], ssfdc->map_len); if (!ssfdc->logic_block_map) goto out_free_ssfdc; memset(ssfdc->logic_block_map, 0xff, sizeof(ssfdc->logic_block_map[0]) * diff --git a/drivers/mux/mmio.c b/drivers/mux/mmio.c index b61e590f2ac9e7..7033402986a826 100644 --- a/drivers/mux/mmio.c +++ b/drivers/mux/mmio.c @@ -100,14 +100,13 @@ static int mux_mmio_probe(struct platform_device *pdev) mux_mmio = mux_chip_priv(mux_chip); - mux_mmio->fields = devm_kcalloc(dev, num_fields, sizeof(*mux_mmio->fields), - GFP_KERNEL); + mux_mmio->fields = devm_kzalloc_objs(dev, *mux_mmio->fields, num_fields); if (!mux_mmio->fields) return -ENOMEM; - mux_mmio->hardware_states = devm_kcalloc(dev, num_fields, - sizeof(*mux_mmio->hardware_states), - GFP_KERNEL); + mux_mmio->hardware_states = devm_kzalloc_objs(dev, + *mux_mmio->hardware_states, + num_fields); if (!mux_mmio->hardware_states) return -ENOMEM; diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 81d26ef82cf5cb..8b9fc3d11eceec 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2147,13 +2147,12 @@ static void amt_mldv1_leave_handler(struct amt_dev *amt, struct sk_buff *skb, struct amt_tunnel_list *tunnel) { struct mld_msg *mld = (struct mld_msg *)icmp6_hdr(skb); - struct iphdr *iph = ip_hdr(skb); + struct ipv6hdr *ip6h = ipv6_hdr(skb); struct amt_group_node *gnode; union amt_addr group, host; memcpy(&group.ip6, &mld->mld_mca, sizeof(struct in6_addr)); - memset(&host, 0, sizeof(union amt_addr)); - host.ip4 = iph->saddr; + memcpy(&host.ip6, &ip6h->saddr, sizeof(struct in6_addr)); gnode = amt_lookup_group(tunnel, &group, &host, true); if (gnode) { @@ -3404,22 +3403,6 @@ static struct rtnl_link_ops amt_link_ops __read_mostly = { .fill_info = amt_fill_info, }; -static struct net_device *amt_lookup_upper_dev(struct net_device *dev) -{ - struct net_device *upper_dev; - struct amt_dev *amt; - - for_each_netdev(dev_net(dev), upper_dev) { - if (netif_is_amt(upper_dev)) { - amt = netdev_priv(upper_dev); - if (amt->stream_dev == dev) - return upper_dev; - } - } - - return NULL; -} - static int amt_device_event(struct notifier_block *unused, unsigned long event, void *ptr) { @@ -3429,26 +3412,34 @@ static int amt_device_event(struct notifier_block *unused, LIST_HEAD(list); int new_mtu; - upper_dev = amt_lookup_upper_dev(dev); - if (!upper_dev) - return NOTIFY_DONE; - amt = netdev_priv(upper_dev); + /* amt_dellink() leaves each device on the netns device list until + * unregister_netdevice_many(), so the walk stays valid. + */ + for_each_netdev(dev_net(dev), upper_dev) { + if (!netif_is_amt(upper_dev)) + continue; + amt = netdev_priv(upper_dev); + if (amt->stream_dev != dev) + continue; - switch (event) { - case NETDEV_UNREGISTER: - amt_dellink(amt->dev, &list); - unregister_netdevice_many(&list); - break; - case NETDEV_CHANGEMTU: - if (amt->mode == AMT_MODE_RELAY) - new_mtu = dev->mtu - AMT_RELAY_HLEN; - else - new_mtu = dev->mtu - AMT_GW_HLEN; + switch (event) { + case NETDEV_UNREGISTER: + amt_dellink(amt->dev, &list); + break; + case NETDEV_CHANGEMTU: + if (amt->mode == AMT_MODE_RELAY) + new_mtu = dev->mtu - AMT_RELAY_HLEN; + else + new_mtu = dev->mtu - AMT_GW_HLEN; - dev_set_mtu(amt->dev, new_mtu); - break; + dev_set_mtu(amt->dev, new_mtu); + break; + } } + if (event == NETDEV_UNREGISTER) + unregister_netdevice_many(&list); + return NOTIFY_DONE; } diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c index 19cd36cba64d05..3bdb20ffba1403 100644 --- a/drivers/net/arcnet/com20020-pci.c +++ b/drivers/net/arcnet/com20020-pci.c @@ -136,8 +136,7 @@ static int com20020pci_probe(struct pci_dev *pdev, if (pci_enable_device(pdev)) return -EIO; - priv = devm_kzalloc(&pdev->dev, sizeof(struct com20020_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct com20020_priv); if (!priv) return -ENOMEM; @@ -239,8 +238,7 @@ static int com20020pci_probe(struct pci_dev *pdev, if (ret) goto err_free_arcdev; - card = devm_kzalloc(&pdev->dev, sizeof(struct com20020_dev), - GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, struct com20020_dev); if (!card) { ret = -ENOMEM; goto err_free_arcdev; diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 7019e5d8fdc8e4..e9f5e753f6770b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2305,7 +2305,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, SLAVE_NL_ERR(bond_dev, slave_dev, extack, "Slave does not support XDP"); res = -EOPNOTSUPP; - goto err_sysfs_del; + goto err_dec_slave_cnt; } } else if (bond->xdp_prog) { struct netdev_bpf xdp = { @@ -2319,14 +2319,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, SLAVE_NL_ERR(bond_dev, slave_dev, extack, "Slave has XDP program loaded, please unload before enslaving"); res = -EOPNOTSUPP; - goto err_sysfs_del; + goto err_dec_slave_cnt; } res = dev_xdp_propagate(slave_dev, &xdp); if (res < 0) { /* ndo_bpf() sets extack error message */ slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res); - goto err_sysfs_del; + goto err_dec_slave_cnt; } if (bond->xdp_prog) bpf_prog_inc(bond->xdp_prog); @@ -2348,6 +2348,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, return 0; /* Undo stages on error */ +err_dec_slave_cnt: + WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1); + err_sysfs_del: bond_sysfs_slave_del(new_slave); @@ -2779,6 +2782,27 @@ static void bond_miimon_link_change(struct bonding *bond, } } +static bool bond_miimon_slave_down(struct bonding *bond, + struct slave *slave) +{ + if (slave->link_failure_count < UINT_MAX) + slave->link_failure_count++; + + bond_set_slave_link_state(slave, BOND_LINK_DOWN, + BOND_SLAVE_NOTIFY_NOW); + + if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP || + BOND_MODE(bond) == BOND_MODE_8023AD) + bond_set_slave_inactive_flags(slave, + BOND_SLAVE_NOTIFY_NOW); + + slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n"); + + bond_miimon_link_change(bond, slave, BOND_LINK_DOWN); + + return slave == rcu_access_pointer(bond->curr_active_slave); +} + static void bond_miimon_commit(struct bonding *bond) { struct slave *slave, *primary, *active; @@ -2807,10 +2831,22 @@ static void bond_miimon_commit(struct bonding *bond) err = bond_update_speed_duplex(slave); netdev_unlock_ops(slave->dev); if (err && bond_needs_speed_duplex(bond)) { - slave->link = BOND_LINK_DOWN; if (net_ratelimit()) slave_warn(bond->dev, slave->dev, "failed to get link speed/duplex\n"); + /* Coming from FAIL/UP, the slave may still be + * in use and may be curr_active_slave, so take + * it through the full down path. Coming from + * DOWN/BACK, it was never brought up, so just + * revert it to DOWN. + */ + if (slave->link == BOND_LINK_FAIL || + slave->link == BOND_LINK_UP) { + if (bond_miimon_slave_down(bond, slave)) + do_failover = true; + continue; + } + slave->link = BOND_LINK_DOWN; continue; } bond_set_slave_link_state(slave, BOND_LINK_UP, @@ -2839,28 +2875,13 @@ static void bond_miimon_commit(struct bonding *bond) continue; case BOND_LINK_DOWN: - if (slave->link_failure_count < UINT_MAX) - slave->link_failure_count++; - - bond_set_slave_link_state(slave, BOND_LINK_DOWN, - BOND_SLAVE_NOTIFY_NOW); - - if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP || - BOND_MODE(bond) == BOND_MODE_8023AD) - bond_set_slave_inactive_flags(slave, - BOND_SLAVE_NOTIFY_NOW); - - slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n"); - - bond_miimon_link_change(bond, slave, BOND_LINK_DOWN); - - if (slave == rcu_access_pointer(bond->curr_active_slave)) + if (bond_miimon_slave_down(bond, slave)) do_failover = true; - continue; case BOND_LINK_FAIL: case BOND_LINK_BACK: + bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER); slave_dbg(bond->dev, slave->dev, "link_new_state %d on slave\n", slave->link_new_state); continue; @@ -2894,8 +2915,6 @@ static void bond_mii_monitor(struct work_struct *work) { struct bonding *bond = container_of(work, struct bonding, mii_work.work); - struct list_head *iter; - struct slave *slave; unsigned long delay; bool commit; @@ -2917,13 +2936,8 @@ static void bond_mii_monitor(struct work_struct *work) goto re_arm; } - if (commit) { - bond_for_each_slave(bond, slave, iter) { - bond_commit_link_state(slave, - BOND_SLAVE_NOTIFY_LATER); - } + if (commit) bond_miimon_commit(bond); - } if (bond->send_peer_notif) bond_peer_notify_may_events(bond, true); @@ -3973,18 +3987,13 @@ static int bond_slave_netdev_event(unsigned long event, case NETDEV_CHANGE: /* For 802.3ad mode only: * Getting invalid Speed/Duplex values here will put slave - * in weird state. Mark it as link-fail if the link was - * previously up or link-down if it hasn't yet come up, and - * let link-monitoring (miimon) set it right when correct - * speeds/duplex are available. + * in weird state. Mark an up slave as link-fail and let + * miimon set it right when correct speed/duplex are available. */ if (bond_update_speed_duplex(slave) && - BOND_MODE(bond) == BOND_MODE_8023AD) { - if (slave->last_link_up) - slave->link = BOND_LINK_FAIL; - else - slave->link = BOND_LINK_DOWN; - } + BOND_MODE(bond) == BOND_MODE_8023AD && + slave->link == BOND_LINK_UP) + slave->link = BOND_LINK_FAIL; if (BOND_MODE(bond) == BOND_MODE_8023AD) bond_3ad_adapter_speed_duplex_changed(slave); diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 766d455950f55d..081dfddda00088 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -720,7 +720,8 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], return 0; } -static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params, +static size_t can_tdc_get_size(const struct net_device *dev, + struct data_bittiming_params *dbt_params, u32 tdc_flags) { bool tdc_manual = tdc_flags & CAN_CTRLMODE_TDC_MANUAL_MASK; @@ -742,7 +743,8 @@ static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params, } if (tdc_flags) { - if (tdc_manual || dbt_params->do_get_auto_tdcv) + if (tdc_manual || + (dbt_params->do_get_auto_tdcv && netif_running(dev))) size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCV */ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_TDCO */ if (dbt_params->tdc_const->tdcf_max) @@ -752,7 +754,8 @@ static size_t can_tdc_get_size(struct data_bittiming_params *dbt_params, return size; } -static size_t can_data_bittiming_get_size(struct data_bittiming_params *dbt_params, +static size_t can_data_bittiming_get_size(const struct net_device *dev, + struct data_bittiming_params *dbt_params, u32 tdc_flags) { size_t size = 0; @@ -764,7 +767,7 @@ static size_t can_data_bittiming_get_size(struct data_bittiming_params *dbt_para if (dbt_params->data_bitrate_const) /* IFLA_CAN_{,XL}_DATA_BITRATE_CONST */ size += nla_total_size(sizeof(*dbt_params->data_bitrate_const) * dbt_params->data_bitrate_const_cnt); - size += can_tdc_get_size(dbt_params, tdc_flags);/* IFLA_CAN_{,XL}_TDC */ + size += can_tdc_get_size(dev, dbt_params, tdc_flags);/* IFLA_CAN_{,XL}_TDC */ return size; } @@ -812,7 +815,7 @@ static size_t can_get_size(const struct net_device *dev) size += nla_total_size(sizeof(u32)); /* IFLA_CAN_STATE */ size += nla_total_size(sizeof(struct can_ctrlmode)); /* IFLA_CAN_CTRLMODE */ size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */ - if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */ + if (priv->do_get_berr_counter && netif_running(dev)) /* IFLA_CAN_BERR_COUNTER */ size += nla_total_size(sizeof(struct can_berr_counter)); if (priv->termination_const) { size += nla_total_size(sizeof(priv->termination)); /* IFLA_CAN_TERMINATION */ @@ -825,10 +828,10 @@ static size_t can_get_size(const struct net_device *dev) size += sizeof(priv->bitrate_max); /* IFLA_CAN_BITRATE_MAX */ size += can_ctrlmode_ext_get_size(); /* IFLA_CAN_CTRLMODE_EXT */ - size += can_data_bittiming_get_size(&priv->fd, + size += can_data_bittiming_get_size(dev, &priv->fd, priv->ctrlmode & CAN_CTRLMODE_FD_TDC_MASK); - size += can_data_bittiming_get_size(&priv->xl, + size += can_data_bittiming_get_size(dev, &priv->xl, priv->ctrlmode & CAN_CTRLMODE_XL_TDC_MASK); size += can_pwm_get_size(priv->xl.pwm_const, /* IFLA_CAN_XL_PWM */ priv->ctrlmode & CAN_CTRLMODE_XL_TMS); @@ -910,7 +913,7 @@ static int can_tdc_fill_info(struct sk_buff *skb, const struct net_device *dev, if (tdc_manual) { tdcv = tdc->tdcv; err = 0; - } else if (dbt_params->do_get_auto_tdcv) { + } else if (dbt_params->do_get_auto_tdcv && netif_running(dev)) { err = dbt_params->do_get_auto_tdcv(dev, &tdcv); } if (!err && nla_put_u32(skb, IFLA_CAN_TDC_TDCV, tdcv)) @@ -1006,7 +1009,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) || nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) || - (priv->do_get_berr_counter && + (priv->do_get_berr_counter && netif_running(dev) && !priv->do_get_berr_counter(dev, &bec) && nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) || diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 14edec5afb57e4..738d5968dfa68f 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -4,6 +4,7 @@ * Copyright (C) 2008-2009 Wolfgang Grandegger */ +#include #include #include #include @@ -54,6 +55,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, if (idx >= priv->echo_skb_max) { netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n", __func__, idx, priv->echo_skb_max); + dev_kfree_skb_any(skb); return -EINVAL; } @@ -62,7 +64,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, (skb->protocol != htons(ETH_P_CAN) && skb->protocol != htons(ETH_P_CANFD) && skb->protocol != htons(ETH_P_CANXL))) { - kfree_skb(skb); + dev_kfree_skb_any(skb); return 0; } @@ -90,7 +92,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, } else { /* locking problem with netif_stop_queue() ?? */ netdev_err(dev, "%s: BUG! echo_skb %d is occupied!\n", __func__, idx); - kfree_skb(skb); + dev_kfree_skb_any(skb); return -EBUSY; } @@ -227,7 +229,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf) csx = can_skb_ext_add(skb); if (!csx) { - kfree_skb(skb); + dev_kfree_skb_any(skb); goto out_error_cc; } @@ -258,7 +260,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev, csx = can_skb_ext_add(skb); if (!csx) { - kfree_skb(skb); + dev_kfree_skb_any(skb); goto out_error_fd; } @@ -296,7 +298,7 @@ struct sk_buff *alloc_canxl_skb(struct net_device *dev, csx = can_skb_ext_add(skb); if (!csx) { - kfree_skb(skb); + dev_kfree_skb_any(skb); goto out_error_xl; } @@ -388,7 +390,7 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) break; case ETH_P_CANXL: - if (!can_is_canxl_skb(skb)) + if (!can_cap_enabled(dev, CAN_CAP_XL) || !can_is_canxl_skb(skb)) goto inval_skb; break; @@ -402,7 +404,7 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) return false; inval_skb: - kfree_skb(skb); + dev_kfree_skb_any(skb); dev->stats.tx_dropped++; return true; } diff --git a/drivers/net/can/esd/esd_402_pci-core.c b/drivers/net/can/esd/esd_402_pci-core.c index c826f00c551b4c..1fb3a503b16089 100644 --- a/drivers/net/can/esd/esd_402_pci-core.c +++ b/drivers/net/can/esd/esd_402_pci-core.c @@ -192,8 +192,8 @@ static int pci402_init_card(struct pci_dev *pdev) card->ov.active_cores); return -EINVAL; } - card->cores = devm_kcalloc(&pdev->dev, card->ov.active_cores, - sizeof(struct acc_core), GFP_KERNEL); + card->cores = devm_kzalloc_objs(&pdev->dev, struct acc_core, + card->ov.active_cores); if (!card->cores) return -ENOMEM; @@ -424,7 +424,7 @@ static int pci402_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) return err; - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); if (!card) { err = -ENOMEM; goto failure_disable_pci; diff --git a/drivers/net/can/peak_canfd/peak_pciefd_main.c b/drivers/net/can/peak_canfd/peak_pciefd_main.c index 7c749301ea84cc..4eb51b6a701f42 100644 --- a/drivers/net/can/peak_canfd/peak_pciefd_main.c +++ b/drivers/net/can/peak_canfd/peak_pciefd_main.c @@ -744,8 +744,7 @@ static int peak_pciefd_probe(struct pci_dev *pdev, can_count = 1; /* allocate board structure object */ - pciefd = devm_kzalloc(&pdev->dev, struct_size(pciefd, can, can_count), - GFP_KERNEL); + pciefd = devm_kzalloc_flex(&pdev->dev, *pciefd, can, can_count); if (!pciefd) { err = -ENOMEM; goto err_release_regions; diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c index fcc37b73ed4366..000a6433f46d81 100644 --- a/drivers/net/can/rcar/rcar_canfd.c +++ b/drivers/net/can/rcar/rcar_canfd.c @@ -2157,7 +2157,7 @@ static int rcar_canfd_probe(struct platform_device *pdev) } /* Global controller context */ - gpriv = devm_kzalloc(dev, sizeof(*gpriv), GFP_KERNEL); + gpriv = devm_kzalloc_obj(dev, *gpriv); if (!gpriv) return -ENOMEM; diff --git a/drivers/net/can/sja1000/f81601.c b/drivers/net/can/sja1000/f81601.c index 18cf170db4575e..6fa0cb9b06ce4d 100644 --- a/drivers/net/can/sja1000/f81601.c +++ b/drivers/net/can/sja1000/f81601.c @@ -108,7 +108,7 @@ static int f81601_pci_probe(struct pci_dev *pdev, dev_info(&pdev->dev, "Detected card at slot #%i\n", PCI_SLOT(pdev->devfn)); - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); if (!card) return -ENOMEM; diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c index 70d5ff0ae7acb6..bb071b40d61d79 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c @@ -570,19 +570,15 @@ mcp251xfd_regmap_init_nocrc(struct mcp251xfd_priv *priv) } if (!priv->map_buf_nocrc_rx) { - priv->map_buf_nocrc_rx = - devm_kzalloc(&priv->spi->dev, - sizeof(*priv->map_buf_nocrc_rx), - GFP_KERNEL); + priv->map_buf_nocrc_rx = devm_kzalloc_obj(&priv->spi->dev, + *priv->map_buf_nocrc_rx); if (!priv->map_buf_nocrc_rx) return -ENOMEM; } if (!priv->map_buf_nocrc_tx) { - priv->map_buf_nocrc_tx = - devm_kzalloc(&priv->spi->dev, - sizeof(*priv->map_buf_nocrc_tx), - GFP_KERNEL); + priv->map_buf_nocrc_tx = devm_kzalloc_obj(&priv->spi->dev, + *priv->map_buf_nocrc_tx); if (!priv->map_buf_nocrc_tx) return -ENOMEM; } @@ -623,19 +619,15 @@ mcp251xfd_regmap_init_crc(struct mcp251xfd_priv *priv) } if (!priv->map_buf_crc_rx) { - priv->map_buf_crc_rx = - devm_kzalloc(&priv->spi->dev, - sizeof(*priv->map_buf_crc_rx), - GFP_KERNEL); + priv->map_buf_crc_rx = devm_kzalloc_obj(&priv->spi->dev, + *priv->map_buf_crc_rx); if (!priv->map_buf_crc_rx) return -ENOMEM; } if (!priv->map_buf_crc_tx) { - priv->map_buf_crc_tx = - devm_kzalloc(&priv->spi->dev, - sizeof(*priv->map_buf_crc_tx), - GFP_KERNEL); + priv->map_buf_crc_tx = devm_kzalloc_obj(&priv->spi->dev, + *priv->map_buf_crc_tx); if (!priv->map_buf_crc_tx) return -ENOMEM; } diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c index 4c147b9d6d690a..22a6cfa5de9a34 100644 --- a/drivers/net/can/usb/f81604.c +++ b/drivers/net/can/usb/f81604.c @@ -1149,7 +1149,7 @@ static int f81604_probe(struct usb_interface *intf, struct f81604_priv *priv; int i, ret; - priv = devm_kzalloc(&intf->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&intf->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index efbb7bed34c9d9..687911d764ded2 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1804,7 +1804,7 @@ static int kvaser_usb_hydra_init_channel(struct kvaser_usb_net_priv *priv) { struct kvaser_usb_net_hydra_priv *hydra; - hydra = devm_kzalloc(&priv->dev->intf->dev, sizeof(*hydra), GFP_KERNEL); + hydra = devm_kzalloc_obj(&priv->dev->intf->dev, *hydra); if (!hydra) return -ENOMEM; diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index a876c7819b81c0..909d0e919653f9 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -1861,7 +1861,7 @@ static int kvaser_usb_leaf_init_channel(struct kvaser_usb_net_priv *priv) { struct kvaser_usb_net_leaf_priv *leaf; - leaf = devm_kzalloc(&priv->dev->intf->dev, sizeof(*leaf), GFP_KERNEL); + leaf = devm_kzalloc_obj(&priv->dev->intf->dev, *leaf); if (!leaf) return -ENOMEM; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 0d46f4ce5dca71..39f0740421c367 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -755,7 +755,7 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb) u16 rx_msg_type, rx_msg_size; size_t rx_msg_min_size; - if (msg_end - msg_ptr < sizeof(*rx_msg)) { + if (msg_end - msg_ptr < sizeof(rx_msg->size)) { err = -EBADMSG; break; } @@ -766,6 +766,11 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb) break; } + if (msg_end - msg_ptr < sizeof(*rx_msg)) { + err = -EBADMSG; + break; + } + rx_msg_size = le16_to_cpu(rx_msg->size); rx_msg_type = le16_to_cpu(rx_msg->type); diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c index f72e0644c5fdb7..a50e2e7e48a919 100644 --- a/drivers/net/can/usb/ucan.c +++ b/drivers/net/can/usb/ucan.c @@ -1379,9 +1379,7 @@ static int ucan_probe(struct usb_interface *intf, */ /* Prepare Memory for control transfers */ - ctl_msg_buffer = devm_kzalloc(&intf->dev, - sizeof(union ucan_ctl_payload), - GFP_KERNEL); + ctl_msg_buffer = devm_kzalloc_obj(&intf->dev, union ucan_ctl_payload); if (!ctl_msg_buffer) { dev_err(&udev->dev, "%s: failed to allocate control pipe memory\n", diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 0880310c9ce3f0..b7aff5e238e857 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -836,6 +836,59 @@ void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) } EXPORT_SYMBOL(b53_brcm_hdr_setup); +int b53_enable_mcast_snooping(struct b53_device *dev) +{ + u16 val16; + u32 val; + int ret; + + /* Older switches use different IGMP controls, not HL_PRTC_CTRL. */ + if (is5325(dev) || is5365(dev) || dev->chip_id == BCM5389_DEVICE_ID || + is5397_98(dev) || is63xx(dev)) + return 0; + + /* IGMPv2 and MLDv1 reports use the group's destination MAC. Once + * the first listener is offloaded, ordinary multicast forwarding + * can keep subsequent reports from reaching the bridge CPU. + */ + + /* BCM5395 has a narrower register and a single IGMP classifier. + * Its ICMPv6 classifier also covers MLD. + */ + if (dev->chip_id == BCM5395_DEVICE_ID) { + ret = b53_read16(dev, B53_MGMT_PAGE, B53_HL_PRTC_CTRL, &val16); + if (ret) + return ret; + + val16 |= HL_PRTC_IGMP_IP_EN_5395 | HL_PRTC_ICMPV6_EN; + /* Zero forwarding modes copy control traffic to the CPU + * independently of the ARL lookup, retaining L2 forwarding. + */ + val16 &= ~(HL_PRTC_IGMP_FWD_MODE_5395 | + HL_PRTC_ICMPV6_FWD_MODE); + + return b53_write16(dev, B53_MGMT_PAGE, B53_HL_PRTC_CTRL, + val16); + } + + ret = b53_read32(dev, B53_MGMT_PAGE, B53_HL_PRTC_CTRL, &val); + if (ret) + return ret; + + val |= HL_PRTC_IGMP_RPTLVE_EN | HL_PRTC_IGMP_QRY_EN | + HL_PRTC_IGMP_UKN_EN | HL_PRTC_MLD_RPTDONE_EN | + HL_PRTC_MLD_QRY_EN; + /* Zero forwarding modes copy control traffic to the CPU + * independently of the ARL lookup, retaining L2 forwarding. + */ + val &= ~(HL_PRTC_IGMP_RPTLVE_FWD_MODE | HL_PRTC_IGMP_QRY_FWD_MODE | + HL_PRTC_IGMP_UKN_FWD_MODE | HL_PRTC_MLD_RPTDONE_FWD_MODE | + HL_PRTC_MLD_QRY_FWD_MODE); + + return b53_write32(dev, B53_MGMT_PAGE, B53_HL_PRTC_CTRL, val); +} +EXPORT_SYMBOL(b53_enable_mcast_snooping); + static void b53_enable_cpu_port(struct b53_device *dev, int port) { u8 port_ctrl; @@ -1334,6 +1387,10 @@ static int b53_setup(struct dsa_switch *ds) b53_disable_port(ds, port); } + ret = b53_enable_mcast_snooping(dev); + if (ret) + return ret; + return b53_setup_devlink_resources(ds); } @@ -1663,9 +1720,15 @@ static void b53_phylink_mac_link_up(struct phylink_config *config, } if (mode == MLO_AN_FIXED) { - /* Force flow control on BCM5301x's CPU port */ - if (is5301x(dev) && dsa_is_cpu_port(ds, port)) - tx_pause = rx_pause = true; + /* Force flow control and 2Gbits/sec on BCM5301x and NSP CPU + * ports + */ + if ((is5301x(dev) || dev->chip_id == BCM58XX_DEVICE_ID) && + dsa_is_cpu_port(ds, port)) { + tx_pause = true; + rx_pause = true; + speed = 2000; + } b53_force_port_config(dev, port, speed, duplex, tx_pause, rx_pause); @@ -3160,15 +3223,13 @@ static int b53_switch_init(struct b53_device *dev) } } - dev->ports = devm_kcalloc(dev->dev, - dev->num_ports, sizeof(struct b53_port), - GFP_KERNEL); + dev->ports = devm_kzalloc_objs(dev->dev, struct b53_port, + dev->num_ports); if (!dev->ports) return -ENOMEM; - dev->vlans = devm_kcalloc(dev->dev, - dev->num_vlans, sizeof(struct b53_vlan), - GFP_KERNEL); + dev->vlans = devm_kzalloc_objs(dev->dev, struct b53_vlan, + dev->num_vlans); if (!dev->vlans) return -ENOMEM; @@ -3187,13 +3248,13 @@ struct b53_device *b53_switch_alloc(struct device *base, struct dsa_switch *ds; struct b53_device *dev; - ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(base, *ds); if (!ds) return NULL; ds->dev = base; - dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(base, *dev); if (!dev) return NULL; diff --git a/drivers/net/dsa/b53/b53_mmap.c b/drivers/net/dsa/b53/b53_mmap.c index f4a59d8fbdd604..0f6402286333c6 100644 --- a/drivers/net/dsa/b53/b53_mmap.c +++ b/drivers/net/dsa/b53/b53_mmap.c @@ -371,8 +371,7 @@ static int b53_mmap_probe_of(struct platform_device *pdev, if (IS_ERR(mem)) return PTR_ERR(mem); - pdata = devm_kzalloc(dev, sizeof(struct b53_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct b53_platform_data); if (!pdata) return -ENOMEM; @@ -421,7 +420,7 @@ static int b53_mmap_probe(struct platform_device *pdev) if (!pdata) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index 29cca7945df719..c4d2a41c714f62 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h @@ -504,6 +504,7 @@ static inline struct gpio_desc *b53_switch_get_reset_gpio(struct b53_device *dev /* Exported functions towards other drivers */ void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port); int b53_configure_vlan(struct dsa_switch *ds); +int b53_enable_mcast_snooping(struct b53_device *dev); void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data); void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data); diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h index 54a278db67c9fd..cfdb5ed3832606 100644 --- a/drivers/net/dsa/b53/b53_regs.h +++ b/drivers/net/dsa/b53/b53_regs.h @@ -274,6 +274,23 @@ /* Revision ID register (8 bit) */ #define B53_REV_ID 0x40 +/* High-level protocol control (16 bit on BCM5395, otherwise 32 bit) */ +#define B53_HL_PRTC_CTRL 0x50 +#define HL_PRTC_ICMPV6_EN BIT(4) +#define HL_PRTC_ICMPV6_FWD_MODE BIT(5) +#define HL_PRTC_IGMP_IP_EN_5395 BIT(6) +#define HL_PRTC_IGMP_FWD_MODE_5395 BIT(8) +#define HL_PRTC_IGMP_RPTLVE_EN BIT(9) +#define HL_PRTC_IGMP_RPTLVE_FWD_MODE BIT(10) +#define HL_PRTC_IGMP_QRY_EN BIT(11) +#define HL_PRTC_IGMP_QRY_FWD_MODE BIT(12) +#define HL_PRTC_IGMP_UKN_EN BIT(13) +#define HL_PRTC_IGMP_UKN_FWD_MODE BIT(14) +#define HL_PRTC_MLD_RPTDONE_EN BIT(15) +#define HL_PRTC_MLD_RPTDONE_FWD_MODE BIT(16) +#define HL_PRTC_MLD_QRY_EN BIT(17) +#define HL_PRTC_MLD_QRY_FWD_MODE BIT(18) + /* Broadcom header RX control (16 bit) */ #define B53_BRCM_HDR_RX_DIS 0x60 diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c index 83a03fca142a02..e6d14fdc56fde2 100644 --- a/drivers/net/dsa/b53/b53_srab.c +++ b/drivers/net/dsa/b53/b53_srab.c @@ -627,14 +627,14 @@ static int b53_srab_probe(struct platform_device *pdev) of_id = of_match_node(b53_srab_of_match, dn); if (of_id) { - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; pdata->chip_id = (u32)(unsigned long)of_id->data; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index 9e5713015187b7..1747a1f20c78e2 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -1059,6 +1059,7 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds) { struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); unsigned int port; + int ret; /* Enable all valid ports and disable those unused */ for (port = 0; port < priv->hw_params.num_ports; port++) { @@ -1074,6 +1075,10 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds) b53_configure_vlan(ds); bcm_sf2_enable_acb(ds); + ret = b53_enable_mcast_snooping(priv->dev); + if (ret) + return ret; + return b53_setup_devlink_resources(ds); } @@ -1379,11 +1384,11 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) u32 reg, rev; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; - ops = devm_kzalloc(&pdev->dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(&pdev->dev, *ops); if (!ops) return -ENOMEM; @@ -1391,7 +1396,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) if (!dev) return -ENOMEM; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c index 0e35e9841b9b26..f10a4951ea8e33 100644 --- a/drivers/net/dsa/dsa_loop.c +++ b/drivers/net/dsa/dsa_loop.c @@ -362,14 +362,14 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev) if (!pdata) return -ENODEV; - ds = devm_kzalloc(&mdiodev->dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(&mdiodev->dev, *ds); if (!ds) return -ENOMEM; ds->dev = &mdiodev->dev; ds->num_ports = DSA_LOOP_NUM_PORTS; - ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL); + ps = devm_kzalloc_obj(&mdiodev->dev, *ps); if (!ps) return -ENOMEM; diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c index aec50414986e7e..3d4bd075eb9809 100644 --- a/drivers/net/dsa/hirschmann/hellcreek.c +++ b/drivers/net/dsa/hirschmann/hellcreek.c @@ -1939,7 +1939,7 @@ static int hellcreek_probe(struct platform_device *pdev) int ret, i; data = of_device_get_match_data(dev); - hellcreek = devm_kzalloc(dev, struct_size(hellcreek, ports, data->num_ports), GFP_KERNEL); + hellcreek = devm_kzalloc_flex(dev, *hellcreek, ports, data->num_ports); if (!hellcreek) return -ENOMEM; @@ -1955,10 +1955,8 @@ static int hellcreek_probe(struct platform_device *pdev) struct hellcreek_port *port = &hellcreek->ports[i]; port->counter_values = - devm_kcalloc(dev, - ARRAY_SIZE(hellcreek_counter), - sizeof(*port->counter_values), - GFP_KERNEL); + devm_kzalloc_objs(dev, *port->counter_values, + ARRAY_SIZE(hellcreek_counter)); if (!port->counter_values) return -ENOMEM; @@ -2014,7 +2012,7 @@ static int hellcreek_probe(struct platform_device *pdev) hellcreek_feature_detect(hellcreek); - hellcreek->ds = devm_kzalloc(dev, sizeof(*hellcreek->ds), GFP_KERNEL); + hellcreek->ds = devm_kzalloc_obj(dev, *hellcreek->ds); if (!hellcreek->ds) return -ENOMEM; diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index d246f95d57ecf8..8eeb8953ff24ee 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -1403,7 +1403,7 @@ static const struct dsa_switch_ops lan9303_switch_ops = { static int lan9303_register_switch(struct lan9303 *chip) { - chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL); + chip->ds = devm_kzalloc_obj(chip->dev, *chip->ds); if (!chip->ds) return -ENOMEM; diff --git a/drivers/net/dsa/lan9303_i2c.c b/drivers/net/dsa/lan9303_i2c.c index 7b70e22371fc40..ba789a044c5216 100644 --- a/drivers/net/dsa/lan9303_i2c.c +++ b/drivers/net/dsa/lan9303_i2c.c @@ -34,8 +34,7 @@ static int lan9303_i2c_probe(struct i2c_client *client) struct lan9303_i2c *sw_dev; int ret; - sw_dev = devm_kzalloc(&client->dev, sizeof(struct lan9303_i2c), - GFP_KERNEL); + sw_dev = devm_kzalloc_obj(&client->dev, struct lan9303_i2c); if (!sw_dev) return -ENOMEM; diff --git a/drivers/net/dsa/lan9303_mdio.c b/drivers/net/dsa/lan9303_mdio.c index d3b5062905b126..9f79e6b8f6032b 100644 --- a/drivers/net/dsa/lan9303_mdio.c +++ b/drivers/net/dsa/lan9303_mdio.c @@ -101,8 +101,7 @@ static int lan9303_mdio_probe(struct mdio_device *mdiodev) struct lan9303_mdio *sw_dev; int ret; - sw_dev = devm_kzalloc(&mdiodev->dev, sizeof(struct lan9303_mdio), - GFP_KERNEL); + sw_dev = devm_kzalloc_obj(&mdiodev->dev, struct lan9303_mdio); if (!sw_dev) return -ENOMEM; diff --git a/drivers/net/dsa/lantiq/lantiq_gswip.c b/drivers/net/dsa/lantiq/lantiq_gswip.c index 4d699d8c16f912..3d52beae01479b 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip.c @@ -277,9 +277,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv, if (IS_ERR(priv->rcu_regmap)) return PTR_ERR(priv->rcu_regmap); - priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw, - sizeof(*priv->gphy_fw), - GFP_KERNEL | __GFP_ZERO); + priv->gphy_fw = devm_kmalloc_objs(dev, *priv->gphy_fw, + priv->num_gphy_fw, + GFP_KERNEL | __GFP_ZERO); if (!priv->gphy_fw) return -ENOMEM; @@ -348,7 +348,7 @@ static int gswip_probe(struct platform_device *pdev) int i; u32 version; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -380,7 +380,7 @@ static int gswip_probe(struct platform_device *pdev) if (!priv->hw_info) return -EINVAL; - priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds = devm_kzalloc_obj(dev, *priv->ds); if (!priv->ds) return -ENOMEM; diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c index 5bb5f4ab4cbfcd..861d9df4ff80bd 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c @@ -1688,7 +1688,7 @@ int gswip_probe_common(struct gswip_priv *priv, u32 version) mutex_init(&priv->pce_table_lock); - priv->ds = devm_kzalloc(priv->dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds = devm_kzalloc_obj(priv->dev, *priv->ds); if (!priv->ds) return -ENOMEM; diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.c b/drivers/net/dsa/lantiq/mxl-gsw1xx.c index a26f78e1a44ce5..0c7ea242a62c20 100644 --- a/drivers/net/dsa/lantiq/mxl-gsw1xx.c +++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.c @@ -725,7 +725,7 @@ static int gsw1xx_probe(struct mdio_device *mdiodev) u16 pnum; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 3c96dd4581cf95..3abaafb9a0746a 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -2503,8 +2503,8 @@ static int ksz8463_setup(struct dsa_switch *ds) regs = dev->info->regs; - dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), - dev->info->num_vlans, GFP_KERNEL); + dev->vlan_cache = devm_kzalloc_objs(dev->dev, struct vlan_table, + dev->info->num_vlans); if (!dev->vlan_cache) return -ENOMEM; @@ -2768,8 +2768,8 @@ static int ksz8_setup(struct dsa_switch *ds) /* KSZ8995XA has no SW controlled VLAN handling */ if (!ksz_is_ksz8995xa(dev)) { - dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), - dev->info->num_vlans, GFP_KERNEL); + dev->vlan_cache = devm_kzalloc_objs(dev->dev, struct vlan_table, + dev->info->num_vlans); if (!dev->vlan_cache) return -ENOMEM; } diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 72528a53b67d2d..8d4647e23cda15 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1678,8 +1678,8 @@ static int ksz9477_setup(struct dsa_switch *ds) regs = dev->info->regs; - dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), - dev->info->num_vlans, GFP_KERNEL); + dev->vlan_cache = devm_kzalloc_objs(dev->dev, struct vlan_table, + dev->info->num_vlans); if (!dev->vlan_cache) return -ENOMEM; diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 767c8fe8e819a5..78af51c182b91d 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3762,7 +3762,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, struct dsa_switch *ds; struct ksz_device *swdev; - ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(base, *ds); if (!ds) return NULL; @@ -3770,7 +3770,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, ds->num_ports = DSA_MAX_PORTS; ds->ops = chip->switch_ops; - swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL); + swdev = devm_kzalloc_obj(base, *swdev); if (!swdev) return NULL; @@ -4023,6 +4023,7 @@ int ksz_switch_register(struct ksz_device *dev) mutex_init(&dev->regmap_mutex); mutex_init(&dev->alu_mutex); mutex_init(&dev->vlan_mutex); + mutex_init(&dev->lock_irq); ret = ksz_switch_detect(dev); if (ret) diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 3a209122fc7dce..f0fb9498026120 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -776,8 +776,8 @@ static int lan937x_setup(struct dsa_switch *ds) regs = dev->info->regs; - dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), - dev->info->num_vlans, GFP_KERNEL); + dev->vlan_cache = devm_kzalloc_objs(dev->dev, struct vlan_table, + dev->info->num_vlans); if (!dev->vlan_cache) return -ENOMEM; diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 33e5fc127244dc..c753c746490a1b 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1405,6 +1405,9 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack) { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct yt921x_port *pp = &priv->ports[port]; + struct net_device *brport_dev; + struct dsa_port *dp; u16 ports_mask; int res; @@ -1414,7 +1417,12 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, ports_mask = dsa_bridge_ports(ds, bridge.dev); ports_mask |= priv->cpu_ports_mask; + dp = dsa_to_port(ds, port); + brport_dev = dsa_port_to_bridge_port(dp); + mutex_lock(&priv->reg_lock); + pp->isolated = br_port_flag_is_set(brport_dev, BR_ISOLATED); + pp->hairpin = br_port_flag_is_set(brport_dev, BR_HAIRPIN_MODE); res = yt921x_bridge_join(priv, port, ports_mask); mutex_unlock(&priv->reg_lock); @@ -2011,7 +2019,7 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port) int res; if (!pm && (BIT(port) & yt921x_info_ports_mask(info))) { - pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL); + pm = devm_kzalloc_obj(dev, *pm); if (!pm) return -ENOMEM; pp->mib = pm; @@ -2617,11 +2625,11 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) struct yt921x_priv *priv; struct dsa_switch *ds; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; - mdio = devm_kzalloc(dev, sizeof(*mdio), GFP_KERNEL); + mdio = devm_kzalloc_obj(dev, *mdio); if (!mdio) return -ENOMEM; diff --git a/drivers/net/dsa/motorcomm/leds.c b/drivers/net/dsa/motorcomm/leds.c index 08fbe86c3334d1..aa68a8793aa25f 100644 --- a/drivers/net/dsa/motorcomm/leds.c +++ b/drivers/net/dsa/motorcomm/leds.c @@ -455,7 +455,7 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, } polarity = force_high ? 1 : force_low ? -1 : 0; - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) { res = -ENOMEM; goto err; diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index 9dbd61e48fee49..e3f057ed580f51 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1030,55 +1030,54 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, const struct flow_rule *rule = flow_cls_offload_flow_rule(cls); const struct flow_action *flow_action = &rule->action; struct netlink_ext_ack *extack = cls->common.extack; - enum flow_action_id redir_act = NUM_FLOW_ACTIONS; const struct flow_action_entry *act; u32 *action = ruleext->r.action; bool seen_priority = false; - const char *reason = NULL; bool seen_police = false; + bool terminal = false; + bool redir = false; + const char *reason; unsigned int i; int res; memset(action, 0, 3 * sizeof(*action)); - flow_action_for_each(i, act, flow_action) + flow_action_for_each(i, act, flow_action) { + /* The flow action entry carries no mirred control, so there + * is no way to tell whether software would continue past a + * redirect and apply the actions after it. Leave the list to + * software instead of guessing a hardware verdict. + */ + if (redir) { + reason = "Action after redirect"; + goto fallback; + } + switch (act->id) { case FLOW_ACTION_ACCEPT: + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_FWD; + terminal = true; + break; case FLOW_ACTION_DROP: - case FLOW_ACTION_REDIRECT: - if (redir_act != NUM_FLOW_ACTIONS && - redir_act != act->id) { - reason = "Different redirect actions"; + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_REDIR; + terminal = true; + break; + case FLOW_ACTION_REDIRECT: { + struct dsa_port *to_dp; + + to_dp = dsa_port_from_netdev(act->dev); + if (IS_ERR(to_dp) || to_dp->ds != &priv->ds) { + reason = "Redirect to non-local port"; goto fallback; } - redir_act = act->id; - - switch (act->id) { - case FLOW_ACTION_ACCEPT: - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_FWD; - break; - case FLOW_ACTION_DROP: - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_REDIR; - break; - case FLOW_ACTION_REDIRECT: { - struct dsa_port *to_dp; - to_dp = dsa_port_from_netdev(act->dev); - if (IS_ERR(to_dp) || to_dp->ds != &priv->ds) { - reason = "Redirect to non-local port"; - goto fallback; - } - - action[2] |= YT921X_ACL_ACTc_FWD_EN | - YT921X_ACL_ACTc_FWD_REDIR | - YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index); - break; - } - default: - break; - } + action[2] |= YT921X_ACL_ACTc_FWD_EN | + YT921X_ACL_ACTc_FWD_REDIR | + YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index); + redir = true; break; + } case FLOW_ACTION_PRIORITY: if (seen_priority) { action[0] &= ~YT921X_ACL_ACTa_PRIO_EN; @@ -1122,6 +1121,7 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, break; } default: + reason = "Unsupported by HW"; fallback: if (cls->common.skip_sw) { NL_SET_ERR_MSG_FMT_MOD(extack, @@ -1131,15 +1131,18 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, } fallthrough; case FLOW_ACTION_TRAP: - redir_act = FLOW_ACTION_TRAP; - action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & ~YT921X_ACL_ACTc_FWD_M; action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_TRAP; + terminal = true; break; } + if (terminal) + break; + } + ruleext->r.sw_assisted = !cls->common.skip_sw; return 0; } @@ -1223,7 +1226,7 @@ static u16 yt921x_acl_activated_ports(const struct yt921x_priv *priv) static unsigned int yt921x_acl_find(const struct yt921x_priv *priv, enum tc_setup_type type, - unsigned long tag) + unsigned long tag, u16 ports_mask) { for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) { const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid]; @@ -1233,7 +1236,10 @@ yt921x_acl_find(const struct yt921x_priv *priv, enum tc_setup_type type, for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) if (aclblk->rules[i] && aclblk->rules[i]->tag == tag && - aclblk->rules[i]->type == type) + aclblk->rules[i]->type == type && + FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, + aclblk->rules[i]->entries[0].key[1]) == + ports_mask) return YT921X_ACL_ENT_PER_BLK * blkid + i; } @@ -1361,7 +1367,7 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) static int yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, - unsigned long tag) + unsigned long tag, u16 ports_mask) { struct yt921x_acl_rule *aclrule; struct yt921x_acl_blk *aclblk; @@ -1375,7 +1381,7 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, int res; int ret; - entid = yt921x_acl_find(priv, type, tag); + entid = yt921x_acl_find(priv, type, tag, ports_mask); if (entid == UINT_MAX) return -ENOENT; @@ -1550,7 +1556,7 @@ yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, int res; mutex_lock(&priv->reg_lock); - res = yt921x_acl_del(priv, TC_SETUP_CLSFLOWER, cls->cookie); + res = yt921x_acl_del(priv, TC_SETUP_CLSFLOWER, cls->cookie, BIT(port)); mutex_unlock(&priv->reg_lock); return res; diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index 0be107dc6759a0..e85ef2aceee56d 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -99,9 +99,8 @@ mt7531_create_sgmii(struct mt7530_priv *priv) int i, ret = 0; for (i = priv->p5_sgmii ? 0 : 1; i < 2; i++) { - mt7531_pcs_config[i] = devm_kzalloc(priv->dev, - sizeof(struct regmap_config), - GFP_KERNEL); + mt7531_pcs_config[i] = devm_kzalloc_obj(priv->dev, + struct regmap_config); if (!mt7531_pcs_config[i]) { ret = -ENOMEM; break; @@ -165,7 +164,7 @@ mt7530_probe(struct mdio_device *mdiodev) dn = mdiodev->dev.of_node; - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&mdiodev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c index cf3bdb23a2d546..5d467be2a32c87 100644 --- a/drivers/net/dsa/mt7530-mmio.c +++ b/drivers/net/dsa/mt7530-mmio.c @@ -33,7 +33,7 @@ mt7988_probe(struct platform_device *pdev) void __iomem *base_addr; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index d4714bc102ee6d..d5a199293f78aa 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2201,7 +2201,7 @@ mt7530_setup_gpio(struct mt7530_priv *priv) struct device *dev = priv->dev; struct gpio_chip *gc; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; @@ -3532,7 +3532,7 @@ mt7530_probe_common(struct mt7530_priv *priv) { struct device *dev = priv->dev; - priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds = devm_kzalloc_obj(dev, *priv->ds); if (!priv->ds) return -ENOMEM; diff --git a/drivers/net/dsa/mt7628.c b/drivers/net/dsa/mt7628.c index fb63f6f644b9ec..75665879309748 100644 --- a/drivers/net/dsa/mt7628.c +++ b/drivers/net/dsa/mt7628.c @@ -569,11 +569,11 @@ static int mt7628_probe(struct platform_device *pdev) struct dsa_switch *ds; void __iomem *base; - ds = devm_kzalloc(&pdev->dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(&pdev->dev, *ds); if (!ds) return -ENOMEM; - esw = devm_kzalloc(&pdev->dev, sizeof(*esw), GFP_KERNEL); + esw = devm_kzalloc_obj(&pdev->dev, *esw); if (!esw) return -ENOMEM; diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index 3bb485a9042990..7939d5291e8b64 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c @@ -308,7 +308,7 @@ static int mv88e6060_probe(struct mdio_device *mdiodev) struct dsa_switch *ds; const char *name; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -321,7 +321,7 @@ static int mv88e6060_probe(struct mdio_device *mdiodev) dev_info(dev, "switch %s detected\n", name); - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 46aef6dfe77e27..425fd2d22c289e 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2403,7 +2403,7 @@ static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port, return -EEXIST; } - policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL); + policy = devm_kzalloc_obj(chip->dev, *policy); if (!policy) return -ENOMEM; @@ -6697,7 +6697,7 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev) { struct mv88e6xxx_chip *chip; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return NULL; @@ -7322,7 +7322,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) struct device *dev = chip->dev; struct dsa_switch *ds; - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; diff --git a/drivers/net/dsa/mv88e6xxx/devlink.c b/drivers/net/dsa/mv88e6xxx/devlink.c index 6f034841883c6f..124f9865a99fc2 100644 --- a/drivers/net/dsa/mv88e6xxx/devlink.c +++ b/drivers/net/dsa/mv88e6xxx/devlink.c @@ -273,7 +273,7 @@ static int mv88e6xxx_region_global_snapshot(struct devlink *dl, u16 *registers; int i, err; - registers = kmalloc_array(32, sizeof(u16), GFP_KERNEL); + registers = kmalloc_objs(u16, 32); if (!registers) return -ENOMEM; @@ -578,7 +578,7 @@ static int mv88e6xxx_region_pvt_snapshot(struct devlink *dl, int dev, port, err; u16 *pvt, *cur; - pvt = kcalloc(MV88E6XXX_MAX_PVT_ENTRIES, sizeof(*pvt), GFP_KERNEL); + pvt = kzalloc_objs(*pvt, MV88E6XXX_MAX_PVT_ENTRIES); if (!pvt) return -ENOMEM; @@ -617,7 +617,7 @@ static int mv88e6xxx_region_port_snapshot(struct devlink_port *devlink_port, u16 *registers; int i, err; - registers = kmalloc_array(32, sizeof(u16), GFP_KERNEL); + registers = kmalloc_objs(u16, 32); if (!registers) return -ENOMEM; diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx/mxl862xx.c index e05ad52cd297e2..da6185963a0d59 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c @@ -2106,13 +2106,13 @@ static int mxl862xx_probe(struct mdio_device *mdiodev) struct dsa_switch *ds; int err, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->mdiodev = mdiodev; - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c index 77077352c1a576..1225ff8153d443 100644 --- a/drivers/net/dsa/netc/netc_main.c +++ b/drivers/net/dsa/netc/netc_main.c @@ -246,9 +246,8 @@ static int netc_init_all_ports(struct netc_switch *priv) int ett_offset = 0; int err; - priv->ports = devm_kcalloc(dev, priv->info->num_ports, - sizeof(struct netc_port *), - GFP_KERNEL); + priv->ports = devm_kzalloc_objs(dev, struct netc_port *, + priv->info->num_ports); if (!priv->ports) return -ENOMEM; @@ -260,7 +259,7 @@ static int netc_init_all_ports(struct netc_switch *priv) * difficult for us to cover. */ for (int i = 0; i < priv->info->num_ports; i++) { - np = devm_kzalloc(dev, sizeof(*np), GFP_KERNEL); + np = devm_kzalloc_obj(dev, *np); if (!np) return -ENOMEM; @@ -308,9 +307,8 @@ static int netc_init_all_cbdrs(struct netc_switch *priv) ntmp->cbdr_num = NETC_CBDR_NUM; ntmp->dev = priv->dev; - ntmp->ring = devm_kcalloc(ntmp->dev, ntmp->cbdr_num, - sizeof(struct netc_cbdr), - GFP_KERNEL); + ntmp->ring = devm_kzalloc_objs(ntmp->dev, struct netc_cbdr, + ntmp->cbdr_num); if (!ntmp->ring) return -ENOMEM; @@ -847,9 +845,8 @@ static int netc_switch_bpt_default_config(struct netc_switch *priv) if (priv->num_bp < priv->info->num_ports) return -EINVAL; - priv->bpt_list = devm_kcalloc(priv->dev, priv->num_bp, - sizeof(struct bpt_cfge_data), - GFP_KERNEL); + priv->bpt_list = devm_kzalloc_objs(priv->dev, struct bpt_cfge_data, + priv->num_bp); if (!priv->bpt_list) return -ENOMEM; @@ -1071,7 +1068,7 @@ static int netc_switch_pci_init(struct pci_dev *pdev) pci_set_master(pdev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -2460,7 +2457,7 @@ static int netc_switch_probe(struct pci_dev *pdev, if (err) return err; - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 84a95007825f75..c99fd3d23bb3f1 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -1522,8 +1522,8 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports) int port, i, err; ocelot->num_phys_ports = num_phys_ports; - ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, - sizeof(struct ocelot_port *), GFP_KERNEL); + ocelot->ports = devm_kzalloc_objs(ocelot->dev, struct ocelot_port *, + num_phys_ports); if (!ocelot->ports) return -ENOMEM; @@ -1572,9 +1572,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports) for (port = 0; port < num_phys_ports; port++) { struct ocelot_port *ocelot_port; - ocelot_port = devm_kzalloc(ocelot->dev, - sizeof(struct ocelot_port), - GFP_KERNEL); + ocelot_port = devm_kzalloc_obj(ocelot->dev, struct ocelot_port); if (!ocelot_port) { dev_err(ocelot->dev, "failed to allocate port memory\n"); @@ -2398,11 +2396,11 @@ int felix_register_switch(struct device *dev, resource_size_t switch_base, struct felix *felix; int err; - felix = devm_kzalloc(dev, sizeof(*felix), GFP_KERNEL); + felix = devm_kzalloc_obj(dev, *felix); if (!felix) return -ENOMEM; - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c index 8387dd208adb9b..21f3c75b2e7b8a 100644 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c @@ -968,9 +968,8 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) int port; int rc; - felix->pcs = devm_kcalloc(dev, felix->info->num_ports, - sizeof(struct phylink_pcs *), - GFP_KERNEL); + felix->pcs = devm_kzalloc_objs(dev, struct phylink_pcs *, + felix->info->num_ports); if (!felix->pcs) { dev_err(dev, "failed to allocate array for PCS PHYs\n"); return -ENOMEM; diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c index 962cf4653c3646..708ddf759f626c 100644 --- a/drivers/net/dsa/ocelot/seville_vsc9953.c +++ b/drivers/net/dsa/ocelot/seville_vsc9953.c @@ -883,9 +883,8 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot) int port; int rc; - felix->pcs = devm_kcalloc(dev, felix->info->num_ports, - sizeof(struct phylink_pcs *), - GFP_KERNEL); + felix->pcs = devm_kzalloc_objs(dev, struct phylink_pcs *, + felix->info->num_ports); if (!felix->pcs) { dev_err(dev, "failed to allocate array for PCS PHYs\n"); return -ENOMEM; diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c index 0526aa96146e7e..0222cba5b36703 100644 --- a/drivers/net/dsa/qca/ar9331.c +++ b/drivers/net/dsa/qca/ar9331.c @@ -1034,7 +1034,7 @@ static int ar9331_sw_probe(struct mdio_device *mdiodev) struct dsa_switch *ds; int ret, i; - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&mdiodev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 07227ae8bc040c..382753bcc466a3 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -2076,7 +2076,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) /* allocate the private data struct so that we can probe the switches * ID register */ - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&mdiodev->dev, *priv); if (!priv) return -ENOMEM; @@ -2112,7 +2112,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) if (ret) return ret; - priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds = devm_kzalloc_obj(&mdiodev->dev, *priv->ds); if (!priv->ds) return -ENOMEM; diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c index 85ff1fd2bbfbaa..13c46cf2c4207f 100644 --- a/drivers/net/dsa/rzn1_a5psw.c +++ b/drivers/net/dsa/rzn1_a5psw.c @@ -1212,7 +1212,7 @@ static int a5psw_probe(struct platform_device *pdev) struct a5psw *a5psw; int ret; - a5psw = devm_kzalloc(dev, sizeof(*a5psw), GFP_KERNEL); + a5psw = devm_kzalloc_obj(dev, *a5psw); if (!a5psw) return -ENOMEM; diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 8984ed55ad594f..06be555b083511 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3251,7 +3251,7 @@ static int sja1105_probe(struct spi_device *spi) if (rc) return rc; - priv = devm_kzalloc(dev, sizeof(struct sja1105_private), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct sja1105_private); if (!priv) return -ENOMEM; @@ -3307,7 +3307,7 @@ static int sja1105_probe(struct spi_device *spi) dev_info(dev, "Probed switch chip: %s\n", priv->info->name); - ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(dev, *ds); if (!ds) return -ENOMEM; @@ -3331,9 +3331,8 @@ static int sja1105_probe(struct spi_device *spi) } if (IS_ENABLED(CONFIG_NET_SCH_CBS)) { - priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers, - sizeof(struct sja1105_cbs_entry), - GFP_KERNEL); + priv->cbs = devm_kzalloc_objs(dev, struct sja1105_cbs_entry, + priv->info->num_cbs_shapers); if (!priv->cbs) return -ENOMEM; } diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 6f586d3da9d4c9..35943787f37d86 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -2372,7 +2372,7 @@ int vsc73xx_probe(struct vsc73xx *vsc) vsc->addr[0], vsc->addr[1], vsc->addr[2], vsc->addr[3], vsc->addr[4], vsc->addr[5]); - vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL); + vsc->ds = devm_kzalloc_obj(dev, *vsc->ds); if (!vsc->ds) return -ENOMEM; diff --git a/drivers/net/dsa/vitesse-vsc73xx-platform.c b/drivers/net/dsa/vitesse-vsc73xx-platform.c index 7a2e0a619b85ad..96e00a499248fb 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-platform.c +++ b/drivers/net/dsa/vitesse-vsc73xx-platform.c @@ -91,7 +91,7 @@ static int vsc73xx_platform_probe(struct platform_device *pdev) struct vsc73xx_platform *vsc_platform; int ret; - vsc_platform = devm_kzalloc(dev, sizeof(*vsc_platform), GFP_KERNEL); + vsc_platform = devm_kzalloc_obj(dev, *vsc_platform); if (!vsc_platform) return -ENOMEM; diff --git a/drivers/net/dsa/vitesse-vsc73xx-spi.c b/drivers/net/dsa/vitesse-vsc73xx-spi.c index 7b784320c41e7a..534a67fa4e5b1e 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-spi.c +++ b/drivers/net/dsa/vitesse-vsc73xx-spi.c @@ -137,7 +137,7 @@ static int vsc73xx_spi_probe(struct spi_device *spi) struct vsc73xx_spi *vsc_spi; int ret; - vsc_spi = devm_kzalloc(dev, sizeof(*vsc_spi), GFP_KERNEL); + vsc_spi = devm_kzalloc_obj(dev, *vsc_spi); if (!vsc_spi) return -ENOMEM; diff --git a/drivers/net/dsa/xrs700x/xrs700x.c b/drivers/net/dsa/xrs700x/xrs700x.c index 0a05f4156ef4d7..90f1cd2b5ab5d4 100644 --- a/drivers/net/dsa/xrs700x/xrs700x.c +++ b/drivers/net/dsa/xrs700x/xrs700x.c @@ -776,13 +776,13 @@ struct xrs700x *xrs700x_switch_alloc(struct device *base, void *devpriv) struct dsa_switch *ds; struct xrs700x *priv; - ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); + ds = devm_kzalloc_obj(base, *ds); if (!ds) return NULL; ds->dev = base; - priv = devm_kzalloc(base, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(base, *priv); if (!priv) return NULL; @@ -804,8 +804,8 @@ static int xrs700x_alloc_port_mib(struct xrs700x *priv, int port) { struct xrs700x_port *p = &priv->ports[port]; - p->mib_data = devm_kcalloc(priv->dev, ARRAY_SIZE(xrs700x_mibs), - sizeof(*p->mib_data), GFP_KERNEL); + p->mib_data = devm_kzalloc_objs(priv->dev, *p->mib_data, + ARRAY_SIZE(xrs700x_mibs)); if (!p->mib_data) return -ENOMEM; @@ -828,8 +828,8 @@ int xrs700x_switch_register(struct xrs700x *priv) if (ret) return ret; - priv->ports = devm_kcalloc(priv->dev, priv->ds->num_ports, - sizeof(*priv->ports), GFP_KERNEL); + priv->ports = devm_kzalloc_objs(priv->dev, *priv->ports, + priv->ds->num_ports); if (!priv->ports) return -ENOMEM; diff --git a/drivers/net/ethernet/actions/owl-emac.c b/drivers/net/ethernet/actions/owl-emac.c index 2538275a1e5765..b8f3040b9b4162 100644 --- a/drivers/net/ethernet/actions/owl-emac.c +++ b/drivers/net/ethernet/actions/owl-emac.c @@ -285,13 +285,11 @@ static int owl_emac_ring_alloc(struct device *dev, struct owl_emac_ring *ring, if (!ring->descs) return -ENOMEM; - ring->skbs = devm_kcalloc(dev, size, sizeof(struct sk_buff *), - GFP_KERNEL); + ring->skbs = devm_kzalloc_objs(dev, struct sk_buff *, size); if (!ring->skbs) return -ENOMEM; - ring->skbs_dma = devm_kcalloc(dev, size, sizeof(dma_addr_t), - GFP_KERNEL); + ring->skbs_dma = devm_kzalloc_objs(dev, dma_addr_t, size); if (!ring->skbs_dma) return -ENOMEM; diff --git a/drivers/net/ethernet/adi/adin1110.c b/drivers/net/ethernet/adi/adin1110.c index 53fac3dc8be62e..f4540477d527e0 100644 --- a/drivers/net/ethernet/adi/adin1110.c +++ b/drivers/net/ethernet/adi/adin1110.c @@ -1651,7 +1651,7 @@ static int adin1110_probe(struct spi_device *spi) struct adin1110_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(struct adin1110_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct adin1110_priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c index b164a78ddac9dc..044ad0302ef359 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.c +++ b/drivers/net/ethernet/airoha/airoha_eth.c @@ -3845,7 +3845,7 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth, return -EINVAL; } - port = devm_kzalloc(eth->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(eth->dev, *port); if (!port) return -ENOMEM; @@ -3934,7 +3934,7 @@ static int airoha_probe(struct platform_device *pdev) struct airoha_eth *eth; int i, err; - eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL); + eth = devm_kzalloc_obj(&pdev->dev, *eth); if (!eth) return -ENOMEM; @@ -3966,9 +3966,8 @@ static int airoha_probe(struct platform_device *pdev) return err; } - xsi_rsts = devm_kcalloc(eth->dev, - eth->soc->num_xsi_rsts, sizeof(*xsi_rsts), - GFP_KERNEL); + xsi_rsts = devm_kzalloc_objs(eth->dev, *xsi_rsts, + eth->soc->num_xsi_rsts); if (!xsi_rsts) return -ENOMEM; diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c index 4d3195eb00f7ae..edec6b11189561 100644 --- a/drivers/net/ethernet/airoha/airoha_npu.c +++ b/drivers/net/ethernet/airoha/airoha_npu.c @@ -706,7 +706,7 @@ static int airoha_npu_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - npu = devm_kzalloc(dev, sizeof(*npu), GFP_KERNEL); + npu = devm_kzalloc_obj(dev, *npu); if (!npu) return -ENOMEM; diff --git a/drivers/net/ethernet/airoha/airoha_ppe.c b/drivers/net/ethernet/airoha/airoha_ppe.c index 92611802801ea1..f5369c45766d28 100644 --- a/drivers/net/ethernet/airoha/airoha_ppe.c +++ b/drivers/net/ethernet/airoha/airoha_ppe.c @@ -1599,7 +1599,7 @@ int airoha_ppe_init(struct airoha_eth *eth) u32 ppe_num_entries; struct airoha_ppe *ppe; - ppe = devm_kzalloc(eth->dev, sizeof(*ppe), GFP_KERNEL); + ppe = devm_kzalloc_obj(eth->dev, *ppe); if (!ppe) return -ENOMEM; diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c index 2455d6dddc2672..e441ed6a8d35a1 100644 --- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c +++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c @@ -1120,7 +1120,7 @@ static void ena_dump_stats_ex(struct ena_adapter *adapter, u8 *buf) return; } - data_buf = kcalloc(strings_num, sizeof(u64), GFP_ATOMIC); + data_buf = kzalloc_objs(u64, strings_num, GFP_ATOMIC); if (!data_buf) { netif_err(adapter, drv, netdev, "Failed to allocate data buf\n"); diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 7eb6456ed0d556..ecc6f1d827f9cf 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -986,7 +986,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, page_offset = rx_info->page_offset; buf_addr = page_address(rx_info->page) + page_offset; - if (len <= rx_ring->rx_copybreak) { + if (len <= rx_ring->rx_copybreak && likely(descs == 1)) { skb = ena_alloc_skb(rx_ring, NULL, len); if (unlikely(!skb)) return NULL; @@ -1009,6 +1009,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, buf_len = SKB_DATA_ALIGN(len + buf_offset + tailroom); + skb = ena_alloc_skb(rx_ring, buf_addr, buf_len); + if (unlikely(!skb)) + return NULL; + /* If XDP isn't loaded try to reuse part of the RX buffer */ reuse_rx_buf_page = !is_xdp_loaded && ena_try_rx_buf_page_reuse(rx_info, buf_len, len, pkt_offset); @@ -1016,10 +1020,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, if (!reuse_rx_buf_page) ena_unmap_rx_buff_attrs(rx_ring, rx_info, DMA_ATTR_SKIP_CPU_SYNC); - skb = ena_alloc_skb(rx_ring, buf_addr, buf_len); - if (unlikely(!skb)) - return NULL; - /* Populate skb's linear part */ skb_reserve(skb, buf_offset); skb_put(skb, len); @@ -1293,7 +1293,8 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi, skb_record_rx_queue(skb, rx_ring->qid); - if (rx_ring->ena_bufs[0].len <= rx_ring->rx_copybreak) + if (rx_ring->ena_bufs[0].len <= rx_ring->rx_copybreak && + ena_rx_ctx.descs == 1) rx_copybreak_pkt++; total_len += skb->len; diff --git a/drivers/net/ethernet/amd/pds_core/debugfs.c b/drivers/net/ethernet/amd/pds_core/debugfs.c index ef0a1b7d159b5d..a27c44aa8f2c90 100644 --- a/drivers/net/ethernet/amd/pds_core/debugfs.c +++ b/drivers/net/ethernet/amd/pds_core/debugfs.c @@ -159,9 +159,8 @@ void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) debugfs_create_u32("index", 0400, intr_dentry, &intr->index); debugfs_create_u32("vector", 0400, intr_dentry, &intr->vector); - intr_ctrl_regset = devm_kzalloc(pdsc->dev, - sizeof(*intr_ctrl_regset), - GFP_KERNEL); + intr_ctrl_regset = devm_kzalloc_obj(pdsc->dev, + *intr_ctrl_regset); if (!intr_ctrl_regset) return; intr_ctrl_regset->regs = intr_ctrl_regs; diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c index 1474df5544fab4..dc2ef2e0ae1504 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c @@ -84,8 +84,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev, } if (!pdata->ets) { - pdata->ets = devm_kzalloc(pdata->dev, sizeof(*pdata->ets), - GFP_KERNEL); + pdata->ets = devm_kzalloc_obj(pdata->dev, *pdata->ets); if (!pdata->ets) return -ENOMEM; } @@ -132,8 +131,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev, } if (!pdata->pfc) { - pdata->pfc = devm_kzalloc(pdata->dev, sizeof(*pdata->pfc), - GFP_KERNEL); + pdata->pfc = devm_kzalloc_obj(pdata->dev, *pdata->pfc); if (!pdata->pfc) return -ENOMEM; } diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v1.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v1.c index 2e6b8ffe785cb9..ee18f30948a8a0 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v1.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v1.c @@ -572,7 +572,7 @@ static int xgbe_phy_init(struct xgbe_prv_data *pdata) struct xgbe_phy_data *phy_data; int ret; - phy_data = devm_kzalloc(pdata->dev, sizeof(*phy_data), GFP_KERNEL); + phy_data = devm_kzalloc_obj(pdata->dev, *phy_data); if (!phy_data) return -ENOMEM; diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c index 59a074ed312a53..0a3cd65d1430ed 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c @@ -3443,7 +3443,7 @@ static int xgbe_phy_init(struct xgbe_prv_data *pdata) if (ret) return ret; - phy_data = devm_kzalloc(pdata->dev, sizeof(*phy_data), GFP_KERNEL); + phy_data = devm_kzalloc_obj(pdata->dev, *phy_data); if (!phy_data) return -ENOMEM; pdata->phy_data = phy_data; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c b/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c index ada70425b48cbd..0e9763d1b89360 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c @@ -249,8 +249,8 @@ static void xgene_get_extd_stats(struct xgene_enet_pdata *pdata) int xgene_extd_stats_init(struct xgene_enet_pdata *pdata) { - pdata->extd_stats = devm_kmalloc_array(&pdata->pdev->dev, - XGENE_EXTD_STATS_LEN, sizeof(u64), GFP_KERNEL); + pdata->extd_stats = devm_kmalloc_objs(&pdata->pdev->dev, u64, + XGENE_EXTD_STATS_LEN); if (!pdata->extd_stats) return -ENOMEM; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index 2ddcbf27014eed..35ea9a024736ce 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c @@ -1225,8 +1225,7 @@ static struct xgene_enet_desc_ring *xgene_enet_create_desc_ring( if (size < 0) return NULL; - ring = devm_kzalloc(dev, sizeof(struct xgene_enet_desc_ring), - GFP_KERNEL); + ring = devm_kzalloc_obj(dev, struct xgene_enet_desc_ring); if (!ring) return NULL; @@ -1347,9 +1346,8 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev) rx_ring->nbufpool = NUM_BUFPOOL; rx_ring->npagepool = NUM_NXTBUFPOOL; rx_ring->irq = pdata->irqs[i]; - buf_pool->rx_skb = devm_kcalloc(dev, buf_pool->slots, - sizeof(struct sk_buff *), - GFP_KERNEL); + buf_pool->rx_skb = devm_kzalloc_objs(dev, struct sk_buff *, + buf_pool->slots); if (!buf_pool->rx_skb) { ret = -ENOMEM; goto err; @@ -1376,17 +1374,15 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev) } slots = page_pool->slots; - page_pool->frag_page = devm_kcalloc(dev, slots, - sizeof(struct page *), - GFP_KERNEL); + page_pool->frag_page = devm_kzalloc_objs(dev, struct page *, + slots); if (!page_pool->frag_page) { ret = -ENOMEM; goto err; } - page_pool->frag_dma_addr = devm_kcalloc(dev, slots, - sizeof(dma_addr_t), - GFP_KERNEL); + page_pool->frag_dma_addr = devm_kzalloc_objs(dev, dma_addr_t, + slots); if (!page_pool->frag_dma_addr) { ret = -ENOMEM; goto err; @@ -1437,9 +1433,8 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev) cp_ring->index = i; } - cp_ring->cp_skb = devm_kcalloc(dev, tx_ring->slots, - sizeof(struct sk_buff *), - GFP_KERNEL); + cp_ring->cp_skb = devm_kzalloc_objs(dev, struct sk_buff *, + tx_ring->slots); if (!cp_ring->cp_skb) { ret = -ENOMEM; goto err; diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_ethtool.c b/drivers/net/ethernet/atheros/atl1c/atl1c_ethtool.c index 0bce122c68f1d6..91fedc8a525268 100644 --- a/drivers/net/ethernet/atheros/atl1c/atl1c_ethtool.c +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_ethtool.c @@ -195,8 +195,7 @@ static int atl1c_get_eeprom(struct net_device *netdev, first_dword = eeprom->offset >> 2; last_dword = (eeprom->offset + eeprom->len - 1) >> 2; - eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u32, last_dword - first_dword + 1); if (eeprom_buff == NULL) return -ENOMEM; diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c index e58f1d2c26bdfd..eddd8406867f75 100644 --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c @@ -1934,6 +1934,39 @@ static int atl1c_clean_rx(struct napi_struct *napi, int budget) break; } atl1c_clean_rfd(rfd_ring, rrs, rfd_num); + + /* A link partner whose l2mtu is larger than ours can hand us a + * frame that does not fit the buffer the hardware was given: + * the descriptor reports the untruncated length while at most + * buffer_info->length bytes were written. skb_put() of such a + * length would pull in whatever the tail of the buffer holds + * and, past the end of the skb, trips skb_over_panic and takes + * the host down. Bound it by what the device actually wrote + * rather than by skb_tailroom(): the skb carries 64 bytes of + * slack for the DMA erratum, so the two are not the same. + * + * Frames shorter than an Ethernet header plus its FCS are + * rejected by the same test; before this, a length below + * ETH_FCS_LEN underflowed in skb_put(). + */ + if (unlikely(length < ETH_HLEN + ETH_FCS_LEN || + length > buffer_info->length)) { + dev_core_stats_rx_dropped_inc(netdev); + if (netif_msg_rx_err(adapter)) + dev_warn_ratelimited(&pdev->dev, + "dropped rx frame: %u bytes, buffer %u\n", + length, buffer_info->length); + kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG); + /* atl1c_clean_rfd() has already recycled the RFD, so + * count the drop as work: the refill at the end of the + * poll only runs when work_done is non-zero, and + * sustained oversized traffic would otherwise drain the + * ring and stop RX for good. + */ + work_done++; + continue; + } + skb_put(skb, length - ETH_FCS_LEN); skb->protocol = eth_type_trans(skb, netdev); atl1c_rx_checksum(adapter, skb, rrs); diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_ethtool.c b/drivers/net/ethernet/atheros/atl1e/atl1e_ethtool.c index 68f1832a198dd1..28728e92642c19 100644 --- a/drivers/net/ethernet/atheros/atl1e/atl1e_ethtool.c +++ b/drivers/net/ethernet/atheros/atl1e/atl1e_ethtool.c @@ -222,8 +222,7 @@ static int atl1e_get_eeprom(struct net_device *netdev, first_dword = eeprom->offset >> 2; last_dword = (eeprom->offset + eeprom->len - 1) >> 2; - eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u32, last_dword - first_dword + 1); if (eeprom_buff == NULL) return -ENOMEM; diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c index 5d3b3357d53df3..bb6b0f3363d4c9 100644 --- a/drivers/net/ethernet/atheros/atlx/atl2.c +++ b/drivers/net/ethernet/atheros/atlx/atl2.c @@ -1896,8 +1896,7 @@ static int atl2_get_eeprom(struct net_device *netdev, first_dword = eeprom->offset >> 2; last_dword = (eeprom->offset + eeprom->len - 1) >> 2; - eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u32, last_dword - first_dword + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 1da0b04f59d7d5..a59a006cea3a73 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -1260,7 +1260,7 @@ static int bcmasp_probe(struct platform_device *pdev) int ret = 0, count = 0; unsigned int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -1324,15 +1324,15 @@ static int bcmasp_probe(struct platform_device *pdev) */ bcmasp_core_init(priv); - priv->mda_filters = devm_kcalloc(dev, priv->num_mda_filters, - sizeof(*priv->mda_filters), GFP_KERNEL); + priv->mda_filters = devm_kzalloc_objs(dev, *priv->mda_filters, + priv->num_mda_filters); if (!priv->mda_filters) { ret = -ENOMEM; goto err_clock_disable; } - priv->net_filters = devm_kcalloc(dev, priv->num_net_filters, - sizeof(*priv->net_filters), GFP_KERNEL); + priv->net_filters = devm_kzalloc_objs(dev, *priv->net_filters, + priv->num_net_filters); if (!priv->net_filters) { ret = -ENOMEM; goto err_clock_disable; diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c index 2b2e8a7e8061a5..bc88a27da16bee 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2490,9 +2490,8 @@ static int bcm_sysport_probe(struct platform_device *pdev) } /* Allocate number of TX rings */ - priv->tx_rings = devm_kcalloc(&pdev->dev, txq, - sizeof(struct bcm_sysport_tx_ring), - GFP_KERNEL); + priv->tx_rings = devm_kzalloc_objs(&pdev->dev, + struct bcm_sysport_tx_ring, txq); if (!priv->tx_rings) { ret = -ENOMEM; goto err_free_netdev; diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c index 4e266ce41180b3..4880b18904812e 100644 --- a/drivers/net/ethernet/broadcom/bgmac-platform.c +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c @@ -243,7 +243,8 @@ static int bgmac_probe(struct platform_device *pdev) bgmac->phy_connect = platform_phy_connect; } else { bgmac->phy_connect = bgmac_phy_connect_direct; - bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; + if (of_machine_is_compatible("brcm,nsp")) + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; } return bgmac_enet_probe(bgmac); diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c index 669eb7ce7d40b8..9ef7307edd41ec 100644 --- a/drivers/net/ethernet/broadcom/bgmac.c +++ b/drivers/net/ethernet/broadcom/bgmac.c @@ -1430,11 +1430,15 @@ void bgmac_adjust_link(struct net_device *net_dev) { struct bgmac *bgmac = netdev_priv(net_dev); struct phy_device *phy_dev = net_dev->phydev; + int speed = phy_dev->speed; bool update = false; + if (bgmac->feature_flags & BGMAC_FEAT_FORCE_SPEED_2500) + speed = SPEED_2500; + if (phy_dev->link) { - if (phy_dev->speed != bgmac->mac_speed) { - bgmac->mac_speed = phy_dev->speed; + if (speed != bgmac->mac_speed) { + bgmac->mac_speed = speed; update = true; } diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c index 65ef34536e36f0..fdef2a52124ced 100644 --- a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c +++ b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c @@ -575,7 +575,7 @@ static int bnge_alloc_rss_indir_tbl(struct bnge_dev *bd) bd->rss_indir_tbl_entries = entries; bd->rss_indir_tbl = - kmalloc_array(entries, sizeof(*bd->rss_indir_tbl), GFP_KERNEL); + kmalloc_objs(*bd->rss_indir_tbl, entries); if (!bd->rss_indir_tbl) return -ENOMEM; diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index 3e2fd2939e8785..39a62d5c166106 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -2677,7 +2677,7 @@ bnx2_alloc_bad_rbuf(struct bnx2 *bp) u32 good_mbuf_cnt; u32 val; - good_mbuf = kmalloc_array(512, sizeof(u16), GFP_KERNEL); + good_mbuf = kmalloc_objs(u16, 512); if (!good_mbuf) return -ENOMEM; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 757c7266ce15d6..6846a27bfef4c0 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -5140,7 +5140,7 @@ static int bnxt_alloc_vnic_attributes(struct bnxt *bp) else max_rings = 1; - vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL); + vnic->fw_grp_ids = kzalloc_objs(u16, max_rings); if (!vnic->fw_grp_ids) { rc = -ENOMEM; goto out; @@ -5690,8 +5690,7 @@ static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init) if (!bp->tx_ring) return -ENOMEM; - bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16), - GFP_KERNEL); + bp->tx_ring_map = kzalloc_objs(u16, bp->tx_nr_rings); if (!bp->tx_ring_map) return -ENOMEM; @@ -6692,7 +6691,7 @@ static int bnxt_alloc_rss_indir_tbl(struct bnxt *bp) bp->rss_indir_tbl_entries = entries; bp->rss_indir_tbl = - kmalloc_array(entries, sizeof(*bp->rss_indir_tbl), GFP_KERNEL); + kmalloc_objs(*bp->rss_indir_tbl, entries); if (!bp->rss_indir_tbl) return -ENOMEM; @@ -11544,6 +11543,7 @@ static int bnxt_change_msix(struct bnxt *bp, int total) map.index = i - 1; map.virq = bp->irq_tbl[i - 1].vector; pci_msix_free_irq(bp->pdev, map); + bp->irq_tbl[i - 1].vector = 0; bp->total_irqs--; } return bp->total_irqs; @@ -11721,8 +11721,23 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) int irqs_required; int rc; - if (!bnxt_need_reserve_rings(bp)) + if (!bnxt_need_reserve_rings(bp)) { + /* FW may already hold the reservation from an earlier + * reservation that was not followed by growing the dynamic + * MSI-X vectors, e.g. because the allocation failed. + */ + if (irq_re_init && BNXT_NEW_RM(bp) && bp->irq_tbl && + pci_msix_can_alloc_dyn(bp->pdev)) { + irqs_required = bnxt_get_num_msix(bp); + if (irqs_required > bp->total_irqs && + bnxt_change_msix(bp, irqs_required) != irqs_required) { + netdev_err(bp->dev, "Unable to allocate %d MSIX vectors, maximum available %d\n", + irqs_required, bp->total_irqs); + return -ENOSPC; + } + } return 0; + } if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) { int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want); @@ -11748,6 +11763,10 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) rc = bnxt_init_int_mode(bp); bnxt_ulp_irq_restart(bp, rc); } else if (irq_change && !rc) { + /* Size the vectors from what FW actually reserved, which + * can be less than what was requested. + */ + irqs_required = bnxt_get_num_msix(bp); if (bnxt_change_msix(bp, irqs_required) != irqs_required) rc = -ENOSPC; } @@ -14818,7 +14837,10 @@ static int bnxt_get_registered_vfs(struct bnxt *bp) void bnxt_fw_reset(struct bnxt *bp) { bnxt_ulp_stop(bp); - bnxt_lock_sp(bp); + if (BNXT_PF(bp)) + bnxt_rtnl_lock_sp(bp); + else + bnxt_lock_sp(bp); if (test_bit(BNXT_STATE_OPEN, &bp->state) && !test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; @@ -14864,7 +14886,10 @@ void bnxt_fw_reset(struct bnxt *bp) bnxt_queue_fw_reset_work(bp, tmo); } fw_reset_exit: - bnxt_unlock_sp(bp); + if (BNXT_PF(bp)) + bnxt_rtnl_unlock_sp(bp); + else + bnxt_unlock_sp(bp); } static void bnxt_chk_missed_irq(struct bnxt *bp) @@ -15113,6 +15138,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp)); } if (hwr.cp > bp->total_irqs) { + int old_total = bp->total_irqs; int total_msix = bnxt_change_msix(bp, hwr.cp); if (total_msix < hwr.cp) { @@ -15120,6 +15146,17 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.cp, total_msix); rc = -ENOSPC; } + /* FW has not reserved the new vectors yet, and writes to + * MSI-X table entries beyond the reserved IRQs don't + * stick (seen on BCM57508). Free them again; + * bnxt_reserve_rings() allocates them after + * __bnxt_reserve_rings(). Without the new resource + * manager there is no IRQ reservation and + * bnxt_reserve_rings() does not grow the vectors, so + * keep them. + */ + if (BNXT_NEW_RM(bp)) + bnxt_change_msix(bp, old_total); } } return rc; @@ -15515,9 +15552,8 @@ static void bnxt_fw_reset_task(struct work_struct *work) bp->fw_reset_timestamp = jiffies; netdev_lock(bp->dev); if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) { - bnxt_fw_reset_abort(bp, rc); netdev_unlock(bp->dev); - goto ulp_start; + goto fw_reset_abort; } bnxt_fw_reset_close(bp); if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) { @@ -15650,9 +15686,11 @@ static void bnxt_fw_reset_task(struct work_struct *work) netdev_err(bp->dev, "fw_health_status 0x%x\n", sts); } fw_reset_abort: + rtnl_lock(); netdev_lock(bp->dev); bnxt_fw_reset_abort(bp, rc); netdev_unlock(bp->dev); + rtnl_unlock(); ulp_start: if (!rc) bnxt_ulp_start(bp); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c index 18e33144f34537..6ba2a0329a2e24 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c @@ -501,8 +501,7 @@ int bnxt_vf_reps_create(struct bnxt *bp) return -ENOMEM; /* storage for cfa_code to vf-idx mapping */ - cfa_code_map = kmalloc_array(MAX_CFA_CODE, sizeof(*bp->cfa_code_map), - GFP_KERNEL); + cfa_code_map = kmalloc_objs(*bp->cfa_code_map, MAX_CFA_CODE); if (!cfa_code_map) { rc = -ENOMEM; goto err; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index f087f278f9e56b..5ad0e32e2b4001 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5854,7 +5854,7 @@ static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk, if (err) return err; - mgmt = devm_kzalloc(&pdev->dev, sizeof(*mgmt), GFP_KERNEL); + mgmt = devm_kzalloc_obj(&pdev->dev, *mgmt); if (!mgmt) { err = -ENOMEM; goto err_disable_clks; diff --git a/drivers/net/ethernet/cavium/common/cavium_ptp.c b/drivers/net/ethernet/cavium/common/cavium_ptp.c index 61e2616570734a..ab0a6432f19f1d 100644 --- a/drivers/net/ethernet/cavium/common/cavium_ptp.c +++ b/drivers/net/ethernet/cavium/common/cavium_ptp.c @@ -227,7 +227,7 @@ static int cavium_ptp_probe(struct pci_dev *pdev, u64 clock_comp; int err; - clock = devm_kzalloc(dev, sizeof(*clock), GFP_KERNEL); + clock = devm_kzalloc_obj(dev, *clock); if (!clock) { err = -ENOMEM; goto error; diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c index 086f32b61580dd..c128b9948b4de2 100644 --- a/drivers/net/ethernet/cavium/thunder/nic_main.c +++ b/drivers/net/ethernet/cavium/thunder/nic_main.c @@ -1297,11 +1297,11 @@ static int nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) BUILD_BUG_ON(sizeof(union nic_mbx) > 16); - nic = devm_kzalloc(dev, sizeof(*nic), GFP_KERNEL); + nic = devm_kzalloc_obj(dev, *nic); if (!nic) return -ENOMEM; - nic->hw = devm_kzalloc(dev, sizeof(struct hw_info), GFP_KERNEL); + nic->hw = devm_kzalloc_obj(dev, struct hw_info); if (!nic->hw) return -ENOMEM; diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c index 062ac4a5fa12d8..3ffa672ca29fd5 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c @@ -511,7 +511,7 @@ static int nicvf_init_snd_queue(struct nicvf *nic, return err; sq->desc = sq->dmem.base; - sq->skbuff = kcalloc(q_len, sizeof(u64), GFP_KERNEL); + sq->skbuff = kzalloc_objs(u64, q_len); if (!sq->skbuff) return -ENOMEM; @@ -524,7 +524,7 @@ static int nicvf_init_snd_queue(struct nicvf *nic, qidx += ((nic->sqs_id + 1) * MAX_SND_QUEUES_PER_QS); if (qidx < nic->pnicvf->xdp_tx_queues) { /* Alloc memory to save page pointers for XDP_TX */ - sq->xdp_page = kcalloc(q_len, sizeof(u64), GFP_KERNEL); + sq->xdp_page = kzalloc_objs(u64, q_len); if (!sq->xdp_page) return -ENOMEM; sq->xdp_desc_cnt = 0; @@ -1037,7 +1037,7 @@ int nicvf_set_qset_resources(struct nicvf *nic) { struct queue_set *qs; - qs = devm_kzalloc(&nic->pdev->dev, sizeof(*qs), GFP_KERNEL); + qs = devm_kzalloc_obj(&nic->pdev->dev, *qs); if (!qs) return -ENOMEM; nic->qs = qs; diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c index b6303999902fce..ebba423564e055 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c @@ -1595,7 +1595,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) u8 lmac; u16 sdevid; - bgx = devm_kzalloc(dev, sizeof(*bgx), GFP_KERNEL); + bgx = devm_kzalloc_obj(dev, *bgx); if (!bgx) return -ENOMEM; bgx->pdev = pdev; diff --git a/drivers/net/ethernet/cavium/thunder/thunder_xcv.c b/drivers/net/ethernet/cavium/thunder/thunder_xcv.c index 3ebb9379283145..57c736dc239ae6 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_xcv.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_xcv.c @@ -156,7 +156,7 @@ static int xcv_probe(struct pci_dev *pdev, const struct pci_device_id *ent) int err; struct device *dev = &pdev->dev; - xcv = devm_kzalloc(dev, sizeof(struct xcv), GFP_KERNEL); + xcv = devm_kzalloc_obj(dev, struct xcv); if (!xcv) return -ENOMEM; xcv->pdev = pdev; diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c index 1ced6df6eac8c2..e21162a86f38e3 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c @@ -864,7 +864,7 @@ int cxgb4_write_rss(const struct port_info *pi, const u16 *queues) u16 *rss; rxq = &adapter->sge.ethrxq[pi->first_qset]; - rss = kmalloc_array(pi->rss_size, sizeof(u16), GFP_KERNEL); + rss = kmalloc_objs(u16, pi->rss_size); if (!rss) return -ENOMEM; @@ -1388,7 +1388,7 @@ static int cxgb4_port_mirror_alloc_queues(struct net_device *dev) } /* Setup RSS for Mirror Rxqs */ - rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL); + rss = kzalloc_objs(u16, pi->rss_size); if (!rss) { ret = -ENOMEM; goto out_free_queues; @@ -6096,7 +6096,7 @@ static int init_rss(struct adapter *adap) for_each_port(adap, i) { struct port_info *pi = adap2pinfo(adap, i); - pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL); + pi->rss = kzalloc_objs(u16, pi->rss_size); if (!pi->rss) return -ENOMEM; } diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c index 1c1a7bc5a89664..2708de7f4d8535 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c @@ -512,8 +512,7 @@ struct cxgb4_tc_u32_table *cxgb4_init_tc_u32(struct adapter *adap) unsigned int bmap_size; bmap_size = BITS_TO_LONGS(max_tids); - link->tid_map = kvcalloc(bmap_size, sizeof(unsigned long), - GFP_KERNEL); + link->tid_map = kvzalloc_objs(unsigned long, bmap_size); if (!link->tid_map) goto out_no_mem; bitmap_zero(link->tid_map, max_tids); diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 2fe7fd0202d266..3ed8b1ae0bbc26 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -2648,7 +2648,7 @@ static int gemini_ethernet_probe(struct platform_device *pdev) u32 val; /* Global registers */ - geth = devm_kzalloc(dev, sizeof(*geth), GFP_KERNEL); + geth = devm_kzalloc_obj(dev, *geth); if (!geth) return -ENOMEM; geth->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c index e294b365eb0661..082bb560334d4e 100644 --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -1389,7 +1389,7 @@ static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev) if (!IS_ENABLED(CONFIG_OF) || !np) return ERR_PTR(-ENXIO); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c index 71ff9e6db209a8..727f40a6d8d306 100644 --- a/drivers/net/ethernet/dec/tulip/eeprom.c +++ b/drivers/net/ethernet/dec/tulip/eeprom.c @@ -224,8 +224,8 @@ void tulip_parse_eeprom(struct net_device *dev) return; } - mtable = devm_kmalloc(&tp->pdev->dev, struct_size(mtable, mleaf, count), - GFP_KERNEL); + mtable = devm_kmalloc_flex(&tp->pdev->dev, *mtable, mleaf, + count); if (mtable == NULL) return; /* Horrible, impossible failure. */ last_mediatable = tp->mtable = mtable; diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c index ed302f5ec47681..ac09fd3a426014 100644 --- a/drivers/net/ethernet/emulex/benet/be_main.c +++ b/drivers/net/ethernet/emulex/benet/be_main.c @@ -4680,8 +4680,7 @@ static int be_if_create(struct be_adapter *adapter) u32 cap_flags = be_if_cap_flags(adapter); /* alloc required memory for other filtering fields */ - adapter->pmac_id = kcalloc(be_max_uc(adapter), - sizeof(*adapter->pmac_id), GFP_KERNEL); + adapter->pmac_id = kzalloc_objs(*adapter->pmac_id, be_max_uc(adapter)); if (!adapter->pmac_id) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index ad2d8256eb8dd5..9da505271bdeea 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -701,8 +701,7 @@ static struct dpaa_fq *dpaa_fq_alloc(struct device *dev, struct dpaa_fq *dpaa_fq; int i; - dpaa_fq = devm_kcalloc(dev, count, sizeof(*dpaa_fq), - GFP_KERNEL); + dpaa_fq = devm_kzalloc_objs(dev, *dpaa_fq, count); if (!dpaa_fq) return NULL; @@ -957,7 +956,7 @@ static int dpaa_fq_setup(struct dpaa_priv *priv, struct dpaa_fq *fq; u16 *channels; - channels = kcalloc(num_possible_cpus(), sizeof(u16), GFP_KERNEL); + channels = kzalloc_objs(u16, num_possible_cpus()); if (!channels) return -ENOMEM; @@ -3205,7 +3204,7 @@ static struct dpaa_bp *dpaa_bp_alloc(struct device *dev) { struct dpaa_bp *dpaa_bp; - dpaa_bp = devm_kzalloc(dev, sizeof(*dpaa_bp), GFP_KERNEL); + dpaa_bp = devm_kzalloc_obj(dev, *dpaa_bp); if (!dpaa_bp) return ERR_PTR(-ENOMEM); @@ -3363,17 +3362,15 @@ static int dpaa_eth_probe(struct platform_device *pdev) priv->msg_enable = netif_msg_init(debug, DPAA_MSG_DEFAULT); - priv->egress_fqs = devm_kcalloc(dev, dpaa_max_num_txqs(), - sizeof(*priv->egress_fqs), - GFP_KERNEL); + priv->egress_fqs = devm_kzalloc_objs(dev, *priv->egress_fqs, + dpaa_max_num_txqs()); if (!priv->egress_fqs) { err = -ENOMEM; goto free_netdev; } - priv->conf_fqs = devm_kcalloc(dev, dpaa_max_num_txqs(), - sizeof(*priv->conf_fqs), - GFP_KERNEL); + priv->conf_fqs = devm_kzalloc_objs(dev, *priv->conf_fqs, + dpaa_max_num_txqs()); if (!priv->conf_fqs) { err = -ENOMEM; goto free_netdev; diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 7227a35dfaf2f8..9003cff88024c4 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -3866,9 +3866,8 @@ static int dpaa2_eth_setup_dpni(struct fsl_mc_device *ls_dev) if (err && err != -EOPNOTSUPP) goto close; - priv->cls_rules = devm_kcalloc(dev, dpaa2_eth_fs_count(priv), - sizeof(struct dpaa2_eth_cls_rule), - GFP_KERNEL); + priv->cls_rules = devm_kzalloc_objs(dev, struct dpaa2_eth_cls_rule, + dpaa2_eth_fs_count(priv)); if (!priv->cls_rules) { err = -ENOMEM; goto close; diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c index a28ddc0542bf25..5506cc9fc02743 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c @@ -134,7 +134,7 @@ static int dpaa2_ptp_probe(struct fsl_mc_device *mc_dev) void __iomem *base; int err; - ptp_qoriq = devm_kzalloc(dev, sizeof(*ptp_qoriq), GFP_KERNEL); + ptp_qoriq = devm_kzalloc_obj(dev, *ptp_qoriq); if (!ptp_qoriq) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c index e4a393a8a58e8f..e99936bd6dbabb 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c @@ -73,8 +73,7 @@ int enetc4_setup_cbdr(struct enetc_si *si) user->cbdr_num = 1; user->dev = dev; - user->ring = devm_kcalloc(dev, user->cbdr_num, - sizeof(struct netc_cbdr), GFP_KERNEL); + user->ring = devm_kzalloc_objs(dev, struct netc_cbdr, user->cbdr_num); if (!user->ring) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ierb.c b/drivers/net/ethernet/freescale/enetc/enetc_ierb.c index f0600b97a3d660..0f1d4764fb54d4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_ierb.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_ierb.c @@ -100,7 +100,7 @@ static int enetc_ierb_probe(struct platform_device *pdev) struct enetc_ierb *ierb; void __iomem *regs; - ierb = devm_kzalloc(&pdev->dev, sizeof(*ierb), GFP_KERNEL); + ierb = devm_kzalloc_obj(&pdev->dev, *ierb); if (!ierb) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c index 998aaa394e9c4c..9268e2de1fd1d5 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_mdio.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_mdio.c @@ -221,7 +221,7 @@ struct enetc_hw *enetc_hw_alloc(struct device *dev, void __iomem *port_regs) { struct enetc_hw *hw; - hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(dev, *hw); if (!hw) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c index 8206884294a477..8facc8bf8693a2 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -585,15 +585,12 @@ int enetc_init_sriov_resources(struct enetc_pf *pf) if (!pf->total_vfs) return 0; - pf->rxmsg = devm_kcalloc(dev, pf->total_vfs, - sizeof(struct enetc_msg_swbd), - GFP_KERNEL); + pf->rxmsg = devm_kzalloc_objs(dev, struct enetc_msg_swbd, pf->total_vfs); if (!pf->rxmsg) return -ENOMEM; - pf->vf_state = devm_kcalloc(dev, pf->total_vfs, - sizeof(struct enetc_vf_state), - GFP_KERNEL); + pf->vf_state = devm_kzalloc_objs(dev, struct enetc_vf_state, + pf->total_vfs); if (!pf->vf_state) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c b/drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c index c7eb0234c78550..658fab31e9ed7b 100644 --- a/drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c +++ b/drivers/net/ethernet/freescale/enetc/netc_blk_ctrl.c @@ -900,7 +900,7 @@ static int netc_blk_ctrl_probe(struct platform_device *pdev) void __iomem *regs; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c index f27ff625fe29d3..29c2fa2be8378a 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c @@ -127,10 +127,10 @@ static int mac_probe(struct platform_device *_of_dev) mac_node = dev->of_node; init = of_device_get_match_data(dev); - mac_dev = devm_kzalloc(dev, sizeof(*mac_dev), GFP_KERNEL); + mac_dev = devm_kzalloc_obj(dev, *mac_dev); if (!mac_dev) return -ENOMEM; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(_of_dev, mac_dev); diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c index e8edef6505bfb2..94905ea9cf7207 100644 --- a/drivers/net/ethernet/freescale/gianfar_ethtool.c +++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c @@ -689,10 +689,8 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, int j = MAX_FILER_IDX, l = 0x0; int ret = 1; - local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int), - GFP_KERNEL); - local_rqfcr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int), - GFP_KERNEL); + local_rqfpr = kmalloc_objs(unsigned int, MAX_FILER_IDX + 1); + local_rqfcr = kmalloc_objs(unsigned int, MAX_FILER_IDX + 1); if (!local_rqfpr || !local_rqfcr) { ret = 0; goto err; diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index b7ce6e8632db67..e509488a3d3e1a 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -871,6 +871,10 @@ struct gve_ctrl_ops { int (*report_link_speed)(struct gve_priv *priv); }; +struct gve_ring_err_stats { + u64 rx_alloc_fails; +}; + struct gve_priv { struct net_device *dev; struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */ @@ -957,9 +961,17 @@ struct gve_priv { struct workqueue_struct *gve_wq; struct work_struct service_task; struct work_struct stats_report_task; + /* Protects the priv->tx/priv->rx arrays, the in-place rewrite of + * priv->rx[idx] and the queue counts against stats readers that do + * not hold the netdev instance lock. + * Also protects base_net_stats and base_ring_err_stats. + */ + spinlock_t stats_lock; unsigned long service_task_flags; unsigned long state_flags; + struct gve_ring_err_stats base_ring_err_stats; + struct rtnl_link_stats64 base_net_stats; struct gve_stats_report *stats_report; u64 stats_report_len; dma_addr_t stats_report_bus; /* dma address for the stats report */ diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 8b215fca9c1b63..2c848f0c23dc2c 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -191,7 +191,9 @@ void gve_parse_device_option(struct gve_priv *priv, *dev_op_modify_ring = (void *)(option + 1); /* device has not provided min ring size */ - if (option_length == GVE_DEVICE_OPTION_NO_MIN_RING_SIZE) + if (option_length == GVE_DEVICE_OPTION_NO_MIN_RING_SIZE || + be16_to_cpu((*dev_op_modify_ring)->min_rx_ring_size) == 0 || + be16_to_cpu((*dev_op_modify_ring)->min_tx_ring_size) == 0) priv->device_info.default_min_ring_size = true; break; case GVE_DEV_OPT_ID_FLOW_STEERING: diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 2437cd8ba6331a..0ee69bc11d8366 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -61,15 +62,44 @@ static netdev_tx_t gve_start_xmit(struct sk_buff *skb, struct net_device *dev) return gve_tx_dqo(skb, dev); } -static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) +static void gve_add_base_stats(struct gve_priv *priv, + struct rtnl_link_stats64 *s) +{ + struct rtnl_link_stats64 *base_stats = &priv->base_net_stats; + + s->rx_packets += base_stats->rx_packets; + s->rx_bytes += base_stats->rx_bytes; + s->tx_packets += base_stats->tx_packets; + s->tx_bytes += base_stats->tx_bytes; +} + +static void gve_add_tx_ring_range_stats(struct gve_priv *priv, int start_ring, + int end_ring, u64 *packets, u64 *bytes) +{ + int ring; + + for (ring = start_ring; ring < end_ring; ring++) { + struct gve_tx_ring *tx = &priv->tx[ring]; + unsigned int start; + u64 pkts, byts; + + do { + start = u64_stats_fetch_begin(&tx->statss); + pkts = tx->pkt_done; + byts = tx->bytes_done; + } while (u64_stats_fetch_retry(&tx->statss, start)); + *packets += pkts; + *bytes += byts; + } +} + +static void gve_get_ring_stats(struct gve_priv *priv, + struct rtnl_link_stats64 *s) { - struct gve_priv *priv = netdev_priv(dev); unsigned int start; u64 packets, bytes; - int num_tx_queues; int ring; - num_tx_queues = gve_num_tx_queues(priv); if (priv->rx) { for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) { do { @@ -83,21 +113,44 @@ static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) s->rx_bytes += bytes; } } - if (priv->tx) { - for (ring = 0; ring < num_tx_queues; ring++) { - do { - start = - u64_stats_fetch_begin(&priv->tx[ring].statss); - packets = priv->tx[ring].pkt_done; - bytes = priv->tx[ring].bytes_done; - } while (u64_stats_fetch_retry(&priv->tx[ring].statss, - start)); - s->tx_packets += packets; - s->tx_bytes += bytes; - } + if (priv->tx) + gve_add_tx_ring_range_stats(priv, 0, gve_num_tx_queues(priv), + &s->tx_packets, &s->tx_bytes); +} + +static void gve_get_ring_err_stats(struct gve_priv *priv, + struct gve_ring_err_stats *err_stats) +{ + int ring; + + if (!priv->rx) + return; + + for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) { + struct gve_rx_ring *rx = &priv->rx[ring]; + unsigned int start; + u64 rx_alloc_fails; + + do { + start = u64_stats_fetch_begin(&rx->statss); + rx_alloc_fails = rx->rx_skb_alloc_fail + + rx->rx_buf_alloc_fail; + } while (u64_stats_fetch_retry(&rx->statss, start)); + + err_stats->rx_alloc_fails += rx_alloc_fails; } } +static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) +{ + struct gve_priv *priv = netdev_priv(dev); + + spin_lock_bh(&priv->stats_lock); + gve_get_ring_stats(priv, s); + gve_add_base_stats(priv, s); + spin_unlock_bh(&priv->stats_lock); +} + static int gve_alloc_flow_rule_caches(struct gve_priv *priv) { struct gve_flow_rules_cache *flow_rules_cache = &priv->flow_rules_cache; @@ -115,8 +168,8 @@ static int gve_alloc_flow_rule_caches(struct gve_priv *priv) } flow_rules_cache->rule_ids_cache = - kvcalloc(GVE_FLOW_RULE_IDS_CACHE_SIZE, sizeof(*flow_rules_cache->rule_ids_cache), - GFP_KERNEL); + kvzalloc_objs(*flow_rules_cache->rule_ids_cache, + GVE_FLOW_RULE_IDS_CACHE_SIZE); if (!flow_rules_cache->rule_ids_cache) { dev_err(&priv->pdev->dev, "Cannot alloc flow rule ids cache\n"); err = -ENOMEM; @@ -154,9 +207,8 @@ static int gve_alloc_rss_config_cache(struct gve_priv *priv) if (!rss_config->hash_key) return -ENOMEM; - rss_config->hash_lut = kcalloc(priv->rss_lut_size, - sizeof(rss_config->hash_lut[0]), - GFP_KERNEL); + rss_config->hash_lut = kzalloc_objs(rss_config->hash_lut[0], + priv->rss_lut_size); if (!rss_config->hash_lut) goto free_rss_key_cache; @@ -642,9 +694,16 @@ static void gve_queues_mem_remove(struct gve_priv *priv) struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0}; gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); - gve_queues_mem_free(priv, &tx_alloc_cfg, &rx_alloc_cfg); + + spin_lock_bh(&priv->stats_lock); + gve_get_ring_stats(priv, &priv->base_net_stats); + gve_get_ring_err_stats(priv, &priv->base_ring_err_stats); + priv->tx = NULL; priv->rx = NULL; + spin_unlock_bh(&priv->stats_lock); + + gve_queues_mem_free(priv, &tx_alloc_cfg, &rx_alloc_cfg); } static void gve_free_control_plane_resources(struct gve_priv *priv) @@ -688,8 +747,7 @@ static int gve_alloc_control_plane_resources(struct gve_priv *priv) goto abort; if (!gve_is_gqi(priv)) { - priv->ptype_lut_dqo = kvzalloc_obj(*priv->ptype_lut_dqo, - GFP_KERNEL); + priv->ptype_lut_dqo = kvzalloc_obj(*priv->ptype_lut_dqo); if (!priv->ptype_lut_dqo) { err = -ENOMEM; goto abort; @@ -1372,6 +1430,37 @@ static void gve_queues_stop(struct gve_priv *priv) gve_rx_stop_rings(priv, priv->rx_cfg.num_queues); } +static void gve_handle_link_status(struct gve_priv *priv) +{ + bool link_up; + + netdev_assert_locked(priv->dev); + + if (!gve_get_napi_enabled(priv)) + return; + + link_up = READ_ONCE(priv->link_up); + if (link_up == netif_carrier_ok(priv->dev)) + return; + + if (link_up) { + netdev_info(priv->dev, "Device link is up.\n"); + netif_carrier_on(priv->dev); + } else { + netdev_info(priv->dev, "Device link is down.\n"); + netif_carrier_off(priv->dev); + } +} + +static void gve_turnup_and_check_status(struct gve_priv *priv) +{ + const struct gve_ctrl_ops *ops = priv->ctrl_ops; + + gve_turnup(priv); + ops->report_link_status(priv); + gve_handle_link_status(priv); +} + /* The passed-in queue memory is stored into priv and the queues are made live. * No memory is allocated. Passed-in memory is freed on errors. */ @@ -1383,6 +1472,7 @@ static int gve_queues_start(struct gve_priv *priv, int err; /* Record new resources into priv */ + spin_lock_bh(&priv->stats_lock); priv->tx = tx_alloc_cfg->tx; priv->rx = rx_alloc_cfg->rx; @@ -1396,10 +1486,11 @@ static int gve_queues_start(struct gve_priv *priv, priv->rx_pages_per_qpl = rx_alloc_cfg->pages_per_qpl; priv->header_split_enabled = rx_alloc_cfg->enable_header_split; priv->rx_cfg.packet_buffer_size = rx_alloc_cfg->packet_buffer_size; + gve_init_sync_stats(priv); + spin_unlock_bh(&priv->stats_lock); gve_tx_start_rings(priv, gve_num_tx_queues(priv)); gve_rx_start_rings(priv, rx_alloc_cfg->qcfg_rx->num_queues); - gve_init_sync_stats(priv); err = netif_set_real_num_tx_queues(dev, priv->tx_cfg.num_queues); if (err) @@ -1433,7 +1524,11 @@ static int gve_queues_start(struct gve_priv *priv, round_jiffies(jiffies + msecs_to_jiffies(priv->stats_report_timer_period))); - gve_turnup(priv); + gve_turnup_and_check_status(priv); + /* Also kick the service task. When the queues come back up after + * gve_reset() or resume, this handles a reset requested while the + * service task was disabled. + */ queue_work(priv->gve_wq, &priv->service_task); priv->interface_up_cnt++; return 0; @@ -1509,26 +1604,6 @@ static int gve_close(struct net_device *dev) return err; } -static void gve_handle_link_status(struct gve_priv *priv) -{ - bool link_up; - - if (!gve_get_napi_enabled(priv)) - return; - - link_up = READ_ONCE(priv->link_up); - if (link_up == netif_carrier_ok(priv->dev)) - return; - - if (link_up) { - netdev_info(priv->dev, "Device link is up.\n"); - netif_carrier_on(priv->dev); - } else { - netdev_info(priv->dev, "Device link is down.\n"); - netif_carrier_off(priv->dev); - } -} - static int gve_configure_rings_xdp(struct gve_priv *priv, u16 num_xdp_rings) { @@ -2003,15 +2078,6 @@ static void gve_turnup(struct gve_priv *priv) gve_set_napi_enabled(priv); } -static void gve_turnup_and_check_status(struct gve_priv *priv) -{ - const struct gve_ctrl_ops *ops = priv->ctrl_ops; - - gve_turnup(priv); - ops->report_link_status(priv); - gve_handle_link_status(priv); -} - static struct gve_notify_block *gve_get_tx_notify_block(struct gve_priv *priv, unsigned int txqueue) { @@ -2266,6 +2332,7 @@ void gve_handle_report_stats(struct gve_priv *priv) if (!gve_get_report_stats(priv)) return; + spin_lock_bh(&priv->stats_lock); be64_add_cpu(&priv->stats_report->written_count, 1); /* tx stats */ if (priv->tx) { @@ -2330,6 +2397,7 @@ void gve_handle_report_stats(struct gve_priv *priv) }; } } + spin_unlock_bh(&priv->stats_lock); } /* Handle NIC status register changes, reset requests and report stats */ @@ -2343,8 +2411,14 @@ static void gve_service_task(struct work_struct *work) gve_handle_status(priv, status); gve_handle_reset(priv); + + /* Serialize with the synchronous link status updates, which all run + * under the netdev instance lock. + */ + netdev_lock(priv->dev); ops->report_link_status(priv); gve_handle_link_status(priv); + netdev_unlock(priv->dev); } static void gve_set_netdev_xdp_features(struct gve_priv *priv) @@ -2679,8 +2753,20 @@ static int gve_rx_queue_stop(struct net_device *dev, void *per_q_mem, int idx) gve_turnup_and_check_status(priv); gve_per_q_mem = (struct gve_rx_ring *)per_q_mem; + spin_lock_bh(&priv->stats_lock); + priv->base_net_stats.rx_packets += priv->rx[idx].rpackets; + priv->base_net_stats.rx_bytes += priv->rx[idx].rbytes; + priv->base_ring_err_stats.rx_alloc_fails += + priv->rx[idx].rx_skb_alloc_fail + + priv->rx[idx].rx_buf_alloc_fail; *gve_per_q_mem = priv->rx[idx]; memset(&priv->rx[idx], 0, sizeof(priv->rx[idx])); + spin_unlock_bh(&priv->stats_lock); + + gve_per_q_mem->rpackets = 0; + gve_per_q_mem->rbytes = 0; + gve_per_q_mem->rx_skb_alloc_fail = 0; + gve_per_q_mem->rx_buf_alloc_fail = 0; return 0; } @@ -2734,7 +2820,9 @@ static int gve_rx_queue_start(struct net_device *dev, return -EAGAIN; gve_per_q_mem = (struct gve_rx_ring *)per_q_mem; + spin_lock_bh(&priv->stats_lock); priv->rx[idx] = *gve_per_q_mem; + spin_unlock_bh(&priv->stats_lock); /* Single-queue creation requires quiescence on all queues */ gve_turndown(priv); @@ -2770,7 +2858,9 @@ static int gve_rx_queue_start(struct net_device *dev, * which needs the rtnl lock, will not run till this func returns and * its caller gives up the lock. */ + spin_lock_bh(&priv->stats_lock); memset(&priv->rx[idx], 0, sizeof(priv->rx[idx])); + spin_unlock_bh(&priv->stats_lock); return err; } @@ -2786,9 +2876,15 @@ static void gve_get_rx_queue_stats(struct net_device *dev, int idx, struct netdev_queue_stats_rx *rx_stats) { struct gve_priv *priv = netdev_priv(dev); - struct gve_rx_ring *rx = &priv->rx[idx]; + struct gve_rx_ring *rx; unsigned int start; + spin_lock_bh(&priv->stats_lock); + if (!priv->rx) + goto unlock; + + rx = &priv->rx[idx]; + do { start = u64_stats_fetch_begin(&rx->statss); rx_stats->packets = rx->rpackets; @@ -2796,32 +2892,62 @@ static void gve_get_rx_queue_stats(struct net_device *dev, int idx, rx_stats->alloc_fail = rx->rx_skb_alloc_fail + rx->rx_buf_alloc_fail; } while (u64_stats_fetch_retry(&rx->statss, start)); + +unlock: + spin_unlock_bh(&priv->stats_lock); } static void gve_get_tx_queue_stats(struct net_device *dev, int idx, struct netdev_queue_stats_tx *tx_stats) { struct gve_priv *priv = netdev_priv(dev); - struct gve_tx_ring *tx = &priv->tx[idx]; + struct gve_tx_ring *tx; unsigned int start; + spin_lock_bh(&priv->stats_lock); + if (!priv->tx) + goto unlock; + + tx = &priv->tx[idx]; + do { start = u64_stats_fetch_begin(&tx->statss); tx_stats->packets = tx->pkt_done; tx_stats->bytes = tx->bytes_done; } while (u64_stats_fetch_retry(&tx->statss, start)); + +unlock: + spin_unlock_bh(&priv->stats_lock); } static void gve_get_base_stats(struct net_device *dev, struct netdev_queue_stats_rx *rx, struct netdev_queue_stats_tx *tx) { - rx->packets = 0; - rx->bytes = 0; - rx->alloc_fail = 0; + const struct gve_ring_err_stats *base_err_stats; + const struct rtnl_link_stats64 *base_stats; + struct gve_priv *priv; - tx->packets = 0; - tx->bytes = 0; + priv = netdev_priv(dev); + base_stats = &priv->base_net_stats; + base_err_stats = &priv->base_ring_err_stats; + + spin_lock_bh(&priv->stats_lock); + rx->packets = base_stats->rx_packets; + rx->bytes = base_stats->rx_bytes; + rx->alloc_fail = base_err_stats->rx_alloc_fails; + + tx->packets = base_stats->tx_packets; + tx->bytes = base_stats->tx_bytes; + /* XDP TX rings are not exposed as netdev queues, so report their live + * counters here to keep the device totals consistent with + * ndo_get_stats64. + */ + if (priv->tx) + gve_add_tx_ring_range_stats(priv, priv->tx_cfg.num_queues, + gve_num_tx_queues(priv), + &tx->packets, &tx->bytes); + spin_unlock_bh(&priv->stats_lock); } static const struct netdev_stat_ops gve_stat_ops = { @@ -2935,6 +3061,7 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } INIT_WORK(&priv->service_task, gve_service_task); INIT_WORK(&priv->stats_report_task, gve_stats_report_task); + spin_lock_init(&priv->stats_lock); priv->tx_cfg.max_queues = max_tx_queues; priv->rx_cfg.max_queues = max_rx_queues; diff --git a/drivers/net/ethernet/google/gve/gve_tx_dqo.c b/drivers/net/ethernet/google/gve/gve_tx_dqo.c index ad99cbb77e291b..f36d2e0baceae8 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -360,9 +360,8 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, /* Only alloc xsk pool for XDP queues */ if (idx >= cfg->qcfg->num_queues && cfg->num_xdp_rings) { tx->dqo.xsk_reorder_queue = - kvcalloc(tx->dqo.complq_mask + 1, - sizeof(tx->dqo.xsk_reorder_queue[0]), - GFP_KERNEL); + kvzalloc_objs(tx->dqo.xsk_reorder_queue[0], + tx->dqo.complq_mask + 1); if (!tx->dqo.xsk_reorder_queue) goto err; } diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_diagnose.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_diagnose.c index c0ce74cf738209..1e6288dd5a361f 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_diagnose.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_diagnose.c @@ -252,7 +252,7 @@ static int hbg_push_irq_cnt(struct hbg_priv *priv) u64 *data; int ret; - data = kcalloc(data_num, sizeof(u64), GFP_KERNEL); + data = kzalloc_objs(u64, data_num); if (!data) return -ENOMEM; @@ -296,7 +296,7 @@ static int hbg_push_stats(struct hbg_priv *priv) u64 *data; int ret; - data = kcalloc(data_num, sizeof(u64), GFP_KERNEL); + data = kzalloc_objs(u64, data_num); if (!data) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c index a518dc66d9ef88..4c8bd32166b43c 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c @@ -339,8 +339,8 @@ static int hbg_mac_filter_init(struct hbg_priv *priv) struct hbg_mac_filter *filter = &priv->filter; struct hbg_mac_table_entry *tmp_table; - tmp_table = devm_kcalloc(&priv->pdev->dev, dev_specs->uc_mac_num, - sizeof(*tmp_table), GFP_KERNEL); + tmp_table = devm_kzalloc_objs(&priv->pdev->dev, *tmp_table, + dev_specs->uc_mac_num); if (!tmp_table) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hisi_femac.c b/drivers/net/ethernet/hisilicon/hisi_femac.c index a44ea0a2b1ee64..95de861b7ae34f 100644 --- a/drivers/net/ethernet/hisilicon/hisi_femac.c +++ b/drivers/net/ethernet/hisilicon/hisi_femac.c @@ -348,13 +348,11 @@ static int hisi_femac_init_queue(struct device *dev, struct hisi_femac_queue *queue, unsigned int num) { - queue->skb = devm_kcalloc(dev, num, sizeof(struct sk_buff *), - GFP_KERNEL); + queue->skb = devm_kzalloc_objs(dev, struct sk_buff *, num); if (!queue->skb) return -ENOMEM; - queue->dma_phys = devm_kcalloc(dev, num, sizeof(dma_addr_t), - GFP_KERNEL); + queue->dma_phys = devm_kzalloc_objs(dev, dma_addr_t, num); if (!queue->dma_phys) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c index 400933ca1a29b3..1469cd4c0b6185 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c @@ -697,7 +697,7 @@ void *hns_gmac_config(struct hns_mac_cb *mac_cb, struct mac_params *mac_param) { struct mac_driver *mac_drv; - mac_drv = devm_kzalloc(mac_cb->dev, sizeof(*mac_drv), GFP_KERNEL); + mac_drv = devm_kzalloc_obj(mac_cb->dev, *mac_drv); if (!mac_drv) return NULL; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c index f1cb6d56e4b9f7..02afdef0211aea 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -1106,8 +1106,7 @@ int hns_mac_init(struct dsaf_device *dsaf_dev) "reg(%u) out of range!\n", port_id); return -EINVAL; } - mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb), - GFP_KERNEL); + mac_cb = devm_kzalloc_obj(dsaf_dev->dev, *mac_cb); if (!mac_cb) return -ENOMEM; @@ -1122,8 +1121,7 @@ int hns_mac_init(struct dsaf_device *dsaf_dev) */ if (!found) { for (port_id = 0; port_id < max_port_num; port_id++) { - mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb), - GFP_KERNEL); + mac_cb = devm_kzalloc_obj(dsaf_dev->dev, *mac_cb); if (!mac_cb) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c index a59fd280a045c9..b5f11f7a7f928f 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c @@ -652,7 +652,7 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) { struct dsaf_misc_op *misc_op; - misc_op = devm_kzalloc(dsaf_dev->dev, sizeof(*misc_op), GFP_KERNEL); + misc_op = devm_kzalloc_obj(dsaf_dev->dev, *misc_op); if (!misc_op) return NULL; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c index 408d36d85fb135..076a36aefdd1c0 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c @@ -76,9 +76,8 @@ static int hns_ppe_common_get_cfg(struct dsaf_device *dsaf_dev, int comm_index) else ppe_num = HNS_PPE_DEBUG_NW_ENGINE_NUM; - ppe_common = devm_kzalloc(dsaf_dev->dev, - struct_size(ppe_common, ppe_cb, ppe_num), - GFP_KERNEL); + ppe_common = devm_kzalloc_flex(dsaf_dev->dev, *ppe_common, ppe_cb, + ppe_num); if (!ppe_common) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c index 3c4e4e8ca14013..520e5cb2fbe003 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c @@ -776,9 +776,8 @@ int hns_rcb_common_get_cfg(struct dsaf_device *dsaf_dev, int ring_num = hns_rcb_get_ring_num(dsaf_dev); rcb_common = - devm_kzalloc(dsaf_dev->dev, - struct_size(rcb_common, ring_pair_cb, ring_num), - GFP_KERNEL); + devm_kzalloc_flex(dsaf_dev->dev, *rcb_common, ring_pair_cb, + ring_num); if (!rcb_common) { dev_err(dsaf_dev->dev, "rcb common devm_kzalloc fail!\n"); return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c index dbc44c2c26c24f..2eb489bbbf79b3 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c @@ -780,7 +780,7 @@ void *hns_xgmac_config(struct hns_mac_cb *mac_cb, struct mac_params *mac_param) { struct mac_driver *mac_drv; - mac_drv = devm_kzalloc(mac_cb->dev, sizeof(*mac_drv), GFP_KERNEL); + mac_drv = devm_kzalloc_obj(mac_cb->dev, *mac_drv); if (!mac_drv) return NULL; diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c index d819d2bb345074..fa0e3736092f64 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -1992,7 +1992,7 @@ static void hns_nic_dump(struct hns_nic_priv *priv) if (ops->get_regs_len && ops->get_regs) { reg_num = ops->get_regs_len(priv->ae_handle); reg_num = (reg_num + 3ul) & ~3ul; - data = kcalloc(reg_num, sizeof(u32), GFP_KERNEL); + data = kzalloc_objs(u32, reg_num); if (data) { ops->get_regs(priv->ae_handle, data); for (i = 0; i < reg_num; i += 4) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c index 1eca53aaf59852..d0d904be95098c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c @@ -49,8 +49,8 @@ int hclge_comm_rss_init_cfg(struct hnae3_handle *nic, rss_cfg->rss_algo = rss_algo; - rss_ind_tbl = devm_kcalloc(&ae_dev->pdev->dev, rss_ind_tbl_size, - sizeof(*rss_ind_tbl), GFP_KERNEL); + rss_ind_tbl = devm_kzalloc_objs(&ae_dev->pdev->dev, *rss_ind_tbl, + rss_ind_tbl_size); if (!rss_ind_tbl) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c index 1347edac76993e..39648d92b97650 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c @@ -849,8 +849,7 @@ static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd) entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry; max_queue_num = hns3_get_max_available_channels(handle); - data = devm_kcalloc(&handle->pdev->dev, max_queue_num, sizeof(*data), - GFP_KERNEL); + data = devm_kzalloc_objs(&handle->pdev->dev, *data, max_queue_num); if (!data) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 47788be64be688..db4f584c4ce127 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -1072,8 +1072,7 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring) goto not_init; } - tx_spare = devm_kzalloc(ring_to_dev(ring), sizeof(*tx_spare), - GFP_KERNEL); + tx_spare = devm_kzalloc_obj(ring_to_dev(ring), *tx_spare); if (!tx_spare) { /* The driver still work without the tx spare buffer */ dev_warn(ring_to_dev(ring), "failed to allocate hns3_tx_spare\n"); @@ -3153,7 +3152,7 @@ static int hns3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) struct hnae3_ae_dev *ae_dev; int ret; - ae_dev = devm_kzalloc(&pdev->dev, sizeof(*ae_dev), GFP_KERNEL); + ae_dev = devm_kzalloc_obj(&pdev->dev, *ae_dev); if (!ae_dev) return -ENOMEM; @@ -4592,7 +4591,7 @@ static int hns3_create_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, } while (ring) { - chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); + chain = devm_kzalloc_obj(&pdev->dev, *chain); if (!chain) return -ENOMEM; if (cur_chain) @@ -4840,8 +4839,7 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) /* Should consider 2p/4p later */ vector_num = min_t(u16, num_online_cpus(), tqp_num); - vector = devm_kcalloc(&pdev->dev, vector_num, sizeof(*vector), - GFP_KERNEL); + vector = devm_kzalloc_objs(&pdev->dev, *vector, vector_num); if (!vector) return -ENOMEM; @@ -4850,8 +4848,7 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) priv->vector_num = vector_num; priv->tqp_vector = (struct hns3_enet_tqp_vector *) - devm_kcalloc(&pdev->dev, vector_num, sizeof(*priv->tqp_vector), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, *priv->tqp_vector, vector_num); if (!priv->tqp_vector) { ret = -ENOMEM; goto out; @@ -5047,8 +5044,8 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) if (ring->desc_num <= 0 || ring->buf_size <= 0) return -EINVAL; - ring->desc_cb = devm_kcalloc(ring_to_dev(ring), ring->desc_num, - sizeof(ring->desc_cb[0]), GFP_KERNEL); + ring->desc_cb = devm_kzalloc_objs(ring_to_dev(ring), ring->desc_cb[0], + ring->desc_num); if (!ring->desc_cb) { ret = -ENOMEM; goto out; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c index 9a4e29bfa1666b..33e11bbf766b26 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -2049,7 +2049,7 @@ static int hclge_dbg_dump_fd_tcam(struct seq_file *s, void *data) if (!hdev->hclge_fd_rule_num || !rule_num) return 0; - rule_locs = kcalloc(rule_num, sizeof(u16), GFP_KERNEL); + rule_locs = kzalloc_objs(u16, rule_num); if (!rule_locs) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index d117a0b442d020..67327ae6cd3cdf 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -1562,8 +1562,8 @@ static int hclge_alloc_tqps(struct hclge_dev *hdev) struct hclge_comm_tqp *tqp; int i; - hdev->htqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps, - sizeof(struct hclge_comm_tqp), GFP_KERNEL); + hdev->htqp = devm_kzalloc_objs(&hdev->pdev->dev, struct hclge_comm_tqp, + hdev->num_tqps); if (!hdev->htqp) return -ENOMEM; @@ -1674,8 +1674,8 @@ static int hclge_knic_setup(struct hclge_vport *vport, u16 num_tqps, kinfo->rx_buf_len = hdev->rx_buf_len; kinfo->tx_spare_buf_size = hdev->tx_spare_buf_size; - kinfo->tqp = devm_kcalloc(&hdev->pdev->dev, num_tqps, - sizeof(struct hnae3_queue *), GFP_KERNEL); + kinfo->tqp = devm_kzalloc_objs(&hdev->pdev->dev, struct hnae3_queue *, + num_tqps); if (!kinfo->tqp) return -ENOMEM; @@ -1771,8 +1771,7 @@ static int hclge_alloc_vport(struct hclge_dev *hdev) tqp_per_vport = hdev->num_tqps / num_vport; tqp_main_vport = tqp_per_vport + hdev->num_tqps % num_vport; - vport = devm_kcalloc(&pdev->dev, num_vport, sizeof(struct hclge_vport), - GFP_KERNEL); + vport = devm_kzalloc_objs(&pdev->dev, struct hclge_vport, num_vport); if (!vport) return -ENOMEM; @@ -2459,8 +2458,7 @@ static int hclge_init_msi(struct hclge_dev *hdev) hdev->num_msi = vectors; hdev->num_msi_left = vectors; - hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi, - sizeof(u16), GFP_KERNEL); + hdev->vector_status = devm_kzalloc_objs(&pdev->dev, u16, hdev->num_msi); if (!hdev->vector_status) { pci_free_irq_vectors(pdev); return -ENOMEM; @@ -2469,8 +2467,7 @@ static int hclge_init_msi(struct hclge_dev *hdev) for (i = 0; i < hdev->num_msi; i++) hdev->vector_status[i] = HCLGE_INVALID_VPORT; - hdev->vector_irq = devm_kcalloc(&pdev->dev, hdev->num_msi, - sizeof(int), GFP_KERNEL); + hdev->vector_irq = devm_kzalloc_objs(&pdev->dev, int, hdev->num_msi); if (!hdev->vector_irq) { pci_free_irq_vectors(pdev); return -ENOMEM; @@ -9500,7 +9497,7 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) struct hclge_dev *hdev; int ret; - hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(&pdev->dev, *hdev); if (!hdev) return -ENOMEM; @@ -10232,8 +10229,7 @@ static int hclge_set_channels(struct hnae3_handle *handle, u32 new_tqps_num, goto out; /* Reinitializes the rss indirect table according to the new RSS size */ - rss_indir = kcalloc(ae_dev->dev_specs.rss_ind_tbl_size, sizeof(u32), - GFP_KERNEL); + rss_indir = kzalloc_objs(u32, ae_dev->dev_specs.rss_ind_tbl_size); if (!rss_indir) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c index 0081c52814550e..d9b3641f55e6cf 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c @@ -427,7 +427,7 @@ static int hclge_ptp_create_clock(struct hclge_dev *hdev) { struct hclge_ptp *ptp; - ptp = devm_kzalloc(&hdev->pdev->dev, sizeof(*ptp), GFP_KERNEL); + ptp = devm_kzalloc_obj(&hdev->pdev->dev, *ptp); if (!ptp) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index 5d14d29b02965e..6dbb368b0fafa2 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -306,8 +306,8 @@ static int hclgevf_alloc_tqps(struct hclgevf_dev *hdev) struct hclge_comm_tqp *tqp; int i; - hdev->htqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps, - sizeof(struct hclge_comm_tqp), GFP_KERNEL); + hdev->htqp = devm_kzalloc_objs(&hdev->pdev->dev, struct hclge_comm_tqp, + hdev->num_tqps); if (!hdev->htqp) return -ENOMEM; @@ -372,8 +372,8 @@ static int hclgevf_knic_setup(struct hclgevf_dev *hdev) new_tqps = kinfo->rss_size * num_tc; kinfo->num_tqps = min(new_tqps, hdev->num_tqps); - kinfo->tqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps, - sizeof(struct hnae3_queue *), GFP_KERNEL); + kinfo->tqp = devm_kzalloc_objs(&hdev->pdev->dev, struct hnae3_queue *, + hdev->num_tqps); if (!kinfo->tqp) return -ENOMEM; @@ -2130,7 +2130,7 @@ static int hclgevf_alloc_hdev(struct hnae3_ae_dev *ae_dev) struct pci_dev *pdev = ae_dev->pdev; struct hclgevf_dev *hdev; - hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(&pdev->dev, *hdev); if (!hdev) return -ENOMEM; @@ -2385,8 +2385,7 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev) hdev->num_msi = vectors; hdev->num_msi_left = vectors; - hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi, - sizeof(u16), GFP_KERNEL); + hdev->vector_status = devm_kzalloc_objs(&pdev->dev, u16, hdev->num_msi); if (!hdev->vector_status) { pci_free_irq_vectors(pdev); return -ENOMEM; @@ -2395,8 +2394,7 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev) for (i = 0; i < hdev->num_msi; i++) hdev->vector_status[i] = HCLGEVF_INVALID_VPORT; - hdev->vector_irq = devm_kcalloc(&pdev->dev, hdev->num_msi, - sizeof(int), GFP_KERNEL); + hdev->vector_irq = devm_kzalloc_objs(&pdev->dev, int, hdev->num_msi); if (!hdev->vector_irq) { devm_kfree(&pdev->dev, hdev->vector_status); pci_free_irq_vectors(pdev); @@ -3184,8 +3182,7 @@ static int hclgevf_set_channels(struct hnae3_handle *handle, u32 new_tqps_num, goto out; /* Reinitializes the rss indirect table according to the new RSS size */ - rss_indir = kcalloc(hdev->ae_dev->dev_specs.rss_ind_tbl_size, - sizeof(u32), GFP_KERNEL); + rss_indir = kzalloc_objs(u32, hdev->ae_dev->dev_specs.rss_ind_tbl_size); if (!rss_indir) return -ENOMEM; diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c b/drivers/net/ethernet/hisilicon/hns_mdio.c index 6812be8dc64fe1..2725e5bc19e0a1 100644 --- a/drivers/net/ethernet/hisilicon/hns_mdio.c +++ b/drivers/net/ethernet/hisilicon/hns_mdio.c @@ -503,7 +503,7 @@ static int hns_mdio_probe(struct platform_device *pdev) return -ENODEV; } - mdio_dev = devm_kzalloc(&pdev->dev, sizeof(*mdio_dev), GFP_KERNEL); + mdio_dev = devm_kzalloc_obj(&pdev->dev, *mdio_dev); if (!mdio_dev) return -ENOMEM; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c index 998717f02136ff..9f12afb230657c 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c @@ -825,8 +825,8 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain, sema_init(&chain->sem, 1); - chain->cell_ctxt = devm_kcalloc(&pdev->dev, chain->num_cells, - sizeof(*chain->cell_ctxt), GFP_KERNEL); + chain->cell_ctxt = devm_kzalloc_objs(&pdev->dev, *chain->cell_ctxt, + chain->num_cells); if (!chain->cell_ctxt) return -ENOMEM; @@ -874,7 +874,7 @@ static struct hinic_api_cmd_chain * return ERR_PTR(-EINVAL); } - chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); + chain = devm_kzalloc_obj(&pdev->dev, *chain); if (!chain) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c index d39eec9c62bf50..0c92fa2f82cecc 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c @@ -793,8 +793,8 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev, struct hinic_pfhwdev *pfhwdev; int err; - cmdq_ctxts = devm_kcalloc(&pdev->dev, HINIC_MAX_CMDQ_TYPES, - sizeof(*cmdq_ctxts), GFP_KERNEL); + cmdq_ctxts = devm_kzalloc_objs(&pdev->dev, *cmdq_ctxts, + HINIC_MAX_CMDQ_TYPES); if (!cmdq_ctxts) return -ENOMEM; @@ -888,8 +888,8 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif, if (!cmdqs->cmdq_buf_pool) return -ENOMEM; - cmdqs->saved_wqs = devm_kcalloc(&pdev->dev, HINIC_MAX_CMDQ_TYPES, - sizeof(*cmdqs->saved_wqs), GFP_KERNEL); + cmdqs->saved_wqs = devm_kzalloc_objs(&pdev->dev, *cmdqs->saved_wqs, + HINIC_MAX_CMDQ_TYPES); if (!cmdqs->saved_wqs) { err = -ENOMEM; goto err_saved_wqs; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c index 27795288c58614..cb443eb0c4b805 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c @@ -164,9 +164,8 @@ static int init_msix(struct hinic_hwdev *hwdev) if (nr_irqs > HINIC_HWIF_NUM_IRQS(hwif)) nr_irqs = HINIC_HWIF_NUM_IRQS(hwif); - hwdev->msix_entries = devm_kcalloc(&pdev->dev, nr_irqs, - sizeof(*hwdev->msix_entries), - GFP_KERNEL); + hwdev->msix_entries = devm_kzalloc_objs(&pdev->dev, + *hwdev->msix_entries, nr_irqs); if (!hwdev->msix_entries) return -ENOMEM; @@ -909,7 +908,7 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev, struct devlink *devli struct hinic_hwif *hwif; int err, num_aeqs; - hwif = devm_kzalloc(&pdev->dev, sizeof(*hwif), GFP_KERNEL); + hwif = devm_kzalloc_obj(&pdev->dev, *hwif); if (!hwif) return ERR_PTR(-ENOMEM); @@ -919,7 +918,7 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev, struct devlink *devli return ERR_PTR(err); } - pfhwdev = devm_kzalloc(&pdev->dev, sizeof(*pfhwdev), GFP_KERNEL); + pfhwdev = devm_kzalloc_obj(&pdev->dev, *pfhwdev); if (!pfhwdev) { err = -ENOMEM; goto err_pfhwdev_alloc; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.c index 28114a59347e76..ca113cd53f5678 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.c @@ -633,13 +633,13 @@ static int alloc_eq_pages(struct hinic_eq *eq) u32 init_val, addr, val; int err, pg; - eq->dma_addr = devm_kcalloc(&pdev->dev, eq->num_pages, - sizeof(*eq->dma_addr), GFP_KERNEL); + eq->dma_addr = devm_kzalloc_objs(&pdev->dev, *eq->dma_addr, + eq->num_pages); if (!eq->dma_addr) return -ENOMEM; - eq->virt_addr = devm_kcalloc(&pdev->dev, eq->num_pages, - sizeof(*eq->virt_addr), GFP_KERNEL); + eq->virt_addr = devm_kzalloc_objs(&pdev->dev, *eq->virt_addr, + eq->num_pages); if (!eq->virt_addr) { err = -ENOMEM; goto err_virt_addr_alloc; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c index c4a0ba6e183a9c..a52d9b6d782825 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c @@ -378,27 +378,27 @@ int hinic_io_create_qps(struct hinic_func_to_io *func_to_io, void *ci_addr_base; int i, j, err; - func_to_io->qps = devm_kcalloc(&pdev->dev, num_qps, - sizeof(*func_to_io->qps), GFP_KERNEL); + func_to_io->qps = devm_kzalloc_objs(&pdev->dev, *func_to_io->qps, + num_qps); if (!func_to_io->qps) return -ENOMEM; - func_to_io->sq_wq = devm_kcalloc(&pdev->dev, num_qps, - sizeof(*func_to_io->sq_wq), GFP_KERNEL); + func_to_io->sq_wq = devm_kzalloc_objs(&pdev->dev, *func_to_io->sq_wq, + num_qps); if (!func_to_io->sq_wq) { err = -ENOMEM; goto err_sq_wq; } - func_to_io->rq_wq = devm_kcalloc(&pdev->dev, num_qps, - sizeof(*func_to_io->rq_wq), GFP_KERNEL); + func_to_io->rq_wq = devm_kzalloc_objs(&pdev->dev, *func_to_io->rq_wq, + num_qps); if (!func_to_io->rq_wq) { err = -ENOMEM; goto err_rq_wq; } - func_to_io->sq_db = devm_kcalloc(&pdev->dev, num_qps, - sizeof(*func_to_io->sq_db), GFP_KERNEL); + func_to_io->sq_db = devm_kzalloc_objs(&pdev->dev, *func_to_io->sq_db, + num_qps); if (!func_to_io->sq_db) { err = -ENOMEM; goto err_sq_db; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c index e1a1735c00c1c6..c54c71f5075be0 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c @@ -192,19 +192,19 @@ static int alloc_page_arrays(struct hinic_wqs *wqs) struct hinic_hwif *hwif = wqs->hwif; struct pci_dev *pdev = hwif->pdev; - wqs->page_paddr = devm_kcalloc(&pdev->dev, wqs->num_pages, - sizeof(*wqs->page_paddr), GFP_KERNEL); + wqs->page_paddr = devm_kzalloc_objs(&pdev->dev, *wqs->page_paddr, + wqs->num_pages); if (!wqs->page_paddr) return -ENOMEM; - wqs->page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages, - sizeof(*wqs->page_vaddr), GFP_KERNEL); + wqs->page_vaddr = devm_kzalloc_objs(&pdev->dev, *wqs->page_vaddr, + wqs->num_pages); if (!wqs->page_vaddr) goto err_page_vaddr; - wqs->shadow_page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages, - sizeof(*wqs->shadow_page_vaddr), - GFP_KERNEL); + wqs->shadow_page_vaddr = devm_kzalloc_objs(&pdev->dev, + *wqs->shadow_page_vaddr, + wqs->num_pages); if (!wqs->shadow_page_vaddr) goto err_page_shadow_vaddr; @@ -383,8 +383,8 @@ static int alloc_wqes_shadow(struct hinic_wq *wq) if (!wq->shadow_wqe) return -ENOMEM; - wq->shadow_idx = devm_kcalloc(&pdev->dev, wq->num_q_pages, - sizeof(*wq->shadow_idx), GFP_KERNEL); + wq->shadow_idx = devm_kzalloc_objs(&pdev->dev, *wq->shadow_idx, + wq->num_q_pages); if (!wq->shadow_idx) goto err_shadow_idx; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_main.c b/drivers/net/ethernet/huawei/hinic/hinic_main.c index 42f4792d255ba9..34ed5ea9e46efb 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_main.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c @@ -134,8 +134,8 @@ static int create_txqs(struct hinic_dev *nic_dev) if (nic_dev->txqs) return -EINVAL; - nic_dev->txqs = devm_kcalloc(&netdev->dev, num_txqs, - sizeof(*nic_dev->txqs), GFP_KERNEL); + nic_dev->txqs = devm_kzalloc_objs(&netdev->dev, *nic_dev->txqs, + num_txqs); if (!nic_dev->txqs) return -ENOMEM; @@ -231,8 +231,8 @@ static int create_rxqs(struct hinic_dev *nic_dev) if (nic_dev->rxqs) return -EINVAL; - nic_dev->rxqs = devm_kcalloc(&netdev->dev, num_rxqs, - sizeof(*nic_dev->rxqs), GFP_KERNEL); + nic_dev->rxqs = devm_kzalloc_objs(&netdev->dev, *nic_dev->rxqs, + num_rxqs); if (!nic_dev->rxqs) return -ENOMEM; @@ -308,7 +308,7 @@ static int hinic_rss_init(struct hinic_dev *nic_dev) u32 *indir_tbl; int err, i; - indir_tbl = kcalloc(HINIC_RSS_INDIR_SIZE, sizeof(u32), GFP_KERNEL); + indir_tbl = kzalloc_objs(u32, HINIC_RSS_INDIR_SIZE); if (!indir_tbl) return -ENOMEM; diff --git a/drivers/net/ethernet/huawei/hinic/hinic_tx.c b/drivers/net/ethernet/huawei/hinic/hinic_tx.c index 899d103f24803b..410a96c28ea37e 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_tx.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_tx.c @@ -864,13 +864,12 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq, txq->max_sges = HINIC_MAX_SQ_BUFDESCS; - txq->sges = devm_kcalloc(&netdev->dev, txq->max_sges, - sizeof(*txq->sges), GFP_KERNEL); + txq->sges = devm_kzalloc_objs(&netdev->dev, *txq->sges, txq->max_sges); if (!txq->sges) return -ENOMEM; - txq->free_sges = devm_kcalloc(&netdev->dev, txq->max_sges, - sizeof(*txq->free_sges), GFP_KERNEL); + txq->free_sges = devm_kzalloc_objs(&netdev->dev, *txq->free_sges, + txq->max_sges); if (!txq->free_sges) { err = -ENOMEM; goto err_alloc_free_sges; diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_rss.c b/drivers/net/ethernet/huawei/hinic3/hinic3_rss.c index 25db74d8c7ddb7..767e925fdb9047 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_rss.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_rss.c @@ -81,8 +81,7 @@ static int alloc_rss_resource(struct net_device *netdev) netdev_rss_key_fill(nic_dev->rss_hkey, L2NIC_RSS_KEY_SIZE); - nic_dev->rss_indir = kcalloc(L2NIC_RSS_INDIR_SIZE, sizeof(u16), - GFP_KERNEL); + nic_dev->rss_indir = kzalloc_objs(u16, L2NIC_RSS_INDIR_SIZE); if (!nic_dev->rss_indir) { kfree(nic_dev->rss_hkey); nic_dev->rss_hkey = NULL; diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c index 640618c0a09e9a..1b95b4d5deff53 100644 --- a/drivers/net/ethernet/ibm/emac/core.c +++ b/drivers/net/ethernet/ibm/emac/core.c @@ -2601,8 +2601,7 @@ static int emac_dt_phy_connect(struct emac_instance *dev, { struct phy_device *phy_dev; - dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def), - GFP_KERNEL); + dev->phy.def = devm_kzalloc_obj(&dev->ofdev->dev, *dev->phy.def); if (!dev->phy.def) return -ENOMEM; diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c index 236603a381bc2b..dc2154a8077bde 100644 --- a/drivers/net/ethernet/ibm/emac/mal.c +++ b/drivers/net/ethernet/ibm/emac/mal.c @@ -531,8 +531,7 @@ static int mal_probe(struct platform_device *ofdev) unsigned long irqflags; irq_handler_t hdlr_serr, hdlr_txde, hdlr_rxde; - mal = devm_kzalloc(&ofdev->dev, sizeof(struct mal_instance), - GFP_KERNEL); + mal = devm_kzalloc_obj(&ofdev->dev, struct mal_instance); if (!mal) return -ENOMEM; diff --git a/drivers/net/ethernet/ibm/emac/rgmii.c b/drivers/net/ethernet/ibm/emac/rgmii.c index b544dd8633b7b7..2ca97e45f277c5 100644 --- a/drivers/net/ethernet/ibm/emac/rgmii.c +++ b/drivers/net/ethernet/ibm/emac/rgmii.c @@ -219,8 +219,7 @@ static int rgmii_probe(struct platform_device *ofdev) struct rgmii_instance *dev; int err; - dev = devm_kzalloc(&ofdev->dev, sizeof(struct rgmii_instance), - GFP_KERNEL); + dev = devm_kzalloc_obj(&ofdev->dev, struct rgmii_instance); if (!dev) return -ENOMEM; diff --git a/drivers/net/ethernet/ibm/emac/tah.c b/drivers/net/ethernet/ibm/emac/tah.c index ed07532aaf85ec..31d8a0ac3928c1 100644 --- a/drivers/net/ethernet/ibm/emac/tah.c +++ b/drivers/net/ethernet/ibm/emac/tah.c @@ -89,8 +89,7 @@ static int tah_probe(struct platform_device *ofdev) struct tah_instance *dev; int err; - dev = devm_kzalloc(&ofdev->dev, sizeof(struct tah_instance), - GFP_KERNEL); + dev = devm_kzalloc_obj(&ofdev->dev, struct tah_instance); if (!dev) return -ENOMEM; diff --git a/drivers/net/ethernet/ibm/emac/zmii.c b/drivers/net/ethernet/ibm/emac/zmii.c index a3839cf02ec4b7..b6a6afaee90882 100644 --- a/drivers/net/ethernet/ibm/emac/zmii.c +++ b/drivers/net/ethernet/ibm/emac/zmii.c @@ -234,8 +234,7 @@ static int zmii_probe(struct platform_device *ofdev) struct zmii_instance *dev; int err; - dev = devm_kzalloc(&ofdev->dev, sizeof(struct zmii_instance), - GFP_KERNEL); + dev = devm_kzalloc_obj(&ofdev->dev, struct zmii_instance); if (!dev) return -ENOMEM; diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index e9874dfedf3787..05d6b60cd187df 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -171,7 +171,7 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool) { int i; - pool->free_map = kmalloc_array(pool->size, sizeof(u16), GFP_KERNEL); + pool->free_map = kmalloc_objs(u16, pool->size); if (!pool->free_map) return -1; diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c index c15ad95c63c110..925f10206cdd57 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c +++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c @@ -435,8 +435,7 @@ static int e1000_get_eeprom(struct net_device *netdev, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/e1000e/ethtool.c b/drivers/net/ethernet/intel/e1000e/ethtool.c index a8b35ae4114175..6f45a37b17d4c7 100644 --- a/drivers/net/ethernet/intel/e1000e/ethtool.c +++ b/drivers/net/ethernet/intel/e1000e/ethtool.c @@ -512,8 +512,7 @@ static int e1000_get_eeprom(struct net_device *netdev, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 51a05ce4c7ce8d..5f5f33b2a09737 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -320,22 +320,19 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, goto out; for (int i = 0; i < nr_frags; i++) { - struct skb_shared_info *skinfo = skb_shinfo(skb); skb_frag_t *frag = &sinfo->frags[i]; + unsigned int frag_size = skb_frag_size(frag); struct page *page; - void *addr; page = dev_alloc_page(); if (!page) { dev_kfree_skb(skb); - return NULL; + skb = NULL; + goto out; } - addr = page_to_virt(page); - memcpy(addr, skb_frag_page(frag), skb_frag_size(frag)); - - __skb_fill_page_desc_noacc(skinfo, skinfo->nr_frags++, - addr, 0, skb_frag_size(frag)); + memcpy(page_to_virt(page), skb_frag_address(frag), frag_size); + skb_add_rx_frag(skb, i, page, 0, frag_size, PAGE_SIZE); } out: @@ -354,7 +351,6 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring, struct sk_buff *skb; *rx_packets = 1; - *rx_bytes = xdp_get_buff_len(xdp_buff); if (likely(xdp_res == I40E_XDP_REDIR) || xdp_res == I40E_XDP_TX) return; @@ -469,21 +465,30 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) xsk_buff_set_size(bi, size); xsk_buff_dma_sync_for_cpu(bi); - if (!first) + if (++next_to_process == count) + next_to_process = 0; + + if (!first) { first = bi; - else if (!xsk_buff_add_frag(first, bi)) { + } else if (!xsk_buff_add_frag(first, bi)) { + /* Drop what has been gathered so far. xp_free() skips + * @bi if it duplicates a buffer that is already on a + * pool list. Remaining buffers of this packet, if any, + * will be processed as a new packet. + */ xsk_buff_free(first); - break; + xsk_buff_free(bi); + next_to_clean = next_to_process; + first = NULL; + continue; } - if (++next_to_process == count) - next_to_process = 0; - if (i40e_is_non_eop(rx_ring, rx_desc)) continue; xsk_buff_to_i40e_ctx(first)->desc = rx_desc; + rx_bytes = xdp_get_buff_len(first); xdp_res = i40e_run_xdp_zc(rx_ring, first, xdp_prog); i40e_handle_xdp_result_zc(rx_ring, first, rx_desc, &rx_packets, &rx_bytes, xdp_res, &failure); diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c index 8c2b63eef82bd5..a87a3e0a900c32 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c @@ -984,7 +984,7 @@ static int ice_devlink_rate_node_new(struct devlink_rate *rate_node, void **priv return -EBUSY; /* preallocate memory for ice_sched_node */ - node = devm_kzalloc(ice_hw_to_dev(pi->hw), sizeof(*node), GFP_KERNEL); + node = devm_kzalloc_obj(ice_hw_to_dev(pi->hw), *node); if (!node) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.c b/drivers/net/ethernet/intel/ice/ice_adapter.c index 536923b6ae979d..aa2d8addae5bef 100644 --- a/drivers/net/ethernet/intel/ice/ice_adapter.c +++ b/drivers/net/ethernet/intel/ice/ice_adapter.c @@ -72,6 +72,7 @@ static struct ice_adapter *ice_adapter_new(struct pci_dev *pdev) spin_lock_init(&adapter->txq_ctx_lock); for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++) mutex_init(&adapter->cpi_phy_lock[i]); + mutex_init(&adapter->cgu_synce_lock); refcount_set(&adapter->refcount, 1); spin_lock_init(&adapter->ports.lock); @@ -85,6 +86,7 @@ static void ice_adapter_free(struct ice_adapter *adapter) WARN_ON(!list_empty(&adapter->ports.list)); for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++) mutex_destroy(&adapter->cpi_phy_lock[i]); + mutex_destroy(&adapter->cgu_synce_lock); cleanup_srcu_struct(&adapter->ports.srcu); diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h index c61bd645e460de..fd5585005d91ba 100644 --- a/drivers/net/ethernet/intel/ice/ice_adapter.h +++ b/drivers/net/ethernet/intel/ice/ice_adapter.h @@ -41,6 +41,8 @@ struct ice_port_list { * @txq_ctx_lock: Spinlock protecting access to the GLCOMM_QTX_CNTX_CTL register * @cpi_phy_lock: Per-PHY mutex serializing CPI REQ/ACK transactions. * Index 0 = PHY0, index 1 = PHY1. Used on E825C devices. + * @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11, + * which all PFs reach. Used on E825C devices. * @ctrl_pf: Control PF of the adapter * @ports: Ports list * @index: 64-bit index cached for collision detection on 32bit systems @@ -53,6 +55,8 @@ struct ice_adapter { spinlock_t txq_ctx_lock; /* Serialize CPI REQ/ACK transactions per PHY (E825C only) */ struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS]; + /* Serialize changes of the SyncE CGU registers (E825C only) */ + struct mutex cgu_synce_lock; struct ice_pf *ctrl_pf; struct ice_port_list ports; diff --git a/drivers/net/ethernet/intel/ice/ice_arfs.c b/drivers/net/ethernet/intel/ice/ice_arfs.c index e0335f5e18fe43..46f4b2940b41f4 100644 --- a/drivers/net/ethernet/intel/ice/ice_arfs.c +++ b/drivers/net/ethernet/intel/ice/ice_arfs.c @@ -227,8 +227,9 @@ ice_arfs_update_flow_rules(struct ice_vsi *vsi, u16 idx, /* check if filter needs to be added to HW */ if (e->fltr_state == ICE_ARFS_INACTIVE) { enum ice_fltr_ptype flow_type = e->fltr_info.flow_type; - struct ice_arfs_entry_ptr *ep = - devm_kzalloc(dev, sizeof(*ep), GFP_ATOMIC); + struct ice_arfs_entry_ptr *ep = devm_kzalloc_obj(dev, + *ep, + GFP_ATOMIC); if (!ep) continue; @@ -305,9 +306,8 @@ ice_arfs_build_entry(struct ice_vsi *vsi, const struct flow_keys *fk, struct ice_ntuple_fltr *fltr_info; u8 ip_proto; - arfs_entry = devm_kzalloc(ice_pf_to_dev(vsi->back), - sizeof(*arfs_entry), - GFP_ATOMIC | __GFP_NOWARN); + arfs_entry = devm_kzalloc_obj(ice_pf_to_dev(vsi->back), *arfs_entry, + GFP_ATOMIC | __GFP_NOWARN); if (!arfs_entry) return NULL; diff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c index 04633103e3e610..90e01eb49ea210 100644 --- a/drivers/net/ethernet/intel/ice/ice_common.c +++ b/drivers/net/ethernet/intel/ice/ice_common.c @@ -824,8 +824,7 @@ static int ice_init_fltr_mgmt_struct(struct ice_hw *hw) struct ice_switch_info *sw; int status; - hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(*hw->switch_info), GFP_KERNEL); + hw->switch_info = devm_kzalloc_obj(ice_hw_to_dev(hw), *hw->switch_info); sw = hw->switch_info; if (!sw) @@ -1032,9 +1031,8 @@ int ice_init_hw(struct ice_hw *hw) goto err_unroll_cqinit; if (!hw->port_info) - hw->port_info = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(*hw->port_info), - GFP_KERNEL); + hw->port_info = devm_kzalloc_obj(ice_hw_to_dev(hw), + *hw->port_info); if (!hw->port_info) { status = -ENOMEM; goto err_unroll_cqinit; diff --git a/drivers/net/ethernet/intel/ice/ice_controlq.c b/drivers/net/ethernet/intel/ice/ice_controlq.c index dcb837cadd1825..3e19aae6d5e915 100644 --- a/drivers/net/ethernet/intel/ice/ice_controlq.c +++ b/drivers/net/ethernet/intel/ice/ice_controlq.c @@ -151,8 +151,8 @@ ice_alloc_rq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq) /* We'll be allocating the buffer info memory first, then we can * allocate the mapped buffers for the event processing */ - cq->rq.dma_head = devm_kcalloc(ice_hw_to_dev(hw), cq->num_rq_entries, - sizeof(cq->rq.desc_buf), GFP_KERNEL); + cq->rq.dma_head = devm_kzalloc_objs(ice_hw_to_dev(hw), cq->rq.desc_buf, + cq->num_rq_entries); if (!cq->rq.dma_head) return -ENOMEM; cq->rq.r.rq_bi = (struct ice_dma_mem *)cq->rq.dma_head; @@ -221,8 +221,8 @@ ice_alloc_sq_bufs(struct ice_hw *hw, struct ice_ctl_q_info *cq) int i; /* No mapped memory needed yet, just the buffer info structures */ - cq->sq.dma_head = devm_kcalloc(ice_hw_to_dev(hw), cq->num_sq_entries, - sizeof(cq->sq.desc_buf), GFP_KERNEL); + cq->sq.dma_head = devm_kzalloc_objs(ice_hw_to_dev(hw), cq->sq.desc_buf, + cq->num_sq_entries); if (!cq->sq.dma_head) return -ENOMEM; cq->sq.r.sq_bi = (struct ice_dma_mem *)cq->sq.dma_head; diff --git a/drivers/net/ethernet/intel/ice/ice_ddp.c b/drivers/net/ethernet/intel/ice/ice_ddp.c index 3b2d9c43697927..d50c555851fbd9 100644 --- a/drivers/net/ethernet/intel/ice/ice_ddp.c +++ b/drivers/net/ethernet/intel/ice/ice_ddp.c @@ -692,7 +692,7 @@ struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw) struct ice_buf_build *bld; struct ice_buf_hdr *buf; - bld = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*bld), GFP_KERNEL); + bld = devm_kzalloc_obj(ice_hw_to_dev(hw), *bld); if (!bld) return NULL; @@ -857,8 +857,7 @@ int ice_get_sw_fv_list(struct ice_hw *hw, struct ice_prot_lkup_ext *lkups, if (j >= hw->blk[ICE_BLK_SW].es.fvw) break; if (i + 1 == lkups->n_val_words) { - fvl = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(*fvl), GFP_KERNEL); + fvl = devm_kzalloc_obj(ice_hw_to_dev(hw), *fvl); if (!fvl) goto err; fvl->fv_ptr = fv; diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index ade1fb3dd06743..5148e419f49a07 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -2027,7 +2027,7 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv, * * DPLL subsystem callback. Set proper signals to recover clock from port. * - * Context: Called under pf->dplls.lock + * Context: Called under pf->dplls.lock, acquires adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error @@ -2035,14 +2035,15 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv, static int ice_dpll_synce_update_e825c(struct ice_hw *hw, bool ena, u32 port_num, enum ice_synce_clk output) { + struct ice_pf *pf = hw->back; int err; + mutex_lock(&pf->adapter->cgu_synce_lock); /* configure the mux to deliver proper signal to DPLL from the MUX */ err = ice_tspll_cfg_bypass_mux_e825c(hw, ena, port_num, output); - if (err) - return err; - - err = ice_tspll_cfg_synce_ethdiv_e825c(hw, output); + if (!err) + err = ice_tspll_cfg_synce_ethdiv_e825c(hw, output); + mutex_unlock(&pf->adapter->cgu_synce_lock); if (err) return err; diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.h b/drivers/net/ethernet/intel/ice/ice_dpll.h index bce0bea9a664bc..3f9a993129acef 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.h +++ b/drivers/net/ethernet/intel/ice/ice_dpll.h @@ -158,6 +158,7 @@ struct ice_dpll { * txclk_notify_rwsem (read) * -> pf->dplls.lock * -> ctrl_pf->dplls.lock + * -> adapter->cgu_synce_lock * * - @lock serializes all DPLL state mutations on this PF. When the * controlling PF's lock must also be taken (e.g. updating the shared @@ -169,6 +170,9 @@ struct ice_dpll { * dpll_*_change_ntf() calls. ice_dpll_deinit() takes the write side * standalone (not nested under any other lock) to drain in-flight * readers before pins and the TXC DPLL device are freed. + * - adapter->cgu_synce_lock serializes changes of the CGU registers R10 and + * R11. All E825C PFs reach one CGU, so @lock, which is per PF, does not + * cover them. */ struct ice_dplls { struct kthread_worker *kworker; diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c index ad519a8513dbe6..8805f0efe97733 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c @@ -567,18 +567,16 @@ ice_fdir_alloc_flow_prof(struct ice_hw *hw, enum ice_fltr_ptype flow) return -EINVAL; if (!hw->fdir_prof) { - hw->fdir_prof = devm_kcalloc(ice_hw_to_dev(hw), - ICE_FLTR_PTYPE_MAX, - sizeof(*hw->fdir_prof), - GFP_KERNEL); + hw->fdir_prof = devm_kzalloc_objs(ice_hw_to_dev(hw), + *hw->fdir_prof, + ICE_FLTR_PTYPE_MAX); if (!hw->fdir_prof) return -ENOMEM; } if (!hw->fdir_prof[flow]) { - hw->fdir_prof[flow] = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(**hw->fdir_prof), - GFP_KERNEL); + hw->fdir_prof[flow] = devm_kzalloc_obj(ice_hw_to_dev(hw), + **hw->fdir_prof); if (!hw->fdir_prof[flow]) return -ENOMEM; } @@ -845,12 +843,11 @@ ice_create_init_fdir_rule(struct ice_pf *pf, enum ice_fltr_ptype flow) hw->fdir_prof[flow]->fdir_seg[0]) return -EINVAL; - seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL); + seg = devm_kzalloc_obj(dev, *seg); if (!seg) return -ENOMEM; - tun_seg = devm_kcalloc(dev, ICE_FD_HW_SEG_MAX, sizeof(*tun_seg), - GFP_KERNEL); + tun_seg = devm_kzalloc_objs(dev, *tun_seg, ICE_FD_HW_SEG_MAX); if (!tun_seg) { devm_kfree(dev, seg); return -ENOMEM; @@ -1311,12 +1308,11 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp, bool perfect_filter = false; int ret; - seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL); + seg = devm_kzalloc_obj(dev, *seg); if (!seg) return -ENOMEM; - tun_seg = devm_kcalloc(dev, ICE_FD_HW_SEG_MAX, sizeof(*tun_seg), - GFP_KERNEL); + tun_seg = devm_kzalloc_objs(dev, *tun_seg, ICE_FD_HW_SEG_MAX); if (!tun_seg) { devm_kfree(dev, seg); return -ENOMEM; @@ -2023,7 +2019,7 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd) return -ENOSPC; } - input = devm_kzalloc(dev, sizeof(*input), GFP_KERNEL); + input = devm_kzalloc_obj(dev, *input); if (!input) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_flex_pipe.c b/drivers/net/ethernet/intel/ice/ice_flex_pipe.c index bb1d12f952cf6d..2a054d3abd4667 100644 --- a/drivers/net/ethernet/intel/ice/ice_flex_pipe.c +++ b/drivers/net/ethernet/intel/ice/ice_flex_pipe.c @@ -2228,44 +2228,42 @@ int ice_init_hw_tbls(struct ice_hw *hw) xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF]; xlt1->count = blk_sizes[i].xlt1; - xlt1->ptypes = devm_kcalloc(ice_hw_to_dev(hw), xlt1->count, - sizeof(*xlt1->ptypes), GFP_KERNEL); + xlt1->ptypes = devm_kzalloc_objs(ice_hw_to_dev(hw), + *xlt1->ptypes, xlt1->count); if (!xlt1->ptypes) goto err; - xlt1->ptg_tbl = devm_kcalloc(ice_hw_to_dev(hw), ICE_MAX_PTGS, - sizeof(*xlt1->ptg_tbl), - GFP_KERNEL); + xlt1->ptg_tbl = devm_kzalloc_objs(ice_hw_to_dev(hw), + *xlt1->ptg_tbl, ICE_MAX_PTGS); if (!xlt1->ptg_tbl) goto err; - xlt1->t = devm_kcalloc(ice_hw_to_dev(hw), xlt1->count, - sizeof(*xlt1->t), GFP_KERNEL); + xlt1->t = devm_kzalloc_objs(ice_hw_to_dev(hw), *xlt1->t, + xlt1->count); if (!xlt1->t) goto err; xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF]; xlt2->count = blk_sizes[i].xlt2; - xlt2->vsis = devm_kcalloc(ice_hw_to_dev(hw), xlt2->count, - sizeof(*xlt2->vsis), GFP_KERNEL); + xlt2->vsis = devm_kzalloc_objs(ice_hw_to_dev(hw), *xlt2->vsis, + xlt2->count); if (!xlt2->vsis) goto err; - xlt2->vsig_tbl = devm_kcalloc(ice_hw_to_dev(hw), xlt2->count, - sizeof(*xlt2->vsig_tbl), - GFP_KERNEL); + xlt2->vsig_tbl = devm_kzalloc_objs(ice_hw_to_dev(hw), + *xlt2->vsig_tbl, xlt2->count); if (!xlt2->vsig_tbl) goto err; for (j = 0; j < xlt2->count; j++) INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst); - xlt2->t = devm_kcalloc(ice_hw_to_dev(hw), xlt2->count, - sizeof(*xlt2->t), GFP_KERNEL); + xlt2->t = devm_kzalloc_objs(ice_hw_to_dev(hw), *xlt2->t, + xlt2->count); if (!xlt2->t) goto err; @@ -2273,18 +2271,17 @@ int ice_init_hw_tbls(struct ice_hw *hw) prof->count = blk_sizes[i].prof_tcam; prof->max_prof_id = blk_sizes[i].prof_id; prof->cdid_bits = blk_sizes[i].prof_cdid_bits; - prof->t = devm_kcalloc(ice_hw_to_dev(hw), prof->count, - sizeof(*prof->t), GFP_KERNEL); + prof->t = devm_kzalloc_objs(ice_hw_to_dev(hw), *prof->t, + prof->count); if (!prof->t) goto err; prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF]; prof_redir->count = blk_sizes[i].prof_redir; - prof_redir->t = devm_kcalloc(ice_hw_to_dev(hw), - prof_redir->count, - sizeof(*prof_redir->t), - GFP_KERNEL); + prof_redir->t = devm_kzalloc_objs(ice_hw_to_dev(hw), + *prof_redir->t, + prof_redir->count); if (!prof_redir->t) goto err; @@ -2292,36 +2289,34 @@ int ice_init_hw_tbls(struct ice_hw *hw) es->sid = ice_blk_sids[i][ICE_SID_ES_OFF]; es->count = blk_sizes[i].es; es->fvw = blk_sizes[i].fvw; - es->t = devm_kcalloc(ice_hw_to_dev(hw), - (u32)(es->count * es->fvw), - sizeof(*es->t), GFP_KERNEL); + es->t = devm_kzalloc_objs(ice_hw_to_dev(hw), *es->t, + (u32)(es->count * es->fvw)); if (!es->t) goto err; - es->ref_count = devm_kcalloc(ice_hw_to_dev(hw), es->count, - sizeof(*es->ref_count), - GFP_KERNEL); + es->ref_count = devm_kzalloc_objs(ice_hw_to_dev(hw), + *es->ref_count, es->count); if (!es->ref_count) goto err; - es->symm = devm_kcalloc(ice_hw_to_dev(hw), es->count, - sizeof(*es->symm), GFP_KERNEL); + es->symm = devm_kzalloc_objs(ice_hw_to_dev(hw), *es->symm, + es->count); if (!es->symm) goto err; - es->written = devm_kcalloc(ice_hw_to_dev(hw), es->count, - sizeof(*es->written), GFP_KERNEL); + es->written = devm_kzalloc_objs(ice_hw_to_dev(hw), *es->written, + es->count); if (!es->written) goto err; - es->mask_ena = devm_kcalloc(ice_hw_to_dev(hw), es->count, - sizeof(*es->mask_ena), GFP_KERNEL); + es->mask_ena = devm_kzalloc_objs(ice_hw_to_dev(hw), + *es->mask_ena, es->count); if (!es->mask_ena) goto err; prof_id->count = blk_sizes[i].prof_id; - prof_id->id = devm_kcalloc(ice_hw_to_dev(hw), prof_id->count, - sizeof(*prof_id->id), GFP_KERNEL); + prof_id->id = devm_kzalloc_objs(ice_hw_to_dev(hw), *prof_id->id, + prof_id->count); if (!prof_id->id) goto err; } @@ -3086,7 +3081,7 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, ice_prof_inc_ref(hw, blk, prof_id); /* add profile info */ - prof = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*prof), GFP_KERNEL); + prof = devm_kzalloc_obj(ice_hw_to_dev(hw), *prof); if (!prof) { status = -ENOMEM; goto err_ice_add_prof; @@ -3270,8 +3265,7 @@ ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, struct ice_vsig_vsi *tmp = vsi_cur->next_vsi; struct ice_chs_chg *p; - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), - GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) return -ENOMEM; @@ -3426,8 +3420,7 @@ ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl, for (i = 0; i < map->ptg_cnt; i++) if (!hw->blk[blk].es.written[map->prof_id]) { /* add ES to change list */ - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), - GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) { status = -ENOMEM; goto err_ice_get_prof; @@ -3515,7 +3508,7 @@ ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk, goto err_ice_add_prof_to_lst; } - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) { status = -ENOMEM; goto err_ice_add_prof_to_lst; @@ -3554,7 +3547,7 @@ ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig, u16 orig_vsig; int status; - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) return -ENOMEM; @@ -3656,7 +3649,7 @@ ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable, return status; /* add TCAM to change list */ - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) return -ENOMEM; @@ -3828,7 +3821,7 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl, return -EEXIST; /* new VSIG profile structure */ - t = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*t), GFP_KERNEL); + t = devm_kzalloc_obj(ice_hw_to_dev(hw), *t); if (!t) return -ENOMEM; @@ -3849,7 +3842,7 @@ ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl, u16 tcam_idx; /* add TCAM to change list */ - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) { status = -ENOMEM; goto err_ice_add_prof_id_vsig; @@ -3933,7 +3926,7 @@ ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl, u16 new_vsig; int status; - p = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(ice_hw_to_dev(hw), *p); if (!p) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_flow.c b/drivers/net/ethernet/intel/ice/ice_flow.c index 121552c644cdbc..837716e3da4447 100644 --- a/drivers/net/ethernet/intel/ice/ice_flow.c +++ b/drivers/net/ethernet/intel/ice/ice_flow.c @@ -1472,8 +1472,7 @@ ice_flow_add_prof_sync(struct ice_hw *hw, enum ice_block blk, if (!params) return -ENOMEM; - params->prof = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*params->prof), - GFP_KERNEL); + params->prof = devm_kzalloc_obj(ice_hw_to_dev(hw), *params->prof); if (!params->prof) { status = -ENOMEM; goto free_params; @@ -1819,7 +1818,7 @@ ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id, /* Allocate memory for the entry being added and associate * the VSI to the found flow profile */ - e = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*e), GFP_KERNEL); + e = devm_kzalloc_obj(ice_hw_to_dev(hw), *e); if (!e) status = -ENOMEM; else @@ -2258,8 +2257,7 @@ ice_add_rss_list(struct ice_hw *hw, u16 vsi_handle, struct ice_flow_prof *prof) return 0; } - rss_cfg = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*rss_cfg), - GFP_KERNEL); + rss_cfg = devm_kzalloc_obj(ice_hw_to_dev(hw), *rss_cfg); if (!rss_cfg) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_fltr.c b/drivers/net/ethernet/intel/ice/ice_fltr.c index aff7a141c30df4..9bcd5d398a264a 100644 --- a/drivers/net/ethernet/intel/ice/ice_fltr.c +++ b/drivers/net/ethernet/intel/ice/ice_fltr.c @@ -34,7 +34,7 @@ ice_fltr_add_entry_to_list(struct device *dev, struct ice_fltr_info *info, { struct ice_fltr_list_entry *entry; - entry = devm_kzalloc(dev, sizeof(*entry), GFP_ATOMIC); + entry = devm_kzalloc_obj(dev, *entry, GFP_ATOMIC); if (!entry) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 7cd2dd066ef5ec..977cd8dd6e31bd 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -80,13 +80,11 @@ static int ice_vsi_alloc_arrays(struct ice_vsi *vsi) return 0; /* allocate memory for both Tx and Rx ring pointers */ - vsi->tx_rings = devm_kcalloc(dev, vsi->alloc_txq, - sizeof(*vsi->tx_rings), GFP_KERNEL); + vsi->tx_rings = devm_kzalloc_objs(dev, *vsi->tx_rings, vsi->alloc_txq); if (!vsi->tx_rings) return -ENOMEM; - vsi->rx_rings = devm_kcalloc(dev, vsi->alloc_rxq, - sizeof(*vsi->rx_rings), GFP_KERNEL); + vsi->rx_rings = devm_kzalloc_objs(dev, *vsi->rx_rings, vsi->alloc_rxq); if (!vsi->rx_rings) goto err_rings; @@ -96,20 +94,19 @@ static int ice_vsi_alloc_arrays(struct ice_vsi *vsi) * per CPU, regardless of queue count settings from user that might * have come from ethtool's set_channels() callback; */ - vsi->txq_map = devm_kcalloc(dev, (vsi->alloc_txq + num_possible_cpus()), - sizeof(*vsi->txq_map), GFP_KERNEL); + vsi->txq_map = devm_kzalloc_objs(dev, *vsi->txq_map, + (vsi->alloc_txq + num_possible_cpus())); if (!vsi->txq_map) goto err_txq_map; - vsi->rxq_map = devm_kcalloc(dev, vsi->alloc_rxq, - sizeof(*vsi->rxq_map), GFP_KERNEL); + vsi->rxq_map = devm_kzalloc_objs(dev, *vsi->rxq_map, vsi->alloc_rxq); if (!vsi->rxq_map) goto err_rxq_map; /* allocate memory for q_vector pointers */ - vsi->q_vectors = devm_kcalloc(dev, vsi->num_q_vectors, - sizeof(*vsi->q_vectors), GFP_KERNEL); + vsi->q_vectors = devm_kzalloc_objs(dev, *vsi->q_vectors, + vsi->num_q_vectors); if (!vsi->q_vectors) goto err_vectors; @@ -731,7 +728,7 @@ struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf) goto unlock_pf; } - vsi = devm_kzalloc(dev, sizeof(*vsi), GFP_KERNEL); + vsi = devm_kzalloc_obj(dev, *vsi); if (!vsi) goto unlock_pf; diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 454fba07d4eccb..47c6798c97e8f1 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -2697,8 +2697,8 @@ int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog, int status, i; dev = ice_pf_to_dev(pf); - vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq, - sizeof(*vsi->xdp_rings), GFP_KERNEL); + vsi->xdp_rings = devm_kzalloc_objs(dev, *vsi->xdp_rings, + vsi->num_xdp_txq); if (!vsi->xdp_rings) return -ENOMEM; @@ -4912,13 +4912,12 @@ static int ice_alloc_vsis(struct ice_pf *pf) pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES; } - pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi), - GFP_KERNEL); + pf->vsi = devm_kzalloc_objs(dev, *pf->vsi, pf->num_alloc_vsi); if (!pf->vsi) return -ENOMEM; - pf->vsi_stats = devm_kcalloc(dev, pf->num_alloc_vsi, - sizeof(*pf->vsi_stats), GFP_KERNEL); + pf->vsi_stats = devm_kzalloc_objs(dev, *pf->vsi_stats, + pf->num_alloc_vsi); if (!pf->vsi_stats) { devm_kfree(dev, pf->vsi); return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_nvm.c b/drivers/net/ethernet/intel/ice/ice_nvm.c index 21f3b615dbbf19..6d472d4f43b544 100644 --- a/drivers/net/ethernet/intel/ice/ice_nvm.c +++ b/drivers/net/ethernet/intel/ice/ice_nvm.c @@ -805,7 +805,7 @@ ice_get_netlist_info(struct ice_hw *hw, enum ice_bank_select bank, return status; node_count &= ICE_LINK_TOPO_NODE_COUNT_M; - id_blk = kcalloc(ICE_NETLIST_ID_BLK_SIZE, sizeof(*id_blk), GFP_KERNEL); + id_blk = kzalloc_objs(*id_blk, ICE_NETLIST_ID_BLK_SIZE); if (!id_blk) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index 7980eaf9ce2535..8908b4f3db353c 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -1350,6 +1350,7 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup) int pin, err; mutex_lock(&pf->dplls.lock); + mutex_lock(&pf->adapter->cgu_synce_lock); for (pin = 0; pin < ICE_SYNCE_CLK_NUM; pin++) { enum ice_synce_clk clk_pin; bool active; @@ -1368,14 +1369,19 @@ void ice_ptp_link_change(struct ice_pf *pf, bool linkup) break; } + /* The divider is shared, set it only for our port */ + if (!active) + continue; + err = ice_tspll_cfg_synce_ethdiv_e825c(hw, clk_pin); - if (active && err) { + if (err) { dev_err_once(ice_pf_to_dev(pf), "Failed to configure SyncE ETH divider for pin %d, err %d\n", pin, err); break; } } + mutex_unlock(&pf->adapter->cgu_synce_lock); mutex_unlock(&pf->dplls.lock); if (linkup) @@ -2549,9 +2555,9 @@ static void ice_ptp_set_funcs_e810(struct ice_pf *pf) } err = 0; } else { - desc = devm_kcalloc(ice_pf_to_dev(pf), ICE_N_PINS_MAX, - sizeof(struct ice_ptp_pin_desc), - GFP_KERNEL); + desc = devm_kzalloc_objs(ice_pf_to_dev(pf), + struct ice_ptp_pin_desc, + ICE_N_PINS_MAX); if (!desc) goto err; diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c index ffa18d86729a0d..a5c7a4e1cebab1 100644 --- a/drivers/net/ethernet/intel/ice/ice_sched.c +++ b/drivers/net/ethernet/intel/ice/ice_sched.c @@ -24,12 +24,12 @@ ice_sched_add_root_node(struct ice_port_info *pi, hw = pi->hw; - root = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*root), GFP_KERNEL); + root = devm_kzalloc_obj(ice_hw_to_dev(hw), *root); if (!root) return -ENOMEM; - root->children = devm_kcalloc(ice_hw_to_dev(hw), hw->max_children[0], - sizeof(*root->children), GFP_KERNEL); + root->children = devm_kzalloc_objs(ice_hw_to_dev(hw), *root->children, + hw->max_children[0]); if (!root->children) { devm_kfree(ice_hw_to_dev(hw), root); return -ENOMEM; @@ -202,13 +202,13 @@ ice_sched_add_node(struct ice_port_info *pi, u8 layer, if (prealloc_node) node = prealloc_node; else - node = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*node), GFP_KERNEL); + node = devm_kzalloc_obj(ice_hw_to_dev(hw), *node); if (!node) return -ENOMEM; if (hw->max_children[layer]) { - node->children = devm_kcalloc(ice_hw_to_dev(hw), - hw->max_children[layer], - sizeof(*node->children), GFP_KERNEL); + node->children = devm_kzalloc_objs(ice_hw_to_dev(hw), + *node->children, + hw->max_children[layer]); if (!node->children) { devm_kfree(ice_hw_to_dev(hw), node); return -ENOMEM; @@ -583,8 +583,7 @@ ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs) return -EINVAL; /* allocate LAN queue contexts */ if (!vsi_ctx->lan_q_ctx[tc]) { - q_ctx = devm_kcalloc(ice_hw_to_dev(hw), new_numqs, - sizeof(*q_ctx), GFP_KERNEL); + q_ctx = devm_kzalloc_objs(ice_hw_to_dev(hw), *q_ctx, new_numqs); if (!q_ctx) return -ENOMEM; @@ -601,8 +600,7 @@ ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs) if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) { u16 prev_num = vsi_ctx->num_lan_q_entries[tc]; - q_ctx = devm_kcalloc(ice_hw_to_dev(hw), new_numqs, - sizeof(*q_ctx), GFP_KERNEL); + q_ctx = devm_kzalloc_objs(ice_hw_to_dev(hw), *q_ctx, new_numqs); if (!q_ctx) return -ENOMEM; @@ -639,10 +637,8 @@ ice_alloc_rdma_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs) return -EINVAL; /* allocate RDMA queue contexts */ if (!vsi_ctx->rdma_q_ctx[tc]) { - vsi_ctx->rdma_q_ctx[tc] = devm_kcalloc(ice_hw_to_dev(hw), - new_numqs, - sizeof(*q_ctx), - GFP_KERNEL); + vsi_ctx->rdma_q_ctx[tc] = devm_kzalloc_objs(ice_hw_to_dev(hw), + *q_ctx, new_numqs); if (!vsi_ctx->rdma_q_ctx[tc]) return -ENOMEM; vsi_ctx->num_rdma_q_entries[tc] = new_numqs; @@ -652,8 +648,7 @@ ice_alloc_rdma_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs) if (new_numqs > vsi_ctx->num_rdma_q_entries[tc]) { u16 prev_num = vsi_ctx->num_rdma_q_entries[tc]; - q_ctx = devm_kcalloc(ice_hw_to_dev(hw), new_numqs, - sizeof(*q_ctx), GFP_KERNEL); + q_ctx = devm_kzalloc_objs(ice_hw_to_dev(hw), *q_ctx, new_numqs); if (!q_ctx) return -ENOMEM; memcpy(q_ctx, vsi_ctx->rdma_q_ctx[tc], @@ -1353,7 +1348,7 @@ int ice_sched_query_res_alloc(struct ice_hw *hw) if (hw->layer_info) return status; - buf = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*buf), GFP_KERNEL); + buf = devm_kzalloc_obj(ice_hw_to_dev(hw), *buf); if (!buf) return -ENOMEM; @@ -2738,8 +2733,7 @@ ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id, agg_info = ice_get_agg_info(hw, agg_id); if (!agg_info) { /* Create new entry for new aggregator ID */ - agg_info = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*agg_info), - GFP_KERNEL); + agg_info = devm_kzalloc_obj(ice_hw_to_dev(hw), *agg_info); if (!agg_info) return -ENOMEM; @@ -2922,8 +2916,8 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); if (!agg_vsi_info) { /* Create new entry for VSI under aggregator list */ - agg_vsi_info = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(*agg_vsi_info), GFP_KERNEL); + agg_vsi_info = devm_kzalloc_obj(ice_hw_to_dev(hw), + *agg_vsi_info); if (!agg_vsi_info) return -EINVAL; @@ -3340,8 +3334,7 @@ ice_sched_add_rl_profile(struct ice_port_info *pi, return rl_prof_elem; /* Create new profile ID */ - rl_prof_elem = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*rl_prof_elem), - GFP_KERNEL); + rl_prof_elem = devm_kzalloc_obj(ice_hw_to_dev(hw), *rl_prof_elem); if (!rl_prof_elem) return NULL; diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index 4daee252e2a63c..d873eda9af8260 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -1463,8 +1463,8 @@ int ice_init_def_sw_recp(struct ice_hw *hw) struct ice_sw_recipe *recps; u8 i; - recps = devm_kcalloc(ice_hw_to_dev(hw), ICE_MAX_NUM_RECIPES, - sizeof(*recps), GFP_KERNEL); + recps = devm_kzalloc_objs(ice_hw_to_dev(hw), *recps, + ICE_MAX_NUM_RECIPES); if (!recps) return -ENOMEM; @@ -1771,8 +1771,7 @@ ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, tmp_vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle); if (!tmp_vsi_ctx) { /* Create a new VSI context */ - tmp_vsi_ctx = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(*tmp_vsi_ctx), GFP_KERNEL); + tmp_vsi_ctx = devm_kzalloc_obj(ice_hw_to_dev(hw), *tmp_vsi_ctx); if (!tmp_vsi_ctx) { ice_aq_free_vsi(hw, vsi_ctx, false, cd); return -ENOMEM; @@ -2851,7 +2850,7 @@ ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi, struct ice_vsi_list_map_info *v_map; int i; - v_map = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*v_map), GFP_KERNEL); + v_map = devm_kzalloc_obj(ice_hw_to_dev(hw), *v_map); if (!v_map) return NULL; @@ -2981,8 +2980,7 @@ ice_create_pkt_fwd_rule(struct ice_hw *hw, GFP_KERNEL); if (!s_rule) return -ENOMEM; - fm_entry = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*fm_entry), - GFP_KERNEL); + fm_entry = devm_kzalloc_obj(ice_hw_to_dev(hw), *fm_entry); if (!fm_entry) { status = -ENOMEM; goto ice_create_pkt_fwd_rule_exit; @@ -4121,7 +4119,7 @@ ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle, /* this memory is freed up in the caller function * once filters for this VSI are removed */ - tmp = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*tmp), GFP_KERNEL); + tmp = devm_kzalloc_obj(ice_hw_to_dev(hw), *tmp); if (!tmp) return -ENOMEM; @@ -6231,9 +6229,8 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, NULL); if (status) goto err_ice_add_adv_rule; - adv_fltr = devm_kzalloc(ice_hw_to_dev(hw), - sizeof(struct ice_adv_fltr_mgmt_list_entry), - GFP_KERNEL); + adv_fltr = devm_kzalloc_obj(ice_hw_to_dev(hw), + struct ice_adv_fltr_mgmt_list_entry); if (!adv_fltr) { status = -ENOMEM; goto err_ice_add_adv_rule; diff --git a/drivers/net/ethernet/intel/ice/ice_tspll.c b/drivers/net/ethernet/intel/ice/ice_tspll.c index 85bacb7c3a7903..0bfbea43529523 100644 --- a/drivers/net/ethernet/intel/ice/ice_tspll.c +++ b/drivers/net/ethernet/intel/ice/ice_tspll.c @@ -746,6 +746,7 @@ int ice_tspll_init(struct ice_hw *hw) * * Check if given port is selected as recovered clock source for given output. * + * Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error @@ -774,8 +775,7 @@ int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, return -EINVAL; } - if (active_clk == port % hw->ptp.ports_per_phy + - ICE_CGU_BYPASS_MUX_OFFSET_E825C) + if (active_clk == port + ICE_CGU_BYPASS_MUX_OFFSET_E825C) *active = true; else *active = false; @@ -792,7 +792,7 @@ int ice_tspll_bypass_mux_active_e825c(struct ice_hw *hw, u8 port, bool *active, * * Set reference clock source and output clock selection. * - * Context: Called under pf->dplls.lock + * Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error @@ -898,7 +898,7 @@ static int ice_tspll_get_div_e825c(u16 link_speed, unsigned int *divider) * * Set the correct CGU divider for RCLKA or RCLKB. * - * Context: Called under pf->dplls.lock + * Context: Called under pf->dplls.lock and adapter->cgu_synce_lock * Return: * * 0 - success * * negative - error diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c b/drivers/net/ethernet/intel/ice/ice_txrx.c index a2c7c4962882da..35a480a1e17266 100644 --- a/drivers/net/ethernet/intel/ice/ice_txrx.c +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c @@ -482,8 +482,7 @@ int ice_setup_tx_ring(struct ice_tx_ring *tx_ring) /* warn if we are about to overwrite the pointer */ WARN_ON(tx_ring->tx_buf); tx_ring->tx_buf = - devm_kcalloc(dev, sizeof(*tx_ring->tx_buf), tx_ring->count, - GFP_KERNEL); + devm_kzalloc_objs(dev, *tx_ring->tx_buf, tx_ring->count); if (!tx_ring->tx_buf) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c index fb526cb847764f..92c6f83a7efec4 100644 --- a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c +++ b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c @@ -360,8 +360,7 @@ static int ice_set_svm(struct ice_hw *hw) return status; } - set_params = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*set_params), - GFP_KERNEL); + set_params = devm_kzalloc_obj(ice_hw_to_dev(hw), *set_params); if (!set_params) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/ethernet/intel/ice/ice_xsk.c index 0643017541c35a..0c1ce3e86a45bb 100644 --- a/drivers/net/ethernet/intel/ice/ice_xsk.c +++ b/drivers/net/ethernet/intel/ice/ice_xsk.c @@ -493,6 +493,11 @@ static int ice_xmit_xdp_tx_zc(struct xdp_buff *xdp, tx_desc->cmd_type_offset_bsz |= cpu_to_le64(ICE_TX_DESC_CMD_EOP << ICE_TXD_QW1_CMD_S); + /* Each frag is now freed via its own Tx buffer. Completing the head + * must not release what is on the pool's frag list at that time. + */ + xdp_buff_clear_frags_flag(head); + return ICE_XDP_TX; busy: @@ -592,6 +597,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, struct sk_buff *skb; u16 stat_err_bits; u16 vlan_tci; + u32 xdp_len; rx_desc = ICE_RX_DESC(rx_ring, ntc); @@ -618,8 +624,11 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, if (!first) { first = xdp; - } else if (likely(size) && !xsk_buff_add_frag(first, xdp)) { + } else if (unlikely(!size)) { + xsk_buff_free(xdp); + } else if (!xsk_buff_add_frag(first, xdp)) { xsk_buff_free(first); + xsk_buff_free(xdp); first = NULL; } @@ -631,6 +640,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, ((struct libeth_xdp_buff *)first)->desc = rx_desc; + xdp_len = xdp_get_buff_len(first); xdp_res = ice_run_xdp_zc(rx_ring, first, xdp_prog, xdp_ring, xsk_pool); if (likely(xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR))) { @@ -645,7 +655,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, goto construct_skb; } - total_rx_bytes += xdp_get_buff_len(first); + total_rx_bytes += xdp_len; total_rx_packets++; first = NULL; @@ -902,6 +912,11 @@ void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring) if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq)) xdp_rxq_info_unreg(&rx_ring->xdp_rxq); + if (rx_ring->xsk) { + xsk_buff_free(&rx_ring->xsk->base); + rx_ring->xsk = NULL; + } + while (ntc != ntu) { struct xdp_buff *xdp = *ice_xdp_buf(rx_ring, ntc); diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c index eca9eda04f3121..aeddb915282240 100644 --- a/drivers/net/ethernet/intel/ice/virt/fdir.c +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c @@ -174,18 +174,16 @@ ice_vc_fdir_alloc_prof(struct ice_vf *vf, enum ice_fltr_ptype flow) struct ice_vf_fdir *fdir = &vf->fdir; if (!fdir->fdir_prof) { - fdir->fdir_prof = devm_kcalloc(ice_pf_to_dev(vf->pf), - ICE_FLTR_PTYPE_MAX, - sizeof(*fdir->fdir_prof), - GFP_KERNEL); + fdir->fdir_prof = devm_kzalloc_objs(ice_pf_to_dev(vf->pf), + *fdir->fdir_prof, + ICE_FLTR_PTYPE_MAX); if (!fdir->fdir_prof) return -ENOMEM; } if (!fdir->fdir_prof[flow]) { - fdir->fdir_prof[flow] = devm_kzalloc(ice_pf_to_dev(vf->pf), - sizeof(**fdir->fdir_prof), - GFP_KERNEL); + fdir->fdir_prof[flow] = devm_kzalloc_obj(ice_pf_to_dev(vf->pf), + **fdir->fdir_prof); if (!fdir->fdir_prof[flow]) return -ENOMEM; } @@ -768,7 +766,7 @@ ice_vc_fdir_config_input_set(struct ice_vf *vf, struct virtchnl_fdir_add *fltr, return ret; } - seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL); + seg = devm_kzalloc_obj(dev, *seg); if (!seg) return -ENOMEM; @@ -2135,7 +2133,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg) goto err_exit; } - conf = devm_kzalloc(dev, sizeof(*conf), GFP_KERNEL); + conf = devm_kzalloc_obj(dev, *conf); if (!conf) { v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY; dev_dbg(dev, "Alloc conf for VF %d failed\n", vf->vf_id); diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index cd1b173e3b2761..523c0e0be884dd 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -31,7 +31,7 @@ static int idpf_init_vector_stack(struct idpf_adapter *adapter) stack->base = min_vec; stack->top = min_vec; - stack->vec_idx = kcalloc(stack->size, sizeof(u16), GFP_KERNEL); + stack->vec_idx = kzalloc_objs(u16, stack->size); if (!stack->vec_idx) { mutex_unlock(&adapter->vector_lock); @@ -378,7 +378,7 @@ int idpf_intr_req(struct idpf_adapter *adapter) adapter->mb_vector.v_idx = le16_to_cpu(adapter->caps.mailbox_vector_id); - vecids = kcalloc(actual_vecs, sizeof(u16), GFP_KERNEL); + vecids = kzalloc_objs(u16, actual_vecs); if (!vecids) { err = -ENOMEM; goto free_msix; @@ -1298,7 +1298,7 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, rsrc = &vport->dflt_qv_rsrc; rsrc->dev = &adapter->pdev->dev; - rsrc->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL); + rsrc->q_vector_idxs = kzalloc_objs(u16, num_max_q); if (!rsrc->q_vector_idxs) goto free_vport; diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index 885df6294ad94c..b346187bbf3018 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -4581,7 +4581,7 @@ static int idpf_vport_intr_init_vec_idx(struct idpf_vport *vport, } total_vecs = idpf_get_reserved_vecs(adapter); - vecids = kcalloc(total_vecs, sizeof(u16), GFP_KERNEL); + vecids = kzalloc_objs(u16, total_vecs); if (!vecids) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 928de868fa624e..c89783966bae3c 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -3042,7 +3042,7 @@ static int idpf_vport_params_buf_alloc(struct idpf_adapter *adapter) if (!adapter->vport_params_recvd) return -ENOMEM; - adapter->vport_ids = kcalloc(num_max_vports, sizeof(u32), GFP_KERNEL); + adapter->vport_ids = kzalloc_objs(u32, num_max_vports); if (!adapter->vport_ids) goto err_mem; @@ -3586,7 +3586,7 @@ int idpf_vport_queue_ids_init(struct idpf_vport *vport, u16 q_type; u32 *qids; - qids = kcalloc(IDPF_MAX_QIDS, sizeof(u32), GFP_KERNEL); + qids = kzalloc_objs(u32, IDPF_MAX_QIDS); if (!qids) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/idpf/xsk.c b/drivers/net/ethernet/intel/idpf/xsk.c index d95d3efdfd36fe..5a0a1d8a7a8668 100644 --- a/drivers/net/ethernet/intel/idpf/xsk.c +++ b/drivers/net/ethernet/intel/idpf/xsk.c @@ -134,6 +134,11 @@ void idpf_xsk_clear_queue(void *q, enum virtchnl2_queue_type type) if (!idpf_queue_has_clear(XSK, rxq)) return; + if (rxq->xsk) { + libeth_xsk_buff_free_slow(rxq->xsk); + rxq->xsk = NULL; + } + rxq->pool = NULL; break; case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER: diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c index 65014a54a6d11c..ccc7302dc7bdbf 100644 --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c @@ -748,8 +748,7 @@ static int igb_get_eeprom(struct net_device *netdev, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; @@ -3261,8 +3260,7 @@ static int igb_get_module_eeprom(struct net_device *netdev, first_word = ee->offset >> 1; last_word = (ee->offset + ee->len - 1) >> 1; - dataword = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + dataword = kmalloc_objs(u16, last_word - first_word + 1); if (!dataword) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/igb/igb_hwmon.c b/drivers/net/ethernet/intel/igb/igb_hwmon.c index 21a29a0ca7f491..3d257f509c364a 100644 --- a/drivers/net/ethernet/intel/igb/igb_hwmon.c +++ b/drivers/net/ethernet/intel/igb/igb_hwmon.c @@ -166,8 +166,7 @@ int igb_sysfs_init(struct igb_adapter *adapter) if (rc) goto exit; - igb_hwmon = devm_kzalloc(&adapter->pdev->dev, sizeof(*igb_hwmon), - GFP_KERNEL); + igb_hwmon = devm_kzalloc_obj(&adapter->pdev->dev, *igb_hwmon); if (!igb_hwmon) { rc = -ENOMEM; goto exit; diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index d4a897a8c82c63..131df3e09ba14a 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4102,8 +4102,7 @@ static int igb_sw_init(struct igb_adapter *adapter) igb_init_queue_configuration(adapter); /* Setup and initialize a copy of the hw vlan table array */ - adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32), - GFP_KERNEL); + adapter->shadow_vfta = kzalloc_objs(u32, E1000_VLAN_FILTER_TBL_SIZE); if (!adapter->shadow_vfta) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c index 89fe2788a565e0..4ebc0c7f5fc45f 100644 --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c @@ -475,8 +475,7 @@ static int igc_ethtool_get_eeprom(struct net_device *netdev, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c index 4d8ae5b56145ad..da8519065d8181 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c @@ -3340,7 +3340,7 @@ static int ixgbe_get_netlist_info(struct ixgbe_hw *hw, node_count &= IXGBE_LINK_TOPO_NODE_COUNT_M; - id_blk = kcalloc(IXGBE_NETLIST_ID_BLK_SIZE, sizeof(*id_blk), GFP_KERNEL); + id_blk = kzalloc_objs(*id_blk, IXGBE_NETLIST_ID_BLK_SIZE); if (!id_blk) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c index 36e43b5e88d1f0..c98c440ccb2069 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c @@ -1069,7 +1069,7 @@ static int ixgbe_get_eeprom(struct net_device *netdev, last_word = (eeprom->offset + eeprom->len - 1) >> 1; eeprom_len = last_word - first_word + 1; - eeprom_buff = kmalloc_array(eeprom_len, sizeof(u16), GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, eeprom_len); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c index 204844288c1659..5aefb77e346d45 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c @@ -159,8 +159,7 @@ int ixgbe_sysfs_init(struct ixgbe_adapter *adapter) if (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw)) goto exit; - ixgbe_hwmon = devm_kzalloc(&adapter->pdev->dev, sizeof(*ixgbe_hwmon), - GFP_KERNEL); + ixgbe_hwmon = devm_kzalloc_obj(&adapter->pdev->dev, *ixgbe_hwmon); if (ixgbe_hwmon == NULL) { rc = -ENOMEM; goto exit; diff --git a/drivers/net/ethernet/jme.c b/drivers/net/ethernet/jme.c index 25ec5f757c6828..acb4d41f56e100 100644 --- a/drivers/net/ethernet/jme.c +++ b/drivers/net/ethernet/jme.c @@ -1502,7 +1502,8 @@ jme_intr_msi(struct jme_adapter *jme, u32 intrstat) * all other events are ignored */ jwrite32(jme, JME_IEVE, intrstat); - schedule_work(&jme->linkch_task); + if (!test_bit(JME_FLAG_WOL_QUIESCE, &jme->flags)) + schedule_work(&jme->linkch_task); goto out_reenable; } @@ -1546,7 +1547,8 @@ jme_intr_msi(struct jme_adapter *jme, u32 intrstat) /* * Re-enable interrupt */ - jwrite32f(jme, JME_IENS, INTR_ENABLE); + if (!test_bit(JME_FLAG_WOL_QUIESCE, &jme->flags)) + jwrite32f(jme, JME_IENS, INTR_ENABLE); } static irqreturn_t @@ -1892,6 +1894,7 @@ jme_powersave_phy(struct jme_adapter *jme) jme_set_100m_half(jme); if (jme->reg_pmcs & (PMCS_LFEN | PMCS_LREN)) jme_wait_link(jme); + jme_mac_rxclk_on(jme); jme_clear_pm_enable_wol(jme); } else { jme_phy_off(jme); @@ -3158,6 +3161,21 @@ jme_shutdown(struct pci_dev *pdev) struct net_device *netdev = pci_get_drvdata(pdev); struct jme_adapter *jme = netdev_priv(netdev); + if (netif_running(netdev)) { + set_bit(JME_FLAG_WOL_QUIESCE, &jme->flags); + netif_device_detach(netdev); + netif_stop_queue(netdev); + jme_stop_irq(jme); + synchronize_irq(pdev->irq); + jme_stop_irq(jme); + cancel_work_sync(&jme->linkch_task); + tasklet_disable(&jme->pcc_task); + napi_disable(&jme->napi); + tasklet_disable(&jme->txclean_task); + tasklet_disable(&jme->rxclean_task); + tasklet_disable(&jme->rxempty_task); + } + jme_powersave_phy(jme); pci_pme_active(pdev, true); } @@ -3172,11 +3190,16 @@ jme_suspend(struct device *dev) if (!netif_running(netdev)) return 0; - atomic_dec(&jme->link_changing); - + set_bit(JME_FLAG_WOL_QUIESCE, &jme->flags); netif_device_detach(netdev); netif_stop_queue(netdev); jme_stop_irq(jme); + synchronize_irq(jme->pdev->irq); + jme_stop_irq(jme); + cancel_work_sync(&jme->linkch_task); + tasklet_disable(&jme->pcc_task); + napi_disable(&jme->napi); + atomic_dec(&jme->link_changing); tasklet_disable(&jme->txclean_task); tasklet_disable(&jme->rxclean_task); @@ -3215,6 +3238,7 @@ jme_resume(struct device *dev) return 0; jme_clear_pm_disable_wol(jme); + jme_mac_rxclk_off(jme); jme_phy_on(jme); if (test_bit(JME_FLAG_SSET, &jme->flags)) jme_set_link_ksettings(netdev, &jme->old_cmd); @@ -3226,8 +3250,11 @@ jme_resume(struct device *dev) atomic_inc(&jme->link_changing); - jme_reset_link(jme); + napi_enable(&jme->napi); + tasklet_enable(&jme->pcc_task); + clear_bit(JME_FLAG_WOL_QUIESCE, &jme->flags); + jme_reset_link(jme); jme_start_irq(jme); return 0; diff --git a/drivers/net/ethernet/jme.h b/drivers/net/ethernet/jme.h index 860494ff37144d..ec5dfddf732273 100644 --- a/drivers/net/ethernet/jme.h +++ b/drivers/net/ethernet/jme.h @@ -450,6 +450,7 @@ enum jme_flags_bits { JME_FLAG_SSET = 2, JME_FLAG_POLL = 5, JME_FLAG_SHUTDOWN = 6, + JME_FLAG_WOL_QUIESCE = 7, }; #define TX_TIMEOUT (5 * HZ) diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c index 38b4d65f58a540..ff6d0a086ca9d0 100644 --- a/drivers/net/ethernet/marvell/mv643xx_eth.c +++ b/drivers/net/ethernet/marvell/mv643xx_eth.c @@ -1868,7 +1868,7 @@ static void mv643xx_eth_program_multicast_filter(struct net_device *dev) goto promiscuous; /* Allocate both mc_spec and mc_other tables */ - mc_spec = kcalloc(128, sizeof(u32), GFP_ATOMIC); + mc_spec = kzalloc_objs(u32, 128, GFP_ATOMIC); if (!mc_spec) goto promiscuous; mc_other = &mc_spec[64]; @@ -2815,7 +2815,7 @@ static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) if (!np) return 0; - pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(&pdev->dev, *pd); if (!pd) return -ENOMEM; pdev->dev.platform_data = pd; @@ -2855,7 +2855,7 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev) pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n", mv643xx_eth_driver_version); - msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL); + msp = devm_kzalloc_obj(&pdev->dev, *msp); if (msp == NULL) return -ENOMEM; platform_set_drvdata(pdev, msp); diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index ea755cf05b9ef5..915c4c35364a02 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -5371,7 +5371,7 @@ static int mvneta_init(struct device *dev, struct mvneta_port *pp) /* Set port default values */ mvneta_defaults_set(pp); - pp->txqs = devm_kcalloc(dev, txq_number, sizeof(*pp->txqs), GFP_KERNEL); + pp->txqs = devm_kzalloc_objs(dev, *pp->txqs, txq_number); if (!pp->txqs) return -ENOMEM; @@ -5383,7 +5383,7 @@ static int mvneta_init(struct device *dev, struct mvneta_port *pp) txq->done_pkts_coal = MVNETA_TXDONE_COAL_PKTS; } - pp->rxqs = devm_kcalloc(dev, rxq_number, sizeof(*pp->rxqs), GFP_KERNEL); + pp->rxqs = devm_kzalloc_objs(dev, *pp->rxqs, rxq_number); if (!pp->rxqs) return -ENOMEM; @@ -5395,10 +5395,8 @@ static int mvneta_init(struct device *dev, struct mvneta_port *pp) rxq->pkts_coal = MVNETA_RX_COAL_PKTS; rxq->time_coal = MVNETA_RX_COAL_USEC; rxq->buf_virt_addr - = devm_kmalloc_array(pp->dev->dev.parent, - rxq->size, - sizeof(*rxq->buf_virt_addr), - GFP_KERNEL); + = devm_kmalloc_objs(pp->dev->dev.parent, + *rxq->buf_virt_addr, rxq->size); if (!rxq->buf_virt_addr) return -ENOMEM; } diff --git a/drivers/net/ethernet/marvell/mvneta_bm.c b/drivers/net/ethernet/marvell/mvneta_bm.c index d6d76fbf27b6a8..41d654041939ff 100644 --- a/drivers/net/ethernet/marvell/mvneta_bm.c +++ b/drivers/net/ethernet/marvell/mvneta_bm.c @@ -362,9 +362,9 @@ static int mvneta_bm_init(struct mvneta_bm *priv) mvneta_bm_default_set(priv); /* Allocate and initialize BM pools structures */ - priv->bm_pools = devm_kcalloc(&priv->pdev->dev, MVNETA_BM_POOLS_NUM, - sizeof(struct mvneta_bm_pool), - GFP_KERNEL); + priv->bm_pools = devm_kzalloc_objs(&priv->pdev->dev, + struct mvneta_bm_pool, + MVNETA_BM_POOLS_NUM); if (!priv->bm_pools) return -ENOMEM; @@ -426,7 +426,7 @@ static int mvneta_bm_probe(struct platform_device *pdev) struct mvneta_bm *priv; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(struct mvneta_bm), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct mvneta_bm); if (!priv) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 317af54369cfe2..35adcee9aa247e 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -687,8 +687,7 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv) } /* Allocate and initialize BM pools */ - priv->bm_pools = devm_kcalloc(dev, poolnum, - sizeof(*priv->bm_pools), GFP_KERNEL); + priv->bm_pools = devm_kzalloc_objs(dev, *priv->bm_pools, poolnum); if (!priv->bm_pools) return -ENOMEM; @@ -6030,8 +6029,7 @@ static int mvpp2_port_init(struct mvpp2_port *port) port->tx_time_coal = MVPP2_TXDONE_COAL_USEC; - port->txqs = devm_kcalloc(dev, port->ntxqs, sizeof(*port->txqs), - GFP_KERNEL); + port->txqs = devm_kzalloc_objs(dev, *port->txqs, port->ntxqs); if (!port->txqs) return -ENOMEM; @@ -6042,7 +6040,7 @@ static int mvpp2_port_init(struct mvpp2_port *port) int queue_phy_id = mvpp2_txq_phys(port->id, queue); struct mvpp2_tx_queue *txq; - txq = devm_kzalloc(dev, sizeof(*txq), GFP_KERNEL); + txq = devm_kzalloc_obj(dev, *txq); if (!txq) { err = -ENOMEM; goto err_free_percpu; @@ -6065,8 +6063,7 @@ static int mvpp2_port_init(struct mvpp2_port *port) port->txqs[queue] = txq; } - port->rxqs = devm_kcalloc(dev, port->nrxqs, sizeof(*port->rxqs), - GFP_KERNEL); + port->rxqs = devm_kzalloc_objs(dev, *port->rxqs, port->nrxqs); if (!port->rxqs) { err = -ENOMEM; goto err_free_percpu; @@ -6077,7 +6074,7 @@ static int mvpp2_port_init(struct mvpp2_port *port) struct mvpp2_rx_queue *rxq; /* Map physical Rx queue to port's logical Rx queue */ - rxq = devm_kzalloc(dev, sizeof(*rxq), GFP_KERNEL); + rxq = devm_kzalloc_obj(dev, *rxq); if (!rxq) { err = -ENOMEM; goto err_free_percpu; @@ -6984,9 +6981,8 @@ static int mvpp2_port_probe(struct platform_device *pdev, goto err_free_irq; } - port->ethtool_stats = devm_kcalloc(&pdev->dev, - MVPP2_N_ETHTOOL_STATS(ntxqs, nrxqs), - sizeof(u64), GFP_KERNEL); + port->ethtool_stats = devm_kzalloc_objs(&pdev->dev, u64, + MVPP2_N_ETHTOOL_STATS(ntxqs, nrxqs)); if (!port->ethtool_stats) { err = -ENOMEM; goto err_free_stats; @@ -7506,9 +7502,8 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) } /* Allocate and initialize aggregated TXQs */ - priv->aggr_txqs = devm_kcalloc(&pdev->dev, MVPP2_MAX_THREADS, - sizeof(*priv->aggr_txqs), - GFP_KERNEL); + priv->aggr_txqs = devm_kzalloc_objs(&pdev->dev, *priv->aggr_txqs, + MVPP2_MAX_THREADS); if (!priv->aggr_txqs) return -ENOMEM; @@ -7584,7 +7579,7 @@ static int mvpp2_probe(struct platform_device *pdev) int i, shared; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c index ad677cfddb4d7d..930800941816e1 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c @@ -2157,15 +2157,13 @@ int mvpp2_prs_default_init(struct platform_device *pdev, struct mvpp2 *priv) { int err, index, i; - priv->prs_shadow = devm_kcalloc(&pdev->dev, MVPP2_PRS_TCAM_SRAM_SIZE, - sizeof(*priv->prs_shadow), - GFP_KERNEL); + priv->prs_shadow = devm_kzalloc_objs(&pdev->dev, *priv->prs_shadow, + MVPP2_PRS_TCAM_SRAM_SIZE); if (!priv->prs_shadow) return -ENOMEM; - priv->prs_double_vlans = devm_kcalloc(&pdev->dev, sizeof(bool), - MVPP2_PRS_DBL_VLANS_MAX, - GFP_KERNEL); + priv->prs_double_vlans = devm_kzalloc_objs(&pdev->dev, bool, + MVPP2_PRS_DBL_VLANS_MAX); if (!priv->prs_double_vlans) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c index 95862aff49f1a3..fca0d1354fcf1b 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c @@ -395,7 +395,7 @@ int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv) struct mvpp2_tai *tai; int ret; - tai = devm_kzalloc(dev, sizeof(*tai), GFP_KERNEL); + tai = devm_kzalloc_obj(dev, *tai); if (!tai) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index ade394c2beba03..f6f6294238377c 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -1959,7 +1959,7 @@ static int cgx_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct cgx *cgx; int err, nvec; - cgx = devm_kzalloc(dev, sizeof(*cgx), GFP_KERNEL); + cgx = devm_kzalloc_obj(dev, *cgx); if (!cgx) return -ENOMEM; cgx->pdev = pdev; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c index b6fda42e44c71f..16b0ba6e1d414a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c @@ -398,7 +398,7 @@ int npc_cn20k_debugfs_init(struct rvu *rvu) debugfs_create_file("vidx2idx", 0444, rvu->rvu_dbg.npc, npc_priv, &npc_vidx2idx_map_fops); - dstats = devm_kzalloc(rvu->dev, sizeof(*dstats), GFP_KERNEL); + dstats = devm_kzalloc_obj(rvu->dev, *dstats); if (!dstats) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/mbox_init.c b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/mbox_init.c index 01f32adac59922..10ff6e113a17fb 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/mbox_init.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/mbox_init.c @@ -42,8 +42,7 @@ int cn20k_register_afvf_mbox_intr(struct rvu *rvu, int pf_vec_start) int err; /* irq data for 4 VFPF intr vectors */ - irq_data = devm_kcalloc(rvu->dev, 4, - sizeof(struct rvu_irq_data), GFP_KERNEL); + irq_data = devm_kzalloc_objs(rvu->dev, struct rvu_irq_data, 4); if (!irq_data) return -ENOMEM; @@ -174,8 +173,7 @@ int cn20k_register_afpf_mbox_intr(struct rvu *rvu) int intr_vec, ret, vec = 0; /* irq data for 4 PF intr vectors */ - irq_data = devm_kcalloc(rvu->dev, 4, - sizeof(struct rvu_irq_data), GFP_KERNEL); + irq_data = devm_kzalloc_objs(rvu->dev, struct rvu_irq_data, 4); if (!irq_data) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 7c829b1da3e52c..7a2a2e7335e0ed 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -2295,7 +2295,7 @@ static int __npc_subbank_alloc(struct rvu *rvu, struct npc_subbank *sb, /* 'save' array stores available indexes temporarily before * marking it as allocated */ - save = kcalloc(count, sizeof(u16), GFP_KERNEL); + save = kzalloc_objs(u16, count); if (!save) { rc = -ENOMEM; goto err1; @@ -3402,8 +3402,7 @@ static int npc_create_srch_order(int cnt) { int val = 0; - subbank_srch_order = kcalloc(cnt, sizeof(u32), - GFP_KERNEL); + subbank_srch_order = kzalloc_objs(u32, cnt); if (!subbank_srch_order) return -ENOMEM; @@ -3869,7 +3868,7 @@ static int npc_defrag_process(struct rvu *rvu, struct list_head *lh) /* Allocate an array to store newly allocated * free slots (mcam indexes) */ - save = kcalloc(cnt, sizeof(*save), GFP_KERNEL); + save = kzalloc_objs(*save, cnt); if (!save) { rc = -ENOMEM; goto err; @@ -4094,9 +4093,8 @@ int npc_cn20k_defrag(struct rvu *rvu) node[i].idx = i; node[i].key_type = sb->key_type; node[i].free_cnt = sb->free_cnt; - node[i].vidx = kcalloc(npc_priv->subbank_depth * 2, - sizeof(*node[i].vidx), - GFP_KERNEL); + node[i].vidx = kzalloc_objs(*node[i].vidx, + npc_priv->subbank_depth * 2); if (!node[i].vidx) { rc = -ENOMEM; goto free_vidx; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/common.h b/drivers/net/ethernet/marvell/octeontx2/af/common.h index 78e42549d9908d..1a378d78463db5 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/common.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/common.h @@ -84,7 +84,7 @@ static inline int qmem_alloc(struct device *dev, struct qmem **q, if (!qsize) return -EINVAL; - *q = devm_kzalloc(dev, sizeof(*qmem), GFP_KERNEL); + *q = devm_kzalloc_obj(dev, *qmem); if (!*q) return -ENOMEM; qmem = *q; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c index 30c672d526a0cf..6784c0a6be5470 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c @@ -1520,11 +1520,11 @@ static int mcs_probe(struct pci_dev *pdev, const struct pci_device_id *id) int lmac, err = 0; struct mcs *mcs; - mcs = devm_kzalloc(dev, sizeof(*mcs), GFP_KERNEL); + mcs = devm_kzalloc_obj(dev, *mcs); if (!mcs) return -ENOMEM; - mcs->hw = devm_kzalloc(dev, sizeof(struct hwinfo), GFP_KERNEL); + mcs->hw = devm_kzalloc_obj(dev, struct hwinfo); if (!mcs->hw) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c index fce22e314cac09..cd9cca5a9cf5cb 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c @@ -899,13 +899,13 @@ int rvu_mcs_init(struct rvu *rvu) mcs->rvu = rvu; /* Allocated memory for PFVF data */ - mcs->pf = devm_kcalloc(mcs->dev, hw->total_pfs, - sizeof(struct mcs_pfvf), GFP_KERNEL); + mcs->pf = devm_kzalloc_objs(mcs->dev, struct mcs_pfvf, + hw->total_pfs); if (!mcs->pf) return -ENOMEM; - mcs->vf = devm_kcalloc(mcs->dev, hw->total_vfs, - sizeof(struct mcs_pfvf), GFP_KERNEL); + mcs->vf = devm_kzalloc_objs(mcs->dev, struct mcs_pfvf, + hw->total_vfs); if (!mcs->vf) return -ENOMEM; } diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c index 30e148291581cf..777111caa8e37b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c @@ -628,8 +628,8 @@ static int rvu_setup_msix_resources(struct rvu *rvu) return err; /* Allocate memory for MSIX vector to RVU block LF mapping */ - pfvf->msix_lfmap = devm_kcalloc(rvu->dev, pfvf->msix.max, - sizeof(u16), GFP_KERNEL); + pfvf->msix_lfmap = devm_kzalloc_objs(rvu->dev, u16, + pfvf->msix.max); if (!pfvf->msix_lfmap) return -ENOMEM; @@ -665,8 +665,7 @@ static int rvu_setup_msix_resources(struct rvu *rvu) return err; pfvf->msix_lfmap = - devm_kcalloc(rvu->dev, pfvf->msix.max, - sizeof(u16), GFP_KERNEL); + devm_kzalloc_objs(rvu->dev, u16, pfvf->msix.max); if (!pfvf->msix_lfmap) return -ENOMEM; @@ -1095,16 +1094,14 @@ static int rvu_setup_hw_resources(struct rvu *rvu) } /* Allocate memory for PFVF data */ - rvu->pf = devm_kcalloc(rvu->dev, hw->total_pfs, - sizeof(struct rvu_pfvf), GFP_KERNEL); + rvu->pf = devm_kzalloc_objs(rvu->dev, struct rvu_pfvf, hw->total_pfs); if (!rvu->pf) { dev_err(rvu->dev, "%s: Failed to allocate memory for PF's rvu_pfvf struct\n", __func__); return -ENOMEM; } - rvu->hwvf = devm_kcalloc(rvu->dev, hw->total_vfs, - sizeof(struct rvu_pfvf), GFP_KERNEL); + rvu->hwvf = devm_kzalloc_objs(rvu->dev, struct rvu_pfvf, hw->total_vfs); if (!rvu->hwvf) { dev_err(rvu->dev, "%s: Failed to allocate memory for VF's rvu_pfvf struct\n", __func__); @@ -1128,8 +1125,7 @@ static int rvu_setup_hw_resources(struct rvu *rvu) continue; /* Allocate memory for block LF/slot to pcifunc mapping info */ - block->fn_map = devm_kcalloc(rvu->dev, block->lf.max, - sizeof(u16), GFP_KERNEL); + block->fn_map = devm_kzalloc_objs(rvu->dev, u16, block->lf.max); if (!block->fn_map) { err = -ENOMEM; goto msix_err; @@ -1239,7 +1235,7 @@ int rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue, struct admin_queue *aq; int err; - *ad_queue = devm_kzalloc(rvu->dev, sizeof(*aq), GFP_KERNEL); + *ad_queue = devm_kzalloc_obj(rvu->dev, *aq); if (!*ad_queue) return -ENOMEM; aq = *ad_queue; @@ -2599,7 +2595,7 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw, } if (!rvu->ng_rvu) { - ng_rvu_mbox = devm_kzalloc(rvu->dev, sizeof(*ng_rvu_mbox), GFP_KERNEL); + ng_rvu_mbox = devm_kzalloc_obj(rvu->dev, *ng_rvu_mbox); if (!ng_rvu_mbox) { err = -ENOMEM; goto free_bitmap; @@ -2653,15 +2649,13 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw, goto unmap_regions; } - mw->mbox_wrk = devm_kcalloc(rvu->dev, num, - sizeof(struct rvu_work), GFP_KERNEL); + mw->mbox_wrk = devm_kzalloc_objs(rvu->dev, struct rvu_work, num); if (!mw->mbox_wrk) { err = -ENOMEM; goto exit; } - mw->mbox_wrk_up = devm_kcalloc(rvu->dev, num, - sizeof(struct rvu_work), GFP_KERNEL); + mw->mbox_wrk_up = devm_kzalloc_objs(rvu->dev, struct rvu_work, num); if (!mw->mbox_wrk_up) { err = -ENOMEM; goto exit; @@ -3153,8 +3147,7 @@ static int rvu_register_interrupts(struct rvu *rvu) if (!rvu->irq_name) return -ENOMEM; - rvu->irq_allocated = devm_kcalloc(rvu->dev, rvu->num_vec, - sizeof(bool), GFP_KERNEL); + rvu->irq_allocated = devm_kzalloc_objs(rvu->dev, bool, rvu->num_vec); if (!rvu->irq_allocated) return -ENOMEM; @@ -3376,8 +3369,7 @@ static int rvu_flr_init(struct rvu *rvu) return -ENOMEM; num_devs = rvu->hw->total_pfs + pci_sriov_get_totalvfs(rvu->pdev); - rvu->flr_wrk = devm_kcalloc(rvu->dev, num_devs, - sizeof(struct rvu_work), GFP_KERNEL); + rvu->flr_wrk = devm_kzalloc_objs(rvu->dev, struct rvu_work, num_devs); if (!rvu->flr_wrk) { destroy_workqueue(rvu->flr_wq); return -ENOMEM; @@ -3564,13 +3556,13 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -EBUSY; } - rvu = devm_kzalloc(dev, sizeof(*rvu), GFP_KERNEL); + rvu = devm_kzalloc_obj(dev, *rvu); if (!rvu) { atomic_set(&device_bound, 0); return -ENOMEM; } - rvu->hw = devm_kzalloc(dev, sizeof(struct rvu_hwinfo), GFP_KERNEL); + rvu->hw = devm_kzalloc_obj(dev, struct rvu_hwinfo); if (!rvu->hw) { devm_kfree(dev, rvu); atomic_set(&device_bound, 0); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h index fb4870cd18e9e4..a6183674c35f04 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -76,8 +76,6 @@ static inline int rvu_pcifunc_pf_mask(struct pci_dev *pdev) #define RVU_AFPF 25 -#ifdef CONFIG_DEBUG_FS - struct dump_ctx { int lf; int id; @@ -112,7 +110,6 @@ struct rvu_debugfs { int npa_qsize_id; int nix_qsize_id; }; -#endif struct rvu_work { struct work_struct work; @@ -649,9 +646,7 @@ struct rvu { int mcs_blk_cnt; int cpt_pf_num; -#ifdef CONFIG_DEBUG_FS struct rvu_debugfs rvu_dbg; -#endif struct rvu_devlink *rvu_dl; /* RVU switch implementation over NPC with DMAC rules */ diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c index 33e3a627c3599c..b07e4068887fe1 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c @@ -3106,7 +3106,7 @@ static void rvu_dbg_cgx_init(struct rvu *rvu) rvu->rvu_dbg.cgx = debugfs_create_dir(dname, rvu->rvu_dbg.cgx_root); - ctx = devm_kzalloc(rvu->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(rvu->dev, *ctx); if (!ctx) continue; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c index 29559db6892907..199723d5ec947e 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c @@ -541,8 +541,7 @@ static int nix_setup_bpids(struct rvu *rvu, struct nix_hw *hw, int blkaddr) if (err) return err; - bp->fn_map = devm_kcalloc(rvu->dev, bp->bpids.max, - sizeof(u16), GFP_KERNEL); + bp->fn_map = devm_kzalloc_objs(rvu->dev, u16, bp->bpids.max); if (!bp->fn_map) goto free_bpids; @@ -3796,8 +3795,7 @@ static int nix_setup_txvlan(struct rvu *rvu, struct nix_hw *nix_hw) return -ENOMEM; /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */ - vlan->entry2pfvf_map = devm_kcalloc(rvu->dev, vlan->rsrc.max, - sizeof(u16), GFP_KERNEL); + vlan->entry2pfvf_map = devm_kzalloc_objs(rvu->dev, u16, vlan->rsrc.max); if (!vlan->entry2pfvf_map) goto free_mem; @@ -3847,8 +3845,8 @@ static int nix_setup_txschq(struct rvu *rvu, struct nix_hw *nix_hw, int blkaddr) /* Allocate memory for scheduler queues to * PF/VF pcifunc mapping info. */ - txsch->pfvf_map = devm_kcalloc(rvu->dev, txsch->schq.max, - sizeof(u32), GFP_KERNEL); + txsch->pfvf_map = devm_kzalloc_objs(rvu->dev, u32, + txsch->schq.max); if (!txsch->pfvf_map) return -ENOMEM; for (schq = 0; schq < txsch->schq.max; schq++) @@ -3909,8 +3907,7 @@ static int nix_af_mark_format_setup(struct rvu *rvu, struct nix_hw *nix_hw, total = (rvu_read64(rvu, blkaddr, NIX_AF_PSE_CONST) & 0xFF00) >> 8; nix_hw->mark_format.total = (u8)total; - nix_hw->mark_format.cfg = devm_kcalloc(rvu->dev, total, sizeof(u32), - GFP_KERNEL); + nix_hw->mark_format.cfg = devm_kzalloc_objs(rvu->dev, u32, total); if (!nix_hw->mark_format.cfg) return -ENOMEM; for (i = 0; i < NIX_MARK_CFG_MAX; i++) { @@ -5163,8 +5160,8 @@ static int rvu_nix_block_init(struct rvu *rvu, struct nix_hw *nix_hw) if (err) return err; - nix_hw->tx_credits = kcalloc(hw->cgx_links + hw->lbk_links, - sizeof(u64), GFP_KERNEL); + nix_hw->tx_credits = kzalloc_objs(u64, + hw->cgx_links + hw->lbk_links); if (!nix_hw->tx_credits) return -ENOMEM; @@ -5184,8 +5181,7 @@ int rvu_nix_init(struct rvu *rvu) int blkaddr = 0, err; int i = 0; - hw->nix = devm_kcalloc(rvu->dev, MAX_NIX_BLKS, sizeof(struct nix_hw), - GFP_KERNEL); + hw->nix = devm_kzalloc_objs(rvu->dev, struct nix_hw, MAX_NIX_BLKS); if (!hw->nix) return -ENOMEM; @@ -5805,8 +5801,8 @@ static int nix_setup_ipolicers(struct rvu *rvu, } hw->cap.ipolicer = true; - nix_hw->ipolicer = devm_kcalloc(rvu->dev, BAND_PROF_NUM_LAYERS, - sizeof(*ipolicer), GFP_KERNEL); + nix_hw->ipolicer = devm_kzalloc_objs(rvu->dev, *ipolicer, + BAND_PROF_NUM_LAYERS); if (!nix_hw->ipolicer) return -ENOMEM; @@ -5833,15 +5829,13 @@ static int nix_setup_ipolicers(struct rvu *rvu, if (err) return err; - ipolicer->pfvf_map = devm_kcalloc(rvu->dev, - ipolicer->band_prof.max, - sizeof(u16), GFP_KERNEL); + ipolicer->pfvf_map = devm_kzalloc_objs(rvu->dev, u16, + ipolicer->band_prof.max); if (!ipolicer->pfvf_map) return -ENOMEM; - ipolicer->match_id = devm_kcalloc(rvu->dev, - ipolicer->band_prof.max, - sizeof(u16), GFP_KERNEL); + ipolicer->match_id = devm_kzalloc_objs(rvu->dev, u16, + ipolicer->band_prof.max); if (!ipolicer->match_id) return -ENOMEM; @@ -5868,9 +5862,8 @@ static int nix_setup_ipolicers(struct rvu *rvu, if (layer != BAND_PROF_MID_LAYER) continue; - ipolicer->ref_count = devm_kcalloc(rvu->dev, - ipolicer->band_prof.max, - sizeof(u16), GFP_KERNEL); + ipolicer->ref_count = devm_kzalloc_objs(rvu->dev, u16, + ipolicer->band_prof.max); if (!ipolicer->ref_count) return -ENOMEM; } diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c index 42a601976db36b..7fadd0e1329cb1 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -1881,13 +1881,11 @@ static int npc_alloc_kpu_cam2_n_action2(struct rvu *rvu, int kpu_num, kpu = &adapter->kpu[kpu_num]; - kpu->cam2 = devm_kcalloc(rvu->dev, num_entries, - sizeof(*kpu->cam2), GFP_KERNEL); + kpu->cam2 = devm_kzalloc_objs(rvu->dev, *kpu->cam2, num_entries); if (!kpu->cam2) return -ENOMEM; - kpu->action2 = devm_kcalloc(rvu->dev, num_entries, - sizeof(*kpu->action2), GFP_KERNEL); + kpu->action2 = devm_kzalloc_objs(rvu->dev, *kpu->action2, num_entries); if (!kpu->action2) return -ENOMEM; @@ -1959,10 +1957,8 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu, fw = rvu->kpu_fwdata; /* Binary blob contains ikpu actions entries at start of data[0] */ - profile->ikpu2 = devm_kcalloc(rvu->dev, - ARRAY_SIZE(ikpu_action_entries), - sizeof(*profile->ikpu2), - GFP_KERNEL); + profile->ikpu2 = devm_kzalloc_objs(rvu->dev, *profile->ikpu2, + ARRAY_SIZE(ikpu_action_entries)); if (!profile->ikpu2) return -ENOMEM; @@ -2088,7 +2084,7 @@ static int npc_apply_custom_kpu(struct rvu *rvu, *fw_kpus = fw->kpus; - sfw = devm_kcalloc(rvu->dev, 1, sizeof(*sfw), GFP_KERNEL); + sfw = devm_kzalloc_objs(rvu->dev, *sfw, 1); if (!sfw) return -ENOMEM; @@ -2443,8 +2439,7 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr) mcam->bmap_fcnt = mcam->bmap_entries; /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */ - mcam->entry2pfvf_map = kcalloc(mcam->bmap_entries, sizeof(u16), - GFP_KERNEL); + mcam->entry2pfvf_map = kzalloc_objs(u16, mcam->bmap_entries); if (!mcam->entry2pfvf_map) goto free_bmap_reverse; @@ -2470,27 +2465,23 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr) if (err) goto free_entry_map; - mcam->cntr2pfvf_map = kcalloc(mcam->counters.max, sizeof(u16), - GFP_KERNEL); + mcam->cntr2pfvf_map = kzalloc_objs(u16, mcam->counters.max); if (!mcam->cntr2pfvf_map) goto free_cntr_bmap; /* Alloc memory for MCAM entry to counter mapping and for tracking * counter's reference count. */ - mcam->entry2cntr_map = kcalloc(mcam->total_entries, sizeof(u16), - GFP_KERNEL); + mcam->entry2cntr_map = kzalloc_objs(u16, mcam->total_entries); if (!mcam->entry2cntr_map) goto free_cntr_map; - mcam->cntr_refcnt = kcalloc(mcam->counters.max, sizeof(u16), - GFP_KERNEL); + mcam->cntr_refcnt = kzalloc_objs(u16, mcam->counters.max); if (!mcam->cntr_refcnt) goto free_entry_cntr_map; /* Alloc memory for saving target device of mcam rule */ - mcam->entry2target_pffunc = kcalloc(mcam->total_entries, - sizeof(u16), GFP_KERNEL); + mcam->entry2target_pffunc = kzalloc_objs(u16, mcam->total_entries); if (!mcam->entry2target_pffunc) goto free_cntr_refcnt; @@ -2704,8 +2695,7 @@ int rvu_npc_init(struct rvu *rvu) rvu_alloc_rsrc(&pkind->rsrc); /* Allocate mem for pkind to PF and channel mapping info */ - pkind->pfchan_map = devm_kcalloc(rvu->dev, pkind->rsrc.max, - sizeof(u32), GFP_KERNEL); + pkind->pfchan_map = devm_kzalloc_objs(rvu->dev, u32, pkind->rsrc.max); if (!pkind->pfchan_map) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c index bbfd8231aed5ce..b760ce095826b9 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c @@ -71,9 +71,8 @@ int rvu_sdp_init(struct rvu *rvu) sdp_pf_num[i] = pdev->bus->number - 1; pfvf = &rvu->pf[sdp_pf_num[i]]; - pfvf->sdp_info = devm_kzalloc(rvu->dev, - sizeof(struct sdp_node_info), - GFP_KERNEL); + pfvf->sdp_info = devm_kzalloc_obj(rvu->dev, + struct sdp_node_info); if (!pfvf->sdp_info) { pci_dev_put(pdev); return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_switch.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_switch.c index 49ce38685a7e6b..f8304391c708c6 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_switch.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_switch.c @@ -183,8 +183,7 @@ void rvu_switch_enable(struct rvu *rvu) goto free_entries; } - rswitch->entry2pcifunc = kcalloc(alloc_req.count, sizeof(u16), - GFP_KERNEL); + rswitch->entry2pcifunc = kzalloc_objs(u16, alloc_req.count); if (!rswitch->entry2pcifunc) goto free_entries; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c b/drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c index e92b77789f088c..6698e0ee3f1527 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c @@ -176,8 +176,7 @@ int cn20k_register_pfvf_mbox_intr(struct otx2_nic *pf, int numvfs) char *irq_name; /* irq data for 4 PF intr vectors */ - irq_data = devm_kcalloc(pf->dev, 4, - sizeof(struct pf_irq_data), GFP_KERNEL); + irq_data = devm_kzalloc_objs(pf->dev, struct pf_irq_data, 4); if (!irq_data) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index c85436457286e2..6bc42e7a354729 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -1198,8 +1198,8 @@ int otx2_config_nix_queues(struct otx2_nic *pfvf) NIX_LF_CQ_OP_STATUS); /* Initialize work queue for receive buffer refill */ - pfvf->refill_wrk = devm_kcalloc(pfvf->dev, pfvf->qset.cq_cnt, - sizeof(struct refill_work), GFP_KERNEL); + pfvf->refill_wrk = devm_kzalloc_objs(pfvf->dev, struct refill_work, + pfvf->qset.cq_cnt); if (!pfvf->refill_wrk) return -ENOMEM; @@ -1525,8 +1525,8 @@ int otx2_pool_aq_init(struct otx2_nic *pfvf, u16 pool_id, if (xsk_pool) { pool->xsk_pool = xsk_pool; pool->xdp_cnt = numptrs; - pool->xdp = devm_kcalloc(pfvf->dev, - numptrs, sizeof(struct xdp_buff *), GFP_KERNEL); + pool->xdp = devm_kzalloc_objs(pfvf->dev, struct xdp_buff *, + numptrs); if (!pool->xdp) return -ENOMEM; } @@ -1687,8 +1687,8 @@ int otx2_config_npa(struct otx2_nic *pfvf) if (!hw->pool_cnt) return -EINVAL; - qset->pool = devm_kcalloc(pfvf->dev, hw->pool_cnt, - sizeof(struct otx2_pool), GFP_KERNEL); + qset->pool = devm_kzalloc_objs(pfvf->dev, struct otx2_pool, + hw->pool_cnt); if (!qset->pool) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c index 6d095023d17b98..74d83498af6ac4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c @@ -172,8 +172,7 @@ int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 count) if (!count) return 0; - flow_cfg->flow_ent = devm_kmalloc_array(pfvf->dev, count, - sizeof(u16), GFP_KERNEL); + flow_cfg->flow_ent = devm_kmalloc_objs(pfvf->dev, u16, count); if (!flow_cfg->flow_ent) { netdev_err(pfvf->netdev, "%s: Unable to allocate memory for flow entries\n", @@ -314,8 +313,7 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf) count = flow_cfg->ucast_flt_cnt + OTX2_MAX_VLAN_FLOWS + vf_vlan_max_flows; - flow_cfg->def_ent = devm_kmalloc_array(pfvf->dev, count, - sizeof(u16), GFP_KERNEL); + flow_cfg->def_ent = devm_kmalloc_objs(pfvf->dev, u16, count); if (!flow_cfg->def_ent) return -ENOMEM; @@ -427,9 +425,7 @@ int otx2vf_mcam_flow_init(struct otx2_nic *pfvf) { struct otx2_flow_config *flow_cfg; - pfvf->flow_cfg = devm_kzalloc(pfvf->dev, - sizeof(struct otx2_flow_config), - GFP_KERNEL); + pfvf->flow_cfg = devm_kzalloc_obj(pfvf->dev, struct otx2_flow_config); if (!pfvf->flow_cfg) return -ENOMEM; @@ -452,8 +448,7 @@ int otx2_mcam_flow_init(struct otx2_nic *pf) { int err; - pf->flow_cfg = devm_kzalloc(pf->dev, sizeof(struct otx2_flow_config), - GFP_KERNEL); + pf->flow_cfg = devm_kzalloc_obj(pf->dev, struct otx2_flow_config); if (!pf->flow_cfg) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c index 7dc0ce669d0b76..cb602a4adcfb80 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -281,8 +281,7 @@ static int otx2_pf_flr_init(struct otx2_nic *pf, int num_vfs) if (!pf->flr_wq) return -ENOMEM; - pf->flr_wrk = devm_kcalloc(pf->dev, num_vfs, - sizeof(struct flr_work), GFP_KERNEL); + pf->flr_wrk = devm_kzalloc_objs(pf->dev, struct flr_work, num_vfs); if (!pf->flr_wrk) { destroy_workqueue(pf->flr_wq); return -ENOMEM; @@ -603,8 +602,7 @@ static int otx2_pfvf_mbox_init(struct otx2_nic *pf, int numvfs) if (!numvfs) return -EINVAL; - pf->mbox_pfvf = devm_kcalloc(&pf->pdev->dev, numvfs, - sizeof(struct mbox), GFP_KERNEL); + pf->mbox_pfvf = devm_kzalloc_objs(&pf->pdev->dev, struct mbox, numvfs); if (!pf->mbox_pfvf) return -ENOMEM; @@ -3108,9 +3106,8 @@ static int otx2_sriov_vfcfg_init(struct otx2_nic *pf) { int i; - pf->vf_configs = devm_kcalloc(pf->dev, pf->total_vfs, - sizeof(struct otx2_vf_config), - GFP_KERNEL); + pf->vf_configs = devm_kzalloc_objs(pf->dev, struct otx2_vf_config, + pf->total_vfs); if (!pf->vf_configs) return -ENOMEM; @@ -3150,8 +3147,8 @@ int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf) if (!hw->irq_name) return -ENOMEM; - hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec, - sizeof(cpumask_var_t), GFP_KERNEL); + hw->affinity_mask = devm_kzalloc_objs(&hw->pdev->dev, cpumask_var_t, + num_vec); if (!hw->affinity_mask) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c index f7765e19d78a9e..abc1a3974930a8 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c @@ -628,8 +628,8 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err_free_netdev; } - hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec, - sizeof(cpumask_var_t), GFP_KERNEL); + hw->affinity_mask = devm_kzalloc_objs(&hw->pdev->dev, cpumask_var_t, + num_vec); if (!hw->affinity_mask) { err = -ENOMEM; goto err_free_netdev; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c index 2ede0b84e5f52d..8683d98d1eda17 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos.c @@ -841,9 +841,7 @@ static int otx2_qos_assign_base_idx_tl(struct otx2_nic *pfvf, /* allocate child index array */ child_cnt = node->child_dwrr_cnt + node->max_static_prio + 1; - child_idx_bmap = kcalloc(BITS_TO_LONGS(child_cnt), - sizeof(unsigned long), - GFP_KERNEL); + child_idx_bmap = kzalloc_objs(unsigned long, BITS_TO_LONGS(child_cnt)); if (!child_idx_bmap) return -ENOMEM; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c index 2872adabc83059..683efce519af01 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c @@ -75,7 +75,7 @@ static int otx2_qos_sq_aura_pool_init(struct otx2_nic *pfvf, int qidx) /* Allocate pointers and free them to aura/pool */ sq = &qset->sq[qidx]; sq->sqb_count = 0; - sq->sqb_ptrs = kcalloc(num_sqbs, sizeof(*sq->sqb_ptrs), GFP_KERNEL); + sq->sqb_ptrs = kzalloc_objs(*sq->sqb_ptrs, num_sqbs); if (!sq->sqb_ptrs) { err = -ENOMEM; goto pool_free; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c index 0f5d5642d3f7a1..b3beb2eb5173ec 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c @@ -47,7 +47,7 @@ static int rvu_rep_mcam_flow_init(struct rep_dev *rep) count = OTX2_DEFAULT_FLOWCOUNT; - rep->flow_cfg->flow_ent = kcalloc(count, sizeof(u16), GFP_KERNEL); + rep->flow_cfg->flow_ent = kzalloc_objs(u16, count); if (!rep->flow_cfg->flow_ent) return -ENOMEM; @@ -792,7 +792,7 @@ static int rvu_rep_probe(struct pci_dev *pdev, const struct pci_device_id *id) pci_set_master(pdev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) { err = -ENOMEM; goto err_set_drv_data; diff --git a/drivers/net/ethernet/marvell/prestera/prestera_pci.c b/drivers/net/ethernet/marvell/prestera/prestera_pci.c index 1ad0e62a8433ba..604718fcd5c059 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_pci.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_pci.c @@ -882,7 +882,7 @@ static int prestera_pci_probe(struct pci_dev *pdev, pci_set_master(pdev); - fw = devm_kzalloc(&pdev->dev, sizeof(*fw), GFP_KERNEL); + fw = devm_kzalloc_obj(&pdev->dev, *fw); if (!fw) { err = -ENOMEM; goto err_pci_dev_alloc; diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index ad0fdc4133fb68..21abeccfe094ca 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -2814,8 +2814,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag) ring->frag_size = mtk_max_frag_size(rx_data_len); ring->buf_size = mtk_max_buf_size(ring->frag_size); - ring->data = kcalloc(rx_dma_size, sizeof(*ring->data), - GFP_KERNEL); + ring->data = kzalloc_objs(*ring->data, rx_dma_size); if (!ring->data) return -ENOMEM; @@ -4880,9 +4879,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip)); mac->hwlro_ip_cnt = 0; - mac->hw_stats = devm_kzalloc(eth->dev, - sizeof(*mac->hw_stats), - GFP_KERNEL); + mac->hw_stats = devm_kzalloc_obj(eth->dev, *mac->hw_stats); if (!mac->hw_stats) { dev_err(eth->dev, "failed to allocate counter memory\n"); err = -ENOMEM; @@ -5120,7 +5117,7 @@ static int mtk_probe(struct platform_device *pdev) struct mtk_eth *eth; int err, i; - eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL); + eth = devm_kzalloc_obj(&pdev->dev, *eth); if (!eth) return -ENOMEM; diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c index 8451dc3fd00aa2..244522cb93d19f 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c @@ -754,8 +754,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash) hlist_for_each_entry_safe(entry, n, head, list) { if (entry->type == MTK_FLOW_TYPE_L2_SUBFLOW) { - if (unlikely(FIELD_GET(MTK_FOE_IB1_STATE, hwe->ib1) == - MTK_FOE_STATE_BIND)) + if (entry->hash != hash) continue; entry->hash = 0xffff; @@ -764,7 +763,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash) } if (found || !mtk_flow_entry_match(ppe->eth, entry, hwe)) { - if (entry->hash != 0xffff) + if (entry->hash == hash) entry->hash = 0xffff; continue; } @@ -885,7 +884,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) u32 foe_flow_size; void *foe; - ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL); + ppe = devm_kzalloc_obj(dev, *ppe); if (!ppe) return NULL; diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c index 53d3b7e00e1cdd..0bae2524779878 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed.c +++ b/drivers/net/ethernet/mediatek/mtk_wed.c @@ -257,7 +257,7 @@ mtk_wdma_rx_reset(struct mtk_wed_device *dev) wdma_w32(dev, MTK_WDMA_RESET_IDX, 0); for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) { - if (dev->rx_wdma[i].desc) + if (!dev->rx_wdma[i].desc) continue; wdma_w32(dev, @@ -535,8 +535,7 @@ mtk_wed_amsdu_buffer_alloc(struct mtk_wed_device *dev) if (!mtk_wed_is_v3_or_greater(hw)) return 0; - wed_amsdu = devm_kcalloc(hw->dev, MTK_WED_AMSDU_NPAGES, - sizeof(*wed_amsdu), GFP_KERNEL); + wed_amsdu = devm_kzalloc_objs(hw->dev, *wed_amsdu, MTK_WED_AMSDU_NPAGES); if (!wed_amsdu) return -ENOMEM; @@ -949,6 +948,14 @@ mtk_wed_free_ring(struct mtk_wed_device *dev, struct mtk_wed_ring *ring) static void mtk_wed_free_rx_rings(struct mtk_wed_device *dev) { + int i; + + for (i = 0; i < ARRAY_SIZE(dev->rx_ring); i++) + mtk_wed_free_ring(dev, &dev->rx_ring[i]); + + for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++) + mtk_wed_free_ring(dev, &dev->tx_wdma[i]); + mtk_wed_free_rx_buffer(dev); mtk_wed_free_ring(dev, &dev->rro.ring); } @@ -1938,7 +1945,7 @@ mtk_wed_wdma_tx_ring_setup(struct mtk_wed_device *dev, int idx, int size, wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_CPU_IDX, 0); wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_DMA_IDX, 0); - if (reset) + if (!mtk_wed_is_v3_or_greater(dev->hw) && reset) mtk_wed_ring_reset(wdma, MTK_WED_WDMA_RING_SIZE, true); if (!idx) { @@ -2337,7 +2344,20 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) if (!dev->rx_wdma[i].desc) - mtk_wed_wdma_rx_ring_setup(dev, i, 16, false); + if (mtk_wed_wdma_rx_ring_setup(dev, i, 16, false)) { + dev_err(dev->hw->dev, "wdma rx ring %d setup failed\n", i); + return; + } + + /* + * non-DBDC MT7986 allocates only rx_ring[1] and tx_wdma[1] during setup + * but tx_wdma[0] is also needed for WED to function. + */ + if (mtk_wed_is_v2(dev->hw) && !dev->rx_ring[0].desc) + if (mtk_wed_wdma_tx_ring_setup(dev, 0, MTK_WED_WDMA_RING_SIZE, !!dev->tx_wdma[0].desc)) { + dev_err(dev->hw->dev, "wdma tx ring 0 setup failed\n"); + return; + } if (dev->wlan.hw_rro) { for (i = 0; i < MTK_WED_RX_PAGE_QUEUES; i++) { diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c index 4f720ec53e20b4..07d302cc4ea53a 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c @@ -464,7 +464,7 @@ int mtk_wed_wo_init(struct mtk_wed_hw *hw) struct mtk_wed_wo *wo; int ret; - wo = devm_kzalloc(hw->dev, sizeof(*wo), GFP_KERNEL); + wo = devm_kzalloc_obj(hw->dev, *wo); if (!wo) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c b/drivers/net/ethernet/mellanox/mlx4/eq.c index f1c3da04de7f43..2ffdadca65cbc2 100644 --- a/drivers/net/ethernet/mellanox/mlx4/eq.c +++ b/drivers/net/ethernet/mellanox/mlx4/eq.c @@ -994,7 +994,7 @@ static int mlx4_create_eq(struct mlx4_dev *dev, int nent, for (i = 0; i < npages; ++i) eq->page_list[i].buf = NULL; - dma_list = kmalloc_array(npages, sizeof(*dma_list), GFP_KERNEL); + dma_list = kmalloc_objs(*dma_list, npages); if (!dma_list) goto err_out_free; diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c index 698a5d1f0d7e26..bbf9551b28c97a 100644 --- a/drivers/net/ethernet/mellanox/mlx4/mr.c +++ b/drivers/net/ethernet/mellanox/mlx4/mr.c @@ -106,10 +106,8 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order) buddy->max_order = max_order; spin_lock_init(&buddy->lock); - buddy->bits = kcalloc(buddy->max_order + 1, sizeof(*buddy->bits), - GFP_KERNEL); - buddy->num_free = kcalloc(buddy->max_order + 1, sizeof(*buddy->num_free), - GFP_KERNEL); + buddy->bits = kzalloc_objs(*buddy->bits, buddy->max_order + 1); + buddy->num_free = kzalloc_objs(*buddy->num_free, buddy->max_order + 1); if (!buddy->bits || !buddy->num_free) goto err_out; @@ -794,7 +792,7 @@ int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt, int err; int i; - page_list = kcalloc(buf->npages, sizeof(*page_list), GFP_KERNEL); + page_list = kzalloc_objs(*page_list, buf->npages); if (!page_list) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c index 5caf7820a136b5..159f79302a0801 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c @@ -911,10 +911,11 @@ static void mlx5e_build_rx_cq_param(struct mlx5_core_dev *mdev, static u8 rq_end_pad_mode(struct mlx5_core_dev *mdev, struct mlx5e_params *params) { - bool lro_en = params->packet_merge.type == MLX5E_PACKET_MERGE_LRO; + bool no_pad = params->packet_merge.type == MLX5E_PACKET_MERGE_LRO || + params->packet_merge.type == MLX5E_PACKET_MERGE_SHAMPO; bool ro = MLX5_CAP_GEN(mdev, relaxed_ordering_write); - return ro && lro_en ? + return ro && no_pad ? MLX5_WQ_END_PAD_MODE_NONE : MLX5_WQ_END_PAD_MODE_ALIGN; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/qos.c b/drivers/net/ethernet/mellanox/mlx5/core/en/qos.c index ac4979087e0dd7..3176549eff3efa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/qos.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/qos.c @@ -483,7 +483,7 @@ int mlx5e_mqprio_rl_init(struct mlx5e_mqprio_rl *rl, struct mlx5_core_dev *mdev, rl->mdev = mdev; rl->num_tc = num_tc; - rl->leaves_id = kvcalloc(num_tc, sizeof(*rl->leaves_id), GFP_KERNEL); + rl->leaves_id = kvzalloc_objs(*rl->leaves_id, num_tc); if (!rl->leaves_id) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rqt.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rqt.c index 8511363f7bec26..e11a86abb25cf3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rqt.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rqt.c @@ -157,13 +157,13 @@ int mlx5e_rqt_init_indir(struct mlx5e_rqt *rqt, struct mlx5_core_dev *mdev, u32 *rss_rqns, *rss_vhca_ids = NULL; int err; - rss_rqns = kvmalloc_array(indir->actual_table_size, sizeof(*rss_rqns), GFP_KERNEL); + rss_rqns = kvmalloc_objs(*rss_rqns, indir->actual_table_size); if (!rss_rqns) return -ENOMEM; if (vhca_ids) { - rss_vhca_ids = kvmalloc_array(indir->actual_table_size, sizeof(*rss_vhca_ids), - GFP_KERNEL); + rss_vhca_ids = kvmalloc_objs(*rss_vhca_ids, + indir->actual_table_size); if (!rss_vhca_ids) { kvfree(rss_rqns); return -ENOMEM; @@ -246,13 +246,13 @@ int mlx5e_rqt_redirect_indir(struct mlx5e_rqt *rqt, u32 *rqns, u32 *vhca_ids, if (WARN_ON(rqt->size != indir->max_table_size)) return -EINVAL; - rss_rqns = kvmalloc_array(indir->actual_table_size, sizeof(*rss_rqns), GFP_KERNEL); + rss_rqns = kvmalloc_objs(*rss_rqns, indir->actual_table_size); if (!rss_rqns) return -ENOMEM; if (vhca_ids) { - rss_vhca_ids = kvmalloc_array(indir->actual_table_size, sizeof(*rss_vhca_ids), - GFP_KERNEL); + rss_vhca_ids = kvmalloc_objs(*rss_vhca_ids, + indir->actual_table_size); if (!rss_vhca_ids) { kvfree(rss_rqns); return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c index e940635f5dcbce..85203947054487 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c @@ -347,14 +347,15 @@ static struct mlx5e_rx_res *mlx5e_rx_res_alloc(struct mlx5_core_dev *mdev, unsig if (!rx_res) return NULL; - rx_res->rss_rqns = kvcalloc(max_nch, sizeof(*rx_res->rss_rqns), GFP_KERNEL); + rx_res->rss_rqns = kvzalloc_objs(*rx_res->rss_rqns, max_nch); if (!rx_res->rss_rqns) { kvfree(rx_res); return NULL; } if (multi_vhca) { - rx_res->rss_vhca_ids = kvcalloc(max_nch, sizeof(*rx_res->rss_vhca_ids), GFP_KERNEL); + rx_res->rss_vhca_ids = kvzalloc_objs(*rx_res->rss_vhca_ids, + max_nch); if (!rx_res->rss_vhca_ids) { kvfree(rx_res->rss_rqns); kvfree(rx_res); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c index 7e991a09b3ff58..fa6cb51fdb939f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c @@ -771,53 +771,72 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, struct xfrm_state *x, struct netlink_ext_ack *extack) { + bool is_acq = x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ; struct mlx5e_ipsec_sa_entry *sa_entry = NULL; bool allow_tunnel_mode = false; + struct mlx5_core_dev *mdev; struct mlx5e_ipsec *ipsec; struct mlx5e_priv *priv; gfp_t gfp; int err; priv = netdev_priv(dev); - if (!priv->ipsec) - return -EOPNOTSUPP; + /* Profile cleanup can memset an already NULL mdev. */ + mdev = data_race(READ_ONCE(priv->mdev)); + /* NULL only during a profile change, which is an eswitch operation. */ + if (!mdev) { + NL_SET_ERR_MSG_MOD(extack, "Eswitch busy, can't add state"); + return -EBUSY; + } + + if (!is_acq) { + err = mlx5_eswitch_block_mode(mdev, false); + if (err) + return err; + } ipsec = priv->ipsec; - gfp = (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ) ? GFP_ATOMIC : GFP_KERNEL; + if (!ipsec) { + err = -EOPNOTSUPP; + goto unblock_mode; + } + + gfp = is_acq ? GFP_ATOMIC : GFP_KERNEL; sa_entry = kzalloc_obj(*sa_entry, gfp); - if (!sa_entry) - return -ENOMEM; + if (!sa_entry) { + err = -ENOMEM; + goto unblock_mode; + } sa_entry->x = x; sa_entry->dev = dev; sa_entry->ipsec = ipsec; /* Check if this SA is originated from acquire flow temporary SA */ - if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ) { + if (is_acq) { x->xso.offload_handle = (unsigned long)sa_entry; return 0; } - err = mlx5e_xfrm_validate_state(priv->mdev, x, extack); + err = mlx5e_xfrm_validate_state(mdev, x, extack); if (err) goto err_xfrm; - if (!mlx5_eswitch_block_ipsec(priv->mdev)) { + if (!mlx5_eswitch_block_ipsec(mdev)) { err = -EBUSY; goto err_xfrm; } - err = mlx5_eswitch_block_mode(priv->mdev); - if (err) - goto unblock_ipsec; - if (x->props.mode == XFRM_MODE_TUNNEL && x->xso.type == XFRM_DEV_OFFLOAD_PACKET) { - allow_tunnel_mode = mlx5e_ipsec_fs_tunnel_allowed(sa_entry); + err = mlx5e_ipsec_fs_tunnel_allowed(sa_entry); + if (err < 0) + goto unblock_ipsec; + allow_tunnel_mode = err; if (!allow_tunnel_mode) { NL_SET_ERR_MSG_MOD(extack, "Packet offload tunnel mode is disabled due to encap settings"); err = -EINVAL; - goto unblock_mode; + goto unblock_ipsec; } } @@ -874,9 +893,9 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, x->xso.offload_handle = (unsigned long)sa_entry; if (allow_tunnel_mode) - mlx5_eswitch_unblock_encap(priv->mdev); + mlx5_eswitch_unblock_encap(mdev); - mlx5_eswitch_unblock_mode(priv->mdev); + mlx5_eswitch_unblock_mode(mdev); return 0; @@ -892,14 +911,15 @@ static int mlx5e_xfrm_add_state(struct net_device *dev, kfree(sa_entry->work); unblock_encap: if (allow_tunnel_mode) - mlx5_eswitch_unblock_encap(priv->mdev); -unblock_mode: - mlx5_eswitch_unblock_mode(priv->mdev); + mlx5_eswitch_unblock_encap(mdev); unblock_ipsec: - mlx5_eswitch_unblock_ipsec(priv->mdev); + mlx5_eswitch_unblock_ipsec(mdev); err_xfrm: kfree(sa_entry); NL_SET_ERR_MSG_WEAK_MOD(extack, "Device failed to offload this state"); +unblock_mode: + if (!is_acq) + mlx5_eswitch_unblock_mode(mdev); return err; } @@ -1265,27 +1285,45 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, { struct net_device *netdev = x->xdo.dev; struct mlx5e_ipsec_pol_entry *pol_entry; + struct mlx5_core_dev *mdev; struct mlx5e_priv *priv; int err; priv = netdev_priv(netdev); + /* Profile cleanup can memset an already NULL mdev. */ + mdev = data_race(READ_ONCE(priv->mdev)); + if (!mdev) { + NL_SET_ERR_MSG_MOD(extack, "Eswitch busy, can't add policy"); + return -EBUSY; + } + + /* Block esw mode changes until the policy holds its own block. */ + err = mlx5_eswitch_block_mode(mdev, false); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Eswitch busy, can't add policy"); + return err; + } + if (!priv->ipsec) { NL_SET_ERR_MSG_MOD(extack, "Device doesn't support IPsec packet offload"); - return -EOPNOTSUPP; + err = -EOPNOTSUPP; + goto unblock_mode; } - err = mlx5e_xfrm_validate_policy(priv->mdev, x, extack); + err = mlx5e_xfrm_validate_policy(mdev, x, extack); if (err) - return err; + goto unblock_mode; pol_entry = kzalloc_obj(*pol_entry); - if (!pol_entry) - return -ENOMEM; + if (!pol_entry) { + err = -ENOMEM; + goto unblock_mode; + } pol_entry->x = x; pol_entry->ipsec = priv->ipsec; - if (!mlx5_eswitch_block_ipsec(priv->mdev)) { + if (!mlx5_eswitch_block_ipsec(mdev)) { err = -EBUSY; goto ipsec_busy; } @@ -1296,13 +1334,16 @@ static int mlx5e_xfrm_add_policy(struct xfrm_policy *x, goto err_fs; x->xdo.offload_handle = (unsigned long)pol_entry; + mlx5_eswitch_unblock_mode(mdev); return 0; err_fs: - mlx5_eswitch_unblock_ipsec(priv->mdev); + mlx5_eswitch_unblock_ipsec(mdev); ipsec_busy: kfree(pol_entry); NL_SET_ERR_MSG_MOD(extack, "Device failed to offload this policy"); +unblock_mode: + mlx5_eswitch_unblock_mode(mdev); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h index abcbd38db9dbbe..f4b2d7b950c009 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h @@ -320,7 +320,7 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry); int mlx5e_accel_ipsec_fs_add_pol(struct mlx5e_ipsec_pol_entry *pol_entry); void mlx5e_accel_ipsec_fs_del_pol(struct mlx5e_ipsec_pol_entry *pol_entry); void mlx5e_accel_ipsec_fs_modify(struct mlx5e_ipsec_sa_entry *sa_entry); -bool mlx5e_ipsec_fs_tunnel_allowed(struct mlx5e_ipsec_sa_entry *sa_entry); +int mlx5e_ipsec_fs_tunnel_allowed(struct mlx5e_ipsec_sa_entry *sa_entry); int mlx5_ipsec_create_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry); void mlx5_ipsec_free_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c index 8ffa8068e90ac9..5c69e89b13a725 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c @@ -720,6 +720,16 @@ static void ipsec_rx_sa_selector_destroy(struct mlx5_core_dev *mdev, mlx5_destroy_flow_table(rx->ft.sa_sel); } +static void +ipsec_rx_status_pass_dest_put(struct mlx5e_ipsec *ipsec, + struct mlx5e_ipsec_rx *rx, + u32 family) +{ + mlx5_ipsec_fs_roce_rx_destroy(ipsec->roce, family, ipsec->mdev); + if (rx == ipsec->rx_esw) + mlx5_esw_ipsec_rx_status_pass_dest_put(ipsec); +} + static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx *rx, u32 family) { @@ -739,13 +749,7 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, ipsec_rx_policy_destroy(rx); - mlx5_ipsec_fs_roce_rx_destroy(ipsec->roce, family, mdev); - -#ifdef CONFIG_MLX5_ESWITCH - if (rx == ipsec->rx_esw) - mlx5_chains_put_table(esw_chains(ipsec->mdev->priv.eswitch), - 0, 1, 0); -#endif + ipsec_rx_status_pass_dest_put(ipsec, rx, family); } static void ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec, @@ -1068,9 +1072,12 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, goto err_fs_ft_sa_sel; /* Create FT */ - if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL) - rx->allow_tunnel_mode = - mlx5_eswitch_block_encap(mdev, rx == ipsec->rx_esw); + if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL) { + err = mlx5_eswitch_block_encap(mdev, rx == ipsec->rx_esw); + if (err < 0) + goto err_fs_ft; + rx->allow_tunnel_mode = err; + } if (rx->allow_tunnel_mode) flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; @@ -1115,7 +1122,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, err_fs_ft_sa_sel: mlx5_destroy_flow_table(rx->ft.status); err_fs_ft_status: - mlx5_ipsec_fs_roce_rx_destroy(ipsec->roce, family, mdev); + ipsec_rx_status_pass_dest_put(ipsec, rx, family); return err; } @@ -1127,7 +1134,7 @@ static int rx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, if (rx->ft.refcnt) goto skip; - err = mlx5_eswitch_block_mode(mdev); + err = mlx5_eswitch_block_mode(mdev, true); if (err) return err; @@ -1311,9 +1318,12 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx, if (err) goto err_status_rule; - if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL) - tx->allow_tunnel_mode = - mlx5_eswitch_block_encap(mdev, tx == ipsec->tx_esw); + if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL) { + err = mlx5_eswitch_block_encap(mdev, tx == ipsec->tx_esw); + if (err < 0) + goto err_encap; + tx->allow_tunnel_mode = err; + } if (tx->allow_tunnel_mode) flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT; @@ -1383,6 +1393,7 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx, err_sa_ft: if (tx->allow_tunnel_mode) mlx5_eswitch_unblock_encap(mdev); +err_encap: mlx5_del_flow_rules(tx->status.rule); err_status_rule: mlx5_destroy_flow_table(tx->ft.status); @@ -1416,7 +1427,7 @@ static int tx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec, if (tx->ft.refcnt) goto skip; - err = mlx5_eswitch_block_mode(mdev); + err = mlx5_eswitch_block_mode(mdev, true); if (err) return err; @@ -2183,7 +2194,6 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry) } setup_fte_no_frags(spec); - setup_fte_upper_proto_match(spec, &attrs->upspec); switch (attrs->type) { case XFRM_DEV_OFFLOAD_CRYPTO: @@ -2196,6 +2206,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry) setup_fte_reg_a(spec); break; case XFRM_DEV_OFFLOAD_PACKET: + setup_fte_upper_proto_match(spec, &attrs->upspec); setup_fte_reg_c4(spec, attrs->reqid); err = setup_pkt_reformat(ipsec, attrs, &flow_act); if (err) @@ -2574,45 +2585,26 @@ void mlx5e_accel_ipsec_fs_read_stats(struct mlx5e_priv *priv, void *ipsec_stats) } } -#ifdef CONFIG_MLX5_ESWITCH static int mlx5e_ipsec_block_tc_offload(struct mlx5_core_dev *mdev) { - struct mlx5_eswitch *esw = mdev->priv.eswitch; - int err = 0; + int ret = 0; - if (esw) { - err = mlx5_esw_lock(esw); - if (err) - return err; - } - - if (mdev->num_block_ipsec) { - err = -EBUSY; - goto unlock; - } - - mdev->num_block_tc++; - -unlock: - if (esw) - mlx5_esw_unlock(esw); - - return err; -} -#else -static int mlx5e_ipsec_block_tc_offload(struct mlx5_core_dev *mdev) -{ - if (mdev->num_block_ipsec) - return -EBUSY; + spin_lock_bh(&mdev->offload_block.lock); + if (mdev->offload_block.num_block_ipsec) + ret = -EBUSY; + else + mdev->offload_block.num_block_tc++; + spin_unlock_bh(&mdev->offload_block.lock); - mdev->num_block_tc++; - return 0; + return ret; } -#endif static void mlx5e_ipsec_unblock_tc_offload(struct mlx5_core_dev *mdev) { - mdev->num_block_tc--; + spin_lock_bh(&mdev->offload_block.lock); + if (!WARN_ON_ONCE(!mdev->offload_block.num_block_tc)) + mdev->offload_block.num_block_tc--; + spin_unlock_bh(&mdev->offload_block.lock); } int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry) @@ -2850,7 +2842,7 @@ void mlx5e_accel_ipsec_fs_modify(struct mlx5e_ipsec_sa_entry *sa_entry) memcpy(sa_entry, &sa_entry_shadow, sizeof(*sa_entry)); } -bool mlx5e_ipsec_fs_tunnel_allowed(struct mlx5e_ipsec_sa_entry *sa_entry) +int mlx5e_ipsec_fs_tunnel_allowed(struct mlx5e_ipsec_sa_entry *sa_entry) { struct mlx5e_ipsec *ipsec = sa_entry->ipsec; struct xfrm_state *x = sa_entry->x; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c index 337201f128958f..3cc1213c2f682d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c @@ -139,7 +139,11 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) err = mlx5e_accel_fs_tcp_create(priv->fs); if (!err && !priv->ktls_rx_was_enabled) { priv->ktls_rx_was_enabled = true; - mlx5e_safe_reopen_channels(priv); + err = mlx5e_safe_reopen_channels(priv); + if (err) { + priv->ktls_rx_was_enabled = false; + mlx5e_accel_fs_tcp_destroy(priv->fs); + } } } else { mlx5e_accel_fs_tcp_destroy(priv->fs); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c index c19238bc821fbd..0f263cd06dfa5d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c @@ -187,7 +187,7 @@ static int mlx5e_vport_context_update_vlans(struct mlx5e_flow_steering *fs) list_size = max_list_size; } - vlans = kvcalloc(list_size, sizeof(*vlans), GFP_KERNEL); + vlans = kvzalloc_objs(*vlans, list_size); if (!vlans) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index c3c2c5720c6f32..d8563f86384473 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -5489,7 +5489,7 @@ static void mlx5e_get_queue_stats_rx(struct net_device *dev, int i, struct mlx5e_rq_stats *xskrq_stats; struct mlx5e_rq_stats *rq_stats; - if (mlx5e_is_uplink_rep(priv) || !mlx5e_stats_nch_read(priv)) + if (mlx5e_is_uplink_rep(priv) || i >= mlx5e_stats_nch_read(priv)) return; channel_stats = priv->channel_stats[i]; @@ -5521,6 +5521,9 @@ static void mlx5e_get_queue_stats_tx(struct net_device *dev, int i, * inactive sqs. */ sq_stats = priv->txq2sq_stats[i]; + if (!sq_stats) + return; + stats->packets = sq_stats->packets; stats->bytes = sq_stats->bytes; @@ -6038,9 +6041,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev, priv->dfs_root = debugfs_create_dir("nic", mlx5_debugfs_get_dev_root(mdev)); - fs = mlx5e_fs_init(priv->profile, mdev, - !test_bit(MLX5E_STATE_DESTROYING, &priv->state), - priv->dfs_root); + fs = mlx5e_fs_init(priv->profile, mdev, false, priv->dfs_root); if (!fs) { err = -ENOMEM; mlx5_core_err(mdev, "FS initialization failed, %d\n", err); @@ -6382,7 +6383,7 @@ int mlx5e_priv_init(struct mlx5e_priv *priv, node = dev_to_node(mlx5_core_dma_dev(mdev)); /* priv init */ - priv->mdev = mdev; + WRITE_ONCE(priv->mdev, mdev); priv->netdev = netdev; priv->max_nch = nch; priv->max_opened_tc = 1; @@ -6467,6 +6468,8 @@ void mlx5e_priv_cleanup(struct mlx5e_priv *priv) mlx5e_mqprio_rl_free(priv->mqprio_rl); } + /* Clear atomically before memset() for lockless XFRM readers. */ + WRITE_ONCE(priv->mdev, NULL); memset(priv, 0, sizeof(*priv)); if (destroying) /* restore destroying bit, to allow unload */ set_bit(MLX5E_STATE_DESTROYING, &priv->state); @@ -6555,10 +6558,6 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) int err; clear_bit(MLX5E_STATE_DESTROYING, &priv->state); - if (priv->fs) - mlx5e_fs_set_rx_mode_active(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, - &priv->state)); /* Validate the max_wqe_size_sq capability. */ if (WARN_ON_ONCE(mlx5e_get_max_sq_wqebbs(priv->mdev) < MLX5E_MAX_TX_WQEBBS)) { @@ -6619,6 +6618,9 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) if (err) goto err_cleanup_tx; + if (priv->fs) + mlx5e_fs_set_rx_mode_active(priv->fs, true); + if (profile->enable) { err = profile->enable(priv); if (err) @@ -6630,6 +6632,10 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) return 0; err_cleanup_rx: + if (priv->fs) { + mlx5e_fs_set_rx_mode_active(priv->fs, false); + cancel_work_sync(&priv->set_rx_mode_work); + } profile->cleanup_rx(priv); err_cleanup_tx: profile->cleanup_tx(priv); @@ -6637,10 +6643,6 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) out: mlx5e_reset_channels(priv->netdev); set_bit(MLX5E_STATE_DESTROYING, &priv->state); - if (priv->fs) - mlx5e_fs_set_rx_mode_active(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, - &priv->state)); cancel_work_sync(&priv->update_stats_work); return err; } @@ -6651,9 +6653,7 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv) set_bit(MLX5E_STATE_DESTROYING, &priv->state); if (priv->fs) - mlx5e_fs_set_rx_mode_active(priv->fs, - !test_bit(MLX5E_STATE_DESTROYING, - &priv->state)); + mlx5e_fs_set_rx_mode_active(priv->fs, false); if (profile->disable) profile->disable(priv); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index 88a170e40bd936..c7b4a8a827738b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -238,6 +238,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport_rep) MLX5_GET_CTR(out, transmitted_ib_unicast.octets) + MLX5_GET_CTR(out, transmitted_eth_unicast.octets) + MLX5_GET_CTR(out, transmitted_ib_multicast.octets) + + MLX5_GET_CTR(out, transmitted_eth_multicast.octets) + MLX5_GET_CTR(out, transmitted_eth_broadcast.octets); rep_stats->vport_tx_bytes = @@ -590,7 +591,7 @@ mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) if (is_uplink_rep) sqs_per_channel += 2; - sqs = kvcalloc(nch * sqs_per_channel, sizeof(*sqs), GFP_KERNEL); + sqs = kvzalloc_objs(*sqs, nch * sqs_per_channel); if (!sqs) goto out; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index 708b7987ea4cd6..1d35c97aea0bc3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -4005,6 +4005,7 @@ parse_branch_ctrl(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, err_branch_false: free_branch_attr(flow, attr->branch_true); + attr->branch_true = NULL; out_err: return err; } @@ -4836,16 +4837,19 @@ static bool is_tc_ipsec_order_check_needed(struct net_device *filter, struct mlx static int mlx5e_tc_block_ipsec_offload(struct net_device *filter, struct mlx5e_priv *priv) { struct mlx5_core_dev *mdev = priv->mdev; + int ret = 0; if (!is_tc_ipsec_order_check_needed(filter, priv)) return 0; - if (mdev->num_block_tc) - return -EBUSY; - - mdev->num_block_ipsec++; + spin_lock_bh(&mdev->offload_block.lock); + if (mdev->offload_block.num_block_tc) + ret = -EBUSY; + else + mdev->offload_block.num_block_ipsec++; + spin_unlock_bh(&mdev->offload_block.lock); - return 0; + return ret; } static void mlx5e_tc_unblock_ipsec_offload(struct net_device *filter, struct mlx5e_priv *priv) @@ -4853,7 +4857,10 @@ static void mlx5e_tc_unblock_ipsec_offload(struct net_device *filter, struct mlx if (!is_tc_ipsec_order_check_needed(filter, priv)) return; - priv->mdev->num_block_ipsec--; + spin_lock_bh(&priv->mdev->offload_block.lock); + if (!WARN_ON_ONCE(!priv->mdev->offload_block.num_block_ipsec)) + priv->mdev->offload_block.num_block_ipsec--; + spin_unlock_bh(&priv->mdev->offload_block.lock); } int mlx5e_configure_flower(struct net_device *dev, struct mlx5e_priv *priv, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c index b4cf3c5ac0dde8..9fac6f985a866b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c @@ -1867,26 +1867,27 @@ int mlx5_esw_bridge_port_mdb_add(struct net_device *dev, u16 vport_num, u16 esw_ port = mlx5_esw_bridge_port_lookup(vport_num, esw_owner_vhca_id, br_offloads); if (!port) { - esw_warn(br_offloads->esw->dev, + /* MDB is added asynchronously from the switchdev deferred + * queue while port might have been deleted concurrently. + */ + esw_info(br_offloads->esw->dev, "Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)\n", addr, vport_num); - NL_SET_ERR_MSG_FMT_MOD(extack, - "Failed to lookup bridge port to add MDB (MAC=%pM,vport=%u)", - addr, vport_num); - return -EINVAL; + return -EOPNOTSUPP; } bridge = port->bridge; if (bridge->flags & MLX5_ESW_BRIDGE_VLAN_FILTERING_FLAG && vid) { vlan = mlx5_esw_bridge_vlan_lookup(vid, port); if (!vlan) { - esw_warn(br_offloads->esw->dev, + /* MDB is added asynchronously from the switchdev + * deferred queue while vlan might have been deleted + * concurrently. + */ + esw_info(br_offloads->esw->dev, "Failed to lookup bridge port vlan metadata to create MDB (MAC=%pM,vid=%u,vport=%u)\n", addr, vid, vport_num); - NL_SET_ERR_MSG_FMT_MOD(extack, - "Failed to lookup vlan metadata for MDB (MAC=%pM,vid=%u,vport=%u)", - addr, vid, vport_num); - return -EINVAL; + return -EOPNOTSUPP; } } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c index ab50d2c734ede0..f8c97954b6eafd 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c @@ -34,12 +34,23 @@ void mlx5_esw_ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec, int mlx5_esw_ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ipsec, struct mlx5_flow_destination *dest) { - dest->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - dest->ft = mlx5_chains_get_table(esw_chains(ipsec->mdev->priv.eswitch), 0, 1, 0); + struct mlx5_flow_table *ft; + + ft = mlx5_chains_get_table(esw_chains(ipsec->mdev->priv.eswitch), + 0, 1, 0); + if (IS_ERR(ft)) + return PTR_ERR(ft); + dest->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; + dest->ft = ft; return 0; } +void mlx5_esw_ipsec_rx_status_pass_dest_put(struct mlx5e_ipsec *ipsec) +{ + mlx5_chains_put_table(esw_chains(ipsec->mdev->priv.eswitch), 0, 1, 0); +} + int mlx5_esw_ipsec_rx_setup_modify_header(struct mlx5e_ipsec_sa_entry *sa_entry, struct mlx5_flow_act *flow_act) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h index 514c15258b1d13..bb6f2423078bd0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h @@ -12,6 +12,7 @@ void mlx5_esw_ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx_create_attr *attr); int mlx5_esw_ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ipsec, struct mlx5_flow_destination *dest); +void mlx5_esw_ipsec_rx_status_pass_dest_put(struct mlx5e_ipsec *ipsec); int mlx5_esw_ipsec_rx_setup_modify_header(struct mlx5e_ipsec_sa_entry *sa_entry, struct mlx5_flow_act *flow_act); void mlx5_esw_ipsec_rx_id_mapping_remove(struct mlx5e_ipsec_sa_entry *sa_entry); @@ -32,6 +33,11 @@ static inline int mlx5_esw_ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ips return -EINVAL; } +static inline +void mlx5_esw_ipsec_rx_status_pass_dest_put(struct mlx5e_ipsec *ipsec) +{ +} + static inline int mlx5_esw_ipsec_rx_setup_modify_header(struct mlx5e_ipsec_sa_entry *sa_entry, struct mlx5_flow_act *flow_act) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 2d289fb1353b0f..76f808e06a88bf 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -1514,13 +1514,9 @@ int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num) struct mlx5_vport *vport; int err; - if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw)) + if (!mlx5_core_is_ecpf(dev)) return 0; - vport = mlx5_eswitch_get_vport(esw, vport_num); - if (IS_ERR(vport)) - return PTR_ERR(vport); - /* Once vport and representor are ready, take the PF out of * initializing state. Enabling HCA clears the iser->initializing * bit and PF driver loading can progress. @@ -1529,7 +1525,11 @@ int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num) if (err) return err; - vport->pf_activated = true; + if (mlx5_esw_allowed(esw)) { + vport = mlx5_eswitch_get_vport(esw, vport_num); + if (!IS_ERR(vport)) + vport->pf_activated = true; + } return 0; } @@ -1540,18 +1540,18 @@ int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num) struct mlx5_vport *vport; int err; - if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw)) + if (!mlx5_core_is_ecpf(dev)) return 0; - vport = mlx5_eswitch_get_vport(esw, vport_num); - if (IS_ERR(vport)) - return PTR_ERR(vport); - err = mlx5_cmd_pf_disable_hca(dev, vport_num); if (err) return err; - vport->pf_activated = false; + if (mlx5_esw_allowed(esw)) { + vport = mlx5_eswitch_get_vport(esw, vport_num); + if (!IS_ERR(vport)) + vport->pf_activated = false; + } return 0; } @@ -3051,12 +3051,36 @@ int mlx5_esw_lock(struct mlx5_eswitch *esw) return 0; } +static void esw_mode_lock(struct mlx5_eswitch *esw) +{ + down_write(&esw->mode_lock); +} + +static void esw_mode_unlock(struct mlx5_eswitch *esw) +{ + up_write(&esw->mode_lock); +} + +/* Lock the eswitch and wait for an operation in progress to finish. */ +void mlx5_esw_lock_wait(struct mlx5_eswitch *esw) +{ + down_write(&esw->mode_lock); + wait_var_event_any_lock(&esw->eswitch_operation_in_progress, + !esw->eswitch_operation_in_progress, + esw, esw_mode, TASK_UNINTERRUPTIBLE); +} + /** * mlx5_esw_unlock() - Release write lock on esw mode lock * @esw: eswitch device. + * + * Also wakes up mlx5_esw_lock_wait() waiters, so it must be used to release + * mode_lock after clearing eswitch_operation_in_progress. */ void mlx5_esw_unlock(struct mlx5_eswitch *esw) { + wake_up_var_locked(&esw->eswitch_operation_in_progress, + &esw->mode_lock); up_write(&esw->mode_lock); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index e9cbcd73b23ffa..48eb6acc1e8715 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -948,6 +948,7 @@ void mlx5_esw_get(struct mlx5_core_dev *dev); void mlx5_esw_put(struct mlx5_core_dev *dev); int mlx5_esw_try_lock(struct mlx5_eswitch *esw); int mlx5_esw_lock(struct mlx5_eswitch *esw); +void mlx5_esw_lock_wait(struct mlx5_eswitch *esw); void mlx5_esw_unlock(struct mlx5_eswitch *esw); void esw_vport_change_handle_locked(struct mlx5_vport *vport); @@ -967,10 +968,10 @@ void mlx5_eswitch_unload_reps(struct mlx5_eswitch *esw); bool mlx5_eswitch_is_peer(struct mlx5_eswitch *esw, struct mlx5_eswitch *peer_esw); -bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb); +int mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb); void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev); -int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev); +int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev, bool check_users); void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev); static inline int mlx5_eswitch_num_vfs(struct mlx5_eswitch *esw) @@ -1071,17 +1072,21 @@ mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw) static inline void mlx5_eswitch_unload_reps(struct mlx5_eswitch *esw) {} -static inline bool +static inline int mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb) { - return true; + return 1; } static inline void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev) { } -static inline int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev) { return 0; } +static inline int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev, + bool check_users) +{ + return 0; +} static inline void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev) {} static inline bool mlx5_eswitch_block_ipsec(struct mlx5_core_dev *dev) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index c712848b202db4..4747841310914b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -2457,8 +2457,8 @@ void mlx5_esw_reps_unblock(struct mlx5_eswitch *esw) static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode) { + mlx5_devcom_comp_assert_locked(esw->dev->priv.hca_devcom_comp); mlx5_esw_reps_unblock(esw); - mlx5_devcom_comp_lock(esw->dev->priv.hca_devcom_comp); if (esw->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_IB_ADEV || mlx5_core_mp_enabled(esw->dev)) { esw->mode = mode; @@ -2471,7 +2471,6 @@ static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode) esw->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV; out: mlx5_rescan_drivers_locked(esw->dev); - mlx5_devcom_comp_unlock(esw->dev->priv.hca_devcom_comp); mlx5_esw_reps_block(esw); } @@ -4366,7 +4365,7 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode) return 0; } -int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev) +int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev, bool check_users) { struct mlx5_eswitch *esw = dev->priv.eswitch; int err; @@ -4374,8 +4373,11 @@ int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev) if (!mlx5_esw_allowed(esw)) return 0; - /* Take TC into account */ - err = mlx5_esw_try_lock(esw); + /* Temporary reservations may reuse tables while TC users exist. */ + if (check_users) + err = mlx5_esw_try_lock(esw); + else + err = mlx5_esw_lock(esw); if (err < 0) return err; @@ -4442,7 +4444,7 @@ static bool mlx5_devlink_switchdev_active_mode_change(struct mlx5_eswitch *esw, !esw->offloads_inactive) return false; - down_write(&esw->mode_lock); + mlx5_esw_lock_wait(esw); esw->offloads_inactive = !esw->offloads_inactive; esw->eswitch_operation_in_progress = true; up_write(&esw->mode_lock); @@ -4454,34 +4456,30 @@ static bool mlx5_devlink_switchdev_active_mode_change(struct mlx5_eswitch *esw, down_write(&esw->mode_lock); esw->eswitch_operation_in_progress = false; - up_write(&esw->mode_lock); + mlx5_esw_unlock(esw); return true; } -#define MLX5_ESW_HOLD_TIMEOUT_MS 7000 -#define MLX5_ESW_HOLD_RETRY_DELAY_MS 500 - void mlx5_eswitch_safe_aux_devs_remove(struct mlx5_core_dev *dev) { - unsigned long timeout; - bool hold_esw = true; + struct mlx5_eswitch *esw = dev->priv.eswitch; - /* Wait for any concurrent eswitch mode transition to complete. */ - if (!mlx5_esw_hold(dev)) { - timeout = jiffies + msecs_to_jiffies(MLX5_ESW_HOLD_TIMEOUT_MS); - while (!mlx5_esw_hold(dev)) { - if (!time_before(jiffies, timeout)) { - hold_esw = false; - break; - } - msleep(MLX5_ESW_HOLD_RETRY_DELAY_MS); - } - } - if (hold_esw) { - if (mlx5_eswitch_mode(dev) == MLX5_ESWITCH_OFFLOADS) - mlx5_core_reps_aux_devs_remove(dev); - mlx5_esw_release(dev); - } + if (!mlx5_esw_allowed(esw)) + return; + + /* Wait for any concurrent eswitch mode transition to complete. + * Deadlock risk if ever called from within an operation in progress. + */ + mlx5_esw_lock_wait(esw); + esw->eswitch_operation_in_progress = true; + up_write(&esw->mode_lock); + + if (mlx5_eswitch_mode(dev) == MLX5_ESWITCH_OFFLOADS) + mlx5_core_reps_aux_devs_remove(dev); + + down_write(&esw->mode_lock); + esw->eswitch_operation_in_progress = false; + mlx5_esw_unlock(esw); } int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, @@ -4508,10 +4506,11 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, return 0; mlx5_lag_disable_change(esw->dev); + mlx5_devcom_comp_lock(esw->dev->priv.hca_devcom_comp); err = mlx5_esw_try_lock(esw); if (err < 0) { NL_SET_ERR_MSG_MOD(extack, "Can't change mode, E-Switch is busy"); - goto enable_lag; + goto unlock_hca; } cur_mlx5_mode = err; err = 0; @@ -4574,7 +4573,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, esw->eswitch_operation_in_progress = false; unlock: mlx5_esw_unlock(esw); -enable_lag: +unlock_hca: + mlx5_devcom_comp_unlock(esw->dev->priv.hca_devcom_comp); mlx5_lag_enable_change(esw->dev); /* Shared FDB activation is creating LAG which is changing reps. */ if (!err) @@ -4655,7 +4655,7 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, if (IS_ERR(esw)) return PTR_ERR(esw); - down_write(&esw->mode_lock); + mlx5_esw_lock_wait(esw); switch (MLX5_CAP_ETH(dev, wqe_inline_mode)) { case MLX5_CAP_INLINE_MODE_NOT_REQUIRED: @@ -4693,7 +4693,7 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, down_write(&esw->mode_lock); esw->eswitch_operation_in_progress = false; - up_write(&esw->mode_lock); + mlx5_esw_unlock(esw); return 0; out: @@ -4712,25 +4712,31 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode) return esw_inline_mode_to_devlink(esw->offloads.inline_mode, mode); } -bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb) +/* Return 1 if allowed, 0 if disallowed by the configuration, or -EBUSY + * if an eswitch operation is in progress. + */ +int mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb) { struct mlx5_eswitch *esw = dev->priv.eswitch; enum devlink_eswitch_encap_mode encap; - bool allow_tunnel = false; + int ret; if (!mlx5_esw_allowed(esw)) - return true; + return 1; + + ret = mlx5_esw_lock(esw); + if (ret) + return ret; - down_write(&esw->mode_lock); encap = esw->offloads.encap; if (esw->mode == MLX5_ESWITCH_LEGACY || (encap == DEVLINK_ESWITCH_ENCAP_MODE_NONE && !from_fdb)) { - allow_tunnel = true; + ret = 1; esw->offloads.num_block_encap++; } - up_write(&esw->mode_lock); + mlx5_esw_unlock(esw); - return allow_tunnel; + return ret; } void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev) @@ -4757,7 +4763,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, if (IS_ERR(esw)) return PTR_ERR(esw); - down_write(&esw->mode_lock); + mlx5_esw_lock_wait(esw); if (encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE && (!MLX5_CAP_ESW_FLOWTABLE_FDB(dev, reformat) || @@ -4813,7 +4819,7 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, esw->eswitch_operation_in_progress = false; unlock: - up_write(&esw->mode_lock); + mlx5_esw_unlock(esw); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c index faa5192543163a..842b039bac34e7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c @@ -9,8 +9,8 @@ int mlx5_fs_bulk_bitmap_alloc(struct mlx5_core_dev *dev, { int i; - fs_bulk->bitmask = kvcalloc(BITS_TO_LONGS(fs_bulk->bulk_len), - sizeof(unsigned long), GFP_KERNEL); + fs_bulk->bitmask = kvzalloc_objs(unsigned long, + BITS_TO_LONGS(fs_bulk->bulk_len)); if (!fs_bulk->bitmask) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/hwmon.c b/drivers/net/ethernet/mellanox/mlx5/core/hwmon.c index afcdebac9c4fd9..8cfee9c923f72e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/hwmon.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/hwmon.c @@ -321,8 +321,8 @@ static struct mlx5_hwmon *mlx5_hwmon_alloc(struct mlx5_core_dev *mdev) } /* sensors configuration values array, must be 0-terminated hence, + 1 */ - hwmon->temp_channel_config = kcalloc(sensors_count + 1, sizeof(*hwmon->temp_channel_config), - GFP_KERNEL); + hwmon->temp_channel_config = kzalloc_objs(*hwmon->temp_channel_config, + sensors_count + 1); if (!hwmon->temp_channel_config) { err = -ENOMEM; goto err_free_temp_channel_desc; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h index d67d5a72bb4198..8c0039c5425e2b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h @@ -82,7 +82,7 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev); int mlx5i_pkey_add_qpn(struct net_device *netdev, u32 qpn); int mlx5i_pkey_del_qpn(struct net_device *netdev, u32 qpn); -/* Get the net-device corresponding to the given underlay QPN */ +/* Get the net-device for a QPN. Caller must hold rcu_read_lock(). */ struct net_device *mlx5i_pkey_get_netdev(struct net_device *netdev, u32 qpn); /* Shared ndo functions */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c index 4120afd097c36d..5edc3924752516 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c @@ -31,6 +31,7 @@ */ #include +#include #include "ipoib.h" #define MLX5I_MAX_LOG_PKEY_SUP 7 @@ -39,11 +40,12 @@ struct qpn_to_netdev { struct net_device *netdev; struct hlist_node hlist; u32 underlay_qpn; + struct rcu_head rcu; }; struct mlx5i_pkey_qpn_ht { struct hlist_head buckets[1 << MLX5I_MAX_LOG_PKEY_SUP]; - spinlock_t ht_lock; /* Synchronise with NAPI */ + spinlock_t ht_lock; /* Serialize hash table updates */ }; int mlx5i_pkey_qpn_ht_init(struct net_device *netdev) @@ -68,13 +70,14 @@ void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev) kfree(ipriv->qpn_htbl); } -static struct qpn_to_netdev *mlx5i_find_qpn_to_netdev_node(struct hlist_head *buckets, - u32 qpn) +static struct qpn_to_netdev * +mlx5i_find_qpn_to_netdev_node(struct mlx5i_pkey_qpn_ht *ht, u32 qpn) { - struct hlist_head *h = &buckets[hash_32(qpn, MLX5I_MAX_LOG_PKEY_SUP)]; + struct hlist_head *h = &ht->buckets[hash_32(qpn, MLX5I_MAX_LOG_PKEY_SUP)]; struct qpn_to_netdev *node; - hlist_for_each_entry(node, h, hlist) { + hlist_for_each_entry_rcu(node, h, hlist, + lockdep_is_held(&ht->ht_lock)) { if (node->underlay_qpn == qpn) return node; } @@ -96,7 +99,7 @@ int mlx5i_pkey_add_qpn(struct net_device *netdev, u32 qpn) new_node->netdev = netdev; new_node->underlay_qpn = qpn; spin_lock_bh(&ht->ht_lock); - hlist_add_head(&new_node->hlist, &ht->buckets[key]); + hlist_add_head_rcu(&new_node->hlist, &ht->buckets[key]); spin_unlock_bh(&ht->ht_lock); return 0; @@ -109,16 +112,17 @@ int mlx5i_pkey_del_qpn(struct net_device *netdev, u32 qpn) struct mlx5i_pkey_qpn_ht *ht = ipriv->qpn_htbl; struct qpn_to_netdev *node; - node = mlx5i_find_qpn_to_netdev_node(ht->buckets, qpn); + spin_lock_bh(&ht->ht_lock); + node = mlx5i_find_qpn_to_netdev_node(ht, qpn); if (!node) { + spin_unlock_bh(&ht->ht_lock); mlx5_core_warn(epriv->mdev, "QPN to netdev delete from HT failed\n"); return -EINVAL; } - spin_lock_bh(&ht->ht_lock); - hlist_del_init(&node->hlist); + hlist_del_rcu(&node->hlist); spin_unlock_bh(&ht->ht_lock); - kfree(node); + kfree_rcu(node, rcu); return 0; } @@ -128,7 +132,7 @@ struct net_device *mlx5i_pkey_get_netdev(struct net_device *netdev, u32 qpn) struct mlx5i_priv *ipriv = netdev_priv(netdev); struct qpn_to_netdev *node; - node = mlx5i_find_qpn_to_netdev_node(ipriv->qpn_htbl->buckets, qpn); + node = mlx5i_find_qpn_to_netdev_node(ipriv->qpn_htbl, qpn); if (!node) return NULL; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index 24086267b4a7f5..9330aab24c02cc 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -711,8 +711,8 @@ static int mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker, int i; int j; - enabled = kcalloc(ldev->ports, sizeof(*enabled), GFP_KERNEL); - disabled = kcalloc(ldev->ports, sizeof(*disabled), GFP_KERNEL); + enabled = kzalloc_objs(*enabled, ldev->ports); + disabled = kzalloc_objs(*disabled, ldev->ports); if (!enabled || !disabled) { err = -ENOMEM; goto out; @@ -1172,7 +1172,6 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev) "Failed to deactivate VF LAG; driver restart required\n" "Make sure all VFs are unbound prior to VF LAG activation or deactivation\n"); } - return err; } if (test_bit(MLX5_LAG_MODE_FLAG_HASH_BASED, &flags)) { @@ -1182,7 +1181,7 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev) if (mlx5_lag_has_drop_rule(ldev)) mlx5_lag_drop_rule_cleanup(ldev); - return 0; + return err; } bool mlx5_lag_check_prereq(struct mlx5_lag *ldev) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c index abf72026c75133..549d31812c2f9e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c @@ -227,7 +227,7 @@ static int mlx5_lag_mpesw_queue_work(struct mlx5_core_dev *dev, int err = 0; if (!ldev) - return 0; + return -EOPNOTSUPP; work = kzalloc_obj(*work); if (!work) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c index 5df786133e4bcb..c3e53d219496f9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c @@ -80,6 +80,7 @@ enum { }; struct mlx5_clock_dev_state { + bool loaded; struct mlx5_core_dev *mdev; struct mlx5_devcom_comp_dev *compdev; struct mlx5_nb pps_nb; @@ -89,7 +90,7 @@ struct mlx5_clock_dev_state { struct mlx5_clock_priv { struct mlx5_clock clock; struct mlx5_core_dev *mdev; - struct mutex lock; /* protect mdev and used in PTP callbacks */ + struct mutex lock; /* protect mdev and serialize hardware callbacks */ struct mlx5_core_dev *event_mdev; }; @@ -100,9 +101,6 @@ static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock) static void mlx5_clock_lockdep_assert(struct mlx5_clock *clock) { - if (!clock->shared) - return; - lockdep_assert(lockdep_is_held(&clock_priv(clock)->lock)); } @@ -115,20 +113,24 @@ static struct mlx5_core_dev *mlx5_clock_mdev_get(struct mlx5_clock *clock) static void mlx5_clock_lock(struct mlx5_clock *clock) { - if (!clock->shared) - return; - mutex_lock(&clock_priv(clock)->lock); } static void mlx5_clock_unlock(struct mlx5_clock *clock) { - if (!clock->shared) - return; - mutex_unlock(&clock_priv(clock)->lock); } +static struct mlx5_core_dev * +mlx5_clock_active_mdev_get(struct mlx5_clock *clock) +{ + struct mlx5_clock_priv *cpriv = clock_priv(clock); + + mlx5_clock_lockdep_assert(clock); + + return cpriv->mdev->clock_state->loaded ? cpriv->mdev : NULL; +} + static bool mlx5_real_time_mode(struct mlx5_core_dev *mdev) { return (mlx5_is_real_time_rq(mdev) || mlx5_is_real_time_sq(mdev)); @@ -333,7 +335,11 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, int err; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } if (!mlx5_is_ptm_source_time_available(mdev)) { err = -EBUSY; @@ -359,7 +365,11 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp, int err; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } if (!mlx5_is_ptm_source_time_available(mdev)) { err = -EBUSY; @@ -411,6 +421,12 @@ static u64 read_internal_timer(struct cyclecounter *cc) return mlx5_read_time(mdev, NULL, false) & cc->mask; } +static void mlx5_timer_snapshot(struct mlx5_timer *timer) +{ + timer->saved_phc_ns = timer->tc.nsec; + timer->saved_boot_ns = ktime_get_boottime_ns(); +} + static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev) { struct mlx5_ib_clock_info *clock_info = mdev->clock_info; @@ -418,6 +434,9 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev) struct mlx5_timer *timer; u32 sign; + timer = &clock->timer; + mlx5_timer_snapshot(timer); + if (!clock_info) return; @@ -425,7 +444,6 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev) smp_store_mb(clock_info->sign, sign | MLX5_IB_CLOCK_INFO_KERNEL_UPDATING); - timer = &clock->timer; clock_info->cycles = timer->tc.cycle_last; clock_info->mult = timer->cycles.mult; clock_info->nsec = timer->tc.nsec; @@ -471,10 +489,9 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info) clock = container_of(ptp_info, struct mlx5_clock, ptp_info); mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); timer = &clock->timer; - - if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) + if (!mdev || mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) goto out; write_seqlock_irqsave(&clock->lock, flags); @@ -531,8 +548,13 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 int err; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } err = mlx5_clock_settime(mdev, clock, ts); +unlock: mlx5_clock_unlock(clock); return err; @@ -550,26 +572,40 @@ struct timespec64 mlx5_ptp_gettimex_real_time(struct mlx5_core_dev *mdev, return ts; } -static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, - struct ptp_system_timestamp *sts) +static void mlx5_clock_gettimex(struct mlx5_core_dev *mdev, + struct mlx5_clock *clock, struct timespec64 *ts, + struct ptp_system_timestamp *sts) { - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); - struct mlx5_core_dev *mdev; u64 cycles, ns; - mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); if (mlx5_real_time_mode(mdev)) { *ts = mlx5_ptp_gettimex_real_time(mdev, sts); - goto out; + return; } cycles = mlx5_read_time(mdev, sts, false); ns = mlx5_timecounter_cyc2time(clock, cycles); *ts = ns_to_timespec64(ns); -out: +} + +static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, + struct ptp_system_timestamp *sts) +{ + struct mlx5_clock *clock = + container_of(ptp, struct mlx5_clock, ptp_info); + struct mlx5_core_dev *mdev; + int err = 0; + + mlx5_clock_lock(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } + mlx5_clock_gettimex(mdev, clock, ts, sts); +unlock: mlx5_clock_unlock(clock); - return 0; + return err; } static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp, @@ -580,14 +616,20 @@ static int mlx5_ptp_getcyclesx(struct ptp_clock_info *ptp, ptp_info); struct mlx5_core_dev *mdev; u64 cycles; + int err = 0; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } cycles = mlx5_read_time(mdev, sts, false); *ts = ns_to_timespec64(cycles); +unlock: mlx5_clock_unlock(clock); - return 0; + return err; } static int mlx5_ptp_adjtime_real_time(struct mlx5_core_dev *mdev, s64 delta) @@ -620,7 +662,11 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) int err = 0; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } if (mlx5_modify_mtutc_allowed(mdev)) { err = mlx5_ptp_adjtime_real_time(mdev, delta); @@ -630,6 +676,7 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) } write_seqlock_irqsave(&clock->lock, flags); + timecounter_read(&timer->tc); timecounter_adjtime(&timer->tc, delta); mlx5_update_clock_info_page(mdev); write_sequnlock_irqrestore(&clock->lock, flags); @@ -646,8 +693,13 @@ static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta) int err; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } err = mlx5_ptp_adjtime_real_time(mdev, delta); +unlock: mlx5_clock_unlock(clock); return err; @@ -683,7 +735,11 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) u32 mult; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } if (mlx5_modify_mtutc_allowed(mdev)) { err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm); @@ -744,7 +800,11 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, } mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } if (!MLX5_PPS_CAP(mdev)) { err = -EOPNOTSUPP; @@ -917,7 +977,11 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, return -EBUSY; mlx5_clock_lock(clock); - mdev = mlx5_clock_mdev_get(clock); + mdev = mlx5_clock_active_mdev_get(clock); + if (!mdev) { + err = -EAGAIN; + goto unlock; + } rt_mode = mlx5_real_time_mode(mdev); if (!MLX5_PPS_CAP(mdev)) { @@ -1151,7 +1215,7 @@ static u64 perout_conf_next_event_timer(struct mlx5_core_dev *mdev, struct timespec64 ts; s64 target_ns; - mlx5_ptp_gettimex(&clock->ptp_info, &ts, NULL); + mlx5_clock_gettimex(mdev, clock, &ts, NULL); ts_next_sec(&ts); target_ns = timespec64_to_ns(&ts); @@ -1222,8 +1286,8 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) timer->nominal_c_mult = timer->cycles.mult; timer->cycles.mask = CLOCKSOURCE_MASK(41); - timecounter_init(&timer->tc, &timer->cycles, - ktime_to_ns(ktime_get_real())); + timecounter_init(&timer->tc, &timer->cycles, ktime_get_real_ns()); + mlx5_timer_snapshot(timer); } static void mlx5_init_overflow_period(struct mlx5_core_dev *mdev) @@ -1381,9 +1445,6 @@ static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev) clock->ptp); clock->ptp = NULL; } - - if (clock->ptp) - ptp_schedule_worker(clock->ptp, 0); } static void mlx5_destroy_clock_dev(struct mlx5_core_dev *mdev) @@ -1530,22 +1591,53 @@ static void mlx5_clock_arm_pps_in_event(struct mlx5_clock *clock, !clock->pps_info.pin_armed[i]) continue; - if (new_mdev) { + if (new_mdev) mlx5_set_mtppse(new_mdev, i, 0, MLX5_EVENT_MODE_REPETETIVE); - cpriv->event_mdev = new_mdev; - } else { - cpriv->event_mdev = NULL; - } if (old_mdev) mlx5_set_mtppse(old_mdev, i, 0, MLX5_EVENT_MODE_DISABLE); } + cpriv->event_mdev = new_mdev; +} + +static void mlx5_set_timecounter(struct mlx5_core_dev *mdev, u64 ns) +{ + struct mlx5_clock *clock = mdev->clock; + struct mlx5_timer *timer; + unsigned long flags; + + timer = &clock->timer; + mlx5_clock_lockdep_assert(clock); + + write_seqlock_irqsave(&clock->lock, flags); + timecounter_init(&timer->tc, &timer->cycles, ns); + mlx5_update_clock_info_page(mdev); + write_sequnlock_irqrestore(&clock->lock, flags); +} + +static void mlx5_save_timecounter(struct mlx5_core_dev *mdev) +{ + struct mlx5_clock *clock = mdev->clock; + struct mlx5_timer *timer; + unsigned long flags; + + timer = &clock->timer; + mlx5_clock_lockdep_assert(clock); + + if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) + return; + + write_seqlock_irqsave(&clock->lock, flags); + timecounter_read(&timer->tc); + mlx5_update_clock_info_page(mdev); + write_sequnlock_irqrestore(&clock->lock, flags); } void mlx5_clock_load(struct mlx5_core_dev *mdev) { struct mlx5_clock *clock = mdev->clock; struct mlx5_clock_priv *cpriv; + bool start; if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) return; @@ -1554,18 +1646,32 @@ void mlx5_clock_load(struct mlx5_core_dev *mdev) MLX5_NB_INIT(&mdev->clock_state->pps_nb, mlx5_pps_event, PPS_EVENT); mlx5_eq_notifier_register(mdev, &mdev->clock_state->pps_nb); - if (!clock->shared) { - mlx5_clock_arm_pps_in_event(clock, mdev, NULL); - return; - } - cpriv = clock_priv(clock); - mlx5_devcom_comp_lock(mdev->clock_state->compdev); + if (clock->shared) + mlx5_devcom_comp_lock(mdev->clock_state->compdev); mlx5_clock_lock(clock); - if (mdev == cpriv->mdev && mdev != cpriv->event_mdev) + start = !cpriv->mdev->clock_state->loaded; + mdev->clock_state->loaded = true; + if (start) { + struct mlx5_timer *timer = &clock->timer; + u64 ns; + + cpriv->mdev = mdev; + if (mlx5_real_time_mode(mdev)) + ns = mlx5_read_time(mdev, NULL, true); + else + ns = timer->saved_phc_ns + + ktime_get_boottime_ns() - timer->saved_boot_ns; + + mlx5_set_timecounter(mdev, ns); mlx5_clock_arm_pps_in_event(clock, mdev, cpriv->event_mdev); + } mlx5_clock_unlock(clock); - mlx5_devcom_comp_unlock(mdev->clock_state->compdev); + + if (start && clock->ptp) + ptp_schedule_worker(clock->ptp, 0); + if (clock->shared) + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); } void mlx5_clock_unload(struct mlx5_core_dev *mdev) @@ -1573,30 +1679,42 @@ void mlx5_clock_unload(struct mlx5_core_dev *mdev) struct mlx5_core_dev *peer_dev, *next = NULL; struct mlx5_clock *clock = mdev->clock; struct mlx5_devcom_comp_dev *pos; + struct mlx5_clock_priv *cpriv; + bool stop; if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) return; - if (!clock->shared) { - mlx5_clock_arm_pps_in_event(clock, NULL, mdev); - goto out; - } - - mlx5_devcom_comp_lock(mdev->clock_state->compdev); - mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, peer_dev, pos) { - if (peer_dev->clock && peer_dev != mdev) { - next = peer_dev; - break; + if (clock->shared) { + mlx5_devcom_comp_lock(mdev->clock_state->compdev); + mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, + peer_dev, pos) { + if (peer_dev->clock == clock && + peer_dev->clock_state->loaded) { + next = peer_dev; + break; + } } } mlx5_clock_lock(clock); - if (mdev == clock_priv(clock)->event_mdev) + cpriv = clock_priv(clock); + mdev->clock_state->loaded = false; + if (mdev == cpriv->mdev && next) + cpriv->mdev = next; + if (mdev == cpriv->event_mdev) mlx5_clock_arm_pps_in_event(clock, next, mdev); + stop = !cpriv->mdev->clock_state->loaded; + if (!mlx5_real_time_mode(cpriv->mdev)) + mlx5_save_timecounter(cpriv->mdev); mlx5_clock_unlock(clock); - mlx5_devcom_comp_unlock(mdev->clock_state->compdev); -out: + /* Keep devcom locked to prevent a peer from restarting the worker. */ + if (stop && clock->ptp) + ptp_cancel_worker_sync(clock->ptp); + if (clock->shared) + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); + mlx5_eq_notifier_unregister(mdev, &mdev->clock_state->pps_nb); cancel_work_sync(&mdev->clock_state->out_work); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h index aff3aed62c748f..86ae447a23ed6c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h @@ -50,6 +50,8 @@ struct mlx5_timer { struct timecounter tc; u32 nominal_c_mult; unsigned long overflow_period; + u64 saved_phc_ns; + u64 saved_boot_ns; }; struct mlx5_clock { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c index efc5167493c125..4892175ca57744 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c @@ -94,6 +94,7 @@ struct mlx5_fs_id { refcount_t refcnt; sci_t sci; struct rhash_head hash; + struct rcu_head rcu; }; struct mlx5_macsec_device { @@ -684,7 +685,7 @@ static void macsec_fs_id_del(struct list_head *macsec_devices_list, u32 fs_id, xa_erase(fs_id_xa, fs_id); - kfree(fs_id_found); + kfree_rcu(fs_id_found, rcu); if (macsec_fs_is_macsec_device_empty(macsec_device)) { list_del(&macsec_device->macsec_devices_list_entry); @@ -763,13 +764,9 @@ static int macsec_fs_id_add(struct list_head *macsec_devices_list, u32 fs_id, return err; } -static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, - struct mlx5_macsec_tx_rule *tx_rule, - void *macdev) +static void macsec_fs_tx_free_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_tx_rule *tx_rule) { - macsec_fs_id_del(&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, - &macsec_fs->sci_hash, true); - if (tx_rule->rule) { mlx5_del_flow_rules(tx_rule->rule); tx_rule->rule = NULL; @@ -790,6 +787,15 @@ static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, macsec_fs_tx_ft_put(macsec_fs); } +static void macsec_fs_tx_del_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_tx_rule *tx_rule, + void *macdev) +{ + macsec_fs_id_del(&macsec_fs->macsec_devices_list, tx_rule->fs_id, macdev, + &macsec_fs->sci_hash, true); + macsec_fs_tx_free_rule(macsec_fs, tx_rule); +} + #define MLX5_REFORMAT_PARAM_ADD_MACSEC_OFFSET_4_BYTES 1 static union mlx5_macsec_rule * @@ -882,7 +888,7 @@ macsec_fs_tx_add_rule(struct mlx5_macsec_fs *macsec_fs, goto out_spec; err: - macsec_fs_tx_del_rule(macsec_fs, tx_rule, macsec_ctx->secy->netdev); + macsec_fs_tx_free_rule(macsec_fs, tx_rule); macsec_rule = NULL; out_spec: kvfree(spec); @@ -1647,15 +1653,11 @@ static void macsec_fs_rx_ft_put(struct mlx5_macsec_fs *macsec_fs) macsec_fs_rx_destroy(macsec_fs); } -static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, - struct mlx5_macsec_rx_rule *rx_rule, - void *macdev, u32 fs_id) +static void macsec_fs_rx_free_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_rx_rule *rx_rule) { int i; - macsec_fs_id_del(&macsec_fs->macsec_devices_list, fs_id, macdev, - &macsec_fs->fs_id_hash, false); - for (i = 0; i < RX_NUM_OF_RULES_PER_SA; ++i) { if (rx_rule->rule[i]) { mlx5_del_flow_rules(rx_rule->rule[i]); @@ -1673,6 +1675,15 @@ static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, macsec_fs_rx_ft_put(macsec_fs); } +static void macsec_fs_rx_del_rule(struct mlx5_macsec_fs *macsec_fs, + struct mlx5_macsec_rx_rule *rx_rule, + void *macdev, u32 fs_id) +{ + macsec_fs_id_del(&macsec_fs->macsec_devices_list, fs_id, macdev, + &macsec_fs->fs_id_hash, false); + macsec_fs_rx_free_rule(macsec_fs, rx_rule); +} + static void macsec_fs_rx_setup_fte(struct mlx5_flow_spec *spec, struct mlx5_flow_act *flow_act, struct mlx5_macsec_rule_attrs *attrs, @@ -1832,7 +1843,7 @@ macsec_fs_rx_add_rule(struct mlx5_macsec_fs *macsec_fs, return macsec_rule; err: - macsec_fs_rx_del_rule(macsec_fs, rx_rule, macsec_ctx->secy->netdev, fs_id); + macsec_fs_rx_free_rule(macsec_fs, rx_rule); macsec_rule = NULL; out_spec: kvfree(spec); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 1a45474ce03db5..0439fcfb9ce571 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1814,6 +1814,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx) lockdep_register_key(&dev->lock_key); mutex_init(&dev->intf_state_mutex); lockdep_set_class(&dev->intf_state_mutex, &dev->lock_key); + spin_lock_init(&dev->offload_block.lock); mutex_init(&dev->mlx5e_res.uplink_netdev_lock); mutex_init(&dev->wc_state_lock); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c index 0f5b8bc7861eb2..2bcafc572a427a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c @@ -653,7 +653,7 @@ static int irq_pools_init(struct mlx5_core_dev *dev, int sf_vec, int pcif_vec, goto err_sf_ctrl; } - table->sf_comp_pool->irqs_per_cpu = kcalloc(nr_cpu_ids, sizeof(u16), GFP_KERNEL); + table->sf_comp_pool->irqs_per_cpu = kzalloc_objs(u16, nr_cpu_ids); if (!table->sf_comp_pool->irqs_per_cpu) { err = -ENOMEM; goto err_irqs_per_cpu; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c index 02736ecf817dde..36a207d6d30a1e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/buddy.c @@ -10,15 +10,11 @@ static int hws_buddy_init(struct mlx5hws_buddy_mem *buddy, u32 max_order) buddy->max_order = max_order; - buddy->bitmap = kcalloc(buddy->max_order + 1, - sizeof(*buddy->bitmap), - GFP_KERNEL); + buddy->bitmap = kzalloc_objs(*buddy->bitmap, buddy->max_order + 1); if (!buddy->bitmap) return -ENOMEM; - buddy->num_free = kcalloc(buddy->max_order + 1, - sizeof(*buddy->num_free), - GFP_KERNEL); + buddy->num_free = kzalloc_objs(*buddy->num_free, buddy->max_order + 1); if (!buddy->num_free) { ret = -ENOMEM; goto err_out_free_bits; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c index 660630f18ce92f..fa3e0405ad8af0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c @@ -459,7 +459,7 @@ static int hws_submatcher_init(struct mlx5hws_bwc_matcher *cmatcher, int idx, goto destroy_tbl; } - subm->bwc_matcher = kzalloc(sizeof(*subm->bwc_matcher), GFP_KERNEL); + subm->bwc_matcher = kzalloc_obj(*subm->bwc_matcher); if (!subm->bwc_matcher) { ret = -ENOMEM; goto destroy_action; @@ -612,7 +612,7 @@ int mlx5hws_bwc_matcher_create_complex(struct mlx5hws_bwc_matcher *bwc_matcher, if (ret) goto free_submasks; - cdata = kzalloc(sizeof(*cdata), GFP_KERNEL); + cdata = kzalloc_obj(*cdata); if (!cdata) { ret = -ENOMEM; goto free_submasks; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c index 812b2f3cddcfff..cbcbc2b62809d7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c @@ -523,13 +523,13 @@ mlx5_fs_get_action_aso_meter(struct mlx5_fs_hws_context *fs_ctx, } static void mlx5_fs_put_action_aso_meter(struct mlx5_fs_hws_context *fs_ctx, - struct mlx5_exe_aso *exe_aso) + u32 base_id) { struct mlx5_fs_hws_data *meter_hws_data; struct xarray *meters_xa; meters_xa = &fs_ctx->hws_pool.aso_meters; - meter_hws_data = xa_load(meters_xa, exe_aso->base_id); + meter_hws_data = xa_load(meters_xa, base_id); if (!meter_hws_data) return; return mlx5_fs_put_hws_action(meter_hws_data); @@ -704,7 +704,7 @@ static void mlx5_fs_destroy_fs_action(struct mlx5_flow_root_namespace *ns, mlx5_fc_put_hws_action(fs_action->counter); break; case MLX5HWS_ACTION_TYP_ASO_METER: - mlx5_fs_put_action_aso_meter(fs_ctx, fs_action->exe_aso); + mlx5_fs_put_action_aso_meter(fs_ctx, fs_action->aso_base_id); break; case MLX5HWS_ACTION_TYP_SAMPLER: mlx5_fs_put_dest_action_sampler(fs_ctx, fs_action->sampler_id); @@ -937,7 +937,7 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, fte_action->exe_aso.flow_meter.init_color; (*ractions)[num_actions++].action = tmp_action; fs_actions[num_fs_actions].action = tmp_action; - fs_actions[num_fs_actions++].exe_aso = &fte_action->exe_aso; + fs_actions[num_fs_actions++].aso_base_id = fte_action->exe_aso.base_id; } if (fte_action->action & MLX5_FLOW_CONTEXT_ACTION_DROP) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h index cf068fb5bdbf92..4fdeea9fdd12d6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h @@ -57,7 +57,7 @@ struct mlx5_fs_hws_rule_action { struct mlx5hws_action *action; union { struct mlx5_fc *counter; - struct mlx5_exe_aso *exe_aso; + u32 aso_base_id; u32 sampler_id; }; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c index 79e3c29d1044e1..2070cc42be0020 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c @@ -283,9 +283,8 @@ static struct mlx5dr_qp *dr_create_rc_qp(struct mlx5_core_dev *mdev, goto err_wq; } - dr_qp->sq.wqe_head = kcalloc(dr_qp->sq.wqe_cnt, - sizeof(dr_qp->sq.wqe_head[0]), - GFP_KERNEL); + dr_qp->sq.wqe_head = kzalloc_objs(dr_qp->sq.wqe_head[0], + dr_qp->sq.wqe_cnt); if (!dr_qp->sq.wqe_head) { mlx5_core_warn(mdev, "Can't allocate wqe head\n"); diff --git a/drivers/net/ethernet/mellanox/mlxsw/i2c.c b/drivers/net/ethernet/mellanox/mlxsw/i2c.c index 60a50222f33ae5..bf42606d3207b2 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/i2c.c +++ b/drivers/net/ethernet/mellanox/mlxsw/i2c.c @@ -638,7 +638,7 @@ static int mlxsw_i2c_probe(struct i2c_client *client) u8 status; int err; - mlxsw_i2c = devm_kzalloc(&client->dev, sizeof(*mlxsw_i2c), GFP_KERNEL); + mlxsw_i2c = devm_kzalloc_obj(&client->dev, *mlxsw_i2c); if (!mlxsw_i2c) return -ENOMEM; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c index 8d6cea43be616e..e8fc608a2f8a23 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c @@ -2311,8 +2311,7 @@ mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp, if (err) goto err_rhashtable_vni_init; - fid_core->port_fid_mappings = kcalloc(max_ports, sizeof(unsigned int), - GFP_KERNEL); + fid_core->port_fid_mappings = kzalloc_objs(unsigned int, max_ports); if (!fid_core->port_fid_mappings) { err = -ENOMEM; goto err_alloc_port_fid_mappings; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.c index e700e9ac33b79a..cc1d9677709e40 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.c @@ -213,8 +213,7 @@ mlxsw_sp_mr_route_info_create(struct mlxsw_sp_mr_table *mr_table, u16 irif_index; u16 erif = 0; - erif_indices = kmalloc_array(MAXVIFS, sizeof(*erif_indices), - GFP_KERNEL); + erif_indices = kmalloc_objs(*erif_indices, MAXVIFS); if (!erif_indices) return -ENOMEM; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h index cbb25d11638c09..c371ac9f78c182 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h @@ -441,6 +441,7 @@ enum { #define FBNIC_TMI_SOP_PROT_CTRL 0x04400 /* 0x11000 */ #define FBNIC_TMI_DROP_CTRL 0x04401 /* 0x11004 */ #define FBNIC_TMI_DROP_CTRL_EN CSR_BIT(0) +#define FBNIC_TMI_DROP_CTRL_CMPL_DIS CSR_BIT(1) #define FBNIC_TMI_DROP_PKTS 0x04402 /* 0x11008 */ #define FBNIC_TMI_DROP_BYTE_L 0x04403 /* 0x1100c */ #define FBNIC_TMI_ILLEGAL_PTP_REQS 0x04409 /* 0x11024 */ @@ -955,6 +956,10 @@ enum { /* PUL User Registers */ #define FBNIC_CSR_START_PUL_USER 0x31000 /* CSR section delimiter */ +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS \ + 0x31030 /* 0xc40c0 */ +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS_AW_FLUSH_DONE CSR_BIT(7) +#define FBNIC_PUL_USER_IP_LINK_RST_STATUS_AR_FLUSH_DONE CSR_BIT(8) #define FBNIC_PUL_OB_TLP_HDR_AW_CFG 0x3103d /* 0xc40f4 */ #define FBNIC_PUL_OB_TLP_HDR_AW_CFG_FLUSH_MODE CSR_BIT(20) #define FBNIC_PUL_OB_TLP_HDR_AW_CFG_FLUSH CSR_BIT(19) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c index 49b8813a356438..e00d626f643847 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "fbnic.h" @@ -176,10 +177,25 @@ static void fbnic_mbx_unmap_and_free_msg(struct fbnic_dev *fbd, int mbx_idx, static void fbnic_mbx_clean_desc_ring(struct fbnic_dev *fbd, int mbx_idx) { + u32 flush_done, val; int i; fbnic_mbx_reset_desc_ring(fbd, mbx_idx); + /* Arming the flush only starts it. Wait for the outbound path to + * retire the requests it still holds before the buffers they may + * target are unmapped and freed. A lost link reads back as all ones, + * which ends the poll on the first pass. + */ + flush_done = mbx_idx == FBNIC_IPC_MBX_RX_IDX ? + FBNIC_PUL_USER_IP_LINK_RST_STATUS_AW_FLUSH_DONE : + FBNIC_PUL_USER_IP_LINK_RST_STATUS_AR_FLUSH_DONE; + if (read_poll_timeout_atomic(fbnic_rd32, val, val & flush_done, 2, + 1000, false, fbd, + FBNIC_PUL_USER_IP_LINK_RST_STATUS)) + dev_warn(fbd->dev, "Outbound flush did not complete: %08x\n", + val); + for (i = FBNIC_IPC_MBX_DESC_LEN; i--;) fbnic_mbx_unmap_and_free_msg(fbd, mbx_idx, i); } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c index 8a6703afca3848..52244219d16687 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c @@ -86,11 +86,11 @@ static int fbnic_stop(struct net_device *netdev) { struct fbnic_net *fbn = netdev_priv(netdev); + fbnic_down(fbn); + fbnic_mac_free_irq(fbn->fbd); phylink_suspend(fbn->phylink, fbnic_bmc_present(fbn->fbd)); - fbnic_down(fbn); - fbnic_time_stop(fbn); fbnic_fw_xmit_ownership_msg(fbn->fbd, false); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c index ad234bb0f75d02..09ae797b1f0dc6 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_pci.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_pci.c @@ -181,10 +181,15 @@ static int fbnic_fw_config_after_crash(struct fbnic_dev *fbd) return -1; } + /* The rx mode work rewrites the same shadow under the instance lock + * alone, and this runs from the service task under RTNL only. + */ + netdev_lock(fbd->netdev); fbnic_rpc_reset_valid_entries(fbd); netif_addr_lock_bh(fbd->netdev); __fbnic_set_rx_mode(fbd, &fbd->netdev->uc, &fbd->netdev->mc); netif_addr_unlock_bh(fbd->netdev); + netdev_unlock(fbd->netdev); return 0; } @@ -229,18 +234,25 @@ static void fbnic_service_task(struct work_struct *work) fbnic_fw_check_heartbeat(fbd); - fbnic_health_check(fbd); - - fbnic_bmc_rpc_check(fbd); - if (netif_carrier_ok(fbd->netdev)) { netdev_lock(fbd->netdev); fbnic_napi_depletion_check(fbd->netdev); netdev_unlock(fbd->netdev); } - if (netif_running(netdev)) + /* fbnic_service_task_stop() does not wait for a pass that is already + * blocked on RTNL, so one can run after ndo_stop. Leave host state + * alone in that case, and do not re-arm; __fbnic_open() reclaims and + * rebuilds it. The PM path calls ndo_stop with the device detached but + * still running; fbnic_up() starts the task again on resume. + */ + if (netif_running(netdev) && netif_device_present(netdev)) { + fbnic_health_check(fbd); + + fbnic_bmc_rpc_check(fbd); + schedule_delayed_work(&fbd->service_task, HZ); + } rtnl_unlock(); } @@ -453,6 +465,12 @@ static int fbnic_pm_suspend(struct device *dev) netdev_unlock(netdev); rtnl_unlock(); + /* ndo_stop could not wait for a pass already blocked on RTNL. That + * pass no longer re-arms, but wait for it to finish before the + * mailbox, IRQs and MMIO go away. + */ + cancel_delayed_work_sync(&fbd->service_task); + null_uc_addr: fbnic_fw_log_disable(fbd); @@ -553,19 +571,26 @@ static void __fbnic_pm_attach(struct device *dev) struct net_device *netdev = fbd->netdev; struct fbnic_net *fbn; - rtnl_lock(); - fbnic_reset_hw_stats(fbd); - rtnl_unlock(); - if (fbnic_init_failure(fbd)) return; fbn = netdev_priv(netdev); + /* Hold RTNL until the device is attached, so the service task pass + * fbnic_up() schedules cannot run until it will see it present. + */ + rtnl_lock(); + netdev_lock(netdev); + + fbnic_reset_hw_stats(fbd); + if (netif_running(netdev)) fbnic_up(fbn); netif_device_attach(netdev); + + netdev_unlock(netdev); + rtnl_unlock(); } static int __maybe_unused fbnic_pm_resume(struct device *dev) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index c572a0062e774a..07d4b2e923627b 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -2072,7 +2072,7 @@ static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn, fbnic_bdq_set_page_size(&qt->sub1, rx_page_size); - err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, qt->sub0.q_idx, + err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, qt->cmpl.q_idx, nv->napi.napi_id); if (err) goto free_page_pools; @@ -2349,15 +2349,19 @@ void fbnic_disable(struct fbnic_net *fbn) static void fbnic_tx_flush(struct fbnic_dev *fbd) { + u32 drop_ctrl = FBNIC_TMI_DROP_CTRL_EN | FBNIC_TMI_DROP_CTRL_CMPL_DIS; + netdev_warn(fbd->netdev, "triggering Tx flush\n"); - fbnic_rmw32(fbd, FBNIC_TMI_DROP_CTRL, FBNIC_TMI_DROP_CTRL_EN, - FBNIC_TMI_DROP_CTRL_EN); + /* Drop packets and retire their PTP completions */ + fbnic_rmw32(fbd, FBNIC_TMI_DROP_CTRL, drop_ctrl, drop_ctrl); } static void fbnic_tx_flush_off(struct fbnic_dev *fbd) { - fbnic_rmw32(fbd, FBNIC_TMI_DROP_CTRL, FBNIC_TMI_DROP_CTRL_EN, 0); + u32 drop_ctrl = FBNIC_TMI_DROP_CTRL_EN | FBNIC_TMI_DROP_CTRL_CMPL_DIS; + + fbnic_rmw32(fbd, FBNIC_TMI_DROP_CTRL, drop_ctrl, 0); } struct fbnic_idle_regs { diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c b/drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c index fe4e6140528405..790d89ed937057 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_ethtool.c @@ -694,9 +694,8 @@ int lan966x_stats_init(struct lan966x *lan966x) lan966x->stats_layout = lan966x_stats_layout; lan966x->num_stats = ARRAY_SIZE(lan966x_stats_layout); - lan966x->stats = devm_kcalloc(lan966x->dev, lan966x->num_phys_ports * - lan966x->num_stats, - sizeof(u64), GFP_KERNEL); + lan966x->stats = devm_kzalloc_objs(lan966x->dev, u64, + lan966x->num_phys_ports * lan966x->num_stats); if (!lan966x->stats) return -ENOMEM; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 21668bbcc9063e..1fbe910c5ec389 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -353,6 +353,12 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight) if (!fdma_db_is_done(db)) continue; + /* XDP and page pool APIs can't be used with a budget of 0. + * Leave these buffers for the next NAPI poll. + */ + if (!weight && !dcb_buf->use_skb) + continue; + dcb_buf->dev->stats.tx_packets++; dcb_buf->dev->stats.tx_bytes += dcb_buf->len; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index c276fec2f9d6f2..b8696fc7e9b936 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -1138,7 +1138,7 @@ static int lan966x_probe(struct platform_device *pdev) u8 mac_addr[ETH_ALEN]; int err; - lan966x = devm_kzalloc(&pdev->dev, sizeof(*lan966x), GFP_KERNEL); + lan966x = devm_kzalloc_obj(&pdev->dev, *lan966x); if (!lan966x) return -ENOMEM; @@ -1167,9 +1167,8 @@ static int lan966x_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, err, "Reset failed"); lan966x->num_phys_ports = NUM_PHYS_PORTS; - lan966x->ports = devm_kcalloc(&pdev->dev, lan966x->num_phys_ports, - sizeof(struct lan966x_port *), - GFP_KERNEL); + lan966x->ports = devm_kzalloc_objs(&pdev->dev, struct lan966x_port *, + lan966x->num_phys_ports); if (!lan966x->ports) return -ENOMEM; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c index d42c57bead89d9..02aed761d21175 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c @@ -1253,10 +1253,8 @@ int sparx5_stats_init(struct sparx5 *sparx5) sparx5->stats_layout = sparx5_stats_layout; sparx5->num_stats = spx5_stats_count; sparx5->num_ethtool_stats = ARRAY_SIZE(sparx5_stats_layout); - sparx5->stats = devm_kcalloc(sparx5->dev, - consts->n_ports_all * - sparx5->num_stats, - sizeof(u64), GFP_KERNEL); + sparx5->stats = devm_kzalloc_objs(sparx5->dev, u64, + consts->n_ports_all * sparx5->num_stats); if (!sparx5->stats) return -ENOMEM; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c index 2bf9c5f64151ca..57c58a3544714f 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -244,8 +244,7 @@ static struct sparx5_mact_entry *alloc_mact_entry(struct sparx5 *sparx5, { struct sparx5_mact_entry *mact_entry; - mact_entry = devm_kzalloc(sparx5->dev, - sizeof(*mact_entry), GFP_ATOMIC); + mact_entry = devm_kzalloc_obj(sparx5->dev, *mact_entry, GFP_ATOMIC); if (!mact_entry) return NULL; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c index e039f5369b95e2..08a398adf1214e 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c @@ -794,7 +794,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev) if (!np && !pdev->dev.platform_data) return -ENODEV; - sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5), GFP_KERNEL); + sparx5 = devm_kzalloc_obj(&pdev->dev, *sparx5); if (!sparx5) return -ENOMEM; diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c index 2826e48af1033e..9f61692b243b7e 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c @@ -204,9 +204,10 @@ static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb, *rew_op = IFH_REW_OP_TWO_STEP_PTP; } -static void sparx5_ptp_txtstamp_old_release(struct sparx5_port *port) +static unsigned int sparx5_ptp_txtstamp_old_release(struct sparx5_port *port) { struct sk_buff *skb, *skb_tmp; + unsigned int purged = 0; unsigned long flags; spin_lock_irqsave(&port->tx_skbs.lock, flags); @@ -217,8 +218,11 @@ static void sparx5_ptp_txtstamp_old_release(struct sparx5_port *port) __skb_unlink(skb, &port->tx_skbs); dev_kfree_skb_any(skb); + purged++; } spin_unlock_irqrestore(&port->tx_skbs.lock, flags); + + return purged; } int sparx5_ptp_txtstamp_request(struct sparx5_port *port, @@ -226,6 +230,7 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port, { struct sparx5 *sparx5 = port->sparx5; u8 rew_op, pdu_type, pdu_w16_offset; + unsigned int purged; unsigned long flags; sparx5_ptp_classify(port, skb, &rew_op, &pdu_type, &pdu_w16_offset); @@ -236,9 +241,10 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port, if (rew_op != IFH_REW_OP_TWO_STEP_PTP) return 0; - sparx5_ptp_txtstamp_old_release(port); + purged = sparx5_ptp_txtstamp_old_release(port); spin_lock_irqsave(&sparx5->ptp_ts_id_lock, flags); + sparx5->ptp_skbs -= purged; if (sparx5->ptp_skbs == SPARX5_MAX_PTP_ID) { spin_unlock_irqrestore(&sparx5->ptp_ts_id_lock, flags); return -EBUSY; diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c index 476f7496a9d449..16bd63f653bf07 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c @@ -389,7 +389,7 @@ void vcap_port_debugfs(struct device *dev, struct dentry *parent, { struct vcap_port_debugfs_info *info; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return; @@ -409,7 +409,7 @@ void vcap_port_debugfs_portno(struct device *dev, struct vcap_port_debugfs_info *info; char name[16]; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return; @@ -469,7 +469,7 @@ struct dentry *vcap_debugfs(struct device *dev, struct dentry *parent, list_for_each_entry(admin, &vctrl->list, list) { sprintf(name, "raw_%s_%d", vctrl->vcaps[admin->vtype].name, admin->vinst); - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return NULL; info->vctrl = vctrl; diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 8c915e0087846f..ab942d5bfe0585 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -757,6 +757,27 @@ void mana_gd_free_service_wq(struct gdma_context *gc) gc->service_wq = NULL; } +static void mana_gd_schedule_eq_cqs(struct gdma_queue *eq) +{ + struct gdma_context *gc = eq->gdma_dev->gdma_context; + struct gdma_queue *cq; + u8 i; + + for (i = 0; i < GDMA_EQ_MAX_CHILD_CQ; i++) { + cq = rcu_dereference(eq->eq.child_cq[i]); + + if (!cq) + continue; + + if (cq->id >= READ_ONCE(gc->max_num_cqs) || + !gc->cq_table || gc->cq_table[cq->id] != cq) + continue; + + if (cq->cq.callback) + cq->cq.callback(cq->cq.context, cq); + } +} + static void mana_gd_process_eqe(struct gdma_queue *eq) { u32 head = eq->head % (eq->queue_size / GDMA_EQE_SIZE); @@ -787,6 +808,14 @@ static void mana_gd_process_eqe(struct gdma_queue *eq) break; + case GDMA_EQE_THROTTLE: + u64_stats_update_begin(&eq->eq.stats.syncp); + u64_stats_inc(&eq->eq.stats.throttle_count); + u64_stats_update_end(&eq->eq.stats.syncp); + + mana_gd_schedule_eq_cqs(eq); + break; + case GDMA_EQE_TEST_EVENT: gc->test_event_eq_id = eq->id; complete(&gc->eq_test_event); @@ -1032,6 +1061,8 @@ static int mana_gd_create_eq(struct gdma_dev *gd, queue->eq.msix_index = INVALID_PCI_MSIX_INDEX; queue->id = INVALID_QUEUE_ID; + u64_stats_init(&queue->eq.stats.syncp); + log2_num_entries = ilog2(queue->queue_size / GDMA_EQE_SIZE); if (spec->eq.log2_throttle_limit > log2_num_entries) { @@ -1073,25 +1104,66 @@ static void mana_gd_create_cq(const struct gdma_queue_spec *spec, struct gdma_queue *queue) { u32 log2_num_entries = ilog2(spec->queue_size / GDMA_CQE_SIZE); + struct gdma_queue *parent; + u8 i; queue->head |= INITIALIZED_OWNER_BIT(log2_num_entries); - queue->cq.parent = spec->cq.parent_eq; + parent = spec->cq.parent_eq; + queue->cq.parent = parent; queue->cq.context = spec->cq.context; queue->cq.callback = spec->cq.callback; + + if (!parent) + return; + + /* For throttled EQE store the child CQ */ + for (i = 0; i < GDMA_EQ_MAX_CHILD_CQ; i++) { + if (!rcu_access_pointer(parent->eq.child_cq[i])) { + rcu_assign_pointer(parent->eq.child_cq[i], queue); + return; + } + } + + WARN_ONCE(1, "mana: EQ %u has no free child CQ slot\n", parent->id); } -static void mana_gd_destroy_cq(struct gdma_context *gc, - struct gdma_queue *queue) +/* Unlink queue from its parent EQ's child_cq[] and from gc->cq_table[]. + * + * Return: true if queue was in the parent EQ's child_cq[]. In that case the + * caller must wait for an RCU grace period before freeing queue, because + * mana_gd_intr() may still be handling a throttle EQE for it. + */ +bool mana_gd_detach_cq(struct gdma_context *gc, struct gdma_queue *queue) { + struct gdma_queue *eq = queue->cq.parent; + bool attached = false; u32 id = queue->id; + u8 i; + + if (eq) { + for (i = 0; i < GDMA_EQ_MAX_CHILD_CQ; i++) { + if (rcu_access_pointer(eq->eq.child_cq[i]) == queue) { + RCU_INIT_POINTER(eq->eq.child_cq[i], NULL); + attached = true; + } + } + } - if (id >= gc->max_num_cqs) - return; + /* Check if CQ might have been detached already, only clear if + * it still points to same queue . + */ + if (id < gc->max_num_cqs && READ_ONCE(gc->cq_table[id]) == queue) + WRITE_ONCE(gc->cq_table[id], NULL); - if (!gc->cq_table[id]) - return; + return attached; +} - gc->cq_table[id] = NULL; +static void mana_gd_destroy_cq(struct gdma_context *gc, + struct gdma_queue *queue) +{ + /* Wait for irq reader holding the cq */ + if (mana_gd_detach_cq(gc, queue)) + synchronize_net(); } int mana_gd_create_hwc_queue(struct gdma_dev *gd, diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c index ed8925296c8a73..edfadfd89829a7 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c @@ -202,7 +202,7 @@ static int mana_pci_schedule_serv_work(struct gdma_context *gc, return -ENODEV; } - mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC); + mns_wk = kzalloc_obj(*mns_wk, GFP_ATOMIC); if (!mns_wk) { module_put(THIS_MODULE); clear_bit(GC_IN_SERVICE, &gc->flags); diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c index 3bca4b683134b8..fb9f38f65911ca 100644 --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c @@ -364,7 +364,7 @@ static void mana_hwc_comp_event(void *ctx, struct gdma_queue *q_self) completions = hwc_cq->comp_buf; comp_read = mana_gd_poll_cq(q_self, completions, hwc_cq->queue_depth); - WARN_ON_ONCE(comp_read <= 0 || comp_read > hwc_cq->queue_depth); + WARN_ON_ONCE(comp_read < 0 || comp_read > hwc_cq->queue_depth); for (i = 0; i < comp_read; ++i) { comp_data = *(struct hwc_rx_oob *)completions[i].cqe_data; @@ -820,9 +820,14 @@ void mana_hwc_destroy_channel(struct gdma_context *gc) */ if (gc->max_num_cqs > 0) { mana_smc_teardown_hwc(&gc->shm_channel, false); - gc->max_num_cqs = 0; + WRITE_ONCE(gc->max_num_cqs, 0); } + if (hwc->cq) + mana_gd_detach_cq(gc, hwc->cq->gdma_cq); + + synchronize_rcu(); + if (hwc->txq) mana_hwc_destroy_wq(hwc, hwc->txq); diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c index 7c55f8724441da..494267b3069a37 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c @@ -78,7 +78,8 @@ int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames, } u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, - struct xdp_buff *xdp, void *buf_va, uint pkt_len) + struct xdp_buff *xdp, void *buf_va, bool from_pool, + uint pkt_len) { struct mana_stats_rx *rx_stats; struct bpf_prog *prog; @@ -90,7 +91,11 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, if (!prog) goto out; - xdp_init_buff(xdp, PAGE_SIZE, &rxq->xdp_rxq); + /* A redirected buffer is freed by its memory model, so a buffer not + * from the page pool must not claim MEM_TYPE_PAGE_POOL. + */ + xdp_init_buff(xdp, PAGE_SIZE, + from_pool ? &rxq->xdp_rxq : &rxq->xdp_rxq_shared); xdp_prepare_buff(xdp, buf_va, rxq->headroom, pkt_len, true); act = bpf_prog_run_xdp(prog, xdp); diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 6b7c027e497ed1..7e9223143fc75f 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -2157,7 +2157,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool, return; } - act = mana_run_xdp(ndev, rxq, &xdp, buf_va, pkt_len); + act = mana_run_xdp(ndev, rxq, &xdp, buf_va, from_pool, pkt_len); if (act == XDP_REDIRECT && !rxq->xdp_rc) return; @@ -2179,10 +2179,9 @@ static void mana_rx_skb(void *buf_va, bool from_pool, skb_checksum_none_assert(skb); skb_record_rx_queue(skb, rxq_idx); - if ((ndev->features & NETIF_F_RXCSUM) && cqe->rx_iphdr_csum_succeed) { - if (cqe->rx_tcp_csum_succeed || cqe->rx_udp_csum_succeed) - skb->ip_summed = CHECKSUM_UNNECESSARY; - } + if ((ndev->features & NETIF_F_RXCSUM) && + (cqe->rx_tcp_csum_succeed || cqe->rx_udp_csum_succeed)) + skb->ip_summed = CHECKSUM_UNNECESSARY; if (cqe->rx_hashtype != 0 && (ndev->features & NETIF_F_RXHASH)) { if (cqe->rx_hashtype & MANA_HASH_L4) @@ -2703,6 +2702,7 @@ static void mana_deinit_txq(struct mana_port_context *apc, struct mana_txq *txq) static void mana_destroy_txq(struct mana_port_context *apc) { + struct gdma_context *gc = apc->ac->gdma_dev->gdma_context; struct napi_struct *napi; int i; @@ -2721,8 +2721,6 @@ static void mana_destroy_txq(struct mana_port_context *apc) napi_synchronize(napi); napi_disable_locked(napi); cancel_work_sync(&apc->tx_qp[i]->tx_cq.dim.work); - netif_napi_del_locked(napi); - apc->tx_qp[i]->txq.napi_initialized = false; } /* Forget the SKBs freed without being completed after a drain @@ -2735,6 +2733,18 @@ static void mana_destroy_txq(struct mana_port_context *apc) if (apc->tx_qp[i]->tx_object != INVALID_MANA_HANDLE) mana_destroy_wq_obj(apc, GDMA_SQ, apc->tx_qp[i]->tx_object); + if (apc->tx_qp[i]->txq.napi_initialized) { + /* Detach the CQ only after the WQ object is destroyed, + * so a completion EQE that arrives before then still + * finds the CQ in cq_table[] rather than hitting the + * WARN in mana_gd_process_eqe(). One grace period then + * covers both mana_gd_intr() and NAPI users. + */ + mana_gd_detach_cq(gc, apc->tx_qp[i]->tx_cq.gdma_cq); + netif_napi_del_locked(napi); + apc->tx_qp[i]->txq.napi_initialized = false; + } + mana_deinit_cq(apc, &apc->tx_qp[i]->tx_cq); mana_deinit_txq(apc, &apc->tx_qp[i]->txq); @@ -2941,15 +2951,23 @@ static void mana_destroy_rxq(struct mana_port_context *apc, napi_disable_locked(napi); cancel_work_sync(&rxq->rx_cq.dim.work); - netif_napi_del_locked(napi); } if (xdp_rxq_info_is_reg(&rxq->xdp_rxq)) xdp_rxq_info_unreg(&rxq->xdp_rxq); + if (xdp_rxq_info_is_reg(&rxq->xdp_rxq_shared)) + xdp_rxq_info_unreg(&rxq->xdp_rxq_shared); + if (rxq->rxobj != INVALID_MANA_HANDLE) mana_destroy_wq_obj(apc, GDMA_RQ, rxq->rxobj); + if (napi_initialized) { + /* See the comment in mana_destroy_txq() */ + mana_gd_detach_cq(gc, rxq->rx_cq.gdma_cq); + netif_napi_del_locked(napi); + } + mana_deinit_cq(apc, &rxq->rx_cq); if (rxq->xdp_save_va) @@ -3225,6 +3243,12 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc, WARN_ON(xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq, MEM_TYPE_PAGE_POOL, rxq->page_pool)); + /* The pre-allocated buffers (mana_pre_alloc_rxbufs) are plain pages */ + WARN_ON(xdp_rxq_info_reg(&rxq->xdp_rxq_shared, ndev, rxq_idx, + cq->napi.napi_id)); + WARN_ON(xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq_shared, + MEM_TYPE_PAGE_SHARED, NULL)); + /* Initialize the DIM work before enabling NAPI, so that a poll * cannot reach net_dim() with an uninitialized cq->dim.work. */ @@ -3355,7 +3379,7 @@ static int mana_rss_table_alloc(struct mana_port_context *apc) return -EINVAL; } - apc->indir_table = kcalloc(apc->indir_table_sz, sizeof(u32), GFP_KERNEL); + apc->indir_table = kzalloc_objs(u32, apc->indir_table_sz); if (!apc->indir_table) return -ENOMEM; diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c index 33db79569d3b6e..4068e08acb1667 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c @@ -147,7 +147,8 @@ static int mana_get_sset_count(struct net_device *ndev, int stringset) return ARRAY_SIZE(mana_eth_stats) + ARRAY_SIZE(mana_phy_stats) + ARRAY_SIZE(mana_hc_stats) + - num_queues * (MANA_STATS_RX_COUNT + MANA_STATS_TX_COUNT); + num_queues * (MANA_STATS_RX_COUNT + MANA_STATS_TX_COUNT + + MANA_STATS_EQ_COUNT); case ETH_SS_PRIV_FLAGS: return MANA_PRIV_FLAG_MAX; @@ -198,6 +199,9 @@ static void mana_get_strings_stats(struct mana_port_context *apc, u8 **data) ethtool_sprintf(data, "tx_%d_csum_partial", i); ethtool_sprintf(data, "tx_%d_mana_map_err", i); } + + for (i = 0; i < num_queues; i++) + ethtool_sprintf(data, "eq_%d_throttle_events", i); } static void mana_get_strings_priv_flags(u8 **data) @@ -234,6 +238,7 @@ static void mana_get_ethtool_stats(struct net_device *ndev, void *phy_stats = &apc->phy_stats; struct mana_stats_rx *rx_stats; struct mana_stats_tx *tx_stats; + struct gdma_eq_stats *eq_stats; unsigned int start; u64 packets, bytes; u64 xdp_redirect; @@ -251,6 +256,7 @@ static void mana_get_ethtool_stats(struct net_device *ndev, u64 csum_partial; u64 mana_map_err; int q, i = 0, j; + u64 throttled; if (!apc->port_is_up) return; @@ -325,6 +331,17 @@ static void mana_get_ethtool_stats(struct net_device *ndev, data[i++] = csum_partial; data[i++] = mana_map_err; } + + for (q = 0; q < num_queues; q++) { + eq_stats = &apc->eqs[q].eq->eq.stats; + + do { + start = u64_stats_fetch_begin(&eq_stats->syncp); + throttled = u64_stats_read(&eq_stats->throttle_count); + } while (u64_stats_fetch_retry(&eq_stats->syncp, start)); + + data[i++] = throttled; + } } static u32 mana_get_rx_ring_count(struct net_device *ndev) @@ -382,7 +399,7 @@ static int mana_set_rxfh(struct net_device *ndev, rxfh->hfunc != ETH_RSS_HASH_TOP) return -EOPNOTSUPP; - save_table = kcalloc(apc->indir_table_sz, sizeof(u32), GFP_KERNEL); + save_table = kzalloc_objs(u32, apc->indir_table_sz); if (!save_table) return -ENOMEM; diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 67ecd0e9100297..9dfddad1aaea9c 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -2140,7 +2140,7 @@ int ocelot_port_mdb_add(struct ocelot *ocelot, int port, mc = ocelot_multicast_get(ocelot, mdb->addr, vid); if (!mc) { /* New entry */ - mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(ocelot->dev, *mc); if (!mc) return -ENOMEM; diff --git a/drivers/net/ethernet/mscc/ocelot_fdma.c b/drivers/net/ethernet/mscc/ocelot_fdma.c index 00326ae8c708b0..d84fed2cb787d5 100644 --- a/drivers/net/ethernet/mscc/ocelot_fdma.c +++ b/drivers/net/ethernet/mscc/ocelot_fdma.c @@ -817,7 +817,7 @@ void ocelot_fdma_init(struct platform_device *pdev, struct ocelot *ocelot) struct ocelot_fdma *fdma; int ret; - fdma = devm_kzalloc(dev, sizeof(*fdma), GFP_KERNEL); + fdma = devm_kzalloc_obj(dev, *fdma); if (!fdma) return; diff --git a/drivers/net/ethernet/mscc/ocelot_mm.c b/drivers/net/ethernet/mscc/ocelot_mm.c index c815ae64e39dd5..d1c3209c33d6c6 100644 --- a/drivers/net/ethernet/mscc/ocelot_mm.c +++ b/drivers/net/ethernet/mscc/ocelot_mm.c @@ -278,8 +278,8 @@ int ocelot_mm_init(struct ocelot *ocelot) if (!ocelot->mm_supported) return 0; - ocelot->mm = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, - sizeof(*ocelot->mm), GFP_KERNEL); + ocelot->mm = devm_kzalloc_objs(ocelot->dev, *ocelot->mm, + ocelot->num_phys_ports); if (!ocelot->mm) return -ENOMEM; diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c index d2be1be3771658..82d27412dea795 100644 --- a/drivers/net/ethernet/mscc/ocelot_stats.c +++ b/drivers/net/ethernet/mscc/ocelot_stats.c @@ -936,8 +936,7 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot) ocelot->map[SYS][last & REG_MASK] + 4) { region->count++; } else { - region = devm_kzalloc(ocelot->dev, sizeof(*region), - GFP_KERNEL); + region = devm_kzalloc_obj(ocelot->dev, *region); if (!region) return -ENOMEM; @@ -960,8 +959,8 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot) dev_dbg(ocelot->dev, "region of %d contiguous counters starting with SYS:STAT:CNT[0x%03x]\n", region->count, addr / 4); - region->buf = devm_kcalloc(ocelot->dev, region->count, - sizeof(*region->buf), GFP_KERNEL); + region->buf = devm_kzalloc_objs(ocelot->dev, *region->buf, + region->count); if (!region->buf) return -ENOMEM; } @@ -987,9 +986,8 @@ int ocelot_stats_init(struct ocelot *ocelot) if (!ocelot_port) continue; - ocelot_port->ts_stats = devm_kzalloc(ocelot->dev, - sizeof(*ocelot_port->ts_stats), - GFP_KERNEL); + ocelot_port->ts_stats = devm_kzalloc_obj(ocelot->dev, + *ocelot_port->ts_stats); if (!ocelot_port->ts_stats) return -ENOMEM; diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 498eec8ae61d83..25d040f35410b4 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -152,15 +152,14 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev, int port, err; u32 reg; - ocelot->ports = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, - sizeof(struct ocelot_port *), GFP_KERNEL); + ocelot->ports = devm_kzalloc_objs(ocelot->dev, struct ocelot_port *, + ocelot->num_phys_ports); if (!ocelot->ports) return -ENOMEM; - ocelot->devlink_ports = devm_kcalloc(ocelot->dev, - ocelot->num_phys_ports, - sizeof(*ocelot->devlink_ports), - GFP_KERNEL); + ocelot->devlink_ports = devm_kzalloc_objs(ocelot->dev, + *ocelot->devlink_ports, + ocelot->num_phys_ports); if (!ocelot->devlink_ports) return -ENOMEM; diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c index cf40ddc4519211..e890cafdd65adf 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c @@ -14,7 +14,7 @@ static struct nbl_hw_mgt *nbl_hw_setup_hw_mgt(struct nbl_common_info *common) struct device *dev = common->dev; struct nbl_hw_mgt *hw_mgt; - hw_mgt = devm_kzalloc(dev, sizeof(*hw_mgt), GFP_KERNEL); + hw_mgt = devm_kzalloc_obj(dev, *hw_mgt); if (!hw_mgt) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c index f2552bc7329376..442da73835b004 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c @@ -19,7 +19,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, struct nbl_adapter *adapter; int ret; - adapter = devm_kzalloc(&pdev->dev, sizeof(*adapter), GFP_KERNEL); + adapter = devm_kzalloc_obj(&pdev->dev, *adapter); if (!adapter) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/netronome/nfp/abm/main.c b/drivers/net/ethernet/netronome/nfp/abm/main.c index 9b6bda523191e3..c4b6db44f4e30e 100644 --- a/drivers/net/ethernet/netronome/nfp/abm/main.c +++ b/drivers/net/ethernet/netronome/nfp/abm/main.c @@ -477,8 +477,7 @@ static int nfp_abm_init(struct nfp_app *app) if (!abm->threshold_undef) goto err_free_abm; - abm->thresholds = kvcalloc(abm->num_thresholds, - sizeof(*abm->thresholds), GFP_KERNEL); + abm->thresholds = kvzalloc_objs(*abm->thresholds, abm->num_thresholds); if (!abm->thresholds) goto err_free_thresh_umap; diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c index 230d5ff99dd7e1..d59a5ab7efcd60 100644 --- a/drivers/net/ethernet/ni/nixge.c +++ b/drivers/net/ethernet/ni/nixge.c @@ -299,9 +299,8 @@ static int nixge_hw_dma_bd_init(struct net_device *ndev) if (!priv->tx_bd_v) goto out; - priv->tx_skb = devm_kcalloc(ndev->dev.parent, - TX_BD_NUM, sizeof(*priv->tx_skb), - GFP_KERNEL); + priv->tx_skb = devm_kzalloc_objs(ndev->dev.parent, *priv->tx_skb, + TX_BD_NUM); if (!priv->tx_skb) goto out; diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index 364027c39fa4a9..8e86cfde6d1c8b 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -1464,7 +1464,7 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev, struct oa_tc6 *tc6; int ret; - tc6 = devm_kzalloc(&spi->dev, sizeof(*tc6), GFP_KERNEL); + tc6 = devm_kzalloc_obj(&spi->dev, *tc6); if (!tc6) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c index ba3d10f9aec6b9..13f00a80f6daf9 100644 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c @@ -556,13 +556,13 @@ static void pch_gbe_mac_set_pause_packet(struct pch_gbe_hw *hw) */ static int pch_gbe_alloc_queues(struct pch_gbe_adapter *adapter) { - adapter->tx_ring = devm_kzalloc(&adapter->pdev->dev, - sizeof(*adapter->tx_ring), GFP_KERNEL); + adapter->tx_ring = devm_kzalloc_obj(&adapter->pdev->dev, + *adapter->tx_ring); if (!adapter->tx_ring) return -ENOMEM; - adapter->rx_ring = devm_kzalloc(&adapter->pdev->dev, - sizeof(*adapter->rx_ring), GFP_KERNEL); + adapter->rx_ring = devm_kzalloc_obj(&adapter->pdev->dev, + *adapter->rx_ring); if (!adapter->rx_ring) return -ENOMEM; return 0; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_debugfs.c b/drivers/net/ethernet/pensando/ionic/ionic_debugfs.c index c98b4e75e28858..071bd1ba78f9ff 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_debugfs.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_debugfs.c @@ -147,7 +147,7 @@ void ionic_debugfs_add_qcq(struct ionic_lif *lif, struct ionic_qcq *qcq) debugfs_create_file("tail", 0400, q_dentry, q, &q_tail_fops); debugfs_create_file("head", 0400, q_dentry, q, &q_head_fops); - desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); + desc_blob = devm_kzalloc_obj(dev, *desc_blob); if (!desc_blob) return; desc_blob->data = q->base; @@ -155,7 +155,7 @@ void ionic_debugfs_add_qcq(struct ionic_lif *lif, struct ionic_qcq *qcq) debugfs_create_blob("desc_blob", 0400, q_dentry, desc_blob); if (qcq->flags & IONIC_QCQ_F_SG) { - desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); + desc_blob = devm_kzalloc_obj(dev, *desc_blob); if (!desc_blob) return; desc_blob->data = q->sg_base; @@ -173,7 +173,7 @@ void ionic_debugfs_add_qcq(struct ionic_lif *lif, struct ionic_qcq *qcq) debugfs_create_file("tail", 0400, cq_dentry, cq, &cq_tail_fops); - desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); + desc_blob = devm_kzalloc_obj(dev, *desc_blob); if (!desc_blob) return; desc_blob->data = cq->base; @@ -190,8 +190,7 @@ void ionic_debugfs_add_qcq(struct ionic_lif *lif, struct ionic_qcq *qcq) debugfs_create_u32("dim_coal_hw", 0400, intr_dentry, &intr->dim_coal_hw); - intr_ctrl_regset = devm_kzalloc(dev, sizeof(*intr_ctrl_regset), - GFP_KERNEL); + intr_ctrl_regset = devm_kzalloc_obj(dev, *intr_ctrl_regset); if (!intr_ctrl_regset) return; intr_ctrl_regset->regs = intr_ctrl_regs; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c index 7f0da2b0defdf0..22d1e4b6d61be8 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c @@ -570,7 +570,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type, *qcq = NULL; - new = devm_kzalloc(dev, sizeof(*new), GFP_KERNEL); + new = devm_kzalloc_obj(dev, *new); if (!new) { netdev_err(lif->netdev, "Cannot allocate queue structure\n"); err = -ENOMEM; @@ -792,21 +792,21 @@ static int ionic_qcqs_alloc(struct ionic_lif *lif) } err = -ENOMEM; - lif->txqcqs = devm_kcalloc(dev, lif->ionic->ntxqs_per_lif, - sizeof(*lif->txqcqs), GFP_KERNEL); + lif->txqcqs = devm_kzalloc_objs(dev, *lif->txqcqs, + lif->ionic->ntxqs_per_lif); if (!lif->txqcqs) goto err_out; - lif->rxqcqs = devm_kcalloc(dev, lif->ionic->nrxqs_per_lif, - sizeof(*lif->rxqcqs), GFP_KERNEL); + lif->rxqcqs = devm_kzalloc_objs(dev, *lif->rxqcqs, + lif->ionic->nrxqs_per_lif); if (!lif->rxqcqs) goto err_out; - lif->txqstats = devm_kcalloc(dev, lif->ionic->ntxqs_per_lif + 1, - sizeof(*lif->txqstats), GFP_KERNEL); + lif->txqstats = devm_kzalloc_objs(dev, *lif->txqstats, + lif->ionic->ntxqs_per_lif + 1); if (!lif->txqstats) goto err_out; - lif->rxqstats = devm_kcalloc(dev, lif->ionic->nrxqs_per_lif + 1, - sizeof(*lif->rxqstats), GFP_KERNEL); + lif->rxqstats = devm_kzalloc_objs(dev, *lif->rxqstats, + lif->ionic->nrxqs_per_lif + 1); if (!lif->rxqstats) goto err_out; @@ -2959,8 +2959,8 @@ int ionic_reconfigure_queues(struct ionic_lif *lif, /* allocate temporary qcq arrays to hold new queue structs */ if (qparam->nxqs != lif->nxqs || qparam->ntxq_descs != lif->ntxq_descs) { - tx_qcqs = devm_kcalloc(lif->ionic->dev, lif->ionic->ntxqs_per_lif, - sizeof(struct ionic_qcq *), GFP_KERNEL); + tx_qcqs = devm_kzalloc_objs(lif->ionic->dev, struct ionic_qcq *, + lif->ionic->ntxqs_per_lif); if (!tx_qcqs) { err = -ENOMEM; goto err_out; @@ -2970,8 +2970,8 @@ int ionic_reconfigure_queues(struct ionic_lif *lif, qparam->nrxq_descs != lif->nrxq_descs || qparam->rxq_features != lif->rxq_features || qparam->xdp_prog != lif->xdp_prog) { - rx_qcqs = devm_kcalloc(lif->ionic->dev, lif->ionic->nrxqs_per_lif, - sizeof(struct ionic_qcq *), GFP_KERNEL); + rx_qcqs = devm_kzalloc_objs(lif->ionic->dev, struct ionic_qcq *, + lif->ionic->nrxqs_per_lif); if (!rx_qcqs) { err = -ENOMEM; goto err_out; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_phc.c b/drivers/net/ethernet/pensando/ionic/ionic_phc.c index 4b8d80a55b72d5..388150cbf7e421 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_phc.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_phc.c @@ -583,7 +583,7 @@ void ionic_lif_alloc_phc(struct ionic_lif *lif) if (!(features & (IONIC_ETH_HW_TIMESTAMP | IONIC_ETH_HW_RDMA_TIMESTAMP))) return; - phc = devm_kzalloc(ionic->dev, sizeof(*phc), GFP_KERNEL); + phc = devm_kzalloc_obj(ionic->dev, *phc); if (!phc) return; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c b/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c index c999754afb5f3c..c8f97d122177e0 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c @@ -156,7 +156,7 @@ int ionic_rx_filter_save(struct ionic_lif *lif, u32 flow_id, u16 rxq_index, hlist_del(&f->by_id); hlist_del(&f->by_hash); } else { - f = devm_kzalloc(dev, sizeof(*f), GFP_ATOMIC); + f = devm_kzalloc_obj(dev, *f, GFP_ATOMIC); if (!f) return -ENOMEM; } @@ -578,8 +578,8 @@ void ionic_rx_filter_sync(struct ionic_lif *lif) hlist_for_each_entry_safe(f, tmp, head, by_id) { if (f->state == IONIC_FILTER_STATE_NEW || f->state == IONIC_FILTER_STATE_OLD) { - sync_item = devm_kzalloc(dev, sizeof(*sync_item), - GFP_ATOMIC); + sync_item = devm_kzalloc_obj(dev, *sync_item, + GFP_ATOMIC); if (!sync_item) goto loop_out; diff --git a/drivers/net/ethernet/qlogic/qed/qed_init_ops.c b/drivers/net/ethernet/qlogic/qed/qed_init_ops.c index edcaecf5b67996..0c18151d4e72a3 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_init_ops.c +++ b/drivers/net/ethernet/qlogic/qed/qed_init_ops.c @@ -214,8 +214,7 @@ int qed_init_alloc(struct qed_hwfn *p_hwfn) if (!rt_data->b_valid) return -ENOMEM; - rt_data->init_val = kcalloc(RUNTIME_ARRAY_SIZE, sizeof(u32), - GFP_KERNEL); + rt_data->init_val = kzalloc_objs(u32, RUNTIME_ARRAY_SIZE); if (!rt_data->init_val) { kfree(rt_data->b_valid); rt_data->b_valid = NULL; diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c index bc82cecd0fe2d4..520798e7961a36 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c @@ -907,12 +907,12 @@ int qlcnic_83xx_alloc_mbx_args(struct qlcnic_cmd_args *mbx, mbx->op_type = QLC_83XX_FW_MBX_CMD; mbx->req.num = mbx_tbl[i].in_args; mbx->rsp.num = mbx_tbl[i].out_args; - mbx->req.arg = kcalloc(mbx->req.num, sizeof(u32), - GFP_ATOMIC); + mbx->req.arg = kzalloc_objs(u32, mbx->req.num, + GFP_ATOMIC); if (!mbx->req.arg) return -ENOMEM; - mbx->rsp.arg = kcalloc(mbx->rsp.num, sizeof(u32), - GFP_ATOMIC); + mbx->rsp.arg = kzalloc_objs(u32, mbx->rsp.num, + GFP_ATOMIC); if (!mbx->rsp.arg) { kfree(mbx->req.arg); mbx->req.arg = NULL; diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c index 1b94c42d669b35..2f4f06d3411c33 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c @@ -61,12 +61,12 @@ int qlcnic_82xx_alloc_mbx_args(struct qlcnic_cmd_args *mbx, if (type == mbx_tbl[i].cmd) { mbx->req.num = mbx_tbl[i].in_args; mbx->rsp.num = mbx_tbl[i].out_args; - mbx->req.arg = kcalloc(mbx->req.num, - sizeof(u32), GFP_ATOMIC); + mbx->req.arg = kzalloc_objs(u32, mbx->req.num, + GFP_ATOMIC); if (!mbx->req.arg) return -ENOMEM; - mbx->rsp.arg = kcalloc(mbx->rsp.num, - sizeof(u32), GFP_ATOMIC); + mbx->rsp.arg = kzalloc_objs(u32, mbx->rsp.num, + GFP_ATOMIC); if (!mbx->rsp.arg) { kfree(mbx->req.arg); mbx->req.arg = NULL; diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c index a106f961e177b3..72d0258cff00ec 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c @@ -452,7 +452,7 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter, return 0; num_vlans = sriov->num_allowed_vlans; - sriov->allowed_vlans = kcalloc(num_vlans, sizeof(u16), GFP_KERNEL); + sriov->allowed_vlans = kzalloc_objs(u16, num_vlans); if (!sriov->allowed_vlans) { qlcnic_sriov_free_vlans(adapter); return -ENOMEM; @@ -729,12 +729,12 @@ static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *mbx, u32 type) mbx->op_type = QLC_BC_CMD; mbx->req.num = mbx_tbl[i].in_args; mbx->rsp.num = mbx_tbl[i].out_args; - mbx->req.arg = kcalloc(mbx->req.num, sizeof(u32), - GFP_ATOMIC); + mbx->req.arg = kzalloc_objs(u32, mbx->req.num, + GFP_ATOMIC); if (!mbx->req.arg) return -ENOMEM; - mbx->rsp.arg = kcalloc(mbx->rsp.num, sizeof(u32), - GFP_ATOMIC); + mbx->rsp.arg = kzalloc_objs(u32, mbx->rsp.num, + GFP_ATOMIC); if (!mbx->rsp.arg) { kfree(mbx->req.arg); mbx->req.arg = NULL; @@ -2167,8 +2167,8 @@ int qlcnic_sriov_alloc_vlans(struct qlcnic_adapter *adapter) for (i = 0; i < sriov->num_vfs; i++) { vf = &sriov->vf_info[i]; - vf->sriov_vlans = kcalloc(sriov->num_allowed_vlans, - sizeof(*vf->sriov_vlans), GFP_KERNEL); + vf->sriov_vlans = kzalloc_objs(*vf->sriov_vlans, + sriov->num_allowed_vlans); if (!vf->sriov_vlans) { qlcnic_sriov_free_vlans(adapter); return -ENOMEM; diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe.c b/drivers/net/ethernet/qualcomm/ppe/ppe.c index b144fd8189983d..a374bf014e798d 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe.c @@ -262,9 +262,8 @@ static int qcom_ppe_probe(struct platform_device *pdev) if (!data) return dev_err_probe(dev, -EINVAL, "PPE no match data provided\n"); - ppe_dev = devm_kzalloc(dev, - struct_size(ppe_dev, icc_paths, data->num_icc_paths), - GFP_KERNEL); + ppe_dev = devm_kzalloc_flex(dev, *ppe_dev, icc_paths, + data->num_icc_paths); if (!ppe_dev) return -ENOMEM; diff --git a/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c b/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c index 8d5a6fad833794..a8dcfd80dd92a1 100644 --- a/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c +++ b/drivers/net/ethernet/qualcomm/ppe/ppe_debugfs.c @@ -827,7 +827,7 @@ void ppe_debugfs_setup(struct ppe_device *ppe_dev) return; for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) { - entry = devm_kzalloc(ppe_dev->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(ppe_dev->dev, *entry); if (!entry) return; diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c index 9016527e229ac0..8f81dc7deef1e3 100644 --- a/drivers/net/ethernet/realtek/8139cp.c +++ b/drivers/net/ethernet/realtek/8139cp.c @@ -600,11 +600,11 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance) goto out_unlock; } - if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr)) - if (napi_schedule_prep(&cp->napi)) { - cpw16_f(IntrMask, cp_norx_intr_mask); + if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr)) { + cpw16_f(IntrMask, cp_norx_intr_mask); + if (napi_schedule_prep(&cp->napi)) __napi_schedule(&cp->napi); - } + } if (status & (TxOK | TxErr | TxEmpty | SWInt)) cp_tx(cp); diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index cd4ebc654dd0b3..f151ab6813932d 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -6880,8 +6880,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->dash_enabled = rtl_dash_is_enabled(tp); if (rtl_hw_support_rss(tp)) { - tp->rss_data = devm_kzalloc(&pdev->dev, sizeof(*tp->rss_data), - GFP_KERNEL); + tp->rss_data = devm_kzalloc_obj(&pdev->dev, *tp->rss_data); if (!tp->rss_data) return -ENOMEM; } @@ -7009,8 +7008,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) } } - tp->rx_ring = kcalloc(tp->num_rx_rings, sizeof(struct rtl8169_rx_ring), - GFP_KERNEL); + tp->rx_ring = kzalloc_objs(struct rtl8169_rx_ring, tp->num_rx_rings); if (!tp->rx_ring) { rc = -ENOMEM; goto err_destroy_phylink; @@ -7019,8 +7017,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) for (int i = 0; i < tp->num_rx_rings; i++) u64_stats_init(&tp->rx_ring[i].stats.syncp); - tp->rtl8169_napi = kcalloc(tp->irq_nvecs, sizeof(struct napi_struct), - GFP_KERNEL); + tp->rtl8169_napi = kzalloc_objs(struct napi_struct, tp->irq_nvecs); if (!tp->rtl8169_napi) { rc = -ENOMEM; goto err_free_rx_ring; diff --git a/drivers/net/ethernet/renesas/rcar_gen4_ptp.c b/drivers/net/ethernet/renesas/rcar_gen4_ptp.c index 27a6f04920978c..da5de448003ac6 100644 --- a/drivers/net/ethernet/renesas/rcar_gen4_ptp.c +++ b/drivers/net/ethernet/renesas/rcar_gen4_ptp.c @@ -183,7 +183,7 @@ struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev, { struct rcar_gen4_ptp_private *ptp; - ptp = devm_kzalloc(&pdev->dev, sizeof(*ptp), GFP_KERNEL); + ptp = devm_kzalloc_obj(&pdev->dev, *ptp); if (!ptp) return NULL; diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c index 64b821ca02f8d5..571f4ccdda52b1 100644 --- a/drivers/net/ethernet/renesas/rswitch_main.c +++ b/drivers/net/ethernet/renesas/rswitch_main.c @@ -2136,7 +2136,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -2168,8 +2168,8 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) priv->gwca.index = AGENT_INDEX_GWCA; priv->gwca.num_queues = min(RSWITCH_NUM_PORTS * NUM_QUEUES_PER_NDEV, RSWITCH_MAX_NUM_QUEUES); - priv->gwca.queues = devm_kcalloc(&pdev->dev, priv->gwca.num_queues, - sizeof(*priv->gwca.queues), GFP_KERNEL); + priv->gwca.queues = devm_kzalloc_objs(&pdev->dev, *priv->gwca.queues, + priv->gwca.num_queues); if (!priv->gwca.queues) return -ENOMEM; diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c index bfaa9aa63fa1bf..762591b62b9178 100644 --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c @@ -3099,7 +3099,7 @@ static int sh_mdio_init(struct sh_eth_private *mdp, struct device_node *pn; /* create bit control struct for PHY */ - bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL); + bitbang = devm_kzalloc_obj(dev, struct bb_info); if (!bitbang) return -ENOMEM; @@ -3208,7 +3208,7 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) phy_interface_t interface; int ret; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c index ace69a1d527575..1e0558bd78c3bf 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -1435,7 +1435,7 @@ static int ofdpa_port_vlan_flood_group(struct ofdpa_port *ofdpa_port, int err = 0; int i; - group_ids = kcalloc(port_count, sizeof(u32), GFP_KERNEL); + group_ids = kzalloc_objs(u32, port_count); if (!group_ids) return -ENOMEM; diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c index 70cf3619555f92..f2fecc3bcea12f 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c @@ -408,13 +408,11 @@ static int init_tx_ring(struct device *dev, u8 queue_no, return -ENOMEM; /* allocate memory for TX skbuff array */ - tx_ring->tx_skbuff_dma = devm_kcalloc(dev, tx_rsize, - sizeof(dma_addr_t), GFP_KERNEL); + tx_ring->tx_skbuff_dma = devm_kzalloc_objs(dev, dma_addr_t, tx_rsize); if (!tx_ring->tx_skbuff_dma) goto dmamem_err; - tx_ring->tx_skbuff = devm_kcalloc(dev, tx_rsize, - sizeof(struct sk_buff *), GFP_KERNEL); + tx_ring->tx_skbuff = devm_kzalloc_objs(dev, struct sk_buff *, tx_rsize); if (!tx_ring->tx_skbuff) goto dmamem_err; @@ -664,8 +662,8 @@ static int txring_mem_alloc(struct sxgbe_priv_data *priv) int queue_num; SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) { - priv->txq[queue_num] = devm_kmalloc(priv->device, - sizeof(struct sxgbe_tx_queue), GFP_KERNEL); + priv->txq[queue_num] = devm_kmalloc_obj(priv->device, + struct sxgbe_tx_queue); if (!priv->txq[queue_num]) return -ENOMEM; } @@ -678,8 +676,8 @@ static int rxring_mem_alloc(struct sxgbe_priv_data *priv) int queue_num; SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { - priv->rxq[queue_num] = devm_kmalloc(priv->device, - sizeof(struct sxgbe_rx_queue), GFP_KERNEL); + priv->rxq[queue_num] = devm_kmalloc_obj(priv->device, + struct sxgbe_rx_queue); if (!priv->rxq[queue_num]) return -ENOMEM; } diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c index e4701b29e1a0f2..1c473591b64413 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c @@ -42,13 +42,11 @@ static int sxgbe_probe_config_dt(struct platform_device *pdev, if (plat->bus_id < 0) plat->bus_id = 0; - plat->mdio_bus_data = devm_kzalloc(&pdev->dev, - sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(&pdev->dev, *plat->mdio_bus_data); if (!plat->mdio_bus_data) return -ENOMEM; - dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL); + dma_cfg = devm_kzalloc_obj(&pdev->dev, *dma_cfg); if (!dma_cfg) return -ENOMEM; @@ -90,9 +88,7 @@ static int sxgbe_platform_probe(struct platform_device *pdev) return PTR_ERR(addr); if (pdev->dev.of_node) { - plat_dat = devm_kzalloc(&pdev->dev, - sizeof(struct sxgbe_plat_data), - GFP_KERNEL); + plat_dat = devm_kzalloc_obj(&pdev->dev, struct sxgbe_plat_data); if (!plat_dat) return -ENOMEM; diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c index 0c197b4486458b..323db6ada50cc7 100644 --- a/drivers/net/ethernet/sfc/falcon/efx.c +++ b/drivers/net/ethernet/sfc/falcon/efx.c @@ -1693,9 +1693,8 @@ static int ef4_probe_filters(struct ef4_nic *efx) ef4_for_each_channel(channel, efx) { channel->rps_flow_id = - kcalloc(efx->type->max_rx_ip_filters, - sizeof(*channel->rps_flow_id), - GFP_KERNEL); + kzalloc_objs(*channel->rps_flow_id, + efx->type->max_rx_ip_filters); if (!channel->rps_flow_id) success = 0; else diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index b6de61062a86ab..d561b933788526 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -1982,10 +1982,10 @@ int efx_mae_insert_ct(struct efx_nic *efx, struct efx_tc_ct_entry *conn) if (!inbuf) return -ENOMEM; - key = kcalloc(kw, sizeof(__le32), GFP_KERNEL); + key = kzalloc_objs(__le32, kw); if (!key) goto out_free; - resp = kcalloc(rw, sizeof(__le32), GFP_KERNEL); + resp = kzalloc_objs(__le32, rw); if (!resp) goto out_free; @@ -2053,7 +2053,7 @@ int efx_mae_remove_ct(struct efx_nic *efx, struct efx_tc_ct_entry *conn) if (!inbuf) return -ENOMEM; - key = kcalloc(kw, sizeof(__le32), GFP_KERNEL); + key = kzalloc_objs(__le32, kw); if (!key) goto out_free; diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index 00cfd8d5b46eab..37511f234d76da 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include "net_driver.h" @@ -266,11 +267,12 @@ struct efx_ptp_rxfilter { * @evt_frag_idx: Current fragment number * @evt_code: Last event code * @start: Address at which MC indicates ready for synchronisation - * @host_time_pps: Host time at last PPS * @adjfreq_ppb_shift: Shift required to convert scaled parts-per-billion * frequency adjustment into a fixed point fractional nanosecond format. * @current_adjfreq: Current ppb adjustment. * @phc_clock: Pointer to registered phc device (if primary function) + * @phc_lock: Serializes PHC commands and synchronization, and protects + * @current_adjfreq * @phc_clock_info: Registration structure for phc device * @pps_work: pps work task for handling pps events * @pps_workwq: pps work queue @@ -326,10 +328,10 @@ struct efx_ptp_data { int evt_frag_idx; int evt_code; struct efx_buffer start; - struct pps_event_time host_time_pps; unsigned int adjfreq_ppb_shift; s64 current_adjfreq; struct ptp_clock *phc_clock; + struct mutex phc_lock; struct ptp_clock_info phc_clock_info; struct work_struct pps_work; struct workqueue_struct *pps_workwq; @@ -907,7 +909,8 @@ static void efx_ptp_read_timeset(MCDI_DECLARE_STRUCT_PTR(data), static int efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), size_t response_length, - const struct pps_event_time *last_time) + const struct pps_event_time *last_time, + struct pps_event_time *host_time_pps) { unsigned number_readings = MCDI_VAR_ARRAY_LEN(response_length, @@ -985,6 +988,10 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), "PTP bad synchronisation seconds\n"); return -EAGAIN; } + + if (!host_time_pps) + return 0; + delta.tv_sec = (last_sec - start_sec) & 1; delta.tv_nsec = last_time->ts_real.tv_nsec - @@ -1001,14 +1008,22 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), delta.tv_nsec += ktime_to_timespec64(mc_time).tv_nsec; /* Set PPS timestamp to match NIC top of second */ - ptp->host_time_pps = *last_time; - pps_sub_ts(&ptp->host_time_pps, delta); + *host_time_pps = *last_time; + pps_sub_ts(host_time_pps, delta); return 0; } -/* Synchronize times between the host and the MC */ -static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings) +/* Synchronize times between the host and the MC. + * + * The MC serializes PTP requests, so MC_CMD_PTP_OP_ADJUST cannot be applied + * while MC_CMD_PTP_OP_SYNCHRONIZE is collecting timesets. This holds across + * functions of a controller, which share the clock but adjust it only through + * the function that registered it, so a secondary function can capture here + * without serializing against the primary. + */ +static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings, + struct pps_event_time *host_time_pps) { struct efx_ptp_data *ptp = efx->ptp_data; MCDI_DECLARE_BUF(synch_buf, MC_CMD_PTP_OUT_SYNCHRONIZE_LENMAX); @@ -1026,11 +1041,14 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings) MCDI_SET_QWORD(synch_buf, PTP_IN_SYNCHRONIZE_START_ADDR, ptp->start.dma_addr); + mutex_lock(&ptp->phc_lock); + /* Clear flag that signals MC ready */ WRITE_ONCE(*start, 0); rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf, MC_CMD_PTP_IN_SYNCHRONIZE_LEN); - EFX_WARN_ON_ONCE_PARANOID(rc); + if (rc) + goto out; /* Wait for start from MCDI (or timeout) */ timeout = jiffies + msecs_to_jiffies(MAX_SYNCHRONISE_WAIT_MS); @@ -1054,18 +1072,20 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings) &response_length); if (rc == 0) { rc = efx_ptp_process_times(efx, synch_buf, response_length, - &last_time); + &last_time, host_time_pps); if (rc == 0) ++ptp->good_syncs; else ++ptp->no_time_syncs; } +out: /* Increment the bad syncs counter if the synchronize fails, whatever * the reason. */ if (rc != 0) ++ptp->bad_syncs; + mutex_unlock(&ptp->phc_lock); return rc; } @@ -1445,7 +1465,6 @@ static int efx_ptp_start(struct efx_nic *efx) goto fail; ptp->evt_frag_idx = 0; - ptp->current_adjfreq = 0; return 0; @@ -1485,14 +1504,15 @@ static void efx_ptp_pps_worker(struct work_struct *work) { struct efx_ptp_data *ptp = container_of(work, struct efx_ptp_data, pps_work); + struct pps_event_time host_time_pps = {}; struct efx_nic *efx = ptp->efx; struct ptp_clock_event ptp_evt; - if (efx_ptp_synchronize(efx, PTP_SYNC_ATTEMPTS)) + if (efx_ptp_synchronize(efx, PTP_SYNC_ATTEMPTS, &host_time_pps)) return; ptp_evt.type = PTP_CLOCK_PPSUSR; - ptp_evt.pps_times = ptp->host_time_pps; + ptp_evt.pps_times = host_time_pps; ptp_clock_event(ptp->phc_clock, &ptp_evt); } @@ -1569,6 +1589,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) if (!efx->ptp_data) return -ENOMEM; + mutex_init(&ptp->phc_lock); ptp->efx = efx; ptp->channel = channel; @@ -1640,6 +1661,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) efx_nic_free_buffer(efx, &ptp->start); fail1: + mutex_destroy(&ptp->phc_lock); kfree(efx->ptp_data); efx->ptp_data = NULL; @@ -1694,6 +1716,7 @@ void efx_ptp_remove(struct efx_nic *efx) destroy_workqueue(efx->ptp_data->workwq); efx_nic_free_buffer(efx, &efx->ptp_data->start); + mutex_destroy(&efx->ptp_data->phc_lock); kfree(efx->ptp_data); efx->ptp_data = NULL; } @@ -1825,7 +1848,8 @@ int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted, rc = efx_ptp_start(efx); if (rc == 0) { rc = efx_ptp_synchronize(efx, - PTP_SYNC_ATTEMPTS * 2); + PTP_SYNC_ATTEMPTS * 2, + NULL); if (rc != 0) efx_ptp_stop(efx); } @@ -2105,23 +2129,23 @@ static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) MCDI_SET_QWORD(inadj, PTP_IN_ADJUST_FREQ, adjustment_ns); MCDI_SET_DWORD(inadj, PTP_IN_ADJUST_SECONDS, 0); MCDI_SET_DWORD(inadj, PTP_IN_ADJUST_NANOSECONDS, 0); + mutex_lock(&ptp_data->phc_lock); rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inadj, sizeof(inadj), NULL, 0, NULL); - if (rc != 0) - return rc; - - ptp_data->current_adjfreq = adjustment_ns; - return 0; + if (!rc) + ptp_data->current_adjfreq = adjustment_ns; + mutex_unlock(&ptp_data->phc_lock); + return rc; } -static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) +static int _efx_phc_adjtime(struct efx_ptp_data *ptp_data, s64 delta) + __must_hold(&ptp_data->phc_lock) { - u32 nic_major, nic_minor; - struct efx_ptp_data *ptp_data = container_of(ptp, - struct efx_ptp_data, - phc_clock_info); - struct efx_nic *efx = ptp_data->efx; MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_ADJUST_LEN); + struct efx_nic *efx = ptp_data->efx; + u32 nic_major, nic_minor; + + lockdep_assert_held(&ptp_data->phc_lock); efx->ptp_data->ns_to_nic_time(delta, &nic_major, &nic_minor); @@ -2134,6 +2158,18 @@ static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) NULL, 0, NULL); } +static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) +{ + struct efx_ptp_data *ptp_data = container_of(ptp, struct efx_ptp_data, + phc_clock_info); + int rc; + + mutex_lock(&ptp_data->phc_lock); + rc = _efx_phc_adjtime(ptp_data, delta); + mutex_unlock(&ptp_data->phc_lock); + return rc; +} + static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) { struct efx_ptp_data *ptp_data = container_of(ptp, @@ -2165,23 +2201,21 @@ static int efx_phc_settime(struct ptp_clock_info *ptp, { /* Get the current NIC time, efx_phc_gettime. * Subtract from the desired time to get the offset - * call efx_phc_adjtime with the offset + * call _efx_phc_adjtime with the offset */ + struct efx_ptp_data *ptp_data = container_of(ptp, struct efx_ptp_data, + phc_clock_info); + struct timespec64 time_now, delta; int rc; - struct timespec64 time_now; - struct timespec64 delta; + mutex_lock(&ptp_data->phc_lock); rc = efx_phc_gettime(ptp, &time_now); - if (rc != 0) - return rc; - - delta = timespec64_sub(*e_ts, time_now); - - rc = efx_phc_adjtime(ptp, timespec64_to_ns(&delta)); - if (rc != 0) - return rc; - - return 0; + if (!rc) { + delta = timespec64_sub(*e_ts, time_now); + rc = _efx_phc_adjtime(ptp_data, timespec64_to_ns(&delta)); + } + mutex_unlock(&ptp_data->phc_lock); + return rc; } static int efx_phc_enable(struct ptp_clock_info *ptp, diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c index fd0a1a8ac2a1f3..020a7091c06b98 100644 --- a/drivers/net/ethernet/sfc/rx_common.c +++ b/drivers/net/ethernet/sfc/rx_common.c @@ -762,9 +762,8 @@ int efx_probe_filters(struct efx_nic *efx) efx_for_each_channel(channel, efx) { channel->rps_flow_id = - kcalloc(efx->type->max_rx_ip_filters, - sizeof(*channel->rps_flow_id), - GFP_KERNEL); + kzalloc_objs(*channel->rps_flow_id, + efx->type->max_rx_ip_filters); if (!channel->rps_flow_id) success = 0; else diff --git a/drivers/net/ethernet/sfc/siena/rx_common.c b/drivers/net/ethernet/sfc/siena/rx_common.c index 4ceb108fad48b8..6c778b791a90b1 100644 --- a/drivers/net/ethernet/sfc/siena/rx_common.c +++ b/drivers/net/ethernet/sfc/siena/rx_common.c @@ -751,9 +751,8 @@ int efx_siena_probe_filters(struct efx_nic *efx) efx_for_each_channel(channel, efx) { channel->rps_flow_id = - kcalloc(efx->type->max_rx_ip_filters, - sizeof(*channel->rps_flow_id), - GFP_KERNEL); + kzalloc_objs(*channel->rps_flow_id, + efx->type->max_rx_ip_filters); if (!channel->rps_flow_id) success = 0; else diff --git a/drivers/net/ethernet/sfc/siena/siena_sriov.c b/drivers/net/ethernet/sfc/siena/siena_sriov.c index d9789330f8dcdb..df715727567eee 100644 --- a/drivers/net/ethernet/sfc/siena/siena_sriov.c +++ b/drivers/net/ethernet/sfc/siena/siena_sriov.c @@ -830,8 +830,7 @@ static int efx_vfdi_set_status_page(struct siena_vf *vf) vf->peer_page_count = 0; if (page_count) { - vf->peer_page_addrs = kcalloc(page_count, sizeof(u64), - GFP_KERNEL); + vf->peer_page_addrs = kzalloc_objs(u64, page_count); if (vf->peer_page_addrs) { memcpy(vf->peer_page_addrs, req->u.set_status_page.peer_page_addr, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c index 5e0fc31762d9d8..97f94aee6c00cb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c @@ -73,7 +73,7 @@ anarion_config_dt(struct platform_device *pdev, return ERR_CAST(ctl_block); } - gmac = devm_kzalloc(&pdev->dev, sizeof(*gmac), GFP_KERNEL); + gmac = devm_kzalloc_obj(&pdev->dev, *gmac); if (!gmac) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c index b0c5d1ecabcec4..12d97c0c7726f0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c @@ -40,9 +40,7 @@ static int dwc_eth_dwmac_config_dt(struct platform_device *pdev, u32 burst_map = 0; if (!plat_dat->axi) { - plat_dat->axi = devm_kzalloc(&pdev->dev, - sizeof(struct stmmac_axi), - GFP_KERNEL); + plat_dat->axi = devm_kzalloc_obj(&pdev->dev, struct stmmac_axi); if (!plat_dat->axi) return -ENOMEM; @@ -191,7 +189,7 @@ static int tegra_eqos_probe(struct platform_device *pdev, struct tegra_eqos *eqos; int err; - eqos = devm_kzalloc(&pdev->dev, sizeof(*eqos), GFP_KERNEL); + eqos = devm_kzalloc_obj(&pdev->dev, *eqos); if (!eqos) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c index 0d654ec07f33f7..c229275b11b3a4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-eic7700.c @@ -183,7 +183,7 @@ static int eic7700_dwmac_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat), "dt configuration failed\n"); - dwc_priv = devm_kzalloc(&pdev->dev, sizeof(*dwc_priv), GFP_KERNEL); + dwc_priv = devm_kzalloc_obj(&pdev->dev, *dwc_priv); if (!dwc_priv) return -ENOMEM; @@ -295,10 +295,8 @@ static int eic7700_dwmac_probe(struct platform_device *pdev) dwc_priv->has_rxd_offset = true; plat_dat->num_clks = ARRAY_SIZE(eic7700_clk_names); - plat_dat->clks = devm_kcalloc(&pdev->dev, - plat_dat->num_clks, - sizeof(*plat_dat->clks), - GFP_KERNEL); + plat_dat->clks = devm_kzalloc_objs(&pdev->dev, *plat_dat->clks, + plat_dat->num_clks); if (!plat_dat->clks) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c index 01260dbbb69895..f4555f46e83f8d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c @@ -302,7 +302,7 @@ static int imx_dwmac_probe(struct platform_device *pdev) if (ret) return ret; - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ingenic.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ingenic.c index 8e4a30c11db06a..2d777959d6df6c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ingenic.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ingenic.c @@ -168,7 +168,7 @@ static int ingenic_mac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - mac = devm_kzalloc(&pdev->dev, sizeof(*mac), GFP_KERNEL); + mac = devm_kzalloc_obj(&pdev->dev, *mac); if (!mac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c index 4ea7b0a803d73c..6755dddd601d1d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c @@ -57,7 +57,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev) return PTR_ERR(plat_dat); } - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c index 4308dccbf25709..fcd8008545c2cf 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c @@ -705,8 +705,7 @@ static int intel_mgbe_common_data(struct pci_dev *pdev, plat->dma_cfg->aal = 0; plat->dma_cfg->dche = true; - plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi), - GFP_KERNEL); + plat->axi = devm_kzalloc_obj(&pdev->dev, *plat->axi); if (!plat->axi) return -ENOMEM; @@ -1305,7 +1304,7 @@ static int intel_eth_pci_probe(struct pci_dev *pdev, struct stmmac_resources res; int ret; - intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL); + intel_priv = devm_kzalloc_obj(&pdev->dev, *intel_priv); if (!intel_priv) return -ENOMEM; @@ -1313,15 +1312,12 @@ static int intel_eth_pci_probe(struct pci_dev *pdev, if (!plat) return -ENOMEM; - plat->mdio_bus_data = devm_kzalloc(&pdev->dev, - sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(&pdev->dev, *plat->mdio_bus_data); if (!plat->mdio_bus_data) return -ENOMEM; - plat->safety_feat_cfg = devm_kzalloc(&pdev->dev, - sizeof(*plat->safety_feat_cfg), - GFP_KERNEL); + plat->safety_feat_cfg = devm_kzalloc_obj(&pdev->dev, + *plat->safety_feat_cfg); if (!plat->safety_feat_cfg) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c index c05f85534f0cac..ad380c092274ca 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c @@ -388,7 +388,7 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); + gmac = devm_kzalloc_obj(dev, *gmac); if (!gmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c index eb14c197d6aef8..a42d80ead9d405 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c @@ -313,7 +313,7 @@ static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac) ld = priv->plat->bsp_priv; pdev = to_pci_dev(priv->device); - dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(priv->device, *dma); if (!dma) return -ENOMEM; @@ -507,13 +507,11 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id if (!plat) return -ENOMEM; - plat->mdio_bus_data = devm_kzalloc(&pdev->dev, - sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(&pdev->dev, *plat->mdio_bus_data); if (!plat->mdio_bus_data) return -ENOMEM; - ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL); + ld = devm_kzalloc_obj(&pdev->dev, *ld); if (!ld) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c index de9aba756aacb5..f7fef8436c875e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c @@ -181,7 +181,7 @@ static int ls1x_dwmac_probe(struct platform_device *pdev) return -EINVAL; } - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c index 30ae0dba7fffdb..f5835e2d3ea5c5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c @@ -466,7 +466,8 @@ static int mediatek_dwmac_clk_init(struct mediatek_dwmac_plat_data *plat) const struct mediatek_dwmac_variant *variant = plat->variant; int i, ret; - plat->clks = devm_kcalloc(plat->dev, variant->num_clks, sizeof(*plat->clks), GFP_KERNEL); + plat->clks = devm_kzalloc_objs(plat->dev, *plat->clks, + variant->num_clks); if (!plat->clks) return -ENOMEM; @@ -571,9 +572,8 @@ static int mediatek_dwmac_common_data(struct platform_device *pdev, plat->resume = mediatek_dwmac_init; plat->clks_config = mediatek_dwmac_clks_config; - plat->safety_feat_cfg = devm_kzalloc(&pdev->dev, - sizeof(*plat->safety_feat_cfg), - GFP_KERNEL); + plat->safety_feat_cfg = devm_kzalloc_obj(&pdev->dev, + *plat->safety_feat_cfg); if (!plat->safety_feat_cfg) return -ENOMEM; @@ -603,7 +603,7 @@ static int mediatek_dwmac_probe(struct platform_device *pdev) struct stmmac_resources stmmac_res; int ret; - priv_plat = devm_kzalloc(&pdev->dev, sizeof(*priv_plat), GFP_KERNEL); + priv_plat = devm_kzalloc_obj(&pdev->dev, *priv_plat); if (!priv_plat) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c index 07c504d07604c8..455594d8c03153 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c @@ -59,7 +59,7 @@ static int meson6_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c index e4d5c41294f4ed..2ad70f0dc4a379 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c @@ -158,7 +158,7 @@ static int meson8b_init_rgmii_tx_clk(struct meson8b_dwmac *dwmac) struct meson8b_dwmac_clk_configs *clk_configs; struct clk_parent_data parent_data = { }; - clk_configs = devm_kzalloc(dev, sizeof(*clk_configs), GFP_KERNEL); + clk_configs = devm_kzalloc_obj(dev, *clk_configs); if (!clk_configs) return -ENOMEM; @@ -394,7 +394,7 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c index 124fcd55a429b5..42f0b11a7b6060 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c @@ -214,12 +214,11 @@ motorcomm_default_plat_data(struct pci_dev *pdev) if (!plat) return NULL; - plat->mdio_bus_data = devm_kzalloc(dev, sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(dev, *plat->mdio_bus_data); if (!plat->mdio_bus_data) return NULL; - plat->axi = devm_kzalloc(dev, sizeof(*plat->axi), GFP_KERNEL); + plat->axi = devm_kzalloc_obj(dev, *plat->axi); if (!plat->axi) return NULL; @@ -297,7 +296,7 @@ static int motorcomm_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct stmmac_resources res = {}; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-nuvoton.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-nuvoton.c index b027cdf6afc27a..065e8f07cec28b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-nuvoton.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-nuvoton.c @@ -95,7 +95,7 @@ static int nvt_gmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return dev_err_probe(dev, PTR_ERR(plat_dat), "Failed to get platform data\n"); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return dev_err_probe(dev, -ENOMEM, "Failed to allocate private data\n"); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index d59be76a20916d..d24509a4b4d7fe 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -890,7 +890,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev) "dt configuration failed\n"); } - ethqos = devm_kzalloc(dev, sizeof(*ethqos), GFP_KERNEL); + ethqos = devm_kzalloc_obj(dev, *ethqos); if (!ethqos) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c index 9af32c26f9c146..41842f6bfa193c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c @@ -151,7 +151,7 @@ static int renesas_gbeth_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(plat_dat), "dt configuration failed\n"); - gbeth = devm_kzalloc(dev, sizeof(*gbeth), GFP_KERNEL); + gbeth = devm_kzalloc_obj(dev, *gbeth); if (!gbeth) return -ENOMEM; @@ -159,8 +159,8 @@ static int renesas_gbeth_probe(struct platform_device *pdev) gbeth->of_data = of_data; plat_dat->num_clks = of_data->num_clks; - plat_dat->clks = devm_kcalloc(dev, plat_dat->num_clks, - sizeof(*plat_dat->clks), GFP_KERNEL); + plat_dat->clks = devm_kzalloc_objs(dev, *plat_dat->clks, + plat_dat->num_clks); if (!plat_dat->clks) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index c4db919ec1640a..a37df5767d84e0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -1143,8 +1143,8 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat) if (phy_iface == PHY_INTERFACE_MODE_RMII) bsp_priv->num_clks += ARRAY_SIZE(rk_rmii_clocks); - bsp_priv->clks = devm_kcalloc(dev, bsp_priv->num_clks, - sizeof(*bsp_priv->clks), GFP_KERNEL); + bsp_priv->clks = devm_kzalloc_objs(dev, *bsp_priv->clks, + bsp_priv->num_clks); if (!bsp_priv->clks) return -ENOMEM; @@ -1288,7 +1288,7 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev, const char *strings = NULL; int value; - bsp_priv = devm_kzalloc(dev, sizeof(*bsp_priv), GFP_KERNEL); + bsp_priv = devm_kzalloc_obj(dev, *bsp_priv); if (!bsp_priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c index 024d8e10e91889..1f51df491370f8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c @@ -149,7 +149,7 @@ static int s32_dwmac_probe(struct platform_device *pdev) struct s32_priv_data *gmac; int ret; - gmac = devm_kzalloc(&pdev->dev, sizeof(*gmac), GFP_KERNEL); + gmac = devm_kzalloc_obj(&pdev->dev, *gmac); if (!gmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 6d4bc1fe8f7511..3a89c4da2af57d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -619,7 +619,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c index 62d8ac53867928..1c16aecb2d8353 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c @@ -162,7 +162,7 @@ static int spacemit_dwmac_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "failed to get platform resources\n"); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c index 4ee5b5fe1fa767..b21a58bc1b1506 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c @@ -105,7 +105,7 @@ static int starfive_dwmac_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat), "dt configuration failed\n"); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c index 6ebbf95d158f2b..33c31e37e5ab1d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c @@ -268,7 +268,7 @@ static int sti_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c index e1b260ed4790b9..4b8a177046cc30 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c @@ -538,7 +538,7 @@ static int stm32_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 47954537b29e42..2ece7ba9dd73bd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -1138,7 +1138,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) if (ret) return ret; - gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); + gmac = devm_kzalloc_obj(dev, *gmac); if (!gmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c index 74bd996d93c90a..79446601c99822 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c @@ -112,7 +112,7 @@ static int sun7i_gmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); + gmac = devm_kzalloc_obj(dev, *gmac); if (!gmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-tegra.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-tegra.c index 4ede4420c93b12..f786b6ce4480ae 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-tegra.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-tegra.c @@ -220,7 +220,7 @@ static int tegra_mgbe_probe(struct platform_device *pdev) int irq, err, i; u32 value; - mgbe = devm_kzalloc(&pdev->dev, sizeof(*mgbe), GFP_KERNEL); + mgbe = devm_kzalloc_obj(&pdev->dev, *mgbe); if (!mgbe) return -ENOMEM; @@ -253,8 +253,8 @@ static int tegra_mgbe_probe(struct platform_device *pdev) res.addr = mgbe->regs; res.irq = irq; - mgbe->clks = devm_kcalloc(&pdev->dev, ARRAY_SIZE(mgbe_clks), - sizeof(*mgbe->clks), GFP_KERNEL); + mgbe->clks = devm_kzalloc_objs(&pdev->dev, *mgbe->clks, + ARRAY_SIZE(mgbe_clks)); if (!mgbe->clks) return -ENOMEM; @@ -332,8 +332,8 @@ static int tegra_mgbe_probe(struct platform_device *pdev) plat->mdio_node = of_get_child_by_name(pdev->dev.of_node, "mdio"); if (!plat->mdio_bus_data) { - plat->mdio_bus_data = devm_kzalloc(&pdev->dev, sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(&pdev->dev, + *plat->mdio_bus_data); if (!plat->mdio_bus_data) { err = -ENOMEM; goto disable_clks; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c index 0d46a6c3f077e8..b9c9b666e53cb3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c @@ -245,7 +245,7 @@ static int thead_dwmac_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(apb_clk), "failed to get apb clock\n"); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c index 9497b13a575393..1826e732c55b5f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c @@ -217,7 +217,7 @@ static int visconti_eth_dwmac_probe(struct platform_device *pdev) if (IS_ERR(plat_dat)) return PTR_ERR(plat_dat); - dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + dwmac = devm_kzalloc_obj(&pdev->dev, *dwmac); if (!dwmac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c index 023b54b72478fc..7ece8d4157a869 100644 --- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c @@ -205,7 +205,7 @@ static int enh_desc_get_rx_status(struct stmmac_extra_stats *x, if (unlikely(!(rdes0 & RDES0_LAST_DESCRIPTOR))) { x->rx_length++; - return discard_frame; + return discard_frame | rx_not_ls; } if (unlikely(rdes0 & RDES0_ERROR_SUMMARY)) { diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index 265671170bf6e3..8d26b43ab2a6a8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -328,7 +328,7 @@ int stmmac_hwif_init(struct stmmac_priv *priv) /* Save ID for later use */ priv->synopsys_id = version.snpsver; - mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); + mac = devm_kzalloc_obj(priv->device, *mac); if (!mac) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index b2e55778880381..8ae95e91a36ab4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -620,7 +620,7 @@ struct stmmac_mmc_ops { struct stmmac_est_ops { int (*configure)(struct stmmac_priv *priv, struct stmmac_est *cfg, - unsigned int ptp_rate); + unsigned int ptp_rate, bool enable); void (*irq_status)(struct stmmac_priv *priv, struct net_device *dev, struct stmmac_extra_stats *x, u32 txqcnt); }; diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c index c4b613564f87ce..d19bf7ca4db383 100644 --- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c @@ -70,7 +70,7 @@ static int ndesc_get_rx_status(struct stmmac_extra_stats *x, if (unlikely(!(rdes0 & RDES0_LAST_DESCRIPTOR))) { x->rx_length++; - return discard_frame; + return discard_frame | rx_not_ls; } if (unlikely(rdes0 & RDES0_ERROR_SUMMARY)) { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 93292014c39376..b76acfe0d958be 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -239,6 +239,7 @@ struct stmmac_est { u32 gcl[EST_GCL]; u32 gcl_size; u32 max_sdu[MTL_MAX_TX_QUEUES]; + u32 pclass; }; struct stmmac_msi { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_est.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_est.c index afc516059b8975..59e9a54e864d6e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_est.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_est.c @@ -26,7 +26,7 @@ static int est_write(void __iomem *est_addr, u32 reg, u32 val, bool gcl) } static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg, - unsigned int ptp_rate) + unsigned int ptp_rate, bool enable) { void __iomem *est_addr = priv->estaddr; int i, ret = 0; @@ -62,7 +62,7 @@ static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg, ctrl |= ((NSEC_PER_SEC / ptp_rate) * EST_GMAC5_PTOV_MUL) << EST_GMAC5_PTOV_SHIFT; } - if (cfg->enable) + if (enable) ctrl |= EST_EEST | EST_SSWL | EST_DFBS; else ctrl &= ~EST_EEST; @@ -70,7 +70,7 @@ static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg, writel(ctrl, est_addr + EST_CONTROL); /* Configure EST interrupt */ - if (cfg->enable) + if (enable) ctrl = EST_IECGCE | EST_IEHS | EST_IEHF | EST_IEBE | EST_IECC; else ctrl = 0; @@ -80,6 +80,61 @@ static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg, return 0; } +int __stmmac_setup_est(struct stmmac_priv *priv) +{ + struct timespec64 current_time, time; + ktime_t current_time_ns, basetime; + u64 cycle_time; + int err; + + lockdep_assert_held(&priv->est_lock); + + priv->ptp_clock_ops.gettimex64(&priv->ptp_clock_ops, ¤t_time, + NULL); + current_time_ns = timespec64_to_ktime(current_time); + + time.tv_nsec = priv->est->btr_reserve[0]; + time.tv_sec = priv->est->btr_reserve[1]; + basetime = timespec64_to_ktime(time); + + cycle_time = (u64)priv->est->ctr[1] * NSEC_PER_SEC + priv->est->ctr[0]; + + time = stmmac_calc_tas_basetime(basetime, current_time_ns, cycle_time); + priv->est->btr[0] = (u32)time.tv_nsec; + priv->est->btr[1] = (u32)time.tv_sec; + + err = stmmac_est_configure(priv, priv, priv->est, + priv->plat->clk_ptp_rate, true); + if (err) { + netdev_err(priv->dev, "failed to re-configure EST\n"); + return err; + } + + return 0; +} + +int stmmac_setup_est(struct stmmac_priv *priv) +{ + int ret = 0; + + if (!priv->ptp_enabled) + return 0; + + mutex_lock(&priv->est_lock); + if (priv->est && priv->est->enable) { + ret = __stmmac_setup_est(priv); + if (ret) + goto unlock; + + ret = stmmac_fpe_map_preemption_class(priv, priv->dev, NULL, + priv->est->pclass); + } +unlock: + mutex_unlock(&priv->est_lock); + + return ret; +} + static void est_irq_status(struct stmmac_priv *priv, struct net_device *dev, struct stmmac_extra_stats *x, u32 txqcnt) { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_est.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_est.h index f70221c9c84afe..5e07b84957f35c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_est.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_est.h @@ -4,6 +4,9 @@ * stmmac EST(802.3 Qbv) handling */ +#ifndef __STMMAC_EST_H__ +#define __STMMAC_EST_H__ + #define EST_GMAC4_OFFSET 0x00000c50 #define EST_XGMAC_OFFSET 0x00001050 @@ -65,3 +68,8 @@ #define EST_GCL_DATA 0x00000034 extern const struct stmmac_est_ops dwmac510_est_ops; + +int __stmmac_setup_est(struct stmmac_priv *priv); +int stmmac_setup_est(struct stmmac_priv *priv); + +#endif /* __STMMAC_EST_H__ */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9ded31150fbe6a..25894771e9e9f8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -48,6 +48,7 @@ #include "stmmac_ptp.h" #include "stmmac_fpe.h" #include "stmmac.h" +#include "stmmac_est.h" #include "stmmac_pcs.h" #include "stmmac_xdp.h" #include @@ -2182,6 +2183,9 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv, else dma_free_rx_skbufs(priv, dma_conf, queue); + dev_kfree_skb_any(rx_q->state.skb); + rx_q->state.skb = NULL; + rx_q->state_saved = false; rx_q->buf_alloc_num = 0; rx_q->xsk_pool = NULL; @@ -3850,7 +3854,7 @@ static int stmmac_msi_init(struct stmmac_priv *priv, { int i; - priv->msi = devm_kmalloc(priv->device, sizeof(*priv->msi), GFP_KERNEL); + priv->msi = devm_kmalloc_obj(priv->device, *priv->msi); if (!priv->msi) return -ENOMEM; @@ -4201,6 +4205,10 @@ static int __stmmac_open(struct net_device *dev, if (ret) goto ptp_error; + ret = stmmac_setup_est(priv); + if (ret) + goto est_error; + stmmac_init_coalesce(priv); phylink_start(priv->phylink); @@ -4224,7 +4232,7 @@ static int __stmmac_open(struct net_device *dev, for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer); - +est_error: stmmac_release_ptp(priv); ptp_error: stmmac_stop_all_dma(priv); @@ -5099,22 +5107,35 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb, return vlan_features_check(skb, features); } -static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) +static int stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) { - struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb); - __be16 vlan_proto = veth->h_vlan_proto; - u16 vlanid; + struct vlan_ethhdr *veth; + + if (!pskb_may_pull(skb, ETH_HLEN)) + return -EINVAL; - if ((vlan_proto == htons(ETH_P_8021Q) && + veth = skb_vlan_eth_hdr(skb); + if ((veth->h_vlan_proto == htons(ETH_P_8021Q) && dev->features & NETIF_F_HW_VLAN_CTAG_RX) || - (vlan_proto == htons(ETH_P_8021AD) && + (veth->h_vlan_proto == htons(ETH_P_8021AD) && dev->features & NETIF_F_HW_VLAN_STAG_RX)) { + __be16 vlan_proto = veth->h_vlan_proto; + u8 meta_len = skb_metadata_len(skb); + u16 vlanid; + /* pop the vlan tag */ + if (!pskb_may_pull(skb, VLAN_ETH_HLEN)) + return -EINVAL; + + veth = skb_vlan_eth_hdr(skb); vlanid = ntohs(veth->h_vlan_TCI); - memmove(skb->data + VLAN_HLEN, veth, ETH_ALEN * 2); + memmove(skb->data - meta_len + VLAN_HLEN, + skb->data - meta_len, meta_len + ETH_ALEN * 2); skb_pull(skb, VLAN_HLEN); __vlan_hwaccel_put_tag(skb, vlan_proto, vlanid); } + + return 0; } static bool stmmac_rx_need_ic(struct stmmac_priv *priv, @@ -5516,7 +5537,8 @@ static struct sk_buff *stmmac_construct_skb_zc(struct stmmac_channel *ch, return NULL; skb_reserve(skb, xdp->data - xdp->data_hard_start); - memcpy(__skb_put(skb, datasize), xdp->data, datasize); + __skb_put(skb, datasize); + memcpy(skb->data - metasize, xdp->data_meta, datasize + metasize); if (metasize) skb_metadata_set(skb, metasize); @@ -5542,12 +5564,15 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue, } stmmac_get_rx_hwtstamp(priv, p, np, skb); - if (priv->hw->hw_vlan_en) + if (priv->hw->hw_vlan_en) { /* MAC level stripping. */ stmmac_rx_hw_vlan(priv, priv->hw, p, skb); - else - /* Driver level stripping. */ - stmmac_rx_vlan(priv->dev, skb); + } else if (stmmac_rx_vlan(priv->dev, skb)) { + dev_kfree_skb_any(skb); + priv->xstats.rx_dropped++; + return; + } + skb->protocol = eth_type_trans(skb, priv->dev); if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb)) @@ -5562,7 +5587,7 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue, napi_gro_receive(&ch->rxtx_napi, skb); u64_stats_update_begin(&rxq_stats->napi_syncp); - u64_stats_inc(&rxq_stats->napi.rx_pkt_n); + u64_stats_inc(&rxq_stats->napi.rx_packets); u64_stats_add(&rxq_stats->napi.rx_bytes, len); u64_stats_update_end(&rxq_stats->napi_syncp); } @@ -5629,12 +5654,12 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) unsigned int count = 0, error = 0, len = 0; int dirty = stmmac_rx_dirty(priv, queue); unsigned int next_entry = rx_q->cur_rx; + bool in_progress = rx_q->state_saved; u32 rx_errors = 0, rx_dropped = 0; unsigned int desc_size; struct bpf_prog *prog; bool failure = false; int xdp_status = 0; - int status = 0; if (netif_msg_rx_status(priv)) { void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0); @@ -5645,23 +5670,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) stmmac_display_ring(priv, rx_head, priv->dma_conf.dma_rx_size, true, rx_q->dma_rx_phy, desc_size); } + + if (rx_q->state_saved) { + error = rx_q->state.error; + len = rx_q->state.len; + rx_q->state_saved = false; + } + while (count < limit) { struct stmmac_rx_buffer *buf; struct stmmac_xdp_buff *ctx; unsigned int buf1_len = 0; struct dma_desc *np, *p; - int entry; + int entry, status; int res; - if (!count && rx_q->state_saved) { - error = rx_q->state.error; - len = rx_q->state.len; - } else { - rx_q->state_saved = false; + if (!in_progress) { error = 0; len = 0; } - read_again: if (count >= limit) break; @@ -5700,6 +5727,8 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) if (!buf->xdp) break; + in_progress = status & rx_not_ls; + if (priv->extend_desc) { /* Read the extended status after the own bit */ dma_rmb(); @@ -5707,18 +5736,21 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) &rx_q->dma_erx[entry], status); } - if (unlikely(status == discard_frame)) { - xsk_buff_free(buf->xdp); - buf->xdp = NULL; - dirty++; + + if (unlikely(!error && (status & discard_frame))) { error = 1; if (!priv->hwts_rx_en) rx_errors++; } - if (unlikely(error && (status & rx_not_ls))) - goto read_again; if (unlikely(error)) { + xsk_buff_free(buf->xdp); + buf->xdp = NULL; + dirty++; + + if (status & rx_not_ls) + goto read_again; + count++; continue; } @@ -5727,8 +5759,9 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) if (likely(status & rx_not_ls)) { xsk_buff_free(buf->xdp); buf->xdp = NULL; + rx_dropped++; + error = 1; dirty++; - count++; goto read_again; } @@ -5776,7 +5809,7 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) count++; } - if (status & rx_not_ls) { + if (in_progress) { rx_q->state_saved = true; rx_q->state.error = error; rx_q->state.len = len; @@ -5818,9 +5851,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue]; struct stmmac_channel *ch = &priv->channel[queue]; unsigned int count = 0, error = 0, len = 0; - int status = 0, coe = priv->hw->rx_csum; unsigned int next_entry = rx_q->cur_rx; + bool in_progress = rx_q->state_saved; enum dma_data_direction dma_dir; + int coe = priv->hw->rx_csum; unsigned int desc_size; struct sk_buff *skb = NULL; struct stmmac_xdp_buff ctx; @@ -5840,25 +5874,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) stmmac_display_ring(priv, rx_head, priv->dma_conf.dma_rx_size, true, rx_q->dma_rx_phy, desc_size); } + + if (rx_q->state_saved) { + skb = rx_q->state.skb; + error = rx_q->state.error; + len = rx_q->state.len; + rx_q->state.skb = NULL; + rx_q->state_saved = false; + } + while (count < limit) { unsigned int buf1_len = 0, buf2_len = 0; enum pkt_hash_types hash_type; struct stmmac_rx_buffer *buf; struct dma_desc *np, *p; - int entry; + int entry, status; u32 hash; - if (!count && rx_q->state_saved) { - skb = rx_q->state.skb; - error = rx_q->state.error; - len = rx_q->state.len; - } else { - rx_q->state_saved = false; + if (!in_progress) { skb = NULL; error = 0; len = 0; } - read_again: if (count >= limit) break; @@ -5887,6 +5924,8 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) prefetch(np); + in_progress = status & rx_not_ls; + if (priv->extend_desc) { /* Read the extended status after the own bit */ dma_rmb(); @@ -5894,21 +5933,26 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) &rx_q->dma_erx[entry], status); } - if (unlikely(status == discard_frame)) { - page_pool_put_page(rx_q->page_pool, buf->page, 0, true); - buf->page = NULL; + + if (unlikely(!error && (status & discard_frame))) { error = 1; if (!priv->hwts_rx_en) rx_errors++; } - if (unlikely(error && (status & rx_not_ls))) - goto read_again; + /* We do not support SG in XDP mode */ + if (unlikely(!error && (status & rx_not_ls) && + stmmac_xdp_is_enabled(priv))) { + rx_dropped++; + error = 1; + } + if (unlikely(error)) { + if (status & rx_not_ls) + goto read_again; + dev_kfree_skb(skb); - skb = NULL; - count++; - continue; + goto next; } /* Buffer is good. Go on. */ @@ -5918,13 +5962,19 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) buf2_len = stmmac_rx_buf2_len(priv, p, status, len); len += buf2_len; + /* Drop the packet if it is split over buf1 and buf2 on a + * single descriptor if the interface is running in XDP mode. + */ + if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) { + rx_dropped++; + goto next; + } + /* ACS is disabled; strip manually. */ if (likely(!(status & rx_not_ls))) len -= ETH_FCS_LEN; if (!skb) { - unsigned int pre_len, sync_len; - /* Each frame starts here: reset the FCS handling */ fcs_stripped = false; @@ -5942,55 +5992,32 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) xdp_prepare_buff(&ctx.xdp, page_address(buf->page), buf->page_offset, buf1_len, true); - pre_len = ctx.xdp.data_end - ctx.xdp.data_hard_start - - buf->page_offset; - ctx.priv = priv; ctx.desc = p; ctx.ndesc = np; skb = stmmac_xdp_run_prog(priv, &ctx.xdp); - /* Due xdp_adjust_tail: DMA sync for_device - * cover max len CPU touch - */ - sync_len = ctx.xdp.data_end - ctx.xdp.data_hard_start - - buf->page_offset; - sync_len = max(sync_len, pre_len); - /* For Not XDP_PASS verdict */ if (IS_ERR(skb)) { unsigned int xdp_res = -PTR_ERR(skb); if (xdp_res & STMMAC_XDP_CONSUMED) { - page_pool_put_page(rx_q->page_pool, - virt_to_head_page(ctx.xdp.data), - sync_len, true); + page_pool_recycle_direct(rx_q->page_pool, + virt_to_head_page(ctx.xdp.data)); buf->page = NULL; rx_dropped++; - - /* Clear skb as it was set as - * status by XDP program. - */ - skb = NULL; - - if (unlikely((status & rx_not_ls))) - goto read_again; - - count++; - continue; + goto next; } else if (xdp_res & (STMMAC_XDP_TX | STMMAC_XDP_REDIRECT)) { xdp_status |= xdp_res; buf->page = NULL; - skb = NULL; - count++; - continue; + goto next; } } } if (!skb) { - unsigned int head_pad_len; + unsigned int metasize; /* XDP program may expand or reduce tail */ buf1_len = ctx.xdp.data_end - ctx.xdp.data; @@ -6007,10 +6034,14 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) } /* XDP program may adjust header */ - head_pad_len = ctx.xdp.data - ctx.xdp.data_hard_start; - skb_reserve(skb, head_pad_len); + skb_reserve(skb, + ctx.xdp.data - ctx.xdp.data_hard_start); skb_put(skb, buf1_len); skb_mark_for_recycle(skb); + + metasize = ctx.xdp.data - ctx.xdp.data_meta; + if (metasize) + skb_metadata_set(skb, metasize); buf->page = NULL; } else if (buf1_len) { dma_sync_single_for_cpu(priv->device, buf->addr, @@ -6041,20 +6072,20 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) /* Remove FCS if needed */ if (!fcs_stripped && pskb_trim(skb, len)) { dev_kfree_skb_any(skb); - skb = NULL; rx_dropped++; - count++; - continue; + goto next; } stmmac_get_rx_hwtstamp(priv, p, np, skb); - if (priv->hw->hw_vlan_en) + if (priv->hw->hw_vlan_en) { /* MAC level stripping. */ stmmac_rx_hw_vlan(priv, priv->hw, p, skb); - else - /* Driver level stripping. */ - stmmac_rx_vlan(priv->dev, skb); + } else if (stmmac_rx_vlan(priv->dev, skb)) { + dev_kfree_skb_any(skb); + rx_dropped++; + goto next; + } skb->protocol = eth_type_trans(skb, priv->dev); @@ -6069,14 +6100,15 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) skb_record_rx_queue(skb, queue); napi_gro_receive(&ch->rx_napi, skb); - skb = NULL; - rx_packets++; rx_bytes += len; +next: + in_progress = false; + skb = NULL; count++; } - if (status & rx_not_ls || skb) { + if (in_progress || skb) { rx_q->state_saved = true; rx_q->state.skb = skb; rx_q->state.error = error; @@ -7934,7 +7966,7 @@ struct plat_stmmacenet_data *stmmac_plat_dat_alloc(struct device *dev) struct plat_stmmacenet_data *plat_dat; int i; - plat_dat = devm_kzalloc(dev, sizeof(*plat_dat), GFP_KERNEL); + plat_dat = devm_kzalloc_obj(dev, *plat_dat); if (!plat_dat) return NULL; @@ -8213,6 +8245,7 @@ static int __stmmac_dvr_probe(struct device *device, stmmac_napi_add(ndev); mutex_init(&priv->lock); + mutex_init(&priv->est_lock); rwlock_init(&priv->ptp_lock); stmmac_fpe_init(priv); @@ -8346,6 +8379,7 @@ void stmmac_dvr_remove(struct device *dev) destroy_workqueue(priv->wq); mutex_destroy(&priv->lock); + mutex_destroy(&priv->est_lock); bitmap_free(priv->af_xdp_zc_qps); pm_runtime_disable(dev); @@ -8421,6 +8455,9 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue) { struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue]; + dev_kfree_skb_any(rx_q->state.skb); + rx_q->state.skb = NULL; + rx_q->state_saved = false; rx_q->cur_rx = 0; rx_q->dirty_rx = 0; } @@ -8525,6 +8562,10 @@ int stmmac_resume(struct device *dev) ret = stmmac_init_timestamping(priv); if (ret) goto error_stop_dma; + + ret = stmmac_setup_est(priv); + if (ret) + goto error_stop_dma; } init_coalesce: diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c index d584fd2daa6f15..d804cb9a88139e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c @@ -85,7 +85,7 @@ static int snps_gmac5_default_data(struct pci_dev *pdev, plat->dma_cfg->pblx8 = true; /* Axi Configuration */ - plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi), GFP_KERNEL); + plat->axi = devm_kzalloc_obj(&pdev->dev, *plat->axi); if (!plat->axi) return -ENOMEM; @@ -128,15 +128,12 @@ static int stmmac_pci_probe(struct pci_dev *pdev, if (!plat) return -ENOMEM; - plat->mdio_bus_data = devm_kzalloc(&pdev->dev, - sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(&pdev->dev, *plat->mdio_bus_data); if (!plat->mdio_bus_data) return -ENOMEM; - plat->safety_feat_cfg = devm_kzalloc(&pdev->dev, - sizeof(*plat->safety_feat_cfg), - GFP_KERNEL); + plat->safety_feat_cfg = devm_kzalloc_obj(&pdev->dev, + *plat->safety_feat_cfg); if (!plat->safety_feat_cfg) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c index df37af5ab837af..dba3601607e94e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c @@ -222,7 +222,7 @@ int stmmac_integrated_pcs_init(struct stmmac_priv *priv, { struct stmmac_pcs *spcs; - spcs = devm_kzalloc(priv->device, sizeof(*spcs), GFP_KERNEL); + spcs = devm_kzalloc_obj(priv->device, *spcs); if (!spcs) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 3ea16d6182151f..b3e06aa58fe50f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -102,7 +102,7 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev) if (!np) return NULL; - axi = devm_kzalloc(&pdev->dev, sizeof(*axi), GFP_KERNEL); + axi = devm_kzalloc_obj(&pdev->dev, *axi); if (!axi) { of_node_put(np); return ERR_PTR(-ENOMEM); @@ -352,9 +352,8 @@ static int stmmac_mdio_setup(struct plat_stmmacenet_data *plat, dev_info(dev, "Deprecated MDIO bus assumption used\n"); if (plat->mdio_node || legacy_mdio) { - plat->mdio_bus_data = devm_kzalloc(dev, - sizeof(*plat->mdio_bus_data), - GFP_KERNEL); + plat->mdio_bus_data = devm_kzalloc_obj(dev, + *plat->mdio_bus_data); if (!plat->mdio_bus_data) return -ENOMEM; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index e54a3c8878265d..31a66e855d6b1a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -8,6 +8,7 @@ Author: Rayagond Kokatanur *******************************************************************************/ #include "stmmac.h" +#include "stmmac_est.h" #include "stmmac_ptp.h" #define PTP_SAFE_TIME_OFFSET_NS 500000 @@ -54,8 +55,7 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta) u32 sec, nsec; u32 quotient, reminder; int neg_adj = 0; - bool xmac, est_rst = false; - int ret; + bool xmac; xmac = dwmac_is_xmac(priv->plat->core_type); @@ -69,47 +69,21 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta) nsec = reminder; /* If EST is enabled, disabled it before adjust ptp time. */ - if (priv->est && priv->est->enable) { - est_rst = true; - mutex_lock(&priv->est_lock); - priv->est->enable = false; + mutex_lock(&priv->est_lock); + if (priv->est && priv->est->enable) stmmac_est_configure(priv, priv, priv->est, - priv->plat->clk_ptp_rate); - mutex_unlock(&priv->est_lock); - } + priv->plat->clk_ptp_rate, false); + mutex_unlock(&priv->est_lock); write_lock_irqsave(&priv->ptp_lock, flags); stmmac_adjust_systime(priv, priv->ptpaddr, sec, nsec, neg_adj, xmac); write_unlock_irqrestore(&priv->ptp_lock, flags); /* Calculate new basetime and re-configured EST after PTP time adjust. */ - if (est_rst) { - struct timespec64 current_time, time; - ktime_t current_time_ns, basetime; - u64 cycle_time; - - mutex_lock(&priv->est_lock); - priv->ptp_clock_ops.gettimex64(&priv->ptp_clock_ops, - ¤t_time, NULL); - current_time_ns = timespec64_to_ktime(current_time); - time.tv_nsec = priv->est->btr_reserve[0]; - time.tv_sec = priv->est->btr_reserve[1]; - basetime = timespec64_to_ktime(time); - cycle_time = (u64)priv->est->ctr[1] * NSEC_PER_SEC + - priv->est->ctr[0]; - time = stmmac_calc_tas_basetime(basetime, - current_time_ns, - cycle_time); - - priv->est->btr[0] = (u32)time.tv_nsec; - priv->est->btr[1] = (u32)time.tv_sec; - priv->est->enable = true; - ret = stmmac_est_configure(priv, priv, priv->est, - priv->plat->clk_ptp_rate); - mutex_unlock(&priv->est_lock); - if (ret) - netdev_err(priv->dev, "failed to configure EST\n"); - } + mutex_lock(&priv->est_lock); + if (priv->est && priv->est->enable) + __stmmac_setup_est(priv); + mutex_unlock(&priv->est_lock); return 0; } @@ -303,6 +277,7 @@ const struct ptp_clock_info stmmac_ptp_clock_ops = { .n_per_out = 0, /* will be overwritten in stmmac_ptp_register */ .n_pins = 0, .pps = 0, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = stmmac_adjust_freq, .adjtime = stmmac_adjust_time, .gettimex64 = stmmac_get_timex, @@ -320,6 +295,7 @@ const struct ptp_clock_info dwmac1000_ptp_clock_ops = { .n_per_out = 0, .n_pins = 0, .pps = 0, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = stmmac_adjust_freq, .adjtime = stmmac_adjust_time, .gettimex64 = stmmac_get_timex, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index e137fb9012d498..c7696b19d072b0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -243,10 +243,8 @@ static int tc_rfs_init(struct stmmac_priv *priv) for (i = 0; i < STMMAC_RFS_T_MAX; i++) priv->rfs_entries_total += priv->rfs_entries_max[i]; - priv->rfs_entries = devm_kcalloc(priv->device, - priv->rfs_entries_total, - sizeof(*priv->rfs_entries), - GFP_KERNEL); + priv->rfs_entries = devm_kzalloc_objs(priv->device, *priv->rfs_entries, + priv->rfs_entries_total); if (!priv->rfs_entries) return -ENOMEM; @@ -264,10 +262,9 @@ static int tc_init(struct stmmac_priv *priv) priv->flow_entries_max = dma_cap->l3l4fnum; if (priv->flow_entries_max) { - priv->flow_entries = devm_kcalloc(priv->device, - priv->flow_entries_max, - sizeof(*priv->flow_entries), - GFP_KERNEL); + priv->flow_entries = devm_kzalloc_objs(priv->device, + *priv->flow_entries, + priv->flow_entries_max); if (!priv->flow_entries) return -ENOMEM; @@ -316,8 +313,8 @@ static int tc_init(struct stmmac_priv *priv) /* Reserve one last filter which lets all pass */ priv->tc_entries_max = count; - priv->tc_entries = devm_kcalloc(priv->device, - count, sizeof(*priv->tc_entries), GFP_KERNEL); + priv->tc_entries = devm_kzalloc_objs(priv->device, *priv->tc_entries, + count); if (!priv->tc_entries) return -ENOMEM; @@ -966,11 +963,12 @@ static void tc_taprio_map_maxsdu_txq(struct stmmac_priv *priv, static int tc_taprio_configure(struct stmmac_priv *priv, struct tc_taprio_qopt_offload *qopt) { - u32 size, wid = priv->dma_cap.estwid, dep = priv->dma_cap.estdep; + u32 wid = priv->dma_cap.estwid, dep = priv->dma_cap.estdep; struct netlink_ext_ack *extack = qopt->mqprio.extack; struct timespec64 time, current_time, qopt_time; ktime_t current_time_ns; int err, i, ret = 0; + u32 *gcl = NULL; u64 ctr; if (qopt->base_time < 0) @@ -1013,44 +1011,46 @@ static int tc_taprio_configure(struct stmmac_priv *priv, return -EOPNOTSUPP; } + mutex_lock(&priv->est_lock); + if (qopt->cmd == TAPRIO_CMD_DESTROY) goto disable; - if (qopt->num_entries > dep) - return -EINVAL; - if (!qopt->cycle_time) - return -ERANGE; - if (qopt->cycle_time_extension >= BIT(wid + 7)) - return -ERANGE; - - if (!priv->est) { - priv->est = devm_kzalloc(priv->device, sizeof(*priv->est), - GFP_KERNEL); - if (!priv->est) - return -ENOMEM; + if (qopt->num_entries > dep) { + ret = -EINVAL; + goto error_unlock; + } - mutex_init(&priv->est_lock); - } else { - mutex_lock(&priv->est_lock); - memset(priv->est, 0, sizeof(*priv->est)); - mutex_unlock(&priv->est_lock); + if (!qopt->cycle_time || + qopt->cycle_time > (u64)U32_MAX * NSEC_PER_SEC) { + ret = -ERANGE; + goto error_unlock; } - size = qopt->num_entries; + if (qopt->cycle_time_extension >= BIT(wid + 7)) { + ret = -ERANGE; + goto error_unlock; + } - mutex_lock(&priv->est_lock); - priv->est->gcl_size = size; - priv->est->enable = qopt->cmd == TAPRIO_CMD_REPLACE; - mutex_unlock(&priv->est_lock); + gcl = kzalloc_objs(*gcl, qopt->num_entries); + if (!gcl) { + ret = -ENOMEM; + goto error_unlock; + } - for (i = 0; i < size; i++) { + for (i = 0; i < qopt->num_entries; i++) { s64 delta_ns = qopt->entries[i].interval; u32 gates = qopt->entries[i].gate_mask; - if (delta_ns > GENMASK(wid - 1, 0)) - return -ERANGE; - if (gates > GENMASK(31 - wid, 0)) - return -ERANGE; + if (delta_ns > GENMASK(wid - 1, 0)) { + ret = -ERANGE; + goto error_unlock; + } + + if (gates > GENMASK(31 - wid, 0)) { + ret = -ERANGE; + goto error_unlock; + } switch (qopt->entries[i].command) { case TC_TAPRIO_CMD_SET_GATES: @@ -1062,13 +1062,25 @@ static int tc_taprio_configure(struct stmmac_priv *priv, gates &= ~BIT(0); break; default: - return -EOPNOTSUPP; + ret = -EOPNOTSUPP; + goto error_unlock; } - priv->est->gcl[i] = delta_ns | (gates << wid); + gcl[i] = delta_ns | (gates << wid); } - mutex_lock(&priv->est_lock); + if (!priv->est) { + priv->est = devm_kzalloc_obj(priv->device, *priv->est); + if (!priv->est) { + ret = -ENOMEM; + goto error_unlock; + } + } else { + memset(priv->est, 0, sizeof(*priv->est)); + } + memcpy(priv->est->gcl, gcl, sizeof(*gcl) * qopt->num_entries); + priv->est->gcl_size = qopt->num_entries; + /* Adjust for real system time */ priv->ptp_clock_ops.gettimex64(&priv->ptp_clock_ops, ¤t_time, NULL); @@ -1092,8 +1104,7 @@ static int tc_taprio_configure(struct stmmac_priv *priv, tc_taprio_map_maxsdu_txq(priv, qopt); ret = stmmac_est_configure(priv, priv, priv->est, - priv->plat->clk_ptp_rate); - mutex_unlock(&priv->est_lock); + priv->plat->clk_ptp_rate, true); if (ret) { netdev_err(priv->dev, "failed to configure EST\n"); goto disable; @@ -1104,24 +1115,31 @@ static int tc_taprio_configure(struct stmmac_priv *priv, if (ret) goto disable; + priv->est->pclass = qopt->mqprio.preemptible_tcs; + priv->est->enable = true; + + mutex_unlock(&priv->est_lock); + kfree(gcl); + return 0; disable: if (priv->est) { - mutex_lock(&priv->est_lock); priv->est->enable = false; stmmac_est_configure(priv, priv, priv->est, - priv->plat->clk_ptp_rate); + priv->plat->clk_ptp_rate, false); /* Reset taprio status */ for (i = 0; i < priv->plat->tx_queues_to_use; i++) { priv->xstats.max_sdu_txq_drop[i] = 0; priv->xstats.mtl_est_txq_hlbf[i] = 0; priv->xstats.mtl_est_txq_hlbs[i] = 0; } - mutex_unlock(&priv->est_lock); } err = stmmac_fpe_map_preemption_class(priv, priv->dev, extack, 0); +error_unlock: + mutex_unlock(&priv->est_lock); + kfree(gcl); return qopt->cmd == TAPRIO_CMD_DESTROY ? err : ret; } diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c index 5e0e4c9ecbb071..9ccaf928ed6603 100644 --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c @@ -333,7 +333,7 @@ static int spl2sw_probe(struct platform_device *pdev) return -ENODEV; /* Allocate memory for 'spl2sw_common' area. */ - comm = devm_kzalloc(&pdev->dev, sizeof(*comm), GFP_KERNEL); + comm = devm_kzalloc_obj(&pdev->dev, *comm); if (!comm) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 2551554add17a4..0ad61458224456 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -128,6 +128,7 @@ #define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 BIT(21) #define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 BIT(22) #define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO BIT(23) +#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN BIT(24) /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */ #define AM65_CPSW_TS_EVENT_MSG_TYPE_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3)) @@ -1857,7 +1858,8 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev, AM65_CPSW_PN_TS_CTL_LTYPE2_TS_132 | AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 | AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 | - AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO; + AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO | + AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN; ts_ctrl = AM65_CPSW_TS_EVENT_MSG_TYPE_BITS << AM65_CPSW_PN_TS_CTL_MSG_TYPE_EN_SHIFT; @@ -3540,7 +3542,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) "TX SW_DATA size exceeds AM65_CPSW_NAV_SW_DATA_SIZE"); BUILD_BUG_ON_MSG(sizeof(struct am65_cpsw_swdata) > AM65_CPSW_NAV_SW_DATA_SIZE, "SW_DATA size exceeds AM65_CPSW_NAV_SW_DATA_SIZE"); - common = devm_kzalloc(dev, sizeof(struct am65_cpsw_common), GFP_KERNEL); + common = devm_kzalloc_obj(dev, struct am65_cpsw_common); if (!common) return -ENOMEM; common->dev = dev; @@ -3576,9 +3578,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev) common->pf_p0_rx_ptype_rrobin = true; common->default_vlan = 1; - common->ports = devm_kcalloc(dev, common->port_num, - sizeof(*common->ports), - GFP_KERNEL); + common->ports = devm_kzalloc_objs(dev, *common->ports, common->port_num); if (!common->ports) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/am65-cpsw-qos.c b/drivers/net/ethernet/ti/am65-cpsw-qos.c index 66e8b224827b66..d2523d61a394ed 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-qos.c +++ b/drivers/net/ethernet/ti/am65-cpsw-qos.c @@ -884,9 +884,8 @@ static int am65_cpsw_taprio_replace(struct net_device *ndev, return -EOPNOTSUPP; } - est_new = devm_kzalloc(&ndev->dev, - struct_size(est_new, taprio.entries, taprio->num_entries), - GFP_KERNEL); + est_new = devm_kzalloc_flex(&ndev->dev, *est_new, taprio.entries, + taprio->num_entries); if (!est_new) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c index df5659ead72f64..3ce3b2245efba4 100644 --- a/drivers/net/ethernet/ti/am65-cpts.c +++ b/drivers/net/ethernet/ti/am65-cpts.c @@ -176,6 +176,9 @@ struct am65_cpts { struct mutex ptp_clk_lock; /* PHC access sync */ u64 timestamp; u32 genf_enable; + bool genf_neg_adj; + u32 genf_ppm_hi; + u32 genf_ppm_low; u32 hw_ts_enable; u32 estf_enable; struct sk_buff_head txq; @@ -436,9 +439,11 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) { struct am65_cpts *cpts = container_of(ptp, struct am65_cpts, ptp_info); u32 estf_ctrl_val = 0, estf_ppm_hi = 0, estf_ppm_low = 0; + u32 genf_ctrl_val[AM65_CPTS_GENF_MAX_NUM]; + u32 genf_ppm_hi, genf_ppm_low; s32 ppb = scaled_ppm_to_ppb(scaled_ppm); int pps_index = cpts->pps_genf_idx; - u64 adj_period, pps_adj_period; + u64 adj_period, genf_adj_period; u32 ctrl_val, ppm_hi, ppm_low; unsigned long flags; int neg_adj = 0, i; @@ -470,20 +475,33 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) ppm_hi = upper_32_bits(adj_period) & 0x3FF; ppm_low = lower_32_bits(adj_period); + /* GenF PPM will do correction using cpts refclk tick which is + * (cpts->ts_add_val + 1) ns, so GenF length PPM adj period + * need to be corrected. + */ + genf_adj_period = adj_period * (cpts->ts_add_val + 1); + genf_ppm_hi = upper_32_bits(genf_adj_period) & 0x3FF; + genf_ppm_low = lower_32_bits(genf_adj_period); + cpts->genf_neg_adj = neg_adj; + cpts->genf_ppm_hi = genf_ppm_hi; + cpts->genf_ppm_low = genf_ppm_low; + + for (i = 0; i < AM65_CPTS_GENF_MAX_NUM; i++) { + if (cpts->genf_enable & BIT(i)) { + genf_ctrl_val[i] = am65_cpts_read32(cpts, + genf[i].control); + if (neg_adj) + genf_ctrl_val[i] &= ~BIT(1); + else + genf_ctrl_val[i] |= BIT(1); + } + } + if (cpts->pps_enabled) { - estf_ctrl_val = am65_cpts_read32(cpts, genf[pps_index].control); - if (neg_adj) - estf_ctrl_val &= ~BIT(1); - else - estf_ctrl_val |= BIT(1); - - /* GenF PPM will do correction using cpts refclk tick which is - * (cpts->ts_add_val + 1) ns, so GenF length PPM adj period - * need to be corrected. - */ - pps_adj_period = adj_period * (cpts->ts_add_val + 1); - estf_ppm_hi = upper_32_bits(pps_adj_period) & 0x3FF; - estf_ppm_low = lower_32_bits(pps_adj_period); + /* am65_cpts_perout_enable_hw() sets pps_index in genf_enable */ + estf_ctrl_val = genf_ctrl_val[pps_index]; + estf_ppm_hi = genf_ppm_hi; + estf_ppm_low = genf_ppm_low; } spin_lock_irqsave(&cpts->lock, flags); @@ -500,10 +518,13 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) am65_cpts_write32(cpts, ppm_hi, ts_ppm_hi); am65_cpts_write32(cpts, ppm_low, ts_ppm_low); - if (cpts->pps_enabled) { - am65_cpts_write32(cpts, estf_ctrl_val, genf[pps_index].control); - am65_cpts_write32(cpts, estf_ppm_hi, genf[pps_index].ppm_hi); - am65_cpts_write32(cpts, estf_ppm_low, genf[pps_index].ppm_low); + for (i = 0; i < AM65_CPTS_GENF_MAX_NUM; i++) { + if (cpts->genf_enable & BIT(i)) { + am65_cpts_write32(cpts, genf_ctrl_val[i], + genf[i].control); + am65_cpts_write32(cpts, genf_ppm_hi, genf[i].ppm_hi); + am65_cpts_write32(cpts, genf_ppm_low, genf[i].ppm_low); + } } for (i = 0; i < AM65_CPTS_ESTF_MAX_NUM; i++) { @@ -513,7 +534,6 @@ static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) am65_cpts_write32(cpts, estf_ppm_low, estf[i].ppm_low); } } - /* All GenF/EstF can be updated here the same way */ spin_unlock_irqrestore(&cpts->lock, flags); mutex_unlock(&cpts->ptp_clk_lock); @@ -679,9 +699,12 @@ static void am65_cpts_perout_enable_hw(struct am65_cpts *cpts, val = lower_32_bits(cycles); am65_cpts_write32(cpts, val, genf[req->index].length); - am65_cpts_write32(cpts, 0, genf[req->index].control); - am65_cpts_write32(cpts, 0, genf[req->index].ppm_hi); - am65_cpts_write32(cpts, 0, genf[req->index].ppm_low); + am65_cpts_write32(cpts, cpts->genf_neg_adj ? 0 : BIT(1), + genf[req->index].control); + am65_cpts_write32(cpts, cpts->genf_ppm_hi, + genf[req->index].ppm_hi); + am65_cpts_write32(cpts, cpts->genf_ppm_low, + genf[req->index].ppm_low); cpts->genf_enable |= BIT(req->index); } else { @@ -788,6 +811,28 @@ static struct ptp_clock_info am65_ptp_info = { .do_aux_work = am65_cpts_ts_work, }; +/* The CPTS decodes the message type of an event using the PTPv2 header + * layout. For PTPv1 that nibble is part of versionPTP and always reads 0, + * while am65_skb_get_mtype_seqid() takes the message type from the PTPv1 + * control field. For PTPv1 take the message type from the skb, but keep + * the event type, port number and sequence id of the event so that an + * event only matches a packet of the same direction on the same port. + */ +static u32 am65_cpts_event_mtype_seqid(struct am65_cpts_event *event, + u32 skb_mtype_seqid, + unsigned int ptp_class) +{ + u32 mtype_seqid = event->event1; + + if (ptp_class & PTP_CLASS_V1) { + mtype_seqid &= ~AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK; + mtype_seqid |= skb_mtype_seqid & + AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK; + } + + return mtype_seqid; +} + static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts, struct am65_cpts_event *event) { @@ -797,7 +842,6 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts, bool found = false; u32 mtype_seqid; - mtype_seqid = event->event1; __skb_queue_head_init(&txq_list); spin_lock_irqsave(&cpts->txq.lock, flags); @@ -810,11 +854,9 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts, struct am65_cpts_skb_cb_data *skb_cb = (struct am65_cpts_skb_cb_data *)skb->cb; - if ((ptp_classify_raw(skb) & PTP_CLASS_V1) && - ((mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK) == - (skb_cb->skb_mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK))) - mtype_seqid = skb_cb->skb_mtype_seqid; - + mtype_seqid = am65_cpts_event_mtype_seqid(event, + skb_cb->skb_mtype_seqid, + ptp_classify_raw(skb)); if (mtype_seqid == skb_cb->skb_mtype_seqid) { u64 ns = event->timestamp; @@ -1154,7 +1196,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs, struct am65_cpts *cpts; int ret, i; - cpts = devm_kzalloc(dev, sizeof(*cpts), GFP_KERNEL); + cpts = devm_kzalloc_obj(dev, *cpts); if (!cpts) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c index 4edb7963f856fa..525aae87fd72cf 100644 --- a/drivers/net/ethernet/ti/cpsw-phy-sel.c +++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c @@ -212,7 +212,7 @@ static int cpsw_phy_sel_probe(struct platform_device *pdev) if (!of_id) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { dev_err(&pdev->dev, "unable to alloc memory for cpsw phy sel\n"); return -ENOMEM; diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 8d36124520ad30..14350ec5b7d0c7 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -1301,10 +1301,8 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, } data->active_slave = prop; - data->slave_data = devm_kcalloc(&pdev->dev, - data->slaves, - sizeof(struct cpsw_slave_data), - GFP_KERNEL); + data->slave_data = devm_kzalloc_objs(&pdev->dev, struct cpsw_slave_data, + data->slaves); if (!data->slave_data) return -ENOMEM; @@ -1570,7 +1568,7 @@ static int cpsw_probe(struct platform_device *pdev) int ret = 0, ch; int irq; - cpsw = devm_kzalloc(dev, sizeof(struct cpsw_common), GFP_KERNEL); + cpsw = devm_kzalloc_obj(dev, struct cpsw_common); if (!cpsw) return -ENOMEM; @@ -1642,9 +1640,7 @@ static int cpsw_probe(struct platform_device *pdev) cpsw->quirk_irq = true; data = &cpsw->data; - cpsw->slaves = devm_kcalloc(dev, - data->slaves, sizeof(struct cpsw_slave), - GFP_KERNEL); + cpsw->slaves = devm_kzalloc_objs(dev, struct cpsw_slave, data->slaves); if (!cpsw->slaves) { ret = -ENOMEM; goto clean_dt_ret; diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c index e202bba4948071..9304405c9581a8 100644 --- a/drivers/net/ethernet/ti/cpsw_ale.c +++ b/drivers/net/ethernet/ti/cpsw_ale.c @@ -1537,7 +1537,7 @@ struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params) params->reg_fields = ale_dev_id->reg_fields; params->num_fields = ale_dev_id->num_fields; - ale = devm_kzalloc(params->dev, sizeof(*ale), GFP_KERNEL); + ale = devm_kzalloc_obj(params->dev, *ale); if (!ale) return ERR_PTR(-ENOMEM); ale->regmap = devm_regmap_init_mmio(params->dev, params->ale_regs, diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index 07832cad5e3c21..9ea7b6ffc992bf 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -1266,9 +1266,8 @@ static int cpsw_probe_dt(struct cpsw_common *cpsw) data->bd_ram_size = CPSW_BD_RAM_SIZE; data->mac_control = 0; - data->slave_data = devm_kcalloc(dev, CPSW_SLAVE_PORTS_NUM, - sizeof(struct cpsw_slave_data), - GFP_KERNEL); + data->slave_data = devm_kzalloc_objs(dev, struct cpsw_slave_data, + CPSW_SLAVE_PORTS_NUM); if (!data->slave_data) { of_node_put(tmp_node); return -ENOMEM; @@ -1896,7 +1895,7 @@ static int cpsw_probe(struct platform_device *pdev) struct clk *clk; int irq; - cpsw = devm_kzalloc(dev, sizeof(struct cpsw_common), GFP_KERNEL); + cpsw = devm_kzalloc_obj(dev, struct cpsw_common); if (!cpsw) return -ENOMEM; @@ -1904,10 +1903,8 @@ static int cpsw_probe(struct platform_device *pdev) cpsw->dev = dev; - cpsw->slaves = devm_kcalloc(dev, - CPSW_SLAVE_PORTS_NUM, - sizeof(struct cpsw_slave), - GFP_KERNEL); + cpsw->slaves = devm_kzalloc_objs(dev, struct cpsw_slave, + CPSW_SLAVE_PORTS_NUM); if (!cpsw->slaves) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/cpsw_sl.c b/drivers/net/ethernet/ti/cpsw_sl.c index 761719a348fa5f..f06ff76e3eb2cd 100644 --- a/drivers/net/ethernet/ti/cpsw_sl.c +++ b/drivers/net/ethernet/ti/cpsw_sl.c @@ -236,7 +236,7 @@ struct cpsw_sl *cpsw_sl_get(const char *device_id, struct device *dev, const struct cpsw_sl_dev_id *sl_dev_id; struct cpsw_sl *sl; - sl = devm_kzalloc(dev, sizeof(struct cpsw_sl), GFP_KERNEL); + sl = devm_kzalloc_obj(dev, struct cpsw_sl); if (!sl) return ERR_PTR(-ENOMEM); sl->dev = dev; diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 2ba4c8795d605e..bf4d6654daa1b5 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -669,11 +669,9 @@ static int cpts_of_mux_clk_setup(struct cpts *cpts, struct device_node *node) goto mux_fail; } - parent_names = devm_kcalloc(cpts->dev, num_parents, - sizeof(*parent_names), GFP_KERNEL); + parent_names = devm_kzalloc_objs(cpts->dev, *parent_names, num_parents); - mux_table = devm_kcalloc(cpts->dev, num_parents, sizeof(*mux_table), - GFP_KERNEL); + mux_table = devm_kzalloc_objs(cpts->dev, *mux_table, num_parents); if (!mux_table || !parent_names) { ret = -ENOMEM; goto mux_fail; @@ -749,7 +747,7 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs, struct cpts *cpts; int ret; - cpts = devm_kzalloc(dev, sizeof(*cpts), GFP_KERNEL); + cpts = devm_kzalloc_obj(dev, *cpts); if (!cpts) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index 41e89a19be5378..a8aa1291c28130 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -215,7 +215,7 @@ static int cpdma_desc_pool_create(struct cpdma_ctlr *ctlr) struct cpdma_desc_pool *pool; int ret = -ENOMEM; - pool = devm_kzalloc(ctlr->dev, sizeof(*pool), GFP_KERNEL); + pool = devm_kzalloc_obj(ctlr->dev, *pool); if (!pool) goto gen_pool_create_fail; ctlr->pool = pool; @@ -511,7 +511,7 @@ struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params) { struct cpdma_ctlr *ctlr; - ctlr = devm_kzalloc(params->dev, sizeof(*ctlr), GFP_KERNEL); + ctlr = devm_kzalloc_obj(params->dev, *ctlr); if (!ctlr) return NULL; @@ -897,7 +897,7 @@ struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num, if (__chan_linear(chan_num) >= ctlr->num_chan) return ERR_PTR(-EINVAL); - chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(ctlr->dev, *chan); if (!chan) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index 3802122d0f1b2a..e14a08091eb3fd 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -1725,7 +1725,7 @@ davinci_emac_of_get_pdata(struct platform_device *pdev, struct emac_priv *priv) if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) return dev_get_platdata(&pdev->dev); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c index 5bec72f2f51dc5..c413887657e92f 100644 --- a/drivers/net/ethernet/ti/davinci_mdio.c +++ b/drivers/net/ethernet/ti/davinci_mdio.c @@ -544,7 +544,7 @@ static int davinci_mdio_probe(struct platform_device *pdev) int autosuspend_delay_ms = -1; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/icssg/icss_iep.c b/drivers/net/ethernet/ti/icssg/icss_iep.c index ec085897edf090..8b05db25993345 100644 --- a/drivers/net/ethernet/ti/icssg/icss_iep.c +++ b/drivers/net/ethernet/ti/icssg/icss_iep.c @@ -844,7 +844,7 @@ static int icss_iep_probe(struct platform_device *pdev) struct clk *iep_clk; int ret, irq; - iep = devm_kzalloc(dev, sizeof(*iep), GFP_KERNEL); + iep = devm_kzalloc_obj(dev, *iep); if (!iep) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c index 591be5c8056b43..c9659a3d40dc11 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c @@ -2195,7 +2195,7 @@ static int prueth_probe(struct platform_device *pdev) BUILD_BUG_ON_MSG((sizeof(struct prueth_swdata) > PRUETH_NAV_SW_DATA_SIZE), "insufficient SW_DATA size"); - prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL); + prueth = devm_kzalloc_obj(dev, *prueth); if (!prueth) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c index b8115ca47082f9..7aab221fead0d7 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c @@ -900,7 +900,7 @@ static int prueth_probe(struct platform_device *pdev) np = dev->of_node; - prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL); + prueth = devm_kzalloc_obj(dev, *prueth); if (!prueth) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/icssm/icssm_prueth.c b/drivers/net/ethernet/ti/icssm/icssm_prueth.c index b42c98e861e081..1aadef061e9236 100644 --- a/drivers/net/ethernet/ti/icssm/icssm_prueth.c +++ b/drivers/net/ethernet/ti/icssm/icssm_prueth.c @@ -1804,7 +1804,7 @@ static int icssm_prueth_probe(struct platform_device *pdev) if (!np) return -ENODEV; /* we don't support non DT */ - prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL); + prueth = devm_kzalloc_obj(dev, *prueth); if (!prueth) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 4f9e20468bbbfe..f5e093dc983b58 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c @@ -265,7 +265,7 @@ static int netcp_module_probe(struct netcp_device *netcp_device, return NETCP_MOD_PROBE_SKIPPED; } - inst_modpriv = devm_kzalloc(dev, sizeof(*inst_modpriv), GFP_KERNEL); + inst_modpriv = devm_kzalloc_obj(dev, *inst_modpriv); if (!inst_modpriv) { of_node_put(child); return -ENOMEM; @@ -300,8 +300,7 @@ static int netcp_module_probe(struct netcp_device *netcp_device, interface_list) { struct netcp_intf_modpriv *intf_modpriv; - intf_modpriv = devm_kzalloc(dev, sizeof(*intf_modpriv), - GFP_KERNEL); + intf_modpriv = devm_kzalloc_obj(dev, *intf_modpriv); if (!intf_modpriv) return -ENOMEM; @@ -474,7 +473,7 @@ int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, struct netcp_hook_list *next; unsigned long flags; - entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(netcp_priv->dev, *entry); if (!entry) return -ENOMEM; @@ -523,7 +522,7 @@ int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, struct netcp_hook_list *next; unsigned long flags; - entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(netcp_priv->dev, *entry); if (!entry) return -ENOMEM; @@ -1401,7 +1400,7 @@ static struct netcp_addr *netcp_addr_add(struct netcp_intf *netcp, { struct netcp_addr *naddr; - naddr = devm_kmalloc(netcp->dev, sizeof(*naddr), GFP_ATOMIC); + naddr = devm_kmalloc_obj(netcp->dev, *naddr, GFP_ATOMIC); if (!naddr) return NULL; @@ -2220,7 +2219,7 @@ static int netcp_probe(struct platform_device *pdev) } /* Allocate a new NETCP device instance */ - netcp_device = devm_kzalloc(dev, sizeof(*netcp_device), GFP_KERNEL); + netcp_device = devm_kzalloc_obj(dev, *netcp_device); if (!netcp_device) return -ENOMEM; diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c index 8f46e9be76b1e5..ff1fa0a2131274 100644 --- a/drivers/net/ethernet/ti/netcp_ethss.c +++ b/drivers/net/ethernet/ti/netcp_ethss.c @@ -3120,7 +3120,7 @@ static void init_secondary_ports(struct gbe_priv *gbe_dev, bool mac_phy_link = false; for_each_child_of_node(node, port) { - slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL); + slave = devm_kzalloc_obj(dev, *slave); if (!slave) { dev_err(dev, "memory alloc failed for secondary port(%pOFn), skipping...\n", port); @@ -3270,18 +3270,15 @@ static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev, gbe_dev->et_stats = xgbe10_et_stats; gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats); - gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u64), - GFP_KERNEL); + gbe_dev->hw_stats = devm_kzalloc_objs(gbe_dev->dev, u64, + gbe_dev->num_et_stats); if (!gbe_dev->hw_stats) { dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n"); return -ENOMEM; } gbe_dev->hw_stats_prev = - devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u32), - GFP_KERNEL); + devm_kzalloc_objs(gbe_dev->dev, u32, gbe_dev->num_et_stats); if (!gbe_dev->hw_stats_prev) { dev_err(gbe_dev->dev, "hw_stats_prev memory allocation failed\n"); @@ -3389,18 +3386,15 @@ static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev, gbe_dev->et_stats = gbe13_et_stats; gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats); - gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u64), - GFP_KERNEL); + gbe_dev->hw_stats = devm_kzalloc_objs(gbe_dev->dev, u64, + gbe_dev->num_et_stats); if (!gbe_dev->hw_stats) { dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n"); return -ENOMEM; } gbe_dev->hw_stats_prev = - devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u32), - GFP_KERNEL); + devm_kzalloc_objs(gbe_dev->dev, u32, gbe_dev->num_et_stats); if (!gbe_dev->hw_stats_prev) { dev_err(gbe_dev->dev, "hw_stats_prev memory allocation failed\n"); @@ -3460,18 +3454,15 @@ static int set_gbenu_ethss_priv(struct gbe_priv *gbe_dev, gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE + GBENU_ET_STATS_PORT_SIZE; - gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u64), - GFP_KERNEL); + gbe_dev->hw_stats = devm_kzalloc_objs(gbe_dev->dev, u64, + gbe_dev->num_et_stats); if (!gbe_dev->hw_stats) { dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n"); return -ENOMEM; } gbe_dev->hw_stats_prev = - devm_kcalloc(gbe_dev->dev, - gbe_dev->num_et_stats, sizeof(u32), - GFP_KERNEL); + devm_kzalloc_objs(gbe_dev->dev, u32, gbe_dev->num_et_stats); if (!gbe_dev->hw_stats_prev) { dev_err(gbe_dev->dev, "hw_stats_prev memory allocation failed\n"); @@ -3555,7 +3546,7 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, return -ENODEV; } - gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL); + gbe_dev = devm_kzalloc_obj(dev, struct gbe_priv); if (!gbe_dev) return -ENOMEM; @@ -3750,7 +3741,7 @@ static int gbe_attach(void *inst_priv, struct net_device *ndev, return -ENODEV; } - gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL); + gbe_intf = devm_kzalloc_obj(gbe_dev->dev, *gbe_intf); if (!gbe_intf) return -ENOMEM; @@ -3758,9 +3749,7 @@ static int gbe_attach(void *inst_priv, struct net_device *ndev, gbe_intf->dev = gbe_dev->dev; gbe_intf->gbe_dev = gbe_dev; - gbe_intf->slave = devm_kzalloc(gbe_dev->dev, - sizeof(*gbe_intf->slave), - GFP_KERNEL); + gbe_intf->slave = devm_kzalloc_obj(gbe_dev->dev, *gbe_intf->slave); if (!gbe_intf->slave) { ret = -ENOMEM; goto fail; diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c index e551ae0e206983..22f1bad92a295f 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c @@ -86,8 +86,7 @@ static int txgbe_calc_eeprom_checksum(struct wx *wx, u16 *checksum) wx_init_eeprom_params(wx); - eeprom_ptrs = kvmalloc_array(TXGBE_EEPROM_LAST_WORD, sizeof(u16), - GFP_KERNEL); + eeprom_ptrs = kvmalloc_objs(u16, TXGBE_EEPROM_LAST_WORD); if (!eeprom_ptrs) return -ENOMEM; /* Read pointer area */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c index eb91c4f28ecd40..184194200917bf 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -918,7 +918,7 @@ static int txgbe_probe(struct pci_dev *pdev, goto err_release_hw; } - txgbe = devm_kzalloc(&pdev->dev, sizeof(*txgbe), GFP_KERNEL); + txgbe = devm_kzalloc_obj(&pdev->dev, *txgbe); if (!txgbe) { err = -ENOMEM; goto err_release_hw; diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c index c81d485221d56d..f40ee2935e6b90 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c @@ -390,7 +390,7 @@ static int txgbe_gpio_init(struct txgbe *txgbe) raw_spin_lock_init(&wx->gpio_lock); - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c index 303b4da66399d9..45d16464c2e899 100644 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -329,8 +329,7 @@ static int temac_dma_bd_init(struct net_device *ndev) dma_addr_t skb_dma_addr; int i; - lp->rx_skb = devm_kcalloc(&ndev->dev, lp->rx_bd_num, - sizeof(*lp->rx_skb), GFP_KERNEL); + lp->rx_skb = devm_kzalloc_objs(&ndev->dev, *lp->rx_skb, lp->rx_bd_num); if (!lp->rx_skb) goto out; @@ -1434,9 +1433,8 @@ static int temac_probe(struct platform_device *pdev) } lp->indirect_lock = pdata->indirect_lock; } else { - lp->indirect_lock = devm_kmalloc(&pdev->dev, - sizeof(*lp->indirect_lock), - GFP_KERNEL); + lp->indirect_lock = devm_kmalloc_obj(&pdev->dev, + *lp->indirect_lock); if (!lp->indirect_lock) return -ENOMEM; spin_lock_init(lp->indirect_lock); diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c index b0faa0f1780d09..9313c74ec13068 100644 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c @@ -1442,7 +1442,7 @@ static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev) u8 mac[ETH_ALEN]; int ret; - plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(dev, *plat); if (!plat) return NULL; diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 1dd32e979cf598..85d1b0c46ecfce 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -561,16 +561,19 @@ static int gtp0_handle_echo_resp(struct gtp_dev *gtp, struct sk_buff *skb) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); if (!msg) - return -ENOMEM; + return -1; ret = gtp_genl_fill_echo(msg, 0, 0, 0, GTP_CMD_ECHOREQ, echo); if (ret < 0) { nlmsg_free(msg); - return ret; + return -1; } - return genlmsg_multicast_netns(>p_genl_family, dev_net(gtp->dev), - msg, 0, GTP_GENL_MCGRP, GFP_ATOMIC); + genlmsg_multicast_netns(>p_genl_family, dev_net(gtp->dev), + msg, 0, GTP_GENL_MCGRP, GFP_ATOMIC); + consume_skb(skb); + + return 0; } static int gtp_proto_to_family(__u16 proto) @@ -748,16 +751,19 @@ static int gtp1u_handle_echo_resp(struct gtp_dev *gtp, struct sk_buff *skb) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); if (!msg) - return -ENOMEM; + return -1; ret = gtp_genl_fill_echo(msg, 0, 0, 0, GTP_CMD_ECHOREQ, echo); if (ret < 0) { nlmsg_free(msg); - return ret; + return -1; } - return genlmsg_multicast_netns(>p_genl_family, dev_net(gtp->dev), - msg, 0, GTP_GENL_MCGRP, GFP_ATOMIC); + genlmsg_multicast_netns(>p_genl_family, dev_net(gtp->dev), + msg, 0, GTP_GENL_MCGRP, GFP_ATOMIC); + consume_skb(skb); + + return 0; } static int gtp_parse_exthdrs(struct sk_buff *skb, unsigned int *hdrlen) diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c index 9b6c44979b4ea6..96225132750695 100644 --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -401,12 +401,12 @@ static inline void *rndis_get_ppi(struct net_device *ndev, /* Validate ppi_offset and ppi_size */ if (ppi->size > len) { netdev_err(ndev, "Invalid ppi size: %u\n", ppi->size); - continue; + return NULL; } if (ppi->ppi_offset >= ppi->size) { netdev_err(ndev, "Invalid ppi_offset: %u\n", ppi->ppi_offset); - continue; + return NULL; } if (ppi->type == type && ppi->internal == internal) { @@ -414,7 +414,7 @@ static inline void *rndis_get_ppi(struct net_device *ndev, if (ppi->size - ppi->ppi_offset < ppi_size) { netdev_err(ndev, "Invalid ppi: size %u ppi_offset %u\n", ppi->size, ppi->ppi_offset); - continue; + return NULL; } return (void *)((ulong)ppi + ppi->ppi_offset); } @@ -1555,7 +1555,7 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, else ndc->rx_table_sz = ITAB_NUM; - ndc->rx_table = kcalloc(ndc->rx_table_sz, sizeof(u16), GFP_KERNEL); + ndc->rx_table = kzalloc_objs(u16, ndc->rx_table_sz); if (!ndc->rx_table) { ret = -ENOMEM; goto err_dev_remv; diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c index abfcfe07246a7b..5b6ab84fad8ad0 100644 --- a/drivers/net/ieee802154/cc2520.c +++ b/drivers/net/ieee802154/cc2520.c @@ -1039,7 +1039,7 @@ static int cc2520_probe(struct spi_device *spi) struct gpio_desc *vreg; int ret; - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/ipa/ipa_interrupt.c b/drivers/net/ipa/ipa_interrupt.c index 131b9cc9420143..766b094eb06945 100644 --- a/drivers/net/ipa/ipa_interrupt.c +++ b/drivers/net/ipa/ipa_interrupt.c @@ -260,10 +260,8 @@ int ipa_interrupt_config(struct ipa *ipa) interrupt->enabled = 0; interrupt->suspend_enabled = bitmap_zalloc(ipa->endpoint_count, GFP_KERNEL); - if (!interrupt->suspend_enabled) { - ret = -ENOMEM; - goto err_kfree; - } + if (!interrupt->suspend_enabled) + return -ENOMEM; /* Disable IPA interrupt types */ reg = ipa_reg(ipa, IPA_IRQ_EN); @@ -289,8 +287,6 @@ int ipa_interrupt_config(struct ipa *ipa) goto err_disable_wakeup; } - ipa->interrupt = interrupt; - return 0; err_disable_wakeup: @@ -299,8 +295,6 @@ int ipa_interrupt_config(struct ipa *ipa) free_irq(interrupt->irq, interrupt); err_free_bitmap: bitmap_free(interrupt->suspend_enabled); -err_kfree: - kfree(interrupt); return ret; } @@ -311,8 +305,6 @@ void ipa_interrupt_deconfig(struct ipa *ipa) struct ipa_interrupt *interrupt = ipa->interrupt; struct device *dev = ipa->dev; - ipa->interrupt = NULL; - dev_pm_clear_wake_irq(dev); (void)device_init_wakeup(dev, false); free_irq(interrupt->irq, interrupt); diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c index 7ad12dc7845c83..d2afc2ec896e03 100644 --- a/drivers/net/ipvlan/ipvlan_core.c +++ b/drivers/net/ipvlan/ipvlan_core.c @@ -438,7 +438,8 @@ static noinline_for_stack int ipvlan_process_v4_outbound(struct sk_buff *skb) .flowi4_mark = skb->mark, }; - if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + if (!pskb_network_may_pull(skb, sizeof(struct iphdr)) || + skb_cow_head(skb, 0)) goto err; ip4h = ip_hdr(skb); @@ -504,7 +505,8 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb) struct net_device *dev = skb->dev; int err, ret = NET_XMIT_DROP; - if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) { + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr)) || + skb_cow_head(skb, 0)) { DEV_STATS_INC(dev, tx_errors); kfree_skb(skb); return ret; diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 87f3f4bdb0265f..240ba0ae07d1e9 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -408,8 +408,10 @@ static bool macsec_validate_skb(struct sk_buff *skb, u16 icv_len, bool xpn) int len = skb->len - 2 * ETH_ALEN; int extra_len = macsec_extra_len(!!(h->tci_an & MACSEC_TCI_SC)) + icv_len; - /* a) It comprises at least 17 octets */ - if (skb->len <= 16) + /* a) It comprises at least 17 octets. The SecTAG and ICV must + * also leave a complete Ethernet header. + */ + if (skb->len < ETH_HLEN + extra_len) return false; /* b) MACsec EtherType: already checked */ @@ -1331,9 +1333,12 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb) nosci: /* 10.6.1 if the SC is not found */ cbit = !!(hdr->tci_an & MACSEC_TCI_C); - if (!cbit) - macsec_finalize_skb(skb, MACSEC_DEFAULT_ICV_LEN, - macsec_extra_len(macsec_skb_cb(skb)->has_sci)); + if (!cbit) { + len = macsec_extra_len(macsec_skb_cb(skb)->has_sci); + if (skb->len < ETH_HLEN + len + MACSEC_DEFAULT_ICV_LEN) + goto drop_nosc; + macsec_finalize_skb(skb, MACSEC_DEFAULT_ICV_LEN, len); + } list_for_each_entry_rcu(macsec, &rxd->secys, secys) { struct sk_buff *nskb; diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index a48c9e662fe9f1..4f8416bb5169b6 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -643,6 +643,14 @@ static int macvlan_open(struct net_device *dev) if (err < 0) goto out; } + if (dev->flags & IFF_ALLMULTI) { + err = dev_set_allmulti(lowerdev, 1); + if (err < 0) { + if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) + dev_set_promiscuity(lowerdev, -1); + goto out; + } + } goto hash_add; } @@ -713,6 +721,8 @@ static int macvlan_stop(struct net_device *dev) dev_mc_unsync(lowerdev, dev); if (macvlan_passthru(vlan->port)) { + if (dev->flags & IFF_ALLMULTI) + dev_set_allmulti(lowerdev, -1); if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) dev_set_promiscuity(lowerdev, -1); goto hash_del; diff --git a/drivers/net/mctp/mctp-i3c.c b/drivers/net/mctp/mctp-i3c.c index 4e857dd5df642c..5f225999d715eb 100644 --- a/drivers/net/mctp/mctp-i3c.c +++ b/drivers/net/mctp/mctp-i3c.c @@ -111,8 +111,7 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi) mi->mrl + sizeof(struct mctp_i3c_internal_hdr)); if (!skb) { stats->rx_dropped++; - rc = -ENOMEM; - goto err; + return -ENOMEM; } skb->protocol = htons(ETH_P_MCTP); diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c index 3a48b10164b097..f4e1258756d4de 100644 --- a/drivers/net/mctp/mctp-usblib-test.c +++ b/drivers/net/mctp/mctp-usblib-test.c @@ -46,7 +46,7 @@ static int mctp_usblib_test_tx_send(struct mctp_usblib_tx_ctx *tx_ctx, ctx = mctp_usblib_tx_ctx_priv(tx_ctx); ndev = ctx->dev->ndev; - new_node = kzalloc_flex(*new_node, data, len, GFP_KERNEL); + new_node = kzalloc_flex(*new_node, data, len); if (!new_node) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-bcm-iproc.c b/drivers/net/mdio/mdio-bcm-iproc.c index 22473c988e3b10..db289de77ec85c 100644 --- a/drivers/net/mdio/mdio-bcm-iproc.c +++ b/drivers/net/mdio/mdio-bcm-iproc.c @@ -125,7 +125,7 @@ static int iproc_mdio_probe(struct platform_device *pdev) struct mii_bus *bus; int rc; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c index 31e396cc9fbf2a..80fb3b5b52ab8f 100644 --- a/drivers/net/mdio/mdio-bcm-unimac.c +++ b/drivers/net/mdio/mdio-bcm-unimac.c @@ -245,7 +245,7 @@ static int unimac_mdio_probe(struct platform_device *pdev) np = pdev->dev.of_node; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-gpio.c b/drivers/net/mdio/mdio-gpio.c index 958d1c6608ab76..96e962f412b649 100644 --- a/drivers/net/mdio/mdio-gpio.c +++ b/drivers/net/mdio/mdio-gpio.c @@ -160,7 +160,7 @@ static int mdio_gpio_probe(struct platform_device *pdev) struct mii_bus *new_bus; int ret, bus_id; - bitbang = devm_kzalloc(&pdev->dev, sizeof(*bitbang), GFP_KERNEL); + bitbang = devm_kzalloc_obj(&pdev->dev, *bitbang); if (!bitbang) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-mux-bcm-iproc.c b/drivers/net/mdio/mdio-mux-bcm-iproc.c index 8ba0917a930a00..bbbfdecf1f3845 100644 --- a/drivers/net/mdio/mdio-mux-bcm-iproc.c +++ b/drivers/net/mdio/mdio-mux-bcm-iproc.c @@ -214,7 +214,7 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev) struct resource *res; int rc; - md = devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); + md = devm_kzalloc_obj(&pdev->dev, *md); if (!md) return -ENOMEM; md->dev = &pdev->dev; diff --git a/drivers/net/mdio/mdio-mux-bcm6368.c b/drivers/net/mdio/mdio-mux-bcm6368.c index 476f8b72d02051..d8f4aae0a8eb78 100644 --- a/drivers/net/mdio/mdio-mux-bcm6368.c +++ b/drivers/net/mdio/mdio-mux-bcm6368.c @@ -93,7 +93,7 @@ static int bcm6368_mdiomux_probe(struct platform_device *pdev) struct resource *res; int rc; - md = devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); + md = devm_kzalloc_obj(&pdev->dev, *md); if (!md) return -ENOMEM; md->dev = &pdev->dev; diff --git a/drivers/net/mdio/mdio-mux-gpio.c b/drivers/net/mdio/mdio-mux-gpio.c index fefa40ea5227c5..4eaed599aaac25 100644 --- a/drivers/net/mdio/mdio-mux-gpio.c +++ b/drivers/net/mdio/mdio-mux-gpio.c @@ -45,7 +45,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev) if (IS_ERR(gpios)) return PTR_ERR(gpios); - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, *s); if (!s) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-mux-meson-g12a.c b/drivers/net/mdio/mdio-mux-meson-g12a.c index e6c9ef3641afa2..71c44385489d45 100644 --- a/drivers/net/mdio/mdio-mux-meson-g12a.c +++ b/drivers/net/mdio/mdio-mux-meson-g12a.c @@ -244,7 +244,7 @@ static int g12a_ephy_glue_clk_register(struct device *dev) } /* create the input mux */ - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; @@ -271,7 +271,7 @@ static int g12a_ephy_glue_clk_register(struct device *dev) } /* create the pll */ - pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + pll = devm_kzalloc_obj(dev, *pll); if (!pll) return -ENOMEM; @@ -308,7 +308,7 @@ static int g12a_mdio_mux_probe(struct platform_device *pdev) struct clk *pclk; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-mux-meson-gxl.c b/drivers/net/mdio/mdio-mux-meson-gxl.c index 3dd12a8c8b03e9..f79355fdb0ceba 100644 --- a/drivers/net/mdio/mdio-mux-meson-gxl.c +++ b/drivers/net/mdio/mdio-mux-meson-gxl.c @@ -119,7 +119,7 @@ static int gxl_mdio_mux_probe(struct platform_device *pdev) struct clk *rclk; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/drivers/net/mdio/mdio-mux-mmioreg.c b/drivers/net/mdio/mdio-mux-mmioreg.c index 9c4b1efd0d53c9..4fbe628415bc79 100644 --- a/drivers/net/mdio/mdio-mux-mmioreg.c +++ b/drivers/net/mdio/mdio-mux-mmioreg.c @@ -104,7 +104,7 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "probing node %pOF\n", np); - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, *s); if (!s) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-mux-multiplexer.c b/drivers/net/mdio/mdio-mux-multiplexer.c index 8e11960fc539d1..7414bc99ccaa1d 100644 --- a/drivers/net/mdio/mdio-mux-multiplexer.c +++ b/drivers/net/mdio/mdio-mux-multiplexer.c @@ -67,7 +67,7 @@ static int mdio_mux_multiplexer_probe(struct platform_device *pdev) struct mdio_mux_multiplexer_state *s; int ret = 0; - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, *s); if (!s) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index fe0e46bd7964f6..c0260d00fdc35d 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/mdio-mux.c @@ -171,7 +171,7 @@ int mdio_mux_init(struct device *dev, get_device(&parent_bus->dev); } - pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL); + pb = devm_kzalloc_obj(dev, *pb); if (!pb) { ret_val = -ENOMEM; goto err_pb_kz; @@ -195,7 +195,7 @@ int mdio_mux_init(struct device *dev, continue; } - cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL); + cb = devm_kzalloc_obj(dev, *cb); if (!cb) { ret_val = -ENOMEM; goto err_loop; diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index eb7a6238dbd108..fcffc4931643cc 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -1098,7 +1098,7 @@ static int otto_emdio_probe(struct platform_device *pdev) struct otto_emdio_priv *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-thunder.c b/drivers/net/mdio/mdio-thunder.c index a3047f7258a723..aea067658de2df 100644 --- a/drivers/net/mdio/mdio-thunder.c +++ b/drivers/net/mdio/mdio-thunder.c @@ -27,7 +27,7 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev, int err; int i; - nexus = devm_kzalloc(&pdev->dev, sizeof(*nexus), GFP_KERNEL); + nexus = devm_kzalloc_obj(&pdev->dev, *nexus); if (!nexus) return -ENOMEM; diff --git a/drivers/net/mdio/mdio-xgene.c b/drivers/net/mdio/mdio-xgene.c index ede6b9ddc42614..78475749a62591 100644 --- a/drivers/net/mdio/mdio-xgene.c +++ b/drivers/net/mdio/mdio-xgene.c @@ -336,7 +336,7 @@ static int xgene_mdio_probe(struct platform_device *pdev) if (!mdio_id) return -ENODEV; - pdata = devm_kzalloc(dev, sizeof(struct xgene_mdio_pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct xgene_mdio_pdata); if (!pdata) return -ENOMEM; pdata->mdio_id = mdio_id; diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index feb88ccbbcedb2..c6b17b3873271b 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -871,9 +871,8 @@ static int nsim_dev_traps_init(struct devlink *devlink) goto err_trap_data_free; } - nsim_trap_data->trap_policers_cnt_arr = kcalloc(policers_count, - sizeof(u64), - GFP_KERNEL); + nsim_trap_data->trap_policers_cnt_arr = kzalloc_objs(u64, + policers_count); if (!nsim_trap_data->trap_policers_cnt_arr) { err = -ENOMEM; goto err_trap_items_free; diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index f8bafce26bf138..682a73cf5a87dc 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -790,7 +790,7 @@ static int miic_probe(struct platform_device *pdev) u32 mode_cfg; int ret; - miic = devm_kzalloc(dev, sizeof(*miic), GFP_KERNEL); + miic = devm_kzalloc_obj(dev, *miic); if (!miic) return -ENOMEM; diff --git a/drivers/net/pcs/pcs-xpcs-plat.c b/drivers/net/pcs/pcs-xpcs-plat.c index c4404500bac60e..2a6a9a7712c32f 100644 --- a/drivers/net/pcs/pcs-xpcs-plat.c +++ b/drivers/net/pcs/pcs-xpcs-plat.c @@ -219,7 +219,7 @@ static struct dw_xpcs_plat *xpcs_plat_create_data(struct platform_device *pdev) { struct dw_xpcs_plat *pxpcs; - pxpcs = devm_kzalloc(&pdev->dev, sizeof(*pxpcs), GFP_KERNEL); + pxpcs = devm_kzalloc_obj(&pdev->dev, *pxpcs); if (!pxpcs) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/pcs/pcs-xpcs-rk.c b/drivers/net/pcs/pcs-xpcs-rk.c index 6f0a110e32d24e..ad187fba4e9d9b 100644 --- a/drivers/net/pcs/pcs-xpcs-rk.c +++ b/drivers/net/pcs/pcs-xpcs-rk.c @@ -225,7 +225,7 @@ static struct dw_xpcs_rk *xpcs_rk_create_data(struct platform_device *pdev) { struct dw_xpcs_rk *pxpcs; - pxpcs = devm_kzalloc(&pdev->dev, sizeof(*pxpcs), GFP_KERNEL); + pxpcs = devm_kzalloc_obj(&pdev->dev, *pxpcs); if (!pxpcs) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index 3a934051b57423..b0cb93be3adb14 100644 --- a/drivers/net/phy/adin.c +++ b/drivers/net/phy/adin.c @@ -892,7 +892,7 @@ static int adin_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct adin_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c index 8f9753d4318c85..f845b440aaef04 100644 --- a/drivers/net/phy/adin1100.c +++ b/drivers/net/phy/adin1100.c @@ -311,7 +311,7 @@ static int adin_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct adin_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/air_an8801.c b/drivers/net/phy/air_an8801.c index f97c78e430237e..98b3ff6c24eb8b 100644 --- a/drivers/net/phy/air_an8801.c +++ b/drivers/net/phy/air_an8801.c @@ -1036,7 +1036,7 @@ static int an8801r_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct an8801r_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index a03d63dd4ac916..81aa9df08deec5 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -1135,8 +1135,7 @@ static int an8811hb_probe(struct phy_device *phydev) u32 reg_val; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct en8811h_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, struct en8811h_priv); if (!priv) return -ENOMEM; phydev->priv = priv; @@ -1204,8 +1203,7 @@ static int en8811h_probe(struct phy_device *phydev) struct en8811h_priv *priv; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct en8811h_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, struct en8811h_priv); if (!priv) return -ENOMEM; phydev->priv = priv; diff --git a/drivers/net/phy/aquantia/aquantia_main.c b/drivers/net/phy/aquantia/aquantia_main.c index 096407bebd52a8..66e4e98c7aedc0 100644 --- a/drivers/net/phy/aquantia/aquantia_main.c +++ b/drivers/net/phy/aquantia/aquantia_main.c @@ -1168,8 +1168,7 @@ static int aqr107_probe(struct phy_device *phydev) { int ret; - phydev->priv = devm_kzalloc(&phydev->mdio.dev, - sizeof(struct aqr107_priv), GFP_KERNEL); + phydev->priv = devm_kzalloc_obj(&phydev->mdio.dev, struct aqr107_priv); if (!phydev->priv) return -ENOMEM; diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c index d5738117eca688..dbe6be963389de 100644 --- a/drivers/net/phy/as21xxx.c +++ b/drivers/net/phy/as21xxx.c @@ -605,8 +605,7 @@ static int as21xxx_probe(struct phy_device *phydev) struct as21xxx_priv *priv; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, - sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; phydev->priv = priv; diff --git a/drivers/net/phy/bcm-cygnus.c b/drivers/net/phy/bcm-cygnus.c index 15cbef8202bc5f..c7367f78309d57 100644 --- a/drivers/net/phy/bcm-cygnus.c +++ b/drivers/net/phy/bcm-cygnus.c @@ -234,15 +234,14 @@ static int bcm_omega_probe(struct phy_device *phydev) { struct bcm_omega_phy_priv *priv; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; phydev->priv = priv; - priv->stats = devm_kcalloc(&phydev->mdio.dev, - bcm_phy_get_sset_count(phydev), sizeof(u64), - GFP_KERNEL); + priv->stats = devm_kzalloc_objs(&phydev->mdio.dev, u64, + bcm_phy_get_sset_count(phydev)); if (!priv->stats) return -ENOMEM; diff --git a/drivers/net/phy/bcm-phy-ptp.c b/drivers/net/phy/bcm-phy-ptp.c index 65d609ed69fb4e..443917c9d1bc39 100644 --- a/drivers/net/phy/bcm-phy-ptp.c +++ b/drivers/net/phy/bcm-phy-ptp.c @@ -929,7 +929,7 @@ struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev) return NULL; } - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/bcm54140.c b/drivers/net/phy/bcm54140.c index a8edf45fd73359..2831ca7f6f2667 100644 --- a/drivers/net/phy/bcm54140.c +++ b/drivers/net/phy/bcm54140.c @@ -582,7 +582,7 @@ static int bcm54140_probe(struct phy_device *phydev) struct bcm54140_priv *priv; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c index 71a163f62c0eb6..44147e4ab294d7 100644 --- a/drivers/net/phy/bcm7xxx.c +++ b/drivers/net/phy/bcm7xxx.c @@ -824,15 +824,14 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev) struct clk *clk; int ret = 0; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; phydev->priv = priv; - priv->stats = devm_kcalloc(&phydev->mdio.dev, - bcm_phy_get_sset_count(phydev), sizeof(u64), - GFP_KERNEL); + priv->stats = devm_kzalloc_objs(&phydev->mdio.dev, u64, + bcm_phy_get_sset_count(phydev)); if (!priv->stats) return -ENOMEM; diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index b515e38755041d..9085b72e322f40 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -815,7 +815,7 @@ static int bcm54616s_probe(struct phy_device *phydev) struct bcm54616s_phy_priv *priv; int val; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; @@ -1180,7 +1180,7 @@ static int bcm54xx_phy_probe(struct phy_device *phydev) struct gpio_desc *wakeup_gpio; int ret = 0; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; @@ -1188,9 +1188,8 @@ static int bcm54xx_phy_probe(struct phy_device *phydev) phydev->priv = priv; - priv->stats = devm_kcalloc(&phydev->mdio.dev, - bcm_phy_get_sset_count(phydev), sizeof(u64), - GFP_KERNEL); + priv->stats = devm_kzalloc_objs(&phydev->mdio.dev, u64, + bcm_phy_get_sset_count(phydev)); if (!priv->stats) return -ENOMEM; diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c index 6fc86be9d593c7..d67ca7e4a7e772 100644 --- a/drivers/net/phy/dp83822.c +++ b/drivers/net/phy/dp83822.c @@ -989,7 +989,7 @@ static int dp8382x_probe(struct phy_device *phydev) struct dp83822_private *dp83822; struct clk *clk; - dp83822 = devm_kzalloc(dev, sizeof(*dp83822), GFP_KERNEL); + dp83822 = devm_kzalloc_obj(dev, *dp83822); if (!dp83822) return -ENOMEM; diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index a3cd5cb11ea0ac..b4b4931c6f8ceb 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -735,8 +735,7 @@ static int dp83867_probe(struct phy_device *phydev) struct dp83867_private *dp83867; int ret; - dp83867 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83867), - GFP_KERNEL); + dp83867 = devm_kzalloc_obj(&phydev->mdio.dev, *dp83867); if (!dp83867) return -ENOMEM; diff --git a/drivers/net/phy/dp83869.c b/drivers/net/phy/dp83869.c index 96a7d255f50fd9..00ee7428f618d3 100644 --- a/drivers/net/phy/dp83869.c +++ b/drivers/net/phy/dp83869.c @@ -877,8 +877,7 @@ static int dp83869_probe(struct phy_device *phydev) struct dp83869_private *dp83869; int ret; - dp83869 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83869), - GFP_KERNEL); + dp83869 = devm_kzalloc_obj(&phydev->mdio.dev, *dp83869); if (!dp83869) return -ENOMEM; diff --git a/drivers/net/phy/dp83td510.c b/drivers/net/phy/dp83td510.c index 31c139bef07665..84b1ea5015c9d4 100644 --- a/drivers/net/phy/dp83td510.c +++ b/drivers/net/phy/dp83td510.c @@ -998,7 +998,7 @@ static int dp83td510_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct dp83td510_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/dp83tg720.c b/drivers/net/phy/dp83tg720.c index 391c1d8688083f..807ff5525ecd8b 100644 --- a/drivers/net/phy/dp83tg720.c +++ b/drivers/net/phy/dp83tg720.c @@ -589,7 +589,7 @@ static int dp83tg720_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct dp83tg720_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c index c0c4f19cfb6a00..f50ae62c1f14db 100644 --- a/drivers/net/phy/icplus.c +++ b/drivers/net/phy/icplus.c @@ -206,7 +206,7 @@ static int ip101a_g_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct ip101a_g_phy_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/intel-xway.c b/drivers/net/phy/intel-xway.c index 3cee31bb931f23..49f72632554a78 100644 --- a/drivers/net/phy/intel-xway.c +++ b/drivers/net/phy/intel-xway.c @@ -323,7 +323,7 @@ static int xway_gphy_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct xway_gphy_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; phydev->priv = priv; diff --git a/drivers/net/phy/marvell-88q2xxx.c b/drivers/net/phy/marvell-88q2xxx.c index 201dee1a16985e..b2896ee16203f2 100644 --- a/drivers/net/phy/marvell-88q2xxx.c +++ b/drivers/net/phy/marvell-88q2xxx.c @@ -799,7 +799,7 @@ static int mv88q2xxx_probe(struct phy_device *phydev) struct mv88q2xxx_priv *priv; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88x2222.c index ba1bbb6c63d641..92014e200c6ff3 100644 --- a/drivers/net/phy/marvell-88x2222.c +++ b/drivers/net/phy/marvell-88x2222.c @@ -565,7 +565,7 @@ static int mv2222_probe(struct phy_device *phydev) linkmode_copy(phydev->supported, supported); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 2c688d661297df..87f66dfa92dda1 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -3642,7 +3642,7 @@ static int marvell_probe(struct phy_device *phydev) { struct marvell_priv *priv; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index b40df82152cd83..0956cb579ccd28 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -507,7 +507,7 @@ static int mv3310_probe(struct phy_device *phydev) return -ENODEV; } - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/mediatek/mtk-2p5ge.c b/drivers/net/phy/mediatek/mtk-2p5ge.c index de8a41a1841da1..d1fb944068578f 100644 --- a/drivers/net/phy/mediatek/mtk-2p5ge.c +++ b/drivers/net/phy/mediatek/mtk-2p5ge.c @@ -365,8 +365,7 @@ static int mt798x_2p5ge_phy_probe(struct phy_device *phydev) if (IS_ERR(pinctrl)) dev_err(&phydev->mdio.dev, "Fail to set LED pins!\n"); - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct mtk_socphy_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, struct mtk_socphy_priv); if (!priv) return -ENOMEM; phydev->priv = priv; diff --git a/drivers/net/phy/mediatek/mtk-ge-soc.c b/drivers/net/phy/mediatek/mtk-ge-soc.c index 0041300d4f1013..9ba2a812c52e95 100644 --- a/drivers/net/phy/mediatek/mtk-ge-soc.c +++ b/drivers/net/phy/mediatek/mtk-ge-soc.c @@ -1415,8 +1415,7 @@ static int mt7981_phy_probe(struct phy_device *phydev) { struct mtk_socphy_priv *priv; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct mtk_socphy_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, struct mtk_socphy_priv); if (!priv) return -ENOMEM; @@ -1438,7 +1437,7 @@ static int an7581_phy_probe(struct phy_device *phydev) dev_err(&phydev->mdio.bus->dev, "Failed to setup PHY LED pinctrl\n"); - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index d0b1ad21667b6e..ac3a12d0e088bc 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -2763,7 +2763,7 @@ static int kszphy_probe(struct phy_device *phydev) struct kszphy_priv *priv; struct clk *clk; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; @@ -4569,10 +4569,8 @@ static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name, /* Initialise shared lock for clock*/ mutex_init(&shared->shared_lock); - shared->pin_config = devm_kmalloc_array(&phydev->mdio.dev, - gpios, - sizeof(*shared->pin_config), - GFP_KERNEL); + shared->pin_config = devm_kmalloc_objs(&phydev->mdio.dev, + *shared->pin_config, gpios); if (!shared->pin_config) return -ENOMEM; @@ -4751,7 +4749,7 @@ static int lan8814_probe(struct phy_device *phydev) u16 addr; int err; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; @@ -6059,10 +6057,9 @@ static int lan8841_probe(struct phy_device *phydev) priv = phydev->priv; ptp_priv = &priv->ptp_priv; - ptp_priv->pin_config = devm_kcalloc(&phydev->mdio.dev, - LAN8841_PTP_GPIO_NUM, - sizeof(*ptp_priv->pin_config), - GFP_KERNEL); + ptp_priv->pin_config = devm_kzalloc_objs(&phydev->mdio.dev, + *ptp_priv->pin_config, + LAN8841_PTP_GPIO_NUM); if (!ptp_priv->pin_config) return -ENOMEM; @@ -6162,7 +6159,7 @@ static int lan8842_probe(struct phy_device *phydev) int addr; int ret; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/microchip.c b/drivers/net/phy/microchip.c index 33bc633bdba05e..10fcee11d748cf 100644 --- a/drivers/net/phy/microchip.c +++ b/drivers/net/phy/microchip.c @@ -269,7 +269,7 @@ static int lan88xx_probe(struct phy_device *phydev) u32 led_modes[4]; int len; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c index 2ad95d5c9d867d..e1bd879c47997b 100644 --- a/drivers/net/phy/microchip_rds_ptp.c +++ b/drivers/net/phy/microchip_rds_ptp.c @@ -1246,7 +1246,7 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd, struct mchp_rds_ptp_clock *clock; int rc; - clock = devm_kzalloc(&phydev->mdio.dev, sizeof(*clock), GFP_KERNEL); + clock = devm_kzalloc_obj(&phydev->mdio.dev, *clock); if (!clock) return ERR_PTR(-ENOMEM); @@ -1255,10 +1255,9 @@ struct mchp_rds_ptp_clock *mchp_rds_ptp_probe(struct phy_device *phydev, u8 mmd, clock->mmd = mmd; mutex_init(&clock->ptp_lock); - clock->pin_config = devm_kmalloc_array(&phydev->mdio.dev, - MCHP_RDS_PTP_N_PIN, - sizeof(*clock->pin_config), - GFP_KERNEL); + clock->pin_config = devm_kmalloc_objs(&phydev->mdio.dev, + *clock->pin_config, + MCHP_RDS_PTP_N_PIN); if (!clock->pin_config) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index e38d20bf6aa4c8..c423db53730d56 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -1494,7 +1494,7 @@ static int lan887x_probe(struct phy_device *phydev) { struct lan887x_priv *priv; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 463e1ea3efc93f..a87e83fdf590c7 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -1092,7 +1092,7 @@ static int yt8521_probe(struct phy_device *phydev) u32 freq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c index 2b9fb8a675a658..e8b0f643779552 100644 --- a/drivers/net/phy/mscc/mscc_main.c +++ b/drivers/net/phy/mscc/mscc_main.c @@ -2246,7 +2246,7 @@ static int vsc85xx_probe_common(struct phy_device *phydev, struct device_node *np; int ret; - vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); + vsc8531 = devm_kzalloc_obj(&phydev->mdio.dev, *vsc8531); if (!vsc8531) return -ENOMEM; @@ -2278,8 +2278,8 @@ static int vsc85xx_probe_common(struct phy_device *phydev, /* Configure hardware stats */ vsc8531->hw_stats = cfg->hw_stats; vsc8531->nstats = cfg->nstats; - vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); + vsc8531->stats = devm_kzalloc_objs(&phydev->mdio.dev, u64, + vsc8531->nstats); if (!vsc8531->stats) return -ENOMEM; diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c index 4865eac74b0ed0..8a737f9ba41106 100644 --- a/drivers/net/phy/mscc/mscc_ptp.c +++ b/drivers/net/phy/mscc/mscc_ptp.c @@ -1592,8 +1592,7 @@ int vsc8584_ptp_probe(struct phy_device *phydev) { struct vsc8531_private *vsc8531 = phydev->priv; - vsc8531->ptp = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531->ptp), - GFP_KERNEL); + vsc8531->ptp = devm_kzalloc_obj(&phydev->mdio.dev, *vsc8531->ptp); if (!vsc8531->ptp) return -ENOMEM; diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c index 089a1a9e5bc613..64a276cb01d8f8 100644 --- a/drivers/net/phy/mxl-gpy.c +++ b/drivers/net/phy/mxl-gpy.c @@ -363,7 +363,7 @@ static int gpy_probe(struct phy_device *phydev) return ret; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; phydev->priv = priv; diff --git a/drivers/net/phy/nxp-c45-tja11xx-macsec.c b/drivers/net/phy/nxp-c45-tja11xx-macsec.c index 63e3934be65345..d4963d31998e00 100644 --- a/drivers/net/phy/nxp-c45-tja11xx-macsec.c +++ b/drivers/net/phy/nxp-c45-tja11xx-macsec.c @@ -1651,7 +1651,7 @@ int nxp_c45_macsec_probe(struct phy_device *phydev) struct nxp_c45_phy *priv = phydev->priv; struct device *dev = &phydev->mdio.dev; - priv->macsec = devm_kzalloc(dev, sizeof(*priv->macsec), GFP_KERNEL); + priv->macsec = devm_kzalloc_obj(dev, *priv->macsec); if (!priv->macsec) return -ENOMEM; diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 8df152f6671fc1..a264616bb4e61c 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -1735,7 +1735,7 @@ static int nxp_c45_probe(struct phy_device *phydev) bool ptp_ability; int ret = 0; - priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&phydev->mdio.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c index 079d912a135781..53ba118fb62ea4 100644 --- a/drivers/net/phy/nxp-tja11xx.c +++ b/drivers/net/phy/nxp-tja11xx.c @@ -534,7 +534,7 @@ static int tja11xx_probe(struct phy_device *phydev) struct tja11xx_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -615,7 +615,7 @@ static int tja1102_p0_probe(struct phy_device *phydev) struct tja11xx_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index 870920311f9a01..828af4c4e9d4cf 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -104,6 +104,36 @@ int genphy_c45_pma_baset1_setup_master_slave(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(genphy_c45_pma_baset1_setup_master_slave); +/* Type selection value for the BASE-T1 PMA/PMD control register (1.2100, + * 802.3-2022 Table 45-178) matching the forced speed. 10 Mbit/s is ambiguous + * between 10BASE-T1L and 10BASE-T1S, so the supported link modes decide. + * 2.5G, 5G and 10GBASE-T1 are not handled as there are no link modes for them + * yet. + */ +static int genphy_c45_baset1_type_sel(struct phy_device *phydev) +{ + switch (phydev->speed) { + case SPEED_10: + if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, + phydev->supported)) + return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1L; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1S_Full_BIT, + phydev->supported) || + linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1S_Half_BIT, + phydev->supported) || + linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT, + phydev->supported)) + return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1S; + return -EINVAL; + case SPEED_100: + return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_100BT1; + case SPEED_1000: + return MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1; + default: + return -EINVAL; + } +} + /** * genphy_c45_pma_setup_forced - configures a forced speed * @phydev: target phy_device struct @@ -166,6 +196,16 @@ int genphy_c45_pma_setup_forced(struct phy_device *phydev) return -EINVAL; } + /* Resolve the type before the first write, so a speed without a + * matching type leaves the PHY untouched. + */ + bt1_ctrl = 0; + if (genphy_c45_baset1_able(phydev)) { + bt1_ctrl = genphy_c45_baset1_type_sel(phydev); + if (bt1_ctrl < 0) + return bt1_ctrl; + } + ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_CTRL1, ctrl1); if (ret < 0) return ret; @@ -179,12 +219,8 @@ int genphy_c45_pma_setup_forced(struct phy_device *phydev) if (ret < 0) return ret; - bt1_ctrl = 0; - if (phydev->speed == SPEED_1000) - bt1_ctrl = MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000; - ret = phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_PMD_BT1_CTRL, - MDIO_PMA_PMD_BT1_CTRL_STRAP, bt1_ctrl); + MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL, bt1_ctrl); if (ret < 0) return ret; } diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 5d4508bcfbe991..b39e945cebd739 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1826,9 +1826,13 @@ static void phy_detach_internal(struct phy_device *phydev, bool notify_bus) struct hwtstamp_provider *hwprov; /* hwprov may technically be protected by ops lock but - * not for devices with a phydev, see phy_link_topo_add_phy() + * not for devices with a phydev, see phy_link_topo_add_phy(). + * Drivers may detach without RTNL while dev is unregistered, + * but then nothing else can reach hwprov. */ - hwprov = rtnl_dereference(dev->hwprov); + hwprov = rcu_dereference_protected(dev->hwprov, + lockdep_rtnl_is_held() || + dev->reg_state != NETREG_REGISTERED); /* Disable timestamp if it is the one selected */ if (hwprov && hwprov->phydev == phydev) { rcu_assign_pointer(dev->hwprov, NULL); @@ -3429,7 +3433,7 @@ static int of_phy_led(struct phy_device *phydev, u32 index; int err; - phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL); + phyled = devm_kzalloc_obj(dev, *phyled); if (!phyled) return -ENOMEM; diff --git a/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index 09105f1e373794..5cc6d7b3b9e061 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -366,7 +366,7 @@ static int at803x_probe(struct phy_device *phydev) struct at803x_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -1110,7 +1110,7 @@ static int ipq5018_probe(struct phy_device *phydev) struct ipq5018_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/qcom/qca807x.c b/drivers/net/phy/qcom/qca807x.c index 6004da5741af37..81b54057b8ba3e 100644 --- a/drivers/net/phy/qcom/qca807x.c +++ b/drivers/net/phy/qcom/qca807x.c @@ -408,13 +408,13 @@ static int qca807x_gpio(struct phy_device *phydev) struct qca807x_gpio_priv *priv; struct gpio_chip *gc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->phy = phydev; - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + gc = devm_kzalloc_obj(dev, *gc); if (!gc) return -ENOMEM; @@ -711,7 +711,7 @@ static int qca807x_probe(struct phy_device *phydev) shared_priv = phy_package_get_priv(phydev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/qcom/qca808x.c b/drivers/net/phy/qcom/qca808x.c index bab26e4c61408c..59084c03e7a95d 100644 --- a/drivers/net/phy/qcom/qca808x.c +++ b/drivers/net/phy/qcom/qca808x.c @@ -186,7 +186,7 @@ static int qca808x_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct qca808x_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/qcom/qca83xx.c b/drivers/net/phy/qcom/qca83xx.c index 2c4d085bacdbad..1528378b478fc0 100644 --- a/drivers/net/phy/qcom/qca83xx.c +++ b/drivers/net/phy/qcom/qca83xx.c @@ -83,7 +83,7 @@ static int qca83xx_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct qca83xx_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index 4927ee838de219..ca2d515b77b36b 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -407,7 +407,7 @@ static int rtl8261x_probe(struct phy_device *phydev) struct rtl8261x_priv *priv; int sub_phy_id, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -737,7 +737,7 @@ static int rtl821x_probe(struct phy_device *phydev) struct device *dev = &phydev->mdio.dev; struct rtl821x_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c index 48487149c22528..c7c9b2eed20c9a 100644 --- a/drivers/net/phy/smsc.c +++ b/drivers/net/phy/smsc.c @@ -661,7 +661,7 @@ int smsc_phy_probe(struct phy_device *phydev) struct smsc_phy_priv *priv; struct clk *refclk; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 2024d8ef36d98b..21a99acd21c8a9 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -89,7 +89,7 @@ static int xgmiitorgmii_probe(struct mdio_device *mdiodev) struct gmii2rgmii *priv; struct clk *clkin; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/xpowers/ac200.c b/drivers/net/phy/xpowers/ac200.c index afdd2a3dfbe41d..3718878e3994a4 100644 --- a/drivers/net/phy/xpowers/ac200.c +++ b/drivers/net/phy/xpowers/ac200.c @@ -221,7 +221,7 @@ ac200_ephy_ctl_create(struct phy_device *phydev, struct clk *clk; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); priv->dev = dev; diff --git a/drivers/net/phy/xpowers/ac300.c b/drivers/net/phy/xpowers/ac300.c index aa560432a14c9c..37e40c16cece6c 100644 --- a/drivers/net/phy/xpowers/ac300.c +++ b/drivers/net/phy/xpowers/ac300.c @@ -325,7 +325,7 @@ ac300_ephy_ctl_create(struct phy_device *phydev, u8 bgs_effuse_code; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); if (phydev->mdio.addr > FIELD_MAX(AC300_PACKAGE_PHY_ADDR_MASK)) diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c index d19ba6d8069a4a..cee6c7ff0278e3 100644 --- a/drivers/net/phy/xpowers/acx00.c +++ b/drivers/net/phy/xpowers/acx00.c @@ -318,7 +318,7 @@ static int acx00_ephy_probe(struct phy_device *phydev) if (!dev->of_node) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c index 209de9cec849aa..7958f5741463a2 100644 --- a/drivers/net/pse-pd/pd692x0.c +++ b/drivers/net/pse-pd/pd692x0.c @@ -944,12 +944,11 @@ pd692x0_register_manager_regulator(struct device *dev, char *reg_name, struct regulator_desc *rdesc; struct regulator_dev *rdev; - rinit_data = devm_kzalloc(dev, sizeof(*rinit_data), - GFP_KERNEL); + rinit_data = devm_kzalloc_obj(dev, *rinit_data); if (!rinit_data) return ERR_PTR(-ENOMEM); - rdesc = devm_kzalloc(dev, sizeof(*rdesc), GFP_KERNEL); + rdesc = devm_kzalloc_obj(dev, *rdesc); if (!rdesc) return ERR_PTR(-ENOMEM); @@ -1263,8 +1262,8 @@ static int pd692x0_setup_pi_matrix(struct pse_controller_dev *pcdev) if (!manager) return -ENOMEM; - port_matrix = devm_kcalloc(&priv->client->dev, PD692X0_MAX_PIS, - sizeof(*port_matrix), GFP_KERNEL); + port_matrix = devm_kzalloc_objs(&priv->client->dev, *port_matrix, + PD692X0_MAX_PIS); if (!port_matrix) { ret = -ENOMEM; goto err_free_manager; @@ -1775,7 +1774,7 @@ static int pd692x0_i2c_probe(struct i2c_client *client) return -ENXIO; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index a5e6d7b26b9fd7..a3d4a3d7e52574 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -835,12 +835,11 @@ devm_pse_pi_regulator_register(struct pse_controller_dev *pcdev, struct regulator_desc *rdesc; struct regulator_dev *rdev; - rinit_data = devm_kzalloc(pcdev->dev, sizeof(*rinit_data), - GFP_KERNEL); + rinit_data = devm_kzalloc_obj(pcdev->dev, *rinit_data); if (!rinit_data) return -ENOMEM; - rdesc = devm_kzalloc(pcdev->dev, sizeof(*rdesc), GFP_KERNEL); + rdesc = devm_kzalloc_obj(pcdev->dev, *rdesc); if (!rdesc) return -ENOMEM; @@ -922,7 +921,7 @@ static struct pse_power_domain *devm_pse_alloc_pw_d(struct device *dev) struct pse_power_domain *pw_d; int index, ret; - pw_d = devm_kzalloc(dev, sizeof(*pw_d), GFP_KERNEL); + pw_d = devm_kzalloc_obj(dev, *pw_d); if (!pw_d) return ERR_PTR(-ENOMEM); @@ -1320,7 +1319,7 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, if (!d || !d->map_event || !d->name) return -EINVAL; - h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL); + h = devm_kzalloc_obj(dev, *h); if (!h) return -ENOMEM; @@ -1336,8 +1335,7 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, snprintf(irq_name, irq_name_len, "pse-%s:%s", dev_name(pcdev->dev), d->name); - h->notifs = devm_kcalloc(dev, pcdev->nr_lines, - sizeof(*h->notifs), GFP_KERNEL); + h->notifs = devm_kzalloc_objs(dev, *h->notifs, pcdev->nr_lines); if (!h->notifs) return -ENOMEM; diff --git a/drivers/net/pse-pd/pse_regulator.c b/drivers/net/pse-pd/pse_regulator.c index 6ce6773fff3104..87628044738c53 100644 --- a/drivers/net/pse-pd/pse_regulator.c +++ b/drivers/net/pse-pd/pse_regulator.c @@ -97,7 +97,7 @@ pse_reg_probe(struct platform_device *pdev) struct pse_reg_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/pse-pd/realtek-pse-mcu-i2c.c b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c index bbded772eddfcd..16df566eb33583 100644 --- a/drivers/net/pse-pd/realtek-pse-mcu-i2c.c +++ b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c @@ -115,7 +115,7 @@ static int rtpse_mcu_i2c_probe(struct i2c_client *client) "SMBus MCU protocol requires SMBus I2C-block support\n"); } - pse = devm_kzalloc(dev, sizeof(*pse), GFP_KERNEL); + pse = devm_kzalloc_obj(dev, *pse); if (!pse) return -ENOMEM; diff --git a/drivers/net/pse-pd/realtek-pse-mcu-uart.c b/drivers/net/pse-pd/realtek-pse-mcu-uart.c index 9baa17d8d31fa2..439d9ca6744cfb 100644 --- a/drivers/net/pse-pd/realtek-pse-mcu-uart.c +++ b/drivers/net/pse-pd/realtek-pse-mcu-uart.c @@ -109,7 +109,7 @@ static int rtpse_mcu_uart_probe(struct serdev_device *serdev) unsigned int baud; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/net/pse-pd/si3474.c b/drivers/net/pse-pd/si3474.c index 35152d462e82db..c18df3c2ceb6e9 100644 --- a/drivers/net/pse-pd/si3474.c +++ b/drivers/net/pse-pd/si3474.c @@ -497,7 +497,7 @@ static int si3474_i2c_probe(struct i2c_client *client) return -ENXIO; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 8a3bbd623412b0..244ce596d845ca 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -1445,7 +1445,7 @@ static int tps23881_i2c_probe(struct i2c_client *client) if (!info) return -EINVAL; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index 957cc7885d2fbd..cfb833c307c14f 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -1365,11 +1365,8 @@ static int team_port_add(struct team *team, struct net_device *port_dev, /* set allmulti level to new slave */ if (dev->flags & IFF_ALLMULTI) { err = dev_set_allmulti(port_dev, 1); - if (err) { - if (dev->flags & IFF_PROMISC) - dev_set_promiscuity(port_dev, -1); + if (err) goto err_set_slave_allmulti; - } } err = team_dev_type_check_change(dev, port_dev); @@ -1397,7 +1394,11 @@ static int team_port_add(struct team *team, struct net_device *port_dev, return 0; err_set_dev_type: + if (dev->flags & IFF_ALLMULTI) + dev_set_allmulti(port_dev, -1); err_set_slave_allmulti: + if (dev->flags & IFF_PROMISC) + dev_set_promiscuity(port_dev, -1); err_set_slave_promisc: __team_option_inst_del_port(team, port); diff --git a/drivers/net/tun.c b/drivers/net/tun.c index dcec7311e6011f..86fd44e1075506 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -615,7 +615,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean) } synchronize_net(); - tun_flow_delete_by_queue(tun, tun->numqueues + 1); + tun_flow_delete_by_queue(tun, tun->numqueues); /* Drop read queue */ tun_queue_purge(tfile); spin_lock_bh(&ntfile->tx_ring.consumer_lock); @@ -1500,6 +1500,12 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile, if (!skb) return ERR_PTR(-ENOMEM); + /* An skb recycled by napi_reuse_skb() keeps the protocol of a + * previous frame. eth_type_trans() sets it after the virtio + * header checks, which must not see a stale one. + */ + skb->protocol = 0; + linear = iov_iter_single_seg_count(it); err = __skb_grow(skb, linear); if (err) @@ -1944,7 +1950,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, break; } - if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) { + if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr, + (tun->flags & TUN_TYPE_MASK) == IFF_TAP)) { atomic_long_inc(&tun->rx_frame_errors); err = -EINVAL; goto free_skb; @@ -2621,7 +2628,11 @@ static int tun_xdp_one(struct tun_struct *tun, tnl_hdr = (struct virtio_net_hdr_v1_hash_tunnel *)gso; skb->dev = tun->dev; skb_set_network_header(skb, ETH_HLEN); - if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr)) { + /* Frames always start with an Ethernet header here, as the + * eth_type_trans() call below expects. + */ + if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr, + true)) { atomic_long_inc(&tun->rx_frame_errors); kfree_skb(skb); ret = -EINVAL; @@ -3362,6 +3373,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, netif_info(tun, drv, tun->dev, "Linktype set failed because interface is up\n"); ret = -EBUSY; + } else if ((unsigned short)arg == ARPHRD_IEEE802154 || + (unsigned short)arg == ARPHRD_IEEE802154_MONITOR || + (unsigned short)arg == ARPHRD_6LOWPAN) { + ret = -EINVAL; } else { ret = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, tun->dev); diff --git a/drivers/net/tun_vnet.h b/drivers/net/tun_vnet.h index f4c652b1fa44d8..3364e08dd6e088 100644 --- a/drivers/net/tun_vnet.h +++ b/drivers/net/tun_vnet.h @@ -197,9 +197,10 @@ static inline netdev_features_t tun_vnet_hdr_guest_features(int vnet_hdr_sz) static inline int tun_vnet_hdr_tnl_to_skb(unsigned int flags, netdev_features_t features, struct sk_buff *skb, - const struct virtio_net_hdr_v1_hash_tunnel *hdr) + const struct virtio_net_hdr_v1_hash_tunnel *hdr, + bool has_eth) { - return virtio_net_hdr_tnl_to_skb(skb, hdr, + return virtio_net_hdr_tnl_to_skb(skb, hdr, has_eth, features & NETIF_F_GSO_UDP_TUNNEL, features & NETIF_F_GSO_UDP_TUNNEL_CSUM, tun_vnet_is_little_endian(flags)); diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c index 51bf887e352039..ad9f0f5e4438e9 100644 --- a/drivers/net/usb/asix_common.c +++ b/drivers/net/usb/asix_common.c @@ -626,8 +626,7 @@ int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; @@ -666,8 +665,7 @@ int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index 293ef80c4e302e..2729b8def9d444 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -832,7 +832,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) u8 buf[ETH_ALEN] = {0}; int ret, i; - priv = devm_kzalloc(&dev->udev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->udev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index c179e231908173..2279dbbcdb4ddc 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -555,8 +555,7 @@ ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; @@ -598,8 +597,7 @@ ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, first_word = eeprom->offset >> 1; last_word = (eeprom->offset + eeprom->len - 1) >> 1; - eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1); if (!eeprom_buff) return -ENOMEM; diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index 19db5a668dcbc7..e92dc7f011ea73 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -1125,7 +1125,7 @@ static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp16(struct cdc_ncm_ctx *ctx, struct s cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); /* verify that there is room for the NDP and the datagram (reserve) */ - if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) + if (skb->len + reserve + ctx->max_ndp_size > ctx->tx_curr_size) return NULL; /* link to it */ @@ -1180,7 +1180,7 @@ static struct usb_cdc_ncm_ndp32 *cdc_ncm_ndp32(struct cdc_ncm_ctx *ctx, struct s cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size); /* verify that there is room for the NDP and the datagram (reserve) */ - if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size) + if (skb->len + reserve + ctx->max_ndp_size > ctx->tx_curr_size) return NULL; /* link to it */ diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 181e8c087655c3..f7126d802b4bc1 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -604,7 +604,7 @@ static int lan78xx_read_reg(struct lan78xx_net *dev, u32 index, u32 *data) if (test_bit(EVENT_DEV_DISCONNECT, &dev->flags)) return -ENODEV; - buf = kmalloc(sizeof(u32), GFP_KERNEL); + buf = kmalloc_obj(u32); if (!buf) return -ENOMEM; @@ -634,7 +634,7 @@ static int lan78xx_write_reg(struct lan78xx_net *dev, u32 index, u32 data) if (test_bit(EVENT_DEV_DISCONNECT, &dev->flags)) return -ENODEV; - buf = kmalloc(sizeof(u32), GFP_KERNEL); + buf = kmalloc_obj(u32); if (!buf) return -ENOMEM; @@ -4593,13 +4593,12 @@ static void lan78xx_disconnect(struct usb_interface *intf) net = dev->net; + unregister_netdev(net); + rtnl_lock(); - phylink_stop(dev->phylink); phylink_disconnect_phy(dev->phylink); rtnl_unlock(); - unregister_netdev(net); - timer_shutdown_sync(&dev->stat_monitor); set_bit(EVENT_DEV_DISCONNECT, &dev->flags); cancel_delayed_work_sync(&dev->wq); @@ -5371,6 +5370,12 @@ static int lan78xx_resume(struct usb_interface *intf) out: mutex_unlock(&dev->dev_mutex); + if (!ret && dev_open) { + rtnl_lock(); + phylink_resume(dev->phylink); + rtnl_unlock(); + } + return ret; } @@ -5385,15 +5390,7 @@ static int lan78xx_reset_resume(struct usb_interface *intf) if (ret < 0) return ret; - ret = lan78xx_resume(intf); - if (ret < 0) - return ret; - - rtnl_lock(); - phylink_resume(dev->phylink); - rtnl_unlock(); - - return 0; + return lan78xx_resume(intf); } static const struct usb_device_id products[] = { diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 3eca92d3dc60df..a61842b2585bfa 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1377,9 +1377,10 @@ static int veth_set_channels(struct net_device *dev, * to identify the range we have to disable */ veth_disable_range_safe(dev, new_rx_count, old_rx_count); - netif_carrier_on(dev); - if (peer) + if (peer && (peer->flags & IFF_UP)) { + netif_carrier_on(dev); netif_carrier_on(peer); + } } /* update XDP supported features */ diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index dd2c41ef6fbe72..ed20e76fbc4c79 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2533,7 +2533,7 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * skb->dev = dev; skb_set_network_header(skb, ETH_HLEN); - if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, vi->rx_tnl, + if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, true, vi->rx_tnl, vi->rx_tnl_csum, virtio_is_little_endian(vi->vdev))) { net_warn_ratelimited("%s: bad gso: type: %x, size: %u, flags %x tunnel %d tnl csum %d\n", diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 22353909977868..d11028b374721c 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1005,12 +1005,6 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, return -EOPNOTSUPP; } - if (rcu_access_pointer(f->nh) && - !(state & (NUD_PERMANENT | NUD_NOARP))) { - NL_SET_ERR_MSG(extack, "Cannot make a nexthop fdb dynamic"); - return -EOPNOTSUPP; - } - /* Do not allow an externally learned entry to take over an entry added * by the user. */ @@ -1274,11 +1268,6 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], if (err) return err; - if (nhid && !(ndm->ndm_state & (NUD_PERMANENT | NUD_NOARP))) { - NL_SET_ERR_MSG(extack, "A nexthop fdb cannot be dynamic"); - return -EINVAL; - } - cfg = rtnl_dereference(vxlan->cfg); if (cfg->remote_ip.sa.sa_family != ip.sa.sa_family) return -EAFNOSUPPORT; @@ -2947,6 +2936,9 @@ static void vxlan_cleanup(struct timer_list *t) if (f->flags & NTF_EXT_LEARNED) continue; + if (rcu_access_pointer(f->nh)) + continue; + timeout = READ_ONCE(f->updated) + cfg->age_interval * HZ; if (time_before_eq(timeout, jiffies)) { spin_lock(&vxlan->hash_lock); diff --git a/drivers/net/wan/framer/pef2256/pef2256.c b/drivers/net/wan/framer/pef2256/pef2256.c index 6938316bf82bfe..9980544a1c5b3b 100644 --- a/drivers/net/wan/framer/pef2256/pef2256.c +++ b/drivers/net/wan/framer/pef2256/pef2256.c @@ -713,7 +713,7 @@ static int pef2256_probe(struct platform_device *pdev) int ret; int irq; - pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); + pef2256 = devm_kzalloc_obj(&pdev->dev, *pef2256); if (!pef2256) return -ENOMEM; diff --git a/drivers/net/wan/fsl_qmc_hdlc.c b/drivers/net/wan/fsl_qmc_hdlc.c index e74f87940c4f1c..43982c7e6f68a4 100644 --- a/drivers/net/wan/fsl_qmc_hdlc.c +++ b/drivers/net/wan/fsl_qmc_hdlc.c @@ -712,7 +712,7 @@ static int qmc_hdlc_probe(struct platform_device *pdev) hdlc_device *hdlc; int ret; - qmc_hdlc = devm_kzalloc(dev, sizeof(*qmc_hdlc), GFP_KERNEL); + qmc_hdlc = devm_kzalloc_obj(dev, *qmc_hdlc); if (!qmc_hdlc) return -ENOMEM; diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c index 7f4645ff90aa92..47bc6f5788c16b 100644 --- a/drivers/net/wan/ixp4xx_hss.c +++ b/drivers/net/wan/ixp4xx_hss.c @@ -1416,7 +1416,7 @@ static int ixp4xx_hss_probe(struct platform_device *pdev) np = dev->of_node; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 7c2939cbde5f05..a749ae582b0a49 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -2985,6 +2985,7 @@ int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode, clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags); ar->running_fw = fw; + ar->thermal.broken = false; if (!test_bit(ATH10K_FW_FEATURE_NON_BMI, ar->running_fw->fw_file.fw_features)) { diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c index 65e941b5275175..3d866dd545512d 100644 --- a/drivers/net/wireless/ath/ath10k/sdio.c +++ b/drivers/net/wireless/ath/ath10k/sdio.c @@ -2549,8 +2549,7 @@ static int ath10k_sdio_probe(struct sdio_func *func, ar_sdio = ath10k_sdio_priv(ar); ar_sdio->irq_data.irq_proc_reg = - devm_kzalloc(ar->dev, sizeof(struct ath10k_sdio_irq_proc_regs), - GFP_KERNEL); + devm_kzalloc_obj(ar->dev, struct ath10k_sdio_irq_proc_regs); if (!ar_sdio->irq_data.irq_proc_reg) { ret = -ENOMEM; goto err_core_destroy; @@ -2563,8 +2562,7 @@ static int ath10k_sdio_probe(struct sdio_func *func, } ar_sdio->irq_data.irq_en_reg = - devm_kzalloc(ar->dev, sizeof(struct ath10k_sdio_irq_enable_regs), - GFP_KERNEL); + devm_kzalloc_obj(ar->dev, struct ath10k_sdio_irq_enable_regs); if (!ar_sdio->irq_data.irq_en_reg) { ret = -ENOMEM; goto err_core_destroy; diff --git a/drivers/net/wireless/ath/ath10k/snoc.c b/drivers/net/wireless/ath/ath10k/snoc.c index 8f171ab6f4de85..356d9c61d5a7aa 100644 --- a/drivers/net/wireless/ath/ath10k/snoc.c +++ b/drivers/net/wireless/ath/ath10k/snoc.c @@ -1816,8 +1816,8 @@ static int ath10k_snoc_probe(struct platform_device *pdev) ar_snoc->num_vregs = 1; } - ar_snoc->vregs = devm_kcalloc(&pdev->dev, ar_snoc->num_vregs, - sizeof(*ar_snoc->vregs), GFP_KERNEL); + ar_snoc->vregs = devm_kzalloc_objs(&pdev->dev, *ar_snoc->vregs, + ar_snoc->num_vregs); if (!ar_snoc->vregs) { ret = -ENOMEM; goto err_free_irq; @@ -1831,8 +1831,8 @@ static int ath10k_snoc_probe(struct platform_device *pdev) goto err_free_irq; ar_snoc->num_clks = ARRAY_SIZE(ath10k_clocks); - ar_snoc->clks = devm_kcalloc(&pdev->dev, ar_snoc->num_clks, - sizeof(*ar_snoc->clks), GFP_KERNEL); + ar_snoc->clks = devm_kzalloc_objs(&pdev->dev, *ar_snoc->clks, + ar_snoc->num_clks); if (!ar_snoc->clks) { ret = -ENOMEM; goto err_free_irq; diff --git a/drivers/net/wireless/ath/ath10k/swap.c b/drivers/net/wireless/ath/ath10k/swap.c index 7198a386f2fbeb..03a771c6da9e50 100644 --- a/drivers/net/wireless/ath/ath10k/swap.c +++ b/drivers/net/wireless/ath/ath10k/swap.c @@ -100,7 +100,7 @@ ath10k_swap_code_seg_alloc(struct ath10k *ar, size_t swap_bin_len) return NULL; } - seg_info = devm_kzalloc(ar->dev, sizeof(*seg_info), GFP_KERNEL); + seg_info = devm_kzalloc_obj(ar->dev, *seg_info); if (!seg_info) return NULL; diff --git a/drivers/net/wireless/ath/ath10k/thermal.c b/drivers/net/wireless/ath/ath10k/thermal.c index 9bb486f8e92078..9ff7de0abd1297 100644 --- a/drivers/net/wireless/ath/ath10k/thermal.c +++ b/drivers/net/wireless/ath/ath10k/thermal.c @@ -75,6 +75,12 @@ static ssize_t ath10k_thermal_show_temp(struct device *dev, goto out; } + /* Don't stall every read on firmware that never answers */ + if (ar->thermal.broken) { + ret = -EOPNOTSUPP; + goto out; + } + reinit_completion(&ar->thermal.wmi_sync); ret = ath10k_wmi_pdev_get_temperature(ar); if (ret) { @@ -90,7 +96,8 @@ static ssize_t ath10k_thermal_show_temp(struct device *dev, time_left = wait_for_completion_timeout(&ar->thermal.wmi_sync, ATH10K_THERMAL_SYNC_TIMEOUT_HZ); if (!time_left) { - ath10k_warn(ar, "failed to synchronize thermal read\n"); + ath10k_warn(ar, "failed to synchronize thermal read, not asking again until the firmware restarts\n"); + ar->thermal.broken = true; ret = -ETIMEDOUT; goto out; } diff --git a/drivers/net/wireless/ath/ath10k/thermal.h b/drivers/net/wireless/ath/ath10k/thermal.h index 1f4de9fbf2b30b..d1fb5b958c37c1 100644 --- a/drivers/net/wireless/ath/ath10k/thermal.h +++ b/drivers/net/wireless/ath/ath10k/thermal.h @@ -19,6 +19,8 @@ struct ath10k_thermal { /* protected by conf_mutex */ u32 throttle_state; u32 quiet_period; + /* the running firmware did not answer a temperature request */ + bool broken; /* temperature value in Celsius degree * protected by data_lock */ diff --git a/drivers/net/wireless/ath/ath12k/ahb.c b/drivers/net/wireless/ath/ath12k/ahb.c index 2c55aae06dd06d..e5bbfca2b2ac0f 100644 --- a/drivers/net/wireless/ath/ath12k/ahb.c +++ b/drivers/net/wireless/ath/ath12k/ahb.c @@ -602,8 +602,8 @@ static int ath12k_ahb_ext_grp_napi_poll(struct napi_struct *napi, int budget) work_done = ath12k_dp_service_srng(dp, irq_grp, budget); if (work_done < budget) { - napi_complete_done(napi, work_done); - ath12k_ahb_ext_grp_enable(irq_grp); + if (likely(napi_complete_done(napi, work_done))) + ath12k_ahb_ext_grp_enable(irq_grp); } if (work_done > budget) @@ -619,9 +619,10 @@ static irqreturn_t ath12k_ahb_ext_interrupt_handler(int irq, void *arg) /* last interrupt received for this group */ irq_grp->timestamp = jiffies; - ath12k_ahb_ext_grp_disable(irq_grp); - - napi_schedule(&irq_grp->napi); + if (napi_schedule_prep(&irq_grp->napi)) { + ath12k_ahb_ext_grp_disable(irq_grp); + __napi_schedule(&irq_grp->napi); + } return IRQ_HANDLED; } diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 25987bc58556e7..353fb9c5a69d64 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -2062,7 +2062,8 @@ static struct ath12k_hw_group *ath12k_core_hw_group_assign(struct ath12k_base *a goto invalid_group; } - ab->device_id = ag->num_probed++; + ag->num_probed++; + ab->device_id = wsi->index; ag->ab[ab->device_id] = ab; ab->ag = ag; diff --git a/drivers/net/wireless/ath/ath12k/dp_mon.c b/drivers/net/wireless/ath/ath12k/dp_mon.c index 709507d44d8e51..ae14e118fe3649 100644 --- a/drivers/net/wireless/ath/ath12k/dp_mon.c +++ b/drivers/net/wireless/ath/ath12k/dp_mon.c @@ -186,7 +186,7 @@ ath12k_dp_mon_fill_rx_rate(struct ath12k_pdev_dp *dp_pdev, } static void ath12k_dp_mon_rx_msdus_set_payload(struct ath12k_base *ab, - struct sk_buff *head_msdu, + struct sk_buff *msdu, struct sk_buff *tail_msdu) { u32 rx_pkt_offset, l2_hdr_offset, total_offset; @@ -200,7 +200,7 @@ static void ath12k_dp_mon_rx_msdus_set_payload(struct ath12k_base *ab, else total_offset = rx_pkt_offset + l2_hdr_offset; - skb_pull(head_msdu, total_offset); + skb_pull(msdu, total_offset); } struct sk_buff * @@ -261,7 +261,7 @@ ath12k_dp_mon_rx_merg_msdus(struct ath12k_pdev_dp *dp_pdev, head_frag_list = NULL; while (msdu) { - ath12k_dp_mon_rx_msdus_set_payload(ab, head_msdu, tail_msdu); + ath12k_dp_mon_rx_msdus_set_payload(ab, msdu, tail_msdu); if (!head_frag_list) head_frag_list = msdu; @@ -296,7 +296,7 @@ ath12k_dp_mon_rx_merg_msdus(struct ath12k_pdev_dp *dp_pdev, msdu = head_msdu; while (msdu) { - ath12k_dp_mon_rx_msdus_set_payload(ab, head_msdu, tail_msdu); + ath12k_dp_mon_rx_msdus_set_payload(ab, msdu, tail_msdu); if (qos_pkt) { dest = skb_push(msdu, sizeof(__le16)); if (!dest) diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index 01f8c6572f657e..7872e7cb3c0657 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -3366,6 +3366,7 @@ static void ath12k_peer_assoc_h_eht(struct ath12k *ar, u32 *rx_mcs, *tx_mcs; u16 *eht_mcs_mask; u8 max_nss = 0; + u8 mcs15; lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); @@ -3416,6 +3417,16 @@ static void ath12k_peer_assoc_h_eht(struct ath12k *ar, memcpy(arg->peer_eht_cap_phy, eht_cap->eht_cap_elem.phy_cap_info, sizeof(eht_cap->eht_cap_elem.phy_cap_info)); + /* + * Firmware rate control enables EHT-MCS15 based only on the peer's + * MCS15 support bits, so keep only the ones we support ourselves. + */ + mcs15 = u8_get_bits(eht_cap->eht_cap_elem.phy_cap_info[6] & + own_eht_cap->eht_cap_elem.phy_cap_info[6], + IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK); + u8p_replace_bits(&((u8 *)arg->peer_eht_cap_phy)[6], mcs15, + IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK); + rx_mcs = arg->peer_eht_rx_mcs_set; tx_mcs = arg->peer_eht_tx_mcs_set; @@ -7845,7 +7856,7 @@ int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, ath12k_hw_warn(ah, "failed to verify assoc link setting with link id %u\n", link_id); ret = -EINVAL; - goto exit; + goto free_unassign_link; } arsta->is_assoc_link = true; @@ -7903,7 +7914,7 @@ int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, if (old_state == IEEE80211_STA_NOTEXIST && new_state == IEEE80211_STA_NONE) - goto peer_delete; + goto free_unassign_link; else goto exit; } @@ -7943,6 +7954,8 @@ int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, ret = 0; goto exit; +free_unassign_link: + ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); peer_delete: ath12k_dp_peer_delete(&ah->dp_hw, sta->addr, sta); ml_peer_id_clear: diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c index 7cf00fda996f3a..7ea7559e882c2a 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c @@ -402,32 +402,32 @@ static void ath12k_hal_extract_rx_desc_data_qcc2072(struct hal_rx_desc_data *rx_ rx_desc_data->is_last_msdu = ath12k_hal_rx_desc_get_last_msdu_qcc2072(ldesc); rx_desc_data->l3_pad_bytes = ath12k_hal_rx_desc_get_l3_pad_bytes_qcc2072(ldesc); rx_desc_data->enctype = ath12k_hal_rx_desc_get_encrypt_type_qcc2072(rx_desc); - rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_qcc2072(rx_desc); + rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_qcc2072(ldesc); rx_desc_data->mesh_ctrl_present = - ath12k_hal_rx_desc_get_mesh_ctl_qcc2072(rx_desc); + ath12k_hal_rx_desc_get_mesh_ctl_qcc2072(ldesc); rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_qcc2072(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_qcc2072(rx_desc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcc2072(rx_desc); rx_desc_data->msdu_len = ath12k_hal_rx_desc_get_msdu_len_qcc2072(ldesc); - rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_qcc2072(rx_desc); - rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_qcc2072(rx_desc); - rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_qcc2072(rx_desc); - rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_qcc2072(rx_desc); - rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_qcc2072(rx_desc); - rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_qcc2072(rx_desc); - rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_qcc2072(rx_desc); - rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_qcc2072(rx_desc)); + rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_qcc2072(ldesc); + rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_qcc2072(ldesc); + rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_qcc2072(ldesc); + rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_qcc2072(ldesc); + rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_qcc2072(ldesc); + rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_qcc2072(ldesc); + rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_qcc2072(ldesc); + rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_qcc2072(ldesc)); rx_desc_data->tid = ath12k_hal_rx_desc_get_mpdu_tid_qcc2072(rx_desc); rx_desc_data->peer_id = ath12k_hal_rx_desc_get_mpdu_peer_id_qcc2072(rx_desc); rx_desc_data->addr2_present = ath12k_hal_rx_desc_mac_addr2_valid_qcc2072(rx_desc); rx_desc_data->addr2 = ath12k_hal_rx_desc_mpdu_start_addr2_qcc2072(rx_desc); - rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_qcc2072(rx_desc); + rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_qcc2072(ldesc); rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_qcc2072(ldesc); - rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcc2072(rx_desc); - rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcc2072(rx_desc); - rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcc2072(rx_desc); - rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcc2072(rx_desc); + rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcc2072(ldesc); + rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcc2072(ldesc); + rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcc2072(ldesc); + rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcc2072(ldesc); } static int ath12k_hal_srng_create_config_qcc2072(struct ath12k_hal *hal) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c index 052b59265af855..355cf50d2785f4 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c @@ -922,32 +922,32 @@ void ath12k_hal_extract_rx_desc_data_qcn9274(struct hal_rx_desc_data *rx_desc_da rx_desc_data->is_last_msdu = ath12k_hal_rx_desc_get_last_msdu_qcn9274(ldesc); rx_desc_data->l3_pad_bytes = ath12k_hal_rx_desc_get_l3_pad_bytes_qcn9274(ldesc); rx_desc_data->enctype = ath12k_hal_rx_desc_get_encrypt_type_qcn9274(rx_desc); - rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_qcn9274(rx_desc); + rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_qcn9274(ldesc); rx_desc_data->mesh_ctrl_present = - ath12k_hal_rx_desc_get_mesh_ctl_qcn9274(rx_desc); + ath12k_hal_rx_desc_get_mesh_ctl_qcn9274(ldesc); rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_qcn9274(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_qcn9274(rx_desc); - rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_qcn9274(rx_desc); - rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_qcn9274(rx_desc); + rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_qcn9274(ldesc); + rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_qcn9274(ldesc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_qcn9274(rx_desc); rx_desc_data->msdu_len = ath12k_hal_rx_desc_get_msdu_len_qcn9274(ldesc); - rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_qcn9274(rx_desc); - rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_qcn9274(rx_desc); - rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_qcn9274(rx_desc); - rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_qcn9274(rx_desc); - rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_qcn9274(rx_desc); - rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_qcn9274(rx_desc)); - rx_desc_data->tid = ath12k_hal_rx_desc_get_mpdu_tid_qcn9274(rx_desc); + rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_qcn9274(ldesc); + rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_qcn9274(ldesc); + rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_qcn9274(ldesc); + rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_qcn9274(ldesc); + rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_qcn9274(ldesc); + rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_qcn9274(ldesc)); + rx_desc_data->tid = ath12k_hal_rx_desc_get_mpdu_tid_qcn9274(ldesc); rx_desc_data->peer_id = ath12k_hal_rx_desc_get_mpdu_peer_id_qcn9274(rx_desc); rx_desc_data->addr2_present = ath12k_hal_rx_desc_mac_addr2_valid_qcn9274(rx_desc); rx_desc_data->addr2 = ath12k_hal_rx_desc_mpdu_start_addr2_qcn9274(rx_desc); - rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_qcn9274(rx_desc); + rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_qcn9274(ldesc); rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_qcn9274(ldesc); - rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcn9274(rx_desc); - rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcn9274(rx_desc); - rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcn9274(rx_desc); - rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcn9274(rx_desc); + rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcn9274(ldesc); + rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcn9274(ldesc); + rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcn9274(ldesc); + rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcn9274(ldesc); } static u16 ath12k_hal_reo_status_dec_tlv_hdr_qcn9274(void *tlv, void **desc) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c index 61be8443e46ee0..abe982faeb2b73 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c @@ -604,32 +604,32 @@ void ath12k_hal_extract_rx_desc_data_wcn7850(struct hal_rx_desc_data *rx_desc_da rx_desc_data->is_last_msdu = ath12k_hal_rx_desc_get_last_msdu_wcn7850(ldesc); rx_desc_data->l3_pad_bytes = ath12k_hal_rx_desc_get_l3_pad_bytes_wcn7850(ldesc); rx_desc_data->enctype = ath12k_hal_rx_desc_get_encrypt_type_wcn7850(rx_desc); - rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_wcn7850(rx_desc); + rx_desc_data->decap_type = ath12k_hal_rx_desc_get_decap_type_wcn7850(ldesc); rx_desc_data->mesh_ctrl_present = - ath12k_hal_rx_desc_get_mesh_ctl_wcn7850(rx_desc); + ath12k_hal_rx_desc_get_mesh_ctl_wcn7850(ldesc); rx_desc_data->seq_ctl_valid = ath12k_hal_rx_desc_get_mpdu_seq_ctl_vld_wcn7850(rx_desc); rx_desc_data->fc_valid = ath12k_hal_rx_desc_get_mpdu_fc_valid_wcn7850(rx_desc); rx_desc_data->seq_no = ath12k_hal_rx_desc_get_mpdu_start_seq_no_wcn7850(rx_desc); rx_desc_data->msdu_len = ath12k_hal_rx_desc_get_msdu_len_wcn7850(ldesc); - rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_wcn7850(rx_desc); - rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_wcn7850(rx_desc); - rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_wcn7850(rx_desc); - rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_wcn7850(rx_desc); - rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_wcn7850(rx_desc); - rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_wcn7850(rx_desc); - rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_wcn7850(rx_desc); - rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_wcn7850(rx_desc)); + rx_desc_data->sgi = ath12k_hal_rx_desc_get_msdu_sgi_wcn7850(ldesc); + rx_desc_data->is_from_ds = ath12k_wifi7_hal_rx_h_from_ds_wcn7850(ldesc); + rx_desc_data->is_to_ds = ath12k_wifi7_hal_rx_h_to_ds_wcn7850(ldesc); + rx_desc_data->rate_mcs = ath12k_hal_rx_desc_get_msdu_rate_mcs_wcn7850(ldesc); + rx_desc_data->bw = ath12k_hal_rx_desc_get_msdu_rx_bw_wcn7850(ldesc); + rx_desc_data->phy_meta_data = ath12k_hal_rx_desc_get_msdu_freq_wcn7850(ldesc); + rx_desc_data->pkt_type = ath12k_hal_rx_desc_get_msdu_pkt_type_wcn7850(ldesc); + rx_desc_data->nss = hweight8(ath12k_hal_rx_desc_get_msdu_nss_wcn7850(ldesc)); rx_desc_data->tid = ath12k_hal_rx_desc_get_mpdu_tid_wcn7850(rx_desc); rx_desc_data->peer_id = ath12k_hal_rx_desc_get_mpdu_peer_id_wcn7850(rx_desc); rx_desc_data->addr2_present = ath12k_hal_rx_desc_mac_addr2_valid_wcn7850(rx_desc); rx_desc_data->addr2 = ath12k_hal_rx_desc_mpdu_start_addr2_wcn7850(rx_desc); - rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_wcn7850(rx_desc); + rx_desc_data->is_mcbc = ath12k_hal_rx_desc_is_da_mcbc_wcn7850(ldesc); rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_wcn7850(ldesc); - rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_wcn7850(rx_desc); - rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_wcn7850(rx_desc); - rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_wcn7850(rx_desc); - rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_wcn7850(rx_desc); + rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_wcn7850(ldesc); + rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_wcn7850(ldesc); + rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_wcn7850(ldesc); + rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_wcn7850(ldesc); } int ath12k_hal_srng_create_config_wcn7850(struct ath12k_hal *hal) diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c index 66b2dee391559e..33297e96f01a2e 100644 --- a/drivers/net/wireless/ath/ath5k/phy.c +++ b/drivers/net/wireless/ath/ath5k/phy.c @@ -886,9 +886,7 @@ ath5k_hw_rfregs_init(struct ath5k_hw *ah, * ah->ah_rf_banks based on ah->ah_rf_banks_size * we set above */ if (ah->ah_rf_banks == NULL) { - ah->ah_rf_banks = kmalloc_array(ah->ah_rf_banks_size, - sizeof(u32), - GFP_KERNEL); + ah->ah_rf_banks = kmalloc_objs(u32, ah->ah_rf_banks_size); if (ah->ah_rf_banks == NULL) { ATH5K_ERR(ah, "out of memory\n"); return -ENOMEM; diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c index 65b7c68a92972b..c91560d559c512 100644 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c @@ -1047,7 +1047,7 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, n_channels = request->n_channels; - channels = kcalloc(n_channels, sizeof(u16), GFP_KERNEL); + channels = kzalloc_objs(u16, n_channels); if (channels == NULL) { ath6kl_warn("failed to set scan channels, scan all channels"); n_channels = 0; diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c index 83d993fff695eb..6170e37d020577 100644 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c @@ -925,7 +925,7 @@ int ar9003_paprd_create_curve(struct ath_hw *ah, memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain])); - buf = kmalloc_array(2 * 48, sizeof(u32), GFP_KERNEL); + buf = kmalloc_objs(u32, 2 * 48); if (!buf) return -ENOMEM; diff --git a/drivers/net/wireless/ath/ath9k/ath9k_pci_owl_loader.c b/drivers/net/wireless/ath/ath9k/ath9k_pci_owl_loader.c index b9ef34709202b2..e0578b101c6ea0 100644 --- a/drivers/net/wireless/ath/ath9k/ath9k_pci_owl_loader.c +++ b/drivers/net/wireless/ath/ath9k/ath9k_pci_owl_loader.c @@ -185,7 +185,7 @@ static int owl_probe(struct pci_dev *pdev, if (pci_enable_device(pdev)) return -EIO; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c index 0d6272ac0dac88..6578114a4019cf 100644 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c @@ -1098,11 +1098,8 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw, ath9k_htc_set_opmode(priv); - if ((priv->ah->opmode == NL80211_IFTYPE_AP) && - !test_bit(ATH_OP_ANI_RUN, &common->op_flags)) { + if (priv->ah->opmode == NL80211_IFTYPE_AP) ath9k_hw_set_tsfadjust(priv->ah, true); - ath9k_htc_start_ani(priv); - } ath_dbg(common, CONFIG, "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index); @@ -1554,6 +1551,9 @@ static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw, ath9k_htc_set_tsfadjust(priv, vif); priv->cur_beacon_conf.enable_beacon = 1; ath9k_htc_beacon_config(priv, vif); + if (priv->ah->opmode == NL80211_IFTYPE_AP && + !test_bit(ATH_OP_ANI_RUN, &common->op_flags)) + ath9k_htc_start_ani(priv); } if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) { diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c index e08ab73fcacb3d..10e819d1bff621 100644 --- a/drivers/net/wireless/ath/ath9k/hw.c +++ b/drivers/net/wireless/ath/ath9k/hw.c @@ -127,13 +127,13 @@ void ath9k_hw_read_array(struct ath_hw *ah, u32 array[][2], int size) u32 *tmp_reg_list, *tmp_data; int i; - tmp_reg_list = kmalloc_array(size, sizeof(u32), GFP_KERNEL); + tmp_reg_list = kmalloc_objs(u32, size); if (!tmp_reg_list) { dev_err(ah->dev, "%s: tmp_reg_list: alloc filed\n", __func__); return; } - tmp_data = kmalloc_array(size, sizeof(u32), GFP_KERNEL); + tmp_data = kmalloc_objs(u32, size); if (!tmp_data) { dev_err(ah->dev, "%s tmp_data: alloc filed\n", __func__); goto error_tmp_data; diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c index 2f0c4ef86b7e1f..b996b7c30da1a4 100644 --- a/drivers/net/wireless/ath/ath9k/init.c +++ b/drivers/net/wireless/ath/ath9k/init.c @@ -339,7 +339,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, if (is_tx) { struct ath_buf *bf; - bf = devm_kcalloc(sc->dev, sizeof(*bf), nbuf, GFP_KERNEL); + bf = devm_kzalloc_objs(sc->dev, *bf, nbuf); if (!bf) return -ENOMEM; @@ -369,7 +369,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, } else { struct ath_rxbuf *bf; - bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbuf, GFP_KERNEL); + bf = devm_kzalloc_objs(sc->dev, struct ath_rxbuf, nbuf); if (!bf) return -ENOMEM; @@ -662,7 +662,7 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc, int ret = 0, i; int csz = 0; - ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL); + ah = devm_kzalloc_obj(sc->dev, struct ath_hw); if (!ah) return -ENOMEM; diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c index 93b41a1bb2af06..1d1114444ba34a 100644 --- a/drivers/net/wireless/ath/ath9k/recv.c +++ b/drivers/net/wireless/ath/ath9k/recv.c @@ -211,7 +211,7 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP], ah->caps.rx_hp_qdepth); - bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbufs, GFP_KERNEL); + bf = devm_kzalloc_objs(sc->dev, struct ath_rxbuf, nbufs); if (!bf) return -ENOMEM; diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c index 61c7a1288743cb..27c4f69382a4bc 100644 --- a/drivers/net/wireless/ath/carl9170/main.c +++ b/drivers/net/wireless/ath/carl9170/main.c @@ -1927,8 +1927,8 @@ static int carl9170_parse_eeprom(struct ar9170 *ar) if (!bands) return -EINVAL; - ar->survey = devm_kcalloc(&ar->udev->dev, chans, - sizeof(struct survey_info), GFP_KERNEL); + ar->survey = devm_kzalloc_objs(&ar->udev->dev, struct survey_info, + chans); if (!ar->survey) return -ENOMEM; ar->num_channels = chans; diff --git a/drivers/net/wireless/broadcom/b43/debugfs.c b/drivers/net/wireless/broadcom/b43/debugfs.c index 173ef5db90fccf..c6d4a290418a99 100644 --- a/drivers/net/wireless/broadcom/b43/debugfs.c +++ b/drivers/net/wireless/broadcom/b43/debugfs.c @@ -5,7 +5,7 @@ debugfs driver debugging code - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43/dma.c b/drivers/net/wireless/broadcom/b43/dma.c index 05da6987a84507..be62144c524df9 100644 --- a/drivers/net/wireless/broadcom/b43/dma.c +++ b/drivers/net/wireless/broadcom/b43/dma.c @@ -5,7 +5,7 @@ DMA ringbuffer and descriptor allocation/management - Copyright (c) 2005, 2006 Michael Buesch + Copyright (c) 2005, 2006 Michael Buesch Some code in this file is derived from the b44.c driver Copyright (C) 2002 David S. Miller diff --git a/drivers/net/wireless/broadcom/b43/leds.c b/drivers/net/wireless/broadcom/b43/leds.c index bfe1be345844da..0e6447c33ee88e 100644 --- a/drivers/net/wireless/broadcom/b43/leds.c +++ b/drivers/net/wireless/broadcom/b43/leds.c @@ -6,7 +6,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005 Stefano Brivio - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch Copyright (c) 2005 Danny van Dyk Copyright (c) 2005 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/lo.c b/drivers/net/wireless/broadcom/b43/lo.c index f86e8969673fde..020d5af0ebdf38 100644 --- a/drivers/net/wireless/broadcom/b43/lo.c +++ b/drivers/net/wireless/broadcom/b43/lo.c @@ -7,7 +7,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005, 2006 Stefano Brivio - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch Copyright (c) 2005, 2006 Danny van Dyk Copyright (c) 2005, 2006 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/main.c b/drivers/net/wireless/broadcom/b43/main.c index 3825b6ad9f4f13..e4f76e638a8909 100644 --- a/drivers/net/wireless/broadcom/b43/main.c +++ b/drivers/net/wireless/broadcom/b43/main.c @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer Copyright (c) 2005 Stefano Brivio - Copyright (c) 2005-2009 Michael Buesch + Copyright (c) 2005-2009 Michael Buesch Copyright (c) 2005 Danny van Dyk Copyright (c) 2005 Andreas Jaggi Copyright (c) 2010-2011 Rafał Miłecki diff --git a/drivers/net/wireless/broadcom/b43/main.h b/drivers/net/wireless/broadcom/b43/main.h index d94ab86e849510..d59ec5a7579b2c 100644 --- a/drivers/net/wireless/broadcom/b43/main.h +++ b/drivers/net/wireless/broadcom/b43/main.h @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/phy_common.c b/drivers/net/wireless/broadcom/b43/phy_common.c index 285490f6f0a1d8..e132b9bbcbec27 100644 --- a/drivers/net/wireless/broadcom/b43/phy_common.c +++ b/drivers/net/wireless/broadcom/b43/phy_common.c @@ -6,7 +6,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005-2007 Stefano Brivio - Copyright (c) 2005-2008 Michael Buesch + Copyright (c) 2005-2008 Michael Buesch Copyright (c) 2005, 2006 Danny van Dyk Copyright (c) 2005, 2006 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/phy_g.c b/drivers/net/wireless/broadcom/b43/phy_g.c index 9e292a3496743f..3af50a755cf752 100644 --- a/drivers/net/wireless/broadcom/b43/phy_g.c +++ b/drivers/net/wireless/broadcom/b43/phy_g.c @@ -6,7 +6,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005-2007 Stefano Brivio - Copyright (c) 2005-2008 Michael Buesch + Copyright (c) 2005-2008 Michael Buesch Copyright (c) 2005, 2006 Danny van Dyk Copyright (c) 2005, 2006 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/phy_lp.c b/drivers/net/wireless/broadcom/b43/phy_lp.c index 8e0058072242e0..6c90b84df91e60 100644 --- a/drivers/net/wireless/broadcom/b43/phy_lp.c +++ b/drivers/net/wireless/broadcom/b43/phy_lp.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver IEEE 802.11a/g LP-PHY driver - Copyright (c) 2008-2009 Michael Buesch + Copyright (c) 2008-2009 Michael Buesch Copyright (c) 2009 Gábor Stefanik @@ -1570,7 +1570,7 @@ static void lpphy_pr41573_workaround(struct b43_wldev *dev) s8 tx_pwr_idx_over; u16 tssi_npt, tssi_idx; - saved_tab = kcalloc(saved_tab_size, sizeof(saved_tab[0]), GFP_KERNEL); + saved_tab = kzalloc_objs(saved_tab[0], saved_tab_size); if (!saved_tab) { b43err(dev->wl, "PR41573 failed. Out of memory!\n"); return; diff --git a/drivers/net/wireless/broadcom/b43/phy_n.c b/drivers/net/wireless/broadcom/b43/phy_n.c index 22359bd9db47d7..007940f3996e25 100644 --- a/drivers/net/wireless/broadcom/b43/phy_n.c +++ b/drivers/net/wireless/broadcom/b43/phy_n.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver IEEE 802.11n PHY support - Copyright (c) 2008 Michael Buesch + Copyright (c) 2008 Michael Buesch Copyright (c) 2010-2011 Rafał Miłecki @@ -1506,7 +1506,7 @@ static int b43_nphy_load_samples(struct b43_wldev *dev, u16 i; u32 *data; - data = kcalloc(len, sizeof(u32), GFP_KERNEL); + data = kzalloc_objs(u32, len); if (!data) { b43err(dev->wl, "allocation for samples loading failed\n"); return -ENOMEM; diff --git a/drivers/net/wireless/broadcom/b43/pio.c b/drivers/net/wireless/broadcom/b43/pio.c index 8358b1d5c298ed..08dba9f3d5fda0 100644 --- a/drivers/net/wireless/broadcom/b43/pio.c +++ b/drivers/net/wireless/broadcom/b43/pio.c @@ -5,7 +5,7 @@ PIO data transfer - Copyright (c) 2005-2008 Michael Buesch + Copyright (c) 2005-2008 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43/radio_2055.c b/drivers/net/wireless/broadcom/b43/radio_2055.c index be841f89190026..7f3ca19a123f3c 100644 --- a/drivers/net/wireless/broadcom/b43/radio_2055.c +++ b/drivers/net/wireless/broadcom/b43/radio_2055.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver IEEE 802.11n PHY and radio device data tables - Copyright (c) 2008 Michael Buesch + Copyright (c) 2008 Michael Buesch Copyright (c) 2010 Rafał Miłecki diff --git a/drivers/net/wireless/broadcom/b43/rfkill.c b/drivers/net/wireless/broadcom/b43/rfkill.c index f0c9687036130e..bf6391b5d10e3d 100644 --- a/drivers/net/wireless/broadcom/b43/rfkill.c +++ b/drivers/net/wireless/broadcom/b43/rfkill.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver RFKILL support - Copyright (c) 2007 Michael Buesch + Copyright (c) 2007 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43/sdio.c b/drivers/net/wireless/broadcom/b43/sdio.c index dda8d894aebeec..35cf31e7d5b685 100644 --- a/drivers/net/wireless/broadcom/b43/sdio.c +++ b/drivers/net/wireless/broadcom/b43/sdio.c @@ -5,7 +5,7 @@ * SDIO over Sonics Silicon Backplane bus glue for b43. * * Copyright (C) 2009 Albert Herranz - * Copyright (C) 2009 Michael Buesch + * Copyright (C) 2009 Michael Buesch */ #include diff --git a/drivers/net/wireless/broadcom/b43/sysfs.c b/drivers/net/wireless/broadcom/b43/sysfs.c index 261b2b746a9c90..c8bd1bce779186 100644 --- a/drivers/net/wireless/broadcom/b43/sysfs.c +++ b/drivers/net/wireless/broadcom/b43/sysfs.c @@ -5,7 +5,7 @@ SYSFS support routines - Copyright (c) 2006 Michael Buesch + Copyright (c) 2006 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43/tables.c b/drivers/net/wireless/broadcom/b43/tables.c index 25c891e2cbfa17..9b2bfa30f08209 100644 --- a/drivers/net/wireless/broadcom/b43/tables.c +++ b/drivers/net/wireless/broadcom/b43/tables.c @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005-2007 Stefano Brivio - Copyright (c) 2006, 2006 Michael Buesch + Copyright (c) 2006, 2006 Michael Buesch Copyright (c) 2005 Danny van Dyk Copyright (c) 2005 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43/tables_lpphy.c b/drivers/net/wireless/broadcom/b43/tables_lpphy.c index fb70a1e3544be2..2bd3dfaa47f67d 100644 --- a/drivers/net/wireless/broadcom/b43/tables_lpphy.c +++ b/drivers/net/wireless/broadcom/b43/tables_lpphy.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver IEEE 802.11a/g LP-PHY and radio device data tables - Copyright (c) 2009 Michael Buesch + Copyright (c) 2009 Michael Buesch Copyright (c) 2009 Gábor Stefanik diff --git a/drivers/net/wireless/broadcom/b43/tables_nphy.c b/drivers/net/wireless/broadcom/b43/tables_nphy.c index ecd660b9c75a47..6b48943d950a13 100644 --- a/drivers/net/wireless/broadcom/b43/tables_nphy.c +++ b/drivers/net/wireless/broadcom/b43/tables_nphy.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver IEEE 802.11n PHY data tables - Copyright (c) 2008 Michael Buesch + Copyright (c) 2008 Michael Buesch Copyright (c) 2010 Rafał Miłecki diff --git a/drivers/net/wireless/broadcom/b43/wa.c b/drivers/net/wireless/broadcom/b43/wa.c index f9209b863e3540..222d88c45a174f 100644 --- a/drivers/net/wireless/broadcom/b43/wa.c +++ b/drivers/net/wireless/broadcom/b43/wa.c @@ -6,7 +6,7 @@ PHY workarounds. Copyright (c) 2005-2007 Stefano Brivio - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43/xmit.c b/drivers/net/wireless/broadcom/b43/xmit.c index f0b082596637ff..4f9e1ebd55b713 100644 --- a/drivers/net/wireless/broadcom/b43/xmit.c +++ b/drivers/net/wireless/broadcom/b43/xmit.c @@ -7,7 +7,7 @@ Copyright (C) 2005 Martin Langer Copyright (C) 2005 Stefano Brivio - Copyright (C) 2005, 2006 Michael Buesch + Copyright (C) 2005, 2006 Michael Buesch Copyright (C) 2005 Danny van Dyk Copyright (C) 2005 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43legacy/debugfs.c b/drivers/net/wireless/broadcom/b43legacy/debugfs.c index 7ce8bcf12f0a99..1e44e04a010515 100644 --- a/drivers/net/wireless/broadcom/b43legacy/debugfs.c +++ b/drivers/net/wireless/broadcom/b43legacy/debugfs.c @@ -5,7 +5,7 @@ debugfs driver debugging code - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43legacy/dma.c b/drivers/net/wireless/broadcom/b43legacy/dma.c index 6c3d847242bbaf..0659af58e7c147 100644 --- a/drivers/net/wireless/broadcom/b43legacy/dma.c +++ b/drivers/net/wireless/broadcom/b43legacy/dma.c @@ -5,7 +5,7 @@ DMA ringbuffer and descriptor allocation/management - Copyright (c) 2005, 2006 Michael Buesch + Copyright (c) 2005, 2006 Michael Buesch Some code in this file is derived from the b44.c driver Copyright (C) 2002 David S. Miller diff --git a/drivers/net/wireless/broadcom/b43legacy/ilt.c b/drivers/net/wireless/broadcom/b43legacy/ilt.c index f62d6886a00316..78bc0e78c5756b 100644 --- a/drivers/net/wireless/broadcom/b43legacy/ilt.c +++ b/drivers/net/wireless/broadcom/b43legacy/ilt.c @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43legacy/leds.c b/drivers/net/wireless/broadcom/b43legacy/leds.c index 79e6fd205bfb70..43c75472d06f20 100644 --- a/drivers/net/wireless/broadcom/b43legacy/leds.c +++ b/drivers/net/wireless/broadcom/b43legacy/leds.c @@ -6,7 +6,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005 Stefano Brivio - Copyright (c) 2005-2007 Michael Buesch + Copyright (c) 2005-2007 Michael Buesch Copyright (c) 2005 Danny van Dyk Copyright (c) 2005 Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43legacy/main.c b/drivers/net/wireless/broadcom/b43legacy/main.c index dfff3710dea3d5..a960b49b2943e5 100644 --- a/drivers/net/wireless/broadcom/b43legacy/main.c +++ b/drivers/net/wireless/broadcom/b43legacy/main.c @@ -5,7 +5,7 @@ * * Copyright (c) 2005 Martin Langer * Copyright (c) 2005-2008 Stefano Brivio - * Copyright (c) 2005, 2006 Michael Buesch + * Copyright (c) 2005, 2006 Michael Buesch * Copyright (c) 2005 Danny van Dyk * Copyright (c) 2005 Andreas Jaggi * Copyright (c) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/b43legacy/main.h b/drivers/net/wireless/broadcom/b43legacy/main.h index 85edbc8c121a1b..420683ecbd10b6 100644 --- a/drivers/net/wireless/broadcom/b43legacy/main.h +++ b/drivers/net/wireless/broadcom/b43legacy/main.h @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Copyright (c) 2005 Stefano Brivio - Copyright (c) 2005, 2006 Michael Buesch + Copyright (c) 2005, 2006 Michael Buesch Copyright (c) 2005 Danny van Dyk Copyright (c) 2005 Andreas Jaggi Copyright (c) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/b43legacy/phy.c b/drivers/net/wireless/broadcom/b43legacy/phy.c index c1395e622759e0..5be36c9ba41486 100644 --- a/drivers/net/wireless/broadcom/b43legacy/phy.c +++ b/drivers/net/wireless/broadcom/b43legacy/phy.c @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi Copyright (c) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/b43legacy/phy.h b/drivers/net/wireless/broadcom/b43legacy/phy.h index bb2c492dab3606..b45d731429b042 100644 --- a/drivers/net/wireless/broadcom/b43legacy/phy.h +++ b/drivers/net/wireless/broadcom/b43legacy/phy.h @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi Copyright (c) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/b43legacy/pio.c b/drivers/net/wireless/broadcom/b43legacy/pio.c index 0274fe47ca7eb8..d1e271c4ef7123 100644 --- a/drivers/net/wireless/broadcom/b43legacy/pio.c +++ b/drivers/net/wireless/broadcom/b43legacy/pio.c @@ -5,7 +5,7 @@ PIO Transmission - Copyright (c) 2005 Michael Buesch + Copyright (c) 2005 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43legacy/radio.c b/drivers/net/wireless/broadcom/b43legacy/radio.c index 8d7eb89c162805..d46a42a05a66e2 100644 --- a/drivers/net/wireless/broadcom/b43legacy/radio.c +++ b/drivers/net/wireless/broadcom/b43legacy/radio.c @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi Copyright (c) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/b43legacy/radio.h b/drivers/net/wireless/broadcom/b43legacy/radio.h index ee8b2c8d1602a2..d833690d17b803 100644 --- a/drivers/net/wireless/broadcom/b43legacy/radio.h +++ b/drivers/net/wireless/broadcom/b43legacy/radio.h @@ -5,7 +5,7 @@ Copyright (c) 2005 Martin Langer , Stefano Brivio - Michael Buesch + Michael Buesch Danny van Dyk Andreas Jaggi diff --git a/drivers/net/wireless/broadcom/b43legacy/rfkill.c b/drivers/net/wireless/broadcom/b43legacy/rfkill.c index 1f532105052e08..b8e3f2734cd7f8 100644 --- a/drivers/net/wireless/broadcom/b43legacy/rfkill.c +++ b/drivers/net/wireless/broadcom/b43legacy/rfkill.c @@ -4,7 +4,7 @@ Broadcom B43 wireless driver RFKILL support - Copyright (c) 2007 Michael Buesch + Copyright (c) 2007 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43legacy/sysfs.c b/drivers/net/wireless/broadcom/b43legacy/sysfs.c index d988fe541bf73b..a29df7481191d3 100644 --- a/drivers/net/wireless/broadcom/b43legacy/sysfs.c +++ b/drivers/net/wireless/broadcom/b43legacy/sysfs.c @@ -5,7 +5,7 @@ SYSFS support routines - Copyright (c) 2006 Michael Buesch + Copyright (c) 2006 Michael Buesch */ diff --git a/drivers/net/wireless/broadcom/b43legacy/xmit.c b/drivers/net/wireless/broadcom/b43legacy/xmit.c index ee199d4eaf039a..c97b8be744c678 100644 --- a/drivers/net/wireless/broadcom/b43legacy/xmit.c +++ b/drivers/net/wireless/broadcom/b43legacy/xmit.c @@ -7,7 +7,7 @@ Copyright (C) 2005 Martin Langer Copyright (C) 2005 Stefano Brivio - Copyright (C) 2005, 2006 Michael Buesch + Copyright (C) 2005, 2006 Michael Buesch Copyright (C) 2005 Danny van Dyk Copyright (C) 2005 Andreas Jaggi Copyright (C) 2007 Larry Finger diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index 069ba7016654ec..ff47d4827722e0 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -1639,7 +1639,7 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) if (!msgbuf->tx_pktids) goto fail; msgbuf->rx_pktids = brcmf_msgbuf_init_pktids(NR_RX_PKTIDS, - DMA_FROM_DEVICE); + DMA_BIDIRECTIONAL); if (!msgbuf->rx_pktids) goto fail; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c index 03efae36a0b2d3..0ebf54ed5e29a0 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c @@ -37,7 +37,7 @@ static int brcmf_of_get_country_codes(struct device *dev, return (count == -EINVAL) ? 0 : count; } - cc = devm_kzalloc(dev, struct_size(cc, table, count), GFP_KERNEL); + cc = devm_kzalloc_flex(dev, *cc, table, count); if (!cc) return -ENOMEM; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c index 813cc15d8b87be..e6f73188d42d08 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c @@ -816,8 +816,7 @@ static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg, } if (request->n_channels) { - chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs), - GFP_KERNEL); + chanspecs = kzalloc_objs(*chanspecs, request->n_channels); if (!chanspecs) { err = -ENOMEM; goto exit; @@ -1100,8 +1099,7 @@ static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel) channel_cnt = AF_PEER_SEARCH_CNT; else channel_cnt = SOCIAL_CHAN_CNT; - default_chan_list = kcalloc(channel_cnt, sizeof(*default_chan_list), - GFP_KERNEL); + default_chan_list = kzalloc_objs(*default_chan_list, channel_cnt); if (default_chan_list == NULL) { bphy_err(drvr, "channel list allocation failed\n"); err = -ENOMEM; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 17bae04c14b045..e0ff122e170110 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -2107,7 +2107,7 @@ static int brcmf_pcie_read_otp(struct brcmf_pciedev_info *devinfo) sromctl | BCMA_CC_SROM_CONTROL_OTPSEL); } - otp = kcalloc(words, sizeof(u16), GFP_KERNEL); + otp = kzalloc_objs(u16, words); if (!otp) return -ENOMEM; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c index 81df41c7fbb5b1..a1888ff02d08dd 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c @@ -189,7 +189,7 @@ brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn, struct dentry *dentry = drvr->dbgfs_dir; struct brcms_debugfs_entry *entry; - entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(dev, *entry); if (!entry) return; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c index d65a68045ca827..70ef76b5546a61 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c @@ -2594,7 +2594,7 @@ wlc_lcnphy_tx_iqlo_cal(struct brcms_phy *pi, if (WARN_ON(CHSPEC_IS5G(pi->radio_chanspec))) return; - values_to_save = kmalloc_array(20, sizeof(u16), GFP_ATOMIC); + values_to_save = kmalloc_objs(u16, 20, GFP_ATOMIC); if (NULL == values_to_save) return; @@ -3602,7 +3602,7 @@ wlc_lcnphy_a1(struct brcms_phy *pi, int cal_type, int num_levels, if (NULL == ptr) return; - phy_c32 = kmalloc_array(20, sizeof(u16), GFP_ATOMIC); + phy_c32 = kmalloc_objs(u16, 20, GFP_ATOMIC); if (NULL == phy_c32) { kfree(ptr); return; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c index 9ddd5d519893e2..0b99106672cc41 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c @@ -23007,7 +23007,7 @@ wlc_phy_loadsampletable_nphy(struct brcms_phy *pi, struct cordic_iq *tone_buf, u16 t; u32 *data_buf = NULL; - data_buf = kmalloc_array(num_samps, sizeof(u32), GFP_ATOMIC); + data_buf = kmalloc_objs(u32, num_samps, GFP_ATOMIC); if (data_buf == NULL) return; diff --git a/drivers/net/wireless/intel/iwlwifi/mei/main.c b/drivers/net/wireless/intel/iwlwifi/mei/main.c index ce92e26c42d7fd..b69ebdc5060fb0 100644 --- a/drivers/net/wireless/intel/iwlwifi/mei/main.c +++ b/drivers/net/wireless/intel/iwlwifi/mei/main.c @@ -1982,7 +1982,7 @@ static int iwl_mei_probe(struct mei_cl_device *cldev, struct iwl_mei *mei; int ret; - mei = devm_kzalloc(&cldev->dev, sizeof(*mei), GFP_KERNEL); + mei = devm_kzalloc_obj(&cldev->dev, *mei); if (!mei) return -ENOMEM; diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index a9425e9a94f451..ecbe864b0797f2 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -382,7 +382,7 @@ static int mwifiex_pcie_probe(struct pci_dev *pdev, pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n", pdev->vendor, pdev->device, pdev->revision); - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); if (!card) return -ENOMEM; diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c index c15d6e1dd8f633..417dc2649b99c3 100644 --- a/drivers/net/wireless/marvell/mwifiex/sdio.c +++ b/drivers/net/wireless/marvell/mwifiex/sdio.c @@ -556,7 +556,7 @@ mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n", func->vendor, func->device, func->class, func->num); - card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&func->dev, *card); if (!card) return -ENOMEM; @@ -2586,9 +2586,8 @@ static int mwifiex_init_sdio(struct mwifiex_adapter *adapter) if (!card->mp_regs) return -ENOMEM; - card->mpa_rx.len_arr = kcalloc(card->mp_agg_pkt_limit, - sizeof(*card->mpa_rx.len_arr), - GFP_KERNEL); + card->mpa_rx.len_arr = kzalloc_objs(*card->mpa_rx.len_arr, + card->mp_agg_pkt_limit); if (!card->mpa_rx.len_arr) { kfree(card->mp_regs); return -ENOMEM; diff --git a/drivers/net/wireless/marvell/mwifiex/usb.c b/drivers/net/wireless/marvell/mwifiex/usb.c index f4b94a1054f650..28e5b84a13c7b4 100644 --- a/drivers/net/wireless/marvell/mwifiex/usb.c +++ b/drivers/net/wireless/marvell/mwifiex/usb.c @@ -392,7 +392,7 @@ static int mwifiex_usb_probe(struct usb_interface *intf, struct usb_card_rec *card; u16 id_vendor, id_product, bcd_device; - card = devm_kzalloc(&intf->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&intf->dev, *card); if (!card) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index c9762082f473a0..92e29c089b9929 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -319,8 +319,7 @@ mt76_init_sband(struct mt76_phy *phy, struct mt76_sband *msband, if (!chanlist) return -ENOMEM; - msband->chan = devm_kcalloc(dev->dev, n_chan, sizeof(*msband->chan), - GFP_KERNEL); + msband->chan = devm_kzalloc_objs(dev->dev, *msband->chan, n_chan); if (!msband->chan) return -ENOMEM; @@ -459,9 +458,8 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw) wiphy->available_antennas_rx = phy->antenna_mask; wiphy->sar_capa = &mt76_sar_capa; - phy->frp = devm_kcalloc(dev->dev, wiphy->sar_capa->num_freq_ranges, - sizeof(struct mt76_freq_range_power), - GFP_KERNEL); + phy->frp = devm_kzalloc_objs(dev->dev, struct mt76_freq_range_power, + wiphy->sar_capa->num_freq_ranges); if (!phy->frp) return -ENOMEM; @@ -2027,7 +2025,7 @@ mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, struct mt76_queue *hwq; int err; - hwq = devm_kzalloc(dev->dev, sizeof(*hwq), GFP_KERNEL); + hwq = devm_kzalloc_obj(dev->dev, *hwq); if (!hwq) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c index 46188951ad194f..f6dee0fb8f2e04 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c @@ -133,9 +133,7 @@ static int mt7663s_probe(struct sdio_func *func, dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev); mdev->sdio.parse_irq = mt7663s_parse_intr; - mdev->sdio.intr_data = devm_kmalloc(mdev->dev, - sizeof(struct mt7663s_intr), - GFP_KERNEL); + mdev->sdio.intr_data = devm_kmalloc_obj(mdev->dev, struct mt7663s_intr); if (!mdev->sdio.intr_data) { ret = -ENOMEM; goto error; diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 9bdfff24b7020e..dd0b1871d2071a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -2224,7 +2224,7 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy, struct mt76_power_limits *limits; const u8 *ch_list; - limits = devm_kmalloc(dev->dev, sizeof(*limits), GFP_KERNEL); + limits = devm_kmalloc_obj(dev->dev, *limits); if (!limits) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.c b/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.c index 21c99ad7ef594c..dc9d727a18b00c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.c @@ -166,7 +166,7 @@ mt76x02_dfs_seq_pool_get(struct mt76x02_dev *dev) struct mt76x02_dfs_sequence *seq; if (list_empty(&dfs_pd->seq_pool)) { - seq = devm_kzalloc(dev->mt76.dev, sizeof(*seq), GFP_ATOMIC); + seq = devm_kzalloc_obj(dev->mt76.dev, *seq, GFP_ATOMIC); } else { seq = list_first_entry(&dfs_pd->seq_pool, struct mt76x02_dfs_sequence, diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/pci.c b/drivers/net/wireless/mediatek/mt76/mt7915/pci.c index 8007e620048b33..6e8ec0a8a9cb25 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/pci.c @@ -85,7 +85,7 @@ static int mt7915_pci_hif2_probe(struct pci_dev *pdev) { struct mt7915_hif *hif; - hif = devm_kzalloc(&pdev->dev, sizeof(*hif), GFP_KERNEL); + hif = devm_kzalloc_obj(&pdev->dev, *hif); if (!hif) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c index 9150f185716cfe..754b33485f6ecb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c @@ -159,9 +159,8 @@ static int mt7921s_probe(struct sdio_func *func, dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev); mdev->sdio.parse_irq = mt7921s_parse_intr; - mdev->sdio.intr_data = devm_kmalloc(mdev->dev, - sizeof(struct mt7921_sdio_intr), - GFP_KERNEL); + mdev->sdio.intr_data = devm_kmalloc_obj(mdev->dev, + struct mt7921_sdio_intr); if (!mdev->sdio.intr_data) { ret = -ENOMEM; goto error; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c index 0209606e1a4748..eb1e1b4c109000 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/cached_cal.c @@ -76,7 +76,7 @@ int mt7925_mcu_send_axidma_info(struct mt792x_dev *dev) if (!dev->cached_cal.va) return -EINVAL; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req); if (!req) return -ENOMEM; @@ -195,7 +195,7 @@ static int mt7925_mcu_fact_cal_rapid_set(struct mt792x_dev *dev, u8 cal_type, if (data_len > MT7925_FACT_CAL_DATA_BUF_LEN) return -EINVAL; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req); if (!req) return -ENOMEM; @@ -225,7 +225,7 @@ int mt7925_mcu_send_fact_cal_mapping_tbl(struct mt792x_dev *dev) if (!dev->cached_cal.va) return -EINVAL; - tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); + tbl = kzalloc_obj(*tbl); if (!tbl) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c index d01ff49de47af7..6dd93eb0ff2c04 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c @@ -122,7 +122,7 @@ mt7925_txpwr(struct seq_file *s, void *data) u8 band_idx = dev->mphy.band_idx; int ret = 0; - txpwr = devm_kmalloc(dev->mt76.dev, sizeof(*txpwr), GFP_KERNEL); + txpwr = devm_kmalloc_obj(dev->mt76.dev, *txpwr); if (!txpwr) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index 15d95ad326362b..8d591f265260f8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -2285,10 +2285,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mconf = &mvif->bss_conf; mlink = &mvif->sta.deflink; } else { - mconf = devm_kzalloc(dev->mt76.dev, sizeof(*mconf), - GFP_KERNEL); - mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), - GFP_KERNEL); + mconf = devm_kzalloc_obj(dev->mt76.dev, *mconf); + mlink = devm_kzalloc_obj(dev->mt76.dev, *mlink); if (!mconf || !mlink) { mt792x_mutex_release(dev); return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index 26cdb3f0a98ae2..153bdec383cf8e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -4004,7 +4004,7 @@ mt7925_mcu_rate_txpower_band(struct mt76_phy *phy, } batch_size = DIV_ROUND_UP(n_chan, batch_len); - limits = devm_kmalloc(dev->dev, sizeof(*limits), GFP_KERNEL); + limits = devm_kmalloc_obj(dev->dev, *limits); if (!limits) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c index e87dfb0f1b3a66..2d7a967fd399ca 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c @@ -225,7 +225,7 @@ int mt792x_init_acpi_sar(struct mt792x_dev *dev) struct mt792x_acpi_sar *asar; int ret; - asar = devm_kzalloc(dev->mt76.dev, sizeof(*asar), GFP_KERNEL); + asar = devm_kzalloc_obj(dev->mt76.dev, *asar); if (!asar) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c index 3ce6c6ceac81c7..d6f3a242b57964 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c @@ -152,8 +152,7 @@ static int mt792x_setup_iface_combinations(struct mt792x_dev *dev, } /* CNM + NAN: dynamically build base + nan list */ - comb = devm_kcalloc(&wiphy->dev, n_base + n_nan, sizeof(*comb), - GFP_KERNEL); + comb = devm_kzalloc_objs(&wiphy->dev, *comb, n_base + n_nan); if (!comb) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c index a7c23b33dde0b6..32f82dbb09739c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/pci.c @@ -86,7 +86,7 @@ static int mt7996_pci_hif2_probe(struct pci_dev *pdev) { struct mt7996_hif *hif; - hif = devm_kzalloc(&pdev->dev, sizeof(*hif), GFP_KERNEL); + hif = devm_kzalloc_obj(&pdev->dev, *hif); if (!hif) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c index ba5f123f7e39dc..91e5fad0479d57 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/sdio.c @@ -306,9 +306,7 @@ int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid) struct mt76_queue *q = &dev->q_rx[qid]; spin_lock_init(&q->lock); - q->entry = devm_kcalloc(dev->dev, - MT76S_NUM_RX_ENTRIES, sizeof(*q->entry), - GFP_KERNEL); + q->entry = devm_kzalloc_objs(dev->dev, *q->entry, MT76S_NUM_RX_ENTRIES); if (!q->entry) return -ENOMEM; @@ -324,14 +322,12 @@ static struct mt76_queue *mt76s_alloc_tx_queue(struct mt76_dev *dev) { struct mt76_queue *q; - q = devm_kzalloc(dev->dev, sizeof(*q), GFP_KERNEL); + q = devm_kzalloc_obj(dev->dev, *q); if (!q) return ERR_PTR(-ENOMEM); spin_lock_init(&q->lock); - q->entry = devm_kcalloc(dev->dev, - MT76S_NUM_TX_ENTRIES, sizeof(*q->entry), - GFP_KERNEL); + q->entry = devm_kzalloc_objs(dev->dev, *q->entry, MT76S_NUM_TX_ENTRIES); if (!q->entry) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index be48a88a3ad020..f6464315e3741c 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -706,9 +706,7 @@ mt76u_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid) return err; spin_lock_init(&q->lock); - q->entry = devm_kcalloc(dev->dev, - MT_NUM_RX_ENTRIES, sizeof(*q->entry), - GFP_KERNEL); + q->entry = devm_kzalloc_objs(dev->dev, *q->entry, MT_NUM_RX_ENTRIES); if (!q->entry) return -ENOMEM; @@ -1013,7 +1011,7 @@ static int mt76u_alloc_tx(struct mt76_dev *dev) struct mt76_queue *q; int j, err; - q = devm_kzalloc(dev->dev, sizeof(*q), GFP_KERNEL); + q = devm_kzalloc_obj(dev->dev, *q); if (!q) return -ENOMEM; @@ -1021,9 +1019,8 @@ static int mt76u_alloc_tx(struct mt76_dev *dev) mt76u_ac_to_hwq(dev, q, i); dev->phy.q_tx[i] = q; - q->entry = devm_kcalloc(dev->dev, - MT_NUM_TX_ENTRIES, sizeof(*q->entry), - GFP_KERNEL); + q->entry = devm_kzalloc_objs(dev->dev, *q->entry, + MT_NUM_TX_ENTRIES); if (!q->entry) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt7601u/dma.c b/drivers/net/wireless/mediatek/mt7601u/dma.c index 773a1cc2f85204..9a2e8b0511c7d5 100644 --- a/drivers/net/wireless/mediatek/mt7601u/dma.c +++ b/drivers/net/wireless/mediatek/mt7601u/dma.c @@ -502,8 +502,7 @@ static int mt7601u_alloc_tx(struct mt7601u_dev *dev) { int i; - dev->tx_q = devm_kcalloc(dev->dev, __MT_EP_OUT_MAX, - sizeof(*dev->tx_q), GFP_KERNEL); + dev->tx_q = devm_kzalloc_objs(dev->dev, *dev->tx_q, __MT_EP_OUT_MAX); if (!dev->tx_q) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c b/drivers/net/wireless/mediatek/mt7601u/eeprom.c index d4d31a54655692..5dea3a3cffb0ba 100644 --- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c +++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c @@ -351,7 +351,7 @@ mt7601u_eeprom_init(struct mt7601u_dev *dev) if (ret) return ret; - dev->ee = devm_kzalloc(dev->dev, sizeof(*dev->ee), GFP_KERNEL); + dev->ee = devm_kzalloc_obj(dev->dev, *dev->ee); if (!dev->ee) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt7601u/init.c b/drivers/net/wireless/mediatek/mt7601u/init.c index 5d9e952b296647..ebc45ed4effaa5 100644 --- a/drivers/net/wireless/mediatek/mt7601u/init.c +++ b/drivers/net/wireless/mediatek/mt7601u/init.c @@ -555,8 +555,7 @@ mt76_init_sband(struct mt7601u_dev *dev, struct ieee80211_supported_band *sband, static int mt76_init_sband_2g(struct mt7601u_dev *dev) { - dev->sband_2g = devm_kzalloc(dev->dev, sizeof(*dev->sband_2g), - GFP_KERNEL); + dev->sband_2g = devm_kzalloc_obj(dev->dev, *dev->sband_2g); if (!dev->sband_2g) return -ENOMEM; @@ -583,8 +582,7 @@ int mt7601u_register_device(struct mt7601u_dev *dev) dev->wcid_mask[0] |= 1; /* init fake wcid for monitor interfaces */ - dev->mon_wcid = devm_kmalloc(dev->dev, sizeof(*dev->mon_wcid), - GFP_KERNEL); + dev->mon_wcid = devm_kmalloc_obj(dev->dev, *dev->mon_wcid); if (!dev->mon_wcid) return -ENOMEM; dev->mon_wcid->idx = 0xff; diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 6f1feb24fe6a6c..cd0bb4d21acf01 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -2005,6 +2005,23 @@ static void mm81x_rx_h_add_rt_s1g_tlv(struct sk_buff *skb, rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; } +/* + * This is a hack to workaround how our firmware reports frequencies. + * For any 1MHz frames report them directly (i.e during scanning), else + * report the 1MHz control channel we are tuned to. + */ +static void mm81x_rx_h_fill_freq(struct mm81x *mors, u32 rx_khz, + struct ieee80211_rx_status *rx_status) +{ + struct ieee80211_channel *chan = mors->chandef.chan; + + if (rx_status->bw != RATE_INFO_BW_1) + rx_khz = ieee80211_channel_to_khz(chan); + + rx_status->freq = KHZ_TO_MHZ(rx_khz); + rx_status->freq_offset = (rx_khz % 1000) ? 1 : 0; +} + static void mm81x_rx_h_fill_status(struct mm81x *mors, struct mm81x_skb_rx_status *hdr_rx_status, struct ieee80211_rx_status *rx_status, @@ -2018,11 +2035,10 @@ static void mm81x_rx_h_fill_status(struct mm81x *mors, rx_status->signal = le16_to_cpu(hdr_rx_status->rssi); rx_status->encoding = RX_ENC_S1G; rx_status->band = NL80211_BAND_S1GHZ; - rx_status->freq = KHZ100_TO_MHZ(freq_100khz); - rx_status->freq_offset = (freq_100khz % 10) ? 1 : 0; rx_status->nss = NSS_IDX_TO_NSS(mm81x_ratecode_nss_index_get(ratecode)); rx_status->rate_idx = mm81x_ratecode_mcs_index_get(ratecode); rx_status->bw = mm81x_rx_h_rc_bw_to_rx_bw(ratecode); + mm81x_rx_h_fill_freq(mors, KHZ100_TO_KHZ(freq_100khz), rx_status); rx_status->mactime = timestamp; rx_status->flag |= RX_FLAG_MACTIME_IS_RTAP_TS64; diff --git a/drivers/net/wireless/nxp/nxpwifi/11ax.c b/drivers/net/wireless/nxp/nxpwifi/11ax.c index dc1e747383eca0..be38a034be325b 100644 --- a/drivers/net/wireless/nxp/nxpwifi/11ax.c +++ b/drivers/net/wireless/nxp/nxpwifi/11ax.c @@ -204,38 +204,61 @@ int nxpwifi_ret_11ax_cfg(struct nxpwifi_private *priv, { struct host_cmd_11ax_cfg *he_cfg = &resp->params.ax_cfg; struct nxpwifi_ie_types_header *header; - u16 left_len, tlv_type, tlv_len; + u16 resp_size, left_len, tlv_type, tlv_len; + struct nxpwifi_11ax_he_cap_cfg *he_cap; u8 ext_id; - struct nxpwifi_11ax_he_cap_cfg *he_cap = &ax_cfg->he_cap_cfg; - left_len = le16_to_cpu(resp->size) - sizeof(*he_cfg) - S_DS_GEN; + if (!ax_cfg) + return 0; + + he_cap = &ax_cfg->he_cap_cfg; + resp_size = le16_to_cpu(resp->size); + if (resp_size < S_DS_GEN + sizeof(*he_cfg)) + return -EINVAL; + + left_len = resp_size - S_DS_GEN - sizeof(*he_cfg); header = (struct nxpwifi_ie_types_header *)he_cfg->tlv; while (left_len > sizeof(*header)) { tlv_type = le16_to_cpu(header->type); tlv_len = le16_to_cpu(header->len); - if (tlv_type == TLV_TYPE_EXTENSION_ID) { - ext_id = *((u8 *)header + sizeof(*header) + 1); + if (sizeof(*header) + tlv_len > left_len) + return -EINVAL; + + if (tlv_type == TLV_TYPE_EXTENSION_ID && tlv_len >= 1) { + ext_id = *((u8 *)header + sizeof(*header)); if (ext_id == WLAN_EID_EXT_HE_CAPABILITY) { + u8 *user_cap, *user_cap_len; + size_t user_cap_size; + + if (he_cfg->band_config & BIT(1)) { + user_cap = priv->user_he_cap; + user_cap_len = &priv->user_he_cap_len; + user_cap_size = + sizeof(priv->user_he_cap); + } else { + user_cap = priv->user_2g_he_cap; + user_cap_len = + &priv->user_2g_he_cap_len; + user_cap_size = + sizeof(priv->user_2g_he_cap); + } + + if (tlv_len > sizeof(*he_cap) - + offsetof(struct nxpwifi_11ax_he_cap_cfg, + ext_id) || + sizeof(*header) + tlv_len > user_cap_size) + return -EINVAL; + he_cap->id = tlv_type; he_cap->len = tlv_len; memcpy((u8 *)&he_cap->ext_id, - (u8 *)header + sizeof(*header) + 1, + (u8 *)header + sizeof(*header), tlv_len); - if (he_cfg->band_config & BIT(1)) { - memcpy(priv->user_he_cap, - (u8 *)header, - sizeof(*header) + tlv_len); - priv->user_he_cap_len = - sizeof(*header) + tlv_len; - } else { - memcpy(priv->user_2g_he_cap, - (u8 *)header, - sizeof(*header) + tlv_len); - priv->user_2g_he_cap_len = - sizeof(*header) + tlv_len; - } + memcpy(user_cap, (u8 *)header, + sizeof(*header) + tlv_len); + *user_cap_len = sizeof(*header) + tlv_len; } } @@ -346,6 +369,9 @@ int nxpwifi_ret_11ax_cmd(struct nxpwifi_private *priv, struct host_cmd_11ax_cmd *he_cmd = &resp->params.ax_cmd; struct nxpwifi_ie_types_data *tlv; + if (!ax_cmd) + return 0; + ax_cmd->sub_id = le16_to_cpu(he_cmd->sub_id); switch (ax_cmd->sub_command) { @@ -584,6 +610,9 @@ int nxpwifi_ret_twt_cfg(struct nxpwifi_private *priv, struct host_cmd_twt_cfg *twt_cfg_cmd = &resp->params.twt_cfg; u16 action; + if (!twt_cfg) + return 0; + action = le16_to_cpu(twt_cfg_cmd->action); twt_cfg->sub_id = le16_to_cpu(twt_cfg_cmd->sub_id); diff --git a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c index ade57f128d1058..ba54078b082cf3 100644 --- a/drivers/net/wireless/nxp/nxpwifi/cfg80211.c +++ b/drivers/net/wireless/nxp/nxpwifi/cfg80211.c @@ -3746,9 +3746,8 @@ int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter) * additional active scan request for hidden SSIDs on passive channels. */ adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a); - adapter->chan_stats = kcalloc(adapter->num_in_chan_stats, - sizeof(*adapter->chan_stats), - GFP_KERNEL); + adapter->chan_stats = kzalloc_objs(*adapter->chan_stats, + adapter->num_in_chan_stats); if (!adapter->chan_stats) return -ENOMEM; diff --git a/drivers/net/wireless/nxp/nxpwifi/scan.c b/drivers/net/wireless/nxp/nxpwifi/scan.c index f3becafb9c23ca..4eeba6700aa724 100644 --- a/drivers/net/wireless/nxp/nxpwifi/scan.c +++ b/drivers/net/wireless/nxp/nxpwifi/scan.c @@ -1873,26 +1873,32 @@ void nxpwifi_cancel_scan(struct nxpwifi_adapter *adapter) { struct nxpwifi_private *priv; int i; + bool cancel = false; nxpwifi_cancel_pending_scan_cmd(adapter); + spin_lock_bh(&adapter->nxpwifi_cmd_lock); if (adapter->scan_processing) { - spin_lock_bh(&adapter->nxpwifi_cmd_lock); adapter->scan_processing = false; - spin_unlock_bh(&adapter->nxpwifi_cmd_lock); - for (i = 0; i < adapter->priv_num; i++) { - priv = adapter->priv[i]; - if (priv->scan_request) { - struct cfg80211_scan_info info = { - .aborted = true, - }; + cancel = true; + } + spin_unlock_bh(&adapter->nxpwifi_cmd_lock); - nxpwifi_dbg(adapter, INFO, - "info: aborting scan\n"); - cfg80211_scan_done(priv->scan_request, &info); - priv->scan_request = NULL; - priv->scan_aborting = false; - } + if (!cancel) + return; + + for (i = 0; i < adapter->priv_num; i++) { + priv = adapter->priv[i]; + if (priv->scan_request) { + struct cfg80211_scan_info info = { + .aborted = true, + }; + + nxpwifi_dbg(adapter, INFO, + "info: aborting scan\n"); + cfg80211_scan_done(priv->scan_request, &info); + priv->scan_request = NULL; + priv->scan_aborting = false; } } } @@ -2017,12 +2023,22 @@ int nxpwifi_ret_802_11_scan(struct nxpwifi_private *priv, * was received. */ if (tsf_tlv) - memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE], - sizeof(fw_tsf)); + if ((idx + 1) * TSF_DATA_SIZE <= + le16_to_cpu(tsf_tlv->header.len)) + memcpy(&fw_tsf, + &tsf_tlv->tsf_data[idx * + TSF_DATA_SIZE], + sizeof(fw_tsf)); if (chan_band_tlv) { - chan_band = &chan_band_tlv->chan_band_param[idx]; - radio_type = &chan_band->radio_type; + if ((idx + 1) * sizeof(*chan_band) <= + le16_to_cpu(chan_band_tlv->header.len)) { + chan_band = + &chan_band_tlv->chan_band_param[idx]; + radio_type = &chan_band->radio_type; + } else { + radio_type = NULL; + } } else { radio_type = NULL; } diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.c b/drivers/net/wireless/nxp/nxpwifi/sdio.c index 010f7827058025..bdc8834fe428e0 100644 --- a/drivers/net/wireless/nxp/nxpwifi/sdio.c +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.c @@ -138,7 +138,7 @@ nxpwifi_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) int ret; struct sdio_mmc_card *card = NULL; - card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&func->dev, *card); if (!card) return -ENOMEM; @@ -1744,8 +1744,8 @@ static int nxpwifi_init_sdio(struct nxpwifi_adapter *adapter) return -ENOMEM; card->mpa_rx.len_arr = - devm_kcalloc(&card->func->dev, card->mp_agg_pkt_limit, - sizeof(*card->mpa_rx.len_arr), GFP_KERNEL); + devm_kzalloc_objs(&card->func->dev, *card->mpa_rx.len_arr, + card->mp_agg_pkt_limit); if (!card->mpa_rx.len_arr) return -ENOMEM; diff --git a/drivers/net/wireless/nxp/nxpwifi/util.c b/drivers/net/wireless/nxp/nxpwifi/util.c index cf94fba22f7911..7dd122f3c7f58e 100644 --- a/drivers/net/wireless/nxp/nxpwifi/util.c +++ b/drivers/net/wireless/nxp/nxpwifi/util.c @@ -623,6 +623,10 @@ int nxpwifi_recv_packet_to_monif(struct nxpwifi_private *priv, has_ext = rxpd->flags & RXPD_FLAG_EXTRA_HEADER; + if (has_ext && + rx_pkt_offset < sizeof(*rxpd) + sizeof(ext)) + return -EINVAL; + if (has_ext) memcpy((void *)&ext, (void *)(rxpd + 1), sizeof(ext)); diff --git a/drivers/net/wireless/realtek/rtlwifi/efuse.c b/drivers/net/wireless/realtek/rtlwifi/efuse.c index 6518e77b89f578..b3936d9e0510d4 100644 --- a/drivers/net/wireless/realtek/rtlwifi/efuse.c +++ b/drivers/net/wireless/realtek/rtlwifi/efuse.c @@ -235,8 +235,7 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf) if (!efuse_word) goto out; for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { - efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16), - GFP_ATOMIC); + efuse_word[i] = kzalloc_objs(u16, efuse_max_section, GFP_ATOMIC); if (!efuse_word[i]) goto done; } diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c index 88e8cc590c544b..d0b233361ba58e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c @@ -64,12 +64,10 @@ static int rtl92du_init_shared_data(struct ieee80211_hw *hw) } /* The other interface doesn't exist or was not probed yet. */ - rtlpriv->curveindex_2g = kcalloc(TARGET_CHNL_NUM_2G, - sizeof(*rtlpriv->curveindex_2g), - GFP_KERNEL); - rtlpriv->curveindex_5g = kcalloc(TARGET_CHNL_NUM_5G, - sizeof(*rtlpriv->curveindex_5g), - GFP_KERNEL); + rtlpriv->curveindex_2g = kzalloc_objs(*rtlpriv->curveindex_2g, + TARGET_CHNL_NUM_2G); + rtlpriv->curveindex_5g = kzalloc_objs(*rtlpriv->curveindex_5g, + TARGET_CHNL_NUM_5G); rtlpriv->mutex_for_power_on_off = kzalloc_obj(*rtlpriv->mutex_for_power_on_off); rtlpriv->mutex_for_hw_init = kzalloc_obj(*rtlpriv->mutex_for_hw_init); diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c index 0f23498b5c96e4..b72173964bdd47 100644 --- a/drivers/net/wireless/realtek/rtw88/main.c +++ b/drivers/net/wireless/realtek/rtw88/main.c @@ -2177,6 +2177,9 @@ int rtw_core_init(struct rtw_dev *rtwdev) spin_lock_init(&rtwdev->txq_lock); spin_lock_init(&rtwdev->tx_report.q_lock); + spin_lock_init(&rtwdev->hiq_lock); + rtwdev->hiq_budget = RTW_TX_HIQ_BUDGET_MAX; + rtwdev->hiq_refill = jiffies; mutex_init(&rtwdev->mutex); mutex_init(&rtwdev->hal.tx_power_mutex); diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h index d59f6e323adf0c..c14c834c27fd3e 100644 --- a/drivers/net/wireless/realtek/rtw88/main.h +++ b/drivers/net/wireless/realtek/rtw88/main.h @@ -2104,6 +2104,11 @@ struct rtw_dev { struct rtw_tx_report tx_report; + /* protects hiq_budget and hiq_refill */ + spinlock_t hiq_lock; + u32 hiq_budget; + unsigned long hiq_refill; + struct { /* indicate the mail box to use with fw */ u8 last_box_num; diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index dc2fd0f8f9fff4..83e9b301ae9be5 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -1308,6 +1308,9 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev, u16 q_map = skb_get_queue_mapping(skb); struct rtw_sdio_tx_data *tx_data; + if (queue == RTW_TX_QUEUE_HI0 && !rtw_tx_bmc_use_hiq(rtwdev, skb)) + queue = rtw_tx_ac_to_hwq(q_map); + rtw_sdio_tx_skb_prepare(rtwdev, pkt_info, skb, queue); tx_data = rtw_sdio_get_tx_data(skb); diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c index 701ed7c4f3f75a..82c1af94f1ccaf 100644 --- a/drivers/net/wireless/realtek/rtw88/tx.c +++ b/drivers/net/wireless/realtek/rtw88/tx.c @@ -2,6 +2,8 @@ /* Copyright(c) 2018-2019 Realtek Corporation */ +#include +#include #include "main.h" #include "tx.h" #include "fw.h" @@ -745,3 +747,60 @@ enum rtw_tx_queue_type rtw_tx_queue_mapping(struct sk_buff *skb) return queue; } EXPORT_SYMBOL(rtw_tx_queue_mapping); + +static bool rtw_tx_bmc_needs_dtim(struct sk_buff *skb) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + struct udphdr *udphdr; + + if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) + return true; + + if (skb->protocol == htons(ETH_P_ARP)) + return true; + + if (skb->protocol == htons(ETH_P_IP) && + ip_hdr(skb)->protocol == IPPROTO_UDP) { + udphdr = udp_hdr(skb); + + return udphdr->dest == htons(67) || udphdr->dest == htons(68); + } + + return false; +} + +static bool rtw_tx_hiq_take_budget(struct rtw_dev *rtwdev) +{ + unsigned long flags, elapsed, add; + bool ok; + + spin_lock_irqsave(&rtwdev->hiq_lock, flags); + + elapsed = jiffies - rtwdev->hiq_refill; + add = elapsed / RTW_TX_HIQ_REFILL_INTERVAL; + if (add) { + rtwdev->hiq_budget = min_t(unsigned long, rtwdev->hiq_budget + add, + RTW_TX_HIQ_BUDGET_MAX); + + /* keep the unfinished part of the interval for the next unit */ + rtwdev->hiq_refill = jiffies - elapsed % RTW_TX_HIQ_REFILL_INTERVAL; + } + + ok = rtwdev->hiq_budget > 0; + if (ok) + rtwdev->hiq_budget--; + + spin_unlock_irqrestore(&rtwdev->hiq_lock, flags); + + return ok; +} + +bool rtw_tx_bmc_use_hiq(struct rtw_dev *rtwdev, struct sk_buff *skb) +{ + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + + return (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) && + rtw_tx_bmc_needs_dtim(skb) && + rtw_tx_hiq_take_budget(rtwdev); +} +EXPORT_SYMBOL(rtw_tx_bmc_use_hiq); diff --git a/drivers/net/wireless/realtek/rtw88/tx.h b/drivers/net/wireless/realtek/rtw88/tx.h index 168f48e87853dc..a68ba3b1215953 100644 --- a/drivers/net/wireless/realtek/rtw88/tx.h +++ b/drivers/net/wireless/realtek/rtw88/tx.h @@ -10,6 +10,9 @@ #define RTW_TX_PROBE_TIMEOUT_SHORT msecs_to_jiffies(500) #define RTW_TX_PROBE_TIMEOUT_LONG msecs_to_jiffies(2500) +#define RTW_TX_HIQ_REFILL_INTERVAL (HZ / 10) +#define RTW_TX_HIQ_BUDGET_MAX 16 + struct rtw_tx_desc { __le32 w0; __le32 w1; @@ -115,6 +118,7 @@ rtw_tx_write_data_h2c_get(struct rtw_dev *rtwdev, enum rtw_tx_queue_type rtw_tx_ac_to_hwq(enum ieee80211_ac_numbers ac); enum rtw_tx_queue_type rtw_tx_queue_mapping(struct sk_buff *skb); +bool rtw_tx_bmc_use_hiq(struct rtw_dev *rtwdev, struct sk_buff *skb); static inline void fill_txdesc_checksum_common(u8 *txdesc, size_t words) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 715a2ce342d922..13adbd415158ec 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -2,10 +2,8 @@ /* Copyright(c) 2018-2019 Realtek Corporation */ -#include #include #include -#include #include #include "main.h" #include "debug.h" @@ -564,61 +562,10 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size) return rtw_usb_write_data(rtwdev, &pkt_info, buf); } -static bool rtw_usb_bmc_needs_dtim(struct sk_buff *skb) -{ - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - struct udphdr *udphdr; - - if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) - return true; - - if (skb->protocol == htons(ETH_P_ARP)) - return true; - - if (skb->protocol == htons(ETH_P_IP) && - ip_hdr(skb)->protocol == IPPROTO_UDP) { - udphdr = udp_hdr(skb); - - return udphdr->dest == htons(67) || udphdr->dest == htons(68); - } - - return false; -} - -#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10) /* one unit of budget per 100 ms */ -#define RTW_USB_HIQ_BUDGET_MAX 16 - -static bool rtw_usb_hiq_take_budget(struct rtw_usb *rtwusb) -{ - unsigned long flags, elapsed, add; - bool ok; - - spin_lock_irqsave(&rtwusb->hiq_lock, flags); - - elapsed = jiffies - rtwusb->hiq_refill; - add = elapsed / RTW_USB_HIQ_REFILL_INTERVAL; - if (add) { - rtwusb->hiq_budget = min_t(unsigned long, rtwusb->hiq_budget + add, - RTW_USB_HIQ_BUDGET_MAX); - - /* keep the unfinished part of the interval for the next unit */ - rtwusb->hiq_refill = jiffies - elapsed % RTW_USB_HIQ_REFILL_INTERVAL; - } - - ok = rtwusb->hiq_budget > 0; - if (ok) - rtwusb->hiq_budget--; - - spin_unlock_irqrestore(&rtwusb->hiq_lock, flags); - - return ok; -} - -static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb, +static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_dev *rtwdev, struct sk_buff *skb) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); __le16 fc = hdr->frame_control; u8 qsel; @@ -626,8 +573,7 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb, qsel = TX_DESC_QSEL_MGMT; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel = (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) && - rtw_usb_bmc_needs_dtim(skb) && rtw_usb_hiq_take_budget(rtwusb) ? + qsel = rtw_tx_bmc_use_hiq(rtwdev, skb) ? TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; @@ -647,7 +593,7 @@ static int rtw_usb_tx_write(struct rtw_dev *rtwdev, u8 *pkt_desc; int ep; - pkt_info->qsel = rtw_usb_tx_queue_mapping_to_qsel(rtwusb, skb); + pkt_info->qsel = rtw_usb_tx_queue_mapping_to_qsel(rtwdev, skb); pkt_desc = skb_push(skb, chip->tx_pkt_desc_sz); memset(pkt_desc, 0, chip->tx_pkt_desc_sz); ep = qsel_to_ep(rtwusb, pkt_info->qsel); @@ -1088,10 +1034,6 @@ static int rtw_usb_init_tx(struct rtw_dev *rtwdev) struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev); int i; - spin_lock_init(&rtwusb->hiq_lock); - rtwusb->hiq_budget = RTW_USB_HIQ_BUDGET_MAX; - rtwusb->hiq_refill = jiffies; - rtwusb->txwq = create_singlethread_workqueue("rtw88_usb: tx wq"); if (!rtwusb->txwq) { rtw_err(rtwdev, "failed to create TX work queue\n"); diff --git a/drivers/net/wireless/realtek/rtw88/usb.h b/drivers/net/wireless/realtek/rtw88/usb.h index 94ff21dd08463d..9b695b688b2422 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.h +++ b/drivers/net/wireless/realtek/rtw88/usb.h @@ -75,11 +75,6 @@ struct rtw_usb { u8 out_ep[RTW_USB_EP_MAX]; int qsel_to_ep[TX_DESC_QSEL_MAX]; - /* protects hiq_budget and hiq_refill */ - spinlock_t hiq_lock; - u32 hiq_budget; - unsigned long hiq_refill; - struct workqueue_struct *txwq, *rxwq; struct sk_buff_head tx_queue[RTW_USB_EP_MAX]; diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index 58ee5efc3b5ef1..5220f74d15d2c0 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -6355,8 +6355,8 @@ static int rtw89_init_he_eht_cap(struct rtw89_dev *rtwdev, enum nl80211_iftype iftype; int idx = 0; - iftype_data = devm_kcalloc(rtwdev->dev, RTW89_SBAND_IFTYPES_NR, - sizeof(*iftype_data), GFP_KERNEL); + iftype_data = devm_kzalloc_objs(rtwdev->dev, *iftype_data, + RTW89_SBAND_IFTYPES_NR); if (!iftype_data) return -ENOMEM; diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c index ea7dba077f5d0e..21b548c63c7836 100644 --- a/drivers/net/wireless/realtek/rtw89/fw.c +++ b/drivers/net/wireless/realtek/rtw89/fw.c @@ -1495,7 +1495,7 @@ int rtw89_recognize_regd_from_elm(struct rtw89_dev *rtwdev, elm_info->regd = NULL; } - p = devm_kzalloc(rtwdev->dev, struct_size(p, map, num_ents), GFP_KERNEL); + p = devm_kzalloc_flex(rtwdev->dev, *p, map, num_ents); if (!p) return -ENOMEM; @@ -13573,7 +13573,7 @@ rtw89_fw_cmd_ofld_alloc_and_get_io_ops(struct rtw89_dev *rtwdev) if (!(rtwdev->hci.type == RTW89_HCI_TYPE_USB && chip->support_fw_cmd_ofld)) return &rtw89_raw_io; - info = devm_kzalloc(rtwdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(rtwdev->dev, *info); if (!info) return &rtw89_raw_io; diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c index 795920b899d9e5..e01af08494f9dd 100644 --- a/drivers/net/wireless/realtek/rtw89/phy.c +++ b/drivers/net/wireless/realtek/rtw89/phy.c @@ -8304,8 +8304,8 @@ static void __rtw89_phy_dm_init_data(struct rtw89_dev *rtwdev, struct rtw89_bb_c hw_band = rtw89_nl80211_to_hw_band(band); env->nhm_his[hw_band] = - devm_kcalloc(rtwdev->dev, sband->n_channels, - sizeof(*env->nhm_his[0]), GFP_KERNEL); + devm_kzalloc_objs(rtwdev->dev, *env->nhm_his[0], + sband->n_channels); for (idx = 0; idx < sband->n_channels; idx++) INIT_LIST_HEAD(&env->nhm_his[hw_band][idx].list); diff --git a/drivers/net/wireless/rsi/rsi_91x_core.c b/drivers/net/wireless/rsi/rsi_91x_core.c index ead4d4e0432800..3281fc94e10780 100644 --- a/drivers/net/wireless/rsi/rsi_91x_core.c +++ b/drivers/net/wireless/rsi/rsi_91x_core.c @@ -458,7 +458,7 @@ void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb) tx_params->sta_id = 0; } - if (rsta) { + if (rsta && tid < IEEE80211_NUM_TIDS) { /* Start aggregation if not done for this tid */ if (!rsta->start_tx_aggr[tid]) { rsta->start_tx_aggr[tid] = true; diff --git a/drivers/net/wireless/silabs/wfx/bus_sdio.c b/drivers/net/wireless/silabs/wfx/bus_sdio.c index 1ca2cc262feb21..603a5529830f6d 100644 --- a/drivers/net/wireless/silabs/wfx/bus_sdio.c +++ b/drivers/net/wireless/silabs/wfx/bus_sdio.c @@ -257,7 +257,7 @@ static int wfx_sdio_probe(struct sdio_func *func, const struct sdio_device_id *i return -ENODEV; } - bus = devm_kzalloc(&func->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&func->dev, *bus); if (!bus) return -ENOMEM; diff --git a/drivers/net/wireless/silabs/wfx/bus_spi.c b/drivers/net/wireless/silabs/wfx/bus_spi.c index 45ee19e1ecbf2c..71decbe6c88f97 100644 --- a/drivers/net/wireless/silabs/wfx/bus_spi.c +++ b/drivers/net/wireless/silabs/wfx/bus_spi.c @@ -243,7 +243,7 @@ static int wfx_spi_probe(struct spi_device *func) if (func->max_speed_hz > 50000000) dev_warn(&func->dev, "%dHz is a very high speed\n", func->max_speed_hz); - bus = devm_kzalloc(&func->dev, sizeof(*bus), GFP_KERNEL); + bus = devm_kzalloc_obj(&func->dev, *bus); if (!bus) return -ENOMEM; bus->func = func; diff --git a/drivers/net/wireless/st/cw1200/cw1200_spi.c b/drivers/net/wireless/st/cw1200/cw1200_spi.c index 52386dfb5f4aa9..f71e71e063590c 100644 --- a/drivers/net/wireless/st/cw1200/cw1200_spi.c +++ b/drivers/net/wireless/st/cw1200/cw1200_spi.c @@ -377,7 +377,7 @@ static int cw1200_spi_probe(struct spi_device *func) spi_get_chipselect(func, 0), func->mode, func->bits_per_word, func->max_speed_hz); - self = devm_kzalloc(&func->dev, sizeof(*self), GFP_KERNEL); + self = devm_kzalloc_obj(&func->dev, *self); if (!self) { pr_err("Can't allocate SPI hwbus_priv."); return -ENOMEM; diff --git a/drivers/net/wireless/ti/wl1251/spi.c b/drivers/net/wireless/ti/wl1251/spi.c index 1936bb3af54ab6..cfdc25210e6633 100644 --- a/drivers/net/wireless/ti/wl1251/spi.c +++ b/drivers/net/wireless/ti/wl1251/spi.c @@ -240,7 +240,7 @@ static int wl1251_spi_probe(struct spi_device *spi) if (!np) return -ENODEV; - wl_spi = devm_kzalloc(&spi->dev, sizeof(*wl_spi), GFP_KERNEL); + wl_spi = devm_kzalloc_obj(&spi->dev, *wl_spi); if (!wl_spi) return -ENOMEM; diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c index 421d688ae58b3f..6dde1fa7bcd09b 100644 --- a/drivers/net/wireless/ti/wlcore/sdio.c +++ b/drivers/net/wireless/ti/wlcore/sdio.c @@ -267,13 +267,13 @@ static int wl1271_probe(struct sdio_func *func, if (func->num != 0x02) return -ENODEV; - pdev_data = devm_kzalloc(&func->dev, sizeof(*pdev_data), GFP_KERNEL); + pdev_data = devm_kzalloc_obj(&func->dev, *pdev_data); if (!pdev_data) return -ENOMEM; pdev_data->if_ops = &sdio_ops; - glue = devm_kzalloc(&func->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&func->dev, *glue); if (!glue) return -ENOMEM; diff --git a/drivers/net/wireless/ti/wlcore/spi.c b/drivers/net/wireless/ti/wlcore/spi.c index 0aa2b2f3c5c914..3767ce6578be0b 100644 --- a/drivers/net/wireless/ti/wlcore/spi.c +++ b/drivers/net/wireless/ti/wlcore/spi.c @@ -465,13 +465,13 @@ static int wl1271_probe(struct spi_device *spi) struct resource res[1]; int ret; - pdev_data = devm_kzalloc(&spi->dev, sizeof(*pdev_data), GFP_KERNEL); + pdev_data = devm_kzalloc_obj(&spi->dev, *pdev_data); if (!pdev_data) return -ENOMEM; pdev_data->if_ops = &spi_ops; - glue = devm_kzalloc(&spi->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&spi->dev, *glue); if (!glue) { dev_err(&spi->dev, "can't allocate glue\n"); return -ENOMEM; diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index e53714b81ec2c6..49ec2948c68ab7 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -6179,7 +6179,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info, for (i = 0; i < ARRAY_SIZE(data->link_data); i++) { hrtimer_setup(&data->link_data[i].beacon_timer, mac80211_hwsim_beacon, - CLOCK_MONOTONIC, HRTIMER_MODE_ABS_SOFT); + CLOCK_BOOTTIME, HRTIMER_MODE_ABS_SOFT); data->link_data[i].link_id = i; } @@ -7293,7 +7293,7 @@ static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, { struct netlink_notify *notify = _notify; - if (state != NETLINK_URELEASE) + if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) return NOTIFY_DONE; remove_user_radios(notify->portid, hwsim_net_get_netgroup(notify->net)); diff --git a/drivers/net/wwan/mhi_wwan_ctrl.c b/drivers/net/wwan/mhi_wwan_ctrl.c index e3c20758895657..7723199278671f 100644 --- a/drivers/net/wwan/mhi_wwan_ctrl.c +++ b/drivers/net/wwan/mhi_wwan_ctrl.c @@ -209,9 +209,17 @@ static void mhi_wwan_ctrl_dtr_work(struct work_struct *work) static void mhi_wwan_ctrl_dtr_rts(struct wwan_port *port, unsigned int mdmbits) { struct mhi_wwan_dev *mhiwwan = wwan_port_get_drvdata(port); + bool drop = (READ_ONCE(mhiwwan->dtr_mdmbits) & TIOCM_DTR) && + !(mdmbits & TIOCM_DTR); WRITE_ONCE(mhiwwan->dtr_mdmbits, mdmbits); schedule_delayed_work(&mhiwwan->dtr_work, 0); + + /* A DTR drop matters on its own, e.g. to hang up a modem set to AT&D2, + * so send it now rather than let a following raise coalesce it away + */ + if (drop) + flush_delayed_work(&mhiwwan->dtr_work); } static int mhi_wwan_ctrl_start(struct wwan_port *port) @@ -246,6 +254,9 @@ static void mhi_wwan_ctrl_stop(struct wwan_port *port) cancel_work_sync(&mhiwwan->rx_refill); + /* Send any pending DTR/RTS state before the channel stops */ + flush_delayed_work(&mhiwwan->dtr_work); + mhi_unprepare_from_transfer(mhiwwan->mhi_dev); } diff --git a/drivers/net/wwan/mhi_wwan_mbim.c b/drivers/net/wwan/mhi_wwan_mbim.c index 336f89756f10d8..b13c30debf9fd0 100644 --- a/drivers/net/wwan/mhi_wwan_mbim.c +++ b/drivers/net/wwan/mhi_wwan_mbim.c @@ -621,7 +621,7 @@ static int mhi_mbim_probe(struct mhi_device *mhi_dev, const struct mhi_device_id struct mhi_mbim_context *mbim; int err; - mbim = devm_kzalloc(&mhi_dev->dev, sizeof(*mbim), GFP_KERNEL); + mbim = devm_kzalloc_obj(&mhi_dev->dev, *mbim); if (!mbim) return -ENOMEM; diff --git a/drivers/net/wwan/qcom_bam_dmux.c b/drivers/net/wwan/qcom_bam_dmux.c index cc6ace8d64371e..90801c001fa14a 100644 --- a/drivers/net/wwan/qcom_bam_dmux.c +++ b/drivers/net/wwan/qcom_bam_dmux.c @@ -769,7 +769,7 @@ static int bam_dmux_probe(struct platform_device *pdev) int ret, pc_ack_irq, i; unsigned int bit; - dmux = devm_kzalloc(dev, sizeof(*dmux), GFP_KERNEL); + dmux = devm_kzalloc_obj(dev, *dmux); if (!dmux) return -ENOMEM; diff --git a/drivers/net/wwan/rpmsg_wwan_ctrl.c b/drivers/net/wwan/rpmsg_wwan_ctrl.c index ba17b5ae6bdb8e..cadc02fd13a4f6 100644 --- a/drivers/net/wwan/rpmsg_wwan_ctrl.c +++ b/drivers/net/wwan/rpmsg_wwan_ctrl.c @@ -119,7 +119,7 @@ static int rpmsg_wwan_ctrl_probe(struct rpmsg_device *rpdev) if (!parent) return -ENODEV; - rpwwan = devm_kzalloc(&rpdev->dev, sizeof(*rpwwan), GFP_KERNEL); + rpwwan = devm_kzalloc_obj(&rpdev->dev, *rpwwan); if (!rpwwan) return -ENOMEM; diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c index 2917cee9b80285..e1b37deb6d9bf3 100644 --- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c +++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c @@ -1110,7 +1110,7 @@ int t7xx_cldma_alloc(enum cldma_id hif_id, struct t7xx_pci_dev *t7xx_dev) struct cldma_ctrl *md_ctrl; int qno; - md_ctrl = devm_kzalloc(dev, sizeof(*md_ctrl), GFP_KERNEL); + md_ctrl = devm_kzalloc_obj(dev, *md_ctrl); if (!md_ctrl) return -ENOMEM; diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c index 7ff33c1d6ac75f..48e6230d52870d 100644 --- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c +++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c @@ -542,7 +542,7 @@ struct dpmaif_ctrl *t7xx_dpmaif_hif_init(struct t7xx_pci_dev *t7xx_dev, if (!callbacks) return NULL; - dpmaif_ctrl = devm_kzalloc(dev, sizeof(*dpmaif_ctrl), GFP_KERNEL); + dpmaif_ctrl = devm_kzalloc_obj(dev, *dpmaif_ctrl); if (!dpmaif_ctrl) return NULL; diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c index adb29d30c63fe7..2202bf734a7210 100644 --- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c +++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c @@ -694,7 +694,7 @@ static struct t7xx_modem *t7xx_md_alloc(struct t7xx_pci_dev *t7xx_dev) struct device *dev = &t7xx_dev->pdev->dev; struct t7xx_modem *md; - md = devm_kzalloc(dev, sizeof(*md), GFP_KERNEL); + md = devm_kzalloc_obj(dev, *md); if (!md) return NULL; diff --git a/drivers/net/wwan/t7xx/t7xx_netdev.c b/drivers/net/wwan/t7xx/t7xx_netdev.c index 8f32c2d2693129..ddafc1111a5250 100644 --- a/drivers/net/wwan/t7xx/t7xx_netdev.c +++ b/drivers/net/wwan/t7xx/t7xx_netdev.c @@ -493,7 +493,7 @@ int t7xx_ccmni_init(struct t7xx_pci_dev *t7xx_dev) struct t7xx_ccmni_ctrl *ctlb; int ret; - ctlb = devm_kzalloc(dev, sizeof(*ctlb), GFP_KERNEL); + ctlb = devm_kzalloc_obj(dev, *ctlb); if (!ctlb) return -ENOMEM; diff --git a/drivers/net/wwan/t7xx/t7xx_pci.c b/drivers/net/wwan/t7xx/t7xx_pci.c index 46613bba1f4110..c51c3b2671861b 100644 --- a/drivers/net/wwan/t7xx/t7xx_pci.c +++ b/drivers/net/wwan/t7xx/t7xx_pci.c @@ -840,7 +840,7 @@ static int t7xx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) void __iomem *iomem; int ret; - t7xx_dev = devm_kzalloc(&pdev->dev, sizeof(*t7xx_dev), GFP_KERNEL); + t7xx_dev = devm_kzalloc_obj(&pdev->dev, *t7xx_dev); if (!t7xx_dev) return -ENOMEM; diff --git a/drivers/net/wwan/t7xx/t7xx_port_proxy.c b/drivers/net/wwan/t7xx/t7xx_port_proxy.c index 4fc131f9632f87..977c25ea20f799 100644 --- a/drivers/net/wwan/t7xx/t7xx_port_proxy.c +++ b/drivers/net/wwan/t7xx/t7xx_port_proxy.c @@ -584,11 +584,8 @@ static int t7xx_proxy_alloc(struct t7xx_modem *md) struct device *dev = &md->t7xx_dev->pdev->dev; struct port_proxy *port_prox; - port_prox = devm_kzalloc(dev, - struct_size(port_prox, - ports, - T7XX_MAX_POSSIBLE_PORTS_NUM), - GFP_KERNEL); + port_prox = devm_kzalloc_flex(dev, *port_prox, ports, + T7XX_MAX_POSSIBLE_PORTS_NUM); if (!port_prox) return -ENOMEM; diff --git a/drivers/net/wwan/t7xx/t7xx_state_monitor.c b/drivers/net/wwan/t7xx/t7xx_state_monitor.c index 091d7cabd630f2..52c8f337aa8a29 100644 --- a/drivers/net/wwan/t7xx/t7xx_state_monitor.c +++ b/drivers/net/wwan/t7xx/t7xx_state_monitor.c @@ -613,7 +613,7 @@ int t7xx_fsm_init(struct t7xx_modem *md) struct device *dev = &md->t7xx_dev->pdev->dev; struct t7xx_fsm_ctl *ctl; - ctl = devm_kzalloc(dev, sizeof(*ctl), GFP_KERNEL); + ctl = devm_kzalloc_obj(dev, *ctl); if (!ctl) return -ENOMEM; diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index a0a43888138808..b233834ec6cc75 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -812,8 +812,6 @@ void xenvif_disconnect_data(struct xenvif *vif) xenvif_disconnect_queue(queue); } - - xenvif_mcast_addr_list_free(vif); } void xenvif_disconnect_ctrl(struct xenvif *vif) diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index 3cdb7fd659db86..dc229756bdc288 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c @@ -1530,12 +1530,17 @@ static inline bool tx_dealloc_work_todo(struct xenvif_queue *queue) void xenvif_unmap_frontend_data_rings(struct xenvif_queue *queue) { - if (queue->tx.sring) + if (queue->tx.sring) { xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif), queue->tx.sring); - if (queue->rx.sring) + queue->tx.sring = NULL; + } + + if (queue->rx.sring) { xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif), queue->rx.sring); + queue->rx.sring = NULL; + } } int xenvif_map_frontend_data_rings(struct xenvif_queue *queue, diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index e020f44ac2c717..74c2745086bb0c 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c @@ -267,6 +267,8 @@ static void backend_disconnect(struct backend_info *be) vif->num_queues = 0; synchronize_net(); + xenvif_mcast_addr_list_free(vif); + for (queue_index = 0; queue_index < num_queues; ++queue_index) xenvif_deinit_queue(&vif->queues[queue_index]); @@ -729,6 +731,7 @@ static void connect(struct backend_info *be) unsigned int queue_index; unsigned int requested_num_queues; struct xenvif_queue *queue; + unsigned int num_queues; /* Check whether the frontend requested multiple queues * and read the number requested. @@ -835,13 +838,15 @@ static void connect(struct backend_info *be) return; err: - if (be->vif->num_queues > 0) + num_queues = be->vif->num_queues; + if (num_queues > 0) xenvif_disconnect_data(be->vif); /* Clean up existing queues */ - for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index) + be->vif->num_queues = 0; + synchronize_net(); + for (queue_index = 0; queue_index < num_queues; ++queue_index) xenvif_deinit_queue(&be->vif->queues[queue_index]); vfree(be->vif->queues); be->vif->queues = NULL; - be->vif->num_queues = 0; xenvif_disconnect_ctrl(be->vif); return; } diff --git a/drivers/nfc/fdp/fdp.c b/drivers/nfc/fdp/fdp.c index da3e2dce8e70a6..22a91628a9484b 100644 --- a/drivers/nfc/fdp/fdp.c +++ b/drivers/nfc/fdp/fdp.c @@ -707,7 +707,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, const struct nfc_phy_ops *phy_ops, u32 protocols; int r; - info = devm_kzalloc(dev, sizeof(struct fdp_nci_info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct fdp_nci_info); if (!info) return -ENOMEM; diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index e131f9933a5ab1..5a4718635fdf58 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -322,7 +322,7 @@ static int fdp_nci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(dev, sizeof(struct fdp_i2c_phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, struct fdp_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/microread/i2c.c b/drivers/nfc/microread/i2c.c index f45e883b8730c6..307e9512427df3 100644 --- a/drivers/nfc/microread/i2c.c +++ b/drivers/nfc/microread/i2c.c @@ -235,8 +235,7 @@ static int microread_i2c_probe(struct i2c_client *client) struct microread_i2c_phy *phy; int r; - phy = devm_kzalloc(&client->dev, sizeof(struct microread_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct microread_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/nfcmrvl/i2c.c b/drivers/nfc/nfcmrvl/i2c.c index 068c5d278a3599..66451ad3354ffd 100644 --- a/drivers/nfc/nfcmrvl/i2c.c +++ b/drivers/nfc/nfcmrvl/i2c.c @@ -195,7 +195,7 @@ static int nfcmrvl_i2c_probe(struct i2c_client *client) return -ENODEV; } - drv_data = devm_kzalloc(&client->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&client->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/nfc/nfcmrvl/spi.c b/drivers/nfc/nfcmrvl/spi.c index 8b8f00dac0f811..cbfcf54ecc6068 100644 --- a/drivers/nfc/nfcmrvl/spi.c +++ b/drivers/nfc/nfcmrvl/spi.c @@ -131,7 +131,7 @@ static int nfcmrvl_spi_probe(struct spi_device *spi) struct nfcmrvl_spi_drv_data *drv_data; int ret = 0; - drv_data = devm_kzalloc(&spi->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&spi->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c index c7f2afe00b9363..c9a6b59606cf28 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -297,7 +297,7 @@ static int nfcmrvl_probe(struct usb_interface *intf, nfc_info(&udev->dev, "intf %p id %p\n", intf, id); - drv_data = devm_kzalloc(&intf->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&intf->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/nfc/nxp-nci/core.c b/drivers/nfc/nxp-nci/core.c index 448e5a4e7338f3..7e5b90e56735b1 100644 --- a/drivers/nfc/nxp-nci/core.c +++ b/drivers/nfc/nxp-nci/core.c @@ -140,7 +140,7 @@ int nxp_nci_probe(void *phy_id, struct device *pdev, struct nxp_nci_info *info; int r; - info = devm_kzalloc(pdev, sizeof(struct nxp_nci_info), GFP_KERNEL); + info = devm_kzalloc_obj(pdev, struct nxp_nci_info); if (!info) return -ENOMEM; diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 92ce096e9b189d..9eec67c10934f6 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -284,8 +284,7 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct nxp_nci_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct nxp_nci_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/pn533/i2c.c b/drivers/nfc/pn533/i2c.c index 66d201c14a404b..3c83cdda912e1f 100644 --- a/drivers/nfc/pn533/i2c.c +++ b/drivers/nfc/pn533/i2c.c @@ -174,8 +174,7 @@ static int pn533_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct pn533_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct pn533_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/pn533/usb.c b/drivers/nfc/pn533/usb.c index 972eaac09e5924..a04f10785b3f3e 100644 --- a/drivers/nfc/pn533/usb.c +++ b/drivers/nfc/pn533/usb.c @@ -490,7 +490,7 @@ static int pn533_usb_probe(struct usb_interface *interface, PN533_STD_FRAME_TAIL_LEN; int rc; - phy = devm_kzalloc(&interface->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&interface->dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/pn544/i2c.c b/drivers/nfc/pn544/i2c.c index 7fde3aefae7002..ee8cc2496136a5 100644 --- a/drivers/nfc/pn544/i2c.c +++ b/drivers/nfc/pn544/i2c.c @@ -873,8 +873,7 @@ static int pn544_hci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct pn544_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct pn544_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c index e769a30b8b5c7e..d1873d7af3a8e9 100644 --- a/drivers/nfc/port100.c +++ b/drivers/nfc/port100.c @@ -1502,7 +1502,7 @@ static int port100_probe(struct usb_interface *interface, u16 fw_version; u64 cmd_type_mask; - dev = devm_kzalloc(&interface->dev, sizeof(struct port100), GFP_KERNEL); + dev = devm_kzalloc_obj(&interface->dev, struct port100); if (!dev) return -ENOMEM; diff --git a/drivers/nfc/s3fwrn5/core.c b/drivers/nfc/s3fwrn5/core.c index af0fa8bd970b4f..b46cfdd226e41a 100644 --- a/drivers/nfc/s3fwrn5/core.c +++ b/drivers/nfc/s3fwrn5/core.c @@ -163,7 +163,7 @@ int s3fwrn5_probe(struct nci_dev **ndev, void *phy_id, struct device *pdev, struct s3fwrn5_info *info; int ret; - info = devm_kzalloc(pdev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(pdev, *info); if (!info) return -ENOMEM; diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c index 4ba76261171185..783c874254e9b8 100644 --- a/drivers/nfc/s3fwrn5/i2c.c +++ b/drivers/nfc/s3fwrn5/i2c.c @@ -149,7 +149,7 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client) struct s3fwrn5_i2c_phy *phy; int ret; - phy = devm_kzalloc(&client->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/s3fwrn5/uart.c b/drivers/nfc/s3fwrn5/uart.c index 8f142a25510169..56704416880efd 100644 --- a/drivers/nfc/s3fwrn5/uart.c +++ b/drivers/nfc/s3fwrn5/uart.c @@ -95,7 +95,7 @@ static int s3fwrn82_uart_probe(struct serdev_device *serdev) struct s3fwrn82_uart_phy *phy; int ret = -ENOMEM; - phy = devm_kzalloc(&serdev->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&serdev->dev, *phy); if (!phy) goto err_exit; diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c index a367136d4330a3..1ad3275e6c14ec 100644 --- a/drivers/nfc/st-nci/core.c +++ b/drivers/nfc/st-nci/core.c @@ -116,8 +116,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom, int r; u32 protocols; - info = devm_kzalloc(ndlc->dev, - sizeof(struct st_nci_info), GFP_KERNEL); + info = devm_kzalloc_obj(ndlc->dev, struct st_nci_info); if (!info) return -ENOMEM; diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index 152c20b6bb01ac..b80e6486253096 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -206,7 +206,7 @@ static int st_nci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(dev, sizeof(struct st_nci_i2c_phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, struct st_nci_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/st-nci/ndlc.c b/drivers/nfc/st-nci/ndlc.c index be4808859cfa9f..9c5f7a6043ce09 100644 --- a/drivers/nfc/st-nci/ndlc.c +++ b/drivers/nfc/st-nci/ndlc.c @@ -255,7 +255,7 @@ int ndlc_probe(void *phy_id, const struct nfc_phy_ops *phy_ops, { struct llt_ndlc *ndlc; - ndlc = devm_kzalloc(dev, sizeof(struct llt_ndlc), GFP_KERNEL); + ndlc = devm_kzalloc_obj(dev, struct llt_ndlc); if (!ndlc) return -ENOMEM; diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 7948c7e0c88c01..95ef01ab2b6c11 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -219,8 +219,7 @@ static int st_nci_spi_probe(struct spi_device *dev) return -ENODEV; } - phy = devm_kzalloc(&dev->dev, sizeof(struct st_nci_spi_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&dev->dev, struct st_nci_spi_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c index 0f44c783bd0417..3031a19ac12ac0 100644 --- a/drivers/nfc/st21nfca/i2c.c +++ b/drivers/nfc/st21nfca/i2c.c @@ -506,8 +506,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct st21nfca_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc_obj(&client->dev, struct st21nfca_i2c_phy); if (!phy) return -ENOMEM; diff --git a/drivers/nfc/st95hf/core.c b/drivers/nfc/st95hf/core.c index 4d772a308bfff1..dcc9e53815caee 100644 --- a/drivers/nfc/st95hf/core.c +++ b/drivers/nfc/st95hf/core.c @@ -1070,9 +1070,7 @@ static int st95hf_probe(struct spi_device *nfc_spi_dev) nfc_info(&nfc_spi_dev->dev, "ST95HF driver probe called.\n"); - st95context = devm_kzalloc(&nfc_spi_dev->dev, - sizeof(struct st95hf_context), - GFP_KERNEL); + st95context = devm_kzalloc_obj(&nfc_spi_dev->dev, struct st95hf_context); if (!st95context) return -ENOMEM; diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index ddfc58c2996495..001748d91ec1c1 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2057,7 +2057,7 @@ static int trf7970a_probe(struct spi_device *spi) return -EINVAL; } - trf = devm_kzalloc(&spi->dev, sizeof(*trf), GFP_KERNEL); + trf = devm_kzalloc_obj(&spi->dev, *trf); if (!trf) return -ENOMEM; diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c index c47607d4f8a7f0..95bd344ab37f93 100644 --- a/drivers/ntb/hw/epf/ntb_hw_epf.c +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c @@ -760,7 +760,7 @@ static int ntb_epf_pci_probe(struct pci_dev *pdev, if (pci_is_bridge(pdev)) return -ENODEV; - ndev = devm_kzalloc(dev, sizeof(*ndev), GFP_KERNEL); + ndev = devm_kzalloc_obj(dev, *ndev); if (!ndev) return -ENOMEM; diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c index f27df8d7f3b971..2bf58d0eca36c8 100644 --- a/drivers/ntb/hw/idt/ntb_hw_idt.c +++ b/drivers/ntb/hw/idt/ntb_hw_idt.c @@ -1049,8 +1049,7 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port, int aprt_size; u32 data; - mws = devm_kcalloc(&ndev->ntb.pdev->dev, IDT_MAX_NR_MWS, - sizeof(*mws), GFP_KERNEL); + mws = devm_kzalloc_objs(&ndev->ntb.pdev->dev, *mws, IDT_MAX_NR_MWS); if (!mws) return ERR_PTR(-ENOMEM); @@ -2598,7 +2597,7 @@ static struct idt_ntb_dev *idt_create_dev(struct pci_dev *pdev, struct idt_ntb_dev *ndev; /* Allocate memory for the IDT PCIe-device descriptor */ - ndev = devm_kzalloc(&pdev->dev, sizeof(*ndev), GFP_KERNEL); + ndev = devm_kzalloc_obj(&pdev->dev, *ndev); if (!ndev) { dev_err(&pdev->dev, "Memory allocation failed for descriptor"); return ERR_PTR(-ENOMEM); diff --git a/drivers/ntb/msi.c b/drivers/ntb/msi.c index 6817d504c12ac8..94205ab4612f92 100644 --- a/drivers/ntb/msi.c +++ b/drivers/ntb/msi.c @@ -42,8 +42,7 @@ int ntb_msi_init(struct ntb_dev *ntb, if (peers <= 0) return -EINVAL; - ntb->msi = devm_kzalloc(&ntb->dev, struct_size(ntb->msi, peer_mws, peers), - GFP_KERNEL); + ntb->msi = devm_kzalloc_flex(&ntb->dev, *ntb->msi, peer_mws, peers); if (!ntb->msi) return -ENOMEM; diff --git a/drivers/ntb/test/ntb_msi_test.c b/drivers/ntb/test/ntb_msi_test.c index f52d409ba6d290..e8bcd54638bb85 100644 --- a/drivers/ntb/test/ntb_msi_test.c +++ b/drivers/ntb/test/ntb_msi_test.c @@ -351,12 +351,11 @@ static int ntb_msit_probe(struct ntb_client *client, struct ntb_dev *ntb) return ret; } - nm = devm_kzalloc(&ntb->dev, struct_size(nm, peers, peers), GFP_KERNEL); + nm = devm_kzalloc_flex(&ntb->dev, *nm, peers, peers); if (!nm) return -ENOMEM; - nm->isr_ctx = devm_kcalloc(&ntb->dev, num_irqs, sizeof(*nm->isr_ctx), - GFP_KERNEL); + nm->isr_ctx = devm_kzalloc_objs(&ntb->dev, *nm->isr_ctx, num_irqs); if (!nm->isr_ctx) return -ENOMEM; diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c index dfd175f79e8f08..d8dfb8233c7b1a 100644 --- a/drivers/ntb/test/ntb_perf.c +++ b/drivers/ntb/test/ntb_perf.c @@ -1389,13 +1389,12 @@ static struct perf_ctx *perf_create_data(struct ntb_dev *ntb) { struct perf_ctx *perf; - perf = devm_kzalloc(&ntb->dev, sizeof(*perf), GFP_KERNEL); + perf = devm_kzalloc_obj(&ntb->dev, *perf); if (!perf) return ERR_PTR(-ENOMEM); perf->pcnt = ntb_peer_port_count(ntb); - perf->peers = devm_kcalloc(&ntb->dev, perf->pcnt, sizeof(*perf->peers), - GFP_KERNEL); + perf->peers = devm_kzalloc_objs(&ntb->dev, *perf->peers, perf->pcnt); if (!perf->peers) return ERR_PTR(-ENOMEM); diff --git a/drivers/ntb/test/ntb_pingpong.c b/drivers/ntb/test/ntb_pingpong.c index 1c1c74f4ff2d3a..1bd5ef2c7e857b 100644 --- a/drivers/ntb/test/ntb_pingpong.c +++ b/drivers/ntb/test/ntb_pingpong.c @@ -277,7 +277,7 @@ static struct pp_ctx *pp_create_data(struct ntb_dev *ntb) { struct pp_ctx *pp; - pp = devm_kzalloc(&ntb->dev, sizeof(*pp), GFP_KERNEL); + pp = devm_kzalloc_obj(&ntb->dev, *pp); if (!pp) return ERR_PTR(-ENOMEM); diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c index 06881047f5bcd3..7a880147737ee4 100644 --- a/drivers/ntb/test/ntb_tool.c +++ b/drivers/ntb/test/ntb_tool.c @@ -441,8 +441,7 @@ static int tool_init_peers(struct tool_ctx *tc) int pidx; tc->peer_cnt = ntb_peer_port_count(tc->ntb); - tc->peers = devm_kcalloc(&tc->ntb->dev, tc->peer_cnt, - sizeof(*tc->peers), GFP_KERNEL); + tc->peers = devm_kzalloc_objs(&tc->ntb->dev, *tc->peers, tc->peer_cnt); if (tc->peers == NULL) return -ENOMEM; @@ -961,8 +960,8 @@ static int tool_init_mws(struct tool_ctx *tc) /* Initialize outbound memory windows */ tc->outmw_cnt = ntb_peer_mw_count(tc->ntb); - tc->outmws = devm_kcalloc(&tc->ntb->dev, tc->outmw_cnt, - sizeof(*tc->outmws), GFP_KERNEL); + tc->outmws = devm_kzalloc_objs(&tc->ntb->dev, *tc->outmws, + tc->outmw_cnt); if (tc->outmws == NULL) return -ENOMEM; @@ -976,8 +975,8 @@ static int tool_init_mws(struct tool_ctx *tc) for (pidx = 0; pidx < tc->peer_cnt; pidx++) { tc->peers[pidx].inmw_cnt = ntb_mw_count(tc->ntb, pidx); tc->peers[pidx].inmws = - devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].inmw_cnt, - sizeof(*tc->peers[pidx].inmws), GFP_KERNEL); + devm_kzalloc_objs(&tc->ntb->dev, *tc->peers[pidx].inmws, + tc->peers[pidx].inmw_cnt); if (tc->peers[pidx].inmws == NULL) return -ENOMEM; @@ -989,8 +988,9 @@ static int tool_init_mws(struct tool_ctx *tc) tc->peers[pidx].outmw_cnt = ntb_peer_mw_count(tc->ntb); tc->peers[pidx].outmws = - devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt, - sizeof(*tc->peers[pidx].outmws), GFP_KERNEL); + devm_kzalloc_objs(&tc->ntb->dev, + *tc->peers[pidx].outmws, + tc->peers[pidx].outmw_cnt); if (tc->peers[pidx].outmws == NULL) return -ENOMEM; @@ -1236,8 +1236,8 @@ static int tool_init_spads(struct tool_ctx *tc) /* Initialize inbound scratchpad structures */ tc->inspad_cnt = ntb_spad_count(tc->ntb); - tc->inspads = devm_kcalloc(&tc->ntb->dev, tc->inspad_cnt, - sizeof(*tc->inspads), GFP_KERNEL); + tc->inspads = devm_kzalloc_objs(&tc->ntb->dev, *tc->inspads, + tc->inspad_cnt); if (tc->inspads == NULL) return -ENOMEM; @@ -1251,8 +1251,9 @@ static int tool_init_spads(struct tool_ctx *tc) for (pidx = 0; pidx < tc->peer_cnt; pidx++) { tc->peers[pidx].outspad_cnt = ntb_spad_count(tc->ntb); tc->peers[pidx].outspads = - devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outspad_cnt, - sizeof(*tc->peers[pidx].outspads), GFP_KERNEL); + devm_kzalloc_objs(&tc->ntb->dev, + *tc->peers[pidx].outspads, + tc->peers[pidx].outspad_cnt); if (tc->peers[pidx].outspads == NULL) return -ENOMEM; @@ -1400,8 +1401,8 @@ static int tool_init_msgs(struct tool_ctx *tc) /* Initialize inbound message structures */ tc->inmsg_cnt = ntb_msg_count(tc->ntb); - tc->inmsgs = devm_kcalloc(&tc->ntb->dev, tc->inmsg_cnt, - sizeof(*tc->inmsgs), GFP_KERNEL); + tc->inmsgs = devm_kzalloc_objs(&tc->ntb->dev, *tc->inmsgs, + tc->inmsg_cnt); if (tc->inmsgs == NULL) return -ENOMEM; @@ -1415,8 +1416,9 @@ static int tool_init_msgs(struct tool_ctx *tc) for (pidx = 0; pidx < tc->peer_cnt; pidx++) { tc->peers[pidx].outmsg_cnt = ntb_msg_count(tc->ntb); tc->peers[pidx].outmsgs = - devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmsg_cnt, - sizeof(*tc->peers[pidx].outmsgs), GFP_KERNEL); + devm_kzalloc_objs(&tc->ntb->dev, + *tc->peers[pidx].outmsgs, + tc->peers[pidx].outmsg_cnt); if (tc->peers[pidx].outmsgs == NULL) return -ENOMEM; @@ -1439,7 +1441,7 @@ static struct tool_ctx *tool_create_data(struct ntb_dev *ntb) { struct tool_ctx *tc; - tc = devm_kzalloc(&ntb->dev, sizeof(*tc), GFP_KERNEL); + tc = devm_kzalloc_obj(&ntb->dev, *tc); if (tc == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index 48b6223e259e1f..d7d22689bb6279 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -721,7 +721,7 @@ static int log_set_indices(struct arena_info *arena) static int btt_rtt_init(struct arena_info *arena) { - arena->rtt = kcalloc(arena->nfree, sizeof(u32), GFP_KERNEL); + arena->rtt = kzalloc_objs(u32, arena->nfree); if (arena->rtt == NULL) return -ENOMEM; @@ -1577,7 +1577,7 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize, struct nd_namespace_io *nsio; struct device *dev = &nd_btt->dev; - btt = devm_kzalloc(dev, sizeof(struct btt), GFP_KERNEL); + btt = devm_kzalloc_obj(dev, struct btt); if (!btt) return NULL; @@ -1666,7 +1666,7 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns) return -ENODEV; } - btt_sb = devm_kzalloc(&nd_btt->dev, sizeof(*btt_sb), GFP_KERNEL); + btt_sb = devm_kzalloc_obj(&nd_btt->dev, *btt_sb); if (!btt_sb) return -ENOMEM; diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index d6b2f157368f65..4d269c13d4a41d 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -348,7 +348,7 @@ int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns) btt_dev = __nd_btt_create(nd_region, 0, NULL, ndns); if (!btt_dev) return -ENOMEM; - btt_sb = devm_kzalloc(dev, sizeof(*btt_sb), GFP_KERNEL); + btt_sb = devm_kzalloc_obj(dev, *btt_sb); rc = __nd_btt_probe(to_nd_btt(btt_dev), ndns, btt_sb); dev_dbg(dev, "btt: %s\n", rc == 0 ? dev_name(btt_dev) : ""); if (rc < 0) { diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c index decc70f2fe3ff4..edc9d239c2e3a5 100644 --- a/drivers/nvdimm/dax_devs.c +++ b/drivers/nvdimm/dax_devs.c @@ -110,7 +110,7 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) if (!dax_dev) return -ENOMEM; } - pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); + pfn_sb = devm_kmalloc_obj(dev, *pfn_sb); nd_pfn = &nd_dax->nd_pfn; nd_pfn->pfn_sb = pfn_sb; rc = nd_pfn_validate(nd_pfn, DAX_SIG); diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 8fa9c16aba7ea0..625a35d7e055d5 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -634,7 +634,7 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) } if (!pfn_dev) return -ENOMEM; - pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); + pfn_sb = devm_kmalloc_obj(dev, *pfn_sb); nd_pfn = to_nd_pfn(pfn_dev); nd_pfn->pfn_sb = pfn_sb; rc = nd_pfn_validate(nd_pfn, PFN_SIG); @@ -728,7 +728,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) u64 checksum; int rc; - pfn_sb = devm_kmalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL); + pfn_sb = devm_kmalloc_obj(&nd_pfn->dev, *pfn_sb); if (!pfn_sb) return -ENOMEM; diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 0766a6949b285b..852a5937b2ca1c 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -483,7 +483,7 @@ static int pmem_attach_disk(struct device *dev, void *addr; int rc; - pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL); + pmem = devm_kzalloc_obj(dev, *pmem); if (!pmem) return -ENOMEM; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 7ee3fb1779f733..3e06ff34c4afc6 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -74,7 +74,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) return -EINVAL; } - vpmem = devm_kzalloc(&vdev->dev, sizeof(*vpmem), GFP_KERNEL); + vpmem = devm_kzalloc_obj(&vdev->dev, *vpmem); if (!vpmem) { err = -ENOMEM; goto out_err; diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 32d16c53133bea..87cb51e1f5a7f3 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -35,6 +35,7 @@ struct key *nvme_tls_key_lookup(key_serial_t key_id) } if (nvme_tls_psk_revoked(key)) { pr_err("key id %08x revoked\n", key_id); + key_put(key); return ERR_PTR(-EKEYREVOKED); } return key; diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 4621584b1b6fd8..7e104f43ecc960 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -1437,13 +1437,11 @@ static int apple_nvme_attach_genpd(struct apple_nvme *anv) if (anv->pd_count <= 1) return 0; - anv->pd_dev = devm_kcalloc(dev, anv->pd_count, sizeof(*anv->pd_dev), - GFP_KERNEL); + anv->pd_dev = devm_kzalloc_objs(dev, *anv->pd_dev, anv->pd_count); if (!anv->pd_dev) return -ENOMEM; - anv->pd_link = devm_kcalloc(dev, anv->pd_count, sizeof(*anv->pd_link), - GFP_KERNEL); + anv->pd_link = devm_kzalloc_objs(dev, *anv->pd_link, anv->pd_count); if (!anv->pd_link) return -ENOMEM; @@ -1478,7 +1476,7 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) struct apple_nvme *anv; int ret; - anv = devm_kzalloc(dev, sizeof(*anv), GFP_KERNEL); + anv = devm_kzalloc_obj(dev, *anv); if (!anv) return ERR_PTR(-ENOMEM); diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index a7a4d09644c132..f4aa02869b7904 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2482,6 +2482,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA; else lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA); + if (ns->ctrl->quirks & NVME_QUIRK_NO_FUA) + lim.features &= ~BLK_FEAT_FUA; if (info->is_rotational) lim.features |= BLK_FEAT_ROTATIONAL; @@ -3953,10 +3955,16 @@ static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys, return 0; } +/* The char device of a namespace rather than of a namespace head */ +static bool nvme_is_ns_cdev(struct device *dev) +{ + return dev->parent->class == &nvme_class; +} + static void nvme_cdev_rel(struct device *dev) { ida_free(&nvme_ns_chr_minor_ida, MINOR(dev->devt)); - if (dev->parent->class == &nvme_class) + if (nvme_is_ns_cdev(dev)) nvme_put_ns(container_of(dev, struct nvme_ns, cdev_device)); else nvme_put_ns_head(container_of(dev, struct nvme_ns_head, @@ -3990,6 +3998,14 @@ int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device, device_initialize(cdev_device); cdev_init(cdev, fops); cdev->owner = owner; + /* Undone in nvme_cdev_rel() */ + if (nvme_is_ns_cdev(cdev_device)) + nvme_get_ns(container_of(cdev_device, struct nvme_ns, + cdev_device)); + else + nvme_get_ns_head(container_of(cdev_device, + struct nvme_ns_head, + cdev_device)); ret = cdev_device_add(cdev, cdev_device); if (ret) put_device(cdev_device); @@ -4022,13 +4038,11 @@ static void nvme_add_ns_cdev(struct nvme_ns *ns) { ns->cdev_device.parent = ns->ctrl->device; - nvme_get_ns(ns); /* Undone in nvme_cdev_rel() */ if (nvme_cdev_add(&ns->cdev, &ns->cdev_device, &nvme_ns_chr_fops, ns->ctrl->ops->module, ns->ctrl->instance, ns->head->instance)) { dev_err(ns->ctrl->device, "Unable to create the ng%dn%d device\n", ns->ctrl->instance, ns->head->instance); - nvme_put_ns(ns); return; } set_bit(NVME_NS_CDEV_LIVE, &ns->flags); @@ -4755,9 +4769,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); mutex_lock(&ctrl->namespaces_lock); - list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); + list_splice_init_srcu(&ctrl->namespaces, &ns_list, &ctrl->srcu); mutex_unlock(&ctrl->namespaces_lock); - synchronize_srcu(&ctrl->srcu); list_for_each_entry_safe(ns, next, &ns_list, list) nvme_ns_remove(ns); diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 9e0a0fd77c56e5..ae8059366b57d4 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -681,14 +681,12 @@ static void nvme_add_ns_head_cdev(struct nvme_ns_head *head) { head->cdev_device.parent = &head->subsys->dev; - nvme_get_ns_head(head); /* Undone in nvme_cdev_rel() */ if (nvme_cdev_add(&head->cdev, &head->cdev_device, &nvme_ns_head_chr_fops, THIS_MODULE, head->subsys->instance, head->instance)) { dev_err(disk_to_dev(head->disk), "Unable to create the ng%dn%d device\n", head->subsys->instance, head->instance); - nvme_put_ns_head(head); return; } set_bit(NVME_NSHEAD_CDEV_LIVE, &head->flags); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 2d8f681079e856..8833a463f1c846 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -183,6 +183,12 @@ enum nvme_quirks { * Admin queue DMA buffers must be page aligned */ NVME_QUIRK_ADMIN_PAGE_ALIGN = (1 << 23), + + /* + * The device is extremely slow on FUA writes but fast on Flush; + * do not advertise FUA so the block layer emulates it. + */ + NVME_QUIRK_NO_FUA = (1 << 24), }; static inline char *nvme_quirk_name(enum nvme_quirks q) @@ -236,6 +242,8 @@ static inline char *nvme_quirk_name(enum nvme_quirks q) return "dmapool_align_512"; case NVME_QUIRK_ADMIN_PAGE_ALIGN: return "admin_page_align"; + case NVME_QUIRK_NO_FUA: + return "no_fua"; } return "unknown"; diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 019a1e3cc0a2db..f8088d5aa724cd 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -4430,6 +4430,8 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1344, 0x6004), /* Micron 4100AT */ .driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, }, + { PCI_DEVICE(0x1e0f, 0x0032), /* KIOXIA XG10d */ + .driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, }, { PCI_DEVICE(0x1c5c, 0x1504), /* SK Hynix PC400 */ .driver_data = NVME_QUIRK_DISABLE_WRITE_ZEROES, }, { PCI_DEVICE(0x1c5c, 0x174a), /* SK Hynix P31 SSD */ @@ -4483,6 +4485,8 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1cc1, 0x5350), /* ADATA XPG GAMMIX S50 */ .driver_data = NVME_QUIRK_BOGUS_NID, }, + { PCI_DEVICE(0x1cc1, 0x5370), /* ADATA XPG GAMMIX S70 BLADE */ + .driver_data = NVME_QUIRK_NO_FUA, }, { PCI_DEVICE(0x1dbe, 0x5216), /* Acer/INNOGRIT FA100/5216 NVMe SSD */ .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1dbe, 0x5236), /* ADATA XPG GAMMIX S70 */ diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index fe7dbe26481584..d8b6ac4d83bb96 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -128,8 +128,12 @@ static int nvme_pr_register(struct block_device *bdev, u64 old_key, u64 new_key, data.crkey = cpu_to_le64(old_key); data.nrkey = cpu_to_le64(new_key); - cdw10 = old_key ? NVME_PR_REGISTER_ACT_REPLACE : - NVME_PR_REGISTER_ACT_REG; + if (!new_key) + cdw10 = NVME_PR_REGISTER_ACT_UNREG; + else if (old_key) + cdw10 = NVME_PR_REGISTER_ACT_REPLACE; + else + cdw10 = NVME_PR_REGISTER_ACT_REG; cdw10 |= (flags & PR_FL_IGNORE_KEY) ? NVME_PR_IGNORE_KEY : 0; cdw10 |= NVME_PR_CPTPL_PERSIST; diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 07216890f75c75..32189fdfc0f51d 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -735,7 +735,6 @@ static int nvme_rdma_setup_io_queues(struct nvme_rdma_ctrl *ctrl, for (i = 0; i < nr_queues; i++) { struct nvme_rdma_queue *queue = &ctrl->queues[first + i]; - queue->ctrl = ctrl; queue->queue_size = queue_size; ctxs[i].queue = queue; @@ -798,7 +797,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, bool pi_capable = false; int error; - ctrl->queues[0].ctrl = ctrl; ctrl->queues[0].queue_size = NVME_AQ_DEPTH; error = nvme_rdma_alloc_queue(&ctrl->queues[0]); if (error) @@ -2284,7 +2282,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) { struct nvme_rdma_ctrl *ctrl; - int ret; + int ret, i; ctrl = kzalloc_obj(*ctrl); if (!ctrl) @@ -2343,6 +2341,9 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev, if (!ctrl->queues) goto out_free_ctrl; + for (i = 0; i < ctrl->ctrl.queue_count; i++) + ctrl->queues[i].ctrl = ctrl; + ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, 0 /* no quirks, we're perfect! */); if (ret) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index bc46e5f3eaa79e..7ecc6c007f8d4f 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -199,6 +199,7 @@ struct nvme_tcp_ctrl { struct delayed_work connect_work; struct nvme_tcp_request async_req; u32 io_queues[HCTX_MAX_TYPES]; + unsigned int nr_allocated_queues; struct net *net; }; @@ -2848,8 +2849,6 @@ static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl) static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl) { struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); - /* the same count used to size and initialize the queue array */ - unsigned int nr_queues = NVME_TCP_OPT_NR_QUEUES(nctrl->opts); unsigned int i; if (list_empty_careful(&ctrl->list)) @@ -2862,7 +2861,7 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl) nvmf_free_options(nctrl->opts); free_ctrl: put_net(ctrl->net); - for (i = 0; i < nr_queues; i++) + for (i = 0; i < ctrl->nr_allocated_queues; i++) nvme_tcp_exit_queue(ctrl, i); kfree(ctrl->queues); kfree(ctrl); @@ -3256,13 +3255,14 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } - ctrl->queues = kzalloc_objs(*ctrl->queues, ctrl->ctrl.queue_count); + ctrl->nr_allocated_queues = ctrl->ctrl.queue_count; + ctrl->queues = kzalloc_objs(*ctrl->queues, ctrl->nr_allocated_queues); if (!ctrl->queues) { ret = -ENOMEM; goto out_free_ctrl; } - for (i = 0; i < ctrl->ctrl.queue_count; i++) + for (i = 0; i < ctrl->nr_allocated_queues; i++) nvme_tcp_init_queue(ctrl, i); ctrl->net = get_net(current->nsproxy->net_ns); diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 26028be8fe4d8b..f12d8309864464 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -543,6 +543,15 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) u16 ngrps = 0; u16 status; + /* + * The header and one descriptor per enabled group are the only bytes + * written below; zero the whole transfer first so the unwritten tail + * does not leak stale kernel memory to the host. + */ + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (status) + goto out; + status = NVME_SC_INTERNAL; desc = kmalloc_flex(*desc, nsids, NVMET_MAX_NAMESPACES); if (!desc) @@ -1227,8 +1236,13 @@ u16 nvmet_set_feat_kato(struct nvmet_req *req) { u32 val32 = le32_to_cpu(req->cmd->common.cdw11); + if (val32 > NVMET_MAX_KATO * MSEC_PER_SEC) { + req->error_loc = offsetof(struct nvme_common_command, cdw11); + return NVME_SC_KA_TIMEOUT_INVALID | NVME_STATUS_DNR; + } + nvmet_stop_keep_alive_timer(req->sq->ctrl); - req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000); + req->sq->ctrl->kato = DIV_ROUND_UP_ULL(val32, MSEC_PER_SEC); nvmet_start_keep_alive_timer(req->sq->ctrl); nvmet_set_result(req, req->sq->ctrl->kato); @@ -1326,7 +1340,7 @@ static u16 nvmet_set_feat_arbitration(struct nvmet_req *req) .hpw = (cdw11 >> 24) & 0xff, .mpw = (cdw11 >> 16) & 0xff, .lpw = (cdw11 >> 8) & 0xff, - .ab = cdw11 & 0x3, + .ab = cdw11 & 0x7, }; if (!ctrl->ops->set_feature) { @@ -1481,7 +1495,7 @@ static u16 nvmet_get_feat_arbitration(struct nvmet_req *req) ((u32)arb.hpw << 24) | ((u32)arb.mpw << 16) | ((u32)arb.lpw << 8) | - (arb.ab & 0x3)); + (arb.ab & 0x7)); return NVME_SC_SUCCESS; } diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 574025730834c0..ccba84b1344e0f 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -135,6 +135,7 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset) int ret = 0; struct nvmet_host_link *p; struct nvmet_host *host = NULL; + struct nvme_dhchap_key *host_key, *ctrl_key = NULL; down_read(&nvmet_config_sem); if (nvmet_is_disc_subsys(ctrl->subsys)) @@ -172,55 +173,41 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset) goto out_unlock; } - if (host->dhchap_hash_id == ctrl->shash_id) { - pr_debug("Re-use existing hash ID %d\n", - ctrl->shash_id); - } else { - ctrl->shash_id = host->dhchap_hash_id; - } - - /* Skip the 'DHHC-1:XX:' prefix */ - nvme_auth_free_key(ctrl->host_key); - ctrl->host_key = nvme_auth_extract_key(host->dhchap_secret + 10, - host->dhchap_key_hash); - if (IS_ERR(ctrl->host_key)) { + /* + * Skip the 'DHHC-1:XX:' prefix. Keep the old keys until the new ones + * are there: a controller without a host key needs no authentication. + */ + host_key = nvme_auth_extract_key(host->dhchap_secret + 10, + host->dhchap_key_hash); + if (IS_ERR(host_key)) { ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; - ctrl->host_key = NULL; - goto out_free_hash; + goto out_unlock; } + if (host->dhchap_ctrl_secret) { + ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, + host->dhchap_ctrl_key_hash); + if (IS_ERR(ctrl_key)) { + nvme_auth_free_key(host_key); + ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; + goto out_unlock; + } + } + nvme_auth_free_key(ctrl->host_key); + ctrl->host_key = host_key; + nvme_auth_free_key(ctrl->ctrl_key); + ctrl->ctrl_key = ctrl_key; + ctrl->shash_id = host->dhchap_hash_id; #ifdef CONFIG_NVME_TARGET_AUTH_DEBUG pr_debug("%s: using hash %s key %*ph\n", __func__, ctrl->host_key->hash > 0 ? nvme_auth_hmac_name(ctrl->host_key->hash) : "none", (int)ctrl->host_key->len, ctrl->host_key->key); + if (ctrl->ctrl_key) + pr_debug("%s: using ctrl hash %s key %*ph\n", __func__, + ctrl->ctrl_key->hash > 0 ? + nvme_auth_hmac_name(ctrl->ctrl_key->hash) : "none", + (int)ctrl->ctrl_key->len, ctrl->ctrl_key->key); #endif - nvme_auth_free_key(ctrl->ctrl_key); - if (!host->dhchap_ctrl_secret) { - ctrl->ctrl_key = NULL; - goto out_unlock; - } - - ctrl->ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, - host->dhchap_ctrl_key_hash); - if (IS_ERR(ctrl->ctrl_key)) { - ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; - ctrl->ctrl_key = NULL; - goto out_free_hash; - } -#ifdef CONFIG_NVME_TARGET_AUTH_DEBUG - pr_debug("%s: using ctrl hash %s key %*ph\n", __func__, - ctrl->ctrl_key->hash > 0 ? - nvme_auth_hmac_name(ctrl->ctrl_key->hash) : "none", - (int)ctrl->ctrl_key->len, ctrl->ctrl_key->key); -#endif -out_free_hash: - if (ret) { - if (ctrl->host_key) { - nvme_auth_free_key(ctrl->host_key); - ctrl->host_key = NULL; - } - ctrl->shash_id = 0; - } out_unlock: up_read(&nvmet_config_sem); diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index b3a5242d06f9e3..bde94656e4b743 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -150,7 +150,7 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item, if (nvmet_is_port_enabled(port, __func__)) return -EACCES; - if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1) + if (sscanf(page, "%255s", port->disc_addr.traddr) != 1) return -EINVAL; return count; } @@ -242,7 +242,7 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item, if (nvmet_is_port_enabled(port, __func__)) return -EACCES; - if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1) + if (sscanf(page, "%31s", port->disc_addr.trsvcid) != 1) return -EINVAL; return count; } @@ -1466,8 +1466,10 @@ static ssize_t nvmet_subsys_attr_tbkas_store(struct config_item *item, subsys->tbkas = tbkas; /* Force reconnect */ + mutex_lock(&subsys->lock); list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) ctrl->ops->delete_ctrl(ctrl); + mutex_unlock(&subsys->lock); up_write(&nvmet_config_sem); return count; diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index a8171b88035c58..e31d65228c1198 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -669,13 +669,15 @@ void nvmet_ns_disable(struct nvmet_ns *ns) /* * Now that we removed the namespaces from the lookup list, we * can kill the per_cpu ref and wait for any remaining references - * to be dropped, as well as a RCU grace period for anyone only - * using the namespace under rcu_read_lock(). Note that we can't - * use call_rcu here as we need to ensure the namespaces have - * been fully destroyed before unloading the module. + * to be dropped. Rely on that wait for anyone only using the + * namespace under rcu_read_lock() too: the ref can't drop to zero + * before an RCU grace period has passed since the kill. This only + * holds as long as nothing switches the ref to atomic mode before + * the kill; bring back synchronize_rcu() here if that changes. + * Note that we can't use call_rcu here as we need to ensure the + * namespaces have been fully destroyed before unloading the module. */ percpu_ref_kill(&ns->ref); - synchronize_rcu(); wait_for_completion(&ns->disable_done); percpu_ref_exit(&ns->ref); @@ -804,6 +806,7 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) { struct nvmet_ns *ns = req->ns; struct nvmet_pr_per_ctrl_ref *pc_ref = req->pc_ref; + struct nvmet_passthru *passthru = nvmet_passthru_ref_held(req); if (!req->sq->sqhd_disabled) nvmet_update_sq_head(req); @@ -822,7 +825,8 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) if (ns) nvmet_put_namespace(ns); - nvmet_put_passthru_ref(req); + if (passthru) + nvmet_put_passthru_ref(passthru); } void nvmet_req_complete(struct nvmet_req *req, u16 status) @@ -1120,9 +1124,6 @@ static u16 nvmet_parse_io_cmd(struct nvmet_req *req) if (nvme_is_fabrics(cmd)) return nvmet_parse_fabrics_io_cmd(req); - if (unlikely(!nvmet_check_auth_status(req))) - return NVME_SC_AUTH_REQUIRED | NVME_STATUS_DNR; - ret = nvmet_check_ctrl_status(req); if (unlikely(ret)) return ret; @@ -1620,6 +1621,12 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) u8 dhchap_status; int ret; + if (kato > NVMET_MAX_KATO * MSEC_PER_SEC) { + args->status = NVME_SC_KA_TIMEOUT_INVALID | NVME_STATUS_DNR; + args->error_loc = offsetof(struct nvmf_connect_command, kato); + return NULL; + } + args->status = NVME_SC_CONNECT_INVALID_PARAM | NVME_STATUS_DNR; subsys = nvmet_find_get_subsys(args->port, args->subsysnqn); if (!subsys) { @@ -1681,8 +1688,8 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) nvmet_init_cap(ctrl); WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL); - ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES, - sizeof(__le32), GFP_KERNEL); + ctrl->changed_ns_list = kmalloc_objs(__le32, + NVME_MAX_CHANGED_NAMESPACES); if (!ctrl->changed_ns_list) goto out_free_ctrl; @@ -1694,7 +1701,7 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) kato = NVMET_DISC_KATO_MS; /* keep-alive timeout in seconds */ - ctrl->kato = DIV_ROUND_UP(kato, 1000); + ctrl->kato = DIV_ROUND_UP_ULL(kato, MSEC_PER_SEC); ctrl->err_counter = 0; spin_lock_init(&ctrl->error_lock); diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c index 70136f6c22e8c7..34c2e14d0bd92b 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -301,7 +301,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) nvmet_check_transfer_len(req, tl); return; } - if (tl < offsetof(struct nvmf_auth_dhchap_success2_data, rsvd1)) { + if (tl < sizeof(struct nvmf_auth_dhchap_failure_data)) { status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; req->error_loc = offsetof(struct nvmf_auth_send_command, tl); @@ -448,18 +448,18 @@ void nvmet_execute_auth_send(struct nvmet_req *req) nvmet_req_complete(req, status); } -static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al) +static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al) { struct nvmf_auth_dhchap_challenge_data *data = d; struct nvmet_ctrl *ctrl = req->sq->ctrl; int ret = 0; int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id); - int data_size = sizeof(*data) + hash_len; + size_t data_size = sizeof(*data) + hash_len; if (ctrl->dh_tfm) data_size += ctrl->dh_keysize; if (al < data_size) { - pr_debug("%s: buffer too small (al %d need %d)\n", __func__, + pr_debug("%s: buffer too small (al %u need %zu)\n", __func__, al, data_size); return -EINVAL; } @@ -488,7 +488,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al) return ret; } -static int nvmet_auth_success1(struct nvmet_req *req, void *d, int al) +static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al) { struct nvmf_auth_dhchap_success1_data *data = d; struct nvmet_ctrl *ctrl = req->sq->ctrl; diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index e579a307798b97..80b67608eb155e 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -420,6 +420,8 @@ static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl) static void nvme_loop_delete_ctrl_host(struct nvme_ctrl *ctrl) { nvme_loop_shutdown_ctrl(to_loop_ctrl(ctrl)); + /* Left quiesced if a failed reset has left no admin queue behind */ + nvme_unquiesce_admin_queue(ctrl); nvme_remove_admin_tag_set(ctrl); } @@ -483,9 +485,8 @@ static void nvme_loop_reset_ctrl_work(struct work_struct *work) nvme_cancel_admin_tagset(&ctrl->ctrl); nvme_loop_destroy_admin_queue(ctrl); out_disable: - nvme_remove_admin_tag_set(&ctrl->ctrl); dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); - nvme_uninit_ctrl(&ctrl->ctrl); + nvme_delete_ctrl(&ctrl->ctrl); } static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = { diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index d7804bf91aaa8c..2c2460ef5e2b74 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -7,6 +7,7 @@ #define _NVMET_H #include +#include #include #include #include @@ -714,6 +715,13 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, #define NVMET_KAS 10 #define NVMET_DISC_KATO_MS 120000 +/* + * Largest keep-alive timeout in seconds that can be reported back in + * milliseconds and converted to jiffies without overflowing. + */ +#define NVMET_MAX_KATO \ + min3(U32_MAX / MSEC_PER_SEC, U32_MAX / HZ, MAX_JIFFY_OFFSET / HZ) + int __init nvmet_init_configfs(void); void __exit nvmet_exit_configfs(void); @@ -824,6 +832,15 @@ static inline struct nvmet_passthru *nvmet_subsys_passthru( return subsys->passthru; } +static inline struct nvmet_passthru *nvmet_passthru_ref_held( + struct nvmet_req *req) +{ + if (req->p.ref_held) + return nvmet_req_subsys(req)->passthru; + + return NULL; +} + static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) { if (!percpu_ref_tryget_live(&nvmet_req_subsys(req)->passthru->ref)) @@ -833,13 +850,9 @@ static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) return true; } -static inline void nvmet_put_passthru_ref(struct nvmet_req *req) +static inline void nvmet_put_passthru_ref(struct nvmet_passthru *passthru) { - if (!req->p.ref_held) - return; - - req->p.ref_held = false; - percpu_ref_put(&nvmet_req_subsys(req)->passthru->ref); + percpu_ref_put(&passthru->ref); } #else /* CONFIG_NVME_TARGET_PASSTHRU */ static inline void nvmet_passthru_subsys_free(struct nvmet_subsys *subsys) @@ -865,11 +878,16 @@ static inline struct nvmet_passthru *nvmet_subsys_passthru( { return NULL; } +static inline struct nvmet_passthru *nvmet_passthru_ref_held( + struct nvmet_req *req) +{ + return NULL; +} static inline bool nvmet_get_passthru_ref(struct nvmet_req *req) { return false; } -static inline void nvmet_put_passthru_ref(struct nvmet_req *req) +static inline void nvmet_put_passthru_ref(struct nvmet_passthru *passthru) { } #endif /* CONFIG_NVME_TARGET_PASSTHRU */ diff --git a/drivers/nvme/target/pci-epf.c b/drivers/nvme/target/pci-epf.c index a8df176c1a574f..670068d1ee3e36 100644 --- a/drivers/nvme/target/pci-epf.c +++ b/drivers/nvme/target/pci-epf.c @@ -2464,7 +2464,7 @@ static int nvmet_pci_epf_probe(struct pci_epf *epf, struct nvmet_pci_epf *nvme_epf; int ret; - nvme_epf = devm_kzalloc(&epf->dev, sizeof(*nvme_epf), GFP_KERNEL); + nvme_epf = devm_kzalloc_obj(&epf->dev, *nvme_epf); if (!nvme_epf) return -ENOMEM; @@ -2611,7 +2611,7 @@ static const struct pci_epf_device_id nvmet_pci_epf_ids[] = { {}, }; -static struct pci_epf_ops nvmet_pci_epf_ops = { +static const struct pci_epf_ops nvmet_pci_epf_ops = { .bind = nvmet_pci_epf_bind, .unbind = nvmet_pci_epf_unbind, .add_cfs = nvmet_pci_epf_add_cfs, diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index b9e39d1657d29f..f386c388da188c 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -71,7 +71,6 @@ struct nvmet_rdma_rsp { struct nvmet_req req; - bool allocated; u8 n_rdma; u32 flags; u32 invalidate_rkey; @@ -1197,13 +1196,18 @@ static void nvmet_rdma_free_dev(struct kref *ref) struct nvmet_rdma_device *ndev = container_of(ref, struct nvmet_rdma_device, ref); + nvmet_rdma_destroy_srqs(ndev); + ib_dealloc_pd(ndev->pd); + + /* + * Only delete from the device list once all RDMA resources are torn + * down because nvmet_rdma_remove_one waits for the release work only + * if the device still is on the list. + */ mutex_lock(&device_list_mutex); list_del(&ndev->entry); mutex_unlock(&device_list_mutex); - nvmet_rdma_destroy_srqs(ndev); - ib_dealloc_pd(ndev->pd); - kfree(ndev); } @@ -1694,7 +1698,7 @@ static void nvmet_rdma_queue_established(struct nvmet_rdma_queue *queue) static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) { - bool disconnect = false; + bool disconnect = false, live = false; unsigned long flags; pr_debug("cm_id= %p queue->state= %d\n", queue->cm_id, queue->state); @@ -1713,6 +1717,7 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) } fallthrough; case NVMET_RDMA_Q_LIVE: + live = queue->state == NVMET_RDMA_Q_LIVE; queue->state = NVMET_RDMA_Q_DISCONNECTING; disconnect = true; break; @@ -1722,24 +1727,34 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) spin_unlock_irqrestore(&queue->state_lock, flags); if (disconnect) { - rdma_disconnect(queue->cm_id); + /* + * Over iWARP rdma_disconnect() sleeps until the CM has handled + * the ESTABLISHED event of this connection. The CM handles the + * events of all connections one at a time, and our handler + * takes nvmet_rdma_queue_mutex, which callers of this function + * hold. So a queue that has not seen the event is left to the + * release work: ib_drain_qp() moves the queue pair to the error + * state, which ends the connection. + */ + if (live) + rdma_disconnect(queue->cm_id); queue_work(nvmet_wq, &queue->release_work); } } static void nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue) { - bool disconnect = false; - + /* + * Queue the release work with &nvmet_rdma_queue_mutex held, so that + * nvmet_rdma_remove_one() either finds the queue on the list or the + * work has already been queued. + */ mutex_lock(&nvmet_rdma_queue_mutex); if (!list_empty(&queue->queue_list)) { list_del_init(&queue->queue_list); - disconnect = true; + __nvmet_rdma_queue_disconnect(queue); } mutex_unlock(&nvmet_rdma_queue_mutex); - - if (disconnect) - __nvmet_rdma_queue_disconnect(queue); } static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id, @@ -1766,10 +1781,13 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id, * queue cm_id and/or a device bound listener cm_id (where in this * case queue will be null). * - * We registered an ib_client to handle device removal for queues, - * so we only need to handle the listening port cm_ids. In this case - * we nullify the priv to prevent double cm_id destruction and destroying - * the cm_id implicitly by returning a non-zero rc to the callout. + * The RDMA CM waits until each cm_id of the device is destroyed, so a queue + * has to go now. Our ib_client also removes the queues, but it cannot be + * relied on here: built in, it is called after the RDMA CM's client. + * + * For a listening port cm_id we nullify the priv to prevent double cm_id + * destruction and destroying the cm_id implicitly by returning a non-zero + * rc to the callout. */ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, struct nvmet_rdma_queue *queue) @@ -1777,11 +1795,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, struct nvmet_rdma_port *port; if (queue) { - /* - * This is a queue cm_id. we have registered - * an ib_client to handle queues removal - * so don't interfere and just return. - */ + nvmet_rdma_queue_disconnect(queue); return 0; } diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 8092ce4914b62c..5105317cc61e3c 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -102,6 +102,7 @@ MODULE_PARM_DESC(tls_handshake_timeout, #define NVMET_TCP_RECV_BUDGET 8 #define NVMET_TCP_SEND_BUDGET 8 #define NVMET_TCP_IO_WORK_BUDGET 64 +#define NVMET_TCP_ACCEPT_BUDGET 16 enum nvmet_tcp_send_state { NVMET_TCP_SEND_DATA_PDU, @@ -1302,6 +1303,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) int len, ret; while (msg_data_left(&cmd->recv_msg)) { + if (queue->tls_pskid) { + /* The last receive has used it up */ + cmd->recv_msg.msg_control = cmd->recv_cbuf; + cmd->recv_msg.msg_controllen = sizeof(cmd->recv_cbuf); + } len = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, cmd->recv_msg.msg_flags); if (len <= 0) @@ -2068,9 +2074,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w) struct nvmet_tcp_port *port = container_of(w, struct nvmet_tcp_port, accept_work); struct socket *newsock; - int ret; + int ret, i; - while (true) { + for (i = 0; i < NVMET_TCP_ACCEPT_BUDGET; i++) { ret = kernel_accept(port->sock, &newsock, O_NONBLOCK); if (ret < 0) { if (ret != -EAGAIN) @@ -2079,6 +2085,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w) } nvmet_tcp_alloc_queue(port, newsock); } + + /* There may be more. Come to an end for those who flush nvmet_wq. */ + queue_work(nvmet_wq, &port->accept_work); } static void nvmet_tcp_listen_data_ready(struct sock *sk) diff --git a/drivers/nvmem/airoha-smc-efuses.c b/drivers/nvmem/airoha-smc-efuses.c index e56a99f4aa1f93..f43c8c4c30cefd 100644 --- a/drivers/nvmem/airoha-smc-efuses.c +++ b/drivers/nvmem/airoha-smc-efuses.c @@ -75,7 +75,7 @@ static int airoha_efuse_probe(struct platform_device *pdev) if (ret) return ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/apple-efuses.c b/drivers/nvmem/apple-efuses.c index 9913e77b8ff067..96efd8c6aff8e8 100644 --- a/drivers/nvmem/apple-efuses.c +++ b/drivers/nvmem/apple-efuses.c @@ -45,7 +45,7 @@ static int apple_efuses_probe(struct platform_device *pdev) .root_only = true, }; - priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(config.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/at24.c b/drivers/nvmem/at24.c index 772c4d9fa65124..b9db13cc3e33b5 100644 --- a/drivers/nvmem/at24.c +++ b/drivers/nvmem/at24.c @@ -683,8 +683,7 @@ static int at24_probe(struct i2c_client *client) if (IS_ERR(regmap)) return PTR_ERR(regmap); - at24 = devm_kzalloc(dev, struct_size(at24, client_regmaps, num_addresses), - GFP_KERNEL); + at24 = devm_kzalloc_flex(dev, *at24, client_regmaps, num_addresses); if (!at24) return -ENOMEM; diff --git a/drivers/nvmem/at25.c b/drivers/nvmem/at25.c index bc2cfb75d9bb40..72240dabdc3b4c 100644 --- a/drivers/nvmem/at25.c +++ b/drivers/nvmem/at25.c @@ -487,7 +487,7 @@ static int at25_probe(struct spi_mem *mem) bool is_fram; int err; - at25 = devm_kzalloc(&spi->dev, sizeof(*at25), GFP_KERNEL); + at25 = devm_kzalloc_obj(&spi->dev, *at25); if (!at25) return -ENOMEM; diff --git a/drivers/nvmem/bcm-ocotp.c b/drivers/nvmem/bcm-ocotp.c index 2490f44caa409c..6c06c6ed03e315 100644 --- a/drivers/nvmem/bcm-ocotp.c +++ b/drivers/nvmem/bcm-ocotp.c @@ -248,7 +248,7 @@ static int bcm_otpc_probe(struct platform_device *pdev) int err; u32 num_words; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c index 9f77aee37121fe..1935fe64e7ae8c 100644 --- a/drivers/nvmem/brcm_nvram.c +++ b/drivers/nvmem/brcm_nvram.c @@ -138,7 +138,7 @@ static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, priv->ncells++; } - priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); + priv->cells = devm_kzalloc_objs(dev, *priv->cells, priv->ncells); if (!priv->cells) { err = -ENOMEM; goto out; @@ -219,7 +219,7 @@ static int brcm_nvram_probe(struct platform_device *pdev) struct brcm_nvram *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 7d4cce8e27424a..d976c0d6603bab 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -494,12 +494,11 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) /* Allocate an array of attributes with a sentinel */ ncells = list_count_nodes(&nvmem->cells); - pattrs = devm_kcalloc(&nvmem->dev, ncells + 1, - sizeof(*pattrs), GFP_KERNEL); + pattrs = devm_kzalloc_objs(&nvmem->dev, *pattrs, ncells + 1); if (!pattrs) return -ENOMEM; - attrs = devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute), GFP_KERNEL); + attrs = devm_kzalloc_objs(&nvmem->dev, struct bin_attribute, ncells); if (!attrs) return -ENOMEM; diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c index f9c3ab52c2f921..fe50956a3e6702 100644 --- a/drivers/nvmem/eeprom_93xx46.c +++ b/drivers/nvmem/eeprom_93xx46.c @@ -417,7 +417,7 @@ static int eeprom_93xx46_probe_fw(struct device *dev) u32 tmp; int ret; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; @@ -472,7 +472,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi) return -ENODEV; } - edev = devm_kzalloc(&spi->dev, sizeof(*edev), GFP_KERNEL); + edev = devm_kzalloc_obj(&spi->dev, *edev); if (!edev) return -ENOMEM; diff --git a/drivers/nvmem/imx-iim.c b/drivers/nvmem/imx-iim.c index 8cfbe55a56cb30..2e8995040ee737 100644 --- a/drivers/nvmem/imx-iim.c +++ b/drivers/nvmem/imx-iim.c @@ -101,7 +101,7 @@ static int imx_iim_probe(struct platform_device *pdev) struct nvmem_config cfg = {}; const struct imx_iim_drvdata *drvdata = NULL; - iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL); + iim = devm_kzalloc_obj(dev, *iim); if (!iim) return -ENOMEM; diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index a0d2985c6d0304..0a122984d66726 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -141,7 +141,7 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev) struct imx_ocotp_priv *priv; struct nvmem_device *nvmem; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/imx-ocotp-scu.c b/drivers/nvmem/imx-ocotp-scu.c index 517d83e11af2c6..20312fba22d230 100644 --- a/drivers/nvmem/imx-ocotp-scu.c +++ b/drivers/nvmem/imx-ocotp-scu.c @@ -243,7 +243,7 @@ static int imx_scu_ocotp_probe(struct platform_device *pdev) struct nvmem_device *nvmem; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 108d78d7f6cba6..55e07fd919a21d 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -599,7 +599,7 @@ static int imx_ocotp_probe(struct platform_device *pdev) struct ocotp_priv *priv; struct nvmem_device *nvmem; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/jz4780-efuse.c b/drivers/nvmem/jz4780-efuse.c index 0b01b840edd9fc..43fa780daf63e8 100644 --- a/drivers/nvmem/jz4780-efuse.c +++ b/drivers/nvmem/jz4780-efuse.c @@ -148,7 +148,7 @@ static int jz4780_efuse_probe(struct platform_device *pdev) void __iomem *regs; int ret; - efuse = devm_kzalloc(dev, sizeof(*efuse), GFP_KERNEL); + efuse = devm_kzalloc_obj(dev, *efuse); if (!efuse) return -ENOMEM; diff --git a/drivers/nvmem/lan9662-otpc.c b/drivers/nvmem/lan9662-otpc.c index 62d1d6381bf884..a83c6679b8a163 100644 --- a/drivers/nvmem/lan9662-otpc.c +++ b/drivers/nvmem/lan9662-otpc.c @@ -183,7 +183,7 @@ static int lan9662_otp_probe(struct platform_device *pdev) struct nvmem_device *nvmem; struct lan9662_otp *otp; - otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL); + otp = devm_kzalloc_obj(&pdev->dev, *otp); if (!otp) return -ENOMEM; diff --git a/drivers/nvmem/layerscape-sfp.c b/drivers/nvmem/layerscape-sfp.c index c1521afd5b43f8..5a4692b425204c 100644 --- a/drivers/nvmem/layerscape-sfp.c +++ b/drivers/nvmem/layerscape-sfp.c @@ -50,7 +50,7 @@ static int layerscape_sfp_probe(struct platform_device *pdev) struct regmap_config config = { 0 }; void __iomem *base; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/lpc18xx_eeprom.c b/drivers/nvmem/lpc18xx_eeprom.c index 504155e30bab29..e393dacb4bf40b 100644 --- a/drivers/nvmem/lpc18xx_eeprom.c +++ b/drivers/nvmem/lpc18xx_eeprom.c @@ -167,7 +167,7 @@ static int lpc18xx_eeprom_probe(struct platform_device *pdev) struct resource *res; int ret; - eeprom = devm_kzalloc(dev, sizeof(*eeprom), GFP_KERNEL); + eeprom = devm_kzalloc_obj(dev, *eeprom); if (!eeprom) return -ENOMEM; diff --git a/drivers/nvmem/lpc18xx_otp.c b/drivers/nvmem/lpc18xx_otp.c index c41a0c58bec765..a6cb46e2051145 100644 --- a/drivers/nvmem/lpc18xx_otp.c +++ b/drivers/nvmem/lpc18xx_otp.c @@ -68,7 +68,7 @@ static int lpc18xx_otp_probe(struct platform_device *pdev) struct nvmem_device *nvmem; struct lpc18xx_otp *otp; - otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL); + otp = devm_kzalloc_obj(&pdev->dev, *otp); if (!otp) return -ENOMEM; diff --git a/drivers/nvmem/m24lr.c b/drivers/nvmem/m24lr.c index 7a9fd45a8e460c..04bec3a5b13801 100644 --- a/drivers/nvmem/m24lr.c +++ b/drivers/nvmem/m24lr.c @@ -506,7 +506,7 @@ static int m24lr_probe(struct i2c_client *client) if (!chip) return -ENODEV; - m24lr = devm_kzalloc(dev, sizeof(struct m24lr), GFP_KERNEL); + m24lr = devm_kzalloc_obj(dev, struct m24lr); if (!m24lr) return -ENOMEM; diff --git a/drivers/nvmem/max77759-nvmem.c b/drivers/nvmem/max77759-nvmem.c index 283000ec3a2ce9..fdab306fd14945 100644 --- a/drivers/nvmem/max77759-nvmem.c +++ b/drivers/nvmem/max77759-nvmem.c @@ -103,7 +103,7 @@ static int max77759_nvmem_probe(struct platform_device *pdev) }; struct max77759_nvmem *nvmem; - nvmem = devm_kzalloc(&pdev->dev, sizeof(*nvmem), GFP_KERNEL); + nvmem = devm_kzalloc_obj(&pdev->dev, *nvmem); if (!nvmem) return -ENOMEM; diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c index d7f9ac99a212f1..2b2a2c515ce09f 100644 --- a/drivers/nvmem/meson-efuse.c +++ b/drivers/nvmem/meson-efuse.c @@ -73,7 +73,7 @@ static int meson_efuse_probe(struct platform_device *pdev) return -EINVAL; } - econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); + econfig = devm_kzalloc_obj(dev, *econfig); if (!econfig) return -ENOMEM; diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c index 8a16f5f0265790..ec27ce932f196f 100644 --- a/drivers/nvmem/meson-mx-efuse.c +++ b/drivers/nvmem/meson-mx-efuse.c @@ -198,7 +198,7 @@ static int meson_mx_efuse_probe(struct platform_device *pdev) if (!drvdata) return -EINVAL; - efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); + efuse = devm_kzalloc_obj(&pdev->dev, *efuse); if (!efuse) return -ENOMEM; diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c index df979e8549fdb4..92524016a8fb48 100644 --- a/drivers/nvmem/microchip-otpc.c +++ b/drivers/nvmem/microchip-otpc.c @@ -209,7 +209,7 @@ static int mchp_otpc_init_packets_list(struct mchp_otpc *otpc, u32 *size) if (!payload_size) break; - packet = devm_kzalloc(otpc->dev, sizeof(*packet), GFP_KERNEL); + packet = devm_kzalloc_obj(otpc->dev, *packet); if (!packet) return -ENOMEM; @@ -247,7 +247,7 @@ static int mchp_otpc_probe(struct platform_device *pdev) u32 size; int ret; - otpc = devm_kzalloc(&pdev->dev, sizeof(*otpc), GFP_KERNEL); + otpc = devm_kzalloc_obj(&pdev->dev, *otpc); if (!otpc) return -ENOMEM; diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index 00a84ea963a823..25669619de1737 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -69,7 +69,7 @@ static int mtk_efuse_probe(struct platform_device *pdev) const struct mtk_efuse_pdata *pdata; struct platform_device *socinfo; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/mxs-ocotp.c b/drivers/nvmem/mxs-ocotp.c index 7b78f18f954595..fa62c11f779acd 100644 --- a/drivers/nvmem/mxs-ocotp.c +++ b/drivers/nvmem/mxs-ocotp.c @@ -147,7 +147,7 @@ static int mxs_ocotp_probe(struct platform_device *pdev) if (!data) return -EINVAL; - otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL); + otp = devm_kzalloc_obj(dev, *otp); if (!otp) return -ENOMEM; diff --git a/drivers/nvmem/nintendo-otp.c b/drivers/nvmem/nintendo-otp.c index a4d986e4588ea2..4035a77522d0c3 100644 --- a/drivers/nvmem/nintendo-otp.c +++ b/drivers/nvmem/nintendo-otp.c @@ -85,7 +85,7 @@ static int nintendo_otp_probe(struct platform_device *pdev) .root_only = true, }; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c index 2aec95dff05d84..1199ce2474eb43 100644 --- a/drivers/nvmem/qcom-spmi-sdam.c +++ b/drivers/nvmem/qcom-spmi-sdam.c @@ -124,7 +124,7 @@ static int sdam_probe(struct platform_device *pdev) unsigned int val; int rc; - sdam = devm_kzalloc(&pdev->dev, sizeof(*sdam), GFP_KERNEL); + sdam = devm_kzalloc_obj(&pdev->dev, *sdam); if (!sdam) return -ENOMEM; diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index 1de3435df116de..bc66cbf0eaa07a 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c @@ -383,7 +383,7 @@ static int qfprom_probe(struct platform_device *pdev) struct qfprom_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/qoriq-efuse.c b/drivers/nvmem/qoriq-efuse.c index 80f514939ae697..a8411d868fc2f3 100644 --- a/drivers/nvmem/qoriq-efuse.c +++ b/drivers/nvmem/qoriq-efuse.c @@ -42,7 +42,7 @@ static int qoriq_efuse_probe(struct platform_device *pdev) struct nvmem_device *nvmem; struct resource *res; - priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(config.dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/rave-sp-eeprom.c b/drivers/nvmem/rave-sp-eeprom.c index 9ecf3873cbb765..980af01db709f0 100644 --- a/drivers/nvmem/rave-sp-eeprom.c +++ b/drivers/nvmem/rave-sp-eeprom.c @@ -309,7 +309,7 @@ static int rave_sp_eeprom_probe(struct platform_device *pdev) return -EINVAL; } - eeprom = devm_kzalloc(dev, sizeof(*eeprom), GFP_KERNEL); + eeprom = devm_kzalloc_obj(dev, *eeprom); if (!eeprom) return -ENOMEM; diff --git a/drivers/nvmem/rcar-efuse.c b/drivers/nvmem/rcar-efuse.c index b94ff83b7df3f1..844c859b846621 100644 --- a/drivers/nvmem/rcar-efuse.c +++ b/drivers/nvmem/rcar-efuse.c @@ -67,7 +67,7 @@ static int rcar_fuse_probe(struct platform_device *pdev) if (ret < 0) return ret; - fuse = devm_kzalloc(dev, sizeof(*fuse), GFP_KERNEL); + fuse = devm_kzalloc_obj(dev, *fuse); if (!fuse) return -ENOMEM; diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index b39d628cb60a1c..16ee0351c47c83 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -124,7 +124,7 @@ static int rmem_probe(struct platform_device *pdev) struct reserved_mem *mem; struct rmem *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/nvmem/rockchip-efuse.c b/drivers/nvmem/rockchip-efuse.c index 013e67136f3b9d..1b53c25680d555 100644 --- a/drivers/nvmem/rockchip-efuse.c +++ b/drivers/nvmem/rockchip-efuse.c @@ -264,8 +264,7 @@ static int rockchip_efuse_probe(struct platform_device *pdev) return -EINVAL; } - efuse = devm_kzalloc(dev, sizeof(struct rockchip_efuse_chip), - GFP_KERNEL); + efuse = devm_kzalloc_obj(dev, struct rockchip_efuse_chip); if (!efuse) return -ENOMEM; diff --git a/drivers/nvmem/rockchip-otp.c b/drivers/nvmem/rockchip-otp.c index f8a8c7cece98d1..7eb834516ab4b5 100644 --- a/drivers/nvmem/rockchip-otp.c +++ b/drivers/nvmem/rockchip-otp.c @@ -432,8 +432,7 @@ static int rockchip_otp_probe(struct platform_device *pdev) if (!data) return dev_err_probe(dev, -EINVAL, "failed to get match data\n"); - otp = devm_kzalloc(&pdev->dev, struct_size(otp, clks, data->num_clks), - GFP_KERNEL); + otp = devm_kzalloc_flex(&pdev->dev, *otp, clks, data->num_clks); if (!otp) return -ENOMEM; diff --git a/drivers/nvmem/s32g-ocotp-nvmem.c b/drivers/nvmem/s32g-ocotp-nvmem.c index 119871ab3a94c0..1167f275585f14 100644 --- a/drivers/nvmem/s32g-ocotp-nvmem.c +++ b/drivers/nvmem/s32g-ocotp-nvmem.c @@ -68,7 +68,7 @@ static int s32g_ocotp_probe(struct platform_device *pdev) struct nvmem_device *nvmem; struct resource *res; - s32g_data = devm_kzalloc(dev, sizeof(*s32g_data), GFP_KERNEL); + s32g_data = devm_kzalloc_obj(dev, *s32g_data); if (!s32g_data) return -ENOMEM; diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c index 4e2ffefac96c91..3e17121221301c 100644 --- a/drivers/nvmem/sc27xx-efuse.c +++ b/drivers/nvmem/sc27xx-efuse.c @@ -207,7 +207,7 @@ static int sc27xx_efuse_probe(struct platform_device *pdev) struct sc27xx_efuse *efuse; int ret; - efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); + efuse = devm_kzalloc_obj(&pdev->dev, *efuse); if (!efuse) return -ENOMEM; diff --git a/drivers/nvmem/sec-qfprom.c b/drivers/nvmem/sec-qfprom.c index 51d21e65a54370..f64ca891a6cda3 100644 --- a/drivers/nvmem/sec-qfprom.c +++ b/drivers/nvmem/sec-qfprom.c @@ -57,7 +57,7 @@ static int sec_qfprom_probe(struct platform_device *pdev) struct sec_qfprom *priv; struct resource *res; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/snvs_lpgpr.c b/drivers/nvmem/snvs_lpgpr.c index 89c27112320f2d..fa5f53cdde4d79 100644 --- a/drivers/nvmem/snvs_lpgpr.c +++ b/drivers/nvmem/snvs_lpgpr.c @@ -99,7 +99,7 @@ static int snvs_lpgpr_probe(struct platform_device *pdev) if (!node) return -ENOENT; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c index 1a7e4e5d8b86c6..5395eb460d3403 100644 --- a/drivers/nvmem/sprd-efuse.c +++ b/drivers/nvmem/sprd-efuse.c @@ -373,7 +373,7 @@ static int sprd_efuse_probe(struct platform_device *pdev) return -EINVAL; } - efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); + efuse = devm_kzalloc_obj(&pdev->dev, *efuse); if (!efuse) return -ENOMEM; diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c index 82879b1c9eb93e..bc00988ff3c049 100644 --- a/drivers/nvmem/stm32-romem.c +++ b/drivers/nvmem/stm32-romem.c @@ -194,7 +194,7 @@ static int stm32_romem_probe(struct platform_device *pdev) struct resource *res; int rc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/sunplus-ocotp.c b/drivers/nvmem/sunplus-ocotp.c index 6884def3ba5f85..c7df9baf2c6daa 100644 --- a/drivers/nvmem/sunplus-ocotp.c +++ b/drivers/nvmem/sunplus-ocotp.c @@ -160,7 +160,7 @@ static int sp_ocotp_probe(struct platform_device *pdev) struct sp_ocotp_priv *otp; int ret; - otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL); + otp = devm_kzalloc_obj(dev, *otp); if (!otp) return -ENOMEM; diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index ba14a76208ab68..51fb10285110b0 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -131,7 +131,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) char *randomness; const struct sunxi_sid_cfg *cfg; - sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); + sid = devm_kzalloc_obj(dev, *sid); if (!sid) return -ENOMEM; @@ -146,7 +146,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) size = cfg->size; - nvmem_cfg = devm_kzalloc(dev, sizeof(*nvmem_cfg), GFP_KERNEL); + nvmem_cfg = devm_kzalloc_obj(dev, *nvmem_cfg); if (!nvmem_cfg) return -ENOMEM; diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 467b288918db22..a9cb1bc5b77918 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -52,7 +52,7 @@ static int u_boot_env_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct u_boot_env *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; diff --git a/drivers/nvmem/uniphier-efuse.c b/drivers/nvmem/uniphier-efuse.c index 85f9372fb97cad..bf2f298a0f6f61 100644 --- a/drivers/nvmem/uniphier-efuse.c +++ b/drivers/nvmem/uniphier-efuse.c @@ -36,7 +36,7 @@ static int uniphier_efuse_probe(struct platform_device *pdev) struct nvmem_config econfig = {}; struct uniphier_efuse_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c index ee9c61ae727da2..6e5170f3960293 100644 --- a/drivers/nvmem/vf610-ocotp.c +++ b/drivers/nvmem/vf610-ocotp.c @@ -215,7 +215,7 @@ static int vf610_ocotp_probe(struct platform_device *pdev) struct resource *res; struct vf610_ocotp *ocotp_dev; - ocotp_dev = devm_kzalloc(dev, sizeof(struct vf610_ocotp), GFP_KERNEL); + ocotp_dev = devm_kzalloc_obj(dev, struct vf610_ocotp); if (!ocotp_dev) return -ENOMEM; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e255f54f4d7606..4161327bee487d 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3123,7 +3123,7 @@ static int unittest_i2c_bus_probe(struct platform_device *pdev) dev_dbg(dev, "%s for node @%pOF\n", __func__, np); - std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL); + std = devm_kzalloc_obj(dev, *std); if (!std) return -ENOMEM; diff --git a/drivers/opp/of.c b/drivers/opp/of.c index ea93800795783f..c773766e70215b 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -599,7 +599,7 @@ static u32 *_parse_named_prop(struct dev_pm_opp *opp, struct device *dev, return ERR_PTR(-EINVAL); } - out = kmalloc_array(count, sizeof(*out), GFP_KERNEL); + out = kmalloc_objs(*out, count); if (!out) return ERR_PTR(-EINVAL); @@ -737,7 +737,7 @@ static int _read_rate(struct dev_pm_opp *new_opp, struct opp_table *opp_table, return -EINVAL; } - rates = kmalloc_array(count, sizeof(*rates), GFP_KERNEL); + rates = kmalloc_objs(*rates, count); if (!rates) return -ENOMEM; @@ -782,7 +782,7 @@ static int _read_bw(struct dev_pm_opp *new_opp, struct opp_table *opp_table, return -EINVAL; } - bw = kmalloc_array(count, sizeof(*bw), GFP_KERNEL); + bw = kmalloc_objs(*bw, count); if (!bw) return -ENOMEM; diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c index 016c9d5a60a8a8..f15bf69906ccf5 100644 --- a/drivers/parisc/led.c +++ b/drivers/parisc/led.c @@ -280,7 +280,7 @@ static int hppa_led_generic_probe(struct platform_device *pdev, struct hppa_drvdata *p; int i, err; - p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index 4d4140c8584daf..e0f9c44e901564 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -726,7 +726,7 @@ static int parport_serial_pci_probe(struct pci_dev *dev, struct parport_serial_private *priv; int err; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c index 822602836b1207..ae29ab4194d416 100644 --- a/drivers/pci/controller/cadence/pci-j721e.c +++ b/drivers/pci/controller/cadence/pci-j721e.c @@ -491,7 +491,7 @@ static int j721e_pcie_probe(struct platform_device *pdev) mode = (u32)data->mode; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; @@ -519,7 +519,7 @@ static int j721e_pcie_probe(struct platform_device *pdev) if (!IS_ENABLED(CONFIG_PCI_J721E_EP)) return -ENODEV; - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); + ep = devm_kzalloc_obj(dev, *ep); if (!ep) return -ENOMEM; diff --git a/drivers/pci/controller/cadence/pci-sky1.c b/drivers/pci/controller/cadence/pci-sky1.c index b8632f1d3156ae..82f4ae5c04a880 100644 --- a/drivers/pci/controller/cadence/pci-sky1.c +++ b/drivers/pci/controller/cadence/pci-sky1.c @@ -141,7 +141,7 @@ static int sky1_pcie_probe(struct platform_device *pdev) struct sky1_pcie *pcie; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; @@ -176,7 +176,7 @@ static int sky1_pcie_probe(struct platform_device *pdev) cdns_pcie->is_rc = true; cdns_pcie->is_hpa = true; - reg_off = devm_kzalloc(dev, sizeof(*reg_off), GFP_KERNEL); + reg_off = devm_kzalloc_obj(dev, *reg_off); if (!reg_off) { pci_ecam_free(pcie->cfg); return -ENOMEM; diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 370b19f4d38fbe..a967f77622839d 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -693,9 +693,7 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep) ep->max_regions = CDNS_PCIE_MAX_OB; of_property_read_u32(np, "cdns,max-outbound-regions", &ep->max_regions); - ep->ob_addr = devm_kcalloc(dev, - ep->max_regions, sizeof(*ep->ob_addr), - GFP_KERNEL); + ep->ob_addr = devm_kzalloc_objs(dev, *ep->ob_addr, ep->max_regions); if (!ep->ob_addr) return -ENOMEM; @@ -713,8 +711,7 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep) if (of_property_read_u8(np, "max-functions", &epc->max_functions) < 0) epc->max_functions = 1; - ep->epf = devm_kcalloc(dev, epc->max_functions, sizeof(*ep->epf), - GFP_KERNEL); + ep->epf = devm_kzalloc_objs(dev, *ep->epf, epc->max_functions); if (!ep->epf) return -ENOMEM; @@ -730,8 +727,8 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep) epf = &ep->epf[i]; if (epc->max_vfs[i] == 0) continue; - epf->epf = devm_kcalloc(dev, epc->max_vfs[i], - sizeof(*ep->epf), GFP_KERNEL); + epf->epf = devm_kzalloc_objs(dev, *ep->epf, + epc->max_vfs[i]); if (!epf->epf) return -ENOMEM; } diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c index 4a24302cc5b2c8..7e3b835914b18a 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-plat.c +++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c @@ -75,7 +75,7 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev) if (!IS_ENABLED(CONFIG_PCIE_CADENCE_PLAT_EP)) return -ENODEV; - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); + ep = devm_kzalloc_obj(dev, *ep); if (!ep) return -ENOMEM; diff --git a/drivers/pci/controller/cadence/pcie-cadence.c b/drivers/pci/controller/cadence/pcie-cadence.c index 0ac98024994141..46e9324440ce65 100644 --- a/drivers/pci/controller/cadence/pcie-cadence.c +++ b/drivers/pci/controller/cadence/pcie-cadence.c @@ -233,7 +233,7 @@ int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie) return 0; } - phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_objs(dev, *phy, phy_count); if (!phy) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c index 0d56fd5a19ea08..1d8eeb01376959 100644 --- a/drivers/pci/controller/dwc/pci-dra7xx.c +++ b/drivers/pci/controller/dwc/pci-dra7xx.c @@ -697,11 +697,11 @@ static int dra7xx_pcie_probe(struct platform_device *pdev) mode = (enum dw_pcie_device_mode)data->mode; b1co_mode_sel_mask = data->b1co_mode_sel_mask; - dra7xx = devm_kzalloc(dev, sizeof(*dra7xx), GFP_KERNEL); + dra7xx = devm_kzalloc_obj(dev, *dra7xx); if (!dra7xx) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; @@ -722,7 +722,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev) return phy_count; } - phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_objs(dev, *phy, phy_count); if (!phy) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-exynos.c b/drivers/pci/controller/dwc/pci-exynos.c index e3c05ade381bb5..a37c7464d272d8 100644 --- a/drivers/pci/controller/dwc/pci-exynos.c +++ b/drivers/pci/controller/dwc/pci-exynos.c @@ -288,7 +288,7 @@ static int exynos_pcie_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); + ep = devm_kzalloc_obj(dev, *ep); if (!ep) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 83fbd998551d03..3917e11dc632f1 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1320,11 +1320,11 @@ static int imx_pcie_parse_legacy_binding(struct imx_pcie *pcie) if (!reset) return 0; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; - perst = devm_kzalloc(dev, sizeof(*perst), GFP_KERNEL); + perst = devm_kzalloc_obj(dev, *perst); if (!perst) return -ENOMEM; @@ -1843,11 +1843,11 @@ static int imx_pcie_probe(struct platform_device *pdev) int i, ret, domain; u16 val; - imx_pcie = devm_kzalloc(dev, sizeof(*imx_pcie), GFP_KERNEL); + imx_pcie = devm_kzalloc_obj(dev, *imx_pcie); if (!imx_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c index edfbc32904cdab..ebf341b45cd624 100644 --- a/drivers/pci/controller/dwc/pci-keystone.c +++ b/drivers/pci/controller/dwc/pci-keystone.c @@ -1152,11 +1152,11 @@ static int ks_pcie_probe(struct platform_device *pdev) ep_ops = data->ep_ops; mode = data->mode; - ks_pcie = devm_kzalloc(dev, sizeof(*ks_pcie), GFP_KERNEL); + ks_pcie = devm_kzalloc_obj(dev, *ks_pcie); if (!ks_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; @@ -1197,7 +1197,7 @@ static int ks_pcie_probe(struct platform_device *pdev) if (ret) num_lanes = 1; - phy = devm_kcalloc(dev, num_lanes, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_objs(dev, *phy, num_lanes); if (!phy) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-layerscape-ep.c b/drivers/pci/controller/dwc/pci-layerscape-ep.c index 527c57114dcfe5..b69621a6513e58 100644 --- a/drivers/pci/controller/dwc/pci-layerscape-ep.c +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c @@ -231,15 +231,15 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev) u8 offset; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; - ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL); + ls_epc = devm_kzalloc_obj(dev, *ls_epc); if (!ls_epc) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-layerscape.c b/drivers/pci/controller/dwc/pci-layerscape.c index 7f37a053715924..7a77607981cdbb 100644 --- a/drivers/pci/controller/dwc/pci-layerscape.c +++ b/drivers/pci/controller/dwc/pci-layerscape.c @@ -331,11 +331,11 @@ static int ls_pcie_probe(struct platform_device *pdev) struct resource *dbi_base; u32 index[2]; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c index 8559d132dcde85..fbc3485e070e22 100644 --- a/drivers/pci/controller/dwc/pci-meson.c +++ b/drivers/pci/controller/dwc/pci-meson.c @@ -385,7 +385,7 @@ static int meson_pcie_probe(struct platform_device *pdev) struct meson_pcie *mp; int ret; - mp = devm_kzalloc(dev, sizeof(*mp), GFP_KERNEL); + mp = devm_kzalloc_obj(dev, *mp); if (!mp) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-al.c b/drivers/pci/controller/dwc/pcie-al.c index ef8c8ce7c78c78..718c47d53848a8 100644 --- a/drivers/pci/controller/dwc/pcie-al.c +++ b/drivers/pci/controller/dwc/pcie-al.c @@ -49,11 +49,11 @@ static int al_pcie_init(struct pci_config_window *cfg) struct resource *res; int ret; - al_pcie = devm_kzalloc(dev, sizeof(*al_pcie), GFP_KERNEL); + al_pcie = devm_kzalloc_obj(dev, *al_pcie); if (!al_pcie) return -ENOMEM; - res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(dev, *res); if (!res) return -ENOMEM; @@ -326,11 +326,11 @@ static int al_pcie_probe(struct platform_device *pdev) struct al_pcie *al_pcie; struct dw_pcie *pci; - al_pcie = devm_kzalloc(dev, sizeof(*al_pcie), GFP_KERNEL); + al_pcie = devm_kzalloc_obj(dev, *al_pcie); if (!al_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-amd-mdb.c b/drivers/pci/controller/dwc/pcie-amd-mdb.c index dee295f281a30c..0ac431d3e006b0 100644 --- a/drivers/pci/controller/dwc/pcie-amd-mdb.c +++ b/drivers/pci/controller/dwc/pcie-amd-mdb.c @@ -477,7 +477,7 @@ static int amd_mdb_pcie_probe(struct platform_device *pdev) struct dw_pcie *pci; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-andes-qilai.c b/drivers/pci/controller/dwc/pcie-andes-qilai.c index bd1588be44e06f..e8f4605d80c9ee 100644 --- a/drivers/pci/controller/dwc/pcie-andes-qilai.c +++ b/drivers/pci/controller/dwc/pcie-andes-qilai.c @@ -146,7 +146,7 @@ static int qilai_pcie_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(&pdev->dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-armada8k.c b/drivers/pci/controller/dwc/pcie-armada8k.c index c2650fd0d45890..a75e6ec06bb506 100644 --- a/drivers/pci/controller/dwc/pcie-armada8k.c +++ b/drivers/pci/controller/dwc/pcie-armada8k.c @@ -271,11 +271,11 @@ static int armada8k_pcie_probe(struct platform_device *pdev) struct resource *base; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-artpec6.c b/drivers/pci/controller/dwc/pcie-artpec6.c index 7f0ba506dd1cf0..8ee199d6893adc 100644 --- a/drivers/pci/controller/dwc/pcie-artpec6.c +++ b/drivers/pci/controller/dwc/pcie-artpec6.c @@ -401,11 +401,11 @@ static int artpec6_pcie_probe(struct platform_device *pdev) variant = (enum artpec_pcie_variants)data->variant; mode = (enum dw_pcie_device_mode)data->mode; - artpec6_pcie = devm_kzalloc(dev, sizeof(*artpec6_pcie), GFP_KERNEL); + artpec6_pcie = devm_kzalloc_obj(dev, *artpec6_pcie); if (!artpec6_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c index be0b84665c9e45..7c35093421842b 100644 --- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c +++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c @@ -569,7 +569,7 @@ static int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci, struct dentry *dir) return 0; } - rasdes_info = devm_kzalloc(dev, sizeof(*rasdes_info), GFP_KERNEL); + rasdes_info = devm_kzalloc_obj(dev, *rasdes_info); if (!rasdes_info) return -ENOMEM; @@ -588,7 +588,7 @@ static int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci, struct dentry *dir) /* Create debugfs files for Error Injection subdirectory. */ for (i = 0; i < ARRAY_SIZE(err_inj_list); i++) { - priv_tmp = devm_kzalloc(dev, sizeof(*priv_tmp), GFP_KERNEL); + priv_tmp = devm_kzalloc_obj(dev, *priv_tmp); if (!priv_tmp) { ret = -ENOMEM; goto err_deinit; @@ -602,7 +602,7 @@ static int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci, struct dentry *dir) /* Create debugfs files for Statistical Counter subdirectory. */ for (i = 0; i < ARRAY_SIZE(event_list); i++) { - priv_tmp = devm_kzalloc(dev, sizeof(*priv_tmp), GFP_KERNEL); + priv_tmp = devm_kzalloc_obj(dev, *priv_tmp); if (!priv_tmp) { ret = -ENOMEM; goto err_deinit; @@ -900,7 +900,7 @@ void dwc_pcie_debugfs_init(struct dw_pcie *pci, enum dw_pcie_device_mode mode) /* Create main directory for each platform driver. */ snprintf(dirname, DWC_DEBUGFS_BUF_MAX, "dwc_pcie_%s", dev_name(dev)); dir = debugfs_create_dir(dirname, NULL); - debugfs = devm_kzalloc(dev, sizeof(*debugfs), GFP_KERNEL); + debugfs = devm_kzalloc_obj(dev, *debugfs); if (!debugfs) return; diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index 630ba172280c2f..e6060bb0bbbdff 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -285,8 +285,7 @@ static int dw_pcie_ep_ib_atu_addr(struct dw_pcie_ep *ep, u8 func_no, int type, return -EINVAL; } - indexes = devm_kcalloc(dev, epf_bar->num_submap, sizeof(*indexes), - GFP_KERNEL); + indexes = devm_kzalloc_objs(dev, *indexes, epf_bar->num_submap); if (!indexes) return -ENOMEM; @@ -1363,8 +1362,7 @@ int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep) } if (!ep->outbound_addr) { - addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t), - GFP_KERNEL); + addr = devm_kzalloc_objs(dev, phys_addr_t, pci->num_ob_windows); if (!addr) goto err_remove_edma; ep->outbound_addr = addr; @@ -1376,7 +1374,7 @@ int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep) if (ep_func) continue; - ep_func = devm_kzalloc(dev, sizeof(*ep_func), GFP_KERNEL); + ep_func = devm_kzalloc_obj(dev, *ep_func); if (!ep_func) goto err_remove_edma; diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 869a39107a81da..bbb02458af58f6 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -401,7 +401,7 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp) win = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM); if (win) { - res = devm_kzalloc(pci->dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(pci->dev, *res); if (!res) return; diff --git a/drivers/pci/controller/dwc/pcie-designware-plat.c b/drivers/pci/controller/dwc/pcie-designware-plat.c index 14d94e76122950..4fad530d136a26 100644 --- a/drivers/pci/controller/dwc/pcie-designware-plat.c +++ b/drivers/pci/controller/dwc/pcie-designware-plat.c @@ -105,11 +105,11 @@ static int dw_plat_pcie_probe(struct platform_device *pdev) mode = (enum dw_pcie_device_mode)data->mode; - dw_plat_pcie = devm_kzalloc(dev, sizeof(*dw_plat_pcie), GFP_KERNEL); + dw_plat_pcie = devm_kzalloc_obj(dev, *dw_plat_pcie); if (!dw_plat_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c index bd86e32cc2b15e..ab2e2669940953 100644 --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c @@ -819,7 +819,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev) if (!data) return -EINVAL; - rockchip = devm_kzalloc(dev, sizeof(*rockchip), GFP_KERNEL); + rockchip = devm_kzalloc_obj(dev, *rockchip); if (!rockchip) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-eswin.c b/drivers/pci/controller/dwc/pcie-eswin.c index 1bb44696057e4a..b9c1e90ce827d0 100644 --- a/drivers/pci/controller/dwc/pcie-eswin.c +++ b/drivers/pci/controller/dwc/pcie-eswin.c @@ -128,7 +128,7 @@ static int eswin_pcie_parse_port(struct eswin_pcie *pcie, struct device *dev = pcie->pci.dev; struct eswin_pcie_port *port; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; @@ -307,7 +307,7 @@ static int eswin_pcie_probe(struct platform_device *pdev) if (!data) return dev_err_probe(dev, -ENODATA, "No platform data\n"); - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-fu740.c b/drivers/pci/controller/dwc/pcie-fu740.c index 6c7ce16031704e..80436eae69b620 100644 --- a/drivers/pci/controller/dwc/pcie-fu740.c +++ b/drivers/pci/controller/dwc/pcie-fu740.c @@ -291,7 +291,7 @@ static int fu740_pcie_probe(struct platform_device *pdev) struct dw_pcie *pci; struct fu740_pcie *afp; - afp = devm_kzalloc(dev, sizeof(*afp), GFP_KERNEL); + afp = devm_kzalloc_obj(dev, *afp); if (!afp) return -ENOMEM; pci = &afp->pci; diff --git a/drivers/pci/controller/dwc/pcie-hisi.c b/drivers/pci/controller/dwc/pcie-hisi.c index 3c17897e56fcb6..a9d54aa99aee6d 100644 --- a/drivers/pci/controller/dwc/pcie-hisi.c +++ b/drivers/pci/controller/dwc/pcie-hisi.c @@ -82,7 +82,7 @@ static int hisi_pcie_init(struct pci_config_window *cfg) struct resource *res; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; @@ -90,7 +90,7 @@ static int hisi_pcie_init(struct pci_config_window *cfg) * Retrieve RC base and size from a HISI0081 device with _UID * matching our segment. */ - res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); + res = devm_kzalloc_obj(dev, *res); if (!res) return -ENOMEM; @@ -128,7 +128,7 @@ static int hisi_pcie_platform_init(struct pci_config_window *cfg) struct platform_device *pdev = to_platform_device(dev); struct resource *res; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-histb.c b/drivers/pci/controller/dwc/pcie-histb.c index 432a54c5bfceaa..f122c124ab39c7 100644 --- a/drivers/pci/controller/dwc/pcie-histb.c +++ b/drivers/pci/controller/dwc/pcie-histb.c @@ -299,11 +299,11 @@ static int histb_pcie_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - hipcie = devm_kzalloc(dev, sizeof(*hipcie), GFP_KERNEL); + hipcie = devm_kzalloc_obj(dev, *hipcie); if (!hipcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-intel-gw.c b/drivers/pci/controller/dwc/pcie-intel-gw.c index 348e579e683fab..bc4bb105abdae1 100644 --- a/drivers/pci/controller/dwc/pcie-intel-gw.c +++ b/drivers/pci/controller/dwc/pcie-intel-gw.c @@ -396,7 +396,7 @@ static int intel_pcie_probe(struct platform_device *pdev) struct dw_pcie *pci; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-keembay.c b/drivers/pci/controller/dwc/pcie-keembay.c index b11e66c10fffa3..7cb149803ae2f5 100644 --- a/drivers/pci/controller/dwc/pcie-keembay.c +++ b/drivers/pci/controller/dwc/pcie-keembay.c @@ -401,7 +401,7 @@ static int keembay_pcie_probe(struct platform_device *pdev) mode = (enum dw_pcie_device_mode)data->mode; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index 91559c8b1866ed..6950d89e55ba13 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -322,7 +322,7 @@ static int hi3660_pcie_phy_init(struct platform_device *pdev, struct hi3660_pcie_phy *phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; @@ -723,11 +723,11 @@ static int kirin_pcie_probe(struct platform_device *pdev) if (!data) return dev_err_probe(dev, -EINVAL, "OF data missing\n"); - kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL); + kirin_pcie = devm_kzalloc_obj(dev, struct kirin_pcie); if (!kirin_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-nxp-s32g.c b/drivers/pci/controller/dwc/pcie-nxp-s32g.c index 386e44dd04770a..a600e630236820 100644 --- a/drivers/pci/controller/dwc/pcie-nxp-s32g.c +++ b/drivers/pci/controller/dwc/pcie-nxp-s32g.c @@ -246,7 +246,7 @@ static int s32g_pcie_parse_port(struct s32g_pcie *s32g_pp, struct device_node *n struct s32g_pcie_port *port; int num_lanes; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; @@ -324,7 +324,7 @@ static int s32g_pcie_probe(struct platform_device *pdev) struct dw_pcie_rp *pp; int ret; - s32g_pp = devm_kzalloc(dev, sizeof(*s32g_pp), GFP_KERNEL); + s32g_pp = devm_kzalloc_obj(dev, *s32g_pp); if (!s32g_pp) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c index e6afdc6198acc4..2d7ddf8d173ff8 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -870,7 +870,7 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev) char *name; int ret; - pcie_ep = devm_kzalloc(dev, sizeof(*pcie_ep), GFP_KERNEL); + pcie_ep = devm_kzalloc_obj(dev, *pcie_ep); if (!pcie_ep) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index d903f10211c236..efad7c8d157924 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -2007,7 +2007,7 @@ static int qcom_pcie_ecam_host_init(struct pci_config_window *cfg) struct dw_pcie *pci; int ret; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; @@ -2116,7 +2116,7 @@ static int qcom_pcie_parse_perst(struct qcom_pcie *pcie, } skip_perst_parsing: - perst = devm_kzalloc(dev, sizeof(*perst), GFP_KERNEL); + perst = devm_kzalloc_obj(dev, *perst); if (!perst) return -ENOMEM; @@ -2148,7 +2148,7 @@ static int qcom_pcie_parse_port(struct qcom_pcie *pcie, struct device_node *node if (IS_ERR(phy)) return PTR_ERR(phy); - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; @@ -2223,11 +2223,11 @@ static int qcom_pcie_parse_legacy_binding(struct qcom_pcie *pcie) if (ret) return ret; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; - perst = devm_kzalloc(dev, sizeof(*perst), GFP_KERNEL); + perst = devm_kzalloc_obj(dev, *perst); if (!perst) return -ENOMEM; @@ -2300,13 +2300,13 @@ static int qcom_pcie_probe(struct platform_device *pdev) return 0; } - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) { ret = -ENOMEM; goto err_pm_runtime_put; } - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) { ret = -ENOMEM; goto err_pm_runtime_put; diff --git a/drivers/pci/controller/dwc/pcie-rcar-gen4.c b/drivers/pci/controller/dwc/pcie-rcar-gen4.c index fceecbd16355c3..05556a3dc725e1 100644 --- a/drivers/pci/controller/dwc/pcie-rcar-gen4.c +++ b/drivers/pci/controller/dwc/pcie-rcar-gen4.c @@ -438,7 +438,7 @@ static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rcar_gen4_pcie *rcar; - rcar = devm_kzalloc(dev, sizeof(*rcar), GFP_KERNEL); + rcar = devm_kzalloc_obj(dev, *rcar); if (!rcar) return ERR_PTR(-ENOMEM); diff --git a/drivers/pci/controller/dwc/pcie-sophgo.c b/drivers/pci/controller/dwc/pcie-sophgo.c index 044088898819e5..b8f59f734f387b 100644 --- a/drivers/pci/controller/dwc/pcie-sophgo.c +++ b/drivers/pci/controller/dwc/pcie-sophgo.c @@ -239,7 +239,7 @@ static int sophgo_pcie_probe(struct platform_device *pdev) struct sophgo_pcie *sophgo; int ret; - sophgo = devm_kzalloc(dev, sizeof(*sophgo), GFP_KERNEL); + sophgo = devm_kzalloc_obj(dev, *sophgo); if (!sophgo) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-spacemit-k1.c b/drivers/pci/controller/dwc/pcie-spacemit-k1.c index 92a71ea90ac313..d960fdfe2d6931 100644 --- a/drivers/pci/controller/dwc/pcie-spacemit-k1.c +++ b/drivers/pci/controller/dwc/pcie-spacemit-k1.c @@ -281,7 +281,7 @@ static int k1_pcie_probe(struct platform_device *pdev) struct k1_pcie *k1; int ret; - k1 = devm_kzalloc(dev, sizeof(*k1), GFP_KERNEL); + k1 = devm_kzalloc_obj(dev, *k1); if (!k1) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-spear13xx.c b/drivers/pci/controller/dwc/pcie-spear13xx.c index 01794a9d3ad293..d44669f09385b8 100644 --- a/drivers/pci/controller/dwc/pcie-spear13xx.c +++ b/drivers/pci/controller/dwc/pcie-spear13xx.c @@ -193,11 +193,11 @@ static int spear13xx_pcie_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - spear13xx_pcie = devm_kzalloc(dev, sizeof(*spear13xx_pcie), GFP_KERNEL); + spear13xx_pcie = devm_kzalloc_obj(dev, *spear13xx_pcie); if (!spear13xx_pcie) return -ENOMEM; - pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-stm32-ep.c b/drivers/pci/controller/dwc/pcie-stm32-ep.c index a7988dff104536..f6163e981ab81a 100644 --- a/drivers/pci/controller/dwc/pcie-stm32-ep.c +++ b/drivers/pci/controller/dwc/pcie-stm32-ep.c @@ -229,7 +229,7 @@ static int stm32_pcie_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - stm32_pcie = devm_kzalloc(dev, sizeof(*stm32_pcie), GFP_KERNEL); + stm32_pcie = devm_kzalloc_obj(dev, *stm32_pcie); if (!stm32_pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-stm32.c b/drivers/pci/controller/dwc/pcie-stm32.c index 349618ea5b9c90..ee6a65d92ae1a5 100644 --- a/drivers/pci/controller/dwc/pcie-stm32.c +++ b/drivers/pci/controller/dwc/pcie-stm32.c @@ -254,7 +254,7 @@ static int stm32_pcie_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - stm32_pcie = devm_kzalloc(dev, sizeof(*stm32_pcie), GFP_KERNEL); + stm32_pcie = devm_kzalloc_obj(dev, *stm32_pcie); if (!stm32_pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-tegra194-acpi.c b/drivers/pci/controller/dwc/pcie-tegra194-acpi.c index 352591dcef834c..d3d6ca921cb7cb 100644 --- a/drivers/pci/controller/dwc/pcie-tegra194-acpi.c +++ b/drivers/pci/controller/dwc/pcie-tegra194-acpi.c @@ -24,7 +24,7 @@ static int tegra194_acpi_init(struct pci_config_window *cfg) struct device *dev = cfg->parent; struct tegra194_pcie_ecam *pcie_ecam; - pcie_ecam = devm_kzalloc(dev, sizeof(*pcie_ecam), GFP_KERNEL); + pcie_ecam = devm_kzalloc_obj(dev, *pcie_ecam); if (!pcie_ecam) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c index 26e2ac5c586956..1108e76759d4bf 100644 --- a/drivers/pci/controller/dwc/pcie-tegra194.c +++ b/drivers/pci/controller/dwc/pcie-tegra194.c @@ -2150,7 +2150,7 @@ static int tegra_pcie_dw_probe(struct platform_device *pdev) data = of_device_get_match_data(dev); - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; @@ -2232,7 +2232,7 @@ static int tegra_pcie_dw_probe(struct platform_device *pdev) return PTR_ERR(pcie->core_apb_rst); } - phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL); + phys = devm_kzalloc_objs(dev, *phys, pcie->phy_count); if (!phys) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-ultrarisc.c b/drivers/pci/controller/dwc/pcie-ultrarisc.c index 523f454c6c5248..cea9f20612570b 100644 --- a/drivers/pci/controller/dwc/pcie-ultrarisc.c +++ b/drivers/pci/controller/dwc/pcie-ultrarisc.c @@ -141,7 +141,7 @@ static int ultrarisc_pcie_probe(struct platform_device *pdev) struct dw_pcie *pci; int ret; - ultra = devm_kzalloc(dev, sizeof(*ultra), GFP_KERNEL); + ultra = devm_kzalloc_obj(dev, *ultra); if (!ultra) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-uniphier-ep.c b/drivers/pci/controller/dwc/pcie-uniphier-ep.c index 89fb7820022232..e9abad999cf225 100644 --- a/drivers/pci/controller/dwc/pcie-uniphier-ep.c +++ b/drivers/pci/controller/dwc/pcie-uniphier-ep.c @@ -342,7 +342,7 @@ static int uniphier_pcie_ep_probe(struct platform_device *pdev) struct uniphier_pcie_ep_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-uniphier.c b/drivers/pci/controller/dwc/pcie-uniphier.c index 297e7a3d9b368d..1c8d7694543fb1 100644 --- a/drivers/pci/controller/dwc/pcie-uniphier.c +++ b/drivers/pci/controller/dwc/pcie-uniphier.c @@ -360,7 +360,7 @@ static int uniphier_pcie_probe(struct platform_device *pdev) struct uniphier_pcie *pcie; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/dwc/pcie-visconti.c b/drivers/pci/controller/dwc/pcie-visconti.c index f21775c3b3a1d3..b8e1e89b19b631 100644 --- a/drivers/pci/controller/dwc/pcie-visconti.c +++ b/drivers/pci/controller/dwc/pcie-visconti.c @@ -295,7 +295,7 @@ static int visconti_pcie_probe(struct platform_device *pdev) struct dw_pcie *pci; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c index a23907a875e574..35ee51cf9d0677 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -75,7 +75,7 @@ static int pci_host_common_parse_perst(struct device *dev, return PTR_ERR(reset); } - perst = devm_kzalloc(dev, sizeof(*perst), GFP_KERNEL); + perst = devm_kzalloc_obj(dev, *perst); if (!perst) return -ENOMEM; @@ -119,7 +119,7 @@ static int pci_host_common_parse_port(struct device *dev, struct pci_host_port *port; int ret; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pci-loongson.c b/drivers/pci/controller/pci-loongson.c index d0c643996476f8..6c0b7a3f4ba053 100644 --- a/drivers/pci/controller/pci-loongson.c +++ b/drivers/pci/controller/pci-loongson.c @@ -418,11 +418,11 @@ static int loongson_pci_ecam_init(struct pci_config_window *cfg) struct loongson_pci *priv; struct loongson_pci_data *data; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index cce1c1c0da58c9..66b50528d167ed 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -1472,7 +1472,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev) num = of_get_available_child_count(np); - pcie->ports = devm_kcalloc(dev, num, sizeof(*pcie->ports), GFP_KERNEL); + pcie->ports = devm_kzalloc_objs(dev, *pcie->ports, num); if (!pcie->ports) return -ENOMEM; diff --git a/drivers/pci/controller/pci-tegra.c b/drivers/pci/controller/pci-tegra.c index 96bd522fa67b38..05a04ed12da2e6 100644 --- a/drivers/pci/controller/pci-tegra.c +++ b/drivers/pci/controller/pci-tegra.c @@ -1350,7 +1350,7 @@ static int tegra_pcie_port_get_phys(struct tegra_pcie_port *port) unsigned int i; int err; - port->phys = devm_kcalloc(dev, port->lanes, sizeof(phy), GFP_KERNEL); + port->phys = devm_kzalloc_objs(dev, phy, port->lanes); if (!port->phys) return -ENOMEM; @@ -1950,9 +1950,8 @@ static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie) return -ENODEV; } - pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -1983,9 +1982,8 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) { pcie->num_supplies = 4; - pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(pcie->dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -1996,9 +1994,8 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) } else if (of_device_is_compatible(np, "nvidia,tegra210-pcie")) { pcie->num_supplies = 3; - pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(pcie->dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -2008,9 +2005,8 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie")) { pcie->num_supplies = 4; - pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -2032,9 +2028,8 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) pcie->num_supplies = 4 + (need_pexa ? 2 : 0) + (need_pexb ? 2 : 0); - pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -2055,9 +2050,8 @@ static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { pcie->num_supplies = 5; - pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, - sizeof(*pcie->supplies), - GFP_KERNEL); + pcie->supplies = devm_kzalloc_objs(dev, *pcie->supplies, + pcie->num_supplies); if (!pcie->supplies) return -ENOMEM; @@ -2133,7 +2127,7 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) mask |= ((1 << value) - 1) << lane; lane += value; - rp = devm_kzalloc(dev, sizeof(*rp), GFP_KERNEL); + rp = devm_kzalloc_obj(dev, *rp); if (!rp) return -ENOMEM; diff --git a/drivers/pci/controller/pci-thunder-pem.c b/drivers/pci/controller/pci-thunder-pem.c index 5fa037fb61dc35..c891cc87fc8881 100644 --- a/drivers/pci/controller/pci-thunder-pem.c +++ b/drivers/pci/controller/pci-thunder-pem.c @@ -309,7 +309,7 @@ static int thunder_pem_init(struct device *dev, struct pci_config_window *cfg, struct thunder_pem_pci *pem_pci; resource_size_t bar4_start; - pem_pci = devm_kzalloc(dev, sizeof(*pem_pci), GFP_KERNEL); + pem_pci = devm_kzalloc_obj(dev, *pem_pci); if (!pem_pci) return -ENOMEM; @@ -385,7 +385,7 @@ static int thunder_pem_acpi_init(struct pci_config_window *cfg) struct resource *res_pem; int ret; - res_pem = devm_kzalloc(&adev->dev, sizeof(*res_pem), GFP_KERNEL); + res_pem = devm_kzalloc_obj(&adev->dev, *res_pem); if (!res_pem) return -ENOMEM; diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controller/pci-xgene-msi.c index 654639bccd10e3..62ecbf01d8c781 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -350,8 +350,7 @@ static int xgene_msi_probe(struct platform_device *pdev) struct xgene_msi *xgene_msi; int rc; - xgene_msi_ctrl = devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl), - GFP_KERNEL); + xgene_msi_ctrl = devm_kzalloc_obj(&pdev->dev, *xgene_msi_ctrl); if (!xgene_msi_ctrl) return -ENOMEM; diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pci-xgene.c index a5b8bbc04a2214..6694a943894737 100644 --- a/drivers/pci/controller/pci-xgene.c +++ b/drivers/pci/controller/pci-xgene.c @@ -227,7 +227,7 @@ static int xgene_pcie_ecam_init(struct pci_config_window *cfg, u32 ipversion) struct resource csr; int ret; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-altera-msi.c b/drivers/pci/controller/pcie-altera-msi.c index ea2ca2e70f2041..afad6aa7cf70c3 100644 --- a/drivers/pci/controller/pcie-altera-msi.c +++ b/drivers/pci/controller/pcie-altera-msi.c @@ -206,8 +206,7 @@ static int altera_msi_probe(struct platform_device *pdev) struct resource *res; int ret; - msi = devm_kzalloc(&pdev->dev, sizeof(struct altera_msi), - GFP_KERNEL); + msi = devm_kzalloc_obj(&pdev->dev, struct altera_msi); if (!msi) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index c2cffc0659f449..dfd0e345bc5678 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -566,7 +566,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, if (IS_ERR(reset)) return PTR_ERR(reset); - port = devm_kzalloc(pcie->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(pcie->dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-aspeed.c b/drivers/pci/controller/pcie-aspeed.c index ecb7562f84c01f..b7027e2d44d5d5 100644 --- a/drivers/pci/controller/pcie-aspeed.c +++ b/drivers/pci/controller/pcie-aspeed.c @@ -926,7 +926,7 @@ static int aspeed_pcie_parse_port(struct aspeed_pcie *pcie, struct device *dev = pcie->dev; int ret; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 26d1305f5e7064..1c142f52f227dd 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -732,7 +732,7 @@ static int brcm_pcie_enable_msi(struct brcm_pcie *pcie) return -ENODEV; } - msi = devm_kzalloc(dev, sizeof(struct brcm_msi), GFP_KERNEL); + msi = devm_kzalloc_obj(dev, struct brcm_msi); if (!msi) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-hisi-error.c b/drivers/pci/controller/pcie-hisi-error.c index 36be86d827a828..b4859a30fb2376 100644 --- a/drivers/pci/controller/pcie-hisi-error.c +++ b/drivers/pci/controller/pcie-hisi-error.c @@ -281,7 +281,7 @@ static int hisi_pcie_error_handler_probe(struct platform_device *pdev) struct hisi_pcie_error_private *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-iproc-msi.c b/drivers/pci/controller/pcie-iproc-msi.c index 9ba242ab95967f..3751a3f7d946df 100644 --- a/drivers/pci/controller/pcie-iproc-msi.c +++ b/drivers/pci/controller/pcie-iproc-msi.c @@ -527,7 +527,7 @@ int iproc_msi_init(struct iproc_pcie *pcie, struct device_node *node) if (pcie->msi) return -EBUSY; - msi = devm_kzalloc(pcie->dev, sizeof(*msi), GFP_KERNEL); + msi = devm_kzalloc_obj(pcie->dev, *msi); if (!msi) return -ENOMEM; @@ -589,8 +589,7 @@ int iproc_msi_init(struct iproc_pcie *pcie, struct device_node *node) if (!msi->bitmap) return -ENOMEM; - msi->grps = devm_kcalloc(pcie->dev, msi->nr_irqs, sizeof(*msi->grps), - GFP_KERNEL); + msi->grps = devm_kzalloc_objs(pcie->dev, *msi->grps, msi->nr_irqs); if (!msi->grps) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-iproc.c b/drivers/pci/controller/pcie-iproc.c index afb3aa38ac6bb8..c6cc87b6023cab 100644 --- a/drivers/pci/controller/pcie-iproc.c +++ b/drivers/pci/controller/pcie-iproc.c @@ -1426,9 +1426,8 @@ static int iproc_pcie_rev_init(struct iproc_pcie *pcie) return -EINVAL; } - pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG, - sizeof(*pcie->reg_offsets), - GFP_KERNEL); + pcie->reg_offsets = devm_kzalloc_objs(dev, *pcie->reg_offsets, + IPROC_PCIE_MAX_NUM_REG); if (!pcie->reg_offsets) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 3a3e91cd0c2113..da59daa3ae30f3 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -1103,7 +1103,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie, char name[20]; int err; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c index 01ead2f92e872f..79f973f8a6050a 100644 --- a/drivers/pci/controller/pcie-mt7621.c +++ b/drivers/pci/controller/pcie-mt7621.c @@ -205,7 +205,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie, char name[11]; int err; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-rcar-ep.c b/drivers/pci/controller/pcie-rcar-ep.c index c2da8ac1f2e85a..e33c66caa1a62c 100644 --- a/drivers/pci/controller/pcie-rcar-ep.c +++ b/drivers/pci/controller/pcie-rcar-ep.c @@ -141,8 +141,7 @@ static int rcar_pcie_ep_get_pdata(struct rcar_pcie_endpoint *ep, if (IS_ERR(pcie->base)) return PTR_ERR(pcie->base); - ep->ob_window = devm_kcalloc(dev, RCAR_PCI_MAX_RESOURCES, - sizeof(*window), GFP_KERNEL); + ep->ob_window = devm_kzalloc_objs(dev, *window, RCAR_PCI_MAX_RESOURCES); if (!ep->ob_window) return -ENOMEM; @@ -480,7 +479,7 @@ static int rcar_pcie_ep_probe(struct platform_device *pdev) struct pci_epc *epc; int err; - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); + ep = devm_kzalloc_obj(dev, *ep); if (!ep) return -ENOMEM; @@ -510,9 +509,8 @@ static int rcar_pcie_ep_probe(struct platform_device *pdev) goto err_pm_put; } - ep->ob_mapped_addr = devm_kcalloc(dev, ep->num_ob_windows, - sizeof(*ep->ob_mapped_addr), - GFP_KERNEL); + ep->ob_mapped_addr = devm_kzalloc_objs(dev, *ep->ob_mapped_addr, + ep->num_ob_windows); if (!ep->ob_mapped_addr) { err = -ENOMEM; dev_err(dev, "failed to allocate memory for outbound memory pointers\n"); diff --git a/drivers/pci/controller/pcie-rockchip-ep.c b/drivers/pci/controller/pcie-rockchip-ep.c index 9ebc227a1ef842..a20536d50c9c54 100644 --- a/drivers/pci/controller/pcie-rockchip-ep.c +++ b/drivers/pci/controller/pcie-rockchip-ep.c @@ -748,14 +748,13 @@ static int rockchip_pcie_ep_init_ob_mem(struct rockchip_pcie_ep *ep) struct pci_epc_mem_window *windows = NULL; int err, i; - ep->ob_addr = devm_kcalloc(dev, ep->max_regions, sizeof(*ep->ob_addr), - GFP_KERNEL); + ep->ob_addr = devm_kzalloc_objs(dev, *ep->ob_addr, ep->max_regions); if (!ep->ob_addr) return -ENOMEM; - windows = devm_kcalloc(dev, ep->max_regions, - sizeof(struct pci_epc_mem_window), GFP_KERNEL); + windows = devm_kzalloc_objs(dev, struct pci_epc_mem_window, + ep->max_regions); if (!windows) return -ENOMEM; @@ -831,7 +830,7 @@ static int rockchip_pcie_ep_probe(struct platform_device *pdev) struct pci_epc *epc; int err; - ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); + ep = devm_kzalloc_obj(dev, *ep); if (!ep) return -ENOMEM; diff --git a/drivers/pci/controller/pcie-rzg3s-host.c b/drivers/pci/controller/pcie-rzg3s-host.c index 077cfb0834b378..2c2ee9d4d3244c 100644 --- a/drivers/pci/controller/pcie-rzg3s-host.c +++ b/drivers/pci/controller/pcie-rzg3s-host.c @@ -1330,20 +1330,16 @@ static int rzg3s_pcie_resets_prepare_and_get(struct rzg3s_pcie_host *host) unsigned int i; int ret; - host->power_resets = devm_kmalloc_array(host->dev, - data->num_power_resets, - sizeof(*host->power_resets), - GFP_KERNEL); + host->power_resets = devm_kmalloc_objs(host->dev, *host->power_resets, + data->num_power_resets); if (!host->power_resets) return -ENOMEM; for (i = 0; i < data->num_power_resets; i++) host->power_resets[i].id = data->power_resets[i]; - host->cfg_resets = devm_kmalloc_array(host->dev, - data->num_cfg_resets, - sizeof(*host->cfg_resets), - GFP_KERNEL); + host->cfg_resets = devm_kmalloc_objs(host->dev, *host->cfg_resets, + data->num_cfg_resets); if (!host->cfg_resets) return -ENOMEM; @@ -1837,7 +1833,7 @@ static int rzg3s_pcie_probe(struct platform_device *pdev) host->data = device_get_match_data(dev); platform_set_drvdata(pdev, host); - host->sysc = devm_kzalloc(dev, sizeof(*host->sysc), GFP_KERNEL); + host->sysc = devm_kzalloc_obj(dev, *host->sysc); if (!host->sysc) return -ENOMEM; diff --git a/drivers/pci/controller/plda/pcie-microchip-host.c b/drivers/pci/controller/plda/pcie-microchip-host.c index 24bbf93b8051fa..ae26afbb73dd02 100644 --- a/drivers/pci/controller/plda/pcie-microchip-host.c +++ b/drivers/pci/controller/plda/pcie-microchip-host.c @@ -744,7 +744,7 @@ static int mc_host_probe(struct platform_device *pdev) int ret; u32 val; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/pci/controller/plda/pcie-starfive.c b/drivers/pci/controller/plda/pcie-starfive.c index b693eabdf85ba3..48f7d747a86cb3 100644 --- a/drivers/pci/controller/plda/pcie-starfive.c +++ b/drivers/pci/controller/plda/pcie-starfive.c @@ -403,7 +403,7 @@ static int starfive_pcie_probe(struct platform_device *pdev) struct plda_pcie_rp *plda; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); + pcie = devm_kzalloc_obj(dev, *pcie); if (!pcie) return -ENOMEM; diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 9d97a832785ee8..f0b2a86f6279de 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -825,8 +825,7 @@ static int vmd_alloc_irqs(struct vmd_dev *vmd) if (vmd->msix_count < 0) return vmd->msix_count; - vmd->irqs = devm_kcalloc(&dev->dev, vmd->msix_count, sizeof(*vmd->irqs), - GFP_KERNEL); + vmd->irqs = devm_kzalloc_objs(&dev->dev, *vmd->irqs, vmd->msix_count); if (!vmd->irqs) return -ENOMEM; @@ -1165,7 +1164,7 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id) if (resource_size(&dev->resource[VMD_CFGBAR]) < (1 << 20)) return -ENOMEM; - vmd = devm_kzalloc(&dev->dev, sizeof(*vmd), GFP_KERNEL); + vmd = devm_kzalloc_obj(&dev->dev, *vmd); if (!vmd) return -ENOMEM; diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c index 78f1fb1a6b0c74..a633e47edf2fa8 100644 --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c @@ -931,7 +931,7 @@ static int pci_epf_mhi_probe(struct pci_epf *epf, struct pci_epf_mhi *epf_mhi; struct device *dev = &epf->dev; - epf_mhi = devm_kzalloc(dev, sizeof(*epf_mhi), GFP_KERNEL); + epf_mhi = devm_kzalloc_obj(dev, *epf_mhi); if (!epf_mhi) return -ENOMEM; diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c index 5314aca2188a00..295da9b61f07b8 100644 --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c @@ -1516,7 +1516,7 @@ static int epf_ntb_epc_create_interface(struct epf_ntb *ntb, dev = &ntb->epf->dev; - ntb_epc = devm_kzalloc(dev, sizeof(*ntb_epc), GFP_KERNEL); + ntb_epc = devm_kzalloc_obj(dev, *ntb_epc); if (!ntb_epc) return -ENOMEM; @@ -2037,7 +2037,7 @@ static int epf_ntb_probe(struct pci_epf *epf, dev = &epf->dev; - ntb = devm_kzalloc(dev, sizeof(*ntb), GFP_KERNEL); + ntb = devm_kzalloc_obj(dev, *ntb); if (!ntb) return -ENOMEM; diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index d4905aa8e4c01a..d9609185551bf4 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -1483,7 +1483,7 @@ static int pci_epf_test_probe(struct pci_epf *epf, struct device *dev = &epf->dev; enum pci_barno bar; - epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL); + epf_test = devm_kzalloc_obj(dev, *epf_test); if (!epf_test) return -ENOMEM; diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index f77e28f2fe96ab..a0221a674a9d5a 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1783,7 +1783,7 @@ static int pci_vntb_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct ntb_dev *ntb; int ret; - ntb = devm_kzalloc(dev, sizeof(*ntb), GFP_KERNEL); + ntb = devm_kzalloc_obj(dev, *ntb); if (!ntb) return -ENOMEM; @@ -1975,7 +1975,7 @@ static int epf_ntb_probe(struct pci_epf *epf, dev = &epf->dev; - ntb = devm_kzalloc(dev, sizeof(*ntb), GFP_KERNEL); + ntb = devm_kzalloc_obj(dev, *ntb); if (!ntb) return -ENOMEM; diff --git a/drivers/pci/hotplug/octep_hp.c b/drivers/pci/hotplug/octep_hp.c index a0a7f9ccb8fa37..3856f1374bbd27 100644 --- a/drivers/pci/hotplug/octep_hp.c +++ b/drivers/pci/hotplug/octep_hp.c @@ -371,7 +371,7 @@ static int octep_hp_pci_probe(struct pci_dev *pdev, u16 slot_number = 0; int ret; - hp_ctrl = devm_kzalloc(&pdev->dev, sizeof(*hp_ctrl), GFP_KERNEL); + hp_ctrl = devm_kzalloc_obj(&pdev->dev, *hp_ctrl); if (!hp_ctrl) return -ENOMEM; diff --git a/drivers/pci/of.c b/drivers/pci/of.c index a51dff91b196d3..ef4ae4b38c3364 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -334,7 +334,7 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev, if (io_base) *io_base = (resource_size_t)OF_BAD_ADDR; - bus_range = devm_kzalloc(dev, sizeof(*bus_range), GFP_KERNEL); + bus_range = devm_kzalloc_obj(dev, *bus_range); if (!bus_range) return -ENOMEM; diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 1500740cc55d25..5dc36bdcdac303 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -268,7 +268,7 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs, if (!map_sz) return 0; - int_map = kcalloc(map_sz, sizeof(u32), GFP_KERNEL); + int_map = kzalloc_objs(u32, map_sz); if (!int_map) return -ENOMEM; mapp = int_map; diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 45260423dfb092..9e6e22542a9223 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -268,7 +268,7 @@ int pcim_p2pdma_init(struct pci_dev *pdev) if (p2p) return 0; - p2p = devm_kzalloc(&pdev->dev, sizeof(*p2p), GFP_KERNEL); + p2p = devm_kzalloc_obj(&pdev->dev, *p2p); if (!p2p) return -ENOMEM; @@ -421,7 +421,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, if (WARN_ON(!mem)) return -EINVAL; - p2p_pgmap = devm_kzalloc(&pdev->dev, sizeof(*p2p_pgmap), GFP_KERNEL); + p2p_pgmap = devm_kzalloc_obj(&pdev->dev, *p2p_pgmap); if (!p2p_pgmap) return -ENOMEM; diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index db4f607f889cb2..8708ca3257bb88 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1812,7 +1812,7 @@ static int aer_probe(struct pcie_device *dev) (pci_pcie_type(port) != PCI_EXP_TYPE_ROOT_PORT)) return -ENODEV; - rpc = devm_kzalloc(device, sizeof(struct aer_rpc), GFP_KERNEL); + rpc = devm_kzalloc_obj(device, struct aer_rpc); if (!rpc) return -ENOMEM; diff --git a/drivers/pci/pcie/bwctrl.c b/drivers/pci/pcie/bwctrl.c index d48021bfd8448c..3b1122461ffd05 100644 --- a/drivers/pci/pcie/bwctrl.c +++ b/drivers/pci/pcie/bwctrl.c @@ -235,8 +235,7 @@ static int pcie_bwnotif_probe(struct pcie_device *srv) if (!port->subordinate) return -ENODEV; - struct pcie_bwctrl_data *data = devm_kzalloc(&srv->device, - sizeof(*data), GFP_KERNEL); + struct pcie_bwctrl_data *data = devm_kzalloc_obj(&srv->device, *data); if (!data) return -ENOMEM; diff --git a/drivers/pci/pwrctrl/generic.c b/drivers/pci/pwrctrl/generic.c index 4b6cbbb522480c..04aa52ef7fe2bd 100644 --- a/drivers/pci/pwrctrl/generic.c +++ b/drivers/pci/pwrctrl/generic.c @@ -72,7 +72,7 @@ static int slot_pwrctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - slot = devm_kzalloc(dev, sizeof(*slot), GFP_KERNEL); + slot = devm_kzalloc_obj(dev, *slot); if (!slot) return -ENOMEM; diff --git a/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c b/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c index c5ced87944b6ca..f034fbcdee0491 100644 --- a/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +++ b/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c @@ -84,7 +84,7 @@ static int pwrseq_pwrctrl_probe(struct platform_device *pdev) return ret; } - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); + pwrseq = devm_kzalloc_obj(dev, *pwrseq); if (!pwrseq) return -ENOMEM; diff --git a/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c b/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c index 59bc0d77d3c444..4091a2f30aa725 100644 --- a/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +++ b/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c @@ -637,7 +637,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) struct i2c_client *client; int ret, addr; - tc9563 = devm_kzalloc(dev, sizeof(*tc9563), GFP_KERNEL); + tc9563 = devm_kzalloc_obj(dev, *tc9563); if (!tc9563) return -ENOMEM; diff --git a/drivers/pcmcia/max1600.c b/drivers/pcmcia/max1600.c index 7be9068f6191f5..79c22284ea2bdd 100644 --- a/drivers/pcmcia/max1600.c +++ b/drivers/pcmcia/max1600.c @@ -36,7 +36,7 @@ int max1600_init(struct device *dev, struct max1600 **ptr, if (code != MAX1600_CODE_LOW && code != MAX1600_CODE_HIGH) return -EINVAL; - m = devm_kzalloc(dev, sizeof(*m), GFP_KERNEL); + m = devm_kzalloc_obj(dev, *m); if (!m) return -ENOMEM; diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c index 7b5ac8fe811df9..b6b737abf8f315 100644 --- a/drivers/pcmcia/sa1100_generic.c +++ b/drivers/pcmcia/sa1100_generic.c @@ -141,7 +141,7 @@ static int sa11x0_drv_pcmcia_probe(struct platform_device *pdev) if (pdev->id == -1) return sa11x0_drv_pcmcia_legacy_probe(pdev); - skt = devm_kzalloc(dev, sizeof(*skt), GFP_KERNEL); + skt = devm_kzalloc_obj(dev, *skt); if (!skt) return -ENOMEM; diff --git a/drivers/pcmcia/sa1111_jornada720.c b/drivers/pcmcia/sa1111_jornada720.c index 1083e1b4f25dbb..3504c44a8c023f 100644 --- a/drivers/pcmcia/sa1111_jornada720.c +++ b/drivers/pcmcia/sa1111_jornada720.c @@ -38,7 +38,7 @@ static int jornada720_pcmcia_hw_init(struct soc_pcmcia_socket *skt) struct device *dev = skt->socket.dev.parent; struct jornada720_data *j; - j = devm_kzalloc(dev, sizeof(*j), GFP_KERNEL); + j = devm_kzalloc_obj(dev, *j); if (!j) return -ENOMEM; diff --git a/drivers/peci/controller/peci-aspeed.c b/drivers/peci/controller/peci-aspeed.c index 1c747ce8840b10..5dd5cac1b05624 100644 --- a/drivers/peci/controller/peci-aspeed.c +++ b/drivers/peci/controller/peci-aspeed.c @@ -428,7 +428,7 @@ static struct clk *devm_aspeed_peci_register_clk_div(struct device *dev, struct init.num_parents = 1; init.flags = 0; - peci_clk = devm_kzalloc(dev, sizeof(struct clk_aspeed_peci), GFP_KERNEL); + peci_clk = devm_kzalloc_obj(dev, struct clk_aspeed_peci); if (!peci_clk) return ERR_PTR(-ENOMEM); @@ -514,7 +514,7 @@ static int aspeed_peci_probe(struct platform_device *pdev) struct clk *ref_clk; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/peci/controller/peci-npcm.c b/drivers/peci/controller/peci-npcm.c index 3cc4e959aff36f..59dec53f30ee25 100644 --- a/drivers/peci/controller/peci-npcm.c +++ b/drivers/peci/controller/peci-npcm.c @@ -234,7 +234,7 @@ static int npcm_peci_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/peci/cpu.c b/drivers/peci/cpu.c index c9fc06c9ff53a4..aec0280e0cb0d6 100644 --- a/drivers/peci/cpu.c +++ b/drivers/peci/cpu.c @@ -279,7 +279,7 @@ peci_cpu_probe(struct peci_device *device, const struct peci_device_id *id) struct device *dev = &device->dev; struct peci_cpu *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c index 5b6d3a4736da39..c47c6ac170b29a 100644 --- a/drivers/perf/alibaba_uncore_drw_pmu.c +++ b/drivers/perf/alibaba_uncore_drw_pmu.c @@ -665,7 +665,7 @@ static int ali_drw_pmu_probe(struct platform_device *pdev) char *name; int ret; - drw_pmu = devm_kzalloc(&pdev->dev, sizeof(*drw_pmu), GFP_KERNEL); + drw_pmu = devm_kzalloc_obj(&pdev->dev, *drw_pmu); if (!drw_pmu) return -ENOMEM; diff --git a/drivers/perf/amlogic/meson_ddr_pmu_core.c b/drivers/perf/amlogic/meson_ddr_pmu_core.c index f614aa3434a516..76187bd8f2aa87 100644 --- a/drivers/perf/amlogic/meson_ddr_pmu_core.c +++ b/drivers/perf/amlogic/meson_ddr_pmu_core.c @@ -485,7 +485,7 @@ int meson_ddr_pmu_create(struct platform_device *pdev) char *name; struct ddr_pmu *pmu; - pmu = devm_kzalloc(&pdev->dev, sizeof(struct ddr_pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(&pdev->dev, struct ddr_pmu); if (!pmu) return -ENOMEM; diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c index 71035227f58bfc..713b59fe164c77 100644 --- a/drivers/perf/arm-cci.c +++ b/drivers/perf/arm-cci.c @@ -1589,7 +1589,7 @@ static struct cci_pmu *cci_pmu_alloc(struct device *dev) * them explicitly on an error, as it would end up in driver * detach. */ - cci_pmu = devm_kzalloc(dev, sizeof(*cci_pmu), GFP_KERNEL); + cci_pmu = devm_kzalloc_obj(dev, *cci_pmu); if (!cci_pmu) return ERR_PTR(-ENOMEM); @@ -1607,14 +1607,13 @@ static struct cci_pmu *cci_pmu_alloc(struct device *dev) } cci_pmu->model = model; - cci_pmu->irqs = devm_kcalloc(dev, CCI_PMU_MAX_HW_CNTRS(model), - sizeof(*cci_pmu->irqs), GFP_KERNEL); + cci_pmu->irqs = devm_kzalloc_objs(dev, *cci_pmu->irqs, + CCI_PMU_MAX_HW_CNTRS(model)); if (!cci_pmu->irqs) return ERR_PTR(-ENOMEM); - cci_pmu->hw_events.events = devm_kcalloc(dev, - CCI_PMU_MAX_HW_CNTRS(model), - sizeof(*cci_pmu->hw_events.events), - GFP_KERNEL); + cci_pmu->hw_events.events = devm_kzalloc_objs(dev, + *cci_pmu->hw_events.events, + CCI_PMU_MAX_HW_CNTRS(model)); if (!cci_pmu->hw_events.events) return ERR_PTR(-ENOMEM); cci_pmu->hw_events.used_mask = devm_bitmap_zalloc(dev, diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c index e3411bdf5c7c52..0c69165e004180 100644 --- a/drivers/perf/arm-ccn.c +++ b/drivers/perf/arm-ccn.c @@ -1453,7 +1453,7 @@ static int arm_ccn_probe(struct platform_device *pdev) int irq; int err; - ccn = devm_kzalloc(&pdev->dev, sizeof(*ccn), GFP_KERNEL); + ccn = devm_kzalloc_obj(&pdev->dev, *ccn); if (!ccn) return -ENOMEM; ccn->dev = &pdev->dev; @@ -1491,10 +1491,8 @@ static int arm_ccn_probe(struct platform_device *pdev) if (err) return err; - ccn->node = devm_kcalloc(ccn->dev, ccn->num_nodes, sizeof(*ccn->node), - GFP_KERNEL); - ccn->xp = devm_kcalloc(ccn->dev, ccn->num_xps, sizeof(*ccn->node), - GFP_KERNEL); + ccn->node = devm_kzalloc_objs(ccn->dev, *ccn->node, ccn->num_nodes); + ccn->xp = devm_kzalloc_objs(ccn->dev, *ccn->node, ccn->num_xps); if (!ccn->node || !ccn->xp) return -ENOMEM; diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index 5378fba916cf53..68a096c1fe6b0b 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -2408,7 +2408,7 @@ static int arm_cmn_init_dtcs(struct arm_cmn *cmn) struct arm_cmn_node *dn, *xp; int dtc_idx = 0; - cmn->dtc = devm_kcalloc(cmn->dev, cmn->num_dtcs, sizeof(cmn->dtc[0]), GFP_KERNEL); + cmn->dtc = devm_kzalloc_objs(cmn->dev, cmn->dtc[0], cmn->num_dtcs); if (!cmn->dtc) return -ENOMEM; @@ -2602,8 +2602,7 @@ static int arm_cmn_discover(struct arm_cmn *cmn, unsigned int rgn_offset) * by creating one of each internally. For a (very) safe initial upper * bound, account for double the number of non-XP nodes. */ - dn = devm_kcalloc(cmn->dev, cmn->num_dns * 2 - cmn->num_xps, - sizeof(*dn), GFP_KERNEL); + dn = devm_kzalloc_objs(cmn->dev, *dn, cmn->num_dns * 2 - cmn->num_xps); if (!dn) return -ENOMEM; @@ -2611,7 +2610,7 @@ static int arm_cmn_discover(struct arm_cmn *cmn, unsigned int rgn_offset) i = cmn->num_xps; if (cmn->multi_dtm) i += cmn->num_xps + 1; - dtm = devm_kcalloc(cmn->dev, i, sizeof(*dtm), GFP_KERNEL); + dtm = devm_kzalloc_objs(cmn->dev, *dtm, i); if (!dtm) return -ENOMEM; @@ -2837,7 +2836,7 @@ static int arm_cmn_probe(struct platform_device *pdev) static atomic_t id; int err, rootnode, this_id; - cmn = devm_kzalloc(&pdev->dev, sizeof(*cmn), GFP_KERNEL); + cmn = devm_kzalloc_obj(&pdev->dev, *cmn); if (!cmn) return -ENOMEM; diff --git a/drivers/perf/arm-ni.c b/drivers/perf/arm-ni.c index 03a1c6bf9223ab..1f8eecf8ca11a0 100644 --- a/drivers/perf/arm-ni.c +++ b/drivers/perf/arm-ni.c @@ -529,7 +529,7 @@ static int arm_ni_init_cd(struct arm_ni *ni, struct arm_ni_node *node, u64 res_s cd->id = node->id; cd->num_units = node->num_components; - cd->units = devm_kcalloc(ni->dev, cd->num_units, sizeof(*(cd->units)), GFP_KERNEL); + cd->units = devm_kzalloc_objs(ni->dev, *(cd->units), cd->num_units); if (!cd->units) return -ENOMEM; @@ -719,7 +719,7 @@ static int arm_ni_probe(struct platform_device *pdev) } } - ni = devm_kzalloc(&pdev->dev, struct_size(ni, cds, num_cds), GFP_KERNEL); + ni = devm_kzalloc_flex(&pdev->dev, *ni, cds, num_cds); if (!ni) return -ENOMEM; diff --git a/drivers/perf/arm_cspmu/ampere_cspmu.c b/drivers/perf/arm_cspmu/ampere_cspmu.c index b8ca69fd9d1d2e..23abeccc3150fc 100644 --- a/drivers/perf/arm_cspmu/ampere_cspmu.c +++ b/drivers/perf/arm_cspmu/ampere_cspmu.c @@ -209,7 +209,7 @@ static int ampere_cspmu_init_ops(struct arm_cspmu *cspmu) struct ampere_cspmu_ctx *ctx; struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops; - ctx = devm_kzalloc(dev, sizeof(struct ampere_cspmu_ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, struct ampere_cspmu_ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/perf/arm_cspmu/arm_cspmu.c b/drivers/perf/arm_cspmu/arm_cspmu.c index 912f03ce3ef5f4..d0b29213f45114 100644 --- a/drivers/perf/arm_cspmu/arm_cspmu.c +++ b/drivers/perf/arm_cspmu/arm_cspmu.c @@ -500,7 +500,7 @@ arm_cspmu_alloc_event_attr_group(struct arm_cspmu *cspmu) const struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops; event_group = - devm_kzalloc(dev, sizeof(struct attribute_group), GFP_KERNEL); + devm_kzalloc_obj(dev, struct attribute_group); if (!event_group) return NULL; @@ -521,7 +521,7 @@ arm_cspmu_alloc_format_attr_group(struct arm_cspmu *cspmu) struct device *dev = cspmu->dev; format_group = - devm_kzalloc(dev, sizeof(struct attribute_group), GFP_KERNEL); + devm_kzalloc_obj(dev, struct attribute_group); if (!format_group) return NULL; @@ -982,7 +982,7 @@ static struct arm_cspmu *arm_cspmu_alloc(struct platform_device *pdev) struct arm_cspmu *cspmu; struct device *dev = &pdev->dev; - cspmu = devm_kzalloc(dev, sizeof(*cspmu), GFP_KERNEL); + cspmu = devm_kzalloc_obj(dev, *cspmu); if (!cspmu) return NULL; @@ -1074,8 +1074,8 @@ static int arm_cspmu_init_mmio(struct arm_cspmu *cspmu) ARM_CSPMU_SET_CLR_COUNTER_NUM); cspmu->hw_events.events = - devm_kcalloc(dev, cspmu->num_logical_ctrs, - sizeof(*cspmu->hw_events.events), GFP_KERNEL); + devm_kzalloc_objs(dev, *cspmu->hw_events.events, + cspmu->num_logical_ctrs); if (!cspmu->hw_events.events) return -ENOMEM; diff --git a/drivers/perf/arm_cspmu/nvidia_cspmu.c b/drivers/perf/arm_cspmu/nvidia_cspmu.c index a4c1ab88670918..af256f6627310d 100644 --- a/drivers/perf/arm_cspmu/nvidia_cspmu.c +++ b/drivers/perf/arm_cspmu/nvidia_cspmu.c @@ -535,7 +535,7 @@ static int pcie_tgt_init_data(struct arm_cspmu *cspmu) struct nv_cspmu_ctx *ctx = to_nv_cspmu_ctx(cspmu); struct device *dev = cspmu->dev; - data = devm_kzalloc(dev, sizeof(struct pcie_tgt_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct pcie_tgt_data); if (!data) return -ENOMEM; @@ -1008,7 +1008,7 @@ static int nv_cspmu_init_ops(struct arm_cspmu *cspmu) struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops; const struct nv_cspmu_match *match = nv_cspmu_match; - ctx = devm_kzalloc(dev, sizeof(struct nv_cspmu_ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, struct nv_cspmu_ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c index 467147a05eec37..9a7b05b48da073 100644 --- a/drivers/perf/arm_dmc620_pmu.c +++ b/drivers/perf/arm_dmc620_pmu.c @@ -667,8 +667,7 @@ static int dmc620_pmu_device_probe(struct platform_device *pdev) int irq_num; int i, ret; - dmc620_pmu = devm_kzalloc(&pdev->dev, - sizeof(struct dmc620_pmu), GFP_KERNEL); + dmc620_pmu = devm_kzalloc_obj(&pdev->dev, struct dmc620_pmu); if (!dmc620_pmu) return -ENOMEM; diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index 8332eaca06dcc6..751bfed944a93b 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -572,7 +572,7 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) { struct dsu_pmu *dsu_pmu; - dsu_pmu = devm_kzalloc(&pdev->dev, sizeof(*dsu_pmu), GFP_KERNEL); + dsu_pmu = devm_kzalloc_obj(&pdev->dev, *dsu_pmu); if (!dsu_pmu) return ERR_PTR(-ENOMEM); diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c index 8ce34e6bb82b15..97440b6233c6ed 100644 --- a/drivers/perf/arm_smmuv3_pmu.c +++ b/drivers/perf/arm_smmuv3_pmu.c @@ -854,7 +854,7 @@ static int smmu_pmu_probe(struct platform_device *pdev) char *name; struct device *dev = &pdev->dev; - smmu_pmu = devm_kzalloc(dev, sizeof(*smmu_pmu), GFP_KERNEL); + smmu_pmu = devm_kzalloc_obj(dev, *smmu_pmu); if (!smmu_pmu) return -ENOMEM; diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index 604ae6ba3b076b..707778c67dab58 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -1377,7 +1377,7 @@ static int arm_spe_pmu_device_probe(struct platform_device *pdev) return -EPERM; } - spe_pmu = devm_kzalloc(dev, sizeof(*spe_pmu), GFP_KERNEL); + spe_pmu = devm_kzalloc_obj(dev, *spe_pmu); if (!spe_pmu) return -ENOMEM; diff --git a/drivers/perf/cxl_pmu.c b/drivers/perf/cxl_pmu.c index 76c7e5af745493..ce4097c4f64e4c 100644 --- a/drivers/perf/cxl_pmu.c +++ b/drivers/perf/cxl_pmu.c @@ -187,7 +187,7 @@ static int cxl_pmu_parse_caps(struct device *dev, struct cxl_pmu_info *info) group_idx = FIELD_GET(CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK, val); events_msk = FIELD_GET(CXL_PMU_COUNTER_CFG_EVENTS_MSK, val); eval = readq(base + CXL_PMU_EVENT_CAP_REG(group_idx)); - pmu_ev = devm_kzalloc(dev, sizeof(*pmu_ev), GFP_KERNEL); + pmu_ev = devm_kzalloc_obj(dev, *pmu_ev); if (!pmu_ev) return -ENOMEM; @@ -211,7 +211,7 @@ static int cxl_pmu_parse_caps(struct device *dev, struct cxl_pmu_info *info) /* Walk event capabilities unused by fixed counters */ for_each_clear_bit(j, &fixed_counter_event_cap_bm, info->num_event_capabilities) { - pmu_ev = devm_kzalloc(dev, sizeof(*pmu_ev), GFP_KERNEL); + pmu_ev = devm_kzalloc_obj(dev, *pmu_ev); if (!pmu_ev) return -ENOMEM; @@ -978,7 +978,7 @@ static int cxl_pmu_probe(struct device *dev) char *dev_name; int rc, irq; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; @@ -993,8 +993,8 @@ static int cxl_pmu_probe(struct device *dev) if (rc) return rc; - info->hw_events = devm_kcalloc(dev, info->num_counters, - sizeof(*info->hw_events), GFP_KERNEL); + info->hw_events = devm_kzalloc_objs(dev, *info->hw_events, + info->num_counters); if (!info->hw_events) return -ENOMEM; diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index eb86e7468c49b5..039730a3b80da2 100644 --- a/drivers/perf/dwc_pcie_pmu.c +++ b/drivers/perf/dwc_pcie_pmu.c @@ -770,7 +770,7 @@ static int dwc_pcie_pmu_probe(struct platform_device *plat_dev) if (!name) return -ENOMEM; - pcie_pmu = devm_kzalloc(&plat_dev->dev, sizeof(*pcie_pmu), GFP_KERNEL); + pcie_pmu = devm_kzalloc_obj(&plat_dev->dev, *pcie_pmu); if (!pcie_pmu) return -ENOMEM; diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 7553c587260063..39b25d70942d4f 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -794,7 +794,7 @@ static int ddr_perf_probe(struct platform_device *pdev) np = pdev->dev.of_node; - pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(&pdev->dev, *pmu); if (!pmu) return -ENOMEM; diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c index d59bc5ea3155ea..739c6567cd684b 100644 --- a/drivers/perf/fsl_imx9_ddr_perf.c +++ b/drivers/perf/fsl_imx9_ddr_perf.c @@ -787,7 +787,7 @@ static int ddr_perf_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(&pdev->dev, *pmu); if (!pmu) return -ENOMEM; diff --git a/drivers/perf/fujitsu_uncore_pmu.c b/drivers/perf/fujitsu_uncore_pmu.c index db90e181b9a871..f6165eb44c0772 100644 --- a/drivers/perf/fujitsu_uncore_pmu.c +++ b/drivers/perf/fujitsu_uncore_pmu.c @@ -458,7 +458,7 @@ static int fujitsu_uncore_pmu_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "unable to read ACPI uid\n"); - uncorepmu = devm_kzalloc(dev, sizeof(*uncorepmu), GFP_KERNEL); + uncorepmu = devm_kzalloc_obj(dev, *uncorepmu); if (!uncorepmu) return -ENOMEM; uncorepmu->dev = dev; diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index 0a69d13fa4539b..2414f222afcdc2 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -938,7 +938,7 @@ static int hisi_pcie_pmu_probe(struct pci_dev *pdev, const struct pci_device_id struct hisi_pcie_pmu *pcie_pmu; int ret; - pcie_pmu = devm_kzalloc(&pdev->dev, sizeof(*pcie_pmu), GFP_KERNEL); + pcie_pmu = devm_kzalloc_obj(&pdev->dev, *pcie_pmu); if (!pcie_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c index 83967725c51ca2..b2a80ce8f05100 100644 --- a/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c @@ -278,7 +278,7 @@ static int hisi_cpa_pmu_probe(struct platform_device *pdev) char *name; int ret; - cpa_pmu = devm_kzalloc(&pdev->dev, sizeof(*cpa_pmu), GFP_KERNEL); + cpa_pmu = devm_kzalloc_obj(&pdev->dev, *cpa_pmu); if (!cpa_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c index e905160523ee29..5e6bba6b43a105 100644 --- a/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c @@ -378,7 +378,7 @@ static int hisi_ddrc_pmu_probe(struct platform_device *pdev) char *name; int ret; - ddrc_pmu = devm_kzalloc(&pdev->dev, sizeof(*ddrc_pmu), GFP_KERNEL); + ddrc_pmu = devm_kzalloc_obj(&pdev->dev, *ddrc_pmu); if (!ddrc_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c b/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c index 93a250b7abb8ec..9a25fb6d6541e5 100644 --- a/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_hha_pmu.c @@ -475,7 +475,7 @@ static int hisi_hha_pmu_probe(struct platform_device *pdev) char *name; int ret; - hha_pmu = devm_kzalloc(&pdev->dev, sizeof(*hha_pmu), GFP_KERNEL); + hha_pmu = devm_kzalloc_obj(&pdev->dev, *hha_pmu); if (!hha_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_its_pmu.c b/drivers/perf/hisilicon/hisi_uncore_its_pmu.c index 66311657db892d..86f8b07bf41bb9 100644 --- a/drivers/perf/hisilicon/hisi_uncore_its_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_its_pmu.c @@ -309,7 +309,7 @@ static int hisi_its_pmu_probe(struct platform_device *pdev) char *name; int ret; - pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(dev, *pmu); if (!pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c b/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c index e40506e09702d3..167e369cf74c40 100644 --- a/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c @@ -825,7 +825,7 @@ static int hisi_l3c_pmu_probe(struct platform_device *pdev) char *name; int ret; - hisi_l3c_pmu = devm_kzalloc(&pdev->dev, sizeof(*hisi_l3c_pmu), GFP_KERNEL); + hisi_l3c_pmu = devm_kzalloc_obj(&pdev->dev, *hisi_l3c_pmu); if (!hisi_l3c_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_mn_pmu.c b/drivers/perf/hisilicon/hisi_uncore_mn_pmu.c index 1ded8a6b235802..fb7091dddc88e9 100644 --- a/drivers/perf/hisilicon/hisi_uncore_mn_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_mn_pmu.c @@ -343,7 +343,7 @@ static int hisi_mn_pmu_probe(struct platform_device *pdev) char *name; int ret; - mn_pmu = devm_kzalloc(&pdev->dev, sizeof(*mn_pmu), GFP_KERNEL); + mn_pmu = devm_kzalloc_obj(&pdev->dev, *mn_pmu); if (!mn_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_noc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_noc_pmu.c index abf44fa46d171c..29488cb2689e81 100644 --- a/drivers/perf/hisilicon/hisi_uncore_noc_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_noc_pmu.c @@ -336,7 +336,7 @@ static int hisi_noc_pmu_probe(struct platform_device *pdev) char *name; int ret; - noc_pmu = devm_kzalloc(dev, sizeof(*noc_pmu), GFP_KERNEL); + noc_pmu = devm_kzalloc_obj(dev, *noc_pmu); if (!noc_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c index 3d1e0af64260a2..91b51985c52b78 100644 --- a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c @@ -454,7 +454,7 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev) char *name; int ret; - pa_pmu = devm_kzalloc(&pdev->dev, sizeof(*pa_pmu), GFP_KERNEL); + pa_pmu = devm_kzalloc_obj(&pdev->dev, *pa_pmu); if (!pa_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c index d01340ff2e5ce5..a17756ec67652a 100644 --- a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c @@ -490,7 +490,7 @@ static int hisi_sllc_pmu_probe(struct platform_device *pdev) char *name; int ret; - sllc_pmu = devm_kzalloc(&pdev->dev, sizeof(*sllc_pmu), GFP_KERNEL); + sllc_pmu = devm_kzalloc_obj(&pdev->dev, *sllc_pmu); if (!sllc_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c index b4d017a5d688b3..9c0564b9be61b2 100644 --- a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c @@ -499,7 +499,7 @@ static int hisi_uc_pmu_probe(struct platform_device *pdev) char *name; int ret; - uc_pmu = devm_kzalloc(&pdev->dev, sizeof(*uc_pmu), GFP_KERNEL); + uc_pmu = devm_kzalloc_obj(&pdev->dev, *uc_pmu); if (!uc_pmu) return -ENOMEM; diff --git a/drivers/perf/hisilicon/hns3_pmu.c b/drivers/perf/hisilicon/hns3_pmu.c index 88a1129e9b90e6..3069257ca79fb3 100644 --- a/drivers/perf/hisilicon/hns3_pmu.c +++ b/drivers/perf/hisilicon/hns3_pmu.c @@ -1601,7 +1601,7 @@ static int hns3_pmu_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct hns3_pmu *hns3_pmu; int ret; - hns3_pmu = devm_kzalloc(&pdev->dev, sizeof(*hns3_pmu), GFP_KERNEL); + hns3_pmu = devm_kzalloc_obj(&pdev->dev, *hns3_pmu); if (!hns3_pmu) return -ENOMEM; diff --git a/drivers/perf/marvell_cn10k_ddr_pmu.c b/drivers/perf/marvell_cn10k_ddr_pmu.c index 9b68d6c1c31cdc..c699a454593543 100644 --- a/drivers/perf/marvell_cn10k_ddr_pmu.c +++ b/drivers/perf/marvell_cn10k_ddr_pmu.c @@ -1216,7 +1216,7 @@ static int cn10k_ddr_perf_probe(struct platform_device *pdev) char *name; int ret; - ddr_pmu = devm_kzalloc(&pdev->dev, sizeof(*ddr_pmu), GFP_KERNEL); + ddr_pmu = devm_kzalloc_obj(&pdev->dev, *ddr_pmu); if (!ddr_pmu) return -ENOMEM; diff --git a/drivers/perf/marvell_cn10k_tad_pmu.c b/drivers/perf/marvell_cn10k_tad_pmu.c index 301be4d92b1bb4..2d64a335143373 100644 --- a/drivers/perf/marvell_cn10k_tad_pmu.c +++ b/drivers/perf/marvell_cn10k_tad_pmu.c @@ -300,7 +300,7 @@ static int tad_pmu_probe(struct platform_device *pdev) int i, ret; char *name; - tad_pmu = devm_kzalloc(&pdev->dev, sizeof(*tad_pmu), GFP_KERNEL); + tad_pmu = devm_kzalloc_obj(&pdev->dev, *tad_pmu); if (!tad_pmu) return -ENOMEM; @@ -339,8 +339,7 @@ static int tad_pmu_probe(struct platform_device *pdev) return ret; } - regions = devm_kcalloc(&pdev->dev, tad_cnt, - sizeof(*regions), GFP_KERNEL); + regions = devm_kzalloc_objs(&pdev->dev, *regions, tad_cnt); if (!regions) return -ENOMEM; diff --git a/drivers/perf/marvell_pem_pmu.c b/drivers/perf/marvell_pem_pmu.c index cf1d8cdb13186f..f72837fa02f95b 100644 --- a/drivers/perf/marvell_pem_pmu.c +++ b/drivers/perf/marvell_pem_pmu.c @@ -319,7 +319,7 @@ static int pem_perf_probe(struct platform_device *pdev) char *name; int ret; - pem_pmu = devm_kzalloc(&pdev->dev, sizeof(*pem_pmu), GFP_KERNEL); + pem_pmu = devm_kzalloc_obj(&pdev->dev, *pem_pmu); if (!pem_pmu) return -ENOMEM; diff --git a/drivers/perf/nvidia_t410_c2c_pmu.c b/drivers/perf/nvidia_t410_c2c_pmu.c index a41d5712da91b7..1fc2adeb719564 100644 --- a/drivers/perf/nvidia_t410_c2c_pmu.c +++ b/drivers/perf/nvidia_t410_c2c_pmu.c @@ -878,7 +878,7 @@ static void *nv_c2c_pmu_init_pmu(struct platform_device *pdev) if (!acpi_dev) return ERR_PTR(-ENODEV); - c2c_pmu = devm_kzalloc(dev, sizeof(*c2c_pmu), GFP_KERNEL); + c2c_pmu = devm_kzalloc_obj(dev, *c2c_pmu); if (!c2c_pmu) return ERR_PTR(-ENOMEM); diff --git a/drivers/perf/nvidia_t410_cmem_latency_pmu.c b/drivers/perf/nvidia_t410_cmem_latency_pmu.c index da91a51fe29e79..f1eff644b0ba55 100644 --- a/drivers/perf/nvidia_t410_cmem_latency_pmu.c +++ b/drivers/perf/nvidia_t410_cmem_latency_pmu.c @@ -610,7 +610,7 @@ static int cmem_lat_pmu_probe(struct platform_device *pdev) if (ret) return ret; - cmem_lat_pmu = devm_kzalloc(dev, sizeof(*cmem_lat_pmu), GFP_KERNEL); + cmem_lat_pmu = devm_kzalloc_obj(dev, *cmem_lat_pmu); name = devm_kasprintf(dev, GFP_KERNEL, "nvidia_cmem_latency_pmu_%u", socket); if (!cmem_lat_pmu || !name) return -ENOMEM; diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c index 29554cca22c502..644bb54845169f 100644 --- a/drivers/perf/qcom_l2_pmu.c +++ b/drivers/perf/qcom_l2_pmu.c @@ -850,7 +850,7 @@ static int l2_cache_pmu_probe_cluster(struct device *dev, void *data) return err; } - cluster = devm_kzalloc(&pdev->dev, sizeof(*cluster), GFP_KERNEL); + cluster = devm_kzalloc_obj(&pdev->dev, *cluster); if (!cluster) return -ENOMEM; @@ -888,8 +888,7 @@ static int l2_cache_pmu_probe(struct platform_device *pdev) int err; struct l2cache_pmu *l2cache_pmu; - l2cache_pmu = - devm_kzalloc(&pdev->dev, sizeof(*l2cache_pmu), GFP_KERNEL); + l2cache_pmu = devm_kzalloc_obj(&pdev->dev, *l2cache_pmu); if (!l2cache_pmu) return -ENOMEM; diff --git a/drivers/perf/qcom_l3_pmu.c b/drivers/perf/qcom_l3_pmu.c index d036fa05aeaba7..3e0c00e3733f54 100644 --- a/drivers/perf/qcom_l3_pmu.c +++ b/drivers/perf/qcom_l3_pmu.c @@ -731,7 +731,7 @@ static int qcom_l3_cache_pmu_probe(struct platform_device *pdev) if (!acpi_dev) return -ENODEV; - l3pmu = devm_kzalloc(&pdev->dev, sizeof(*l3pmu), GFP_KERNEL); + l3pmu = devm_kzalloc_obj(&pdev->dev, *l3pmu); name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "l3cache_%s_%s", acpi_device_uid(acpi_dev_parent(acpi_dev)), acpi_device_uid(acpi_dev)); diff --git a/drivers/perf/starfive_starlink_pmu.c b/drivers/perf/starfive_starlink_pmu.c index d9843645554bad..7f603a95136b43 100644 --- a/drivers/perf/starfive_starlink_pmu.c +++ b/drivers/perf/starfive_starlink_pmu.c @@ -510,7 +510,7 @@ static int starlink_pmu_probe(struct platform_device *pdev) struct resource *res; int cpuid, i, ret; - starlink_pmu = devm_kzalloc(&pdev->dev, sizeof(*starlink_pmu), GFP_KERNEL); + starlink_pmu = devm_kzalloc_obj(&pdev->dev, *starlink_pmu); if (!starlink_pmu) return -ENOMEM; diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c index a69c02d2d874f5..3cf079c7ff41ce 100644 --- a/drivers/perf/thunderx2_pmu.c +++ b/drivers/perf/thunderx2_pmu.c @@ -815,7 +815,7 @@ static struct tx2_uncore_pmu *tx2_uncore_pmu_init_dev(struct device *dev, if (IS_ERR(base)) return NULL; - tx2_pmu = devm_kzalloc(dev, sizeof(*tx2_pmu), GFP_KERNEL); + tx2_pmu = devm_kzalloc_obj(dev, *tx2_pmu); if (!tx2_pmu) return NULL; diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c index aa38426352d2f6..9ac57f9b44133a 100644 --- a/drivers/perf/xgene_pmu.c +++ b/drivers/perf/xgene_pmu.c @@ -1120,7 +1120,7 @@ xgene_pmu_dev_add(struct xgene_pmu *xgene_pmu, struct xgene_pmu_dev_ctx *ctx) struct device *dev = xgene_pmu->dev; struct xgene_pmu_dev *pmu; - pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(dev, *pmu); if (!pmu) return -ENOMEM; pmu->parent = xgene_pmu; @@ -1454,7 +1454,7 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, int enable_bit; int rc; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return NULL; @@ -1620,7 +1620,7 @@ xgene_pmu_dev_ctx *fdt_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, struct resource res; int enable_bit; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return NULL; @@ -1839,7 +1839,7 @@ static int xgene_pmu_probe(struct platform_device *pdev) if (rc) return rc; - xgene_pmu = devm_kzalloc(&pdev->dev, sizeof(*xgene_pmu), GFP_KERNEL); + xgene_pmu = devm_kzalloc_obj(&pdev->dev, *xgene_pmu); if (!xgene_pmu) return -ENOMEM; xgene_pmu->dev = &pdev->dev; diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index e2fbf8ccf99e17..f26eed0db17efb 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -724,7 +724,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int i, ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/phy/allwinner/phy-sun50i-usb3.c b/drivers/phy/allwinner/phy-sun50i-usb3.c index 84055b720016eb..06bd74e7fe8da4 100644 --- a/drivers/phy/allwinner/phy-sun50i-usb3.c +++ b/drivers/phy/allwinner/phy-sun50i-usb3.c @@ -135,7 +135,7 @@ static int sun50i_usb3_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct phy_provider *phy_provider; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/allwinner/phy-sun6i-mipi-dphy.c b/drivers/phy/allwinner/phy-sun6i-mipi-dphy.c index 36eab95271b2dc..e5a9aa3f4aac87 100644 --- a/drivers/phy/allwinner/phy-sun6i-mipi-dphy.c +++ b/drivers/phy/allwinner/phy-sun6i-mipi-dphy.c @@ -553,7 +553,7 @@ static int sun6i_dphy_probe(struct platform_device *pdev) void __iomem *regs; int ret; - dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); + dphy = devm_kzalloc_obj(&pdev->dev, *dphy); if (!dphy) return -ENOMEM; diff --git a/drivers/phy/allwinner/phy-sun9i-usb.c b/drivers/phy/allwinner/phy-sun9i-usb.c index 2f9e60c188b8f9..8811870b63cbad 100644 --- a/drivers/phy/allwinner/phy-sun9i-usb.c +++ b/drivers/phy/allwinner/phy-sun9i-usb.c @@ -118,7 +118,7 @@ static int sun9i_usb_phy_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct phy_provider *phy_provider; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-axg-mipi-dphy.c b/drivers/phy/amlogic/phy-meson-axg-mipi-dphy.c index 5e2b7d93bdb114..6cf06041e254bd 100644 --- a/drivers/phy/amlogic/phy-meson-axg-mipi-dphy.c +++ b/drivers/phy/amlogic/phy-meson-axg-mipi-dphy.c @@ -339,7 +339,7 @@ static int phy_meson_axg_mipi_dphy_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-axg-mipi-pcie-analog.c b/drivers/phy/amlogic/phy-meson-axg-mipi-pcie-analog.c index c0ba2852dbb8e2..d5d5d13f2d41bc 100644 --- a/drivers/phy/amlogic/phy-meson-axg-mipi-pcie-analog.c +++ b/drivers/phy/amlogic/phy-meson-axg-mipi-pcie-analog.c @@ -201,7 +201,7 @@ static int phy_axg_mipi_pcie_analog_probe(struct platform_device *pdev) struct device_node *np = dev->of_node, *parent_np; struct regmap *map; - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-axg-pcie.c b/drivers/phy/amlogic/phy-meson-axg-pcie.c index 13668764655c59..63d2ffe2fee7b8 100644 --- a/drivers/phy/amlogic/phy-meson-axg-pcie.c +++ b/drivers/phy/amlogic/phy-meson-axg-pcie.c @@ -131,7 +131,7 @@ static int phy_axg_pcie_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; void __iomem *base; - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c b/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c index 46e5f7e7eb6c8a..5fc8d2054e0f0b 100644 --- a/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c +++ b/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c @@ -125,7 +125,7 @@ static int phy_g12a_mipi_dphy_analog_probe(struct platform_device *pdev) struct device_node *np = dev->of_node, *parent_np; struct regmap *map; - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb2.c b/drivers/phy/amlogic/phy-meson-g12a-usb2.c index 66bf0b7ef8ed38..9f398856b31786 100644 --- a/drivers/phy/amlogic/phy-meson-g12a-usb2.c +++ b/drivers/phy/amlogic/phy-meson-g12a-usb2.c @@ -308,7 +308,7 @@ static int phy_meson_g12a_usb2_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c index 5468831d6ab9bb..f94c08b17267ae 100644 --- a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c +++ b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c @@ -389,7 +389,7 @@ static int phy_g12a_usb3_pcie_probe(struct platform_device *pdev) struct phy_provider *phy_provider; void __iomem *base; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson-gxl-usb2.c b/drivers/phy/amlogic/phy-meson-gxl-usb2.c index f6bc0ca248f72c..58e47a31e4c981 100644 --- a/drivers/phy/amlogic/phy-meson-gxl-usb2.c +++ b/drivers/phy/amlogic/phy-meson-gxl-usb2.c @@ -237,7 +237,7 @@ static int phy_meson_gxl_usb2_probe(struct platform_device *pdev) struct phy *phy; void __iomem *base; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson8-hdmi-tx.c b/drivers/phy/amlogic/phy-meson8-hdmi-tx.c index 2617f7f6c2ec59..f6b5df74a58f5b 100644 --- a/drivers/phy/amlogic/phy-meson8-hdmi-tx.c +++ b/drivers/phy/amlogic/phy-meson8-hdmi-tx.c @@ -116,7 +116,7 @@ static int phy_meson8_hdmi_tx_probe(struct platform_device *pdev) if (!res) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/amlogic/phy-meson8b-usb2.c b/drivers/phy/amlogic/phy-meson8b-usb2.c index 71e5e281f18836..0cecd23f0ab58a 100644 --- a/drivers/phy/amlogic/phy-meson8b-usb2.c +++ b/drivers/phy/amlogic/phy-meson8b-usb2.c @@ -235,7 +235,7 @@ static int phy_meson8b_usb2_probe(struct platform_device *pdev) struct phy_provider *phy_provider; void __iomem *base; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 45f1280a6faa32..37d7e266a0159c 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -2297,7 +2297,7 @@ static int atcphy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - atcphy = devm_kzalloc(&pdev->dev, sizeof(*atcphy), GFP_KERNEL); + atcphy = devm_kzalloc_obj(&pdev->dev, *atcphy); if (!atcphy) return -ENOMEM; diff --git a/drivers/phy/aspeed/phy-aspeed-usb3.c b/drivers/phy/aspeed/phy-aspeed-usb3.c index 6f371cae02f3e6..9983644831a678 100644 --- a/drivers/phy/aspeed/phy-aspeed-usb3.c +++ b/drivers/phy/aspeed/phy-aspeed-usb3.c @@ -186,7 +186,7 @@ static int aspeed_usb3_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct phy *phy; - aspeed_phy = devm_kzalloc(dev, sizeof(*aspeed_phy), GFP_KERNEL); + aspeed_phy = devm_kzalloc_obj(dev, *aspeed_phy); if (!aspeed_phy) return -ENOMEM; diff --git a/drivers/phy/axiado/phy-axiado-emmc.c b/drivers/phy/axiado/phy-axiado-emmc.c index e0e2174776ad02..1b4a73161fbc92 100644 --- a/drivers/phy/axiado/phy-axiado-emmc.c +++ b/drivers/phy/axiado/phy-axiado-emmc.c @@ -182,7 +182,7 @@ static int axiado_emmc_phy_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - ax_phy = devm_kzalloc(dev, sizeof(*ax_phy), GFP_KERNEL); + ax_phy = devm_kzalloc_obj(dev, *ax_phy); if (!ax_phy) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c b/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c index 462c61a24ec5cf..ef621bdc90350c 100644 --- a/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c +++ b/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c @@ -123,7 +123,7 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev) return -ENODEV; } - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-kona-usb2.c b/drivers/phy/broadcom/phy-bcm-kona-usb2.c index e9cc5f2cb89afc..449748d1cf1236 100644 --- a/drivers/phy/broadcom/phy-bcm-kona-usb2.c +++ b/drivers/phy/broadcom/phy-bcm-kona-usb2.c @@ -97,7 +97,7 @@ static int bcm_kona_usb2_probe(struct platform_device *pdev) struct phy *gphy; struct phy_provider *phy_provider; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb2.c b/drivers/phy/broadcom/phy-bcm-ns-usb2.c index c5d35031b39833..028afac15158e9 100644 --- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c +++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c @@ -88,7 +88,7 @@ static int bcm_ns_usb2_probe(struct platform_device *pdev) struct bcm_ns_usb2 *usb2; struct phy_provider *phy_provider; - usb2 = devm_kzalloc(&pdev->dev, sizeof(*usb2), GFP_KERNEL); + usb2 = devm_kzalloc_obj(&pdev->dev, *usb2); if (!usb2) return -ENOMEM; usb2->dev = dev; diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb3.c b/drivers/phy/broadcom/phy-bcm-ns-usb3.c index 9240600aeef6e4..1cf3babfc5a22c 100644 --- a/drivers/phy/broadcom/phy-bcm-ns-usb3.c +++ b/drivers/phy/broadcom/phy-bcm-ns-usb3.c @@ -197,7 +197,7 @@ static int bcm_ns_usb3_mdio_probe(struct mdio_device *mdiodev) struct resource res; int err; - usb3 = devm_kzalloc(dev, sizeof(*usb3), GFP_KERNEL); + usb3 = devm_kzalloc_obj(dev, *usb3); if (!usb3) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c index 171bf097a8b811..bb4221fec01b59 100644 --- a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c +++ b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c @@ -285,13 +285,11 @@ static int ns2_drd_phy_probe(struct platform_device *pdev) int ret; u32 val; - driver = devm_kzalloc(dev, sizeof(struct ns2_phy_driver), - GFP_KERNEL); + driver = devm_kzalloc_obj(dev, struct ns2_phy_driver); if (!driver) return -ENOMEM; - driver->data = devm_kzalloc(dev, sizeof(struct ns2_phy_data), - GFP_KERNEL); + driver->data = devm_kzalloc_obj(dev, struct ns2_phy_data); if (!driver->data) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-sr-pcie.c b/drivers/phy/broadcom/phy-bcm-sr-pcie.c index 706e1d83b4ceec..1361acd64206ed 100644 --- a/drivers/phy/broadcom/phy-bcm-sr-pcie.c +++ b/drivers/phy/broadcom/phy-bcm-sr-pcie.c @@ -220,7 +220,7 @@ static int sr_pcie_phy_probe(struct platform_device *pdev) struct phy_provider *provider; unsigned int phy_idx = 0; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm-sr-usb.c b/drivers/phy/broadcom/phy-bcm-sr-usb.c index 6bcfe83609c865..cca8303a66e9c8 100644 --- a/drivers/phy/broadcom/phy-bcm-sr-usb.c +++ b/drivers/phy/broadcom/phy-bcm-sr-usb.c @@ -260,8 +260,7 @@ static int bcm_usb_phy_create(struct device *dev, struct device_node *node, phy_set_drvdata(phy_cfg[idx].phy, &phy_cfg[idx]); } } else if (version == BCM_SR_USB_HS_PHY) { - phy_cfg = devm_kzalloc(dev, sizeof(struct bcm_usb_phy_cfg), - GFP_KERNEL); + phy_cfg = devm_kzalloc_obj(dev, struct bcm_usb_phy_cfg); if (!phy_cfg) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-bcm63xx-usbh.c b/drivers/phy/broadcom/phy-bcm63xx-usbh.c index 29fd6791bae642..43894d4dfec693 100644 --- a/drivers/phy/broadcom/phy-bcm63xx-usbh.c +++ b/drivers/phy/broadcom/phy-bcm63xx-usbh.c @@ -383,7 +383,7 @@ static int bcm63xx_usbh_phy_probe(struct platform_device *pdev) struct phy *phy; struct phy_provider *phy_provider; - usbh = devm_kzalloc(dev, sizeof(*usbh), GFP_KERNEL); + usbh = devm_kzalloc_obj(dev, *usbh); if (!usbh) return -ENOMEM; diff --git a/drivers/phy/broadcom/phy-brcm-sata.c b/drivers/phy/broadcom/phy-brcm-sata.c index 43b287a25e7a8e..e9829587f284bf 100644 --- a/drivers/phy/broadcom/phy-brcm-sata.c +++ b/drivers/phy/broadcom/phy-brcm-sata.c @@ -760,7 +760,7 @@ static int brcm_sata_phy_probe(struct platform_device *pdev) if (of_get_child_count(dn) == 0) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; dev_set_drvdata(dev, priv); diff --git a/drivers/phy/broadcom/phy-brcm-usb.c b/drivers/phy/broadcom/phy-brcm-usb.c index e606db489698a4..0662ff45062833 100644 --- a/drivers/phy/broadcom/phy-brcm-usb.c +++ b/drivers/phy/broadcom/phy-brcm-usb.c @@ -491,7 +491,7 @@ static int brcm_usb_phy_probe(struct platform_device *pdev) struct regmap *rmap; int x; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/drivers/phy/cadence/cdns-dphy-rx.c b/drivers/phy/cadence/cdns-dphy-rx.c index 469b8eaca94c77..d3f7e9513dd68f 100644 --- a/drivers/phy/cadence/cdns-dphy-rx.c +++ b/drivers/phy/cadence/cdns-dphy-rx.c @@ -240,7 +240,7 @@ static int cdns_dphy_rx_probe(struct platform_device *pdev) struct phy_provider *provider; struct cdns_dphy_rx *dphy; - dphy = devm_kzalloc(dev, sizeof(*dphy), GFP_KERNEL); + dphy = devm_kzalloc_obj(dev, *dphy); if (!dphy) return -ENOMEM; diff --git a/drivers/phy/cadence/cdns-dphy.c b/drivers/phy/cadence/cdns-dphy.c index d5b0e516b93c0f..483e35c82a1139 100644 --- a/drivers/phy/cadence/cdns-dphy.c +++ b/drivers/phy/cadence/cdns-dphy.c @@ -471,7 +471,7 @@ static int cdns_dphy_probe(struct platform_device *pdev) struct cdns_dphy *dphy; int ret; - dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); + dphy = devm_kzalloc_obj(&pdev->dev, *dphy); if (!dphy) return -ENOMEM; dev_set_drvdata(&pdev->dev, dphy); diff --git a/drivers/phy/cadence/phy-cadence-salvo.c b/drivers/phy/cadence/phy-cadence-salvo.c index f461585c84c62f..81edac6778edaa 100644 --- a/drivers/phy/cadence/phy-cadence-salvo.c +++ b/drivers/phy/cadence/phy-cadence-salvo.c @@ -335,7 +335,7 @@ static int cdns_salvo_phy_probe(struct platform_device *pdev) u32 val; data = (struct cdns_salvo_data *)of_device_get_match_data(dev); - salvo_phy = devm_kzalloc(dev, sizeof(*salvo_phy), GFP_KERNEL); + salvo_phy = devm_kzalloc_obj(dev, *salvo_phy); if (!salvo_phy) return -ENOMEM; diff --git a/drivers/phy/cadence/phy-cadence-sierra.c b/drivers/phy/cadence/phy-cadence-sierra.c index dbeda7f01cbb27..c90e3cd6365a9d 100644 --- a/drivers/phy/cadence/phy-cadence-sierra.c +++ b/drivers/phy/cadence/phy-cadence-sierra.c @@ -755,7 +755,7 @@ static int cdns_sierra_pll_mux_register(struct cdns_sierra_phy *sp, char clk_name[100]; int ret; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; @@ -856,7 +856,7 @@ static int cdns_sierra_derived_refclk_register(struct cdns_sierra_phy *sp) char clk_name[100]; int ret; - derived_refclk = devm_kzalloc(dev, sizeof(*derived_refclk), GFP_KERNEL); + derived_refclk = devm_kzalloc_obj(dev, *derived_refclk); if (!derived_refclk) return -ENOMEM; @@ -974,7 +974,7 @@ static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base, { struct cdns_regmap_cdb_context *ctx; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); @@ -1373,9 +1373,8 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev) if (!data) return -EINVAL; - sp = devm_kzalloc(dev, struct_size(sp, clk_data.hws, - CDNS_SIERRA_OUTPUT_CLOCKS), - GFP_KERNEL); + sp = devm_kzalloc_flex(dev, *sp, clk_data.hws, + CDNS_SIERRA_OUTPUT_CLOCKS); if (!sp) return -ENOMEM; dev_set_drvdata(dev, sp); diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c index d446a0f97688ef..1e178aa2ffd76e 100644 --- a/drivers/phy/cadence/phy-cadence-torrent.c +++ b/drivers/phy/cadence/phy-cadence-torrent.c @@ -1863,7 +1863,7 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph struct clk *clk; int ret; - derived_refclk = devm_kzalloc(dev, sizeof(*derived_refclk), GFP_KERNEL); + derived_refclk = devm_kzalloc_obj(dev, *derived_refclk); if (!derived_refclk) return -ENOMEM; @@ -1946,7 +1946,7 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p struct clk *clk; int ret; - received_refclk = devm_kzalloc(dev, sizeof(*received_refclk), GFP_KERNEL); + received_refclk = devm_kzalloc_obj(dev, *received_refclk); if (!received_refclk) return -ENOMEM; @@ -2053,7 +2053,7 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy struct clk_hw *hw; int i, ret; - refclk_driver = devm_kzalloc(dev, sizeof(*refclk_driver), GFP_KERNEL); + refclk_driver = devm_kzalloc_obj(dev, *refclk_driver); if (!refclk_driver) return -ENOMEM; @@ -2115,7 +2115,7 @@ static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base, { struct cdns_regmap_cdb_context *ctx; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return ERR_PTR(-ENOMEM); @@ -2752,7 +2752,7 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy) struct clk_hw_onecell_data *data; int ret; - data = devm_kzalloc(dev, struct_size(data, hws, CDNS_TORRENT_OUTPUT_CLOCKS), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, hws, CDNS_TORRENT_OUTPUT_CLOCKS); if (!data) return -ENOMEM; @@ -2924,7 +2924,7 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) if (!data) return -EINVAL; - cdns_phy = devm_kzalloc(dev, sizeof(*cdns_phy), GFP_KERNEL); + cdns_phy = devm_kzalloc_obj(dev, *cdns_phy); if (!cdns_phy) return -ENOMEM; diff --git a/drivers/phy/canaan/phy-k230-usb.c b/drivers/phy/canaan/phy-k230-usb.c index 52dad35fc6cf18..2480eeaf0f6665 100644 --- a/drivers/phy/canaan/phy-k230-usb.c +++ b/drivers/phy/canaan/phy-k230-usb.c @@ -220,7 +220,7 @@ static int k230_usb_phy_probe(struct platform_device *pdev) struct phy_provider *provider; int i; - global = devm_kzalloc(dev, sizeof(*global), GFP_KERNEL); + global = devm_kzalloc_obj(dev, *global); if (!global) return -ENOMEM; dev_set_drvdata(dev, global); diff --git a/drivers/phy/eswin/phy-eic7700-sata.c b/drivers/phy/eswin/phy-eic7700-sata.c index 76774b9e391b1f..2656e0b7688975 100644 --- a/drivers/phy/eswin/phy-eic7700-sata.c +++ b/drivers/phy/eswin/phy-eic7700-sata.c @@ -200,7 +200,7 @@ static int eic7700_sata_phy_probe(struct platform_device *pdev) struct resource *res; void __iomem *regs; - sata_phy = devm_kzalloc(dev, sizeof(*sata_phy), GFP_KERNEL); + sata_phy = devm_kzalloc_obj(dev, *sata_phy); if (!sata_phy) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c index 0928a526e2ab36..24c8b077774762 100644 --- a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c +++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c @@ -670,7 +670,7 @@ static int mixel_dphy_probe(struct platform_device *pdev) if (!np) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-imx8m-pcie.c b/drivers/phy/freescale/phy-fsl-imx8m-pcie.c index 7f5600103a0019..b94b9ab2636784 100644 --- a/drivers/phy/freescale/phy-fsl-imx8m-pcie.c +++ b/drivers/phy/freescale/phy-fsl-imx8m-pcie.c @@ -215,7 +215,7 @@ static int imx8_pcie_phy_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct imx8_pcie_phy *imx8_phy; - imx8_phy = devm_kzalloc(dev, sizeof(*imx8_phy), GFP_KERNEL); + imx8_phy = devm_kzalloc_obj(dev, *imx8_phy); if (!imx8_phy) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c index 8859835541b171..3f8fe63fa7cd91 100644 --- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c +++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c @@ -262,7 +262,7 @@ static struct tca_blk *imx95_usb_phy_get_tca(struct platform_device *pdev, if (!res) return NULL; - tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL); + tca = devm_kzalloc_obj(dev, *tca); if (!tca) return ERR_PTR(-ENOMEM); @@ -705,7 +705,7 @@ static int imx8mq_usb_phy_probe(struct platform_device *pdev) const struct imx8mq_usb_phy_drvdata *phy_data; int ret; - imx_phy = devm_kzalloc(dev, sizeof(*imx_phy), GFP_KERNEL); + imx_phy = devm_kzalloc_obj(dev, *imx_phy); if (!imx_phy) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c index 4ab45c9f53dff0..d29dbf57db88a0 100644 --- a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c +++ b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c @@ -555,7 +555,7 @@ static int imx_hsio_probe(struct platform_device *pdev) struct imx_hsio_priv *priv; struct phy_provider *provider; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; diff --git a/drivers/phy/freescale/phy-fsl-imx8qm-lvds-phy.c b/drivers/phy/freescale/phy-fsl-imx8qm-lvds-phy.c index 368679436d8627..2ad50201999511 100644 --- a/drivers/phy/freescale/phy-fsl-imx8qm-lvds-phy.c +++ b/drivers/phy/freescale/phy-fsl-imx8qm-lvds-phy.c @@ -327,7 +327,7 @@ static int mixel_lvds_phy_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -356,7 +356,7 @@ static int mixel_lvds_phy_probe(struct platform_device *pdev) } for (i = 0; i < PHY_NUM; i++) { - lvds_phy = devm_kzalloc(dev, sizeof(*lvds_phy), GFP_KERNEL); + lvds_phy = devm_kzalloc_obj(dev, *lvds_phy); if (!lvds_phy) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-lynx-core.c b/drivers/phy/freescale/phy-fsl-lynx-core.c index 2cfe9236ffc55c..efdd56cc1f353e 100644 --- a/drivers/phy/freescale/phy-fsl-lynx-core.c +++ b/drivers/phy/freescale/phy-fsl-lynx-core.c @@ -357,7 +357,7 @@ int lynx_probe(struct platform_device *pdev, const struct lynx_info *info, if (!info) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -368,8 +368,7 @@ int lynx_probe(struct platform_device *pdev, const struct lynx_info *info, spin_lock_init(&priv->pcc_lock); INIT_DELAYED_WORK(&priv->cdr_check, lynx_cdr_lock_check); - priv->lane = devm_kcalloc(dev, priv->info->num_lanes, - sizeof(*priv->lane), GFP_KERNEL); + priv->lane = devm_kzalloc_objs(dev, *priv->lane, priv->info->num_lanes); if (!priv->lane) return -ENOMEM; diff --git a/drivers/phy/freescale/phy-fsl-samsung-hdmi.c b/drivers/phy/freescale/phy-fsl-samsung-hdmi.c index 02539ad0b0fedf..aaa651abcbc614 100644 --- a/drivers/phy/freescale/phy-fsl-samsung-hdmi.c +++ b/drivers/phy/freescale/phy-fsl-samsung-hdmi.c @@ -643,7 +643,7 @@ static int fsl_samsung_hdmi_phy_probe(struct platform_device *pdev) struct fsl_samsung_hdmi_phy *phy; int ret; - phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&pdev->dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hi3660-usb3.c b/drivers/phy/hisilicon/phy-hi3660-usb3.c index e2a09d67faed9a..004275a1ce3f22 100644 --- a/drivers/phy/hisilicon/phy-hi3660-usb3.c +++ b/drivers/phy/hisilicon/phy-hi3660-usb3.c @@ -175,7 +175,7 @@ static int hi3660_phy_probe(struct platform_device *pdev) struct phy *phy; struct hi3660_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hi3670-pcie.c b/drivers/phy/hisilicon/phy-hi3670-pcie.c index 148763ed2c62a8..78758d704315fa 100644 --- a/drivers/phy/hisilicon/phy-hi3670-pcie.c +++ b/drivers/phy/hisilicon/phy-hi3670-pcie.c @@ -805,7 +805,7 @@ static int hi3670_pcie_phy_probe(struct platform_device *pdev) struct phy *generic_phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hi3670-usb3.c b/drivers/phy/hisilicon/phy-hi3670-usb3.c index 40d3cf128b4403..db22564dddd637 100644 --- a/drivers/phy/hisilicon/phy-hi3670-usb3.c +++ b/drivers/phy/hisilicon/phy-hi3670-usb3.c @@ -592,7 +592,7 @@ static int hi3670_phy_probe(struct platform_device *pdev) struct phy *phy; struct hi3670_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hi6220-usb.c b/drivers/phy/hisilicon/phy-hi6220-usb.c index 4e6ff3af381f2c..e94a7612011365 100644 --- a/drivers/phy/hisilicon/phy-hi6220-usb.c +++ b/drivers/phy/hisilicon/phy-hi6220-usb.c @@ -121,7 +121,7 @@ static int hi6220_phy_probe(struct platform_device *pdev) struct phy *phy; struct hi6220_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c index c843923252aace..9310533d53f08b 100644 --- a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c +++ b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c @@ -141,7 +141,7 @@ static int hisi_inno_phy_probe(struct platform_device *pdev) int i = 0; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-histb-combphy.c b/drivers/phy/hisilicon/phy-histb-combphy.c index 9dd0bd00b4e440..7d2bbe6e33628f 100644 --- a/drivers/phy/hisilicon/phy-histb-combphy.c +++ b/drivers/phy/hisilicon/phy-histb-combphy.c @@ -199,7 +199,7 @@ static int histb_combphy_probe(struct platform_device *pdev) u32 vals[3]; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/hisilicon/phy-hix5hd2-sata.c b/drivers/phy/hisilicon/phy-hix5hd2-sata.c index 1b26ddb4c8a71b..a1a00a52a340ea 100644 --- a/drivers/phy/hisilicon/phy-hix5hd2-sata.c +++ b/drivers/phy/hisilicon/phy-hix5hd2-sata.c @@ -139,7 +139,7 @@ static int hix5hd2_sata_phy_probe(struct platform_device *pdev) struct phy *phy; struct hix5hd2_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/ingenic/phy-ingenic-usb.c b/drivers/phy/ingenic/phy-ingenic-usb.c index 7e62d46850fdaf..f21c3727ad5951 100644 --- a/drivers/phy/ingenic/phy-ingenic-usb.c +++ b/drivers/phy/ingenic/phy-ingenic-usb.c @@ -320,7 +320,7 @@ static int ingenic_usb_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/intel/phy-intel-keembay-emmc.c b/drivers/phy/intel/phy-intel-keembay-emmc.c index 0eb11ac7c2e2e3..3f53032152fedb 100644 --- a/drivers/phy/intel/phy-intel-keembay-emmc.c +++ b/drivers/phy/intel/phy-intel-keembay-emmc.c @@ -265,7 +265,7 @@ static int keembay_emmc_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; void __iomem *base; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/intel/phy-intel-keembay-usb.c b/drivers/phy/intel/phy-intel-keembay-usb.c index 7c2192965f685a..288c0e0f158b12 100644 --- a/drivers/phy/intel/phy-intel-keembay-usb.c +++ b/drivers/phy/intel/phy-intel-keembay-usb.c @@ -238,7 +238,7 @@ static int keembay_usb_phy_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/intel/phy-intel-lgm-combo.c b/drivers/phy/intel/phy-intel-lgm-combo.c index 9ee3cf61cdd004..72f8c32ea41103 100644 --- a/drivers/phy/intel/phy-intel-lgm-combo.c +++ b/drivers/phy/intel/phy-intel-lgm-combo.c @@ -573,7 +573,7 @@ static int intel_cbphy_probe(struct platform_device *pdev) struct intel_combo_phy *cbphy; int ret; - cbphy = devm_kzalloc(dev, sizeof(*cbphy), GFP_KERNEL); + cbphy = devm_kzalloc_obj(dev, *cbphy); if (!cbphy) return -ENOMEM; diff --git a/drivers/phy/intel/phy-intel-lgm-emmc.c b/drivers/phy/intel/phy-intel-lgm-emmc.c index 703aeb122541ce..a37d98b12b603c 100644 --- a/drivers/phy/intel/phy-intel-lgm-emmc.c +++ b/drivers/phy/intel/phy-intel-lgm-emmc.c @@ -239,7 +239,7 @@ static int intel_emmc_phy_probe(struct platform_device *pdev) struct phy *generic_phy; struct phy_provider *phy_provider; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/lantiq/phy-lantiq-rcu-usb2.c b/drivers/phy/lantiq/phy-lantiq-rcu-usb2.c index 82f1ffc0b0ad97..ff0cde7a33a679 100644 --- a/drivers/phy/lantiq/phy-lantiq-rcu-usb2.c +++ b/drivers/phy/lantiq/phy-lantiq-rcu-usb2.c @@ -210,7 +210,7 @@ static int ltq_rcu_usb2_phy_probe(struct platform_device *pdev) struct phy_provider *provider; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/lantiq/phy-lantiq-vrx200-pcie.c b/drivers/phy/lantiq/phy-lantiq-vrx200-pcie.c index 406a87c8b75990..e9742f80f33c8b 100644 --- a/drivers/phy/lantiq/phy-lantiq-vrx200-pcie.c +++ b/drivers/phy/lantiq/phy-lantiq-vrx200-pcie.c @@ -405,7 +405,7 @@ static int ltq_vrx200_pcie_phy_probe(struct platform_device *pdev) void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-armada375-usb2.c b/drivers/phy/marvell/phy-armada375-usb2.c index 3731f9b25655e4..6f4baaa5ca77ae 100644 --- a/drivers/phy/marvell/phy-armada375-usb2.c +++ b/drivers/phy/marvell/phy-armada375-usb2.c @@ -107,7 +107,7 @@ static int armada375_usb_phy_probe(struct platform_device *pdev) void __iomem *usb_cluster_base; struct armada375_cluster_phy *cluster_phy; - cluster_phy = devm_kzalloc(dev, sizeof(*cluster_phy), GFP_KERNEL); + cluster_phy = devm_kzalloc_obj(dev, *cluster_phy); if (!cluster_phy) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-armada38x-comphy.c b/drivers/phy/marvell/phy-armada38x-comphy.c index 5063361b01208e..fdbf5d4350e4f7 100644 --- a/drivers/phy/marvell/phy-armada38x-comphy.c +++ b/drivers/phy/marvell/phy-armada38x-comphy.c @@ -200,7 +200,7 @@ static int a38x_comphy_probe(struct platform_device *pdev) struct resource *res; void __iomem *base; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-berlin-sata.c b/drivers/phy/marvell/phy-berlin-sata.c index c90e2867900c3f..084671ee7d565b 100644 --- a/drivers/phy/marvell/phy-berlin-sata.c +++ b/drivers/phy/marvell/phy-berlin-sata.c @@ -196,7 +196,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev) int ret, i = 0; u32 phy_id; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -216,8 +216,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev) if (priv->nphys == 0) return -ENODEV; - priv->phys = devm_kcalloc(dev, priv->nphys, sizeof(*priv->phys), - GFP_KERNEL); + priv->phys = devm_kzalloc_objs(dev, *priv->phys, priv->nphys); if (!priv->phys) return -ENOMEM; @@ -245,7 +244,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev) goto put_child; } - phy_desc = devm_kzalloc(dev, sizeof(*phy_desc), GFP_KERNEL); + phy_desc = devm_kzalloc_obj(dev, *phy_desc); if (!phy_desc) { ret = -ENOMEM; goto put_child; diff --git a/drivers/phy/marvell/phy-berlin-usb.c b/drivers/phy/marvell/phy-berlin-usb.c index f26bf630da2c9f..8d62a8d5873664 100644 --- a/drivers/phy/marvell/phy-berlin-usb.c +++ b/drivers/phy/marvell/phy-berlin-usb.c @@ -167,7 +167,7 @@ static int phy_berlin_usb_probe(struct platform_device *pdev) struct phy *phy; struct phy_provider *phy_provider; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mmp3-hsic.c b/drivers/phy/marvell/phy-mmp3-hsic.c index 41bfa542b73e5e..debe95bc068c2f 100644 --- a/drivers/phy/marvell/phy-mmp3-hsic.c +++ b/drivers/phy/marvell/phy-mmp3-hsic.c @@ -48,7 +48,7 @@ static int mmp3_hsic_phy_probe(struct platform_device *pdev) struct phy_provider *provider; struct phy *phy; - mmp3 = devm_kzalloc(dev, sizeof(*mmp3), GFP_KERNEL); + mmp3 = devm_kzalloc_obj(dev, *mmp3); if (!mmp3) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mmp3-usb.c b/drivers/phy/marvell/phy-mmp3-usb.c index 04c0bada351946..57b0d8b344258d 100644 --- a/drivers/phy/marvell/phy-mmp3-usb.c +++ b/drivers/phy/marvell/phy-mmp3-usb.c @@ -249,7 +249,7 @@ static int mmp3_usb_phy_probe(struct platform_device *pdev) struct mmp3_usb_phy *mmp3_usb_phy; struct phy_provider *provider; - mmp3_usb_phy = devm_kzalloc(dev, sizeof(*mmp3_usb_phy), GFP_KERNEL); + mmp3_usb_phy = devm_kzalloc_obj(dev, *mmp3_usb_phy); if (!mmp3_usb_phy) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c index 1d1db1737422a8..dfc7cf7093093c 100644 --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c @@ -1247,7 +1247,7 @@ static int mvebu_a3700_comphy_probe(struct platform_device *pdev) struct clk *clk; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -1320,7 +1320,7 @@ static int mvebu_a3700_comphy_probe(struct platform_device *pdev) continue; } - lane = devm_kzalloc(&pdev->dev, sizeof(*lane), GFP_KERNEL); + lane = devm_kzalloc_obj(&pdev->dev, *lane); if (!lane) { of_node_put(child); return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mvebu-a3700-utmi.c b/drivers/phy/marvell/phy-mvebu-a3700-utmi.c index f882bc57649c77..3a33e9237675d7 100644 --- a/drivers/phy/marvell/phy-mvebu-a3700-utmi.c +++ b/drivers/phy/marvell/phy-mvebu-a3700-utmi.c @@ -216,7 +216,7 @@ static int mvebu_a3700_utmi_phy_probe(struct platform_device *pdev) struct mvebu_a3700_utmi *utmi; struct phy_provider *provider; - utmi = devm_kzalloc(dev, sizeof(*utmi), GFP_KERNEL); + utmi = devm_kzalloc_obj(dev, *utmi); if (!utmi) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mvebu-cp110-comphy.c b/drivers/phy/marvell/phy-mvebu-cp110-comphy.c index 71f9c14fb50ddb..601da58e563d39 100644 --- a/drivers/phy/marvell/phy-mvebu-cp110-comphy.c +++ b/drivers/phy/marvell/phy-mvebu-cp110-comphy.c @@ -1002,7 +1002,7 @@ static int mvebu_comphy_probe(struct platform_device *pdev) struct resource *res; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -1050,7 +1050,7 @@ static int mvebu_comphy_probe(struct platform_device *pdev) continue; } - lane = devm_kzalloc(&pdev->dev, sizeof(*lane), GFP_KERNEL); + lane = devm_kzalloc_obj(&pdev->dev, *lane); if (!lane) { of_node_put(child); ret = -ENOMEM; diff --git a/drivers/phy/marvell/phy-mvebu-cp110-utmi.c b/drivers/phy/marvell/phy-mvebu-cp110-utmi.c index dd3e515a8e8650..5b423282e76030 100644 --- a/drivers/phy/marvell/phy-mvebu-cp110-utmi.c +++ b/drivers/phy/marvell/phy-mvebu-cp110-utmi.c @@ -299,7 +299,7 @@ static int mvebu_cp110_utmi_phy_probe(struct platform_device *pdev) u32 usb_devices = 0; u32 swap_dx = 0; - utmi = devm_kzalloc(dev, sizeof(*utmi), GFP_KERNEL); + utmi = devm_kzalloc_obj(dev, *utmi); if (!utmi) return -ENOMEM; @@ -332,7 +332,7 @@ static int mvebu_cp110_utmi_phy_probe(struct platform_device *pdev) continue; } - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) { of_node_put(child); return -ENOMEM; diff --git a/drivers/phy/marvell/phy-mvebu-sata.c b/drivers/phy/marvell/phy-mvebu-sata.c index 51a4646e293357..aaccbf173ce276 100644 --- a/drivers/phy/marvell/phy-mvebu-sata.c +++ b/drivers/phy/marvell/phy-mvebu-sata.c @@ -83,7 +83,7 @@ static int phy_mvebu_sata_probe(struct platform_device *pdev) struct priv *priv; struct phy *phy; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-pxa-28nm-hsic.c b/drivers/phy/marvell/phy-pxa-28nm-hsic.c index eff6dd6b2dd01d..a5d635659c7b61 100644 --- a/drivers/phy/marvell/phy-pxa-28nm-hsic.c +++ b/drivers/phy/marvell/phy-pxa-28nm-hsic.c @@ -163,7 +163,7 @@ static int mv_hsic_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct mv_hsic_phy *mv_phy; - mv_phy = devm_kzalloc(&pdev->dev, sizeof(*mv_phy), GFP_KERNEL); + mv_phy = devm_kzalloc_obj(&pdev->dev, *mv_phy); if (!mv_phy) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-pxa-28nm-usb2.c b/drivers/phy/marvell/phy-pxa-28nm-usb2.c index 64afb82cf70e5d..b676e879260e5d 100644 --- a/drivers/phy/marvell/phy-pxa-28nm-usb2.c +++ b/drivers/phy/marvell/phy-pxa-28nm-usb2.c @@ -294,7 +294,7 @@ static int mv_usb2_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct mv_usb2_phy *mv_phy; - mv_phy = devm_kzalloc(&pdev->dev, sizeof(*mv_phy), GFP_KERNEL); + mv_phy = devm_kzalloc_obj(&pdev->dev, *mv_phy); if (!mv_phy) return -ENOMEM; diff --git a/drivers/phy/marvell/phy-pxa-usb.c b/drivers/phy/marvell/phy-pxa-usb.c index c0bb71f80c0420..51b88372ec916f 100644 --- a/drivers/phy/marvell/phy-pxa-usb.c +++ b/drivers/phy/marvell/phy-pxa-usb.c @@ -290,7 +290,7 @@ static int pxa_usb_phy_probe(struct platform_device *pdev) struct phy_provider *provider; const struct of_device_id *of_id; - pxa_usb_phy = devm_kzalloc(dev, sizeof(struct pxa_usb_phy), GFP_KERNEL); + pxa_usb_phy = devm_kzalloc_obj(dev, struct pxa_usb_phy); if (!pxa_usb_phy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-dp.c b/drivers/phy/mediatek/phy-mtk-dp.c index dbef4a4bd60a96..0048e1a8c60d82 100644 --- a/drivers/phy/mediatek/phy-mtk-dp.c +++ b/drivers/phy/mediatek/phy-mtk-dp.c @@ -709,7 +709,7 @@ static int mtk_dp_phy_probe(struct platform_device *pdev) struct phy *phy; int ret; - dp_phy = devm_kzalloc(dev, sizeof(*dp_phy), GFP_KERNEL); + dp_phy = devm_kzalloc_obj(dev, *dp_phy); if (!dp_phy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-hdmi.c b/drivers/phy/mediatek/phy-mtk-hdmi.c index 52a7d525ff9b7a..d063fc787c28a4 100644 --- a/drivers/phy/mediatek/phy-mtk-hdmi.c +++ b/drivers/phy/mediatek/phy-mtk-hdmi.c @@ -112,7 +112,7 @@ static int mtk_hdmi_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int ret; - hdmi_phy = devm_kzalloc(dev, sizeof(*hdmi_phy), GFP_KERNEL); + hdmi_phy = devm_kzalloc_obj(dev, *hdmi_phy); if (!hdmi_phy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c index 058e1d9266309b..506cc7c6f000ee 100644 --- a/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c +++ b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c @@ -216,7 +216,7 @@ static int mtk_mipi_cdphy_probe(struct platform_device *pdev) int ret; u32 phy_type; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-mipi-dsi.c b/drivers/phy/mediatek/phy-mtk-mipi-dsi.c index 46f0cb3ac096da..29168a40b7a8f3 100644 --- a/drivers/phy/mediatek/phy-mtk-mipi-dsi.c +++ b/drivers/phy/mediatek/phy-mtk-mipi-dsi.c @@ -117,7 +117,7 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int ret; - mipi_tx = devm_kzalloc(dev, sizeof(*mipi_tx), GFP_KERNEL); + mipi_tx = devm_kzalloc_obj(dev, *mipi_tx); if (!mipi_tx) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-pcie-sphy.c b/drivers/phy/mediatek/phy-mtk-pcie-sphy.c index 2bf10346ea97ac..253a68b19fbecf 100644 --- a/drivers/phy/mediatek/phy-mtk-pcie-sphy.c +++ b/drivers/phy/mediatek/phy-mtk-pcie-sphy.c @@ -494,7 +494,7 @@ static int mtk_pcie_sphy_probe(struct platform_device *pdev) u32 num_lanes; int ret; - pcie_sphy = devm_kzalloc(dev, sizeof(*pcie_sphy), GFP_KERNEL); + pcie_sphy = devm_kzalloc_obj(dev, *pcie_sphy); if (!pcie_sphy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-pcie.c b/drivers/phy/mediatek/phy-mtk-pcie.c index a2f69d6c72f080..a605431459c7ed 100644 --- a/drivers/phy/mediatek/phy-mtk-pcie.c +++ b/drivers/phy/mediatek/phy-mtk-pcie.c @@ -202,7 +202,7 @@ static int mtk_pcie_phy_probe(struct platform_device *pdev) struct mtk_pcie_phy *pcie_phy; int ret; - pcie_phy = devm_kzalloc(dev, sizeof(*pcie_phy), GFP_KERNEL); + pcie_phy = devm_kzalloc_obj(dev, *pcie_phy); if (!pcie_phy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c index acf5065295072c..22273a4df9b25a 100644 --- a/drivers/phy/mediatek/phy-mtk-tphy.c +++ b/drivers/phy/mediatek/phy-mtk-tphy.c @@ -1573,7 +1573,7 @@ static int mtk_tphy_probe(struct platform_device *pdev) struct resource res; int port, ret; - tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL); + tphy = devm_kzalloc_obj(dev, *tphy); if (!tphy) return -ENOMEM; @@ -1582,8 +1582,7 @@ static int mtk_tphy_probe(struct platform_device *pdev) return -EINVAL; tphy->nphys = of_get_child_count(np); - tphy->phys = devm_kcalloc(dev, tphy->nphys, - sizeof(*tphy->phys), GFP_KERNEL); + tphy->phys = devm_kzalloc_objs(dev, *tphy->phys, tphy->nphys); if (!tphy->phys) return -ENOMEM; @@ -1618,7 +1617,7 @@ static int mtk_tphy_probe(struct platform_device *pdev) struct phy *phy; int retval; - instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL); + instance = devm_kzalloc_obj(dev, *instance); if (!instance) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-ufs.c b/drivers/phy/mediatek/phy-mtk-ufs.c index fc19e0fa8ed551..8acd5bb1d916c7 100644 --- a/drivers/phy/mediatek/phy-mtk-ufs.c +++ b/drivers/phy/mediatek/phy-mtk-ufs.c @@ -154,7 +154,7 @@ static int ufs_mtk_phy_probe(struct platform_device *pdev) struct ufs_mtk_phy *phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-xfi-tphy.c b/drivers/phy/mediatek/phy-mtk-xfi-tphy.c index 100a50d0e8619a..3dbc52eac3cf25 100644 --- a/drivers/phy/mediatek/phy-mtk-xfi-tphy.c +++ b/drivers/phy/mediatek/phy-mtk-xfi-tphy.c @@ -399,7 +399,7 @@ static int mtk_xfi_tphy_probe(struct platform_device *pdev) if (!np) return -ENODEV; - xfi_tphy = devm_kzalloc(&pdev->dev, sizeof(*xfi_tphy), GFP_KERNEL); + xfi_tphy = devm_kzalloc_obj(&pdev->dev, *xfi_tphy); if (!xfi_tphy) return -ENOMEM; diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c b/drivers/phy/mediatek/phy-mtk-xsphy.c index 597186de48c537..4c2db497a8f804 100644 --- a/drivers/phy/mediatek/phy-mtk-xsphy.c +++ b/drivers/phy/mediatek/phy-mtk-xsphy.c @@ -549,7 +549,7 @@ static int mtk_xsphy_probe(struct platform_device *pdev) int port; nphys = of_get_child_count(np); - xsphy = devm_kzalloc(dev, struct_size(xsphy, phys, nphys), GFP_KERNEL); + xsphy = devm_kzalloc_flex(dev, *xsphy, phys, nphys); if (!xsphy) return -ENOMEM; @@ -581,7 +581,7 @@ static int mtk_xsphy_probe(struct platform_device *pdev) struct phy *phy; int retval; - inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL); + inst = devm_kzalloc_obj(dev, *inst); if (!inst) return -ENOMEM; diff --git a/drivers/phy/microchip/lan966x_serdes.c b/drivers/phy/microchip/lan966x_serdes.c index 835e369cdfc5fe..caa43338d3fa1f 100644 --- a/drivers/phy/microchip/lan966x_serdes.c +++ b/drivers/phy/microchip/lan966x_serdes.c @@ -550,7 +550,7 @@ static int serdes_phy_create(struct serdes_ctrl *ctrl, u8 idx, struct phy **phy) if (IS_ERR(*phy)) return PTR_ERR(*phy); - macro = devm_kzalloc(ctrl->dev, sizeof(*macro), GFP_KERNEL); + macro = devm_kzalloc_obj(ctrl->dev, *macro); if (!macro) return -ENOMEM; @@ -572,7 +572,7 @@ static int serdes_probe(struct platform_device *pdev) u32 val; int ret; - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/phy/microchip/sparx5_serdes.c b/drivers/phy/microchip/sparx5_serdes.c index 320cf5b50a8cc3..3e7caa8e64189e 100644 --- a/drivers/phy/microchip/sparx5_serdes.c +++ b/drivers/phy/microchip/sparx5_serdes.c @@ -2441,7 +2441,7 @@ static int sparx5_phy_create(struct sparx5_serdes_private *priv, if (IS_ERR(*phy)) return PTR_ERR(*phy); - macro = devm_kzalloc(priv->dev, sizeof(*macro), GFP_KERNEL); + macro = devm_kzalloc_obj(priv->dev, *macro); if (!macro) return -ENOMEM; @@ -2662,7 +2662,7 @@ static int sparx5_serdes_probe(struct platform_device *pdev) if (!np && !pdev->dev.platform_data) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/motorola/phy-cpcap-usb.c b/drivers/phy/motorola/phy-cpcap-usb.c index 9591672b0511c9..bcf3e1990d08c0 100644 --- a/drivers/phy/motorola/phy-cpcap-usb.c +++ b/drivers/phy/motorola/phy-cpcap-usb.c @@ -613,7 +613,7 @@ static int cpcap_usb_phy_probe(struct platform_device *pdev) struct usb_otg *otg; int error; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; @@ -621,7 +621,7 @@ static int cpcap_usb_phy_probe(struct platform_device *pdev) if (!ddata->reg) return -ENODEV; - otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(&pdev->dev, *otg); if (!otg) return -ENOMEM; diff --git a/drivers/phy/motorola/phy-mapphone-mdm6600.c b/drivers/phy/motorola/phy-mapphone-mdm6600.c index fd0e0cd1c1cfb1..ff364a9901877a 100644 --- a/drivers/phy/motorola/phy-mapphone-mdm6600.c +++ b/drivers/phy/motorola/phy-mapphone-mdm6600.c @@ -557,7 +557,7 @@ static int phy_mdm6600_probe(struct platform_device *pdev) struct phy_mdm6600 *ddata; int error; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/phy/mscc/phy-ocelot-serdes.c b/drivers/phy/mscc/phy-ocelot-serdes.c index 1cd1b5db2ad7cf..36bb5468158a65 100644 --- a/drivers/phy/mscc/phy-ocelot-serdes.c +++ b/drivers/phy/mscc/phy-ocelot-serdes.c @@ -477,7 +477,7 @@ static int serdes_phy_create(struct serdes_ctrl *ctrl, u8 idx, struct phy **phy) if (IS_ERR(*phy)) return PTR_ERR(*phy); - macro = devm_kzalloc(ctrl->dev, sizeof(*macro), GFP_KERNEL); + macro = devm_kzalloc_obj(ctrl->dev, *macro); if (!macro) return -ENOMEM; @@ -498,7 +498,7 @@ static int serdes_probe(struct platform_device *pdev) unsigned int i; int ret; - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/phy/nuvoton/phy-ma35d1-usb2.c b/drivers/phy/nuvoton/phy-ma35d1-usb2.c index 9a459b700ed48c..205cc04cde6cd0 100644 --- a/drivers/phy/nuvoton/phy-ma35d1-usb2.c +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c @@ -93,7 +93,7 @@ static int ma35_usb_phy_probe(struct platform_device *pdev) struct ma35_usb_phy *p_phy; struct phy *phy; - p_phy = devm_kzalloc(&pdev->dev, sizeof(*p_phy), GFP_KERNEL); + p_phy = devm_kzalloc_obj(&pdev->dev, *p_phy); if (!p_phy) return -ENOMEM; diff --git a/drivers/phy/phy-airoha-pcie.c b/drivers/phy/phy-airoha-pcie.c index 56e9ade8a9fd3d..2ad7d386e47b41 100644 --- a/drivers/phy/phy-airoha-pcie.c +++ b/drivers/phy/phy-airoha-pcie.c @@ -1218,7 +1218,7 @@ static int airoha_pcie_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct phy_provider *provider; - pcie_phy = devm_kzalloc(dev, sizeof(*pcie_phy), GFP_KERNEL); + pcie_phy = devm_kzalloc_obj(dev, *pcie_phy); if (!pcie_phy) return -ENOMEM; diff --git a/drivers/phy/phy-can-transceiver.c b/drivers/phy/phy-can-transceiver.c index 9aa30662105f06..923aa560bbd5b2 100644 --- a/drivers/phy/phy-can-transceiver.c +++ b/drivers/phy/phy-can-transceiver.c @@ -140,7 +140,7 @@ static int can_transceiver_phy_probe(struct platform_device *pdev) else num_ch = 1; - priv = devm_kzalloc(dev, struct_size(priv, can_transceiver_phy, num_ch), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, can_transceiver_phy, num_ch); if (!priv) return -ENOMEM; diff --git a/drivers/phy/phy-common-props.c b/drivers/phy/phy-common-props.c index 3e814bcbea8681..c97f0eb5c7b205 100644 --- a/drivers/phy/phy-common-props.c +++ b/drivers/phy/phy-common-props.c @@ -88,7 +88,7 @@ static int fwnode_get_u32_prop_for_name(struct fwnode_handle *fwnode, } /* We implicitly know idx >= 0 here */ - props = kcalloc(n_props, sizeof(*props), GFP_KERNEL); + props = kzalloc_objs(*props, n_props); if (!props) return -ENOMEM; diff --git a/drivers/phy/phy-econet-pcie.c b/drivers/phy/phy-econet-pcie.c index 96be69d1ffeb9e..4855e4b7ed1904 100644 --- a/drivers/phy/phy-econet-pcie.c +++ b/drivers/phy/phy-econet-pcie.c @@ -129,7 +129,7 @@ static int en75_pcie_phy_probe(struct platform_device *pdev) if (!data) return -EINVAL; - ephy = devm_kzalloc(dev, sizeof(*ephy), GFP_KERNEL); + ephy = devm_kzalloc_obj(dev, *ephy); if (!ephy) return -ENOMEM; diff --git a/drivers/phy/phy-eyeq5-eth.c b/drivers/phy/phy-eyeq5-eth.c index d1107bc605c1b2..fae147268f5fef 100644 --- a/drivers/phy/phy-eyeq5-eth.c +++ b/drivers/phy/phy-eyeq5-eth.c @@ -236,7 +236,7 @@ static int eq5_phy_probe(struct auxiliary_device *adev, void __iomem *base; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/phy-google-usb.c b/drivers/phy/phy-google-usb.c index 70d3a3833948e4..2acdb2b0e53448 100644 --- a/drivers/phy/phy-google-usb.c +++ b/drivers/phy/phy-google-usb.c @@ -494,7 +494,7 @@ static int google_usb_phy_parse_clocks(struct google_usb_phy *gphy) struct google_usb_phy_instance *inst = &gphy->insts[id]; inst->num_clks = cfg->num_clks; - inst->clks = devm_kcalloc(dev, inst->num_clks, sizeof(*inst->clks), GFP_KERNEL); + inst->clks = devm_kzalloc_objs(dev, *inst->clks, inst->num_clks); if (!inst->clks) return -ENOMEM; @@ -519,7 +519,7 @@ static int google_usb_phy_parse_resets(struct google_usb_phy *gphy) struct google_usb_phy_instance *inst = &gphy->insts[id]; inst->num_rsts = cfg->num_rsts; - inst->rsts = devm_kcalloc(dev, inst->num_rsts, sizeof(*inst->rsts), GFP_KERNEL); + inst->rsts = devm_kzalloc_objs(dev, *inst->rsts, inst->num_rsts); if (!inst->rsts) return -ENOMEM; @@ -542,7 +542,7 @@ static int google_usb_phy_probe(struct platform_device *pdev) u32 args[1]; int ret; - gphy = devm_kzalloc(dev, sizeof(*gphy), GFP_KERNEL); + gphy = devm_kzalloc_obj(dev, *gphy); if (!gphy) return -ENOMEM; @@ -576,7 +576,7 @@ static int google_usb_phy_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(gphy->usb3_tca_base), "invalid usb3 tca\n"); - gphy->insts = devm_kcalloc(dev, GOOGLE_USB_PHY_NUM, sizeof(*gphy->insts), GFP_KERNEL); + gphy->insts = devm_kzalloc_objs(dev, *gphy->insts, GOOGLE_USB_PHY_NUM); if (!gphy->insts) return -ENOMEM; diff --git a/drivers/phy/phy-lgm-usb.c b/drivers/phy/phy-lgm-usb.c index eb7c6fed20d34e..0bbbb42328648c 100644 --- a/drivers/phy/phy-lgm-usb.c +++ b/drivers/phy/phy-lgm-usb.c @@ -192,7 +192,7 @@ static int phy_probe(struct platform_device *pdev) struct tca_apb *ta; int i; - ta = devm_kzalloc(dev, sizeof(*ta), GFP_KERNEL); + ta = devm_kzalloc_obj(dev, *ta); if (!ta) return -ENOMEM; diff --git a/drivers/phy/phy-lpc18xx-usb-otg.c b/drivers/phy/phy-lpc18xx-usb-otg.c index f905d3c6458424..360b49ad962a03 100644 --- a/drivers/phy/phy-lpc18xx-usb-otg.c +++ b/drivers/phy/phy-lpc18xx-usb-otg.c @@ -95,7 +95,7 @@ static int lpc18xx_usb_otg_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct lpc18xx_usb_otg_phy *lpc; - lpc = devm_kzalloc(&pdev->dev, sizeof(*lpc), GFP_KERNEL); + lpc = devm_kzalloc_obj(&pdev->dev, *lpc); if (!lpc) return -ENOMEM; diff --git a/drivers/phy/phy-nxp-ptn3222.c b/drivers/phy/phy-nxp-ptn3222.c index 6cb79b5c4fdb81..b4ed99d957e87b 100644 --- a/drivers/phy/phy-nxp-ptn3222.c +++ b/drivers/phy/phy-nxp-ptn3222.c @@ -66,7 +66,7 @@ static int ptn3222_probe(struct i2c_client *client) struct ptn3222 *ptn3222; int ret; - ptn3222 = devm_kzalloc(dev, sizeof(*ptn3222), GFP_KERNEL); + ptn3222 = devm_kzalloc_obj(dev, *ptn3222); if (!ptn3222) return -ENOMEM; diff --git a/drivers/phy/phy-pistachio-usb.c b/drivers/phy/phy-pistachio-usb.c index 231792f48cede9..e0884708317ecd 100644 --- a/drivers/phy/phy-pistachio-usb.c +++ b/drivers/phy/phy-pistachio-usb.c @@ -136,7 +136,7 @@ static int pistachio_usb_phy_probe(struct platform_device *pdev) struct phy *phy; int ret; - p_phy = devm_kzalloc(&pdev->dev, sizeof(*p_phy), GFP_KERNEL); + p_phy = devm_kzalloc_obj(&pdev->dev, *p_phy); if (!p_phy) return -ENOMEM; p_phy->dev = &pdev->dev; diff --git a/drivers/phy/phy-snps-eusb2.c b/drivers/phy/phy-snps-eusb2.c index af4fa17ac6cbcb..ee473b32f116d8 100644 --- a/drivers/phy/phy-snps-eusb2.c +++ b/drivers/phy/phy-snps-eusb2.c @@ -533,7 +533,7 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev) int ret, i; int num; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; @@ -549,8 +549,7 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev) if (IS_ERR(phy->phy_reset)) return PTR_ERR(phy->phy_reset); - phy->clks = devm_kcalloc(dev, phy->data->num_clks, sizeof(*phy->clks), - GFP_KERNEL); + phy->clks = devm_kzalloc_objs(dev, *phy->clks, phy->data->num_clks); if (!phy->clks) return -ENOMEM; diff --git a/drivers/phy/phy-xgene.c b/drivers/phy/phy-xgene.c index 59f18e16bbbb61..615e9fca97a2a6 100644 --- a/drivers/phy/phy-xgene.c +++ b/drivers/phy/phy-xgene.c @@ -1656,7 +1656,7 @@ static int xgene_phy_probe(struct platform_device *pdev) u32 default_txcp1[] = DEFAULT_SATA_TXCP1; int i; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-ath79-usb.c b/drivers/phy/qualcomm/phy-ath79-usb.c index 09a77e556ecebf..ec8d061d54ff55 100644 --- a/drivers/phy/qualcomm/phy-ath79-usb.c +++ b/drivers/phy/qualcomm/phy-ath79-usb.c @@ -65,7 +65,7 @@ static int ath79_usb_phy_probe(struct platform_device *pdev) struct ath79_usb_phy *priv; struct phy *phy; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-apq8064-sata.c b/drivers/phy/qualcomm/phy-qcom-apq8064-sata.c index cae290a6e19fcb..6db7054da01b2f 100644 --- a/drivers/phy/qualcomm/phy-qcom-apq8064-sata.c +++ b/drivers/phy/qualcomm/phy-qcom-apq8064-sata.c @@ -205,7 +205,7 @@ static int qcom_apq8064_sata_phy_probe(struct platform_device *pdev) struct phy *generic_phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-edp.c b/drivers/phy/qualcomm/phy-qcom-edp.c index a3c893f72908f4..5e773843d6e62a 100644 --- a/drivers/phy/qualcomm/phy-qcom-edp.c +++ b/drivers/phy/qualcomm/phy-qcom-edp.c @@ -1385,7 +1385,7 @@ static int qcom_edp_clks_register(struct qcom_edp *edp, struct device_node *np) char name[64]; int ret; - data = devm_kzalloc(edp->dev, struct_size(data, hws, 2), GFP_KERNEL); + data = devm_kzalloc_flex(edp->dev, *data, hws, 2); if (!data) return -ENOMEM; data->num = 2; @@ -1419,7 +1419,7 @@ static int qcom_edp_phy_probe(struct platform_device *pdev) struct qcom_edp *edp; int ret; - edp = devm_kzalloc(dev, sizeof(*edp), GFP_KERNEL); + edp = devm_kzalloc_obj(dev, *edp); if (!edp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c index 89bc1c89fc85e7..ae00854738860c 100644 --- a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c @@ -128,7 +128,7 @@ static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr) struct device *dev = rptr->dev; int i; - rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL); + rptr->vregs = devm_kzalloc_objs(dev, *rptr->vregs, num); if (!rptr->vregs) return -ENOMEM; @@ -254,7 +254,7 @@ static int eusb2_repeater_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL); + rptr = devm_kzalloc_obj(dev, *rptr); if (!rptr) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c b/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c index da6f290af72212..13ccad70e77a94 100644 --- a/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c +++ b/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c @@ -97,7 +97,7 @@ static int ipq4019_usb_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct ipq4019_usb_phy *phy; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-ipq806x-sata.c b/drivers/phy/qualcomm/phy-qcom-ipq806x-sata.c index f5eb0bdac418bb..2bf1c6491b140e 100644 --- a/drivers/phy/qualcomm/phy-qcom-ipq806x-sata.c +++ b/drivers/phy/qualcomm/phy-qcom-ipq806x-sata.c @@ -132,7 +132,7 @@ static int qcom_ipq806x_sata_phy_probe(struct platform_device *pdev) struct phy *generic_phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c b/drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c index f22c0000479f69..c7e726d00edcee 100644 --- a/drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c +++ b/drivers/phy/qualcomm/phy-qcom-ipq806x-usb.c @@ -487,7 +487,7 @@ static int qcom_ipq806x_usb_phy_probe(struct platform_device *pdev) const struct phy_drvdata *data; struct phy_provider *phy_provider; - phy_dwc3 = devm_kzalloc(&pdev->dev, sizeof(*phy_dwc3), GFP_KERNEL); + phy_dwc3 = devm_kzalloc_obj(&pdev->dev, *phy_dwc3); if (!phy_dwc3) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-m31-eusb2.c b/drivers/phy/qualcomm/phy-qcom-m31-eusb2.c index 275df38256de38..d0cdd80ae1ada7 100644 --- a/drivers/phy/qualcomm/phy-qcom-m31-eusb2.c +++ b/drivers/phy/qualcomm/phy-qcom-m31-eusb2.c @@ -250,7 +250,7 @@ static int m31eusb2_phy_probe(struct platform_device *pdev) struct m31eusb2_phy *phy; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-m31.c b/drivers/phy/qualcomm/phy-qcom-m31.c index 168ea980fda03d..8287ce8b659ebd 100644 --- a/drivers/phy/qualcomm/phy-qcom-m31.c +++ b/drivers/phy/qualcomm/phy-qcom-m31.c @@ -276,7 +276,7 @@ static int m31usb_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct m31usb_phy *qphy; - qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); + qphy = devm_kzalloc_obj(dev, *qphy); if (!qphy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c index c0a4fa20eaf0c8..e04bde03e278c2 100644 --- a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c +++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c @@ -350,7 +350,7 @@ static int phy_qcom_mipi_csi2_probe(struct platform_device *pdev) struct phy *generic_phy; int ret; - csi2phy = devm_kzalloc(dev, sizeof(*csi2phy), GFP_KERNEL); + csi2phy = devm_kzalloc_obj(dev, *csi2phy); if (!csi2phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-pcie2.c b/drivers/phy/qualcomm/phy-qcom-pcie2.c index 11a2bb9586816e..2fb80453d4fc7d 100644 --- a/drivers/phy/qualcomm/phy-qcom-pcie2.c +++ b/drivers/phy/qualcomm/phy-qcom-pcie2.c @@ -233,7 +233,7 @@ static int phy_pipe_clksrc_register(struct qcom_phy *qphy) return ret; } - fixed = devm_kzalloc(qphy->dev, sizeof(*fixed), GFP_KERNEL); + fixed = devm_kzalloc_obj(qphy->dev, *fixed); if (!fixed) return -ENOMEM; @@ -258,7 +258,7 @@ static int qcom_pcie2_phy_probe(struct platform_device *pdev) struct phy *phy; int ret; - qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); + qphy = devm_kzalloc_obj(dev, *qphy); if (!qphy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c index 187f0cd11f6c3f..61d8b7a5ce8f91 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c @@ -4770,8 +4770,7 @@ static int qmp_combo_reset_init(struct qmp_combo *qmp) int i; int ret; - qmp->resets = devm_kcalloc(dev, cfg->num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, cfg->num_resets); if (!qmp->resets) return -ENOMEM; @@ -4791,7 +4790,7 @@ static int qmp_combo_clk_init(struct qmp_combo *qmp) int num = ARRAY_SIZE(qmp_combo_phy_clk_l); int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -5507,7 +5506,7 @@ static int qmp_combo_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c index ed22b7a256efaf..f07872673dcb52 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c @@ -508,7 +508,7 @@ static int qmp_pcie_msm8996_vreg_init(struct device *dev, const struct qmp_phy_c int num = cfg->num_vregs; int i; - qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); + qmp->vregs = devm_kzalloc_objs(dev, *qmp->vregs, num); if (!qmp->vregs) return -ENOMEM; @@ -524,8 +524,7 @@ static int qmp_pcie_msm8996_reset_init(struct device *dev, const struct qmp_phy_ int i; int ret; - qmp->resets = devm_kcalloc(dev, cfg->num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, cfg->num_resets); if (!qmp->resets) return -ENOMEM; @@ -545,7 +544,7 @@ static int qmp_pcie_msm8996_clk_init(struct device *dev, const struct qmp_phy_cf int num = cfg->num_clks; int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -590,7 +589,7 @@ static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np) return ret; } - fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL); + fixed = devm_kzalloc_obj(qmp->dev, *fixed); if (!fixed) return -ENOMEM; @@ -634,7 +633,7 @@ static int qmp_pcie_msm8996_create(struct device *dev, struct device_node *np, i struct qmp_phy *qphy; int ret; - qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); + qphy = devm_kzalloc_obj(dev, *qphy); if (!qphy) return -ENOMEM; @@ -707,7 +706,7 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev) int num, id, expected_phys; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; @@ -743,7 +742,7 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev) if (num > expected_phys) return -EINVAL; - qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL); + qmp->phys = devm_kzalloc_objs(dev, *qmp->phys, num); if (!qmp->phys) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-multiphy.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-multiphy.c index 3d225c0bb80e29..ccdb7748a9e1c8 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-multiphy.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-multiphy.c @@ -1205,8 +1205,7 @@ static int qmp_pcie_pd_init(struct qmp_pcie *qmp, struct phy *phy) if (!cfg->num_pds) return 0; - qmp->pd_devs = devm_kcalloc(pd_dev, cfg->num_pds, sizeof(*qmp->pd_devs), - GFP_KERNEL); + qmp->pd_devs = devm_kzalloc_objs(pd_dev, *qmp->pd_devs, cfg->num_pds); if (!qmp->pd_devs) return -ENOMEM; @@ -1229,8 +1228,7 @@ static int qmp_pcie_vreg_init(struct qmp_pcie *qmp) struct device *dev = qmp->dev; int i; - qmp->vregs = devm_kcalloc(dev, cfg->num_vregs, sizeof(*qmp->vregs), - GFP_KERNEL); + qmp->vregs = devm_kzalloc_objs(dev, *qmp->vregs, cfg->num_vregs); if (!qmp->vregs) return -ENOMEM; @@ -1247,8 +1245,8 @@ static int qmp_pcie_reset_init(struct qmp_pcie *qmp) int i, ret; if (cfg->num_resets) { - qmp->resets = devm_kcalloc(dev, cfg->num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, + cfg->num_resets); if (!qmp->resets) return -ENOMEM; @@ -1262,9 +1260,8 @@ static int qmp_pcie_reset_init(struct qmp_pcie *qmp) } if (cfg->num_nocsr_resets) { - qmp->nocsr_resets = devm_kcalloc(dev, cfg->num_nocsr_resets, - sizeof(*qmp->nocsr_resets), - GFP_KERNEL); + qmp->nocsr_resets = devm_kzalloc_objs(dev, *qmp->nocsr_resets, + cfg->num_nocsr_resets); if (!qmp->nocsr_resets) return -ENOMEM; @@ -1287,8 +1284,7 @@ static int qmp_pcie_clk_init(struct qmp_pcie *qmp) struct device *dev = qmp->dev; int i, ret; - qmp->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(*qmp->clks), - GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, cfg->num_clks); if (!qmp->clks) return -ENOMEM; @@ -1299,8 +1295,8 @@ static int qmp_pcie_clk_init(struct qmp_pcie *qmp) if (ret) return ret; - qmp->pipe_clks = devm_kcalloc(dev, cfg->num_pipe_clks, - sizeof(*qmp->pipe_clks), GFP_KERNEL); + qmp->pipe_clks = devm_kzalloc_objs(dev, *qmp->pipe_clks, + cfg->num_pipe_clks); if (!qmp->pipe_clks) return -ENOMEM; @@ -1361,9 +1357,9 @@ static int qmp_pcie_multiphy_register_clocks(struct device *dev, "failed to read clock-output-names\n"); qmp_data->num_pipe_outputs = num_pipe_outputs; - qmp_data->pipe_out_clks = devm_kcalloc(dev, num_pipe_outputs, - sizeof(*qmp_data->pipe_out_clks), - GFP_KERNEL); + qmp_data->pipe_out_clks = devm_kzalloc_objs(dev, + *qmp_data->pipe_out_clks, + num_pipe_outputs); if (!qmp_data->pipe_out_clks) return -ENOMEM; @@ -1385,8 +1381,7 @@ static int qmp_pcie_get_mmio(struct qmp_pcie *qmp) void __iomem *base; int i; - qmp->base = devm_kcalloc(dev, cfg->num_regs, sizeof(*qmp->base), - GFP_KERNEL); + qmp->base = devm_kzalloc_objs(dev, *qmp->base, cfg->num_regs); if (!qmp->base) return -ENOMEM; @@ -1479,7 +1474,7 @@ static int qmp_pcie_multiphy_probe(struct platform_device *pdev) int phy_index; int ret; - qmp_data = devm_kzalloc(dev, sizeof(*qmp_data), GFP_KERNEL); + qmp_data = devm_kzalloc_obj(dev, *qmp_data); if (!qmp_data) return -ENOMEM; @@ -1497,11 +1492,11 @@ static int qmp_pcie_multiphy_probe(struct platform_device *pdev) qmp_data->mode_cfg = &match_data->mode_cfgs[link_mode]; - qmp = devm_kcalloc(dev, qmp_data->mode_cfg->num_phys, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_objs(dev, *qmp, qmp_data->mode_cfg->num_phys); if (!qmp) return -ENOMEM; - phys = devm_kcalloc(dev, qmp_data->mode_cfg->num_phys, sizeof(*phys), GFP_KERNEL); + phys = devm_kzalloc_objs(dev, *phys, qmp_data->mode_cfg->num_phys); if (!phys) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c index 9cfabf474fd63f..b9fe3ce942270c 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c @@ -5969,7 +5969,7 @@ static int qmp_pcie_vreg_init(struct qmp_pcie *qmp) int num = cfg->num_vregs; int i; - qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); + qmp->vregs = devm_kzalloc_objs(dev, *qmp->vregs, num); if (!qmp->vregs) return -ENOMEM; @@ -5986,8 +5986,7 @@ static int qmp_pcie_reset_init(struct qmp_pcie *qmp) int i; int ret; - qmp->resets = devm_kcalloc(dev, cfg->num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, cfg->num_resets); if (!qmp->resets) return -ENOMEM; @@ -6012,7 +6011,7 @@ static int qmp_pcie_clk_init(struct qmp_pcie *qmp) int num = ARRAY_SIZE(qmp_pciephy_clk_l); int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -6332,7 +6331,7 @@ static int qmp_pcie_probe(struct platform_device *pdev) struct qmp_pcie *qmp; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-ufs.c b/drivers/phy/qualcomm/phy-qcom-qmp-ufs.c index d15db9ab9a90c3..9693797927943d 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-ufs.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-ufs.c @@ -2192,9 +2192,8 @@ static int qmp_ufs_register_clocks(struct qmp_ufs *qmp, struct device_node *np) char name[64]; int ret; - clk_data = devm_kzalloc(qmp->dev, - struct_size(clk_data, hws, UFS_SYMBOL_CLOCKS), - GFP_KERNEL); + clk_data = devm_kzalloc_flex(qmp->dev, *clk_data, hws, + UFS_SYMBOL_CLOCKS); if (!clk_data) return -ENOMEM; @@ -2314,7 +2313,7 @@ static int qmp_ufs_probe(struct platform_device *pdev) struct qmp_ufs *qmp; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c b/drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c index c5160cb8920795..b2271a68ff821f 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c @@ -1050,7 +1050,7 @@ static int qmp_usb_legacy_vreg_init(struct qmp_usb *qmp) int num = cfg->num_vregs; int i; - qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL); + qmp->vregs = devm_kzalloc_objs(dev, *qmp->vregs, num); if (!qmp->vregs) return -ENOMEM; @@ -1067,8 +1067,7 @@ static int qmp_usb_legacy_reset_init(struct qmp_usb *qmp) int i; int ret; - qmp->resets = devm_kcalloc(dev, cfg->num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, cfg->num_resets); if (!qmp->resets) return -ENOMEM; @@ -1089,7 +1088,7 @@ static int qmp_usb_legacy_clk_init(struct qmp_usb *qmp) int num = cfg->num_clks; int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -1251,7 +1250,7 @@ static int qmp_usb_legacy_probe(struct platform_device *pdev) struct qmp_usb *qmp; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usb.c b/drivers/phy/qualcomm/phy-qcom-qmp-usb.c index 6a9faa0ce3bb41..6348bb68d8225f 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-usb.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usb.c @@ -2139,8 +2139,7 @@ static int qmp_usb_reset_init(struct qmp_usb *qmp, int i; int ret; - qmp->resets = devm_kcalloc(dev, num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, num_resets); if (!qmp->resets) return -ENOMEM; @@ -2162,7 +2161,7 @@ static int qmp_usb_clk_init(struct qmp_usb *qmp) int num = ARRAY_SIZE(qmp_usb_phy_clk_l); int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -2368,7 +2367,7 @@ static int qmp_usb_probe(struct platform_device *pdev) struct qmp_usb *qmp; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c index 548ec97373ac3a..509e683740ab9c 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c @@ -1439,8 +1439,7 @@ static int qmp_usbc_reset_init(struct qmp_usbc *qmp, int i; int ret; - qmp->resets = devm_kcalloc(dev, num_resets, - sizeof(*qmp->resets), GFP_KERNEL); + qmp->resets = devm_kzalloc_objs(dev, *qmp->resets, num_resets); if (!qmp->resets) return -ENOMEM; @@ -1462,7 +1461,7 @@ static int qmp_usbc_clk_init(struct qmp_usbc *qmp) int num = ARRAY_SIZE(qmp_usbc_phy_clk_l); int i; - qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL); + qmp->clks = devm_kzalloc_objs(dev, *qmp->clks, num); if (!qmp->clks) return -ENOMEM; @@ -1940,7 +1939,7 @@ static int qmp_usbc_probe(struct platform_device *pdev) struct qmp_usbc *qmp; int ret; - qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c index 2e5fdb620cb2dc..fa1c2f2c6053ac 100644 --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c @@ -1009,7 +1009,7 @@ static int qusb2_phy_probe(struct platform_device *pdev) u32 value; struct override_params *or; - qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); + qphy = devm_kzalloc_obj(dev, *qphy); if (!qphy) return -ENOMEM; or = &qphy->overrides; diff --git a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c index 7137200c3f310a..04fc3e80b49638 100644 --- a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c +++ b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c @@ -381,7 +381,7 @@ static int qcom_dwmac_sgmii_phy_probe(struct platform_device *pdev) struct phy *phy; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c index 980ad1fb1e2e3c..75e21865b2c8de 100644 --- a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +++ b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c @@ -143,7 +143,7 @@ static int qcom_snps_hsphy_clk_init(struct qcom_snps_hsphy *hsphy) struct device *dev = hsphy->dev; hsphy->num_clks = 2; - hsphy->clks = devm_kcalloc(dev, hsphy->num_clks, sizeof(*hsphy->clks), GFP_KERNEL); + hsphy->clks = devm_kzalloc_objs(dev, *hsphy->clks, hsphy->num_clks); if (!hsphy->clks) return -ENOMEM; @@ -570,7 +570,7 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev) int ret, i; int num; - hsphy = devm_kzalloc(dev, sizeof(*hsphy), GFP_KERNEL); + hsphy = devm_kzalloc_obj(dev, *hsphy); if (!hsphy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c b/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c index 324c0a5d658e43..ef8709ff0e16b0 100644 --- a/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c +++ b/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c @@ -279,7 +279,7 @@ static int qcom_uniphy_pcie_probe(struct platform_device *pdev) struct phy *generic_phy; int ret; - phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&pdev->dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hs-28nm.c b/drivers/phy/qualcomm/phy-qcom-usb-hs-28nm.c index a52a9bf13b758d..febdce27226aaf 100644 --- a/drivers/phy/qualcomm/phy-qcom-usb-hs-28nm.c +++ b/drivers/phy/qualcomm/phy-qcom-usb-hs-28nm.c @@ -312,7 +312,7 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev) int ret; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -321,8 +321,7 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev) return PTR_ERR(priv->base); priv->num_clks = ARRAY_SIZE(qcom_snps_hsphy_clks); - priv->clks = devm_kcalloc(dev, priv->num_clks, sizeof(*priv->clks), - GFP_KERNEL); + priv->clks = devm_kzalloc_objs(dev, *priv->clks, priv->num_clks); if (!priv->clks) return -ENOMEM; diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hs.c b/drivers/phy/qualcomm/phy-qcom-usb-hs.c index 928a982a8a76c5..d7f6456c0505a5 100644 --- a/drivers/phy/qualcomm/phy-qcom-usb-hs.c +++ b/drivers/phy/qualcomm/phy-qcom-usb-hs.c @@ -213,7 +213,7 @@ static int qcom_usb_hs_phy_probe(struct ulpi *ulpi) if (size < 0) size = 0; - uphy = devm_kzalloc(&ulpi->dev, struct_size(uphy, init_seq, (size / 2) + 1), GFP_KERNEL); + uphy = devm_kzalloc_flex(&ulpi->dev, *uphy, init_seq, (size / 2) + 1); if (!uphy) return -ENOMEM; ulpi_set_drvdata(ulpi, uphy); diff --git a/drivers/phy/qualcomm/phy-qcom-usb-hsic.c b/drivers/phy/qualcomm/phy-qcom-usb-hsic.c index 20f6dd37c7c106..492559c5aa0156 100644 --- a/drivers/phy/qualcomm/phy-qcom-usb-hsic.c +++ b/drivers/phy/qualcomm/phy-qcom-usb-hsic.c @@ -107,7 +107,7 @@ static int qcom_usb_hsic_phy_probe(struct ulpi *ulpi) struct phy_provider *p; struct clk *clk; - uphy = devm_kzalloc(&ulpi->dev, sizeof(*uphy), GFP_KERNEL); + uphy = devm_kzalloc_obj(&ulpi->dev, *uphy); if (!uphy) return -ENOMEM; ulpi_set_drvdata(ulpi, uphy); diff --git a/drivers/phy/qualcomm/phy-qcom-usb-ss.c b/drivers/phy/qualcomm/phy-qcom-usb-ss.c index a3a6d3ce7ea1c4..3afb689b3d159f 100644 --- a/drivers/phy/qualcomm/phy-qcom-usb-ss.c +++ b/drivers/phy/qualcomm/phy-qcom-usb-ss.c @@ -191,7 +191,7 @@ static int qcom_ssphy_probe(struct platform_device *pdev) struct phy *phy; int ret; - priv = devm_kzalloc(dev, sizeof(struct ssphy_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct ssphy_priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/ralink/phy-mt7621-pci.c b/drivers/phy/ralink/phy-mt7621-pci.c index a591ad95347ccf..40314742c1e6c1 100644 --- a/drivers/phy/ralink/phy-mt7621-pci.c +++ b/drivers/phy/ralink/phy-mt7621-pci.c @@ -297,7 +297,7 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev) struct phy_provider *provider; struct mt7621_pci_phy *phy; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/ralink/phy-ralink-usb.c b/drivers/phy/ralink/phy-ralink-usb.c index 0ff07e210769ee..e2da6b78bc7055 100644 --- a/drivers/phy/ralink/phy-ralink-usb.c +++ b/drivers/phy/ralink/phy-ralink-usb.c @@ -173,7 +173,7 @@ static int ralink_usb_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct ralink_usb_phy *phy; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/realtek/phy-rtk-usb2.c b/drivers/phy/realtek/phy-rtk-usb2.c index 1f08b151d90a66..9a23a3eb8babd1 100644 --- a/drivers/phy/realtek/phy-rtk-usb2.c +++ b/drivers/phy/realtek/phy-rtk-usb2.c @@ -1017,13 +1017,12 @@ static int rtk_usb2phy_probe(struct platform_device *pdev) return -EINVAL; } - rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); + rtk_phy = devm_kzalloc_obj(dev, *rtk_phy); if (!rtk_phy) return -ENOMEM; rtk_phy->dev = &pdev->dev; - rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*rtk_phy->phy_cfg), - GFP_KERNEL); + rtk_phy->phy_cfg = devm_kzalloc_obj(dev, *rtk_phy->phy_cfg); if (!rtk_phy->phy_cfg) return -ENOMEM; diff --git a/drivers/phy/realtek/phy-rtk-usb3.c b/drivers/phy/realtek/phy-rtk-usb3.c index 4231a8aa0ba5d7..63d42ab0b98490 100644 --- a/drivers/phy/realtek/phy-rtk-usb3.c +++ b/drivers/phy/realtek/phy-rtk-usb3.c @@ -571,13 +571,12 @@ static int rtk_usb3phy_probe(struct platform_device *pdev) return -EINVAL; } - rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); + rtk_phy = devm_kzalloc_obj(dev, *rtk_phy); if (!rtk_phy) return -ENOMEM; rtk_phy->dev = &pdev->dev; - rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*rtk_phy->phy_cfg), - GFP_KERNEL); + rtk_phy->phy_cfg = devm_kzalloc_obj(dev, *rtk_phy->phy_cfg); if (!rtk_phy->phy_cfg) return -ENOMEM; diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/phy-rcar-gen2.c index 5a272e25e051c2..414c6814ef9950 100644 --- a/drivers/phy/renesas/phy-rcar-gen2.c +++ b/drivers/phy/renesas/phy-rcar-gen2.c @@ -358,7 +358,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; @@ -372,9 +372,8 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) return -EINVAL; drv->num_channels = of_get_child_count(dev->of_node); - drv->channels = devm_kcalloc(dev, drv->num_channels, - sizeof(struct rcar_gen2_channel), - GFP_KERNEL); + drv->channels = devm_kzalloc_objs(dev, struct rcar_gen2_channel, + drv->num_channels); if (!drv->channels) return -ENOMEM; diff --git a/drivers/phy/renesas/phy-rcar-gen3-pcie.c b/drivers/phy/renesas/phy-rcar-gen3-pcie.c index c0e5a4ac82de2c..9072174ac804bc 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-pcie.c +++ b/drivers/phy/renesas/phy-rcar-gen3-pcie.c @@ -88,7 +88,7 @@ static int rcar_gen3_phy_pcie_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index b5ba751805aae9..ac3dc8b6e1ea1b 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -1184,7 +1184,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) return -EINVAL; } - channel = devm_kzalloc(dev, sizeof(*channel), GFP_KERNEL); + channel = devm_kzalloc_obj(dev, *channel); if (!channel) return -ENOMEM; diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb3.c b/drivers/phy/renesas/phy-rcar-gen3-usb3.c index 0420f5b283ce42..58f1a48b9d5c30 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb3.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb3.c @@ -141,7 +141,7 @@ static int rcar_gen3_phy_usb3_probe(struct platform_device *pdev) return -EINVAL; } - r = devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); + r = devm_kzalloc_obj(dev, *r); if (!r) return -ENOMEM; diff --git a/drivers/phy/renesas/phy-rzg3e-usb3.c b/drivers/phy/renesas/phy-rzg3e-usb3.c index 060309547ea527..57aa449edb8cd0 100644 --- a/drivers/phy/renesas/phy-rzg3e-usb3.c +++ b/drivers/phy/renesas/phy-rzg3e-usb3.c @@ -159,7 +159,7 @@ static int rzg3e_phy_usb3_probe(struct platform_device *pdev) struct phy *phy; int ret; - r = devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); + r = devm_kzalloc_obj(dev, *r); if (!r) return -ENOMEM; diff --git a/drivers/phy/renesas/r8a779f0-ether-serdes.c b/drivers/phy/renesas/r8a779f0-ether-serdes.c index 8a6b6f366fe376..721d8ae527ca3a 100644 --- a/drivers/phy/renesas/r8a779f0-ether-serdes.c +++ b/drivers/phy/renesas/r8a779f0-ether-serdes.c @@ -429,7 +429,7 @@ static int r8a779f0_eth_serdes_probe(struct platform_device *pdev) struct phy_provider *provider; int i; - dd = devm_kzalloc(&pdev->dev, sizeof(*dd), GFP_KERNEL); + dd = devm_kzalloc_obj(&pdev->dev, *dd); if (!dd) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-dp.c b/drivers/phy/rockchip/phy-rockchip-dp.c index 592aa956eead82..07c86c2e8a07db 100644 --- a/drivers/phy/rockchip/phy-rockchip-dp.c +++ b/drivers/phy/rockchip/phy-rockchip-dp.c @@ -86,7 +86,7 @@ static int rockchip_dp_phy_probe(struct platform_device *pdev) if (!dev->parent || !dev->parent->of_node) return -ENODEV; - dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(dev, *dp); if (!dp) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-dphy-rx0.c b/drivers/phy/rockchip/phy-rockchip-dphy-rx0.c index e6a768bbb9b316..70b145394a882c 100644 --- a/drivers/phy/rockchip/phy-rockchip-dphy-rx0.c +++ b/drivers/phy/rockchip/phy-rockchip-dphy-rx0.c @@ -334,7 +334,7 @@ static int rk_dphy_probe(struct platform_device *pdev) if (!dev->parent || !dev->parent->of_node) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; @@ -347,8 +347,8 @@ static int rk_dphy_probe(struct platform_device *pdev) drv_data = of_device_get_match_data(dev); priv->drv_data = drv_data; - priv->clks = devm_kcalloc(&pdev->dev, drv_data->num_clks, - sizeof(*priv->clks), GFP_KERNEL); + priv->clks = devm_kzalloc_objs(&pdev->dev, *priv->clks, + drv_data->num_clks); if (!priv->clks) return -ENOMEM; for (i = 0; i < drv_data->num_clks; i++) diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c b/drivers/phy/rockchip/phy-rockchip-emmc.c index 5187983c58e5e9..996ec1ef1ccf2a 100644 --- a/drivers/phy/rockchip/phy-rockchip-emmc.c +++ b/drivers/phy/rockchip/phy-rockchip-emmc.c @@ -364,7 +364,7 @@ static int rockchip_emmc_phy_probe(struct platform_device *pdev) return PTR_ERR(grf); } - rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL); + rk_phy = devm_kzalloc_obj(dev, *rk_phy); if (!rk_phy) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-inno-csidphy.c b/drivers/phy/rockchip/phy-rockchip-inno-csidphy.c index b4f64ebfbcf722..1d4e15750278fc 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-csidphy.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-csidphy.c @@ -479,7 +479,7 @@ static int rockchip_inno_csidphy_probe(struct platform_device *pdev) u32 phase; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-inno-dsidphy.c b/drivers/phy/rockchip/phy-rockchip-inno-dsidphy.c index 30d5e5ddff4a14..6ad04b0c9f8c08 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-dsidphy.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-dsidphy.c @@ -778,7 +778,7 @@ static int inno_dsidphy_probe(struct platform_device *pdev) struct phy *phy; int ret; - inno = devm_kzalloc(dev, sizeof(*inno), GFP_KERNEL); + inno = devm_kzalloc_obj(dev, *inno); if (!inno) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c b/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c index d2c2b17df5f340..f5874cd674e6cc 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-hdmi.c @@ -1355,7 +1355,7 @@ static int inno_hdmi_phy_probe(struct platform_device *pdev) void __iomem *regs; int ret; - inno = devm_kzalloc(&pdev->dev, sizeof(*inno), GFP_KERNEL); + inno = devm_kzalloc_obj(&pdev->dev, *inno); if (!inno) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index e47b89015586fe..848c07ccb5e7d6 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -1356,7 +1356,7 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev) unsigned int reg; int index = 0, ret; - rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL); + rphy = devm_kzalloc_obj(dev, *rphy); if (!rphy) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c b/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c index 3102a99128f62c..51c7c8405244a2 100644 --- a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +++ b/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c @@ -415,7 +415,7 @@ static int rockchip_combphy_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-pcie.c b/drivers/phy/rockchip/phy-rockchip-pcie.c index 126306c014546d..6861556df75b9c 100644 --- a/drivers/phy/rockchip/phy-rockchip-pcie.c +++ b/drivers/phy/rockchip/phy-rockchip-pcie.c @@ -277,7 +277,7 @@ static int rockchip_pcie_phy_probe(struct platform_device *pdev) return PTR_ERR(grf); } - rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL); + rk_phy = devm_kzalloc_obj(dev, *rk_phy); if (!rk_phy) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c b/drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c index 7382043e1f319f..724eff7bea2aca 100644 --- a/drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c +++ b/drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c @@ -1558,7 +1558,7 @@ static int samsung_mipi_dcphy_probe(struct platform_device *pdev) void __iomem *regs; int ret; - samsung = devm_kzalloc(dev, sizeof(*samsung), GFP_KERNEL); + samsung = devm_kzalloc_obj(dev, *samsung); if (!samsung) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c index 6879eecc5a9fda..515646f9cb649f 100644 --- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c +++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c @@ -2506,7 +2506,7 @@ static int rk_hdptx_phy_probe(struct platform_device *pdev) void __iomem *regs; int ret, id; - hdptx = devm_kzalloc(dev, sizeof(*hdptx), GFP_KERNEL); + hdptx = devm_kzalloc_obj(dev, *hdptx); if (!hdptx) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c b/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c index 4e8ffd173096a4..5f517bab1aa425 100644 --- a/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c +++ b/drivers/phy/rockchip/phy-rockchip-snps-pcie3.c @@ -249,7 +249,7 @@ static int rockchip_p3phy_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c index d9701b6106d550..d7934dfe1c5edf 100644 --- a/drivers/phy/rockchip/phy-rockchip-typec.c +++ b/drivers/phy/rockchip/phy-rockchip-typec.c @@ -1106,7 +1106,7 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev) const struct rockchip_usb3phy_port_cfg *phy_cfgs; int index, ret; - tcphy = devm_kzalloc(dev, sizeof(*tcphy), GFP_KERNEL); + tcphy = devm_kzalloc_obj(dev, *tcphy); if (!tcphy) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-usb.c b/drivers/phy/rockchip/phy-rockchip-usb.c index c5a2853a63d309..903130c3a45aa2 100644 --- a/drivers/phy/rockchip/phy-rockchip-usb.c +++ b/drivers/phy/rockchip/phy-rockchip-usb.c @@ -205,7 +205,7 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base, const char *clk_name; int err, i; - rk_phy = devm_kzalloc(base->dev, sizeof(*rk_phy), GFP_KERNEL); + rk_phy = devm_kzalloc_obj(base->dev, *rk_phy); if (!rk_phy) return -ENOMEM; @@ -448,7 +448,7 @@ static int rockchip_usb_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int err; - phy_base = devm_kzalloc(dev, sizeof(*phy_base), GFP_KERNEL); + phy_base = devm_kzalloc_obj(dev, *phy_base); if (!phy_base) return -ENOMEM; diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c index e748acdd2d3139..79072f4664d8bb 100644 --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c @@ -473,8 +473,7 @@ static int rk_udphy_reset_init(struct rk_udphy *udphy, struct device *dev) int idx; udphy->num_rsts = cfg->num_rsts; - udphy->rsts = devm_kcalloc(dev, udphy->num_rsts, - sizeof(*udphy->rsts), GFP_KERNEL); + udphy->rsts = devm_kzalloc_objs(dev, *udphy->rsts, udphy->num_rsts); if (!udphy->rsts) return -ENOMEM; @@ -1412,7 +1411,7 @@ static int rk_udphy_probe(struct platform_device *pdev) void __iomem *base; int id, ret; - udphy = devm_kzalloc(dev, sizeof(*udphy), GFP_KERNEL); + udphy = devm_kzalloc_obj(dev, *udphy); if (!udphy) return -ENOMEM; diff --git a/drivers/phy/samsung/phy-exynos-dp-video.c b/drivers/phy/samsung/phy-exynos-dp-video.c index a636dee075858c..86acf1d27800cd 100644 --- a/drivers/phy/samsung/phy-exynos-dp-video.c +++ b/drivers/phy/samsung/phy-exynos-dp-video.c @@ -77,7 +77,7 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct phy *phy; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/phy/samsung/phy-exynos-mipi-video.c b/drivers/phy/samsung/phy-exynos-mipi-video.c index be925508ed97a3..40f5fc31b784ea 100644 --- a/drivers/phy/samsung/phy-exynos-mipi-video.c +++ b/drivers/phy/samsung/phy-exynos-mipi-video.c @@ -352,7 +352,7 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev) if (!phy_dev) return -ENODEV; - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/phy/samsung/phy-exynos-pcie.c b/drivers/phy/samsung/phy-exynos-pcie.c index 53c9230c290783..b7943aeda87e04 100644 --- a/drivers/phy/samsung/phy-exynos-pcie.c +++ b/drivers/phy/samsung/phy-exynos-pcie.c @@ -147,7 +147,7 @@ static int exynos_pcie_phy_probe(struct platform_device *pdev) struct phy *generic_phy; struct phy_provider *phy_provider; - exynos_phy = devm_kzalloc(dev, sizeof(*exynos_phy), GFP_KERNEL); + exynos_phy = devm_kzalloc_obj(dev, *exynos_phy); if (!exynos_phy) return -ENOMEM; diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c index 087d552eb5119c..5a208a584b3b78 100644 --- a/drivers/phy/samsung/phy-exynos5-usbdrd.c +++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c @@ -1805,8 +1805,8 @@ static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd) struct clk *ref_clk; unsigned long ref_rate; - phy_drd->clks = devm_kcalloc(phy_drd->dev, phy_drd->drv_data->n_clks, - sizeof(*phy_drd->clks), GFP_KERNEL); + phy_drd->clks = devm_kzalloc_objs(phy_drd->dev, *phy_drd->clks, + phy_drd->drv_data->n_clks); if (!phy_drd->clks) return -ENOMEM; @@ -1819,10 +1819,9 @@ static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd) return dev_err_probe(phy_drd->dev, ret, "failed to get phy clock(s)\n"); - phy_drd->core_clks = devm_kcalloc(phy_drd->dev, - phy_drd->drv_data->n_core_clks, - sizeof(*phy_drd->core_clks), - GFP_KERNEL); + phy_drd->core_clks = devm_kzalloc_objs(phy_drd->dev, + *phy_drd->core_clks, + phy_drd->drv_data->n_core_clks); if (!phy_drd->core_clks) return -ENOMEM; @@ -2961,7 +2960,7 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev) int i, ret; int channel; - phy_drd = devm_kzalloc(dev, sizeof(*phy_drd), GFP_KERNEL); + phy_drd = devm_kzalloc_obj(dev, *phy_drd); if (!phy_drd) return -ENOMEM; @@ -3032,10 +3031,8 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev) dev_dbg(dev, "Not a multi-controller usbdrd phy\n"); /* Get regulators */ - phy_drd->regulators = devm_kcalloc(dev, - drv_data->n_regulators, - sizeof(*phy_drd->regulators), - GFP_KERNEL); + phy_drd->regulators = devm_kzalloc_objs(dev, *phy_drd->regulators, + drv_data->n_regulators); if (!phy_drd->regulators) return -ENOMEM; regulator_bulk_set_supply_names(phy_drd->regulators, diff --git a/drivers/phy/samsung/phy-exynos5250-sata.c b/drivers/phy/samsung/phy-exynos5250-sata.c index 595adba5fb8f13..a88534eba2bee5 100644 --- a/drivers/phy/samsung/phy-exynos5250-sata.c +++ b/drivers/phy/samsung/phy-exynos5250-sata.c @@ -166,7 +166,7 @@ static int exynos_sata_phy_probe(struct platform_device *pdev) struct device_node *node; int ret = 0; - sata_phy = devm_kzalloc(dev, sizeof(*sata_phy), GFP_KERNEL); + sata_phy = devm_kzalloc_obj(dev, *sata_phy); if (!sata_phy) return -ENOMEM; diff --git a/drivers/phy/samsung/phy-samsung-ufs.c b/drivers/phy/samsung/phy-samsung-ufs.c index ee665f26c2361f..56c2fa53bf7743 100644 --- a/drivers/phy/samsung/phy-samsung-ufs.c +++ b/drivers/phy/samsung/phy-samsung-ufs.c @@ -150,8 +150,7 @@ static int samsung_ufs_phy_clks_init(struct samsung_ufs_phy *phy) const struct samsung_ufs_phy_drvdata *drvdata = phy->drvdata; int num_clks = drvdata->num_clks; - phy->clks = devm_kcalloc(phy->dev, num_clks, sizeof(*phy->clks), - GFP_KERNEL); + phy->clks = devm_kzalloc_objs(phy->dev, *phy->clks, num_clks); if (!phy->clks) return -ENOMEM; @@ -295,7 +294,7 @@ static int samsung_ufs_phy_probe(struct platform_device *pdev) goto out; } - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) { err = -ENOMEM; goto out; diff --git a/drivers/phy/samsung/phy-samsung-usb2.c b/drivers/phy/samsung/phy-samsung-usb2.c index d2749b67cf8fff..307d33a244322e 100644 --- a/drivers/phy/samsung/phy-samsung-usb2.c +++ b/drivers/phy/samsung/phy-samsung-usb2.c @@ -157,8 +157,7 @@ static int samsung_usb2_phy_probe(struct platform_device *pdev) if (!cfg) return -EINVAL; - drv = devm_kzalloc(dev, struct_size(drv, instances, cfg->num_phys), - GFP_KERNEL); + drv = devm_kzalloc_flex(dev, *drv, instances, cfg->num_phys); if (!drv) return -ENOMEM; diff --git a/drivers/phy/socionext/phy-uniphier-ahci.c b/drivers/phy/socionext/phy-uniphier-ahci.c index 28cf3efe06956d..213eb581dad3e1 100644 --- a/drivers/phy/socionext/phy-uniphier-ahci.c +++ b/drivers/phy/socionext/phy-uniphier-ahci.c @@ -391,7 +391,7 @@ static int uniphier_ahciphy_probe(struct platform_device *pdev) struct phy *phy; struct phy_provider *phy_provider; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/socionext/phy-uniphier-pcie.c b/drivers/phy/socionext/phy-uniphier-pcie.c index c19173492b794f..8a7f61a6a6c072 100644 --- a/drivers/phy/socionext/phy-uniphier-pcie.c +++ b/drivers/phy/socionext/phy-uniphier-pcie.c @@ -225,7 +225,7 @@ static int uniphier_pciephy_probe(struct platform_device *pdev) struct regmap *regmap; struct phy *phy; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/socionext/phy-uniphier-usb2.c b/drivers/phy/socionext/phy-uniphier-usb2.c index c49d432e526b3a..1bf3d4bb775a70 100644 --- a/drivers/phy/socionext/phy-uniphier-usb2.c +++ b/drivers/phy/socionext/phy-uniphier-usb2.c @@ -130,7 +130,7 @@ static int uniphier_u2phy_probe(struct platform_device *pdev) } for_each_child_of_node_scoped(dev->of_node, child) { - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/socionext/phy-uniphier-usb3hs.c b/drivers/phy/socionext/phy-uniphier-usb3hs.c index c8971eee36404a..b5e96440733761 100644 --- a/drivers/phy/socionext/phy-uniphier-usb3hs.c +++ b/drivers/phy/socionext/phy-uniphier-usb3hs.c @@ -328,7 +328,7 @@ static int uniphier_u3hsphy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct phy *phy; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/socionext/phy-uniphier-usb3ss.c b/drivers/phy/socionext/phy-uniphier-usb3ss.c index f402ed8732fddc..f683137e310602 100644 --- a/drivers/phy/socionext/phy-uniphier-usb3ss.c +++ b/drivers/phy/socionext/phy-uniphier-usb3ss.c @@ -219,7 +219,7 @@ static int uniphier_u3ssphy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct phy *phy; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/sophgo/phy-cv1800-usb2.c b/drivers/phy/sophgo/phy-cv1800-usb2.c index 6fe846534e9cbd..b55d62907ae2e4 100644 --- a/drivers/phy/sophgo/phy-cv1800-usb2.c +++ b/drivers/phy/sophgo/phy-cv1800-usb2.c @@ -107,7 +107,7 @@ static int cv1800_usb_phy_probe(struct platform_device *pdev) if (!parent) return -ENODEV; - phy = devm_kmalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kmalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/spacemit/phy-k1-pcie.c b/drivers/phy/spacemit/phy-k1-pcie.c index 75477bea7f700d..35ebb1d7b5fa4c 100644 --- a/drivers/phy/spacemit/phy-k1-pcie.c +++ b/drivers/phy/spacemit/phy-k1-pcie.c @@ -609,7 +609,7 @@ static int k1_pcie_phy_probe(struct platform_device *pdev) if (!k1_phy_rterm_valid() && !probing_port_a) return -EPROBE_DEFER; - k1_phy = devm_kzalloc(dev, sizeof(*k1_phy), GFP_KERNEL); + k1_phy = devm_kzalloc_obj(dev, *k1_phy); if (!k1_phy) return -ENOMEM; k1_phy->dev = dev; diff --git a/drivers/phy/spacemit/phy-k1-usb2.c b/drivers/phy/spacemit/phy-k1-usb2.c index 8df12eeb20b184..fd08a3ab88f377 100644 --- a/drivers/phy/spacemit/phy-k1-usb2.c +++ b/drivers/phy/spacemit/phy-k1-usb2.c @@ -189,7 +189,7 @@ static int spacemit_usb2phy_probe(struct platform_device *pdev) const struct phy_ops *ops; void __iomem *base; - sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); + sphy = devm_kzalloc_obj(dev, *sphy); if (!sphy) return -ENOMEM; diff --git a/drivers/phy/spacemit/phy-k3-combo.c b/drivers/phy/spacemit/phy-k3-combo.c index 0bc08bb6247a80..6c24b021648424 100644 --- a/drivers/phy/spacemit/phy-k3-combo.c +++ b/drivers/phy/spacemit/phy-k3-combo.c @@ -192,7 +192,7 @@ static int k3_combo_phy_probe(struct platform_device *pdev) u32 config = 0; int ret; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c index c576fc5569fe97..74d34278c7e875 100644 --- a/drivers/phy/st/phy-miphy28lp.c +++ b/drivers/phy/st/phy-miphy28lp.c @@ -1171,7 +1171,7 @@ static int miphy28lp_probe(struct platform_device *pdev) size_t nphys; nphys = of_get_child_count(np); - miphy_dev = devm_kzalloc(&pdev->dev, struct_size(miphy_dev, phys, nphys), GFP_KERNEL); + miphy_dev = devm_kzalloc_flex(&pdev->dev, *miphy_dev, phys, nphys); if (!miphy_dev) return -ENOMEM; @@ -1192,8 +1192,7 @@ static int miphy28lp_probe(struct platform_device *pdev) for_each_child_of_node(np, child) { struct miphy28lp_phy *miphy_phy; - miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy), - GFP_KERNEL); + miphy_phy = devm_kzalloc_obj(&pdev->dev, *miphy_phy); if (!miphy_phy) { ret = -ENOMEM; goto put_child; diff --git a/drivers/phy/st/phy-spear1310-miphy.c b/drivers/phy/st/phy-spear1310-miphy.c index c661ab63505f9b..ad7721323415ab 100644 --- a/drivers/phy/st/phy-spear1310-miphy.c +++ b/drivers/phy/st/phy-spear1310-miphy.c @@ -208,7 +208,7 @@ static int spear1310_miphy_probe(struct platform_device *pdev) struct spear1310_miphy_priv *priv; struct phy_provider *phy_provider; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/st/phy-spear1340-miphy.c b/drivers/phy/st/phy-spear1340-miphy.c index 85a60d64ebb7db..1e16d64306f724 100644 --- a/drivers/phy/st/phy-spear1340-miphy.c +++ b/drivers/phy/st/phy-spear1340-miphy.c @@ -245,7 +245,7 @@ static int spear1340_miphy_probe(struct platform_device *pdev) struct spear1340_miphy_priv *priv; struct phy_provider *phy_provider; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/st/phy-stih407-usb.c b/drivers/phy/st/phy-stih407-usb.c index 7a3e4584895c22..3f2c27c406e00f 100644 --- a/drivers/phy/st/phy-stih407-usb.c +++ b/drivers/phy/st/phy-stih407-usb.c @@ -94,7 +94,7 @@ static int stih407_usb2_picophy_probe(struct platform_device *pdev) unsigned int syscon_args[2]; struct phy *phy; - phy_dev = devm_kzalloc(dev, sizeof(*phy_dev), GFP_KERNEL); + phy_dev = devm_kzalloc_obj(dev, *phy_dev); if (!phy_dev) return -ENOMEM; diff --git a/drivers/phy/st/phy-stm32-combophy.c b/drivers/phy/st/phy-stm32-combophy.c index 607b4d607eb5e6..d77d64f513f505 100644 --- a/drivers/phy/st/phy-stm32-combophy.c +++ b/drivers/phy/st/phy-stm32-combophy.c @@ -522,7 +522,7 @@ static int stm32_combophy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; int ret, irq; - combophy = devm_kzalloc(dev, sizeof(*combophy), GFP_KERNEL); + combophy = devm_kzalloc_obj(dev, *combophy); if (!combophy) return -ENOMEM; diff --git a/drivers/phy/st/phy-stm32-usbphyc.c b/drivers/phy/st/phy-stm32-usbphyc.c index b44afbff8616ba..094329f0ba08cf 100644 --- a/drivers/phy/st/phy-stm32-usbphyc.c +++ b/drivers/phy/st/phy-stm32-usbphyc.c @@ -623,7 +623,7 @@ static int stm32_usbphyc_probe(struct platform_device *pdev) u32 pllen, version; int ret, port = 0; - usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL); + usbphyc = devm_kzalloc_obj(dev, *usbphyc); if (!usbphyc) return -ENOMEM; usbphyc->dev = dev; @@ -669,8 +669,7 @@ static int stm32_usbphyc_probe(struct platform_device *pdev) usbphyc->switch_setup = -EINVAL; usbphyc->nphys = of_get_child_count(np); - usbphyc->phys = devm_kcalloc(dev, usbphyc->nphys, - sizeof(*usbphyc->phys), GFP_KERNEL); + usbphyc->phys = devm_kzalloc_objs(dev, *usbphyc->phys, usbphyc->nphys); if (!usbphyc->phys) { ret = -ENOMEM; goto clk_disable; @@ -704,8 +703,7 @@ static int stm32_usbphyc_probe(struct platform_device *pdev) goto put_child; } - usbphyc_phy = devm_kzalloc(dev, sizeof(*usbphyc_phy), - GFP_KERNEL); + usbphyc_phy = devm_kzalloc_obj(dev, *usbphyc_phy); if (!usbphyc_phy) { ret = -ENOMEM; goto put_child; diff --git a/drivers/phy/starfive/phy-jh7110-dphy-rx.c b/drivers/phy/starfive/phy-jh7110-dphy-rx.c index d06f21ad633251..043a7e11d18750 100644 --- a/drivers/phy/starfive/phy-jh7110-dphy-rx.c +++ b/drivers/phy/starfive/phy-jh7110-dphy-rx.c @@ -152,7 +152,7 @@ static int stf_dphy_probe(struct platform_device *pdev) struct stf_dphy *dphy; int ret; - dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); + dphy = devm_kzalloc_obj(&pdev->dev, *dphy); if (!dphy) return -ENOMEM; diff --git a/drivers/phy/starfive/phy-jh7110-dphy-tx.c b/drivers/phy/starfive/phy-jh7110-dphy-tx.c index e9ffd0f811d2ba..49a9c351203010 100644 --- a/drivers/phy/starfive/phy-jh7110-dphy-tx.c +++ b/drivers/phy/starfive/phy-jh7110-dphy-tx.c @@ -402,7 +402,7 @@ static int stf_dphy_probe(struct platform_device *pdev) struct stf_dphy *dphy; int ret; - dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL); + dphy = devm_kzalloc_obj(&pdev->dev, *dphy); if (!dphy) return -ENOMEM; diff --git a/drivers/phy/starfive/phy-jh7110-pcie.c b/drivers/phy/starfive/phy-jh7110-pcie.c index 734c8e00772773..c36e89052aa379 100644 --- a/drivers/phy/starfive/phy-jh7110-pcie.c +++ b/drivers/phy/starfive/phy-jh7110-pcie.c @@ -141,7 +141,7 @@ static int jh7110_pcie_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; u32 args[2]; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/starfive/phy-jh7110-usb.c b/drivers/phy/starfive/phy-jh7110-usb.c index b505d89860b439..c5fc27df24a0ed 100644 --- a/drivers/phy/starfive/phy-jh7110-usb.c +++ b/drivers/phy/starfive/phy-jh7110-usb.c @@ -119,7 +119,7 @@ static int jh7110_usb_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct phy_provider *phy_provider; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c index 0ad4c7160d17c2..6fe096ff1e432a 100644 --- a/drivers/phy/sunplus/phy-sunplus-usb2.c +++ b/drivers/phy/sunplus/phy-sunplus-usb2.c @@ -242,7 +242,7 @@ static int sp_usb_phy_probe(struct platform_device *pdev) struct phy *phy; int ret; - usbphy = devm_kzalloc(&pdev->dev, sizeof(*usbphy), GFP_KERNEL); + usbphy = devm_kzalloc_obj(&pdev->dev, *usbphy); if (!usbphy) return -ENOMEM; diff --git a/drivers/phy/tegra/phy-tegra-mphy.c b/drivers/phy/tegra/phy-tegra-mphy.c index 01cafe1c7477fb..17722aaaa36141 100644 --- a/drivers/phy/tegra/phy-tegra-mphy.c +++ b/drivers/phy/tegra/phy-tegra-mphy.c @@ -396,7 +396,7 @@ static int tegra_mphy_probe(struct platform_device *pdev) struct tegra_mphy *mphy; int err; - mphy = devm_kzalloc(dev, sizeof(*mphy), GFP_KERNEL); + mphy = devm_kzalloc_obj(dev, *mphy); if (!mphy) return -ENOMEM; diff --git a/drivers/phy/tegra/phy-tegra194-p2u.c b/drivers/phy/tegra/phy-tegra194-p2u.c index f49b417c9eb605..e1cf4178a8f701 100644 --- a/drivers/phy/tegra/phy-tegra194-p2u.c +++ b/drivers/phy/tegra/phy-tegra194-p2u.c @@ -111,7 +111,7 @@ static int tegra_p2u_probe(struct platform_device *pdev) struct phy *generic_phy; struct tegra_p2u *phy; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/tegra/xusb-tegra124.c b/drivers/phy/tegra/xusb-tegra124.c index 70b6213370a8ea..e52de4d6fcd138 100644 --- a/drivers/phy/tegra/xusb-tegra124.c +++ b/drivers/phy/tegra/xusb-tegra124.c @@ -1693,7 +1693,7 @@ tegra124_xusb_padctl_probe(struct device *dev, struct tegra124_xusb_padctl *padctl; int err; - padctl = devm_kzalloc(dev, sizeof(*padctl), GFP_KERNEL); + padctl = devm_kzalloc_obj(dev, *padctl); if (!padctl) return ERR_PTR(-ENOMEM); diff --git a/drivers/phy/tegra/xusb-tegra186.c b/drivers/phy/tegra/xusb-tegra186.c index aa8ab94fad4cf0..82f5c6c8f6a8a7 100644 --- a/drivers/phy/tegra/xusb-tegra186.c +++ b/drivers/phy/tegra/xusb-tegra186.c @@ -1473,11 +1473,11 @@ tegra186_xusb_read_fuse_calibration(struct tegra186_xusb_padctl *padctl) count = soc->ports.usb2.count; - level = devm_kcalloc(dev, count, sizeof(u32), GFP_KERNEL); + level = devm_kzalloc_objs(dev, u32, count); if (!level) return -ENOMEM; - hs_term_range_adj = devm_kcalloc(dev, count, sizeof(u32), GFP_KERNEL); + hs_term_range_adj = devm_kzalloc_objs(dev, u32, count); if (!hs_term_range_adj) return -ENOMEM; @@ -1532,7 +1532,7 @@ tegra186_xusb_padctl_probe(struct device *dev, struct resource *res; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c index 1abc5913ec4903..42082d552d296b 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -3146,7 +3146,7 @@ tegra210_xusb_padctl_probe(struct device *dev, struct device_node *np; int err; - padctl = devm_kzalloc(dev, sizeof(*padctl), GFP_KERNEL); + padctl = devm_kzalloc_obj(dev, *padctl); if (!padctl) return ERR_PTR(-ENOMEM); diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c index 89ce9ac8730060..cd1cd985f36aa1 100644 --- a/drivers/phy/tegra/xusb.c +++ b/drivers/phy/tegra/xusb.c @@ -208,8 +208,7 @@ int tegra_xusb_pad_register(struct tegra_xusb_pad *pad, if (!children) return -ENODEV; - pad->lanes = devm_kcalloc(&pad->dev, pad->soc->num_lanes, sizeof(lane), - GFP_KERNEL); + pad->lanes = devm_kzalloc_objs(&pad->dev, lane, pad->soc->num_lanes); if (!pad->lanes) { of_node_put(children); return -ENOMEM; @@ -685,9 +684,7 @@ static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port) * where an optimal solution is possible with changes to USB role * switch driver. */ - port->dev.driver = devm_kzalloc(&port->dev, - sizeof(struct device_driver), - GFP_KERNEL); + port->dev.driver = devm_kzalloc_obj(&port->dev, struct device_driver); if (!port->dev.driver) return -ENOMEM; @@ -705,8 +702,7 @@ static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port) INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work); usb_role_switch_set_drvdata(port->usb_role_sw, port); - port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg), - GFP_KERNEL); + port->usb_phy.otg = devm_kzalloc_obj(&port->dev, struct usb_otg); if (!port->usb_phy.otg) return -ENOMEM; @@ -1226,8 +1222,8 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev) goto remove; } - padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, - sizeof(*padctl->supplies), GFP_KERNEL); + padctl->supplies = devm_kzalloc_objs(&pdev->dev, *padctl->supplies, + padctl->soc->num_supplies); if (!padctl->supplies) { err = -ENOMEM; goto remove; diff --git a/drivers/phy/ti/phy-am654-serdes.c b/drivers/phy/ti/phy-am654-serdes.c index 5b6c27aa7e8bbb..f7b6156163d154 100644 --- a/drivers/phy/ti/phy-am654-serdes.c +++ b/drivers/phy/ti/phy-am654-serdes.c @@ -652,7 +652,7 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, unsigned int reg; struct clk *clk; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; @@ -747,7 +747,7 @@ static int serdes_am654_probe(struct platform_device *pdev) int ret; int i; - am654_phy = devm_kzalloc(dev, sizeof(*am654_phy), GFP_KERNEL); + am654_phy = devm_kzalloc_obj(dev, *am654_phy); if (!am654_phy) return -ENOMEM; diff --git a/drivers/phy/ti/phy-da8xx-usb.c b/drivers/phy/ti/phy-da8xx-usb.c index 62fa6f89c0e61e..32f663b42019d7 100644 --- a/drivers/phy/ti/phy-da8xx-usb.c +++ b/drivers/phy/ti/phy-da8xx-usb.c @@ -182,7 +182,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev) struct da8xx_usb_phy *d_phy; int ret; - d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL); + d_phy = devm_kzalloc_obj(dev, *d_phy); if (!d_phy) return -ENOMEM; diff --git a/drivers/phy/ti/phy-dm816x-usb.c b/drivers/phy/ti/phy-dm816x-usb.c index d274831b731c33..ec26d98703e64a 100644 --- a/drivers/phy/ti/phy-dm816x-usb.c +++ b/drivers/phy/ti/phy-dm816x-usb.c @@ -177,7 +177,7 @@ static int dm816x_usb_phy_probe(struct platform_device *pdev) struct usb_otg *otg; int error; - phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&pdev->dev, *phy); if (!phy) return -ENOMEM; @@ -200,7 +200,7 @@ static int dm816x_usb_phy_probe(struct platform_device *pdev) if (phy->usbphy_ctrl == 0x2c) phy->instance = 1; - otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(&pdev->dev, *otg); if (!otg) return -ENOMEM; diff --git a/drivers/phy/ti/phy-ds125df111.c b/drivers/phy/ti/phy-ds125df111.c index 84ff96d7d589a9..a9fe6c614f26cc 100644 --- a/drivers/phy/ti/phy-ds125df111.c +++ b/drivers/phy/ti/phy-ds125df111.c @@ -244,7 +244,7 @@ static int ds125df111_probe(struct i2c_client *client) struct ds125df111_priv *priv; int i, err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->client = client; diff --git a/drivers/phy/ti/phy-gmii-sel.c b/drivers/phy/ti/phy-gmii-sel.c index c2865a6b1d7fbd..3649dc75c28899 100644 --- a/drivers/phy/ti/phy-gmii-sel.c +++ b/drivers/phy/ti/phy-gmii-sel.c @@ -452,8 +452,7 @@ static int phy_gmii_sel_init_ports(struct phy_gmii_sel_priv *priv) priv->reg_offset = __be32_to_cpu(*offset); } - if_phys = devm_kcalloc(dev, priv->num_ports, - sizeof(*if_phys), GFP_KERNEL); + if_phys = devm_kzalloc_objs(dev, *if_phys, priv->num_ports); if (!if_phys) return -ENOMEM; dev_dbg(dev, "%s %d\n", __func__, priv->num_ports); @@ -489,7 +488,7 @@ static int phy_gmii_sel_probe(struct platform_device *pdev) if (!of_id) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/phy/ti/phy-j721e-wiz.c b/drivers/phy/ti/phy-j721e-wiz.c index 1f5dba49ace4ef..1494b10a62e16c 100644 --- a/drivers/phy/ti/phy-j721e-wiz.c +++ b/drivers/phy/ti/phy-j721e-wiz.c @@ -748,7 +748,7 @@ static int wiz_phy_en_refclk_register(struct wiz *wiz) char *clk_name; unsigned int sz; - wiz_phy_en_refclk = devm_kzalloc(dev, sizeof(*wiz_phy_en_refclk), GFP_KERNEL); + wiz_phy_en_refclk = devm_kzalloc_obj(dev, *wiz_phy_en_refclk); if (!wiz_phy_en_refclk) return -ENOMEM; @@ -819,7 +819,7 @@ static int wiz_mux_clk_register(struct wiz *wiz, struct regmap_field *field, struct clk *clk; int ret = 0, i; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; @@ -880,7 +880,7 @@ static int wiz_mux_of_clk_register(struct wiz *wiz, struct device_node *node, struct clk *clk; int ret; - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; @@ -975,7 +975,7 @@ static int wiz_div_clk_register(struct wiz *wiz, struct device_node *node, struct clk *clk; int ret; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return -ENOMEM; @@ -1483,7 +1483,7 @@ static int wiz_probe(struct platform_device *pdev) u32 num_lanes; const struct wiz_data *data; - wiz = devm_kzalloc(dev, sizeof(*wiz), GFP_KERNEL); + wiz = devm_kzalloc_obj(dev, *wiz); if (!wiz) return -ENOMEM; diff --git a/drivers/phy/ti/phy-omap-control.c b/drivers/phy/ti/phy-omap-control.c index 4968434312f86a..99989971046480 100644 --- a/drivers/phy/ti/phy-omap-control.c +++ b/drivers/phy/ti/phy-omap-control.c @@ -270,8 +270,7 @@ static int omap_control_phy_probe(struct platform_device *pdev) { struct omap_control_phy *control_phy; - control_phy = devm_kzalloc(&pdev->dev, sizeof(*control_phy), - GFP_KERNEL); + control_phy = devm_kzalloc_obj(&pdev->dev, *control_phy); if (!control_phy) return -ENOMEM; diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c index 1eb252604441b5..a531381fec1e5c 100644 --- a/drivers/phy/ti/phy-omap-usb2.c +++ b/drivers/phy/ti/phy-omap-usb2.c @@ -386,11 +386,11 @@ static int omap_usb2_probe(struct platform_device *pdev) if (!phy_data) return -EINVAL; - phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(&pdev->dev, *phy); if (!phy) return -ENOMEM; - otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(&pdev->dev, *otg); if (!otg) return -ENOMEM; diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c index b5543b5c674c83..c280e696fff96b 100644 --- a/drivers/phy/ti/phy-ti-pipe3.c +++ b/drivers/phy/ti/phy-ti-pipe3.c @@ -794,7 +794,7 @@ static int ti_pipe3_probe(struct platform_device *pdev) int ret; const struct pipe3_data *data; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return -ENOMEM; diff --git a/drivers/phy/ti/phy-tusb1210.c b/drivers/phy/ti/phy-tusb1210.c index 9956921c094bed..864125b05bba2a 100644 --- a/drivers/phy/ti/phy-tusb1210.c +++ b/drivers/phy/ti/phy-tusb1210.c @@ -492,7 +492,7 @@ static int tusb1210_probe(struct ulpi *ulpi) u8 val, reg; int ret; - tusb = devm_kzalloc(dev, sizeof(*tusb), GFP_KERNEL); + tusb = devm_kzalloc_obj(dev, *tusb); if (!tusb) return -ENOMEM; diff --git a/drivers/phy/ti/phy-twl4030-usb.c b/drivers/phy/ti/phy-twl4030-usb.c index a26aec3ab29e09..580e5f697b0bb5 100644 --- a/drivers/phy/ti/phy-twl4030-usb.c +++ b/drivers/phy/ti/phy-twl4030-usb.c @@ -690,7 +690,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct phy_provider *phy_provider; - twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); + twl = devm_kzalloc_obj(&pdev->dev, *twl); if (!twl) return -ENOMEM; @@ -704,7 +704,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) return -EINVAL; } - otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(&pdev->dev, *otg); if (!otg) return -ENOMEM; diff --git a/drivers/phy/xilinx/phy-zynqmp.c b/drivers/phy/xilinx/phy-zynqmp.c index 240626b5547505..f2909333871104 100644 --- a/drivers/phy/xilinx/phy-zynqmp.c +++ b/drivers/phy/xilinx/phy-zynqmp.c @@ -1014,7 +1014,7 @@ static int xpsgtr_probe(struct platform_device *pdev) unsigned int port; int ret; - gtr_dev = devm_kzalloc(&pdev->dev, sizeof(*gtr_dev), GFP_KERNEL); + gtr_dev = devm_kzalloc_obj(&pdev->dev, *gtr_dev); if (!gtr_dev) return -ENOMEM; diff --git a/drivers/pinctrl/actions/pinctrl-owl.c b/drivers/pinctrl/actions/pinctrl-owl.c index 9f5637756bd35f..c6d99af6b8ee5c 100644 --- a/drivers/pinctrl/actions/pinctrl-owl.c +++ b/drivers/pinctrl/actions/pinctrl-owl.c @@ -903,8 +903,8 @@ static int owl_gpio_init(struct owl_pinctrl *pctrl) gpio_irq->num_parents = pctrl->num_irq; gpio_irq->parents = pctrl->irq; - gpio_irq->map = devm_kcalloc(pctrl->dev, chip->ngpio, - sizeof(*gpio_irq->map), GFP_KERNEL); + gpio_irq->map = devm_kzalloc_objs(pctrl->dev, *gpio_irq->map, + chip->ngpio); if (!gpio_irq->map) return -ENOMEM; @@ -932,7 +932,7 @@ int owl_pinctrl_probe(struct platform_device *pdev, struct owl_pinctrl *pctrl; int ret, i; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; @@ -983,8 +983,7 @@ int owl_pinctrl_probe(struct platform_device *pdev, pctrl->num_irq = ret; - pctrl->irq = devm_kcalloc(&pdev->dev, pctrl->num_irq, - sizeof(*pctrl->irq), GFP_KERNEL); + pctrl->irq = devm_kzalloc_objs(&pdev->dev, *pctrl->irq, pctrl->num_irq); if (!pctrl->irq) { ret = -ENOMEM; goto err_exit; diff --git a/drivers/pinctrl/airoha/pinctrl-airoha.c b/drivers/pinctrl/airoha/pinctrl-airoha.c index 52a768c859b71c..32d4af044ae132 100644 --- a/drivers/pinctrl/airoha/pinctrl-airoha.c +++ b/drivers/pinctrl/airoha/pinctrl-airoha.c @@ -805,7 +805,7 @@ int airoha_pinctrl_probe(struct platform_device *pdev) if (!data) return -EINVAL; - pinctrl = devm_kzalloc(dev, sizeof(*pinctrl), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(dev, *pinctrl); if (!pinctrl) return -ENOMEM; diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g7-soc1.c b/drivers/pinctrl/aspeed/pinctrl-aspeed-g7-soc1.c index f8b4066699ce54..4707e5f28c19e3 100644 --- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g7-soc1.c +++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g7-soc1.c @@ -1691,7 +1691,7 @@ static int aspeed_g7_soc1_pinctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int i, ret; - pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(dev, *pctl); if (!pctl) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c index 725e880ae086f8..c155af38ab81e9 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c @@ -1299,7 +1299,7 @@ static int bcm2835_pinctrl_probe(struct platform_device *pdev) BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_pins) != BCM2711_NUM_GPIOS); BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_groups) != BCM2711_NUM_GPIOS); - pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); + pc = devm_kzalloc_obj(dev, *pc); if (!pc) return -ENOMEM; @@ -1362,18 +1362,15 @@ static int bcm2835_pinctrl_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &bcm2835_gpio_irq_chip); girq->parent_handler = bcm2835_gpio_irq_handler; girq->num_parents = BCM2835_NUM_IRQS; - girq->parents = devm_kcalloc(dev, BCM2835_NUM_IRQS, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, BCM2835_NUM_IRQS); if (!girq->parents) { err = -ENOMEM; goto out_remove; } if (is_7211) { - pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS, - sizeof(*pc->wake_irq), - GFP_KERNEL); + pc->wake_irq = devm_kzalloc_objs(dev, *pc->wake_irq, + BCM2835_NUM_IRQS); if (!pc->wake_irq) { err = -ENOMEM; goto out_remove; diff --git a/drivers/pinctrl/bcm/pinctrl-bcm4908.c b/drivers/pinctrl/bcm/pinctrl-bcm4908.c index 709ef4add92797..3ccfc45f7a8d07 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm4908.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm4908.c @@ -476,7 +476,7 @@ static int bcm4908_pinctrl_probe(struct platform_device *pdev) char **pin_names; int i; - bcm4908_pinctrl = devm_kzalloc(dev, sizeof(*bcm4908_pinctrl), GFP_KERNEL); + bcm4908_pinctrl = devm_kzalloc_obj(dev, *bcm4908_pinctrl); if (!bcm4908_pinctrl) return -ENOMEM; pctldesc = &bcm4908_pinctrl->pctldesc; @@ -500,7 +500,7 @@ static int bcm4908_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(pin_names)) return PTR_ERR(pin_names); - pins = devm_kcalloc(dev, BCM4908_NUM_PINS, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, BCM4908_NUM_PINS); if (!pins) return -ENOMEM; for (i = 0; i < BCM4908_NUM_PINS; i++) { @@ -524,7 +524,7 @@ static int bcm4908_pinctrl_probe(struct platform_device *pdev) int *pins; int j; - pins = devm_kcalloc(dev, group->num_pins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, group->num_pins); if (!pins) return -ENOMEM; for (j = 0; j < group->num_pins; j++) diff --git a/drivers/pinctrl/bcm/pinctrl-bcm6358.c b/drivers/pinctrl/bcm/pinctrl-bcm6358.c index 4c8cd65fc31e8f..8ac46d8f47bc00 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm6358.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm6358.c @@ -332,7 +332,7 @@ static int bcm6358_pinctrl_probe(struct platform_device *pdev) struct bcm6358_priv *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-bcm6368.c b/drivers/pinctrl/bcm/pinctrl-bcm6368.c index 6208467ba6f943..344800df792e4c 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm6368.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm6368.c @@ -477,7 +477,7 @@ static int bcm6368_pinctrl_probe(struct platform_device *pdev) struct bcm6368_priv *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-bcm63xx.c b/drivers/pinctrl/bcm/pinctrl-bcm63xx.c index b41a3d16aabea4..892f5edac2922a 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm63xx.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm63xx.c @@ -69,7 +69,7 @@ int bcm63xx_pinctrl_probe(struct platform_device *pdev, struct bcm63xx_pinctrl *pc; int err; - pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); + pc = devm_kzalloc_obj(dev, *pc); if (!pc) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-brcmstb.c b/drivers/pinctrl/bcm/pinctrl-brcmstb.c index f46b27155c3c40..d4ef954ab69f90 100644 --- a/drivers/pinctrl/bcm/pinctrl-brcmstb.c +++ b/drivers/pinctrl/bcm/pinctrl-brcmstb.c @@ -389,7 +389,7 @@ int brcmstb_pinctrl_probe(struct platform_device *pdev) pdata = of_device_get_match_data(dev); - pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); + pc = devm_kzalloc_obj(dev, *pc); if (!pc) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-cygnus-mux.c b/drivers/pinctrl/bcm/pinctrl-cygnus-mux.c index e9aa99f85e0594..27ac1ee307b8af 100644 --- a/drivers/pinctrl/bcm/pinctrl-cygnus-mux.c +++ b/drivers/pinctrl/bcm/pinctrl-cygnus-mux.c @@ -911,9 +911,9 @@ static int cygnus_mux_log_init(struct cygnus_pinctrl *pinctrl) struct cygnus_mux_log *log; unsigned int i, j; - pinctrl->mux_log = devm_kcalloc(pinctrl->dev, CYGNUS_NUM_IOMUX, - sizeof(struct cygnus_mux_log), - GFP_KERNEL); + pinctrl->mux_log = devm_kzalloc_objs(pinctrl->dev, + struct cygnus_mux_log, + CYGNUS_NUM_IOMUX); if (!pinctrl->mux_log) return -ENOMEM; @@ -937,7 +937,7 @@ static int cygnus_pinmux_probe(struct platform_device *pdev) int i, ret; struct pinctrl_pin_desc *pins; - pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(&pdev->dev, *pinctrl); if (!pinctrl) return -ENOMEM; @@ -963,8 +963,7 @@ static int cygnus_pinmux_probe(struct platform_device *pdev) return ret; } - pins = devm_kcalloc(&pdev->dev, ARRAY_SIZE(cygnus_pins), sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, ARRAY_SIZE(cygnus_pins)); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c index e20f7dc79d43e1..a3d87c2155ea6f 100644 --- a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c +++ b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c @@ -457,9 +457,8 @@ static int iproc_pinconf_disable_map_create(struct iproc_gpio *chip, * Allocate an array to store PINCONF parameters that need to be * disabled */ - chip->pinconf_disable = devm_kcalloc(chip->dev, nbits, - sizeof(*chip->pinconf_disable), - GFP_KERNEL); + chip->pinconf_disable = devm_kzalloc_objs(chip->dev, + *chip->pinconf_disable, nbits); if (!chip->pinconf_disable) return -ENOMEM; @@ -764,7 +763,7 @@ static int iproc_gpio_register_pinconf(struct iproc_gpio *chip) struct gpio_chip *gc = &chip->gc; int i; - pins = devm_kcalloc(chip->dev, gc->ngpio, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(chip->dev, *pins, gc->ngpio); if (!pins) return -ENOMEM; @@ -820,7 +819,7 @@ static int iproc_gpio_probe(struct platform_device *pdev) "brcm,iproc-stingray-gpio")) no_pinconf = true; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -880,9 +879,7 @@ static int iproc_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &iproc_gpio_irq_chip); girq->parent_handler = iproc_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/pinctrl/bcm/pinctrl-ns.c b/drivers/pinctrl/bcm/pinctrl-ns.c index e134c9c73450bc..3026beb182cf55 100644 --- a/drivers/pinctrl/bcm/pinctrl-ns.c +++ b/drivers/pinctrl/bcm/pinctrl-ns.c @@ -215,7 +215,7 @@ static int ns_pinctrl_probe(struct platform_device *pdev) struct resource *res; int i; - ns_pinctrl = devm_kzalloc(dev, sizeof(*ns_pinctrl), GFP_KERNEL); + ns_pinctrl = devm_kzalloc_obj(dev, *ns_pinctrl); if (!ns_pinctrl) return -ENOMEM; pctldesc = &ns_pinctrl->pctldesc; @@ -237,9 +237,8 @@ static int ns_pinctrl_probe(struct platform_device *pdev) /* Set pinctrl properties */ - pctldesc->pins = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_pins), - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + pctldesc->pins = devm_kzalloc_objs(dev, struct pinctrl_pin_desc, + ARRAY_SIZE(ns_pinctrl_pins)); if (!pctldesc->pins) return -ENOMEM; for (i = 0, pin = (struct pinctrl_pin_desc *)&pctldesc->pins[0]; diff --git a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c index 23ab3ab064b6f2..da985f9502c304 100644 --- a/drivers/pinctrl/bcm/pinctrl-ns2-mux.c +++ b/drivers/pinctrl/bcm/pinctrl-ns2-mux.c @@ -979,9 +979,8 @@ static int ns2_mux_log_init(struct ns2_pinctrl *pinctrl) struct ns2_mux_log *log; unsigned int i; - pinctrl->mux_log = devm_kcalloc(pinctrl->dev, NS2_NUM_IOMUX, - sizeof(struct ns2_mux_log), - GFP_KERNEL); + pinctrl->mux_log = devm_kzalloc_objs(pinctrl->dev, struct ns2_mux_log, + NS2_NUM_IOMUX); if (!pinctrl->mux_log) return -ENOMEM; @@ -1028,7 +1027,7 @@ static int ns2_pinmux_probe(struct platform_device *pdev) int i, ret; struct pinctrl_pin_desc *pins; - pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(&pdev->dev, *pinctrl); if (!pinctrl) return -ENOMEM; @@ -1060,8 +1059,7 @@ static int ns2_pinmux_probe(struct platform_device *pdev) return ret; } - pins = devm_kcalloc(&pdev->dev, ARRAY_SIZE(ns2_pins), sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, ARRAY_SIZE(ns2_pins)); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c index 83fcc80d596740..3aeb7643c859c4 100644 --- a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c +++ b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c @@ -582,7 +582,7 @@ static int nsp_gpio_register_pinconf(struct nsp_gpio *chip) struct gpio_chip *gc = &chip->gc; int i; - pins = devm_kcalloc(chip->dev, gc->ngpio, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(chip->dev, *pins, gc->ngpio); if (!pins) return -ENOMEM; for (i = 0; i < gc->ngpio; i++) { @@ -625,7 +625,7 @@ static int nsp_gpio_probe(struct platform_device *pdev) return -ENODEV; } - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/pinctrl/bcm/pinctrl-nsp-mux.c b/drivers/pinctrl/bcm/pinctrl-nsp-mux.c index 9b716c0d2b9456..8c7cb1c7d9c897 100644 --- a/drivers/pinctrl/bcm/pinctrl-nsp-mux.c +++ b/drivers/pinctrl/bcm/pinctrl-nsp-mux.c @@ -534,9 +534,8 @@ static int nsp_mux_log_init(struct nsp_pinctrl *pinctrl) unsigned int i; u32 no_of_groups = ARRAY_SIZE(nsp_pin_groups); - pinctrl->mux_log = devm_kcalloc(pinctrl->dev, no_of_groups, - sizeof(struct nsp_mux_log), - GFP_KERNEL); + pinctrl->mux_log = devm_kzalloc_objs(pinctrl->dev, struct nsp_mux_log, + no_of_groups); if (!pinctrl->mux_log) return -ENOMEM; @@ -558,7 +557,7 @@ static int nsp_pinmux_probe(struct platform_device *pdev) int i, ret; struct pinctrl_pin_desc *pins; - pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(&pdev->dev, *pinctrl); if (!pinctrl) return -ENOMEM; pinctrl->dev = &pdev->dev; @@ -589,8 +588,7 @@ static int nsp_pinmux_probe(struct platform_device *pdev) return ret; } - pins = devm_kcalloc(&pdev->dev, ARRAY_SIZE(nsp_pins), sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, ARRAY_SIZE(nsp_pins)); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/berlin/berlin-bg4ct.c b/drivers/pinctrl/berlin/berlin-bg4ct.c index 9bf0a54f2798a2..b9ec9be42a17b0 100644 --- a/drivers/pinctrl/berlin/berlin-bg4ct.c +++ b/drivers/pinctrl/berlin/berlin-bg4ct.c @@ -457,7 +457,7 @@ static int berlin4ct_pinctrl_probe(struct platform_device *pdev) struct resource *res; void __iomem *base; - rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL); + rmconfig = devm_kzalloc_obj(&pdev->dev, *rmconfig); if (!rmconfig) return -ENOMEM; diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c index 7971339e269f43..8a612ce2d1d362 100644 --- a/drivers/pinctrl/berlin/berlin.c +++ b/drivers/pinctrl/berlin/berlin.c @@ -264,10 +264,9 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) if (!function->groups) { function->groups = - devm_kcalloc(&pdev->dev, - function->ngroups, - sizeof(*function->groups), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, + *function->groups, + function->ngroups); if (!function->groups) { kfree(pctrl->functions); return -ENOMEM; @@ -302,7 +301,7 @@ int berlin_pinctrl_probe_regmap(struct platform_device *pdev, struct berlin_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/berlin/pinctrl-as370.c b/drivers/pinctrl/berlin/pinctrl-as370.c index fc0daec94e1059..676194b38d76a3 100644 --- a/drivers/pinctrl/berlin/pinctrl-as370.c +++ b/drivers/pinctrl/berlin/pinctrl-as370.c @@ -338,7 +338,7 @@ static int as370_pinctrl_probe(struct platform_device *pdev) struct resource *res; void __iomem *base; - rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL); + rmconfig = devm_kzalloc_obj(&pdev->dev, *rmconfig); if (!rmconfig) return -ENOMEM; diff --git a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c index 8990fab0446cfe..a1c839b3555784 100644 --- a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c +++ b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c @@ -543,7 +543,7 @@ static int cs42l43_pin_probe(struct platform_device *pdev) struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev); int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/cirrus/pinctrl-lochnagar.c b/drivers/pinctrl/cirrus/pinctrl-lochnagar.c index ca6ae566082bb8..d0520c94cadbdc 100644 --- a/drivers/pinctrl/cirrus/pinctrl-lochnagar.c +++ b/drivers/pinctrl/cirrus/pinctrl-lochnagar.c @@ -1117,9 +1117,8 @@ static int lochnagar_fill_func_groups(struct lochnagar_pin_priv *priv) if (!funcs->ngroups) continue; - funcs->groups = devm_kcalloc(priv->dev, funcs->ngroups, - sizeof(*funcs->groups), - GFP_KERNEL); + funcs->groups = devm_kzalloc_objs(priv->dev, *funcs->groups, + funcs->ngroups); if (!funcs->groups) return -ENOMEM; @@ -1144,14 +1143,14 @@ static int lochnagar_pin_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; priv->dev = dev; priv->lochnagar = lochnagar; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return -ENOMEM; diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c index 1d9481b1709178..61a84e9b07ed16 100644 --- a/drivers/pinctrl/cirrus/pinctrl-madera-core.c +++ b/drivers/pinctrl/cirrus/pinctrl-madera-core.c @@ -1009,7 +1009,7 @@ static int madera_pin_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/cix/pinctrl-sky1-base.c b/drivers/pinctrl/cix/pinctrl-sky1-base.c index a5b583f10441e4..490115ef8b6444 100644 --- a/drivers/pinctrl/cix/pinctrl-sky1-base.c +++ b/drivers/pinctrl/cix/pinctrl-sky1-base.c @@ -479,14 +479,14 @@ static int sky1_pctrl_build_state(struct platform_device *pdev) int i; /* Allocate groups */ - spctl->groups = devm_kcalloc(&pdev->dev, info->npins, - sizeof(*spctl->groups), GFP_KERNEL); + spctl->groups = devm_kzalloc_objs(&pdev->dev, *spctl->groups, + info->npins); if (!spctl->groups) return -ENOMEM; /* We assume that one pin is one group, use pin name as group name. */ - spctl->grp_names = devm_kcalloc(&pdev->dev, info->npins, - sizeof(*spctl->grp_names), GFP_KERNEL); + spctl->grp_names = devm_kzalloc_objs(&pdev->dev, *spctl->grp_names, + info->npins); if (!spctl->grp_names) return -ENOMEM; @@ -517,7 +517,7 @@ int sky1_base_pinctrl_probe(struct platform_device *pdev, } /* Create state holders etc for this driver */ - spctl = devm_kzalloc(&pdev->dev, sizeof(*spctl), GFP_KERNEL); + spctl = devm_kzalloc_obj(&pdev->dev, *spctl); if (!spctl) return -ENOMEM; @@ -528,13 +528,11 @@ int sky1_base_pinctrl_probe(struct platform_device *pdev, if (IS_ERR(spctl->base)) return PTR_ERR(spctl->base); - sky1_pinctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*sky1_pinctrl_desc), - GFP_KERNEL); + sky1_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *sky1_pinctrl_desc); if (!sky1_pinctrl_desc) return -ENOMEM; - pins = devm_kcalloc(&pdev->dev, info->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, info->npins); if (!pins) return -ENOMEM; for (i = 0; i < info->npins; i++) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index ba6c71e6fc2c29..4968747a9650d5 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -668,7 +668,7 @@ int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name, selector = pctldev->num_groups; - group = devm_kzalloc(pctldev->dev, sizeof(*group), GFP_KERNEL); + group = devm_kzalloc_obj(pctldev->dev, *group); if (!group) return -ENOMEM; diff --git a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c index 613552e3507039..2cc3521f8df475 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c +++ b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c @@ -279,7 +279,7 @@ scmi_pinctrl_imx_get_pins(struct scmi_pinctrl_imx *pmx, struct pinctrl_desc *des int ret, i; npins = pmx->ops->count_get(pmx->ph, PIN_TYPE); - pins = devm_kmalloc_array(pmx->dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kmalloc_objs(pmx->dev, *pins, npins); if (!pins) return -ENOMEM; @@ -325,7 +325,7 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev) if (IS_ERR(pinctrl_ops)) return PTR_ERR(pinctrl_ops); - pmx = devm_kzalloc(dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c index 5a06be45f5c35f..ebcce9aeac8c32 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx.c +++ b/drivers/pinctrl/freescale/pinctrl-imx.c @@ -600,11 +600,11 @@ static int imx_pinctrl_parse_groups(struct device_node *np, } grp->grp.npins = size / pin_size; - grp->data = devm_kcalloc(ipctl->dev, grp->grp.npins, sizeof(*pin), GFP_KERNEL); + grp->data = devm_kzalloc_objs(ipctl->dev, *pin, grp->grp.npins); if (!grp->data) return -ENOMEM; - pins = devm_kcalloc(ipctl->dev, grp->grp.npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(ipctl->dev, *pins, grp->grp.npins); if (!pins) return -ENOMEM; grp->grp.pins = pins; @@ -633,7 +633,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np, dev_dbg(pctl->dev, "parse function(%d): %pOFn\n", index, np); - func = devm_kzalloc(ipctl->dev, sizeof(*func), GFP_KERNEL); + func = devm_kzalloc_obj(ipctl->dev, *func); if (!func) return -ENOMEM; @@ -645,8 +645,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np, return -EINVAL; } - group_names = devm_kcalloc(ipctl->dev, func->ngroups, - sizeof(*group_names), GFP_KERNEL); + group_names = devm_kzalloc_objs(ipctl->dev, *group_names, func->ngroups); if (!group_names) return -ENOMEM; i = 0; @@ -660,7 +659,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np, i = 0; for_each_child_of_node_scoped(np, child) { - grp = devm_kzalloc(ipctl->dev, sizeof(*grp), GFP_KERNEL); + grp = devm_kzalloc_obj(ipctl->dev, *grp); if (!grp) return -ENOMEM; @@ -766,14 +765,14 @@ int imx_pinctrl_probe(struct platform_device *pdev, } /* Create state holders etc for this driver */ - ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); + ipctl = devm_kzalloc_obj(&pdev->dev, *ipctl); if (!ipctl) return -ENOMEM; if (!(info->flags & IMX_USE_SCU)) { - ipctl->pin_regs = devm_kmalloc_array(&pdev->dev, info->npins, - sizeof(*ipctl->pin_regs), - GFP_KERNEL); + ipctl->pin_regs = devm_kmalloc_objs(&pdev->dev, + *ipctl->pin_regs, + info->npins); if (!ipctl->pin_regs) return -ENOMEM; @@ -803,8 +802,7 @@ int imx_pinctrl_probe(struct platform_device *pdev, } } - imx_pinctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*imx_pinctrl_desc), - GFP_KERNEL); + imx_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *imx_pinctrl_desc); if (!imx_pinctrl_desc) return -ENOMEM; diff --git a/drivers/pinctrl/freescale/pinctrl-imx1-core.c b/drivers/pinctrl/freescale/pinctrl-imx1-core.c index 4a6bdaefa42f20..0791de29b82704 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx1-core.c +++ b/drivers/pinctrl/freescale/pinctrl-imx1-core.c @@ -484,10 +484,8 @@ static int imx1_pinctrl_parse_groups(struct device_node *np, } grp->npins = size / 12; - grp->pins = devm_kcalloc(info->dev, - grp->npins, sizeof(struct imx1_pin), GFP_KERNEL); - grp->pin_ids = devm_kcalloc(info->dev, - grp->npins, sizeof(unsigned int), GFP_KERNEL); + grp->pins = devm_kzalloc_objs(info->dev, struct imx1_pin, grp->npins); + grp->pin_ids = devm_kzalloc_objs(info->dev, unsigned int, grp->npins); if (!grp->pins || !grp->pin_ids) return -ENOMEM; @@ -590,12 +588,12 @@ static int imx1_pinctrl_parse_dt(struct platform_device *pdev, } info->nfunctions = nfuncs; - info->functions = devm_kcalloc(&pdev->dev, - nfuncs, sizeof(struct imx1_pmx_func), GFP_KERNEL); + info->functions = devm_kzalloc_objs(&pdev->dev, struct imx1_pmx_func, + nfuncs); info->ngroups = ngroups; - info->groups = devm_kcalloc(&pdev->dev, - ngroups, sizeof(struct imx1_pin_group), GFP_KERNEL); + info->groups = devm_kzalloc_objs(&pdev->dev, struct imx1_pin_group, + ngroups); if (!info->functions || !info->groups) @@ -629,7 +627,7 @@ int imx1_pinctrl_core_probe(struct platform_device *pdev, info->dev = &pdev->dev; /* Create state holders etc for this driver */ - ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); + ipctl = devm_kzalloc_obj(&pdev->dev, *ipctl); if (!ipctl) return -ENOMEM; diff --git a/drivers/pinctrl/freescale/pinctrl-mxs.c b/drivers/pinctrl/freescale/pinctrl-mxs.c index 6280009be3faee..e68dccc59ca52f 100644 --- a/drivers/pinctrl/freescale/pinctrl-mxs.c +++ b/drivers/pinctrl/freescale/pinctrl-mxs.c @@ -373,8 +373,7 @@ static int mxs_pinctrl_parse_group(struct platform_device *pdev, return -EINVAL; g->npins = length / sizeof(u32); - g->pins = devm_kcalloc(&pdev->dev, g->npins, sizeof(*g->pins), - GFP_KERNEL); + g->pins = devm_kzalloc_objs(&pdev->dev, *g->pins, g->npins); if (!g->pins) return -ENOMEM; @@ -434,16 +433,12 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev, } } - soc->functions = devm_kcalloc(&pdev->dev, - soc->nfunctions, - sizeof(*soc->functions), - GFP_KERNEL); + soc->functions = devm_kzalloc_objs(&pdev->dev, *soc->functions, + soc->nfunctions); if (!soc->functions) return -ENOMEM; - soc->groups = devm_kcalloc(&pdev->dev, - soc->ngroups, sizeof(*soc->groups), - GFP_KERNEL); + soc->groups = devm_kzalloc_objs(&pdev->dev, *soc->groups, soc->ngroups); if (!soc->groups) return -ENOMEM; @@ -503,10 +498,8 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev, if (strcmp(fn, child->name)) { f = &soc->functions[idxf++]; - f->groups = devm_kcalloc(&pdev->dev, - f->ngroups, - sizeof(*f->groups), - GFP_KERNEL); + f->groups = devm_kzalloc_objs(&pdev->dev, *f->groups, + f->ngroups); if (!f->groups) return -ENOMEM; fn = child->name; @@ -528,7 +521,7 @@ int mxs_pinctrl_probe(struct platform_device *pdev, struct mxs_pinctrl_data *d; int ret; - d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(&pdev->dev, *d); if (!d) return -ENOMEM; diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/intel/pinctrl-baytrail.c index b733ec31ad9d75..081cef82695de1 100644 --- a/drivers/pinctrl/intel/pinctrl-baytrail.c +++ b/drivers/pinctrl/intel/pinctrl-baytrail.c @@ -1525,8 +1525,8 @@ static int byt_gpio_probe(struct intel_pinctrl *vg) gc->ngpio = vg->soc->npins; #ifdef CONFIG_PM_SLEEP - vg->context.pads = devm_kcalloc(vg->dev, gc->ngpio, sizeof(*vg->context.pads), - GFP_KERNEL); + vg->context.pads = devm_kzalloc_objs(vg->dev, *vg->context.pads, + gc->ngpio); if (!vg->context.pads) return -ENOMEM; #endif @@ -1542,8 +1542,8 @@ static int byt_gpio_probe(struct intel_pinctrl *vg) girq->init_valid_mask = byt_init_irq_valid_mask; girq->parent_handler = byt_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(vg->dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(vg->dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; @@ -1600,7 +1600,7 @@ static int byt_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(soc_data)) return PTR_ERR(soc_data); - vg = devm_kzalloc(dev, sizeof(*vg), GFP_KERNEL); + vg = devm_kzalloc_obj(dev, *vg); if (!vg) return -ENOMEM; diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c index a33eca5eafc44e..37bb0b07ed1ab6 100644 --- a/drivers/pinctrl/intel/pinctrl-cherryview.c +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c @@ -1595,7 +1595,7 @@ static int chv_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(soc_data)) return PTR_ERR(soc_data); - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; @@ -1616,16 +1616,15 @@ static int chv_pinctrl_probe(struct platform_device *pdev) community->pad_regs = community->regs + FAMILY_PAD_REGS_OFF; #ifdef CONFIG_PM_SLEEP - pctrl->context.pads = devm_kcalloc(dev, pctrl->soc->npins, - sizeof(*pctrl->context.pads), - GFP_KERNEL); + pctrl->context.pads = devm_kzalloc_objs(dev, *pctrl->context.pads, + pctrl->soc->npins); if (!pctrl->context.pads) return -ENOMEM; #endif - pctrl->context.communities = devm_kcalloc(dev, pctrl->soc->ncommunities, - sizeof(*pctrl->context.communities), - GFP_KERNEL); + pctrl->context.communities = devm_kzalloc_objs(dev, + *pctrl->context.communities, + pctrl->soc->ncommunities); if (!pctrl->context.communities) return -ENOMEM; diff --git a/drivers/pinctrl/intel/pinctrl-intel-platform.c b/drivers/pinctrl/intel/pinctrl-intel-platform.c index c83e3859b65595..11d819f1a6f590 100644 --- a/drivers/pinctrl/intel/pinctrl-intel-platform.c +++ b/drivers/pinctrl/intel/pinctrl-intel-platform.c @@ -124,7 +124,7 @@ static int intel_platform_pinctrl_prepare_community(struct device *dev, if (!ngpps) return -ENODEV; - gpps = devm_kcalloc(dev, ngpps, sizeof(*gpps), GFP_KERNEL); + gpps = devm_kzalloc_objs(dev, *gpps, ngpps); if (!gpps) return -ENOMEM; @@ -158,7 +158,7 @@ static int intel_platform_pinctrl_prepare_soc_data(struct device *dev, /* Version 1.0 of the specification assumes only a single community per device node */ ncommunities = 1; - communities = devm_kcalloc(dev, ncommunities, sizeof(*communities), GFP_KERNEL); + communities = devm_kzalloc_objs(dev, *communities, ncommunities); if (!communities) return -ENOMEM; @@ -190,7 +190,7 @@ static int intel_platform_pinctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c index 1363301098d5a6..51a86975909cf4 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -1440,7 +1440,7 @@ static int intel_pinctrl_add_padgroups_by_gpps(struct intel_pinctrl *pctrl, unsigned int padown_num = 0; size_t i, ngpps = community->ngpps; - gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL); + gpps = devm_kzalloc_objs(pctrl->dev, *gpps, ngpps); if (!gpps) return -ENOMEM; @@ -1484,7 +1484,7 @@ static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl, if (community->gpp_size > INTEL_PINCTRL_MAX_GPP_SIZE) return -EINVAL; - gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL); + gpps = devm_kzalloc_objs(pctrl->dev, *gpps, ngpps); if (!gpps) return -ENOMEM; @@ -1516,12 +1516,12 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) struct intel_pad_context *pads; int i; - pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL); + pads = devm_kzalloc_objs(pctrl->dev, *pads, soc->npins); if (!pads) return -ENOMEM; - communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities, - sizeof(*communities), GFP_KERNEL); + communities = devm_kzalloc_objs(pctrl->dev, *communities, + pctrl->ncommunities); if (!communities) return -ENOMEM; @@ -1530,15 +1530,15 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) struct intel_community *community = &pctrl->communities[i]; u32 *intmask, *hostown; - intmask = devm_kcalloc(pctrl->dev, community->ngpps, - sizeof(*intmask), GFP_KERNEL); + intmask = devm_kzalloc_objs(pctrl->dev, *intmask, + community->ngpps); if (!intmask) return -ENOMEM; communities[i].intmask = intmask; - hostown = devm_kcalloc(pctrl->dev, community->ngpps, - sizeof(*hostown), GFP_KERNEL); + hostown = devm_kzalloc_objs(pctrl->dev, *hostown, + community->ngpps); if (!hostown) return -ENOMEM; @@ -1582,7 +1582,7 @@ int intel_pinctrl_probe(struct platform_device *pdev, struct intel_pinctrl *pctrl; int i, ret, irq; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/intel/pinctrl-lynxpoint.c b/drivers/pinctrl/intel/pinctrl-lynxpoint.c index 299ee4f22bdcd5..c5131e100e5db2 100644 --- a/drivers/pinctrl/intel/pinctrl-lynxpoint.c +++ b/drivers/pinctrl/intel/pinctrl-lynxpoint.c @@ -715,7 +715,7 @@ static int lp_gpio_probe(struct platform_device *pdev) if (!soc) return -ENODEV; - lg = devm_kzalloc(dev, sizeof(*lg), GFP_KERNEL); + lg = devm_kzalloc_obj(dev, *lg); if (!lg) return -ENOMEM; @@ -723,8 +723,8 @@ static int lp_gpio_probe(struct platform_device *pdev) lg->soc = soc; lg->ncommunities = lg->soc->ncommunities; - lg->communities = devm_kcalloc(dev, lg->ncommunities, - sizeof(*lg->communities), GFP_KERNEL); + lg->communities = devm_kzalloc_objs(dev, *lg->communities, + lg->ncommunities); if (!lg->communities) return -ENOMEM; @@ -785,9 +785,8 @@ static int lp_gpio_probe(struct platform_device *pdev) girq->init_hw = lp_gpio_irq_init_hw; girq->parent_handler = lp_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, girq->num_parents, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c index 827231dc0d2463..389ceaffcee4a2 100644 --- a/drivers/pinctrl/mediatek/mtk-eint.c +++ b/drivers/pinctrl/mediatek/mtk-eint.c @@ -540,8 +540,8 @@ int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin) if (!eint->regs) eint->regs = &mtk_generic_eint_regs; - eint->base_pin_num = devm_kmalloc_array(eint->dev, eint->nbase, sizeof(u16), - GFP_KERNEL | __GFP_ZERO); + eint->base_pin_num = devm_kmalloc_objs(eint->dev, u16, eint->nbase, + GFP_KERNEL | __GFP_ZERO); if (!eint->base_pin_num) return -ENOMEM; @@ -567,18 +567,18 @@ int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin) } } - eint->pin_list = devm_kcalloc(eint->dev, eint->nbase, - sizeof(*eint->pin_list), GFP_KERNEL); + eint->pin_list = devm_kzalloc_objs(eint->dev, *eint->pin_list, + eint->nbase); if (!eint->pin_list) goto err_pin_list; - eint->wake_mask = devm_kcalloc(eint->dev, eint->nbase, - sizeof(*eint->wake_mask), GFP_KERNEL); + eint->wake_mask = devm_kzalloc_objs(eint->dev, *eint->wake_mask, + eint->nbase); if (!eint->wake_mask) goto err_wake_mask; - eint->cur_mask = devm_kcalloc(eint->dev, eint->nbase, - sizeof(*eint->cur_mask), GFP_KERNEL); + eint->cur_mask = devm_kzalloc_objs(eint->dev, *eint->cur_mask, + eint->nbase); if (!eint->cur_mask) goto err_cur_mask; diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c index fdfbe007b84fb5..487b146e9c056b 100644 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c @@ -661,7 +661,7 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, struct mtk_pinctrl *hw; int err, i; - hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(&pdev->dev, *hw); if (!hw) return -ENOMEM; @@ -672,8 +672,8 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, return dev_err_probe(dev, -EINVAL, "SoC should be assigned at least one register base\n"); - hw->base = devm_kmalloc_array(&pdev->dev, hw->soc->nbase_names, - sizeof(*hw->base), GFP_KERNEL); + hw->base = devm_kmalloc_objs(&pdev->dev, *hw->base, + hw->soc->nbase_names); if (!hw->base) return -ENOMEM; @@ -689,8 +689,7 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, spin_lock_init(&hw->lock); /* Copy from internal struct mtk_pin_desc to register to the core */ - pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kmalloc_objs(&pdev->dev, *pins, hw->soc->npins); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c index faa6dbf0f6356f..e01a782bbc3d6a 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c @@ -377,7 +377,7 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) if (!of_property_read_bool(np, "interrupt-controller")) return -ENODEV; - hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL); + hw->eint = devm_kzalloc_obj(hw->dev, *hw->eint); if (!hw->eint) return -ENOMEM; @@ -389,8 +389,9 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) if (hw->eint->nbase <= 0) return -EINVAL; - hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase, - sizeof(*hw->eint->base), GFP_KERNEL | __GFP_ZERO); + hw->eint->base = devm_kmalloc_objs(&pdev->dev, *hw->eint->base, + hw->eint->nbase, + GFP_KERNEL | __GFP_ZERO); if (!hw->eint->base) { ret = -ENOMEM; goto err_free_base; diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c index 857d39f3438d81..9b642d3a2be068 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c @@ -939,14 +939,14 @@ static int mtk_pctrl_build_state(struct platform_device *pdev) pctl->ngroups = pctl->devdata->npins; /* Allocate groups */ - pctl->groups = devm_kcalloc(&pdev->dev, pctl->ngroups, - sizeof(*pctl->groups), GFP_KERNEL); + pctl->groups = devm_kzalloc_objs(&pdev->dev, *pctl->groups, + pctl->ngroups); if (!pctl->groups) return -ENOMEM; /* We assume that one pin is one group, use pin name as group name. */ - pctl->grp_names = devm_kcalloc(&pdev->dev, pctl->ngroups, - sizeof(*pctl->grp_names), GFP_KERNEL); + pctl->grp_names = devm_kzalloc_objs(&pdev->dev, *pctl->grp_names, + pctl->ngroups); if (!pctl->grp_names) return -ENOMEM; @@ -1026,14 +1026,13 @@ static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev) if (!of_property_read_bool(np, "interrupt-controller")) return -ENODEV; - pctl->eint = devm_kzalloc(pctl->dev, sizeof(*pctl->eint), GFP_KERNEL); + pctl->eint = devm_kzalloc_obj(pctl->dev, *pctl->eint); if (!pctl->eint) return -ENOMEM; pctl->eint->nbase = 1; /* mtk-eint expects an array */ - pctl->eint->base = devm_kzalloc(pctl->dev, sizeof(*pctl->eint->base), - GFP_KERNEL); + pctl->eint->base = devm_kzalloc_obj(pctl->dev, *pctl->eint->base); if (!pctl->eint->base) return -ENOMEM; @@ -1069,7 +1068,7 @@ int mtk_pctrl_init(struct platform_device *pdev, struct device_node *np = pdev->dev.of_node, *node; int ret, i; - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; @@ -1101,8 +1100,7 @@ int mtk_pctrl_init(struct platform_device *pdev, if (ret) return dev_err_probe(dev, ret, "build state failed\n"); - pins = devm_kcalloc(&pdev->dev, pctl->devdata->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, pctl->devdata->npins); if (!pins) return -ENOMEM; @@ -1124,7 +1122,7 @@ int mtk_pctrl_init(struct platform_device *pdev, return dev_err_probe(dev, PTR_ERR(pctl->pctl_dev), "Couldn't register pinctrl driver\n"); - pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); + pctl->chip = devm_kzalloc_obj(&pdev->dev, *pctl->chip); if (!pctl->chip) return -ENOMEM; diff --git a/drivers/pinctrl/mediatek/pinctrl-mtmips.c b/drivers/pinctrl/mediatek/pinctrl-mtmips.c index b2d7a79ff9cc67..efac14accce37f 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtmips.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtmips.c @@ -217,10 +217,8 @@ static int mtmips_pinctrl_index(struct mtmips_priv *p) p->func_count++; /* allocate our function and group mapping index buffers */ - p->func = devm_kcalloc(p->dev, p->func_count, - sizeof(*p->func), GFP_KERNEL); - gpio_func.groups = devm_kcalloc(p->dev, p->group_count, sizeof(int), - GFP_KERNEL); + p->func = devm_kzalloc_objs(p->dev, *p->func, p->func_count); + gpio_func.groups = devm_kzalloc_objs(p->dev, int, p->group_count); if (!p->func || !gpio_func.groups) return -ENOMEM; @@ -236,8 +234,7 @@ static int mtmips_pinctrl_index(struct mtmips_priv *p) for (i = 0; i < p->group_count; i++) { for (j = 0; j < p->groups[i].func_count; j++) { p->func[c] = &p->groups[i].func[j]; - p->func[c]->groups = devm_kzalloc(p->dev, sizeof(int), - GFP_KERNEL); + p->func[c]->groups = devm_kzalloc_obj(p->dev, int); if (!p->func[c]->groups) return -ENOMEM; p->func[c]->groups[0] = i; @@ -262,10 +259,8 @@ static int mtmips_pinctrl_pins(struct mtmips_priv *p) if (!p->func[i]->pin_count) continue; - p->func[i]->pins = devm_kcalloc(p->dev, - p->func[i]->pin_count, - sizeof(int), - GFP_KERNEL); + p->func[i]->pins = devm_kzalloc_objs(p->dev, int, + p->func[i]->pin_count); if (!p->func[i]->pins) return -ENOMEM; for (j = 0; j < p->func[i]->pin_count; j++) @@ -279,8 +274,8 @@ static int mtmips_pinctrl_pins(struct mtmips_priv *p) /* the buffer that tells us which pins are gpio */ p->gpio = devm_kcalloc(p->dev, p->max_pins, sizeof(u8), GFP_KERNEL); /* the pads needed to tell pinctrl about our pins */ - p->pads = devm_kcalloc(p->dev, p->max_pins, - sizeof(struct pinctrl_pin_desc), GFP_KERNEL); + p->pads = devm_kzalloc_objs(p->dev, struct pinctrl_pin_desc, + p->max_pins); if (!p->pads || !p->gpio) return -ENOMEM; @@ -324,7 +319,7 @@ int mtmips_pinctrl_init(struct platform_device *pdev, return -ENOTSUPP; /* setup the private data */ - p = devm_kzalloc(&pdev->dev, sizeof(struct mtmips_priv), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, struct mtmips_priv); if (!p) return -ENOMEM; diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c index 09098b68f72575..1ae8133dd9c55e 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -970,14 +970,13 @@ static int mtk_pctrl_build_state(struct platform_device *pdev) int i; /* Allocate groups */ - hw->groups = devm_kmalloc_array(&pdev->dev, hw->soc->ngrps, - sizeof(*hw->groups), GFP_KERNEL); + hw->groups = devm_kmalloc_objs(&pdev->dev, *hw->groups, hw->soc->ngrps); if (!hw->groups) return -ENOMEM; /* We assume that one pin is one group, use pin name as group name. */ - hw->grp_names = devm_kmalloc_array(&pdev->dev, hw->soc->ngrps, - sizeof(*hw->grp_names), GFP_KERNEL); + hw->grp_names = devm_kmalloc_objs(&pdev->dev, *hw->grp_names, + hw->soc->ngrps); if (!hw->grp_names) return -ENOMEM; @@ -1001,7 +1000,7 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev) struct mtk_pinctrl *hw; int err, i; - hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(&pdev->dev, *hw); if (!hw) return -ENOMEM; @@ -1017,8 +1016,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev) return dev_err_probe(dev, -EINVAL, "SoC should be assigned at least one register base\n"); - hw->base = devm_kmalloc_array(&pdev->dev, hw->soc->nbase_names, - sizeof(*hw->base), GFP_KERNEL); + hw->base = devm_kmalloc_objs(&pdev->dev, *hw->base, + hw->soc->nbase_names); if (!hw->base) return -ENOMEM; @@ -1041,8 +1040,7 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev) return dev_err_probe(dev, err, "build state failed\n"); /* Copy from internal struct mtk_pin_desc to register to the core */ - pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kmalloc_objs(&pdev->dev, *pins, hw->soc->npins); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c index 39eb8cc7fc0d13..b258bd88d74536 100644 --- a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c +++ b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c @@ -824,7 +824,7 @@ static int aml_pctl_parse_functions(struct device_node *np, if (func->ngroups == 0) return dev_err_probe(dev, -EINVAL, "No groups defined\n"); - func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL); + func->groups = devm_kzalloc_objs(dev, *func->groups, func->ngroups); if (!func->groups) return -ENOMEM; @@ -1122,11 +1122,12 @@ static int aml_pctl_probe_dt(struct platform_device *pdev, dev_dbg(dev, "nfunctions = %d\n", info->nfunctions); dev_dbg(dev, "ngroups = %d\n", info->ngroups); - info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL); + info->functions = devm_kzalloc_objs(dev, *info->functions, + info->nfunctions); - info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL); + info->groups = devm_kzalloc_objs(dev, *info->groups, info->ngroups); - info->banks = devm_kcalloc(dev, info->nbanks, sizeof(*info->banks), GFP_KERNEL); + info->banks = devm_kzalloc_objs(dev, *info->banks, info->nbanks); if (!info->functions || !info->groups || !info->banks) return -ENOMEM; @@ -1135,7 +1136,7 @@ static int aml_pctl_probe_dt(struct platform_device *pdev, pctl_desc->npins = aml_count_pins(np); - pdesc = devm_kcalloc(dev, pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL); + pdesc = devm_kzalloc_objs(dev, *pdesc, pctl_desc->npins); if (!pdesc) return -ENOMEM; @@ -1183,11 +1184,11 @@ static int aml_pctl_probe(struct platform_device *pdev) struct pinctrl_desc *pctl_desc; int ret, i; - pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL); + pctl_desc = devm_kzalloc_obj(dev, *pctl_desc); if (!pctl_desc) return -ENOMEM; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c index 9fc30aee96a564..6540ac59eb95d7 100644 --- a/drivers/pinctrl/meson/pinctrl-meson.c +++ b/drivers/pinctrl/meson/pinctrl-meson.c @@ -739,7 +739,7 @@ int meson_pinctrl_probe(struct platform_device *pdev) struct meson_pinctrl *pc; int ret; - pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); + pc = devm_kzalloc_obj(dev, struct meson_pinctrl); if (!pc) return -ENOMEM; diff --git a/drivers/pinctrl/microchip/pinctrl-mpfs-iomux0.c b/drivers/pinctrl/microchip/pinctrl-mpfs-iomux0.c index a390caa8318168..2c3d8162dd7ff3 100644 --- a/drivers/pinctrl/microchip/pinctrl-mpfs-iomux0.c +++ b/drivers/pinctrl/microchip/pinctrl-mpfs-iomux0.c @@ -231,7 +231,7 @@ static int mpfs_iomux0_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct mpfs_iomux0_pinctrl *pctrl; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c b/drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c index 8da0c5312ce376..d33f4ef389bd95 100644 --- a/drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c +++ b/drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c @@ -679,7 +679,7 @@ static int mpfs_pinctrl_probe(struct platform_device *pdev) struct mpfs_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/microchip/pinctrl-pic64gx-gpio2.c b/drivers/pinctrl/microchip/pinctrl-pic64gx-gpio2.c index 633ef40e1c27fc..862364e31e53f2 100644 --- a/drivers/pinctrl/microchip/pinctrl-pic64gx-gpio2.c +++ b/drivers/pinctrl/microchip/pinctrl-pic64gx-gpio2.c @@ -301,7 +301,7 @@ static int pic64gx_gpio2_probe(struct platform_device *pdev) struct pic64gx_gpio2_pinctrl *pctrl; void __iomem *base; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c index 81dfbd5e7f0711..074b2c626f6f31 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c @@ -785,7 +785,7 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev, * the chained irq with all of them. */ girq->num_parents = nr_irq_parent; - girq->parents = devm_kcalloc(dev, nr_irq_parent, sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, nr_irq_parent); if (!girq->parents) return -ENOMEM; for (i = 0; i < nr_irq_parent; i++) { @@ -880,9 +880,8 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) struct armada_37xx_pin_group *grp = &info->groups[n]; int i, j, f; - grp->pins = devm_kcalloc(dev, grp->npins + grp->extra_npins, - sizeof(*grp->pins), - GFP_KERNEL); + grp->pins = devm_kzalloc_objs(dev, *grp->pins, + grp->npins + grp->extra_npins); if (!grp->pins) return -ENOMEM; @@ -932,9 +931,8 @@ static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info) const char **groups; int g; - funcs[n].groups = devm_kcalloc(dev, funcs[n].ngroups, - sizeof(*(funcs[n].groups)), - GFP_KERNEL); + funcs[n].groups = devm_kzalloc_objs(dev, *(funcs[n].groups), + funcs[n].ngroups); if (!funcs[n].groups) return -ENOMEM; @@ -974,7 +972,7 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, ctrldesc->pmxops = &armada_37xx_pmx_ops; ctrldesc->confops = &armada_37xx_pinconf_ops; - pindesc = devm_kcalloc(dev, pin_data->nr_pins, sizeof(*pindesc), GFP_KERNEL); + pindesc = devm_kzalloc_objs(dev, *pindesc, pin_data->nr_pins); if (!pindesc) return -ENOMEM; @@ -996,7 +994,7 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, * we allocate functions for number of pins and hope there are * fewer unique functions than pins available */ - info->funcs = devm_kcalloc(dev, pin_data->nr_pins, sizeof(*info->funcs), GFP_KERNEL); + info->funcs = devm_kzalloc_objs(dev, *info->funcs, pin_data->nr_pins); if (!info->funcs) return -ENOMEM; @@ -1151,7 +1149,7 @@ static int __init armada_37xx_pinctrl_probe(struct platform_device *pdev) return PTR_ERR(regmap); } - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-cp110.c b/drivers/pinctrl/mvebu/pinctrl-armada-cp110.c index 9a250c491f33d3..7c51c953bfe29f 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-cp110.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-cp110.c @@ -643,8 +643,7 @@ static int armada_cp110_pinctrl_probe(struct platform_device *pdev) if (!pdev->dev.parent) return -ENODEV; - soc = devm_kzalloc(&pdev->dev, - sizeof(struct mvebu_pinctrl_soc_info), GFP_KERNEL); + soc = devm_kzalloc_obj(&pdev->dev, struct mvebu_pinctrl_soc_info); if (!soc) return -ENOMEM; diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c index 487825bfd125f3..8bf51bee221bce 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c @@ -621,8 +621,7 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev) nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG); - mpp_saved_regs = devm_kmalloc_array(&pdev->dev, nregs, sizeof(u32), - GFP_KERNEL); + mpp_saved_regs = devm_kmalloc_objs(&pdev->dev, u32, nregs); if (!mpp_saved_regs) return -ENOMEM; diff --git a/drivers/pinctrl/mvebu/pinctrl-dove.c b/drivers/pinctrl/mvebu/pinctrl-dove.c index dce601d993728c..a8359af130efca 100644 --- a/drivers/pinctrl/mvebu/pinctrl-dove.c +++ b/drivers/pinctrl/mvebu/pinctrl-dove.c @@ -788,8 +788,8 @@ static int dove_pinctrl_probe(struct platform_device *pdev) goto err_probe; } - mpp_data = devm_kcalloc(&pdev->dev, dove_pinctrl_info.ncontrols, - sizeof(*mpp_data), GFP_KERNEL); + mpp_data = devm_kzalloc_objs(&pdev->dev, *mpp_data, + dove_pinctrl_info.ncontrols); if (!mpp_data) { ret = -ENOMEM; goto err_probe; diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c index 5ce3d7fcdd3415..40f6234b252b97 100644 --- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c +++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c @@ -507,9 +507,8 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev, /* we allocate functions for number of pins and hope * there are fewer unique functions than pins available */ - funcs = devm_kcalloc(&pdev->dev, - funcsize, sizeof(struct mvebu_pinctrl_function), - GFP_KERNEL); + funcs = devm_kzalloc_objs(&pdev->dev, struct mvebu_pinctrl_function, + funcsize); if (!funcs) return -ENOMEM; @@ -591,8 +590,7 @@ int mvebu_pinctrl_probe(struct platform_device *pdev) return -EINVAL; } - pctl = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pinctrl), - GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, struct mvebu_pinctrl); if (!pctl) return -ENOMEM; @@ -630,10 +628,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev) } } - pdesc = devm_kcalloc(&pdev->dev, - pctl->desc.npins, - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + pdesc = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, + pctl->desc.npins); if (!pdesc) return -ENOMEM; @@ -776,8 +772,7 @@ int mvebu_pinctrl_simple_mmio_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - mpp_data = devm_kcalloc(&pdev->dev, soc->ncontrols, sizeof(*mpp_data), - GFP_KERNEL); + mpp_data = devm_kzalloc_objs(&pdev->dev, *mpp_data, soc->ncontrols); if (!mpp_data) return -ENOMEM; @@ -828,8 +823,7 @@ int mvebu_pinctrl_simple_regmap_probe(struct platform_device *pdev, if (IS_ERR(regmap)) return PTR_ERR(regmap); - mpp_data = devm_kcalloc(&pdev->dev, soc->ncontrols, sizeof(*mpp_data), - GFP_KERNEL); + mpp_data = devm_kzalloc_objs(&pdev->dev, *mpp_data, soc->ncontrols); if (!mpp_data) return -ENOMEM; diff --git a/drivers/pinctrl/nomadik/pinctrl-abx500.c b/drivers/pinctrl/nomadik/pinctrl-abx500.c index 858fbaebcf8e51..881c87ddce7278 100644 --- a/drivers/pinctrl/nomadik/pinctrl-abx500.c +++ b/drivers/pinctrl/nomadik/pinctrl-abx500.c @@ -995,7 +995,7 @@ static int abx500_gpio_probe(struct platform_device *pdev) return -ENODEV; } - pct = devm_kzalloc(&pdev->dev, sizeof(*pct), GFP_KERNEL); + pct = devm_kzalloc_obj(&pdev->dev, *pct); if (!pct) return -ENOMEM; diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c index db0311b1413227..617ad259f62c20 100644 --- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c +++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c @@ -1215,7 +1215,7 @@ static int nmk_pinctrl_probe(struct platform_device *pdev) uintptr_t version = 0; int i; - npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL); + npct = devm_kzalloc_obj(&pdev->dev, *npct); if (!npct) return -ENOMEM; diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c index a79ebf4be2c3c5..564ec0aa4287e6 100644 --- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c +++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c @@ -535,8 +535,9 @@ static int ma35_gpiolib_register(struct platform_device *pdev, struct ma35_pinct girq->parent_handler = ma35_irq_demux_intgroup; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, + *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; @@ -588,8 +589,8 @@ static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_ ctrl = pctl->ctrl; ctrl->nr_banks = MA35_GPIO_BANK_MAX; - ctrl->pin_banks = devm_kcalloc(&pdev->dev, ctrl->nr_banks, - sizeof(*ctrl->pin_banks), GFP_KERNEL); + ctrl->pin_banks = devm_kzalloc_objs(&pdev->dev, *ctrl->pin_banks, + ctrl->nr_banks); if (!ctrl->pin_banks) return -ENOMEM; @@ -998,7 +999,7 @@ static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_ if (!count || count % 3) return -EINVAL; - elems = devm_kmalloc_array(npctl->dev, count, sizeof(u32), GFP_KERNEL); + elems = devm_kmalloc_objs(npctl->dev, u32, count); if (!elems) return -ENOMEM; @@ -1009,12 +1010,12 @@ static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_ return -EINVAL; grp->grp.npins = count / 3; - pins = devm_kcalloc(npctl->dev, grp->grp.npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(npctl->dev, *pins, grp->grp.npins); if (!pins) return -ENOMEM; grp->grp.pins = pins; - pin = devm_kcalloc(npctl->dev, grp->grp.npins, sizeof(*pin), GFP_KERNEL); + pin = devm_kzalloc_objs(npctl->dev, *pin, grp->grp.npins); if (!pin) return -ENOMEM; grp->data = pin; @@ -1053,7 +1054,7 @@ static int ma35_pinctrl_parse_functions(struct fwnode_handle *fwnode, struct ma3 if (func->ngroups <= 0) return 0; - groups = devm_kcalloc(npctl->dev, func->ngroups, sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(npctl->dev, *groups, func->ngroups); if (!groups) return -ENOMEM; @@ -1091,13 +1092,13 @@ static int ma35_pinctrl_probe_dt(struct platform_device *pdev, struct ma35_pinct if (!npctl->nfunctions) return -EINVAL; - npctl->functions = devm_kcalloc(&pdev->dev, npctl->nfunctions, - sizeof(*npctl->functions), GFP_KERNEL); + npctl->functions = devm_kzalloc_objs(&pdev->dev, *npctl->functions, + npctl->nfunctions); if (!npctl->functions) return -ENOMEM; - npctl->groups = devm_kcalloc(&pdev->dev, npctl->ngroups, - sizeof(*npctl->groups), GFP_KERNEL); + npctl->groups = devm_kzalloc_objs(&pdev->dev, *npctl->groups, + npctl->ngroups); if (!npctl->groups) return -ENOMEM; @@ -1127,15 +1128,15 @@ int ma35_pinctrl_probe(struct platform_device *pdev, const struct ma35_pinctrl_s return -EINVAL; } - npctl = devm_kzalloc(&pdev->dev, sizeof(*npctl), GFP_KERNEL); + npctl = devm_kzalloc_obj(&pdev->dev, *npctl); if (!npctl) return -ENOMEM; - ma35_pinctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*ma35_pinctrl_desc), GFP_KERNEL); + ma35_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *ma35_pinctrl_desc); if (!ma35_pinctrl_desc) return -ENOMEM; - npctl->ctrl = devm_kzalloc(&pdev->dev, sizeof(*npctl->ctrl), GFP_KERNEL); + npctl->ctrl = devm_kzalloc_obj(&pdev->dev, *npctl->ctrl); if (!npctl->ctrl) return -ENOMEM; diff --git a/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c b/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c index e051ff141d6c83..c5bdc8faa865c7 100644 --- a/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +++ b/drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c @@ -1898,9 +1898,7 @@ static int npcm7xx_gpio_register(struct npcm7xx_pinctrl *pctrl) gpio_irq_chip_set_chip(girq, &npcmgpio_irqchip); girq->parent_handler = npcmgpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(pctrl->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(pctrl->dev, *girq->parents, 1); if (!girq->parents) { ret = -ENOMEM; goto err_register; @@ -1942,7 +1940,7 @@ static int npcm7xx_pinctrl_probe(struct platform_device *pdev) struct npcm7xx_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c b/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c index 6150cde7e824e6..b695a682b4342d 100644 --- a/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c +++ b/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c @@ -2533,9 +2533,8 @@ static int npcm8xx_gpio_register(struct npcm8xx_pinctrl *pctrl) girq->chip = &pctrl->gpio_bank[id].irq_chip; girq->parent_handler = npcmgpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(pctrl->dev, girq->num_parents, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(pctrl->dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; @@ -2558,7 +2557,7 @@ static int npcm8xx_pinctrl_probe(struct platform_device *pdev) struct npcm8xx_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/nuvoton/pinctrl-wpcm450.c b/drivers/pinctrl/nuvoton/pinctrl-wpcm450.c index bc030abdadca93..5ca3a92a66e8e6 100644 --- a/drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +++ b/drivers/pinctrl/nuvoton/pinctrl-wpcm450.c @@ -1084,8 +1084,8 @@ static int wpcm450_gpio_register(struct platform_device *pdev, girq = &gpio->chip.gc.irq; gpio_irq_chip_set_chip(girq, &wpcm450_gpio_irqchip); girq->parent_handler = wpcm450_gpio_irqhandler; - girq->parents = devm_kcalloc(dev, WPCM450_NUM_GPIO_IRQS, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + WPCM450_NUM_GPIO_IRQS); if (!girq->parents) return -ENOMEM; girq->default_type = IRQ_TYPE_NONE; @@ -1119,7 +1119,7 @@ static int wpcm450_pinctrl_probe(struct platform_device *pdev) struct wpcm450_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c index 9c4ebae22674c0..e852dcde12088e 100644 --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c @@ -783,8 +783,8 @@ static int s32_pinctrl_parse_groups(struct device_node *np, grp->data.npins = npins; - pins = devm_kcalloc(info->dev, npins, sizeof(*pins), GFP_KERNEL); - sss = devm_kcalloc(info->dev, npins, sizeof(*sss), GFP_KERNEL); + pins = devm_kzalloc_objs(info->dev, *pins, npins); + sss = devm_kzalloc_objs(info->dev, *sss, npins); if (!pins || !sss) return -ENOMEM; @@ -824,8 +824,7 @@ static int s32_pinctrl_parse_functions(struct device_node *np, return dev_err_probe(info->dev, -EINVAL, "No groups defined in %pOF\n", np); - groups = devm_kcalloc(info->dev, func->ngroups, - sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(info->dev, *groups, func->ngroups); if (!groups) return -ENOMEM; @@ -864,8 +863,8 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, return -EINVAL; } - ipctl->regions = devm_kcalloc(&pdev->dev, mem_regions, - sizeof(*ipctl->regions), GFP_KERNEL); + ipctl->regions = devm_kzalloc_objs(&pdev->dev, *ipctl->regions, + mem_regions); if (!ipctl->regions) return -ENOMEM; @@ -898,8 +897,8 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, "No functions defined\n"); info->nfunctions = nfuncs; - info->functions = devm_kcalloc(&pdev->dev, nfuncs, - sizeof(*info->functions), GFP_KERNEL); + info->functions = devm_kzalloc_objs(&pdev->dev, *info->functions, + nfuncs); if (!info->functions) return -ENOMEM; @@ -907,8 +906,8 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev, for_each_child_of_node_scoped(np, child) info->ngroups += of_get_child_count(child); - info->groups = devm_kcalloc(&pdev->dev, info->ngroups, - sizeof(*info->groups), GFP_KERNEL); + info->groups = devm_kzalloc_objs(&pdev->dev, *info->groups, + info->ngroups); if (!info->groups) return -ENOMEM; @@ -937,7 +936,7 @@ int s32_pinctrl_probe(struct platform_device *pdev, return dev_err_probe(&pdev->dev, -EINVAL, "Wrong pinctrl info\n"); - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; @@ -945,7 +944,7 @@ int s32_pinctrl_probe(struct platform_device *pdev, info->dev = &pdev->dev; /* Create state holders etc for this driver */ - ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); + ipctl = devm_kzalloc_obj(&pdev->dev, *ipctl); if (!ipctl) return -ENOMEM; @@ -956,8 +955,7 @@ int s32_pinctrl_probe(struct platform_device *pdev, INIT_LIST_HEAD(&ipctl->gpio_configs); spin_lock_init(&ipctl->gpio_configs_lock); - s32_pinctrl_desc = - devm_kzalloc(&pdev->dev, sizeof(*s32_pinctrl_desc), GFP_KERNEL); + s32_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *s32_pinctrl_desc); if (!s32_pinctrl_desc) return -ENOMEM; @@ -983,9 +981,8 @@ int s32_pinctrl_probe(struct platform_device *pdev, #ifdef CONFIG_PM_SLEEP saved_context = &ipctl->saved_context; saved_context->pads = - devm_kcalloc(&pdev->dev, info->soc_data->npins, - sizeof(*saved_context->pads), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, *saved_context->pads, + info->soc_data->npins); if (!saved_context->pads) return -ENOMEM; #endif diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c index 36845517984e02..7c1f08672a3cac 100644 --- a/drivers/pinctrl/pinconf-generic.c +++ b/drivers/pinctrl/pinconf-generic.c @@ -336,8 +336,8 @@ int pinconf_generic_parse_dt_pinmux(struct device_node *np, struct device *dev, return -EINVAL; } - pid_t = devm_kcalloc(dev, npins_t, sizeof(*pid_t), GFP_KERNEL); - pmux_t = devm_kcalloc(dev, npins_t, sizeof(*pmux_t), GFP_KERNEL); + pid_t = devm_kzalloc_objs(dev, *pid_t, npins_t); + pmux_t = devm_kzalloc_objs(dev, *pmux_t, npins_t); if (!pid_t || !pmux_t) { dev_err(dev, "kalloc memory fail\n"); return -ENOMEM; @@ -392,7 +392,7 @@ int pinconf_generic_parse_dt_config(struct device_node *np, max_cfg = ARRAY_SIZE(dt_params); if (pctldev) max_cfg += pctldev->desc->num_custom_params; - cfg = kcalloc(max_cfg, sizeof(*cfg), GFP_KERNEL); + cfg = kzalloc_objs(*cfg, max_cfg); if (!cfg) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-ambarella.c b/drivers/pinctrl/pinctrl-ambarella.c index 5ed1010c5ce5b4..75d3cc2c6fdfbb 100644 --- a/drivers/pinctrl/pinctrl-ambarella.c +++ b/drivers/pinctrl/pinctrl-ambarella.c @@ -420,8 +420,7 @@ static int amb_pinctrl_register(struct amb_pinctrl *ipc) char **names; int ret; - pindesc = devm_kcalloc(ipc->dev, ipc->data->npins, sizeof(*pindesc), - GFP_KERNEL); + pindesc = devm_kzalloc_objs(ipc->dev, *pindesc, ipc->data->npins); if (!pindesc) return -ENOMEM; @@ -463,7 +462,7 @@ static int amb_pinctrl_probe(struct platform_device *pdev) struct amb_pinctrl *ipc; int ret; - ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL); + ipc = devm_kzalloc_obj(dev, *ipc); if (!ipc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c index 9fa752f552d434..30da75bb93b9a7 100644 --- a/drivers/pinctrl/pinctrl-amd.c +++ b/drivers/pinctrl/pinctrl-amd.c @@ -1279,8 +1279,7 @@ static int amd_gpio_probe(struct platform_device *pdev) struct amd_gpio *gpio_dev; struct gpio_irq_chip *girq; - gpio_dev = devm_kzalloc(&pdev->dev, - sizeof(struct amd_gpio), GFP_KERNEL); + gpio_dev = devm_kzalloc_obj(&pdev->dev, struct amd_gpio); if (!gpio_dev) return -ENOMEM; @@ -1310,9 +1309,9 @@ static int amd_gpio_probe(struct platform_device *pdev) return gpio_dev->irq; #ifdef CONFIG_SUSPEND - gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins, - sizeof(*gpio_dev->saved_regs), - GFP_KERNEL); + gpio_dev->saved_regs = devm_kzalloc_objs(&pdev->dev, + *gpio_dev->saved_regs, + amd_pinctrl_desc.npins); if (!gpio_dev->saved_regs) return -ENOMEM; #endif diff --git a/drivers/pinctrl/pinctrl-amdisp.c b/drivers/pinctrl/pinctrl-amdisp.c index e0874cc086a720..a1a84f46e04d82 100644 --- a/drivers/pinctrl/pinctrl-amdisp.c +++ b/drivers/pinctrl/pinctrl-amdisp.c @@ -178,7 +178,7 @@ static int amdisp_pinctrl_probe(struct platform_device *pdev) struct resource *res; int ret; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 6b26a23d283c54..f903d29e834447 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -412,9 +412,7 @@ static int apple_gpio_register(struct apple_gpio_pinctrl *pctl) gpio_irq_chip_set_chip(girq, &apple_gpio_irqchip); girq->parent_handler = apple_gpio_irq_handler; - girq->parents = kmalloc_array(girq->num_parents, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = kmalloc_objs(*girq->parents, girq->num_parents); irq_data = kmalloc_objs(*irq_data, girq->num_parents); if (!girq->parents || !irq_data) { ret = -ENOMEM; @@ -465,8 +463,7 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) nirqs = res; } - pctl = devm_kzalloc(&pdev->dev, struct_size(pctl, irqgrps, nirqs), - GFP_KERNEL); + pctl = devm_kzalloc_flex(&pdev->dev, *pctl, irqgrps, nirqs); if (!pctl) return -ENOMEM; pctl->dev = &pdev->dev; @@ -477,12 +474,9 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, -EINVAL, "apple,npins property not found\n"); - pins = devm_kmalloc_array(&pdev->dev, npins, sizeof(pins[0]), - GFP_KERNEL); - pin_names = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_names[0]), - GFP_KERNEL); - pin_nums = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_nums[0]), - GFP_KERNEL); + pins = devm_kmalloc_objs(&pdev->dev, pins[0], npins); + pin_names = devm_kmalloc_objs(&pdev->dev, pin_names[0], npins); + pin_nums = devm_kmalloc_objs(&pdev->dev, pin_nums[0], npins); if (!pins || !pin_names || !pin_nums) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-artpec6.c b/drivers/pinctrl/pinctrl-artpec6.c index af67057128ff1e..8c06dc73bd4f2c 100644 --- a/drivers/pinctrl/pinctrl-artpec6.c +++ b/drivers/pinctrl/pinctrl-artpec6.c @@ -937,7 +937,7 @@ static int artpec6_pmx_probe(struct platform_device *pdev) { struct artpec6_pmx *pmx; - pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(&pdev->dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-as3722.c b/drivers/pinctrl/pinctrl-as3722.c index 3d2f477aac9e03..08d1b55b014b6a 100644 --- a/drivers/pinctrl/pinctrl-as3722.c +++ b/drivers/pinctrl/pinctrl-as3722.c @@ -544,7 +544,7 @@ static int as3722_pinctrl_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - as_pci = devm_kzalloc(&pdev->dev, sizeof(*as_pci), GFP_KERNEL); + as_pci = devm_kzalloc_obj(&pdev->dev, *as_pci); if (!as_pci) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c index 41cbb46ac58907..ccddbe4646c8b0 100644 --- a/drivers/pinctrl/pinctrl-at91-pio4.c +++ b/drivers/pinctrl/pinctrl-at91-pio4.c @@ -1096,7 +1096,7 @@ static int atmel_pinctrl_probe(struct platform_device *pdev) struct atmel_pioctrl *atmel_pioctrl; const struct atmel_pioctrl_data *atmel_pioctrl_data; - atmel_pioctrl = devm_kzalloc(dev, sizeof(*atmel_pioctrl), GFP_KERNEL); + atmel_pioctrl = devm_kzalloc_obj(dev, *atmel_pioctrl); if (!atmel_pioctrl) return -ENOMEM; atmel_pioctrl->dev = dev; @@ -1124,15 +1124,12 @@ static int atmel_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(atmel_pioctrl->clk)) return dev_err_probe(dev, PTR_ERR(atmel_pioctrl->clk), "failed to get clock\n"); - atmel_pioctrl->pins = devm_kcalloc(dev, - atmel_pioctrl->npins, - sizeof(*atmel_pioctrl->pins), - GFP_KERNEL); + atmel_pioctrl->pins = devm_kzalloc_objs(dev, *atmel_pioctrl->pins, + atmel_pioctrl->npins); if (!atmel_pioctrl->pins) return -ENOMEM; - pin_desc = devm_kcalloc(dev, atmel_pioctrl->npins, sizeof(*pin_desc), - GFP_KERNEL); + pin_desc = devm_kzalloc_objs(dev, *pin_desc, atmel_pioctrl->npins); if (!pin_desc) return -ENOMEM; atmel_pinctrl_desc.pins = pin_desc; @@ -1141,16 +1138,14 @@ static int atmel_pinctrl_probe(struct platform_device *pdev) atmel_pinctrl_desc.custom_params = atmel_custom_bindings; /* One pin is one group since a pin can achieve all functions. */ - group_names = devm_kcalloc(dev, - atmel_pioctrl->npins, sizeof(*group_names), - GFP_KERNEL); + group_names = devm_kzalloc_objs(dev, *group_names, atmel_pioctrl->npins); if (!group_names) return -ENOMEM; atmel_pioctrl->group_names = group_names; - atmel_pioctrl->groups = devm_kcalloc(&pdev->dev, - atmel_pioctrl->npins, sizeof(*atmel_pioctrl->groups), - GFP_KERNEL); + atmel_pioctrl->groups = devm_kzalloc_objs(&pdev->dev, + *atmel_pioctrl->groups, + atmel_pioctrl->npins); if (!atmel_pioctrl->groups) return -ENOMEM; for (i = 0 ; i < atmel_pioctrl->npins; i++) { @@ -1158,8 +1153,8 @@ static int atmel_pinctrl_probe(struct platform_device *pdev) unsigned int bank = ATMEL_PIO_BANK(i); unsigned int line = ATMEL_PIO_LINE(i); - atmel_pioctrl->pins[i] = devm_kzalloc(dev, - sizeof(**atmel_pioctrl->pins), GFP_KERNEL); + atmel_pioctrl->pins[i] = devm_kzalloc_obj(dev, + **atmel_pioctrl->pins); if (!atmel_pioctrl->pins[i]) return -ENOMEM; @@ -1187,24 +1182,20 @@ static int atmel_pinctrl_probe(struct platform_device *pdev) atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names; atmel_pioctrl->gpio_chip->set_config = gpiochip_generic_config; - atmel_pioctrl->pm_wakeup_sources = devm_kcalloc(dev, - atmel_pioctrl->nbanks, - sizeof(*atmel_pioctrl->pm_wakeup_sources), - GFP_KERNEL); + atmel_pioctrl->pm_wakeup_sources = devm_kzalloc_objs(dev, + *atmel_pioctrl->pm_wakeup_sources, + atmel_pioctrl->nbanks); if (!atmel_pioctrl->pm_wakeup_sources) return -ENOMEM; - atmel_pioctrl->pm_suspend_backup = devm_kcalloc(dev, - atmel_pioctrl->nbanks, - sizeof(*atmel_pioctrl->pm_suspend_backup), - GFP_KERNEL); + atmel_pioctrl->pm_suspend_backup = devm_kzalloc_objs(dev, + *atmel_pioctrl->pm_suspend_backup, + atmel_pioctrl->nbanks); if (!atmel_pioctrl->pm_suspend_backup) return -ENOMEM; - atmel_pioctrl->irqs = devm_kcalloc(dev, - atmel_pioctrl->nbanks, - sizeof(*atmel_pioctrl->irqs), - GFP_KERNEL); + atmel_pioctrl->irqs = devm_kzalloc_objs(dev, *atmel_pioctrl->irqs, + atmel_pioctrl->nbanks); if (!atmel_pioctrl->irqs) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c index 0a57ed51d4c98d..cf8fe3fa545bc7 100644 --- a/drivers/pinctrl/pinctrl-at91.c +++ b/drivers/pinctrl/pinctrl-at91.c @@ -308,8 +308,7 @@ static int at91_dt_node_to_map(struct pinctrl_dev *pctldev, } map_num += grp->npins; - new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map), - GFP_KERNEL); + new_map = devm_kzalloc_objs(pctldev->dev, *new_map, map_num); if (!new_map) return -ENOMEM; @@ -1218,12 +1217,9 @@ static int at91_pinctrl_parse_groups(struct device_node *np, } grp->npins = size / 4; - pin = grp->pins_conf = devm_kcalloc(info->dev, - grp->npins, - sizeof(struct at91_pmx_pin), - GFP_KERNEL); - grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int), - GFP_KERNEL); + pin = grp->pins_conf = devm_kzalloc_objs(info->dev, struct at91_pmx_pin, + grp->npins); + grp->pins = devm_kzalloc_objs(info->dev, unsigned int, grp->npins); if (!grp->pins_conf || !grp->pins) return -ENOMEM; @@ -1329,13 +1325,12 @@ static int at91_pinctrl_probe_dt(struct platform_device *pdev, dev_dbg(dev, "nfunctions = %d\n", info->nfunctions); dev_dbg(dev, "ngroups = %d\n", info->ngroups); - info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), - GFP_KERNEL); + info->functions = devm_kzalloc_objs(dev, *info->functions, + info->nfunctions); if (!info->functions) return -ENOMEM; - info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), - GFP_KERNEL); + info->groups = devm_kzalloc_objs(dev, *info->groups, info->ngroups); if (!info->groups) return -ENOMEM; @@ -1363,7 +1358,7 @@ static int at91_pinctrl_probe(struct platform_device *pdev) struct pinctrl_pin_desc *pdesc; int ret, i, j, k; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; @@ -1374,7 +1369,7 @@ static int at91_pinctrl_probe(struct platform_device *pdev) at91_pinctrl_desc.name = dev_name(dev); at91_pinctrl_desc.npins = gpio_banks * MAX_NB_GPIO_PER_BANK; at91_pinctrl_desc.pins = pdesc = - devm_kcalloc(dev, at91_pinctrl_desc.npins, sizeof(*pdesc), GFP_KERNEL); + devm_kzalloc_objs(dev, *pdesc, at91_pinctrl_desc.npins); if (!at91_pinctrl_desc.pins) return -ENOMEM; @@ -1731,7 +1726,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev, struct gpio_irq_chip *girq; int i; - gpio_irqchip = devm_kzalloc(dev, sizeof(*gpio_irqchip), GFP_KERNEL); + gpio_irqchip = devm_kzalloc_obj(dev, *gpio_irqchip); if (!gpio_irqchip) return -ENOMEM; @@ -1770,9 +1765,8 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev, if (!gpiochip_prev) { girq->parent_handler = gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, girq->num_parents, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; girq->parents[0] = at91_gpio->pioc_virq; @@ -1840,7 +1834,7 @@ static int at91_gpio_probe(struct platform_device *pdev) if (irq < 0) return irq; - at91_chip = devm_kzalloc(dev, sizeof(*at91_chip), GFP_KERNEL); + at91_chip = devm_kzalloc_obj(dev, *at91_chip); if (!at91_chip) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-aw9523.c b/drivers/pinctrl/pinctrl-aw9523.c index a13b1cdb78eac6..58292236cf4608 100644 --- a/drivers/pinctrl/pinctrl-aw9523.c +++ b/drivers/pinctrl/pinctrl-aw9523.c @@ -808,7 +808,7 @@ static int aw9523_init_irq(struct aw9523 *awi, int irq) if (!device_property_read_bool(dev, "interrupt-controller")) return 0; - awi->irq = devm_kzalloc(dev, sizeof(*awi->irq), GFP_KERNEL); + awi->irq = devm_kzalloc_obj(dev, *awi->irq); if (!awi->irq) return -ENOMEM; @@ -955,7 +955,7 @@ static int aw9523_probe(struct i2c_client *client) struct aw9523 *awi; int ret; - awi = devm_kzalloc(dev, sizeof(*awi), GFP_KERNEL); + awi = devm_kzalloc_obj(dev, *awi); if (!awi) return -ENOMEM; @@ -981,7 +981,7 @@ static int aw9523_probe(struct i2c_client *client) lockdep_set_subclass(&awi->i2c_lock, i2c_adapter_depth(client->adapter)); - pdesc = devm_kzalloc(dev, sizeof(*pdesc), GFP_KERNEL); + pdesc = devm_kzalloc_obj(dev, *pdesc); if (!pdesc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c index 5539ce642b3976..825e9b50bc2688 100644 --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -447,7 +447,7 @@ static int axp20x_pctl_probe(struct platform_device *pdev) return -EINVAL; } - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; @@ -479,7 +479,7 @@ static int axp20x_pctl_probe(struct platform_device *pdev) return ret; } - pctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctrl_desc), GFP_KERNEL); + pctrl_desc = devm_kzalloc_obj(&pdev->dev, *pctrl_desc); if (!pctrl_desc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-bm1880.c b/drivers/pinctrl/pinctrl-bm1880.c index 387798fb09be51..8cd7fc4b5b20d6 100644 --- a/drivers/pinctrl/pinctrl-bm1880.c +++ b/drivers/pinctrl/pinctrl-bm1880.c @@ -1313,7 +1313,7 @@ static int bm1880_pinctrl_probe(struct platform_device *pdev) { struct bm1880_pinctrl *pctrl; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index 9a54b259ef4b70..62f3360a54b759 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -1377,7 +1377,7 @@ static int cy8c95x0_probe(struct i2c_client *client) unsigned long driver_data; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-da850-pupd.c b/drivers/pinctrl/pinctrl-da850-pupd.c index c5f243d1311f9f..12e2e39c02bd45 100644 --- a/drivers/pinctrl/pinctrl-da850-pupd.c +++ b/drivers/pinctrl/pinctrl-da850-pupd.c @@ -146,7 +146,7 @@ static int da850_pupd_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct da850_pupd_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-da9062.c b/drivers/pinctrl/pinctrl-da9062.c index 53298cbcc5cfd3..ab62b802bae35d 100644 --- a/drivers/pinctrl/pinctrl-da9062.c +++ b/drivers/pinctrl/pinctrl-da9062.c @@ -252,7 +252,7 @@ static int da9062_pctl_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-digicolor.c b/drivers/pinctrl/pinctrl-digicolor.c index 58f22b4a5a6f17..53dc9c82c9c771 100644 --- a/drivers/pinctrl/pinctrl-digicolor.c +++ b/drivers/pinctrl/pinctrl-digicolor.c @@ -276,7 +276,7 @@ static int dc_pinctrl_probe(struct platform_device *pdev) int name_len = strlen("GP_xx") + 1; int i, j; - pmap = devm_kzalloc(&pdev->dev, sizeof(*pmap), GFP_KERNEL); + pmap = devm_kzalloc_obj(&pdev->dev, *pmap); if (!pmap) return -ENOMEM; @@ -284,8 +284,7 @@ static int dc_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(pmap->regs)) return PTR_ERR(pmap->regs); - pins = devm_kcalloc(&pdev->dev, PINS_COUNT, sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, PINS_COUNT); if (!pins) return -ENOMEM; pin_names = devm_kcalloc(&pdev->dev, PINS_COUNT, name_len, @@ -306,7 +305,7 @@ static int dc_pinctrl_probe(struct platform_device *pdev) } } - pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL); + pctl_desc = devm_kzalloc_obj(&pdev->dev, *pctl_desc); if (!pctl_desc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-eic7700.c b/drivers/pinctrl/pinctrl-eic7700.c index 09a3b097383cbb..20baf5012ca5f2 100644 --- a/drivers/pinctrl/pinctrl-eic7700.c +++ b/drivers/pinctrl/pinctrl-eic7700.c @@ -579,7 +579,7 @@ static int eic7700_pinctrl_init_function_groups(struct device *dev, struct eic77 } } - groups = devm_kcalloc(dev, ngroups, sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(dev, *groups, ngroups); if (!groups) return -ENOMEM; @@ -627,7 +627,7 @@ static int eic7700_pinctrl_probe(struct platform_device *pdev) u32 rgmii0_mode, rgmii1_mode; int ret, voltage; - pc = devm_kzalloc(dev, struct_size(pc, functions, EIC7700_FUNCTIONS_COUNT), GFP_KERNEL); + pc = devm_kzalloc_flex(dev, *pc, functions, EIC7700_FUNCTIONS_COUNT); if (!pc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-ep93xx.c b/drivers/pinctrl/pinctrl-ep93xx.c index abafbbb8fd6a50..b357aa2c138edb 100644 --- a/drivers/pinctrl/pinctrl-ep93xx.c +++ b/drivers/pinctrl/pinctrl-ep93xx.c @@ -1373,7 +1373,7 @@ static int ep93xx_pmx_probe(struct auxiliary_device *adev, struct ep93xx_pmx *pmx; /* Create state holders etc for this driver */ - pmx = devm_kzalloc(dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-equilibrium.c b/drivers/pinctrl/pinctrl-equilibrium.c index 8e6cd35fc80cc7..efeaa8733b5664 100644 --- a/drivers/pinctrl/pinctrl-equilibrium.c +++ b/drivers/pinctrl/pinctrl-equilibrium.c @@ -203,7 +203,7 @@ static int gpiochip_setup(struct device *dev, struct eqbr_gpio_ctrl *gctrl) gpio_irq_chip_set_chip(girq, &eqbr_irq_chip); girq->parent_handler = eqbr_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; @@ -669,7 +669,7 @@ static int eqbr_build_functions(struct eqbr_pinctrl_drv_data *drvdata) if (ret) return ret; - funcs = devm_kcalloc(dev, nr_funcs, sizeof(*funcs), GFP_KERNEL); + funcs = devm_kzalloc_objs(dev, *funcs, nr_funcs); if (!funcs) return -ENOMEM; @@ -684,9 +684,8 @@ static int eqbr_build_functions(struct eqbr_pinctrl_drv_data *drvdata) for (i = 0; i < nr_funcs; i++) { if (!funcs[i].ngroups) continue; - funcs[i].groups = devm_kcalloc(dev, funcs[i].ngroups, - sizeof(*(funcs[i].groups)), - GFP_KERNEL); + funcs[i].groups = devm_kzalloc_objs(dev, *(funcs[i].groups), + funcs[i].ngroups); if (!funcs[i].groups) return -ENOMEM; } @@ -734,13 +733,13 @@ static int eqbr_build_groups(struct eqbr_pinctrl_drv_data *drvdata) } grp->npins = err; grp->name = prop->value; - pins = devm_kcalloc(dev, grp->npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, grp->npins); if (!pins) return -ENOMEM; grp->pins = pins; - pinmux = devm_kcalloc(dev, grp->npins, sizeof(*pinmux), GFP_KERNEL); + pinmux = devm_kzalloc_objs(dev, *pinmux, grp->npins); if (!pinmux) return -ENOMEM; @@ -799,7 +798,7 @@ static int pinctrl_reg(struct eqbr_pinctrl_drv_data *drvdata) for (i = 0, nr_pins = 0; i < drvdata->nr_banks; i++) nr_pins += drvdata->pin_banks[i].nr_pins; - pdesc = devm_kcalloc(dev, nr_pins, sizeof(*pdesc), GFP_KERNEL); + pdesc = devm_kzalloc_objs(dev, *pdesc, nr_pins); if (!pdesc) return -ENOMEM; pin_names = devm_kcalloc(dev, nr_pins, PIN_NAME_LEN, GFP_KERNEL); @@ -887,11 +886,11 @@ static int pinbank_probe(struct eqbr_pinctrl_drv_data *drvdata) } /* Count pin bank number and gpio controller number */ - banks = devm_kcalloc(dev, nr_gpio, sizeof(*banks), GFP_KERNEL); + banks = devm_kzalloc_objs(dev, *banks, nr_gpio); if (!banks) return -ENOMEM; - gctrls = devm_kcalloc(dev, nr_gpio, sizeof(*gctrls), GFP_KERNEL); + gctrls = devm_kzalloc_objs(dev, *gctrls, nr_gpio); if (!gctrls) return -ENOMEM; @@ -924,7 +923,7 @@ static int eqbr_pinctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-eyeq5.c b/drivers/pinctrl/pinctrl-eyeq5.c index 19d845b4793984..852fc67bc7c2f0 100644 --- a/drivers/pinctrl/pinctrl-eyeq5.c +++ b/drivers/pinctrl/pinctrl-eyeq5.c @@ -705,7 +705,7 @@ static int eq5p_probe(struct auxiliary_device *adev, if (!match || !match->data) return -ENODEV; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-gemini.c b/drivers/pinctrl/pinctrl-gemini.c index a029cab229bf3a..85f1b6dcec4a2e 100644 --- a/drivers/pinctrl/pinctrl-gemini.c +++ b/drivers/pinctrl/pinctrl-gemini.c @@ -2536,7 +2536,7 @@ static int gemini_pmx_probe(struct platform_device *pdev) int i; /* Create state holders etc for this driver */ - pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(&pdev->dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-generic-mux.c b/drivers/pinctrl/pinctrl-generic-mux.c index de85b4e75eb80d..2936acb30cc3e7 100644 --- a/drivers/pinctrl/pinctrl-generic-mux.c +++ b/drivers/pinctrl/pinctrl-generic-mux.c @@ -72,11 +72,11 @@ static int mux_pinctrl_probe_dt(struct pinctrl_dev *pctldev, const char **group_names; int ret; - function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL); + function = devm_kzalloc_obj(dev, *function); if (!function) return -ENOMEM; - group_names = devm_kcalloc(dev, 1, sizeof(*group_names), GFP_KERNEL); + group_names = devm_kzalloc_objs(dev, *group_names, 1); if (!group_names) return -ENOMEM; @@ -163,7 +163,7 @@ static int mux_pinctrl_probe(struct platform_device *pdev) struct pinctrl_desc *pctl_desc; int ret; - mpctl = devm_kzalloc(dev, sizeof(*mpctl), GFP_KERNEL); + mpctl = devm_kzalloc_obj(dev, *mpctl); if (!mpctl) return -ENOMEM; @@ -171,7 +171,7 @@ static int mux_pinctrl_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mpctl); - pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL); + pctl_desc = devm_kzalloc_obj(dev, *pctl_desc); if (!pctl_desc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-generic.c b/drivers/pinctrl/pinctrl-generic.c index 4277c87485135c..7b0eaf72c7f991 100644 --- a/drivers/pinctrl/pinctrl-generic.c +++ b/drivers/pinctrl/pinctrl-generic.c @@ -107,11 +107,11 @@ static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_dev *p return npins; } - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) return -ENOMEM; - functions = devm_kcalloc(dev, npins, sizeof(*functions), GFP_KERNEL); + functions = devm_kzalloc_objs(dev, *functions, npins); if (!functions) return -ENOMEM; @@ -153,11 +153,11 @@ static int pinctrl_generic_pinmux_dt_subnode_to_map(struct pinctrl_dev *pctldev, return npins; } - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) return -ENOMEM; - muxes = devm_kcalloc(dev, npins, sizeof(*muxes), GFP_KERNEL); + muxes = devm_kzalloc_objs(dev, *muxes, npins); if (!muxes) return -ENOMEM; @@ -210,7 +210,7 @@ static int pinctrl_generic_dt_node_to_map(struct pinctrl_dev *pctldev, if (!of_property_present(np, "pins")) goto parent; - group_names = devm_kcalloc(dev, 1, sizeof(*group_names), GFP_KERNEL); + group_names = devm_kzalloc_objs(dev, *group_names, 1); if (!group_names) return -ENOMEM; @@ -233,7 +233,7 @@ static int pinctrl_generic_dt_node_to_map(struct pinctrl_dev *pctldev, for_each_available_child_of_node(np, child_np) ngroups += 1; - group_names = devm_kcalloc(dev, ngroups, sizeof(*group_names), GFP_KERNEL); + group_names = devm_kzalloc_objs(dev, *group_names, ngroups); if (!group_names) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c index 1aa6a6dc12095e..e2c3ac8c12422e 100644 --- a/drivers/pinctrl/pinctrl-ingenic.c +++ b/drivers/pinctrl/pinctrl-ingenic.c @@ -4424,7 +4424,7 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc, return err; } - jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL); + jzgc = devm_kzalloc_obj(dev, *jzgc); if (!jzgc) return -ENOMEM; @@ -4467,8 +4467,7 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc, gpio_irq_chip_set_chip(girq, &ingenic_gpio_irqchip); girq->parent_handler = ingenic_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; @@ -4501,7 +4500,7 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) return -EINVAL; } - jzpc = devm_kzalloc(dev, sizeof(*jzpc), GFP_KERNEL); + jzpc = devm_kzalloc_obj(dev, *jzpc); if (!jzpc) return -ENOMEM; @@ -4526,7 +4525,7 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) jzpc->dev = dev; jzpc->info = chip_info; - pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL); + pctl_desc = devm_kzalloc_obj(&pdev->dev, *pctl_desc); if (!pctl_desc) return -ENOMEM; @@ -4537,8 +4536,9 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev) pctl_desc->pmxops = &ingenic_pmxops; pctl_desc->confops = &ingenic_confops; pctl_desc->npins = chip_info->num_chips * PINS_PER_GPIO_CHIP; - pctl_desc->pins = jzpc->pdesc = devm_kcalloc(&pdev->dev, - pctl_desc->npins, sizeof(*jzpc->pdesc), GFP_KERNEL); + pctl_desc->pins = jzpc->pdesc = devm_kzalloc_objs(&pdev->dev, + *jzpc->pdesc, + pctl_desc->npins); if (!jzpc->pdesc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-k210.c b/drivers/pinctrl/pinctrl-k210.c index ddd6d6bfd51399..ab01bdbdbb973c 100644 --- a/drivers/pinctrl/pinctrl-k210.c +++ b/drivers/pinctrl/pinctrl-k210.c @@ -927,7 +927,7 @@ static int k210_fpioa_probe(struct platform_device *pdev) dev_info(dev, "K210 FPIOA pin controller\n"); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-k230.c b/drivers/pinctrl/pinctrl-k230.c index 886577abf0d05a..668bb3c4dfbdb8 100644 --- a/drivers/pinctrl/pinctrl-k230.c +++ b/drivers/pinctrl/pinctrl-k230.c @@ -485,10 +485,8 @@ static int k230_pinctrl_parse_groups(struct device_node *np, size /= sizeof(*list); grp->num_pins = size; - grp->pins = devm_kcalloc(dev, grp->num_pins, sizeof(*grp->pins), - GFP_KERNEL); - grp->data = devm_kcalloc(dev, grp->num_pins, sizeof(*grp->data), - GFP_KERNEL); + grp->pins = devm_kzalloc_objs(dev, *grp->pins, grp->num_pins); + grp->data = devm_kzalloc_objs(dev, *grp->data, grp->num_pins); if (!grp->pins || !grp->data) return -ENOMEM; @@ -525,10 +523,9 @@ static int k230_pinctrl_parse_functions(struct device_node *np, if (func->ngroups <= 0) return 0; - func->groups = devm_kcalloc(dev, func->ngroups, - sizeof(*func->groups), GFP_KERNEL); - func->group_idx = devm_kcalloc(dev, func->ngroups, - sizeof(*func->group_idx), GFP_KERNEL); + func->groups = devm_kzalloc_objs(dev, *func->groups, func->ngroups); + func->group_idx = devm_kzalloc_objs(dev, *func->group_idx, + func->ngroups); if (!func->groups || !func->group_idx) return -ENOMEM; @@ -566,10 +563,9 @@ static int k230_pinctrl_parse_dt(struct platform_device *pdev, k230_pinctrl_child_count(info, np); - info->functions = devm_kcalloc(dev, info->nfunctions, - sizeof(*info->functions), GFP_KERNEL); - info->groups = devm_kcalloc(dev, info->ngroups, - sizeof(*info->groups), GFP_KERNEL); + info->functions = devm_kzalloc_objs(dev, *info->functions, + info->nfunctions); + info->groups = devm_kzalloc_objs(dev, *info->groups, info->ngroups); if (!info->functions || !info->groups) return -ENOMEM; @@ -593,7 +589,7 @@ static int k230_pinctrl_probe(struct platform_device *pdev) struct pinctrl_desc *pctl; int ret; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c index 3241d3ae621917..c6a00f55c0fd23 100644 --- a/drivers/pinctrl/pinctrl-keembay.c +++ b/drivers/pinctrl/pinctrl-keembay.c @@ -1471,8 +1471,9 @@ static int keembay_gpiochip_probe(struct keembay_pinctrl *kpc, girq->chip = &keembay_gpio_irqchip; girq->parent_handler = keembay_gpio_irq_handler; girq->num_parents = KEEMBAY_GPIO_NUM_IRQ; - girq->parents = devm_kcalloc(kpc->dev, girq->num_parents, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents = devm_kzalloc_objs(kpc->dev, + *girq->parents, + girq->num_parents); if (!girq->parents) return -ENOMEM; @@ -1527,7 +1528,7 @@ static int keembay_build_groups(struct keembay_pinctrl *kpc) unsigned int i; kpc->ngroups = kpc->npins; - grp = devm_kcalloc(kpc->dev, kpc->ngroups, sizeof(*grp), GFP_KERNEL); + grp = devm_kzalloc_objs(kpc->dev, *grp, kpc->ngroups); if (!grp) return -ENOMEM; @@ -1572,8 +1573,8 @@ static int keembay_add_functions(struct keembay_pinctrl *kpc, unsigned int grp_idx = 0; int j; - group_names = devm_kcalloc(kpc->dev, func->func.ngroups, - sizeof(*group_names), GFP_KERNEL); + group_names = devm_kzalloc_objs(kpc->dev, *group_names, + func->func.ngroups); if (!group_names) return -ENOMEM; @@ -1608,8 +1609,8 @@ static int keembay_build_functions(struct keembay_pinctrl *kpc) * being part of 8 (hw maximum) globally unique muxes. */ kpc->nfuncs = 0; - keembay_funcs = devm_kcalloc(kpc->dev, kpc->npins * 8, - sizeof(*keembay_funcs), GFP_KERNEL); + keembay_funcs = devm_kzalloc_objs(kpc->dev, *keembay_funcs, + kpc->npins * 8); if (!keembay_funcs) return -ENOMEM; @@ -1665,7 +1666,7 @@ static int keembay_pinctrl_probe(struct platform_device *pdev) struct keembay_pinctrl *kpc; int ret; - kpc = devm_kzalloc(dev, sizeof(*kpc), GFP_KERNEL); + kpc = devm_kzalloc_obj(dev, *kpc); if (!kpc) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-loongson2.c b/drivers/pinctrl/pinctrl-loongson2.c index 7d04fa81d2e5e2..d7da828b749730 100644 --- a/drivers/pinctrl/pinctrl-loongson2.c +++ b/drivers/pinctrl/pinctrl-loongson2.c @@ -253,7 +253,7 @@ static int loongson2_pinctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct loongson2_pinctrl *pctrl; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c index 9431810ffaff37..b154cd22aaefb9 100644 --- a/drivers/pinctrl/pinctrl-lpc18xx.c +++ b/drivers/pinctrl/pinctrl-lpc18xx.c @@ -1327,7 +1327,7 @@ static int lpc18xx_scu_probe(struct platform_device *pdev) struct lpc18xx_scu_data *scu; int ret; - scu = devm_kzalloc(&pdev->dev, sizeof(*scu), GFP_KERNEL); + scu = devm_kzalloc_obj(&pdev->dev, *scu); if (!scu) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-max7360.c b/drivers/pinctrl/pinctrl-max7360.c index abfaff468bad1f..fdf2ac8276af59 100644 --- a/drivers/pinctrl/pinctrl-max7360.c +++ b/drivers/pinctrl/pinctrl-max7360.c @@ -173,7 +173,7 @@ static int max7360_pinctrl_probe(struct platform_device *pdev) if (!regmap) return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-max77620.c b/drivers/pinctrl/pinctrl-max77620.c index 0fa28d697e8c11..b181cde6d7c5e2 100644 --- a/drivers/pinctrl/pinctrl-max77620.c +++ b/drivers/pinctrl/pinctrl-max77620.c @@ -556,7 +556,7 @@ static int max77620_pinctrl_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - mpci = devm_kzalloc(&pdev->dev, sizeof(*mpci), GFP_KERNEL); + mpci = devm_kzalloc_obj(&pdev->dev, *mpci); if (!mpci) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c index 928b665318580b..21b7147ffef778 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c +++ b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c @@ -14,7 +14,7 @@ static int mcp230xx_probe(struct i2c_client *client) struct mcp23s08 *mcp; int ret; - mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL); + mcp = devm_kzalloc_obj(dev, *mcp); if (!mcp) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c index bacebcff67ef25..a2e9a3b714ef20 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c @@ -164,7 +164,7 @@ static int mcp23s08_probe(struct spi_device *spi) chips = hweight_long(spi_present_mask); - data = devm_kzalloc(dev, struct_size(data, chip, chips), GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, chip, chips); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c index aa0f7c809978df..7ffc34240dc595 100644 --- a/drivers/pinctrl/pinctrl-microchip-sgpio.c +++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c @@ -821,7 +821,7 @@ static int microchip_sgpio_register_bank(struct device *dev, pctl_desc->confops = &sgpio_confops; pctl_desc->owner = THIS_MODULE; - pins = devm_kcalloc(dev, ngpios, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, ngpios); if (!pins) return -ENOMEM; @@ -874,9 +874,8 @@ static int microchip_sgpio_register_bank(struct device *dev, gpio_irq_chip_set_chip(girq, µchip_sgpio_irqchip); girq->parent_handler = sgpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, + 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; @@ -913,7 +912,7 @@ static int microchip_sgpio_probe(struct platform_device *pdev) .reg_stride = 4, }; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-mlxbf3.c b/drivers/pinctrl/pinctrl-mlxbf3.c index 1b285c9ee05ae5..a5882748866412 100644 --- a/drivers/pinctrl/pinctrl-mlxbf3.c +++ b/drivers/pinctrl/pinctrl-mlxbf3.c @@ -247,7 +247,7 @@ static int mlxbf3_pinctrl_probe(struct platform_device *pdev) struct mlxbf3_pinctrl *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c index 58d3cde9f964da..4cf7b36cc0e410 100644 --- a/drivers/pinctrl/pinctrl-ocelot.c +++ b/drivers/pinctrl/pinctrl-ocelot.c @@ -2374,9 +2374,7 @@ static int ocelot_gpiochip_register(struct platform_device *pdev, gpio_irq_chip_set_chip(girq, &ocelot_irqchip); girq->parent_handler = ocelot_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; @@ -2442,7 +2440,7 @@ static int ocelot_pinctrl_probe(struct platform_device *pdev) .reg_stride = 4, }; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-palmas.c b/drivers/pinctrl/pinctrl-palmas.c index d69f114e46426c..d436b5baecad6f 100644 --- a/drivers/pinctrl/pinctrl-palmas.c +++ b/drivers/pinctrl/pinctrl-palmas.c @@ -999,7 +999,7 @@ static int palmas_pinctrl_probe(struct platform_device *pdev) "ti,palmas-enable-dvfs2"); } - pci = devm_kzalloc(&pdev->dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(&pdev->dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-pef2256.c b/drivers/pinctrl/pinctrl-pef2256.c index 868ea33bec3c0a..70101e3757dbdf 100644 --- a/drivers/pinctrl/pinctrl-pef2256.c +++ b/drivers/pinctrl/pinctrl-pef2256.c @@ -323,7 +323,7 @@ static int pef2256_pinctrl_probe(struct platform_device *pdev) struct pef2256 *pef2256; int ret; - pef2256_pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pef2256_pinctrl), GFP_KERNEL); + pef2256_pinctrl = devm_kzalloc_obj(&pdev->dev, *pef2256_pinctrl); if (!pef2256_pinctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-pic32.c b/drivers/pinctrl/pinctrl-pic32.c index 07a24e17d35b21..617008af9b5874 100644 --- a/drivers/pinctrl/pinctrl-pic32.c +++ b/drivers/pinctrl/pinctrl-pic32.c @@ -2164,7 +2164,7 @@ static int pic32_pinctrl_probe(struct platform_device *pdev) struct pic32_pinctrl *pctl; int ret; - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; pctl->dev = &pdev->dev; @@ -2246,8 +2246,7 @@ static int pic32_gpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &pic32_gpio_irq_chip); girq->parent_handler = pic32_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->default_type = IRQ_TYPE_NONE; diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c index cc5cd2a538c5a9..e2f30b48beb54e 100644 --- a/drivers/pinctrl/pinctrl-pistachio.c +++ b/drivers/pinctrl/pinctrl-pistachio.c @@ -1410,9 +1410,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl) gpio_irq_chip_set_chip(girq, &pistachio_gpio_irq_chip); girq->parent_handler = pistachio_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(pctl->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(pctl->dev, *girq->parents, 1); if (!girq->parents) { ret = -ENOMEM; goto err; @@ -1457,7 +1455,7 @@ static int pistachio_pinctrl_probe(struct platform_device *pdev) { struct pistachio_pinctrl *pctl; - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; pctl->dev = &pdev->dev; diff --git a/drivers/pinctrl/pinctrl-rk805.c b/drivers/pinctrl/pinctrl-rk805.c index 22f576337faa9c..24e76b4d919bbd 100644 --- a/drivers/pinctrl/pinctrl-rk805.c +++ b/drivers/pinctrl/pinctrl-rk805.c @@ -607,7 +607,7 @@ static int rk805_pinctrl_probe(struct platform_device *pdev) device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); - pci = devm_kzalloc(&pdev->dev, sizeof(*pci), GFP_KERNEL); + pci = devm_kzalloc_obj(&pdev->dev, *pci); if (!pci) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index ba47b6f323ccc3..ee03c9f064b2b5 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -4346,8 +4346,8 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np, grp->npins = size / 4; - grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL); - grp->data = devm_kcalloc(dev, grp->npins, sizeof(*grp->data), GFP_KERNEL); + grp->pins = devm_kzalloc_objs(dev, *grp->pins, grp->npins); + grp->data = devm_kzalloc_objs(dev, *grp->data, grp->npins); if (!grp->pins || !grp->data) return -ENOMEM; @@ -4399,7 +4399,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np, if (func->ngroups <= 0) return 0; - func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL); + func->groups = devm_kzalloc_objs(dev, *func->groups, func->ngroups); if (!func->groups) return -ENOMEM; @@ -4427,11 +4427,12 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev, dev_dbg(dev, "nfunctions = %d\n", info->nfunctions); dev_dbg(dev, "ngroups = %d\n", info->ngroups); - info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL); + info->functions = devm_kzalloc_objs(dev, *info->functions, + info->nfunctions); if (!info->functions) return -ENOMEM; - info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL); + info->groups = devm_kzalloc_objs(dev, *info->groups, info->ngroups); if (!info->groups) return -ENOMEM; @@ -4468,7 +4469,7 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, ctrldesc->pmxops = &rockchip_pmx_ops; ctrldesc->confops = &rockchip_pinconf_ops; - pindesc = devm_kcalloc(dev, info->ctrl->nr_pins, sizeof(*pindesc), GFP_KERNEL); + pindesc = devm_kzalloc_objs(dev, *pindesc, info->ctrl->nr_pins); if (!pindesc) return -ENOMEM; @@ -4775,7 +4776,7 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) if (!dev->of_node) return dev_err_probe(dev, -ENODEV, "device tree node not found\n"); - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-scmi.c b/drivers/pinctrl/pinctrl-scmi.c index c93d61dfa28227..43d5f3d54a8a0a 100644 --- a/drivers/pinctrl/pinctrl-scmi.c +++ b/drivers/pinctrl/pinctrl-scmi.c @@ -216,7 +216,7 @@ pinctrl_scmi_alloc_configs(struct pinctrl_dev *pctldev, u32 num_configs, if (num_configs <= SCMI_NUM_CONFIGS) return 0; - *p_config_value = kcalloc(num_configs, sizeof(**p_config_value), GFP_KERNEL); + *p_config_value = kzalloc_objs(**p_config_value, num_configs); if (!*p_config_value) return -ENOMEM; @@ -400,8 +400,7 @@ static int pinctrl_scmi_get_functions(struct scmi_pinctrl *pmx) "Function %s contains no groups\n", fname); - gnames = devm_kmalloc_array(pmx->dev, nr_groups, - sizeof(*gnames), GFP_KERNEL); + gnames = devm_kmalloc_objs(pmx->dev, *gnames, nr_groups); if (!gnames) return -ENOMEM; @@ -477,7 +476,7 @@ static int pinctrl_scmi_get_pins(struct scmi_pinctrl *pmx, * npins will never be zero, the scmi pinctrl driver has bailed out * if npins is zero. */ - pins = devm_kmalloc_array(pmx->dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kmalloc_objs(pmx->dev, *pins, npins); if (!pins) return -ENOMEM; @@ -527,7 +526,7 @@ static int scmi_pinctrl_probe(struct scmi_device *sdev) if (IS_ERR(pinctrl_ops)) return PTR_ERR(pinctrl_ops); - pmx = devm_kzalloc(dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index e0eb7240a98595..10f52a7a52c1cf 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -744,9 +744,7 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs) } dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins); - pcs->pins.pa = devm_kcalloc(pcs->dev, - nr_pins, sizeof(*pcs->pins.pa), - GFP_KERNEL); + pcs->pins.pa = devm_kzalloc_objs(pcs->dev, *pcs->pins.pa, nr_pins); if (!pcs->pins.pa) return -ENOMEM; @@ -791,7 +789,7 @@ static int pcs_add_function(struct pcs_device *pcs, struct pcs_function *function; int selector; - function = devm_kzalloc(pcs->dev, sizeof(*function), GFP_KERNEL); + function = devm_kzalloc_obj(pcs->dev, *function); if (!function) return -ENOMEM; @@ -956,16 +954,13 @@ static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np, if (!nconfs) return -ENOTSUPP; - func->conf = devm_kcalloc(pcs->dev, - nconfs, sizeof(struct pcs_conf_vals), - GFP_KERNEL); + func->conf = devm_kzalloc_objs(pcs->dev, struct pcs_conf_vals, nconfs); if (!func->conf) return -ENOMEM; func->nconfs = nconfs; conf = &(func->conf[0]); m++; - settings = devm_kcalloc(pcs->dev, nconfs, sizeof(unsigned long), - GFP_KERNEL); + settings = devm_kzalloc_objs(pcs->dev, unsigned long, nconfs); if (!settings) return -ENOMEM; s = &settings[0]; @@ -1019,11 +1014,11 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs, return -EINVAL; } - vals = devm_kcalloc(pcs->dev, rows, sizeof(*vals), GFP_KERNEL); + vals = devm_kzalloc_objs(pcs->dev, *vals, rows); if (!vals) return -ENOMEM; - pins = devm_kcalloc(pcs->dev, rows, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(pcs->dev, *pins, rows); if (!pins) goto free_vals; @@ -1268,13 +1263,13 @@ static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev, pcs = pinctrl_dev_get_drvdata(pctldev); /* create 2 maps. One is for pinmux, and the other is for pinconf. */ - *map = devm_kcalloc(pcs->dev, 2, sizeof(**map), GFP_KERNEL); + *map = devm_kzalloc_objs(pcs->dev, **map, 2); if (!*map) return -ENOMEM; *num_maps = 0; - pgnames = devm_kzalloc(pcs->dev, sizeof(*pgnames), GFP_KERNEL); + pgnames = devm_kzalloc_obj(pcs->dev, *pgnames); if (!pgnames) { ret = -ENOMEM; goto free_map; @@ -1358,7 +1353,7 @@ static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs) ret = 0; break; } - range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL); + range = devm_kzalloc_obj(pcs->dev, *range); if (!range) { of_node_put(gpiospec.np); ret = -ENOMEM; @@ -1547,7 +1542,7 @@ static int pcs_irqdomain_map(struct irq_domain *d, unsigned int irq, struct pcs_interrupt *pcswi; pcs = container_of(pcs_soc, struct pcs_device, socdata); - pcswi = devm_kzalloc(pcs->dev, sizeof(*pcswi), GFP_KERNEL); + pcswi = devm_kzalloc_obj(pcs->dev, *pcswi); if (!pcswi) return -ENOMEM; @@ -1755,12 +1750,12 @@ static int pcs_quirk_missing_pinctrl_cells(struct pcs_device *pcs, dev_warn(pcs->dev, "please update dts to use %s = <%i>\n", name, cells); - p = devm_kzalloc(pcs->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(pcs->dev, *p); if (!p) return -ENOMEM; p->length = sizeof(__be32); - p->value = devm_kzalloc(pcs->dev, sizeof(__be32), GFP_KERNEL); + p->value = devm_kzalloc_obj(pcs->dev, __be32); if (!p->value) return -ENOMEM; *(__be32 *)p->value = cpu_to_be32(cells); @@ -1791,7 +1786,7 @@ static int pcs_probe(struct platform_device *pdev) if (WARN_ON(!soc)) return -EINVAL; - pcs = devm_kzalloc(&pdev->dev, sizeof(*pcs), GFP_KERNEL); + pcs = devm_kzalloc_obj(&pdev->dev, *pcs); if (!pcs) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c index 59ecc295fb8ee7..dc23599764e2b8 100644 --- a/drivers/pinctrl/pinctrl-st.c +++ b/drivers/pinctrl/pinctrl-st.c @@ -819,7 +819,7 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev, } map_num = grp->npins + 1; - new_map = devm_kcalloc(dev, map_num, sizeof(*new_map), GFP_KERNEL); + new_map = devm_kzalloc_objs(dev, *new_map, map_num); if (!new_map) return -ENOMEM; @@ -1217,8 +1217,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np, grp->npins = npins; grp->name = np->name; - grp->pins = devm_kcalloc(dev, npins, sizeof(*grp->pins), GFP_KERNEL); - grp->pin_conf = devm_kcalloc(dev, npins, sizeof(*grp->pin_conf), GFP_KERNEL); + grp->pins = devm_kzalloc_objs(dev, *grp->pins, npins); + grp->pin_conf = devm_kzalloc_objs(dev, *grp->pin_conf, npins); if (!grp->pins || !grp->pin_conf) return -ENOMEM; @@ -1271,7 +1271,7 @@ static int st_pctl_parse_functions(struct device_node *np, func->ngroups = of_get_child_count(np); if (func->ngroups == 0) return dev_err_probe(dev, -EINVAL, "No groups defined\n"); - func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL); + func->groups = devm_kzalloc_objs(dev, *func->groups, func->ngroups); if (!func->groups) return -ENOMEM; @@ -1556,8 +1556,7 @@ static int st_gpiolib_register_bank(struct st_pinctrl *info, gpio_irq_chip_set_chip(girq, &st_gpio_irqchip); girq->parent_handler = st_gpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = gpio_irq; @@ -1601,11 +1600,12 @@ static int st_pctl_probe_dt(struct platform_device *pdev, dev_info(dev, "nfunctions = %d\n", info->nfunctions); dev_info(dev, "ngroups = %d\n", info->ngroups); - info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL); + info->functions = devm_kzalloc_objs(dev, *info->functions, + info->nfunctions); - info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL); + info->groups = devm_kzalloc_objs(dev, *info->groups, info->ngroups); - info->banks = devm_kcalloc(dev, info->nbanks, sizeof(*info->banks), GFP_KERNEL); + info->banks = devm_kzalloc_objs(dev, *info->banks, info->nbanks); if (!info->functions || !info->groups || !info->banks) return -ENOMEM; @@ -1627,7 +1627,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev, } pctl_desc->npins = info->nbanks * ST_GPIO_PINS_PER_BANK; - pdesc = devm_kcalloc(dev, pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL); + pdesc = devm_kzalloc_objs(dev, *pdesc, pctl_desc->npins); if (!pdesc) return -ENOMEM; @@ -1682,11 +1682,11 @@ static int st_pctl_probe(struct platform_device *pdev) return -EINVAL; } - pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL); + pctl_desc = devm_kzalloc_obj(dev, *pctl_desc); if (!pctl_desc) return -ENOMEM; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-stmfx.c b/drivers/pinctrl/pinctrl-stmfx.c index 935cace7f6459b..b85fea7489d6ba 100644 --- a/drivers/pinctrl/pinctrl-stmfx.c +++ b/drivers/pinctrl/pinctrl-stmfx.c @@ -648,7 +648,7 @@ static int stmfx_pinctrl_probe(struct platform_device *pdev) struct gpio_irq_chip *girq; int irq, ret; - pctl = devm_kzalloc(stmfx->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(stmfx->dev, *pctl); if (!pctl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c index 04a0e6269e5bc4..6c64a0a44faaa1 100644 --- a/drivers/pinctrl/pinctrl-sx150x.c +++ b/drivers/pinctrl/pinctrl-sx150x.c @@ -1132,7 +1132,7 @@ static int sx150x_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, i2c_funcs)) return -ENOSYS; - pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(dev, *pctl); if (!pctl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-tb10x.c b/drivers/pinctrl/pinctrl-tb10x.c index b7cbd69dd877d0..a03f566a97cbbd 100644 --- a/drivers/pinctrl/pinctrl-tb10x.c +++ b/drivers/pinctrl/pinctrl-tb10x.c @@ -749,9 +749,8 @@ static int tb10x_pinctrl_probe(struct platform_device *pdev) return -EINVAL; } - state = devm_kzalloc(dev, struct_size(state, pinfuncs, - of_get_child_count(of_node)), - GFP_KERNEL); + state = devm_kzalloc_flex(dev, *state, pinfuncs, + of_get_child_count(of_node)); if (!state) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c index 50a5889df7c47b..02332137182dc6 100644 --- a/drivers/pinctrl/pinctrl-th1520.c +++ b/drivers/pinctrl/pinctrl-th1520.c @@ -485,7 +485,8 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, } npins = of_property_count_strings(child, "pins"); - pgnames = devm_kcalloc(thp->pctl->dev, npins, sizeof(*pgnames), GFP_KERNEL); + pgnames = devm_kzalloc_objs(thp->pctl->dev, *pgnames, + npins); if (!pgnames) { ret = -ENOMEM; goto free_configs; @@ -855,7 +856,7 @@ static int th1520_pinctrl_probe(struct platform_device *pdev) u32 pin_group; int ret; - thp = devm_kzalloc(dev, sizeof(*thp), GFP_KERNEL); + thp = devm_kzalloc_obj(dev, *thp); if (!thp) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-tps6594.c b/drivers/pinctrl/pinctrl-tps6594.c index 937fc9cb54b7f2..c18a5f4a2eab3c 100644 --- a/drivers/pinctrl/pinctrl-tps6594.c +++ b/drivers/pinctrl/pinctrl-tps6594.c @@ -492,11 +492,11 @@ static int tps6594_pinctrl_probe(struct platform_device *pdev) struct pinctrl_desc *pctrl_desc; struct gpio_regmap_config config = {}; - pctrl_desc = devm_kzalloc(dev, sizeof(*pctrl_desc), GFP_KERNEL); + pctrl_desc = devm_kzalloc_obj(dev, *pctrl_desc); if (!pctrl_desc) return -ENOMEM; - pinctrl = devm_kzalloc(dev, sizeof(*pinctrl), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(dev, *pinctrl); if (!pinctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-upboard.c b/drivers/pinctrl/pinctrl-upboard.c index de1920a3387d5d..b9af6dd93c343d 100644 --- a/drivers/pinctrl/pinctrl-upboard.c +++ b/drivers/pinctrl/pinctrl-upboard.c @@ -960,11 +960,11 @@ static int upboard_pinctrl_probe(struct platform_device *pdev) unsigned int i; int ret; - pctldesc = devm_kzalloc(dev, sizeof(*pctldesc), GFP_KERNEL); + pctldesc = devm_kzalloc_obj(dev, *pctldesc); if (!pctldesc) return -ENOMEM; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; @@ -997,7 +997,7 @@ static int upboard_pinctrl_probe(struct platform_device *pdev) pctrl->dev = dev; - pins = devm_kcalloc(dev, pctldesc->npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, pctldesc->npins); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-xway.c b/drivers/pinctrl/pinctrl-xway.c index 3d4ad61d0da90c..fb8ef9623a6cf7 100644 --- a/drivers/pinctrl/pinctrl-xway.c +++ b/drivers/pinctrl/pinctrl-xway.c @@ -1467,9 +1467,8 @@ static int pinmux_xway_probe(struct platform_device *pdev) xway_chip.ngpio = xway_soc->pin_count; /* load our pad descriptors */ - xway_info.pads = devm_kcalloc(&pdev->dev, - xway_chip.ngpio, sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + xway_info.pads = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, + xway_chip.ngpio); if (!xway_info.pads) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-zynq.c b/drivers/pinctrl/pinctrl-zynq.c index dcde86fed10db3..d44349b4ebb557 100644 --- a/drivers/pinctrl/pinctrl-zynq.c +++ b/drivers/pinctrl/pinctrl-zynq.c @@ -1164,7 +1164,7 @@ static int zynq_pinctrl_probe(struct platform_device *pdev) struct resource *res; struct zynq_pinctrl *pctrl; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c index aba129ead04c00..e3e5eda5796526 100644 --- a/drivers/pinctrl/pinctrl-zynqmp.c +++ b/drivers/pinctrl/pinctrl-zynqmp.c @@ -613,8 +613,8 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid, } done: npins = bitmap_weight(used_pins, zynqmp_desc.npins); - fgroups = devm_kcalloc(dev, size_add(func->ngroups, npins), - sizeof(*fgroups), GFP_KERNEL); + fgroups = devm_kzalloc_objs(dev, *fgroups, + size_add(func->ngroups, npins)); if (!fgroups) return -ENOMEM; @@ -790,7 +790,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev, if (ret) return ret; - funcs = devm_kcalloc(dev, pctrl->nfuncs, sizeof(*funcs), GFP_KERNEL); + funcs = devm_kzalloc_objs(dev, *funcs, pctrl->nfuncs); if (!funcs) return -ENOMEM; @@ -804,7 +804,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev, pctrl->ngroups += funcs[i].ngroups; } - groups = devm_kcalloc(dev, pctrl->ngroups, sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(dev, *groups, pctrl->ngroups); if (!groups) return -ENOMEM; @@ -866,7 +866,7 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct device *dev, if (ret) return ret; - pins = devm_kcalloc(dev, *npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, *npins); if (!pins) return -ENOMEM; @@ -918,7 +918,7 @@ static int versal_pinctrl_prepare_pin_desc(struct device *dev, if (ret) return ret; - pins = devm_kcalloc(dev, *npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, *npins); if (!pins) return -ENOMEM; @@ -953,7 +953,7 @@ static int zynqmp_pinctrl_probe(struct platform_device *pdev) struct zynqmp_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 574fc95b6712e9..3d4d39db51f854 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -944,7 +944,7 @@ int pinmux_generic_add_pinfunction(struct pinctrl_dev *pctldev, selector = pctldev->num_functions; - function = devm_kzalloc(pctldev->dev, sizeof(*function), GFP_KERNEL); + function = devm_kzalloc_obj(pctldev->dev, *function); if (!function) return -ENOMEM; diff --git a/drivers/pinctrl/pxa/pinctrl-pxa2xx.c b/drivers/pinctrl/pxa/pinctrl-pxa2xx.c index 9fd7a8fb2bc44f..93f5a0e16598a2 100644 --- a/drivers/pinctrl/pxa/pinctrl-pxa2xx.c +++ b/drivers/pinctrl/pxa/pinctrl-pxa2xx.c @@ -272,8 +272,7 @@ static int pxa2xx_build_functions(struct pxa_pinctrl *pctl) * alternate function, 6 * npins is an absolute high limit of the number * of functions. */ - functions = devm_kcalloc(pctl->dev, pctl->npins * 6, - sizeof(*functions), GFP_KERNEL); + functions = devm_kzalloc_objs(pctl->dev, *functions, pctl->npins * 6); if (!functions) return -ENOMEM; @@ -297,8 +296,7 @@ static int pxa2xx_build_groups(struct pxa_pinctrl *pctl) struct pinfunction *func; const char **gtmp; - gtmp = devm_kmalloc_array(pctl->dev, pctl->npins, sizeof(*gtmp), - GFP_KERNEL); + gtmp = devm_kmalloc_objs(pctl->dev, *gtmp, pctl->npins); if (!gtmp) return -ENOMEM; @@ -335,7 +333,7 @@ static int pxa2xx_build_state(struct pxa_pinctrl *pctl, pctl->ngroups = npins; pctl->desc.npins = npins; - pins = devm_kcalloc(pctl->dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(pctl->dev, *pins, npins); if (!pins) return -ENOMEM; @@ -343,8 +341,8 @@ static int pxa2xx_build_state(struct pxa_pinctrl *pctl, for (i = 0; i < npins; i++) pins[i] = ppins[i].pin; - pctl->groups = devm_kmalloc_array(pctl->dev, pctl->ngroups, - sizeof(*pctl->groups), GFP_KERNEL); + pctl->groups = devm_kmalloc_objs(pctl->dev, *pctl->groups, + pctl->ngroups); if (!pctl->groups) return -ENOMEM; @@ -377,15 +375,15 @@ int pxa2xx_pinctrl_init(struct platform_device *pdev, for (i = 0; i < npins; i++) maxpin = max_t(int, ppins[i].pin.number, maxpin); - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; - pctl->base_gafr = devm_kcalloc(&pdev->dev, roundup(maxpin, 16), - sizeof(*pctl->base_gafr), GFP_KERNEL); - pctl->base_gpdr = devm_kcalloc(&pdev->dev, roundup(maxpin, 32), - sizeof(*pctl->base_gpdr), GFP_KERNEL); - pctl->base_pgsr = devm_kcalloc(&pdev->dev, roundup(maxpin, 32), - sizeof(*pctl->base_pgsr), GFP_KERNEL); + pctl->base_gafr = devm_kzalloc_objs(&pdev->dev, *pctl->base_gafr, + roundup(maxpin, 16)); + pctl->base_gpdr = devm_kzalloc_objs(&pdev->dev, *pctl->base_gpdr, + roundup(maxpin, 32)); + pctl->base_pgsr = devm_kzalloc_objs(&pdev->dev, *pctl->base_pgsr, + roundup(maxpin, 32)); if (!pctl->base_gafr || !pctl->base_gpdr || !pctl->base_pgsr) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c index 9412fd36a4aae5..679a7d35de8f10 100644 --- a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c +++ b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c @@ -507,7 +507,7 @@ int lpi_pinctrl_probe(struct platform_device *pdev) struct lpi_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index 27f06bbc113c96..657ecdaec4251e 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -759,7 +759,7 @@ static int msm_gpio_init_valid_mask(struct gpio_chip *gc, if (ret > ngpios) return -EINVAL; - tmp = kmalloc_array(len, sizeof(*tmp), GFP_KERNEL); + tmp = kmalloc_objs(*tmp, len); if (!tmp) return -ENOMEM; @@ -1492,8 +1492,7 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) girq->parent_handler = msm_gpio_irq_handler; girq->fwnode = dev_fwnode(pctrl->dev); girq->num_parents = 1; - girq->parents = devm_kcalloc(pctrl->dev, 1, sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(pctrl->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->default_type = IRQ_TYPE_NONE; @@ -1597,7 +1596,7 @@ int msm_pinctrl_probe(struct platform_device *pdev, int ret; int i; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c b/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c index 3b9edcf8780ba6..073a0e0ca19d4c 100644 --- a/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c +++ b/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c @@ -74,11 +74,9 @@ static int qdf2xxx_pinctrl_probe(struct platform_device *pdev) return ret; } - pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pinctrl), GFP_KERNEL); - pins = devm_kcalloc(&pdev->dev, num_gpios, - sizeof(struct pinctrl_pin_desc), GFP_KERNEL); - groups = devm_kcalloc(&pdev->dev, num_gpios, - sizeof(struct msm_pingroup), GFP_KERNEL); + pinctrl = devm_kzalloc_obj(&pdev->dev, *pinctrl); + pins = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, num_gpios); + groups = devm_kzalloc_objs(&pdev->dev, struct msm_pingroup, num_gpios); names = devm_kcalloc(&pdev->dev, avail_gpios, NAME_SIZE, GFP_KERNEL); if (!pinctrl || !pins || !groups || !names) diff --git a/drivers/pinctrl/qcom/pinctrl-sc8180x.c b/drivers/pinctrl/qcom/pinctrl-sc8180x.c index 062cb913e5eeb1..1c921869456d0f 100644 --- a/drivers/pinctrl/qcom/pinctrl-sc8180x.c +++ b/drivers/pinctrl/qcom/pinctrl-sc8180x.c @@ -1631,7 +1631,7 @@ static int sc8180x_pinctrl_add_tile_resources(struct platform_device *pdev) return 0; /* Allocate for new resources */ - nres = devm_kcalloc(&pdev->dev, nres_num, sizeof(*nres), GFP_KERNEL); + nres = devm_kzalloc_objs(&pdev->dev, *nres, nres_num); if (!nres) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c index 9163bb14d70365..05291b7397d6b1 100644 --- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c +++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c @@ -1113,7 +1113,7 @@ static int pmic_gpio_probe(struct platform_device *pdev) npins = (uintptr_t) device_get_match_data(&pdev->dev); - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; @@ -1125,15 +1125,15 @@ static int pmic_gpio_probe(struct platform_device *pdev) state->usid = parent_spmi_dev->usid; state->pid_base = reg >> 8; - pindesc = devm_kcalloc(dev, npins, sizeof(*pindesc), GFP_KERNEL); + pindesc = devm_kzalloc_objs(dev, *pindesc, npins); if (!pindesc) return -ENOMEM; - pads = devm_kcalloc(dev, npins, sizeof(*pads), GFP_KERNEL); + pads = devm_kzalloc_objs(dev, *pads, npins); if (!pads) return -ENOMEM; - pctrldesc = devm_kzalloc(dev, sizeof(*pctrldesc), GFP_KERNEL); + pctrldesc = devm_kzalloc_obj(dev, *pctrldesc); if (!pctrldesc) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c index 64f8024a865cd3..9ad07bb28eeb5f 100644 --- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c +++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c @@ -873,7 +873,7 @@ static int pmic_mpp_probe(struct platform_device *pdev) BUG_ON(npins > ARRAY_SIZE(pmic_mpp_groups)); - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(dev, *state); if (!state) return -ENOMEM; @@ -882,15 +882,15 @@ static int pmic_mpp_probe(struct platform_device *pdev) state->dev = &pdev->dev; state->map = dev_get_regmap(dev->parent, NULL); - pindesc = devm_kcalloc(dev, npins, sizeof(*pindesc), GFP_KERNEL); + pindesc = devm_kzalloc_objs(dev, *pindesc, npins); if (!pindesc) return -ENOMEM; - pads = devm_kcalloc(dev, npins, sizeof(*pads), GFP_KERNEL); + pads = devm_kzalloc_objs(dev, *pads, npins); if (!pads) return -ENOMEM; - pctrldesc = devm_kzalloc(dev, sizeof(*pctrldesc), GFP_KERNEL); + pctrldesc = devm_kzalloc_obj(dev, *pctrldesc); if (!pctrldesc) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c index c42dd7c736fec2..06a735de5fa7c4 100644 --- a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c +++ b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c @@ -736,7 +736,7 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev) struct pm8xxx_gpio *pctrl; int ret, i; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; @@ -752,17 +752,13 @@ static int pm8xxx_gpio_probe(struct platform_device *pdev) pctrl->desc = pm8xxx_pinctrl_desc; pctrl->desc.npins = pctrl->npins; - pins = devm_kcalloc(&pdev->dev, - pctrl->desc.npins, - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, + pctrl->desc.npins); if (!pins) return -ENOMEM; - pin_data = devm_kcalloc(&pdev->dev, - pctrl->desc.npins, - sizeof(struct pm8xxx_pin_data), - GFP_KERNEL); + pin_data = devm_kzalloc_objs(&pdev->dev, struct pm8xxx_pin_data, + pctrl->desc.npins); if (!pin_data) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c b/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c index 7970fa6e15579e..d2117ed1bdaf84 100644 --- a/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c +++ b/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c @@ -824,7 +824,7 @@ static int pm8xxx_mpp_probe(struct platform_device *pdev) int ret; int i; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; @@ -840,17 +840,13 @@ static int pm8xxx_mpp_probe(struct platform_device *pdev) pctrl->desc = pm8xxx_pinctrl_desc; pctrl->desc.npins = pctrl->npins; - pins = devm_kcalloc(&pdev->dev, - pctrl->desc.npins, - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, + pctrl->desc.npins); if (!pins) return -ENOMEM; - pin_data = devm_kcalloc(&pdev->dev, - pctrl->desc.npins, - sizeof(struct pm8xxx_pin_data), - GFP_KERNEL); + pin_data = devm_kzalloc_objs(&pdev->dev, struct pm8xxx_pin_data, + pctrl->desc.npins); if (!pin_data) return -ENOMEM; diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c index 8bff92dc0d0b8f..77970b1be381a2 100644 --- a/drivers/pinctrl/qcom/tlmm-test.c +++ b/drivers/pinctrl/qcom/tlmm-test.c @@ -587,7 +587,7 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res) return count; } - reg_names = kcalloc(count, sizeof(*reg_names), GFP_KERNEL); + reg_names = kzalloc_objs(*reg_names, count); if (!reg_names) return -ENOMEM; diff --git a/drivers/pinctrl/realtek/pinctrl-rtd.c b/drivers/pinctrl/realtek/pinctrl-rtd.c index 60222339726b46..df2850d73014b5 100644 --- a/drivers/pinctrl/realtek/pinctrl-rtd.c +++ b/drivers/pinctrl/realtek/pinctrl-rtd.c @@ -633,7 +633,7 @@ int rtd_pinctrl_probe(struct platform_device *pdev, const struct rtd_pinctrl_des { struct rtd_pinctrl *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/core.c b/drivers/pinctrl/renesas/core.c index a466ebf9959390..bc735422971e77 100644 --- a/drivers/pinctrl/renesas/core.c +++ b/drivers/pinctrl/renesas/core.c @@ -51,8 +51,7 @@ static int sh_pfc_map_resources(struct sh_pfc *pfc, return num_irqs; /* Allocate memory windows and IRQs arrays. */ - windows = devm_kcalloc(pfc->dev, num_windows, sizeof(*windows), - GFP_KERNEL); + windows = devm_kzalloc_objs(pfc->dev, *windows, num_windows); if (windows == NULL) return -ENOMEM; @@ -60,8 +59,7 @@ static int sh_pfc_map_resources(struct sh_pfc *pfc, pfc->windows = windows; if (num_irqs) { - irqs = devm_kcalloc(pfc->dev, num_irqs, sizeof(*irqs), - GFP_KERNEL); + irqs = devm_kzalloc_objs(pfc->dev, *irqs, num_irqs); if (irqs == NULL) return -ENOMEM; @@ -407,8 +405,7 @@ static int sh_pfc_init_ranges(struct sh_pfc *pfc) * continuous and allocate a single range. */ pfc->nr_ranges = 1; - pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges), - GFP_KERNEL); + pfc->ranges = devm_kzalloc_obj(pfc->dev, *pfc->ranges); if (pfc->ranges == NULL) return -ENOMEM; @@ -429,8 +426,7 @@ static int sh_pfc_init_ranges(struct sh_pfc *pfc) } pfc->nr_ranges = nr_ranges; - pfc->ranges = devm_kcalloc(pfc->dev, nr_ranges, sizeof(*pfc->ranges), - GFP_KERNEL); + pfc->ranges = devm_kzalloc_objs(pfc->dev, *pfc->ranges, nr_ranges); if (pfc->ranges == NULL) return -ENOMEM; @@ -710,9 +706,7 @@ static int sh_pfc_suspend_init(struct sh_pfc *pfc) if (!n) return 0; - pfc->saved_regs = devm_kmalloc_array(pfc->dev, n, - sizeof(*pfc->saved_regs), - GFP_KERNEL); + pfc->saved_regs = devm_kmalloc_objs(pfc->dev, *pfc->saved_regs, n); if (!pfc->saved_regs) return -ENOMEM; @@ -1135,7 +1129,7 @@ static void __init sh_pfc_check_info(const struct sh_pfc_soc_info *info) } /* Check groups and functions */ - refcnts = kcalloc(info->nr_groups, sizeof(*refcnts), GFP_KERNEL); + refcnts = kzalloc_objs(*refcnts, info->nr_groups); if (!refcnts) return; @@ -1277,8 +1271,7 @@ static void __init sh_pfc_check_driver(const struct platform_driver *pdrv) if (!sh_pfc_regs) return; - sh_pfc_enums = kcalloc(SH_PFC_MAX_ENUMS, sizeof(*sh_pfc_enums), - GFP_KERNEL); + sh_pfc_enums = kzalloc_objs(*sh_pfc_enums, SH_PFC_MAX_ENUMS); if (!sh_pfc_enums) goto free_regs; @@ -1315,7 +1308,7 @@ static int sh_pfc_probe(struct platform_device *pdev) else info = (const void *)platform_get_device_id(pdev)->driver_data; - pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); + pfc = devm_kzalloc_obj(&pdev->dev, *pfc); if (pfc == NULL) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/gpio.c b/drivers/pinctrl/renesas/gpio.c index 2293af6428493c..188b6907d6e76d 100644 --- a/drivers/pinctrl/renesas/gpio.c +++ b/drivers/pinctrl/renesas/gpio.c @@ -103,8 +103,7 @@ static int gpio_setup_data_regs(struct sh_pfc_chip *chip) for (i = 0; pfc->info->data_regs[i].reg_width; ++i) ; - chip->regs = devm_kcalloc(pfc->dev, i, sizeof(*chip->regs), - GFP_KERNEL); + chip->regs = devm_kzalloc_objs(pfc->dev, *chip->regs, i); if (chip->regs == NULL) return -ENOMEM; @@ -219,9 +218,8 @@ static int gpio_pin_setup(struct sh_pfc_chip *chip) struct gpio_chip *gc = &chip->gpio_chip; int ret; - chip->pins = devm_kcalloc(pfc->dev, - pfc->info->nr_pins, sizeof(*chip->pins), - GFP_KERNEL); + chip->pins = devm_kzalloc_objs(pfc->dev, *chip->pins, + pfc->info->nr_pins); if (chip->pins == NULL) return -ENOMEM; @@ -298,7 +296,7 @@ sh_pfc_add_gpiochip(struct sh_pfc *pfc, int(*setup)(struct sh_pfc_chip *), struct sh_pfc_chip *chip; int ret; - chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(pfc->dev, *chip); if (unlikely(!chip)) return ERR_PTR(-ENOMEM); diff --git a/drivers/pinctrl/renesas/pinctrl-rza1.c b/drivers/pinctrl/renesas/pinctrl-rza1.c index d2949e4dbaf73c..07afa4b3abaee1 100644 --- a/drivers/pinctrl/renesas/pinctrl-rza1.c +++ b/drivers/pinctrl/renesas/pinctrl-rza1.c @@ -1007,11 +1007,9 @@ static int rza1_dt_node_to_map(struct pinctrl_dev *pctldev, * except that functions carry an array of per-pin mux configuration * settings. */ - mux_confs = devm_kcalloc(rza1_pctl->dev, npins, sizeof(*mux_confs), - GFP_KERNEL); - grpins = devm_kcalloc(rza1_pctl->dev, npins, sizeof(*grpins), - GFP_KERNEL); - fngrps = devm_kzalloc(rza1_pctl->dev, sizeof(*fngrps), GFP_KERNEL); + mux_confs = devm_kzalloc_objs(rza1_pctl->dev, *mux_confs, npins); + grpins = devm_kzalloc_objs(rza1_pctl->dev, *grpins, npins); + fngrps = devm_kzalloc_obj(rza1_pctl->dev, *fngrps); if (!mux_confs || !grpins || !fngrps) return -ENOMEM; @@ -1245,10 +1243,9 @@ static int rza1_gpio_register(struct rza1_pinctrl *rza1_pctl) return 0; } - gpio_chips = devm_kcalloc(rza1_pctl->dev, ngpiochips, - sizeof(*gpio_chips), GFP_KERNEL); - gpio_ranges = devm_kcalloc(rza1_pctl->dev, ngpiochips, - sizeof(*gpio_ranges), GFP_KERNEL); + gpio_chips = devm_kzalloc_objs(rza1_pctl->dev, *gpio_chips, ngpiochips); + gpio_ranges = devm_kzalloc_objs(rza1_pctl->dev, *gpio_ranges, + ngpiochips); if (!gpio_chips || !gpio_ranges) return -ENOMEM; @@ -1282,10 +1279,8 @@ static int rza1_pinctrl_register(struct rza1_pinctrl *rza1_pctl) unsigned int i; int ret; - pins = devm_kcalloc(rza1_pctl->dev, RZA1_NPINS, sizeof(*pins), - GFP_KERNEL); - ports = devm_kcalloc(rza1_pctl->dev, RZA1_NPORTS, sizeof(*ports), - GFP_KERNEL); + pins = devm_kzalloc_objs(rza1_pctl->dev, *pins, RZA1_NPINS); + ports = devm_kzalloc_objs(rza1_pctl->dev, *ports, RZA1_NPORTS); if (!pins || !ports) return -ENOMEM; @@ -1347,7 +1342,7 @@ static int rza1_pinctrl_probe(struct platform_device *pdev) struct rza1_pinctrl *rza1_pctl; int ret; - rza1_pctl = devm_kzalloc(&pdev->dev, sizeof(*rza1_pctl), GFP_KERNEL); + rza1_pctl = devm_kzalloc_obj(&pdev->dev, *rza1_pctl); if (!rza1_pctl) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl-rza2.c b/drivers/pinctrl/renesas/pinctrl-rza2.c index 4cab641c335097..8860900ae54ba5 100644 --- a/drivers/pinctrl/renesas/pinctrl-rza2.c +++ b/drivers/pinctrl/renesas/pinctrl-rza2.c @@ -346,10 +346,9 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev, } npins = of_pins->length / sizeof(u32); - pins = devm_kcalloc(priv->dev, npins, sizeof(*pins), GFP_KERNEL); - psel_val = devm_kcalloc(priv->dev, npins, sizeof(*psel_val), - GFP_KERNEL); - pin_fn = devm_kzalloc(priv->dev, sizeof(*pin_fn), GFP_KERNEL); + pins = devm_kzalloc_objs(priv->dev, *pins, npins); + psel_val = devm_kzalloc_objs(priv->dev, *psel_val, npins); + pin_fn = devm_kzalloc_obj(priv->dev, *pin_fn); if (!pins || !psel_val || !pin_fn) return -ENOMEM; @@ -482,7 +481,7 @@ static int rza2_pinctrl_probe(struct platform_device *pdev) npins = (uintptr_t)of_device_get_match_data(&pdev->dev) * RZA2_PINS_PER_PORT; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, pins, npins), GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, pins, npins); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c index 9bf3743dc1ce2e..ca2f36c46c391e 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c @@ -1003,10 +1003,9 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev, goto done; } - pins = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*pins), GFP_KERNEL); - psel_val = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*psel_val), - GFP_KERNEL); - pin_fn = devm_kzalloc(pctrl->dev, sizeof(*pin_fn), GFP_KERNEL); + pins = devm_kzalloc_objs(pctrl->dev, *pins, num_pinmux); + psel_val = devm_kzalloc_objs(pctrl->dev, *psel_val, num_pinmux); + pin_fn = devm_kzalloc_obj(pctrl->dev, *pin_fn); if (!pins || !psel_val || !pin_fn) { ret = -ENOMEM; goto done; @@ -3212,11 +3211,11 @@ static int rzg2l_pinctrl_reg_cache_alloc(struct rzg2l_pinctrl *pctrl) u32 nports = pctrl->data->n_port_pins / RZG2L_PINS_PER_PORT; struct rzg2l_pinctrl_reg_cache *cache, *dedicated_cache; - cache = devm_kzalloc(pctrl->dev, sizeof(*cache), GFP_KERNEL); + cache = devm_kzalloc_obj(pctrl->dev, *cache); if (!cache) return -ENOMEM; - dedicated_cache = devm_kzalloc(pctrl->dev, sizeof(*dedicated_cache), GFP_KERNEL); + dedicated_cache = devm_kzalloc_obj(pctrl->dev, *dedicated_cache); if (!dedicated_cache) return -ENOMEM; @@ -3224,7 +3223,7 @@ static int rzg2l_pinctrl_reg_cache_alloc(struct rzg2l_pinctrl *pctrl) if (!cache->p) return -ENOMEM; - cache->pm = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pm), GFP_KERNEL); + cache->pm = devm_kzalloc_objs(pctrl->dev, *cache->pm, nports); if (!cache->pm) return -ENOMEM; @@ -3232,71 +3231,71 @@ static int rzg2l_pinctrl_reg_cache_alloc(struct rzg2l_pinctrl *pctrl) if (!cache->pmc) return -ENOMEM; - cache->pfc = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pfc), GFP_KERNEL); + cache->pfc = devm_kzalloc_objs(pctrl->dev, *cache->pfc, nports); if (!cache->pfc) return -ENOMEM; for (u8 i = 0; i < 2; i++) { u32 n_dedicated_pins = pctrl->data->n_dedicated_pins; - cache->iolh[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->iolh[i]), - GFP_KERNEL); + cache->iolh[i] = devm_kzalloc_objs(pctrl->dev, *cache->iolh[i], + nports); if (!cache->iolh[i]) return -ENOMEM; - cache->ien[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->ien[i]), - GFP_KERNEL); + cache->ien[i] = devm_kzalloc_objs(pctrl->dev, *cache->ien[i], + nports); if (!cache->ien[i]) return -ENOMEM; - cache->pupd[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->pupd[i]), - GFP_KERNEL); + cache->pupd[i] = devm_kzalloc_objs(pctrl->dev, *cache->pupd[i], + nports); if (!cache->pupd[i]) return -ENOMEM; - cache->smt[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->smt[i]), - GFP_KERNEL); + cache->smt[i] = devm_kzalloc_objs(pctrl->dev, *cache->smt[i], + nports); if (!cache->smt[i]) return -ENOMEM; - cache->sr[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->sr[i]), - GFP_KERNEL); + cache->sr[i] = devm_kzalloc_objs(pctrl->dev, *cache->sr[i], + nports); if (!cache->sr[i]) return -ENOMEM; - cache->nod[i] = devm_kcalloc(pctrl->dev, nports, sizeof(*cache->nod[i]), - GFP_KERNEL); + cache->nod[i] = devm_kzalloc_objs(pctrl->dev, *cache->nod[i], + nports); if (!cache->nod[i]) return -ENOMEM; /* Allocate dedicated cache. */ - dedicated_cache->iolh[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, - sizeof(*dedicated_cache->iolh[i]), - GFP_KERNEL); + dedicated_cache->iolh[i] = devm_kzalloc_objs(pctrl->dev, + *dedicated_cache->iolh[i], + n_dedicated_pins); if (!dedicated_cache->iolh[i]) return -ENOMEM; - dedicated_cache->ien[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, - sizeof(*dedicated_cache->ien[i]), - GFP_KERNEL); + dedicated_cache->ien[i] = devm_kzalloc_objs(pctrl->dev, + *dedicated_cache->ien[i], + n_dedicated_pins); if (!dedicated_cache->ien[i]) return -ENOMEM; - dedicated_cache->sr[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, - sizeof(*dedicated_cache->sr[i]), - GFP_KERNEL); + dedicated_cache->sr[i] = devm_kzalloc_objs(pctrl->dev, + *dedicated_cache->sr[i], + n_dedicated_pins); if (!dedicated_cache->sr[i]) return -ENOMEM; - dedicated_cache->nod[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, - sizeof(*dedicated_cache->nod[i]), - GFP_KERNEL); + dedicated_cache->nod[i] = devm_kzalloc_objs(pctrl->dev, + *dedicated_cache->nod[i], + n_dedicated_pins); if (!dedicated_cache->nod[i]) return -ENOMEM; - dedicated_cache->pupd[i] = devm_kcalloc(pctrl->dev, n_dedicated_pins, - sizeof(*dedicated_cache->pupd[i]), - GFP_KERNEL); + dedicated_cache->pupd[i] = devm_kzalloc_objs(pctrl->dev, + *dedicated_cache->pupd[i], + n_dedicated_pins); if (!dedicated_cache->pupd[i]) return -ENOMEM; } @@ -3399,12 +3398,11 @@ static int rzg2l_pinctrl_register(struct rzg2l_pinctrl *pctrl) #endif } - pins = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(pctrl->dev, *pins, pctrl->desc.npins); if (!pins) return -ENOMEM; - pin_data = devm_kcalloc(pctrl->dev, pctrl->desc.npins, - sizeof(*pin_data), GFP_KERNEL); + pin_data = devm_kzalloc_objs(pctrl->dev, *pin_data, pctrl->desc.npins); if (!pin_data) return -ENOMEM; @@ -3434,8 +3432,8 @@ static int rzg2l_pinctrl_register(struct rzg2l_pinctrl *pctrl) pins[index].drv_data = &pin_data[index]; } - pctrl->settings = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pctrl->settings), - GFP_KERNEL); + pctrl->settings = devm_kzalloc_objs(pctrl->dev, *pctrl->settings, + pctrl->desc.npins); if (!pctrl->settings) return -ENOMEM; @@ -3493,7 +3491,7 @@ static int rzg2l_pinctrl_probe(struct platform_device *pdev) BUILD_BUG_ON(ARRAY_SIZE(r9a09g057_gpio_configs) * RZG2L_PINS_PER_PORT > ARRAY_SIZE(rzv2h_gpio_names)); - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl-rzn1.c b/drivers/pinctrl/renesas/pinctrl-rzn1.c index fb874867dbfb98..6fbeff5dbc155f 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzn1.c +++ b/drivers/pinctrl/renesas/pinctrl-rzn1.c @@ -721,9 +721,7 @@ static int rzn1_pinctrl_parse_groups(struct device_node *np, grp->pin_ids = devm_kmalloc_array(ipctl->dev, grp->npins, sizeof(grp->pin_ids[0]), GFP_KERNEL); - grp->pins = devm_kmalloc_array(ipctl->dev, - grp->npins, sizeof(grp->pins[0]), - GFP_KERNEL); + grp->pins = devm_kmalloc_objs(ipctl->dev, grp->pins[0], grp->npins); if (!grp->pin_ids || !grp->pins) return -ENOMEM; @@ -821,9 +819,8 @@ static int rzn1_pinctrl_probe_dt(struct platform_device *pdev, return 0; ipctl->nfunctions = nfuncs; - ipctl->functions = devm_kmalloc_array(&pdev->dev, nfuncs, - sizeof(*ipctl->functions), - GFP_KERNEL); + ipctl->functions = devm_kmalloc_objs(&pdev->dev, *ipctl->functions, + nfuncs); if (!ipctl->functions) return -ENOMEM; @@ -831,10 +828,7 @@ static int rzn1_pinctrl_probe_dt(struct platform_device *pdev, for_each_child_of_node_scoped(np, child) maxgroups += rzn1_pinctrl_count_function_groups(child); - ipctl->groups = devm_kmalloc_array(&pdev->dev, - maxgroups, - sizeof(*ipctl->groups), - GFP_KERNEL); + ipctl->groups = devm_kmalloc_objs(&pdev->dev, *ipctl->groups, maxgroups); if (!ipctl->groups) return -ENOMEM; @@ -854,7 +848,7 @@ static int rzn1_pinctrl_probe(struct platform_device *pdev) int ret; /* Create state holders etc for this driver */ - ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); + ipctl = devm_kzalloc_obj(&pdev->dev, *ipctl); if (!ipctl) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl-rzt2h.c b/drivers/pinctrl/renesas/pinctrl-rzt2h.c index 4872a208e0c3db..a9bc543f0da07a 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzt2h.c +++ b/drivers/pinctrl/renesas/pinctrl-rzt2h.c @@ -396,10 +396,10 @@ static int rzt2h_dt_subnode_to_map(struct pinctrl_dev *pctldev, goto done; } - pins = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(pctrl->dev, *pins, num_pinmux); psel_val = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*psel_val), GFP_KERNEL); - pin_fn = devm_kzalloc(pctrl->dev, sizeof(*pin_fn), GFP_KERNEL); + pin_fn = devm_kzalloc_obj(pctrl->dev, *pin_fn); if (!pins || !psel_val || !pin_fn) { ret = -ENOMEM; goto done; @@ -1209,7 +1209,7 @@ static int rzt2h_pinctrl_register(struct rzt2h_pinctrl *pctrl) desc->confops = &rzt2h_pinctrl_confops; desc->owner = THIS_MODULE; - pins = devm_kcalloc(dev, desc->npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, desc->npins); if (!pins) return -ENOMEM; @@ -1269,7 +1269,7 @@ static int rzt2h_pinctrl_probe(struct platform_device *pdev) struct rzt2h_pinctrl *pctrl; int ret; - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl-rzv2m.c b/drivers/pinctrl/renesas/pinctrl-rzv2m.c index 9029d1947bbb27..b550c9df0ba45b 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzv2m.c +++ b/drivers/pinctrl/renesas/pinctrl-rzv2m.c @@ -292,10 +292,9 @@ static int rzv2m_dt_subnode_to_map(struct pinctrl_dev *pctldev, goto done; } - pins = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*pins), GFP_KERNEL); - psel_val = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*psel_val), - GFP_KERNEL); - pin_fn = devm_kzalloc(pctrl->dev, sizeof(*pin_fn), GFP_KERNEL); + pins = devm_kzalloc_objs(pctrl->dev, *pins, num_pinmux); + psel_val = devm_kzalloc_objs(pctrl->dev, *psel_val, num_pinmux); + pin_fn = devm_kzalloc_obj(pctrl->dev, *pin_fn); if (!pins || !psel_val || !pin_fn) { ret = -ENOMEM; goto done; @@ -996,12 +995,11 @@ static int rzv2m_pinctrl_register(struct rzv2m_pinctrl *pctrl) pctrl->desc.confops = &rzv2m_pinctrl_confops; pctrl->desc.owner = THIS_MODULE; - pins = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(pctrl->dev, *pins, pctrl->desc.npins); if (!pins) return -ENOMEM; - pin_data = devm_kcalloc(pctrl->dev, pctrl->desc.npins, - sizeof(*pin_data), GFP_KERNEL); + pin_data = devm_kzalloc_objs(pctrl->dev, *pin_data, pctrl->desc.npins); if (!pin_data) return -ENOMEM; @@ -1054,7 +1052,7 @@ static int rzv2m_pinctrl_probe(struct platform_device *pdev) struct clk *clk; int ret; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/renesas/pinctrl.c b/drivers/pinctrl/renesas/pinctrl.c index 8585ed4bcfe096..a1fc79162e8451 100644 --- a/drivers/pinctrl/renesas/pinctrl.c +++ b/drivers/pinctrl/renesas/pinctrl.c @@ -780,15 +780,12 @@ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) unsigned int i; /* Allocate and initialize the pins and configs arrays. */ - pmx->pins = devm_kcalloc(pfc->dev, - pfc->info->nr_pins, sizeof(*pmx->pins), - GFP_KERNEL); + pmx->pins = devm_kzalloc_objs(pfc->dev, *pmx->pins, pfc->info->nr_pins); if (unlikely(!pmx->pins)) return -ENOMEM; - pmx->configs = devm_kcalloc(pfc->dev, - pfc->info->nr_pins, sizeof(*pmx->configs), - GFP_KERNEL); + pmx->configs = devm_kzalloc_objs(pfc->dev, *pmx->configs, + pfc->info->nr_pins); if (unlikely(!pmx->configs)) return -ENOMEM; @@ -809,7 +806,7 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) struct sh_pfc_pinctrl *pmx; int ret; - pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(pfc->dev, *pmx); if (unlikely(!pmx)) return -ENOMEM; diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c index d3d8672f74dc62..94cbeefb82fd21 100644 --- a/drivers/pinctrl/samsung/pinctrl-exynos-arm.c +++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm.c @@ -72,7 +72,7 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata, struct device_node *np; void __iomem *clk_base; - ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(drvdata->dev, *ctrl); if (!ctrl) return ERR_PTR(-ENOMEM); diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c index 81fe0b08a9af56..c45da9f1341163 100644 --- a/drivers/pinctrl/samsung/pinctrl-exynos.c +++ b/drivers/pinctrl/samsung/pinctrl-exynos.c @@ -451,8 +451,8 @@ __init int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d) goto err_domains; } - bank->soc_priv = devm_kzalloc(d->dev, - sizeof(struct exynos_eint_gpio_save), GFP_KERNEL); + bank->soc_priv = devm_kzalloc_obj(d->dev, + struct exynos_eint_gpio_save); if (!bank->soc_priv) { irq_domain_remove(bank->irq_domain); ret = -ENOMEM; @@ -817,9 +817,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) continue; } - weint_data = devm_kcalloc(dev, - bank->nr_pins, sizeof(*weint_data), - GFP_KERNEL); + weint_data = devm_kzalloc_objs(dev, *weint_data, bank->nr_pins); if (!weint_data) return -ENOMEM; @@ -1081,7 +1079,7 @@ exynos_retention_init(struct samsung_pinctrl_drv_data *drvdata, struct regmap *pmu_regs; int i; - ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(drvdata->dev, *ctrl); if (!ctrl) return ERR_PTR(-ENOMEM); diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c index 68715c09baa9d0..53c895f5d3c079 100644 --- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c +++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c @@ -494,8 +494,7 @@ static int s3c64xx_eint_gpio_init(struct samsung_pinctrl_drv_data *d) ++nr_domains; } - data = devm_kzalloc(dev, struct_size(data, domains, nr_domains), - GFP_KERNEL); + data = devm_kzalloc_flex(dev, *data, domains, nr_domains); if (!data) return -ENOMEM; data->drvdata = d; @@ -713,7 +712,7 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d) if (!eint0_np) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) { of_node_put(eint0_np); return -ENOMEM; diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index 5ecc9ed4c44dbf..646d3990152fae 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -747,8 +747,7 @@ static struct samsung_pin_group *samsung_pinctrl_create_groups( const struct pinctrl_pin_desc *pdesc; int i; - groups = devm_kcalloc(dev, ctrldesc->npins, sizeof(*groups), - GFP_KERNEL); + groups = devm_kzalloc_objs(dev, *groups, ctrldesc->npins); if (!groups) return ERR_PTR(-EINVAL); grp = groups; @@ -841,8 +840,7 @@ static struct samsung_pmx_func *samsung_pinctrl_create_functions( } } - functions = devm_kcalloc(dev, func_cnt, sizeof(*functions), - GFP_KERNEL); + functions = devm_kzalloc_objs(dev, *functions, func_cnt); if (!functions) return ERR_PTR(-ENOMEM); func = functions; @@ -931,9 +929,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev, ctrldesc->pmxops = &samsung_pinmux_ops; ctrldesc->confops = &samsung_pinconf_ops; - pindesc = devm_kcalloc(&pdev->dev, - drvdata->nr_pins, sizeof(*pindesc), - GFP_KERNEL); + pindesc = devm_kzalloc_objs(&pdev->dev, *pindesc, drvdata->nr_pins); if (!pindesc) return -ENOMEM; ctrldesc->pins = pindesc; @@ -1200,8 +1196,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, d->suspend = ctrl->suspend; d->resume = ctrl->resume; d->nr_banks = ctrl->nr_banks; - d->pin_banks = devm_kcalloc(&pdev->dev, d->nr_banks, - sizeof(*d->pin_banks), GFP_KERNEL); + d->pin_banks = devm_kzalloc_objs(&pdev->dev, *d->pin_banks, d->nr_banks); if (!d->pin_banks) return ERR_PTR(-ENOMEM); @@ -1265,7 +1260,7 @@ static int samsung_pinctrl_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c index 36e3c4f9e90f47..427d842ed64319 100644 --- a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c +++ b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c @@ -412,8 +412,7 @@ static int cv1800_pinctrl_init(struct platform_device *pdev, const struct sophgo_pinctrl_data *pctrl_data = pctrl->data; struct cv1800_priv *priv; - priv = devm_kzalloc(&pdev->dev, struct_size(priv, power_cfg, pctrl_data->npds), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, power_cfg, pctrl_data->npds); if (!priv) return -ENOMEM; priv->num_power_cfg = pctrl_data->npds; diff --git a/drivers/pinctrl/sophgo/pinctrl-sg2042-ops.c b/drivers/pinctrl/sophgo/pinctrl-sg2042-ops.c index 0526aa3f84384c..3e91e8d9dabf3c 100644 --- a/drivers/pinctrl/sophgo/pinctrl-sg2042-ops.c +++ b/drivers/pinctrl/sophgo/pinctrl-sg2042-ops.c @@ -274,7 +274,7 @@ static int sophgo_pinctrl_init(struct platform_device *pdev, { struct sg2042_priv *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/sophgo/pinctrl-sophgo-common.c b/drivers/pinctrl/sophgo/pinctrl-sophgo-common.c index 4dfe16b6618803..451c521f03ef43 100644 --- a/drivers/pinctrl/sophgo/pinctrl-sophgo-common.c +++ b/drivers/pinctrl/sophgo/pinctrl-sophgo-common.c @@ -90,7 +90,7 @@ int sophgo_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node for_each_available_child_of_node(np, child) ngroups += 1; - grpnames = devm_kcalloc(dev, ngroups, sizeof(*grpnames), GFP_KERNEL); + grpnames = devm_kzalloc_objs(dev, *grpnames, ngroups); if (!grpnames) return -ENOMEM; @@ -123,13 +123,13 @@ int sophgo_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node grpnames[ngroups++] = grpname; - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) { ret = -ENOMEM; goto dt_failed; } - pinmuxs = devm_kcalloc(dev, npins, sizeof(*pinmuxs), GFP_KERNEL); + pinmuxs = devm_kzalloc_objs(dev, *pinmuxs, npins); if (!pinmuxs) { ret = -ENOMEM; goto dt_failed; @@ -414,7 +414,7 @@ int sophgo_pinctrl_probe(struct platform_device *pdev) if (pctrl_data->npins == 0) return dev_err_probe(dev, -EINVAL, "invalid pin data\n"); - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/spacemit/pinctrl-k1.c b/drivers/pinctrl/spacemit/pinctrl-k1.c index c3a7538783b8a4..d0706f77d1204d 100644 --- a/drivers/pinctrl/spacemit/pinctrl-k1.c +++ b/drivers/pinctrl/spacemit/pinctrl-k1.c @@ -776,7 +776,7 @@ static int spacemit_pinctrl_probe(struct platform_device *pdev) if (pctrl_data->npins == 0) return dev_err_probe(dev, -EINVAL, "invalid pin data\n"); - pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/spear/pinctrl-plgpio.c b/drivers/pinctrl/spear/pinctrl-plgpio.c index 5fcbea32089d88..b5fc76e114be25 100644 --- a/drivers/pinctrl/spear/pinctrl-plgpio.c +++ b/drivers/pinctrl/spear/pinctrl-plgpio.c @@ -532,7 +532,7 @@ static int plgpio_probe(struct platform_device *pdev) struct plgpio *plgpio; int ret, irq; - plgpio = devm_kzalloc(&pdev->dev, sizeof(*plgpio), GFP_KERNEL); + plgpio = devm_kzalloc_obj(&pdev->dev, *plgpio); if (!plgpio) return -ENOMEM; @@ -565,10 +565,8 @@ static int plgpio_probe(struct platform_device *pdev) dev_warn(&pdev->dev, "clk_get() failed, work without it\n"); #ifdef CONFIG_PM_SLEEP - plgpio->csave_regs = devm_kcalloc(&pdev->dev, - DIV_ROUND_UP(plgpio->chip.ngpio, MAX_GPIO_PER_REG), - sizeof(*plgpio->csave_regs), - GFP_KERNEL); + plgpio->csave_regs = devm_kzalloc_objs(&pdev->dev, *plgpio->csave_regs, + DIV_ROUND_UP(plgpio->chip.ngpio, MAX_GPIO_PER_REG)); if (!plgpio->csave_regs) return -ENOMEM; #endif @@ -603,9 +601,7 @@ static int plgpio_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(girq, &plgpio_irqchip); girq->parent_handler = plgpio_irq_handler; girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); + girq->parents = devm_kzalloc_objs(&pdev->dev, *girq->parents, 1); if (!girq->parents) return -ENOMEM; girq->parents[0] = irq; diff --git a/drivers/pinctrl/spear/pinctrl-spear.c b/drivers/pinctrl/spear/pinctrl-spear.c index f92f6efde1dcd7..b1c3080de75f90 100644 --- a/drivers/pinctrl/spear/pinctrl-spear.c +++ b/drivers/pinctrl/spear/pinctrl-spear.c @@ -360,7 +360,7 @@ int spear_pinctrl_probe(struct platform_device *pdev, if (!machdata) return -ENODEV; - pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL); + pmx = devm_kzalloc_obj(&pdev->dev, *pmx); if (!pmx) return -ENOMEM; diff --git a/drivers/pinctrl/sprd/pinctrl-sprd.c b/drivers/pinctrl/sprd/pinctrl-sprd.c index a565d4fd4233cb..fa7dab2edfd27b 100644 --- a/drivers/pinctrl/sprd/pinctrl-sprd.c +++ b/drivers/pinctrl/sprd/pinctrl-sprd.c @@ -893,9 +893,7 @@ static int sprd_pinctrl_parse_groups(struct device_node *np, grp->name = np->name; grp->npins = ret; - grp->pins = devm_kcalloc(sprd_pctl->dev, - grp->npins, sizeof(unsigned int), - GFP_KERNEL); + grp->pins = devm_kzalloc_objs(sprd_pctl->dev, unsigned int, grp->npins); if (!grp->pins) return -ENOMEM; @@ -945,10 +943,8 @@ static int sprd_pinctrl_parse_dt(struct sprd_pinctrl *sprd_pctl) if (!info->ngroups) return 0; - info->groups = devm_kcalloc(sprd_pctl->dev, - info->ngroups, - sizeof(struct sprd_pin_group), - GFP_KERNEL); + info->groups = devm_kzalloc_objs(sprd_pctl->dev, struct sprd_pin_group, + info->ngroups); if (!info->groups) return -ENOMEM; @@ -995,9 +991,8 @@ static int sprd_pinctrl_add_pins(struct sprd_pinctrl *sprd_pctl, int i; info->npins = pins_cnt; - info->pins = devm_kcalloc(sprd_pctl->dev, - info->npins, sizeof(struct sprd_pin), - GFP_KERNEL); + info->pins = devm_kzalloc_objs(sprd_pctl->dev, struct sprd_pin, + info->npins); if (!info->pins) return -ENOMEM; @@ -1045,8 +1040,7 @@ int sprd_pinctrl_core_probe(struct platform_device *pdev, struct pinctrl_pin_desc *pin_desc; int ret, i; - sprd_pctl = devm_kzalloc(&pdev->dev, sizeof(struct sprd_pinctrl), - GFP_KERNEL); + sprd_pctl = devm_kzalloc_obj(&pdev->dev, struct sprd_pinctrl); if (!sprd_pctl) return -ENOMEM; @@ -1054,9 +1048,8 @@ int sprd_pinctrl_core_probe(struct platform_device *pdev, if (IS_ERR(sprd_pctl->base)) return PTR_ERR(sprd_pctl->base); - pinctrl_info = devm_kzalloc(&pdev->dev, - sizeof(struct sprd_pinctrl_soc_info), - GFP_KERNEL); + pinctrl_info = devm_kzalloc_obj(&pdev->dev, + struct sprd_pinctrl_soc_info); if (!pinctrl_info) return -ENOMEM; @@ -1076,10 +1069,8 @@ int sprd_pinctrl_core_probe(struct platform_device *pdev, return ret; } - pin_desc = devm_kcalloc(&pdev->dev, - pinctrl_info->npins, - sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); + pin_desc = devm_kzalloc_objs(&pdev->dev, struct pinctrl_pin_desc, + pinctrl_info->npins); if (!pin_desc) return -ENOMEM; diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c index 37da176cad4920..d89f6a47221bb5 100644 --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c @@ -512,7 +512,7 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev, ngroups += 1; } - pgnames = devm_kcalloc(dev, ngroups, sizeof(*pgnames), GFP_KERNEL); + pgnames = devm_kzalloc_objs(dev, *pgnames, ngroups); if (!pgnames) return -ENOMEM; @@ -536,13 +536,13 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev, pgnames[ngroups++] = grpname; if ((npins = of_property_count_u32_elems(child, "pinmux")) > 0) { - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) { ret = -ENOMEM; goto free_map; } - pinmux = devm_kcalloc(dev, npins, sizeof(*pinmux), GFP_KERNEL); + pinmux = devm_kzalloc_objs(dev, *pinmux, npins); if (!pinmux) { ret = -ENOMEM; goto free_map; @@ -563,7 +563,7 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev, map[nmaps].data.mux.group = grpname; nmaps += 1; } else if ((npins = of_property_count_u32_elems(child, "pins")) > 0) { - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) { ret = -ENOMEM; goto free_map; @@ -1220,7 +1220,7 @@ static int starfive_probe(struct platform_device *pdev) u32 value; int ret; - sfp = devm_kzalloc(dev, sizeof(*sfp), GFP_KERNEL); + sfp = devm_kzalloc_obj(dev, *sfp); if (!sfp) return -ENOMEM; @@ -1310,8 +1310,8 @@ static int starfive_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(&sfp->gc.irq, &starfive_irq_chip); sfp->gc.irq.parent_handler = starfive_gpio_irq_handler; sfp->gc.irq.num_parents = 1; - sfp->gc.irq.parents = devm_kcalloc(dev, sfp->gc.irq.num_parents, - sizeof(*sfp->gc.irq.parents), GFP_KERNEL); + sfp->gc.irq.parents = devm_kzalloc_objs(dev, *sfp->gc.irq.parents, + sfp->gc.irq.num_parents); if (!sfp->gc.irq.parents) return -ENOMEM; sfp->gc.irq.default_type = IRQ_TYPE_NONE; diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c index 7fcb6cdc1e864a..2713cd89b181c6 100644 --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c @@ -138,7 +138,7 @@ static int jh7110_dt_node_to_map(struct pinctrl_dev *pctldev, ngroups += 1; nmaps = 2 * ngroups; - pgnames = devm_kcalloc(dev, ngroups, sizeof(*pgnames), GFP_KERNEL); + pgnames = devm_kzalloc_objs(dev, *pgnames, ngroups); if (!pgnames) return -ENOMEM; @@ -171,13 +171,13 @@ static int jh7110_dt_node_to_map(struct pinctrl_dev *pctldev, pgnames[ngroups++] = grpname; - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) { ret = -ENOMEM; goto free_map; } - pinmux = devm_kcalloc(dev, npins, sizeof(*pinmux), GFP_KERNEL); + pinmux = devm_kzalloc_objs(dev, *pinmux, npins); if (!pinmux) { ret = -ENOMEM; goto free_map; @@ -858,8 +858,7 @@ int jh7110_pinctrl_probe(struct platform_device *pdev) } num_saved_regs = IS_ENABLED(CONFIG_PM_SLEEP) ? info->nsaved_regs : 0; - sfp = devm_kzalloc(dev, struct_size(sfp, saved_regs, num_saved_regs), - GFP_KERNEL); + sfp = devm_kzalloc_flex(dev, *sfp, saved_regs, num_saved_regs); if (!sfp) return -ENOMEM; sfp->num_saved_regs = num_saved_regs; @@ -895,9 +894,7 @@ int jh7110_pinctrl_probe(struct platform_device *pdev) return ret; } - jh7110_pinctrl_desc = devm_kzalloc(&pdev->dev, - sizeof(*jh7110_pinctrl_desc), - GFP_KERNEL); + jh7110_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *jh7110_pinctrl_desc); if (!jh7110_pinctrl_desc) return -ENOMEM; @@ -941,9 +938,8 @@ int jh7110_pinctrl_probe(struct platform_device *pdev) gpio_irq_chip_set_chip(&sfp->gc.irq, &jh7110_irq_chip); sfp->gc.irq.parent_handler = info->jh7110_gpio_irq_handler; sfp->gc.irq.num_parents = 1; - sfp->gc.irq.parents = devm_kcalloc(dev, sfp->gc.irq.num_parents, - sizeof(*sfp->gc.irq.parents), - GFP_KERNEL); + sfp->gc.irq.parents = devm_kzalloc_objs(dev, *sfp->gc.irq.parents, + sfp->gc.irq.num_parents); if (!sfp->gc.irq.parents) return -ENOMEM; sfp->gc.irq.default_type = IRQ_TYPE_NONE; diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jhb100.c b/drivers/pinctrl/starfive/pinctrl-starfive-jhb100.c index 462a26697b883c..4147edd6fbad03 100644 --- a/drivers/pinctrl/starfive/pinctrl-starfive-jhb100.c +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jhb100.c @@ -1245,7 +1245,7 @@ struct pinctrl_pin_desc *devm_create_pins_from_pld(struct device *dev, dev_dbg(dev, "Total pins to create: %d\n", npins); - pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, npins); if (!pins) return ERR_PTR(-ENOMEM); @@ -1327,7 +1327,7 @@ int jhb100_pinctrl_probe(struct platform_device *pdev) pinctrl_regs = info->regs; - sfp = devm_kzalloc(dev, sizeof(*sfp), GFP_KERNEL); + sfp = devm_kzalloc_obj(dev, *sfp); if (!sfp) return -ENOMEM; @@ -1361,9 +1361,7 @@ int jhb100_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(sfp->pins)) return PTR_ERR(sfp->pins); - jhb100_pinctrl_desc = devm_kzalloc(&pdev->dev, - sizeof(*jhb100_pinctrl_desc), - GFP_KERNEL); + jhb100_pinctrl_desc = devm_kzalloc_obj(&pdev->dev, *jhb100_pinctrl_desc); if (!jhb100_pinctrl_desc) return -ENOMEM; diff --git a/drivers/pinctrl/stm32/pinctrl-stm32-hdp.c b/drivers/pinctrl/stm32/pinctrl-stm32-hdp.c index cce477e86ef90a..2c193f0f26c130 100644 --- a/drivers/pinctrl/stm32/pinctrl-stm32-hdp.c +++ b/drivers/pinctrl/stm32/pinctrl-stm32-hdp.c @@ -613,7 +613,7 @@ static int stm32_hdp_probe(struct platform_device *pdev) u8 version; int err; - hdp = devm_kzalloc(dev, sizeof(*hdp), GFP_KERNEL); + hdp = devm_kzalloc_obj(dev, *hdp); if (!hdp) return -ENOMEM; hdp->dev = dev; diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c index 98cf9c6f4b598f..405ebb22c9eaf8 100644 --- a/drivers/pinctrl/stm32/pinctrl-stm32.c +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c @@ -1804,14 +1804,14 @@ static int stm32_pctrl_build_state(struct platform_device *pdev) pctl->ngroups = pctl->npins; /* Allocate groups */ - pctl->groups = devm_kcalloc(&pdev->dev, pctl->ngroups, - sizeof(*pctl->groups), GFP_KERNEL); + pctl->groups = devm_kzalloc_objs(&pdev->dev, *pctl->groups, + pctl->ngroups); if (!pctl->groups) return -ENOMEM; /* We assume that one pin is one group, use pin name as group name. */ - pctl->grp_names = devm_kcalloc(&pdev->dev, pctl->ngroups, - sizeof(*pctl->grp_names), GFP_KERNEL); + pctl->grp_names = devm_kzalloc_objs(&pdev->dev, *pctl->grp_names, + pctl->ngroups); if (!pctl->grp_names) return -ENOMEM; @@ -1863,7 +1863,7 @@ int stm32_pctl_probe(struct platform_device *pdev) if (!match_data) return -EINVAL; - pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(dev, *pctl); if (!pctl) return -ENOMEM; @@ -1894,8 +1894,8 @@ int stm32_pctl_probe(struct platform_device *pdev) if (!device_property_read_u32(dev, "st,package", &pctl->pkg)) dev_dbg(pctl->dev, "package detected: %x\n", pctl->pkg); - pctl->pins = devm_kcalloc(pctl->dev, pctl->match_data->npins, - sizeof(*pctl->pins), GFP_KERNEL); + pctl->pins = devm_kzalloc_objs(pctl->dev, *pctl->pins, + pctl->match_data->npins); if (!pctl->pins) return -ENOMEM; @@ -1915,8 +1915,7 @@ int stm32_pctl_probe(struct platform_device *pdev) return ret; } - pins = devm_kcalloc(&pdev->dev, pctl->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, pctl->npins); if (!pins) return -ENOMEM; @@ -1948,13 +1947,11 @@ int stm32_pctl_probe(struct platform_device *pdev) dev_err(dev, "at least one GPIO bank is required\n"); return -EINVAL; } - pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks), - GFP_KERNEL); + pctl->banks = devm_kzalloc_objs(dev, *pctl->banks, banks); if (!pctl->banks) return -ENOMEM; - pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks), - GFP_KERNEL); + pctl->clks = devm_kzalloc_objs(dev, *pctl->clks, banks); if (!pctl->clks) return -ENOMEM; diff --git a/drivers/pinctrl/sunplus/sppctl.c b/drivers/pinctrl/sunplus/sppctl.c index 8a3fb9b56597ed..68ff6d8451bb8e 100644 --- a/drivers/pinctrl/sunplus/sppctl.c +++ b/drivers/pinctrl/sunplus/sppctl.c @@ -540,7 +540,7 @@ static int sppctl_gpio_new(struct platform_device *pdev, struct sppctl_pdata *pc struct gpio_chip *gchip; int err; - spp_gchip = devm_kzalloc(&pdev->dev, sizeof(*spp_gchip), GFP_KERNEL); + spp_gchip = devm_kzalloc_obj(&pdev->dev, *spp_gchip); if (!spp_gchip) return -ENOMEM; pctl->spp_gchip = spp_gchip; @@ -1014,13 +1014,13 @@ static int sppctl_group_groups(struct platform_device *pdev) if (sppctl_list_funcs[i].type == pinmux_type_grp) sppctl->unq_grps_sz += sppctl_list_funcs[i].gnum; - sppctl->unq_grps = devm_kcalloc(&pdev->dev, sppctl->unq_grps_sz + 1, - sizeof(*sppctl->unq_grps), GFP_KERNEL); + sppctl->unq_grps = devm_kzalloc_objs(&pdev->dev, *sppctl->unq_grps, + sppctl->unq_grps_sz + 1); if (!sppctl->unq_grps) return -ENOMEM; - sppctl->g2fp_maps = devm_kcalloc(&pdev->dev, sppctl->unq_grps_sz + 1, - sizeof(*sppctl->g2fp_maps), GFP_KERNEL); + sppctl->g2fp_maps = devm_kzalloc_objs(&pdev->dev, *sppctl->g2fp_maps, + sppctl->unq_grps_sz + 1); if (!sppctl->g2fp_maps) return -ENOMEM; @@ -1100,7 +1100,7 @@ static int sppctl_probe(struct platform_device *pdev) struct sppctl_pdata *sppctl; int ret; - sppctl = devm_kzalloc(&pdev->dev, sizeof(*sppctl), GFP_KERNEL); + sppctl = devm_kzalloc_obj(&pdev->dev, *sppctl); if (!sppctl) return -ENOMEM; platform_set_drvdata(pdev, sppctl); diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c index 8bcd566593ae87..aeaf5534cf80c8 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c @@ -104,7 +104,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev, return ERR_PTR(-EINVAL); } - pins = devm_kcalloc(dev, desc->npins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, desc->npins); if (!pins) return ERR_PTR(-ENOMEM); @@ -200,7 +200,7 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, * Allocate the memory needed for the functions in one table. * We later use pointers into this table to mark each pin. */ - func = devm_kcalloc(dev, num_funcs, sizeof(*func), GFP_KERNEL); + func = devm_kzalloc_objs(dev, *func, num_funcs); if (!func) return -ENOMEM; diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 3ee5012463da37..bf4ec4665e2b26 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -388,7 +388,7 @@ static unsigned long *sunxi_pctrl_build_pin_config(struct device_node *node, if (!configlen) return NULL; - pinconfig = kcalloc(configlen, sizeof(*pinconfig), GFP_KERNEL); + pinconfig = kzalloc_objs(*pinconfig, configlen); if (!pinconfig) return ERR_PTR(-ENOMEM); @@ -1402,9 +1402,8 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) * this means that the number of pins is the maximum group * number we will ever see. */ - pctl->groups = devm_kcalloc(&pdev->dev, - pctl->desc->npins, sizeof(*pctl->groups), - GFP_KERNEL); + pctl->groups = devm_kzalloc_objs(&pdev->dev, *pctl->groups, + pctl->desc->npins); if (!pctl->groups) return -ENOMEM; @@ -1488,10 +1487,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) if (!func_item->groups) { func_item->groups = - devm_kcalloc(&pdev->dev, - func_item->ngroups, - sizeof(*func_item->groups), - GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, + *func_item->groups, + func_item->ngroups); if (!func_item->groups) { kfree(pctl->functions); return -ENOMEM; @@ -1605,7 +1603,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, int i, ret, last_pin, pin_idx, nbanks; struct clk *clk; - pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); + pctl = devm_kzalloc_obj(&pdev->dev, *pctl); if (!pctl) return -ENOMEM; platform_set_drvdata(pdev, pctl); @@ -1643,10 +1641,8 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, else pctl->pow_mod_sel_offset = PIO_POW_MOD_SEL_REG; - pctl->irq_array = devm_kcalloc(&pdev->dev, - IRQ_PER_BANK * pctl->desc->irq_banks, - sizeof(*pctl->irq_array), - GFP_KERNEL); + pctl->irq_array = devm_kzalloc_objs(&pdev->dev, *pctl->irq_array, + IRQ_PER_BANK * pctl->desc->irq_banks); if (!pctl->irq_array) return -ENOMEM; @@ -1669,8 +1665,8 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, last_pin = pctl->desc->pins[pctl->desc->npins - 1].pin.number; nbanks = DIV_ROUND_UP(last_pin + 1 - pctl->desc->pin_base, PINS_PER_BANK); - pctl->dat_shadow = devm_kcalloc(&pdev->dev, nbanks, - sizeof(*pctl->dat_shadow), GFP_KERNEL); + pctl->dat_shadow = devm_kzalloc_objs(&pdev->dev, *pctl->dat_shadow, + nbanks); if (!pctl->dat_shadow) return -ENOMEM; @@ -1687,9 +1683,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, return ret; } - pins = devm_kcalloc(&pdev->dev, - pctl->desc->npins, sizeof(*pins), - GFP_KERNEL); + pins = devm_kzalloc_objs(&pdev->dev, *pins, pctl->desc->npins); if (!pins) return -ENOMEM; @@ -1703,9 +1697,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, pins[pin_idx++] = pin->pin; } - pctrl_desc = devm_kzalloc(&pdev->dev, - sizeof(*pctrl_desc), - GFP_KERNEL); + pctrl_desc = devm_kzalloc_obj(&pdev->dev, *pctrl_desc); if (!pctrl_desc) return -ENOMEM; @@ -1732,7 +1724,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, return PTR_ERR(pctl->pctl_dev); } - pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); + pctl->chip = devm_kzalloc_obj(&pdev->dev, *pctl->chip); if (!pctl->chip) return -ENOMEM; @@ -1769,10 +1761,8 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, goto gpiochip_error; } - pctl->irq = devm_kcalloc(&pdev->dev, - pctl->desc->irq_banks, - sizeof(*pctl->irq), - GFP_KERNEL); + pctl->irq = devm_kzalloc_objs(&pdev->dev, *pctl->irq, + pctl->desc->irq_banks); if (!pctl->irq) { ret = -ENOMEM; goto gpiochip_error; diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c index fb70f8aee56ba2..be6baf411bb9d5 100644 --- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c +++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c @@ -876,7 +876,7 @@ int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev) struct phy *phy; int err; - padctl = devm_kzalloc(&pdev->dev, sizeof(*padctl), GFP_KERNEL); + padctl = devm_kzalloc_obj(&pdev->dev, *padctl); if (!padctl) return -ENOMEM; diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c index 3f58f7db525f74..51684c5dda349a 100644 --- a/drivers/pinctrl/tegra/pinctrl-tegra.c +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c @@ -833,8 +833,8 @@ int tegra_pinctrl_probe(struct platform_device *pdev, int fn, gn, gfn; unsigned long backup_regs_size = 0; - pmx = devm_kzalloc(&pdev->dev, - struct_size(pmx, pingroup_configs, soc_data->ngroups), GFP_KERNEL); + pmx = devm_kzalloc_flex(&pdev->dev, *pmx, pingroup_configs, + soc_data->ngroups); if (!pmx) return -ENOMEM; @@ -846,13 +846,13 @@ int tegra_pinctrl_probe(struct platform_device *pdev, * Each mux group will appear in 4 functions' list of groups. * This over-allocates slightly, since not all groups are mux groups. */ - pmx->group_pins = devm_kcalloc(&pdev->dev, pmx->soc->ngroups * 4, - sizeof(*pmx->group_pins), GFP_KERNEL); + pmx->group_pins = devm_kzalloc_objs(&pdev->dev, *pmx->group_pins, + pmx->soc->ngroups * 4); if (!pmx->group_pins) return -ENOMEM; - pmx->functions = devm_kcalloc(&pdev->dev, pmx->soc->nfunctions, - sizeof(*pmx->functions), GFP_KERNEL); + pmx->functions = devm_kzalloc_objs(&pdev->dev, *pmx->functions, + pmx->soc->nfunctions); if (!pmx->functions) return -ENOMEM; @@ -904,8 +904,7 @@ int tegra_pinctrl_probe(struct platform_device *pdev, } pmx->nbanks = i; - pmx->regs = devm_kcalloc(&pdev->dev, pmx->nbanks, sizeof(*pmx->regs), - GFP_KERNEL); + pmx->regs = devm_kzalloc_objs(&pdev->dev, *pmx->regs, pmx->nbanks); if (!pmx->regs) return -ENOMEM; diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c index 019b302db2b001..28c893bcad2b90 100644 --- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c +++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c @@ -508,24 +508,24 @@ static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev, if (rows < 0) return rows; - *map = devm_kzalloc(iod->dev, sizeof(**map), GFP_KERNEL); + *map = devm_kzalloc_obj(iod->dev, **map); if (!*map) return -ENOMEM; *num_maps = 0; - g = devm_kzalloc(iod->dev, sizeof(*g), GFP_KERNEL); + g = devm_kzalloc_obj(iod->dev, *g); if (!g) { error = -ENOMEM; goto free_map; } - pins = devm_kcalloc(iod->dev, rows, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(iod->dev, *pins, rows); if (!pins) { error = -ENOMEM; goto free_group; } - cfg = devm_kcalloc(iod->dev, rows, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_objs(iod->dev, *cfg, rows); if (!cfg) { error = -ENOMEM; goto free_pins; @@ -759,7 +759,7 @@ static int ti_iodelay_alloc_pins(struct device *dev, nr_pins = ti_iodelay_offset_to_pin(iod, r->regmap_config->max_register); dev_dbg(dev, "Allocating %i pins\n", nr_pins); - iod->pa = devm_kcalloc(dev, nr_pins, sizeof(*iod->pa), GFP_KERNEL); + iod->pa = devm_kzalloc_objs(dev, *iod->pa, nr_pins); if (!iod->pa) return -ENOMEM; @@ -838,7 +838,7 @@ static int ti_iodelay_probe(struct platform_device *pdev) return -EINVAL; } - iod = devm_kzalloc(dev, sizeof(*iod), GFP_KERNEL); + iod = devm_kzalloc_obj(dev, *iod); if (!iod) return -ENOMEM; diff --git a/drivers/pinctrl/ultrarisc/pinctrl-ultrarisc.c b/drivers/pinctrl/ultrarisc/pinctrl-ultrarisc.c index 8fb5b0ea5b9362..1d09c3ca1e7d83 100644 --- a/drivers/pinctrl/ultrarisc/pinctrl-ultrarisc.c +++ b/drivers/pinctrl/ultrarisc/pinctrl-ultrarisc.c @@ -479,11 +479,11 @@ int ur_pinctrl_probe(struct platform_device *pdev, if (!data) return -ENODEV; - desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(&pdev->dev, *desc); if (!desc) return -ENOMEM; - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); + pctrl = devm_kzalloc_obj(&pdev->dev, *pctrl); if (!pctrl) return -ENOMEM; diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c index fbd0fcdb42c8d7..79920a18ae1d58 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c @@ -751,8 +751,7 @@ static int uniphier_pinctrl_add_reg_region(struct device *dev, nregs = DIV_ROUND_UP(count * width, 32); - region = devm_kzalloc(dev, struct_size(region, vals, nregs), - GFP_KERNEL); + region = devm_kzalloc_flex(dev, *region, vals, nregs); if (!region) return -ENOMEM; @@ -876,7 +875,7 @@ int uniphier_pinctrl_probe(struct platform_device *pdev, return -EINVAL; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pinctrl/visconti/pinctrl-common.c b/drivers/pinctrl/visconti/pinctrl-common.c index 21c7e0d18fea6b..b137af1f3b017b 100644 --- a/drivers/pinctrl/visconti/pinctrl-common.c +++ b/drivers/pinctrl/visconti/pinctrl-common.c @@ -284,7 +284,7 @@ int visconti_pinctrl_probe(struct platform_device *pdev, struct pinctrl_pin_desc *pins; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -298,8 +298,7 @@ int visconti_pinctrl_probe(struct platform_device *pdev, return PTR_ERR(priv->base); } - pins = devm_kcalloc(dev, devdata->nr_pins, - sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, devdata->nr_pins); if (!pins) return -ENOMEM; diff --git a/drivers/pinctrl/vt8500/pinctrl-vt8500.c b/drivers/pinctrl/vt8500/pinctrl-vt8500.c index 1cb5a75480c9da..14b02c59d5bde2 100644 --- a/drivers/pinctrl/vt8500/pinctrl-vt8500.c +++ b/drivers/pinctrl/vt8500/pinctrl-vt8500.c @@ -449,7 +449,7 @@ static int vt8500_pinctrl_probe(struct platform_device *pdev) { struct wmt_pinctrl_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8505.c b/drivers/pinctrl/vt8500/pinctrl-wm8505.c index 1584a198478d8c..e56fd690edb6d7 100644 --- a/drivers/pinctrl/vt8500/pinctrl-wm8505.c +++ b/drivers/pinctrl/vt8500/pinctrl-wm8505.c @@ -480,7 +480,7 @@ static int wm8505_pinctrl_probe(struct platform_device *pdev) { struct wmt_pinctrl_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8650.c b/drivers/pinctrl/vt8500/pinctrl-wm8650.c index 097fa43d69fbb5..37d159e95fb6e1 100644 --- a/drivers/pinctrl/vt8500/pinctrl-wm8650.c +++ b/drivers/pinctrl/vt8500/pinctrl-wm8650.c @@ -318,7 +318,7 @@ static int wm8650_pinctrl_probe(struct platform_device *pdev) { struct wmt_pinctrl_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8750.c b/drivers/pinctrl/vt8500/pinctrl-wm8750.c index 94d333b9aed36e..8b129bf5eb18b5 100644 --- a/drivers/pinctrl/vt8500/pinctrl-wm8750.c +++ b/drivers/pinctrl/vt8500/pinctrl-wm8750.c @@ -357,7 +357,7 @@ static int wm8750_pinctrl_probe(struct platform_device *pdev) { struct wmt_pinctrl_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8850.c b/drivers/pinctrl/vt8500/pinctrl-wm8850.c index 869e5addb7695d..0ef3080eb18f3e 100644 --- a/drivers/pinctrl/vt8500/pinctrl-wm8850.c +++ b/drivers/pinctrl/vt8500/pinctrl-wm8850.c @@ -336,7 +336,7 @@ static int wm8850_pinctrl_probe(struct platform_device *pdev) { struct wmt_pinctrl_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/arm64/Kconfig b/drivers/platform/arm64/Kconfig index 2a84775a13a99c..3f879410b311f5 100644 --- a/drivers/platform/arm64/Kconfig +++ b/drivers/platform/arm64/Kconfig @@ -40,7 +40,6 @@ config EC_ASUS_GLYMUR depends on HWMON depends on INPUT depends on PM - depends on THERMAL || THERMAL=n select NEW_LEDS select LEDS_CLASS help diff --git a/drivers/platform/arm64/asus-glymur-ec.c b/drivers/platform/arm64/asus-glymur-ec.c index d75923fac9c4c9..b741afb189742c 100644 --- a/drivers/platform/arm64/asus-glymur-ec.c +++ b/drivers/platform/arm64/asus-glymur-ec.c @@ -510,7 +510,7 @@ static int asus_glymur_ec_probe(struct i2c_client *client) struct asus_ec *ec; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/arm64/huawei-gaokun-ec.c b/drivers/platform/arm64/huawei-gaokun-ec.c index d4ce8ad6426c5c..ac21f732d041bc 100644 --- a/drivers/platform/arm64/huawei-gaokun-ec.c +++ b/drivers/platform/arm64/huawei-gaokun-ec.c @@ -746,7 +746,7 @@ static int gaokun_ec_probe(struct i2c_client *client) struct gaokun_ec *ec; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/arm64/lenovo-thinkpad-t14s.c b/drivers/platform/arm64/lenovo-thinkpad-t14s.c index 7a875877c8f307..873747838a4faf 100644 --- a/drivers/platform/arm64/lenovo-thinkpad-t14s.c +++ b/drivers/platform/arm64/lenovo-thinkpad-t14s.c @@ -567,7 +567,7 @@ static int t14s_ec_probe(struct i2c_client *client) struct t14s_ec *ec; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/arm64/lenovo-yoga-c630.c b/drivers/platform/arm64/lenovo-yoga-c630.c index cad40c58c55b85..5702e19dbbd417 100644 --- a/drivers/platform/arm64/lenovo-yoga-c630.c +++ b/drivers/platform/arm64/lenovo-yoga-c630.c @@ -209,7 +209,7 @@ static int yoga_c630_ec_probe(struct i2c_client *client) struct yoga_c630_ec *ec; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c b/drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c index 257d64eb0e56f2..36dcbff5875516 100644 --- a/drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c +++ b/drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c @@ -410,7 +410,7 @@ static int slim7x11_ec_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return dev_err_probe(dev, -ENODEV, "adapter lacks SMBus block transfers\n"); - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/arm64/qcom-hamoa-ec.c b/drivers/platform/arm64/qcom-hamoa-ec.c index d34afd901324d8..dd35fa39188be4 100644 --- a/drivers/platform/arm64/qcom-hamoa-ec.c +++ b/drivers/platform/arm64/qcom-hamoa-ec.c @@ -362,7 +362,7 @@ static int qcom_ec_probe(struct i2c_client *client) unsigned int i; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; @@ -392,7 +392,8 @@ static int qcom_ec_probe(struct i2c_client *client) return 0; } - ec->ec_cdev = devm_kcalloc(dev, ec->thermal_cap.fan_cnt, sizeof(*ec->ec_cdev), GFP_KERNEL); + ec->ec_cdev = devm_kzalloc_objs(dev, *ec->ec_cdev, + ec->thermal_cap.fan_cnt); if (!ec->ec_cdev) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 5d0f5a9187b1e4..81631b36340228 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -43,7 +43,7 @@ struct cros_ec_device *cros_ec_device_alloc(struct device *dev) { struct cros_ec_device *ec_dev; - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); + ec_dev = devm_kzalloc_obj(dev, *ec_dev); if (!ec_dev) return NULL; diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index c3e40ad7e03c6c..97a6c96aba137d 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -480,7 +480,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd) struct cros_ec_debugfs *debug_info; int ret; - debug_info = devm_kzalloc(ec->dev, sizeof(*debug_info), GFP_KERNEL); + debug_info = devm_kzalloc_obj(ec->dev, *debug_info); if (!debug_info) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_ishtp.c b/drivers/platform/chrome/cros_ec_ishtp.c index b21a27ad376250..3ab3ac22e69dd3 100644 --- a/drivers/platform/chrome/cros_ec_ishtp.c +++ b/drivers/platform/chrome/cros_ec_ishtp.c @@ -600,9 +600,8 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device) { int rv; struct ishtp_cl *cros_ish_cl; - struct ishtp_cl_data *client_data = - devm_kzalloc(ishtp_device(cl_device), - sizeof(*client_data), GFP_KERNEL); + struct ishtp_cl_data *client_data = devm_kzalloc_obj(ishtp_device(cl_device), + *client_data); if (!client_data) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 78cfff80cdeafe..1e683e90a9dfca 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -520,7 +520,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) int irq, ret; u32 quirks; - ec_lpc = devm_kzalloc(dev, sizeof(*ec_lpc), GFP_KERNEL); + ec_lpc = devm_kzalloc_obj(dev, *ec_lpc); if (!ec_lpc) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_rpmsg.c b/drivers/platform/chrome/cros_ec_rpmsg.c index 7390c2c91ea5d7..cb6bdff55c10ee 100644 --- a/drivers/platform/chrome/cros_ec_rpmsg.c +++ b/drivers/platform/chrome/cros_ec_rpmsg.c @@ -220,7 +220,7 @@ static int cros_ec_rpmsg_probe(struct rpmsg_device *rpdev) if (!ec_dev) return -ENOMEM; - ec_rpmsg = devm_kzalloc(dev, sizeof(*ec_rpmsg), GFP_KERNEL); + ec_rpmsg = devm_kzalloc_obj(dev, *ec_rpmsg); if (!ec_rpmsg) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_sensorhub.c b/drivers/platform/chrome/cros_ec_sensorhub.c index a8395ab0a12a0a..d1b0e0cbc4181e 100644 --- a/drivers/platform/chrome/cros_ec_sensorhub.c +++ b/drivers/platform/chrome/cros_ec_sensorhub.c @@ -156,7 +156,7 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev) msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; - data = devm_kzalloc(dev, sizeof(struct cros_ec_sensorhub), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct cros_ec_sensorhub); if (!data) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_sensorhub_ring.c b/drivers/platform/chrome/cros_ec_sensorhub_ring.c index d92b6021372073..448f11ba5e620b 100644 --- a/drivers/platform/chrome/cros_ec_sensorhub_ring.c +++ b/drivers/platform/chrome/cros_ec_sensorhub_ring.c @@ -1022,10 +1022,9 @@ int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub) * Allocate the callback area based on the number of sensors. * Add one for the sensor ring. */ - sensorhub->push_data = devm_kcalloc(sensorhub->dev, - sensorhub->sensor_num, - sizeof(*sensorhub->push_data), - GFP_KERNEL); + sensorhub->push_data = devm_kzalloc_objs(sensorhub->dev, + *sensorhub->push_data, + sensorhub->sensor_num); if (!sensorhub->push_data) return -ENOMEM; @@ -1034,10 +1033,9 @@ int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub) EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS); if (sensorhub->tight_timestamps) { - sensorhub->batch_state = devm_kcalloc(sensorhub->dev, - sensorhub->sensor_num, - sizeof(*sensorhub->batch_state), - GFP_KERNEL); + sensorhub->batch_state = devm_kzalloc_objs(sensorhub->dev, + *sensorhub->batch_state, + sensorhub->sensor_num); if (!sensorhub->batch_state) return -ENOMEM; } @@ -1076,8 +1074,8 @@ int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub) * timestamps properly. */ sensorhub->fifo_size = sensorhub->resp->fifo_info.size; - sensorhub->ring = devm_kcalloc(sensorhub->dev, sensorhub->fifo_size, - sizeof(*sensorhub->ring), GFP_KERNEL); + sensorhub->ring = devm_kzalloc_objs(sensorhub->dev, *sensorhub->ring, + sensorhub->fifo_size); if (!sensorhub->ring) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index 28fa82f8cb07e0..a9c82b79297a5f 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -745,7 +745,7 @@ static int cros_ec_spi_probe(struct spi_device *spi) if (err < 0) return err; - ec_spi = devm_kzalloc(dev, sizeof(*ec_spi), GFP_KERNEL); + ec_spi = devm_kzalloc_obj(dev, *ec_spi); if (ec_spi == NULL) return -ENOMEM; ec_spi->spi = spi; diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 5871fe031f14d3..df502db6330cbd 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -512,7 +512,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) dev_dbg(dev, "Registering port %d\n", port_num); - cros_port = devm_kzalloc(dev, sizeof(*cros_port), GFP_KERNEL); + cros_port = devm_kzalloc_obj(dev, *cros_port); if (!cros_port) { ret = -ENOMEM; goto unregister_ports; @@ -958,7 +958,7 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ } /* If no memory is available we should unregister and exit. */ - node = devm_kzalloc(typec->dev, sizeof(*node), GFP_KERNEL); + node = devm_kzalloc_obj(typec->dev, *node); if (!node) { ret = -ENOMEM; typec_unregister_altmode(amode); @@ -1400,7 +1400,7 @@ static int cros_typec_probe(struct platform_device *pdev) struct ec_response_usb_pd_ports resp; int ret, i; - typec = devm_kzalloc(dev, sizeof(*typec), GFP_KERNEL); + typec = devm_kzalloc_obj(dev, *typec); if (!typec) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_ec_uart.c b/drivers/platform/chrome/cros_ec_uart.c index d5b37414ff1245..2c6c6b7a72df9c 100644 --- a/drivers/platform/chrome/cros_ec_uart.c +++ b/drivers/platform/chrome/cros_ec_uart.c @@ -255,7 +255,7 @@ static int cros_ec_uart_probe(struct serdev_device *serdev) struct cros_ec_uart *ec_uart; int ret; - ec_uart = devm_kzalloc(dev, sizeof(*ec_uart), GFP_KERNEL); + ec_uart = devm_kzalloc_obj(dev, *ec_uart); if (!ec_uart) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_hps_i2c.c b/drivers/platform/chrome/cros_hps_i2c.c index 3b948562783129..c320489bfe1a04 100644 --- a/drivers/platform/chrome/cros_hps_i2c.c +++ b/drivers/platform/chrome/cros_hps_i2c.c @@ -62,7 +62,7 @@ static int hps_i2c_probe(struct i2c_client *client) struct hps_drvdata *hps; int ret; - hps = devm_kzalloc(&client->dev, sizeof(*hps), GFP_KERNEL); + hps = devm_kzalloc_obj(&client->dev, *hps); if (!hps) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index 94888db1c00e81..8f992a8f79d05d 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -188,7 +188,7 @@ static int keyboard_led_probe(struct platform_device *pdev) if (!drvdata) return -EINVAL; - keyboard_led = devm_kzalloc(&pdev->dev, sizeof(*keyboard_led), GFP_KERNEL); + keyboard_led = devm_kzalloc_obj(&pdev->dev, *keyboard_led); if (!keyboard_led) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platform/chrome/cros_typec_altmode.c index 66c546bf89b532..0d06fb2a7d0bc7 100644 --- a/drivers/platform/chrome/cros_typec_altmode.c +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -318,7 +318,7 @@ cros_typec_register_displayport(struct cros_typec_port *port, if (IS_ERR(alt)) return alt; - dp_data = devm_kzalloc(&alt->dev, sizeof(*dp_data), GFP_KERNEL); + dp_data = devm_kzalloc_obj(&alt->dev, *dp_data); if (!dp_data) { typec_unregister_altmode(alt); return ERR_PTR(-ENOMEM); @@ -352,7 +352,7 @@ cros_typec_register_thunderbolt(struct cros_typec_port *port, if (IS_ERR(alt)) return alt; - adata = devm_kzalloc(&alt->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&alt->dev, *adata); if (!adata) { typec_unregister_altmode(alt); return ERR_PTR(-ENOMEM); diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index fe0eddd2cf45bd..81e2857ab45232 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -221,7 +221,7 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) } device_for_each_child_node(dev, fwnode) { - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) { ret = -ENOMEM; goto err_switch; @@ -276,7 +276,7 @@ static int cros_typec_switch_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct cros_typec_switch_data *sdata; - sdata = devm_kzalloc(dev, sizeof(*sdata), GFP_KERNEL); + sdata = devm_kzalloc_obj(dev, *sdata); if (!sdata) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_usbpd_logger.c b/drivers/platform/chrome/cros_usbpd_logger.c index 0eb714d679c85a..cd9d16439da80f 100644 --- a/drivers/platform/chrome/cros_usbpd_logger.c +++ b/drivers/platform/chrome/cros_usbpd_logger.c @@ -201,7 +201,7 @@ static int cros_usbpd_logger_probe(struct platform_device *pd) struct logger_data *logger; int ret; - logger = devm_kzalloc(dev, sizeof(*logger), GFP_KERNEL); + logger = devm_kzalloc_obj(dev, *logger); if (!logger) return -ENOMEM; diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c index 25da31ec19969d..61abe3e42f4df1 100644 --- a/drivers/platform/chrome/cros_usbpd_notify.c +++ b/drivers/platform/chrome/cros_usbpd_notify.c @@ -106,7 +106,7 @@ static int cros_usbpd_notify_probe_acpi(struct platform_device *pdev) adev = ACPI_COMPANION(dev); - pdnotify = devm_kzalloc(dev, sizeof(*pdnotify), GFP_KERNEL); + pdnotify = devm_kzalloc_obj(dev, *pdnotify); if (!pdnotify) return -ENOMEM; @@ -203,7 +203,7 @@ static int cros_usbpd_notify_probe_plat(struct platform_device *pdev) struct cros_usbpd_notify_data *pdnotify; int ret; - pdnotify = devm_kzalloc(dev, sizeof(*pdnotify), GFP_KERNEL); + pdnotify = devm_kzalloc_obj(dev, *pdnotify); if (!pdnotify) return -ENOMEM; diff --git a/drivers/platform/chrome/wilco_ec/core.c b/drivers/platform/chrome/wilco_ec/core.c index 9d4521889d40de..8f3fc3876735b3 100644 --- a/drivers/platform/chrome/wilco_ec/core.c +++ b/drivers/platform/chrome/wilco_ec/core.c @@ -40,7 +40,7 @@ static int wilco_ec_probe(struct platform_device *pdev) struct wilco_ec_device *ec; int ret; - ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + ec = devm_kzalloc_obj(dev, *ec); if (!ec) return -ENOMEM; diff --git a/drivers/platform/chrome/wilco_ec/debugfs.c b/drivers/platform/chrome/wilco_ec/debugfs.c index 32fb11939b9be9..e52dee9360a624 100644 --- a/drivers/platform/chrome/wilco_ec/debugfs.c +++ b/drivers/platform/chrome/wilco_ec/debugfs.c @@ -245,7 +245,7 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev) { struct wilco_ec_device *ec = dev_get_drvdata(pdev->dev.parent); - debug_info = devm_kzalloc(&pdev->dev, sizeof(*debug_info), GFP_KERNEL); + debug_info = devm_kzalloc_obj(&pdev->dev, *debug_info); if (!debug_info) return 0; debug_info->ec = ec; diff --git a/drivers/platform/chrome/wilco_ec/keyboard_leds.c b/drivers/platform/chrome/wilco_ec/keyboard_leds.c index 6ce9c678206520..dabebf6bcfa39e 100644 --- a/drivers/platform/chrome/wilco_ec/keyboard_leds.c +++ b/drivers/platform/chrome/wilco_ec/keyboard_leds.c @@ -185,7 +185,7 @@ int wilco_keyboard_leds_init(struct wilco_ec_device *ec) if (!leds_exist) return 0; - wkl = devm_kzalloc(ec->dev, sizeof(*wkl), GFP_KERNEL); + wkl = devm_kzalloc_obj(ec->dev, *wkl); if (!wkl) return -ENOMEM; diff --git a/drivers/platform/cznic/turris-omnia-mcu-base.c b/drivers/platform/cznic/turris-omnia-mcu-base.c index f0416302a1f3c1..60d8690f923d24 100644 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c @@ -361,7 +361,7 @@ static int omnia_mcu_probe(struct i2c_client *client) if (!client->irq) return dev_err_probe(dev, -EINVAL, "IRQ resource not found\n"); - mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL); + mcu = devm_kzalloc_obj(dev, *mcu); if (!mcu) return -ENOMEM; diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 3f34db896ecef7..e30128e771ca8d 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -873,7 +873,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev) struct resource *r; struct goldfish_pipe_dev *dev; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/platform/mellanox/mlx-platform.c b/drivers/platform/mellanox/mlx-platform.c index efcba68d3aa51d..c6f0022062fee9 100644 --- a/drivers/platform/mellanox/mlx-platform.c +++ b/drivers/platform/mellanox/mlx-platform.c @@ -8545,8 +8545,7 @@ static int mlxplat_probe(struct platform_device *pdev) if (err) return err; - priv = devm_kzalloc(&mlxplat_dev->dev, sizeof(struct mlxplat_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&mlxplat_dev->dev, struct mlxplat_priv); if (!priv) { err = -ENOMEM; goto fail_alloc; diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c index 2ad9e2b0493c4b..f4a33b9087a072 100644 --- a/drivers/platform/mellanox/mlxbf-pmc.c +++ b/drivers/platform/mellanox/mlxbf-pmc.c @@ -2028,15 +2028,15 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, unsigned int blk_ attr = NULL; } - pmc->block[blk_num].attr_counter = devm_kcalloc( - dev, pmc->block[blk_num].counters, - sizeof(struct mlxbf_pmc_attribute), GFP_KERNEL); + pmc->block[blk_num].attr_counter = devm_kzalloc_objs(dev, + struct mlxbf_pmc_attribute, + pmc->block[blk_num].counters); if (!pmc->block[blk_num].attr_counter) return -ENOMEM; - pmc->block[blk_num].attr_event = devm_kcalloc( - dev, pmc->block[blk_num].counters, - sizeof(struct mlxbf_pmc_attribute), GFP_KERNEL); + pmc->block[blk_num].attr_event = devm_kzalloc_objs(dev, + struct mlxbf_pmc_attribute, + pmc->block[blk_num].counters); if (!pmc->block[blk_num].attr_event) return -ENOMEM; @@ -2084,8 +2084,9 @@ static int mlxbf_pmc_init_perftype_reg(struct device *dev, unsigned int blk_num) if (!events) return -ENOENT; - pmc->block[blk_num].attr_event = devm_kcalloc( - dev, count, sizeof(struct mlxbf_pmc_attribute), GFP_KERNEL); + pmc->block[blk_num].attr_event = devm_kzalloc_objs(dev, + struct mlxbf_pmc_attribute, + count); if (!pmc->block[blk_num].attr_event) return -ENOMEM; @@ -2281,7 +2282,7 @@ static int mlxbf_pmc_probe(struct platform_device *pdev) if (!mlxbf_pmc_guid_match(&guid, &res)) return -ENODEV; - pmc = devm_kzalloc(dev, sizeof(struct mlxbf_pmc_context), GFP_KERNEL); + pmc = devm_kzalloc_obj(dev, struct mlxbf_pmc_context); if (!pmc) return -ENOMEM; diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c index d67215df7371ed..4809caf9af0e2e 100644 --- a/drivers/platform/mellanox/mlxbf-tmfifo.c +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c @@ -1358,7 +1358,7 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev) return rc; } - fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); + fifo = devm_kzalloc_obj(dev, *fifo); if (!fifo) return -ENOMEM; diff --git a/drivers/platform/mellanox/mlxreg-dpu.c b/drivers/platform/mellanox/mlxreg-dpu.c index 39f89c47144a2f..bfb63cd487af52 100644 --- a/drivers/platform/mellanox/mlxreg-dpu.c +++ b/drivers/platform/mellanox/mlxreg-dpu.c @@ -534,7 +534,7 @@ static int mlxreg_dpu_probe(struct platform_device *pdev) if (!data->hpdev.adapter) return -EPROBE_DEFER; - mlxreg_dpu = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_dpu), GFP_KERNEL); + mlxreg_dpu = devm_kzalloc_obj(&pdev->dev, *mlxreg_dpu); if (!mlxreg_dpu) { err = -ENOMEM; goto alloc_fail; diff --git a/drivers/platform/mellanox/mlxreg-hotplug.c b/drivers/platform/mellanox/mlxreg-hotplug.c index d6549dd2177265..79a9d38440a421 100644 --- a/drivers/platform/mellanox/mlxreg-hotplug.c +++ b/drivers/platform/mellanox/mlxreg-hotplug.c @@ -325,10 +325,8 @@ static int mlxreg_hotplug_attr_init(struct mlxreg_hotplug_priv_data *priv) num_attrs += k; } - priv->group.attrs = devm_kcalloc(&priv->pdev->dev, - num_attrs, - sizeof(struct attribute *), - GFP_KERNEL); + priv->group.attrs = devm_kzalloc_objs(&priv->pdev->dev, + struct attribute *, num_attrs); if (!priv->group.attrs) return -ENOMEM; @@ -721,7 +719,7 @@ static int mlxreg_hotplug_probe(struct platform_device *pdev) return -EPROBE_DEFER; i2c_put_adapter(deferred_adap); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/mellanox/mlxreg-io.c b/drivers/platform/mellanox/mlxreg-io.c index 97fefe6c38d1d3..1190861de1f606 100644 --- a/drivers/platform/mellanox/mlxreg-io.c +++ b/drivers/platform/mellanox/mlxreg-io.c @@ -181,10 +181,9 @@ static int mlxreg_io_attr_init(struct mlxreg_io_priv_data *priv) { int i; - priv->group.attrs = devm_kcalloc(&priv->pdev->dev, - priv->pdata->counter, - sizeof(struct attribute *), - GFP_KERNEL); + priv->group.attrs = devm_kzalloc_objs(&priv->pdev->dev, + struct attribute *, + priv->pdata->counter); if (!priv->group.attrs) return -ENOMEM; @@ -225,7 +224,7 @@ static int mlxreg_io_probe(struct platform_device *pdev) struct mlxreg_io_priv_data *priv; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/mellanox/mlxreg-lc.c b/drivers/platform/mellanox/mlxreg-lc.c index d1518598dfed5c..3a538ebb48505e 100644 --- a/drivers/platform/mellanox/mlxreg-lc.c +++ b/drivers/platform/mellanox/mlxreg-lc.c @@ -819,7 +819,7 @@ static int mlxreg_lc_probe(struct platform_device *pdev) if (!data) return -EINVAL; - mlxreg_lc = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_lc), GFP_KERNEL); + mlxreg_lc = devm_kzalloc_obj(&pdev->dev, *mlxreg_lc); if (!mlxreg_lc) return -ENOMEM; diff --git a/drivers/platform/mellanox/nvsw-sn2201.c b/drivers/platform/mellanox/nvsw-sn2201.c index 92b58ba8f97bdc..d4d1970c47e4b7 100644 --- a/drivers/platform/mellanox/nvsw-sn2201.c +++ b/drivers/platform/mellanox/nvsw-sn2201.c @@ -1293,7 +1293,7 @@ static int nvsw_sn2201_probe(struct platform_device *pdev) const char *sku; int ret; - nvsw_sn2201 = devm_kzalloc(&pdev->dev, sizeof(*nvsw_sn2201), GFP_KERNEL); + nvsw_sn2201 = devm_kzalloc_obj(&pdev->dev, *nvsw_sn2201); if (!nvsw_sn2201) return -ENOMEM; diff --git a/drivers/platform/olpc/olpc-xo175-ec.c b/drivers/platform/olpc/olpc-xo175-ec.c index bee271a4fda1a9..64920c7aa75edd 100644 --- a/drivers/platform/olpc/olpc-xo175-ec.c +++ b/drivers/platform/olpc/olpc-xo175-ec.c @@ -669,7 +669,7 @@ static int olpc_xo175_ec_probe(struct spi_device *spi) return -EBUSY; } - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c b/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c index e7864170325222..dae1fc0fea2925 100644 --- a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c +++ b/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c @@ -291,7 +291,7 @@ vchiq_platform_init_state(struct vchiq_state *state) { struct vchiq_arm_state *platform_state; - platform_state = devm_kzalloc(state->dev, sizeof(*platform_state), GFP_KERNEL); + platform_state = devm_kzalloc_obj(state->dev, *platform_state); if (!platform_state) return -ENOMEM; @@ -1387,7 +1387,7 @@ static int vchiq_probe(struct platform_device *pdev) return -ENOENT; } - mgmt = devm_kzalloc(&pdev->dev, sizeof(*mgmt), GFP_KERNEL); + mgmt = devm_kzalloc_obj(&pdev->dev, *mgmt); if (!mgmt) return -ENOMEM; diff --git a/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c b/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c index 48d6b1d743293e..e809a19f553584 100644 --- a/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c +++ b/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c @@ -2350,8 +2350,7 @@ recycle_func(void *v) length = sizeof(*found) * BITSET_SIZE(VCHIQ_MAX_SERVICES); - found = kmalloc_array(BITSET_SIZE(VCHIQ_MAX_SERVICES), sizeof(*found), - GFP_KERNEL); + found = kmalloc_objs(*found, BITSET_SIZE(VCHIQ_MAX_SERVICES)); if (!found) return -ENOMEM; diff --git a/drivers/platform/surface/surface3_power.c b/drivers/platform/surface/surface3_power.c index 94fdddc7f207bd..72a7625780eaa4 100644 --- a/drivers/platform/surface/surface3_power.c +++ b/drivers/platform/surface/surface3_power.c @@ -510,7 +510,7 @@ static int mshw0011_probe(struct i2c_client *client) struct mshw0011_data *data; int error, mask; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c index 593a7aba62432e..54991075106995 100644 --- a/drivers/platform/surface/surface_acpi_notify.c +++ b/drivers/platform/surface/surface_acpi_notify.c @@ -795,7 +795,7 @@ static int san_probe(struct platform_device *pdev) if (status) return status; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c index 541e9180f97605..cad9c429e19cad 100644 --- a/drivers/platform/surface/surface_aggregator_hub.c +++ b/drivers/platform/surface/surface_aggregator_hub.c @@ -164,7 +164,7 @@ static int ssam_hub_probe(struct ssam_device *sdev) return -EINVAL; } - hub = devm_kzalloc(&sdev->dev, sizeof(*hub), GFP_KERNEL); + hub = devm_kzalloc_obj(&sdev->dev, *hub); if (!hub) return -ENOMEM; diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c index 13031c329553d4..35f777e9d884f6 100644 --- a/drivers/platform/surface/surface_aggregator_tabletsw.c +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c @@ -126,7 +126,7 @@ static int ssam_tablet_sw_probe(struct ssam_device *sdev) return -EINVAL; } - sw = devm_kzalloc(&sdev->dev, sizeof(*sw), GFP_KERNEL); + sw = devm_kzalloc_obj(&sdev->dev, *sw); if (!sw) return -ENOMEM; diff --git a/drivers/platform/surface/surface_gpe.c b/drivers/platform/surface/surface_gpe.c index 29b264f2a444e4..60c19283c79b8a 100644 --- a/drivers/platform/surface/surface_gpe.c +++ b/drivers/platform/surface/surface_gpe.c @@ -240,7 +240,7 @@ static int surface_gpe_probe(struct platform_device *pdev) return ret; } - lid = devm_kzalloc(&pdev->dev, sizeof(*lid), GFP_KERNEL); + lid = devm_kzalloc_obj(&pdev->dev, *lid); if (!lid) return -ENOMEM; diff --git a/drivers/platform/surface/surface_hotplug.c b/drivers/platform/surface/surface_hotplug.c index 33a8a9d41900d8..24d26bb65b3916 100644 --- a/drivers/platform/surface/surface_hotplug.c +++ b/drivers/platform/surface/surface_hotplug.c @@ -215,7 +215,7 @@ static int surface_hotplug_probe(struct platform_device *pdev) if (status) return status; - sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL); + sdev = devm_kzalloc_obj(&pdev->dev, *sdev); if (!sdev) return -ENOMEM; diff --git a/drivers/platform/surface/surface_platform_profile.c b/drivers/platform/surface/surface_platform_profile.c index 0e479e35e66e16..52c57447266ffa 100644 --- a/drivers/platform/surface/surface_platform_profile.c +++ b/drivers/platform/surface/surface_platform_profile.c @@ -221,7 +221,7 @@ static int surface_platform_profile_probe(struct ssam_device *sdev) { struct ssam_platform_profile_device *tpd; - tpd = devm_kzalloc(&sdev->dev, sizeof(*tpd), GFP_KERNEL); + tpd = devm_kzalloc_obj(&sdev->dev, *tpd); if (!tpd) return -ENOMEM; diff --git a/drivers/platform/wmi/bmof.c b/drivers/platform/wmi/bmof.c index 6623cf60e4b4d7..cc7ac281e54257 100644 --- a/drivers/platform/wmi/bmof.c +++ b/drivers/platform/wmi/bmof.c @@ -58,7 +58,7 @@ static int wmi_bmof_probe(struct wmi_device *wdev, const void *context) struct wmi_buffer *buffer; int ret; - buffer = devm_kzalloc(&wdev->dev, sizeof(*buffer), GFP_KERNEL); + buffer = devm_kzalloc_obj(&wdev->dev, *buffer); if (!buffer) return -ENOMEM; diff --git a/drivers/platform/x86/acer-wmi-battery.c b/drivers/platform/x86/acer-wmi-battery.c index 10a34d4ab0581e..431f1bdc669e12 100644 --- a/drivers/platform/x86/acer-wmi-battery.c +++ b/drivers/platform/x86/acer-wmi-battery.c @@ -277,7 +277,7 @@ static int acer_wmi_battery_probe(struct wmi_device *wdev, const void *context) { struct acer_wmi_battery_data *data; - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/adv_swbutton.c b/drivers/platform/x86/adv_swbutton.c index 8f7a26e6de81dd..efa42deb420b6e 100644 --- a/drivers/platform/x86/adv_swbutton.c +++ b/drivers/platform/x86/adv_swbutton.c @@ -56,7 +56,7 @@ static int adv_swbutton_probe(struct platform_device *device) if (!handle) return -ENODEV; - button = devm_kzalloc(&device->dev, sizeof(*button), GFP_KERNEL); + button = devm_kzalloc_obj(&device->dev, *button); if (!button) return -ENOMEM; diff --git a/drivers/platform/x86/amd/amd_halo_led.c b/drivers/platform/x86/amd/amd_halo_led.c index b21d956c7d96cf..b9e58644db22d8 100644 --- a/drivers/platform/x86/amd/amd_halo_led.c +++ b/drivers/platform/x86/amd/amd_halo_led.c @@ -254,7 +254,7 @@ static int amd_halo_probe(struct wmi_device *wdev, const void *context) u8 r, g, b; int ret; - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/amd/amd_isp4.c b/drivers/platform/x86/amd/amd_isp4.c index 0d494899502c03..9183611877f0aa 100644 --- a/drivers/platform/x86/amd/amd_isp4.c +++ b/drivers/platform/x86/amd/amd_isp4.c @@ -317,7 +317,7 @@ static struct amdisp_platform *prepare_amdisp_platform(struct device *dev, struct amdisp_platform *isp4_platform; int ret; - isp4_platform = devm_kzalloc(dev, sizeof(*isp4_platform), GFP_KERNEL); + isp4_platform = devm_kzalloc_obj(dev, *isp4_platform); if (!isp4_platform) return ERR_PTR(-ENOMEM); diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c index a923345dd1cf68..86a7f4332c35a3 100644 --- a/drivers/platform/x86/amd/hfi/hfi.c +++ b/drivers/platform/x86/amd/hfi/hfi.c @@ -234,13 +234,11 @@ static int amd_hfi_alloc_class_data(struct platform_device *pdev) struct amd_hfi_classes *classes; int *ipcc_scores; - classes = devm_kcalloc(dev, - nr_class_id, - sizeof(struct amd_hfi_classes), - GFP_KERNEL); + classes = devm_kzalloc_objs(dev, struct amd_hfi_classes, + nr_class_id); if (!classes) return -ENOMEM; - ipcc_scores = devm_kcalloc(dev, nr_class_id, sizeof(int), GFP_KERNEL); + ipcc_scores = devm_kzalloc_objs(dev, int, nr_class_id); if (!ipcc_scores) return -ENOMEM; hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, idx); @@ -367,13 +365,13 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev, acpi_status status; int ret; - pcc_mbox_channels = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT, - sizeof(*pcc_mbox_channels), GFP_KERNEL); + pcc_mbox_channels = devm_kzalloc_objs(&pdev->dev, *pcc_mbox_channels, + AMD_HFI_MAILBOX_COUNT); if (!pcc_mbox_channels) return -ENOMEM; - pcc_chan = devm_kcalloc(&pdev->dev, AMD_HFI_MAILBOX_COUNT, - sizeof(*pcc_chan), GFP_KERNEL); + pcc_chan = devm_kzalloc_objs(&pdev->dev, *pcc_chan, + AMD_HFI_MAILBOX_COUNT); if (!pcc_chan) return -ENOMEM; @@ -481,7 +479,7 @@ static int amd_hfi_probe(struct platform_device *pdev) if (!acpi_match_device(amd_hfi_platform_match, &pdev->dev)) return -ENODEV; - amd_hfi_data = devm_kzalloc(&pdev->dev, sizeof(*amd_hfi_data), GFP_KERNEL); + amd_hfi_data = devm_kzalloc_obj(&pdev->dev, *amd_hfi_data); if (!amd_hfi_data) return -ENOMEM; diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c index e9b2b809c0f52a..c3dc7c9f45acc6 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -226,9 +226,8 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) { int ret; - hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets, - sizeof(*hsmp_pdev->sock), - GFP_KERNEL); + hsmp_pdev->sock = devm_kzalloc_objs(&pdev->dev, *hsmp_pdev->sock, + hsmp_pdev->num_sockets); if (!hsmp_pdev->sock) return -ENOMEM; diff --git a/drivers/platform/x86/amd/pmc/mp2_stb.c b/drivers/platform/x86/amd/pmc/mp2_stb.c index 9775ddc1b27afb..293cb4602fef5d 100644 --- a/drivers/platform/x86/amd/pmc/mp2_stb.c +++ b/drivers/platform/x86/amd/pmc/mp2_stb.c @@ -228,7 +228,7 @@ void amd_mp2_stb_init(struct amd_pmc_dev *dev) struct pci_dev *pdev; int rc; - mp2 = devm_kzalloc(dev->dev, sizeof(*mp2), GFP_KERNEL); + mp2 = devm_kzalloc_obj(dev->dev, *mp2); if (!mp2) return; diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index ba932444858680..926de4de2cdb61 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -455,7 +455,7 @@ static int amd_pmf_probe(struct platform_device *pdev) if (id->driver_data == 0x100 && !force_load) return -ENODEV; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 3fe79f0f37c563..2ed2ea4abeb6a4 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -580,7 +580,7 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) amd_pmf_hex_dump_pb(dev); - dev->prev_data = devm_kzalloc(dev->dev, sizeof(*dev->prev_data), GFP_KERNEL); + dev->prev_data = devm_kzalloc_obj(dev->dev, *dev->prev_data); if (!dev->prev_data) return -ENOMEM; diff --git a/drivers/platform/x86/amd/x3d_vcache.c b/drivers/platform/x86/amd/x3d_vcache.c index 0f6d3c54d87955..fe8864e0470946 100644 --- a/drivers/platform/x86/amd/x3d_vcache.c +++ b/drivers/platform/x86/amd/x3d_vcache.c @@ -141,7 +141,7 @@ static int amd_x3d_probe(struct platform_device *pdev) if (!acpi_check_dsm(handle, &x3d_guid, DSM_REVISION_ID, BIT(DSM_SET_X3D_MODE))) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/asus-tf103c-dock.c b/drivers/platform/x86/asus-tf103c-dock.c index 3be5b96de5484e..54c4b3641ce8cb 100644 --- a/drivers/platform/x86/asus-tf103c-dock.c +++ b/drivers/platform/x86/asus-tf103c-dock.c @@ -725,7 +725,7 @@ static int tf103c_dock_probe(struct i2c_client *client) if (!dmi_check_system(tf103c_dock_dmi_ids)) return -ENODEV; - dock = devm_kzalloc(dev, sizeof(*dock), GFP_KERNEL); + dock = devm_kzalloc_obj(dev, *dock); if (!dock) return -ENOMEM; diff --git a/drivers/platform/x86/asus-wireless.c b/drivers/platform/x86/asus-wireless.c index aab45f0442c5ba..e825b15f622758 100644 --- a/drivers/platform/x86/asus-wireless.c +++ b/drivers/platform/x86/asus-wireless.c @@ -136,7 +136,7 @@ static int asus_wireless_probe(struct platform_device *pdev) if (!id) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/ayaneo-ec.c b/drivers/platform/x86/ayaneo-ec.c index 81dac81262e7ef..0be04ee148dcb6 100644 --- a/drivers/platform/x86/ayaneo-ec.c +++ b/drivers/platform/x86/ayaneo-ec.c @@ -478,7 +478,7 @@ static int ayaneo_ec_probe(struct platform_device *pdev) if (!dmi_entry) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c index e1400382465dc4..9a730fc3edb927 100644 --- a/drivers/platform/x86/barco-p50-gpio.c +++ b/drivers/platform/x86/barco-p50-gpio.c @@ -321,7 +321,7 @@ static int p50_gpio_probe(struct platform_device *pdev) return -EBUSY; } - p50 = devm_kzalloc(&pdev->dev, sizeof(*p50), GFP_KERNEL); + p50 = devm_kzalloc_obj(&pdev->dev, *p50); if (!p50) return -ENOMEM; diff --git a/drivers/platform/x86/bitland-mifs-wmi.c b/drivers/platform/x86/bitland-mifs-wmi.c index dd1648b7de7753..6dd901e54d9da5 100644 --- a/drivers/platform/x86/bitland-mifs-wmi.c +++ b/drivers/platform/x86/bitland-mifs-wmi.c @@ -668,7 +668,7 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) }; int ret; - drv_data = devm_kzalloc(&wdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&wdev->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c index 05890815795d56..a7c7580993bee8 100644 --- a/drivers/platform/x86/classmate-laptop.c +++ b/drivers/platform/x86/classmate-laptop.c @@ -403,7 +403,7 @@ static int cmpc_accel_probe_v4(struct platform_device *pdev) if (!acpi) return -ENODEV; - accel = devm_kzalloc(&pdev->dev, sizeof(*accel), GFP_KERNEL); + accel = devm_kzalloc_obj(&pdev->dev, *accel); if (!accel) return -ENOMEM; @@ -664,7 +664,7 @@ static int cmpc_accel_probe(struct platform_device *pdev) if (!acpi) return -ENODEV; - accel = devm_kzalloc(&pdev->dev, sizeof(*accel), GFP_KERNEL); + accel = devm_kzalloc_obj(&pdev->dev, *accel); if (!accel) return -ENOMEM; diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c index abbebd4bfb151a..a818e1493bf9e5 100644 --- a/drivers/platform/x86/compal-laptop.c +++ b/drivers/platform/x86/compal-laptop.c @@ -966,7 +966,7 @@ static int compal_probe(struct platform_device *pdev) return 0; /* Fan control */ - data = devm_kzalloc(&pdev->dev, sizeof(struct compal_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct compal_data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/dasharo-acpi.c b/drivers/platform/x86/dasharo-acpi.c index f0c5136af29d41..dfea00cdde1834 100644 --- a/drivers/platform/x86/dasharo-acpi.c +++ b/drivers/platform/x86/dasharo-acpi.c @@ -326,7 +326,7 @@ static int dasharo_probe(struct platform_device *pdev) struct dasharo_data *data; struct device *hwmon; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; data->pdev = pdev; diff --git a/drivers/platform/x86/dell/alienware-wmi-base.c b/drivers/platform/x86/dell/alienware-wmi-base.c index 19cadf21203a6b..581c503aa62559 100644 --- a/drivers/platform/x86/dell/alienware-wmi-base.c +++ b/drivers/platform/x86/dell/alienware-wmi-base.c @@ -394,7 +394,7 @@ static int alienfx_probe(struct platform_device *pdev) { struct alienfx_priv *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/dell/alienware-wmi-wmax.c b/drivers/platform/x86/dell/alienware-wmi-wmax.c index 2b0ffcb56a95e1..499e64dd79caf0 100644 --- a/drivers/platform/x86/dell/alienware-wmi-wmax.c +++ b/drivers/platform/x86/dell/alienware-wmi-wmax.c @@ -1136,7 +1136,7 @@ static int awcc_hwmon_fans_init(struct wmi_device *wdev) u8 id; for (i = 0; i < priv->fan_count; i++) { - fan_data = devm_kzalloc(&wdev->dev, sizeof(*fan_data), GFP_KERNEL); + fan_data = devm_kzalloc_obj(&wdev->dev, *fan_data); if (!fan_data) return -ENOMEM; @@ -1190,8 +1190,8 @@ static int awcc_hwmon_init(struct wmi_device *wdev) struct awcc_priv *priv = dev_get_drvdata(&wdev->dev); int ret; - priv->fan_data = devm_kcalloc(&wdev->dev, priv->fan_count, - sizeof(*priv->fan_data), GFP_KERNEL); + priv->fan_data = devm_kzalloc_objs(&wdev->dev, *priv->fan_data, + priv->fan_count); if (!priv->fan_data) return -ENOMEM; @@ -1534,7 +1534,7 @@ static int alienware_awcc_setup(struct wmi_device *wdev) struct awcc_priv *priv; int ret; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-dw5826e-reset.c b/drivers/platform/x86/dell/dell-dw5826e-reset.c index c72c243b460ed3..fb5abe425c416b 100644 --- a/drivers/platform/x86/dell/dell-dw5826e-reset.c +++ b/drivers/platform/x86/dell/dell-dw5826e-reset.c @@ -78,7 +78,7 @@ static int palc_probe(struct platform_device *pdev) if (!handle) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-rbtn.c b/drivers/platform/x86/dell/dell-rbtn.c index 180b8c6720e653..c0b3877bb27d94 100644 --- a/drivers/platform/x86/dell/dell-rbtn.c +++ b/drivers/platform/x86/dell/dell-rbtn.c @@ -411,7 +411,7 @@ static int rbtn_probe(struct platform_device *pdev) return -EINVAL; } - rbtn_data = devm_kzalloc(&pdev->dev, sizeof(*rbtn_data), GFP_KERNEL); + rbtn_data = devm_kzalloc_obj(&pdev->dev, *rbtn_data); if (!rbtn_data) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-smbios-base.c b/drivers/platform/x86/dell/dell-smbios-base.c index d8c55ec6acd4d2..c8e93c12c445f1 100644 --- a/drivers/platform/x86/dell/dell-smbios-base.c +++ b/drivers/platform/x86/dell/dell-smbios-base.c @@ -150,7 +150,7 @@ int dell_smbios_register_device(struct device *d, int priority, smbios_callback_ { struct smbios_device *priv; - priv = devm_kzalloc(d, sizeof(struct smbios_device), GFP_KERNEL); + priv = devm_kzalloc_obj(d, struct smbios_device); if (!priv) return -ENOMEM; get_device(d); diff --git a/drivers/platform/x86/dell/dell-smbios-wmi.c b/drivers/platform/x86/dell/dell-smbios-wmi.c index f9443ddfff551d..7a5c6d7730ab11 100644 --- a/drivers/platform/x86/dell/dell-smbios-wmi.c +++ b/drivers/platform/x86/dell/dell-smbios-wmi.c @@ -222,8 +222,7 @@ static int dell_smbios_wmi_probe(struct wmi_device *wdev, const void *context) if (ret) return ret; - priv = devm_kzalloc(&wdev->dev, sizeof(struct wmi_smbios_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, struct wmi_smbios_priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index 8872f9b57fce28..e056664656a78c 100644 --- a/drivers/platform/x86/dell/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c @@ -108,7 +108,7 @@ static int smo8800_probe(struct platform_device *device) int err; struct smo8800_device *smo8800; - smo8800 = devm_kzalloc(&device->dev, sizeof(*smo8800), GFP_KERNEL); + smo8800 = devm_kzalloc_obj(&device->dev, *smo8800); if (!smo8800) { dev_err(&device->dev, "failed to allocate device data\n"); return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-uart-backlight.c b/drivers/platform/x86/dell/dell-uart-backlight.c index f323a667dc2d2c..bbb270ae36977c 100644 --- a/drivers/platform/x86/dell/dell-uart-backlight.c +++ b/drivers/platform/x86/dell/dell-uart-backlight.c @@ -275,7 +275,7 @@ static int dell_uart_bl_serdev_probe(struct serdev_device *serdev) struct device *dev = &serdev->dev; int ret; - dell_bl = devm_kzalloc(dev, sizeof(*dell_bl), GFP_KERNEL); + dell_bl = devm_kzalloc_obj(dev, *dell_bl); if (!dell_bl) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-wmi-aio.c b/drivers/platform/x86/dell/dell-wmi-aio.c index 42c0032991d2b0..cea50ccac7ea95 100644 --- a/drivers/platform/x86/dell/dell-wmi-aio.c +++ b/drivers/platform/x86/dell/dell-wmi-aio.c @@ -106,7 +106,7 @@ static int dell_wmi_aio_probe(struct wmi_device *wdev, const void *context) struct dell_wmi_aio_data *data; int ret; - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-wmi-base.c b/drivers/platform/x86/dell/dell-wmi-base.c index 38a6b3ae2f75c1..44857e99fdfe6f 100644 --- a/drivers/platform/x86/dell/dell-wmi-base.c +++ b/drivers/platform/x86/dell/dell-wmi-base.c @@ -795,8 +795,7 @@ static int dell_wmi_probe(struct wmi_device *wdev, const void *context) if (ret) return ret; - priv = devm_kzalloc( - &wdev->dev, sizeof(struct dell_wmi_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, struct dell_wmi_priv); if (!priv) return -ENOMEM; dev_set_drvdata(&wdev->dev, priv); diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c index f8903ced461b11..00213dbd737d0b 100644 --- a/drivers/platform/x86/dell/dell-wmi-ddv.c +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -519,7 +519,7 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev struct combined_channel_info *cinfo; int i; - cinfo = devm_kzalloc(dev, struct_size(cinfo, config, count + 1), GFP_KERNEL); + cinfo = devm_kzalloc_flex(dev, *cinfo, config, count + 1); if (!cinfo) return ERR_PTR(-ENOMEM); @@ -592,7 +592,7 @@ static int dell_wmi_ddv_hwmon_add(struct dell_wmi_ddv_data *data) if (!devres_open_group(&wdev->dev, dell_wmi_ddv_hwmon_add, GFP_KERNEL)) return -ENOMEM; - cinfo = devm_kzalloc(&wdev->dev, struct_size(cinfo, info, 4), GFP_KERNEL); + cinfo = devm_kzalloc_flex(&wdev->dev, *cinfo, info, 4); if (!cinfo) { ret = -ENOMEM; @@ -1044,7 +1044,7 @@ static int dell_wmi_ddv_probe(struct wmi_device *wdev, const void *context) version); } - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-wmi-descriptor.c b/drivers/platform/x86/dell/dell-wmi-descriptor.c index 179d5678b3ad37..c496535bf13c34 100644 --- a/drivers/platform/x86/dell/dell-wmi-descriptor.c +++ b/drivers/platform/x86/dell/dell-wmi-descriptor.c @@ -142,7 +142,7 @@ static int dell_wmi_descriptor_probe(struct wmi_device *wdev, const void *contex dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%u)\n", le32_to_cpu(desc->interface_version)); - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/dell/dell-wmi-privacy.c b/drivers/platform/x86/dell/dell-wmi-privacy.c index 366e5b8dc868f7..b7f589ad7c6f62 100644 --- a/drivers/platform/x86/dell/dell-wmi-privacy.c +++ b/drivers/platform/x86/dell/dell-wmi-privacy.c @@ -288,7 +288,7 @@ static int dell_privacy_wmi_probe(struct wmi_device *wdev, const void *context) struct key_entry *keymap; int ret, i, j; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index ea543deef68f6a..8e909cb726f1f2 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -540,7 +540,7 @@ static int acpi_fujitsu_bl_probe(struct platform_device *pdev) if (acpi_video_get_backlight_type() != acpi_backlight_vendor) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -846,7 +846,7 @@ static int acpi_fujitsu_laptop_leds_register(struct device *dev) int ret; if (call_fext_func(dev, FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -860,7 +860,7 @@ static int acpi_fujitsu_laptop_leds_register(struct device *dev) if ((call_fext_func(dev, FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) && (call_fext_func(dev, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -882,7 +882,7 @@ static int acpi_fujitsu_laptop_leds_register(struct device *dev) * whether given model has a radio toggle button. */ if (priv->flags_supported & BIT(17)) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -902,7 +902,7 @@ static int acpi_fujitsu_laptop_leds_register(struct device *dev) */ if ((call_fext_func(dev, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) && (call_fext_func(dev, FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; @@ -1002,7 +1002,7 @@ static int acpi_fujitsu_laptop_probe(struct platform_device *pdev) if (!device) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/gpd-pocket-fan.c b/drivers/platform/x86/gpd-pocket-fan.c index ced93795c5d4b5..4a26137e63e581 100644 --- a/drivers/platform/x86/gpd-pocket-fan.c +++ b/drivers/platform/x86/gpd-pocket-fan.c @@ -148,7 +148,7 @@ static int gpd_pocket_fan_probe(struct platform_device *pdev) speed_on_ac = SPEED_ON_AC_DEFAULT; } - fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); + fan = devm_kzalloc_obj(&pdev->dev, *fan); if (!fan) return -ENOMEM; diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c index 52077833ac89d3..0069af86800e1d 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -3186,7 +3186,7 @@ static int hp_wmi_hwmon_init(void) struct device *hwmon; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/inspur_platform_profile.c b/drivers/platform/x86/inspur_platform_profile.c index e02f5a55a6c5d3..30f6bff57224c7 100644 --- a/drivers/platform/x86/inspur_platform_profile.c +++ b/drivers/platform/x86/inspur_platform_profile.c @@ -183,7 +183,7 @@ static int inspur_wmi_probe(struct wmi_device *wdev, const void *context) { struct inspur_wmi_priv *priv; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/intel/bxtwc_tmu.c b/drivers/platform/x86/intel/bxtwc_tmu.c index 73d7f71b2fd0f5..70e5c78b75872f 100644 --- a/drivers/platform/x86/intel/bxtwc_tmu.c +++ b/drivers/platform/x86/intel/bxtwc_tmu.c @@ -50,7 +50,7 @@ static int bxt_wcove_tmu_probe(struct platform_device *pdev) struct wcove_tmu *wctmu; int ret; - wctmu = devm_kzalloc(&pdev->dev, sizeof(*wctmu), GFP_KERNEL); + wctmu = devm_kzalloc_obj(&pdev->dev, *wctmu); if (!wctmu) return -ENOMEM; diff --git a/drivers/platform/x86/intel/bytcrc_pwrsrc.c b/drivers/platform/x86/intel/bytcrc_pwrsrc.c index 1f39850b80fd0f..debe5fc9c934d4 100644 --- a/drivers/platform/x86/intel/bytcrc_pwrsrc.c +++ b/drivers/platform/x86/intel/bytcrc_pwrsrc.c @@ -181,7 +181,7 @@ static int crc_pwrsrc_probe(struct platform_device *pdev) struct crc_pwrsrc_data *data; int irq, ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/intel/chtwc_int33fe.c b/drivers/platform/x86/intel/chtwc_int33fe.c index d183aa53c318ba..9fb09e565ffc88 100644 --- a/drivers/platform/x86/intel/chtwc_int33fe.c +++ b/drivers/platform/x86/intel/chtwc_int33fe.c @@ -323,7 +323,7 @@ static int cht_int33fe_typec_probe(struct platform_device *pdev) if (!dmi_check_system(cht_int33fe_typec_ids)) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/intel/crystal_cove_charger.c b/drivers/platform/x86/intel/crystal_cove_charger.c index 425c7eb32442a9..311992528bc65f 100644 --- a/drivers/platform/x86/intel/crystal_cove_charger.c +++ b/drivers/platform/x86/intel/crystal_cove_charger.c @@ -89,7 +89,7 @@ static int crystal_cove_charger_probe(struct platform_device *pdev) struct crystal_cove_charger_data *charger; int ret; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/platform/x86/intel/ehl_pse_io.c b/drivers/platform/x86/intel/ehl_pse_io.c index f75f3a8cc6b030..3837523eeecedb 100644 --- a/drivers/platform/x86/intel/ehl_pse_io.c +++ b/drivers/platform/x86/intel/ehl_pse_io.c @@ -29,7 +29,7 @@ static int ehl_pse_io_dev_create(struct pci_dev *pci, const char *name, int idx) resource_size_t start, offset; u32 id; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/intel/hid.c b/drivers/platform/x86/intel/hid.c index 6024bf29c4dfd5..60e6b476500e40 100644 --- a/drivers/platform/x86/intel/hid.c +++ b/drivers/platform/x86/intel/hid.c @@ -734,7 +734,7 @@ static int intel_hid_probe(struct platform_device *device) return -ENODEV; } - priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&device->dev, *priv); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); diff --git a/drivers/platform/x86/intel/int0002_vgpio.c b/drivers/platform/x86/intel/int0002_vgpio.c index 96b36cfcd9e406..909a90e060c7f8 100644 --- a/drivers/platform/x86/intel/int0002_vgpio.c +++ b/drivers/platform/x86/intel/int0002_vgpio.c @@ -182,7 +182,7 @@ static int int0002_probe(struct platform_device *pdev) if (irq < 0) return irq; - int0002 = devm_kzalloc(dev, sizeof(*int0002), GFP_KERNEL); + int0002 = devm_kzalloc_obj(dev, *int0002); if (!int0002) return -ENOMEM; diff --git a/drivers/platform/x86/intel/int1092/intel_sar.c b/drivers/platform/x86/intel/int1092/intel_sar.c index f506155f35d4d2..8764fff059d06c 100644 --- a/drivers/platform/x86/intel/int1092/intel_sar.c +++ b/drivers/platform/x86/intel/int1092/intel_sar.c @@ -91,10 +91,9 @@ static acpi_status parse_package(struct wwan_sar_context *context, union acpi_ob item->package.count <= data->total_dev_mode) return AE_ERROR; - data->device_mode_info = devm_kcalloc(&context->sar_device->dev, - data->total_dev_mode, - sizeof(*data->device_mode_info), - GFP_KERNEL); + data->device_mode_info = devm_kzalloc_objs(&context->sar_device->dev, + *data->device_mode_info, + data->total_dev_mode); if (!data->device_mode_info) return AE_ERROR; @@ -255,7 +254,7 @@ static int sar_probe(struct platform_device *device) if (!handle) return -ENODEV; - context = devm_kzalloc(&device->dev, sizeof(*context), GFP_KERNEL); + context = devm_kzalloc_obj(&device->dev, *context); if (!context) return -ENOMEM; diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c index b19ea6ee3374c1..f14bee2b430ac8 100644 --- a/drivers/platform/x86/intel/int3472/discrete.c +++ b/drivers/platform/x86/intel/int3472/discrete.c @@ -526,8 +526,8 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev) } /* Max num GPIOs we've seen plus a terminator */ - int3472 = devm_kzalloc(&pdev->dev, struct_size(int3472, gpios.table, - INT3472_MAX_SENSOR_GPIOS + 1), GFP_KERNEL); + int3472 = devm_kzalloc_flex(&pdev->dev, *int3472, gpios.table, + INT3472_MAX_SENSOR_GPIOS + 1); if (!int3472) return -ENOMEM; diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c index 14edef175b20e3..14f5ff9254d222 100644 --- a/drivers/platform/x86/intel/int3472/tps68470.c +++ b/drivers/platform/x86/intel/int3472/tps68470.c @@ -117,8 +117,7 @@ skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data return -ENODEV; } - *clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers), - GFP_KERNEL); + *clk_pdata = devm_kzalloc_flex(dev, **clk_pdata, consumers, n_consumers); if (!*clk_pdata) return -ENOMEM; @@ -188,10 +187,9 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) "No board-data found for this model\n"); if (board_data->n_clk_consumers) { - clk_pdata = devm_kzalloc(&client->dev, - struct_size(clk_pdata, consumers, - board_data->n_clk_consumers), - GFP_KERNEL); + clk_pdata = devm_kzalloc_flex(&client->dev, *clk_pdata, + consumers, + board_data->n_clk_consumers); if (!clk_pdata) return -ENOMEM; clk_pdata->n_consumers = board_data->n_clk_consumers; diff --git a/drivers/platform/x86/intel/ishtp_eclite.c b/drivers/platform/x86/intel/ishtp_eclite.c index bca7e217878b4a..84c98c51a5e5bf 100644 --- a/drivers/platform/x86/intel/ishtp_eclite.c +++ b/drivers/platform/x86/intel/ishtp_eclite.c @@ -557,8 +557,7 @@ static int ecl_ishtp_cl_probe(struct ishtp_cl_device *cl_device) struct ishtp_opregion_dev *opr_dev; int rv; - opr_dev = devm_kzalloc(ishtp_device(cl_device), sizeof(*opr_dev), - GFP_KERNEL); + opr_dev = devm_kzalloc_obj(ishtp_device(cl_device), *opr_dev); if (!opr_dev) return -ENOMEM; diff --git a/drivers/platform/x86/intel/plr_tpmi.c b/drivers/platform/x86/intel/plr_tpmi.c index f98c241edee482..785c279b45403c 100644 --- a/drivers/platform/x86/intel/plr_tpmi.c +++ b/drivers/platform/x86/intel/plr_tpmi.c @@ -304,7 +304,7 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia if (!num_resources) return -EINVAL; - plr = devm_kzalloc(&auxdev->dev, sizeof(*plr), GFP_KERNEL); + plr = devm_kzalloc_obj(&auxdev->dev, *plr); if (!plr) return -ENOMEM; @@ -314,8 +314,8 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia intel_plr_register_notifier(&plr->nb); - plr->die_info = devm_kcalloc(&auxdev->dev, num_resources, sizeof(*plr->die_info), - GFP_KERNEL); + plr->die_info = devm_kzalloc_objs(&auxdev->dev, *plr->die_info, + num_resources); if (!plr->die_info) { err = -ENOMEM; goto err_notify; diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index 71be313bdf0e1c..47759b2a8012bd 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -272,7 +272,7 @@ static void pmc_core_lpm_display(struct pmc *pmc, struct device *dev, u32 bit_mask, *lpm_regs; arr_size = pmc_core_lpm_get_arr_size(maps); - lpm_regs = kmalloc_array(arr_size, sizeof(*lpm_regs), GFP_KERNEL); + lpm_regs = kmalloc_objs(*lpm_regs, arr_size); if (!lpm_regs) return; @@ -1628,8 +1628,8 @@ int pmc_core_pmt_get_blk_sub_req(struct pmc_dev *pmcdev, struct pmc *pmc, num_blocker = pmc->map->num_s0ix_blocker; sample_offset = pmc->map->blocker_req_offset; - pmc->lpm_req_regs = devm_kcalloc(&pmcdev->pdev->dev, num_blocker, - sizeof(u32), GFP_KERNEL); + pmc->lpm_req_regs = devm_kzalloc_objs(&pmcdev->pdev->dev, u32, + num_blocker); if (!pmc->lpm_req_regs) return -ENOMEM; @@ -1715,7 +1715,7 @@ static int pmc_core_pmc_add(struct pmc_dev *pmcdev, unsigned int pmc_idx) pmc = pmcdev->pmcs[pmc_idx]; /* Memory for primary PMC has been allocated */ if (!pmc) { - pmc = devm_kzalloc(&pmcdev->pdev->dev, sizeof(*pmc), GFP_KERNEL); + pmc = devm_kzalloc_obj(&pmcdev->pdev->dev, *pmc); if (!pmc) return -ENOMEM; } @@ -1935,7 +1935,7 @@ static int pmc_core_probe(struct platform_device *pdev) if (device_initialized) return -ENODEV; - pmcdev = devm_kzalloc(&pdev->dev, sizeof(*pmcdev), GFP_KERNEL); + pmcdev = devm_kzalloc_obj(&pdev->dev, *pmcdev); if (!pmcdev) return -ENOMEM; @@ -1951,17 +1951,16 @@ static int pmc_core_probe(struct platform_device *pdev) pmc_dev_info = (struct pmc_dev_info *)cpu_id->driver_data; /* Primary PMC */ - primary_pmc = devm_kzalloc(&pdev->dev, sizeof(*primary_pmc), GFP_KERNEL); + primary_pmc = devm_kzalloc_obj(&pdev->dev, *primary_pmc); if (!primary_pmc) return -ENOMEM; pmcdev->pmcs[PMC_IDX_MAIN] = primary_pmc; /* The last element in msr_map is empty */ pmcdev->num_of_pkgc = ARRAY_SIZE(msr_map) - 1; - pmcdev->pkgc_res_cnt = devm_kcalloc(&pdev->dev, - pmcdev->num_of_pkgc, - sizeof(*pmcdev->pkgc_res_cnt), - GFP_KERNEL); + pmcdev->pkgc_res_cnt = devm_kzalloc_objs(&pdev->dev, + *pmcdev->pkgc_res_cnt, + pmcdev->num_of_pkgc); if (!pmcdev->pkgc_res_cnt) return -ENOMEM; diff --git a/drivers/platform/x86/intel/pmc/ssram_telemetry.c b/drivers/platform/x86/intel/pmc/ssram_telemetry.c index 8e280ec525a69f..3e2e62a9af8da8 100644 --- a/drivers/platform/x86/intel/pmc/ssram_telemetry.c +++ b/drivers/platform/x86/intel/pmc/ssram_telemetry.c @@ -410,7 +410,7 @@ static int pmc_ssram_telemetry_probe(struct pci_dev *pcidev, const struct pci_de pmc_ssram_mark_probing(probe_cache.owned_mask); - drvdata = devm_kzalloc(&pcidev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pcidev->dev, *drvdata); if (!drvdata) { ret = -ENOMEM; goto probe_finish; diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/intel/pmc/tgl.c index fc5b4cacc1c62b..c657ed20e0b257 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -273,8 +273,7 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev) addr = (u32 *)out_obj->buffer.pointer; - lpm_req_regs = devm_kcalloc(&pdev->dev, lpm_size, sizeof(u32), - GFP_KERNEL); + lpm_req_regs = devm_kzalloc_objs(&pdev->dev, u32, lpm_size); if (!lpm_req_regs) goto free_acpi_obj; diff --git a/drivers/platform/x86/intel/punit_ipc.c b/drivers/platform/x86/intel/punit_ipc.c index a3d2b0b64135e0..8d797fc86498f4 100644 --- a/drivers/platform/x86/intel/punit_ipc.c +++ b/drivers/platform/x86/intel/punit_ipc.c @@ -236,8 +236,7 @@ static int intel_punit_ipc_probe(struct platform_device *pdev) { int irq, ret; - punit_ipcdev = devm_kzalloc(&pdev->dev, - sizeof(*punit_ipcdev), GFP_KERNEL); + punit_ipcdev = devm_kzalloc_obj(&pdev->dev, *punit_ipcdev); if (!punit_ipcdev) return -ENOMEM; diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c index d7e37d4ace238a..fccbb846b03a39 100644 --- a/drivers/platform/x86/intel/sdsi.c +++ b/drivers/platform/x86/intel/sdsi.c @@ -658,7 +658,7 @@ static int sdsi_probe(struct auxiliary_device *auxdev, const struct auxiliary_de struct sdsi_priv *priv; int ret; - priv = devm_kzalloc(&auxdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&auxdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/intel/speed_select_if/isst_if_mbox_pci.c b/drivers/platform/x86/intel/speed_select_if/isst_if_mbox_pci.c index df1fc6c719f323..c31cc60c58c461 100644 --- a/drivers/platform/x86/intel/speed_select_if/isst_if_mbox_pci.c +++ b/drivers/platform/x86/intel/speed_select_if/isst_if_mbox_pci.c @@ -172,7 +172,7 @@ static int isst_if_mbox_probe(struct pci_dev *pdev, struct isst_if_cmd_cb cb; int ret; - punit_dev = devm_kzalloc(&pdev->dev, sizeof(*punit_dev), GFP_KERNEL); + punit_dev = devm_kzalloc_obj(&pdev->dev, *punit_dev); if (!punit_dev) return -ENOMEM; diff --git a/drivers/platform/x86/intel/speed_select_if/isst_if_mmio.c b/drivers/platform/x86/intel/speed_select_if/isst_if_mmio.c index 950ede5eab7694..60bdb30da8f3c5 100644 --- a/drivers/platform/x86/intel/speed_select_if/isst_if_mmio.c +++ b/drivers/platform/x86/intel/speed_select_if/isst_if_mmio.c @@ -98,7 +98,7 @@ static int isst_if_probe(struct pci_dev *pdev, const struct pci_device_id *ent) u64 base_addr; int ret; - punit_dev = devm_kzalloc(&pdev->dev, sizeof(*punit_dev), GFP_KERNEL); + punit_dev = devm_kzalloc_obj(&pdev->dev, *punit_dev); if (!punit_dev) return -ENOMEM; diff --git a/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c index bb0d0b8fc54ac4..fa71c0fe172f88 100644 --- a/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +++ b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c @@ -335,7 +335,7 @@ static int sst_add_perf_profiles(struct auxiliary_device *auxdev, u64 perf_level_offsets; int i; - pd_info->perf_levels = devm_kcalloc(dev, levels, sizeof(struct perf_level), GFP_KERNEL); + pd_info->perf_levels = devm_kzalloc_objs(dev, struct perf_level, levels); if (!pd_info->perf_levels) { pd_info->pp_header.allowed_level_mask = 0; pd_info->pp_header.level_en_mask = 0; @@ -1686,7 +1686,7 @@ int tpmi_sst_dev_add(struct auxiliary_device *auxdev) ret = 0; - pd_info = devm_kcalloc(dev, num_resources, sizeof(*pd_info), GFP_KERNEL); + pd_info = devm_kzalloc_objs(dev, *pd_info, num_resources); if (!pd_info) { ret = -ENOMEM; goto unlock_free; diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x86/intel/tpmi_common.c index b6b811016dfdd4..816606767b8268 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -717,9 +717,9 @@ int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct device *tpmi_dev, if (pci_dev) tpmi_info->plat_info.bus_number = pci_dev->bus->number; - tpmi_info->tpmi_features = devm_kcalloc(tpmi_info->tpmi_dev, tpmi_info->feature_count, - sizeof(*tpmi_info->tpmi_features), - GFP_KERNEL); + tpmi_info->tpmi_features = devm_kzalloc_objs(tpmi_info->tpmi_dev, + *tpmi_info->tpmi_features, + tpmi_info->feature_count); if (!tpmi_info->tpmi_features) return -ENOMEM; diff --git a/drivers/platform/x86/intel/tpmi_power_domains.c b/drivers/platform/x86/intel/tpmi_power_domains.c index d89b9894c42a41..ebe052c3bbe432 100644 --- a/drivers/platform/x86/intel/tpmi_power_domains.c +++ b/drivers/platform/x86/intel/tpmi_power_domains.c @@ -240,8 +240,8 @@ static int __init tpmi_init(void) if (!tpmi_power_domain_mask) return -ENOMEM; - domain_die_map = kcalloc(size_mul(topology_max_packages(), MAX_POWER_DOMAINS), - sizeof(*domain_die_map), GFP_KERNEL); + domain_die_map = kzalloc_objs(*domain_die_map, + size_mul(topology_max_packages(), MAX_POWER_DOMAINS)); if (!domain_die_map) { ret = -ENOMEM; goto free_domain_mask; diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c index 44e2a90004df39..753ddfe8c75907 100644 --- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c +++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c @@ -581,16 +581,16 @@ static int uncore_probe(struct auxiliary_device *auxdev, const struct auxiliary_ return ret; /* Allocate uncore instance per package */ - tpmi_uncore = devm_kzalloc(&auxdev->dev, sizeof(*tpmi_uncore), GFP_KERNEL); + tpmi_uncore = devm_kzalloc_obj(&auxdev->dev, *tpmi_uncore); if (!tpmi_uncore) { ret = -ENOMEM; goto err_rem_common; } /* Allocate memory for all power domains in a package */ - tpmi_uncore->pd_info = devm_kcalloc(&auxdev->dev, num_resources, - sizeof(*tpmi_uncore->pd_info), - GFP_KERNEL); + tpmi_uncore->pd_info = devm_kzalloc_objs(&auxdev->dev, + *tpmi_uncore->pd_info, + num_resources); if (!tpmi_uncore->pd_info) { ret = -ENOMEM; goto err_rem_common; @@ -666,9 +666,9 @@ static int uncore_probe(struct auxiliary_device *auxdev, const struct auxiliary_ /* Find out number of clusters in this resource */ pd_info->cluster_count = hweight8(cluster_mask); - pd_info->cluster_infos = devm_kcalloc(&auxdev->dev, pd_info->cluster_count, - sizeof(struct tpmi_uncore_cluster_info), - GFP_KERNEL); + pd_info->cluster_infos = devm_kzalloc_objs(&auxdev->dev, + struct tpmi_uncore_cluster_info, + pd_info->cluster_count); if (!pd_info->cluster_infos) { ret = -ENOMEM; goto remove_clusters; diff --git a/drivers/platform/x86/intel/vbtn.c b/drivers/platform/x86/intel/vbtn.c index 874023c38fd15a..975d8534d4cd38 100644 --- a/drivers/platform/x86/intel/vbtn.c +++ b/drivers/platform/x86/intel/vbtn.c @@ -294,7 +294,7 @@ static int intel_vbtn_probe(struct platform_device *device) return -ENODEV; } - priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&device->dev, *priv); if (!priv) return -ENOMEM; dev_set_drvdata(&device->dev, priv); diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 380d8231549f8e..85c458aadcd449 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -714,7 +714,7 @@ static int intel_vsec_pci_probe(struct pci_dev *pdev, const struct pci_device_id if (!info) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/intel/vsec_tpmi.c index 053fe0f586418e..d31631a71db9a0 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -37,7 +37,7 @@ static int tpmi_probe(struct auxiliary_device *auxdev, struct intel_vsec_device *vsec_dev = auxdev_to_ivdev(auxdev); struct intel_tpmi_info *tpmi_info; - tpmi_info = devm_kzalloc(&auxdev->dev, sizeof(*tpmi_info), GFP_KERNEL); + tpmi_info = devm_kzalloc_obj(&auxdev->dev, *tpmi_info); if (!tpmi_info) return -ENOMEM; diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index b1b2d9caba7b38..636f4511127f7a 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c @@ -960,12 +960,12 @@ static int ips_monitor(void *data) u16 *mcp_samples, *ctv1_samples, *ctv2_samples, *mch_samples; u8 cur_seqno, last_seqno; - mcp_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u16), GFP_KERNEL); - ctv1_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u16), GFP_KERNEL); - ctv2_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u16), GFP_KERNEL); - mch_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u16), GFP_KERNEL); - cpu_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u32), GFP_KERNEL); - mchp_samples = kcalloc(IPS_SAMPLE_COUNT, sizeof(u32), GFP_KERNEL); + mcp_samples = kzalloc_objs(u16, IPS_SAMPLE_COUNT); + ctv1_samples = kzalloc_objs(u16, IPS_SAMPLE_COUNT); + ctv2_samples = kzalloc_objs(u16, IPS_SAMPLE_COUNT); + mch_samples = kzalloc_objs(u16, IPS_SAMPLE_COUNT); + cpu_samples = kzalloc_objs(u32, IPS_SAMPLE_COUNT); + mchp_samples = kzalloc_objs(u32, IPS_SAMPLE_COUNT); if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples || !cpu_samples || !mchp_samples) { dev_err(ips->dev, @@ -1431,7 +1431,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) if (dmi_check_system(ips_blacklist)) return -ENODEV; - ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL); + ips = devm_kzalloc_obj(&dev->dev, *ips); if (!ips) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c index 857a449c4f8a03..91a8d11c79c582 100644 --- a/drivers/platform/x86/lenovo/ideapad-laptop.c +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c @@ -2278,7 +2278,7 @@ static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context) { struct ideapad_wmi_private *wpriv; - wpriv = devm_kzalloc(&wdev->dev, sizeof(*wpriv), GFP_KERNEL); + wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv); if (!wpriv) return -ENOMEM; @@ -2394,7 +2394,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) if (!adev || eval_int(adev->handle, "_CFG", &cfg)) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-camera.c b/drivers/platform/x86/lenovo/wmi-camera.c index 89ecbce60bf4f7..090b1e52535752 100644 --- a/drivers/platform/x86/lenovo/wmi-camera.c +++ b/drivers/platform/x86/lenovo/wmi-camera.c @@ -101,7 +101,7 @@ static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context) { struct lenovo_wmi_priv *priv; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x86/lenovo/wmi-capdata.c index 1d44ff83e157f6..cdcddf40533913 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -417,7 +417,7 @@ static int lwmi_cd_sub_master_add(struct lwmi_cd_priv *priv, if (sub_component_type == CD_TYPE_NONE) return 0; - priv->sub_master = devm_kzalloc(&priv->wdev->dev, sizeof(*priv->sub_master), GFP_KERNEL); + priv->sub_master = devm_kzalloc_obj(&priv->wdev->dev, *priv->sub_master); if (!priv->sub_master) return -ENOMEM; @@ -856,7 +856,7 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_priv *priv) if (!count) return 0; - list = devm_kzalloc(&priv->wdev->dev, struct_size(list, cd_fan, count), GFP_KERNEL); + list = devm_kzalloc_flex(&priv->wdev->dev, *list, cd_fan, count); if (!list) return -ENOMEM; @@ -1032,7 +1032,7 @@ static int lwmi_cd_probe(struct wmi_device *wdev, const void *context) if (!info) return -EINVAL; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-events.c b/drivers/platform/x86/lenovo/wmi-events.c index fc25bba68a7c67..3a82192dc9e59d 100644 --- a/drivers/platform/x86/lenovo/wmi-events.c +++ b/drivers/platform/x86/lenovo/wmi-events.c @@ -161,7 +161,7 @@ static int lwmi_events_probe(struct wmi_device *wdev, const void *context) if (!context) return -EINVAL; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c index 109c0b564a9f6b..94a57b0160cb12 100644 --- a/drivers/platform/x86/lenovo/wmi-gamezone.c +++ b/drivers/platform/x86/lenovo/wmi-gamezone.c @@ -357,7 +357,7 @@ static int lwmi_gz_probe(struct wmi_device *wdev, const void *context) struct lwmi_gz_priv *priv; int ret; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-hotkey-utilities.c b/drivers/platform/x86/lenovo/wmi-hotkey-utilities.c index 7b9bad1978ff20..b3a254970810f1 100644 --- a/drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +++ b/drivers/platform/x86/lenovo/wmi-hotkey-utilities.c @@ -191,7 +191,7 @@ static int lenovo_super_hotkey_wmi_probe(struct wmi_device *wdev, const void *co { struct lenovo_super_hotkey_wmi_private *wpriv; - wpriv = devm_kzalloc(&wdev->dev, sizeof(*wpriv), GFP_KERNEL); + wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv); if (!wpriv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c index cecb89bb08ebf6..bd64e7b44669db 100644 --- a/drivers/platform/x86/lenovo/wmi-other.c +++ b/drivers/platform/x86/lenovo/wmi-other.c @@ -1694,7 +1694,7 @@ static int lwmi_other_probe(struct wmi_device *wdev, const void *context) struct component_match *master_match = NULL; struct lwmi_om_priv *priv; - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/yb9-kbdock.c b/drivers/platform/x86/lenovo/yb9-kbdock.c index 70d81f3af09ec8..2efab9d07a4154 100644 --- a/drivers/platform/x86/lenovo/yb9-kbdock.c +++ b/drivers/platform/x86/lenovo/yb9-kbdock.c @@ -194,7 +194,7 @@ static int yb9_kbdock_block_probe(struct wmi_device *wdev, const void *ctx) struct input_dev *input_dev; int ret; - d = devm_kzalloc(&wdev->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(&wdev->dev, *d); if (!d) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/ymc.c b/drivers/platform/x86/lenovo/ymc.c index df96107d250124..91de02d989a0c8 100644 --- a/drivers/platform/x86/lenovo/ymc.c +++ b/drivers/platform/x86/lenovo/ymc.c @@ -133,7 +133,7 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx) return -ENODEV; } - priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&wdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c index 8551ab4d2c7dbc..9e2ac80edbed76 100644 --- a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c +++ b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c @@ -154,7 +154,7 @@ static int yt2_1380_fc_serdev_probe(struct serdev_device *serdev) struct yt2_1380_fc *fc; int ret; - fc = devm_kzalloc(dev, sizeof(*fc), GFP_KERNEL); + fc = devm_kzalloc_obj(dev, *fc); if (!fc) return -ENOMEM; diff --git a/drivers/platform/x86/lenovo/yogabook.c b/drivers/platform/x86/lenovo/yogabook.c index f35c307300c293..ea8173200ed2aa 100644 --- a/drivers/platform/x86/lenovo/yogabook.c +++ b/drivers/platform/x86/lenovo/yogabook.c @@ -332,7 +332,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) struct yogabook_data *data; int r; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -449,7 +449,7 @@ static int yogabook_pdev_probe(struct platform_device *pdev) struct yogabook_data *data; int r; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/msi-wmi-platform.c b/drivers/platform/x86/msi-wmi-platform.c index e912fcc12d1243..af0797db7ec407 100644 --- a/drivers/platform/x86/msi-wmi-platform.c +++ b/drivers/platform/x86/msi-wmi-platform.c @@ -298,7 +298,7 @@ static void msi_wmi_platform_debugfs_add(struct msi_wmi_platform_data *drvdata, struct msi_wmi_platform_debugfs_data *data; struct dentry *entry; - data = devm_kzalloc(&drvdata->wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&drvdata->wdev->dev, *data); if (!data) return; @@ -410,7 +410,7 @@ static int msi_wmi_platform_probe(struct wmi_device *wdev, const void *context) struct msi_wmi_platform_data *data; int ret; - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/quickstart.c b/drivers/platform/x86/quickstart.c index 186a243a012da0..2c59d6245161d1 100644 --- a/drivers/platform/x86/quickstart.c +++ b/drivers/platform/x86/quickstart.c @@ -164,7 +164,7 @@ static int quickstart_probe(struct platform_device *pdev) if (!handle) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/redmi-wmi.c b/drivers/platform/x86/redmi-wmi.c index cc82ef502002e7..a8eabd93ff3ef2 100644 --- a/drivers/platform/x86/redmi-wmi.c +++ b/drivers/platform/x86/redmi-wmi.c @@ -70,7 +70,7 @@ static int redmi_wmi_probe(struct wmi_device *wdev, const void *context) int err; /* Init dev */ - data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/samsung-galaxybook.c b/drivers/platform/x86/samsung-galaxybook.c index 88ef11004ad068..b150e1fc347ae0 100644 --- a/drivers/platform/x86/samsung-galaxybook.c +++ b/drivers/platform/x86/samsung-galaxybook.c @@ -1003,12 +1003,12 @@ static int galaxybook_fw_attr_init(struct samsung_galaxybook *galaxybook, struct galaxybook_fw_attr *fw_attr; struct attribute **attrs; - fw_attr = devm_kzalloc(&galaxybook->platform->dev, sizeof(*fw_attr), GFP_KERNEL); + fw_attr = devm_kzalloc_obj(&galaxybook->platform->dev, *fw_attr); if (!fw_attr) return -ENOMEM; - attrs = devm_kcalloc(&galaxybook->platform->dev, NUM_FW_ATTR_ENUM_ATTRS + 1, - sizeof(*attrs), GFP_KERNEL); + attrs = devm_kzalloc_objs(&galaxybook->platform->dev, *attrs, + NUM_FW_ATTR_ENUM_ATTRS + 1); if (!attrs) return -ENOMEM; @@ -1375,7 +1375,7 @@ static int galaxybook_probe(struct platform_device *pdev) if (!adev) return -ENODEV; - galaxybook = devm_kzalloc(&pdev->dev, sizeof(*galaxybook), GFP_KERNEL); + galaxybook = devm_kzalloc_obj(&pdev->dev, *galaxybook); if (!galaxybook) return -ENOMEM; diff --git a/drivers/platform/x86/sel3350-platform.c b/drivers/platform/x86/sel3350-platform.c index f3a31423563251..2983f102482dc6 100644 --- a/drivers/platform/x86/sel3350-platform.c +++ b/drivers/platform/x86/sel3350-platform.c @@ -209,7 +209,7 @@ static int sel3350_probe(struct platform_device *pdev) struct sel3350_data *sel3350; struct power_supply_config ps_cfg = {}; - sel3350 = devm_kzalloc(&pdev->dev, sizeof(struct sel3350_data), GFP_KERNEL); + sel3350 = devm_kzalloc_obj(&pdev->dev, struct sel3350_data); if (!sel3350) return -ENOMEM; diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c index d535025a3f733f..ffec4f0a4992ad 100644 --- a/drivers/platform/x86/serial-multi-instantiate.c +++ b/drivers/platform/x86/serial-multi-instantiate.c @@ -125,7 +125,7 @@ static int smi_spi_probe(struct platform_device *pdev, struct smi *smi, count = ret; - smi->spi_devs = devm_kcalloc(dev, count, sizeof(*smi->spi_devs), GFP_KERNEL); + smi->spi_devs = devm_kzalloc_objs(dev, *smi->spi_devs, count); if (!smi->spi_devs) return -ENOMEM; @@ -208,7 +208,7 @@ static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi, count = ret; - smi->i2c_devs = devm_kcalloc(dev, count, sizeof(*smi->i2c_devs), GFP_KERNEL); + smi->i2c_devs = devm_kzalloc_objs(dev, *smi->i2c_devs, count); if (!smi->i2c_devs) return -ENOMEM; @@ -259,7 +259,7 @@ static int smi_probe(struct platform_device *pdev) return -ENODEV; } - smi = devm_kzalloc(dev, sizeof(*smi), GFP_KERNEL); + smi = devm_kzalloc_obj(dev, *smi); if (!smi) return -ENOMEM; diff --git a/drivers/platform/x86/silicom-platform.c b/drivers/platform/x86/silicom-platform.c index 266f7bc5e416bd..5f864160469088 100644 --- a/drivers/platform/x86/silicom-platform.c +++ b/drivers/platform/x86/silicom-platform.c @@ -732,7 +732,7 @@ static int __init silicom_mc_leds_register(struct device *dev, for (i = 0; mc_leds[i].led_cdev.name; i++) { - led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(dev, *led); if (!led) return -ENOMEM; memcpy(led, &mc_leds[i], sizeof(*led)); diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c index dd7b1b07c31659..ce72e50e686a25 100644 --- a/drivers/platform/x86/system76_acpi.c +++ b/drivers/platform/x86/system76_acpi.c @@ -682,7 +682,7 @@ static int system76_probe(struct platform_device *pdev) if (!acpi_dev) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/toshiba_haps.c b/drivers/platform/x86/toshiba_haps.c index b2eb91929d1db2..403a3d94fa3e3a 100644 --- a/drivers/platform/x86/toshiba_haps.c +++ b/drivers/platform/x86/toshiba_haps.c @@ -196,7 +196,7 @@ static int toshiba_haps_probe(struct platform_device *pdev) pr_info("Toshiba HDD Active Protection Sensor device\n"); - haps = devm_kzalloc(&pdev->dev, sizeof(*haps), GFP_KERNEL); + haps = devm_kzalloc_obj(&pdev->dev, *haps); if (!haps) return -ENOMEM; diff --git a/drivers/platform/x86/tuxedo/nb04/wmi_ab.c b/drivers/platform/x86/tuxedo/nb04/wmi_ab.c index 3e5ba524fe588c..5c56c6b1a85ec9 100644 --- a/drivers/platform/x86/tuxedo/nb04/wmi_ab.c +++ b/drivers/platform/x86/tuxedo/nb04/wmi_ab.c @@ -433,7 +433,7 @@ static int tux_ll_start(struct hid_device *hdev) u8 keyboard_type; int ret; - driver_data = devm_kzalloc(&hdev->dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(&hdev->dev, *driver_data); if (!driver_data) return -ENOMEM; @@ -868,7 +868,7 @@ static int tux_probe(struct wmi_device *wdev, const void *context __always_unuse { struct tux_driver_data_t *driver_data; - driver_data = devm_kzalloc(&wdev->dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(&wdev->dev, *driver_data); if (!driver_data) return -ENOMEM; diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c index f62d59f2967623..060324ed3c4d60 100644 --- a/drivers/platform/x86/uniwill/uniwill-acpi.c +++ b/drivers/platform/x86/uniwill/uniwill-acpi.c @@ -1543,12 +1543,18 @@ static void uniwill_lightbar_trigger_deactivate(struct led_classdev *led_cdev) dev_err(led_cdev->dev, "Failed to stop rainbow animation: %d\n", ret); } +static bool uniwill_lightbar_trigger_hw_offloaded(struct led_classdev *led_cdev) +{ + return true; +} + static struct led_hw_trigger_type uniwill_lightbar_trigger_type; static struct led_trigger uniwill_lightbar_trigger = { .name = "uniwill-rainbow", .activate = uniwill_lightbar_trigger_activate, .deactivate = uniwill_lightbar_trigger_deactivate, + .hw_offloaded = uniwill_lightbar_trigger_hw_offloaded, .trigger_type = &uniwill_lightbar_trigger_type, }; @@ -2366,7 +2372,7 @@ static int uniwill_probe(struct platform_device *pdev) if (!handle) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/x86-android-tablets/other.c b/drivers/platform/x86/x86-android-tablets/other.c index 7532af2d72d1d9..0ee2531c3891cc 100644 --- a/drivers/platform/x86/x86-android-tablets/other.c +++ b/drivers/platform/x86/x86-android-tablets/other.c @@ -832,7 +832,7 @@ static int __init xiaomi_mipad2_init(struct device *dev) if (IS_ERR(xiaomi_mipad2_led_pwm)) return dev_err_probe(dev, PTR_ERR(xiaomi_mipad2_led_pwm), "getting pwm\n"); - led_cdev = devm_kzalloc(dev, sizeof(*led_cdev), GFP_KERNEL); + led_cdev = devm_kzalloc_obj(dev, *led_cdev); if (!led_cdev) return -ENOMEM; diff --git a/drivers/platform/x86/x86-android-tablets/vexia_atla10_ec.c b/drivers/platform/x86/x86-android-tablets/vexia_atla10_ec.c index 67dba9aa51f66a..90d925f3543b37 100644 --- a/drivers/platform/x86/x86-android-tablets/vexia_atla10_ec.c +++ b/drivers/platform/x86/x86-android-tablets/vexia_atla10_ec.c @@ -216,7 +216,7 @@ static int atla10_ec_probe(struct i2c_client *client) struct atla10_ec_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/platform/x86/xiaomi-wmi.c b/drivers/platform/x86/xiaomi-wmi.c index 3874f3336a0dc1..60226ccb3d902e 100644 --- a/drivers/platform/x86/xiaomi-wmi.c +++ b/drivers/platform/x86/xiaomi-wmi.c @@ -33,7 +33,7 @@ static int xiaomi_wmi_probe(struct wmi_device *wdev, const void *context) if (!context) return -EINVAL; - data = devm_kzalloc(&wdev->dev, sizeof(struct xiaomi_wmi), GFP_KERNEL); + data = devm_kzalloc_obj(&wdev->dev, struct xiaomi_wmi); if (data == NULL) return -ENOMEM; dev_set_drvdata(&wdev->dev, data); diff --git a/drivers/platform/x86/xo15-ebook.c b/drivers/platform/x86/xo15-ebook.c index 4c3185e2ceec21..bbc8a87d904d3e 100644 --- a/drivers/platform/x86/xo15-ebook.c +++ b/drivers/platform/x86/xo15-ebook.c @@ -86,7 +86,7 @@ static int ebook_switch_probe(struct platform_device *pdev) struct input_dev *input; int error; - button = devm_kzalloc(dev, sizeof(*button), GFP_KERNEL); + button = devm_kzalloc_obj(dev, *button); if (!button) return -ENOMEM; diff --git a/drivers/pmdomain/actions/owl-sps.c b/drivers/pmdomain/actions/owl-sps.c index bf5eb80cc3b4db..793c63f30635f4 100644 --- a/drivers/pmdomain/actions/owl-sps.c +++ b/drivers/pmdomain/actions/owl-sps.c @@ -77,7 +77,7 @@ static int owl_sps_init_domain(struct owl_sps *sps, int index) { struct owl_sps_domain *pd; - pd = devm_kzalloc(sps->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(sps->dev, *pd); if (!pd) return -ENOMEM; @@ -107,9 +107,8 @@ static int owl_sps_probe(struct platform_device *pdev) return -EINVAL; } - sps = devm_kzalloc(&pdev->dev, - struct_size(sps, domains, sps_info->num_domains), - GFP_KERNEL); + sps = devm_kzalloc_flex(&pdev->dev, *sps, domains, + sps_info->num_domains); if (!sps) return -ENOMEM; diff --git a/drivers/pmdomain/amlogic/meson-ee-pwrc.c b/drivers/pmdomain/amlogic/meson-ee-pwrc.c index 55c8c9f66a1b7a..338f70d77bf037 100644 --- a/drivers/pmdomain/amlogic/meson-ee-pwrc.c +++ b/drivers/pmdomain/amlogic/meson-ee-pwrc.c @@ -511,18 +511,18 @@ static int meson_ee_pwrc_probe(struct platform_device *pdev) return -ENODEV; } - pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + pwrc = devm_kzalloc_obj(&pdev->dev, *pwrc); if (!pwrc) return -ENOMEM; - pwrc->xlate.domains = devm_kcalloc(&pdev->dev, match->count, - sizeof(*pwrc->xlate.domains), - GFP_KERNEL); + pwrc->xlate.domains = devm_kzalloc_objs(&pdev->dev, + *pwrc->xlate.domains, + match->count); if (!pwrc->xlate.domains) return -ENOMEM; - pwrc->domains = devm_kcalloc(&pdev->dev, match->count, - sizeof(*pwrc->domains), GFP_KERNEL); + pwrc->domains = devm_kzalloc_objs(&pdev->dev, *pwrc->domains, + match->count); if (!pwrc->domains) return -ENOMEM; diff --git a/drivers/pmdomain/amlogic/meson-secure-pwrc.c b/drivers/pmdomain/amlogic/meson-secure-pwrc.c index 133549956efa48..c424a1e7617479 100644 --- a/drivers/pmdomain/amlogic/meson-secure-pwrc.c +++ b/drivers/pmdomain/amlogic/meson-secure-pwrc.c @@ -411,7 +411,7 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev) return -ENODEV; } - pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + pwrc = devm_kzalloc_obj(&pdev->dev, *pwrc); if (!pwrc) { of_node_put(sm_np); return -ENOMEM; @@ -422,14 +422,14 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev) if (!pwrc->fw) return -EPROBE_DEFER; - pwrc->xlate.domains = devm_kcalloc(&pdev->dev, match->count, - sizeof(*pwrc->xlate.domains), - GFP_KERNEL); + pwrc->xlate.domains = devm_kzalloc_objs(&pdev->dev, + *pwrc->xlate.domains, + match->count); if (!pwrc->xlate.domains) return -ENOMEM; - pwrc->domains = devm_kcalloc(&pdev->dev, match->count, - sizeof(*pwrc->domains), GFP_KERNEL); + pwrc->domains = devm_kzalloc_objs(&pdev->dev, *pwrc->domains, + match->count); if (!pwrc->domains) return -ENOMEM; diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 82c33cf727a825..1f6c88481152a5 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -205,7 +205,7 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL); + ps = devm_kzalloc_obj(dev, *ps); if (!ps) return -ENOMEM; diff --git a/drivers/pmdomain/arm/scmi_perf_domain.c b/drivers/pmdomain/arm/scmi_perf_domain.c index e390f902a44426..b1d20fecaf3e43 100644 --- a/drivers/pmdomain/arm/scmi_perf_domain.c +++ b/drivers/pmdomain/arm/scmi_perf_domain.c @@ -105,15 +105,15 @@ static int scmi_perf_domain_probe(struct scmi_device *sdev) return 0; } - scmi_pd = devm_kcalloc(dev, num_domains, sizeof(*scmi_pd), GFP_KERNEL); + scmi_pd = devm_kzalloc_objs(dev, *scmi_pd, num_domains); if (!scmi_pd) return -ENOMEM; - scmi_pd_data = devm_kzalloc(dev, sizeof(*scmi_pd_data), GFP_KERNEL); + scmi_pd_data = devm_kzalloc_obj(dev, *scmi_pd_data); if (!scmi_pd_data) return -ENOMEM; - domains = devm_kcalloc(dev, num_domains, sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, num_domains); if (!domains) return -ENOMEM; diff --git a/drivers/pmdomain/arm/scmi_pm_domain.c b/drivers/pmdomain/arm/scmi_pm_domain.c index 3d73aef21d2f99..fff7b4f438cae7 100644 --- a/drivers/pmdomain/arm/scmi_pm_domain.c +++ b/drivers/pmdomain/arm/scmi_pm_domain.c @@ -63,15 +63,15 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev) return num_domains; } - scmi_pd = devm_kcalloc(dev, num_domains, sizeof(*scmi_pd), GFP_KERNEL); + scmi_pd = devm_kzalloc_objs(dev, *scmi_pd, num_domains); if (!scmi_pd) return -ENOMEM; - scmi_pd_data = devm_kzalloc(dev, sizeof(*scmi_pd_data), GFP_KERNEL); + scmi_pd_data = devm_kzalloc_obj(dev, *scmi_pd_data); if (!scmi_pd_data) return -ENOMEM; - domains = devm_kcalloc(dev, num_domains, sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, num_domains); if (!domains) return -ENOMEM; diff --git a/drivers/pmdomain/arm/scpi_pm_domain.c b/drivers/pmdomain/arm/scpi_pm_domain.c index 2231e6dd2070a2..1d55a9e548e0e2 100644 --- a/drivers/pmdomain/arm/scpi_pm_domain.c +++ b/drivers/pmdomain/arm/scpi_pm_domain.c @@ -93,15 +93,15 @@ static int scpi_pm_domain_probe(struct platform_device *pdev) return -EINVAL; } - scpi_pd = devm_kcalloc(dev, num_domains, sizeof(*scpi_pd), GFP_KERNEL); + scpi_pd = devm_kzalloc_objs(dev, *scpi_pd, num_domains); if (!scpi_pd) return -ENOMEM; - scpi_pd_data = devm_kzalloc(dev, sizeof(*scpi_pd_data), GFP_KERNEL); + scpi_pd_data = devm_kzalloc_obj(dev, *scpi_pd_data); if (!scpi_pd_data) return -ENOMEM; - domains = devm_kcalloc(dev, num_domains, sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, num_domains); if (!domains) return -ENOMEM; diff --git a/drivers/pmdomain/bcm/bcm-pmb.c b/drivers/pmdomain/bcm/bcm-pmb.c index a72ba26ecf9d60..d074c8cf2038bc 100644 --- a/drivers/pmdomain/bcm/bcm-pmb.c +++ b/drivers/pmdomain/bcm/bcm-pmb.c @@ -279,7 +279,7 @@ static int bcm_pmb_probe(struct platform_device *pdev) int max_id; int err; - pmb = devm_kzalloc(dev, sizeof(*pmb), GFP_KERNEL); + pmb = devm_kzalloc_obj(dev, *pmb); if (!pmb) return -ENOMEM; @@ -303,13 +303,13 @@ static int bcm_pmb_probe(struct platform_device *pdev) pmb->genpd_onecell_data.num_domains = max_id + 1; pmb->genpd_onecell_data.domains = - devm_kcalloc(dev, pmb->genpd_onecell_data.num_domains, - sizeof(struct generic_pm_domain *), GFP_KERNEL); + devm_kzalloc_objs(dev, struct generic_pm_domain *, + pmb->genpd_onecell_data.num_domains); if (!pmb->genpd_onecell_data.domains) return -ENOMEM; for (e = table; e->name; e++) { - struct bcm_pmb_pm_domain *pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + struct bcm_pmb_pm_domain *pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; diff --git a/drivers/pmdomain/bcm/bcm2835-power.c b/drivers/pmdomain/bcm/bcm2835-power.c index fad3113093d535..6fd48e34a68d47 100644 --- a/drivers/pmdomain/bcm/bcm2835-power.c +++ b/drivers/pmdomain/bcm/bcm2835-power.c @@ -621,7 +621,7 @@ static int bcm2835_power_probe(struct platform_device *pdev) int ret = 0, i; u32 id; - power = devm_kzalloc(dev, sizeof(*power), GFP_KERNEL); + power = devm_kzalloc_obj(dev, *power); if (!power) return -ENOMEM; platform_set_drvdata(pdev, power); @@ -648,10 +648,9 @@ static int bcm2835_power_probe(struct platform_device *pdev) } } - power->pd_xlate.domains = devm_kcalloc(dev, - ARRAY_SIZE(power_domain_names), - sizeof(*power->pd_xlate.domains), - GFP_KERNEL); + power->pd_xlate.domains = devm_kzalloc_objs(dev, + *power->pd_xlate.domains, + ARRAY_SIZE(power_domain_names)); if (!power->pd_xlate.domains) return -ENOMEM; diff --git a/drivers/pmdomain/bcm/bcm63xx-power.c b/drivers/pmdomain/bcm/bcm63xx-power.c index 98b0c2430dbc6b..9454f9066709ce 100644 --- a/drivers/pmdomain/bcm/bcm63xx-power.c +++ b/drivers/pmdomain/bcm/bcm63xx-power.c @@ -96,7 +96,7 @@ static int bcm63xx_power_probe(struct platform_device *pdev) uint8_t max_bit = 0; int ret; - power = devm_kzalloc(dev, sizeof(*power), GFP_KERNEL); + power = devm_kzalloc_obj(dev, *power); if (!power) return -ENOMEM; @@ -120,15 +120,13 @@ static int bcm63xx_power_probe(struct platform_device *pdev) power->genpd_data.num_domains = max_bit + 1; - power->dev = devm_kcalloc(dev, power->genpd_data.num_domains, - sizeof(struct bcm63xx_power_dev), - GFP_KERNEL); + power->dev = devm_kzalloc_objs(dev, struct bcm63xx_power_dev, + power->genpd_data.num_domains); if (!power->dev) return -ENOMEM; - power->genpd = devm_kcalloc(dev, power->genpd_data.num_domains, - sizeof(struct generic_pm_domain *), - GFP_KERNEL); + power->genpd = devm_kzalloc_objs(dev, struct generic_pm_domain *, + power->genpd_data.num_domains); if (!power->genpd) return -ENOMEM; diff --git a/drivers/pmdomain/bcm/raspberrypi-power.c b/drivers/pmdomain/bcm/raspberrypi-power.c index b87ea7adb7beac..1304c5545f3613 100644 --- a/drivers/pmdomain/bcm/raspberrypi-power.c +++ b/drivers/pmdomain/bcm/raspberrypi-power.c @@ -164,15 +164,13 @@ static int rpi_power_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rpi_power_domains *rpi_domains; - rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL); + rpi_domains = devm_kzalloc_obj(dev, *rpi_domains); if (!rpi_domains) return -ENOMEM; rpi_domains->xlate.domains = - devm_kcalloc(dev, - RPI_POWER_DOMAIN_COUNT, - sizeof(*rpi_domains->xlate.domains), - GFP_KERNEL); + devm_kzalloc_objs(dev, *rpi_domains->xlate.domains, + RPI_POWER_DOMAIN_COUNT); if (!rpi_domains->xlate.domains) return -ENOMEM; diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c index 14fb969bba2876..9df933a7a2380d 100644 --- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c +++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c @@ -206,7 +206,7 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev) .reg_stride = 4, }; - bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL); + bc = devm_kzalloc_obj(dev, *bc); if (!bc) return -ENOMEM; @@ -228,16 +228,15 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(bc->regmap), "failed to init regmap\n"); - bc->domains = devm_kcalloc(dev, bc_data->num_domains, - sizeof(struct imx8m_blk_ctrl_domain), - GFP_KERNEL); + bc->domains = devm_kzalloc_objs(dev, struct imx8m_blk_ctrl_domain, + bc_data->num_domains); if (!bc->domains) return -ENOMEM; bc->onecell_data.num_domains = bc_data->num_domains; bc->onecell_data.domains = - devm_kcalloc(dev, bc_data->num_domains, - sizeof(struct generic_pm_domain *), GFP_KERNEL); + devm_kzalloc_objs(dev, struct generic_pm_domain *, + bc_data->num_domains); if (!bc->onecell_data.domains) return -ENOMEM; diff --git a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c index d255c20f58e21b..212d491c75e4f7 100644 --- a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c +++ b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c @@ -153,7 +153,7 @@ static int imx8mp_hsio_blk_ctrl_probe(struct imx8mp_blk_ctrl *bc) struct clk_init_data init = {}; int ret; - clk_hsio_pll = devm_kzalloc(bc->dev, sizeof(*clk_hsio_pll), GFP_KERNEL); + clk_hsio_pll = devm_kzalloc_obj(bc->dev, *clk_hsio_pll); if (!clk_hsio_pll) return -ENOMEM; @@ -622,7 +622,7 @@ static int imx8mp_blk_ctrl_probe(struct platform_device *pdev) .reg_stride = 4, }; - bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL); + bc = devm_kzalloc_obj(dev, *bc); if (!bc) return -ENOMEM; @@ -641,16 +641,14 @@ static int imx8mp_blk_ctrl_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(bc->regmap), "failed to init regmap\n"); - bc->domains = devm_kcalloc(dev, num_domains, - sizeof(struct imx8mp_blk_ctrl_domain), - GFP_KERNEL); + bc->domains = devm_kzalloc_objs(dev, struct imx8mp_blk_ctrl_domain, + num_domains); if (!bc->domains) return -ENOMEM; bc->onecell_data.num_domains = num_domains; bc->onecell_data.domains = - devm_kcalloc(dev, num_domains, - sizeof(struct generic_pm_domain *), GFP_KERNEL); + devm_kzalloc_objs(dev, struct generic_pm_domain *, num_domains); if (!bc->onecell_data.domains) return -ENOMEM; diff --git a/drivers/pmdomain/imx/imx93-blk-ctrl.c b/drivers/pmdomain/imx/imx93-blk-ctrl.c index 6d4c55a85c6457..9ff38e3d5c6ca1 100644 --- a/drivers/pmdomain/imx/imx93-blk-ctrl.c +++ b/drivers/pmdomain/imx/imx93-blk-ctrl.c @@ -236,7 +236,7 @@ static int imx93_blk_ctrl_probe(struct platform_device *pdev) .max_register = SZ_4K, }; - bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL); + bc = devm_kzalloc_obj(dev, *bc); if (!bc) return -ENOMEM; @@ -251,16 +251,15 @@ static int imx93_blk_ctrl_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(bc->regmap), "failed to init regmap\n"); - bc->domains = devm_kcalloc(dev, bc_data->num_domains, - sizeof(struct imx93_blk_ctrl_domain), - GFP_KERNEL); + bc->domains = devm_kzalloc_objs(dev, struct imx93_blk_ctrl_domain, + bc_data->num_domains); if (!bc->domains) return -ENOMEM; bc->onecell_data.num_domains = bc_data->num_domains; bc->onecell_data.domains = - devm_kcalloc(dev, bc_data->num_domains, - sizeof(struct generic_pm_domain *), GFP_KERNEL); + devm_kzalloc_objs(dev, struct generic_pm_domain *, + bc_data->num_domains); if (!bc->onecell_data.domains) return -ENOMEM; @@ -325,7 +324,7 @@ static int imx93_blk_ctrl_probe(struct platform_device *pdev) data->parent == BLK_CTRL_NO_PARENT) continue; - link = devm_kzalloc(dev, sizeof(*link), GFP_KERNEL); + link = devm_kzalloc_obj(dev, *link); if (!link) return -ENOMEM; diff --git a/drivers/pmdomain/imx/imx93-pd.c b/drivers/pmdomain/imx/imx93-pd.c index 50d1eb852f759f..75c315ca37295a 100644 --- a/drivers/pmdomain/imx/imx93-pd.c +++ b/drivers/pmdomain/imx/imx93-pd.c @@ -100,7 +100,7 @@ static int imx93_pd_probe(struct platform_device *pdev) bool init_off; int ret; - domain = devm_kzalloc(dev, sizeof(*domain), GFP_KERNEL); + domain = devm_kzalloc_obj(dev, *domain); if (!domain) return -ENOMEM; diff --git a/drivers/pmdomain/imx/scu-pd.c b/drivers/pmdomain/imx/scu-pd.c index 05d4364f34be9d..32864dd7d17de3 100644 --- a/drivers/pmdomain/imx/scu-pd.c +++ b/drivers/pmdomain/imx/scu-pd.c @@ -420,7 +420,7 @@ imx_scu_add_pm_domain(struct device *dev, int idx, if (!imx_sc_rm_is_resource_owned(pm_ipc_handle, pd_ranges->rsrc + idx)) return NULL; - sc_pd = devm_kzalloc(dev, sizeof(*sc_pd), GFP_KERNEL); + sc_pd = devm_kzalloc_obj(dev, *sc_pd); if (!sc_pd) return ERR_PTR(-ENOMEM); @@ -479,11 +479,11 @@ static int imx_scu_init_pm_domains(struct device *dev, for (i = 0; i < pd_soc->num_ranges; i++) count += pd_ranges[i].num; - domains = devm_kcalloc(dev, count, sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, count); if (!domains) return -ENOMEM; - pd_data = devm_kzalloc(dev, sizeof(*pd_data), GFP_KERNEL); + pd_data = devm_kzalloc_obj(dev, *pd_data); if (!pd_data) return -ENOMEM; diff --git a/drivers/pmdomain/marvell/pxa1908-power-controller.c b/drivers/pmdomain/marvell/pxa1908-power-controller.c index 4a957ab0e4f58f..a156541803d82f 100644 --- a/drivers/pmdomain/marvell/pxa1908-power-controller.c +++ b/drivers/pmdomain/marvell/pxa1908-power-controller.c @@ -259,7 +259,7 @@ pxa1908_pd_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_ struct device *dev = &auxdev->dev; int ret; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c b/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c index 5efd7a38f4daab..03556fb0cccf37 100644 --- a/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c +++ b/drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c @@ -70,7 +70,7 @@ static int airoha_cpu_pmdomain_probe(struct platform_device *pdev) struct generic_pm_domain *pd; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c index 1417ffc22b3e0e..093f8fac2a2cd7 100644 --- a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c +++ b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c @@ -537,14 +537,14 @@ static int mtk_mfg_read_opp_tables(struct mtk_mfg *mfg) return -EINVAL; } - mfg->gpu_opps = devm_kcalloc(dev, mfg->num_gpu_opps, - sizeof(struct dev_pm_opp_data), GFP_KERNEL); + mfg->gpu_opps = devm_kzalloc_objs(dev, struct dev_pm_opp_data, + mfg->num_gpu_opps); if (!mfg->gpu_opps) return -ENOMEM; if (mfg->num_stack_opps) { - mfg->stack_opps = devm_kcalloc(dev, mfg->num_stack_opps, - sizeof(struct dev_pm_opp_data), GFP_KERNEL); + mfg->stack_opps = devm_kzalloc_objs(dev, struct dev_pm_opp_data, + mfg->num_stack_opps); if (!mfg->stack_opps) return -ENOMEM; } @@ -782,7 +782,7 @@ static int mtk_mfg_init_mbox(struct mtk_mfg *mfg) struct mtk_mfg_mbox *gf; struct mtk_mfg_mbox *slp; - gf = devm_kzalloc(dev, sizeof(*gf), GFP_KERNEL); + gf = devm_kzalloc_obj(dev, *gf); if (!gf) return -ENOMEM; @@ -801,7 +801,7 @@ static int mtk_mfg_init_mbox(struct mtk_mfg *mfg) mfg->gf_mbox = gf; - slp = devm_kzalloc(dev, sizeof(*slp), GFP_KERNEL); + slp = devm_kzalloc_obj(dev, *slp); if (!slp) return -ENOMEM; @@ -827,7 +827,7 @@ static int mtk_mfg_init_clk_provider(struct mtk_mfg *mfg) struct clk_hw_onecell_data *clk_data; int ret; - clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, 2), GFP_KERNEL); + clk_data = devm_kzalloc_flex(dev, *clk_data, hws, 2); if (!clk_data) return -ENOMEM; @@ -916,7 +916,7 @@ static int mtk_mfg_probe(struct platform_device *pdev) struct resource res; int ret, i; - mfg = devm_kzalloc(dev, sizeof(*mfg), GFP_KERNEL); + mfg = devm_kzalloc_obj(dev, *mfg); if (!mfg) return -ENOMEM; @@ -940,8 +940,7 @@ static int mtk_mfg_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(mfg->clk_eb), "Couldn't get 'eb' clock\n"); - mfg->gpu_clks = devm_kcalloc(dev, data->num_clks, sizeof(*mfg->gpu_clks), - GFP_KERNEL); + mfg->gpu_clks = devm_kzalloc_objs(dev, *mfg->gpu_clks, data->num_clks); if (!mfg->gpu_clks) return -ENOMEM; @@ -952,8 +951,8 @@ static int mtk_mfg_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "Couldn't get GPU clocks\n"); - mfg->gpu_regs = devm_kcalloc(dev, data->num_regulators, - sizeof(*mfg->gpu_regs), GFP_KERNEL); + mfg->gpu_regs = devm_kzalloc_objs(dev, *mfg->gpu_regs, + data->num_regulators); if (!mfg->gpu_regs) return -ENOMEM; diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c b/drivers/pmdomain/mediatek/mtk-pm-domains.c index f0fa79e01f9c37..5f85db3fc5394a 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c @@ -892,7 +892,7 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no return ERR_PTR(-EINVAL); } - pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(scpsys->dev, *pd); if (!pd) return ERR_PTR(-ENOMEM); @@ -921,12 +921,14 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys *scpsys, struct device_no pd->num_clks++; } - pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); + pd->clks = devm_kzalloc_objs(scpsys->dev, *pd->clks, + pd->num_clks); if (!pd->clks) return ERR_PTR(-ENOMEM); - pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, - sizeof(*pd->subsys_clks), GFP_KERNEL); + pd->subsys_clks = devm_kzalloc_objs(scpsys->dev, + *pd->subsys_clks, + pd->num_subsys_clks); if (!pd->subsys_clks) return ERR_PTR(-ENOMEM); @@ -1215,8 +1217,8 @@ static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s return 0; } - scpsys->bus_prot = devm_kmalloc_array(dev, num_regmaps, - sizeof(*scpsys->bus_prot), GFP_KERNEL); + scpsys->bus_prot = devm_kmalloc_objs(dev, *scpsys->bus_prot, + num_regmaps); if (!scpsys->bus_prot) return -ENOMEM; @@ -1248,8 +1250,8 @@ static int scpsys_get_bus_protection(struct device *dev, struct scpsys *scpsys) "Cannot get access controllers: expected %u, got %d\n", soc->num_bus_prot_blocks, num_handles); - scpsys->bus_prot = devm_kmalloc_array(dev, soc->num_bus_prot_blocks, - sizeof(*scpsys->bus_prot), GFP_KERNEL); + scpsys->bus_prot = devm_kmalloc_objs(dev, *scpsys->bus_prot, + soc->num_bus_prot_blocks); if (!scpsys->bus_prot) return -ENOMEM; @@ -1371,7 +1373,7 @@ static int scpsys_probe(struct platform_device *pdev) num_domains = soc->num_domains + soc->num_hwv_domains; - scpsys = devm_kzalloc(dev, struct_size(scpsys, domains, num_domains), GFP_KERNEL); + scpsys = devm_kzalloc_flex(dev, *scpsys, domains, num_domains); if (!scpsys) return -ENOMEM; diff --git a/drivers/pmdomain/mediatek/mtk-scpsys.c b/drivers/pmdomain/mediatek/mtk-scpsys.c index efc8f276ffce1e..5a3ef8ba1a253e 100644 --- a/drivers/pmdomain/mediatek/mtk-scpsys.c +++ b/drivers/pmdomain/mediatek/mtk-scpsys.c @@ -429,7 +429,7 @@ static struct scp *init_scp(struct platform_device *pdev, struct scp *scp; struct clk *clk[CLK_MAX]; - scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL); + scp = devm_kzalloc_obj(&pdev->dev, *scp); if (!scp) return ERR_PTR(-ENOMEM); @@ -444,15 +444,13 @@ static struct scp *init_scp(struct platform_device *pdev, if (IS_ERR(scp->base)) return ERR_CAST(scp->base); - scp->domains = devm_kcalloc(&pdev->dev, - num, sizeof(*scp->domains), GFP_KERNEL); + scp->domains = devm_kzalloc_objs(&pdev->dev, *scp->domains, num); if (!scp->domains) return ERR_PTR(-ENOMEM); pd_data = &scp->pd_data; - pd_data->domains = devm_kcalloc(&pdev->dev, - num, sizeof(*pd_data->domains), GFP_KERNEL); + pd_data->domains = devm_kzalloc_objs(&pdev->dev, *pd_data->domains, num); if (!pd_data->domains) return ERR_PTR(-ENOMEM); diff --git a/drivers/pmdomain/qcom/cpr.c b/drivers/pmdomain/qcom/cpr.c index c30690ef6919c6..4e86ffc85a5b39 100644 --- a/drivers/pmdomain/qcom/cpr.c +++ b/drivers/pmdomain/qcom/cpr.c @@ -1086,9 +1086,8 @@ static int cpr_corner_init(struct cpr_drv *drv) corner = drv->corners; end = &corner[drv->num_corners - 1]; - cdata = devm_kcalloc(drv->dev, drv->num_corners, - sizeof(struct corner_data), - GFP_KERNEL); + cdata = devm_kzalloc_objs(drv->dev, struct corner_data, + drv->num_corners); if (!cdata) return -ENOMEM; @@ -1220,9 +1219,8 @@ static const struct cpr_fuse *cpr_get_fuses(struct cpr_drv *drv) struct cpr_fuse *fuses; int i; - fuses = devm_kcalloc(drv->dev, desc->num_fuse_corners, - sizeof(struct cpr_fuse), - GFP_KERNEL); + fuses = devm_kzalloc_objs(drv->dev, struct cpr_fuse, + desc->num_fuse_corners); if (!fuses) return ERR_PTR(-ENOMEM); @@ -1489,9 +1487,8 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain, return -EINVAL; } - drv->corners = devm_kcalloc(drv->dev, drv->num_corners, - sizeof(*drv->corners), - GFP_KERNEL); + drv->corners = devm_kzalloc_objs(drv->dev, *drv->corners, + drv->num_corners); if (!drv->corners) return -ENOMEM; @@ -1601,9 +1598,8 @@ static int cpr_probe(struct platform_device *pdev) if (!data || !data->cpr_desc || !data->acc_desc) return -EINVAL; - drv = devm_kzalloc(dev, - struct_size(drv, fuse_corners, data->cpr_desc->num_fuse_corners), - GFP_KERNEL); + drv = devm_kzalloc_flex(dev, *drv, fuse_corners, + data->cpr_desc->num_fuse_corners); if (!drv) return -ENOMEM; drv->dev = dev; diff --git a/drivers/pmdomain/qcom/rpmhpd.c b/drivers/pmdomain/qcom/rpmhpd.c index fa8fed5bd3e585..919efa34e3a36a 100644 --- a/drivers/pmdomain/qcom/rpmhpd.c +++ b/drivers/pmdomain/qcom/rpmhpd.c @@ -1178,12 +1178,11 @@ static int rpmhpd_probe(struct platform_device *pdev) rpmhpds = desc->rpmhpds; num_pds = desc->num_pds; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; - data->domains = devm_kcalloc(dev, num_pds, sizeof(*data->domains), - GFP_KERNEL); + data->domains = devm_kzalloc_objs(dev, *data->domains, num_pds); if (!data->domains) return -ENOMEM; diff --git a/drivers/pmdomain/qcom/rpmpd.c b/drivers/pmdomain/qcom/rpmpd.c index 5f55fc791131a1..1a952cdaa3f7f9 100644 --- a/drivers/pmdomain/qcom/rpmpd.c +++ b/drivers/pmdomain/qcom/rpmpd.c @@ -1103,12 +1103,11 @@ static int rpmpd_probe(struct platform_device *pdev) rpmpds = desc->rpmpds; num = desc->num_pds; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; - data->domains = devm_kcalloc(&pdev->dev, num, sizeof(*data->domains), - GFP_KERNEL); + data->domains = devm_kzalloc_objs(&pdev->dev, *data->domains, num); if (!data->domains) return -ENOMEM; diff --git a/drivers/pmdomain/renesas/r8a78000-mdlc.c b/drivers/pmdomain/renesas/r8a78000-mdlc.c index 1fd71bb3da776e..75de869872de9e 100644 --- a/drivers/pmdomain/renesas/r8a78000-mdlc.c +++ b/drivers/pmdomain/renesas/r8a78000-mdlc.c @@ -236,7 +236,7 @@ static int r8a78000_mdlc_probe(struct platform_device *pdev) if (!info) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c index c7c46717dd7329..86b58ab29ca505 100644 --- a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c +++ b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c @@ -336,7 +336,7 @@ static int rpmi_pm_domain_probe(struct platform_device *pdev) int ret; u32 i; - mpxy_ctx = devm_kzalloc(&pdev->dev, sizeof(*mpxy_ctx), GFP_KERNEL); + mpxy_ctx = devm_kzalloc_obj(&pdev->dev, *mpxy_ctx); if (!mpxy_ctx) return -ENOMEM; @@ -378,15 +378,15 @@ static int rpmi_pm_domain_probe(struct platform_device *pdev) dev_info(&pdev->dev, "%u MPXY PM domains are found\n", num_domains); - mpxy_pd = devm_kcalloc(&pdev->dev, num_domains, sizeof(*mpxy_pd), GFP_KERNEL); + mpxy_pd = devm_kzalloc_objs(&pdev->dev, *mpxy_pd, num_domains); if (!mpxy_pd) return -ENOMEM; - domains = devm_kcalloc(&pdev->dev, num_domains, sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(&pdev->dev, *domains, num_domains); if (!domains) return -ENOMEM; - mpxy_pd_data = devm_kzalloc(&pdev->dev, sizeof(*mpxy_pd_data), GFP_KERNEL); + mpxy_pd_data = devm_kzalloc_obj(&pdev->dev, *mpxy_pd_data); if (!mpxy_pd_data) return -ENOMEM; diff --git a/drivers/pmdomain/rockchip/pm-domains.c b/drivers/pmdomain/rockchip/pm-domains.c index db3879846db67f..6eca21e0bb1262 100644 --- a/drivers/pmdomain/rockchip/pm-domains.c +++ b/drivers/pmdomain/rockchip/pm-domains.c @@ -827,7 +827,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, return -EINVAL; } - pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(pmu->dev, *pd); if (!pd) return -ENOMEM; @@ -837,8 +837,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->num_clks = of_clk_get_parent_count(node); if (pd->num_clks > 0) { - pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, - sizeof(*pd->clks), GFP_KERNEL); + pd->clks = devm_kzalloc_objs(pmu->dev, *pd->clks, pd->num_clks); if (!pd->clks) return -ENOMEM; } else { @@ -866,19 +865,16 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, NULL); if (pd->num_qos > 0) { - pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, - sizeof(*pd->qos_regmap), - GFP_KERNEL); + pd->qos_regmap = devm_kzalloc_objs(pmu->dev, *pd->qos_regmap, + pd->num_qos); if (!pd->qos_regmap) { error = -ENOMEM; goto err_unprepare_clocks; } for (j = 0; j < MAX_QOS_REGS_NUM; j++) { - pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, - pd->num_qos, - sizeof(u32), - GFP_KERNEL); + pd->qos_save_regs[j] = devm_kzalloc_objs(pmu->dev, u32, + pd->num_qos); if (!pd->qos_save_regs[j]) { error = -ENOMEM; goto err_unprepare_clocks; @@ -1054,9 +1050,7 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev) pmu_info = device_get_match_data(dev); - pmu = devm_kzalloc(dev, - struct_size(pmu, domains, pmu_info->num_domains), - GFP_KERNEL); + pmu = devm_kzalloc_flex(dev, *pmu, domains, pmu_info->num_domains); if (!pmu) return -ENOMEM; diff --git a/drivers/pmdomain/samsung/exynos-pm-domains.c b/drivers/pmdomain/samsung/exynos-pm-domains.c index 5c3aa898308793..c8c2ea06e99099 100644 --- a/drivers/pmdomain/samsung/exynos-pm-domains.c +++ b/drivers/pmdomain/samsung/exynos-pm-domains.c @@ -112,7 +112,7 @@ static int exynos_pd_probe(struct platform_device *pdev) int on, ret; pm_domain_cfg = of_device_get_match_data(dev); - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; diff --git a/drivers/pmdomain/starfive/jh71xx-pmu.c b/drivers/pmdomain/starfive/jh71xx-pmu.c index 74720c09a6e3a6..c48fadfd412a50 100644 --- a/drivers/pmdomain/starfive/jh71xx-pmu.c +++ b/drivers/pmdomain/starfive/jh71xx-pmu.c @@ -291,7 +291,7 @@ static int jh71xx_pmu_init_domain(struct jh71xx_pmu *pmu, int index) int ret; bool is_on = false; - pmd = devm_kzalloc(pmu->dev, sizeof(*pmd), GFP_KERNEL); + pmd = devm_kzalloc_obj(pmu->dev, *pmd); if (!pmd) return -ENOMEM; @@ -325,7 +325,7 @@ static int jh71xx_pmu_probe(struct platform_device *pdev) unsigned int i; int ret; - pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(dev, *pmu); if (!pmu) return -ENOMEM; @@ -347,9 +347,8 @@ static int jh71xx_pmu_probe(struct platform_device *pdev) } } - pmu->genpd = devm_kcalloc(dev, match_data->num_domains, - sizeof(struct generic_pm_domain *), - GFP_KERNEL); + pmu->genpd = devm_kzalloc_objs(dev, struct generic_pm_domain *, + match_data->num_domains); if (!pmu->genpd) return -ENOMEM; diff --git a/drivers/pmdomain/sunxi/sun20i-ppu.c b/drivers/pmdomain/sunxi/sun20i-ppu.c index b65876a68cc172..6af1dcad4a76e5 100644 --- a/drivers/pmdomain/sunxi/sun20i-ppu.c +++ b/drivers/pmdomain/sunxi/sun20i-ppu.c @@ -114,16 +114,15 @@ static int sun20i_ppu_probe(struct platform_device *pdev) if (!desc) return -EINVAL; - pds = devm_kcalloc(dev, desc->num_domains, sizeof(*pds), GFP_KERNEL); + pds = devm_kzalloc_objs(dev, *pds, desc->num_domains); if (!pds) return -ENOMEM; - ppu = devm_kzalloc(dev, sizeof(*ppu), GFP_KERNEL); + ppu = devm_kzalloc_obj(dev, *ppu); if (!ppu) return -ENOMEM; - ppu->domains = devm_kcalloc(dev, desc->num_domains, - sizeof(*ppu->domains), GFP_KERNEL); + ppu->domains = devm_kzalloc_objs(dev, *ppu->domains, desc->num_domains); if (!ppu->domains) return -ENOMEM; diff --git a/drivers/pmdomain/sunxi/sun50i-h6-prcm-ppu.c b/drivers/pmdomain/sunxi/sun50i-h6-prcm-ppu.c index d59644499dfe0b..cde5a27e080979 100644 --- a/drivers/pmdomain/sunxi/sun50i-h6-prcm-ppu.c +++ b/drivers/pmdomain/sunxi/sun50i-h6-prcm-ppu.c @@ -128,17 +128,16 @@ static int sun50i_h6_ppu_probe(struct platform_device *pdev) if (!data) return -EINVAL; - pds = devm_kcalloc(dev, data->nr_domains, sizeof(*pds), GFP_KERNEL); + pds = devm_kzalloc_objs(dev, *pds, data->nr_domains); if (!pds) return -ENOMEM; - ppu = devm_kzalloc(dev, sizeof(*ppu), GFP_KERNEL); + ppu = devm_kzalloc_obj(dev, *ppu); if (!ppu) return -ENOMEM; ppu->num_domains = data->nr_domains; - ppu->domains = devm_kcalloc(dev, data->nr_domains, - sizeof(*ppu->domains), GFP_KERNEL); + ppu->domains = devm_kzalloc_objs(dev, *ppu->domains, data->nr_domains); if (!ppu->domains) return -ENOMEM; diff --git a/drivers/pmdomain/sunxi/sun55i-pck600.c b/drivers/pmdomain/sunxi/sun55i-pck600.c index 8a37d11b65a247..81c3b18a38a4f1 100644 --- a/drivers/pmdomain/sunxi/sun55i-pck600.c +++ b/drivers/pmdomain/sunxi/sun55i-pck600.c @@ -139,7 +139,7 @@ static int sunxi_pck600_probe(struct platform_device *pdev) desc = of_device_get_match_data(dev); - pck = devm_kzalloc(dev, struct_size(pck, pds, desc->num_domains), GFP_KERNEL); + pck = devm_kzalloc_flex(dev, *pck, pds, desc->num_domains); if (!pck) return -ENOMEM; @@ -148,8 +148,8 @@ static int sunxi_pck600_probe(struct platform_device *pdev) genpds = &pck->genpd_data; genpds->num_domains = desc->num_domains; - genpds->domains = devm_kcalloc(dev, desc->num_domains, - sizeof(*genpds->domains), GFP_KERNEL); + genpds->domains = devm_kzalloc_objs(dev, *genpds->domains, + desc->num_domains); if (!genpds->domains) return -ENOMEM; diff --git a/drivers/pmdomain/tegra/powergate-bpmp.c b/drivers/pmdomain/tegra/powergate-bpmp.c index e6a7e025b01227..92237161465a90 100644 --- a/drivers/pmdomain/tegra/powergate-bpmp.c +++ b/drivers/pmdomain/tegra/powergate-bpmp.c @@ -181,7 +181,7 @@ tegra_powergate_add(struct tegra_bpmp *bpmp, off = !tegra_bpmp_powergate_is_powered(bpmp, info->id); - powergate = devm_kzalloc(bpmp->dev, sizeof(*powergate), GFP_KERNEL); + powergate = devm_kzalloc_obj(bpmp->dev, *powergate); if (!powergate) return ERR_PTR(-ENOMEM); diff --git a/drivers/pmdomain/thead/th1520-pm-domains.c b/drivers/pmdomain/thead/th1520-pm-domains.c index d7cb9633c7c8a3..3d1a959f59f3bf 100644 --- a/drivers/pmdomain/thead/th1520-pm-domains.c +++ b/drivers/pmdomain/thead/th1520-pm-domains.c @@ -91,7 +91,7 @@ th1520_add_pm_domain(struct device *dev, const struct th1520_power_info *pi) struct th1520_power_domain *pd; int ret; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return ERR_PTR(-ENOMEM); @@ -152,7 +152,7 @@ static int th1520_pd_pwrseq_gpu_init(struct device *dev) */ return 0; - adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); + adev = devm_kzalloc_obj(dev, *adev); if (!adev) return -ENOMEM; @@ -198,14 +198,13 @@ static int th1520_pd_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(aon_chan), "Failed to get AON channel\n"); - domains = devm_kcalloc(dev, ARRAY_SIZE(th1520_pd_ranges), - sizeof(*domains), GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, ARRAY_SIZE(th1520_pd_ranges)); if (!domains) { ret = -ENOMEM; goto err_clean_aon; } - pd_data = devm_kzalloc(dev, sizeof(*pd_data), GFP_KERNEL); + pd_data = devm_kzalloc_obj(dev, *pd_data); if (!pd_data) { ret = -ENOMEM; goto err_clean_aon; diff --git a/drivers/pmdomain/ti/omap_prm.c b/drivers/pmdomain/ti/omap_prm.c index 64a187f79a1a70..671b028e367eb9 100644 --- a/drivers/pmdomain/ti/omap_prm.c +++ b/drivers/pmdomain/ti/omap_prm.c @@ -693,7 +693,7 @@ static int omap_prm_domain_init(struct device *dev, struct omap_prm *prm) of_node_put(dev->of_node); - prmd = devm_kzalloc(dev, sizeof(*prmd), GFP_KERNEL); + prmd = devm_kzalloc_obj(dev, *prmd); if (!prmd) return -ENOMEM; @@ -900,7 +900,7 @@ static int omap_prm_reset_init(struct platform_device *pdev, if (!map) return -EINVAL; - reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(&pdev->dev, *reset); if (!reset) return -ENOMEM; @@ -953,7 +953,7 @@ static int omap_prm_probe(struct platform_device *pdev) if (!data) return -ENOTSUPP; - prm = devm_kzalloc(&pdev->dev, sizeof(*prm), GFP_KERNEL); + prm = devm_kzalloc_obj(&pdev->dev, *prm); if (!prm) return -ENOMEM; diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c index 949e4115f930b9..50898dc43310cf 100644 --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c @@ -228,7 +228,7 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) u32 max_id = 0; int index; - pd_provider = devm_kzalloc(dev, sizeof(*pd_provider), GFP_KERNEL); + pd_provider = devm_kzalloc_obj(dev, *pd_provider); if (!pd_provider) return -ENOMEM; @@ -261,7 +261,7 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) } } - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return -ENOMEM; @@ -299,9 +299,7 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) } pd_provider->data.domains = - devm_kcalloc(dev, max_id + 1, - sizeof(*pd_provider->data.domains), - GFP_KERNEL); + devm_kzalloc_objs(dev, *pd_provider->data.domains, max_id + 1); if (!pd_provider->data.domains) return -ENOMEM; diff --git a/drivers/pmdomain/xilinx/zynqmp-pm-domains.c b/drivers/pmdomain/xilinx/zynqmp-pm-domains.c index b5aedd6e33ad0e..892c0709334094 100644 --- a/drivers/pmdomain/xilinx/zynqmp-pm-domains.c +++ b/drivers/pmdomain/xilinx/zynqmp-pm-domains.c @@ -247,18 +247,17 @@ static int zynqmp_gpd_probe(struct platform_device *pdev) struct zynqmp_pm_domain *pd; struct device *dev = &pdev->dev; - pd = devm_kcalloc(dev, ZYNQMP_NUM_DOMAINS, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_objs(dev, *pd, ZYNQMP_NUM_DOMAINS); if (!pd) return -ENOMEM; - zynqmp_pd_data = devm_kzalloc(dev, sizeof(*zynqmp_pd_data), GFP_KERNEL); + zynqmp_pd_data = devm_kzalloc_obj(dev, *zynqmp_pd_data); if (!zynqmp_pd_data) return -ENOMEM; zynqmp_pd_data->xlate = zynqmp_gpd_xlate; - domains = devm_kcalloc(dev, ZYNQMP_NUM_DOMAINS, sizeof(*domains), - GFP_KERNEL); + domains = devm_kzalloc_objs(dev, *domains, ZYNQMP_NUM_DOMAINS); if (!domains) return -ENOMEM; diff --git a/drivers/power/reset/as3722-poweroff.c b/drivers/power/reset/as3722-poweroff.c index 8075382cbc3625..fb00553796ebf4 100644 --- a/drivers/power/reset/as3722-poweroff.c +++ b/drivers/power/reset/as3722-poweroff.c @@ -44,8 +44,7 @@ static int as3722_poweroff_probe(struct platform_device *pdev) if (!of_property_read_bool(np, "ams,system-power-controller")) return 0; - as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff), - GFP_KERNEL); + as3722_poweroff = devm_kzalloc_obj(&pdev->dev, *as3722_poweroff); if (!as3722_poweroff) return -ENOMEM; diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c index 511f5a8f8961ce..a9ad43217f4885 100644 --- a/drivers/power/reset/at91-reset.c +++ b/drivers/power/reset/at91-reset.c @@ -343,7 +343,7 @@ static int at91_reset_probe(struct platform_device *pdev) struct device_node *np; int ret, idx = 0; - reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(&pdev->dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c index ecf15694f9255e..589599cca0765c 100644 --- a/drivers/power/reset/at91-sama5d2_shdwc.c +++ b/drivers/power/reset/at91-sama5d2_shdwc.c @@ -344,7 +344,7 @@ static int at91_shdwc_probe(struct platform_device *pdev) if (at91_shdwc) return -EBUSY; - at91_shdwc = devm_kzalloc(&pdev->dev, sizeof(*at91_shdwc), GFP_KERNEL); + at91_shdwc = devm_kzalloc_obj(&pdev->dev, *at91_shdwc); if (!at91_shdwc) return -ENOMEM; diff --git a/drivers/power/reset/atc260x-poweroff.c b/drivers/power/reset/atc260x-poweroff.c index e3e4621ccb1dd2..ecd0ffadc489cd 100644 --- a/drivers/power/reset/atc260x-poweroff.c +++ b/drivers/power/reset/atc260x-poweroff.c @@ -186,7 +186,7 @@ static int atc260x_pwrc_probe(struct platform_device *pdev) struct atc260x_pwrc *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/reset/ep93xx-restart.c b/drivers/power/reset/ep93xx-restart.c index 119394bb030581..46415a3071e7b1 100644 --- a/drivers/power/reset/ep93xx-restart.c +++ b/drivers/power/reset/ep93xx-restart.c @@ -52,7 +52,7 @@ static int ep93xx_reboot_probe(struct auxiliary_device *adev, if (!rdev->update_bits) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/reset/gemini-poweroff.c b/drivers/power/reset/gemini-poweroff.c index 06d6992dec892b..c0099e0ab740ab 100644 --- a/drivers/power/reset/gemini-poweroff.c +++ b/drivers/power/reset/gemini-poweroff.c @@ -95,7 +95,7 @@ static int gemini_poweroff_probe(struct platform_device *pdev) int irq; int ret; - gpw = devm_kzalloc(dev, sizeof(*gpw), GFP_KERNEL); + gpw = devm_kzalloc_obj(dev, *gpw); if (!gpw) return -ENOMEM; diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c index 1cd5900be03872..08fb7b8488c4c0 100644 --- a/drivers/power/reset/gpio-poweroff.c +++ b/drivers/power/reset/gpio-poweroff.c @@ -62,7 +62,7 @@ static int gpio_poweroff_probe(struct platform_device *pdev) int priority = SYS_OFF_PRIO_DEFAULT; int ret; - gpio_poweroff = devm_kzalloc(&pdev->dev, sizeof(*gpio_poweroff), GFP_KERNEL); + gpio_poweroff = devm_kzalloc_obj(&pdev->dev, *gpio_poweroff); if (!gpio_poweroff) return -ENOMEM; diff --git a/drivers/power/reset/gpio-restart.c b/drivers/power/reset/gpio-restart.c index d1e177176fa1f1..a08871eebeb764 100644 --- a/drivers/power/reset/gpio-restart.c +++ b/drivers/power/reset/gpio-restart.c @@ -53,8 +53,7 @@ static int gpio_restart_probe(struct platform_device *pdev) u32 property; int ret; - gpio_restart = devm_kzalloc(&pdev->dev, sizeof(*gpio_restart), - GFP_KERNEL); + gpio_restart = devm_kzalloc_obj(&pdev->dev, *gpio_restart); if (!gpio_restart) return -ENOMEM; diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c index c3a0435938c86f..50093cf6270d1e 100644 --- a/drivers/power/reset/ltc2952-poweroff.c +++ b/drivers/power/reset/ltc2952-poweroff.c @@ -262,7 +262,7 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev) return -EBUSY; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c index 7b8460a55e9dae..131ca75a97cb64 100644 --- a/drivers/power/reset/macsmc-reboot.c +++ b/drivers/power/reset/macsmc-reboot.c @@ -204,7 +204,7 @@ static int macsmc_reboot_probe(struct platform_device *pdev) struct macsmc_reboot *reboot; int ret, i; - reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL); + reboot = devm_kzalloc_obj(&pdev->dev, *reboot); if (!reboot) return -ENOMEM; diff --git a/drivers/power/reset/mcf-rcm-reset.c b/drivers/power/reset/mcf-rcm-reset.c index 18f11c05a86816..fd441cfa24b6c9 100644 --- a/drivers/power/reset/mcf-rcm-reset.c +++ b/drivers/power/reset/mcf-rcm-reset.c @@ -83,7 +83,7 @@ static int mcf_rcm_probe(struct platform_device *pdev) void __iomem *base; u8 rsr; - rcm = devm_kzalloc(&pdev->dev, sizeof(*rcm), GFP_KERNEL); + rcm = devm_kzalloc_obj(&pdev->dev, *rcm); if (!rcm) return -ENOMEM; diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c index c663347547f978..77653b204dc8e0 100644 --- a/drivers/power/reset/mt6323-poweroff.c +++ b/drivers/power/reset/mt6323-poweroff.c @@ -54,7 +54,7 @@ static int mt6323_pwrc_probe(struct platform_device *pdev) struct resource *res; int ret; - pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + pwrc = devm_kzalloc_obj(&pdev->dev, *pwrc); if (!pwrc) return -ENOMEM; diff --git a/drivers/power/reset/nvmem-reboot-mode.c b/drivers/power/reset/nvmem-reboot-mode.c index d260715fccf67f..19d12a59383fd7 100644 --- a/drivers/power/reset/nvmem-reboot-mode.c +++ b/drivers/power/reset/nvmem-reboot-mode.c @@ -47,7 +47,7 @@ static int nvmem_reboot_mode_probe(struct platform_device *pdev) int ret; struct nvmem_reboot_mode *nvmem_rbm; - nvmem_rbm = devm_kzalloc(&pdev->dev, sizeof(*nvmem_rbm), GFP_KERNEL); + nvmem_rbm = devm_kzalloc_obj(&pdev->dev, *nvmem_rbm); if (!nvmem_rbm) return -ENOMEM; diff --git a/drivers/power/reset/ocelot-reset.c b/drivers/power/reset/ocelot-reset.c index 9d4b8afb6cbb1c..0acfa63b6b5d86 100644 --- a/drivers/power/reset/ocelot-reset.c +++ b/drivers/power/reset/ocelot-reset.c @@ -71,7 +71,7 @@ static int ocelot_reset_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int err; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/power/reset/odroid-go-ultra-poweroff.c b/drivers/power/reset/odroid-go-ultra-poweroff.c index 9cac7aef77f0f0..5e72e8319b5513 100644 --- a/drivers/power/reset/odroid-go-ultra-poweroff.c +++ b/drivers/power/reset/odroid-go-ultra-poweroff.c @@ -97,7 +97,7 @@ static int odroid_go_ultra_poweroff_probe(struct platform_device *pdev) struct odroid_go_ultra_poweroff_data *poweroff_data; int ret; - poweroff_data = devm_kzalloc(&pdev->dev, sizeof(*poweroff_data), GFP_KERNEL); + poweroff_data = devm_kzalloc_obj(&pdev->dev, *poweroff_data); if (!poweroff_data) return -ENOMEM; diff --git a/drivers/power/reset/pwr-mlxbf.c b/drivers/power/reset/pwr-mlxbf.c index 459c2b7f3a2139..ea810055b45ba1 100644 --- a/drivers/power/reset/pwr-mlxbf.c +++ b/drivers/power/reset/pwr-mlxbf.c @@ -48,7 +48,7 @@ static int pwr_mlxbf_probe(struct platform_device *pdev) const char *hid; int irq, err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c index cd7ba680b84135..112d1bcefedf52 100644 --- a/drivers/power/reset/qcom-pon.c +++ b/drivers/power/reset/qcom-pon.c @@ -59,7 +59,7 @@ static int qcom_pon_probe(struct platform_device *pdev) long reason_shift; int error; - pon = devm_kzalloc(&pdev->dev, sizeof(*pon), GFP_KERNEL); + pon = devm_kzalloc_obj(&pdev->dev, *pon); if (!pon) return -ENOMEM; diff --git a/drivers/power/reset/qemu-virt-ctrl.c b/drivers/power/reset/qemu-virt-ctrl.c index 97875007fda325..e0939582fd620a 100644 --- a/drivers/power/reset/qemu-virt-ctrl.c +++ b/drivers/power/reset/qemu-virt-ctrl.c @@ -67,7 +67,7 @@ static int qemu_virt_ctrl_probe(struct platform_device *pdev) struct qemu_virt_ctrl *ctrl; int ret; - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(&pdev->dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/power/reset/syscon-poweroff.c b/drivers/power/reset/syscon-poweroff.c index 203936f4c544f1..e085246f44dd69 100644 --- a/drivers/power/reset/syscon-poweroff.c +++ b/drivers/power/reset/syscon-poweroff.c @@ -43,7 +43,7 @@ static int syscon_poweroff_probe(struct platform_device *pdev) struct syscon_poweroff_data *data; int mask_err, value_err; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/reset/syscon-reboot-mode.c b/drivers/power/reset/syscon-reboot-mode.c index e0772c9f70f7a1..946b6774d5e58c 100644 --- a/drivers/power/reset/syscon-reboot-mode.c +++ b/drivers/power/reset/syscon-reboot-mode.c @@ -41,7 +41,7 @@ static int syscon_reboot_mode_probe(struct platform_device *pdev) int ret; struct syscon_reboot_mode *syscon_rbm; - syscon_rbm = devm_kzalloc(&pdev->dev, sizeof(*syscon_rbm), GFP_KERNEL); + syscon_rbm = devm_kzalloc_obj(&pdev->dev, *syscon_rbm); if (!syscon_rbm) return -ENOMEM; diff --git a/drivers/power/reset/syscon-reboot.c b/drivers/power/reset/syscon-reboot.c index 60e855cae68eed..3b0a20a2729f88 100644 --- a/drivers/power/reset/syscon-reboot.c +++ b/drivers/power/reset/syscon-reboot.c @@ -70,7 +70,7 @@ static int syscon_reboot_probe(struct platform_device *pdev) u32 priority; int err; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/power/reset/xgene-reboot.c b/drivers/power/reset/xgene-reboot.c index b5eee19bac4261..f02086e84e2a27 100644 --- a/drivers/power/reset/xgene-reboot.c +++ b/drivers/power/reset/xgene-reboot.c @@ -46,7 +46,7 @@ static int xgene_reboot_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int err; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/power/sequencing/core.c b/drivers/power/sequencing/core.c index d7a545bb4ed2e2..a40021526c8d24 100644 --- a/drivers/power/sequencing/core.c +++ b/drivers/power/sequencing/core.c @@ -270,6 +270,11 @@ static void pwrseq_device_put(struct pwrseq_device *pwrseq) * @target: Reference to the target this descriptor allows to control. * @powered_on: Power state set by the holder of the descriptor (not necessarily * corresponding to the actual power state of the device). + * + * Note: The user that requested the descriptor from the provider is + * responsible for the serialization of access to it. Concurrent threads must + * not access the descriptor structure without synchronization as power + * sequencing core does not provide any per-descriptor locking. */ struct pwrseq_desc { struct pwrseq_device *pwrseq; diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c index 56c5d51293c10f..cdadb6617762a9 100644 --- a/drivers/power/sequencing/pwrseq-pcie-m2.c +++ b/drivers/power/sequencing/pwrseq-pcie-m2.c @@ -296,7 +296,7 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx, struct serdev_controller *serdev_ctrl; struct device *dev = ctx->dev; struct pwrseq_pci_dev *pci_dev; - int ret; + int ret = 0; struct device_node *serdev_parent __free(device_node) = of_graph_get_remote_node(dev_of_node(ctx->dev), 3, 0); @@ -308,16 +308,14 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx, return 0; /* Bail out if the device was already attached to this controller */ - if (serdev_ctrl->serdev) { - serdev_controller_put(serdev_ctrl); - return 0; - } + if (serdev_ctrl->serdev) + goto err_put_ctrl; /* Bail out if the serdev device was already created for the PCI dev */ scoped_guard(mutex, &ctx->list_lock) { list_for_each_entry(pci_dev, &ctx->pci_devices, list) { if (pci_dev->pdev == pdev) - return 0; + goto err_put_ctrl; } } @@ -533,6 +531,14 @@ static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx) return ret; } +static void pwrseq_pcie_m2_free_regulators(void *data) +{ + struct pwrseq_pcie_m2_ctx *ctx = data; + + regulator_bulk_free(ctx->num_vregs, ctx->regs); + kfree(ctx->regs); +} + static int pwrseq_pcie_m2_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -540,7 +546,7 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev) struct pwrseq_config config = {}; int ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -563,19 +569,19 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev) ctx->num_vregs = ret; + ret = devm_add_action_or_reset(dev, pwrseq_pcie_m2_free_regulators, ctx); + if (ret) + return ret; + ctx->w_disable1_gpio = devm_gpiod_get_optional(dev, "w-disable1", GPIOD_OUT_HIGH); - if (IS_ERR(ctx->w_disable1_gpio)) { - ret = dev_err_probe(dev, PTR_ERR(ctx->w_disable1_gpio), + if (IS_ERR(ctx->w_disable1_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->w_disable1_gpio), "Failed to get the W_DISABLE_1# GPIO\n"); - goto err_free_regulators; - } ctx->w_disable2_gpio = devm_gpiod_get_optional(dev, "w-disable2", GPIOD_OUT_HIGH); - if (IS_ERR(ctx->w_disable2_gpio)) { - ret = dev_err_probe(dev, PTR_ERR(ctx->w_disable2_gpio), + if (IS_ERR(ctx->w_disable2_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->w_disable2_gpio), "Failed to get the W_DISABLE_2# GPIO\n"); - goto err_free_regulators; - } config.parent = dev; config.owner = THIS_MODULE; @@ -584,20 +590,21 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev) config.targets = ctx->pdata->targets; ctx->pwrseq = devm_pwrseq_device_register(dev, &config); - if (IS_ERR(ctx->pwrseq)) { - ret = dev_err_probe(dev, PTR_ERR(ctx->pwrseq), + if (IS_ERR(ctx->pwrseq)) + return dev_err_probe(dev, PTR_ERR(ctx->pwrseq), "Failed to register the power sequencer\n"); - goto err_free_regulators; - } - mutex_init(&ctx->list_lock); + ret = devm_mutex_init(dev, &ctx->list_lock); + if (ret) + return ret; + INIT_LIST_HEAD(&ctx->pci_devices); ctx->dev = dev; /* Create serdev for available PCI devices (if required) */ ret = pwrseq_pcie_m2_create_serdev(ctx); if (ret) - goto err_destroy_mutex; + return ret; /* * Register a notifier for creating protocol devices for @@ -605,17 +612,7 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev) */ ret = pwrseq_pcie_m2_register_notifier(ctx); if (ret) - goto err_remove_serdev; - - return 0; - -err_remove_serdev: - pwrseq_pcie_m2_remove_serdev(ctx, NULL); -err_destroy_mutex: - mutex_destroy(&ctx->list_lock); -err_free_regulators: - regulator_bulk_free(ctx->num_vregs, ctx->regs); - kfree(ctx->regs); + pwrseq_pcie_m2_remove_serdev(ctx, NULL); return ret; } @@ -626,10 +623,6 @@ static void pwrseq_pcie_m2_remove(struct platform_device *pdev) bus_unregister_notifier(&pci_bus_type, &ctx->nb); pwrseq_pcie_m2_remove_serdev(ctx, NULL); - mutex_destroy(&ctx->list_lock); - - regulator_bulk_free(ctx->num_vregs, ctx->regs); - kfree(ctx->regs); } static const struct of_device_id pwrseq_pcie_m2_of_match[] = { diff --git a/drivers/power/sequencing/pwrseq-qcom-wcn.c b/drivers/power/sequencing/pwrseq-qcom-wcn.c index 636dd7e6389172..e51b655add01c3 100644 --- a/drivers/power/sequencing/pwrseq-qcom-wcn.c +++ b/drivers/power/sequencing/pwrseq-qcom-wcn.c @@ -427,7 +427,7 @@ static const char *const pwrseq_wcn7850_vregs[] = { static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn7850_of_data = { .vregs = pwrseq_wcn7850_vregs, .num_vregs = ARRAY_SIZE(pwrseq_wcn7850_vregs), - .pwup_delay_ms = 50, + .pwup_delay_ms = 100, .targets = pwrseq_qcom_wcn_targets, }; @@ -491,7 +491,7 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev) struct pwrseq_config config; int i, ret; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; @@ -502,8 +502,7 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev) return dev_err_probe(dev, -ENODEV, "Failed to obtain platform data\n"); - ctx->regs = devm_kcalloc(dev, ctx->pdata->num_vregs, - sizeof(*ctx->regs), GFP_KERNEL); + ctx->regs = devm_kzalloc_objs(dev, *ctx->regs, ctx->pdata->num_vregs); if (!ctx->regs) return -ENOMEM; diff --git a/drivers/power/sequencing/pwrseq-thead-gpu.c b/drivers/power/sequencing/pwrseq-thead-gpu.c index a45318b4b2c122..24cdfd5d726a1c 100644 --- a/drivers/power/sequencing/pwrseq-thead-gpu.c +++ b/drivers/power/sequencing/pwrseq-thead-gpu.c @@ -183,7 +183,7 @@ static int pwrseq_thead_gpu_probe(struct auxiliary_device *adev, struct pwrseq_thead_gpu_ctx *ctx; struct pwrseq_config config = {}; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/power/supply/88pm860x_battery.c b/drivers/power/supply/88pm860x_battery.c index 8d93c7a6a5f055..daf14a2087985c 100644 --- a/drivers/power/supply/88pm860x_battery.c +++ b/drivers/power/supply/88pm860x_battery.c @@ -916,7 +916,7 @@ static int pm860x_battery_probe(struct platform_device *pdev) struct pm860x_power_pdata *pdata; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/88pm860x_charger.c b/drivers/power/supply/88pm860x_charger.c index 47f95f31e4723d..7317d7d94d653f 100644 --- a/drivers/power/supply/88pm860x_charger.c +++ b/drivers/power/supply/88pm860x_charger.c @@ -670,7 +670,7 @@ static int pm860x_charger_probe(struct platform_device *pdev) int i; int j; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c index d8845fd2f0843d..ea9dec3135fc68 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -692,7 +692,7 @@ static int ab8500_btemp_probe(struct platform_device *pdev) int irq, i, ret = 0; u8 val; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c index 71d82c6c193e5e..fba6ba90eecd2e 100644 --- a/drivers/power/supply/ab8500_chargalg.c +++ b/drivers/power/supply/ab8500_chargalg.c @@ -1772,7 +1772,7 @@ static int ab8500_chargalg_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct ab8500_chargalg *di; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index 19cc56624ee4b4..7dbb647392e599 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -3697,7 +3697,7 @@ static int ab8500_charger_probe(struct platform_device *pdev) int i, irq; int ret; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 069e7fee1d1674..eddd3e85310653 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -3012,7 +3012,7 @@ static int ab8500_fg_probe(struct platform_device *pdev) int i, irq; int ret = 0; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/acer_a500_battery.c b/drivers/power/supply/acer_a500_battery.c index daf01dc8025bb3..2f2b3b7a66fc8c 100644 --- a/drivers/power/supply/acer_a500_battery.c +++ b/drivers/power/supply/acer_a500_battery.c @@ -226,7 +226,7 @@ static int a500_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct a500_battery *bat; - bat = devm_kzalloc(&pdev->dev, sizeof(*bat), GFP_KERNEL); + bat = devm_kzalloc_obj(&pdev->dev, *bat); if (!bat) return -ENOMEM; diff --git a/drivers/power/supply/act8945a_charger.c b/drivers/power/supply/act8945a_charger.c index 7e4b087f76791c..3ea43ec7f8a8b2 100644 --- a/drivers/power/supply/act8945a_charger.c +++ b/drivers/power/supply/act8945a_charger.c @@ -577,7 +577,7 @@ static int act8945a_charger_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int irq, ret; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c index 7478986e6b3cbf..06c6207912989e 100644 --- a/drivers/power/supply/adp5061.c +++ b/drivers/power/supply/adp5061.c @@ -698,7 +698,7 @@ static int adp5061_probe(struct i2c_client *client) struct power_supply_config psy_cfg = {}; struct adp5061_state *st; - st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(&client->dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index 46889567bc18ba..0c101df8cb79b1 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -333,9 +333,8 @@ static int axp20x_ac_power_probe(struct platform_device *pdev) axp_data = of_device_get_match_data(&pdev->dev); - power = devm_kzalloc(&pdev->dev, - struct_size(power, irqs, axp_data->num_irq_names), - GFP_KERNEL); + power = devm_kzalloc_flex(&pdev->dev, *power, irqs, + axp_data->num_irq_names); if (!power) return -ENOMEM; diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index c119014b319a63..4af1a209c9cf3a 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -1097,8 +1097,7 @@ static int axp20x_power_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - axp20x_batt = devm_kzalloc(&pdev->dev, sizeof(*axp20x_batt), - GFP_KERNEL); + axp20x_batt = devm_kzalloc_obj(&pdev->dev, *axp20x_batt); if (!axp20x_batt) return -ENOMEM; diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 7625366104bc86..53e3e05c2c8cad 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -930,8 +930,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) axp_data = of_device_get_match_data(dev); - power = devm_kzalloc(dev, struct_size(power, irqs, axp_data->num_irq_names), - GFP_KERNEL); + power = devm_kzalloc_flex(dev, *power, irqs, axp_data->num_irq_names); if (!power) return -ENOMEM; diff --git a/drivers/power/supply/axp288_charger.c b/drivers/power/supply/axp288_charger.c index 8f209035601797..cca676d614fd7e 100644 --- a/drivers/power/supply/axp288_charger.c +++ b/drivers/power/supply/axp288_charger.c @@ -849,7 +849,7 @@ static int axp288_charger_probe(struct platform_device *pdev) if (val == 0) return -ENODEV; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/axp288_fuel_gauge.c b/drivers/power/supply/axp288_fuel_gauge.c index 68dabaf7a4f8fd..fcb0b4a364c181 100644 --- a/drivers/power/supply/axp288_fuel_gauge.c +++ b/drivers/power/supply/axp288_fuel_gauge.c @@ -719,7 +719,7 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) if (quirks & AXP288_QUIRK_NO_BATTERY) return -ENODEV; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/bd71828-power.c b/drivers/power/supply/bd71828-power.c index 3be7a75a7d6ca3..cb8e3f5a74ad3c 100644 --- a/drivers/power/supply/bd71828-power.c +++ b/drivers/power/supply/bd71828-power.c @@ -1174,7 +1174,7 @@ static int bd71828_power_probe(struct platform_device *pdev) struct power_supply_config bat_cfg = {}; int ret; - pwr = devm_kzalloc(&pdev->dev, sizeof(*pwr), GFP_KERNEL); + pwr = devm_kzalloc_obj(&pdev->dev, *pwr); if (!pwr) return -ENOMEM; diff --git a/drivers/power/supply/bd99954-charger.c b/drivers/power/supply/bd99954-charger.c index b3068c2197c793..d13b8e4316eba3 100644 --- a/drivers/power/supply/bd99954-charger.c +++ b/drivers/power/supply/bd99954-charger.c @@ -973,7 +973,7 @@ static int bd9995x_probe(struct i2c_client *client) int ret; int i; - bd = devm_kzalloc(dev, sizeof(*bd), GFP_KERNEL); + bd = devm_kzalloc_obj(dev, *bd); if (!bd) return -ENOMEM; diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c index 9f801717bfb03f..4fa923396b0e21 100644 --- a/drivers/power/supply/bq2415x_charger.c +++ b/drivers/power/supply/bq2415x_charger.c @@ -1584,7 +1584,7 @@ static int bq2415x_probe(struct i2c_client *client) goto error_1; } - bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc_obj(&client->dev, *bq); if (!bq) { ret = -ENOMEM; goto error_2; diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index 7a5867dd74c239..b6e2e3160740e0 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -2128,7 +2128,7 @@ static int bq24190_probe(struct i2c_client *client) return -ENODEV; } - bdi = devm_kzalloc(dev, sizeof(*bdi), GFP_KERNEL); + bdi = devm_kzalloc_obj(dev, *bdi); if (!bdi) { dev_err(dev, "Can't alloc bdi struct\n"); return -ENOMEM; diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c index 8eea7d0395ce02..5b176679beb7bb 100644 --- a/drivers/power/supply/bq24257_charger.c +++ b/drivers/power/supply/bq24257_charger.c @@ -995,7 +995,7 @@ static int bq24257_probe(struct i2c_client *client) return -ENODEV; } - bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc_obj(dev, *bq); if (!bq) return -ENOMEM; diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index 22c2b86c3b30ff..a4a12598294de9 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c @@ -328,7 +328,7 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) u32 val; int ret; - pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&client->dev, *pdata); if (!pdata) { dev_err(&client->dev, "Memory alloc for bq24735 pdata failed\n"); @@ -360,7 +360,7 @@ static int bq24735_charger_probe(struct i2c_client *client) struct power_supply_config psy_cfg = {}; char *name; - charger = devm_kzalloc(&client->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&client->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/bq2515x_charger.c b/drivers/power/supply/bq2515x_charger.c index c2b17562cf8bb0..08db58e91e08f1 100644 --- a/drivers/power/supply/bq2515x_charger.c +++ b/drivers/power/supply/bq2515x_charger.c @@ -1086,7 +1086,7 @@ static int bq2515x_probe(struct i2c_client *client) struct power_supply_config charger_cfg = {}; int ret; - bq2515x = devm_kzalloc(dev, sizeof(*bq2515x), GFP_KERNEL); + bq2515x = devm_kzalloc_obj(dev, *bq2515x); if (!bq2515x) return -ENOMEM; diff --git a/drivers/power/supply/bq25630_charger.c b/drivers/power/supply/bq25630_charger.c index bf54ff557a40f1..7155608c9ddcc9 100644 --- a/drivers/power/supply/bq25630_charger.c +++ b/drivers/power/supply/bq25630_charger.c @@ -1070,7 +1070,7 @@ static int bq25630_probe(struct i2c_client *client) struct bq25630_data *data; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c index 454bc497b0d816..b5dd5ce9f3fabc 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -1765,7 +1765,7 @@ static int bq256xx_probe(struct i2c_client *client) int ret; - bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc_obj(dev, *bq); if (!bq) return -ENOMEM; diff --git a/drivers/power/supply/bq257xx_charger.c b/drivers/power/supply/bq257xx_charger.c index 569608bc0d6a94..36e675237f974f 100644 --- a/drivers/power/supply/bq257xx_charger.c +++ b/drivers/power/supply/bq257xx_charger.c @@ -1230,7 +1230,7 @@ static int bq257xx_charger_probe(struct platform_device *pdev) device_set_of_node_from_dev(dev, pdev->dev.parent); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index f7510ada6b7342..6af1811909e4e5 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1465,7 +1465,7 @@ static int bq25890_probe(struct i2c_client *client) struct bq25890_device *bq; int ret; - bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc_obj(dev, *bq); if (!bq) return -ENOMEM; diff --git a/drivers/power/supply/bq25980_charger.c b/drivers/power/supply/bq25980_charger.c index eced3aecc7d267..57e9ffa3c78683 100644 --- a/drivers/power/supply/bq25980_charger.c +++ b/drivers/power/supply/bq25980_charger.c @@ -1213,7 +1213,7 @@ static int bq25980_probe(struct i2c_client *client) struct bq25980_device *bq; int ret; - bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc_obj(dev, *bq); if (!bq) return -ENOMEM; diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 09272249b4f77b..b6110940f8a7ab 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -2256,7 +2256,7 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) di->dm_regs = bq27xxx_chip_data[di->chip].dm_regs; di->opts = bq27xxx_chip_data[di->chip].opts; - psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL); + psy_desc = devm_kzalloc_obj(di->dev, *psy_desc); if (!psy_desc) return -ENOMEM; diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c index 922759ab2e0454..058371bafe9d83 100644 --- a/drivers/power/supply/bq27xxx_battery_hdq.c +++ b/drivers/power/supply/bq27xxx_battery_hdq.c @@ -76,7 +76,7 @@ static int bq27xxx_battery_hdq_add_slave(struct w1_slave *sl) { struct bq27xxx_device_info *di; - di = devm_kzalloc(&sl->dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(&sl->dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 715ce8b6e40161..bd1d5d046a175d 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -175,7 +175,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) if (!name) return -ENOMEM; - di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(&client->dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/chagall-battery.c b/drivers/power/supply/chagall-battery.c index 129566d0bd9d40..23836ae9610892 100644 --- a/drivers/power/supply/chagall-battery.c +++ b/drivers/power/supply/chagall-battery.c @@ -195,7 +195,7 @@ static int chagall_battery_probe(struct i2c_client *client) struct power_supply_config cfg = { }; int ret; - cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL); + cg = devm_kzalloc_obj(dev, *cg); if (!cg) return -ENOMEM; diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 8e8c5109401a4b..b688623a20d027 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -1299,7 +1299,7 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) u32 battery_stat = CM_NO_BATTERY; int num_chgs = 0; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return ERR_PTR(-ENOMEM); @@ -1360,19 +1360,15 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) struct charger_regulator *chg_regs; struct device_node *child; - chg_regs = devm_kcalloc(dev, - desc->num_charger_regulators, - sizeof(*chg_regs), - GFP_KERNEL); + chg_regs = devm_kzalloc_objs(dev, *chg_regs, + desc->num_charger_regulators); if (!chg_regs) return ERR_PTR(-ENOMEM); desc->charger_regulators = chg_regs; - desc->sysfs_groups = devm_kcalloc(dev, - desc->num_charger_regulators + 1, - sizeof(*desc->sysfs_groups), - GFP_KERNEL); + desc->sysfs_groups = devm_kzalloc_objs(dev, *desc->sysfs_groups, + desc->num_charger_regulators + 1); if (!desc->sysfs_groups) return ERR_PTR(-ENOMEM); @@ -1386,10 +1382,8 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) /* charger cables */ chg_regs->num_cables = of_get_child_count(child); if (chg_regs->num_cables) { - cables = devm_kcalloc(dev, - chg_regs->num_cables, - sizeof(*cables), - GFP_KERNEL); + cables = devm_kzalloc_objs(dev, *cables, + chg_regs->num_cables); if (!cables) { of_node_put(child); return ERR_PTR(-ENOMEM); @@ -1446,7 +1440,7 @@ static int charger_manager_probe(struct platform_device *pdev) return PTR_ERR(desc); } - cm = devm_kzalloc(&pdev->dev, sizeof(*cm), GFP_KERNEL); + cm = devm_kzalloc_obj(&pdev->dev, *cm); if (!cm) return -ENOMEM; @@ -1457,7 +1451,7 @@ static int charger_manager_probe(struct platform_device *pdev) /* Initialize alarm timer */ if (alarmtimer_get_rtcdev()) { - cm_timer = devm_kzalloc(cm->dev, sizeof(*cm_timer), GFP_KERNEL); + cm_timer = devm_kzalloc_obj(cm->dev, *cm_timer); if (!cm_timer) return -ENOMEM; alarm_init(cm_timer, ALARM_BOOTTIME, cm_timer_func); @@ -1536,10 +1530,8 @@ static int charger_manager_probe(struct platform_device *pdev) cm->charger_psy_desc.name = cm->psy_name_buf; /* Allocate for psy properties because they may vary */ - properties = devm_kcalloc(&pdev->dev, - ARRAY_SIZE(default_charger_props) + - NUM_CHARGER_PSY_OPTIONAL, - sizeof(*properties), GFP_KERNEL); + properties = devm_kzalloc_objs(&pdev->dev, *properties, + ARRAY_SIZE(default_charger_props) + NUM_CHARGER_PSY_OPTIONAL); if (!properties) return -ENOMEM; diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 808714c6ce95b7..da214b37aa5430 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -960,7 +960,7 @@ static int cpcap_battery_init_irq(struct platform_device *pdev, if (error) return error; - d = devm_kzalloc(ddata->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(ddata->dev, *d); if (!d) return -ENOMEM; @@ -1117,7 +1117,7 @@ static int cpcap_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int error; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c index d423a8bdc0c279..f7507c5751f4f5 100644 --- a/drivers/power/supply/cpcap-charger.c +++ b/drivers/power/supply/cpcap-charger.c @@ -764,7 +764,7 @@ static int cpcap_usb_init_irq(struct platform_device *pdev, if (error) return error; - d = devm_kzalloc(ddata->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(ddata->dev, *d); if (!d) return -ENOMEM; @@ -874,7 +874,7 @@ static int cpcap_charger_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int error; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c index e5841b40563ecf..5f2916c5bb57b7 100644 --- a/drivers/power/supply/cros_charge-control.c +++ b/drivers/power/supply/cros_charge-control.c @@ -397,7 +397,7 @@ static int cros_chctl_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c index b640930366d404..fdfa510f0f2de6 100644 --- a/drivers/power/supply/cros_peripheral_charger.c +++ b/drivers/power/supply/cros_peripheral_charger.c @@ -280,7 +280,7 @@ static int cros_pchg_probe(struct platform_device *pdev) int ret; int i; - charger = devm_kzalloc(dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(dev, *charger); if (!charger) return -ENOMEM; @@ -319,7 +319,7 @@ static int cros_pchg_probe(struct platform_device *pdev) for (i = 0; i < num_ports; i++) { struct power_supply_config psy_cfg = {}; - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 69d227ceb5c9ec..1adafcc155139b 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -546,8 +546,7 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) int ret = -EINVAL; int i; - charger = devm_kzalloc(dev, sizeof(struct charger_data), - GFP_KERNEL); + charger = devm_kzalloc_obj(dev, struct charger_data); if (!charger) return -ENOMEM; @@ -613,7 +612,7 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) for (i = 0; i < charger->num_charger_ports; i++) { struct power_supply_config psy_cfg = {}; - port = devm_kzalloc(dev, sizeof(struct port_data), GFP_KERNEL); + port = devm_kzalloc_obj(dev, struct port_data); if (!port) { ret = -ENOMEM; goto fail; diff --git a/drivers/power/supply/cw2015_battery.c b/drivers/power/supply/cw2015_battery.c index 1bcb60cf763d95..9fab56756dcffd 100644 --- a/drivers/power/supply/cw2015_battery.c +++ b/drivers/power/supply/cw2015_battery.c @@ -642,7 +642,7 @@ static int cw_bat_probe(struct i2c_client *client) struct cw_battery *cw_bat; struct power_supply_config psy_cfg = { 0 }; - cw_bat = devm_kzalloc(&client->dev, sizeof(*cw_bat), GFP_KERNEL); + cw_bat = devm_kzalloc_obj(&client->dev, *cw_bat); if (!cw_bat) return -ENOMEM; @@ -685,9 +685,8 @@ static int cw_bat_probe(struct i2c_client *client) ret = power_supply_get_battery_info(cw_bat->rk_bat, &cw_bat->battery); if (ret) { /* Allocate an empty battery */ - cw_bat->battery = devm_kzalloc(&client->dev, - sizeof(*cw_bat->battery), - GFP_KERNEL); + cw_bat->battery = devm_kzalloc_obj(&client->dev, + *cw_bat->battery); if (!cw_bat->battery) return -ENOMEM; dev_warn(cw_bat->dev, diff --git a/drivers/power/supply/da9030_battery.c b/drivers/power/supply/da9030_battery.c index 8c4daec0a6b67e..8d7d585f2d42aa 100644 --- a/drivers/power/supply/da9030_battery.c +++ b/drivers/power/supply/da9030_battery.c @@ -494,7 +494,7 @@ static int da9030_battery_probe(struct platform_device *pdev) pdata->charge_millivolt > 4350) return -EINVAL; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (charger == NULL) return -ENOMEM; diff --git a/drivers/power/supply/da9052-battery.c b/drivers/power/supply/da9052-battery.c index 6f17e2fa1a28ef..f49d9b0cf7fb74 100644 --- a/drivers/power/supply/da9052-battery.c +++ b/drivers/power/supply/da9052-battery.c @@ -590,8 +590,7 @@ static s32 da9052_bat_probe(struct platform_device *pdev) int ret; int i; - bat = devm_kzalloc(&pdev->dev, sizeof(struct da9052_battery), - GFP_KERNEL); + bat = devm_kzalloc_obj(&pdev->dev, struct da9052_battery); if (!bat) return -ENOMEM; diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c index 58449df6068c57..52c63c175db595 100644 --- a/drivers/power/supply/da9150-charger.c +++ b/drivers/power/supply/da9150-charger.c @@ -512,7 +512,7 @@ static int da9150_charger_probe(struct platform_device *pdev) u8 reg; int ret; - charger = devm_kzalloc(dev, sizeof(struct da9150_charger), GFP_KERNEL); + charger = devm_kzalloc_obj(dev, struct da9150_charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/da9150-fg.c b/drivers/power/supply/da9150-fg.c index 7b2fa723acd96d..1a0777302d8751 100644 --- a/drivers/power/supply/da9150-fg.c +++ b/drivers/power/supply/da9150-fg.c @@ -420,7 +420,7 @@ static struct da9150_fg_pdata *da9150_fg_dt_pdata(struct device *dev) struct device_node *fg_node = dev->of_node; struct da9150_fg_pdata *pdata; - pdata = devm_kzalloc(dev, sizeof(struct da9150_fg_pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct da9150_fg_pdata); if (!pdata) return NULL; @@ -450,7 +450,7 @@ static int da9150_fg_probe(struct platform_device *pdev) struct da9150_fg *fg; int ver, irq, ret = 0; - fg = devm_kzalloc(dev, sizeof(*fg), GFP_KERNEL); + fg = devm_kzalloc_obj(dev, *fg); if (fg == NULL) return -ENOMEM; diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c index 142c7492c3c22e..49184fce26ea93 100644 --- a/drivers/power/supply/ds2760_battery.c +++ b/drivers/power/supply/ds2760_battery.c @@ -630,7 +630,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) char name[32]; char status; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(dev, *di); if (!di) { retval = -ENOMEM; goto di_alloc_failed; diff --git a/drivers/power/supply/ds2780_battery.c b/drivers/power/supply/ds2780_battery.c index ef2446386c2af6..6472c06fe77d74 100644 --- a/drivers/power/supply/ds2780_battery.c +++ b/drivers/power/supply/ds2780_battery.c @@ -747,7 +747,7 @@ static int ds2780_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct ds2780_device_info *dev_info; - dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL); + dev_info = devm_kzalloc_obj(&pdev->dev, *dev_info); if (!dev_info) return -ENOMEM; diff --git a/drivers/power/supply/ds2781_battery.c b/drivers/power/supply/ds2781_battery.c index 1319e02f3f95e9..9eaf77e7ecebe7 100644 --- a/drivers/power/supply/ds2781_battery.c +++ b/drivers/power/supply/ds2781_battery.c @@ -751,7 +751,7 @@ static int ds2781_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct ds2781_device_info *dev_info; - dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL); + dev_info = devm_kzalloc_obj(&pdev->dev, *dev_info); if (!dev_info) return -ENOMEM; diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c index ed44837473e7a1..d4152d33558f72 100644 --- a/drivers/power/supply/ds2782_battery.c +++ b/drivers/power/supply/ds2782_battery.c @@ -385,7 +385,7 @@ static int ds278x_battery_probe(struct i2c_client *client) if (ret) return ret; - info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 7a1f8188bd27ce..bf92e2c05ad353 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -167,7 +167,7 @@ static int gab_probe(struct platform_device *pdev) int index = ARRAY_SIZE(gab_props); bool any = false; - adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL); + adc_bat = devm_kzalloc_obj(&pdev->dev, *adc_bat); if (!adc_bat) return -ENOMEM; @@ -186,11 +186,8 @@ static int gab_probe(struct platform_device *pdev) * copying the static properties and allocating extra memory for holding * the extra configurable properties received from platform data. */ - properties = devm_kcalloc(&pdev->dev, - ARRAY_SIZE(gab_props) + - ARRAY_SIZE(gab_chan_name), - sizeof(*properties), - GFP_KERNEL); + properties = devm_kzalloc_objs(&pdev->dev, *properties, + ARRAY_SIZE(gab_props) + ARRAY_SIZE(gab_chan_name)); if (!properties) return -ENOMEM; diff --git a/drivers/power/supply/goldfish_battery.c b/drivers/power/supply/goldfish_battery.c index 5aa24e4dc4455d..205dff78330726 100644 --- a/drivers/power/supply/goldfish_battery.c +++ b/drivers/power/supply/goldfish_battery.c @@ -202,7 +202,7 @@ static int goldfish_battery_probe(struct platform_device *pdev) struct goldfish_battery_data *data; struct power_supply_config psy_cfg = {}; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c index 1dad49acc42410..3b2fafb5694be8 100644 --- a/drivers/power/supply/gpio-charger.c +++ b/drivers/power/supply/gpio-charger.c @@ -222,8 +222,9 @@ static int init_charge_current_limit(struct device *dev, return -EINVAL; } - gpio_charger->current_limit_map = devm_kmalloc_array(dev, - len / 2, sizeof(*gpio_charger->current_limit_map), GFP_KERNEL); + gpio_charger->current_limit_map = devm_kmalloc_objs(dev, + *gpio_charger->current_limit_map, + len / 2); if (!gpio_charger->current_limit_map) return -ENOMEM; @@ -290,7 +291,7 @@ static int gpio_charger_probe(struct platform_device *pdev) return -ENOENT; } - gpio_charger = devm_kzalloc(dev, sizeof(*gpio_charger), GFP_KERNEL); + gpio_charger = devm_kzalloc_obj(dev, *gpio_charger); if (!gpio_charger) return -ENOMEM; gpio_charger->dev = dev; diff --git a/drivers/power/supply/huawei-gaokun-battery.c b/drivers/power/supply/huawei-gaokun-battery.c index e4dfec3b424100..c88eda5691e078 100644 --- a/drivers/power/supply/huawei-gaokun-battery.c +++ b/drivers/power/supply/huawei-gaokun-battery.c @@ -588,7 +588,7 @@ static int gaokun_psy_probe(struct auxiliary_device *adev, struct device *dev = &adev->dev; struct gaokun_psy *ecbat; - ecbat = devm_kzalloc(&adev->dev, sizeof(*ecbat), GFP_KERNEL); + ecbat = devm_kzalloc_obj(&adev->dev, *ecbat); if (!ecbat) return -ENOMEM; diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c index 5be269f17bffcd..3f7029614ffba0 100644 --- a/drivers/power/supply/ingenic-battery.c +++ b/drivers/power/supply/ingenic-battery.c @@ -130,7 +130,7 @@ static int ingenic_battery_probe(struct platform_device *pdev) struct power_supply_desc *desc; int ret; - bat = devm_kzalloc(dev, sizeof(*bat), GFP_KERNEL); + bat = devm_kzalloc_obj(dev, *bat); if (!bat) return -ENOMEM; diff --git a/drivers/power/supply/intel_dc_ti_battery.c b/drivers/power/supply/intel_dc_ti_battery.c index 5819df23a54351..5414e8ea41c6e9 100644 --- a/drivers/power/supply/intel_dc_ti_battery.c +++ b/drivers/power/supply/intel_dc_ti_battery.c @@ -340,7 +340,7 @@ static int dc_ti_battery_probe(struct platform_device *pdev) fwnode_handle_put(args.fwnode); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c index 24eea7a91b3022..9a0e612423fa35 100644 --- a/drivers/power/supply/ip5xxx_power.c +++ b/drivers/power/supply/ip5xxx_power.c @@ -834,7 +834,7 @@ static int ip5xxx_power_probe(struct i2c_client *client) struct power_supply *psy; struct ip5xxx *ip5xxx; - ip5xxx = devm_kzalloc(dev, sizeof(*ip5xxx), GFP_KERNEL); + ip5xxx = devm_kzalloc_obj(dev, *ip5xxx); if (!ip5xxx) return -ENOMEM; diff --git a/drivers/power/supply/ipaq_micro_battery.c b/drivers/power/supply/ipaq_micro_battery.c index 5e3fe3852d0ecf..f1d179b91aab8c 100644 --- a/drivers/power/supply/ipaq_micro_battery.c +++ b/drivers/power/supply/ipaq_micro_battery.c @@ -228,7 +228,7 @@ static int micro_batt_probe(struct platform_device *pdev) struct micro_battery *mb; int ret; - mb = devm_kzalloc(&pdev->dev, sizeof(*mb), GFP_KERNEL); + mb = devm_kzalloc_obj(&pdev->dev, *mb); if (!mb) return -ENOMEM; diff --git a/drivers/power/supply/isp1704_charger.c b/drivers/power/supply/isp1704_charger.c index e329321d06dbdd..d9596b24e6ad36 100644 --- a/drivers/power/supply/isp1704_charger.c +++ b/drivers/power/supply/isp1704_charger.c @@ -383,7 +383,7 @@ static int isp1704_charger_probe(struct platform_device *pdev) int ret = -ENODEV; struct power_supply_config psy_cfg = {}; - isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(&pdev->dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/power/supply/lego_ev3_battery.c b/drivers/power/supply/lego_ev3_battery.c index 1e53f11a8e2b2d..5fd87efbfd7093 100644 --- a/drivers/power/supply/lego_ev3_battery.c +++ b/drivers/power/supply/lego_ev3_battery.c @@ -158,7 +158,7 @@ static int lego_ev3_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int err; - batt = devm_kzalloc(dev, sizeof(*batt), GFP_KERNEL); + batt = devm_kzalloc_obj(dev, *batt); if (!batt) return -ENOMEM; diff --git a/drivers/power/supply/lenovo_yoga_c630_battery.c b/drivers/power/supply/lenovo_yoga_c630_battery.c index 7a6c8af9e8c248..a083e22d3b5169 100644 --- a/drivers/power/supply/lenovo_yoga_c630_battery.c +++ b/drivers/power/supply/lenovo_yoga_c630_battery.c @@ -427,7 +427,7 @@ static int yoga_c630_psy_probe(struct auxiliary_device *adev, struct yoga_c630_psy *ecbat; int ret; - ecbat = devm_kzalloc(&adev->dev, sizeof(*ecbat), GFP_KERNEL); + ecbat = devm_kzalloc_obj(&adev->dev, *ecbat); if (!ecbat) return -ENOMEM; diff --git a/drivers/power/supply/lp8727_charger.c b/drivers/power/supply/lp8727_charger.c index 4537b7b413ddc2..337028601d8197 100644 --- a/drivers/power/supply/lp8727_charger.c +++ b/drivers/power/supply/lp8727_charger.c @@ -444,7 +444,7 @@ static int lp8727_register_psy(struct lp8727_chg *pchg) struct power_supply_config psy_cfg = {}; /* Only for ac and usb */ struct lp8727_psy *psy; - psy = devm_kzalloc(pchg->dev, sizeof(*psy), GFP_KERNEL); + psy = devm_kzalloc_obj(pchg->dev, *psy); if (!psy) return -ENOMEM; @@ -475,7 +475,7 @@ static struct lp8727_chg_param { struct lp8727_chg_param *param; - param = devm_kzalloc(dev, sizeof(*param), GFP_KERNEL); + param = devm_kzalloc_obj(dev, *param); if (!param) goto out; @@ -492,7 +492,7 @@ static struct lp8727_platform_data *lp8727_parse_dt(struct device *dev) struct lp8727_platform_data *pdata; const char *type; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -538,7 +538,7 @@ static int lp8727_probe(struct i2c_client *cl) pdata = dev_get_platdata(&cl->dev); } - pchg = devm_kzalloc(&cl->dev, sizeof(*pchg), GFP_KERNEL); + pchg = devm_kzalloc_obj(&cl->dev, *pchg); if (!pchg) return -ENOMEM; diff --git a/drivers/power/supply/lp8788-charger.c b/drivers/power/supply/lp8788-charger.c index b8b74efc9671ab..f72c3ba5c6c882 100644 --- a/drivers/power/supply/lp8788-charger.c +++ b/drivers/power/supply/lp8788-charger.c @@ -681,7 +681,7 @@ static int lp8788_charger_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - pchg = devm_kzalloc(dev, sizeof(struct lp8788_charger), GFP_KERNEL); + pchg = devm_kzalloc_obj(dev, struct lp8788_charger); if (!pchg) return -ENOMEM; diff --git a/drivers/power/supply/lt3651-charger.c b/drivers/power/supply/lt3651-charger.c index ebfbdbcb768321..fe73c6626408db 100644 --- a/drivers/power/supply/lt3651-charger.c +++ b/drivers/power/supply/lt3651-charger.c @@ -98,8 +98,7 @@ static int lt3651_charger_probe(struct platform_device *pdev) struct power_supply_desc *charger_desc; int ret; - lt3651_charger = devm_kzalloc(&pdev->dev, sizeof(*lt3651_charger), - GFP_KERNEL); + lt3651_charger = devm_kzalloc_obj(&pdev->dev, *lt3651_charger); if (!lt3651_charger) return -ENOMEM; diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c index 6ebb555f203d34..9924cbcacb11bf 100644 --- a/drivers/power/supply/ltc2941-battery-gauge.c +++ b/drivers/power/supply/ltc2941-battery-gauge.c @@ -449,7 +449,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client) s32 r_sense; u8 status; - info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, *info); if (info == NULL) return -ENOMEM; diff --git a/drivers/power/supply/ltc4162-l-charger.c b/drivers/power/supply/ltc4162-l-charger.c index 01b0511da9aeec..31417e0f0ea61b 100644 --- a/drivers/power/supply/ltc4162-l-charger.c +++ b/drivers/power/supply/ltc4162-l-charger.c @@ -1189,7 +1189,7 @@ static int ltc4162l_probe(struct i2c_client *client) dev_err(dev, "No support for SMBUS_WORD_DATA\n"); return -ENODEV; } - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c index ef735f86394e4c..ad2c4dea033480 100644 --- a/drivers/power/supply/macsmc-power.c +++ b/drivers/power/supply/macsmc-power.c @@ -653,7 +653,7 @@ static int macsmc_power_probe(struct platform_device *pdev) if (!smc) return -ENODEV; - power = devm_kzalloc(dev, sizeof(*power), GFP_KERNEL); + power = devm_kzalloc_obj(dev, *power); if (!power) return -ENOMEM; @@ -686,9 +686,8 @@ static int macsmc_power_probe(struct platform_device *pdev) if (has_battery) { power->batt_desc = macsmc_battery_desc_template; - props = devm_kcalloc(dev, MACSMC_MAX_BATT_PROPS, - sizeof(enum power_supply_property), - GFP_KERNEL); + props = devm_kzalloc_objs(dev, enum power_supply_property, + MACSMC_MAX_BATT_PROPS); if (!props) return -ENOMEM; @@ -818,9 +817,8 @@ static int macsmc_power_probe(struct platform_device *pdev) if (has_ac_adapter) { power->ac_desc = macsmc_ac_desc_template; - props = devm_kcalloc(dev, MACSMC_MAX_AC_PROPS, - sizeof(enum power_supply_property), - GFP_KERNEL); + props = devm_kzalloc_objs(dev, enum power_supply_property, + MACSMC_MAX_AC_PROPS); if (!props) return -ENOMEM; diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c index a15d9494218488..00bb07bee21a88 100644 --- a/drivers/power/supply/max14577_charger.c +++ b/drivers/power/supply/max14577_charger.c @@ -465,7 +465,7 @@ static struct max14577_charger_platform_data *max14577_charger_dt_init( return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -563,7 +563,7 @@ static int max14577_charger_probe(struct platform_device *pdev) struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); int ret; - chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(&pdev->dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max14656_charger_detector.c b/drivers/power/supply/max14656_charger_detector.c index f78d0341d0efff..9d64325f218abb 100644 --- a/drivers/power/supply/max14656_charger_detector.c +++ b/drivers/power/supply/max14656_charger_detector.c @@ -252,7 +252,7 @@ static int max14656_probe(struct i2c_client *client) return -ENODEV; } - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index 16e42de284367f..5c7f25acffeda4 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c @@ -480,7 +480,7 @@ static int max17040_probe(struct i2c_client *client) bool enable_irq = false; int ret; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 8138b52e05e15a..ae7e9b42579ce2 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -669,7 +669,7 @@ static int max17042_init_model(struct max17042_chip *chip) int table_size = ARRAY_SIZE(chip->config_data->cell_char_tbl); u16 *temp_data; - temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); + temp_data = kzalloc_objs(*temp_data, table_size); if (!temp_data) return -ENOMEM; @@ -698,7 +698,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip) u16 *temp_data; int ret = 0; - temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); + temp_data = kzalloc_objs(*temp_data, table_size); if (!temp_data) return -ENOMEM; @@ -1332,7 +1332,7 @@ static int max17042_apply_battery_properties(struct max17042_chip *chip, config = chip->config_data; if (!config) { - config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(dev, *config); if (!config) return -ENOMEM; } @@ -1446,7 +1446,7 @@ static int max17042_probe(struct i2c_client *client, struct device *dev, int irq if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -EIO; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/max1720x_battery.c b/drivers/power/supply/max1720x_battery.c index e2bd54ee397080..4686b871be680a 100644 --- a/drivers/power/supply/max1720x_battery.c +++ b/drivers/power/supply/max1720x_battery.c @@ -589,7 +589,7 @@ static int max1720x_probe(struct i2c_client *client) struct power_supply *bat; int ret; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/max1721x_battery.c b/drivers/power/supply/max1721x_battery.c index bac43ab9e97cdf..450cd1f62bc5a1 100644 --- a/drivers/power/supply/max1721x_battery.c +++ b/drivers/power/supply/max1721x_battery.c @@ -325,7 +325,7 @@ static int devm_w1_max1721x_add_device(struct w1_slave *sl) struct power_supply_config psy_cfg = {}; struct max17211_device_info *info; - info = devm_kzalloc(&sl->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&sl->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/max77650-charger.c b/drivers/power/supply/max77650-charger.c index 4ae43668992ecd..154fcd6aa71cb2 100644 --- a/drivers/power/supply/max77650-charger.c +++ b/drivers/power/supply/max77650-charger.c @@ -286,7 +286,7 @@ static int max77650_charger_probe(struct platform_device *pdev) dev = &pdev->dev; parent = dev->parent; - chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 76c58b32a3748b..d6f07e59f751d3 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -724,7 +724,7 @@ static int max77693_charger_probe(struct platform_device *pdev) struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); int ret; - chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(&pdev->dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c index 63b0b4f0cd217f..ca9ad041f1ed19 100644 --- a/drivers/power/supply/max77705_charger.c +++ b/drivers/power/supply/max77705_charger.c @@ -607,7 +607,7 @@ static int max77705_charger_probe(struct i2c_client *i2c) dev = &i2c->dev; - chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max77759_charger.c b/drivers/power/supply/max77759_charger.c index 689fc733fa3f84..a93adb266f019e 100644 --- a/drivers/power/supply/max77759_charger.c +++ b/drivers/power/supply/max77759_charger.c @@ -690,7 +690,7 @@ static int max77759_charger_probe(struct platform_device *pdev) int ret; device_set_of_node_from_dev(dev, dev->parent); - chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max77976_charger.c b/drivers/power/supply/max77976_charger.c index 9a8a09d2a55e83..379b862a704824 100644 --- a/drivers/power/supply/max77976_charger.c +++ b/drivers/power/supply/max77976_charger.c @@ -446,7 +446,7 @@ static int max77976_probe(struct i2c_client *client) int err; int i; - chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/max8903_charger.c b/drivers/power/supply/max8903_charger.c index d5267ba1996989..1f76a8ed0608eb 100644 --- a/drivers/power/supply/max8903_charger.c +++ b/drivers/power/supply/max8903_charger.c @@ -498,7 +498,7 @@ static int max8903_parse_dc_current_limit(struct platform_device *pdev, * reason to keep the raw mirror around for the lifetime of the * device. */ - map = kmalloc_array(map_size, sizeof(*map), GFP_KERNEL); + map = kmalloc_objs(*map, map_size); if (!map) return -ENOMEM; @@ -511,10 +511,9 @@ static int max8903_parse_dc_current_limit(struct platform_device *pdev, } data->dc_current_limit_map_size = map_size / 2; - data->dc_current_limit_map = devm_kcalloc(dev, - data->dc_current_limit_map_size, - sizeof(*data->dc_current_limit_map), - GFP_KERNEL); + data->dc_current_limit_map = devm_kzalloc_objs(dev, + *data->dc_current_limit_map, + data->dc_current_limit_map_size); if (!data->dc_current_limit_map) { kfree(map); return -ENOMEM; @@ -700,7 +699,7 @@ static int max8903_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int ret = 0; - data = devm_kzalloc(dev, sizeof(struct max8903_data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct max8903_data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/max8925_power.c b/drivers/power/supply/max8925_power.c index d753145de3bb38..9928f83275f5dd 100644 --- a/drivers/power/supply/max8925_power.c +++ b/drivers/power/supply/max8925_power.c @@ -471,9 +471,7 @@ max8925_power_dt_init(struct platform_device *pdev) return NULL; } - pdata = devm_kzalloc(&pdev->dev, - sizeof(struct max8925_power_pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, struct max8925_power_pdata); if (!pdata) goto ret; @@ -515,8 +513,7 @@ static int max8925_power_probe(struct platform_device *pdev) return -EINVAL; } - info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_power_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8925_power_info); if (!info) return -ENOMEM; info->chip = chip; diff --git a/drivers/power/supply/max8971_charger.c b/drivers/power/supply/max8971_charger.c index 0d69e9f44c05cf..54cdad4dba7d58 100644 --- a/drivers/power/supply/max8971_charger.c +++ b/drivers/power/supply/max8971_charger.c @@ -646,7 +646,7 @@ static int max8971_probe(struct i2c_client *client) struct power_supply_config cfg = { }; int err, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/supply/max8997_charger.c b/drivers/power/supply/max8997_charger.c index 19da9eff03720f..a1abb143dd8372 100644 --- a/drivers/power/supply/max8997_charger.c +++ b/drivers/power/supply/max8997_charger.c @@ -213,7 +213,7 @@ static int max8997_battery_probe(struct platform_device *pdev) return ret; } - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/max8998_charger.c b/drivers/power/supply/max8998_charger.c index 13071350f31854..eefada4a1f3c29 100644 --- a/drivers/power/supply/max8998_charger.c +++ b/drivers/power/supply/max8998_charger.c @@ -101,8 +101,7 @@ static int max8998_battery_probe(struct platform_device *pdev) return -ENODEV; } - max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_battery_data), - GFP_KERNEL); + max8998 = devm_kzalloc_obj(&pdev->dev, struct max8998_battery_data); if (!max8998) return -ENOMEM; diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c index c38f48338d42ad..a8d4416e857fc0 100644 --- a/drivers/power/supply/mm8013.c +++ b/drivers/power/supply/mm8013.c @@ -257,7 +257,7 @@ static int mm8013_probe(struct i2c_client *client) return dev_err_probe(dev, -EIO, "I2C_FUNC_SMBUS_WORD_DATA not supported\n"); - chip = devm_kzalloc(dev, sizeof(struct mm8013_chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, struct mm8013_chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c index 0aace004025922..24af66be3007f4 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -566,7 +566,7 @@ static int mp2629_charger_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; int ret, i, irq; - charger = devm_kzalloc(dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/mt6360_charger.c index b4d4623431515f..b927870a54f7c8 100644 --- a/drivers/power/supply/mt6360_charger.c +++ b/drivers/power/supply/mt6360_charger.c @@ -782,7 +782,7 @@ static int mt6360_charger_probe(struct platform_device *pdev) struct regulator_config config = { }; int ret; - mci = devm_kzalloc(&pdev->dev, sizeof(*mci), GFP_KERNEL); + mci = devm_kzalloc_obj(&pdev->dev, *mci); if (!mci) return -ENOMEM; diff --git a/drivers/power/supply/mt6370-charger.c b/drivers/power/supply/mt6370-charger.c index 29ce34fd38044e..ceb246b8bf34e7 100644 --- a/drivers/power/supply/mt6370-charger.c +++ b/drivers/power/supply/mt6370-charger.c @@ -849,7 +849,7 @@ static int mt6370_chg_probe(struct platform_device *pdev) struct mt6370_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c index 17433c58fcd4dc..fd755afb8dcb72 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -638,7 +638,7 @@ static int olpc_battery_probe(struct platform_device *pdev) uint8_t ecver; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; platform_set_drvdata(pdev, data); diff --git a/drivers/power/supply/pf1550-charger.c b/drivers/power/supply/pf1550-charger.c index e3d4e9817f917c..9a7b3a831cd4d5 100644 --- a/drivers/power/supply/pf1550-charger.c +++ b/drivers/power/supply/pf1550-charger.c @@ -553,7 +553,7 @@ static int pf1550_charger_probe(struct platform_device *pdev) struct pf1550_charger *chg; int i, irq, ret; - chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(&pdev->dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/pm8916_bms_vm.c b/drivers/power/supply/pm8916_bms_vm.c index b279f79f302c42..3cea8c85ef3d44 100644 --- a/drivers/power/supply/pm8916_bms_vm.c +++ b/drivers/power/supply/pm8916_bms_vm.c @@ -152,7 +152,7 @@ static int pm8916_bms_vm_battery_probe(struct platform_device *pdev) int ret, irq; unsigned int tmp; - bat = devm_kzalloc(dev, sizeof(*bat), GFP_KERNEL); + bat = devm_kzalloc_obj(dev, *bat); if (!bat) return -ENOMEM; diff --git a/drivers/power/supply/pm8916_lbc.c b/drivers/power/supply/pm8916_lbc.c index 6910b8c24343b5..c71d7862b2ba48 100644 --- a/drivers/power/supply/pm8916_lbc.c +++ b/drivers/power/supply/pm8916_lbc.c @@ -252,7 +252,7 @@ static int pm8916_lbc_charger_probe(struct platform_device *pdev) int ret, len, irq; unsigned int tmp; - chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index de15314ef95490..1cc203f2780b77 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -202,9 +202,8 @@ static int power_supply_check_supplies_by_name(struct power_supply *psy) if (nval <= 0) return 0; - psy->supplied_from = devm_kmalloc_array(&psy->dev, nval, - sizeof(*psy->supplied_from), - GFP_KERNEL); + psy->supplied_from = devm_kmalloc_objs(&psy->dev, *psy->supplied_from, + nval); if (!psy->supplied_from) return -ENOMEM; @@ -320,9 +319,8 @@ static int power_supply_check_supplies(struct power_supply *psy) return power_supply_check_supplies_by_name(psy); /* All supplies found, allocate char * array for filling */ - psy->supplied_from = devm_kcalloc(&psy->dev, - cnt, sizeof(*psy->supplied_from), - GFP_KERNEL); + psy->supplied_from = devm_kzalloc_objs(&psy->dev, *psy->supplied_from, + cnt); if (!psy->supplied_from) return -ENOMEM; @@ -765,7 +763,7 @@ int power_supply_get_battery_info(struct power_supply *psy, goto out_put_node; } - info = devm_kzalloc(&psy->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&psy->dev, *info); if (!info) { err = -ENOMEM; goto out_put_node; @@ -921,7 +919,7 @@ int power_supply_get_battery_info(struct power_supply *psy, info->ocv_table_size[index] = tab_len; info->ocv_table[index] = table = - devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL); + devm_kzalloc_objs(&psy->dev, *table, tab_len); if (!info->ocv_table[index]) { power_supply_put_battery_info(psy, info); err = -ENOMEM; @@ -959,10 +957,9 @@ int power_supply_get_battery_info(struct power_supply *psy, } info->resist_table_size = proplen / 2; - info->resist_table = resist_table = devm_kcalloc(&psy->dev, - info->resist_table_size, - sizeof(*resist_table), - GFP_KERNEL); + info->resist_table = resist_table = devm_kzalloc_objs(&psy->dev, + *resist_table, + info->resist_table_size); if (!info->resist_table) { power_supply_put_battery_info(psy, info); err = -ENOMEM; diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index 95245e6a6baa3e..3958e390ee0136 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -381,7 +381,7 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy) GFP_KERNEL)) return -ENOMEM; - psyhw = devm_kzalloc(dev, sizeof(*psyhw), GFP_KERNEL); + psyhw = devm_kzalloc_obj(dev, *psyhw); if (!psyhw) { ret = -ENOMEM; goto error; diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c index 636d6f6acecc5e..58e238e6fb2a15 100644 --- a/drivers/power/supply/qcom_battmgr.c +++ b/drivers/power/supply/qcom_battmgr.c @@ -1662,7 +1662,7 @@ static int qcom_battmgr_probe(struct auxiliary_device *adev, struct device *dev = &adev->dev; int ret; - battmgr = devm_kzalloc(dev, sizeof(*battmgr), GFP_KERNEL); + battmgr = devm_kzalloc_obj(dev, *battmgr); if (!battmgr) return -ENOMEM; diff --git a/drivers/power/supply/qcom_smbb.c b/drivers/power/supply/qcom_smbb.c index f33aab9619c4a3..378c121e473e7c 100644 --- a/drivers/power/supply/qcom_smbb.c +++ b/drivers/power/supply/qcom_smbb.c @@ -837,7 +837,7 @@ static int smbb_charger_probe(struct platform_device *pdev) struct regulator_config config = { }; int rc, i; - chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + chg = devm_kzalloc_obj(&pdev->dev, *chg); if (!chg) return -ENOMEM; diff --git a/drivers/power/supply/qcom_smbx.c b/drivers/power/supply/qcom_smbx.c index 52bb5a6eb145d1..8a2f635a6ccb1e 100644 --- a/drivers/power/supply/qcom_smbx.c +++ b/drivers/power/supply/qcom_smbx.c @@ -961,7 +961,7 @@ static int smb_probe(struct platform_device *pdev) int float_voltage_uv; int rc, irq; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; @@ -1008,7 +1008,7 @@ static int smb_probe(struct platform_device *pdev) supply_config.drv_data = chip; supply_config.fwnode = dev_fwnode(&pdev->dev); - desc = devm_kzalloc(chip->dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(chip->dev, *desc); if (!desc) return -ENOMEM; memcpy(desc, &smb_psy_desc, sizeof(smb_psy_desc)); diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c index 5558b182a1a617..39b45e085fc49c 100644 --- a/drivers/power/supply/rk817_charger.c +++ b/drivers/power/supply/rk817_charger.c @@ -1076,7 +1076,7 @@ static int rk817_charger_probe(struct platform_device *pdev) if (ret) return ret; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/rn5t618_power.c b/drivers/power/supply/rn5t618_power.c index 84b9d624848987..92243a2f6a443d 100644 --- a/drivers/power/supply/rn5t618_power.c +++ b/drivers/power/supply/rn5t618_power.c @@ -719,7 +719,7 @@ static int rn5t618_power_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct rn5t618_power_info *info; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c index 63333f6aa819d4..f8c3939708dd0f 100644 --- a/drivers/power/supply/rt5033_battery.c +++ b/drivers/power/supply/rt5033_battery.c @@ -147,7 +147,7 @@ static int rt5033_battery_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; - battery = devm_kzalloc(&client->dev, sizeof(*battery), GFP_KERNEL); + battery = devm_kzalloc_obj(&client->dev, *battery); if (!battery) return -ENOMEM; diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c index e545a6e7fad7ca..5d5419807970bf 100644 --- a/drivers/power/supply/rt5033_charger.c +++ b/drivers/power/supply/rt5033_charger.c @@ -666,7 +666,7 @@ static int rt5033_charger_probe(struct platform_device *pdev) struct device_node *np_conn, *np_edev; int ret; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/rt9455_charger.c b/drivers/power/supply/rt9455_charger.c index 313a7371211e57..502410f5564a77 100644 --- a/drivers/power/supply/rt9455_charger.c +++ b/drivers/power/supply/rt9455_charger.c @@ -1615,7 +1615,7 @@ static int rt9455_probe(struct i2c_client *client) dev_err(dev, "No support for SMBUS_BYTE_DATA\n"); return -ENODEV; } - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/rt9467-charger.c b/drivers/power/supply/rt9467-charger.c index f0d10f44b10902..9399c06ad50cef 100644 --- a/drivers/power/supply/rt9467-charger.c +++ b/drivers/power/supply/rt9467-charger.c @@ -1205,7 +1205,7 @@ static int rt9467_charger_probe(struct i2c_client *i2c) struct gpio_desc *ceb_gpio; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/rt9471.c b/drivers/power/supply/rt9471.c index b16d39a774dd4d..2eaa2db016c9b2 100644 --- a/drivers/power/supply/rt9471.c +++ b/drivers/power/supply/rt9471.c @@ -898,7 +898,7 @@ static int rt9471_probe(struct i2c_client *i2c) struct regmap *regmap; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/rt9756.c b/drivers/power/supply/rt9756.c index a7b7e3fb69b1f3..7da6974b209932 100644 --- a/drivers/power/supply/rt9756.c +++ b/drivers/power/supply/rt9756.c @@ -641,7 +641,7 @@ static int rt9756_register_psy(struct rt9756_data *data) if (IS_ERR(data->bat_psy)) return dev_err_probe(dev, PTR_ERR(data->bat_psy), "Failed to register battery\n"); - supplied_to = devm_kzalloc(dev, sizeof(*supplied_to), GFP_KERNEL); + supplied_to = devm_kzalloc_obj(dev, *supplied_to); if (!supplied_to) return -ENOMEM; @@ -860,7 +860,7 @@ static int rt9756_probe(struct i2c_client *i2c) if (!dev_data) return dev_err_probe(dev, -EINVAL, "No device data found\n"); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/rx51_battery.c b/drivers/power/supply/rx51_battery.c index 57266921dc8e2d..fd8c50b07a3fab 100644 --- a/drivers/power/supply/rx51_battery.c +++ b/drivers/power/supply/rx51_battery.c @@ -193,7 +193,7 @@ static int rx51_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct rx51_device_info *di; - di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc_obj(&pdev->dev, *di); if (!di) return -ENOMEM; diff --git a/drivers/power/supply/s2m-charger.c b/drivers/power/supply/s2m-charger.c index 4d1f2c2c714460..60a3c12683d930 100644 --- a/drivers/power/supply/s2m-charger.c +++ b/drivers/power/supply/s2m-charger.c @@ -245,7 +245,7 @@ static int s2m_chgr_probe(struct platform_device *pdev) work_func_t extcon_work_func; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/supply/s2mu005-battery.c b/drivers/power/supply/s2mu005-battery.c index a76154e5a09176..712f0505193576 100644 --- a/drivers/power/supply/s2mu005-battery.c +++ b/drivers/power/supply/s2mu005-battery.c @@ -248,7 +248,7 @@ static int s2mu005_fg_i2c_probe(struct i2c_client *client) const struct power_supply_desc *psy_desc; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 6714313bb3a3f1..8e8a1039d8be66 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -1148,7 +1148,7 @@ static int sbs_probe(struct i2c_client *client) if (!sbs_desc->name) return -ENOMEM; - chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct sbs_info); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/sbs-charger.c b/drivers/power/supply/sbs-charger.c index bc40bbb429e686..497ed1a9fb5ced 100644 --- a/drivers/power/supply/sbs-charger.c +++ b/drivers/power/supply/sbs-charger.c @@ -178,7 +178,7 @@ static int sbs_probe(struct i2c_client *client) if (!sbs_desc->name) return -ENOMEM; - chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct sbs_info); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/sbs-manager.c b/drivers/power/supply/sbs-manager.c index 9ad3fb117a4d69..5071a4f29c5c1f 100644 --- a/drivers/power/supply/sbs-manager.c +++ b/drivers/power/supply/sbs-manager.c @@ -332,7 +332,7 @@ static int sbsm_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -EPFNOSUPPORT; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/sc2731_charger.c b/drivers/power/supply/sc2731_charger.c index 2b25e44da7978b..79a379711b14d1 100644 --- a/drivers/power/supply/sc2731_charger.c +++ b/drivers/power/supply/sc2731_charger.c @@ -459,7 +459,7 @@ static int sc2731_charger_probe(struct platform_device *pdev) struct power_supply_config charger_cfg = { }; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index 0999fc5bc662de..345fb5b3396cc6 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -1144,7 +1144,7 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) struct sc27xx_fgu_data *data; int ret, irq; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/sgm41542_charger.c b/drivers/power/supply/sgm41542_charger.c index 8880962528d66b..efdaa28f124ef9 100644 --- a/drivers/power/supply/sgm41542_charger.c +++ b/drivers/power/supply/sgm41542_charger.c @@ -988,7 +988,7 @@ static int sgm4154x_probe(struct i2c_client *client) struct sgm4154x_device *sgm; int ret; - sgm = devm_kzalloc(dev, sizeof(*sgm), GFP_KERNEL); + sgm = devm_kzalloc_obj(dev, *sgm); if (!sgm) return -ENOMEM; diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index 72dfa15b3d8060..0b8e12ae62e5a9 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -1537,7 +1537,7 @@ static int smb347_probe(struct i2c_client *client) struct smb347_charger *smb; int ret; - smb = devm_kzalloc(dev, sizeof(*smb), GFP_KERNEL); + smb = devm_kzalloc_obj(dev, *smb); if (!smb) return -ENOMEM; smb->dev = &client->dev; diff --git a/drivers/power/supply/stc3117_fuel_gauge.c b/drivers/power/supply/stc3117_fuel_gauge.c index 469f2b359920b7..81963b526eb9a3 100644 --- a/drivers/power/supply/stc3117_fuel_gauge.c +++ b/drivers/power/supply/stc3117_fuel_gauge.c @@ -532,7 +532,7 @@ static int stc3117_probe(struct i2c_client *client) struct power_supply_battery_info *info; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/power/supply/surface-rt-ec.c b/drivers/power/supply/surface-rt-ec.c index da57b0a1a4951c..b175bc63c5042a 100644 --- a/drivers/power/supply/surface-rt-ec.c +++ b/drivers/power/supply/surface-rt-ec.c @@ -269,7 +269,7 @@ static int srt_ec_probe(struct i2c_client *client) char str_buf[4]; int ret; - srt = devm_kzalloc(dev, sizeof(*srt), GFP_KERNEL); + srt = devm_kzalloc_obj(dev, *srt); if (!srt) return -ENOMEM; diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c index 1273b6082311de..dac19932c83170 100644 --- a/drivers/power/supply/surface_battery.c +++ b/drivers/power/supply/surface_battery.c @@ -823,7 +823,7 @@ static int surface_battery_probe(struct ssam_device *sdev) if (!p) return -ENODEV; - bat = devm_kzalloc(&sdev->dev, sizeof(*bat), GFP_KERNEL); + bat = devm_kzalloc_obj(&sdev->dev, *bat); if (!bat) return -ENOMEM; diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c index d4bba6b4179476..e8e790f6597556 100644 --- a/drivers/power/supply/surface_charger.c +++ b/drivers/power/supply/surface_charger.c @@ -237,7 +237,7 @@ static int surface_ac_probe(struct ssam_device *sdev) if (!p) return -ENODEV; - ac = devm_kzalloc(&sdev->dev, sizeof(*ac), GFP_KERNEL); + ac = devm_kzalloc_obj(&sdev->dev, *ac); if (!ac) return -ENOMEM; diff --git a/drivers/power/supply/tps65090-charger.c b/drivers/power/supply/tps65090-charger.c index 36340c56d27274..c6f7f0d0cb88f9 100644 --- a/drivers/power/supply/tps65090-charger.c +++ b/drivers/power/supply/tps65090-charger.c @@ -191,7 +191,7 @@ static struct tps65090_platform_data * struct device_node *np = pdev->dev.of_node; unsigned int prop; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) { dev_err(&pdev->dev, "Memory alloc for tps65090_pdata failed\n"); return NULL; @@ -246,7 +246,7 @@ static int tps65090_charger_probe(struct platform_device *pdev) return -ENODEV; } - cdata = devm_kzalloc(&pdev->dev, sizeof(*cdata), GFP_KERNEL); + cdata = devm_kzalloc_obj(&pdev->dev, *cdata); if (!cdata) { dev_err(&pdev->dev, "failed to allocate memory status\n"); return -ENOMEM; diff --git a/drivers/power/supply/tps65217_charger.c b/drivers/power/supply/tps65217_charger.c index cd00a3f372b30b..2d11c5fcaf3305 100644 --- a/drivers/power/supply/tps65217_charger.c +++ b/drivers/power/supply/tps65217_charger.c @@ -190,7 +190,7 @@ static int tps65217_charger_probe(struct platform_device *pdev) int ret; int i; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c index e6c9b2b1ffce70..35b974c0a44a64 100644 --- a/drivers/power/supply/twl4030_charger.c +++ b/drivers/power/supply/twl4030_charger.c @@ -934,7 +934,7 @@ twl4030_bci_parse_dt(struct device *dev) if (!np) return NULL; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return pdata; @@ -979,7 +979,7 @@ static int twl4030_bci_probe(struct platform_device *pdev) int ret; u32 reg; - bci = devm_kzalloc(&pdev->dev, sizeof(*bci), GFP_KERNEL); + bci = devm_kzalloc_obj(&pdev->dev, *bci); if (bci == NULL) return -ENOMEM; diff --git a/drivers/power/supply/twl4030_madc_battery.c b/drivers/power/supply/twl4030_madc_battery.c index 5e04b4f0a13500..40634839261b20 100644 --- a/drivers/power/supply/twl4030_madc_battery.c +++ b/drivers/power/supply/twl4030_madc_battery.c @@ -187,8 +187,7 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev) struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data; struct power_supply_config psy_cfg = {}; - twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat), - GFP_KERNEL); + twl4030_madc_bat = devm_kzalloc_obj(&pdev->dev, *twl4030_madc_bat); if (!twl4030_madc_bat) return -ENOMEM; diff --git a/drivers/power/supply/twl6030_charger.c b/drivers/power/supply/twl6030_charger.c index e8ef221fa0f34b..5812d44cf41cd0 100644 --- a/drivers/power/supply/twl6030_charger.c +++ b/drivers/power/supply/twl6030_charger.c @@ -453,7 +453,7 @@ static int twl6030_charger_probe(struct platform_device *pdev) int ret; u8 val; - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + charger = devm_kzalloc_obj(&pdev->dev, *charger); if (!charger) return -ENOMEM; diff --git a/drivers/power/supply/ucs1002_power.c b/drivers/power/supply/ucs1002_power.c index bf13e958982ece..f6a3e5da9be637 100644 --- a/drivers/power/supply/ucs1002_power.c +++ b/drivers/power/supply/ucs1002_power.c @@ -544,7 +544,7 @@ static int ucs1002_probe(struct i2c_client *client) struct ucs1002_info *info; unsigned int regval; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/power/supply/ug3105_battery.c b/drivers/power/supply/ug3105_battery.c index cccf7499e129a1..ff29a3ab66f901 100644 --- a/drivers/power/supply/ug3105_battery.c +++ b/drivers/power/supply/ug3105_battery.c @@ -134,7 +134,7 @@ static int ug3105_probe(struct i2c_client *client) struct ug3105_chip *chip; int ret; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/power/supply/wm831x_backup.c b/drivers/power/supply/wm831x_backup.c index 9673fcf7f3afba..ac6dd5b20a50ce 100644 --- a/drivers/power/supply/wm831x_backup.c +++ b/drivers/power/supply/wm831x_backup.c @@ -165,8 +165,7 @@ static int wm831x_backup_probe(struct platform_device *pdev) struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data; struct wm831x_backup *devdata; - devdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_backup), - GFP_KERNEL); + devdata = devm_kzalloc_obj(&pdev->dev, struct wm831x_backup); if (devdata == NULL) return -ENOMEM; diff --git a/drivers/power/supply/wm831x_power.c b/drivers/power/supply/wm831x_power.c index 78fa0573ef25c7..d4e85c233be928 100644 --- a/drivers/power/supply/wm831x_power.c +++ b/drivers/power/supply/wm831x_power.c @@ -542,8 +542,7 @@ static int wm831x_power_probe(struct platform_device *pdev) struct wm831x_power *power; int ret, irq, i; - power = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_power), - GFP_KERNEL); + power = devm_kzalloc_obj(&pdev->dev, struct wm831x_power); if (power == NULL) return -ENOMEM; diff --git a/drivers/power/supply/wm97xx_battery.c b/drivers/power/supply/wm97xx_battery.c index a6c55b1e02863f..9c66dd490fa4cc 100644 --- a/drivers/power/supply/wm97xx_battery.c +++ b/drivers/power/supply/wm97xx_battery.c @@ -192,7 +192,7 @@ static int wm97xx_bat_probe(struct platform_device *dev) if (pdata->min_voltage >= 0) props++; /* POWER_SUPPLY_PROP_VOLTAGE_MIN */ - prop = devm_kcalloc(&dev->dev, props, sizeof(*prop), GFP_KERNEL); + prop = devm_kzalloc_objs(&dev->dev, *prop, props); if (!prop) return -ENOMEM; diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c index ab66e9a3b1e2c5..63a956cf8d2bc5 100644 --- a/drivers/powercap/arm_scmi_powercap.c +++ b/drivers/powercap/arm_scmi_powercap.c @@ -432,7 +432,7 @@ static int scmi_powercap_probe(struct scmi_device *sdev) if (IS_ERR(powercap_ops)) return PTR_ERR(powercap_ops); - pr = devm_kzalloc(dev, sizeof(*pr), GFP_KERNEL); + pr = devm_kzalloc_obj(dev, *pr); if (!pr) return -ENOMEM; @@ -443,15 +443,13 @@ static int scmi_powercap_probe(struct scmi_device *sdev) } pr->num_zones = ret; - pr->spzones = devm_kcalloc(dev, pr->num_zones, - sizeof(*pr->spzones), GFP_KERNEL); + pr->spzones = devm_kzalloc_objs(dev, *pr->spzones, pr->num_zones); if (!pr->spzones) return -ENOMEM; /* Allocate for worst possible scenario of maximum tree height. */ - pr->registered_zones = devm_kcalloc(dev, pr->num_zones, - sizeof(*pr->registered_zones), - GFP_KERNEL); + pr->registered_zones = devm_kzalloc_objs(dev, *pr->registered_zones, + pr->num_zones); if (!pr->registered_zones) return -ENOMEM; diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c index 70cab5f08bc693..f58649ff4f53e6 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -1139,21 +1139,23 @@ static struct rapl_pmu rapl_pmu; /* PMU helpers */ -static void set_pmu_cpumask(struct rapl_package *rp, cpumask_var_t mask) +static int get_pmu_cpu(struct rapl_package *rp) { int cpu; if (!rp->has_pmu) - return; + return nr_cpu_ids; /* Only TPMI & MSR RAPL are supported for now */ if (rp->priv->type != RAPL_IF_TPMI && rp->priv->type != RAPL_IF_MSR) - return; + return nr_cpu_ids; /* TPMI/MSR RAPL uses any CPU in the package for PMU */ for_each_online_cpu(cpu) if (topology_physical_package_id(cpu) == rp->id) - cpumask_set_cpu(cpu, mask); + return cpu; + + return nr_cpu_ids; } static bool is_rp_pmu_cpu(struct rapl_package *rp, int cpu) @@ -1435,6 +1437,7 @@ static ssize_t cpumask_show(struct device *dev, { struct rapl_package *rp; cpumask_var_t cpu_mask; + int cpu; int ret; if (!alloc_cpumask_var(&cpu_mask, GFP_KERNEL)) @@ -1446,7 +1449,9 @@ static ssize_t cpumask_show(struct device *dev, /* Choose a cpu for each RAPL Package */ list_for_each_entry(rp, &rapl_packages, plist) { - set_pmu_cpumask(rp, cpu_mask); + cpu = get_pmu_cpu(rp); + if (cpu < nr_cpu_ids) + cpumask_set_cpu(cpu, cpu_mask); } cpus_read_unlock(); diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c index 73ec2c7335e518..fbaa1e3413a8d9 100644 --- a/drivers/pps/clients/pps-gpio.c +++ b/drivers/pps/clients/pps-gpio.c @@ -150,7 +150,7 @@ static int pps_gpio_probe(struct platform_device *pdev) int pps_default_params; /* allocate space for device info */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c index 5088aaf1a63a81..c6d41fb2105f45 100644 --- a/drivers/pps/generators/pps_gen_tio.c +++ b/drivers/pps/generators/pps_gen_tio.c @@ -203,7 +203,7 @@ static int pps_gen_tio_probe(struct platform_device *pdev) return -ENODEV; } - tio = devm_kzalloc(dev, sizeof(*tio), GFP_KERNEL); + tio = devm_kzalloc_obj(dev, *tio); if (!tio) return -ENOMEM; diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 4111342d64f03d..47ffc773065a31 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -508,6 +508,11 @@ static int unregister_vclock(struct device *dev, void *data) int ptp_clock_unregister(struct ptp_clock *ptp) { + /* + * Stop and drain virtual-clock creation and deletion before walking the + * children. Do not hold n_vclocks_mux while waiting for sysfs callbacks. + */ + ptp_vclock_remove_sysfs(ptp); if (ptp_vclock_in_use(ptp)) { device_for_each_child(&ptp->dev, NULL, unregister_vclock); } diff --git a/drivers/ptp/ptp_clockmatrix.c b/drivers/ptp/ptp_clockmatrix.c index 59cd6bbb33f3d5..6fd1fb669d6d59 100644 --- a/drivers/ptp/ptp_clockmatrix.c +++ b/drivers/ptp/ptp_clockmatrix.c @@ -2391,7 +2391,7 @@ static int idtcm_probe(struct platform_device *pdev) int err; u8 i; - idtcm = devm_kzalloc(&pdev->dev, sizeof(struct idtcm), GFP_KERNEL); + idtcm = devm_kzalloc_obj(&pdev->dev, struct idtcm); if (!idtcm) return -ENOMEM; diff --git a/drivers/ptp/ptp_dfl_tod.c b/drivers/ptp/ptp_dfl_tod.c index f699d541b3603f..eaa3b4c683c432 100644 --- a/drivers/ptp/ptp_dfl_tod.c +++ b/drivers/ptp/ptp_dfl_tod.c @@ -282,7 +282,7 @@ static int dfl_tod_probe(struct dfl_device *ddev) struct device *dev = &ddev->dev; struct dfl_tod *dt; - dt = devm_kzalloc(dev, sizeof(*dt), GFP_KERNEL); + dt = devm_kzalloc_obj(dev, *dt); if (!dt) return -ENOMEM; diff --git a/drivers/ptp/ptp_dte.c b/drivers/ptp/ptp_dte.c index 834ecacc7bd3c1..a6ea65cd468d23 100644 --- a/drivers/ptp/ptp_dte.c +++ b/drivers/ptp/ptp_dte.c @@ -231,7 +231,7 @@ static int ptp_dte_probe(struct platform_device *pdev) struct ptp_dte *ptp_dte; struct device *dev = &pdev->dev; - ptp_dte = devm_kzalloc(dev, sizeof(struct ptp_dte), GFP_KERNEL); + ptp_dte = devm_kzalloc_obj(dev, struct ptp_dte); if (!ptp_dte) return -ENOMEM; diff --git a/drivers/ptp/ptp_fc3.c b/drivers/ptp/ptp_fc3.c index 02b973995d7c1d..c84b60fa1ff5b4 100644 --- a/drivers/ptp/ptp_fc3.c +++ b/drivers/ptp/ptp_fc3.c @@ -951,7 +951,7 @@ static int idtfc3_probe(struct platform_device *pdev) struct idtfc3 *idtfc3; int err; - idtfc3 = devm_kzalloc(&pdev->dev, sizeof(struct idtfc3), GFP_KERNEL); + idtfc3 = devm_kzalloc_obj(&pdev->dev, struct idtfc3); if (!idtfc3) return -ENOMEM; diff --git a/drivers/ptp/ptp_idt82p33.c b/drivers/ptp/ptp_idt82p33.c index ffc2ec1fc4bedb..ef141311b6c3af 100644 --- a/drivers/ptp/ptp_idt82p33.c +++ b/drivers/ptp/ptp_idt82p33.c @@ -1396,8 +1396,7 @@ static int idt82p33_probe(struct platform_device *pdev) int err; u8 i; - idt82p33 = devm_kzalloc(&pdev->dev, - sizeof(struct idt82p33), GFP_KERNEL); + idt82p33 = devm_kzalloc_obj(&pdev->dev, struct idt82p33); if (!idt82p33) return -ENOMEM; diff --git a/drivers/ptp/ptp_kvm_x86.c b/drivers/ptp/ptp_kvm_x86.c index 6cea4fe39bcfe4..811758bd8b0def 100644 --- a/drivers/ptp/ptp_kvm_x86.c +++ b/drivers/ptp/ptp_kvm_x86.c @@ -36,7 +36,7 @@ int kvm_arch_ptp_init(void) clock_pair = page_address(p); ret = set_memory_decrypted((unsigned long)clock_pair, 1); if (ret) { - __free_page(p); + /* The page may be left shared, so leak it. */ clock_pair = NULL; goto nofree; } @@ -68,8 +68,9 @@ int kvm_arch_ptp_init(void) void kvm_arch_ptp_exit(void) { if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { - WARN_ON(set_memory_encrypted((unsigned long)clock_pair, 1)); - free_page((unsigned long)clock_pair); + /* Leak the page if it cannot be made private again. */ + if (!WARN_ON(set_memory_encrypted((unsigned long)clock_pair, 1))) + free_page((unsigned long)clock_pair); clock_pair = NULL; } } diff --git a/drivers/ptp/ptp_netc.c b/drivers/ptp/ptp_netc.c index 19ca99d80e95b5..1a327a7561e395 100644 --- a/drivers/ptp/ptp_netc.c +++ b/drivers/ptp/ptp_netc.c @@ -803,7 +803,7 @@ static int netc_timer_pci_probe(struct pci_dev *pdev) struct netc_timer *priv; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/ptp/ptp_pch.c b/drivers/ptp/ptp_pch.c index f854da2fd81214..68dfc48ad43ba6 100644 --- a/drivers/ptp/ptp_pch.c +++ b/drivers/ptp/ptp_pch.c @@ -452,7 +452,7 @@ pch_probe(struct pci_dev *pdev, const struct pci_device_id *id) unsigned long flags; struct pch_dev *chip; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (chip == NULL) return -ENOMEM; diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index db4039d642b41c..99e7eb241336e8 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -81,7 +81,11 @@ struct ptp_vclock { struct hlist_node vclock_hash_node; struct cyclecounter cc; struct timecounter tc; - struct mutex lock; /* protects tc/cc */ + u64 cycles; + struct mutex lock; /* protects tc/cc and the cached sample */ + /* Owned by the auxiliary worker. */ + unsigned long retry_delay; + unsigned long refresh_deadline; }; /* @@ -169,6 +173,7 @@ extern const struct attribute_group *ptp_groups[]; int ptp_populate_pin_groups(struct ptp_clock *ptp); void ptp_cleanup_pin_groups(struct ptp_clock *ptp); +void ptp_vclock_remove_sysfs(struct ptp_clock *ptp); struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock); void ptp_vclock_unregister(struct ptp_vclock *vclock); diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index dc398c6b75284b..8e0e0aa099815e 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -80,13 +80,17 @@ static ssize_t extts_fifo_show(struct device *dev, size_t qcnt; int cnt = 0; + spin_lock_irqsave(&ptp->tsevqs_lock, flags); cnt = list_count_nodes(&ptp->tsevqs); - if (cnt <= 0) + if (cnt <= 0) { + spin_unlock_irqrestore(&ptp->tsevqs_lock, flags); goto out; + } /* The sysfs fifo will always draw from the fist queue */ queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue, qlist); + spin_unlock_irqrestore(&ptp->tsevqs_lock, flags); memset(&event, 0, sizeof(event)); spin_lock_irqsave(&queue->lock, flags); @@ -224,8 +228,10 @@ static ssize_t n_vclocks_store(struct device *dev, if (num > ptp->n_vclocks) { for (i = 0; i < num - ptp->n_vclocks; i++) { vclock = ptp_vclock_register(ptp); - if (!vclock) - goto out; + if (IS_ERR(vclock)) { + err = PTR_ERR(vclock); + goto err_register; + } *(ptp->vclock_index + ptp->n_vclocks + i) = vclock->clock->index; @@ -257,12 +263,24 @@ static ssize_t n_vclocks_store(struct device *dev, mutex_unlock(&ptp->n_vclocks_mux); return count; +err_register: + num = i; + if (num) + device_for_each_child_reverse(dev, &num, unregister_vclock); + for (num = 0; num < i; num++) + ptp->vclock_index[ptp->n_vclocks + num] = -1; out: mutex_unlock(&ptp->n_vclocks_mux); return err; } static DEVICE_ATTR_RW(n_vclocks); +void ptp_vclock_remove_sysfs(struct ptp_clock *ptp) +{ + if (!ptp->is_virtual_clock) + device_remove_file(&ptp->dev, &dev_attr_n_vclocks); +} + static ssize_t max_vclocks_show(struct device *dev, struct device_attribute *attr, char *page) { diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 84cb527f59ccc6..e9cf4da3ed8a4b 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -4,6 +4,7 @@ * * Copyright 2021 NXP */ +#include #include #include #include "ptp_private.h" @@ -13,6 +14,7 @@ #define PTP_VCLOCK_FADJ_SHIFT 9 #define PTP_VCLOCK_FADJ_DENOMINATOR 15625ULL #define PTP_VCLOCK_REFRESH_INTERVAL (HZ * 2) +#define PTP_VCLOCK_RETRY_INTERVAL msecs_to_jiffies(10) /* protects vclock_hash addition/deletion */ static DEFINE_SPINLOCK(vclock_hash_lock); @@ -42,21 +44,39 @@ static void ptp_vclock_hash_del(struct ptp_vclock *vclock) synchronize_srcu(&vclock_srcu); } +/* The caller holds vclock->lock, or has not published the clock yet. */ +static int ptp_vclock_sample(struct ptp_vclock *vclock) +{ + struct ptp_clock *ptp = vclock->pclock; + struct timespec64 ts; + int err; + + err = ptp->info->getcycles64(ptp->info, &ts); + if (!err) + vclock->cycles = timespec64_to_ns(&ts); + + return err; +} + static int ptp_vclock_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) { struct ptp_vclock *vclock = info_to_vclock(ptp); s64 adj; + int err; adj = (s64)scaled_ppm << PTP_VCLOCK_FADJ_SHIFT; adj = div_s64(adj, PTP_VCLOCK_FADJ_DENOMINATOR); if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - timecounter_read(&vclock->tc); - vclock->cc.mult = PTP_VCLOCK_CC_MULT + adj; + err = ptp_vclock_sample(vclock); + if (!err) { + timecounter_read(&vclock->tc); + vclock->cc.mult = PTP_VCLOCK_CC_MULT + adj; + } mutex_unlock(&vclock->lock); - return 0; + return err; } static int ptp_vclock_adjtime(struct ptp_clock_info *ptp, s64 delta) @@ -75,15 +95,16 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) { struct ptp_vclock *vclock = info_to_vclock(ptp); - u64 ns; + int err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns = timecounter_read(&vclock->tc); + err = ptp_vclock_sample(vclock); + if (!err) + *ts = ns_to_timespec64(timecounter_read(&vclock->tc)); mutex_unlock(&vclock->lock); - *ts = ns_to_timespec64(ns); - return 0; + return err; } static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, @@ -94,20 +115,18 @@ static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, struct ptp_clock *pptp = vclock->pclock; struct timespec64 pts; int err; - u64 ns; - - err = pptp->info->getcyclesx64(pptp->info, &pts, sts); - if (err) - return err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); - mutex_unlock(&vclock->lock); + err = pptp->info->getcyclesx64(pptp->info, &pts, sts); + if (!err) { + u64 ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); - *ts = ns_to_timespec64(ns); + *ts = ns_to_timespec64(ns); + } + mutex_unlock(&vclock->lock); - return 0; + return err; } static int ptp_vclock_settime(struct ptp_clock_info *ptp, @@ -115,13 +134,16 @@ static int ptp_vclock_settime(struct ptp_clock_info *ptp, { struct ptp_vclock *vclock = info_to_vclock(ptp); u64 ns = timespec64_to_ns(ts); + int err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - timecounter_init(&vclock->tc, &vclock->cc, ns); + err = ptp_vclock_sample(vclock); + if (!err) + timecounter_init(&vclock->tc, &vclock->cc, ns); mutex_unlock(&vclock->lock); - return 0; + return err; } static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, @@ -130,20 +152,18 @@ static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, struct ptp_vclock *vclock = info_to_vclock(ptp); struct ptp_clock *pptp = vclock->pclock; int err; - u64 ns; - - err = pptp->info->getcrosscycles(pptp->info, xtstamp); - if (err) - return err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); - mutex_unlock(&vclock->lock); + err = pptp->info->getcrosscycles(pptp->info, xtstamp); + if (!err) { + u64 ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); - xtstamp->device = ns_to_ktime(ns); + xtstamp->device = ns_to_ktime(ns); + } + mutex_unlock(&vclock->lock); - return 0; + return err; } static long ptp_vclock_refresh(struct ptp_clock_info *ptp) @@ -151,8 +171,24 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp) struct ptp_vclock *vclock = info_to_vclock(ptp); struct timespec64 ts; - ptp_vclock_gettime(&vclock->info, &ts); + /* Retry transient failures promptly, but back off during long outages. */ + if (ptp_vclock_gettime(&vclock->info, &ts)) { + unsigned long now = jiffies; + + /* Retries must not postpone the next regular refresh attempt. */ + if (!vclock->retry_delay || time_after_eq(now, vclock->refresh_deadline)) + vclock->refresh_deadline = now + PTP_VCLOCK_REFRESH_INTERVAL; + + if (!vclock->retry_delay) + vclock->retry_delay = PTP_VCLOCK_RETRY_INTERVAL; + else + vclock->retry_delay = min_t(unsigned long, + vclock->retry_delay * 2, + PTP_VCLOCK_REFRESH_INTERVAL); + return min(vclock->retry_delay, vclock->refresh_deadline - now); + } + vclock->retry_delay = 0; return PTP_VCLOCK_REFRESH_INTERVAL; } @@ -174,12 +210,9 @@ static const struct ptp_clock_info ptp_vclock_info = { static u64 ptp_vclock_read(struct cyclecounter *cc) { struct ptp_vclock *vclock = cc_to_vclock(cc); - struct ptp_clock *ptp = vclock->pclock; - struct timespec64 ts = {}; - ptp->info->getcycles64(ptp->info, &ts); - - return timespec64_to_ns(&ts); + /* The cyclecounter callback cannot report a failed PHC read. */ + return vclock->cycles; } static const struct cyclecounter ptp_vclock_cc = { @@ -192,10 +225,11 @@ static const struct cyclecounter ptp_vclock_cc = { struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) { struct ptp_vclock *vclock; + int err; vclock = kzalloc_obj(*vclock); if (!vclock) - return NULL; + return ERR_PTR(-ENOMEM); vclock->pclock = pclock; vclock->info = ptp_vclock_info; @@ -214,20 +248,29 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) mutex_init(&vclock->lock); + err = ptp_vclock_sample(vclock); + if (err) + goto free_vclock; + timecounter_init(&vclock->tc, &vclock->cc, 0); + vclock->clock = ptp_clock_register(&vclock->info, &pclock->dev); - if (IS_ERR_OR_NULL(vclock->clock)) { - kfree(vclock); - return NULL; + if (IS_ERR(vclock->clock)) { + err = PTR_ERR(vclock->clock); + goto free_vclock; } ptp_vclock_set_subclass(vclock->clock); - timecounter_init(&vclock->tc, &vclock->cc, 0); - ptp_schedule_worker(vclock->clock, PTP_VCLOCK_REFRESH_INTERVAL); + /* The initial sample predates registration; refresh without more delay. */ + ptp_schedule_worker(vclock->clock, 0); ptp_vclock_hash_add(vclock); return vclock; + +free_vclock: + kfree(vclock); + return ERR_PTR(err); } void ptp_vclock_unregister(struct ptp_vclock *vclock) @@ -283,6 +326,8 @@ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index) u64 ns; ns = ktime_to_ns(*hwtstamp); + if (!ns) + return 0; srcu_idx = srcu_read_lock(&vclock_srcu); diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index bb0e14bac9f2ab..7f25fe6c2ce2a8 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -665,7 +665,7 @@ static int vmclock_probe(struct platform_device *pdev) struct vmclock_state *st; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c index 8ba7ef2c27d0e5..eadb11c28ad362 100644 --- a/drivers/pwm/pwm-dwc.c +++ b/drivers/pwm/pwm-dwc.c @@ -68,7 +68,7 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) pci_set_master(pci); info = (const struct dwc_pwm_info *)id->driver_data; - ddata = devm_kzalloc(dev, struct_size(ddata, chips, info->nr), GFP_KERNEL); + ddata = devm_kzalloc_flex(dev, *ddata, chips, info->nr); if (!ddata) return -ENOMEM; diff --git a/drivers/pwm/pwm-lp3943.c b/drivers/pwm/pwm-lp3943.c index e42af9007546e9..a8e34939ba2754 100644 --- a/drivers/pwm/pwm-lp3943.c +++ b/drivers/pwm/pwm-lp3943.c @@ -226,7 +226,7 @@ static int lp3943_pwm_parse_dt(struct device *dev, if (!node) return -EINVAL; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -240,8 +240,7 @@ static int lp3943_pwm_parse_dt(struct device *dev, if (num_outputs <= 0) continue; - output = devm_kcalloc(dev, num_outputs, sizeof(*output), - GFP_KERNEL); + output = devm_kzalloc_objs(dev, *output, num_outputs); if (!output) return -ENOMEM; @@ -250,7 +249,7 @@ static int lp3943_pwm_parse_dt(struct device *dev, if (err) return err; - pwm_map = devm_kzalloc(dev, sizeof(*pwm_map), GFP_KERNEL); + pwm_map = devm_kzalloc_obj(dev, *pwm_map); if (!pwm_map) return -ENOMEM; diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index e5c3cf594571d1..c1beacb26b4d85 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -602,8 +602,7 @@ static int sti_pwm_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(pc->cpt_clk), "failed to get PWM capture clock\n"); - pc->ddata = devm_kcalloc(dev, cpt_num_devs, - sizeof(*pc->ddata), GFP_KERNEL); + pc->ddata = devm_kzalloc_objs(dev, *pc->ddata, cpt_num_devs); if (!pc->ddata) return -ENOMEM; diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c index 4ccaaf7b70bfdb..2b28a5504f5e82 100644 --- a/drivers/ras/amd/fmpm.c +++ b/drivers/ras/amd/fmpm.c @@ -834,7 +834,7 @@ static int allocate_records(void) } } - spa_entries = kcalloc(spa_nr_entries, sizeof(u64), GFP_KERNEL); + spa_entries = kzalloc_objs(u64, spa_nr_entries); if (!spa_entries) { ret = -ENOMEM; goto out_free; diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index be6b72daa76f01..83a76b78e58cc7 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1210,6 +1210,7 @@ config REGULATOR_QCOM_SMD_RPM config REGULATOR_QCOM_SPMI tristate "Qualcomm SPMI regulator driver" depends on SPMI || COMPILE_TEST + select REGMAP_MMIO help If you say yes to this option, support will be included for the regulators found in Qualcomm SPMI PMICs. diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index 882b6e58e9110b..c2460f5904b92a 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -711,7 +711,7 @@ static int act8865_pmic_probe(struct i2c_client *client) return -EINVAL; } - act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); + act8865 = devm_kzalloc_obj(dev, struct act8865); if (!act8865) return -ENOMEM; diff --git a/drivers/regulator/act8945a-regulator.c b/drivers/regulator/act8945a-regulator.c index 5bbe2bce740eaf..7c9711b727751e 100644 --- a/drivers/regulator/act8945a-regulator.c +++ b/drivers/regulator/act8945a-regulator.c @@ -280,7 +280,7 @@ static int act8945a_pmic_probe(struct platform_device *pdev) int i, num_regulators; bool voltage_select; - act8945a = devm_kzalloc(&pdev->dev, sizeof(*act8945a), GFP_KERNEL); + act8945a = devm_kzalloc_obj(&pdev->dev, *act8945a); if (!act8945a) return -ENOMEM; diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 0123ca8157a881..0bdaa46532e0b3 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -222,7 +222,7 @@ static int ad5398_probe(struct i2c_client *client) const struct ad5398_current_data_format *df = (struct ad5398_current_data_format *)id->driver_data; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/adp5055-regulator.c b/drivers/regulator/adp5055-regulator.c index 194dcfe4f5279b..cb7314d57cc521 100644 --- a/drivers/regulator/adp5055-regulator.c +++ b/drivers/regulator/adp5055-regulator.c @@ -354,7 +354,7 @@ static int adp5055_probe(struct i2c_client *client) if (!init_data) return -EINVAL; - adp5055 = devm_kzalloc(dev, sizeof(struct adp5055), GFP_KERNEL); + adp5055 = devm_kzalloc_obj(dev, struct adp5055); if (!adp5055) return -ENOMEM; diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index 700bd0343196a1..04cbd41a95a40a 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -172,7 +172,7 @@ static int anatop_regulator_probe(struct platform_device *pdev) int ret = 0; u32 val; - sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); + sreg = devm_kzalloc_obj(dev, *sreg); if (!sreg) return -ENOMEM; diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c index 501843996faae1..ae4df04cbcbfe1 100644 --- a/drivers/regulator/arizona-ldo1.c +++ b/drivers/regulator/arizona-ldo1.c @@ -300,7 +300,7 @@ static int arizona_ldo1_probe(struct platform_device *pdev) bool external_dcvdd; int ret; - ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); + ldo1 = devm_kzalloc_obj(&pdev->dev, *ldo1); if (!ldo1) return -ENOMEM; @@ -354,7 +354,7 @@ static int madera_ldo1_probe(struct platform_device *pdev) bool external_dcvdd; int ret; - ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); + ldo1 = devm_kzalloc_obj(&pdev->dev, *ldo1); if (!ldo1) return -ENOMEM; diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c index be7208bc7409b6..5886b468ed5b70 100644 --- a/drivers/regulator/arizona-micsupp.c +++ b/drivers/regulator/arizona-micsupp.c @@ -306,7 +306,7 @@ static int arizona_micsupp_probe(struct platform_device *pdev) const struct regulator_desc *desc; struct arizona_micsupp *micsupp; - micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL); + micsupp = devm_kzalloc_obj(&pdev->dev, *micsupp); if (!micsupp) return -ENOMEM; @@ -342,7 +342,7 @@ static int madera_micsupp_probe(struct platform_device *pdev) struct madera *madera = dev_get_drvdata(pdev->dev.parent); struct arizona_micsupp *micsupp; - micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL); + micsupp = devm_kzalloc_obj(&pdev->dev, *micsupp); if (!micsupp) return -ENOMEM; diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index 85e2aaa1a06bd7..42e5fc54f95f55 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -642,8 +642,7 @@ static int as3722_regulator_probe(struct platform_device *pdev) int id; int ret; - as3722_regs = devm_kzalloc(&pdev->dev, sizeof(*as3722_regs), - GFP_KERNEL); + as3722_regs = devm_kzalloc_obj(&pdev->dev, *as3722_regs); if (!as3722_regs) return -ENOMEM; diff --git a/drivers/regulator/atc260x-regulator.c b/drivers/regulator/atc260x-regulator.c index 3e9f8fd54fca8f..f795330ef7416b 100644 --- a/drivers/regulator/atc260x-regulator.c +++ b/drivers/regulator/atc260x-regulator.c @@ -481,7 +481,7 @@ static int atc260x_regulator_probe(struct platform_device *pdev) bool atc2603c_ver_b = false; int i, nregulators; - atc260x_data = devm_kzalloc(&pdev->dev, sizeof(*atc260x_data), GFP_KERNEL); + atc260x_data = devm_kzalloc_obj(&pdev->dev, *atc260x_data); if (!atc260x_data) return -ENOMEM; diff --git a/drivers/regulator/aw37503-regulator.c b/drivers/regulator/aw37503-regulator.c index ca5f2a14c28c04..27a779e4cf504a 100644 --- a/drivers/regulator/aw37503-regulator.c +++ b/drivers/regulator/aw37503-regulator.c @@ -184,7 +184,7 @@ static int aw37503_probe(struct i2c_client *client) struct regulator_config config = { }; int id; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index ec6ec071ffdeef..e88da44aa2a0d4 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -1652,8 +1652,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) (regulators == axp803_regulators && i == AXP803_DC1SW) || (regulators == axp809_regulators && i == AXP809_DC1SW) || (regulators == axp15060_regulators && i == AXP15060_SW)) { - new_desc = devm_kzalloc(&pdev->dev, sizeof(*new_desc), - GFP_KERNEL); + new_desc = devm_kzalloc_obj(&pdev->dev, *new_desc); if (!new_desc) return -ENOMEM; @@ -1665,8 +1664,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) || (regulators == axp809_regulators && i == AXP809_DC5LDO) || (regulators == axp15060_regulators && i == AXP15060_CPUSLDO)) { - new_desc = devm_kzalloc(&pdev->dev, sizeof(*new_desc), - GFP_KERNEL); + new_desc = devm_kzalloc_obj(&pdev->dev, *new_desc); if (!new_desc) return -ENOMEM; @@ -1677,8 +1675,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) if (regulators == axp15060_regulators && i == AXP15060_RTC_LDO) { - new_desc = devm_kzalloc(&pdev->dev, sizeof(*new_desc), - GFP_KERNEL); + new_desc = devm_kzalloc_obj(&pdev->dev, *new_desc); if (!new_desc) return -ENOMEM; diff --git a/drivers/regulator/bcm590xx-regulator.c b/drivers/regulator/bcm590xx-regulator.c index 50414f4cb10958..1f82e204b58c02 100644 --- a/drivers/regulator/bcm590xx-regulator.c +++ b/drivers/regulator/bcm590xx-regulator.c @@ -1104,7 +1104,7 @@ static int bcm590xx_probe(struct platform_device *pdev) struct regulator_dev *rdev; unsigned int i; - pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL); + pmu = devm_kzalloc_obj(&pdev->dev, *pmu); if (!pmu) return -ENOMEM; diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c index 9cc29b9409d037..828b74ea35a6c2 100644 --- a/drivers/regulator/bd718x7-regulator.c +++ b/drivers/regulator/bd718x7-regulator.c @@ -1598,9 +1598,8 @@ static int setup_feedback_loop(struct device *dev, struct device_node *np, if (desc->n_linear_ranges && desc->linear_ranges) { struct linear_range *new; - new = devm_kcalloc(dev, desc->n_linear_ranges, - sizeof(struct linear_range), - GFP_KERNEL); + new = devm_kzalloc_objs(dev, struct linear_range, + desc->n_linear_ranges); if (!new) return -ENOMEM; diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c index 5bf02dc0d20e37..b52810abd050b0 100644 --- a/drivers/regulator/bd9571mwv-regulator.c +++ b/drivers/regulator/bd9571mwv-regulator.c @@ -279,7 +279,7 @@ static int bd9571mwv_regulator_probe(struct platform_device *pdev) int i; enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; - bdreg = devm_kzalloc(&pdev->dev, sizeof(*bdreg), GFP_KERNEL); + bdreg = devm_kzalloc_obj(&pdev->dev, *bdreg); if (!bdreg) return -ENOMEM; diff --git a/drivers/regulator/bd96801-regulator.c b/drivers/regulator/bd96801-regulator.c index 308279b31fd38b..e3aadfa003ee8d 100644 --- a/drivers/regulator/bd96801-regulator.c +++ b/drivers/regulator/bd96801-regulator.c @@ -1053,7 +1053,7 @@ static int initialize_pmic_data(struct platform_device *pdev, template = pdata->regulator_data[r].irq_desc.irqinfo; num_infos = pdata->regulator_data[r].irq_desc.num_irqs; - new = devm_kcalloc(dev, num_infos, sizeof(*new), GFP_KERNEL); + new = devm_kzalloc_objs(dev, *new, num_infos); if (!new) return -ENOMEM; diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c index 577b277efd7fc3..02221a82247177 100644 --- a/drivers/regulator/bq257xx-regulator.c +++ b/drivers/regulator/bq257xx-regulator.c @@ -147,7 +147,7 @@ static int bq257xx_regulator_probe(struct platform_device *pdev) device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent); - pdata = devm_kzalloc(&pdev->dev, sizeof(struct bq257xx_reg_data), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, struct bq257xx_reg_data); if (!pdata) return -ENOMEM; diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c index 63f5c90ddf50b7..de34f73dcc3283 100644 --- a/drivers/regulator/cpcap-regulator.c +++ b/drivers/regulator/cpcap-regulator.c @@ -613,7 +613,7 @@ static int cpcap_regulator_probe(struct platform_device *pdev) return -ENODEV; } - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/regulator/cros-ec-regulator.c b/drivers/regulator/cros-ec-regulator.c index aec275fe1f44f6..cfe464fe66869d 100644 --- a/drivers/regulator/cros-ec-regulator.c +++ b/drivers/regulator/cros-ec-regulator.c @@ -164,8 +164,7 @@ static int cros_ec_regulator_probe(struct platform_device *pdev) struct regulator_desc *desc; int ret; - drvdata = devm_kzalloc( - &pdev->dev, sizeof(struct cros_ec_regulator_data), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct cros_ec_regulator_data); if (!drvdata) return -ENOMEM; diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index fbebe538a648ee..6a09488173cb3b 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c @@ -398,8 +398,7 @@ static int da9052_regulator_probe(struct platform_device *pdev) struct da9052 *da9052; struct da9052_pdata *pdata; - regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9052_regulator), - GFP_KERNEL); + regulator = devm_kzalloc_obj(&pdev->dev, struct da9052_regulator); if (!regulator) return -ENOMEM; diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index a0d3414aa79e6b..21a444a357e8e0 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -513,8 +513,7 @@ static int da9055_regulator_probe(struct platform_device *pdev) struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); int ret, irq; - regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator), - GFP_KERNEL); + regulator = devm_kzalloc_obj(&pdev->dev, struct da9055_regulator); if (!regulator) return -ENOMEM; diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c index e0c96f10e570ce..21f6511ab9ba35 100644 --- a/drivers/regulator/da9062-regulator.c +++ b/drivers/regulator/da9062-regulator.c @@ -942,8 +942,8 @@ static int da9062_regulator_probe(struct platform_device *pdev) } /* Allocate memory required by usable regulators */ - regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, regulator, - max_regulators), GFP_KERNEL); + regulators = devm_kzalloc_flex(&pdev->dev, *regulators, regulator, + max_regulators); if (!regulators) return -ENOMEM; diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c index bf34ea440d77c0..4a2bf69b68cf58 100644 --- a/drivers/regulator/da9063-regulator.c +++ b/drivers/regulator/da9063-regulator.c @@ -857,7 +857,7 @@ static struct da9063_regulators_pdata *da9063_parse_regulators_dt( return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(&pdev->dev, struct_size(pdata, regulator_data, num), GFP_KERNEL); + pdata = devm_kzalloc_flex(&pdev->dev, *pdata, regulator_data, num); if (!pdata) return ERR_PTR(-ENOMEM); @@ -930,8 +930,8 @@ static int da9063_regulator_probe(struct platform_device *pdev) n_regulators--; /* remove BMEM_BIO_MERGED */ /* Allocate memory required by usable regulators */ - regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, - regulator, n_regulators), GFP_KERNEL); + regulators = devm_kzalloc_flex(&pdev->dev, *regulators, regulator, + n_regulators); if (!regulators) return -ENOMEM; diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c index f501cf8152c230..8fe9817f7a45c5 100644 --- a/drivers/regulator/da9121-regulator.c +++ b/drivers/regulator/da9121-regulator.c @@ -382,7 +382,7 @@ static int da9121_of_parse_cb(struct device_node *np, struct gpio_desc *ena_gpiod; if (chip->pdata == NULL) { - pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(chip->dev, *pdata); if (!pdata) return -ENOMEM; } else { @@ -1151,7 +1151,7 @@ static int da9121_i2c_probe(struct i2c_client *i2c) const int mask_all[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; int ret = 0; - chip = devm_kzalloc(&i2c->dev, sizeof(struct da9121), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct da9121); if (!chip) { ret = -ENOMEM; goto error; diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c index 9154e32bd74531..dd9e943b22a4ae 100644 --- a/drivers/regulator/da9210-regulator.c +++ b/drivers/regulator/da9210-regulator.c @@ -136,7 +136,7 @@ static int da9210_i2c_probe(struct i2c_client *i2c) struct regulator_config config = { }; int error; - chip = devm_kzalloc(&i2c->dev, sizeof(struct da9210), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct da9210); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c index 9cf71375563679..0b51acf10d4fca 100644 --- a/drivers/regulator/da9211-regulator.c +++ b/drivers/regulator/da9211-regulator.c @@ -302,7 +302,7 @@ static struct da9211_pdata *da9211_parse_regulators_dt( return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -450,7 +450,7 @@ static int da9211_i2c_probe(struct i2c_client *i2c) int error, ret; unsigned int data; - chip = devm_kzalloc(&i2c->dev, sizeof(struct da9211), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct da9211); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 615deba5d22c8c..62c67b9fd0cf0c 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -407,12 +407,11 @@ int devm_regulator_bulk_get_enable(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers; int i, ret; - devres = devm_kmalloc(dev, sizeof(*devres), GFP_KERNEL); + devres = devm_kmalloc_obj(dev, *devres); if (!devres) return -ENOMEM; - devres->consumers = devm_kcalloc(dev, num_consumers, sizeof(*consumers), - GFP_KERNEL); + devres->consumers = devm_kzalloc_objs(dev, *consumers, num_consumers); consumers = devres->consumers; if (!consumers) return -ENOMEM; diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c index 6557d8cbe98d2f..374cd1caa0582a 100644 --- a/drivers/regulator/fan53555.c +++ b/drivers/regulator/fan53555.c @@ -118,6 +118,7 @@ enum { }; enum { + SILERGY_SYM827 = 1, SILERGY_SYR82X = 8, SILERGY_SYR83X = 9, }; @@ -412,6 +413,10 @@ static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di) { /* Init voltage range and step */ switch (di->chip_id) { + case SILERGY_SYM827: + di->vsel_min = 600000; + di->vsel_step = 12500; + break; case SILERGY_SYR82X: case SILERGY_SYR83X: di->vsel_min = 712500; @@ -657,7 +662,7 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, int ret; u32 tmp; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -684,6 +689,9 @@ static const struct of_device_id __maybe_unused fan53555_dt_ids[] = { }, { .compatible = "rockchip,rk8602", .data = (void *)RK8602_VENDOR_ROCKCHIP + }, { + .compatible = "silergy,sym827", + .data = (void *)FAN53555_VENDOR_SILERGY, }, { .compatible = "silergy,syr827", .data = (void *)FAN53555_VENDOR_SILERGY, @@ -711,8 +719,7 @@ static int fan53555_regulator_probe(struct i2c_client *client) unsigned int val; int ret; - di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), - GFP_KERNEL); + di = devm_kzalloc_obj(&client->dev, struct fan53555_device_info); if (!di) return -ENOMEM; @@ -794,6 +801,9 @@ static const struct i2c_device_id fan53555_id[] = { }, { .name = "rk8602", .driver_data = RK8602_VENDOR_ROCKCHIP + }, { + .name = "sym827", + .driver_data = FAN53555_VENDOR_SILERGY }, { .name = "syr827", .driver_data = FAN53555_VENDOR_SILERGY diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index faa82f30eb1f13..c353bcc72da047 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -168,8 +168,7 @@ of_get_fixed_voltage_config(struct device *dev, struct device_node *np = dev->of_node; struct regulator_init_data *init_data; - config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), - GFP_KERNEL); + config = devm_kzalloc_obj(dev, struct fixed_voltage_config); if (!config) return ERR_PTR(-ENOMEM); @@ -229,8 +228,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) if (!pdev->dev.of_node && strcmp(pdev->name, "reg-fixed-voltage")) return -ENODEV; - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct fixed_voltage_data); if (!drvdata) return -ENOMEM; diff --git a/drivers/regulator/fp9931.c b/drivers/regulator/fp9931.c index ff743a8b0dfe80..da0f5dd87f2f23 100644 --- a/drivers/regulator/fp9931.c +++ b/drivers/regulator/fp9931.c @@ -407,7 +407,7 @@ static int fp9931_probe(struct i2c_client *client) int ret = 0; int i; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 6351ceefdb3e13..352a9385894ffe 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -136,9 +136,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, int ngpios; int ret; - config = devm_kzalloc(dev, - sizeof(struct gpio_regulator_config), - GFP_KERNEL); + config = devm_kzalloc_obj(dev, struct gpio_regulator_config); if (!config) return ERR_PTR(-ENOMEM); @@ -193,10 +191,8 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, return ERR_PTR(-EINVAL); } - config->states = devm_kcalloc(dev, - proplen / 2, - sizeof(struct gpio_regulator_state), - GFP_KERNEL); + config->states = devm_kzalloc_objs(dev, struct gpio_regulator_state, + proplen / 2); if (!config->states) return ERR_PTR(-ENOMEM); @@ -242,8 +238,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) enum gpiod_flags gflags; int ptr, state, i; - drvdata = devm_kzalloc(dev, sizeof(struct gpio_regulator_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct gpio_regulator_data); if (drvdata == NULL) return -ENOMEM; @@ -260,8 +255,8 @@ static int gpio_regulator_probe(struct platform_device *pdev) return -ENOMEM; } - drvdata->gpiods = devm_kcalloc(dev, config->ngpios, - sizeof(struct gpio_desc *), GFP_KERNEL); + drvdata->gpiods = devm_kzalloc_objs(dev, struct gpio_desc *, + config->ngpios); if (!drvdata->gpiods) return -ENOMEM; diff --git a/drivers/regulator/hi6421-regulator.c b/drivers/regulator/hi6421-regulator.c index 3373c4fdbddf3f..6a1894729dc733 100644 --- a/drivers/regulator/hi6421-regulator.c +++ b/drivers/regulator/hi6421-regulator.c @@ -544,7 +544,7 @@ static int hi6421_regulator_probe(struct platform_device *pdev) struct regulator_dev *rdev; int i; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; mutex_init(&pdata->lock); diff --git a/drivers/regulator/hi6421v600-regulator.c b/drivers/regulator/hi6421v600-regulator.c index c42858c93b47eb..52abea0b6c2050 100644 --- a/drivers/regulator/hi6421v600-regulator.c +++ b/drivers/regulator/hi6421v600-regulator.c @@ -250,7 +250,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) if (WARN_ON(!regmap)) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/irq_helpers.c b/drivers/regulator/irq_helpers.c index cdbd170d2b150a..c03625a19a8e7c 100644 --- a/drivers/regulator/irq_helpers.c +++ b/drivers/regulator/irq_helpers.c @@ -338,7 +338,7 @@ void *regulator_irq_helper(struct device *dev, if (!rdev_amount || !d || !d->map_event || !d->name) return ERR_PTR(-EINVAL); - h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL); + h = devm_kzalloc_obj(dev, *h); if (!h) return ERR_PTR(-ENOMEM); diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index 868f2b823a1076..819324033928b6 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c @@ -109,7 +109,7 @@ static int isl6271a_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - pmic = devm_kzalloc(&i2c->dev, sizeof(struct isl_pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&i2c->dev, struct isl_pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 6f830ae1bb613b..75d1ec20848361 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c @@ -412,7 +412,7 @@ static int lp3971_i2c_probe(struct i2c_client *i2c) return -ENODEV; } - lp3971 = devm_kzalloc(&i2c->dev, sizeof(struct lp3971), GFP_KERNEL); + lp3971 = devm_kzalloc_obj(&i2c->dev, struct lp3971); if (lp3971 == NULL) return -ENOMEM; diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index 235c640ba57f53..712b18d171cde1 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c @@ -507,7 +507,7 @@ static int lp3972_i2c_probe(struct i2c_client *i2c) return -ENODEV; } - lp3972 = devm_kzalloc(&i2c->dev, sizeof(struct lp3972), GFP_KERNEL); + lp3972 = devm_kzalloc_obj(&i2c->dev, struct lp3972); if (!lp3972) return -ENOMEM; diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c index 8b95c2cbb0237d..8887037c33f84d 100644 --- a/drivers/regulator/lp872x.c +++ b/drivers/regulator/lp872x.c @@ -611,7 +611,7 @@ static int lp872x_probe(struct i2c_client *cl) struct lp872x *lp; int ret; - lp = devm_kzalloc(dev, sizeof(*lp), GFP_KERNEL); + lp = devm_kzalloc_obj(dev, *lp); if (!lp) return -ENOMEM; diff --git a/drivers/regulator/lp8755.c b/drivers/regulator/lp8755.c index 632320ba18004f..0b5812e4edbb4a 100644 --- a/drivers/regulator/lp8755.c +++ b/drivers/regulator/lp8755.c @@ -367,8 +367,7 @@ static int lp8755_probe(struct i2c_client *client) return -EOPNOTSUPP; } - pchip = devm_kzalloc(&client->dev, - sizeof(struct lp8755_chip), GFP_KERNEL); + pchip = devm_kzalloc_obj(&client->dev, struct lp8755_chip); if (!pchip) return -ENOMEM; @@ -385,9 +384,8 @@ static int lp8755_probe(struct i2c_client *client) pchip->pdata = pdata; pchip->mphase = pdata->mphase; } else { - pchip->pdata = devm_kzalloc(pchip->dev, - sizeof(struct lp8755_platform_data), - GFP_KERNEL); + pchip->pdata = devm_kzalloc_obj(pchip->dev, + struct lp8755_platform_data); if (!pchip->pdata) return -ENOMEM; ret = lp8755_init_data(pchip); diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c index 2ade249ab6df33..a9bac86d89617f 100644 --- a/drivers/regulator/lp8788-buck.c +++ b/drivers/regulator/lp8788-buck.c @@ -486,7 +486,7 @@ static int lp8788_buck_probe(struct platform_device *pdev) if (id >= LP8788_NUM_BUCKS) return -EINVAL; - buck = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_buck), GFP_KERNEL); + buck = devm_kzalloc_obj(&pdev->dev, struct lp8788_buck); if (!buck) return -ENOMEM; diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c index 8e45b7b99556a6..64915ee00121b2 100644 --- a/drivers/regulator/lp8788-ldo.c +++ b/drivers/regulator/lp8788-ldo.c @@ -529,7 +529,7 @@ static int lp8788_dldo_probe(struct platform_device *pdev) struct regulator_dev *rdev; int ret; - ldo = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct lp8788_ldo); if (!ldo) return -ENOMEM; @@ -577,7 +577,7 @@ static int lp8788_aldo_probe(struct platform_device *pdev) struct regulator_dev *rdev; int ret; - ldo = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct lp8788_ldo); if (!ldo) return -ENOMEM; diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c index 8bae5d8aeaf4e7..6f54757333bbd1 100644 --- a/drivers/regulator/ltc3589.c +++ b/drivers/regulator/ltc3589.c @@ -383,7 +383,7 @@ static int ltc3589_probe(struct i2c_client *client) struct ltc3589 *ltc3589; int i, ret; - ltc3589 = devm_kzalloc(dev, sizeof(*ltc3589), GFP_KERNEL); + ltc3589 = devm_kzalloc_obj(dev, *ltc3589); if (!ltc3589) return -ENOMEM; diff --git a/drivers/regulator/ltc3676.c b/drivers/regulator/ltc3676.c index d67cee4e0be06c..010a13bff167c9 100644 --- a/drivers/regulator/ltc3676.c +++ b/drivers/regulator/ltc3676.c @@ -312,7 +312,7 @@ static int ltc3676_regulator_probe(struct i2c_client *client) struct ltc3676 *ltc3676; int i, ret; - ltc3676 = devm_kzalloc(dev, sizeof(*ltc3676), GFP_KERNEL); + ltc3676 = devm_kzalloc_obj(dev, *ltc3676); if (!ltc3676) return -ENOMEM; diff --git a/drivers/regulator/max14577-regulator.c b/drivers/regulator/max14577-regulator.c index cd592c5de14834..aea39c867353fc 100644 --- a/drivers/regulator/max14577-regulator.c +++ b/drivers/regulator/max14577-regulator.c @@ -300,8 +300,7 @@ static int max14577_regulator_probe(struct platform_device *pdev) supported_regulators[i].id == MAX77836_LDO2)) { struct max77836_ldo *ldo; - ldo = devm_kzalloc(&pdev->dev, sizeof(*ldo), - GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, *ldo); if (!ldo) return -ENOMEM; diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index e5cbc09c2d3960..6bb819681c4bf9 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c @@ -181,10 +181,8 @@ static int of_get_max1586_platform_data(struct device *dev, if (matched <= 0) return matched; - pdata->subdevs = devm_kcalloc(dev, - matched, - sizeof(struct max1586_subdev_data), - GFP_KERNEL); + pdata->subdevs = devm_kzalloc_objs(dev, struct max1586_subdev_data, + matched); if (!pdata->subdevs) return -ENOMEM; @@ -222,8 +220,7 @@ static int max1586_pmic_probe(struct i2c_client *client) pdata = &pdata_of; } - max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data), - GFP_KERNEL); + max1586 = devm_kzalloc_obj(&client->dev, struct max1586_data); if (!max1586) return -ENOMEM; diff --git a/drivers/regulator/max20086-regulator.c b/drivers/regulator/max20086-regulator.c index 92594b2915f3d0..8c3ba372d9400f 100644 --- a/drivers/regulator/max20086-regulator.c +++ b/drivers/regulator/max20086-regulator.c @@ -144,8 +144,8 @@ static int max20086_parse_regulators_dt(struct max20086 *chip, bool *boot_on) return -ENODEV; } - matches = devm_kcalloc(chip->dev, chip->info->num_outputs, - sizeof(*matches), GFP_KERNEL); + matches = devm_kzalloc_objs(chip->dev, *matches, + chip->info->num_outputs); if (!matches) return -ENOMEM; @@ -223,7 +223,7 @@ static int max20086_i2c_probe(struct i2c_client *i2c) bool boot_on; int ret; - chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/max20411-regulator.c b/drivers/regulator/max20411-regulator.c index ac7a9aa014aae9..01c920490573d9 100644 --- a/drivers/regulator/max20411-regulator.c +++ b/drivers/regulator/max20411-regulator.c @@ -103,7 +103,7 @@ static int max20411_probe(struct i2c_client *client) struct regulator_config cfg = {}; struct max20411 *max20411; - max20411 = devm_kzalloc(dev, sizeof(*max20411), GFP_KERNEL); + max20411 = devm_kzalloc_obj(dev, *max20411); if (!max20411) return -ENOMEM; diff --git a/drivers/regulator/max5970-regulator.c b/drivers/regulator/max5970-regulator.c index fc14177ddf5d2b..4393c036b1a76a 100644 --- a/drivers/regulator/max5970-regulator.c +++ b/drivers/regulator/max5970-regulator.c @@ -565,8 +565,8 @@ static int max597x_regulator_probe(struct platform_device *pdev) if (!regmap) return -EPROBE_DEFER; - rdevs = devm_kcalloc(&i2c->dev, MAX5970_NUM_SWITCHES, sizeof(struct regulator_dev *), - GFP_KERNEL); + rdevs = devm_kzalloc_objs(&i2c->dev, struct regulator_dev *, + MAX5970_NUM_SWITCHES); if (!rdevs) return -ENOMEM; @@ -579,8 +579,7 @@ static int max597x_regulator_probe(struct platform_device *pdev) for (i = 0; i < num_switches; i++) { data = - devm_kzalloc(&i2c->dev, sizeof(struct max5970_regulator), - GFP_KERNEL); + devm_kzalloc_obj(&i2c->dev, struct max5970_regulator); if (!data) return -ENOMEM; diff --git a/drivers/regulator/max77620-regulator.c b/drivers/regulator/max77620-regulator.c index 5099c372eea58d..8b42595ebb1cef 100644 --- a/drivers/regulator/max77620-regulator.c +++ b/drivers/regulator/max77620-regulator.c @@ -786,7 +786,7 @@ static int max77620_regulator_probe(struct platform_device *pdev) int ret = 0; int id; - pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c index 11b04a13f889a2..6b177897eececb 100644 --- a/drivers/regulator/max77650-regulator.c +++ b/drivers/regulator/max77650-regulator.c @@ -339,8 +339,8 @@ static int max77650_regulator_probe(struct platform_device *pdev) if (!dev->of_node) device_set_of_node_from_dev(dev, parent); - rdescs = devm_kcalloc(dev, MAX77650_REGULATOR_NUM_REGULATORS, - sizeof(*rdescs), GFP_KERNEL); + rdescs = devm_kzalloc_objs(dev, *rdescs, + MAX77650_REGULATOR_NUM_REGULATORS); if (!rdescs) return -ENOMEM; diff --git a/drivers/regulator/max77675-regulator.c b/drivers/regulator/max77675-regulator.c index 23b54b44f8b7d4..375ed94f62e268 100644 --- a/drivers/regulator/max77675-regulator.c +++ b/drivers/regulator/max77675-regulator.c @@ -968,7 +968,7 @@ static int max77675_regulator_probe(struct i2c_client *client) struct regulator_config config = {}; int i, ret; - maxreg = devm_kzalloc(&client->dev, sizeof(*maxreg), GFP_KERNEL); + maxreg = devm_kzalloc_obj(&client->dev, *maxreg); if (!maxreg) return -ENOMEM; diff --git a/drivers/regulator/max77686-regulator.c b/drivers/regulator/max77686-regulator.c index 3a0156f4d6e7e2..00aa3bec1dd0f9 100644 --- a/drivers/regulator/max77686-regulator.c +++ b/drivers/regulator/max77686-regulator.c @@ -487,8 +487,7 @@ static int max77686_pmic_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s\n", __func__); - max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), - GFP_KERNEL); + max77686 = devm_kzalloc_obj(&pdev->dev, struct max77686_data); if (!max77686) return -ENOMEM; diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c index 4c05cc9c4bd292..6ed32c4de09712 100644 --- a/drivers/regulator/max77802-regulator.c +++ b/drivers/regulator/max77802-regulator.c @@ -494,9 +494,7 @@ static int max77802_pmic_probe(struct platform_device *pdev) int i, val; struct regulator_config config = { }; - max77802 = devm_kzalloc(&pdev->dev, - sizeof(struct max77802_regulator_prv), - GFP_KERNEL); + max77802 = devm_kzalloc_obj(&pdev->dev, struct max77802_regulator_prv); if (!max77802) return -ENOMEM; diff --git a/drivers/regulator/max77826-regulator.c b/drivers/regulator/max77826-regulator.c index 8b60a9fcab44d2..bd4611e8de63bd 100644 --- a/drivers/regulator/max77826-regulator.c +++ b/drivers/regulator/max77826-regulator.c @@ -240,8 +240,7 @@ static int max77826_i2c_probe(struct i2c_client *client) struct regmap *regmap; int i; - info = devm_kzalloc(dev, sizeof(struct max77826_regulator_info), - GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct max77826_regulator_info); if (!info) return -ENOMEM; diff --git a/drivers/regulator/max77838-regulator.c b/drivers/regulator/max77838-regulator.c index 765756fdcf6e23..5e836477d9c15b 100644 --- a/drivers/regulator/max77838-regulator.c +++ b/drivers/regulator/max77838-regulator.c @@ -162,8 +162,7 @@ static int max77838_i2c_probe(struct i2c_client *client) struct regmap *regmap; int i; - info = devm_kzalloc(dev, sizeof(struct max77838_regulator_info), - GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct max77838_regulator_info); if (!info) return -ENOMEM; diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c index 2d17405242e70a..d02b9373ec4c69 100644 --- a/drivers/regulator/max8649.c +++ b/drivers/regulator/max8649.c @@ -155,8 +155,7 @@ static int max8649_regulator_probe(struct i2c_client *client) unsigned char data; int ret; - info = devm_kzalloc(&client->dev, sizeof(struct max8649_regulator_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, struct max8649_regulator_info); if (!info) return -ENOMEM; diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c index ede17099b72749..9bcecdc17c9874 100644 --- a/drivers/regulator/max8660.c +++ b/drivers/regulator/max8660.c @@ -338,10 +338,8 @@ static int max8660_pdata_from_dt(struct device *dev, if (matched <= 0) return matched; - pdata->subdevs = devm_kcalloc(dev, - matched, - sizeof(struct max8660_subdev_data), - GFP_KERNEL); + pdata->subdevs = devm_kzalloc_objs(dev, struct max8660_subdev_data, + matched); if (!pdata->subdevs) return -ENOMEM; @@ -401,7 +399,7 @@ static int max8660_probe(struct i2c_client *client) return -EINVAL; } - max8660 = devm_kzalloc(dev, sizeof(struct max8660), GFP_KERNEL); + max8660 = devm_kzalloc_obj(dev, struct max8660); if (!max8660) return -ENOMEM; diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c index e59aa7a3ee5460..a9f014eae4d610 100644 --- a/drivers/regulator/max8907-regulator.c +++ b/drivers/regulator/max8907-regulator.c @@ -287,7 +287,7 @@ static int max8907_regulator_probe(struct platform_device *pdev) if (ret) return ret; - pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&pdev->dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c index f8b91a5701f3e3..03988a37ff8c64 100644 --- a/drivers/regulator/max8952.c +++ b/drivers/regulator/max8952.c @@ -128,7 +128,7 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev) int ret; int i; - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, *pd); if (!pd) return NULL; @@ -194,8 +194,7 @@ static int max8952_pmic_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; - max8952 = devm_kzalloc(&client->dev, sizeof(struct max8952_data), - GFP_KERNEL); + max8952 = devm_kzalloc_obj(&client->dev, struct max8952_data); if (!max8952) return -ENOMEM; diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index 95062032dc7e30..1dd3a5afb52fd2 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -520,7 +520,7 @@ static struct max8973_regulator_platform_data *max8973_parse_dt( bool etr_enable; bool etr_sensitivity_high; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -606,7 +606,7 @@ static int max8973_probe(struct i2c_client *client) return -EIO; } - max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); + max = devm_kzalloc_obj(&client->dev, *max); if (!max) return -ENOMEM; diff --git a/drivers/regulator/max8997-regulator.c b/drivers/regulator/max8997-regulator.c index e48ba694a90659..22f28f2a0a5e95 100644 --- a/drivers/regulator/max8997-regulator.c +++ b/drivers/regulator/max8997-regulator.c @@ -897,9 +897,7 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, /* count the number of regulators to be supported in pmic */ pdata->num_regulators = of_get_child_count(regulators_np); - rdata = devm_kcalloc(&pdev->dev, - pdata->num_regulators, sizeof(*rdata), - GFP_KERNEL); + rdata = devm_kzalloc_objs(&pdev->dev, *rdata, pdata->num_regulators); if (!rdata) return -ENOMEM; @@ -999,8 +997,7 @@ static int max8997_pmic_probe(struct platform_device *pdev) return ret; } - max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), - GFP_KERNEL); + max8997 = devm_kzalloc_obj(&pdev->dev, struct max8997_data); if (!max8997) return -ENOMEM; diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 90651f4d18281d..281904f8b0a300 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c @@ -558,9 +558,7 @@ static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev, /* count the number of regulators to be supported in pmic */ pdata->num_regulators = of_get_child_count(regulators_np); - rdata = devm_kcalloc(iodev->dev, - pdata->num_regulators, sizeof(*rdata), - GFP_KERNEL); + rdata = devm_kzalloc_objs(iodev->dev, *rdata, pdata->num_regulators); if (!rdata) { of_node_put(regulators_np); return -ENOMEM; @@ -646,8 +644,7 @@ static int max8998_pmic_probe(struct platform_device *pdev) return ret; } - max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data), - GFP_KERNEL); + max8998 = devm_kzalloc_obj(&pdev->dev, struct max8998_data); if (!max8998) return -ENOMEM; diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index fb3aa1cec1f29f..b9df98b5e9c950 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c @@ -405,9 +405,7 @@ static int mc13783_regulator_probe(struct platform_device *pdev) if (num_regulators <= 0) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, regulators, num_regulators), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, regulators, num_regulators); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index b29cf6ba6f12ce..3b4ecf078a742d 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c @@ -543,9 +543,7 @@ static int mc13892_regulator_probe(struct platform_device *pdev) if (num_regulators <= 0) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, regulators, num_regulators), - GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, regulators, num_regulators); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c index 8ff19150ca9230..a8a1433cc48cd6 100644 --- a/drivers/regulator/mc13xxx-regulator-core.c +++ b/drivers/regulator/mc13xxx-regulator-core.c @@ -171,8 +171,7 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( if (!parent) return NULL; - data = devm_kcalloc(&pdev->dev, priv->num_regulators, sizeof(*data), - GFP_KERNEL); + data = devm_kzalloc_objs(&pdev->dev, *data, priv->num_regulators); if (!data) { of_node_put(parent); return NULL; diff --git a/drivers/regulator/mcp16502.c b/drivers/regulator/mcp16502.c index 07c67ad1ab7f27..7ccccc4f1c59bb 100644 --- a/drivers/regulator/mcp16502.c +++ b/drivers/regulator/mcp16502.c @@ -513,7 +513,7 @@ static int mcp16502_probe(struct i2c_client *client) dev = &client->dev; config.dev = dev; - mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL); + mcp = devm_kzalloc_obj(dev, *mcp); if (!mcp) return -ENOMEM; diff --git a/drivers/regulator/mp886x.c b/drivers/regulator/mp886x.c index e483e9d7dcf22e..58d25d58af8e90 100644 --- a/drivers/regulator/mp886x.c +++ b/drivers/regulator/mp886x.c @@ -319,7 +319,7 @@ static int mp886x_i2c_probe(struct i2c_client *client) u32 freq; int ret; - di = devm_kzalloc(dev, sizeof(struct mp886x_device_info), GFP_KERNEL); + di = devm_kzalloc_obj(dev, struct mp886x_device_info); if (!di) return -ENOMEM; diff --git a/drivers/regulator/mpq4210.c b/drivers/regulator/mpq4210.c index 293e7b209a987a..5befbf0c6da591 100644 --- a/drivers/regulator/mpq4210.c +++ b/drivers/regulator/mpq4210.c @@ -173,8 +173,7 @@ static int mpq4210_i2c_probe(struct i2c_client *client) r[0], r[1]); desc->uV_step = mpq4210_scale(MPQ4210_REF_STEP_UV, r[0], r[1]); - slew = devm_kcalloc(dev, ARRAY_SIZE(mpq4210_ref_slew_rate), - sizeof(*slew), GFP_KERNEL); + slew = devm_kzalloc_objs(dev, *slew, ARRAY_SIZE(mpq4210_ref_slew_rate)); if (!slew) return -ENOMEM; diff --git a/drivers/regulator/mpq7920.c b/drivers/regulator/mpq7920.c index 0cbc17deb1d16d..eb1808f537f932 100644 --- a/drivers/regulator/mpq7920.c +++ b/drivers/regulator/mpq7920.c @@ -268,8 +268,7 @@ static int mpq7920_i2c_probe(struct i2c_client *client) struct regmap *regmap; int i; - info = devm_kzalloc(dev, sizeof(struct mpq7920_regulator_info), - GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct mpq7920_regulator_info); if (!info) return -ENOMEM; diff --git a/drivers/regulator/mt6315-regulator.c b/drivers/regulator/mt6315-regulator.c index 231e64fb059638..6603daa3d92670 100644 --- a/drivers/regulator/mt6315-regulator.c +++ b/drivers/regulator/mt6315-regulator.c @@ -227,11 +227,11 @@ static int mt6315_regulator_probe(struct spmi_device *pdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - chip = devm_kzalloc(dev, sizeof(struct mt6315_chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, struct mt6315_chip); if (!chip) return -ENOMEM; - init_data = devm_kzalloc(dev, sizeof(struct mt_regulator_init_data), GFP_KERNEL); + init_data = devm_kzalloc_obj(dev, struct mt_regulator_init_data); if (!init_data) return -ENOMEM; diff --git a/drivers/regulator/mt6359-regulator.c b/drivers/regulator/mt6359-regulator.c index 7c3a3ecb36413a..4363fe4903c228 100644 --- a/drivers/regulator/mt6359-regulator.c +++ b/drivers/regulator/mt6359-regulator.c @@ -1075,7 +1075,7 @@ static int mt6359_regulator_probe(struct platform_device *pdev) /* Use vio18's actual name as supply_name for vbbck */ if (i == MT6359_ID_VBBCK && strcmp(desc->supply_name, vio18_name) != 0) { - _desc = devm_kzalloc(&pdev->dev, sizeof(*_desc), GFP_KERNEL); + _desc = devm_kzalloc_obj(&pdev->dev, *_desc); if (!_desc) return -ENOMEM; @@ -1087,7 +1087,7 @@ static int mt6359_regulator_probe(struct platform_device *pdev) /* Use vcn33_1's actual name as supply_name for vcn33_1_(bt|wifi) */ if ((i == MT6359_ID_VCN33_1_BT || i == MT6359_ID_VCN33_1_WIFI) && strcmp(desc->supply_name, vcn33_1_name) != 0) { - _desc = devm_kzalloc(&pdev->dev, sizeof(*_desc), GFP_KERNEL); + _desc = devm_kzalloc_obj(&pdev->dev, *_desc); if (!_desc) return -ENOMEM; @@ -1099,7 +1099,7 @@ static int mt6359_regulator_probe(struct platform_device *pdev) /* Use vcn33_2's actual name as supply_name for vcn33_2_(bt|wifi) */ if ((i == MT6359_ID_VCN33_2_BT || i == MT6359_ID_VCN33_2_WIFI) && strcmp(desc->supply_name, vcn33_2_name) != 0) { - _desc = devm_kzalloc(&pdev->dev, sizeof(*_desc), GFP_KERNEL); + _desc = devm_kzalloc_obj(&pdev->dev, *_desc); if (!_desc) return -ENOMEM; diff --git a/drivers/regulator/mt6360-regulator.c b/drivers/regulator/mt6360-regulator.c index ed25e9603b2b4c..5ebeb4d4e19d50 100644 --- a/drivers/regulator/mt6360-regulator.c +++ b/drivers/regulator/mt6360-regulator.c @@ -408,7 +408,7 @@ static int mt6360_regulator_probe(struct platform_device *pdev) struct regulator_config config = {}; int i, ret; - mrd = devm_kzalloc(&pdev->dev, sizeof(*mrd), GFP_KERNEL); + mrd = devm_kzalloc_obj(&pdev->dev, *mrd); if (!mrd) return -ENOMEM; diff --git a/drivers/regulator/mt6363-regulator.c b/drivers/regulator/mt6363-regulator.c index aa6a8eb7ac4b44..e6c4bd851fef54 100644 --- a/drivers/regulator/mt6363-regulator.c +++ b/drivers/regulator/mt6363-regulator.c @@ -4,7 +4,6 @@ // Copyright (c) 2025 Collabora Ltd // AngeloGioacchino Del Regno -#include #include #include #include @@ -147,7 +146,7 @@ struct mt6363_regulator_info { } #define MT6363_LDO_LINEAR_OPS(match, vreg, in_sup, vops, min, max, \ - step, buck_reg, ocp_intn) \ + step, en_reg, lp_reg, ocp_intn) \ [MT6363_ID_##vreg] = { \ .desc = { \ .name = match, \ @@ -160,13 +159,13 @@ struct mt6363_regulator_info { .n_voltages = (max - min) / step + 1, \ .min_uV = min, \ .uV_step = step, \ - .enable_reg = MT6363_RG_##buck_reg##_EN_ADDR, \ + .enable_reg = en_reg, \ .enable_mask = BIT(MT6363_RG_LDO_##vreg##_EN_BIT), \ .vsel_reg = MT6363_RG_LDO_##vreg##_VOSEL_ADDR, \ .vsel_mask = MT6363_RG_LDO_##vreg##_VOSEL_MASK, \ .of_map_mode = mt6363_map_mode, \ }, \ - .lp_mode_reg = MT6363_RG_##buck_reg##_LP_ADDR, \ + .lp_mode_reg = lp_reg, \ .lp_mode_mask = BIT(MT6363_RG_LDO_##vreg##_LP_BIT), \ .hw_lp_mode_reg = MT6363_LDO_##vreg##_HW_LP_MODE, \ .hw_lp_mode_mask = 0x4, \ @@ -176,12 +175,15 @@ struct mt6363_regulator_info { #define MT6363_LDO_L_SC(match, vreg, inp, min, max, step, buck_reg, \ ocp_intn) \ MT6363_LDO_LINEAR_OPS(match, vreg, inp, mt6363_vreg_setclr_ops, \ - min, max, step, buck_reg, ocp_intn) + min, max, step, \ + MT6363_RG_##buck_reg##_EN_ADDR, \ + MT6363_RG_##buck_reg##_LP_ADDR, ocp_intn) -#define MT6363_LDO_L(match, vreg, inp, min, max, step, buck_reg, \ - ocp_intn) \ +#define MT6363_LDO_L(match, vreg, inp, min, max, step, ocp_intn) \ MT6363_LDO_LINEAR_OPS(match, vreg, inp, mt6363_ldo_linear_ops, \ - min, max, step, buck_reg, ocp_intn) + min, max, step, \ + MT6363_RG_LDO_##vreg##_ADDR, \ + MT6363_RG_LDO_##vreg##_ADDR, ocp_intn) #define MT6363_LDO_LINEAR_CAL_OPS(match, vreg, in_sup, vops, vrnum, \ ocp_intn) \ @@ -381,7 +383,7 @@ static unsigned int mt6363_regulator_get_mode(struct regulator_dev *rdev) static int mt6363_buck_unlock(struct regmap *map, bool unlock) { - u16 buf = unlock ? MT6363_BUCK_TOP_UNLOCK_VALUE : 0; + __le16 buf = cpu_to_le16(unlock ? MT6363_BUCK_TOP_UNLOCK_VALUE : 0); return regmap_bulk_write(map, MT6363_BUCK_TOP_KEY_PROT_LO, &buf, sizeof(buf)); } @@ -482,31 +484,9 @@ static int mt6363_regulator_set_load(struct regulator_dev *rdev, int load_uA) static int mt6363_vemc_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel) { - const u16 tma_unlock_key = MT6363_TMA_UNLOCK_VALUE; - const struct regulator_desc *rdesc = rdev->desc; - struct regmap *regmap = rdev->regmap; - unsigned int range, val; - int i, ret; - u16 mask; - - for (i = 0; i < rdesc->n_linear_ranges; i++) { - const struct linear_range *r = &rdesc->linear_ranges[i]; - unsigned int voltages_in_range = linear_range_values_in_range(r); - - if (sel < voltages_in_range) - break; - sel -= voltages_in_range; - } - - if (i == rdesc->n_linear_ranges) - return -EINVAL; - - ret = regmap_read(rdev->regmap, MT6363_TOP_TRAP, &val); - if (ret) - return ret; - - if (val > 1) - return -EINVAL; + const __le16 tma_unlock_key = cpu_to_le16(MT6363_TMA_UNLOCK_VALUE); + const __le16 tma_lock_key = cpu_to_le16(0); + int ret; /* Unlock TMA for writing */ ret = regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L, @@ -514,76 +494,15 @@ static int mt6363_vemc_set_voltage_sel(struct regulator_dev *rdev, unsigned int if (ret) return ret; - /* If HW trapping value is 1, use VEMC_VOSEL_1 instead of VEMC_VOSEL_0 */ - if (val == 1) { - mask = MT6363_RG_VEMC_VOSEL_1_MASK; - sel = FIELD_PREP(MT6363_RG_VEMC_VOSEL_1_MASK, sel); - } else { - mask = rdesc->vsel_mask; - } - - sel <<= ffs(rdesc->vsel_mask) - 1; - sel += rdesc->linear_ranges[i].min_sel; - - range = rdesc->linear_range_selectors_bitfield[i]; - range <<= ffs(rdesc->vsel_range_mask) - 1; - - /* Write to the vreg calibration register for voltage finetuning */ - ret = regmap_update_bits(regmap, rdesc->vsel_range_reg, - rdesc->vsel_range_mask, range); - if (ret) - goto lock_tma; - - /* Function must return the result of this write operation */ - ret = regmap_update_bits(regmap, rdesc->vsel_reg, mask, sel); + ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel); -lock_tma: /* Unconditionally re-lock TMA */ - val = 0; - regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L, &val, 2); + regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L, + &tma_lock_key, sizeof(tma_lock_key)); return ret; } -static int mt6363_vemc_get_voltage_sel(struct regulator_dev *rdev) -{ - const struct regulator_desc *rdesc = rdev->desc; - unsigned int vosel, trap, calsel; - int vcal, vsel, range, ret; - - ret = regmap_read(rdev->regmap, rdesc->vsel_reg, &vosel); - if (ret) - return ret; - - ret = regmap_read(rdev->regmap, rdesc->vsel_range_reg, &calsel); - if (ret) - return ret; - - calsel &= rdesc->vsel_range_mask; - for (range = 0; range < rdesc->n_linear_ranges; range++) - if (rdesc->linear_range_selectors_bitfield[range] != calsel) - break; - - if (range == rdesc->n_linear_ranges) - return -EINVAL; - - ret = regmap_read(rdev->regmap, MT6363_TOP_TRAP, &trap); - if (ret) - return ret; - - /* If HW trapping value is 1, use VEMC_VOSEL_1 instead of VEMC_VOSEL_0 */ - if (trap > 1) - return -EINVAL; - else if (trap == 1) - vsel = FIELD_GET(MT6363_RG_VEMC_VOSEL_1_MASK, vosel); - else - vsel = vosel & rdesc->vsel_mask; - - vcal = linear_range_values_in_range_array(rdesc->linear_ranges, range); - - return vsel + vcal; -} - static int mt6363_va15_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel) { struct regmap *regmap = rdev->regmap; @@ -696,7 +615,7 @@ static const struct regulator_ops mt6363_ldo_vemc_ops = { .list_voltage = regulator_list_voltage_pickable_linear_range, .map_voltage = regulator_map_voltage_pickable_linear_range, .set_voltage_sel = mt6363_vemc_set_voltage_sel, - .get_voltage_sel = mt6363_vemc_get_voltage_sel, + .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, .set_voltage_time_sel = regulator_set_voltage_time_sel, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, @@ -754,10 +673,10 @@ static struct mt6363_regulator_info mt6363_regulators[] = { MT6363_LDO_VT("vio0p75", VIO075, "vs1-ldo1", 5, 36), MT6363_LDO_VT("vio18", VIO18, "vs1-ldo2", 3, 35), MT6363_LDO_VT("vm18", VM18, "vs1-ldo1", 4, 40), - MT6363_LDO_L("vsram-apu", VSRAM_APU, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 30), - MT6363_LDO_L("vsram-cpub", VSRAM_CPUB, "vs2-ldo1", 400000, 1193750, 6250, BUCK1, 27), - MT6363_LDO_L("vsram-cpum", VSRAM_CPUM, "vs2-ldo1", 400000, 1193750, 6250, BUCK1, 28), - MT6363_LDO_L("vsram-cpul", VSRAM_CPUL, "vs2-ldo2", 400000, 1193750, 6250, BUCK1, 29), + MT6363_LDO_L("vsram-apu", VSRAM_APU, "vs3-ldo1", 400000, 1193750, 6250, 30), + MT6363_LDO_L("vsram-cpub", VSRAM_CPUB, "vs2-ldo1", 400000, 1193750, 6250, 27), + MT6363_LDO_L("vsram-cpum", VSRAM_CPUM, "vs2-ldo1", 400000, 1193750, 6250, 28), + MT6363_LDO_L("vsram-cpul", VSRAM_CPUL, "vs2-ldo2", 400000, 1193750, 6250, 29), MT6363_LDO_L_SC("vsram-digrf", VSRAM_DIGRF, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 23), MT6363_LDO_L_SC("vsram-mdfe", VSRAM_MDFE, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 24), MT6363_LDO_L_SC("vsram-modem", VSRAM_MODEM, "vs3-ldo2", 400000, 1193750, 6250, BUCK1, 25), @@ -793,6 +712,30 @@ static int mt6363_backup_op_setting(struct regmap *map, struct mt6363_regulator_ return 0; } +static int mt6363_vemc_select_bank(struct regmap *map, struct regulator_desc *desc) +{ + unsigned int trap; + int ret; + + ret = regmap_read(map, MT6363_TOP_TRAP, &trap); + if (ret) + return ret; + + /* The hardware trap value selects which VEMC voltage controls are used */ + switch (trap) { + case 0: + desc->vsel_reg = MT6363_RG_VEMC_VOCAL_ADDR; + desc->vsel_range_mask = MT6363_RG_VEMC_VOSEL_MASK; + return 0; + case 1: + desc->vsel_reg = MT6363_RG_VEMC_VOCAL_1_ADDR; + desc->vsel_range_mask = MT6363_RG_VEMC_VOSEL_1_MASK; + return 0; + default: + return -EINVAL; + } +} + static void mt6363_irq_remove(void *data) { int *virq = data; @@ -811,7 +754,7 @@ static struct regmap *mt6363_spmi_register_regmap(struct device *dev) { struct regmap_config mt6363_regmap_config = { .reg_bits = 16, - .val_bits = 16, + .val_bits = 8, .max_register = 0x1f90, .fast_io = true, }; @@ -877,6 +820,11 @@ static int mt6363_regulator_probe(struct platform_device *pdev) */ regmap_read(config.regmap, MT6363_TOP_TRAP, &val); + ret = mt6363_vemc_select_bank(config.regmap, + &mt6363_regulators[MT6363_ID_VEMC].desc); + if (ret) + return dev_err_probe(dev, ret, "Failed to select VEMC bank\n"); + interrupt_parent = of_irq_find_parent(dev->of_node); if (!interrupt_parent) return dev_err_probe(dev, -EINVAL, "Cannot find IRQ parent\n"); diff --git a/drivers/regulator/mt6370-regulator.c b/drivers/regulator/mt6370-regulator.c index 6997beb51409fd..2447be34e8f829 100644 --- a/drivers/regulator/mt6370-regulator.c +++ b/drivers/regulator/mt6370-regulator.c @@ -350,7 +350,7 @@ static int mt6370_regulator_probe(struct platform_device *pdev) struct mt6370_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 09e26febfc834e..81d4f8b6458b94 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -355,7 +355,7 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, if (!node) return NULL; - init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL); + init_data = devm_kzalloc_obj(dev, *init_data); if (!init_data) return NULL; /* Out of memory? */ diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index f82618a7010617..cbc5289def33b3 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c @@ -1496,7 +1496,7 @@ static int palmas_dt_to_pdata(struct device *dev, if (!match->init_data || !np) continue; - rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL); + rinit = devm_kzalloc_obj(dev, *rinit); if (!rinit) return -ENOMEM; @@ -1608,11 +1608,11 @@ static int palmas_regulators_probe(struct platform_device *pdev) if (!driver_data) return -ENODATA; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; - pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&pdev->dev, *pmic); if (!pmic) return -ENOMEM; diff --git a/drivers/regulator/pbias-regulator.c b/drivers/regulator/pbias-regulator.c index cd5a0d7e44555f..c630465e8825dc 100644 --- a/drivers/regulator/pbias-regulator.c +++ b/drivers/regulator/pbias-regulator.c @@ -162,7 +162,7 @@ static int pbias_regulator_probe(struct platform_device *pdev) if (count < 0) return count; - desc = devm_kcalloc(&pdev->dev, count, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_objs(&pdev->dev, *desc, count); if (!desc) return -ENOMEM; diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c index 613bce411f3198..f1c787e6db8bfd 100644 --- a/drivers/regulator/pca9450-regulator.c +++ b/drivers/regulator/pca9450-regulator.c @@ -1356,7 +1356,7 @@ static int pca9450_i2c_probe(struct i2c_client *i2c) const char *type_name; int ret; - pca9450 = devm_kzalloc(&i2c->dev, sizeof(struct pca9450), GFP_KERNEL); + pca9450 = devm_kzalloc_obj(&i2c->dev, struct pca9450); if (!pca9450) return -ENOMEM; diff --git a/drivers/regulator/pf0900-regulator.c b/drivers/regulator/pf0900-regulator.c index 5c44d2dbcab4d6..c8fbe150a6744f 100644 --- a/drivers/regulator/pf0900-regulator.c +++ b/drivers/regulator/pf0900-regulator.c @@ -837,7 +837,7 @@ static int pf0900_i2c_probe(struct i2c_client *i2c) if (!i2c->irq) return dev_err_probe(&i2c->dev, -EINVAL, "No IRQ configured?\n"); - pf0900 = devm_kzalloc(&i2c->dev, sizeof(struct pf0900), GFP_KERNEL); + pf0900 = devm_kzalloc_obj(&i2c->dev, struct pf0900); if (!pf0900) return -ENOMEM; diff --git a/drivers/regulator/pf1550-regulator.c b/drivers/regulator/pf1550-regulator.c index 84f8b187a91bf5..6a2fa00a022017 100644 --- a/drivers/regulator/pf1550-regulator.c +++ b/drivers/regulator/pf1550-regulator.c @@ -357,7 +357,7 @@ static int pf1550_regulator_probe(struct platform_device *pdev) struct pf1550_regulator_info *info; int i, irq = -1, ret = 0; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/regulator/pf530x-regulator.c b/drivers/regulator/pf530x-regulator.c index 8ad1cbbd7a8c4f..cbc6b4303fc103 100644 --- a/drivers/regulator/pf530x-regulator.c +++ b/drivers/regulator/pf530x-regulator.c @@ -308,7 +308,7 @@ static int pf530x_i2c_probe(struct i2c_client *client) struct regulator_dev *rdev; struct regulator_init_data *init_data; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/pf8x00-regulator.c b/drivers/regulator/pf8x00-regulator.c index c938b4632ef165..fa3aa4ae391e68 100644 --- a/drivers/regulator/pf8x00-regulator.c +++ b/drivers/regulator/pf8x00-regulator.c @@ -549,7 +549,7 @@ static int pf8x00_i2c_probe(struct i2c_client *client) int id; int ret; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/pf9453-regulator.c b/drivers/regulator/pf9453-regulator.c index 07cbcd312653b8..88a24b40b721ea 100644 --- a/drivers/regulator/pf9453-regulator.c +++ b/drivers/regulator/pf9453-regulator.c @@ -771,7 +771,7 @@ static int pf9453_i2c_probe(struct i2c_client *i2c) if (!i2c->irq) return dev_err_probe(&i2c->dev, -EINVAL, "No IRQ configured?\n"); - pf9453 = devm_kzalloc(&i2c->dev, sizeof(struct pf9453), GFP_KERNEL); + pf9453 = devm_kzalloc_obj(&i2c->dev, struct pf9453); if (!pf9453) return -ENOMEM; diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index d3a0e250552488..3535a5941099c5 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -713,8 +713,7 @@ static int pfuze100_regulator_probe(struct i2c_client *client) u32 regulator_num; u32 sw_check_start, sw_check_end, sw_hi = 0x40; - pfuze_chip = devm_kzalloc(&client->dev, sizeof(*pfuze_chip), - GFP_KERNEL); + pfuze_chip = devm_kzalloc_obj(&client->dev, *pfuze_chip); if (!pfuze_chip) return -ENOMEM; diff --git a/drivers/regulator/pv88060-regulator.c b/drivers/regulator/pv88060-regulator.c index 375d9e759c4753..94c7eefa0da93c 100644 --- a/drivers/regulator/pv88060-regulator.c +++ b/drivers/regulator/pv88060-regulator.c @@ -280,7 +280,7 @@ static int pv88060_i2c_probe(struct i2c_client *i2c) struct regulator_config config = { }; int error, i, ret = 0; - chip = devm_kzalloc(&i2c->dev, sizeof(struct pv88060), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct pv88060); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/pv88080-regulator.c b/drivers/regulator/pv88080-regulator.c index 1f2c405fd2bdec..acc4633df48cc7 100644 --- a/drivers/regulator/pv88080-regulator.c +++ b/drivers/regulator/pv88080-regulator.c @@ -368,7 +368,7 @@ static int pv88080_i2c_probe(struct i2c_client *i2c) int i, error, ret; unsigned int conf2, conf5; - chip = devm_kzalloc(&i2c->dev, sizeof(struct pv88080), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct pv88080); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/pv88090-regulator.c b/drivers/regulator/pv88090-regulator.c index ca5eeb5dfe6210..5821014829f4b8 100644 --- a/drivers/regulator/pv88090-regulator.c +++ b/drivers/regulator/pv88090-regulator.c @@ -274,7 +274,7 @@ static int pv88090_i2c_probe(struct i2c_client *i2c) int error, i, ret = 0; unsigned int conf2, range, index; - chip = devm_kzalloc(&i2c->dev, sizeof(struct pv88090), GFP_KERNEL); + chip = devm_kzalloc_obj(&i2c->dev, struct pv88090); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index 7434b6b22d3253..af4aafeb96b699 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -361,7 +361,7 @@ static int pwm_regulator_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, -EINVAL, "Device Tree node missing\n"); - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c index 1b14015caca635..8641e69b55c38f 100644 --- a/drivers/regulator/qcom-labibb-regulator.c +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -799,8 +799,7 @@ static int qcom_labibb_regulator_probe(struct platform_device *pdev) WARN_ON(type != reg_data->type)) return -EINVAL; - vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), - GFP_KERNEL); + vreg = devm_kzalloc_obj(&pdev->dev, *vreg); if (!vreg) return -ENOMEM; diff --git a/drivers/regulator/qcom-pm8008-regulator.c b/drivers/regulator/qcom-pm8008-regulator.c index 9c9b8be2e15a49..c1ebe5a0b50024 100644 --- a/drivers/regulator/qcom-pm8008-regulator.c +++ b/drivers/regulator/qcom-pm8008-regulator.c @@ -127,7 +127,7 @@ static int pm8008_regulator_probe(struct platform_device *pdev) for (i = 0; i < ARRAY_SIZE(pm8008_reg_data); i++) { data = &pm8008_reg_data[i]; - preg = devm_kzalloc(dev, sizeof(*preg), GFP_KERNEL); + preg = devm_kzalloc_obj(dev, *preg); if (!preg) return -ENOMEM; diff --git a/drivers/regulator/qcom-refgen-regulator.c b/drivers/regulator/qcom-refgen-regulator.c index cc72e5a43ba62a..aeacd44de6f824 100644 --- a/drivers/regulator/qcom-refgen-regulator.c +++ b/drivers/regulator/qcom-refgen-regulator.c @@ -197,7 +197,7 @@ static int qcom_refgen_probe(struct platform_device *pdev) return -ENODATA; if (data->has_clocks) { - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/regulator/qcom-rpmh-regulator.c b/drivers/regulator/qcom-rpmh-regulator.c index 4c90d206e63bc1..08e39499be8682 100644 --- a/drivers/regulator/qcom-rpmh-regulator.c +++ b/drivers/regulator/qcom-rpmh-regulator.c @@ -1952,7 +1952,7 @@ static int rpmh_regulator_probe(struct platform_device *pdev) } for_each_available_child_of_node_scoped(dev->of_node, node) { - vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); + vreg = devm_kzalloc_obj(dev, *vreg); if (!vreg) return -ENOMEM; diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c index 23ed594b574e36..6292a1643fb517 100644 --- a/drivers/regulator/qcom_smd-regulator.c +++ b/drivers/regulator/qcom_smd-regulator.c @@ -1511,7 +1511,7 @@ static int rpm_reg_probe(struct platform_device *pdev) return -ENODEV; for_each_available_child_of_node_scoped(dev->of_node, node) { - vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); + vreg = devm_kzalloc_obj(&pdev->dev, *vreg); if (!vreg) return -ENOMEM; diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index c1a41ce70b3639..5624a93f0edaf1 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c @@ -12,13 +12,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include /* Pin control enable input pins. */ @@ -1335,6 +1335,14 @@ static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data) static struct regmap *saw_regmap; +static const struct regmap_config saw_regmap_config = { + .name = "saw", + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .use_raw_spinlock = true, +}; + static void spmi_saw_set_vdd(void *data) { u32 vctl, data3, avs_ctl, pmic_sts; @@ -2504,12 +2512,13 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) const char *name; struct device *dev = &pdev->dev; struct device_node *node = pdev->dev.of_node; - struct device_node *syscon, *reg_node; + struct device_node *saw, *reg_node; + void __iomem *saw_base; struct property *reg_prop; int ret, lenp; struct list_head *vreg_list; - vreg_list = devm_kzalloc(dev, sizeof(*vreg_list), GFP_KERNEL); + vreg_list = devm_kzalloc_obj(dev, *vreg_list); if (!vreg_list) return -ENOMEM; INIT_LIST_HEAD(vreg_list); @@ -2523,12 +2532,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) if (!reg) return -ENODEV; - syscon = of_parse_phandle(node, "qcom,saw-reg", 0); - if (syscon) { - saw_regmap = syscon_node_to_regmap(syscon); - of_node_put(syscon); - if (IS_ERR(saw_regmap)) - dev_err(dev, "ERROR reading SAW regmap\n"); + saw = of_parse_phandle(node, "qcom,saw-reg", 0); + if (saw) { + saw_base = devm_of_iomap(dev, saw, 0, NULL); + of_node_put(saw); + if (IS_ERR(saw_base)) + return dev_err_probe(dev, PTR_ERR(saw_base), + "failed to map the SAW\n"); + + saw_regmap = devm_regmap_init_mmio(dev, saw_base, + &saw_regmap_config); + if (IS_ERR(saw_regmap)) { + ret = PTR_ERR(saw_regmap); + saw_regmap = NULL; + return dev_err_probe(dev, ret, + "failed to set the SAW regmap up\n"); + } } for (; reg->name; reg++) { @@ -2542,7 +2561,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) continue; } - vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); + vreg = devm_kzalloc_obj(dev, *vreg); if (!vreg) return -ENOMEM; diff --git a/drivers/regulator/qcom_usb_vbus-regulator.c b/drivers/regulator/qcom_usb_vbus-regulator.c index 9aea68876284e5..d909a6f2b7f14b 100644 --- a/drivers/regulator/qcom_usb_vbus-regulator.c +++ b/drivers/regulator/qcom_usb_vbus-regulator.c @@ -116,7 +116,7 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) return -ENOENT; } - rdesc = devm_kzalloc(dev, sizeof(*rdesc), GFP_KERNEL); + rdesc = devm_kzalloc_obj(dev, *rdesc); if (!rdesc) return -ENOMEM; diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c index 1e956153427e54..3e51a758cc4773 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -2120,7 +2120,7 @@ static int rk808_regulator_probe(struct platform_device *pdev) if (!regmap) return -ENODEV; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/regulator/rpi-panel-attiny-regulator.c b/drivers/regulator/rpi-panel-attiny-regulator.c index 77da916852e1b9..3e09300e577cdd 100644 --- a/drivers/regulator/rpi-panel-attiny-regulator.c +++ b/drivers/regulator/rpi-panel-attiny-regulator.c @@ -289,7 +289,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c) unsigned int data; int ret; - state = devm_kzalloc(&i2c->dev, sizeof(*state), GFP_KERNEL); + state = devm_kzalloc_obj(&i2c->dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c index 4955bfea4e844c..3610e82a3233f1 100644 --- a/drivers/regulator/rt4801-regulator.c +++ b/drivers/regulator/rt4801-regulator.c @@ -180,7 +180,7 @@ static int rt4801_probe(struct i2c_client *i2c) struct regmap *regmap; int i; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt4803.c b/drivers/regulator/rt4803.c index 34cd3f249ada93..d246efde07903b 100644 --- a/drivers/regulator/rt4803.c +++ b/drivers/regulator/rt4803.c @@ -158,7 +158,7 @@ static int rt4803_probe(struct i2c_client *i2c) bool vsel_act_high; int ret; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return -ENOMEM; diff --git a/drivers/regulator/rt5120-regulator.c b/drivers/regulator/rt5120-regulator.c index a2a13ce2e67bc5..fe8e4849893705 100644 --- a/drivers/regulator/rt5120-regulator.c +++ b/drivers/regulator/rt5120-regulator.c @@ -357,7 +357,7 @@ static int rt5120_regulator_probe(struct platform_device *pdev) struct regulator_config config = {}; int i, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt5133-regulator.c b/drivers/regulator/rt5133-regulator.c index 129b1f13c88028..22e28f53dd77d3 100644 --- a/drivers/regulator/rt5133-regulator.c +++ b/drivers/regulator/rt5133-regulator.c @@ -546,7 +546,7 @@ static int rt5133_probe(struct i2c_client *i2c) struct regulator_config config = {0}; int i, ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt5190a-regulator.c b/drivers/regulator/rt5190a-regulator.c index a53ed523b5d7d5..eead8d6fc8a451 100644 --- a/drivers/regulator/rt5190a-regulator.c +++ b/drivers/regulator/rt5190a-regulator.c @@ -434,7 +434,7 @@ static int rt5190a_probe(struct i2c_client *i2c) struct regulator_config cfg = {}; int i, ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt5739.c b/drivers/regulator/rt5739.c index 00706cba9f9e20..414605133146b2 100644 --- a/drivers/regulator/rt5739.c +++ b/drivers/regulator/rt5739.c @@ -263,7 +263,7 @@ static int rt5739_probe(struct i2c_client *i2c) unsigned int vid; int ret; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return -ENOMEM; diff --git a/drivers/regulator/rt5759-regulator.c b/drivers/regulator/rt5759-regulator.c index c2553dcee050ae..abdd8905eac143 100644 --- a/drivers/regulator/rt5759-regulator.c +++ b/drivers/regulator/rt5759-regulator.c @@ -319,7 +319,7 @@ static int rt5759_probe(struct i2c_client *i2c) struct rt5759_priv *priv; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt6160-regulator.c b/drivers/regulator/rt6160-regulator.c index 548ffdf537d30f..26bb9c465dc6f7 100644 --- a/drivers/regulator/rt6160-regulator.c +++ b/drivers/regulator/rt6160-regulator.c @@ -237,7 +237,7 @@ static int rt6160_probe(struct i2c_client *i2c) unsigned int devid; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt6190-regulator.c b/drivers/regulator/rt6190-regulator.c index 21ced348a2cfed..6c5e56b3d1e761 100644 --- a/drivers/regulator/rt6190-regulator.c +++ b/drivers/regulator/rt6190-regulator.c @@ -389,7 +389,7 @@ static int rt6190_probe(struct i2c_client *i2c) unsigned int vid; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/regulator/rt6245-regulator.c b/drivers/regulator/rt6245-regulator.c index 5c0ee04e97ac78..cc284676a71cca 100644 --- a/drivers/regulator/rt6245-regulator.c +++ b/drivers/regulator/rt6245-regulator.c @@ -196,7 +196,7 @@ static int rt6245_probe(struct i2c_client *i2c) struct regulator_dev *rdev; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rt8092.c b/drivers/regulator/rt8092.c index 2ea4872ad8e0d4..a131ffbce618ac 100644 --- a/drivers/regulator/rt8092.c +++ b/drivers/regulator/rt8092.c @@ -242,7 +242,7 @@ static int rt8092_probe(struct i2c_client *i2c) bool vsel_high; int ret; - desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dev, *desc); if (!desc) return -ENOMEM; diff --git a/drivers/regulator/rtmv20-regulator.c b/drivers/regulator/rtmv20-regulator.c index 3d8d29f87b5861..0358b752b37a5d 100644 --- a/drivers/regulator/rtmv20-regulator.c +++ b/drivers/regulator/rtmv20-regulator.c @@ -327,7 +327,7 @@ static int rtmv20_probe(struct i2c_client *i2c) struct regulator_config config = {}; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2208-regulator.c index b4eb5d3eb5bdef..1846fbf6e7a890 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -477,7 +477,7 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int * for (i = 0; i < n_regulator; i++) { idx = regulator_idx_table[i]; - rdesc[i] = devm_kcalloc(dev, 1, sizeof(*rdesc[0]), GFP_KERNEL); + rdesc[i] = devm_kzalloc_objs(dev, *rdesc[0], 1); if (!rdesc[i]) return -ENOMEM; @@ -606,7 +606,7 @@ static int rtq2208_probe(struct i2c_client *i2c) buck_masks[RTQ2208_BUCK_NUM_IRQ_REGS] = {0x33, 0x33, 0x33, 0x33, 0x33}; unsigned int ldo1_fixed_uV, ldo2_fixed_uV; - rdev_map = devm_kzalloc(dev, sizeof(struct rtq2208_rdev_map), GFP_KERNEL); + rdev_map = devm_kzalloc_obj(dev, struct rtq2208_rdev_map); if (!rdev_map) return -ENOMEM; diff --git a/drivers/regulator/rtq6752-regulator.c b/drivers/regulator/rtq6752-regulator.c index 618904ede72c44..1ef1e5139b0e11 100644 --- a/drivers/regulator/rtq6752-regulator.c +++ b/drivers/regulator/rtq6752-regulator.c @@ -223,7 +223,7 @@ static int rtq6752_probe(struct i2c_client *i2c) struct regulator_dev *rdev; int i, ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/s2dos05-regulator.c b/drivers/regulator/s2dos05-regulator.c index 6e25f663496a27..b2ae716a73d386 100644 --- a/drivers/regulator/s2dos05-regulator.c +++ b/drivers/regulator/s2dos05-regulator.c @@ -117,7 +117,7 @@ static int s2dos05_pmic_probe(struct platform_device *pdev) struct regulator_config config = { }; unsigned int rdev_num = ARRAY_SIZE(regulators); - s2dos05 = devm_kzalloc(dev, sizeof(*s2dos05), GFP_KERNEL); + s2dos05 = devm_kzalloc_obj(dev, *s2dos05); if (!s2dos05) return -ENOMEM; diff --git a/drivers/regulator/s2mpa01.c b/drivers/regulator/s2mpa01.c index 8171503861c1bf..1cadf695c4ae5f 100644 --- a/drivers/regulator/s2mpa01.c +++ b/drivers/regulator/s2mpa01.c @@ -343,7 +343,7 @@ static int s2mpa01_pmic_probe(struct platform_device *pdev) struct s2mpa01_info *s2mpa01; int i; - s2mpa01 = devm_kzalloc(&pdev->dev, sizeof(*s2mpa01), GFP_KERNEL); + s2mpa01 = devm_kzalloc_obj(&pdev->dev, *s2mpa01); if (!s2mpa01) return -ENOMEM; diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c index 0fb54617b8a7d6..3c77b59ea3d75d 100644 --- a/drivers/regulator/s2mps11.c +++ b/drivers/regulator/s2mps11.c @@ -2170,8 +2170,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev) const struct regulator_desc *regulators; const struct s2mpg10_regulator_desc *s2mpg1x_regulators = NULL; - s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), - GFP_KERNEL); + s2mps11 = devm_kzalloc_obj(&pdev->dev, struct s2mps11_info); if (!s2mps11) return -ENOMEM; diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 2794245d40420c..3116d0f97d214c 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -507,15 +507,11 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, /* count the number of regulators to be supported in pmic */ pdata->num_regulators = of_get_child_count(regulators_np); - rdata = devm_kcalloc(&pdev->dev, - pdata->num_regulators, sizeof(*rdata), - GFP_KERNEL); + rdata = devm_kzalloc_objs(&pdev->dev, *rdata, pdata->num_regulators); if (!rdata) return -ENOMEM; - rmode = devm_kcalloc(&pdev->dev, - pdata->num_regulators, sizeof(*rmode), - GFP_KERNEL); + rmode = devm_kzalloc_objs(&pdev->dev, *rmode, pdata->num_regulators); if (!rmode) return -ENOMEM; @@ -675,8 +671,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev) } } - s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), - GFP_KERNEL); + s5m8767 = devm_kzalloc_obj(&pdev->dev, struct s5m8767_info); if (!s5m8767) return -ENOMEM; diff --git a/drivers/regulator/scmi-regulator.c b/drivers/regulator/scmi-regulator.c index c005e65ba0ecbe..05aaa59aacf653 100644 --- a/drivers/regulator/scmi-regulator.c +++ b/drivers/regulator/scmi-regulator.c @@ -274,9 +274,7 @@ static int process_scmi_regulator_of_node(struct scmi_device *sdev, return -EINVAL; } - rinfo->sregv[dom] = devm_kzalloc(&sdev->dev, - sizeof(struct scmi_regulator), - GFP_KERNEL); + rinfo->sregv[dom] = devm_kzalloc_obj(&sdev->dev, struct scmi_regulator); if (!rinfo->sregv[dom]) return -ENOMEM; @@ -322,7 +320,7 @@ static int scmi_regulator_probe(struct scmi_device *sdev) return num_doms; } - rinfo = devm_kzalloc(&sdev->dev, sizeof(*rinfo), GFP_KERNEL); + rinfo = devm_kzalloc_obj(&sdev->dev, *rinfo); if (!rinfo) return -ENOMEM; diff --git a/drivers/regulator/sgm3804-regulator.c b/drivers/regulator/sgm3804-regulator.c index a34c9418b27580..7314ca414049cb 100644 --- a/drivers/regulator/sgm3804-regulator.c +++ b/drivers/regulator/sgm3804-regulator.c @@ -231,7 +231,7 @@ static int sgm3804_probe(struct i2c_client *i2c) struct sgm3804_data *ctx; int ret, i; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/regulator/slg51000-regulator.c b/drivers/regulator/slg51000-regulator.c index d682764cdbf8ff..9a70ff434f4ae9 100644 --- a/drivers/regulator/slg51000-regulator.c +++ b/drivers/regulator/slg51000-regulator.c @@ -442,7 +442,7 @@ static int slg51000_i2c_probe(struct i2c_client *client) struct gpio_desc *cs_gpiod; int error, ret; - chip = devm_kzalloc(dev, sizeof(struct slg51000), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, struct slg51000); if (!chip) return -ENOMEM; diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c index b7aeef6e09e7c1..435c058e707d48 100644 --- a/drivers/regulator/stm32-pwr.c +++ b/drivers/regulator/stm32-pwr.c @@ -143,8 +143,7 @@ static int stm32_pwr_regulator_probe(struct platform_device *pdev) config.dev = &pdev->dev; for (i = 0; i < STM32PWR_REG_NUM_REGS; i++) { - priv = devm_kzalloc(&pdev->dev, sizeof(struct stm32_pwr_reg), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct stm32_pwr_reg); if (!priv) return -ENOMEM; priv->base = base; diff --git a/drivers/regulator/stm32-vrefbuf.c b/drivers/regulator/stm32-vrefbuf.c index 9e391206f09dde..759ea9036f9e9f 100644 --- a/drivers/regulator/stm32-vrefbuf.c +++ b/drivers/regulator/stm32-vrefbuf.c @@ -172,7 +172,7 @@ static int stm32_vrefbuf_probe(struct platform_device *pdev) struct regulator_dev *rdev; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; diff --git a/drivers/regulator/sy7636a-regulator.c b/drivers/regulator/sy7636a-regulator.c index c44c445ea1390e..8108f578cf1a3c 100644 --- a/drivers/regulator/sy7636a-regulator.c +++ b/drivers/regulator/sy7636a-regulator.c @@ -94,7 +94,7 @@ static int sy7636a_regulator_probe(struct platform_device *pdev) return PTR_ERR(gdp); } - data = devm_kzalloc(&pdev->dev, sizeof(struct sy7636a_data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct sy7636a_data); if (!data) return -ENOMEM; diff --git a/drivers/regulator/sy8824x.c b/drivers/regulator/sy8824x.c index 3f07e7da90cbdc..6c369cb275a8be 100644 --- a/drivers/regulator/sy8824x.c +++ b/drivers/regulator/sy8824x.c @@ -131,7 +131,7 @@ static int sy8824_i2c_probe(struct i2c_client *client) struct regmap *regmap; int ret; - di = devm_kzalloc(dev, sizeof(struct sy8824_device_info), GFP_KERNEL); + di = devm_kzalloc_obj(dev, struct sy8824_device_info); if (!di) return -ENOMEM; diff --git a/drivers/regulator/sy8827n.c b/drivers/regulator/sy8827n.c index a1cac8cc3d96ba..32d128acbfe4f9 100644 --- a/drivers/regulator/sy8827n.c +++ b/drivers/regulator/sy8827n.c @@ -130,7 +130,7 @@ static int sy8827n_i2c_probe(struct i2c_client *client) struct regmap *regmap; int ret; - di = devm_kzalloc(dev, sizeof(struct sy8827n_device_info), GFP_KERNEL); + di = devm_kzalloc_obj(dev, struct sy8827n_device_info); if (!di) return -ENOMEM; diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c index 04133510e5af7d..e89e2a48cdc32b 100644 --- a/drivers/regulator/ti-abb-regulator.c +++ b/drivers/regulator/ti-abb-regulator.c @@ -523,14 +523,13 @@ static int ti_abb_init_table(struct device *dev, struct ti_abb *abb, } num_entries /= num_values; - info = devm_kcalloc(dev, num_entries, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_objs(dev, *info, num_entries); if (!info) return -ENOMEM; abb->info = info; - volt_table = devm_kcalloc(dev, num_entries, sizeof(unsigned int), - GFP_KERNEL); + volt_table = devm_kzalloc_objs(dev, unsigned int, num_entries); if (!volt_table) return -ENOMEM; @@ -697,7 +696,7 @@ static int ti_abb_probe(struct platform_device *pdev) char *pname; int ret = 0; - abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL); + abb = devm_kzalloc_obj(dev, struct ti_abb); if (!abb) return -ENOMEM; diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c index 8459b49ec26e68..5046c42e111315 100644 --- a/drivers/regulator/tps51632-regulator.c +++ b/drivers/regulator/tps51632-regulator.c @@ -216,7 +216,7 @@ static struct tps51632_regulator_platform_data * struct tps51632_regulator_platform_data *pdata; struct device_node *np = dev->of_node; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -254,7 +254,7 @@ static int tps51632_probe(struct i2c_client *client) int ret; struct regulator_config config = { }; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c index 00f19082c1daf4..1b2d40e79738f5 100644 --- a/drivers/regulator/tps62360-regulator.c +++ b/drivers/regulator/tps62360-regulator.c @@ -285,7 +285,7 @@ static struct tps62360_regulator_platform_data * struct tps62360_regulator_platform_data *pdata; struct device_node *np = dev->of_node; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -329,7 +329,7 @@ static int tps62360_probe(struct i2c_client *client) pdata = dev_get_platdata(&client->dev); - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/regulator/tps6287x-regulator.c b/drivers/regulator/tps6287x-regulator.c index e6403398facc44..cd81c7e7056d40 100644 --- a/drivers/regulator/tps6287x-regulator.c +++ b/drivers/regulator/tps6287x-regulator.c @@ -187,7 +187,7 @@ static int tps6287x_i2c_probe(struct i2c_client *i2c) struct tps6287x_reg_data *reg_data; struct regulator_dev *rdev; - reg_data = devm_kzalloc(dev, sizeof(struct tps6287x_reg_data), GFP_KERNEL); + reg_data = devm_kzalloc_obj(dev, struct tps6287x_reg_data); if (!reg_data) return -ENOMEM; diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index 5a2fc57cddf6b6..57b91b1fe32842 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c @@ -266,7 +266,7 @@ static int tps_65023_probe(struct i2c_client *client) int i; int error; - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&client->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index 6655d9c31187e3..e45ed4d494934f 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c @@ -386,7 +386,7 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) if (tps_board) init_data = tps_board->tps6507x_pmic_init_data; - tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(&pdev->dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c index 8f916ee366e513..7433b273379266 100644 --- a/drivers/regulator/tps65090-regulator.c +++ b/drivers/regulator/tps65090-regulator.c @@ -316,14 +316,12 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data( int idx = 0, ret; struct tps65090_regulator_plat_data *reg_pdata; - tps65090_pdata = devm_kzalloc(&pdev->dev, sizeof(*tps65090_pdata), - GFP_KERNEL); + tps65090_pdata = devm_kzalloc_obj(&pdev->dev, *tps65090_pdata); if (!tps65090_pdata) return ERR_PTR(-ENOMEM); - reg_pdata = devm_kcalloc(&pdev->dev, - TPS65090_REGULATOR_MAX, sizeof(*reg_pdata), - GFP_KERNEL); + reg_pdata = devm_kzalloc_objs(&pdev->dev, *reg_pdata, + TPS65090_REGULATOR_MAX); if (!reg_pdata) return ERR_PTR(-ENOMEM); @@ -426,9 +424,7 @@ static int tps65090_regulator_probe(struct platform_device *pdev) return tps65090_pdata ? PTR_ERR(tps65090_pdata) : -EINVAL; } - pmic = devm_kcalloc(&pdev->dev, - TPS65090_REGULATOR_MAX, sizeof(*pmic), - GFP_KERNEL); + pmic = devm_kzalloc_objs(&pdev->dev, *pmic, TPS65090_REGULATOR_MAX); if (!pmic) return -ENOMEM; diff --git a/drivers/regulator/tps65132-regulator.c b/drivers/regulator/tps65132-regulator.c index fecda3fd8ebc45..912db82ab51d06 100644 --- a/drivers/regulator/tps65132-regulator.c +++ b/drivers/regulator/tps65132-regulator.c @@ -230,7 +230,7 @@ static int tps65132_probe(struct i2c_client *client) int id; int ret; - tps = devm_kzalloc(dev, sizeof(*tps), GFP_KERNEL); + tps = devm_kzalloc_obj(dev, *tps); if (!tps) return -ENOMEM; diff --git a/drivers/regulator/tps65185.c b/drivers/regulator/tps65185.c index 4865227e444a6e..33728e764eb554 100644 --- a/drivers/regulator/tps65185.c +++ b/drivers/regulator/tps65185.c @@ -335,7 +335,7 @@ static int tps65185_probe(struct i2c_client *client) int ret = 0; int i; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c index a667c3f44bb794..429c3fd20db1b5 100644 --- a/drivers/regulator/tps65219-regulator.c +++ b/drivers/regulator/tps65219-regulator.c @@ -431,7 +431,7 @@ static int tps65219_register_irqs(struct platform_device *pdev, if (irq < 0) return -EINVAL; - irq_data = devm_kmalloc(tps->dev, sizeof(*irq_data), GFP_KERNEL); + irq_data = devm_kmalloc_obj(tps->dev, *irq_data); if (!irq_data) return -ENOMEM; diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c index 6beb51293e8e1d..015f3ceb76ffb8 100644 --- a/drivers/regulator/tps6524x-regulator.c +++ b/drivers/regulator/tps6524x-regulator.c @@ -592,7 +592,7 @@ static int pmic_probe(struct spi_device *spi) return -EINVAL; } - hw = devm_kzalloc(&spi->dev, sizeof(struct tps6524x), GFP_KERNEL); + hw = devm_kzalloc_obj(&spi->dev, struct tps6524x); if (!hw) return -ENOMEM; diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index 1ab5767590f39b..08403e50c5f99c 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c @@ -415,7 +415,7 @@ static struct tps6586x_platform_data *tps6586x_parse_regulator_dt( return NULL; } - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return NULL; diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 3a3027e0b94ef3..6b14c39e42de78 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -1005,8 +1005,7 @@ static struct tps65910_board *tps65910_parse_dt_reg_data( unsigned int prop; int idx = 0, ret, count; - pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data), - GFP_KERNEL); + pmic_plat_data = devm_kzalloc_obj(&pdev->dev, *pmic_plat_data); if (!pmic_plat_data) return NULL; @@ -1089,7 +1088,7 @@ static int tps65910_probe(struct platform_device *pdev) return -EINVAL; } - pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); + pmic = devm_kzalloc_obj(&pdev->dev, *pmic); if (!pmic) return -ENOMEM; @@ -1128,24 +1127,18 @@ static int tps65910_probe(struct platform_device *pdev) return -ENODEV; } - pmic->desc = devm_kcalloc(&pdev->dev, - pmic->num_regulators, - sizeof(struct regulator_desc), - GFP_KERNEL); + pmic->desc = devm_kzalloc_objs(&pdev->dev, struct regulator_desc, + pmic->num_regulators); if (!pmic->desc) return -ENOMEM; - pmic->info = devm_kcalloc(&pdev->dev, - pmic->num_regulators, - sizeof(struct tps_info *), - GFP_KERNEL); + pmic->info = devm_kzalloc_objs(&pdev->dev, struct tps_info *, + pmic->num_regulators); if (!pmic->info) return -ENOMEM; - pmic->rdev = devm_kcalloc(&pdev->dev, - pmic->num_regulators, - sizeof(struct regulator_dev *), - GFP_KERNEL); + pmic->rdev = devm_kzalloc_objs(&pdev->dev, struct regulator_dev *, + pmic->num_regulators); if (!pmic->rdev) return -ENOMEM; diff --git a/drivers/regulator/tps6594-regulator.c b/drivers/regulator/tps6594-regulator.c index 503b89a2f5f810..fbf365a46a9e5e 100644 --- a/drivers/regulator/tps6594-regulator.c +++ b/drivers/regulator/tps6594-regulator.c @@ -721,8 +721,9 @@ static int tps6594_regulator_probe(struct platform_device *pdev) reg_irq_nb = desc->num_irq_types * (desc->num_buck_regs + desc->num_ldo_regs); - irq_data = devm_kmalloc_array(tps->dev, reg_irq_nb, - sizeof(struct tps6594_regulator_irq_data), GFP_KERNEL); + irq_data = devm_kmalloc_objs(tps->dev, + struct tps6594_regulator_irq_data, + reg_irq_nb); if (!irq_data) return -ENOMEM; @@ -810,10 +811,9 @@ static int tps6594_regulator_probe(struct platform_device *pdev) return error; } - irq_ext_reg_data = devm_kmalloc_array(tps->dev, - desc->num_ext_irqs, - sizeof(struct tps6594_ext_regulator_irq_data), - GFP_KERNEL); + irq_ext_reg_data = devm_kmalloc_objs(tps->dev, + struct tps6594_ext_regulator_irq_data, + desc->num_ext_irqs); if (!irq_ext_reg_data) return -ENOMEM; diff --git a/drivers/regulator/tps68470-regulator.c b/drivers/regulator/tps68470-regulator.c index de7db7690f6b1f..4e84cde07f61f3 100644 --- a/drivers/regulator/tps68470-regulator.c +++ b/drivers/regulator/tps68470-regulator.c @@ -144,7 +144,7 @@ static int tps68470_regulator_probe(struct platform_device *pdev) struct regulator_dev *rdev; int i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/regulator/uniphier-regulator.c b/drivers/regulator/uniphier-regulator.c index 74939b7fcd8185..0bd4dc07dfa1da 100644 --- a/drivers/regulator/uniphier-regulator.c +++ b/drivers/regulator/uniphier-regulator.c @@ -49,7 +49,7 @@ static int uniphier_regulator_probe(struct platform_device *pdev) const char *name; int i, ret, nr; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c index 72bb5ffb49a8ce..9172a26e0ac4b4 100644 --- a/drivers/regulator/userspace-consumer.c +++ b/drivers/regulator/userspace-consumer.c @@ -132,7 +132,7 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) pdata->no_autoswitch = true; pdata->num_supplies = 1; - pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies), GFP_KERNEL); + pdata->supplies = devm_kzalloc_obj(&pdev->dev, *pdata->supplies); if (!pdata->supplies) return -ENOMEM; pdata->supplies[0].supply = "vout"; @@ -143,9 +143,7 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) return -EINVAL; } - drvdata = devm_kzalloc(&pdev->dev, - sizeof(struct userspace_consumer_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct userspace_consumer_data); if (drvdata == NULL) return -ENOMEM; diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c index 2796580a3a3ccb..c5a5447d057ad5 100644 --- a/drivers/regulator/vctrl-regulator.c +++ b/drivers/regulator/vctrl-regulator.c @@ -347,9 +347,9 @@ static int vctrl_init_vtable(struct platform_device *pdev, return -EINVAL; } - vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages, - sizeof(struct vctrl_voltage_table), - GFP_KERNEL); + vctrl->vtable = devm_kzalloc_objs(&pdev->dev, + struct vctrl_voltage_table, + rdesc->n_voltages); if (!vctrl->vtable) return -ENOMEM; @@ -451,8 +451,7 @@ static int vctrl_probe(struct platform_device *pdev) int ctrl_uV; int ret; - vctrl = devm_kzalloc(&pdev->dev, sizeof(struct vctrl_data), - GFP_KERNEL); + vctrl = devm_kzalloc_obj(&pdev->dev, struct vctrl_data); if (!vctrl) return -ENOMEM; diff --git a/drivers/regulator/vexpress-regulator.c b/drivers/regulator/vexpress-regulator.c index 5a2e0143cfdf96..e2c9b4331af0b1 100644 --- a/drivers/regulator/vexpress-regulator.c +++ b/drivers/regulator/vexpress-regulator.c @@ -45,7 +45,7 @@ static int vexpress_regulator_probe(struct platform_device *pdev) struct regulator_dev *rdev; struct regmap *regmap; - desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(&pdev->dev, *desc); if (!desc) return -ENOMEM; diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index 218a0d66a15282..a7e3c67967e8a2 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c @@ -309,8 +309,7 @@ static int regulator_virtual_probe(struct platform_device *pdev) pr_warn("**********************************************************\n"); } - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct virtual_consumer_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct virtual_consumer_data); if (drvdata == NULL) return -ENOMEM; diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 834d7c181971db..2036735f0e154c 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c @@ -402,8 +402,7 @@ static int wm831x_buckv_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); - dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), - GFP_KERNEL); + dcdc = devm_kzalloc_obj(&pdev->dev, struct wm831x_dcdc); if (!dcdc) return -ENOMEM; @@ -561,8 +560,7 @@ static int wm831x_buckp_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); - dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), - GFP_KERNEL); + dcdc = devm_kzalloc_obj(&pdev->dev, struct wm831x_dcdc); if (!dcdc) return -ENOMEM; @@ -691,7 +689,7 @@ static int wm831x_boostp_probe(struct platform_device *pdev) if (pdata == NULL || pdata->dcdc[id] == NULL) return -ENODEV; - dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); + dcdc = devm_kzalloc_obj(&pdev->dev, struct wm831x_dcdc); if (!dcdc) return -ENOMEM; @@ -780,7 +778,7 @@ static int wm831x_epe_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1); - dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); + dcdc = devm_kzalloc_obj(&pdev->dev, struct wm831x_dcdc); if (!dcdc) return -ENOMEM; diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index b46e2cde5e9dad..5afd3094b3ce27 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -118,8 +118,7 @@ static int wm831x_isink_probe(struct platform_device *pdev) if (pdata == NULL || pdata->isink[id] == NULL) return -ENODEV; - isink = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_isink), - GFP_KERNEL); + isink = devm_kzalloc_obj(&pdev->dev, struct wm831x_isink); if (!isink) return -ENOMEM; diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 76b89b1cd519cb..34a6d6cf753a31 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c @@ -229,7 +229,7 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); - ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct wm831x_ldo); if (!ldo) return -ENOMEM; @@ -440,7 +440,7 @@ static int wm831x_aldo_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); - ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct wm831x_ldo); if (!ldo) return -ENOMEM; @@ -586,7 +586,7 @@ static int wm831x_alive_ldo_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); - ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct wm831x_ldo); if (!ldo) return -ENOMEM; diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c index 2946db448aecab..0ce30f4c140d97 100644 --- a/drivers/regulator/wm8994-regulator.c +++ b/drivers/regulator/wm8994-regulator.c @@ -158,7 +158,7 @@ static int wm8994_ldo_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); - ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL); + ldo = devm_kzalloc_obj(&pdev->dev, struct wm8994_ldo); if (!ldo) return -ENOMEM; diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c index 006fa7b5672716..e57dcb5598dfa3 100644 --- a/drivers/remoteproc/da8xx_remoteproc.c +++ b/drivers/remoteproc/da8xx_remoteproc.c @@ -201,8 +201,7 @@ static int da8xx_rproc_get_internal_memories(struct platform_device *pdev, struct resource *res; int i; - drproc->mem = devm_kcalloc(dev, num_mems, sizeof(*drproc->mem), - GFP_KERNEL); + drproc->mem = devm_kzalloc_objs(dev, *drproc->mem, num_mems); if (!drproc->mem) return -ENOMEM; diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c index 407d6034f74853..1b6b49a2245455 100644 --- a/drivers/remoteproc/keystone_remoteproc.c +++ b/drivers/remoteproc/keystone_remoteproc.c @@ -283,8 +283,7 @@ static int keystone_rproc_of_get_memories(struct platform_device *pdev, int i; num_mems = ARRAY_SIZE(mem_names); - ksproc->mem = devm_kcalloc(ksproc->dev, num_mems, - sizeof(*ksproc->mem), GFP_KERNEL); + ksproc->mem = devm_kzalloc_objs(ksproc->dev, *ksproc->mem, num_mems); if (!ksproc->mem) return -ENOMEM; diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 9751acc2bf83fb..3a4627fd6cbf29 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -1408,7 +1408,7 @@ static int scp_probe(struct platform_device *pdev) struct resource *res; int ret; - scp_cluster = devm_kzalloc(dev, sizeof(*scp_cluster), GFP_KERNEL); + scp_cluster = devm_kzalloc_obj(dev, *scp_cluster); if (!scp_cluster) return -ENOMEM; diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c index 1e96506ce7ca79..f52a531877ae04 100644 --- a/drivers/remoteproc/omap_remoteproc.c +++ b/drivers/remoteproc/omap_remoteproc.c @@ -1143,8 +1143,7 @@ static int omap_rproc_get_boot_data(struct platform_device *pdev, if (!of_property_present(np, "ti,bootreg")) return 0; - oproc->boot_data = devm_kzalloc(&pdev->dev, sizeof(*oproc->boot_data), - GFP_KERNEL); + oproc->boot_data = devm_kzalloc_obj(&pdev->dev, *oproc->boot_data); if (!oproc->boot_data) return -ENOMEM; @@ -1185,8 +1184,7 @@ static int omap_rproc_of_get_internal_memories(struct platform_device *pdev, num_mems = of_property_count_elems_of_size(dev->of_node, "reg", sizeof(u32)) / 2; - oproc->mem = devm_kcalloc(dev, num_mems, sizeof(*oproc->mem), - GFP_KERNEL); + oproc->mem = devm_kzalloc_objs(dev, *oproc->mem, num_mems); if (!oproc->mem) return -ENOMEM; @@ -1263,9 +1261,8 @@ static int omap_rproc_of_get_timers(struct platform_device *pdev, num_timers = oproc->num_timers + oproc->num_wd_timers; if (num_timers) { - oproc->timers = devm_kcalloc(dev, num_timers, - sizeof(*oproc->timers), - GFP_KERNEL); + oproc->timers = devm_kzalloc_objs(dev, *oproc->timers, + num_timers); if (!oproc->timers) return -ENOMEM; diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c index a4636c7bc6b7be..bcdb62b9acfb8e 100644 --- a/drivers/remoteproc/pru_rproc.c +++ b/drivers/remoteproc/pru_rproc.c @@ -534,8 +534,7 @@ static int pru_handle_intrmap(struct rproc *rproc) return -EINVAL; pru->evt_count = rsc->num_evts; - pru->mapped_irq = kcalloc(pru->evt_count, sizeof(unsigned int), - GFP_KERNEL); + pru->mapped_irq = kzalloc_objs(unsigned int, pru->evt_count); if (!pru->mapped_irq) { pru->evt_count = 0; return -ENOMEM; diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c index 46d9169a37f6f6..23fabf4ce84df3 100644 --- a/drivers/remoteproc/qcom_q6v5_adsp.c +++ b/drivers/remoteproc/qcom_q6v5_adsp.c @@ -545,8 +545,7 @@ static int adsp_init_clock(struct qcom_adsp *adsp, const char **clk_ids) num_clks++; adsp->num_clks = num_clks; - adsp->clks = devm_kcalloc(adsp->dev, adsp->num_clks, - sizeof(*adsp->clks), GFP_KERNEL); + adsp->clks = devm_kzalloc_objs(adsp->dev, *adsp->clks, adsp->num_clks); if (!adsp->clks) return -ENOMEM; diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index f37b77ae187e99..e7dfad27e52633 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -859,8 +859,7 @@ static int qcom_pas_setup_tmd(struct qcom_pas *pas, const struct qcom_pas_data * if (!desc->tmd_name || desc->num_tmd == 0) return 0; - tmd_names = devm_kcalloc(pas->dev, desc->num_tmd, - sizeof(*tmd_names), GFP_KERNEL); + tmd_names = devm_kzalloc_objs(pas->dev, *tmd_names, desc->num_tmd); if (!tmd_names) return -ENOMEM; diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c index c856a92af43cea..02f38fe29f20f4 100644 --- a/drivers/remoteproc/qcom_wcnss.c +++ b/drivers/remoteproc/qcom_wcnss.c @@ -468,9 +468,8 @@ static int wcnss_init_regulators(struct qcom_wcnss *wcnss, num_vregs += data->num_pd_vregs; } - bulk = devm_kcalloc(wcnss->dev, - num_vregs, sizeof(struct regulator_bulk_data), - GFP_KERNEL); + bulk = devm_kzalloc_objs(wcnss->dev, struct regulator_bulk_data, + num_vregs); if (!bulk) return -ENOMEM; diff --git a/drivers/remoteproc/qcom_wcnss_iris.c b/drivers/remoteproc/qcom_wcnss_iris.c index 2b89b4db6c94f5..415ad475036be9 100644 --- a/drivers/remoteproc/qcom_wcnss_iris.c +++ b/drivers/remoteproc/qcom_wcnss_iris.c @@ -161,10 +161,8 @@ struct qcom_iris *qcom_iris_probe(struct device *parent, bool *use_48mhz_xo) } iris->num_vregs = data->num_vregs; - iris->vregs = devm_kcalloc(&iris->dev, - iris->num_vregs, - sizeof(struct regulator_bulk_data), - GFP_KERNEL); + iris->vregs = devm_kzalloc_objs(&iris->dev, struct regulator_bulk_data, + iris->num_vregs); if (!iris->vregs) { ret = -ENOMEM; goto err_device_del; diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 12f55a81cfa0e2..6098fc237425fc 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -513,7 +513,7 @@ static int rproc_virtio_probe(struct platform_device *pdev) if (!rvdev_data) return -EINVAL; - rvdev = devm_kzalloc(dev, sizeof(*rvdev), GFP_KERNEL); + rvdev = devm_kzalloc_obj(dev, *rvdev); if (!rvdev) return -ENOMEM; diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index a47e040c6db89d..b1d73ffc8a149f 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -132,7 +132,7 @@ static int stm32_rproc_of_memory_translations(struct platform_device *pdev, return -EINVAL; } - p_mems = devm_kcalloc(dev, cnt, sizeof(*p_mems), GFP_KERNEL); + p_mems = devm_kzalloc_objs(dev, *p_mems, cnt); if (!p_mems) return -ENOMEM; mem_range = kzalloc_objs(*mem_range, cnt); diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 4b6da3363f6c2b..f79ccb57a37258 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -409,8 +409,7 @@ int k3_rproc_of_get_memories(struct platform_device *pdev, int i; num_mems = data->num_mems; - kproc->mem = devm_kcalloc(kproc->dev, num_mems, - sizeof(*kproc->mem), GFP_KERNEL); + kproc->mem = devm_kzalloc_objs(kproc->dev, *kproc->mem, num_mems); if (!kproc->mem) return -ENOMEM; @@ -490,7 +489,7 @@ int k3_reserved_mem_init(struct k3_rproc *kproc) return ret; num_rmems--; - kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); + kproc->rmem = devm_kzalloc_objs(dev, *kproc->rmem, num_rmems); if (!kproc->rmem) return -ENOMEM; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index d7d9756afed0e9..618c72dc08ecfb 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -921,8 +921,7 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, int i, ret; num_mems = data->num_mems; - kproc->mem = devm_kcalloc(kproc->dev, num_mems, sizeof(*kproc->mem), - GFP_KERNEL); + kproc->mem = devm_kzalloc_objs(kproc->dev, *kproc->mem, num_mems); if (!kproc->mem) return -ENOMEM; @@ -972,7 +971,7 @@ static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev, return 0; } - core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL); + core->sram = devm_kzalloc_objs(dev, *core->sram, num_sram); if (!core->sram) return -ENOMEM; @@ -1216,7 +1215,7 @@ static int k3_r5_core_of_init(struct platform_device *pdev) if (!devres_open_group(dev, k3_r5_core_of_init, GFP_KERNEL)) return -ENOMEM; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) { ret = -ENOMEM; goto err; @@ -1345,7 +1344,7 @@ static int k3_r5_probe(struct platform_device *pdev) return -ENODEV; } - cluster = devm_kzalloc(dev, sizeof(*cluster), GFP_KERNEL); + cluster = devm_kzalloc_obj(dev, *cluster); if (!cluster) return -ENOMEM; diff --git a/drivers/remoteproc/ti_sci_proc.h b/drivers/remoteproc/ti_sci_proc.h index f3911ce75252ec..aa9cffbfdd852e 100644 --- a/drivers/remoteproc/ti_sci_proc.h +++ b/drivers/remoteproc/ti_sci_proc.h @@ -41,7 +41,7 @@ struct ti_sci_proc *ti_sci_proc_of_get_tsp(struct device *dev, if (ret < 0) return ERR_PTR(ret); - tsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL); + tsp = devm_kzalloc_obj(dev, *tsp); if (!tsp) return ERR_PTR(-ENOMEM); diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c index a9873a37dd8fc8..dfa01a32428165 100644 --- a/drivers/remoteproc/xlnx_r5_remoteproc.c +++ b/drivers/remoteproc/xlnx_r5_remoteproc.c @@ -954,8 +954,7 @@ static int zynqmp_r5_get_sram_banks(struct zynqmp_r5_core *r5_core) return -EINVAL; } - sram = devm_kcalloc(dev, num_sram, - sizeof(struct zynqmp_sram_bank), GFP_KERNEL); + sram = devm_kzalloc_objs(dev, struct zynqmp_sram_bank, num_sram); if (!sram) return -ENOMEM; @@ -1038,16 +1037,15 @@ static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster) return -EINVAL; } - r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count, - sizeof(struct mem_bank_data *), - GFP_KERNEL); + r5_core->tcm_banks = devm_kzalloc_objs(dev, + struct mem_bank_data *, + tcm_bank_count); if (!r5_core->tcm_banks) return -ENOMEM; r5_core->tcm_bank_count = tcm_bank_count; for (j = 0, tcm_pd_idx = 1; j < tcm_bank_count; j++, tcm_pd_idx++) { - tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data), - GFP_KERNEL); + tcm = devm_kzalloc_obj(dev, struct mem_bank_data); if (!tcm) return -ENOMEM; @@ -1139,9 +1137,9 @@ static int zynqmp_r5_get_tcm_node(struct zynqmp_r5_cluster *cluster) tcm_node = 0; for (i = 0; i < cluster->core_count; i++) { r5_core = cluster->r5_cores[i]; - r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count, - sizeof(struct mem_bank_data *), - GFP_KERNEL); + r5_core->tcm_banks = devm_kzalloc_objs(dev, + struct mem_bank_data *, + tcm_bank_count); if (!r5_core->tcm_banks) return -ENOMEM; diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index c067b6d57d71e1..27abf60f4d6752 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -706,7 +706,7 @@ static int mpam_ris_create_locked(struct mpam_msc *msc, u8 ris_idx, if (test_and_set_bit(ris_idx, &msc->ris_idxs)) return -EBUSY; - ris = devm_kzalloc(&msc->pdev->dev, sizeof(*ris), GFP_KERNEL); + ris = devm_kzalloc_obj(&msc->pdev->dev, *ris); if (!ris) return -ENOMEM; init_garbage(&ris->garbage); @@ -2450,7 +2450,7 @@ static struct mpam_msc *do_mpam_msc_drv_probe(struct platform_device *pdev) lockdep_assert_held(&mpam_list_lock); - msc = devm_kzalloc(&pdev->dev, sizeof(*msc), GFP_KERNEL); + msc = devm_kzalloc_obj(&pdev->dev, *msc); if (!msc) return ERR_PTR(-ENOMEM); init_garbage(&msc->garbage); diff --git a/drivers/reset/amlogic/reset-meson-audio-arb.c b/drivers/reset/amlogic/reset-meson-audio-arb.c index 6ec253976bed07..1cb41459e605bc 100644 --- a/drivers/reset/amlogic/reset-meson-audio-arb.c +++ b/drivers/reset/amlogic/reset-meson-audio-arb.c @@ -141,7 +141,7 @@ static int meson_audio_arb_probe(struct platform_device *pdev) if (!data) return -EINVAL; - arb = devm_kzalloc(dev, sizeof(*arb), GFP_KERNEL); + arb = devm_kzalloc_obj(dev, *arb); if (!arb) return -ENOMEM; platform_set_drvdata(pdev, arb); diff --git a/drivers/reset/amlogic/reset-meson-common.c b/drivers/reset/amlogic/reset-meson-common.c index a90e0ecaaadf07..998b23d0a3a925 100644 --- a/drivers/reset/amlogic/reset-meson-common.c +++ b/drivers/reset/amlogic/reset-meson-common.c @@ -120,7 +120,7 @@ int meson_reset_controller_register(struct device *dev, struct regmap *map, { struct meson_reset *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/hisilicon/hi6220_reset.c b/drivers/reset/hisilicon/hi6220_reset.c index 65aa5ff5ed82c2..804d22a3979cd0 100644 --- a/drivers/reset/hisilicon/hi6220_reset.c +++ b/drivers/reset/hisilicon/hi6220_reset.c @@ -159,7 +159,7 @@ static int hi6220_reset_probe(struct platform_device *pdev) struct hi6220_reset_data *data; struct regmap *regmap; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/hisilicon/reset-hi3660.c b/drivers/reset/hisilicon/reset-hi3660.c index 1beb275275ad28..c2d350b0ec28ed 100644 --- a/drivers/reset/hisilicon/reset-hi3660.c +++ b/drivers/reset/hisilicon/reset-hi3660.c @@ -79,7 +79,7 @@ static int hi3660_reset_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; - rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL); + rc = devm_kzalloc_obj(dev, *rc); if (!rc) return -ENOMEM; diff --git a/drivers/reset/reset-a10sr.c b/drivers/reset/reset-a10sr.c index 99b3bc8382f35d..748a1282678638 100644 --- a/drivers/reset/reset-a10sr.c +++ b/drivers/reset/reset-a10sr.c @@ -92,8 +92,7 @@ static int a10sr_reset_probe(struct platform_device *pdev) struct altr_a10sr *a10sr = dev_get_drvdata(pdev->dev.parent); struct a10sr_reset *a10r; - a10r = devm_kzalloc(&pdev->dev, sizeof(struct a10sr_reset), - GFP_KERNEL); + a10r = devm_kzalloc_obj(&pdev->dev, struct a10sr_reset); if (!a10r) return -ENOMEM; diff --git a/drivers/reset/reset-aspeed.c b/drivers/reset/reset-aspeed.c index dd2f860a69d77c..1cb65f02fde45d 100644 --- a/drivers/reset/reset-aspeed.c +++ b/drivers/reset/reset-aspeed.c @@ -206,7 +206,7 @@ static int aspeed_reset_probe(struct auxiliary_device *adev, struct aspeed_reset *reset; struct device *dev = &adev->dev; - reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/reset/reset-ath79.c b/drivers/reset/reset-ath79.c index 1a2c0f8a5e9e73..2ff62820ff1c3b 100644 --- a/drivers/reset/reset-ath79.c +++ b/drivers/reset/reset-ath79.c @@ -84,8 +84,7 @@ static int ath79_reset_probe(struct platform_device *pdev) struct ath79_reset *ath79_reset; int err; - ath79_reset = devm_kzalloc(&pdev->dev, - sizeof(*ath79_reset), GFP_KERNEL); + ath79_reset = devm_kzalloc_obj(&pdev->dev, *ath79_reset); if (!ath79_reset) return -ENOMEM; diff --git a/drivers/reset/reset-axs10x.c b/drivers/reset/reset-axs10x.c index ea0e6b0b6b4d86..3e4c3b88dd1651 100644 --- a/drivers/reset/reset-axs10x.c +++ b/drivers/reset/reset-axs10x.c @@ -44,7 +44,7 @@ static int axs10x_reset_probe(struct platform_device *pdev) { struct axs10x_rst *rst; - rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL); + rst = devm_kzalloc_obj(&pdev->dev, *rst); if (!rst) return -ENOMEM; diff --git a/drivers/reset/reset-bcm6345.c b/drivers/reset/reset-bcm6345.c index 441d9dd7657248..f6857dea0ea037 100644 --- a/drivers/reset/reset-bcm6345.c +++ b/drivers/reset/reset-bcm6345.c @@ -96,8 +96,7 @@ static int bcm6345_reset_probe(struct platform_device *pdev) { struct bcm6345_reset *bcm6345_reset; - bcm6345_reset = devm_kzalloc(&pdev->dev, - sizeof(*bcm6345_reset), GFP_KERNEL); + bcm6345_reset = devm_kzalloc_obj(&pdev->dev, *bcm6345_reset); if (!bcm6345_reset) return -ENOMEM; diff --git a/drivers/reset/reset-berlin.c b/drivers/reset/reset-berlin.c index 578fe867080ce0..ffdcd4a2e093b7 100644 --- a/drivers/reset/reset-berlin.c +++ b/drivers/reset/reset-berlin.c @@ -71,7 +71,7 @@ static int berlin2_reset_probe(struct platform_device *pdev) struct device_node *parent_np; struct berlin_reset_priv *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-brcmstb-rescal.c b/drivers/reset/reset-brcmstb-rescal.c index 823317772bacfa..92c90c4e174918 100644 --- a/drivers/reset/reset-brcmstb-rescal.c +++ b/drivers/reset/reset-brcmstb-rescal.c @@ -67,7 +67,7 @@ static int brcm_rescal_reset_probe(struct platform_device *pdev) { struct brcm_rescal_reset *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-brcmstb.c b/drivers/reset/reset-brcmstb.c index 810fe76452d671..af243486c9bcd0 100644 --- a/drivers/reset/reset-brcmstb.c +++ b/drivers/reset/reset-brcmstb.c @@ -86,7 +86,7 @@ static int brcmstb_reset_probe(struct platform_device *pdev) struct brcmstb_reset *priv; struct resource *res; - priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(kdev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-dr1v90.c b/drivers/reset/reset-dr1v90.c index daa99c797b1af2..8cfbc7f9f62540 100644 --- a/drivers/reset/reset-dr1v90.c +++ b/drivers/reset/reset-dr1v90.c @@ -105,7 +105,7 @@ static int dr1v90_reset_probe(struct auxiliary_device *adev, struct dr1v90_reset_controller *rstc; struct device *dev = &adev->dev; - rstc = devm_kzalloc(dev, sizeof(*rstc), GFP_KERNEL); + rstc = devm_kzalloc_obj(dev, *rstc); if (!rstc) return -ENOMEM; diff --git a/drivers/reset/reset-eic7700-hsp.c b/drivers/reset/reset-eic7700-hsp.c index 1575ee4a20d682..2b20975ccea767 100644 --- a/drivers/reset/reset-eic7700-hsp.c +++ b/drivers/reset/reset-eic7700-hsp.c @@ -78,7 +78,7 @@ static int eic7700_hsp_reset_probe(struct auxiliary_device *adev, struct eic7700_hsp_reset_data *data; struct device *dev = &adev->dev; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-eic7700.c b/drivers/reset/reset-eic7700.c index b72283b18b0877..09a742f8e38aa3 100644 --- a/drivers/reset/reset-eic7700.c +++ b/drivers/reset/reset-eic7700.c @@ -390,7 +390,7 @@ static int eic7700_reset_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; void __iomem *base; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-eyeq.c b/drivers/reset/reset-eyeq.c index f2533086bb764c..6b210e2ae6e754 100644 --- a/drivers/reset/reset-eyeq.c +++ b/drivers/reset/reset-eyeq.c @@ -564,7 +564,7 @@ static int eqr_probe(struct auxiliary_device *adev, if (!match || !match->data) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-gpio.c b/drivers/reset/reset-gpio.c index bf95296a512ef8..d11d1d6de445de 100644 --- a/drivers/reset/reset-gpio.c +++ b/drivers/reset/reset-gpio.c @@ -57,7 +57,7 @@ static int reset_gpio_probe(struct auxiliary_device *adev, struct device *dev = &adev->dev; struct reset_gpio_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-hsdk.c b/drivers/reset/reset-hsdk.c index 98460e08752c60..076c5ddb3f36e0 100644 --- a/drivers/reset/reset-hsdk.c +++ b/drivers/reset/reset-hsdk.c @@ -93,7 +93,7 @@ static int hsdk_reset_probe(struct platform_device *pdev) { struct hsdk_rst *rst; - rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL); + rst = devm_kzalloc_obj(&pdev->dev, *rst); if (!rst) return -ENOMEM; diff --git a/drivers/reset/reset-imx-scu.c b/drivers/reset/reset-imx-scu.c index 919fc29f944c6e..cf7b9619639d0b 100644 --- a/drivers/reset/reset-imx-scu.c +++ b/drivers/reset/reset-imx-scu.c @@ -61,7 +61,7 @@ static int imx_scu_reset_probe(struct platform_device *pdev) struct imx_scu_reset *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-imx7.c b/drivers/reset/reset-imx7.c index a3cb8244d76a6f..b4821044b88f63 100644 --- a/drivers/reset/reset-imx7.c +++ b/drivers/reset/reset-imx7.c @@ -371,7 +371,7 @@ static int imx7_reset_probe(struct platform_device *pdev) struct regmap_config config = { .name = "src" }; const struct imx7_src_variant *variant = of_device_get_match_data(dev); - imx7src = devm_kzalloc(dev, sizeof(*imx7src), GFP_KERNEL); + imx7src = devm_kzalloc_obj(dev, *imx7src); if (!imx7src) return -ENOMEM; diff --git a/drivers/reset/reset-imx8mp-audiomix.c b/drivers/reset/reset-imx8mp-audiomix.c index b7fa3110f282ad..7213abafaf6659 100644 --- a/drivers/reset/reset-imx8mp-audiomix.c +++ b/drivers/reset/reset-imx8mp-audiomix.c @@ -192,7 +192,7 @@ static int imx8mp_audiomix_reset_probe(struct auxiliary_device *adev, rinfo = (void *)id->driver_data; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-intel-gw.c b/drivers/reset/reset-intel-gw.c index 0db64cc8a2822e..151e3f8dcd67aa 100644 --- a/drivers/reset/reset-intel-gw.c +++ b/drivers/reset/reset-intel-gw.c @@ -170,7 +170,7 @@ static int intel_reset_probe(struct platform_device *pdev) u32 rb_id[3]; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-k210.c b/drivers/reset/reset-k210.c index e77e4cca377dca..7ad462711af83f 100644 --- a/drivers/reset/reset-k210.c +++ b/drivers/reset/reset-k210.c @@ -95,7 +95,7 @@ static int k210_rst_probe(struct platform_device *pdev) dev_info(dev, "K210 reset controller\n"); - ksr = devm_kzalloc(dev, sizeof(*ksr), GFP_KERNEL); + ksr = devm_kzalloc_obj(dev, *ksr); if (!ksr) return -ENOMEM; diff --git a/drivers/reset/reset-k230.c b/drivers/reset/reset-k230.c index c81045bb4a142a..4ca74ba6cec0f2 100644 --- a/drivers/reset/reset-k230.c +++ b/drivers/reset/reset-k230.c @@ -332,7 +332,7 @@ static int k230_rst_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct k230_rst *rstc; - rstc = devm_kzalloc(dev, sizeof(*rstc), GFP_KERNEL); + rstc = devm_kzalloc_obj(dev, *rstc); if (!rstc) return -ENOMEM; diff --git a/drivers/reset/reset-lantiq.c b/drivers/reset/reset-lantiq.c index 652a45890cb22a..b41295c221283d 100644 --- a/drivers/reset/reset-lantiq.c +++ b/drivers/reset/reset-lantiq.c @@ -168,7 +168,7 @@ static int lantiq_rcu_reset_probe(struct platform_device *pdev) struct lantiq_rcu_reset_priv *priv; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-lpc18xx.c b/drivers/reset/reset-lpc18xx.c index 8ac9f237e1cebc..631f67b76cf156 100644 --- a/drivers/reset/reset-lpc18xx.c +++ b/drivers/reset/reset-lpc18xx.c @@ -139,7 +139,7 @@ static int lpc18xx_rgu_probe(struct platform_device *pdev) u32 fcclk, firc; int ret; - rc = devm_kzalloc(&pdev->dev, sizeof(*rc), GFP_KERNEL); + rc = devm_kzalloc_obj(&pdev->dev, *rc); if (!rc) return -ENOMEM; diff --git a/drivers/reset/reset-ma35d1.c b/drivers/reset/reset-ma35d1.c index 4ee901f001326d..d2962c0c80bee4 100644 --- a/drivers/reset/reset-ma35d1.c +++ b/drivers/reset/reset-ma35d1.c @@ -199,7 +199,7 @@ static int ma35d1_reset_probe(struct platform_device *pdev) return -EINVAL; } - reset_data = devm_kzalloc(dev, sizeof(*reset_data), GFP_KERNEL); + reset_data = devm_kzalloc_obj(dev, *reset_data); if (!reset_data) return -ENOMEM; diff --git a/drivers/reset/reset-microchip-sparx5.c b/drivers/reset/reset-microchip-sparx5.c index 6d3e75b33260ea..a190c84e1d2372 100644 --- a/drivers/reset/reset-microchip-sparx5.c +++ b/drivers/reset/reset-microchip-sparx5.c @@ -151,7 +151,7 @@ static int mchp_sparx5_reset_probe(struct platform_device *pdev) struct mchp_reset_context *ctx; int err; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/reset/reset-mpfs.c b/drivers/reset/reset-mpfs.c index 8ffcc54ee6f696..e034048fb55246 100644 --- a/drivers/reset/reset-mpfs.c +++ b/drivers/reset/reset-mpfs.c @@ -121,7 +121,7 @@ static int mpfs_reset_mfd_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct mpfs_reset *rst; - rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL); + rst = devm_kzalloc_obj(dev, *rst); if (!rst) return -ENOMEM; @@ -157,7 +157,7 @@ static int mpfs_reset_adev_probe(struct auxiliary_device *adev, struct device *dev = &adev->dev; struct mpfs_reset *rst; - rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL); + rst = devm_kzalloc_obj(dev, *rst); if (!rst) return -ENOMEM; diff --git a/drivers/reset/reset-npcm.c b/drivers/reset/reset-npcm.c index a762d0215e76e5..d083e261933785 100644 --- a/drivers/reset/reset-npcm.c +++ b/drivers/reset/reset-npcm.c @@ -440,7 +440,7 @@ static int npcm_rc_probe(struct platform_device *pdev) struct npcm_rc_data *rc; int ret; - rc = devm_kzalloc(&pdev->dev, sizeof(*rc), GFP_KERNEL); + rc = devm_kzalloc_obj(&pdev->dev, *rc); if (!rc) return -ENOMEM; diff --git a/drivers/reset/reset-pistachio.c b/drivers/reset/reset-pistachio.c index 151ceeb42c3049..d3a28ce7ab068f 100644 --- a/drivers/reset/reset-pistachio.c +++ b/drivers/reset/reset-pistachio.c @@ -105,7 +105,7 @@ static int pistachio_reset_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = pdev->dev.of_node; - rd = devm_kzalloc(dev, sizeof(*rd), GFP_KERNEL); + rd = devm_kzalloc_obj(dev, *rd); if (!rd) return -ENOMEM; diff --git a/drivers/reset/reset-qcom-aoss.c b/drivers/reset/reset-qcom-aoss.c index 93c84d70ef6448..5a6481239fa947 100644 --- a/drivers/reset/reset-qcom-aoss.c +++ b/drivers/reset/reset-qcom-aoss.c @@ -95,7 +95,7 @@ static int qcom_aoss_reset_probe(struct platform_device *pdev) if (!desc) return -EINVAL; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-qcom-pdc.c b/drivers/reset/reset-qcom-pdc.c index ae2b5aba7a5989..70721fe8cd48a1 100644 --- a/drivers/reset/reset-qcom-pdc.c +++ b/drivers/reset/reset-qcom-pdc.c @@ -118,7 +118,7 @@ static int qcom_pdc_reset_probe(struct platform_device *pdev) if (!desc) return -EINVAL; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-raspberrypi.c b/drivers/reset/reset-raspberrypi.c index fa23db554bcf7a..90117ed1788ad1 100644 --- a/drivers/reset/reset-raspberrypi.c +++ b/drivers/reset/reset-raspberrypi.c @@ -87,7 +87,7 @@ static int rpi_reset_probe(struct platform_device *pdev) if (!fw) return -EPROBE_DEFER; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-rzg2l-usbphy-ctrl.c b/drivers/reset/reset-rzg2l-usbphy-ctrl.c index f003b360629c90..ed0d14ed61ab34 100644 --- a/drivers/reset/reset-rzg2l-usbphy-ctrl.c +++ b/drivers/reset/reset-rzg2l-usbphy-ctrl.c @@ -194,7 +194,7 @@ static int rzg2l_usbphy_ctrl_probe(struct platform_device *pdev) struct regmap *regmap; int error; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-rzv2h-usb2phy.c b/drivers/reset/reset-rzv2h-usb2phy.c index d96042e28cd585..8fd989111ea440 100644 --- a/drivers/reset/reset-rzv2h-usb2phy.c +++ b/drivers/reset/reset-rzv2h-usb2phy.c @@ -136,7 +136,7 @@ static int rzv2h_usb2phy_reset_probe(struct platform_device *pdev) void __iomem *base; int error; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c index 4335811e0cfaa5..5cb925321c6c7e 100644 --- a/drivers/reset/reset-scmi.c +++ b/drivers/reset/reset-scmi.c @@ -101,7 +101,7 @@ static int scmi_reset_probe(struct scmi_device *sdev) if (IS_ERR(reset_ops)) return PTR_ERR(reset_ops); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-simple.c b/drivers/reset/reset-simple.c index 79e94ecfe4f553..85e3ac55cccfc0 100644 --- a/drivers/reset/reset-simple.c +++ b/drivers/reset/reset-simple.c @@ -169,7 +169,7 @@ static int reset_simple_probe(struct platform_device *pdev) devdata = of_device_get_match_data(dev); - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-sky1-audss.c b/drivers/reset/reset-sky1-audss.c index d9735db681c7fe..fbdb818ab4c03d 100644 --- a/drivers/reset/reset-sky1-audss.c +++ b/drivers/reset/reset-sky1-audss.c @@ -92,7 +92,7 @@ static int sky1_audss_reset_probe(struct auxiliary_device *adev, struct sky1_audss_reset *priv; struct device *dev = &adev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-sky1.c b/drivers/reset/reset-sky1.c index 78e80a533c3992..18395f09bdf64b 100644 --- a/drivers/reset/reset-sky1.c +++ b/drivers/reset/reset-sky1.c @@ -324,7 +324,7 @@ static int sky1_reset_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; const struct sky1_src_variant *variant; - sky1src = devm_kzalloc(dev, sizeof(*sky1src), GFP_KERNEL); + sky1src = devm_kzalloc_obj(dev, *sky1src); if (!sky1src) return -ENOMEM; diff --git a/drivers/reset/reset-sunplus.c b/drivers/reset/reset-sunplus.c index c136a1f0767a45..c847a151d7e7ce 100644 --- a/drivers/reset/reset-sunplus.c +++ b/drivers/reset/reset-sunplus.c @@ -169,7 +169,7 @@ static int sp_reset_probe(struct platform_device *pdev) struct resource *res; int ret; - reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL); + reset = devm_kzalloc_obj(dev, *reset); if (!reset) return -ENOMEM; diff --git a/drivers/reset/reset-tenstorrent-atlantis.c b/drivers/reset/reset-tenstorrent-atlantis.c index ab8be52fdd5e41..0b976c10ae21ca 100644 --- a/drivers/reset/reset-tenstorrent-atlantis.c +++ b/drivers/reset/reset-tenstorrent-atlantis.c @@ -145,7 +145,7 @@ static int atlantis_reset_probe(struct auxiliary_device *adev, if (!regmap) return -ENODEV; - controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL); + controller = devm_kzalloc_obj(dev, *controller); if (!controller) return -ENOMEM; controller->data = diff --git a/drivers/reset/reset-th1520.c b/drivers/reset/reset-th1520.c index fd32e991c4cbc7..c89f8a9c7d39a2 100644 --- a/drivers/reset/reset-th1520.c +++ b/drivers/reset/reset-th1520.c @@ -897,7 +897,7 @@ static int th1520_reset_probe(struct platform_device *pdev) data = device_get_match_data(dev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-ti-sci.c b/drivers/reset/reset-ti-sci.c index 1dc5b766aac1fe..11b42f133ed75c 100644 --- a/drivers/reset/reset-ti-sci.c +++ b/drivers/reset/reset-ti-sci.c @@ -190,7 +190,7 @@ static int ti_sci_reset_of_xlate(struct reset_controller_dev *rcdev, if (WARN_ON(reset_spec->args_count != rcdev->of_reset_n_cells)) return -EINVAL; - control = devm_kzalloc(data->dev, sizeof(*control), GFP_KERNEL); + control = devm_kzalloc_obj(data->dev, *control); if (!control) return -ENOMEM; @@ -214,7 +214,7 @@ static int ti_sci_reset_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-ti-syscon.c b/drivers/reset/reset-ti-syscon.c index 23f86ddb8668cb..6d10ea3a192167 100644 --- a/drivers/reset/reset-ti-syscon.c +++ b/drivers/reset/reset-ti-syscon.c @@ -166,7 +166,7 @@ static int ti_syscon_reset_probe(struct platform_device *pdev) struct ti_syscon_reset_control *controls; int size, nr_controls, i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -181,8 +181,7 @@ static int ti_syscon_reset_probe(struct platform_device *pdev) } nr_controls = (size / sizeof(*list)) / 7; - controls = devm_kcalloc(dev, nr_controls, sizeof(*controls), - GFP_KERNEL); + controls = devm_kzalloc_objs(dev, *controls, nr_controls); if (!controls) return -ENOMEM; diff --git a/drivers/reset/reset-tn48m.c b/drivers/reset/reset-tn48m.c index 177ee5127a1e30..81a89299f8c66f 100644 --- a/drivers/reset/reset-tn48m.c +++ b/drivers/reset/reset-tn48m.c @@ -93,7 +93,7 @@ static int tn48m_reset_probe(struct platform_device *pdev) if (!regmap) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/reset-tps380x.c b/drivers/reset/reset-tps380x.c index 09d511f069ba24..f07fec0fc0400e 100644 --- a/drivers/reset/reset-tps380x.c +++ b/drivers/reset/reset-tps380x.c @@ -78,7 +78,7 @@ static int tps380x_reset_probe(struct platform_device *pdev) if (!devdata) return -EINVAL; - tps380x = devm_kzalloc(dev, sizeof(*tps380x), GFP_KERNEL); + tps380x = devm_kzalloc_obj(dev, *tps380x); if (!tps380x) return -ENOMEM; diff --git a/drivers/reset/reset-uniphier-glue.c b/drivers/reset/reset-uniphier-glue.c index a2a262bf6bfc71..9575e02a009484 100644 --- a/drivers/reset/reset-uniphier-glue.c +++ b/drivers/reset/reset-uniphier-glue.c @@ -42,7 +42,7 @@ static int uniphier_glue_reset_probe(struct platform_device *pdev) struct resource *res; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c index 79c43c204d46f2..aef8ccebf75a3c 100644 --- a/drivers/reset/reset-uniphier.c +++ b/drivers/reset/reset-uniphier.c @@ -362,7 +362,7 @@ static int uniphier_reset_probe(struct platform_device *pdev) return PTR_ERR(regmap); } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-zynq.c b/drivers/reset/reset-zynq.c index 688b512882ec81..fd4a90aa5b7ce7 100644 --- a/drivers/reset/reset-zynq.c +++ b/drivers/reset/reset-zynq.c @@ -91,7 +91,7 @@ static int zynq_reset_probe(struct platform_device *pdev) struct resource *res; struct zynq_reset_data *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/reset-zynqmp.c b/drivers/reset/reset-zynqmp.c index c770ea3a189435..58865161c931a2 100644 --- a/drivers/reset/reset-zynqmp.c +++ b/drivers/reset/reset-zynqmp.c @@ -104,7 +104,7 @@ static int zynqmp_reset_probe(struct platform_device *pdev) { struct zynqmp_reset_data *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/reset/spacemit/reset-spacemit-common.c b/drivers/reset/spacemit/reset-spacemit-common.c index 0626633a5e7db6..2d96f9f769e045 100644 --- a/drivers/reset/spacemit/reset-spacemit-common.c +++ b/drivers/reset/spacemit/reset-spacemit-common.c @@ -63,7 +63,7 @@ int spacemit_reset_probe(struct auxiliary_device *adev, struct ccu_reset_controller *controller; struct device *dev = &adev->dev; - controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL); + controller = devm_kzalloc_obj(dev, *controller); if (!controller) return -ENOMEM; controller->data = (const struct ccu_reset_controller_data *)id->driver_data; diff --git a/drivers/reset/starfive/reset-starfive-jh71x0.c b/drivers/reset/starfive/reset-starfive-jh71x0.c index 29ce3486752f38..d410a5a0ded400 100644 --- a/drivers/reset/starfive/reset-starfive-jh71x0.c +++ b/drivers/reset/starfive/reset-starfive-jh71x0.c @@ -114,7 +114,7 @@ int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_no { struct jh71x0_reset *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/reset/sti/reset-syscfg.c b/drivers/reset/sti/reset-syscfg.c index 38f78d78fa4fb2..ed50ff564977d0 100644 --- a/drivers/reset/sti/reset-syscfg.c +++ b/drivers/reset/sti/reset-syscfg.c @@ -135,7 +135,7 @@ static int syscfg_reset_controller_register(struct device *dev, struct syscfg_reset_controller *rc; int i, err; - rc = devm_kzalloc(dev, struct_size(rc, channels, data->nr_channels), GFP_KERNEL); + rc = devm_kzalloc_flex(dev, *rc, channels, data->nr_channels); if (!rc) return -ENOMEM; diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 55793fc18293b2..f848ab46161d17 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1894,7 +1894,7 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev, int ret; struct qcom_glink *glink; - glink = devm_kzalloc(dev, sizeof(*glink), GFP_KERNEL); + glink = devm_kzalloc_obj(dev, *glink); if (!glink) return ERR_PTR(-ENOMEM); diff --git a/drivers/rpmsg/qcom_glink_rpm.c b/drivers/rpmsg/qcom_glink_rpm.c index e3ba2c63a5fce5..0d4465d4f59855 100644 --- a/drivers/rpmsg/qcom_glink_rpm.c +++ b/drivers/rpmsg/qcom_glink_rpm.c @@ -296,7 +296,7 @@ static int glink_rpm_probe(struct platform_device *pdev) struct resource r; int ret; - rpm = devm_kzalloc(&pdev->dev, sizeof(*rpm), GFP_KERNEL); + rpm = devm_kzalloc_obj(&pdev->dev, *rpm); if (!rpm) return -ENOMEM; diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c index 35bb03e67ae8a1..a35f41cb2e01dc 100644 --- a/drivers/rpmsg/qcom_glink_smem.c +++ b/drivers/rpmsg/qcom_glink_smem.c @@ -263,8 +263,8 @@ struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, smem->remote_pid = remote_pid; - rx_pipe = devm_kzalloc(dev, sizeof(*rx_pipe), GFP_KERNEL); - tx_pipe = devm_kzalloc(dev, sizeof(*tx_pipe), GFP_KERNEL); + rx_pipe = devm_kzalloc_obj(dev, *rx_pipe); + tx_pipe = devm_kzalloc_obj(dev, *tx_pipe); if (!rx_pipe || !tx_pipe) { ret = -ENOMEM; goto err_put_dev; diff --git a/drivers/rpmsg/qcom_glink_ssr.c b/drivers/rpmsg/qcom_glink_ssr.c index e71d3716c55c5c..950f711a47ed5c 100644 --- a/drivers/rpmsg/qcom_glink_ssr.c +++ b/drivers/rpmsg/qcom_glink_ssr.c @@ -128,7 +128,7 @@ static int qcom_glink_ssr_probe(struct rpmsg_device *rpdev) { struct glink_ssr *ssr; - ssr = devm_kzalloc(&rpdev->dev, sizeof(*ssr), GFP_KERNEL); + ssr = devm_kzalloc_obj(&rpdev->dev, *ssr); if (!ssr) return -ENOMEM; diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c index a3e52a5a708ff3..0f2b37eb0d691f 100644 --- a/drivers/rtc/rtc-88pm80x.c +++ b/drivers/rtc/rtc-88pm80x.c @@ -251,7 +251,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev) } if (!pdata) { - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) { dev_err(&pdev->dev, "failed to allocate memory\n"); return -ENOMEM; @@ -259,7 +259,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev) } info = - devm_kzalloc(&pdev->dev, sizeof(struct pm80x_rtc_info), GFP_KERNEL); + devm_kzalloc_obj(&pdev->dev, struct pm80x_rtc_info); if (!info) return -ENOMEM; info->irq = platform_get_irq(pdev, 0); diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index 964cd048fcdba7..5d23d2cc231ded 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -270,8 +270,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev) struct pm860x_rtc_info *info; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct pm860x_rtc_info); if (!info) return -ENOMEM; info->irq = platform_get_irq(pdev, 0); diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c index 6439ca427c32b4..81d75ab401ec7e 100644 --- a/drivers/rtc/rtc-ab-b5ze-s3.c +++ b/drivers/rtc/rtc-ab-b5ze-s3.c @@ -841,7 +841,7 @@ static int abb5zes3_probe(struct i2c_client *client) if (ret) return ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/rtc/rtc-ab-eoz9.c b/drivers/rtc/rtc-ab-eoz9.c index eb6d267c2ec34d..f339d0396481a8 100644 --- a/drivers/rtc/rtc-ab-eoz9.c +++ b/drivers/rtc/rtc-ab-eoz9.c @@ -485,7 +485,7 @@ static int abeoz9_probe(struct i2c_client *client) return ret; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index 1c69d0e2f940da..02eaaf58dabdcf 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -785,7 +785,7 @@ static int abx80x_probe(struct device *dev, struct regmap *regmap, int irq, unsigned int wafer; unsigned int uid; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (priv == NULL) return -ENOMEM; diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c index c6fca15af241cf..be57a33ecf53e2 100644 --- a/drivers/rtc/rtc-ac100.c +++ b/drivers/rtc/rtc-ac100.c @@ -310,10 +310,8 @@ static int ac100_rtc_register_clks(struct ac100_rtc_dev *chip) const char *parents[2] = {AC100_RTC_32K_NAME}; int i, ret; - chip->clk_data = devm_kzalloc(chip->dev, - struct_size(chip->clk_data, hws, - AC100_CLKOUT_NUM), - GFP_KERNEL); + chip->clk_data = devm_kzalloc_flex(chip->dev, *chip->clk_data, hws, + AC100_CLKOUT_NUM); if (!chip->clk_data) return -ENOMEM; @@ -555,7 +553,7 @@ static int ac100_rtc_probe(struct platform_device *pdev) struct ac100_rtc_dev *chip; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/rtc/rtc-amlogic-a4.c b/drivers/rtc/rtc-amlogic-a4.c index 50938c35af36a6..1e42d981485d16 100644 --- a/drivers/rtc/rtc-amlogic-a4.c +++ b/drivers/rtc/rtc-amlogic-a4.c @@ -328,7 +328,7 @@ static int aml_rtc_probe(struct platform_device *pdev) .max_register = RTC_REAL_TIME, }; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c index 245290ae1a8de6..30eb103595f18b 100644 --- a/drivers/rtc/rtc-armada38x.c +++ b/drivers/rtc/rtc-armada38x.c @@ -490,8 +490,7 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev) { struct armada38x_rtc *rtc; - rtc = devm_kzalloc(&pdev->dev, struct_size(rtc, val_to_freq, SAMPLE_NR), - GFP_KERNEL); + rtc = devm_kzalloc_flex(&pdev->dev, *rtc, val_to_freq, SAMPLE_NR); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-as3722.c b/drivers/rtc/rtc-as3722.c index 9682d6457b7fd1..b9199d31cd848f 100644 --- a/drivers/rtc/rtc-as3722.c +++ b/drivers/rtc/rtc-as3722.c @@ -170,7 +170,7 @@ static int as3722_rtc_probe(struct platform_device *pdev) struct as3722_rtc *as3722_rtc; int ret; - as3722_rtc = devm_kzalloc(&pdev->dev, sizeof(*as3722_rtc), GFP_KERNEL); + as3722_rtc = devm_kzalloc_obj(&pdev->dev, *as3722_rtc); if (!as3722_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-asm9260.c b/drivers/rtc/rtc-asm9260.c index 422c2e5d83aa49..95d7b894acd5de 100644 --- a/drivers/rtc/rtc-asm9260.c +++ b/drivers/rtc/rtc-asm9260.c @@ -246,7 +246,7 @@ static int asm9260_rtc_probe(struct platform_device *pdev) int irq_alarm, ret; u32 ccr; - priv = devm_kzalloc(dev, sizeof(struct asm9260_rtc_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct asm9260_rtc_priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c index 8f5b440f8c0a97..25192ebdad190c 100644 --- a/drivers/rtc/rtc-aspeed.c +++ b/drivers/rtc/rtc-aspeed.c @@ -86,7 +86,7 @@ static int aspeed_rtc_probe(struct platform_device *pdev) struct aspeed_rtc *rtc; struct rtc_device *rtc_dev; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 38991cca593086..cbd2f1a6c54acc 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -344,7 +344,7 @@ static int at91_rtc_probe(struct platform_device *pdev) if (irq < 0) return irq; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-atcrtc100.c b/drivers/rtc/rtc-atcrtc100.c index 2433df386c4038..25183331a158dd 100644 --- a/drivers/rtc/rtc-atcrtc100.c +++ b/drivers/rtc/rtc-atcrtc100.c @@ -272,7 +272,7 @@ static int atcrtc_probe(struct platform_device *pdev) unsigned int rtc_id; int ret; - atcrtc_dev = devm_kzalloc(&pdev->dev, sizeof(*atcrtc_dev), GFP_KERNEL); + atcrtc_dev = devm_kzalloc_obj(&pdev->dev, *atcrtc_dev); if (!atcrtc_dev) return -ENOMEM; platform_set_drvdata(pdev, atcrtc_dev); diff --git a/drivers/rtc/rtc-bd70528.c b/drivers/rtc/rtc-bd70528.c index dd5569d175677f..b9d27e169b8854 100644 --- a/drivers/rtc/rtc-bd70528.c +++ b/drivers/rtc/rtc-bd70528.c @@ -246,7 +246,7 @@ static int bd70528_probe(struct platform_device *pdev) u8 hour_reg; enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; - bd_rtc = devm_kzalloc(&pdev->dev, sizeof(*bd_rtc), GFP_KERNEL); + bd_rtc = devm_kzalloc_obj(&pdev->dev, *bd_rtc); if (!bd_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c index 472e7566891740..4a9903f996d676 100644 --- a/drivers/rtc/rtc-bq4802.c +++ b/drivers/rtc/rtc-bq4802.c @@ -141,7 +141,7 @@ static const struct rtc_class_ops bq4802_ops = { static int bq4802_probe(struct platform_device *pdev) { - struct bq4802 *p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); + struct bq4802 *p = devm_kzalloc_obj(&pdev->dev, *p); int err = -ENOMEM; if (!p) diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c index 55c15aad42cff4..6f73def04ad964 100644 --- a/drivers/rtc/rtc-brcmstb-waketimer.c +++ b/drivers/rtc/rtc-brcmstb-waketimer.c @@ -276,7 +276,7 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev) struct brcmstb_waketmr *timer; int ret; - timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); + timer = devm_kzalloc_obj(dev, *timer); if (!timer) return -ENOMEM; diff --git a/drivers/rtc/rtc-cadence.c b/drivers/rtc/rtc-cadence.c index 8634eea799ab0e..711ba97d4cfbb3 100644 --- a/drivers/rtc/rtc-cadence.c +++ b/drivers/rtc/rtc-cadence.c @@ -258,7 +258,7 @@ static int cdns_rtc_probe(struct platform_device *pdev) int ret; unsigned long ref_clk_freq; - crtc = devm_kzalloc(&pdev->dev, sizeof(*crtc), GFP_KERNEL); + crtc = devm_kzalloc_obj(&pdev->dev, *crtc); if (!crtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-cpcap.c b/drivers/rtc/rtc-cpcap.c index a7db3173d24c5b..d6c4b273099426 100644 --- a/drivers/rtc/rtc-cpcap.c +++ b/drivers/rtc/rtc-cpcap.c @@ -246,7 +246,7 @@ static int cpcap_rtc_probe(struct platform_device *pdev) struct cpcap_rtc *rtc; int err; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c index f56650899b3780..293dd1dad6d1f4 100644 --- a/drivers/rtc/rtc-cros-ec.c +++ b/drivers/rtc/rtc-cros-ec.c @@ -315,8 +315,7 @@ static int cros_ec_rtc_probe(struct platform_device *pdev) struct rtc_time tm; int ret; - cros_ec_rtc = devm_kzalloc(&pdev->dev, sizeof(*cros_ec_rtc), - GFP_KERNEL); + cros_ec_rtc = devm_kzalloc_obj(&pdev->dev, *cros_ec_rtc); if (!cros_ec_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-cv1800.c b/drivers/rtc/rtc-cv1800.c index 678c2c10bf5809..b9f35a0dd17747 100644 --- a/drivers/rtc/rtc-cv1800.c +++ b/drivers/rtc/rtc-cv1800.c @@ -160,7 +160,7 @@ static int cv1800_rtc_probe(struct platform_device *pdev) struct cv1800_rtc_priv *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c index 9ca99bd3570223..a0b0e224c6ae38 100644 --- a/drivers/rtc/rtc-da9052.c +++ b/drivers/rtc/rtc-da9052.c @@ -276,7 +276,7 @@ static int da9052_rtc_probe(struct platform_device *pdev) struct da9052_rtc *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(struct da9052_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, struct da9052_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c index 05adec6b77bff9..8c1cee091282d5 100644 --- a/drivers/rtc/rtc-da9055.c +++ b/drivers/rtc/rtc-da9055.c @@ -269,7 +269,7 @@ static int da9055_rtc_probe(struct platform_device *pdev) struct da9055_pdata *pdata = NULL; int ret, alm_irq; - rtc = devm_kzalloc(&pdev->dev, sizeof(struct da9055_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, struct da9055_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c index 557c9b29dcc14c..b56b9d9cb4e5ce 100644 --- a/drivers/rtc/rtc-da9063.c +++ b/drivers/rtc/rtc-da9063.c @@ -366,7 +366,7 @@ static int da9063_rtc_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENXIO; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c index 218a6de19247a4..4f04bc60fbd2a9 100644 --- a/drivers/rtc/rtc-digicolor.c +++ b/drivers/rtc/rtc-digicolor.c @@ -178,7 +178,7 @@ static int __init dc_rtc_probe(struct platform_device *pdev) struct dc_rtc *rtc; int irq, ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c index 7eeb3f359de832..2b450edb6548c4 100644 --- a/drivers/rtc/rtc-ds1216.c +++ b/drivers/rtc/rtc-ds1216.c @@ -140,7 +140,7 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev) struct ds1216_priv *priv; u8 dummy[8]; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c index 7acf849d4902a9..648a705c55e952 100644 --- a/drivers/rtc/rtc-ds1286.c +++ b/drivers/rtc/rtc-ds1286.c @@ -325,7 +325,7 @@ static int ds1286_probe(struct platform_device *pdev) struct rtc_device *rtc; struct ds1286_priv *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(struct ds1286_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct ds1286_priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c index 19a32d3476b5db..20c6e4cfd1df19 100644 --- a/drivers/rtc/rtc-ds1305.c +++ b/drivers/rtc/rtc-ds1305.c @@ -564,7 +564,7 @@ static int ds1305_probe(struct spi_device *spi) return -EINVAL; /* set up driver data */ - ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL); + ds1305 = devm_kzalloc_obj(&spi->dev, *ds1305); if (!ds1305) return -ENOMEM; ds1305->spi = spi; diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 206a79d2856820..8ab28cc2f1815d 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -1622,13 +1622,13 @@ static int ds3231_clks_register(struct ds1307 *ds1307) struct clk_onecell_data *onecell; int i; - onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL); + onecell = devm_kzalloc_obj(ds1307->dev, *onecell); if (!onecell) return -ENOMEM; onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); - onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, - sizeof(onecell->clks[0]), GFP_KERNEL); + onecell->clks = devm_kzalloc_objs(ds1307->dev, onecell->clks[0], + onecell->clk_num); if (!onecell->clks) return -ENOMEM; @@ -1843,7 +1843,7 @@ static void ds1307_wdt_register(struct ds1307 *ds1307) if (ds1307->type != ds_1388) return; - wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(ds1307->dev, *wdt); if (!wdt) return; @@ -1886,7 +1886,7 @@ static int ds1307_probe(struct i2c_client *client) struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); u8 trickle_charger_setup = 0; - ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); + ds1307 = devm_kzalloc_obj(&client->dev, struct ds1307); if (!ds1307) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c index 0ec5eaba6bd429..455ed8582e8d4a 100644 --- a/drivers/rtc/rtc-ds1343.c +++ b/drivers/rtc/rtc-ds1343.c @@ -355,7 +355,7 @@ static int ds1343_probe(struct spi_device *spi) .reg_write = ds1343_nvram_write, }; - priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, struct ds1343_priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index 2ed6777e7035e3..6ee2b31ca12055 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c @@ -473,7 +473,7 @@ static int ds1374_probe(struct i2c_client *client) struct ds1374 *ds1374; int ret; - ds1374 = devm_kzalloc(&client->dev, sizeof(struct ds1374), GFP_KERNEL); + ds1374 = devm_kzalloc_obj(&client->dev, struct ds1374); if (!ds1374) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c index f7afd6bdeb4a8e..0c51ee4d097d74 100644 --- a/drivers/rtc/rtc-ds1390.c +++ b/drivers/rtc/rtc-ds1390.c @@ -188,7 +188,7 @@ static int ds1390_probe(struct spi_device *spi) spi->bits_per_word = 8; spi_setup(spi); - chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&spi->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c index 8b087d9556bee8..1afc0df49670b2 100644 --- a/drivers/rtc/rtc-ds1511.c +++ b/drivers/rtc/rtc-ds1511.c @@ -283,7 +283,7 @@ static int ds1511_rtc_probe(struct platform_device *pdev) .priv = &pdev->dev, }; - ds1511 = devm_kzalloc(&pdev->dev, sizeof(*ds1511), GFP_KERNEL); + ds1511 = devm_kzalloc_obj(&pdev->dev, *ds1511); if (!ds1511) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c index dbff5b621ef5cc..3e65b2a4eadbd6 100644 --- a/drivers/rtc/rtc-ds1553.c +++ b/drivers/rtc/rtc-ds1553.c @@ -263,7 +263,7 @@ static int ds1553_rtc_probe(struct platform_device *pdev) .priv = pdev, }; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c index 3d0f491d0e88ee..f27d6ae4f78314 100644 --- a/drivers/rtc/rtc-ds1685.c +++ b/drivers/rtc/rtc-ds1685.c @@ -1085,7 +1085,7 @@ ds1685_rtc_probe(struct platform_device *pdev) return -ENODEV; /* Allocate memory for the rtc device. */ - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c index 6ae8b9a294feef..c8593626c622c1 100644 --- a/drivers/rtc/rtc-ds1742.c +++ b/drivers/rtc/rtc-ds1742.c @@ -153,7 +153,7 @@ static int ds1742_rtc_probe(struct platform_device *pdev) }; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c index 217694eca36c34..07fe7637676ce6 100644 --- a/drivers/rtc/rtc-ds2404.c +++ b/drivers/rtc/rtc-ds2404.c @@ -184,7 +184,7 @@ static int rtc_probe(struct platform_device *pdev) struct rtc_device *rtc; int retval = -EBUSY; - chip = devm_kzalloc(&pdev->dev, sizeof(struct ds2404), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, struct ds2404); if (!chip) return -ENOMEM; diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c index f6407c631d6d0d..75ac99b192fb7d 100644 --- a/drivers/rtc/rtc-ds3232.c +++ b/drivers/rtc/rtc-ds3232.c @@ -468,7 +468,7 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, .type = NVMEM_TYPE_BATTERY_BACKED }; - ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); + ds3232 = devm_kzalloc_obj(dev, *ds3232); if (!ds3232) return -ENOMEM; diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c index f105aba2845963..6eab05fb8d420f 100644 --- a/drivers/rtc/rtc-ep93xx.c +++ b/drivers/rtc/rtc-ep93xx.c @@ -124,7 +124,7 @@ static int ep93xx_rtc_probe(struct platform_device *pdev) struct rtc_device *rtc; int err; - ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL); + ep93xx_rtc = devm_kzalloc_obj(&pdev->dev, *ep93xx_rtc); if (!ep93xx_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c index 28bb6d3f644eb5..7e43a51c62ea27 100644 --- a/drivers/rtc/rtc-fm3130.c +++ b/drivers/rtc/rtc-fm3130.c @@ -351,7 +351,7 @@ static int fm3130_probe(struct i2c_client *client) I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) return -EIO; - fm3130 = devm_kzalloc(&client->dev, sizeof(struct fm3130), GFP_KERNEL); + fm3130 = devm_kzalloc_obj(&client->dev, struct fm3130); if (!fm3130) return -ENOMEM; diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c index dcb7ef663a78f1..5473f697d4eab4 100644 --- a/drivers/rtc/rtc-fsl-ftm-alarm.c +++ b/drivers/rtc/rtc-fsl-ftm-alarm.c @@ -246,7 +246,7 @@ static int ftm_rtc_probe(struct platform_device *pdev) int ret; struct ftm_rtc *rtc; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (unlikely(!rtc)) { dev_err(&pdev->dev, "cannot alloc memory for rtc\n"); return -ENOMEM; diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c index c66d4a85f23c1a..d3331a70f4c7e5 100644 --- a/drivers/rtc/rtc-ftrtc010.c +++ b/drivers/rtc/rtc-ftrtc010.c @@ -114,7 +114,7 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev) struct rtc_device *rtc_dev; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (unlikely(!rtc)) return -ENOMEM; platform_set_drvdata(pdev, rtc); diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c index 889028cecf4a56..3fd562d3526af2 100644 --- a/drivers/rtc/rtc-gamecube.c +++ b/drivers/rtc/rtc-gamecube.c @@ -323,7 +323,7 @@ static int gamecube_rtc_probe(struct platform_device *pdev) struct priv *d; int ret; - d = devm_kzalloc(dev, sizeof(struct priv), GFP_KERNEL); + d = devm_kzalloc_obj(dev, struct priv); if (!d) return -ENOMEM; diff --git a/drivers/rtc/rtc-goldfish.c b/drivers/rtc/rtc-goldfish.c index 53ec7173c28ec4..c77d966e49e954 100644 --- a/drivers/rtc/rtc-goldfish.c +++ b/drivers/rtc/rtc-goldfish.c @@ -158,7 +158,7 @@ static int goldfish_rtc_probe(struct platform_device *pdev) struct goldfish_rtc *rtcdrv; int err; - rtcdrv = devm_kzalloc(&pdev->dev, sizeof(*rtcdrv), GFP_KERNEL); + rtcdrv = devm_kzalloc_obj(&pdev->dev, *rtcdrv); if (!rtcdrv) return -ENOMEM; diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index 6228d0b2486e9f..911711c45f1406 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -223,8 +223,8 @@ static int hid_time_probe(struct platform_device *pdev) { int ret = 0; struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); - struct hid_time_state *time_state = devm_kzalloc(&pdev->dev, - sizeof(struct hid_time_state), GFP_KERNEL); + struct hid_time_state *time_state = devm_kzalloc_obj(&pdev->dev, + struct hid_time_state); if (time_state == NULL) return -ENOMEM; diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c index e3d7ca477e7510..62726eaf57c1b7 100644 --- a/drivers/rtc/rtc-hym8563.c +++ b/drivers/rtc/rtc-hym8563.c @@ -503,7 +503,7 @@ static int hym8563_probe(struct i2c_client *client) struct hym8563 *hym8563; int ret; - hym8563 = devm_kzalloc(&client->dev, sizeof(*hym8563), GFP_KERNEL); + hym8563 = devm_kzalloc_obj(&client->dev, *hym8563); if (!hym8563) return -ENOMEM; diff --git a/drivers/rtc/rtc-imx-sm-bbm.c b/drivers/rtc/rtc-imx-sm-bbm.c index daa472be7c8069..c260c7436a35f7 100644 --- a/drivers/rtc/rtc-imx-sm-bbm.c +++ b/drivers/rtc/rtc-imx-sm-bbm.c @@ -123,7 +123,7 @@ static int scmi_imx_bbm_rtc_probe(struct scmi_device *sdev) if (!handle) return -ENODEV; - bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); + bbnsm = devm_kzalloc_obj(dev, *bbnsm); if (!bbnsm) return -ENOMEM; diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c index ca4a0af95e8c5a..4066e32b58f23f 100644 --- a/drivers/rtc/rtc-imxdi.c +++ b/drivers/rtc/rtc-imxdi.c @@ -745,7 +745,7 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) int norm_irq, sec_irq; int rc; - imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL); + imxdi = devm_kzalloc_obj(&pdev->dev, *imxdi); if (!imxdi) return -ENOMEM; diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c index bc36288854ee7a..ebd69b4693dc06 100644 --- a/drivers/rtc/rtc-isl12022.c +++ b/drivers/rtc/rtc-isl12022.c @@ -558,7 +558,7 @@ static int isl12022_probe(struct i2c_client *client) return -ENODEV; /* Allocate driver state */ - isl12022 = devm_kzalloc(&client->dev, sizeof(*isl12022), GFP_KERNEL); + isl12022 = devm_kzalloc_obj(&client->dev, *isl12022); if (!isl12022) return -ENOMEM; diff --git a/drivers/rtc/rtc-isl12026.c b/drivers/rtc/rtc-isl12026.c index b86a325d8a23f1..2aa3694c4de70a 100644 --- a/drivers/rtc/rtc-isl12026.c +++ b/drivers/rtc/rtc-isl12026.c @@ -445,7 +445,7 @@ static int isl12026_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&client->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c index ee2eb8c475eab3..5150a1051e01ce 100644 --- a/drivers/rtc/rtc-isl1208.c +++ b/drivers/rtc/rtc-isl1208.c @@ -881,7 +881,7 @@ isl1208_probe(struct i2c_client *client) return -ENODEV; /* Allocate driver state, point i2c client data to it */ - isl1208 = devm_kzalloc(&client->dev, sizeof(*isl1208), GFP_KERNEL); + isl1208 = devm_kzalloc_obj(&client->dev, *isl1208); if (!isl1208) return -ENOMEM; i2c_set_clientdata(client, isl1208); diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 11fce47be780bb..32c331f3feb356 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -345,7 +345,7 @@ static int jz4740_rtc_probe(struct platform_device *pdev) struct clk *clk; int ret, irq; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-loongson.c b/drivers/rtc/rtc-loongson.c index 066f0644d1c3fb..d337241b6f123d 100644 --- a/drivers/rtc/rtc-loongson.c +++ b/drivers/rtc/rtc-loongson.c @@ -344,7 +344,7 @@ static int loongson_rtc_probe(struct platform_device *pdev) struct loongson_rtc_priv *priv; struct device *dev = &pdev->dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-lp8788.c b/drivers/rtc/rtc-lp8788.c index 0793d70507f7c6..1deda55cf2f84d 100644 --- a/drivers/rtc/rtc-lp8788.c +++ b/drivers/rtc/rtc-lp8788.c @@ -285,7 +285,7 @@ static int lp8788_rtc_probe(struct platform_device *pdev) struct lp8788_rtc *rtc; struct device *dev = &pdev->dev; - rtc = devm_kzalloc(dev, sizeof(struct lp8788_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, struct lp8788_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-lpc24xx.c b/drivers/rtc/rtc-lpc24xx.c index a1266986dead52..04a09bdf807dce 100644 --- a/drivers/rtc/rtc-lpc24xx.c +++ b/drivers/rtc/rtc-lpc24xx.c @@ -194,7 +194,7 @@ static int lpc24xx_rtc_probe(struct platform_device *pdev) struct lpc24xx_rtc *rtc; int irq, ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c index 74280bffe1b07f..a78030f2d96486 100644 --- a/drivers/rtc/rtc-lpc32xx.c +++ b/drivers/rtc/rtc-lpc32xx.c @@ -189,7 +189,7 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) int err; u32 tmp; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (unlikely(!rtc)) return -ENOMEM; diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 1385cb43864bae..cfab27aaa51891 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c @@ -912,8 +912,7 @@ static int m41t80_probe(struct i2c_client *client) return -ENODEV; } - m41t80_data = devm_kzalloc(&client->dev, sizeof(*m41t80_data), - GFP_KERNEL); + m41t80_data = devm_kzalloc_obj(&client->dev, *m41t80_data); if (!m41t80_data) return -ENOMEM; diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c index fa7a4b5f848dfe..fa97251f24820e 100644 --- a/drivers/rtc/rtc-m41t93.c +++ b/drivers/rtc/rtc-m41t93.c @@ -524,7 +524,7 @@ static int m41t93_probe(struct spi_device *spi) spi->bits_per_word = 8; spi_setup(spi); - m41t93 = devm_kzalloc(&spi->dev, sizeof(struct m41t93_data), GFP_KERNEL); + m41t93 = devm_kzalloc_obj(&spi->dev, struct m41t93_data); if (!m41t93) return -ENOMEM; diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c index 92f19bf997b2f8..ddcd1a17c28177 100644 --- a/drivers/rtc/rtc-m48t35.c +++ b/drivers/rtc/rtc-m48t35.c @@ -155,7 +155,7 @@ static int m48t35_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(struct m48t35_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct m48t35_priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index 4e608bc8bbd369..1208ebfc7a7f0d 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c @@ -369,8 +369,7 @@ static int m48t59_rtc_probe(struct platform_device *pdev) } else if (res->flags & IORESOURCE_MEM) { /* we are memory-mapped */ if (!pdata) { - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; /* Ensure we only kmalloc platform data once */ @@ -386,7 +385,7 @@ static int m48t59_rtc_probe(struct platform_device *pdev) pdata->read_byte = m48t59_mem_readb; } - m48t59 = devm_kzalloc(&pdev->dev, sizeof(*m48t59), GFP_KERNEL); + m48t59 = devm_kzalloc_obj(&pdev->dev, *m48t59); if (!m48t59) return -ENOMEM; diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c index db3bdb171ff0f7..d0f7f146bd65f3 100644 --- a/drivers/rtc/rtc-m48t86.c +++ b/drivers/rtc/rtc-m48t86.c @@ -230,7 +230,7 @@ static int m48t86_rtc_probe(struct platform_device *pdev) .priv = &pdev->dev, }; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-ma35d1.c b/drivers/rtc/rtc-ma35d1.c index cfcfc28060f621..eb0da8b091dc9d 100644 --- a/drivers/rtc/rtc-ma35d1.c +++ b/drivers/rtc/rtc-ma35d1.c @@ -213,7 +213,7 @@ static int ma35d1_rtc_probe(struct platform_device *pdev) struct clk *clk; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-macsmc.c b/drivers/rtc/rtc-macsmc.c index 8fe88306695691..f01b3dab34ee5c 100644 --- a/drivers/rtc/rtc-macsmc.c +++ b/drivers/rtc/rtc-macsmc.c @@ -95,7 +95,7 @@ static int macsmc_rtc_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-max31335.c b/drivers/rtc/rtc-max31335.c index 59581697385115..1953921f8335c2 100644 --- a/drivers/rtc/rtc-max31335.c +++ b/drivers/rtc/rtc-max31335.c @@ -678,7 +678,7 @@ static int max31335_probe(struct i2c_client *client) const struct chip_desc *match; int ret; - max31335 = devm_kzalloc(&client->dev, sizeof(*max31335), GFP_KERNEL); + max31335 = devm_kzalloc_obj(&client->dev, *max31335); if (!max31335) return -ENOMEM; diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c index 375565a3bddfb8..fc7756c80240a6 100644 --- a/drivers/rtc/rtc-max77686.c +++ b/drivers/rtc/rtc-max77686.c @@ -753,8 +753,7 @@ static int max77686_rtc_probe(struct platform_device *pdev) const struct platform_device_id *id = platform_get_device_id(pdev); int ret; - info = devm_kzalloc(&pdev->dev, sizeof(struct max77686_rtc_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max77686_rtc_info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c index af97140dd00a5c..14b8639259caa5 100644 --- a/drivers/rtc/rtc-max8907.c +++ b/drivers/rtc/rtc-max8907.c @@ -177,7 +177,7 @@ static int max8907_rtc_probe(struct platform_device *pdev) struct max8907_rtc *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; platform_set_drvdata(pdev, rtc); diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c index 6ce8afbeac6802..f998fabe3e5b2b 100644 --- a/drivers/rtc/rtc-max8925.c +++ b/drivers/rtc/rtc-max8925.c @@ -248,8 +248,7 @@ static int max8925_rtc_probe(struct platform_device *pdev) struct max8925_rtc_info *info; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_rtc_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8925_rtc_info); if (!info) return -ENOMEM; info->chip = chip; diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c index 89203c92e2cd5a..c0bd6c5edb1d90 100644 --- a/drivers/rtc/rtc-max8997.c +++ b/drivers/rtc/rtc-max8997.c @@ -451,8 +451,7 @@ static int max8997_rtc_probe(struct platform_device *pdev) struct max8997_rtc_info *info; int ret, virq; - info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_rtc_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8997_rtc_info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c index a2c946edcd1a96..07dec77aa28214 100644 --- a/drivers/rtc/rtc-max8998.c +++ b/drivers/rtc/rtc-max8998.c @@ -251,8 +251,7 @@ static int max8998_rtc_probe(struct platform_device *pdev) struct max8998_rtc_info *info; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(struct max8998_rtc_info), - GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct max8998_rtc_info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c index 7960d5fa8cf0ad..107c5ddc273a72 100644 --- a/drivers/rtc/rtc-mc13xxx.c +++ b/drivers/rtc/rtc-mc13xxx.c @@ -262,7 +262,7 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) struct mc13xxx_rtc *priv; struct mc13xxx *mc13xxx; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-meson-vrtc.c b/drivers/rtc/rtc-meson-vrtc.c index 7d38258cbe376e..e5f9f05ffee04f 100644 --- a/drivers/rtc/rtc-meson-vrtc.c +++ b/drivers/rtc/rtc-meson-vrtc.c @@ -66,7 +66,7 @@ static int meson_vrtc_probe(struct platform_device *pdev) struct meson_vrtc_data *vrtc; struct rtc_device *rtc; - vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL); + vrtc = devm_kzalloc_obj(&pdev->dev, *vrtc); if (!vrtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-meson.c b/drivers/rtc/rtc-meson.c index 21eceb9e2e134e..ca857ebfbcfacf 100644 --- a/drivers/rtc/rtc-meson.c +++ b/drivers/rtc/rtc-meson.c @@ -295,7 +295,7 @@ static int meson_rtc_probe(struct platform_device *pdev) int ret; u32 tm; - rtc = devm_kzalloc(dev, sizeof(struct meson_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, struct meson_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-moxart.c b/drivers/rtc/rtc-moxart.c index bc0345db6ed667..04c96525344331 100644 --- a/drivers/rtc/rtc-moxart.c +++ b/drivers/rtc/rtc-moxart.c @@ -245,7 +245,7 @@ static int moxart_rtc_probe(struct platform_device *pdev) struct moxart_rtc *moxart_rtc; int ret = 0; - moxart_rtc = devm_kzalloc(&pdev->dev, sizeof(*moxart_rtc), GFP_KERNEL); + moxart_rtc = devm_kzalloc_obj(&pdev->dev, *moxart_rtc); if (!moxart_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c index b90f8337a7e6de..e1cef77c1a0eb0 100644 --- a/drivers/rtc/rtc-mpc5121.c +++ b/drivers/rtc/rtc-mpc5121.c @@ -293,7 +293,7 @@ static int mpc5121_rtc_probe(struct platform_device *op) struct mpc5121_rtc_data *rtc; int err = 0; - rtc = devm_kzalloc(&op->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&op->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-mpfs.c b/drivers/rtc/rtc-mpfs.c index 6616ca1f02c756..628305b48615e8 100644 --- a/drivers/rtc/rtc-mpfs.c +++ b/drivers/rtc/rtc-mpfs.c @@ -219,7 +219,7 @@ static int mpfs_rtc_probe(struct platform_device *pdev) unsigned long prescaler; int wakeup_irq, ret; - rtcdev = devm_kzalloc(&pdev->dev, sizeof(struct mpfs_rtc_dev), GFP_KERNEL); + rtcdev = devm_kzalloc_obj(&pdev->dev, struct mpfs_rtc_dev); if (!rtcdev) return -ENOMEM; diff --git a/drivers/rtc/rtc-msc313.c b/drivers/rtc/rtc-msc313.c index 912a46c6f17e84..27fc95734e5e36 100644 --- a/drivers/rtc/rtc-msc313.c +++ b/drivers/rtc/rtc-msc313.c @@ -185,7 +185,7 @@ static int msc313_rtc_probe(struct platform_device *pdev) int ret; int irq; - priv = devm_kzalloc(&pdev->dev, sizeof(struct msc313_rtc), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct msc313_rtc); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c index 80e364baac5363..b58ba463791d66 100644 --- a/drivers/rtc/rtc-msm6242.c +++ b/drivers/rtc/rtc-msm6242.c @@ -196,7 +196,7 @@ static int __init msm6242_rtc_probe(struct platform_device *pdev) if (!res) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-mt2712.c b/drivers/rtc/rtc-mt2712.c index cd92a9788351dc..2dbd51a00478d1 100644 --- a/drivers/rtc/rtc-mt2712.c +++ b/drivers/rtc/rtc-mt2712.c @@ -313,8 +313,7 @@ static int mt2712_rtc_probe(struct platform_device *pdev) struct mt2712_rtc *mt2712_rtc; int ret; - mt2712_rtc = devm_kzalloc(&pdev->dev, - sizeof(struct mt2712_rtc), GFP_KERNEL); + mt2712_rtc = devm_kzalloc_obj(&pdev->dev, struct mt2712_rtc); if (!mt2712_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index d6e156516aa6c6..ab402f9f85c3c1 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -333,7 +333,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) struct mt6397_rtc *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(struct mt6397_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, struct mt6397_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-mt7622.c b/drivers/rtc/rtc-mt7622.c index 9e17dd09d56738..1772cb25b25dbe 100644 --- a/drivers/rtc/rtc-mt7622.c +++ b/drivers/rtc/rtc-mt7622.c @@ -304,7 +304,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) struct mtk_rtc *hw; int ret; - hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(&pdev->dev, *hw); if (!hw) return -ENOMEM; diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c index db64c459ee19ef..3f48b4eaeef239 100644 --- a/drivers/rtc/rtc-mv.c +++ b/drivers/rtc/rtc-mv.c @@ -211,7 +211,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev) u32 rtc_time; int ret = 0; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c index 608db97d450c53..f91b0994b715fb 100644 --- a/drivers/rtc/rtc-mxc.c +++ b/drivers/rtc/rtc-mxc.c @@ -298,7 +298,7 @@ static int mxc_rtc_probe(struct platform_device *pdev) unsigned long rate; int ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-mxc_v2.c b/drivers/rtc/rtc-mxc_v2.c index a07acbbcfaebb0..965170bb8cd7fd 100644 --- a/drivers/rtc/rtc-mxc_v2.c +++ b/drivers/rtc/rtc-mxc_v2.c @@ -280,7 +280,7 @@ static int mxc_rtc_probe(struct platform_device *pdev) void __iomem *ioaddr; int ret = 0; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c index 194ba077363aaf..c770450e48b4ef 100644 --- a/drivers/rtc/rtc-nct3018y.c +++ b/drivers/rtc/rtc-nct3018y.c @@ -593,8 +593,7 @@ static int nct3018y_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BLOCK_DATA)) return -ENODEV; - nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y), - GFP_KERNEL); + nct3018y = devm_kzalloc_obj(&client->dev, struct nct3018y); if (!nct3018y) return -ENOMEM; diff --git a/drivers/rtc/rtc-nct6694.c b/drivers/rtc/rtc-nct6694.c index 1cf9b672256a7f..501c364277d8bd 100644 --- a/drivers/rtc/rtc-nct6694.c +++ b/drivers/rtc/rtc-nct6694.c @@ -236,12 +236,11 @@ static int nct6694_rtc_probe(struct platform_device *pdev) struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent); int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; - data->msg = devm_kzalloc(&pdev->dev, sizeof(union nct6694_rtc_msg), - GFP_KERNEL); + data->msg = devm_kzalloc_obj(&pdev->dev, union nct6694_rtc_msg); if (!data->msg) return -ENOMEM; diff --git a/drivers/rtc/rtc-ntxec.c b/drivers/rtc/rtc-ntxec.c index d28ddb34e19e77..d5dda13b5cd211 100644 --- a/drivers/rtc/rtc-ntxec.c +++ b/drivers/rtc/rtc-ntxec.c @@ -112,7 +112,7 @@ static int ntxec_rtc_probe(struct platform_device *pdev) device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent); - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-nvidia-vrs10.c b/drivers/rtc/rtc-nvidia-vrs10.c index caac63f4e0fcc3..afd6e41f847065 100644 --- a/drivers/rtc/rtc-nvidia-vrs10.c +++ b/drivers/rtc/rtc-nvidia-vrs10.c @@ -423,7 +423,7 @@ static int nvvrs_rtc_probe(struct i2c_client *client) struct nvvrs_rtc_info *info; int ret; - info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&client->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-nxp-bbnsm.c b/drivers/rtc/rtc-nxp-bbnsm.c index d4fc9dc583d317..a369908db3a0db 100644 --- a/drivers/rtc/rtc-nxp-bbnsm.c +++ b/drivers/rtc/rtc-nxp-bbnsm.c @@ -166,7 +166,7 @@ static int bbnsm_rtc_probe(struct platform_device *pdev) struct bbnsm_rtc *bbnsm; int ret; - bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); + bbnsm = devm_kzalloc_obj(&pdev->dev, *bbnsm); if (!bbnsm) return -ENOMEM; diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 18492165a19f3f..3c978edd6c2cb7 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -730,7 +730,7 @@ static int omap_rtc_probe(struct platform_device *pdev) const struct platform_device_id *id_entry; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-optee.c b/drivers/rtc/rtc-optee.c index 6c908c0d861a6f..256f60f1800a06 100644 --- a/drivers/rtc/rtc-optee.c +++ b/drivers/rtc/rtc-optee.c @@ -554,7 +554,7 @@ static int optee_rtc_probe(struct tee_client_device *rtc_device) struct tee_shm *shm; int ret, err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-palmas.c b/drivers/rtc/rtc-palmas.c index aecada6bcf8b5c..64c901106cd9c9 100644 --- a/drivers/rtc/rtc-palmas.c +++ b/drivers/rtc/rtc-palmas.c @@ -235,8 +235,7 @@ static int palmas_rtc_probe(struct platform_device *pdev) "ti,backup-battery-charge-high-current"); } - palmas_rtc = devm_kzalloc(&pdev->dev, sizeof(struct palmas_rtc), - GFP_KERNEL); + palmas_rtc = devm_kzalloc_obj(&pdev->dev, struct palmas_rtc); if (!palmas_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c index 22c626d57090e5..95654be6f7254d 100644 --- a/drivers/rtc/rtc-pcf2123.c +++ b/drivers/rtc/rtc-pcf2123.c @@ -378,8 +378,7 @@ static int pcf2123_probe(struct spi_device *spi) struct pcf2123_data *pcf2123; int ret = 0; - pcf2123 = devm_kzalloc(&spi->dev, sizeof(struct pcf2123_data), - GFP_KERNEL); + pcf2123 = devm_kzalloc_obj(&spi->dev, struct pcf2123_data); if (!pcf2123) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 49542cc534119e..27c5fb9b2aaa37 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -1196,7 +1196,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, dev_dbg(dev, "%s\n", __func__); - pcf2127 = devm_kzalloc(dev, sizeof(*pcf2127), GFP_KERNEL); + pcf2127 = devm_kzalloc_obj(dev, *pcf2127); if (!pcf2127) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c index 32952e73f2f1c1..819648619dffed 100644 --- a/drivers/rtc/rtc-pcf85063.c +++ b/drivers/rtc/rtc-pcf85063.c @@ -645,8 +645,7 @@ static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq, dev_dbg(dev, "%s\n", __func__); - pcf85063 = devm_kzalloc(dev, sizeof(struct pcf85063), - GFP_KERNEL); + pcf85063 = devm_kzalloc_obj(dev, struct pcf85063); if (!pcf85063) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c index e8354953836c27..bbd42358a4c24a 100644 --- a/drivers/rtc/rtc-pcf8523.c +++ b/drivers/rtc/rtc-pcf8523.c @@ -424,7 +424,7 @@ static int pcf8523_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - pcf8523 = devm_kzalloc(&client->dev, sizeof(struct pcf8523), GFP_KERNEL); + pcf8523 = devm_kzalloc_obj(&client->dev, struct pcf8523); if (!pcf8523) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c index ccc7834e575997..54f7ffca239ecc 100644 --- a/drivers/rtc/rtc-pcf85363.c +++ b/drivers/rtc/rtc-pcf85363.c @@ -407,8 +407,7 @@ static int pcf85363_probe(struct i2c_client *client) if (data) config = data; - pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), - GFP_KERNEL); + pcf85363 = devm_kzalloc_obj(&client->dev, struct pcf85363); if (!pcf85363) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 3801acc9ac8d67..62e68ba9a226f5 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c @@ -483,8 +483,7 @@ static int pcf8563_probe(struct i2c_client *client) !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return -ENODEV; - pcf8563 = devm_kzalloc(&client->dev, sizeof(struct pcf8563), - GFP_KERNEL); + pcf8563 = devm_kzalloc_obj(&client->dev, struct pcf8563); if (!pcf8563) return -ENOMEM; diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c index df5e20cbc26cbf..8c50df84c4172b 100644 --- a/drivers/rtc/rtc-pcf8583.c +++ b/drivers/rtc/rtc-pcf8583.c @@ -282,8 +282,7 @@ static int pcf8583_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - pcf8583 = devm_kzalloc(&client->dev, sizeof(struct pcf8583), - GFP_KERNEL); + pcf8583 = devm_kzalloc_obj(&client->dev, struct pcf8583); if (!pcf8583) return -ENOMEM; diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c index 3c7a38a4ac08eb..4a4fedb7cf71fc 100644 --- a/drivers/rtc/rtc-pic32.c +++ b/drivers/rtc/rtc-pic32.c @@ -297,7 +297,7 @@ static int pic32_rtc_probe(struct platform_device *pdev) struct pic32_rtc_dev *pdata; int ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c index 5caaa714f44854..60a377b542c015 100644 --- a/drivers/rtc/rtc-pl030.c +++ b/drivers/rtc/rtc-pl030.c @@ -91,7 +91,7 @@ static int pl030_probe(struct amba_device *dev, const struct amba_id *id) if (ret) goto err_req; - rtc = devm_kzalloc(&dev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&dev->dev, *rtc); if (!rtc) { ret = -ENOMEM; goto err_rtc; diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c index eab39dfa4e5fe5..9adbf4e36dcc5d 100644 --- a/drivers/rtc/rtc-pl031.c +++ b/drivers/rtc/rtc-pl031.c @@ -303,8 +303,7 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id) if (ret) goto err_req; - ldata = devm_kzalloc(&adev->dev, sizeof(struct pl031_local), - GFP_KERNEL); + ldata = devm_kzalloc_obj(&adev->dev, struct pl031_local); ops = devm_kmemdup(&adev->dev, &vendor->ops, sizeof(vendor->ops), GFP_KERNEL); if (!ldata || !ops) { diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index e624f848c22b57..40b6b62116dc4c 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -602,7 +602,7 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) if (!match) return -ENXIO; - rtc_dd = devm_kzalloc(&pdev->dev, sizeof(*rtc_dd), GFP_KERNEL); + rtc_dd = devm_kzalloc_obj(&pdev->dev, *rtc_dd); if (rtc_dd == NULL) return -ENOMEM; diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c index 62ee6b8f9bcd6b..6443824f2a3e0d 100644 --- a/drivers/rtc/rtc-pxa.c +++ b/drivers/rtc/rtc-pxa.c @@ -306,7 +306,7 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) struct sa1100_rtc *sa1100_rtc; int ret; - pxa_rtc = devm_kzalloc(dev, sizeof(*pxa_rtc), GFP_KERNEL); + pxa_rtc = devm_kzalloc_obj(dev, *pxa_rtc); if (!pxa_rtc) return -ENOMEM; sa1100_rtc = &pxa_rtc->sa1100_rtc; diff --git a/drivers/rtc/rtc-r7301.c b/drivers/rtc/rtc-r7301.c index 6323b777151fcc..ceec6c05ed2b0e 100644 --- a/drivers/rtc/rtc-r7301.c +++ b/drivers/rtc/rtc-r7301.c @@ -371,7 +371,7 @@ static int __init rtc7301_rtc_probe(struct platform_device *dev) int ret; u32 val; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-raspberrypi.c b/drivers/rtc/rtc-raspberrypi.c index 0547a96c62ac4a..cfeec1956febfe 100644 --- a/drivers/rtc/rtc-raspberrypi.c +++ b/drivers/rtc/rtc-raspberrypi.c @@ -215,7 +215,7 @@ static int rpi_rtc_probe(struct platform_device *pdev) if (!firmware) return -EPROBE_DEFER; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c index 8ba9cda74acf1a..e7ebc6680ce288 100644 --- a/drivers/rtc/rtc-rc5t583.c +++ b/drivers/rtc/rtc-rc5t583.c @@ -210,8 +210,7 @@ static int rc5t583_rtc_probe(struct platform_device *pdev) int ret; int irq; - ricoh_rtc = devm_kzalloc(&pdev->dev, sizeof(struct rc5t583_rtc), - GFP_KERNEL); + ricoh_rtc = devm_kzalloc_obj(&pdev->dev, struct rc5t583_rtc); if (!ricoh_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-rc5t619.c b/drivers/rtc/rtc-rc5t619.c index 74d16910207414..37a391d7130803 100644 --- a/drivers/rtc/rtc-rc5t619.c +++ b/drivers/rtc/rtc-rc5t619.c @@ -355,7 +355,7 @@ static int rc5t619_rtc_probe(struct platform_device *pdev) unsigned int ctrl2; int err; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-renesas-rtca3.c b/drivers/rtc/rtc-renesas-rtca3.c index b3875d041de59e..1d808e507a938d 100644 --- a/drivers/rtc/rtc-renesas-rtca3.c +++ b/drivers/rtc/rtc-renesas-rtca3.c @@ -718,7 +718,7 @@ static int rtca3_probe(struct platform_device *pdev) struct clk *clk; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c index 59b8e9a30fe673..43ee263ee17562 100644 --- a/drivers/rtc/rtc-rk808.c +++ b/drivers/rtc/rtc-rk808.c @@ -381,7 +381,7 @@ static int rk808_rtc_probe(struct platform_device *pdev) struct rk808_rtc *rk808_rtc; int ret; - rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc), GFP_KERNEL); + rk808_rtc = devm_kzalloc_obj(&pdev->dev, *rk808_rtc); if (rk808_rtc == NULL) return -ENOMEM; diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c index 44afa6d996e74c..13ba5dd8655cac 100644 --- a/drivers/rtc/rtc-rp5c01.c +++ b/drivers/rtc/rtc-rp5c01.c @@ -234,7 +234,7 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev) if (!res) return -ENODEV; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c index fec633f80789dd..5fb3d887dff7b2 100644 --- a/drivers/rtc/rtc-rs5c348.c +++ b/drivers/rtc/rtc-rs5c348.c @@ -167,8 +167,7 @@ static int rs5c348_probe(struct spi_device *spi) struct rtc_device *rtc; struct rs5c348_plat_data *pdata; - pdata = devm_kzalloc(&spi->dev, sizeof(struct rs5c348_plat_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&spi->dev, struct rs5c348_plat_data); if (!pdata) return -ENOMEM; spi->dev.platform_data = pdata; diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c index a4bd042908b893..8a61d0a5482286 100644 --- a/drivers/rtc/rtc-rs5c372.c +++ b/drivers/rtc/rtc-rs5c372.c @@ -851,8 +851,7 @@ static int rs5c372_probe(struct i2c_client *client) } } - rs5c372 = devm_kzalloc(&client->dev, sizeof(struct rs5c372), - GFP_KERNEL); + rs5c372 = devm_kzalloc_obj(&client->dev, struct rs5c372); if (!rs5c372) { err = -ENOMEM; goto exit; diff --git a/drivers/rtc/rtc-rtd119x.c b/drivers/rtc/rtc-rtd119x.c index 85a138db81d78a..04b4ab4017bbc3 100644 --- a/drivers/rtc/rtc-rtd119x.c +++ b/drivers/rtc/rtc-rtd119x.c @@ -169,7 +169,7 @@ static int rtd119x_rtc_probe(struct platform_device *pdev) u32 val; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/rtc/rtc-rv3028.c b/drivers/rtc/rtc-rv3028.c index b3a5b1ef33d168..44afac814aff35 100644 --- a/drivers/rtc/rtc-rv3028.c +++ b/drivers/rtc/rtc-rv3028.c @@ -943,8 +943,7 @@ static int rv3028_probe(struct i2c_client *client) .reg_write = rv3028_eeprom_write, }; - rv3028 = devm_kzalloc(&client->dev, sizeof(struct rv3028_data), - GFP_KERNEL); + rv3028 = devm_kzalloc_obj(&client->dev, struct rv3028_data); if (!rv3028) return -ENOMEM; diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c index 33b73bbcaf52f5..b5db9546fa3b6d 100644 --- a/drivers/rtc/rtc-rv3029c2.c +++ b/drivers/rtc/rtc-rv3029c2.c @@ -715,7 +715,7 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, }; int rc = 0; - rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL); + rv3029 = devm_kzalloc_obj(dev, *rv3029); if (!rv3029) return -ENOMEM; diff --git a/drivers/rtc/rtc-rv3032.c b/drivers/rtc/rtc-rv3032.c index 687faaef42b257..916e5ca5cfa187 100644 --- a/drivers/rtc/rtc-rv3032.c +++ b/drivers/rtc/rtc-rv3032.c @@ -914,8 +914,7 @@ static int rv3032_probe(struct i2c_client *client) .reg_write = rv3032_eeprom_write, }; - rv3032 = devm_kzalloc(&client->dev, sizeof(struct rv3032_data), - GFP_KERNEL); + rv3032 = devm_kzalloc_obj(&client->dev, struct rv3032_data); if (!rv3032) return -ENOMEM; diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c index b9b5fee16ee439..7445c815105609 100644 --- a/drivers/rtc/rtc-rv8803.c +++ b/drivers/rtc/rtc-rv8803.c @@ -660,8 +660,7 @@ static int rv8803_probe(struct i2c_client *client) return -EIO; } - rv8803 = devm_kzalloc(&client->dev, sizeof(struct rv8803_data), - GFP_KERNEL); + rv8803 = devm_kzalloc_obj(&client->dev, struct rv8803_data); if (!rv8803) return -ENOMEM; diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c index 1eacd470a27c11..c0fa43367cc1f4 100644 --- a/drivers/rtc/rtc-rx6110.c +++ b/drivers/rtc/rtc-rx6110.c @@ -351,7 +351,7 @@ static int rx6110_spi_probe(struct spi_device *spi) dev_warn(&spi->dev, "driving device in an unsupported mode"); } - rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL); + rx6110 = devm_kzalloc_obj(&spi->dev, *rx6110); if (!rx6110) return -ENOMEM; @@ -427,7 +427,7 @@ static int rx6110_i2c_probe(struct i2c_client *client) return -EIO; } - rx6110 = devm_kzalloc(&client->dev, sizeof(*rx6110), GFP_KERNEL); + rx6110 = devm_kzalloc_obj(&client->dev, *rx6110); if (!rx6110) return -ENOMEM; diff --git a/drivers/rtc/rtc-rx8010.c b/drivers/rtc/rtc-rx8010.c index 0a9be6ea62d090..2fbd66a1f31285 100644 --- a/drivers/rtc/rtc-rx8010.c +++ b/drivers/rtc/rtc-rx8010.c @@ -373,7 +373,7 @@ static int rx8010_probe(struct i2c_client *client) struct rx8010_data *rx8010; int err = 0; - rx8010 = devm_kzalloc(dev, sizeof(*rx8010), GFP_KERNEL); + rx8010 = devm_kzalloc_obj(dev, *rx8010); if (!rx8010) return -ENOMEM; diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c index 96a04c977d0f1e..1ccec7b5ae42bb 100644 --- a/drivers/rtc/rtc-rx8025.c +++ b/drivers/rtc/rtc-rx8025.c @@ -531,7 +531,7 @@ static int rx8025_probe(struct i2c_client *client) return -EIO; } - rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL); + rx8025 = devm_kzalloc_obj(&client->dev, *rx8025); if (!rx8025) return -ENOMEM; diff --git a/drivers/rtc/rtc-rx8111.c b/drivers/rtc/rtc-rx8111.c index 8450d9f0b566c6..4019a3354f01a7 100644 --- a/drivers/rtc/rtc-rx8111.c +++ b/drivers/rtc/rtc-rx8111.c @@ -306,7 +306,7 @@ static int rx8111_probe(struct i2c_client *client) struct rtc_device *rtc; size_t i; - data = devm_kmalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kmalloc_obj(&client->dev, *data); if (!data) { dev_dbg(&client->dev, "Could not allocate device data\n"); return -ENOMEM; diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c index 1db518ab3a3ae2..df2c5a3c30f6f4 100644 --- a/drivers/rtc/rtc-rzn1.c +++ b/drivers/rtc/rtc-rzn1.c @@ -427,7 +427,7 @@ static int rzn1_rtc_probe(struct platform_device *pdev) if (!data) return -ENODEV; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-s32g.c b/drivers/rtc/rtc-s32g.c index 86716192d10ff0..a8a67d496eae88 100644 --- a/drivers/rtc/rtc-s32g.c +++ b/drivers/rtc/rtc-s32g.c @@ -272,7 +272,7 @@ static int s32g_rtc_probe(struct platform_device *pdev) unsigned long rtc_hz; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c index d3e829052927bc..04797e6c440d3d 100644 --- a/drivers/rtc/rtc-s35390a.c +++ b/drivers/rtc/rtc-s35390a.c @@ -704,7 +704,7 @@ static int s35390a_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - s35390a = devm_kzalloc(dev, sizeof(struct s35390a), GFP_KERNEL); + s35390a = devm_kzalloc_obj(dev, struct s35390a); if (!s35390a) return -ENOMEM; diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index 291c0ccb0acd25..221a9461dbc029 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c @@ -387,7 +387,7 @@ static int s3c_rtc_probe(struct platform_device *pdev) struct s3c_rtc *info = NULL; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c index aa706074ec3e79..031191d4eeb903 100644 --- a/drivers/rtc/rtc-s5m.c +++ b/drivers/rtc/rtc-s5m.c @@ -669,7 +669,7 @@ static int s5m_rtc_probe(struct platform_device *pdev) struct s5m_rtc_info *info; int ret, alarm_irq; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index 26b2f4184eccf7..b170685237c590 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c @@ -248,7 +248,7 @@ static int sa1100_rtc_probe(struct platform_device *pdev) if (irq_1hz < 0 || irq_alarm < 0) return -ENODEV; - info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct sa1100_rtc); if (!info) return -ENOMEM; info->irq_1hz = irq_1hz; diff --git a/drivers/rtc/rtc-sc27xx.c b/drivers/rtc/rtc-sc27xx.c index 2b83561d4d2805..c71e4f05614aef 100644 --- a/drivers/rtc/rtc-sc27xx.c +++ b/drivers/rtc/rtc-sc27xx.c @@ -565,7 +565,7 @@ static int sprd_rtc_probe(struct platform_device *pdev) struct sprd_rtc *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-sd2405al.c b/drivers/rtc/rtc-sd2405al.c index 7982a910a53768..990080f09457e8 100644 --- a/drivers/rtc/rtc-sd2405al.c +++ b/drivers/rtc/rtc-sd2405al.c @@ -174,7 +174,7 @@ static int sd2405al_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; - sd2405al = devm_kzalloc(&client->dev, sizeof(*sd2405al), GFP_KERNEL); + sd2405al = devm_kzalloc_obj(&client->dev, *sd2405al); if (!sd2405al) return -ENOMEM; diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index 7a5feceb9ee7a6..49f737206e45c3 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c @@ -330,7 +330,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev) unsigned int tmp; resource_size_t regsize; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (unlikely(!rtc)) return -ENOMEM; diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index d82acf1af1faec..d99a352d6d3159 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -320,7 +320,7 @@ static int snvs_rtc_probe(struct platform_device *pdev) int ret; void __iomem *mmio; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/rtc/rtc-spacemit-p1.c b/drivers/rtc/rtc-spacemit-p1.c index 1de7bd995d296c..fcfce534f60c86 100644 --- a/drivers/rtc/rtc-spacemit-p1.c +++ b/drivers/rtc/rtc-spacemit-p1.c @@ -129,7 +129,7 @@ static int p1_rtc_probe(struct platform_device *pdev) struct rtc_device *rtc; struct p1_rtc *p1; - p1 = devm_kzalloc(dev, sizeof(*p1), GFP_KERNEL); + p1 = devm_kzalloc_obj(dev, *p1); if (!p1) return -ENOMEM; dev_set_drvdata(dev, p1); diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c index d12bccb3cf5ecb..408df168a1fe1b 100644 --- a/drivers/rtc/rtc-spear.c +++ b/drivers/rtc/rtc-spear.c @@ -350,7 +350,7 @@ static int spear_rtc_probe(struct platform_device *pdev) int status = 0; int irq; - config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(&pdev->dev, *config); if (!config) return -ENOMEM; diff --git a/drivers/rtc/rtc-ssd202d.c b/drivers/rtc/rtc-ssd202d.c index 72aa02eb86ea93..dd0cf5391fe907 100644 --- a/drivers/rtc/rtc-ssd202d.c +++ b/drivers/rtc/rtc-ssd202d.c @@ -207,7 +207,7 @@ static int ssd202d_rtc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct ssd202d_rtc *priv; - priv = devm_kzalloc(&pdev->dev, sizeof(struct ssd202d_rtc), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct ssd202d_rtc); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index ae79ddf24f371e..0b6e58d8bbbf7b 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c @@ -197,7 +197,7 @@ static int st_rtc_probe(struct platform_device *pdev) if (mode != ST_LPC_MODE_RTC) return -ENODEV; - rtc = devm_kzalloc(&pdev->dev, sizeof(struct st_rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, struct st_rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c index 7cb6be1b781510..8155315bb92a81 100644 --- a/drivers/rtc/rtc-stk17ta8.c +++ b/drivers/rtc/rtc-stk17ta8.c @@ -270,7 +270,7 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) .reg_write = stk17ta8_nvram_write, }; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c index 1c4e4bd7afe44e..0e51626824a40e 100644 --- a/drivers/rtc/rtc-stm32.c +++ b/drivers/rtc/rtc-stm32.c @@ -1059,7 +1059,7 @@ static int stm32_rtc_probe(struct platform_device *pdev) struct pinctrl_dev *pctl; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c index 7afcd14aeee562..d79e282e3817d1 100644 --- a/drivers/rtc/rtc-stmp3xxx.c +++ b/drivers/rtc/rtc-stmp3xxx.c @@ -251,7 +251,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) u32 crystalfreq = 0; int err; - rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); + rtc_data = devm_kzalloc_obj(&pdev->dev, *rtc_data); if (!rtc_data) return -ENOMEM; diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c index c6916edbf40074..121a7f77153de2 100644 --- a/drivers/rtc/rtc-sun6i.c +++ b/drivers/rtc/rtc-sun6i.c @@ -778,7 +778,7 @@ static int sun6i_rtc_probe(struct platform_device *pdev) } if (!chip) { - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/rtc/rtc-sunplus.c b/drivers/rtc/rtc-sunplus.c index 519a06e728d6ca..aeff6f1d259f23 100644 --- a/drivers/rtc/rtc-sunplus.c +++ b/drivers/rtc/rtc-sunplus.c @@ -231,7 +231,7 @@ static int sp_rtc_probe(struct platform_device *plat_dev) struct sunplus_rtc *sp_rtc; int ret; - sp_rtc = devm_kzalloc(&plat_dev->dev, sizeof(*sp_rtc), GFP_KERNEL); + sp_rtc = devm_kzalloc_obj(&plat_dev->dev, *sp_rtc); if (!sp_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c index 5cab9953c44f5d..8f415d0ee56d1c 100644 --- a/drivers/rtc/rtc-sunxi.c +++ b/drivers/rtc/rtc-sunxi.c @@ -422,7 +422,7 @@ static int sunxi_rtc_probe(struct platform_device *pdev) struct sunxi_rtc_dev *chip; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c index f16405c3911c71..4bc1d1f8c24c78 100644 --- a/drivers/rtc/rtc-tegra.c +++ b/drivers/rtc/rtc-tegra.c @@ -284,7 +284,7 @@ static int tegra_rtc_probe(struct platform_device *pdev) struct tegra_rtc_info *info; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c index 94f995febe5b4b..9214497ece0a5f 100644 --- a/drivers/rtc/rtc-test.c +++ b/drivers/rtc/rtc-test.c @@ -116,7 +116,7 @@ static int test_probe(struct platform_device *plat_dev) { struct rtc_test_data *rtd; - rtd = devm_kzalloc(&plat_dev->dev, sizeof(*rtd), GFP_KERNEL); + rtd = devm_kzalloc_obj(&plat_dev->dev, *rtd); if (!rtd) return -ENOMEM; diff --git a/drivers/rtc/rtc-ti-k3.c b/drivers/rtc/rtc-ti-k3.c index 8df00319cb6bbf..8bde650b24588e 100644 --- a/drivers/rtc/rtc-ti-k3.c +++ b/drivers/rtc/rtc-ti-k3.c @@ -556,7 +556,7 @@ static int ti_k3_rtc_probe(struct platform_device *pdev) void __iomem *rtc_base; int ret; - priv = devm_kzalloc(dev, sizeof(struct ti_k3_rtc), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct ti_k3_rtc); if (!priv) return -ENOMEM; diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c index 54c8429b16bfcc..521f1bce85c8c9 100644 --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c @@ -224,7 +224,7 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) struct tps6586x_rtc *rtc; int ret; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(&pdev->dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c index 284aa2f0392b3b..8b2f04dbaa45e7 100644 --- a/drivers/rtc/rtc-tps65910.c +++ b/drivers/rtc/rtc-tps65910.c @@ -372,8 +372,7 @@ static int tps65910_rtc_probe(struct platform_device *pdev) tps65910 = dev_get_drvdata(pdev->dev.parent); - tps_rtc = devm_kzalloc(&pdev->dev, sizeof(struct tps65910_rtc), - GFP_KERNEL); + tps_rtc = devm_kzalloc_obj(&pdev->dev, struct tps65910_rtc); if (!tps_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index f89fc3e59be043..45e52cca3f0665 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -364,7 +364,7 @@ static int tps6594_rtc_probe(struct platform_device *pdev) int irq; int ret; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc_obj(dev, *rtc); if (!rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c index e6106e67e1f40d..e6f12071c4b63e 100644 --- a/drivers/rtc/rtc-twl.c +++ b/drivers/rtc/rtc-twl.c @@ -518,7 +518,7 @@ static int twl_rtc_probe(struct platform_device *pdev) if (irq <= 0) return ret; - twl_rtc = devm_kzalloc(&pdev->dev, sizeof(*twl_rtc), GFP_KERNEL); + twl_rtc = devm_kzalloc_obj(&pdev->dev, *twl_rtc); if (!twl_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c index c8b568498016f2..5435774690552c 100644 --- a/drivers/rtc/rtc-vt8500.c +++ b/drivers/rtc/rtc-vt8500.c @@ -196,8 +196,7 @@ static int vt8500_rtc_probe(struct platform_device *pdev) struct vt8500_rtc *vt8500_rtc; int ret; - vt8500_rtc = devm_kzalloc(&pdev->dev, - sizeof(struct vt8500_rtc), GFP_KERNEL); + vt8500_rtc = devm_kzalloc_obj(&pdev->dev, struct vt8500_rtc); if (!vt8500_rtc) return -ENOMEM; diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c index 218316be942aea..1943cb1eb94b27 100644 --- a/drivers/rtc/rtc-wm831x.c +++ b/drivers/rtc/rtc-wm831x.c @@ -405,7 +405,7 @@ static int wm831x_rtc_probe(struct platform_device *pdev) int alm_irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "ALM")); int ret = 0; - wm831x_rtc = devm_kzalloc(&pdev->dev, sizeof(*wm831x_rtc), GFP_KERNEL); + wm831x_rtc = devm_kzalloc_obj(&pdev->dev, *wm831x_rtc); if (wm831x_rtc == NULL) return -ENOMEM; diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c index 6660b664e8dd35..b44d69794b7b67 100644 --- a/drivers/rtc/rtc-xgene.c +++ b/drivers/rtc/rtc-xgene.c @@ -139,7 +139,7 @@ static int xgene_rtc_probe(struct platform_device *pdev) int ret; int irq; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; platform_set_drvdata(pdev, pdata); diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index 5bcb7536e9734c..31e65fc892034e 100644 --- a/drivers/rtc/rtc-zynqmp.c +++ b/drivers/rtc/rtc-zynqmp.c @@ -282,7 +282,7 @@ static int xlnx_rtc_probe(struct platform_device *pdev) u32 alarm_time; int ret; - xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); + xrtcdev = devm_kzalloc_obj(&pdev->dev, *xrtcdev); if (!xrtcdev) return -ENOMEM; diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c index 4ab05e105a76b5..8771c3a696bcd5 100644 --- a/drivers/rtc/sysfs.c +++ b/drivers/rtc/sysfs.c @@ -326,7 +326,7 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) old_cnt++; new_cnt = old_cnt + add_cnt + 1; - groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL); + groups = devm_kzalloc_objs(&rtc->dev, *groups, new_cnt); if (!groups) return -ENOMEM; memcpy(groups, rtc->dev.groups, old_cnt * sizeof(*groups)); diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index 2ffe404b890fd7..3a55c937d0d643 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -1396,6 +1396,7 @@ int dasd_start_IO(struct dasd_ccw_req *cqr) cqr->status = DASD_CQR_ERROR; return -EIO; } + dasd_start_IO_prepare(cqr); cqr->startclk = get_tod_clock(); cqr->starttime = jiffies; cqr->retries--; @@ -2576,7 +2577,7 @@ static inline int _dasd_term_running_cqr(struct dasd_device *device) return rc; } -int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) +int dasd_sleep_on_immediately(struct dasd_ccw_req *cqr) { struct dasd_device *device; int rc; @@ -2628,7 +2629,7 @@ int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) return rc; } -EXPORT_SYMBOL(dasd_sleep_on_immediatly); +EXPORT_SYMBOL(dasd_sleep_on_immediately); /* * Cancels a request that was started with dasd_sleep_on_req. diff --git a/drivers/s390/block/dasd_alias.c b/drivers/s390/block/dasd_alias.c index 8d6c16d35c22a9..1ffcfcfe4565f0 100644 --- a/drivers/s390/block/dasd_alias.c +++ b/drivers/s390/block/dasd_alias.c @@ -750,7 +750,7 @@ static int reset_summary_unit_check(struct alias_lcu *lcu, cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); return rc; } diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index 9d1b11020b4e82..7e60d5b3b343ca 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -845,20 +845,29 @@ static int dasd_eckd_compare_path_uid(struct dasd_device *device, return memcmp(&device_uid, &path_uid, sizeof(struct dasd_uid)); } +/* + * The RCD buffer has to start with EBCDIC "V1.0" to show support for + * virtual device SNEQ. The RCD data is written into the same buffer, so + * a failed attempt may already have overwritten the magic. Re-initialize + * it before every start, including restarts by ERP requests. + */ +static void dasd_eckd_rcd_prepare_io(struct dasd_ccw_req *cqr) +{ + struct ccw1 *ccw = cqr->cpaddr; + __u8 *rcd_buffer = dma32_to_virt(ccw->cda); + + rcd_buffer[0] = 0xE5; + rcd_buffer[1] = 0xF1; + rcd_buffer[2] = 0x4B; + rcd_buffer[3] = 0xF0; +} + static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device, struct dasd_ccw_req *cqr, __u8 *rcd_buffer, __u8 lpm) { struct ccw1 *ccw; - /* - * buffer has to start with EBCDIC "V1.0" to show - * support for virtual device SNEQ - */ - rcd_buffer[0] = 0xE5; - rcd_buffer[1] = 0xF1; - rcd_buffer[2] = 0x4B; - rcd_buffer[3] = 0xF0; ccw = cqr->cpaddr; ccw->cmd_code = DASD_ECKD_CCW_RCD; @@ -875,33 +884,10 @@ static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device, cqr->retries = 256; cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; + cqr->prepare_io = dasd_eckd_rcd_prepare_io; set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); } -/* - * Wakeup helper for read_conf - * if the cqr is not done and needs some error recovery - * the buffer has to be re-initialized with the EBCDIC "V1.0" - * to show support for virtual device SNEQ - */ -static void read_conf_cb(struct dasd_ccw_req *cqr, void *data) -{ - struct ccw1 *ccw; - __u8 *rcd_buffer; - - if (cqr->status != DASD_CQR_DONE) { - ccw = cqr->cpaddr; - rcd_buffer = dma32_to_virt(ccw->cda); - memset(rcd_buffer, 0, sizeof(*rcd_buffer)); - - rcd_buffer[0] = 0xE5; - rcd_buffer[1] = 0xF1; - rcd_buffer[2] = 0x4B; - rcd_buffer[3] = 0xF0; - } - dasd_wakeup_cb(cqr, data); -} - static int dasd_eckd_read_conf_immediately(struct dasd_device *device, struct dasd_ccw_req *cqr, __u8 *rcd_buffer, @@ -921,8 +907,7 @@ static int dasd_eckd_read_conf_immediately(struct dasd_device *device, clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); cqr->retries = 5; - cqr->callback = read_conf_cb; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); return rc; } @@ -959,7 +944,6 @@ static int dasd_eckd_read_conf_lpm(struct dasd_device *device, goto out_error; } dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm); - cqr->callback = read_conf_cb; ret = dasd_sleep_on(cqr); /* * on success we update the user input parms @@ -2780,7 +2764,8 @@ dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata, return cqr; out_err: - dasd_sfree_request(cqr, startdev); + start_priv->count--; + dasd_ffree_request(cqr, startdev); return ERR_PTR(rc); } @@ -6008,7 +5993,7 @@ __context_unsafe(/* Conditional locking */) cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); if (!rc) clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); @@ -6064,7 +6049,7 @@ __context_unsafe(/* Conditional locking */) cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); if (!rc) set_bit(DASD_FLAG_IS_RESERVED, &device->flags); @@ -6119,7 +6104,7 @@ __context_unsafe(/* Conditional locking */) cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); if (!rc) set_bit(DASD_FLAG_IS_RESERVED, &device->flags); @@ -6183,7 +6168,7 @@ __context_unsafe(/* Conditional locking */) cqr->status = DASD_CQR_FILLED; cqr->lpm = usrparm.path_mask; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); /* verify that I/O processing didn't modify the path mask */ if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask)) rc = -EIO; @@ -6815,7 +6800,7 @@ static int dasd_eckd_read_message_buffer(struct dasd_device *device, cqr->block = NULL; cqr->expires = 10 * HZ; set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); - /* dasd_sleep_on_immediatly does not do complex error + /* dasd_sleep_on_immediately does not do complex error * recovery so clear erp flag and set retry counter to * do basic erp */ clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); @@ -6847,7 +6832,7 @@ static int dasd_eckd_read_message_buffer(struct dasd_device *device, cqr->buildclk = get_tod_clock(); cqr->status = DASD_CQR_FILLED; - rc = dasd_sleep_on_immediatly(cqr); + rc = dasd_sleep_on_immediately(cqr); if (rc == 0) { prssdp = (struct dasd_psf_prssd_data *) cqr->data; message_buf = (struct dasd_rssd_messages *) diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h index ef4930432c098a..53c450036fe105 100644 --- a/drivers/s390/block/dasd_int.h +++ b/drivers/s390/block/dasd_int.h @@ -147,6 +147,8 @@ struct dasd_ccw_req { void *data; /* pointer to data area */ struct irb irb; /* device status in case of an error */ struct dasd_ccw_req *refers; /* ERP-chain queueing. */ + /* optional prepare function called before every start_io, must not sleep */ + void (*prepare_io)(struct dasd_ccw_req *cqr); void *function; /* originating ERP action */ void *mem_chunk; @@ -892,6 +894,19 @@ static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr) return cqr->callback_data; } +/* + * Walk down the ERP chain to the original CQR and call its + * prepare_io function if set. + */ +static inline void dasd_start_IO_prepare(struct dasd_ccw_req *cqr) +{ + /* ERP requests use the prepare function of the original request */ + while (cqr->refers) + cqr = cqr->refers; + if (cqr->prepare_io) + cqr->prepare_io(cqr); +} + static inline bool dasd_req_conflict(struct dasd_ccw_req *cqr1, struct dasd_ccw_req *cqr2) { @@ -998,7 +1013,7 @@ void dasd_schedule_device_bh(struct dasd_device *); void dasd_schedule_block_bh(struct dasd_block *); int dasd_sleep_on(struct dasd_ccw_req *); int dasd_sleep_on_queue(struct list_head *); -int dasd_sleep_on_immediatly(struct dasd_ccw_req *); +int dasd_sleep_on_immediately(struct dasd_ccw_req *); int dasd_sleep_on_queue_interruptible(struct list_head *); int dasd_sleep_on_interruptible(struct dasd_ccw_req *); void dasd_device_set_timer(struct dasd_device *, int); diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index e5b8b413f5abfe..2f2ec2bea33334 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -303,7 +303,9 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp) goto out_err; } - if (copy_from_user(&cdata, argp, sizeof(cdata))) { + /* copy only input fields, clear the rest */ + memset(&cdata, 0, sizeof(cdata)); + if (copy_from_user(&cdata.expect, argp, sizeof(cdata.expect))) { rc = -EFAULT; goto out_err; } diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c index 63bcb52d6e87c8..28083467e1b3a2 100644 --- a/drivers/s390/char/keyboard.c +++ b/drivers/s390/char/keyboard.c @@ -81,8 +81,7 @@ kbd_alloc(void) { kbd = kzalloc_obj(struct kbd_data); if (!kbd) goto out; - kbd->key_maps = kcalloc(ARRAY_SIZE(ebc_key_maps), - sizeof(*kbd->key_maps), GFP_KERNEL); + kbd->key_maps = kzalloc_objs(*kbd->key_maps, ARRAY_SIZE(ebc_key_maps)); if (!kbd->key_maps) goto out_kbd; for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) { @@ -94,8 +93,8 @@ kbd_alloc(void) { goto out_maps; } } - kbd->func_table = kcalloc(ARRAY_SIZE(ebc_func_table), - sizeof(*kbd->func_table), GFP_KERNEL); + kbd->func_table = kzalloc_objs(*kbd->func_table, + ARRAY_SIZE(ebc_func_table)); if (!kbd->func_table) goto out_maps; for (i = 0; i < ARRAY_SIZE(ebc_func_table); i++) { diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c index 80435fd8e6ad61..15927d4ed41972 100644 --- a/drivers/s390/crypto/zcrypt_api.c +++ b/drivers/s390/crypto/zcrypt_api.c @@ -1668,7 +1668,7 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd, case ZCRYPT_PERDEV_REQCNT: { u32 *reqcnt; - reqcnt = kcalloc(AP_DEVICES, sizeof(u32), GFP_KERNEL); + reqcnt = kzalloc_objs(u32, AP_DEVICES); if (!reqcnt) return -ENOMEM; zcrypt_perdev_reqcnt(reqcnt, AP_DEVICES); diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c index e94222b3523cdc..60fe022783edb2 100644 --- a/drivers/sbus/char/display7seg.c +++ b/drivers/sbus/char/display7seg.c @@ -177,7 +177,7 @@ static int d7s_probe(struct platform_device *op) if (d7s_device) goto out; - p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&op->dev, *p); err = -ENOMEM; if (!p) goto out; diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c index 27b446c0c5d0f0..4179f29b3066e4 100644 --- a/drivers/scsi/BusLogic.c +++ b/drivers/scsi/BusLogic.c @@ -276,8 +276,10 @@ static void blogic_create_addlccbs(struct blogic_adapter *adapter, Lock should already have been acquired by the caller. */ -static struct blogic_ccb *blogic_alloc_ccb(struct blogic_adapter *adapter) +static struct blogic_ccb *blogic_alloc_ccb(struct Scsi_Host *host) + __must_hold(&host->host_lock) { + struct blogic_adapter *adapter = (void *)host->hostdata; static unsigned long serial; struct blogic_ccb *ccb; ccb = adapter->free_ccbs; @@ -307,7 +309,9 @@ static struct blogic_ccb *blogic_alloc_ccb(struct blogic_adapter *adapter) caller. */ -static void blogic_dealloc_ccb(struct blogic_ccb *ccb, int dma_unmap) +static void blogic_dealloc_ccb(struct Scsi_Host *host, struct blogic_ccb *ccb, + int dma_unmap) + __must_hold(&host->host_lock) { struct blogic_adapter *adapter = ccb->adapter; @@ -2596,8 +2600,11 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter) should already have been acquired by the caller. */ -static void blogic_process_ccbs(struct blogic_adapter *adapter) +static void blogic_process_ccbs(struct Scsi_Host *host) + __must_hold(&host->host_lock) { + struct blogic_adapter *adapter = (void *)host->hostdata; + if (adapter->processing_ccbs) return; adapter->processing_ccbs = true; @@ -2621,7 +2628,7 @@ static void blogic_process_ccbs(struct blogic_adapter *adapter) /* Place CCB back on the Host Adapter's free list. */ - blogic_dealloc_ccb(ccb, 1); + blogic_dealloc_ccb(host, ccb, 1); #if 0 /* this needs to be redone different for new EH */ /* Bus Device Reset CCBs have the command field @@ -2650,7 +2657,7 @@ static void blogic_process_ccbs(struct blogic_adapter *adapter) if (ccb->status == BLOGIC_CCB_RESET && ccb->tgt_id == tgt_id) { command = ccb->command; - blogic_dealloc_ccb(ccb, 1); + blogic_dealloc_ccb(host, ccb, 1); adapter->active_cmds[tgt_id]--; command->result = DID_RESET << 16; scsi_done(command); @@ -2721,7 +2728,7 @@ static void blogic_process_ccbs(struct blogic_adapter *adapter) /* Place CCB back on the Host Adapter's free list. */ - blogic_dealloc_ccb(ccb, 1); + blogic_dealloc_ccb(host, ccb, 1); /* Call the SCSI Command Completion Routine. */ @@ -2740,11 +2747,12 @@ static void blogic_process_ccbs(struct blogic_adapter *adapter) static irqreturn_t blogic_inthandler(int irq_ch, void *devid) { struct blogic_adapter *adapter = (struct blogic_adapter *) devid; + struct Scsi_Host *host = adapter->scsi_host; unsigned long processor_flag; /* Acquire exclusive access to Host Adapter. */ - spin_lock_irqsave(&adapter->scsi_host->host_lock, processor_flag); + spin_lock_irqsave(&host->host_lock, processor_flag); /* Handle Interrupts appropriately for each Host Adapter type. */ @@ -2794,25 +2802,25 @@ static irqreturn_t blogic_inthandler(int irq_ch, void *devid) Process any completed CCBs. */ if (adapter->firstccb != NULL) - blogic_process_ccbs(adapter); + blogic_process_ccbs(host); /* Reset the Host Adapter if requested. */ if (adapter->adapter_extreset) { blogic_warn("Resetting %s due to External SCSI Bus Reset\n", adapter, adapter->full_model); blogic_inc_count(&adapter->ext_resets); - blogic_resetadapter(adapter, false); + blogic_resetadapter(host, false); adapter->adapter_extreset = false; } else if (adapter->adapter_intern_err) { blogic_warn("Resetting %s due to Host Adapter Internal Error\n", adapter, adapter->full_model); blogic_inc_count(&adapter->adapter_intern_errors); - blogic_resetadapter(adapter, true); + blogic_resetadapter(host, true); adapter->adapter_intern_err = false; } /* Release exclusive access to Host Adapter. */ - spin_unlock_irqrestore(&adapter->scsi_host->host_lock, processor_flag); + spin_unlock_irqrestore(&host->host_lock, processor_flag); return IRQ_HANDLED; } @@ -2823,9 +2831,11 @@ static irqreturn_t blogic_inthandler(int irq_ch, void *devid) already have been acquired by the caller. */ -static bool blogic_write_outbox(struct blogic_adapter *adapter, +static bool blogic_write_outbox(struct Scsi_Host *host, enum blogic_action action, struct blogic_ccb *ccb) + __must_hold(&host->host_lock) { + struct blogic_adapter *adapter = (void *)host->hostdata; struct blogic_outbox *next_outbox; next_outbox = adapter->next_outbox; @@ -2859,17 +2869,16 @@ static int blogic_hostreset(struct scsi_cmnd *SCpnt) { struct blogic_adapter *adapter = (struct blogic_adapter *) SCpnt->device->host->hostdata; - + struct Scsi_Host *shost = adapter->scsi_host; unsigned int id = SCpnt->device->id; struct blogic_tgt_stats *stats = &adapter->tgt_stats[id]; int rc; - spin_lock_irq(&SCpnt->device->host->host_lock); - + spin_lock_irq(&shost->host_lock); blogic_inc_count(&stats->adapter_reset_req); + rc = blogic_resetadapter(shost, false); + spin_unlock_irq(&shost->host_lock); - rc = blogic_resetadapter(adapter, false); - spin_unlock_irq(&SCpnt->device->host->host_lock); return rc; } @@ -2878,11 +2887,12 @@ static int blogic_hostreset(struct scsi_cmnd *SCpnt) Outgoing Mailbox for execution by the associated Host Adapter. */ -static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) +static enum scsi_qc_status blogic_qcmd_lck(struct Scsi_Host *shost, struct scsi_cmnd *command) + __must_hold(&shost->host_lock) { void (*comp_cb)(struct scsi_cmnd *) = scsi_done; struct blogic_adapter *adapter = - (struct blogic_adapter *) command->device->host->hostdata; + (struct blogic_adapter *) shost->hostdata; struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[command->device->id]; struct blogic_tgt_stats *tgt_stats = adapter->tgt_stats; @@ -2913,12 +2923,12 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) probably hung so signal an error as a Host Adapter Hard Reset should be initiated soon. */ - ccb = blogic_alloc_ccb(adapter); + ccb = blogic_alloc_ccb(shost); if (ccb == NULL) { - spin_unlock_irq(&adapter->scsi_host->host_lock); + spin_unlock_irq(&shost->host_lock); blogic_delay(1); - spin_lock_irq(&adapter->scsi_host->host_lock); - ccb = blogic_alloc_ccb(adapter); + spin_lock_irq(&shost->host_lock); + ccb = blogic_alloc_ccb(shost); if (ccb == NULL) { command->result = DID_ERROR << 16; comp_cb(command); @@ -3046,7 +3056,7 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) if (dma_mapping_error(&adapter->pci_device->dev, sense_buf)) { blogic_err("DMA mapping for sense data buffer failed\n", adapter); - blogic_dealloc_ccb(ccb, 0); + blogic_dealloc_ccb(shost, ccb, 0); return SCSI_MLQUEUE_HOST_BUSY; } ccb->sensedata = sense_buf; @@ -3061,15 +3071,15 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) so signal an error as a Host Adapter Hard Reset should be initiated soon. */ - if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START, ccb)) { - spin_unlock_irq(&adapter->scsi_host->host_lock); + if (!blogic_write_outbox(shost, BLOGIC_MBOX_START, ccb)) { + spin_unlock_irq(&shost->host_lock); blogic_warn("Unable to write Outgoing Mailbox - Pausing for 1 second\n", adapter); blogic_delay(1); - spin_lock_irq(&adapter->scsi_host->host_lock); - if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START, + spin_lock_irq(&shost->host_lock); + if (!blogic_write_outbox(shost, BLOGIC_MBOX_START, ccb)) { blogic_warn("Still unable to write Outgoing Mailbox - Host Adapter Dead?\n", adapter); - blogic_dealloc_ccb(ccb, 1); + blogic_dealloc_ccb(shost, ccb, 1); command->result = DID_ERROR << 16; scsi_done(command); } @@ -3089,12 +3099,20 @@ static enum scsi_qc_status blogic_qcmd_lck(struct scsi_cmnd *command) pending. */ if (ccb->status == BLOGIC_CCB_COMPLETE) - blogic_process_ccbs(adapter); + blogic_process_ccbs(shost); } return 0; } -static DEF_SCSI_QCMD(blogic_qcmd) +static enum scsi_qc_status blogic_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) +{ + enum scsi_qc_status rc; + + spin_lock_irq(&shost->host_lock); + rc = blogic_qcmd_lck(shost, cmd); + spin_unlock_irq(&shost->host_lock); + return rc; +} #if 0 /* @@ -3103,9 +3121,8 @@ static DEF_SCSI_QCMD(blogic_qcmd) static int blogic_abort(struct scsi_cmnd *command) { - struct blogic_adapter *adapter = - (struct blogic_adapter *) command->device->host->hostdata; - + struct Scsi_Host *const shost = command->device->host; + struct blogic_adapter *adapter = (void *) shost->hostdata; int tgt_id = command->device->id; struct blogic_ccb *ccb; blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_request); @@ -3144,7 +3161,7 @@ static int blogic_abort(struct scsi_cmnd *command) adapter->fw_ver[0] < '5') { blogic_warn("Unable to Abort CCB #%ld to Target %d - Abort Tag Not Supported\n", adapter, ccb->serial, tgt_id); return FAILURE; - } else if (blogic_write_outbox(adapter, BLOGIC_MBOX_ABORT, + } else if (blogic_write_outbox(shost, BLOGIC_MBOX_ABORT, ccb)) { blogic_warn("Aborting CCB #%ld to Target %d\n", adapter, ccb->serial, tgt_id); @@ -3169,7 +3186,7 @@ static int blogic_abort(struct scsi_cmnd *command) may still be pending. */ if (ccb->status == BLOGIC_CCB_COMPLETE) - blogic_process_ccbs(adapter); + blogic_process_ccbs(shost); return SUCCESS; } return SUCCESS; @@ -3181,8 +3198,10 @@ static int blogic_abort(struct scsi_cmnd *command) currently executing SCSI Commands as having been Reset. */ -static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset) +static int blogic_resetadapter(struct Scsi_Host *host, bool hard_reset) + __must_hold(&host->host_lock) { + struct blogic_adapter *adapter = (void *)host->hostdata; struct blogic_ccb *ccb; int tgt_id; @@ -3203,7 +3222,7 @@ static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset) for (ccb = adapter->all_ccbs; ccb != NULL; ccb = ccb->next_all) if (ccb->status == BLOGIC_CCB_ACTIVE) - blogic_dealloc_ccb(ccb, 1); + blogic_dealloc_ccb(host, ccb, 1); /* * Wait a few seconds between the Host Adapter Hard Reset which * initiates a SCSI Bus Reset and issuing any SCSI Commands. Some @@ -3212,9 +3231,9 @@ static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset) */ if (hard_reset) { - spin_unlock_irq(&adapter->scsi_host->host_lock); + spin_unlock_irq(&host->host_lock); blogic_delay(adapter->bus_settle_time); - spin_lock_irq(&adapter->scsi_host->host_lock); + spin_lock_irq(&host->host_lock); } for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) { diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h index 24697a5bedc8b7..455d442525f605 100644 --- a/drivers/scsi/BusLogic.h +++ b/drivers/scsi/BusLogic.h @@ -1279,7 +1279,8 @@ static int blogic_sdev_configure(struct scsi_device *, struct queue_limits *lim); static void blogic_qcompleted_ccb(struct blogic_ccb *); static irqreturn_t blogic_inthandler(int, void *); -static int blogic_resetadapter(struct blogic_adapter *, bool hard_reset); +static int blogic_resetadapter(struct Scsi_Host *host, bool hard_reset) + __must_hold(&host->host_lock); static void blogic_msg(enum blogic_msglevel, char *, struct blogic_adapter *, ...); static int __init blogic_setup(char *); diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c index 7ea38d5090720e..8191d258f162f4 100644 --- a/drivers/scsi/aha1542.c +++ b/drivers/scsi/aha1542.c @@ -271,8 +271,6 @@ static void aha1542_free_cmd(struct scsi_cmnd *cmd) buf += bv.bv_len; } } - - scsi_dma_unmap(cmd); } static irqreturn_t aha1542_interrupt(int irq, void *dev_id) diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c index 3602a1fc40e4e5..4abc7948187f89 100644 --- a/drivers/scsi/aic7xxx/aic79xx_core.c +++ b/drivers/scsi/aic7xxx/aic79xx_core.c @@ -8942,8 +8942,10 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb) } #endif - if (ahd_perform_autosense(scb) == 0) + if (ahd_perform_autosense(scb) == 0) { + ahd_done(ahd, scb); break; + } ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb), SCB_GET_TARGET(ahd, scb), diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h index c6eb2b97e929c6..1facfd238f895f 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.h +++ b/drivers/scsi/aic7xxx/aic79xx_osm.h @@ -501,6 +501,8 @@ int ahd_linux_show_info(struct seq_file *,struct Scsi_Host *); static inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status) { + if (!cmd) + return; cmd->result &= ~(CAM_STATUS_MASK << 16); cmd->result |= status << 16; } @@ -514,6 +516,8 @@ void ahd_set_transaction_status(struct scb *scb, uint32_t status) static inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status) { + if (!cmd) + return; cmd->result &= ~0xFFFF; cmd->result |= status; } @@ -527,6 +531,8 @@ void ahd_set_scsi_status(struct scb *scb, uint32_t status) static inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd) { + if (!cmd) + return CAM_REQ_INPROG; return ((cmd->result >> 16) & CAM_STATUS_MASK); } @@ -539,6 +545,8 @@ uint32_t ahd_get_transaction_status(struct scb *scb) static inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd) { + if (!cmd) + return SAM_STAT_GOOD; return (cmd->result & 0xFFFF); } @@ -566,13 +574,16 @@ u_long ahd_get_transfer_length(struct scb *scb) static inline int ahd_get_transfer_dir(struct scb *scb) { + if (!scb->io_ctx) + return DMA_NONE; return (scb->io_ctx->sc_data_direction); } static inline void ahd_set_residual(struct scb *scb, u_long resid) { - scsi_set_resid(scb->io_ctx, resid); + if (scb->io_ctx) + scsi_set_resid(scb->io_ctx, resid); } static inline @@ -584,6 +595,8 @@ void ahd_set_sense_residual(struct scb *scb, u_long resid) static inline u_long ahd_get_residual(struct scb *scb) { + if (!scb->io_ctx) + return 0; return scsi_get_resid(scb->io_ctx); } @@ -597,11 +610,12 @@ static inline int ahd_perform_autosense(struct scb *scb) { /* - * We always perform autosense in Linux. - * On other platforms this is set on a - * per-transaction basis. + * We always perform autosense in Linux, except for the device + * reset SCB, which has no command to return sense data to. */ - return (1); + if (!scb->io_ctx) + return 0; + return 1; } static inline uint32_t @@ -631,6 +645,8 @@ void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb); static inline void ahd_freeze_scb(struct scb *scb) { + if (!scb->io_ctx) + return; if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) { scb->io_ctx->result |= CAM_DEV_QFRZN << 16; scb->platform_data->dev->qfrozen++; diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c index b9761f9f0bbc8f..af6115bfb28082 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_core.c +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c @@ -1097,7 +1097,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) sc->byte2 = SCB_GET_LUN(scb) << 5; sc->unused[0] = 0; sc->unused[1] = 0; - sc->length = sg->len; + sc->length = ahc_get_sense_bufsize(ahc, scb); sc->control = 0; /* @@ -5266,9 +5266,13 @@ ahc_init(struct ahc_softc *ahc) /* * Assume we have a board at this stage and it has been reset. + * PCI controllers keep the host ID ahc_pci_config() chose. */ - if ((ahc->flags & AHC_USEDEFAULTS) != 0) - ahc->our_id = ahc->our_id_b = 7; + if ((ahc->flags & AHC_USEDEFAULTS) != 0) { + if ((ahc->chip & AHC_PCI) == 0) + ahc->our_id = 7; + ahc->our_id_b = 7; + } /* * Default to allowing initiator operations. diff --git a/drivers/scsi/aic7xxx/aic7xxx_pci.c b/drivers/scsi/aic7xxx/aic7xxx_pci.c index 2d4c85426dc3eb..5a04c7d55e4b5b 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_pci.c +++ b/drivers/scsi/aic7xxx/aic7xxx_pci.c @@ -701,6 +701,21 @@ ahc_find_pci_device(ahc_dev_softc_t pci) return (NULL); } +/* + * The SGI O2 firmware runs its onboard controllers, in slots 1 and 2 of the + * root bus, without the Adaptec BIOS and at host ID 0. It leaves no settings + * in scratch RAM, which may still hold power-on contents with bad parity. + */ +static bool +ahc_pci_sgi_o2_onboard(struct ahc_softc *ahc) +{ + int slot = ahc_get_pci_slot(ahc->dev_softc); + + return IS_ENABLED(CONFIG_SGI_IP32) && + ahc_get_pci_bus(ahc->dev_softc) == 0 && + (slot == 1 || slot == 2); +} + int ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry) { @@ -782,6 +797,9 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry) ahc->bus_intr = ahc_pci_intr; ahc->bus_chip_init = ahc_pci_chip_init; + if (ahc_pci_sgi_o2_onboard(ahc)) + ahc->flags |= AHC_NO_BIOS_INIT; + /* Remember how the card was setup in case there is no SEEPROM */ if ((ahc_inb(ahc, HCNTRL) & POWRDN) == 0) { ahc_pause(ahc); @@ -898,7 +916,7 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry) * Assume only one connector and always turn * on termination. */ - our_id = 0x07; + our_id = ahc_pci_sgi_o2_onboard(ahc) ? 0 : 0x07; sxfrctl1 = STPWEN; } ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI); diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index 356ab9c0fb7cf1..cadcaefaa8a52e 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -4007,9 +4007,8 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba) /* Allocate memory for CID array */ ptr_cid_info->cid_array = - kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num), - sizeof(*ptr_cid_info->cid_array), - GFP_KERNEL); + kzalloc_objs(*ptr_cid_info->cid_array, + BEISCSI_GET_CID_COUNT(phba, ulp_num)); if (!ptr_cid_info->cid_array) { kfree(ptr_cid_info); ptr_cid_info = NULL; diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index cf7aa0a699cde4..06455c7a9e2ad5 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -2320,9 +2320,8 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba) if (!hisi_hba->itct) goto err_out; - hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, - sizeof(struct hisi_sas_slot), - GFP_KERNEL); + hisi_hba->slot_info = devm_kzalloc_objs(dev, struct hisi_sas_slot, + max_command_entries); if (!hisi_hba->slot_info) goto err_out; diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 187505950b630f..14e9ba69316926 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -6500,7 +6500,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, return -EINVAL; if (ioc->buf_size > ioc->malloc_size * SG_ENTRIES_IN_CMD) return -EINVAL; - buff = kcalloc(SG_ENTRIES_IN_CMD, sizeof(*buff), GFP_KERNEL); + buff = kzalloc_objs(*buff, SG_ENTRIES_IN_CMD); if (!buff) { status = -ENOMEM; goto cleanup1; @@ -8640,7 +8640,7 @@ static struct ctlr_info *hpda_alloc_ctlr_info(void) if (!h) return NULL; - h->reply_map = kcalloc(nr_cpu_ids, sizeof(*h->reply_map), GFP_KERNEL); + h->reply_map = kzalloc_objs(*h->reply_map, nr_cpu_ids); if (!h->reply_map) { kfree(h); return NULL; diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c index acf0c2038d208e..005477f02cd60e 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -483,7 +483,7 @@ static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id) struct Scsi_Host *shost; int err, i; - ihost = devm_kzalloc(&pdev->dev, sizeof(*ihost), GFP_KERNEL); + ihost = devm_kzalloc_obj(&pdev->dev, *ihost); if (!ihost) return NULL; @@ -599,7 +599,7 @@ static int isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) dev_info(&pdev->dev, "driver configured for rev: %d silicon\n", pdev->revision); - pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL); + pci_info = devm_kzalloc_obj(&pdev->dev, *pci_info); if (!pci_info) return -ENOMEM; pci_set_drvdata(pdev, pci_info); diff --git a/drivers/scsi/isci/probe_roms.c b/drivers/scsi/isci/probe_roms.c index a2bbe46f8ccbd3..cfcf6d430a2eb1 100644 --- a/drivers/scsi/isci/probe_roms.c +++ b/drivers/scsi/isci/probe_roms.c @@ -52,7 +52,7 @@ struct isci_orom *isci_request_oprom(struct pci_dev *pdev) return NULL; len = pci_biosrom_size(pdev); - rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL); + rom = devm_kzalloc_obj(&pdev->dev, *rom); if (!rom) { pci_unmap_biosrom(oprom); dev_warn(&pdev->dev, diff --git a/drivers/scsi/leapraid/leapraid_func.c b/drivers/scsi/leapraid/leapraid_func.c index 66b43c1c72e1b0..573bccf1a4cea0 100644 --- a/drivers/scsi/leapraid/leapraid_func.c +++ b/drivers/scsi/leapraid/leapraid_func.c @@ -7839,7 +7839,7 @@ static int leapraid_request_host_memory(struct leapraid_adapter *adapter) /* Allocate I/O tracker to SCSI I/O. */ adapter->mem_desc.taskid_to_uniq_tag = - kcalloc(adapter->shost->can_queue, sizeof(u16), GFP_KERNEL); + kzalloc_objs(u16, adapter->shost->can_queue); if (!adapter->mem_desc.taskid_to_uniq_tag) return -ENOMEM; diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index 2340790c9f6ba4..8f5f1ef6f6193b 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -372,6 +372,7 @@ static int local_ata_check_ready(struct ata_link *link) } } +__printf(3, 4) static int sas_ata_printk(const char *level, const struct domain_device *ddev, const char *fmt, ...) { diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 7352cb6e584bfc..6df5f4e7c5d655 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -3026,7 +3026,7 @@ lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) uint32_t *HashWorking; uint32_t *pwwnn = (uint32_t *) phba->wwnn; - HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); + HashWorking = kzalloc_objs(uint32_t, 80); if (!HashWorking) return; @@ -8347,8 +8347,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; - phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), - GFP_KERNEL); + phba->fcf.fcf_rr_bmask = kzalloc_objs(unsigned long, longs); if (!phba->fcf.fcf_rr_bmask) { lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, "2759 Failed allocate memory for FCF round " diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c index 715b328d3d184c..9173263c87f937 100644 --- a/drivers/scsi/lpfc/lpfc_sli.c +++ b/drivers/scsi/lpfc/lpfc_sli.c @@ -5727,17 +5727,14 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba) */ if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; - phba->vpi_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->vpi_bmask = kzalloc_objs(unsigned long, longs); if (!phba->vpi_bmask) { rc = -ENOMEM; goto lpfc_sli_hba_setup_error; } - phba->vpi_ids = kcalloc(phba->max_vpi + 1, - sizeof(uint16_t), - GFP_KERNEL); + phba->vpi_ids = kzalloc_objs(uint16_t, + phba->max_vpi + 1); if (!phba->vpi_ids) { kfree(phba->vpi_bmask); rc = -ENOMEM; @@ -6467,16 +6464,12 @@ lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) length = sizeof(struct lpfc_rsrc_blks); switch (type) { case LPFC_RSC_TYPE_FCOE_RPI: - phba->sli4_hba.rpi_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.rpi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.rpi_bmask)) { rc = -ENOMEM; goto err_exit; } - phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, - sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.rpi_ids = kzalloc_objs(uint16_t, rsrc_id_cnt); if (unlikely(!phba->sli4_hba.rpi_ids)) { kfree(phba->sli4_hba.rpi_bmask); rc = -ENOMEM; @@ -6496,14 +6489,12 @@ lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; break; case LPFC_RSC_TYPE_FCOE_VPI: - phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), - GFP_KERNEL); + phba->vpi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->vpi_bmask)) { rc = -ENOMEM; goto err_exit; } - phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), - GFP_KERNEL); + phba->vpi_ids = kzalloc_objs(uint16_t, rsrc_id_cnt); if (unlikely(!phba->vpi_ids)) { kfree(phba->vpi_bmask); rc = -ENOMEM; @@ -6516,17 +6507,13 @@ lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) ext_blk_list = &phba->lpfc_vpi_blk_list; break; case LPFC_RSC_TYPE_FCOE_XRI: - phba->sli4_hba.xri_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.xri_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.xri_bmask)) { rc = -ENOMEM; goto err_exit; } phba->sli4_hba.max_cfg_param.xri_used = 0; - phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, - sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.xri_ids = kzalloc_objs(uint16_t, rsrc_id_cnt); if (unlikely(!phba->sli4_hba.xri_ids)) { kfree(phba->sli4_hba.xri_bmask); rc = -ENOMEM; @@ -6539,16 +6526,12 @@ lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; break; case LPFC_RSC_TYPE_FCOE_VFI: - phba->sli4_hba.vfi_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.vfi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.vfi_bmask)) { rc = -ENOMEM; goto err_exit; } - phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, - sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.vfi_ids = kzalloc_objs(uint16_t, rsrc_id_cnt); if (unlikely(!phba->sli4_hba.vfi_ids)) { kfree(phba->sli4_hba.vfi_bmask); rc = -ENOMEM; @@ -7232,15 +7215,12 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) } base = phba->sli4_hba.max_cfg_param.rpi_base; longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; - phba->sli4_hba.rpi_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.rpi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.rpi_bmask)) { rc = -ENOMEM; goto err_exit; } - phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.rpi_ids = kzalloc_objs(uint16_t, count); if (unlikely(!phba->sli4_hba.rpi_ids)) { rc = -ENOMEM; goto free_rpi_bmask; @@ -7260,14 +7240,12 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) } base = phba->sli4_hba.max_cfg_param.vpi_base; longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; - phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), - GFP_KERNEL); + phba->vpi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->vpi_bmask)) { rc = -ENOMEM; goto free_rpi_ids; } - phba->vpi_ids = kcalloc(count, sizeof(uint16_t), - GFP_KERNEL); + phba->vpi_ids = kzalloc_objs(uint16_t, count); if (unlikely(!phba->vpi_ids)) { rc = -ENOMEM; goto free_vpi_bmask; @@ -7287,16 +7265,13 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) } base = phba->sli4_hba.max_cfg_param.xri_base; longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; - phba->sli4_hba.xri_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.xri_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.xri_bmask)) { rc = -ENOMEM; goto free_vpi_ids; } phba->sli4_hba.max_cfg_param.xri_used = 0; - phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.xri_ids = kzalloc_objs(uint16_t, count); if (unlikely(!phba->sli4_hba.xri_ids)) { rc = -ENOMEM; goto free_xri_bmask; @@ -7316,15 +7291,12 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) } base = phba->sli4_hba.max_cfg_param.vfi_base; longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; - phba->sli4_hba.vfi_bmask = kcalloc(longs, - sizeof(unsigned long), - GFP_KERNEL); + phba->sli4_hba.vfi_bmask = kzalloc_objs(unsigned long, longs); if (unlikely(!phba->sli4_hba.vfi_bmask)) { rc = -ENOMEM; goto free_xri_ids; } - phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), - GFP_KERNEL); + phba->sli4_hba.vfi_ids = kzalloc_objs(uint16_t, count); if (unlikely(!phba->sli4_hba.vfi_ids)) { rc = -ENOMEM; goto free_vfi_bmask; diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 1064c5baae8e49..602173fd313a0f 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -7157,8 +7157,7 @@ static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance) */ static int megasas_alloc_ctrl_mem(struct megasas_instance *instance) { - instance->reply_map = kcalloc(nr_cpu_ids, sizeof(unsigned int), - GFP_KERNEL); + instance->reply_map = kzalloc_objs(unsigned int, nr_cpu_ids); if (!instance->reply_map) return -ENOMEM; diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 1af25a22611a13..5c957044eded18 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -6589,8 +6589,7 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc) ioc->internal, ioc->internal_depth, ioc->internal_smid)); - ioc->io_queue_num = kcalloc(ioc->scsiio_depth, - sizeof(u16), GFP_KERNEL); + ioc->io_queue_num = kzalloc_objs(u16, ioc->scsiio_depth); if (!ioc->io_queue_num) goto out; /* diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 085d4672db8545..a77bbc3d2b6662 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -7700,7 +7700,9 @@ _scsih_determine_disposition(struct MPT3SAS_ADAPTER *ioc, u16 scode = scsi_sense_code(sense_info.asc, sense_info.ascq); - if (scode == + if (scode == LU_NOT_READY_SANITIZE_IN_PROGRESS) + rc = DEVICE_READY; + else if (scode == LU_NOT_READY_MANUAL_INTERVENTION_REQUIRED || scode == LU_NOT_ACCESSIBLE_TARGET_PORT_IN_STANDBY_STATE || diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c index 5eec248a77a6b3..e4a65d7a237422 100644 --- a/drivers/scsi/scsi_bsg.c +++ b/drivers/scsi/scsi_bsg.c @@ -41,7 +41,7 @@ static void scsi_bsg_uring_task_cb(struct io_tw_req tw_req, io_tw_token_t tw) u8 sense_len_wr = 0; if (pdu->bio) - blk_rq_unmap_user(pdu->bio); + ret = blk_rq_unmap_user(pdu->bio); if (scsi_status_is_check_condition(scmd->result)) { driver_status = DRIVER_SENSE; @@ -199,7 +199,7 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr, struct scsi_cmnd *scmd; struct request *rq; struct bio *bio; - int ret; + int ret, unmap_ret; if (hdr->protocol != BSG_PROTOCOL_SCSI || hdr->subprotocol != BSG_SUB_PROTOCOL_SCSI_CMD) @@ -273,7 +273,9 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr, else hdr->dout_resid = scmd->resid_len; - blk_rq_unmap_user(bio); + unmap_ret = blk_rq_unmap_user(bio); + if (!ret) + ret = unmap_ret; out_put_request: blk_mq_free_request(rq); diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index a922c8318a2fb4..c5c4312e23aac3 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -9053,6 +9053,7 @@ static void __exit scsi_debug_exit(void) sdebug_erase_all_stores(false); xa_destroy(per_store_ap); + async_synchronize_full_domain(&sdebug_async_domain); debugfs_remove(sdebug_debugfs_root); } diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 8aae12fd38f3a6..52f3b525d2fdae 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -2154,14 +2154,13 @@ struct scsi_device *scsi_get_pseudo_sdev(struct Scsi_Host *shost) goto out; sdev = scsi_alloc_sdev(starget, U64_MAX, NULL); - if (!sdev) { - scsi_target_reap(starget); + if (!sdev) goto put_target; - } sdev->borken = 0; put_target: + scsi_target_reap(starget); /* See also the get_device(dev) call in scsi_alloc_target(). */ put_device(&starget->dev); diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c index ffbe60234eefc6..913ce0dc07e0c7 100644 --- a/drivers/sh/intc/core.c +++ b/drivers/sh/intc/core.c @@ -243,12 +243,12 @@ int __init register_intc_controller(struct intc_desc *desc) d->nr_reg += hw->ack_regs ? hw->nr_ack_regs : 0; d->nr_reg += hw->subgroups ? hw->nr_subgroups : 0; - d->reg = kcalloc(d->nr_reg, sizeof(*d->reg), GFP_NOWAIT); + d->reg = kzalloc_objs(*d->reg, d->nr_reg, GFP_NOWAIT); if (!d->reg) goto err2; #ifdef CONFIG_SMP - d->smp = kcalloc(d->nr_reg, sizeof(*d->smp), GFP_NOWAIT); + d->smp = kzalloc_objs(*d->smp, d->nr_reg, GFP_NOWAIT); if (!d->smp) goto err3; #endif diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c index eb983b6d1815fa..8da75c4b50e529 100644 --- a/drivers/slimbus/qcom-ngd-ctrl.c +++ b/drivers/slimbus/qcom-ngd-ctrl.c @@ -456,7 +456,7 @@ static int qcom_slim_qmi_init(struct qcom_slim_ngd_ctrl *ctrl, struct qmi_handle *handle; int rc; - handle = devm_kzalloc(ctrl->dev, sizeof(*handle), GFP_KERNEL); + handle = devm_kzalloc_obj(ctrl->dev, *handle); if (!handle) return -ENOMEM; @@ -1673,7 +1673,7 @@ static int qcom_slim_ngd_ctrl_probe(struct platform_device *pdev) int ret; struct pdr_service *pds; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/soc/amlogic/meson-canvas.c b/drivers/soc/amlogic/meson-canvas.c index 79681afea8c612..124187fe08327c 100644 --- a/drivers/soc/amlogic/meson-canvas.c +++ b/drivers/soc/amlogic/meson-canvas.c @@ -168,7 +168,7 @@ static int meson_canvas_probe(struct platform_device *pdev) struct meson_canvas *canvas; struct device *dev = &pdev->dev; - canvas = devm_kzalloc(dev, sizeof(*canvas), GFP_KERNEL); + canvas = devm_kzalloc_obj(dev, *canvas); if (!canvas) return -ENOMEM; diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c index 33767f0bc67c63..9e4d4d7d7162b6 100644 --- a/drivers/soc/amlogic/meson-clk-measure.c +++ b/drivers/soc/amlogic/meson-clk-measure.c @@ -2002,8 +2002,7 @@ static int meson_msr_probe(struct platform_device *pdev) void __iomem *base; int i; - priv = devm_kzalloc(&pdev->dev, sizeof(struct meson_msr), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct meson_msr); if (!priv) return -ENOMEM; @@ -2013,10 +2012,9 @@ static int meson_msr_probe(struct platform_device *pdev) return -ENODEV; } - priv->data.msr_table = devm_kcalloc(&pdev->dev, - match_data->msr_count, - sizeof(struct meson_msr_id), - GFP_KERNEL); + priv->data.msr_table = devm_kzalloc_objs(&pdev->dev, + struct meson_msr_id, + match_data->msr_count); if (!priv->data.msr_table) return -ENOMEM; @@ -2034,8 +2032,7 @@ static int meson_msr_probe(struct platform_device *pdev) if (IS_ERR(priv->regmap)) return PTR_ERR(priv->regmap); - priv->data.reg = devm_kzalloc(&pdev->dev, sizeof(struct msr_reg_offset), - GFP_KERNEL); + priv->data.reg = devm_kzalloc_obj(&pdev->dev, struct msr_reg_offset); if (!priv->data.reg) return -ENOMEM; diff --git a/drivers/soc/apple/apple-pmgr-misc.c b/drivers/soc/apple/apple-pmgr-misc.c index 7db29f7de3294b..4e6f9f24e71985 100644 --- a/drivers/soc/apple/apple-pmgr-misc.c +++ b/drivers/soc/apple/apple-pmgr-misc.c @@ -116,7 +116,7 @@ static int apple_pmgr_misc_probe(struct platform_device *pdev) struct apple_pmgr_misc *misc; int ret; - misc = devm_kzalloc(dev, sizeof(*misc), GFP_KERNEL); + misc = devm_kzalloc_obj(dev, *misc); if (!misc) return -ENOMEM; diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 5c48455185c9ba..9770ef4fb7b488 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -338,7 +338,7 @@ static int apple_mbox_probe(struct platform_device *pdev) struct apple_mbox *mbox; struct device *dev = &pdev->dev; - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); + mbox = devm_kzalloc_obj(dev, *mbox); if (!mbox) return -ENOMEM; diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index 66b99955b395b6..520396e8bd17fe 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -183,7 +183,7 @@ static int apple_sart_probe(struct platform_device *pdev) struct apple_sart *sart; struct device *dev = &pdev->dev; - sart = devm_kzalloc(dev, sizeof(*sart), GFP_KERNEL); + sart = devm_kzalloc_obj(dev, *sart); if (!sart) return -ENOMEM; diff --git a/drivers/soc/apple/tunable.c b/drivers/soc/apple/tunable.c index 6593238391715b..10fa09a631c525 100644 --- a/drivers/soc/apple/tunable.c +++ b/drivers/soc/apple/tunable.c @@ -38,7 +38,7 @@ struct apple_tunable *devm_apple_tunable_parse(struct device *dev, return ERR_PTR(-EINVAL); sz = prop->length / (3 * sizeof(u32)); - tunable = devm_kzalloc(dev, struct_size(tunable, values, sz), GFP_KERNEL); + tunable = devm_kzalloc_flex(dev, *tunable, values, sz); if (!tunable) return ERR_PTR(-ENOMEM); tunable->sz = sz; diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c b/drivers/soc/aspeed/aspeed-lpc-ctrl.c index 4d8574cac703b5..5d91ba2038d5c4 100644 --- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c +++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c @@ -231,7 +231,7 @@ static int aspeed_lpc_ctrl_probe(struct platform_device *pdev) dev = &pdev->dev; - lpc_ctrl = devm_kzalloc(dev, sizeof(*lpc_ctrl), GFP_KERNEL); + lpc_ctrl = devm_kzalloc_obj(dev, *lpc_ctrl); if (!lpc_ctrl) return -ENOMEM; diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index b09dca34099fe5..99fca2cbb9b319 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -314,7 +314,7 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev) dev = &pdev->dev; - lpc_snoop = devm_kzalloc(dev, sizeof(*lpc_snoop), GFP_KERNEL); + lpc_snoop = devm_kzalloc_obj(dev, *lpc_snoop); if (!lpc_snoop) return -ENOMEM; diff --git a/drivers/soc/aspeed/aspeed-p2a-ctrl.c b/drivers/soc/aspeed/aspeed-p2a-ctrl.c index b6b7b80f842a24..efa106d37bd762 100644 --- a/drivers/soc/aspeed/aspeed-p2a-ctrl.c +++ b/drivers/soc/aspeed/aspeed-p2a-ctrl.c @@ -338,7 +338,7 @@ static int aspeed_p2a_ctrl_probe(struct platform_device *pdev) dev = &pdev->dev; - misc_ctrl = devm_kzalloc(dev, sizeof(*misc_ctrl), GFP_KERNEL); + misc_ctrl = devm_kzalloc_obj(dev, *misc_ctrl); if (!misc_ctrl) return -ENOMEM; diff --git a/drivers/soc/aspeed/aspeed-uart-routing.c b/drivers/soc/aspeed/aspeed-uart-routing.c index b4b521b5ddf191..3b3f18b00968f7 100644 --- a/drivers/soc/aspeed/aspeed-uart-routing.c +++ b/drivers/soc/aspeed/aspeed-uart-routing.c @@ -542,7 +542,7 @@ static int aspeed_uart_routing_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct aspeed_uart_routing *uart_routing; - uart_routing = devm_kzalloc(&pdev->dev, sizeof(*uart_routing), GFP_KERNEL); + uart_routing = devm_kzalloc_obj(&pdev->dev, *uart_routing); if (!uart_routing) return -ENOMEM; diff --git a/drivers/soc/atmel/sfr.c b/drivers/soc/atmel/sfr.c index cc94ca1b494ce5..badd7c550fa5ac 100644 --- a/drivers/soc/atmel/sfr.c +++ b/drivers/soc/atmel/sfr.c @@ -47,7 +47,7 @@ static int atmel_sfr_probe(struct platform_device *pdev) u8 sn[SFR_SN_SIZE]; int ret; - priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/soc/cirrus/soc-ep93xx.c b/drivers/soc/cirrus/soc-ep93xx.c index d55cf28ed7269d..5f6820925040cc 100644 --- a/drivers/soc/cirrus/soc-ep93xx.c +++ b/drivers/soc/cirrus/soc-ep93xx.c @@ -189,7 +189,7 @@ static int __init ep93xx_syscon_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - attrs = devm_kzalloc(dev, sizeof(*attrs), GFP_KERNEL); + attrs = devm_kzalloc_obj(dev, *attrs); if (!attrs) return -ENOMEM; @@ -203,7 +203,7 @@ static int __init ep93xx_syscon_probe(struct platform_device *pdev) if (IS_ERR(soc_dev)) return PTR_ERR(soc_dev); - map_info = devm_kzalloc(dev, sizeof(*map_info), GFP_KERNEL); + map_info = devm_kzalloc_obj(dev, *map_info); if (!map_info) return -ENOMEM; diff --git a/drivers/soc/fsl/dpio/dpio-driver.c b/drivers/soc/fsl/dpio/dpio-driver.c index d8f28fb7c37aa3..3534453047f61c 100644 --- a/drivers/soc/fsl/dpio/dpio-driver.c +++ b/drivers/soc/fsl/dpio/dpio-driver.c @@ -125,7 +125,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) int possible_next_cpu; int sdest; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) goto err_priv_alloc; diff --git a/drivers/soc/fsl/qbman/bman_portal.c b/drivers/soc/fsl/qbman/bman_portal.c index 4d7b9caee1c471..046034a7cba338 100644 --- a/drivers/soc/fsl/qbman/bman_portal.c +++ b/drivers/soc/fsl/qbman/bman_portal.c @@ -110,7 +110,7 @@ static int bman_portal_probe(struct platform_device *pdev) return -ENODEV; } - pcfg = devm_kmalloc(dev, sizeof(*pcfg), GFP_KERNEL); + pcfg = devm_kmalloc_obj(dev, *pcfg); if (!pcfg) { __bman_portals_probed = -1; return -ENOMEM; diff --git a/drivers/soc/fsl/qbman/dpaa_sys.c b/drivers/soc/fsl/qbman/dpaa_sys.c index e1d7b79cc45039..3504ff5572314b 100644 --- a/drivers/soc/fsl/qbman/dpaa_sys.c +++ b/drivers/soc/fsl/qbman/dpaa_sys.c @@ -69,7 +69,7 @@ int qbman_init_private_mem(struct device *dev, int idx, const char *compat, if (!of_property_present(mem_node, "reg")) { struct property *prop; - prop = devm_kzalloc(dev, sizeof(*prop), GFP_KERNEL); + prop = devm_kzalloc_obj(dev, *prop); if (!prop) return -ENOMEM; prop->value = res_array = devm_kzalloc(dev, sizeof(__be32) * 4, diff --git a/drivers/soc/fsl/qbman/qman_portal.c b/drivers/soc/fsl/qbman/qman_portal.c index 456ef5d5c1996b..d2063a86866a2d 100644 --- a/drivers/soc/fsl/qbman/qman_portal.c +++ b/drivers/soc/fsl/qbman/qman_portal.c @@ -196,7 +196,7 @@ static int qman_portal_probe(struct platform_device *pdev) return -ENODEV; } - pcfg = devm_kmalloc(dev, sizeof(*pcfg), GFP_KERNEL); + pcfg = devm_kmalloc_obj(dev, *pcfg); if (!pcfg) { __qman_portals_probed = -1; return -ENOMEM; diff --git a/drivers/soc/fsl/qe/gpio.c b/drivers/soc/fsl/qe/gpio.c index 1b5a1b134596e8..3fc1ff742279d0 100644 --- a/drivers/soc/fsl/qe/gpio.c +++ b/drivers/soc/fsl/qe/gpio.c @@ -330,7 +330,7 @@ static int qe_gpio_probe(struct platform_device *ofdev) struct qe_gpio_chip *qe_gc; struct gpio_chip *gc; - qe_gc = devm_kzalloc(dev, sizeof(*qe_gc), GFP_KERNEL); + qe_gc = devm_kzalloc_obj(dev, *qe_gc); if (!qe_gc) return -ENOMEM; qe_gc->np = np; diff --git a/drivers/soc/fsl/qe/qe_ic.c b/drivers/soc/fsl/qe/qe_ic.c index bccc7d612009b3..f9fc976a1dd4f2 100644 --- a/drivers/soc/fsl/qe/qe_ic.c +++ b/drivers/soc/fsl/qe/qe_ic.c @@ -414,7 +414,7 @@ static int qe_ic_init(struct platform_device *pdev) return -ENODEV; } - qe_ic = devm_kzalloc(dev, sizeof(*qe_ic), GFP_KERNEL); + qe_ic = devm_kzalloc_obj(dev, *qe_ic); if (qe_ic == NULL) return -ENOMEM; diff --git a/drivers/soc/fsl/qe/qe_ports_ic.c b/drivers/soc/fsl/qe/qe_ports_ic.c index fb3b92039547a6..14242dcddd36f1 100644 --- a/drivers/soc/fsl/qe/qe_ports_ic.c +++ b/drivers/soc/fsl/qe/qe_ports_ic.c @@ -151,7 +151,7 @@ static int qepic_probe(struct platform_device *pdev) struct irq_domain *domain; struct qepic_data *data; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; d_info.host_data = data; diff --git a/drivers/soc/fsl/qe/qmc.c b/drivers/soc/fsl/qe/qmc.c index 672adff8e35f4c..f17829fc0aad24 100644 --- a/drivers/soc/fsl/qe/qmc.c +++ b/drivers/soc/fsl/qe/qmc.c @@ -1301,7 +1301,7 @@ static int qmc_of_parse_chans(struct qmc *qmc, struct device_node *np) return -EINVAL; } - chan = devm_kzalloc(qmc->dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(qmc->dev, *chan); if (!chan) return -ENOMEM; @@ -1906,7 +1906,7 @@ static int qmc_probe(struct platform_device *pdev) int irq; int ret; - qmc = devm_kzalloc(&pdev->dev, sizeof(*qmc), GFP_KERNEL); + qmc = devm_kzalloc_obj(&pdev->dev, *qmc); if (!qmc) return -ENOMEM; diff --git a/drivers/soc/fsl/qe/tsa.c b/drivers/soc/fsl/qe/tsa.c index 502e2ffe868984..1bb4d3bc553b89 100644 --- a/drivers/soc/fsl/qe/tsa.c +++ b/drivers/soc/fsl/qe/tsa.c @@ -972,7 +972,7 @@ static int tsa_probe(struct platform_device *pdev) unsigned int i; int ret; - tsa = devm_kzalloc(&pdev->dev, sizeof(*tsa), GFP_KERNEL); + tsa = devm_kzalloc_obj(&pdev->dev, *tsa); if (!tsa) return -ENOMEM; diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index 06bd94b29fb321..7a613b69168474 100644 --- a/drivers/soc/fsl/rcpm.c +++ b/drivers/soc/fsl/rcpm.c @@ -150,7 +150,7 @@ static int rcpm_probe(struct platform_device *pdev) struct rcpm *rcpm; int ret; - rcpm = devm_kzalloc(dev, sizeof(*rcpm), GFP_KERNEL); + rcpm = devm_kzalloc_obj(dev, *rcpm); if (!rcpm) return -ENOMEM; diff --git a/drivers/soc/fujitsu/a64fx-diag.c b/drivers/soc/fujitsu/a64fx-diag.c index 76cb0b6a221c27..aafbd7050cb595 100644 --- a/drivers/soc/fujitsu/a64fx-diag.c +++ b/drivers/soc/fujitsu/a64fx-diag.c @@ -79,7 +79,7 @@ static int a64fx_diag_probe(struct platform_device *pdev) unsigned long irq_flags; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (priv == NULL) return -ENOMEM; diff --git a/drivers/soc/hisilicon/kunpeng_hccs.c b/drivers/soc/hisilicon/kunpeng_hccs.c index 0cc2953d59a54b..3b9fa3a74abd7f 100644 --- a/drivers/soc/hisilicon/kunpeng_hccs.c +++ b/drivers/soc/hisilicon/kunpeng_hccs.c @@ -737,9 +737,9 @@ static int hccs_init_type_name_maps(struct hccs_dev *hdev) u16 idx = 0; hdev->used_type_num = hccs_calc_used_type_num(hdev, hccs_ver); - hdev->type_name_maps = devm_kcalloc(hdev->dev, hdev->used_type_num, - sizeof(struct hccs_type_name_map), - GFP_KERNEL); + hdev->type_name_maps = devm_kzalloc_objs(hdev->dev, + struct hccs_type_name_map, + hdev->used_type_num); if (!hdev->type_name_maps) return -ENOMEM; @@ -1741,7 +1741,7 @@ static int hccs_probe(struct platform_device *pdev) if (!acpi_dev) return -ENODEV; - hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(&pdev->dev, *hdev); if (!hdev) return -ENOMEM; hdev->acpi_dev = acpi_dev; diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c index fc080e56f50d42..f0929916f04235 100644 --- a/drivers/soc/imx/soc-imx8m.c +++ b/drivers/soc/imx/soc-imx8m.c @@ -231,11 +231,11 @@ static int imx8m_soc_probe(struct platform_device *pdev) u64 soc_uid[2] = {0, 0}; int ret; - soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), GFP_KERNEL); + soc_dev_attr = devm_kzalloc_obj(dev, *soc_dev_attr); if (!soc_dev_attr) return -ENOMEM; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/soc/imx/soc-imx9.c b/drivers/soc/imx/soc-imx9.c index 23b54b7d75027d..cc8f3b7d39e6f0 100644 --- a/drivers/soc/imx/soc-imx9.c +++ b/drivers/soc/imx/soc-imx9.c @@ -26,7 +26,7 @@ static int imx9_soc_probe(struct platform_device *pdev) u64 uid127_64, uid63_0; int err; - attr = devm_kzalloc(dev, sizeof(*attr), GFP_KERNEL); + attr = devm_kzalloc_obj(dev, *attr); if (!attr) return -ENOMEM; diff --git a/drivers/soc/litex/litex_soc_ctrl.c b/drivers/soc/litex/litex_soc_ctrl.c index 104a5f9bfd2688..6a2bd4cbc0ce89 100644 --- a/drivers/soc/litex/litex_soc_ctrl.c +++ b/drivers/soc/litex/litex_soc_ctrl.c @@ -90,7 +90,7 @@ static int litex_soc_ctrl_probe(struct platform_device *pdev) struct litex_soc_ctrl_device *soc_ctrl_dev; int error; - soc_ctrl_dev = devm_kzalloc(&pdev->dev, sizeof(*soc_ctrl_dev), GFP_KERNEL); + soc_ctrl_dev = devm_kzalloc_obj(&pdev->dev, *soc_ctrl_dev); if (!soc_ctrl_dev) return -ENOMEM; diff --git a/drivers/soc/loongson/loongson2_guts.c b/drivers/soc/loongson/loongson2_guts.c index a2f2c1e119fe1f..b28d101eb110ba 100644 --- a/drivers/soc/loongson/loongson2_guts.c +++ b/drivers/soc/loongson/loongson2_guts.c @@ -99,7 +99,7 @@ static int loongson2_guts_probe(struct platform_device *pdev) u32 svr; /* Initialize guts */ - guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL); + guts = devm_kzalloc_obj(dev, *guts); if (!guts) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-devapc.c b/drivers/soc/mediatek/mtk-devapc.c index f54c966138b5b8..aaa3c800fe35f6 100644 --- a/drivers/soc/mediatek/mtk-devapc.c +++ b/drivers/soc/mediatek/mtk-devapc.c @@ -261,7 +261,7 @@ static int mtk_devapc_probe(struct platform_device *pdev) if (IS_ERR(node)) return -ENODEV; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-dvfsrc.c b/drivers/soc/mediatek/mtk-dvfsrc.c index e8cdee8aed353c..c691a895c92c11 100644 --- a/drivers/soc/mediatek/mtk-dvfsrc.c +++ b/drivers/soc/mediatek/mtk-dvfsrc.c @@ -520,12 +520,11 @@ static int dvfsrc_get_hw_opps_v4(struct mtk_dvfsrc *dvfsrc) num_opps, num_vcore, num_dram, num_emi); /* Allocate everything now as anything else after that cannot fail */ - desc = devm_kzalloc(dvfsrc->dev, sizeof(*desc), GFP_KERNEL); + desc = devm_kzalloc_obj(dvfsrc->dev, *desc); if (!desc) return -ENOMEM; - dvfsrc_opps = devm_kcalloc(dvfsrc->dev, num_opps + 1, - sizeof(*dvfsrc_opps), GFP_KERNEL); + dvfsrc_opps = devm_kzalloc_objs(dvfsrc->dev, *dvfsrc_opps, num_opps + 1); if (!dvfsrc_opps) return -ENOMEM; @@ -653,7 +652,7 @@ static int mtk_dvfsrc_probe(struct platform_device *pdev) struct mtk_dvfsrc *dvfsrc; int ret; - dvfsrc = devm_kzalloc(&pdev->dev, sizeof(*dvfsrc), GFP_KERNEL); + dvfsrc = devm_kzalloc_obj(&pdev->dev, *dvfsrc); if (!dvfsrc) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c index 2f3e0778bb175e..bfcd9383085629 100644 --- a/drivers/soc/mediatek/mtk-mmsys.c +++ b/drivers/soc/mediatek/mtk-mmsys.c @@ -394,7 +394,7 @@ static int mtk_mmsys_probe(struct platform_device *pdev) struct mtk_mmsys *mmsys; int ret; - mmsys = devm_kzalloc(dev, sizeof(*mmsys), GFP_KERNEL); + mmsys = devm_kzalloc_obj(dev, *mmsys); if (!mmsys) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-mutex.c b/drivers/soc/mediatek/mtk-mutex.c index eb5d381ff5aff6..6d4e475cb92d9e 100644 --- a/drivers/soc/mediatek/mtk-mutex.c +++ b/drivers/soc/mediatek/mtk-mutex.c @@ -1098,7 +1098,7 @@ static int mtk_mutex_probe(struct platform_device *pdev) struct resource *regs; int i, ret; - mtx = devm_kzalloc(dev, sizeof(*mtx), GFP_KERNEL); + mtx = devm_kzalloc_obj(dev, *mtx); if (!mtx) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c index 0bcd8582637550..90677187c3b566 100644 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c @@ -2480,7 +2480,7 @@ static int pwrap_probe(struct platform_device *pdev) return -EINVAL; } - wrp = devm_kzalloc(&pdev->dev, sizeof(*wrp), GFP_KERNEL); + wrp = devm_kzalloc_obj(&pdev->dev, *wrp); if (!wrp) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-socinfo.c b/drivers/soc/mediatek/mtk-socinfo.c index e294730ba7094d..cd14706c2f28a1 100644 --- a/drivers/soc/mediatek/mtk-socinfo.c +++ b/drivers/soc/mediatek/mtk-socinfo.c @@ -72,7 +72,7 @@ static int mtk_socinfo_create_socinfo_node(struct mtk_socinfo *mtk_socinfop) struct socinfo_data *data = mtk_socinfop->socinfo_data; static const char *soc_manufacturer = "MediaTek"; - attrs = devm_kzalloc(mtk_socinfop->dev, sizeof(*attrs), GFP_KERNEL); + attrs = devm_kzalloc_obj(mtk_socinfop->dev, *attrs); if (!attrs) return -ENOMEM; @@ -177,7 +177,7 @@ static int mtk_socinfo_probe(struct platform_device *pdev) struct mtk_socinfo *mtk_socinfop; int ret; - mtk_socinfop = devm_kzalloc(&pdev->dev, sizeof(*mtk_socinfop), GFP_KERNEL); + mtk_socinfop = devm_kzalloc_obj(&pdev->dev, *mtk_socinfop); if (!mtk_socinfop) return -ENOMEM; diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c index 99edecb204f254..0f37b3aadaa201 100644 --- a/drivers/soc/mediatek/mtk-svs.c +++ b/drivers/soc/mediatek/mtk-svs.c @@ -1783,7 +1783,7 @@ static int svs_bank_resource_setup(struct svs_platform *svsp) return -EINVAL; } - svsb->dev = devm_kzalloc(svsp->dev, sizeof(*svsb->dev), GFP_KERNEL); + svsb->dev = devm_kzalloc_obj(svsp->dev, *svsb->dev); if (!svsb->dev) return -ENOMEM; @@ -2844,7 +2844,7 @@ static int svs_probe(struct platform_device *pdev) svsp_data = of_device_get_match_data(&pdev->dev); - svsp = devm_kzalloc(&pdev->dev, sizeof(*svsp), GFP_KERNEL); + svsp = devm_kzalloc_obj(&pdev->dev, *svsp); if (!svsp) return -ENOMEM; diff --git a/drivers/soc/pxa/ssp.c b/drivers/soc/pxa/ssp.c index bb0062c165fe90..91ed3c110ec59f 100644 --- a/drivers/soc/pxa/ssp.c +++ b/drivers/soc/pxa/ssp.c @@ -114,7 +114,7 @@ static int pxa_ssp_probe(struct platform_device *pdev) struct ssp_device *ssp; struct device *dev = &pdev->dev; - ssp = devm_kzalloc(dev, sizeof(struct ssp_device), GFP_KERNEL); + ssp = devm_kzalloc_obj(dev, struct ssp_device); if (ssp == NULL) return -ENOMEM; diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 2d5645ff991971..028e57bfae1e35 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -583,7 +583,7 @@ static int apr_probe(struct rpmsg_device *rpdev) struct packet_router *apr; int ret; - apr = devm_kzalloc(dev, sizeof(*apr), GFP_KERNEL); + apr = devm_kzalloc_obj(dev, *apr); if (!apr) return -ENOMEM; diff --git a/drivers/soc/qcom/icc-bwmon.c b/drivers/soc/qcom/icc-bwmon.c index 597f9025e42280..1ee9f5ce35cd8c 100644 --- a/drivers/soc/qcom/icc-bwmon.c +++ b/drivers/soc/qcom/icc-bwmon.c @@ -757,7 +757,7 @@ static int bwmon_probe(struct platform_device *pdev) struct icc_bwmon *bwmon; int ret; - bwmon = devm_kzalloc(dev, sizeof(*bwmon), GFP_KERNEL); + bwmon = devm_kzalloc_obj(dev, *bwmon); if (!bwmon) return -ENOMEM; diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c index e256595b9826f3..f9ac45505908fc 100644 --- a/drivers/soc/qcom/ice.c +++ b/drivers/soc/qcom/ice.c @@ -573,7 +573,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } - engine = devm_kzalloc(dev, sizeof(*engine), GFP_KERNEL); + engine = devm_kzalloc_obj(dev, *engine); if (!engine) return ERR_PTR(-ENOMEM); diff --git a/drivers/soc/qcom/llcc-qcom.c b/drivers/soc/qcom/llcc-qcom.c index d7a42a8040a163..623765421f07b4 100644 --- a/drivers/soc/qcom/llcc-qcom.c +++ b/drivers/soc/qcom/llcc-qcom.c @@ -5628,8 +5628,7 @@ static int qcom_llcc_get_fw_config(struct platform_device *pdev) sz = le32_to_cpu(slc_mem->slice_descs_count); - drv_data->desc = devm_kcalloc(dev, sz, sizeof(struct llcc_slice_desc), - GFP_KERNEL); + drv_data->desc = devm_kzalloc_objs(dev, struct llcc_slice_desc, sz); if (!drv_data->desc) return -ENOMEM; @@ -5688,7 +5687,7 @@ static int qcom_llcc_probe(struct platform_device *pdev) if (!IS_ERR(drv_data)) return -EBUSY; - drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(dev, *drv_data); if (!drv_data) { ret = -ENOMEM; goto err; @@ -5724,7 +5723,8 @@ static int qcom_llcc_probe(struct platform_device *pdev) drv_data->num_banks = num_banks; - drv_data->regmaps = devm_kcalloc(dev, num_banks, sizeof(*drv_data->regmaps), GFP_KERNEL); + drv_data->regmaps = devm_kzalloc_objs(dev, *drv_data->regmaps, + num_banks); if (!drv_data->regmaps) { ret = -ENOMEM; goto err; @@ -5781,8 +5781,8 @@ static int qcom_llcc_probe(struct platform_device *pdev) } else { drv_data->cfg = cfg->sct_data; drv_data->cfg_size = cfg->size; - drv_data->desc = devm_kcalloc(dev, cfg->size, - sizeof(struct llcc_slice_desc), GFP_KERNEL); + drv_data->desc = devm_kzalloc_objs(dev, struct llcc_slice_desc, + cfg->size); if (!drv_data->desc) { ret = -ENOMEM; diff --git a/drivers/soc/qcom/ocmem.c b/drivers/soc/qcom/ocmem.c index 96ca0b87bfc485..6857701e8be1be 100644 --- a/drivers/soc/qcom/ocmem.c +++ b/drivers/soc/qcom/ocmem.c @@ -300,7 +300,7 @@ static int ocmem_dev_probe(struct platform_device *pdev) if (!qcom_scm_is_available()) return -EPROBE_DEFER; - ocmem = devm_kzalloc(dev, sizeof(*ocmem), GFP_KERNEL); + ocmem = devm_kzalloc_obj(dev, *ocmem); if (!ocmem) return -ENOMEM; @@ -369,8 +369,8 @@ static int ocmem_dev_probe(struct platform_device *pdev) ocmem->num_ports, ocmem->config->num_regions, ocmem->num_macros, ocmem->interleaved ? "" : "not "); - ocmem->regions = devm_kcalloc(dev, ocmem->config->num_regions, - sizeof(struct ocmem_region), GFP_KERNEL); + ocmem->regions = devm_kzalloc_objs(dev, struct ocmem_region, + ocmem->config->num_regions); if (!ocmem->regions) { ret = -ENOMEM; goto err_clk_disable; diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c index 84fd0c82c0c4db..0e354fcd87c9f3 100644 --- a/drivers/soc/qcom/pmic_glink.c +++ b/drivers/soc/qcom/pmic_glink.c @@ -303,7 +303,7 @@ static int pmic_glink_probe(struct platform_device *pdev) struct pmic_glink *pg; int ret; - pg = devm_kzalloc(&pdev->dev, sizeof(*pg), GFP_KERNEL); + pg = devm_kzalloc_obj(&pdev->dev, *pg); if (!pg) return -ENOMEM; diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c index 465e5d2316a048..9fd077737e9f5b 100644 --- a/drivers/soc/qcom/pmic_glink_altmode.c +++ b/drivers/soc/qcom/pmic_glink_altmode.c @@ -577,7 +577,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, u32 port; int ret; - altmode = devm_kzalloc(dev, sizeof(*altmode), GFP_KERNEL); + altmode = devm_kzalloc_obj(dev, *altmode); if (!altmode) return -ENOMEM; diff --git a/drivers/soc/qcom/pmic_pdcharger_ulog.c b/drivers/soc/qcom/pmic_pdcharger_ulog.c index 06cd9c4411c2fb..105a12458d6b1c 100644 --- a/drivers/soc/qcom/pmic_pdcharger_ulog.c +++ b/drivers/soc/qcom/pmic_pdcharger_ulog.c @@ -125,7 +125,7 @@ static int pmic_pdcharger_ulog_rpmsg_probe(struct rpmsg_device *rpdev) struct pmic_pdcharger_ulog *pg; struct device *dev = &rpdev->dev; - pg = devm_kzalloc(dev, sizeof(*pg), GFP_KERNEL); + pg = devm_kzalloc_obj(dev, *pg); if (!pg) return -ENOMEM; diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 074087c592cc31..f2efeca78b56e0 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -698,9 +698,8 @@ int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl) return se->num_clk_levels; } - se->clk_perf_tbl = devm_kcalloc(se->dev, MAX_CLK_PERF_LEVEL, - sizeof(*se->clk_perf_tbl), - GFP_KERNEL); + se->clk_perf_tbl = devm_kzalloc_objs(se->dev, *se->clk_perf_tbl, + MAX_CLK_PERF_LEVEL); if (!se->clk_perf_tbl) return -ENOMEM; @@ -1618,7 +1617,7 @@ static int geni_se_probe(struct platform_device *pdev) const struct geni_se_desc *desc; int ret; - wrapper = devm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL); + wrapper = devm_kzalloc_obj(dev, *wrapper); if (!wrapper) return -ENOMEM; diff --git a/drivers/soc/qcom/qcom-pbs.c b/drivers/soc/qcom/qcom-pbs.c index 06b4a596e27578..aee447200aff0d 100644 --- a/drivers/soc/qcom/qcom-pbs.c +++ b/drivers/soc/qcom/qcom-pbs.c @@ -185,7 +185,7 @@ static int qcom_pbs_probe(struct platform_device *pdev) u32 val; int ret; - pbs = devm_kzalloc(&pdev->dev, sizeof(*pbs), GFP_KERNEL); + pbs = devm_kzalloc_obj(&pdev->dev, *pbs); if (!pbs) return -ENOMEM; diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c index a6b673cd76786b..2d248c7bee0d24 100644 --- a/drivers/soc/qcom/qcom_aoss.c +++ b/drivers/soc/qcom/qcom_aoss.c @@ -401,9 +401,8 @@ static int qmp_cooling_devices_register(struct qmp *qmp) np = qmp->dev->of_node; - qmp->cooling_devs = devm_kcalloc(qmp->dev, QMP_NUM_COOLING_RESOURCES, - sizeof(*qmp->cooling_devs), - GFP_KERNEL); + qmp->cooling_devs = devm_kzalloc_objs(qmp->dev, *qmp->cooling_devs, + QMP_NUM_COOLING_RESOURCES); if (!qmp->cooling_devs) return -ENOMEM; @@ -579,7 +578,7 @@ static int qmp_probe(struct platform_device *pdev) int irq; int ret; - qmp = devm_kzalloc(&pdev->dev, sizeof(*qmp), GFP_KERNEL); + qmp = devm_kzalloc_obj(&pdev->dev, *qmp); if (!qmp) return -ENOMEM; diff --git a/drivers/soc/qcom/qcom_gsbi.c b/drivers/soc/qcom/qcom_gsbi.c index a25d1de592f060..dfffd4c27c0801 100644 --- a/drivers/soc/qcom/qcom_gsbi.c +++ b/drivers/soc/qcom/qcom_gsbi.c @@ -133,7 +133,7 @@ static int gsbi_probe(struct platform_device *pdev) u32 mask, gsbi_num; const struct crci_config *config = NULL; - gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL); + gsbi = devm_kzalloc_obj(&pdev->dev, *gsbi); if (!gsbi) return -ENOMEM; diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c index 3422d6df7b51f2..af40b2ec49bedb 100644 --- a/drivers/soc/qcom/qcom_stats.c +++ b/drivers/soc/qcom/qcom_stats.c @@ -311,8 +311,7 @@ static int qcom_stats_probe(struct platform_device *pdev) if (IS_ERR(reg)) return -ENOMEM; - d = devm_kcalloc(&pdev->dev, config->num_records, - sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_objs(&pdev->dev, *d, config->num_records); if (!d) return -ENOMEM; diff --git a/drivers/soc/qcom/qmi_tmd.c b/drivers/soc/qcom/qmi_tmd.c index 54e5ce8dc462ac..0d7f6091093419 100644 --- a/drivers/soc/qcom/qmi_tmd.c +++ b/drivers/soc/qcom/qmi_tmd.c @@ -419,7 +419,7 @@ static void qmi_tmd_svc_arrive(struct work_struct *work) int ret, i; struct qmi_txn txn; - resp = kzalloc_obj(*resp, GFP_KERNEL); + resp = kzalloc_obj(*resp); if (!resp) { ret = -ENOMEM; goto out; @@ -535,7 +535,7 @@ struct qmi_tmd_client *qmi_tmd_init(struct device *dev, if (!dev || !tmd_names || num_tmds <= 0) return ERR_PTR(-EINVAL); - qmi_tmd_cli = devm_kzalloc(dev, struct_size(qmi_tmd_cli, tmds, num_tmds), GFP_KERNEL); + qmi_tmd_cli = devm_kzalloc_flex(dev, *qmi_tmd_cli, tmds, num_tmds); if (!qmi_tmd_cli) return ERR_PTR(-ENOMEM); diff --git a/drivers/soc/qcom/ramp_controller.c b/drivers/soc/qcom/ramp_controller.c index 15782bed292527..c93842a3149331 100644 --- a/drivers/soc/qcom/ramp_controller.c +++ b/drivers/soc/qcom/ramp_controller.c @@ -290,7 +290,7 @@ static int qcom_ramp_controller_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - qrc = devm_kmalloc(&pdev->dev, sizeof(*qrc), GFP_KERNEL); + qrc = devm_kmalloc_obj(&pdev->dev, *qrc); if (!qrc) return -ENOMEM; diff --git a/drivers/soc/qcom/rpm_master_stats.c b/drivers/soc/qcom/rpm_master_stats.c index c7788337e1647d..df3c10f08ea3a7 100644 --- a/drivers/soc/qcom/rpm_master_stats.c +++ b/drivers/soc/qcom/rpm_master_stats.c @@ -78,7 +78,7 @@ static int master_stats_probe(struct platform_device *pdev) if (count < 0) return count; - data = devm_kcalloc(dev, count, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_objs(dev, *data, count); if (!data) return -ENOMEM; diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index c4542318eac47b..aa4b722c0a87a6 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -1068,7 +1068,7 @@ static int rpmh_rsc_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, ret, "Command DB not available\n"); - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&pdev->dev, *drv); if (!drv) return -ENOMEM; diff --git a/drivers/soc/qcom/smd-rpm.c b/drivers/soc/qcom/smd-rpm.c index f2b3e02abdf138..7037d9845d98a2 100644 --- a/drivers/soc/qcom/smd-rpm.c +++ b/drivers/soc/qcom/smd-rpm.c @@ -196,7 +196,7 @@ static int qcom_smd_rpm_probe(struct rpmsg_device *rpdev) { struct qcom_smd_rpm *rpm; - rpm = devm_kzalloc(&rpdev->dev, sizeof(*rpm), GFP_KERNEL); + rpm = devm_kzalloc_obj(&rpdev->dev, *rpm); if (!rpm) return -ENOMEM; diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index b5e7bd8c1512b3..c394a63e856280 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -1061,7 +1061,7 @@ qcom_smem_enumerate_partitions(struct qcom_smem *smem, u16 local_host) if (!header) return -EINVAL; - part = devm_kzalloc(smem->dev, sizeof(struct smem_partition), GFP_KERNEL); + part = devm_kzalloc_obj(smem->dev, struct smem_partition); if (!part) return -ENOMEM; @@ -1153,8 +1153,7 @@ static int qcom_smem_probe(struct platform_device *pdev) if (of_property_present(pdev->dev.of_node, "qcom,rpm-msg-ram")) num_regions++; - smem = devm_kzalloc(&pdev->dev, struct_size(smem, regions, num_regions), - GFP_KERNEL); + smem = devm_kzalloc_flex(&pdev->dev, *smem, regions, num_regions); if (!smem) return -ENOMEM; diff --git a/drivers/soc/qcom/smem_dramc.c b/drivers/soc/qcom/smem_dramc.c index 497513c953084d..a1964faf234109 100644 --- a/drivers/soc/qcom/smem_dramc.c +++ b/drivers/soc/qcom/smem_dramc.c @@ -458,7 +458,7 @@ struct dentry *smem_dram_parse(struct qcom_smem *smem, struct device *dev) return ERR_PTR(-EINVAL); } - dram = devm_kzalloc(dev, sizeof(*dram), GFP_KERNEL); + dram = devm_kzalloc_obj(dev, *dram); if (!dram) return ERR_PTR(-ENOMEM); diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c index 01b8580c9f2712..027c588ee467e7 100644 --- a/drivers/soc/qcom/smp2p.c +++ b/drivers/soc/qcom/smp2p.c @@ -627,7 +627,7 @@ static int qcom_smp2p_probe(struct platform_device *pdev) int irq; int ret; - smp2p = devm_kzalloc(&pdev->dev, sizeof(*smp2p), GFP_KERNEL); + smp2p = devm_kzalloc_obj(&pdev->dev, *smp2p); if (!smp2p) return -ENOMEM; @@ -676,7 +676,7 @@ static int qcom_smp2p_probe(struct platform_device *pdev) goto release_mbox; for_each_available_child_of_node_scoped(pdev->dev.of_node, node) { - entry = devm_kzalloc(&pdev->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(&pdev->dev, *entry); if (!entry) { ret = -ENOMEM; goto unwind_interfaces; diff --git a/drivers/soc/qcom/smsm.c b/drivers/soc/qcom/smsm.c index bb487bf6bf037f..f6b7266a5af0f7 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -509,7 +509,7 @@ static int qcom_smsm_probe(struct platform_device *pdev) u32 id; int ret; - smsm = devm_kzalloc(&pdev->dev, sizeof(*smsm), GFP_KERNEL); + smsm = devm_kzalloc_obj(&pdev->dev, *smsm); if (!smsm) return -ENOMEM; smsm->dev = &pdev->dev; @@ -519,17 +519,13 @@ static int qcom_smsm_probe(struct platform_device *pdev) if (ret) return ret; - smsm->entries = devm_kcalloc(&pdev->dev, - smsm->num_entries, - sizeof(struct smsm_entry), - GFP_KERNEL); + smsm->entries = devm_kzalloc_objs(&pdev->dev, struct smsm_entry, + smsm->num_entries); if (!smsm->entries) return -ENOMEM; - smsm->hosts = devm_kcalloc(&pdev->dev, - smsm->num_hosts, - sizeof(struct smsm_host), - GFP_KERNEL); + smsm->hosts = devm_kzalloc_objs(&pdev->dev, struct smsm_host, + smsm->num_hosts); if (!smsm->hosts) return -ENOMEM; diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c index 38efc5db7fa834..b794ae3b18f566 100644 --- a/drivers/soc/qcom/socinfo.c +++ b/drivers/soc/qcom/socinfo.c @@ -908,7 +908,7 @@ static int qcom_socinfo_probe(struct platform_device *pdev) return PTR_ERR(info); } - qs = devm_kzalloc(&pdev->dev, sizeof(*qs), GFP_KERNEL); + qs = devm_kzalloc_obj(&pdev->dev, *qs); if (!qs) return -ENOMEM; diff --git a/drivers/soc/qcom/spm.c b/drivers/soc/qcom/spm.c index f75659fff2874f..2e10ab48f17b75 100644 --- a/drivers/soc/qcom/spm.c +++ b/drivers/soc/qcom/spm.c @@ -425,7 +425,7 @@ static int spm_register_regulator(struct device *dev, struct spm_driver_data *dr if (!drv->reg_data->set_vdd) return 0; - rdesc = devm_kzalloc(dev, sizeof(*rdesc), GFP_KERNEL); + rdesc = devm_kzalloc_obj(dev, *rdesc); if (!rdesc) return -ENOMEM; @@ -511,7 +511,7 @@ static int spm_dev_probe(struct platform_device *pdev) struct spm_driver_data *drv; void __iomem *addr; - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&pdev->dev, *drv); if (!drv) return -ENOMEM; diff --git a/drivers/soc/qcom/wcnss_ctrl.c b/drivers/soc/qcom/wcnss_ctrl.c index 942e11feba65df..358e9a152a4b69 100644 --- a/drivers/soc/qcom/wcnss_ctrl.c +++ b/drivers/soc/qcom/wcnss_ctrl.c @@ -320,7 +320,7 @@ static int wcnss_ctrl_probe(struct rpmsg_device *rpdev) { struct wcnss_ctrl *wcnss; - wcnss = devm_kzalloc(&rpdev->dev, sizeof(*wcnss), GFP_KERNEL); + wcnss = devm_kzalloc_obj(&rpdev->dev, *wcnss); if (!wcnss) return -ENOMEM; diff --git a/drivers/soc/renesas/pwc-rzv2m.c b/drivers/soc/renesas/pwc-rzv2m.c index 6209168b37343d..5f336035ee736d 100644 --- a/drivers/soc/renesas/pwc-rzv2m.c +++ b/drivers/soc/renesas/pwc-rzv2m.c @@ -91,7 +91,7 @@ static int rzv2m_pwc_probe(struct platform_device *pdev) struct rzv2m_pwc_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/soc/renesas/rcar-mfis.c b/drivers/soc/renesas/rcar-mfis.c index d5bbc3077373b4..821032d141d1bc 100644 --- a/drivers/soc/renesas/rcar-mfis.c +++ b/drivers/soc/renesas/rcar-mfis.c @@ -300,12 +300,11 @@ static int mfis_mb_probe(struct mfis_priv *priv) num_chan *= 2; } - chan = devm_kcalloc(dev, num_chan, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_objs(dev, *chan, num_chan); if (!chan) return -ENOMEM; - priv->chan_privs = devm_kcalloc(dev, num_chan, sizeof(*priv->chan_privs), - GFP_KERNEL); + priv->chan_privs = devm_kzalloc_objs(dev, *priv->chan_privs, num_chan); if (!priv->chan_privs) return -ENOMEM; @@ -357,7 +356,7 @@ static int mfis_probe(struct platform_device *pdev) struct mfis_priv *priv; int ret; - priv = devm_kzalloc(dev, struct_size(priv, bank.lock, MFIS_NUM_LOCKS), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, bank.lock, MFIS_NUM_LOCKS); if (!priv) return -ENOMEM; diff --git a/drivers/soc/renesas/rz-sysc.c b/drivers/soc/renesas/rz-sysc.c index 0e92c415d4befc..987f826ef09d94 100644 --- a/drivers/soc/renesas/rz-sysc.c +++ b/drivers/soc/renesas/rz-sysc.c @@ -46,7 +46,7 @@ static int rz_sysc_soc_init(struct rz_sysc *sysc, const struct of_device_id *mat size = sizeof(soc_id); strscpy(soc_id, soc_id_start, size); - soc_dev_attr = devm_kzalloc(sysc->dev, sizeof(*soc_dev_attr), GFP_KERNEL); + soc_dev_attr = devm_kzalloc_obj(sysc->dev, *soc_dev_attr); if (!soc_dev_attr) return -ENOMEM; @@ -124,7 +124,7 @@ static int rz_sysc_probe(struct platform_device *pdev) data = match->data; - sysc = devm_kzalloc(dev, sizeof(*sysc), GFP_KERNEL); + sysc = devm_kzalloc_obj(dev, *sysc); if (!sysc) return -ENOMEM; diff --git a/drivers/soc/rockchip/io-domain.c b/drivers/soc/rockchip/io-domain.c index f94985a905c296..91fe641298b258 100644 --- a/drivers/soc/rockchip/io-domain.c +++ b/drivers/soc/rockchip/io-domain.c @@ -619,7 +619,7 @@ static int rockchip_iodomain_probe(struct platform_device *pdev) if (!np) return -ENODEV; - iod = devm_kzalloc(&pdev->dev, sizeof(*iod), GFP_KERNEL); + iod = devm_kzalloc_obj(&pdev->dev, *iod); if (!iod) return -ENOMEM; diff --git a/drivers/soc/samsung/exynos-asv.c b/drivers/soc/samsung/exynos-asv.c index 8e681f51952644..2279d7ddace6bf 100644 --- a/drivers/soc/samsung/exynos-asv.c +++ b/drivers/soc/samsung/exynos-asv.c @@ -125,7 +125,7 @@ int exynos_asv_init(struct device *dev, struct regmap *regmap) u32 product_id = 0; int ret, i; - asv = devm_kzalloc(dev, sizeof(*asv), GFP_KERNEL); + asv = devm_kzalloc_obj(dev, *asv); if (!asv) return -ENOMEM; diff --git a/drivers/soc/samsung/exynos-chipid.c b/drivers/soc/samsung/exynos-chipid.c index 506a0bcdfe30ab..ad41691cfee87b 100644 --- a/drivers/soc/samsung/exynos-chipid.c +++ b/drivers/soc/samsung/exynos-chipid.c @@ -180,7 +180,7 @@ static int exynos_chipid_probe(struct platform_device *pdev) if (ret < 0) return ret; - soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), GFP_KERNEL); + soc_dev_attr = devm_kzalloc_obj(dev, *soc_dev_attr); if (!soc_dev_attr) return -ENOMEM; diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c index 702f7d21eda7fe..b4324c4685574a 100644 --- a/drivers/soc/samsung/exynos-pmu.c +++ b/drivers/soc/samsung/exynos-pmu.c @@ -527,8 +527,7 @@ static int exynos_pmu_probe(struct platform_device *pdev) if (IS_ERR(pmu_base_addr)) return PTR_ERR(pmu_base_addr); - ctx = devm_kzalloc(&pdev->dev, sizeof(struct exynos_pmu_context), - GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, struct exynos_pmu_context); if (!ctx) return -ENOMEM; diff --git a/drivers/soc/samsung/exynos-usi.c b/drivers/soc/samsung/exynos-usi.c index 5f7bdf3bab05cc..dd05c807629cdd 100644 --- a/drivers/soc/samsung/exynos-usi.c +++ b/drivers/soc/samsung/exynos-usi.c @@ -275,7 +275,7 @@ static int exynos_usi_get_clocks(struct exynos_usi *usi) if (num == 0) return 0; - usi->clks = devm_kcalloc(dev, num, sizeof(*usi->clks), GFP_KERNEL); + usi->clks = devm_kzalloc_objs(dev, *usi->clks, num); if (!usi->clks) return -ENOMEM; @@ -292,7 +292,7 @@ static int exynos_usi_probe(struct platform_device *pdev) struct exynos_usi *usi; int ret; - usi = devm_kzalloc(dev, sizeof(*usi), GFP_KERNEL); + usi = devm_kzalloc_obj(dev, *usi); if (!usi) return -ENOMEM; diff --git a/drivers/soc/starfive/socinfo/jhb100-socinfo.c b/drivers/soc/starfive/socinfo/jhb100-socinfo.c index 0a31cae9b4f51e..38d2d2fa1871cb 100644 --- a/drivers/soc/starfive/socinfo/jhb100-socinfo.c +++ b/drivers/soc/starfive/socinfo/jhb100-socinfo.c @@ -51,7 +51,7 @@ static int jhb100_socinfo_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "failed to read revision ID\n"); - attrs = devm_kzalloc(dev, sizeof(*attrs), GFP_KERNEL); + attrs = devm_kzalloc_obj(dev, *attrs); if (!attrs) return -ENOMEM; diff --git a/drivers/soc/tegra/cbb/tegra194-cbb.c b/drivers/soc/tegra/cbb/tegra194-cbb.c index be35ec0f39de49..349db7a6186edd 100644 --- a/drivers/soc/tegra/cbb/tegra194-cbb.c +++ b/drivers/soc/tegra/cbb/tegra194-cbb.c @@ -2204,8 +2204,8 @@ static int tegra194_cbb_get_bridges(struct tegra194_cbb *cbb, struct device_node if (!cbb->bridges) { cbb->num_bridges = of_address_count(np); - cbb->bridges = devm_kcalloc(cbb->base.dev, cbb->num_bridges, - sizeof(*cbb->bridges), GFP_KERNEL); + cbb->bridges = devm_kzalloc_objs(cbb->base.dev, *cbb->bridges, + cbb->num_bridges); if (!cbb->bridges) return -ENOMEM; @@ -2254,7 +2254,7 @@ static int tegra194_cbb_probe(struct platform_device *pdev) } } - cbb = devm_kzalloc(&pdev->dev, sizeof(*cbb), GFP_KERNEL); + cbb = devm_kzalloc_obj(&pdev->dev, *cbb); if (!cbb) return -ENOMEM; diff --git a/drivers/soc/tegra/cbb/tegra234-cbb.c b/drivers/soc/tegra/cbb/tegra234-cbb.c index 785072fa4e85ec..947fdb37ab95af 100644 --- a/drivers/soc/tegra/cbb/tegra234-cbb.c +++ b/drivers/soc/tegra/cbb/tegra234-cbb.c @@ -1702,7 +1702,7 @@ static int tegra234_cbb_probe(struct platform_device *pdev) } } - cbb = devm_kzalloc(&pdev->dev, sizeof(*cbb), GFP_KERNEL); + cbb = devm_kzalloc_obj(&pdev->dev, *cbb); if (!cbb) return -ENOMEM; diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index 2c70eedf514e05..721e9596b07d03 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -1264,7 +1264,7 @@ static int tegra_powergate_of_get_clks(struct tegra_powergate *pg, if (!pg->clks) return -ENOMEM; - pg->clk_rates = kcalloc(count, sizeof(*pg->clk_rates), GFP_KERNEL); + pg->clk_rates = kzalloc_objs(*pg->clk_rates, count); if (!pg->clk_rates) { kfree(pg->clks); return -ENOMEM; @@ -1465,7 +1465,7 @@ static int tegra_pmc_core_pd_add(struct tegra_pmc *pmc, struct device_node *np) struct tegra_pmc_core_pd *pd; int err; - pd = devm_kzalloc(pmc->dev, sizeof(*pd), GFP_KERNEL); + pd = devm_kzalloc_obj(pmc->dev, *pd); if (!pd) return -ENOMEM; @@ -1979,7 +1979,7 @@ static int tegra_pmc_init(struct tegra_pmc *pmc) if (!pmc->wake_cntrl_level_map) return -ENOMEM; - pmc->wake_status = kcalloc(pmc->soc->max_wake_vectors, sizeof(u32), GFP_KERNEL); + pmc->wake_status = kzalloc_objs(u32, pmc->soc->max_wake_vectors); if (!pmc->wake_status) return -ENOMEM; @@ -2698,7 +2698,7 @@ tegra_pmc_clk_out_register(struct tegra_pmc *pmc, struct clk_init_data init = {}; struct pmc_clk *pmc_clk; - pmc_clk = devm_kzalloc(pmc->dev, sizeof(*pmc_clk), GFP_KERNEL); + pmc_clk = devm_kzalloc_obj(pmc->dev, *pmc_clk); if (!pmc_clk) return ERR_PTR(-ENOMEM); @@ -2756,7 +2756,7 @@ tegra_pmc_clk_gate_register(struct tegra_pmc *pmc, const char *name, struct clk_init_data init = {}; struct pmc_clk_gate *gate; - gate = devm_kzalloc(pmc->dev, sizeof(*gate), GFP_KERNEL); + gate = devm_kzalloc_obj(pmc->dev, *gate); if (!gate) return ERR_PTR(-ENOMEM); @@ -2789,12 +2789,12 @@ static void tegra_pmc_clock_register(struct tegra_pmc *pmc, if (!num_clks) return; - clk_data = devm_kmalloc(pmc->dev, sizeof(*clk_data), GFP_KERNEL); + clk_data = devm_kmalloc_obj(pmc->dev, *clk_data); if (!clk_data) return; - clk_data->clks = devm_kcalloc(pmc->dev, TEGRA_PMC_CLK_MAX, - sizeof(*clk_data->clks), GFP_KERNEL); + clk_data->clks = devm_kzalloc_objs(pmc->dev, *clk_data->clks, + TEGRA_PMC_CLK_MAX); if (!clk_data->clks) return; @@ -3009,7 +3009,7 @@ static int tegra_pmc_probe(struct platform_device *pdev) return -ENODEV; #endif - pmc = devm_kzalloc(&pdev->dev, sizeof(*pmc), GFP_KERNEL); + pmc = devm_kzalloc_obj(&pdev->dev, *pmc); if (!pmc) return -ENOMEM; diff --git a/drivers/soc/ti/k3-ringacc.c b/drivers/soc/ti/k3-ringacc.c index 5966db4327b133..8c5f685e10f688 100644 --- a/drivers/soc/ti/k3-ringacc.c +++ b/drivers/soc/ti/k3-ringacc.c @@ -1469,7 +1469,7 @@ struct k3_ringacc *k3_ringacc_dmarings_init(struct platform_device *pdev, void __iomem *base_rt; int i; - ringacc = devm_kzalloc(dev, sizeof(*ringacc), GFP_KERNEL); + ringacc = devm_kzalloc_obj(dev, *ringacc); if (!ringacc) return ERR_PTR(-ENOMEM); @@ -1531,7 +1531,7 @@ static int k3_ringacc_probe(struct platform_device *pdev) if (!match_data) return -ENODEV; - ringacc = devm_kzalloc(dev, sizeof(*ringacc), GFP_KERNEL); + ringacc = devm_kzalloc_obj(dev, *ringacc); if (!ringacc) return -ENOMEM; diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c index 96df3982e47bdb..8b587df224e9bc 100644 --- a/drivers/soc/ti/knav_dma.c +++ b/drivers/soc/ti/knav_dma.c @@ -566,7 +566,7 @@ static int pktdma_init_chan(struct knav_dma_device *dma, struct knav_dma_chan *chan; int ret = -EINVAL; - chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL); + chan = devm_kzalloc_obj(dev, *chan); if (!chan) return -ENOMEM; @@ -601,7 +601,7 @@ static int dma_init(struct device_node *cloud, struct device_node *dma_node) u32 timeout; u32 i; - dma = devm_kzalloc(kdev->dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(kdev->dev, *dma); if (!dma) { dev_err(kdev->dev, "could not allocate driver mem\n"); return -ENOMEM; @@ -705,8 +705,7 @@ static int knav_dma_probe(struct platform_device *pdev) if (!node) return dev_err_probe(dev, -EINVAL, "could not find device info\n"); - kdev = devm_kzalloc(dev, - sizeof(struct knav_dma_pool_device), GFP_KERNEL); + kdev = devm_kzalloc_obj(dev, struct knav_dma_pool_device); if (!kdev) return -ENOMEM; diff --git a/drivers/soc/ti/knav_qmss_acc.c b/drivers/soc/ti/knav_qmss_acc.c index 1f8b5acdd462f3..261ae82d5e7e73 100644 --- a/drivers/soc/ti/knav_qmss_acc.c +++ b/drivers/soc/ti/knav_qmss_acc.c @@ -397,8 +397,7 @@ static int knav_acc_init_queue(struct knav_range_info *range, { unsigned id = kq->id - range->queue_base; - kq->descs = devm_kcalloc(range->kdev->dev, - ACC_DESCS_MAX, sizeof(u32), GFP_KERNEL); + kq->descs = devm_kzalloc_objs(range->kdev->dev, u32, ACC_DESCS_MAX); if (!kq->descs) return -ENOMEM; @@ -544,8 +543,7 @@ int knav_init_acc_range(struct knav_device *kdev, info->list_size = list_size; mem_size = PAGE_ALIGN(list_size * 2); info->mem_size = mem_size; - range->acc = devm_kcalloc(kdev->dev, channels, sizeof(*range->acc), - GFP_KERNEL); + range->acc = devm_kzalloc_objs(kdev->dev, *range->acc, channels); if (!range->acc) return -ENOMEM; diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index 6186454dff517d..e86fed21fae077 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -217,7 +217,7 @@ static struct knav_queue *__knav_queue_open(struct knav_queue_inst *inst, unsigned id; int ret = 0; - qh = devm_kzalloc(inst->kdev->dev, sizeof(*qh), GFP_KERNEL); + qh = devm_kzalloc_obj(inst->kdev->dev, *qh); if (!qh) return ERR_PTR(-ENOMEM); @@ -765,7 +765,7 @@ void *knav_pool_create(const char *name, if (!knav_qdev->dev) return ERR_PTR(-ENODEV); - pool = devm_kzalloc(knav_qdev->dev, sizeof(*pool), GFP_KERNEL); + pool = devm_kzalloc_obj(knav_qdev->dev, *pool); if (!pool) return ERR_PTR(-ENOMEM); @@ -1020,7 +1020,7 @@ static void knav_queue_setup_region(struct knav_device *kdev, } region->dma_end = region->dma_start + size; - pool = devm_kzalloc(kdev->dev, sizeof(*pool), GFP_KERNEL); + pool = devm_kzalloc_obj(kdev->dev, *pool); if (!pool) goto fail; pool->num_desc = 0; @@ -1081,7 +1081,7 @@ static int knav_queue_setup_regions(struct knav_device *kdev, "descriptor-regions not specified\n"); for_each_child_of_node_scoped(regions, child) { - region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL); + region = devm_kzalloc_obj(dev, *region); if (!region) return -ENOMEM; @@ -1204,7 +1204,7 @@ static int knav_setup_queue_range(struct knav_device *kdev, u32 temp[2], start, end, id, index; int ret, i; - range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL); + range = devm_kzalloc_obj(dev, *range); if (!range) return -ENOMEM; @@ -1393,7 +1393,7 @@ static int knav_queue_init_qmgrs(struct knav_device *kdev, "queue manager info not specified\n"); for_each_child_of_node_scoped(qmgrs, child) { - qmgr = devm_kzalloc(dev, sizeof(*qmgr), GFP_KERNEL); + qmgr = devm_kzalloc_obj(dev, *qmgr); if (!qmgr) return -ENOMEM; @@ -1489,7 +1489,7 @@ static int knav_queue_init_pdsps(struct knav_device *kdev, struct knav_pdsp_info *pdsp; for_each_child_of_node_scoped(pdsps, child) { - pdsp = devm_kzalloc(dev, sizeof(*pdsp), GFP_KERNEL); + pdsp = devm_kzalloc_obj(dev, *pdsp); if (!pdsp) return -ENOMEM; @@ -1773,7 +1773,7 @@ static int knav_queue_probe(struct platform_device *pdev) return -ENODEV; } - knav_qdev = devm_kzalloc(dev, sizeof(struct knav_device), GFP_KERNEL); + knav_qdev = devm_kzalloc_obj(dev, struct knav_device); if (!knav_qdev) { dev_err(dev, "memory allocation failed\n"); return -ENOMEM; diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c index 0fd59c73f585d2..7a72bb4dacdb16 100644 --- a/drivers/soc/ti/pruss.c +++ b/drivers/soc/ti/pruss.c @@ -325,8 +325,7 @@ static int pruss_clk_mux_setup(struct pruss *pruss, struct clk *clk_mux, goto put_clk_mux_np; } - parent_names = devm_kcalloc(dev, sizeof(*parent_names), num_parents, - GFP_KERNEL); + parent_names = devm_kzalloc_objs(dev, *parent_names, num_parents); if (!parent_names) { ret = -ENOMEM; goto put_clk_mux_np; @@ -510,7 +509,7 @@ static int pruss_probe(struct platform_device *pdev) return ret; } - pruss = devm_kzalloc(dev, sizeof(*pruss), GFP_KERNEL); + pruss = devm_kzalloc_obj(dev, *pruss); if (!pruss) return -ENOMEM; diff --git a/drivers/soc/ti/smartreflex.c b/drivers/soc/ti/smartreflex.c index 01a214c3fa21c9..4a80499b007437 100644 --- a/drivers/soc/ti/smartreflex.c +++ b/drivers/soc/ti/smartreflex.c @@ -817,7 +817,7 @@ static int omap_sr_probe(struct platform_device *pdev) struct dentry *nvalue_dir; int i, ret = 0; - sr_info = devm_kzalloc(&pdev->dev, sizeof(struct omap_sr), GFP_KERNEL); + sr_info = devm_kzalloc_obj(&pdev->dev, struct omap_sr); if (!sr_info) return -ENOMEM; diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c index f8640cdc2a21c1..eb6074a67ba3b1 100644 --- a/drivers/soc/ti/wkup_m3_ipc.c +++ b/drivers/soc/ti/wkup_m3_ipc.c @@ -616,7 +616,7 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev) struct wkup_m3_ipc *m3_ipc; struct device_node *np = dev->of_node; - m3_ipc = devm_kzalloc(dev, sizeof(*m3_ipc), GFP_KERNEL); + m3_ipc = devm_kzalloc_obj(dev, *m3_ipc); if (!m3_ipc) return -ENOMEM; diff --git a/drivers/soc/versatile/soc-realview.c b/drivers/soc/versatile/soc-realview.c index cf91abe07d38d0..addb8eb32f0d9d 100644 --- a/drivers/soc/versatile/soc-realview.c +++ b/drivers/soc/versatile/soc-realview.c @@ -101,7 +101,7 @@ static int realview_soc_probe(struct platform_device *pdev) if (IS_ERR(syscon_regmap)) return PTR_ERR(syscon_regmap); - soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), GFP_KERNEL); + soc_dev_attr = devm_kzalloc_obj(&pdev->dev, *soc_dev_attr); if (!soc_dev_attr) return -ENOMEM; diff --git a/drivers/soc/vt8500/wmt-socinfo.c b/drivers/soc/vt8500/wmt-socinfo.c index 461f8c1ae56ee3..e514c98a796fc3 100644 --- a/drivers/soc/vt8500/wmt-socinfo.c +++ b/drivers/soc/vt8500/wmt-socinfo.c @@ -59,7 +59,7 @@ static int wmt_socinfo_probe(struct platform_device *pdev) sccid = readl(reg); - attrs = devm_kzalloc(&pdev->dev, sizeof(*attrs), GFP_KERNEL); + attrs = devm_kzalloc_obj(&pdev->dev, *attrs); if (!attrs) return -ENOMEM; diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c index 54c796afb89efd..555cb29760138b 100644 --- a/drivers/soc/xilinx/zynqmp_power.c +++ b/drivers/soc/xilinx/zynqmp_power.c @@ -303,9 +303,8 @@ static int zynqmp_pm_probe(struct platform_device *pdev) * is not available to use) or -ENODEV(Xilinx Event Manager not compiled), * then use ipi-mailbox or interrupt method. */ - zynqmp_pm_init_suspend_work = devm_kzalloc(&pdev->dev, - sizeof(struct zynqmp_pm_work_struct), - GFP_KERNEL); + zynqmp_pm_init_suspend_work = devm_kzalloc_obj(&pdev->dev, + struct zynqmp_pm_work_struct); if (!zynqmp_pm_init_suspend_work) return -ENOMEM; @@ -326,9 +325,8 @@ static int zynqmp_pm_probe(struct platform_device *pdev) else return -ENODEV; - zynqmp_pm_init_restart_work = devm_kzalloc(&pdev->dev, - sizeof(struct zynqmp_pm_work_struct), - GFP_KERNEL); + zynqmp_pm_init_restart_work = devm_kzalloc_obj(&pdev->dev, + struct zynqmp_pm_work_struct); if (!zynqmp_pm_init_restart_work) return -ENOMEM; @@ -346,7 +344,7 @@ static int zynqmp_pm_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to Register with Xilinx Event manager %d\n", ret); return ret; } else if (of_property_present(pdev->dev.of_node, "mboxes")) { - client = devm_kzalloc(&pdev->dev, sizeof(*client), GFP_KERNEL); + client = devm_kzalloc_obj(&pdev->dev, *client); if (!client) return -ENOMEM; diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index f40a3af4351f6e..c80efcadfc6c91 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -898,13 +898,12 @@ static int amd_sdw_register_dais(struct amd_sdw_manager *amd_manager) dev = amd_manager->dev; num_dais = amd_manager->num_dout_ports + amd_manager->num_din_ports; - dais = devm_kcalloc(dev, num_dais, sizeof(*dais), GFP_KERNEL); + dais = devm_kzalloc_objs(dev, *dais, num_dais); if (!dais) return -ENOMEM; - dai_runtime_array = devm_kcalloc(dev, num_dais, - sizeof(struct sdw_amd_dai_runtime *), - GFP_KERNEL); + dai_runtime_array = devm_kzalloc_objs(dev, struct sdw_amd_dai_runtime *, + num_dais); if (!dai_runtime_array) return -ENOMEM; amd_manager->dai_runtime_array = dai_runtime_array; @@ -1065,7 +1064,7 @@ static int amd_sdw_manager_probe(struct platform_device *pdev) struct amd_sdw_manager *amd_manager; int ret; - amd_manager = devm_kzalloc(dev, sizeof(struct amd_sdw_manager), GFP_KERNEL); + amd_manager = devm_kzalloc_obj(dev, struct amd_sdw_manager); if (!amd_manager) return -ENOMEM; diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c index e411008ffbd5a3..0fdbe1b4e3bf4f 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -1287,7 +1287,7 @@ static int cdns_allocate_pdi(struct sdw_cdns *cdns, if (!num) return 0; - pdi = devm_kcalloc(cdns->dev, num, sizeof(*pdi), GFP_KERNEL); + pdi = devm_kzalloc_objs(cdns->dev, *pdi, num); if (!pdi) return -ENOMEM; diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index af65214836b4d0..6ab8691ec75540 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -1031,14 +1031,14 @@ static int intel_register_dai(struct sdw_intel *sdw) /* DAIs are created based on total number of PDIs supported */ num_dai = cdns->pcm.num_pdi; - dai_runtime_array = devm_kcalloc(cdns->dev, num_dai, - sizeof(struct sdw_cdns_dai_runtime *), - GFP_KERNEL); + dai_runtime_array = devm_kzalloc_objs(cdns->dev, + struct sdw_cdns_dai_runtime *, + num_dai); if (!dai_runtime_array) return -ENOMEM; cdns->dai_runtime_array = dai_runtime_array; - dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL); + dais = devm_kzalloc_objs(cdns->dev, *dais, num_dai); if (!dais) return -ENOMEM; diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c index 642b33ab552606..43961c45ed2749 100644 --- a/drivers/soundwire/intel_ace2x.c +++ b/drivers/soundwire/intel_ace2x.c @@ -1080,14 +1080,14 @@ static int intel_register_dai(struct sdw_intel *sdw) /* DAIs are created based on total number of PDIs supported */ num_dai = cdns->pcm.num_pdi; - dai_runtime_array = devm_kcalloc(cdns->dev, num_dai, - sizeof(struct sdw_cdns_dai_runtime *), - GFP_KERNEL); + dai_runtime_array = devm_kzalloc_objs(cdns->dev, + struct sdw_cdns_dai_runtime *, + num_dai); if (!dai_runtime_array) return -ENOMEM; cdns->dai_runtime_array = dai_runtime_array; - dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL); + dais = devm_kzalloc_objs(cdns->dev, *dais, num_dai); if (!dais) return -ENOMEM; diff --git a/drivers/soundwire/intel_auxdevice.c b/drivers/soundwire/intel_auxdevice.c index 5983fbc5725a26..8bdb2bf1c64466 100644 --- a/drivers/soundwire/intel_auxdevice.c +++ b/drivers/soundwire/intel_auxdevice.c @@ -197,7 +197,7 @@ static int sdw_master_read_intel_prop(struct sdw_bus *bus) prop->quirks = SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH | SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY; - intel_prop = devm_kzalloc(bus->dev, sizeof(*intel_prop), GFP_KERNEL); + intel_prop = devm_kzalloc_obj(bus->dev, *intel_prop); if (!intel_prop) { fwnode_handle_put(link); return -ENOMEM; @@ -320,7 +320,7 @@ static int intel_link_probe(struct auxiliary_device *auxdev, struct sdw_bus *bus; int ret; - sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL); + sdw = devm_kzalloc_obj(dev, *sdw); if (!sdw) return -ENOMEM; diff --git a/drivers/soundwire/mipi_disco.c b/drivers/soundwire/mipi_disco.c index 259ad98b5b7a9a..8110a5399fd943 100644 --- a/drivers/soundwire/mipi_disco.c +++ b/drivers/soundwire/mipi_disco.c @@ -85,9 +85,8 @@ int sdw_master_read_prop(struct sdw_bus *bus) nval = fwnode_property_count_u32(link, "mipi-sdw-clock-frequencies-supported"); if (nval > 0) { prop->num_clk_freq = nval; - prop->clk_freq = devm_kcalloc(bus->dev, prop->num_clk_freq, - sizeof(*prop->clk_freq), - GFP_KERNEL); + prop->clk_freq = devm_kzalloc_objs(bus->dev, *prop->clk_freq, + prop->num_clk_freq); if (!prop->clk_freq) { fwnode_handle_put(link); return -ENOMEM; @@ -120,9 +119,8 @@ int sdw_master_read_prop(struct sdw_bus *bus) } if (nval > 0) { prop->num_clk_gears = nval; - prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears, - sizeof(*prop->clk_gears), - GFP_KERNEL); + prop->clk_gears = devm_kzalloc_objs(bus->dev, *prop->clk_gears, + prop->num_clk_gears); if (!prop->clk_gears) { fwnode_handle_put(link); return -ENOMEM; @@ -174,9 +172,8 @@ static int sdw_slave_read_dp0(struct sdw_slave *slave, if (nval > 0) { dp0->num_words = nval; - dp0->words = devm_kcalloc(&slave->dev, - dp0->num_words, sizeof(*dp0->words), - GFP_KERNEL); + dp0->words = devm_kzalloc_objs(&slave->dev, *dp0->words, + dp0->num_words); if (!dp0->words) return -ENOMEM; @@ -199,9 +196,8 @@ static int sdw_slave_read_dp0(struct sdw_slave *slave, nval = fwnode_property_count_u32(port, "mipi-sdw-lane-list"); if (nval > 0) { dp0->num_lanes = nval; - dp0->lane_list = devm_kcalloc(&slave->dev, - dp0->num_lanes, sizeof(*dp0->lane_list), - GFP_KERNEL); + dp0->lane_list = devm_kzalloc_objs(&slave->dev, *dp0->lane_list, + dp0->num_lanes); if (!dp0->lane_list) return -ENOMEM; @@ -250,10 +246,9 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave, nval = fwnode_property_count_u32(node, "mipi-sdw-port-wordlength-configs"); if (nval > 0) { dpn[i].num_words = nval; - dpn[i].words = devm_kcalloc(&slave->dev, - dpn[i].num_words, - sizeof(*dpn[i].words), - GFP_KERNEL); + dpn[i].words = devm_kzalloc_objs(&slave->dev, + *dpn[i].words, + dpn[i].num_words); if (!dpn[i].words) { fwnode_handle_put(node); return -ENOMEM; @@ -293,10 +288,9 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave, nval = fwnode_property_count_u32(node, "mipi-sdw-channel-number-list"); if (nval > 0) { dpn[i].num_channels = nval; - dpn[i].channels = devm_kcalloc(&slave->dev, - dpn[i].num_channels, - sizeof(*dpn[i].channels), - GFP_KERNEL); + dpn[i].channels = devm_kzalloc_objs(&slave->dev, + *dpn[i].channels, + dpn[i].num_channels); if (!dpn[i].channels) { fwnode_handle_put(node); return -ENOMEM; @@ -312,10 +306,9 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave, nval = fwnode_property_count_u32(node, "mipi-sdw-channel-combination-list"); if (nval > 0) { dpn[i].num_ch_combinations = nval; - dpn[i].ch_combinations = devm_kcalloc(&slave->dev, - dpn[i].num_ch_combinations, - sizeof(*dpn[i].ch_combinations), - GFP_KERNEL); + dpn[i].ch_combinations = devm_kzalloc_objs(&slave->dev, + *dpn[i].ch_combinations, + dpn[i].num_ch_combinations); if (!dpn[i].ch_combinations) { fwnode_handle_put(node); return -ENOMEM; @@ -344,9 +337,9 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave, nval = fwnode_property_count_u32(node, "mipi-sdw-lane-list"); if (nval > 0) { dpn[i].num_lanes = nval; - dpn[i].lane_list = devm_kcalloc(&slave->dev, - dpn[i].num_lanes, sizeof(*dpn[i].lane_list), - GFP_KERNEL); + dpn[i].lane_list = devm_kzalloc_objs(&slave->dev, + *dpn[i].lane_list, + dpn[i].num_lanes); if (!dpn[i].lane_list) return -ENOMEM; @@ -488,9 +481,7 @@ int sdw_slave_read_prop(struct sdw_slave *slave) if (!port) { dev_dbg(dev, "DP0 node not found!!\n"); } else { - prop->dp0_prop = devm_kzalloc(&slave->dev, - sizeof(*prop->dp0_prop), - GFP_KERNEL); + prop->dp0_prop = devm_kzalloc_obj(&slave->dev, *prop->dp0_prop); if (!prop->dp0_prop) { fwnode_handle_put(port); return -ENOMEM; @@ -508,9 +499,8 @@ int sdw_slave_read_prop(struct sdw_slave *slave) /* Allocate memory for set bits in port lists */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -519,9 +509,8 @@ int sdw_slave_read_prop(struct sdw_slave *slave) prop->source_ports, "source"); nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index f9500d387c7b49..7c080869475876 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -1464,12 +1464,12 @@ static int qcom_swrm_register_dais(struct qcom_swrm_ctrl *ctrl) struct device *dev = ctrl->dev; int i; - ctrl->sruntime = devm_kcalloc(dev, num_dais, sizeof(*ctrl->sruntime), GFP_KERNEL); + ctrl->sruntime = devm_kzalloc_objs(dev, *ctrl->sruntime, num_dais); if (!ctrl->sruntime) return -ENOMEM; /* PDM dais are only tested for now */ - dais = devm_kcalloc(dev, num_dais, sizeof(*dais), GFP_KERNEL); + dais = devm_kzalloc_objs(dev, *dais, num_dais); if (!dais) return -ENOMEM; @@ -1530,8 +1530,8 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl) ctrl->nports = ctrl->num_dout_ports + ctrl->num_din_ports; - ctrl->pconfig = devm_kcalloc(ctrl->dev, ctrl->nports + 1, - sizeof(*ctrl->pconfig), GFP_KERNEL); + ctrl->pconfig = devm_kzalloc_objs(ctrl->dev, *ctrl->pconfig, + ctrl->nports + 1); if (!ctrl->pconfig) return -ENOMEM; @@ -1624,7 +1624,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) int ret; u32 val; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/soundwire/sysfs_slave_dpn.c b/drivers/soundwire/sysfs_slave_dpn.c index d2561400da7713..d280913160a4b2 100644 --- a/drivers/soundwire/sysfs_slave_dpn.c +++ b/drivers/soundwire/sysfs_slave_dpn.c @@ -31,7 +31,7 @@ static int field##_attribute_alloc(struct device *dev, \ { \ struct dpn_attribute *dpn_attr; \ \ - dpn_attr = devm_kzalloc(dev, sizeof(*dpn_attr), GFP_KERNEL); \ + dpn_attr = devm_kzalloc_obj(dev, *dpn_attr); \ if (!dpn_attr) \ return -ENOMEM; \ dpn_attr->N = N; \ @@ -171,9 +171,8 @@ static int add_all_attributes(struct device *dev, int N, int dir) int ret; /* allocate attributes, last one is NULL */ - dpn_attrs = devm_kcalloc(dev, SDW_DPN_ATTRIBUTES + 1, - sizeof(struct attribute *), - GFP_KERNEL); + dpn_attrs = devm_kzalloc_objs(dev, struct attribute *, + SDW_DPN_ATTRIBUTES + 1); if (!dpn_attrs) return -ENOMEM; @@ -259,7 +258,7 @@ static int add_all_attributes(struct device *dev, int N, int dir) return -EINVAL; } - dpn_group = devm_kzalloc(dev, sizeof(*dpn_group), GFP_KERNEL); + dpn_group = devm_kzalloc_obj(dev, *dpn_group); if (!dpn_group) return -ENOMEM; diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index ddf89e5353c55c..d3953de255be6e 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -331,13 +331,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, else amd_set_spi_freq(amd_spi, spi->max_speed_hz); - /* Reject transfers that would overflow the FIFO window */ - if (fifo_pos + xfer->len > - AMD_SPI_FIFO_BASE + AMD_SPI_FIFO_SIZE) { - message->status = -EMSGSIZE; - goto fin_msg; - } - if (xfer->tx_buf) { buf = (u8 *)xfer->tx_buf; if (!tx_len) { @@ -346,6 +339,10 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, xfer->len--; } tx_len += xfer->len; + if (tx_len + rx_len > AMD_SPI_FIFO_SIZE) { + message->status = -EMSGSIZE; + goto fin_msg; + } /* Write data into the FIFO. */ for (i = 0; i < xfer->len; i++) @@ -355,8 +352,13 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, } /* Store no. of bytes to be received from FIFO */ - if (xfer->rx_buf) + if (xfer->rx_buf) { rx_len += xfer->len; + if (tx_len + rx_len > AMD_SPI_FIFO_SIZE) { + message->status = -EMSGSIZE; + goto fin_msg; + } + } } if (!buf) { @@ -380,12 +382,6 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi, list_for_each_entry(xfer, &message->transfers, transfer_list) if (xfer->rx_buf) { - /* Reject transfers that would overflow the FIFO window */ - if (fifo_pos + xfer->len > - AMD_SPI_FIFO_BASE + AMD_SPI_FIFO_SIZE) { - message->status = -EMSGSIZE; - goto fin_msg; - } buf = (u8 *)xfer->rx_buf; /* Read data from FIFO to receive buffer */ for (i = 0; i < xfer->len; i++) diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c index 1b00f34e9e931a..c59df9b115eed0 100644 --- a/drivers/spi/spi-amlogic-spisg.c +++ b/drivers/spi/spi-amlogic-spisg.c @@ -708,7 +708,7 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base) clk_disable_unprepare(spisg->pclk); - tbl = devm_kcalloc(dev, (DIV_NUM + 1), sizeof(*tbl), GFP_KERNEL); + tbl = devm_kzalloc_objs(dev, *tbl, (DIV_NUM + 1)); if (!tbl) return -ENOMEM; @@ -718,7 +718,7 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base) } spisg->tbl = tbl; - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + div = devm_kzalloc_obj(dev, *div); if (!div) return -ENOMEM; diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index ead5b295e680ad..9cfee409f15cb6 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -818,6 +818,8 @@ static int spi_engine_optimize_message(struct spi_message *msg) p = kzalloc_flex(*p, instructions, p_dry.length + 1); if (!p) return -ENOMEM; + /* spi_engine_program_add_cmd() counts the instructions as it adds them. */ + p->length = 0; spi_engine_compile_message(msg, false, p); diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index 73ea51c41f955e..44d96b8cf8f0c2 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -955,11 +955,11 @@ static int cqspi_versal_indirect_read_dma(struct cqspi_flash_pdata *f_pdata, writel(CQSPI_REG_VERSAL_DMA_DST_CTRL_VAL, reg_base + CQSPI_REG_VERSAL_DMA_DST_CTRL); + reinit_completion(&cqspi->transfer_complete); + writel(CQSPI_REG_INDIRECTRD_START_MASK, reg_base + CQSPI_REG_INDIRECTRD); - reinit_completion(&cqspi->transfer_complete); - if (!wait_for_completion_timeout(&cqspi->transfer_complete, msecs_to_jiffies(max_t(size_t, bytes_to_dma, 500)))) { ret = -ETIMEDOUT; diff --git a/drivers/spi/spi-cs42l43.c b/drivers/spi/spi-cs42l43.c index 46eeb44130dd5e..74eaa96ba2d615 100644 --- a/drivers/spi/spi-cs42l43.c +++ b/drivers/spi/spi-cs42l43.c @@ -385,14 +385,14 @@ static struct spi_board_info *cs42l43_create_bridge_amp(struct cs42l43_spi *priv struct spi_board_info *info; if (spkid >= 0) { - props = devm_kcalloc(priv->dev, 2, sizeof(*props), GFP_KERNEL); + props = devm_kzalloc_objs(priv->dev, *props, 2); if (!props) return NULL; *props = PROPERTY_ENTRY_U32("cirrus,speaker-id", spkid); } - swnode = devm_kmalloc(priv->dev, sizeof(*swnode), GFP_KERNEL); + swnode = devm_kmalloc_obj(priv->dev, *swnode); if (!swnode) return NULL; @@ -424,7 +424,7 @@ static int cs42l43_spi_probe(struct platform_device *pdev) int spkid = -EINVAL; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c index 9c70947c969cc0..dd703c1e56c511 100644 --- a/drivers/spi/spi-dw-mmio.c +++ b/drivers/spi/spi-dw-mmio.c @@ -103,7 +103,7 @@ static int dw_spi_mscc_init(struct platform_device *pdev, { struct dw_spi_mscc *dwsmscc; - dwsmscc = devm_kzalloc(&pdev->dev, sizeof(*dwsmscc), GFP_KERNEL); + dwsmscc = devm_kzalloc_obj(&pdev->dev, *dwsmscc); if (!dwsmscc) return -ENOMEM; @@ -187,7 +187,7 @@ static int dw_spi_mscc_sparx5_init(struct platform_device *pdev, return -EOPNOTSUPP; } - dwsmscc = devm_kzalloc(dev, sizeof(*dwsmscc), GFP_KERNEL); + dwsmscc = devm_kzalloc_obj(dev, *dwsmscc); if (!dwsmscc) return -ENOMEM; @@ -377,8 +377,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) struct dw_spi *dws; int ret; - dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio), - GFP_KERNEL); + dwsmmio = devm_kzalloc_obj(&pdev->dev, struct dw_spi_mmio); if (!dwsmmio) return -ENOMEM; diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c index 2f3bea51f1e62a..66511db8e2b7c4 100644 --- a/drivers/spi/spi-dw-pci.c +++ b/drivers/spi/spi-dw-pci.c @@ -90,7 +90,7 @@ static int dw_spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *en if (ret) return ret; - dws = devm_kzalloc(&pdev->dev, sizeof(*dws), GFP_KERNEL); + dws = devm_kzalloc_obj(&pdev->dev, *dws); if (!dws) return -ENOMEM; diff --git a/drivers/spi/spi-fsi.c b/drivers/spi/spi-fsi.c index 451cb4cfdb9c99..10867b84bf8105 100644 --- a/drivers/spi/spi-fsi.c +++ b/drivers/spi/spi-fsi.c @@ -539,7 +539,7 @@ static int fsi_spi_probe(struct fsi_device *fsi) if (rc) return -ENODEV; - bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL); + bridge = devm_kzalloc_obj(dev, *bridge); if (!bridge) return -ENOMEM; diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index f03488870d024b..ea45da28584137 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -675,7 +675,7 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) struct fsl_dspi_dma *dma; int ret; - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) return -ENOMEM; @@ -1554,7 +1554,7 @@ static int dspi_probe(struct platform_device *pdev) void __iomem *base; bool big_endian; - dspi = devm_kzalloc(&pdev->dev, sizeof(*dspi), GFP_KERNEL); + dspi = devm_kzalloc_obj(&pdev->dev, *dspi); if (!dspi) return -ENOMEM; diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c index 1f8960f1548302..9a431807eb9f3b 100644 --- a/drivers/spi/spi-fsl-lib.c +++ b/drivers/spi/spi-fsl-lib.c @@ -119,7 +119,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) const void *prop; int ret = -ENOMEM; - pinfo = devm_kzalloc(&ofdev->dev, sizeof(*pinfo), GFP_KERNEL); + pinfo = devm_kzalloc_obj(&ofdev->dev, *pinfo); if (!pinfo) return ret; diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index c32c33b27e1a54..1b18b623a6d320 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -320,9 +320,8 @@ static int spi_gpio_probe_pdata(struct platform_device *pdev, return 0; host->num_chipselect = pdata->num_chipselect; - spi_gpio->cs_gpios = devm_kcalloc(dev, host->num_chipselect, - sizeof(*spi_gpio->cs_gpios), - GFP_KERNEL); + spi_gpio->cs_gpios = devm_kzalloc_objs(dev, *spi_gpio->cs_gpios, + host->num_chipselect); if (!spi_gpio->cs_gpios) return -ENOMEM; diff --git a/drivers/spi/spi-intel.c b/drivers/spi/spi-intel.c index 7494b921a743a9..5be123b63107de 100644 --- a/drivers/spi/spi-intel.c +++ b/drivers/spi/spi-intel.c @@ -1383,13 +1383,13 @@ static int intel_spi_populate_chip(struct intel_spi *ispi) if (ret) return ret; - pdata = devm_kzalloc(ispi->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(ispi->dev, *pdata); if (!pdata) return -ENOMEM; pdata->nr_parts = 1; - pdata->parts = devm_kcalloc(ispi->dev, pdata->nr_parts, - sizeof(*pdata->parts), GFP_KERNEL); + pdata->parts = devm_kzalloc_objs(ispi->dev, *pdata->parts, + pdata->nr_parts); if (!pdata->parts) return -ENOMEM; @@ -1406,7 +1406,7 @@ static int intel_spi_populate_chip(struct intel_spi *ispi) if (ispi->host->num_chipselect < 2) return 0; - pdata = devm_kzalloc(ispi->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(ispi->dev, *pdata); if (!pdata) return -ENOMEM; @@ -1416,8 +1416,7 @@ static int intel_spi_populate_chip(struct intel_spi *ispi) return -ENOMEM; pdata->nr_parts = 1; - parts = devm_kcalloc(ispi->dev, pdata->nr_parts, sizeof(*parts), - GFP_KERNEL); + parts = devm_kzalloc_objs(ispi->dev, *parts, pdata->nr_parts); if (!parts) return -ENOMEM; diff --git a/drivers/spi/spi-iproc-qspi.c b/drivers/spi/spi-iproc-qspi.c index 5255d5124385ac..2116675ec4a331 100644 --- a/drivers/spi/spi-iproc-qspi.c +++ b/drivers/spi/spi-iproc-qspi.c @@ -95,7 +95,7 @@ static int bcm_iproc_probe(struct platform_device *pdev) struct bcm_iproc_intc *priv; struct bcm_qspi_soc_intc *soc_intc; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; soc_intc = &priv->soc_intc; diff --git a/drivers/spi/spi-kspi2.c b/drivers/spi/spi-kspi2.c index ca73ec52ce6300..0a93ecce9ad093 100644 --- a/drivers/spi/spi-kspi2.c +++ b/drivers/spi/spi-kspi2.c @@ -350,8 +350,8 @@ static int kspi2_probe(struct auxiliary_device *auxdev, kspi = spi_controller_get_devdata(host); kspi->auxdev = container_of(auxdev, struct keba_spi_auxdev, auxdev); kspi->host = host; - kspi->device = devm_kcalloc(dev, kspi->auxdev->info_size, - sizeof(*kspi->device), GFP_KERNEL); + kspi->device = devm_kzalloc_objs(dev, *kspi->device, + kspi->auxdev->info_size); if (!kspi->device) return -ENOMEM; kspi->device_size = kspi->auxdev->info_size; diff --git a/drivers/spi/spi-ljca.c b/drivers/spi/spi-ljca.c index 8fd001610f67e2..b1babd43adda19 100644 --- a/drivers/spi/spi-ljca.c +++ b/drivers/spi/spi-ljca.c @@ -109,8 +109,9 @@ static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data, if (ret < sizeof(*r_packet)) return -EIO; - if (!r_packet->len || ret < sizeof(*r_packet) + r_packet->len || - r_packet->len > len) + /* write acks carry no payload */ + if (!r_packet->len || r_packet->len > len || + (r_data && ret < sizeof(*r_packet) + r_packet->len)) return -EIO; if (r_data) diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index 9ad42dd9de7053..8f9eab24706aee 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -1118,7 +1118,7 @@ static int spi_mem_probe(struct spi_device *spi) struct spi_controller *ctlr = spi->controller; struct spi_mem *mem; - mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); + mem = devm_kzalloc_obj(&spi->dev, *mem); if (!mem) return -ENOMEM; diff --git a/drivers/spi/spi-meson-spicc.c b/drivers/spi/spi-meson-spicc.c index b1f8c823d5d014..3f8c2bc37fb109 100644 --- a/drivers/spi/spi-meson-spicc.c +++ b/drivers/spi/spi-meson-spicc.c @@ -848,7 +848,7 @@ static int meson_spicc_pow2_clk_init(struct meson_spicc_device *spicc) /* algorithm for pow2 div: rate = freq / 4 / (2 ^ N) */ - pow2_fixed_div = devm_kzalloc(dev, sizeof(*pow2_fixed_div), GFP_KERNEL); + pow2_fixed_div = devm_kzalloc_obj(dev, *pow2_fixed_div); if (!pow2_fixed_div) return -ENOMEM; @@ -914,7 +914,7 @@ static int meson_spicc_enh_clk_init(struct meson_spicc_device *spicc) /* algorithm for enh div: rate = freq / 2 / (N + 1) */ - enh_fixed_div = devm_kzalloc(dev, sizeof(*enh_fixed_div), GFP_KERNEL); + enh_fixed_div = devm_kzalloc_obj(dev, *enh_fixed_div); if (!enh_fixed_div) return -ENOMEM; @@ -938,7 +938,7 @@ static int meson_spicc_enh_clk_init(struct meson_spicc_device *spicc) if (WARN_ON(IS_ERR(clk))) return PTR_ERR(clk); - enh_div = devm_kzalloc(dev, sizeof(*enh_div), GFP_KERNEL); + enh_div = devm_kzalloc_obj(dev, *enh_div); if (!enh_div) return -ENOMEM; @@ -958,7 +958,7 @@ static int meson_spicc_enh_clk_init(struct meson_spicc_device *spicc) if (WARN_ON(IS_ERR(clk))) return PTR_ERR(clk); - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + mux = devm_kzalloc_obj(dev, *mux); if (!mux) return -ENOMEM; diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index b845a599f7c6cd..8b4deef91fa379 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -1221,8 +1221,7 @@ static int mtk_spi_probe(struct platform_device *pdev) return dev_err_probe(dev, -EINVAL, "No 'mediatek,pad-select' property\n"); - mdata->pad_sel = devm_kmalloc_array(dev, mdata->pad_num, - sizeof(u32), GFP_KERNEL); + mdata->pad_sel = devm_kmalloc_objs(dev, u32, mdata->pad_num); if (!mdata->pad_sel) return -ENOMEM; diff --git a/drivers/spi/spi-offload-trigger-pwm.c b/drivers/spi/spi-offload-trigger-pwm.c index 0eff14328a6b67..e0e1abf585381c 100644 --- a/drivers/spi/spi-offload-trigger-pwm.c +++ b/drivers/spi/spi-offload-trigger-pwm.c @@ -125,7 +125,7 @@ static int spi_offload_trigger_pwm_probe(struct platform_device *pdev) struct pwm_state state; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/drivers/spi/spi-offload.c b/drivers/spi/spi-offload.c index a446927a51d36e..8fd5ea50945456 100644 --- a/drivers/spi/spi-offload.c +++ b/drivers/spi/spi-offload.c @@ -68,7 +68,7 @@ struct spi_offload *devm_spi_offload_alloc(struct device *dev, struct spi_offload *offload; void *priv; - offload = devm_kzalloc(dev, sizeof(*offload), GFP_KERNEL); + offload = devm_kzalloc_obj(dev, *offload); if (!offload) return ERR_PTR(-ENOMEM); diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index e46b1d9c8cd085..73b6c29cae1b1f 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -1635,9 +1635,9 @@ static int omap2_mcspi_probe(struct platform_device *pdev) INIT_LIST_HEAD(&mcspi->ctx.cs); - mcspi->dma_channels = devm_kcalloc(&pdev->dev, ctlr->num_chipselect, - sizeof(struct omap2_mcspi_dma), - GFP_KERNEL); + mcspi->dma_channels = devm_kzalloc_objs(&pdev->dev, + struct omap2_mcspi_dma, + ctlr->num_chipselect); if (mcspi->dma_channels == NULL) return -ENOMEM; diff --git a/drivers/spi/spi-pci1xxxx.c b/drivers/spi/spi-pci1xxxx.c index c50e6841de52bc..e00b59ed823ab2 100644 --- a/drivers/spi/spi-pci1xxxx.c +++ b/drivers/spi/spi-pci1xxxx.c @@ -886,9 +886,7 @@ static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id * else only_sec_inst = 0; - spi_bus = devm_kzalloc(&pdev->dev, - struct_size(spi_bus, spi_int, hw_inst_cnt), - GFP_KERNEL); + spi_bus = devm_kzalloc_flex(&pdev->dev, *spi_bus, spi_int, hw_inst_cnt); if (!spi_bus) return -ENOMEM; @@ -897,9 +895,8 @@ static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id * pci_set_master(pdev); for (iter = 0; iter < hw_inst_cnt; iter++) { - spi_bus->spi_int[iter] = devm_kzalloc(&pdev->dev, - sizeof(struct pci1xxxx_spi_internal), - GFP_KERNEL); + spi_bus->spi_int[iter] = devm_kzalloc_obj(&pdev->dev, + struct pci1xxxx_spi_internal); if (!spi_bus->spi_int[iter]) return -ENOMEM; spi_sub_ptr = spi_bus->spi_int[iter]; diff --git a/drivers/spi/spi-pic32-sqi.c b/drivers/spi/spi-pic32-sqi.c index 5d3921e29461ca..35f0c60a31d644 100644 --- a/drivers/spi/spi-pic32-sqi.c +++ b/drivers/spi/spi-pic32-sqi.c @@ -297,7 +297,7 @@ static int pic32_sqi_one_transfer(struct pic32_sqi *sqi, /* get ring descriptor */ rdesc = ring_desc_get(sqi); if (!rdesc) - break; + return -ENOMEM; bd = rdesc->bd; @@ -387,6 +387,7 @@ static int pic32_sqi_one_message(struct spi_controller *host, ret = pic32_sqi_one_transfer(sqi, msg, xfer); if (ret) { dev_err(&spi->dev, "xfer %p err\n", xfer); + msg->status = ret; goto xfer_out; } } diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 3ff30486b2892f..f52130465abd8c 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -1839,7 +1839,7 @@ pl022_platform_data_dt_get(struct device *dev) return NULL; } - pd = devm_kzalloc(dev, sizeof(struct pl022_ssp_controller), GFP_KERNEL); + pd = devm_kzalloc_obj(dev, struct pl022_ssp_controller); if (!pd) return NULL; diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c index cae77ac1852061..77dfdb9139c83a 100644 --- a/drivers/spi/spi-pxa2xx-pci.c +++ b/drivers/spi/spi-pxa2xx-pci.c @@ -273,7 +273,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, if (ret) return ret; - pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&dev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/spi/spi-pxa2xx-platform.c b/drivers/spi/spi-pxa2xx-platform.c index 849a14cd0343c4..c8d7b235c35420 100644 --- a/drivers/spi/spi-pxa2xx-platform.c +++ b/drivers/spi/spi-pxa2xx-platform.c @@ -106,7 +106,7 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev) if (!(type > SSP_UNDEFINED && type < SSP_MAX)) return ERR_PTR(-EINVAL); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); diff --git a/drivers/spi/spi-qcom-qspi.c b/drivers/spi/spi-qcom-qspi.c index e5b7755ae4f95c..7c92395721ede5 100644 --- a/drivers/spi/spi-qcom-qspi.c +++ b/drivers/spi/spi-qcom-qspi.c @@ -721,8 +721,7 @@ static int qcom_qspi_probe(struct platform_device *pdev) if (IS_ERR(ctrl->base)) return PTR_ERR(ctrl->base); - ctrl->clks = devm_kcalloc(dev, QSPI_NUM_CLKS, - sizeof(*ctrl->clks), GFP_KERNEL); + ctrl->clks = devm_kzalloc_objs(dev, *ctrl->clks, QSPI_NUM_CLKS); if (!ctrl->clks) return -ENOMEM; diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c index c90c2001ee8df2..b03e2e4f0f0bc2 100644 --- a/drivers/spi/spi-qpic-snand.c +++ b/drivers/spi/spi-qpic-snand.c @@ -1581,7 +1581,7 @@ static int qcom_spi_probe(struct platform_device *pdev) struct resource *res; int ret; - qspi = devm_kzalloc(dev, sizeof(*qspi), GFP_KERNEL); + qspi = devm_kzalloc_obj(dev, *qspi); if (!qspi) return -ENOMEM; diff --git a/drivers/spi/spi-rtk-nor.c b/drivers/spi/spi-rtk-nor.c index 75856c31d2e679..55ea7c37185434 100644 --- a/drivers/spi/spi-rtk-nor.c +++ b/drivers/spi/spi-rtk-nor.c @@ -357,6 +357,18 @@ static bool rtk_spi_supports_op(struct spi_mem *mem, return spi_mem_default_supports_op(mem, op); } +static int rtk_spi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) +{ + /* + * A write through exec_op is a single access to the data window, + * which programs one byte. Let the caller split longer writes. + */ + if (op->data.dir == SPI_MEM_DATA_OUT && op->addr.nbytes) + op->data.nbytes = min(op->data.nbytes, 1U); + + return 0; +} + static int rtk_spi_dirmap_create(struct spi_mem_dirmap_desc *desc) { const struct spi_mem_op *op = desc->info.op_tmpl; @@ -449,6 +461,7 @@ static const struct spi_controller_mem_ops rtk_spi_mem_ops = { .dirmap_create = rtk_spi_dirmap_create, .dirmap_read = rtk_spi_dirmap_read, .dirmap_write = rtk_spi_dirmap_write, + .adjust_op_size = rtk_spi_adjust_op_size, }; static int rtk_spi_probe(struct platform_device *pdev) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 58e306cc730fcc..79c278b3c82982 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1161,7 +1161,7 @@ static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev) struct s3c64xx_spi_info *sci; u32 temp; - sci = devm_kzalloc(dev, sizeof(*sci), GFP_KERNEL); + sci = devm_kzalloc_obj(dev, *sci); if (!sci) return ERR_PTR(-ENOMEM); diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 89fbdde46cfe9a..8e3f070361375b 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c @@ -1029,7 +1029,7 @@ static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) struct device_node *np = dev->of_node; u32 num_cs = 1; - info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, struct sh_msiof_spi_info); if (!info) return NULL; diff --git a/drivers/spi/spi-slave-system-control.c b/drivers/spi/spi-slave-system-control.c index 8f5c32b61a5b4a..da39eb5a81a49a 100644 --- a/drivers/spi/spi-slave-system-control.c +++ b/drivers/spi/spi-slave-system-control.c @@ -115,7 +115,7 @@ static int spi_slave_system_control_probe(struct spi_device *spi) struct spi_slave_system_control_priv *priv; int ret; - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/spi/spi-slave-time.c b/drivers/spi/spi-slave-time.c index 8bb3070e4b8006..c64bf922296072 100644 --- a/drivers/spi/spi-slave-time.c +++ b/drivers/spi/spi-slave-time.c @@ -89,7 +89,7 @@ static int spi_slave_time_probe(struct spi_device *spi) struct spi_slave_time_priv *priv; int ret; - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-quad.c index d8cca3aa276b29..87c0e80f055130 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -237,6 +237,17 @@ struct tegra_qspi { bool is_packed; bool use_dma; + /* + * Set while a streaming mapping created by + * tegra_qspi_dma_map_xfer() is outstanding, together with the + * length that was handed to dma_map_single(). is_curr_dma_xfer + * only records that the last armed chunk took the DMA path, + * which is not the same thing: a chunk whose mapping failed + * leaves the DMA path flagged with nothing mapped. + */ + bool is_dma_mapped; + unsigned int dma_map_len; + u32 command1_reg; u32 dma_control_reg; u32 def_command1_reg; @@ -606,24 +617,32 @@ static int tegra_qspi_dma_map_xfer(struct tegra_qspi *tqspi, struct spi_transfer if (t->rx_buf) { t->rx_dma = dma_map_single(tqspi->rx_dma_dev, (void *)rx_buf, len, DMA_FROM_DEVICE); if (dma_mapping_error(tqspi->rx_dma_dev, t->rx_dma)) { - dma_unmap_single(tqspi->tx_dma_dev, t->tx_dma, len, DMA_TO_DEVICE); + if (t->tx_buf) + dma_unmap_single(tqspi->tx_dma_dev, t->tx_dma, + len, DMA_TO_DEVICE); return -ENOMEM; } } + tqspi->dma_map_len = len; + tqspi->is_dma_mapped = true; + return 0; } static void tegra_qspi_dma_unmap_xfer(struct tegra_qspi *tqspi, struct spi_transfer *t) { - unsigned int len; - - len = DIV_ROUND_UP(tqspi->curr_dma_words * tqspi->bytes_per_word, 4) * 4; + if (!tqspi->is_dma_mapped) + return; if (t->tx_buf) - dma_unmap_single(tqspi->tx_dma_dev, t->tx_dma, len, DMA_TO_DEVICE); + dma_unmap_single(tqspi->tx_dma_dev, t->tx_dma, + tqspi->dma_map_len, DMA_TO_DEVICE); if (t->rx_buf) - dma_unmap_single(tqspi->rx_dma_dev, t->rx_dma, len, DMA_FROM_DEVICE); + dma_unmap_single(tqspi->rx_dma_dev, t->rx_dma, + tqspi->dma_map_len, DMA_FROM_DEVICE); + + tqspi->is_dma_mapped = false; } static int tegra_qspi_start_dma_based_transfer(struct tegra_qspi *tqspi, struct spi_transfer *t) @@ -1032,7 +1051,7 @@ static struct tegra_qspi_client_data *tegra_qspi_parse_cdata_dt(struct spi_devic struct tegra_qspi_client_data *cdata; struct tegra_qspi *tqspi = spi_controller_get_devdata(spi->controller); - cdata = devm_kzalloc(tqspi->dev, sizeof(*cdata), GFP_KERNEL); + cdata = devm_kzalloc_obj(tqspi->dev, *cdata); if (!cdata) return NULL; @@ -1260,8 +1279,17 @@ static int tegra_qspi_handle_timeout(struct tegra_qspi *tqspi) * loaded the cache but before we masked). */ refreshed = smp_load_acquire(&tqspi->trans_status); - if (refreshed) + if (refreshed) { status = refreshed; + /* + * The drain observed a real ISR completion. Prefer the + * ISR-published status_reg / tx_status / rx_status over + * the pre-drain lost-IRQ snapshot, which may have been + * taken after the ISR W1C-ed the hardware error bits and + * therefore holds cleared values. + */ + lost_irq_snapshot = false; + } if (!(status & QSPI_RDY)) { retval = -ETIMEDOUT; @@ -1479,10 +1507,12 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi, dev_err(tqspi->dev, "transfer timeout\n"); /* Abort transfer by resetting pio/dma bit */ - if (tqspi->is_curr_dma_xfer) + if (tqspi->is_curr_dma_xfer) { tegra_qspi_dma_stop(tqspi); - else + tegra_qspi_dma_unmap_xfer(tqspi, xfer); + } else { tegra_qspi_pio_stop(tqspi); + } /* Reset controller if timeout happens */ tegra_qspi_reset(tqspi); @@ -1596,8 +1626,10 @@ static int tegra_qspi_non_combined_seq_xfer(struct tegra_qspi *tqspi, WARN_ON(1); dev_err(tqspi->dev, "transfer timeout\n"); - if (tqspi->is_curr_dma_xfer) + if (tqspi->is_curr_dma_xfer) { tegra_qspi_dma_stop(tqspi); + tegra_qspi_dma_unmap_xfer(tqspi, xfer); + } tegra_qspi_handle_error(tqspi); ret = -EIO; diff --git a/drivers/spi/spi-virtio.c b/drivers/spi/spi-virtio.c index 26f9711c99b39a..2eeb79ff5aa261 100644 --- a/drivers/spi/spi-virtio.c +++ b/drivers/spi/spi-virtio.c @@ -315,10 +315,8 @@ static int virtio_spi_find_vqs(struct virtio_spi_priv *priv) } /* Function must not be called before virtio_spi_find_vqs() has been run */ -static void virtio_spi_del_vq(void *data) +static void virtio_spi_del_vq(struct virtio_device *vdev) { - struct virtio_device *vdev = data; - virtio_reset_device(vdev); vdev->config->del_vqs(vdev); } @@ -347,21 +345,26 @@ static int virtio_spi_probe(struct virtio_device *vdev) if (ret) return dev_err_probe(&vdev->dev, ret, "Cannot setup virtqueues\n"); - /* Register cleanup for virtqueues using devm */ - ret = devm_add_action_or_reset(&vdev->dev, virtio_spi_del_vq, vdev); - if (ret) - return dev_err_probe(&vdev->dev, ret, "Cannot register virtqueue cleanup\n"); - virtio_device_ready(vdev); - /* Use devm version to register controller */ - ret = devm_spi_register_controller(&vdev->dev, ctrl); - if (ret) + ret = spi_register_controller(ctrl); + if (ret) { + virtio_spi_del_vq(vdev); return dev_err_probe(&vdev->dev, ret, "Cannot register controller\n"); + } return 0; } +static void virtio_spi_remove(struct virtio_device *vdev) +{ + struct spi_controller *ctrl = dev_get_drvdata(&vdev->dev); + + spi_unregister_controller(ctrl); + + virtio_spi_del_vq(vdev); +} + static int virtio_spi_freeze(struct device *dev) { struct spi_controller *ctrl = dev_get_drvdata(dev); @@ -415,6 +418,7 @@ static struct virtio_driver virtio_spi_driver = { }, .id_table = virtio_spi_id_table, .probe = virtio_spi_probe, + .remove = virtio_spi_remove, }; module_virtio_driver(virtio_spi_driver); diff --git a/drivers/spi/spi-xlp.c b/drivers/spi/spi-xlp.c index d014955e6d4b38..26764b031fa590 100644 --- a/drivers/spi/spi-xlp.c +++ b/drivers/spi/spi-xlp.c @@ -372,7 +372,7 @@ static int xlp_spi_probe(struct platform_device *pdev) struct clk *clk; int irq, err; - xspi = devm_kzalloc(&pdev->dev, sizeof(*xspi), GFP_KERNEL); + xspi = devm_kzalloc_obj(&pdev->dev, *xspi); if (!xspi) return -ENOMEM; diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 40cda0037ea5a6..8a06fb4e309a96 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1349,8 +1349,24 @@ static int spi_map_buf_attrs(struct spi_controller *ctlr, struct device *dev, int i, ret; if (vmalloced_buf || kmap_buf) { - desc_len = min_t(unsigned long, max_seg_size, PAGE_SIZE); - sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len); + size_t off = offset_in_page(buf); + size_t first = min_t(size_t, len, PAGE_SIZE - off); + size_t rest; + + desc_len = min_t(size_t, max_seg_size, PAGE_SIZE); + /* + * The buffer is first split at page boundaries, then every + * piece is split into desc_len chunks. Sizing the table with + * DIV_ROUND_UP(len + off, desc_len) does not model that and + * leaves zero-length entries whenever a page boundary does + * not coincide with a chunk boundary (which trips + * BUG_ON(!nslots) in swiotlb on 64K pages). + */ + sgs = DIV_ROUND_UP(first, desc_len); + rest = len - first; + sgs += (rest / PAGE_SIZE) * DIV_ROUND_UP(PAGE_SIZE, desc_len); + if (rest % PAGE_SIZE) + sgs += DIV_ROUND_UP(rest % PAGE_SIZE, desc_len); } else if (virt_addr_valid(buf)) { desc_len = min_t(size_t, max_seg_size, ctlr->max_dma_len); sgs = DIV_ROUND_UP(len, desc_len); @@ -2995,7 +3011,6 @@ struct acpi_spi_lookup { acpi_handle device_handle; u32 max_speed_hz; u32 mode; - int irq; u8 bits_per_word; u8 chip_select; int n; @@ -3138,17 +3153,25 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) if (sb->device_polarity == ACPI_SPI_ACTIVE_HIGH) lookup->mode |= SPI_CS_HIGH; } - } else if (lookup->irq < 0) { - struct resource r; - - if (acpi_dev_resource_interrupt(ares, 0, &r)) - lookup->irq = r.start; } /* Always tell the ACPI core to skip this resource */ return 1; } +static int acpi_spi_add_irq_resource(struct acpi_resource *ares, void *data) +{ + int *irq = data; + struct resource r; + + if (*irq < 0 && ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS && + acpi_dev_resource_interrupt(ares, 0, &r)) + *irq = r.start; + + /* Always tell the ACPI core to skip this resource */ + return 1; +} + /** * acpi_spi_device_alloc - Allocate a spi device, and fill it in with ACPI information * @ctlr: controller to which the spi device belongs @@ -3173,6 +3196,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, struct list_head resource_list; struct acpi_spi_lookup lookup = {}; struct spi_device *spi; + int irq = -1; int ret; if (!ctlr && index == -1) @@ -3180,7 +3204,6 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, lookup.ctlr = ctlr; lookup.device_handle = acpi_device_handle(adev); - lookup.irq = -1; lookup.index = index; lookup.n = 0; @@ -3203,6 +3226,19 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, if (!lookup.max_speed_hz) return ERR_PTR(-ENODEV); + /* + * Only look up the IRQ once we know this is an SPI device for us. + * Parsing an interrupt resource maps its GSI, which must not be done + * for every unrelated ACPI device walked during enumeration. + */ + INIT_LIST_HEAD(&resource_list); + ret = acpi_dev_get_resources(adev, &resource_list, + acpi_spi_add_irq_resource, &irq); + if (ret < 0) + return ERR_PTR(ret); + + acpi_dev_free_resource_list(&resource_list); + spi = spi_alloc_device(lookup.ctlr); if (!spi) { dev_err(&lookup.ctlr->dev, "failed to allocate SPI device for %s\n", @@ -3215,7 +3251,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, ACPI_COMPANION_SET(&spi->dev, adev); spi->max_speed_hz = lookup.max_speed_hz; spi->mode |= lookup.mode; - spi->irq = lookup.irq; + spi->irq = irq; spi->bits_per_word = lookup.bits_per_word; /* * By default spi->chip_select[0] will hold the physical CS number, @@ -3551,8 +3587,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect); - cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs), - GFP_KERNEL); + cs = devm_kzalloc_objs(dev, *cs, ctlr->num_chipselect); if (!cs) return -ENOMEM; ctlr->cs_gpiods = cs; diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c index 833c2b30d09f0a..4d5c5f2b9543d9 100644 --- a/drivers/spmi/spmi-mtk-pmif.c +++ b/drivers/spmi/spmi-mtk-pmif.c @@ -799,7 +799,7 @@ static int mtk_spmi_probe(struct platform_device *pdev) u8 cur_bus = 0; int ret; - arb = devm_kzalloc(&pdev->dev, sizeof(*arb), GFP_KERNEL); + arb = devm_kzalloc_obj(&pdev->dev, *arb); if (!arb) return -ENOMEM; diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 402ffeaff8e2b8..a7293fbec729f2 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -1097,8 +1097,8 @@ static int pmic_arb_init_apid_v1(struct spmi_pmic_arb_bus *bus, int index) return -EINVAL; } - mapping_table = devm_kcalloc(&bus->spmic->dev, pmic_arb->max_periphs, - sizeof(*mapping_table), GFP_KERNEL); + mapping_table = devm_kzalloc_objs(&bus->spmic->dev, *mapping_table, + pmic_arb->max_periphs); if (!mapping_table) return -ENOMEM; @@ -1965,15 +1965,13 @@ static int spmi_pmic_arb_bus_init(struct platform_device *pdev, raw_spin_lock_init(&bus->lock); - bus->ppid_to_apid = devm_kcalloc(dev, PMIC_ARB_MAX_PPID, - sizeof(*bus->ppid_to_apid), - GFP_KERNEL); + bus->ppid_to_apid = devm_kzalloc_objs(dev, *bus->ppid_to_apid, + PMIC_ARB_MAX_PPID); if (!bus->ppid_to_apid) return -ENOMEM; - bus->apid_data = devm_kcalloc(dev, pmic_arb->max_periphs, - sizeof(*bus->apid_data), - GFP_KERNEL); + bus->apid_data = devm_kzalloc_objs(dev, *bus->apid_data, + pmic_arb->max_periphs); if (!bus->apid_data) return -ENOMEM; @@ -2085,7 +2083,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) u32 channel, ee, hw_ver; int err; - pmic_arb = devm_kzalloc(dev, sizeof(*pmic_arb), GFP_KERNEL); + pmic_arb = devm_kzalloc_obj(dev, *pmic_arb); if (!pmic_arb) return -ENOMEM; diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c index 9c7316b5685fdd..5bd56b78c56137 100644 --- a/drivers/ssb/b43_pci_bridge.c +++ b/drivers/ssb/b43_pci_bridge.c @@ -5,7 +5,7 @@ * because of its small size we include it in the SSB core * instead of creating a standalone module. * - * Copyright 2007 Michael Buesch + * Copyright 2007 Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/bridge_pcmcia_80211.c b/drivers/ssb/bridge_pcmcia_80211.c index 689ff069ff376d..60898ba1e0c2d4 100644 --- a/drivers/ssb/bridge_pcmcia_80211.c +++ b/drivers/ssb/bridge_pcmcia_80211.c @@ -1,7 +1,7 @@ /* * Broadcom 43xx PCMCIA-SSB bridge module * - * Copyright (c) 2007 Michael Buesch + * Copyright (c) 2007 Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/driver_chipcommon.c b/drivers/ssb/driver_chipcommon.c index a8d2525e7af9e8..f51ee760e1fa38 100644 --- a/drivers/ssb/driver_chipcommon.c +++ b/drivers/ssb/driver_chipcommon.c @@ -3,7 +3,7 @@ * Broadcom ChipCommon core driver * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * Copyright 2012, Hauke Mehrtens * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/ssb/driver_chipcommon_pmu.c b/drivers/ssb/driver_chipcommon_pmu.c index 888069e1065932..c93141bf93e3f3 100644 --- a/drivers/ssb/driver_chipcommon_pmu.c +++ b/drivers/ssb/driver_chipcommon_pmu.c @@ -2,7 +2,7 @@ * Sonics Silicon Backplane * Broadcom ChipCommon Power Management Unit driver * - * Copyright 2009, Michael Buesch + * Copyright 2009, Michael Buesch * Copyright 2007, Broadcom Corporation * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/ssb/driver_extif.c b/drivers/ssb/driver_extif.c index bc275968fcc6d0..7fe777938e8897 100644 --- a/drivers/ssb/driver_extif.c +++ b/drivers/ssb/driver_extif.c @@ -3,7 +3,7 @@ * Broadcom EXTIF core driver * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * Copyright 2006, 2007, Felix Fietkau * Copyright 2007, Aurelien Jarno * diff --git a/drivers/ssb/driver_gige.c b/drivers/ssb/driver_gige.c index 0aca0711807b29..822ea364397d18 100644 --- a/drivers/ssb/driver_gige.c +++ b/drivers/ssb/driver_gige.c @@ -3,7 +3,7 @@ * Broadcom Gigabit Ethernet core driver * * Copyright 2008, Broadcom Corporation - * Copyright 2008, Michael Buesch + * Copyright 2008, Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/driver_mipscore.c b/drivers/ssb/driver_mipscore.c index 354486b7ed3a71..7afd9a421f7218 100644 --- a/drivers/ssb/driver_mipscore.c +++ b/drivers/ssb/driver_mipscore.c @@ -3,7 +3,7 @@ * Broadcom MIPS core driver * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/driver_pcicore.c b/drivers/ssb/driver_pcicore.c index d11b4242b6d2ee..8a9f930b77c300 100644 --- a/drivers/ssb/driver_pcicore.c +++ b/drivers/ssb/driver_pcicore.c @@ -3,7 +3,7 @@ * Broadcom PCI-core driver * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/embedded.c b/drivers/ssb/embedded.c index 8254ed25e0637a..2a72102d6d7acd 100644 --- a/drivers/ssb/embedded.c +++ b/drivers/ssb/embedded.c @@ -3,7 +3,7 @@ * Embedded systems support code * * Copyright 2005-2008, Broadcom Corporation - * Copyright 2006-2008, Michael Buesch + * Copyright 2006-2008, Michael Buesch * Copyright 2012, Hauke Mehrtens * * Licensed under the GNU/GPL. See COPYING for details. diff --git a/drivers/ssb/host_soc.c b/drivers/ssb/host_soc.c index 3b438480515cb7..fc4a9b0202678b 100644 --- a/drivers/ssb/host_soc.c +++ b/drivers/ssb/host_soc.c @@ -3,7 +3,7 @@ * Subsystem core * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c index b2d339eb57d53e..6aa3d73e185d0f 100644 --- a/drivers/ssb/main.c +++ b/drivers/ssb/main.c @@ -3,7 +3,7 @@ * Subsystem core * * Copyright 2005, Broadcom Corporation - * Copyright 2006, 2007, Michael Buesch + * Copyright 2006, 2007, Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c index 493bebbba521cb..0e5b34e5be2835 100644 --- a/drivers/ssb/pci.c +++ b/drivers/ssb/pci.c @@ -1,7 +1,7 @@ /* * Sonics Silicon Backplane PCI-Hostbus related functions. * - * Copyright (C) 2005-2006 Michael Buesch + * Copyright (C) 2005-2006 Michael Buesch * Copyright (C) 2005 Martin Langer * Copyright (C) 2005 Stefano Brivio * Copyright (C) 2005 Danny van Dyk @@ -882,7 +882,7 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus, } pr_debug("SPROM offset is 0x%x\n", bus->sprom_offset); - buf = kcalloc(SSB_SPROMSIZE_WORDS_R123, sizeof(u16), GFP_KERNEL); + buf = kzalloc_objs(u16, SSB_SPROMSIZE_WORDS_R123); if (!buf) return -ENOMEM; bus->sprom_size = SSB_SPROMSIZE_WORDS_R123; @@ -891,8 +891,7 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus, if (err) { /* try for a 440 byte SPROM - revision 4 and higher */ kfree(buf); - buf = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16), - GFP_KERNEL); + buf = kzalloc_objs(u16, SSB_SPROMSIZE_WORDS_R4); if (!buf) return -ENOMEM; bus->sprom_size = SSB_SPROMSIZE_WORDS_R4; diff --git a/drivers/ssb/pcihost_wrapper.c b/drivers/ssb/pcihost_wrapper.c index 5b6b5e0e4433e2..ae8cc9dce650a8 100644 --- a/drivers/ssb/pcihost_wrapper.c +++ b/drivers/ssb/pcihost_wrapper.c @@ -6,7 +6,7 @@ * Copyright (c) 2005 Stefano Brivio * Copyright (c) 2005 Danny van Dyk * Copyright (c) 2005 Andreas Jaggi - * Copyright (c) 2005-2007 Michael Buesch + * Copyright (c) 2005-2007 Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/pcmcia.c b/drivers/ssb/pcmcia.c index 45502098e0c785..e244819327d485 100644 --- a/drivers/ssb/pcmcia.c +++ b/drivers/ssb/pcmcia.c @@ -3,7 +3,7 @@ * PCMCIA-Hostbus related functions * * Copyright 2006 Johannes Berg - * Copyright 2007-2008 Michael Buesch + * Copyright 2007-2008 Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. */ diff --git a/drivers/ssb/scan.c b/drivers/ssb/scan.c index 4161e5d1f276e1..8c0ec41e5f61e2 100644 --- a/drivers/ssb/scan.c +++ b/drivers/ssb/scan.c @@ -2,7 +2,7 @@ * Sonics Silicon Backplane * Bus scanning * - * Copyright (C) 2005-2007 Michael Buesch + * Copyright (C) 2005-2007 Michael Buesch * Copyright (C) 2005 Martin Langer * Copyright (C) 2005 Stefano Brivio * Copyright (C) 2005 Danny van Dyk diff --git a/drivers/ssb/sdio.c b/drivers/ssb/sdio.c index 66c5c2169704b8..8b6745edc70455 100644 --- a/drivers/ssb/sdio.c +++ b/drivers/ssb/sdio.c @@ -6,7 +6,7 @@ * * Based on drivers/ssb/pcmcia.c * Copyright 2006 Johannes Berg - * Copyright 2007-2008 Michael Buesch + * Copyright 2007-2008 Michael Buesch * * Licensed under the GNU/GPL. See COPYING for details. * diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c index 7cd55312786124..33f728718c67b4 100644 --- a/drivers/ssb/sprom.c +++ b/drivers/ssb/sprom.c @@ -2,7 +2,7 @@ * Sonics Silicon Backplane * Common SPROM support routines * - * Copyright (C) 2005-2008 Michael Buesch + * Copyright (C) 2005-2008 Michael Buesch * Copyright (C) 2005 Martin Langer * Copyright (C) 2005 Stefano Brivio * Copyright (C) 2005 Danny van Dyk @@ -72,7 +72,7 @@ ssize_t ssb_attr_sprom_show(struct ssb_bus *bus, char *buf, ssize_t count = 0; size_t sprom_size_words = bus->sprom_size; - sprom = kcalloc(sprom_size_words, sizeof(u16), GFP_KERNEL); + sprom = kzalloc_objs(u16, sprom_size_words); if (!sprom) goto out; @@ -106,7 +106,7 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, size_t sprom_size_words = bus->sprom_size; struct ssb_freeze_context freeze; - sprom = kcalloc(bus->sprom_size, sizeof(u16), GFP_KERNEL); + sprom = kzalloc_objs(u16, bus->sprom_size); if (!sprom) goto out; err = hex2sprom(sprom, buf, count, sprom_size_words); diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c index 7bb35e11d1dd39..233d2b15393440 100644 --- a/drivers/staging/axis-fifo/axis-fifo.c +++ b/drivers/staging/axis-fifo/axis-fifo.c @@ -434,7 +434,7 @@ static int axis_fifo_probe(struct platform_device *pdev) int rc = 0; /* error return value */ int irq; - fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); + fifo = devm_kzalloc_obj(dev, *fifo); if (!fifo) return -ENOMEM; diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index 7925d974de8017..c69ba12d43b099 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -564,7 +564,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, height = display->height; } - fbdefio = devm_kzalloc(dev, sizeof(struct fb_deferred_io), GFP_KERNEL); + fbdefio = devm_kzalloc_obj(dev, struct fb_deferred_io); if (!fbdefio) return NULL; @@ -573,11 +573,8 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, return NULL; if (display->gamma_num && display->gamma_len) { - gamma_curves = devm_kcalloc(dev, - display->gamma_num * - display->gamma_len, - sizeof(gamma_curves[0]), - GFP_KERNEL); + gamma_curves = devm_kzalloc_objs(dev, gamma_curves[0], + display->gamma_num * display->gamma_len); if (!gamma_curves) return NULL; } @@ -852,7 +849,7 @@ static int fbtft_init_display_from_property(struct fbtft_par *par) if (count == 0) return -EINVAL; - values = kmalloc_array(count + 1, sizeof(*values), GFP_KERNEL); + values = kmalloc_objs(*values, count + 1); if (!values) return -ENOMEM; @@ -1095,7 +1092,7 @@ static struct fbtft_platform_data *fbtft_properties_read(struct device *dev) return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c index 6daa4e706792c0..9a4f6bca88df55 100644 --- a/drivers/staging/greybus/audio_codec.c +++ b/drivers/staging/greybus/audio_codec.c @@ -699,7 +699,7 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, snprintf(module->jack_name, NAME_SIZE, "GB %d Headset Jack", module->dev_id); - headset = devm_kzalloc(module->dev, sizeof(*headset), GFP_KERNEL); + headset = devm_kzalloc_obj(module->dev, *headset); if (!headset) return -ENOMEM; @@ -721,7 +721,7 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, snprintf(module->button_name, NAME_SIZE, "GB %d Button Jack", module->dev_id); - button = devm_kzalloc(module->dev, sizeof(*button), GFP_KERNEL); + button = devm_kzalloc_obj(module->dev, *button); if (!button) { ret = -ENOMEM; goto free_jacks; @@ -1005,7 +1005,7 @@ static int gbcodec_probe(struct snd_soc_component *comp) struct gbaudio_codec_info *info; struct gbaudio_codec_dai *dai; - info = devm_kzalloc(comp->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(comp->dev, *info); if (!info) return -ENOMEM; @@ -1017,7 +1017,7 @@ static int gbcodec_probe(struct snd_soc_component *comp) /* init dai_list used to maintain runtime stream info */ for (i = 0; i < ARRAY_SIZE(gbaudio_dai); i++) { - dai = devm_kzalloc(comp->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(comp->dev, *dai); if (!dai) return -ENOMEM; dai->id = gbaudio_dai[i].id; diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c index 4cd1f42c11f0f5..c7fa4d2d3337cd 100644 --- a/drivers/staging/greybus/audio_module.c +++ b/drivers/staging/greybus/audio_module.c @@ -205,7 +205,7 @@ static int gb_audio_add_data_connection(struct gbaudio_module_info *gbmodule, struct gb_connection *connection; struct gbaudio_data_connection *dai; - dai = devm_kzalloc(gbmodule->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(gbmodule->dev, *dai); if (!dai) return -ENOMEM; @@ -250,7 +250,7 @@ static int gb_audio_probe(struct gb_bundle *bundle, * There can be only one Management connection and any number of data * connections. */ - gbmodule = devm_kzalloc(dev, sizeof(*gbmodule), GFP_KERNEL); + gbmodule = devm_kzalloc_obj(dev, *gbmodule); if (!gbmodule) return -ENOMEM; diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c index 76146f91cddcc2..82d6339b2a2209 100644 --- a/drivers/staging/greybus/audio_topology.c +++ b/drivers/staging/greybus/audio_topology.c @@ -642,7 +642,7 @@ static int gbaudio_tplg_create_enum_kctl(struct gbaudio_module_info *gb, struct gb_audio_enumerated *gb_enum; int i; - gbe = devm_kzalloc(gb->dev, sizeof(*gbe), GFP_KERNEL); + gbe = devm_kzalloc_obj(gb->dev, *gbe); if (!gbe) return -ENOMEM; @@ -680,9 +680,8 @@ static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb, ret = gbaudio_tplg_create_enum_kctl(gb, kctl, ctl); break; default: - ctldata = devm_kzalloc(gb->dev, - sizeof(struct gbaudio_ctl_pvt), - GFP_KERNEL); + ctldata = devm_kzalloc_obj(gb->dev, + struct gbaudio_ctl_pvt); if (!ctldata) return -ENOMEM; ctldata->ctl_id = ctl->id; @@ -848,7 +847,7 @@ static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info *gb, struct gb_audio_enumerated *gb_enum; int i; - gbe = devm_kzalloc(gb->dev, sizeof(*gbe), GFP_KERNEL); + gbe = devm_kzalloc_obj(gb->dev, *gbe); if (!gbe) return -ENOMEM; @@ -878,8 +877,7 @@ static int gbaudio_tplg_create_mixer_ctl(struct gbaudio_module_info *gb, { struct gbaudio_ctl_pvt *ctldata; - ctldata = devm_kzalloc(gb->dev, sizeof(struct gbaudio_ctl_pvt), - GFP_KERNEL); + ctldata = devm_kzalloc_obj(gb->dev, struct gbaudio_ctl_pvt); if (!ctldata) return -ENOMEM; ctldata->ctl_id = ctl->id; @@ -1048,9 +1046,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, curr->name, curr->iface); goto error; } - control = devm_kzalloc(module->dev, - sizeof(struct gbaudio_control), - GFP_KERNEL); + control = devm_kzalloc_obj(module->dev, struct gbaudio_control); if (!control) { ret = -ENOMEM; goto error; @@ -1159,9 +1155,7 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module, curr->name, curr->iface); goto error; } - control = devm_kzalloc(module->dev, sizeof(struct - gbaudio_control), - GFP_KERNEL); + control = devm_kzalloc_obj(module->dev, struct gbaudio_control); if (!control) { ret = -ENOMEM; goto error; @@ -1232,9 +1226,7 @@ static int gbaudio_tplg_process_widgets(struct gbaudio_module_info *module, curr->name, curr->type); goto error; } - widget = devm_kzalloc(module->dev, sizeof(struct - gbaudio_widget), - GFP_KERNEL); + widget = devm_kzalloc_obj(module->dev, struct gbaudio_widget); if (!widget) { ret = -ENOMEM; goto error; diff --git a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c index f8875d2b581bd5..ef5d0169e8ce38 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c +++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c @@ -1200,7 +1200,7 @@ static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i start = pci_resource_start(pdev, ATOM_ISP_PCI_BAR); dev_dbg(&pdev->dev, "start: 0x%x\n", start); - isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(&pdev->dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/staging/media/imx/imx-ic-common.c b/drivers/staging/media/imx/imx-ic-common.c index 6df1ffb5389592..d36bf0a26ce656 100644 --- a/drivers/staging/media/imx/imx-ic-common.c +++ b/drivers/staging/media/imx/imx-ic-common.c @@ -26,7 +26,7 @@ struct v4l2_subdev *imx_media_ic_register(struct v4l2_device *v4l2_dev, struct imx_ic_priv *priv; int ret; - priv = devm_kzalloc(ipu_dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(ipu_dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index b2c648149964c6..4c0aee3690259e 100644 --- a/drivers/staging/media/imx/imx-ic-prp.c +++ b/drivers/staging/media/imx/imx-ic-prp.c @@ -496,7 +496,7 @@ static int prp_init(struct imx_ic_priv *ic_priv) struct prp_priv *priv; int i; - priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(ic_priv->ipu_dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 3430ddeac35696..ceb5ea40ebe137 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -1345,7 +1345,7 @@ static int prp_init(struct imx_ic_priv *ic_priv) struct prp_priv *priv; int i, ret; - priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(ic_priv->ipu_dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index 9216a221b72f4f..1e58e2a48d91a9 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -967,7 +967,7 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd, struct vb2_queue *vq; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index 43c637b333f2f6..34827f96067a4b 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1981,7 +1981,7 @@ static int imx_csi_probe(struct platform_device *pdev) struct csi_priv *priv; int i, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/staging/media/imx/imx-media-dev-common.c b/drivers/staging/media/imx/imx-media-dev-common.c index 0d0ee8627a2dd8..c4987790729622 100644 --- a/drivers/staging/media/imx/imx-media-dev-common.c +++ b/drivers/staging/media/imx/imx-media-dev-common.c @@ -85,7 +85,7 @@ static int imx_media_add_vdev_to_pad(struct imx_media_dev *imxmd, dev_dbg(imxmd->md.dev, "adding %s to pad %s:%u\n", vdev->vfd->entity.name, entity->name, srcpad->index); - pad_vdev = devm_kzalloc(imxmd->md.dev, sizeof(*pad_vdev), GFP_KERNEL); + pad_vdev = devm_kzalloc_obj(imxmd->md.dev, *pad_vdev); if (!pad_vdev) return -ENOMEM; @@ -127,9 +127,8 @@ static int imx_media_alloc_pad_vdev_lists(struct imx_media_dev *imxmd) list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) { entity = &sd->entity; - vdev_lists = devm_kcalloc(imxmd->md.dev, - entity->num_pads, sizeof(*vdev_lists), - GFP_KERNEL); + vdev_lists = devm_kzalloc_objs(imxmd->md.dev, *vdev_lists, + entity->num_pads); if (!vdev_lists) return -ENOMEM; @@ -335,7 +334,7 @@ struct imx_media_dev *imx_media_dev_init(struct device *dev, struct imx_media_dev *imxmd; int ret; - imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL); + imxmd = devm_kzalloc_obj(dev, *imxmd); if (!imxmd) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/imx/imx-media-fim.c b/drivers/staging/media/imx/imx-media-fim.c index ccbc0371fba2e4..d56019b3632cfa 100644 --- a/drivers/staging/media/imx/imx-media-fim.c +++ b/drivers/staging/media/imx/imx-media-fim.c @@ -410,7 +410,7 @@ struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd) struct imx_media_fim *fim; int ret; - fim = devm_kzalloc(sd->dev, sizeof(*fim), GFP_KERNEL); + fim = devm_kzalloc_obj(sd->dev, *fim); if (!fim) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 8dcbb6fe764910..4838d11f5f6d3e 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -881,7 +881,7 @@ struct v4l2_subdev *imx_media_vdic_register(struct v4l2_device *v4l2_dev, struct vdic_priv *priv; int i, ret; - priv = devm_kzalloc(ipu_dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(ipu_dev, *priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c index f6cbf0310e89ca..e429aeb345caf6 100644 --- a/drivers/staging/media/imx/imx6-mipi-csi2.c +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c @@ -722,7 +722,7 @@ static int csi2_probe(struct platform_device *pdev) struct csi2_dev *csi2; int i, ret; - csi2 = devm_kzalloc(&pdev->dev, sizeof(*csi2), GFP_KERNEL); + csi2 = devm_kzalloc_obj(&pdev->dev, *csi2); if (!csi2) return -ENOMEM; diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index 84c4d0bf027d50..8f8817c83f151b 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -622,7 +622,7 @@ static int imgu_pci_probe(struct pci_dev *pci_dev, void __iomem *const *iomap; int r; - imgu = devm_kzalloc(&pci_dev->dev, sizeof(*imgu), GFP_KERNEL); + imgu = devm_kzalloc_obj(&pci_dev->dev, *imgu); if (!imgu) return -ENOMEM; diff --git a/drivers/staging/media/ipu7/ipu7-fw-isys.c b/drivers/staging/media/ipu7/ipu7-fw-isys.c index e4b9c364572b95..309830921f2cf2 100644 --- a/drivers/staging/media/ipu7/ipu7-fw-isys.c +++ b/drivers/staging/media/ipu7/ipu7-fw-isys.c @@ -92,8 +92,7 @@ int ipu7_fw_isys_init(struct ipu7_isys *isys) int ret; /* Allocate and init syscom context. */ - syscom = devm_kzalloc(dev, sizeof(struct ipu7_syscom_context), - GFP_KERNEL); + syscom = devm_kzalloc_obj(dev, struct ipu7_syscom_context); if (!syscom) return -ENOMEM; diff --git a/drivers/staging/media/ipu7/ipu7-isys-subdev.c b/drivers/staging/media/ipu7/ipu7-isys-subdev.c index 2cb0521b424028..a4003132a2cc29 100644 --- a/drivers/staging/media/ipu7/ipu7-isys-subdev.c +++ b/drivers/staging/media/ipu7/ipu7-isys-subdev.c @@ -282,8 +282,8 @@ int ipu7_isys_subdev_init(struct ipu7_isys_subdev *asd, asd->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; asd->sd.internal_ops = &ipu7_isys_subdev_internal_ops; - asd->pad = devm_kcalloc(&asd->isys->adev->auxdev.dev, num_pads, - sizeof(*asd->pad), GFP_KERNEL); + asd->pad = devm_kzalloc_objs(&asd->isys->adev->auxdev.dev, *asd->pad, + num_pads); if (!asd->pad) return -ENOMEM; diff --git a/drivers/staging/media/ipu7/ipu7-isys.c b/drivers/staging/media/ipu7/ipu7-isys.c index a54393fbb9db63..f2d778ba9c2ac1 100644 --- a/drivers/staging/media/ipu7/ipu7-isys.c +++ b/drivers/staging/media/ipu7/ipu7-isys.c @@ -119,7 +119,7 @@ static int isys_fw_log_init(struct ipu7_isys *isys) if (isys->fw_log) return 0; - fw_log = devm_kzalloc(dev, sizeof(*fw_log), GFP_KERNEL); + fw_log = devm_kzalloc_obj(dev, *fw_log); if (!fw_log) return -ENOMEM; @@ -706,7 +706,7 @@ static int isys_probe(struct auxiliary_device *auxdev, if (!isp->ipu7_bus_ready_to_probe) return -EPROBE_DEFER; - isys = devm_kzalloc(&auxdev->dev, sizeof(*isys), GFP_KERNEL); + isys = devm_kzalloc_obj(&auxdev->dev, *isys); if (!isys) return -ENOMEM; @@ -723,8 +723,8 @@ static int isys_probe(struct auxiliary_device *auxdev, INIT_LIST_HEAD(&isys->requests); csi2_pdata = &isys->pdata->ipdata->csi2; - isys->csi2 = devm_kcalloc(&auxdev->dev, csi2_pdata->nports, - sizeof(*isys->csi2), GFP_KERNEL); + isys->csi2 = devm_kzalloc_objs(&auxdev->dev, *isys->csi2, + csi2_pdata->nports); if (!isys->csi2) { ret = -ENOMEM; goto out_runtime_put; diff --git a/drivers/staging/media/ipu7/ipu7-mmu.c b/drivers/staging/media/ipu7/ipu7-mmu.c index 6ded07ccd78062..b50ae37225936b 100644 --- a/drivers/staging/media/ipu7/ipu7-mmu.c +++ b/drivers/staging/media/ipu7/ipu7-mmu.c @@ -802,7 +802,7 @@ struct ipu7_mmu *ipu7_mmu_init(struct device *dev, if (hw->nr_mmus > IPU_MMU_MAX_NUM) return ERR_PTR(-EINVAL); - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -820,7 +820,7 @@ struct ipu7_mmu *ipu7_mmu_init(struct device *dev, pdata_mmu->uao_base = base + src_mmu->uao_offset; } - mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL); + mmu = devm_kzalloc_obj(dev, *mmu); if (!mmu) return ERR_PTR(-ENOMEM); diff --git a/drivers/staging/media/ipu7/ipu7.c b/drivers/staging/media/ipu7/ipu7.c index 88e362c7ae350a..543c9f08da88b9 100644 --- a/drivers/staging/media/ipu7/ipu7.c +++ b/drivers/staging/media/ipu7/ipu7.c @@ -2424,7 +2424,7 @@ static int ipu7_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!fwnode || fwnode_property_read_u32(fwnode, "is_es", &is_es)) is_es = 0; - isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c index be29d5a11c2e68..3e086223c4f8c0 100644 --- a/drivers/staging/media/meson/vdec/vdec.c +++ b/drivers/staging/media/meson/vdec/vdec.c @@ -992,7 +992,7 @@ static int vdec_probe(struct platform_device *pdev) int irq; int ret; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c index c3331b4f3f0205..d060dcd3c01cd9 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c @@ -456,7 +456,7 @@ static int cedrus_probe(struct platform_device *pdev) struct video_device *vfd; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c index 6877f2beee8c8c..d6685442ce62d0 100644 --- a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c +++ b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c @@ -428,7 +428,7 @@ static int sun6i_isp_probe(struct platform_device *platform_dev) if (!variant) return -EINVAL; - isp_dev = devm_kzalloc(dev, sizeof(*isp_dev), GFP_KERNEL); + isp_dev = devm_kzalloc_obj(dev, *isp_dev); if (!isp_dev) return -ENOMEM; diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c index 5a5fca378ae64a..a18515c4532001 100644 --- a/drivers/staging/media/tegra-video/csi.c +++ b/drivers/staging/media/tegra-video/csi.c @@ -791,7 +791,7 @@ static int tegra_csi_probe(struct platform_device *pdev) unsigned int i; int ret; - csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); + csi = devm_kzalloc_obj(&pdev->dev, *csi); if (!csi) return -ENOMEM; @@ -801,8 +801,8 @@ static int tegra_csi_probe(struct platform_device *pdev) csi->soc = of_device_get_match_data(&pdev->dev); - csi->clks = devm_kcalloc(&pdev->dev, csi->soc->num_clks, - sizeof(*csi->clks), GFP_KERNEL); + csi->clks = devm_kzalloc_objs(&pdev->dev, *csi->clks, + csi->soc->num_clks); if (!csi->clks) return -ENOMEM; diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c index d8c77d1290efd8..72043359177126 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -1864,7 +1864,7 @@ static int tegra_vi_probe(struct platform_device *pdev) struct tegra_vi *vi; int ret; - vi = devm_kzalloc(&pdev->dev, sizeof(*vi), GFP_KERNEL); + vi = devm_kzalloc_obj(&pdev->dev, *vi); if (!vi) return -ENOMEM; diff --git a/drivers/staging/media/tegra-video/vip.c b/drivers/staging/media/tegra-video/vip.c index 5fba11e31e1d06..b73ba0eab5573e 100644 --- a/drivers/staging/media/tegra-video/vip.c +++ b/drivers/staging/media/tegra-video/vip.c @@ -227,7 +227,7 @@ static int tegra_vip_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing VIP \"%s\" from %pOF\n", pdev->name, pdev->dev.of_node); - vip = devm_kzalloc(&pdev->dev, sizeof(*vip), GFP_KERNEL); + vip = devm_kzalloc_obj(&pdev->dev, *vip); if (!vip) return -ENOMEM; diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 41cbdfdc1da692..b4ad6cb275da96 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -797,7 +797,7 @@ static int tegra_nvec_probe(struct platform_device *pdev) return -ENODEV; } - nvec = devm_kzalloc(dev, sizeof(struct nvec_chip), GFP_KERNEL); + nvec = devm_kzalloc_obj(dev, struct nvec_chip); if (!nvec) return -ENOMEM; diff --git a/drivers/staging/nvec/nvec_paz00.c b/drivers/staging/nvec/nvec_paz00.c index 55d59840fca450..81cc7b99142f58 100644 --- a/drivers/staging/nvec/nvec_paz00.c +++ b/drivers/staging/nvec/nvec_paz00.c @@ -42,7 +42,7 @@ static int nvec_paz00_probe(struct platform_device *pdev) struct nvec_led *led; int ret = 0; - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc_obj(&pdev->dev, *led); if (!led) return -ENOMEM; diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c index c514d51a9e57a8..c9173a0609c081 100644 --- a/drivers/staging/nvec/nvec_power.c +++ b/drivers/staging/nvec/nvec_power.c @@ -377,7 +377,7 @@ static int nvec_power_probe(struct platform_device *pdev) struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); struct power_supply_config psy_cfg = {}; - power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_KERNEL); + power = devm_kzalloc_obj(&pdev->dev, struct nvec_power); if (!power) return -ENOMEM; diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c index 42ec4b8324a834..dea5696a6642a9 100644 --- a/drivers/staging/octeon/ethernet.c +++ b/drivers/staging/octeon/ethernet.c @@ -695,7 +695,7 @@ static int cvm_oct_probe(struct platform_device *pdev) int mtu_overhead = ETH_HLEN + ETH_FCS_LEN; struct octeon_ethernet_platform *plat; - plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(&pdev->dev, *plat); if (!plat) return -ENOMEM; diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index 21e31027433041..6ce02ea48d2c97 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -973,7 +973,7 @@ static int lynxfb_pci_probe(struct pci_dev *pdev, return err; err = -ENOMEM; - sm750_dev = devm_kzalloc(&pdev->dev, sizeof(*sm750_dev), GFP_KERNEL); + sm750_dev = devm_kzalloc_obj(&pdev->dev, *sm750_dev); if (!sm750_dev) return err; diff --git a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c index 75c37c8866c864..dcae93e5c5ac7a 100644 --- a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c +++ b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c @@ -129,7 +129,7 @@ static int iscsit_randomize_pdu_lists( seq_count++; continue; } - array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL); + array = kzalloc_objs(u32, seq_count); if (!array) { pr_err("Unable to allocate memory" " for random array.\n"); @@ -149,7 +149,7 @@ static int iscsit_randomize_pdu_lists( } if (seq_count) { - array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL); + array = kzalloc_objs(u32, seq_count); if (!array) { pr_err("Unable to allocate memory for" " random array.\n"); @@ -181,7 +181,7 @@ static int iscsit_randomize_seq_lists( if (!seq_count) return 0; - array = kcalloc(seq_count, sizeof(u32), GFP_KERNEL); + array = kzalloc_objs(u32, seq_count); if (!array) { pr_err("Unable to allocate memory for random array.\n"); return -ENOMEM; diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c index 896fc0f0379f77..44fd25a750594c 100644 --- a/drivers/target/sbp/sbp_target.c +++ b/drivers/target/sbp/sbp_target.c @@ -1813,7 +1813,7 @@ static int sbp_update_unit_directory(struct sbp_tport *tport) num_entries++; /* allocate num_entries + 4 for the header and unique ID leaf */ - data = kcalloc((num_entries + 4), sizeof(u32), GFP_KERNEL); + data = kzalloc_objs(u32, (num_entries + 4)); if (!data) return -ENOMEM; diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 9db2201aa553f1..c5d5d6a91fee7f 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -349,6 +349,19 @@ int core_enable_device_list_for_node( new->attach_count++; mutex_lock(&nacl->lun_entry_mutex); + /* + * Do not attach a new dev entry to an se_lun that is being torn down. + * lun_shutdown is set by core_tpg_remove_lun() before its + * core_clear_lun_from_tpg() sweep; checking it here under the same + * nacl->lun_entry_mutex the sweep takes guarantees that once the sweep + * has passed this ACL no dev entry can be left dangling on the + * se_lun->lun_deve_list that is about to be freed. + */ + if (lun->lun_shutdown) { + mutex_unlock(&nacl->lun_entry_mutex); + ret = -ENODEV; + goto free_stats; + } orig = target_nacl_find_deve(nacl, mapped_lun); if (orig && orig->se_lun) { struct se_lun *orig_lun = orig->se_lun; @@ -375,12 +388,12 @@ int core_enable_device_list_for_node( new->se_lun_acl = lun_acl; hlist_del_rcu(&orig->link); hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); - mutex_unlock(&nacl->lun_entry_mutex); spin_lock(&lun->lun_deve_lock); list_del(&orig->lun_link); list_add_tail(&new->lun_link, &lun->lun_deve_list); spin_unlock(&lun->lun_deve_lock); + mutex_unlock(&nacl->lun_entry_mutex); kref_put(&orig->pr_kref, target_pr_kref_release); wait_for_completion(&orig->pr_comp); @@ -393,11 +406,10 @@ int core_enable_device_list_for_node( new->se_lun = lun; new->se_lun_acl = lun_acl; hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); - mutex_unlock(&nacl->lun_entry_mutex); - spin_lock(&lun->lun_deve_lock); list_add_tail(&new->lun_link, &lun->lun_deve_list); spin_unlock(&lun->lun_deve_lock); + mutex_unlock(&nacl->lun_entry_mutex); target_luns_data_has_changed(nacl, new, true); return 0; diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index 2853b95b2c5976..ad024009df56bb 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -371,6 +371,16 @@ static bool iscsi_parse_pr_out_transport_id( pr_err("Missing ISID in iSCSI Initiator port TransportID\n"); return false; } + /* + * The registration code reads the ISID as a C string, + * and its first 8 bytes with get_unaligned_be64(), so + * require 8 bytes after the separator and a NUL inside + * the rest of the descriptor. + */ + if (buf + tid_len - p < 8 || !memchr(p, '\0', buf + tid_len - p)) { + pr_err("Incomplete or unterminated ISID in iSCSI Initiator port TransportID\n"); + return false; + } *port_nexus_ptr = p; /* * Go ahead and do the lower case conversion of the received diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 25b1bcacc0c8f5..ca1a2802aa228c 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -3226,10 +3226,11 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key, transport_kunmap_data_sg(cmd); buf = NULL; - if ((tid_len + 24) != cmd->data_length) { - pr_err("SPC-3 PR: Illegal tid_len: %u + 24 byte header" - " does not equal CDB data_length: %u\n", tid_len, - cmd->data_length); + /* TransportID is at least 24 bytes. buf[24] is its first byte. */ + if (tid_len < 24 || + tid_len != cmd->data_length - 24) { + pr_err("SPC-3 PR: Illegal tid_len: %u for data_length: %u\n", + tid_len, cmd->data_length); ret = TCM_INVALID_PARAMETER_LIST; goto out_put_pr_reg; } diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index ccff9f6e482663..e615e5e3042730 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -266,6 +266,15 @@ struct se_node_acl *core_tpg_check_initiator_node_acl( kref_get(&acl->acl_kref); acl->dynamic_node_acl = 1; + /* + * Publish the dynamic NodeACL on tpg->acl_node_list before creating + * its demo-mode MappedLUN dev entries below, so that a concurrent LUN + * teardown sweep (core_clear_lun_from_tpg(), which walks acl_node_list) + * can observe and disable those dev entries. Otherwise a dev entry can + * be left on an se_lun->lun_deve_list that is about to be freed. + */ + target_add_node_acl(acl); + /* * Here we only create demo-mode MappedLUNs from the active * TPG LUNs if the fabric is not explicitly asking for @@ -275,7 +284,6 @@ struct se_node_acl *core_tpg_check_initiator_node_acl( (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1)) core_tpg_add_node_to_devs(acl, tpg, NULL); - target_add_node_acl(acl); return acl; } EXPORT_SYMBOL(core_tpg_check_initiator_node_acl); diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 425ad1246a7595..80da90accac564 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -645,8 +645,7 @@ static struct tcmu_cmd *tcmu_alloc_cmd(struct se_cmd *se_cmd) tcmu_cmd->tcmu_dev = udev; tcmu_cmd_set_block_cnts(tcmu_cmd); - tcmu_cmd->dbi = kcalloc(tcmu_cmd->dbi_cnt, sizeof(uint32_t), - GFP_NOIO); + tcmu_cmd->dbi = kzalloc_objs(uint32_t, tcmu_cmd->dbi_cnt, GFP_NOIO); if (!tcmu_cmd->dbi) { kmem_cache_free(tcmu_cmd_cache, tcmu_cmd); return NULL; @@ -2524,6 +2523,11 @@ static int tcmu_set_data_pages_per_blk(struct tcmu_dev *udev, substring_t *arg) return ret; } + if (val <= 0) { + pr_err("Invalid data_pages_per_blk %d.\n", val); + return -EINVAL; + } + if (val > TCMU_MBS_TO_PAGES(udev->data_area_mb)) { pr_err("Invalid data_pages_per_blk %d: greater than max_data_area_mb %d -> %zd pages).\n", val, udev->data_area_mb, diff --git a/drivers/tee/optee/protmem.c b/drivers/tee/optee/protmem.c index be3abf6e8aa6d9..bf2c678108df40 100644 --- a/drivers/tee/optee/protmem.c +++ b/drivers/tee/optee/protmem.c @@ -304,8 +304,7 @@ struct tee_protmem_pool *optee_protmem_alloc_dyn_pool(struct optee *optee, if (rc) { if (rc != -ENOSPC) goto err; - rp->mem_attrs = kcalloc(rp->mem_attr_count, - sizeof(*rp->mem_attrs), GFP_KERNEL); + rp->mem_attrs = kzalloc_objs(*rp->mem_attrs, rp->mem_attr_count); if (!rp->mem_attrs) { rc = -ENOMEM; goto err; diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c index 7c63a1b44a6b93..e328b6a0cf5393 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -729,7 +729,7 @@ static int airoha_thermal_probe(struct platform_device *pdev) soc_data = device_get_match_data(dev); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -751,7 +751,7 @@ static int airoha_thermal_probe(struct platform_device *pdev) struct airoha_thermal_zone *zone; struct thermal_zone_device *tz; - zone = devm_kzalloc(dev, sizeof(*zone), GFP_KERNEL); + zone = devm_kzalloc_obj(dev, *zone); if (!zone) return -ENOMEM; diff --git a/drivers/thermal/amlogic_thermal.c b/drivers/thermal/amlogic_thermal.c index 60728de6968ac0..5f2565d028299b 100644 --- a/drivers/thermal/amlogic_thermal.c +++ b/drivers/thermal/amlogic_thermal.c @@ -307,7 +307,7 @@ static int amlogic_thermal_probe(struct platform_device *pdev) void __iomem *base; int ret; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index ff63b4f2b97791..83672f95b011bc 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -821,11 +821,11 @@ static int armada_thermal_probe(struct platform_device *pdev) if (!match) return -ENODEV; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; @@ -910,9 +910,8 @@ static int armada_thermal_probe(struct platform_device *pdev) * channel has one sensor. */ for (sensor_id = 0; sensor_id <= priv->data->cpu_nr; sensor_id++) { - sensor = devm_kzalloc(&pdev->dev, - sizeof(struct armada_thermal_sensor), - GFP_KERNEL); + sensor = devm_kzalloc_obj(&pdev->dev, + struct armada_thermal_sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c index 03ac2d02e9d40a..5ebc987ff985e6 100644 --- a/drivers/thermal/broadcom/bcm2711_thermal.c +++ b/drivers/thermal/broadcom/bcm2711_thermal.c @@ -73,7 +73,7 @@ static int bcm2711_thermal_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c index c5105dfc6ec97a..d2200f36907fc5 100644 --- a/drivers/thermal/broadcom/bcm2835_thermal.c +++ b/drivers/thermal/broadcom/bcm2835_thermal.c @@ -120,7 +120,7 @@ static void bcm2835_thermal_debugfs(struct platform_device *pdev) data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL); - regset = devm_kzalloc(&pdev->dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(&pdev->dev, *regset); if (!regset) return; @@ -167,7 +167,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) u32 val; unsigned long rate; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c index 5e23f9e008475d..7403fa7a77ec4b 100644 --- a/drivers/thermal/broadcom/brcmstb_thermal.c +++ b/drivers/thermal/broadcom/brcmstb_thermal.c @@ -326,7 +326,7 @@ static int brcmstb_thermal_probe(struct platform_device *pdev) struct brcmstb_thermal_priv *priv; int irq, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c index 9a29dfd4c7fe5f..f8d1d7b013b367 100644 --- a/drivers/thermal/broadcom/sr-thermal.c +++ b/drivers/thermal/broadcom/sr-thermal.c @@ -55,7 +55,7 @@ static int sr_thermal_probe(struct platform_device *pdev) unsigned int i; int ret; - sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL); + sr_thermal = devm_kzalloc_obj(dev, *sr_thermal); if (!sr_thermal) return -ENOMEM; diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a8d4b766ba21b8..515ca492a4e39c 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -182,8 +182,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) } } - thermal = devm_kzalloc(&pdev->dev, sizeof(struct da9062_thermal), - GFP_KERNEL); + thermal = devm_kzalloc_obj(&pdev->dev, struct da9062_thermal); if (!thermal) { ret = -ENOMEM; goto err; diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c index 46005b4767224d..48981247763fbf 100644 --- a/drivers/thermal/db8500_thermal.c +++ b/drivers/thermal/db8500_thermal.c @@ -154,7 +154,7 @@ static int db8500_thermal_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int low_irq, high_irq, ret = 0; - th = devm_kzalloc(dev, sizeof(*th), GFP_KERNEL); + th = devm_kzalloc_obj(dev, *th); if (!th) return -ENOMEM; diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 9ada52cbf7dd73..283c2c966f2ad8 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -353,8 +353,7 @@ static int devfreq_cooling_gen_tables(struct devfreq_cooling_device *dfc, unsigned long freq; int i; - dfc->freq_table = kcalloc(num_opps, sizeof(*dfc->freq_table), - GFP_KERNEL); + dfc->freq_table = kzalloc_objs(*dfc->freq_table, num_opps); if (!dfc->freq_table) return -ENOMEM; diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c index 723bc72f06264b..0bfdc9ffcea8b4 100644 --- a/drivers/thermal/dove_thermal.c +++ b/drivers/thermal/dove_thermal.c @@ -121,7 +121,7 @@ static int dove_thermal_probe(struct platform_device *pdev) struct dove_thermal_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 17ed0c5b7767d6..9986fb09b177fd 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -393,7 +393,7 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) if (IS_ERR(data->clk)) return dev_err_probe(dev, PTR_ERR(data->clk), "failed to get thermal clk\n"); - data->sensor = devm_kzalloc(dev, sizeof(*data->sensor), GFP_KERNEL); + data->sensor = devm_kzalloc_obj(dev, *data->sensor); if (!data->sensor) return -ENOMEM; @@ -412,8 +412,7 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data) data->nr_sensors = 1; - data->sensor = devm_kcalloc(dev, data->nr_sensors, - sizeof(*data->sensor), GFP_KERNEL); + data->sensor = devm_kzalloc_objs(dev, *data->sensor, data->nr_sensors); if (!data->sensor) return -ENOMEM; @@ -544,7 +543,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int i, ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c index 719d71f5b23565..8cf9d554a21810 100644 --- a/drivers/thermal/imx8mm_thermal.c +++ b/drivers/thermal/imx8mm_thermal.c @@ -300,8 +300,7 @@ static int imx8mm_tmu_probe(struct platform_device *pdev) data = of_device_get_match_data(&pdev->dev); - tmu = devm_kzalloc(&pdev->dev, struct_size(tmu, sensors, - data->num_sensors), GFP_KERNEL); + tmu = devm_kzalloc_flex(&pdev->dev, *tmu, sensors, data->num_sensors); if (!tmu) return -ENOMEM; diff --git a/drivers/thermal/imx91_thermal.c b/drivers/thermal/imx91_thermal.c index 196ee20fce1e3e..6d0aba992244ba 100644 --- a/drivers/thermal/imx91_thermal.c +++ b/drivers/thermal/imx91_thermal.c @@ -239,7 +239,7 @@ static int imx91_tmu_probe(struct platform_device *pdev) int irq, ret; u32 div; - tmu = devm_kzalloc(dev, sizeof(struct imx91_tmu), GFP_KERNEL); + tmu = devm_kzalloc_obj(dev, struct imx91_tmu); if (!tmu) return -ENOMEM; diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c index 88558ce588807a..28154dffdaf89a 100644 --- a/drivers/thermal/imx_sc_thermal.c +++ b/drivers/thermal/imx_sc_thermal.c @@ -85,7 +85,7 @@ static int imx_sc_thermal_probe(struct platform_device *pdev) for (i = 0; resource_id[i] >= 0; i++) { - sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&pdev->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 887d381541a349..1a57aa9dc9001c 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -590,7 +590,7 @@ static int imx_thermal_probe(struct platform_device *pdev) int measure_freq; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/intel/int340x_thermal/int3401_thermal.c b/drivers/thermal/intel/int340x_thermal/int3401_thermal.c index 96d6277a5a8c47..ffaf1911c1b8ff 100644 --- a/drivers/thermal/intel/int340x_thermal/int3401_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3401_thermal.c @@ -23,7 +23,7 @@ static int int3401_add(struct platform_device *pdev) struct proc_thermal_device *proc_priv; int ret; - proc_priv = devm_kzalloc(&pdev->dev, sizeof(*proc_priv), GFP_KERNEL); + proc_priv = devm_kzalloc_obj(&pdev->dev, *proc_priv); if (!proc_priv) return -ENOMEM; diff --git a/drivers/thermal/intel/int340x_thermal/int3402_thermal.c b/drivers/thermal/intel/int340x_thermal/int3402_thermal.c index 57b90005888a31..2691f585e2d2b4 100644 --- a/drivers/thermal/intel/int340x_thermal/int3402_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3402_thermal.c @@ -51,7 +51,7 @@ static int int3402_thermal_probe(struct platform_device *pdev) if (!acpi_has_method(adev->handle, "_TMP")) return -ENODEV; - d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(&pdev->dev, *d); if (!d) return -ENOMEM; diff --git a/drivers/thermal/intel/int340x_thermal/int3403_thermal.c b/drivers/thermal/intel/int340x_thermal/int3403_thermal.c index 2262de1e14d950..65ad648bece7c7 100644 --- a/drivers/thermal/intel/int340x_thermal/int3403_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3403_thermal.c @@ -73,7 +73,7 @@ static int int3403_sensor_add(struct int3403_priv *priv) int result = 0; struct int3403_sensor *obj; - obj = devm_kzalloc(&priv->pdev->dev, sizeof(*obj), GFP_KERNEL); + obj = devm_kzalloc_obj(&priv->pdev->dev, *obj); if (!obj) return -ENOMEM; @@ -160,7 +160,7 @@ static int int3403_cdev_add(struct int3403_priv *priv) struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *p; - obj = devm_kzalloc(&priv->pdev->dev, sizeof(*obj), GFP_KERNEL); + obj = devm_kzalloc_obj(&priv->pdev->dev, *obj); if (!obj) return -ENOMEM; @@ -204,8 +204,7 @@ static int int3403_add(struct platform_device *pdev) unsigned long long tmp; acpi_status status; - priv = devm_kzalloc(&pdev->dev, sizeof(struct int3403_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct int3403_priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/intel/int340x_thermal/int3406_thermal.c b/drivers/thermal/intel/int340x_thermal/int3406_thermal.c index e21fcbccf4ba63..7b2ad59733b412 100644 --- a/drivers/thermal/intel/int340x_thermal/int3406_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3406_thermal.c @@ -141,7 +141,7 @@ static int int3406_thermal_probe(struct platform_device *pdev) if (!ACPI_HANDLE(&pdev->dev)) return -ENODEV; - d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL); + d = devm_kzalloc_obj(&pdev->dev, *d); if (!d) return -ENOMEM; d->handle = ACPI_HANDLE(&pdev->dev); diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index c5131423ec9bd8..7d6fee59ade202 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -334,11 +334,11 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ }; int irq_flag = 0, irq, ret; - proc_priv = devm_kzalloc(&pdev->dev, sizeof(*proc_priv), GFP_KERNEL); + proc_priv = devm_kzalloc_obj(&pdev->dev, *proc_priv); if (!proc_priv) return -ENOMEM; - pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL); + pci_info = devm_kzalloc_obj(&pdev->dev, *pci_info); if (!pci_info) return -ENOMEM; diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c index ccfdd2f9d9737c..5a474db14a3673 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c @@ -40,7 +40,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, return ret; } - proc_priv = devm_kzalloc(&pdev->dev, sizeof(*proc_priv), GFP_KERNEL); + proc_priv = devm_kzalloc_obj(&pdev->dev, *proc_priv); if (!proc_priv) return -ENOMEM; diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index 52e71af67dc6f8..074bc8ca5f0f4b 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -168,7 +168,7 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, u8 tsel; int err; - ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL); + ptd = devm_kzalloc_obj(&pdev->dev, *ptd); if (!ptd) return -ENOMEM; diff --git a/drivers/thermal/intel/therm_throt.c b/drivers/thermal/intel/therm_throt.c index 4d4e81601d1796..59520cac6cc800 100644 --- a/drivers/thermal/intel/therm_throt.c +++ b/drivers/thermal/intel/therm_throt.c @@ -758,9 +758,8 @@ static __init void init_directed_pkg_intr(void) if (!boot_cpu_has(X86_FEATURE_DPTI)) return; - directed_intr_handler_cpus = kmalloc_array(topology_max_packages(), - sizeof(*directed_intr_handler_cpus), - GFP_KERNEL); + directed_intr_handler_cpus = kmalloc_objs(*directed_intr_handler_cpus, + topology_max_packages()); if (!directed_intr_handler_cpus) return; diff --git a/drivers/thermal/k3_bandgap.c b/drivers/thermal/k3_bandgap.c index 678d6ed711b5ef..7ac348f724a66d 100644 --- a/drivers/thermal/k3_bandgap.c +++ b/drivers/thermal/k3_bandgap.c @@ -168,7 +168,7 @@ static int k3_bandgap_probe(struct platform_device *pdev) K3_VTM_ADC_BEGIN_VAL)) return -EINVAL; - bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL); + bgp = devm_kzalloc_obj(&pdev->dev, *bgp); if (!bgp) return -ENOMEM; @@ -190,7 +190,7 @@ static int k3_bandgap_probe(struct platform_device *pdev) cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK; cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK); - data = devm_kcalloc(dev, cnt, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_objs(dev, *data, cnt); if (!data) { ret = -ENOMEM; goto err_alloc; diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c index 6aba00d8b8fdae..5debfd5dfb9bfe 100644 --- a/drivers/thermal/k3_j72xx_bandgap.c +++ b/drivers/thermal/k3_j72xx_bandgap.c @@ -402,7 +402,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) -1157800000000, }; - bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL); + bgp = devm_kzalloc_obj(&pdev->dev, *bgp); if (!bgp) return -ENOMEM; @@ -456,7 +456,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) bgp->cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK; bgp->cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK); - data = devm_kcalloc(bgp->dev, bgp->cnt, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_objs(bgp->dev, *data, bgp->cnt); if (!data) { ret = -ENOMEM; goto err_alloc; @@ -468,8 +468,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) goto err_alloc; } - derived_table = devm_kcalloc(bgp->dev, TABLE_SIZE, sizeof(*derived_table), - GFP_KERNEL); + derived_table = devm_kzalloc_objs(bgp->dev, *derived_table, TABLE_SIZE); if (!derived_table) { ret = -ENOMEM; goto err_free_ref_table; diff --git a/drivers/thermal/khadas_mcu_fan.c b/drivers/thermal/khadas_mcu_fan.c index 1da639d0549717..9bda503615fe04 100644 --- a/drivers/thermal/khadas_mcu_fan.c +++ b/drivers/thermal/khadas_mcu_fan.c @@ -109,7 +109,7 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev) if (!id) return -EINVAL; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c index 4619e090f75619..7519a97d782847 100644 --- a/drivers/thermal/kirkwood_thermal.c +++ b/drivers/thermal/kirkwood_thermal.c @@ -63,7 +63,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) struct kirkwood_thermal_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c index 4d40fc706a5350..197ed24d99e71f 100644 --- a/drivers/thermal/loongson2_thermal.c +++ b/drivers/thermal/loongson2_thermal.c @@ -129,7 +129,7 @@ static int loongson2_thermal_probe(struct platform_device *pdev) struct thermal_zone_device *tzd; int ret, irq, i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c index f4a1535f480640..1456dcc1d4d82c 100644 --- a/drivers/thermal/max77620_thermal.c +++ b/drivers/thermal/max77620_thermal.c @@ -88,7 +88,7 @@ static int max77620_thermal_probe(struct platform_device *pdev) struct max77620_therm_info *mtherm; int ret; - mtherm = devm_kzalloc(&pdev->dev, sizeof(*mtherm), GFP_KERNEL); + mtherm = devm_kzalloc_obj(&pdev->dev, *mtherm); if (!mtherm) return -ENOMEM; diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index 9ee2e7283435ac..434f856c0f0458 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -1200,7 +1200,7 @@ static int mtk_thermal_probe(struct platform_device *pdev) struct thermal_zone_device *tzdev; void __iomem *apmixed_base, *auxadc_base; - mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL); + mt = devm_kzalloc_obj(&pdev->dev, *mt); if (!mt) return -ENOMEM; diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index 52f99f3e645001..350fffd3e5a28d 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -276,7 +276,7 @@ static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) if (IS_ERR(dentry)) continue; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) continue; @@ -1450,7 +1450,7 @@ static int lvts_probe(struct platform_device *pdev) struct resource *res; int irq, ret; - lvts_td = devm_kzalloc(dev, sizeof(*lvts_td), GFP_KERNEL); + lvts_td = devm_kzalloc_obj(dev, *lvts_td); if (!lvts_td) return -ENOMEM; diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c index 99396b93eff5d1..6bfe25021e05f1 100644 --- a/drivers/thermal/qcom/lmh.c +++ b/drivers/thermal/qcom/lmh.c @@ -107,7 +107,7 @@ static int lmh_probe(struct platform_device *pdev) if (!qcom_scm_is_available()) return -EPROBE_DEFER; - lmh_data = devm_kzalloc(dev, sizeof(*lmh_data), GFP_KERNEL); + lmh_data = devm_kzalloc_obj(dev, *lmh_data); if (!lmh_data) return -ENOMEM; diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c index 9cf552d3686847..910b241fa94d6c 100644 --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c @@ -347,7 +347,7 @@ static int adc_tm5_probe(struct auxiliary_device *aux_dev, struct device *dev = &aux_dev->dev; int ret; - adc_tm5 = devm_kzalloc(dev, sizeof(*adc_tm5), GFP_KERNEL); + adc_tm5 = devm_kzalloc_obj(dev, *adc_tm5); if (!adc_tm5) return -ENOMEM; @@ -356,8 +356,8 @@ static int adc_tm5_probe(struct auxiliary_device *aux_dev, adc_tm5->dev = dev; adc_tm5->dev_data = aux_dev_wrapper->dev_data; adc_tm5->nchannels = aux_dev_wrapper->n_tm_channels; - adc_tm5->chan_props = devm_kcalloc(dev, aux_dev_wrapper->n_tm_channels, - sizeof(*adc_tm5->chan_props), GFP_KERNEL); + adc_tm5->chan_props = devm_kzalloc_objs(dev, *adc_tm5->chan_props, + aux_dev_wrapper->n_tm_channels); if (!adc_tm5->chan_props) return -ENOMEM; diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c index 4554a6fa55d113..12d30affcc5dc7 100644 --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c @@ -943,8 +943,8 @@ static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node * if (!adc_tm->nchannels) return -EINVAL; - adc_tm->channels = devm_kcalloc(dev, adc_tm->nchannels, - sizeof(*adc_tm->channels), GFP_KERNEL); + adc_tm->channels = devm_kzalloc_objs(dev, *adc_tm->channels, + adc_tm->nchannels); if (!adc_tm->channels) return -ENOMEM; @@ -1006,7 +1006,7 @@ static int adc_tm5_probe(struct platform_device *pdev) if (ret) return ret; - adc_tm = devm_kzalloc(&pdev->dev, sizeof(*adc_tm), GFP_KERNEL); + adc_tm = devm_kzalloc_obj(&pdev->dev, *adc_tm); if (!adc_tm) return -ENOMEM; diff --git a/drivers/thermal/qcom/qcom-spmi-mbg-tm.c b/drivers/thermal/qcom/qcom-spmi-mbg-tm.c index a05bb444627aa1..512bfda540484f 100644 --- a/drivers/thermal/qcom/qcom-spmi-mbg-tm.c +++ b/drivers/thermal/qcom/qcom-spmi-mbg-tm.c @@ -202,7 +202,7 @@ static int mbg_tm_probe(struct platform_device *pdev) u32 res; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index 911ebfd0cdeb65..9fb63fa36fa730 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -765,7 +765,7 @@ static int qpnp_tm_probe(struct platform_device *pdev) node = pdev->dev.of_node; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 4d7013fc79d63f..ff7c573c6a2139 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -1410,9 +1410,7 @@ static int tsens_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(dev, - struct_size(priv, sensor, num_sensors), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, sensor, num_sensors); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 297724e81593fe..320ad33bd16070 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -334,8 +334,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev) }; void __iomem *base; - data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data), - GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct qoriq_tmu_data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/renesas/rcar_gen3_thermal.c b/drivers/thermal/renesas/rcar_gen3_thermal.c index 94804816e9e1f4..9c64cbc2ee6701 100644 --- a/drivers/thermal/renesas/rcar_gen3_thermal.c +++ b/drivers/thermal/renesas/rcar_gen3_thermal.c @@ -518,7 +518,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) unsigned int i; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -540,7 +540,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) if (!res) break; - tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); + tsc = devm_kzalloc_obj(dev, *tsc); if (!tsc) { ret = -ENOMEM; goto error_unregister; diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c index 9a9038671b04f1..af6d09a75bb61e 100644 --- a/drivers/thermal/renesas/rcar_thermal.c +++ b/drivers/thermal/renesas/rcar_thermal.c @@ -403,7 +403,7 @@ static int rcar_thermal_probe(struct platform_device *pdev) int idle = IDLE_INTERVAL; u32 enr_bits = 0; - common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); + common = devm_kzalloc_obj(dev, *common); if (!common) return -ENOMEM; @@ -459,7 +459,7 @@ static int rcar_thermal_probe(struct platform_device *pdev) if (!res) break; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) { ret = -ENOMEM; goto error_unregister; diff --git a/drivers/thermal/renesas/rzg2l_thermal.c b/drivers/thermal/renesas/rzg2l_thermal.c index d9afd061916797..90e2ba378a4bb5 100644 --- a/drivers/thermal/renesas/rzg2l_thermal.c +++ b/drivers/thermal/renesas/rzg2l_thermal.c @@ -164,7 +164,7 @@ static int rzg2l_thermal_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/renesas/rzg3e_thermal.c b/drivers/thermal/renesas/rzg3e_thermal.c index e806d130dc53df..bba1eecf19e403 100644 --- a/drivers/thermal/renesas/rzg3e_thermal.c +++ b/drivers/thermal/renesas/rzg3e_thermal.c @@ -402,7 +402,7 @@ static int rzg3e_thermal_probe(struct platform_device *pdev) struct clk *clk; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/renesas/rzg3s_thermal.c b/drivers/thermal/renesas/rzg3s_thermal.c index a8716da7fcd2f4..7582c770ba4a70 100644 --- a/drivers/thermal/renesas/rzg3s_thermal.c +++ b/drivers/thermal/renesas/rzg3s_thermal.c @@ -191,7 +191,7 @@ static int rzg3s_thermal_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 08891608baa66b..5e32703960ba7d 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1702,8 +1702,7 @@ static int rockchip_thermal_probe(struct platform_device *pdev) if (irq < 0) return -EINVAL; - thermal = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_thermal_data), - GFP_KERNEL); + thermal = devm_kzalloc_obj(&pdev->dev, struct rockchip_thermal_data); if (!thermal) return -ENOMEM; @@ -1713,8 +1712,8 @@ static int rockchip_thermal_probe(struct platform_device *pdev) if (!thermal->chip) return -EINVAL; - thermal->sensors = devm_kcalloc(&pdev->dev, thermal->chip->chn_num, - sizeof(*thermal->sensors), GFP_KERNEL); + thermal->sensors = devm_kzalloc_objs(&pdev->dev, *thermal->sensors, + thermal->chip->chn_num); if (!thermal->sensors) return -ENOMEM; diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c index f9802080acd7cb..b86dfa3c3ddb6e 100644 --- a/drivers/thermal/samsung/acpm-tmu.c +++ b/drivers/thermal/samsung/acpm-tmu.c @@ -416,9 +416,7 @@ static int acpm_tmu_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(acpm_handle), "Failed to get ACPM handle\n"); - priv = devm_kzalloc(dev, - struct_size(priv, sensors, data->num_sensor_groups), - GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, sensors, data->num_sensor_groups); if (!priv) return -ENOMEM; diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 56717bb50d607e..0f9e1cbf665238 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -1008,7 +1008,7 @@ static int exynos_tmu_probe(struct platform_device *pdev) struct exynos_tmu_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/thermal/spacemit/k1_tsensor.c b/drivers/thermal/spacemit/k1_tsensor.c index ef91453e553890..568ada885cff2b 100644 --- a/drivers/thermal/spacemit/k1_tsensor.c +++ b/drivers/thermal/spacemit/k1_tsensor.c @@ -239,7 +239,7 @@ static int k1_tsensor_probe(struct platform_device *pdev) struct clk *clk; int i, irq, ret; - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c index 5e3e9c1f32f8eb..4cf7c570be64c3 100644 --- a/drivers/thermal/spear_thermal.c +++ b/drivers/thermal/spear_thermal.c @@ -98,7 +98,7 @@ static int spear_thermal_probe(struct platform_device *pdev) return -EINVAL; } - stdev = devm_kzalloc(&pdev->dev, sizeof(*stdev), GFP_KERNEL); + stdev = devm_kzalloc_obj(&pdev->dev, *stdev); if (!stdev) return -ENOMEM; diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index b57277e2eac01b..4b1950f5e64294 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -344,7 +344,7 @@ static int sprd_thm_probe(struct platform_device *pdev) return -EINVAL; } - thm = devm_kzalloc(&pdev->dev, sizeof(*thm), GFP_KERNEL); + thm = devm_kzalloc_obj(&pdev->dev, *thm); if (!thm) return -ENOMEM; @@ -381,7 +381,7 @@ static int sprd_thm_probe(struct platform_device *pdev) return ret; for_each_child_of_node(np, sen_child) { - sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL); + sen = devm_kzalloc_obj(&pdev->dev, *sen); if (!sen) { ret = -ENOMEM; goto of_put; diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c index 1470ca519def46..d678d1e5fe759f 100644 --- a/drivers/thermal/st/st_thermal.c +++ b/drivers/thermal/st/st_thermal.c @@ -151,7 +151,7 @@ int st_thermal_register(struct platform_device *pdev, return -EINVAL; } - sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index 3290da7ab607ab..46d1db8618e93e 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -489,7 +489,7 @@ static int stm_thermal_probe(struct platform_device *pdev) return -EINVAL; } - sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&pdev->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 284684137c4343..b3f551e0288612 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -556,7 +556,7 @@ static int sun8i_ths_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret, irq; - tmdev = devm_kzalloc(dev, sizeof(*tmdev), GFP_KERNEL); + tmdev = devm_kzalloc_obj(dev, *tmdev); if (!tmdev) return -ENOMEM; diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c index f74acf13b24d23..fa179dfd76e31e 100644 --- a/drivers/thermal/tegra/soctherm.c +++ b/drivers/thermal/tegra/soctherm.c @@ -1561,7 +1561,7 @@ static int soctherm_thermtrips_parse(struct platform_device *pdev) n = min(max_num_prop, n); - tlb = devm_kcalloc(&pdev->dev, max_num_prop, sizeof(u32), GFP_KERNEL); + tlb = devm_kzalloc_objs(&pdev->dev, u32, max_num_prop); if (!tlb) return -ENOMEM; ret = of_property_read_u32_array(dev->of_node, "nvidia,thermtrips", @@ -2101,7 +2101,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev) if (soc->num_ttgs > TEGRA124_SOCTHERM_SENSOR_NUM) return -EINVAL; - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(&pdev->dev, *tegra); if (!tegra) return -ENOMEM; @@ -2148,9 +2148,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev) return PTR_ERR(tegra->clock_soctherm); } - tegra->calib = devm_kcalloc(&pdev->dev, - soc->num_tsensors, sizeof(u32), - GFP_KERNEL); + tegra->calib = devm_kzalloc_objs(&pdev->dev, u32, soc->num_tsensors); if (!tegra->calib) return -ENOMEM; @@ -2168,9 +2166,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev) return err; } - tegra->thermctl_tzs = devm_kcalloc(&pdev->dev, - soc->num_ttgs, sizeof(z), - GFP_KERNEL); + tegra->thermctl_tzs = devm_kzalloc_objs(&pdev->dev, z, soc->num_ttgs); if (!tegra->thermctl_tzs) return -ENOMEM; @@ -2189,8 +2185,8 @@ static int tegra_soctherm_probe(struct platform_device *pdev) soctherm_init(pdev); for (i = 0; i < soc->num_ttgs; ++i) { - struct tegra_thermctl_zone *zone = - devm_kzalloc(&pdev->dev, sizeof(*zone), GFP_KERNEL); + struct tegra_thermctl_zone *zone = devm_kzalloc_obj(&pdev->dev, + *zone); if (!zone) return -ENOMEM; diff --git a/drivers/thermal/tegra/tegra-bpmp-thermal.c b/drivers/thermal/tegra/tegra-bpmp-thermal.c index 997d77ce30d94c..5ac1f63e163ee6 100644 --- a/drivers/thermal/tegra/tegra-bpmp-thermal.c +++ b/drivers/thermal/tegra/tegra-bpmp-thermal.c @@ -230,7 +230,7 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev) else thermal_ops = &tegra_bpmp_of_thermal_ops_notrips; - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(&pdev->dev, *tegra); if (!tegra) return -ENOMEM; @@ -244,8 +244,8 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev) return err; } - tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones, - sizeof(*tegra->zones), GFP_KERNEL); + tegra->zones = devm_kzalloc_objs(&pdev->dev, *tegra->zones, + max_num_zones); if (!tegra->zones) return -ENOMEM; @@ -253,7 +253,7 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev) struct tegra_bpmp_thermal_zone *zone; int temp; - zone = devm_kzalloc(&pdev->dev, sizeof(*zone), GFP_KERNEL); + zone = devm_kzalloc_obj(&pdev->dev, *zone); if (!zone) return -ENOMEM; diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c index 10a5ab1fe1b928..c8f72280786611 100644 --- a/drivers/thermal/tegra/tegra30-tsensor.c +++ b/drivers/thermal/tegra/tegra30-tsensor.c @@ -539,7 +539,7 @@ static int tegra_tsensor_probe(struct platform_device *pdev) unsigned int i; int err, irq; - ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); + ts = devm_kzalloc_obj(&pdev->dev, *ts); if (!ts) return -ENOMEM; diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c index cfdb8e674dd270..c6a7a65aa6a624 100644 --- a/drivers/thermal/thermal-generic-adc.c +++ b/drivers/thermal/thermal-generic-adc.c @@ -149,9 +149,7 @@ static int gadc_thermal_read_linear_lookup_table(struct device *dev, return -EINVAL; } - gti->lookup_table = devm_kcalloc(dev, - ntable, sizeof(*gti->lookup_table), - GFP_KERNEL); + gti->lookup_table = devm_kzalloc_objs(dev, *gti->lookup_table, ntable); if (!gti->lookup_table) return -ENOMEM; @@ -179,7 +177,7 @@ static int gadc_thermal_probe(struct platform_device *pdev) return -ENODEV; } - gti = devm_kzalloc(dev, sizeof(*gti), GFP_KERNEL); + gti = devm_kzalloc_obj(dev, *gti); if (!gti) return -ENOMEM; diff --git a/drivers/thermal/thermal_mmio.c b/drivers/thermal/thermal_mmio.c index 6845756ad5e749..201b70b6be5870 100644 --- a/drivers/thermal/thermal_mmio.c +++ b/drivers/thermal/thermal_mmio.c @@ -46,7 +46,7 @@ static int thermal_mmio_probe(struct platform_device *pdev) int ret; int temperature; - sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc_obj(&pdev->dev, *sensor); if (!sensor) return -ENOMEM; diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index 457639be2b32ae..13b00bcc747280 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -830,7 +830,7 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) return ERR_PTR(-EINVAL); } - bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL); + bgp = devm_kzalloc_obj(&pdev->dev, *bgp); if (!bgp) return ERR_PTR(-ENOMEM); @@ -839,8 +839,8 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) bgp->conf = of_id->data; /* register shadow for context save and restore */ - bgp->regval = devm_kcalloc(&pdev->dev, bgp->conf->sensor_count, - sizeof(*bgp->regval), GFP_KERNEL); + bgp->regval = devm_kzalloc_objs(&pdev->dev, *bgp->regval, + bgp->conf->sensor_count); if (!bgp->regval) return ERR_PTR(-ENOMEM); diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 4bf3b2e0fc6821..6f6ca0444f5b40 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -144,7 +144,7 @@ static struct ti_thermal_data { struct ti_thermal_data *data; - data = devm_kzalloc(bgp->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(bgp->dev, *data); if (!data) { dev_err(bgp->dev, "kzalloc fail\n"); return NULL; diff --git a/drivers/thermal/uniphier_thermal.c b/drivers/thermal/uniphier_thermal.c index 1a04294effea29..be4474729b59cf 100644 --- a/drivers/thermal/uniphier_thermal.c +++ b/drivers/thermal/uniphier_thermal.c @@ -268,7 +268,7 @@ static int uniphier_tm_probe(struct platform_device *pdev) struct uniphier_tm_dev *tdev; int ret, irq; - tdev = devm_kzalloc(dev, sizeof(*tdev), GFP_KERNEL); + tdev = devm_kzalloc_obj(dev, *tdev); if (!tdev) return -ENOMEM; tdev->dev = dev; diff --git a/drivers/thunderbolt/debugfs.c b/drivers/thunderbolt/debugfs.c index ccefc5dd1ded7a..6a6875eb07ba47 100644 --- a/drivers/thunderbolt/debugfs.c +++ b/drivers/thunderbolt/debugfs.c @@ -1960,8 +1960,7 @@ static int port_clear_all_counters(struct tb_port *port) u32 *buf; int ret; - buf = kcalloc(COUNTER_SET_LEN * port->config.max_counters, sizeof(u32), - GFP_KERNEL); + buf = kzalloc_objs(u32, COUNTER_SET_LEN * port->config.max_counters); if (!buf) return -ENOMEM; diff --git a/drivers/thunderbolt/dma_test.c b/drivers/thunderbolt/dma_test.c index bcecb0edcb81a6..cfaa4b3365f201 100644 --- a/drivers/thunderbolt/dma_test.c +++ b/drivers/thunderbolt/dma_test.c @@ -641,7 +641,7 @@ static int dma_test_probe(struct tb_service *svc) struct tb_xdomain *xd = tb_service_parent(svc); struct dma_test *dt; - dt = devm_kzalloc(&svc->dev, sizeof(*dt), GFP_KERNEL); + dt = devm_kzalloc_obj(&svc->dev, *dt); if (!dt) return -ENOMEM; diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c index e99a3fcc4a2991..f54ab2189cf424 100644 --- a/drivers/thunderbolt/nhi.c +++ b/drivers/thunderbolt/nhi.c @@ -1321,13 +1321,10 @@ int nhi_probe(struct tb_nhi *nhi) nhi->hop_count = ioread32(nhi->iobase + REG_CAPS) & 0x3ff; dev_dbg(dev, "total paths: %d\n", nhi->hop_count); - nhi->tx_rings = devm_kcalloc(dev, nhi->hop_count, - sizeof(*nhi->tx_rings), GFP_KERNEL); - nhi->rx_rings = devm_kcalloc(dev, nhi->hop_count, - sizeof(*nhi->rx_rings), GFP_KERNEL); - nhi->interrupt_mask = devm_kcalloc(dev, RING_INTERRUPT_REG_COUNT(nhi), - sizeof(*nhi->interrupt_mask), - GFP_KERNEL); + nhi->tx_rings = devm_kzalloc_objs(dev, *nhi->tx_rings, nhi->hop_count); + nhi->rx_rings = devm_kzalloc_objs(dev, *nhi->rx_rings, nhi->hop_count); + nhi->interrupt_mask = devm_kzalloc_objs(dev, *nhi->interrupt_mask, + RING_INTERRUPT_REG_COUNT(nhi)); if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask) return -ENOMEM; diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c index 4408229d8ac7b6..9fe2ef43d8ac8a 100644 --- a/drivers/thunderbolt/pci.c +++ b/drivers/thunderbolt/pci.c @@ -570,7 +570,7 @@ static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (res) return dev_err_probe(dev, res, "cannot enable PCI device, aborting\n"); - nhi_pci = devm_kzalloc(dev, sizeof(*nhi_pci), GFP_KERNEL); + nhi_pci = devm_kzalloc_obj(dev, *nhi_pci); if (!nhi_pci) return -ENOMEM; diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c index b187a60663f513..45e26833c95307 100644 --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c @@ -398,7 +398,7 @@ static int tb_xdp_properties_request(struct tb_ctl *ctl, u64 route, goto err; } - data = kcalloc(data_len, sizeof(u32), GFP_KERNEL); + data = kzalloc_objs(u32, data_len); if (!data) { ret = -ENOMEM; goto err; @@ -710,7 +710,7 @@ static void update_property_block(struct tb_xdomain *xd) } block_len = ret; - block = kcalloc(block_len, sizeof(*block), GFP_KERNEL); + block = kzalloc_objs(*block, block_len); if (!block) { tb_property_free_dir(dir); goto out_unlock; diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c index ba7690c3e15e7e..4a41a5c3d7dde0 100644 --- a/drivers/tty/mips_ejtag_fdc.c +++ b/drivers/tty/mips_ejtag_fdc.c @@ -891,7 +891,7 @@ static int mips_ejtag_fdc_tty_probe(struct mips_cdmm_device *dev) struct tty_driver *driver; unsigned int cfg, tx_fifo; - priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, *priv); if (!priv) return -ENOMEM; priv->cpu = dev->cpu; diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 94677fec685e57..281c599a12f2e8 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -1742,8 +1742,7 @@ static int mxser_probe(struct pci_dev *pdev, goto err; } - brd = devm_kzalloc(&pdev->dev, struct_size(brd, ports, nports), - GFP_KERNEL); + brd = devm_kzalloc_flex(&pdev->dev, *brd, ports, nports); if (!brd) goto err; diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c index c8dc87f6886c1f..452bef82bec2a2 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -426,7 +426,7 @@ static int aspeed_vuart_probe(struct platform_device *pdev) np = pdev->dev.of_node; - vuart = devm_kzalloc(&pdev->dev, sizeof(*vuart), GFP_KERNEL); + vuart = devm_kzalloc_obj(&pdev->dev, *vuart); if (!vuart) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_bcm2835aux.c b/drivers/tty/serial/8250/8250_bcm2835aux.c index b842dba3059d1b..8624c46ade6459 100644 --- a/drivers/tty/serial/8250/8250_bcm2835aux.c +++ b/drivers/tty/serial/8250/8250_bcm2835aux.c @@ -244,7 +244,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) int ret; /* allocate the custom structure */ - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/8250/8250_bcm7271.c index 974d9af146a152..65df87a65a469f 100644 --- a/drivers/tty/serial/8250/8250_bcm7271.c +++ b/drivers/tty/serial/8250/8250_bcm7271.c @@ -966,8 +966,7 @@ static int brcmuart_probe(struct platform_device *pdev) "uart", "dma_rx", "dma_tx", "dma_intr2", "dma_arb" }; - priv = devm_kzalloc(dev, sizeof(struct brcmuart_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct brcmuart_priv); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index eca02e8bd6d13e..a5e893e459593a 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -653,7 +653,7 @@ static int dw8250_probe(struct platform_device *pdev) p->set_termios = dw8250_set_termios; p->set_divisor = dw8250_set_divisor; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c index 57847c5bd2fcf6..2737a09cf8be19 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -1461,7 +1461,7 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) if (nr_ports == 0) return dev_err_probe(&pcidev->dev, -ENODEV, "failed to get number of ports\n"); - priv = devm_kzalloc(&pcidev->dev, struct_size(priv, uport, nr_ports), GFP_KERNEL); + priv = devm_kzalloc_flex(&pcidev->dev, *priv, uport, nr_ports); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c index 976c5748905c12..b2843c664b9d6f 100644 --- a/drivers/tty/serial/8250/8250_fintek.c +++ b/drivers/tty/serial/8250/8250_fintek.c @@ -471,7 +471,7 @@ int fintek_8250_probe(struct uart_8250_port *uart) if (probe_setup_port(&probe_data, uart)) return -ENODEV; - pdata = devm_kzalloc(uart->port.dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(uart->port.dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_ingenic.c b/drivers/tty/serial/8250/8250_ingenic.c index 0cdadacd701950..bb8aa3ac44e60f 100644 --- a/drivers/tty/serial/8250/8250_ingenic.c +++ b/drivers/tty/serial/8250/8250_ingenic.c @@ -249,7 +249,7 @@ static int ingenic_uart_probe(struct platform_device *pdev) return -EINVAL; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_keba.c b/drivers/tty/serial/8250/8250_keba.c index c53ca05a57d73d..6c44f3bc853e59 100644 --- a/drivers/tty/serial/8250/8250_keba.c +++ b/drivers/tty/serial/8250/8250_keba.c @@ -175,7 +175,7 @@ static int kuart_probe(struct auxiliary_device *auxdev, struct resource res; struct kuart *kuart; - kuart = devm_kzalloc(dev, sizeof(*kuart), GFP_KERNEL); + kuart = devm_kzalloc_obj(dev, *kuart); if (!kuart) return -ENOMEM; kuart->auxdev = container_of(auxdev, struct keba_uart_auxdev, auxdev); diff --git a/drivers/tty/serial/8250/8250_loongson.c b/drivers/tty/serial/8250/8250_loongson.c index 6d06ed28382dfd..eadde70417f944 100644 --- a/drivers/tty/serial/8250/8250_loongson.c +++ b/drivers/tty/serial/8250/8250_loongson.c @@ -112,7 +112,7 @@ static int loongson_uart_probe(struct platform_device *pdev) struct uart_port *port; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_lpc18xx.c b/drivers/tty/serial/8250/8250_lpc18xx.c index 5d4d4366e711e0..5fe5027567d35a 100644 --- a/drivers/tty/serial/8250/8250_lpc18xx.c +++ b/drivers/tty/serial/8250/8250_lpc18xx.c @@ -108,7 +108,7 @@ static int lpc18xx_serial_probe(struct platform_device *pdev) if (!uart.port.membase) return -ENOMEM; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c index f1b4b975571a0b..f94a54cc57ca93 100644 --- a/drivers/tty/serial/8250/8250_lpss.c +++ b/drivers/tty/serial/8250/8250_lpss.c @@ -320,7 +320,7 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id) pci_set_master(pdev); - lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL); + lpss = devm_kzalloc_obj(&pdev->dev, *lpss); if (!lpss) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_men_mcb.c b/drivers/tty/serial/8250/8250_men_mcb.c index 1f34e58aaeaf7e..94264d11e937bb 100644 --- a/drivers/tty/serial/8250/8250_men_mcb.c +++ b/drivers/tty/serial/8250/8250_men_mcb.c @@ -189,9 +189,7 @@ static int serial_8250_men_mcb_probe(struct mcb_device *mdev, if (mem == NULL) return -ENXIO; - data = devm_kzalloc(&mdev->dev, - sizeof(struct serial_8250_men_mcb_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&mdev->dev, struct serial_8250_men_mcb_data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_mid.c b/drivers/tty/serial/8250/8250_mid.c index 44b43163df511b..df721418e97efd 100644 --- a/drivers/tty/serial/8250/8250_mid.c +++ b/drivers/tty/serial/8250/8250_mid.c @@ -269,11 +269,11 @@ static int mid8250_dma_setup(struct mid8250 *mid, struct uart_8250_port *port) if (!mid->dma_dev) return 0; - rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL); + rx_param = devm_kzalloc_obj(dev, *rx_param); if (!rx_param) return -ENOMEM; - tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL); + tx_param = devm_kzalloc_obj(dev, *tx_param); if (!tx_param) return -ENOMEM; @@ -304,7 +304,7 @@ static int mid8250_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) return ret; - mid = devm_kzalloc(&pdev->dev, sizeof(*mid), GFP_KERNEL); + mid = devm_kzalloc_obj(&pdev->dev, *mid); if (!mid) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c index d1fb917b762a19..4e16cfb05a85d7 100644 --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -503,8 +503,7 @@ static int mtk8250_probe_of(struct platform_device *pdev, struct uart_port *p, #ifdef CONFIG_SERIAL_8250_DMA dmacnt = of_property_count_strings(pdev->dev.of_node, "dma-names"); if (dmacnt == 2) { - data->dma = devm_kzalloc(&pdev->dev, sizeof(*data->dma), - GFP_KERNEL); + data->dma = devm_kzalloc_obj(&pdev->dev, *data->dma); if (!data->dma) return -ENOMEM; @@ -541,7 +540,7 @@ static int mtk8250_probe(struct platform_device *pdev) if (!uart.port.membase) return -ENOMEM; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c index 4935a5d1c1a3fc..a4e45e3923ae7c 100644 --- a/drivers/tty/serial/8250/8250_mxpcie.c +++ b/drivers/tty/serial/8250/8250_mxpcie.c @@ -528,7 +528,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id num_ports = mxpcie8250_get_nports(device); - priv = devm_kzalloc(dev, struct_size(priv, port, num_ports), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, port, num_ports); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_ni.c b/drivers/tty/serial/8250/8250_ni.c index 509c1814cc8725..60775fae479ad5 100644 --- a/drivers/tty/serial/8250/8250_ni.c +++ b/drivers/tty/serial/8250/8250_ni.c @@ -289,7 +289,7 @@ static int ni16550_probe(struct platform_device *pdev) if (!uart) return -ENOMEM; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 29a203ed93fd8f..ed0b8f12533270 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -1425,7 +1425,7 @@ static int omap8250_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index 1dda63be6b8935..c34eb2dd171688 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c @@ -1759,7 +1759,7 @@ static int pci_fintek_f815xxa_setup(struct serial_private *priv, struct pci_dev *pdev = priv->dev; struct f815xxa_data *data; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8250/8250_pci1xxxx.c index af4c5c745fa9e9..72fdb1bac2eb69 100644 --- a/drivers/tty/serial/8250/8250_pci1xxxx.c +++ b/drivers/tty/serial/8250/8250_pci1xxxx.c @@ -778,7 +778,7 @@ static int pci1xxxx_serial_probe(struct pci_dev *pdev, nr_ports = pci1xxxx_get_num_ports(pdev); - priv = devm_kzalloc(dev, struct_size(priv, uport, nr_ports), GFP_KERNEL); + priv = devm_kzalloc_flex(dev, *priv, uport, nr_ports); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_pericom.c b/drivers/tty/serial/8250/8250_pericom.c index bbbf48c6d07d09..199d69fa828f22 100644 --- a/drivers/tty/serial/8250/8250_pericom.c +++ b/drivers/tty/serial/8250/8250_pericom.c @@ -103,7 +103,7 @@ static int pericom8250_probe(struct pci_dev *pdev, const struct pci_device_id *i else nr = 1; - pericom = devm_kzalloc(&pdev->dev, struct_size(pericom, uport, nr), GFP_KERNEL); + pericom = devm_kzalloc_flex(&pdev->dev, *pericom, uport, nr); if (!pericom) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_pxa.c b/drivers/tty/serial/8250/8250_pxa.c index a56aa5fec563d8..0fca8ef2b3cff0 100644 --- a/drivers/tty/serial/8250/8250_pxa.c +++ b/drivers/tty/serial/8250/8250_pxa.c @@ -99,7 +99,7 @@ static int serial_pxa_probe(struct platform_device *pdev) if (!mmres) return -ENODEV; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_tegra.c b/drivers/tty/serial/8250/8250_tegra.c index 2f6b822f79a8d6..1e616b6d1a1ace 100644 --- a/drivers/tty/serial/8250/8250_tegra.c +++ b/drivers/tty/serial/8250/8250_tegra.c @@ -49,7 +49,7 @@ static int tegra_uart_probe(struct platform_device *pdev) struct resource *res; int ret; - uart = devm_kzalloc(&pdev->dev, sizeof(*uart), GFP_KERNEL); + uart = devm_kzalloc_obj(&pdev->dev, *uart); if (!uart) return -ENOMEM; diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8250/8250_uniphier.c index a8ee45a0d41e76..4d131c323e4437 100644 --- a/drivers/tty/serial/8250/8250_uniphier.c +++ b/drivers/tty/serial/8250/8250_uniphier.c @@ -173,7 +173,7 @@ static int uniphier_uart_probe(struct platform_device *pdev) if (!membase) return -ENOMEM; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c index c3a7fad02ac9b3..362620b7f6ffdf 100644 --- a/drivers/tty/serial/amba-pl010.c +++ b/drivers/tty/serial/amba-pl010.c @@ -672,8 +672,7 @@ static int pl010_probe(struct amba_device *dev, const struct amba_id *id) if (i == ARRAY_SIZE(amba_ports)) return -EBUSY; - uap = devm_kzalloc(&dev->dev, sizeof(struct uart_amba_port), - GFP_KERNEL); + uap = devm_kzalloc_obj(&dev->dev, struct uart_amba_port); if (!uap) return -ENOMEM; diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index e6f652905ca6f1..7b1f99395f6c75 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -3120,8 +3120,7 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id) if (portnr < 0) return portnr; - uap = devm_kzalloc(&dev->dev, sizeof(struct uart_amba_port), - GFP_KERNEL); + uap = devm_kzalloc_obj(&dev->dev, struct uart_amba_port); if (!uap) return -ENOMEM; @@ -3266,8 +3265,7 @@ static int sbsa_uart_probe(struct platform_device *pdev) if (portnr < 0) return portnr; - uap = devm_kzalloc(&pdev->dev, sizeof(struct uart_amba_port), - GFP_KERNEL); + uap = devm_kzalloc_obj(&pdev->dev, struct uart_amba_port); if (!uap) return -ENOMEM; diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_uart.c index 5b491db9d2fc01..f9c2e5c8b3246f 100644 --- a/drivers/tty/serial/ar933x_uart.c +++ b/drivers/tty/serial/ar933x_uart.c @@ -790,8 +790,7 @@ static int ar933x_uart_probe(struct platform_device *pdev) if (irq < 0) return irq; - up = devm_kzalloc(&pdev->dev, sizeof(struct ar933x_uart_port), - GFP_KERNEL); + up = devm_kzalloc_obj(&pdev->dev, struct ar933x_uart_port); if (!up) return -ENOMEM; diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c index 83186bf5000272..f0f19481ce1ef4 100644 --- a/drivers/tty/serial/clps711x.c +++ b/drivers/tty/serial/clps711x.c @@ -443,7 +443,7 @@ static int uart_clps711x_probe(struct platform_device *pdev) struct clk *uart_clk; int irq, ret; - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, *s); if (!s) return -ENOMEM; diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c index d2482df5cb9b46..0c64aeb79e796a 100644 --- a/drivers/tty/serial/digicolor-usart.c +++ b/drivers/tty/serial/digicolor-usart.c @@ -463,7 +463,7 @@ static int digicolor_uart_probe(struct platform_device *pdev) if (index < 0 || index >= DIGICOLOR_USART_NR) return -EINVAL; - dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(&pdev->dev, *dp); if (!dp) return -ENOMEM; diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c index e70a56de1fcedb..62cae6fd5b3c06 100644 --- a/drivers/tty/serial/fsl_linflexuart.c +++ b/drivers/tty/serial/fsl_linflexuart.c @@ -811,7 +811,7 @@ static int linflex_probe(struct platform_device *pdev) struct resource *res; int ret; - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); + sport = devm_kzalloc_obj(&pdev->dev, *sport); if (!sport) return -ENOMEM; diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index c8575c9652035e..6ccc6a8b653b05 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -2878,7 +2878,7 @@ static int lpuart_probe(struct platform_device *pdev) irq_handler_t handler; int ret; - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); + sport = devm_kzalloc_obj(&pdev->dev, *sport); if (!sport) return -ENOMEM; diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 986fefb45c6322..256d85e398d13f 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -2421,7 +2421,7 @@ static int imx_uart_probe(struct platform_device *pdev) struct resource *res; int txirq, rxirq, rtsirq; - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); + sport = devm_kzalloc_obj(&pdev->dev, *sport); if (!sport) return -ENOMEM; diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c index 62cd9e0bb377b8..fc75476c0935ec 100644 --- a/drivers/tty/serial/lantiq.c +++ b/drivers/tty/serial/lantiq.c @@ -817,8 +817,7 @@ static int lqasc_probe(struct platform_device *pdev) return -ENODEV; } - ltq_port = devm_kzalloc(&pdev->dev, sizeof(struct ltq_uart_port), - GFP_KERNEL); + ltq_port = devm_kzalloc_obj(&pdev->dev, struct ltq_uart_port); if (!ltq_port) return -ENOMEM; diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index 6429e8f11f36fc..021c69f473b3be 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -284,7 +284,7 @@ static int liteuart_probe(struct platform_device *pdev) struct xa_limit limit; int dev_id, ret; - uart = devm_kzalloc(&pdev->dev, sizeof(struct liteuart_port), GFP_KERNEL); + uart = devm_kzalloc_obj(&pdev->dev, struct liteuart_port); if (!uart) return -ENOMEM; diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index a0ed70185555ee..de8a1f05cf30ed 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -1871,7 +1871,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty return PTR_ERR(regmaps[i]); /* Alloc port structure */ - s = devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL); + s = devm_kzalloc_flex(dev, *s, p, devtype->nr); if (!s) return -ENOMEM; diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c index 9138fa29d301b1..861b783cec3d67 100644 --- a/drivers/tty/serial/men_z135_uart.c +++ b/drivers/tty/serial/men_z135_uart.c @@ -808,7 +808,7 @@ static int men_z135_probe(struct mcb_device *mdev, dev = &mdev->dev; - uart = devm_kzalloc(dev, sizeof(struct men_z135_port), GFP_KERNEL); + uart = devm_kzalloc_obj(dev, struct men_z135_port); if (!uart) return -ENOMEM; diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index a6cb2a535f9dcc..03faa39de51aa7 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -736,7 +736,7 @@ static int meson_uart_probe(struct platform_device *pdev) "port %d already allocated\n", pdev->id); } - port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); + port = devm_kzalloc_obj(&pdev->dev, struct uart_port); if (!port) return -ENOMEM; diff --git a/drivers/tty/serial/mps2-uart.c b/drivers/tty/serial/mps2-uart.c index 2a4c09f3a83406..fdd4984080e968 100644 --- a/drivers/tty/serial/mps2-uart.c +++ b/drivers/tty/serial/mps2-uart.c @@ -579,7 +579,7 @@ static int mps2_serial_probe(struct platform_device *pdev) struct mps2_uart_port *mps_port; int ret; - mps_port = devm_kzalloc(&pdev->dev, sizeof(struct mps2_uart_port), GFP_KERNEL); + mps_port = devm_kzalloc_obj(&pdev->dev, struct mps2_uart_port); if (!mps_port) return -ENOMEM; diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c index 33ea496c93b293..8a61517d81f21e 100644 --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -913,8 +913,7 @@ static int mvebu_uart_probe(struct platform_device *pdev) return PTR_ERR(port->membase); port->mapbase = reg->start; - mvuart = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_uart), - GFP_KERNEL); + mvuart = devm_kzalloc_obj(&pdev->dev, struct mvebu_uart); if (!mvuart) return -ENOMEM; @@ -1330,9 +1329,7 @@ static int mvebu_uart_clock_probe(struct platform_device *pdev) BUILD_BUG_ON(ARRAY_SIZE(parent_clk_names) != ARRAY_SIZE(uart_clock_base->parent_rates)); - uart_clock_base = devm_kzalloc(dev, - sizeof(*uart_clock_base), - GFP_KERNEL); + uart_clock_base = devm_kzalloc_obj(dev, *uart_clock_base); if (!uart_clock_base) return -ENOMEM; @@ -1374,10 +1371,8 @@ static int mvebu_uart_clock_probe(struct platform_device *pdev) if (!uart_clock_base->reg2) return -ENOMEM; - hw_clk_data = devm_kzalloc(dev, - struct_size(hw_clk_data, hws, - ARRAY_SIZE(uart_clk_names)), - GFP_KERNEL); + hw_clk_data = devm_kzalloc_flex(dev, *hw_clk_data, hws, + ARRAY_SIZE(uart_clk_names)); if (!hw_clk_data) return -ENOMEM; diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 697318dbb146bd..211cf85f38c59d 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -1575,7 +1575,7 @@ static int mxs_auart_probe(struct platform_device *pdev) int ret, irq; struct resource *r; - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, *s); if (!s) return -ENOMEM; diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index a689d190940cf6..6d60084ad341b5 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -1466,7 +1466,7 @@ static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) { struct omap_uart_port_info *omap_up_info; - omap_up_info = devm_kzalloc(dev, sizeof(*omap_up_info), GFP_KERNEL); + omap_up_info = devm_kzalloc_obj(dev, *omap_up_info); if (!omap_up_info) return NULL; /* out of memory */ @@ -1560,7 +1560,7 @@ static int serial_omap_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL); + up = devm_kzalloc_obj(&pdev->dev, *up); if (!up) return -ENOMEM; diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c index 0542882cfbbe45..863363ddad00e4 100644 --- a/drivers/tty/serial/owl-uart.c +++ b/drivers/tty/serial/owl-uart.c @@ -676,7 +676,7 @@ static int owl_uart_probe(struct platform_device *pdev) return -EBUSY; } - owl_port = devm_kzalloc(&pdev->dev, sizeof(*owl_port), GFP_KERNEL); + owl_port = devm_kzalloc_obj(&pdev->dev, *owl_port); if (!owl_port) return -ENOMEM; diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c index 8407f85776c07a..a645b646bf8d6a 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -877,7 +877,7 @@ static int pic32_uart_probe(struct platform_device *pdev) if (!res_mem) return -EINVAL; - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); + sport = devm_kzalloc_obj(&pdev->dev, *sport); if (!sport) return -ENOMEM; diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index bfdc155c128da7..8ea43b29491574 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -287,7 +287,7 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console, } else { int max_alias_num = of_alias_get_highest_id("serial"); - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return ERR_PTR(-ENOMEM); diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c index 87fa30d6868784..9da58ffa02d545 100644 --- a/drivers/tty/serial/rda-uart.c +++ b/drivers/tty/serial/rda-uart.c @@ -729,7 +729,7 @@ static int rda_uart_probe(struct platform_device *pdev) return -EBUSY; } - rda_port = devm_kzalloc(&pdev->dev, sizeof(*rda_port), GFP_KERNEL); + rda_port = devm_kzalloc_obj(&pdev->dev, *rda_port); if (!rda_port) return -ENOMEM; diff --git a/drivers/tty/serial/rp2.c b/drivers/tty/serial/rp2.c index 51e81ec0ffdbad..158b06424b5672 100644 --- a/drivers/tty/serial/rp2.c +++ b/drivers/tty/serial/rp2.c @@ -700,7 +700,7 @@ static int rp2_probe(struct pci_dev *pdev, struct rp2_uart_port *ports; int rc; - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); if (!card) return -ENOMEM; pci_set_drvdata(pdev, card); @@ -734,8 +734,7 @@ static int rp2_probe(struct pci_dev *pdev, rp2_init_card(card); - ports = devm_kcalloc(&pdev->dev, card->n_ports, sizeof(*ports), - GFP_KERNEL); + ports = devm_kzalloc_objs(&pdev->dev, *ports, card->n_ports); if (!ports) return -ENOMEM; card->ports = ports; diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index 640f85e2d636b1..738536014742eb 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1860,9 +1860,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, */ if (platdev->dev.of_node && of_find_property(platdev->dev.of_node, "dmas", NULL)) { - ourport->dma = devm_kzalloc(port->dev, - sizeof(*ourport->dma), - GFP_KERNEL); + ourport->dma = devm_kzalloc_obj(port->dev, *ourport->dma); if (!ourport->dma) { ret = -ENOMEM; goto err; diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index fba58855959574..dbf38825a78ce9 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -1593,7 +1593,7 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, return -EPROBE_DEFER; /* Alloc port structure */ - s = devm_kzalloc(dev, struct_size(s, p, devtype->nr_uart), GFP_KERNEL); + s = devm_kzalloc_flex(dev, *s, p, devtype->nr_uart); if (!s) return -ENOMEM; diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c index cb31e3aceb623f..b8f81dd6e7dbda 100644 --- a/drivers/tty/serial/sccnxp.c +++ b/drivers/tty/serial/sccnxp.c @@ -893,7 +893,7 @@ static int sccnxp_probe(struct platform_device *pdev) if (IS_ERR(membase)) return PTR_ERR(membase); - s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL); + s = devm_kzalloc_obj(&pdev->dev, struct sccnxp_port); if (!s) { dev_err(&pdev->dev, "Error allocating port structure\n"); return -ENOMEM; diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c index b0fc4ae3686f8d..e93873a1d1c63e 100644 --- a/drivers/tty/serial/serial-tegra.c +++ b/drivers/tty/serial/serial-tegra.c @@ -1582,7 +1582,7 @@ static int tegra_uart_probe(struct platform_device *pdev) return -ENODEV; } - tup = devm_kzalloc(&pdev->dev, sizeof(*tup), GFP_KERNEL); + tup = devm_kzalloc_obj(&pdev->dev, *tup); if (!tup) { dev_err(&pdev->dev, "Failed to allocate memory for tup\n"); return -ENOMEM; diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index dff13a9f261453..4399ae3b70aeb7 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -140,7 +140,7 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) struct mctrl_gpios *gpios; enum mctrl_gpio_idx i; - gpios = devm_kzalloc(dev, sizeof(*gpios), GFP_KERNEL); + gpios = devm_kzalloc_obj(dev, *gpios); if (!gpios) return ERR_PTR(-ENOMEM); diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index bd58bbfa65aa7a..abaab62971b0a6 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3757,7 +3757,7 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev, return ERR_PTR(ret); } - p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL); + p = devm_kzalloc_obj(&pdev->dev, struct plat_sci_port); if (!p) return ERR_PTR(-ENOMEM); diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c index c720e9888416b0..892b498540ac49 100644 --- a/drivers/tty/serial/sifive.c +++ b/drivers/tty/serial/sifive.c @@ -1005,7 +1005,7 @@ static int sifive_serial_probe(struct platform_device *pdev) } #endif - ssp = devm_kzalloc(&pdev->dev, sizeof(*ssp), GFP_KERNEL); + ssp = devm_kzalloc_obj(&pdev->dev, *ssp); if (!ssp) return -ENOMEM; diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c index 3fdf5939a62c14..7bca7151344e4a 100644 --- a/drivers/tty/serial/sprd_serial.c +++ b/drivers/tty/serial/sprd_serial.c @@ -1186,7 +1186,7 @@ static int sprd_probe(struct platform_device *pdev) return -EINVAL; } - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); + sport = devm_kzalloc_obj(&pdev->dev, *sport); if (!sport) return -ENOMEM; diff --git a/drivers/tty/serial/sunplus-uart.c b/drivers/tty/serial/sunplus-uart.c index 38deee571b0d08..62e516bdf6b8b3 100644 --- a/drivers/tty/serial/sunplus-uart.c +++ b/drivers/tty/serial/sunplus-uart.c @@ -595,7 +595,7 @@ static int sunplus_uart_probe(struct platform_device *pdev) if (pdev->id < 0 || pdev->id >= SUP_UART_NR) return -EINVAL; - sup = devm_kzalloc(&pdev->dev, sizeof(*sup), GFP_KERNEL); + sup = devm_kzalloc_obj(&pdev->dev, *sup); if (!sup) return -ENOMEM; diff --git a/drivers/tty/serial/tegra-tcu.c b/drivers/tty/serial/tegra-tcu.c index 077023ce184257..6c45de1aad8c82 100644 --- a/drivers/tty/serial/tegra-tcu.c +++ b/drivers/tty/serial/tegra-tcu.c @@ -182,7 +182,7 @@ static int tegra_tcu_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int err; - tcu = devm_kzalloc(dev, sizeof(*tcu), GFP_KERNEL); + tcu = devm_kzalloc_obj(dev, *tcu); if (!tcu) return -ENOMEM; diff --git a/drivers/tty/serial/tegra-utc.c b/drivers/tty/serial/tegra-utc.c index 3d43c11824caa9..8b38f4f18554f6 100644 --- a/drivers/tty/serial/tegra-utc.c +++ b/drivers/tty/serial/tegra-utc.c @@ -537,7 +537,7 @@ static int tegra_utc_probe(struct platform_device *pdev) struct tegra_utc_port *tup; int ret; - tup = devm_kzalloc(dev, sizeof(*tup), GFP_KERNEL); + tup = devm_kzalloc_obj(dev, *tup); if (!tup) return -ENOMEM; diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c index 6240c3d4dfd798..b9a14dc2f2fdf2 100644 --- a/drivers/tty/serial/uartlite.c +++ b/drivers/tty/serial/uartlite.c @@ -783,8 +783,7 @@ static int ulite_probe(struct platform_device *pdev) int irq, ret; int id = pdev->id; - pdata = devm_kzalloc(&pdev->dev, sizeof(struct uartlite_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, struct uartlite_data); if (!pdata) return -ENOMEM; diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index fc6fdc751b1675..a7f167a734160f 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -638,8 +638,7 @@ static int vt8500_serial_probe(struct platform_device *pdev) return -EBUSY; } - vt8500_port = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_port), - GFP_KERNEL); + vt8500_port = devm_kzalloc_obj(&pdev->dev, struct vt8500_port); if (!vt8500_port) return -ENOMEM; diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index a072b75dbaf232..e8c4b1fa7658b6 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1646,11 +1646,10 @@ static int cdns_uart_probe(struct platform_device *pdev) struct cdns_uart *cdns_uart_data; const struct of_device_id *match; - cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), - GFP_KERNEL); + cdns_uart_data = devm_kzalloc_obj(&pdev->dev, *cdns_uart_data); if (!cdns_uart_data) return -ENOMEM; - port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(&pdev->dev, *port); if (!port) return -ENOMEM; diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index 7d564341a7eb7c..111a5631ab8cd7 100644 --- a/drivers/tty/vt/consolemap.c +++ b/drivers/tty/vt/consolemap.c @@ -260,8 +260,8 @@ static void set_inverse_trans_unicode(struct uni_pagedict *dict) inv = dict->inverse_trans_unicode; if (!inv) { - inv = dict->inverse_trans_unicode = kmalloc_array(MAX_GLYPH, - sizeof(*inv), GFP_KERNEL); + inv = dict->inverse_trans_unicode = kmalloc_objs(*inv, + MAX_GLYPH); if (!inv) return; } @@ -511,8 +511,7 @@ con_insert_unipair(struct uni_pagedict *p, u_short unicode, u_short fontpos) n = UNI_DIR(unicode); dir = p->uni_pgdir[n]; if (!dir) { - dir = p->uni_pgdir[n] = kcalloc(UNI_DIR_ROWS, sizeof(*dir), - GFP_KERNEL); + dir = p->uni_pgdir[n] = kzalloc_objs(*dir, UNI_DIR_ROWS); if (!dir) return -ENOMEM; } @@ -520,8 +519,7 @@ con_insert_unipair(struct uni_pagedict *p, u_short unicode, u_short fontpos) n = UNI_ROW(unicode); row = dir[n]; if (!row) { - row = dir[n] = kmalloc_array(UNI_ROW_GLYPHS, sizeof(*row), - GFP_KERNEL); + row = dir[n] = kmalloc_objs(*row, UNI_ROW_GLYPHS); if (!row) return -ENOMEM; /* No glyphs for the characters (yet) */ @@ -776,8 +774,7 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct uni_pagedict *dict; unsigned int d, r, g; - struct unipair *unilist __free(kvfree) = kvmalloc_objs(*unilist, ct, - GFP_KERNEL); + struct unipair *unilist __free(kvfree) = kvmalloc_objs(*unilist, ct); if (!unilist) return -ENOMEM; diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index ef4a19aeb3ce88..d59d51dafa55ef 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -1731,8 +1731,8 @@ static int vt_do_kdgkbdiacr(void __user *udp) struct kbdiacrs __user *a = udp; int i, asize; - struct kbdiacr __free(kfree) *dia = kmalloc_array(MAX_DIACR, sizeof(struct kbdiacr), - GFP_KERNEL); + struct kbdiacr __free(kfree) *dia = kmalloc_objs(struct kbdiacr, + MAX_DIACR); if (!dia) return -ENOMEM; @@ -1759,8 +1759,7 @@ static int vt_do_kdgkbdiacruc(void __user *udp) struct kbdiacrsuc __user *a = udp; int asize; - void __free(kfree) *buf = kmalloc_array(MAX_DIACR, sizeof(struct kbdiacruc), - GFP_KERNEL); + void __free(kfree) *buf = kmalloc_objs(struct kbdiacruc, MAX_DIACR); if (buf == NULL) return -ENOMEM; diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c index 65f2d71cf073bf..75667333764802 100644 --- a/drivers/ufs/core/ufs-rpmb.c +++ b/drivers/ufs/core/ufs-rpmb.c @@ -189,7 +189,7 @@ int ufs_rpmb_probe(struct ufs_hba *hba) if (!cap) continue; - ufs_rpmb = devm_kzalloc(hba->dev, sizeof(*ufs_rpmb), GFP_KERNEL); + ufs_rpmb = devm_kzalloc_obj(hba->dev, *ufs_rpmb); if (!ufs_rpmb) { ret = -ENOMEM; goto err_out; diff --git a/drivers/ufs/core/ufs-txeq.c b/drivers/ufs/core/ufs-txeq.c index 6192512e29ded4..428a1895dc63e9 100644 --- a/drivers/ufs/core/ufs-txeq.c +++ b/drivers/ufs/core/ufs-txeq.c @@ -1239,9 +1239,8 @@ static int ufshcd_tx_eqtr(struct ufs_hba *hba, noio_flag = memalloc_noio_save(); if (!params->eqtr_record) { - params->eqtr_record = devm_kzalloc(hba->dev, - sizeof(*params->eqtr_record), - GFP_KERNEL); + params->eqtr_record = devm_kzalloc_obj(hba->dev, + *params->eqtr_record); if (!params->eqtr_record) { ret = -ENOMEM; goto out_noio_restore; diff --git a/drivers/ufs/core/ufshcd-crypto.c b/drivers/ufs/core/ufshcd-crypto.c index 9e63a9d3cb7e2c..dec59551169bb1 100644 --- a/drivers/ufs/core/ufshcd-crypto.c +++ b/drivers/ufs/core/ufshcd-crypto.c @@ -168,8 +168,8 @@ int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) hba->crypto_cfg_register = (u32)hba->crypto_capabilities.config_array_ptr * 0x100; hba->crypto_cap_array = - devm_kcalloc(hba->dev, hba->crypto_capabilities.num_crypto_cap, - sizeof(hba->crypto_cap_array[0]), GFP_KERNEL); + devm_kzalloc_objs(hba->dev, hba->crypto_cap_array[0], + hba->crypto_capabilities.num_crypto_cap); if (!hba->crypto_cap_array) { err = -ENOMEM; goto out; diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index ee643830a57a2f..3c28bc67c65f1a 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5931,18 +5931,26 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status) { irqreturn_t retval = IRQ_NONE; struct uic_command *cmd; + bool ah8_err; guard(spinlock_irqsave)(&hba->host->host_lock); + + /* + * Auto-hibern8 is performed without a UIC command, so check for + * auto-hibern8 errors before checking for an active UIC command. + */ + ah8_err = ufshcd_is_auto_hibern8_error(hba, intr_status); + if (ah8_err) + hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status); + cmd = hba->active_uic_cmd; if (!cmd) { - dev_err(hba->dev, - "No active UIC command. Maybe a timeout occurred?\n"); + if (!ah8_err) + dev_err(hba->dev, + "No active UIC command. Maybe a timeout occurred?\n"); return retval; } - if (ufshcd_is_auto_hibern8_error(hba, intr_status)) - hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status); - if (intr_status & UIC_COMMAND_COMPL) { /* * Store the UIC command result in the lowest byte of @@ -11184,8 +11192,7 @@ static int ufshcd_add_scsi_host(struct ufs_hba *hba) err = PTR_ERR(hba->tmf_queue); goto free_tmf_tag_set; } - hba->tmf_rqs = devm_kcalloc(hba->dev, hba->nutmrs, - sizeof(*hba->tmf_rqs), GFP_KERNEL); + hba->tmf_rqs = devm_kzalloc_objs(hba->dev, *hba->tmf_rqs, hba->nutmrs); if (!hba->tmf_rqs) { err = -ENOMEM; goto free_tmf_queue; diff --git a/drivers/ufs/host/cdns-pltfrm.c b/drivers/ufs/host/cdns-pltfrm.c index e793e3538c48f8..3ef62acb04fa2d 100644 --- a/drivers/ufs/host/cdns-pltfrm.c +++ b/drivers/ufs/host/cdns-pltfrm.c @@ -215,7 +215,7 @@ static int cdns_ufs_init(struct ufs_hba *hba) struct cdns_ufs_host *host; struct device *dev = hba->dev; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/ufs/host/ti-j721e-ufs.c b/drivers/ufs/host/ti-j721e-ufs.c index 43781593b5c1ae..d246bde505b15c 100644 --- a/drivers/ufs/host/ti-j721e-ufs.c +++ b/drivers/ufs/host/ti-j721e-ufs.c @@ -28,7 +28,7 @@ static int ti_j721e_ufs_probe(struct platform_device *pdev) struct clk *clk; int ret; - ufs = devm_kzalloc(dev, sizeof(*ufs), GFP_KERNEL); + ufs = devm_kzalloc_obj(dev, *ufs); if (!ufs) return -ENOMEM; diff --git a/drivers/ufs/host/ufs-amd-versal2.c b/drivers/ufs/host/ufs-amd-versal2.c index dff0c2c9548655..65cb0b5028b987 100644 --- a/drivers/ufs/host/ufs-amd-versal2.c +++ b/drivers/ufs/host/ufs-amd-versal2.c @@ -276,7 +276,7 @@ static int ufs_versal2_init(struct ufs_hba *hba) int ret; u32 cal; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/ufs/host/ufs-exynos.c b/drivers/ufs/host/ufs-exynos.c index 3bcbc9ebbb2834..265e01467a9b3b 100644 --- a/drivers/ufs/host/ufs-exynos.c +++ b/drivers/ufs/host/ufs-exynos.c @@ -1537,7 +1537,7 @@ static int exynos_ufs_init(struct ufs_hba *hba) struct exynos_ufs *ufs; int ret; - ufs = devm_kzalloc(dev, sizeof(*ufs), GFP_KERNEL); + ufs = devm_kzalloc_obj(dev, *ufs); if (!ufs) return -ENOMEM; @@ -1880,7 +1880,7 @@ static int exynosauto_ufs_vh_init(struct ufs_hba *hba) struct exynos_ufs *ufs; int ret; - ufs = devm_kzalloc(dev, sizeof(*ufs), GFP_KERNEL); + ufs = devm_kzalloc_obj(dev, *ufs); if (!ufs) return -ENOMEM; diff --git a/drivers/ufs/host/ufs-hisi.c b/drivers/ufs/host/ufs-hisi.c index 993e20ac211de9..73eef0e0d278e7 100644 --- a/drivers/ufs/host/ufs-hisi.c +++ b/drivers/ufs/host/ufs-hisi.c @@ -472,7 +472,7 @@ static int ufs_hisi_init_common(struct ufs_hba *hba) struct device *dev = hba->dev; struct ufs_hisi_host *host; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index 5b6bff2cf9a20b..7691349c502a36 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -649,8 +649,7 @@ static void ufs_mtk_init_boost_crypt(struct ufs_hba *hba) struct regulator *reg; u32 volt; - host->crypt = devm_kzalloc(dev, sizeof(*(host->crypt)), - GFP_KERNEL); + host->crypt = devm_kzalloc_obj(dev, *(host->crypt)); if (!host->crypt) goto disable_caps; @@ -1234,7 +1233,7 @@ static int ufs_mtk_init(struct ufs_hba *hba) int err = 0; struct arm_smccc_res res; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) { err = -ENOMEM; dev_info(dev, "%s: no memory for mtk ufs host\n", __func__); diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index 27c87e62f8e98d..67c2a3b95e5806 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1608,7 +1608,7 @@ static int ufs_qcom_init(struct ufs_hba *hba) struct ufs_clk_info *clki; const struct ufs_qcom_drvdata *drvdata = of_device_get_match_data(hba->dev); - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; @@ -1713,7 +1713,7 @@ static int ufs_qcom_fw_managed_init(struct ufs_hba *hba) struct ufs_qcom_host *host; int err; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; @@ -2457,7 +2457,7 @@ static int ufs_qcom_config_esi(struct ufs_hba *hba) return ret; /* Continue without ESI */ } - qi = devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL); + qi = devm_kzalloc_objs(hba->dev, *qi, nr_irqs); if (!qi) { platform_device_msi_free_irqs_all(hba->dev); return -ENOMEM; diff --git a/drivers/ufs/host/ufs-renesas.c b/drivers/ufs/host/ufs-renesas.c index 5bf7d0e77ad857..e418c5878038bc 100644 --- a/drivers/ufs/host/ufs-renesas.c +++ b/drivers/ufs/host/ufs-renesas.c @@ -455,7 +455,7 @@ static int ufs_renesas_init(struct ufs_hba *hba) size_t len; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; ufshcd_set_variant(hba, priv); diff --git a/drivers/ufs/host/ufs-rockchip.c b/drivers/ufs/host/ufs-rockchip.c index bac68f238e1c4f..8ce6534a73de4b 100644 --- a/drivers/ufs/host/ufs-rockchip.c +++ b/drivers/ufs/host/ufs-rockchip.c @@ -143,7 +143,7 @@ static int ufs_rockchip_common_init(struct ufs_hba *hba) struct ufs_rockchip_host *host; int err; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/ufs/host/ufs-sprd.c b/drivers/ufs/host/ufs-sprd.c index 6862250c542e06..8c0a13e9555627 100644 --- a/drivers/ufs/host/ufs-sprd.c +++ b/drivers/ufs/host/ufs-sprd.c @@ -137,7 +137,7 @@ static int ufs_sprd_common_init(struct ufs_hba *hba) const struct of_device_id *of_id; int ret = 0; - host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(dev, *host); if (!host) return -ENOMEM; diff --git a/drivers/ufs/host/ufshcd-pci.c b/drivers/ufs/host/ufshcd-pci.c index 668b57403e6261..8d7a266f4529f8 100644 --- a/drivers/ufs/host/ufshcd-pci.c +++ b/drivers/ufs/host/ufshcd-pci.c @@ -365,7 +365,7 @@ static int ufs_intel_common_init(struct ufs_hba *hba) hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND; - host = devm_kzalloc(hba->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(hba->dev, *host); if (!host) return -ENOMEM; host->saved_spm_lvl = -1; diff --git a/drivers/ufs/host/ufshcd-pltfrm.c b/drivers/ufs/host/ufshcd-pltfrm.c index 169dbc1a75fe57..c238f6073ad095 100644 --- a/drivers/ufs/host/ufshcd-pltfrm.c +++ b/drivers/ufs/host/ufshcd-pltfrm.c @@ -61,8 +61,7 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba) goto out; } - clkfreq = devm_kcalloc(dev, sz, sizeof(*clkfreq), - GFP_KERNEL); + clkfreq = devm_kzalloc_objs(dev, *clkfreq, sz); if (!clkfreq) { ret = -ENOMEM; goto out; @@ -82,7 +81,7 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba) if (ret) goto out; - clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); + clki = devm_kzalloc_obj(dev, *clki); if (!clki) { ret = -ENOMEM; goto out; @@ -137,7 +136,7 @@ int ufshcd_populate_vreg(struct device *dev, const char *name, goto out; } - vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); + vreg = devm_kzalloc_obj(dev, *vreg); if (!vreg) return -ENOMEM; @@ -440,7 +439,7 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba) } /* OPP expects clk_names to be NULL terminated */ - clk_names = devm_kcalloc(dev, cnt + 1, sizeof(*clk_names), GFP_KERNEL); + clk_names = devm_kzalloc_objs(dev, *clk_names, cnt + 1); if (!clk_names) return -ENOMEM; @@ -454,7 +453,7 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba) if (ret) return ret; - clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); + clki = devm_kzalloc_obj(dev, *clki); if (!clki) return -ENOMEM; diff --git a/drivers/uio/uio_aec.c b/drivers/uio/uio_aec.c index dafcc5f44f24ed..1dd163d5b9021f 100644 --- a/drivers/uio/uio_aec.c +++ b/drivers/uio/uio_aec.c @@ -71,7 +71,7 @@ static int probe(struct pci_dev *pdev, const struct pci_device_id *id) struct uio_info *info; int ret; - info = devm_kzalloc(&pdev->dev, sizeof(struct uio_info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct uio_info); if (!info) return -ENOMEM; diff --git a/drivers/uio/uio_cif.c b/drivers/uio/uio_cif.c index 4e4b589ddef1cb..eba80af2ef5b43 100644 --- a/drivers/uio/uio_cif.c +++ b/drivers/uio/uio_cif.c @@ -43,7 +43,7 @@ static int hilscher_pci_probe(struct pci_dev *dev, { struct uio_info *info; - info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, struct uio_info); if (!info) return -ENOMEM; diff --git a/drivers/uio/uio_dfl.c b/drivers/uio/uio_dfl.c index 6d99e5a06ae8c2..e07475398f0a02 100644 --- a/drivers/uio/uio_dfl.c +++ b/drivers/uio/uio_dfl.c @@ -19,7 +19,7 @@ static int uio_dfl_probe(struct dfl_device *ddev) struct uio_mem *uiomem; int ret; - uioinfo = devm_kzalloc(dev, sizeof(struct uio_info), GFP_KERNEL); + uioinfo = devm_kzalloc_obj(dev, struct uio_info); if (!uioinfo) return -ENOMEM; diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c index 41c18ec62a4530..263c1ebc2d57b9 100644 --- a/drivers/uio/uio_dmem_genirq.c +++ b/drivers/uio/uio_dmem_genirq.c @@ -160,7 +160,7 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) if (pdev->dev.of_node) { /* alloc uioinfo for one device */ - uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo), GFP_KERNEL); + uioinfo = devm_kzalloc_obj(&pdev->dev, *uioinfo); if (!uioinfo) { dev_err(&pdev->dev, "unable to kmalloc\n"); return -ENOMEM; @@ -183,7 +183,7 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { dev_err(&pdev->dev, "unable to kmalloc\n"); return -ENOMEM; diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c index 08cb150fb12fc6..a8e4d8203ad8cb 100644 --- a/drivers/uio/uio_fsl_elbc_gpcm.c +++ b/drivers/uio/uio_fsl_elbc_gpcm.c @@ -324,7 +324,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) return irq; /* allocate private data */ - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; @@ -337,7 +337,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) return ret; /* allocate UIO structure */ - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 7b4cc456c45341..dff92dcbb10d93 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -262,7 +262,7 @@ hv_uio_probe(struct hv_device *dev, /* Adjust ring size if necessary to have it page aligned */ ring_size = VMBUS_RING_SIZE(ring_size); - pdata = devm_kzalloc(&dev->device, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&dev->device, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c index 790412f8dfd5eb..5fb44b560ea913 100644 --- a/drivers/uio/uio_mf624.c +++ b/drivers/uio/uio_mf624.c @@ -136,7 +136,7 @@ static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct uio_info *info; - info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, struct uio_info); if (!info) return -ENOMEM; diff --git a/drivers/uio/uio_netx.c b/drivers/uio/uio_netx.c index 18917b2ac04ca9..0a84b9d8f28ba9 100644 --- a/drivers/uio/uio_netx.c +++ b/drivers/uio/uio_netx.c @@ -53,7 +53,7 @@ static int netx_pci_probe(struct pci_dev *dev, struct uio_info *info; int bar; - info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, struct uio_info); if (!info) return -ENOMEM; diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c index e03f9b532a96ef..c0cab3adb7b0ea 100644 --- a/drivers/uio/uio_pci_generic.c +++ b/drivers/uio/uio_pci_generic.c @@ -86,7 +86,7 @@ static int probe(struct pci_dev *pdev, if (pdev->irq && !pci_intx_mask_supported(pdev)) return -ENODEV; - gdev = devm_kzalloc(&pdev->dev, sizeof(struct uio_pci_generic_dev), GFP_KERNEL); + gdev = devm_kzalloc_obj(&pdev->dev, struct uio_pci_generic_dev); if (!gdev) return -ENOMEM; diff --git a/drivers/uio/uio_pci_generic_sva.c b/drivers/uio/uio_pci_generic_sva.c index d05ef77f7e322f..08ba6f67ae8ad2 100644 --- a/drivers/uio/uio_pci_generic_sva.c +++ b/drivers/uio/uio_pci_generic_sva.c @@ -88,8 +88,7 @@ static int probe(struct pci_dev *pdev, const struct pci_device_id *id) dev_warn(&pdev->dev, "No IRQ vectors available (%d), using polling\n", ret); - udev = devm_kzalloc(&pdev->dev, sizeof(struct uio_pci_sva_dev), - GFP_KERNEL); + udev = devm_kzalloc_obj(&pdev->dev, struct uio_pci_sva_dev); if (!udev) { ret = -ENOMEM; goto out_disable; diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c index 0c8d73e7be523b..87e43821ab0c7a 100644 --- a/drivers/uio/uio_pdrv_genirq.c +++ b/drivers/uio/uio_pdrv_genirq.c @@ -119,8 +119,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) const char *name; /* alloc uioinfo for one device */ - uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo), - GFP_KERNEL); + uioinfo = devm_kzalloc_obj(&pdev->dev, *uioinfo); if (!uioinfo) { dev_err(&pdev->dev, "unable to kmalloc\n"); return -ENOMEM; @@ -147,7 +146,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) return ret; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { dev_err(&pdev->dev, "unable to kmalloc\n"); return -ENOMEM; diff --git a/drivers/uio/uio_sercos3.c b/drivers/uio/uio_sercos3.c index 80087897f9b86e..83b760e867c7ab 100644 --- a/drivers/uio/uio_sercos3.c +++ b/drivers/uio/uio_sercos3.c @@ -124,11 +124,11 @@ static int sercos3_pci_probe(struct pci_dev *dev, struct sercos3_priv *priv; int i; - info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL); + info = devm_kzalloc_obj(&dev->dev, struct uio_info); if (!info) return -ENOMEM; - priv = devm_kzalloc(&dev->dev, sizeof(struct sercos3_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&dev->dev, struct sercos3_priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index f4dfd013170832..380c4fde8298e3 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -3190,8 +3190,7 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev) continue; } - priv_ep = devm_kzalloc(priv_dev->dev, sizeof(*priv_ep), - GFP_KERNEL); + priv_ep = devm_kzalloc_obj(priv_dev->dev, *priv_ep); if (!priv_ep) goto err; @@ -3512,7 +3511,7 @@ int cdns3_gadget_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + rdrv = devm_kzalloc_obj(cdns->dev, *rdrv); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c index a2f041e1707c0d..710334c3431e74 100644 --- a/drivers/usb/cdns3/cdns3-imx.c +++ b/drivers/usb/cdns3/cdns3-imx.c @@ -172,7 +172,7 @@ static int cdns_imx_probe(struct platform_device *pdev) if (!node) return -ENODEV; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c index e3f32c3e953526..af67e8bc160c83 100644 --- a/drivers/usb/cdns3/cdns3-plat.c +++ b/drivers/usb/cdns3/cdns3-plat.c @@ -72,7 +72,7 @@ static int cdns3_plat_probe(struct platform_device *pdev) void __iomem *regs; int ret; - cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); + cdns = devm_kzalloc_obj(dev, *cdns); if (!cdns) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdns3-starfive.c b/drivers/usb/cdns3/cdns3-starfive.c index 2ff7f2b48cc2b7..a6ac650e220576 100644 --- a/drivers/usb/cdns3/cdns3-starfive.c +++ b/drivers/usb/cdns3/cdns3-starfive.c @@ -111,7 +111,7 @@ static int cdns_starfive_probe(struct platform_device *pdev) unsigned int args; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c index 302ebf6d8e5367..61850cd5b68f62 100644 --- a/drivers/usb/cdns3/cdns3-ti.c +++ b/drivers/usb/cdns3/cdns3-ti.c @@ -144,7 +144,7 @@ static int cdns_ti_probe(struct platform_device *pdev) unsigned long rate; int error, i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c index e84405352caaba..2830b595d632e4 100644 --- a/drivers/usb/cdns3/cdnsp-gadget.c +++ b/drivers/usb/cdns3/cdnsp-gadget.c @@ -2179,7 +2179,7 @@ int cdnsp_gadget_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + rdrv = devm_kzalloc_obj(cdns->dev, *rdrv); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index 87122fb5bdb82d..0c455a46a8f948 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -265,7 +265,7 @@ static int cdns_idle_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + rdrv = devm_kzalloc_obj(cdns->dev, *rdrv); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c index f0df114c2b53bc..e01264dc625dab 100644 --- a/drivers/usb/cdns3/host.c +++ b/drivers/usb/cdns3/host.c @@ -152,7 +152,7 @@ int cdns_host_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + rdrv = devm_kzalloc_obj(cdns->dev, *rdrv); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index edbf9df9b8f289..418be1f2f48f43 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -144,7 +144,7 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) if (!of_property_present(np, "fsl,usbmisc")) return NULL; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return ERR_PTR(-ENOMEM); @@ -389,7 +389,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) imx_platform_flag = of_device_get_match_data(&pdev->dev); - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index 3ab3daa78e3401..cec8474d7a9554 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c @@ -180,7 +180,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); - ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); + ci = devm_kzalloc_obj(&pdev->dev, *ci); if (!ci) return -ENOMEM; platform_set_drvdata(pdev, ci); diff --git a/drivers/usb/chipidea/ci_hdrc_npcm.c b/drivers/usb/chipidea/ci_hdrc_npcm.c index e52a2b05cbe2ae..75a0223b578a8d 100644 --- a/drivers/usb/chipidea/ci_hdrc_npcm.c +++ b/drivers/usb/chipidea/ci_hdrc_npcm.c @@ -42,7 +42,7 @@ static int npcm_udc_probe(struct platform_device *pdev) struct platform_device *plat_ci; struct device *dev = &pdev->dev; - ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); + ci = devm_kzalloc_obj(&pdev->dev, *ci); if (!ci) return -ENOMEM; platform_set_drvdata(pdev, ci); diff --git a/drivers/usb/chipidea/ci_hdrc_pci.c b/drivers/usb/chipidea/ci_hdrc_pci.c index d63479e1ad104e..e41a400c892d2e 100644 --- a/drivers/usb/chipidea/ci_hdrc_pci.c +++ b/drivers/usb/chipidea/ci_hdrc_pci.c @@ -64,7 +64,7 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, return -ENODEV; } - ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); + ci = devm_kzalloc_obj(&pdev->dev, *ci); if (!ci) return -ENOMEM; diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c index 26225b034d3b21..e42e1b6a1933ad 100644 --- a/drivers/usb/chipidea/ci_hdrc_tegra.c +++ b/drivers/usb/chipidea/ci_hdrc_tegra.c @@ -278,7 +278,7 @@ static int tegra_usb_probe(struct platform_device *pdev) struct tegra_usb *usb; int err; - usb = devm_kzalloc(&pdev->dev, sizeof(*usb), GFP_KERNEL); + usb = devm_kzalloc_obj(&pdev->dev, *usb); if (!usb) return -ENOMEM; diff --git a/drivers/usb/chipidea/ci_hdrc_usb2.c b/drivers/usb/chipidea/ci_hdrc_usb2.c index 8ffa1e95d8e860..b0200c5937cd5b 100644 --- a/drivers/usb/chipidea/ci_hdrc_usb2.c +++ b/drivers/usb/chipidea/ci_hdrc_usb2.c @@ -55,7 +55,7 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev) int ret; if (!ci_pdata) { - ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL); + ci_pdata = devm_kmalloc_obj(dev, *ci_pdata); if (!ci_pdata) return -ENOMEM; *ci_pdata = ci_default_pdata; /* struct copy */ @@ -66,7 +66,7 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev) /* struct copy */ *ci_pdata = *data; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 3461dd763a6e25..1f7c73fdc74b73 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -1041,7 +1041,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); + ci = devm_kzalloc_obj(dev, *ci); if (!ci) return -ENOMEM; diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index ced6076a824842..3862aebccb231e 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -478,7 +478,7 @@ int ci_hdrc_host_init(struct ci_hdrc *ci) if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC)) return -ENXIO; - rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL); + rdrv = devm_kzalloc_obj(ci->dev, struct ci_role_driver); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index c29b2d0dcc7c88..9afffd22d697e6 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -2417,7 +2417,7 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci) if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC)) return -ENXIO; - rdrv = devm_kzalloc(ci->dev, sizeof(*rdrv), GFP_KERNEL); + rdrv = devm_kzalloc_obj(ci->dev, *rdrv); if (!rdrv) return -ENOMEM; diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index bb027d2bd7008e..c799162402cec6 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -1514,7 +1514,7 @@ static int usbmisc_imx_probe(struct platform_device *pdev) struct imx_usbmisc *data; struct resource *res; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index f6db03d89efdee..6850d45c18b332 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -197,7 +197,7 @@ static int usb_conn_probe(struct platform_device *pdev) struct usb_conn_info *info; int ret = 0; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return -ENOMEM; diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c index 4d966cc9cdc951..0981dce4e2f131 100644 --- a/drivers/usb/core/phy.c +++ b/drivers/usb/core/phy.c @@ -30,7 +30,7 @@ static int usb_phy_roothub_add_phy_by_name(struct device *dev, const char *name, if (IS_ERR(phy)) return PTR_ERR(phy); - roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); + roothub_entry = devm_kzalloc_obj(dev, *roothub_entry); if (!roothub_entry) return -ENOMEM; @@ -57,7 +57,7 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index, return PTR_ERR(phy); } - roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); + roothub_entry = devm_kzalloc_obj(dev, *roothub_entry); if (!roothub_entry) return -ENOMEM; @@ -83,7 +83,7 @@ struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev) if (num_phys <= 0) return NULL; - phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL); + phy_roothub = devm_kzalloc_obj(dev, *phy_roothub); if (!phy_roothub) return ERR_PTR(-ENOMEM); @@ -134,7 +134,7 @@ struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy(struct device *dev) if (usb2_phy_index < 0) return NULL; - phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL); + phy_roothub = devm_kzalloc_obj(dev, *phy_roothub); if (!phy_roothub) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c index 2ecbf6523aaae9..198d92d50f65bc 100644 --- a/drivers/usb/dwc2/debugfs.c +++ b/drivers/usb/dwc2/debugfs.c @@ -788,7 +788,7 @@ int dwc2_debugfs_init(struct dwc2_hsotg *hsotg) /* Add gadget debugfs nodes */ dwc2_hsotg_create_debug(hsotg); - hsotg->regset = kzalloc_obj(*hsotg->regset, GFP_KERNEL); + hsotg->regset = kzalloc_obj(*hsotg->regset); if (!hsotg->regset) { ret = -ENOMEM; goto err; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 6c8a9f05fff006..c72f02adff5955 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4964,9 +4964,7 @@ static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) /* Add ep0 */ hsotg->num_of_eps++; - hsotg->eps_in[0] = devm_kzalloc(hsotg->dev, - sizeof(struct dwc2_hsotg_ep), - GFP_KERNEL); + hsotg->eps_in[0] = devm_kzalloc_obj(hsotg->dev, struct dwc2_hsotg_ep); if (!hsotg->eps_in[0]) return -ENOMEM; /* Same dwc2_hsotg_ep is used in both directions for ep0 */ @@ -4977,15 +4975,15 @@ static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) ep_type = cfg & 3; /* Direction in or both */ if (!(ep_type & 2)) { - hsotg->eps_in[i] = devm_kzalloc(hsotg->dev, - sizeof(struct dwc2_hsotg_ep), GFP_KERNEL); + hsotg->eps_in[i] = devm_kzalloc_obj(hsotg->dev, + struct dwc2_hsotg_ep); if (!hsotg->eps_in[i]) return -ENOMEM; } /* Direction out or both */ if (!(ep_type & 1)) { - hsotg->eps_out[i] = devm_kzalloc(hsotg->dev, - sizeof(struct dwc2_hsotg_ep), GFP_KERNEL); + hsotg->eps_out[i] = devm_kzalloc_obj(hsotg->dev, + struct dwc2_hsotg_ep); if (!hsotg->eps_out[i]) return -ENOMEM; } diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index d5275cd658d4c6..2e1927dfa34f1f 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5120,14 +5120,12 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS - hsotg->frame_num_array = kcalloc(FRAME_NUM_ARRAY_SIZE, - sizeof(*hsotg->frame_num_array), - GFP_KERNEL); + hsotg->frame_num_array = kzalloc_objs(*hsotg->frame_num_array, + FRAME_NUM_ARRAY_SIZE); if (!hsotg->frame_num_array) goto error1; hsotg->last_frame_num_array = - kcalloc(FRAME_NUM_ARRAY_SIZE, - sizeof(*hsotg->last_frame_num_array), GFP_KERNEL); + kzalloc_objs(*hsotg->last_frame_num_array, FRAME_NUM_ARRAY_SIZE); if (!hsotg->last_frame_num_array) goto error1; #endif diff --git a/drivers/usb/dwc2/hcd_ddma.c b/drivers/usb/dwc2/hcd_ddma.c index 703cda5a589534..9fbe7f61d06988 100644 --- a/drivers/usb/dwc2/hcd_ddma.c +++ b/drivers/usb/dwc2/hcd_ddma.c @@ -77,7 +77,7 @@ static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, qh->desc_list_sz, DMA_TO_DEVICE); - qh->n_bytes = kcalloc(dwc2_max_desc_num(qh), sizeof(u32), flags); + qh->n_bytes = kzalloc_objs(u32, dwc2_max_desc_num(qh), flags); if (!qh->n_bytes) { dma_unmap_single(hsotg->dev, qh->desc_list_dma, qh->desc_list_sz, diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c index f3a1e4232a31dc..75a2891475ef5a 100644 --- a/drivers/usb/dwc2/pci.c +++ b/drivers/usb/dwc2/pci.c @@ -99,7 +99,7 @@ static int dwc2_pci_probe(struct pci_dev *pci, dwc2->dev.parent = dev; - glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(dev, *glue); if (!glue) { ret = -ENOMEM; goto err; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index ef0d7307703473..3df9b198d1b224 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -442,7 +442,7 @@ static int dwc2_driver_probe(struct platform_device *dev) struct resource *res; int retval; - hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); + hsotg = devm_kzalloc_obj(&dev->dev, *hsotg); if (!hsotg) return -ENOMEM; diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index fd5c2cd36c595c..372737f4750b10 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -489,7 +489,7 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, { struct dwc3_event_buffer *evt; - evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); + evt = devm_kzalloc_obj(dwc->dev, *evt); if (!evt) return ERR_PTR(-ENOMEM); @@ -1140,7 +1140,7 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc) if (ntype <= 0) return; - vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL); + vals = kzalloc_objs(u32, ntype); if (!vals) return; @@ -2460,7 +2460,7 @@ static int dwc3_probe(struct platform_device *pdev) return -ENODEV; } - dwc = devm_kzalloc(&pdev->dev, sizeof(*dwc), GFP_KERNEL); + dwc = devm_kzalloc_obj(&pdev->dev, *dwc); if (!dwc) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c index d03b3950ce046a..88702868436472 100644 --- a/drivers/usb/dwc3/dwc3-am62.c +++ b/drivers/usb/dwc3/dwc3-am62.c @@ -225,7 +225,7 @@ static int dwc3_ti_probe(struct platform_device *pdev) unsigned long rate; int i, ret; - am62 = devm_kzalloc(dev, sizeof(*am62), GFP_KERNEL); + am62 = devm_kzalloc_obj(dev, *am62); if (!am62) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 40c3ccfddb6702..1f474a8bc59ea6 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -438,7 +438,7 @@ static int dwc3_apple_probe(struct platform_device *pdev) struct dwc3_apple *appledwc; int ret; - appledwc = devm_kzalloc(&pdev->dev, sizeof(*appledwc), GFP_KERNEL); + appledwc = devm_kzalloc_obj(&pdev->dev, *appledwc); if (!appledwc) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index e934f94e8fd8e5..a4dab9285874fd 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -45,7 +45,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev) const struct dwc3_exynos_driverdata *driver_data; int i, ret; - exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); + exynos = devm_kzalloc_obj(dev, *exynos); if (!exynos) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-generic-plat.c b/drivers/usb/dwc3/dwc3-generic-plat.c index ca69ac0eb07cec..a53991a46b4c9c 100644 --- a/drivers/usb/dwc3/dwc3-generic-plat.c +++ b/drivers/usb/dwc3/dwc3-generic-plat.c @@ -94,7 +94,7 @@ static int dwc3_generic_probe(struct platform_device *pdev) struct resource *res; int ret; - dwc3g = devm_kzalloc(dev, sizeof(*dwc3g), GFP_KERNEL); + dwc3g = devm_kzalloc_obj(dev, *dwc3g); if (!dwc3g) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-google.c b/drivers/usb/dwc3/dwc3-google.c index ec53e658760e88..67eda7f0d52839 100644 --- a/drivers/usb/dwc3/dwc3-google.c +++ b/drivers/usb/dwc3/dwc3-google.c @@ -367,7 +367,7 @@ static int dwc3_google_probe(struct platform_device *pdev) int ret; u32 args[2]; - google = devm_kzalloc(&pdev->dev, sizeof(*google), GFP_KERNEL); + google = devm_kzalloc_obj(&pdev->dev, *google); if (!google) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-haps.c b/drivers/usb/dwc3/dwc3-haps.c index f6e3817fa7af05..fc54e5fd0cbb5a 100644 --- a/drivers/usb/dwc3/dwc3-haps.c +++ b/drivers/usb/dwc3/dwc3-haps.c @@ -53,7 +53,7 @@ static int dwc3_haps_probe(struct pci_dev *pci, pci_set_master(pci); - dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); + dwc = devm_kzalloc_obj(dev, *dwc); if (!dwc) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-imx.c b/drivers/usb/dwc3/dwc3-imx.c index d967acd43d44e5..845358f7b33315 100644 --- a/drivers/usb/dwc3/dwc3-imx.c +++ b/drivers/usb/dwc3/dwc3-imx.c @@ -201,7 +201,7 @@ static int dwc3_imx_probe(struct platform_device *pdev) struct dwc3_probe_data probe_data = {}; int ret, irq; - dwc_imx = devm_kzalloc(dev, sizeof(*dwc_imx), GFP_KERNEL); + dwc_imx = devm_kzalloc_obj(dev, *dwc_imx); if (!dwc_imx) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-imx8mp.c b/drivers/usb/dwc3/dwc3-imx8mp.c index ee92a5efaa6e84..ad1d6442bbf985 100644 --- a/drivers/usb/dwc3/dwc3-imx8mp.c +++ b/drivers/usb/dwc3/dwc3-imx8mp.c @@ -191,7 +191,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev) return -EINVAL; } - dwc3_imx = devm_kzalloc(dev, sizeof(*dwc3_imx), GFP_KERNEL); + dwc3_imx = devm_kzalloc_obj(dev, *dwc3_imx); if (!dwc3_imx) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c index 8ad302abe883c2..7a5fc8545d4bf4 100644 --- a/drivers/usb/dwc3/dwc3-keystone.c +++ b/drivers/usb/dwc3/dwc3-keystone.c @@ -86,7 +86,7 @@ static int kdwc3_probe(struct platform_device *pdev) struct dwc3_keystone *kdwc; int error, irq; - kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL); + kdwc = devm_kzalloc_obj(dev, *kdwc); if (!kdwc) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index 4d611c08e8a4cf..ca07e813fd64fc 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -702,7 +702,7 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev) void __iomem *base; int ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-octeon.c b/drivers/usb/dwc3/dwc3-octeon.c index 2201f0f34abb77..0c221429f94e89 100644 --- a/drivers/usb/dwc3/dwc3-octeon.c +++ b/drivers/usb/dwc3/dwc3-octeon.c @@ -479,7 +479,7 @@ static int dwc3_octeon_probe(struct platform_device *pdev) power_gpio = gpio_pwr[1]; } - octeon = devm_kzalloc(dev, sizeof(*octeon), GFP_KERNEL); + octeon = devm_kzalloc_obj(dev, *octeon); if (!octeon) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c index c116143335d9f9..541524d167a6fa 100644 --- a/drivers/usb/dwc3/dwc3-of-simple.c +++ b/drivers/usb/dwc3/dwc3-of-simple.c @@ -38,7 +38,7 @@ static int dwc3_of_simple_probe(struct platform_device *pdev) int ret; - simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); + simple = devm_kzalloc_obj(dev, *simple); if (!simple) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 3bff775fbe4e21..0c6e72c4bdfbe4 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c @@ -469,7 +469,7 @@ static int dwc3_omap_probe(struct platform_device *pdev) return -EINVAL; } - omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); + omap = devm_kzalloc_obj(dev, *omap); if (!omap) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 6c1cbb722ca858..0b03db68a0e749 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c @@ -343,7 +343,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) pci_set_master(pci); - dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); + dwc = devm_kzalloc_obj(dev, *dwc); if (!dwc) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-qcom-legacy.c b/drivers/usb/dwc3/dwc3-qcom-legacy.c index d3fad0fcfdac33..189f5447aa786c 100644 --- a/drivers/usb/dwc3/dwc3-qcom-legacy.c +++ b/drivers/usb/dwc3/dwc3-qcom-legacy.c @@ -667,8 +667,7 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) qcom->num_clocks = count; - qcom->clks = devm_kcalloc(dev, qcom->num_clocks, - sizeof(struct clk *), GFP_KERNEL); + qcom->clks = devm_kzalloc_objs(dev, struct clk *, qcom->num_clocks); if (!qcom->clks) return -ENOMEM; @@ -739,7 +738,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) bool ignore_pipe_clk; bool wakeup_source; - qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); + qcom = devm_kzalloc_obj(&pdev->dev, *qcom); if (!qcom) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index ac68b4218b56b7..a2608416e04ecb 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -618,7 +618,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) bool ignore_pipe_clk; bool wakeup_source; - qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); + qcom = devm_kzalloc_obj(&pdev->dev, *qcom); if (!qcom) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c index 56c53e0c025748..5ee84812d7cd5f 100644 --- a/drivers/usb/dwc3/dwc3-rtk.c +++ b/drivers/usb/dwc3/dwc3-rtk.c @@ -359,7 +359,7 @@ static int dwc3_rtk_probe(struct platform_device *pdev) struct resource *res; void __iomem *regs; - rtk = devm_kzalloc(dev, sizeof(*rtk), GFP_KERNEL); + rtk = devm_kzalloc_obj(dev, *rtk); if (!rtk) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index 5d513decaacd22..64fb866cd7b0af 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c @@ -203,7 +203,7 @@ static int st_dwc3_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL); + dwc3_data = devm_kzalloc_obj(dev, *dwc3_data); if (!dwc3_data) return -ENOMEM; diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c index b832505e1b0428..c9fb8c259493ef 100644 --- a/drivers/usb/dwc3/dwc3-xilinx.c +++ b/drivers/usb/dwc3/dwc3-xilinx.c @@ -283,7 +283,7 @@ static int dwc3_xlnx_probe(struct platform_device *pdev) void __iomem *regs; int ret; - priv_data = devm_kzalloc(dev, sizeof(*priv_data), GFP_KERNEL); + priv_data = devm_kzalloc_obj(dev, *priv_data); if (!priv_data) return -ENOMEM; diff --git a/drivers/usb/fotg210/fotg210-core.c b/drivers/usb/fotg210/fotg210-core.c index 7de49b7eb3aa68..2ead1300d723a1 100644 --- a/drivers/usb/fotg210/fotg210-core.c +++ b/drivers/usb/fotg210/fotg210-core.c @@ -184,7 +184,7 @@ static int fotg210_probe(struct platform_device *pdev) u32 val; int ret; - fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL); + fotg = devm_kzalloc_obj(dev, *fotg); if (!fotg) return -ENOMEM; fotg->dev = dev; diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 500c9c19c78b4f..7f4324981eb31a 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1457,7 +1457,7 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f) ncm_opts = container_of(f->fi, struct f_ncm_opts, func_inst); if (cdev->use_os_string) { - os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL); + os_desc_table = kzalloc_obj(*os_desc_table); if (!os_desc_table) return -ENOMEM; } diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 70a1415ea4014f..b9af49940d5f21 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -2089,7 +2089,7 @@ static ssize_t uvcg_frame_dw_frame_interval_store(struct config_item *item, if (ret) goto end; - tmp = frm_intrv = kcalloc(n, sizeof(u32), GFP_KERNEL); + tmp = frm_intrv = kzalloc_objs(u32, n); if (!frm_intrv) { ret = -ENOMEM; goto end; diff --git a/drivers/usb/gadget/udc/aspeed-vhub/core.c b/drivers/usb/gadget/udc/aspeed-vhub/core.c index cabe8703fa6c9d..c8a69893b584dd 100644 --- a/drivers/usb/gadget/udc/aspeed-vhub/core.c +++ b/drivers/usb/gadget/udc/aspeed-vhub/core.c @@ -306,7 +306,7 @@ static int ast_vhub_probe(struct platform_device *pdev) int i, rc = 0; const struct device_node *np = pdev->dev.of_node; - vhub = devm_kzalloc(&pdev->dev, sizeof(*vhub), GFP_KERNEL); + vhub = devm_kzalloc_obj(&pdev->dev, *vhub); if (!vhub) return -ENOMEM; @@ -315,8 +315,8 @@ static int ast_vhub_probe(struct platform_device *pdev) if (rc < 0) vhub->max_ports = AST_VHUB_NUM_PORTS; - vhub->ports = devm_kcalloc(&pdev->dev, vhub->max_ports, - sizeof(*vhub->ports), GFP_KERNEL); + vhub->ports = devm_kzalloc_objs(&pdev->dev, *vhub->ports, + vhub->max_ports); if (!vhub->ports) return -ENOMEM; @@ -325,8 +325,7 @@ static int ast_vhub_probe(struct platform_device *pdev) if (rc < 0) vhub->max_epns = AST_VHUB_NUM_GEN_EPs; - vhub->epns = devm_kcalloc(&pdev->dev, vhub->max_epns, - sizeof(*vhub->epns), GFP_KERNEL); + vhub->epns = devm_kzalloc_objs(&pdev->dev, *vhub->epns, vhub->max_epns); if (!vhub->epns) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c index 81fa495bbacd15..10214232c08fa2 100644 --- a/drivers/usb/gadget/udc/aspeed_udc.c +++ b/drivers/usb/gadget/udc/aspeed_udc.c @@ -1482,7 +1482,7 @@ static int ast_udc_probe(struct platform_device *pdev) struct ast_udc_dev *udc; int rc; - udc = devm_kzalloc(&pdev->dev, sizeof(struct ast_udc_dev), GFP_KERNEL); + udc = devm_kzalloc_obj(&pdev->dev, struct ast_udc_dev); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index 0fccca1878033a..ecb3805e7a58a9 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c @@ -1814,7 +1814,7 @@ static int at91udc_probe(struct platform_device *pdev) struct at91_ep *ep; int i; - udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(dev, *udc); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 18b4b2358d1ea0..9036ff323101d2 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -2172,8 +2172,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, udc->num_ep = usba_config_fifo_table(udc); } - eps = devm_kcalloc(&pdev->dev, udc->num_ep, sizeof(struct usba_ep), - GFP_KERNEL); + eps = devm_kzalloc_objs(&pdev->dev, struct usba_ep, udc->num_ep); if (!eps) return ERR_PTR(-ENOMEM); @@ -2276,7 +2275,7 @@ static int usba_udc_probe(struct platform_device *pdev) struct usba_udc *udc; int irq, ret, i; - udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(&pdev->dev, *udc); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c index ba91b1ebbf57eb..54ce0ddbd9e1d8 100644 --- a/drivers/usb/gadget/udc/bcm63xx_udc.c +++ b/drivers/usb/gadget/udc/bcm63xx_udc.c @@ -2273,7 +2273,7 @@ static int bcm63xx_udc_probe(struct platform_device *pdev) struct bcm63xx_udc *udc; int rc = -ENOMEM, i, irq; - udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(dev, *udc); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c index a8dbaef54abaef..5149c98bf9bf90 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_core.c +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c @@ -491,7 +491,7 @@ static int bdc_probe(struct platform_device *pdev) dev_dbg(dev, "%s()\n", __func__); - bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL); + bdc = devm_kzalloc_obj(dev, *bdc); if (!bdc) return -ENOMEM; @@ -511,8 +511,7 @@ static int bdc_probe(struct platform_device *pdev) bdc->num_phys = of_count_phandle_with_args(dev->of_node, "phys", "#phy-cells"); if (bdc->num_phys > 0) { - bdc->phys = devm_kcalloc(dev, bdc->num_phys, - sizeof(struct phy *), GFP_KERNEL); + bdc->phys = devm_kzalloc_objs(dev, struct phy *, bdc->num_phys); if (!bdc->phys) return -ENOMEM; } else { diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-pci.c b/drivers/usb/gadget/udc/cdns2/cdns2-pci.c index e589593b4cbf89..b579e9cfc214cc 100644 --- a/drivers/usb/gadget/udc/cdns2/cdns2-pci.c +++ b/drivers/usb/gadget/udc/cdns2/cdns2-pci.c @@ -40,7 +40,7 @@ static int cdns2_pci_probe(struct pci_dev *pdev, pci_set_master(pdev); - priv_dev = devm_kzalloc(&pdev->dev, sizeof(*priv_dev), GFP_KERNEL); + priv_dev = devm_kzalloc_obj(&pdev->dev, *priv_dev); if (!priv_dev) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index cdcbfae140e9ea..3b407de88eb54c 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c @@ -2127,7 +2127,7 @@ static int gr_probe(struct platform_device *pdev) int retval; u32 status; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; dev->dev = &pdev->dev; diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c index 11fd61cba5af9a..6dbea43022a7e3 100644 --- a/drivers/usb/gadget/udc/max3420_udc.c +++ b/drivers/usb/gadget/udc/max3420_udc.c @@ -1215,7 +1215,7 @@ static int max3420_probe(struct spi_device *spi) return -EFAULT; } - udc = devm_kzalloc(&spi->dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(&spi->dev, *udc); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c index 99b3ce28210f9a..78183eff931846 100644 --- a/drivers/usb/gadget/udc/pch_udc.c +++ b/drivers/usb/gadget/udc/pch_udc.c @@ -3041,7 +3041,7 @@ static int pch_udc_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct pch_udc_dev *dev; /* init */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c index 915786c9628c14..469075b064baf2 100644 --- a/drivers/usb/gadget/udc/r8a66597-udc.c +++ b/drivers/usb/gadget/udc/r8a66597-udc.c @@ -1858,7 +1858,7 @@ static int r8a66597_probe(struct platform_device *pdev) } /* initialize ucd */ - r8a66597 = devm_kzalloc(dev, sizeof(struct r8a66597), GFP_KERNEL); + r8a66597 = devm_kzalloc_obj(dev, struct r8a66597); if (r8a66597 == NULL) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 2c9c3e935a5ec8..0ebea52cbf2f27 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -2689,9 +2689,7 @@ static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES(usb3)) usb3->num_usb3_eps = USB3_MAX_NUM_PIPES(usb3); - usb3->usb3_ep = devm_kcalloc(dev, - usb3->num_usb3_eps, sizeof(*usb3_ep), - GFP_KERNEL); + usb3->usb3_ep = devm_kzalloc_objs(dev, *usb3_ep, usb3->num_usb3_eps); if (!usb3->usb3_ep) return -ENOMEM; @@ -2849,7 +2847,7 @@ static int renesas_usb3_probe(struct platform_device *pdev) if (irq < 0) return irq; - usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); + usb3 = devm_kzalloc_obj(&pdev->dev, *usb3); if (!usb3) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/renesas_usbf.c b/drivers/usb/gadget/udc/renesas_usbf.c index 367c9e73f366aa..e482d89850bd56 100644 --- a/drivers/usb/gadget/udc/renesas_usbf.c +++ b/drivers/usb/gadget/udc/renesas_usbf.c @@ -3249,7 +3249,7 @@ static int usbf_probe(struct platform_device *pdev) int irq; int ret; - udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(dev, *udc); if (!udc) return -ENOMEM; platform_set_drvdata(pdev, udc); diff --git a/drivers/usb/gadget/udc/rzv2m_usb3drd.c b/drivers/usb/gadget/udc/rzv2m_usb3drd.c index 4692eae89f4435..f9480f856b0a7e 100644 --- a/drivers/usb/gadget/udc/rzv2m_usb3drd.c +++ b/drivers/usb/gadget/udc/rzv2m_usb3drd.c @@ -73,7 +73,7 @@ static int rzv2m_usb3drd_probe(struct platform_device *pdev) struct rzv2m_usb3drd *usb3; int ret; - usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); + usb3 = devm_kzalloc_obj(&pdev->dev, *usb3); if (!usb3) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/snps_udc_plat.c b/drivers/usb/gadget/udc/snps_udc_plat.c index 8ce43c4f8fba62..3687690ca33da4 100644 --- a/drivers/usb/gadget/udc/snps_udc_plat.c +++ b/drivers/usb/gadget/udc/snps_udc_plat.c @@ -104,7 +104,7 @@ static int udc_plat_probe(struct platform_device *pdev) struct udc *udc; int ret; - udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(dev, *udc); if (!udc) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index 5042c13f92be67..a7736627e6e214 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -3497,18 +3497,18 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) int err = 0, usb3_companion_port; unsigned int i, j; - xudc->utmi_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, - sizeof(*xudc->utmi_phy), GFP_KERNEL); + xudc->utmi_phy = devm_kzalloc_objs(xudc->dev, *xudc->utmi_phy, + xudc->soc->num_phys); if (!xudc->utmi_phy) return -ENOMEM; - xudc->usb3_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, - sizeof(*xudc->usb3_phy), GFP_KERNEL); + xudc->usb3_phy = devm_kzalloc_objs(xudc->dev, *xudc->usb3_phy, + xudc->soc->num_phys); if (!xudc->usb3_phy) return -ENOMEM; - xudc->usbphy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, - sizeof(*xudc->usbphy), GFP_KERNEL); + xudc->usbphy = devm_kzalloc_objs(xudc->dev, *xudc->usbphy, + xudc->soc->num_phys); if (!xudc->usbphy) return -ENOMEM; @@ -3770,7 +3770,7 @@ static int tegra_xudc_probe(struct platform_device *pdev) unsigned int i; int err; - xudc = devm_kzalloc(&pdev->dev, sizeof(*xudc), GFP_KERNEL); + xudc = devm_kzalloc_obj(&pdev->dev, *xudc); if (!xudc) return -ENOMEM; @@ -3806,8 +3806,8 @@ static int tegra_xudc_probe(struct platform_device *pdev) if (err < 0) return err; - xudc->clks = devm_kcalloc(&pdev->dev, xudc->soc->num_clks, sizeof(*xudc->clks), - GFP_KERNEL); + xudc->clks = devm_kzalloc_objs(&pdev->dev, *xudc->clks, + xudc->soc->num_clks); if (!xudc->clks) return -ENOMEM; @@ -3820,8 +3820,8 @@ static int tegra_xudc_probe(struct platform_device *pdev) return err; } - xudc->supplies = devm_kcalloc(&pdev->dev, xudc->soc->num_supplies, - sizeof(*xudc->supplies), GFP_KERNEL); + xudc->supplies = devm_kzalloc_objs(&pdev->dev, *xudc->supplies, + xudc->soc->num_supplies); if (!xudc->supplies) return -ENOMEM; diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c index bef06fe7543bab..8abe40d12ad24a 100644 --- a/drivers/usb/gadget/udc/udc-xilinx.c +++ b/drivers/usb/gadget/udc/udc-xilinx.c @@ -2067,13 +2067,12 @@ static int xudc_probe(struct platform_device *pdev) u32 ier; u8 *buff; - udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); + udc = devm_kzalloc_obj(&pdev->dev, *udc); if (!udc) return -ENOMEM; /* Create a dummy request for GET_STATUS, SET_ADDRESS */ - udc->req = devm_kzalloc(&pdev->dev, sizeof(struct xusb_req), - GFP_KERNEL); + udc->req = devm_kzalloc_obj(&pdev->dev, struct xusb_req); if (!udc->req) return -ENOMEM; diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c index 519386255886c5..a6aa77189535e4 100644 --- a/drivers/usb/host/bcma-hcd.c +++ b/drivers/usb/host/bcma-hcd.c @@ -7,7 +7,7 @@ * Copyright 2015 Felix Fietkau * * Based on ssb-ohci driver - * Copyright 2007 Michael Buesch + * Copyright 2007 Michael Buesch * * Derived from the OHCI-PCI driver * Copyright 1999 Roman Weissgaerber @@ -399,8 +399,7 @@ static int bcma_hcd_probe(struct bcma_device *core) /* TODO: Probably need checks here; is the core connected? */ - usb_dev = devm_kzalloc(&core->dev, sizeof(struct bcma_hcd_device), - GFP_KERNEL); + usb_dev = devm_kzalloc_obj(&core->dev, struct bcma_hcd_device); if (!usb_dev) return -ENOMEM; usb_dev->core = core; diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c index 2d23690d72c507..200a51ecf462b5 100644 --- a/drivers/usb/host/ehci-sh.c +++ b/drivers/usb/host/ehci-sh.c @@ -103,8 +103,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev) hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); - priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct ehci_sh_priv); if (!priv) { ret = -ENOMEM; goto fail_request_resource; diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c index 73e76d0e697385..11c0d0e1f48d34 100644 --- a/drivers/usb/host/max3421-hcd.c +++ b/drivers/usb/host/max3421-hcd.c @@ -1845,7 +1845,7 @@ max3421_probe(struct spi_device *spi) } if (IS_ENABLED(CONFIG_OF) && dev->of_node) { - pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&spi->dev, *pdata); if (!pdata) { retval = -ENOMEM; goto error; diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 12fdb18934cf84..ccbb42b2013179 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c @@ -545,7 +545,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) if (ret) return ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index 45d026e85168b4..2a25307987a46d 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c @@ -348,7 +348,7 @@ static int ohci_pxa_of_init(struct platform_device *pdev) if (ret) return ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index ca96067e6d6dcb..d12cf85bbf22f6 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c @@ -4224,7 +4224,7 @@ static int oxu_drv_probe(struct platform_device *pdev) /* Allocate a driver data struct to hold useful info for both * SPH & OTG devices */ - info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, struct oxu_info); if (!info) { ret = -EFAULT; goto error; diff --git a/drivers/usb/host/ssb-hcd.c b/drivers/usb/host/ssb-hcd.c index 016987764afbfe..56d785c587c03f 100644 --- a/drivers/usb/host/ssb-hcd.c +++ b/drivers/usb/host/ssb-hcd.c @@ -6,7 +6,7 @@ * Copyright 2011-2012 Hauke Mehrtens * * Based on ssb-ohci driver - * Copyright 2007 Michael Buesch + * Copyright 2007 Michael Buesch * * Derived from the OHCI-PCI driver * Copyright 1999 Roman Weissgaerber @@ -165,8 +165,7 @@ static int ssb_hcd_probe(struct ssb_device *dev, if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32))) return -EOPNOTSUPP; - usb_dev = devm_kzalloc(dev->dev, sizeof(struct ssb_hcd_device), - GFP_KERNEL); + usb_dev = devm_kzalloc_obj(dev->dev, struct ssb_hcd_device); if (!usb_dev) return -ENOMEM; diff --git a/drivers/usb/host/xhci-histb.c b/drivers/usb/host/xhci-histb.c index fddb43bf63230e..aa6364d7b40668 100644 --- a/drivers/usb/host/xhci-histb.c +++ b/drivers/usb/host/xhci-histb.c @@ -199,7 +199,7 @@ static int xhci_histb_probe(struct platform_device *pdev) return -ENODEV; driver = &xhci_histb_hc_driver; - histb = devm_kzalloc(dev, sizeof(*histb), GFP_KERNEL); + histb = devm_kzalloc_obj(dev, *histb); if (!histb) return -ENOMEM; diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c index 60af5fe29bd49a..6a5a42eccbca84 100644 --- a/drivers/usb/host/xhci-mtk.c +++ b/drivers/usb/host/xhci-mtk.c @@ -524,7 +524,7 @@ static int xhci_mtk_probe(struct platform_device *pdev) return -ENODEV; driver = &xhci_mtk_hc_driver; - mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); + mtk = devm_kzalloc_obj(dev, *mtk); if (!mtk) return -ENOMEM; diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 50d733b2ad7191..1a14aea58b0b72 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -937,13 +937,13 @@ static int tegra_xusb_init_context(struct tegra_xusb *tegra) { const struct tegra_xusb_context_soc *soc = tegra->soc->context; - tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, - sizeof(u32), GFP_KERNEL); + tegra->context.ipfs = devm_kzalloc_objs(tegra->dev, u32, + soc->ipfs.num_offsets); if (!tegra->context.ipfs) return -ENOMEM; - tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, - sizeof(u32), GFP_KERNEL); + tegra->context.fpci = devm_kzalloc_objs(tegra->dev, u32, + soc->fpci.num_offsets); if (!tegra->context.fpci) return -ENOMEM; @@ -1509,8 +1509,8 @@ static int tegra_xusb_init_usb_phy(struct tegra_xusb *tegra) { unsigned int i; - tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, - sizeof(*tegra->usbphy), GFP_KERNEL); + tegra->usbphy = devm_kzalloc_objs(tegra->dev, *tegra->usbphy, + tegra->num_usb_phys); if (!tegra->usbphy) return -ENOMEM; @@ -1560,9 +1560,8 @@ static int tegra_xusb_setup_wakeup(struct platform_device *pdev, struct tegra_xu if (tegra->soc->max_num_wakes == 0) return 0; - tegra->wake_irqs = devm_kcalloc(tegra->dev, - tegra->soc->max_num_wakes, - sizeof(*tegra->wake_irqs), GFP_KERNEL); + tegra->wake_irqs = devm_kzalloc_objs(tegra->dev, *tegra->wake_irqs, + tegra->soc->max_num_wakes); if (!tegra->wake_irqs) return -ENOMEM; @@ -1606,7 +1605,7 @@ static int tegra_xusb_probe(struct platform_device *pdev) BUILD_BUG_ON(sizeof(struct tegra_xusb_fw_header) != 256); - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); + tegra = devm_kzalloc_obj(&pdev->dev, *tegra); if (!tegra) return -ENOMEM; @@ -1762,8 +1761,8 @@ static int tegra_xusb_probe(struct platform_device *pdev) goto put_powerdomains; } - tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, - sizeof(*tegra->supplies), GFP_KERNEL); + tegra->supplies = devm_kzalloc_objs(&pdev->dev, *tegra->supplies, + tegra->soc->num_supplies); if (!tegra->supplies) { err = -ENOMEM; goto put_powerdomains; @@ -1786,8 +1785,8 @@ static int tegra_xusb_probe(struct platform_device *pdev) tegra->num_phys += tegra->soc->phy_types[i].num; } - tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, - sizeof(*tegra->phys), GFP_KERNEL); + tegra->phys = devm_kzalloc_objs(&pdev->dev, *tegra->phys, + tegra->num_phys); if (!tegra->phys) { err = -ENOMEM; goto put_powerdomains; diff --git a/drivers/usb/isp1760/isp1760-core.c b/drivers/usb/isp1760/isp1760-core.c index af88f4fe00d27b..89ae81f0c18789 100644 --- a/drivers/usb/isp1760/isp1760-core.c +++ b/drivers/usb/isp1760/isp1760-core.c @@ -504,7 +504,7 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags, (!udc_enabled || !IS_ENABLED(CONFIG_USB_ISP1761_UDC))) return -ENODEV; - isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c index 9b6e10177f80c8..0bab02cf9c70b4 100644 --- a/drivers/usb/misc/lvstest.c +++ b/drivers/usb/misc/lvstest.c @@ -412,7 +412,7 @@ static int lvs_rh_probe(struct usb_interface *intf, return -EINVAL; } - lvs = devm_kzalloc(&intf->dev, sizeof(*lvs), GFP_KERNEL); + lvs = devm_kzalloc_obj(&intf->dev, *lvs); if (!lvs) return -ENOMEM; diff --git a/drivers/usb/misc/onboard_usb_dev.c b/drivers/usb/misc/onboard_usb_dev.c index c604062404162e..0606d405c16f11 100644 --- a/drivers/usb/misc/onboard_usb_dev.c +++ b/drivers/usb/misc/onboard_usb_dev.c @@ -432,7 +432,7 @@ static int onboard_dev_probe(struct platform_device *pdev) struct device_node *i2c_node; int err; - onboard_dev = devm_kzalloc(dev, sizeof(*onboard_dev), GFP_KERNEL); + onboard_dev = devm_kzalloc_obj(dev, *onboard_dev); if (!onboard_dev) return -ENOMEM; diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c index a7b9ed4ac07156..73f9fac22e19aa 100644 --- a/drivers/usb/misc/qcom_eud.c +++ b/drivers/usb/misc/qcom_eud.c @@ -194,7 +194,7 @@ static int eud_probe(struct platform_device *pdev) struct resource *res; int ret; - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c index fcb627b49eac65..6a84ba72190717 100644 --- a/drivers/usb/misc/usb-ljca.c +++ b/drivers/usb/misc/usb-ljca.c @@ -763,7 +763,7 @@ static int ljca_probe(struct usb_interface *interface, struct ljca_adapter *adap; int ret; - adap = devm_kzalloc(dev, sizeof(*adap), GFP_KERNEL); + adap = devm_kzalloc_obj(dev, *adap); if (!adap) return -ENOMEM; diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c index fb0693742f0182..81bba33e66a75b 100644 --- a/drivers/usb/misc/usb251xb.c +++ b/drivers/usb/misc/usb251xb.c @@ -700,7 +700,7 @@ static int usb251xb_i2c_probe(struct i2c_client *i2c) { struct usb251xb *hub; - hub = devm_kzalloc(&i2c->dev, sizeof(struct usb251xb), GFP_KERNEL); + hub = devm_kzalloc_obj(&i2c->dev, struct usb251xb); if (!hub) return -ENOMEM; @@ -773,7 +773,7 @@ static int usb251xb_plat_probe(struct platform_device *pdev) { struct usb251xb *hub; - hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL); + hub = devm_kzalloc_obj(&pdev->dev, *hub); if (!hub) return -ENOMEM; diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index 759770a1326061..9f356b4bd84e37 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c @@ -298,7 +298,7 @@ static int usb3503_i2c_probe(struct i2c_client *i2c) struct usb3503 *hub; int err; - hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL); + hub = devm_kzalloc_obj(&i2c->dev, struct usb3503); if (!hub) return -ENOMEM; @@ -326,7 +326,7 @@ static int usb3503_platform_probe(struct platform_device *pdev) { struct usb3503 *hub; - hub = devm_kzalloc(&pdev->dev, sizeof(struct usb3503), GFP_KERNEL); + hub = devm_kzalloc_obj(&pdev->dev, struct usb3503); if (!hub) return -ENOMEM; hub->dev = &pdev->dev; diff --git a/drivers/usb/misc/usb4604.c b/drivers/usb/misc/usb4604.c index 2ae9656715e016..d3505288e7ba78 100644 --- a/drivers/usb/misc/usb4604.c +++ b/drivers/usb/misc/usb4604.c @@ -101,7 +101,7 @@ static int usb4604_i2c_probe(struct i2c_client *i2c) { struct usb4604 *hub; - hub = devm_kzalloc(&i2c->dev, sizeof(*hub), GFP_KERNEL); + hub = devm_kzalloc_obj(&i2c->dev, *hub); if (!hub) return -ENOMEM; diff --git a/drivers/usb/misc/usbio.c b/drivers/usb/misc/usbio.c index fe093e7760d5ef..7b5f8669aee35c 100644 --- a/drivers/usb/misc/usbio.c +++ b/drivers/usb/misc/usbio.c @@ -555,7 +555,7 @@ static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *i struct usbio_fwver fwver; int ret; - usbio = devm_kzalloc(dev, sizeof(*usbio), GFP_KERNEL); + usbio = devm_kzalloc_obj(dev, *usbio); if (!usbio) return -ENOMEM; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 990e2e8e6bc2ab..386fcb5d628e8c 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -926,7 +926,7 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb) struct mtu3 *mtu = NULL; int ret = -ENOMEM; - mtu = devm_kzalloc(dev, sizeof(struct mtu3), GFP_KERNEL); + mtu = devm_kzalloc_obj(dev, struct mtu3); if (mtu == NULL) return -ENOMEM; diff --git a/drivers/usb/mtu3/mtu3_debugfs.c b/drivers/usb/mtu3/mtu3_debugfs.c index c003049bafbfb5..1651614231c724 100644 --- a/drivers/usb/mtu3/mtu3_debugfs.c +++ b/drivers/usb/mtu3/mtu3_debugfs.c @@ -129,7 +129,7 @@ static void mtu3_debugfs_regset(struct mtu3 *mtu, void __iomem *base, struct debugfs_regset32 *regset; struct mtu3_regset *mregs; - mregs = devm_kzalloc(mtu->dev, sizeof(*mregs), GFP_KERNEL); + mregs = devm_kzalloc_obj(mtu->dev, *mregs); if (!mregs) return; @@ -149,7 +149,7 @@ static void mtu3_debugfs_ep_regset(struct mtu3 *mtu, struct mtu3_ep *mep, int epnum = mep->epnum; int in = mep->is_in; - regs = devm_kcalloc(mtu->dev, 7, sizeof(*regs), GFP_KERNEL); + regs = devm_kzalloc_objs(mtu->dev, *regs, 7); if (!regs) return; diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index b4f4c776adb98a..e50e32c27a4b69 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -243,8 +243,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) ssusb->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); if (ssusb->num_phys > 0) { - ssusb->phys = devm_kcalloc(dev, ssusb->num_phys, - sizeof(*ssusb->phys), GFP_KERNEL); + ssusb->phys = devm_kzalloc_objs(dev, *ssusb->phys, + ssusb->num_phys); if (!ssusb->phys) return -ENOMEM; } else { @@ -332,7 +332,7 @@ static int mtu3_probe(struct platform_device *pdev) int ret = -ENOMEM; /* all elements are set to ZERO as default value */ - ssusb = devm_kzalloc(dev, sizeof(*ssusb), GFP_KERNEL); + ssusb = devm_kzalloc_obj(dev, *ssusb); if (!ssusb) return -ENOMEM; diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index 6c859a1a11d042..bd7ba674140b84 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c @@ -521,7 +521,7 @@ static int da8xx_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int ret; - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) return -ENOMEM; @@ -540,7 +540,7 @@ static int da8xx_probe(struct platform_device *pdev) glue->clk = clk; if (IS_ENABLED(CONFIG_OF) && np) { - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c index c770ba576f05b6..c5f2a1c8d14703 100644 --- a/drivers/usb/musb/jz4740.c +++ b/drivers/usb/musb/jz4740.c @@ -241,7 +241,7 @@ static int jz4740_probe(struct platform_device *pdev) struct clk *clk; int ret; - glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(dev, *glue); if (!glue) return -ENOMEM; diff --git a/drivers/usb/musb/mediatek.c b/drivers/usb/musb/mediatek.c index c6cbe718b1da2f..45eea9aaa82127 100644 --- a/drivers/usb/musb/mediatek.c +++ b/drivers/usb/musb/mediatek.c @@ -406,12 +406,12 @@ static int mtk_musb_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; int ret; - glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(dev, *glue); if (!glue) return -ENOMEM; glue->dev = dev; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/usb/musb/mpfs.c b/drivers/usb/musb/mpfs.c index 587127abd30a8e..1ec93af9e5f5e7 100644 --- a/drivers/usb/musb/mpfs.c +++ b/drivers/usb/musb/mpfs.c @@ -262,7 +262,7 @@ static int mpfs_probe(struct platform_device *pdev) struct clk *clk; int ret; - glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(dev, *glue); if (!glue) return -ENOMEM; @@ -294,7 +294,7 @@ static int mpfs_probe(struct platform_device *pdev) glue->musb = musb_pdev; glue->clk = clk; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) { ret = -ENOMEM; goto err_clk_disable; diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 73ac25f53698f4..9b63b56edc4531 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -2144,7 +2144,7 @@ static struct musb *allocate_instance(struct device *dev, int epnum; int ret; - musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL); + musb = devm_kzalloc_obj(dev, *musb); if (!musb) return NULL; @@ -2257,7 +2257,7 @@ int musb_queue_resume_work(struct musb *musb, is_suspended = musb->is_runtime_suspended; if (is_suspended) { - w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC); + w = devm_kzalloc_obj(musb->controller, *w, GFP_ATOMIC); if (!w) { error = -ENOMEM; goto out_unlock; diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index efd1f0dbb92640..91d8712efa41b1 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -794,7 +794,7 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, goto err; } - config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(&parent->dev, *config); if (!config) { ret = -ENOMEM; goto err; @@ -906,7 +906,7 @@ static int dsps_probe(struct platform_device *pdev) dsps_ops.read_fifo = dsps_read_fifo32; /* allocate glue */ - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) return -ENOMEM; diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 6e749faac33cbf..8d2c5b2cd65201 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -315,7 +315,7 @@ static int omap2430_probe(struct platform_device *pdev) if (!np) return -ENODEV; - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) return -ENOMEM; @@ -343,15 +343,15 @@ static int omap2430_probe(struct platform_device *pdev) glue->status = MUSB_UNKNOWN; glue->control_otghs = ERR_PTR(-ENODEV); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) goto err_put_musb; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) goto err_put_musb; - config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(&pdev->dev, *config); if (!config) goto err_put_musb; diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c index a6bd3e968cc733..a17b1c150626b7 100644 --- a/drivers/usb/musb/sunxi.c +++ b/drivers/usb/musb/sunxi.c @@ -688,7 +688,7 @@ static int sunxi_musb_probe(struct platform_device *pdev) return -EINVAL; } - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) return -ENOMEM; diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 1d9571f24a5667..86e5ddf7dbdbff 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c @@ -1228,7 +1228,7 @@ static int tusb_probe(struct platform_device *pdev) struct platform_device_info pinfo; int ret; - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) return -ENOMEM; diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index 8c2a43d992f5c9..1a9f0f12983207 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c @@ -192,7 +192,7 @@ ux500_of_probe(struct platform_device *pdev, struct device_node *np) const char *mode; int strlen; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) return NULL; @@ -236,7 +236,7 @@ static int ux500_probe(struct platform_device *pdev) } } - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); + glue = devm_kzalloc_obj(&pdev->dev, *glue); if (!glue) goto err0; diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index e2e06e57dced55..5bd78e8f5b24d9 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -875,11 +875,11 @@ static int ab8500_usb_probe(struct platform_device *pdev) return -ENODEV; } - ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL); + ab = devm_kzalloc_obj(&pdev->dev, *ab); if (!ab) return -ENOMEM; - otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(&pdev->dev, *otg); if (!otg) return -ENOMEM; diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c index ada508be090a78..e2889d288d3058 100644 --- a/drivers/usb/phy/phy-am335x-control.c +++ b/drivers/usb/phy/phy-am335x-control.c @@ -159,7 +159,7 @@ static int am335x_control_usb_probe(struct platform_device *pdev) phy_ctrl = of_id->data; - ctrl_usb = devm_kzalloc(&pdev->dev, sizeof(*ctrl_usb), GFP_KERNEL); + ctrl_usb = devm_kzalloc_obj(&pdev->dev, *ctrl_usb); if (!ctrl_usb) return -ENOMEM; diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c index ca9353dad71aa2..a107e86ef4d821 100644 --- a/drivers/usb/phy/phy-am335x.c +++ b/drivers/usb/phy/phy-am335x.c @@ -41,7 +41,7 @@ static int am335x_phy_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL); + am_phy = devm_kzalloc_obj(dev, *am_phy); if (!am_phy) return -ENOMEM; diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index a41671eda2a144..76641c385b5e7f 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c @@ -216,8 +216,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop) if (nop->gpiod_reset) gpiod_direction_output(nop->gpiod_reset, 1); - nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg), - GFP_KERNEL); + nop->phy.otg = devm_kzalloc_obj(dev, *nop->phy.otg); if (!nop->phy.otg) return -ENOMEM; @@ -267,7 +266,7 @@ static int usb_phy_generic_probe(struct platform_device *pdev) struct usb_phy_generic *nop; int err; - nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); + nop = devm_kzalloc_obj(dev, *nop); if (!nop) return -ENOMEM; diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c index c0135a30cabd11..60b7c1219dd2c7 100644 --- a/drivers/usb/phy/phy-gpio-vbus-usb.c +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c @@ -236,13 +236,11 @@ static int gpio_vbus_probe(struct platform_device *pdev) int err, irq; unsigned long irqflags; - gpio_vbus = devm_kzalloc(&pdev->dev, sizeof(struct gpio_vbus_data), - GFP_KERNEL); + gpio_vbus = devm_kzalloc_obj(&pdev->dev, struct gpio_vbus_data); if (!gpio_vbus) return -ENOMEM; - gpio_vbus->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), - GFP_KERNEL); + gpio_vbus->phy.otg = devm_kzalloc_obj(&pdev->dev, struct usb_otg); if (!gpio_vbus->phy.otg) return -ENOMEM; diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c index 73cc70e958dea6..bd8a556b2fbd66 100644 --- a/drivers/usb/phy/phy-isp1301.c +++ b/drivers/usb/phy/phy-isp1301.c @@ -97,7 +97,7 @@ static int isp1301_probe(struct i2c_client *client) struct isp1301 *isp; struct usb_phy *phy; - isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL); + isp = devm_kzalloc_obj(&client->dev, *isp); if (!isp) return -ENOMEM; diff --git a/drivers/usb/phy/phy-keystone.c b/drivers/usb/phy/phy-keystone.c index 51155c5513d3c6..ca8759bce891bb 100644 --- a/drivers/usb/phy/phy-keystone.c +++ b/drivers/usb/phy/phy-keystone.c @@ -68,7 +68,7 @@ static int keystone_usbphy_probe(struct platform_device *pdev) struct keystone_usbphy *k_phy; int ret; - k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL); + k_phy = devm_kzalloc_obj(dev, *k_phy); if (!k_phy) return -ENOMEM; diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 7069dd3f4d0d94..d899369d2d927a 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -773,7 +773,7 @@ static int mxs_phy_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(clk), "can't get the clock\n"); - mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL); + mxs_phy = devm_kzalloc_obj(&pdev->dev, *mxs_phy); if (!mxs_phy) return -ENOMEM; diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c index 6e6ef8c0bc7ed7..84330ee0af6584 100644 --- a/drivers/usb/phy/phy-omap-otg.c +++ b/drivers/usb/phy/phy-omap-otg.c @@ -98,7 +98,7 @@ static int omap_otg_probe(struct platform_device *pdev) if (IS_ERR(extcon)) return PTR_ERR(extcon); - otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL); + otg_dev = devm_kzalloc_obj(&pdev->dev, *otg_dev); if (!otg_dev) return -ENOMEM; diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c index 88607d0edb0148..3db327eaf90bee 100644 --- a/drivers/usb/phy/phy-tahvo.c +++ b/drivers/usb/phy/phy-tahvo.c @@ -322,12 +322,11 @@ static int tahvo_usb_probe(struct platform_device *pdev) struct tahvo_usb *tu; int ret; - tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); + tu = devm_kzalloc_obj(&pdev->dev, *tu); if (!tu) return -ENOMEM; - tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), - GFP_KERNEL); + tu->phy.otg = devm_kzalloc_obj(&pdev->dev, *tu->phy.otg); if (!tu->phy.otg) return -ENOMEM; diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index 00443a7beaeb05..7b37f61b4f401c 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c @@ -1345,8 +1345,7 @@ static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, return -ENOMEM; } - tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), - GFP_KERNEL); + tegra_phy->config = devm_kzalloc_obj(&pdev->dev, *config); if (!tegra_phy->config) return -ENOMEM; @@ -1497,7 +1496,7 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) struct usb_phy *phy; int err; - tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); + tegra_phy = devm_kzalloc_obj(&pdev->dev, *tegra_phy); if (!tegra_phy) return -ENOMEM; diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c index 8c09db750bfd63..9bfcb2c1dfd0ee 100644 --- a/drivers/usb/phy/phy-twl6030-usb.c +++ b/drivers/usb/phy/phy-twl6030-usb.c @@ -338,7 +338,7 @@ static int twl6030_usb_probe(struct platform_device *pdev) return -EINVAL; } - twl = devm_kzalloc(dev, sizeof(*twl), GFP_KERNEL); + twl = devm_kzalloc_obj(dev, *twl); if (!twl) return -ENOMEM; diff --git a/drivers/usb/phy/phy-ulpi.c b/drivers/usb/phy/phy-ulpi.c index 4df63e67bb37de..dbb26680e0288c 100644 --- a/drivers/usb/phy/phy-ulpi.c +++ b/drivers/usb/phy/phy-ulpi.c @@ -263,11 +263,11 @@ devm_otg_ulpi_create(struct device *dev, struct usb_phy *phy; struct usb_otg *otg; - phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + phy = devm_kzalloc_obj(dev, *phy); if (!phy) return NULL; - otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); + otg = devm_kzalloc_obj(dev, *otg); if (!otg) { devm_kfree(dev, phy); return NULL; diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 51d3035f82bedd..22a5175dcceb9b 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -630,7 +630,7 @@ static int usbhs_probe(struct platform_device *pdev) return irq; /* usb private data */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c index cd2e026dcb22f1..2f3d85ca8a7cc1 100644 --- a/drivers/usb/roles/intel-xhci-usb-role-switch.c +++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c @@ -156,7 +156,7 @@ static int intel_xhci_usb_probe(struct platform_device *pdev) struct resource *res; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index dcceb95d7d99fc..9a3ede35a3d9ea 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -915,7 +915,7 @@ static int f81232_port_probe(struct usb_serial_port *port) { struct f81232_private *priv; - priv = devm_kzalloc(&port->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&port->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c index 0037767e4bbf72..8fc60c4d616604 100644 --- a/drivers/usb/serial/f81534.c +++ b/drivers/usb/serial/f81534.c @@ -851,8 +851,7 @@ static int f81534_calc_num_ports(struct usb_serial *serial, return -ENODEV; } - serial_priv = devm_kzalloc(&serial->interface->dev, - sizeof(*serial_priv), GFP_KERNEL); + serial_priv = devm_kzalloc_obj(&serial->interface->dev, *serial_priv); if (!serial_priv) return -ENOMEM; @@ -1357,7 +1356,7 @@ static int f81534_port_probe(struct usb_serial_port *port) u8 value; serial_priv = usb_get_serial_data(port->serial); - port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL); + port_priv = devm_kzalloc_obj(&port->dev, *port_priv); if (!port_priv) return -ENOMEM; diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 319704e645288f..953e24620bb1b3 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -1419,8 +1419,7 @@ static int mxuport_port_probe(struct usb_serial_port *port) struct mxuport_port *mxport; int err; - mxport = devm_kzalloc(&port->dev, sizeof(struct mxuport_port), - GFP_KERNEL); + mxport = devm_kzalloc_obj(&port->dev, struct mxuport_port); if (!mxport) return -ENOMEM; diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c index a9358e04ab4b63..fea2614e767c70 100644 --- a/drivers/usb/storage/ene_ub6250.c +++ b/drivers/usb/storage/ene_ub6250.c @@ -805,12 +805,10 @@ static int ms_lib_alloc_logicalmap(struct us_data *us) u32 i; struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; - info->MS_Lib.Phy2LogMap = kmalloc_array(info->MS_Lib.NumberOfPhyBlock, - sizeof(u16), - GFP_KERNEL); - info->MS_Lib.Log2PhyMap = kmalloc_array(info->MS_Lib.NumberOfLogBlock, - sizeof(u16), - GFP_KERNEL); + info->MS_Lib.Phy2LogMap = kmalloc_objs(u16, + info->MS_Lib.NumberOfPhyBlock); + info->MS_Lib.Log2PhyMap = kmalloc_objs(u16, + info->MS_Lib.NumberOfLogBlock); if ((info->MS_Lib.Phy2LogMap == NULL) || (info->MS_Lib.Log2PhyMap == NULL)) { ms_lib_free_logicalmap(us); diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index 51c92dd887aba6..4a566388bd6a59 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -791,7 +791,7 @@ int dp_altmode_probe(struct typec_altmode *alt) return -ENODEV; } - dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(&alt->dev, *dp); if (!dp) { typec_altmode_put_plug(plug); return -ENOMEM; diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/altmodes/thunderbolt.c index 2e1b1a1da7d9f8..0fb21c6fac5891 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -274,7 +274,7 @@ static int tbt_altmode_probe(struct typec_altmode *alt) { struct tbt_altmode *tbt; - tbt = devm_kzalloc(&alt->dev, sizeof(*tbt), GFP_KERNEL); + tbt = devm_kzalloc_obj(&alt->dev, *tbt); if (!tbt) return -ENOMEM; diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c index 06c25af094b3e0..6f9c15ee0d8699 100644 --- a/drivers/usb/typec/anx7411.c +++ b/drivers/usb/typec/anx7411.c @@ -1468,7 +1468,7 @@ static int anx7411_i2c_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return -ENODEV; - plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + plat = devm_kzalloc_obj(dev, *plat); if (!plat) return -ENOMEM; diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c index a717d0f8a4e563..60d6de9ba33995 100644 --- a/drivers/usb/typec/hd3ss3220.c +++ b/drivers/usb/typec/hd3ss3220.c @@ -400,8 +400,7 @@ static int hd3ss3220_probe(struct i2c_client *client) unsigned int data; int ret; - hd3ss3220 = devm_kzalloc(&client->dev, sizeof(struct hd3ss3220), - GFP_KERNEL); + hd3ss3220 = devm_kzalloc_obj(&client->dev, struct hd3ss3220); if (!hd3ss3220) return -ENOMEM; diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c index bea0c1deec94d5..88783f9ed44cad 100644 --- a/drivers/usb/typec/mux/fsa4480.c +++ b/drivers/usb/typec/mux/fsa4480.c @@ -259,7 +259,7 @@ static int fsa4480_probe(struct i2c_client *client) int val = 0; int ret; - fsa = devm_kzalloc(dev, sizeof(*fsa), GFP_KERNEL); + fsa = devm_kzalloc_obj(dev, *fsa); if (!fsa) return -ENOMEM; diff --git a/drivers/usb/typec/mux/gpio-sbu-mux.c b/drivers/usb/typec/mux/gpio-sbu-mux.c index b1aa976aca240f..8a8aa7470df4ed 100644 --- a/drivers/usb/typec/mux/gpio-sbu-mux.c +++ b/drivers/usb/typec/mux/gpio-sbu-mux.c @@ -105,7 +105,7 @@ static int gpio_sbu_mux_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct gpio_sbu_mux *sbu_mux; - sbu_mux = devm_kzalloc(dev, sizeof(*sbu_mux), GFP_KERNEL); + sbu_mux = devm_kzalloc_obj(dev, *sbu_mux); if (!sbu_mux) return -ENOMEM; diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c index 219a32da134808..18e6e92584e16b 100644 --- a/drivers/usb/typec/mux/intel_pmc_mux.c +++ b/drivers/usb/typec/mux/intel_pmc_mux.c @@ -745,7 +745,7 @@ static int pmc_usb_probe(struct platform_device *pdev) return -ERANGE; } - pmc = devm_kzalloc(&pdev->dev, struct_size(pmc, port, num_ports), GFP_KERNEL); + pmc = devm_kzalloc_flex(&pdev->dev, *pmc, port, num_ports); if (!pmc) return -ENOMEM; diff --git a/drivers/usb/typec/mux/it5205.c b/drivers/usb/typec/mux/it5205.c index 2ab2ba6a3cbdde..d78f41e59be5be 100644 --- a/drivers/usb/typec/mux/it5205.c +++ b/drivers/usb/typec/mux/it5205.c @@ -178,7 +178,7 @@ static int it5205_probe(struct i2c_client *client) u32 val, chipid = 0; int i, ret; - it = devm_kzalloc(dev, sizeof(*it), GFP_KERNEL); + it = devm_kzalloc_obj(dev, *it); if (!it) return -ENOMEM; diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c index d1fa26ff442c27..00b2a1784e6cc8 100644 --- a/drivers/usb/typec/mux/nb7vpq904m.c +++ b/drivers/usb/typec/mux/nb7vpq904m.c @@ -391,7 +391,7 @@ static int nb7vpq904m_probe(struct i2c_client *client) struct nb7vpq904m *nb7; int ret; - nb7 = devm_kzalloc(dev, sizeof(*nb7), GFP_KERNEL); + nb7 = devm_kzalloc_obj(dev, *nb7); if (!nb7) return -ENOMEM; diff --git a/drivers/usb/typec/mux/pi3usb30532.c b/drivers/usb/typec/mux/pi3usb30532.c index 985683fe49e914..5728b539907acc 100644 --- a/drivers/usb/typec/mux/pi3usb30532.c +++ b/drivers/usb/typec/mux/pi3usb30532.c @@ -119,7 +119,7 @@ static int pi3usb30532_probe(struct i2c_client *client) struct pi3usb30532 *pi; int ret; - pi = devm_kzalloc(dev, sizeof(*pi), GFP_KERNEL); + pi = devm_kzalloc_obj(dev, *pi); if (!pi) return -ENOMEM; diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c index 2ec57cfe748a9c..66072a08d3bde2 100644 --- a/drivers/usb/typec/mux/ps883x.c +++ b/drivers/usb/typec/mux/ps883x.c @@ -416,7 +416,7 @@ static int ps883x_retimer_probe(struct i2c_client *client) unsigned int val; int ret; - retimer = devm_kzalloc(dev, sizeof(*retimer), GFP_KERNEL); + retimer = devm_kzalloc_obj(dev, *retimer); if (!retimer) return -ENOMEM; diff --git a/drivers/usb/typec/mux/ptn36502.c b/drivers/usb/typec/mux/ptn36502.c index afd16775dbafa9..0c39bfb863fa20 100644 --- a/drivers/usb/typec/mux/ptn36502.c +++ b/drivers/usb/typec/mux/ptn36502.c @@ -304,7 +304,7 @@ static int ptn36502_probe(struct i2c_client *client) struct ptn36502 *ptn; int ret; - ptn = devm_kzalloc(dev, sizeof(*ptn), GFP_KERNEL); + ptn = devm_kzalloc_obj(dev, *ptn); if (!ptn) return -ENOMEM; diff --git a/drivers/usb/typec/mux/tusb1046.c b/drivers/usb/typec/mux/tusb1046.c index 34ef81f75693e0..55a7b246f3f999 100644 --- a/drivers/usb/typec/mux/tusb1046.c +++ b/drivers/usb/typec/mux/tusb1046.c @@ -126,7 +126,7 @@ static int tusb1046_i2c_probe(struct i2c_client *client) struct tusb1046_priv *priv; int ret = 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/typec/mux/wcd939x-usbss.c b/drivers/usb/typec/mux/wcd939x-usbss.c index 73db3aa3cec4e6..ca806041aa0a1a 100644 --- a/drivers/usb/typec/mux/wcd939x-usbss.c +++ b/drivers/usb/typec/mux/wcd939x-usbss.c @@ -590,7 +590,7 @@ static int wcd939x_usbss_probe(struct i2c_client *client) struct wcd939x_usbss *usbss; int ret; - usbss = devm_kzalloc(dev, sizeof(*usbss), GFP_KERNEL); + usbss = devm_kzalloc_obj(dev, *usbss); if (!usbss) return -ENOMEM; diff --git a/drivers/usb/typec/rt1719.c b/drivers/usb/typec/rt1719.c index 0b0c23a0b014bd..354ecb25e97645 100644 --- a/drivers/usb/typec/rt1719.c +++ b/drivers/usb/typec/rt1719.c @@ -842,7 +842,7 @@ static int rt1719_probe(struct i2c_client *i2c) struct typec_capability typec_cap = { }; int ret; - data = devm_kzalloc(&i2c->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&i2c->dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/usb/typec/stusb160x.c b/drivers/usb/typec/stusb160x.c index 6d85b25b40bc0c..a2ec0565bd85da 100644 --- a/drivers/usb/typec/stusb160x.c +++ b/drivers/usb/typec/stusb160x.c @@ -638,7 +638,7 @@ static int stusb160x_probe(struct i2c_client *client) struct fwnode_handle *fwnode; int ret; - chip = devm_kzalloc(&client->dev, sizeof(struct stusb160x), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, struct stusb160x); if (!chip) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c index 3319f6a2b0c9b4..83bd287dadc7ee 100644 --- a/drivers/usb/typec/tcpm/fusb302.c +++ b/drivers/usb/typec/tcpm/fusb302.c @@ -1700,7 +1700,7 @@ static int fusb302_probe(struct i2c_client *client) "I2C/SMBus block functionality not supported!\n"); return -ENODEV; } - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c index d770e58bc16cff..58d1e6aae637d1 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c @@ -43,7 +43,7 @@ static int qcom_pmic_typec_probe(struct platform_device *pdev) if (!res) return -ENODEV; - tcpm = devm_kzalloc(dev, sizeof(*tcpm), GFP_KERNEL); + tcpm = devm_kzalloc_obj(dev, *tcpm); if (!tcpm) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c index 926fa017ebafc4..435e07659d6538 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c @@ -561,15 +561,14 @@ int qcom_pmic_typec_pdphy_probe(struct platform_device *pdev, struct pmic_typec_pdphy_irq_data *irq_data; int i, ret, irq; - pmic_typec_pdphy = devm_kzalloc(dev, sizeof(*pmic_typec_pdphy), GFP_KERNEL); + pmic_typec_pdphy = devm_kzalloc_obj(dev, *pmic_typec_pdphy); if (!pmic_typec_pdphy) return -ENOMEM; if (!res->nr_irqs || res->nr_irqs > PMIC_PDPHY_MAX_IRQS) return -EINVAL; - irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data), - GFP_KERNEL); + irq_data = devm_kzalloc_objs(dev, *irq_data, res->nr_irqs); if (!irq_data) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c index d3523435f3e018..b2ad31e85b5e6d 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c @@ -712,15 +712,14 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev, struct fwnode_handle *connector; int i, ret, irq; - pmic_typec_port = devm_kzalloc(dev, sizeof(*pmic_typec_port), GFP_KERNEL); + pmic_typec_port = devm_kzalloc_obj(dev, *pmic_typec_port); if (!pmic_typec_port) return -ENOMEM; if (!res->nr_irqs || res->nr_irqs > PMIC_TYPEC_MAX_IRQS) return -EINVAL; - irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data), - GFP_KERNEL); + irq_data = devm_kzalloc_objs(dev, *irq_data, res->nr_irqs); if (!irq_data) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 6717ac914c6a60..c6165466c54b66 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -847,7 +847,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) struct tcpci *tcpci; int err; - tcpci = devm_kzalloc(dev, sizeof(*tcpci), GFP_KERNEL); + tcpci = devm_kzalloc_obj(dev, *tcpci); if (!tcpci) return ERR_PTR(-ENOMEM); @@ -924,7 +924,7 @@ static int tcpci_probe(struct i2c_client *client) if (err && err != -ENODEV) return dev_err_probe(&client->dev, err, "Failed to get regulator\n"); - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index 52dbbbe53691ec..a19f52515429be 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -493,7 +493,7 @@ static int max_tcpci_probe(struct i2c_client *client) struct max_tcpci_chip *chip; u8 power_status; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c b/drivers/usb/typec/tcpm/tcpci_mt6360.c index d4010ea5183b04..ef7e235ae33d9c 100644 --- a/drivers/usb/typec/tcpm/tcpci_mt6360.c +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c @@ -141,7 +141,7 @@ static int mt6360_tcpc_probe(struct platform_device *pdev) struct mt6360_tcpc_info *mti; int ret; - mti = devm_kzalloc(&pdev->dev, sizeof(*mti), GFP_KERNEL); + mti = devm_kzalloc_obj(&pdev->dev, *mti); if (!mti) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpci_mt6370.c b/drivers/usb/typec/tcpm/tcpci_mt6370.c index 2e85cb05ed3776..fc8f1a0c3759cf 100644 --- a/drivers/usb/typec/tcpm/tcpci_mt6370.c +++ b/drivers/usb/typec/tcpm/tcpci_mt6370.c @@ -129,7 +129,7 @@ static int mt6370_tcpc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index af8356df6b98fa..0581659763a8d8 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -306,7 +306,7 @@ static int rt1711h_probe(struct i2c_client *client) TCPC_ALERT_CC_STATUS | TCPC_ALERT_RX_BUF_OVF | TCPC_ALERT_FAULT; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index d721baef52104f..bb90211660cae3 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -8376,22 +8376,22 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, struct fwnode_handle *fwnode } } - port->pds = devm_kcalloc(port->dev, port->pd_count, sizeof(struct usb_power_delivery *), - GFP_KERNEL); + port->pds = devm_kzalloc_objs(port->dev, struct usb_power_delivery *, + port->pd_count); if (!port->pds) { ret = -ENOMEM; goto put_capabilities; } - port->pd_list = devm_kcalloc(port->dev, port->pd_count, sizeof(struct pd_data *), - GFP_KERNEL); + port->pd_list = devm_kzalloc_objs(port->dev, struct pd_data *, + port->pd_count); if (!port->pd_list) { ret = -ENOMEM; goto put_capabilities; } for (i = 0; i < port->pd_count; i++) { - port->pd_list[i] = devm_kzalloc(port->dev, sizeof(struct pd_data), GFP_KERNEL); + port->pd_list[i] = devm_kzalloc_obj(port->dev, struct pd_data); if (!port->pd_list[i]) { ret = -ENOMEM; goto put_capabilities; @@ -8873,7 +8873,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) !tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit) return ERR_PTR(-EINVAL); - port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + port = devm_kzalloc_obj(dev, *port); if (!port) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/typec/tcpm/wcove.c b/drivers/usb/typec/tcpm/wcove.c index 0e5a3e277c3e43..ee2a348d1b7713 100644 --- a/drivers/usb/typec/tcpm/wcove.c +++ b/drivers/usb/typec/tcpm/wcove.c @@ -612,7 +612,7 @@ static int wcove_typec_probe(struct platform_device *pdev) int irq; int ret; - wcove = devm_kzalloc(&pdev->dev, sizeof(*wcove), GFP_KERNEL); + wcove = devm_kzalloc_obj(&pdev->dev, *wcove); if (!wcove) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c index c38eb678d5fe83..1a052524ed836a 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -263,7 +263,7 @@ static int cros_ucsi_probe(struct platform_device *pdev) struct cros_ucsi_data *udata; int ret; - udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); + udata = devm_kzalloc_obj(dev, *udata); if (!udata) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c index 572da7bbd29c73..c36ed27da21c8d 100644 --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c @@ -332,7 +332,7 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, if (IS_ERR(alt)) return alt; - dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL); + dp = devm_kzalloc_obj(&alt->dev, *dp); if (!dp) { typec_unregister_altmode(alt); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/typec/ucsi/thunderbolt.c b/drivers/usb/typec/ucsi/thunderbolt.c index 434d3d8ea5b6ee..6641d536197c3c 100644 --- a/drivers/usb/typec/ucsi/thunderbolt.c +++ b/drivers/usb/typec/ucsi/thunderbolt.c @@ -184,7 +184,7 @@ struct typec_altmode *ucsi_register_thunderbolt(struct ucsi_connector *con, if (IS_ERR(alt) || !override) return alt; - tbt = devm_kzalloc(&alt->dev, sizeof(*tbt), GFP_KERNEL); + tbt = devm_kzalloc_obj(&alt->dev, *tbt); if (!tbt) { typec_unregister_altmode(alt); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 5697ccc24ec3fc..2d079d7177ac54 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -233,7 +233,7 @@ static int ucsi_acpi_probe(struct platform_device *pdev) if (adev->dep_unmet) return -EPROBE_DEFER; - ua = devm_kzalloc(&pdev->dev, sizeof(*ua), GFP_KERNEL); + ua = devm_kzalloc_obj(&pdev->dev, *ua); if (!ua) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 3f12db95c7f468..96d0557a862dba 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -1466,7 +1466,7 @@ static int ucsi_ccg_probe(struct i2c_client *client) const char *fw_name; int status; - uc = devm_kzalloc(dev, sizeof(*uc), GFP_KERNEL); + uc = devm_kzalloc_obj(dev, *uc); if (!uc) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index 1db0c88d817e6d..1c64b3a3ca4f69 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -398,7 +398,7 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, const struct of_device_id *match; int ret; - ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL); + ucsi = devm_kzalloc_obj(dev, *ucsi); if (!ucsi) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c index 57b37fca150c23..54e5b6013ee6ed 100644 --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c @@ -413,8 +413,7 @@ static int gaokun_ucsi_ports_init(struct gaokun_ucsi *uec) gaokun_ec_ucsi_get_reg(uec->ec, &ureg); num_ports = ureg.num_ports; - uec->ports = devm_kcalloc(dev, num_ports, sizeof(*uec->ports), - GFP_KERNEL); + uec->ports = devm_kzalloc_objs(dev, *uec->ports, num_ports); if (!uec->ports) return -ENOMEM; @@ -500,7 +499,7 @@ static int gaokun_ucsi_probe(struct auxiliary_device *adev, struct gaokun_ucsi *uec; int ret; - uec = devm_kzalloc(dev, sizeof(*uec), GFP_KERNEL); + uec = devm_kzalloc_obj(dev, *uec); if (!uec) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c index 848ed459a6deb0..7341abe0f0b602 100644 --- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c +++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c @@ -618,7 +618,7 @@ static int ucsi_stm32g0_probe(struct i2c_client *client) struct ucsi_stm32g0 *g0; int ret; - g0 = devm_kzalloc(dev, sizeof(*g0), GFP_KERNEL); + g0 = devm_kzalloc_obj(dev, *g0); if (!g0) return -ENOMEM; diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c index bb7b09bc7c1c1f..91ea486c731a14 100644 --- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c @@ -221,7 +221,7 @@ static int yoga_c630_ucsi_probe(struct auxiliary_device *adev, struct yoga_c630_ucsi *uec; int ret; - uec = devm_kzalloc(&adev->dev, sizeof(*uec), GFP_KERNEL); + uec = devm_kzalloc_obj(&adev->dev, *uec); if (!uec) return -ENOMEM; diff --git a/drivers/usb/typec/wusb3801.c b/drivers/usb/typec/wusb3801.c index 6062875fb04a9d..fe231095e86db7 100644 --- a/drivers/usb/typec/wusb3801.c +++ b/drivers/usb/typec/wusb3801.c @@ -327,7 +327,7 @@ static int wusb3801_probe(struct i2c_client *client) const char *cap_str; int ret; - wusb3801 = devm_kzalloc(dev, sizeof(*wusb3801), GFP_KERNEL); + wusb3801 = devm_kzalloc_obj(dev, *wusb3801); if (!wusb3801) return -ENOMEM; diff --git a/drivers/vdpa/alibaba/eni_vdpa.c b/drivers/vdpa/alibaba/eni_vdpa.c index 1288402d3dd8b3..9910d283d72715 100644 --- a/drivers/vdpa/alibaba/eni_vdpa.c +++ b/drivers/vdpa/alibaba/eni_vdpa.c @@ -503,9 +503,8 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id) eni_vdpa->vdpa.vmap.dma_dev = &pdev->dev; eni_vdpa->queues = eni_vdpa_get_num_queues(eni_vdpa); - eni_vdpa->vring = devm_kcalloc(&pdev->dev, eni_vdpa->queues, - sizeof(*eni_vdpa->vring), - GFP_KERNEL); + eni_vdpa->vring = devm_kzalloc_objs(&pdev->dev, *eni_vdpa->vring, + eni_vdpa->queues); if (!eni_vdpa->vring) { ret = -ENOMEM; ENI_ERR(pdev, "failed to allocate virtqueues\n"); diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 8563fec2855d50..0fcb18b5f30ac9 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3059,7 +3059,15 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, bool teardown = !is_resumable(ndev); int err; - suspend_vqs(ndev, 0, ndev->cur_num_vqs); + if ((mvdev->status & VIRTIO_CONFIG_S_DRIVER_OK) && !mvdev->suspended) { + err = suspend_vqs(ndev, 0, ndev->cur_num_vqs); + if (err && !teardown) { + for (int i = 0; i < ndev->cur_num_vqs; i++) + resume_vqs(ndev, i, 1); + mlx5_vdpa_put_mr(mvdev, new_mr); + return err; + } + } if (teardown) { err = save_channels_info(ndev); if (err) { diff --git a/drivers/vdpa/octeon_ep/octep_vdpa_hw.c b/drivers/vdpa/octeon_ep/octep_vdpa_hw.c index 74240101c5052e..a8c657a6940f26 100644 --- a/drivers/vdpa/octeon_ep/octep_vdpa_hw.c +++ b/drivers/vdpa/octeon_ep/octep_vdpa_hw.c @@ -525,7 +525,8 @@ int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev) } oct_hw->nr_vring = vp_ioread16(&oct_hw->common_cfg->num_queues); - oct_hw->vqs = devm_kcalloc(&pdev->dev, oct_hw->nr_vring, sizeof(*oct_hw->vqs), GFP_KERNEL); + oct_hw->vqs = devm_kzalloc_objs(&pdev->dev, *oct_hw->vqs, + oct_hw->nr_vring); if (!oct_hw->vqs) return -ENOMEM; diff --git a/drivers/vdpa/octeon_ep/octep_vdpa_main.c b/drivers/vdpa/octeon_ep/octep_vdpa_main.c index 85a3d35ea1e474..984780f32218be 100644 --- a/drivers/vdpa/octeon_ep/octep_vdpa_main.c +++ b/drivers/vdpa/octeon_ep/octep_vdpa_main.c @@ -156,7 +156,7 @@ static int octep_request_irqs(struct octep_hw *oct_hw, irqreturn_t (*irq_handler else return 0; - oct_hw->irqs = devm_kcalloc(&pdev->dev, nb_irqs, sizeof(int), GFP_KERNEL); + oct_hw->irqs = devm_kzalloc_objs(&pdev->dev, int, nb_irqs); if (!oct_hw->irqs) return -ENOMEM; @@ -770,7 +770,7 @@ static int octep_vdpa_probe_vf(struct pci_dev *pdev) } pci_set_master(pdev); - mgmt_dev = devm_kzalloc(dev, sizeof(struct octep_vdpa_mgmt_dev), GFP_KERNEL); + mgmt_dev = devm_kzalloc_obj(dev, struct octep_vdpa_mgmt_dev); if (!mgmt_dev) return -ENOMEM; @@ -935,7 +935,7 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev) dev_err(dev, "No usable DMA configuration\n"); goto disable_pci; } - octpf = devm_kzalloc(dev, sizeof(*octpf), GFP_KERNEL); + octpf = devm_kzalloc_obj(dev, *octpf); if (!octpf) { ret = -ENOMEM; goto disable_pci; diff --git a/drivers/vdpa/solidrun/snet_ctrl.c b/drivers/vdpa/solidrun/snet_ctrl.c index e284c3a06717c9..09afa0487fd6a0 100644 --- a/drivers/vdpa/solidrun/snet_ctrl.c +++ b/drivers/vdpa/solidrun/snet_ctrl.c @@ -291,7 +291,6 @@ static int snet_send_ctrl_msg(struct snet *snet, u16 opcode, u16 vq_idx) /* Check for errors */ val = snet_read_ctrl(regs); - ret = SNET_VAL_TO_ERR(val); /* Clear the chunk ready bit */ val &= ~SNET_CTRL_CHUNK_RDY_MASK; @@ -301,6 +300,8 @@ static int snet_send_ctrl_msg(struct snet *snet, u16 opcode, u16 vq_idx) if (ret) SNET_WARN(pdev, "Timeout waiting for DPU to complete a control command, err %d\n", ret); + else + ret = SNET_VAL_TO_ERR(val); exit: mutex_unlock(&snet->ctrl_lock); diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 47c6c3d23f5c79..6455f837dd2637 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -1313,15 +1313,16 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info } err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq, 0, info->extack); - if (!err) + if (!err) { err = genlmsg_reply(msg, info); + msg = NULL; + } mdev_err: put_device(dev); dev_err: up_read(&vdpa_dev_lock); - if (err) - nlmsg_free(msg); + nlmsg_free(msg); return err; } diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index cfa88a60a38fd4..97d437d89524a1 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -638,6 +638,7 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, if (asid >= vdpasim->dev_attr.nas) return -EINVAL; + mutex_lock(&vdpasim->mutex); spin_lock(&vdpasim->iommu_lock); iommu = &vdpasim->iommu[asid]; @@ -652,11 +653,13 @@ static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid, goto err; } spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return 0; err: vhost_iotlb_reset(iommu); spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return ret; } @@ -713,6 +716,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, if (asid >= vdpasim->dev_attr.nas) return -EINVAL; + mutex_lock(&vdpasim->mutex); spin_lock(&vdpasim->iommu_lock); if (vdpasim->iommu_pt[asid]) { vhost_iotlb_reset(&vdpasim->iommu[asid]); @@ -721,6 +725,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, ret = vhost_iotlb_add_range_ctx(&vdpasim->iommu[asid], iova, iova + size - 1, pa, perm, opaque); spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return ret; } @@ -733,6 +738,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, if (asid >= vdpasim->dev_attr.nas) return -EINVAL; + mutex_lock(&vdpasim->mutex); spin_lock(&vdpasim->iommu_lock); if (vdpasim->iommu_pt[asid]) { vhost_iotlb_reset(&vdpasim->iommu[asid]); @@ -740,6 +746,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, } vhost_iotlb_del_range(&vdpasim->iommu[asid], iova, iova + size - 1); spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return 0; } diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c index b6c958224b7ceb..28a977248a0d34 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -76,6 +76,10 @@ int vduse_domain_set_map(struct vduse_iova_domain *domain, for (map = vhost_iotlb_itree_first(iotlb, start, last); map; map = vhost_iotlb_itree_next(map, start, last)) { map_file = (struct vdpa_map_file *)map->opaque; + if (!map_file || map_file->file == domain->file) { + ret = -EINVAL; + goto err; + } ret = vduse_iotlb_add_range(domain, map->start, map->last, map->addr, map->perm, map_file->file, @@ -226,6 +230,7 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) { u64 start = iova & PAGE_MASK; u64 last = start + PAGE_SIZE - 1; + struct vdpa_map_file *map_file; struct vhost_iotlb_map *map; struct page *page = NULL; @@ -234,6 +239,10 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) if (!map) goto out; + map_file = (struct vdpa_map_file *)map->opaque; + if (!map_file || map_file->file != domain->file) + goto out; + page = pfn_to_page((map->addr + iova - map->start) >> PAGE_SHIFT); get_page(page); out: @@ -579,7 +588,7 @@ static int vduse_domain_mmap(struct file *file, struct vm_area_struct *vma) { struct vduse_iova_domain *domain = file->private_data; - vm_flags_set(vma, VM_DONTDUMP | VM_DONTEXPAND); + vm_flags_set(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND); vma->vm_private_data = domain; vma->vm_ops = &vduse_domain_mmap_ops; diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 49a231bdf94893..f953353b50b4ab 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1430,14 +1431,10 @@ static void vduse_vq_update_effective_cpu(struct vduse_virtqueue *vq) { int curr_cpu = vq->irq_effective_cpu; - while (true) { - curr_cpu = cpumask_next(curr_cpu, &vq->irq_affinity); - if (cpu_online(curr_cpu)) - break; - - if (curr_cpu >= nr_cpu_ids) - curr_cpu = IRQ_UNBOUND; - } + curr_cpu = cpumask_next_and_wrap(curr_cpu, &vq->irq_affinity, + cpu_online_mask); + if (curr_cpu >= nr_cpu_ids) + curr_cpu = IRQ_UNBOUND; vq->irq_effective_cpu = curr_cpu; } @@ -1672,10 +1669,12 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, ret = 0; index = array_index_nospec(index, dev->vq_num); if (!vduse_vq_signal_irqfd(dev->vqs[index])) { + cpus_read_lock(); vduse_vq_update_effective_cpu(dev->vqs[index]); ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, dev->vqs[index]->irq_effective_cpu); + cpus_read_unlock(); } break; } diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c index f2eb654b1665a1..646efd9384fbaa 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -540,9 +540,8 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, goto err; } - vp_vdpa->vring = devm_kcalloc(&pdev->dev, vp_vdpa->queues, - sizeof(*vp_vdpa->vring), - GFP_KERNEL); + vp_vdpa->vring = devm_kzalloc_objs(&pdev->dev, *vp_vdpa->vring, + vp_vdpa->queues); if (!vp_vdpa->vring) { ret = -ENOMEM; dev_err(&pdev->dev, "Fail to allocate virtqueues\n"); diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 885fac5ed042ea..e44044449cef82 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -638,6 +638,16 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) return; } + /* + * Eventq buffers are device-writable only. A nonzero in count + * guarantees that out is within the bounds of vq->iov. + */ + if (unlikely(out || !in)) { + vq_err(vq, "Invalid event buffer: out %u, in %u\n", out, in); + vs->vs_events_missed = true; + return; + } + if ((vq->iov[out].iov_len != sizeof(struct virtio_scsi_event))) { vq_err(vq, "Expecting virtio_scsi_event, got %zu bytes\n", vq->iov[out].iov_len); @@ -660,19 +670,26 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) vhost_scsi_log_write(vq, vq_log, log_num); } -static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) +/* Caller must hold the event virtqueue mutex. */ +static void __vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) { - struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; struct vhost_scsi_evt *evt, *t; struct llist_node *llnode; - mutex_lock(&vq->mutex); - llnode = llist_del_all(&vs->vs_event_list); + llnode = llist_reverse_order(llist_del_all(&vs->vs_event_list)); llist_for_each_entry_safe(evt, t, llnode, list) { if (!drop) vhost_scsi_do_evt_work(vs, evt); vhost_scsi_free_evt(vs, evt); } +} + +static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) +{ + struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; + + mutex_lock(&vq->mutex); + __vhost_scsi_complete_events(vs, drop); mutex_unlock(&vq->mutex); } @@ -883,11 +900,16 @@ vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, vhost_scsi_revert_map_iov_to_sgl(iter, *sgl, sg); iov_iter_revert(iter, bytes); + /* + * pages[npages] is the first page not added to the SG list. + * The remaining data starts at offset in that page. + */ while (bytes) { - n = min_t(unsigned int, PAGE_SIZE, bytes); + n = min_t(unsigned int, PAGE_SIZE - offset, bytes); put_page(pages[npages++]); bytes -= n; + offset = 0; } return -EINVAL; @@ -937,7 +959,12 @@ vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter, } for_each_sgtable_sg(sg_table, sg, i) { - page = alloc_page(GFP_KERNEL); + /* + * Completion copies the full bounce buffer, including bytes the + * target did not write. This is already the slow fallback for + * misaligned I/O, so zeroing is acceptable here. + */ + page = alloc_page(GFP_KERNEL | __GFP_ZERO); if (!page) { ret = -ENOMEM; goto err; @@ -1534,9 +1561,17 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) * vhost_scsi_queue_data_in() and vhost_scsi_queue_status() */ cmd->tvc_vq_desc = vc.head; + /* + * vhost_scsi_mapal() maps the PI bytes into cmd->prot_table. + * It maps the remaining exp_data_len bytes into cmd->table, + * which is the data SGL passed to the target core. Its + * expected length must therefore exclude prot_bytes. + * + * sbc_check_prot() derives the data length for protected READ + * and WRITE commands from the CDB. + */ vhost_scsi_target_queue_cmd(nexus, cmd, cdb, lun, task_attr, - data_direction, - exp_data_len + prot_bytes); + data_direction, exp_data_len); ret = 0; err: /* @@ -1859,7 +1894,7 @@ vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq, llist_add(&evt->list, &vs->vs_event_list); if (!vhost_vq_work_queue(vq, &vs->vs_event_work)) - vhost_scsi_complete_events(vs, true); + __vhost_scsi_complete_events(vs, true); } static void vhost_scsi_evt_handle_kick(struct vhost_work *work) @@ -2105,6 +2140,9 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs, for (i = 0; i < vs->dev.nvqs; i++) { vq = &vs->vqs[i].vq; + if (i >= VHOST_SCSI_VQ_IO && !vs->vqs[i].scsi_cmds) + continue; + mutex_lock(&vq->mutex); vhost_vq_set_backend(vq, vs_tpg); vhost_vq_init_access(vq); @@ -2466,10 +2504,16 @@ vhost_scsi_ioctl(struct file *f, default: mutex_lock(&vs->dev.mutex); r = vhost_dev_ioctl(&vs->dev, ioctl, argp); - if (r == -ENOIOCTLCMD) - r = vhost_vring_ioctl(&vs->dev, ioctl, argp); - else + if (r == -ENOIOCTLCMD) { + if (vs->vs_tpg && + (ioctl == VHOST_SET_VRING_NUM || + ioctl == VHOST_SET_VRING_ADDR)) + r = -EBUSY; + else + r = vhost_vring_ioctl(&vs->dev, ioctl, argp); + } else { vhost_scsi_flush(vs); + } mutex_unlock(&vs->dev.mutex); return r; } diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c index 84ed9ea81219d3..65dc8c71336d52 100644 --- a/drivers/vhost/test.c +++ b/drivers/vhost/test.c @@ -287,6 +287,10 @@ static long vhost_test_set_backend(struct vhost_test *n, unsigned index, int fd) r = -EFAULT; goto err_vq; } + if (enable && !vq->kick) { + r = -EINVAL; + goto err_vq; + } if (!enable) { vhost_poll_stop(&vq->poll); backend = vhost_vq_get_backend(vq); diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ff7d9071917120..c912ac40ca3754 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -767,13 +767,46 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, if (ops->get_status(vdpa) & VIRTIO_CONFIG_S_DRIVER_OK) vhost_vdpa_unsetup_vq_irq(v, idx); + /* + * The parent caches call_ctx.ctx in cb.trigger without + * holding a reference, so it has to stop using it + * before vhost_vring_ioctl() drops the last one. + */ + cb.callback = NULL; + cb.private = NULL; + cb.trigger = NULL; + ops->set_vq_cb(vdpa, idx, &cb); + + /* + * A parent interrupt handler that loaded the callback + * before that store can still be running, so wait for + * it to finish with the context too. + */ + if (ops->get_vq_irq) { + int irq = ops->get_vq_irq(vdpa, idx); + + if (irq >= 0) + synchronize_irq(irq); + } } break; } r = vhost_vring_ioctl(&v->vdev, cmd, argp); - if (r) + if (r) { + /* + * A failure here means the swap never happened and the old + * context is still installed, so give the parent back the + * callback that was torn down above. + */ + if (cmd == VHOST_SET_VRING_CALL && vq->call_ctx.ctx) { + cb.callback = vhost_vdpa_virtqueue_cb; + cb.private = vq; + cb.trigger = vq->call_ctx.ctx; + ops->set_vq_cb(vdpa, idx, &cb); + } return r; + } switch (cmd) { case VHOST_SET_VRING_ADDR: @@ -972,20 +1005,14 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, { struct vhost_dev *dev = &v->vdev; struct vhost_iotlb_map *map; - struct page *page; - unsigned long pfn, pinned; while ((map = vhost_iotlb_itree_first(iotlb, start, last)) != NULL) { - pinned = PFN_DOWN(map->size); - for (pfn = PFN_DOWN(map->addr); - pinned > 0; pfn++, pinned--) { - page = pfn_to_page(pfn); - if (map->perm & VHOST_ACCESS_WO) - set_page_dirty_lock(page); - unpin_user_page(page); - } - atomic64_sub(PFN_DOWN(map->size), &dev->mm->pinned_vm); + /* Stop device access before releasing the pinned pages. */ vhost_vdpa_general_unmap(v, map, asid); + unpin_user_page_range_dirty_lock(pfn_to_page(PFN_DOWN(map->addr)), + PFN_DOWN(map->size), + map->perm & VHOST_ACCESS_WO); + atomic64_sub(PFN_DOWN(map->size), &dev->mm->pinned_vm); vhost_iotlb_map_free(iotlb, map); } } @@ -997,10 +1024,10 @@ static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, struct vdpa_map_file *map_file; while ((map = vhost_iotlb_itree_first(iotlb, start, last)) != NULL) { + vhost_vdpa_general_unmap(v, map, asid); map_file = (struct vdpa_map_file *)map->opaque; fput(map_file->file); kfree(map_file); - vhost_vdpa_general_unmap(v, map, asid); vhost_iotlb_map_free(iotlb, map); } } @@ -1074,21 +1101,39 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, return 0; } -static void vhost_vdpa_unmap(struct vhost_vdpa *v, - struct vhost_iotlb *iotlb, - u64 iova, u64 size) +static int vhost_vdpa_unmap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + u64 iova, u64 size) { struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + struct vhost_iotlb_map *map; + struct vhost_iotlb new_iotlb; u32 asid = iotlb_to_asid(iotlb); + u64 last = iova + size - 1; + int ret; - vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1, asid); + if (ops->set_map && !ops->dma_map) { + vhost_iotlb_init(&new_iotlb, iotlb->limit, iotlb->flags); + list_for_each_entry(map, &iotlb->list, link) { + if (map->start <= last && map->last >= iova) + continue; + ret = vhost_iotlb_add_range_ctx(&new_iotlb, map->start, + map->last, map->addr, + map->perm, map->opaque); + if (ret) + goto reset; + } - if (ops->set_map) { - if (!v->in_batch) - ops->set_map(vdpa, asid, iotlb); + ret = ops->set_map(vdpa, asid, &new_iotlb); +reset: + vhost_iotlb_reset(&new_iotlb); + if (ret) + return ret; } + vhost_vdpa_iotlb_unmap(v, iotlb, iova, last, asid); + return 0; } static int vhost_vdpa_va_map(struct vhost_vdpa *v, @@ -1151,7 +1196,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, unsigned long list_size = PAGE_SIZE / sizeof(struct page *); unsigned int gup_flags = FOLL_LONGTERM; unsigned long npages, cur_base, map_pfn, last_pfn = 0; - unsigned long lock_limit, sz2pin, nchunks, i; + unsigned long lock_limit, sz2pin, i; unsigned long page_offset; u64 start = iova; long pinned; @@ -1187,7 +1232,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, cur_base = uaddr & PAGE_MASK; iova &= PAGE_MASK; - nchunks = 0; while (npages) { sz2pin = min_t(unsigned long, npages, list_size); @@ -1202,7 +1246,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, } goto out; } - nchunks++; if (!last_pfn) map_pfn = page_to_pfn(page_list[0]); @@ -1233,7 +1276,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, map_pfn = this_pfn; iova += csize; - nchunks = 0; } last_pfn = this_pfn; @@ -1248,9 +1290,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, PFN_PHYS(map_pfn), perm, NULL); out: if (ret) { - if (nchunks) { - unsigned long pfn; - + if (last_pfn) { /* * Unpin the outstanding pages which are yet to be * mapped but haven't due to vdpa_map() or @@ -1260,9 +1300,9 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, * the corresponding unpinning will be handled by * vdpa_unmap(). */ - WARN_ON(!last_pfn); - for (pfn = map_pfn; pfn <= last_pfn; pfn++) - unpin_user_page(pfn_to_page(pfn)); + unpin_user_page_range_dirty_lock(pfn_to_page(map_pfn), + last_pfn - map_pfn + 1, + false); } vhost_vdpa_unmap(v, iotlb, start, size); } @@ -1342,7 +1382,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, r = vhost_vdpa_process_iotlb_update(v, iotlb, msg); break; case VHOST_IOTLB_INVALIDATE: - vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); + if (!msg->size || msg->iova > U64_MAX - msg->size + 1) { + r = -EINVAL; + break; + } + r = vhost_vdpa_unmap(v, iotlb, msg->iova, msg->size); break; case VHOST_IOTLB_BATCH_BEGIN: v->batch_asid = asid; @@ -1655,7 +1699,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) return minor; } - atomic_set(&v->opened, 0); + atomic_set(&v->opened, 1); spin_lock_init(&v->config_lock); v->minor = minor; v->vdpa = vdpa; @@ -1678,16 +1722,17 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) cdev_init(&v->cdev, &vhost_vdpa_fops); v->cdev.owner = THIS_MODULE; + init_completion(&v->completion); + for (i = 0; i < VHOST_VDPA_IOTLB_BUCKETS; i++) + INIT_HLIST_HEAD(&v->as[i]); r = cdev_device_add(&v->cdev, &v->dev); if (r) goto err; - init_completion(&v->completion); vdpa_set_drvdata(vdpa, v); - for (i = 0; i < VHOST_VDPA_IOTLB_BUCKETS; i++) - INIT_HLIST_HEAD(&v->as[i]); + atomic_set_release(&v->opened, 0); return 0; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 4d5d32e68d35f0..e29f154706da03 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -529,8 +529,7 @@ static long vhost_dev_alloc_iovecs(struct vhost_dev *dev) vq->indirect = kmalloc_objs(*vq->indirect, UIO_MAXIOV); vq->log = kmalloc_objs(*vq->log, dev->iov_limit); vq->heads = kmalloc_objs(*vq->heads, dev->iov_limit); - vq->nheads = kmalloc_array(dev->iov_limit, sizeof(*vq->nheads), - GFP_KERNEL); + vq->nheads = kmalloc_objs(*vq->nheads, dev->iov_limit); if (!vq->indirect || !vq->log || !vq->heads || !vq->nheads) goto err_nomem; } @@ -1766,7 +1765,8 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, goto done; } - if (msg.type == VHOST_IOTLB_UPDATE && msg.size == 0) { + if (msg.type == VHOST_IOTLB_UPDATE && + (!msg.size || !msg.perm || (msg.perm & ~VHOST_ACCESS_RW))) { ret = -EINVAL; goto done; } @@ -3179,7 +3179,6 @@ static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq, return -EINVAL; start = vq->last_used_idx & (vq->num - 1); - used = vq->used->ring + start; for (i = 0; i < count; i++) { if (vhost_put_used(vq, &heads[i], start, 1)) { @@ -3188,19 +3187,35 @@ static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq, } start += nheads[i]; new += nheads[i]; - if (start >= vq->num) - start -= vq->num; + start &= vq->num - 1; } if (unlikely(vq->log_used)) { + unsigned int log_count = 0; + int log_start = 0, next; + /* Make sure data is seen before log. */ smp_wmb(); - /* Log used ring entry write. */ - log_used(vq, ((void __user *)used - (void __user *)vq->used), - (vq->num - start) * sizeof *used); - if (start + count > vq->num) - log_used(vq, 0, - (start + count - vq->num) * sizeof *used); + /* Log contiguous runs of used ring entries that were written. */ + start = vq->last_used_idx & (vq->num - 1); + for (i = 0; i < count; i++) { + if (!log_count) + log_start = start; + log_count++; + + next = start + nheads[i]; + if (next >= vq->num) + next -= vq->num; + if (i + 1 == count || next != start + 1) { + used = vq->used->ring + log_start; + log_used(vq, + ((void __user *)used - + (void __user *)vq->used), + log_count * sizeof(*used)); + log_count = 0; + } + start = next; + } } old = vq->last_used_idx; diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 74836eb60c7a5d..5094715dd8bc4a 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -197,8 +197,9 @@ static int move_to_indirect(const struct vringh *vrh, } len = vringh32_to_cpu(vrh, desc->len); - if (unlikely(len % sizeof(struct vring_desc))) { - vringh_bad("Strange indirect len %u", desc->len); + if (unlikely(len < sizeof(struct vring_desc) || + len % sizeof(struct vring_desc))) { + vringh_bad("Invalid indirect len %u", desc->len); return -EINVAL; } @@ -333,6 +334,17 @@ __vringh_iov(struct vringh *vrh, u16 i, if (unlikely(err)) goto fail; + if (up_next == -1) + count++; + else + indirect_count++; + + if (count > vrh->vring.num || indirect_count > desc_max) { + vringh_bad("Descriptor loop in %p", descs); + err = -ELOOP; + goto fail; + } + if (unlikely(desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_INDIRECT))) { u64 a = vringh64_to_cpu(vrh, desc.addr); @@ -358,17 +370,6 @@ __vringh_iov(struct vringh *vrh, u16 i, continue; } - if (up_next == -1) - count++; - else - indirect_count++; - - if (count > vrh->vring.num || indirect_count > desc_max) { - vringh_bad("Descriptor loop in %p", descs); - err = -ELOOP; - goto fail; - } - if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_WRITE)) iov = wiov; else { @@ -1244,7 +1245,7 @@ static inline int putu16_iotlb(const struct vringh *vrh, /* Atomic write is needed for putu16 */ ret = iotlb_translate(vrh, (u64)(uintptr_t)p, sizeof(*p), - NULL, &ivec, VHOST_MAP_RO); + NULL, &ivec, VHOST_MAP_WO); if (ret < 0) return ret; diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 0cb87971d74919..88a310390eb0a4 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -360,7 +360,7 @@ static struct sk_buff * vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, unsigned int out, unsigned int in) { - struct virtio_vsock_hdr *hdr; + struct virtio_vsock_hdr hdr; struct iov_iter iov_iter; struct sk_buff *skb; size_t payload_len; @@ -378,34 +378,32 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) return NULL; - /* len contains both payload and hdr */ - skb = virtio_vsock_alloc_skb(len, GFP_KERNEL); - if (!skb) - return NULL; - iov_iter_init(&iov_iter, ITER_SOURCE, vq->iov, out, len); - hdr = virtio_vsock_hdr(skb); - nbytes = copy_from_iter(hdr, sizeof(*hdr), &iov_iter); - if (nbytes != sizeof(*hdr)) { + nbytes = copy_from_iter(&hdr, sizeof(hdr), &iov_iter); + if (nbytes != sizeof(hdr)) { vq_err(vq, "Expected %zu bytes for pkt->hdr, got %zu bytes\n", - sizeof(*hdr), nbytes); - kfree_skb(skb); + sizeof(hdr), nbytes); return NULL; } - payload_len = le32_to_cpu(hdr->len); + payload_len = le32_to_cpu(hdr.len); + + /* The pkt is too big or the length in the header is invalid */ + if (payload_len > len - sizeof(hdr)) + return NULL; + + /* Allocate only for the payload declared in the header. */ + skb = virtio_vsock_alloc_skb(payload_len + sizeof(hdr), GFP_KERNEL); + if (!skb) + return NULL; + + memcpy(virtio_vsock_hdr(skb), &hdr, sizeof(hdr)); /* No payload */ if (!payload_len) return skb; - /* The pkt is too big or the length in the header is invalid */ - if (payload_len + sizeof(*hdr) > len) { - kfree_skb(skb); - return NULL; - } - virtio_vsock_skb_put(skb, payload_len); if (skb_copy_datagram_from_iter(skb, 0, &iov_iter, payload_len)) { diff --git a/drivers/video/aperture.c b/drivers/video/aperture.c index 2b5a1e666e9b25..4530e22ed7f047 100644 --- a/drivers/video/aperture.c +++ b/drivers/video/aperture.c @@ -178,7 +178,7 @@ static int devm_aperture_acquire(struct device *dev, } } - ap = devm_kzalloc(dev, sizeof(*ap), GFP_KERNEL); + ap = devm_kzalloc_obj(dev, *ap); if (!ap) { mutex_unlock(&apertures_lock); return -ENOMEM; diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c index 0a1db28240763f..9381d202a0f860 100644 --- a/drivers/video/backlight/88pm860x_bl.c +++ b/drivers/video/backlight/88pm860x_bl.c @@ -186,8 +186,7 @@ static int pm860x_backlight_probe(struct platform_device *pdev) char name[MFD_NAME_SIZE]; int ret = 0; - data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_backlight_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct pm860x_backlight_data); if (data == NULL) return -ENOMEM; res = platform_get_resource_byname(pdev, IORESOURCE_REG, "duty cycle"); diff --git a/drivers/video/backlight/aat2870_bl.c b/drivers/video/backlight/aat2870_bl.c index 8b790df1e842b3..5af36d3784f11a 100644 --- a/drivers/video/backlight/aat2870_bl.c +++ b/drivers/video/backlight/aat2870_bl.c @@ -114,9 +114,7 @@ static int aat2870_bl_probe(struct platform_device *pdev) goto out; } - aat2870_bl = devm_kzalloc(&pdev->dev, - sizeof(struct aat2870_bl_driver_data), - GFP_KERNEL); + aat2870_bl = devm_kzalloc_obj(&pdev->dev, struct aat2870_bl_driver_data); if (!aat2870_bl) { ret = -ENOMEM; goto out; diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c index 81c40d355aae4f..329af17f195604 100644 --- a/drivers/video/backlight/adp5520_bl.c +++ b/drivers/video/backlight/adp5520_bl.c @@ -283,7 +283,7 @@ static int adp5520_bl_probe(struct platform_device *pdev) struct adp5520_bl *data; int ret = 0; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c index 09dd677024312b..75c2cd171f620f 100644 --- a/drivers/video/backlight/adp8860_bl.c +++ b/drivers/video/backlight/adp8860_bl.c @@ -221,8 +221,7 @@ static int adp8860_led_probe(struct i2c_client *client) struct led_info *cur_led; int ret, i; - led = devm_kcalloc(&client->dev, pdata->num_leds, sizeof(*led), - GFP_KERNEL); + led = devm_kzalloc_objs(&client->dev, *led, pdata->num_leds); if (led == NULL) return -ENOMEM; @@ -669,7 +668,7 @@ static int adp8860_probe(struct i2c_client *client) return -EINVAL; } - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c index d009f2c8a11d86..095fcb44b63823 100644 --- a/drivers/video/backlight/adp8870_bl.c +++ b/drivers/video/backlight/adp8870_bl.c @@ -244,8 +244,7 @@ static int adp8870_led_probe(struct i2c_client *client) struct led_info *cur_led; int ret, i; - led = devm_kcalloc(&client->dev, pdata->num_leds, sizeof(*led), - GFP_KERNEL); + led = devm_kzalloc_objs(&client->dev, *led, pdata->num_leds); if (led == NULL) return -ENOMEM; @@ -866,7 +865,7 @@ static int adp8870_probe(struct i2c_client *client) return -ENODEV; } - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/ams369fg06.c b/drivers/video/backlight/ams369fg06.c index f8442689ac4366..538d985559c7b2 100644 --- a/drivers/video/backlight/ams369fg06.c +++ b/drivers/video/backlight/ams369fg06.c @@ -443,7 +443,7 @@ static int ams369fg06_probe(struct spi_device *spi) struct backlight_device *bd = NULL; struct backlight_properties props; - lcd = devm_kzalloc(&spi->dev, sizeof(struct ams369fg06), GFP_KERNEL); + lcd = devm_kzalloc_obj(&spi->dev, struct ams369fg06); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/apple_dwi_bl.c b/drivers/video/backlight/apple_dwi_bl.c index 93bd744972d60a..a006506f77515b 100644 --- a/drivers/video/backlight/apple_dwi_bl.c +++ b/drivers/video/backlight/apple_dwi_bl.c @@ -76,7 +76,7 @@ static int dwi_bl_probe(struct platform_device *dev) struct backlight_properties props; struct resource *res; - dwi_bl = devm_kzalloc(&dev->dev, sizeof(*dwi_bl), GFP_KERNEL); + dwi_bl = devm_kzalloc_obj(&dev->dev, *dwi_bl); if (!dwi_bl) return -ENOMEM; diff --git a/drivers/video/backlight/arcxcnn_bl.c b/drivers/video/backlight/arcxcnn_bl.c index f46eeab02e90ee..3abe13529ccbe1 100644 --- a/drivers/video/backlight/arcxcnn_bl.c +++ b/drivers/video/backlight/arcxcnn_bl.c @@ -152,7 +152,7 @@ static int arcxcnn_backlight_register(struct arcxcnn *lp) struct backlight_properties *props; const char *name = lp->pdata->name ? : "arctic_bl"; - props = devm_kzalloc(lp->dev, sizeof(*props), GFP_KERNEL); + props = devm_kzalloc_obj(lp->dev, *props); if (!props) return -ENOMEM; @@ -246,7 +246,7 @@ static int arcxcnn_probe(struct i2c_client *cl) if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - lp = devm_kzalloc(&cl->dev, sizeof(*lp), GFP_KERNEL); + lp = devm_kzalloc_obj(&cl->dev, *lp); if (!lp) return -ENOMEM; @@ -261,8 +261,7 @@ static int arcxcnn_probe(struct i2c_client *cl) goto probe_err; if (!lp->pdata) { - lp->pdata = devm_kzalloc(lp->dev, - sizeof(*lp->pdata), GFP_KERNEL); + lp->pdata = devm_kzalloc_obj(lp->dev, *lp->pdata); if (!lp->pdata) return -ENOMEM; diff --git a/drivers/video/backlight/as3711_bl.c b/drivers/video/backlight/as3711_bl.c index 753160bbc3e722..2d419b9e8aea79 100644 --- a/drivers/video/backlight/as3711_bl.c +++ b/drivers/video/backlight/as3711_bl.c @@ -406,7 +406,7 @@ static int as3711_backlight_probe(struct platform_device *pdev) return -EINVAL; } - supply = devm_kzalloc(&pdev->dev, sizeof(*supply), GFP_KERNEL); + supply = devm_kzalloc_obj(&pdev->dev, *supply); if (!supply) return -ENOMEM; diff --git a/drivers/video/backlight/aw99706.c b/drivers/video/backlight/aw99706.c index c4a66b59ecf139..43f82c83f91a3a 100644 --- a/drivers/video/backlight/aw99706.c +++ b/drivers/video/backlight/aw99706.c @@ -376,7 +376,7 @@ static int aw99706_probe(struct i2c_client *client) struct backlight_properties props = {}; int ret = 0; - aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL); + aw = devm_kzalloc_obj(dev, *aw); if (!aw) return -ENOMEM; diff --git a/drivers/video/backlight/bd6107.c b/drivers/video/backlight/bd6107.c index 6778b4030b0275..371d6384a86414 100644 --- a/drivers/video/backlight/bd6107.c +++ b/drivers/video/backlight/bd6107.c @@ -131,7 +131,7 @@ static int bd6107_probe(struct i2c_client *client) return -EIO; } - bd = devm_kzalloc(&client->dev, sizeof(*bd), GFP_KERNEL); + bd = devm_kzalloc_obj(&client->dev, *bd); if (!bd) return -ENOMEM; diff --git a/drivers/video/backlight/cgbc_bl.c b/drivers/video/backlight/cgbc_bl.c index ab27e14338a861..3be140284eabc1 100644 --- a/drivers/video/backlight/cgbc_bl.c +++ b/drivers/video/backlight/cgbc_bl.c @@ -136,7 +136,7 @@ static int cgbc_bl_probe(struct platform_device *pdev) struct cgbc_bl_data *bl_data; int ret; - bl_data = devm_kzalloc(&pdev->dev, sizeof(*bl_data), GFP_KERNEL); + bl_data = devm_kzalloc_obj(&pdev->dev, *bl_data); if (!bl_data) return -ENOMEM; diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c index 69f49371ea3533..c76e61db59fa5b 100644 --- a/drivers/video/backlight/corgi_lcd.c +++ b/drivers/video/backlight/corgi_lcd.c @@ -501,7 +501,7 @@ static int corgi_lcd_probe(struct spi_device *spi) return -EINVAL; } - lcd = devm_kzalloc(&spi->dev, sizeof(struct corgi_lcd), GFP_KERNEL); + lcd = devm_kzalloc_obj(&spi->dev, struct corgi_lcd); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c index 81ff42bec0ad4b..8bfd9c144ff981 100644 --- a/drivers/video/backlight/da903x_bl.c +++ b/drivers/video/backlight/da903x_bl.c @@ -100,7 +100,7 @@ static int da903x_backlight_probe(struct platform_device *pdev) struct backlight_properties props; int max_brightness; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/da9052_bl.c b/drivers/video/backlight/da9052_bl.c index f41523d78121b7..406c12434c4436 100644 --- a/drivers/video/backlight/da9052_bl.c +++ b/drivers/video/backlight/da9052_bl.c @@ -107,7 +107,7 @@ static int da9052_backlight_probe(struct platform_device *pdev) struct backlight_properties props; struct da9052_bl *wleds; - wleds = devm_kzalloc(&pdev->dev, sizeof(struct da9052_bl), GFP_KERNEL); + wleds = devm_kzalloc_obj(&pdev->dev, struct da9052_bl); if (!wleds) return -ENOMEM; diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c index f59effc0235286..bcfbea77abd1b1 100644 --- a/drivers/video/backlight/ep93xx_bl.c +++ b/drivers/video/backlight/ep93xx_bl.c @@ -57,7 +57,7 @@ static int ep93xxbl_probe(struct platform_device *dev) struct backlight_properties props; struct resource *res; - ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL); + ep93xxbl = devm_kzalloc_obj(&dev->dev, *ep93xxbl); if (!ep93xxbl) return -ENOMEM; diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 728a546904b097..1864a4e77d32d4 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -53,7 +53,7 @@ static int gpio_backlight_probe(struct platform_device *pdev) struct gpio_backlight *gbl; int ret, init_brightness, def_value; - gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL); + gbl = devm_kzalloc_obj(dev, *gbl); if (gbl == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c index 590365c6a51ba9..27d895b576787a 100644 --- a/drivers/video/backlight/hx8357.c +++ b/drivers/video/backlight/hx8357.c @@ -224,7 +224,7 @@ static int hx8357_spi_write_then_read(struct lcd_device *lcdev, if (txlen) { int i; - local_txbuf = kcalloc(txlen, sizeof(*local_txbuf), GFP_KERNEL); + local_txbuf = kzalloc_objs(*local_txbuf, txlen); if (!local_txbuf) return -ENOMEM; @@ -573,7 +573,7 @@ static int hx8357_probe(struct spi_device *spi) hx8357_init_fn init_fn; int i, ret; - lcd = devm_kzalloc(dev, sizeof(*lcd), GFP_KERNEL); + lcd = devm_kzalloc_obj(dev, *lcd); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/ili922x.c b/drivers/video/backlight/ili922x.c index 5e1bf0c5831ff8..b07fcf6425c5eb 100644 --- a/drivers/video/backlight/ili922x.c +++ b/drivers/video/backlight/ili922x.c @@ -483,7 +483,7 @@ static int ili922x_probe(struct spi_device *spi) int ret; u16 reg = 0; - ili = devm_kzalloc(&spi->dev, sizeof(*ili), GFP_KERNEL); + ili = devm_kzalloc_obj(&spi->dev, *ili); if (!ili) return -ENOMEM; diff --git a/drivers/video/backlight/ili9320.c b/drivers/video/backlight/ili9320.c index d2f094dd7fc35f..3117d8183fecc7 100644 --- a/drivers/video/backlight/ili9320.c +++ b/drivers/video/backlight/ili9320.c @@ -214,7 +214,7 @@ int ili9320_probe_spi(struct spi_device *spi, /* allocate and initialse our state */ - ili = devm_kzalloc(&spi->dev, sizeof(struct ili9320), GFP_KERNEL); + ili = devm_kzalloc_obj(&spi->dev, struct ili9320); if (ili == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/ktd253-backlight.c b/drivers/video/backlight/ktd253-backlight.c index f2c5527d02e0ff..8091c7e085e86e 100644 --- a/drivers/video/backlight/ktd253-backlight.c +++ b/drivers/video/backlight/ktd253-backlight.c @@ -148,7 +148,7 @@ static int ktd253_backlight_probe(struct platform_device *pdev) u32 brightness; int ret; - ktd253 = devm_kzalloc(dev, sizeof(*ktd253), GFP_KERNEL); + ktd253 = devm_kzalloc_obj(dev, *ktd253); if (!ktd253) return -ENOMEM; ktd253->dev = dev; diff --git a/drivers/video/backlight/ktd2801-backlight.c b/drivers/video/backlight/ktd2801-backlight.c index 02baf3a60b2a23..c218ee55f25384 100644 --- a/drivers/video/backlight/ktd2801-backlight.c +++ b/drivers/video/backlight/ktd2801-backlight.c @@ -64,7 +64,7 @@ static int ktd2801_backlight_probe(struct platform_device *pdev) u32 brightness, max_brightness; int ret; - ktd2801 = devm_kzalloc(dev, sizeof(*ktd2801), GFP_KERNEL); + ktd2801 = devm_kzalloc_obj(dev, *ktd2801); if (!ktd2801) return -ENOMEM; ktd2801->was_on = true; diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c index 53c1301dbb8c5a..20b8483433b448 100644 --- a/drivers/video/backlight/ktz8866.c +++ b/drivers/video/backlight/ktz8866.c @@ -131,7 +131,7 @@ static int ktz8866_probe(struct i2c_client *client) struct ktz8866 *ktz; int ret = 0; - ktz = devm_kzalloc(&client->dev, sizeof(*ktz), GFP_KERNEL); + ktz = devm_kzalloc_obj(&client->dev, *ktz); if (!ktz) return -ENOMEM; diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c index d04d2256306e8a..9dd4f68822181d 100644 --- a/drivers/video/backlight/l4f00242t03.c +++ b/drivers/video/backlight/l4f00242t03.c @@ -168,8 +168,7 @@ static int l4f00242t03_probe(struct spi_device *spi) struct l4f00242t03_priv *priv; int ret; - priv = devm_kzalloc(&spi->dev, sizeof(struct l4f00242t03_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, struct l4f00242t03_priv); if (priv == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/led_bl.c b/drivers/video/backlight/led_bl.c index f7ab9b3607313c..70b74a535f44cc 100644 --- a/drivers/video/backlight/led_bl.c +++ b/drivers/video/backlight/led_bl.c @@ -90,8 +90,7 @@ static int led_bl_get_leds(struct device *dev, return -EINVAL; } - leds = devm_kcalloc(dev, nb_leds, sizeof(struct led_classdev *), - GFP_KERNEL); + leds = devm_kzalloc_objs(dev, struct led_classdev *, nb_leds); if (!leds) return -ENOMEM; @@ -138,8 +137,7 @@ static int led_bl_parse_levels(struct device *dev, unsigned int db; u32 *levels = NULL; - levels = devm_kcalloc(dev, num_levels, sizeof(u32), - GFP_KERNEL); + levels = devm_kzalloc_objs(dev, u32, num_levels); if (!levels) return -ENOMEM; @@ -179,7 +177,7 @@ static int led_bl_probe(struct platform_device *pdev) struct led_bl_data *priv; int ret, i; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/video/backlight/lm3509_bl.c b/drivers/video/backlight/lm3509_bl.c index 53136c5e1460d6..2789d99bc96146 100644 --- a/drivers/video/backlight/lm3509_bl.c +++ b/drivers/video/backlight/lm3509_bl.c @@ -223,7 +223,7 @@ static int lm3509_probe(struct i2c_client *client) return -EOPNOTSUPP; } - data = devm_kzalloc(dev, sizeof(struct lm3509_bl), GFP_KERNEL); + data = devm_kzalloc_obj(dev, struct lm3509_bl); if (!data) return -ENOMEM; diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c index adcd6ac7cf2293..fd6e7f4f1f61c8 100644 --- a/drivers/video/backlight/lm3533_bl.c +++ b/drivers/video/backlight/lm3533_bl.c @@ -271,7 +271,7 @@ static int lm3533_bl_probe(struct platform_device *pdev) return -EINVAL; } - bl = devm_kzalloc(&pdev->dev, sizeof(*bl), GFP_KERNEL); + bl = devm_kzalloc_obj(&pdev->dev, *bl); if (!bl) return -ENOMEM; diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c index 8ef8163c7fef0b..83cd116ff94437 100644 --- a/drivers/video/backlight/lm3630a_bl.c +++ b/drivers/video/backlight/lm3630a_bl.c @@ -503,8 +503,7 @@ static int lm3630a_probe(struct i2c_client *client) return -EOPNOTSUPP; } - pchip = devm_kzalloc(&client->dev, sizeof(struct lm3630a_chip), - GFP_KERNEL); + pchip = devm_kzalloc_obj(&client->dev, struct lm3630a_chip); if (!pchip) return -ENOMEM; pchip->dev = &client->dev; @@ -518,9 +517,8 @@ static int lm3630a_probe(struct i2c_client *client) i2c_set_clientdata(client, pchip); if (pdata == NULL) { - pdata = devm_kzalloc(pchip->dev, - sizeof(struct lm3630a_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(pchip->dev, + struct lm3630a_platform_data); if (pdata == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/lm3639_bl.c b/drivers/video/backlight/lm3639_bl.c index ea748b80b73798..88025c09b8d8c6 100644 --- a/drivers/video/backlight/lm3639_bl.c +++ b/drivers/video/backlight/lm3639_bl.c @@ -313,8 +313,7 @@ static int lm3639_probe(struct i2c_client *client) return -ENODATA; } - pchip = devm_kzalloc(&client->dev, - sizeof(struct lm3639_chip_data), GFP_KERNEL); + pchip = devm_kzalloc_obj(&client->dev, struct lm3639_chip_data); if (!pchip) return -ENOMEM; diff --git a/drivers/video/backlight/lms283gf05.c b/drivers/video/backlight/lms283gf05.c index c8b7eeeb333e0b..734ab79fba0b6b 100644 --- a/drivers/video/backlight/lms283gf05.c +++ b/drivers/video/backlight/lms283gf05.c @@ -149,8 +149,7 @@ static int lms283gf05_probe(struct spi_device *spi) struct lms283gf05_state *st; struct lcd_device *ld; - st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state), - GFP_KERNEL); + st = devm_kzalloc_obj(&spi->dev, struct lms283gf05_state); if (st == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/lms501kf03.c b/drivers/video/backlight/lms501kf03.c index 28721b48b4c784..db4ad52882b6a5 100644 --- a/drivers/video/backlight/lms501kf03.c +++ b/drivers/video/backlight/lms501kf03.c @@ -313,7 +313,7 @@ static int lms501kf03_probe(struct spi_device *spi) struct lcd_device *ld = NULL; int ret = 0; - lcd = devm_kzalloc(&spi->dev, sizeof(struct lms501kf03), GFP_KERNEL); + lcd = devm_kzalloc_obj(&spi->dev, struct lms501kf03); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 43a2123d3a4dc5..a8126a6727316a 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -346,7 +346,7 @@ static int lp855x_parse_dt(struct lp855x *lp) struct device_node *child; int i = 0; - rom = devm_kcalloc(dev, rom_length, sizeof(*rom), GFP_KERNEL); + rom = devm_kzalloc_objs(dev, *rom, rom_length); if (!rom) return -ENOMEM; @@ -403,7 +403,7 @@ static int lp855x_probe(struct i2c_client *cl) if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; - lp = devm_kzalloc(dev, sizeof(struct lp855x), GFP_KERNEL); + lp = devm_kzalloc_obj(dev, struct lp855x); if (!lp) return -ENOMEM; @@ -440,7 +440,7 @@ static int lp855x_probe(struct i2c_client *cl) } if (!lp->pdata) { - lp->pdata = devm_kzalloc(dev, sizeof(*lp->pdata), GFP_KERNEL); + lp->pdata = devm_kzalloc_obj(dev, *lp->pdata); if (!lp->pdata) return -ENOMEM; diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c index f61a64905a02dc..9a4e499d1bef87 100644 --- a/drivers/video/backlight/lp8788_bl.c +++ b/drivers/video/backlight/lp8788_bl.c @@ -128,7 +128,7 @@ static int lp8788_backlight_probe(struct platform_device *pdev) struct lp8788_bl *bl; int ret; - bl = devm_kzalloc(lp->dev, sizeof(struct lp8788_bl), GFP_KERNEL); + bl = devm_kzalloc_obj(lp->dev, struct lp8788_bl); if (!bl) return -ENOMEM; diff --git a/drivers/video/backlight/ltv350qv.c b/drivers/video/backlight/ltv350qv.c index c919b0fe4cd9bc..392708f25f2b5c 100644 --- a/drivers/video/backlight/ltv350qv.c +++ b/drivers/video/backlight/ltv350qv.c @@ -227,7 +227,7 @@ static int ltv350qv_probe(struct spi_device *spi) struct lcd_device *ld; int ret; - lcd = devm_kzalloc(&spi->dev, sizeof(struct ltv350qv), GFP_KERNEL); + lcd = devm_kzalloc_obj(&spi->dev, struct ltv350qv); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/lv5207lp.c b/drivers/video/backlight/lv5207lp.c index e643ab9c3536c5..a22b0772b162f1 100644 --- a/drivers/video/backlight/lv5207lp.c +++ b/drivers/video/backlight/lv5207lp.c @@ -94,7 +94,7 @@ static int lv5207lp_probe(struct i2c_client *client) return -EIO; } - lv = devm_kzalloc(&client->dev, sizeof(*lv), GFP_KERNEL); + lv = devm_kzalloc_obj(&client->dev, *lv); if (!lv) return -ENOMEM; diff --git a/drivers/video/backlight/max25014.c b/drivers/video/backlight/max25014.c index 3ee45617261f3c..64d21b17f004e9 100644 --- a/drivers/video/backlight/max25014.c +++ b/drivers/video/backlight/max25014.c @@ -277,7 +277,7 @@ static int max25014_probe(struct i2c_client *cl) struct max25014 *maxim; int ret; - maxim = devm_kzalloc(&cl->dev, sizeof(struct max25014), GFP_KERNEL); + maxim = devm_kzalloc_obj(&cl->dev, struct max25014); if (!maxim) return -ENOMEM; diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c index 4ac20a59e007fa..0fbf272d22a702 100644 --- a/drivers/video/backlight/max8925_bl.c +++ b/drivers/video/backlight/max8925_bl.c @@ -95,9 +95,7 @@ static void max8925_backlight_dt_init(struct platform_device *pdev) if (!nproot || !IS_ENABLED(CONFIG_OF)) return; - pdata = devm_kzalloc(&pdev->dev, - sizeof(struct max8925_backlight_pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, struct max8925_backlight_pdata); if (!pdata) return; @@ -126,8 +124,7 @@ static int max8925_backlight_probe(struct platform_device *pdev) unsigned char value; int ret = 0; - data = devm_kzalloc(&pdev->dev, sizeof(struct max8925_backlight_data), - GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, struct max8925_backlight_data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c index 752a45798bfc98..a966c1e8f92c50 100644 --- a/drivers/video/backlight/mp3309c.c +++ b/drivers/video/backlight/mp3309c.c @@ -256,7 +256,7 @@ static int mp3309c_parse_fwnode(struct mp3309c_chip *chip, } /* Fill brightness levels array */ - pdata->levels = devm_kcalloc(dev, num_levels, sizeof(*pdata->levels), GFP_KERNEL); + pdata->levels = devm_kzalloc_objs(dev, *pdata->levels, num_levels); if (!pdata->levels) return -ENOMEM; if (device_property_present(dev, "brightness-levels")) { @@ -326,7 +326,7 @@ static int mp3309c_probe(struct i2c_client *client) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return dev_err_probe(dev, -EOPNOTSUPP, "failed to check i2c functionality\n"); - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -340,7 +340,7 @@ static int mp3309c_probe(struct i2c_client *client) i2c_set_clientdata(client, chip); if (!pdata) { - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/drivers/video/backlight/mt6370-backlight.c b/drivers/video/backlight/mt6370-backlight.c index 7905372c2a4c0e..1ba37c0048f7bf 100644 --- a/drivers/video/backlight/mt6370-backlight.c +++ b/drivers/video/backlight/mt6370-backlight.c @@ -280,7 +280,7 @@ static int mt6370_bl_probe(struct platform_device *pdev) struct mt6370_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c index e461e19231ae3f..65481d046946cb 100644 --- a/drivers/video/backlight/omap1_bl.c +++ b/drivers/video/backlight/omap1_bl.c @@ -116,8 +116,7 @@ static int omapbl_probe(struct platform_device *pdev) if (!pdata) return -ENXIO; - bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight), - GFP_KERNEL); + bl = devm_kzalloc_obj(&pdev->dev, struct omap_backlight); if (unlikely(!bl)) return -ENOMEM; diff --git a/drivers/video/backlight/otm3225a.c b/drivers/video/backlight/otm3225a.c index 5c6575f23ea889..5991b849aeeb38 100644 --- a/drivers/video/backlight/otm3225a.c +++ b/drivers/video/backlight/otm3225a.c @@ -216,7 +216,7 @@ static int otm3225a_probe(struct spi_device *spi) struct lcd_device *ld; struct device *dev = &spi->dev; - dd = devm_kzalloc(dev, sizeof(struct otm3225a_data), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, struct otm3225a_data); if (dd == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/pandora_bl.c b/drivers/video/backlight/pandora_bl.c index 8a63ded0fa90f7..e6889e2ac55e14 100644 --- a/drivers/video/backlight/pandora_bl.c +++ b/drivers/video/backlight/pandora_bl.c @@ -112,7 +112,7 @@ static int pandora_backlight_probe(struct platform_device *pdev) struct pandora_private *priv; u8 r; - priv = devm_kmalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kmalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c index c9fe50f4d8ed20..7a46192963d2df 100644 --- a/drivers/video/backlight/platform_lcd.c +++ b/drivers/video/backlight/platform_lcd.c @@ -81,8 +81,7 @@ static int platform_lcd_probe(struct platform_device *pdev) return err; } - plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd), - GFP_KERNEL); + plcd = devm_kzalloc_obj(&pdev->dev, struct platform_lcd); if (!plcd) return -ENOMEM; diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 237d3d3f3bb1a6..3ad71ee3657afd 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -194,8 +194,8 @@ int pwm_backlight_brightness_default(struct device *dev, data->max_brightness = min((int)DIV_ROUND_UP(period, fls(period)), 4096); - data->levels = devm_kcalloc(dev, data->max_brightness, - sizeof(*data->levels), GFP_KERNEL); + data->levels = devm_kzalloc_objs(dev, *data->levels, + data->max_brightness); if (!data->levels) return -ENOMEM; @@ -252,8 +252,7 @@ static int pwm_backlight_parse_dt(struct device *dev, /* read brightness levels from DT property */ if (num_levels > 0) { - data->levels = devm_kcalloc(dev, num_levels, - sizeof(*data->levels), GFP_KERNEL); + data->levels = devm_kzalloc_objs(dev, *data->levels, num_levels); if (!data->levels) return -ENOMEM; @@ -308,8 +307,7 @@ static int pwm_backlight_parse_dt(struct device *dev, * Create a new table of brightness levels with all the * interpolated steps. */ - table = devm_kcalloc(dev, num_levels, sizeof(*table), - GFP_KERNEL); + table = devm_kzalloc_objs(dev, *table, num_levels); if (!table) return -ENOMEM; /* @@ -463,7 +461,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) return ret; } - pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); + pb = devm_kzalloc_obj(&pdev->dev, *pb); if (!pb) { ret = -ENOMEM; goto err_alloc; diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index ca350f320e1773..a95eb67366429c 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -1725,7 +1725,7 @@ static int wled_probe(struct platform_device *pdev) return -EINVAL; } - wled = devm_kzalloc(&pdev->dev, sizeof(*wled), GFP_KERNEL); + wled = devm_kzalloc_obj(&pdev->dev, *wled); if (!wled) return -ENOMEM; diff --git a/drivers/video/backlight/rt4831-backlight.c b/drivers/video/backlight/rt4831-backlight.c index 7ead75929a437a..d93734a858dd6b 100644 --- a/drivers/video/backlight/rt4831-backlight.c +++ b/drivers/video/backlight/rt4831-backlight.c @@ -172,7 +172,7 @@ static int rt4831_bl_probe(struct platform_device *pdev) .scale = BACKLIGHT_SCALE_LINEAR }; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c index b2679b24de14bf..a0eac28ad78a2f 100644 --- a/drivers/video/backlight/sky81452-backlight.c +++ b/drivers/video/backlight/sky81452-backlight.c @@ -193,7 +193,7 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt( return ERR_PTR(-ENODATA); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); diff --git a/drivers/video/backlight/sy7758.c b/drivers/video/backlight/sy7758.c index 786589cb8df910..e9017c74a75042 100644 --- a/drivers/video/backlight/sy7758.c +++ b/drivers/video/backlight/sy7758.c @@ -164,7 +164,7 @@ static int sy7758_probe(struct i2c_client *client) unsigned int dev_id; int ret; - sydev = devm_kzalloc(dev, sizeof(*sydev), GFP_KERNEL); + sydev = devm_kzalloc_obj(dev, *sydev); if (!sydev) return -ENOMEM; diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c index c04ee3d04d8793..505d3119e43484 100644 --- a/drivers/video/backlight/tdo24m.c +++ b/drivers/video/backlight/tdo24m.c @@ -348,7 +348,7 @@ static int tdo24m_probe(struct spi_device *spi) if (err) return err; - lcd = devm_kzalloc(&spi->dev, sizeof(struct tdo24m), GFP_KERNEL); + lcd = devm_kzalloc_obj(&spi->dev, struct tdo24m); if (!lcd) return -ENOMEM; diff --git a/drivers/video/backlight/tps65217_bl.c b/drivers/video/backlight/tps65217_bl.c index 8aa860350644f2..44b332a478e9e7 100644 --- a/drivers/video/backlight/tps65217_bl.c +++ b/drivers/video/backlight/tps65217_bl.c @@ -175,7 +175,7 @@ tps65217_bl_parse_dt(struct platform_device *pdev) if (!node) return ERR_PTR(-ENODEV); - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (!pdata) { err = ERR_PTR(-ENOMEM); goto err; @@ -261,8 +261,7 @@ static int tps65217_bl_probe(struct platform_device *pdev) if (IS_ERR(pdata)) return PTR_ERR(pdata); - tps65217_bl = devm_kzalloc(&pdev->dev, sizeof(*tps65217_bl), - GFP_KERNEL); + tps65217_bl = devm_kzalloc_obj(&pdev->dev, *tps65217_bl); if (tps65217_bl == NULL) return -ENOMEM; diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c index 49027f04a1ecb0..7f4d6cf5e99ac3 100644 --- a/drivers/video/backlight/wm831x_bl.c +++ b/drivers/video/backlight/wm831x_bl.c @@ -170,7 +170,7 @@ static int wm831x_backlight_probe(struct platform_device *pdev) if (ret < 0) return ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/atmel_lcdfb.c b/drivers/video/fbdev/atmel_lcdfb.c index bed11a652d14d0..a8dce75d14bc5c 100644 --- a/drivers/video/fbdev/atmel_lcdfb.c +++ b/drivers/video/fbdev/atmel_lcdfb.c @@ -969,7 +969,7 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo) if (IS_ERR(gpiod)) continue; - og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL); + og = devm_kzalloc_obj(dev, *og); if (!og) goto put_display_node; diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c index 71610d5ecc2b1a..1b29542aa69d84 100644 --- a/drivers/video/fbdev/au1100fb.c +++ b/drivers/video/fbdev/au1100fb.c @@ -732,7 +732,7 @@ static int au1100fb_drv_probe(struct platform_device *dev) struct clk *c; /* Allocate new device private */ - fbdev = devm_kzalloc(&dev->dev, sizeof(*fbdev), GFP_KERNEL); + fbdev = devm_kzalloc_obj(&dev->dev, *fbdev); if (!fbdev) return -ENOMEM; diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c index 7a021da0a32a2d..f6f910110f8572 100644 --- a/drivers/video/fbdev/imxfb.c +++ b/drivers/video/fbdev/imxfb.c @@ -918,8 +918,7 @@ static int imxfb_probe(struct platform_device *pdev) */ fbi->num_modes = 1; - fbi->mode = devm_kzalloc(&pdev->dev, - sizeof(struct imx_fb_videomode), GFP_KERNEL); + fbi->mode = devm_kzalloc_obj(&pdev->dev, struct imx_fb_videomode); if (!fbi->mode) { ret = -ENOMEM; of_node_put(display_np); diff --git a/drivers/video/fbdev/mmp/hw/mmp_ctrl.c b/drivers/video/fbdev/mmp/hw/mmp_ctrl.c index 3db608e5aef19a..9d139efef2fefb 100644 --- a/drivers/video/fbdev/mmp/hw/mmp_ctrl.c +++ b/drivers/video/fbdev/mmp/hw/mmp_ctrl.c @@ -469,9 +469,7 @@ static int mmphw_probe(struct platform_device *pdev) } /* allocate */ - ctrl = devm_kzalloc(&pdev->dev, - struct_size(ctrl, path_plats, mi->path_num), - GFP_KERNEL); + ctrl = devm_kzalloc_flex(&pdev->dev, *ctrl, path_plats, mi->path_num); if (!ctrl) { ret = -ENOMEM; goto failed; diff --git a/drivers/video/fbdev/ocfb.c b/drivers/video/fbdev/ocfb.c index c16e907e57101a..e9df603220d296 100644 --- a/drivers/video/fbdev/ocfb.c +++ b/drivers/video/fbdev/ocfb.c @@ -297,7 +297,7 @@ static int ocfb_probe(struct platform_device *pdev) struct ocfb_dev *fbdev; int fbsize; - fbdev = devm_kzalloc(&pdev->dev, sizeof(*fbdev), GFP_KERNEL); + fbdev = devm_kzalloc_obj(&pdev->dev, *fbdev); if (!fbdev) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/connector-analog-tv.c b/drivers/video/fbdev/omap2/omapfb/displays/connector-analog-tv.c index cef1603b753084..0794d97a937802 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/connector-analog-tv.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/connector-analog-tv.c @@ -186,7 +186,7 @@ static int tvc_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/connector-dvi.c b/drivers/video/fbdev/omap2/omapfb/displays/connector-dvi.c index 3f129ce9ff01a4..ba691fce42b573 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/connector-dvi.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/connector-dvi.c @@ -268,7 +268,7 @@ static int dvic_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/connector-hdmi.c b/drivers/video/fbdev/omap2/omapfb/displays/connector-hdmi.c index e3df731172e830..712210c9a6dd11 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/connector-hdmi.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/connector-hdmi.c @@ -207,7 +207,7 @@ static int hdmic_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/encoder-opa362.c b/drivers/video/fbdev/omap2/omapfb/displays/encoder-opa362.c index 8423d90313da34..cb6e1d2ff55651 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/encoder-opa362.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/encoder-opa362.c @@ -191,7 +191,7 @@ static int opa362_probe(struct platform_device *pdev) return -EINVAL; } - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tfp410.c b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tfp410.c index 881c8f1ad7a883..46a78593876031 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tfp410.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tfp410.c @@ -172,7 +172,7 @@ static int tfp410_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c index 635375e9080c97..4a2f9d7300c1d5 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c @@ -220,7 +220,7 @@ static int tpd_probe(struct platform_device *pdev) int r; struct gpio_desc *gpio; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-dpi.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-dpi.c index 22f4262b243242..8e6ebb853d9046 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-dpi.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-dpi.c @@ -180,7 +180,7 @@ static int panel_dpi_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-dsi-cm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-dsi-cm.c index b2328671e067cb..2b16f80e274876 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-dsi-cm.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-dsi-cm.c @@ -1121,7 +1121,7 @@ static int dsicm_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-lgphilips-lb035q02.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-lgphilips-lb035q02.c index e69856cb62d5b3..dd8d54caebba79 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-lgphilips-lb035q02.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-lgphilips-lb035q02.c @@ -261,7 +261,7 @@ static int lb035q02_panel_spi_probe(struct spi_device *spi) if (!spi->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-nec-nl8048hl11.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-nec-nl8048hl11.c index 33563953b2ff9a..449b362165cd8a 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-nec-nl8048hl11.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-nec-nl8048hl11.c @@ -243,7 +243,7 @@ static int nec_8048_probe(struct spi_device *spi) init_nec_8048_wvga_lcd(spi); - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sharp-ls037v7dw01.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sharp-ls037v7dw01.c index 888d94ea8e7db8..4ccb95294ee5a5 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sharp-ls037v7dw01.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sharp-ls037v7dw01.c @@ -259,7 +259,7 @@ static int sharp_ls_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c index 0202ca8cbfc239..c69597e912f152 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c @@ -706,7 +706,7 @@ static int acx565akm_probe(struct spi_device *spi) spi->mode = SPI_MODE_3; - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c index c18d290693c11d..dcb0c6c8aa2df0 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c @@ -389,7 +389,7 @@ static int td028ttec1_panel_probe(struct spi_device *spi) return r; } - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c index d487941853e647..19bf60800b0d34 100644 --- a/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c +++ b/drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td043mtea1.c @@ -466,7 +466,7 @@ static int tpo_td043_probe(struct spi_device *spi) return r; } - ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&spi->dev, *ddata); if (ddata == NULL) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/dss/dpi.c b/drivers/video/fbdev/omap2/omapfb/dss/dpi.c index ad8ae17279663c..246d36140f6361 100644 --- a/drivers/video/fbdev/omap2/omapfb/dss/dpi.c +++ b/drivers/video/fbdev/omap2/omapfb/dss/dpi.c @@ -778,7 +778,7 @@ static int dpi_bind(struct device *dev, struct device *master, void *data) struct platform_device *pdev = to_platform_device(dev); struct dpi_data *dpi; - dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL); + dpi = devm_kzalloc_obj(&pdev->dev, *dpi); if (!dpi) return -ENOMEM; @@ -841,7 +841,7 @@ int dpi_init_port(struct platform_device *pdev, struct device_node *port) u32 datalines; int r; - dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL); + dpi = devm_kzalloc_obj(&pdev->dev, *dpi); if (!dpi) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/dss/dsi.c b/drivers/video/fbdev/omap2/omapfb/dss/dsi.c index d98db01fdd39c4..e91f1dab98f135 100644 --- a/drivers/video/fbdev/omap2/omapfb/dss/dsi.c +++ b/drivers/video/fbdev/omap2/omapfb/dss/dsi.c @@ -5259,7 +5259,7 @@ static int dsi_bind(struct device *dev, struct device *master, void *data) struct resource *res; struct resource temp_res; - dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL); + dsi = devm_kzalloc_obj(&dsidev->dev, *dsi); if (!dsi) return -ENOMEM; diff --git a/drivers/video/fbdev/omap2/omapfb/dss/video-pll.c b/drivers/video/fbdev/omap2/omapfb/dss/video-pll.c index ca430ca69ba3e0..42999ee04c8c20 100644 --- a/drivers/video/fbdev/omap2/omapfb/dss/video-pll.c +++ b/drivers/video/fbdev/omap2/omapfb/dss/video-pll.c @@ -159,7 +159,7 @@ struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id, return ERR_CAST(clk); } - vpll = devm_kzalloc(&pdev->dev, sizeof(*vpll), GFP_KERNEL); + vpll = devm_kzalloc_obj(&pdev->dev, *vpll); if (!vpll) return ERR_PTR(-ENOMEM); diff --git a/drivers/video/fbdev/omap2/omapfb/omapfb-main.c b/drivers/video/fbdev/omap2/omapfb/omapfb-main.c index 046892682fc62a..776ad60efa6495 100644 --- a/drivers/video/fbdev/omap2/omapfb/omapfb-main.c +++ b/drivers/video/fbdev/omap2/omapfb/omapfb-main.c @@ -2472,8 +2472,7 @@ static int omapfb_probe(struct platform_device *pdev) goto err0; } - fbdev = devm_kzalloc(&pdev->dev, sizeof(struct omapfb2_device), - GFP_KERNEL); + fbdev = devm_kzalloc_obj(&pdev->dev, struct omapfb2_device); if (fbdev == NULL) { r = -ENOMEM; goto err0; diff --git a/drivers/video/fbdev/omap2/omapfb/vrfb.c b/drivers/video/fbdev/omap2/omapfb/vrfb.c index 675482cde519c8..e0a0b6a6762a18 100644 --- a/drivers/video/fbdev/omap2/omapfb/vrfb.c +++ b/drivers/video/fbdev/omap2/omapfb/vrfb.c @@ -346,9 +346,7 @@ static int __init vrfb_probe(struct platform_device *pdev) num_ctxs = pdev->num_resources - 1; - ctxs = devm_kcalloc(&pdev->dev, - num_ctxs, sizeof(struct vrfb_ctx), - GFP_KERNEL); + ctxs = devm_kzalloc_objs(&pdev->dev, struct vrfb_ctx, num_ctxs); if (!ctxs) return -ENOMEM; diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c index fc5bd7e7aae67b..052a6535cdb227 100644 --- a/drivers/video/fbdev/pxa3xx-gcu.c +++ b/drivers/video/fbdev/pxa3xx-gcu.c @@ -581,7 +581,7 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev) struct pxa3xx_gcu_priv *priv; struct device *dev = &pdev->dev; - priv = devm_kzalloc(dev, sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct pxa3xx_gcu_priv); if (!priv) return -ENOMEM; diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c index 1682345fb9b0a9..ca90ebe60a7690 100644 --- a/drivers/video/fbdev/pxafb.c +++ b/drivers/video/fbdev/pxafb.c @@ -2108,9 +2108,8 @@ static int of_get_pxafb_display(struct device *dev, struct device_node *disp, return -EINVAL; ret = -ENOMEM; - info->modes = devm_kcalloc(dev, timings->num_timings, - sizeof(info->modes[0]), - GFP_KERNEL); + info->modes = devm_kzalloc_objs(dev, info->modes[0], + timings->num_timings); if (!info->modes) goto out; info->num_modes = timings->num_timings; @@ -2196,7 +2195,7 @@ static struct pxafb_mach_info *of_pxafb_of_mach_info(struct device *dev) if (!dev->of_node) return NULL; - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(dev, *info); if (!info) return ERR_PTR(-ENOMEM); ret = of_get_pxafb_mode_info(dev, info); diff --git a/drivers/video/fbdev/s3c-fb.c b/drivers/video/fbdev/s3c-fb.c index 82a3bc9de433c0..fde78707d31342 100644 --- a/drivers/video/fbdev/s3c-fb.c +++ b/drivers/video/fbdev/s3c-fb.c @@ -1375,7 +1375,7 @@ static int s3c_fb_probe(struct platform_device *pdev) return -EINVAL; } - sfb = devm_kzalloc(dev, sizeof(*sfb), GFP_KERNEL); + sfb = devm_kzalloc_obj(dev, *sfb); if (!sfb) return -ENOMEM; diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 8102ab7d51e644..7132dbb3d6d932 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1038,7 +1038,7 @@ static struct sa1100fb_info *sa1100fb_init_fbinfo(struct device *dev) struct sa1100fb_info *fbi; unsigned i; - fbi = devm_kzalloc(dev, sizeof(struct sa1100fb_info), GFP_KERNEL); + fbi = devm_kzalloc_obj(dev, struct sa1100fb_info); if (!fbi) return NULL; diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 60e5dcec201fff..75284ebbe333f6 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -363,8 +363,8 @@ static int simplefb_regulators_get(struct simplefb_par *par, if (!count) return 0; - par->regulators = devm_kcalloc(&pdev->dev, count, - sizeof(struct regulator *), GFP_KERNEL); + par->regulators = devm_kzalloc_objs(&pdev->dev, struct regulator *, + count); if (!par->regulators) return -ENOMEM; @@ -479,14 +479,11 @@ static int simplefb_attach_genpds(struct simplefb_par *par, return 0; } - par->genpds = devm_kcalloc(dev, num_genpds, sizeof(*par->genpds), - GFP_KERNEL); + par->genpds = devm_kzalloc_objs(dev, *par->genpds, num_genpds); if (!par->genpds) return -ENOMEM; - par->genpd_links = devm_kcalloc(dev, num_genpds, - sizeof(*par->genpd_links), - GFP_KERNEL); + par->genpd_links = devm_kzalloc_objs(dev, *par->genpd_links, num_genpds); if (!par->genpd_links) return -ENOMEM; diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c index 0254a547182d32..ef4bb920c6ff61 100644 --- a/drivers/video/fbdev/ssd1307fb.c +++ b/drivers/video/fbdev/ssd1307fb.c @@ -741,8 +741,7 @@ static int ssd1307fb_probe(struct i2c_client *client) goto fb_alloc_error; } - ssd1307fb_defio = devm_kzalloc(dev, sizeof(*ssd1307fb_defio), - GFP_KERNEL); + ssd1307fb_defio = devm_kzalloc_obj(dev, *ssd1307fb_defio); if (!ssd1307fb_defio) { dev_err(dev, "Couldn't allocate deferred io.\n"); ret = -ENOMEM; diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c index 2c67a18d16ad38..74f35dddbb2750 100644 --- a/drivers/video/fbdev/via/viafbdev.c +++ b/drivers/video/fbdev/via/viafbdev.c @@ -581,8 +581,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg) break; case VIAFB_GET_GAMMA_LUT: - viafb_gamma_table = kmalloc_array(256, sizeof(u32), - GFP_KERNEL); + viafb_gamma_table = kmalloc_objs(u32, 256); if (!viafb_gamma_table) return -ENOMEM; viafb_get_gamma_table(viafb_gamma_table); diff --git a/drivers/video/fbdev/xilinxfb.c b/drivers/video/fbdev/xilinxfb.c index 462fe2e94d55d7..5f511c8cc6146e 100644 --- a/drivers/video/fbdev/xilinxfb.c +++ b/drivers/video/fbdev/xilinxfb.c @@ -415,7 +415,7 @@ static int xilinxfb_of_probe(struct platform_device *pdev) pdata = xilinx_fb_default_pdata; /* Allocate the driver data region */ - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c index f170ff4617fdd1..0c0a5504fc4eb6 100644 --- a/drivers/virt/acrn/hsm.c +++ b/drivers/virt/acrn/hsm.c @@ -50,7 +50,7 @@ static int pmcmd_ioctl(u64 cmd, void __user *uptr) switch (cmd & PMCMD_TYPE_MASK) { case ACRN_PMCMD_GET_PX_CNT: case ACRN_PMCMD_GET_CX_CNT: - pm_info = kzalloc(sizeof(u64), GFP_KERNEL); + pm_info = kzalloc_obj(u64); if (!pm_info) return -ENOMEM; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 935537a41469b0..5fade6cc135727 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -636,7 +636,7 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL); + snp_dev = devm_kzalloc_obj(&pdev->dev, struct snp_guest_dev); if (!snp_dev) return -ENOMEM; diff --git a/drivers/virt/vboxguest/vboxguest_core.c b/drivers/virt/vboxguest/vboxguest_core.c index b5dc0d01facd50..35de1f02212a49 100644 --- a/drivers/virt/vboxguest/vboxguest_core.c +++ b/drivers/virt/vboxguest/vboxguest_core.c @@ -377,8 +377,8 @@ static void vbg_balloon_work(struct work_struct *work) */ if (!gdev->mem_balloon.max_chunks) { gdev->mem_balloon.pages = - devm_kcalloc(gdev->dev, req->phys_mem_chunks, - sizeof(struct page **), GFP_KERNEL); + devm_kzalloc_objs(gdev->dev, struct page **, + req->phys_mem_chunks); if (!gdev->mem_balloon.pages) return; diff --git a/drivers/virt/vboxguest/vboxguest_linux.c b/drivers/virt/vboxguest/vboxguest_linux.c index 8c92ea5b730519..7474bae2cd9adb 100644 --- a/drivers/virt/vboxguest/vboxguest_linux.c +++ b/drivers/virt/vboxguest/vboxguest_linux.c @@ -292,7 +292,7 @@ static int vbg_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) struct vbg_dev *gdev; int ret; - gdev = devm_kzalloc(dev, sizeof(*gdev), GFP_KERNEL); + gdev = devm_kzalloc_obj(dev, *gdev); if (!gdev) return -ENOMEM; diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index ce957f5b1c317d..9070bce5a19ee8 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -141,7 +141,7 @@ static int vmgenid_add(struct platform_device *pdev) struct vmgenid_state *state; int ret; - state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL); + state = devm_kmalloc_obj(dev, *state); if (!state) return -ENOMEM; diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index ab3e3d887e00f3..8c1b47ec17a293 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -942,6 +942,7 @@ static int virtballoon_probe(struct virtio_device *vdev) INIT_WORK(&vb->update_balloon_stats_work, update_balloon_stats_func); INIT_WORK(&vb->update_balloon_size_work, update_balloon_size_func); spin_lock_init(&vb->stop_update_lock); + spin_lock_init(&vb->wakeup_lock); mutex_init(&vb->balloon_lock); init_waitqueue_head(&vb->acked); vb->vdev = vdev; @@ -1049,8 +1050,6 @@ static int virtballoon_probe(struct virtio_device *vdev) goto out_unregister_oom; } - spin_lock_init(&vb->wakeup_lock); - /* * The virtio balloon itself can't wake up the device, but it is * responsible for processing wakeup events passed up from the transport diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index faae58e3401a63..e2ec0ec01d672c 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -270,7 +270,7 @@ static void vm_reset(struct virtio_device *vdev) /* Transport interface */ -/* the notify function used when creating a virt queue */ +/* the notify function used when creating a virtqueue */ static bool vm_notify(struct virtqueue *vq) { struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev); diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index b90c174450b20a..79d3395f370501 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -47,7 +47,7 @@ void vp_synchronize_vectors(struct virtio_device *vdev) synchronize_irq(pci_irq_vector(vp_dev->pci_dev, i)); } -/* the notify function used when creating a virt queue */ +/* the notify function used when creating a virtqueue */ bool vp_notify(struct virtqueue *vq) { /* we write the queue's selector into the notification register to @@ -224,6 +224,12 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int in goto out_info; info->vq = vq; + + if (msix_vec != VIRTIO_MSI_NO_VECTOR) + info->virq = pci_irq_vector(vp_dev->pci_dev, msix_vec); + else + info->virq = 0; + if (callback) { spin_lock_irqsave(&vp_dev->lock, flags); if (!vp_is_slow_path_vector(msix_vec)) @@ -571,7 +577,7 @@ int vp_set_vq_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask) if (vp_dev->msix_enabled) { mask = vp_dev->msix_affinity_masks[info->msix_vector]; - irq = pci_irq_vector(vp_dev->pci_dev, info->msix_vector); + irq = info->virq; if (!cpu_mask) irq_update_affinity_hint(irq, NULL); else { @@ -633,7 +639,7 @@ static bool vp_supports_pm_no_reset(struct device *dev) pci_read_config_word(pci_dev, pci_dev->pm_cap + PCI_PM_CTRL, &pmcsr); if (PCI_POSSIBLE_ERROR(pmcsr)) { - dev_err(dev, "Unable to query pmcsr"); + dev_err(dev, "Unable to query pmcsr\n"); return false; } diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h index 8cd01de27bafe2..4ce903e7d3a99b 100644 --- a/drivers/virtio/virtio_pci_common.h +++ b/drivers/virtio/virtio_pci_common.h @@ -40,6 +40,9 @@ struct virtio_pci_vq_info { /* MSI-X vector (or none) */ unsigned int msix_vector; + + /* Linux IRQ number of msix_vector, or 0 if not mapped */ + unsigned int virq; }; struct virtio_pci_admin_vq { @@ -127,7 +130,7 @@ static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev) /* wait for pending irq handlers */ void vp_synchronize_vectors(struct virtio_device *vdev); -/* the notify function used when creating a virt queue */ +/* the notify function used when creating a virtqueue */ bool vp_notify(struct virtqueue *vq); /* the config->del_vqs() implementation */ void vp_del_vqs(struct virtio_device *vdev); diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index db678f5a80e03a..f683a2d6a2002f 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -559,6 +559,11 @@ static void virtqueue_init(struct vring_virtqueue *vq, u32 num) vq->in_use = false; vq->last_add_time_valid = false; #endif + + if (virtqueue_is_in_order(vq)) { + vq->free_head = 0; + vq->batch_last.id = UINT_MAX; + } } @@ -905,7 +910,6 @@ static unsigned detach_buf_split_in_order(struct vring_virtqueue *vq, { struct vring_desc_extra *extra; unsigned int i; - __virtio16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT); /* Clear data ptr. */ vq->split.desc_state[head].data = NULL; @@ -915,7 +919,7 @@ static unsigned detach_buf_split_in_order(struct vring_virtqueue *vq, /* Put back on free list: unmap first-level descriptors and find end */ i = head; - while (vq->split.vring.desc[i].flags & nextflag) { + while (extra[i].flags & VRING_DESC_F_NEXT) { i = vring_unmap_one_split(vq, &extra[i]); vq->vq.num_free++; } @@ -1571,6 +1575,11 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq, 0 : VRING_DESC_F_WRITE); desc[i].addr = cpu_to_le64(addr); desc[i].len = cpu_to_le32(len); + /* The id field is unused in indirect descriptors but + * must be initialized to prevent leaking kernel heap + * memory to the device through the DMA-mapped table. + */ + desc[i].id = 0; if (unlikely(vq->use_map_api)) { extra[i].addr = premapped ? DMA_MAPPING_ERROR : addr; diff --git a/drivers/virtio/virtio_rtc_class.c b/drivers/virtio/virtio_rtc_class.c index 05d6d28255cf3d..ec974aeacda8ba 100644 --- a/drivers/virtio/virtio_rtc_class.c +++ b/drivers/virtio/virtio_rtc_class.c @@ -238,8 +238,7 @@ struct viortc_class *viortc_class_init(struct viortc_dev *viortc, struct viortc_class *viortc_class; struct rtc_device *rtc; - viortc_class = - devm_kzalloc(parent_dev, sizeof(*viortc_class), GFP_KERNEL); + viortc_class = devm_kzalloc_obj(parent_dev, *viortc_class); if (!viortc_class) return ERR_PTR(-ENOMEM); diff --git a/drivers/virtio/virtio_rtc_driver.c b/drivers/virtio/virtio_rtc_driver.c index 74616ba5be119c..b45a7abe13c95e 100644 --- a/drivers/virtio/virtio_rtc_driver.c +++ b/drivers/virtio/virtio_rtc_driver.c @@ -163,7 +163,7 @@ static struct viortc_msg *viortc_msg_init(struct viortc_dev *viortc, struct virtio_rtc_req_head *req_head; struct viortc_msg *msg; - msg = devm_kzalloc(dev, sizeof(*msg), GFP_KERNEL); + msg = devm_kzalloc_obj(dev, *msg); if (!msg) return NULL; @@ -1099,8 +1099,8 @@ static int viortc_clocks_init(struct viortc_dev *viortc) viortc->num_clocks = num_clocks; viortc->clocks_to_unregister = - devm_kcalloc(&viortc->vdev->dev, num_clocks, - sizeof(*viortc->clocks_to_unregister), GFP_KERNEL); + devm_kzalloc_objs(&viortc->vdev->dev, + *viortc->clocks_to_unregister, num_clocks); if (!viortc->clocks_to_unregister) return -ENOMEM; @@ -1182,7 +1182,7 @@ static int viortc_alloc_vq_bufs(struct viortc_dev *viortc, unsigned int i; void *buf; - buf_list = devm_kcalloc(dev, num_elems, sizeof(*buf_list), GFP_KERNEL); + buf_list = devm_kzalloc_objs(dev, *buf_list, num_elems); if (!buf_list) return -ENOMEM; @@ -1282,7 +1282,7 @@ static int viortc_probe(struct virtio_device *vdev) bool notify; int ret; - viortc = devm_kzalloc(&vdev->dev, sizeof(*viortc), GFP_KERNEL); + viortc = devm_kzalloc_obj(&vdev->dev, *viortc); if (!viortc) return -ENOMEM; diff --git a/drivers/virtio/virtio_rtc_ptp.c b/drivers/virtio/virtio_rtc_ptp.c index ff8d834493dcbe..54d6efd41fd9b9 100644 --- a/drivers/virtio/virtio_rtc_ptp.c +++ b/drivers/virtio/virtio_rtc_ptp.c @@ -309,7 +309,7 @@ struct viortc_ptp_clock *viortc_ptp_register(struct viortc_dev *viortc, ssize_t len; int ret; - vio_ptp = devm_kzalloc(parent_dev, sizeof(*vio_ptp), GFP_KERNEL); + vio_ptp = devm_kzalloc_obj(parent_dev, *vio_ptp); if (!vio_ptp) return ERR_PTR(-ENOMEM); diff --git a/drivers/w1/masters/amd_axi_w1.c b/drivers/w1/masters/amd_axi_w1.c index 96d986e0f58d77..31e7f0b3c88db8 100644 --- a/drivers/w1/masters/amd_axi_w1.c +++ b/drivers/w1/masters/amd_axi_w1.c @@ -299,7 +299,7 @@ static int amd_axi_w1_probe(struct platform_device *pdev) u32 ver_major, ver_minor; int val, rc = 0; - lp = devm_kzalloc(dev, sizeof(*lp), GFP_KERNEL); + lp = devm_kzalloc_obj(dev, *lp); if (!lp) return -ENOMEM; diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c index cbd11bc6127493..eee9df238f6a4c 100644 --- a/drivers/w1/masters/ds2482.c +++ b/drivers/w1/masters/ds2482.c @@ -457,7 +457,7 @@ static int ds2482_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE)) return -ENODEV; - data = devm_kzalloc(&client->dev, sizeof(struct ds2482_data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, struct ds2482_data); if (!data) return -ENOMEM; diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c index 3cbff88c339e96..b4e1415573c1a8 100644 --- a/drivers/w1/masters/ds2490.c +++ b/drivers/w1/masters/ds2490.c @@ -718,7 +718,7 @@ static void ds9490r_search(void *data, struct w1_master *master, * We are holding the bus mutex during the scan, but adding devices via the * callback needs the bus to be unlocked. So we queue up found ids here. */ - found_ids = kmalloc_array(master->max_slave_count, sizeof(u64), GFP_KERNEL); + found_ids = kmalloc_objs(u64, master->max_slave_count); if (!found_ids) { kfree(buf); return; diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c index 761dcbdd732afa..06be7bf0b71558 100644 --- a/drivers/w1/masters/mxc_w1.c +++ b/drivers/w1/masters/mxc_w1.c @@ -94,8 +94,7 @@ static int mxc_w1_probe(struct platform_device *pdev) unsigned int clkdiv; int err; - mdev = devm_kzalloc(&pdev->dev, sizeof(struct mxc_w1_device), - GFP_KERNEL); + mdev = devm_kzalloc_obj(&pdev->dev, struct mxc_w1_device); if (!mdev) return -ENOMEM; diff --git a/drivers/w1/masters/omap_hdq.c b/drivers/w1/masters/omap_hdq.c index d13db339657094..f3fffcf9828ad7 100644 --- a/drivers/w1/masters/omap_hdq.c +++ b/drivers/w1/masters/omap_hdq.c @@ -568,7 +568,7 @@ static int omap_hdq_probe(struct platform_device *pdev) u8 rev; const char *mode; - hdq_data = devm_kzalloc(dev, sizeof(*hdq_data), GFP_KERNEL); + hdq_data = devm_kzalloc_obj(dev, *hdq_data); if (!hdq_data) return -ENOMEM; diff --git a/drivers/w1/masters/sgi_w1.c b/drivers/w1/masters/sgi_w1.c index 48c10062022c6a..2bc2459b360537 100644 --- a/drivers/w1/masters/sgi_w1.c +++ b/drivers/w1/masters/sgi_w1.c @@ -77,8 +77,7 @@ static int sgi_w1_probe(struct platform_device *pdev) struct sgi_w1_device *sdev; struct sgi_w1_platform_data *pdata; - sdev = devm_kzalloc(&pdev->dev, sizeof(struct sgi_w1_device), - GFP_KERNEL); + sdev = devm_kzalloc_obj(&pdev->dev, struct sgi_w1_device); if (!sdev) return -ENOMEM; diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c index 184aea37bfafba..9c8b8fd3862736 100644 --- a/drivers/w1/masters/w1-gpio.c +++ b/drivers/w1/masters/w1-gpio.c @@ -71,7 +71,7 @@ static int w1_gpio_probe(struct platform_device *pdev) enum gpiod_flags gflags = GPIOD_OUT_LOW_OPEN_DRAIN; int err; - ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(&pdev->dev, *ddata); if (!ddata) return -ENOMEM; @@ -84,7 +84,7 @@ static int w1_gpio_probe(struct platform_device *pdev) if (device_property_present(dev, "linux,open-drain")) gflags = GPIOD_OUT_LOW; - master = devm_kzalloc(dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(dev, *master); if (!master) return -ENOMEM; diff --git a/drivers/w1/masters/w1-uart.c b/drivers/w1/masters/w1-uart.c index c87eea34780678..6e46773167d90e 100644 --- a/drivers/w1/masters/w1-uart.c +++ b/drivers/w1/masters/w1-uart.c @@ -361,7 +361,7 @@ static int w1_uart_probe(struct serdev_device *serdev) struct w1_uart_device *w1dev; int ret; - w1dev = devm_kzalloc(dev, sizeof(*w1dev), GFP_KERNEL); + w1dev = devm_kzalloc_obj(dev, *w1dev); if (!w1dev) return -ENOMEM; w1dev->bus.data = w1dev; diff --git a/drivers/w1/slaves/w1_ds250x.c b/drivers/w1/slaves/w1_ds250x.c index cb426f7dd23d44..9c5e9033d14cc9 100644 --- a/drivers/w1/slaves/w1_ds250x.c +++ b/drivers/w1/slaves/w1_ds250x.c @@ -177,7 +177,7 @@ static int w1_eprom_add_slave(struct w1_slave *sl) .id = -1 }; - data = devm_kzalloc(&sl->dev, sizeof(struct w1_eprom_data), GFP_KERNEL); + data = devm_kzalloc_obj(&sl->dev, struct w1_eprom_data); if (!data) return -ENOMEM; diff --git a/drivers/w1/slaves/w1_ds28e17.c b/drivers/w1/slaves/w1_ds28e17.c index b638963d4b5951..9b32d824524879 100644 --- a/drivers/w1/slaves/w1_ds28e17.c +++ b/drivers/w1/slaves/w1_ds28e17.c @@ -691,7 +691,7 @@ static int w1_f19_add_slave(struct w1_slave *sl) struct w1_f19_data *data = NULL; /* Allocate memory for slave specific data. */ - data = devm_kzalloc(&sl->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&sl->dev, *data); if (!data) return -ENOMEM; sl->family_data = data; diff --git a/drivers/watchdog/airoha_wdt.c b/drivers/watchdog/airoha_wdt.c index c535c48ab6a86d..332677bd828ac8 100644 --- a/drivers/watchdog/airoha_wdt.c +++ b/drivers/watchdog/airoha_wdt.c @@ -133,7 +133,7 @@ static int airoha_wdt_probe(struct platform_device *pdev) struct clk *bus_clk; int ret; - airoha_wdt = devm_kzalloc(dev, sizeof(*airoha_wdt), GFP_KERNEL); + airoha_wdt = devm_kzalloc_obj(dev, *airoha_wdt); if (!airoha_wdt) return -ENOMEM; diff --git a/drivers/watchdog/apple_wdt.c b/drivers/watchdog/apple_wdt.c index f533953294f62a..181b687d8601c1 100644 --- a/drivers/watchdog/apple_wdt.c +++ b/drivers/watchdog/apple_wdt.c @@ -161,7 +161,7 @@ static int apple_wdt_probe(struct platform_device *pdev) struct clk *clk; u32 wdt_ctrl; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/arm_smc_wdt.c b/drivers/watchdog/arm_smc_wdt.c index c73ed1dcdfcb02..479863450a9cad 100644 --- a/drivers/watchdog/arm_smc_wdt.c +++ b/drivers/watchdog/arm_smc_wdt.c @@ -118,7 +118,7 @@ static int smcwd_probe(struct platform_device *pdev) struct arm_smccc_res res; u32 smc_func_id; - wdd = devm_kzalloc(&pdev->dev, sizeof(*wdd), GFP_KERNEL); + wdd = devm_kzalloc_obj(&pdev->dev, *wdd); if (!wdd) return -ENOMEM; platform_set_drvdata(pdev, wdd); diff --git a/drivers/watchdog/armada_37xx_wdt.c b/drivers/watchdog/armada_37xx_wdt.c index d62b02c40b0eba..3af8dd8bceb9a2 100644 --- a/drivers/watchdog/armada_37xx_wdt.c +++ b/drivers/watchdog/armada_37xx_wdt.c @@ -252,8 +252,7 @@ static int armada_37xx_wdt_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(struct armada_37xx_watchdog), - GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, struct armada_37xx_watchdog); if (!dev) return -ENOMEM; diff --git a/drivers/watchdog/asm9260_wdt.c b/drivers/watchdog/asm9260_wdt.c index 45047e514b8e6f..15c264ff3afcf6 100644 --- a/drivers/watchdog/asm9260_wdt.c +++ b/drivers/watchdog/asm9260_wdt.c @@ -290,7 +290,7 @@ static int asm9260_wdt_probe(struct platform_device *pdev) int ret; static const char * const mode_name[] = { "hw", "sw", "debug", }; - priv = devm_kzalloc(dev, sizeof(struct asm9260_wdt_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct asm9260_wdt_priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index d4bd41cb801e60..13e3b80f61b036 100644 --- a/drivers/watchdog/aspeed_wdt.c +++ b/drivers/watchdog/aspeed_wdt.c @@ -410,7 +410,7 @@ static int aspeed_wdt_probe(struct platform_device *pdev) u32 status; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c index f966da6020111c..fea97543389042 100644 --- a/drivers/watchdog/at91sam9_wdt.c +++ b/drivers/watchdog/at91sam9_wdt.c @@ -330,7 +330,7 @@ static int at91wdt_probe(struct platform_device *pdev) int err; struct at91wdt *wdt; - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&pdev->dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/atcwdt200_wdt.c b/drivers/watchdog/atcwdt200_wdt.c index ceedc3f6763207..9bfdece76afd21 100644 --- a/drivers/watchdog/atcwdt200_wdt.c +++ b/drivers/watchdog/atcwdt200_wdt.c @@ -492,7 +492,7 @@ static int atcwdt_probe(struct platform_device *pdev) struct atcwdt_drv *drv_data; int ret; - drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c index 1a0fc66cc0930a..755954cbadee4d 100644 --- a/drivers/watchdog/bcm2835_wdt.c +++ b/drivers/watchdog/bcm2835_wdt.c @@ -177,7 +177,7 @@ static int bcm2835_wdt_probe(struct platform_device *pdev) struct bcm2835_wdt *wdt; int err; - wdt = devm_kzalloc(dev, sizeof(struct bcm2835_wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, struct bcm2835_wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/bcm7038_wdt.c b/drivers/watchdog/bcm7038_wdt.c index 1117026cf95945..5bac9c330b6036 100644 --- a/drivers/watchdog/bcm7038_wdt.c +++ b/drivers/watchdog/bcm7038_wdt.c @@ -136,7 +136,7 @@ static int bcm7038_wdt_probe(struct platform_device *pdev) const char *clk_name = NULL; int err; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/bcm_kona_wdt.c b/drivers/watchdog/bcm_kona_wdt.c index 66bd0324fd68db..d4f031deb25439 100644 --- a/drivers/watchdog/bcm_kona_wdt.c +++ b/drivers/watchdog/bcm_kona_wdt.c @@ -271,7 +271,7 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev) struct bcm_kona_wdt *wdt; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/bd9576_wdt.c b/drivers/watchdog/bd9576_wdt.c index f00ea1b4e40b6a..f2171d87b16638 100644 --- a/drivers/watchdog/bd9576_wdt.c +++ b/drivers/watchdog/bd9576_wdt.c @@ -204,7 +204,7 @@ static int bd9576_wdt_probe(struct platform_device *pdev) int count; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/bd96801_wdt.c b/drivers/watchdog/bd96801_wdt.c index e5a56f53b41923..ce93a900b0be02 100644 --- a/drivers/watchdog/bd96801_wdt.c +++ b/drivers/watchdog/bd96801_wdt.c @@ -337,7 +337,7 @@ static int bd96801_wdt_probe(struct platform_device *pdev) int ret, irq; unsigned int val; - w = devm_kzalloc(&pdev->dev, sizeof(*w), GFP_KERNEL); + w = devm_kzalloc_obj(&pdev->dev, *w); if (!w) return -ENOMEM; diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c index 55a7c08dc1c159..19e3f3f03cbee1 100644 --- a/drivers/watchdog/cadence_wdt.c +++ b/drivers/watchdog/cadence_wdt.c @@ -292,7 +292,7 @@ static int cdns_wdt_probe(struct platform_device *pdev) struct cdns_wdt *wdt; struct watchdog_device *cdns_wdt_device; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/cgbc_wdt.c b/drivers/watchdog/cgbc_wdt.c index a90e6af13bed30..f5e895921f3b41 100644 --- a/drivers/watchdog/cgbc_wdt.c +++ b/drivers/watchdog/cgbc_wdt.c @@ -171,7 +171,7 @@ static int cgbc_wdt_probe(struct platform_device *pdev) struct cgbc_wdt_data *wdt_data; struct watchdog_device *wdd; - wdt_data = devm_kzalloc(dev, sizeof(*wdt_data), GFP_KERNEL); + wdt_data = devm_kzalloc_obj(dev, *wdt_data); if (!wdt_data) return -ENOMEM; diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c index 13a4d47e68cd82..cf79437064a6a3 100644 --- a/drivers/watchdog/cpwd.c +++ b/drivers/watchdog/cpwd.c @@ -520,7 +520,7 @@ static int cpwd_probe(struct platform_device *op) if (cpwd_device) return -EINVAL; - p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&op->dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c index 2283419d8b3810..d051a5db364250 100644 --- a/drivers/watchdog/cros_ec_wdt.c +++ b/drivers/watchdog/cros_ec_wdt.c @@ -124,7 +124,7 @@ static int cros_ec_wdt_probe(struct platform_device *pdev) union cros_ec_wdt_data arg; int ret = 0; - wdd = devm_kzalloc(&pdev->dev, sizeof(*wdd), GFP_KERNEL); + wdd = devm_kzalloc_obj(&pdev->dev, *wdd); if (!wdd) return -ENOMEM; diff --git a/drivers/watchdog/da9052_wdt.c b/drivers/watchdog/da9052_wdt.c index 959cba0a881951..f725c24faef951 100644 --- a/drivers/watchdog/da9052_wdt.c +++ b/drivers/watchdog/da9052_wdt.c @@ -173,7 +173,7 @@ static int da9052_wdt_probe(struct platform_device *pdev) struct watchdog_device *da9052_wdt; int ret; - driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(dev, *driver_data); if (!driver_data) return -ENOMEM; driver_data->da9052 = da9052; diff --git a/drivers/watchdog/da9055_wdt.c b/drivers/watchdog/da9055_wdt.c index cbb87855bd6a45..abbfb19225e417 100644 --- a/drivers/watchdog/da9055_wdt.c +++ b/drivers/watchdog/da9055_wdt.c @@ -126,7 +126,7 @@ static int da9055_wdt_probe(struct platform_device *pdev) struct watchdog_device *da9055_wdt; int ret; - driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(dev, *driver_data); if (!driver_data) return -ENOMEM; diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c index 3d7bf2f351db1a..4bb6f484527e78 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -211,7 +211,7 @@ static int da9062_wdt_probe(struct platform_device *pdev) if (!chip) return -EINVAL; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c index 3703110e82fcc5..ca901a755b3a2d 100644 --- a/drivers/watchdog/da9063_wdt.c +++ b/drivers/watchdog/da9063_wdt.c @@ -225,7 +225,7 @@ static int da9063_wdt_probe(struct platform_device *pdev) if (!da9063) return -EINVAL; - wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); + wdd = devm_kzalloc_obj(dev, *wdd); if (!wdd) return -ENOMEM; diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c index 074e95cf2fe7b5..8c9bbf17952663 100644 --- a/drivers/watchdog/davinci_wdt.c +++ b/drivers/watchdog/davinci_wdt.c @@ -195,7 +195,7 @@ static int davinci_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdd; struct davinci_wdt_device *davinci_wdt; - davinci_wdt = devm_kzalloc(dev, sizeof(*davinci_wdt), GFP_KERNEL); + davinci_wdt = devm_kzalloc_obj(dev, *davinci_wdt); if (!davinci_wdt) return -ENOMEM; diff --git a/drivers/watchdog/digicolor_wdt.c b/drivers/watchdog/digicolor_wdt.c index de1a3267a97233..4f8faf7886d8ee 100644 --- a/drivers/watchdog/digicolor_wdt.c +++ b/drivers/watchdog/digicolor_wdt.c @@ -120,7 +120,7 @@ static int dc_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct dc_wdt *wdt; - wdt = devm_kzalloc(dev, sizeof(struct dc_wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, struct dc_wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c index c1d40d7b2165f5..389bcc846ff80b 100644 --- a/drivers/watchdog/dw_wdt.c +++ b/drivers/watchdog/dw_wdt.c @@ -521,7 +521,7 @@ static void dw_wdt_dbgfs_init(struct dw_wdt *dw_wdt) struct device *dev = dw_wdt->wdd.parent; struct debugfs_regset32 *regset; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + regset = devm_kzalloc_obj(dev, *regset); if (!regset) return; @@ -553,7 +553,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev) struct dw_wdt *dw_wdt; int ret; - dw_wdt = devm_kzalloc(dev, sizeof(*dw_wdt), GFP_KERNEL); + dw_wdt = devm_kzalloc_obj(dev, *dw_wdt); if (!dw_wdt) return -ENOMEM; diff --git a/drivers/watchdog/ebc-c384_wdt.c b/drivers/watchdog/ebc-c384_wdt.c index 39cc1f7e1cdb0e..c80a28b09de0b8 100644 --- a/drivers/watchdog/ebc-c384_wdt.c +++ b/drivers/watchdog/ebc-c384_wdt.c @@ -98,7 +98,7 @@ static int ebc_c384_wdt_probe(struct device *dev, unsigned int id) return -EBUSY; } - wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); + wdd = devm_kzalloc_obj(dev, *wdd); if (!wdd) return -ENOMEM; diff --git a/drivers/watchdog/ep93xx_wdt.c b/drivers/watchdog/ep93xx_wdt.c index 59dfd7f6bf0ba1..36c308b76fa1b4 100644 --- a/drivers/watchdog/ep93xx_wdt.c +++ b/drivers/watchdog/ep93xx_wdt.c @@ -92,7 +92,7 @@ static int ep93xx_wdt_probe(struct platform_device *pdev) unsigned long val; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c index 2790061a68f343..f61a53e64dcb9e 100644 --- a/drivers/watchdog/f71808e_wdt.c +++ b/drivers/watchdog/f71808e_wdt.c @@ -459,7 +459,7 @@ static int fintek_wdt_probe(struct platform_device *pdev) sioaddr = res->start; - wd = devm_kzalloc(dev, sizeof(*wd), GFP_KERNEL); + wd = devm_kzalloc_obj(dev, *wd); if (!wd) return -ENOMEM; diff --git a/drivers/watchdog/ftwdt010_wdt.c b/drivers/watchdog/ftwdt010_wdt.c index 67f16b34a25fb0..66f0768c22a2cc 100644 --- a/drivers/watchdog/ftwdt010_wdt.c +++ b/drivers/watchdog/ftwdt010_wdt.c @@ -140,7 +140,7 @@ static int ftwdt010_wdt_probe(struct platform_device *pdev) int irq; int ret; - gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL); + gwdt = devm_kzalloc_obj(dev, *gwdt); if (!gwdt) return -ENOMEM; diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c index 2cd79c8f60dcd8..ed42988077136d 100644 --- a/drivers/watchdog/gpio_wdt.c +++ b/drivers/watchdog/gpio_wdt.c @@ -113,7 +113,7 @@ static int gpio_wdt_probe(struct platform_device *pdev) const char *algo; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/gunyah_wdt.c b/drivers/watchdog/gunyah_wdt.c index 557a78306d18fb..35958594e17ca9 100644 --- a/drivers/watchdog/gunyah_wdt.c +++ b/drivers/watchdog/gunyah_wdt.c @@ -62,19 +62,12 @@ static int gunyah_wdt_call(unsigned long func_id, unsigned long arg1, return gunyah_error_remap(res.a0); } -static int gunyah_wdt_start(struct watchdog_device *wdd) +static int gunyah_wdt_enable(struct watchdog_device *wdd) { - unsigned int timeout_ms; + unsigned int timeout_ms = wdd->timeout * 1000; struct device *dev = wdd->parent; int ret; - ret = gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0); - if (ret && watchdog_active(wdd)) { - dev_err(dev, "%s: Failed to stop gunyah wdt %d\n", __func__, ret); - return ret; - } - - timeout_ms = wdd->timeout * 1000; ret = gunyah_wdt_call(GUNYAH_WDT_SET_TIME, timeout_ms, timeout_ms); if (ret) { dev_err(dev, "%s: Failed to set timeout for gunyah wdt %d\n", @@ -89,6 +82,20 @@ static int gunyah_wdt_start(struct watchdog_device *wdd) return ret; } +static int gunyah_wdt_start(struct watchdog_device *wdd) +{ + struct device *dev = wdd->parent; + int ret; + + ret = gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0); + if (ret && watchdog_active(wdd)) { + dev_err(dev, "%s: Failed to stop gunyah wdt %d\n", __func__, ret); + return ret; + } + + return gunyah_wdt_enable(wdd); +} + static int gunyah_wdt_stop(struct watchdog_device *wdd) { return gunyah_wdt_call(GUNYAH_WDT_CONTROL, WDT_CTRL_DISABLE, 0); @@ -178,7 +185,7 @@ static int gunyah_wdt_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "status check failed\n"); - wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); + wdd = devm_kzalloc_obj(dev, *wdd); if (!wdd) return -ENOMEM; @@ -224,7 +231,7 @@ static int gunyah_wdt_resume(struct device *dev) struct watchdog_device *wdd = dev_get_drvdata(dev); if (watchdog_active(wdd)) - gunyah_wdt_start(wdd); + gunyah_wdt_enable(wdd); return 0; } diff --git a/drivers/watchdog/gxp-wdt.c b/drivers/watchdog/gxp-wdt.c index f2c23616026621..173fdaa4f345cc 100644 --- a/drivers/watchdog/gxp-wdt.c +++ b/drivers/watchdog/gxp-wdt.c @@ -117,7 +117,7 @@ static int gxp_wdt_probe(struct platform_device *pdev) int err; u8 val; - drvdata = devm_kzalloc(dev, sizeof(struct gxp_wdt), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct gxp_wdt); if (!drvdata) return -ENOMEM; diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c index 7f08d6d2ca7789..c93ea556eb6ba3 100644 --- a/drivers/watchdog/i6300esb.c +++ b/drivers/watchdog/i6300esb.c @@ -301,7 +301,7 @@ static int esb_probe(struct pci_dev *pdev, struct esb_dev *edev; int ret; - edev = devm_kzalloc(&pdev->dev, sizeof(*edev), GFP_KERNEL); + edev = devm_kzalloc_obj(&pdev->dev, *edev); if (!edev) return -ENOMEM; diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c index 0a8bf28f57688b..5281d6e15963be 100644 --- a/drivers/watchdog/iTCO_wdt.c +++ b/drivers/watchdog/iTCO_wdt.c @@ -462,7 +462,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev) if (!pdata) return -ENODEV; - p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(dev, *p); if (!p) return -ENOMEM; diff --git a/drivers/watchdog/imgpdc_wdt.c b/drivers/watchdog/imgpdc_wdt.c index bb6227c40de433..b409f6784b5027 100644 --- a/drivers/watchdog/imgpdc_wdt.c +++ b/drivers/watchdog/imgpdc_wdt.c @@ -183,7 +183,7 @@ static int pdc_wdt_probe(struct platform_device *pdev) unsigned long clk_rate; struct pdc_wdt_dev *pdc_wdt; - pdc_wdt = devm_kzalloc(dev, sizeof(*pdc_wdt), GFP_KERNEL); + pdc_wdt = devm_kzalloc_obj(dev, *pdc_wdt); if (!pdc_wdt) return -ENOMEM; diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c index 58aa5f999f4feb..4240732b2c34f6 100644 --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -274,7 +274,7 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) int ret; u32 val; - wdev = devm_kzalloc(dev, sizeof(*wdev), GFP_KERNEL); + wdev = devm_kzalloc_obj(dev, *wdev); if (!wdev) return -ENOMEM; diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c index f61936194aea82..7d675ca07aaec2 100644 --- a/drivers/watchdog/imx7ulp_wdt.c +++ b/drivers/watchdog/imx7ulp_wdt.c @@ -317,7 +317,7 @@ static int imx7ulp_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdog; int ret; - imx7ulp_wdt = devm_kzalloc(dev, sizeof(*imx7ulp_wdt), GFP_KERNEL); + imx7ulp_wdt = devm_kzalloc_obj(dev, *imx7ulp_wdt); if (!imx7ulp_wdt) return -ENOMEM; diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c index fc39f9db4c06f5..5da8f02c802f55 100644 --- a/drivers/watchdog/imx_sc_wdt.c +++ b/drivers/watchdog/imx_sc_wdt.c @@ -183,7 +183,7 @@ static int imx_sc_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - imx_sc_wdd = devm_kzalloc(dev, sizeof(*imx_sc_wdd), GFP_KERNEL); + imx_sc_wdd = devm_kzalloc_obj(dev, *imx_sc_wdd); if (!imx_sc_wdd) return -ENOMEM; diff --git a/drivers/watchdog/intel-mid_wdt.c b/drivers/watchdog/intel-mid_wdt.c index b1e1b77ed19059..e5afef4a03e746 100644 --- a/drivers/watchdog/intel-mid_wdt.c +++ b/drivers/watchdog/intel-mid_wdt.c @@ -141,7 +141,7 @@ static int mid_wdt_probe(struct platform_device *pdev) return ret; } - mid = devm_kzalloc(dev, sizeof(*mid), GFP_KERNEL); + mid = devm_kzalloc_obj(dev, *mid); if (!mid) return -ENOMEM; diff --git a/drivers/watchdog/intel_oc_wdt.c b/drivers/watchdog/intel_oc_wdt.c index d1e9a3f62369f5..0b012aeb18e155 100644 --- a/drivers/watchdog/intel_oc_wdt.c +++ b/drivers/watchdog/intel_oc_wdt.c @@ -172,7 +172,7 @@ static int intel_oc_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdd; int ret; - oc_wdt = devm_kzalloc(&pdev->dev, sizeof(*oc_wdt), GFP_KERNEL); + oc_wdt = devm_kzalloc_obj(&pdev->dev, *oc_wdt); if (!oc_wdt) return -ENOMEM; diff --git a/drivers/watchdog/ixp4xx_wdt.c b/drivers/watchdog/ixp4xx_wdt.c index ec0c08652ec2f9..29d913b1e8d124 100644 --- a/drivers/watchdog/ixp4xx_wdt.c +++ b/drivers/watchdog/ixp4xx_wdt.c @@ -146,7 +146,7 @@ static int ixp4xx_wdt_probe(struct platform_device *pdev) iwdt_ops = &ixp4xx_wdt_ops; } - iwdt = devm_kzalloc(dev, sizeof(*iwdt), GFP_KERNEL); + iwdt = devm_kzalloc_obj(dev, *iwdt); if (!iwdt) return -ENOMEM; iwdt->base = (void __iomem *)dev->platform_data; diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c index 9dec1b82241014..a804875a06dded 100644 --- a/drivers/watchdog/jz4740_wdt.c +++ b/drivers/watchdog/jz4740_wdt.c @@ -143,8 +143,7 @@ static int jz4740_wdt_probe(struct platform_device *pdev) long rate; int ret; - drvdata = devm_kzalloc(dev, sizeof(struct jz4740_wdt_drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct jz4740_wdt_drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/watchdog/keembay_wdt.c b/drivers/watchdog/keembay_wdt.c index 76246a7714ca43..9405ac8508aa1b 100644 --- a/drivers/watchdog/keembay_wdt.c +++ b/drivers/watchdog/keembay_wdt.c @@ -191,7 +191,7 @@ static int keembay_wdt_probe(struct platform_device *pdev) struct keembay_wdt *wdt; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/kempld_wdt.c b/drivers/watchdog/kempld_wdt.c index b4cde48d2b10a7..2bf4baa1862694 100644 --- a/drivers/watchdog/kempld_wdt.c +++ b/drivers/watchdog/kempld_wdt.c @@ -441,7 +441,7 @@ static int kempld_wdt_probe(struct platform_device *pdev) u8 status; int ret = 0; - wdt_data = devm_kzalloc(dev, sizeof(*wdt_data), GFP_KERNEL); + wdt_data = devm_kzalloc_obj(dev, *wdt_data); if (!wdt_data) return -ENOMEM; diff --git a/drivers/watchdog/lantiq_wdt.c b/drivers/watchdog/lantiq_wdt.c index a273b97ebcb4bd..5ea53c6f2131e2 100644 --- a/drivers/watchdog/lantiq_wdt.c +++ b/drivers/watchdog/lantiq_wdt.c @@ -207,7 +207,7 @@ static int ltq_wdt_probe(struct platform_device *pdev) int ret; u32 status; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/lenovo_se10_wdt.c b/drivers/watchdog/lenovo_se10_wdt.c index 1eaf86c85cc0e7..2007c7ee447aed 100644 --- a/drivers/watchdog/lenovo_se10_wdt.c +++ b/drivers/watchdog/lenovo_se10_wdt.c @@ -190,7 +190,7 @@ static int se10_wdt_probe(struct platform_device *pdev) dev_info(dev, "Found Lenovo SE10 0x%x\n", chip_id); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/lenovo_se30_wdt.c b/drivers/watchdog/lenovo_se30_wdt.c index 127ea9a1933ffb..a8da482f46405c 100644 --- a/drivers/watchdog/lenovo_se30_wdt.c +++ b/drivers/watchdog/lenovo_se30_wdt.c @@ -264,7 +264,7 @@ static int lenovo_se30_wdt_probe(struct platform_device *pdev) if (base_phys == 0xFFFFFFFF || base_phys == 0) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/lenovo_se30g2_se60_wdt.c b/drivers/watchdog/lenovo_se30g2_se60_wdt.c index c87abdb1a1b2d1..f79864b28550b1 100644 --- a/drivers/watchdog/lenovo_se30g2_se60_wdt.c +++ b/drivers/watchdog/lenovo_se30g2_se60_wdt.c @@ -188,7 +188,7 @@ static int se_30g2_60_wdt_probe(struct platform_device *pdev) release_region(CFG_PORT, CFG_SIZE); dev_info(dev, "Found Lenovo SE30G2 SE60 0x%x\n", chip_id); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c index 7f8de11f1b4ab1..2811e7eab631a2 100644 --- a/drivers/watchdog/loongson1_wdt.c +++ b/drivers/watchdog/loongson1_wdt.c @@ -130,7 +130,7 @@ static int ls1x_wdt_probe(struct platform_device *pdev) struct watchdog_device *ls1x_wdt; unsigned long clk_rate; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; platform_set_drvdata(pdev, drvdata); diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c index 633119e4b126d8..fc0fe30a8aa7d3 100644 --- a/drivers/watchdog/lpc18xx_wdt.c +++ b/drivers/watchdog/lpc18xx_wdt.c @@ -204,7 +204,7 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev) struct lpc18xx_wdt_dev *lpc18xx_wdt; struct device *dev = &pdev->dev; - lpc18xx_wdt = devm_kzalloc(dev, sizeof(*lpc18xx_wdt), GFP_KERNEL); + lpc18xx_wdt = devm_kzalloc_obj(dev, *lpc18xx_wdt); if (!lpc18xx_wdt) return -ENOMEM; diff --git a/drivers/watchdog/ma35d1_wdt.c b/drivers/watchdog/ma35d1_wdt.c index ede4bee594f1f3..0ca3436be1ccbd 100644 --- a/drivers/watchdog/ma35d1_wdt.c +++ b/drivers/watchdog/ma35d1_wdt.c @@ -197,7 +197,7 @@ static int ma35d1_wdt_probe(struct platform_device *pdev) unsigned long clk_rate, val; int ret; - ma35d1_wdt = devm_kzalloc(dev, sizeof(*ma35d1_wdt), GFP_KERNEL); + ma35d1_wdt = devm_kzalloc_obj(dev, *ma35d1_wdt); if (!ma35d1_wdt) return -ENOMEM; diff --git a/drivers/watchdog/marvell_gti_wdt.c b/drivers/watchdog/marvell_gti_wdt.c index 31167034963c1c..03aae675a3d1ec 100644 --- a/drivers/watchdog/marvell_gti_wdt.c +++ b/drivers/watchdog/marvell_gti_wdt.c @@ -255,7 +255,7 @@ static int gti_wdt_probe(struct platform_device *pdev) int irq; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/max63xx_wdt.c b/drivers/watchdog/max63xx_wdt.c index 17b19dfdad16f0..9e46b86b9b20cf 100644 --- a/drivers/watchdog/max63xx_wdt.c +++ b/drivers/watchdog/max63xx_wdt.c @@ -203,7 +203,7 @@ static int max63xx_wdt_probe(struct platform_device *pdev) const struct max63xx_timeout *table; int err; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/max77620_wdt.c b/drivers/watchdog/max77620_wdt.c index 79148cbad4f26b..4fc8a858d221c6 100644 --- a/drivers/watchdog/max77620_wdt.c +++ b/drivers/watchdog/max77620_wdt.c @@ -163,7 +163,7 @@ static int max77620_wdt_probe(struct platform_device *pdev) unsigned int regval; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c index a762462c25c543..775c27ef16ac2a 100644 --- a/drivers/watchdog/mena21_wdt.c +++ b/drivers/watchdog/mena21_wdt.c @@ -135,7 +135,7 @@ static int a21_wdt_probe(struct platform_device *pdev) int ret; int i; - drv = devm_kzalloc(dev, sizeof(struct a21_wdt_drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, struct a21_wdt_drv); if (!drv) return -ENOMEM; diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c index bb8eda18fbad6b..1aa7492abc9080 100644 --- a/drivers/watchdog/menf21bmc_wdt.c +++ b/drivers/watchdog/menf21bmc_wdt.c @@ -119,7 +119,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev) struct menf21bmc_wdt *drv_data; struct i2c_client *i2c_client = to_i2c_client(dev->parent); - drv_data = devm_kzalloc(dev, sizeof(struct menf21bmc_wdt), GFP_KERNEL); + drv_data = devm_kzalloc_obj(dev, struct menf21bmc_wdt); if (!drv_data) return -ENOMEM; diff --git a/drivers/watchdog/menz69_wdt.c b/drivers/watchdog/menz69_wdt.c index 962c6867bc0734..61434604f90255 100644 --- a/drivers/watchdog/menz69_wdt.c +++ b/drivers/watchdog/menz69_wdt.c @@ -105,7 +105,7 @@ static int men_z069_probe(struct mcb_device *dev, struct men_z069_drv *drv; struct resource *mem; - drv = devm_kzalloc(&dev->dev, sizeof(struct men_z069_drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&dev->dev, struct men_z069_drv); if (!drv) return -ENOMEM; diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c index fb276060e8314e..a88fe8cbeef57c 100644 --- a/drivers/watchdog/meson_gxbb_wdt.c +++ b/drivers/watchdog/meson_gxbb_wdt.c @@ -124,7 +124,8 @@ static int __maybe_unused meson_gxbb_wdt_resume(struct device *dev) { struct meson_gxbb_wdt *data = dev_get_drvdata(dev); - if (watchdog_active(&data->wdt_dev)) + if (watchdog_active(&data->wdt_dev) || + watchdog_hw_running(&data->wdt_dev)) meson_gxbb_wdt_start(&data->wdt_dev); return 0; @@ -134,7 +135,8 @@ static int __maybe_unused meson_gxbb_wdt_suspend(struct device *dev) { struct meson_gxbb_wdt *data = dev_get_drvdata(dev); - if (watchdog_active(&data->wdt_dev)) + if (watchdog_active(&data->wdt_dev) || + watchdog_hw_running(&data->wdt_dev)) meson_gxbb_wdt_stop(&data->wdt_dev); return 0; @@ -166,7 +168,7 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev) struct wdt_params *params; u32 ctrl_reg; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c index 80a4f877133596..b9ad8c0c63ab83 100644 --- a/drivers/watchdog/meson_wdt.c +++ b/drivers/watchdog/meson_wdt.c @@ -164,7 +164,7 @@ static int meson_wdt_probe(struct platform_device *pdev) struct meson_wdt_dev *meson_wdt; int err; - meson_wdt = devm_kzalloc(dev, sizeof(*meson_wdt), GFP_KERNEL); + meson_wdt = devm_kzalloc_obj(dev, *meson_wdt); if (!meson_wdt) return -ENOMEM; diff --git a/drivers/watchdog/mlx_wdt.c b/drivers/watchdog/mlx_wdt.c index 5dc69363f06ae0..04b66a4b0fdb28 100644 --- a/drivers/watchdog/mlx_wdt.c +++ b/drivers/watchdog/mlx_wdt.c @@ -287,7 +287,7 @@ static int mlxreg_wdt_probe(struct platform_device *pdev) dev_err(dev, "Failed to get platform data.\n"); return -EINVAL; } - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/moxart_wdt.c b/drivers/watchdog/moxart_wdt.c index 1b68a1917003fe..3b2682ac1c4dda 100644 --- a/drivers/watchdog/moxart_wdt.c +++ b/drivers/watchdog/moxart_wdt.c @@ -93,7 +93,7 @@ static int moxart_wdt_probe(struct platform_device *pdev) unsigned int max_timeout; bool nowayout = WATCHDOG_NOWAYOUT; - moxart_wdt = devm_kzalloc(dev, sizeof(*moxart_wdt), GFP_KERNEL); + moxart_wdt = devm_kzalloc_obj(dev, *moxart_wdt); if (!moxart_wdt) return -ENOMEM; diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c index 0d5a360b56292b..96faa525cd5331 100644 --- a/drivers/watchdog/mpc8xxx_wdt.c +++ b/drivers/watchdog/mpc8xxx_wdt.c @@ -144,7 +144,7 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev) if (!freq || freq == -1) return -EINVAL; - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); + ddata = devm_kzalloc_obj(dev, *ddata); if (!ddata) return -ENOMEM; diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c index 0a68be7a217b6d..a88825a1703467 100644 --- a/drivers/watchdog/msc313e_wdt.c +++ b/drivers/watchdog/msc313e_wdt.c @@ -126,7 +126,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev) unsigned long rate; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c index 9e0ebec43c8887..212cea97e243b4 100644 --- a/drivers/watchdog/mt7621_wdt.c +++ b/drivers/watchdog/mt7621_wdt.c @@ -144,7 +144,7 @@ static int mt7621_wdt_probe(struct platform_device *pdev) struct mt7621_wdt_data *drvdata; int err; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c index 1630ab65d59329..f8602d61a08406 100644 --- a/drivers/watchdog/mtk_wdt.c +++ b/drivers/watchdog/mtk_wdt.c @@ -494,7 +494,7 @@ static int mtk_wdt_probe(struct platform_device *pdev) const struct mtk_wdt_data *wdt_data; int err, irq; - mtk_wdt = devm_kzalloc(dev, sizeof(*mtk_wdt), GFP_KERNEL); + mtk_wdt = devm_kzalloc_obj(dev, *mtk_wdt); if (!mtk_wdt) return -ENOMEM; @@ -540,6 +540,18 @@ static int mtk_wdt_probe(struct platform_device *pdev) mtk_wdt->reset_by_toprgu = of_property_read_bool(dev->of_node, "mediatek,reset-by-toprgu"); + wdt_data = of_device_get_match_data(dev); + if (wdt_data) { + mtk_wdt->toprgu_sw_rst_num = wdt_data->toprgu_sw_rst_num; + mtk_wdt->toprgu_sw_rst_tb = wdt_data->toprgu_sw_rst_tb; + mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en; + + err = toprgu_register_reset_controller(pdev, + wdt_data->toprgu_sw_rst_num); + if (err) + return err; + } + mtk_wdt_init(&mtk_wdt->wdt_dev); watchdog_stop_on_reboot(&mtk_wdt->wdt_dev); @@ -553,18 +565,6 @@ static int mtk_wdt_probe(struct platform_device *pdev) dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)\n", mtk_wdt->wdt_dev.timeout, nowayout); - wdt_data = of_device_get_match_data(dev); - if (wdt_data) { - mtk_wdt->toprgu_sw_rst_num = wdt_data->toprgu_sw_rst_num; - mtk_wdt->toprgu_sw_rst_tb = wdt_data->toprgu_sw_rst_tb; - mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en; - - err = toprgu_register_reset_controller(pdev, - wdt_data->toprgu_sw_rst_num); - if (err) - return err; - } - return 0; } @@ -572,7 +572,8 @@ static int mtk_wdt_suspend(struct device *dev) { struct mtk_wdt_dev *mtk_wdt = dev_get_drvdata(dev); - if (watchdog_active(&mtk_wdt->wdt_dev)) + if (watchdog_active(&mtk_wdt->wdt_dev) || + watchdog_hw_running(&mtk_wdt->wdt_dev)) mtk_wdt_stop(&mtk_wdt->wdt_dev); return 0; @@ -582,7 +583,8 @@ static int mtk_wdt_resume(struct device *dev) { struct mtk_wdt_dev *mtk_wdt = dev_get_drvdata(dev); - if (watchdog_active(&mtk_wdt->wdt_dev)) { + if (watchdog_active(&mtk_wdt->wdt_dev) || + watchdog_hw_running(&mtk_wdt->wdt_dev)) { mtk_wdt_start(&mtk_wdt->wdt_dev); mtk_wdt_ping(&mtk_wdt->wdt_dev); } diff --git a/drivers/watchdog/nct6694_wdt.c b/drivers/watchdog/nct6694_wdt.c index 169a6736e9ea0e..57bcc129997383 100644 --- a/drivers/watchdog/nct6694_wdt.c +++ b/drivers/watchdog/nct6694_wdt.c @@ -250,12 +250,11 @@ static int nct6694_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdev; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; - data->msg = devm_kzalloc(dev, sizeof(union nct6694_wdt_msg), - GFP_KERNEL); + data->msg = devm_kzalloc_obj(dev, union nct6694_wdt_msg); if (!data->msg) return -ENOMEM; diff --git a/drivers/watchdog/ni903x_wdt.c b/drivers/watchdog/ni903x_wdt.c index 68b7c485726b23..5dfa51dc38870c 100644 --- a/drivers/watchdog/ni903x_wdt.c +++ b/drivers/watchdog/ni903x_wdt.c @@ -192,7 +192,7 @@ static int ni903x_acpi_probe(struct platform_device *pdev) if (!handle) return -ENODEV; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/nic7018_wdt.c b/drivers/watchdog/nic7018_wdt.c index 2b122ba8733a5a..eef5d178c0a9c8 100644 --- a/drivers/watchdog/nic7018_wdt.c +++ b/drivers/watchdog/nic7018_wdt.c @@ -174,7 +174,7 @@ static int nic7018_probe(struct platform_device *pdev) struct resource *io_rc; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c index 51348969bf4925..07ea810fb8c90e 100644 --- a/drivers/watchdog/npcm_wdt.c +++ b/drivers/watchdog/npcm_wdt.c @@ -145,13 +145,11 @@ static int npcm_wdt_ping(struct watchdog_device *wdd) return 0; } -static int npcm_wdt_start(struct watchdog_device *wdd) +static void __npcm_wdt_start(struct watchdog_device *wdd) { struct npcm_wdt *wdt = to_npcm_wdt(wdd); u32 val; - clk_prepare_enable(wdt->clk); - if (wdd->timeout < 2) val = 0x800; else if (wdd->timeout < 3) @@ -176,6 +174,15 @@ static int npcm_wdt_start(struct watchdog_device *wdd) val |= NPCM_WTRE | NPCM_WTE | NPCM_WTR | NPCM_WTIE; writel(val, wdt->reg); +} + +static int npcm_wdt_start(struct watchdog_device *wdd) +{ + struct npcm_wdt *wdt = to_npcm_wdt(wdd); + + clk_prepare_enable(wdt->clk); + + __npcm_wdt_start(wdd); return 0; } @@ -216,7 +223,7 @@ static int npcm_wdt_set_timeout(struct watchdog_device *wdd, wdd->timeout = 2750; if (watchdog_active(wdd)) - npcm_wdt_start(wdd); + __npcm_wdt_start(wdd); return 0; } @@ -396,7 +403,7 @@ static int npcm_wdt_probe(struct platform_device *pdev) int irq; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c index d6b1adfe31d11a..d89f5593369e66 100644 --- a/drivers/watchdog/of_xilinx_wdt.c +++ b/drivers/watchdog/of_xilinx_wdt.c @@ -161,7 +161,7 @@ static int xwdt_probe(struct platform_device *pdev) struct xwdt_device *xdev; struct watchdog_device *xilinx_wdt_wdd; - xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c index 2a6de73e6f0b36..c60bc678262c32 100644 --- a/drivers/watchdog/omap_wdt.c +++ b/drivers/watchdog/omap_wdt.c @@ -232,7 +232,7 @@ static int omap_wdt_probe(struct platform_device *pdev) struct omap_wdt_dev *wdev; int ret; - wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); + wdev = devm_kzalloc_obj(&pdev->dev, *wdev); if (!wdev) return -ENOMEM; @@ -277,6 +277,8 @@ static int omap_wdt_probe(struct platform_device *pdev) ret = watchdog_register_device(&wdev->wdog); if (ret) { + if (wdev->omap_wdt_users) + omap_wdt_stop(&wdev->wdog); pm_runtime_put(wdev->dev); pm_runtime_disable(wdev->dev); return ret; @@ -286,9 +288,6 @@ static int omap_wdt_probe(struct platform_device *pdev) readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, wdev->wdog.timeout); - if (early_enable) - omap_wdt_start(&wdev->wdog); - pm_runtime_put(wdev->dev); return 0; diff --git a/drivers/watchdog/orion_wdt.c b/drivers/watchdog/orion_wdt.c index 5d56e93f040646..83a24f58011ea0 100644 --- a/drivers/watchdog/orion_wdt.c +++ b/drivers/watchdog/orion_wdt.c @@ -232,6 +232,9 @@ static int armada370_start(struct watchdog_device *wdt_dev) /* Set watchdog duration */ writel(dev->clk_rate * wdt_dev->timeout, dev->reg + dev->data->wdt_counter_offset); + if (dev->wdt.info->options & WDIOF_PRETIMEOUT) + writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout), + dev->reg + TIMER1_VAL_OFF); /* Clear the watchdog expiration bit */ atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0); @@ -559,8 +562,7 @@ static int orion_wdt_probe(struct platform_device *pdev) unsigned int wdt_max_duration; /* (seconds) */ int ret, irq; - dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog), - GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, struct orion_watchdog); if (!dev) return -ENOMEM; diff --git a/drivers/watchdog/pic32-dmt.c b/drivers/watchdog/pic32-dmt.c index 12e3a8f6358986..8688b7bf5e3e83 100644 --- a/drivers/watchdog/pic32-dmt.c +++ b/drivers/watchdog/pic32-dmt.c @@ -169,7 +169,7 @@ static int pic32_dmt_probe(struct platform_device *pdev) struct pic32_dmt *dmt; struct watchdog_device *wdd = &pic32_dmt_wdd; - dmt = devm_kzalloc(dev, sizeof(*dmt), GFP_KERNEL); + dmt = devm_kzalloc_obj(dev, *dmt); if (!dmt) return -ENOMEM; diff --git a/drivers/watchdog/pic32-wdt.c b/drivers/watchdog/pic32-wdt.c index 2e7186b8519464..caa641014ed07e 100644 --- a/drivers/watchdog/pic32-wdt.c +++ b/drivers/watchdog/pic32-wdt.c @@ -167,7 +167,7 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev) struct watchdog_device *wdd = &pic32_wdd; struct pic32_wdt *wdt; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/pm8916_wdt.c b/drivers/watchdog/pm8916_wdt.c index a7ae57fb24532a..16778c67d4292e 100644 --- a/drivers/watchdog/pm8916_wdt.c +++ b/drivers/watchdog/pm8916_wdt.c @@ -146,7 +146,7 @@ static int pm8916_wdt_probe(struct platform_device *pdev) int err, irq; u8 poff[2]; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/pseries-wdt.c b/drivers/watchdog/pseries-wdt.c index 5f531a03a0fc6f..4f8325b5021a50 100644 --- a/drivers/watchdog/pseries-wdt.c +++ b/drivers/watchdog/pseries-wdt.c @@ -106,7 +106,7 @@ static int pseries_wdt_probe(struct platform_device *pdev) return -EIO; cap = ret[0]; - pw = devm_kzalloc(&pdev->dev, sizeof(*pw), GFP_KERNEL); + pw = devm_kzalloc_obj(&pdev->dev, *pw); if (!pw) return -ENOMEM; diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c index 4eb1bf9790125b..289e79d8943e84 100644 --- a/drivers/watchdog/qcom-wdt.c +++ b/drivers/watchdog/qcom-wdt.c @@ -263,7 +263,7 @@ static int qcom_wdt_probe(struct platform_device *pdev) return -ENODEV; } - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/rave-sp-wdt.c b/drivers/watchdog/rave-sp-wdt.c index 5d1c2176d445d7..f06926460cbc47 100644 --- a/drivers/watchdog/rave-sp-wdt.c +++ b/drivers/watchdog/rave-sp-wdt.c @@ -259,7 +259,7 @@ static int rave_sp_wdt_probe(struct platform_device *pdev) __le16 timeout = 0; int ret; - sp_wd = devm_kzalloc(dev, sizeof(*sp_wd), GFP_KERNEL); + sp_wd = devm_kzalloc_obj(dev, *sp_wd); if (!sp_wd) return -ENOMEM; diff --git a/drivers/watchdog/realtek_otto_wdt.c b/drivers/watchdog/realtek_otto_wdt.c index 35d34834ce0469..462e8d0f43680e 100644 --- a/drivers/watchdog/realtek_otto_wdt.c +++ b/drivers/watchdog/realtek_otto_wdt.c @@ -281,7 +281,7 @@ static int otto_wdt_probe(struct platform_device *pdev) void __iomem *base; int ret; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c index 8c0041ce555214..d9760f2a3b2356 100644 --- a/drivers/watchdog/renesas_wdt.c +++ b/drivers/watchdog/renesas_wdt.c @@ -221,7 +221,7 @@ static int rwdt_probe(struct platform_device *pdev) if (rwdt_blacklisted(dev)) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/renesas_wwdt.c b/drivers/watchdog/renesas_wwdt.c index b250913c349ac9..6204300e778538 100644 --- a/drivers/watchdog/renesas_wwdt.c +++ b/drivers/watchdog/renesas_wwdt.c @@ -80,7 +80,7 @@ static int wwdt_probe(struct platform_device *pdev) int ret; u8 val; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/retu_wdt.c b/drivers/watchdog/retu_wdt.c index 2b9017e1cd91f8..ea682e0abadc07 100644 --- a/drivers/watchdog/retu_wdt.c +++ b/drivers/watchdog/retu_wdt.c @@ -107,11 +107,11 @@ static int retu_wdt_probe(struct platform_device *pdev) struct retu_wdt_dev *wdev; int ret; - retu_wdt = devm_kzalloc(&pdev->dev, sizeof(*retu_wdt), GFP_KERNEL); + retu_wdt = devm_kzalloc_obj(&pdev->dev, *retu_wdt); if (!retu_wdt) return -ENOMEM; - wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); + wdev = devm_kzalloc_obj(&pdev->dev, *wdev); if (!wdev) return -ENOMEM; diff --git a/drivers/watchdog/riowd.c b/drivers/watchdog/riowd.c index 83806ccf06d1a7..153a7b3f104ab8 100644 --- a/drivers/watchdog/riowd.c +++ b/drivers/watchdog/riowd.c @@ -182,7 +182,7 @@ static int riowd_probe(struct platform_device *op) goto out; err = -ENOMEM; - p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL); + p = devm_kzalloc_obj(&op->dev, *p); if (!p) goto out; diff --git a/drivers/watchdog/rn5t618_wdt.c b/drivers/watchdog/rn5t618_wdt.c index 14056af36445cc..a0dcbf185c421a 100644 --- a/drivers/watchdog/rn5t618_wdt.c +++ b/drivers/watchdog/rn5t618_wdt.c @@ -148,7 +148,7 @@ static int rn5t618_wdt_probe(struct platform_device *pdev) int ret; unsigned int val; - wdt = devm_kzalloc(dev, sizeof(struct rn5t618_wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, struct rn5t618_wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/rt2880_wdt.c b/drivers/watchdog/rt2880_wdt.c index 38f31d302a4b36..4e3c22480646fa 100644 --- a/drivers/watchdog/rt2880_wdt.c +++ b/drivers/watchdog/rt2880_wdt.c @@ -144,7 +144,7 @@ static int rt288x_wdt_probe(struct platform_device *pdev) struct rt2880_wdt_data *drvdata; int ret; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return -ENOMEM; diff --git a/drivers/watchdog/rtd119x_wdt.c b/drivers/watchdog/rtd119x_wdt.c index 0bfadb58917b9d..4e0fd7d6f2a34b 100644 --- a/drivers/watchdog/rtd119x_wdt.c +++ b/drivers/watchdog/rtd119x_wdt.c @@ -100,7 +100,7 @@ static int rtd119x_wdt_probe(struct platform_device *pdev) struct rtd119x_watchdog_device *data; unsigned long rate; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c index 6a64adbe1a8eac..135367dbfd4b92 100644 --- a/drivers/watchdog/rti_wdt.c +++ b/drivers/watchdog/rti_wdt.c @@ -233,7 +233,7 @@ static int rti_wdt_probe(struct platform_device *pdev) u32 *vaddr; u64 paddr; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/rza_wdt.c b/drivers/watchdog/rza_wdt.c index 9334255a37e933..a0cfd3b39c2e51 100644 --- a/drivers/watchdog/rza_wdt.c +++ b/drivers/watchdog/rza_wdt.c @@ -170,7 +170,7 @@ static int rza_wdt_probe(struct platform_device *pdev) struct rza_wdt *priv; unsigned long rate; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 592ea7ce6d69a7..c224aee875022f 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -254,7 +254,7 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) unsigned long pclk_rate; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/rzn1_wdt.c b/drivers/watchdog/rzn1_wdt.c index 4fdc5363ba98fb..6cab6986280580 100644 --- a/drivers/watchdog/rzn1_wdt.c +++ b/drivers/watchdog/rzn1_wdt.c @@ -98,7 +98,7 @@ static int rzn1_wdt_probe(struct platform_device *pdev) struct clk *clk; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c index a8db85e85c73a6..c1c01ee7432c22 100644 --- a/drivers/watchdog/rzv2h_wdt.c +++ b/drivers/watchdog/rzv2h_wdt.c @@ -175,7 +175,7 @@ static int rzv2h_wdt_stop(struct watchdog_device *wdev) if (priv->of_data->wdtdcr) rzt2h_wdt_wdtdcr_count_stop(priv); - pm_runtime_put(wdev->parent); + pm_runtime_put_sync(wdev->parent); return 0; } @@ -257,20 +257,12 @@ static const struct watchdog_ops rzv2h_wdt_ops = { static int rzt2h_wdt_wdtdcr_init(struct platform_device *pdev, struct rzv2h_wdt_priv *priv) { - int ret; - priv->wdtdcr = devm_platform_ioremap_resource(pdev, 1); if (IS_ERR(priv->wdtdcr)) return PTR_ERR(priv->wdtdcr); - ret = pm_runtime_resume_and_get(&pdev->dev); - if (ret) - return ret; - rzt2h_wdt_wdtdcr_count_stop(priv); - pm_runtime_put(&pdev->dev); - return 0; } @@ -282,7 +274,7 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) unsigned long rate; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/s32g_wdt.c b/drivers/watchdog/s32g_wdt.c index bd8740153c17f4..8f491de71d5d23 100644 --- a/drivers/watchdog/s32g_wdt.c +++ b/drivers/watchdog/s32g_wdt.c @@ -220,7 +220,7 @@ static int s32g_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdog; int ret; - wdev = devm_kzalloc(dev, sizeof(*wdev), GFP_KERNEL); + wdev = devm_kzalloc_obj(dev, *wdev); if (!wdev) return -ENOMEM; diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c index 7053963fb0ac63..d11cf2382bd942 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -773,7 +773,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev) int wdt_irq; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c index 85efe4db40f0b5..5d6a2d5512b3ce 100644 --- a/drivers/watchdog/sama5d4_wdt.c +++ b/drivers/watchdog/sama5d4_wdt.c @@ -249,7 +249,7 @@ static int sama5d4_wdt_probe(struct platform_device *pdev) u32 reg; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c index 3a5ff48a58f20e..537c48b883b30c 100644 --- a/drivers/watchdog/sbsa_gwdt.c +++ b/drivers/watchdog/sbsa_gwdt.c @@ -72,12 +72,16 @@ #define SBSA_GWDT_WCS_WS0 BIT(1) #define SBSA_GWDT_WCS_WS1 BIT(2) -#define SBSA_GWDT_VERSION_MASK GENMASK(3, 0) -#define SBSA_GWDT_VERSION_SHIFT 16 +#define SBSA_GWDT_VERSION_MASK GENMASK(3, 0) +#define SBSA_GWDT_VERSION_SHIFT 16 -#define SBSA_GWDT_IMPL_MASK GENMASK(11, 0) -#define SBSA_GWDT_IMPL_SHIFT 0 -#define SBSA_GWDT_IMPL_MEDIATEK 0x426 +#define SBSA_GWDT_REVISION_MASK GENMASK(3, 0) +#define SBSA_GWDT_REVISION_SHIFT 12 +#define SBSA_GWDT_REV_RACE_WA 0x0 + +#define SBSA_GWDT_IMPL_MASK GENMASK(11, 0) +#define SBSA_GWDT_IMPL_SHIFT 0 +#define SBSA_GWDT_IMPL_MEDIATEK 0x426 /** * struct sbsa_gwdt - Internal representation of the SBSA GWDT @@ -239,15 +243,17 @@ static int sbsa_gwdt_keepalive(struct watchdog_device *wdd) static void sbsa_gwdt_get_version(struct watchdog_device *wdd) { struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd); - int iidr, ver, impl; + int iidr, ver, rev, impl; iidr = readl(gwdt->control_base + SBSA_GWDT_W_IIDR); ver = (iidr >> SBSA_GWDT_VERSION_SHIFT) & SBSA_GWDT_VERSION_MASK; + rev = (iidr >> SBSA_GWDT_REVISION_SHIFT) & SBSA_GWDT_REVISION_MASK; impl = (iidr >> SBSA_GWDT_IMPL_SHIFT) & SBSA_GWDT_IMPL_MASK; gwdt->version = ver; gwdt->need_ws0_race_workaround = - !action && (impl == SBSA_GWDT_IMPL_MEDIATEK); + !action && (impl == SBSA_GWDT_IMPL_MEDIATEK) && + (rev == SBSA_GWDT_REV_RACE_WA); } static int sbsa_gwdt_start(struct watchdog_device *wdd) @@ -304,7 +310,7 @@ static int sbsa_gwdt_probe(struct platform_device *pdev) u32 status; bool early_action; - gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL); + gwdt = devm_kzalloc_obj(dev, *gwdt); if (!gwdt) return -ENOMEM; platform_set_drvdata(pdev, gwdt); diff --git a/drivers/watchdog/sc1200wdt.c b/drivers/watchdog/sc1200wdt.c index 34cd57420c86d8..12af8c736d0f6a 100644 --- a/drivers/watchdog/sc1200wdt.c +++ b/drivers/watchdog/sc1200wdt.c @@ -343,6 +343,7 @@ static const struct pnp_device_id scl200wdt_pnp_devices[] = { { .id = "NSC0800" }, { } }; +MODULE_DEVICE_TABLE(pnp, scl200wdt_pnp_devices); static int scl200wdt_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) diff --git a/drivers/watchdog/shwdt.c b/drivers/watchdog/shwdt.c index 8adecf54b9bc84..cb04b948063c53 100644 --- a/drivers/watchdog/shwdt.c +++ b/drivers/watchdog/shwdt.c @@ -226,7 +226,7 @@ static int sh_wdt_probe(struct platform_device *pdev) if (pdev->id != -1) return -EINVAL; - wdt = devm_kzalloc(&pdev->dev, sizeof(struct sh_wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&pdev->dev, struct sh_wdt); if (unlikely(!wdt)) return -ENOMEM; diff --git a/drivers/watchdog/sl28cpld_wdt.c b/drivers/watchdog/sl28cpld_wdt.c index e32b757372eb64..ce8d942a84592f 100644 --- a/drivers/watchdog/sl28cpld_wdt.c +++ b/drivers/watchdog/sl28cpld_wdt.c @@ -128,7 +128,7 @@ static int sl28cpld_wdt_probe(struct platform_device *pdev) if (!pdev->dev.parent) return -ENODEV; - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&pdev->dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index 14d4bffface41e..96ff3c5d116e37 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -407,16 +407,13 @@ static int sp5100_tco_setupdevice_mmio(struct device *dev, struct sp5100_tco *tco = watchdog_get_drvdata(wdd); const char *dev_name = SB800_DEVNAME; u32 mmio_addr = 0, alt_mmio_addr = 0; - struct resource *res; void __iomem *addr; int ret; u32 val; - res = request_mem_region_muxed(EFCH_PM_ACPI_MMIO_PM_ADDR, - EFCH_PM_ACPI_MMIO_PM_SIZE, - "sp5100_tco"); - - if (!res) { + if (!request_mem_region_muxed(EFCH_PM_ACPI_MMIO_PM_ADDR, + EFCH_PM_ACPI_MMIO_PM_SIZE, + "sp5100_tco")) { dev_err(dev, "Memory region 0x%08x already in use\n", EFCH_PM_ACPI_MMIO_PM_ADDR); @@ -467,8 +464,8 @@ static int sp5100_tco_setupdevice_mmio(struct device *dev, if (addr) iounmap(addr); - release_resource(res); - kfree(res); + release_mem_region(EFCH_PM_ACPI_MMIO_PM_ADDR, + EFCH_PM_ACPI_MMIO_PM_SIZE); return ret; } @@ -575,7 +572,7 @@ static int sp5100_tco_probe(struct platform_device *pdev) struct sp5100_tco *tco; int ret; - tco = devm_kzalloc(dev, sizeof(*tco), GFP_KERNEL); + tco = devm_kzalloc_obj(dev, *tco); if (!tco) return -ENOMEM; diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c index 925f1215718137..a14ff7ac0db486 100644 --- a/drivers/watchdog/sp805_wdt.c +++ b/drivers/watchdog/sp805_wdt.c @@ -236,7 +236,7 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id) u64 rate = 0; int ret = 0; - wdt = devm_kzalloc(&adev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&adev->dev, *wdt); if (!wdt) { ret = -ENOMEM; goto err; diff --git a/drivers/watchdog/sprd_wdt.c b/drivers/watchdog/sprd_wdt.c index 616b4d7f21d787..913900bd05f5f7 100644 --- a/drivers/watchdog/sprd_wdt.c +++ b/drivers/watchdog/sprd_wdt.c @@ -267,7 +267,7 @@ static int sprd_wdt_probe(struct platform_device *pdev) struct sprd_wdt *wdt; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/st_lpc_wdt.c b/drivers/watchdog/st_lpc_wdt.c index d206452072ae2e..6d13a9c6755093 100644 --- a/drivers/watchdog/st_lpc_wdt.c +++ b/drivers/watchdog/st_lpc_wdt.c @@ -167,7 +167,7 @@ static int st_wdog_probe(struct platform_device *pdev) if (mode != ST_LPC_MODE_WDT) return -ENODEV; - st_wdog = devm_kzalloc(dev, sizeof(*st_wdog), GFP_KERNEL); + st_wdog = devm_kzalloc_obj(dev, *st_wdog); if (!st_wdog) return -ENOMEM; diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c index 044b4fdb73505b..60d93e651b01f0 100644 --- a/drivers/watchdog/starfive-wdt.c +++ b/drivers/watchdog/starfive-wdt.c @@ -431,7 +431,7 @@ static int starfive_wdt_probe(struct platform_device *pdev) struct starfive_wdt *wdt; int ret; - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(&pdev->dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c index a8d2db2d3cf8be..8a6f0b78a2b0a6 100644 --- a/drivers/watchdog/stm32_iwdg.c +++ b/drivers/watchdog/stm32_iwdg.c @@ -319,7 +319,7 @@ static int stm32_iwdg_probe(struct platform_device *pdev) struct stm32_iwdg *wdt; int ret; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c index 17f0cdecd22c3c..d68cac4befa823 100644 --- a/drivers/watchdog/stpmic1_wdt.c +++ b/drivers/watchdog/stpmic1_wdt.c @@ -94,7 +94,7 @@ static int pmic_wdt_probe(struct platform_device *pdev) if (!pmic) return -EINVAL; - wdt = devm_kzalloc(dev, sizeof(struct stpmic1_wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, struct stpmic1_wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/sunplus_wdt.c b/drivers/watchdog/sunplus_wdt.c index f2e45907d882c4..158a0c4a258ea3 100644 --- a/drivers/watchdog/sunplus_wdt.c +++ b/drivers/watchdog/sunplus_wdt.c @@ -147,7 +147,7 @@ static int sp_wdt_probe(struct platform_device *pdev) struct sp_wdt_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c index 1e55c5fd43b8a9..a6500ebf24badd 100644 --- a/drivers/watchdog/sunxi_wdt.c +++ b/drivers/watchdog/sunxi_wdt.c @@ -295,7 +295,7 @@ static int sunxi_wdt_probe(struct platform_device *pdev) unsigned int running_timeout; int err; - sunxi_wdt = devm_kzalloc(dev, sizeof(*sunxi_wdt), GFP_KERNEL); + sunxi_wdt = devm_kzalloc_obj(dev, *sunxi_wdt); if (!sunxi_wdt) return -ENOMEM; diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c index 6b3f65c4d593b8..4bf673d94660b4 100644 --- a/drivers/watchdog/tegra_wdt.c +++ b/drivers/watchdog/tegra_wdt.c @@ -197,7 +197,7 @@ static int tegra_wdt_probe(struct platform_device *pdev) * Allocate our watchdog driver data, which has the * struct watchdog_device nested within it. */ - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/tqmx86_wdt.c b/drivers/watchdog/tqmx86_wdt.c index 1da45a3f8cf3f0..e285d8e1cc5dd1 100644 --- a/drivers/watchdog/tqmx86_wdt.c +++ b/drivers/watchdog/tqmx86_wdt.c @@ -76,7 +76,7 @@ static int tqmx86_wdt_probe(struct platform_device *pdev) struct resource *res; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/ts4800_wdt.c b/drivers/watchdog/ts4800_wdt.c index 1bfc8db323c6ae..6e5eccfc58e64c 100644 --- a/drivers/watchdog/ts4800_wdt.c +++ b/drivers/watchdog/ts4800_wdt.c @@ -129,7 +129,7 @@ static int ts4800_wdt_probe(struct platform_device *pdev) } /* allocate memory for watchdog struct */ - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) { of_node_put(syscon_np); return -ENOMEM; diff --git a/drivers/watchdog/ts72xx_wdt.c b/drivers/watchdog/ts72xx_wdt.c index ede46a442b946a..d6b2d61000ebcb 100644 --- a/drivers/watchdog/ts72xx_wdt.c +++ b/drivers/watchdog/ts72xx_wdt.c @@ -125,7 +125,7 @@ static int ts72xx_wdt_probe(struct platform_device *pdev) struct watchdog_device *wdd; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/twl4030_wdt.c b/drivers/watchdog/twl4030_wdt.c index d5e06dcf74d9a0..377ac2a55f7d77 100644 --- a/drivers/watchdog/twl4030_wdt.c +++ b/drivers/watchdog/twl4030_wdt.c @@ -61,7 +61,7 @@ static int twl4030_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct watchdog_device *wdt; - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); + wdt = devm_kzalloc_obj(dev, *wdt); if (!wdt) return -ENOMEM; diff --git a/drivers/watchdog/uniphier_wdt.c b/drivers/watchdog/uniphier_wdt.c index d09fb2acfdde3a..3155dc0cc8944c 100644 --- a/drivers/watchdog/uniphier_wdt.c +++ b/drivers/watchdog/uniphier_wdt.c @@ -188,7 +188,7 @@ static int uniphier_wdt_probe(struct platform_device *pdev) struct device_node *parent; int ret; - wdev = devm_kzalloc(dev, sizeof(*wdev), GFP_KERNEL); + wdev = devm_kzalloc_obj(dev, *wdev); if (!wdev) return -ENOMEM; diff --git a/drivers/watchdog/visconti_wdt.c b/drivers/watchdog/visconti_wdt.c index fc4f0d4d3d5542..3a3b5a5afce40a 100644 --- a/drivers/watchdog/visconti_wdt.c +++ b/drivers/watchdog/visconti_wdt.c @@ -121,7 +121,7 @@ static int visconti_wdt_probe(struct platform_device *pdev) struct clk *clk; unsigned long clk_freq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c index a418da46bda2c0..acf05cfb1bb629 100644 --- a/drivers/watchdog/wdat_wdt.c +++ b/drivers/watchdog/wdat_wdt.c @@ -351,14 +351,13 @@ static int wdat_wdt_probe(struct platform_device *pdev) if (ACPI_FAILURE(status)) return -ENODEV; - wdat = devm_kzalloc(dev, sizeof(*wdat), GFP_KERNEL); + wdat = devm_kzalloc_obj(dev, *wdat); if (!wdat) { ret = -ENOMEM; goto out_put_table; } - regs = devm_kcalloc(dev, pdev->num_resources, sizeof(*regs), - GFP_KERNEL); + regs = devm_kzalloc_objs(dev, *regs, pdev->num_resources); if (!regs) { ret = -ENOMEM; goto out_put_table; @@ -423,7 +422,7 @@ static int wdat_wdt_probe(struct platform_device *pdev) continue; } - instr = devm_kzalloc(dev, sizeof(*instr), GFP_KERNEL); + instr = devm_kzalloc_obj(dev, *instr); if (!instr) { ret = -ENOMEM; goto out_put_table; @@ -464,9 +463,7 @@ static int wdat_wdt_probe(struct platform_device *pdev) instructions = wdat->instructions[action]; if (!instructions) { - instructions = devm_kzalloc(dev, - sizeof(*instructions), - GFP_KERNEL); + instructions = devm_kzalloc_obj(dev, *instructions); if (!instructions) { ret = -ENOMEM; goto out_put_table; diff --git a/drivers/watchdog/wm831x_wdt.c b/drivers/watchdog/wm831x_wdt.c index 1aeb532dfebae7..7d9272ea9a653f 100644 --- a/drivers/watchdog/wm831x_wdt.c +++ b/drivers/watchdog/wm831x_wdt.c @@ -190,7 +190,7 @@ static int wm831x_wdt_probe(struct platform_device *pdev) if (reg & WM831X_WDOG_DEBUG) dev_warn(wm831x->dev, "Watchdog is paused\n"); - driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL); + driver_data = devm_kzalloc_obj(dev, *driver_data); if (!driver_data) return -ENOMEM; diff --git a/drivers/watchdog/xilinx_wwdt.c b/drivers/watchdog/xilinx_wwdt.c index b7cdf8140666f9..afdce49c08c305 100644 --- a/drivers/watchdog/xilinx_wwdt.c +++ b/drivers/watchdog/xilinx_wwdt.c @@ -144,7 +144,7 @@ static int xwwdt_probe(struct platform_device *pdev) u64 ms_count; int ret; - xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); + xdev = devm_kzalloc_obj(dev, *xdev); if (!xdev) return -ENOMEM; diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 10d4eaa8592a04..9166d15cc8c411 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -609,7 +609,7 @@ static int ziirave_wdt_probe(struct i2c_client *client) I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)) return -ENODEV; - w_priv = devm_kzalloc(&client->dev, sizeof(*w_priv), GFP_KERNEL); + w_priv = devm_kzalloc_obj(&client->dev, *w_priv); if (!w_priv) return -ENOMEM; diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c index 3218686be45b89..c0dffabbf1b39c 100644 --- a/drivers/xen/gntalloc.c +++ b/drivers/xen/gntalloc.c @@ -287,7 +287,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv, goto out; } - gref_ids = kcalloc(op.count, sizeof(gref_ids[0]), GFP_KERNEL); + gref_ids = kzalloc_objs(gref_ids[0], op.count); if (!gref_ids) { rc = -ENOMEM; goto out; diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index df1883aca850e2..80fc91dc88e819 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -611,7 +611,7 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev, gntdev_dmabuf->u.imp.sgt = sgt; - gfns = kcalloc(count, sizeof(*gfns), GFP_KERNEL); + gfns = kzalloc_objs(*gfns, count); if (!gfns) { ret = ERR_PTR(-ENOMEM); goto fail_unmap; @@ -738,7 +738,7 @@ long gntdev_ioctl_dmabuf_exp_from_refs(struct gntdev_priv *priv, if (unlikely(gntdev_test_page_count(op.count))) return -EINVAL; - refs = kcalloc(op.count, sizeof(*refs), GFP_KERNEL); + refs = kzalloc_objs(*refs, op.count); if (!refs) return -ENOMEM; diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 49957e3ab49d27..385ba47d093ba7 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -670,15 +670,19 @@ static long gntdev_ioctl_map_grant_ref(struct gntdev_priv *priv, mutex_lock(&priv->lock); gntdev_add_map(priv, map); op.index = map->index << PAGE_SHIFT; + mutex_unlock(&priv->lock); if (copy_to_user(u, &op, sizeof(op)) != 0) { - list_del(&map->next); + mutex_lock(&priv->lock); + map = gntdev_find_map_index(priv, op.index >> PAGE_SHIFT, + op.count); + if (map) + list_del(&map->next); mutex_unlock(&priv->lock); gntdev_put_map(priv, map); return -EFAULT; } - mutex_unlock(&priv->lock); return 0; } diff --git a/drivers/xen/grant-dma-iommu.c b/drivers/xen/grant-dma-iommu.c index 0965e2dd4edf53..bfab770bcdc87e 100644 --- a/drivers/xen/grant-dma-iommu.c +++ b/drivers/xen/grant-dma-iommu.c @@ -36,7 +36,7 @@ static int grant_dma_iommu_probe(struct platform_device *pdev) struct grant_dma_iommu_device *mmu; int ret; - mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL); + mmu = devm_kzalloc_obj(&pdev->dev, *mmu); if (!mmu) return -ENOMEM; diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index 2aa1a772a0ffc9..5fcafa4c344fc7 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -385,7 +385,7 @@ static void xen_grant_setup_dma_ops(struct device *dev, domid_t backend_domid) return; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) goto err; diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index f75b5cc71cfc5a..957500dd309a4a 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1063,6 +1064,9 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) size_t size; int i, ret; + if (WARN_ON(xen_pv_domain())) + return -EINVAL; + if (args->nr_pages < 0 || args->nr_pages > (INT_MAX >> PAGE_SHIFT)) return -ENOMEM; @@ -1090,11 +1094,27 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) xenmem_reservation_scrub_page(page); } - xenmem_reservation_va_mapping_reset(args->nr_pages, args->pages); - ret = xenmem_reservation_decrease(args->nr_pages, args->frames); if (ret != args->nr_pages) { pr_debug("Failed to decrease reservation for DMA buffer\n"); + if (ret >= 0) { + /* Free the part where decrease didn't work. */ + size_t done = ret << PAGE_SHIFT; + + if (args->coherent) + dma_free_coherent(args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + else + dma_free_wc(args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + + if (!ret) /* Nothing else to do? */ + return -EFAULT; + + args->nr_pages = ret; + } ret = -EFAULT; goto fail; } @@ -1120,6 +1140,9 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) size_t size; int i, ret; + if (WARN_ON(xen_pv_domain())) + return -EINVAL; + gnttab_pages_clear_private(args->nr_pages, args->pages); for (i = 0; i < args->nr_pages; i++) @@ -1128,14 +1151,16 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) ret = xenmem_reservation_increase(args->nr_pages, args->frames); if (ret != args->nr_pages) { pr_debug("Failed to increase reservation for DMA buffer\n"); - ret = -EFAULT; + /* Can only free what has been re-filled. */ + if (!ret) + return -ENOMEM; + if (ret > 0) + args->nr_pages = ret; + ret = -ENOMEM; } else { ret = 0; } - xenmem_reservation_va_mapping_update(args->nr_pages, args->pages, - args->frames); - size = args->nr_pages << PAGE_SHIFT; if (args->coherent) dma_free_coherent(args->dev, size, @@ -1360,12 +1385,21 @@ static void unmap_refs_callback(int result, int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item) { struct unmap_refs_callback_data data; + bool on_stack = object_is_on_stack(item); init_completion(&data.completion); item->data = &data; item->done = &unmap_refs_callback; - gnttab_unmap_refs_async(item); + /* blkback keeps @item, and so its retry work, on the stack. */ + if (on_stack) + INIT_DELAYED_WORK_ONSTACK(&item->gnttab_work, gnttab_unmap_work); + else + INIT_DELAYED_WORK(&item->gnttab_work, gnttab_unmap_work); + item->age = 0; + __gnttab_unmap_refs_async(item); wait_for_completion(&data.completion); + if (on_stack) + destroy_delayed_work_on_stack(&item->gnttab_work); return data.result; } @@ -1405,7 +1439,7 @@ static int gnttab_map_frames_v2(xen_pfn_t *frames, unsigned int nr_gframes) /* No need for kzalloc as it is initialized in following hypercall * GNTTABOP_get_status_frames. */ - sframes = kmalloc_array(nr_sframes, sizeof(*sframes), GFP_ATOMIC); + sframes = kmalloc_objs(*sframes, nr_sframes, GFP_ATOMIC); if (!sframes) return -ENOMEM; diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index f2438232518c2c..a12ac57274a692 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c @@ -95,6 +95,7 @@ static int platform_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { int i, ret; + int requested_bars = 0; long ioaddr; long mmio_addr, mmio_len; unsigned int max_nr_gframes; @@ -115,16 +116,18 @@ static int platform_pci_probe(struct pci_dev *pdev, if (mmio_addr == 0 || ioaddr == 0) { dev_err(&pdev->dev, "no resources found\n"); ret = -ENOENT; - goto pci_out; + goto out; } ret = pci_request_region(pdev, 1, DRV_NAME); if (ret < 0) - goto pci_out; + goto out; + requested_bars |= BIT(1); ret = pci_request_region(pdev, 0, DRV_NAME); if (ret < 0) - goto mem_out; + goto out; + requested_bars |= BIT(0); platform_mmio = mmio_addr; platform_mmiolen = mmio_len; @@ -165,11 +168,8 @@ static int platform_pci_probe(struct pci_dev *pdev, if (!xen_have_vector_callback) free_irq(pdev->irq, pdev); out: - pci_release_region(pdev, 0); -mem_out: - pci_release_region(pdev, 1); -pci_out: pci_disable_device(pdev); + pci_release_selected_regions(pdev, requested_bars); return ret; } diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 5e56fbc934478b..221b31611343ec 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -901,10 +901,25 @@ struct privcmd_kernel_irqfd { poll_table pt; }; +static bool irqfd_is_active(struct privcmd_kernel_irqfd *kirqfd) +{ + lockdep_assert_held(&irqfds_lock); + + return !list_empty(&kirqfd->list); +} + static void irqfd_deactivate(struct privcmd_kernel_irqfd *kirqfd) { lockdep_assert_held(&irqfds_lock); + /* + * Both the deassign ioctl and the eventfd wakeup path can reach + * this function. list_del_init() marks the irqfd inactive, so + * only the first caller may queue the shutdown work. + */ + if (!irqfd_is_active(kirqfd)) + return; + list_del_init(&kirqfd->list); queue_work(irqfd_cleanup_wq, &kirqfd->shutdown); } diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index ba62651a7f338b..d97c5eca5f3513 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -337,7 +337,7 @@ static struct sock_mapping *pvcalls_new_active_socket( ret = xenbus_map_ring_valloc(fedata->dev, &ref, 1, &page); if (ret < 0) - goto out; + goto out_map; map->ring = page; map->ring_order = map->ring->ring_order; /* first read the order, then map the data ring */ @@ -345,19 +345,19 @@ static struct sock_mapping *pvcalls_new_active_socket( if (map->ring_order > MAX_RING_ORDER) { pr_warn("%s frontend requested ring_order %u, which is > MAX (%u)\n", __func__, map->ring_order, MAX_RING_ORDER); - goto out; + goto out_unmap_ring; } ret = xenbus_map_ring_valloc(fedata->dev, map->ring->ref, (1 << map->ring_order), &page); if (ret < 0) - goto out; + goto out_unmap_ring; map->bytes = page; ret = bind_interdomain_evtchn_to_irqhandler_lateeoi( fedata->dev, evtchn, pvcalls_back_conn_event, 0, "pvcalls-backend", map); if (ret < 0) - goto out; + goto out_unmap_bytes; map->irq = ret; map->data.in = map->bytes; @@ -365,7 +365,7 @@ static struct sock_mapping *pvcalls_new_active_socket( map->ioworker.wq = alloc_ordered_workqueue("pvcalls_io", 0); if (!map->ioworker.wq) - goto out; + goto out_unbind; atomic_set(&map->io, 1); INIT_WORK(&map->ioworker.register_work, pvcalls_back_ioworker); @@ -381,11 +381,16 @@ static struct sock_mapping *pvcalls_new_active_socket( write_unlock_bh(&map->sock->sk->sk_callback_lock); return map; -out: - down(&fedata->socket_lock); - list_del(&map->list); - pvcalls_back_release_active(fedata->dev, fedata, map); - up(&fedata->socket_lock); + +out_unbind: + unbind_from_irqhandler(map->irq, map); +out_unmap_bytes: + xenbus_unmap_ring_vfree(fedata->dev, map->bytes); +out_unmap_ring: + xenbus_unmap_ring_vfree(fedata->dev, (void *)map->ring); +out_map: + sock_release(sock); + kfree(map); return NULL; } @@ -447,6 +452,7 @@ static int pvcalls_back_release_active(struct xenbus_device *dev, atomic_set(&map->release, 1); flush_work(&map->ioworker.register_work); + destroy_workqueue(map->ioworker.wq); xenbus_unmap_ring_vfree(dev, map->bytes); xenbus_unmap_ring_vfree(dev, (void *)map->ring); diff --git a/fs/9p/acl.h b/fs/9p/acl.h index 2d1b24abcd3f50..d123ab6133172d 100644 --- a/fs/9p/acl.h +++ b/fs/9p/acl.h @@ -51,4 +51,4 @@ static inline int v9fs_acl_mode(struct inode *dir, umode_t *modep, } #endif -#endif /* FS_9P_XATTR_H */ +#endif /* FS_9P_ACL_H */ diff --git a/fs/9p/cache.c b/fs/9p/cache.c index 12c0ae29f1857c..194a912158ac31 100644 --- a/fs/9p/cache.c +++ b/fs/9p/cache.c @@ -20,17 +20,14 @@ int v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses, const char *dev_name) { struct fscache_volume *vcookie; - char *name, *p; + char *name; name = kasprintf(GFP_KERNEL, "9p,%s,%s", dev_name, v9ses->cachetag ?: v9ses->aname); if (!name) return -ENOMEM; - for (p = name; *p; p++) - if (*p == '/') - *p = ';'; - + strreplace(name, '/', ';'); vcookie = fscache_acquire_volume(name, NULL, NULL, 0); p9_debug(P9_DEBUG_FSC, "session %p get volume %p (%s)\n", v9ses, vcookie, name); diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 76242d450aa7ca..b6a1ca93bd0ec2 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -154,7 +154,7 @@ static int build_path_from_dentry(struct v9fs_session_info *v9ses, for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent) n++; - wnames = kmalloc_array(n, sizeof(char *), GFP_KERNEL); + wnames = kmalloc_objs(*wnames, n); if (!wnames) goto err_out; diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 274c5157135da3..b30ca5145faefb 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -406,7 +407,7 @@ int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_privport: fd_opts->privport = true; - rdma_opts->port = true; + rdma_opts->privport = true; break; } @@ -617,21 +618,14 @@ static ssize_t caches_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - ssize_t n = 0, count = 0, limit = PAGE_SIZE; + ssize_t count = 0; struct v9fs_session_info *v9ses; spin_lock(&v9fs_sessionlist_lock); list_for_each_entry(v9ses, &v9fs_sessionlist, slist) { - if (v9ses->cachetag) { - n = snprintf(buf + count, limit, "%s\n", v9ses->cachetag); - if (n < 0) { - count = n; - break; - } - - count += n; - limit -= n; - } + if (v9ses->cachetag) + count += sysfs_emit_at(buf, count, "%s\n", + v9ses->cachetag); } spin_unlock(&v9fs_sessionlist_lock); diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index e26e9811875b90..7603d0960689c3 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -21,20 +21,16 @@ * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy * @V9FS_ACCESS_USER: a new attach will be issued for every user (default) * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client. - * @V9FS_ACCESS_ANY: use a single attach for all users - * @V9FS_ACCESS_MASK: bit mask of different ACCESS options * @V9FS_POSIX_ACL: POSIX ACLs are enforced + * @V9FS_NO_XATTR: do not offer xattr functions on this mount + * @V9FS_IGNORE_QV: ignore qid.version==0 as a marker to disable data cache + * @V9FS_DIRECT_IO: disable data read/write cache + * @V9FS_SYNC: disable data write cache * @V9FS_NDENTRY_TIMEOUT_SET: Has negative dentry timeout retention time been * overridden by negtimeout mount option * * Session flags reflect options selected by users at mount time */ -#define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \ - V9FS_ACCESS_USER | \ - V9FS_ACCESS_CLIENT) -#define V9FS_ACCESS_MASK V9FS_ACCESS_ANY -#define V9FS_ACL_MASK V9FS_POSIX_ACL - enum p9_session_flags { V9FS_PROTO_2000U = 0x01, V9FS_PROTO_2000L = 0x02, @@ -49,6 +45,20 @@ enum p9_session_flags { V9FS_NDENTRY_TIMEOUT_SET = 0x400, }; +/** + * V9FS_ACCESS_ANY - use a single attach for all users + */ +#define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \ + V9FS_ACCESS_USER | \ + V9FS_ACCESS_CLIENT) + +/** + * V9FS_ACCESS_MASK - bit mask of different ACCESS options + */ +#define V9FS_ACCESS_MASK V9FS_ACCESS_ANY + +#define V9FS_ACL_MASK V9FS_POSIX_ACL + /** * enum p9_cache_shortcuts - human readable cache preferences * @CACHE_SC_NONE: disable all caches diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 170a2b91c5f07a..90756b2c3fdd6c 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * This file contians vfs address (mmap) ops for 9P2000. + * This file contains vfs address (mmap) ops for 9P2000. * * Copyright (C) 2005 by Eric Van Hensbergen * Copyright (C) 2002 by Ron Minnich @@ -99,6 +99,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) char *target; unsigned long long pos = subreq->start + subreq->transferred; int total = 0, err, len, n; + size_t to_read = iov_iter_count(&subreq->io_iter); if (S_ISLNK(rreq->inode->i_mode)) { /* p9_client_readlink() must not be called for legacy protocols @@ -131,6 +132,8 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags); if (pos + total >= i_size_read(rreq->inode)) __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags); + if (!err && !total && to_read) + __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags); if (!err && total) { subreq->transferred += total; __set_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags); @@ -165,13 +168,16 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) goto no_fid; p9_fid_get(fid); } else if (S_ISLNK(rreq->inode->i_mode)) { + /* racing unlink/rename can make this fail with -ENOENT; + * that's expected, not a kernel bug, so don't WARN + */ dentry = d_find_any_alias(rreq->inode); if (!dentry) goto no_fid; fid = v9fs_fid_lookup(dentry); dput(dentry); if (IS_ERR(fid)) - goto no_fid; + return PTR_ERR(fid); } else { fid = v9fs_fid_find_inode(rreq->inode, writing, INVALID_UID, true); if (!fid) diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c index fa6b7143db98ff..5b05fa7bbc0652 100644 --- a/fs/9p/vfs_dentry.c +++ b/fs/9p/vfs_dentry.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * This file contians vfs dentry ops for the 9P2000 protocol. + * This file contains vfs dentry ops for the 9P2000 protocol. * * Copyright (C) 2004 by Eric Van Hensbergen * Copyright (C) 2002 by Ron Minnich diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 323f85352f6a40..b561f4ce020ef9 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -85,7 +85,6 @@ static struct p9_rdir *v9fs_alloc_rdir_buf(struct file *filp, int buflen) static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) { - bool over; struct p9_wstat st; int err = 0; struct p9_fid *fid; @@ -125,6 +124,9 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) rdir->offset = ctx->pos; } while (rdir->head < rdir->tail) { + bool over = false; + size_t namelen; + err = p9stat_read(fid->clnt, rdir->buf + rdir->head, rdir->tail - rdir->head, &st); if (err <= 0) { @@ -132,8 +134,15 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) return -EIO; } - over = !dir_emit(ctx, st.name, strlen(st.name), - QID2INO(&st.qid), dt_type(&st)); + namelen = strlen(st.name); + if (namelen > NAME_MAX) { + p9_debug(P9_DEBUG_ERROR, + "skip dentry: name length %zu > NAME_MAX\n", + namelen); + } else { + over = !dir_emit(ctx, st.name, namelen, + QID2INO(&st.qid), dt_type(&st)); + } p9stat_free(&st); if (over) return 0; @@ -184,6 +193,7 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx) } while (rdir->head < rdir->tail) { + size_t namelen; err = p9dirent_read(fid->clnt, rdir->buf + rdir->head, rdir->tail - rdir->head, @@ -193,11 +203,19 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx) return -EIO; } - if (!dir_emit(ctx, curdirent.d_name, - strlen(curdirent.d_name), - QID2INO(&curdirent.qid), - curdirent.d_type)) + namelen = strlen(curdirent.d_name); + if (namelen > NAME_MAX) { + p9_debug(P9_DEBUG_ERROR, + "skip dentry: name length %zu > NAME_MAX\n", + namelen); + } else if (!dir_emit(ctx, curdirent.d_name, namelen, + QID2INO(&curdirent.qid), + curdirent.d_type)) { + kfree(curdirent.d_name); return 0; + } + + kfree(curdirent.d_name); ctx->pos = curdirent.d_off; rdir->head += err; diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index cddfb4b7ce4e22..a983ef86671374 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * This file contians vfs file ops for 9P2000. + * This file contains vfs file ops for 9P2000. * * Copyright (C) 2004 by Eric Van Hensbergen * Copyright (C) 2002 by Ron Minnich diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 537cb22ac48b67..73776416902c21 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -481,7 +481,7 @@ static int v9fs_at_to_dotl_flags(int flags) } /** - * v9fs_dec_count - helper functon to drop i_nlink. + * v9fs_dec_count - helper function to drop i_nlink. * * If a directory had nlink <= 2 (including . and ..), then we should not drop * the link count, which indicates the underlying exported fs doesn't maintain @@ -495,6 +495,12 @@ static int v9fs_at_to_dotl_flags(int flags) * nothing and races with concurrent metadata fetches that may already * have observed the post-unlink value (nlink == 0). * + * The same applies to a regular file whose cached nlink has already been + * driven to zero by the server: in the cached modes the attributes come + * from GETATTR and are applied verbatim, so decrementing a link count the + * server does not maintain only trips the drop_nlink() WARN_ON and + * underflows i_nlink. + * * @inode: inode whose nlink is being dropped */ static void v9fs_dec_count(struct inode *inode) @@ -503,6 +509,8 @@ static void v9fs_dec_count(struct inode *inode) if (!(v9ses->cache & (CACHE_META | CACHE_LOOSE))) return; + if (inode->i_nlink == 0) + return; if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2) drop_nlink(inode); } @@ -673,8 +681,8 @@ v9fs_vfs_create(const struct mnt_idmap *idmap, struct inode *dir, /** * v9fs_vfs_mkdir - VFS mkdir hook to create a directory * @idmap: idmap of the mount - * @dir: inode that is being unlinked - * @dentry: dentry that is being unlinked + * @dir: inode of the parent directory + * @dentry: dentry representing the directory being created * @mode: mode for new directory * */ @@ -802,6 +810,16 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, v9fs_invalidate_inode_attr(dir); inode = d_inode(dentry); v9inode = V9FS_I(inode); + if (!S_ISREG(inode->i_mode)) { + /* + * Not a regular file. v9fs_create() already stored the + * unopened fid on the dentry. Clunk the opened fid from + * the create and let the VFS call ->open. + */ + p9_fid_put(fid); + file->f_mode |= FMODE_CREATED; + return finish_no_open(file, NULL); + } err = finish_open(file, dentry, generic_file_open); if (unlikely(err)) { p9_fid_put(fid); @@ -1134,7 +1152,7 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, if (v9fs_proto_dotu(v9ses)) { unsigned int i_nlink; /* - * Hadlink support got added later to the .u extension. + * Hardlink support got added later to the .u extension. * So there can be a server out there that doesn't * support this even with .u extension. That would * just leave us with stat->extension being an empty diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index c6afc9c1cf58f2..b224a089317764 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -312,20 +312,40 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); + if (!S_ISREG(inode->i_mode)) { + /* + * Not a regular file. The unopened fid is already on the + * dentry. Clunk the opened create fid and let the VFS call + * ->open. + */ + p9_fid_put(ofid); + ofid = NULL; + file->f_mode |= FMODE_CREATED; + err = finish_no_open(file, NULL); + goto out; + } /* Since we are opening a file, assign the open fid to the file */ err = finish_open(file, dentry, generic_file_open); if (err) goto out; - file->private_data = ofid; + /* + * Special files have type-specific fops that own + * file->private_data. The create fid is unused + * there: leave it for p9_fid_put() on the out + * path so it is clunked before we return. + */ + if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)) { + file->private_data = ofid; #ifdef CONFIG_9P_FSCACHE - if (v9ses->cache & CACHE_FSCACHE) { - struct v9fs_inode *v9inode = V9FS_I(inode); - fscache_use_cookie(v9fs_inode_cookie(v9inode), - file->f_mode & FMODE_WRITE); - } + if (v9ses->cache & CACHE_FSCACHE) { + struct v9fs_inode *v9inode = V9FS_I(inode); + fscache_use_cookie(v9fs_inode_cookie(v9inode), + file->f_mode & FMODE_WRITE); + } #endif - v9fs_fid_add_modes(ofid, v9ses->flags, v9ses->cache, flags); - v9fs_open_fid_add(inode, &ofid); + v9fs_fid_add_modes(ofid, v9ses->flags, v9ses->cache, flags); + v9fs_open_fid_add(inode, &ofid); + } file->f_mode |= FMODE_CREATED; out: p9_fid_put(dfid); diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 79526044685c9f..7b67193d921094 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -34,7 +34,7 @@ static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl; static int v9fs_fill_super(struct super_block *sb) { int ret; - struct v9fs_session_info *v9ses = v9ses = sb->s_fs_info; + struct v9fs_session_info *v9ses = sb->s_fs_info; sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_blocksize_bits = fls(v9ses->maxdata - 1); diff --git a/fs/adfs/dir_fplus.c b/fs/adfs/dir_fplus.c index 4a15924014da27..c68c301d890339 100644 --- a/fs/adfs/dir_fplus.c +++ b/fs/adfs/dir_fplus.c @@ -192,6 +192,8 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj) obj->indaddr = le32_to_cpu(bde.bigdirindaddr); obj->attr = le32_to_cpu(bde.bigdirattr); obj->name_len = le32_to_cpu(bde.bigdirobnamelen); + if (obj->name_len > ADFS_MAX_NAME_LEN - 4) /* leave room for ,xyz suffix */ + return -EIO; offset = adfs_fplus_offset(h, le32_to_cpu(h->bigdirentries)); offset += le32_to_cpu(bde.bigdirobnameptr); diff --git a/fs/aio.c b/fs/aio.c index bf002a9d2ad790..8cf02878a3ccea 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -961,7 +961,7 @@ void exit_aio(struct mm_struct *mm) if (!table) return; - atomic_set(&wait.count, table->nr); + atomic_set(&wait.count, table->nr + 1); init_completion(&wait.comp); skipped = 0; @@ -985,7 +985,7 @@ void exit_aio(struct mm_struct *mm) kill_ioctx(mm, ctx, &wait); } - if (!atomic_sub_and_test(skipped, &wait.count)) { + if (!atomic_sub_and_test(skipped + 1, &wait.count)) { /* Wait until all IO for the context are done. */ wait_for_completion(&wait.comp); } diff --git a/fs/backing-file.c b/fs/backing-file.c index 5780f60662d075..c601b27f0fd35c 100644 --- a/fs/backing-file.c +++ b/fs/backing-file.c @@ -115,8 +115,13 @@ struct backing_aio { static struct kmem_cache *backing_aio_cachep; +/* + * RWF_NOAPPEND stays set in ki_flags. Pass it on, because the backing file is + * in append mode as well and a new kiocb for it starts with IOCB_APPEND. + */ #define BACKING_IOCB_MASK \ - (IOCB_NOWAIT | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC | IOCB_APPEND) + (IOCB_NOWAIT | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC | IOCB_APPEND | \ + (__force int) RWF_NOAPPEND) static rwf_t iocb_to_rw_flags(int flags) { diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 2c6234f6182f89..2e12a6d7e16f55 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -624,6 +624,8 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free) /* If an error occurred we just want to clean up the bio and move on. */ if (bio->bi_status) { + btrfs_put_bioc(async->bioc); + btrfs_bio_counter_dec(async->bbio->inode->root->fs_info); btrfs_bio_end_io(async->bbio, bio->bi_status); return; } @@ -762,6 +764,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) split = btrfs_split_bio(fs_info, bbio, map_length); if (IS_ERR(split)) { status = errno_to_blk_status(PTR_ERR(split)); + btrfs_put_bioc(bioc); btrfs_bio_counter_dec(fs_info); goto end_bbio; } @@ -822,6 +825,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) return map_length == length; fail: + btrfs_put_bioc(bioc); btrfs_bio_counter_dec(fs_info); /* * We have split the original bbio, now we have to end both the current diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 9a98e291769ca6..f923d27f1bf2ea 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -3727,7 +3727,7 @@ void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes, if (bg_ro) space_info->bytes_readonly += num_bytes; else if (btrfs_is_zoned(cache->fs_info)) - space_info->bytes_zone_unusable += num_bytes; + btrfs_space_info_update_bytes_zone_unusable(space_info, num_bytes); space_info->bytes_reserved -= num_bytes; space_info->max_extent_size = 0; diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c index 7010d714cfe100..cbc532b49c67d7 100644 --- a/fs/btrfs/defrag.c +++ b/fs/btrfs/defrag.c @@ -242,13 +242,22 @@ static int btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info, goto cleanup; } + /* + * Clear the flag right away. On the first iteration (cur == 0) if the + * inode happened to have been truncated to 0 after it was added to + * autodefrag and before we were called, then we need to clear the flag, + * otherwise if writes are done to the inode we won't be able to add it + * to autodefrag again (unless the inode is evicted, loaded again, and + * small writes to it happen again). + */ + clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags); + if (cur >= i_size_read(&inode->vfs_inode)) { iput(&inode->vfs_inode); goto cleanup; } /* Do a chunk of defrag */ - clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags); memset(&range, 0, sizeof(range)); range.len = (u64)-1; range.start = cur; diff --git a/fs/btrfs/direct-io.c b/fs/btrfs/direct-io.c index ed3914257d3959..90919d79d069c7 100644 --- a/fs/btrfs/direct-io.c +++ b/fs/btrfs/direct-io.c @@ -807,10 +807,6 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio, static DEFINE_IOMAP_ITER_NEXT_END(btrfs_dio_iomap_next, btrfs_dio_iomap_begin, btrfs_dio_iomap_end); -static const struct iomap_ops btrfs_dio_iomap_ops = { - .iomap_next = btrfs_dio_iomap_next, -}; - static const struct iomap_dio_ops btrfs_dio_ops = { .submit_io = btrfs_dio_submit_io, .bio_set = &btrfs_dio_bioset, @@ -821,7 +817,7 @@ static ssize_t btrfs_dio_read(struct kiocb *iocb, struct iov_iter *iter, { struct btrfs_dio_data data = { 0 }; - return iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops, + return iomap_dio_rw(iocb, iter, btrfs_dio_iomap_next, &btrfs_dio_ops, IOMAP_DIO_PARTIAL | IOMAP_DIO_FSBLOCK_ALIGNED, &data, done_before); } @@ -858,7 +854,7 @@ static struct iomap_dio *btrfs_dio_write(struct kiocb *iocb, struct iov_iter *it dio_flags |= IOMAP_DIO_BOUNCE; } - return __iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops, + return __iomap_dio_rw(iocb, iter, btrfs_dio_iomap_next, &btrfs_dio_ops, dio_flags, &data, done_before); } diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c45cda4290d5a3..9100874093469b 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1169,6 +1169,8 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, return btrfs_grab_root(fs_info->stripe_root); case BTRFS_REMAP_TREE_OBJECTID: return btrfs_grab_root(fs_info->remap_root); + case BTRFS_DATA_RELOC_TREE_OBJECTID: + return btrfs_grab_root(fs_info->data_reloc_root); default: return NULL; } @@ -1304,8 +1306,15 @@ static struct btrfs_root *btrfs_get_root_ref(struct btrfs_fs_info *fs_info, * * This is namely for free-space-tree and quota tree, which can change * at runtime and should only be grabbed from fs_info. + * + * The data reloc tree is also such a tree. It is loaded at mount time + * by read_data_reloc_root() and never inserted into the radix tree, as + * radix tree keys are of type `unsigned long`, which is 32 bits wide + * on 32-bit platforms. + * Casting the objectid to `unsigned long` can therefore result in a + * conflict with a subvolume. */ - if (!btrfs_is_fstree(objectid) && objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) + if (!btrfs_is_fstree(objectid)) return ERR_PTR(-ENOENT); again: root = btrfs_lookup_fs_root(fs_info, objectid); @@ -1409,6 +1418,39 @@ struct btrfs_root *btrfs_get_new_fs_root(struct btrfs_fs_info *fs_info, return btrfs_get_root_ref(fs_info, objectid, anon_dev, true); } +/* Read and initialize the data reloc tree. */ +static struct btrfs_root *read_data_reloc_root(struct btrfs_fs_info *fs_info) +{ + struct btrfs_key key = { + .objectid = BTRFS_DATA_RELOC_TREE_OBJECTID, + .type = BTRFS_ROOT_ITEM_KEY, + .offset = (u64)-1, + }; + struct btrfs_root *root; + int ret; + + root = btrfs_read_tree_root(fs_info->tree_root, &key); + if (IS_ERR(root)) + return root; + + if (btrfs_root_refs(&root->root_item) == 0) { + ret = -ENOENT; + goto fail; + } + + /* + * This tree can share blocks with some other fs tree during + * relocation and we need a proper setup by btrfs_init_fs_root(). + */ + ret = btrfs_init_fs_root(root, 0); + if (ret) + goto fail; + return root; +fail: + btrfs_put_root(root); + return ERR_PTR(ret); +} + /* * Return a root for the given objectid. * @@ -1847,6 +1889,7 @@ void btrfs_put_root(struct btrfs_root *root) if (root->anon_dev) free_anon_bdev(root->anon_dev); free_root_extent_buffers(root); + btrfs_qgroup_clean_swapped_blocks(root); #ifdef CONFIG_BTRFS_DEBUG spin_lock(&root->fs_info->fs_roots_radix_lock); list_del_init(&root->leak_list); @@ -1862,6 +1905,25 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info) struct btrfs_root *gang[8]; int i; + /* + * Some dirty roots may still be linked to dirty_cowonly_roots after + * the transaction is aborted. Cleanup them here. + */ + while (!list_empty(&fs_info->dirty_cowonly_roots)) { + struct btrfs_root *root; + + root = list_first_entry(&fs_info->dirty_cowonly_roots, + struct btrfs_root, dirty_list); + list_del_init(&root->dirty_list); + /* + * The dirty_log_pages should never be populated for + * cowonly trees. + */ + spin_lock(&root->dirty_log_pages.lock); + ASSERT(RB_EMPTY_ROOT(&root->dirty_log_pages.state)); + spin_unlock(&root->dirty_log_pages.lock); + } + while (!list_empty(&fs_info->dead_roots)) { gang[0] = list_first_entry(&fs_info->dead_roots, struct btrfs_root, root_list); @@ -2255,12 +2317,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) PTR_ERR(root)); } } else { - /* - * This tree can share blocks with some other fs tree during - * relocation and we need a proper setup by btrfs_get_fs_root(). - */ - root = btrfs_get_fs_root(tree_root->fs_info, - BTRFS_DATA_RELOC_TREE_OBJECTID, true); + root = read_data_reloc_root(fs_info); if (IS_ERR(root)) { if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { location.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID; @@ -3795,8 +3852,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device btrfs_put_block_group_cache(fs_info); fail_tree_roots: - if (fs_info->data_reloc_root) - btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root); free_root_pointers(fs_info, true); invalidate_and_check_btree_folios(fs_info); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 55e9144d47595f..5ff630630490e3 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -504,7 +504,7 @@ static bool btrfs_verify_folio(struct fsverity_info *vi, struct folio *folio, if (!vi || btrfs_folio_test_uptodate(fs_info, folio, start, len)) return true; - return fsverity_verify_folio(vi, folio); + return fsverity_verify_blocks(vi, folio, len, offset_in_folio(folio, start)); } static void end_folio_read(struct fsverity_info *vi, struct folio *folio, diff --git a/fs/btrfs/fiemap.c b/fs/btrfs/fiemap.c index 7a2a9718009938..817171028413c1 100644 --- a/fs/btrfs/fiemap.c +++ b/fs/btrfs/fiemap.c @@ -228,7 +228,8 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo, * * 3) Share same flags */ - if (cache->offset + cache->len == offset && + if (!(flags & FIEMAP_EXTENT_ENCODED) && + cache->offset + cache->len == offset && cache->phys + cache->len == phys && cache->flags == flags) { cache->len += len; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index f3e2afe221be35..6ba883db107b46 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -375,6 +375,19 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap, } } + /* + * Callers write back the whole flag set, so only touch the compression + * flags and the compression property if FS_COMPR_FL or FS_NOCOMP_FL + * changes. + */ + if (!((fsflags ^ old_fsflags) & (FS_COMPR_FL | FS_NOCOMP_FL))) { + /* 1 item for the inode */ + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); + goto update_flags; + } + /* * The COMPRESS flag can only be changed by users, while the NOCOMPRESS * flag may be changed automatically if compression code won't make @@ -2380,6 +2393,17 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, inode = d_inode(dentry); dest = BTRFS_I(inode)->root; + + /* + * A concurrent rename may have changed which subvolume the name + * refers to. Verify that the resolved ID still matches the requested ID. + */ + if (destroy_v2 && (vol_args2->flags & BTRFS_SUBVOL_SPEC_BY_ID) && + btrfs_root_id(dest) != vol_args2->subvolid) { + ret = -EAGAIN; + goto out_end_removing; + } + if (!capable(CAP_SYS_ADMIN)) { /* * Regular user. Only allow this with a special mount @@ -5137,8 +5161,12 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a return -ENOENT; wait_for_deletion = true; - ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, "root_flags=0x%llx", - root_flags); + if (unlikely(!(root_flags & BTRFS_ROOT_SUBVOL_DEAD))) { + btrfs_err(fs_info, + "subvol %llu has refs 0 without DEAD flag", + args.subvolid); + return -EUCLEAN; + } sched_ret = schedule_timeout_interruptible(HZ); /* Early wake up or error. */ if (sched_ret != 0) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a0651fbfe77820..baef546fa213e3 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1440,10 +1440,6 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info) goto out; } - spin_lock(&fs_info->trans_lock); - list_del("a_root->dirty_list); - spin_unlock(&fs_info->trans_lock); - btrfs_tree_lock(quota_root->node); btrfs_clear_buffer_dirty(trans, quota_root->node); btrfs_tree_unlock(quota_root->node); @@ -1454,7 +1450,13 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info) btrfs_abort_transaction(trans, ret); out: - btrfs_put_root(quota_root); + if (quota_root) { + spin_lock(&fs_info->trans_lock); + list_del("a_root->dirty_list); + spin_unlock(&fs_info->trans_lock); + btrfs_put_root(quota_root); + } + mutex_unlock(&fs_info->qgroup_ioctl_lock); if (ret && trans) btrfs_end_transaction(trans); diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 479c0e037015ab..bbe74af3506c18 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2250,7 +2250,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx, "scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl", full_stripe_start, i, stripe->nr_sectors, &error); - return ret; + return -EIO; } bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent, stripe->nr_sectors); @@ -3171,7 +3171,6 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, memalloc_nofs_restore(nofs_flag); atomic_dec(&fs_info->scrubs_running); - wake_up(&fs_info->scrub_pause_wait); if (progress) memcpy(progress, &sctx->stat, sizeof(*progress)); @@ -3184,6 +3183,13 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, dev->scrub_ctx = NULL; mutex_unlock(&fs_info->scrub_lock); + /* + * We have set dev->scrub_ctx to NULL, now do the wakeup as a concurrent + * scrub cancel (btrfs_scrub_cancel_dev()) waits for dev->scrub_ctx to + * be set to NULL. + */ + wake_up(&fs_info->scrub_pause_wait); + scrub_workers_put(fs_info); scrub_put_ctx(sctx); @@ -3289,10 +3295,16 @@ int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid, mutex_lock(&fs_info->fs_devices->device_list_mutex); dev = btrfs_find_device(fs_info->fs_devices, &args); - if (dev) + if (dev) { + mutex_lock(&fs_info->scrub_lock); sctx = dev->scrub_ctx; - if (sctx) - memcpy(progress, &sctx->stat, sizeof(*progress)); + if (sctx) { + spin_lock(&sctx->stat_lock); + memcpy(progress, &sctx->stat, sizeof(*progress)); + spin_unlock(&sctx->stat_lock); + } + mutex_unlock(&fs_info->scrub_lock); + } mutex_unlock(&fs_info->fs_devices->device_list_mutex); return dev ? (sctx ? 0 : -ENOTCONN) : -ENODEV; diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 3ac1fa608d3b56..89b0a4ef4063ed 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1741,6 +1741,7 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group *cache) if (space_info->block_group_kobjs[index]) { spin_unlock(&space_info->lock); kobject_put(&rkobj->kobj); + memalloc_nofs_restore(nofs_flag); return; } else { space_info->block_group_kobjs[index] = &rkobj->kobj; @@ -2049,6 +2050,9 @@ int btrfs_sysfs_add_device(struct btrfs_device *device) ret = kobject_init_and_add(&device->devid_kobj, &devid_ktype, devinfo_kobj, "%llu", device->devid); if (ret) { + if (device->bdev) + sysfs_remove_link(devices_kobj, + bdev_kobj(device->bdev)->name); kobject_put(&device->devid_kobj); btrfs_warn(device->fs_info, "devinfo init for devid %llu failed: %d", diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 9cd79d97b9b5e7..a2aa4013e08285 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1766,7 +1766,11 @@ static int check_extent_item(struct extent_buffer *leaf, inline_refs += btrfs_shared_data_ref_count(leaf, sref); break; case BTRFS_EXTENT_OWNER_REF_KEY: - WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA)); + if (unlikely(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA))) { + extent_err(leaf, slot, + "extent owner ref without simple quota"); + return -EUCLEAN; + } break; default: extent_err(leaf, slot, "unknown inline ref type: %u", diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c index b34d2247cf84e0..79ace98714ad8d 100644 --- a/fs/btrfs/verity.c +++ b/fs/btrfs/verity.c @@ -610,7 +610,7 @@ static int btrfs_begin_enable_verity(struct file *filp) set_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags); btrfs_end_transaction(trans); - return 0; + return ret; } /* diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d3e6a9b429dd9d..f1305f68b1f8ab 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3097,7 +3097,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path mutex_unlock(&fs_info->chunk_mutex); /* Add sysfs device entry */ - btrfs_sysfs_add_device(device); + ret = btrfs_sysfs_add_device(device); + if (ret) { + mutex_unlock(&fs_devices->device_list_mutex); + goto error_unwind_device; + } mutex_unlock(&fs_devices->device_list_mutex); @@ -3178,6 +3182,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path error_sysfs: btrfs_sysfs_remove_device(device); +error_unwind_device: mutex_lock(&fs_info->fs_devices->device_list_mutex); if (seeding_dev) btrfs_assign_next_active_device(device, seed_devices->latest_dev); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 6eddda23922152..1c4cfb21ad1240 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -708,9 +708,8 @@ static inline enum btrfs_map_op btrfs_op(const struct bio *bio) static inline unsigned long btrfs_chunk_item_size(int num_stripes) { - ASSERT(num_stripes); - return sizeof(struct btrfs_chunk) + - sizeof(struct btrfs_stripe) * (num_stripes - 1); + return offsetof(struct btrfs_chunk, stripe) + + sizeof(struct btrfs_stripe) * num_stripes; } /* diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 1cda88332284e8..bdadc704c8cbba 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -645,6 +645,11 @@ struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *o if (!zone_info) return NULL; + /* Don't let the error path free the bitmaps still owned by @orig_dev. */ + zone_info->seq_zones = NULL; + zone_info->empty_zones = NULL; + zone_info->active_zones = NULL; + zone_info->seq_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL); if (!zone_info->seq_zones) goto out; @@ -1117,11 +1122,13 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, return pos; } -static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) +static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos, bool *new) { struct btrfs_zoned_device_info *zone_info = device->zone_info; unsigned int zno = (pos >> zone_info->zone_size_shift); + *new = false; + /* We can use any number of zones */ if (zone_info->max_active_zones == 0) return true; @@ -1133,23 +1140,29 @@ static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) if (test_and_set_bit(zno, zone_info->active_zones)) { /* Someone already set the bit */ atomic_inc(&zone_info->active_zones_left); + } else { + *new = true; } } return true; } -static void btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) +static bool btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) { struct btrfs_zoned_device_info *zone_info = device->zone_info; unsigned int zno = (pos >> zone_info->zone_size_shift); /* We can use any number of zones */ if (zone_info->max_active_zones == 0) - return; + return false; - if (test_and_clear_bit(zno, zone_info->active_zones)) + if (test_and_clear_bit(zno, zone_info->active_zones)) { atomic_inc(&zone_info->active_zones_left); + return true; + } + + return false; } int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, @@ -1371,11 +1384,13 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx, return 0; } + ASSERT(!test_bit(BTRFS_FS_OPEN, &fs_info->flags)); + up_read(&dev_replace->rwsem); + nofs_flag = memalloc_nofs_save(); ret = btrfs_get_dev_zone(device, info->physical, &zone); memalloc_nofs_restore(nofs_flag); if (ret) { - up_read(&dev_replace->rwsem); if (ret != -EIO && ret != -EOPNOTSUPP) return ret; info->alloc_offset = WP_MISSING_DEV; @@ -1387,7 +1402,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx, "zoned: unexpected conventional zone %llu on device %s (devid %llu)", zone.start << SECTOR_SHIFT, rcu_dereference(device->name), device->devid); - up_read(&dev_replace->rwsem); return -EIO; } @@ -1415,8 +1429,6 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx, break; } - up_read(&dev_replace->rwsem); - return 0; } @@ -2402,6 +2414,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) u64 physical; const bool is_data = (block_group->flags & BTRFS_BLOCK_GROUP_DATA); bool ret; + bool new; int i; if (!btrfs_is_zoned(block_group->fs_info)) @@ -2455,12 +2468,12 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) goto out_unlock; } - if (!btrfs_dev_set_active_zone(device, physical)) { + if (!btrfs_dev_set_active_zone(device, physical, &new)) { /* Cannot activate the zone */ ret = false; goto out_unlock; } - if (!is_data) + if (!is_data && new) zinfo->reserved_active_zones--; } @@ -2494,8 +2507,16 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group) continue; if (eb->start >= end) break; + /* + * Skip if we can't get the refcount for the extent buffer, + * i.e. because it was already written back. Otherwise an eb + * disappering underneath us can cause a use-after-free. + */ + if (!refcount_inc_not_zero(&eb->refs)) + continue; rcu_read_unlock(); wait_on_extent_buffer_writeback(eb); + free_extent_buffer(eb); rcu_read_lock(); } rcu_read_unlock(); @@ -2507,6 +2528,7 @@ static int call_zone_finish(struct btrfs_block_group *block_group, struct btrfs_device *device = stripe->dev; const u64 physical = stripe->physical; struct btrfs_zoned_device_info *zinfo = device->zone_info; + bool cleared; int ret; if (!device->bdev) @@ -2528,9 +2550,9 @@ static int call_zone_finish(struct btrfs_block_group *block_group, return ret; } - if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA)) + cleared = btrfs_dev_clear_active_zone(device, physical); + if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA) && cleared) zinfo->reserved_active_zones++; - btrfs_dev_clear_active_zone(device, physical); return 0; } @@ -2578,9 +2600,10 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ /* Ensure all writes in this block group finish */ btrfs_wait_block_group_reservations(block_group); - /* No need to wait for NOCOW writers. Zoned mode does not allow that */ - btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group); - /* Wait for extent buffers to be written. */ + /* + * No need to wait for NOCOW writers, as zoned mode does not + * allow that, only wait for extent buffers to be written. + */ if (is_metadata) wait_eb_writebacks(block_group); @@ -3109,6 +3132,8 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num { struct btrfs_fs_info *fs_info = space_info->fs_info; const sector_t zone_size_sectors = fs_info->zone_size >> SECTOR_SHIFT; + LIST_HEAD(retry_list); + int ret = 0; if (!btrfs_is_zoned(fs_info)) return 0; @@ -3150,11 +3175,10 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num } if (!found) { spin_unlock(&fs_info->unused_bgs_lock); - return 0; + goto out; } list_del_init(&bg->bg_list); - btrfs_put_block_group(bg); spin_unlock(&fs_info->unused_bgs_lock); /* @@ -3168,7 +3192,6 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num for (int i = 0; i < map->num_stripes; i++) { struct btrfs_io_stripe *stripe = &map->stripes[i]; unsigned int nofs_flags; - int ret; nofs_flags = memalloc_nofs_save(); ret = blkdev_zone_mgmt(stripe->dev->bdev, REQ_OP_ZONE_RESET, @@ -3178,7 +3201,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num if (ret) { up_read(&fs_info->dev_replace.rwsem); - return ret; + goto requeue; } } up_read(&fs_info->dev_replace.rwsem); @@ -3189,7 +3212,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num if (bg->ro) { spin_unlock(&bg->lock); spin_unlock(&space_info->lock); - continue; + goto requeue; } reclaimed = bg->alloc_offset; @@ -3213,17 +3236,33 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num ASSERT(reclaimed == bg->zone_capacity, "reclaimed=%llu bg->zone_capacity=%llu", reclaimed, bg->zone_capacity); bg->free_space_ctl->free_space += reclaimed; - space_info->bytes_zone_unusable -= reclaimed; + btrfs_space_info_update_bytes_zone_unusable(space_info, -reclaimed); spin_unlock(&bg->lock); btrfs_return_free_space(space_info, reclaimed); spin_unlock(&space_info->lock); + btrfs_put_block_group(bg); + if (num_bytes <= reclaimed) break; num_bytes -= reclaimed; + continue; + +requeue: + list_add_tail(&bg->bg_list, &retry_list); + + if (ret) + goto out; } - return 0; +out: + if (!list_empty(&retry_list)) { + spin_lock(&fs_info->unused_bgs_lock); + list_splice_tail(&retry_list, &fs_info->unused_bgs); + spin_unlock(&fs_info->unused_bgs_lock); + } + + return ret; } void btrfs_show_zoned_stats(struct btrfs_fs_info *fs_info, struct seq_file *seq) diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index cc92d0b1b948cd..9b7c7f43527f7f 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -347,7 +347,8 @@ void zstd_put_workspace(struct btrfs_fs_info *fs_info, struct list_head *ws) /* A node is only taken off the lru if we are the corresponding level */ if (clip_level(workspace->req_level) == workspace->level) { /* Hide a max level workspace from reclaim */ - if (list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) { + if (workspace->level == ZSTD_BTRFS_MAX_LEVEL - 1 && + list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) { INIT_LIST_HEAD(&workspace->lru_list); } else { workspace->last_used = jiffies; diff --git a/fs/buffer.c b/fs/buffer.c index 5d3852b726d6b1..f951559e7d32cd 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -621,12 +621,15 @@ void write_boundary_block(struct block_device *bdev, * @bh: The buffer to mark dirty. * @mmb: The list of buffers to add the buffer to. * - * Mark the buffer dirty and add it to the list if it is not already on - * a list. + * Mark the buffer dirty, add it to the list if it is not already on a list + * and set I_METADATA_WRITEBACK on the inode so that fsync() and eviction + * write it out. */ void mmb_mark_buffer_dirty(struct buffer_head *bh, struct mapping_metadata_bhs *mmb) { + struct inode *inode = mmb->mapping->host; + mark_buffer_dirty(bh); if (!bh->b_mmb) { spin_lock(&mmb->lock); @@ -641,6 +644,15 @@ void mmb_mark_buffer_dirty(struct buffer_head *bh, list_move_tail(&bh->b_assoc_buffers, &mmb->list); spin_unlock(&mmb->lock); } + /* + * The inode itself may never have been dirtied, so attach it to a wb + * before setting the bit or writeback_single_inode() has nothing to + * lock when evict() syncs it. + */ + spin_lock(&inode->i_lock); + inode_attach_wb(inode, NULL); + inode_state_set(inode, I_METADATA_WRITEBACK); + spin_unlock(&inode->i_lock); } EXPORT_SYMBOL(mmb_mark_buffer_dirty); diff --git a/fs/ceph/file.c b/fs/ceph/file.c index bbb986781891c5..4a19a00be96f8b 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -137,7 +137,7 @@ static ssize_t iter_get_bvecs_alloc(struct iov_iter *iter, size_t maxsize, iov_iter_reexpand(iter, orig_count); /* Worst case is one bio_vec per page */ - bv = kvmalloc_objs(*bv, npages, GFP_KERNEL); + bv = kvmalloc_objs(*bv, npages); if (!bv) return -ENOMEM; diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index de36c83e94c0d3..3791fc627714ca 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -4538,8 +4538,8 @@ static void handle_session(struct ceph_mds_session *session, ceph_decode_64_safe(&p, end, cap_auths[i].match.uid, bad); ceph_decode_32_safe(&p, end, _len, bad); if (_len) { - cap_auths[i].match.gids = kcalloc(_len, sizeof(u32), - GFP_KERNEL); + cap_auths[i].match.gids = kzalloc_objs(u32, + _len); if (!cap_auths[i].match.gids) { pr_err_client(cl, "No memory for gids\n"); goto fail; diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index 8e2937e4e56283..d317c91547f10c 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c @@ -267,8 +267,9 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p, info->laggy = laggy; info->num_export_targets = num_export_targets; if (num_export_targets) { - info->export_targets = kcalloc(num_export_targets, - sizeof(u32), GFP_NOFS); + info->export_targets = kzalloc_objs(u32, + num_export_targets, + GFP_NOFS); if (!info->export_targets) goto nomem; for (j = 0; j < num_export_targets; j++) { @@ -287,7 +288,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p, /* pg_pools */ ceph_decode_32_safe(p, end, n, bad); m->m_num_data_pg_pools = n; - m->m_data_pg_pools = kcalloc(n, sizeof(u64), GFP_NOFS); + m->m_data_pg_pools = kzalloc_objs(u64, n, GFP_NOFS); if (!m->m_data_pg_pools) goto nomem; ceph_decode_need(p, end, sizeof(u64)*(n+1), bad); diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index 5c1540d95b8c39..895968ab6a1fa6 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -493,7 +493,7 @@ static int dup_array(u64 **dst, __le64 *src, u32 num) kfree(*dst); if (num) { - *dst = kcalloc(num, sizeof(u64), GFP_NOFS); + *dst = kzalloc_objs(u64, num, GFP_NOFS); if (!*dst) return -ENOMEM; for (i = 0; i < num; i++) diff --git a/fs/coda/file.c b/fs/coda/file.c index 6ca8bfcb58f295..c9fba41f7ceace 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -71,6 +71,7 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) struct file *host_file = cfi->cfi_container; loff_t ki_pos = iocb->ki_pos; size_t count = iov_iter_count(to); + rwf_t flags = (iocb->ki_flags & IOCB_APPEND) ? RWF_APPEND : RWF_NOAPPEND; ssize_t ret; ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), @@ -80,7 +81,7 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) goto finish_write; inode_lock(coda_inode); - ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0); + ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, flags); coda_inode->i_size = file_inode(host_file)->i_size; coda_inode->i_blocks = (coda_inode->i_size + 511) >> 9; inode_set_mtime_to_ts(coda_inode, inode_set_ctime_current(coda_inode)); diff --git a/fs/dax.c b/fs/dax.c index 94ba41273347cf..9d161d7ef3ef74 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1485,7 +1485,7 @@ static int dax_unshare_iter(struct iomap_iter *iter) } int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_iter iter = { .inode = inode, @@ -1499,7 +1499,7 @@ int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, return 0; iter.len = min(len, size - pos); - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = dax_unshare_iter(&iter); return ret; } @@ -1577,7 +1577,7 @@ static int dax_zero_iter(struct iomap_iter *iter, bool *did_zero) } int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_iter iter = { .inode = inode, @@ -1587,14 +1587,14 @@ int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, }; int ret; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = dax_zero_iter(&iter, did_zero); return ret; } EXPORT_SYMBOL_GPL(dax_zero_range); int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { unsigned int blocksize = i_blocksize(inode); unsigned int off = pos & (blocksize - 1); @@ -1602,7 +1602,7 @@ int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, /* Block boundary? Nothing to do */ if (!off) return 0; - return dax_zero_range(inode, pos, blocksize - off, did_zero, ops); + return dax_zero_range(inode, pos, blocksize - off, did_zero, next); } EXPORT_SYMBOL_GPL(dax_truncate_page); @@ -1727,7 +1727,8 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter) * dax_iomap_rw - Perform I/O to a DAX file * @iocb: The control block for this I/O * @iter: The addresses to do I/O from or to - * @ops: iomap ops passed from the file system + * @next: Callback passed from the file system for advancing to next + * iteration * * This function performs read and write operations to directly mapped * persistent memory. The callers needs to take care of read/write exclusion @@ -1735,7 +1736,7 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter) */ ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_iter iomi = { .inode = iocb->ki_filp->f_mapping->host, @@ -1762,7 +1763,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, if (iocb->ki_flags & IOCB_NOWAIT) iomi.flags |= IOMAP_NOWAIT; - while ((ret = iomap_iter(&iomi, ops)) > 0) + while ((ret = iomap_iter(&iomi, next)) > 0) iomi.status = dax_iomap_iter(&iomi, iter); done = iomi.pos - iocb->ki_pos; @@ -1890,7 +1891,7 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, } static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, unsigned long *pfnp, - int *iomap_errp, const struct iomap_ops *ops) + int *iomap_errp, iomap_iter_next_fn next) { struct address_space *mapping = vmf->vma->vm_file->f_mapping; XA_STATE(xas, &mapping->i_pages, vmf->pgoff); @@ -1935,7 +1936,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, unsigned long *pfnp, goto unlock_entry; } - while ((error = iomap_iter(&iter, ops)) > 0) { + while ((error = iomap_iter(&iter, next)) > 0) { if (WARN_ON_ONCE(iomap_length(&iter) < PAGE_SIZE)) { iter.status = -EIO; /* fs corruption? */ continue; @@ -2000,7 +2001,7 @@ static bool dax_fault_check_fallback(struct vm_fault *vmf, struct xa_state *xas, } static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct address_space *mapping = vmf->vma->vm_file->f_mapping; XA_STATE_ORDER(xas, &mapping->i_pages, vmf->pgoff, PMD_ORDER); @@ -2057,7 +2058,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, } iter.pos = (loff_t)xas.xa_index << PAGE_SHIFT; - while (iomap_iter(&iter, ops) > 0) { + while (iomap_iter(&iter, next) > 0) { if (iomap_length(&iter) < PMD_SIZE) continue; /* actually breaks out of the loop */ @@ -2079,7 +2080,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, } #else static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { return VM_FAULT_FALLBACK; } @@ -2091,7 +2092,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, * @order: Order of the page to fault in * @pfnp: PFN to insert for synchronous faults if fsync is required * @iomap_errp: Storage for detailed error code in case of error - * @ops: Iomap ops passed from the file system + * @next: The iomap iteration function for the filesystem * * When a page fault occurs, filesystems may call this helper in * their fault handler for DAX files. dax_iomap_fault() assumes the caller @@ -2100,12 +2101,12 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp, */ vm_fault_t dax_iomap_fault(struct vm_fault *vmf, unsigned int order, unsigned long *pfnp, int *iomap_errp, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { if (order == 0) - return dax_iomap_pte_fault(vmf, pfnp, iomap_errp, ops); + return dax_iomap_pte_fault(vmf, pfnp, iomap_errp, next); else if (order == PMD_ORDER) - return dax_iomap_pmd_fault(vmf, pfnp, ops); + return dax_iomap_pmd_fault(vmf, pfnp, next); else return VM_FAULT_FALLBACK; } @@ -2235,7 +2236,7 @@ static int dax_range_compare_iter(struct iomap_iter *it_src, int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dst, loff_t dstoff, loff_t len, bool *same, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_iter src_iter = { .inode = src, @@ -2251,8 +2252,8 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, }; int ret, status; - while ((ret = iomap_iter(&src_iter, ops)) > 0 && - (ret = iomap_iter(&dst_iter, ops)) > 0) { + while ((ret = iomap_iter(&src_iter, next)) > 0 && + (ret = iomap_iter(&dst_iter, next)) > 0) { status = dax_range_compare_iter(&src_iter, &dst_iter, min(src_iter.len, dst_iter.len), same); if (status < 0) @@ -2265,9 +2266,10 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, int dax_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *len, unsigned int remap_flags, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { return __generic_remap_file_range_prep(file_in, pos_in, file_out, - pos_out, len, remap_flags, ops); + pos_out, len, remap_flags, + next); } EXPORT_SYMBOL_GPL(dax_remap_file_range_prep); diff --git a/fs/dcache.c b/fs/dcache.c index 409f841e058e43..ba17f49f8a6369 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "internal.h" #include "mount.h" @@ -45,7 +46,8 @@ * dcache_hash_bucket lock protects: * - the dcache hash table * s_roots_lock protects: - * - the s_roots list (see __d_move()/dentry_unlist()/d_obtain_root()) + * - the s_roots list (see __d_move()/dentry_unlist()/d_obtain_root()/ + * dput_to_list()) * dentry->d_sb->s_dentry_lru_lock protects: * - the dcache lru lists and counters * d_lock protects: @@ -359,58 +361,51 @@ static inline int dname_external(const struct dentry *dentry) return dentry->d_name.name != dentry->d_shortname.string; } -static bool __take_dentry_name_snapshot(struct name_snapshot *name, - struct dentry *dentry, bool retry) +static bool try_name_snapshot(struct name_snapshot *name, struct dentry *dentry) { - unsigned seq; - const unsigned char *s; + const unsigned char *s = READ_ONCE(dentry->d_name.name); + struct external_name *p; - rcu_read_lock(); -retry: - seq = read_seqcount_begin(&dentry->d_seq); - s = READ_ONCE(dentry->d_name.name); name->name.hash_len = dentry->d_name.hash_len; name->name.name = name->inline_name.string; if (likely(s == dentry->d_shortname.string)) { name->inline_name = dentry->d_shortname; - } else { - struct external_name *p; - p = container_of(s, struct external_name, name[0]); - // get a valid reference - if (unlikely(!atomic_inc_not_zero(&p->count))) { - if (retry) - goto retry; - rcu_read_unlock(); - return false; - } - name->name.name = s; + return true; } - if (read_seqcount_retry(&dentry->d_seq, seq)) { - release_dentry_name_snapshot(name); - goto retry; + + // Try to get a valid external reference + // + // In case we fail to get a ref, 'name.name' will + // point to the inline_name, which we leave as an + // empty name. release_dentry_name_snapshot() can + // be called regardless. + p = container_of(s, struct external_name, name[0]); + if (unlikely(!atomic_inc_not_zero(&p->count))) { + name->name.len = 0; + name->inline_name.string[0] = 0; + return false; } - rcu_read_unlock(); + + // We got a ref and the name is now needs to be + // free'd regardless of whether the sequence count + // matches or not + name->name.name = s; return true; } -void take_dentry_name_snapshot(struct name_snapshot *name, struct dentry *dentry) +bool take_dentry_name_snapshot(struct name_snapshot *name, struct dentry *dentry) { - __take_dentry_name_snapshot(name, dentry, true); + guard(rcu)(); + for (;;) { + unsigned seq = read_seqcount_begin(&dentry->d_seq); + bool retval = try_name_snapshot(name, dentry); + if (!read_seqcount_retry(&dentry->d_seq, seq)) + return retval; + release_dentry_name_snapshot(name); + } } EXPORT_SYMBOL(take_dentry_name_snapshot); -/* - * For a caller that holds no reference on @dentry, e.g. in RCU walk. - * The external name of a dead dentry has a zero refcount forever, so - * take_dentry_name_snapshot() would retry without end. Fail instead. - */ -bool try_take_dentry_name_snapshot(struct name_snapshot *name, - struct dentry *dentry) -{ - return __take_dentry_name_snapshot(name, dentry, false); -} -EXPORT_SYMBOL(try_take_dentry_name_snapshot); - void release_dentry_name_snapshot(struct name_snapshot *name) { if (unlikely(name->name.name != name->inline_name.string)) { @@ -1124,7 +1119,18 @@ void dput_to_list(struct dentry *dentry, struct list_head *list) { if (likely(fast_dput(dentry))) return; - __move_to_shrink_list(dentry, list); + /* + * The list owner need not pin the superblock, so make a disconnected + * root a secondary one for shrink_dcache_for_umount() to find. + */ + if (__move_to_shrink_list(dentry, list) && + unlikely(IS_ROOT(dentry) && hlist_unhashed(&dentry->d_sib))) { + struct super_block *sb = dentry->d_sb; + + spin_lock(&sb->s_roots_lock); + hlist_add_head(&dentry->d_sib, &sb->s_roots); + spin_unlock(&sb->s_roots_lock); + } spin_unlock(&dentry->d_lock); } @@ -1612,21 +1618,25 @@ int path_has_submounts(const struct path *parent) } EXPORT_SYMBOL(path_has_submounts); +/* odd while d_set_mounted() runs, d_invalidate() waits on it */ +static __cacheline_aligned_in_smp DEFINE_SEQLOCK(d_set_mounted_lock); + /* * Called by mount code to set a mountpoint and check if the mountpoint is * reachable (e.g. NFS can unhash a directory dentry and then the complete * subtree can become unreachable). * * Only one of d_invalidate() and d_set_mounted() must succeed. For - * this reason take rename_lock and d_lock on dentry and ancestors. - * Likewise for dont_mount() which marks a dentry that is being removed - * under d_lock. + * this reason take rename_lock, d_set_mounted_lock and d_lock on dentry + * and ancestors. Likewise for dont_mount() which marks a dentry that + * is being removed under d_lock. */ int d_set_mounted(struct dentry *dentry) { struct dentry *p; int ret = -ENOENT; read_seqlock_excl(&rename_lock); + write_seqlock(&d_set_mounted_lock); for (p = dentry->d_parent; !IS_ROOT(p); p = p->d_parent) { /* Need exclusion wrt. d_invalidate() */ spin_lock(&p->d_lock); @@ -1644,8 +1654,9 @@ int d_set_mounted(struct dentry *dentry) ret = 0; } } - spin_unlock(&dentry->d_lock); + spin_unlock(&dentry->d_lock); out: + write_sequnlock(&d_set_mounted_lock); read_sequnlock_excl(&rename_lock); return ret; } @@ -1834,8 +1845,13 @@ static void do_one_tree(struct dentry *dentry) d_walk(dentry, dentry, umount_check); spin_lock(&dentry->d_lock); __d_drop(dentry); - /* A busy root survives the dput() below so don't leave it on ->s_roots. */ - if (unlikely(!hlist_unhashed(&dentry->d_sib))) + /* + * A busy root survives the dput() below so don't leave it on ->s_roots. + * An idle one stays until dentry_unlist() so that umount can wait for + * a racing eviction, see lock_for_kill(). + */ + if (unlikely(dentry->d_lockref.count > 1 && + !hlist_unhashed(&dentry->d_sib))) unlink_secondary_root(dentry); spin_unlock(&dentry->d_lock); dput(dentry); @@ -1898,6 +1914,7 @@ static enum d_walk_ret find_submount(void *_data, struct dentry *dentry) void d_invalidate(struct dentry *dentry) { bool had_submounts = false; + unsigned seq; spin_lock(&dentry->d_lock); if (d_unhashed(dentry)) { spin_unlock(&dentry->d_lock); @@ -1910,6 +1927,11 @@ void d_invalidate(struct dentry *dentry) if (!dentry->d_inode) return; + /* wait for a d_set_mounted() that saw us hashed to set its flag */ + do { + seq = read_seqbegin(&d_set_mounted_lock); + } while (read_seqretry(&d_set_mounted_lock, seq)); + shrink_dcache_parent(dentry); for (;;) { struct dentry *victim = NULL; @@ -3697,6 +3719,7 @@ void __init vfs_caches_init(void) inode_init(); files_init(); files_maxfiles_init(); + dquot_cache_init(); mnt_init(); bdev_cache_init(); chrdev_init(); diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 170feb75317ff8..32bf549e0adcf2 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -1362,7 +1362,7 @@ void debugfs_create_devm_seqfile(struct device *dev, const char *name, if (IS_ERR(parent)) return; - entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(dev, *entry); if (!entry) return; diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 968303afd6204f..e0b4ab96bc1e94 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -60,6 +60,7 @@ int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb, struct erofs_sb_info *sbi = EROFS_SB(sb); buf->mc = false; + buf->off = 0; if (in_metabox) { if (unlikely(!sbi->metabox_inode)) return -EFSCORRUPTED; @@ -374,10 +375,6 @@ static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length, static DEFINE_IOMAP_ITER_NEXT_END(erofs_iomap_next, erofs_iomap_begin, erofs_iomap_end); -static const struct iomap_ops erofs_iomap_ops = { - .iomap_next = erofs_iomap_next, -}; - int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) { @@ -385,9 +382,9 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP)) return -EOPNOTSUPP; return iomap_fiemap(inode, fieinfo, start, len, - &z_erofs_iomap_report_ops); + z_erofs_iomap_next_report); } - return iomap_fiemap(inode, fieinfo, start, len, &erofs_iomap_ops); + return iomap_fiemap(inode, fieinfo, start, len, erofs_iomap_next); } /* @@ -408,7 +405,7 @@ static int erofs_read_folio(struct file *file, struct folio *folio) }; trace_erofs_read_folio(iter_ctx.realinode, folio, true); - iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx); + iomap_read_folio(erofs_iomap_next, &read_ctx, &iter_ctx); if (need_iput) iput(iter_ctx.realinode); return 0; @@ -429,14 +426,14 @@ static void erofs_readahead(struct readahead_control *rac) trace_erofs_readahead(iter_ctx.realinode, readahead_index(rac), readahead_count(rac), true); - iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx); + iomap_readahead(erofs_iomap_next, &read_ctx, &iter_ctx); if (need_iput) iput(iter_ctx.realinode); } static sector_t erofs_bmap(struct address_space *mapping, sector_t block) { - return iomap_bmap(mapping, block, &erofs_iomap_ops); + return iomap_bmap(mapping, block, erofs_iomap_next); } static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) @@ -448,14 +445,14 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return 0; if (IS_ENABLED(CONFIG_FS_DAX) && IS_DAX(inode)) - return dax_iomap_rw(iocb, to, &erofs_iomap_ops); + return dax_iomap_rw(iocb, to, erofs_iomap_next); if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) { struct erofs_iomap_iter_ctx iter_ctx = { .realinode = inode, }; - return iomap_dio_rw(iocb, to, &erofs_iomap_ops, + return iomap_dio_rw(iocb, to, erofs_iomap_next, NULL, 0, &iter_ctx, 0); } return filemap_read(iocb, to, 0); @@ -474,7 +471,7 @@ const struct address_space_operations erofs_aops = { static vm_fault_t erofs_dax_huge_fault(struct vm_fault *vmf, unsigned int order) { - return dax_iomap_fault(vmf, order, NULL, NULL, &erofs_iomap_ops); + return dax_iomap_fault(vmf, order, NULL, NULL, erofs_iomap_next); } static vm_fault_t erofs_dax_fault(struct vm_fault *vmf) @@ -506,18 +503,18 @@ static int erofs_file_mmap_prepare(struct vm_area_desc *desc) loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode = file->f_mapping->host; - const struct iomap_ops *ops = &erofs_iomap_ops; + iomap_iter_next_fn next = erofs_iomap_next; if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) { if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP)) return generic_file_llseek(file, offset, whence); - ops = &z_erofs_iomap_report_ops; + next = z_erofs_iomap_next_report; } if (whence == SEEK_HOLE) - offset = iomap_seek_hole(inode, offset, ops); + offset = iomap_seek_hole(inode, offset, next); else if (whence == SEEK_DATA) - offset = iomap_seek_data(inode, offset, ops); + offset = iomap_seek_data(inode, offset, next); else return generic_file_llseek(file, offset, whence); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 8363c0c051f6b3..c16dfa752cf932 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -397,9 +397,10 @@ struct erofs_iomap_iter_ctx { struct inode *realinode; }; -extern const struct iomap_ops z_erofs_iomap_report_ops; extern const struct iomap_read_ops erofs_fileio_iomap_read_ops; +DECLARE_IOMAP_ITER_NEXT(z_erofs_iomap_next_report); + int erofs_setup_managed_cache(struct super_block *sb); #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE int erofs_read_meta_folio(struct file *file, struct folio *folio); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index ce05557bd99836..e92a7fa90ae34d 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -122,6 +122,17 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, return buffer; } +/* see the comment in erofs_fc_fill_super() */ +static bool erofs_is_stacked_file(struct file *file) +{ + struct inode *inode = file_inode(file); + struct super_block *sb = inode->i_sb; + + return (sb->s_op == &erofs_sops && !sb->s_bdev) || sb->s_stack_depth || + (IS_ENABLED(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) && + inode->i_fop == &erofs_ishare_fops); +} + static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, struct erofs_device_info *dif, erofs_off_t *pos) { @@ -161,6 +172,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, } else if (!S_ISREG(file_inode(file)->i_mode)) { fput(file); return -EINVAL; + } else if (erofs_is_stacked_file(file)) { + erofs_err(sb, "%s: file-backed devices cannot be on stacked fses", + dif->path); + fput(file); + return -EINVAL; } if (!dif->dax_dev && test_opt(&sbi->opt, DAX_ALWAYS)) { erofs_info(sb, "DAX unsupported by %s. Turning off DAX.", @@ -700,10 +716,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) * EROFS is the only fs supporting file-backed mounts for now. * It MUST change if another fs plans to support them, which * may also require adjusting FILESYSTEM_MAX_STACK_DEPTH. + * Files shared by inode_share may be read through a + * file-backed EROFS in the same domain, so treat them as + * stacked too. */ - inode = file_inode(sbi->dif0.file); - if ((inode->i_sb->s_op == &erofs_sops && - !inode->i_sb->s_bdev) || inode->i_sb->s_stack_depth) { + if (erofs_is_stacked_file(sbi->dif0.file)) { erofs_err(sb, "file-backed mounts cannot be applied to stacked fses"); return -ENOTBLK; } diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index f8981fc74246e1..e0d5987b742bb8 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -830,9 +830,4 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset, return 0; } -static DEFINE_IOMAP_ITER_NEXT(z_erofs_iomap_next_report, - z_erofs_iomap_begin_report); - -const struct iomap_ops z_erofs_iomap_report_ops = { - .iomap_next = z_erofs_iomap_next_report, -}; +DEFINE_IOMAP_ITER_NEXT(z_erofs_iomap_next_report, z_erofs_iomap_begin_report); diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 7a32c70bf2ad05..b959af04772c87 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -2144,10 +2144,17 @@ static int ep_send_events(struct eventpoll *ep, /* * Always short-circuit for fatal signals to allow threads to make a * timely exit without the chance of finding more events available and - * fetching repeatedly. + * fetching repeatedly. The wakeup that got us here may have been the + * only one for the events on ->rdllist, so pass it on to the next + * waiter, as ep_done_scan() would have. */ - if (fatal_signal_pending(current)) + if (fatal_signal_pending(current)) { + spin_lock_irq(&ep->lock); + if (!list_empty(&ep->rdllist)) + wake_up(&ep->wq); + spin_unlock_irq(&ep->lock); return -EINTR; + } init_poll_funcptr(&pt, NULL); diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 1386149916bbef..435bbef288b83b 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -828,7 +828,7 @@ static ssize_t exfat_fallback_buffered_write(struct kiocb *iocb, inode_dio_wait(file_inode(iocb->ki_filp)); - written = iomap_file_buffered_write(iocb, from, &exfat_write_iomap_ops, + written = iomap_file_buffered_write(iocb, from, exfat_write_iomap_next, NULL, NULL); if (written < 0) return written; @@ -850,7 +850,7 @@ static ssize_t exfat_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) { ssize_t ret; - ret = iomap_dio_rw(iocb, from, &exfat_write_iomap_ops, + ret = iomap_dio_rw(iocb, from, exfat_write_iomap_next, &exfat_write_dio_ops, 0, NULL, 0); if (ret == -ENOTBLK) ret = 0; @@ -921,7 +921,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) */ inode_dio_wait(inode); ret = iomap_file_buffered_write(iocb, iter, - &exfat_write_iomap_ops, NULL, NULL); + exfat_write_iomap_next, NULL, NULL); } if (ret != -EIOCBQUEUED && end > i_size_read(inode)) exfat_write_failed(inode); @@ -957,7 +957,7 @@ static ssize_t exfat_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) if (iocb->ki_flags & IOCB_DIRECT) { file_accessed(iocb->ki_filp); - ret = iomap_dio_rw(iocb, iter, &exfat_iomap_ops, NULL, 0, + ret = iomap_dio_rw(iocb, iter, exfat_iomap_next, NULL, 0, NULL, 0); } else { ret = generic_file_read_iter(iocb, iter); @@ -1016,7 +1016,7 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf) file_update_time(vmf->vma->vm_file); filemap_invalidate_lock_shared(inode->i_mapping); - ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL); + ret = iomap_page_mkwrite(vmf, exfat_iomap_next, NULL); filemap_invalidate_unlock_shared(inode->i_mapping); sb_end_pagefault(inode->i_sb); inode_unlock(inode); @@ -1073,12 +1073,12 @@ static loff_t exfat_file_llseek(struct file *file, loff_t offset, int whence) switch (whence) { case SEEK_HOLE: inode_lock_shared(inode); - offset = iomap_seek_hole(inode, offset, &exfat_iomap_ops); + offset = iomap_seek_hole(inode, offset, exfat_iomap_next); inode_unlock_shared(inode); break; case SEEK_DATA: inode_lock_shared(inode); - offset = iomap_seek_data(inode, offset, &exfat_iomap_ops); + offset = iomap_seek_data(inode, offset, exfat_iomap_next); inode_unlock_shared(inode); break; default: diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 5129df1e79b443..c1d15d4fc5e727 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -249,7 +249,7 @@ static int exfat_read_folio(struct file *file, struct folio *folio) .ops = &exfat_iomap_bio_read_ops, }; - iomap_read_folio(&exfat_iomap_ops, &ctx, NULL); + iomap_read_folio(exfat_iomap_next, &ctx, NULL); return 0; } @@ -271,7 +271,7 @@ static void exfat_readahead(struct readahead_control *rac) valid_size < pos + readahead_length(rac)) return; - iomap_readahead(&exfat_iomap_ops, &ctx, NULL); + iomap_readahead(exfat_iomap_next, &ctx, NULL); } static int exfat_writepages(struct address_space *mapping, @@ -294,7 +294,7 @@ static sector_t exfat_aop_bmap(struct address_space *mapping, sector_t block) sector_t blocknr; inode_lock_shared(mapping->host); - blocknr = iomap_bmap(mapping, block, &exfat_iomap_ops); + blocknr = iomap_bmap(mapping, block, exfat_iomap_next); inode_unlock_shared(mapping->host); return blocknr; } diff --git a/fs/exfat/iomap.c b/fs/exfat/iomap.c index e50ecbfbfbe0f8..4e6f3ed9dcc854 100644 --- a/fs/exfat/iomap.c +++ b/fs/exfat/iomap.c @@ -179,15 +179,11 @@ static int exfat_write_iomap_begin(struct inode *inode, loff_t offset, loff_t le * Zero the invalid bytes from valid_size to the end of the block * to prevent stale data from being exposed through the page cache. */ - return iomap_truncate_page(inode, valid_size, NULL, &exfat_iomap_ops, + return iomap_truncate_page(inode, valid_size, NULL, exfat_iomap_next, NULL, NULL); } -static DEFINE_IOMAP_ITER_NEXT(exfat_iomap_next, exfat_iomap_begin); - -const struct iomap_ops exfat_iomap_ops = { - .iomap_next = exfat_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(exfat_iomap_next, exfat_iomap_begin); #ifdef CONFIG_SWAP static int exfat_swap_iomap_begin(struct inode *inode, loff_t offset, @@ -204,10 +200,6 @@ static int exfat_swap_iomap_begin(struct inode *inode, loff_t offset, static DEFINE_IOMAP_ITER_NEXT(exfat_swap_iomap_next, exfat_swap_iomap_begin); - -static const struct iomap_ops exfat_swap_iomap_ops = { - .iomap_next = exfat_swap_iomap_next, -}; #endif /* @@ -245,12 +237,8 @@ static int exfat_write_iomap_end(struct inode *inode, loff_t pos, loff_t length, return written; } -static DEFINE_IOMAP_ITER_NEXT_END(exfat_write_iomap_next, - exfat_write_iomap_begin, exfat_write_iomap_end); - -const struct iomap_ops exfat_write_iomap_ops = { - .iomap_next = exfat_write_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(exfat_write_iomap_next, exfat_write_iomap_begin, + exfat_write_iomap_end); /* * exfat_writeback_range - Map folio during writeback @@ -327,7 +315,7 @@ int exfat_iomap_swap_activate(struct swap_info_struct *sis, { #ifdef CONFIG_SWAP return iomap_swapfile_activate(sis, file, span, - &exfat_swap_iomap_ops); + exfat_swap_iomap_next); #else return -EIO; #endif diff --git a/fs/exfat/iomap.h b/fs/exfat/iomap.h index fd8a913f779460..519132367b65ea 100644 --- a/fs/exfat/iomap.h +++ b/fs/exfat/iomap.h @@ -6,9 +6,11 @@ #ifndef _LINUX_EXFAT_IOMAP_H #define _LINUX_EXFAT_IOMAP_H +#include + extern const struct iomap_dio_ops exfat_write_dio_ops; -extern const struct iomap_ops exfat_iomap_ops; -extern const struct iomap_ops exfat_write_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(exfat_iomap_next); +DECLARE_IOMAP_ITER_NEXT(exfat_write_iomap_next); extern const struct iomap_writeback_ops exfat_writeback_ops; extern const struct iomap_read_ops exfat_iomap_bio_read_ops; diff --git a/fs/exfat/nls.c b/fs/exfat/nls.c index 055447edcf9a69..47aa187c54cccb 100644 --- a/fs/exfat/nls.c +++ b/fs/exfat/nls.c @@ -655,7 +655,7 @@ static int exfat_load_upcase_table(struct super_block *sb, unsigned char skip = false; unsigned short *upcase_table; - upcase_table = kvcalloc(UTBL_COUNT, sizeof(unsigned short), GFP_KERNEL); + upcase_table = kvzalloc_objs(unsigned short, UTBL_COUNT); if (!upcase_table) return -ENOMEM; @@ -707,7 +707,7 @@ static int exfat_load_default_upcase_table(struct super_block *sb) unsigned short uni = 0, *upcase_table; unsigned int index = 0; - upcase_table = kvcalloc(UTBL_COUNT, sizeof(unsigned short), GFP_KERNEL); + upcase_table = kvzalloc_objs(unsigned short, UTBL_COUNT); if (!upcase_table) return -ENOMEM; diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c index e17bbc7598c143..5de32c221a83b3 100644 --- a/fs/ext2/dir.c +++ b/fs/ext2/dir.c @@ -442,6 +442,9 @@ static int ext2_handle_dirsync(struct inode *dir) { int err; + if (!IS_DIRSYNC(dir)) + return 0; + err = filemap_write_and_wait(dir->i_mapping); if (!err) err = sync_inode_metadata(dir, 1); diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 7bdada93dd060e..b46649c510a5ae 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -18,6 +18,7 @@ #include #include #include +#include /* XXX Here for now... not interested in restructing headers JUST now */ @@ -782,7 +783,7 @@ extern const struct file_operations ext2_file_operations; /* inode.c */ extern void ext2_set_file_ops(struct inode *inode); extern const struct address_space_operations ext2_aops; -extern const struct iomap_ops ext2_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(ext2_iomap_next); /* namei.c */ extern const struct inode_operations ext2_dir_inode_operations; diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 67fe423c3828d8..f4607a039b0b61 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -55,7 +55,7 @@ static ssize_t ext2_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) trace_ext2_dio_read_begin(iocb, to, 0); inode_lock_shared(inode); - ret = iomap_dio_rw(iocb, to, &ext2_iomap_ops, NULL, 0, NULL, 0); + ret = iomap_dio_rw(iocb, to, ext2_iomap_next, NULL, 0, NULL, 0); inode_unlock_shared(inode); trace_ext2_dio_read_end(iocb, to, ret); @@ -119,7 +119,7 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) (!IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(from), blocksize))) flags |= IOMAP_DIO_FORCE_WAIT; - ret = iomap_dio_rw(iocb, from, &ext2_iomap_ops, &ext2_dio_write_ops, + ret = iomap_dio_rw(iocb, from, ext2_iomap_next, &ext2_dio_write_ops, flags, NULL, 0); /* ENOTBLK is magic return value for fallback to buffered-io */ @@ -145,7 +145,8 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) pos = iocb->ki_pos; status = generic_perform_write(iocb, from); if (unlikely(status < 0)) { - ret = status; + if (!ret) + ret = status; goto out_unlock; } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 12ac4cfe150038..9a5416fcd8ab1d 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -58,8 +58,10 @@ void ext2_write_failed(struct address_space *mapping, loff_t to) struct inode *inode = mapping->host; if (to > inode->i_size) { + filemap_invalidate_lock(mapping); truncate_pagecache(inode, inode->i_size); ext2_truncate_blocks(inode, inode->i_size); + filemap_invalidate_unlock(mapping); } } @@ -91,8 +93,6 @@ void ext2_evict_inode(struct inode * inode) if (inode->i_blocks) ext2_truncate_blocks(inode, 0); ext2_xattr_delete_inode(inode); - } else { - mmb_sync(&EXT2_I(inode)->i_metadata_bhs); } mmb_invalidate(&EXT2_I(inode)->i_metadata_bhs); clear_inode(inode); @@ -805,6 +805,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, (first_block << blkbits) < i_size_read(inode)) create = 0; + ret = ext2_get_blocks(inode, first_block, max_blocks, + &bno, &new, &boundary, create); + if (ret < 0) + return ret; + + iomap->flags = 0; /* * Writes that span EOF might trigger an IO size update on completion, * so consider them to be dirty for the purposes of O_DSYNC even if @@ -812,13 +818,6 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, */ if ((flags & IOMAP_WRITE) && offset + length > i_size_read(inode)) iomap->flags |= IOMAP_F_DIRTY; - - ret = ext2_get_blocks(inode, first_block, max_blocks, - &bno, &new, &boundary, create); - if (ret < 0) - return ret; - - iomap->flags = 0; iomap->offset = (u64)first_block << blkbits; iomap->bdev = inode->i_sb->s_bdev; @@ -862,12 +861,7 @@ ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length, return 0; } -static DEFINE_IOMAP_ITER_NEXT_END(ext2_iomap_next, ext2_iomap_begin, - ext2_iomap_end); - -const struct iomap_ops ext2_iomap_ops = { - .iomap_next = ext2_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ext2_iomap_next, ext2_iomap_begin, ext2_iomap_end); int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) @@ -886,7 +880,7 @@ int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (i_size == 0) i_size = 1; len = min_t(u64, len, i_size); - ret = iomap_fiemap(inode, fieinfo, start, len, &ext2_iomap_ops); + ret = iomap_fiemap(inode, fieinfo, start, len, ext2_iomap_next); inode_unlock(inode); return ret; @@ -1236,9 +1230,7 @@ static void ext2_truncate_blocks(struct inode *inode, loff_t offset) if (ext2_inode_is_fast_symlink(inode)) return; - filemap_invalidate_lock(inode->i_mapping); __ext2_truncate_blocks(inode, offset); - filemap_invalidate_unlock(inode->i_mapping); } static int ext2_setsize(struct inode *inode, loff_t newsize) @@ -1272,46 +1264,59 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) return 0; } -static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, - struct buffer_head **p) +/* + * Find the inode table block that holds inode @ino and the offset of the + * inode in that block. + */ +static int ext2_inode_block(struct super_block *sb, ino_t ino, + unsigned long *block, unsigned long *offset) { - struct buffer_head * bh; unsigned long block_group; - unsigned long block; - unsigned long offset; struct ext2_group_desc * gdp; - *p = NULL; if ((ino != EXT2_ROOT_INO && ino < EXT2_FIRST_INO(sb)) || - ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) - goto Einval; + ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) { + ext2_error(sb, __func__, "bad inode number: %lu", + (unsigned long) ino); + return -EINVAL; + } block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb); gdp = ext2_get_group_desc(sb, block_group, NULL); if (!gdp) - goto Egdp; + return -EIO; /* * Figure out the offset within the block group inode table */ - offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb); - block = le32_to_cpu(gdp->bg_inode_table) + - (offset >> EXT2_BLOCK_SIZE_BITS(sb)); + *offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb); + *block = le32_to_cpu(gdp->bg_inode_table) + + (*offset >> EXT2_BLOCK_SIZE_BITS(sb)); + *offset &= (EXT2_BLOCK_SIZE(sb) - 1); + return 0; +} + +static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, + struct buffer_head **p) +{ + struct buffer_head *bh; + unsigned long block; + unsigned long offset; + int err; + + *p = NULL; + err = ext2_inode_block(sb, ino, &block, &offset); + if (err) + return ERR_PTR(err); if (!(bh = sb_bread(sb, block))) goto Eio; *p = bh; - offset &= (EXT2_BLOCK_SIZE(sb) - 1); return (struct ext2_inode *) (bh->b_data + offset); -Einval: - ext2_error(sb, "ext2_get_inode", "bad inode number: %lu", - (unsigned long) ino); - return ERR_PTR(-EINVAL); Eio: ext2_error(sb, "ext2_get_inode", "unable to read inode block - inode=%lu, block=%lu", (unsigned long) ino, block); -Egdp: return ERR_PTR(-EIO); } @@ -1573,19 +1578,22 @@ int ext2_write_inode(struct inode *inode, struct writeback_control *wbc) int ext2_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc) { struct buffer_head *bh; - struct ext2_inode *raw_inode = ext2_get_inode(inode->i_sb, inode->i_ino, - &bh); + unsigned long block, offset; int err = 0; - if (IS_ERR(raw_inode)) + if (ext2_inode_block(inode->i_sb, inode->i_ino, &block, &offset)) return -EIO; err = mmb_sync(&EXT2_I(inode)->i_metadata_bhs); if (err) { ext2_error(inode->i_sb, __func__, "Error syncing inode metadata ino=%lu\n", (unsigned long)inode->i_ino); - goto out; + return err; } + /* A block that isn't cached is neither dirty nor under writeback. */ + bh = sb_find_get_block_nonatomic(inode->i_sb, block); + if (!bh) + return 0; sync_dirty_buffer(bh); if (buffer_write_io_error(bh)) { ext2_error(inode->i_sb, __func__, @@ -1593,7 +1601,6 @@ int ext2_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc) (unsigned long)inode->i_ino); err = -EIO; } -out: brelse(bh); return err; } diff --git a/fs/ext2/super.c b/fs/ext2/super.c index fb217ef2d69f07..54a6c26d0388ae 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -883,17 +883,18 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc) __le32 features; int err; - sbi = kzalloc_obj(*sbi); - if (!sbi) + sb->s_fs_info = kzalloc_obj(*sbi); + if (!sb->s_fs_info) return -ENOMEM; + sbi = EXT2_SB(sb); sbi->s_blockgroup_lock = kzalloc_obj(struct blockgroup_lock); if (!sbi->s_blockgroup_lock) { - kfree(sbi); + kfree(sb->s_fs_info); + sb->s_fs_info = NULL; return -ENOMEM; } - sb->s_fs_info = sbi; sbi->s_sb_block = sb_block; guard(spinlock_init)(&EXT2_SB(sb)->s_lock); @@ -1106,7 +1107,7 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc) goto failed_mount; } bgl_lock_init(sbi->s_blockgroup_lock); - sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL); + sbi->s_debts = kzalloc_objs(*sbi->s_debts, sbi->s_groups_count); if (!sbi->s_debts) { ret = -ENOMEM; ext2_msg(sb, KERN_ERR, "error: not enough memory"); diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index f38fec3167fbd0..bf0325ecbec7a4 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -4105,10 +4106,11 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) io_end->flag &= ~EXT4_IO_END_UNWRITTEN; } -extern const struct iomap_ops ext4_iomap_ops; -extern const struct iomap_ops ext4_iomap_report_ops; -extern const struct iomap_ops ext4_iomap_buffered_write_ops; -extern const struct iomap_ops ext4_iomap_buffered_da_write_ops; +DECLARE_IOMAP_ITER_NEXT(ext4_iomap_next); +DECLARE_IOMAP_ITER_NEXT(ext4_iomap_next_report); +DECLARE_IOMAP_ITER_NEXT(ext4_iomap_buffered_write_next); +DECLARE_IOMAP_ITER_NEXT(ext4_iomap_buffered_da_write_next); + extern const struct iomap_write_ops ext4_iomap_write_ops; int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index ad0d80e33f6090..cd35e88bc372b1 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -5315,10 +5315,6 @@ static int ext4_iomap_xattr_begin(struct inode *inode, loff_t offset, static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_xattr_next, ext4_iomap_xattr_begin); -static const struct iomap_ops ext4_iomap_xattr_ops = { - .iomap_next = ext4_iomap_xattr_next, -}; - static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len) { u64 maxbytes = ext4_get_maxbytes(inode); @@ -5361,10 +5357,10 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR; error = iomap_fiemap(inode, fieinfo, start, len, - &ext4_iomap_xattr_ops); + ext4_iomap_xattr_next); } else { error = iomap_fiemap(inode, fieinfo, start, len, - &ext4_iomap_report_ops); + ext4_iomap_next_report); } unlock: inode_unlock_shared(inode); diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 50d3c92709c8b8..ad8985c529c61d 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -93,7 +93,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = iomap_dio_read_simple(iocb, to, ext4_iomap_begin); if (ret == -ENOTBLK) - ret = iomap_dio_rw(iocb, to, &ext4_iomap_ops, NULL, 0, NULL, 0); + ret = iomap_dio_rw(iocb, to, ext4_iomap_next, NULL, 0, NULL, 0); inode_unlock_shared(inode); file_accessed(iocb->ki_filp); @@ -121,7 +121,7 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) /* Fallback to buffered IO in case we cannot support DAX */ return generic_file_read_iter(iocb, to); } - ret = dax_iomap_rw(iocb, to, &ext4_iomap_ops); + ret = dax_iomap_rw(iocb, to, ext4_iomap_next); inode_unlock_shared(inode); file_accessed(iocb->ki_filp); @@ -334,14 +334,14 @@ static ssize_t ext4_iomap_buffered_write(struct kiocb *iocb, struct iov_iter *from) { struct inode *inode = file_inode(iocb->ki_filp); - const struct iomap_ops *iomap_ops; + iomap_iter_next_fn next; if (test_opt(inode->i_sb, DELALLOC) && !ext4_nonda_switch(inode->i_sb)) - iomap_ops = &ext4_iomap_buffered_da_write_ops; + next = ext4_iomap_buffered_da_write_next; else - iomap_ops = &ext4_iomap_buffered_write_ops; + next = ext4_iomap_buffered_write_next; - return iomap_file_buffered_write(iocb, from, iomap_ops, + return iomap_file_buffered_write(iocb, from, next, &ext4_iomap_write_ops, NULL); } @@ -663,7 +663,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) goto out; } - ret = iomap_dio_rw(iocb, from, &ext4_iomap_ops, &ext4_dio_write_ops, + ret = iomap_dio_rw(iocb, from, ext4_iomap_next, &ext4_dio_write_ops, dio_flags, NULL, 0); if (ret == -ENOTBLK) ret = 0; @@ -767,7 +767,7 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from) ext4_journal_stop(handle); } - ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops); + ret = dax_iomap_rw(iocb, from, ext4_iomap_next); if (extend) { ret = ext4_handle_inode_extension(inode, offset, ret, count); @@ -855,7 +855,7 @@ static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order) } else { filemap_invalidate_lock_shared(mapping); } - result = dax_iomap_fault(vmf, order, &pfn, &error, &ext4_iomap_ops); + result = dax_iomap_fault(vmf, order, &pfn, &error, ext4_iomap_next); if (write) { ext4_journal_stop(handle); @@ -1034,13 +1034,13 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence) case SEEK_HOLE: inode_lock_shared(inode); offset = iomap_seek_hole(inode, offset, - &ext4_iomap_report_ops); + ext4_iomap_next_report); inode_unlock_shared(inode); break; case SEEK_DATA: inode_lock_shared(inode); offset = iomap_seek_data(inode, offset, - &ext4_iomap_report_ops); + ext4_iomap_next_report); inode_unlock_shared(inode); break; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 10cd85d4c721b2..e3129353d4edbb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -250,8 +250,6 @@ void ext4_evict_inode(struct inode *inode) if (EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL) ext4_evict_ea_inode(inode); if (inode->i_nlink) { - struct mapping_metadata_bhs *mmb; - /* * If there's dirty page will lead to data loss, user * could see stale data. @@ -261,9 +259,6 @@ void ext4_evict_inode(struct inode *inode) ext4_warning_inode(inode, "data will be lost"); truncate_inode_pages_final(&inode->i_data); - mmb = ext4_i_metadata_bhs(inode); - if (mmb) - mmb_sync(mmb); goto no_delete; } @@ -3519,7 +3514,7 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block) filemap_write_and_wait(mapping); } - ret = iomap_bmap(mapping, block, &ext4_iomap_ops); + ret = iomap_bmap(mapping, block, ext4_iomap_next); out: inode_unlock_shared(inode); @@ -3994,11 +3989,7 @@ int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return 0; } -static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next, ext4_iomap_begin); - -const struct iomap_ops ext4_iomap_ops = { - .iomap_next = ext4_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next, ext4_iomap_begin); static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, @@ -4051,11 +4042,7 @@ static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, return 0; } -static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next_report, ext4_iomap_begin_report); - -const struct iomap_ops ext4_iomap_report_ops = { - .iomap_next = ext4_iomap_next_report, -}; +DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next_report, ext4_iomap_begin_report); static int ext4_iomap_map_blocks(struct inode *inode, loff_t offset, loff_t length, struct ext4_map_blocks *map, @@ -4260,45 +4247,29 @@ static int ext4_iomap_zero_begin(struct inode *inode, static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_zero_next, ext4_iomap_zero_begin); -static const struct iomap_ops ext4_iomap_zero_ops = { - .iomap_next = ext4_iomap_zero_next, -}; - /* * Since we always allocate unwritten extents, there is no need for * iomap_end to clean up allocated blocks on a short write. */ -static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_buffered_write_next, - ext4_iomap_buffered_write_begin); - -const struct iomap_ops ext4_iomap_buffered_write_ops = { - .iomap_next = ext4_iomap_buffered_write_next, -}; +DEFINE_IOMAP_ITER_NEXT(ext4_iomap_buffered_write_next, + ext4_iomap_buffered_write_begin); -static DEFINE_IOMAP_ITER_NEXT_END(ext4_iomap_buffered_da_write_next, - ext4_iomap_buffered_da_write_begin, - ext4_iomap_buffered_da_write_end); - -const struct iomap_ops ext4_iomap_buffered_da_write_ops = { - .iomap_next = ext4_iomap_buffered_da_write_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ext4_iomap_buffered_da_write_next, + ext4_iomap_buffered_da_write_begin, + ext4_iomap_buffered_da_write_end); static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_buffered_read_next, ext4_iomap_buffered_read_begin); -static const struct iomap_ops ext4_iomap_buffered_read_ops = { - .iomap_next = ext4_iomap_buffered_read_next, -}; - static int ext4_iomap_read_folio(struct file *file, struct folio *folio) { - iomap_bio_read_folio(folio, &ext4_iomap_buffered_read_ops); + iomap_bio_read_folio(folio, ext4_iomap_buffered_read_next); return 0; } static void ext4_iomap_readahead(struct readahead_control *rac) { - iomap_bio_readahead(rac, &ext4_iomap_buffered_read_ops); + iomap_bio_readahead(rac, ext4_iomap_buffered_read_next); } @@ -4561,7 +4532,7 @@ static int ext4_iomap_swap_activate(struct swap_info_struct *sis, struct file *file, sector_t *span) { return iomap_swapfile_activate(sis, file, span, - &ext4_iomap_report_ops); + ext4_iomap_next_report); } static const struct address_space_operations ext4_aops = { @@ -4827,7 +4798,7 @@ static int ext4_block_iomap_zero_range(struct inode *inode, loff_t from, !rwsem_is_locked(&inode->i_mapping->invalidate_lock)); ret = iomap_zero_range(inode, from, length, did_zero, - &ext4_iomap_zero_ops, &ext4_iomap_write_ops, + ext4_iomap_zero_next, &ext4_iomap_write_ops, NULL); if (ret) return ret; @@ -4866,7 +4837,7 @@ static int ext4_block_zero_range(struct inode *inode, if (IS_DAX(inode)) { return dax_zero_range(inode, from, length, did_zero, - &ext4_iomap_ops); + ext4_iomap_next); } else if (ext4_should_journal_data(inode)) { return ext4_block_journalled_zero_range(inode, from, length, did_zero); @@ -5876,7 +5847,8 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) /* * ext4_get_inode_loc_noio() is a best-effort variant of ext4_get_inode_loc(). * It looks up the inode table block in the buffer cache and returns -EAGAIN if - * the block is not present or not uptodate, without starting any I/O. + * the block is not present or not uptodate, without starting any I/O. It may + * sleep on the folio lock of the block. */ int ext4_get_inode_loc_noio(struct inode *inode, struct ext4_iloc *iloc) { @@ -5912,7 +5884,7 @@ int ext4_get_inode_loc_noio(struct inode *inode, struct ext4_iloc *iloc) } block += inode_offset / inodes_per_block; - bh = sb_find_get_block(sb, block); + bh = sb_find_get_block_nonatomic(sb, block); if (!bh) return -EAGAIN; if (!ext4_buffer_uptodate(bh)) { @@ -6820,22 +6792,24 @@ int ext4_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc) if (WARN_ON_ONCE(EXT4_SB(inode->i_sb)->s_journal)) return -EFSCORRUPTED; - err = __ext4_get_inode_loc_noinmem(inode, &iloc); - if (err) - return err; mmb = READ_ONCE(EXT4_I(inode)->i_metadata_bhs); if (mmb) { err = mmb_sync(mmb); if (err) - goto out; + return err; } + /* A block that isn't cached is neither dirty nor under writeback. */ + err = ext4_get_inode_loc_noio(inode, &iloc); + if (err == -EAGAIN) + return 0; + if (err) + return err; sync_dirty_buffer(iloc.bh); if (buffer_write_io_error(iloc.bh)) { ext4_error_inode_block(inode, iloc.bh->b_blocknr, EIO, "IO error syncing inode"); err = -EIO; } -out: brelse(iloc.bh); return err; } @@ -7829,18 +7803,18 @@ static int ext4_block_page_mkwrite(struct inode *inode, struct folio *folio, static vm_fault_t ext4_iomap_page_mkwrite(struct vm_fault *vmf) { struct inode *inode = file_inode(vmf->vma->vm_file); - const struct iomap_ops *iomap_ops; + iomap_iter_next_fn next; /* * ext4_nonda_switch() could writeback this folio, so have to * call it before lock folio. */ if (test_opt(inode->i_sb, DELALLOC) && !ext4_nonda_switch(inode->i_sb)) - iomap_ops = &ext4_iomap_buffered_da_write_ops; + next = ext4_iomap_buffered_da_write_next; else - iomap_ops = &ext4_iomap_buffered_write_ops; + next = ext4_iomap_buffered_write_next; - return iomap_page_mkwrite(vmf, iomap_ops, NULL); + return iomap_page_mkwrite(vmf, next, NULL); } vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index 5e3ad8393cf833..041ab212c3a6c3 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -265,8 +265,7 @@ static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned int flexbg_size, if (flex_gd->groups == NULL) goto out2; - flex_gd->bg_flags = kmalloc_array(flex_gd->resize_bg, sizeof(__u16), - GFP_NOFS); + flex_gd->bg_flags = kmalloc_objs(__u16, flex_gd->resize_bg, GFP_NOFS); if (flex_gd->bg_flags == NULL) goto out1; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 28fd8afff5d44f..7c5aa95b7da850 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -4853,8 +4853,4 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return 0; } -static DEFINE_IOMAP_ITER_NEXT(f2fs_iomap_next, f2fs_iomap_begin); - -const struct iomap_ops f2fs_iomap_ops = { - .iomap_next = f2fs_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(f2fs_iomap_next, f2fs_iomap_begin); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f7423b3f6e4aac..6941891d7cae47 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -4397,7 +4398,7 @@ int f2fs_init_post_read_processing(void); void f2fs_destroy_post_read_processing(void); int f2fs_init_wq(struct f2fs_sb_info *sbi); void f2fs_destroy_wq(struct f2fs_sb_info *sbi); -extern const struct iomap_ops f2fs_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(f2fs_iomap_next); /* * gc.c diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index e2c0f508331338..cf095978fad45e 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -5245,7 +5245,7 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) * F2FS_DIO_READ counter will be decremented correctly in all cases. */ inc_cache_count(sbi, F2FS_DIO_READ); - dio = __iomap_dio_rw(iocb, to, &f2fs_iomap_ops, + dio = __iomap_dio_rw(iocb, to, f2fs_iomap_next, &f2fs_iomap_dio_read_ops, 0, NULL, 0); if (IS_ERR_OR_NULL(dio)) { ret = PTR_ERR_OR_ZERO(dio); @@ -5584,7 +5584,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from, dio_flags = 0; if (pos + count > inode->i_size) dio_flags |= IOMAP_DIO_FORCE_WAIT; - dio = __iomap_dio_rw(iocb, from, &f2fs_iomap_ops, + dio = __iomap_dio_rw(iocb, from, f2fs_iomap_next, &f2fs_iomap_dio_write_ops, dio_flags, iocb, 0); if (IS_ERR_OR_NULL(dio)) { ret = PTR_ERR_OR_ZERO(dio); diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 35bdb62944a2eb..0cebcaf8242643 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -963,6 +963,16 @@ int fat_dir_empty(struct inode *dir) } EXPORT_SYMBOL_GPL(fat_dir_empty); +void fat_dir_drop_nlink(struct inode *dir) +{ + if (dir->i_nlink >= 3) + drop_nlink(dir); + else + fat_fs_error(dir->i_sb, "parent dir link count too low (%u)", + dir->i_nlink); +} +EXPORT_SYMBOL_GPL(fat_dir_drop_nlink); + /* * fat_subdirs counts the number of sub-directories of dir. It can be run * on directories being created. diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 76978a268410ae..a8a3ca4f465bf5 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -332,6 +332,7 @@ extern const struct file_operations fat_dir_operations; extern int fat_search_long(struct inode *inode, const unsigned char *name, int name_len, struct fat_slot_info *sinfo); extern int fat_dir_empty(struct inode *dir); +void fat_dir_drop_nlink(struct inode *dir); extern int fat_subdirs(struct inode *dir); extern int fat_scan(struct inode *dir, const unsigned char *name, struct fat_slot_info *sinfo); diff --git a/fs/fat/file.c b/fs/fat/file.c index d4f1b360b97436..70583e791bdc7d 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -217,13 +217,62 @@ const struct file_operations fat_file_operations = { .setlease = generic_setlease, }; +static int fat_preallocate(struct inode *inode, loff_t new_size) +{ + int nr_cluster; /* Number of clusters to be allocated */ + loff_t mm_bytes; /* Number of bytes to be allocated for file */ + loff_t ondisksize; /* block aligned on-disk size in bytes*/ + struct super_block *sb = inode->i_sb; + struct msdos_sb_info *sbi = MSDOS_SB(sb); + + ondisksize = inode->i_blocks << 9; + if (new_size <= ondisksize) + return 0; + + /* First compute the number of clusters to be allocated */ + mm_bytes = new_size - ondisksize; + nr_cluster = (mm_bytes + (sbi->cluster_size - 1)) >> + sbi->cluster_bits; + + /* Allocate the clusters. We are not zeroing them out */ + return fat_add_clusters(inode, nr_cluster); +} + +static int fat_cont_expand_simple(struct inode *inode, loff_t size) +{ + struct address_space *mapping = inode->i_mapping; + const struct address_space_operations *aops = mapping->a_ops; + struct folio *folio; + void *fsdata = NULL; + int err; + + err = aops->write_begin(NULL, mapping, size, 0, &folio, &fsdata); + if (err) + goto out; + + err = aops->write_end(NULL, mapping, size, 0, 0, folio, fsdata); + +out: + return err; +} + static int fat_cont_expand(struct inode *inode, loff_t size) { struct address_space *mapping = inode->i_mapping; loff_t start = inode->i_size, count = size - inode->i_size; int err; - err = generic_cont_expand_simple(inode, size); + /* + * Preallocating space here is more efficient than during + * fat_cont_expand_simple() because of batching. + */ + err = inode_newsize_ok(inode, size); + if (err) + goto out; + err = fat_preallocate(inode, size); + if (err) + goto out; + err = fat_cont_expand_simple(inode, size); if (err) goto out; @@ -263,12 +312,7 @@ static int fat_cont_expand(struct inode *inode, loff_t size) static long fat_fallocate(struct file *file, int mode, loff_t offset, loff_t len) { - int nr_cluster; /* Number of clusters to be allocated */ - loff_t mm_bytes; /* Number of bytes to be allocated for file */ - loff_t ondisksize; /* block aligned on-disk size in bytes*/ struct inode *inode = file->f_mapping->host; - struct super_block *sb = inode->i_sb; - struct msdos_sb_info *sbi = MSDOS_SB(sb); int err = 0; /* No support for hole punch or other fallocate flags. */ @@ -281,19 +325,7 @@ static long fat_fallocate(struct file *file, int mode, inode_lock(inode); if (mode & FALLOC_FL_KEEP_SIZE) { - ondisksize = inode->i_blocks << 9; - if ((offset + len) <= ondisksize) - goto error; - - /* First compute the number of clusters to be allocated */ - mm_bytes = offset + len - ondisksize; - nr_cluster = (mm_bytes + (sbi->cluster_size - 1)) >> - sbi->cluster_bits; - - /* Allocate the clusters. We are not zeroing them out */ - err = fat_add_clusters(inode, nr_cluster); - if (err) - goto error; + err = fat_preallocate(inode, offset + len); } else { if ((offset + len) <= i_size_read(inode)) goto error; diff --git a/fs/fat/inode.c b/fs/fat/inode.c index d85c8fbdcca462..642e690632d839 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -217,7 +217,9 @@ static void fat_write_failed(struct address_space *mapping, loff_t to) if (to > inode->i_size) { truncate_pagecache(inode, inode->i_size); + down_write(&MSDOS_I(inode)->truncate_lock); fat_truncate_blocks(inode, inode->i_size); + up_write(&MSDOS_I(inode)->truncate_lock); } } @@ -693,7 +695,6 @@ static void fat_evict_inode(struct inode *inode) inode->i_size = 0; fat_truncate_blocks(inode, 0); } else { - mmb_sync(&MSDOS_I(inode)->i_metadata_bhs); fat_free_eofblocks(inode); } diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index c7500c2859e005..5a43d042eb01f5 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -333,12 +333,7 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) err = fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - if (dir->i_nlink >= 3) - drop_nlink(dir); - else { - fat_fs_error(sb, "parent dir link count too low (%u)", - dir->i_nlink); - } + fat_dir_drop_nlink(dir); clear_nlink(inode); fat_detach(inode); @@ -565,6 +560,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, (void)sync_inode_metadata(old_dir, 1); if (new_inode) { + if (is_dir && old_dir == new_dir) + fat_dir_drop_nlink(old_dir); drop_nlink(new_inode); if (is_dir) drop_nlink(new_inode); diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index ff7652bf0410b7..791f2d7b850926 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -809,12 +809,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry) err = fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - if (dir->i_nlink >= 3) - drop_nlink(dir); - else { - fat_fs_error(sb, "parent dir link count too low (%u)", - dir->i_nlink); - } + fat_dir_drop_nlink(dir); clear_nlink(inode); fat_truncate_time(inode, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME); @@ -1011,6 +1006,8 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, vfat_update_dir_metadata(old_dir, &ts); if (new_inode) { + if (is_dir && old_dir == new_dir) + fat_dir_drop_nlink(old_dir); drop_nlink(new_inode); if (is_dir) drop_nlink(new_inode); diff --git a/fs/file.c b/fs/file.c index 4cd40dfa6129fa..fd08d34874ac68 100644 --- a/fs/file.c +++ b/fs/file.c @@ -1387,14 +1387,18 @@ static inline bool file_needs_f_pos_lock(struct file *file) bool file_seek_cur_needs_f_lock(struct file *file) { - if (!(file->f_mode & FMODE_ATOMIC_POS) && !file->f_op->iterate_shared) - return false; - /* + * Files that go through f_pos_lock when they are shared, i.e. + * FMODE_ATOMIC_POS files and directories, don't need f_lock for a + * SEEK_CUR. Everything else does, since nothing else serializes + * the f_pos update. + * * Note that we are not guaranteed to be called after fdget_pos() on * this file obj, in which case the caller is expected to provide the * appropriate locking. */ + if ((file->f_mode & FMODE_ATOMIC_POS) || file->f_op->iterate_shared) + return false; return true; } diff --git a/fs/fuse/args.h b/fs/fuse/args.h index 5173264a1261b3..36ef0c6d599982 100644 --- a/fs/fuse/args.h +++ b/fs/fuse/args.h @@ -36,7 +36,6 @@ struct fuse_args { bool user_pages:1; bool out_argvar:1; bool page_zeroing:1; - bool page_replace:1; bool may_block:1; bool is_ext:1; bool is_pinned:1; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index cae217ff89ba64..e20a5ae6fecc16 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -656,10 +656,6 @@ static int fuse_iomap_end(struct inode *inode, loff_t pos, loff_t length, static DEFINE_IOMAP_ITER_NEXT_END(fuse_iomap_next, fuse_iomap_begin, fuse_iomap_end); -static const struct iomap_ops fuse_iomap_ops = { - .iomap_next = fuse_iomap_next, -}; - static void fuse_wait_dax_page(struct inode *inode) { filemap_invalidate_unlock(inode->i_mapping); @@ -687,7 +683,7 @@ ssize_t fuse_vdax_read_iter(struct kiocb *iocb, struct iov_iter *to) inode_lock_shared(inode); } - ret = dax_iomap_rw(iocb, to, &fuse_iomap_ops); + ret = dax_iomap_rw(iocb, to, fuse_iomap_next); inode_unlock_shared(inode); /* TODO file_accessed(iocb->f_filp) */ @@ -742,7 +738,7 @@ ssize_t fuse_vdax_write_iter(struct kiocb *iocb, struct iov_iter *from) if (file_extending_write(iocb, from)) ret = fuse_dax_direct_write(iocb, from); else - ret = dax_iomap_rw(iocb, from, &fuse_iomap_ops); + ret = dax_iomap_rw(iocb, from, fuse_iomap_next); out: inode_unlock(inode); @@ -777,7 +773,7 @@ static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order, * to populate page cache or access memory we are trying to free. */ filemap_invalidate_lock_shared(inode->i_mapping); - ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops); + ret = dax_iomap_fault(vmf, order, &pfn, &error, fuse_iomap_next); if ((ret & VM_FAULT_ERROR) && error == -EAGAIN) { error = 0; retry = true; diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 3641abb90d6bb3..a5c08a00cf83b0 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1099,128 +1099,6 @@ static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) return ncpy; } -static int fuse_check_folio(struct folio *folio) -{ - if (folio_mapped(folio) || - folio->mapping != NULL || - (folio->flags.f & PAGE_FLAGS_CHECK_AT_PREP & - ~(1 << PG_locked | - 1 << PG_referenced | - 1 << PG_lru | - 1 << PG_active | - 1 << PG_workingset | - 1 << PG_reclaim | - 1 << PG_waiters | - LRU_GEN_MASK | LRU_REFS_MASK))) { - dump_page(&folio->page, "fuse: trying to steal weird page"); - return 1; - } - return 0; -} - -/* - * Attempt to steal a page from the splice() pipe and move it into the - * pagecache. If successful, the pointer in @pagep will be updated. The - * folio that was originally in @pagep will lose a reference and the new - * folio returned in @pagep will carry a reference. - */ -static int fuse_try_move_folio(struct fuse_copy_state *cs, struct folio **foliop) -{ - int err; - struct folio *oldfolio = *foliop; - struct folio *newfolio; - struct pipe_buffer *buf = cs->pipebufs; - - folio_get(oldfolio); - err = unlock_request(cs->req); - if (err) - goto out_put_old; - - fuse_copy_finish(cs); - - err = pipe_buf_confirm(cs->pipe, buf); - if (err) - goto out_put_old; - - BUG_ON(!cs->nr_segs); - cs->currbuf = buf; - cs->len = buf->len; - cs->pipebufs++; - cs->nr_segs--; - - if (cs->len != folio_size(oldfolio)) - goto out_fallback; - - newfolio = page_folio(buf->page); - - if (folio_test_large(newfolio)) - goto out_fallback; - - /* - * This is a new and locked page, it shouldn't be mapped or - * have any special flags on it - */ - if (WARN_ON(folio_mapped(oldfolio))) - goto out_fallback; - if (WARN_ON(folio_has_private(oldfolio))) - goto out_fallback; - if (WARN_ON(folio_test_dirty(oldfolio) || - folio_test_writeback(oldfolio))) - goto out_fallback; - if (WARN_ON(folio_test_mlocked(oldfolio))) - goto out_fallback; - - if (!pipe_buf_try_steal(cs->pipe, buf)) - goto out_fallback; - - folio_clear_uptodate(newfolio); - folio_clear_mappedtodisk(newfolio); - - if (fuse_check_folio(newfolio) != 0) - goto out_fallback_unlock; - - err = lock_request(cs->req); - if (err) - goto out_fallback_unlock; - - replace_page_cache_folio(oldfolio, newfolio); - - folio_get(newfolio); - - if (!(buf->flags & PIPE_BUF_FLAG_LRU)) - folio_add_lru(newfolio); - - /* - * Release while we have extra ref on stolen page. Otherwise - * anon_pipe_buf_release() might think the page can be reused. - */ - pipe_buf_release(cs->pipe, buf); - - *foliop = newfolio; - folio_unlock(oldfolio); - /* Drop ref for ap->pages[] array */ - folio_put(oldfolio); - cs->len = 0; - - err = 0; -out_put_old: - /* Drop ref obtained in this function */ - folio_put(oldfolio); - return err; - -out_fallback_unlock: - folio_unlock(newfolio); -out_fallback: - cs->pg = buf->page; - cs->offset = buf->offset; - - err = lock_request(cs->req); - if (!err) - err = 1; - - goto out_put_old; -} - static int fuse_ref_folio(struct fuse_copy_state *cs, struct folio *folio, unsigned offset, unsigned count) { @@ -1275,16 +1153,9 @@ int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop, return fuse_ref_folio(cs, folio, offset, count); } } else if (!cs->len) { - if (cs->move_folios && folio && - offset == 0 && count == folio_size(folio)) { - err = fuse_try_move_folio(cs, foliop); - if (err <= 0) - return err; - } else { - err = fuse_copy_fill(cs); - if (err) - return err; - } + err = fuse_copy_fill(cs); + if (err) + return err; } if (folio) { void *mapaddr = kmap_local_folio(folio, offset); @@ -1756,7 +1627,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, * Need to be careful about this. Having buf->ops in module * code can Oops if the buffer persists after module unload. */ - bufs[page_nr].ops = &nosteal_pipe_buf_ops; + bufs[page_nr].ops = &default_pipe_buf_ops; bufs[page_nr].flags = 0; ret = add_to_pipe(pipe, &bufs[page_nr++]); if (unlikely(ret < 0)) @@ -1920,9 +1791,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, if (!smp_load_acquire(&fch->initialized) || !fch->connected) goto copy_finish; - /* Don't try to move folios (yet) */ - cs->move_folios = false; - err = fuse_notify(fch->conn, oh.error, nbytes - sizeof(oh), cs); goto copy_finish; } @@ -1966,8 +1834,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, set_bit(FR_LOCKED, &req->flags); spin_unlock(&fpq->lock); cs->req = req; - if (!req->args->page_replace) - cs->move_folios = false; if (oh.error) err = nbytes != sizeof(oh) ? -EINVAL : 0; @@ -2068,7 +1934,6 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, goto out_free; *obuf = *ibuf; - obuf->flags &= ~PIPE_BUF_FLAG_GIFT; obuf->len = rem; ibuf->offset += obuf->len; ibuf->len -= obuf->len; @@ -2083,9 +1948,6 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, cs.nr_segs = nbuf; cs.pipe = pipe; - if (flags & SPLICE_F_MOVE) - cs.move_folios = true; - ret = fuse_dev_do_write(fud, &cs, len); pipe_lock(pipe); diff --git a/fs/fuse/ext_map.c b/fs/fuse/ext_map.c index 7f04edc33fe38c..9b605ecdab5e22 100644 --- a/fs/fuse/ext_map.c +++ b/fs/fuse/ext_map.c @@ -210,9 +210,8 @@ static int fuse_ext_map_iomap_begin(struct inode *inode, loff_t offset, loff_t l return 0; } -static const struct iomap_ops fuse_ext_map_iomap_ops = { - .iomap_begin = fuse_ext_map_iomap_begin, -}; +static DEFINE_IOMAP_ITER_NEXT(fuse_ext_map_iomap_next, + fuse_ext_map_iomap_begin); static vm_fault_t fuse_ext_map_huge_fault(struct vm_fault *vmf, unsigned int order) { @@ -234,7 +233,7 @@ static vm_fault_t fuse_ext_map_huge_fault(struct vm_fault *vmf, unsigned int ord filemap_invalidate_lock_shared(inode->i_mapping); - ret = dax_iomap_fault(vmf, order, &pfn, NULL, &fuse_ext_map_iomap_ops); + ret = dax_iomap_fault(vmf, order, &pfn, NULL, fuse_ext_map_iomap_next); if (ret & VM_FAULT_NEEDDSYNC) ret = dax_finish_sync_fault(vmf, order, pfn); @@ -283,7 +282,7 @@ ssize_t fuse_ext_map_read_iter(struct kiocb *iocb, struct iov_iter *to) if (!IS_ENABLED(CONFIG_FS_DAX)) return -EIO; - res = dax_iomap_rw(iocb, to, &fuse_ext_map_iomap_ops); + res = dax_iomap_rw(iocb, to, fuse_ext_map_iomap_next); file_accessed(iocb->ki_filp); return res; @@ -309,7 +308,7 @@ ssize_t fuse_ext_map_write_iter(struct kiocb *iocb, struct iov_iter *from) if (!IS_ENABLED(CONFIG_FS_DAX)) return -EIO; - return dax_iomap_rw(iocb, from, &fuse_ext_map_iomap_ops); + return dax_iomap_rw(iocb, from, fuse_ext_map_iomap_next); } int fuse_ext_map_mmap(struct file *file, struct vm_area_struct *vma) @@ -351,7 +350,7 @@ int fuse_ext_map_populate(struct fuse_conn *fc, struct fuse_notify_backing_map_o fb->backing_id = arg->backing_id; err = -ENOMEM; - fb->extents = kvcalloc(arg->num_extents, sizeof(*fb->extents), GFP_KERNEL); + fb->extents = kvzalloc_objs(*fb->extents, arg->num_extents); if (!fb->extents) goto err_put; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index d5e1cb53d86a6b..1dc517edfac861 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -923,10 +923,6 @@ static int fuse_iomap_begin(struct inode *inode, loff_t offset, loff_t length, static DEFINE_IOMAP_ITER_NEXT(fuse_iomap_next, fuse_iomap_begin); -static const struct iomap_ops fuse_iomap_ops = { - .iomap_next = fuse_iomap_next, -}; - struct fuse_fill_read_data { struct file *file; @@ -1036,7 +1032,7 @@ static int fuse_read_folio(struct file *file, struct folio *folio) return -EIO; } - iomap_read_folio(&fuse_iomap_ops, &ctx, NULL); + iomap_read_folio(fuse_iomap_next, &ctx, NULL); fuse_invalidate_atime(inode); return 0; } @@ -1096,7 +1092,6 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file, ap->args.out_pages = true; ap->args.page_zeroing = true; - ap->args.page_replace = true; /* * Don't overflow end offset. @@ -1146,7 +1141,7 @@ static void fuse_readahead(struct readahead_control *rac) if (fuse_is_bad(inode)) return; - iomap_readahead(&fuse_iomap_ops, &ctx, NULL); + iomap_readahead(fuse_iomap_next, &ctx, NULL); if (data.ia) fuse_send_readpages(data.ia, data.file, data.nr_bytes, fc->async_read); @@ -1570,7 +1565,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) * and granular dirty tracking for large folios. */ written = iomap_file_buffered_write(iocb, from, - &fuse_iomap_ops, + fuse_iomap_next, &fuse_iomap_write_ops, file); } else { diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h index 4b412a76225f86..a90ce26ded3192 100644 --- a/fs/fuse/fuse_dev_i.h +++ b/fs/fuse/fuse_dev_i.h @@ -326,7 +326,6 @@ struct fuse_copy_state { unsigned int len; unsigned int offset; bool write:1; - bool move_folios:1; bool is_uring:1; /* set when the payload is zero-copied. folios are filled in place */ bool skip_folio_copy:1; diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index ba8d79c4bcac6f..ff872c7c07628e 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1053,7 +1053,8 @@ static void virtio_fs_cleanup_vqs(struct virtio_device *vdev) } /* Map a window offset to a page frame number. The window offset will have - * been produced by .iomap_next(), which maps a file offset to a window offset. + * been produced by fuse_iomap_next(), which maps a file offset to a window + * offset. */ static long virtio_fs_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, enum dax_access_mode mode, @@ -1135,7 +1136,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n", cache_reg.len, cache_reg.addr); - pgmap = devm_kzalloc(&vdev->dev, sizeof(*pgmap), GFP_KERNEL); + pgmap = devm_kzalloc_obj(&vdev->dev, *pgmap); if (!pgmap) return -ENOMEM; diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index ee11d494e47c52..d31615f497543e 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c @@ -425,7 +425,7 @@ static int gfs2_read_folio(struct file *file, struct folio *folio) if (!gfs2_is_jdata(ip) || (i_blocksize(inode) == PAGE_SIZE && !folio_buffers(folio))) { - iomap_bio_read_folio(folio, &gfs2_iomap_ops); + iomap_bio_read_folio(folio, gfs2_iomap_next); } else if (gfs2_is_stuffed(ip)) { error = stuffed_read_folio(ip, folio); } else { @@ -500,7 +500,7 @@ static void gfs2_readahead(struct readahead_control *rac) else if (gfs2_is_jdata(ip)) mpage_readahead(rac, gfs2_block_map); else - iomap_bio_readahead(rac, &gfs2_iomap_ops); + iomap_bio_readahead(rac, gfs2_iomap_next); } /** @@ -572,7 +572,7 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) return 0; if (!gfs2_is_stuffed(ip)) - dblock = iomap_bmap(mapping, lblock, &gfs2_iomap_ops); + dblock = iomap_bmap(mapping, lblock, gfs2_iomap_next); gfs2_glock_dq_uninit(&i_gh); diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 264170f91c5dd8..09884f698d919c 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1205,12 +1205,7 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length, return 0; } -static DEFINE_IOMAP_ITER_NEXT_END(gfs2_iomap_next, gfs2_iomap_begin, - gfs2_iomap_end); - -const struct iomap_ops gfs2_iomap_ops = { - .iomap_next = gfs2_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(gfs2_iomap_next, gfs2_iomap_begin, gfs2_iomap_end); /** * gfs2_block_map - Map one or more blocks of an inode to a disk block @@ -1325,7 +1320,7 @@ static int gfs2_block_zero_range(struct inode *inode, loff_t from, loff_t length if (from >= inode->i_size) return 0; length = min(length, inode->i_size - from); - return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops, + return iomap_zero_range(inode, from, length, NULL, gfs2_iomap_next, &gfs2_iomap_write_ops, NULL); } diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index e3d6efdfd89037..cceb47950b7b1f 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -43,7 +43,7 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip, } } -extern const struct iomap_ops gfs2_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(gfs2_iomap_next); extern const struct iomap_write_ops gfs2_iomap_write_ops; extern const struct iomap_writeback_ops gfs2_writeback_ops; diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 6cfe335fd5909f..52248d7eb075ae 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1062,7 +1062,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) /* Change the pointers. Don't bother distinguishing stuffed from non-stuffed. This code is complicated enough already. */ - lp = kmalloc_array(half_len, sizeof(__be64), GFP_NOFS); + lp = kmalloc_objs(__be64, half_len, GFP_NOFS); if (!lp) { error = -ENOMEM; goto fail_brelse; diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 1efd0679badd93..cea24d5de91cef 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -851,7 +851,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to, goto out_uninit; pagefault_disable(); to->nofault = true; - ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL, + ret = iomap_dio_rw(iocb, to, gfs2_iomap_next, NULL, IOMAP_DIO_PARTIAL, NULL, read); to->nofault = false; pagefault_enable(); @@ -917,7 +917,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, goto out_unlock; from->nofault = true; - ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL, + ret = iomap_dio_rw(iocb, from, gfs2_iomap_next, NULL, IOMAP_DIO_PARTIAL, NULL, written); from->nofault = false; if (ret <= 0) { @@ -1069,7 +1069,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, goto out_unlock; pagefault_disable(); - ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops, + ret = iomap_file_buffered_write(iocb, from, gfs2_iomap_next, &gfs2_iomap_write_ops, NULL); pagefault_enable(); if (ret > 0) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 2c2dc459c0375a..75fb1a0c914253 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -2229,7 +2229,7 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; pagefault_disable(); - ret = iomap_fiemap(inode, fieinfo, start, len, &gfs2_iomap_ops); + ret = iomap_fiemap(inode, fieinfo, start, len, gfs2_iomap_next); pagefault_enable(); gfs2_glock_dq_uninit(&gh); @@ -2254,7 +2254,7 @@ loff_t gfs2_seek_data(struct file *file, loff_t offset) inode_lock_shared(inode); ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh); if (!ret) - ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops); + ret = iomap_seek_data(inode, offset, gfs2_iomap_next); gfs2_glock_dq_uninit(&gh); inode_unlock_shared(inode); @@ -2273,7 +2273,7 @@ loff_t gfs2_seek_hole(struct file *file, loff_t offset) inode_lock_shared(inode); ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh); if (!ret) - ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops); + ret = iomap_seek_hole(inode, offset, gfs2_iomap_next); gfs2_glock_dq_uninit(&gh); inode_unlock_shared(inode); diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c index 47eec0c13025d5..c1aeef0fa8c013 100644 --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c @@ -1120,8 +1120,8 @@ static int set_recover_size(struct gfs2_sbd *sdp, struct dlm_slot *slots, if (new_size == old_size) return 0; - submit = kcalloc(new_size, sizeof(uint32_t), GFP_NOFS); - result = kcalloc(new_size, sizeof(uint32_t), GFP_NOFS); + submit = kzalloc_objs(uint32_t, new_size, GFP_NOFS); + result = kzalloc_objs(uint32_t, new_size, GFP_NOFS); if (!submit || !result) { kfree(submit); kfree(result); diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 6a629ab956fc00..ef7eb601be09b4 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -158,10 +158,6 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, static DEFINE_IOMAP_ITER_NEXT(hpfs_iomap_next, hpfs_iomap_begin); -static const struct iomap_ops hpfs_iomap_ops = { - .iomap_next = hpfs_iomap_next, -}; - static int hpfs_read_folio(struct file *file, struct folio *folio) { return mpage_read_folio(folio, hpfs_get_block); @@ -238,7 +234,7 @@ static int hpfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, inode_lock(inode); len = min_t(u64, len, i_size_read(inode)); - ret = iomap_fiemap(inode, fieinfo, start, len, &hpfs_iomap_ops); + ret = iomap_fiemap(inode, fieinfo, start, len, hpfs_iomap_next); inode_unlock(inode); return ret; diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 01c4d6f44ebe0a..02e0a65d596d86 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -840,6 +841,13 @@ static int hugetlbfs_setattr(const struct mnt_idmap *idmap, if (error) return error; + if (S_ISREG(inode->i_mode) && (ia_valid & ATTR_MODE)) { + error = memfd_check_seals_mode(info->seals, inode->i_mode, + attr->ia_mode); + if (error) + return error; + } + trace_hugetlbfs_setattr(inode, dentry, attr); if (ia_valid & ATTR_SIZE) { diff --git a/fs/inode.c b/fs/inode.c index f63535ee36291d..de207f2f95a98e 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -817,6 +817,14 @@ static void evict(struct inode *inode) inode_wait_for_writeback(inode); spin_unlock(&inode->i_lock); + /* + * fsync() can't find what I_METADATA_WRITEBACK tracks anymore once the + * inode is gone, so write it out unless the inode is being deleted. + */ + if (inode->i_nlink && + (inode_state_read_once(inode) & I_METADATA_WRITEBACK)) + sync_inode_metadata(inode, 1); + if (op->evict_inode) { op->evict_inode(inode); } else { @@ -952,9 +960,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item, * they're already on the LRU, and this can make them * unreclaimable for a while. Remove them lazily here; iput, * sync, or the last page cache deletion will requeue them. + * Nothing requeues them for I_METADATA_WRITEBACK, evict() writes + * that out instead. */ if (icount_read(inode) || - (inode_state_read(inode) & ~I_REFERENCED) || + (inode_state_read(inode) & + ~(I_REFERENCED | I_METADATA_WRITEBACK)) || !mapping_shrinkable(&inode->i_data)) { list_lru_isolate(lru, &inode->i_lru); spin_unlock(&inode->i_lock); @@ -2858,9 +2869,10 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode) { struct super_block *sb = inode->i_sb; unsigned int gran = sb->s_time_gran; + time64_t seconds = t.tv_sec; t.tv_sec = clamp(t.tv_sec, sb->s_time_min, sb->s_time_max); - if (unlikely(t.tv_sec == sb->s_time_max || t.tv_sec == sb->s_time_min)) + if (unlikely(t.tv_sec != seconds)) t.tv_nsec = 0; /* Avoid division in the common cases 1 ns and 1 s. */ diff --git a/fs/internal.h b/fs/internal.h index 967c8556c17fc4..3f2fbac40f8ee5 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -8,7 +8,6 @@ struct super_block; struct file_system_type; struct iomap; -struct iomap_ops; struct linux_binprm; struct path; struct mount; diff --git a/fs/ioctl.c b/fs/ioctl.c index 1c152c2b1b67de..ecc2a4cfe6100b 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -550,8 +551,8 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd, if (!S_ISREG(inode->i_mode) || IS_ANON_FILE(inode)) return vfs_ioctl(filp, cmd, arg); - return put_user(i_size_read(inode) - filp->f_pos, - (int __user *)argp); + return put_user(clamp_t(loff_t, i_size_read(inode) - filp->f_pos, + INT_MIN, INT_MAX), (int __user *)argp); case FS_IOC_GETFLAGS: return ioctl_getflags(filp, argp); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d6e2f1ded5ca6f..6d843b168d5f7d 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -648,8 +648,8 @@ static int iomap_read_folio_iter(struct iomap_iter *iter, return 0; } -void iomap_read_folio(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx, void *private) +void iomap_read_folio(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx, + void *private) { struct folio *folio = ctx->cur_folio; struct iomap_iter iter = { @@ -672,7 +672,7 @@ void iomap_read_folio(const struct iomap_ops *ops, fsverity_readahead(ctx->vi, folio->index, folio_nr_pages(folio)); - while ((ret = iomap_iter(&iter, ops)) > 0) { + while ((ret = iomap_iter(&iter, next)) > 0) { iter.status = iomap_read_folio_iter(&iter, ctx, &bytes_submitted); if (ctx->read_ctx && ctx->ops->submit_read) @@ -711,22 +711,22 @@ static int iomap_readahead_iter(struct iomap_iter *iter, /** * iomap_readahead - Attempt to read pages from a file. - * @ops: The operations vector for the filesystem. + * @next: The iomap iteration function for the filesystem. * @ctx: The ctx used for issuing readahead. * @private: The filesystem-specific information for issuing iomap_iter. * * This function is for filesystems to call to implement their readahead * address_space operation. * - * Context: The @ops callbacks may submit I/O (eg to read the addresses of + * Context: The @next callback may submit I/O (eg to read the addresses of * blocks from disc), and may wait for it. The caller may be trying to * access a different page, and so sleeping excessively should be avoided. * It may allocate memory, but should avoid costly allocations. This * function is called with memalloc_nofs set, so allocations will not cause * the filesystem to be reentered. */ -void iomap_readahead(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx, void *private) +void iomap_readahead(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx, + void *private) { struct readahead_control *rac = ctx->rac; struct iomap_iter iter = { @@ -748,7 +748,7 @@ void iomap_readahead(const struct iomap_ops *ops, fsverity_readahead(ctx->vi, readahead_index(rac), readahead_count(rac)); - while (iomap_iter(&iter, ops) > 0) { + while (iomap_iter(&iter, next) > 0) { iter.status = iomap_readahead_iter(&iter, ctx, &cur_bytes_submitted); if (ctx->read_ctx && ctx->ops->submit_read) @@ -1293,7 +1293,7 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i, ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private) { struct iomap_iter iter = { @@ -1314,7 +1314,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_DONTCACHE) iter.flags |= IOMAP_DONTCACHE; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_write_iter(&iter, i, write_ops); if (unlikely(iter.pos == iocb->ki_pos)) @@ -1326,7 +1326,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, EXPORT_SYMBOL_GPL(iomap_file_buffered_write); int iomap_fsverity_write(struct file *file, loff_t pos, size_t length, - const void *buf, const struct iomap_ops *ops, + const void *buf, iomap_iter_next_fn next, const struct iomap_write_ops *write_ops) { int ret; @@ -1343,7 +1343,7 @@ int iomap_fsverity_write(struct file *file, loff_t pos, size_t length, iov_iter_kvec(&iiter, WRITE, &kvec, 1, length); - ret = iomap_file_buffered_write(&iocb, &iiter, ops, write_ops, NULL); + ret = iomap_file_buffered_write(&iocb, &iiter, next, write_ops, NULL); if (ret < 0) return ret; return ret == length ? 0 : -EIO; @@ -1615,7 +1615,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter, int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops) { struct iomap_iter iter = { @@ -1630,7 +1630,7 @@ iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, return 0; iter.len = min(len, size - pos); - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_unshare_iter(&iter, write_ops); return ret; } @@ -1743,7 +1743,7 @@ EXPORT_SYMBOL_GPL(iomap_fill_dirty_folios); int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private) { struct folio_batch fbatch; @@ -1768,7 +1768,7 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, */ range_dirty = filemap_range_needs_writeback(mapping, iter.pos, iter.pos + iter.len - 1); - while ((ret = iomap_iter(&iter, ops)) > 0) { + while ((ret = iomap_iter(&iter, next)) > 0) { const struct iomap *srcmap = iomap_iter_srcmap(&iter); if (!(iter.iomap.flags & IOMAP_F_FOLIO_BATCH) && @@ -1794,7 +1794,7 @@ EXPORT_SYMBOL_GPL(iomap_zero_range); int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private) { unsigned int blocksize = i_blocksize(inode); @@ -1803,7 +1803,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, /* Block boundary? Nothing to do */ if (!off) return 0; - return iomap_zero_range(inode, pos, blocksize - off, did_zero, ops, + return iomap_zero_range(inode, pos, blocksize - off, did_zero, next, write_ops, private); } EXPORT_SYMBOL_GPL(iomap_truncate_page); @@ -1828,7 +1828,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter, return iomap_iter_advance(iter, length); } -vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops, +vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, iomap_iter_next_fn next, void *private) { struct iomap_iter iter = { @@ -1845,7 +1845,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops, goto out_unlock; iter.pos = folio_pos(folio); iter.len = ret; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_folio_mkwrite_iter(&iter, folio); if (ret < 0) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index ad041ac3252a57..f00b0841fdd081 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -695,7 +695,7 @@ static int iomap_dio_iter(struct iomap_iter *iter, struct iomap_dio *dio) */ struct iomap_dio * __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops, const struct iomap_dio_ops *dops, + iomap_iter_next_fn next, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before) { struct inode *inode = file_inode(iocb->ki_filp); @@ -819,7 +819,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, inode_dio_begin(inode); blk_start_plug(&plug); - while ((ret = iomap_iter(&iomi, ops)) > 0) { + while ((ret = iomap_iter(&iomi, next)) > 0) { iomi.status = iomap_dio_iter(&iomi, dio); /* @@ -909,12 +909,12 @@ EXPORT_SYMBOL_GPL(__iomap_dio_rw); ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops, const struct iomap_dio_ops *dops, + iomap_iter_next_fn next, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before) { struct iomap_dio *dio; - dio = __iomap_dio_rw(iocb, iter, ops, dops, dio_flags, private, + dio = __iomap_dio_rw(iocb, iter, next, dops, dio_flags, private, done_before); if (IS_ERR_OR_NULL(dio)) return PTR_ERR_OR_ZERO(dio); diff --git a/fs/iomap/fiemap.c b/fs/iomap/fiemap.c index 54b824b7edb5c6..a9e33c7af91080 100644 --- a/fs/iomap/fiemap.c +++ b/fs/iomap/fiemap.c @@ -56,7 +56,7 @@ static int iomap_fiemap_iter(struct iomap_iter *iter, } int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, - u64 start, u64 len, const struct iomap_ops *ops) + u64 start, u64 len, iomap_iter_next_fn next) { struct iomap_iter iter = { .inode = inode, @@ -73,7 +73,7 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, if (ret) return ret; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_fiemap_iter(&iter, fi, &prev); /* inode with no (attribute) mapping will give ENOENT */ @@ -92,7 +92,7 @@ EXPORT_SYMBOL_GPL(iomap_fiemap); /* legacy ->bmap interface. 0 is the error return (!) */ sector_t iomap_bmap(struct address_space *mapping, sector_t bno, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_iter iter = { .inode = mapping->host, @@ -107,7 +107,7 @@ iomap_bmap(struct address_space *mapping, sector_t bno, return 0; bno = 0; - while ((ret = iomap_iter(&iter, ops)) > 0) { + while ((ret = iomap_iter(&iter, next)) > 0) { if (iter.iomap.type == IOMAP_MAPPED) bno = iomap_sector(&iter.iomap, iter.pos) >> blkshift; /* leave iter.status unset to abort loop */ diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index fd8791c4963bbc..771b60fd1022ef 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -101,7 +101,7 @@ EXPORT_SYMBOL_GPL(iomap_iter_continue); /** * iomap_iter - iterate over ranges in a file * @iter: iteration structure - * @ops: iomap ops provided by the filesystem + * @next: the iomap iteration function for the filesystem * * Iterate over filesystem-provided space mappings for the provided file range. * @@ -113,18 +113,13 @@ EXPORT_SYMBOL_GPL(iomap_iter_continue); * of the loop body: leave @iter.status unchanged, or set it to a negative * errno. */ -int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) +int iomap_iter(struct iomap_iter *iter, iomap_iter_next_fn next) { int ret; - trace_iomap_iter(iter, ops, _RET_IP_); - - if (ops->iomap_next) - ret = ops->iomap_next(iter, &iter->iomap, &iter->srcmap); - else - ret = iomap_iter_next(iter, &iter->iomap, &iter->srcmap, - ops->iomap_begin, ops->iomap_end); + trace_iomap_iter(iter, next, _RET_IP_); + ret = next(iter, &iter->iomap, &iter->srcmap); iter->status = 0; if (ret > 0) iomap_iter_done(iter); diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c index 6cbc587c93dab2..6fd3173d25f51c 100644 --- a/fs/iomap/seek.c +++ b/fs/iomap/seek.c @@ -27,7 +27,7 @@ static int iomap_seek_hole_iter(struct iomap_iter *iter, } loff_t -iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops) +iomap_seek_hole(struct inode *inode, loff_t pos, iomap_iter_next_fn next) { loff_t size = i_size_read(inode); struct iomap_iter iter = { @@ -42,7 +42,7 @@ iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops) return -ENXIO; iter.len = size - pos; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_seek_hole_iter(&iter, &pos); if (ret < 0) return ret; @@ -73,7 +73,7 @@ static int iomap_seek_data_iter(struct iomap_iter *iter, } loff_t -iomap_seek_data(struct inode *inode, loff_t pos, const struct iomap_ops *ops) +iomap_seek_data(struct inode *inode, loff_t pos, iomap_iter_next_fn next) { loff_t size = i_size_read(inode); struct iomap_iter iter = { @@ -88,7 +88,7 @@ iomap_seek_data(struct inode *inode, loff_t pos, const struct iomap_ops *ops) return -ENXIO; iter.len = size - pos; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_seek_data_iter(&iter, &pos); if (ret < 0) return ret; diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c index 0db77c449467a7..c59f67a7de097a 100644 --- a/fs/iomap/swapfile.c +++ b/fs/iomap/swapfile.c @@ -139,7 +139,7 @@ static int iomap_swapfile_iter(struct iomap_iter *iter, */ int iomap_swapfile_activate(struct swap_info_struct *sis, struct file *swap_file, sector_t *pagespan, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct inode *inode = swap_file->f_mapping->host; struct iomap_iter iter = { @@ -163,7 +163,7 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, if (ret) return ret; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, next)) > 0) iter.status = iomap_swapfile_iter(&iter, &iter.iomap, &isi); if (ret < 0) return ret; diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h index e1ea8392cf47d4..d36a77b854aa50 100644 --- a/fs/iomap/trace.h +++ b/fs/iomap/trace.h @@ -218,9 +218,9 @@ TRACE_EVENT(iomap_add_to_ioend, ); TRACE_EVENT(iomap_iter, - TP_PROTO(struct iomap_iter *iter, const void *ops, + TP_PROTO(struct iomap_iter *iter, const void *next, unsigned long caller), - TP_ARGS(iter, ops, caller), + TP_ARGS(iter, next, caller), TP_STRUCT__entry( __field(dev_t, dev) __field(u64, ino) @@ -228,7 +228,7 @@ TRACE_EVENT(iomap_iter, __field(u64, length) __field(int, status) __field(unsigned int, flags) - __field(const void *, ops) + __field(const void *, next) __field(unsigned long, caller) ), TP_fast_assign( @@ -238,10 +238,10 @@ TRACE_EVENT(iomap_iter, __entry->length = iomap_length(iter); __entry->status = iter->status; __entry->flags = iter->flags; - __entry->ops = ops; + __entry->next = next; __entry->caller = caller; ), - TP_printk("dev %d:%d ino 0x%llx pos 0x%llx length 0x%llx status %d flags %s (0x%x) ops %ps caller %pS", + TP_printk("dev %d:%d ino 0x%llx pos 0x%llx length 0x%llx status %d flags %s (0x%x) next %ps caller %pS", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->pos, @@ -249,7 +249,7 @@ TRACE_EVENT(iomap_iter, __entry->status, __print_flags(__entry->flags, "|", IOMAP_FLAGS_STRINGS), __entry->flags, - __entry->ops, + __entry->next, (void *)__entry->caller) ); diff --git a/fs/isofs/util.c b/fs/isofs/util.c index 42f479da0b282c..6f9a90e58a890e 100644 --- a/fs/isofs/util.c +++ b/fs/isofs/util.c @@ -25,7 +25,7 @@ struct timespec64 iso_date(u8 *p, int flags) year = (p[0] - '0') * 1000 + (p[1] - '0') * 100 + (p[2] - '0') * 10 + - (p[3] - '0') - 1900; + (p[3] - '0'); month = ((p[4] - '0') * 10 + (p[5] - '0')); day = ((p[6] - '0') * 10 + (p[7] - '0')); hour = ((p[8] - '0') * 10 + (p[9] - '0')); @@ -34,7 +34,7 @@ struct timespec64 iso_date(u8 *p, int flags) ts.tv_nsec = ((p[14] - '0') * 10 + (p[15] - '0')) * 10000000; tz = p[16]; } else { - year = p[0]; + year = p[0] + 1900; month = p[1]; day = p[2]; hour = p[3]; @@ -45,10 +45,10 @@ struct timespec64 iso_date(u8 *p, int flags) tz = flags & ISO_DATE_HIGH_SIERRA ? 0 : p[6]; } - if (year < 0) { + if (year < 1) { ts.tv_sec = 0; } else { - ts.tv_sec = mktime64(year+1900, month, day, hour, minute, second); + ts.tv_sec = mktime64(year, month, day, hour, minute, second); /* sign extend */ if (tz & 0x80) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 324d61a00545b0..800af10d9511e7 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -750,7 +750,7 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, struct kernfs_iattrs *attrs = READ_ONCE(parent->iattr); if (attrs) - gid = READ_ONCE(attrs->ia_gid); + gid = KGIDT_INIT(READ_ONCE(attrs->ia_gid.val)); if (flags & KERNFS_DIR) mode |= S_ISGID; diff --git a/fs/libfs.c b/fs/libfs.c index 96a6e9b1535fb7..46e0205154e722 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -263,17 +263,18 @@ static long dentry2offset(struct dentry *dentry) return (long)dentry->d_fsdata; } -static struct lock_class_key simple_offset_lock_class; - /** * simple_offset_init - initialize an offset_ctx * @octx: directory offset map to be initialized + * @dir: the directory @octx belongs to * + * The directory's i_rwsem is the lock of the offset map. Writers hold it + * exclusive, offset_readdir() holds it shared. */ -void simple_offset_init(struct offset_ctx *octx) +void simple_offset_init(struct offset_ctx *octx, struct inode *dir) { - mt_init_flags(&octx->mt, MT_FLAGS_ALLOC_RANGE); - lockdep_set_class(&octx->mt.ma_lock, &simple_offset_lock_class); + mt_init_flags(&octx->mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN); + mt_set_external_lock(&octx->mt, &dir->i_rwsem); octx->next_offset = DIR_OFFSET_MIN; } @@ -282,6 +283,12 @@ void simple_offset_init(struct offset_ctx *octx) * @octx: directory offset ctx to be updated * @dentry: new dentry being added * + * The offset map holds no reference to @dentry. Once positive, @dentry + * must be pinned with d_make_persistent() for as long as it is in the + * map, and entries may only be added, removed or renamed with the + * directory's i_rwsem held exclusive: offset_readdir() emits straight + * from the map under the shared lock. + * * Returns zero on success. @octx and the dentry's offset are updated. * Otherwise, a negative errno value is returned. */ @@ -290,12 +297,13 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) unsigned long offset; int ret; + MA_STATE(mas, &octx->mt, 0, 0); + if (dentry2offset(dentry) != 0) return -EBUSY; - ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN, - DIR_OFFSET_MAX, &octx->next_offset, - GFP_KERNEL); + ret = mas_alloc_cyclic(&mas, &offset, dentry, DIR_OFFSET_MIN, + DIR_OFFSET_MAX, &octx->next_offset, GFP_KERNEL); if (unlikely(ret < 0)) return ret == -EBUSY ? -ENOSPC : ret; @@ -308,7 +316,9 @@ static int simple_offset_replace(struct offset_ctx *octx, struct dentry *dentry, { int ret; - ret = mtree_store(&octx->mt, offset, dentry, GFP_KERNEL); + MA_STATE(mas, &octx->mt, offset, offset); + + ret = mas_store_gfp(&mas, dentry, GFP_KERNEL); if (ret) return ret; offset_set(dentry, offset); @@ -323,13 +333,14 @@ static int simple_offset_replace(struct offset_ctx *octx, struct dentry *dentry, */ void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry) { - long offset; + long offset = dentry2offset(dentry); + + MA_STATE(mas, &octx->mt, offset, offset); - offset = dentry2offset(dentry); if (offset == 0) return; - mtree_erase(&octx->mt, offset); + mas_erase(&mas); offset_set(dentry, 0); } @@ -387,16 +398,20 @@ int simple_offset_rename_exchange(struct inode *old_dir, long new_index = dentry2offset(new_dentry); int ret; + MA_STATE(old_mas, &old_ctx->mt, old_index, old_index); + MA_STATE(new_mas, &new_ctx->mt, new_index, new_index); + if (WARN_ON(!old_index || !new_index)) return -EINVAL; - ret = mtree_store(&new_ctx->mt, new_index, old_dentry, GFP_KERNEL); + ret = mas_store_gfp(&new_mas, old_dentry, GFP_KERNEL); if (WARN_ON(ret)) return ret; - ret = mtree_store(&old_ctx->mt, old_index, new_dentry, GFP_KERNEL); + ret = mas_store_gfp(&old_mas, new_dentry, GFP_KERNEL); if (WARN_ON(ret)) { - mtree_store(&new_ctx->mt, new_index, new_dentry, GFP_KERNEL); + mas_set(&new_mas, new_index); + mas_store_gfp(&new_mas, new_dentry, GFP_KERNEL); return ret; } @@ -411,11 +426,14 @@ int simple_offset_rename_exchange(struct inode *old_dir, * @octx: directory offset ctx that is about to be destroyed * * During fs teardown (eg. umount), a directory's offset map might still - * contain entries. xa_destroy() cleans out anything that remains. + * contain entries. __mt_destroy() cleans out anything that remains. + * Nothing can reach the map of a directory that is being destroyed, so + * this runs without the directory's i_rwsem. */ void simple_offset_destroy(struct offset_ctx *octx) { - mtree_destroy(&octx->mt); + mt_on_stack(octx->mt); + __mt_destroy(&octx->mt); } /** @@ -446,51 +464,6 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) return vfs_setpos(file, offset, LONG_MAX); } -static struct dentry *find_positive_dentry(struct dentry *parent, - struct dentry *dentry, - bool next) -{ - struct dentry *found = NULL; - - spin_lock(&parent->d_lock); - if (next) - dentry = d_next_sibling(dentry); - else if (!dentry) - dentry = d_first_child(parent); - hlist_for_each_entry_from(dentry, d_sib) { - if (!simple_positive(dentry)) - continue; - spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); - if (simple_positive(dentry)) - found = dget_dlock(dentry); - spin_unlock(&dentry->d_lock); - if (likely(found)) - break; - } - spin_unlock(&parent->d_lock); - return found; -} - -static noinline_for_stack struct dentry * -offset_dir_lookup(struct dentry *parent, loff_t offset) -{ - struct inode *inode = d_inode(parent); - struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); - struct dentry *child, *found = NULL; - - MA_STATE(mas, &octx->mt, offset, offset); - - if (offset == DIR_OFFSET_FIRST) - found = find_positive_dentry(parent, NULL, false); - else { - rcu_read_lock(); - child = mas_find_rev(&mas, DIR_OFFSET_MIN); - found = find_positive_dentry(parent, child, false); - rcu_read_unlock(); - } - return found; -} - static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) { struct inode *inode = d_inode(dentry); @@ -499,32 +472,30 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) inode->i_ino, fs_umode_to_dtype(inode->i_mode)); } +/* + * Emit entries in descending offset order. The directory's i_rwsem is the + * lock of the offset tree and the persistent dentries in it only change + * with it held exclusive. We hold it shared, so @mas stays valid across + * dir_emit() and the dentries need no references. + */ static void offset_iterate_dir(struct file *file, struct dir_context *ctx) { - struct dentry *dir = file->f_path.dentry; + struct inode *inode = file_inode(file); + struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); + loff_t start = ctx->pos == DIR_OFFSET_FIRST ? DIR_OFFSET_MAX : ctx->pos; struct dentry *dentry; - dentry = offset_dir_lookup(dir, ctx->pos); - if (!dentry) - goto out_eod; - while (true) { - struct dentry *next; + MA_STATE(mas, &octx->mt, start, start); + for (;;) { + dentry = mas_find_rev(&mas, DIR_OFFSET_MIN); + if (!dentry) + break; + VFS_WARN_ON_ONCE(!(dentry->d_flags & DCACHE_PERSISTENT)); ctx->pos = dentry2offset(dentry); if (!offset_dir_emit(ctx, dentry)) - break; - - next = find_positive_dentry(dir, dentry, true); - dput(dentry); - - if (!next) - goto out_eod; - dentry = next; + return; } - dput(dentry); - return; - -out_eod: ctx->pos = DIR_OFFSET_EOD; } @@ -559,7 +530,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit_dots(file, ctx)) return 0; - if (ctx->pos != DIR_OFFSET_EOD) + if (ctx->pos < DIR_OFFSET_EOD) offset_iterate_dir(file, ctx); return 0; } diff --git a/fs/minix/bitmap.c b/fs/minix/bitmap.c index 0ac96c88e74d7c..3d5691111183d3 100644 --- a/fs/minix/bitmap.c +++ b/fs/minix/bitmap.c @@ -121,21 +121,35 @@ unsigned long minix_count_free_blocks(struct super_block *sb) << sbi->s_log_zone_size); } -struct minix_inode * -minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh) +/* Return the block that holds inode @ino or 0 if @ino is out of range. */ +int minix_inode_block(struct super_block *sb, ino_t ino) { - int block; struct minix_sb_info *sbi = minix_sb(sb); - struct minix_inode *p; + int inodes_per_block; if (!ino || ino > sbi->s_ninodes) { printk("Bad inode number on dev %s: %ld is out of range\n", sb->s_id, (long)ino); - return NULL; + return 0; } + if (sbi->s_version == MINIX_V1) + inodes_per_block = MINIX_INODES_PER_BLOCK; + else + inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode); + return 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks + + (ino - 1) / inodes_per_block; +} + +struct minix_inode * +minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh) +{ + int block; + struct minix_inode *p; + + block = minix_inode_block(sb, ino); + if (!block) + return NULL; ino--; - block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks + - ino / MINIX_INODES_PER_BLOCK; *bh = sb_bread(sb, block); if (!*bh) { printk("Unable to read inode block\n"); @@ -149,19 +163,14 @@ struct minix2_inode * minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh) { int block; - struct minix_sb_info *sbi = minix_sb(sb); struct minix2_inode *p; int minix2_inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode); *bh = NULL; - if (!ino || ino > sbi->s_ninodes) { - printk("Bad inode number on dev %s: %ld is out of range\n", - sb->s_id, (long)ino); + block = minix_inode_block(sb, ino); + if (!block) return NULL; - } ino--; - block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks + - ino / minix2_inodes_per_block; *bh = sb_bread(sb, block); if (!*bh) { printk("Unable to read inode block\n"); diff --git a/fs/minix/inode.c b/fs/minix/inode.c index 670179173645b3..9fb938ec586891 100644 --- a/fs/minix/inode.c +++ b/fs/minix/inode.c @@ -50,8 +50,6 @@ static void minix_evict_inode(struct inode *inode) if (!inode->i_nlink) { inode->i_size = 0; minix_truncate(inode); - } else { - mmb_sync(&minix_i(inode)->i_metadata_bhs); } mmb_invalidate(&minix_i(inode)->i_metadata_bhs); clear_inode(inode); @@ -702,24 +700,24 @@ static int minix_sync_inode_metadata(struct inode *inode, { int err = 0; struct buffer_head *bh; - void *raw_inode; + int block; - if (INODE_VERSION(inode) == MINIX_V1) - raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh); - else - raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh); - if (!raw_inode) + block = minix_inode_block(inode->i_sb, inode->i_ino); + if (!block) return -EIO; err = mmb_sync(&minix_i(inode)->i_metadata_bhs); if (err) - goto out; + return err; + /* A block that isn't cached is neither dirty nor under writeback. */ + bh = sb_find_get_block_nonatomic(inode->i_sb, block); + if (!bh) + return 0; sync_dirty_buffer(bh); if (buffer_write_io_error(bh)) { printk("IO error syncing minix inode [%s:%08llx]\n", inode->i_sb->s_id, inode->i_ino); err = -EIO; } -out: brelse(bh); return err; } diff --git a/fs/minix/minix.h b/fs/minix/minix.h index db92cf9e0e1bf3..67d8e2a7dc061e 100644 --- a/fs/minix/minix.h +++ b/fs/minix/minix.h @@ -47,6 +47,7 @@ void __minix_error_inode(struct inode *inode, const char *function, unsigned int line, const char *fmt, ...); struct inode *minix_iget(struct super_block *, unsigned long); +int minix_inode_block(struct super_block *sb, ino_t ino); struct minix_inode *minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **); struct minix2_inode *minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **); struct inode *minix_new_inode(const struct inode *, umode_t); diff --git a/fs/namespace.c b/fs/namespace.c index 25e196c051263a..aecd05ac01705d 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3296,7 +3296,7 @@ static struct mnt_namespace *create_new_namespace(struct path *path, } new_ns->root = new_ns_root; - ns_tree_add_raw(new_ns); + ns_tree_add(new_ns); return new_ns; } @@ -4394,8 +4394,6 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a dec_mnt_namespaces(ucounts); return ERR_PTR(ret); } - ns_tree_gen_id(new_ns); - new_ns->is_anon = anon; refcount_set(&new_ns->passive, 1); new_ns->mounts = RB_ROOT; @@ -4499,7 +4497,7 @@ struct mnt_namespace *copy_mnt_ns(u64 flags, struct mnt_namespace *ns, p = next_mnt(skip_mnt_tree(p), old); } } - ns_tree_add_raw(new_ns); + ns_tree_add(new_ns); return new_ns; } @@ -6301,8 +6299,8 @@ static inline int prepare_klistmount(struct klistmount *kls, struct mnt_id_req * kls->last_mnt_id = last_mnt_id; kls->nr_mnt_ids = nr_mnt_ids; - kls->kmnt_ids = kvmalloc_array(nr_mnt_ids, sizeof(*kls->kmnt_ids), - GFP_KERNEL_ACCOUNT); + kls->kmnt_ids = kvmalloc_objs(*kls->kmnt_ids, nr_mnt_ids, + GFP_KERNEL_ACCOUNT); if (!kls->kmnt_ids) return -ENOMEM; diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c index 5bd8dee5a83467..bfaaebea12df8b 100644 --- a/fs/netfs/read_retry.c +++ b/fs/netfs/read_retry.c @@ -28,6 +28,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) struct netfs_io_subrequest *subreq; struct netfs_io_stream *stream = &rreq->io_streams[0]; struct list_head *next; + int ret; _enter("R=%x", rreq->debug_id); @@ -140,8 +141,11 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) /* Renegotiate max_len (rsize) */ stream->sreq_max_len = subreq->len; - if (rreq->netfs_ops->prepare_read && - rreq->netfs_ops->prepare_read(subreq) < 0) { + ret = 0; + if (rreq->netfs_ops->prepare_read) + ret = rreq->netfs_ops->prepare_read(subreq); + if (ret < 0) { + subreq->error = ret; trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed); __set_bit(NETFS_SREQ_FAILED, &subreq->flags); goto abandon; @@ -221,7 +225,9 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs); netfs_stat(&netfs_n_rh_download); - if (rreq->netfs_ops->prepare_read(subreq) < 0) { + ret = rreq->netfs_ops->prepare_read(subreq); + if (ret < 0) { + subreq->error = ret; trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed); __set_bit(NETFS_SREQ_FAILED, &subreq->flags); goto abandon; @@ -257,10 +263,13 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) if (!test_bit(NETFS_SREQ_FAILED, &subreq->flags) && !test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) continue; - subreq->error = -ENOMEM; + if (!subreq->error || + !test_bit(NETFS_SREQ_FAILED, &subreq->flags)) + subreq->error = -ENOMEM; __set_bit(NETFS_SREQ_FAILED, &subreq->flags); __clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); } + netfs_wake_collector(rreq); } /* diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c index b8237e1314d8a4..f233641164210e 100644 --- a/fs/netfs/write_issue.c +++ b/fs/netfs/write_issue.c @@ -268,7 +268,9 @@ void netfs_reissue_write(struct netfs_io_stream *stream, iov_iter_truncate(&subreq->io_iter, size); subreq->retry_count++; - subreq->error = 0; + /* Keep prepare_write() errno; do_issue_write() terminates FAILED. */ + if (!test_bit(NETFS_SREQ_FAILED, &subreq->flags)) + subreq->error = 0; __clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags); __set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags); netfs_stat(&netfs_n_wh_retry_write_subreq); diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index fba4699952b815..cd6142939d34d8 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h @@ -95,6 +95,8 @@ void nfs4_inode_make_writeable(struct inode *inode); void nfs_update_delegated_atime(struct inode *inode); void nfs_update_delegated_mtime(struct inode *inode); void nfs_update_delegated_mtime_locked(struct inode *inode); +void nfs_delegated_ctime_raise(struct inode *inode, + const struct nfs_fattr *fattr); static inline int nfs_have_read_or_write_delegation(struct inode *inode) { diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 08a940e63152da..49437037f948d3 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1253,6 +1253,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) spin_lock(&file->f_lock); desc->dir_cookie = dir_ctx->dir_cookie; desc->folio_index = dir_ctx->page_index; + desc->current_index = (loff_t)desc->folio_index * + nfs_readdir_array_maxentries(); desc->last_cookie = dir_ctx->last_cookie; desc->attr_gencount = dir_ctx->attr_gencount; desc->eof = dir_ctx->eof; @@ -2735,7 +2737,7 @@ static bool nfs_rename_is_unsafe_cross_dir(struct dentry *old_dentry, { struct nfs_server *server = NFS_SB(old_dentry->d_sb); - if (old_dentry->d_parent != new_dentry->d_parent) + if (old_dentry->d_parent == new_dentry->d_parent) return false; if (server->fh_expire_type & NFS_FH_RENAME_UNSAFE) return !(server->fh_expire_type & NFS_FH_NOEXPIRE_WITH_OPEN); diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 9492d6bc1d1a71..5c289737366f26 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -340,6 +341,7 @@ static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls) { if (fls) { ff_layout_free_mirror_array(fls); + bitmap_free(fls->cancelled_stripes); kfree(fls); } } @@ -653,6 +655,12 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, fls->mirror_array[i]->report_interval = be32_to_cpup(p); out_sort_mirrors: + fls->cancelled_stripes = bitmap_zalloc( + fls->mirror_array_cnt * dss_count, gfp_flags); + if (!fls->cancelled_stripes) { + rc = -ENOMEM; + goto out_err_free; + } ff_layout_sort_mirrors(fls); ret = &fls->generic_hdr; dprintk("<-- %s (success)\n", __func__); @@ -2582,6 +2590,10 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg, if (devid && memcmp(&mirror->dss[dss_id].devid, devid, sizeof(*devid)) != 0) continue; + /* Do not cancel a stripe again while this lseg drains. */ + if (test_and_set_bit(idx * mirror->dss_count + dss_id, + flseg->cancelled_stripes)) + continue; rcu_read_lock(); mirror_ds = rcu_dereference(mirror->dss[dss_id].mirror_ds); if (IS_ERR_OR_NULL(mirror_ds) || @@ -2599,10 +2611,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg, clnt = ds_clp->cl_rpcclient; if (!clnt) goto next; - if (!rpc_cancel_tasks(clnt, -ECANCELED, - ff_layout_match_io, lseg)) - goto next; - rpc_clnt_disconnect(clnt); + rpc_cancel_tasks_and_disconnect(clnt, -ECANCELED, + ff_layout_match_io, + lseg); next: nfs4_ff_layout_put_deviceid(mirror_ds); } diff --git a/fs/nfs/flexfilelayout/flexfilelayout.h b/fs/nfs/flexfilelayout/flexfilelayout.h index 09c3cd6964fd63..5d5587fded76fb 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.h +++ b/fs/nfs/flexfilelayout/flexfilelayout.h @@ -109,6 +109,7 @@ struct nfs4_ff_layout_segment { u64 stripe_unit; u32 flags; u32 mirror_array_cnt; + unsigned long *cancelled_stripes; struct nfs4_ff_layout_mirror *mirror_array[] __counted_by(mirror_array_cnt); }; diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index e0a2e92952afa8..5a682f74d7d150 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -629,28 +629,52 @@ nfs_fattr_fixup_delegated(struct inode *inode, struct nfs_fattr *fattr) } } +/* + * With delegated timestamps, the client's coarse clock can trail the + * server's fine-grained ctime cached from an OPEN or SETATTR reply. The + * server won't move ctime backward when the times are returned, so a + * new stamp must land after the cached ctime. + */ +static struct timespec64 nfs_delegated_stamp(struct inode *inode) +{ + struct timespec64 ctime = inode_get_ctime(inode); + struct timespec64 now = current_time(inode); + + if (timespec64_compare(&now, &ctime) <= 0) { + now = ctime; + timespec64_add_ns(&now, 1); + } + return now; +} + +/* + * The server stamped c/mtime itself (e.g. for a size change). Raise the + * cached ctime to the server's so that the next delegated stamp lands + * after it. + */ +void nfs_delegated_ctime_raise(struct inode *inode, + const struct nfs_fattr *fattr) +{ + struct timespec64 ctime = inode_get_ctime(inode); + + if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && + timespec64_compare(&fattr->ctime, &ctime) > 0) + inode_set_ctime_to_ts(inode, fattr->ctime); +} +EXPORT_SYMBOL_GPL(nfs_delegated_ctime_raise); + static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr) { unsigned int cache_flags = 0; if (attr->ia_valid & ATTR_MTIME_SET) { - struct timespec64 ctime = inode_get_ctime(inode); - struct timespec64 mtime = inode_get_mtime(inode); - struct timespec64 now; - bool updated = false; - - now = inode_set_ctime_current(inode); - if (!timespec64_equal(&now, &ctime)) - updated = true; - + /* The stamp is always after the old ctime */ + inode_set_ctime_to_ts(inode, nfs_delegated_stamp(inode)); inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (!timespec64_equal(&now, &mtime)) - updated = true; - - inode_maybe_inc_iversion(inode, updated); + inode_maybe_inc_iversion(inode, true); cache_flags |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; } - if (attr->ia_valid & ATTR_ATIME_SET) { + if (attr->ia_valid & ATTR_ATIME) { inode_set_atime_to_ts(inode, attr->ia_atime); cache_flags |= NFS_INO_INVALID_ATIME; } @@ -665,7 +689,11 @@ static void nfs_update_atime(struct inode *inode) static void nfs_update_mtime(struct inode *inode) { - inode_update_time(inode, FS_UPD_CMTIME, 0); + struct timespec64 now = nfs_delegated_stamp(inode); + + /* Not inode_update_time(): lockless readers would see its stamp */ + inode_set_ctime_to_ts(inode, now); + inode_set_mtime_to_ts(inode, now); NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME); } @@ -684,6 +712,7 @@ void nfs_update_delegated_mtime_locked(struct inode *inode) nfs_have_directory_delegation(inode)) nfs_update_mtime(inode); } +EXPORT_SYMBOL_GPL(nfs_update_delegated_mtime_locked); void nfs_update_delegated_mtime(struct inode *inode) { @@ -746,7 +775,7 @@ nfs_setattr(const struct mnt_idmap *idmap, struct dentry *dentry, } else if (nfs_have_delegated_atime(inode) && attr->ia_valid & ATTR_ATIME && !(attr->ia_valid & ATTR_MTIME)) { - if (!(attr->ia_valid & ATTR_ATIME_SET)) { + if (!(attr->ia_valid & (ATTR_ATIME_SET | ATTR_TIMES_SET))) { nfs_update_delegated_atime(inode); attr->ia_valid &= ~ATTR_ATIME; } @@ -808,10 +837,14 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset) nfs_ooo_clear(NFS_I(inode)); } NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE; + /* + * Stamp in the same i_lock section that checked the delegation and + * raised ctime, before a delegation return can start. + */ + nfs_update_delegated_mtime_locked(inode); spin_unlock(&inode->i_lock); truncate_pagecache(inode, offset); - nfs_update_delegated_mtime_locked(inode); spin_lock(&inode->i_lock); out: return err; @@ -837,6 +870,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, if ((attr->ia_valid & ATTR_SIZE) != 0) { if (!nfs_have_delegated_mtime(inode)) nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME); + else + nfs_delegated_ctime_raise(inode, fattr); nfs_set_cache_invalid(inode, NFS_INO_INVALID_BLOCKS); nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC); nfs_vmtruncate(inode, attr->ia_size); diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index cdada6cbb13bff..7f8d794581a3f6 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -25,6 +25,7 @@ #include #include "internal.h" +#include "netns.h" #include "pnfs.h" #include "nfstrace.h" @@ -55,7 +56,50 @@ struct nfs_local_fsync_ctx { }; static bool localio_enabled __read_mostly = true; -module_param(localio_enabled, bool, 0644); + +static void nfs_local_probe_all(void); + +/* + * localio_enabled is checked on every I/O, so turning it off stops LOCALIO + * at once and turning it back on resumes it for clients that use it. A + * client that probed while it was off was disabled, and nothing probes it + * again: turning it on probes every client that does not use LOCALIO. + */ +static int localio_enabled_set(const char *val, const struct kernel_param *kp) +{ + bool was = READ_ONCE(localio_enabled); + int ret; + + ret = param_set_bool(val, kp); + if (!ret && !was && READ_ONCE(localio_enabled)) + nfs_local_probe_all(); + return ret; +} + +static const struct kernel_param_ops localio_enabled_ops = { + .set = localio_enabled_set, + .get = param_get_bool, +}; +module_param_cb(localio_enabled, &localio_enabled_ops, &localio_enabled, 0644); + +/* + * Seconds the LOCALIO probe waits for each reply. With 0, the probe uses + * the NFS client's timeouts instead. + */ +static unsigned int localio_timeout __read_mostly = 10; + +static int localio_timeout_set(const char *val, const struct kernel_param *kp) +{ + return param_set_uint_minmax(val, kp, 0, 600); +} + +static const struct kernel_param_ops localio_timeout_ops = { + .set = localio_timeout_set, + .get = param_get_uint, +}; +module_param_cb(localio_timeout, &localio_timeout_ops, &localio_timeout, 0644); +MODULE_PARM_DESC(localio_timeout, + "LOCALIO probe timeout in seconds (default 10), 0 to use the mount's default"); static void nfs_local_do_read(struct nfs_local_kiocb *iocb, const struct rpc_call_ops *call_ops); @@ -131,13 +175,45 @@ const struct rpc_program nfslocalio_program = { /* * nfs_init_localioclient - Initialise an NFS localio client connection + * + * A server that does not support LOCALIO may not answer its RPCs at all. + * The probe shares the NFS client's transport and runs beside its RPCs. + * With localio_timeout set, it gets a quiet, soft timeout of that many + * seconds of its own, whatever timeouts the mount uses. With 0, it uses + * the NFS client's timeouts, as an NFS RPC would. */ static struct rpc_clnt *nfs_init_localioclient(struct nfs_client *clp) { - struct rpc_clnt *rpcclient_localio; + unsigned int timeout_secs = READ_ONCE(localio_timeout); + struct rpc_clnt *parent = clp->cl_rpcclient; + struct rpc_clnt *probe = NULL, *rpcclient_localio; - rpcclient_localio = rpc_bind_new_program(clp->cl_rpcclient, - &nfslocalio_program, 1); + /* + * rpc_bind_new_program() pings the new program with the timeout of + * the client it clones, so set the probe's timeout on a private + * clone first. The clone's cl_timeout points at the transport's + * timeout: give it its own copy rather than write through it. + */ + if (timeout_secs) { + probe = rpc_clone_client(parent); + if (IS_ERR(probe)) + return probe; + probe->cl_timeout_default = (struct rpc_timeout) { + .to_initval = timeout_secs * HZ, + .to_maxval = timeout_secs * HZ, + .to_retries = 0, + }; + probe->cl_timeout = &probe->cl_timeout_default; + probe->cl_softrtry = 1; + probe->cl_noretranstimeo = 0; + probe->cl_chatty = 0; + parent = probe; + } + + rpcclient_localio = rpc_bind_new_program(parent, &nfslocalio_program, 1); + /* The new client holds a reference to its parent, the probe clone */ + if (probe) + rpc_shutdown_client(probe); dprintk_rcu("%s: server (%s) %s NFS LOCALIO.\n", __func__, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), @@ -203,18 +279,49 @@ void nfs_local_probe_async_work(struct work_struct *work) struct nfs_client *clp = container_of(work, struct nfs_client, cl_local_probe_work); - if (!refcount_inc_not_zero(&clp->cl_count)) - return; nfs_local_probe(clp); + /* The reference nfs_local_probe_async() took for this work */ nfs_put_client(clp); } +/* + * The work is part of the client, so it holds a reference on the client + * from when it is queued until it has run: the last nfs_put_client() + * cannot free the client under a queued probe. + */ void nfs_local_probe_async(struct nfs_client *clp) { - queue_work(nfsiod_workqueue, &clp->cl_local_probe_work); + if (!refcount_inc_not_zero(&clp->cl_count)) + return; + if (!queue_work(nfsiod_workqueue, &clp->cl_local_probe_work)) + nfs_put_client(clp); /* already queued, with its reference */ } EXPORT_SYMBOL_GPL(nfs_local_probe_async); +/* Probe every client, in every namespace, that does not use LOCALIO. */ +static void nfs_local_probe_all(void) +{ + struct nfs_client *clp; + struct net *net; + + /* Set on the module command line: there are no clients yet. */ + if (!nfs_net_id) + return; + + down_read(&net_rwsem); + for_each_net(net) { + struct nfs_net *nn = net_generic(net, nfs_net_id); + + spin_lock(&nn->nfs_client_lock); + list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) + if (clp->cl_cons_state == NFS_CS_READY && + !nfs_client_is_local(clp)) + nfs_local_probe_async(clp); + spin_unlock(&nn->nfs_client_lock); + } + up_read(&net_rwsem); +} + static inline void nfs_local_file_put(struct nfsd_file *localio) { /* nfs_to_nfsd_file_put_local() expects an __rcu pointer diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index ab86246fc364f6..09b4a6ecad880a 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -380,6 +380,7 @@ static int process_copy_commit(struct file *dst, loff_t pos_dst, * @pos: destination offset * @len: copy length * @oldsize: length of the file prior to clone/copy + * @fattr: destination attributes from the reply, or NULL * * Punch a hole in the inode page cache, so that the NFS client will * know to retrieve new data. @@ -387,7 +388,7 @@ static int process_copy_commit(struct file *dst, loff_t pos_dst, * invalid cached values for change attribute, ctime, mtime and space used. */ static void nfs42_copy_dest_done(struct file *file, loff_t pos, loff_t len, - loff_t oldsize) + loff_t oldsize, const struct nfs_fattr *fattr) { struct inode *inode = file_inode(file); struct address_space *mapping = file->f_mapping; @@ -405,8 +406,12 @@ static void nfs42_copy_dest_done(struct file *file, loff_t pos, loff_t len, NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME | NFS_INO_INVALID_BLOCKS); + /* The server may have stamped c/mtime; stamp after it */ + if (fattr && nfs_have_delegated_mtime(inode)) + nfs_delegated_ctime_raise(inode, fattr); + /* Before a refresh can see the times invalid and take the server's */ + nfs_update_delegated_mtime_locked(inode); spin_unlock(&inode->i_lock); - nfs_update_delegated_mtime(inode); } static ssize_t _nfs42_proc_copy(struct file *src, @@ -506,7 +511,8 @@ static ssize_t _nfs42_proc_copy(struct file *src, goto out; } - nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst); + nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst, + NULL); nfs_invalidate_atime(src_inode); status = res->write_res.count; out: @@ -1311,8 +1317,17 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f, /* a zero-length count means clone to EOF in src */ if (count == 0 && res.dst_fattr->valid & NFS_ATTR_FATTR_SIZE) count = nfs_size_to_loff_t(res.dst_fattr->size) - dst_offset; - nfs42_copy_dest_done(dst_f, dst_offset, count, oldsize_dst); - status = nfs_post_op_update_inode(dst_inode, res.dst_fattr); + nfs42_copy_dest_done(dst_f, dst_offset, count, oldsize_dst, + res.dst_fattr); + /* + * nfs_post_op_update_inode() would mark ctime invalid, so the + * reply's ctime would overwrite the delegated stamp. + */ + if (nfs_have_delegated_mtime(dst_inode)) + status = nfs_refresh_inode(dst_inode, res.dst_fattr); + else + status = nfs_post_op_update_inode(dst_inode, + res.dst_fattr); } kfree(res.dst_fattr); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e1018b03c1cbd7..6759fa61b9b45d 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1722,6 +1722,8 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state, { DEFINE_WAIT(wait); int status = 0; + unsigned long deadline = jiffies + 5 * HZ; + signed long remaining; for (;;) { if (nfs_stateid_is_sequential(state, stateid)) @@ -1756,7 +1758,8 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state, if (!fatal_signal_pending(current) && !nfs_current_task_exiting()) { - if (schedule_timeout(5*HZ) == 0) + remaining = (long)(deadline - jiffies); + if (remaining <= 0 || schedule_timeout(remaining) == 0) status = -EAGAIN; else status = 0; @@ -3093,6 +3096,8 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, if (server->caps & NFS_CAP_POSIX_LOCK) set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) + server->nfs_client->cl_may_notify_lock = true; + if (server->nfs_client->cl_may_notify_lock) set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); if (opendata->o_res.rflags & NFS4_OPEN_RESULT_PRESERVE_UNLINKED) set_bit(NFS_INO_PRESERVE_UNLINKED, &NFS_I(state->inode)->flags); @@ -7287,8 +7292,15 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * if (status != 0) goto out; /* Is this a delegated lock? */ - if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) + if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) { + struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; + struct cb_notify_lock_args cbnl = { .cbnl_valid = false }; + + /* The server never saw it, so it will not notify waiters */ + nfs_copy_fh(&cbnl.cbnl_fh, NFS_FH(inode)); + __wake_up(&clp->cl_lock_waitq, TASK_NORMAL, 0, &cbnl); goto out; + } alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); status = -ENOMEM; @@ -7708,8 +7720,14 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vo struct nfs_lowner *lowner = &cbnl->cbnl_owner, *wowner = &waiter->owner; - /* Only wake if the callback was for the same owner. */ - if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) + /* + * Only wake the owner a CB_NOTIFY_LOCK names. A lock cached + * under a delegation is released locally, and the releasing + * thread cannot tell which waiter wants it, so those wakeups + * (cbnl_valid false) name only the inode and wake them all. + */ + if (cbnl->cbnl_valid && + (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev)) return 0; /* Make sure it's for the right inode */ diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a057a06318c76d..14f4a4b12ffd3b 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2086,7 +2086,7 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx, break; } if (size_set && io_set) { - if (size && io) + if (size || io) ret = true; } else if (size || io) ret = true; @@ -3169,7 +3169,7 @@ void pnfs_deviceid_delete_mark(struct nfs_client *clp, { struct nfs4_deviceid_delete *dd, *new; - new = kzalloc_obj(*new, GFP_KERNEL); + new = kzalloc_obj(*new); if (!new) return; /* lost notification; recovery waits for the next */ new->ld = pnfs_find_layoutdriver(ld->id); diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index e5a0f1ababe627..80824d7f45e40a 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -361,7 +361,7 @@ int nfsd_nl_expkey_get_reqs_dumpit(struct sk_buff *skb, } items = kzalloc_objs(*items, cnt); - seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL); + seqnos = kzalloc_objs(*seqnos, cnt); if (!items || !seqnos) { ret = -ENOMEM; goto out_alloc; @@ -688,7 +688,7 @@ int nfsd_nl_svc_export_get_reqs_dumpit(struct sk_buff *skb, } items = kzalloc_objs(*items, cnt); - seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL); + seqnos = kzalloc_objs(*seqnos, cnt); pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); if (!items || !seqnos || !pathbuf) { ret = -ENOMEM; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 1de6c6d757c3ed..567a856af482f3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1361,7 +1361,7 @@ alloc_init_dir_deleg(struct nfs4_client *clp, struct nfs4_file *fp) nfs4_put_stid(&dp->dl_stid); return NULL; } - ncn->ncn_masks = kcalloc(NOTIFY4_EVENT_QUEUE_SIZE, sizeof(*ncn->ncn_masks), GFP_KERNEL); + ncn->ncn_masks = kzalloc_objs(*ncn->ncn_masks, NOTIFY4_EVENT_QUEUE_SIZE); if (!ncn->ncn_masks) { nfs4_put_stid(&dp->dl_stid); return NULL; diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index 30dd8e5ebe5b88..d1bf52b003497d 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c @@ -149,7 +149,7 @@ static ssize_t nilfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) if (iocb->ki_flags & IOCB_DIRECT) { inode_lock_shared(inode); - ret = iomap_dio_rw(iocb, to, &nilfs_iomap_ops, + ret = iomap_dio_rw(iocb, to, nilfs_iomap_next, NULL, 0, NULL, 0); inode_unlock_shared(inode); } else diff --git a/fs/nilfs2/iomap.c b/fs/nilfs2/iomap.c index e130ed63abd9ac..c00189ade86140 100644 --- a/fs/nilfs2/iomap.c +++ b/fs/nilfs2/iomap.c @@ -67,6 +67,4 @@ static int nilfs_iomap_begin(struct inode *inode, loff_t offset, return 0; } -const struct iomap_ops nilfs_iomap_ops = { - .iomap_begin = nilfs_iomap_begin, -}; +DEFINE_IOMAP_ITER_NEXT(nilfs_iomap_next, nilfs_iomap_begin); diff --git a/fs/nilfs2/iomap.h b/fs/nilfs2/iomap.h index adef3e22346df0..5f9c05bd1230cc 100644 --- a/fs/nilfs2/iomap.h +++ b/fs/nilfs2/iomap.h @@ -8,6 +8,8 @@ #ifndef _NILFS_IOMAP_H #define _NILFS_IOMAP_H -extern const struct iomap_ops nilfs_iomap_ops; +#include + +DECLARE_IOMAP_ITER_NEXT(nilfs_iomap_next); #endif /* _NILFS_IOMAP_H */ diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 87ba788574bff3..c25cf5c1fc70f7 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -444,7 +444,7 @@ struct fanotify_perm_event { struct fanotify_event fae; struct path path; loff_t pos; /* FANOTIFY_NO_RANGE if unavailable */ - size_t count; + u64 count; u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ unsigned short watchdog_cnt; /* already scanned by watchdog? */ diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 7e2f330fd28372..8657bb94dfa8b4 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -157,7 +157,7 @@ static inline __u32 fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, /* Report pre-content event with optional range info */ int fsnotify_pre_content(const struct path *path, const loff_t *ppos, - size_t count) + u64 count) { struct file_range range; diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index 7c326ec2e8a8ca..6e3af6452dccb6 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c @@ -36,7 +36,7 @@ static bool event_compare(struct fsnotify_event *old_fsn, old = INOTIFY_E(old_fsn); new = INOTIFY_E(new_fsn); - if (old->mask & FS_IN_IGNORED) + if (old->mask & (FS_IN_IGNORED | FS_MOVE)) return false; if ((old->mask == new->mask) && (old->wd == new->wd) && diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c index ad781674fef1af..cb3d5443ee1dd6 100644 --- a/fs/ntfs/aops.c +++ b/fs/ntfs/aops.c @@ -103,7 +103,7 @@ static int ntfs_read_folio(struct file *file, struct folio *folio) return ntfs_read_compressed_block(folio); } - iomap_read_folio(&ntfs_read_iomap_ops, &ctx, NULL); + iomap_read_folio(ntfs_read_iomap_next, &ctx, NULL); return 0; } @@ -247,7 +247,7 @@ static void ntfs_readahead(struct readahead_control *rac) if (!NInoNonResident(ni) || NInoEncrypted(ni) || NInoCompressed(ni) || NInoWofCompressed(ni)) return; - iomap_readahead(&ntfs_read_iomap_ops, &ctx, NULL); + iomap_readahead(ntfs_read_iomap_next, &ctx, NULL); } static int ntfs_writepages(struct address_space *mapping, @@ -301,7 +301,7 @@ static int ntfs_swap_activate(struct swap_info_struct *sis, return -EOPNOTSUPP; return iomap_swapfile_activate(sis, swap_file, span, - &ntfs_read_iomap_ops); + ntfs_read_iomap_next); } const struct address_space_operations ntfs_aops = { diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index fce7144d7bef64..ce7c1b524180af 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -704,17 +704,20 @@ static bool ntfs_resident_attr_value_get(const struct attr_record *a, struct ntfs_resident_attr_value *value) { u32 attr_len; + u32 min_len; u16 value_offset; attr_len = le32_to_cpu(a->length); - if (attr_len < offsetof(struct attr_record, data.resident.reserved) + - sizeof(a->data.resident.reserved)) + min_len = offsetof(struct attr_record, data.resident.reserved) + + sizeof(a->data.resident.reserved); + if (attr_len < min_len) return false; value->len = le32_to_cpu(a->data.resident.value_length); value_offset = le16_to_cpu(a->data.resident.value_offset); - if (value->len > attr_len || value_offset > attr_len - value->len) + if (value_offset < min_len || value->len > attr_len || + value_offset > attr_len - value->len) return false; value->data = (const u8 *)a + value_offset; diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c index fce10baa2b93fe..9fb5bb3d351205 100644 --- a/fs/ntfs/dir.c +++ b/fs/ntfs/dir.c @@ -308,6 +308,20 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname, ia_mapping = ia_vi->i_mapping; descend_into_child_node: + /* + * The child node has to be inside $INDEX_ALLOCATION. A directory that + * lacks the attribute gets an empty index inode that is not + * non-resident, and reading a folio from it locks the mft record that + * is already locked here. + */ + if (!NInoNonResident(NTFS_I(ia_vi)) || vcn < 0 || + (u64)vcn >= (u64)i_size_read(ia_vi) >> dir_ni->itype.index.vcn_size_bits) { + ntfs_error(sb, + "Child node vcn %lld is outside $INDEX_ALLOCATION in directory inode 0x%llx.", + vcn, dir_ni->mft_no); + err = -EIO; + goto err_out; + } /* * Convert vcn to index into the index allocation attribute in units * of PAGE_SIZE and map the page cache page, reading it from diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c index fa5c5c62575105..68397b2a4e43ef 100644 --- a/fs/ntfs/ea.c +++ b/fs/ntfs/ea.c @@ -721,6 +721,11 @@ static int ntfs_new_attr_flags(struct ntfs_inode *ni, __le32 fattr) goto err_out; } + if ((new_aflags & ATTR_IS_COMPRESSED) && ni->vol->cluster_size > 4096) { + err = -EOPNOTSUPP; + goto err_out; + } + if (!a->non_resident) { if (!(new_aflags & (ATTR_IS_SPARSE | ATTR_IS_COMPRESSED))) { err = 0; diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index b2f5882d9990da..1861d0f07fef8a 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -686,12 +686,12 @@ loff_t ntfs_file_llseek(struct file *file, loff_t offset, int whence) switch (whence) { case SEEK_HOLE: inode_lock_shared(inode); - offset = iomap_seek_hole(inode, offset, &ntfs_seek_iomap_ops); + offset = iomap_seek_hole(inode, offset, ntfs_seek_iomap_next); inode_unlock_shared(inode); break; case SEEK_DATA: inode_lock_shared(inode); - offset = iomap_seek_data(inode, offset, &ntfs_seek_iomap_ops); + offset = iomap_seek_data(inode, offset, ntfs_seek_iomap_next); inode_unlock_shared(inode); break; default: @@ -728,7 +728,7 @@ ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) } file_accessed(iocb->ki_filp); - ret = iomap_dio_rw(iocb, to, &ntfs_read_iomap_ops, NULL, 0, + ret = iomap_dio_rw(iocb, to, ntfs_read_iomap_next, NULL, 0, NULL, 0); } else { ret = generic_file_read_iter(iocb, to); @@ -770,7 +770,7 @@ static ssize_t ntfs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) { ssize_t ret; - ret = iomap_dio_rw(iocb, from, &ntfs_dio_iomap_ops, + ret = iomap_dio_rw(iocb, from, ntfs_dio_iomap_next, &ntfs_write_dio_ops, 0, NULL, 0); if (ret == -ENOTBLK) ret = 0; @@ -798,7 +798,7 @@ static ssize_t ntfs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) inode_dio_wait(file_inode(iocb->ki_filp)); written = iomap_file_buffered_write(iocb, from, - &ntfs_write_iomap_ops, &ntfs_iomap_folio_ops, + ntfs_write_iomap_next, &ntfs_iomap_folio_ops, NULL); if (written < 0) { ret = written; @@ -930,7 +930,7 @@ ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (NInoNonResident(ni) && iocb->ki_flags & IOCB_DIRECT) ret = ntfs_dio_write_iter(iocb, from); else - ret = iomap_file_buffered_write(iocb, from, &ntfs_write_iomap_ops, + ret = iomap_file_buffered_write(iocb, from, ntfs_write_iomap_next, &ntfs_iomap_folio_ops, NULL); out: if (ret < 0 && ret != -EIOCBQUEUED) { @@ -1017,7 +1017,7 @@ static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf) * exclusively while invalidating pagecache and changing extents. */ filemap_invalidate_lock_shared(mapping); - ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL); + ret = iomap_page_mkwrite(vmf, ntfs_page_mkwrite_iomap_next, NULL); filemap_invalidate_unlock_shared(mapping); sb_end_pagefault(inode->i_sb); return ret; @@ -1072,7 +1072,7 @@ int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (NInoWofCompressed(NTFS_I(inode))) return -EOPNOTSUPP; - return iomap_fiemap(inode, fieinfo, start, len, &ntfs_read_iomap_ops); + return iomap_fiemap(inode, fieinfo, start, len, ntfs_read_iomap_next); } static const char *ntfs_get_link(struct dentry *dentry, struct inode *inode, @@ -1322,7 +1322,7 @@ static int ntfs_punch_hole(struct ntfs_inode *ni, int mode, loff_t offset, ntfs_cluster_to_bytes(vol, start_vcn + 1), end_offset); err = iomap_zero_range(vi, offset, to - offset, - NULL, &ntfs_seek_iomap_ops, + NULL, ntfs_seek_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err < 0) goto out; @@ -1338,7 +1338,7 @@ static int ntfs_punch_hole(struct ntfs_inode *ni, int mode, loff_t offset, from = ntfs_cluster_to_bytes(vol, end_vcn - 1); if (from < ni->initialized_size) { err = iomap_zero_range(vi, from, end_offset - from, - NULL, &ntfs_seek_iomap_ops, + NULL, ntfs_seek_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err < 0) goto out; diff --git a/fs/ntfs/index.c b/fs/ntfs/index.c index 66411a712b1414..b4462f760e3b6b 100644 --- a/fs/ntfs/index.c +++ b/fs/ntfs/index.c @@ -14,6 +14,8 @@ * Copyright (c) 2007-2021 Jean-Pierre Andre */ +#include + #include "collate.h" #include "index.h" #include "ntfs.h" @@ -41,9 +43,11 @@ static int ntfs_index_entry_inconsistent(const struct ntfs_volume *vol, } else { if (collation_rule == COLLATION_FILE_NAME) { - if ((offsetof(struct index_entry, key.file_name.file_name) + - ie->key.file_name.file_name_length * sizeof(__le16)) > - le16_to_cpu(ie->length)) { + if (le16_to_cpu(ie->key_length) < + offsetof(struct file_name_attr, file_name) || + (offsetof(struct file_name_attr, file_name) + + ie->key.file_name.file_name_length * sizeof(__le16)) > + le16_to_cpu(ie->key_length)) { ntfs_error(vol->sb, "File name overflow from index entry in inode %lld\n", (long long)inum); @@ -97,12 +101,30 @@ static s64 ntfs_ib_pos_to_vcn(struct ntfs_index_context *icx, s64 pos) return pos >> icx->vcn_size_bits; } +/* Open the index allocation inode if no earlier step of the operation did. */ +static int ntfs_icx_ia_ensure(struct ntfs_index_context *icx) +{ + if (!icx->ia_ni) { + icx->ia_ni = ntfs_ia_open(icx, icx->idx_ni); + if (!icx->ia_ni) + return -EIO; + } + /* Without $INDEX_ALLOCATION the index inode is an empty resident stub. */ + if (!NInoNonResident(icx->ia_ni)) + return -EIO; + return 0; +} + static int ntfs_ib_write(struct ntfs_index_context *icx, struct index_block *ib) { s64 ret, vcn = le64_to_cpu(ib->index_block_vcn); ntfs_debug("vcn: %lld\n", vcn); + ret = ntfs_icx_ia_ensure(icx); + if (ret) + return ret; + ret = pre_write_mst_fixup((struct ntfs_record *)ib, icx->block_size); if (ret) return -EIO; @@ -255,6 +277,32 @@ static s64 ntfs_ie_get_vcn(struct index_entry *ie) return le64_to_cpup(ntfs_ie_get_vcn_addr(ie)); } +static int ntfs_index_entry_vcn_inconsistent(const struct ntfs_volume *vol, + struct index_entry *ie, + u8 vcn_size_bits, u64 inum) +{ + s64 vcn, pos; + + if (le16_to_cpu(ie->length) < + sizeof(struct index_entry_header) + sizeof(s64)) { + ntfs_error(vol->sb, + "Index entry with node flag has no VCN in inode %llu.", + (unsigned long long)inum); + return -EIO; + } + + vcn = ntfs_ie_get_vcn(ie); + if (vcn < 0 || + check_shl_overflow(vcn, vcn_size_bits, &pos)) { + ntfs_error(vol->sb, + "Invalid index entry VCN %lld in inode %llu.", + vcn, (unsigned long long)inum); + return -EIO; + } + + return 0; +} + static struct index_entry *ntfs_ie_get_first(struct index_header *ih) { return (struct index_entry *)((u8 *)ih + le32_to_cpu(ih->entries_offset)); @@ -326,10 +374,13 @@ static int ntfs_index_header_inconsistent(struct ntfs_volume *vol, int ntfs_index_entries_inconsistent(const struct ntfs_volume *vol, const struct index_header *ih, + u32 block_size, __le32 collation_rule, u64 inum) { struct index_entry *ie; u8 *index_end = (u8 *)ih + le32_to_cpu(ih->index_length); + u8 vcn_size_bits = vol->cluster_size <= block_size ? + vol->cluster_size_bits : NTFS_BLOCK_SIZE_BITS; for (ie = ntfs_ie_get_first((struct index_header *)ih); ; ie = ntfs_ie_get_next(ie)) { @@ -348,6 +399,11 @@ int ntfs_index_entries_inconsistent(const struct ntfs_volume *vol, return -EIO; } + if ((ie->flags & INDEX_ENTRY_NODE) && + ntfs_index_entry_vcn_inconsistent(vol, ie, + vcn_size_bits, inum)) + return -EIO; + if (ntfs_ie_end(ie)) break; @@ -566,7 +622,8 @@ int ntfs_index_block_inconsistent(struct ntfs_volume *vol, return -EIO; } - if (ntfs_index_entries_inconsistent(vol, &ib->index, cr, inum)) + if (ntfs_index_entries_inconsistent(vol, &ib->index, block_size, + cr, inum)) return -EIO; return 0; } @@ -768,6 +825,10 @@ static int ntfs_ib_read(struct ntfs_index_context *icx, s64 vcn, struct index_bl ntfs_debug("vcn: %lld\n", vcn); + ret = ntfs_icx_ia_ensure(icx); + if (ret) + return ret; + pos = ntfs_ib_vcn_to_pos(icx, vcn); ret = ntfs_inode_attr_pread(VFS_I(icx->ia_ni), pos, icx->block_size, (u8 *)dst); @@ -1547,9 +1608,9 @@ static int ntfs_ih_insert(struct index_header *ih, struct index_entry *orig_ie, ie_node = ntfs_ie_get_by_pos(ih, pos); old_vcn = ntfs_ie_get_vcn(ie_node); ntfs_ie_set_vcn(ie_node, new_vcn); + ntfs_ie_set_vcn(ie, old_vcn); ntfs_ie_insert(ih, ie, ie_node); - ntfs_ie_set_vcn(ie_node, old_vcn); out: kfree(ie); return ret; diff --git a/fs/ntfs/index.h b/fs/ntfs/index.h index a898e348f2c9e2..bc2f1bbdfba495 100644 --- a/fs/ntfs/index.h +++ b/fs/ntfs/index.h @@ -98,6 +98,7 @@ int ntfs_index_block_inconsistent(struct ntfs_volume *vol, __le32 cr, u64 inum); int ntfs_index_entries_inconsistent(const struct ntfs_volume *vol, const struct index_header *ih, + u32 block_size, __le32 collation_rule, u64 inum); struct ntfs_index_context *ntfs_index_ctx_get(struct ntfs_inode *ni, __le16 *name, u32 name_len); diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 206db4e99ef133..b799e6668a6939 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -1034,6 +1034,7 @@ static int ntfs_read_locked_inode(struct inode *vi) le16_to_cpu(a->data.resident.value_offset)); if (ntfs_index_root_inconsistent(ni->vol, a, ir, ni->mft_no) || ntfs_index_entries_inconsistent(ni->vol, &ir->index, + le32_to_cpu(ir->index_block_size), ir->collation_rule, ni->mft_no)) { ntfs_error(vi->i_sb, "Directory index is corrupt."); goto unm_err_out; @@ -1684,6 +1685,7 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi) ir = (struct index_root *)((u8 *)a + le16_to_cpu(a->data.resident.value_offset)); if (ntfs_index_root_inconsistent(vol, a, ir, ni->mft_no) || ntfs_index_entries_inconsistent(vol, &ir->index, + le32_to_cpu(ir->index_block_size), ir->collation_rule, ni->mft_no)) { ntfs_error(vi->i_sb, "Index is corrupt."); goto unm_err_out; @@ -2554,8 +2556,12 @@ int ntfs_show_options(struct seq_file *sf, struct dentry *root) return 0; } -int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset, - const loff_t new_size) +/* + * The caller must hold @vi's mapping invalidate lock. + */ +static int __ntfs_extend_initialized_size(struct inode *vi, + const loff_t offset, + const loff_t new_size) { struct ntfs_inode *ni = NTFS_I(vi); struct ntfs_inode *mrec_ni = ntfs_base_inode(ni); @@ -2563,10 +2569,11 @@ int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset, unsigned long flags; int err = 0; + lockdep_assert_held_write(&vi->i_mapping->invalidate_lock); + if (!NInoNonResident(ni)) return -EINVAL; - filemap_invalidate_lock(vi->i_mapping); read_lock_irqsave(&ni->size_lock, flags); old_init_size = ni->initialized_size; read_unlock_irqrestore(&ni->size_lock, flags); @@ -2589,7 +2596,7 @@ int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset, if (old_init_size < offset) { err = iomap_zero_range(vi, old_init_size, offset - old_init_size, - NULL, &ntfs_seek_iomap_ops, + NULL, ntfs_seek_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err) goto out; @@ -2599,9 +2606,17 @@ int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset, mutex_lock(&mrec_ni->mrec_lock); err = ntfs_attr_set_initialized_size(ni, new_size); mutex_unlock(&mrec_ni->mrec_lock); - if (err) - truncate_setsize(vi, old_init_size); out: + return err; +} + +int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset, + const loff_t new_size) +{ + int err; + + filemap_invalidate_lock(vi->i_mapping); + err = __ntfs_extend_initialized_size(vi, offset, new_size); filemap_invalidate_unlock(vi->i_mapping); return err; } @@ -3715,11 +3730,11 @@ s64 ntfs_inode_attr_pread(struct inode *vi, s64 pos, s64 count, u8 *buf) } } isize = i_size_read(vi); - if (pos > isize) { + if (pos < 0 || pos > isize) { mutex_unlock(&mrec_ni->mrec_lock); return -EINVAL; } - if (pos + count > isize) + if (count > isize - pos) count = isize - pos; if (!NInoNonResident(ni)) { @@ -4087,8 +4102,13 @@ s64 ntfs_inode_attr_pwrite(struct inode *vi, s64 pos, s64 count, u8 *buf, bool s mutex_unlock(&mrec_ni->mrec_lock); /* Attribute writes bypass iomap's delayed-allocation preparation. */ if (ntfs_inode_is_named_stream(ni)) { - /* A failed write must not expose any newly initialized data. */ - ret = ntfs_extend_initialized_size(vi, pos + count, pos + count); + /* + * A failed write must not expose any newly initialized + * data. The stream ioctl caller holds the mapping + * invalidate lock. + */ + ret = __ntfs_extend_initialized_size(vi, pos + count, + pos + count); modified |= ni->initialized_size != old_init_size; if (!ret) ret = ntfs_attr_fallocate(ni, pos, count, true); diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c index 6e51cce3aeba11..b459d3e6e5fa5f 100644 --- a/fs/ntfs/iomap.c +++ b/fs/ntfs/iomap.c @@ -293,12 +293,8 @@ static int ntfs_read_iomap_end(struct inode *inode, loff_t pos, loff_t length, return written; } -static DEFINE_IOMAP_ITER_NEXT_END(ntfs_read_iomap_next, - ntfs_read_iomap_begin, ntfs_read_iomap_end); - -const struct iomap_ops ntfs_read_iomap_ops = { - .iomap_next = ntfs_read_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ntfs_read_iomap_next, ntfs_read_iomap_begin, + ntfs_read_iomap_end); /* * Check that the cached iomap still matches the NTFS runlist before @@ -351,15 +347,7 @@ static int ntfs_zero_read_iomap_end(struct inode *inode, loff_t pos, loff_t leng static DEFINE_IOMAP_ITER_NEXT_END(ntfs_zero_read_iomap_next, ntfs_seek_iomap_begin, ntfs_zero_read_iomap_end); -static const struct iomap_ops ntfs_zero_read_iomap_ops = { - .iomap_next = ntfs_zero_read_iomap_next, -}; - -static DEFINE_IOMAP_ITER_NEXT(ntfs_seek_iomap_next, ntfs_seek_iomap_begin); - -const struct iomap_ops ntfs_seek_iomap_ops = { - .iomap_next = ntfs_seek_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(ntfs_seek_iomap_next, ntfs_seek_iomap_begin); int ntfs_dio_zero_range(struct inode *inode, loff_t offset, loff_t length) { @@ -378,7 +366,7 @@ static int ntfs_zero_range(struct inode *inode, loff_t offset, loff_t length) return iomap_zero_range(inode, offset, length, NULL, - &ntfs_zero_read_iomap_ops, + ntfs_zero_read_iomap_next, &ntfs_zero_iomap_folio_ops, NULL); } @@ -499,7 +487,7 @@ static int ntfs_write_simple_iomap_begin_non_resident(struct inode *inode, loff_ ntfs_error(vol->sb, "Failed to merge runlists"); up_write(&ni->runlist.lock); mutex_unlock(&mrec_ni->mrec_lock); - kvfree(rlc); + kfree(rlc); return PTR_ERR(rl); } @@ -782,12 +770,8 @@ static int ntfs_write_iomap_end(struct inode *inode, loff_t pos, loff_t length, return written; } -static DEFINE_IOMAP_ITER_NEXT_END(ntfs_write_iomap_next, - ntfs_write_iomap_begin, ntfs_write_iomap_end); - -const struct iomap_ops ntfs_write_iomap_ops = { - .iomap_next = ntfs_write_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ntfs_write_iomap_next, ntfs_write_iomap_begin, + ntfs_write_iomap_end); static int ntfs_page_mkwrite_iomap_begin(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, @@ -797,13 +781,9 @@ static int ntfs_page_mkwrite_iomap_begin(struct inode *inode, loff_t offset, NTFS_IOMAP_FLAGS_MKWRITE); } -static DEFINE_IOMAP_ITER_NEXT_END(ntfs_page_mkwrite_iomap_next, +DEFINE_IOMAP_ITER_NEXT_END(ntfs_page_mkwrite_iomap_next, ntfs_page_mkwrite_iomap_begin, ntfs_write_iomap_end); -const struct iomap_ops ntfs_page_mkwrite_iomap_ops = { - .iomap_next = ntfs_page_mkwrite_iomap_next, -}; - static int ntfs_dio_iomap_begin(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) @@ -812,12 +792,8 @@ static int ntfs_dio_iomap_begin(struct inode *inode, loff_t offset, NTFS_IOMAP_FLAGS_DIO); } -static DEFINE_IOMAP_ITER_NEXT_END(ntfs_dio_iomap_next, - ntfs_dio_iomap_begin, ntfs_write_iomap_end); - -const struct iomap_ops ntfs_dio_iomap_ops = { - .iomap_next = ntfs_dio_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ntfs_dio_iomap_next, ntfs_dio_iomap_begin, + ntfs_write_iomap_end); static ssize_t ntfs_writeback_range(struct iomap_writepage_ctx *wpc, struct folio *folio, u64 offset, unsigned int len, u64 end_pos) diff --git a/fs/ntfs/iomap.h b/fs/ntfs/iomap.h index 3abc1d493e918d..fec8b907c48f6c 100644 --- a/fs/ntfs/iomap.h +++ b/fs/ntfs/iomap.h @@ -12,11 +12,11 @@ #include "volume.h" #include "inode.h" -extern const struct iomap_ops ntfs_write_iomap_ops; -extern const struct iomap_ops ntfs_read_iomap_ops; -extern const struct iomap_ops ntfs_seek_iomap_ops; -extern const struct iomap_ops ntfs_page_mkwrite_iomap_ops; -extern const struct iomap_ops ntfs_dio_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(ntfs_write_iomap_next); +DECLARE_IOMAP_ITER_NEXT(ntfs_read_iomap_next); +DECLARE_IOMAP_ITER_NEXT(ntfs_seek_iomap_next); +DECLARE_IOMAP_ITER_NEXT(ntfs_page_mkwrite_iomap_next); +DECLARE_IOMAP_ITER_NEXT(ntfs_dio_iomap_next); extern const struct iomap_writeback_ops ntfs_writeback_ops; extern const struct iomap_write_ops ntfs_iomap_folio_ops; extern int ntfs_dio_zero_range(struct inode *inode, loff_t offset, loff_t length); diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 89288b794348bb..60734500a40624 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -3259,7 +3259,7 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w file_limit = min_t(u64, i_size, allocated_size); nr_records = PAGE_SIZE / vol->mft_record_size; max_units = PAGE_SIZE / min(vol->cluster_size, vol->mft_record_size); - units = kmalloc_array(max_units, sizeof(*units), GFP_NOFS); + units = kmalloc_objs(*units, max_units, GFP_NOFS); if (!locked_nis || !ref_inos || !units) { err = -ENOMEM; goto out_noio; diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c index 95a3c05f982110..70c5892077133c 100644 --- a/fs/ntfs/named_stream.c +++ b/fs/ntfs/named_stream.c @@ -1632,6 +1632,10 @@ int ntfs_ioctl_list_streams(struct file *filp, unsigned long arg) ubuf = (void __user *)arg + sizeof(hdr); mutex_lock(&ni->mrec_lock); + if (NInoBeingDeleted(ni) || !inode->i_nlink) { + mutex_unlock(&ni->mrec_lock); + return -ENOENT; + } actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) { mutex_unlock(&ni->mrec_lock); @@ -1731,7 +1735,7 @@ int ntfs_ioctl_list_streams(struct file *filp, unsigned long arg) } entry_size = ALIGN(name_offset + name_len, 8); - if (offset > required - entry_size) { + if (offset > required || entry_size > required - offset) { ret = -EOVERFLOW; kfree(sn); sn = NULL; diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 62b01646c26235..b46fe44b63b554 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -472,8 +472,10 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in #ifdef CONFIG_NTFS_FS_POSIX_ACL if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) { err = ntfs_init_acl(idmap, vi, dir); - if (err) - goto err_out; + if (err) { + iput(vi); + return ERR_PTR(err); + } } else #endif { diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 71f0aea46bf8f2..891b5e0c384b19 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -2790,8 +2790,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) mutex_unlock(&ntfs_lock); lcn_bit_pages = (((vol->nr_clusters + 7) >> 3) + PAGE_SIZE - 1) >> PAGE_SHIFT; - vol->lcn_empty_bits_per_page = kvmalloc_array(lcn_bit_pages, sizeof(unsigned int), - GFP_KERNEL); + vol->lcn_empty_bits_per_page = kvmalloc_objs(unsigned int, + lcn_bit_pages); if (!vol->lcn_empty_bits_per_page) { ntfs_error(sb, "Unable to allocate pages for storing LCN empty bit counts\n"); diff --git a/fs/ntfs/upcase.c b/fs/ntfs/upcase.c index 4b954470883f9d..f024fd8381fd8d 100644 --- a/fs/ntfs/upcase.c +++ b/fs/ntfs/upcase.c @@ -52,7 +52,7 @@ __le16 *generate_default_upcase(void) int i, r; __le16 *uc; - uc = kvcalloc(default_upcase_len, sizeof(__le16), GFP_NOFS); + uc = kvzalloc_objs(__le16, default_upcase_len, GFP_NOFS); if (!uc) return uc; /* Generate the little endian Unicode upcase table used by ntfs. */ diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 60b362f388d960..52feb3504d5be5 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -677,7 +677,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits) wnd->bits_last = wbits; wnd->free_bits = - kvmalloc_array(wnd->nwnd, sizeof(u16), GFP_KERNEL | __GFP_ZERO); + kvmalloc_objs(u16, wnd->nwnd, GFP_KERNEL | __GFP_ZERO); if (!wnd->free_bits) return -ENOMEM; @@ -1342,7 +1342,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits) new_last = wbits; if (new_wnd != wnd->nwnd) { - new_free = kmalloc_array(new_wnd, sizeof(u16), GFP_NOFS); + new_free = kmalloc_objs(u16, new_wnd, GFP_NOFS); if (!new_free) return -ENOMEM; diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 1624f9b014e091..6c84a3e1c7fea5 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -319,7 +319,7 @@ static int ntfs_extend_initialized_size(struct file *file, } err = iomap_zero_range(inode, valid, new_valid - valid, NULL, - &ntfs_iomap_ops, &ntfs_iomap_folio_ops, NULL); + ntfs_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err) { ni->i_valid = valid; ntfs_inode_warn(inode, @@ -558,7 +558,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) /* Zero head of punch. */ if (tmp > from) { err = iomap_zero_range(inode, from, tmp - from, NULL, - &ntfs_iomap_ops, + ntfs_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err) goto out; @@ -576,7 +576,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) /* Zero tail of punch. */ if (vbo < end_a && end_a < end) { err = iomap_zero_range(inode, end_a, end - end_a, NULL, - &ntfs_iomap_ops, + ntfs_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err) goto out; @@ -896,7 +896,7 @@ static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) goto out; } - ret = iomap_dio_rw(iocb, iter, &ntfs_iomap_ops, NULL, dio_flags, + ret = iomap_dio_rw(iocb, iter, ntfs_iomap_next, NULL, dio_flags, NULL, 0); if (ret <= 0) @@ -1313,7 +1313,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) !ntfs_should_use_dio(iocb, from)) { iocb->ki_flags &= ~IOCB_DIRECT; - ret = iomap_file_buffered_write(iocb, from, &ntfs_iomap_ops, + ret = iomap_file_buffered_write(iocb, from, ntfs_iomap_next, &ntfs_iomap_folio_ops, NULL); inode_unlock(inode); @@ -1330,7 +1330,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) goto out; } - ret = iomap_dio_rw(iocb, from, &ntfs_iomap_ops, NULL, + ret = iomap_dio_rw(iocb, from, ntfs_iomap_next, NULL, IOMAP_DIO_FORCE_WAIT, NULL, 0); if (ret == -ENOTBLK) { @@ -1343,7 +1343,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) vbo = iocb->ki_pos; iocb->ki_flags &= ~IOCB_DIRECT; - err = iomap_file_buffered_write(iocb, from, &ntfs_iomap_ops, + err = iomap_file_buffered_write(iocb, from, ntfs_iomap_next, &ntfs_iomap_folio_ops, NULL); if (err < 0) { ret = err; @@ -1493,7 +1493,7 @@ int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, inode_lock_shared(inode); - err = iomap_fiemap(inode, fieinfo, start, len, &ntfs_iomap_ops); + err = iomap_fiemap(inode, fieinfo, start, len, ntfs_iomap_next); inode_unlock_shared(inode); return err; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 43d5e83403aa42..45f894d182dde5 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -788,7 +788,7 @@ static sector_t ntfs_bmap(struct address_space *mapping, sector_t block) ni_allocate_da_blocks(ni); } - return iomap_bmap(mapping, block, &ntfs_iomap_ops); + return iomap_bmap(mapping, block, ntfs_iomap_next); } static void ntfs_iomap_read_end_io(struct bio *bio) @@ -860,7 +860,7 @@ static int ntfs_read_folio(struct file *file, struct folio *folio) return err; } - iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL); + iomap_read_folio(ntfs_iomap_next, &ctx, NULL); return 0; } @@ -884,7 +884,7 @@ static void ntfs_readahead(struct readahead_control *rac) return; } - iomap_readahead(&ntfs_iomap_ops, &ctx, NULL); + iomap_readahead(ntfs_iomap_next, &ctx, NULL); } int ntfs_set_size(struct inode *inode, u64 new_size) @@ -2336,12 +2336,7 @@ const struct address_space_operations ntfs_aops_cmpr = { .invalidate_folio = iomap_invalidate_folio, }; -static DEFINE_IOMAP_ITER_NEXT_END(ntfs_iomap_next, ntfs_iomap_begin, - ntfs_iomap_end); - -const struct iomap_ops ntfs_iomap_ops = { - .iomap_next = ntfs_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT_END(ntfs_iomap_next, ntfs_iomap_begin, ntfs_iomap_end); const struct iomap_write_ops ntfs_iomap_folio_ops = { .put_folio = ntfs_iomap_put_folio, diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index f400cf94d05bad..16e7eab3e16dea 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -814,7 +815,7 @@ int ntfs_create_inode(const struct mnt_idmap *idmap, struct inode *dir, int ntfs_link_inode(struct inode *inode, struct dentry *dentry); int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry); void ntfs_evict_inode(struct inode *inode); -extern const struct iomap_ops ntfs_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(ntfs_iomap_next); extern const struct iomap_write_ops ntfs_iomap_folio_ops; extern const struct inode_operations ntfs_link_inode_operations; extern const struct address_space_operations ntfs_aops; diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index b45adc39aacca9..7a18e71b507b34 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -269,6 +269,8 @@ struct o2hb_region { struct list_head hr_handler_list; /* Serializes timeout arming against failed-start and teardown. */ struct mutex hr_arming_mutex; + /* Serializes the dev, block_bytes, start_block and blocks attributes. */ + struct mutex hr_dev_mutex; bool hr_stopping; /* last hb status, 0 for success, other value for error. */ @@ -1681,6 +1683,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item, unsigned long block_bytes; unsigned int block_bits; + guard(mutex)(®->hr_dev_mutex); if (reg->hr_bdev_file) return -EINVAL; @@ -1710,6 +1713,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item, char *p = (char *)page; ssize_t ret; + guard(mutex)(®->hr_dev_mutex); if (reg->hr_bdev_file) return -EINVAL; @@ -1736,6 +1740,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item, char *p = (char *)page; int ret; + guard(mutex)(®->hr_dev_mutex); if (reg->hr_bdev_file) return -EINVAL; @@ -1753,10 +1758,12 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item, static ssize_t o2hb_region_dev_show(struct config_item *item, char *page) { + struct o2hb_region *reg = to_o2hb_region(item); unsigned int ret = 0; - if (to_o2hb_region(item)->hr_bdev_file) - ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item))); + guard(mutex)(®->hr_dev_mutex); + if (reg->hr_bdev_file) + ret = sprintf(page, "%pg\n", reg_bdev(reg)); return ret; } @@ -1872,11 +1879,9 @@ static int o2hb_populate_slot_data(struct o2hb_region *reg) * this is acting as commit; we set up all of hr_bdev_file and hr_task or * nothing */ -static ssize_t o2hb_region_dev_store(struct config_item *item, - const char *page, - size_t count) +static ssize_t __o2hb_region_dev_store(struct o2hb_region *reg, + const char *page, size_t count) { - struct o2hb_region *reg = to_o2hb_region(item); struct task_struct *hb_task; long fd; int sectsize; @@ -1884,6 +1889,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, ssize_t ret = -EINVAL; int live_threshold; + lockdep_assert_held(®->hr_dev_mutex); + if (reg->hr_bdev_file) return -EINVAL; @@ -1987,9 +1994,15 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, wake_up_process(hb_task); + /* + * Don't hold hr_dev_mutex across the wait, which can take seconds. + * hr_bdev_file is already set, so other writers still get -EINVAL. + */ + mutex_unlock(®->hr_dev_mutex); ret = wait_event_interruptible(o2hb_steady_queue, atomic_read(®->hr_steady_iterations) == 0 || reg->hr_node_deleted); + mutex_lock(®->hr_dev_mutex); if (ret) { atomic_set(®->hr_steady_iterations, 0); reg->hr_aborted_start = 1; @@ -2041,6 +2054,20 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, return ret; } +static ssize_t o2hb_region_dev_store(struct config_item *item, + const char *page, + size_t count) +{ + struct o2hb_region *reg = to_o2hb_region(item); + ssize_t ret; + + mutex_lock(®->hr_dev_mutex); + ret = __o2hb_region_dev_store(reg, page, count); + mutex_unlock(®->hr_dev_mutex); + + return ret; +} + static ssize_t o2hb_region_pid_show(struct config_item *item, char *page) { struct o2hb_region *reg = to_o2hb_region(item); @@ -2143,6 +2170,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g INIT_LIST_HEAD(®->hr_all_item); mutex_init(®->hr_arming_mutex); + mutex_init(®->hr_dev_mutex); reg->hr_stopping = true; INIT_DELAYED_WORK(®->hr_write_timeout_work, o2hb_write_timeout); INIT_DELAYED_WORK(®->hr_nego_timeout_work, o2hb_nego_timeout); diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c index 8b3830b601ba6e..0eaf2c4a6989ec 100644 --- a/fs/ocfs2/cluster/tcp.c +++ b/fs/ocfs2/cluster/tcp.c @@ -393,6 +393,9 @@ static void sc_kref_release(struct kref *kref) sclog(sc, "releasing\n"); + /* Unlink before freeing anything the debugfs readers dereference. */ + o2net_debug_del_sc(sc); + if (sc->sc_sock) { sock_release(sc->sc_sock); sc->sc_sock = NULL; @@ -402,8 +405,6 @@ static void sc_kref_release(struct kref *kref) o2nm_node_put(sc->sc_node); sc->sc_node = NULL; - o2net_debug_del_sc(sc); - if (sc->sc_page) __free_page(sc->sc_page); kfree(sc); diff --git a/fs/ocfs2/dcache.h b/fs/ocfs2/dcache.h index 7f246c5692d82c..046ab9a8076921 100644 --- a/fs/ocfs2/dcache.h +++ b/fs/ocfs2/dcache.h @@ -17,9 +17,8 @@ struct ocfs2_dentry_lock { u64 dl_parent_blkno; /* - * The ocfs2_dentry_lock keeps an inode reference until - * dl_lockres has been destroyed. This is usually done in - * ->d_iput() anyway, so there should be minimal impact. + * The inode reference is dropped before dl_lockres is unlocked. + * Callbacks must not use it to find the mount context during teardown. */ struct inode *dl_inode; struct ocfs2_lock_res dl_lockres; diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c index 612969867ff924..ea48c013f7fbbe 100644 --- a/fs/ocfs2/dlm/dlmmaster.c +++ b/fs/ocfs2/dlm/dlmmaster.c @@ -2525,6 +2525,52 @@ static int dlm_is_lockres_migratable(struct dlm_ctxt *dlm, */ +/* + * Drop the sender's references on a migration MLE after the attempt has + * failed. The finishing assert from the target may already have unlinked + * the MLE and consumed its base reference; decide under the locks the + * assert handler holds, and only drop the base reference while the MLE is + * still hashed. Returns true when the assert got there first: the target + * has become the master, so the caller must complete the migration. + */ +static bool dlm_put_migration_mle(struct dlm_ctxt *dlm, + struct dlm_master_list_entry *mle) +{ + bool asserted; + + spin_lock(&dlm->spinlock); + spin_lock(&dlm->master_lock); + __dlm_mle_detach_hb_events(dlm, mle); + asserted = hlist_unhashed(&mle->master_hash_node); + if (!asserted) { + __dlm_unlink_mle(dlm, mle); + __dlm_put_mle(mle); + } + spin_unlock(&dlm->master_lock); + spin_unlock(&dlm->spinlock); + + dlm_put_mle_inuse(mle); + return asserted; +} + +/* + * The finishing assert got there first: it switched the owner to the + * target and cleared DLM_LOCK_RES_MIGRATING. Drop the other nodes' locks + * as a completed migration does, unless recovery has taken the lockres + * over since, and let the usage be recalculated. + */ +static void dlm_migrate_lockres_asserted(struct dlm_ctxt *dlm, + struct dlm_lock_resource *res, + u8 target) +{ + spin_lock(&res->spinlock); + if (res->owner == target) + dlm_remove_nonlocal_locks(dlm, res); + spin_unlock(&res->spinlock); + + dlm_lockres_calc_usage(dlm, res); +} + static int dlm_migrate_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, u8 target) { @@ -2609,9 +2655,10 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm, if (ret < 0) { if (mle_added) { - dlm_mle_detach_hb_events(dlm, mle); - dlm_put_mle(mle); - dlm_put_mle_inuse(mle); + if (dlm_put_migration_mle(dlm, mle)) { + dlm_migrate_lockres_asserted(dlm, res, target); + ret = 0; + } } else if (mle) { kmem_cache_free(dlm_mle_cache, mle); mle = NULL; @@ -2640,9 +2687,11 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm, mlog(0, "migration to node %u failed with %d\n", target, ret); /* migration failed, detach and clean up mle */ - dlm_mle_detach_hb_events(dlm, mle); - dlm_put_mle(mle); - dlm_put_mle_inuse(mle); + if (dlm_put_migration_mle(dlm, mle)) { + dlm_migrate_lockres_asserted(dlm, res, target); + ret = 0; + goto leave; + } spin_lock(&res->spinlock); res->state &= ~DLM_LOCK_RES_MIGRATING; wake = 1; @@ -2686,9 +2735,12 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm, res->lockname.name, target); ret = -EINVAL; /* migration failed, detach and clean up mle */ - dlm_mle_detach_hb_events(dlm, mle); - dlm_put_mle(mle); - dlm_put_mle_inuse(mle); + if (dlm_put_migration_mle(dlm, mle)) { + dlm_migrate_lockres_asserted(dlm, res, + target); + ret = 0; + goto leave; + } spin_lock(&res->spinlock); res->state &= ~DLM_LOCK_RES_MIGRATING; wake = 1; diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index 88d94646608330..c281902e3becec 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -58,7 +58,6 @@ struct ocfs2_mask_waiter { #endif }; -static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres); @@ -258,7 +257,6 @@ static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { }; static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags = 0, @@ -309,7 +307,7 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res { BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY); - return (struct ocfs2_dentry_lock *)lockres->l_priv; + return container_of(lockres, struct ocfs2_dentry_lock, dl_lockres); } static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo(struct ocfs2_lock_res *lockres) @@ -610,13 +608,6 @@ static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres) return be64_to_cpu(inode_blkno_be); } -static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres) -{ - struct ocfs2_dentry_lock *dl = lockres->l_priv; - - return OCFS2_SB(dl->dl_inode->i_sb); -} - void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl, u64 parent, struct inode *inode) { @@ -624,6 +615,7 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl, u64 inode_blkno = OCFS2_I(inode)->ip_blkno; __be64 inode_blkno_be = cpu_to_be64(inode_blkno); struct ocfs2_lock_res *lockres = &dl->dl_lockres; + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); ocfs2_lock_res_init_once(lockres); @@ -652,9 +644,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl, memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be, sizeof(__be64)); - ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres, + ocfs2_lock_res_init_common(osb, lockres, OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops, - dl); + osb); } static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res, @@ -3356,6 +3348,14 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb) { struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug; + /* + * Drain the readers before the cluster stack goes away: the + * locking_state reader resolves ocfs2_dlm_lvb() through the + * stack. Every caller removes the parent directory later. + */ + debugfs_lookup_and_remove("locking_state", osb->osb_debug_root); + debugfs_lookup_and_remove("locking_filter", osb->osb_debug_root); + if (dlm_debug) ocfs2_put_dlm_debug(dlm_debug); } @@ -3370,8 +3370,6 @@ int ocfs2_dlm_init(struct ocfs2_super *osb) goto local; } - ocfs2_dlm_init_debug(osb); - /* launch downconvert thread */ osb->dc_task = kthread_run(ocfs2_downconvert_thread, osb, "ocfs2dc-%s", osb->uuid_str); @@ -3411,9 +3409,10 @@ int ocfs2_dlm_init(struct ocfs2_super *osb) ocfs2_orphan_scan_lock_res_init(&osb->osb_orphan_scan.os_lockres, osb); osb->cconn = conn; + if (conn) + ocfs2_dlm_init_debug(osb); bail: if (status < 0) { - ocfs2_dlm_shutdown_debug(osb); if (osb->dc_task) kthread_stop(osb->dc_task); } @@ -3443,10 +3442,11 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb, ocfs2_lock_res_free(&osb->osb_orphan_scan.os_lockres); if (osb->cconn) { + /* The disconnect below may release the selected stack. */ + ocfs2_dlm_shutdown_debug(osb); + ocfs2_cluster_disconnect(osb->cconn, hangup_pending); osb->cconn = NULL; - - ocfs2_dlm_shutdown_debug(osb); } } diff --git a/fs/ocfs2/filecheck.c b/fs/ocfs2/filecheck.c index 75334e4bd0823f..e3b79bc749f565 100644 --- a/fs/ocfs2/filecheck.c +++ b/fs/ocfs2/filecheck.c @@ -189,6 +189,8 @@ int ocfs2_filecheck_create_sysfs(struct ocfs2_super *osb) /* Mount failure still calls ocfs2_filecheck_remove_sysfs(). */ entry->fs_fcheck = NULL; kobject_put(&entry->fs_kobj); + /* Keep ocfs2_super alive until the kobject is released. */ + wait_for_completion(&entry->fs_kobj_unregister); kfree(fcheck); return ret; } diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index cc60db6b97060c..cbb44e280d4bb5 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -227,13 +227,22 @@ void ocfs2_recovery_disable_quota(struct ocfs2_super *osb) ocfs2_recovery_disable(osb, OCFS2_REC_QUOTA_WANT_DISABLE); } +/* Stop producers and drain completion work without freeing recovery state. */ +void ocfs2_recovery_stop(struct ocfs2_super *osb) +{ + ocfs2_recovery_disable(osb, OCFS2_REC_WANT_DISABLE); +} + void ocfs2_recovery_exit(struct ocfs2_super *osb) { struct ocfs2_recovery_map *rm; - /* disable any new recovery threads and wait for any currently - * running ones to exit. Do this before setting the vol_state. */ - ocfs2_recovery_disable(osb, OCFS2_REC_WANT_DISABLE); + /* + * Disable producers and drain work before freeing recovery state. + * Do this before setting vol_state to VOLUME_DISMOUNTED: completion + * work may still be waiting in __ocfs2_wait_on_mount(). + */ + ocfs2_recovery_stop(osb); /* * Now that recovery is shut down, and the osb is about to be diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h index 19fc920d26b1cd..4b52bf7b0938e6 100644 --- a/fs/ocfs2/journal.h +++ b/fs/ocfs2/journal.h @@ -147,6 +147,7 @@ void ocfs2_complete_recovery(struct work_struct *work); void ocfs2_wait_for_recovery(struct ocfs2_super *osb); int ocfs2_recovery_init(struct ocfs2_super *osb); +void ocfs2_recovery_stop(struct ocfs2_super *osb); void ocfs2_recovery_exit(struct ocfs2_super *osb); void ocfs2_recovery_disable_quota(struct ocfs2_super *osb); diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index ad1678ee7cc461..93b45531bf7d8e 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -907,6 +907,30 @@ static int __ocfs2_move_extents_range(struct buffer_head *di_bh, return ret; } +static int ocfs2_validate_and_adjust_move_range(struct inode *inode, + struct ocfs2_move_extents *range) +{ + u64 i_size = i_size_read(inode); + + if (range->me_start > i_size) + return -EINVAL; + + if (range->me_len > i_size - range->me_start) + range->me_len = i_size - range->me_start; + + /* + * The default threshold for defragmentation is 1 MiB, which + * matches the maximum OCFS2 cluster size. + */ + if (!range->me_threshold) + range->me_threshold = 1024 * 1024; + + if (range->me_threshold > i_size) + range->me_threshold = i_size; + + return 0; +} + static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) { int status; @@ -936,6 +960,21 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) goto out_rw_unlock; } + status = ocfs2_validate_and_adjust_move_range(inode, context->range); + if (status) { + mlog_errno(status); + goto out_inode_unlock; + } + + /* The goal check depends on the adjusted range length. */ + if (!context->auto_defrag) { + status = ocfs2_validate_and_adjust_move_goal(inode, context->range); + if (status) { + mlog_errno(status); + goto out_inode_unlock; + } + } + /* * remember ip_xattr_sem also needs to be held if necessary */ @@ -1028,27 +1067,8 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) goto out_free; } - if (range.me_start > i_size_read(inode)) { - status = -EINVAL; - goto out_free; - } - - if (range.me_start + range.me_len > i_size_read(inode)) - range.me_len = i_size_read(inode) - range.me_start; - context->range = ⦥ - /* - * ok, the default threshold for the defragmentation - * is 1M, since our maximum clustersize was 1M also. - * any thought? - */ - if (!range.me_threshold) - range.me_threshold = 1024 * 1024; - - if (range.me_threshold > i_size_read(inode)) - range.me_threshold = i_size_read(inode); - if (range.me_flags & ~(OCFS2_MOVE_EXT_FL_AUTO_DEFRAG | OCFS2_MOVE_EXT_FL_PART_DEFRAG)) { status = -EINVAL; @@ -1060,23 +1080,11 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG) context->partial = 1; - } else { - /* - * first best-effort attempt to validate and adjust the goal - * (physical address in block), while it can't guarantee later - * operation can succeed all the time since global_bitmap may - * change a bit over time. - */ - - status = ocfs2_validate_and_adjust_move_goal(inode, &range); - if (status) - goto out_copy; } status = ocfs2_move_extents(context); if (status) mlog_errno(status); -out_copy: /* * movement/defragmentation may end up being partially completed, * that's the reason why we need to return userspace the finished diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 0af2245ae30369..0781c5cbdb1199 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -1831,6 +1831,9 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err) /* Wait for worker to be done with the work structure in osb */ cancel_work_sync(&osb->dquot_drop_work); + /* Stop recovery producers before releasing their local allocators. */ + ocfs2_recovery_stop(osb); + ocfs2_shutdown_local_alloc(osb); ocfs2_truncate_log_shutdown(osb); @@ -2069,8 +2072,7 @@ static int ocfs2_initialize_super(struct super_block *sb, } osb->slot_recovery_generations = - kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations), - GFP_KERNEL); + kzalloc_objs(*osb->slot_recovery_generations, osb->max_slots); if (!osb->slot_recovery_generations) { status = -ENOMEM; mlog_errno(status); @@ -2078,9 +2080,8 @@ static int ocfs2_initialize_super(struct super_block *sb, } init_waitqueue_head(&osb->osb_wipe_event); - osb->osb_orphan_wipes = kcalloc(osb->max_slots, - sizeof(*osb->osb_orphan_wipes), - GFP_KERNEL); + osb->osb_orphan_wipes = kzalloc_objs(*osb->osb_orphan_wipes, + osb->max_slots); if (!osb->osb_orphan_wipes) { status = -ENOMEM; mlog_errno(status); diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index b2bd06083a14d9..71e5986bafaab2 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -275,6 +275,7 @@ static int ocfs2_xattr_tree_list_index_block(struct inode *inode, size_t buffer_size); static int ocfs2_xattr_create_index_block(struct inode *inode, + struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt); @@ -3375,7 +3376,7 @@ static int ocfs2_xattr_block_set(struct inode *inode, else if ((ret != -ENOSPC) || ctxt->set_abort) goto end; else { - ret = ocfs2_xattr_create_index_block(inode, xs, ctxt); + ret = ocfs2_xattr_create_index_block(inode, xi, xs, ctxt); if (ret) goto end; } @@ -4703,6 +4704,21 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode, for (i = 0; i < blks; i++) memset(bucket_block(bucket, i), 0, blocksize); + /* + * An empty block has no names or values to carry over, and the + * xh_entries[count - 1] below would be xh_entries[-1]. Leave the + * bucket empty, but carry over the hash ocfs2_xa_remove_entry() left + * in the block's xh_entries[0] so that the bucket still holds the key + * it is looked up by. + */ + if (!count) { + xh->xh_num_buckets = cpu_to_le16(1); + xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); + xh->xh_entries[0].xe_name_hash = + xb_xh->xh_entries[0].xe_name_hash; + return; + } + /* * Since the xe_name_offset is based on ocfs2_xattr_header, * there is a offset change corresponding to the change of @@ -4749,13 +4765,10 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode, * real place of the xattr. */ static void ocfs2_xattr_update_xattr_search(struct inode *inode, - struct ocfs2_xattr_search *xs, - struct buffer_head *old_bh) + struct ocfs2_xattr_info *xi, + struct ocfs2_xattr_search *xs) { - char *buf = old_bh->b_data; - struct ocfs2_xattr_block *old_xb = (struct ocfs2_xattr_block *)buf; - struct ocfs2_xattr_header *old_xh = &old_xb->xb_attrs.xb_header; - int i; + int i, count; xs->header = bucket_xh(xs->bucket); xs->base = bucket_block(xs->bucket, 0); @@ -4764,8 +4777,43 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode, if (xs->not_found) return; - i = xs->here - old_xh->xh_entries; - xs->here = &xs->header->xh_entries[i]; + /* + * A block holds its entries in insertion order while a bucket holds + * them by name hash, so ocfs2_cp_xattr_block_to_bucket() sorted the + * copies and the index this entry had in the block no longer says + * where it is. It copied every entry and every name unchanged, and + * (type, name) pairs are unique within a block, so find it again by + * name. + * + * Search for the name being set, not for the name xs->here carries. + * A failed set may have removed that entry, and ocfs2_xa_remove_entry() + * then memmoves its successor into the slot. Comparing every entry + * rather than narrowing on the hash also finds an entry stored under + * the legacy signed hash, which ocfs2_find_xe_in_bucket() would skip. + */ + count = le16_to_cpu(xs->header->xh_count); + for (i = 0; i < count; i++) { + struct ocfs2_xattr_entry *xe = &xs->header->xh_entries[i]; + + if (ocfs2_xattr_get_type(xe) != xi->xi_name_index) + continue; + if (xe->xe_name_len != xi->xi_name_len) + continue; + if (!memcmp(xs->base + le16_to_cpu(xe->xe_name_offset), + xi->xi_name, xi->xi_name_len)) { + xs->here = xe; + return; + } + } + + /* + * The entry did not survive the failed set, so this has become an + * insert. Point xs->here back inside the bucket: it still refers to + * the block being converted, which is about to be rewritten as a tree + * root. + */ + xs->not_found = -ENODATA; + xs->here = xs->header->xh_entries; } /* @@ -4773,6 +4821,7 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode, * is allocated and the xattr block header is rewritten. */ static int ocfs2_xattr_create_index_block(struct inode *inode, + struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { @@ -4834,7 +4883,7 @@ static int ocfs2_xattr_create_index_block(struct inode *inode, ocfs2_cp_xattr_block_to_bucket(inode, xb_bh, xs->bucket); ocfs2_xattr_bucket_journal_dirty(handle, xs->bucket); - ocfs2_xattr_update_xattr_search(inode, xs, xb_bh); + ocfs2_xattr_update_xattr_search(inode, xi, xs); /* Change from ocfs2_xattr_header to ocfs2_xattr_tree_root */ memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize - @@ -5194,7 +5243,15 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, start = ocfs2_xattr_find_divide_pos(xh); if (start == count) { - xe = &xh->xh_entries[start-1]; + /* + * start == count means every entry shares one hash, so the + * first of them carries it too. An empty bucket has no + * entries[start - 1], but its entries[0] still carries the + * bucket key: either the hash ocfs2_xa_remove_entry() + * deliberately leaves behind, or the sentinel a previous + * divide wrote. + */ + xe = &xh->xh_entries[0]; /* * initialized a new empty bucket here. @@ -6027,11 +6084,20 @@ static int ocfs2_check_xattr_bucket_collision(struct ocfs2_xattr_bucket *bucket, u32 name_hash) { struct ocfs2_xattr_header *xh = bucket_xh(bucket); + u16 count = le16_to_cpu(xh->xh_count); + + /* + * An empty bucket keeps the hash of the entry that was removed in + * xh_entries[0] so that it can still be found, but it holds no + * entries to collide with. + */ + if (!count) + return 0; if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0; - if (xh->xh_entries[le16_to_cpu(xh->xh_count) - 1].xe_name_hash == + if (xh->xh_entries[count - 1].xe_name_hash == xh->xh_entries[0].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n", @@ -6052,13 +6118,18 @@ static int ocfs2_xattr_set_entry_bucket(struct inode *inode, struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { - int ret; + int ret, found = 0; + u16 xe_index; + u32 name_hash; struct ocfs2_xa_loc loc; trace_ocfs2_xattr_set_entry_bucket(xi->xi_name); ocfs2_init_xattr_bucket_xa_loc(&loc, xs->bucket, xs->not_found ? NULL : xs->here); + /* Defragmenting below may move this entry, so remember its hash. */ + name_hash = loc.xl_entry ? le32_to_cpu(loc.xl_entry->xe_name_hash) : 0; + ret = ocfs2_xa_set(&loc, xi, ctxt); if (!ret) { xs->here = loc.xl_entry; @@ -6077,6 +6148,29 @@ static int ocfs2_xattr_set_entry_bucket(struct inode *inode, goto out; } + /* + * ocfs2_defrag_xattr_bucket() sorts the entries by name hash and + * lib/sort.c is not stable, so entries sharing a hash may have traded + * slots. Look the entry up again before writing through it. + */ + if (loc.xl_entry) { + ret = ocfs2_find_xe_in_bucket(inode, xs->bucket, + xi->xi_name_index, xi->xi_name, + name_hash, &xe_index, &found); + if (ret) { + mlog_errno(ret); + goto out; + } + if (!found) { + mlog(ML_ERROR, "xattr entry not found in bucket %llu after defrag\n", + (unsigned long long)bucket_blkno(xs->bucket)); + ret = -EFSCORRUPTED; + goto out; + } + loc.xl_entry = &bucket_xh(xs->bucket)->xh_entries[xe_index]; + xs->here = loc.xl_entry; + } + ret = ocfs2_xa_set(&loc, xi, ctxt); if (!ret) { xs->here = loc.xl_entry; @@ -6100,6 +6194,22 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode, trace_ocfs2_xattr_set_entry_index_block(xi->xi_name); + /* + * An existing entry keeps the hash it was stored under, and that is + * the hash a split has to work with. A new entry is stored under the + * unsigned one, which is what ocfs2_xa_add_entry() will write. + * + * Read it before the set below. Filling the bucket may defragment it, + * and ocfs2_defrag_xattr_bucket() re-sorts the entry array, so + * afterwards xs->here only denotes whichever entry the sort left in + * that slot. + */ + if (xs->not_found) + name_hash = ocfs2_xattr_name_hash(inode, xi->xi_name, + xi->xi_name_len); + else + name_hash = le32_to_cpu(xs->here->xe_name_hash); + ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt); if (!ret) goto out; @@ -6115,17 +6225,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode, * the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. - * - * An existing entry keeps the hash it was stored under, and that is - * the hash a split has to work with. A new entry is stored under the - * unsigned one, which is what ocfs2_xa_add_entry() will write. */ - if (xs->not_found) - name_hash = ocfs2_xattr_name_hash(inode, xi->xi_name, - xi->xi_name_len); - else - name_hash = le32_to_cpu(xs->here->xe_name_hash); - ret = ocfs2_check_xattr_bucket_collision(xs->bucket, name_hash); if (ret) { mlog_errno(ret); @@ -7798,7 +7898,7 @@ static int ocfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array for (xattr = xattr_array; xattr->name != NULL; xattr++) count++; - xattrs = kcalloc(count, sizeof(*xattrs), GFP_NOFS); + xattrs = kzalloc_objs(*xattrs, count, GFP_NOFS); if (!xattrs) return -ENOMEM; diff --git a/fs/open.c b/fs/open.c index e43f02ff64acbe..bb484b07390ac3 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1172,6 +1172,7 @@ struct file *dentry_open_nonotify(const struct path *path, int flags, } return f; } +EXPORT_SYMBOL_GPL(dentry_open_nonotify); /** * kernel_file_open - open a file for kernel internal use diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 1792e41146216d..8fec18dc5fc751 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -74,39 +74,34 @@ static struct dentry *ovl_start_creating_temp(struct ovl_fs *ofs, &QSTR(name)); } +/* + * The whiteout is the source of a rename, so it has to be hashed. + * ovl_create_temp() takes care of that for a casefolded workdir. + */ static struct dentry *ovl_whiteout(struct ovl_fs *ofs) { int err; struct dentry *whiteout, *link; struct dentry *workdir = ofs->workdir; - struct inode *wdir = workdir->d_inode; - char name[OVL_TEMPNAME_SIZE]; guard(mutex)(&ofs->whiteout_lock); if (!ofs->whiteout) { - whiteout = ovl_start_creating_temp(ofs, workdir, name); + whiteout = ovl_create_temp(ofs, workdir, &(struct ovl_cattr) { + .mode = S_IFCHR | WHITEOUT_MODE, + .rdev = WHITEOUT_DEV }); if (IS_ERR(whiteout)) return whiteout; - err = ovl_do_whiteout(ofs, wdir, whiteout); - if (!err) - ofs->whiteout = dget(whiteout); - end_creating(whiteout); - if (err) - return ERR_PTR(err); + ofs->whiteout = whiteout; } if (!ofs->no_shared_whiteout) { - link = ovl_start_creating_temp(ofs, workdir, name); - if (IS_ERR(link)) + link = ovl_create_temp(ofs, workdir, &(struct ovl_cattr) { + .hardlink = ofs->whiteout }); + if (!IS_ERR(link)) return link; - err = ovl_do_link(ofs, ofs->whiteout, wdir, link); - if (!err) - whiteout = dget(link); - end_creating(link); - if (!err) - return whiteout; + err = PTR_ERR(link); if (err != -EMLINK) { pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%u)\n", ofs->whiteout->d_inode->i_nlink, @@ -120,9 +115,10 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs) } int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir, - struct dentry *dentry) + struct dentry *dentry, const struct qstr *name) { struct dentry *whiteout; + struct qstr last = QSTR_LEN(name->name, name->len); struct renamedata rd = {}; int err; int flags = 0; @@ -139,9 +135,17 @@ int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir, rd.old_parent = ofs->workdir; rd.new_parent = dir; rd.flags = flags; - err = start_renaming_two_dentries(&rd, whiteout, dentry); + /* + * The caller looked up @dentry by @name without a lock on @dir, and a + * casefolded directory leaves a negative dentry unhashed. Nothing tells + * if such a dentry is still valid, so look up @name again with @dir locked. + */ + err = start_renaming_dentry(&rd, 0, whiteout, &last); if (!err) { - err = ovl_do_rename_rd(&rd); + if (d_inode(rd.new_dentry) != d_inode(dentry)) + err = -ESTALE; + else + err = ovl_do_rename_rd(&rd); end_renaming(&rd); } if (err) @@ -364,7 +368,7 @@ static bool ovl_type_origin(struct dentry *dentry) } static int ovl_create_upper(struct dentry *dentry, struct inode *inode, - struct ovl_cattr *attr) + struct ovl_cattr *attr, bool origin) { struct ovl_fs *ofs = OVL_FS(dentry->d_sb); struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); @@ -389,7 +393,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode, ovl_set_opaque(dentry, newdentry); } - ovl_dir_modified(dentry->d_parent, false); + ovl_dir_modified(dentry->d_parent, origin); err = ovl_instantiate(dentry, inode, newdentry, !!attr->hardlink, NULL); if (err) goto out_cleanup; @@ -487,7 +491,7 @@ static int ovl_set_upper_acl(struct ovl_fs *ofs, struct dentry *upperdentry, } static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, - struct ovl_cattr *cattr) + struct ovl_cattr *cattr, bool origin) { struct ovl_fs *ofs = OVL_FS(dentry->d_sb); struct dentry *workdir = ovl_workdir(dentry); @@ -578,7 +582,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, if (err) goto out_cleanup_unlocked; } - ovl_dir_modified(dentry->d_parent, false); + ovl_dir_modified(dentry->d_parent, origin); err = ovl_instantiate(dentry, inode, newdentry, hardlink, NULL); if (err) { ovl_cleanup(ofs, upperdir, newdentry); @@ -643,12 +647,12 @@ DEFINE_CLASS(ovl_override_creator_creds, static int ovl_create_handle_whiteouts(struct dentry *dentry, struct inode *inode, - struct ovl_cattr *attr) + struct ovl_cattr *attr, bool origin) { if (!ovl_dentry_is_whiteout(dentry)) - return ovl_create_upper(dentry, inode, attr); + return ovl_create_upper(dentry, inode, attr, origin); - return ovl_create_over_whiteout(dentry, inode, attr); + return ovl_create_over_whiteout(dentry, inode, attr, origin); } static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, @@ -683,12 +687,14 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, */ if (attr->hardlink) - return ovl_create_handle_whiteouts(dentry, inode, attr); + return ovl_create_handle_whiteouts(dentry, inode, attr, + origin); scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, attr->mode) { if (IS_ERR(cred)) return PTR_ERR(cred); - return ovl_create_handle_whiteouts(dentry, inode, attr); + return ovl_create_handle_whiteouts(dentry, inode, attr, + origin); } } return err; @@ -847,7 +853,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, goto out_dput_upper; } - err = ovl_cleanup_and_whiteout(ofs, upperdir, upper); + err = ovl_cleanup_and_whiteout(ofs, upperdir, upper, &dentry->d_name); if (!err) ovl_dir_modified(dentry->d_parent, true); diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 9aae20c59608ae..bd998a3d8b95c0 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -713,9 +713,9 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, } } - /* Then lookup indexed upper/whiteout by origin fh */ + /* Then lookup indexed upper/whiteout by origin */ if (ovl_indexdir(sb)) { - index = ovl_get_index_fh(ofs, fh); + index = ovl_get_index_origin(ofs, origin.dentry); err = PTR_ERR(index); if (IS_ERR(index)) { index = NULL; diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index a11564e9075186..f1c6df39d0ae4e 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -658,6 +658,14 @@ int ovl_fileattr_set(const struct mnt_idmap *idmap, unsigned int flags; int err; + /* + * Lookup refuses a directory that does not agree with the casefold + * state of the mount. Only FS_IOC_SETFLAGS can ask for a change. + */ + if (S_ISDIR(inode->i_mode) && fa->flags_valid && + !!(fa->flags & FS_CASEFOLD_FL) != OVL_FS(inode->i_sb)->casefold) + return -EOPNOTSUPP; + err = ovl_copy_up(dentry); if (!err) { ovl_path_real(dentry, &upperpath); diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index c6127edb9be954..ddf60254888a04 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -27,6 +27,7 @@ struct ovl_lookup_data { bool last; char *redirect; char *upperredirect; + char *lowerdata_redirect; int metacopy; /* Referring to last redirect xattr */ bool absolute_redirect; @@ -39,13 +40,12 @@ static int ovl_check_redirect(const struct path *path, struct ovl_lookup_data *d char *buf; struct ovl_fs *ofs = OVL_FS(d->sb); - d->absolute_redirect = false; buf = ovl_get_redirect_xattr(ofs, path, prelen + strlen(post)); if (IS_ERR_OR_NULL(buf)) return PTR_ERR(buf); - if (buf[0] == '/') { - d->absolute_redirect = true; + d->absolute_redirect = buf[0] == '/'; + if (d->absolute_redirect) { /* * One of the ancestor path elements in an absolute path * lookup in ovl_lookup_layer() could have been opaque and @@ -781,14 +781,21 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin, return err; } -/* Lookup index by file handle for NFS export */ -struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh) +/* + * Lookup index by decoded origin for NFS export. + * + * The name of an index is the hex of the file handle that copy up encoded. + * The bytes of the handle to decode cannot be used as the name, because a + * lower fs may decode many handles to the same inode. For example, it may + * ignore the fid type, extra fid bytes or a zero generation. + */ +struct dentry *ovl_get_index_origin(struct ovl_fs *ofs, struct dentry *origin) { struct dentry *index; struct qstr name; int err; - err = ovl_get_index_name_fh(fh, &name); + err = ovl_get_index_name(ofs, origin, &name); if (err) return ERR_PTR(err); @@ -1040,6 +1047,14 @@ static int ovl_maybe_lookup_lowerdata(struct dentry *dentry) out_err: pr_warn_ratelimited("lazy lowerdata lookup failed (%pd2, err=%i)\n", dentry, err); + /* + * The data of a metacopy file is missing or is not a regular file in + * the data-only layers: the layers are corrupted. Do not return the + * error of the lookup (e.g. ENOENT) to the caller, it would make the + * file look like it does not exist. + */ + if (err != -ENOMEM) + err = -EIO; goto out; } @@ -1072,7 +1087,8 @@ static bool ovl_check_follow_redirect(struct ovl_lookup_data *d) pr_warn_ratelimited("refusing to follow metacopy origin for (%pd2)\n", d->dentry); return false; } - if ((d->redirect || d->upperredirect) && !ovl_redirect_follow(ofs)) { + /* Check follow to lower layer, redirects to lowerdata are not checked here */ + if ((d->redirect || d->upperredirect) && !ovl_redirect_follow_lower(ofs)) { pr_warn_ratelimited("refusing to follow redirect for (%pd2)\n", d->dentry); return false; } @@ -1090,13 +1106,26 @@ struct ovl_lookup_ctx { unsigned int ctr; }; +/* + * Without metacopy=on, the absolute redirect of a lower metacopy file is + * followed only into the data-only layers. + */ +static bool ovl_is_lowerdata_redirect(struct ovl_lookup_ctx *ctx, + struct ovl_lookup_data *d) +{ + struct ovl_fs *ofs = OVL_FS(d->sb); + + return ofs->numdatalayer && !ofs->config.metacopy && ctx->ctr && + d->metacopy && d->absolute_redirect; +} + static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data *d) { struct dentry *dentry = ctx->dentry; struct ovl_fs *ofs = OVL_FS(dentry->d_sb); struct ovl_entry *poe = OVL_E(dentry->d_parent); struct ovl_entry *roe = OVL_E(dentry->d_sb->s_root); - bool check_redirect = (ovl_redirect_follow(ofs) || ofs->numdatalayer); + bool check_redirect = ovl_redirect_follow(ofs); struct dentry *upperdir; struct dentry *this; struct dentry *origin = NULL; @@ -1227,6 +1256,10 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data ctx->ctr++; } + /* Lookup of lowerdata in the data-only layers only */ + if (ovl_is_lowerdata_redirect(ctx, d)) + d->stop = true; + if (d->stop) break; @@ -1244,6 +1277,8 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data if (d->metacopy && ctx->ctr && ofs->numdatalayer && d->absolute_redirect) { d->metacopy = 0; ctx->ctr++; + d->lowerdata_redirect = d->redirect; + d->redirect = NULL; } else if (!ovl_check_follow_redirect(d)) { err = -EPERM; return err; @@ -1360,24 +1395,32 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *ctx, struct ovl_lookup_data }; /* Store lowerdata redirect for lazy lookup */ - if (ctx->ctr > 1 && !d->is_dir && !ctx->stack[ctx->ctr - 1].dentry) { - oip.lowerdata_redirect = d->redirect; - d->redirect = NULL; - } + if (d->lowerdata_redirect) + oip.lowerdata_redirect = d->lowerdata_redirect; inode = ovl_get_inode(dentry->d_sb, &oip); if (IS_ERR(inode)) return PTR_ERR(inode); + d->lowerdata_redirect = NULL; + ctx->inode = inode; if (ctx->upperdentry && !uppermetacopy) ovl_set_flag(OVL_UPPERDATA, ctx->inode); if (metacopy_size > OVL_METACOPY_MIN_SIZE) ovl_set_flag(OVL_HAS_DIGEST, ctx->inode); - } - ovl_dentry_init_reval(dentry, ctx->upperdentry, OVL_I_E(ctx->inode)); + /* + * ovl_get_inode() puts ctx->upperdentry if it finds a cached + * inode, e.g. for another hard link, so use the upper dentry + * of the inode. + */ + ovl_dentry_init_reval(dentry, ovl_i_dentry_upper(inode), + OVL_I_E(inode)); + } else { + ovl_dentry_init_reval(dentry, NULL, NULL); + } return 0; } @@ -1387,7 +1430,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, { struct ovl_fs *ofs = OVL_FS(dentry->d_sb); struct ovl_entry *poe = OVL_E(dentry->d_parent); - bool check_redirect = (ovl_redirect_follow(ofs) || ofs->numdatalayer); + bool check_redirect = ovl_redirect_follow(ofs); int err; struct ovl_lookup_ctx ctx = { .dentry = dentry, @@ -1412,6 +1455,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, dput(ctx.index); ovl_stack_free(ctx.stack, ctx.ctr); kfree(d.redirect); + kfree(d.lowerdata_redirect); if (err) { ovl_free_entry(ctx.oe); diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 901335026a20cb..646f8ffc40aef2 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -76,9 +76,15 @@ enum ovl_entry_flag { }; enum { - OVL_REDIRECT_OFF, /* "off" mode is never used. In effect */ - OVL_REDIRECT_FOLLOW, /* ...it translates to either "follow" */ - OVL_REDIRECT_NOFOLLOW, /* ...or "nofollow". */ + /* + * "off" mode is never used after mount options are verified. + * In effect it translates to either "follow", "nofollow" or + * "followdata" (with data-only layers). + */ + OVL_REDIRECT_OFF, + OVL_REDIRECT_FOLLOW, + OVL_REDIRECT_FOLLOWDATA, + OVL_REDIRECT_NOFOLLOW, OVL_REDIRECT_ON, }; @@ -396,14 +402,6 @@ static inline int ovl_do_rename(struct ovl_fs *ofs, struct dentry *olddir, return ovl_do_rename_rd(&rd); } -static inline int ovl_do_whiteout(struct ovl_fs *ofs, - struct inode *dir, struct dentry *dentry) -{ - int err = vfs_whiteout(ovl_upper_mnt_idmap(ofs), dir, dentry); - pr_debug("whiteout(%pd2) = %i\n", dentry, err); - return err; -} - static inline struct file *ovl_do_tmpfile(struct ovl_fs *ofs, struct dentry *dentry, umode_t mode) { @@ -539,7 +537,14 @@ void ovl_dir_modified(struct dentry *dentry, bool impurity); u64 ovl_inode_version_get(struct inode *inode); bool ovl_is_whiteout(struct dentry *dentry); bool ovl_path_is_whiteout(struct ovl_fs *ofs, const struct path *path); -struct file *ovl_path_open(const struct path *path, int flags); +struct file *ovl_path_open_realfile(const struct file *user_file, + const struct path *path, int flags); + +static inline struct file *ovl_path_open(const struct path *path, int flags) +{ + return ovl_path_open_realfile(NULL, path, flags); +} + int ovl_copy_up_start(struct dentry *dentry, int flags); void ovl_copy_up_end(struct dentry *dentry); bool ovl_already_copied_up(struct dentry *dentry, int flags); @@ -583,6 +588,7 @@ static inline int ovl_set_impure_dir(struct dentry *dentry) bool ovl_inuse_trylock(struct dentry *dentry); void ovl_inuse_unlock(struct dentry *dentry); bool ovl_is_inuse(struct dentry *dentry); +void ovl_inuse_unlock_all(struct ovl_fs *ofs); bool ovl_need_index(struct dentry *dentry); int ovl_nlink_start(struct dentry *dentry); void ovl_nlink_end(struct dentry *dentry); @@ -633,11 +639,20 @@ static inline char ovl_get_opaquedir_val(struct ovl_fs *ofs, return ovl_get_dir_xattr_val(ofs, path, OVL_XATTR_OPAQUE); } +/* Are redirects followed into lower layers? */ +static inline bool ovl_redirect_follow_lower(struct ovl_fs *ofs) +{ + return ofs->config.redirect_mode == OVL_REDIRECT_FOLLOW || + ofs->config.redirect_mode == OVL_REDIRECT_ON; +} + +/* Are redirects followed into lower or lowerdata layers? */ static inline bool ovl_redirect_follow(struct ovl_fs *ofs) { return ofs->config.redirect_mode != OVL_REDIRECT_NOFOLLOW; } +/* Are redirects created in upper dir? */ static inline bool ovl_redirect_dir(struct ovl_fs *ofs) { return ofs->config.redirect_mode == OVL_REDIRECT_ON; @@ -751,7 +766,7 @@ int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); int ovl_get_index_name_fh(const struct ovl_fh *fh, struct qstr *name); int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin, struct qstr *name); -struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); +struct dentry *ovl_get_index_origin(struct ovl_fs *ofs, struct dentry *origin); struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, struct dentry *origin, bool verify); int ovl_path_next(int idx, struct dentry *dentry, struct path *path, @@ -899,7 +914,7 @@ static inline void ovl_copyflags(struct inode *from, struct inode *to) /* dir.c */ extern const struct inode_operations ovl_dir_inode_operations; int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir, - struct dentry *dentry); + struct dentry *dentry, const struct qstr *name); struct ovl_cattr { dev_t rdev; umode_t mode; diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index ac07e8769f9be6..5b2f1b930daad3 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -24,6 +24,8 @@ struct ovl_config { struct ovl_sb { struct super_block *sb; dev_t pseudo_dev; + /* Idmap of the first lower layer on this fs */ + const struct mnt_idmap *lower_idmap; /* Unusable (conflicting) uuid */ bool bad_uuid; /* Used as a lower layer (but maybe also as upper) */ diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 5a15e5478a6b87..d1ca4a9094f282 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -107,21 +107,40 @@ static int ovl_xino_def(void) const struct constant_table ovl_parameter_redirect_dir[] = { { "off", OVL_REDIRECT_OFF }, { "follow", OVL_REDIRECT_FOLLOW }, + { "followdata", OVL_REDIRECT_FOLLOWDATA }, { "nofollow", OVL_REDIRECT_NOFOLLOW }, { "on", OVL_REDIRECT_ON }, {} }; -static const char *ovl_redirect_mode(struct ovl_config *config) +static const char *ovl_redirect_mode_name(int redirect_mode) { - return ovl_parameter_redirect_dir[config->redirect_mode].name; + return ovl_parameter_redirect_dir[redirect_mode].name; } +const char *ovl_redirect_mode(struct ovl_config *config) +{ + return ovl_redirect_mode_name(config->redirect_mode); +} + +int ovl_redirect_follow_mode(bool follow_lower, size_t nr_data) +{ + if (ovl_redirect_always_follow && follow_lower) + return OVL_REDIRECT_FOLLOW; + + /* Data-only layers cannot be used without following redirects to them */ + return nr_data ? OVL_REDIRECT_FOLLOWDATA : OVL_REDIRECT_NOFOLLOW; +} + +/* + * The default for show_options() is resolved as if there are no data-only layers, + * so that redirect_dir=followdata, which is auto selected with data-only layers, + * is displayed in mount options. + */ static int ovl_redirect_mode_def(void) { - return ovl_redirect_dir_def ? OVL_REDIRECT_ON : - ovl_redirect_always_follow ? OVL_REDIRECT_FOLLOW : - OVL_REDIRECT_NOFOLLOW; + return ovl_redirect_dir_def ? OVL_REDIRECT_ON : + ovl_redirect_follow_mode(true, 0); } static const struct constant_table ovl_parameter_verity[] = { @@ -659,11 +678,6 @@ static int ovl_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_redirect_dir: config->redirect_mode = result.uint_32; - if (config->redirect_mode == OVL_REDIRECT_OFF) { - config->redirect_mode = ovl_redirect_always_follow ? - OVL_REDIRECT_FOLLOW : - OVL_REDIRECT_NOFOLLOW; - } ctx->set.redirect = true; break; case Opt_index: @@ -819,7 +833,13 @@ int ovl_init_fs_context(struct fs_context *fc) if (!ofs) goto out_err; - ofs->config.redirect_mode = ovl_redirect_mode_def(); + /* + * The module default determines only if new redirects are created in + * upper dir. If they are not, the redirect follow mode will be + * determined after parsing mount options. + */ + ofs->config.redirect_mode = ovl_redirect_dir_def ? + OVL_REDIRECT_ON : OVL_REDIRECT_OFF; ofs->config.index = ovl_index_def; ofs->config.uuid = ovl_uuid_def(); ofs->config.nfs_export = ovl_nfs_export_def; @@ -845,15 +865,12 @@ void ovl_free_fs(struct ovl_fs *ofs) struct vfsmount **mounts; unsigned i; + ovl_inuse_unlock_all(ofs); iput(ofs->workbasedir_trap); iput(ofs->workdir_trap); dput(ofs->whiteout); dput(ofs->workdir); - if (ofs->workdir_locked) - ovl_inuse_unlock(ofs->workbasedir); dput(ofs->workbasedir); - if (ofs->upperdir_locked) - ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root); /* Reuse ofs->config.lowerdirs as a vfsmount array before freeing it */ mounts = (struct vfsmount **) ofs->config.lowerdirs; @@ -880,6 +897,11 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, struct ovl_config *config) { struct ovl_opt_set set = ctx->set; + /* The requested redirect_dir=, for reporting conflicts with it */ + int redirect_opt = config->redirect_mode; + /* The redirect follow mode for redirect_dir=off and for the default */ + int follow_mode = ovl_redirect_follow_mode(!config->userxattr, + ctx->nr_data); /* Workdir/index are useless in non-upper mount */ if (!config->upperdir) { @@ -906,6 +928,13 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, config->uuid = OVL_UUID_NULL; } + /* + * Resolve redirect_dir=off to the default redirect follow mode. + * With userxattr, redirects are not followed to lower by default. + */ + if (config->redirect_mode == OVL_REDIRECT_OFF) + config->redirect_mode = follow_mode; + /* * This is to make the logic below simpler. It doesn't make any other * difference, since redirect_dir=on is only used for upper. @@ -917,7 +946,7 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, if (config->metacopy && config->redirect_mode != OVL_REDIRECT_ON) { if (set.metacopy && set.redirect) { pr_err("conflicting options: metacopy=on,redirect_dir=%s\n", - ovl_redirect_mode(config)); + ovl_redirect_mode_name(redirect_opt)); return -EINVAL; } if (set.redirect) { @@ -926,7 +955,7 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, * in this conflict. */ pr_info("disabling metacopy due to redirect_dir=%s\n", - ovl_redirect_mode(config)); + ovl_redirect_mode_name(redirect_opt)); config->metacopy = false; } else { /* Automatically enable redirect otherwise. */ @@ -934,6 +963,16 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, } } + /* Resolve nfs_export -> !data-only layers dependency */ + if (config->nfs_export && ctx->nr_data) { + if (set.nfs_export) { + pr_err("NFS export is not supported with data-only layers\n"); + return -EINVAL; + } + pr_info("disabling nfs_export due to data-only layers\n"); + config->nfs_export = false; + } + /* Resolve nfs_export -> index dependency */ if (config->nfs_export && !config->index) { if (!config->upperdir && @@ -991,9 +1030,10 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, /* Resolve userxattr -> !redirect && !metacopy dependency */ if (config->userxattr) { if (set.redirect && - config->redirect_mode != OVL_REDIRECT_NOFOLLOW) { + config->redirect_mode != OVL_REDIRECT_NOFOLLOW && + config->redirect_mode != OVL_REDIRECT_FOLLOWDATA) { pr_err("conflicting options: userxattr,redirect_dir=%s\n", - ovl_redirect_mode(config)); + ovl_redirect_mode_name(redirect_opt)); return -EINVAL; } if (config->metacopy && set.metacopy) { @@ -1006,10 +1046,21 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, * options must be explicitly enabled if used together with * userxattr. */ - config->redirect_mode = OVL_REDIRECT_NOFOLLOW; + if (!set.redirect) + config->redirect_mode = follow_mode; config->metacopy = false; } + /* Data-only layers are reached through redirects */ + if (ctx->nr_data && config->redirect_mode == OVL_REDIRECT_NOFOLLOW) { + pr_err("redirect_dir=nofollow is not supported with data-only layers\n"); + return -EINVAL; + } + if (!ctx->nr_data && config->redirect_mode == OVL_REDIRECT_FOLLOWDATA) { + pr_err("redirect_dir=followdata requires data-only layers\n"); + return -EINVAL; + } + /* * Fail if we don't have trusted xattr capability and a feature was * explicitly requested that requires them. diff --git a/fs/overlayfs/params.h b/fs/overlayfs/params.h index ffd53cdd84827c..3a514a21b14c4f 100644 --- a/fs/overlayfs/params.h +++ b/fs/overlayfs/params.h @@ -42,3 +42,5 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, struct ovl_config *config); int ovl_show_options(struct seq_file *m, struct dentry *dentry); const char *ovl_xino_mode(struct ovl_config *config); +const char *ovl_redirect_mode(struct ovl_config *config); +int ovl_redirect_follow_mode(bool follow_lower, size_t nr_data); diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index 2018e311465554..4cd4af097e5c19 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -43,6 +43,7 @@ struct ovl_dir_cache { struct ovl_readdir_data { struct dir_context ctx; + const struct file *user_file; struct dentry *dentry; bool is_lowest; struct rb_root *root; @@ -377,7 +378,8 @@ static inline int ovl_dir_read(const struct path *realpath, struct file *realfile; int err; - realfile = ovl_path_open(realpath, O_RDONLY | O_LARGEFILE); + realfile = ovl_path_open_realfile(rdd->user_file, realpath, + O_RDONLY | O_LARGEFILE); if (IS_ERR(realfile)) return PTR_ERR(realfile); @@ -421,13 +423,14 @@ static void ovl_dir_reset(struct file *file) } static int ovl_dir_read_merged(struct dentry *dentry, struct list_head *list, - struct rb_root *root) + struct rb_root *root, const struct file *user_file) { int err; struct path realpath; struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, .ctx.count = INT_MAX, + .user_file = user_file, .dentry = dentry, .list = list, .root = root, @@ -498,9 +501,10 @@ static struct ovl_dir_cache *ovl_dir_cache_check(struct inode *inode, return cache; } -static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get(struct file *file) { int res; + struct dentry *dentry = file->f_path.dentry; struct ovl_dir_cache *cache; struct inode *inode = d_inode(dentry); @@ -521,7 +525,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) INIT_LIST_HEAD(&cache->entries); cache->root = RB_ROOT; - res = ovl_dir_read_merged(dentry, &cache->entries, &cache->root); + res = ovl_dir_read_merged(dentry, &cache->entries, &cache->root, file); if (res) { ovl_cache_free(&cache->entries); kfree(cache); @@ -665,8 +669,8 @@ static bool ovl_fill_plain(struct dir_context *ctx, const char *name, return true; } -static int ovl_dir_read_impure(const struct path *path, struct list_head *list, - struct rb_root *root) +static int ovl_dir_read_impure(const struct path *path, struct list_head *list, + struct rb_root *root, const struct file *user_file) { int err; struct path realpath; @@ -674,6 +678,7 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list, struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, .ctx.count = INT_MAX, + .user_file = user_file, .list = list, .root = root, }; @@ -710,9 +715,10 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list, return 0; } -static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure(struct file *file) { int res; + const struct path *path = &file->f_path; struct dentry *dentry = path->dentry; struct inode *inode = d_inode(dentry); struct ovl_fs *ofs = OVL_FS(dentry->d_sb); @@ -731,7 +737,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path) return ERR_PTR(-ENOMEM); cache->is_refcounted = false; - res = ovl_dir_read_impure(path, &cache->entries, &cache->root); + res = ovl_dir_read_impure(path, &cache->entries, &cache->root, file); if (res) { ovl_cache_free(&cache->entries); kfree(cache); @@ -852,7 +858,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx) dput(parent); if (ovl_is_impure_dir(file)) { - rdt.cache = ovl_cache_get_impure(&file->f_path); + rdt.cache = ovl_cache_get_impure(file); if (IS_ERR(rdt.cache)) return PTR_ERR(rdt.cache); } @@ -866,14 +872,13 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx) static int ovl_iterate_merged(struct file *file, struct dir_context *ctx) { struct ovl_dir_file *od = file->private_data; - struct dentry *dentry = file->f_path.dentry; struct ovl_cache_entry *p; int err; if (!od->cache) { struct ovl_dir_cache *cache; - cache = ovl_cache_get(dentry); + cache = ovl_dir_cache_get(file); if (IS_ERR(cache)) return PTR_ERR(cache); @@ -994,7 +999,8 @@ static struct file *ovl_dir_open_realfile(const struct file *file, const struct path *realpath) { with_ovl_creds(file_inode(file)->i_sb) - return ovl_path_open(realpath, O_RDONLY | (file->f_flags & O_LARGEFILE)); + return ovl_path_open_realfile(file, realpath, + O_RDONLY | (file->f_flags & O_LARGEFILE)); } /* @@ -1119,7 +1125,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) struct rb_root root = RB_ROOT; with_ovl_creds(dentry->d_sb) - err = ovl_dir_read_merged(dentry, list, &root); + err = ovl_dir_read_merged(dentry, list, &root, NULL); if (err) return err; @@ -1343,7 +1349,8 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) * Whiteout orphan index to block future open by * handle after overlay nlink dropped to zero. */ - err = ovl_cleanup_and_whiteout(ofs, indexdir, index); + err = ovl_cleanup_and_whiteout(ofs, indexdir, index, + &QSTR_LEN(p->name, p->len)); } else { /* Cleanup orphan index entries */ err = ovl_cleanup(ofs, indexdir, index); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 08695a99f4f930..e61aab1999d366 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -100,17 +100,13 @@ static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak) dir = d_inode_rcu(parent); if (!dir) return -ECHILD; - /* - * Nothing pins d in RCU walk: eviction of the overlay - * inode may drop the last reference at any time. - */ - if (!try_take_dentry_name_snapshot(&n, d)) - return -ECHILD; } else { parent = dget_parent(d); dir = d_inode(parent); - take_dentry_name_snapshot(&n, d); } + /* In RCU walk the dentry name may go away at any time */ + if (!take_dentry_name_snapshot(&n, d)) + return -ECHILD; ret = d->d_op->d_revalidate(dir, &n.name, d, flags); release_dentry_name_snapshot(&n); if (!(flags & LOOKUP_RCU)) @@ -705,7 +701,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs) } static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, - const struct path *workpath) + const struct path *workpath, size_t nr_data) { struct vfsmount *mnt = ovl_upper_mnt(ofs); struct dentry *workdir; @@ -769,9 +765,11 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, if (err) { pr_warn("failed to set xattr on upper\n"); ofs->noxattr = true; - if (ovl_redirect_follow(ofs)) { - ofs->config.redirect_mode = OVL_REDIRECT_NOFOLLOW; - pr_warn("...falling back to redirect_dir=nofollow.\n"); + if (ovl_redirect_follow_lower(ofs)) { + ofs->config.redirect_mode = + ovl_redirect_follow_mode(false, nr_data); + pr_warn("...falling back to redirect_dir=%s.\n", + ovl_redirect_mode(&ofs->config)); } if (ofs->config.metacopy) { ofs->config.metacopy = false; @@ -848,7 +846,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs, const struct path *upperpath, - const struct path *workpath) + const struct path *workpath, size_t nr_data) { int err; @@ -877,7 +875,7 @@ static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs, if (err) return err; - return ovl_make_workdir(sb, ofs, workpath); + return ovl_make_workdir(sb, ofs, workpath, nr_data); } static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs, @@ -1145,6 +1143,29 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs, return err; } + /* + * Lower file handles identify the lower fs, but not the layer, + * so with different idmaps on the same lower fs, index and + * nfs_export may decode a file handle through a layer with the + * wrong idmap. Following copy up origin without index is only + * used for st_ino, which does not depend on the idmap. + */ + if (i < nr_merged_lower && + (ofs->config.index || ofs->config.nfs_export)) { + const struct mnt_idmap *idmap = mnt_idmap(mnt); + struct ovl_sb *fs = &ofs->fs[fsid]; + + if (!fs->lower_idmap) { + fs->lower_idmap = idmap; + } else if (fs->lower_idmap != idmap) { + pr_err("lower layer '%pd2' conflicts with idmap of another lower layer on the same fs, mount with '-o index=off,nfs_export=off' to override.\n", + l->path.dentry); + iput(trap); + kern_unmount(mnt); + return -EINVAL; + } + } + /* * Make lower layers R/O. That way fchmod/fchown on lower file * will fail instead of modifying lower fs. @@ -1391,7 +1412,6 @@ static struct dentry *ovl_get_root(struct super_block *sb, ovl_dentry_set_flag(OVL_E_CONNECTED, root); ovl_set_upperdata(d_inode(root)); ovl_inode_init(d_inode(root), &oip, ino, fsid); - WARN_ON(!!IS_CASEFOLDED(d_inode(root)) != ofs->casefold); ovl_dentry_init_flags(root, upperdentry, oe, DCACHE_OP_WEAK_REVALIDATE); /* root keeps a reference of upperdentry */ dget(upperdentry); @@ -1490,7 +1510,8 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb) } } - err = ovl_get_workdir(sb, ofs, &ctx->upper, &ctx->work); + err = ovl_get_workdir(sb, ofs, &ctx->upper, &ctx->work, + ctx->nr_data); if (err) return err; @@ -1575,6 +1596,17 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb) if (!sb->s_root) goto out_free_oe; + /* + * The casefold flag of an empty layer root may have changed since the + * mount options were parsed. The root inode owns oe by now. + */ + if (!!IS_CASEFOLDED(d_inode(sb->s_root)) != ofs->casefold) { + pr_err("casefold flag of the root directory has changed\n"); + dput(sb->s_root); + sb->s_root = NULL; + return -EINVAL; + } + return 0; out_free_oe: @@ -1613,13 +1645,23 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc) return err; } +static void ovl_kill_sb(struct super_block *sb) +{ + struct ovl_fs *ofs = OVL_FS(sb); + + /* Nothing can modify them now, do not hold them across the sync */ + if (ofs) + ovl_inuse_unlock_all(ofs); + kill_anon_super(sb); +} + struct file_system_type ovl_fs_type = { .owner = THIS_MODULE, .name = "overlay", .init_fs_context = ovl_init_fs_context, .parameters = ovl_parameter_spec, .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, - .kill_sb = kill_anon_super, + .kill_sb = ovl_kill_sb, }; MODULE_ALIAS_FS("overlay"); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 521717209b2e44..fd4b1fcf57ad3d 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -654,7 +654,8 @@ bool ovl_path_is_whiteout(struct ovl_fs *ofs, const struct path *path) ovl_path_check_xwhiteout_xattr(ofs, path); } -struct file *ovl_path_open(const struct path *path, int flags) +struct file *ovl_path_open_realfile(const struct file *user_file, + const struct path *path, int flags) { struct inode *inode = d_inode(path->dentry); const struct mnt_idmap *real_idmap = mnt_idmap(path->mnt); @@ -682,6 +683,14 @@ struct file *ovl_path_open(const struct path *path, int flags) if (inode_owner_or_capable(real_idmap, inode)) flags |= O_NOATIME; + /* + * Directory opens use dentry_open() here, not backing_file_open(). + * Inherit FMODE_NONOTIFY from a fanotify permission fd so a listener + * that also watches the real filesystem does not deadlock. + */ + if (user_file && FMODE_FSNOTIFY_NONE(user_file->f_mode)) + return dentry_open_nonotify(path, flags, current_cred()); + return dentry_open(path, flags, current_cred()); } @@ -1050,6 +1059,18 @@ bool ovl_is_inuse(struct dentry *dentry) return inuse; } +void ovl_inuse_unlock_all(struct ovl_fs *ofs) +{ + if (ofs->workdir_locked) { + ovl_inuse_unlock(ofs->workbasedir); + ofs->workdir_locked = false; + } + if (ofs->upperdir_locked) { + ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root); + ofs->upperdir_locked = false; + } +} + /* * Does this overlay dentry need to be indexed on copy up? */ @@ -1118,7 +1139,7 @@ static void ovl_cleanup_index(struct dentry *dentry) } else if (ovl_index_all(dentry->d_sb)) { /* Whiteout orphan index to block future open by handle */ err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb), - indexdir, index); + indexdir, index, &name); } else { /* Cleanup orphan index entries */ err = ovl_cleanup(ofs, indexdir, index); diff --git a/fs/pidfs.c b/fs/pidfs.c index 114d2713a79e88..d1aa0229866a28 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -590,6 +590,14 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (arg) return -EINVAL; + /* + * Require the target to be visible in the caller's pid namespace + * for operations that grant access to its resources, mirroring + * procfs and PIDFD_GET_INFO. + */ + if (!pid_in_current_pidns(pidfd_pid(file))) + return -EREMOTE; + /* * We're trying to open a file descriptor to the namespace so perform a * filesystem cred ptrace check. Hold @task's exec_update_lock for the diff --git a/fs/pipe.c b/fs/pipe.c index 4fa69192e6fba1..4c1122597a3c37 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -222,48 +222,6 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe, anon_pipe_put_page(pipe, page); } -static bool anon_pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - struct page *page = buf->page; - - if (page_count(page) != 1) - return false; - memcg_kmem_uncharge_page(page, 0); - __SetPageLocked(page); - return true; -} - -/** - * generic_pipe_buf_try_steal - attempt to take ownership of a &pipe_buffer - * @pipe: the pipe that the buffer belongs to - * @buf: the buffer to attempt to steal - * - * Description: - * This function attempts to steal the &struct page attached to - * @buf. If successful, this function returns 0 and returns with - * the page locked. The caller may then reuse the page for whatever - * he wishes; the typical use is insertion into a different file - * page cache. - */ -bool generic_pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - struct page *page = buf->page; - - /* - * A reference of one is golden, that means that the owner of this - * page is the only one holding a reference to it. lock the page - * and return OK. - */ - if (page_count(page) == 1) { - lock_page(page); - return true; - } - return false; -} -EXPORT_SYMBOL(generic_pipe_buf_try_steal); - /** * generic_pipe_buf_get - get a reference to a &struct pipe_buffer * @pipe: the pipe that the buffer belongs to @@ -297,7 +255,6 @@ EXPORT_SYMBOL(generic_pipe_buf_release); static const struct pipe_buf_operations anon_pipe_buf_ops = { .release = anon_pipe_buf_release, - .try_steal = anon_pipe_buf_try_steal, .get = generic_pipe_buf_get, }; diff --git a/fs/proc/base.c b/fs/proc/base.c index c9aebee0a338c7..7685660c36241e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -478,8 +478,7 @@ static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns, if (!file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN)) return -EACCES; - entries = kmalloc_array(MAX_STACK_TRACE_DEPTH, sizeof(*entries), - GFP_KERNEL); + entries = kmalloc_objs(*entries, MAX_STACK_TRACE_DEPTH); if (!entries) return -ENOMEM; diff --git a/fs/proc/internal.h b/fs/proc/internal.h index df873df9afc560..9af1f63258b71f 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -393,6 +393,7 @@ struct proc_maps_private { struct inode *inode; struct task_struct *task; struct vma_iterator iter; + struct vma_rcu_iter rvmi; loff_t last_pos; struct proc_maps_locking_ctx lock_ctx; #ifdef CONFIG_NUMA diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 6c0859c6656356..eeebf813668e09 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -557,6 +557,8 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter, struct ctl_table_header *head = grab_header(inode); const struct ctl_table *table = PROC_I(inode)->sysctl_entry; size_t count = iov_iter_count(iter); + /* ->write_iter() must never report more than the iterator held */ + size_t orig_count = count; char *kbuf; ssize_t error; @@ -607,7 +609,8 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter, goto out_free_buf; } - error = count; + /* the write path consumed at most the original iterator length */ + error = write ? min(count, orig_count) : count; out_free_buf: kvfree(kbuf); out: diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 7452b695fdaec4..b87d3e86442d0c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -160,7 +160,7 @@ static struct vm_area_struct *get_next_vma(struct proc_maps_private *priv, return vma_next(&priv->iter); unlock_ctx_vma(lock_ctx); - vma = lock_next_vma(lock_ctx->mm, &priv->iter, last_pos); + vma = lock_next_vma(&priv->rvmi, last_pos); if (!IS_ERR_OR_NULL(vma)) lock_ctx->locked_vma = vma; @@ -265,7 +265,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos) */ if (last_addr > 0) *ppos = last_addr = priv->last_pos; - vma_iter_init(&priv->iter, mm, (unsigned long)last_addr); + vma_rcu_iter_init(&priv->rvmi, mm, &priv->iter, (unsigned long)last_addr); hold_task_mempolicy(priv); /* * If seq_file had to flush its collected data right after m_next() set @@ -515,6 +515,7 @@ static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_locking_ct struct mm_struct *mm = lock_ctx->mm; struct vm_area_struct *vma; struct vma_iterator vmi; + struct vma_rcu_iter rvmi; if (lock_ctx->mmap_locked) return find_vma(mm, addr); @@ -522,8 +523,8 @@ static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_locking_ct /* Unlock previously locked VMA and find the next one under RCU */ unlock_ctx_vma(lock_ctx); rcu_read_lock(); - vma_iter_init(&vmi, mm, addr); - vma = lock_next_vma(mm, &vmi, addr); + vma_rcu_iter_init(&rvmi, mm, &vmi, addr); + vma = lock_next_vma(&rvmi, addr); rcu_read_unlock(); if (!vma) @@ -1416,7 +1417,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v) rcu_read_lock(); reset_lock_ctx(lock_ctx); - vma_iter_init(&priv->iter, mm, 0); + vma_rcu_iter_init(&priv->rvmi, mm, &priv->iter, 0); vma = proc_get_vma(m, &pos); if (unlikely(!vma)) goto empty_set; @@ -1465,7 +1466,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v) reset_lock_ctx(lock_ctx); /* Resume from the last position. */ pos = last_vma_end; - vma_iter_init(&priv->iter, mm, pos); + vma_rcu_iter_init(&priv->rvmi, mm, &priv->iter, pos); } vma = proc_get_vma(m, &pos); } @@ -3201,7 +3202,7 @@ static long do_pagemap_cmd(struct file *file, unsigned int cmd, return do_pagemap_scan(mm, arg); default: - return -EINVAL; + return -ENOIOCTLCMD; } } diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 3ad19d7e472f62..a3d50359187146 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -2958,7 +2958,7 @@ static const struct ctl_table fs_dqstats_table[] = { }, }; -static int __init dquot_init(void) +void __init dquot_cache_init(void) { int i, ret; unsigned long nr_hash; @@ -2966,8 +2966,6 @@ static int __init dquot_init(void) printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__); - register_sysctl_init("fs/quota", fs_dqstats_table); - dquot_cachep = kmem_cache_create("dquot", sizeof(struct dquot), sizeof(unsigned long) * 4, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| @@ -3008,7 +3006,11 @@ static int __init dquot_init(void) WQ_UNBOUND | WQ_MEM_RECLAIM, WQ_MAX_ACTIVE); if (!quota_unbound_wq) panic("Cannot create quota_unbound_wq\n"); +} +static int __init init_fs_dquot_sysctls(void) +{ + register_sysctl_init("fs/quota", fs_dqstats_table); return 0; } -fs_initcall(dquot_init); +fs_initcall(init_fs_dquot_sysctls); diff --git a/fs/read_write.c b/fs/read_write.c index 67672831089914..b15522cf96cd62 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -333,45 +333,25 @@ loff_t default_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode = file_inode(file); loff_t retval; + int ret; retval = inode_lock_killable(inode); if (retval) return retval; - switch (whence) { - case SEEK_END: - offset += i_size_read(inode); - break; - case SEEK_CUR: - if (offset == 0) { - retval = file->f_pos; - goto out; - } - offset += file->f_pos; - break; - case SEEK_DATA: - /* - * In the generic case the entire file is data, so as - * long as offset isn't at the end of the file then the - * offset is data. - */ - if (offset >= inode->i_size) { - retval = -ENXIO; - goto out; - } - break; - case SEEK_HOLE: - /* - * There is a virtual hole at the end of the file, so - * as long as offset isn't i_size or larger, return - * i_size. - */ - if (offset >= inode->i_size) { - retval = -ENXIO; - goto out; - } - offset = inode->i_size; - break; + + ret = must_set_pos(file, &offset, whence, i_size_read(inode)); + if (ret < 0) { + retval = ret; + goto out; + } + if (ret == 0) { + retval = offset; + goto out; } + + if (whence == SEEK_CUR) + offset += file->f_pos; + retval = -EINVAL; if (offset >= 0 || unsigned_offsets(file)) { if (offset != file->f_pos) diff --git a/fs/remap_range.c b/fs/remap_range.c index 6eb7d845de5d4b..7d269837f63f09 100644 --- a/fs/remap_range.c +++ b/fs/remap_range.c @@ -277,7 +277,7 @@ int __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *len, unsigned int remap_flags, - const struct iomap_ops *dax_read_ops) + iomap_iter_next_fn dax_read_next) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); @@ -340,10 +340,10 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (!IS_DAX(inode_in)) ret = vfs_dedupe_file_range_compare(file_in, pos_in, file_out, pos_out, *len, &is_same); - else if (dax_read_ops) + else if (dax_read_next) ret = dax_dedupe_file_range_compare(inode_in, pos_in, inode_out, pos_out, *len, &is_same, - dax_read_ops); + dax_read_next); else return -EINVAL; if (ret) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 04e4ea612b7c6d..b9336464cc533e 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1887,7 +1887,7 @@ static int closid_num_dirty_rmid_alloc(struct rdt_resource *r) * use a smaller system wide value based on the resources in * use. */ - tmp = kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL); + tmp = kzalloc_objs(*tmp, num_closid); if (!tmp) { mutex_unlock(&rdtgroup_mutex); return -ENOMEM; diff --git a/fs/smb/client/cifs_fs_sb.h b/fs/smb/client/cifs_fs_sb.h index d6494e1d93ccf6..b322718d919909 100644 --- a/fs/smb/client/cifs_fs_sb.h +++ b/fs/smb/client/cifs_fs_sb.h @@ -57,6 +57,7 @@ struct cifs_sb_info { atomic_t active; atomic_t mnt_cifs_flags; atomic_t outstanding_rreq; /* nr of rreqs not yet fully deinitialized */ + atomic_t umount_aborts; /* nr of umount -f attempts */ struct delayed_work prune_tlinks; struct rcu_head rcu; @@ -68,6 +69,7 @@ struct cifs_sb_info { * (cifs_autodisable_serverino) in order to match new mounts. */ bool mnt_cifs_serverino_autodisabled; + bool exiting; /* umount -f committed: stop retries */ /* * Available once the mount has completed. */ diff --git a/fs/smb/client/cifsacl.c b/fs/smb/client/cifsacl.c index f9f61c758a753e..d8f30c35cbe5b4 100644 --- a/fs/smb/client/cifsacl.c +++ b/fs/smb/client/cifsacl.c @@ -385,7 +385,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) goto out_revert_creds; } else if (sidkey->datalen < CIFS_SID_BASE_SIZE) { rc = smb_EIO1(smb_eio_trace_malformed_sid_key, sidkey->datalen); - cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu)\n", + cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%u)\n", __func__, sidkey->datalen); goto invalidate_key; } @@ -403,7 +403,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) if (ksid_size > sidkey->datalen) { rc = smb_EIO2(smb_eio_trace_malformed_ksid_key, ksid_size, sidkey->datalen); - cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu, ksid_size=%u)\n", + cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%u, ksid_size=%u)\n", __func__, sidkey->datalen, ksid_size); goto invalidate_key; } @@ -498,7 +498,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, */ BUILD_BUG_ON(sizeof(uid_t) != sizeof(gid_t)); if (sidkey->datalen != sizeof(uid_t)) { - cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu)\n", + cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%u)\n", __func__, sidkey->datalen); key_invalidate(sidkey); goto out_key_put; @@ -1134,7 +1134,10 @@ static void populate_new_aces(char *nacl_base, * updated in the inode. */ - if (!memcmp(pownersid, pgrpsid, sizeof(struct smb_sid))) { + if (pownersid->num_subauth == pgrpsid->num_subauth && + !memcmp(pownersid, pgrpsid, + CIFS_SID_BASE_SIZE + + pownersid->num_subauth * sizeof(__le32))) { /* * Case when owner and group SIDs are the same. * Set the more restrictive of the two modes. diff --git a/fs/smb/client/cifsacl.h b/fs/smb/client/cifsacl.h index 31b51a8fc25611..ebc1b7c08c6ad4 100644 --- a/fs/smb/client/cifsacl.h +++ b/fs/smb/client/cifsacl.h @@ -93,18 +93,4 @@ struct owner_group_sids { struct owner_sid group; } __packed; -/* - * Minimum security identifier can be one for system defined Users - * and Groups such as NULL SID and World or Built-in accounts such - * as Administrator and Guest and consists of - * Revision + Num (Sub)Auths + Authority + Domain (one Subauthority) - */ -#define MIN_SID_LEN (1 + 1 + 6 + 4) /* in bytes */ - -/* - * Minimum security descriptor can be one without any SACL and DACL and can - * consist of revision, type, and two sids of minimum size for owner and group - */ -#define MIN_SEC_DESC_LEN (sizeof(struct smb_ntsd) + (2 * MIN_SID_LEN)) - #endif /* _CIFSACL_H */ diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index bf199a5ca084be..8cff7857b45095 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -164,6 +164,7 @@ struct workqueue_struct *cifsoplockd_wq; struct workqueue_struct *deferredclose_wq; struct workqueue_struct *serverclose_wq; struct workqueue_struct *cfid_put_wq; +struct workqueue_struct *cifs_writeback_wq; __u32 cifs_lock_secret; /* @@ -293,9 +294,115 @@ cifs_read_super(struct super_block *sb) return rc; } +struct cifs_tcon_ref { + struct list_head list; + struct tcon_link *tlink; + struct cifs_tcon *tcon; + bool shared; +}; + +static bool used_by_other_mounts(struct cifs_tcon *tcon, + struct list_head *tcons) +{ + struct cifs_tcon_ref *ref; + int n = 0; + + list_for_each_entry(ref, tcons, list) + n += ref->tcon == tcon; + + guard(spinlock)(&tcon->tc_lock); + return tcon->mnt_refs - tcon->mnt_unlinked > n; +} + +static void get_sb_tcons(struct cifs_sb_info *cifs_sb, struct list_head *tcons) +{ + struct rb_root *root = &cifs_sb->tlink_tree; + struct cifs_tcon_ref *ref; + struct tcon_link *tlink; + struct cifs_tcon *tcon; + struct rb_node *node; + + guard(spinlock)(&cifs_sb->tlink_tree_lock); + for (node = rb_first(root); node; node = rb_next(node)) { + tlink = rb_entry(node, struct tcon_link, tl_rbnode); + tcon = tlink_tcon(tlink); + if (IS_ERR_OR_NULL(tcon)) + continue; + + ref = kmalloc_obj(struct cifs_tcon_ref, GFP_ATOMIC); + if (!ref) + break; + + ref->tlink = cifs_get_tlink(tlink); + ref->tcon = tcon; + list_add_tail(&ref->list, tcons); + } + list_for_each_entry(ref, tcons, list) + ref->shared = used_by_other_mounts(ref->tcon, tcons); +} + +static void put_sb_tcons(struct list_head *tcons) +{ + struct cifs_tcon_ref *ref, *tmp; + + list_for_each_entry_safe(ref, tmp, tcons, list) { + cifs_put_tlink(ref->tlink); + list_del(&ref->list); + kfree(ref); + } +} + +/* + * While a forced unmount tears a superblock down, keep its tcons from + * reconnecting or replaying so the teardown (flushing close and oplock work, + * sending the tree disconnect) can't hang on a server that is gone. It is a + * count, not a flag, so a tcon shared with another mount only has its retries + * suppressed for the duration of this teardown; one no mount uses any more + * stays dying until it is freed. + */ +static void set_tcons_dying(struct cifs_sb_info *cifs_sb, + struct list_head *tcons) +{ + struct cifs_tcon_ref *ref; + + get_sb_tcons(cifs_sb, tcons); + list_for_each_entry(ref, tcons, list) { + atomic_inc(&ref->tcon->dying); + cifs_wake_ses_waiters(ref->tcon->ses); + } +} + +static void clear_tcons_dying(struct list_head *tcons) +{ + struct cifs_tcon_ref *ref; + + flush_workqueue(serverclose_wq); + list_for_each_entry(ref, tcons, list) { + guard(spinlock)(&ref->tcon->tc_lock); + if (ref->tcon->mnt_refs) + atomic_dec(&ref->tcon->dying); + } + put_sb_tcons(tcons); +} + static void cifs_kill_sb(struct super_block *sb) { struct cifs_sb_info *cifs_sb = CIFS_SB(sb); + LIST_HEAD(tcons); + bool force; + + force = atomic_read(&cifs_sb->umount_aborts); + + /* + * Reaching here after a umount -f means the mount is going away for + * good, so stop retrying I/O that can no longer complete (e.g. + * writeback to a server that is gone) rather than looping forever on + * a hard mount and hanging the teardown below. + */ + if (force) { + WRITE_ONCE(cifs_sb->exiting, true); + set_tcons_dying(cifs_sb, &tcons); + } /* * We need to release all dentries for the cached directories @@ -329,6 +436,9 @@ static void cifs_kill_sb(struct super_block *sb) kill_anon_super(sb); cifs_umount(cifs_sb); + + if (force) + clear_tcons_dying(&tcons); } static int @@ -827,46 +937,46 @@ cifs_show_options(struct seq_file *s, struct dentry *root) return 0; } +static void abort_reconnect(struct cifs_tcon *tcon) +{ + scoped_guard(spinlock, &tcon->tc_lock) + trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, + netfs_trace_tcon_ref_see_umount); + + atomic_inc(&tcon->umount_aborts); + if (tcon->ses && tcon->ses->server) { + cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n"); + cifs_wake_ses_waiters(tcon->ses); + msleep(1); /* yield */ + /* we have to kick the requests once more */ + cifs_wake_ses_waiters(tcon->ses); + msleep(1); + } +} + static void cifs_umount_begin(struct super_block *sb) { struct cifs_sb_info *cifs_sb = CIFS_SB(sb); - struct cifs_tcon *tcon; + struct cifs_tcon_ref *ref; + LIST_HEAD(tcons); if (cifs_sb == NULL) return; - tcon = cifs_sb_master_tcon(cifs_sb); + atomic_inc(&cifs_sb->umount_aborts); - spin_lock(&cifs_tcp_ses_lock); - spin_lock(&tcon->tc_lock); - trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, - netfs_trace_tcon_ref_see_umount); - if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) { - /* we have other mounts to same share or we have - already tried to umount this and woken up - all waiting network requests, nothing to do */ - spin_unlock(&tcon->tc_lock); - spin_unlock(&cifs_tcp_ses_lock); - return; - } /* - * can not set tcon->status to TID_EXITING yet since we don't know if umount -f will - * fail later (e.g. due to open files). TID_EXITING will be set just before tdis req sent + * Abort the reconnect waits of the master tcon and of any per-user + * tcons of a multiuser mount that no other mount uses, pinning their + * tlinks so that they stay alive, and aren't pruned, while we abort and + * sleep outside the tree lock. */ - spin_unlock(&tcon->tc_lock); - spin_unlock(&cifs_tcp_ses_lock); - - if (tcon->ses && tcon->ses->server) { - cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n"); - wake_up_all(&tcon->ses->server->request_q); - wake_up_all(&tcon->ses->server->response_q); - msleep(1); /* yield */ - /* we have to kick the requests once more */ - wake_up_all(&tcon->ses->server->response_q); - msleep(1); + get_sb_tcons(cifs_sb, &tcons); + list_for_each_entry(ref, &tcons, list) { + if (!ref->shared) + abort_reconnect(ref->tcon); } - - return; + put_sb_tcons(&tcons); } static int cifs_freeze(struct super_block *sb) @@ -2123,9 +2233,16 @@ init_cifs(void) goto out_destroy_serverclose_wq; } + cifs_writeback_wq = alloc_workqueue("cifswritebackd", + WQ_UNBOUND | WQ_MEM_RECLAIM, 0); + if (!cifs_writeback_wq) { + rc = -ENOMEM; + goto out_destroy_cfid_put_wq; + } + rc = cifs_init_inodecache(); if (rc) - goto out_destroy_cfid_put_wq; + goto out_destroy_writeback_wq; rc = cifs_init_netfs(); if (rc) @@ -2196,6 +2313,8 @@ init_cifs(void) cifs_destroy_netfs(); out_destroy_inodecache: cifs_destroy_inodecache(); +out_destroy_writeback_wq: + destroy_workqueue(cifs_writeback_wq); out_destroy_cfid_put_wq: destroy_workqueue(cfid_put_wq); out_destroy_serverclose_wq: @@ -2241,6 +2360,7 @@ exit_cifs(void) destroy_workqueue(fileinfo_put_wq); destroy_workqueue(serverclose_wq); destroy_workqueue(cfid_put_wq); + destroy_workqueue(cifs_writeback_wq); destroy_workqueue(cifsiod_wq); } diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index d3ca688b6aba99..4e16347886ed60 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -585,7 +585,7 @@ struct smb_version_operations { unsigned int (*wp_retry_size)(struct inode *); /* get mtu credits */ int (*wait_mtu_credits)(struct TCP_Server_Info *, size_t, - size_t *, struct cifs_credits *); + size_t *, struct cifs_credits *, bool nowait); /* adjust previously taken mtu credits to request size */ int (*adjust_credits)(struct TCP_Server_Info *server, struct cifs_io_subrequest *subreq, @@ -887,6 +887,14 @@ has_credits(struct TCP_Server_Info *server, int *credits, int num_credits) return num >= num_credits; } +static inline bool +credits_or_conn_down(struct TCP_Server_Info *server, int *credits, + int num_credits, bool nowait) +{ + return has_credits(server, credits, num_credits) || + (nowait && READ_ONCE(server->tcpStatus) == CifsNeedReconnect); +} + static inline void add_credits(struct TCP_Server_Info *server, struct cifs_credits *credits, const int optype) @@ -1196,6 +1204,10 @@ struct cifs_tcon { struct list_head tcon_list; int debug_id; /* Debugging for tracing */ int tc_count; + int mnt_refs; /* refs held by mounts, under tc_lock */ + int mnt_unlinked; /* mnt_refs of tlinks being built */ + atomic_t umount_aborts; /* nr of umount -f attempts */ + atomic_t dying; /* umount -f: stop reconnects/replays */ struct list_head rlist; /* reconnect list */ spinlock_t tc_lock; /* protect anything here that is not protected */ atomic_t num_local_opens; /* num of all opens including disconnected */ @@ -1407,6 +1419,9 @@ struct cifs_open_parms { umode_t mode; bool reconnect:1; bool replay:1; /* indicates that this open is for a replay */ + bool no_replay:1; /* don't replay this open internally */ + bool pending:1; /* in/out: last built create had no answer */ + bool no_reconnect_wait:1; /* fail fast, don't wait for reconnect */ struct kvec *ea_cctx; __le32 lease_flags; }; @@ -1458,6 +1473,10 @@ struct cifsFileInfo { int count; spinlock_t file_info_lock; /* protects four flag/count fields above */ struct mutex fh_mutex; /* prevents reopen race after dead ses*/ + unsigned int reopens; + bool reopen_fresh; /* durable handle gone: reopen opens afresh */ + bool reopen_replay; /* reopen replays its last create */ + int reopen_access; /* desired access of that create */ struct cifs_search_info srch_inf; struct work_struct oplock_break; /* work for oplock breaks */ struct work_struct put; /* work for the final part of _put */ @@ -1482,6 +1501,16 @@ struct cifs_io_request { struct netfs_io_request rreq; struct cifsFileInfo *cfile; pid_t pid; + int umount_aborts; + bool reopen_gave_up; + bool replay; + atomic_t bad_reopens; /* 0 or bad gen + 1 */ + int reopen_err; + int reopen_pass_err; + struct mutex reopen_lock; /* serializes reopens */ + unsigned long retry_deadline; + unsigned int cur_sleep; + unsigned int slept; }; /* asynchronous read support */ @@ -1496,8 +1525,11 @@ struct cifs_io_subrequest { int result; bool have_xid; bool replay; + bool deferred; /* issue in a worker */ + unsigned int reopens; unsigned int retries; /* number of retries so far */ unsigned int cur_sleep; /* time to sleep before replay */ + unsigned long retry_deadline; struct kvec iov[2]; struct TCP_Server_Info *server; #ifdef CONFIG_CIFS_SMB_DIRECT @@ -1891,6 +1923,8 @@ enum cifs_find_flags { FIND_WITH_DELETE = (1U << 1), FIND_NO_PENDING_DELETE = (1U << 2), FIND_OPEN_FLAGS = (1U << 3), + FIND_NO_DIRECT = (1U << 4), + FIND_NO_REOPEN = (1U << 5), }; #define MID_FREE 0 @@ -1933,6 +1967,7 @@ enum cifs_find_flags { #define CIFS_COMPRESS_REQ 0x4000 /* compress request before sending */ #define CIFS_INTERRUPTIBLE_WAIT 0x8000 /* Interruptible wait (e.g. lock request) */ #define CIFS_WINDOWS_LOCK 0x10000 /* We're trying to get a Windows lock */ +#define CIFS_NO_RECONNECT_WAIT 0x20000 /* don't wait if conn is down */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001 @@ -2141,6 +2176,7 @@ extern struct workqueue_struct *cifsoplockd_wq; extern struct workqueue_struct *deferredclose_wq; extern struct workqueue_struct *serverclose_wq; extern struct workqueue_struct *cfid_put_wq; +extern struct workqueue_struct *cifs_writeback_wq; extern __u32 cifs_lock_secret; extern mempool_t *cifs_sm_req_poolp; @@ -2373,6 +2409,18 @@ static inline void cifs_reset_oplock(struct cifsInodeInfo *cinode) WRITE_ONCE(cinode->oplock, 0); } +static inline bool cifs_tcon_dying(struct cifs_tcon *tcon) +{ + return atomic_read(&tcon->dying) || + (!tcon->ipc && !tcon->dummy && !READ_ONCE(tcon->mnt_refs)); +} + +static inline bool cifs_tcon_retry(struct cifs_tcon *tcon, int aborts) +{ + return tcon->retry && atomic_read(&tcon->umount_aborts) == aborts && + !cifs_tcon_dying(tcon); +} + static inline bool cifs_forced_shutdown(const struct cifs_sb_info *sbi) { return cifs_sb_flags(sbi) & CIFS_MOUNT_SHUTDOWN; diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index f9ea35597bc27f..15123c7b93730f 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -112,7 +112,8 @@ int __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, int wait_for_free_request(struct TCP_Server_Info *server, const int flags, unsigned int *instance); int cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size, - size_t *num, struct cifs_credits *credits); + size_t *num, struct cifs_credits *credits, + bool nowait); static inline int send_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server, @@ -137,6 +138,8 @@ bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file, bool from_readdir); void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t result); +bool cifs_io_stopped(struct cifs_io_subrequest *subreq); +bool cifs_io_should_replay(struct cifs_io_subrequest *subreq); struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, int flags); int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, @@ -241,7 +244,7 @@ int cifs_match_super(struct super_block *sb, struct fs_context *fc); int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx); void cifs_umount(struct cifs_sb_info *cifs_sb); void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); -void cifs_reopen_persistent_handles(struct cifs_tcon *tcon); +bool cifs_reopen_persistent_handles(struct cifs_tcon *tcon); bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, __u8 type, __u16 flags, @@ -440,7 +443,10 @@ static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options) return options; } -int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry); +void cifs_wake_ses_waiters(struct cifs_ses *ses); +int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, + struct cifs_tcon *tcon, int aborts, + bool nowait); static inline void cifs_put_smb_ses(struct cifs_ses *ses) { diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 2936b38de98f9e..68f05a52605f4f 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -73,6 +73,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) { struct TCP_Server_Info *server; struct cifs_ses *ses; + int aborts; int rc; /* @@ -83,6 +84,8 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) if (!tcon) return 0; + aborts = atomic_read(&tcon->umount_aborts); + ses = tcon->ses; server = ses->server; @@ -102,7 +105,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) spin_unlock(&tcon->tc_lock); again: - rc = cifs_wait_for_server_reconnect(server, tcon->retry); + rc = cifs_wait_for_server_reconnect(server, tcon, aborts, false); if (rc) return rc; @@ -127,7 +130,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) case CifsNeedReconnect: spin_unlock(&server->srv_lock); mutex_unlock(&ses->session_mutex); - if (!tcon->retry) + if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; default: @@ -159,7 +162,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) rc = cifs_negotiate_protocol(0, ses, server); if (rc) { mutex_unlock(&ses->session_mutex); - if (!tcon->retry) + if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; } @@ -1939,12 +1942,14 @@ cifs_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) break; case MID_REQUEST_SUBMITTED: trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted); - __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + if (wdata->rreq->origin != NETFS_WRITEBACK) + __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); result = -EAGAIN; break; case MID_RETRY_NEEDED: trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); - __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + if (wdata->rreq->origin != NETFS_WRITEBACK) + __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); result = -EAGAIN; break; case MID_RESPONSE_MALFORMED: diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index e68fffb2ab2ea0..750b5bb72dc773 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -352,6 +352,7 @@ cifs_abort_connection(struct TCP_Server_Info *server) mid_execute_callback(server, mid); release_mid(server, mid); } + wake_up_all(&server->request_q); } static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num_targets) @@ -2200,7 +2201,8 @@ void __cifs_put_smb_ses(struct cifs_ses *ses) kref_put(&ses->chans[i].iface->refcount, release_iface); ses->chans[i].iface = NULL; } - cifs_put_tcp_session(ses->chans[i].server, 0); + if (ses->chans[i].server) + cifs_put_tcp_session(ses->chans[i].server, 0); ses->chans[i].server = NULL; } @@ -2610,18 +2612,21 @@ static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) } static struct cifs_tcon * -cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) +cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx, + bool unlinked) { struct cifs_tcon *tcon; spin_lock(&cifs_tcp_ses_lock); list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { spin_lock(&tcon->tc_lock); - if (!match_tcon(tcon, ctx)) { + if (!match_tcon(tcon, ctx) || cifs_tcon_dying(tcon)) { spin_unlock(&tcon->tc_lock); continue; } ++tcon->tc_count; + ++tcon->mnt_refs; + tcon->mnt_unlinked += unlinked; trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, netfs_trace_tcon_ref_get_find); spin_unlock(&tcon->tc_lock); @@ -2695,10 +2700,47 @@ cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) #endif } +void cifs_wake_ses_waiters(struct cifs_ses *ses) +{ + guard(spinlock)(&ses->chan_lock); + for (size_t i = 0; i < ses->chan_count; i++) { + struct TCP_Server_Info *server = ses->chans[i].server; + + if (!server) + continue; + wake_up_all(&server->request_q); + wake_up_all(&server->response_q); + } +} + +static void drop_mnt_ref(struct cifs_tcon *tcon) +{ + scoped_guard(spinlock, &tcon->tc_lock) { + if (--tcon->mnt_refs) + return; + } + cifs_wake_ses_waiters(tcon->ses); +} + +static void put_mnt_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) +{ + drop_mnt_ref(tcon); + cifs_put_tcon(tcon, trace); +} + +static void erase_tlink(struct cifs_sb_info *cifs_sb, struct tcon_link *tlink) +{ + clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); + rb_erase(&tlink->tl_rbnode, &cifs_sb->tlink_tree); + if (!IS_ERR(tlink_tcon(tlink))) + drop_mnt_ref(tlink_tcon(tlink)); +} + /** * cifs_get_tcon - get a tcon matching @ctx data from @ses * @ses: smb session to issue the request on * @ctx: the superblock configuration context to use for building the + * @unlinked: the mount reference is for a tlink not yet in a superblock's tree * * - tcon refcount is the number of mount points using the tcon. * - ses refcount is the number of tcon using the session. @@ -2718,13 +2760,13 @@ cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) * decrement the ses refcount. */ static struct cifs_tcon * -cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) +cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx, bool unlinked) { struct cifs_tcon *tcon; bool nohandlecache; int rc, xid; - tcon = cifs_find_tcon(ses, ctx); + tcon = cifs_find_tcon(ses, ctx, unlinked); if (tcon) { /* * tcon has refcount already incremented but we need to @@ -2750,6 +2792,8 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) rc = -ENOMEM; goto out_fail; } + tcon->mnt_refs = 1; + tcon->mnt_unlinked = unlinked; tcon->nohandlecache = nohandlecache; if (ctx->snapshot_time) { @@ -3576,7 +3620,7 @@ void cifs_mount_put_conns(struct cifs_mount_ctx *mnt_ctx) int rc = 0; if (mnt_ctx->tcon) - cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx); + put_mnt_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx); else if (mnt_ctx->ses) cifs_put_smb_ses(mnt_ctx->ses); else if (mnt_ctx->server) @@ -3656,7 +3700,7 @@ int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx) cifs_sb = mnt_ctx->cifs_sb; /* search for existing tcon to this server share */ - tcon = cifs_get_tcon(mnt_ctx->ses, ctx); + tcon = cifs_get_tcon(mnt_ctx->ses, ctx, false); if (IS_ERR(tcon)) { rc = PTR_ERR(tcon); tcon = NULL; @@ -4032,8 +4076,7 @@ cifs_umount(struct cifs_sb_info *cifs_sb) while ((node = rb_first(root))) { tlink = rb_entry(node, struct tcon_link, tl_rbnode); cifs_get_tlink(tlink); - clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); - rb_erase(node, root); + erase_tlink(cifs_sb, tlink); spin_unlock(&cifs_sb->tlink_tree_lock); cifs_put_tlink(tlink); @@ -4321,7 +4364,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) } #endif - tcon = cifs_get_tcon(ses, ctx); + tcon = cifs_get_tcon(ses, ctx, true); if (IS_ERR(tcon)) { cifs_put_smb_ses(ses); goto out; @@ -4424,6 +4467,7 @@ cifs_sb_tlink(struct cifs_sb_info *cifs_sb) { struct tcon_link *tlink, *newtlink; kuid_t fsuid = current_fsuid(); + struct cifs_tcon *tcon; int err; if (!(cifs_sb_flags(cifs_sb) & CIFS_MOUNT_MULTIUSER)) @@ -4481,7 +4525,16 @@ cifs_sb_tlink(struct cifs_sb_info *cifs_sb) goto wait_for_construction; } - tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid); + tcon = cifs_construct_tcon(cifs_sb, fsuid); + scoped_guard(spinlock, &cifs_sb->tlink_tree_lock) { + tlink->tl_tcon = tcon; + if (!IS_ERR(tcon)) { + scoped_guard(spinlock, &tcon->tc_lock) + tcon->mnt_unlinked--; + if (!test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags)) + drop_mnt_ref(tcon); + } + } clear_bit(TCON_LINK_PENDING, &tlink->tl_flags); wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING); @@ -4530,8 +4583,7 @@ cifs_prune_tlinks(struct work_struct *work) continue; cifs_get_tlink(tlink); - clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); - rb_erase(tmp, root); + erase_tlink(cifs_sb, tlink); spin_unlock(&cifs_sb->tlink_tree_lock); cifs_put_tlink(tlink); diff --git a/fs/smb/client/dfs.c b/fs/smb/client/dfs.c index b7143335d70a5a..57c90a2512a3cb 100644 --- a/fs/smb/client/dfs.c +++ b/fs/smb/client/dfs.c @@ -33,7 +33,7 @@ int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_para if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0)) return -EINVAL; - if (strlen(full_path) - ref->path_consumed) { + if ((size_t)ref->path_consumed < strlen(full_path)) { prepath = full_path + ref->path_consumed; /* skip initial delimiter */ if (*prepath == '/' || *prepath == '\\') @@ -103,6 +103,7 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw) struct cifs_sb_info *cifs_sb = rw->mnt_ctx->cifs_sb; struct smb3_fs_context *ctx = rw->mnt_ctx->fs_ctx; char *ref_path, *full_path; + const char *raw_path; int rc; set_root_smb_session(rw->mnt_ctx); @@ -114,9 +115,10 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw) if (!tgt || (tgt->server_type == DFS_TYPE_LINK && DFS_INTERLINK(tgt->flags))) - ref_path = dfs_get_path(cifs_sb, ctx->UNC); + raw_path = ctx->UNC; else - ref_path = dfs_get_path(cifs_sb, full_path); + raw_path = full_path; + ref_path = dfs_get_path(cifs_sb, raw_path); if (IS_ERR(ref_path)) { rc = PTR_ERR(ref_path); kfree(full_path); @@ -125,9 +127,7 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw) ref_walk_path(rw) = ref_path; ref_walk_fpath(rw) = full_path; - return dfs_get_referral(rw->mnt_ctx, - ref_walk_path(rw) + 1, - ref_walk_tl(rw)); + return dfs_get_referral(rw->mnt_ctx, raw_path + 1, ref_walk_tl(rw)); } static int __dfs_referral_walk(struct dfs_ref_walk *rw) diff --git a/fs/smb/client/dfs_cache.c b/fs/smb/client/dfs_cache.c index 26956e33037e7c..02864f7acefc25 100644 --- a/fs/smb/client/dfs_cache.c +++ b/fs/smb/client/dfs_cache.c @@ -798,7 +798,7 @@ static int get_targets(struct cache_entry *ce, struct dfs_cache_tgt_list *tl) INIT_LIST_HEAD(head); list_for_each_entry(t, &ce->tlist, list) { - it = kzalloc_obj(*it, GFP_KERNEL); + it = kzalloc_obj(*it); if (!it) { rc = -ENOMEM; goto err_free_it; diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 0767eb5f4687ae..f51653cb6432a7 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -37,7 +37,261 @@ #include "cached_dir.h" #include -static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush); +/* flags for cifs_reopen_file() */ +#define CIFS_REOPEN_BOUND BIT(0) /* caller bounds the retries */ +#define CIFS_REOPEN_NOWAIT BIT(1) /* fail fast, skip reconnect wait */ + +static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush, + unsigned int flags); + +bool cifs_io_stopped(struct cifs_io_subrequest *subreq) +{ + struct super_block *sb = subreq->rreq->inode->i_sb; + struct cifs_sb_info *cifs_sb = CIFS_SB(sb); + int aborts; + + if (cifs_forced_shutdown(cifs_sb) || READ_ONCE(cifs_sb->exiting)) + return true; + aborts = atomic_read(&cifs_sb->umount_aborts); + if (aborts != subreq->req->umount_aborts) + return true; + return aborts && rwsem_is_contended(&sb->s_umount); +} + +static bool cifs_writeback_retry_expired(struct cifs_io_subrequest *subreq, + struct cifs_tcon *tcon) +{ + struct TCP_Server_Info *server = tcon->ses->server; + unsigned long window; + + if (tcon->retry) + return false; + if (!subreq->retry_deadline) { + window = max(3U, server->retrans) * server->echo_interval; + subreq->retry_deadline = (jiffies + window) | 1; + } + return time_after(jiffies, subreq->retry_deadline); +} + +bool cifs_io_should_replay(struct cifs_io_subrequest *subreq) +{ + struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink); + + if (cifs_io_stopped(subreq)) + return false; + if (subreq->rreq->origin == NETFS_WRITEBACK) { + if (cifs_writeback_retry_expired(subreq, tcon)) + return false; + smb2_replay_backoff(&subreq->cur_sleep); + return true; + } + return smb2_should_replay(tcon, &subreq->retries, &subreq->cur_sleep); +} + +static bool cifs_io_aborted(struct cifs_io_subrequest *subreq) +{ + struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink); + + if (!cifs_io_stopped(subreq)) + return false; + return subreq->subreq.retry_count || subreq->replay || + READ_ONCE(subreq->server->tcpStatus) == CifsNeedReconnect || + tcon->need_reconnect; +} + +static bool cifs_writeback_transient(int rc) +{ + if (is_replayable_error(rc) || is_interrupt_error(rc)) + return true; + + switch (rc) { + case -ENOMEM: + case -EHOSTDOWN: + case -ENETRESET: + case -ESHUTDOWN: + case -EREMCHG: + case -EBADF: + return true; + } + return false; +} + +static int cifs_writeback_error(struct netfs_io_subrequest *subreq, int rc) +{ + if (subreq->rreq->origin == NETFS_WRITEBACK && + cifs_writeback_transient(rc)) + return -EIO; + return rc; +} + +static bool cifs_writeback_dying(struct netfs_io_subrequest *subreq) +{ + return subreq->rreq->origin == NETFS_WRITEBACK && + fatal_signal_pending(current); +} + +static unsigned int cifs_ses_reconnects(struct cifs_ses *ses) +{ + unsigned int n = 0; + + guard(spinlock)(&ses->chan_lock); + for (size_t i = 0; i < ses->chan_count; i++) { + struct TCP_Server_Info *server = ses->chans[i].server; + + if (server) + n += READ_ONCE(server->reconnect_instance); + } + return n; +} + +static bool cifs_tcon_reconnecting(struct cifs_tcon *tcon) +{ + struct cifs_ses *ses = tcon->ses; + + if (tcon->need_reconnect) + return true; + + guard(spinlock)(&ses->chan_lock); + for (size_t i = 0; i < ses->chan_count; i++) { + struct TCP_Server_Info *server = ses->chans[i].server; + + if (server && READ_ONCE(server->tcpStatus) == CifsNeedReconnect) + return true; + } + return false; +} + +static int cifs_reopen_file_retry(struct cifsFileInfo *cfile, bool can_flush, + struct cifs_io_subrequest *subreq) +{ + struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); + struct cifs_ses *ses = tcon->ses; + unsigned int reconnects; + bool free_retry = true; + bool retrying = false; + int rc; + + for (;;) { + if ((retrying && cifs_io_stopped(subreq)) || + cifs_io_aborted(subreq)) + return -EIO; + retrying = true; + reconnects = cifs_ses_reconnects(ses); + rc = cifs_reopen_file(cfile, can_flush, CIFS_REOPEN_BOUND); + if (!rc || !is_replayable_error(rc)) + return rc; + if (free_retry && !cifs_io_stopped(subreq) && + (cifs_ses_reconnects(ses) != reconnects || + cifs_tcon_reconnecting(tcon))) { + free_retry = false; + continue; + } + if (!cifs_io_should_replay(subreq)) + return rc; + msleep(subreq->cur_sleep); + } +} + +/* + * Record, as generation + 1 (0 means none), the newest reopen generation of a + * handle that a writeback subrequest found bad (-EBADF). Subrequests of the + * same request can fail concurrently on different channels, so keep the newest. + */ +static void cifs_mark_bad_handle(struct cifs_io_request *req, unsigned int gen) +{ + int cur = atomic_read(&req->bad_reopens); + int want = gen + 1; + + while (want > cur && !atomic_try_cmpxchg(&req->bad_reopens, &cur, want)) + ; +} + +static bool cifs_bad_handle_pending(struct cifs_io_request *req) +{ + unsigned int bad = atomic_read(&req->bad_reopens); + + return bad && bad - 1 == READ_ONCE(req->cfile->reopens); +} + +static void __cifs_invalidate_bad_handle(struct cifs_io_request *req) +{ + unsigned int bad = atomic_read(&req->bad_reopens); + struct cifsFileInfo *cfile = req->cfile; + + lockdep_assert_held(&cfile->fh_mutex); + if (bad && bad - 1 == cfile->reopens) + cfile->invalidHandle = true; +} + +static void cifs_invalidate_bad_handle(struct cifs_io_request *req) +{ + if (!cifs_bad_handle_pending(req)) + return; + guard(mutex)(&req->cfile->fh_mutex); + __cifs_invalidate_bad_handle(req); +} + +static bool cifs_try_invalidate_bad_handle(struct cifs_io_request *req) +{ + if (!cifs_bad_handle_pending(req)) + return true; + if (!mutex_trylock(&req->cfile->fh_mutex)) + return false; + __cifs_invalidate_bad_handle(req); + mutex_unlock(&req->cfile->fh_mutex); + return true; +} + +static int cifs_reopen_failed(struct cifs_io_request *req) +{ + if (READ_ONCE(req->reopen_gave_up)) + return -EIO; + return READ_ONCE(req->reopen_err); +} + +static int cifs_reopen_writeback(struct cifs_io_subrequest *wdata) +{ + struct cifs_io_request *req = wdata->req; + struct cifsFileInfo *cfile = req->cfile; + int rc; + + if (cifs_io_aborted(wdata)) + return -EIO; + + guard(mutex)(&req->reopen_lock); + if (!cifs_bad_handle_pending(req) && !cfile->invalidHandle) + return 0; + + rc = cifs_reopen_failed(req); + if (rc) + return rc; + + rc = req->reopen_pass_err; + if (!rc) { + if (!cifs_try_invalidate_bad_handle(req)) + rc = -EAGAIN; + else if (cfile->invalidHandle) + rc = cifs_reopen_file(cfile, false, + CIFS_REOPEN_BOUND | + CIFS_REOPEN_NOWAIT); + if (!rc) + return 0; + if (!cifs_writeback_transient(rc)) { + WRITE_ONCE(req->reopen_err, rc); + return rc; + } + req->reopen_pass_err = rc; + } + + if (!cifs_io_should_replay(wdata)) { + WRITE_ONCE(req->reopen_gave_up, true); + return -EIO; + } + + trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); + __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + return rc; +} /* * Prepare a subrequest to upload to the server. We need to allocate credits @@ -52,6 +306,8 @@ static void cifs_prepare_write(struct netfs_io_subrequest *subreq) struct TCP_Server_Info *server; struct cifsFileInfo *open_file = req->cfile; struct cifs_sb_info *cifs_sb = CIFS_SB(wdata->rreq->inode->i_sb); + bool writeback = subreq->rreq->origin == NETFS_WRITEBACK; + bool reprepared = wdata->have_xid; size_t wsize = req->rreq.wsize; int rc; @@ -62,29 +318,68 @@ static void cifs_prepare_write(struct netfs_io_subrequest *subreq) server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses); wdata->server = server; + wdata->deferred = false; + + if (reprepared) { + req->retry_deadline = wdata->retry_deadline; + req->cur_sleep = wdata->cur_sleep; + req->replay = wdata->replay; + } else if (subreq->retry_count) { + wdata->retry_deadline = req->retry_deadline; + wdata->cur_sleep = req->cur_sleep; + wdata->replay = req->replay; + } + + if (cifs_io_aborted(wdata) || + (reprepared && cifs_io_stopped(wdata))) { + subreq->error = -EIO; + return netfs_prepare_write_failed(subreq); + } if (cifs_sb->ctx->wsize == 0) cifs_negotiate_wsize(server, cifs_sb->ctx, tlink_tcon(req->cfile->tlink)); -retry: - if (open_file->invalidHandle) { - rc = cifs_reopen_file(open_file, false); - if (rc < 0) { - if (rc == -EAGAIN) - goto retry; + if (writeback && + (cifs_bad_handle_pending(req) || open_file->invalidHandle)) { + rc = cifs_reopen_failed(req); + if (rc) { subreq->error = rc; return netfs_prepare_write_failed(subreq); } + goto defer; + } + + if (cifs_writeback_dying(subreq)) + goto defer; + + if (!writeback) { + cifs_invalidate_bad_handle(req); + if (open_file->invalidHandle) { + rc = cifs_reopen_file_retry(open_file, false, wdata); + if (rc < 0) { + subreq->error = rc; + return netfs_prepare_write_failed(subreq); + } + } } rc = server->ops->wait_mtu_credits(server, wsize, &stream->sreq_max_len, - &wdata->credits); + &wdata->credits, writeback); if (rc < 0) { - subreq->error = rc; + if (cifs_writeback_dying(subreq) || + (writeback && rc == -EAGAIN)) + goto defer; + subreq->error = cifs_writeback_error(subreq, rc); return netfs_prepare_write_failed(subreq); } + goto out; +defer: + wdata->deferred = true; + wdata->credits = (struct cifs_credits){}; + stream->sreq_max_len = min_t(size_t, wsize, SMB2_MAX_BUFFER_SIZE); +out: wdata->credits.rreq_debug_id = subreq->rreq->debug_id; wdata->credits.rreq_debug_index = subreq->debug_index; wdata->credits.in_flight_check = 1; @@ -108,7 +403,7 @@ static void cifs_prepare_write(struct netfs_io_subrequest *subreq) /* * Issue a subrequest to upload to the server. */ -static void cifs_issue_write(struct netfs_io_subrequest *subreq) +static void __cifs_issue_write(struct netfs_io_subrequest *subreq) { struct cifs_io_subrequest *wdata = container_of(subreq, struct cifs_io_subrequest, subreq); @@ -120,28 +415,142 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq) goto fail; } + rc = -EIO; + if (cifs_io_aborted(wdata)) + goto fail; + rc = adjust_credits(wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust); if (rc) goto fail; rc = -EAGAIN; - if (wdata->req->cfile->invalidHandle) + if (wdata->req->cfile->invalidHandle || + (wdata->credits.value && + wdata->credits.instance != + READ_ONCE(wdata->server->reconnect_instance))) goto fail; + /* pairs with smp_store_release() in cifs_reopen_file() */ + wdata->reopens = smp_load_acquire(&wdata->req->cfile->reopens); wdata->server->ops->async_writev(wdata); out: return; fail: - if (rc == -EAGAIN) + if (rc == -EAGAIN) { trace_netfs_sreq(subreq, netfs_sreq_trace_retry); - else + __set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); + } else { trace_netfs_sreq(subreq, netfs_sreq_trace_fail); + } add_credits_and_wake_if(wdata->server, &wdata->credits, 0); cifs_write_subrequest_terminated(wdata, rc); goto out; } +static void cifs_issue_write_worker(struct work_struct *work) +{ + struct cifs_io_subrequest *wdata; + struct cifsFileInfo *cfile; + int rc = 0; + + wdata = container_of(work, struct cifs_io_subrequest, subreq.work); + cfile = wdata->req->cfile; + if (cifs_bad_handle_pending(wdata->req) || cfile->invalidHandle) + rc = cifs_reopen_writeback(wdata); + if (rc) { + add_credits_and_wake_if(wdata->server, &wdata->credits, 0); + cifs_write_subrequest_terminated(wdata, rc); + return; + } + __cifs_issue_write(&wdata->subreq); +} + +static void cifs_issue_write(struct netfs_io_subrequest *subreq) +{ + struct cifs_io_subrequest *wdata = + container_of(subreq, struct cifs_io_subrequest, subreq); + struct cifs_io_request *req = wdata->req; + + if (wdata->cur_sleep > req->slept) { + msleep(wdata->cur_sleep - req->slept); + req->slept = wdata->cur_sleep; + } + + if (unlikely(wdata->deferred || cifs_writeback_dying(subreq))) { + subreq->work.func = cifs_issue_write_worker; + WARN_ON_ONCE(!queue_work(cifs_writeback_wq, &subreq->work)); + return; + } + __cifs_issue_write(subreq); +} + +static void cifs_share_retry_state(struct netfs_io_subrequest *from, + struct netfs_io_subrequest *stop, + struct list_head *head) +{ + struct netfs_io_subrequest *subreq = from; + struct cifs_io_subrequest *wdata; + unsigned long deadline = 0; + unsigned int sleep = 0; + bool replay = false; + + list_for_each_entry_from(subreq, head, rreq_link) { + if (subreq == stop) + break; + wdata = container_of(subreq, struct cifs_io_subrequest, subreq); + if (wdata->retry_deadline && + (!deadline || time_before(wdata->retry_deadline, deadline))) + deadline = wdata->retry_deadline; + sleep = max(sleep, wdata->cur_sleep); + replay |= wdata->replay; + } + + subreq = from; + list_for_each_entry_from(subreq, head, rreq_link) { + if (subreq == stop) + break; + wdata = container_of(subreq, struct cifs_io_subrequest, subreq); + wdata->retry_deadline = deadline; + wdata->cur_sleep = sleep; + wdata->replay = replay; + } +} + +static void cifs_retry_request(struct netfs_io_request *wreq, + struct netfs_io_stream *stream) +{ + struct netfs_io_subrequest *subreq, *from = NULL; + struct cifs_io_request *req = + container_of(wreq, struct cifs_io_request, rreq); + uoff_t end = 0; + + req->slept = 0; + req->reopen_pass_err = 0; + if (!stream) + return; + + guard(spinlock)(&wreq->lock); + list_for_each_entry(subreq, &stream->subrequests, rreq_link) { + if (from && test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags) && + !test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) && + subreq->start + subreq->transferred == end) { + end += subreq->len; + continue; + } + if (from) + cifs_share_retry_state(from, subreq, + &stream->subrequests); + from = NULL; + if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) { + from = subreq; + end = subreq->start + subreq->len; + } + } + if (from) + cifs_share_retry_state(from, NULL, &stream->subrequests); +} + static void cifs_netfs_invalidate_cache(struct netfs_io_request *wreq) { cifs_invalidate_cache(wreq->inode, 0); @@ -157,6 +566,7 @@ static int cifs_prepare_read(struct netfs_io_subrequest *subreq) struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); struct TCP_Server_Info *server; struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); + bool reprepared = rdata->have_xid; size_t size; int rc = 0; @@ -168,12 +578,22 @@ static int cifs_prepare_read(struct netfs_io_subrequest *subreq) server = cifs_pick_channel(tlink_tcon(req->cfile->tlink)->ses); rdata->server = server; + if (cifs_io_aborted(rdata) || + (reprepared && cifs_io_stopped(rdata))) + return -EIO; + if (cifs_sb->ctx->rsize == 0) cifs_negotiate_rsize(server, cifs_sb->ctx, tlink_tcon(req->cfile->tlink)); + if (req->cfile->invalidHandle) { + rc = cifs_reopen_file_retry(req->cfile, true, rdata); + if (rc) + return rc; + } + rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize, - &size, &rdata->credits); + &size, &rdata->credits, false); if (rc) return rc; @@ -218,18 +638,27 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq) __func__, rreq->debug_id, subreq->debug_index, rreq->mapping, subreq->transferred, subreq->len); + rc = -EIO; + if (cifs_io_aborted(rdata)) + goto failed; + rc = adjust_credits(server, rdata, cifs_trace_rw_credits_issue_read_adjust); if (rc) - goto failed; + goto not_sent; - if (req->cfile->invalidHandle) { - do { - rc = cifs_reopen_file(req->cfile, true); - } while (rc == -EAGAIN); - if (rc) + if (rdata->replay && rdata->cur_sleep) { + msleep(rdata->cur_sleep); + rc = -EIO; + if (cifs_io_aborted(rdata)) goto failed; } + rc = -EAGAIN; + if (req->cfile->invalidHandle || + (rdata->credits.value && + rdata->credits.instance != READ_ONCE(server->reconnect_instance))) + goto not_sent; + if (subreq->rreq->origin != NETFS_UNBUFFERED_READ && subreq->rreq->origin != NETFS_DIO_READ) __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags); @@ -240,6 +669,11 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq) goto failed; return; +not_sent: + if (rc == -EAGAIN) { + trace_netfs_sreq(subreq, netfs_sreq_trace_retry); + __set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); + } failed: add_credits_and_wake_if(rdata->server, &rdata->credits, 0); subreq->error = rc; @@ -255,9 +689,17 @@ static void cifs_begin_writeback(struct netfs_io_request *wreq) struct cifs_io_request *req = container_of(wreq, struct cifs_io_request, rreq); int ret; - ret = cifs_get_writable_file(CIFS_I(wreq->inode), FIND_ANY, &req->cfile); + ret = cifs_get_writable_file(CIFS_I(wreq->inode), + FIND_NO_REOPEN | FIND_NO_DIRECT, + &req->cfile); + if (ret) { + ret = cifs_get_writable_file(CIFS_I(wreq->inode), + FIND_NO_REOPEN, &req->cfile); + } if (ret) { - cifs_dbg(VFS, "No writable handle in writepages ret=%d\n", ret); + cifs_dbg(VFS, "%s: couldn't find writable handle: %d\n", + __func__, ret); + mapping_set_error(wreq->mapping, -EIO); return; } @@ -276,6 +718,8 @@ static int cifs_init_request(struct netfs_io_request *rreq, struct file *file) rreq->rsize = cifs_sb->ctx->rsize; rreq->wsize = cifs_sb->ctx->wsize; req->pid = current->tgid; // Ummm... This may be a workqueue + req->umount_aborts = atomic_read(&cifs_sb->umount_aborts); + mutex_init(&req->reopen_lock); if (file) { open_file = file->private_data; @@ -364,6 +808,7 @@ const struct netfs_request_ops cifs_req_ops = { .begin_writeback = cifs_begin_writeback, .prepare_write = cifs_prepare_write, .issue_write = cifs_issue_write, + .retry_request = cifs_retry_request, .invalidate_cache = cifs_netfs_invalidate_cache, }; @@ -1274,8 +1719,18 @@ cifs_relock_file(struct cifsFileInfo *cfile) return rc; } +static bool reopen_aborted(struct cifs_tcon *tcon, int aborts) +{ + struct TCP_Server_Info *server; + + if (atomic_read(&tcon->umount_aborts) == aborts) + return false; + server = cifs_pick_channel(tcon->ses); + return server && READ_ONCE(server->tcpStatus) == CifsNeedReconnect; +} + static int -cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) +cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush, unsigned int flags) { int rc = -EACCES; unsigned int xid; @@ -1292,18 +1747,31 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) int create_options = CREATE_NOT_DIR; struct cifs_open_parms oparms; int rdwr_for_fscache = 0; + int aborts; + bool fresh; + tcon = tlink_tcon(cfile->tlink); + aborts = atomic_read(&tcon->umount_aborts); xid = get_xid(); - mutex_lock(&cfile->fh_mutex); + if (!(flags & CIFS_REOPEN_NOWAIT)) { + mutex_lock(&cfile->fh_mutex); + } else if (!mutex_trylock(&cfile->fh_mutex)) { + free_xid(xid); + return -EAGAIN; + } if (!cfile->invalidHandle) { mutex_unlock(&cfile->fh_mutex); free_xid(xid); return 0; } + if (reopen_aborted(tcon, aborts)) { + mutex_unlock(&cfile->fh_mutex); + free_xid(xid); + return -EHOSTDOWN; + } inode = d_inode(cfile->dentry); cifs_sb = CIFS_SB(inode->i_sb); - tcon = tlink_tcon(cfile->tlink); server = tcon->ses->server; /* @@ -1359,6 +1827,10 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) if (cifs_fscache_enabled(inode) && (cfile->f_flags & O_ACCMODE) == O_WRONLY) rdwr_for_fscache = 1; + if (cfile->reopen_replay && rdwr_for_fscache == 1 && + !(cfile->reopen_access & GENERIC_READ)) + rdwr_for_fscache = 2; + desired_access = cifs_convert_flags(cfile->f_flags, rdwr_for_fscache); create_options |= cifs_open_create_options(cfile->f_flags, create_options); @@ -1367,15 +1839,21 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) server->ops->get_lease_key(inode, &cfile->fid); retry_open: + fresh = cfile->reopen_fresh; oparms = (struct cifs_open_parms) { .tcon = tcon, .cifs_sb = cifs_sb, - .desired_access = desired_access, + .desired_access = cfile->reopen_replay ? + cfile->reopen_access : desired_access, .create_options = cifs_create_options(cifs_sb, create_options), .disposition = disposition, .path = full_path, .fid = &cfile->fid, - .reconnect = true, + .reconnect = !fresh, + .replay = cfile->reopen_replay, + .pending = cfile->reopen_replay, + .no_replay = !!(flags & CIFS_REOPEN_BOUND), + .no_reconnect_wait = !!(flags & CIFS_REOPEN_NOWAIT), }; /* @@ -1385,14 +1863,28 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) * version of file size can be stale. If we knew for sure that inode was * not dirty locally we could do this. */ - rc = server->ops->open(xid, &oparms, &oplock, NULL); - if (rc == -ENOENT && oparms.reconnect == false) { - /* durable handle timeout is expired - open the file again */ + if (reopen_aborted(tcon, aborts)) + rc = -EHOSTDOWN; + else rc = server->ops->open(xid, &oparms, &oplock, NULL); - /* indicate that we need to relock the file */ - oparms.reconnect = true; + if (rc == -ENOENT && !fresh && !oparms.reconnect && !oparms.pending) { + /* durable handle timeout is expired - open the file again */ + fresh = true; + oparms.desired_access = desired_access; + oparms.replay = false; + if (reopen_aborted(tcon, aborts)) + rc = -EHOSTDOWN; + else + rc = server->ops->open(xid, &oparms, &oplock, NULL); } - if (rc == -EACCES && rdwr_for_fscache == 1) { + cfile->reopen_fresh = rc && fresh; + cfile->reopen_replay = rc && oparms.pending; + if (cfile->reopen_replay) + cfile->reopen_access = oparms.desired_access; + /* indicate that we need to relock the file */ + if (fresh) + oparms.reconnect = true; + if (rc == -EACCES && rdwr_for_fscache == 1 && !oparms.pending) { desired_access = cifs_convert_flags(cfile->f_flags, 0); rdwr_for_fscache = 2; goto retry_open; @@ -1411,6 +1903,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY reopen_success: #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ + /* pairs with smp_load_acquire() in __cifs_issue_write() */ + smp_store_release(&cfile->reopens, cfile->reopens + 1); cfile->invalidHandle = false; mutex_unlock(&cfile->fh_mutex); cinode = CIFS_I(inode); @@ -1546,14 +2040,16 @@ int cifs_close(struct inode *inode, struct file *file) return 0; } -void +bool cifs_reopen_persistent_handles(struct cifs_tcon *tcon) { struct cifsFileInfo *open_file, *tmp; LIST_HEAD(tmp_list); + bool retry = false; + int rc; if (!tcon->use_persistent || !tcon->need_reopen_files) - return; + return false; tcon->need_reopen_files = false; @@ -1570,11 +2066,17 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon) spin_unlock(&tcon->open_file_lock); list_for_each_entry_safe(open_file, tmp, &tmp_list, rlist) { - if (cifs_reopen_file(open_file, false /* do not flush */)) + /* do not flush */ + rc = cifs_reopen_file(open_file, false, + CIFS_REOPEN_BOUND | CIFS_REOPEN_NOWAIT); + if (rc) { tcon->need_reopen_files = true; + retry |= is_replayable_error(rc); + } list_del_init(&open_file->rlist); cifsFileInfo_put(open_file); } + return retry; } int cifs_closedir(struct inode *inode, struct file *file) @@ -2235,7 +2737,7 @@ cifs_get_hardlink_path(struct cifs_tcon *tcon, struct inode *inode, spin_lock(&cinode->open_file_lock); list_for_each_entry(open_file, &cinode->openFileList, flist) { - if (file->f_flags == open_file->f_flags) { + if (open_file->dentry != file_dentry(file)) { rc = -EINVAL; break; } @@ -2629,6 +3131,20 @@ void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t spin_unlock(&inode->i_lock); } + if (wreq->origin == NETFS_WRITEBACK && + !test_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags) && + cifs_writeback_transient(result) && cifs_io_should_replay(wdata)) { + if (result == -EBADF) + cifs_mark_bad_handle(wdata->req, wdata->reopens); + wdata->replay = true; + trace_netfs_sreq(&wdata->subreq, + netfs_sreq_trace_io_retry_needed); + __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + } + + if (result < 0 && + !test_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags)) + result = cifs_writeback_error(&wdata->subreq, result); netfs_write_subrequest_terminated(&wdata->subreq, result); } @@ -2722,7 +3238,7 @@ int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, } if (test_bit(CIFS_INO_TMPFILE, &cifs_inode->flags)) - find_flags = FIND_ANY; + find_flags &= FIND_NO_REOPEN | FIND_NO_DIRECT; cifs_sb = CIFS_SB(cifs_inode); @@ -2752,6 +3268,9 @@ int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, !open_flags_match(cifs_inode, open_flags, open_file->f_flags)) continue; + if ((find_flags & FIND_NO_DIRECT) && + (open_file->f_flags & O_DIRECT)) + continue; if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { if (!open_file->invalidHandle) { /* found a good writable file */ @@ -2779,7 +3298,11 @@ int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, spin_unlock(&cifs_inode->open_file_lock); if (inv_file) { - rc = cifs_reopen_file(inv_file, false); + if (find_flags & FIND_NO_REOPEN) { + *ret_file = inv_file; + return 0; + } + rc = cifs_reopen_file(inv_file, false, 0); if (!rc) { *ret_file = inv_file; return 0; @@ -2880,6 +3403,45 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, return -ENOENT; } +static int cifs_wait_writeback_killable(struct address_space *mapping, + loff_t start, loff_t end) +{ + pgoff_t end_index = end >> PAGE_SHIFT; + pgoff_t index = start >> PAGE_SHIFT; + struct folio_batch fbatch; + int rc = 0; + + folio_batch_init(&fbatch); + while (!rc && + filemap_get_folios_tag(mapping, &index, end_index, + PAGECACHE_TAG_WRITEBACK, &fbatch)) { + for (unsigned int i = 0; + !rc && i < folio_batch_count(&fbatch); i++) + rc = folio_wait_writeback_killable(fbatch.folios[i]); + folio_batch_release(&fbatch); + cond_resched(); + } + return rc; +} + +static int cifs_file_write_and_wait_killable(struct file *file, + loff_t start, loff_t end) +{ + struct address_space *mapping = file->f_mapping; + int rc, rc2; + + if (end < start) + return 0; + + rc = filemap_fdatawrite_range(mapping, start, end); + if (cifs_wait_writeback_killable(mapping, start, end)) + return -EINTR; + rc2 = file_check_and_advance_wb_err(file); + if (!rc) + rc = rc2; + return rc; +} + /* * Flush data on a strict file. */ @@ -2891,7 +3453,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, unsigned int xid; int rc; - rc = file_write_and_wait_range(file, start, end); + rc = cifs_file_write_and_wait_killable(file, start, end); if (rc) { trace_cifs_fsync_err(inode->i_ino, rc); return rc; @@ -2923,7 +3485,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) struct inode *inode = file_inode(file); struct cifs_sb_info *cifs_sb = CIFS_SB(file); - rc = file_write_and_wait_range(file, start, end); + rc = cifs_file_write_and_wait_killable(file, start, end); if (rc) { trace_cifs_fsync_err(file_inode(file)->i_ino, rc); return rc; @@ -2964,11 +3526,19 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) */ int cifs_flush(struct file *file, fl_owner_t id) { + struct address_space *mapping = file->f_mapping; struct inode *inode = file_inode(file); - int rc = 0; + int rc = 0, rc2; - if (file->f_mode & FMODE_WRITE) - rc = filemap_write_and_wait(inode->i_mapping); + if (file->f_mode & FMODE_WRITE) { + rc = filemap_fdatawrite(mapping); + if (fatal_signal_pending(current) || + cifs_wait_writeback_killable(mapping, 0, LLONG_MAX)) + return 0; + rc2 = filemap_check_errors(mapping); + if (!rc) + rc = rc2; + } cifs_dbg(FYI, "Flush inode %p file %p rc %d\n", inode, file, rc); if (rc) { @@ -3357,6 +3927,14 @@ void cifs_oplock_break(struct work_struct *work) __u64 persistent_fid, volatile_fid; __u16 net_fid; + /* + * Dropping the handle reference below also drops the dentry + * reference that pins this inode, and cinode is still needed to + * acknowledge the break and to report it as complete. Hold the inode + * until that is done. + */ + ihold(inode); + wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS, TASK_UNINTERRUPTIBLE); @@ -3444,6 +4022,7 @@ void cifs_oplock_break(struct work_struct *work) cifs_put_tlink(tlink); out: cifs_done_oplock_break(cinode); + iput(inode); } #ifdef CONFIG_SWAP diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index ec28f102ea08a1..4d0df73d15d7ac 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -1073,7 +1073,17 @@ int cifs_inval_name_dfs_link_error(const unsigned int xid, } #endif -int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry) +static bool reco_wait_done(struct TCP_Server_Info *server, + struct cifs_tcon *tcon, int aborts) +{ + return server->tcpStatus != CifsNeedReconnect || + atomic_read(&tcon->umount_aborts) != aborts || + cifs_tcon_dying(tcon); +} + +int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, + struct cifs_tcon *tcon, int aborts, + bool nowait) { int timeout = 10; int rc; @@ -1083,6 +1093,10 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry) spin_unlock(&server->srv_lock); return 0; } + if (nowait) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } timeout *= server->nr_targets; spin_unlock(&server->srv_lock); @@ -1096,7 +1110,9 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry) */ do { rc = wait_event_interruptible_timeout(server->response_q, - (server->tcpStatus != CifsNeedReconnect), + reco_wait_done(server, + tcon, + aborts), timeout * HZ); if (rc < 0) { cifs_dbg(FYI, "%s: aborting reconnect due to received signal\n", @@ -1111,7 +1127,7 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry) return 0; } spin_unlock(&server->srv_lock); - } while (retry); + } while (cifs_tcon_retry(tcon, aborts)); cifs_dbg(FYI, "%s: gave up waiting on reconnect\n", __func__); return -EHOSTDOWN; diff --git a/fs/smb/client/sess.c b/fs/smb/client/sess.c index c1fc90726e2d15..fe006e9f2e1025 100644 --- a/fs/smb/client/sess.c +++ b/fs/smb/client/sess.c @@ -666,8 +666,8 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, } if (memcmp(pblob->Signature, "NTLMSSP", 8)) { - cifs_dbg(VFS, "blob signature incorrect %s\n", - pblob->Signature); + cifs_dbg(VFS, "%s: blob signature incorrect: %8phN\n", + __func__, pblob->Signature); return -EINVAL; } if (pblob->MessageType != NtLmChallenge) { diff --git a/fs/smb/client/smb2file.c b/fs/smb/client/smb2file.c index fb2fccbe86677e..764cfd894ad09c 100644 --- a/fs/smb/client/smb2file.c +++ b/fs/smb/client/smb2file.c @@ -175,6 +175,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, struct cifs_fid *fid = oparms->fid; struct network_resiliency_req nr_ioctl_req; bool retry_without_read_attributes = false; + bool reconnect = oparms->reconnect; smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb); if (smb2_path == NULL) @@ -186,23 +187,30 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, * FILE_READ_ATTRIBUTES when not needed and prevent calling code path * for retry_without_read_attributes. */ - if (!(oparms->desired_access & FILE_READ_ATTRIBUTES) && - !(oparms->desired_access & GENERIC_READ) && + if (!(oparms->desired_access & GENERIC_READ) && !(oparms->desired_access & GENERIC_EXECUTE) && !(oparms->desired_access & GENERIC_ALL) && !(oparms->desired_access & MAXIMUM_ALLOWED)) { - oparms->desired_access |= FILE_READ_ATTRIBUTES; - retry_without_read_attributes = true; + if (oparms->replay) { + retry_without_read_attributes = + oparms->desired_access & FILE_READ_ATTRIBUTES; + } else if (!(oparms->desired_access & FILE_READ_ATTRIBUTES)) { + oparms->desired_access |= FILE_READ_ATTRIBUTES; + retry_without_read_attributes = true; + } } smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH; rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov, &err_buftype); - if (rc == -EACCES && retry_without_read_attributes) { + if (rc == -EACCES && retry_without_read_attributes && + !oparms->pending) { free_rsp_buf(err_buftype, err_iov.iov_base); memset(&err_iov, 0, sizeof(err_iov)); err_buftype = CIFS_NO_BUFFER; oparms->desired_access &= ~FILE_READ_ATTRIBUTES; + oparms->reconnect = reconnect; + oparms->replay = false; rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov, &err_buftype); } diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index dc55cd512616ab..298f549bd7ed37 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -244,7 +244,7 @@ smb2_get_credits(struct mid_q_entry *mid) static int smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size, - size_t *num, struct cifs_credits *credits) + size_t *num, struct cifs_credits *credits, bool nowait) { int rc = 0; unsigned int scredits, in_flight; @@ -258,6 +258,10 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size, spin_unlock(&server->srv_lock); return -ENOENT; } + if (nowait && server->tcpStatus == CifsNeedReconnect) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } spin_unlock(&server->srv_lock); spin_lock(&server->req_lock); @@ -265,7 +269,8 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size, spin_unlock(&server->req_lock); cifs_num_waiters_inc(server); rc = wait_event_killable(server->request_q, - has_credits(server, &server->credits, 1)); + credits_or_conn_down(server, &server->credits, + 1, nowait)); cifs_num_waiters_dec(server); if (rc) return rc; @@ -2933,15 +2938,12 @@ bool smb2_should_replay(struct cifs_tcon *tcon, if (!pretries || !pcur_sleep) return false; + /* the tcon is being torn down; stop replaying */ + if (cifs_tcon_dying(tcon)) + return false; + if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) { - /* Update sleep time for exponential backoff */ - if (!(*pcur_sleep)) - (*pcur_sleep) = 1; - else { - (*pcur_sleep) = ((*pcur_sleep) << 1); - if ((*pcur_sleep) > CIFS_MAX_SLEEP) - (*pcur_sleep) = CIFS_MAX_SLEEP; - } + smb2_replay_backoff(pcur_sleep); return true; } diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index f85595136ef8a2..b26bfb4bd91ae4 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -248,11 +248,14 @@ int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *serve static int smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, - struct TCP_Server_Info *server, bool from_reconnect) + struct TCP_Server_Info *server, bool from_reconnect, + bool nowait) { + bool hold_server_ref = false; struct cifs_ses *ses; - int xid; int rc = 0; + int aborts; + int xid; /* * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so @@ -262,6 +265,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, if (tcon == NULL) return 0; + aborts = atomic_read(&tcon->umount_aborts); + if (smb2_command == SMB2_TREE_CONNECT) return 0; @@ -308,6 +313,10 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, spin_unlock(&server->srv_lock); return -EAGAIN; } + if (nowait) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } } /* if server is marked for termination, cifsd will cleanup */ @@ -318,7 +327,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, spin_unlock(&server->srv_lock); again: - rc = cifs_wait_for_server_reconnect(server, tcon->retry); + rc = cifs_wait_for_server_reconnect(server, tcon, aborts, nowait); if (rc) return rc; @@ -346,7 +355,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, case CifsNeedReconnect: spin_unlock(&server->srv_lock); mutex_unlock(&ses->session_mutex); - if (!tcon->retry) + if (nowait) + return -EAGAIN; + if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; default: @@ -377,7 +388,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, rc = cifs_negotiate_protocol(0, ses, server); if (rc) { mutex_unlock(&ses->session_mutex); - if (!tcon->retry) + if (nowait) + return -EAGAIN; + if (!cifs_tcon_retry(tcon, aborts)) return -EHOSTDOWN; goto again; } @@ -470,6 +483,20 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, * treat this as server not supporting multichannel */ + /* + * If server is a secondary channel, + * cifs_chan_skip_or_disable() called below may + * drop its last reference, so hold our own + * reference until the reconnect work below has + * been queued. + */ + spin_lock(&cifs_tcp_ses_lock); + if (server->srv_count) { + server->srv_count++; + hold_server_ref = true; + } + spin_unlock(&cifs_tcp_ses_lock); + rc = smb3_update_ses_channels(ses, server, from_reconnect, true /* disable_mchan */); @@ -498,6 +525,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, if (smb2_command != SMB2_INTERNAL_CMD) cifs_queue_server_reconn(server); + if (hold_server_ref) + cifs_put_tcp_session(server, from_reconnect); atomic_inc(&tconInfoReconnectCount); out: @@ -589,7 +618,22 @@ static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, { int rc; - rc = smb2_reconnect(smb2_command, tcon, server, false); + rc = smb2_reconnect(smb2_command, tcon, server, false, false); + if (rc) + return rc; + + return __smb2_plain_req_init(smb2_command, tcon, server, request_buf, + total_len); +} + +/* As smb2_plain_req_init(), but fail fast instead of waiting for reconnect. */ +static int smb2_io_req_init(__le16 smb2_command, struct cifs_tcon *tcon, + struct TCP_Server_Info *server, + void **request_buf, unsigned int *total_len) +{ + int rc; + + rc = smb2_reconnect(smb2_command, tcon, server, false, true); if (rc) return rc; @@ -3144,8 +3188,12 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, __le16 *copy_path; int rc; - rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, - (void **) &req, &total_len); + if (oparms->no_reconnect_wait) + rc = smb2_io_req_init(SMB2_CREATE, tcon, server, + (void **) &req, &total_len); + else + rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, + (void **) &req, &total_len); if (rc) return rc; @@ -3329,14 +3377,25 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, int flags = 0; int retries = 0, cur_sleep = 0; struct smb2_file_all_info *file_info = buf ? &buf->fi : NULL; + bool reconnect = oparms->reconnect; + bool replay = oparms->replay; + bool unanswered = replay; + bool answered; + bool sent; replay_again: /* reinitialize for possible replay */ + answered = false; + sent = false; resp_buftype = CIFS_NO_BUFFER; memset(&rsp_iov, 0, sizeof(rsp_iov)); flags = 0; server = cifs_pick_channel(ses); - oparms->replay = !!(retries); + /* reissue the same create: a durable reconnect clears ->reconnect */ + oparms->reconnect = reconnect; + /* with no_replay the caller owns oparms->replay */ + if (!oparms->no_replay) + oparms->replay = unanswered; cifs_dbg(FYI, "create/open\n"); if (!ses || !server) @@ -3344,6 +3403,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, if (smb3_encryption_required(tcon)) flags |= CIFS_TRANSFORM_REQ; + if (oparms->no_reconnect_wait) + flags |= CIFS_NO_RECONNECT_WAIT; memset(&rqst, 0, sizeof(struct smb_rqst)); memset(&iov, 0, sizeof(iov)); @@ -3354,21 +3415,22 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, &rqst, oplock, oparms, path); if (rc) goto creat_exit; + sent = true; trace_smb3_open_enter(xid, tcon->tid, tcon->ses->Suid, oparms->path, oparms->create_options, oparms->desired_access); - if (retries) { - /* Back-off before retry */ - if (cur_sleep) - msleep(cur_sleep); + /* Back-off before retry */ + if (cur_sleep) + msleep(cur_sleep); + if (oparms->replay) smb2_set_replay(server, &rqst); - } rc = cifs_send_recv(xid, ses, server, &rqst, &resp_buftype, flags, &rsp_iov); rsp = (struct smb2_create_rsp *)rsp_iov.iov_base; + answered = rsp; if (rc != 0) { cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); @@ -3425,10 +3487,27 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, SMB2_open_free(&rqst); free_rsp_buf(resp_buftype, rsp); - if (is_replayable_error(rc) && - smb2_should_replay(tcon, &retries, &cur_sleep)) + if (sent) { + if (!rc || (answered && (!oparms->replay || + !is_replayable_error(rc)))) + unanswered = false; + else if (!answered && !is_interrupt_error(rc)) + unanswered = true; + oparms->pending = unanswered; + } + + if (!oparms->no_replay && is_replayable_error(rc) && + smb2_should_replay(tcon, &retries, &cur_sleep)) { + if (err_iov && answered && !rsp) { + free_rsp_buf(*buftype, err_iov->iov_base); + *err_iov = (struct kvec){}; + *buftype = CIFS_NO_BUFFER; + } goto replay_again; + } + if (!oparms->no_replay) + oparms->replay = replay; return rc; } @@ -3439,11 +3518,12 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, char *in_data, u32 indatalen, __u32 max_response_size) { - struct smb2_ioctl_req *req; struct kvec *iov = rqst->rq_iov; + struct smb2_ioctl_req *req; + u32 in_buf_len = indatalen; unsigned int total_len; - int rc; char *in_data_buf; + int rc; rc = smb2_ioctl_req_init(opcode, tcon, server, (void **) &req, &total_len); @@ -3451,15 +3531,18 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, return rc; if (indatalen) { + if (smb3_encryption_required(tcon)) + in_buf_len = ALIGN(indatalen, 8); /* * indatalen is usually small at a couple of bytes max, so * just allocate through generic pool */ - in_data_buf = kmemdup(in_data, indatalen, GFP_NOFS); + in_data_buf = kzalloc(in_buf_len, GFP_NOFS); if (!in_data_buf) { cifs_small_buf_release(req); return -ENOMEM; } + memcpy(in_data_buf, in_data, indatalen); } req->CtlCode = cpu_to_le32(opcode); @@ -3483,7 +3566,7 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, rqst->rq_nvec = 2; iov[0].iov_len = total_len - 1; iov[1].iov_base = in_data_buf; - iov[1].iov_len = indatalen; + iov[1].iov_len = in_buf_len; } else { rqst->rq_nvec = 1; iov[0].iov_len = total_len; @@ -4023,6 +4106,14 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, ses->Suid, info_class, (__u32)info_type); if (dlen) { + rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), + le32_to_cpu(rsp->OutputBufferLength), + &rsp_iov, min_len); + if (rc) { + *dlen = 0; + goto qinf_exit; + } + *dlen = le32_to_cpu(rsp->OutputBufferLength); if (!*data) { *data = kmalloc(*dlen, GFP_KERNEL); @@ -4077,7 +4168,8 @@ SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon, return query_info(xid, tcon, persistent_fid, volatile_fid, 0, SMB2_O_INFO_SECURITY, extra_info, - SMB2_MAX_BUFFER_SIZE, MIN_SEC_DESC_LEN, data, plen); + SMB2_MAX_BUFFER_SIZE, sizeof(struct smb_ntsd), + data, plen); } int @@ -4354,10 +4446,12 @@ void smb2_reconnect_server(struct work_struct *work) spin_unlock(&cifs_tcp_ses_lock); list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { - rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); + rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true, + true); if (!rc) { cifs_renegotiate_iosize(server, tcon); - cifs_reopen_persistent_handles(tcon); + if (cifs_reopen_persistent_handles(tcon)) + resched = true; } else resched = true; list_del_init(&tcon->rlist); @@ -4386,7 +4480,8 @@ void smb2_reconnect_server(struct work_struct *work) /* now reconnect sessions for necessary channels */ list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) { tcon->ses = ses; - rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); + rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true, + true); if (rc) resched = true; list_del_init(&ses->rlist); @@ -4695,6 +4790,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) struct smb_rqst rqst = { .rq_iov = &rdata->iov[0], .rq_nvec = 1 }; unsigned int rreq_debug_id = rdata->rreq->debug_id; unsigned int subreq_debug_index = rdata->subreq.debug_index; + bool cut_short = false; if (rdata->got_bytes) { rqst.rq_iter = rdata->subreq.io_iter; @@ -4743,6 +4839,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed); do_retry: __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); + cut_short = true; rdata->result = -EAGAIN; if (server->sign && rdata->got_bytes) /* reset bytes number since we can not check a sign */ @@ -4815,9 +4912,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) /* see if we need to retry */ if (is_replayable_error(rdata->result) && - smb2_should_replay(tcon, - &rdata->retries, - &rdata->cur_sleep)) + (cut_short || cifs_io_should_replay(rdata))) rdata->replay = true; trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, @@ -4880,12 +4975,8 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) shdr = (struct smb2_hdr *)buf; - if (rdata->replay) { - /* Back-off before retry */ - if (rdata->cur_sleep) - msleep(rdata->cur_sleep); + if (rdata->replay) smb2_set_replay(server, &rqst); - } if (rdata->credits.value > 0) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(io_parms.length, @@ -4926,9 +5017,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) out: /* if the send error is retryable, let netfs know about it */ if (is_replayable_error(rc) && - smb2_should_replay(tcon, - &rdata->retries, - &rdata->cur_sleep)) { + cifs_io_should_replay(rdata)) { rdata->replay = true; trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed); __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); @@ -5060,6 +5149,7 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) }; unsigned int rreq_debug_id = wdata->rreq->debug_id; unsigned int subreq_debug_index = wdata->subreq.debug_index; + bool cut_short = false; ssize_t result = 0; size_t written = 0; @@ -5073,10 +5163,7 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) credits.instance = server->reconnect_instance; result = smb2_check_receive(mid, server, 0); if (result != 0) { - if (is_replayable_error(result)) { - trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); - __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); - } else { + if (!is_replayable_error(result)) { wdata->subreq.error = result; trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_bad); } @@ -5105,12 +5192,9 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) break; case MID_REQUEST_SUBMITTED: trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted); - __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); - result = -EAGAIN; - break; + fallthrough; case MID_RETRY_NEEDED: - trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); - __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + cut_short = true; result = -EAGAIN; break; case MID_RESPONSE_MALFORMED: @@ -5164,11 +5248,17 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid) wdata->credits.value = 0; /* see if we need to retry */ - if (is_replayable_error(wdata->result) && - smb2_should_replay(tcon, - &wdata->retries, - &wdata->cur_sleep)) + if (is_replayable_error(result) && + ((cut_short && wdata->rreq->origin != NETFS_WRITEBACK && + !cifs_io_stopped(wdata)) || + cifs_io_should_replay(wdata))) { wdata->replay = true; + trace_netfs_sreq(&wdata->subreq, + netfs_sreq_trace_io_retry_needed); + __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); + } else if (cut_short && cifs_io_stopped(wdata)) { + result = -EIO; + } cifs_write_subrequest_terminated(wdata, result ?: written); release_mid(server, mid); @@ -5209,8 +5299,14 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) }; io_parms = &_io_parms; - rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, - (void **) &req, &total_len); + if (wdata->subreq.rreq->origin == NETFS_WRITEBACK) { + flags |= CIFS_NO_RECONNECT_WAIT; + rc = smb2_io_req_init(SMB2_WRITE, tcon, server, + (void **) &req, &total_len); + } else { + rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, + (void **) &req, &total_len); + } if (rc) goto out; @@ -5286,12 +5382,8 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) } #endif - if (wdata->replay) { - /* Back-off before retry */ - if (wdata->cur_sleep) - msleep(wdata->cur_sleep); + if (wdata->replay) smb2_set_replay(server, &rqst); - } cifs_dbg(FYI, "async write at %llu %u bytes iter=%zx\n", io_parms->offset, io_parms->length, iov_iter_count(&wdata->subreq.io_iter)); @@ -5339,9 +5431,7 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) out: /* if the send error is retryable, let netfs know about it */ if (is_replayable_error(rc) && - smb2_should_replay(tcon, - &wdata->retries, - &wdata->cur_sleep)) { + cifs_io_should_replay(wdata)) { wdata->replay = true; trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags); diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index c79e5cb2ce26ad..b2acff8938f32a 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -121,6 +121,15 @@ unsigned long smb_rqst_len(struct TCP_Server_Info *server, void smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst); void smb2_set_related(struct smb_rqst *rqst); void smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst); + +static inline void smb2_replay_backoff(int *pcur_sleep) +{ + if (!*pcur_sleep) + *pcur_sleep = 1; + else + *pcur_sleep = min(*pcur_sleep << 1, CIFS_MAX_SLEEP); +} + bool smb2_should_replay(struct cifs_tcon *tcon, int *pretries, int *pcur_sleep); diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c index d0d0159c1061b3..c51f99d7be4b31 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -430,6 +430,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, const int timeout, const int flags, unsigned int *instance) { + bool nowait = flags & CIFS_NO_RECONNECT_WAIT; long rc; int *credits; int optype; @@ -478,6 +479,10 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, spin_unlock(&server->srv_lock); return -ENOENT; } + if (nowait && server->tcpStatus == CifsNeedReconnect) { + spin_unlock(&server->srv_lock); + return -EAGAIN; + } spin_unlock(&server->srv_lock); spin_lock(&server->req_lock); @@ -487,7 +492,8 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, cifs_num_waiters_inc(server); rc = wait_event_killable_timeout(server->request_q, - has_credits(server, credits, num_credits), t); + credits_or_conn_down(server, credits, + num_credits, nowait), t); cifs_num_waiters_dec(server); if (!rc) { spin_lock(&server->req_lock); @@ -527,8 +533,9 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, cifs_num_waiters_inc(server); rc = wait_event_killable_timeout( server->request_q, - has_credits(server, credits, - MAX_COMPOUND + 1), + credits_or_conn_down(server, credits, + MAX_COMPOUND + 1, + nowait), t); cifs_num_waiters_dec(server); if (!rc) { @@ -595,6 +602,10 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num, credits = server->ops->get_credits_field(server, flags & CIFS_OP_MASK); + if ((flags & CIFS_NO_RECONNECT_WAIT) && + READ_ONCE(server->tcpStatus) == CifsNeedReconnect) + return -EAGAIN; + spin_lock(&server->req_lock); scredits = *credits; in_flight = server->in_flight; @@ -618,6 +629,9 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num, */ if (server->in_flight == 0) { spin_unlock(&server->req_lock); + if ((flags & CIFS_NO_RECONNECT_WAIT) && + READ_ONCE(server->tcpStatus) == CifsNeedReconnect) + return -EAGAIN; trace_smb3_insufficient_credits(server->current_mid, server->conn_id, server->hostname, scredits, num, in_flight); @@ -634,7 +648,7 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num, int cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size, - size_t *num, struct cifs_credits *credits) + size_t *num, struct cifs_credits *credits, bool nowait) { *num = size; credits->value = 0; diff --git a/fs/smb/common/compress/lz77.c b/fs/smb/common/compress/lz77.c index 9216d973d8769d..c915b114a05a18 100644 --- a/fs/smb/common/compress/lz77.c +++ b/fs/smb/common/compress/lz77.c @@ -240,7 +240,7 @@ noinline int smb_lz77_compress(const void *src, const u32 slen, dstp += sizeof(u32); nib = NULL; - htable = kvcalloc(LZ77_HASH_SIZE, sizeof(*htable), GFP_KERNEL); + htable = kvzalloc_objs(*htable, LZ77_HASH_SIZE); if (!htable) return -ENOMEM; diff --git a/fs/smb/server/mgmt/user_config.h b/fs/smb/server/mgmt/user_config.h index cc460b4ff7d393..e116b2ee99179e 100644 --- a/fs/smb/server/mgmt/user_config.h +++ b/fs/smb/server/mgmt/user_config.h @@ -67,4 +67,9 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, void ksmbd_free_user(struct ksmbd_user *user); bool ksmbd_anonymous_user(struct ksmbd_user *user); bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2); + +static inline bool ksmbd_user_authenticated(struct ksmbd_user *user) +{ + return user && !user_guest(user) && !ksmbd_anonymous_user(user); +} #endif /* __USER_CONFIG_MANAGEMENT_H__ */ diff --git a/fs/smb/server/mgmt/user_session.c b/fs/smb/server/mgmt/user_session.c index 3f75049be8785c..15662fd745abb9 100644 --- a/fs/smb/server/mgmt/user_session.c +++ b/fs/smb/server/mgmt/user_session.c @@ -85,6 +85,8 @@ static const char *session_state_string(struct ksmbd_session *session) static const char *session_user_name(struct ksmbd_session *session) { + if (!session->user) + return "(Unauthenticated)"; if (user_guest(session->user)) return "(Guest)"; else if (ksmbd_anonymous_user(session->user)) @@ -94,6 +96,8 @@ static const char *session_user_name(struct ksmbd_session *session) static const char *session_account_type(struct ksmbd_session *session) { + if (!session->user) + return "unauthenticated"; if (user_guest(session->user)) return "guest"; if (ksmbd_anonymous_user(session->user)) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index be226664b8afc8..fe17d406123746 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -2365,6 +2365,17 @@ static int ntlm_authenticate(struct ksmbd_work *work, return -EKEYREJECTED; } ksmbd_free_user(user); + } else if (sess->user) { + /* + * Reauthentication of an expired session: as for a valid + * session, and as krb5_authenticate() does, it must be by the + * same user. Replacing sess->user would also leak the old one. + */ + if (!ksmbd_compare_user(sess->user, user)) { + ksmbd_free_user(user); + return -EKEYREJECTED; + } + ksmbd_free_user(user); } else { sess->user = user; } @@ -3454,6 +3465,11 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, if (!eabuf->EaNameLength) goto next; + if (eabuf->name[eabuf->EaNameLength]) { + rc = -EBADMSG; + break; + } + ksmbd_debug(SMB, "name : <%s>, name_len : %u, value_len : %u, next : %u\n", eabuf->name, eabuf->EaNameLength, @@ -3536,7 +3552,8 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, static noinline int smb2_set_stream_name_xattr(const struct path *path, struct ksmbd_file *fp, - char *stream_name, int s_type) + char *stream_name, int s_type, + bool *created) { const struct mnt_idmap *idmap = mnt_idmap(path->mnt); size_t xattr_stream_size; @@ -3566,7 +3583,8 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, if (fp->cdoption == FILE_OPEN_LE) { if (!strcmp(stream_name, "AFP_AfpInfo") && test_share_config_flag(fp->tcon->share_conf, - KSMBD_SHARE_FLAG_TIME_MACHINE)) { + KSMBD_SHARE_FLAG_TIME_MACHINE) && + test_tree_conn_flag(fp->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { /* * Synthesize an empty AFP_AfpInfo xattr on first access. * type=0/creator=0 tells macOS to use the file extension @@ -3593,9 +3611,14 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, return -EBADF; } + if (!test_tree_conn_flag(fp->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) + return -EACCES; + rc = ksmbd_vfs_setxattr(idmap, path, xattr_stream_name, NULL, 0, 0, false); if (rc < 0) pr_err("Failed to store XATTR stream name :%d\n", rc); + else + *created = true; return 0; } @@ -4326,7 +4349,8 @@ static int smb2_handle_app_instance_id(struct ksmbd_work *work, /* Authorize the referenced open even if its name changes meanwhile. */ old_path = &old_fp->filp->f_path; rc = smb_check_perm_dacl(conn, old_path, &maximal_access, 0, - work->sess->user->uid, false); + work->sess->user->uid, + ksmbd_user_authenticated(work->sess->user), false); if (rc) { /* Access denial prevents takeover, not the CREATE itself. */ ksmbd_put_durable_fd(old_fp); @@ -4385,6 +4409,7 @@ int smb2_open(struct ksmbd_work *work) char *stream_name = NULL; bool file_present = false, created = false, already_permitted = false; bool app_instance_id_checked = false, app_instance_closed; + bool stream_created = false; int share_ret, need_truncate = 0; u64 time, alloc_size = 0; umode_t posix_mode = 0; @@ -4526,7 +4551,7 @@ int smb2_open(struct ksmbd_work *work) file_info = FILE_OPENED; rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat); if (rc) - goto err_out2; + goto err_out1; goto reconnected_fp; } @@ -4556,7 +4581,7 @@ int smb2_open(struct ksmbd_work *work) rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat); if (rc) - goto err_out2; + goto err_out1; goto reconnected_fp; } @@ -4606,6 +4631,14 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } } + + /* MS-FSA 2.1.5.1: delete-on-close requires DELETE access */ + if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && + !(smb_map_generic_desired_access(req->DesiredAccess) & + FILE_DELETE_LE)) { + rc = -EINVAL; + goto err_out2; + } } if (le32_to_cpu(req->CreateDisposition) > @@ -4839,14 +4872,17 @@ int smb2_open(struct ksmbd_work *work) if (file_present && !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) { rc = smb_check_perm_dacl(conn, &path, &daccess, req->DesiredAccess, - sess->user->uid, false); + sess->user->uid, + ksmbd_user_authenticated(sess->user), false); if (rc) goto err_out; if (maximal_access_ctxt) { maximal_access = FILE_MAXIMAL_ACCESS_LE; rc = smb_check_perm_dacl(conn, &path, &maximal_access, - 0, sess->user->uid, false); + 0, sess->user->uid, + ksmbd_user_authenticated(sess->user), + false); if (rc) goto err_out; @@ -4875,6 +4911,13 @@ int smb2_open(struct ksmbd_work *work) maximal_access = daccess; } + /* MAXIMUM_ALLOWED may not have granted the requested DELETE */ + if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && + !(daccess & FILE_DELETE_LE)) { + rc = -EACCES; + goto err_out; + } + open_flags = smb2_create_open_flags(file_present, daccess, req->CreateDisposition, &may_flags, @@ -4937,16 +4980,32 @@ int smb2_open(struct ksmbd_work *work) if ((daccess & FILE_DELETE_LE) || (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) { - rc = inode_permission(idmap, - d_inode(path.dentry->d_parent), - MAY_EXEC | MAY_WRITE); + struct dentry *parent = dget_parent(path.dentry); + struct inode *parent_inode = d_inode(parent); + + if (parent_inode) + rc = inode_permission(idmap, parent_inode, + MAY_EXEC | MAY_WRITE); + else + rc = -ENOENT; + dput(parent); if (rc) goto err_out; } } } - rc = ksmbd_query_inode_status(path.dentry->d_parent); + { + struct dentry *parent = dget_parent(path.dentry); + + if (!d_inode(parent)) { + dput(parent); + rc = -ENOENT; + goto err_out; + } + rc = ksmbd_query_inode_status(parent); + dput(parent); + } if (rc == KSMBD_INODE_STATUS_PENDING_DELETE) { rc = -EBUSY; goto err_out; @@ -5029,10 +5088,17 @@ int smb2_open(struct ksmbd_work *work) if (created) { int posix_acl_rc; struct inode *inode = d_inode(path.dentry); - - posix_acl_rc = ksmbd_vfs_inherit_posix_acl(idmap, - &path, - d_inode(path.dentry->d_parent)); + struct inode *parent_inode; + struct dentry *parent; + + parent = dget_parent(path.dentry); + parent_inode = d_inode(parent); + if (parent_inode) + posix_acl_rc = ksmbd_vfs_inherit_posix_acl(idmap, &path, + parent_inode); + else + posix_acl_rc = -ENOENT; + dput(parent); if (posix_acl_rc) ksmbd_debug(SMB, "inherit posix acl failed : %d\n", posix_acl_rc); @@ -5114,7 +5180,8 @@ int smb2_open(struct ksmbd_work *work) rc = smb2_set_stream_name_xattr(&path, fp, stream_name, - s_type); + s_type, + &stream_created); if (rc) goto err_out; file_info = FILE_CREATED; @@ -5122,13 +5189,25 @@ int smb2_open(struct ksmbd_work *work) fp->attrib_only = !(req->DesiredAccess & ~(FILE_READ_ATTRIBUTES_LE | FILE_WRITE_ATTRIBUTES_LE | FILE_SYNCHRONIZE_LE)); + need_truncate = !S_ISDIR(file_inode(filp)->i_mode) && + open_flags & O_TRUNC && !fp->attrib_only && !stream_name; + /* + * Count the FILE_WRITE_DATA that MS-FSA 2.1.5.1.2 grants an overwrite, + * supersede included, or a new named stream on an existing file. + * An attribute-only open of the file is not truncated, and the + * synthesized AFP_AfpInfo stream is not created by the client. + */ + fp->implied_write = need_truncate || + (stream_name && + (open_flags & O_TRUNC || + (file_present && stream_created))); fp->is_posix_ctxt = posix_ctxt; fp->posix_append = posix_ctxt && !!(open_flags & O_APPEND); /* fp should be searchable through ksmbd_inode.m_fp_list - * after daccess, saccess, attrib_only, and stream are - * initialized. + * after daccess, saccess, attrib_only, implied_write, and + * stream are initialized. */ down_write(&fp->f_ci->m_lock); list_add(&fp->node, &fp->f_ci->m_fp_list); @@ -5149,11 +5228,8 @@ int smb2_open(struct ksmbd_work *work) if (file_present || created) path_put(&path); - if (!S_ISDIR(file_inode(filp)->i_mode) && open_flags & O_TRUNC && - !fp->attrib_only && !stream_name) { + if (need_truncate) smb_break_all_oplock(work, fp); - need_truncate = 1; - } share_ret = ksmbd_smb_check_shared_mode(fp->filp, fp); if (!test_share_config_flag(work->tcon->share_conf, KSMBD_SHARE_FLAG_OPLOCKS) || @@ -5606,6 +5682,8 @@ int smb2_open(struct ksmbd_work *work) if (rc) { if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EOPNOTSUPP) rsp->hdr.Status = STATUS_NOT_SUPPORTED; else if ((rc == -EACCES || rc == -ESTALE || rc == -EXDEV) && @@ -6307,6 +6385,7 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv) rc = smb_check_perm_dacl(priv->work->conn, &path, &daccess, daccess, priv->work->sess->user->uid, + ksmbd_user_authenticated(priv->work->sess->user), true); if (rc) { dput(dent); @@ -7394,8 +7473,7 @@ static int smb2_add_stream_info(struct smb2_stream_info_buffer *buf, buf->capacity - offset < sizeof(*file_info)) return -ENOSPC; - utf16_name = kmalloc_array(name_len + 1, sizeof(*utf16_name), - KSMBD_DEFAULT_GFP); + utf16_name = kmalloc_objs(*utf16_name, name_len + 1, KSMBD_DEFAULT_GFP); if (!utf16_name) return -ENOMEM; @@ -7718,8 +7796,8 @@ static int find_file_posix_info(struct ksmbd_work *work, if (filename[0] == '\\') memmove(filename, filename + 1, strlen(filename)); name_bytes = strlen(filename); - utf16_name = kmalloc_array(name_bytes + 1, sizeof(*utf16_name), - KSMBD_DEFAULT_GFP); + utf16_name = kmalloc_objs(*utf16_name, name_bytes + 1, + KSMBD_DEFAULT_GFP); if (!utf16_name) { kfree(filename); return -ENOMEM; @@ -9304,6 +9382,8 @@ int smb2_set_info(struct ksmbd_work *work) } else if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EMSGSIZE) rsp->hdr.Status = STATUS_INFO_LENGTH_MISMATCH; else if (rc == -ENOSPC || rc == -EFBIG) diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c index f9fb3741ada322..e7a987af64ba56 100644 --- a/fs/smb/server/smb_common.c +++ b/fs/smb/server/smb_common.c @@ -695,10 +695,24 @@ static void smb_shared_mode_error(int error, struct ksmbd_file *prev_fp, prev_fp->saccess, curr_fp->daccess); } +/* + * Sharing checks use fp->daccess plus the FILE_WRITE_DATA that MS-FSA + * grants an open that overwrites data or creates a named stream. + * fp->daccess keeps the open's own access. + */ +__le32 ksmbd_sharing_daccess(const struct ksmbd_file *fp) +{ + if (fp->implied_write) + return fp->daccess | FILE_WRITE_DATA_LE; + return fp->daccess; +} + int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp) { int rc = 0; struct ksmbd_file *prev_fp; + __le32 curr_access = ksmbd_sharing_daccess(curr_fp); + __le32 access; /* * Lookup fp in master fp list, and check desired access and @@ -719,6 +733,24 @@ int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp) if (prev_fp->attrib_only != curr_fp->attrib_only) continue; + /* + * MS-FSA checks sharing per stream, so a named stream open's + * implied write is not a write against the primary stream. + * It still decides whether the pair is checked. + */ + access = curr_access; + if (ksmbd_stream_fd(curr_fp) && !ksmbd_stream_fd(prev_fp)) + access = curr_fp->daccess; + + /* + * Two opens conflict only if both hold a right in + * FILE_SHARE_CHECKED_ACCESS_LE (MS-FSA 2.1.5.1.2.1 and + * 2.1.5.1.2.2) + */ + if (!(ksmbd_sharing_daccess(prev_fp) & FILE_SHARE_CHECKED_ACCESS_LE) || + !(curr_access & FILE_SHARE_CHECKED_ACCESS_LE)) + continue; + if (!(prev_fp->saccess & FILE_SHARE_DELETE_LE) && curr_fp->daccess & FILE_DELETE_LE) { smb_shared_mode_error(SHARE_DELETE_ERROR, @@ -745,7 +777,7 @@ int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp) } if (!(prev_fp->saccess & FILE_SHARE_WRITE_LE) && - curr_fp->daccess & (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE)) { + access & (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE)) { smb_shared_mode_error(SHARE_WRITE_ERROR, prev_fp, curr_fp); diff --git a/fs/smb/server/smb_common.h b/fs/smb/server/smb_common.h index a9cc09e3172121..d3d19f1a23ea62 100644 --- a/fs/smb/server/smb_common.h +++ b/fs/smb/server/smb_common.h @@ -69,6 +69,10 @@ FILE_EXECUTE | FILE_DELETE_CHILD | \ FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES) +/* Rights that make an open take part in sharing checks */ +#define FILE_SHARE_CHECKED_ACCESS_LE (FILE_EXECUTE_LE | FILE_READ_DATA_LE | \ + FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE | FILE_DELETE_LE) + #define SMB_COM_NEGOTIATE 0x72 /* See MS-CIFS 2.2.2.1 */ /* See MS-CIFS 2.2.3.1 */ @@ -284,6 +288,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command); +__le32 ksmbd_sharing_daccess(const struct ksmbd_file *fp); int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp); int __ksmbd_override_fsids(struct ksmbd_work *work, struct ksmbd_share_config *share); diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c index 664f0126361168..6b5f22d6280c15 100644 --- a/fs/smb/server/smbacl.c +++ b/fs/smb/server/smbacl.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1207,7 +1208,7 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, struct smb_acl *parent_pdacl; struct smb_ntsd *parent_pntsd = NULL; struct smb_sid owner_sid, group_sid; - struct dentry *parent = path->dentry->d_parent; + struct dentry *parent; const struct mnt_idmap *idmap = mnt_idmap(path->mnt); int inherited_flags = 0, flags = 0, i, nt_size = 0, pdacl_size; int rc = 0, pntsd_type, ppntsd_size, acl_len, aces_size; @@ -1217,8 +1218,14 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, char *aces_base; bool is_dir = S_ISDIR(d_inode(path->dentry)->i_mode); + parent = dget_parent(path->dentry); + if (!d_inode(parent)) { + dput(parent); + return -ENOENT; + } ppntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap, parent, &parent_pntsd); + dput(parent); if (ppntsd_size <= 0) return -ENOENT; @@ -1459,9 +1466,49 @@ bool smb_inherit_flags(int flags, bool is_dir) return false; } +/* Whether the caller's credentials hold the group of an S-1-22-2- SID */ +static bool smb_sid_in_group(const struct smb_sid *sid) +{ + gid_t gid; + + if (sid->num_subauth != sid_unix_groups.num_subauth + 1 || + compare_sids(sid, &sid_unix_groups)) + return false; + gid = le32_to_cpu(sid->sub_auth[sid->num_subauth - 1]); + /* + * ksmbd_override_fsids() builds the caller's credentials with + * make_kgid(&init_user_ns, ...), so the group membership test must + * compare in that space. Applying the mount idmap here (as when + * resolving a SID to an on-disk gid) would mismatch on idmapped + * mounts. + */ + return in_group_p(make_kgid(&init_user_ns, gid)); +} + +/* Whether two SIDs are the same SID */ +static bool smb_sid_equal(const struct smb_sid *a, const struct smb_sid *b) +{ + return a->num_subauth == b->num_subauth && !compare_sids(a, b); +} + +/* + * compare_sids() compares only the sub-authorities both SIDs have, so it + * also matches a shorter or longer SID, such as S-1-3 or S-1-3-4-777 + */ +static bool smb_sid_is_owner_rights(const struct smb_sid *sid) +{ + return sid->num_subauth == sid_owner_rights.num_subauth && + !compare_sids(sid, &sid_owner_rights); +} + +static unsigned int smb_parent_derived_rights(struct ksmbd_conn *conn, + const struct path *path, int uid, + bool authenticated, + unsigned int want); + int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, __le32 *pdaccess, __le32 raw_daccess, int uid, - bool strict) + bool authenticated, bool strict) { const struct mnt_idmap *idmap = mnt_idmap(path->mnt); struct smb_ntsd *pntsd = NULL; @@ -1475,12 +1522,23 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, int granted = requested; struct smb_ace *ace; int i, found = 0; - unsigned int access_bits = 0, denied = 0; + unsigned int access_bits = 0, denied = 0, grp_granted = 0; + unsigned int grp_allowed = 0, grp_denied = 0, bits; struct smb_ace *others_ace = NULL; + bool or_ace = false, obj_deny = false, au_ace = false, member, counted; + bool grp_ace = false; struct posix_acl_entry *pa_entry; unsigned int sid_type = SIDOWNER; unsigned short ace_size; bool is_owner, owner_rights = false; + bool maximal = *pdaccess & FILE_MAXIMAL_ACCESS_LE; + /* + * MAXIMUM_ALLOWED requests that are not strict match every session + * against Authenticated Users and do not count ACEs for the + * caller's groups. Strict ones match SIDs as explicit requests do. + */ + bool open_max = maximal && !strict; + bool authusers = authenticated || open_max; vfsuid_t vfsuid; ksmbd_debug(SMB, "check permission using windows acl\n"); @@ -1509,76 +1567,140 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, is_owner = uid == from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid)); if (!pdacl->num_aces) { + unsigned int allowed = 0; + /* * An empty (present, zero-ACE) DACL grants no access to * anyone except the object owner's implicit READ_CONTROL - * and WRITE_DAC (MS-DTYP 2.4.5). Deny every other caller, - * deny the owner any access beyond those two bits, and do - * not let trailing bytes after a zero-ACE DACL become an - * implicit grant. + * and WRITE_DAC (MS-DTYP 2.5.3.2), besides what the parent + * grants. Deny every other right, and do not let trailing + * bytes after a zero-ACE DACL become an implicit grant. */ - if (!is_owner || - (*pdaccess & ~(FILE_READ_CONTROL_LE | FILE_WRITE_DAC_LE))) + if (is_owner) + allowed = READ_CONTROL | WRITE_DAC; + if (!strict) + allowed |= smb_parent_derived_rights(conn, path, uid, + authenticated, + requested & ~allowed); + if (maximal) + requested |= allowed; + if (!allowed || requested & ~allowed) rc = -EACCES; + else + *pdaccess = cpu_to_le32(requested); goto err_out; } - if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) { - ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl)); - aces_size = pdacl_size - sizeof(struct smb_acl); - for (i = 0; i < le16_to_cpu(pdacl->num_aces); i++) { - if (aces_size < offsetof(struct smb_ace, sid) + - CIFS_SID_BASE_SIZE) - break; - ace_size = le16_to_cpu(ace->size); - if (ace_size > aces_size || - ace_size < offsetof(struct smb_ace, sid) + - CIFS_SID_BASE_SIZE) - break; - aces_size -= ace_size; + /* + * Evaluate the DACL in order (MS-DTYP 2.5.3.2). access_bits collects + * the result for the ACEs that apply to the caller, without its groups + * for a MAXIMUM_ALLOWED request that is not strict. grp_granted + * collects what ACEs for the caller's groups, or OWNER RIGHTS for the + * owner, grant. It is used when the SID lookup and POSIX ACL fallback + * below do not decide. + */ + ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl)); + aces_size = pdacl_size - sizeof(struct smb_acl); + for (i = 0; i < le16_to_cpu(pdacl->num_aces); i++) { + if (aces_size < offsetof(struct smb_ace, sid) + + CIFS_SID_BASE_SIZE) + break; + ace_size = le16_to_cpu(ace->size); + if (ace_size > aces_size || + ace_size < offsetof(struct smb_ace, sid) + + CIFS_SID_BASE_SIZE) + break; + aces_size -= ace_size; - if (ace->sid.num_subauth > SID_MAX_SUB_AUTHORITIES || - ace_size < offsetof(struct smb_ace, sid) + - CIFS_SID_BASE_SIZE + - sizeof(__le32) * ace->sid.num_subauth) - break; + if (ace->sid.num_subauth > SID_MAX_SUB_AUTHORITIES || + ace_size < offsetof(struct smb_ace, sid) + + CIFS_SID_BASE_SIZE + + sizeof(__le32) * ace->sid.num_subauth) + break; - if (!compare_sids(&sid_owner_rights, &ace->sid)) { - owner_rights = true; - if (!is_owner) - goto next_ace; - } + if ((ace->type == ACCESS_DENIED_OBJECT_ACE_TYPE || + ace->type == ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE) && + !(ace->flags & INHERIT_ONLY_ACE)) + obj_deny = true; - if (ace->flags & INHERIT_ONLY_ACE || - (compare_sids(&sid, &ace->sid) && - compare_sids(&sid_unix_NFS_mode, &ace->sid) && - compare_sids(&sid_everyone, &ace->sid) && - compare_sids(&sid_authusers, &ace->sid) && - compare_sids(&sid_owner_rights, &ace->sid))) + if (!compare_sids(&sid_owner_rights, &ace->sid)) { + owner_rights = true; + if (!is_owner) goto next_ace; + } - switch (ace->type) { - case ACCESS_ALLOWED_ACE_TYPE: - access_bits |= le32_to_cpu(ace->access_req); - break; - case ACCESS_DENIED_ACE_TYPE: - case ACCESS_DENIED_CALLBACK_ACE_TYPE: - denied |= ~access_bits & - le32_to_cpu(ace->access_req); + member = smb_sid_in_group(&ace->sid); + /* The grp_ masks count groups and OWNER RIGHTS only */ + counted = member || + (is_owner && smb_sid_is_owner_rights(&ace->sid)); + if (ace->flags & INHERIT_ONLY_ACE || + (compare_sids(&sid, &ace->sid) && + compare_sids(&sid_unix_NFS_mode, &ace->sid) && + compare_sids(&sid_everyone, &ace->sid) && + (!authusers || + compare_sids(&sid_authusers, &ace->sid)) && + compare_sids(&sid_owner_rights, &ace->sid) && + !member)) + goto next_ace; + /* Other requests count only SIDs that match exactly */ + if (!open_max && !member && + !smb_sid_equal(&sid, &ace->sid) && + !smb_sid_equal(&sid_everyone, &ace->sid) && + !(authusers && smb_sid_equal(&sid_authusers, &ace->sid)) && + !smb_sid_is_owner_rights(&ace->sid)) + goto next_ace; + + bits = le32_to_cpu(ace->access_req); + switch (ace->type) { + case ACCESS_ALLOWED_ACE_TYPE: + grp_ace |= counted; + if (counted) + grp_allowed |= bits; + /* An open's MAXIMUM_ALLOWED takes no group grants */ + if (open_max && member) break; - } -next_ace: - ace = (struct smb_ace *)((char *)ace + le16_to_cpu(ace->size)); + if (counted) + grp_granted |= bits; + access_bits |= bits; + break; + case ACCESS_DENIED_ACE_TYPE: + case ACCESS_DENIED_CALLBACK_ACE_TYPE: + grp_ace |= counted; + if (counted) + grp_denied |= ~grp_allowed & bits; + /* nor group denials */ + if (!(open_max && member)) + denied |= ~access_bits & bits; + break; } +next_ace: + ace = (struct smb_ace *)((char *)ace + le16_to_cpu(ace->size)); + } + + /* Keep only file rights, not MAXIMUM_ALLOWED or generic bits */ + grp_granted &= GENERIC_ALL_FLAGS & ~grp_denied; + if (maximal) { if (is_owner && !owner_rights) access_bits |= READ_CONTROL | WRITE_DAC | FILE_READ_ATTRIBUTES | DELETE; access_bits &= ~denied; + /* An object deny ACE could deny the parent's rights */ + if (!open_max && obj_deny) + access_bits = 0; if ((raw_daccess & FILE_GENERIC_EXECUTE_LE) && S_ISREG(d_inode(path->dentry)->i_mode) && (access_bits & GENERIC_READ_FLAGS) == GENERIC_READ_FLAGS) access_bits |= FILE_EXECUTE; granted = requested | access_bits; + } else if (!obj_deny) { + /* An explicit request takes the ordered result */ + access_bits &= ~denied; + } else { + /* + * ksmbd does not parse object deny ACEs, so with one present an + * explicit request keeps the answer of the ACE found below + */ + access_bits = 0; } ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl)); @@ -1604,16 +1726,30 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, found = 1; break; } + if (!compare_sids(&sid_owner_rights, &ace->sid) && + !(ace->flags & INHERIT_ONLY_ACE)) + or_ace = true; if (!compare_sids(&sid_everyone, &ace->sid) || - !compare_sids(&sid_authusers, &ace->sid)) + (authusers && + !compare_sids(&sid_authusers, &ace->sid))) others_ace = ace; + if (!compare_sids(&sid_authusers, &ace->sid)) + au_ace = true; ace = (struct smb_ace *)((char *)ace + le16_to_cpu(ace->size)); } if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) { posix_acls = get_inode_acl(d_inode(path->dentry), ACL_TYPE_ACCESS); - if (!IS_ERR_OR_NULL(posix_acls) && !found && !others_ace) { + /* + * An Authenticated Users ACE keeps the POSIX ACL from deciding, + * also for sessions that it does not match. For a strict + * MAXIMUM_ALLOWED request, ACEs for the caller's groups or + * OWNER RIGHTS decide before the POSIX ACL, unless the DACL has + * an object deny ACE, which ksmbd does not parse. + */ + if (!IS_ERR_OR_NULL(posix_acls) && !found && !others_ace && + !au_ace && !(strict && maximal && grp_ace && !obj_deny)) { unsigned int id = -1; pa_entry = posix_acls->a_entries; @@ -1625,13 +1761,25 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, else continue; - if (id == uid) { + /* A group entry grants only to the group's members */ + if (id == uid && + (pa_entry->e_tag == ACL_USER || + in_group_p(make_kgid(&init_user_ns, id)))) { mode_to_access_flags(pa_entry->e_perm, 0777, &access_bits); if (!access_bits) access_bits = SET_MINIMUM_RIGHTS; + /* + * Only ACEs for the caller's groups, + * or OWNER RIGHTS for the owner, apply + * here. The POSIX ACL entry does not + * grant an explicitly requested right + * that they deny first in DACL order. + */ + access_bits &= ~(grp_denied & + requested); posix_acl_release(posix_acls); goto check_access_bits; } @@ -1645,13 +1793,40 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, if (others_ace) { ace = others_ace; } else { - ksmbd_debug(SMB, "Can't find corresponding sid\n"); - rc = -EACCES; + unsigned int allowed = 0; + + /* + * No ACE names the owner, who may still read and + * change the DACL unless OWNER RIGHTS applies + * (MS-DTYP 2.5.3.2). + */ + if (is_owner && !or_ace) + allowed = READ_CONTROL | WRITE_DAC; + /* + * Add what ACEs for the caller's groups, or OWNER + * RIGHTS for the owner, grant in DACL order, unless an + * object deny ACE, which ksmbd does not parse, could + * apply. + */ + if (!obj_deny) + allowed |= grp_granted; + if (!strict) + allowed |= smb_parent_derived_rights(conn, path, uid, + authenticated, + requested & ~allowed); + if (maximal) + requested |= allowed; + if (!allowed || requested & ~allowed) { + ksmbd_debug(SMB, "Can't find corresponding sid\n"); + rc = -EACCES; + goto err_out; + } + *pdaccess = cpu_to_le32(requested); goto err_out; } } - if (!(*pdaccess & FILE_MAXIMAL_ACCESS_LE)) { + if (!maximal && obj_deny) { switch (ace->type) { case ACCESS_ALLOWED_ACE_TYPE: access_bits = le32_to_cpu(ace->access_req); @@ -1672,8 +1847,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, } if (granted & ~access_bits) { - ksmbd_debug(SMB, "Access denied with winACL, granted : %x, access_req : %x\n", - granted, le32_to_cpu(ace->access_req)); + ksmbd_debug(SMB, "Access denied with winACL, requested : %x, allowed : %x\n", + granted, access_bits); rc = -EACCES; goto err_out; } @@ -1685,6 +1860,45 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, } EXPORT_SYMBOL_IF_KUNIT(smb_check_perm_dacl); +/* + * Return the rights in @want that @path gets from its parent directory: + * DELETE if the parent's DACL grants FILE_DELETE_CHILD, and + * FILE_READ_ATTRIBUTES if it grants FILE_LIST_DIRECTORY + * (MS-FSA 2.1.5.1.2.1). A parent with no DACL, or with one that ksmbd + * cannot read, gives nothing. Callers pass only rights that the request + * names. + */ +static unsigned int smb_parent_derived_rights(struct ksmbd_conn *conn, + const struct path *path, int uid, + bool authenticated, + unsigned int want) +{ + struct path parent = { .mnt = path->mnt }; + __le32 granted = FILE_MAXIMAL_ACCESS_LE; + unsigned int rights = 0; + int rc; + + if (!(want & (DELETE | FILE_READ_ATTRIBUTES))) + return 0; + + /* The root of the mount, or a disconnected dentry, has no parent */ + if (path->dentry == path->mnt->mnt_root || IS_ROOT(path->dentry)) + return 0; + + parent.dentry = dget_parent(path->dentry); + /* Strict, so the parent's own parent is not consulted */ + rc = smb_check_perm_dacl(conn, &parent, &granted, 0, uid, + authenticated, true); + dput(parent.dentry); + if (rc || granted == FILE_MAXIMAL_ACCESS_LE) + return 0; + if (granted & FILE_DELETE_CHILD_LE) + rights |= DELETE; + if (granted & FILE_LIST_DIRECTORY_LE) + rights |= FILE_READ_ATTRIBUTES; + return rights & want; +} + int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, const struct path *path, struct smb_ntsd *pntsd, int ntsd_len, bool type_check, bool get_write, bool posix_open, diff --git a/fs/smb/server/smbacl.h b/fs/smb/server/smbacl.h index 3342cebab33331..bbd35948a37904 100644 --- a/fs/smb/server/smbacl.h +++ b/fs/smb/server/smbacl.h @@ -97,7 +97,7 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, const struct path *path, unsigned int uid, unsigned int gid); int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, __le32 *pdaccess, __le32 raw_daccess, int uid, - bool strict); + bool authenticated, bool strict); int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, const struct path *path, struct smb_ntsd *pntsd, int ntsd_len, bool type_check, bool get_write, bool posix_open, diff --git a/fs/smb/server/tests/smbacl_kunit.c b/fs/smb/server/tests/smbacl_kunit.c index 33496b4d31a3ec..bf28439a76967e 100644 --- a/fs/smb/server/tests/smbacl_kunit.c +++ b/fs/smb/server/tests/smbacl_kunit.c @@ -229,7 +229,7 @@ static void ksmbd_smb_check_perm_dacl_boundary_test(struct kunit *test) goto out; rc = smb_check_perm_dacl(NULL, &file->f_path, &daccess, - cpu_to_le32(FILE_READ_DATA), 0, false); + cpu_to_le32(FILE_READ_DATA), 0, true, false); /* * The post-boundary ACE (ACE #2, beyond pdacl->size) grants @@ -271,7 +271,7 @@ ksmbd_smb_check_perm_dacl_maximal_boundary_test(struct kunit *test) goto out; rc = smb_check_perm_dacl(NULL, &file->f_path, &daccess, - FILE_MAXIMAL_ACCESS_LE, 0, false); + FILE_MAXIMAL_ACCESS_LE, 0, true, false); KUNIT_EXPECT_EQ(test, 0, rc); if (rc) goto out; diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c index a98a0f16423992..870f3cf0c22788 100644 --- a/fs/smb/server/transport_tcp.c +++ b/fs/smb/server/transport_tcp.c @@ -489,7 +489,7 @@ static struct tcp_tx *ksmbd_tcp_alloc_tx(const struct ksmbd_transport_write *tx, struct iov_iter iter; size_t remaining = tx->size - offset; - msg = kvmalloc(struct_size(msg, data, remaining), KSMBD_DEFAULT_GFP); + msg = kvmalloc_flex(*msg, data, remaining, KSMBD_DEFAULT_GFP); if (!msg) return NULL; diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index 1f2bc76f0d090b..cb3f4f5fe9cf0b 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -367,6 +367,10 @@ int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count, if (ksmbd_stream_fd(fp)) return ksmbd_vfs_stream_read(fp, rbuf, pos, count); + /* The access granted on open can include FILE_EXECUTE for a write-only file */ + if (!(filp->f_mode & FMODE_READ)) + return -EACCES; + if (!fp->is_posix_ctxt) { int ret; diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index f9079c529d070d..c846023e5adad9 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -420,7 +420,12 @@ bool ksmbd_has_stream_without_delete_share(struct ksmbd_file *fp) if (file_inode(fp->filp) != file_inode(prev_fp->filp)) continue; - if (!(prev_fp->saccess & FILE_SHARE_DELETE_LE)) { + /* + * A stream open with no right in FILE_SHARE_CHECKED_ACCESS_LE, + * implied writes included, never conflicts. + */ + if (!(prev_fp->saccess & FILE_SHARE_DELETE_LE) && + ksmbd_sharing_daccess(prev_fp) & FILE_SHARE_CHECKED_ACCESS_LE) { ret = true; break; } diff --git a/fs/smb/server/vfs_cache.h b/fs/smb/server/vfs_cache.h index a0239ec178d8d9..57c81287efe63c 100644 --- a/fs/smb/server/vfs_cache.h +++ b/fs/smb/server/vfs_cache.h @@ -131,6 +131,8 @@ struct ksmbd_file { bool is_nt_open; bool attrib_only; + /* writes data on open, see ksmbd_sharing_daccess() */ + bool implied_write; bool allocation_size_set; char client_guid[16]; diff --git a/fs/splice.c b/fs/splice.c index e6d43329ed3f06..5397ded643a7f5 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -55,63 +55,6 @@ static noinline void pipe_clear_nowait(struct file *file) } while (!try_cmpxchg(&file->f_mode, &fmode, fmode & ~FMODE_NOWAIT)); } -/* - * Attempt to steal a page from a pipe buffer. This should perhaps go into - * a vm helper function, it's already simplified quite a bit by the - * addition of remove_mapping(). If success is returned, the caller may - * attempt to reuse this page for another destination. - */ -static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - struct folio *folio = page_folio(buf->page); - struct address_space *mapping; - - folio_lock(folio); - - mapping = folio_mapping(folio); - if (mapping) { - WARN_ON(!folio_test_uptodate(folio)); - - /* - * At least for ext2 with nobh option, we need to wait on - * writeback completing on this folio, since we'll remove it - * from the pagecache. Otherwise truncate wont wait on the - * folio, allowing the disk blocks to be reused by someone else - * before we actually wrote our data to them. fs corruption - * ensues. - */ - folio_wait_writeback(folio); - - if (!filemap_release_folio(folio, GFP_KERNEL)) - goto out_unlock; - - /* - * If we succeeded in removing the mapping, set LRU flag - * and return good. - */ - if (remove_mapping(mapping, folio)) { - buf->flags |= PIPE_BUF_FLAG_LRU; - return true; - } - } - - /* - * Raced with truncate or failed to remove folio from current - * address space, unlock and return failure. - */ -out_unlock: - folio_unlock(folio); - return false; -} - -static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - put_page(buf->page); - buf->flags &= ~PIPE_BUF_FLAG_LRU; -} - /* * Check whether the contents of buf is OK to access. Since the content * is a page cache page, IO may be in flight. @@ -154,24 +97,12 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, const struct pipe_buf_operations page_cache_pipe_buf_ops = { .confirm = page_cache_pipe_buf_confirm, - .release = page_cache_pipe_buf_release, - .try_steal = page_cache_pipe_buf_try_steal, + .release = generic_pipe_buf_release, .get = generic_pipe_buf_get, }; -static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - if (!(buf->flags & PIPE_BUF_FLAG_GIFT)) - return false; - - buf->flags |= PIPE_BUF_FLAG_LRU; - return generic_pipe_buf_try_steal(pipe, buf); -} - static const struct pipe_buf_operations user_page_pipe_buf_ops = { - .release = page_cache_pipe_buf_release, - .try_steal = user_page_pipe_buf_try_steal, + .release = generic_pipe_buf_release, .get = generic_pipe_buf_get, }; @@ -400,16 +331,9 @@ EXPORT_SYMBOL(copy_splice_read); const struct pipe_buf_operations default_pipe_buf_ops = { .release = generic_pipe_buf_release, - .try_steal = generic_pipe_buf_try_steal, .get = generic_pipe_buf_get, }; - -/* Pipe buffer operations for a socket and similar. */ -const struct pipe_buf_operations nosteal_pipe_buf_ops = { - .release = generic_pipe_buf_release, - .get = generic_pipe_buf_get, -}; -EXPORT_SYMBOL(nosteal_pipe_buf_ops); +EXPORT_SYMBOL(default_pipe_buf_ops); static void wakeup_pipe_writers(struct pipe_inode_info *pipe) { @@ -737,9 +661,12 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, sd.pos = kiocb.ki_pos; if (ret <= 0) break; - WARN_ONCE(ret > sd.total_len - left, - "Splice Exceeded! ret=%zd tot=%zu left=%zu\n", - ret, sd.total_len, left); + if (unlikely(ret > sd.total_len - left)) { + WARN_ONCE(1, + "Splice Exceeded! ret=%zd tot=%zu left=%zu\n", + ret, sd.total_len, left); + ret = sd.total_len - left; + } sd.num_spliced += ret; sd.total_len -= ret; @@ -863,9 +790,9 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, bvec_set_page(&bvec[bc++], buf->page, seg, buf->offset); remain -= seg; + tail++; if (remain == 0 || bc >= ARRAY_SIZE(bvec)) break; - tail++; } if (!bc) @@ -1469,12 +1396,10 @@ static ssize_t __do_splice(struct file *in, loff_t __user *off_in, } static ssize_t iter_to_pipe(struct iov_iter *from, - struct pipe_inode_info *pipe, - unsigned int flags) + struct pipe_inode_info *pipe) { struct pipe_buffer buf = { .ops = &user_page_pipe_buf_ops, - .flags = flags }; size_t total = 0; ssize_t ret = 0; @@ -1564,10 +1489,6 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter, { struct pipe_inode_info *pipe; ssize_t ret = 0; - unsigned buf_flag = 0; - - if (flags & SPLICE_F_GIFT) - buf_flag = PIPE_BUF_FLAG_GIFT; pipe = get_pipe_info(file, true); if (!pipe) @@ -1578,7 +1499,7 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter, pipe_lock(pipe); ret = wait_for_space(pipe, flags); if (!ret) - ret = iter_to_pipe(iter, pipe, buf_flag); + ret = iter_to_pipe(iter, pipe); pipe_unlock(pipe); if (ret > 0) { wakeup_pipe_readers(pipe); @@ -1839,11 +1760,7 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, } *obuf = *ibuf; - /* - * Don't inherit the gift and merge flags, we need to - * prevent multiple steals of this page. - */ - obuf->flags &= ~PIPE_BUF_FLAG_GIFT; + /* The page is shared with ipipe: don't append to it */ obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE; obuf->len = len; @@ -1956,11 +1873,7 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, *obuf = *ibuf; - /* - * Don't inherit the gift and merge flag, we need to prevent - * multiple steals of this page. - */ - obuf->flags &= ~PIPE_BUF_FLAG_GIFT; + /* The page is shared with ipipe: don't append to it */ obuf->flags &= ~PIPE_BUF_FLAG_CAN_MERGE; if (obuf->len > len) diff --git a/fs/stat.c b/fs/stat.c index a2e63c6c45b774..34d786c1de3ee7 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -710,8 +710,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) /* STATX_CHANGE_COOKIE is kernel-only for now */ tmp.stx_mask = stat->result_mask & ~STATX_CHANGE_COOKIE; tmp.stx_blksize = stat->blksize; - /* STATX_ATTR_CHANGE_MONOTONIC is kernel-only for now */ - tmp.stx_attributes = stat->attributes & ~STATX_ATTR_CHANGE_MONOTONIC; + tmp.stx_attributes = stat->attributes & ~STATX_ATTR_INTERNAL_MASK; tmp.stx_nlink = stat->nlink; tmp.stx_uid = from_kuid_munged(current_user_ns(), stat->uid); tmp.stx_gid = from_kgid_munged(current_user_ns(), stat->gid); @@ -719,7 +718,8 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_ino = stat->ino; tmp.stx_size = stat->size; tmp.stx_blocks = stat->blocks; - tmp.stx_attributes_mask = stat->attributes_mask; + tmp.stx_attributes_mask = stat->attributes_mask & + ~STATX_ATTR_INTERNAL_MASK; tmp.stx_atime.tv_sec = stat->atime.tv_sec; tmp.stx_atime.tv_nsec = stat->atime.tv_nsec; tmp.stx_btime.tv_sec = stat->btime.tv_sec; diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 30cec560014916..b6551cc7c6cfe2 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c @@ -457,6 +457,7 @@ static void udf_table_free_blocks(struct super_block *sb, int adsize; + eloc.partitionReferenceNum = bloc->partitionReferenceNum; eloc.logicalBlockNum = start; elen = EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits); @@ -524,30 +525,22 @@ static int udf_table_prealloc_blocks(struct super_block *sb, while (first_block != eloc.logicalBlockNum) { ret = udf_next_aext(table, &epos, &eloc, &elen, &etype, 1); - if (ret < 0) + if (ret <= 0) goto err_out; - if (ret == 0) - break; udf_debug("eloc=%u, elen=%u, first_block=%u\n", eloc.logicalBlockNum, elen, first_block); } - if (first_block == eloc.logicalBlockNum) { - epos.offset -= adsize; - - alloc_count = (elen >> sb->s_blocksize_bits); - if (alloc_count > block_count) { - alloc_count = block_count; - eloc.logicalBlockNum += alloc_count; - elen -= (alloc_count << sb->s_blocksize_bits); - udf_write_aext(table, &epos, &eloc, - (etype << 30) | elen, 1); - } else - udf_delete_aext(table, epos, &freed); - } else { - alloc_count = 0; - } + epos.offset -= adsize; + alloc_count = (elen >> sb->s_blocksize_bits); + if (alloc_count > block_count) { + alloc_count = block_count; + eloc.logicalBlockNum += alloc_count; + elen -= (alloc_count << sb->s_blocksize_bits); + udf_write_aext(table, &epos, &eloc, (etype << 30) | elen, 1); + } else + udf_delete_aext(table, epos, &freed); err_out: brelse(epos.bh); @@ -572,7 +565,7 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, uint32_t elen, goal_elen = 0; struct kernel_lb_addr eloc, goal_eloc; struct extent_position epos, goal_epos; - int8_t etype; + int8_t etype, goal_etype = 0; struct udf_inode_info *iinfo = UDF_I(table); int ret = 0; @@ -623,7 +616,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_epos.block = epos.block; goal_epos.offset = epos.offset - adsize; goal_eloc = eloc; - goal_elen = (etype << 30) | elen; + goal_elen = elen; + goal_etype = etype; } } @@ -647,7 +641,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_elen -= sb->s_blocksize; if (goal_elen) - udf_write_aext(table, &goal_epos, &goal_eloc, goal_elen, 1); + udf_write_aext(table, &goal_epos, &goal_eloc, + (goal_etype << 30) | goal_elen, 1); else udf_delete_aext(table, goal_epos, &freed); brelse(goal_epos.bh); diff --git a/fs/udf/inode.c b/fs/udf/inode.c index bacf2a86161e6c..29900065673cfc 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -152,8 +152,6 @@ void udf_evict_inode(struct inode *inode) } } truncate_inode_pages_final(&inode->i_data); - if (!want_delete) - mmb_sync(&iinfo->i_metadata_bhs); mmb_invalidate(&iinfo->i_metadata_bhs); clear_inode(inode); kfree(iinfo->i_data); @@ -1607,6 +1605,11 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode) */ if (iinfo->i_lenEAttr > bs || iinfo->i_lenAlloc > bs) goto out; + /* We need to have space at least for generic descriptor */ + if (iinfo->i_lenEAttr && iinfo->i_lenEAttr < + sizeof(struct extendedAttrHeaderDesc)) + goto out; + /* Now do exact checks */ if (udf_file_entry_alloc_offset(inode) + iinfo->i_lenAlloc > bs) goto out; @@ -1742,25 +1745,24 @@ void udf_update_extra_perms(struct inode *inode, umode_t mode) int udf_sync_inode_metadata(struct inode *inode, struct writeback_control *wbc) { struct buffer_head *bh; + unsigned long block; int err = 0; - bh = sb_getblk(inode->i_sb, - udf_get_lb_pblock(inode->i_sb, - &UDF_I(inode)->i_location, 0)); - if (!bh) - return -EIO; - - sync_dirty_buffer(bh); - if (buffer_write_io_error(bh)) { - udf_warn(inode->i_sb, "IO error syncing udf inode [%08llx]\n", - inode->i_ino); - err = -EIO; - goto out; + block = udf_get_lb_pblock(inode->i_sb, &UDF_I(inode)->i_location, 0); + /* A block that isn't cached is neither dirty nor under writeback. */ + bh = sb_find_get_block_nonatomic(inode->i_sb, block); + if (bh) { + sync_dirty_buffer(bh); + if (buffer_write_io_error(bh)) { + udf_warn(inode->i_sb, "IO error syncing udf inode [%08llx]\n", + inode->i_ino); + err = -EIO; + } + brelse(bh); + if (err) + return err; } - err = mmb_sync(&UDF_I(inode)->i_metadata_bhs); -out: - brelse(bh); - return err; + return mmb_sync(&UDF_I(inode)->i_metadata_bhs); } static void udf_adjust_time(struct udf_inode_info *iinfo, struct timespec64 time) @@ -2325,10 +2327,10 @@ int udf_current_aext(struct inode *inode, struct extent_position *epos, ptr = epos->bh->b_data + epos->offset; if (check_add_overflow(sizeof(struct allocExtDesc), le32_to_cpu(header->lengthAllocDescs), &alen)) - return -1; + return -EFSCORRUPTED; if (alen > epos->bh->b_size) - return -1; + return -EFSCORRUPTED; } switch (iinfo->i_alloc_type) { diff --git a/fs/udf/super.c b/fs/udf/super.c index 5351755aca3ecc..a81a8509524a9f 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -1106,6 +1106,73 @@ static int check_partition_desc(struct super_block *sb, return 0; } +/* + * Check the Unallocated Space Table once when it is loaded: the allocator + * hands out blocks from the start of each extent and trusts that every + * extent covers at least one whole block inside the partition. + */ +static int udf_check_unalloc_table(struct super_block *sb, + struct inode *table, u32 partition_len) +{ + struct extent_position epos = { + .block = UDF_I(table)->i_location, + .offset = sizeof(struct unallocSpaceEntry), + }; + struct kernel_lb_addr eloc; + uint32_t elen, blocks; + struct kernel_lb_addr seen_block = {}; + uint32_t seen_offset = 0; + u64 steps = 0, period = 1; + int8_t etype; + int ret; + + /* The walk below assumes the layout of an Unallocated Space Entry */ + if (!UDF_I(table)->i_use) { + udf_err(sb, "unallocated space table is not an unallocated space entry\n"); + return -EFSCORRUPTED; + } + + while ((ret = udf_next_aext(table, &epos, &eloc, &elen, &etype, 1)) > 0) { + blocks = elen >> sb->s_blocksize_bits; + if (!blocks || (elen & (sb->s_blocksize - 1)) || + eloc.logicalBlockNum >= partition_len || + blocks > partition_len - eloc.logicalBlockNum) { + udf_err(sb, "invalid unallocated space table extent (block %u, length %u)\n", + eloc.logicalBlockNum, elen); + ret = -EFSCORRUPTED; + break; + } + /* + * A chain of allocation extents can lead back to itself, and + * then the walk returns the same extents forever. Remember a + * position at doubling intervals; a walk that comes back to it + * is in a loop. + */ + if (epos.block.logicalBlockNum == seen_block.logicalBlockNum && + epos.block.partitionReferenceNum == + seen_block.partitionReferenceNum && + epos.offset == seen_offset) { + udf_err(sb, "unallocated space table loops back on itself\n"); + ret = -EFSCORRUPTED; + break; + } + if (++steps == period) { + seen_block = epos.block; + seen_offset = epos.offset; + steps = 0; + period <<= 1; + } + if (fatal_signal_pending(current)) { + udf_err(sb, "interrupted while checking the unallocated space table\n"); + ret = -EINTR; + break; + } + cond_resched(); + } + brelse(epos.bh); + return ret; +} + static int udf_fill_partdesc_info(struct super_block *sb, struct partitionDesc *p, int p_index) { @@ -1166,6 +1233,16 @@ static int udf_fill_partdesc_info(struct super_block *sb, p_index); return PTR_ERR(inode); } + err = udf_check_unalloc_table(sb, inode, map->s_partition_len); + if (err) { + iput(inode); + if (err == -EINTR) + return err; + if (!sb_rdonly(sb)) + return -EACCES; + UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT); + return 0; + } map->s_uspace.s_table = inode; map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; udf_debug("unallocSpaceTable (part %d) @ %llu\n", @@ -1252,6 +1329,12 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) (sbi->s_vat_inode->i_size - 36) >> 2; } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { vati = UDF_I(sbi->s_vat_inode); + if (sbi->s_vat_inode->i_size < + sizeof(struct virtualAllocationTable20)) { + udf_err(sb, "Too short VAT inode size %lld\n", + sbi->s_vat_inode->i_size); + return -EFSCORRUPTED; + } if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { int err = 0; @@ -1269,8 +1352,12 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) map->s_type_specific.s_virtual.s_start_offset = le16_to_cpu(vat20->lengthHeader); - if (map->s_type_specific.s_virtual.s_start_offset - > sbi->s_vat_inode->i_size) { + if (map->s_type_specific.s_virtual.s_start_offset < + sizeof(struct virtualAllocationTable20) || + map->s_type_specific.s_virtual.s_start_offset > + sb->s_blocksize || + map->s_type_specific.s_virtual.s_start_offset > + sbi->s_vat_inode->i_size) { udf_err(sb, "Corrupted VAT header length %u (VAT inode size %lld)\n", map->s_type_specific.s_virtual.s_start_offset, sbi->s_vat_inode->i_size); @@ -2233,8 +2320,9 @@ static int udf_fill_super(struct super_block *sb, struct fs_context *fc) /* * EACCES is special - we want to propagate to * upper layers that we cannot handle RW mount. + * EINTR means that a fatal signal is pending. */ - if (ret == -EACCES) + if (ret == -EACCES || ret == -EINTR) break; } else break; diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index 0990f94b855183..75151a59f0da66 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c @@ -124,8 +124,8 @@ void udf_discard_prealloc(struct inode *inode) { struct extent_position epos = {}; struct extent_position prev_epos = {}; - struct kernel_lb_addr eloc; - uint32_t elen; + struct kernel_lb_addr eloc, tmpeloc; + uint32_t elen, tmpelen; uint64_t lbcount = 0; int8_t etype = -1; struct udf_inode_info *iinfo = UDF_I(inode); @@ -141,7 +141,8 @@ void udf_discard_prealloc(struct inode *inode) /* Find the last extent in the file */ while (1) { - ret = udf_next_aext(inode, &epos, &eloc, &elen, &tmpetype, 0); + ret = udf_next_aext(inode, &epos, &tmpeloc, &tmpelen, + &tmpetype, 0); if (ret < 0) goto out; if (ret == 0) diff --git a/fs/verity/open.c b/fs/verity/open.c index d1ac9556e94748..398c3611445156 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -236,9 +236,8 @@ struct fsverity_info *fsverity_create_info(struct inode *inode, vi->tree_params.tree_pages << vi->tree_params.log_blocks_per_page; - vi->hash_block_verified = kvcalloc(BITS_TO_LONGS(num_bits), - sizeof(unsigned long), - GFP_KERNEL); + vi->hash_block_verified = kvzalloc_objs(unsigned long, + BITS_TO_LONGS(num_bits)); if (!vi->hash_block_verified) { err = -ENOMEM; goto fail; diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 6068fad9dc9e84..82932b5c02fd71 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -3042,7 +3042,14 @@ xfs_attr3_leaf_setflag( #endif entry = &xfs_attr3_leaf_entryp(leaf)[args->index]; - ASSERT((entry->flags & XFS_ATTR_INCOMPLETE) == 0); + if (entry->flags & XFS_ATTR_INCOMPLETE) { + if (!(args->op_flags & XFS_DA_OP_RECOVERY)) { + ASSERT(args->op_flags & XFS_DA_OP_RECOVERY); + return -EFSCORRUPTED; + } + return 0; + } + entry->flags |= XFS_ATTR_INCOMPLETE; xfs_trans_log_buf(args->trans, bp, XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry))); diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index ca49bf4a50c5f2..050522c58b168f 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4130,6 +4130,8 @@ xfs_bmapi_finish( * Returns a negative error code on failure, including -ENOSPC when it could not * allocate any blocks and -ENOSR when it did allocate blocks to convert a * delalloc range, but those blocks were before the passed in range. + * With XFS_BMAPI_CONVERT_ONLY, it stops at a hole or a delalloc extent instead + * of allocating blocks, and returns -ENOSR if it stops before mapping anything. */ int xfs_bmapi_write( @@ -4189,6 +4191,8 @@ xfs_bmapi_write( */ ASSERT((flags & (XFS_BMAPI_PREALLOC | XFS_BMAPI_ZERO)) != (XFS_BMAPI_PREALLOC | XFS_BMAPI_ZERO)); + ASSERT(!(flags & XFS_BMAPI_CONVERT_ONLY) || + (flags & XFS_BMAPI_CONVERT)); if (XFS_IS_CORRUPT(mp, !xfs_ifork_has_extents(ifp)) || XFS_TEST_ERROR(mp, XFS_ERRTAG_BMAPIFORMAT)) { @@ -4237,6 +4241,9 @@ xfs_bmapi_write( * that we found, if any. */ if (need_alloc || wasdelay) { + if (flags & XFS_BMAPI_CONVERT_ONLY) + break; + bma.eof = eof; bma.conv = !!(flags & XFS_BMAPI_CONVERT); bma.wasdel = wasdelay; @@ -4332,10 +4339,13 @@ xfs_bmapi_write( * * To avoid a successful return with *nmap set to 0, return the magic * -ENOSR error code for this particular case so that the caller can - * handle it. + * handle it. The same goes for XFS_BMAPI_CONVERT_ONLY stopping at a + * hole or a delalloc extent at the start of the range, in which case + * nothing has been changed. */ if (!n) { - ASSERT(bma.nallocs >= *nmap); + ASSERT((flags & XFS_BMAPI_CONVERT_ONLY) ? bma.nallocs == 0 : + bma.nallocs >= *nmap); return -ENOSR; } *nmap = n; diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index e9f5416e4c050d..fb7481e8190c64 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -90,6 +90,13 @@ struct xfs_bmalloca { /* Try to align allocations to the extent size hint */ #define XFS_BMAPI_EXTSZALIGN (1u << 11) +/* + * Use with XFS_BMAPI_CONVERT to convert unwritten extents without allocating + * blocks. Stop at a hole or a delalloc extent: return the mappings found so + * far, or -ENOSR if there are none. + */ +#define XFS_BMAPI_CONVERT_ONLY (1u << 12) + #define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \ @@ -102,7 +109,8 @@ struct xfs_bmalloca { { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ { XFS_BMAPI_NORMAP, "NORMAP" },\ - { XFS_BMAPI_EXTSZALIGN, "EXTSZALIGN" } + { XFS_BMAPI_EXTSZALIGN, "EXTSZALIGN" }, \ + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } static inline int xfs_bmapi_aflag(int w) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 2434c54a35708e..5d1d73f99ce055 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -2567,7 +2567,7 @@ xfs_btree_lshift( if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) { xfs_btree_mark_sick(cur); error = -EFSCORRUPTED; - goto error0; + goto error1; } error = xfs_btree_decrement(tcur, level, &i); @@ -2737,7 +2737,7 @@ xfs_btree_rshift( if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) { xfs_btree_mark_sick(cur); error = -EFSCORRUPTED; - goto error0; + goto error1; } error = xfs_btree_increment(tcur, level, &i); @@ -3009,10 +3009,6 @@ xfs_btree_split_worker( struct xfs_btree_split_args, work); unsigned int nofs_flags; - /* - * Don't use xfs_trans_set_context() here: it would overwrite the - * caller's saved NOFS state in tp->t_pflags. Use a local scope. - */ nofs_flags = memalloc_nofs_save(); args->result = __xfs_btree_split(args->cur, args->level, args->ptrp, diff --git a/fs/xfs/libxfs/xfs_trans.h b/fs/xfs/libxfs/xfs_trans.h index 05b3cc19a311bd..b0c7724d06196a 100644 --- a/fs/xfs/libxfs/xfs_trans.h +++ b/fs/xfs/libxfs/xfs_trans.h @@ -264,20 +264,6 @@ int xfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv, struct xfs_inode *ip, unsigned int *dblocks, struct xfs_trans **tpp, int *nospace_error); -static inline void -xfs_trans_set_context( - struct xfs_trans *tp) -{ - tp->t_pflags = memalloc_nofs_save(); -} - -static inline void -xfs_trans_clear_context( - struct xfs_trans *tp) -{ - memalloc_nofs_restore(tp->t_pflags); -} - static inline void xfs_trans_cancel( struct xfs_trans *tp) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index c30e688cfc9f6e..1db6f3640c53bd 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -575,7 +575,7 @@ xfs_vm_bmap( */ if (xfs_is_cow_inode(ip) || XFS_IS_REALTIME_INODE(ip)) return 0; - return iomap_bmap(mapping, block, &xfs_read_iomap_ops); + return iomap_bmap(mapping, block, xfs_read_iomap_next); } static void @@ -614,7 +614,7 @@ xfs_vm_read_folio( struct iomap_read_folio_ctx ctx = { .cur_folio = folio }; ctx.ops = xfs_get_iomap_read_ops(folio->mapping); - iomap_read_folio(&xfs_read_iomap_ops, &ctx, NULL); + iomap_read_folio(xfs_read_iomap_next, &ctx, NULL); return 0; } @@ -625,7 +625,7 @@ xfs_vm_readahead( struct iomap_read_folio_ctx ctx = { .rac = rac }; ctx.ops = xfs_get_iomap_read_ops(rac->mapping), - iomap_readahead(&xfs_read_iomap_ops, &ctx, NULL); + iomap_readahead(xfs_read_iomap_next, &ctx, NULL); } static int @@ -671,7 +671,7 @@ xfs_vm_swap_activate( sis->bdev = xfs_inode_buftarg(ip)->bt_bdev; return iomap_swapfile_activate(sis, swap_file, span, - &xfs_read_iomap_ops); + xfs_read_iomap_next); } const struct address_space_operations xfs_address_space_operations = { diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 906221ffe9ba86..cdf660344c281a 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -155,6 +155,8 @@ struct xfs_trim_cur { xfs_agblock_t end; xfs_extlen_t minlen; bool by_bno; + /* restart point (with count) for the by-length walk */ + xfs_agblock_t restart_bno; }; static int @@ -198,14 +200,15 @@ xfs_trim_gather_extents( error = xfs_alloc_lookup_le(cur, tcur->start, 0, &i); if (!error && !i) error = xfs_alloc_lookup_ge(cur, tcur->start, 0, &i); - } else if (tcur->start == 0) { - /* first time through a by-len starts with max length */ - cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag); - error = xfs_alloc_lookup_ge(cur, 0, tcur->count, &i); } else { - /* nth time through a by-len starts where we left off */ + /* + * A by-len walk starts at the last record of the longest + * length (restart_bno is NULLAGBLOCK until the first batch + * ends) and then where the previous batch stopped. + */ cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag); - error = xfs_alloc_lookup_le(cur, tcur->start, tcur->count, &i); + error = xfs_alloc_lookup_le(cur, tcur->restart_bno, + tcur->count, &i); } if (error) goto out_del_cursor; @@ -235,9 +238,15 @@ xfs_trim_gather_extents( if (--batch <= 0) { /* * Update the cursor to point at this extent so we - * restart the next batch from this extent. + * restart the next batch from this extent. The + * by-length walk does not visit extents in block + * order, so it must keep the start of the range and + * restart from restart_bno instead. */ - tcur->start = fbno; + if (tcur->by_bno) + tcur->start = fbno; + else + tcur->restart_bno = fbno; tcur->count = flen; break; } @@ -340,6 +349,7 @@ xfs_trim_perag_extents( .start = start, .end = end, .minlen = minlen, + .restart_bno = NULLAGBLOCK, }; int error = 0; diff --git a/fs/xfs/xfs_export.c b/fs/xfs/xfs_export.c index 9afda52ed1a265..9dd6dd8c27c882 100644 --- a/fs/xfs/xfs_export.c +++ b/fs/xfs/xfs_export.c @@ -234,7 +234,7 @@ STATIC int xfs_fs_nfs_commit_metadata( struct inode *inode) { - return xfs_log_force_inode(XFS_I(inode)); + return xfs_log_force_inode(XFS_I(inode), false, NULL); } const struct export_operations xfs_export_operations = { diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 7d0c8a197575cf..d61ea8e2c8e40c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -76,49 +76,7 @@ xfs_dir_fsync( struct xfs_inode *ip = XFS_I(file->f_mapping->host); trace_xfs_dir_fsync(ip); - return xfs_log_force_inode(ip); -} - -/* - * All metadata updates are logged, which means that we just have to push the - * journal to the required sequence number than holds the updates. We track - * datasync commits separately to full sync commits, and hence only need to - * select the correct sequence number for the log force here. - * - * We don't have to serialise against concurrent modifications, as we do not - * have to wait for modifications that have not yet completed. We define a - * transaction commit as completing when the commit sequence number is updated, - * hence if the sequence number has not updated, the sync operation has been - * run before the commit completed and we don't have to wait for it. - * - * If we have concurrent fsync/fdatasync() calls, the sequence numbers remain - * set on the log item until - at least - the journal flush completes. In - * reality, they are only cleared when the inode is fully unpinned (i.e. - * persistent in the journal and not dirty in the CIL), and so we rely on - * xfs_log_force_seq() either skipping sequences that have been persisted or - * waiting on sequences that are still in flight to correctly order concurrent - * sync operations. - */ -static int -xfs_fsync_flush_log( - struct xfs_inode *ip, - bool datasync, - int *log_flushed) -{ - struct xfs_inode_log_item *iip = ip->i_itemp; - xfs_csn_t seq = 0; - - spin_lock(&iip->ili_lock); - if (datasync) - seq = iip->ili_datasync_seq; - else - seq = iip->ili_commit_seq; - spin_unlock(&iip->ili_lock); - - if (!seq) - return 0; - - return xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, log_flushed); + return xfs_log_force_inode(ip, false, NULL); } STATIC int @@ -151,7 +109,7 @@ xfs_file_fsync( * no modifications to this inode that need to be pushed out. */ if (ip->i_itemp) { - error = xfs_fsync_flush_log(ip, datasync, &log_flushed); + error = xfs_log_force_inode(ip, datasync, &log_flushed); if (error) return error; } @@ -250,12 +208,12 @@ xfs_file_dio_read( if (ret) return ret; if (mapping_stable_writes(iocb->ki_filp->f_mapping)) { - ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, + ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next, &xfs_dio_read_bounce_ops, 0, NULL, 0); } else { ret = iomap_dio_read_simple(iocb, to, xfs_read_iomap_begin); if (ret == -ENOTBLK) - ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL, + ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next, NULL, 0, NULL, 0); } xfs_iunlock(ip, XFS_IOLOCK_SHARED); @@ -279,7 +237,7 @@ xfs_file_dax_read( ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED); if (ret) return ret; - ret = dax_iomap_rw(iocb, to, &xfs_read_iomap_ops); + ret = dax_iomap_rw(iocb, to, xfs_read_iomap_next); xfs_iunlock(ip, XFS_IOLOCK_SHARED); file_accessed(iocb->ki_filp); @@ -666,7 +624,7 @@ xfs_dio_write_end_io( * they are converted. */ if (flags & IOMAP_DIO_UNWRITTEN) { - error = xfs_iomap_write_unwritten(ip, offset, size, true); + error = xfs_iomap_write_unwritten(ip, offset, size, true, 0); goto out; } @@ -729,7 +687,7 @@ xfs_file_dio_write_aligned( struct xfs_inode *ip, struct kiocb *iocb, struct iov_iter *from, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_dio_ops *dops, struct xfs_zone_alloc_ctx *ac) { @@ -764,9 +722,10 @@ xfs_file_dio_write_aligned( if (mapping_stable_writes(iocb->ki_filp->f_mapping)) dio_flags |= IOMAP_DIO_BOUNCE; trace_xfs_file_direct_write(iocb, from); - ret = iomap_dio_rw(iocb, from, ops, dops, dio_flags, ac, 0); + ret = iomap_dio_rw(iocb, from, next, dops, dio_flags, ac, 0); out_unlock: - xfs_iunlock(ip, iolock); + if (iolock) + xfs_iunlock(ip, iolock); return ret; } @@ -786,7 +745,7 @@ xfs_file_dio_write_zoned( if (ret < 0) return ret; ret = xfs_file_dio_write_aligned(ip, iocb, from, - &xfs_zoned_direct_write_iomap_ops, + xfs_zoned_direct_write_iomap_next, &xfs_dio_zoned_write_ops, &ac); xfs_zoned_space_unreserve(ip->i_mount, &ac); return ret; @@ -811,16 +770,16 @@ xfs_file_dio_write_atomic( unsigned int iolock = XFS_IOLOCK_SHARED; ssize_t ret, ocount = iov_iter_count(from); unsigned int dio_flags = 0; - const struct iomap_ops *dops; + iomap_iter_next_fn next; /* * HW offload should be faster, so try that first if it is already * known that the write length is not too large. */ if (ocount > xfs_inode_buftarg(ip)->bt_awu_max) - dops = &xfs_atomic_write_cow_iomap_ops; + next = xfs_atomic_write_cow_iomap_next; else - dops = &xfs_direct_write_iomap_ops; + next = xfs_direct_write_iomap_next; retry: ret = xfs_ilock_iocb_for_write(iocb, &iolock); @@ -840,18 +799,19 @@ xfs_file_dio_write_atomic( trace_xfs_file_direct_write(iocb, from); if (mapping_stable_writes(iocb->ki_filp->f_mapping)) dio_flags |= IOMAP_DIO_BOUNCE; - ret = iomap_dio_rw(iocb, from, dops, &xfs_dio_write_ops, dio_flags, + ret = iomap_dio_rw(iocb, from, next, &xfs_dio_write_ops, dio_flags, NULL, 0); /* - * The retry mechanism is based on the ->iomap_next method returning - * -ENOPROTOOPT, which would be when the REQ_ATOMIC-based write is not - * possible. The REQ_ATOMIC-based method is typically not possible if - * the write spans multiple extents or the disk blocks are misaligned. + * The retry mechanism is based on the iomap_iter_next_fn callback + * returning -ENOPROTOOPT, which would be when the REQ_ATOMIC-based + * write is not possible. The REQ_ATOMIC-based method is typically not + * possible if the write spans multiple extents or the disk blocks are + * misaligned. */ - if (ret == -ENOPROTOOPT && dops == &xfs_direct_write_iomap_ops) { + if (ret == -ENOPROTOOPT && next == xfs_direct_write_iomap_next) { xfs_iunlock(ip, iolock); - dops = &xfs_atomic_write_cow_iomap_ops; + next = xfs_atomic_write_cow_iomap_next; goto retry; } @@ -934,7 +894,7 @@ xfs_file_dio_write_unaligned( flags |= IOMAP_DIO_BOUNCE; trace_xfs_file_direct_write(iocb, from); - ret = iomap_dio_rw(iocb, from, &xfs_direct_write_iomap_ops, + ret = iomap_dio_rw(iocb, from, xfs_direct_write_iomap_next, &xfs_dio_write_ops, flags, NULL, 0); /* @@ -974,7 +934,7 @@ xfs_file_dio_write( if (iocb->ki_flags & IOCB_ATOMIC) return xfs_file_dio_write_atomic(ip, iocb, from); return xfs_file_dio_write_aligned(ip, iocb, from, - &xfs_direct_write_iomap_ops, &xfs_dio_write_ops, NULL); + xfs_direct_write_iomap_next, &xfs_dio_write_ops, NULL); } static noinline ssize_t @@ -998,7 +958,7 @@ xfs_file_dax_write( pos = iocb->ki_pos; trace_xfs_file_dax_write(iocb, from); - ret = dax_iomap_rw(iocb, from, &xfs_dax_write_iomap_ops); + ret = dax_iomap_rw(iocb, from, xfs_dax_write_iomap_next); if (ret > 0 && iocb->ki_pos > i_size_read(inode)) { i_size_write(inode, iocb->ki_pos); error = xfs_setfilesize(ip, pos, ret); @@ -1041,7 +1001,7 @@ xfs_file_buffered_write( trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, - &xfs_buffered_write_iomap_ops, &xfs_iomap_write_ops, + xfs_buffered_write_iomap_next, &xfs_iomap_write_ops, NULL); /* @@ -1122,7 +1082,7 @@ xfs_file_buffered_write_zoned( retry: trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, - &xfs_buffered_write_iomap_ops, &xfs_iomap_write_ops, + xfs_buffered_write_iomap_next, &xfs_iomap_write_ops, &ac); if (ret == -ENOSPC && !cleared_space) { /* @@ -1599,7 +1559,7 @@ __xfs_file_fallocate( } if (!error && xfs_file_sync_writes(file)) - error = xfs_log_force_inode(ip); + error = xfs_log_force_inode(ip, false, NULL); out_unlock: xfs_iunlock(ip, iolock); @@ -1750,7 +1710,7 @@ xfs_file_remap_range( goto out_unlock; if (xfs_file_sync_writes(file_in) || xfs_file_sync_writes(file_out)) - xfs_log_force_inode(dest); + xfs_log_force_inode(dest, false, NULL); out_unlock: xfs_iunlock2_remapping(src, dest); if (ret) @@ -1931,10 +1891,10 @@ xfs_file_llseek( default: return generic_file_llseek(file, offset, whence); case SEEK_HOLE: - offset = iomap_seek_hole(inode, offset, &xfs_seek_iomap_ops); + offset = iomap_seek_hole(inode, offset, xfs_seek_iomap_next); break; case SEEK_DATA: - offset = iomap_seek_data(inode, offset, &xfs_seek_iomap_ops); + offset = iomap_seek_data(inode, offset, xfs_seek_iomap_next); break; } @@ -1958,8 +1918,8 @@ xfs_dax_fault_locked( } ret = dax_iomap_fault(vmf, order, &pfn, NULL, (write_fault && !vmf->cow_page) ? - &xfs_dax_write_iomap_ops : - &xfs_read_iomap_ops); + xfs_dax_write_iomap_next : + xfs_read_iomap_next); if (ret & VM_FAULT_NEEDDSYNC) ret = dax_finish_sync_fault(vmf, order, pfn); return ret; @@ -2023,7 +1983,7 @@ __xfs_write_fault( if (IS_DAX(inode)) ret = xfs_dax_fault_locked(vmf, order, true); else - ret = iomap_page_mkwrite(vmf, &xfs_buffered_write_iomap_ops, + ret = iomap_page_mkwrite(vmf, xfs_buffered_write_iomap_next, ac); xfs_iunlock(ip, lock_mode); diff --git a/fs/xfs/xfs_healthmon.c b/fs/xfs/xfs_healthmon.c index 2bdd747f1ead24..05d6f0494139df 100644 --- a/fs/xfs/xfs_healthmon.c +++ b/fs/xfs/xfs_healthmon.c @@ -114,8 +114,8 @@ xfs_healthmon_attach( } refcount_inc(&hm->ref); - rcu_assign_pointer(mp->m_healthmon, hm); hm->mount_cookie = (uintptr_t)mp->m_super; + rcu_assign_pointer(mp->m_healthmon, hm); spin_unlock(&xfs_healthmon_lock); return 0; diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 05a14da280314b..cb61305e4b80dc 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1481,8 +1481,17 @@ xfs_inactive( */ if (xfs_inode_has_attr_fork(ip)) { error = xfs_attr_inactive(ip); - if (error) + if (error) { + /* + * Attr teardown failed, leaking blocks with no in-core + * record. Clear i_mode to block xfs_iget() recycling, + * then shut down so recovery cleans up the inode. + */ + VFS_I(ip)->i_mode = 0; + if (!xfs_is_shutdown(mp)) + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); goto out; + } } ASSERT(ip->i_forkoff == 0); @@ -2669,11 +2678,36 @@ xfs_irele( } /* - * Ensure all committed transactions touching the inode are written to the log. + * Ensure all committed transactions touching the inode are written to the log, + * or with @datasync only those that fdatasync has to wait for. + * + * All metadata updates are logged, which means that we just have to push the + * journal to the required sequence number that holds the updates. We track + * datasync commits separately to full sync commits, and hence only need to + * select the correct sequence number for the log force here. + * + * We don't have to serialise against concurrent modifications, as we do not + * have to wait for modifications that have not yet completed. We define a + * transaction commit as completing when the commit sequence number is updated, + * hence if the sequence number has not updated, the sync operation has been + * run before the commit completed and we don't have to wait for it. + * + * If we have concurrent fsync/fdatasync() calls, the sequence numbers remain + * set on the log item until - at least - the journal flush completes. In + * reality, they are only cleared when the inode is fully unpinned (i.e. + * persistent in the journal and not dirty in the CIL), and so we rely on + * xfs_log_force_seq() either skipping sequences that have been persisted or + * waiting on sequences that are still in flight to correctly order concurrent + * sync operations. + * + * If @log_flushed is not NULL, it is set when the log force wrote an iclog, + * which flushes the device caches before the log write. */ int xfs_log_force_inode( - struct xfs_inode *ip) + struct xfs_inode *ip, + bool datasync, + int *log_flushed) { struct xfs_inode_log_item *iip = ip->i_itemp; xfs_csn_t seq = 0; @@ -2682,12 +2716,15 @@ xfs_log_force_inode( return 0; spin_lock(&iip->ili_lock); - seq = iip->ili_commit_seq; + if (datasync) + seq = iip->ili_datasync_seq; + else + seq = iip->ili_commit_seq; spin_unlock(&iip->ili_lock); if (!seq) return 0; - return xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, NULL); + return xfs_log_force_seq(ip->i_mount, seq, XFS_LOG_SYNC, log_flushed); } /* diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 75eff68c1e3950..b16eee99b567b9 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -595,7 +595,8 @@ int xfs_ifree(struct xfs_trans *, struct xfs_inode *); int xfs_itruncate_extents_flags(struct xfs_trans **, struct xfs_inode *, int, xfs_fsize_t, int); -int xfs_log_force_inode(struct xfs_inode *ip); +int xfs_log_force_inode(struct xfs_inode *ip, bool datasync, + int *log_flushed); void xfs_iunpin_wait(xfs_inode_t *); #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount)) diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c index f6875a2cc7065d..77bc936bf0d9cb 100644 --- a/fs/xfs/xfs_ioctl32.c +++ b/fs/xfs/xfs_ioctl32.c @@ -143,8 +143,8 @@ xfs_ioctl32_bstat_copyin( xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) || xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) || xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) || - get_user(bstat->bs_blocks, &bstat32->bs_size) || - get_user(bstat->bs_xflags, &bstat32->bs_size) || + get_user(bstat->bs_blocks, &bstat32->bs_blocks) || + get_user(bstat->bs_xflags, &bstat32->bs_xflags) || get_user(bstat->bs_extsize, &bstat32->bs_extsize) || get_user(bstat->bs_extents, &bstat32->bs_extents) || get_user(bstat->bs_gen, &bstat32->bs_gen) || diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c index 48becc3bf60889..7f4a4a95afe50d 100644 --- a/fs/xfs/xfs_ioend.c +++ b/fs/xfs/xfs_ioend.c @@ -237,7 +237,7 @@ xfs_end_ioend_write( if (ioend->io_flags & IOMAP_IOEND_SHARED) error = xfs_reflink_end_cow(ip, offset, size); else if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN) - error = xfs_iomap_write_unwritten(ip, offset, size, false); + error = xfs_iomap_write_unwritten(ip, offset, size, false, 0); if (!error && !(ioend->io_flags & IOMAP_IOEND_DIRECT) && diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 329c745e312045..50eae7ff614534 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -285,6 +285,14 @@ xfs_iomap_write_direct( ASSERT(count_fsb > 0); + /* + * xfs_bmapi_write() maps at most XFS_MAX_BMBT_EXTLEN blocks in one + * mapping, so don't reserve blocks for more. A pNFS layout range + * comes from a client, and its block count may not even fit the + * 32-bit reservation. The caller maps the rest with a later call. + */ + count_fsb = min_t(xfs_filblks_t, count_fsb, XFS_MAX_BMBT_EXTLEN); + resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb, xfs_get_extsz_hint(ip)); if (unlikely(XFS_IS_REALTIME_INODE(ip))) { @@ -614,7 +622,8 @@ xfs_iomap_write_unwritten( xfs_inode_t *ip, xfs_off_t offset, xfs_off_t count, - bool update_isize) + bool update_isize, + uint32_t bmapi_flags) { xfs_mount_t *mp = ip->i_mount; xfs_fileoff_t offset_fsb; @@ -676,8 +685,21 @@ xfs_iomap_write_unwritten( */ nimaps = 1; error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb, - XFS_BMAPI_CONVERT, resblks, &imap, - &nimaps); + XFS_BMAPI_CONVERT | bmapi_flags, + resblks, &imap, &nimaps); + if (error == -ENOSR && (bmapi_flags & XFS_BMAPI_CONVERT_ONLY)) { + /* + * Nothing was mapped: the rest of the range starts + * with a hole or a delalloc extent. Nothing was + * changed either, but xfs_iext_count_extend() may + * have logged the inode, and cancelling a dirty + * transaction shuts the filesystem down. Commit it, + * as xfs_alloc_file_space() does on -ENOSR. + */ + error = xfs_trans_commit(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error ? error : -EIO; + } if (error) goto error_on_bmapi_transaction; @@ -1037,13 +1059,9 @@ xfs_direct_write_iomap_begin( return error; } -static DEFINE_IOMAP_ITER_NEXT(xfs_direct_write_iomap_next, +DEFINE_IOMAP_ITER_NEXT(xfs_direct_write_iomap_next, xfs_direct_write_iomap_begin); -const struct iomap_ops xfs_direct_write_iomap_ops = { - .iomap_next = xfs_direct_write_iomap_next, -}; - #ifdef CONFIG_XFS_RT /* * This is really simple. The space has already been reserved before taking the @@ -1087,12 +1105,9 @@ xfs_zoned_direct_write_iomap_begin( return 0; } -static DEFINE_IOMAP_ITER_NEXT(xfs_zoned_direct_write_iomap_next, +DEFINE_IOMAP_ITER_NEXT(xfs_zoned_direct_write_iomap_next, xfs_zoned_direct_write_iomap_begin); -const struct iomap_ops xfs_zoned_direct_write_iomap_ops = { - .iomap_next = xfs_zoned_direct_write_iomap_next, -}; #endif /* CONFIG_XFS_RT */ #ifdef DEBUG @@ -1275,13 +1290,9 @@ xfs_atomic_write_cow_iomap_begin( return error; } -static DEFINE_IOMAP_ITER_NEXT(xfs_atomic_write_cow_iomap_next, +DEFINE_IOMAP_ITER_NEXT(xfs_atomic_write_cow_iomap_next, xfs_atomic_write_cow_iomap_begin); -const struct iomap_ops xfs_atomic_write_cow_iomap_ops = { - .iomap_next = xfs_atomic_write_cow_iomap_next, -}; - static int xfs_dax_write_iomap_end( struct inode *inode, @@ -1302,13 +1313,9 @@ xfs_dax_write_iomap_end( return xfs_reflink_end_cow(ip, pos, written); } -static DEFINE_IOMAP_ITER_NEXT_END(xfs_dax_write_iomap_next, +DEFINE_IOMAP_ITER_NEXT_END(xfs_dax_write_iomap_next, xfs_direct_write_iomap_begin, xfs_dax_write_iomap_end); -const struct iomap_ops xfs_dax_write_iomap_ops = { - .iomap_next = xfs_dax_write_iomap_next, -}; - /* * Convert a hole to a delayed allocation. */ @@ -2191,13 +2198,9 @@ xfs_buffered_write_iomap_end( return 0; } -static DEFINE_IOMAP_ITER_NEXT_END(xfs_buffered_write_iomap_next, +DEFINE_IOMAP_ITER_NEXT_END(xfs_buffered_write_iomap_next, xfs_buffered_write_iomap_begin, xfs_buffered_write_iomap_end); -const struct iomap_ops xfs_buffered_write_iomap_ops = { - .iomap_next = xfs_buffered_write_iomap_next, -}; - int xfs_read_iomap_begin( struct inode *inode, @@ -2239,11 +2242,7 @@ xfs_read_iomap_begin( shared ? IOMAP_F_SHARED : 0, seq); } -static DEFINE_IOMAP_ITER_NEXT(xfs_read_iomap_next, xfs_read_iomap_begin); - -const struct iomap_ops xfs_read_iomap_ops = { - .iomap_next = xfs_read_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(xfs_read_iomap_next, xfs_read_iomap_begin); static int xfs_seek_iomap_begin( @@ -2329,11 +2328,7 @@ xfs_seek_iomap_begin( return error; } -static DEFINE_IOMAP_ITER_NEXT(xfs_seek_iomap_next, xfs_seek_iomap_begin); - -const struct iomap_ops xfs_seek_iomap_ops = { - .iomap_next = xfs_seek_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(xfs_seek_iomap_next, xfs_seek_iomap_begin); static int xfs_xattr_iomap_begin( @@ -2378,11 +2373,7 @@ xfs_xattr_iomap_begin( return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, IOMAP_F_XATTR, seq); } -static DEFINE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next, xfs_xattr_iomap_begin); - -const struct iomap_ops xfs_xattr_iomap_ops = { - .iomap_next = xfs_xattr_iomap_next, -}; +DEFINE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next, xfs_xattr_iomap_begin); int xfs_zero_range( @@ -2398,9 +2389,9 @@ xfs_zero_range( if (IS_DAX(inode)) return dax_zero_range(inode, pos, len, did_zero, - &xfs_dax_write_iomap_ops); + xfs_dax_write_iomap_next); return iomap_zero_range(inode, pos, len, did_zero, - &xfs_buffered_write_iomap_ops, &xfs_iomap_write_ops, + xfs_buffered_write_iomap_next, &xfs_iomap_write_ops, ac); } @@ -2415,8 +2406,8 @@ xfs_truncate_page( if (IS_DAX(inode)) return dax_truncate_page(inode, pos, did_zero, - &xfs_dax_write_iomap_ops); + xfs_dax_write_iomap_next); return iomap_truncate_page(inode, pos, did_zero, - &xfs_buffered_write_iomap_ops, &xfs_iomap_write_ops, + xfs_buffered_write_iomap_next, &xfs_iomap_write_ops, ac); } diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h index f2520a9b3a13e6..071fff6665070e 100644 --- a/fs/xfs/xfs_iomap.h +++ b/fs/xfs/xfs_iomap.h @@ -15,7 +15,8 @@ struct xfs_zone_alloc_ctx; int xfs_iomap_write_direct(struct xfs_inode *ip, xfs_fileoff_t offset_fsb, xfs_fileoff_t count_fsb, unsigned int flags, struct xfs_bmbt_irec *imap, u64 *sequence); -int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool); +int xfs_iomap_write_unwritten(struct xfs_inode *ip, xfs_off_t offset, + xfs_off_t count, bool update_isize, uint32_t bmapi_flags); xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip, xfs_fileoff_t end_fsb); @@ -69,14 +70,14 @@ int xfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t length, unsigned flags, struct iomap *iomap, struct iomap *srcmap); -extern const struct iomap_ops xfs_buffered_write_iomap_ops; -extern const struct iomap_ops xfs_direct_write_iomap_ops; -extern const struct iomap_ops xfs_zoned_direct_write_iomap_ops; -extern const struct iomap_ops xfs_read_iomap_ops; -extern const struct iomap_ops xfs_seek_iomap_ops; -extern const struct iomap_ops xfs_xattr_iomap_ops; -extern const struct iomap_ops xfs_dax_write_iomap_ops; -extern const struct iomap_ops xfs_atomic_write_cow_iomap_ops; +DECLARE_IOMAP_ITER_NEXT(xfs_buffered_write_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_direct_write_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_zoned_direct_write_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_read_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_seek_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_dax_write_iomap_next); +DECLARE_IOMAP_ITER_NEXT(xfs_atomic_write_cow_iomap_next); extern const struct iomap_write_ops xfs_iomap_write_ops; #endif /* __XFS_IOMAP_H__*/ diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index d307ec97fac820..6c5633db30daea 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1256,10 +1256,10 @@ xfs_vn_fiemap( if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR; error = iomap_fiemap(inode, fieinfo, start, length, - &xfs_xattr_iomap_ops); + xfs_xattr_iomap_next); } else { error = iomap_fiemap(inode, fieinfo, start, length, - &xfs_read_iomap_ops); + xfs_read_iomap_next); } xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED); diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c index ab385617003a20..065875c8b7dab8 100644 --- a/fs/xfs/xfs_pnfs.c +++ b/fs/xfs/xfs_pnfs.c @@ -110,7 +110,15 @@ xfs_fs_map_update_inode( ip->i_diflags |= XFS_DIFLAG_PREALLOC; xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - return xfs_trans_commit(tp); + error = xfs_trans_commit(tp); + if (error) + return error; + + /* + * Force the log so that the blocks handed out to the client are + * guaranteed to be present even after a server crash. + */ + return xfs_log_force_inode(ip, false, NULL); } /* @@ -134,6 +142,7 @@ xfs_fs_map_blocks( uint lock_flags; int error = 0; u64 seq; + bool update_inode = false; if (xfs_is_shutdown(mp)) return -EIO; @@ -159,18 +168,20 @@ xfs_fs_map_blocks( * similar to direct I/O, except that the synchronization is much more * complicated. See the comment near xfs_break_leased_layouts * for a detailed explanation. + * + * Take the invalidate lock as well, so that page faults cannot add + * delalloc extents to the range while it is being mapped. */ - xfs_ilock(ip, XFS_IOLOCK_EXCL); + xfs_ilock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); error = -EINVAL; limit = mp->m_super->s_maxbytes; if (!write) limit = max(limit, round_up(i_size_read(inode), inode->i_sb->s_blocksize)); - if (offset > limit) + if (offset < 0 || offset >= limit) goto out_unlock; - if (offset > limit - length) - length = limit - offset; + length = min_t(u64, length, limit - offset); error = filemap_write_and_wait(inode->i_mapping); if (error) @@ -221,28 +232,35 @@ xfs_fs_map_blocks( end_fsb - offset_fsb, 0, &imap, &seq); if (error) goto out_unlock; + update_inode = true; + } else { + xfs_iunlock(ip, lock_flags); /* - * Ensure the next transaction is committed synchronously so - * that the blocks allocated and handed out to the client are - * guaranteed to be present even after a server crash. + * Blocks past EOF that were allocated for buffered writes, such + * as speculative preallocation, can be freed by + * xfs_free_eofblocks() without breaking the layout unless the + * inode is marked as preallocated. Mark it before handing them + * out for writing, as for blocks allocated above. */ + if (write && !(ip->i_diflags & XFS_DIFLAG_PREALLOC) && + imap.br_startoff + imap.br_blockcount > + XFS_B_TO_FSB(mp, XFS_ISIZE(ip))) + update_inode = true; + } + + if (update_inode) { error = xfs_fs_map_update_inode(ip); - if (!error) - error = xfs_log_force_inode(ip); if (error) goto out_unlock; - - } else { - xfs_iunlock(ip, lock_flags); } - xfs_iunlock(ip, XFS_IOLOCK_EXCL); + xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0, 0, seq); *device_generation = mp->m_generation; return error; out_unlock: - xfs_iunlock(ip, XFS_IOLOCK_EXCL); + xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); return error; } @@ -277,10 +295,12 @@ xfs_pnfs_validate_isize( * converting any unwritten extents, flushing the disk cache and updating the * time stamps. * - * Note that we rely on the caller to always send us a timestamp update so that - * we always commit a transaction here. If that stops being true we will have - * to manually flush the cache here similar to what the fsync code path does - * for datasyncs on files that have no dirty metadata. + * Like fdatasync, a commit that only updates the timestamps does not force the + * log: they are logged as XFS_ILOG_TIMESTAMP and reach the disk with a later + * log write. The log is forced up to the last change that a datasync needs, + * such as the unwritten extent conversions or a new size, and the cache of the + * device holding the file data is flushed if that log force did not write an + * iclog itself. */ static int xfs_fs_commit_blocks( @@ -294,6 +314,7 @@ xfs_fs_commit_blocks( struct xfs_trans *tp; struct timespec64 now; bool update_isize = false; + int log_flushed = 0; int error, i; loff_t size; @@ -312,9 +333,7 @@ xfs_fs_commit_blocks( if (start > size) continue; - end = start + maps[i].length; - if (end > size) - end = size; + end = start + min_t(u64, maps[i].length, size - start); length = end - start; if (!length) @@ -328,7 +347,14 @@ xfs_fs_commit_blocks( (end - 1) >> PAGE_SHIFT); WARN_ON_ONCE(error); - error = xfs_iomap_write_unwritten(ip, start, length, false); + /* + * A client may only write to blocks that a layout handed out, + * and xfs_fs_map_blocks() allocates blocks for any hole in a + * write layout, so refuse to allocate blocks for a hole or a + * delalloc extent in the committed range. + */ + error = xfs_iomap_write_unwritten(ip, start, length, false, + XFS_BMAPI_CONVERT_ONLY); if (error) goto out_drop_iolock; } @@ -345,7 +371,8 @@ xfs_fs_commit_blocks( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + xfs_trans_log_inode(tp, ip, + update_isize ? XFS_ILOG_CORE : XFS_ILOG_TIMESTAMP); now = inode_set_ctime_current(inode); inode_set_atime_to_ts(inode, now); @@ -356,8 +383,13 @@ xfs_fs_commit_blocks( ip->i_disk_size = new_size; } - xfs_trans_set_sync(tp); error = xfs_trans_commit(tp); + if (error) + goto out_drop_iolock; + + error = xfs_log_force_inode(ip, true, &log_flushed); + if (!error && !log_flushed) + error = blkdev_issue_flush(xfs_inode_buftarg(ip)->bt_bdev); out_drop_iolock: xfs_iunlock(ip, XFS_IOLOCK_EXCL); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 104542b10d9e02..c5c796e2b83d18 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1724,7 +1724,7 @@ xfs_reflink_remap_prep( pos_out, len, remap_flags); else ret = dax_remap_file_range_prep(file_in, pos_in, file_out, - pos_out, len, remap_flags, &xfs_read_iomap_ops); + pos_out, len, remap_flags, xfs_read_iomap_next); if (ret || *len == 0) goto out_unlock; @@ -1919,10 +1919,10 @@ xfs_reflink_unshare( if (IS_DAX(inode)) error = dax_file_unshare(inode, offset, len, - &xfs_dax_write_iomap_ops); + xfs_dax_write_iomap_next); else error = iomap_file_unshare(inode, offset, len, - &xfs_buffered_write_iomap_ops, + xfs_buffered_write_iomap_next, &xfs_iomap_write_ops); if (error) goto out; diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c index e77917ac179d47..4a6a8c92c3a12e 100644 --- a/fs/xfs/xfs_sysfs.c +++ b/fs/xfs/xfs_sysfs.c @@ -906,7 +906,7 @@ xfs_mount_sysfs_init( "metadata", &mp->m_error_meta_kobj, xfs_error_meta_init); if (error) - goto out_remove_csum_dir; + goto out_remove_error_dir; return 0; diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 8f0c308f312f38..973e82e1e32300 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -72,7 +72,7 @@ xfs_trans_free( xfs_extent_busy_clear(&tp->t_busy, false); trace_xfs_trans_free(tp, _RET_IP_); - xfs_trans_clear_context(tp); + memalloc_nofs_restore(tp->t_pflags); if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT)) sb_end_intwrite(tp->t_mountp->m_super); xfs_trans_free_dqinfo(tp); @@ -220,7 +220,11 @@ __xfs_trans_alloc( tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL); if (!(flags & XFS_TRANS_NO_WRITECOUNT)) sb_start_intwrite(mp->m_super); - xfs_trans_set_context(tp); + /* + * Save NOFS state for xfs_trans_free() to restore. Only the + * transaction owner thread may touch tp->t_pflags. + */ + tp->t_pflags = memalloc_nofs_save(); tp->t_flags = flags; tp->t_mountp = mp; INIT_LIST_HEAD(&tp->t_items); @@ -1038,7 +1042,7 @@ xfs_trans_roll( * xfs_trans_free. Set it again here before doing memory * allocations. */ - xfs_trans_set_context(tp); + tp->t_pflags = memalloc_nofs_save(); if (error) return error; diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c index 54b70ed2922f52..cea5447a886da9 100644 --- a/fs/xfs/xfs_zone_gc.c +++ b/fs/xfs/xfs_zone_gc.c @@ -1018,7 +1018,7 @@ xfs_zone_gc_reset_zones( struct xfs_gc_bio *chunk; struct bio *bio; - xfs_log_force_inode(rtg_rmap(rtg)); + xfs_log_force_inode(rtg_rmap(rtg), false, NULL); next = rtg_group(rtg)->xg_next_reset; rtg_group(rtg)->xg_next_reset = NULL; diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 5b34849be7a2c7..319d9502ba5654 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -59,10 +59,6 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, static DEFINE_IOMAP_ITER_NEXT(zonefs_read_iomap_next, zonefs_read_iomap_begin); -static const struct iomap_ops zonefs_read_iomap_ops = { - .iomap_next = zonefs_read_iomap_next, -}; - static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) @@ -111,19 +107,15 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, static DEFINE_IOMAP_ITER_NEXT(zonefs_write_iomap_next, zonefs_write_iomap_begin); -static const struct iomap_ops zonefs_write_iomap_ops = { - .iomap_next = zonefs_write_iomap_next, -}; - static int zonefs_read_folio(struct file *unused, struct folio *folio) { - iomap_bio_read_folio(folio, &zonefs_read_iomap_ops); + iomap_bio_read_folio(folio, zonefs_read_iomap_next); return 0; } static void zonefs_readahead(struct readahead_control *rac) { - iomap_bio_readahead(rac, &zonefs_read_iomap_ops); + iomap_bio_readahead(rac, zonefs_read_iomap_next); } /* @@ -184,7 +176,7 @@ static int zonefs_swap_activate(struct swap_info_struct *sis, } return iomap_swapfile_activate(sis, swap_file, span, - &zonefs_read_iomap_ops); + zonefs_read_iomap_next); } const struct address_space_operations zonefs_file_aops = { @@ -314,7 +306,7 @@ static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf) /* Serialize against truncates */ filemap_invalidate_lock_shared(inode->i_mapping); - ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL); + ret = iomap_page_mkwrite(vmf, zonefs_write_iomap_next, NULL); filemap_invalidate_unlock_shared(inode->i_mapping); sb_end_pagefault(inode->i_sb); @@ -530,7 +522,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) * page invalidation. Overwrite that error code with EBUSY so that * the user can make sense of the error. */ - ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops, + ret = iomap_dio_rw(iocb, from, zonefs_write_iomap_next, &zonefs_write_dio_ops, 0, NULL, 0); if (ret == -ENOTBLK) ret = -EBUSY; @@ -580,7 +572,7 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, if (ret <= 0) goto inode_unlock; - ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops, + ret = iomap_file_buffered_write(iocb, from, zonefs_write_iomap_next, NULL, NULL); if (ret == -EIO) zonefs_io_error(inode, true); @@ -675,7 +667,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) goto inode_unlock; } file_accessed(iocb->ki_filp); - ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops, + ret = iomap_dio_rw(iocb, to, zonefs_read_iomap_next, &zonefs_read_dio_ops, 0, NULL, 0); } else { ret = generic_file_read_iter(iocb, to); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index f59b2de865e6d7..fad52a96d613b8 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -327,6 +327,7 @@ struct acpi_device_physical_node { struct device *dev; unsigned int node_id; bool put_online:1; + bool offline_pending:1; }; struct acpi_device_properties { diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index fbe1114e9a443d..3f4a180b48f3c0 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -350,8 +350,7 @@ struct mmu_gather { void tlb_flush_mmu(struct mmu_gather *tlb); static inline void __tlb_adjust_range(struct mmu_gather *tlb, - unsigned long address, - unsigned int range_size) + unsigned long address, unsigned long range_size) { tlb->start = min(tlb->start, address); tlb->end = max(tlb->end, address + range_size); diff --git a/include/crypto/mldsa.h b/include/crypto/mldsa.h index 3ef2676787c9ed..b156f166a14132 100644 --- a/include/crypto/mldsa.h +++ b/include/crypto/mldsa.h @@ -48,11 +48,13 @@ enum mldsa_alg { * Return: * * 0 if the signature is valid * * -EBADMSG if the signature and/or public key is malformed + * * -EINVAL if @alg is not a valid value * * -EKEYREJECTED if the signature is invalid but otherwise well-formed * * -ENOMEM if out of memory so the validity of the signature is unknown */ -int mldsa_verify(enum mldsa_alg alg, const u8 *sig, size_t sig_len, - const u8 *msg, size_t msg_len, const u8 *pk, size_t pk_len); +int __must_check mldsa_verify(enum mldsa_alg alg, const u8 *sig, size_t sig_len, + const u8 *msg, size_t msg_len, const u8 *pk, + size_t pk_len); #if IS_ENABLED(CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST) /* Internal function, exposed only for unit testing */ diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index e653bc7b1e40bc..97d35818f2ce89 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -60,7 +60,7 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test, { struct drm_driver *driver; - driver = devm_kzalloc(dev, sizeof(*driver), GFP_KERNEL); + driver = devm_kzalloc_obj(dev, *driver); KUNIT_ASSERT_NOT_NULL(test, driver); driver->driver_features = features; diff --git a/include/dt-bindings/sound/cs35l45.h b/include/dt-bindings/sound/cs35l45.h index 5cb77d48b0b8cc..4a7535a8161258 100644 --- a/include/dt-bindings/sound/cs35l45.h +++ b/include/dt-bindings/sound/cs35l45.h @@ -17,6 +17,51 @@ #define CS35L45_ASP_TX_HIZ_UNUSED 0x1 #define CS35L45_ASP_TX_HIZ_DISABLED 0x2 +/* + * cirrus,boost-bpe-inductor-release-mode + */ +#define CS35L45_BST_BPE_IL_RELEASE_MODE_INSTANT 0x0 +#define CS35L45_BST_BPE_IL_RELEASE_MODE_COUNTER 0x1 + +/* + * cirrus,boost-bpe-output-operating-mode + */ +#define CS35L45_BST_BPE_OUTPUT_MODE_BOTH 0x0 +#define CS35L45_BST_BPE_OUTPUT_MODE_VOLTAGE_ONLY 0x1 + +/* + * Boost BPE attack-rate selectors + */ +#define CS35L45_BST_BPE_ATTACK_RATE_INSTANT 0x0 +#define CS35L45_BST_BPE_ATTACK_RATE_250MA_PER_US 0x1 +#define CS35L45_BST_BPE_ATTACK_RATE_125MA_PER_US 0x2 +#define CS35L45_BST_BPE_ATTACK_RATE_62P5MA_PER_US 0x3 +#define CS35L45_BST_BPE_ATTACK_RATE_31P25MA_PER_US 0x4 +#define CS35L45_BST_BPE_ATTACK_RATE_15P625MA_PER_US 0x5 +#define CS35L45_BST_BPE_ATTACK_RATE_7P8125MA_PER_US 0x6 +#define CS35L45_BST_BPE_ATTACK_RATE_3P90625MA_PER_US 0x7 + +/* + * Boost BPE release-rate selectors + */ +#define CS35L45_BST_BPE_RELEASE_RATE_INSTANT 0x00 +#define CS35L45_BST_BPE_RELEASE_RATE_62P5MA_PER_US 0x01 +#define CS35L45_BST_BPE_RELEASE_RATE_31P25MA_PER_US 0x02 +#define CS35L45_BST_BPE_RELEASE_RATE_15P625MA_PER_US 0x03 +#define CS35L45_BST_BPE_RELEASE_RATE_7P8125MA_PER_US 0x04 +#define CS35L45_BST_BPE_RELEASE_RATE_3P90625MA_PER_US 0x05 +#define CS35L45_BST_BPE_RELEASE_RATE_1P953125MA_PER_US 0x06 +#define CS35L45_BST_BPE_RELEASE_RATE_0P976562MA_PER_US 0x07 +#define CS35L45_BST_BPE_RELEASE_RATE_0P488281MA_PER_US 0x08 +#define CS35L45_BST_BPE_RELEASE_RATE_0P244141MA_PER_US 0x09 +#define CS35L45_BST_BPE_RELEASE_RATE_0P122070MA_PER_US 0x0A +#define CS35L45_BST_BPE_RELEASE_RATE_0P061035MA_PER_US 0x0B +#define CS35L45_BST_BPE_RELEASE_RATE_0P030518MA_PER_US 0x0C +#define CS35L45_BST_BPE_RELEASE_RATE_0P015259MA_PER_US 0x0D +#define CS35L45_BST_BPE_RELEASE_RATE_0P007629MA_PER_US 0x0E +#define CS35L45_BST_BPE_RELEASE_RATE_0P003815MA_PER_US 0x0F +#define CS35L45_BST_BPE_RELEASE_RATE_0P001907MA_PER_US 0x10 + /* * cirrus,boost-low-power-mode * diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 104817e8d8977f..5c9dcf720f8464 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -76,15 +76,4 @@ static inline int amd_iommu_snp_disable(void) { return 0; } static inline bool amd_iommu_sev_tio_supported(void) { return false; } #endif -#ifdef CONFIG_AMD_IOMMU -int amd_iommu_enable_perfopt(struct pci_dev *pdev); -void amd_iommu_disable_perfopt(struct pci_dev *pdev); -#else -static inline int amd_iommu_enable_perfopt(struct pci_dev *pdev) -{ - return 0; -} -static inline void amd_iommu_disable_perfopt(struct pci_dev *pdev) { } -#endif - #endif /* _ASM_X86_AMD_IOMMU_H */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0c20102306329d..215753171cef0e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -678,7 +678,7 @@ enum { QUEUE_FLAG_HCTX_ACTIVE, /* at least one blk-mq hctx is active */ QUEUE_FLAG_SQ_SCHED, /* single queue style io dispatch */ QUEUE_FLAG_DISABLE_WBT_DEF, /* for sched to disable/enable wbt */ - QUEUE_FLAG_NO_ELV_SWITCH, /* can't switch elevator any more */ + QUEUE_FLAG_NO_ELV_SWITCH, /* a switch is running or disk is going away */ QUEUE_FLAG_QOS_ENABLED, /* qos is enabled */ QUEUE_FLAG_BIO_ISSUE_TIME, /* record bio->issue_time_ns */ QUEUE_FLAG_ZONED_QD1_WRITES, /* Limit zoned devices writes to QD=1 */ @@ -719,8 +719,6 @@ void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); ((q)->limits.features & BLK_FEAT_SKIP_TAGSET_QUIESCE) #define blk_queue_disable_wbt(q) \ test_bit(QUEUE_FLAG_DISABLE_WBT_DEF, &(q)->queue_flags) -#define blk_queue_no_elv_switch(q) \ - test_bit(QUEUE_FLAG_NO_ELV_SWITCH, &(q)->queue_flags) #define blk_queue_zoned_qd1_writes(q) \ test_bit(QUEUE_FLAG_ZONED_QD1_WRITES, &(q)->queue_flags) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index ff043678129358..fdbf638300fc51 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1752,12 +1752,22 @@ enum bpf_func_context { BPF_FUNC_CTX_CNT, }; +struct bpf_subprog_arg_info { + enum bpf_arg_type arg_type; + union { + u32 mem_size; + u32 btf_id; + }; +}; + struct bpf_func_info_aux { u16 linkage; bool unreliable; bool called[BPF_FUNC_CTX_CNT]; bool verified[BPF_FUNC_CTX_CNT]; bool called_with_pkt_ptrs; + /* what the callers of a global function are checked against */ + struct bpf_subprog_arg_info args[MAX_BPF_FUNC_REG_ARGS]; }; enum bpf_jit_poke_reason { @@ -1916,6 +1926,8 @@ struct bpf_prog_aux { const char *attach_func_name; struct bpf_prog **func; struct bpf_prog_aux *main_prog_aux; + /* main prog: there when the prog has timed may_goto */ + struct bpf_timed_may_goto __percpu *timed_may_goto; void *jit_data; /* JIT specific data. arch dependent */ struct bpf_jit_poke_descriptor *poke_tab; struct bpf_kfunc_desc_tab *kfunc_tab; @@ -3044,6 +3056,8 @@ static inline void bpf_map_dec_elem_count(struct bpf_map *map) this_cpu_dec(*map->elem_count); } +s64 bpf_map_sum_elem_count(const struct bpf_map *map); + extern int sysctl_unprivileged_bpf_disabled; bool bpf_token_capable(const struct bpf_token *token, int cap); diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 7baeb831281f38..b43eb97bcd4407 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -50,6 +50,13 @@ enum bpf_iter_state { BPF_ITER_STATE_DRAINED, }; +/* Bytes [off, off + size) of the stack of frame frameno. Nothing when size is 0. */ +struct bpf_stack_range { + u32 frameno; + s32 off; + u32 size; +}; + struct bpf_reg_state { /* Ordering of fields matters. See states_equal() */ enum bpf_reg_type type; @@ -83,6 +90,12 @@ struct bpf_reg_state { struct { /* for PTR_TO_MEM | PTR_TO_MEM_OR_NULL */ u32 mem_size; + /* + * bpf_dynptr_slice() and bpf_dynptr_slice_rdwr() return the + * buffer when the data is not contiguous: the register may + * point to this part of the stack. + */ + struct bpf_stack_range buf; }; /* For dynptr stack slots */ @@ -923,14 +936,6 @@ struct bpf_func_ptr { /* the subprog that a bpf_func_ptr pointed to was removed as dead code */ #define BPF_FUNC_PTR_DELETED ((u32)-1) -struct bpf_subprog_arg_info { - enum bpf_arg_type arg_type; - union { - u32 mem_size; - u32 btf_id; - }; -}; - enum priv_stack_mode { PRIV_STACK_UNKNOWN, NO_PRIV_STACK, @@ -964,6 +969,10 @@ struct bpf_subprog_info { bool is_cb: 1; bool is_async_cb: 1; bool is_exception_cb: 1; + /* bpf_loop() or bpf_for_each_map_elem() call it in a loop */ + bool is_loop_cb: 1; + /* BPF code, another helper or a kfunc call it */ + bool is_called: 1; bool args_cached: 1; /* true if the return value is passed in the R0:R2 register pair */ bool ret_reg_pair: 1; @@ -1099,6 +1108,8 @@ struct bpf_verifier_env { bool bypass_spec_v1; bool bypass_spec_v4; bool seen_direct_write; + /* a register may point to the stack and is not PTR_TO_STACK, see bpf_reg_state::buf */ + bool seen_stack_slice; /* a global function is verified for BPF_FUNC_CTX_NO_RCU_LOCK */ bool no_rcu_read_lock; bool seen_exception; @@ -1823,6 +1834,8 @@ struct bpf_call_arg_meta { struct arg_constant_desc arg_constant; /* The type of the dynptr that the kfunc writes through */ enum bpf_dynptr_type dynptr_write_type; + /* The buffer of bpf_dynptr_slice() or bpf_dynptr_slice_rdwr() */ + struct bpf_stack_range slice_buf; /* arg_{btf,btf_id,owning_ref} are used by kfunc-specific handling, * generally to pass info about user-defined local kptr types to later @@ -1900,6 +1913,7 @@ bpf_global_subprog_stack_access_bytes(struct bpf_verifier_env *env, int bpf_compute_subprog_arg_access(struct bpf_verifier_env *env); bool bpf_same_memory_origin(const struct bpf_reg_state *reg_a, const struct bpf_reg_state *reg_b); +void bpf_trim_pkt_range(struct bpf_reg_state *reg, s64 smax); int bpf_set_reg_range(struct bpf_verifier_env *env, struct bpf_reg_state *reg, struct cnum64 r64, struct cnum32 r32, u16 base, u16 step); bool bpf_reg_union_compatible(const struct bpf_reg_state *a, const struct bpf_reg_state *b); diff --git a/include/linux/btf.h b/include/linux/btf.h index a18254b7521bdd..87fad4076f0e9d 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -631,6 +631,7 @@ s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id); int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt, struct module *owner); struct btf_struct_meta *btf_find_struct_meta(const struct btf *btf, u32 btf_id); +bool btf_is_projection_type(const char *pname); bool btf_is_projection_of(const char *pname, const char *tname); bool btf_is_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf, const struct btf_type *t, enum bpf_prog_type prog_type, diff --git a/include/linux/can/can-ml.h b/include/linux/can/can-ml.h index 1e99fda2b3803b..cfefa4a385be9f 100644 --- a/include/linux/can/can-ml.h +++ b/include/linux/can/can-ml.h @@ -45,6 +45,7 @@ #include #include #include +#include /* exposed CAN device capabilities for network layer */ #define CAN_CAP_CC BIT(0) /* CAN CC aka Classical CAN */ @@ -59,6 +60,7 @@ enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_MAX }; struct can_dev_rcv_lists { + spinlock_t lock; /* protects the receive lists and entries */ struct hlist_head rx[RX_MAX]; struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ]; struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ]; @@ -81,6 +83,7 @@ static inline struct can_ml_priv *can_get_ml_priv(struct net_device *dev) static inline void can_set_ml_priv(struct net_device *dev, struct can_ml_priv *ml_priv) { + spin_lock_init(&ml_priv->dev_rcv_lists.lock); netdev_set_ml_priv(dev, ml_priv, ML_PRIV_CAN); } diff --git a/include/linux/can/core.h b/include/linux/can/core.h index 2de74c2b78b6c1..effb5c31ef4010 100644 --- a/include/linux/can/core.h +++ b/include/linux/can/core.h @@ -51,7 +51,7 @@ extern void can_proto_unregister(const struct can_proto *cp); int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *), - void *data, char *ident, struct sock *sk); + void *data, u64 ino, struct sock *sk); extern void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 6d0710d6f571db..346faddee02ebd 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -176,7 +176,7 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s return can_dropped_invalid_skb(dev, skb); invalid_skb: - kfree_skb(skb); + dev_kfree_skb_any(skb); dev->stats.tx_dropped++; return true; } diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h index 5d27843862fca4..87ace09c0d8bd7 100644 --- a/include/linux/can/skb.h +++ b/include/linux/can/skb.h @@ -78,12 +78,12 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb) nskb = skb_clone(skb, GFP_ATOMIC); if (unlikely(!nskb)) { - kfree_skb(skb); + dev_kfree_skb_any(skb); return NULL; } can_skb_set_owner(nskb, skb->sk); - consume_skb(skb); + dev_consume_skb_any(skb); return nskb; } diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 0ea7150dba7b4e..ea161a72d1c760 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -258,10 +258,13 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #endif /* __KERNEL__ */ -#if defined(CONFIG_CFI) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) +#if defined(CONFIG_CFI) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) && \ + !defined(MODULE) /* * Force a reference to the external symbol so the compiler generates - * __kcfi_typid. + * __kcfi_typid. Only vmlinux needs it, as that is where the assembly + * using the typeid lives; in a module it would only add a reference to + * the symbol, which fails modpost if the symbol is GPL-only. */ #define KCFI_REFERENCE(sym) __ADDRESSABLE(sym) #else diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index d3d0d9d02aa4a6..be1eaa43aeb00a 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -146,8 +146,11 @@ struct cpufreq_policy { /* Per policy boost supported flag. */ bool boost_supported; - /* Pending policy->min/max update for the driver */ - bool update_limits; + /* Force passing target frequency to the driver. */ + bool force_target; + + /* The policy has been suspended. */ + bool suspended; /* Cached frequency lookup from cpufreq_driver_resolve_freq. */ unsigned int cached_target_freq; diff --git a/include/linux/damon.h b/include/linux/damon.h index 63050eb2206a0f..380f9cf6ddd827 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -958,6 +958,16 @@ struct damon_ctx { /* @rnd_state: Per-ctx PRNG state for damon_rand(). */ struct rnd_state rnd_state; + /* + * number of regions after last merge. Read kdamond_split_regions() + * for more details. + */ + unsigned long last_nr_regions; + /* + * number of damon_split_some_regions() invocations for this context. + * Read damon_split_some_regions() for more details. + */ + unsigned long region_split_rotation; }; /* Get a random number in [@l, @r) using @ctx's lockless PRNG. */ diff --git a/include/linux/dax.h b/include/linux/dax.h index a3af0c63c61bdd..2e0797e4d40884 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -3,6 +3,7 @@ #define _LINUX_DAX_H #include +#include #include #include @@ -10,9 +11,6 @@ typedef unsigned long dax_entry_t; struct dax_device; struct gendisk; -struct iomap_ops; -struct iomap_iter; -struct iomap; enum dax_access_mode { DAX_ACCESS, @@ -200,11 +198,11 @@ static inline void dax_unlock_mapping_entry(struct address_space *mapping, #endif int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, - const struct iomap_ops *ops); + iomap_iter_next_fn next); int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, - const struct iomap_ops *ops); + iomap_iter_next_fn next); int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops); + iomap_iter_next_fn next); static inline bool dax_page_is_idle(struct page *page) { @@ -253,10 +251,10 @@ int dax_holder_notify_failure(struct dax_device *dax_dev, u64 off, u64 len, void dax_flush(struct dax_device *dax_dev, void *addr, size_t size); ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops); + iomap_iter_next_fn next); vm_fault_t dax_iomap_fault(struct vm_fault *vmf, unsigned int order, unsigned long *pfnp, int *errp, - const struct iomap_ops *ops); + iomap_iter_next_fn next); vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, unsigned int order, unsigned long pfn); int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); @@ -275,11 +273,11 @@ void dax_break_layout_final(struct inode *inode); int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same, - const struct iomap_ops *ops); + iomap_iter_next_fn next); int dax_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *len, unsigned int remap_flags, - const struct iomap_ops *ops); + iomap_iter_next_fn next); static inline bool dax_mapping(struct address_space *mapping) { return mapping->host && IS_DAX(mapping->host); diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 84b0cfe4ed0e78..aaa4ba7a129917 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -664,8 +664,7 @@ struct name_snapshot { struct qstr name; union shortname_store inline_name; }; -void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *); -bool try_take_dentry_name_snapshot(struct name_snapshot *, struct dentry *); +bool take_dentry_name_snapshot(struct name_snapshot *, struct dentry *); void release_dentry_name_snapshot(struct name_snapshot *); static inline struct dentry *d_first_child(const struct dentry *dentry) diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index fa2854fed1f289..15278416f88607 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -62,7 +62,7 @@ void trace_syscall_enter(struct pt_regs *regs); void trace_syscall_exit(struct pt_regs *regs, long ret); void syscall_enter_audit(struct pt_regs *regs); -static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned long work, +static __always_inline bool syscall_trace_enter(struct pt_regs *regs, unsigned long work, long syscall) { /* @@ -202,7 +202,7 @@ do { \ \ instrumentation_begin(); \ local_irq_enable(); \ - long _ret = syscall_enter_from_user_mode_work(regs, syscall); \ + bool _ret = syscall_enter_from_user_mode_work(regs, syscall); \ instrumentation_end(); \ \ _ret; \ diff --git a/include/linux/filter.h b/include/linux/filter.h index 98254742ae37a2..4f0cd67caccb80 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -758,9 +758,15 @@ struct bpf_prog_stats { struct u64_stats_sync syncp; } __aligned(2 * sizeof(u64)); +/* + * Per-cpu memory of a prog. All may_goto of one invocation of the prog use it. An invocation is + * one call from the kernel into the main prog, with the subprogs and sync callbacks it reaches. + */ struct bpf_timed_may_goto { u64 count; u64 timestamp; + /* the async callback that has set count and timestamp, see bpf_timed_may_goto_save() */ + void *owner; }; struct sk_filter { @@ -1328,6 +1334,8 @@ u64 bpf_arch_uaddress_limit(void); void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie); u64 arch_bpf_timed_may_goto(void); u64 bpf_check_timed_may_goto(struct bpf_timed_may_goto *); +void bpf_timed_may_goto_save(const struct bpf_prog *prog, struct bpf_timed_may_goto *saved); +void bpf_timed_may_goto_restore(const struct bpf_prog *prog, struct bpf_timed_may_goto *saved); bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id); static inline bool bpf_dump_raw_ok(const struct cred *cred) diff --git a/include/linux/fs.h b/include/linux/fs.h index 99caef43ff3c47..5b3a100aba77b0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -70,7 +70,8 @@ struct fsnotify_mark_connector; struct fs_context; struct fs_parameter_spec; struct file_kattr; -struct iomap_ops; +struct iomap_iter; +struct iomap; struct delegated_inode; extern void __init inode_init(void); @@ -2083,7 +2084,9 @@ int remap_verify_area(struct file *file, loff_t pos, loff_t len, bool write); int __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *len, unsigned int remap_flags, - const struct iomap_ops *dax_read_ops); + int (*dax_read_next)(const struct iomap_iter *iter, + struct iomap *iomap, + struct iomap *srcmap)); int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *count, unsigned int remap_flags); @@ -3332,7 +3335,7 @@ struct offset_ctx { unsigned long next_offset; }; -void simple_offset_init(struct offset_ctx *octx); +void simple_offset_init(struct offset_ctx *octx, struct inode *dir); int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, diff --git a/include/linux/fs/super_types.h b/include/linux/fs/super_types.h index 72f4288e16c526..6ce105fe8359c8 100644 --- a/include/linux/fs/super_types.h +++ b/include/linux/fs/super_types.h @@ -173,7 +173,7 @@ struct super_block { struct unicode_map *s_encoding; __u16 s_encoding_flags; #endif - struct hlist_head s_roots; /* alternate root dentries for NFS */ + struct hlist_head s_roots; /* alternate root dentries for NFS and ex-mountpoints */ spinlock_t s_roots_lock; struct mount *s_mounts; /* list of mounts; _not_ for fs use */ struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */ diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index bda798bc67bc52..a4a29b3650080f 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -135,7 +135,7 @@ int fsnotify_open_perm_and_set_mode(struct file *file); * fsnotify_file_area_perm - permission hook before access to file range */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, - const loff_t *ppos, size_t count) + const loff_t *ppos, u64 count) { /* * filesystem may be modified in the context of permission events @@ -213,7 +213,7 @@ static inline int fsnotify_open_perm_and_set_mode(struct file *file) } static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, - const loff_t *ppos, size_t count) + const loff_t *ppos, u64 count) { return 0; } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index a6d5c1a89cffa7..faf21564380d9f 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -323,7 +323,7 @@ struct fs_error_report { struct file_range { const struct path *path; loff_t pos; - size_t count; + u64 count; }; static inline const struct path *file_range_path(const struct file_range *range) @@ -946,12 +946,12 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } int fsnotify_pre_content(const struct path *path, const loff_t *ppos, - size_t count); + u64 count); #else static inline int fsnotify_pre_content(const struct path *path, - const loff_t *ppos, size_t count) + const loff_t *ppos, u64 count) { return 0; } diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index b041d9142d2b8a..1c2056a1a68b30 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -618,19 +618,21 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_JMP +#define FTRACE_JMP_BIT BIT(BITS_PER_LONG - 1) + static inline bool ftrace_is_jmp(unsigned long addr) { - return addr & 1; + return !(addr & FTRACE_JMP_BIT); } static inline unsigned long ftrace_jmp_set(unsigned long addr) { - return addr | 1UL; + return addr & ~FTRACE_JMP_BIT; } static inline unsigned long ftrace_jmp_get(unsigned long addr) { - return addr & ~1UL; + return addr | FTRACE_JMP_BIT; } #else static inline bool ftrace_is_jmp(unsigned long addr) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index c745f7ad22987f..fac05120ab7744 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -12,9 +12,8 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr, struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); bool huge_pmd_set_accessed(struct vm_fault *vmf); -int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, - pud_t *dst_pud, pud_t *src_pud, unsigned long addr, - struct vm_area_struct *vma); +int copy_huge_pud(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, + pud_t *dst_pud, pud_t *src_pud, unsigned long addr); #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 5029c72418631b..58f755e70e966d 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -121,10 +121,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool); void hugetlb_dup_vma_private(struct vm_area_struct *vma); void clear_vma_resv_huge_pages(struct vm_area_struct *vma); -int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, unsigned long new_addr, - unsigned long len); +unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len); int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *, struct vm_area_struct *); void unmap_hugepage_range(struct vm_area_struct *, @@ -338,11 +337,9 @@ static inline int copy_hugetlb_page_range(struct mm_struct *dst, return 0; } -static inline int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, - unsigned long new_addr, - unsigned long len) +static inline unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len) { BUG(); return 0; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 5254430844b2c0..78a1b7603a4f28 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -195,7 +195,7 @@ struct iomap_write_ops { }; /* - * Flags for iomap_begin / iomap_end. No flag implies a read. + * Flags for iomap_next. No flag implies a read. */ #define IOMAP_WRITE (1 << 0) /* writing, must allocate blocks */ #define IOMAP_ZERO (1 << 1) /* zeroing operation, may skip holes */ @@ -239,12 +239,6 @@ typedef int (*iomap_iter_end_fn)(struct inode *inode, loff_t pos, loff_t length, typedef int (*iomap_iter_next_fn)(const struct iomap_iter *iter, struct iomap *iomap, struct iomap *srcmap); -struct iomap_ops { - iomap_iter_begin_fn iomap_begin; - iomap_iter_end_fn iomap_end; - iomap_iter_next_fn iomap_next; -}; - /** * struct iomap_iter - Iterate through a range of a file * @inode: Set at the start of the iteration and should not change. @@ -256,7 +250,7 @@ struct iomap_ops { * incremental iter advance. * @status: Status of the most recent iteration. Zero on success or a negative * errno on error. - * @flags: Zero or more of the iomap_begin flags above. + * @flags: Zero or more of the iomap_iter_next flags above. * @iomap: Map describing the I/O iteration * @srcmap: Source map for COW operations */ @@ -273,7 +267,7 @@ struct iomap_iter { void *private; }; -int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); +int iomap_iter(struct iomap_iter *iter, iomap_iter_next_fn next); int iomap_iter_advance(struct iomap_iter *iter, u64 count); /** @@ -341,7 +335,7 @@ int iomap_iter_continue(const struct iomap_iter *iter, struct iomap *iomap, * @begin: callback that produces a mapping for the current position * @end: optional callback that finishes the previous mapping, or NULL * - * Inline helper that implements the common body of an ->iomap_next() + * Inline helper that implements the common body of an iomap_iter_next_fn * callback: it finishes the previous mapping via @end (if present), decides * via iomap_iter_continue() whether to keep going, and obtains the next * mapping via @begin. @@ -395,6 +389,14 @@ int name(const struct iomap_iter *iter, struct iomap *iomap, \ #define DEFINE_IOMAP_ITER_NEXT(name, begin_fn) \ DEFINE_IOMAP_ITER_NEXT_END(name, begin_fn, NULL) +/* + * Forward-declare an iomap_iter_next_fn callback generated by + * DEFINE_IOMAP_ITER_NEXT(). + */ +#define DECLARE_IOMAP_ITER_NEXT(name) \ +int name(const struct iomap_iter *iter, struct iomap *iomap, \ + struct iomap *srcmap) + /* * Return the file offset for the first unchanged block after a short write. * @@ -429,15 +431,15 @@ static inline bool iomap_want_unshare_iter(const struct iomap_iter *iter) } ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private); int iomap_fsverity_write(struct file *file, loff_t pos, size_t length, - const void *buf, const struct iomap_ops *ops, + const void *buf, iomap_iter_next_fn next, const struct iomap_write_ops *write_ops); -void iomap_read_folio(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx, void *private); -void iomap_readahead(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx, void *private); +void iomap_read_folio(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx, + void *private); +void iomap_readahead(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx, + void *private); bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count); struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len); bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); @@ -445,17 +447,17 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len); bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio); void iomap_folio_mark_uptodate(struct folio *folio); int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops); unsigned int iomap_fill_dirty_folios(struct iomap_iter *iter, loff_t *start, loff_t end, unsigned int *iomap_flags); int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, - bool *did_zero, const struct iomap_ops *ops, + bool *did_zero, iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private); int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops, + iomap_iter_next_fn next, const struct iomap_write_ops *write_ops, void *private); -vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops, +vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, iomap_iter_next_fn next, void *private); typedef void (*iomap_punch_t)(struct inode *inode, loff_t offset, loff_t length, struct iomap *iomap); @@ -464,13 +466,13 @@ void iomap_write_delalloc_release(struct inode *inode, loff_t start_byte, iomap_punch_t punch); int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, - u64 start, u64 len, const struct iomap_ops *ops); + u64 start, u64 len, iomap_iter_next_fn next); loff_t iomap_seek_hole(struct inode *inode, loff_t offset, - const struct iomap_ops *ops); + iomap_iter_next_fn next); loff_t iomap_seek_data(struct inode *inode, loff_t offset, - const struct iomap_ops *ops); + iomap_iter_next_fn next); sector_t iomap_bmap(struct address_space *mapping, sector_t bno, - const struct iomap_ops *ops); + iomap_iter_next_fn next); /* * Flags for iomap_ioend->io_flags. @@ -711,10 +713,10 @@ struct iomap_dio_ops { #define IOMAP_DIO_BOUNCE (1 << 4) ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops, const struct iomap_dio_ops *dops, + iomap_iter_next_fn next, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before); struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, - const struct iomap_ops *ops, const struct iomap_dio_ops *dops, + iomap_iter_next_fn next, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before); ssize_t iomap_dio_complete(struct iomap_dio *dio); void iomap_dio_bio_end_io(struct bio *bio); @@ -790,9 +792,9 @@ struct swap_info_struct; int iomap_swapfile_activate(struct swap_info_struct *sis, struct file *swap_file, sector_t *pagespan, - const struct iomap_ops *ops); + iomap_iter_next_fn next); #else -# define iomap_swapfile_activate(sis, swapfile, pagespan, ops) (-EIO) +# define iomap_swapfile_activate(sis, swapfile, pagespan, next) (-EIO) #endif /* CONFIG_SWAP */ extern struct bio_set iomap_ioend_bioset; @@ -806,25 +808,25 @@ void iomap_bio_submit_read_endio(const struct iomap_iter *iter, extern const struct iomap_read_ops iomap_bio_read_ops; static inline void iomap_bio_read_folio(struct folio *folio, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_read_folio_ctx ctx = { .ops = &iomap_bio_read_ops, .cur_folio = folio, }; - iomap_read_folio(ops, &ctx, NULL); + iomap_read_folio(next, &ctx, NULL); } static inline void iomap_bio_readahead(struct readahead_control *rac, - const struct iomap_ops *ops) + iomap_iter_next_fn next) { struct iomap_read_folio_ctx ctx = { .ops = &iomap_bio_read_ops, .rac = rac, }; - iomap_readahead(ops, &ctx, NULL); + iomap_readahead(next, &ctx, NULL); } #endif /* CONFIG_BLOCK */ diff --git a/include/linux/key.h b/include/linux/key.h index 115db6e6025429..420412aab9263a 100644 --- a/include/linux/key.h +++ b/include/linux/key.h @@ -37,6 +37,9 @@ struct net; #undef KEY_DEBUGGING +/* Maximum length of a key description, including the trailing NUL */ +#define KEY_MAX_DESC_SIZE 4096 + #define KEY_POS_VIEW 0x01000000 /* possessor can view a key's attributes */ #define KEY_POS_READ 0x02000000 /* possessor can read key payload / view keyring */ #define KEY_POS_WRITE 0x04000000 /* possessor can update key payload / add link to keyring */ @@ -216,8 +219,8 @@ struct key { kuid_t uid; kgid_t gid; key_perm_t perm; /* access permissions */ - unsigned short quotalen; /* length added to quota */ - unsigned short datalen; /* payload data length + unsigned int quotalen; /* length added to quota */ + unsigned int datalen; /* payload data length * - may not match RCU dereferenced payload * - payload should contain own length */ diff --git a/include/linux/ksm.h b/include/linux/ksm.h index d39d0d5483a23a..a0d358a1feb632 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -91,8 +91,8 @@ static inline void ksm_exit(struct mm_struct *mm) * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE, * but what if the vma was unmerged while the page was swapped out? */ -struct folio *ksm_might_need_to_copy(struct folio *folio, - struct vm_area_struct *vma, unsigned long addr); +struct folio *ksm_might_need_to_copy(struct folio *folio, struct page *page, + struct vm_area_struct *vma, unsigned long addr); void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); @@ -145,7 +145,7 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } static inline struct folio *ksm_might_need_to_copy(struct folio *folio, - struct vm_area_struct *vma, unsigned long addr) + struct page *page, struct vm_area_struct *vma, unsigned long addr) { return folio; } diff --git a/include/linux/memfd.h b/include/linux/memfd.h index c159e40e3f34a0..272479317cf10c 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -2,10 +2,19 @@ #ifndef __LINUX_MEMFD_H #define __LINUX_MEMFD_H +#include #include #define MEMFD_ANON_NAME "[memfd]" +static inline int memfd_check_seals_mode(unsigned int seals, umode_t old_mode, + umode_t new_mode) +{ + if ((seals & F_SEAL_EXEC) && ((old_mode ^ new_mode) & 0111)) + return -EPERM; + return 0; +} + #ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg); struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx); diff --git a/include/linux/mfd/cs42l43-regs.h b/include/linux/mfd/cs42l43-regs.h index 4c00ceae8b4610..924438655c630b 100644 --- a/include/linux/mfd/cs42l43-regs.h +++ b/include/linux/mfd/cs42l43-regs.h @@ -1204,6 +1204,8 @@ #define CS42L43B_ISRC2DEC3_INPUT1 0x0000C7A0 #define CS42L43B_ISRC2DEC4_INPUT1 0x0000C7B0 +#define CS42L43B_LOAD_DET_SEL 0x000170E8 + #define CS42L43B_FW_MISSION_CTRL_NEED_CONFIGS 0x00117E00 #define CS42L43B_FW_MISSION_CTRL_HAVE_CONFIGS 0x00117E04 #define CS42L43B_FW_MISSION_CTRL_PATCH_START_ADDR_REG 0x00117E08 diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index abb99371ff1344..84e9f6bdb7c140 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -789,8 +789,12 @@ struct mlx5_core_dev { u32 vsc_addr; struct mlx5_hv_vhca *hv_vhca; struct mlx5_hwmon *hwmon; - u64 num_block_tc; - u64 num_block_ipsec; + struct { + /* Protects the fields below. */ + spinlock_t lock; + u64 num_block_tc; + u64 num_block_ipsec; + } offload_block; #ifdef CONFIG_MLX5_MACSEC struct mlx5_macsec_fs *macsec_fs; /* MACsec notifier chain to sync MACsec core and IB database */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 9f167950926a15..6af3b7008f1ad1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -602,7 +602,7 @@ enum { #define VMA_LOCKED_MASK mk_vma_flags(VMA_LOCKED_BIT, VMA_LOCKONFAULT_BIT) /* These flags can be updated atomically via VMA/mmap read lock. */ -#define VM_ATOMIC_SET_ALLOWED VM_MAYBE_GUARD +#define VMA_ATOMIC_SET_ALLOWED mk_vma_flags(VMA_MAYBE_GUARD_BIT) /* Arch-specific flags to clear when updating VM flags on protection change */ #ifndef VM_ARCH_CLEAR @@ -987,22 +987,6 @@ static inline void vm_flags_reset(struct vm_area_struct *vma, vm_flags_init(vma, flags); } -static inline void vma_flags_reset_once(struct vm_area_struct *vma, - vma_flags_t *flags) -{ - const unsigned long word = flags->__vma_flags[0]; - - /* It is assumed only the first system word must be written once. */ - vma_flags_overwrite_word_once(&vma->flags, word); - /* The remainder can be copied normally. */ - if (NUM_VMA_FLAG_BITS > BITS_PER_LONG) { - unsigned long *dst = &vma->flags.__vma_flags[1]; - const unsigned long *src = &flags->__vma_flags[1]; - - bitmap_copy(dst, src, NUM_VMA_FLAG_BITS - BITS_PER_LONG); - } -} - static inline void vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags) { @@ -1039,48 +1023,6 @@ static inline void vm_flags_mod(struct vm_area_struct *vma, __vm_flags_mod(vma, set, clear); } -static __always_inline bool __vma_atomic_valid_flag(struct vm_area_struct *vma, - vma_flag_t bit) -{ - const vm_flags_t mask = BIT((__force int)bit); - - /* Only specific flags are permitted */ - if (WARN_ON_ONCE(!(mask & VM_ATOMIC_SET_ALLOWED))) - return false; - - return true; -} - -/* - * Set VMA flag atomically. Requires only VMA/mmap read lock. Only specific - * valid flags are allowed to do this. - */ -static __always_inline void vma_set_atomic_flag(struct vm_area_struct *vma, - vma_flag_t bit) -{ - unsigned long *bitmap = vma->flags.__vma_flags; - - vma_assert_stabilised(vma); - if (__vma_atomic_valid_flag(vma, bit)) - set_bit((__force int)bit, bitmap); -} - -/* - * Test for VMA flag atomically. Requires no locks. Only specific valid flags - * are allowed to do this. - * - * This is necessarily racey, so callers must ensure that serialisation is - * achieved through some other means, or that races are permissible. - */ -static __always_inline bool vma_test_atomic_flag(struct vm_area_struct *vma, - vma_flag_t bit) -{ - if (__vma_atomic_valid_flag(vma, bit)) - return test_bit((__force int)bit, &vma->vm_flags); - - return false; -} - /* Set an individual VMA flag in flags, non-atomically. */ static __always_inline void vma_flags_set_flag(vma_flags_t *flags, vma_flag_t bit) @@ -1302,34 +1244,24 @@ static __always_inline vma_flags_t vma_flags_diff_pair(const vma_flags_t *flags, return dst; } -/* Determine if flags and flags_other have precisely the same flags set. */ +/* + * Determine if flags and flags_other have precisely the same flags set, + * excluding atomic VMA flags. + */ static __always_inline bool vma_flags_same_pair(const vma_flags_t *flags, - const vma_flags_t *flags_other) + const vma_flags_t *flags_other) { - const unsigned long *bitmap = flags->__vma_flags; - const unsigned long *bitmap_other = flags_other->__vma_flags; - - return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); -} + vma_flags_t diff = vma_flags_diff_pair(flags, flags_other); -/* Determine if flags and flags_other have precisely the same flags set. */ -static __always_inline bool vma_flags_same_mask(const vma_flags_t *flags, - vma_flags_t flags_other) -{ - const unsigned long *bitmap = flags->__vma_flags; - const unsigned long *bitmap_other = flags_other.__vma_flags; + /* + * Atomic VMA flags may be set concurrently under the VMA read lock, so + * are disregarded for equality testing purposes. + */ + vma_flags_clear_mask(&diff, VMA_ATOMIC_SET_ALLOWED); - return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); + return vma_flags_empty(&diff); } -/* - * Helper macro to determine if only the specific flags are set, e.g.: - * - * if (vma_flags_same(&flags, VMA_WRITE_BIT) { ... } - */ -#define vma_flags_same(flags, ...) \ - vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__)) - /* * Test whether a specific flag in the VMA is set, e.g.: * @@ -1436,6 +1368,78 @@ static __always_inline void vma_clear_flags_mask(struct vm_area_struct *vma, #define vma_clear_flags(vma, ...) \ vma_clear_flags_mask(vma, mk_vma_flags(__VA_ARGS__)) +static __always_inline bool __vma_atomic_valid_flag(struct vm_area_struct *vma, + vma_flag_t bit) +{ + const vma_flags_t mask = VMA_ATOMIC_SET_ALLOWED; + + /* Is this flag allowed to be set atomically? */ + if (WARN_ON_ONCE(!vma_flags_test(&mask, bit))) + return false; + + return true; +} + +/* + * Set VMA flag atomically. Requires only VMA/mmap read lock. Only specific + * valid flags are allowed to do this. + */ +static __always_inline void vma_set_atomic_flag(struct vm_area_struct *vma, + vma_flag_t bit) +{ + unsigned long *bitmap = vma->flags.__vma_flags; + + vma_assert_stabilised(vma); + if (__vma_atomic_valid_flag(vma, bit)) + set_bit((__force int)bit, bitmap); +} + +/* + * Test for VMA flag atomically. Requires no locks. Only specific valid flags + * are allowed to do this. + * + * This is necessarily racey, so callers must ensure that serialisation is + * achieved through some other means, or that races are permissible. + */ +static __always_inline bool vma_test_atomic_flag(struct vm_area_struct *vma, + vma_flag_t bit) +{ + if (__vma_atomic_valid_flag(vma, bit)) + return test_bit((__force int)bit, &vma->vm_flags); + + return false; +} + +/* + * Overwrite the VMA's flags with new ones, preserving atomic VMA flags in the + * process. The write is done once and once only. + */ +static inline void vma_overwrite_flags(struct vm_area_struct *vma, + vma_flags_t new_flags) +{ + vma_flags_t atomic; + + vma_assert_write_locked(vma); + + /* + * Preserve the VMA's atomic flags, which are kept stable by the VMA + * write lock. + */ + atomic = vma_flags_and_mask(&vma->flags, VMA_ATOMIC_SET_ALLOWED); + vma_flags_clear_mask(&new_flags, VMA_ATOMIC_SET_ALLOWED); + vma_flags_set_mask(&new_flags, atomic); + + /* It is assumed only the first system word must be written once. */ + vma_flags_overwrite_word_once(&vma->flags, new_flags.__vma_flags[0]); + /* The remainder can be copied normally. */ + if (NUM_VMA_FLAG_BITS > BITS_PER_LONG) { + unsigned long *dst = &vma->flags.__vma_flags[1]; + const unsigned long *src = &new_flags.__vma_flags[1]; + + bitmap_copy(dst, src, NUM_VMA_FLAG_BITS - BITS_PER_LONG); + } +} + /* * Test whether a specific VMA flag is set in a VMA descriptor, e.g.: * diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 11b3ffef3966e1..9ccbbcbd7aca0d 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -17,6 +17,13 @@ extern int rcuwait_wake_up(struct rcuwait *w); #define MMAP_LOCK_INITIALIZER(name) \ .mmap_lock = __RWSEM_INITIALIZER((name).mmap_lock), +/* Tie a VMA iterator to mm write lock state at iterator initialisation. */ +struct vma_rcu_iter { + struct mm_struct *mm; + struct vma_iterator *vmi; + unsigned int mm_wr_seq; +}; + DECLARE_TRACEPOINT(mmap_lock_start_locking); DECLARE_TRACEPOINT(mmap_lock_acquire_returned); DECLARE_TRACEPOINT(mmap_lock_released); @@ -509,6 +516,16 @@ static inline void vma_mark_detached(struct vm_area_struct *vma) struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, unsigned long address); +static inline void vma_rcu_iter_init(struct vma_rcu_iter *rvmi, + struct mm_struct *mm, struct vma_iterator *vmi, + unsigned long addr) +{ + vma_iter_init(vmi, mm, addr); + rvmi->mm = mm; + rvmi->vmi = vmi; + rvmi->mm_wr_seq = UINT_MAX; /* Start odd so changed by default. */ +} + /* * Locks next vma pointed by the iterator. Confirms the locked vma has not * been modified and will retry under mmap_lock protection if modification @@ -516,9 +533,8 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, * Returns either a valid locked VMA, NULL if no more VMAs or -EINTR if the * process was interrupted. */ -struct vm_area_struct *lock_next_vma(struct mm_struct *mm, - struct vma_iterator *iter, - unsigned long address); +struct vm_area_struct *lock_next_vma(struct vma_rcu_iter *rvmi, + unsigned long from_addr); static inline void vma_assert_can_modify(struct vm_area_struct *vma) { diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index a11a44eef521e9..5db78e5761c5c3 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -483,7 +483,8 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) /* * This version of mmu_notifier_invalidate_range_start() avoids blocking, but it * can return an error if a notifier can't proceed without blocking, in which - * case you're not allowed to modify PTEs in the specified range. + * case you're not allowed to modify PTEs in the specified range or call + * mmu_notifier_invalidate_range_end(). * * This is mainly intended for OOM handling. */ diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index ecd1ebd49756cc..72ffb2959c4ff4 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1439,7 +1439,6 @@ struct zoneref { * * zonelist_zone() - Return the struct zone * for an entry in _zonerefs * zonelist_zone_idx() - Return the index of the zone for an entry - * zonelist_node_idx() - Return the index of the node for an entry */ struct zonelist { struct zoneref _zonerefs[MAX_ZONES_PER_ZONELIST + 1]; @@ -1855,7 +1854,8 @@ extern struct zone *next_zone(struct zone *zone); static inline struct zone *zonelist_zone(struct zoneref *zoneref) { - return zoneref->zone; + /* Memory hotplug rewrites zonelists in place. */ + return READ_ONCE(zoneref->zone); } static inline int zonelist_zone_idx(const struct zoneref *zoneref) @@ -1863,11 +1863,6 @@ static inline int zonelist_zone_idx(const struct zoneref *zoneref) return zoneref->zone_idx; } -static inline int zonelist_node_idx(const struct zoneref *zoneref) -{ - return zone_to_nid(zoneref->zone); -} - struct zoneref *__next_zones_zonelist(struct zoneref *z, enum zone_type highest_zoneidx, const nodemask_t *nodes); diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h index 4d55827e970537..2d506966357b25 100644 --- a/include/linux/mroute_base.h +++ b/include/linux/mroute_base.h @@ -119,6 +119,7 @@ enum { * @mfc_flags: entry flags * @expires: unresolved entry expire time * @unresolved: unresolved cached skbs + * @nl_queries: queued RTM_GETROUTE requests waiting for resolution * @last_assert: time of last assert * @minvif: minimum VIF id * @maxvif: maximum VIF id @@ -141,6 +142,7 @@ struct mr_mfc { struct { unsigned long expires; struct sk_buff_head unresolved; + struct sk_buff_head nl_queries; } unres; struct { unsigned long last_assert; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index c0ae442c4344b6..435be7880d7e59 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -440,6 +440,7 @@ enum { NAPI_STATE_HAS_NOTIFIER, /* Napi has an IRQ notifier */ NAPI_STATE_THREADED_BUSY_POLL, /* The threaded NAPI poller will busy poll */ NAPI_STATE_PERCPU, /* NAPI handler is run per-CPU - incompatible with threaded mode */ + NAPI_STATE_DISABLED, /* NAPI is disabled */ }; enum { @@ -456,6 +457,7 @@ enum { NAPIF_STATE_HAS_NOTIFIER = BIT(NAPI_STATE_HAS_NOTIFIER), NAPIF_STATE_THREADED_BUSY_POLL = BIT(NAPI_STATE_THREADED_BUSY_POLL), NAPIF_STATE_PERCPU = BIT(NAPI_STATE_PERCPU), + NAPIF_STATE_DISABLED = BIT(NAPI_STATE_DISABLED), }; enum gro_result { diff --git a/include/linux/netdevice_xmit.h b/include/linux/netdevice_xmit.h index cc232508e695ee..286ae5a6101e8c 100644 --- a/include/linux/netdevice_xmit.h +++ b/include/linux/netdevice_xmit.h @@ -18,8 +18,8 @@ struct netdev_xmit { u8 sched_mirred_nest; struct net_device *sched_mirred_dev[MIRRED_NEST_LIMIT]; #endif -#if IS_ENABLED(CONFIG_NF_DUP_NETDEV) - u8 nf_dup_skb_recursion; +#if IS_ENABLED(CONFIG_NETFILTER) + u8 nf_xmit_skb_recursion; #endif }; diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 416c6f39f31ddb..6e1b0332f2de41 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -120,6 +120,7 @@ struct nfs_client { #define NFS_SP4_MACH_CRED_COMMIT 6 /* COMMIT */ #define NFS_SP4_MACH_CRED_PNFS_CLEANUP 7 /* LAYOUTRETURN */ wait_queue_head_t cl_lock_waitq; + bool cl_may_notify_lock; #endif /* CONFIG_NFS_V4 */ /* Our own IP address, as a null-terminated string. diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h index c8e227a3f9e22b..e8b2bf0da5eded 100644 --- a/include/linux/ns_common.h +++ b/include/linux/ns_common.h @@ -9,7 +9,8 @@ #include bool is_current_namespace(struct ns_common *ns); -int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum); +int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, + int inum, u64 ns_id); void __ns_common_free(struct ns_common *ns); struct ns_common *__must_check ns_owner(struct ns_common *ns); @@ -41,17 +42,18 @@ static __always_inline bool is_ns_init_id(const struct ns_common *ns) .ns_owner_root.ns_list_head = LIST_HEAD_INIT(nsname.ns.ns_owner_root.ns_list_head), \ } -#define ns_common_init(__ns) \ - __ns_common_init(to_ns_common(__ns), \ - ns_common_type(__ns), \ - to_ns_operations(__ns), \ - (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0)) +#define ns_common_init(__ns) \ + __ns_common_init(to_ns_common(__ns), \ + ns_common_type(__ns), \ + to_ns_operations(__ns), \ + (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0), \ + (((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0)) #define ns_common_init_inum(__ns, __inum) \ __ns_common_init(to_ns_common(__ns), \ ns_common_type(__ns), \ to_ns_operations(__ns), \ - __inum) + __inum, 0) #define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns))) diff --git a/include/linux/nstree.h b/include/linux/nstree.h index 5b64d457288198..eeed713804be96 100644 --- a/include/linux/nstree.h +++ b/include/linux/nstree.h @@ -41,43 +41,22 @@ void ns_tree_node_del(struct ns_tree_node *node, struct ns_tree_root *root); struct user_namespace *: &(user_ns_tree), \ struct uts_namespace *: &(uts_ns_tree)) -#define ns_tree_gen_id(__ns) \ - __ns_tree_gen_id(to_ns_common(__ns), \ - (((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0)) - u64 __ns_tree_gen_id(struct ns_common *ns, u64 id); -void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree_root *ns_tree); +void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree); void __ns_tree_remove(struct ns_common *ns, struct ns_tree_root *ns_tree); struct ns_common *ns_tree_lookup_rcu(u64 ns_id, int ns_type); struct ns_common *__ns_tree_adjoined_rcu(struct ns_common *ns, struct ns_tree_root *ns_tree, bool previous); -static inline void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree, u64 id) -{ - __ns_tree_gen_id(ns, id); - __ns_tree_add_raw(ns, ns_tree); -} - -/** - * ns_tree_add_raw - Add a namespace to a namespace - * @__ns: Namespace to add - * - * This function adds a namespace to the appropriate namespace tree - * without assigning a id. - */ -#define ns_tree_add_raw(__ns) __ns_tree_add_raw(to_ns_common(__ns), to_ns_tree(__ns)) - /** * ns_tree_add - Add a namespace to a namespace tree * @__ns: Namespace to add * - * This function assigns a new id to the namespace and adds it to the - * appropriate namespace tree and list. + * This function adds a namespace to the appropriate namespace tree and + * list. The namespace must already have been assigned an id. */ -#define ns_tree_add(__ns) \ - __ns_tree_add(to_ns_common(__ns), to_ns_tree(__ns), \ - (((__ns) == ns_init_ns(__ns)) ? ns_init_id(__ns) : 0)) +#define ns_tree_add(__ns) __ns_tree_add(to_ns_common(__ns), to_ns_tree(__ns)) /** * ns_tree_remove - Remove a namespace from a namespace tree diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index eb3f7bab498ca9..e1e11500df097a 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -304,9 +304,8 @@ struct perf_event_pmu_context; #define PERF_PMU_CAP_AUX_OUTPUT 0x0080 #define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0100 #define PERF_PMU_CAP_AUX_PAUSE 0x0200 -#define PERF_PMU_CAP_AUX_PREFER_LARGE 0x0400 -#define PERF_PMU_CAP_MEDIATED_VPMU 0x0800 -#define PERF_PMU_CAP_SIMD_REGS 0x1000 +#define PERF_PMU_CAP_MEDIATED_VPMU 0x0400 +#define PERF_PMU_CAP_SIMD_REGS 0x0800 /** * pmu::scope @@ -1814,6 +1813,12 @@ extern unsigned long perf_misc_flags(struct perf_event *event, struct pt_regs *r extern unsigned long perf_instruction_pointer(struct perf_event *event, struct pt_regs *regs); +extern void perf_sample_regs_user(struct perf_regs *regs_user, + struct pt_regs *regs); +extern void perf_sample_regs_intr(struct perf_regs *regs_intr, + struct pt_regs *regs, + bool exclude_kernel); + #ifndef perf_arch_misc_flags # define perf_arch_misc_flags(regs) \ (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 6402930282e592..95f6236c5c5b9e 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -4,9 +4,7 @@ #define PIPE_DEF_BUFFERS 16 -#define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */ #define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */ -#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */ #define PIPE_BUF_FLAG_PACKET 0x08 /* read() as a packet */ #define PIPE_BUF_FLAG_CAN_MERGE 0x10 /* can merge buffers */ #define PIPE_BUF_FLAG_WHOLE 0x20 /* read() must return entire buffer or error */ @@ -127,16 +125,6 @@ struct pipe_inode_info { #endif }; -/* - * Note on the nesting of these functions: - * - * ->confirm() - * ->try_steal() - * - * That is, ->try_steal() must be called on a confirmed buffer. See below for - * the meaning of each operation. Also see the kerneldoc in fs/pipe.c for the - * pipe and generic variants of these hooks. - */ struct pipe_buf_operations { /* * ->confirm() verifies that the data in the pipe buffer is there @@ -153,16 +141,6 @@ struct pipe_buf_operations { */ void (*release)(struct pipe_inode_info *, struct pipe_buffer *); - /* - * Attempt to take ownership of the pipe buffer and its contents. - * ->try_steal() returns %true for success, in which case the contents - * of the pipe (the buf->page) is locked and now completely owned by the - * caller. The page may then be transferred to a different mapping, the - * most often used case is insertion into different file address space - * cache. - */ - bool (*try_steal)(struct pipe_inode_info *, struct pipe_buffer *); - /* * Get a reference to the pipe buffer. */ @@ -304,19 +282,6 @@ static inline int pipe_buf_confirm(struct pipe_inode_info *pipe, return buf->ops->confirm(pipe, buf); } -/** - * pipe_buf_try_steal - attempt to take ownership of a pipe_buffer - * @pipe: the pipe that the buffer belongs to - * @buf: the buffer to attempt to steal - */ -static inline bool pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - if (!buf->ops->try_steal) - return false; - return buf->ops->try_steal(pipe, buf); -} - /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ #define PIPE_SIZE PAGE_SIZE @@ -335,11 +300,8 @@ void free_pipe_info(struct pipe_inode_info *); /* Generic pipe buffer ops functions */ bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *); -bool generic_pipe_buf_try_steal(struct pipe_inode_info *, struct pipe_buffer *); void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *); -extern const struct pipe_buf_operations nosteal_pipe_buf_ops; - unsigned long account_pipe_buffers(struct user_struct *user, unsigned long old, unsigned long new); bool too_many_pipe_buffers_soft(unsigned long user_bufs); diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 36a27a91059587..56f6ab1855d389 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -496,7 +496,7 @@ int ptp_get_vclocks_index(int pclock_index, int **vclock_index); * @hwtstamp: timestamp * @vclock_index: phc index of ptp vclock. * - * Returns: converted timestamp, or 0 on error. + * Returns: converted timestamp, or 0 if @hwtstamp is zero or on error. */ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index); #else diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h index 0c64ca674e778a..7346efc85d436f 100644 --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -40,6 +40,7 @@ void __quota_error(struct super_block *sb, const char *func, /* * declaration of quota_function calls in kernel. */ +void dquot_cache_init(void); int dquot_initialize(struct inode *inode); bool dquot_initialize_needed(struct inode *inode); void dquot_drop(struct inode *inode); @@ -206,6 +207,10 @@ static inline int sb_has_quota_active(struct super_block *sb, int type) return 0; } +static inline void dquot_cache_init(void) +{ +} + static inline int dquot_initialize(struct inode *inode) { return 0; diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 8f3034881f8a2e..7e888decc9fafd 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -10,6 +10,7 @@ * Author: Mark Brown */ +#include #include #include #include @@ -1464,19 +1465,19 @@ struct reg_field { unsigned int id_offset; }; -#define REG_FIELD(_reg, _lsb, _msb) { \ - .reg = _reg, \ - .lsb = _lsb, \ - .msb = _msb, \ - } +#define REG_FIELD(_reg, _lsb, _msb) ((struct reg_field){ \ + .reg = _reg, \ + .lsb = _lsb, \ + .msb = _msb, \ + }) -#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \ - .reg = _reg, \ - .lsb = _lsb, \ - .msb = _msb, \ - .id_size = _size, \ - .id_offset = _offset, \ - } +#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) ((struct reg_field){ \ + .reg = _reg, \ + .lsb = _lsb, \ + .msb = _msb, \ + .id_size = _size, \ + .id_offset = _offset, \ + }) #define REG_FIELD_GENMASK(_reg_field) GENMASK(_reg_field.msb, _reg_field.lsb) @@ -1586,6 +1587,29 @@ regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id, NULL, false, true); } +static inline int +regmap_reg_field_read(struct regmap *regmap, struct reg_field field, + unsigned int *val) +{ + int ret; + + ret = regmap_read(regmap, field.reg, val); + if (ret) + return ret; + + *val = field_get(REG_FIELD_GENMASK(field), *val); + + return ret; +} + +static inline int +regmap_reg_field_write(struct regmap *regmap, struct reg_field field, + unsigned int val) +{ + return regmap_update_bits(regmap, field.reg, + REG_FIELD_GENMASK(field), val << field.lsb); +} + /** * struct regmap_irq_type - IRQ type definitions. * @@ -2074,6 +2098,22 @@ regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id, return -EINVAL; } +static inline int +regmap_reg_field_read(struct regmap *regmap, struct reg_field field, + unsigned int *val) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +static inline int +regmap_reg_field_write(struct regmap *regmap, struct reg_field field, + unsigned int val) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + static inline int regmap_get_val_bytes(struct regmap *map) { WARN_ONCE(1, "regmap API is disabled"); diff --git a/include/linux/regulator/mt6363-regulator.h b/include/linux/regulator/mt6363-regulator.h index 60761f01d3ad8b..e0d2c01827a7ae 100644 --- a/include/linux/regulator/mt6363-regulator.h +++ b/include/linux/regulator/mt6363-regulator.h @@ -138,6 +138,7 @@ #define MT6363_RG_LDO_VSRAM_APU_VOSEL_ADDR 0x1b17 #define MT6363_RG_LDO_VSRAM_APU_VOSEL_MASK GENMASK(6, 0) #define MT6363_RG_VEMC_VOCAL_ADDR 0x1b1b +#define MT6363_RG_VEMC_VOCAL_1_ADDR 0x1b1c #define MT6363_RG_VEMC_VOCAL_MASK GENMASK(3, 0) #define MT6363_RG_LDO_VCN15_ADDR 0x1b57 #define MT6363_RG_LDO_VCN15_EN_BIT 0 diff --git a/include/linux/sched.h b/include/linux/sched.h index 1c93da75226e32..e4f6323d785554 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -881,6 +881,8 @@ struct task_struct { */ int recent_used_cpu; int wake_cpu; + /* CPU charged while is_blocked && in_iowait. */ + int iowait_cpu; int prio; int static_prio; diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index a7c7a96a7cbf90..f89b4b15113323 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -117,8 +117,14 @@ extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts); #ifdef CONFIG_SHMEM +bool shmem_file(struct file *file); bool shmem_mapping(const struct address_space *mapping); #else +static inline bool shmem_file(struct file *file) +{ + return false; +} + static inline bool shmem_mapping(const struct address_space *mapping) { return false; @@ -193,15 +199,6 @@ static inline struct page *shmem_read_mapping_page( mapping_gfp_mask(mapping)); } -static inline bool shmem_file(struct file *file) -{ - if (!IS_ENABLED(CONFIG_SHMEM)) - return false; - if (!file || !file->f_mapping) - return false; - return shmem_mapping(file->f_mapping); -} - /* Must be called with inode lock taken exclusive. */ static inline void shmem_freeze(struct inode *inode, bool freeze) { diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 1a8a465a5650dc..d4dcaeb83e2b63 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -118,6 +119,41 @@ void cleanup_srcu_struct(struct srcu_struct *ssp); void synchronize_srcu(struct srcu_struct *ssp); void synchronize_srcu_atomic(struct srcu_struct *ssp); +/** + * list_splice_init_srcu - splice an SRCU-protected list into an existing list + * @list: the SRCU-protected list to splice + * @head: the place in the existing list to splice the first list into + * @ssp: the srcu_struct that readers of @list use + * + * Like list_splice_init_rcu(), but wait for the SRCU readers of @list + * instead of RCU ones, so that none of them can follow a next pointer + * onto @head. + * + * Note that this function blocks, and that the caller must prevent any + * other updates to @list. + */ +static inline void list_splice_init_srcu(struct list_head *list, + struct list_head *head, + struct srcu_struct *ssp) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + struct list_head *next = head->next; + + if (list_empty(list)) + return; + + INIT_LIST_HEAD_RCU(list); + synchronize_srcu(ssp); + ASSERT_EXCLUSIVE_ACCESS(*first); + ASSERT_EXCLUSIVE_ACCESS(*last); + + last->next = next; + rcu_assign_pointer(list_next_rcu(head), first); + first->prev = head; + next->prev = last; +} + #define SRCU_GET_STATE_COMPLETED 0x1 /** diff --git a/include/linux/ssb/ssb_driver_chipcommon.h b/include/linux/ssb/ssb_driver_chipcommon.h index c44335b011be99..17345729eb7339 100644 --- a/include/linux/ssb/ssb_driver_chipcommon.h +++ b/include/linux/ssb/ssb_driver_chipcommon.h @@ -9,7 +9,7 @@ * gpio interface, extbus, and support for serial and parallel flashes. * * Copyright 2005, Broadcom Corporation - * Copyright 2006, Michael Buesch + * Copyright 2006, Michael Buesch */ /** ChipCommon core registers. **/ diff --git a/include/linux/stat.h b/include/linux/stat.h index 9c570913286224..4f0a4af7a0671d 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -69,4 +69,7 @@ struct kstat { /* file attribute values */ #define STATX_ATTR_CHANGE_MONOTONIC 0x8000000000000000ULL /* version monotonically increases */ +/* mask of STATX_ATTR_* bits that is private to the kernel */ +#define STATX_ATTR_INTERNAL_MASK (STATX_ATTR_CHANGE_MONOTONIC) + #endif diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index 0dbdf3722537f9..dbaad8b5f181ce 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -230,6 +230,10 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, bool (*fnmatch)(const struct rpc_task *, const void *), const void *data); +unsigned long rpc_cancel_tasks_and_disconnect(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data); void rpc_execute(struct rpc_task *); void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *); void rpc_init_wait_queue(struct rpc_wait_queue *, const char *); diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h index 005730623f3be6..780eaa157a9f6c 100644 --- a/include/linux/sunrpc/xprt.h +++ b/include/linux/sunrpc/xprt.h @@ -112,6 +112,11 @@ struct rpc_rqst { ktime_t rq_xtime; /* transmit time stamp */ int rq_ntrans; + bool rq_disconnect_on_release; + /* + * protected by rq_xprt->transport_lock + * while the request is active + */ #if defined(CONFIG_SUNRPC_BACKCHANNEL) struct lwq_node rq_bc_list; /* Callback service list */ diff --git a/include/linux/tcp.h b/include/linux/tcp.h index d18f7bc1e5d0f7..e6b79cf4798f49 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -179,6 +179,9 @@ struct tcp_request_sock { u8 ao_rcv_next; bool used_tcp_ao; #endif +#if IS_ENABLED(CONFIG_IPV6) + __be32 syn_flowlabel; +#endif }; #define tcp_rsk(ptr) container_of_const(ptr, struct tcp_request_sock, req.req) @@ -363,6 +366,7 @@ struct tcp_sock { u32 rcv_rtt_last_tsecr; u32 delivered_ecn_bytes[3]; u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ + u32 rcv_collapse_credit; /* memory queued since last collapse */ struct { u32 rtt_us; u32 seq; @@ -618,13 +622,13 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog) static inline void tcp_move_syn(struct tcp_sock *tp, struct request_sock *req) { - tp->saved_syn = req->saved_syn; - req->saved_syn = NULL; + tp->saved_syn = unrcu_pointer(req->saved_syn); + RCU_INIT_POINTER(req->saved_syn, NULL); } static inline void tcp_saved_syn_free(struct tcp_sock *tp) { - kfree(tp->saved_syn); + kfree_rcu(tp->saved_syn, rcu); tp->saved_syn = NULL; } diff --git a/include/linux/uio.h b/include/linux/uio.h index 638c1116e912e7..76e4103b9ec423 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -373,11 +373,11 @@ struct iovec *iovec_from_user(const struct iovec __user *uvector, unsigned long nr_segs, unsigned long fast_segs, struct iovec *fast_iov, bool compat); ssize_t import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i); + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i); ssize_t __import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i, bool compat); + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i, bool compat); int import_ubuf(int type, void __user *buf, size_t len, struct iov_iter *i); static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index a14b8a9ffb7b1c..dff9a5c9a0dfa4 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -153,8 +153,6 @@ extern int mrwprotect_range(struct userfaultfd_ctx *ctx, unsigned long start, unsigned long len, bool enable_rwp); /* move_pages */ -void double_pt_lock(spinlock_t *ptl1, spinlock_t *ptl2); -void double_pt_unlock(spinlock_t *ptl1, spinlock_t *ptl2); int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pmd_t dst_pmdval, struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, @@ -168,22 +166,12 @@ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, } /* - * Never enable huge pmd sharing on some uffd registered vmas: - * - * - VM_UFFD_WP and VM_UFFD_RWP VMAs, because the write protect / access - * tracking information is per pgtable entry. - * - * - VM_UFFD_MINOR VMAs, because otherwise we would never get minor faults for - * VMAs which share huge pmds. (If you have two mappings to the same - * underlying pages, and fault in the non-UFFD-registered one with a write, - * with huge pmd sharing this would *also* setup the second UFFD-registered - * mapping, and we'd not get minor faults.) + * Never enable huge pmd sharing on userfaultfd registered VMAs, because + * userfaultfd state can be tracked per VMA or per page table entry. */ static inline bool uffd_disable_huge_pmd_share(struct vm_area_struct *vma) { - return vma_test_any_mask(vma, - mk_vma_flags_from_masks(VMA_UFFD_WP, VMA_UFFD_RWP, - VMA_UFFD_MINOR)); + return vma->vm_userfaultfd_ctx.ctx; } /* diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index d6466f96cdd00c..fc9667176f23c0 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -5,7 +5,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -48,6 +51,145 @@ static inline int virtio_net_hdr_set_proto(struct sk_buff *skb, return 0; } +/* TODO: nothing virtio specific here, move to ip.h */ + +/* + * Pull and minimally validate the IPv4 header at @nhoff. + * Returns the header and stores the transport header offset in + * @thoff, or NULL if truncated or malformed. The whole header, + * options included, is guaranteed linear on return. + */ +static inline struct iphdr *virtio_net_ip4_parse(struct sk_buff *skb, + unsigned int nhoff, + unsigned int *thoff) +{ + unsigned int ihl; + struct iphdr *iph; + + if (!pskb_may_pull(skb, nhoff + sizeof(struct iphdr))) + return NULL; + + iph = (struct iphdr *)(skb->data + nhoff); + if (iph->version != 4 || + iph->ihl < sizeof(struct iphdr) / sizeof(u32)) + return NULL; + + ihl = iph->ihl * sizeof(u32); + *thoff = nhoff + ihl; + /* Pull the options as well: the transport header offset + * returned above must be within the linear data. iph goes + * stale across the pull. + */ + if (!pskb_may_pull(skb, nhoff + ihl)) + return NULL; + + return (struct iphdr *)(skb->data + nhoff); +} + +/* Where does the L3 header start, and what protocol is it? + * With @has_eth, the frame starts with an Ethernet header, possibly + * followed by VLAN tags. Otherwise the L3 header starts at the network + * header offset the caller set up. + * + * The caller knows how the frame will be parsed later: the device + * type does not tell, as tun can change it with TUNSETLINK. + */ +static inline bool +virtio_net_l3_start(struct sk_buff *skb, bool has_eth, int *nhoff, + __be16 *proto) +{ + if (has_eth) { + __be16 h_proto; + + if (!pskb_may_pull(skb, ETH_HLEN)) + return false; + h_proto = eth_hdr(skb)->h_proto; + /* skb->protocol is a sender claim, and parts of the + * stack parse the packet per it: when it disagrees with + * the frame we do not know which view the packet will + * be parsed as, so do not validate. + */ + if (skb->protocol && skb->protocol != h_proto) + return false; + *nhoff = ETH_HLEN; + *proto = h_proto; + if (eth_type_vlan(*proto)) { + *proto = __vlan_get_protocol(skb, *proto, nhoff); + if (!*proto) + return false; + } + } else { + const struct iphdr *iph; + + *nhoff = skb_network_offset(skb); + /* An unset network header shows up as an offset + * outside of the packet. + */ + if (*nhoff < 0 || (unsigned int)*nhoff >= skb->len) + return false; + /* No L2 header to cross-check with: take the protocol + * from the IP version at the network header. + */ + if (!pskb_may_pull(skb, *nhoff + 1)) + return false; + iph = (const struct iphdr *)(skb->data + *nhoff); + if (iph->version == 4) + *proto = htons(ETH_P_IP); + else if (iph->version == 6) + *proto = htons(ETH_P_IPV6); + else + return false; + if (skb->protocol && skb->protocol != *proto) + return false; + } + return true; +} + +/* Walk the L3 header at @nhoff: where does its transport header + * start, and which protocol is it? Returns false if the header + * is truncated, malformed or fragmented. + */ +static inline bool +virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto, + unsigned int *thoff, int *ip_proto) +{ + if (proto == htons(ETH_P_IP)) { + const struct iphdr *iph = virtio_net_ip4_parse(skb, nhoff, thoff); + + if (!iph || ip_is_fragment(iph)) + return false; + *ip_proto = iph->protocol; + return true; + } + + if (proto == htons(ETH_P_IPV6)) { + const struct ipv6hdr *iph; + int flags = IP6_FH_F_AUTH; + + if (!pskb_may_pull(skb, nhoff + sizeof(*iph))) + return false; + iph = (const void *)(skb->data + nhoff); + if (iph->version != 6) + return false; + *thoff = nhoff + sizeof(*iph); + *ip_proto = iph->nexthdr; + if (*ip_proto != IPPROTO_TCP && *ip_proto != IPPROTO_UDP) { + *thoff = nhoff; + /* Find the transport header behind any + * extension headers. IP6_FH_F_AUTH stops + * the walk at AH, so frames with AH are rejected. + */ + *ip_proto = ipv6_find_hdr(skb, thoff, -1, NULL, + &flags); + if (*ip_proto < 0 || flags & IP6_FH_F_FRAG) + return false; + } + return true; + } + + return false; +} + static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb, const struct virtio_net_hdr *hdr, bool little_endian, u8 hdr_gso_type) @@ -282,9 +424,33 @@ static inline unsigned int virtio_l3min(bool is_ipv6) return is_ipv6 ? sizeof(struct ipv6hdr) : sizeof(struct iphdr); } +/* Do the tunnel offsets match the outer headers in the frame? + * The L3 header the tunnel claims must be the one the frame + * carries, with UDP following it at @outer_th. + */ +static inline bool +virtio_net_tnl_offsets_ok(struct sk_buff *skb, bool has_eth, bool outer_isv6, + unsigned int outer_th) +{ + int nhoff; + __be16 proto; + unsigned int thoff; + int ip_proto; + + if (!virtio_net_l3_start(skb, has_eth, &nhoff, &proto)) + return false; + if (outer_isv6 != (proto == htons(ETH_P_IPV6))) + return false; + if (!virtio_net_l4_start(skb, nhoff, proto, &thoff, &ip_proto)) + return false; + + return ip_proto == IPPROTO_UDP && outer_th == thoff; +} + static inline int virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, const struct virtio_net_hdr_v1_hash_tunnel *vhdr, + bool has_eth, bool tnl_hdr_negotiated, bool tnl_csum_negotiated, bool little_endian) @@ -338,6 +504,9 @@ virtio_net_hdr_tnl_to_skb(struct sk_buff *skb, if (ret) return ret; + if (!virtio_net_tnl_offsets_ok(skb, has_eth, outer_isv6, outer_th)) + return -EINVAL; + /* In case of USO, the inner protocol is still unknown and * `inner_isv6` is just a guess, additional parsing is needed. * The previous validation ensures that accessing an ipv4 inner @@ -453,7 +622,10 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb, if (feature_hdrlen && hdr->hdr_len) __virtio_net_set_tnl_hdrlen(skb, hdr); - if (skb->protocol == htons(ETH_P_IPV6)) + /* skb->protocol is the VLAN protocol when the tag is in the + * packet data. + */ + if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) hdr->gso_type |= VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6; else hdr->gso_type |= VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4; @@ -461,8 +633,11 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb, if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM) hdr->flags |= VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM; - inner_nh = skb->inner_network_header - skb_headroom(skb); - outer_th = skb->transport_header - skb_headroom(skb); + /* Like csum_start, the offsets must account for a VLAN tag + * the caller inserts in the frame. + */ + inner_nh = skb->inner_network_header - skb_headroom(skb) + vlan_hlen; + outer_th = skb->transport_header - skb_headroom(skb) + vlan_hlen; vhdr->inner_nh_offset = cpu_to_le16(inner_nh); vhdr->outer_th_offset = cpu_to_le16(outer_th); return 0; diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index fd7a034b827817..067e8a3b38d0d5 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h @@ -120,7 +120,7 @@ void _p9_debug(enum p9_debug_flags level, const char *func, * @P9_RCREATE: response with file access information * @P9_TREAD: request to transfer data from a file or directory * @P9_RREAD: response with data requested - * @P9_TWRITE: reuqest to transfer data to a file + * @P9_TWRITE: request to transfer data to a file * @P9_RWRITE: response with out much data was transferred to file * @P9_TCLUNK: forget about a handle to an entity within the file system * @P9_RCLUNK: response when server has forgotten about the handle @@ -581,6 +581,7 @@ struct p9_rstatfs { struct p9_fcall { u32 size; u8 id; + bool zc; u16 tag; size_t offset; @@ -588,7 +589,6 @@ struct p9_fcall { struct kmem_cache *cache; u8 *sdata; - bool zc; }; int p9_errstr2errno(char *errstr, int len); diff --git a/include/net/9p/client.h b/include/net/9p/client.h index 55c6cb54bd2548..e4e5cb102fb189 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -97,7 +97,7 @@ struct p9_req_t { * @proto_version: 9P protocol version to use * @trans_mod: module API instantiated with this client * @status: connection state - * @trans: tranport instance state and API + * @trans: transport instance state and API * @fids: All active FID handles * @reqs: All active requests. * @name: node name used as client id @@ -122,8 +122,12 @@ struct p9_client { struct { u16 port; bool privport; - } tcp; +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) + struct { + u32 port; + } vsock; +#endif } trans_opts; struct idr fids; @@ -151,13 +155,13 @@ struct p9_client_opts { * struct p9_fd_opts - per-transport options for fd transport * @rfd: file descriptor for reading (trans=fd) * @wfd: file descriptor for writing (trans=fd) - * @port: port to connect to (trans=tcp) + * @port: port to connect to (trans=tcp, trans=vsock) * @privport: port is privileged */ struct p9_fd_opts { int rfd; int wfd; - u16 port; + u32 port; bool privport; }; @@ -270,7 +274,7 @@ struct p9_dirent { struct p9_qid qid; u64 d_off; unsigned char d_type; - char d_name[256]; + char *d_name; }; struct iov_iter; diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index aa04dec4515341..6fb713d5e4be98 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -680,6 +680,45 @@ enum conn_reasons { CONN_REASON_ISO_CONNECT, }; +enum { + HCI_CONN_AUTH_PEND, + HCI_CONN_ENCRYPT_PEND, + HCI_CONN_RSWITCH_PEND, + HCI_CONN_MODE_CHANGE_PEND, + HCI_CONN_SCO_SETUP_PEND, + HCI_CONN_MGMT_CONNECTED, + HCI_CONN_SSP_ENABLED, + HCI_CONN_SC_ENABLED, + HCI_CONN_AES_CCM, + HCI_CONN_POWER_SAVE, + HCI_CONN_FLUSH_KEY, + HCI_CONN_ENCRYPT, + HCI_CONN_AUTH, + HCI_CONN_SECURE, + HCI_CONN_FIPS, + HCI_CONN_STK_ENCRYPT, + HCI_CONN_AUTH_INITIATOR, + HCI_CONN_DROP, + HCI_CONN_CANCEL, + HCI_CONN_PARAM_REMOVAL_PEND, + HCI_CONN_NEW_LINK_KEY, + HCI_CONN_SCANNING, + HCI_CONN_AUTH_FAILURE, + HCI_CONN_PER_ADV, + HCI_CONN_BIG_CREATED, + HCI_CONN_CREATE, + HCI_CONN_CREATE_CIS, + HCI_CONN_CREATE_BIG_SYNC, + HCI_CONN_BIG_SYNC, + HCI_CONN_BIG_SYNC_FAILED, + HCI_CONN_CREATE_PA_SYNC, + HCI_CONN_PA_SYNC, + HCI_CONN_PA_SYNC_FAILED, + HCI_CONN_ENC_KEY_SIZE_PEND, + + __HCI_CONN_NUM_FLAGS, +}; + struct hci_conn { struct list_head list; @@ -750,7 +789,7 @@ struct hci_conn { __u8 num_bis; __u8 bis[HCI_MAX_ISO_BIS]; - unsigned long flags; + DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS); enum conn_reasons conn_reason; __u8 abort_reason; @@ -980,55 +1019,18 @@ u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, bool name_known); void hci_inquiry_cache_flush(struct hci_dev *hdev); -/* ----- HCI Connections ----- */ -enum { - HCI_CONN_AUTH_PEND, - HCI_CONN_ENCRYPT_PEND, - HCI_CONN_RSWITCH_PEND, - HCI_CONN_MODE_CHANGE_PEND, - HCI_CONN_SCO_SETUP_PEND, - HCI_CONN_MGMT_CONNECTED, - HCI_CONN_SSP_ENABLED, - HCI_CONN_SC_ENABLED, - HCI_CONN_AES_CCM, - HCI_CONN_POWER_SAVE, - HCI_CONN_FLUSH_KEY, - HCI_CONN_ENCRYPT, - HCI_CONN_AUTH, - HCI_CONN_SECURE, - HCI_CONN_FIPS, - HCI_CONN_STK_ENCRYPT, - HCI_CONN_AUTH_INITIATOR, - HCI_CONN_DROP, - HCI_CONN_CANCEL, - HCI_CONN_PARAM_REMOVAL_PEND, - HCI_CONN_NEW_LINK_KEY, - HCI_CONN_SCANNING, - HCI_CONN_AUTH_FAILURE, - HCI_CONN_PER_ADV, - HCI_CONN_BIG_CREATED, - HCI_CONN_CREATE, - HCI_CONN_CREATE_CIS, - HCI_CONN_CREATE_BIG_SYNC, - HCI_CONN_BIG_SYNC, - HCI_CONN_BIG_SYNC_FAILED, - HCI_CONN_CREATE_PA_SYNC, - HCI_CONN_PA_SYNC, - HCI_CONN_PA_SYNC_FAILED, -}; - static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) { struct hci_dev *hdev = conn->hdev; return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && - test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); + test_bit(HCI_CONN_SSP_ENABLED, conn->flags); } static inline bool hci_conn_sc_enabled(struct hci_conn *conn) { struct hci_dev *hdev = conn->hdev; return hci_dev_test_flag(hdev, HCI_SC_ENABLED) && - test_bit(HCI_CONN_SC_ENABLED, &conn->flags); + test_bit(HCI_CONN_SC_ENABLED, conn->flags); } static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) @@ -1219,7 +1221,7 @@ hci_conn_hash_lookup_create_pa_sync(struct hci_dev *hdev) if (c->type != PA_LINK) continue; - if (!test_bit(HCI_CONN_CREATE_PA_SYNC, &c->flags)) + if (!test_bit(HCI_CONN_CREATE_PA_SYNC, c->flags)) continue; rcu_read_unlock(); @@ -1245,7 +1247,7 @@ hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev, list_for_each_entry_rcu(c, &h->list, list) { if (bacmp(&c->dst, ba) || c->type != BIS_LINK || - !test_bit(HCI_CONN_PER_ADV, &c->flags)) + !test_bit(HCI_CONN_PER_ADV, c->flags)) continue; if (c->iso_qos.bcast.big == big && @@ -1502,7 +1504,7 @@ hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big) list_for_each_entry_rcu(c, &h->list, list) { if (c->type != BIS_LINK || - !test_bit(HCI_CONN_PA_SYNC, &c->flags)) + !test_bit(HCI_CONN_PA_SYNC, c->flags)) continue; if (c->iso_qos.bcast.big == big) { @@ -1580,7 +1582,7 @@ static inline void hci_conn_hash_list_flag(struct hci_dev *hdev, rcu_read_lock(); list_for_each_entry_rcu(c, &h->list, list) { - if (c->type == type && test_bit(flag, &c->flags)) + if (c->type == type && test_bit(flag, c->flags)) func(c, data); } @@ -1598,7 +1600,7 @@ static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev) list_for_each_entry_rcu(c, &h->list, list) { if (c->type == LE_LINK && c->state == BT_CONNECT && - !test_bit(HCI_CONN_SCANNING, &c->flags)) { + !test_bit(HCI_CONN_SCANNING, c->flags)) { rcu_read_unlock(); return c; } @@ -1619,7 +1621,7 @@ static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) list_for_each_entry_rcu(c, &h->list, list) { if (c->type == LE_LINK && c->state == BT_CONNECT && - test_bit(HCI_CONN_SCANNING, &c->flags)) { + test_bit(HCI_CONN_SCANNING, c->flags)) { rcu_read_unlock(); return true; } @@ -2239,10 +2241,10 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) struct hci_cb *cb; __u8 encrypt; - if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) + if (test_bit(HCI_CONN_ENCRYPT_PEND, conn->flags)) return; - encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; + encrypt = test_bit(HCI_CONN_ENCRYPT, conn->flags) ? 0x01 : 0x00; mutex_lock(&hci_cb_list_lock); list_for_each_entry(cb, &hci_cb_list, list) { @@ -2271,9 +2273,9 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) return; } - if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + if (!test_bit(HCI_CONN_ENCRYPT, conn->flags)) encrypt = 0x00; - else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) + else if (test_bit(HCI_CONN_AES_CCM, conn->flags)) encrypt = 0x02; else encrypt = 0x01; @@ -2365,8 +2367,6 @@ static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev, static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, u16 to_multiplier) { - u16 max_latency; - if (min > max) { BT_WARN("min %d > max %d", min, max); return -EINVAL; @@ -2392,19 +2392,14 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, return -EINVAL; } - if (max >= to_multiplier * 8) { - BT_WARN("max %d >= to_multiplier %d * 8", max, to_multiplier); - return -EINVAL; - } - - max_latency = (to_multiplier * 4 / max) - 1; if (latency > 499) { BT_WARN("latency %d > 499", latency); return -EINVAL; } - if (latency > max_latency) { - BT_WARN("latency %d > max_latency %d", latency, max_latency); + if ((latency + 1) * max >= to_multiplier * 4) { + BT_WARN("latency %d, max %d and timeout %d are incompatible", + latency, max, to_multiplier); return -EINVAL; } @@ -2426,6 +2421,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb); void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); +void *hci_sent_cmd_data_len(struct hci_dev *hdev, __u16 opcode, + size_t *len); void *hci_recv_event_data(struct hci_dev *hdev, __u8 event); u32 hci_conn_get_phy(struct hci_conn *conn); diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 54eddcdd341f98..2a05bda8ab4321 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -756,6 +756,7 @@ enum { FLAG_DEFER_SETUP, FLAG_LE_CONN_REQ_SENT, FLAG_ECRED_CONN_REQ_SENT, + FLAG_ECRED_RECONF_REQ_SENT, FLAG_PENDING_SECURITY, FLAG_HOLD_HCI_CONN, FLAG_DEL, diff --git a/include/net/cipso_ipv4.h b/include/net/cipso_ipv4.h index d6780d7903f4a1..b41672221797b2 100644 --- a/include/net/cipso_ipv4.h +++ b/include/net/cipso_ipv4.h @@ -185,12 +185,12 @@ int cipso_v4_sock_setattr(struct sock *sk, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr, bool sk_locked); -void cipso_v4_sock_delattr(struct sock *sk); +int cipso_v4_sock_delattr(struct sock *sk); int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr); int cipso_v4_req_setattr(struct request_sock *req, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr); -void cipso_v4_req_delattr(struct request_sock *req); +int cipso_v4_req_delattr(struct request_sock *req); int cipso_v4_skbuff_setattr(struct sk_buff *skb, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr); @@ -221,8 +221,9 @@ static inline int cipso_v4_sock_setattr(struct sock *sk, return -ENOSYS; } -static inline void cipso_v4_sock_delattr(struct sock *sk) +static inline int cipso_v4_sock_delattr(struct sock *sk) { + return 0; } static inline int cipso_v4_sock_getattr(struct sock *sk, @@ -238,9 +239,9 @@ static inline int cipso_v4_req_setattr(struct request_sock *req, return -ENOSYS; } -static inline void cipso_v4_req_delattr(struct request_sock *req) +static inline int cipso_v4_req_delattr(struct request_sock *req) { - return; + return 0; } static inline int cipso_v4_skbuff_setattr(struct sk_buff *skb, diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h index f45d1e3163f007..02fffbb8509987 100644 --- a/include/net/dst_metadata.h +++ b/include/net/dst_metadata.h @@ -116,6 +116,8 @@ static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a, return memcmp(&a->u.port_info, &b->u.port_info, sizeof(a->u.port_info)); case METADATA_IP_TUNNEL: + if (a->u.tun_info.options_len != b->u.tun_info.options_len) + return 1; return memcmp(&a->u.tun_info, &b->u.tun_info, sizeof(a->u.tun_info) + a->u.tun_info.options_len); diff --git a/include/net/espintcp.h b/include/net/espintcp.h index c70efd704b6d5d..7cad3c6822df95 100644 --- a/include/net/espintcp.h +++ b/include/net/espintcp.h @@ -34,7 +34,8 @@ static inline struct espintcp_ctx *espintcp_getctx(const struct sock *sk) { const struct inet_connection_sock *icsk = inet_csk(sk); - /* RCU is only needed for diag */ - return (__force void *)icsk->icsk_ulp_data; + /* pairs with smp_wmb() in espintcp_init_sk() */ + smp_rmb(); + return (__force void *)READ_ONCE(icsk->icsk_ulp_data); } #endif diff --git a/include/net/gro.h b/include/net/gro.h index 2300b6da05b272..7a19d448645636 100644 --- a/include/net/gro.h +++ b/include/net/gro.h @@ -160,9 +160,19 @@ static inline bool skb_gro_may_pull(const struct sk_buff *skb, return likely(hlen <= NAPI_GRO_CB(skb)->frag0_len); } +/* A pull can release the page fragment frag0 points to, or reallocate + * skb->head, even if it fails. Call this before the pull, to make sure later + * skb_gro_header() and skb_gro_network_header() calls no longer use frag0. + */ +static inline void skb_gro_frag0_invalidate(struct sk_buff *skb) +{ + NAPI_GRO_CB(skb)->frag0_len = 0; +} + static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, unsigned int offset) { + skb_gro_frag0_invalidate(skb); if (!pskb_may_pull(skb, hlen)) return NULL; @@ -351,7 +361,13 @@ static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb, void *ptr; size_t plen = grc->offset + sizeof(u16); - if (!grc->delta) + /* Once merged, grc->offset can not be trusted: the frags or head + * of this skb now belong to the GRO packet, or skb->data was pulled + * past the headers before adding it to a frag_list. + * skb_gro_receive_list() does not merge packets with an adjusted + * checksum, other merged packets do not use their headers anymore. + */ + if (!grc->delta || NAPI_GRO_CB(skb)->same_flow) return; ptr = skb_gro_header(skb, plen, grc->offset); diff --git a/include/net/gso.h b/include/net/gso.h index fe3260b381d4ed..119fc4c170e164 100644 --- a/include/net/gso.h +++ b/include/net/gso.h @@ -19,7 +19,7 @@ struct skb_gso_cb { int encap_level; __wsum csum; __u16 csum_start; - /* Number of IPv4/IPv6 GSO handler entries for this packet. */ + /* Number of IPv4/IPv6/NSH GSO handler entries for this packet. */ u8 recursion_counter; /* Max MSS segs per output skb, 0 = no limit */ u8 max_segs; diff --git a/include/net/inet_common.h b/include/net/inet_common.h index 3d747896be300a..0f088a213c3811 100644 --- a/include/net/inet_common.h +++ b/include/net/inet_common.h @@ -25,7 +25,7 @@ int inet_release(struct socket *sock); int inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len, int flags); int __inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, - int addr_len, int flags, int is_sendmsg); + int addr_len, int flags, bool defer_connect); int inet_dgram_connect(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len, int flags); int inet_accept(struct socket *sock, struct socket *newsock, diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h index b02d2472b003ec..c1fb419a9cf03a 100644 --- a/include/net/inet_frag.h +++ b/include/net/inet_frag.h @@ -79,6 +79,7 @@ struct frag_v6_compare_key { * @tstamp_type: stamp has a mono delivery time (EDT) * @flags: fragment queue flags * @max_size: maximum received fragment size + * @truesize: sum of the truesize of queued fragments * @fqdir: pointer to struct fqdir * @rcu: rcu head for freeing deferall */ @@ -100,6 +101,7 @@ struct inet_frag_queue { u8 tstamp_type; __u8 flags; u16 max_size; + unsigned int truesize; struct fqdir *fqdir; struct rcu_head rcu; }; @@ -172,6 +174,13 @@ extern const u8 ip_frag_ecn_table[16]; #define IPFRAG_DUP 1 #define IPFRAG_OVERLAP 2 #define IPFRAG_MIXED_SECPATH 3 +#define IPFRAG_TOOBIG 4 + +/* Max sum of the truesize of fragments in a queue. This keeps the sums + * done in inet_frag_reasm_prepare() and inet_frag_reasm_finish() well + * below INT_MAX. Legitimate traffic stays far below this limit. + */ +#define INET_FRAG_MAX_TRUESIZE (INT_MAX / 2) int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, int offset, int end); void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, diff --git a/include/net/iw_handler.h b/include/net/iw_handler.h index b80e474cb0aa92..632618d9ff937d 100644 --- a/include/net/iw_handler.h +++ b/include/net/iw_handler.h @@ -201,6 +201,8 @@ #include /* IOCTL user space API */ #include +struct net; + /***************************** VERSION *****************************/ /* * This constant is used to know which version of the driver API is @@ -411,10 +413,10 @@ struct iw_spy_data { void wireless_send_event(struct net_device *dev, unsigned int cmd, union iwreq_data *wrqu, const char *extra); #ifdef CONFIG_WEXT_CORE -/* flush all previous wext events - if work is done from netdev notifiers */ -void wireless_nlevent_flush(void); +/* Flush previous wext events in this netns from netdev notifiers. */ +void wireless_nlevent_flush(struct net *net); #else -static inline void wireless_nlevent_flush(void) {} +static inline void wireless_nlevent_flush(struct net *net) {} #endif /* We may need a function to send a stream of events to user space. diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h index a452b7828ce4ec..249b1c7407881f 100644 --- a/include/net/libeth/xsk.h +++ b/include/net/libeth/xsk.h @@ -77,11 +77,17 @@ libeth_xsk_tx_queue_bulk(struct libeth_xdp_tx_bulk *bq, if (!libeth_xsk_tx_queue_head(bq, xdp)) goto out; - for (const struct libeth_xdp_buff *head = xdp; ; ) { + for (struct libeth_xdp_buff *head = xdp; ; ) { xdp = container_of(xsk_buff_get_frag(&head->base), typeof(*xdp), base); - if (!xdp) + if (!xdp) { + /* Each frag is now freed via its own SQE. Freeing + * the head must not release what is on the pool's + * frag list at that time. + */ + xdp_buff_clear_frags_flag(&head->base); break; + } if (unlikely(bq->count == LIBETH_XDP_TX_BULK) && unlikely(!flush_bulk(bq, LIBETH_XDP_TX_XSK))) { diff --git a/include/net/mac80211.h b/include/net/mac80211.h index a1a6409b44c12f..b74c15207cb911 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1772,7 +1772,8 @@ enum mac80211_rx_encoding { * @zero_length_psdu_type: radiotap type of the 0-length PSDU * @link_id: id of the link used to receive the packet. Set and used by * mac80211 internally, it uses @freq set by the driver to identify the - * correct link per vif. + * correct link per vif. Set to %IEEE80211_LINK_UNSPECIFIED for non-MLD + * or if link information is not applicable. */ struct ieee80211_rx_status { u64 mactime; diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 0b52582118e848..29d152e185967e 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -60,6 +60,7 @@ enum gdma_work_request_flags { enum gdma_eqe_type { GDMA_EQE_COMPLETION = 3, + GDMA_EQE_THROTTLE = 4, GDMA_EQE_TEST_EVENT = 64, GDMA_EQE_HWC_INIT_EQ_ID_DB = 129, GDMA_EQE_HWC_INIT_DATA = 130, @@ -291,6 +292,7 @@ struct gdma_dev { #define GDMA_EQE_SIZE 16 #define GDMA_MAX_SQE_SIZE 512 #define GDMA_MAX_RQE_SIZE 256 +#define GDMA_EQ_MAX_CHILD_CQ 2 #define GDMA_COMP_DATA_SIZE 0x3C @@ -318,6 +320,11 @@ struct gdma_event { struct gdma_queue; +struct gdma_eq_stats { + u64_stats_t throttle_count; + struct u64_stats_sync syncp; +}; + struct mana_eq { struct gdma_queue *eq; struct dentry *mana_eq_debugfs; @@ -371,6 +378,10 @@ struct gdma_queue { unsigned int irq; u32 log2_throttle_limit; + + struct gdma_eq_stats stats; + + struct gdma_queue __rcu *child_cq[GDMA_EQ_MAX_CHILD_CQ]; } eq; struct { @@ -601,6 +612,8 @@ void mana_gd_free_service_wq(struct gdma_context *gc); void mana_gd_ring_dim(struct gdma_queue *cq, u32 mod_usec, bool mod_usec_vld, u32 mod_comps, bool mod_comps_vld); +bool mana_gd_detach_cq(struct gdma_context *gc, struct gdma_queue *queue); + struct gdma_wqe { u32 reserved :24; u32 last_vbytes :8; @@ -760,6 +773,9 @@ enum { /* Driver supports non-contiguous queue buffers */ #define GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS BIT(30) +/* Driver supports handling throttled EQEs */ +#define GDMA_DRV_CAP_FLAG_1_THROTTLED_EVENT_QUEUE BIT_ULL(32) + /* Capabilities in the PCI-only group below rely on dynamic MSI-X allocation * and on the servicing and reset paths reached through * mana_schedule_serv_work(). Transports that provide neither leave @@ -784,7 +800,8 @@ enum { GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \ GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_DYN_INTERRUPT_MODERATION | \ - GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS) + GDMA_DRV_CAP_FLAG_1_NON_CONTIGUOUS_BUFFERS | \ + GDMA_DRV_CAP_FLAG_1_THROTTLED_EVENT_QUEUE) #define GDMA_DRV_CAP_FLAGS2 0 diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 71d726b1f78404..218d540bc99404 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -90,6 +90,7 @@ enum mana_priv_flag_bits { /* Update this count whenever the respective structures are changed */ #define MANA_STATS_RX_COUNT (6 + MANA_CQE_COAL_PKTS_8 - 1) #define MANA_STATS_TX_COUNT 11 +#define MANA_STATS_EQ_COUNT 1 #define MANA_RX_FRAG_ALIGNMENT 64 @@ -420,6 +421,8 @@ struct mana_rxq { struct bpf_prog __rcu *bpf_prog; struct xdp_rxq_info xdp_rxq; + /* For buffers not from the page pool (from_pool == false) */ + struct xdp_rxq_info xdp_rxq_shared; void *xdp_save_va; /* for reusing */ bool xdp_flush; int xdp_rc; /* XDP redirect return code */ @@ -695,7 +698,8 @@ void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev); int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames, u32 flags); u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, - struct xdp_buff *xdp, void *buf_va, uint pkt_len); + struct xdp_buff *xdp, void *buf_va, bool from_pool, + uint pkt_len); struct bpf_prog *mana_xdp_get(struct mana_port_context *apc); void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog); int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf); diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index c29a22ca178fa6..4a4d72080acdc7 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -72,6 +72,7 @@ struct net { unsigned int dev_base_seq; /* protected by rtnl_mutex */ atomic_t dev_mc_genid; /* dev->mc membership changes */ + atomic_t dev_unreg_pending; /* devices in netdev_run_todo() */ u32 ifindex; spinlock_t nsid_lock; diff --git a/include/net/netfilter/nf_dup_netdev.h b/include/net/netfilter/nf_dup_netdev.h index f6b05bd80c3fe3..a394112646144e 100644 --- a/include/net/netfilter/nf_dup_netdev.h +++ b/include/net/netfilter/nf_dup_netdev.h @@ -9,41 +9,6 @@ void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif); void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif); -#define NF_RECURSION_LIMIT 2 - -#ifndef CONFIG_PREEMPT_RT -static inline bool nf_dev_xmit_recursion(void) -{ - return unlikely(__this_cpu_read(softnet_data.xmit.nf_dup_skb_recursion) > - NF_RECURSION_LIMIT); -} - -static inline void nf_dev_xmit_recursion_inc(void) -{ - __this_cpu_inc(softnet_data.xmit.nf_dup_skb_recursion); -} - -static inline void nf_dev_xmit_recursion_dec(void) -{ - __this_cpu_dec(softnet_data.xmit.nf_dup_skb_recursion); -} -#else -static inline bool nf_dev_xmit_recursion(void) -{ - return unlikely(current->net_xmit.nf_dup_skb_recursion > NF_RECURSION_LIMIT); -} - -static inline void nf_dev_xmit_recursion_inc(void) -{ - current->net_xmit.nf_dup_skb_recursion++; -} - -static inline void nf_dev_xmit_recursion_dec(void) -{ - current->net_xmit.nf_dup_skb_recursion--; -} -#endif - struct nft_offload_ctx; struct nft_flow_rule; diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h index 86021c55ba3ce9..4a8cefd8398d79 100644 --- a/include/net/netfilter/nf_queue.h +++ b/include/net/netfilter/nf_queue.h @@ -23,6 +23,7 @@ struct nf_queue_entry { struct net_device *physout; #endif struct nf_hook_state state; + bool in_nf_duplicate; bool nf_ct_is_unconfirmed; u16 size; /* sizeof(entry) + saved route keys */ diff --git a/include/net/netfilter/nf_recursion.h b/include/net/netfilter/nf_recursion.h new file mode 100644 index 00000000000000..1ac65f7793f197 --- /dev/null +++ b/include/net/netfilter/nf_recursion.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NF_RECURSION_H_ +#define _NF_RECURSION_H_ + +#include + +#define NF_RECURSION_LIMIT 2 + +#ifndef CONFIG_PREEMPT_RT +static inline bool nf_dev_xmit_recursion(void) +{ + return unlikely(__this_cpu_read(softnet_data.xmit.nf_xmit_skb_recursion) > + NF_RECURSION_LIMIT); +} + +static inline void nf_dev_xmit_recursion_inc(void) +{ + __this_cpu_inc(softnet_data.xmit.nf_xmit_skb_recursion); +} + +static inline void nf_dev_xmit_recursion_dec(void) +{ + __this_cpu_dec(softnet_data.xmit.nf_xmit_skb_recursion); +} +#else +static inline bool nf_dev_xmit_recursion(void) +{ + return unlikely(current->net_xmit.nf_xmit_skb_recursion > NF_RECURSION_LIMIT); +} + +static inline void nf_dev_xmit_recursion_inc(void) +{ + current->net_xmit.nf_xmit_skb_recursion++; +} + +static inline void nf_dev_xmit_recursion_dec(void) +{ + current->net_xmit.nf_xmit_skb_recursion--; +} +#endif + +#endif /* _NF_RECURSION_H_ */ diff --git a/include/net/netlabel.h b/include/net/netlabel.h index 02914b1df38baa..f896b9d52ed16e 100644 --- a/include/net/netlabel.h +++ b/include/net/netlabel.h @@ -477,7 +477,7 @@ int netlbl_sock_setattr(struct sock *sk, u16 family, const struct netlbl_lsm_secattr *secattr, bool sk_locked); -void netlbl_sock_delattr(struct sock *sk); +int netlbl_sock_delattr(struct sock *sk); int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr); int netlbl_conn_setattr(struct sock *sk, @@ -485,7 +485,7 @@ int netlbl_conn_setattr(struct sock *sk, const struct netlbl_lsm_secattr *secattr); int netlbl_req_setattr(struct request_sock *req, const struct netlbl_lsm_secattr *secattr); -void netlbl_req_delattr(struct request_sock *req); +int netlbl_req_delattr(struct request_sock *req); int netlbl_skbuff_setattr(struct sk_buff *skb, u16 family, const struct netlbl_lsm_secattr *secattr); @@ -626,8 +626,9 @@ static inline int netlbl_sock_setattr(struct sock *sk, { return -ENOSYS; } -static inline void netlbl_sock_delattr(struct sock *sk) +static inline int netlbl_sock_delattr(struct sock *sk) { + return 0; } static inline int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr) @@ -645,9 +646,9 @@ static inline int netlbl_req_setattr(struct request_sock *req, { return -ENOSYS; } -static inline void netlbl_req_delattr(struct request_sock *req) +static inline int netlbl_req_delattr(struct request_sock *req) { - return; + return 0; } static inline int netlbl_skbuff_setattr(struct sk_buff *skb, u16 family, diff --git a/include/net/netns/can.h b/include/net/netns/can.h index 48b79f7e6236d9..54f23681e0d452 100644 --- a/include/net/netns/can.h +++ b/include/net/netns/can.h @@ -29,7 +29,7 @@ struct netns_can { /* receive filters subscribed for 'all' CAN devices */ struct can_dev_rcv_lists *rx_alldev_list; - spinlock_t rcvlists_lock; + spinlock_t rcvlists_lock; /* protects the rcv_entries(_max) stats */ struct timer_list stattimer; /* timer for statistics update */ struct can_pkg_stats *pkg_stats; struct can_rcv_lists_stats *rcv_lists_stats; diff --git a/include/net/request_sock.h b/include/net/request_sock.h index 5a9c826a7092dd..faa6dc49cea881 100644 --- a/include/net/request_sock.h +++ b/include/net/request_sock.h @@ -39,6 +39,7 @@ struct request_sock_ops { }; struct saved_syn { + struct rcu_head rcu; u32 mac_hdrlen; u32 network_hdrlen; u32 tcp_hdrlen; @@ -68,7 +69,7 @@ struct request_sock { struct timer_list rsk_timer; const struct request_sock_ops *rsk_ops; struct sock *sk; - struct saved_syn *saved_syn; + struct saved_syn __rcu *saved_syn; u32 secid; u32 peer_secid; u32 timeout; diff --git a/include/net/sock.h b/include/net/sock.h index 173b37b2b8bb09..3144efad8c361f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2218,10 +2218,13 @@ sk_dst_get(const struct sock *sk) static inline void __dst_negative_advice(struct sock *sk) { - struct dst_entry *dst = __sk_dst_get(sk); + struct dst_entry *dst; + rcu_read_lock(); + dst = __sk_dst_get(sk); if (dst && dst->ops->negative_advice) dst->ops->negative_advice(sk, dst); + rcu_read_unlock(); } static inline void dst_negative_advice(struct sock *sk) @@ -2284,6 +2287,14 @@ struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie); struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie); +/* This helper checks if a socket is a full socket, + * ie _not_ a timewait or request socket. + */ +static inline bool sk_fullsock(const struct sock *sk) +{ + return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); +} + static inline void sk_dst_confirm(struct sock *sk) { if (!READ_ONCE(sk->sk_dst_pending_confirm)) @@ -2295,7 +2306,8 @@ static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n) if (skb_get_dst_pending_confirm(skb)) { struct sock *sk = skb->sk; - if (sk && READ_ONCE(sk->sk_dst_pending_confirm)) + if (sk && sk_fullsock(sk) && + READ_ONCE(sk->sk_dst_pending_confirm)) WRITE_ONCE(sk->sk_dst_pending_confirm, 0); neigh_confirm(n); } @@ -3028,14 +3040,6 @@ skb_sk_is_prefetched(struct sk_buff *skb) #endif /* CONFIG_INET */ } -/* This helper checks if a socket is a full socket, - * ie _not_ a timewait or request socket. - */ -static inline bool sk_fullsock(const struct sock *sk) -{ - return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV); -} - static inline bool sk_is_refcounted(struct sock *sk) { diff --git a/include/net/tcp.h b/include/net/tcp.h index 3560adddf82154..5c9203aae83417 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1554,6 +1554,15 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) #define TCP_INFINITE_SSTHRESH 0x7fffffff +/* Default and maximum snd_cwnd_clamp, in packets. + * A peer can not advertise more than 65535 << 14 bytes, so a larger + * cwnd is useless with any MSS of 1024 bytes or more. + * Congestion control modules multiply cwnd by u32 factors up to 2047 + * (cwnd * (BICTCP_BETA_SCALE + beta) in CUBIC), and CUBIC's + * bictcp_update() expects cwnd to stay below about one million packets. + */ +#define TCP_MAX_SND_CWND (1U << 20) + static inline u32 tcp_snd_cwnd(const struct tcp_sock *tp) { return tp->snd_cwnd; diff --git a/include/net/tcp_ao.h b/include/net/tcp_ao.h index 9a2333e62e9940..edf4c9bc5ef5d2 100644 --- a/include/net/tcp_ao.h +++ b/include/net/tcp_ao.h @@ -303,7 +303,8 @@ static inline enum skb_drop_reason tcp_inbound_ao_hash(struct sock *sk, const struct request_sock *req, int l3index, const struct tcp_ao_hdr *aoh) { - return SKB_NOT_DROPPED_YET; + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOKEYNOTFOUND); + return SKB_DROP_REASON_TCP_AOUNEXPECTED; } static inline struct tcp_ao_key *tcp_ao_do_lookup(const struct sock *sk, diff --git a/include/net/tls.h b/include/net/tls.h index e57bef58851eac..0b001b8ab1c3b3 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -139,6 +139,7 @@ struct tls_sw_context_rx { u8 zc_capable:1; u8 reader_contended:1; bool key_update_pending; + u8 empty_run; struct tls_strparser strp; diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h index d94aeb506379c4..a40ad3f90f13cc 100644 --- a/include/net/xdp_sock_drv.h +++ b/include/net/xdp_sock_drv.h @@ -153,6 +153,7 @@ static inline void xsk_buff_free(struct xdp_buff *xdp) } xdp_get_shared_info_from_buff(xdp)->nr_frags = 0; + xdp_buff_clear_frags_flag(xdp); out: xp_free(xskb); } @@ -160,15 +161,18 @@ static inline void xsk_buff_free(struct xdp_buff *xdp) static inline bool xsk_buff_add_frag(struct xdp_buff *head, struct xdp_buff *xdp) { + struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp); const void *data = xdp->data; - struct xdp_buff_xsk *frag; + + /* Duplicate fill ring entries map to the same xskb in aligned mode */ + if (unlikely(xdp == head || !list_empty(&frag->list_node))) + return false; if (!__xdp_buff_add_frag(head, virt_to_netmem(data), offset_in_page(data), xdp->data_end - data, xdp->frame_sz, false)) return false; - frag = container_of(xdp, struct xdp_buff_xsk, xdp); list_add_tail(&frag->list_node, &frag->pool->xskb_list); return true; @@ -222,7 +226,8 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size) xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM; xdp->data_meta = xdp->data; xdp->data_end = xdp->data + size; - xdp->flags = 0; + /* Frags flag is cleared when the frags of a head are released */ + xdp->flags &= XDP_FLAGS_HAS_FRAGS; } static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool, diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 298ca9bb008352..445223a8dc6f14 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -1765,6 +1765,13 @@ struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, u32 mark, const xfrm_address_t *saddr, u8 proto, unsigned short family); +struct xfrm_state *xfrm_state_lookup_exact(struct net *net, const struct xfrm_mark *mark, + const xfrm_address_t *daddr, __be32 spi, + u8 proto, unsigned short family); +bool xfrm_state_mark_collides(struct net *net, u32 mark, + const xfrm_address_t *daddr, __be32 spi, + u8 proto, unsigned short family, + const struct xfrm_state *self); #ifdef CONFIG_XFRM_SUB_POLICY void xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n, unsigned short family); diff --git a/include/sound/cs35l56.h b/include/sound/cs35l56.h index ce6383c2c60cc2..362dfa2761bc9b 100644 --- a/include/sound/cs35l56.h +++ b/include/sound/cs35l56.h @@ -386,9 +386,9 @@ static inline bool cs35l56_is_otp_register(unsigned int reg) static inline int cs35l56_init_config_for_spi(struct cs35l56_base *cs35l56, struct spi_device *spi) { - cs35l56->spi_payload_buf = devm_kzalloc(&spi->dev, - sizeof(*cs35l56->spi_payload_buf), - GFP_KERNEL | GFP_DMA); + cs35l56->spi_payload_buf = devm_kzalloc_obj(&spi->dev, + *cs35l56->spi_payload_buf, + GFP_KERNEL | GFP_DMA); if (!cs35l56->spi_payload_buf) return -ENOMEM; @@ -412,7 +412,7 @@ extern const char * const cs35l56_cal_set_status_text[3]; extern const char * const cs35l56_tx_input_texts[CS35L56_NUM_INPUT_SRC]; extern const unsigned int cs35l56_tx_input_values[CS35L56_NUM_INPUT_SRC]; -int cs35l56_set_asp_patch(struct cs35l56_base *cs35l56_base); +int cs35l56_set_asp_defaults(struct cs35l56_base *cs35l56_base); int cs35l56_set_patch(struct cs35l56_base *cs35l56_base); int cs35l56_mbox_send(struct cs35l56_base *cs35l56_base, unsigned int command); int cs35l56_firmware_shutdown(struct cs35l56_base *cs35l56_base); diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h index 81422219ed3901..909ce442a19491 100644 --- a/include/sound/dmaengine_pcm.h +++ b/include/sound/dmaengine_pcm.h @@ -127,7 +127,7 @@ int snd_dmaengine_pcm_refine_runtime_hwparams( * channel for platforms which do not use devicetree. The filter parameter * will be the DAI's DMA data. * @dma_dev: If set, request DMA channel on this device rather than the DAI - * device. + * device. Only the channels listed in @chan_names are requested then. * @chan_names: If set, these custom DMA channel names will be requested at * registration time. * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM. diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h index 599a72f3351535..26740f69f2beed 100644 --- a/include/sound/sdca_asoc.h +++ b/include/sound/sdca_asoc.h @@ -12,6 +12,7 @@ struct device; struct regmap; +struct sdw_slave; struct sdca_function_data; struct sdca_pde_delay; struct snd_ctl_elem_value; @@ -89,12 +90,14 @@ int sdca_asoc_populate_rate_format(struct device *dev, struct sdca_entity *entity, struct snd_soc_pcm_stream *stream); -int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap, +int sdca_asoc_alloc_constraints(struct snd_soc_dai *dai); +int sdca_asoc_free_constraints(struct snd_soc_dai *dai); +int sdca_asoc_set_constraints(struct device *dev, struct sdw_slave *sdw, + struct regmap *regmap, struct sdca_function_data *function, struct snd_pcm_substream *substream, struct snd_soc_dai *dai); -void sdca_asoc_free_constraints(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai); + int sdca_asoc_get_port(struct device *dev, struct regmap *regmap, struct sdca_function_data *function, struct snd_soc_dai *dai); diff --git a/include/sound/soc-acpi.h b/include/sound/soc-acpi.h index 2ee303b791dc84..81b27778e27a3c 100644 --- a/include/sound/soc-acpi.h +++ b/include/sound/soc-acpi.h @@ -257,4 +257,38 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev, const struct snd_soc_acpi_link_adr *link, struct sdw_peripherals *peripherals); +enum snd_soc_acpi_tplg_device_id { + SND_SOC_ACPI_TPLG_DEVICE_SDCA_JACK, + SND_SOC_ACPI_TPLG_DEVICE_SDCA_AMP, + SND_SOC_ACPI_TPLG_DEVICE_SDCA_MIC, + SND_SOC_ACPI_TPLG_DEVICE_PCH_DMIC, + SND_SOC_ACPI_TPLG_DEVICE_HDMI, + SND_SOC_ACPI_TPLG_DEVICE_SSP_JACK, + SND_SOC_ACPI_TPLG_DEVICE_SSP_AMP, + SND_SOC_ACPI_TPLG_DEVICE_SSP_BT, + SND_SOC_ACPI_TPLG_DEVICE_SSP_HDMI_IN, + SND_SOC_ACPI_TPLG_DEVICE_LOOPBACK_VIRTUAL, + SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_JACK, + SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_AMP, + SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_MIC, + SND_SOC_ACPI_TPLG_DEVICE_ACP_DMIC, + SND_SOC_ACPI_TPLG_DEVICE_MAX +}; + +/* + * Minimum size, including the trailing NUL, of the buffer that + * snd_soc_acpi_sof_get_platform_name() fills from a + * "sof--...tplg" topology file name. The "sof-%7[^-]" + * conversion can write up to seven characters plus a NUL terminator, + * so callers must provide a buffer of at least this size. + */ +#define SND_SOC_ACPI_SOF_PLATFORM_NAME_MAX 8 + +int snd_soc_acpi_sof_get_platform_name(struct device *dev, + const struct snd_soc_acpi_mach *mach, char *platform); +char *snd_soc_acpi_sof_get_tplg_filename(struct device *dev, const char *prefix, + const char *platform, const char *tplg_dev_name, + int dai_link_id, + enum snd_soc_acpi_tplg_device_id tplg_dev); + #endif diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index c044909ef10d81..aeac0de0c4f096 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -227,8 +227,6 @@ int snd_soc_dai_startup(struct snd_soc_dai *dai, struct snd_pcm_substream *substream); void snd_soc_dai_shutdown(struct snd_soc_dai *dai, struct snd_pcm_substream *substream, int rollback); -void snd_soc_dai_suspend(struct snd_soc_dai *dai); -void snd_soc_dai_resume(struct snd_soc_dai *dai); int snd_soc_dai_compress_new(struct snd_soc_dai *dai, struct snd_soc_pcm_runtime *rtd); bool snd_soc_dai_stream_valid(const struct snd_soc_dai *dai, int stream); diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h index 1eedd203ac2990..cf5c9bd1037e2d 100644 --- a/include/sound/soc-topology.h +++ b/include/sound/soc-topology.h @@ -30,6 +30,7 @@ struct snd_soc_dai_link; struct snd_soc_dai_driver; struct snd_soc_dai; struct snd_soc_dapm_route; +struct device; /* dynamic object type */ enum snd_soc_dobj_type { @@ -181,6 +182,9 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp, const struct snd_soc_tplg_ops *ops, const struct firmware *fw); int snd_soc_tplg_component_remove(struct snd_soc_component *comp); +/* Check for presence of topology firmware files */ +bool snd_soc_tplg_files_exist(struct device *dev, const char *tplg_files); + /* Binds event handlers to dynamic widgets */ int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, const struct snd_soc_tplg_widget_events *events, int num_events, @@ -193,6 +197,12 @@ static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp) return 0; } +static inline bool snd_soc_tplg_files_exist(struct device *dev, + const char *tplg_files) +{ + return false; +} + #endif #endif diff --git a/include/sound/tas2573-reg.h b/include/sound/tas2573-reg.h new file mode 100644 index 00000000000000..4fedc8a3329e8f --- /dev/null +++ b/include/sound/tas2573-reg.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier +// +// Copyright (C) 2026 Texas Instruments Incorporated +// https://www.ti.com +// +// Register definitions for the TAS2573 Audio Smart Amplifier, used by the +// speaker calibration (FCT) and real-time speaker protection data. +// +// Author: Shenghao Ding +// + +#ifndef __TAS2573_REG_H__ +#define __TAS2573_REG_H__ + +/* + * Register map descriptor: binds the register table, its length, and the log + * tag together into a single argument. + */ +struct tasdev_reg_map { + const unsigned int *regs; + unsigned int nregs; + const char *tag; +}; + +#define TAS2573_TDM_DET_REG TASDEVICE_REG(0x00, 0x00, 0x14) +#define TAS2573_FCT_INT_LATCH TASDEVICE_REG(0x00, 0x00, 0x67) +/* YM57 */ +#define TAS2573_FCT_OUTPUT_R0 TASDEVICE_REG(0x00, 0x65, 0x74) +/* YM58 */ +#define TAS2573_FCT_OUTPUT_R0_LOW TASDEVICE_REG(0x00, 0x65, 0x78) +/* YM59 */ +#define TAS2573_FCT_OUTPUT_INV_R0 TASDEVICE_REG(0x00, 0x65, 0x7C) +/* YM61 */ +#define TAS2573_FCT_OUTPUT_POWERTOT TASDEVICE_REG(0x00, 0x66, 0x0C) +/* YM64 */ +#define TAS2573_FCT_OUTPUT_F0 TASDEVICE_REG(0x00, 0x65, 0x18) +/* YM147 */ +#define TAS2573_FCT_STATUS_CTRL TASDEVICE_REG(0x00, 0x68, 0x74) +/* YM148 */ +#define TAS2573_FCT_STATUS_BINNING TASDEVICE_REG(0x00, 0x68, 0x78) +/* YM510 */ +#define TAS2573_SPK_COIL_TEMPERATURE TASDEVICE_REG(0x00, 0x75, 0x08) +/* YM664 */ +#define TAS2573_RE_OUT TASDEVICE_REG(0x00, 0x7A, 0x18) +/* YM694 */ +#define TAS2573_A1_OUT TASDEVICE_REG(0x00, 0x7B, 0x18) +/* YM695 */ +#define TAS2573_A2_OUT TASDEVICE_REG(0x00, 0x7B, 0x1C) +/* YM793 */ +#define TAS2573_EXCURSION_GAIN TASDEVICE_REG(0x00, 0x7E, 0x3C) +/* YM800 */ +#define TAS2573_THERMAL_GAIN TASDEVICE_REG(0x00, 0x7E, 0x58) +/* YM952 */ +#define TAS2573_SILENCE_DETECTED TASDEVICE_REG(0x00, 0x83, 0x60) +/* YM954 */ +#define TAS2573_OPEN_CIRCUIT TASDEVICE_REG(0x00, 0x83, 0x68) +/* YM955 */ +#define TAS2573_SHORTCKT TASDEVICE_REG(0x00, 0x83, 0x6C) + +/* Registers for the realtime (RT) speaker protection data */ +static const __maybe_unused unsigned int tas2573_rt_data_regs[] = { + TAS2573_TDM_DET_REG, + TAS2573_SPK_COIL_TEMPERATURE, + TAS2573_RE_OUT, + TAS2573_A1_OUT, + TAS2573_A2_OUT, + TAS2573_EXCURSION_GAIN, + TAS2573_THERMAL_GAIN, +}; +static const __maybe_unused struct tasdev_reg_map tas2573_rt_data_map = { + .regs = tas2573_rt_data_regs, + .nregs = ARRAY_SIZE(tas2573_rt_data_regs), + .tag = "tas2573_rt_data_regs", +}; +#endif diff --git a/include/sound/tas2781.h b/include/sound/tas2781.h index f4275226366de7..8d2621f9d19713 100644 --- a/include/sound/tas2781.h +++ b/include/sound/tas2781.h @@ -98,30 +98,6 @@ /* prm_TE_1_Beta1 */ #define TAS2563_TE_DT_REG TASDEVICE_REG(0x00, 0x0f, 0x70) -#define TAS2573_FCT_INT_LATCH TASDEVICE_REG(0x00, 0x00, 0x67) -/* YM57 */ -#define TAS2573_FCT_OUTPUT_R0 TASDEVICE_REG(0x00, 0x65, 0x74) -/* YM58 */ -#define TAS2573_FCT_OUTPUT_R0_LOW TASDEVICE_REG(0x00, 0x65, 0x78) -/* YM59 */ -#define TAS2573_FCT_OUTPUT_INV_R0 TASDEVICE_REG(0x00, 0x65, 0x7C) -/* YM61 */ -#define TAS2573_FCT_OUTPUT_POWERTOT TASDEVICE_REG(0x00, 0x66, 0x0C) -/* YM64 */ -#define TAS2573_FCT_OUTPUT_F0 TASDEVICE_REG(0x00, 0x65, 0x18) -/* YM147 */ -#define TAS2573_FCT_STATUS_CTRL TASDEVICE_REG(0x00, 0x68, 0x74) -/* YM148 */ -#define TAS2573_FCT_STATUS_BINNING TASDEVICE_REG(0x00, 0x68, 0x78) -/* YM664 */ -#define TAS2573_RE_OUT TASDEVICE_REG(0x00, 0x7A, 0x18) -/* YM952 */ -#define TAS2573_SILENCE_DETECTED TASDEVICE_REG(0x00, 0x83, 0x60) -/* YM954 */ -#define TAS2573_OPEN_CIRCUIT TASDEVICE_REG(0x00, 0x83, 0x68) -/* YM955 */ -#define TAS2573_SHORTCKT TASDEVICE_REG(0x00, 0x83, 0x6C) - #define TAS2781_PRM_INT_MASK_REG TASDEVICE_REG(0x00, 0x00, 0x3b) #define TAS2781_PRM_CLK_CFG_REG TASDEVICE_REG(0x00, 0x00, 0x5c) #define TAS2781_PRM_RSVD_REG TASDEVICE_REG(0x00, 0x01, 0x19) diff --git a/include/trace/events/intel-sst.h b/include/trace/events/intel-sst.h deleted file mode 100644 index 0416e91f81817a..00000000000000 --- a/include/trace/events/intel-sst.h +++ /dev/null @@ -1,156 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM intel-sst - -/* - * The TRACE_SYSTEM_VAR defaults to TRACE_SYSTEM, but must be a - * legitimate C variable. It is not exported to user space. - */ -#undef TRACE_SYSTEM_VAR -#define TRACE_SYSTEM_VAR intel_sst - -#if !defined(_TRACE_INTEL_SST_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_INTEL_SST_H - -#include -#include -#include - -DECLARE_EVENT_CLASS(sst_ipc_msg, - - TP_PROTO(unsigned int val), - - TP_ARGS(val), - - TP_STRUCT__entry( - __field( unsigned int, val ) - ), - - TP_fast_assign( - __entry->val = val; - ), - - TP_printk("0x%8.8x", (unsigned int)__entry->val) -); - -DEFINE_EVENT(sst_ipc_msg, sst_ipc_msg_tx, - - TP_PROTO(unsigned int val), - - TP_ARGS(val) - -); - -DEFINE_EVENT(sst_ipc_msg, sst_ipc_msg_rx, - - TP_PROTO(unsigned int val), - - TP_ARGS(val) - -); - -DECLARE_EVENT_CLASS(sst_ipc_mailbox, - - TP_PROTO(unsigned int offset, unsigned int val), - - TP_ARGS(offset, val), - - TP_STRUCT__entry( - __field( unsigned int, offset ) - __field( unsigned int, val ) - ), - - TP_fast_assign( - __entry->offset = offset; - __entry->val = val; - ), - - TP_printk(" 0x%4.4x = 0x%8.8x", - (unsigned int)__entry->offset, (unsigned int)__entry->val) -); - -DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_inbox_rdata, - - TP_PROTO(unsigned int offset, unsigned int val), - - TP_ARGS(offset, val) - -); - -DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_inbox_wdata, - - TP_PROTO(unsigned int offset, unsigned int val), - - TP_ARGS(offset, val) - -); - -DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_outbox_rdata, - - TP_PROTO(unsigned int offset, unsigned int val), - - TP_ARGS(offset, val) - -); - -DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_outbox_wdata, - - TP_PROTO(unsigned int offset, unsigned int val), - - TP_ARGS(offset, val) - -); - -DECLARE_EVENT_CLASS(sst_ipc_mailbox_info, - - TP_PROTO(unsigned int size), - - TP_ARGS(size), - - TP_STRUCT__entry( - __field( unsigned int, size ) - ), - - TP_fast_assign( - __entry->size = size; - ), - - TP_printk("Mailbox bytes 0x%8.8x", (unsigned int)__entry->size) -); - -DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_inbox_read, - - TP_PROTO(unsigned int size), - - TP_ARGS(size) - -); - -DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_inbox_write, - - TP_PROTO(unsigned int size), - - TP_ARGS(size) - -); - -DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_outbox_read, - - TP_PROTO(unsigned int size), - - TP_ARGS(size) - -); - -DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_outbox_write, - - TP_PROTO(unsigned int size), - - TP_ARGS(size) - -); - -#endif /* _TRACE_SST_H */ - -/* This part must be outside protection */ -#include diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h index 6d9d9e7c7ca2d9..b6fdc6e2eef871 100644 --- a/include/trace/events/landlock.h +++ b/include/trace/events/landlock.h @@ -987,7 +987,8 @@ TRACE_EVENT(landlock_deny_access_net, * @logged: Whether this denial was selected for audit logging. * @blockers: Request type and final missing permission subset (never NULL). * @namespace_type: CLONE_NEW* namespace type that was denied. - * @namespace_id: Namespace ID, or 0 when creation was denied. + * @namespace_id: Namespace ID, not directly visible from user space when + * creation was denied. * * Emitted when a Landlock domain denies namespace use. */ diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index 9f0a5d1482c448..cbcf6fe4cc6156 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -33,7 +33,7 @@ TRACE_EVENT(oom_score_adj_update, TRACE_EVENT(reclaim_retry_zone, - TP_PROTO(struct zoneref *zoneref, + TP_PROTO(struct zone *zone, int order, unsigned long reclaimable, unsigned long available, @@ -41,7 +41,7 @@ TRACE_EVENT(reclaim_retry_zone, int no_progress_loops, bool wmark_check), - TP_ARGS(zoneref, order, reclaimable, available, min_wmark, no_progress_loops, wmark_check), + TP_ARGS(zone, order, reclaimable, available, min_wmark, no_progress_loops, wmark_check), TP_STRUCT__entry( __field( int, node) @@ -55,8 +55,8 @@ TRACE_EVENT(reclaim_retry_zone, ), TP_fast_assign( - __entry->node = zonelist_node_idx(zoneref); - __entry->zone_idx = zonelist_zone_idx(zoneref); + __entry->node = zone_to_nid(zone); + __entry->zone_idx = zone_idx(zone); __entry->order = order; __entry->reclaimable = reclaimable; __entry->available = available; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index b456f45fa8de77..cf1afd11bb8712 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -646,6 +646,7 @@ struct io_uring_params { #define IORING_FEAT_MIN_TIMEOUT (1U << 15) #define IORING_FEAT_RW_ATTR (1U << 16) #define IORING_FEAT_NO_IOWAIT (1U << 17) +#define IORING_FEAT_REGBUF_TYPES (1U << 18) /* * io_uring_register(2) opcodes and arguments diff --git a/include/uapi/linux/mdio.h b/include/uapi/linux/mdio.h index 06f4bc3c20c717..2806f60ed1054a 100644 --- a/include/uapi/linux/mdio.h +++ b/include/uapi/linux/mdio.h @@ -417,8 +417,17 @@ #define MDIO_AN_10BT1_AN_STAT_LPA_EEE_T1L 0x4000 /* 10BASE-T1L LP EEE ability advertisement */ /* BASE-T1 PMA/PMD control register */ -#define MDIO_PMA_PMD_BT1_CTRL_STRAP 0x000F /* Type selection (Strap) */ -#define MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000 0x0001 /* Select 1000BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL 0x000F /* Type selection */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_100BT1 0x0000 /* Select 100BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1 0x0001 /* Select 1000BASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1L 0x0002 /* Select 10BASE-T1L */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10BT1S 0x0003 /* Select 10BASE-T1S */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_2P5GBT1 0x0004 /* Select 2.5GBASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_5GBT1 0x0005 /* Select 5GBASE-T1 */ +#define MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_10GBT1 0x0006 /* Select 10GBASE-T1 */ +/* Legacy names, kept for userspace */ +#define MDIO_PMA_PMD_BT1_CTRL_STRAP MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL +#define MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000 MDIO_PMA_PMD_BT1_CTRL_TYPE_SEL_1000BT1 #define MDIO_PMA_PMD_BT1_CTRL_CFG_MST 0x4000 /* MASTER-SLAVE config value */ /* 1000BASE-T1 PCS control register */ diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index b56a96f57bec28..dae8fb894a79ec 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -6,7 +6,7 @@ * Copyright 2006-2010 Johannes Berg * Copyright 2008 Michael Wu * Copyright 2008 Luis Carlos Cobo - * Copyright 2008 Michael Buesch + * Copyright 2008 Michael Buesch * Copyright 2008, 2009 Luis R. Rodriguez * Copyright 2008 Jouni Malinen * Copyright 2008 Colin McCabe diff --git a/include/uapi/linux/virtio_spi.h b/include/uapi/linux/virtio_spi.h index 8ab3c970cdd311..459c2276c938c0 100644 --- a/include/uapi/linux/virtio_spi.h +++ b/include/uapi/linux/virtio_spi.h @@ -73,7 +73,7 @@ * @max_cs_hold_ns: the maximum delay supported before chipselect is deasserted, * in ns unit, 0 means delay is not supported to introduce before chipselect * is deasserted. - * @max_cs_incative_ns: maximum delay supported after chipselect is deasserted, + * @max_cs_inactive_ns: maximum delay supported after chipselect is deasserted, * in ns unit, 0 means delay is not supported to introduce after chipselect is * deasserted. */ diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h index 9076483c9fbbd0..726fd15efc8260 100644 --- a/include/vdso/unaligned.h +++ b/include/vdso/unaligned.h @@ -4,6 +4,20 @@ #include +#ifdef CONFIG_VDSO_UNALIGNED_PACKED + +#define __get_unaligned_t(type, ptr) ({ \ + const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \ + __get_pptr->x; \ +}) + +#define __put_unaligned_t(type, val, ptr) do { \ + struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \ + __put_pptr->x = (val); \ +} while (0) + +#else /* !CONFIG_VDSO_UNALIGNED_PACKED */ + /** * __get_unaligned_t - read an unaligned value from memory. * @type: the type to load from the pointer. @@ -41,4 +55,6 @@ sizeof(__put_unaligned_val)); \ } while (0) +#endif /* CONFIG_VDSO_UNALIGNED_PACKED */ + #endif /* __VDSO_UNALIGNED_H */ diff --git a/init/Kconfig b/init/Kconfig index 4013781e0a0292..c8a7cfa60a6ea4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -884,6 +884,7 @@ config MEMCG select EVENTFD select SLAB_OBJ_EXT select VM_EVENT_COUNTERS + select BLK_CGROUP if BLOCK help Provides control over the memory footprint of tasks in a cgroup. diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 48bfab2fc62f91..448a734a0f6252 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -258,6 +258,11 @@ int __init rd_load_image(void) fput(in_file); noclose_input: fput(out_file); + /* + * The image only reaches the ramdisk when the deferred __fput() + * syncs the block device. Flush it before mount_root() reads it. + */ + init_flush_fput(); out: kfree(buf); init_unlink("/dev/ram"); diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 79b5c133319b77..e3d9fe8fc982c6 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -198,7 +198,8 @@ static int __io_async_cancel(struct io_cancel_data *cd, break; if (!all) return ret; - nr++; + /* poll, futex and waitid return how many they cancelled */ + nr += max(ret, 1); } while (1); /* slow path, try all io-wq's */ diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c index 132e3d0d70237c..61825d59e384ef 100644 --- a/io_uring/dma-buf.c +++ b/io_uring/dma-buf.c @@ -28,7 +28,7 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx, if (desc->uaddr || desc->size) return -EINVAL; - bd = kzalloc(sizeof(*bd), GFP_KERNEL); + bd = kzalloc_obj(*bd); if (!bd) return -ENOMEM; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 03724419c4e157..5db57bf675f0e7 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2547,7 +2547,10 @@ static __cold void io_ring_ctx_wait_inflight(struct io_ring_ctx *ctx) if (current->flags & (PF_KTHREAD | PF_EXITING)) return; - if (tctx && atomic_read(&tctx->in_cancel)) + /* Only wait if this task has attached to the ring */ + if (!tctx || !xa_load(&tctx->xa, (unsigned long)ctx)) + return; + if (atomic_read(&tctx->in_cancel)) return; while (io_ring_ctx_inflight(ctx) && !fatal_signal_pending(current)) { diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 32247529076c51..c8592f4ef5108b 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -50,7 +50,8 @@ struct io_ctx_config { IORING_FEAT_RECVSEND_BUNDLE |\ IORING_FEAT_MIN_TIMEOUT |\ IORING_FEAT_RW_ATTR |\ - IORING_FEAT_NO_IOWAIT) + IORING_FEAT_NO_IOWAIT |\ + IORING_FEAT_REGBUF_TYPES) #define IORING_SETUP_FLAGS (IORING_SETUP_IOPOLL |\ IORING_SETUP_SQPOLL |\ @@ -139,6 +140,7 @@ struct io_wait_queue { #ifdef CONFIG_NET_RX_BUSY_POLL ktime_t napi_busy_poll_dt; + ktime_t napi_busy_poll_end; bool napi_prefer_busy_poll; #endif }; diff --git a/io_uring/napi.c b/io_uring/napi.c index d299c89cfc3d96..0724c608777d95 100644 --- a/io_uring/napi.c +++ b/io_uring/napi.c @@ -128,19 +128,15 @@ static inline void io_napi_remove_stale(struct io_ring_ctx *ctx, bool is_stale) __io_napi_remove_stale(ctx); } -static inline bool io_napi_busy_loop_timeout(ktime_t start_time, - ktime_t bp) +static inline bool io_napi_busy_loop_timeout(struct io_wait_queue *iowq) { - if (bp) { - ktime_t end_time = ktime_add(start_time, bp); - ktime_t now = net_to_ktime(busy_loop_current_time()); - - return ktime_after(now, end_time); - } - - return true; + if (!iowq->napi_busy_poll_dt) + return true; + return ktime_after(net_to_ktime(busy_loop_current_time()), + iowq->napi_busy_poll_end); } +/* Uses an absolute deadline, so the napi loop can be re-entered */ static bool io_napi_busy_loop_should_end(void *data, unsigned long start_time) { @@ -150,8 +146,7 @@ static bool io_napi_busy_loop_should_end(void *data, return true; if (io_should_wake(iowq) || io_has_work(iowq->ctx)) return true; - if (io_napi_busy_loop_timeout(net_to_ktime(start_time), - iowq->napi_busy_poll_dt)) + if (io_napi_busy_loop_timeout(iowq)) return true; return false; @@ -209,13 +204,16 @@ __io_napi_do_busy_loop(struct io_ring_ctx *ctx, static void io_napi_blocking_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq) { - unsigned long start_time = busy_loop_current_time(); + ktime_t now = net_to_ktime(busy_loop_current_time()); bool (*loop_end)(void *, unsigned long) = NULL; void *loop_end_arg = NULL; bool is_stale = false; - /* Singular lists use a different napi loop end check function and are - * only executed once. + iowq->napi_busy_poll_end = ktime_add(now, iowq->napi_busy_poll_dt); + + /* + * A single NAPI is held by __napi_busy_loop() for the whole spin. It + * may return early on need_resched(), loop until our own deadline. */ if (list_is_singular(&ctx->napi_list)) { loop_end = io_napi_busy_loop_should_end; @@ -226,8 +224,7 @@ static void io_napi_blocking_busy_loop(struct io_ring_ctx *ctx, do { is_stale = __io_napi_do_busy_loop(ctx, loop_end, loop_end_arg); - } while (!io_napi_busy_loop_should_end(iowq, start_time) && - !loop_end_arg); + } while (!io_napi_busy_loop_should_end(iowq, 0)); } io_napi_remove_stale(ctx, is_stale); diff --git a/io_uring/poll.c b/io_uring/poll.c index 4f04bda42f7ffe..fc1800c7097b53 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -128,12 +128,24 @@ static void io_poll_req_insert(struct io_kiocb *req) hlist_add_head(&req->hash_node, &table->hbs[index].list); } +#define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL) + +static __poll_t io_poll_unmask(__poll_t events) +{ + /* + * A peer that stopped sending is an event for a reader, but a write + * only poll must stay armed until the file is writable again. + */ + if (events & (EPOLLIN | EPOLLRDNORM | EPOLLRDBAND)) + return IO_POLL_UNMASK | EPOLLRDHUP; + return IO_POLL_UNMASK; +} + static void io_init_poll_iocb(struct io_poll *poll, __poll_t events) { poll->head = NULL; -#define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL|EPOLLRDHUP) /* mask in events that we always want/need */ - poll->events = events | IO_POLL_UNMASK; + poll->events = events | io_poll_unmask(events); INIT_LIST_HEAD(&poll->wait.entry); init_waitqueue_func_entry(&poll->wait, io_poll_wake); } @@ -727,7 +739,7 @@ int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask) int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) { const struct io_issue_def *def = &io_issue_defs[req->opcode]; - __poll_t mask = POLLPRI | POLLERR; + __poll_t mask = EPOLLERR; if (!def->pollin && !def->pollout) return IO_APOLL_ABORTED; @@ -735,7 +747,8 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) return IO_APOLL_ABORTED; if (def->pollin) { - mask |= EPOLLIN | EPOLLRDNORM; + /* urgent data is an event for a reader only */ + mask |= EPOLLIN | EPOLLRDNORM | EPOLLPRI; /* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */ if (req->flags & REQ_F_CLEAR_POLLIN) @@ -827,12 +840,47 @@ static int io_poll_disarm(struct io_kiocb *req) return 0; } +/* + * Cancel every request matching @cd in one pass. Cancelled requests stay + * hashed until their task work runs, so finding them one at a time would + * walk past all the earlier ones on each lookup. + */ +static int io_poll_cancel_all(struct io_ring_ctx *ctx, struct io_cancel_data *cd) +{ + unsigned int nr_buckets = 1U << ctx->cancel_table.hash_bits; + unsigned int i = 0; + struct hlist_node *tmp; + struct io_kiocb *req; + int nr = 0; + + if (!(cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP | + IORING_ASYNC_CANCEL_ANY))) { + /* keyed by user_data, so only one bucket can match */ + i = hash_long(cd->data, ctx->cancel_table.hash_bits); + nr_buckets = i + 1; + } + + for (; i < nr_buckets; i++) { + struct io_hash_bucket *hb = &ctx->cancel_table.hbs[i]; + + hlist_for_each_entry_safe(req, tmp, &hb->list, hash_node) { + if (!io_cancel_req_match(req, cd)) + continue; + io_poll_cancel_req(req); + nr++; + } + } + return nr ?: -ENOENT; +} + static int __io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd) { struct io_kiocb *req; - if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP | - IORING_ASYNC_CANCEL_ANY)) + if (cd->flags & (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_ANY)) + return io_poll_cancel_all(ctx, cd); + + if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP)) req = io_poll_file_find(ctx, cd); else req = io_poll_find(ctx, false, cd); @@ -971,7 +1019,7 @@ int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags) poll->events &= ~0xffff; poll->events |= poll_update->events & 0xffff; - poll->events |= IO_POLL_UNMASK; + poll->events |= io_poll_unmask(poll->events); } if (poll_update->update_user_data) preq->cqe.user_data = poll_update->new_user_data; diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index e0345c3e764ecb..8de5737d223e8b 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -572,11 +572,12 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req, { struct io_rsrc_update *up = io_kiocb_to_cmd(req, struct io_rsrc_update); __s32 __user *fds = u64_to_user_ptr(up->arg); + struct io_ring_ctx *ctx = req->ctx; unsigned int done; struct file *file; int ret, fd; - if (!req->ctx->file_table.data.nr) + if (!ctx->file_table.data.nr) return -ENXIO; for (done = 0; done < up->nr_args; done++) { @@ -590,15 +591,25 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req, ret = -EBADF; break; } - ret = io_fixed_fd_install(req, issue_flags, file, - IORING_FILE_INDEX_ALLOC); - if (ret < 0) + /* + * Hold the lock across the put_user(), if it's dropped the + * slot can be closed and reused before the error path runs. + */ + io_ring_submit_lock(ctx, issue_flags); + ret = __io_fixed_fd_install(ctx, file, + IORING_FILE_INDEX_ALLOC); + if (ret < 0) { + io_ring_submit_unlock(ctx, issue_flags); + fput(file); break; + } if (put_user(ret, &fds[done])) { - __io_close_fixed(req->ctx, issue_flags, ret); + io_fixed_fd_remove(ctx, ret); + io_ring_submit_unlock(ctx, issue_flags); ret = -EFAULT; break; } + io_ring_submit_unlock(ctx, issue_flags); } if (done) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index c833e776320d43..d387488db2dec9 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -29,6 +29,7 @@ enum { IO_SQ_THREAD_SHOULD_STOP = 0, IO_SQ_THREAD_SHOULD_PARK, + IO_SQ_THREAD_EXITING, }; void io_sq_thread_unpark(struct io_sq_data *sqd) @@ -348,6 +349,18 @@ static int io_sq_thread(void *data) timeout = jiffies + sqd->sq_thread_idle; } + /* + * The SQPOLL thread never returns to userspace, so do the + * return-to-userspace work, like memory.high reclaim, here. + * It can sleep for a long time, so drop sqd->lock. + */ + if (test_thread_flag(TIF_NOTIFY_RESUME)) { + mutex_unlock(&sqd->lock); + resume_user_mode_work(NULL); + mutex_lock(&sqd->lock); + sqd->sq_cpu = raw_smp_processor_id(); + } + cap_entries = !list_is_singular(&sqd->ctx_list); list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { int ret; @@ -436,9 +449,10 @@ static int io_sq_thread(void *data) /* * Cancelation drops sqd->lock while it waits, and a ring could attach * to a thread that is on its way out. A fatal signal doesn't set the - * bit, so set it here for io_sq_offload_create() to see. + * stop bit, so mark the thread as exiting here for + * io_sq_offload_create() to see. */ - set_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state); + set_bit(IO_SQ_THREAD_EXITING, &sqd->state); io_uring_cancel_generic(true, sqd); rcu_assign_pointer(sqd->thread, NULL); put_task_struct(current); @@ -510,7 +524,8 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, /* don't attach to a dying SQPOLL thread, would be racy */ ret = 0; if (attached && (!sqd->thread || - test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state))) + test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state) || + test_bit(IO_SQ_THREAD_EXITING, &sqd->state))) ret = -ENXIO; io_sq_thread_unpark(sqd); diff --git a/io_uring/wait.c b/io_uring/wait.c index fb1c082993a7e0..367d49d631eca6 100644 --- a/io_uring/wait.c +++ b/io_uring/wait.c @@ -165,6 +165,14 @@ static int __io_cqring_wait_schedule(struct io_ring_ctx *ctx, { int ret = 0; + /* + * Don't arm a timer for a timeout that has already passed, it would + * only fire to return -ETIME. NAPI busy polling gets here like that. + */ + if (iowq->timeout != KTIME_MAX && + ktime_compare(io_get_time(ctx), iowq->timeout) >= 0) + return -ETIME; + /* * Mark us as being in io_wait if we have pending requests, so cpufreq * can take into account that the task is waiting for IO - turns out diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 6d7abb1636e7fc..21e042b3ccb97c 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -549,8 +549,8 @@ static int __zcrx_create_area(struct io_zcrx_ifq *ifq, if (!area->nia.niovs) goto err; - area->freelist = kvmalloc_array(nr_iovs, sizeof(area->freelist[0]), - GFP_KERNEL_ACCOUNT | __GFP_ZERO); + area->freelist = kvmalloc_objs(area->freelist[0], nr_iovs, + GFP_KERNEL_ACCOUNT | __GFP_ZERO); if (!area->freelist) goto err; diff --git a/ipc/namespace.c b/ipc/namespace.c index b54d23fd83d701..69a7c94d51dcac 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -66,7 +66,6 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, if (err) goto fail_free; - ns_tree_gen_id(ns); ns->user_ns = get_user_ns(user_ns); ns->ucounts = ucounts; @@ -87,7 +86,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, sem_init_ns(ns); shm_init_ns(ns); - ns_tree_add_raw(ns); + ns_tree_add(ns); return ns; diff --git a/ipc/sem.c b/ipc/sem.c index 5ec41de7e85b2b..b16a877911e9ed 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -1447,8 +1447,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum, } sem_unlock(sma, -1); rcu_read_unlock(); - sem_io = kvmalloc_array(nsems, sizeof(ushort), - GFP_KERNEL); + sem_io = kvmalloc_objs(ushort, nsems); if (sem_io == NULL) { ipc_rcu_putref(&sma->sem_perm, sem_rcu_free); return -ENOMEM; @@ -1482,8 +1481,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum, rcu_read_unlock(); if (nsems > SEMMSL_FAST) { - sem_io = kvmalloc_array(nsems, sizeof(ushort), - GFP_KERNEL); + sem_io = kvmalloc_objs(ushort, nsems); if (sem_io == NULL) { ipc_rcu_putref(&sma->sem_perm, sem_rcu_free); return -ENOMEM; diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c index 3c61c181a6fa97..ec2bda1a6ebf60 100644 --- a/kernel/bpf/arena.c +++ b/kernel/bpf/arena.c @@ -7,6 +7,7 @@ #include #include "linux/filter.h" #include +#include #include #include #include @@ -630,11 +631,11 @@ static unsigned long arena_get_unmapped_area(struct file *filp, unsigned long ad { struct bpf_map *map = filp->private_data; struct bpf_arena *arena = container_of(map, struct bpf_arena, map); - long ret; + unsigned long ret; if (pgoff) return -EINVAL; - if (len > SZ_4G) + if (len > (u64)map->max_entries * PAGE_SIZE) return -E2BIG; /* if user_vm_start was specified at arena creation time */ @@ -647,14 +648,22 @@ static unsigned long arena_get_unmapped_area(struct file *filp, unsigned long ad return -EINVAL; } - ret = mm_get_unmapped_area(filp, addr, len * 2, 0, flags); + /* + * Without MAP_FIXED the mm finds a free range. Ask for twice the + * length, so that there is room for round_up(). With MAP_FIXED the mm + * does no search, and the caller wants this address. Thus the range + * cannot move. + */ + ret = mm_get_unmapped_area(filp, addr, flags & MAP_FIXED ? len : len * 2, 0, flags); if (IS_ERR_VALUE(ret)) return ret; + if (!ret) + /* user_vm_start == 0 means that the user range is not set yet */ + return -EINVAL; if ((ret >> 32) == ((ret + len - 1) >> 32)) return ret; - if (WARN_ON_ONCE(arena->user_vm_start)) - /* checks at map creation time should prevent this */ - return -EFAULT; + if (flags & MAP_FIXED) + return -EINVAL; return round_up(ret, SZ_4G); } @@ -679,7 +688,7 @@ static int arena_map_mmap(struct bpf_map *map, struct vm_area_struct *vma) return -EBUSY; /* Earlier checks should prevent this */ - if (WARN_ON_ONCE(vma->vm_end - vma->vm_start > SZ_4G || vma->vm_pgoff)) + if (WARN_ON_ONCE(vma_pages(vma) > map->max_entries || vma->vm_pgoff)) return -EFAULT; if (remember_vma(arena, vma)) @@ -988,6 +997,8 @@ static int arena_free_range(struct bpf_arena *arena, long uaddr, long page_cnt) static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt, bool sleepable) { + /* The first mmap() may be setting the user range right now */ + u64 user_vm_start = READ_ONCE(arena->user_vm_start); struct mem_cgroup *new_memcg, *old_memcg; u64 full_uaddr, uaddr_end; struct arena_free_span *s; @@ -995,8 +1006,8 @@ static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt, /* only aligned lower 32-bit are relevant */ uaddr = (u32)uaddr; uaddr &= PAGE_MASK; - full_uaddr = clear_lo32(arena->user_vm_start) + uaddr; - if (full_uaddr < arena->user_vm_start) + full_uaddr = clear_lo32(user_vm_start) + uaddr; + if (!user_vm_start || full_uaddr < user_vm_start) return; uaddr_end = min(arena->user_vm_end, full_uaddr + (page_cnt << PAGE_SHIFT)); if (full_uaddr >= uaddr_end) diff --git a/kernel/bpf/backtrack.c b/kernel/bpf/backtrack.c index 43d5740034c0fd..2d6535f271a672 100644 --- a/kernel/bpf/backtrack.c +++ b/kernel/bpf/backtrack.c @@ -746,6 +746,17 @@ void bpf_mark_all_scalars_precise(struct bpf_verifier_env *env, i, -(j + 1) * 8); } } + for (j = 0; j < func->out_stack_arg_cnt; j++) { + reg = &func->stack_arg_regs[j]; + if (reg->type != SCALAR_VALUE || reg->precise) + continue; + reg->precise = true; + if (env->log.level & BPF_LOG_LEVEL2) { + verbose(env, + "force_precise: frame%d: forcing r11%d to be precise\n", + i, -(j + 1) * BPF_REG_SIZE); + } + } } } } diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index f58dce888ff4a7..468e63dbd922d0 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -411,6 +411,8 @@ BTF_ID(func, bpf_lsm_bpf_map_free) BTF_ID(func, bpf_lsm_bpf_prog_free) BTF_ID(func, bpf_lsm_file_alloc_security) BTF_ID(func, bpf_lsm_file_free_security) +BTF_ID(func, bpf_lsm_namespace_init) +BTF_ID(func, bpf_lsm_namespace_free) #ifdef CONFIG_SECURITY_NETWORK BTF_ID(func, bpf_lsm_sk_alloc_security) BTF_ID(func, bpf_lsm_sk_free_security) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 1be30487a2fa75..7e866bf017b537 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -1960,13 +1960,13 @@ static int env_resolve_init(struct btf_verifier_env *env) u32 *resolved_ids = NULL; u8 *visit_states = NULL; - resolved_sizes = kvcalloc(nr_types, sizeof(*resolved_sizes), - GFP_KERNEL | __GFP_NOWARN); + resolved_sizes = kvzalloc_objs(*resolved_sizes, nr_types, + GFP_KERNEL | __GFP_NOWARN); if (!resolved_sizes) goto nomem; - resolved_ids = kvcalloc(nr_types, sizeof(*resolved_ids), - GFP_KERNEL | __GFP_NOWARN); + resolved_ids = kvzalloc_objs(*resolved_ids, nr_types, + GFP_KERNEL | __GFP_NOWARN); if (!resolved_ids) goto nomem; @@ -6590,6 +6590,15 @@ static int find_kern_ctx_type_id(enum bpf_prog_type prog_type) return ctx_type->type; } +/* + * A projection type is the view that programs have of a kernel object with + * another layout: see btf_is_projection_of() for the two types behind them. + */ +bool btf_is_projection_type(const char *pname) +{ + return strcmp(pname, "__sk_buff") == 0 || strcmp(pname, "xdp_md") == 0; +} + bool btf_is_projection_of(const char *pname, const char *tname) { if (strcmp(pname, "__sk_buff") == 0 && strcmp(tname, "sk_buff") == 0) @@ -8483,9 +8492,8 @@ static int btf_check_func_type_match(struct bpf_verifier_log *log, } /* This is an optional check to make program writing easier. * Compare names of structs and report an error to the user. - * btf_prepare_func_args() already checked that t2 struct - * is a context type. btf_prepare_func_args() will check - * later that t1 struct is a context type as well. + * check_ext_args() compares what btf_prepare_func_args() + * derives for the two arguments. */ s1 = btf_name_by_offset(btf1, t1->name_off); s2 = btf_name_by_offset(btf2, t2->name_off); @@ -9019,6 +9027,11 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog) return err; sub->arg_slot_cnt = slots_used; + /* check_ext_args() needs them after env is freed */ + if (is_global) + memcpy(subprog_aux(env, subprog)->args, sub->args, + sizeof(subprog_aux(env, subprog)->args)); + sub->args_cached = true; return 0; diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c index 2ee950e9ac829e..1b04538351a1f5 100644 --- a/kernel/bpf/cfg.c +++ b/kernel/bpf/cfg.c @@ -868,8 +868,8 @@ int bpf_compute_scc(struct bpf_verifier_env *env) stack = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL_ACCOUNT); pre = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL_ACCOUNT); low = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL_ACCOUNT); - dfs = kvcalloc(insn_cnt, sizeof(*dfs), GFP_KERNEL_ACCOUNT); - dfs_pos = kvcalloc(insn_cnt, sizeof(*dfs_pos), GFP_KERNEL_ACCOUNT); + dfs = kvzalloc_objs(*dfs, insn_cnt, GFP_KERNEL_ACCOUNT); + dfs_pos = kvzalloc_objs(*dfs_pos, insn_cnt, GFP_KERNEL_ACCOUNT); if (!stack || !pre || !low || !dfs || !dfs_pos) { err = -ENOMEM; goto exit; diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index ce82963bcfc7dd..57a785241d42fb 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1279,9 +1279,14 @@ static struct bpf_prog_list *find_detach_entry(struct hlist_head *progs, return ERR_PTR(-ENOENT); /* to maintain backward compatibility NONE and OVERRIDE cgroups - * allow detaching with invalid FD (prog==NULL) in legacy mode + * allow detaching with invalid FD (prog==NULL) in legacy mode. + * Without the FD of the attached program the caller needs + * CAP_NET_ADMIN or CAP_SYS_ADMIN in the initial user namespace. */ - return hlist_entry(progs->first, typeof(*pl), node); + pl = hlist_entry(progs->first, typeof(*pl), node); + if (pl->prog != prog && !bpf_net_capable()) + return ERR_PTR(-EPERM); + return pl; } if (!prog && !link) @@ -1785,7 +1790,7 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk, struct sk_buff *skb, enum cgroup_bpf_attach_type atype) { - unsigned int offset = -skb_network_offset(skb); + int offset = skb_network_offset(skb); struct sock *save_sk; void *saved_data_end; struct cgroup *cgrp; @@ -1797,7 +1802,15 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk, cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); save_sk = skb->sk; skb->sk = sk; - __skb_push(skb, offset); + + /* + * The program sees the packet from its network header on, on + * whichever side of skb->data that header lies. + */ + if (offset > 0) + __skb_pull(skb, offset); + else + __skb_push(skb, -offset); /* compute pointers for the bpf prog */ bpf_compute_and_save_data_end(skb, &saved_data_end); @@ -1839,7 +1852,10 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk, ret = -EFAULT; } bpf_restore_data_end(skb, saved_data_end); - __skb_pull(skb, offset); + if (offset > 0) + __skb_push(skb, offset); + else + __skb_pull(skb, -offset); skb->sk = save_sk; return ret; diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 7cf37690d41fa4..0b8456f2dce9fb 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -206,7 +206,9 @@ void bpf_prog_jit_attempt_done(struct bpf_prog *prog) * here is relative to the prog itself instead of the main prog. * This array has one entry for each xlated bpf insn. * - * jited_off is the byte off to the end of the jited insn. + * jited_off is the byte off to the end of the jited insn, counted from + * the start of the jited image, which is cfi_get_offset() bytes before + * prog->bpf_func. * * Hence, with * insn_start: @@ -220,7 +222,7 @@ void bpf_prog_jit_attempt_done(struct bpf_prog *prog) * * For i > linfo_idx, * - * jited_linfo[i] = prog->bpf_func + + * jited_linfo[i] = prog->bpf_func - cfi_get_offset() + * insn_to_jit_off[linfo[i].insn_off - insn_start - 1] */ void bpf_prog_fill_jited_linfo(struct bpf_prog *prog, @@ -248,7 +250,7 @@ void bpf_prog_fill_jited_linfo(struct bpf_prog *prog, /* The verifier ensures that linfo[i].insn_off is * strictly increasing */ - jited_linfo[i] = prog->bpf_func + + jited_linfo[i] = prog->bpf_func - cfi_get_offset() + insn_to_jit_off[linfo[i].insn_off - insn_start - 1]; } @@ -292,6 +294,7 @@ void __bpf_prog_free(struct bpf_prog *fp) mutex_destroy(&fp->aux->used_maps_mutex); mutex_destroy(&fp->aux->dst_mutex); kfree(fp->aux->poke_tab); + free_percpu(fp->aux->timed_may_goto); kfree(fp->aux); } free_percpu(fp->stats); @@ -2919,7 +2922,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array *array, * bpf_prog_array_copy_to_user(..., cnt); * so below kcalloc doesn't need extra cnt > 0 check. */ - ids = kcalloc(cnt, sizeof(u32), GFP_USER | __GFP_NOWARN); + ids = kzalloc_objs(u32, cnt, GFP_USER | __GFP_NOWARN); if (!ids) return -ENOMEM; nospc = bpf_prog_array_copy_core(array, ids, cnt); @@ -3643,6 +3646,38 @@ u64 bpf_check_timed_may_goto(struct bpf_timed_may_goto *p) return BPF_MAX_TIMED_LOOPS; } +/* + * The main prog sets count and timestamp in its first insns. A call of an async callback is an + * invocation of its own too, but it can interrupt an invocation of the prog on this cpu, or go on + * next to one that is preempted. So its caller sets count and timestamp, and puts the old ones + * back at the end. Not when another invocation has set them in the meantime: they are for that + * one now. + * The caller has disabled migration. + */ +void bpf_timed_may_goto_save(const struct bpf_prog *prog, struct bpf_timed_may_goto *saved) +{ + struct bpf_timed_may_goto *cur; + + if (!prog->aux->timed_may_goto) + return; + cur = this_cpu_ptr(prog->aux->timed_may_goto); + *saved = *cur; + cur->count = BPF_MAX_TIMED_LOOPS; + cur->timestamp = 0; + cur->owner = saved; +} + +void bpf_timed_may_goto_restore(const struct bpf_prog *prog, struct bpf_timed_may_goto *saved) +{ + struct bpf_timed_may_goto *cur; + + if (!prog->aux->timed_may_goto) + return; + cur = this_cpu_ptr(prog->aux->timed_may_goto); + if (cur->owner == saved) + *cur = *saved; +} + /* for configs without MMU or 32-bit */ __weak const struct bpf_map_ops arena_map_ops; __weak u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena) diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c index b5204798231d43..08e12714bb95f7 100644 --- a/kernel/bpf/diagnostics.c +++ b/kernel/bpf/diagnostics.c @@ -1561,7 +1561,8 @@ static void diag_record_mod(struct bpf_verifier_env *env, u32 insn_idx, if (origin) { event.mod.origin = *origin; event.mod.origin_valid = true; - } else if (diag_mod_insn_origin(env, insn_idx, &target, &event.mod.origin)) { + } else if (reason != BPF_DIAG_MOD_SLICE_BUF && /* the insn writes the buffer */ + diag_mod_insn_origin(env, insn_idx, &target, &event.mod.origin)) { event.mod.origin_valid = true; } if (old_reg && new_reg && reason == BPF_DIAG_MOD_WRITE && @@ -2237,6 +2238,9 @@ static void diag_print_mod(struct bpf_verifier_env *env, const struct bpf_diag_h case BPF_DIAG_MOD_PKT_DATA_CHANGE: reason = "packet data may have moved"; break; + case BPF_DIAG_MOD_SLICE_BUF: + reason = "the stack buffer of this dynptr slice was written, or its frame returned"; + break; case BPF_DIAG_MOD_NON_OWN_REF: reason = "leaving the protected region invalidated this borrowed pointer"; break; diff --git a/kernel/bpf/diagnostics.h b/kernel/bpf/diagnostics.h index a4102fb049ece4..490decc133f6c1 100644 --- a/kernel/bpf/diagnostics.h +++ b/kernel/bpf/diagnostics.h @@ -23,6 +23,7 @@ enum bpf_diag_mod_reason { BPF_DIAG_MOD_VAR_WRITE, BPF_DIAG_MOD_REF_RELEASE, BPF_DIAG_MOD_PKT_DATA_CHANGE, + BPF_DIAG_MOD_SLICE_BUF, BPF_DIAG_MOD_NON_OWN_REF, BPF_DIAG_MOD_CALLER_SAVED, }; diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c index 41bc37e205e0f2..a656634fa9e468 100644 --- a/kernel/bpf/fixups.c +++ b/kernel/bpf/fixups.c @@ -1803,6 +1803,50 @@ static int may_goto_expand(struct bpf_insn *insn_buf, int off, int stack_off, return cnt + tail_cnt; } +/* + * Timed may_goto. All may_goto of a prog use one count and one timestamp: per-cpu memory of the + * prog, set in the first insns of the main prog, and by the callers of async callbacks. + * @reg holds the address. It is a register that is dead at the may_goto, or R0 that is saved at + * @save_off in the stack. + */ +static int may_goto_expand_timed(struct bpf_insn *insn_buf, int off, + struct bpf_timed_may_goto __percpu *tmg, int reg, int save_off) +{ + struct bpf_insn ld_tmg[] = { BPF_LD_IMM64(reg, (__force unsigned long)tmg) }; + int cnt = 0, jmp, tail_cnt = save_off ? 6 : 5; + + if (save_off) + insn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_10, reg, save_off); + insn_buf[cnt++] = ld_tmg[0]; + insn_buf[cnt++] = ld_tmg[1]; + insn_buf[cnt++] = BPF_MOV64_PERCPU_REG(reg, reg); + insn_buf[cnt++] = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, reg, 0); + if (save_off) { + insn_buf[cnt++] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2); + insn_buf[cnt++] = BPF_LDX_MEM(BPF_DW, reg, BPF_REG_10, save_off); + jmp = cnt++; + insn_buf[jmp] = BPF_JMP32_A(off >= 0 ? off + tail_cnt : off - jmp); + } else { + jmp = cnt; + off = off >= 0 ? off + tail_cnt : off - jmp; + if (off == (s16)off) { + insn_buf[cnt++] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, off); + } else { + insn_buf[cnt++] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 1); + insn_buf[cnt++] = BPF_JMP32_A(off >= 0 ? off : off - 1); + } + } + insn_buf[cnt++] = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1); + insn_buf[cnt++] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2); + /* AX is the argument and the return value */ + insn_buf[cnt++] = BPF_MOV64_REG(BPF_REG_AX, reg); + insn_buf[cnt++] = BPF_EMIT_CALL(arch_bpf_timed_may_goto); + insn_buf[cnt++] = BPF_STX_MEM(BPF_DW, reg, BPF_REG_AX, 0); + if (save_off) + insn_buf[cnt++] = BPF_LDX_MEM(BPF_DW, reg, BPF_REG_10, save_off); + return cnt; +} + /* Do various post-verification rewrites in a single program pass. * These rewrites simplify JIT and interpreter implementations. */ @@ -1823,6 +1867,9 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) struct bpf_subprog_info *subprogs = env->subprog_info; u16 stack_depth = subprogs[cur_subprog].stack_depth; u16 stack_depth_extra = 0; + /* arch_bpf_timed_may_goto() takes and returns AX in a cpu register: for JITs only */ + bool timed_may_goto = prog->jit_requested && bpf_jit_supports_timed_may_goto(); + struct bpf_timed_may_goto __percpu *tmg = NULL; if (env->seen_exception && !env->exception_callback_subprog) { struct bpf_insn *patch = insn_buf; @@ -2078,38 +2125,28 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) goto next_insn; } - if (bpf_is_may_goto_insn(insn) && bpf_jit_supports_timed_may_goto()) { - int stack_off_cnt = -stack_depth - 16; - /* - * AX is used as an argument to pass in stack_off_cnt - * (to add to r10/fp), and also as the return value of - * the call to arch_bpf_timed_may_goto. - */ - struct bpf_insn tail[] = { - BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1), - BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2), - BPF_MOV64_IMM(BPF_REG_AX, stack_off_cnt), - BPF_EMIT_CALL(arch_bpf_timed_may_goto), - BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off_cnt), - }; + if (bpf_is_may_goto_insn(insn) && timed_may_goto) { + u16 live = env->insn_aux_data[i + delta].live_regs_before; + int reg, save_off = 0; - /* - * Two 8 byte slots, depth-16 stores the count, and - * depth-8 stores the start timestamp of the loop. - * - * The starting value of count is BPF_MAX_TIMED_LOOPS - * (0xffff). Every iteration loads it and subs it by 1, - * until the value becomes 0 in AX (thus, 1 in stack), - * after which we call arch_bpf_timed_may_goto, which - * either sets AX to 0xffff to keep looping, or to 0 - * upon timeout. AX is then stored into the stack. In - * the next iteration, we either see 0 and break out, or - * continue iterating until the next time value is 0 - * after subtraction, rinse and repeat. - */ - stack_depth_extra = 16; - cnt = may_goto_expand(insn_buf, insn->off, stack_off_cnt, - tail, ARRAY_SIZE(tail)); + /* a register that is dead here holds the address of the count */ + for (reg = BPF_REG_0; reg <= BPF_REG_9; reg++) + if (!(live & BIT(reg))) + break; + if (reg > BPF_REG_9) { + reg = BPF_REG_0; + save_off = -stack_depth - 8; + stack_depth_extra = 8; + } + if (!tmg) { + tmg = alloc_percpu_gfp(struct bpf_timed_may_goto, + GFP_KERNEL_ACCOUNT); + if (!tmg) + return -ENOMEM; + prog->aux->timed_may_goto = tmg; + } + prog->jit_required = 1; + cnt = may_goto_expand_timed(insn_buf, insn->off, tmg, reg, save_off); new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); if (!new_prog) @@ -2730,24 +2767,52 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) env->prog->aux->stack_depth = subprogs[0].stack_depth; for (i = 0; i < env->subprog_cnt; i++) { - int delta = bpf_jit_supports_timed_may_goto() ? 2 : 1; int subprog_start = subprogs[i].start; int stack_slots = subprogs[i].stack_extra / 8; - int slots = delta, cnt = 0; - - if (!stack_slots) + /* an invocation begins, see bpf_timed_may_goto_save() for async callbacks */ + bool main_prog = tmg && !i; + /* only a helper calls it, in a loop that ends when it returns 1 */ + bool loop_cb = tmg && i && subprogs[i].is_loop_cb && !subprogs[i].is_called && + !subprogs[i].is_async_cb; + int cnt = 0; + + if (timed_may_goto ? !main_prog && !loop_cb : !stack_slots) continue; - /* We need two slots in case timed may_goto is supported. */ - if (stack_slots > slots) { + if (stack_slots > 1) { verifier_bug(env, "stack_slots supports may_goto only"); return -EFAULT; } stack_depth = subprogs[i].stack_depth; - if (bpf_jit_supports_timed_may_goto()) { - insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth, - BPF_MAX_TIMED_LOOPS); - insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth + 8, 0); + if (timed_may_goto) { + struct bpf_insn ld_tmg[] = { + BPF_LD_IMM64(BPF_REG_0, (__force unsigned long)tmg) + }; + int count_off = offsetof(struct bpf_timed_may_goto, count); + int timestamp_off = offsetof(struct bpf_timed_may_goto, timestamp); + int owner_off = offsetof(struct bpf_timed_may_goto, owner); + + /* R0 has nothing at the entry */ + insn_buf[cnt++] = ld_tmg[0]; + insn_buf[cnt++] = ld_tmg[1]; + insn_buf[cnt++] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); + if (main_prog) { + insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_0, count_off, + BPF_MAX_TIMED_LOOPS); + insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_0, timestamp_off, 0); + insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_0, owner_off, 0); + } else { + /* + * The time is up, but the helper would call the function again and + * again. End its loop. The verifier has seen that: the loop can end + * after each call. + */ + insn_buf[cnt++] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, + count_off); + insn_buf[cnt++] = BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2); + insn_buf[cnt++] = BPF_MOV64_IMM(BPF_REG_0, 1); + insn_buf[cnt++] = BPF_EXIT_INSN(); + } } else { /* Add ST insn to subprog prologue to init extra stack */ insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth, @@ -2774,7 +2839,7 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) * to insn after BPF_ST that inits may_goto count. * Adjustment will succeed because bpf_patch_insn_data() didn't fail. */ - WARN_ON(adjust_jmp_off(env->prog, subprog_start, delta)); + WARN_ON(adjust_jmp_off(env->prog, subprog_start, cnt - 1)); } /* Since poke tab is now finalized, publish aux to tracker. */ diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index bf78e09f4d5189..6e2115477cb9e0 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -94,10 +94,10 @@ struct bpf_htab { struct bpf_lru lru; }; struct htab_elem *__percpu *extra_elems; - /* number of elements in non-preallocated hashtable are kept - * in either pcount or count + /* number of elements in non-preallocated hashtable. With + * use_percpu_counter it only follows map.elem_count in steps of + * PERCPU_COUNTER_BATCH, see is_map_full() */ - struct percpu_counter pcount; atomic_t count; bool use_percpu_counter; bool has_hash; @@ -739,29 +739,20 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) htab_init_buckets(htab); -/* compute_batch_value() computes batch value as num_online_cpus() * 2 - * and __percpu_counter_compare() needs - * htab->max_entries - cur_number_of_elems to be more than batch * num_online_cpus() - * for percpu_counter to be faster than atomic_t. In practice the average bpf - * hash map size is 10k, which means that a system with 64 cpus will fill - * hashmap to 20% of 10k before percpu_counter becomes ineffective. Therefore - * define our own batch count as 32 then 10k hash map can be filled up to 80%: +/* is_map_full() needs htab->max_entries - cur_number_of_elems to be more than + * batch * nr_cpu_ids for the percpu counter to be faster than atomic_t. In + * practice the average bpf hash map size is 10k. With batch count of 32 a 10k + * hash map on a system with 64 cpus can be filled up to 80%: * 10k - 8k > 32 _batch_ * 64 _cpus_ - * and __percpu_counter_compare() will still be fast. At that point hash map + * and is_map_full() will still be fast. At that point hash map * collisions will dominate its performance anyway. Assume that hash map filled * to 50+% isn't going to be O(1) and use the following formula to choose - * between percpu_counter and atomic_t. + * between the percpu counter and atomic_t. The batch has to be a power of 2. */ #define PERCPU_COUNTER_BATCH 32 - if (attr->max_entries / 2 > num_online_cpus() * PERCPU_COUNTER_BATCH) + if (attr->max_entries / 2 > nr_cpu_ids * PERCPU_COUNTER_BATCH) htab->use_percpu_counter = true; - if (htab->use_percpu_counter) { - err = percpu_counter_init(&htab->pcount, 0, GFP_KERNEL); - if (err) - goto free_map_locked; - } - if (prealloc) { err = prealloc_init(htab); if (err) @@ -789,8 +780,6 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) free_prealloc: prealloc_destroy(htab); free_map_locked: - if (htab->use_percpu_counter) - percpu_counter_destroy(&htab->pcount); bpf_map_area_free(htab->buckets); bpf_mem_alloc_destroy(&htab->pcpu_ma); bpf_mem_alloc_destroy(&htab->ma); @@ -1162,30 +1151,33 @@ static void htab_put_fd_value(struct bpf_htab *htab, struct htab_elem *l) static bool is_map_full(struct bpf_htab *htab) { - if (htab->use_percpu_counter) - return __percpu_counter_compare(&htab->pcount, htab->map.max_entries, - PERCPU_COUNTER_BATCH) >= 0; - return atomic_read(&htab->count) >= htab->map.max_entries; + s64 count = atomic_read(&htab->count); + + /* each cpu's elem_count is ahead of count by less than the batch */ + if (htab->use_percpu_counter && + count + nr_cpu_ids * PERCPU_COUNTER_BATCH >= htab->map.max_entries) + count = bpf_map_sum_elem_count(&htab->map); + return count >= htab->map.max_entries; } static void inc_elem_count(struct bpf_htab *htab) { - bpf_map_inc_elem_count(&htab->map); + s64 cnt = this_cpu_inc_return(*htab->map.elem_count); - if (htab->use_percpu_counter) - percpu_counter_add_batch(&htab->pcount, 1, PERCPU_COUNTER_BATCH); - else + if (!htab->use_percpu_counter) atomic_inc(&htab->count); + else if (!(cnt & (PERCPU_COUNTER_BATCH - 1))) + atomic_add(PERCPU_COUNTER_BATCH, &htab->count); } static void dec_elem_count(struct bpf_htab *htab) { - bpf_map_dec_elem_count(&htab->map); + s64 cnt = this_cpu_dec_return(*htab->map.elem_count); - if (htab->use_percpu_counter) - percpu_counter_add_batch(&htab->pcount, -1, PERCPU_COUNTER_BATCH); - else + if (!htab->use_percpu_counter) atomic_dec(&htab->count); + else if (!((cnt + 1) & (PERCPU_COUNTER_BATCH - 1))) + atomic_sub(PERCPU_COUNTER_BATCH, &htab->count); } static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l) @@ -1866,8 +1858,6 @@ static void htab_map_free(struct bpf_map *map) bpf_map_area_free(htab->buckets); bpf_mem_alloc_destroy(&htab->pcpu_ma); bpf_mem_alloc_destroy(&htab->ma); - if (htab->use_percpu_counter) - percpu_counter_destroy(&htab->pcount); bpf_map_area_free(htab); } @@ -2577,9 +2567,7 @@ static u64 htab_map_mem_usage(const struct bpf_map *map) } else { #define LLIST_NODE_SZ sizeof(struct llist_node) - num_entries = htab->use_percpu_counter ? - percpu_counter_sum(&htab->pcount) : - atomic_read(&htab->count); + num_entries = bpf_map_sum_elem_count(map); usage += (htab->elem_size + LLIST_NODE_SZ) * num_entries; if (percpu) { usage += (LLIST_NODE_SZ + sizeof(void *)) * num_entries; diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 58e357302850e3..6788489a2608b3 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1222,6 +1222,8 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer) { struct bpf_hrtimer *t = container_of(hrtimer, struct bpf_hrtimer, timer); struct bpf_map *map = READ_ONCE(t->cb.map); + struct bpf_prog *prog = READ_ONCE(t->cb.prog); + struct bpf_timed_may_goto saved; void *value = t->cb.value; bpf_callback_t callback_fn; void *key; @@ -1229,7 +1231,7 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer) BTF_TYPE_EMIT(struct bpf_timer); callback_fn = rcu_dereference_check(t->cb.callback_fn, rcu_read_lock_bh_held()); - if (!callback_fn || !map) + if (!callback_fn || !map || !prog) goto out; /* bpf_timer_cb() runs in hrtimer_run_softirq. It doesn't migrate and @@ -1242,8 +1244,10 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer) key = map_key_from_value(map, value, &idx); + bpf_timed_may_goto_save(prog, &saved); callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0); /* The verifier checked that return value is zero. */ + bpf_timed_may_goto_restore(prog, &saved); this_cpu_write(hrtimer_running, NULL); out: @@ -1254,6 +1258,8 @@ static void bpf_wq_work(struct work_struct *work) { struct bpf_work *w = container_of(work, struct bpf_work, work); struct bpf_async_cb *cb = &w->cb; + struct bpf_timed_may_goto saved; + struct bpf_prog *prog; struct bpf_map *map; bpf_callback_t callback_fn; void *value = cb->value; @@ -1267,14 +1273,17 @@ static void bpf_wq_work(struct work_struct *work) map = READ_ONCE(cb->map); callback_fn = READ_ONCE(cb->callback_fn); - if (!callback_fn || !map) + prog = READ_ONCE(cb->prog); + if (!callback_fn || !map || !prog) goto out; key = map_key_from_value(map, value, &idx); migrate_disable(); + bpf_timed_may_goto_save(prog, &saved); callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0); + bpf_timed_may_goto_restore(prog, &saved); migrate_enable(); out: @@ -3088,6 +3097,10 @@ __bpf_kfunc struct task_struct *bpf_task_from_vpid(s32 vpid) * bpf_dynptr_slice will not invalidate any ctx->data/data_end pointers in * the bpf program. * + * Please also note that when the buffer is on the stack, the verifier invalidates + * the returned pointer when the program stores to the buffer (helpers and kfuncs + * may fill it), or returns from the function that has it. + * * Return: NULL if the call failed (eg invalid dynptr), pointer to a read-only * data slice (can be either direct pointer to the data or a pointer to the user * provided buffer, with its contents containing the data, if unable to obtain @@ -3173,6 +3186,12 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, * Please note that, as in the example above, the user must check that the * returned pointer is not null before using it. * + * Please also note that when the buffer is on the stack, the verifier invalidates + * the returned pointer when the program stores to the buffer (helpers and kfuncs + * may fill it), or returns from the function that has it. Change the data through + * the returned pointer, and before the comparison with the buffer, as in the + * example above: after it the compiler may use one pointer in place of the other. + * * Please also note that in the case of skb and xdp dynptrs, bpf_dynptr_slice_rdwr * does not change the underlying packet data pointers, so a call to * bpf_dynptr_slice_rdwr will not invalidate any ctx->data/data_end pointers in @@ -3294,8 +3313,10 @@ __bpf_kfunc int bpf_dynptr_copy(const struct bpf_dynptr *dst_ptr, u64 dst_off, { const struct bpf_dynptr_kern *dst = (struct bpf_dynptr_kern *)dst_ptr; const struct bpf_dynptr_kern *src = (struct bpf_dynptr_kern *)src_ptr; + bool same = src->data == dst->data; void *src_slice, *dst_slice; char buf[256]; + bool rev; u64 off; src_slice = bpf_dynptr_slice(src_ptr, src_off, NULL, size); @@ -3306,25 +3327,31 @@ __bpf_kfunc int bpf_dynptr_copy(const struct bpf_dynptr *dst_ptr, u64 dst_off, return 0; } - if (src_slice) + /* The other range is copied piece by piece. A slice of the same packet + * may overlap with it, so it cannot be the buffer for that. + */ + if (src_slice && !same) return __bpf_dynptr_write(dst, dst_off, src_slice, size, 0); - if (dst_slice) + if (dst_slice && !same) return __bpf_dynptr_read(dst_slice, size, src, src_off, 0); if (bpf_dynptr_check_off_len(dst, dst_off, size) || bpf_dynptr_check_off_len(src, src_off, size)) return -E2BIG; + /* like memmove(): from the end if the destination is above the source */ + rev = same && dst->offset + dst_off > src->offset + src_off; off = 0; while (off < size) { u64 chunk_sz = min_t(u64, sizeof(buf), size - off); + u64 pos = rev ? size - off - chunk_sz : off; int err; - err = __bpf_dynptr_read(buf, chunk_sz, src, src_off + off, 0); + err = __bpf_dynptr_read(buf, chunk_sz, src, src_off + pos, 0); if (err) return err; - err = __bpf_dynptr_write(dst, dst_off + off, buf, chunk_sz, 0); + err = __bpf_dynptr_write(dst, dst_off + pos, buf, chunk_sz, 0); if (err) return err; @@ -4593,6 +4620,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx, static void bpf_task_work_callback(struct callback_head *cb) { struct bpf_task_work_ctx *ctx = container_of(cb, struct bpf_task_work_ctx, work); + struct bpf_timed_may_goto saved; enum bpf_task_work_state state; u32 idx; void *key; @@ -4614,8 +4642,10 @@ static void bpf_task_work_callback(struct callback_head *cb) key = (void *)map_key_from_value(ctx->map, ctx->map_val, &idx); migrate_disable(); + bpf_timed_may_goto_save(ctx->prog, &saved); ctx->callback_fn((u64)(long)ctx->map, (u64)(long)key, (u64)(long)ctx->map_val, 0, 0); + bpf_timed_may_goto_restore(ctx->prog, &saved); migrate_enable(); bpf_task_work_ctx_reset(ctx); @@ -4855,6 +4885,7 @@ static void bpf_rcu_run_callback(struct rcu_head *rcu) struct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu); bpf_callback_t callback_fn = rh->callback_fn; struct bpf_prog *prog = rh->prog; + struct bpf_timed_may_goto saved; struct bpf_map *map = rh->map; void *value, *key; u32 idx; @@ -4866,7 +4897,9 @@ static void bpf_rcu_run_callback(struct rcu_head *rcu) smp_store_release(&rh->armed, 0); rcu_read_lock_dont_migrate(); + bpf_timed_may_goto_save(prog, &saved); callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0); + bpf_timed_may_goto_restore(prog, &saved); rcu_read_unlock_migrate(); bpf_prog_put(prog); diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c index e657e6d95408f4..75d9af4921dec4 100644 --- a/kernel/bpf/liveness.c +++ b/kernel/bpf/liveness.c @@ -976,6 +976,19 @@ static struct arg_track arg_join_imprecise(struct arg_track a, struct arg_track return (struct arg_track){ .mask = m, .frame = ARG_IMPRECISE }; } +/* + * 'a' or a value that is not a pointer to stack. A single fp-N gets a fake fp+0, + * to keep stack_use and prevent stack_def. fp+0 itself would stay a single offset. + */ +static struct arg_track arg_or_none(struct arg_track a) +{ + if (a.off_cnt != 1) + return a; + if (!a.off[0]) + return (struct arg_track){ .frame = a.frame }; + return arg_merge_offsets(a, arg_single(a.frame, 0)); +} + /* Join two arg_track values at merge points */ static struct arg_track __arg_track_join(struct arg_track a, struct arg_track b) { @@ -1000,20 +1013,10 @@ static struct arg_track __arg_track_join(struct arg_track a, struct arg_track b) */ if (a.frame == ARG_NONE && b.frame == ARG_NONE) return a; - if (a.frame >= 0 && b.frame == ARG_NONE) { - /* - * When joining single fp-N add fake fp+0 to - * keep stack_use and prevent stack_def - */ - if (a.off_cnt == 1) - return arg_merge_offsets(a, arg_single(a.frame, 0)); - return a; - } - if (b.frame >= 0 && a.frame == ARG_NONE) { - if (b.off_cnt == 1) - return arg_merge_offsets(b, arg_single(b.frame, 0)); - return b; - } + if (a.frame >= 0 && b.frame == ARG_NONE) + return arg_or_none(a); + if (b.frame >= 0 && a.frame == ARG_NONE) + return arg_or_none(b); return arg_join_imprecise(a, b); } @@ -1380,6 +1383,31 @@ static struct arg_track arg_track_deref(struct bpf_verifier_env *env, struct bpf return (struct arg_track){ .frame = ARG_NONE }; } +/* + * True if the call at @insn_idx can pass a pointer to the frame at @depth to a static subprog + * or to a callback. They use it as a pointer to stack, a global subprog gets plain memory. + * It errs on the safe side: it looks at all argument registers and stack args, also at those + * that this callee doesn't take. + */ +static bool subprog_gets_local_fp(struct bpf_verifier_env *env, struct bpf_insn *insn, int insn_idx, + struct arg_track *at, int depth) +{ + int r; + + if (bpf_pseudo_call(insn)) { + r = bpf_find_subprog(env, insn_idx + insn->imm + 1); + if (r >= 0 && bpf_subprog_is_global(env, r)) + return false; + } else if (!bpf_is_callx(insn) && !bpf_calls_callback(env, insn_idx)) { + return false; + } + /* R1-R5 and stack args */ + for (r = BPF_REG_1; r < MAX_AT_TRACK_REGS; r++) + if ((r <= BPF_REG_5 || r >= MAX_BPF_REG) && can_be_local_fp(depth, r, &at[r])) + return true; + return false; +} + /* * Pure dataflow transfer function for arg_track state. * Updates at_out[] based on how the instruction modifies registers. @@ -1443,21 +1471,22 @@ static void arg_track_xfer(struct bpf_verifier_env *env, struct bpf_insn *insn, *dst = none; } else if (class == BPF_JMP && code == BPF_CALL) { /* - * at_stack_out[slot] is not cleared by the helper and subprog calls. - * The fill_from_stack() may return the stale spill — which is an FP-derived arg_track - * (the value that was originally spilled there). The loaded register then carries - * a phantom FP-derived identity that doesn't correspond to what's actually in the slot. - * This phantom FP pointer propagates forward, and wherever it's subsequently used - * (as a helper argument, another store, etc.), it sets stack liveness bits. - * Those bits correspond to stack accesses that don't actually happen. - * So the effect is over-reporting stack liveness — marking slots as live that aren't - * actually accessed. The verifier preserves more state than necessary across calls, - * which is conservative. + * Helpers, kfuncs and global subprogs can scratch stack slots. The verifier reads + * a scalar from a scratched slot, but at_stack_out[slot] is not cleared, and + * fill_from_stack() returns the stale spill: an FP-derived arg_track for a scalar. + * A scalar can't be dereferenced, so the stale value can only set liveness bits + * for stack accesses that don't happen. That is conservative. * - * helpers can scratch stack slots, but they won't make a valid pointer out of it. - * subprogs are allowed to write into parent slots, but they cannot write - * _any_ FP-derived pointer into it (either their own or parent's FP). + * Static subprogs and callbacks can't store an FP-derived pointer into the frame of + * the caller, but they can store any other pointer there. The caller can fill it + * and store through it. With the stale spill that store would be a definite write + * to a stack slot, and it doesn't touch the stack. Callees are analyzed after the + * caller, and they reach the whole frame from one pointer to it. So after the call + * every slot holds what it held before or a value that is not FP-derived. */ + if (subprog_gets_local_fp(env, insn, insn_idx, at_out, depth)) + for (slot = 0; slot < nslots; slot++) + at_stack_out[slot] = __arg_track_join(at_stack_out[slot], none); for (r = BPF_REG_0; r <= BPF_REG_5; r++) at_out[r] = none; } else if (class == BPF_LDX) { diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c index fa29d9b994e4c8..916408c6335506 100644 --- a/kernel/bpf/log.c +++ b/kernel/bpf/log.c @@ -684,6 +684,8 @@ static void print_reg_state(struct bpf_verifier_env *env, if (base_type(t) == PTR_TO_MEM) { verbose_a("sz="); verbose_unum(env, reg->mem_size); + if (reg->buf.size) + verbose_a("buf=fp[%u]%d+%u", reg->buf.frameno, reg->buf.off, reg->buf.size); } if (t == CONST_PTR_TO_DYNPTR) verbose_a("type=%s", dynptr_type_str(reg->dynptr.type)); diff --git a/kernel/bpf/loops.c b/kernel/bpf/loops.c index 2568079c294515..fee2c6081135a2 100644 --- a/kernel/bpf/loops.c +++ b/kernel/bpf/loops.c @@ -29,7 +29,7 @@ static struct bpf_iarray **compute_predecessors(struct bpf_verifier_env *env) size_t sz; void *tmp; - num_preds = kvcalloc(prog->len, sizeof(u32), GFP_KERNEL_ACCOUNT); + num_preds = kvzalloc_objs(u32, prog->len, GFP_KERNEL_ACCOUNT); if (!num_preds) return NULL; @@ -156,7 +156,7 @@ int bpf_compute_idoms(struct bpf_verifier_env *env) if (!preds) return -ENOMEM; - idoms = kvcalloc(len, sizeof(*idoms), GFP_KERNEL_ACCOUNT); + idoms = kvzalloc_objs(*idoms, len, GFP_KERNEL_ACCOUNT); if (!idoms) { kvfree(preds); return -ENOMEM; @@ -216,7 +216,8 @@ static int add_exit(struct bpf_loop *loop, int from, int to) return 0; } if (!loop->exits) { - loop->exits = kvcalloc(MAX_LOOP_EXITS, sizeof(*loop->exits), GFP_KERNEL_ACCOUNT); + loop->exits = kvzalloc_objs(*loop->exits, MAX_LOOP_EXITS, + GFP_KERNEL_ACCOUNT); if (!loop->exits) return -ENOMEM; } @@ -467,9 +468,9 @@ int bpf_compute_loops(struct bpf_verifier_env *env) struct bpf_iarray *succ; struct bpf_loop *loop; - dfs.dfs_pos = kvcalloc(len, sizeof(int), GFP_KERNEL_ACCOUNT); - dfs.state = kvcalloc(len, sizeof(struct dfs_state), GFP_KERNEL_ACCOUNT); - dfs.stack = kvcalloc(len, sizeof(int), GFP_KERNEL_ACCOUNT); + dfs.dfs_pos = kvzalloc_objs(int, len, GFP_KERNEL_ACCOUNT); + dfs.state = kvzalloc_objs(struct dfs_state, len, GFP_KERNEL_ACCOUNT); + dfs.stack = kvzalloc_objs(int, len, GFP_KERNEL_ACCOUNT); if (!dfs.dfs_pos || !dfs.state || !dfs.stack) { err = -ENOMEM; goto out; diff --git a/kernel/bpf/scev.c b/kernel/bpf/scev.c index 7b82fd79f9cc98..db123ef1f0718d 100644 --- a/kernel/bpf/scev.c +++ b/kernel/bpf/scev.c @@ -518,7 +518,7 @@ static struct env *get_loop_env(struct scev *scev, int loop_header, int insn_idx if (e) return e; - e = kzalloc(sizeof(*e), GFP_KERNEL_ACCOUNT); + e = kzalloc_obj(*e, GFP_KERNEL_ACCOUNT); if (!e) return NULL; @@ -1276,11 +1276,11 @@ static int compute_scev_for_loop(struct bpf_verifier_env *env, int cur_header) return 0; } - cur_env = kzalloc(sizeof(*cur_env), GFP_KERNEL_ACCOUNT); + cur_env = kzalloc_obj(*cur_env, GFP_KERNEL_ACCOUNT); if (!cur_env) goto nomem; if (log_level2) { - old_env = kzalloc(sizeof(*old_env), GFP_KERNEL_ACCOUNT); + old_env = kzalloc_obj(*old_env, GFP_KERNEL_ACCOUNT); if (!old_env) goto nomem; } @@ -1725,7 +1725,7 @@ int bpf_init_scev(struct bpf_verifier_env *env) { struct scev *scev; - scev = kzalloc(sizeof(struct scev), GFP_KERNEL_ACCOUNT); + scev = kzalloc_obj(struct scev, GFP_KERNEL_ACCOUNT); if (!scev) return -ENOMEM; env->scev = scev; @@ -1733,13 +1733,16 @@ int bpf_init_scev(struct bpf_verifier_env *env) bpf_mark_reg_unknown_imprecise(&scev->unknown_reg); /* A power of two for hash & (exprs_ht_cnt - 1)` indexing. */ scev->exprs_ht_cnt = roundup_pow_of_two(max(256U, DIV_ROUND_UP(env->prog->len, 4))); - scev->exprs_ht = kvcalloc(scev->exprs_ht_cnt, sizeof(*scev->exprs_ht), GFP_KERNEL_ACCOUNT); + scev->exprs_ht = kvzalloc_objs(*scev->exprs_ht, scev->exprs_ht_cnt, + GFP_KERNEL_ACCOUNT); if (!scev->exprs_ht) goto nomem; if (expr0(scev, UNKNOWN) < 0 || expr0(scev, OPAQUE) < 0) goto nomem; - scev->envs = kvcalloc(env->prog->len, sizeof(*scev->envs), GFP_KERNEL_ACCOUNT); - scev->discovered = kvcalloc(env->prog->len, sizeof(*scev->discovered), GFP_KERNEL_ACCOUNT); + scev->envs = kvzalloc_objs(*scev->envs, env->prog->len, + GFP_KERNEL_ACCOUNT); + scev->discovered = kvzalloc_objs(*scev->discovered, env->prog->len, + GFP_KERNEL_ACCOUNT); if (!scev->envs || !scev->discovered) goto nomem; /* @@ -1831,7 +1834,11 @@ scev_reg_for_read(struct bpf_verifier_env *env, const struct bpf_func_state *st, return zero ? &env->scev->zero_reg : &env->scev->unknown_reg; } -/* Materialize a writable value in the current state, growing its stack if needed. */ +/* + * Materialize a writable value in the current state, growing its stack if needed. + * This does not go through check_stack_write(). The callers skip is_unbound_scev_reg() slots, + * thus the buffer of a live dynptr slice, see bpf_reg_state::buf, does not become a spill here. + */ static int scev_reg_for_write(struct bpf_verifier_env *env, struct bpf_func_state *st, u32 r, struct bpf_reg_state **out) { @@ -2762,6 +2769,7 @@ static int union_any_reg(struct bpf_verifier_env *env, struct bpf_func_state *lo const struct bpf_reg_state *leaf_reg; struct scev *scev = env->scev; u32 l, r, leaf, order; + s64 smax = reg_smax(acc); s64 imm; int err; @@ -2785,10 +2793,13 @@ static int union_any_reg(struct bpf_verifier_env *env, struct bpf_func_state *lo verifier_bug(env, "scev ANY union has an unsupported leaf"); return -EFAULT; } + smax = max(smax, reg_smax(leaf_reg)); err = bpf_reg_union(env, acc, leaf_reg); if (err) return err; } + /* All leaves have the same range. It goes with the largest offset of all leaves. */ + bpf_trim_pkt_range(acc, smax); return 0; } @@ -2837,6 +2848,9 @@ int bpf_widen_scev_regs(struct bpf_verifier_env *env, struct bpf_verifier_state bpf_log(log, "\n"); } scratch_widened_reg_id(env, reg); + /* "at pkt_end" and "beyond pkt_end" are not valid in all iterations */ + if (type_is_pkt_pointer(reg->type)) + reg->range = max(reg->range, 0); err = bpf_set_reg_range(env, reg, bounds.r64, bounds.r32, bounds.base, bounds.step); if (err) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index f7e8d766d12834..a19126f5db0292 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -522,12 +522,14 @@ static int stackid_init(struct stackid *stackid, struct bpf_map *map, u32 skip = flags & BPF_F_SKIP_FIELD_MASK; u32 max_depth; + max_depth = stack_map_calculate_max_depth(map->value_size, stack_map_data_size(map), flags); + /* trace_nr can be above max_depth and max_depth below skip: clamp first */ + trace_nr = min_t(u32, trace_nr, max_depth); if (trace_nr <= skip) /* skipping more than usable stack trace */ return -EFAULT; - max_depth = stack_map_calculate_max_depth(map->value_size, stack_map_data_size(map), flags); - stackid->nr = min_t(u32, trace_nr - skip, max_depth - skip); + stackid->nr = trace_nr - skip; stackid->len = stackid->nr * sizeof(u64); stackid->ips = trace->ip + skip; stackid->hash = jhash2((const u32 *)stackid->ips, stackid->len / sizeof(u32), 0); @@ -642,7 +644,8 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map, /* couldn't fetch the stack trace */ return -EFAULT; - err = stackid_fastpath(&stackid, map, trace, trace->nr, flags); + /* the entry is released already, an NMI can change trace->nr */ + err = stackid_fastpath(&stackid, map, trace, READ_ONCE(trace->nr), flags); if (err != -ENOENT) return err; @@ -822,14 +825,20 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task, crosstask, false, 0); } - if (unlikely(!trace) || trace->nr < skip) { - if (may_fault) - rcu_read_unlock(); - preempt_enable(); - goto err_fault; - } + if (unlikely(!trace)) + goto err_unlock; - trace_nr = callchain_store(trace, trace->nr, buf, elem_size, flags); + /* + * trace->nr can be above max_depth. The per-CPU entry is released + * already: a tracing program or an NMI which takes a callchain in the + * same context before the copy below reuses it. And the unwinders of + * PowerPC store context markers on top of max_depth. + */ + trace_nr = min_t(u32, READ_ONCE(trace->nr), max_depth); + if (trace_nr < skip) + goto err_unlock; + + trace_nr = callchain_store(trace, trace_nr, buf, elem_size, flags); /* trace should not be dereferenced after this point */ if (may_fault) @@ -838,6 +847,10 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task, return callchain_finalize(buf, size, trace_nr, elem_size, flags, may_fault); +err_unlock: + if (may_fault) + rcu_read_unlock(); + preempt_enable(); err_fault: err = -EFAULT; clear: diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c index a6ae86f973e359..50480c42bcad1e 100644 --- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -1116,6 +1116,20 @@ static int propagate_precision(struct bpf_verifier_env *env, bpf_bt_set_frame_slot(&env->bt, fr, i); first = false; } + for (i = 0; i < state->out_stack_arg_cnt; i++) { + state_reg = &state->stack_arg_regs[i]; + if (state_reg->type != SCALAR_VALUE || !state_reg->precise) + continue; + if (env->log.level & BPF_LOG_LEVEL2) { + if (first) + verbose(env, "frame %d: propagating r11%d", + fr, -(i + 1) * BPF_REG_SIZE); + else + verbose(env, ",r11%d", -(i + 1) * BPF_REG_SIZE); + } + bt_set_frame_stack_arg_slot(&env->bt, fr, i); + first = false; + } if (!first && (env->log.level & BPF_LOG_LEVEL2)) verbose(env, "\n"); } diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 26a5ee0708a3d3..5e4700fda66b9f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -1010,6 +1010,13 @@ static bool dynptr_write_changes_pkt_data(enum bpf_dynptr_type type) return type == BPF_DYNPTR_TYPE_SKB || type == BPF_DYNPTR_TYPE_SKB_META; } +/* The data of the other types is contiguous: bpf_dynptr_slice() does not use the buffer. */ +static bool dynptr_slice_may_be_buffer(enum bpf_dynptr_type type) +{ + return type != BPF_DYNPTR_TYPE_LOCAL && type != BPF_DYNPTR_TYPE_RINGBUF && + type != BPF_DYNPTR_TYPE_SKB_META; +} + static bool is_dynptr_type_expected(struct bpf_verifier_env *env, struct bpf_reg_state *reg, enum bpf_arg_type arg_type) { @@ -4558,6 +4565,31 @@ static int check_stack_read(struct bpf_verifier_env *env, return err; } +/* + * An access through a slice that may be the buffer on the stack, see bpf_reg_state::buf, is + * not seen as an access to the stack. That's fine as long as nothing is tracked in the buffer. + * The output of helpers and kfuncs is not tracked. Here an insn stores to [min_off, max_off) + * of frame @frameno, a dynptr, an iterator or irq flags are made there, or the frame is gone. + */ +static void invalidate_stack_slices(struct bpf_verifier_env *env, u32 frameno, + int min_off, int max_off) +{ + struct bpf_func_state *state; + struct bpf_reg_state *reg; + + if (!env->seen_stack_slice) + return; + + bpf_for_each_reg_in_vstate(env->cur_state, state, reg, ({ + if (base_type(reg->type) != PTR_TO_MEM || !reg->buf.size || + reg->buf.frameno != frameno || reg->buf.off >= max_off || + reg->buf.off + (int)reg->buf.size <= min_off) + continue; + bpf_diag_record_scrub(env, reg, BPF_DIAG_MOD_SLICE_BUF); + mark_reg_invalid(env, reg); + })); +} + /* check_stack_write dispatches to check_stack_write_fixed_off or * check_stack_write_var_off. * @@ -4572,6 +4604,8 @@ static int check_stack_write(struct bpf_verifier_env *env, int value_regno, int insn_idx) { struct bpf_func_state *state = bpf_func(env, reg); + int min_off = reg_smin(reg) + off; + int max_off = reg_smax(reg) + off + size; int err; if (tnum_is_const(reg->var_off)) { @@ -4586,6 +4620,8 @@ static int check_stack_write(struct bpf_verifier_env *env, reg, off, size, value_regno, insn_idx); } + /* After the write is modelled: the insn may store a slice to its own buffer. */ + invalidate_stack_slices(env, state->frameno, min_off, max_off); return err; } @@ -10466,15 +10502,18 @@ static int mark_raw_stack(struct bpf_verifier_env *env, struct bpf_call_arg_meta */ for (slot = 0; slot < MAX_BPF_FUNC_ARGS; slot++) { struct bpf_reg_state *reg; - argno_t argno = argno_from_arg(slot + 1); if (!meta->arg_raw_mem.size[slot]) continue; reg = get_func_arg_reg(caller, cur_regs(env), slot); + /* + * check_stack_range_initialized() checked the range, its offset is a constant. + * Not check_stack_write(): unknown bytes in its buffer leave a dynptr slice valid. + */ for (i = 0; i < meta->arg_raw_mem.size[slot]; i++) { - err = check_mem_access(env, insn_idx, reg, argno, i, BPF_B, - BPF_WRITE, -1, false, false); + err = check_stack_write_fixed_off(env, bpf_func(env, reg), + reg->var_off.value + i, 1, -1, insn_idx); if (err) return err; } @@ -11469,6 +11508,12 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins if (err) return err; + if (!bpf_pseudo_kfunc_call(insn) && + (insn->imm == BPF_FUNC_loop || insn->imm == BPF_FUNC_for_each_map_elem)) + env->subprog_info[subprog].is_loop_cb = true; + else + env->subprog_info[subprog].is_called = true; + /* for callback functions enqueue entry to callback and * proceed with next instruction within current frame. */ @@ -11505,6 +11550,7 @@ static int check_static_func_call(struct bpf_verifier_env *env, int subprog, int err; caller = state->frame[state->curframe]; + env->subprog_info[subprog].is_called = true; /* * Track caller's total stack arg count (incoming + max outgoing). @@ -12176,6 +12222,7 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx) callee->allocated_stack / BPF_REG_SIZE - 1); if (err) return err; + invalidate_stack_slices(env, callee->frameno, INT_MIN, 0); /* for callbacks like bpf_loop or bpf_for_each_map_elem go back to callsite, * there function call logic would reschedule callback visit. If iteration @@ -13574,7 +13621,12 @@ static int resolve_func_arg_type(struct bpf_verifier_env *env, if (base_type(*arg_type) != ARG_PTR_TO_BTF_ID) return 0; + /* + * A kfunc that releases an object, or that takes a reference to one, + * needs the object itself: memory of the program cannot stand in for it. + */ if (!is_kfunc(meta) || arg_type_is_release(*arg_type) || + is_kfunc_acquire(meta) || base_type(reg->type) == PTR_TO_BTF_ID || reg2btf_ids[base_type(reg->type)]) return 0; @@ -13585,7 +13637,15 @@ static int resolve_func_arg_type(struct bpf_verifier_env *env, ref_t = btf_type_skip_modifiers(btf, ref_id, &ref_id); ref_tname = btf_name_by_offset(btf, ref_t->name_off); - if (!btf_type_is_scalar_struct(env, btf, ref_t)) + /* + * A kfunc that takes a projection type (ie. xdp_md) casts it to the + * underlying type. So memory of the program cannot stand in for it, + * even if the projection type holds only scalars. A struct without + * members (ie. iou_ctx) is a handle for an object of another type. + */ + if (btf_is_projection_type(ref_tname) || + !btf_type_is_scalar_struct(env, btf, ref_t) || + !btf_type_vlen(ref_t)) return 0; resolve_ret = btf_resolve_size(btf, ref_t, arg_size); @@ -14340,9 +14400,13 @@ static int process_arg_ptr_to_btf_id(struct bpf_verifier_env *env, struct bpf_re /* If kfunc is accepting a projection type (ie. __sk_buff), it cannot * actually use it -- it must cast to the underlying type. So we allow - * caller to pass in the underlying type. + * caller to pass in the underlying type. Only kernel BTF has that type: + * a type of the same name in the BTF of the program is program memory. + * And only a pointer to the start of the object points to that type. */ - taking_projection = is_kfunc(meta) && btf_is_projection_of(arg_tname, reg_tname); + taking_projection = is_kfunc(meta) && btf_is_kernel(reg_btf) && + !reg->var_off.value && + btf_is_projection_of(arg_tname, reg_tname); if (!taking_projection && !struct_same) { verbose(env, "%s %s expected pointer to %s %s but %s has a pointer to %s %s\n", meta->func_name, reg_arg_name(env, argno), @@ -15394,6 +15458,9 @@ static int check_special_kfunc(struct bpf_verifier_env *env, struct bpf_call_arg return -EFAULT; } regs[BPF_REG_0].parent_id = meta->dynptr.id; + regs[BPF_REG_0].buf = meta->slice_buf; + if (meta->slice_buf.size) + env->seen_stack_slice = true; } else { return 0; } @@ -15651,6 +15718,22 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, ref_convert_owning_non_owning(env, id); } + if ((is_kfunc_call(&meta, special_kfunc_list[KF_bpf_dynptr_slice]) || + is_kfunc_call(&meta, special_kfunc_list[KF_bpf_dynptr_slice_rdwr])) && + dynptr_slice_may_be_buffer(meta.dynptr.type)) { + struct bpf_reg_state *buf = ®s[BPF_REG_3]; + + if (buf->type == PTR_TO_STACK) { + meta.slice_buf.frameno = buf->frameno; + meta.slice_buf.off = reg_smin(buf); + meta.slice_buf.size = reg_smax(buf) - reg_smin(buf) + + meta.arg_constant.value; + } else if (base_type(buf->type) == PTR_TO_MEM) { + /* a slice is the buffer of the next one */ + meta.slice_buf = buf->buf; + } + } + if (meta.func_id == special_kfunc_list[KF_bpf_throw]) { if (!bpf_jit_supports_exceptions()) { verbose(env, "JIT does not support calling kfunc %s#%d\n", @@ -17736,6 +17819,18 @@ bool bpf_same_memory_origin(const struct bpf_reg_state *reg_a, } } +/* + * 'range - smax' bytes from a packet pointer are in the packet. reg_bounds_sync() can make smax + * smaller than @smax: with a step of 8, or with 3 zero bits in var_off, 58 becomes 56. Make the + * range smaller by the same number, so that the number of bytes does not grow. umax is not + * sufficient: it is U64_MAX when the offset can be negative. + */ +void bpf_trim_pkt_range(struct bpf_reg_state *reg, s64 smax) +{ + if (type_is_pkt_pointer(reg->type) && reg->range > 0) + reg->range = max_t(s64, reg->range - (smax - reg_smax(reg)), 0); +} + int bpf_set_reg_range(struct bpf_verifier_env *env, struct bpf_reg_state *reg, struct cnum64 r64, struct cnum32 r32, u16 base, u16 step) { @@ -17745,6 +17840,7 @@ int bpf_set_reg_range(struct bpf_verifier_env *env, struct bpf_reg_state *reg, reg->base = base; reg->var_off = tnum_unknown; reg_bounds_sync(reg); /* this should infer the tnum alignment */ + bpf_trim_pkt_range(reg, cnum64_smax(r64)); return reg_bounds_sanity_check(env, reg, "bpf_set_reg_range"); } @@ -22497,6 +22593,37 @@ static bool func_has_rcu_read_lock(const struct bpf_prog *prog, int subprog) !sub_aux->called[BPF_FUNC_CTX_NO_RCU_LOCK]; } +/* + * The callers of a global function are checked against the arguments that its + * BTF describes, and an extension is verified with those of its own BTF. It + * must not expect more than the callers of the function provide. + * + * While an extension is loaded, bpf_check_attach_target() runs before its + * arguments are known. check_attach_btf_id() does the check when they are. + */ +static int check_ext_args(struct bpf_verifier_log *log, const struct bpf_prog *prog, + const struct bpf_prog *tgt_prog, int subprog) +{ + const struct bpf_subprog_arg_info *tgt = tgt_prog->aux->func_info_aux[subprog].args; + const struct bpf_subprog_arg_info *ext = prog->aux->func_info_aux[0].args; + int i; + + for (i = 0; i < MAX_BPF_FUNC_REG_ARGS && ext[i].arg_type != ARG_UNUSED; i++) { + /* An extension may accept NULL where the callers never pass it. */ + if ((ext[i].arg_type == tgt[i].arg_type || + ext[i].arg_type == (tgt[i].arg_type | PTR_MAYBE_NULL)) && + (base_type(ext[i].arg_type) == ARG_PTR_TO_MEM ? + ext[i].mem_size <= tgt[i].mem_size : ext[i].btf_id == tgt[i].btf_id)) + continue; + + bpf_log(log, "Extension program's argument in R%d is incompatible with original\n", + i + 1); + return -EINVAL; + } + + return 0; +} + int bpf_check_attach_target(struct bpf_verifier_log *log, const struct bpf_prog *prog, const struct bpf_prog *tgt_prog, @@ -22784,7 +22911,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, return -EINVAL; } if (prog_extension && - btf_check_type_match(log, prog, btf, t)) + (btf_check_type_match(log, prog, btf, t) || + check_ext_args(log, prog, tgt_prog, subprog))) return -EINVAL; t = btf_attach_func_proto(log, btf, btf_id); if (!t || !btf_type_is_func_proto(t)) @@ -23004,6 +23132,15 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) */ env->ops = bpf_verifier_ops[tgt_prog->type]; prog->expected_attach_type = tgt_prog->expected_attach_type; + + /* only now it is known what the arguments of prog stand for */ + ret = btf_prepare_func_args(env, 0); + if (ret) + return ret; + ret = check_ext_args(&env->log, prog, tgt_prog, + find_tgt_subprog(tgt_prog, btf_id)); + if (ret) + return ret; } /* store info about the attachment target that will be used later */ diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index a284225f8dc95b..b3657e72db99e8 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4806,19 +4806,21 @@ void cgroup_file_notify(struct cgroup_file *cfile) if (!READ_ONCE(cfile->kn)) return; - last = READ_ONCE(cfile->notified_at); - next = last + CGROUP_FILE_NOTIFY_MIN_INTV; - if (time_in_range(jiffies, last, next)) { - timer_reduce(&cfile->notify_timer, next); - if (timer_pending(&cfile->notify_timer)) - return; - } + if (timer_pending(&cfile->notify_timer)) + return; spin_lock_irqsave(&cfile->lock, flags); if (cfile->kn) { - kn = cfile->kn; - kernfs_get(kn); - WRITE_ONCE(cfile->notified_at, jiffies); + last = cfile->notified_at; + next = last + CGROUP_FILE_NOTIFY_MIN_INTV; + + if (time_in_range(jiffies, last, next)) { + timer_reduce(&cfile->notify_timer, next); + } else { + kn = cfile->kn; + kernfs_get(kn); + cfile->notified_at = jiffies; + } } spin_unlock_irqrestore(&cfile->lock, flags); diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 3219f927c35e85..db32d330cfbc29 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1244,17 +1244,17 @@ static bool isolated_cpu_update(int new_prs, int cpu) } /* - * isolated_cpus_update - Update the isolated_cpus mask - * @old_prs: old partition_root_state - * @new_prs: new partition_root_state - * @xcpus: exclusive CPUs with state change + * isolated_cpus_update - Set the isolation state of @xcpus + * @new_prs: partition root state that @xcpus will belong to + * @xcpus: exclusive CPUs whose isolation state may change + * + * CPUs isolated at boot time are kept isolated. */ -static void isolated_cpus_update(int old_prs, int new_prs, struct cpumask *xcpus) +static void isolated_cpus_update(int new_prs, struct cpumask *xcpus) { bool updated = false; int cpu; - WARN_ON_ONCE(old_prs == new_prs); lockdep_assert_held(&callback_lock); lockdep_assert_held(&cpuset_mutex); for_each_cpu(cpu, xcpus) @@ -1263,45 +1263,6 @@ static void isolated_cpus_update(int old_prs, int new_prs, struct cpumask *xcpus update_housekeeping = true; } -/* - * isolated_cpus_release - Remove the relevant CPUs in @xcpus from isolated_cpus - * @cs: the current cpuset - * @xcpus: the set of effective xcpus to be considered for removal - * - * This function is called when an isolated partition is invalidated or when - * some of its effective xcpus are to be removed from isolated_cpus due to - * changes in parent cpuset. The given @xcpus must be modifiable as the function - * will update its value to determine the right set of CPUs to be removed. - */ -static void isolated_cpus_release(struct cpuset *cs, struct cpumask *xcpus) -{ - struct cpuset *ancestor = parent_cs(cs); - struct cpuset *iancestor = NULL; - - /* - * Search the furthest isolated partition root ancestor available - * until top_cpuset or a remote partition root is hit. - */ - for (; ancestor; ancestor = parent_cs(ancestor)) { - if (ancestor->partition_root_state == PRS_ISOLATED) - iancestor = ancestor; - if (is_remote_partition(ancestor)) - break; - } - - /* - * If a furthest isolated partition acnestor is found, use it to - * determine which of the CPUs in @xcpus should be removed from - * isolated_cpus. Otherwise, all of them will be removed. - */ - if (iancestor && !cpumask_andnot(xcpus, xcpus, iancestor->effective_xcpus)) - return; /* No CPU should be removed from isolated_cpus */ - - spin_lock_irq(&callback_lock); - isolated_cpus_update(PRS_ISOLATED, PRS_ROOT, xcpus); - spin_unlock_irq(&callback_lock); -} - /* * partition_xcpus_add - Add new exclusive CPUs to partition * @new_prs: new partition_root_state @@ -1315,16 +1276,17 @@ static void partition_xcpus_add(int new_prs, struct cpuset *parent, { WARN_ON_ONCE(new_prs < 0); lockdep_assert_held(&callback_lock); + + if (cpumask_empty(xcpus)) + return; + if (!parent) parent = &top_cpuset; - if (parent == &top_cpuset) cpumask_or(subpartitions_cpus, subpartitions_cpus, xcpus); - if (new_prs != parent->partition_root_state) - isolated_cpus_update(parent->partition_root_state, new_prs, - xcpus); + isolated_cpus_update(new_prs, xcpus); cpumask_andnot(parent->effective_cpus, parent->effective_cpus, xcpus); } @@ -1342,15 +1304,18 @@ static void partition_xcpus_del(int old_prs, struct cpuset *parent, { WARN_ON_ONCE(old_prs < 0); lockdep_assert_held(&callback_lock); + + if (cpumask_empty(xcpus)) + return; + if (!parent) parent = &top_cpuset; if (parent == &top_cpuset) cpumask_andnot(subpartitions_cpus, subpartitions_cpus, xcpus); - if (old_prs != parent->partition_root_state) - isolated_cpus_update(old_prs, parent->partition_root_state, - xcpus); + /* CPUs given back, including those of descendants, take parent's state */ + isolated_cpus_update(parent->partition_root_state, xcpus); cpumask_or(parent->effective_cpus, parent->effective_cpus, xcpus); cpumask_and(parent->effective_cpus, parent->effective_cpus, cpu_active_mask); @@ -1449,6 +1414,48 @@ static bool prstate_housekeeping_conflict(int new_prs, int parent_prs, return res; } +/** + * validate_partition - Validate a cpuset partition configuration + * @cs: The cpuset to validate + * @parent: Parent partition of @cs, NULL for remote partition + * @new_prs: The proposed new partition root state + * @new_excpus: The new effective exclusive CPUs mask to validate + * @del: exclusive CPUs to be deleted from @cs, can be NULL + * + * A remote partition gets its CPUs from top_cpuset, so top_cpuset is used + * as the parent when @parent is NULL. + * + * The housekeeping check is skipped if @parent is not a valid partition + * root as @cs can't be a valid local partition in that case. + * + * Return: PRS error code (0 if valid, non-zero error code if invalid) + */ +static enum prs_errcode validate_partition(struct cpuset *cs, + struct cpuset *parent, int new_prs, + struct cpumask *new_excpus, + struct cpumask *del) +{ + int parent_prs; + + if (new_prs == PRS_MEMBER) + return PERR_NONE; + + if (cpumask_empty(new_excpus)) + return PERR_INVCPUS; + + if (!parent) + parent = &top_cpuset; + parent_prs = parent->partition_root_state; + if (parent_prs > 0 && + prstate_housekeeping_conflict(new_prs, parent_prs, new_excpus, del)) + return PERR_HKEEPING; + + if (tasks_nocpu_error(parent, cs, new_excpus)) + return PERR_NOCPUS; + + return PERR_NONE; +} + /* * cpuset_update_sd_hk_unlock - Rebuild sched domains, update HK & unlock * @@ -1605,6 +1612,7 @@ static void compute_partition_effective_cpumask(struct cpuset *cs, struct cgroup_subsys_state *css; struct cpuset *child; bool populated = partition_is_populated(cs, NULL); + static cpumask_t xcpus; /* Protected by cpuset_mutex */ /* * Check child partition roots to see if they should be invalidated @@ -1633,14 +1641,15 @@ static void compute_partition_effective_cpumask(struct cpuset *cs, int parent_prs = cs->partition_root_state; /* - * Invalidate child partition and update isolated_cpus - * if necessary. + * Invalidate child partition. Its CPUs still owned by + * cs take the isolation state of cs. effective_xcpus + * of cs may not be updated yet, so recompute it. */ spin_lock_irq(&callback_lock); WRITE_ONCE(child->prs_err, PERR_NOCPUS); - if ((old_prs == PRS_ISOLATED) && (parent_prs == PRS_ROOT)) - isolated_cpus_update(PRS_ISOLATED, PRS_ROOT, - child->effective_xcpus); + compute_excpus(cs, &xcpus); + cpumask_and(&xcpus, &xcpus, child->effective_xcpus); + isolated_cpus_update(parent_prs, &xcpus); child->partition_root_state = -old_prs; spin_unlock_irq(&callback_lock); notify_partition_change(child, old_prs); @@ -1824,7 +1833,6 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, * left in the top cpuset. */ if (adding) { - WARN_ON_ONCE(cpumask_intersects(tmp->addmask, subpartitions_cpus)); if (!capable(CAP_SYS_ADMIN)) WRITE_ONCE(cs->prs_err, PERR_ACCESS); else if (cpumask_intersects(tmp->addmask, subpartitions_cpus) || @@ -1967,18 +1975,10 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) { new_prs = (cmd == partcmd_enable) ? PRS_ROOT : PRS_ISOLATED; - /* - * Enabling partition root is not allowed if its - * effective_xcpus is empty. - */ - if (cpumask_empty(tmp->delmask)) - return PERR_INVCPUS; - - if (prstate_housekeeping_conflict(new_prs, parent_prs, tmp->delmask, NULL)) - return PERR_HKEEPING; - - if (nocpu) - return PERR_NOCPUS; + part_error = validate_partition(cs, parent, new_prs, + tmp->delmask, NULL); + if (part_error) + return part_error; /* * This function will only be called when all the preliminary @@ -2083,21 +2083,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, * * A partition error happens when parent has tasks and all * its effective CPUs will have to be distributed out. - * - * For an isolated partition with a shrunk root partition parent - * we may need to return some or all of its isolated CPUs. */ nocpu |= cpumask_empty(tmp->delmask); - if ((parent_prs == PRS_ROOT) && (old_prs == PRS_ISOLATED)) { - cpumask_clear(tmp->addmask); - if (nocpu) - cpumask_copy(tmp->addmask, cs->effective_xcpus); - else if (!cpumask_subset(cs->effective_xcpus, parent->effective_xcpus)) - cpumask_andnot(tmp->addmask, cs->effective_xcpus, - parent->effective_xcpus); - if (!cpumask_empty(tmp->addmask)) - isolated_cpus_release(cs, tmp->addmask); - } if (nocpu) { part_error = PERR_NOCPUS; if (is_partition_valid(cs)) @@ -2106,11 +2093,34 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, parent->effective_xcpus); } else if ((parent_prs == PRS_ISOLATED) && ((old_prs == PRS_ROOT) || (old_prs == -PRS_ROOT))) { + /* Parent partition state changed to PRS_ISOLATED */ part_error = PERR_ISOPARENT; if (old_prs == PRS_ROOT) { cpumask_copy(tmp->addmask, cs->effective_xcpus); adding = true; } + } else if (is_partition_valid(cs) && + !cpumask_equal(tmp->delmask, cs->effective_xcpus)) { + /* + * If there is an expansion of parent's effective_xcpus, + * we may take more xcpus from parent. The parent's + * effective_cpus should still have active CPUs or nocpu + * should have been set. We also need to do a + * housekeeping check for an isolated child with root + * parent to make sure that it won't exhaust all the + * active housekeeping CPUs. + */ + cpumask_andnot(tmp->addmask, cs->effective_xcpus, tmp->delmask); + if ((parent_prs == PRS_ROOT) && (old_prs == PRS_ISOLATED) && + prstate_housekeeping_conflict(old_prs, parent_prs, + tmp->delmask, tmp->addmask)) { + adding = cpumask_and(tmp->addmask, cs->effective_xcpus, + tmp->delmask); + part_error = PERR_HKEEPING; + } else { + deleting = cpumask_andnot(tmp->delmask, tmp->delmask, + cs->effective_xcpus); + } } else if (is_partition_invalid(cs)) { struct cgroup_subsys_state *css; struct cpuset *child; @@ -2143,12 +2153,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, else part_error = PERR_NOTEXCL; } - /* - * When both cs and parent remain valid, parent's - * compute_partition_effective_cpumask() call would have removed - * cs's effective_xcpus from the parent's effective_cpus. So - * there is no need to adjust parent's effective_cpus here. - */ } write_error: @@ -2320,18 +2324,12 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp, /* * When parent is not a valid partition root, * child partition roots become invalid too. - * - * For a to be invalidated isolated partition, - * call return_isolated_cpus() to remove the - * relevant CPUs from isolated_cpus. + * The isolation state of their CPUs has been + * settled when the parent gave them back. */ if (is_partition_valid(cp)) new_prs = -old_prs; - if (old_prs == PRS_ISOLATED) { - cpumask_copy(tmp->delmask, cp->effective_xcpus); - isolated_cpus_release(cp, tmp->delmask); - } WRITE_ONCE(cp->prs_err, is_partition_invalid(parent) ? PERR_INVPARENT : PERR_NOTPART); @@ -2347,12 +2345,12 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp, update_parent_effective_cpumask(cp, partcmd_update, NULL, tmp); /* * Capture current partition_root_state as it may have - * changed. Recompute effective cpumask if changed. + * changed. Always recompute effective cpumask as tmp->new_cpus + * may be clobbered when update_sibling_cpumasks() is called + * within update_parent_effective_cpumask(). */ new_prs = cp->partition_root_state; - if (new_prs != old_prs) { - compute_effective_cpumask(tmp->new_cpus, cp, parent); - } + compute_effective_cpumask(tmp->new_cpus, cp, parent); } spin_lock_irq(&callback_lock); @@ -2463,32 +2461,6 @@ static int parse_cpuset_cpulist(const char *buf, struct cpumask *out_mask) return 0; } -/** - * validate_partition - Validate a cpuset partition configuration - * @cs: The cpuset to validate - * @trialcs: The trial cpuset containing proposed configuration changes - * - * If any validation check fails, the appropriate error code is set in the - * cpuset's prs_err field. - * - * Return: PRS error code (0 if valid, non-zero error code if invalid) - */ -static enum prs_errcode validate_partition(struct cpuset *cs, struct cpuset *trialcs) -{ - struct cpuset *parent = parent_cs(cs); - - if (cs_is_member(trialcs)) - return PERR_NONE; - - if (cpumask_empty(trialcs->effective_xcpus)) - return PERR_INVCPUS; - - if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) - return PERR_NOCPUS; - - return PERR_NONE; -} - /** * partition_cpus_change - Handle partition state changes due to CPU mask updates * @cs: The target cpuset being modified @@ -2502,33 +2474,24 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs, struct tmpmasks *tmp) { enum prs_errcode prs_err; - int parent_prs = is_remote_partition(cs) - ? PRS_ROOT : parent_cs(cs)->partition_root_state; + struct cpuset *parent = is_remote_partition(cs) ? NULL : parent_cs(cs); if (cs_is_member(cs)) return; - prs_err = validate_partition(cs, trialcs); - if (!prs_err && (parent_prs > 0) && - !cpumask_empty(trialcs->effective_xcpus)) { - int prs = cs->partition_root_state; - - /* - * Check for housekeeping conflict by passing the whole - * effective_xcpus as well as those CPUs that are to be - * removed from cs as delmask. - */ - if (prs > 0) - cpumask_andnot(tmp->delmask, cs->effective_xcpus, - trialcs->effective_xcpus); - else - cpumask_clear(tmp->delmask); - - if (prstate_housekeeping_conflict(prs, parent_prs, - trialcs->effective_xcpus, tmp->delmask)) - prs_err = PERR_HKEEPING; - } + /* + * Check for housekeeping conflict by passing the whole + * effective_xcpus as well as those CPUs that are to be + * removed from cs as delmask. + */ + if (is_partition_valid(cs)) + cpumask_andnot(tmp->delmask, cs->effective_xcpus, + trialcs->effective_xcpus); + else + cpumask_clear(tmp->delmask); + prs_err = validate_partition(cs, parent, trialcs->partition_root_state, + trialcs->effective_xcpus, tmp->delmask); if (prs_err) { WRITE_ONCE(cs->prs_err, prs_err); trialcs->prs_err = prs_err; @@ -2593,8 +2556,11 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, spin_lock_irq(&callback_lock); cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed); cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); - if ((old_prs > 0) && !is_partition_valid(cs)) + if (old_prs && !is_partition_valid(cs)) { reset_partition_data(cs); + /* effective_xcpus may be cleared, update the subtree too */ + force = true; + } spin_unlock_irq(&callback_lock); /* effective_cpus/effective_xcpus will be updated here */ @@ -2658,8 +2624,11 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs, spin_lock_irq(&callback_lock); cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus); cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); - if ((old_prs > 0) && !is_partition_valid(cs)) + if (old_prs && !is_partition_valid(cs)) { reset_partition_data(cs); + /* effective_xcpus may be cleared, update the subtree too */ + force = true; + } spin_unlock_irq(&callback_lock); /* @@ -3042,12 +3011,32 @@ static int update_prstate(struct cpuset *cs, int new_prs) cs->effective_xcpus, NULL)) err = PERR_HKEEPING; else if (parent_prs == PRS_ISOLATED) - err = PERR_ISOPARENT; + err = PERR_ISOPARENT; /* old_prs should be isolated */ - if (!err) - isolcpus_updated = true; - else + if (err) { disable_partition = true; + } else { + struct cgroup_subsys_state *css; + struct cpuset *child; + + /* + * Need to scan child partitions, if present, and + * exclude their effective_xcpus from cs. In the case + * of switching to isolated partition with child root + * partitions, those child partitions will be + * invalidated in update_cpumasks_hier(). + */ + isolcpus_updated = true; + cpumask_copy(tmpmask.new_cpus, cs->effective_xcpus); + rcu_read_lock(); + cpuset_for_each_child(child, css, cs) { + if (!is_partition_valid(child)) + continue; + cpumask_andnot(tmpmask.new_cpus, tmpmask.new_cpus, + child->effective_xcpus); + } + rcu_read_unlock(); + } } else { /* * Switching back to member is always allowed even if it @@ -3081,7 +3070,7 @@ static int update_prstate(struct cpuset *cs, int new_prs) if (!is_partition_valid(cs)) reset_partition_data(cs); else if (isolcpus_updated) - isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus); + isolated_cpus_update(new_prs, tmpmask.new_cpus); spin_unlock_irq(&callback_lock); /* Force update if partition is disabled & update effective_xcpus */ @@ -3856,11 +3845,20 @@ static void cpuset_fork(struct task_struct *task) rcu_read_unlock(); if (cs == oldcs) { + unsigned int seq; + if (cs == &top_cpuset) return; set_cpus_allowed_ptr(task, current->cpus_ptr); - task->mems_allowed = current->mems_allowed; + /* + * A cpuset.mems update can update current->mems_allowed + * concurrently, so retry it again if it really happens. + */ + do { + seq = read_mems_allowed_begin(); + task->mems_allowed = current->mems_allowed; + } while (read_mems_allowed_retry(seq)); return; } @@ -4017,10 +4015,10 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp) partcmd = partcmd_invalidate; /* * On the other hand, an invalid partition root may be transitioned - * back to a regular one with a non-empty effective xcpus. + * back to a regular one if its effective xcpus has an active CPU. */ else if (is_partition_valid(parent) && is_partition_invalid(cs) && - !cpumask_empty(cs->effective_xcpus)) + cpumask_intersects(cs->effective_xcpus, cpu_active_mask)) partcmd = partcmd_update; if (partcmd >= 0) { diff --git a/kernel/cgroup/legacy_freezer.c b/kernel/cgroup/legacy_freezer.c index 8545e0d1ba3d8f..1792523d119ae4 100644 --- a/kernel/cgroup/legacy_freezer.c +++ b/kernel/cgroup/legacy_freezer.c @@ -265,7 +265,7 @@ static void update_if_frozen(struct cgroup_subsys_state *css) rcu_read_unlock(); /* are all tasks frozen? */ - css_task_iter_start(css, 0, &it); + css_task_iter_start(css, CSS_TASK_ITER_WITH_DEAD, &it); while ((task = css_task_iter_next(&it))) { if (freezing(task) && !frozen(task)) @@ -309,7 +309,7 @@ static void freeze_cgroup(struct freezer *freezer) struct css_task_iter it; struct task_struct *task; - css_task_iter_start(&freezer->css, 0, &it); + css_task_iter_start(&freezer->css, CSS_TASK_ITER_WITH_DEAD, &it); while ((task = css_task_iter_next(&it))) freeze_task(task); css_task_iter_end(&it); @@ -320,7 +320,7 @@ static void unfreeze_cgroup(struct freezer *freezer) struct css_task_iter it; struct task_struct *task; - css_task_iter_start(&freezer->css, 0, &it); + css_task_iter_start(&freezer->css, CSS_TASK_ITER_WITH_DEAD, &it); while ((task = css_task_iter_next(&it))) __thaw_task(task); css_task_iter_end(&it); @@ -382,6 +382,24 @@ static void freezer_change_state(struct freezer *freezer, bool freeze) * CGROUP_FREEZING_PARENT. */ mutex_lock(&freezer_mutex); + + /* + * A dead cgroup must not be frozen. + * + * rmdir thaws the cgroup from freezer_css_killed(), but freezer.state + * stays writable until rmdir removes it a moment later. A FROZEN write + * in that gap would freeze the cgroup again, and nothing could thaw it + * after that. + * + * A freezer.state write doesn't take cgroup_mutex, but testing + * cgroup_is_dead() without it is safe. rmdir marks the cgroup dead + * before the thaw, so a write that takes freezer_mutex after the thaw + * sees it dead. One that takes it before the thaw may still see the + * cgroup alive, but the thaw then undoes its freeze. + */ + if (freeze && data_race(cgroup_is_dead(freezer->css.cgroup))) + goto out_unlock; + rcu_read_lock(); css_for_each_descendant_pre(pos, &freezer->css) { struct freezer *pos_f = css_freezer(pos); @@ -403,10 +421,25 @@ static void freezer_change_state(struct freezer *freezer, bool freeze) css_put(pos); } rcu_read_unlock(); +out_unlock: mutex_unlock(&freezer_mutex); cpus_read_unlock(); } +/** + * freezer_css_killed - Thaw a freezer cgroup being removed + * @css: css being killed + * + * Exiting tasks hidden from cgroup.procs can still be in the cgroup when it is + * removed, and a frozen one has nothing left to thaw it once freezer.state is + * gone. Thaw the cgroup as a THAWED write to it would. A frozen ancestor keeps + * the tasks frozen through CGROUP_FREEZING_PARENT until the ancestor is thawed. + */ +static void freezer_css_killed(struct cgroup_subsys_state *css) +{ + freezer_change_state(css_freezer(css), false); +} + static ssize_t freezer_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -466,6 +499,7 @@ static struct cftype files[] = { struct cgroup_subsys freezer_cgrp_subsys = { .css_alloc = freezer_css_alloc, .css_online = freezer_css_online, + .css_killed = freezer_css_killed, .css_offline = freezer_css_offline, .css_free = freezer_css_free, .attach = freezer_attach, diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c index 957707158ff610..04ec87c27de824 100644 --- a/kernel/dma/map_benchmark.c +++ b/kernel/dma/map_benchmark.c @@ -500,7 +500,7 @@ static int __map_benchmark_probe(struct device *dev) struct map_benchmark_data *map; int ret; - map = devm_kzalloc(dev, sizeof(*map), GFP_KERNEL); + map = devm_kzalloc_obj(dev, *map); if (!map) return -ENOMEM; map->dev = dev; diff --git a/kernel/events/core.c b/kernel/events/core.c index 457d75ea714209..e870f12c3ad812 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1072,8 +1072,13 @@ static void perf_cgroup_switch(struct task_struct *task) * must not be done before ctxswout due * to update_cgrp_time_from_cpuctx() in * ctx_sched_out() + * + * ctx_sched_out() can consume a pending disable and drop the last cgroup + * event, which clear the cpuctx->cgrp. Cgroup tracking follow active cgroup + * event, so do not resurrect it */ - cpuctx->cgrp = cgrp; + if (cpuctx->ctx.nr_cgroups) + cpuctx->cgrp = cgrp; /* * set cgrp before ctxsw in to allow * perf_cgroup_set_timestamp() in ctx_sched_in() @@ -1332,14 +1337,19 @@ static int perf_mux_hrtimer_restart(struct perf_cpu_pmu_context *cpc) return 0; } -static int perf_mux_hrtimer_restart_ipi(void *arg) +static __always_inline struct perf_cpu_pmu_context *this_cpc(struct pmu *pmu) { - return perf_mux_hrtimer_restart(arg); + return *this_cpu_ptr(pmu->cpu_pmu_context); } -static __always_inline struct perf_cpu_pmu_context *this_cpc(struct pmu *pmu) +static int perf_mux_hrtimer_interval_ipi(void *arg) { - return *this_cpu_ptr(pmu->cpu_pmu_context); + struct pmu *pmu = arg; + struct perf_cpu_pmu_context *cpc = this_cpc(pmu); + int ms = pmu->hrtimer_interval_ms; + + cpc->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * ms); + return perf_mux_hrtimer_restart(cpc); } void perf_pmu_disable(struct pmu *pmu) @@ -5356,7 +5366,7 @@ static bool is_sb_event(struct perf_event *event) attr->comm || attr->comm_exec || attr->task || attr->ksymbol || attr->context_switch || attr->text_poke || - attr->bpf_event) + attr->bpf_event || attr->defer_output) return true; return false; @@ -7646,6 +7656,15 @@ static void perf_sigtrap(struct perf_event *event) if (event->ctx->task == TASK_TOMBSTONE) return; + /* + * The event was removed after this signal was queued, e.g. by exec() + * (remove_on_exec), which may also have closed its fd (close-on-exec). + * The new program has default signal handlers, so a SIGTRAP would + * kill it. + */ + if (READ_ONCE(event->state) <= PERF_EVENT_STATE_EXIT) + return; + /* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the @@ -7919,8 +7938,8 @@ perf_output_sample_simd_regs(struct perf_output_handle *handle, } } -static void perf_sample_regs_user(struct perf_regs *regs_user, - struct pt_regs *regs) +void perf_sample_regs_user(struct perf_regs *regs_user, + struct pt_regs *regs) { if (user_mode(regs)) { regs_user->abi = perf_reg_abi(current); @@ -7933,9 +7952,9 @@ static void perf_sample_regs_user(struct perf_regs *regs_user, } } -static void perf_sample_regs_intr(struct perf_regs *regs_intr, - struct pt_regs *regs, - bool exclude_kernel) +void perf_sample_regs_intr(struct perf_regs *regs_intr, + struct pt_regs *regs, + bool exclude_kernel) { /* * Hardware skid can lead to a scenario where a PMI is @@ -10514,8 +10533,6 @@ struct perf_callchain_deferred_event { struct { struct perf_event_header header; u64 cookie; - u64 nr; - u64 ips[]; } event; }; @@ -10524,12 +10541,19 @@ static void perf_callchain_deferred_output(struct perf_event *event, void *data) struct perf_callchain_deferred_event *deferred_event = data; struct perf_output_handle handle; struct perf_sample_data sample; + u64 nr = deferred_event->trace->nr; + u16 size, id_size, max_payload; int ret; - u16 size = sizeof(deferred_event->event) + (deferred_event->trace->nr * sizeof(u64)); if (!event->attr.defer_output) return; + id_size = event->attr.sample_id_all ? event->id_header_size : 0; + max_payload = round_down(U16_MAX - sizeof(deferred_event->event) - + sizeof(u64) - id_size, sizeof(u64)); + nr = min_t(u64, nr, max_payload / sizeof(u64)); + size = sizeof(deferred_event->event) + sizeof(u64) + nr * sizeof(u64); + /* XXX do we really need sample_id_all for this ??? */ perf_event_header__init(&deferred_event->event.header, &sample, PERF_RECORD_CALLCHAIN_DEFERRED, @@ -10543,8 +10567,10 @@ static void perf_callchain_deferred_output(struct perf_event *event, void *data) return; perf_output_put(&handle, deferred_event->event); - for (int i = 0; i < deferred_event->trace->nr; i++) { + perf_output_put(&handle, nr); + for (u64 i = 0; i < nr; i++) { u64 entry = deferred_event->trace->entries[i]; + perf_output_put(&handle, entry); } perf_event__output_id_sample(event, &handle, &sample); @@ -10559,7 +10585,6 @@ static void perf_unwind_deferred_callback(struct unwind_work *work, .trace = trace, .event = { .cookie = cookie, - .nr = trace->nr, }, }; @@ -12765,13 +12790,8 @@ perf_event_mux_interval_ms_store(struct device *dev, /* update all cpuctx for this PMU */ cpus_read_lock(); - for_each_online_cpu(cpu) { - struct perf_cpu_pmu_context *cpc; - cpc = *per_cpu_ptr(pmu->cpu_pmu_context, cpu); - cpc->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer); - - cpu_function_call(cpu, perf_mux_hrtimer_restart_ipi, cpc); - } + for_each_online_cpu(cpu) + cpu_function_call(cpu, perf_mux_hrtimer_interval_ipi, pmu); cpus_read_unlock(); mutex_unlock(&mux_interval_mutex); diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index 789add0c185a0f..7a606213f33d7a 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c @@ -968,8 +968,7 @@ static int hw_breakpoint_event_init(struct perf_event *bp) static int hw_breakpoint_add(struct perf_event *bp, int flags) { - if (!(flags & PERF_EF_START)) - bp->hw.state = PERF_HES_STOPPED; + bp->hw.state = (flags & PERF_EF_START) ? 0 : PERF_HES_STOPPED; if (is_sampling_event(bp)) { bp->hw.last_period = bp->hw.sample_period; diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 64d4dbdc6c071b..95f4fbdfd2764d 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -684,15 +684,7 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, { bool overwrite = !(flags & RING_BUFFER_WRITABLE); int node = (event->cpu == -1) ? -1 : cpu_to_node(event->cpu); - bool use_contiguous_pages = event->pmu->capabilities & ( - PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_AUX_PREFER_LARGE); - /* - * Initialize max_order to 0 for page allocation. This allocates single - * pages to minimize memory fragmentation. This is overridden if the - * PMU needs or prefers contiguous pages (use_contiguous_pages = true). - */ - int max_order = 0; - int ret = -ENOMEM; + int ret = -ENOMEM, max_order; if (!has_aux(event)) return -EOPNOTSUPP; @@ -702,8 +694,8 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, if (!overwrite) { /* - * Watermark defaults to half the buffer, to aid PMU drivers - * in double buffering. + * Watermark defaults to half the buffer, and so does the + * max_order, to aid PMU drivers in double buffering. */ if (!watermark) watermark = min_t(unsigned long, @@ -711,19 +703,16 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, (unsigned long)nr_pages << (PAGE_SHIFT - 1)); /* - * If using contiguous pages, use aux_watermark as the basis - * for chunking to help PMU drivers honor the watermark. + * Use aux_watermark as the basis for chunking to + * help PMU drivers honor the watermark. */ - if (use_contiguous_pages) - max_order = get_order(watermark); + max_order = get_order(watermark); } else { /* - * If using contiguous pages, we need to start with the - * max_order that fits in nr_pages, not the other way around, - * hence ilog2() and not get_order. + * We need to start with the max_order that fits in nr_pages, + * not the other way around, hence ilog2() and not get_order. */ - if (use_contiguous_pages) - max_order = ilog2(nr_pages); + max_order = ilog2(nr_pages); watermark = 0; } diff --git a/kernel/fork.c b/kernel/fork.c index 8b108ed371529c..5efceb8d58a78b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1533,12 +1533,19 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, if (!mm) goto fail_nomem; + uprobe_start_dup_mmap(); + if (mmap_write_lock_killable(oldmm)) { + free_mm(mm); + goto fail_uprobe; + } + memcpy(mm, oldmm, sizeof(*mm)); - if (!mm_init(mm, tsk)) - goto fail_nomem; + if (!mm_init(mm, tsk)) { + mmap_write_unlock(oldmm); + goto fail_uprobe; + } - uprobe_start_dup_mmap(); err = dup_mmap(mm, oldmm); if (err) goto free_pt; @@ -1557,9 +1564,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt = NULL; mm_init_owner(mm, NULL); mmput(mm); - if (err) - uprobe_end_dup_mmap(); - + if (!err) + return NULL; +fail_uprobe: + uprobe_end_dup_mmap(); fail_nomem: return NULL; } diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c index b411886986222d..1295e27a9bef1e 100644 --- a/kernel/irq/devres.c +++ b/kernel/irq/devres.c @@ -268,7 +268,7 @@ devm_irq_alloc_generic_chip(struct device *dev, const char *name, int num_ct, { struct irq_chip_generic *gc; - gc = devm_kzalloc(dev, struct_size(gc, chip_types, num_ct), GFP_KERNEL); + gc = devm_kzalloc_flex(dev, *gc, chip_types, num_ct); if (gc) irq_init_generic_chip(gc, name, num_ct, irq_base, reg_base, handler); diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c index 2af39ba5b70b9b..2005ca79d066a4 100644 --- a/kernel/kcsan/debugfs.c +++ b/kernel/kcsan/debugfs.c @@ -156,7 +156,7 @@ static ssize_t insert_report_filterlist(const char *func) */ if (data_race(report_filterlist.used == report_filterlist.size)) { new_size = (report_filterlist.size ?: 4) * 2; - delay_free = new_addrs = kmalloc_array(new_size, sizeof(unsigned long), GFP_KERNEL); + delay_free = new_addrs = kmalloc_objs(unsigned long, new_size); if (!new_addrs) return -ENOMEM; } diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2441b9e3934386..f14f7ff45961c4 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -552,17 +552,13 @@ static unsigned long optimizer_passes; #define OPTIMIZE_DELAY 5 -/* - * Note: gen->cooling_list is not checked here because it is strictly - * an in-flight holding list for dispatched generations, so it is always - * empty in optprobe_cur_gen. - */ static bool optprobe_has_queued_probes(void) { struct optprobe_generation *gen = &optprobe_gens[optprobe_cur_gen]; return !list_empty(&gen->optimizing_list) || !list_empty(&gen->unoptimizing_list) || + !list_empty(&gen->cooling_list) || !list_empty(&gen->freeing_list); } @@ -612,6 +608,7 @@ static void do_unoptimize_kprobes(struct list_head *unopt_list, struct list_head *cooling_list) { struct optimized_kprobe *op, *tmp; + LIST_HEAD(unoptimized); lockdep_assert_held(&text_mutex); /* @@ -626,15 +623,21 @@ static void do_unoptimize_kprobes(struct list_head *unopt_list, */ lockdep_assert_cpus_held(); - if (!list_empty(unopt_list)) - arch_unoptimize_kprobes(unopt_list, free_list); + if (list_empty(unopt_list)) + return; - /* Loop on 'free_list' for disarming and removing from kprobe hash list */ - list_for_each_entry_safe(op, tmp, free_list, list) { + arch_unoptimize_kprobes(unopt_list, &unoptimized); + + /* Loop on newly unoptimized probes for disarming and hash list removal */ + list_for_each_entry_safe(op, tmp, &unoptimized, list) { /* Switching from detour code to origin */ op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; - /* Disarm probes if marked disabled and not gone */ - if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp)) + /* + * Disarm probes if marked disabled and not gone. Unhashed probes + * were disarmed before they were unhashed. + */ + if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp) && + !hlist_unhashed(&op->kp.hlist)) arch_disarm_kprobe(&op->kp); if (kprobe_unused(&op->kp)) { /* @@ -643,6 +646,7 @@ static void do_unoptimize_kprobes(struct list_head *unopt_list, * (reclaiming is done by do_free_cleaned_kprobes().) */ hlist_del_init_rcu(&op->kp.hlist); + list_move(&op->list, free_list); } else { /* * Keep on cooling_list until the quiescence period @@ -725,10 +729,17 @@ static void optprobe_finalize_generation(struct optprobe_generation *gen) list_move(&op->list, &optprobe_gens[optprobe_cur_gen].freeing_list); kick_kprobe_optimizer(); } else { + struct kprobe *_p; + /* Still in use; now safely disarmed */ list_del_init(&op->list); - if (!kprobe_disabled(&op->kp)) + if (!kprobe_disabled(&op->kp)) { optimize_kprobe(&op->kp); + } else { + _p = get_optimized_kprobe(op->kp.addr); + if (unlikely(_p)) + optimize_kprobe(_p); + } } } @@ -1002,9 +1013,10 @@ static void unoptimize_kprobe(struct kprobe *p, bool force) * for cooling down (or freeing if unused). */ force_unoptimize_kprobe(op); + /* Disarm probes if marked disabled and not gone */ + if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp)) + arch_disarm_kprobe(&op->kp); if (kprobe_unused(&op->kp)) { - if (!kprobe_gone(&op->kp)) - arch_disarm_kprobe(&op->kp); hlist_del_init_rcu(&op->kp.hlist); list_move(&op->list, &cur->freeing_list); } else { @@ -1039,10 +1051,11 @@ static void unoptimize_kprobe(struct kprobe *p, bool force) if (force) { /* Forcibly update the code: this is a special case */ force_unoptimize_kprobe(op); + list_add(&op->list, &cur->cooling_list); } else { list_add(&op->list, &cur->unoptimizing_list); - kick_kprobe_optimizer(); } + kick_kprobe_optimizer(); } /* Cancel unoptimizing for reusing */ @@ -1056,6 +1069,10 @@ static int reuse_unused_kprobe(struct kprobe *ap) */ op = container_of(ap, struct optimized_kprobe, kp); WARN_ON_ONCE(list_empty(&op->list)); + /* Already disarmed, the caller arms it only for an enabled probe */ + if (optprobe_queued_cooling(op)) + return 0; + /* Enable the probe again */ ap->flags &= ~KPROBE_FLAG_DISABLED; /* Optimize it again. (remove from 'op->list') */ @@ -1253,6 +1270,19 @@ static void __init kprobe_sysctls_init(void) } #endif /* CONFIG_SYSCTL */ +/* Return true if the probe is queued on unoptimizing lists */ +static bool kprobe_queued_unopt(struct kprobe *p) +{ + struct optimized_kprobe *op; + + if (kprobe_aggrprobe(p)) { + op = container_of(p, struct optimized_kprobe, kp); + if (optprobe_queued_unopt(op)) + return true; + } + return false; +} + /* Put a breakpoint for a probe. */ static void __arm_kprobe(struct kprobe *p) { @@ -1266,21 +1296,11 @@ static void __arm_kprobe(struct kprobe *p) /* Fallback to unoptimized kprobe */ unoptimize_kprobe(_p, true); - arch_arm_kprobe(p); + if (!kprobe_queued_unopt(p)) + arch_arm_kprobe(p); optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ -} - -/* Return true if the probe is queued on unoptimizing lists */ -static bool kprobe_queued_unopt(struct kprobe *p) -{ - struct optimized_kprobe *op; - - if (kprobe_aggrprobe(p)) { - op = container_of(p, struct optimized_kprobe, kp); - if (optprobe_queued_unopt(op)) - return true; - } - return false; + if (unlikely(kprobe_queued_unopt(p))) + unoptimize_kprobe(p, true); } /* Remove the breakpoint of a probe. */ @@ -1435,9 +1455,14 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, (*cnt)--; ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); - WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (error %d)\n", - p->addr, ret); - return ret; + if (WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (error %d)\n", + p->addr, ret)) { + if (*cnt == 0) + register_ftrace_function(ops); + (*cnt)++; + return ret; + } + return 0; } static int disarm_kprobe_ftrace(struct kprobe *p) @@ -1566,16 +1591,13 @@ void kprobe_busy_end(void) } /* Add the new probe to 'ap->list'. */ -static int add_new_kprobe(struct kprobe *ap, struct kprobe *p) +static void add_new_kprobe(struct kprobe *ap, struct kprobe *p) { - if (p->post_handler) + /* A reused cooling probe is already unoptimized */ + if (p->post_handler && !kprobe_unused(ap)) unoptimize_kprobe(ap, true); /* Fall back to normal kprobe */ list_add_rcu(&p->list, &ap->list); - if (p->post_handler && !ap->post_handler) - ap->post_handler = aggr_post_handler; - - return 0; } /* @@ -1608,6 +1630,8 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) { int ret = 0; struct kprobe *ap = orig_p; + bool reset_post_handler = false; + bool ftrace_switch_ops = false; scoped_guard(cpus_read_lock) { /* For preparing optimization, jump_label_text_reserved() is called */ @@ -1654,18 +1678,50 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) | KPROBE_FLAG_DISABLED; } + if (p->post_handler && !ap->post_handler) { + reset_post_handler = true; + if (kprobe_ftrace(ap) && !kprobes_all_disarmed && + !kprobe_disabled(ap)) + ftrace_switch_ops = true; + else + ap->post_handler = aggr_post_handler; + } + /* Copy the insn slot of 'p' to 'ap'. */ copy_kprobe(ap, p); - ret = add_new_kprobe(ap, p); + if (!ftrace_switch_ops) + add_new_kprobe(ap, p); + } + + if (ftrace_switch_ops) { + /* + * Must switch ftrace ops outside of text_mutex and cpus_read_lock + * to prevent deadlocks when ftrace code modification acquires text_mutex. + */ + ret = disarm_kprobe_ftrace(ap); + if (ret) + return ret; + + ap->post_handler = aggr_post_handler; + ret = arm_kprobe_ftrace(ap); + if (ret) { + ap->post_handler = NULL; + if (arm_kprobe_ftrace(ap)) + ap->flags |= KPROBE_FLAG_DISABLED; + return ret; + } + add_new_kprobe(ap, p); } - if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) { + if (kprobe_disabled(ap) && !kprobe_disabled(p)) { ap->flags &= ~KPROBE_FLAG_DISABLED; if (!kprobes_all_disarmed) { /* Arm the breakpoint again. */ ret = arm_kprobe(ap); if (ret) { ap->flags |= KPROBE_FLAG_DISABLED; + if (reset_post_handler) + ap->post_handler = NULL; list_del_rcu(&p->list); synchronize_rcu(); } @@ -1793,52 +1849,61 @@ _kprobe_addr(kprobe_opcode_t *addr, const char *symbol_name, return addr; } -static kprobe_opcode_t *kprobe_addr(struct kprobe *p) -{ - bool on_func_entry; - - return _kprobe_addr(p->addr, p->symbol_name, p->offset, &on_func_entry); -} - /* * Check the 'p' is valid and return the aggregator kprobe * at the same address. */ -static struct kprobe *__get_valid_kprobe(struct kprobe *p) +static struct kprobe *__get_valid_kprobe_at(struct kprobe *p, kprobe_opcode_t *addr) { + struct hlist_head *head; struct kprobe *ap, *list_p; lockdep_assert_held(&kprobe_mutex); - ap = get_kprobe(p->addr); - if (unlikely(!ap)) + if (unlikely(!addr)) return NULL; - if (p == ap) - return ap; - - list_for_each_entry(list_p, &ap->list, list) - if (list_p == p) - /* kprobe p is a valid probe */ + head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)]; + hlist_for_each_entry_rcu(ap, head, hlist, + lockdep_is_held(&kprobe_mutex)) { + if (ap == p) { + p->addr = addr; return ap; + } + if (ap->addr == addr && kprobe_aggrprobe(ap)) { + list_for_each_entry(list_p, &ap->list, list) { + if (list_p == p) { + p->addr = addr; + return ap; + } + } + } + } return NULL; } -/* - * Warn and return error if the kprobe is being re-registered since - * there must be a software bug. - */ -static inline int warn_kprobe_rereg(struct kprobe *p) +static inline struct kprobe *__get_valid_kprobe(struct kprobe *p) +{ + return __get_valid_kprobe_at(p, p->addr); +} + +/* Return error if the kprobe is being re-registered */ +static inline int check_kprobe_rereg_at(struct kprobe *p, kprobe_opcode_t *addr) { guard(mutex)(&kprobe_mutex); - if (WARN_ON_ONCE(__get_valid_kprobe(p))) + if (__get_valid_kprobe_at(p, addr)) return -EINVAL; return 0; } +static inline int check_kprobe_rereg(struct kprobe *p) +{ + return check_kprobe_rereg_at(p, p->addr); +} + static int check_ftrace_location(struct kprobe *p) { unsigned long addr = (unsigned long)p->addr; @@ -1946,6 +2011,8 @@ static int __register_kprobe(struct kprobe *p) if (ret) { hlist_del_rcu(&p->hlist); synchronize_rcu(); + arch_remove_kprobe(p); + return ret; } } @@ -1967,7 +2034,7 @@ int register_kprobe(struct kprobe *p) return PTR_ERR(addr); p->addr = addr; - ret = warn_kprobe_rereg(p); + ret = check_kprobe_rereg(p); if (ret) return ret; @@ -2503,20 +2570,19 @@ int register_kretprobe(struct kretprobe *rp) int ret; int i; void *addr; + bool on_func_entry; - ret = kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset); - if (ret) - return ret; + addr = _kprobe_addr(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset, &on_func_entry); + if (IS_ERR(addr)) + return PTR_ERR(addr); - /* If only 'rp->kp.addr' is specified, check reregistering kprobes */ - if (rp->kp.addr && warn_kprobe_rereg(&rp->kp)) + if (!on_func_entry) return -EINVAL; - if (kretprobe_blacklist_size) { - addr = kprobe_addr(&rp->kp); - if (IS_ERR(addr)) - return PTR_ERR(addr); + if (check_kprobe_rereg_at(&rp->kp, addr)) + return -EINVAL; + if (kretprobe_blacklist_size) { for (i = 0; kretprobe_blacklist[i].name != NULL; i++) { if (kretprobe_blacklist[i].addr == addr) return -EINVAL; @@ -2603,8 +2669,10 @@ void unregister_kretprobes(struct kretprobe **rps, int num) for (i = 0; i < num; i++) { guard(mutex)(&kprobe_mutex); - if (__unregister_kprobe_top(&rps[i]->kp) < 0) + if (__unregister_kprobe_top(&rps[i]->kp) < 0) { rps[i]->kp.addr = NULL; + continue; + } #ifdef CONFIG_KRETPROBE_ON_RETHOOK rethook_free(rps[i]->rh); #else @@ -2616,7 +2684,9 @@ void unregister_kretprobes(struct kretprobe **rps, int num) for (i = 0; i < num; i++) { if (rps[i]->kp.addr) { __unregister_kprobe_bottom(&rps[i]->kp); -#ifndef CONFIG_KRETPROBE_ON_RETHOOK +#ifdef CONFIG_KRETPROBE_ON_RETHOOK + rps[i]->rh = NULL; +#else free_rp_inst(rps[i]); #endif } diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 6f1f55fe318192..42c6609a1766a5 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1643,7 +1643,7 @@ EXPORT_SYMBOL_GPL(kho_restore_free); */ bool is_kho_boot(void) { - return !!kho_get_fdt(); + return !!kho_in.fdt_phys; } EXPORT_SYMBOL_GPL(is_kho_boot); diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c index f48e9a4185f978..74bc66929f4b53 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -176,16 +176,6 @@ static int luo_session_insert(struct luo_session_header *sh, guard(rwsem_write)(&sh->rwsem); - /* - * For outgoing we should make sure there is room in serialization array - * for new session. - */ - if (sh == &luo_session_global.outgoing) { - err = kho_block_set_grow(&sh->block_set, sh->count + 1); - if (err) - return err; - } - /* * For small number of sessions this loop won't hurt performance * but if we ever start using a lot of sessions, this might @@ -196,6 +186,17 @@ static int luo_session_insert(struct luo_session_header *sh, if (!strncmp(it->name, session->name, sizeof(it->name))) return -EEXIST; } + + /* + * For outgoing we should make sure there is room in serialization array + * for new session. + */ + if (sh == &luo_session_global.outgoing) { + err = kho_block_set_grow(&sh->block_set, sh->count + 1); + if (err) + return err; + } + list_add_tail(&session->list, &sh->list); sh->count++; diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c3dc84a7cef26f..fdae495bf918bd 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -811,7 +811,7 @@ static void lockdep_print_held_locks(struct task_struct *p) */ printk("locks held by %s/%d: %d, %s CPU#%d%s\n", p->comm, task_pid_nr(p), depth, - task_is_running(p) ? "last" : "on", task_cpu(p), + task_is_running(p) ? "on" : "last", task_cpu(p), depth > 0 ? ":" : ""); for (i = 0; i < depth; i++) { diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index b4233dc2c2b04c..2bcc148eb2ddbd 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -59,7 +59,7 @@ osq_wait_next(struct optimistic_spin_queue *lock, for (;;) { if (atomic_read(&lock->tail) == curr && - atomic_cmpxchg_acquire(&lock->tail, curr, old_cpu) == curr) { + atomic_cmpxchg_release(&lock->tail, curr, old_cpu) == curr) { /* * We were the last queued, we moved @lock back. @prev * will now observe @lock and will complete its @@ -90,6 +90,49 @@ osq_wait_next(struct optimistic_spin_queue *lock, } } +/* + * Set prev->next; this is the counterpart of osq_wait_next() in that + * by setting ->next the wait is terminated and progress is resumed. + */ +static inline void osq_link_next(struct optimistic_spin_node *prev, + struct optimistic_spin_node *next) +{ + /* + * Suppose: + * + * tail + * | + * V + * CPU1 -> CPU2 -> CPU3: + * n: 2 n: 3 n: nil + * p: nil p: 1 p: 2 + * + * And this is CPU2 doing the self-unqueue concurrent against CPU1s + * unlock()/unqueue(). Since 'prev->next == NULL' and CPU1 will be + * stuck in osq_wait_next() until the below store of 'prev->next'. + * + * CPU2 CPU1 + * + * next->prev = prev; osq_wait_next() + * WMB MB + * prev->next = next; next->prev = prev + * + * Without the WMB it would be possible to have conflicting stores + * like: + * + * CPU2 CPU1 + * + * prev->next = next // CPU1.n = 3 + * next = osq_wait_next() // = 3 + * next->prev = prev // CPU3.p = nil + * next->prev = prev // CPU3.p = 1 + * + * Which would result in list corruption. + */ + smp_wmb(); + WRITE_ONCE(prev->next, next); +} + bool osq_lock(struct optimistic_spin_queue *lock) { struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); @@ -113,20 +156,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) prev = decode_cpu(old); node->prev = prev; - - /* - * osq_lock() unqueue - * - * node->prev = prev osq_wait_next() - * WMB MB - * prev->next = node next->prev = prev // unqueue-C - * - * Here 'node->prev' and 'next->prev' are the same variable and we need - * to ensure these stores happen in-order to avoid corrupting the list. - */ - smp_wmb(); - - WRITE_ONCE(prev->next, node); + osq_link_next(prev, node); /* * Normally @prev is untouchable after the above store; because at that @@ -202,7 +232,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) */ WRITE_ONCE(next->prev, prev); - WRITE_ONCE(prev->next, next); + osq_link_next(prev, next); return false; } diff --git a/kernel/module/kmod.c b/kernel/module/kmod.c index 24091210741e08..6db525d9779d8f 100644 --- a/kernel/module/kmod.c +++ b/kernel/module/kmod.c @@ -82,7 +82,7 @@ static int call_modprobe(char *orig_module_name, int wait) char *module_name; int ret; - char **argv = kmalloc_array(5, sizeof(*argv), GFP_KERNEL); + char **argv = kmalloc_objs(*argv, 5); if (!argv) goto out; diff --git a/kernel/nscommon.c b/kernel/nscommon.c index e72426bba29ab1..4438c6b663f913 100644 --- a/kernel/nscommon.c +++ b/kernel/nscommon.c @@ -54,7 +54,8 @@ static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops) } #endif -int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum) +int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, + int inum, u64 ns_id) { int ret = 0; @@ -64,7 +65,6 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope ns->ns_security = NULL; #endif ns->ops = ops; - ns->ns_id = 0; ns->ns_type = ns_type; ns_tree_node_init(&ns->ns_tree_node); ns_tree_node_init(&ns->ns_unified_node); @@ -82,6 +82,9 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope if (ret) return ret; + /* Allocate the id before the LSM hook so it can track the namespace by it. */ + __ns_tree_gen_id(ns, ns_id); + ret = security_namespace_init(ns); if (ret) { if (!inum) diff --git a/kernel/nstree.c b/kernel/nstree.c index a756ae2e7881a9..44e07d0fa8e5df 100644 --- a/kernel/nstree.c +++ b/kernel/nstree.c @@ -194,7 +194,7 @@ static int ns_cmp_owner(struct rb_node *a, const struct rb_node *b) return ns_id_cmp(node_to_ns_owner(a)->ns_id, node_to_ns_owner(b)->ns_id); } -void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree_root *ns_tree) +void __ns_tree_add(struct ns_common *ns, struct ns_tree_root *ns_tree) { struct rb_node *node; const struct proc_ns_operations *ops = ns->ops; diff --git a/kernel/panic.c b/kernel/panic.c index 574ee5a12f92e4..91e48d33b7dbbd 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -884,7 +884,7 @@ static __init int alloc_taint_buf(void) size += 1; /* For NULL terminator */ - buf = kmalloc(size, GFP_KERNEL); + buf = kzalloc(size, GFP_KERNEL); if (!buf) { panic("Failed to allocate taint string buffer"); diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index d19a65461ae80f..23bc3e798a938f 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -156,8 +156,7 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("id", 0444, d, dev->em_pd, &em_debug_id_fops); - em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states, - sizeof(*em_dbg), GFP_KERNEL); + em_dbg = devm_kzalloc_objs(dev, *em_dbg, dev->em_pd->nr_perf_states); if (!em_dbg) return; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9a205f94bfac7b..5dbcf8a9909bb6 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3792,6 +3792,13 @@ static struct syscore printk_syscore = { * If appropriate, start nbcon kthreads and set @printk_kthreads_running. * If any kthreads fail to start, those consoles are unregistered. * + * Called after consoles are registered or unregistered. + * + * This MUST NOT be called within an hlist_for_each_entry_safe(console_list) + * loop because it can unregister multiple consoles if any kthreads fail to + * start. That would lead to use-after-free scenarios within the + * hlist_for_each_entry_safe(console_list) loop of the caller. + * * Must be called under console_list_lock(). */ static void printk_kthreads_check_locked(void) @@ -4230,7 +4237,20 @@ void register_console(struct console *newcon) } EXPORT_SYMBOL(register_console); -/* Must be called under console_list_lock(). */ +/* + * Unregister the specified console. + * + * This can be called safely from within an + * hlist_for_each_entry_safe(console_list) loop because it unregisters + * _only_ the specified console. + * + * Afterwards the caller should call printk_kthreads_check_locked() since + * unregistering a console may require printer threads to start/stop. Note + * that printk_kthreads_check_locked() cannot be called safely from within + * an hlist_for_each_entry_safe(console_list) loop. + * + * Must be called under console_list_lock(). + */ static int unregister_console_locked(struct console *console) { bool use_device_lock = (console->flags & CON_NBCON) && console->write_atomic; @@ -4322,9 +4342,6 @@ static int unregister_console_locked(struct console *console) if (console->exit) res = console->exit(console); - /* Changed console list, may require printer threads to start/stop. */ - printk_kthreads_check_locked(); - return res; } @@ -4333,7 +4350,12 @@ int unregister_console(struct console *console) int res; console_list_lock(); + res = unregister_console_locked(console); + + /* Changed console list, may require printer threads to start/stop. */ + printk_kthreads_check_locked(); + console_list_unlock(); return res; } @@ -4472,6 +4494,10 @@ static int __init printk_late_init(void) unregister_console_locked(con); } + + /* Changed console list, may require printer threads to start/stop. */ + printk_kthreads_check_locked(); + console_list_unlock(); ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index d38e7c2f688760..46a79ec0940a7c 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1237,11 +1237,9 @@ static unsigned int space_used(struct prb_data_ring *data_ring, if (BLK_DATALESS(blk_lpos)) return 0; - if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) { - /* Data block does not wrap. */ - return (DATA_INDEX(data_ring, blk_lpos->next) - - DATA_INDEX(data_ring, blk_lpos->begin)); - } + /* Data block does not wrap. */ + if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) + return blk_lpos->next - blk_lpos->begin; /* * For wrapping data blocks, the trailing (wasted) space is diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c index 1097ec15879cb3..38c75c37a07c30 100644 --- a/kernel/rcu/rcuscale.c +++ b/kernel/rcu/rcuscale.c @@ -1188,7 +1188,7 @@ rcu_scale_init(void) } } writer_tasks = kzalloc_objs(writer_tasks[0], nrealwriters); - writer_durations = kcalloc(nrealwriters, sizeof(*writer_durations), GFP_KERNEL); + writer_durations = kzalloc_objs(*writer_durations, nrealwriters); writer_n_durations = kzalloc_objs(*writer_n_durations, nrealwriters); writer_done = kzalloc_objs(writer_done[0], nrealwriters); if (gp_async) { @@ -1210,8 +1210,7 @@ rcu_scale_init(void) } for (i = 0; i < nrealwriters; i++) { writer_durations[i] = - kcalloc(MAX_MEAS, sizeof(*writer_durations[i]), - GFP_KERNEL); + kzalloc_objs(*writer_durations[i], MAX_MEAS); if (!writer_durations[i]) { firsterr = -ENOMEM; goto unwind; diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index 968343be4e0d1a..93ca7f06371e47 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -1763,7 +1763,7 @@ rcu_torture_writer(void *arg) return 0; } if (cur_ops->poll_active > 0) { - ulo = kcalloc(cur_ops->poll_active, sizeof(*ulo), GFP_KERNEL); + ulo = kzalloc_objs(*ulo, cur_ops->poll_active); if (!WARN_ON(!ulo)) ulo_size = cur_ops->poll_active; } @@ -2791,8 +2791,8 @@ static void rcu_torture_nmi_init(void) if (!nmi_calls || !cur_ops->nmi_capable || !cur_ops->call) return; - rcu_torture_nmi_events = kcalloc(nr_cpu_ids, sizeof(*rcu_torture_nmi_events), - GFP_KERNEL); + rcu_torture_nmi_events = kzalloc_objs(*rcu_torture_nmi_events, + nr_cpu_ids); if (!rcu_torture_nmi_events) return; ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "rcutorture/nmi:online", diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index a2d9d75d88a10d..4f3460700e34b1 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -1366,7 +1366,7 @@ static int main_func(void *arg) set_user_nice(current, MAX_NICE); VERBOSE_SCALEOUT("main_func task started"); - result_avg = kcalloc(nruns, sizeof(*result_avg), GFP_KERNEL); + result_avg = kzalloc_objs(*result_avg, nruns); buf = kzalloc(800 + 64, GFP_KERNEL); if (!result_avg || !buf) { SCALEOUT_ERRSTRING("out of memory"); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 04b62c16fa8ca0..5ed660f099a55a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -636,7 +636,7 @@ int task_llc(const struct task_struct *p) * * p->is_blocked <- { 0, 1 }: * - * is set by try_to_block_task() and cleared by ttwu_do_wakeup() and tracks + * is set by try_to_block_task() and cleared by unblock_task() and tracks * if the task is blocked. Traditionally this would mirror p->on_rq, however * due things like DELAY_DEQUEUE and PROXY_EXEC, this can diverge. * @@ -3773,12 +3773,22 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_flags) __schedstat_inc(p->stats.nr_wakeups_sync); } +static inline void unblock_task(struct task_struct *p) +{ + if (p->is_blocked && p->in_iowait) { + delayacct_blkio_end(p); + atomic_dec(&cpu_rq(p->iowait_cpu)->nr_iowait); + } + + p->is_blocked = 0; +} + /* * Mark the task runnable. */ static inline void ttwu_do_wakeup(struct task_struct *p) { - p->is_blocked = 0; + unblock_task(p); WRITE_ONCE(p->__state, TASK_RUNNING); trace_sched_wakeup(p); } @@ -3889,10 +3899,6 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, en_flags |= ENQUEUE_RQ_SELECTED; if (wake_flags & WF_MIGRATED) en_flags |= ENQUEUE_MIGRATED; - else if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } activate_task(rq, p, en_flags); wakeup_preempt(rq, p, wake_flags); @@ -4465,11 +4471,6 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) cpu = select_task_rq(p, p->wake_cpu, &wake_flags); if (task_cpu(p) != cpu) { - if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } - wake_flags |= WF_MIGRATED; psi_ttwu_dequeue(p); set_task_cpu(p, cpu); @@ -6296,7 +6297,6 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) __must_hold(__rq_lockp(rq)) { struct task_struct *next, *p, *max; - const struct cpumask *smt_mask; bool fi_before = false; bool core_clock_updated = (rq == rq->core); unsigned long cookie; @@ -6343,8 +6343,6 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) prev_balance(rq, rf); - smt_mask = cpu_smt_mask(cpu); - restart: need_sync |= !!rq->core->core_cookie; @@ -6412,7 +6410,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) * Tie-break prio towards the current CPU */ max = NULL; - for_each_cpu_wrap(i, smt_mask, cpu) { + for_each_core_cpu_wrap(i, rq) { rq_i = cpu_rq(i); /* @@ -6445,7 +6443,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) * For each thread: try and find a runnable task that matches @max or * force idle. */ - for_each_cpu(i, smt_mask) { + for_each_core_cpu(i, rq) { rq_i = cpu_rq(i); p = rq_i->core_pick; @@ -6490,7 +6488,7 @@ pick_next_task(struct rq *rq, struct rq_flags *rf) * their task. This ensures there is no inter-sibling overlap between * non-matching user state. */ - for_each_cpu(i, smt_mask) { + for_each_core_cpu(i, rq) { rq_i = cpu_rq(i); /* @@ -6813,6 +6811,12 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p, p->is_blocked = 1; + if (p->in_iowait) { + p->iowait_cpu = cpu_of(rq); + atomic_inc(&rq->nr_iowait); + delayacct_blkio_start(); + } + /* * We check should_block after signal_pending because we * will want to wake the task in that case. But if @@ -7020,7 +7024,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) if (!mutex) { clear_task_blocked_on(p, mutex); if (task_current(rq, p)) { - p->is_blocked = 0; + unblock_task(p); return p; } goto deactivate; @@ -7056,7 +7060,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) */ __clear_task_blocked_on(p, NULL); if (task_current(rq, p)) { - p->is_blocked = 0; + unblock_task(p); return p; } goto deactivate; diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c index 43e0bde3038e9f..d56be1c31435f6 100644 --- a/kernel/sched/core_sched.c +++ b/kernel/sched/core_sched.c @@ -241,7 +241,6 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type, /* REQUIRES: rq->core's clock recently updated. */ void __sched_core_account_forceidle(struct rq *rq) { - const struct cpumask *smt_mask = cpu_smt_mask(cpu_of(rq)); u64 delta, now = rq_clock(rq->core); struct rq *rq_i; struct task_struct *p; @@ -273,7 +272,7 @@ void __sched_core_account_forceidle(struct rq *rq) delta = div_u64(delta, rq->core->core_forceidle_occupation); } - for_each_cpu(i, smt_mask) { + for_each_core_cpu(i, rq) { rq_i = cpu_rq(i); p = rq_i->core_pick ?: rq_i->curr; diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index c0ebdcde5fe5d4..dfae08625342e0 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -444,7 +444,7 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task) if (!dl_task || READ_ONCE(p->__state) == TASK_DEAD) { struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); - if (READ_ONCE(p->__state) == TASK_DEAD) + if (dl_task && READ_ONCE(p->__state) == TASK_DEAD) sub_rq_bw(dl_se, &rq->dl); raw_spin_lock(&dl_b->lock); __dl_sub(dl_b, dl_se->dl_bw, dl_bw_cpus(task_cpu(p))); diff --git a/kernel/sched/ext/cid.c b/kernel/sched/ext/cid.c index 8e04a8494e1188..0cc397055f5775 100644 --- a/kernel/sched/ext/cid.c +++ b/kernel/sched/ext/cid.c @@ -64,7 +64,13 @@ static void calc_shard_layout(const struct cpumask *llc_cpus, u32 shard_size, for_each_cpu(cpu, llc_cpus) { nr_cpus++; - if (cpumask_first(topology_sibling_cpumask(cpu)) == cpu) + /* + * scx_cid_init() forms each core from the siblings in + * @llc_cpus. The sibling mask may include cpus outside + * @llc_cpus, so count a core at its first sibling in @llc_cpus. + */ + if (cpumask_first_and(topology_sibling_cpumask(cpu), + llc_cpus) == cpu) nr_cores++; } diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index f74ffb3b1aca6e..10de6bd865e82a 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -461,6 +461,14 @@ static bool rq_is_open(struct rq *rq, u64 enq_flags) * @rq is either picking, in transition to, or running an SCX task. */ + /* + * A local insertion can raise next_class to ext while the donor is + * still idle. Keep the rq open so that the local DSQ head is not + * unnecessarily reenqueued before the CPU can pick it. + */ + if (rq->donor == rq->idle) + return true; + /* * If we're in the dispatch path holding rq lock, $donor may or may not * be ready depending on whether the on-going dispatch decides to extend @@ -580,12 +588,14 @@ enum scx_dsq_iter_flags { /* iterate in the reverse dispatch order */ SCX_DSQ_ITER_REV = 1U << 16, + __SCX_DSQ_ITER_DRAINED = 1U << 28, __SCX_DSQ_ITER_HAS_REENQ = 1U << 29, __SCX_DSQ_ITER_HAS_SLICE = 1U << 30, __SCX_DSQ_ITER_HAS_VTIME = 1U << 31, __SCX_DSQ_ITER_USER_FLAGS = SCX_DSQ_ITER_REV, __SCX_DSQ_ITER_ALL_FLAGS = __SCX_DSQ_ITER_USER_FLAGS | + __SCX_DSQ_ITER_DRAINED | __SCX_DSQ_ITER_HAS_REENQ | __SCX_DSQ_ITER_HAS_SLICE | __SCX_DSQ_ITER_HAS_VTIME, @@ -2225,11 +2235,11 @@ static void direct_dispatch(struct scx_sched *sch, struct task_struct *p, bool scx_rq_online(struct rq *rq) { /* - * Test both cpu_active() and %SCX_RQ_ONLINE. %SCX_RQ_ONLINE follows the - * core's rq online state. cpu_active() test guarantees that, if this - * function returns %true, %SCX_RQ_ONLINE will stay set until the - * current scheduling operation is complete even if we aren't locking - * @rq. + * Test both cpu_active() and %SCX_RQ_ONLINE. %SCX_RQ_ONLINE is set + * after the root's ops.cpu_online() and cleared when the cpu goes down. + * cpu_active() test guarantees that, if this function returns %true, + * %SCX_RQ_ONLINE will stay set until the current scheduling operation + * is complete even if we aren't locking @rq. */ return likely((rq->scx.flags & SCX_RQ_ONLINE) && cpu_active(cpu_of(rq))); } @@ -2420,7 +2430,7 @@ static void set_task_runnable(struct rq *rq, struct task_struct *p) } /* - * list_add_tail() must be used. scx_bypass() and rq_offline_scx() + * list_add_tail() must be used. scx_bypass() and drain_offline_rq() * depend on tasks being appended to the runnable_list. */ list_add_tail(&p->scx.runnable_node, &rq->scx.runnable_list); @@ -3399,6 +3409,12 @@ static enum scx_dsp_verdict dispatch_one(struct rq *rq, struct task_struct *prev rq->scx.cpu_released = false; } + /* the ecaps sync may have dropped the rq lock */ + if (scx_dsp_prev_stale(rq, prev)) { + verdict = SCX_DSP_RETRY; + goto has_tasks; + } + if (prev->sched_class == &ext_sched_class) { update_curr_scx(rq); @@ -3441,6 +3457,10 @@ static enum scx_dsp_verdict dispatch_one(struct rq *rq, struct task_struct *prev } verdict = scx_dispatch_sched(root_sch, rq, prev, false); + + /* scx_dispatch_sched() may have dropped the rq lock */ + if (scx_dsp_prev_stale(rq, prev)) + verdict = SCX_DSP_RETRY; if (verdict != SCX_DSP_NONE) goto has_tasks; @@ -4296,12 +4316,37 @@ static void set_cpus_allowed_scx(struct task_struct *p, scx_call_op_set_cpumask(sch, task_rq(p), p, (struct cpumask *)p->cpus_ptr); } +static void drain_offline_rq(struct rq *rq) +{ + struct task_struct *p, *n; + + scx_rescue_flush(rq); + + /* + * An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks + * onto the local DSQ so that they run here and balance_push() moves + * them off. + */ + list_for_each_entry_safe_reverse(p, n, &rq->scx.runnable_list, scx.runnable_node) { + if (p->scx.dsq == &rq->scx.local_dsq) + continue; + guard(sched_change)(p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK); + } +} + static void handle_hotplug(struct rq *rq, bool online) { struct scx_sched *sch = scx_root_protected(); s32 cpu = cpu_of(rq); s32 cpu_or_cid = cpu; + if (!online) { + guard(rq_lock_irqsave)(rq); + update_rq_clock(rq); + rq->scx.flags &= ~SCX_RQ_ONLINE; + drain_offline_rq(rq); + } + atomic_long_inc(&scx_hotplug_seq); scx_update_frozen_cpus(cpu, online); @@ -4310,8 +4355,14 @@ static void handle_hotplug(struct rq *rq, bool online) * stable here. Note that we can't depend on scx_enabled() test as the * hotplug ops need to be enabled before __scx_enabled is set. */ - if (unlikely(!sch)) + if (unlikely(!sch)) { + /* no root to notify, set %SCX_RQ_ONLINE right away */ + if (online) { + guard(rq_lock_irqsave)(rq); + rq->scx.flags |= SCX_RQ_ONLINE; + } return; + } if (scx_enabled()) scx_idle_update_selcpu_topology(&sch->ops); @@ -4362,8 +4413,22 @@ static void handle_hotplug(struct rq *rq, bool online) "cpu %d going %s, exiting scheduler", cpu, online ? "online" : "offline"); - if (online) + if (online) { + /* + * The cpu must not call ops.enqueue() or ops.dispatch() before + * the root's ops.cpu_online(). The core's rq online state can't + * gate them, as the sched domain rebuild in + * sched_cpu_activate() can put @rq online before this function + * runs. Set %SCX_RQ_ONLINE here. + * + * scx_online_ecaps() queues a reseed whose ecaps ops run in + * dispatch context on the cpu and can insert into its local + * DSQ. Set the flag first. + */ + scoped_guard (rq_lock_irqsave, rq) + rq->scx.flags |= SCX_RQ_ONLINE; scx_online_ecaps(rq); + } } void scx_rq_activate(struct rq *rq) @@ -4376,35 +4441,6 @@ void scx_rq_deactivate(struct rq *rq) handle_hotplug(rq, false); } -static void rq_online_scx(struct rq *rq) -{ - rq->scx.flags |= SCX_RQ_ONLINE; -} - -static void rq_offline_scx(struct rq *rq) -{ - struct task_struct *p, *n; - - rq->scx.flags &= ~SCX_RQ_ONLINE; - - /* sched domain rebuilds call rq_offline with the CPU staying alive */ - if (cpu_active(cpu_of(rq))) - return; - - scx_rescue_flush(rq); - - /* - * An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks - * onto the local DSQ so that they run here and balance_push() moves - * them off. - */ - list_for_each_entry_safe_reverse(p, n, &rq->scx.runnable_list, scx.runnable_node) { - if (p->scx.dsq == &rq->scx.local_dsq) - continue; - guard(sched_change)(p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK); - } -} - static bool check_rq_for_timeouts(struct rq *rq) { struct scx_sched *sch; @@ -4728,6 +4764,7 @@ void __scx_disable_and_exit_task(struct scx_sched *sch, struct task_struct *p) args.cancelled = true; break; case SCX_TASK_READY: + scx_reset_task_fields(task_rq(p), p); break; case SCX_TASK_ENABLED: scx_disable_task(sch, p); @@ -5876,9 +5913,6 @@ DEFINE_SCHED_CLASS(ext) = { .task_woken = task_woken_scx, .set_cpus_allowed = set_cpus_allowed_scx, - .rq_online = rq_online_scx, - .rq_offline = rq_offline_scx, - .task_tick = task_tick_scx, .switching_to = switching_to_scx, @@ -7779,10 +7813,17 @@ void scx_flush_disable_work(struct scx_sched *sch) { int kind; + /* + * scx_disable_workfn() sets SCX_EXIT_DONE before tearing down. Read + * exit_kind with acquire ordering (paired with atomic_try_cmpxchg() in + * scx_disable_workfn()) before syncing and flushing so that, once DONE + * is seen, the following flush observes the queued work and waits for + * the teardown to finish. + */ do { + kind = atomic_read_acquire(&sch->exit_kind); irq_work_sync(&sch->disable_irq_work); kthread_flush_work(&sch->disable_work); - kind = atomic_read(&sch->exit_kind); } while (kind != SCX_EXIT_NONE && kind != SCX_EXIT_DONE); } @@ -11028,13 +11069,24 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id, __bpf_kfunc struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *it) { struct bpf_iter_scx_dsq_kern *kit = (void *)it; + struct task_struct *p; - if (!kit->dsq) + if (!kit->dsq || (kit->cursor.flags & __SCX_DSQ_ITER_DRAINED)) return NULL; guard(raw_spinlock_irqsave)(&kit->dsq->lock); - return nldsq_cursor_next_task(&kit->cursor, kit->dsq); + p = nldsq_cursor_next_task(&kit->cursor, kit->dsq); + /* + * nldsq_cursor_next_task() unlinks the cursor and starts from the DSQ + * head when it is called again. The verifier relies on an iterator + * which returned NULL to keep returning NULL (see + * process_iter_next_call()), so remember the drained state. + */ + if (!p) + kit->cursor.flags |= __SCX_DSQ_ITER_DRAINED; + + return p; } /** @@ -11107,7 +11159,7 @@ __bpf_kfunc struct task_struct *scx_bpf_dsq_peek(u64 dsq_id, /** * scx_bpf_dsq_reenq - Re-enqueue tasks on a DSQ * @dsq_id: DSQ to re-enqueue - * @reenq_flags: %SCX_RENQ_* + * @reenq_flags: %SCX_REENQ_* * @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs * * Iterate over all of the tasks currently enqueued on the DSQ identified by @@ -11117,8 +11169,9 @@ __bpf_kfunc struct task_struct *scx_bpf_dsq_peek(u64 dsq_id, * - Local DSQs (%SCX_DSQ_LOCAL or %SCX_DSQ_LOCAL_ON | $cpu) * - User DSQs * - * Re-enqueues are performed asynchronously. Can be called from anywhere. A - * re-enqueue of an inactive cpu's local DSQ is ignored. + * Re-enqueues are performed asynchronously. Can be called from any context + * except NMI. A call from NMI aborts the scheduler. A re-enqueue of an inactive + * cpu's local DSQ is ignored. * * %SCX_DSQ_LOCAL resolves to the local DSQ of the rq the current scheduler * operation is locked to - e.g. the rq being dispatched for in ops.dispatch() - @@ -11215,9 +11268,10 @@ __bpf_kfunc bool scx_bpf_dsq_reenq_task(struct bpf_iter_scx_dsq *it__iter, * scx_bpf_reenqueue_local___v2 - Re-enqueue tasks on a local DSQ * @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs * - * Iterate over all of the tasks currently enqueued on the local DSQ of the - * caller's CPU, and re-enqueue them in the BPF scheduler. Can be called from - * anywhere. + * Iterate over all of the tasks currently enqueued on the local DSQ of the rq + * the current scheduler operation is locked to, or the calling CPU's when no rq + * is locked, and re-enqueue them in the BPF scheduler. Can be called from any + * context except NMI. A call from NMI aborts the scheduler. * * This is now a special case of scx_bpf_dsq_reenq() and may be removed in the * future. @@ -12134,6 +12188,11 @@ static const struct btf_kfunc_id_set scx_kfunc_set_any = { * when scx_locked_rq() returns NULL. Taking it while the context already holds * an rq lock, the same one or another cpu's, can deadlock. * + * scx_bpf_destroy_dsq() takes a user DSQ lock. So do + * bpf_iter_scx_dsq_next() and bpf_iter_scx_dsq_destroy(), the latter only + * after a successful next() has linked the cursor. A tracing program can + * run while that lock is already held and recursively acquire it. + * * Before returning, scx_bpf_sub_grant() and scx_bpf_sub_revoke() invoke * ops.sub_caps_updated() of the sub-schedulers whose caps changed, so those ops * run in the tracing program's context. No SCX op expects to run from an @@ -12148,6 +12207,9 @@ BTF_ID_FLAGS(func, scx_bpf_cpuperf_set, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_cidperf_set, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_sub_grant, KF_IMPLICIT_ARGS) BTF_ID_FLAGS(func, scx_bpf_sub_revoke, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, scx_bpf_destroy_dsq, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, bpf_iter_scx_dsq_next, KF_ITER_NEXT | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_iter_scx_dsq_destroy, KF_ITER_DESTROY) BTF_KFUNCS_END(scx_kfunc_ids_no_tracing) /* diff --git a/kernel/sched/ext/inlines.h b/kernel/sched/ext/inlines.h index 1e39d12678c4dc..8de281a5c9c6e5 100644 --- a/kernel/sched/ext/inlines.h +++ b/kernel/sched/ext/inlines.h @@ -18,9 +18,32 @@ enum scx_dsp_verdict { SCX_DSP_NONE, /* nothing to run */ SCX_DSP_LOCAL, /* local DSQ has tasks */ SCX_DSP_PREV, /* keep running @prev */ - SCX_DSP_RETRY, /* pick helpers only: restart the pick */ + SCX_DSP_RETRY, /* restart the pick */ }; +/** + * scx_dsp_prev_stale - Test whether dispatch's @prev went stale + * @rq: rq being dispatched for + * @prev: @rq's donor when dispatch started + * + * @prev can stop being @rq's donor while dispatch has the rq lock dropped. With + * proxy execution, @prev may not be the running task, and another CPU can reset + * the donor to rq->curr. With core scheduling, the core pick runs dispatch for + * the sibling rqs too, and a sibling can switch @prev out. Dispatch restarts + * the pick when that happened and doesn't hand the old donor to the BPF + * scheduler. + * + * With proxy execution alone, the donor only ever changes to rq->curr during a + * pick. Only __schedule() on this CPU sets a different donor, after the pick, + * so the restarted pick takes rq->curr as @prev and can't go stale again. Under + * core scheduling, the restart goes through the core pick, which already + * retries whenever dispatch dropped the lock. + */ +static inline bool scx_dsp_prev_stale(struct rq *rq, struct task_struct *prev) +{ + return (sched_proxy_exec() || sched_core_enabled(rq)) && unlikely(prev != rq->donor); +} + /* * One user of this function is scx_bpf_sub_dispatch() which can be called * recursively as sub-sched dispatches nest. Always inline to reduce stack usage @@ -33,8 +56,7 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq, struct scx_dsp_ctx *dspc = &this_cpu_ptr(sch->pcpu)->dsp_ctx; int nr_loops = SCX_DSP_MAX_LOOPS; s32 cpu = cpu_of(rq); - bool prev_on_sch = (prev->sched_class == &ext_sched_class) && - scx_task_on_sched(sch, prev); + bool prev_on_sch; if (scx_consume_global_dsq(sch, rq)) return SCX_DSP_LOCAL; @@ -82,7 +104,7 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq, /* * scx_rq_online() can't be used. Its cpu_active() test goes false * before CPU hotplug waits for an RCU grace period, and - * rq_offline_scx() moves this CPU's tasks to the local DSQ only after + * handle_hotplug() moves this CPU's tasks to the local DSQ only after * the wait. The grace period can depend on those tasks running. */ if (unlikely(!SCX_HAS_OP(sch, dispatch)) || !(rq->scx.flags & SCX_RQ_ONLINE)) @@ -106,6 +128,11 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq, rq->scx.sub_dispatch_prev = prev; #endif + /* the dispatch so far may have dropped the rq lock */ + prev_on_sch = !scx_dsp_prev_stale(rq, prev) && + prev->sched_class == &ext_sched_class && + scx_task_on_sched(sch, prev); + SCX_CALL_OP(sch, dispatch, rq, scx_cpu_arg(cpu), prev_on_sch ? prev : NULL); @@ -116,7 +143,9 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq, scx_flush_dispatch_buf(sch, rq); - if ((prev->scx.flags & SCX_TASK_QUEUED) && prev->scx.slice) + /* ops.dispatch() and the flush may have dropped the rq lock */ + if (!scx_dsp_prev_stale(rq, prev) && + (prev->scx.flags & SCX_TASK_QUEUED) && prev->scx.slice) return SCX_DSP_PREV; if (rq->scx.local_dsq.nr) return SCX_DSP_LOCAL; diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h index ff0a3d508533f0..58652370da5ad2 100644 --- a/kernel/sched/ext/internal.h +++ b/kernel/sched/ext/internal.h @@ -869,6 +869,10 @@ struct sched_ext_ops { * @sub_attach: Attach a sub-scheduler * @args: argument container, see the struct definition * + * The sub-scheduler's cgroup is online for the whole call. If it goes + * offline after the sub-scheduler is accepted, ops.sub_detach() + * follows. + * * Return 0 to accept the sub-scheduler. -errno to reject. */ s32 (*sub_attach)(struct scx_sub_attach_args *args); diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c index b5d92d89629bf0..d2a20114eaa23f 100644 --- a/kernel/sched/ext/sub.c +++ b/kernel/sched/ext/sub.c @@ -918,10 +918,11 @@ struct scx_dispatch_q *__scx_resolve_local_dsq(struct scx_sched *sch, struct rq return &rq->scx.local_dsq; /* - * The task must run on this CPU regardless of caps: the rq is draining - * offline (BPF scheduler bypassed), the task is migration-disabled, or a - * migration is pending. Admit despite the missing caps and count it. - * Refuse preemptions. + * The task must run on this CPU regardless of caps: ops.enqueue() is + * skipped while the CPU is going down or before the root's + * ops.cpu_online(), the task is migration-disabled, or a migration is + * pending. Admit despite the missing caps and count it. Refuse + * preemptions. */ if (unlikely(!scx_rq_online(rq) || is_migration_disabled(p) || p->migration_pending)) { @@ -2340,8 +2341,21 @@ void scx_sub_enable_workfn(struct kthread_work *work) .cgroup_path = sch->cgrp_path, }; + /* + * The cgroup stays online across ops.sub_attach(), so the parent never + * sees an attach for a cgroup that rmdir already removed. + */ + cgroup_lock(); + if (!(cgrp->self.flags & CSS_ONLINE)) { + cgroup_unlock(); + scx_error(sch, "cgroup is not online"); + ret = -ENODEV; + goto err_disable; + } ret = SCX_CALL_OP_RET(parent, sub_attach, NULL, &sub_attach_args); + cgroup_unlock(); + if (ret) { ret = scx_ops_sanitize_err(sch, "sub_attach", ret); scx_error(sch, "parent rejected (%d)", ret); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index cfc982205b98c6..0c8af1cac2d5bb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1469,6 +1469,12 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu) return false; } +/* Are the running threads (in SMT siblings) below ~80% of the LLC's CPUs? */ +static inline bool fits_llc_nr(u64 nr_threads, unsigned int nr_cpus) +{ + return nr_threads * 5 < (u64)nr_cpus * 4; +} + static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p, int cpu) { @@ -1485,8 +1491,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p, if (scale == INT_MAX) return false; - return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads), - (scale * per_cpu(sd_llc_size, cpu))); + return !fits_llc_nr(READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads, + scale * per_cpu(sd_llc_size, cpu)); } /* @@ -6964,8 +6970,8 @@ static void dequeue_throttled_task(struct task_struct *p, int flags) WARN_ON_ONCE(p->se.on_rq); list_del_init(&p->throttle_node); - /* task blocked after throttled */ - if (flags & DEQUEUE_SLEEP) { + /* Task blocked after throttling or is leaving the fair class: */ + if (flags & (DEQUEUE_SLEEP | DEQUEUE_CLASS)) { p->throttled = false; return; } @@ -11029,7 +11035,14 @@ alb_break_llc(struct lb_env *env) return true; cur = rcu_dereference_all(env->src_rq->curr); - if (cur && cur->sched_class == &fair_sched_class) + /* + * Active balance only detaches CFS tasks, so a non-fair + * curr is never migrated. Ignore it and avoid using its + * state util in the misfit and LLC checks. + */ + if (cur && cur->sched_class != &fair_sched_class) + cur = NULL; + if (cur) util = task_util(cur); if (task_misfits_asym_cpu(env, cur) || diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index 779eb58a42614e..d10d57b6b8ec7a 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -99,7 +99,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3) * d1 y^p + 1024 \Sum y^n + d3 y^0 (Step 2) * n=1 */ -static __always_inline u32 +static __always_inline u64 accumulate_sum(u64 delta, struct sched_avg *sa, unsigned long load, unsigned long runnable, int running) { diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 6c7c5633524a3b..220927453a8892 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -781,19 +781,20 @@ struct cfs_rq { /* scx_rq->flags, protected by the rq lock */ enum scx_rq_flags { /* - * Set while the core has the rq online, see rq_online_scx() and - * rq_offline_scx(). A hotplugged cpu starts scheduling before - * rq_online_scx(). ops.enqueue() and ops.dispatch() are called for the - * cpu only while it is set, see scx_rq_online() and - * scx_dispatch_sched(). + * Set right after the root's ops.cpu_online() when a cpu comes up and + * cleared when the cpu goes down, see handle_hotplug(). A hotplugged + * cpu starts scheduling before %SCX_RQ_ONLINE is set. ops.enqueue() and + * ops.dispatch() are called for the cpu only while the flag is set, see + * scx_rq_online() and scx_dispatch_sched(). */ SCX_RQ_ONLINE = 1 << 0, SCX_RQ_CAN_STOP_TICK = 1 << 1, /* * Set while the root considers the cpu online, from its * ops.cpu_online() until its ops.cpu_offline(). ecaps are delivered - * only while it is set. %SCX_RQ_ONLINE follows the core's rq state - * instead, which changes ahead of the root's view on both edges. + * only while it is set. %SCX_RQ_ONLINE can't gate them, as a cpu going + * down clears it before the ecaps loss is reported, see + * scx_offline_ecaps(). */ SCX_RQ_OPS_ONLINE = 1 << 2, SCX_RQ_CLK_VALID = 1 << 5, /* RQ clock is fresh and valid */ @@ -1534,6 +1535,25 @@ static inline raw_spinlock_t *__rq_lockp(struct rq *rq) return &rq->__lock; } +/* + * A CPU coming online is set in cpu_smt_mask() before + * sched_core_cpu_starting() links its rq->core to the core leader. + * Until then it does not share the core-wide lock, so it must not be + * touched as part of the core. + */ +static inline bool sched_core_sibling(struct rq *rq, struct rq *rq_i) +{ + return rq_i->core == rq->core; +} + +#define for_each_core_cpu(i, rq) \ + for_each_cpu(i, cpu_smt_mask(rq->cpu)) \ + if (sched_core_sibling(rq, cpu_rq(i))) + +#define for_each_core_cpu_wrap(i, rq) \ + for_each_cpu_wrap(i, cpu_smt_mask(rq->cpu), rq->cpu) \ + if (sched_core_sibling(rq, cpu_rq(i))) + extern bool cfs_prio_less(const struct task_struct *a, const struct task_struct *b, bool fi); @@ -3124,11 +3144,6 @@ static inline void __block_task(struct rq *rq, struct task_struct *p) if (p->sched_contributes_to_load) rq->nr_uninterruptible++; - if (p->in_iowait) { - atomic_inc(&rq->nr_iowait); - delayacct_blkio_start(); - } - ASSERT_EXCLUSIVE_WRITER(p->on_rq); /* @@ -4294,7 +4309,7 @@ extern void balance_callbacks(struct rq *rq, struct balance_callback *head); * Typically this must be called while holding task_rq_lock, since most/all * properties are serialized under those locks. There are currently two * exceptions to this rule in sched/ext which only hold rq->lock: scx_bypass() - * and rq_offline_scx(). + * and drain_offline_rq(). */ /* diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index 45a127deeadd97..0ec401af80d127 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -318,8 +318,8 @@ static inline void __setscheduler_dl_pi(int newprio, int policy, static int uclamp_validate(struct task_struct *p, const struct sched_attr *attr) { - int util_min = p->uclamp_req[UCLAMP_MIN].value; - int util_max = p->uclamp_req[UCLAMP_MAX].value; + unsigned int util_min = p->uclamp_req[UCLAMP_MIN].value; + unsigned int util_max = p->uclamp_req[UCLAMP_MAX].value; if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { util_min = attr->sched_util_min; @@ -628,7 +628,7 @@ int __sched_setscheduler(struct task_struct *p, * the entire root_domain to become SCHED_DEADLINE. We * will also fail if there's no bandwidth available. */ - if (!cpumask_subset(span, p->cpus_ptr) || + if (!cpumask_subset(span, &p->cpus_mask) || rq->rd->dl_bw.bw == 0) { retval = -EPERM; goto unlock; @@ -640,8 +640,10 @@ int __sched_setscheduler(struct task_struct *p, if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) { policy = oldpolicy = -1; task_rq_unlock(rq, p, &rf); - if (cpuset_locked) + if (cpuset_locked) { cpuset_unlock(); + cpuset_locked = false; + } goto recheck; } diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 919d0fb00bd9f2..9d3a1b8dd39349 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -3332,13 +3332,25 @@ int __init sched_init_domains(const struct cpumask *cpu_map) static void detach_destroy_domains(const struct cpumask *cpu_map) { unsigned int cpu = cpumask_any(cpu_map); + bool has_cluster = false; int i; if (rcu_access_pointer(per_cpu(sd_asym_cpucapacity, cpu))) static_branch_dec_cpuslocked(&sched_asym_cpucapacity); - if (static_branch_unlikely(&sched_cluster_active)) - static_branch_dec_cpuslocked(&sched_cluster_active); + if (static_branch_unlikely(&sched_cluster_active)) { + rcu_read_lock(); + for_each_cpu(i, cpu_map) { + if (lowest_flag_domain(i, SD_CLUSTER)) { + has_cluster = true; + break; + } + } + rcu_read_unlock(); + + if (has_cluster) + static_branch_dec_cpuslocked(&sched_cluster_active); + } rcu_read_lock(); for_each_cpu(i, cpu_map) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dcf47f1ffdcf79..be72cfd2b1ca0d 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1600,6 +1600,9 @@ int get_device_system_crosststamp(int (*get_time_fn) do { seq = read_seqcount_begin(&tkd->seq); + if (!tk->clock_valid) + return -ENODEV; + /* * Try to synchronously capture device time and a system * counter value calling back into the device driver @@ -1775,6 +1778,7 @@ static int __timekeeping_inject_offset(struct tk_data *tkd, const struct timespe struct tk_read_base *tkr_mono = &tks->tkr_mono; ktime_t now, offs; + tk_update_ktime_data(tks); /* Get the current time */ now = ktime_add_ns(tkr_mono->base, timekeeping_get_ns(tkr_mono)); /* Add the relative offset change */ @@ -2700,7 +2704,13 @@ void update_wall_time(void) void getboottime64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; - ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot); + unsigned int seq; + ktime_t t; + + do { + seq = read_seqcount_begin(&tk_core.seq); + t = ktime_sub(tk->offs_real, tk->offs_boot); + } while (read_seqcount_retry(&tk_core.seq, seq)); *ts = ktime_to_timespec64(t); } diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 2aec56d7f3d3ef..d22e78e7f28da7 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2064,7 +2064,7 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info) ids_len = query.ids_len; if (ids_len > BPF_TRACE_MAX_PROGS) return -E2BIG; - ids = kcalloc(ids_len, sizeof(u32), GFP_USER | __GFP_NOWARN); + ids = kzalloc_objs(u32, ids_len, GFP_USER | __GFP_NOWARN); if (!ids) return -ENOMEM; /* @@ -2403,7 +2403,7 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 if (!access_ok(usyms, cnt * sizeof(*usyms))) return -EFAULT; - syms = kvmalloc_array(cnt, sizeof(*syms), GFP_KERNEL); + syms = kvmalloc_objs(*syms, cnt); if (!syms) return -ENOMEM; @@ -2847,7 +2847,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return -E2BIG; size = cnt * sizeof(*addrs); - addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); + addrs = kvmalloc_objs(*addrs, cnt); if (!addrs) return -ENOMEM; diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index ed455b53513bee..6d87143b3ddb5f 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1235,8 +1235,8 @@ static int start_graph_tracing(void) unsigned long **ret_stack_list; int ret, cpu; - ret_stack_list = kcalloc(FTRACE_RETSTACK_ALLOC_SIZE, - sizeof(*ret_stack_list), GFP_KERNEL); + ret_stack_list = kzalloc_objs(*ret_stack_list, + FTRACE_RETSTACK_ALLOC_SIZE); if (!ret_stack_list) return -ENOMEM; diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index da286619c5d898..47d565a1e2c56e 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -745,7 +745,7 @@ static int fprobe_module_callback(struct notifier_block *nb, if (val != MODULE_STATE_GOING) return NOTIFY_DONE; - alist.addrs = kcalloc(alist.size, sizeof(*alist.addrs), GFP_KERNEL); + alist.addrs = kzalloc_objs(*alist.addrs, alist.size); /* * If failed to alloc memory, ftrace_ops will not be able to remove ips from * hash, but we can still remove nodes from fprobe_ip_table, so we can avoid @@ -815,7 +815,7 @@ static unsigned long *get_ftrace_locations(const char **syms, int num) unsigned long *addrs; /* Convert symbols to symbol address */ - addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL); + addrs = kzalloc_objs(*addrs, num); if (!addrs) return ERR_PTR(-ENOMEM); @@ -1082,7 +1082,7 @@ static int unregister_fprobe_nolock(struct fprobe *fp) unsigned long *addrs = NULL; int i, count; - addrs = kcalloc(hlist_array->size, sizeof(unsigned long), GFP_KERNEL); + addrs = kzalloc_objs(unsigned long, hlist_array->size); /* * This will remove fprobe_hash_node from the hash table even if * memory allocation fails. However, ftrace_ops will not be updated. diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 1fd28a72e6ee13..75cd8df23c1b9c 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -7866,7 +7866,7 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu, return err; /* subbuf_ids includes the reader while nr_pages does not */ - subbuf_ids = kcalloc(cpu_buffer->nr_pages + 1, sizeof(*subbuf_ids), GFP_KERNEL); + subbuf_ids = kzalloc_objs(*subbuf_ids, cpu_buffer->nr_pages + 1); if (!subbuf_ids) { rb_free_meta_page(cpu_buffer); return -ENOMEM; diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index e8c4efa8107bf1..4ccdefb5c3efe5 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1281,7 +1281,7 @@ static int save_selftest(struct tracer *type) { struct trace_selftests *selftest; - selftest = kmalloc(sizeof(*selftest), GFP_KERNEL); + selftest = kmalloc_obj(*selftest); if (!selftest) return -ENOMEM; diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 998e6390937af6..f65393fb1c1029 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -94,14 +94,18 @@ static int eprobe_dyn_event_show(struct seq_file *m, struct dyn_event *ev) static int unregister_trace_eprobe(struct trace_eprobe *ep) { - /* If other probes are on the event, just unregister eprobe */ - if (trace_probe_has_sibling(&ep->tp)) - goto unreg; - /* Enabled event can not be unregistered */ if (trace_probe_is_enabled(&ep->tp)) return -EBUSY; + /* If there's a reference to the dynamic event */ + if (trace_event_dyn_busy(trace_probe_event_call(&ep->tp))) + return -EBUSY; + + /* If other probes are on the event, just unregister eprobe */ + if (trace_probe_has_sibling(&ep->tp)) + goto unreg; + /* Will fail if probe is being used by ftrace or perf */ if (trace_probe_unregister_event_call(&ep->tp)) return -EBUSY; @@ -330,21 +334,21 @@ get_event_field(struct fetch_insn *code, void *rec) switch (field->size) { case 1: if (field->is_signed) - val = *(char *)addr; + val = *(s8 *)addr; else - val = *(unsigned char *)addr; + val = *(u8 *)addr; break; case 2: if (field->is_signed) - val = *(short *)addr; + val = *(s16 *)addr; else - val = *(unsigned short *)addr; + val = *(u16 *)addr; break; case 4: if (field->is_signed) - val = *(int *)addr; + val = *(s32 *)addr; else - val = *(unsigned int *)addr; + val = *(u32 *)addr; break; default: if (field->size == sizeof(long)) { @@ -644,37 +648,32 @@ static int enable_trace_eprobe(struct trace_event_call *call, { struct trace_probe *tp; struct trace_eprobe *ep; - bool enabled; int ret = 0; int cnt = 0; + if (WARN_ON_ONCE(!file)) + return -EINVAL; + tp = trace_probe_primary_from_call(call); if (WARN_ON_ONCE(!tp)) return -ENODEV; - enabled = trace_probe_is_enabled(tp); /* This also changes "enabled" state */ - if (file) { - ret = trace_probe_add_file(tp, file); - if (ret) - return ret; - } else - trace_probe_set_flag(tp, TP_FLAG_PROFILE); - - if (enabled) - return 0; + ret = trace_probe_add_file(tp, file); + if (ret) + return ret; + /* The trigger lives in the instance of the file, add it for each file */ for_each_trace_eprobe_tp(ep, tp) { ret = enable_eprobe(ep, file); if (ret) break; - enabled = true; cnt++; } if (ret) { /* Failed to enable one of them. Roll back all */ - if (enabled) { + if (cnt) { /* * It's a bug if one failed for something other than memory * not being available but another eprobe succeeded. @@ -687,10 +686,7 @@ static int enable_trace_eprobe(struct trace_event_call *call, break; } } - if (file) - trace_probe_remove_file(tp, file); - else - trace_probe_clear_flag(tp, TP_FLAG_PROFILE); + trace_probe_remove_file(tp, file); } return ret; @@ -702,33 +698,21 @@ static int disable_trace_eprobe(struct trace_event_call *call, struct trace_probe *tp; struct trace_eprobe *ep; + if (WARN_ON_ONCE(!file)) + return -EINVAL; + tp = trace_probe_primary_from_call(call); if (WARN_ON_ONCE(!tp)) return -ENODEV; - if (file) { - if (!trace_probe_get_file_link(tp, file)) - return -ENOENT; - if (!trace_probe_has_single_file(tp)) - goto out; - trace_probe_clear_flag(tp, TP_FLAG_TRACE); - } else - trace_probe_clear_flag(tp, TP_FLAG_PROFILE); + if (!trace_probe_get_file_link(tp, file)) + return -ENOENT; - if (!trace_probe_is_enabled(tp)) { - for_each_trace_eprobe_tp(ep, tp) - disable_eprobe(ep, file->tr); - } + for_each_trace_eprobe_tp(ep, tp) + disable_eprobe(ep, file->tr); - out: - if (file) - /* - * Synchronization is done in below function. For perf event, - * file == NULL and perf_trace_event_unreg() calls - * tracepoint_synchronize_unregister() to ensure synchronize - * event. We don't need to care about it. - */ - trace_probe_remove_file(tp, file); + /* Synchronization is done in below function. */ + trace_probe_remove_file(tp, file); return 0; } @@ -778,7 +762,8 @@ find_and_get_event(const char *system, const char *event_name) (TRACE_EVENT_FL_IGNORE_ENABLE | TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE | - TRACE_EVENT_FL_EPROBE)) + TRACE_EVENT_FL_EPROBE | + TRACE_EVENT_FL_FPROBE)) continue; if (!tp_event->class->system || strcmp(system, tp_event->class->system)) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 5b272856e5ab19..a549897ee408f4 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -354,8 +354,7 @@ int perf_trace_add(struct perf_event *p_event, int flags) struct trace_event_call *tp_event = p_event->tp_event; struct hw_perf_event *hwc = &p_event->hw; - if (!(flags & PERF_EF_START)) - p_event->hw.state = PERF_HES_STOPPED; + hwc->state = (flags & PERF_EF_START) ? 0 : PERF_HES_STOPPED; if (is_sampling_event(p_event)) { hwc->last_period = hwc->sample_period; diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 4e9034ebc3fbdc..9ab0871a64619c 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -853,10 +853,6 @@ static void __unregister_trace_fprobe(struct trace_fprobe *tf) /* Unregister a trace_probe and probe_event */ static int unregister_trace_fprobe(struct trace_fprobe *tf) { - /* If other probes are on the event, just unregister fprobe */ - if (trace_probe_has_sibling(&tf->tp)) - goto unreg; - /* Enabled event can not be unregistered */ if (trace_probe_is_enabled(&tf->tp)) return -EBUSY; @@ -865,6 +861,10 @@ static int unregister_trace_fprobe(struct trace_fprobe *tf) if (trace_event_dyn_busy(trace_probe_event_call(&tf->tp))) return -EBUSY; + /* If other probes are on the event, just unregister fprobe */ + if (trace_probe_has_sibling(&tf->tp)) + goto unreg; + /* Will fail if probe is being used by ftrace or perf */ if (unregister_fprobe_event(tf)) return -EBUSY; @@ -933,7 +933,10 @@ static int append_trace_fprobe_event(struct trace_fprobe *tf, struct trace_fprob if (ret) return ret; - ret = trace_fprobe_verify_target(tf); + if (trace_probe_is_enabled(&tf->tp)) + ret = __register_trace_fprobe(tf); + else + ret = trace_fprobe_verify_target(tf); if (ret) trace_probe_unlink(&tf->tp); else @@ -1520,13 +1523,8 @@ static int disable_trace_fprobe(struct trace_event_call *call, trace_probe_clear_flag(tp, TP_FLAG_PROFILE); if (!trace_probe_is_enabled(tp)) { - list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) { - unregister_fprobe(&tf->fp); - if (tf->tuser) { - tracepoint_user_put(tf->tuser); - tf->tuser = NULL; - } - } + list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) + __unregister_trace_fprobe(tf); } out: diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index e41a7c113646ba..1dd6a6942eb7da 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -548,10 +548,6 @@ static void __unregister_trace_kprobe(struct trace_kprobe *tk) /* Unregister a trace_probe and probe_event */ static int unregister_trace_kprobe(struct trace_kprobe *tk) { - /* If other probes are on the event, just unregister kprobe */ - if (trace_probe_has_sibling(&tk->tp)) - goto unreg; - /* Enabled event can not be unregistered */ if (trace_probe_is_enabled(&tk->tp)) return -EBUSY; @@ -560,6 +556,10 @@ static int unregister_trace_kprobe(struct trace_kprobe *tk) if (trace_event_dyn_busy(trace_probe_event_call(&tk->tp))) return -EBUSY; + /* If other probes are on the event, just unregister kprobe */ + if (trace_probe_has_sibling(&tk->tp)) + goto unreg; + /* Will fail if probe is being used by ftrace or perf */ if (unregister_kprobe_event(tk)) return -EBUSY; @@ -2017,6 +2017,9 @@ static __init void setup_boot_kprobe_events(void) char *p, *cmd = kprobe_boot_events_buf; int ret; + if (!kprobe_boot_events_buf[0]) + return; + strreplace(kprobe_boot_events_buf, ',', ' '); while (cmd && *cmd != '\0') { diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index a880a90642d7c4..cff55dcae36f2f 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -411,6 +411,9 @@ static bool btf_type_is_char_ptr(struct btf *btf, const struct btf_type *type) const struct btf_type *real_type; u32 intdata; + if (BTF_INFO_KIND(type->info) != BTF_KIND_PTR) + return false; + real_type = btf_type_skip_modifiers(btf, type->type, NULL); if (!real_type) return false; @@ -435,6 +438,11 @@ static bool btf_type_is_char_array(struct btf *btf, const struct btf_type *type) array = (const struct btf_array *)(type + 1); real_type = btf_type_skip_modifiers(btf, array->type, NULL); + if (!real_type) + return false; + + if (BTF_INFO_KIND(real_type->info) != BTF_KIND_INT) + return false; intdata = btf_type_int(real_type); return !(BTF_INT_ENCODING(intdata) & BTF_INT_SIGNED) @@ -486,6 +494,18 @@ static const char *fetch_type_from_btf_type(struct btf *btf, { u32 intdata; + if (ctx->last_bitsize) { + u32 bits = ctx->last_bitsize + ctx->last_bitoffs; + + if (bits <= 8) + return "u8"; + if (bits <= 16) + return "u16"; + if (bits <= 32) + return "u32"; + return "u64"; + } + /* TODO: const char * could be converted as a string */ switch (BTF_INFO_KIND(type->info)) { case BTF_KIND_ENUM: @@ -520,10 +540,6 @@ static const char *fetch_type_from_btf_type(struct btf *btf, case 64: return "u64"; } - /* bitfield, size is encoded in the type */ - ctx->last_bitsize = BTF_INT_BITS(intdata); - ctx->last_bitoffs += BTF_INT_OFFSET(intdata); - return "u64"; } } /* TODO: support other types */ @@ -653,6 +669,12 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty /* Add anonymous structure/union offset */ bitoffs += anon_offs; + type = btf_type_skip_modifiers(btf, field->type, NULL); + if (!type) { + trace_probe_log_err(ctx->offset, BAD_BTF_TID); + return -EINVAL; + } + /* Accumulate the bit-offsets of the dot-connected fields */ if (btf_type_kflag(container_type)) { bitoffs += BTF_MEMBER_BIT_OFFSET(field->offset); @@ -660,12 +682,15 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty } else { bitoffs += field->offset; ctx->last_bitsize = 0; - } - - type = btf_type_skip_modifiers(btf, field->type, NULL); - if (!type) { - trace_probe_log_err(ctx->offset, BAD_BTF_TID); - return -EINVAL; + if (BTF_INFO_KIND(type->info) == BTF_KIND_INT) { + u32 intdata = btf_type_int(type); + + bitoffs += BTF_INT_OFFSET(intdata); + if ((bitoffs % 8) || + BTF_INT_BITS(intdata) != BYTES_TO_BITS(type->size) || + !is_power_of_2(type->size)) + ctx->last_bitsize = BTF_INT_BITS(intdata); + } } if (next) @@ -858,13 +883,22 @@ static const struct fetch_type *find_fetch_type_from_btf_type( } static int parse_btf_bitfield(struct fetch_insn **pcode, + const struct fetch_type *t, struct traceprobe_parse_context *ctx) { struct fetch_insn *code = *pcode; - if ((ctx->last_bitsize % 8 == 0) && ctx->last_bitoffs == 0) + if ((ctx->last_bitsize == 0 || + ctx->last_bitsize == BYTES_TO_BITS(t->size)) && + ctx->last_bitoffs == 0) return 0; + if (ctx->last_bitsize == 0 || + BYTES_TO_BITS(t->size) < (ctx->last_bitsize + ctx->last_bitoffs)) { + trace_probe_log_err(ctx->offset, BAD_BITFIELD); + return -EINVAL; + } + code++; if (code->op != FETCH_OP_NOP) { trace_probe_log_err(ctx->offset, TOO_MANY_OPS); @@ -873,9 +907,13 @@ static int parse_btf_bitfield(struct fetch_insn **pcode, *pcode = code; code->op = FETCH_OP_MOD_BF; - code->lshift = 64 - (ctx->last_bitsize + ctx->last_bitoffs); - code->rshift = 64 - ctx->last_bitsize; - code->basesize = 64 / 8; +#ifdef __BIG_ENDIAN_BITFIELD + code->lshift = ctx->last_bitoffs; +#else + code->lshift = BYTES_TO_BITS(t->size) - (ctx->last_bitsize + ctx->last_bitoffs); +#endif + code->rshift = BYTES_TO_BITS(t->size) - ctx->last_bitsize; + code->basesize = t->size; return 0; } @@ -1085,6 +1123,7 @@ static int parse_btf_arg(char *varname, } static int parse_btf_bitfield(struct fetch_insn **pcode, + const struct fetch_type *t, struct traceprobe_parse_context *ctx) { trace_probe_log_err(ctx->offset, NOSUP_BTFARG); @@ -1917,6 +1956,8 @@ static int finalize_fetch_insn(struct fetch_insn *code, /* Store operation */ if (parg->type->is_string) { + bool is_uderef; + /* Check bad combination of the type and the last fetch_insn. */ if (!strcmp(parg->type->name, "symstr")) { if (code->op != FETCH_OP_REG && code->op != FETCH_OP_STACK && @@ -1936,6 +1977,7 @@ static int finalize_fetch_insn(struct fetch_insn *code, } } + is_uderef = (code->op == FETCH_OP_UDEREF); if (!strcmp(parg->type->name, "symstr") || (code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM || code->op == FETCH_OP_IMMSTR) || code->op == FETCH_OP_TP_ARG || @@ -1948,6 +1990,12 @@ static int finalize_fetch_insn(struct fetch_insn *code, * For the symstr, it doesn't need to dereference, thus * it just get the value. */ + if (parg->count && (code->op != FETCH_OP_DEREF && + code->op != FETCH_OP_UDEREF)) { + trace_probe_log_err(ctx->offset + type_offset, + BAD_STRING); + return -EINVAL; + } code++; if (code->op != FETCH_OP_NOP) { trace_probe_log_err(ctx->offset, TOO_MANY_OPS); @@ -1956,8 +2004,7 @@ static int finalize_fetch_insn(struct fetch_insn *code, } /* If op == DEREF, replace it with STRING */ - if (!strcmp(parg->type->name, "ustring") || - code->op == FETCH_OP_UDEREF) + if (!strcmp(parg->type->name, "ustring") || is_uderef) code->op = FETCH_OP_ST_USTRING; else if (!strcmp(parg->type->name, "symstr")) code->op = FETCH_OP_ST_SYMSTR; @@ -1995,7 +2042,7 @@ static int finalize_fetch_insn(struct fetch_insn *code, } else if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && ctx->last_type) { /* If user not specified the type, try parsing BTF bitfield. */ - ret = parse_btf_bitfield(&code, ctx); + ret = parse_btf_bitfield(&code, parg->type, ctx); if (ret) return ret; } @@ -2315,7 +2362,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], else *new_argc = argc; - new_argv = kcalloc(*new_argc, sizeof(*new_argv), GFP_KERNEL); + new_argv = kzalloc_objs(*new_argv, *new_argc); if (!new_argv) return ERR_PTR(-ENOMEM); diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 8db12f758fdae2..8acc0f0ebd7a6b 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -87,15 +87,27 @@ fetch_store_symstrlen(unsigned long addr) static nokprobe_inline int fetch_store_symstring(unsigned long addr, void *dest, void *base) { + char namebuf[KSYM_SYMBOL_LEN]; int maxlen = get_loc_len(*(u32 *)dest); void *__dest; + int len; if (unlikely(!maxlen)) return -ENOMEM; __dest = get_loc_data(dest, base); + len = sprint_symbol(namebuf, addr); + if (len < 0) { + *(u32 *)dest = make_data_loc(0, __dest - base); + return 0; + } + + len = min(len, maxlen - 1); + memcpy(__dest, namebuf, len); + ((char *)__dest)[len] = '\0'; + *(u32 *)dest = make_data_loc(len + 1, __dest - base); - return sprint_symbol(__dest, addr); + return len + 1; } /* common part of process_fetch_insn*/ diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 22cc3c8181b86b..fb7991543db7d1 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -396,13 +396,17 @@ static int unregister_trace_uprobe(struct trace_uprobe *tu) { int ret; - if (trace_probe_has_sibling(&tu->tp)) - goto unreg; + /* Enabled event can not be unregistered */ + if (trace_probe_is_enabled(&tu->tp)) + return -EBUSY; /* If there's a reference to the dynamic event */ if (trace_event_dyn_busy(trace_probe_event_call(&tu->tp))) return -EBUSY; + if (trace_probe_has_sibling(&tu->tp)) + goto unreg; + ret = unregister_uprobe_event(tu); if (ret) return ret; @@ -443,6 +447,28 @@ static bool trace_uprobe_has_same_uprobe(struct trace_uprobe *orig, return false; } +typedef bool (*filter_func_t)(struct uprobe_consumer *self, struct mm_struct *mm); + +#ifdef CONFIG_PERF_EVENTS +static bool uprobe_perf_filter(struct uprobe_consumer *uc, struct mm_struct *mm); +#else +#define uprobe_perf_filter NULL +#endif + +static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter) +{ + struct inode *inode = d_real_inode(tu->path.dentry); + struct uprobe *uprobe; + + tu->consumer.filter = filter; + uprobe = uprobe_register(inode, tu->offset, tu->ref_ctr_offset, &tu->consumer); + if (IS_ERR(uprobe)) + return PTR_ERR(uprobe); + + tu->uprobe = uprobe; + return 0; +} + static int append_trace_uprobe(struct trace_uprobe *tu, struct trace_uprobe *to) { int ret; @@ -462,10 +488,22 @@ static int append_trace_uprobe(struct trace_uprobe *tu, struct trace_uprobe *to) /* Append to existing event */ ret = trace_probe_append(&tu->tp, &to->tp); - if (!ret) - dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp)); + if (ret) + return ret; - return ret; + if (trace_probe_is_enabled(&tu->tp)) { + ret = trace_uprobe_enable(tu, + trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE) ? + uprobe_perf_filter : NULL); + if (ret) { + trace_probe_unlink(&tu->tp); + return ret; + } + } + + dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp)); + + return 0; } /* @@ -663,7 +701,7 @@ static int __trace_uprobe_create(int argc, const char **argv) } if (!event) { - char *tail; + char *tail __free(kfree) = NULL; char *ptr; tail = kstrdup(kbasename(filename), GFP_KERNEL); @@ -679,7 +717,6 @@ static int __trace_uprobe_create(int argc, const char **argv) return -ENOMEM; snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset); event = buf; - kfree(tail); } argc -= 2; @@ -1101,22 +1138,6 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e return trace_handle_return(s); } -typedef bool (*filter_func_t)(struct uprobe_consumer *self, struct mm_struct *mm); - -static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter) -{ - struct inode *inode = d_real_inode(tu->path.dentry); - struct uprobe *uprobe; - - tu->consumer.filter = filter; - uprobe = uprobe_register(inode, tu->offset, tu->ref_ctr_offset, &tu->consumer); - if (IS_ERR(uprobe)) - return PTR_ERR(uprobe); - - tu->uprobe = uprobe; - return 0; -} - static void __probe_event_disable(struct trace_probe *tp) { struct trace_uprobe *tu; diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 5c153106e64271..48320684c7c016 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -24,7 +24,7 @@ void bacct_add_tsk(struct user_namespace *user_ns, const struct cred *tcred; u64 utime, stime, utimescaled, stimescaled; u64 now_ns, delta; - time64_t btime; + struct timespec64 btime; BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); @@ -39,9 +39,11 @@ void bacct_add_tsk(struct user_namespace *user_ns, do_div(delta, NSEC_PER_USEC); stats->ac_etime = delta; /* Convert to seconds for btime (note y2106 limit) */ - btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC); - stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); - stats->ac_btime64 = btime; + getboottime64(&btime); + btime = timespec64_add(btime, ns_to_timespec64(tsk->start_boottime)); + stats->ac_btime = clamp_t(time64_t, btime.tv_sec, 0, U32_MAX); + /* Setting the clock back after suspend can make btime negative. */ + stats->ac_btime64 = max_t(time64_t, btime.tv_sec, 0); if (tsk->flags & PF_EXITING) stats->ac_exitcode = tsk->exit_code; diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 453dcf613205ab..e2bdd5fb0db138 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -77,13 +77,9 @@ static void watch_queue_pipe_buf_release(struct pipe_inode_info *pipe, generic_pipe_buf_release(pipe, buf); } -// No try_steal function => no stealing -#define watch_queue_pipe_buf_try_steal NULL - /* New data written to a pipe may be appended to a buffer with this type. */ static const struct pipe_buf_operations watch_queue_pipe_buf_ops = { .release = watch_queue_pipe_buf_release, - .try_steal = watch_queue_pipe_buf_try_steal, .get = generic_pipe_buf_get, }; diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f2e8071a6f4eb0..af845214e78bfd 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5267,7 +5267,7 @@ static int alloc_flush_pnodes(struct workqueue_struct *wq) struct wq_flush_pnode *fpn; int node; - wq->flush_pnodes = kcalloc(nr_node_ids + 1, sizeof(*wq->flush_pnodes), GFP_KERNEL); + wq->flush_pnodes = kzalloc_objs(*wq->flush_pnodes, nr_node_ids + 1); if (!wq->flush_pnodes) return -ENOMEM; diff --git a/lib/argv_split.c b/lib/argv_split.c index e28db8e3b58c81..cf15892139e6ed 100644 --- a/lib/argv_split.c +++ b/lib/argv_split.c @@ -69,7 +69,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp) return NULL; argc = count_argc(argv_str); - argv = kmalloc_array(argc + 2, sizeof(*argv), gfp); + argv = kmalloc_objs(*argv, argc + 2, gfp); if (!argv) { kfree(argv_str); return NULL; diff --git a/lib/base64.c b/lib/base64.c index 325c7332b04928..e46be3a55585c2 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -52,11 +52,14 @@ static const char base64_tables[][65] = { INIT_32(0x60, ch_62, ch_63), \ [0x80 ... 0xff] = -1 } +__diag_push(); +__diag_ignore(clang, all, "-Wconstant-conversion", "https://github.com/llvm/llvm-project/issues/223923"); static const s8 base64_rev_maps[][256] = { [BASE64_STD] = BASE64_REV_INIT('+', '/'), [BASE64_URLSAFE] = BASE64_REV_INIT('-', '_'), [BASE64_IMAP] = BASE64_REV_INIT('+', ',') }; +__diag_pop(); #undef BASE64_REV_INIT #undef INIT_32 diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 819685d6c68db1..948c8c10e4b985 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -428,9 +428,9 @@ int __init xbc_node_compose_key_after(struct xbc_node *root, node = xbc_node_get_parent(node); while (node && node != root) { - keys[depth++] = xbc_node_index(node); if (depth == XBC_DEPTH_MAX) return -ERANGE; + keys[depth++] = xbc_node_index(node); node = xbc_node_get_parent(node); } if (!node && root) @@ -793,16 +793,17 @@ static int __init __xbc_parse_value(char **__v, char **__n) return xbc_parse_error("No value delimiter", p); if (*p) p++; - break; + goto skip_trim; } if (strchr(",;\n#}", c)) { *p++ = '\0'; - v = strim(v); break; } } if (quotes) return xbc_parse_error("No closing quotes", p); + v = strim(v); +skip_trim: if (c == '#') { p = skip_comment(p); c = '\n'; /* A comment must be treated as a newline */ diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 56f308dd027311..4644dee78ae3dc 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -197,8 +197,6 @@ config CRYPTO_LIB_POLY1305_ARCH default y if ARM default y if ARM64 default y if MIPS - # The PPC64 code needs to be fixed to work in softirq context. - default y if PPC64 && CPU_LITTLE_ENDIAN && VSX && BROKEN default y if RISCV default y if X86_64 @@ -209,9 +207,7 @@ config CRYPTO_LIB_POLY1305_ARCH config CRYPTO_LIB_POLY1305_GENERIC bool depends on CRYPTO_LIB_POLY1305 - # Enable if there's no arch impl or the arch impl requires the generic - # impl as a fallback. (Or if selected explicitly.) - default y if !CRYPTO_LIB_POLY1305_ARCH || PPC64 + default y if !CRYPTO_LIB_POLY1305_ARCH config CRYPTO_LIB_POLY1305_RSIZE int @@ -237,7 +233,7 @@ config CRYPTO_LIB_SHA1_ARCH depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC default y if S390 default y if SPARC64 @@ -255,7 +251,7 @@ config CRYPTO_LIB_SHA256_ARCH depends on CRYPTO_LIB_SHA256 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC && SPE default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS @@ -275,7 +271,7 @@ config CRYPTO_LIB_SHA512_ARCH depends on CRYPTO_LIB_SHA512 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS default y if S390 diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 832d170cab941a..126e72419ebbfb 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -256,8 +256,6 @@ $(obj)/mips/poly1305-core.S: $(src)/mips/poly1305-mips.pl FORCE targets += mips/poly1305-core.S endif -libpoly1305-$(CONFIG_PPC) += powerpc/poly1305-p10le_64.o - ifeq ($(CONFIG_RISCV),y) libpoly1305-y += riscv/poly1305-core.o poly1305-perlasm-flavour-$(CONFIG_32BIT) := 32 diff --git a/lib/crypto/mldsa.c b/lib/crypto/mldsa.c index c96fddc4e7dcf9..80e0e63b418a7b 100644 --- a/lib/crypto/mldsa.c +++ b/lib/crypto/mldsa.c @@ -306,7 +306,7 @@ static const u8 *decode_t1_elem(struct mldsa_ring_elem *out, * Reference: FIPS 204 Algorithm 27, sigDecode. * * This also validates that the coefficients of z are in range, corresponding - * the infinity norm check at the end of Algorithm 8, ML-DSA.Verify_internal. + * to the infinity norm check at the end of Algorithm 8, ML-DSA.Verify_internal. * * Finally, this also converts z to NTT form. */ @@ -528,15 +528,21 @@ static size_t encode_w1(u8 out[MAX_W1_ENCODED_LEN], int mldsa_verify(enum mldsa_alg alg, const u8 *sig, size_t sig_len, const u8 *msg, size_t msg_len, const u8 *pk, size_t pk_len) { - const struct mldsa_parameter_set *params = &mldsa_parameter_sets[alg]; - const int k = params->k, l = params->l; + const struct mldsa_parameter_set *params; + int k, l; /* For now this just does pure ML-DSA with an empty context string. */ static const u8 msg_prefix[2] = { /* dom_sep= */ 0, /* ctx_len= */ 0 }; const u8 *ctilde; /* The signer's commitment hash */ - const u8 *t1_encoded = &pk[RHO_LEN]; /* Next encoded element of t_1 */ + const u8 *t1_encoded; /* Next encoded element of t_1 */ u8 *h; /* The signer's hint vector, length k * N */ size_t w1_enc_len; + if (alg != MLDSA44 && alg != MLDSA65 && alg != MLDSA87) + return -EINVAL; + params = &mldsa_parameter_sets[alg]; + k = params->k; + l = params->l; + /* Validate the public key and signature lengths. */ if (pk_len != params->pk_len || sig_len != params->sig_len) return -EBADMSG; @@ -587,6 +593,7 @@ int mldsa_verify(enum mldsa_alg alg, const u8 *sig, size_t sig_len, * The computation is the same for each of the k rows. Just do each row * before moving on to the next, resulting in only one loop over k. */ + t1_encoded = &pk[RHO_LEN]; for (int i = 0; i < k; i++) { /* * tmp = NTT(A) * NTT(z) * 2^-32 diff --git a/lib/crypto/powerpc/poly1305-p10le_64.S b/lib/crypto/powerpc/poly1305-p10le_64.S deleted file mode 100644 index ffd5b4aa0a5b97..00000000000000 --- a/lib/crypto/powerpc/poly1305-p10le_64.S +++ /dev/null @@ -1,1076 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -# -# Accelerated poly1305 implementation for ppc64le. -# -# Copyright 2023- IBM Corp. All rights reserved -# -#=================================================================================== -# Written by Danny Tsen -# -# Poly1305 - this version mainly using vector/VSX/Scalar -# - 26 bits limbs -# - Handle multiple 64 byte blcok. -# -# Block size 16 bytes -# key = (r, s) -# clamp r &= 0x0FFFFFFC0FFFFFFC 0x0FFFFFFC0FFFFFFF -# p = 2^130 - 5 -# a += m -# a = (r + a) % p -# a += s -# -# Improve performance by breaking down polynominal to the sum of products with -# h4 = m1 * r⁴ + m2 * r³ + m3 * r² + m4 * r -# -# 07/22/21 - this revison based on the above sum of products. Setup r^4, r^3, r^2, r and s3, s2, s1, s0 -# to 9 vectors for multiplications. -# -# setup r^4, r^3, r^2, r vectors -# vs [r^1, r^3, r^2, r^4] -# vs0 = [r0,.....] -# vs1 = [r1,.....] -# vs2 = [r2,.....] -# vs3 = [r3,.....] -# vs4 = [r4,.....] -# vs5 = [r1*5,...] -# vs6 = [r2*5,...] -# vs7 = [r2*5,...] -# vs8 = [r4*5,...] -# -# Each word in a vector consists a member of a "r/s" in [a * r/s]. -# -# r0, r4*5, r3*5, r2*5, r1*5; -# r1, r0, r4*5, r3*5, r2*5; -# r2, r1, r0, r4*5, r3*5; -# r3, r2, r1, r0, r4*5; -# r4, r3, r2, r1, r0 ; -# -# -# void poly1305_p10le_4blocks(struct poly1305_block_state *state, const u8 *m, -# size_t mlen); -# r3 = state -# r4 = m -# r5 = mlen -# -#include -#include -#include -#include - -.machine "any" - -.text - -.macro SAVE_GPR GPR OFFSET FRAME - std \GPR,\OFFSET(\FRAME) -.endm - -.macro SAVE_VRS VRS OFFSET FRAME - li 16, \OFFSET - stvx \VRS, 16, \FRAME -.endm - -.macro SAVE_VSX VSX OFFSET FRAME - li 16, \OFFSET - stxvx \VSX, 16, \FRAME -.endm - -.macro RESTORE_GPR GPR OFFSET FRAME - ld \GPR,\OFFSET(\FRAME) -.endm - -.macro RESTORE_VRS VRS OFFSET FRAME - li 16, \OFFSET - lvx \VRS, 16, \FRAME -.endm - -.macro RESTORE_VSX VSX OFFSET FRAME - li 16, \OFFSET - lxvx \VSX, 16, \FRAME -.endm - -.macro SAVE_REGS - mflr 0 - std 0, 16(1) - stdu 1,-752(1) - - SAVE_GPR 14, 112, 1 - SAVE_GPR 15, 120, 1 - SAVE_GPR 16, 128, 1 - SAVE_GPR 17, 136, 1 - SAVE_GPR 18, 144, 1 - SAVE_GPR 19, 152, 1 - SAVE_GPR 20, 160, 1 - SAVE_GPR 21, 168, 1 - SAVE_GPR 22, 176, 1 - SAVE_GPR 23, 184, 1 - SAVE_GPR 24, 192, 1 - SAVE_GPR 25, 200, 1 - SAVE_GPR 26, 208, 1 - SAVE_GPR 27, 216, 1 - SAVE_GPR 28, 224, 1 - SAVE_GPR 29, 232, 1 - SAVE_GPR 30, 240, 1 - SAVE_GPR 31, 248, 1 - - addi 9, 1, 256 - SAVE_VRS 20, 0, 9 - SAVE_VRS 21, 16, 9 - SAVE_VRS 22, 32, 9 - SAVE_VRS 23, 48, 9 - SAVE_VRS 24, 64, 9 - SAVE_VRS 25, 80, 9 - SAVE_VRS 26, 96, 9 - SAVE_VRS 27, 112, 9 - SAVE_VRS 28, 128, 9 - SAVE_VRS 29, 144, 9 - SAVE_VRS 30, 160, 9 - SAVE_VRS 31, 176, 9 - - SAVE_VSX 14, 192, 9 - SAVE_VSX 15, 208, 9 - SAVE_VSX 16, 224, 9 - SAVE_VSX 17, 240, 9 - SAVE_VSX 18, 256, 9 - SAVE_VSX 19, 272, 9 - SAVE_VSX 20, 288, 9 - SAVE_VSX 21, 304, 9 - SAVE_VSX 22, 320, 9 - SAVE_VSX 23, 336, 9 - SAVE_VSX 24, 352, 9 - SAVE_VSX 25, 368, 9 - SAVE_VSX 26, 384, 9 - SAVE_VSX 27, 400, 9 - SAVE_VSX 28, 416, 9 - SAVE_VSX 29, 432, 9 - SAVE_VSX 30, 448, 9 - SAVE_VSX 31, 464, 9 -.endm # SAVE_REGS - -.macro RESTORE_REGS - addi 9, 1, 256 - RESTORE_VRS 20, 0, 9 - RESTORE_VRS 21, 16, 9 - RESTORE_VRS 22, 32, 9 - RESTORE_VRS 23, 48, 9 - RESTORE_VRS 24, 64, 9 - RESTORE_VRS 25, 80, 9 - RESTORE_VRS 26, 96, 9 - RESTORE_VRS 27, 112, 9 - RESTORE_VRS 28, 128, 9 - RESTORE_VRS 29, 144, 9 - RESTORE_VRS 30, 160, 9 - RESTORE_VRS 31, 176, 9 - - RESTORE_VSX 14, 192, 9 - RESTORE_VSX 15, 208, 9 - RESTORE_VSX 16, 224, 9 - RESTORE_VSX 17, 240, 9 - RESTORE_VSX 18, 256, 9 - RESTORE_VSX 19, 272, 9 - RESTORE_VSX 20, 288, 9 - RESTORE_VSX 21, 304, 9 - RESTORE_VSX 22, 320, 9 - RESTORE_VSX 23, 336, 9 - RESTORE_VSX 24, 352, 9 - RESTORE_VSX 25, 368, 9 - RESTORE_VSX 26, 384, 9 - RESTORE_VSX 27, 400, 9 - RESTORE_VSX 28, 416, 9 - RESTORE_VSX 29, 432, 9 - RESTORE_VSX 30, 448, 9 - RESTORE_VSX 31, 464, 9 - - RESTORE_GPR 14, 112, 1 - RESTORE_GPR 15, 120, 1 - RESTORE_GPR 16, 128, 1 - RESTORE_GPR 17, 136, 1 - RESTORE_GPR 18, 144, 1 - RESTORE_GPR 19, 152, 1 - RESTORE_GPR 20, 160, 1 - RESTORE_GPR 21, 168, 1 - RESTORE_GPR 22, 176, 1 - RESTORE_GPR 23, 184, 1 - RESTORE_GPR 24, 192, 1 - RESTORE_GPR 25, 200, 1 - RESTORE_GPR 26, 208, 1 - RESTORE_GPR 27, 216, 1 - RESTORE_GPR 28, 224, 1 - RESTORE_GPR 29, 232, 1 - RESTORE_GPR 30, 240, 1 - RESTORE_GPR 31, 248, 1 - - addi 1, 1, 752 - ld 0, 16(1) - mtlr 0 -.endm # RESTORE_REGS - -# -# p[0] = a0*r0 + a1*r4*5 + a2*r3*5 + a3*r2*5 + a4*r1*5; -# p[1] = a0*r1 + a1*r0 + a2*r4*5 + a3*r3*5 + a4*r2*5; -# p[2] = a0*r2 + a1*r1 + a2*r0 + a3*r4*5 + a4*r3*5; -# p[3] = a0*r3 + a1*r2 + a2*r1 + a3*r0 + a4*r4*5; -# p[4] = a0*r4 + a1*r3 + a2*r2 + a3*r1 + a4*r0 ; -# -# [r^2, r^3, r^1, r^4] -# [m3, m2, m4, m1] -# -# multiply odd and even words -.macro mul_odd - vmulouw 14, 4, 26 - vmulouw 10, 5, 3 - vmulouw 11, 6, 2 - vmulouw 12, 7, 1 - vmulouw 13, 8, 0 - vmulouw 15, 4, 27 - vaddudm 14, 14, 10 - vaddudm 14, 14, 11 - vmulouw 10, 5, 26 - vmulouw 11, 6, 3 - vaddudm 14, 14, 12 - vaddudm 14, 14, 13 # x0 - vaddudm 15, 15, 10 - vaddudm 15, 15, 11 - vmulouw 12, 7, 2 - vmulouw 13, 8, 1 - vaddudm 15, 15, 12 - vaddudm 15, 15, 13 # x1 - vmulouw 16, 4, 28 - vmulouw 10, 5, 27 - vmulouw 11, 6, 26 - vaddudm 16, 16, 10 - vaddudm 16, 16, 11 - vmulouw 12, 7, 3 - vmulouw 13, 8, 2 - vaddudm 16, 16, 12 - vaddudm 16, 16, 13 # x2 - vmulouw 17, 4, 29 - vmulouw 10, 5, 28 - vmulouw 11, 6, 27 - vaddudm 17, 17, 10 - vaddudm 17, 17, 11 - vmulouw 12, 7, 26 - vmulouw 13, 8, 3 - vaddudm 17, 17, 12 - vaddudm 17, 17, 13 # x3 - vmulouw 18, 4, 30 - vmulouw 10, 5, 29 - vmulouw 11, 6, 28 - vaddudm 18, 18, 10 - vaddudm 18, 18, 11 - vmulouw 12, 7, 27 - vmulouw 13, 8, 26 - vaddudm 18, 18, 12 - vaddudm 18, 18, 13 # x4 -.endm - -.macro mul_even - vmuleuw 9, 4, 26 - vmuleuw 10, 5, 3 - vmuleuw 11, 6, 2 - vmuleuw 12, 7, 1 - vmuleuw 13, 8, 0 - vaddudm 14, 14, 9 - vaddudm 14, 14, 10 - vaddudm 14, 14, 11 - vaddudm 14, 14, 12 - vaddudm 14, 14, 13 # x0 - - vmuleuw 9, 4, 27 - vmuleuw 10, 5, 26 - vmuleuw 11, 6, 3 - vmuleuw 12, 7, 2 - vmuleuw 13, 8, 1 - vaddudm 15, 15, 9 - vaddudm 15, 15, 10 - vaddudm 15, 15, 11 - vaddudm 15, 15, 12 - vaddudm 15, 15, 13 # x1 - - vmuleuw 9, 4, 28 - vmuleuw 10, 5, 27 - vmuleuw 11, 6, 26 - vmuleuw 12, 7, 3 - vmuleuw 13, 8, 2 - vaddudm 16, 16, 9 - vaddudm 16, 16, 10 - vaddudm 16, 16, 11 - vaddudm 16, 16, 12 - vaddudm 16, 16, 13 # x2 - - vmuleuw 9, 4, 29 - vmuleuw 10, 5, 28 - vmuleuw 11, 6, 27 - vmuleuw 12, 7, 26 - vmuleuw 13, 8, 3 - vaddudm 17, 17, 9 - vaddudm 17, 17, 10 - vaddudm 17, 17, 11 - vaddudm 17, 17, 12 - vaddudm 17, 17, 13 # x3 - - vmuleuw 9, 4, 30 - vmuleuw 10, 5, 29 - vmuleuw 11, 6, 28 - vmuleuw 12, 7, 27 - vmuleuw 13, 8, 26 - vaddudm 18, 18, 9 - vaddudm 18, 18, 10 - vaddudm 18, 18, 11 - vaddudm 18, 18, 12 - vaddudm 18, 18, 13 # x4 -.endm - -# -# poly1305_setup_r -# -# setup r^4, r^3, r^2, r vectors -# [r, r^3, r^2, r^4] -# vs0 = [r0,...] -# vs1 = [r1,...] -# vs2 = [r2,...] -# vs3 = [r3,...] -# vs4 = [r4,...] -# vs5 = [r4*5,...] -# vs6 = [r3*5,...] -# vs7 = [r2*5,...] -# vs8 = [r1*5,...] -# -# r0, r4*5, r3*5, r2*5, r1*5; -# r1, r0, r4*5, r3*5, r2*5; -# r2, r1, r0, r4*5, r3*5; -# r3, r2, r1, r0, r4*5; -# r4, r3, r2, r1, r0 ; -# -.macro poly1305_setup_r - - # save r - xxlor 26, 58, 58 - xxlor 27, 59, 59 - xxlor 28, 60, 60 - xxlor 29, 61, 61 - xxlor 30, 62, 62 - - xxlxor 31, 31, 31 - -# [r, r^3, r^2, r^4] - # compute r^2 - vmr 4, 26 - vmr 5, 27 - vmr 6, 28 - vmr 7, 29 - vmr 8, 30 - bl do_mul # r^2 r^1 - xxpermdi 58, 58, 36, 0x3 # r0 - xxpermdi 59, 59, 37, 0x3 # r1 - xxpermdi 60, 60, 38, 0x3 # r2 - xxpermdi 61, 61, 39, 0x3 # r3 - xxpermdi 62, 62, 40, 0x3 # r4 - xxpermdi 36, 36, 36, 0x3 - xxpermdi 37, 37, 37, 0x3 - xxpermdi 38, 38, 38, 0x3 - xxpermdi 39, 39, 39, 0x3 - xxpermdi 40, 40, 40, 0x3 - vspltisb 13, 2 - vsld 9, 27, 13 - vsld 10, 28, 13 - vsld 11, 29, 13 - vsld 12, 30, 13 - vaddudm 0, 9, 27 - vaddudm 1, 10, 28 - vaddudm 2, 11, 29 - vaddudm 3, 12, 30 - - bl do_mul # r^4 r^3 - vmrgow 26, 26, 4 - vmrgow 27, 27, 5 - vmrgow 28, 28, 6 - vmrgow 29, 29, 7 - vmrgow 30, 30, 8 - vspltisb 13, 2 - vsld 9, 27, 13 - vsld 10, 28, 13 - vsld 11, 29, 13 - vsld 12, 30, 13 - vaddudm 0, 9, 27 - vaddudm 1, 10, 28 - vaddudm 2, 11, 29 - vaddudm 3, 12, 30 - - # r^2 r^4 - xxlor 0, 58, 58 - xxlor 1, 59, 59 - xxlor 2, 60, 60 - xxlor 3, 61, 61 - xxlor 4, 62, 62 - xxlor 5, 32, 32 - xxlor 6, 33, 33 - xxlor 7, 34, 34 - xxlor 8, 35, 35 - - vspltw 9, 26, 3 - vspltw 10, 26, 2 - vmrgow 26, 10, 9 - vspltw 9, 27, 3 - vspltw 10, 27, 2 - vmrgow 27, 10, 9 - vspltw 9, 28, 3 - vspltw 10, 28, 2 - vmrgow 28, 10, 9 - vspltw 9, 29, 3 - vspltw 10, 29, 2 - vmrgow 29, 10, 9 - vspltw 9, 30, 3 - vspltw 10, 30, 2 - vmrgow 30, 10, 9 - - vsld 9, 27, 13 - vsld 10, 28, 13 - vsld 11, 29, 13 - vsld 12, 30, 13 - vaddudm 0, 9, 27 - vaddudm 1, 10, 28 - vaddudm 2, 11, 29 - vaddudm 3, 12, 30 -.endm - -SYM_FUNC_START_LOCAL(do_mul) - mul_odd - - # do reduction ( h %= p ) - # carry reduction - vspltisb 9, 2 - vsrd 10, 14, 31 - vsrd 11, 17, 31 - vand 7, 17, 25 - vand 4, 14, 25 - vaddudm 18, 18, 11 - vsrd 12, 18, 31 - vaddudm 15, 15, 10 - - vsrd 11, 15, 31 - vand 8, 18, 25 - vand 5, 15, 25 - vaddudm 4, 4, 12 - vsld 10, 12, 9 - vaddudm 6, 16, 11 - - vsrd 13, 6, 31 - vand 6, 6, 25 - vaddudm 4, 4, 10 - vsrd 10, 4, 31 - vaddudm 7, 7, 13 - - vsrd 11, 7, 31 - vand 7, 7, 25 - vand 4, 4, 25 - vaddudm 5, 5, 10 - vaddudm 8, 8, 11 - blr -SYM_FUNC_END(do_mul) - -# -# init key -# -.macro do_poly1305_init - addis 10, 2, rmask@toc@ha - addi 10, 10, rmask@toc@l - - ld 11, 0(10) - ld 12, 8(10) - - li 14, 16 - li 15, 32 - addis 10, 2, cnum@toc@ha - addi 10, 10, cnum@toc@l - lvx 25, 0, 10 # v25 - mask - lvx 31, 14, 10 # v31 = 1a - lvx 19, 15, 10 # v19 = 1 << 24 - lxv 24, 48(10) # vs24 - lxv 25, 64(10) # vs25 - - # initialize - # load key from r3 to vectors - ld 9, 24(3) - ld 10, 32(3) - and. 9, 9, 11 - and. 10, 10, 12 - - # break 26 bits - extrdi 14, 9, 26, 38 - extrdi 15, 9, 26, 12 - extrdi 16, 9, 12, 0 - mtvsrdd 58, 0, 14 - insrdi 16, 10, 14, 38 - mtvsrdd 59, 0, 15 - extrdi 17, 10, 26, 24 - mtvsrdd 60, 0, 16 - extrdi 18, 10, 24, 0 - mtvsrdd 61, 0, 17 - mtvsrdd 62, 0, 18 - - # r1 = r1 * 5, r2 = r2 * 5, r3 = r3 * 5, r4 = r4 * 5 - li 9, 5 - mtvsrdd 36, 0, 9 - vmulouw 0, 27, 4 # v0 = rr0 - vmulouw 1, 28, 4 # v1 = rr1 - vmulouw 2, 29, 4 # v2 = rr2 - vmulouw 3, 30, 4 # v3 = rr3 -.endm - -# -# void poly1305_p10le_4blocks(struct poly1305_block_state *state, const u8 *m, -# size_t mlen); -# r3 = state -# r4 = m -# r5 = mlen -# -SYM_FUNC_START(poly1305_p10le_4blocks) -.align 5 - cmpdi 5, 64 - blt Out_no_poly1305 - - SAVE_REGS - - do_poly1305_init - - li 21, 0 # counter to message - - poly1305_setup_r - - # load previous H state - # break/convert r6 to 26 bits - ld 9, 0(3) - ld 10, 8(3) - ld 19, 16(3) - sldi 19, 19, 24 - mtvsrdd 41, 0, 19 - extrdi 14, 9, 26, 38 - extrdi 15, 9, 26, 12 - extrdi 16, 9, 12, 0 - mtvsrdd 36, 0, 14 - insrdi 16, 10, 14, 38 - mtvsrdd 37, 0, 15 - extrdi 17, 10, 26, 24 - mtvsrdd 38, 0, 16 - extrdi 18, 10, 24, 0 - mtvsrdd 39, 0, 17 - mtvsrdd 40, 0, 18 - vor 8, 8, 9 - - # input m1 m2 - add 20, 4, 21 - xxlor 49, 24, 24 - xxlor 50, 25, 25 - lxvw4x 43, 0, 20 - addi 17, 20, 16 - lxvw4x 44, 0, 17 - vperm 14, 11, 12, 17 - vperm 15, 11, 12, 18 - vand 9, 14, 25 # a0 - vsrd 10, 14, 31 # >> 26 - vsrd 11, 10, 31 # 12 bits left - vand 10, 10, 25 # a1 - vspltisb 13, 12 - vand 16, 15, 25 - vsld 12, 16, 13 - vor 11, 11, 12 - vand 11, 11, 25 # a2 - vspltisb 13, 14 - vsrd 12, 15, 13 # >> 14 - vsrd 13, 12, 31 # >> 26, a4 - vand 12, 12, 25 # a3 - - vaddudm 20, 4, 9 - vaddudm 21, 5, 10 - vaddudm 22, 6, 11 - vaddudm 23, 7, 12 - vaddudm 24, 8, 13 - - # m3 m4 - addi 17, 17, 16 - lxvw4x 43, 0, 17 - addi 17, 17, 16 - lxvw4x 44, 0, 17 - vperm 14, 11, 12, 17 - vperm 15, 11, 12, 18 - vand 9, 14, 25 # a0 - vsrd 10, 14, 31 # >> 26 - vsrd 11, 10, 31 # 12 bits left - vand 10, 10, 25 # a1 - vspltisb 13, 12 - vand 16, 15, 25 - vsld 12, 16, 13 - vspltisb 13, 14 - vor 11, 11, 12 - vand 11, 11, 25 # a2 - vsrd 12, 15, 13 # >> 14 - vsrd 13, 12, 31 # >> 26, a4 - vand 12, 12, 25 # a3 - - # Smash 4 message blocks into 5 vectors of [m4, m2, m3, m1] - vmrgow 4, 9, 20 - vmrgow 5, 10, 21 - vmrgow 6, 11, 22 - vmrgow 7, 12, 23 - vmrgow 8, 13, 24 - vaddudm 8, 8, 19 - - addi 5, 5, -64 # len -= 64 - addi 21, 21, 64 # offset += 64 - - li 9, 64 - divdu 31, 5, 9 - - cmpdi 31, 0 - ble Skip_block_loop - - mtctr 31 - -# h4 = m1 * r⁴ + m2 * r³ + m3 * r² + m4 * r -# Rewrite the polynominal sum of product as follows, -# h1 = (h0 + m1) * r^2, h2 = (h0 + m2) * r^2 -# h3 = (h1 + m3) * r^2, h4 = (h2 + m4) * r^2 --> (h0 + m1) r*4 + (h3 + m3) r^2, (h0 + m2) r^4 + (h0 + m4) r^2 -# .... Repeat -# h5 = (h3 + m5) * r^2, h6 = (h4 + m6) * r^2 --> -# h7 = (h5 + m7) * r^2, h8 = (h6 + m8) * r^1 --> m5 * r^4 + m6 * r^3 + m7 * r^2 + m8 * r -# -loop_4blocks: - - # Multiply odd words and even words - mul_odd - mul_even - # carry reduction - vspltisb 9, 2 - vsrd 10, 14, 31 - vsrd 11, 17, 31 - vand 7, 17, 25 - vand 4, 14, 25 - vaddudm 18, 18, 11 - vsrd 12, 18, 31 - vaddudm 15, 15, 10 - - vsrd 11, 15, 31 - vand 8, 18, 25 - vand 5, 15, 25 - vaddudm 4, 4, 12 - vsld 10, 12, 9 - vaddudm 6, 16, 11 - - vsrd 13, 6, 31 - vand 6, 6, 25 - vaddudm 4, 4, 10 - vsrd 10, 4, 31 - vaddudm 7, 7, 13 - - vsrd 11, 7, 31 - vand 7, 7, 25 - vand 4, 4, 25 - vaddudm 5, 5, 10 - vaddudm 8, 8, 11 - - # input m1 m2 m3 m4 - add 20, 4, 21 - xxlor 49, 24, 24 - xxlor 50, 25, 25 - lxvw4x 43, 0, 20 - addi 17, 20, 16 - lxvw4x 44, 0, 17 - vperm 14, 11, 12, 17 - vperm 15, 11, 12, 18 - addi 17, 17, 16 - lxvw4x 43, 0, 17 - addi 17, 17, 16 - lxvw4x 44, 0, 17 - vperm 17, 11, 12, 17 - vperm 18, 11, 12, 18 - - vand 20, 14, 25 # a0 - vand 9, 17, 25 # a0 - vsrd 21, 14, 31 # >> 26 - vsrd 22, 21, 31 # 12 bits left - vsrd 10, 17, 31 # >> 26 - vsrd 11, 10, 31 # 12 bits left - - vand 21, 21, 25 # a1 - vand 10, 10, 25 # a1 - - vspltisb 13, 12 - vand 16, 15, 25 - vsld 23, 16, 13 - vor 22, 22, 23 - vand 22, 22, 25 # a2 - vand 16, 18, 25 - vsld 12, 16, 13 - vor 11, 11, 12 - vand 11, 11, 25 # a2 - vspltisb 13, 14 - vsrd 23, 15, 13 # >> 14 - vsrd 24, 23, 31 # >> 26, a4 - vand 23, 23, 25 # a3 - vsrd 12, 18, 13 # >> 14 - vsrd 13, 12, 31 # >> 26, a4 - vand 12, 12, 25 # a3 - - vaddudm 4, 4, 20 - vaddudm 5, 5, 21 - vaddudm 6, 6, 22 - vaddudm 7, 7, 23 - vaddudm 8, 8, 24 - - # Smash 4 message blocks into 5 vectors of [m4, m2, m3, m1] - vmrgow 4, 9, 4 - vmrgow 5, 10, 5 - vmrgow 6, 11, 6 - vmrgow 7, 12, 7 - vmrgow 8, 13, 8 - vaddudm 8, 8, 19 - - addi 5, 5, -64 # len -= 64 - addi 21, 21, 64 # offset += 64 - - bdnz loop_4blocks - -Skip_block_loop: - xxlor 58, 0, 0 - xxlor 59, 1, 1 - xxlor 60, 2, 2 - xxlor 61, 3, 3 - xxlor 62, 4, 4 - xxlor 32, 5, 5 - xxlor 33, 6, 6 - xxlor 34, 7, 7 - xxlor 35, 8, 8 - - # Multiply odd words and even words - mul_odd - mul_even - - # Sum the products. - xxpermdi 41, 31, 46, 0 - xxpermdi 42, 31, 47, 0 - vaddudm 4, 14, 9 - xxpermdi 36, 31, 36, 3 - vaddudm 5, 15, 10 - xxpermdi 37, 31, 37, 3 - xxpermdi 43, 31, 48, 0 - vaddudm 6, 16, 11 - xxpermdi 38, 31, 38, 3 - xxpermdi 44, 31, 49, 0 - vaddudm 7, 17, 12 - xxpermdi 39, 31, 39, 3 - xxpermdi 45, 31, 50, 0 - vaddudm 8, 18, 13 - xxpermdi 40, 31, 40, 3 - - # carry reduction - vspltisb 9, 2 - vsrd 10, 4, 31 - vsrd 11, 7, 31 - vand 7, 7, 25 - vand 4, 4, 25 - vaddudm 8, 8, 11 - vsrd 12, 8, 31 - vaddudm 5, 5, 10 - - vsrd 11, 5, 31 - vand 8, 8, 25 - vand 5, 5, 25 - vaddudm 4, 4, 12 - vsld 10, 12, 9 - vaddudm 6, 6, 11 - - vsrd 13, 6, 31 - vand 6, 6, 25 - vaddudm 4, 4, 10 - vsrd 10, 4, 31 - vaddudm 7, 7, 13 - - vsrd 11, 7, 31 - vand 7, 7, 25 - vand 4, 4, 25 - vaddudm 5, 5, 10 - vsrd 10, 5, 31 - vand 5, 5, 25 - vaddudm 6, 6, 10 - vaddudm 8, 8, 11 - - b do_final_update - -do_final_update: - # combine 26 bit limbs - # v4, v5, v6, v7 and v8 are 26 bit vectors - vsld 5, 5, 31 - vor 20, 4, 5 - vspltisb 11, 12 - vsrd 12, 6, 11 - vsld 6, 6, 31 - vsld 6, 6, 31 - vor 20, 20, 6 - vspltisb 11, 14 - vsld 7, 7, 11 - vor 21, 7, 12 - mfvsrld 16, 40 # save last 2 bytes - vsld 8, 8, 11 - vsld 8, 8, 31 - vor 21, 21, 8 - mfvsrld 17, 52 - mfvsrld 19, 53 - srdi 16, 16, 24 - - std 17, 0(3) - std 19, 8(3) - stw 16, 16(3) - -Out_loop: - li 3, 0 - - RESTORE_REGS - - blr - -Out_no_poly1305: - li 3, 0 - blr -SYM_FUNC_END(poly1305_p10le_4blocks) - -# -# ======================================================================= -# The following functions implement 64 x 64 bits multiplication poly1305. -# -SYM_FUNC_START_LOCAL(Poly1305_init_64) - # mask 0x0FFFFFFC0FFFFFFC - # mask 0x0FFFFFFC0FFFFFFF - addis 10, 2, rmask@toc@ha - addi 10, 10, rmask@toc@l - ld 11, 0(10) - ld 12, 8(10) - - # initialize - # load key from r3 - ld 9, 24(3) - ld 10, 32(3) - and. 9, 9, 11 # cramp mask r0 - and. 10, 10, 12 # cramp mask r1 - - srdi 21, 10, 2 - add 19, 21, 10 # s1: r19 - (r1 >> 2) *5 - - # setup r and s - li 25, 0 - mtvsrdd 32+0, 9, 19 # r0, s1 - mtvsrdd 32+1, 10, 9 # r1, r0 - mtvsrdd 32+2, 19, 25 # s1 - mtvsrdd 32+3, 9, 25 # r0 - - blr -SYM_FUNC_END(Poly1305_init_64) - -# Poly1305_mult -# v6 = (h0, h1), v8 = h2 -# v0 = (r0, s1), v1 = (r1, r0), v2 = s1, v3 = r0 -# -# Output: v7, v10, v11 -# -SYM_FUNC_START_LOCAL(Poly1305_mult) - # - # d0 = h0 * r0 + h1 * s1 - vmsumudm 7, 6, 0, 9 # h0 * r0, h1 * s1 - - # d1 = h0 * r1 + h1 * r0 + h2 * s1 - vmsumudm 11, 6, 1, 9 # h0 * r1, h1 * r0 - vmsumudm 10, 8, 2, 11 # d1 += h2 * s1 - - # d2 = r0 - vmsumudm 11, 8, 3, 9 # d2 = h2 * r0 - blr -SYM_FUNC_END(Poly1305_mult) - -# -# carry reduction -# h %=p -# -# Input: v7, v10, v11 -# Output: r27, r28, r29 -# -SYM_FUNC_START_LOCAL(Carry_reduction) - mfvsrld 27, 32+7 - mfvsrld 28, 32+10 - mfvsrld 29, 32+11 - mfvsrd 20, 32+7 # h0.h - mfvsrd 21, 32+10 # h1.h - - addc 28, 28, 20 - adde 29, 29, 21 - srdi 22, 29, 0x2 - sldi 23, 22, 0x2 - add 23, 23, 22 # (h2 & 3) * 5 - addc 27, 27, 23 # h0 - addze 28, 28 # h1 - andi. 29, 29, 0x3 # h2 - blr -SYM_FUNC_END(Carry_reduction) - -# -# poly1305 multiplication -# h *= r, h %= p -# d0 = h0 * r0 + h1 * s1 -# d1 = h0 * r1 + h1 * r0 + h2 * s1 -# d2 = h0 * r0 -# -# -# void poly1305_64s(struct poly1305_block_state *state, const u8 *m, -# size_t mlen, int highbit); -# - no highbit if final leftover block (highbit = 0) -# -SYM_FUNC_START(poly1305_64s) - cmpdi 5, 0 - ble Out_no_poly1305_64 - - mflr 0 - std 0, 16(1) - stdu 1,-400(1) - - SAVE_GPR 14, 112, 1 - SAVE_GPR 15, 120, 1 - SAVE_GPR 16, 128, 1 - SAVE_GPR 17, 136, 1 - SAVE_GPR 18, 144, 1 - SAVE_GPR 19, 152, 1 - SAVE_GPR 20, 160, 1 - SAVE_GPR 21, 168, 1 - SAVE_GPR 22, 176, 1 - SAVE_GPR 23, 184, 1 - SAVE_GPR 24, 192, 1 - SAVE_GPR 25, 200, 1 - SAVE_GPR 26, 208, 1 - SAVE_GPR 27, 216, 1 - SAVE_GPR 28, 224, 1 - SAVE_GPR 29, 232, 1 - SAVE_GPR 30, 240, 1 - SAVE_GPR 31, 248, 1 - - # Init poly1305 - bl Poly1305_init_64 - - li 25, 0 # offset to inp and outp - - add 11, 25, 4 - - # load h - # h0, h1, h2? - ld 27, 0(3) - ld 28, 8(3) - lwz 29, 16(3) - - li 30, 16 - divdu 31, 5, 30 - - mtctr 31 - - mr 24, 6 # highbit - -Loop_block_64: - vxor 9, 9, 9 - - ld 20, 0(11) - ld 21, 8(11) - addi 11, 11, 16 - - addc 27, 27, 20 - adde 28, 28, 21 - adde 29, 29, 24 - - li 22, 0 - mtvsrdd 32+6, 27, 28 # h0, h1 - mtvsrdd 32+8, 29, 22 # h2 - - bl Poly1305_mult - - bl Carry_reduction - - bdnz Loop_block_64 - - std 27, 0(3) - std 28, 8(3) - stw 29, 16(3) - - li 3, 0 - - RESTORE_GPR 14, 112, 1 - RESTORE_GPR 15, 120, 1 - RESTORE_GPR 16, 128, 1 - RESTORE_GPR 17, 136, 1 - RESTORE_GPR 18, 144, 1 - RESTORE_GPR 19, 152, 1 - RESTORE_GPR 20, 160, 1 - RESTORE_GPR 21, 168, 1 - RESTORE_GPR 22, 176, 1 - RESTORE_GPR 23, 184, 1 - RESTORE_GPR 24, 192, 1 - RESTORE_GPR 25, 200, 1 - RESTORE_GPR 26, 208, 1 - RESTORE_GPR 27, 216, 1 - RESTORE_GPR 28, 224, 1 - RESTORE_GPR 29, 232, 1 - RESTORE_GPR 30, 240, 1 - RESTORE_GPR 31, 248, 1 - - addi 1, 1, 400 - ld 0, 16(1) - mtlr 0 - - blr - -Out_no_poly1305_64: - li 3, 0 - blr -SYM_FUNC_END(poly1305_64s) - -# -# Input: r3 = h, r4 = s, r5 = mac -# mac = h + s -# -SYM_FUNC_START(poly1305_emit_64) - ld 10, 0(3) - ld 11, 8(3) - ld 12, 16(3) - - # compare modulus - # h + 5 + (-p) - mr 6, 10 - mr 7, 11 - mr 8, 12 - addic. 6, 6, 5 - addze 7, 7 - addze 8, 8 - srdi 9, 8, 2 # overflow? - cmpdi 9, 0 - beq Skip_h64 - mr 10, 6 - mr 11, 7 - mr 12, 8 - -Skip_h64: - ld 6, 0(4) - ld 7, 8(4) - addc 10, 10, 6 - adde 11, 11, 7 - addze 12, 12 - - std 10, 0(5) - std 11, 8(5) - blr -SYM_FUNC_END(poly1305_emit_64) - -SYM_DATA_START_LOCAL(RMASK) -.align 5 -rmask: -.byte 0xff, 0xff, 0xff, 0x0f, 0xfc, 0xff, 0xff, 0x0f, 0xfc, 0xff, 0xff, 0x0f, 0xfc, 0xff, 0xff, 0x0f -cnum: -.long 0x03ffffff, 0x00000000, 0x03ffffff, 0x00000000 -.long 0x1a, 0x00, 0x1a, 0x00 -.long 0x01000000, 0x01000000, 0x01000000, 0x01000000 -.long 0x00010203, 0x04050607, 0x10111213, 0x14151617 -.long 0x08090a0b, 0x0c0d0e0f, 0x18191a1b, 0x1c1d1e1f -SYM_DATA_END(RMASK) diff --git a/lib/crypto/powerpc/poly1305.h b/lib/crypto/powerpc/poly1305.h deleted file mode 100644 index f758c24b312947..00000000000000 --- a/lib/crypto/powerpc/poly1305.h +++ /dev/null @@ -1,76 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Poly1305 authenticator algorithm, RFC7539. - * - * Copyright 2023- IBM Corp. All rights reserved. - */ -#include -#include -#include -#include -#include - -asmlinkage void poly1305_p10le_4blocks(struct poly1305_block_state *state, - const u8 *m, size_t mlen); -asmlinkage void poly1305_64s(struct poly1305_block_state *state, const u8 *m, - size_t mlen, int highbit); -asmlinkage void poly1305_emit_64(const struct poly1305_state *state, const u32 nonce[4], u8 digest[POLY1305_DIGEST_SIZE]); - -static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_p10); - -static void vsx_begin(void) -{ - preempt_disable(); - enable_kernel_vsx(); -} - -static void vsx_end(void) -{ - disable_kernel_vsx(); - preempt_enable(); -} - -static void poly1305_block_init(struct poly1305_block_state *dctx, - const u8 raw_key[POLY1305_BLOCK_SIZE]) -{ - if (!static_key_enabled(&have_p10)) - return poly1305_block_init_generic(dctx, raw_key); - - dctx->h = (struct poly1305_state){}; - dctx->core_r.key.r64[0] = get_unaligned_le64(raw_key + 0); - dctx->core_r.key.r64[1] = get_unaligned_le64(raw_key + 8); -} - -static void poly1305_blocks(struct poly1305_block_state *state, const u8 *src, - size_t len, u32 padbit) -{ - if (!static_key_enabled(&have_p10)) - return poly1305_blocks_generic(state, src, len, padbit); - vsx_begin(); - if (len >= POLY1305_BLOCK_SIZE * 4) { - poly1305_p10le_4blocks(state, src, len); - src += len - (len % (POLY1305_BLOCK_SIZE * 4)); - len %= POLY1305_BLOCK_SIZE * 4; - } - while (len >= POLY1305_BLOCK_SIZE) { - poly1305_64s(state, src, POLY1305_BLOCK_SIZE, padbit); - len -= POLY1305_BLOCK_SIZE; - src += POLY1305_BLOCK_SIZE; - } - vsx_end(); -} - -static void poly1305_emit(const struct poly1305_state *state, - u8 digest[POLY1305_DIGEST_SIZE], const u32 nonce[4]) -{ - if (!static_key_enabled(&have_p10)) - return poly1305_emit_generic(state, digest, nonce); - poly1305_emit_64(state, nonce, digest); -} - -#define poly1305_mod_init_arch poly1305_mod_init_arch -static void poly1305_mod_init_arch(void) -{ - if (cpu_has_feature(CPU_FTR_ARCH_31)) - static_branch_enable(&have_p10); -} diff --git a/lib/crypto/tests/mldsa_kunit.c b/lib/crypto/tests/mldsa_kunit.c index ec64e10c97f252..d0ee704a369444 100644 --- a/lib/crypto/tests/mldsa_kunit.c +++ b/lib/crypto/tests/mldsa_kunit.c @@ -372,6 +372,14 @@ static void test_mldsa_use_hint(struct kunit *test) } } +static void test_mldsa_invalid_alg(struct kunit *test) +{ + KUNIT_ASSERT_EQ(test, -EINVAL, + mldsa_verify(MLDSA44 - 1, NULL, 0, NULL, 0, NULL, 0)); + KUNIT_ASSERT_EQ(test, -EINVAL, + mldsa_verify(MLDSA87 + 1, NULL, 0, NULL, 0, NULL, 0)); +} + static void benchmark_mldsa(struct kunit *test, const struct mldsa_testvector *tv) { @@ -414,6 +422,7 @@ static struct kunit_case mldsa_kunit_cases[] = { KUNIT_CASE(test_mldsa65), KUNIT_CASE(test_mldsa87), KUNIT_CASE(test_mldsa_use_hint), + KUNIT_CASE(test_mldsa_invalid_alg), KUNIT_CASE(benchmark_mldsa44), KUNIT_CASE(benchmark_mldsa65), KUNIT_CASE(benchmark_mldsa87), diff --git a/lib/errseq.c b/lib/errseq.c index 13a2581c5a8784..ea4ff9cc21669c 100644 --- a/lib/errseq.c +++ b/lib/errseq.c @@ -162,7 +162,8 @@ EXPORT_SYMBOL(errseq_check); * points to. If it does, then just return 0. * * If it doesn't, then the value has changed. Set the "seen" flag, and try to - * swap it into place as the new eseq value. Then, set that value as the new + * swap it into place as the new eseq value. If the swap fails because the + * value changed, retry with the new value. Then, set that value as the new * "since" value, and return whatever the error portion is set to. * * Note that no locking is provided here for concurrent updates to the "since" @@ -184,24 +185,30 @@ int errseq_check_and_advance(errseq_t *eseq, errseq_t *since) * to take the lock that protects the "since" value. */ old = READ_ONCE(*eseq); - if (old != *since) { + while (old != *since) { /* * Set the flag and try to swap it into place if it has * changed. * - * We don't care about the outcome of the swap here. If the - * swap doesn't occur, then it has either been updated by a - * writer who is altering the value in some way (updating - * counter or resetting the error), or another reader who is - * just setting the "seen" flag. Either outcome is OK, and we - * can advance "since" and return an error based on what we - * have. + * If the swap fails, a writer or another reader changed the + * value under us, so retry with the new value. "since" must + * only ever be set to a value that was stored with the SEEN + * flag: errseq_set() does not bump the counter while the + * flag is clear, so an unstored value could come back later + * and hide the errors that were recorded in the meantime. */ new = old | ERRSEQ_SEEN; - if (new != old) - cmpxchg(eseq, old, new); + if (new != old) { + errseq_t cur = cmpxchg(eseq, old, new); + + if (cur != old) { + old = cur; + continue; + } + } *since = new; err = -(new & ERRNO_MASK); + break; } return err; } diff --git a/lib/iov_iter.c b/lib/iov_iter.c index fa4fe2e9238316..af005ef5cb8218 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1382,8 +1382,8 @@ static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec, } ssize_t __import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i, bool compat) + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i, bool compat) { ssize_t total_len = 0; unsigned long seg; @@ -1454,7 +1454,7 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec, * Return: Negative error code on error, bytes imported on success */ ssize_t import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, + unsigned long nr_segs, unsigned int fast_segs, struct iovec **iovp, struct iov_iter *i) { return __import_iovec(type, uvec, nr_segs, fast_segs, iovp, i, diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c index 864484c01827e1..fe84c6a2a5a8ff 100644 --- a/lib/reed_solomon/reed_solomon.c +++ b/lib/reed_solomon/reed_solomon.c @@ -88,15 +88,15 @@ static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int), rs->gffunc = gffunc; /* Allocate the arrays */ - rs->alpha_to = kmalloc_array(rs->nn + 1, sizeof(uint16_t), gfp); + rs->alpha_to = kmalloc_objs(uint16_t, rs->nn + 1, gfp); if (rs->alpha_to == NULL) goto err; - rs->index_of = kmalloc_array(rs->nn + 1, sizeof(uint16_t), gfp); + rs->index_of = kmalloc_objs(uint16_t, rs->nn + 1, gfp); if (rs->index_of == NULL) goto err; - rs->genpoly = kmalloc_array(rs->nroots + 1, sizeof(uint16_t), gfp); + rs->genpoly = kmalloc_objs(uint16_t, rs->nroots + 1, gfp); if(rs->genpoly == NULL) goto err; diff --git a/lib/reed_solomon/test_rslib.c b/lib/reed_solomon/test_rslib.c index 42b856e6c8a846..acfc172c8025dd 100644 --- a/lib/reed_solomon/test_rslib.c +++ b/lib/reed_solomon/test_rslib.c @@ -115,8 +115,7 @@ static struct wspace *alloc_ws(struct rs_codec *rs) if (!ws) return NULL; - ws->c = kmalloc_array(2 * (nn + nroots), - sizeof(uint16_t), GFP_KERNEL); + ws->c = kmalloc_objs(uint16_t, 2 * (nn + nroots)); if (!ws->c) goto err; diff --git a/lib/region_alloc_benchmark.c b/lib/region_alloc_benchmark.c index a644f3d5431a0c..4ca797dfa4ee98 100644 --- a/lib/region_alloc_benchmark.c +++ b/lib/region_alloc_benchmark.c @@ -180,9 +180,9 @@ static int __init region_alloc_benchmark(void) max_cap = max(max_cap, capacities[i]); } - bitmap = kvmalloc_array(BITS_TO_LONGS(max_cap), sizeof(*bitmap), GFP_KERNEL); + bitmap = kvmalloc_objs(*bitmap, BITS_TO_LONGS(max_cap)); reg_sz = kvmalloc_array(max_cap + 1, sizeof(*reg_sz), GFP_KERNEL); - reg_idx = kvmalloc_array(max_cap, sizeof(*reg_idx), GFP_KERNEL); + reg_idx = kvmalloc_objs(*reg_idx, max_cap); if (!bitmap || !reg_sz || !reg_idx) goto out; diff --git a/lib/test_bitops.c b/lib/test_bitops.c index 55669624bb28a0..e6f3987ca270f7 100644 --- a/lib/test_bitops.c +++ b/lib/test_bitops.c @@ -59,7 +59,7 @@ static int __init test_fns(void) unsigned int i, n; ktime_t time; - buf = kmalloc_array(10000, sizeof(unsigned long), GFP_KERNEL); + buf = kmalloc_objs(unsigned long, 10000); if (!buf) return -ENOMEM; diff --git a/lib/test_hmm.c b/lib/test_hmm.c index b409c42bfe6fc4..a09a766b15b05e 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -195,8 +195,8 @@ static void dmirror_device_evict_chunk(struct dmirror_chunk *chunk) unsigned long *dst_pfns; unsigned int order = 0; - src_pfns = kvcalloc(npages, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL); - dst_pfns = kvcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL); + src_pfns = kvzalloc_objs(*src_pfns, npages, GFP_KERNEL | __GFP_NOFAIL); + dst_pfns = kvzalloc_objs(*dst_pfns, npages, GFP_KERNEL | __GFP_NOFAIL); migrate_device_range(src_pfns, start_pfn, npages); for (i = 0; i < npages; i++) { @@ -1241,8 +1241,10 @@ static int dmirror_migrate_to_system(struct dmirror *dmirror, if (!mmget_not_zero(mm)) return -EINVAL; - src_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL); - dst_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL); + src_pfns = kvzalloc_objs(*src_pfns, PTRS_PER_PTE, + GFP_KERNEL | __GFP_NOFAIL); + dst_pfns = kvzalloc_objs(*dst_pfns, PTRS_PER_PTE, + GFP_KERNEL | __GFP_NOFAIL); cmd->cpages = 0; mmap_read_lock(mm); @@ -1311,10 +1313,10 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror, if (!mmget_not_zero(mm)) return -EINVAL; - src_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*src_pfns), - GFP_KERNEL | __GFP_NOFAIL); - dst_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*dst_pfns), - GFP_KERNEL | __GFP_NOFAIL); + src_pfns = kvzalloc_objs(*src_pfns, PTRS_PER_PTE, + GFP_KERNEL | __GFP_NOFAIL); + dst_pfns = kvzalloc_objs(*dst_pfns, PTRS_PER_PTE, + GFP_KERNEL | __GFP_NOFAIL); ret = 0; mmap_read_lock(mm); @@ -1788,8 +1790,8 @@ static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf) args.end = args.start + (PAGE_SIZE << order); nr = (args.end - args.start) >> PAGE_SHIFT; - args.src = kcalloc(nr, sizeof(unsigned long), GFP_KERNEL); - args.dst = kcalloc(nr, sizeof(unsigned long), GFP_KERNEL); + args.src = kzalloc_objs(unsigned long, nr); + args.dst = kzalloc_objs(unsigned long, nr); args.pgmap_owner = dmirror->mdevice; args.flags = dmirror_select_device(dmirror); args.fault_page = vmf->page; diff --git a/lib/test_workqueue.c b/lib/test_workqueue.c index 2bdfcbbcabb4ea..bdced8750197c9 100644 --- a/lib/test_workqueue.c +++ b/lib/test_workqueue.c @@ -160,7 +160,7 @@ static int __init run_bench(int n_threads, const char *scope, const char *label) } total_items = (unsigned long)n_threads * wq_items; - all_latencies = kvmalloc_array(total_items, sizeof(u64), GFP_KERNEL); + all_latencies = kvmalloc_objs(u64, total_items); if (!all_latencies) { kfree(tasks); kfree(ctxs); @@ -169,8 +169,7 @@ static int __init run_bench(int n_threads, const char *scope, const char *label) /* Allocate per-thread latency arrays */ for (i = 0; i < n_threads; i++) { - ctxs[i].latencies = kvmalloc_array(wq_items, sizeof(u64), - GFP_KERNEL); + ctxs[i].latencies = kvmalloc_objs(u64, wq_items); if (!ctxs[i].latencies) { while (--i >= 0) kvfree(ctxs[i].latencies); diff --git a/lib/tests/errseq_kunit.c b/lib/tests/errseq_kunit.c index 8f39ebc4a2488e..5ebc411ea749a0 100644 --- a/lib/tests/errseq_kunit.c +++ b/lib/tests/errseq_kunit.c @@ -2,21 +2,26 @@ /* * KUnit tests for the errseq_t error-tracking infrastructure. * - * These exercise the documented single-threaded semantics of the errseq - * API (see Documentation/core-api/errseq.rst and lib/errseq.c): error + * Most cases exercise the documented single-threaded semantics of the + * errseq API (see Documentation/core-api/errseq.rst and lib/errseq.c): error * recording and overwriting, the "seen" handoff between errseq_sample() * and errseq_check_and_advance(), and the re-reporting of an error that * is recorded again after it has been seen. * - * The lockless properties of errseq_t under concurrent updates are - * outside the scope of these deterministic tests, as is the WARN path - * for invalid error values. + * The WARN path for invalid error values is not tested. The last case + * races errseq_set() against errseq_check_and_advance() on another CPU. */ #include +#include +#include #include #include #include +#include +#include +#include +#include /* * A zeroed errseq_t is the "no error has ever occurred" epoch: it @@ -209,6 +214,100 @@ static void errseq_test_two_subscribers_independent(struct kunit *test) KUNIT_EXPECT_EQ(test, errseq_check_and_advance(&eseq, &cursor_b), 0); } +/* + * errseq_check_and_advance() racing with errseq_set() on another CPU. + * + * Each round, cursor @f checks an unseen -EIO while another CPU records + * -ENOSPC. Afterwards -EIO is recorded again and cursor @g checks. The + * second -EIO is recorded after @f's check returned, so @f's next check + * must report an error, whichever way the race with -ENOSPC went. + */ +struct errseq_race { + errseq_t eseq; + atomic_t go; /* round the writer should run */ + atomic_t done; /* last round the writer completed */ + unsigned int wdelay; +}; + +static void errseq_race_spin(unsigned int n) +{ + while (n--) + cpu_relax(); +} + +static int errseq_race_writer(void *data) +{ + struct errseq_race *r = data; + int seen = 0; + + while (!kthread_should_stop()) { + int round = atomic_read_acquire(&r->go); + + if (round == seen) { + cond_resched(); + continue; + } + seen = round; + errseq_race_spin(READ_ONCE(r->wdelay)); + errseq_set(&r->eseq, -ENOSPC); + atomic_set_release(&r->done, round); + } + return 0; +} + +#define ERRSEQ_RACE_ROUNDS 2000000 +#define ERRSEQ_RACE_SECONDS 5 + +static void errseq_test_check_and_advance_race(struct kunit *test) +{ + struct errseq_race *r; + struct task_struct *writer; + unsigned long deadline; + int round, unreported = 0, missed = 0; + + if (num_online_cpus() < 2) + kunit_skip(test, "needs at least two CPUs"); + + r = kunit_kzalloc(test, sizeof(*r), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, r); + + writer = kthread_run(errseq_race_writer, r, "errseq_race"); + KUNIT_ASSERT_FALSE(test, IS_ERR(writer)); + + deadline = jiffies + ERRSEQ_RACE_SECONDS * HZ; + for (round = 1; round <= ERRSEQ_RACE_ROUNDS; round++) { + errseq_t f = 0, g = 0; + + WRITE_ONCE(r->eseq, 0); + errseq_set(&r->eseq, -EIO); + WRITE_ONCE(r->wdelay, get_random_u32_below(64)); + atomic_set_release(&r->go, round); + + errseq_race_spin(get_random_u32_below(64)); + if (!errseq_check_and_advance(&r->eseq, &f)) + unreported++; + + while (atomic_read_acquire(&r->done) != round) + cond_resched(); + + /* Recorded after f's check returned: f must hear about it. */ + errseq_set(&r->eseq, -EIO); + errseq_check_and_advance(&r->eseq, &g); + if (!errseq_check_and_advance(&r->eseq, &f)) + missed++; + + if (time_after(jiffies, deadline)) + break; + if (!(round & 1023)) + cond_resched(); + } + kthread_stop(writer); + + kunit_info(test, "%d rounds, %d missed errors\n", round - 1, missed); + KUNIT_EXPECT_EQ(test, unreported, 0); + KUNIT_EXPECT_EQ(test, missed, 0); +} + static struct kunit_case errseq_test_cases[] = { KUNIT_CASE(errseq_test_zero_epoch_reports_no_error), KUNIT_CASE(errseq_test_set_records_error), @@ -223,6 +322,7 @@ static struct kunit_case errseq_test_cases[] = { KUNIT_CASE(errseq_test_repeat_error_visible_to_all_cursors), KUNIT_CASE(errseq_test_advance_stable_when_unchanged), KUNIT_CASE(errseq_test_two_subscribers_independent), + KUNIT_CASE_SLOW(errseq_test_check_and_advance_race), {} }; diff --git a/lib/vdso/Kconfig b/lib/vdso/Kconfig index 597f5f0f96819c..2436c20ee0efe8 100644 --- a/lib/vdso/Kconfig +++ b/lib/vdso/Kconfig @@ -23,3 +23,13 @@ config VDSO_GETRANDOM select VDSO_DATASTORE help Selected by architectures that support vDSO getrandom(). + +config VDSO_UNALIGNED_PACKED + bool + default !HAVE_EFFICIENT_UNALIGNED_ACCESS + help + Use packed structs rather than memcpy() in include/vdso/unaligned.h + for unaligned memory accesses. Enabled by default when the + architecture does not have efficient unaligned accesses, as GCC may + emit stack spills or out-of-line memcpy() calls instead of inlining + byte shifts. diff --git a/mm/cma.c b/mm/cma.c index a10ea37a261da3..9ec1d1fd5dff50 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -381,6 +381,8 @@ static int __init cma_fixed_reserve(phys_addr_t base, phys_addr_t size) return -EBUSY; } + accept_memory(base, size); + return 0; } @@ -678,6 +680,8 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size, break; } + accept_memory(mlp->base, size); + pr_debug("created region %d: %016llx - %016llx\n", nr, (u64)mlp->base, (u64)mlp->base + size); cmrp = &cma->ranges[nr++]; @@ -1020,7 +1024,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned long count) { struct cma_memrange *cmr; - unsigned long ret = 0; + unsigned long leaked = 0; unsigned long i, pfn; cmr = find_cma_memrange(cma, pages, count); @@ -1029,9 +1033,13 @@ bool cma_release(struct cma *cma, const struct page *pages, pfn = page_to_pfn(pages); for (i = 0; i < count; i++, pfn++) - ret += !put_page_testzero(pfn_to_page(pfn)); + leaked += !page_ref_freeze(pfn_to_page(pfn), 1); - WARN(ret, "%lu pages are still in use!\n", ret); + if (leaked) { + pr_warn_ratelimited("%lu pages are still in use, not freeing CMA region!\n", + leaked); + return true; + } __cma_release_frozen(cma, cmr, pages, count); diff --git a/mm/damon/core.c b/mm/damon/core.c index eb1fcdabc00756..946b28440dff10 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1516,15 +1516,14 @@ static int damos_commit_dests(struct damos_migrate_dests *dst, kfree(dst->node_id_arr); kfree(dst->weight_arr); - dst->node_id_arr = kmalloc_array(src->nr_dests, - sizeof(*dst->node_id_arr), GFP_KERNEL); + dst->node_id_arr = kmalloc_objs(*dst->node_id_arr, + src->nr_dests); if (!dst->node_id_arr) { dst->weight_arr = NULL; return -ENOMEM; } - dst->weight_arr = kmalloc_array(src->nr_dests, - sizeof(*dst->weight_arr), GFP_KERNEL); + dst->weight_arr = kmalloc_objs(*dst->weight_arr, src->nr_dests); if (!dst->weight_arr) { /* ->node_id_arr will be freed by scheme destruction */ return -ENOMEM; @@ -3753,12 +3752,13 @@ static void damon_split_regions_of(struct damon_ctx *ctx, static void damon_split_some_regions(struct damon_ctx *ctx, unsigned long split_step) { - static unsigned long rotation; struct damon_target *t; struct damon_region *r, *next; - unsigned long offset = rotation++ % split_step; + unsigned long offset; unsigned long idx = 0; + offset = ctx->region_split_rotation++ % split_step; + damon_for_each_target(t, ctx) { damon_for_each_region_safe(r, next, t) { unsigned long sz_region, sz_sub; @@ -3795,7 +3795,6 @@ static noinline_for_stack void kdamond_split_regions(struct damon_ctx *ctx) struct damon_target *t; unsigned long nr_regions = 0; unsigned long max_nr_regions = ctx->attrs.max_nr_regions; - static unsigned long last_nr_regions; int nr_subregions = 2; damon_for_each_target(t, ctx) @@ -3811,7 +3810,7 @@ static noinline_for_stack void kdamond_split_regions(struct damon_ctx *ctx) } /* Maybe the middle of the region has different access frequency */ - if (last_nr_regions == nr_regions && + if (ctx->last_nr_regions == nr_regions && nr_regions < max_nr_regions / 3) nr_subregions = 3; @@ -3820,7 +3819,7 @@ static noinline_for_stack void kdamond_split_regions(struct damon_ctx *ctx) ctx->min_region_sz); done: - last_nr_regions = nr_regions; + ctx->last_nr_regions = nr_regions; } /* @@ -4038,8 +4037,8 @@ static int kdamond_fn(void *data) if (ctx->ops.init) ctx->ops.init(ctx); - ctx->regions_score_histogram = kmalloc_array(DAMOS_MAX_SCORE + 1, - sizeof(*ctx->regions_score_histogram), GFP_KERNEL); + ctx->regions_score_histogram = kmalloc_objs(*ctx->regions_score_histogram, + DAMOS_MAX_SCORE + 1); if (!ctx->regions_score_histogram) goto done; diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 8f083611741fdb..637f1bd0c950b2 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1310,7 +1310,10 @@ static ssize_t target_metric_store(struct kobject *kobj, metric_name = &damos_sysfs_qgoal_metric_names[i]; if (sysfs_streq(buf, metric_name->name)) { + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; goal->metric = metric_name->metric; + mutex_unlock(&damon_sysfs_lock); return count; } } diff --git a/mm/filemap.c b/mm/filemap.c index b74bc1e5015c6f..b04be64a5069f4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -227,18 +227,6 @@ void __filemap_remove_folio(struct folio *folio, void *shadow) page_cache_delete(mapping, folio, shadow); } -static void filemap_free_folio(const struct address_space *mapping, - struct folio *folio) -{ - void (*free_folio)(struct folio *); - - free_folio = mapping->a_ops->free_folio; - if (free_folio) - free_folio(folio); - - folio_put_refs(folio, folio_nr_pages(folio)); -} - /** * filemap_remove_folio - Remove folio from page cache. * @folio: The folio. @@ -250,6 +238,7 @@ static void filemap_free_folio(const struct address_space *mapping, void filemap_remove_folio(struct folio *folio) { struct address_space *mapping = folio->mapping; + void (*free_folio)(struct folio *folio); BUG_ON(!folio_test_locked(folio)); spin_lock(&mapping->host->i_lock); @@ -258,9 +247,12 @@ void filemap_remove_folio(struct folio *folio) xa_unlock_irq(&mapping->i_pages); if (mapping_shrinkable(mapping)) inode_lru_list_add(mapping->host); + free_folio = mapping->a_ops->free_folio; spin_unlock(&mapping->host->i_lock); - filemap_free_folio(mapping, folio); + if (free_folio) + free_folio(folio); + folio_put_refs(folio, folio_nr_pages(folio)); } /* @@ -320,6 +312,7 @@ static void page_cache_delete_batch(struct address_space *mapping, void delete_from_page_cache_batch(struct address_space *mapping, struct folio_batch *fbatch) { + void (*free_folio)(struct folio *folio); int i; if (!folio_batch_count(fbatch)) @@ -337,10 +330,16 @@ void delete_from_page_cache_batch(struct address_space *mapping, xa_unlock_irq(&mapping->i_pages); if (mapping_shrinkable(mapping)) inode_lru_list_add(mapping->host); + free_folio = mapping->a_ops->free_folio; spin_unlock(&mapping->host->i_lock); - for (i = 0; i < folio_batch_count(fbatch); i++) - filemap_free_folio(mapping, fbatch->folios[i]); + for (i = 0; i < folio_batch_count(fbatch); i++) { + struct folio *folio = fbatch->folios[i]; + + if (free_folio) + free_folio(folio); + folio_put_refs(folio, folio_nr_pages(folio)); + } } int filemap_check_errors(struct address_space *mapping) @@ -1374,10 +1373,22 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, * return value based on that state without races. * * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive - * waiter, but an exclusive one requires WQ_FLAG_DONE. + * waiter, but an exclusive one must also acquire the bit. */ - if (behavior == EXCLUSIVE) - return wait->flags & WQ_FLAG_DONE ? 0 : -EINTR; + if (behavior == EXCLUSIVE) { + if (wait->flags & WQ_FLAG_DONE) + return 0; + /* + * We might have just been woken up and the waker will not + * wake up anybody else. If we ignore that now, the remaining + * waiters may not get woken up: take the bit now if it is + * still free. + */ + if ((wait->flags & WQ_FLAG_WOKEN) && + !test_and_set_bit(bit_nr, folio_flags(folio, 0))) + return 0; + return -EINTR; + } return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR; } @@ -3297,11 +3308,11 @@ loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start, * @folio - the folio to lock. * @fpin - the pointer to the file we may pin (or is already pinned). * - * This works similar to lock_folio_or_retry in that it can drop the - * mmap_lock. It differs in that it actually returns the folio locked - * if it returns 1 and 0 if it couldn't lock the folio. If we did have - * to drop the mmap_lock then fpin will point to the pinned file and - * needs to be fput()'ed at a later point. + * Returns 1 with the folio locked, or 0 if locking failed. + * + * On both entry and return, a non-NULL *fpin means the fault lock has + * already been dropped and the caller must eventually fput() the file. + * Otherwise the fault lock is still held, including on failure. */ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio, struct file **fpin) @@ -3318,21 +3329,9 @@ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio, return 0; *fpin = maybe_unlock_mmap_for_io(vmf, *fpin); - if (vmf->flags & FAULT_FLAG_KILLABLE) { - if (__folio_lock_killable(folio)) { - /* - * We didn't have the right flags to drop the - * fault lock, but all fault_handlers only check - * for fatal signals if we return VM_FAULT_RETRY, - * so we need to drop the fault lock here and - * return 0 if we don't have a fpin. - */ - if (*fpin == NULL) - release_fault_lock(vmf); - return 0; - } - } else - __folio_lock(folio); + if (vmf->flags & FAULT_FLAG_KILLABLE) + return !__folio_lock_killable(folio); + __folio_lock(folio); return 1; } @@ -3561,7 +3560,7 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) * vma->vm_mm->mmap_lock must be held on entry. * * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock - * may be dropped before doing I/O or by lock_folio_maybe_drop_mmap(). + * may be dropped before doing I/O or when aborting an interrupted wait. * * If our return value does not have VM_FAULT_RETRY set, the mmap_lock * has not been released. @@ -3717,9 +3716,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) out_retry: /* - * We dropped the mmap_lock, we need to return to the fault handler to - * re-find the vma and come back and find our hopefully still populated - * page. + * With fpin set, the fault lock was already dropped. Otherwise it is + * still held. Release invalidate_lock before dropping either protection. */ if (!IS_ERR(folio)) folio_put(folio); @@ -3727,6 +3725,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) filemap_invalidate_unlock_shared(mapping); if (fpin) fput(fpin); + else if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) + release_fault_lock(vmf); return ret | VM_FAULT_RETRY; } EXPORT_SYMBOL(filemap_fault); diff --git a/mm/gup.c b/mm/gup.c index 7d43ce717b2461..2b405cce2ca5ca 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -658,9 +658,6 @@ static struct page *follow_huge_pud(struct vm_area_struct *vma, assert_spin_locked(pud_lockptr(mm, pudp)); - if (!pud_present(pud)) - return NULL; - if ((flags & FOLL_WRITE) && !can_follow_write_pud(pud, pfn_to_page(pfn), vma, flags)) return NULL; @@ -896,15 +893,17 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, } static struct page *follow_pmd_mask(struct vm_area_struct *vma, - unsigned long address, pud_t *pudp, - unsigned int flags, - unsigned long *page_mask) + unsigned long address, pud_t *pudp, pud_t pud, + unsigned int flags, unsigned long *page_mask) { pmd_t *pmd, pmdval; spinlock_t *ptl; struct page *page; struct mm_struct *mm = vma->vm_mm; + if (unlikely(pud_bad(pud))) + return no_page_table(vma, flags, address); + pmd = pmd_offset(pudp, address); pmdval = pmdp_get_lockless(pmd); if (pmd_none(pmdval)) @@ -953,18 +952,23 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, pud = pudp_get(pudp); if (!pud_present(pud)) return no_page_table(vma, flags, address); - if (pud_leaf(pud)) { - ptl = pud_lock(mm, pudp); - page = follow_huge_pud(vma, address, pudp, flags, page_mask); + if (!pud_leaf(pud)) + return follow_pmd_mask(vma, address, pudp, pud, flags, page_mask); + + ptl = pud_lock(mm, pudp); + pud = *pudp; + if (unlikely(!pud_present(pud))) { spin_unlock(ptl); - if (page) - return page; return no_page_table(vma, flags, address); } - if (unlikely(pud_bad(pud))) - return no_page_table(vma, flags, address); + if (unlikely(!pud_leaf(pud))) { + spin_unlock(ptl); + return follow_pmd_mask(vma, address, pudp, pud, flags, page_mask); + } - return follow_pmd_mask(vma, address, pudp, flags, page_mask); + page = follow_huge_pud(vma, address, pudp, flags, page_mask); + spin_unlock(ptl); + return page; } static struct page *follow_p4d_mask(struct vm_area_struct *vma, @@ -3211,6 +3215,9 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages, FOLL_PCI_P2PDMA | FOLL_HONOR_NUMA_FAULT))) return -EINVAL; + if (unlikely(!nr_pages)) + return 0; + if (gup_flags & FOLL_PIN) mm_set_has_pinned_flag(current->mm); @@ -3218,8 +3225,8 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages, might_lock_read(¤t->mm->mmap_lock); start = untagged_addr(start) & PAGE_MASK; - len = nr_pages << PAGE_SHIFT; - if (check_add_overflow(start, len, &end)) + if (check_shl_overflow(nr_pages, PAGE_SHIFT, &len) || + check_add_overflow(start, len, &end)) return -EOVERFLOW; if (end > TASK_SIZE_MAX) return -EFAULT; @@ -3464,7 +3471,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, { unsigned int flags, nr_folios, nr_found; unsigned int i, pgshift = PAGE_SHIFT; - pgoff_t start_idx, end_idx; + pgoff_t start_idx, end_idx, retry_idx; struct folio *folio = NULL; struct folio_batch fbatch; struct hstate *h; @@ -3505,6 +3512,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, * reason, we try to allocate them and add them to the * page cache. */ + retry_idx = start_idx; nr_found = filemap_get_folios_contig(memfd->f_mapping, &start_idx, end_idx, @@ -3517,12 +3525,38 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, for (i = 0; i < nr_found; i++) { folio = fbatch.folios[i]; + /* + * The folio might have been removed from the + * page cache (e.g., truncated or collapsed) + * after the lookup. Recheck under the folio + * lock. + */ + folio_lock(folio); + if (unlikely(folio->mapping != memfd->f_mapping)) { + folio_unlock(folio); + start_idx = retry_idx; + break; + } + if (try_grab_folio(folio, 1, FOLL_PIN)) { + folio_unlock(folio); folio_batch_release(&fbatch); ret = -EINVAL; goto err; } + /* + * fallocate() can leave folios in the + * page cache that were never cleared. + */ + if (!folio_test_uptodate(folio)) { + folio_zero_range(folio, 0, folio_size(folio)); + flush_dcache_folio(folio); + folio_mark_uptodate(folio); + } + retry_idx = folio_next_index(folio); + folio_unlock(folio); + if (nr_folios == 0) *offset = offset_in_folio(folio, start); diff --git a/mm/hmm.c b/mm/hmm.c index 2f1e98c6b6440b..9871d3c3cd0714 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -860,8 +860,8 @@ int hmm_dma_map_alloc(struct device *dev, struct hmm_dma_map *map, return -EOPNOTSUPP; map->dma_entry_size = dma_entry_size; - map->pfn_list = kvcalloc(nr_entries, sizeof(*map->pfn_list), - GFP_KERNEL | __GFP_NOWARN); + map->pfn_list = kvzalloc_objs(*map->pfn_list, nr_entries, + GFP_KERNEL | __GFP_NOWARN); if (!map->pfn_list) return -ENOMEM; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index bd44d58e86845c..eb913acb03b74b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2072,11 +2072,13 @@ void touch_pud(struct vm_area_struct *vma, unsigned long addr, update_mmu_cache_pud(vma, addr, pud); } -int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, - pud_t *dst_pud, pud_t *src_pud, unsigned long addr, - struct vm_area_struct *vma) +int copy_huge_pud(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, + pud_t *dst_pud, pud_t *src_pud, unsigned long addr) { + struct mm_struct *dst_mm = dst_vma->vm_mm; + struct mm_struct *src_mm = src_vma->vm_mm; spinlock_t *dst_ptl, *src_ptl; + struct page *page; pud_t pud; int ret; @@ -2089,11 +2091,20 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, if (unlikely(!pud_trans_huge(pud))) goto out_unlock; - /* - * TODO: once we support anonymous pages, use - * folio_try_dup_anon_rmap_*() and split if duplicating fails. - */ - if (vma_is_cow_mapping(vma) && pud_write(pud)) { + page = vm_normal_page_pud(src_vma, addr, pud); + if (page) { + struct folio *folio = page_folio(page); + + folio_get(folio); + /* + * TODO: once we support anonymous pages, use + * folio_try_dup_anon_rmap_*() and split if duplicating fails. + */ + folio_add_file_rmap_pud(folio, page, dst_vma); + add_mm_counter(dst_mm, mm_counter_file(folio), HPAGE_PUD_NR); + } + + if (vma_is_cow_mapping(src_vma) && pud_write(pud)) { pudp_set_wrprotect(src_mm, addr, src_pud); pud = pud_wrprotect(pud); } @@ -2482,11 +2493,7 @@ static inline void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd) static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t pmdval, struct folio *folio, bool is_present) { - const bool is_device_private = folio_is_device_private(folio); - - /* Present and device private folios are rmappable. */ - if (is_present || is_device_private) - folio_remove_rmap_pmd(folio, &folio->page, vma); + const bool is_device_private = pmd_is_device_private_entry(pmdval); if (folio_test_anon(folio)) { add_mm_counter(mm, MM_ANONPAGES, -HPAGE_PMD_NR); @@ -2501,6 +2508,13 @@ static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma, folio_mark_accessed(folio); } + /* + * Present and device private folios are rmappable. Remove the + * rmap after transferring young+dirty to the folio. + */ + if (is_present || is_device_private) + folio_remove_rmap_pmd(folio, &folio->page, vma); + /* Device private folios are pinned. */ if (is_device_private) folio_put(folio); @@ -2632,15 +2646,11 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, return false; } - /* - * We don't have to worry about the ordering of src and dst - * ptlocks because exclusive mmap_lock prevents deadlock. - */ - old_ptl = __pmd_trans_huge_lock(old_pmd, vma); - if (old_ptl) { - new_ptl = pmd_lockptr(mm, new_pmd); - if (new_ptl != old_ptl) - spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); + old_ptl = pmd_lockptr(mm, old_pmd); + new_ptl = pmd_lockptr(mm, new_pmd); + + double_pt_lock(old_ptl, new_ptl); + if (likely(pmd_is_huge(*old_pmd))) { pmd = pmdp_huge_get_and_clear(mm, old_addr, old_pmd); if (pmd_present(pmd)) force_flush = true; @@ -2669,11 +2679,10 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, set_pmd_at(mm, new_addr, new_pmd, pmd); if (force_flush) flush_pmd_tlb_range(vma, old_addr, old_addr + PMD_SIZE); - if (new_ptl != old_ptl) - spin_unlock(new_ptl); - spin_unlock(old_ptl); + double_pt_unlock(old_ptl, new_ptl); return true; } + double_pt_unlock(old_ptl, new_ptl); return false; } @@ -3040,6 +3049,8 @@ int zap_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, spinlock_t *ptl; pud_t orig_pud; + tlb_change_page_size(tlb, HPAGE_PUD_SIZE); + ptl = __pud_trans_huge_lock(pud, vma); if (!ptl) return 0; @@ -3495,16 +3506,66 @@ void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, __split_huge_pmd(vma, pmd, address, freeze); } -static inline void split_huge_pmd_if_needed(struct vm_area_struct *vma, unsigned long address) +static bool pud_split_required(const struct vm_area_struct *vma, + unsigned long address) { + if (!IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) + return false; + if (IS_ALIGNED(address, HPAGE_PUD_SIZE)) + return false; /* - * If the new address isn't hpage aligned and it could previously - * contain an hugepage: check if we need to split an huge pmd. + * Only selected VMAs support mapping PUDs for now. Lift the + * restriction once this changes. */ - if (!IS_ALIGNED(address, HPAGE_PMD_SIZE) && - range_in_vma(vma, ALIGN_DOWN(address, HPAGE_PMD_SIZE), - ALIGN(address, HPAGE_PMD_SIZE))) - split_huge_pmd_address(vma, address, false); + if (!vma_is_dax(vma) && !vma_test_any(vma, VMA_PFNMAP_BIT, VMA_MIXEDMAP_BIT)) + return false; + return range_in_vma(vma, ALIGN_DOWN(address, HPAGE_PUD_SIZE), + ALIGN(address, HPAGE_PUD_SIZE)); +} + +static bool pmd_split_required(const struct vm_area_struct *vma, + unsigned long address) +{ + if (IS_ALIGNED(address, HPAGE_PMD_SIZE)) + return false; + + return range_in_vma(vma, ALIGN_DOWN(address, HPAGE_PMD_SIZE), + ALIGN(address, HPAGE_PMD_SIZE)); +} + +static void split_huge_leaf(struct vm_area_struct *vma, + unsigned long address) +{ + const bool split_pud = pud_split_required(vma, address); + const bool split_pmd = pmd_split_required(vma, address); + pgd_t *pgd; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + + /* + * mmap, VMA and rmap write locks protect the walk; the split helpers + * take the page table locks. + */ + if (!split_pud && !split_pmd) + return; + + pgd = pgd_offset(vma->vm_mm, address); + if (!pgd_present(*pgd)) + return; + + p4d = p4d_offset(pgd, address); + if (!p4d_present(*p4d)) + return; + + pud = pud_offset(p4d, address); + if (pud_leaf(*pud)) + __split_huge_pud(vma, pud, address); + if (!split_pmd || !pud_present(*pud)) + return; + + pmd = pmd_offset(pud, address); + __split_huge_pmd(vma, pmd, address, false); } void vma_adjust_trans_huge(struct vm_area_struct *vma, @@ -3513,14 +3574,14 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, struct vm_area_struct *next) { /* Check if we need to split start first. */ - split_huge_pmd_if_needed(vma, start); + split_huge_leaf(vma, start); /* Check if we need to split end next. */ - split_huge_pmd_if_needed(vma, end); + split_huge_leaf(vma, end); /* If we're incrementing next->vm_start, we might need to split it. */ if (next) - split_huge_pmd_if_needed(next, end); + split_huge_leaf(next, end); } /* @@ -4522,8 +4583,7 @@ int split_folio_to_list(struct folio *folio, struct list_head *list) * * It is unsafe to call folio_unqueue_deferred_split() until folio refcount is * zero: because even when the list_lru lock is held, a non-empty - * _deferred_list might be in use on deferred_split_scan()'s unlocked - * on-stack list. + * _deferred_list might be in use on deferred_split_scan()'s on-stack list. * * The list_lru sublist is determined by folio's memcg: it is therefore * important to unqueue deferred split before changing folio memcg. @@ -4665,10 +4725,22 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, deferred_split_isolate, &dispose); list_for_each_entry_safe(folio, next, &dispose, _deferred_list) { + struct mem_cgroup *memcg; + struct list_lru_one *lru; bool did_split = false; bool underused = false; + /* + * Sync with deferred_split_folio(), which can requeue the + * folio once list_empty() is true, and sets PG_partially_mapped. + */ + rcu_read_lock(); + memcg = folio_memcg(folio); + lru = list_lru_lock_irq(&deferred_split_lru, folio_nid(folio), + &memcg); list_del_init(&folio->_deferred_list); + list_lru_unlock_irq(lru); + rcu_read_unlock(); if (!folio_test_partially_mapped(folio)) { /* diff --git a/mm/hugetlb.c b/mm/hugetlb.c index da5d04edf7c108..ce9c8e57b8e5c0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -137,6 +137,10 @@ static int __huge_pmd_unshare(struct mmu_gather *tlb, bool check_locks); static void hugetlb_unshare_pmds(struct vm_area_struct *vma, unsigned long start, unsigned long end, bool take_locks); +static void hugetlb_unmap_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, unsigned long start, + unsigned long end, struct folio *folio, + zap_flags_t zap_flags); static struct resv_map *vma_resv_map(struct vm_area_struct *vma); static inline bool subpool_is_free(struct hugepage_subpool *spool) @@ -1293,11 +1297,11 @@ static struct folio *dequeue_hugetlb_folio_node_exact(struct hstate *h, static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nmask) { - unsigned int cpuset_mems_cookie; + unsigned int cpuset_mems_cookie, zonelist_cookie; struct zonelist *zonelist; struct zone *zone; struct zoneref *z; - int node = NUMA_NO_NODE; + int node; /* 'nid' should not be NUMA_NO_NODE. Try to catch any misuse of it and rectifiy. */ if (nid == NUMA_NO_NODE) @@ -1306,10 +1310,16 @@ static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_ zonelist = node_zonelist(nid, gfp_mask); retry_cpuset: + node = NUMA_NO_NODE; cpuset_mems_cookie = read_mems_allowed_begin(); + zonelist_cookie = zonelist_iter_begin(); for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nmask) { struct folio *folio; + /* A rebuild may have shifted a node outside @nmask into this slot. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry_cpuset; + if (!cpuset_zone_allowed(zone, gfp_mask)) continue; /* @@ -1324,7 +1334,8 @@ static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_ if (folio) return folio; } - if (unlikely(read_mems_allowed_retry(cpuset_mems_cookie))) + if (unlikely(read_mems_allowed_retry(cpuset_mems_cookie) || + check_retry_zonelist(zonelist_cookie))) goto retry_cpuset; return NULL; @@ -5153,15 +5164,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, spinlock_t *src_ptl, *dst_ptl; pte_t pte; - dst_ptl = huge_pte_lock(h, mm, dst_pte); + dst_ptl = huge_pte_lockptr(h, mm, dst_pte); src_ptl = huge_pte_lockptr(h, mm, src_pte); - - /* - * We don't have to worry about the ordering of src and dst ptlocks - * because exclusive mmap_lock (or the i_mmap_lock) prevents deadlock. - */ - if (src_ptl != dst_ptl) - spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); + double_pt_lock(dst_ptl, src_ptl); pte = huge_ptep_get_and_clear(mm, old_addr, src_pte, sz); @@ -5190,15 +5195,12 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, set_huge_pte_at(mm, new_addr, dst_pte, pte, sz); } - if (src_ptl != dst_ptl) - spin_unlock(src_ptl); - spin_unlock(dst_ptl); + double_pt_unlock(dst_ptl, src_ptl); } -int move_hugetlb_page_tables(struct vm_area_struct *vma, - struct vm_area_struct *new_vma, - unsigned long old_addr, unsigned long new_addr, - unsigned long len) +unsigned long move_hugetlb_page_tables(struct vm_area_struct *vma, + struct vm_area_struct *new_vma, unsigned long old_addr, + unsigned long new_addr, unsigned long len) { struct hstate *h = hstate_vma(vma); struct address_space *mapping = vma->vm_file->f_mapping; @@ -5228,6 +5230,8 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, for (; old_addr < old_end; old_addr += sz, new_addr += sz) { const unsigned long offset_to_last_entry = (old_addr | last_addr_mask) - old_addr; + const unsigned long offset_to_last_dst_entry = + (new_addr | last_addr_mask) - new_addr; src_pte = hugetlb_walk(vma, old_addr, sz); if (!src_pte) { @@ -5244,6 +5248,24 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, continue; } + /* + * Avoid entering the destination PMD sharing path while holding + * i_mmap_rwsem for write. Leave destination page table + * population to the fault path, which can share the PMD lazily. + */ + if (sz == PMD_SIZE && want_pmd_share(new_vma, new_addr)) { + const unsigned long unmap_size = + min(old_end - old_addr, + offset_to_last_dst_entry + sz); + + hugetlb_unmap_range(&tlb, vma, old_addr, + old_addr + unmap_size, NULL, + ZAP_FLAG_DROP_MARKER); + old_addr += unmap_size - sz; + new_addr += unmap_size - sz; + continue; + } + dst_pte = huge_pte_alloc(mm, new_vma, new_addr, sz); if (!dst_pte) break; @@ -5263,9 +5285,10 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma, return len + old_addr - old_end; } -void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, - unsigned long start, unsigned long end, - struct folio *folio, zap_flags_t zap_flags) +static void hugetlb_unmap_range(struct mmu_gather *tlb, + struct vm_area_struct *vma, unsigned long start, + unsigned long end, struct folio *folio, + zap_flags_t zap_flags) { struct mm_struct *mm = vma->vm_mm; const bool folio_provided = !!folio; @@ -5283,13 +5306,6 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, BUG_ON(start & ~huge_page_mask(h)); BUG_ON(end & ~huge_page_mask(h)); - /* - * This is a hugetlb vma, all the pte entries should point - * to huge page. - */ - tlb_change_page_size(tlb, sz); - tlb_start_vma(tlb, vma); - last_addr_mask = hugetlb_mask_last_page(h); address = start; for (; address < end; address += sz) { @@ -5418,6 +5434,15 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, if (folio_provided) break; } +} + +void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, + unsigned long start, unsigned long end, + struct folio *folio, zap_flags_t zap_flags) +{ + tlb_change_page_size(tlb, huge_page_size(hstate_vma(vma))); + tlb_start_vma(tlb, vma); + hugetlb_unmap_range(tlb, vma, start, end, folio, zap_flags); tlb_end_vma(tlb, vma); huge_pmd_unshare_flush(tlb, vma); @@ -6389,6 +6414,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, return -EEXIST; } + VM_WARN_ON_ONCE(size == PMD_SIZE && hugetlb_pmd_shared(dst_pte)); _dst_pte = make_pte_marker(PTE_MARKER_POISONED); set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte, size); diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 0057fa2a16a891..9aa8af5c8856cc 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -222,10 +222,12 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, VM_WARN_ON_ONCE(!PageTail((const struct page *)addr)); /* - * Remap the tail pages as read-only to catch illegal write - * operation to the tail pages. + * Map the shared tail page writable. A lockless get that read + * a non-zero refcount before the remap can still do its + * cmpxchg after it. The refcount is zero, so the cmpxchg + * fails and leaves the page unchanged. */ - entry = mk_pte(walk->vmemmap_tail, PAGE_KERNEL_RO); + entry = mk_pte(walk->vmemmap_tail, PAGE_KERNEL); } list_add(&page->lru, walk->vmemmap_pages); diff --git a/mm/internal.h b/mm/internal.h index 566cbd2dce4855..e3f92883bf2384 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -589,14 +589,16 @@ void free_pgtables(struct mmu_gather *tlb, struct unmap_desc *desc); void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte); /** - * sync_with_folio_pmd_zap - sync with concurrent zapping of a folio PMD + * sync_with_folio_pmd_zap - sync with concurrent zapping of folios * @mm: The mm_struct. * @pmdp: Pointer to the pmd that was found to be pmd_none(). * * When we find a pmd_none() while unmapping a folio without holding the PTL, - * zap_huge_pmd() may have cleared the PMD but not yet modified the folio to - * indicate that it's unmapped. Skipping the PMD without synchronization could - * make folio unmapping code assume that unmapping failed. + * zap_huge_pmd() may have cleared the PMD but not yet updated the folio + * mapcount, and zap_empty_pte_table() clears the PMD only after the rmaps + * for the table have been removed, but nothing orders the pmd_none() read + * against later mapcount reads. Skipping the PMD without synchronization + * could make folio unmapping code assume that unmapping failed. * * Wait for concurrent zapping to complete by grabbing the PTL. */ @@ -624,6 +626,34 @@ static inline void force_page_cache_readahead(struct address_space *mapping, force_page_cache_ra(&ractl, nr_to_read); } +/* + * Take two page table locks at the same level in address order such that + * we cannot deadlock. + */ +static inline void double_pt_lock(spinlock_t *ptl1, spinlock_t *ptl2) + __acquires(ptl1) + __acquires(ptl2) +{ + if (ptl1 > ptl2) + swap(ptl1, ptl2); + spin_lock(ptl1); + if (ptl1 != ptl2) + spin_lock_nested(ptl2, SINGLE_DEPTH_NESTING); + else + __acquire(ptl2); +} + +static inline void double_pt_unlock(spinlock_t *ptl1, spinlock_t *ptl2) + __releases(ptl1) + __releases(ptl2) +{ + spin_unlock(ptl1); + if (ptl1 != ptl2) + spin_unlock(ptl2); + else + __release(ptl2); +} + unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4b71d010b2aff5..4bbe319ef86fa3 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1904,7 +1904,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign result = SCAN_FAIL; start_pte = pte_offset_map_lock(mm, pmd, haddr, &ptl); - if (!start_pte) /* mmap_lock + page lock should prevent this */ + if (!start_pte) goto drop_folio; /* step 1: check all mapped PTEs are to the right huge page */ @@ -1935,6 +1935,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign } pte_unmap_unlock(start_pte, ptl); + ptl = NULL; mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, haddr, haddr + HPAGE_PMD_SIZE); mmu_notifier_invalidate_range_start(&range); @@ -1952,7 +1953,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign pml = pmd_lock(mm, pmd); start_pte = pte_offset_map_rw_nolock(mm, pmd, haddr, &pgt_pmd, &ptl); - if (!start_pte) /* mmap_lock + page lock should prevent this */ + if (!start_pte) goto abort; if (!pml) spin_lock(ptl); @@ -1994,9 +1995,10 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign /* * Must clear entry, or a racing truncate may re-remove it. * TLB flush can be left until pmdp_collapse_flush() does it. - * PTE dirty? Shmem page is already dirty; file is read-only. */ - clear_ptes(mm, addr, pte, nr_batch_ptes); + ptent = get_and_clear_ptes(mm, addr, pte, nr_batch_ptes); + if (pte_dirty(ptent)) + folio_mark_dirty(folio); folio_remove_rmap_ptes(folio, page, nr_batch_ptes, vma); nr_mapped_ptes += nr_batch_ptes; } @@ -2013,12 +2015,11 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign /* step 4: remove empty page table */ if (!pml) { pml = pmd_lock(mm, pmd); - if (ptl != pml) { + if (ptl != pml) spin_lock_nested(ptl, SINGLE_DEPTH_NESTING); - if (unlikely(!pmd_same(pgt_pmd, pmdp_get_lockless(pmd)))) { - flush_tlb_mm(mm); - goto unlock; - } + if (unlikely(!pmd_same(pgt_pmd, pmdp_get_lockless(pmd)))) { + flush_tlb_mm(mm); + goto unlock; } } pgt_pmd = pmdp_collapse_flush(vma, haddr, pmd); @@ -2230,6 +2231,7 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, struct file *file, pgoff_t start, struct collapse_control *cc) { struct address_space *mapping = file->f_mapping; + const bool is_shmem = shmem_mapping(mapping); struct page *dst; struct folio *folio, *tmp, *new_folio; unsigned long new_pfn = -1; @@ -2238,7 +2240,8 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER); enum scan_result result = SCAN_SUCCEED; int nr_none = 0; - bool is_shmem = shmem_file(file); + bool do_readahead = false; + bool readahead_done = false; /* * MADV_COLLAPSE ignores shmem huge config, so do not check shmem @@ -2256,6 +2259,10 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, mapping_set_update(&xas, mapping); +retry: + result = SCAN_SUCCEED; + do_readahead = false; + xas_set_order(&xas, start, HPAGE_PMD_ORDER); __folio_set_locked(new_folio); if (is_shmem) __folio_set_swapbacked(new_folio); @@ -2320,17 +2327,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, } } else { /* !is_shmem */ if (!folio || xa_is_value(folio)) { - xas_unlock_irq(&xas); - page_cache_sync_readahead(mapping, &file->f_ra, - file, index, - end - index); - /* drain lru cache to help folio_isolate_lru() */ - lru_add_drain(); - folio = filemap_lock_folio(mapping, index); - if (IS_ERR(folio)) { - result = SCAN_FAIL; - goto xa_unlocked; - } + do_readahead = !readahead_done; + result = SCAN_FAIL; + goto xa_locked; } else if (folio_test_dirty(folio)) { /* * This page is dirty because it hasn't @@ -2467,6 +2466,11 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, index += folio_nr_pages(folio); continue; out_unlock: + /* + * The folio may have been unmapped with TTU_BATCH_FLUSH. + * Flush before releasing the lock and our last reference. + */ + try_to_unmap_flush(); folio_unlock(folio); folio_put(folio); goto xa_unlocked; @@ -2477,9 +2481,8 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, xa_unlocked: /* - * If collapse is successful, flush must be done now before copying. - * If collapse is unsuccessful, does flush actually need to be done? - * Do it anyway, to clear the state. + * Flush before copying the folios, or releasing them in rollback. + * This is a no-op if out_unlock already flushed the batch. */ try_to_unmap_flush(); @@ -2653,6 +2656,30 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, new_folio->mapping = NULL; folio_unlock(new_folio); + + /* Readahead may take invalidate_lock; source folios are unlocked. */ + if (do_readahead) { + for (index = start; index < end;) { + folio = filemap_lock_folio(mapping, index); + if (IS_ERR(folio)) { + page_cache_sync_readahead(mapping, &file->f_ra, + file, index, end - index); + folio = filemap_lock_folio(mapping, index); + if (IS_ERR(folio)) { + result = SCAN_FAIL; + goto out_put; + } + } + index = folio_next_index(folio); + folio_unlock(folio); + folio_put(folio); + } + /* Drain the local LRU batch before retrying isolation. */ + lru_add_drain(); + readahead_done = true; + goto retry; + } +out_put: folio_put(new_folio); out: VM_BUG_ON(!list_empty(&pagelist)); diff --git a/mm/ksm.c b/mm/ksm.c index dbfb8f98b18925..d24b129932bf79 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -475,6 +476,7 @@ static void advisor_stop_scan(void) #ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes = 1; +/* Number of allocated stable and unstable tree roots. */ static int ksm_nr_node_ids = 1; #else #define ksm_merge_across_nodes 1U @@ -1463,6 +1465,15 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, dec_mm_counter(mm, MM_ANONPAGES); } + /* Preserve soft-dirty and uffd protection when replacing the page. */ + if (pte_soft_dirty(orig_pte)) + newpte = pte_mksoft_dirty(newpte); + if (pte_uffd(orig_pte)) { + newpte = pte_mkuffd(newpte); + if (userfaultfd_rwp(vma)) + newpte = pte_modify(newpte, PAGE_NONE); + } + flush_cache_page(vma, addr, pte_pfn(ptep_get(ptep))); /* * No need to notify as we are replacing a read only page with another @@ -3136,24 +3147,52 @@ void __ksm_exit(struct mm_struct *mm) trace_ksm_exit(mm); } -struct folio *ksm_might_need_to_copy(struct folio *folio, - struct vm_area_struct *vma, unsigned long addr) +static bool folio_anon_rmap_compatible(const struct folio *folio, + const struct page *page, struct vm_area_struct *vma, + unsigned long addr) { - struct page *page = folio_page(folio, 0); - struct anon_vma *anon_vma = folio_anon_vma(folio); - struct folio *new_folio; + const struct anon_vma *anon_vma = folio_anon_vma(folio); + struct anon_vma_chain *avc; - if (folio_test_large(folio)) - return folio; + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio); + VM_WARN_ON_ONCE_FOLIO(page_folio(page) != folio, folio); + VM_WARN_ON_ONCE_FOLIO(folio_test_ksm(folio), folio); + vma_assert_stabilised(vma); + + if (!anon_vma) + return true; + if (page_pgoff(folio, page) != linear_anon_page_index(vma, addr)) + return false; + + /* + * Careful: anon_vma might have been freed, so we cannot safely + * dereference it. Add a fast path before we walk the anon_vma chain. + */ + if (anon_vma == vma->anon_vma || anon_vma == vma->anon_vma->root) + return true; + list_for_each_entry(avc, &vma->anon_vma_chain, same_vma) { + if (avc->anon_vma == anon_vma) + return true; + } + return false; +} + +struct folio *ksm_might_need_to_copy(struct folio *folio, struct page *page, + struct vm_area_struct *vma, unsigned long addr) +{ + struct folio *new_folio; + + /* + * A KSM folio is small, but the slot that it left behind can be swapped + * in as a part of a large folio by one of the processes that shared it. + * So test, and copy, the page of the slot. + */ if (folio_test_ksm(folio)) { if (folio_stable_node(folio) && !(ksm_run & KSM_RUN_UNMERGE)) return folio; /* no need to copy it */ - } else if (!anon_vma) { - return folio; /* no need to copy it */ - } else if (folio->index == linear_anon_page_index(vma, addr) && - anon_vma->root == vma->anon_vma->root) { + } else if (folio_anon_rmap_compatible(folio, page, vma, addr)) { return folio; /* still no need to copy it */ } if (PageHWPoison(page)) @@ -3636,14 +3675,13 @@ static ssize_t merge_across_nodes_store(struct kobject *kobj, else { root_stable_tree = buf; root_unstable_tree = buf + nr_node_ids; + ksm_nr_node_ids = nr_node_ids; /* Stable tree is empty but not the unstable */ root_unstable_tree[0] = one_unstable_tree[0]; } } - if (!err) { + if (!err) ksm_merge_across_nodes = knob; - ksm_nr_node_ids = knob ? 1 : nr_node_ids; - } } mutex_unlock(&ksm_thread_mutex); diff --git a/mm/madvise.c b/mm/madvise.c index 75b409e97dbf24..0214efd2a014f9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -158,7 +158,7 @@ static int madvise_update_vma(vm_flags_t new_flags, bool set_new_anon_name = madv_behavior->behavior == __MADV_SET_ANON_VMA_NAME; VMA_ITERATOR(vmi, madv_behavior->mm, range->start); - if (vma_flags_same_mask(&vma->flags, new_vma_flags) && + if (vma_flags_same_pair(&vma->flags, &new_vma_flags) && (!set_new_anon_name || anon_vma_name_eq(anon_vma_name(vma), anon_name))) return 0; @@ -177,7 +177,10 @@ static int madvise_update_vma(vm_flags_t new_flags, /* vm_flags is protected by the mmap_lock held in write mode. */ vma_start_write(vma); - vma->flags = new_vma_flags; + if (set_new_anon_name) + return replace_anon_vma_name(vma, anon_name); + + vma_overwrite_flags(vma, new_vma_flags); /* * If the vma become good for khugepaged to scan, * register it here without waiting a page fault that @@ -186,9 +189,6 @@ static int madvise_update_vma(vm_flags_t new_flags, if (vma_flags_test(&new_vma_flags, VMA_HUGEPAGE_BIT)) khugepaged_enter_vma(vma, vma_flags_to_legacy(new_vma_flags)); - if (set_new_anon_name) - return replace_anon_vma_name(vma, anon_name); - return 0; } @@ -756,6 +756,15 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, if (folio_test_swapcache(folio) || folio_test_dirty(folio)) { if (!folio_trylock(folio)) continue; + /* + * KSM folios can gain new mappings at any time, so we must + * not clear their dirty flag. + */ + if (folio_test_ksm(folio)) { + folio_unlock(folio); + continue; + } + /* * If we have a large folio at this point, we know it is * fully mapped so if its mapcount is the same as its diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a05d9a8baa1b6b..84f4a8fd4d16f1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2457,7 +2457,10 @@ static void high_work_func(struct work_struct *work) struct mem_cgroup *memcg; memcg = container_of(work, struct mem_cgroup, high_work); + if (!css_tryget_online(&memcg->css)) + return; reclaim_high(memcg, MEMCG_CHARGE_BATCH, GFP_KERNEL); + css_put(&memcg->css); } static void high_irq_work_func(struct irq_work *work) @@ -4463,6 +4466,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) page_counter_set_min(&memcg->memory, 0); page_counter_set_low(&memcg->memory, 0); + page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX); + page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); zswap_memcg_offline_cleanup(memcg); diff --git a/mm/memfd.c b/mm/memfd.c index 0f6fff004f5e4c..0e3ff3eebfa829 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -482,6 +482,8 @@ struct file *memfd_alloc_file(const char *name, unsigned int flags) } file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; + /* a regular file like any other: POSIX.1-2008/SUSv4 Section XSI 2.9.7 */ + file->f_mode |= FMODE_ATOMIC_POS; file->f_flags |= O_LARGEFILE; if (flags & MFD_NOEXEC_SEAL) { diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 25e121851b5862..8eda313cf61925 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -572,21 +572,14 @@ static struct memory_tier *set_node_memory_tier(int node) return memtier; } -static void destroy_memory_tier(struct memory_tier *memtier) +static struct memory_tier *clear_node_memory_tier(int node) { - list_del(&memtier->list); - device_unregister(&memtier->dev); -} - -static bool clear_node_memory_tier(int node) -{ - bool cleared = false; pg_data_t *pgdat; struct memory_tier *memtier; pgdat = NODE_DATA(node); if (!pgdat) - return false; + return NULL; /* * Make sure that anybody looking at NODE_DATA who finds @@ -604,14 +597,10 @@ static bool clear_node_memory_tier(int node) synchronize_rcu(); memtype = node_memory_types[node].memtype; node_clear(node, memtype->nodes); - if (nodes_empty(memtype->nodes)) { + if (nodes_empty(memtype->nodes)) list_del_init(&memtype->tier_sibling); - if (list_empty(&memtier->memory_types)) - destroy_memory_tier(memtier); - } - cleared = true; } - return cleared; + return memtier; } static void release_memtype(struct kref *kref) @@ -884,13 +873,21 @@ static int __meminit memtier_hotplug_callback(struct notifier_block *self, { struct memory_tier *memtier; struct node_notify *nn = _arg; + bool empty = false; switch (action) { case NODE_REMOVED_LAST_MEMORY: mutex_lock(&memory_tier_lock); - if (clear_node_memory_tier(nn->nid)) + memtier = clear_node_memory_tier(nn->nid); + if (memtier) { + empty = list_empty(&memtier->memory_types); + if (empty) + list_del(&memtier->list); establish_demotion_targets(); + } mutex_unlock(&memory_tier_lock); + if (empty) + device_unregister(&memtier->dev); break; case NODE_ADDED_FIRST_MEMORY: mutex_lock(&memory_tier_lock); diff --git a/mm/memory.c b/mm/memory.c index 0fb676dd2bd639..ec3d9d99ccee2f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1463,7 +1463,6 @@ copy_pud_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, unsigned long end) { struct mm_struct *dst_mm = dst_vma->vm_mm; - struct mm_struct *src_mm = src_vma->vm_mm; pud_t *src_pud, *dst_pud; unsigned long next; @@ -1477,8 +1476,7 @@ copy_pud_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, int err; VM_BUG_ON_VMA(next-addr != HPAGE_PUD_SIZE, src_vma); - err = copy_huge_pud(dst_mm, src_mm, - dst_pud, src_pud, addr, src_vma); + err = copy_huge_pud(dst_vma, src_vma, dst_pud, src_pud, addr); if (err == -ENOMEM) return -ENOMEM; if (!err) @@ -2036,6 +2034,15 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, } } while (pte += nr, addr += PAGE_SIZE * nr, addr != end); + add_mm_rss_vec(mm, rss); + lazy_mmu_mode_disable(); + + /* Do the actual TLB flush before dropping ptl */ + if (force_flush) { + tlb_flush_mmu_tlbonly(tlb); + tlb_flush_rmaps(tlb, vma); + } + /* * Fast path: try to hold the pmd lock and unmap the PTE page. * @@ -2043,18 +2050,12 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, * to hold the pmd lock failed, then we need to recheck all pte entries * to ensure they are still none, thereby preventing the pte entries * from being repopulated by another thread. + * + * Clear the PMD after the rmaps for the table have been removed, in case + * an incorrect mapcount is observed after unmapping the folio. */ if (can_reclaim_pt && direct_reclaim && addr == end) direct_reclaim = zap_empty_pte_table(mm, pmd, ptl, &pmdval); - - add_mm_rss_vec(mm, rss); - lazy_mmu_mode_disable(); - - /* Do the actual TLB flush before dropping ptl */ - if (force_flush) { - tlb_flush_mmu_tlbonly(tlb); - tlb_flush_rmaps(tlb, vma); - } pte_unmap_unlock(start_pte, ptl); /* @@ -2101,13 +2102,15 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, addr = next; continue; } + /* We already synchronized with concurrent zapping. */ + if (pmd_none(*pmd)) { + addr = next; + continue; + } /* fall through */ - } else if (details && details->single_folio && - folio_test_pmd_mappable(details->single_folio) && - next - addr == HPAGE_PMD_SIZE && pmd_none(*pmd)) { - sync_with_folio_pmd_zap(tlb->mm, pmd); - } - if (pmd_none(*pmd)) { + } else if (pmd_none(*pmd)) { + if (details && details->single_folio) + sync_with_folio_pmd_zap(tlb->mm, pmd); addr = next; continue; } @@ -3763,6 +3766,13 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, return 0; } + /* + * __copy_from_user_inatomic() only works as expected for local faults. + * Reject remote faults. + */ + if (unlikely(mm != current->mm)) + return -EFAULT; + /* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by @@ -4088,6 +4098,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) folio_put(old_folio); delayacct_wpcopy_end(); + if (err == -EFAULT) + return VM_FAULT_SIGBUS; return err == -EHWPOISON ? VM_FAULT_HWPOISON : 0; } kmsan_copy_page_meta(&new_folio->page, vmf->page); @@ -4120,8 +4132,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (unlikely(unshare)) { if (pte_soft_dirty(vmf->orig_pte)) entry = pte_mksoft_dirty(entry); - if (pte_uffd(vmf->orig_pte)) + if (pte_uffd(vmf->orig_pte)) { entry = pte_mkuffd(entry); + if (userfaultfd_rwp(vma)) + entry = pte_modify(entry, PAGE_NONE); + } } else { entry = maybe_mkwrite(pte_mkdirty(entry), vma); } @@ -4642,8 +4657,8 @@ EXPORT_SYMBOL_GPL(unmap_mapping_pages); void unmap_mapping_range(struct address_space *mapping, loff_t const holebegin, loff_t const holelen, int even_cows) { - pgoff_t hba = (pgoff_t)(holebegin) >> PAGE_SHIFT; - pgoff_t hlen = ((pgoff_t)(holelen) + PAGE_SIZE - 1) >> PAGE_SHIFT; + pgoff_t hba = (u64)holebegin >> PAGE_SHIFT; + pgoff_t hlen = ((u64)holelen + PAGE_SIZE - 1) >> PAGE_SHIFT; /* Check for overflow. */ if (sizeof(holelen) > sizeof(hlen)) { @@ -4933,6 +4948,34 @@ static void check_swap_exclusive(struct folio *folio, swp_entry_t entry, } while (--nr_pages); } +/* + * Get the address range in which a folio might be mapped, assuming its pages + * are mapped consecutively and the folio page at the given idx is mapped at + * the given address. + */ +static void folio_pte_range(const struct folio *folio, + const struct vm_area_struct *vma, unsigned long addr, + unsigned long idx, unsigned long *start, unsigned long *end) +{ + /* Stay within the page table and VMA boundaries. */ + const unsigned long pmd_start = addr & PMD_MASK; + const unsigned long pmd_end = pmd_start + PMD_SIZE; + const unsigned long lower = max(pmd_start, vma->vm_start); + /* + * We cannot use pmd_addr_end(), as it does not clamp reliably. To + * avoid wraparounds, compute using the inclusive end. + */ + const unsigned long upper = min(pmd_end - 1, vma->vm_end - 1) + 1; + const unsigned long offset = idx << PAGE_SHIFT; + + /* + * Avoid start/end addresses wrapping by not adding/subtracting more + * than the lower/upper limits would allow. + */ + *start = addr - min(addr - lower, offset); + *end = addr + min(upper - addr, folio_size(folio) - offset); +} + /* * We enter with either the VMA lock or the mmap_lock held (see * FAULT_FLAG_VMA_LOCK), and pte mapped but not yet locked. @@ -5089,7 +5132,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) * folio->index of non-ksm folios would be nonlinear inside the * anon VMA -- the ksm flag is lost on actual swapout. */ - folio = ksm_might_need_to_copy(folio, vma, vmf->address); + folio = ksm_might_need_to_copy(folio, page, vma, vmf->address); if (unlikely(!folio)) { ret = VM_FAULT_OOM; folio = swapcache; @@ -5121,16 +5164,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) address = vmf->address; ptep = vmf->pte; if (folio_test_large(folio) && folio_test_swapcache(folio)) { - int nr = folio_nr_pages(folio); - unsigned long idx = folio_page_idx(folio, page); - unsigned long folio_start = address - idx * PAGE_SIZE; - unsigned long folio_end = folio_start + nr * PAGE_SIZE; + const int nr = folio_nr_pages(folio); + const unsigned long idx = folio_page_idx(folio, page); + unsigned long folio_start, folio_end; pte_t *folio_ptep; pte_t folio_pte; - if (unlikely(folio_start < max(address & PMD_MASK, vma->vm_start))) - goto check_folio; - if (unlikely(folio_end > pmd_addr_end(address, vma->vm_end))) + folio_pte_range(folio, vma, address, idx, &folio_start, + &folio_end); + if (unlikely((folio_end - folio_start) >> PAGE_SHIFT != nr)) goto check_folio; folio_ptep = vmf->pte - idx; @@ -5271,7 +5313,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (unlikely(folio != swapcache)) { folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); - folio_put_swap(swapcache, NULL); + folio_put_swap(swapcache, + folio_file_page(swapcache, swp_offset(entry))); } else if (!folio_test_anon(folio)) { /* * We currently only expect !anon folios that are fully @@ -6280,16 +6323,11 @@ static void numa_rebuild_large_mapping(struct vm_fault *vmf, struct vm_area_stru struct folio *folio, pte_t fault_pte, bool ignore_writable, bool pte_write_upgrade) { - int nr = pte_pfn(fault_pte) - folio_pfn(folio); + const unsigned long idx = pte_pfn(fault_pte) - folio_pfn(folio); unsigned long start, end, addr = vmf->address; - unsigned long addr_start = addr - (nr << PAGE_SHIFT); - unsigned long pt_start = ALIGN_DOWN(addr, PMD_SIZE); pte_t *start_ptep; - /* Stay within the VMA and within the page table. */ - start = max3(addr_start, pt_start, vma->vm_start); - end = min3(addr_start + folio_size(folio), pt_start + PMD_SIZE, - vma->vm_end); + folio_pte_range(folio, vma, addr, idx, &start, &end); start_ptep = vmf->pte - ((addr - start) >> PAGE_SHIFT); /* Restore all PTEs' mapping of the large folio */ @@ -6635,9 +6673,12 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * VM_UFFD_RWP VMA, a protnone PTE without the uffd bit is * NUMA hinting and must still fall through to do_numa_page(). */ - if (userfaultfd_pte_rwp(vmf->vma, vmf->orig_pte)) - return do_uffd_rwp(vmf); - return do_numa_page(vmf); + if (userfaultfd_pte_rwp(vmf->vma, vmf->orig_pte)) { + if (!(vmf->flags & FAULT_FLAG_UNSHARE)) + return do_uffd_rwp(vmf); + } else { + return do_numa_page(vmf); + } } spin_lock(vmf->ptl); @@ -6950,8 +6991,12 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, lru_gen_exit_fault(); - /* If the mapping is droppable, then errors due to OOM aren't fatal. */ - if (is_droppable) + /* + * If the mapping is droppable, then errors due to OOM aren't fatal: the + * task returns to user mode, handles its signals and tries again. A + * fault from kernel mode has no such return, so it must see the error. + */ + if (is_droppable && (flags & FAULT_FLAG_USER)) ret &= ~VM_FAULT_OOM; if (flags & FAULT_FLAG_USER) { diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c9cc42e54f05d4..b9f02bc6ed0d2e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -461,6 +461,22 @@ static unsigned long find_biggest_section_pfn(struct zone *zone, return 0; } +/* + * The page allocator checks pages against the span of their zone while the + * zone is resized, see page_outside_zone_boundaries(). It must not see the + * new value of one field together with the old value of the other one. + */ +static void zone_set_span(struct zone *zone, unsigned long start_pfn, + unsigned long spanned_pages) +{ + unsigned long flags; + + write_seqlock_irqsave(&zone->span_seqlock, flags); + zone->zone_start_pfn = start_pfn; + zone->spanned_pages = spanned_pages; + write_sequnlock_irqrestore(&zone->span_seqlock, flags); +} + static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { @@ -475,13 +491,10 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, */ pfn = find_smallest_section_pfn(zone, end_pfn, zone_end_pfn(zone)); - if (pfn) { - zone->spanned_pages = zone_end_pfn(zone) - pfn; - zone->zone_start_pfn = pfn; - } else { - zone->zone_start_pfn = 0; - zone->spanned_pages = 0; - } + if (pfn) + zone_set_span(zone, pfn, zone_end_pfn(zone) - pfn); + else + zone_set_span(zone, 0, 0); } else if (zone_end_pfn(zone) == end_pfn) { /* * If the section is biggest section in the zone, it need @@ -492,11 +505,10 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, pfn = find_biggest_section_pfn(zone, zone->zone_start_pfn, start_pfn); if (pfn) - zone->spanned_pages = pfn - zone->zone_start_pfn + 1; - else { - zone->zone_start_pfn = 0; - zone->spanned_pages = 0; - } + zone_set_span(zone, zone->zone_start_pfn, + pfn - zone->zone_start_pfn + 1); + else + zone_set_span(zone, 0, 0); } } @@ -684,12 +696,12 @@ static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages) static void __meminit resize_zone_range(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages) { - unsigned long old_end_pfn = zone_end_pfn(zone); + unsigned long end_pfn = max(start_pfn + nr_pages, zone_end_pfn(zone)); - if (zone_is_empty(zone) || start_pfn < zone->zone_start_pfn) - zone->zone_start_pfn = start_pfn; + if (!zone_is_empty(zone) && start_pfn > zone->zone_start_pfn) + start_pfn = zone->zone_start_pfn; - zone->spanned_pages = max(start_pfn + nr_pages, old_end_pfn) - zone->zone_start_pfn; + zone_set_span(zone, start_pfn, end_pfn - start_pfn); } static void __meminit resize_pgdat_range(struct pglist_data *pgdat, unsigned long start_pfn, @@ -1832,6 +1844,13 @@ static int scan_movable_pages(unsigned long start, unsigned long end, if (PageOffline(page) && page_count(page)) return -EBUSY; + /* + * A page that was allocated, but was not a slab page yet, when + * its pageblock was isolated. + */ + if (PageSlab(page)) + return -EBUSY; + folio = page_folio(page); if (!folio_test_hugetlb(folio)) continue; diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 0884c629670dd6..c7d4d149c9b883 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -246,7 +246,7 @@ int mempolicy_set_node_perf(unsigned int node, struct access_coordinate *coords) int i; bw_val = min(coords->read_bandwidth, coords->write_bandwidth); - new_bw = kcalloc(nr_node_ids, sizeof(unsigned int), GFP_KERNEL); + new_bw = kzalloc_objs(unsigned int, nr_node_ids); if (!new_bw) return -ENOMEM; @@ -2176,6 +2176,7 @@ unsigned int mempolicy_slab_node(void) case MPOL_PREFERRED_MANY: { struct zoneref *z; + struct zone *zone; /* * Follow bind policy behavior and start allocation at the @@ -2186,7 +2187,8 @@ unsigned int mempolicy_slab_node(void) zonelist = &NODE_DATA(node)->node_zonelists[ZONELIST_FALLBACK]; z = first_zones_zonelist(zonelist, highest_zoneidx, &policy->nodes); - return zonelist_zone(z) ? zonelist_node_idx(z) : node; + zone = zonelist_zone(z); + return zone ? zone_to_nid(zone) : node; } case MPOL_LOCAL: return node; @@ -3085,7 +3087,7 @@ int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, node_zonelist(thisnid, GFP_HIGHUSER), gfp_zone(GFP_HIGHUSER), &pol->nodes); - polnid = zonelist_node_idx(z); + polnid = zone_to_nid(zonelist_zone(z)); break; default: @@ -3372,11 +3374,11 @@ void __init numa_policy_init(void) policy_cache = kmem_cache_create("numa_policy", sizeof(struct mempolicy), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, NULL); sn_cache = kmem_cache_create("shared_policy_node", sizeof(struct sp_node), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, NULL); for_each_node(nid) { preferred_node_policy[nid] = (struct mempolicy) { diff --git a/mm/migrate.c b/mm/migrate.c index 7bdcdb57652f8f..875079464930a4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2461,7 +2461,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, mmap_read_lock(mm); for (i = 0; i < nr_pages; i++) { - unsigned long addr = (unsigned long)(*pages); + unsigned long addr = (unsigned long)untagged_addr_remote(mm, *pages); struct vm_area_struct *vma; struct folio_walk fw; struct folio *folio; @@ -2756,6 +2756,7 @@ int migrate_misplaced_folio(struct folio *folio, int node) pg_data_t *pgdat = NODE_DATA(node); int nr_remaining; unsigned int nr_succeeded; + int src_node = folio_nid(folio); LIST_HEAD(migratepages); struct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio); struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); @@ -2770,7 +2771,7 @@ int migrate_misplaced_folio(struct folio *folio, int node) count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); count_memcg_events(memcg, NUMA_PAGE_MIGRATE, nr_succeeded); if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) - && !node_is_toptier(folio_nid(folio)) + && !node_is_toptier(src_node) && node_is_toptier(node)) mod_lruvec_state(lruvec, PGPROMOTE_SUCCESS, nr_succeeded); } diff --git a/mm/mlock.c b/mm/mlock.c index 67ae9b18b92351..1c70a782939442 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -432,14 +432,14 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma, } vma_start_write(vma); - vma_flags_reset_once(vma, &walk_flags); + vma_overwrite_flags(vma, walk_flags); lru_add_drain(); walk_page_range_vma(vma, start, end, &mlock_walk_ops, (void *)lock); lru_add_drain(); if (lock) - vma_flags_reset_once(vma, new_vma_flags); + vma_overwrite_flags(vma, *new_vma_flags); } /* @@ -494,7 +494,7 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma, vma_flags_test(&old_vma_flags, VMA_LOCKED_BIT)) { /* No work to do, and mlocking twice would be wrong */ vma_start_write(vma); - vma->flags = *new_vma_flags; + vma_overwrite_flags(vma, *new_vma_flags); } else { mlock_vma_pages_range(vma, start, end, new_vma_flags); } diff --git a/mm/mm_init.c b/mm/mm_init.c index 2a0e782a151d82..d99af80ec75201 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2478,8 +2478,6 @@ void __init memblock_free_pages(unsigned long pfn, unsigned int order) return; } - /* pages were reserved and not allocated */ - clear_page_tag_ref(page); __free_pages_core(page, order, MEMINIT_EARLY); } diff --git a/mm/mmap.c b/mm/mmap.c index 148ba01c03739f..7618e72766a522 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1713,8 +1713,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) LIST_HEAD(uf); VMA_ITERATOR(vmi, mm, 0); - if (mmap_write_lock_killable(oldmm)) - return -EINTR; + mmap_assert_write_locked(oldmm); flush_cache_dup_mm(oldmm); uprobe_dup_mmap(oldmm, mm); /* @@ -1725,11 +1724,6 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) /* No ordering required: file already has been exposed. */ dup_mm_exe_file(mm, oldmm); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; - /* Use __mt_dup() to efficiently build an identical maple tree. */ retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL); if (unlikely(retval)) diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index 83b7d3ded0dc7b..834bbf86e00442 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -13,6 +13,8 @@ #include #include +#include "internal.h" + EXPORT_TRACEPOINT_SYMBOL(mmap_lock_start_locking); EXPORT_TRACEPOINT_SYMBOL(mmap_lock_acquire_returned); EXPORT_TRACEPOINT_SYMBOL(mmap_lock_released); @@ -428,21 +430,53 @@ static struct vm_area_struct *lock_next_vma_under_mmap_lock(struct mm_struct *mm return vma; } -struct vm_area_struct *lock_next_vma(struct mm_struct *mm, - struct vma_iterator *vmi, +/* Is there no VMA in [start, last]? */ +static bool vma_range_is_empty(struct mm_struct *mm, unsigned long start, + unsigned long last) +{ + VMA_ITERATOR(vmi, mm, start); + + return !vma_iter_load(&vmi) && vma_iter_end(&vmi) - 1 >= last; +} + +/* Might the VMA tree have been modified since last mm speculation? */ +static bool vma_rcu_iter_maybe_changed(const struct vma_rcu_iter *rvmi) +{ + return (rvmi->mm_wr_seq & 1) || /* Odd implies write-lock. */ + mmap_lock_speculate_retry(rvmi->mm, rvmi->mm_wr_seq); +} + +/* Could the VMA iterator have skipped a VMA due to the tree changing? */ +static bool vma_rcu_iter_may_have_skipped(const struct vma_rcu_iter *rvmi, + unsigned long from, unsigned long to) +{ + return vma_rcu_iter_maybe_changed(rvmi) && + !vma_range_is_empty(rvmi->mm, from, to); +} + +struct vm_area_struct *lock_next_vma(struct vma_rcu_iter *rvmi, unsigned long from_addr) { + struct mm_struct *mm = rvmi->mm; + struct vma_iterator *vmi = rvmi->vmi; struct vm_area_struct *vma; - unsigned int mm_wr_seq; - bool mmap_unlocked; RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "no rcu read lock held"); retry: - /* Start mmap_lock speculation in case we need to verify the vma later */ - mmap_unlocked = mmap_lock_speculate_try_begin(mm, &mm_wr_seq); + /* Only trust the iterator's position if the tree cannot have changed. */ + if (vma_rcu_iter_maybe_changed(rvmi)) { + vma_iter_set(vmi, from_addr); + mmap_lock_speculate_try_begin(mm, &rvmi->mm_wr_seq); + } vma = vma_next(vmi); - if (!vma) - return NULL; + if (!vma) { + /* No reason to fallback if nothing left in range. */ + if (!vma_rcu_iter_may_have_skipped(rvmi, from_addr, ULONG_MAX)) + return NULL; + + rcu_read_unlock(); + goto fallback; + } vma = vma_start_read(mm, vma); if (IS_ERR_OR_NULL(vma)) { @@ -471,14 +505,9 @@ struct vm_area_struct *lock_next_vma(struct mm_struct *mm, * installed ahead of it. Otherwise we might observe a gap that should * not be there. */ - if (from_addr < vma->vm_start) { - /* Verify only if the address space might have changed since vma lookup. */ - if (!mmap_unlocked || mmap_lock_speculate_retry(mm, mm_wr_seq)) { - vma_iter_set(vmi, from_addr); - if (vma != vma_next(vmi)) - goto fallback_unlock; - } - } + if (from_addr < vma->vm_start && + vma_rcu_iter_may_have_skipped(rvmi, from_addr, vma->vm_start - 1)) + goto fallback_unlock; return vma; diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index df69ba6e797f76..a7bae5de5fedc1 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -569,16 +569,25 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; - int ret; + const bool has_itree = subscriptions->has_itree; + int ret = 0; - if (subscriptions->has_itree) { + if (has_itree) { ret = mn_itree_invalidate(subscriptions, range); if (ret) return ret; } if (!hlist_empty(&subscriptions->list)) - return mn_hlist_invalidate_range_start(subscriptions, range); - return 0; + ret = mn_hlist_invalidate_range_start(subscriptions, range); + + /* + * On error, the non-blocking caller is not allowed to call + * invalidate_range_end(), as in mn_itree_invalidate(). + */ + if (ret && has_itree && !mmu_notifier_range_blockable(range)) + mn_itree_inv_end(subscriptions); + + return ret; } static void @@ -938,7 +947,6 @@ static int __mmu_interval_notifier_insert( struct mmu_notifier_subscriptions *subscriptions, unsigned long start, unsigned long length, const struct mmu_interval_notifier_ops *ops) { - interval_sub->mm = mm; interval_sub->ops = ops; RB_CLEAR_NODE(&interval_sub->interval_tree.rb); interval_sub->interval_tree.start = start; @@ -955,8 +963,12 @@ static int __mmu_interval_notifier_insert( if (WARN_ON(atomic_read(&mm->mm_users) <= 0)) return -EINVAL; - /* pairs with mmdrop in mmu_interval_notifier_remove() */ + /* + * Pairs with mmdrop in mmu_interval_notifier_remove(). Drivers take a + * non-NULL ->mm for "registered", so set it only with the reference. + */ mmgrab(mm); + interval_sub->mm = mm; /* * If some invalidate_range_start/end region is going on in parallel diff --git a/mm/mmzone.c b/mm/mmzone.c index 9cc9ef588580d2..65880396f10445 100644 --- a/mm/mmzone.c +++ b/mm/mmzone.c @@ -43,13 +43,14 @@ struct zone *next_zone(struct zone *zone) return zone; } -static inline int zref_in_nodemask(struct zoneref *zref, - const nodemask_t *nodes) +/* A NULL zone terminates the zonelist, so it ends the search. */ +static inline bool zone_in_nodemask(const struct zone *zone, + const nodemask_t *nodes) { #ifdef CONFIG_NUMA - return node_isset(zonelist_node_idx(zref), *nodes); + return !zone || node_isset(zone_to_nid(zone), *nodes); #else - return 1; + return true; #endif /* CONFIG_NUMA */ } @@ -67,7 +68,7 @@ struct zoneref *__next_zones_zonelist(struct zoneref *z, z++; else while (zonelist_zone_idx(z) > highest_zoneidx || - (zonelist_zone(z) && !zref_in_nodemask(z, nodes))) + !zone_in_nodemask(zonelist_zone(z), nodes)) z++; return z; diff --git a/mm/mprotect.c b/mm/mprotect.c index 754333698c1ea2..e18d4e12fc3415 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -833,7 +833,7 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb, * held in write mode. */ vma_start_write(vma); - vma_flags_reset_once(vma, &new_vma_flags); + vma_overwrite_flags(vma, new_vma_flags); if (vma_wants_manual_pte_write_upgrade(vma)) mm_cp_flags |= MM_CP_TRY_CHANGE_WRITABLE; vma_set_page_prot(vma); diff --git a/mm/mremap.c b/mm/mremap.c index 0d06d7f37f19a1..70b7264aa6bf5c 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -87,7 +87,7 @@ static pud_t *get_old_pud(struct mm_struct *mm, unsigned long addr) return NULL; pud = pud_offset(p4d, addr); - if (pud_none_or_clear_bad(pud)) + if (!pud_trans_huge(*pud) && pud_none_or_clear_bad(pud)) return NULL; return pud; @@ -202,7 +202,7 @@ static int move_ptes(struct pagetable_move_control *pmc, struct mm_struct *mm = vma->vm_mm; pte_t *old_ptep, *new_ptep; pte_t old_pte, pte; - pmd_t dummy_pmdval; + pmd_t old_pmdval, new_pmdval; spinlock_t *old_ptl, *new_ptl; bool force_flush = false; unsigned long old_addr = pmc->old_addr; @@ -234,31 +234,30 @@ static int move_ptes(struct pagetable_move_control *pmc, if (pmc->need_rmap_locks) take_rmap_locks(vma); - /* - * We don't have to worry about the ordering of src and dst - * pte locks because exclusive mmap_lock prevents deadlock. - */ - old_ptep = pte_offset_map_lock(mm, old_pmd, old_addr, &old_ptl); + old_ptep = pte_offset_map_rw_nolock(mm, old_pmd, old_addr, &old_pmdval, + &old_ptl); if (!old_ptep) { err = -EAGAIN; goto out; } - /* - * Now new_pte is none, so collapse_scan_file() path can not find - * this by traversing file->f_mapping, so there is no concurrency with - * retract_page_tables(). In addition, we already hold the exclusive - * mmap_lock, so this new_pte page is stable, so there is no need to get - * pmdval and do pmd_same() check. - */ - new_ptep = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &dummy_pmdval, - &new_ptl); + new_ptep = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &new_pmdval, + &new_ptl); if (!new_ptep) { - pte_unmap_unlock(old_ptep, old_ptl); + pte_unmap(old_ptep); + err = -EAGAIN; + goto out; + } + + double_pt_lock(old_ptl, new_ptl); + if (unlikely(!pmd_same(old_pmdval, pmdp_get_lockless(old_pmd)) || + !pmd_same(new_pmdval, pmdp_get_lockless(new_pmd)))) { + double_pt_unlock(old_ptl, new_ptl); + pte_unmap(new_ptep); + pte_unmap(old_ptep); err = -EAGAIN; goto out; } - if (new_ptl != old_ptl) - spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); + flush_tlb_batched_pending(vma->vm_mm); lazy_mmu_mode_enable(); @@ -317,10 +316,9 @@ static int move_ptes(struct pagetable_move_control *pmc, lazy_mmu_mode_disable(); if (force_flush) flush_tlb_range(vma, old_end - len, old_end); - if (new_ptl != old_ptl) - spin_unlock(new_ptl); + double_pt_unlock(old_ptl, new_ptl); pte_unmap(new_ptep - 1); - pte_unmap_unlock(old_ptep - 1, old_ptl); + pte_unmap(old_ptep - 1); out: if (pmc->need_rmap_locks) drop_rmap_locks(vma); @@ -395,14 +393,9 @@ static bool move_normal_pmd(struct pagetable_move_control *pmc, if (WARN_ON_ONCE(!pmd_none(*new_pmd))) return false; - /* - * We don't have to worry about the ordering of src and dst - * ptlocks because exclusive mmap_lock prevents deadlock. - */ - old_ptl = pmd_lock(mm, old_pmd); + old_ptl = pmd_lockptr(mm, old_pmd); new_ptl = pmd_lockptr(mm, new_pmd); - if (new_ptl != old_ptl) - spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); + double_pt_lock(old_ptl, new_ptl); pmd = *old_pmd; @@ -418,9 +411,7 @@ static bool move_normal_pmd(struct pagetable_move_control *pmc, pmd_populate(mm, new_pmd, pmd_pgtable(pmd)); flush_tlb_range(vma, pmc->old_addr, pmc->old_addr + PMD_SIZE); out_unlock: - if (new_ptl != old_ptl) - spin_unlock(new_ptl); - spin_unlock(old_ptl); + double_pt_unlock(old_ptl, new_ptl); return res; } @@ -452,26 +443,24 @@ static bool move_normal_pud(struct pagetable_move_control *pmc, if (WARN_ON_ONCE(!pud_none(*new_pud))) return false; - /* - * We don't have to worry about the ordering of src and dst - * ptlocks because exclusive mmap_lock prevents deadlock. - */ - old_ptl = pud_lock(mm, old_pud); + old_ptl = pud_lockptr(mm, old_pud); new_ptl = pud_lockptr(mm, new_pud); - if (new_ptl != old_ptl) - spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); - /* Clear the pud */ + double_pt_lock(old_ptl, new_ptl); + pud = *old_pud; + if (unlikely(pud_none(pud))) + goto out_unlock; + + /* Clear the pud */ pud_clear(old_pud); VM_BUG_ON(!pud_none(*new_pud)); pud_populate(mm, new_pud, pud_pgtable(pud)); flush_tlb_range(vma, pmc->old_addr, pmc->old_addr + PUD_SIZE); - if (new_ptl != old_ptl) - spin_unlock(new_ptl); - spin_unlock(old_ptl); +out_unlock: + double_pt_unlock(old_ptl, new_ptl); return true; } @@ -499,18 +488,17 @@ static bool move_huge_pud(struct pagetable_move_control *pmc, if (WARN_ON_ONCE(!pud_none(*new_pud))) return false; - /* - * We don't have to worry about the ordering of src and dst - * ptlocks because exclusive mmap_lock prevents deadlock. - */ - old_ptl = pud_lock(mm, old_pud); + old_ptl = pud_lockptr(mm, old_pud); new_ptl = pud_lockptr(mm, new_pud); - if (new_ptl != old_ptl) - spin_lock_nested(new_ptl, SINGLE_DEPTH_NESTING); + + double_pt_lock(old_ptl, new_ptl); + if (unlikely(!pud_trans_huge(*old_pud))) { + double_pt_unlock(old_ptl, new_ptl); + return false; + } /* Clear the pud */ - pud = *old_pud; - pud_clear(old_pud); + pud = pudp_huge_get_and_clear(mm, pmc->old_addr, old_pud); VM_BUG_ON(!pud_none(*new_pud)); @@ -518,9 +506,7 @@ static bool move_huge_pud(struct pagetable_move_control *pmc, /* mark soft_ditry when we add pud level soft dirty support */ set_pud_at(mm, pmc->new_addr, new_pud, pud); flush_pud_tlb_range(vma, pmc->old_addr, pmc->old_addr + HPAGE_PUD_SIZE); - if (new_ptl != old_ptl) - spin_unlock(new_ptl); - spin_unlock(old_ptl); + double_pt_unlock(old_ptl, new_ptl); return true; } @@ -842,11 +828,10 @@ unsigned long move_page_tables(struct pagetable_move_control *pmc) if (!new_pud) break; if (pud_trans_huge(*old_pud)) { - if (extent == HPAGE_PUD_SIZE) { - move_pgt_entry(pmc, HPAGE_PUD, old_pud, new_pud); - /* We ignore and continue on error? */ + if (extent == HPAGE_PUD_SIZE && + move_pgt_entry(pmc, HPAGE_PUD, old_pud, new_pud)) continue; - } + split_huge_pud(pmc->old, old_pud, pmc->old_addr); } else if (IS_ENABLED(CONFIG_HAVE_MOVE_PUD) && extent == PUD_SIZE) { if (move_pgt_entry(pmc, NORMAL_PUD, old_pud, new_pud)) continue; diff --git a/mm/nommu.c b/mm/nommu.c index 91ab65afda7055..6c6f9532967461 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1887,7 +1887,7 @@ subsys_initcall(init_admin_reserve); int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) { - mmap_write_lock(oldmm); + mmap_assert_write_locked(oldmm); dup_mm_exe_file(mm, oldmm); mmap_write_unlock(oldmm); return 0; diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 499a35473e4f31..0694ec4098f6dd 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -883,6 +883,7 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, { struct wb_domain *dom = dtc_dom(dtc); struct bdi_writeback *wb = dtc->wb; + u64 threshold = thresh; u64 wb_thresh; u64 wb_max_thresh; unsigned long numerator, denominator; @@ -894,13 +895,14 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, fprop_fraction_percpu(&dom->completions, dtc->wb_completions, &numerator, &denominator); - wb_thresh = (thresh * (100 * BDI_RATIO_SCALE - bdi_min_ratio)) / (100 * BDI_RATIO_SCALE); + wb_thresh = div_u64(threshold * (100 * BDI_RATIO_SCALE - bdi_min_ratio), + 100 * BDI_RATIO_SCALE); wb_thresh *= numerator; wb_thresh = div64_ul(wb_thresh, denominator); wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio); - wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE); + wb_thresh += div_u64(threshold * wb_min_ratio, 100 * BDI_RATIO_SCALE); /* * It's very possible that wb_thresh is close to 0 not because the @@ -916,7 +918,7 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, wb_thresh = max(wb_thresh, (thresh - dtc->dirty) / 8); } - wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); + wb_max_thresh = div_u64(threshold * wb_max_ratio, 100 * BDI_RATIO_SCALE); if (wb_thresh > wb_max_thresh) wb_thresh = wb_max_thresh; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a8cac5e01066cb..6624293e4d7875 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -370,7 +370,6 @@ get_pfnblock_bitmap_bitidx(const struct page *page, unsigned long pfn, BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); #endif BUILD_BUG_ON(__MIGRATE_TYPE_END > PAGEBLOCK_MIGRATETYPE_MASK); - VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); bitmap = get_pageblock_bitmap(page, pfn); *bitidx = pfn_to_bitidx(page, pfn); @@ -1562,6 +1561,8 @@ static void free_one_page(struct zone *zone, struct page *page, llist_for_each_entry_safe(p, tmp, llnode, pcp_llist) { unsigned int p_order = p->private; + /* It may end up as a tail of the merged free page. */ + p->private = 0; split_large_buddy(zone, p, page_to_pfn(p), p_order, fpi_flags); __count_vm_events(PGFREE, 1 << p_order); } @@ -1616,6 +1617,9 @@ void __meminit __free_pages_core(struct page *page, unsigned int order, atomic_long_add(nr_pages, &page_zone(page)->managed_pages); } + /* pages were never allocated */ + clear_page_tag_ref(page); + if (page_contains_unaccepted(page, order)) { if (order == MAX_PAGE_ORDER && __free_unaccepted(page)) return; @@ -2929,7 +2933,7 @@ static bool free_frozen_page_commit(struct zone *zone, * kswapd work again by resetting kswapd_failures. */ if (kswapd_test_hopeless(pgdat) && - next_memory_node(pgdat->node_id) < MAX_NUMNODES) + num_node_state(N_MEMORY) > 1) kswapd_clear_hopeless(pgdat, KSWAPD_CLEAR_HOPELESS_PCP); } return ret; @@ -3238,7 +3242,9 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, * reserves as failing now is worse than failing a * high-order atomic allocation in the future. */ - if (!page && (alloc_flags & (ALLOC_OOM|ALLOC_NON_BLOCK))) + if (!page && + ((alloc_flags & ALLOC_OOM) || + (alloc_flags & ALLOC_MASK_ATOMIC) == ALLOC_MASK_ATOMIC)) page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); if (!page) { @@ -3794,12 +3800,21 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, { struct zoneref *z; struct zone *zone; + struct zone *preferred_zone; struct pglist_data *last_pgdat = NULL; bool last_pgdat_dirty_ok = false; bool no_fallback; bool skip_kswapd_nodes = nr_online_nodes > 1; bool skipped_kswapd_nodes = false; + /* + * A concurrent zonelist rebuild can NULL or replace this slot. Zones + * are never freed, so reading it once keeps a usable zone. + */ + preferred_zone = zonelist_zone(ac->preferred_zoneref); + if (!preferred_zone) + return NULL; + retry: /* * Scan zonelist, looking for a zone with enough free. @@ -3846,7 +3861,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, } if (no_fallback && !defrag_mode && nr_online_nodes > 1 && - zone != zonelist_zone(ac->preferred_zoneref)) { + zone != preferred_zone) { int local_nid; /* @@ -3854,7 +3869,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, * fragmenting fallbacks. Locality is more important * than fragmentation avoidance. */ - local_nid = zonelist_node_idx(ac->preferred_zoneref); + local_nid = zone_to_nid(preferred_zone); if (zone_to_nid(zone) != local_nid) { alloc_flags &= ~ALLOC_NOFRAGMENT; goto retry; @@ -3916,7 +3931,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, goto try_this_zone; if (!node_reclaim_enabled() || - !zone_allows_reclaim(zonelist_zone(ac->preferred_zoneref), zone)) + !zone_allows_reclaim(preferred_zone, zone)) continue; if (!node_reclaim(zone->zone_pgdat, gfp_mask, order)) @@ -3929,7 +3944,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, } try_this_zone: - page = rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, + page = rmqueue(preferred_zone, zone, order, gfp_mask, alloc_flags, ac->migratetype); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags); @@ -4400,24 +4415,21 @@ EXPORT_SYMBOL_GPL(fs_reclaim_release); * retries the allocation if zonelist changes. Writer side is protected by the * embedded spin_lock. */ -static DEFINE_SEQLOCK(zonelist_update_seq); +DEFINE_SEQLOCK(zonelist_update_seq); -static unsigned int zonelist_iter_begin(void) +/* + * Never wait for the writer, which an ALLOC_NOLOCK caller in NMI may have + * interrupted. Read the raw seqcount: on PREEMPT_RT the seqlock accessor takes + * the spinlock while a write is in progress. + */ +static unsigned int zonelist_iter_sample(void) { - if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) - return read_seqbegin(&zonelist_update_seq); + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return raw_seqcount_begin(&zonelist_update_seq.seqcount.seqcount); return 0; } -static unsigned int check_retry_zonelist(unsigned int seq) -{ - if (IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) - return read_seqretry(&zonelist_update_seq, seq); - - return seq; -} - /* Perform direct synchronous page reclaim */ static unsigned long __perform_reclaim(gfp_t gfp_mask, unsigned int order, @@ -4670,7 +4682,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, */ wmark = __zone_watermark_ok(zone, order, min_wmark, ac->highest_zoneidx, alloc_flags, available); - trace_reclaim_retry_zone(z, order, reclaimable, + trace_reclaim_retry_zone(zone, order, reclaimable, available, min_wmark, *no_progress_loops, wmark); if (wmark) { ret = true; @@ -4768,10 +4780,10 @@ static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { - bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; - bool can_compact = can_direct_reclaim && gfp_compaction_allowed(gfp_mask); - bool nofail = gfp_mask & __GFP_NOFAIL; const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; + bool can_direct_reclaim; + bool can_compact; + bool nofail; struct page *page = NULL; unsigned int alloc_flags; unsigned long did_some_progress; @@ -4783,9 +4795,21 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, unsigned int zonelist_iter_cookie; int reserve_flags; bool compact_first = false; - bool can_retry_reserves = true; + bool can_retry_reserves; unsigned long alloc_start_time = jiffies; + /* + * Costly __GFP_NORETRY callers have a cheap fallback, so don't stall + * them in reclaim or compaction. __GFP_THISNODE callers are exempt. + */ + if (costly_order && (gfp_mask & __GFP_NORETRY) && + !(gfp_mask & __GFP_THISNODE)) + gfp_mask &= ~__GFP_DIRECT_RECLAIM; + + can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; + can_compact = can_direct_reclaim && gfp_compaction_allowed(gfp_mask); + nofail = gfp_mask & __GFP_NOFAIL; + if (unlikely(nofail)) { /* * We don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM, @@ -4805,6 +4829,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, no_progress_loops = 0; compact_result = COMPACT_SKIPPED; compact_priority = DEF_COMPACT_PRIORITY; + can_retry_reserves = true; cpuset_mems_cookie = read_mems_allowed_begin(); zonelist_iter_cookie = zonelist_iter_begin(); @@ -4902,8 +4927,11 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * Reclaim/compaction cannot run, so defrag_mode's strategy * of enforcing ALLOC_NOFRAGMENT cannot be fulfilled. Allow * fallbacks rather than failing the allocation outright. + * Not for __GFP_NORETRY: those have a cheap lower order + * fallback, so failing beats fragmenting. */ if (defrag_mode && (alloc_flags & ALLOC_NOFRAGMENT) && + !(gfp_mask & __GFP_NORETRY) && (gfp_mask & __GFP_KSWAPD_RECLAIM)) { alloc_flags &= ~ALLOC_NOFRAGMENT; goto retry; @@ -5090,6 +5118,12 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: + /* A rebuild during the walk may have handed out an ineligible zone. */ + if (page && check_retry_zonelist(zonelist_iter_cookie)) { + __free_frozen_pages(page, order, FPI_NONE); + page = NULL; + goto restart; + } return page; } @@ -5168,11 +5202,13 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, { struct page *page; struct zone *zone; + struct zone *preferred_zone; struct zoneref *z; struct per_cpu_pages *pcp; struct list_head *pcp_list; struct alloc_context ac; unsigned int alloc_flags = ALLOC_WMARK_LOW; + unsigned int zonelist_iter_cookie; int nr_populated = 0, nr_account = 0; /* @@ -5213,9 +5249,15 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, /* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */ gfp &= gfp_allowed_mask; gfp = current_gfp_context(gfp); + zonelist_iter_cookie = zonelist_iter_sample(); if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &gfp, &alloc_flags)) goto out; + /* Read once; see get_page_from_freelist(). */ + preferred_zone = zonelist_zone(ac.preferred_zoneref); + if (!preferred_zone) + goto failed; + /* Find an allowed local zone that meets the low watermark. */ z = ac.preferred_zoneref; for_next_zone_zonelist_nodemask(zone, z, ac.highest_zoneidx, ac.nodemask) { @@ -5226,8 +5268,8 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, continue; } - if (nr_online_nodes > 1 && zone != zonelist_zone(ac.preferred_zoneref) && - zone_to_nid(zone) != zonelist_node_idx(ac.preferred_zoneref)) { + if (nr_online_nodes > 1 && zone != preferred_zone && + zone_to_nid(zone) != zone_to_nid(preferred_zone)) { goto failed; } @@ -5235,7 +5277,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, retry_this_zone: mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages - nr_populated; if (zone_watermark_fast(zone, 0, mark, - zonelist_zone_idx(ac.preferred_zoneref), + zone_idx(preferred_zone), alloc_flags, gfp)) { break; } @@ -5257,6 +5299,10 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, if (unlikely(!zone)) goto failed; + /* The zone was chosen from a zonelist that a rebuild may have changed. */ + if (unlikely(check_retry_zonelist(zonelist_iter_cookie))) + goto failed; + /* spin_trylock may fail due to a parallel drain or IRQ reentrancy. */ pcp = pcp_spin_trylock(zone->per_cpu_pageset); if (!pcp) @@ -5294,7 +5340,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, pcp_spin_unlock(pcp); __count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account); - zone_statistics(zonelist_zone(ac.preferred_zoneref), zone, nr_account); + zone_statistics(preferred_zone, zone, nr_account); out: return nr_populated; @@ -5397,6 +5443,7 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, .alloc_flags = alloc_flags, }; unsigned int fastpath_alloc_flags = alloc_flags; + unsigned int zonelist_iter_cookie; /* Other flags could be supported later if needed. */ if (WARN_ON(alloc_flags & ~(ALLOC_NOLOCK | ALLOC_NO_CODETAG))) @@ -5426,6 +5473,7 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, */ gfp = current_gfp_context(gfp); alloc_gfp = gfp; + zonelist_iter_cookie = zonelist_iter_sample(); if (!prepare_alloc_pages(gfp, order, preferred_nid, nodemask, &ac, &alloc_gfp, &fastpath_alloc_flags)) return NULL; @@ -5442,6 +5490,11 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, /* First allocation attempt (or, for nolock, only attempt) */ page = get_page_from_freelist(alloc_gfp, order, fastpath_alloc_flags, &ac); + if (likely(page) && unlikely(check_retry_zonelist(zonelist_iter_cookie))) { + __free_frozen_pages(page, order, + alloc_flags & ALLOC_NOLOCK ? FPI_NOLOCK : 0); + page = NULL; + } if (likely(page) || (alloc_flags & ALLOC_NOLOCK)) goto out; @@ -5941,7 +5994,7 @@ int local_memory_node(int node) z = first_zones_zonelist(node_zonelist(node, GFP_KERNEL), gfp_zone(GFP_KERNEL), NULL); - return zonelist_node_idx(z); + return zone_to_nid(zonelist_zone(z)); } #endif @@ -6307,6 +6360,10 @@ void __meminit setup_zone_pageset(struct zone *zone) { int cpu; + /* The zone has been populated before, see zone_pcp_reset(). */ + if (zone->per_cpu_pageset != &boot_pageset) + return; + /* Size may be 0 on !SMP && !NUMA */ if (sizeof(struct per_cpu_zonestat) > 0) zone->per_cpu_zonestats = alloc_percpu(struct per_cpu_zonestat); @@ -6399,6 +6456,10 @@ void __init setup_per_cpu_pageset(void) __meminit void zone_pcp_init(struct zone *zone) { + /* This initialization only needs to be done once */ + if (zone->per_cpu_pageset) + return; + /* * per cpu subsystem is not up at this point. The following code * relies on the ability of the linker to provide the @@ -7324,9 +7385,13 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, * put back to page allocator so that buddy can use them. */ + /* + * On failure this has undone its own isolation, and any other + * isolated blocks in the range belong to someone else, e.g. offline. + */ ret = start_isolate_page_range(start, end, mode); if (ret) - goto done; + return ret; drain_all_pages(cc.zone); @@ -7530,6 +7595,7 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, gfp_t gfp_mask, int nid, nodemask_t *nodemask) { unsigned long ret, pfn, flags; + unsigned int zonelist_cookie; struct zonelist *zonelist; struct zone *zone; struct zoneref *z; @@ -7538,8 +7604,13 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, retry: zonelist = node_zonelist(nid, gfp_mask); + zonelist_cookie = zonelist_iter_begin(); for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nodemask) { + /* A rebuild may have shifted an ineligible zone into this slot. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry; + spin_lock_irqsave(&zone->lock, flags); pfn = ALIGN(zone->zone_start_pfn, nr_pages); @@ -7574,6 +7645,9 @@ struct page *alloc_contig_frozen_pages_noprof(unsigned long nr_pages, * second pass, we will try moving HugeTLB pages when those pages are * smaller than the requested contiguous region size. */ + /* Redo a pass that a rebuild cut short before escalating. */ + if (unlikely(check_retry_zonelist(zonelist_cookie))) + goto retry; if (skip_hugetlb && skipped_hugetlb) { skip_hugetlb = false; goto retry; @@ -7679,6 +7753,12 @@ void zone_pcp_enable(struct zone *zone) mutex_unlock(&pcp_batch_high_lock); } +/* + * The zone has become empty. Its pagesets and zonestats are not freed: nothing + * keeps somebody who found the zone populated, such as refresh_cpu_vm_stats() + * or drain_all_pages(), from still using them. They are used again when the + * zone gets memory again. + */ void zone_pcp_reset(struct zone *zone) { int cpu; @@ -7689,12 +7769,6 @@ void zone_pcp_reset(struct zone *zone) pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); drain_zonestat(zone, pzstats); } - free_percpu(zone->per_cpu_pageset); - zone->per_cpu_pageset = &boot_pageset; - if (zone->per_cpu_zonestats != &boot_zonestats) { - free_percpu(zone->per_cpu_zonestats); - zone->per_cpu_zonestats = &boot_zonestats; - } } } diff --git a/mm/page_alloc.h b/mm/page_alloc.h index e238ee91ed2453..917653ae14a3de 100644 --- a/mm/page_alloc.h +++ b/mm/page_alloc.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #define ALLOC_DEFAULT 0 @@ -32,12 +33,11 @@ #define ALLOC_OOM ALLOC_NO_WATERMARKS #endif -#define ALLOC_NON_BLOCK 0x10 /* Caller cannot block. Allow access - * to 25% of the min watermark or - * 62.5% if __GFP_HIGH is set. - */ +#define ALLOC_NON_BLOCK 0x10 /* Caller cannot block. */ #define ALLOC_MIN_RESERVE 0x20 /* __GFP_HIGH set. Allow access to 50% - * of the min watermark. + * of the min watermark, or 62.5% if + * the caller cannot block either + * (ALLOC_NON_BLOCK). */ #define ALLOC_CPUSET 0x40 /* check for correct cpuset */ #define ALLOC_CMA 0x80 /* allow allocations from CMA areas */ @@ -58,7 +58,10 @@ #define ALLOC_NO_CODETAG 0x1000 /* Flags that allow allocations below the min watermark. */ -#define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) +#define ALLOC_RESERVES (ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) + +/* Flags that mean GFP_ATOMIC */ +#define ALLOC_MASK_ATOMIC (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE) /* * Structure for holding the mostly immutable allocation parameters passed @@ -265,6 +268,24 @@ extern void zone_pcp_disable(struct zone *zone); extern void zone_pcp_enable(struct zone *zone); extern void zone_pcp_init(struct zone *zone); +extern seqlock_t zonelist_update_seq; + +static inline unsigned int zonelist_iter_begin(void) +{ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return read_seqbegin(&zonelist_update_seq); + + return 0; +} + +static inline unsigned int check_retry_zonelist(unsigned int seq) +{ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return read_seqretry(&zonelist_update_seq, seq); + + return 0; +} + enum fallback_result { /* Found suitable migratetype, *mt_out is valid. */ FALLBACK_FOUND, diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index e63efe78b7d4b4..8914437ddc5197 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -119,15 +119,20 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, size = PAGE_SIZE << encoded_page_decode_order(encoded_page); offset = __ALIGN_KERNEL_MASK(nc->offset, ~align_mask); if (unlikely(offset + fragsz > size)) { - if (unlikely(fragsz > PAGE_SIZE)) { + if (unlikely(fragsz > size)) { /* - * The caller is trying to allocate a fragment - * with fragsz > PAGE_SIZE but the cache isn't big - * enough to satisfy the request, this may - * happen in low memory conditions. - * We don't release the cache page because - * it could make memory pressure worse - * so we simply return NULL here. + * The caller is trying to allocate a fragment that's + * larger than the whole cache page. + * + * Either fragsz is larger than PAGE_FRAG_CACHE_MAX_SIZE + * so this cannot ever succeed. + * + * Or the refill has fallen back to order-0 due to a low + * memory condition. Then we don't want to release the + * cache page to attempt a new large-size refill because + * it could make memory pressure worse. + * + * So in both cases we simply return NULL here. */ return NULL; } diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 5aaad037384e44..f4f0571607abf4 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -74,6 +74,13 @@ bool page_is_unmovable(struct zone *zone, struct page *page, return false; } + /* + * Slab pages are frozen: do not take their reference count of zero + * for that of a free page. + */ + if (PageSlab(page)) + return true; + /* * We can't use page_count without pin a page * because another CPU can free compound page. diff --git a/mm/rmap.c b/mm/rmap.c index 1131b76bbbc28b..0faef46806e5ca 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -924,6 +924,7 @@ static bool folio_referenced_one(struct folio *folio, DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0); int ptes = 0, referenced = 0; unsigned int nr; + pte_t pteval; while (page_vma_mapped_walk(&pvmw)) { address = pvmw.address; @@ -968,10 +969,12 @@ static bool folio_referenced_one(struct folio *folio, return false; } - if (pvmw.pte && folio_test_large(folio)) { + if (pvmw.pte) + pteval = ptep_get(pvmw.pte); + + if (pvmw.pte && pte_present(pteval) && folio_test_large(folio)) { const unsigned long end_addr = pmd_addr_end(address, vma->vm_end); const unsigned int max_nr = (end_addr - address) >> PAGE_SHIFT; - pte_t pteval = ptep_get(pvmw.pte); nr = folio_pte_batch(folio, pvmw.pte, pteval, max_nr); } @@ -981,11 +984,23 @@ static bool folio_referenced_one(struct folio *folio, * are. —they could be on active/inactive lists or on MGLRU. So the * simplest approach is to disable this look-around optimization. */ - if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte) { + if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte && + pte_present(pteval)) { if (lru_gen_look_around(&pvmw, nr)) referenced++; } else if (pvmw.pte) { - if (clear_flush_young_ptes_notify(vma, address, pvmw.pte, nr)) + bool young = false; + + /* + * PFN swap PTEs, such as device-exclusive ones, that + * actually map pages are "old" from a CPU perspective. + * The MMU notifier takes care of any device aspects. + */ + if (pte_present(pteval)) + young = clear_flush_young_ptes(vma, address, pvmw.pte, nr); + young |= mmu_notifier_clear_flush_young(vma->vm_mm, address, + address + nr * PAGE_SIZE); + if (young) referenced++; } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { if (pmdp_clear_flush_young_notify(vma, address, diff --git a/mm/shmem.c b/mm/shmem.c index af21a89abb0f63..10cef89b00b087 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -77,6 +77,7 @@ static struct vfsmount *shm_mnt __ro_after_init; #include #include #include +#include #include #include #include @@ -275,6 +276,11 @@ static const struct vm_operations_struct shmem_vm_ops; static const struct vm_operations_struct shmem_anon_vm_ops; static struct file_system_type shmem_fs_type; +bool shmem_file(struct file *file) +{ + return file && file_inode(file)->i_fop == &shmem_file_operations; +} + bool shmem_mapping(const struct address_space *mapping) { return mapping->a_ops == &shmem_aops; @@ -1176,12 +1182,11 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) } /* - * Remove swap entry from page cache, free the swap and its page cache. Returns - * the number of pages being freed. 0 means entry not found in XArray (0 pages - * being freed). + * Remove a swap entry or swapin-error marker wholly within [index, end]. + * Return whether it was removed, counting freed swap pages in nr_swaps_freed. */ -static long shmem_free_swap(struct address_space *mapping, - pgoff_t index, pgoff_t end, void *radswap) +static bool shmem_free_swap(struct address_space *mapping, + pgoff_t index, pgoff_t end, void *radswap, long *nr_swaps_freed) { XA_STATE(xas, &mapping->i_pages, index); const softleaf_t swp = radix_to_swp_entry(radswap); @@ -1202,8 +1207,10 @@ static long shmem_free_swap(struct address_space *mapping, xas_unlock_irq(&xas); /* A swapin-error marker holds no swap slot, so just drop it. */ - if (nr_pages && softleaf_is_swap(swp)) + if (nr_pages && softleaf_is_swap(swp)) { swap_put_entries_direct(swp, nr_pages); + *nr_swaps_freed += nr_pages; + } return nr_pages; } @@ -1297,12 +1304,10 @@ void shmem_unlock_mapping(struct address_space *mapping) static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) { + const gfp_t gfp = mapping_gfp_mask(inode->i_mapping); struct folio *folio; - /* - * At first avoid shmem_get_folio(,,,SGP_READ): that fails - * beyond i_size, and reports fallocated folios as holes. - */ +retry: folio = filemap_get_entry(inode->i_mapping, index); if (!folio) return folio; @@ -1313,13 +1318,14 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) /* The folio has been swapped out */ folio_unlock(folio); folio_put(folio); + goto retry; } /* - * But read a folio back from swap if any of it is within i_size - * (although in some cases this is just a waste of time). + * Truncation can look up a large swap entry at or beyond i_size. + * Swap it in directly to bypass the size check in shmem_get_folio(). */ - folio = NULL; - shmem_get_folio(inode, index, 0, &folio, SGP_READ); + if (shmem_swapin_folio(inode, index, &folio, SGP_READ, gfp, NULL, NULL) == -EEXIST) + goto retry; return folio; } @@ -1358,8 +1364,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, if (xa_is_value(folio)) { if (unfalloc) continue; - nr_swaps_freed += shmem_free_swap(mapping, indices[i], - end - 1, folio); + shmem_free_swap(mapping, indices[i], end - 1, + folio, &nr_swaps_freed); continue; } @@ -1422,32 +1428,31 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, if (xa_is_value(folio)) { int order; - long swaps_freed; if (unfalloc) continue; - swaps_freed = shmem_free_swap(mapping, indices[i], - end - 1, folio); - if (!swaps_freed) { + if (!shmem_free_swap(mapping, indices[i], end - 1, + folio, &nr_swaps_freed)) { pgoff_t base = indices[i]; order = shmem_confirm_swap(mapping, indices[i], radix_to_swp_entry(folio)); /* - * If found a large swap entry cross the end or start - * border, skip it as the truncate_inode_partial_folio - * above should have at least zerod its content once. + * Skip boundary entries when restarting + * the scan to avoid endless loops after + * swapin failure. */ if (order > 0) { base = round_down(base, 1 << order); - if (base < start || base + (1 << order) > end) + if (base < start || base + (1 << order) > end) { + start = max(start, base + (1 << order)); continue; + } } /* Swap was replaced by page or extended, retry */ index = base; break; } - nr_swaps_freed += swaps_freed; continue; } @@ -1463,23 +1468,35 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); - if (!folio_test_large(folio)) { + /* + * A shared mapping can have dirty PTEs while + * the folio is still clean. Mark the folio + * dirty so a failed split cannot discard data + * outside the range. + */ + if (!unfalloc && folio_test_large(folio)) + folio_mark_dirty(folio); + + if (unfalloc || !folio_test_large(folio)) { truncate_inode_folio(mapping, folio); } else if (truncate_inode_partial_folio(folio, lstart, lend, NULL, NULL)) { /* - * If we split a page, reset the loop so - * that we pick up the new sub pages. - * Otherwise the THP was entirely - * dropped or the target range was - * zeroed, so just continue the loop as - * is. + * The folio was split. Retry the scan + * to find the split folios. */ - if (!folio_test_large(folio)) { - folio_unlock(folio); - index = start; - break; - } + folio_unlock(folio); + index = start; + break; + } else if (folio->mapping) { + /* + * Splitting failed, but the part in the + * range is already zeroed. The folio + * was not dropped, so skip it when + * restarting the scan to avoid retrying + * it forever. + */ + start = max(start, folio_next_index(folio)); } } folio_unlock(folio); @@ -1546,10 +1563,11 @@ static int shmem_setattr(const struct mnt_idmap *idmap, if (error) return error; - if ((info->seals & F_SEAL_EXEC) && (attr->ia_valid & ATTR_MODE)) { - if ((inode->i_mode ^ attr->ia_mode) & 0111) { - return -EPERM; - } + if (attr->ia_valid & ATTR_MODE) { + error = memfd_check_seals_mode(info->seals, inode->i_mode, + attr->ia_mode); + if (error) + return error; } if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { @@ -1578,7 +1596,8 @@ static int shmem_setattr(const struct mnt_idmap *idmap, if (oldsize > holebegin) unmap_mapping_range(inode->i_mapping, holebegin, 0, 1); - if (info->alloced) + /* Swapin-error markers are not counted in alloced. */ + if (info->alloced || !mapping_empty(inode->i_mapping)) shmem_truncate_range(inode, newsize, (loff_t)-1); /* unmap again to remove racily COWed private pages */ @@ -1614,6 +1633,17 @@ static int shmem_setattr(const struct mnt_idmap *idmap, return error; } +static void shmem_disallow_eviction(struct shmem_inode_info *info) +{ + atomic_inc(&info->stop_eviction); +} + +static void shmem_allow_eviction(struct shmem_inode_info *info) +{ + if (atomic_dec_and_test(&info->stop_eviction)) + wake_up_var(&info->stop_eviction); +} + static void shmem_evict_inode(struct inode *inode) { struct shmem_inode_info *info = SHMEM_I(inode); @@ -1626,16 +1656,21 @@ static void shmem_evict_inode(struct inode *inode) mapping_set_exiting(inode->i_mapping); shmem_truncate_range(inode, 0, (loff_t)-1); shmem_unused_huge_del(inode); - while (!list_empty(&info->swaplist)) { - /* Wait while shmem_unuse() is scanning this inode... */ + /* + * Writeout may still use the inode after swapoff has removed it + * from the swaplist, so always wait at least once. + */ + do { wait_var_event(&info->stop_eviction, !atomic_read(&info->stop_eviction)); + if (list_empty(&info->swaplist)) + break; spin_lock(&shmem_swaplist_lock); /* ...but beware of the race if we peeked too early */ if (!atomic_read(&info->stop_eviction)) list_del_init(&info->swaplist); spin_unlock(&shmem_swaplist_lock); - } + } while (!list_empty(&info->swaplist)); } simple_xattrs_free(&sbinfo->xa_cache, &info->xattrs, sbinfo->max_inodes ? &freed : NULL); @@ -1742,6 +1777,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type) if (ret < 0) break; + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } start = indices[folio_batch_count(&fbatch) - 1]; } while (true); @@ -1774,15 +1813,14 @@ int shmem_unuse(unsigned int type) * remove placeholder inode from swaplist, nor let it be freed * (igrab() would protect from unlink, but not from unmount). */ - atomic_inc(&info->stop_eviction); + shmem_disallow_eviction(info); spin_unlock(&shmem_swaplist_lock); error = shmem_unuse_inode(&info->vfs_inode, type); cond_resched(); spin_lock(&shmem_swaplist_lock); - if (atomic_dec_and_test(&info->stop_eviction)) - wake_up_var(&info->stop_eviction); + shmem_allow_eviction(info); if (error) break; if (list_empty(&info->swaplist)) @@ -1913,6 +1951,13 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio, spin_unlock(&shmem_swaplist_lock); } + /* + * Once the folio has left the page cache, its lock no longer + * keeps the inode from being evicted and freed: hold eviction + * off, in case the folio has to be put back below. + */ + shmem_disallow_eviction(info); + folio_dup_swap(folio, NULL); shmem_delete_from_page_cache(folio, swp_to_radix_entry(folio->swap)); @@ -1920,6 +1965,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio, error = swap_writeout(ctx, folio); if (error != AOP_WRITEPAGE_ACTIVATE) { /* folio has been unlocked */ + shmem_allow_eviction(info); return error; } @@ -1936,6 +1982,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio, shmem_recalc_inode(inode, 0, -nr_pages); folio_put_swap(folio, NULL); } + shmem_allow_eviction(info); /* * The swap_cache_del_folio() below could be left for @@ -2370,11 +2417,10 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, folio_put_swap(folio, NULL); swap_cache_del_folio(folio); /* - * Don't treat swapin error folio as alloced. Otherwise inode->i_blocks - * won't be 0 when inode is released and thus trigger WARN_ON(i_blocks) - * in shmem_evict_inode(). + * Let shmem_recalc_inode() reduce alloced and release the block charge + * for the freed swap pages. */ - shmem_recalc_inode(inode, -nr_pages, -nr_pages); + shmem_recalc_inode(inode, 0, -nr_pages); } static int shmem_split_large_entry(struct inode *inode, pgoff_t index, @@ -2515,6 +2561,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, else error = -ENOMEM; folio = NULL; + /* Make sure to validate the original value. */ + swap = index_entry; goto failed; } if (fault_type) { @@ -3287,7 +3335,7 @@ static struct inode *__shmem_get_inode(const struct mnt_idmap *idmap, inode->i_size = 2 * BOGO_DIRENT_SIZE; inode->i_op = &shmem_dir_inode_operations; inode->i_fop = &simple_offset_dir_operations; - simple_offset_init(shmem_get_offset_ctx(inode)); + simple_offset_init(shmem_get_offset_ctx(inode), inode); break; case S_IFLNK: /* @@ -3655,15 +3703,8 @@ static void zero_pipe_buf_release(struct pipe_inode_info *pipe, { } -static bool zero_pipe_buf_try_steal(struct pipe_inode_info *pipe, - struct pipe_buffer *buf) -{ - return false; -} - static const struct pipe_buf_operations zero_pipe_buf_ops = { .release = zero_pipe_buf_release, - .try_steal = zero_pipe_buf_try_steal, .get = zero_pipe_buf_get, }; @@ -5404,12 +5445,35 @@ static const struct file_operations shmem_file_operations = { #endif }; +#ifdef CONFIG_TMPFS_POSIX_ACL +static int shmem_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry, + struct posix_acl *acl, int type) +{ + struct inode *inode = d_inode(dentry); + umode_t mode = inode->i_mode; + int error; + + if (type == ACL_TYPE_ACCESS) { + error = posix_acl_equiv_mode(acl, &mode); + if (error < 0) + return error; + error = memfd_check_seals_mode(SHMEM_I(inode)->seals, + inode->i_mode, mode); + if (error) + return error; + } + return simple_set_acl(idmap, dentry, acl, type); +} +#else +#define shmem_set_acl simple_set_acl +#endif + static const struct inode_operations shmem_inode_operations = { .getattr = shmem_getattr, .setattr = shmem_setattr, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, - .set_acl = simple_set_acl, + .set_acl = shmem_set_acl, .fileattr_get = shmem_fileattr_get, .fileattr_set = shmem_fileattr_set, #endif diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c index a3fa4bd93e753a..d191ebda3f00e5 100644 --- a/mm/shmem_quota.c +++ b/mm/shmem_quota.c @@ -239,7 +239,7 @@ static int shmem_acquire_dquot(struct dquot *dquot) return ret; } -static bool shmem_is_empty_dquot(struct dquot *dquot) +static bool shmem_is_default_dquot(struct dquot *dquot) { struct shmem_sb_info *sbinfo = dquot->dq_sb->s_fs_info; qsize_t bhardlimit; @@ -253,19 +253,21 @@ static bool shmem_is_empty_dquot(struct dquot *dquot) ihardlimit = sbinfo->qlimits.grpquota_ihardlimit; } - if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || - (dquot->dq_dqb.dqb_curspace == 0 && - dquot->dq_dqb.dqb_curinodes == 0 && - dquot->dq_dqb.dqb_bhardlimit == bhardlimit && - dquot->dq_dqb.dqb_ihardlimit == ihardlimit)) - return true; - - return false; + /* + * Defaults are zero usage and soft limits, and the mount's hard limits. + * DQ_FAKE_B only means that *all* limits are zero, which need not match + * the mount defaults. + */ + return dquot->dq_dqb.dqb_curspace == 0 && + dquot->dq_dqb.dqb_curinodes == 0 && + dquot->dq_dqb.dqb_bsoftlimit == 0 && + dquot->dq_dqb.dqb_isoftlimit == 0 && + dquot->dq_dqb.dqb_bhardlimit == bhardlimit && + dquot->dq_dqb.dqb_ihardlimit == ihardlimit; } /* - * Store limits from dquot in the tree unless it's fake. If it is fake - * remove the id from the tree since there is no useful information in - * there. + * Remove the ID from the tree if it has no usage and its limits match + * the mount defaults. Otherwise, save its limits for the next acquire. */ static int shmem_release_dquot(struct dquot *dquot) { @@ -300,7 +302,7 @@ static int shmem_release_dquot(struct dquot *dquot) return -ENOENT; found: - if (shmem_is_empty_dquot(dquot)) { + if (shmem_is_default_dquot(dquot)) { /* Remove entry from the tree */ rb_erase(&entry->node, info->dqi_priv); kfree(entry); diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index cafb566301326d..3cf7bb076c6a71 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -53,7 +53,7 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) bool memcg_aware; int ret = 0, nid; - count_per_node = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL); + count_per_node = kzalloc_objs(unsigned long, nr_node_ids); if (!count_per_node) return -ENOMEM; diff --git a/mm/slab_common.c b/mm/slab_common.c index 01c64ef661e7f8..2befd24b4d0999 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1103,7 +1103,7 @@ int cache_random_seq_create(struct kmem_cache *cachep, unsigned int count, if (count < 2 || cachep->random_seq) return 0; - cachep->random_seq = kcalloc(count, sizeof(unsigned int), gfp); + cachep->random_seq = kzalloc_objs(unsigned int, count, gfp); if (!cachep->random_seq) return -ENOMEM; diff --git a/mm/slub.c b/mm/slub.c index 45e077c7526c2a..cd671b93471918 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -9221,7 +9221,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s, unsigned long *nodes; int len = 0; - nodes = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL); + nodes = kzalloc_objs(unsigned long, nr_node_ids); if (!nodes) return -ENOMEM; diff --git a/mm/swapfile.c b/mm/swapfile.c index 254ce86fa923e6..2d2df53fc51a91 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2514,7 +2514,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, return 0; swapcache = folio; - folio = ksm_might_need_to_copy(folio, vma, addr); + folio = ksm_might_need_to_copy(folio, + folio_file_page(folio, swp_offset(entry)), vma, addr); if (unlikely(!folio)) return -ENOMEM; else if (unlikely(folio == ERR_PTR(-EHWPOISON))) { @@ -2689,6 +2690,8 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, pmd = pmd_offset(pud, addr); do { cond_resched(); + if (signal_pending(current)) + return -ERESTARTSYS; next = pmd_addr_end(addr, end); ret = unuse_pte_range(vma, pmd, addr, next, type); if (ret) @@ -2922,7 +2925,7 @@ static int try_to_unuse(unsigned int type) if (swap_usage_in_pages(si)) { if (!signal_pending(current)) goto retry; - return -EINTR; + return -ERESTARTSYS; } success: diff --git a/mm/truncate.c b/mm/truncate.c index 733d2713a875a5..9e9bf029635cfd 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -475,8 +475,11 @@ void truncate_inode_pages_range(struct address_space *mapping, } } + if (start >= end) + return; + index = start; - while (index < end) { + while (true) { cond_resched(); if (!find_get_entries(mapping, &index, end - 1, &fbatch, indices)) { @@ -499,6 +502,7 @@ void truncate_inode_pages_range(struct address_space *mapping, folio_lock(folio); VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio); folio_wait_writeback(folio); + /* Do not handle errors, we'll do another lookup */ truncate_inode_folio(mapping, folio); folio_unlock(folio); } @@ -760,7 +764,12 @@ int invalidate_inode_pages2_range(struct address_space *mapping, folio_lock(folio); if (unlikely(folio->mapping != mapping)) { folio_unlock(folio); - continue; + /* + * Folio might have been replaced: look up + * again. + */ + index = indices[i]; + break; } VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio); folio_wait_writeback(folio); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 928ad95eeb2ba9..169f681f9849b4 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1206,33 +1206,6 @@ int mrwprotect_range(struct userfaultfd_ctx *ctx, unsigned long start, return 0; } -void double_pt_lock(spinlock_t *ptl1, - spinlock_t *ptl2) - __acquires(ptl1) - __acquires(ptl2) -{ - if (ptl1 > ptl2) - swap(ptl1, ptl2); - /* lock in virtual address order to avoid lock inversion */ - spin_lock(ptl1); - if (ptl1 != ptl2) - spin_lock_nested(ptl2, SINGLE_DEPTH_NESTING); - else - __acquire(ptl2); -} - -void double_pt_unlock(spinlock_t *ptl1, - spinlock_t *ptl2) - __releases(ptl1) - __releases(ptl2) -{ - spin_unlock(ptl1); - if (ptl1 != ptl2) - spin_unlock(ptl2); - else - __release(ptl2); -} - static inline bool is_pte_pages_stable(pte_t *dst_pte, pte_t *src_pte, pte_t orig_dst_pte, pte_t orig_src_pte, pmd_t *dst_pmd, pmd_t dst_pmdval) @@ -2270,6 +2243,9 @@ static struct vm_area_struct *userfaultfd_clear_vma(struct vma_iterator *vmi, return ret; } +static void wake_userfault_range(struct userfaultfd_ctx *ctx, + unsigned long start, unsigned long end); + /* Assumes mmap write lock taken, and mm_struct pinned. */ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, struct vm_area_struct *vma, @@ -2287,6 +2263,9 @@ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, prev = vma; for_each_vma_range(vmi, vma, end) { + const bool any_mode_removed = vma->vm_flags & __VM_UFFD_FLAGS & ~vm_flags; + const vma_flags_t curr_vma_flags = vma_flags_and_mask(&vma->flags, __VMA_UFFD_FLAGS); + cond_resched(); VM_WARN_ON_ONCE(!vma_can_userfault(vma, vm_flags, wp_async)); @@ -2299,7 +2278,7 @@ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, * userfaultfd and with the right tracking mode too. */ if (vma->vm_userfaultfd_ctx.ctx == ctx && - vma_test_all_mask(vma, vma_flags)) + vma_flags_same_pair(&curr_vma_flags, &vma_flags)) goto skip; /* @@ -2332,6 +2311,10 @@ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, */ userfaultfd_set_ctx(vma, ctx, vm_flags); + /* Retry faults for removed modes while the VMA is write-locked. */ + if (any_mode_removed) + wake_userfault_range(ctx, start, vma_end); + if (vma_is_hugetlb(vma) && uffd_disable_huge_pmd_share(vma)) hugetlb_unshare_all_pmds(vma); @@ -3648,6 +3631,17 @@ static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx, __wake_userfault(ctx, range); } +static void wake_userfault_range(struct userfaultfd_ctx *ctx, + unsigned long start, unsigned long end) +{ + struct userfaultfd_wake_range range = { + .start = start, + .len = end - start, + }; + + wake_userfault(ctx, &range); +} + static __always_inline int validate_unaligned_range( struct mm_struct *mm, __u64 start, __u64 len) { @@ -3977,6 +3971,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, ret = 0; for_each_vma_range(vmi, vma, end) { + struct userfaultfd_wake_range range; + cond_resched(); /* VMA not registered with userfaultfd. */ @@ -3991,18 +3987,17 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, start = vma->vm_start; vma_end = min(end, vma->vm_end); - if (userfaultfd_missing(vma)) { - /* - * Wake any concurrent pending userfault while - * we unregister, so they will not hang - * permanently and it avoids userland to call - * UFFDIO_WAKE explicitly. - */ - struct userfaultfd_wake_range range; - range.start = start; - range.len = vma_end - start; - wake_userfault(vma->vm_userfaultfd_ctx.ctx, &range); - } + /* Prevent new userfaults from being queued after the wakeup. */ + vma_start_write(vma); + + /* + * Wake any concurrent pending userfault while we unregister, + * so they will not hang permanently and it avoids userland to + * call UFFDIO_WAKE explicitly. + */ + range.start = start; + range.len = vma_end - start; + wake_userfault(ctx, &range); vma = userfaultfd_clear_vma(&vmi, prev, vma, start, vma_end); diff --git a/mm/util.c b/mm/util.c index 8acfe2148ba52b..80f6c714844f2b 100644 --- a/mm/util.c +++ b/mm/util.c @@ -697,6 +697,19 @@ void *vcalloc_noprof(size_t n, size_t size) } EXPORT_SYMBOL(vcalloc_noprof); +/** + * folio_anon_vma - Get a folio's raw anon_vma pointer. + * @folio: The folio. + * + * The returned pointer may be stale for an unmapped folio. The caller + * must ensure the anon_vma stays alive before dereferencing it. A folio + * reference or lock alone is insufficient; use folio_get_anon_vma() when + * the anon_vma's lifetime is not otherwise protected. Note that + * folio_get_anon_vma() is only useful for folios that are still mapped. + * + * Return: The raw anon_vma pointer for an anonymous, non-KSM folio, or + * %NULL otherwise. + */ struct anon_vma *folio_anon_vma(const struct folio *folio) { unsigned long mapping = (unsigned long)folio->mapping; diff --git a/mm/vma.c b/mm/vma.c index 1be613044b4a50..e38e22a5e752e4 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -516,6 +516,15 @@ void unmap_region(struct unmap_desc *unmap) tlb_finish_mmu(&tlb); } +static int check_split(struct vm_area_struct *vma, unsigned long addr) +{ + if (!vma->vm_ops) + return 0; + if (!vma->vm_ops->may_split) + return 0; + return vma->vm_ops->may_split(vma, addr); +} + /* * __split_vma() bypasses sysctl_max_map_count checking. We use this where it * has already been checked or doesn't make sense to fail. @@ -532,12 +541,11 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, WARN_ON(vma->vm_start >= addr); WARN_ON(vma->vm_end <= addr); - if (vma->vm_ops && vma->vm_ops->may_split) { - err = vma->vm_ops->may_split(vma, addr); - if (err) - return err; - } + err = check_split(vma, addr); + if (err) + return err; + vma_start_write(vma); new = vm_area_dup(vma); if (!new) return -ENOMEM; @@ -568,7 +576,6 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, if (new->vm_ops && new->vm_ops->open) new->vm_ops->open(new); - vma_start_write(vma); vma_start_write(new); init_vma_prep(&vp, vma); @@ -783,6 +790,27 @@ static void vmg_adjust_set_range(struct vma_merge_struct *vmg) } } +static void propagate_sticky_flags(struct vma_merge_struct *vmg, + const struct vm_area_struct *vma) +{ + const vma_flags_t sticky = + vma_flags_and_mask(&vma->flags, VMA_STICKY_FLAGS); + + /* Write lock prevents concurrent atomic VMA flag updates. */ + vma_assert_write_locked(vma); + vma_flags_set_mask(&vmg->vma_flags, sticky); +} + +static void commit_sticky_flags(struct vma_merge_struct *vmg) +{ + const vma_flags_t sticky = + vma_flags_and_mask(&vmg->vma_flags, VMA_STICKY_FLAGS); + struct vm_area_struct *target = vmg->target; + + vma_assert_write_locked(target); + vma_set_flags_mask(target, sticky); +} + /* * Actually perform the VMA merge operation. * @@ -818,6 +846,8 @@ static int commit_merge(struct vma_merge_struct *vmg) return -ENOMEM; vma_prepare(&vp); + /* Must be made visible before vma_complete() for rmap walkers. */ + commit_sticky_flags(vmg); /* * THP pages may need to do additional splits if we increase * middle->vm_start. @@ -857,8 +887,8 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) * merge. * * As part of this operation, if a merge occurs, the @vmg object will have its - * vma, start, end, and pgoff fields modified to execute the merge. Subsequent - * calls to this function should reset these fields. + * vma, start, end, pgoff and vma_flags fields modified to execute the merge. + * Subsequent calls to this function should reset these fields. * * Returns: The merged VMA if merge succeeds, or NULL otherwise. * @@ -872,8 +902,6 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) static __must_check struct vm_area_struct *vma_merge_existing_range( struct vma_merge_struct *vmg) { - vma_flags_t sticky_flags = vma_flags_and_mask(&vmg->vma_flags, - VMA_STICKY_FLAGS); struct vm_area_struct *middle = vmg->middle; struct vm_area_struct *prev = vmg->prev; struct vm_area_struct *next; @@ -948,6 +976,10 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (vmg->__remove_middle && !can_merge_remove_vma(middle)) return NULL; + /* If middle isn't removed then it's resized, i.e. splits. */ + if (!vmg->__remove_middle && check_split(middle, left_side ? end : start)) + return NULL; + /* * If we merge both VMAs, then next is also deleted. This implies * merge_will_delete_vma also. @@ -966,24 +998,18 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* No matter what happens, we will be adjusting middle. */ vma_start_write(middle); + propagate_sticky_flags(vmg, middle); if (merge_right) { - vma_flags_t next_sticky; - vma_start_write(next); vmg->target = next; - next_sticky = vma_flags_and_mask(&next->flags, VMA_STICKY_FLAGS); - vma_flags_set_mask(&sticky_flags, next_sticky); + propagate_sticky_flags(vmg, next); } if (merge_left) { - vma_flags_t prev_sticky; - vma_start_write(prev); vmg->target = prev; - - prev_sticky = vma_flags_and_mask(&prev->flags, VMA_STICKY_FLAGS); - vma_flags_set_mask(&sticky_flags, prev_sticky); + propagate_sticky_flags(vmg, prev); } if (merge_both) { @@ -1054,7 +1080,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (err || commit_merge(vmg)) goto abort; - vma_set_flags_mask(vmg->target, sticky_flags); khugepaged_enter_vma(vmg->target, vmg->vm_flags); vmg->state = VMA_MERGE_SUCCESS; return vmg->target; @@ -1127,6 +1152,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) struct vm_area_struct *next = vmg->next; unsigned long end = vmg->end; bool can_merge_left, can_merge_right; + bool move_iter_back = false; mmap_assert_write_locked(vmg->mm); VM_WARN_ON_VMG(vmg->middle, vmg); @@ -1168,23 +1194,30 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) vmg->end = end; /* In expand-only case we are already positioned at prev. */ - if (!vmg->just_expand) { - /* Equivalent to going to the previous range. */ - vma_prev(vmg->vmi); - } + if (!vmg->just_expand) + move_iter_back = true; } + if (!can_merge_left && !can_merge_right) + return NULL; + + if (move_iter_back) + vma_prev(vmg->vmi); + /* * Now try to expand adjacent VMA(s). This takes care of removing the * following VMA if we have VMAs on both sides. */ - if (vmg->target && !vma_expand(vmg)) { - khugepaged_enter_vma(vmg->target, vmg->vm_flags); - vmg->state = VMA_MERGE_SUCCESS; - return vmg->target; + if (vma_expand(vmg)) { + /* Error occurred, restore iterator. */ + if (move_iter_back) + vma_iter_next_range(vmg->vmi); + return NULL; } - return NULL; + khugepaged_enter_vma(vmg->target, vmg->vm_flags); + vmg->state = VMA_MERGE_SUCCESS; + return vmg->target; } /* @@ -1241,16 +1274,11 @@ int vma_expand(struct vma_merge_struct *vmg) struct vm_area_struct *target = vmg->target; struct vm_area_struct *next = vmg->next; bool remove_next = false; - vma_flags_t sticky_flags = - vma_flags_and_mask(&vmg->vma_flags, VMA_STICKY_FLAGS); - vma_flags_t target_sticky; int ret = 0; mmap_assert_write_locked(vmg->mm); vma_start_write(target); - target_sticky = vma_flags_and_mask(&target->flags, VMA_STICKY_FLAGS); - if (next && target != next && vmg->end == next->vm_end) remove_next = true; @@ -1265,7 +1293,7 @@ int vma_expand(struct vma_merge_struct *vmg) VM_WARN_ON_VMG(target->vm_start < vmg->start || target->vm_end > vmg->end, vmg); - vma_flags_set_mask(&sticky_flags, target_sticky); + propagate_sticky_flags(vmg, target); /* * If we are removing the next VMA or copying from a VMA @@ -1279,21 +1307,17 @@ int vma_expand(struct vma_merge_struct *vmg) if (!ret && vmg->copied_from) ret = dup_anon_vma(target, vmg->copied_from, &anon_dup); if (ret) - return ret; + goto nomem; if (remove_next) { - vma_flags_t next_sticky; - vma_start_write(next); vmg->__remove_next = true; - next_sticky = vma_flags_and_mask(&next->flags, VMA_STICKY_FLAGS); - vma_flags_set_mask(&sticky_flags, next_sticky); + propagate_sticky_flags(vmg, next); } if (commit_merge(vmg)) goto nomem; - vma_set_flags_mask(target, sticky_flags); return 0; nomem: @@ -1851,12 +1875,25 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta) { - VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); + const unsigned long start = + vma_can_merge(vma) ? vma->vm_end : vma->vm_start; + VMG_VMA_STATE(vmg, vmi, vma, vma, start, vma->vm_end + delta); - vmg.next = vma_iter_next_rewind(vmi, NULL); vmg.middle = NULL; /* We use the VMA to populate VMG fields only. */ - return vma_merge_new_range(&vmg); + if (vma_can_merge(vma)) { + vmg.next = vma_iter_next_rewind(vmi, NULL); + return vma_merge_new_range(&vmg); + } + + /* Mixed mappings are permitted to be expanded, not merged. */ + VM_WARN_ON_ONCE(vma_is_fixed_mapping(vma)); + VM_WARN_ON_ONCE(!vma_test(vma, VMA_MIXEDMAP_BIT)); + vma_prev(vmi); /* Reposition to start of VMA. */ + vmg.target = vma; + if (vma_expand(&vmg)) + return NULL; + return vma; } void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb) @@ -3380,7 +3417,8 @@ static int acct_stack_growth(struct vm_area_struct *vma, * Overcommit.. This must be the final test, as it will * update security statistics. */ - if (security_vm_enough_memory_mm(mm, grow)) + if (vma_test(vma, VMA_ACCOUNT_BIT) && + security_vm_enough_memory_mm(mm, grow)) return -ENOMEM; return 0; diff --git a/mm/vma_init.c b/mm/vma_init.c index baa7e82f47e3f8..d661f229a734f0 100644 --- a/mm/vma_init.c +++ b/mm/vma_init.c @@ -127,6 +127,9 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) { struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); + /* Must hold a write lock to stabilise atomic VMA flags. */ + vma_assert_write_locked(orig); + if (!new) return NULL; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f7aa4686fe5b9f..a4c22c569b1de9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -5374,7 +5374,7 @@ static void show_busy_info(struct seq_file *m) unsigned int *counters; if (IS_ENABLED(CONFIG_NUMA)) - counters = kmalloc_array(nr_node_ids, sizeof(unsigned int), GFP_KERNEL); + counters = kmalloc_objs(unsigned int, nr_node_ids); for_each_vmap_node(vn) { spin_lock(&vn->busy.lock); diff --git a/mm/vmscan.c b/mm/vmscan.c index 9959ca158ce835..6a1af9b92349fb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3911,7 +3911,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, walk->mm_stats[MM_NONLEAF_FOUND]++; - if (!walk_pte_range(&val, addr, next, args)) + if (!walk_pte_range(pmd + i, addr, next, args)) continue; walk->mm_stats[MM_NONLEAF_ADDED]++; @@ -3947,7 +3947,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end, if (!pud_present(val) || WARN_ON_ONCE(pud_leaf(val))) continue; - walk_pmd_range(&val, addr, next, args); + walk_pmd_range(pud + i, addr, next, args); if (need_resched() || walk->batched >= MAX_LRU_BATCH) { end = (addr | ~PUD_MASK) + 1; diff --git a/mm/vmstat.c b/mm/vmstat.c index a3e809c57f295a..c6beac6be2bc79 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1911,7 +1911,7 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) BUILD_BUG_ON(ARRAY_SIZE(vmstat_text) != NR_VMSTAT_ITEMS); fold_vm_numa_events(); - v = kmalloc_array(NR_VMSTAT_ITEMS, sizeof(unsigned long), GFP_KERNEL); + v = kmalloc_objs(unsigned long, NR_VMSTAT_ITEMS); m->private = v; if (!v) return ERR_PTR(-ENOMEM); diff --git a/net/9p/Kconfig b/net/9p/Kconfig index 22f8c167845d11..b0a6342e347584 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig @@ -32,6 +32,16 @@ config NET_9P_VIRTIO This builds support for a transports between guest partitions and a host partition. +config NET_9P_VSOCK + depends on NET_9P_FD + depends on VSOCKETS + bool "9P VSOCK Transport" + help + This builds support for a transport for 9pfs over + virtual sockets (vsock). This is useful for communication + between virtual machines and their host without requiring + TCP/IP networking configuration or additional userspace software. + config NET_9P_XEN depends on XEN select XEN_XENBUS_FRONTEND diff --git a/net/9p/client.c b/net/9p/client.c index ef64546c6d52a1..e63e8c2a853df7 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -448,6 +448,9 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode); } + if (!err) + err = -EPROTO; + return err; out_err: diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 67b0586d807f91..d4335884e0c08a 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -770,7 +770,7 @@ int p9dirent_read(struct p9_client *clnt, char *buf, int len, { struct p9_fcall fake_pdu; int ret; - char *nameptr; + char *nameptr = NULL; fake_pdu.size = len; fake_pdu.capacity = len; @@ -785,15 +785,7 @@ int p9dirent_read(struct p9_client *clnt, char *buf, int len, return ret; } - ret = strscpy(dirent->d_name, nameptr, sizeof(dirent->d_name)); - if (ret < 0) { - p9_debug(P9_DEBUG_ERROR, - "On the wire dirent name too long: %s\n", - nameptr); - kfree(nameptr); - return ret; - } - kfree(nameptr); + dirent->d_name = nameptr; return fake_pdu.offset; } diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index eb685b52aeb264..159d57e41e56f6 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -28,6 +28,9 @@ #include #include #include +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) +#include +#endif #include /* killme */ @@ -36,6 +39,9 @@ static struct p9_trans_module p9_tcp_trans; static struct p9_trans_module p9_fd_trans; +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) +static struct p9_trans_module p9_vsock_trans; +#endif enum { Rworksched = 1, /* read work scheduled or running */ @@ -714,6 +720,12 @@ static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt) if (clnt->trans_opts.fd.wfd != ~0) seq_printf(m, ",wfd=%u", clnt->trans_opts.fd.wfd); } +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) + else if (clnt->trans_mod == &p9_vsock_trans) { + if (clnt->trans_opts.vsock.port != P9_FD_PORT) + seq_printf(m, ",port=%u", clnt->trans_opts.vsock.port); + } +#endif return 0; } @@ -875,7 +887,7 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc) const char *addr = fc->source; struct v9fs_context *ctx = fc->fs_private; int err; - char port_str[6]; + char port_str[11]; struct socket *csocket; struct sockaddr_storage stor = { 0 }; struct p9_fd_opts opts; @@ -887,8 +899,8 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc) return -EINVAL; sprintf(port_str, "%u", opts.port); - err = inet_pton_with_scope(current->nsproxy->net_ns, AF_UNSPEC, addr, - port_str, &stor); + err = inet_pton_with_scope(fc->net_ns, AF_UNSPEC, addr, port_str, + &stor); if (err < 0) return err; @@ -896,8 +908,8 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc) client->trans_opts.tcp.port = opts.port; client->trans_opts.tcp.privport = opts.privport; - err = __sock_create(current->nsproxy->net_ns, stor.ss_family, - SOCK_STREAM, IPPROTO_TCP, &csocket, 1); + err = __sock_create(fc->net_ns, stor.ss_family, SOCK_STREAM, + IPPROTO_TCP, &csocket, 1); if (err) { pr_err("%s (%d): problem creating socket\n", __func__, task_pid_nr(current)); @@ -946,8 +958,7 @@ p9_fd_create_unix(struct p9_client *client, struct fs_context *fc) __func__, task_pid_nr(current), addr); return -ENAMETOOLONG; } - err = __sock_create(current->nsproxy->net_ns, PF_UNIX, - SOCK_STREAM, 0, &csocket, 1); + err = __sock_create(fc->net_ns, PF_UNIX, SOCK_STREAM, 0, &csocket, 1); if (err < 0) { pr_err("%s (%d): problem creating socket\n", __func__, task_pid_nr(current)); @@ -966,6 +977,67 @@ p9_fd_create_unix(struct p9_client *client, struct fs_context *fc) return p9_socket_open(client, csocket); } +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) +static int +p9_fd_create_vsock(struct p9_client *client, struct fs_context *fc) +{ + const char *addr = fc->source; + struct v9fs_context *ctx = fc->fs_private; + int err; + struct socket *csocket; + struct sockaddr_vm addr_vm = { 0 }; + struct p9_fd_opts opts; + unsigned int cid; + + /* opts are already parsed in context */ + opts = ctx->fd_opts; + + if (opts.privport) { + // TODO: implement vsock privileged port binding + pr_err("%s (%d): privport currently not implemented for vsock\n", + __func__, task_pid_nr(current)); + return -EOPNOTSUPP; + } + + if (!addr) + return -EINVAL; + + err = kstrtouint(addr, 10, &cid); + if (err < 0) { + pr_err("%s (%d): invalid CID: %s\n", + __func__, task_pid_nr(current), addr); + return err; + } + + csocket = NULL; + + client->trans_opts.vsock.port = opts.port; + err = __sock_create(fc->net_ns, AF_VSOCK, + SOCK_STREAM, 0, &csocket, 1); + if (err) { + pr_err("%s (%d): problem creating socket\n", + __func__, task_pid_nr(current)); + return err; + } + + addr_vm.svm_family = AF_VSOCK; + addr_vm.svm_port = opts.port; + addr_vm.svm_cid = cid; + + err = READ_ONCE(csocket->ops)->connect(csocket, + (struct sockaddr_unsized *)&addr_vm, + sizeof(addr_vm), 0); + if (err < 0) { + pr_err("%s (%d): problem connecting socket to %s:%u\n", + __func__, task_pid_nr(current), addr, opts.port); + sock_release(csocket); + return err; + } + + return p9_socket_open(client, csocket); +} +#endif /* CONFIG_NET_9P_VSOCK */ + static int p9_fd_create(struct p9_client *client, struct fs_context *fc) { @@ -1036,6 +1108,23 @@ static struct p9_trans_module p9_fd_trans = { }; MODULE_ALIAS_9P("fd"); +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) +static struct p9_trans_module p9_vsock_trans = { + .name = "vsock", + .maxsize = MAX_SOCK_BUF, + .def = false, + .supports_vmalloc = true, + .create = p9_fd_create_vsock, + .close = p9_fd_close, + .request = p9_fd_request, + .cancel = p9_fd_cancel, + .cancelled = p9_fd_cancelled, + .show_options = p9_fd_show_options, + .owner = THIS_MODULE, +}; +MODULE_ALIAS_9P("vsock"); +#endif + /** * p9_poll_workfn - poll worker thread * @work: work queue @@ -1073,6 +1162,9 @@ static int __init p9_trans_fd_init(void) v9fs_register_trans(&p9_tcp_trans); v9fs_register_trans(&p9_unix_trans); v9fs_register_trans(&p9_fd_trans); +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) + v9fs_register_trans(&p9_vsock_trans); +#endif return 0; } @@ -1083,6 +1175,9 @@ static void __exit p9_trans_fd_exit(void) v9fs_unregister_trans(&p9_tcp_trans); v9fs_unregister_trans(&p9_unix_trans); v9fs_unregister_trans(&p9_fd_trans); +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) + v9fs_unregister_trans(&p9_vsock_trans); +#endif } module_init(p9_trans_fd_init); diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index b4274f10fa4487..f4450e779a7919 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -556,7 +556,7 @@ rdma_create_trans(struct p9_client *client, struct fs_context *fc) return -ENOMEM; /* Create the RDMA CM ID */ - rdma->cm_id = rdma_create_id(&init_net, p9_cm_event_handler, client, + rdma->cm_id = rdma_create_id(fc->net_ns, p9_cm_event_handler, client, RDMA_PS_TCP, IB_QPT_RC); if (IS_ERR(rdma->cm_id)) goto error; diff --git a/net/9p/trans_usbg.c b/net/9p/trans_usbg.c index 419cda13a7b568..45b0ea594211c3 100644 --- a/net/9p/trans_usbg.c +++ b/net/9p/trans_usbg.c @@ -149,7 +149,8 @@ static void usb9pfs_tx_complete(struct usb_ep *ep, struct usb_request *req) { struct f_usb9pfs *usb9pfs = ep->driver_data; struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; - struct p9_req_t *p9_tx_req = req->context; + struct p9_client *client; + struct p9_req_t *p9_tx_req; unsigned long flags; /* reset zero packages */ @@ -165,18 +166,25 @@ static void usb9pfs_tx_complete(struct usb_ep *ep, struct usb_request *req) ep->name, req->status, req->actual, req->length); spin_lock_irqsave(&usb9pfs->lock, flags); - WRITE_ONCE(p9_tx_req->status, REQ_STATUS_SENT); + client = usb9pfs->client; + p9_tx_req = req->context; + req->context = NULL; - p9_req_put(usb9pfs->client, p9_tx_req); + if (!client || !p9_tx_req) + goto unlock_complete; - req->context = NULL; + WRITE_ONCE(p9_tx_req->status, REQ_STATUS_SENT); + p9_req_put(client, p9_tx_req); + +unlock_complete: spin_unlock_irqrestore(&usb9pfs->lock, flags); complete(&usb9pfs->send); } -static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf) +static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, + struct p9_client *client, void *buf) { struct p9_req_t *p9_rx_req; struct p9_fcall rc; @@ -202,7 +210,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf) "mux %p pkt: size: %d bytes tag: %d\n", usb9pfs, rc.size, rc.tag); - p9_rx_req = p9_tag_lookup(usb9pfs->client, rc.tag); + p9_rx_req = p9_tag_lookup(client, rc.tag); if (!p9_rx_req || p9_rx_req->status != REQ_STATUS_SENT) { p9_debug(P9_DEBUG_ERROR, "Unexpected packet tag %d\n", rc.tag); return NULL; @@ -212,7 +220,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf) p9_debug(P9_DEBUG_ERROR, "requested packet size too big: %d for tag %d with capacity %zd\n", rc.size, rc.tag, p9_rx_req->rc.capacity); - p9_req_put(usb9pfs->client, p9_rx_req); + p9_req_put(client, p9_rx_req); return NULL; } @@ -220,7 +228,7 @@ static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf) p9_debug(P9_DEBUG_ERROR, "No recv fcall for tag %d (req %p), disconnecting!\n", rc.tag, p9_rx_req); - p9_req_put(usb9pfs->client, p9_rx_req); + p9_req_put(client, p9_rx_req); return NULL; } @@ -231,8 +239,10 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) { struct f_usb9pfs *usb9pfs = ep->driver_data; struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; + struct p9_client *client; struct p9_req_t *p9_rx_req; unsigned int req_size = req->actual; + unsigned long flags; int status = REQ_STATUS_RCVD; if (req->status) { @@ -241,9 +251,16 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) return; } - p9_rx_req = usb9pfs_rx_header(usb9pfs, req->buf); - if (!p9_rx_req) + spin_lock_irqsave(&usb9pfs->lock, flags); + client = usb9pfs->client; + if (!client) { + spin_unlock_irqrestore(&usb9pfs->lock, flags); return; + } + + p9_rx_req = usb9pfs_rx_header(usb9pfs, client, req->buf); + if (!p9_rx_req) + goto out_unlock; if (req_size > p9_rx_req->rc.capacity) { dev_err(&cdev->gadget->dev, @@ -257,8 +274,11 @@ static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) p9_rx_req->rc.size = req_size; - p9_client_cb(usb9pfs->client, p9_rx_req, status); - p9_req_put(usb9pfs->client, p9_rx_req); + p9_client_cb(client, p9_rx_req, status); + p9_req_put(client, p9_rx_req); + +out_unlock: + spin_unlock_irqrestore(&usb9pfs->lock, flags); complete(&usb9pfs->received); } @@ -278,18 +298,18 @@ static void disable_usb9pfs(struct f_usb9pfs *usb9pfs) struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; + disable_ep(cdev, usb9pfs->in_ep); + disable_ep(cdev, usb9pfs->out_ep); + if (usb9pfs->in_req) { usb_ep_free_request(usb9pfs->in_ep, usb9pfs->in_req); usb9pfs->in_req = NULL; } if (usb9pfs->out_req) { - usb_ep_free_request(usb9pfs->out_ep, usb9pfs->out_req); + free_ep_req(usb9pfs->out_ep, usb9pfs->out_req); usb9pfs->out_req = NULL; } - - disable_ep(cdev, usb9pfs->in_ep); - disable_ep(cdev, usb9pfs->out_ep); dev_dbg(&cdev->gadget->dev, "%s disabled\n", usb9pfs->function.name); } @@ -314,10 +334,6 @@ static int alloc_requests(struct usb_composite_dev *cdev, usb9pfs->in_req->complete = usb9pfs_tx_complete; usb9pfs->out_req->complete = usb9pfs_rx_complete; - /* length will be set in complete routine */ - usb9pfs->in_req->context = usb9pfs; - usb9pfs->out_req->context = usb9pfs; - return 0; fail_in: @@ -391,7 +407,7 @@ static int p9_usbg_create(struct p9_client *client, struct fs_context *fc) guard(mutex)(&usb9pfs_lock); list_for_each_entry(dev, &usbg_instance_list, usb9pfs_instance) { - if (!strncmp(devname, dev->tag, strlen(devname))) { + if (!strcmp(devname, dev->tag)) { if (!dev->inuse) { dev->inuse = true; found = 1; @@ -416,7 +432,9 @@ static int p9_usbg_create(struct p9_client *client, struct fs_context *fc) client->status = Disconnected; else client->status = Connected; + spin_lock_irq(&usb9pfs->lock); usb9pfs->client = client; + spin_unlock_irq(&usb9pfs->lock); client->trans_mod->maxsize = usb9pfs->buflen; @@ -427,18 +445,31 @@ static int p9_usbg_create(struct p9_client *client, struct fs_context *fc) static void usb9pfs_clear_tx(struct f_usb9pfs *usb9pfs) { + struct p9_client *client; struct p9_req_t *req; + unsigned long flags; - guard(spinlock_irqsave)(&usb9pfs->lock); + spin_lock_irqsave(&usb9pfs->lock, flags); + client = usb9pfs->client; + usb9pfs->client = NULL; + req = usb9pfs->in_req ? usb9pfs->in_req->context : NULL; + if (usb9pfs->in_req) + usb9pfs->in_req->context = NULL; + spin_unlock_irqrestore(&usb9pfs->lock, flags); + + if (!req || !client) + return; + + usb9pfs->in_req->context = NULL; - req = usb9pfs->in_req->context; - if (!req) + if (!usb9pfs->client) return; if (!req->t_err) req->t_err = -ECONNRESET; - p9_client_cb(usb9pfs->client, req, REQ_STATUS_ERROR); + p9_client_cb(client, req, REQ_STATUS_ERROR); + usb9pfs->in_req->context = NULL; } static void p9_usbg_close(struct p9_client *client) @@ -457,6 +488,7 @@ static void p9_usbg_close(struct p9_client *client) client->status = Disconnected; usb9pfs_clear_tx(usb9pfs); + usb9pfs->client = NULL; opts = container_of(usb9pfs->function.fi, struct f_usb9pfs_opts, func_inst); @@ -466,6 +498,9 @@ static void p9_usbg_close(struct p9_client *client) mutex_lock(&usb9pfs_lock); dev->inuse = false; mutex_unlock(&usb9pfs_lock); + + disable_usb9pfs(usb9pfs); + reinit_completion(&usb9pfs->send); } static int p9_usbg_request(struct p9_client *client, struct p9_req_t *p9_req) @@ -725,8 +760,6 @@ static void usb9pfs_free_func(struct usb_function *f) struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); struct f_usb9pfs_opts *opts; - kfree(usb9pfs); - opts = container_of(f->fi, struct f_usb9pfs_opts, func_inst); mutex_lock(&opts->lock); @@ -734,6 +767,8 @@ static void usb9pfs_free_func(struct usb_function *f) mutex_unlock(&opts->lock); usb_free_all_descriptors(f); + + kfree(usb9pfs); } static int usb9pfs_set_alt(struct usb_function *f, @@ -748,8 +783,18 @@ static int usb9pfs_set_alt(struct usb_function *f, static void usb9pfs_disable(struct usb_function *f) { struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); + unsigned long flags; + spin_lock_irqsave(&usb9pfs->lock, flags); + if (usb9pfs->client) + usb9pfs->client->status = Disconnected; + spin_unlock_irqrestore(&usb9pfs->lock, flags); usb9pfs_clear_tx(usb9pfs); + + if (usb9pfs->in_ep->enabled) + disable_usb9pfs(usb9pfs); + + reinit_completion(&usb9pfs->send); } static struct usb_function *usb9pfs_alloc(struct usb_function_instance *fi) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index b0d0094ec8e2c8..9fa63e3ebf6730 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -633,6 +633,11 @@ static int p9_virtio_probe(struct virtio_device *vdev) err = -EINVAL; goto out_free_vq; } + if (tag_len > NAME_MAX) { + dev_err(&vdev->dev, "mount tag too long (%u bytes)\n", tag_len); + err = -EINVAL; + goto out_free_vq; + } tag = kzalloc(tag_len + 1, GFP_KERNEL); if (!tag) { err = -ENOMEM; diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c index f9fb2db7a0663c..690d941236b680 100644 --- a/net/9p/trans_xen.c +++ b/net/9p/trans_xen.c @@ -55,7 +55,7 @@ struct xen_9pfs_front_priv { char *tag; struct p9_client *client; - struct xen_9pfs_dataring *rings; + struct xen_9pfs_dataring rings[XEN_9PFS_NUM_RINGS]; }; static LIST_HEAD(xen_9pfs_devs); @@ -200,9 +200,19 @@ static void p9_xen_response(struct work_struct *work) masked_prod, &masked_cons, XEN_9PFS_RING_SIZE(ring)); + if (h.size < sizeof(h) || + h.size > xen_9pfs_queued(prod, cons, + XEN_9PFS_RING_SIZE(ring))) { + dev_warn_ratelimited(&priv->dev->dev, + "bad response size %u from backend\n", h.size); + break; + } + req = p9_tag_lookup(priv->client, h.tag); if (!req || req->status != REQ_STATUS_SENT) { dev_warn(&priv->dev->dev, "Wrong req tag=%x\n", h.tag); + if (req) + p9_req_put(priv->client, req); cons += h.size; virt_mb(); ring->intf->in_cons = cons; @@ -277,41 +287,37 @@ static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv) { int i, j; - if (priv->rings) { - for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { - struct xen_9pfs_dataring *ring = &priv->rings[i]; + for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { + struct xen_9pfs_dataring *ring = &priv->rings[i]; - cancel_work_sync(&ring->work); + if (!ring->intf) + break; + if (ring->irq >= 0) { + unbind_from_irqhandler(ring->irq, ring); + ring->irq = -1; + } + cancel_work_sync(&ring->work); - if (!ring->intf) - break; - if (ring->irq >= 0) { - unbind_from_irqhandler(ring->irq, ring); - ring->irq = -1; - } - if (ring->data.in) { - for (j = 0; j < (1 << ring->intf->ring_order); - j++) { - grant_ref_t ref; - - ref = ring->intf->ref[j]; - gnttab_end_foreign_access(ref, NULL); - ring->intf->ref[j] = INVALID_GRANT_REF; - } - free_pages_exact(ring->data.in, - 1UL << (ring->intf->ring_order + - XEN_PAGE_SHIFT)); - ring->data.in = NULL; - ring->data.out = NULL; - } - if (ring->ref != INVALID_GRANT_REF) { - gnttab_end_foreign_access(ring->ref, NULL); - ring->ref = INVALID_GRANT_REF; + if (ring->data.in) { + for (j = 0; j < (1 << ring->intf->ring_order); j++) { + grant_ref_t ref; + + ref = ring->intf->ref[j]; + gnttab_end_foreign_access(ref, NULL); + ring->intf->ref[j] = INVALID_GRANT_REF; } - free_page((unsigned long)ring->intf); - ring->intf = NULL; + free_pages_exact(ring->data.in, + 1UL << (ring->intf->ring_order + + XEN_PAGE_SHIFT)); + ring->data.in = NULL; + ring->data.out = NULL; } - kfree(priv->rings); + if (ring->ref != INVALID_GRANT_REF) { + gnttab_end_foreign_access(ring->ref, NULL); + ring->ref = INVALID_GRANT_REF; + } + free_page((unsigned long)ring->intf); + ring->intf = NULL; } kfree(priv->tag); kfree(priv); @@ -450,11 +456,6 @@ static int xen_9pfs_front_init(struct xenbus_device *dev) if (!priv) return -ENOMEM; priv->dev = dev; - priv->rings = kzalloc_objs(*priv->rings, XEN_9PFS_NUM_RINGS); - if (!priv->rings) { - kfree(priv); - return -ENOMEM; - } for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { priv->rings[i].priv = priv; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 89b499f7a37dd7..85e99506a53f5e 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -1410,7 +1410,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, return BATADV_NO_DUP; orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); - if (WARN_ON(!orig_ifinfo)) { + if (!orig_ifinfo) { batadv_orig_node_put(orig_node); return 0; } @@ -1909,6 +1909,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } + /* Mark aggregate as full before forcing emit. */ + spin_lock_bh(&bat_priv->forw_bat_list_lock); + forw_packet->num_packets = BATADV_MAX_AGGREGATION_PACKETS; + spin_unlock_bh(&bat_priv->forw_bat_list_lock); + batadv_iv_ogm_emit(forw_packet); /* we have to have at least one packet in the queue to determine the diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index 74050bffedbceb..0260ed7e828b20 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -653,6 +653,7 @@ static void batadv_choose_next_candidate(struct batadv_priv *bat_priv, * NOT_FOUND */ cands[select].type = BATADV_DAT_CANDIDATE_NOT_FOUND; + cands[select].orig_node = NULL; /* iterate over the originator list and find the node with the closest * dat_address which has not been selected yet diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 6c54a8d4be3ec1..3b9fa861be7be6 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -295,6 +295,11 @@ void batadv_mesh_free(struct net_device *mesh_iface) WRITE_ONCE(bat_priv->mesh_state, BATADV_MESH_DEACTIVATING); + /* the originator purge worker accesses (among others) the TT tables + * and must therefore be stopped before any of them are freed + */ + disable_delayed_work_sync(&bat_priv->orig_work); + batadv_purge_outstanding_packets(bat_priv, NULL); batadv_tp_stop_all(bat_priv); @@ -484,8 +489,10 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, * shut down otherwise the packet may trigger de-reference errors * further down in the receive path. */ - if (!kref_get_unless_zero(&hard_iface->refcount)) - goto err_out; + if (!kref_get_unless_zero(&hard_iface->refcount)) { + kfree_skb(skb); + return NET_RX_DROP; + } skb = skb_share_check(skb, GFP_ATOMIC); @@ -541,7 +548,6 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, kfree_skb(skb); err_put: batadv_hardif_put(hard_iface); -err_out: return NET_RX_DROP; } diff --git a/net/batman-adv/multicast_forw.c b/net/batman-adv/multicast_forw.c index ac97cd8b81dc9c..9ffed1f237b6b7 100644 --- a/net/batman-adv/multicast_forw.c +++ b/net/batman-adv/multicast_forw.c @@ -950,8 +950,11 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv, dest = (u8 *)mcast_tracker + sizeof(*mcast_tracker); - /* check if full tracker tvlv is within skb length */ + /* check if full tracker tvlv, including padding, is within skb length */ tvlv_len = sizeof(*mcast_tracker) + ETH_ALEN * num_dests; + if (!(num_dests % 2)) + tvlv_len += 2; + if (tvlv_len > skb_network_header_len(skb)) return -EINVAL; diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c index 022eb13e8ec475..56feb02d2b7efd 100644 --- a/net/batman-adv/tp_meter.c +++ b/net/batman-adv/tp_meter.c @@ -221,7 +221,7 @@ static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason, unsigned long start_time, u64 total_sent, u32 cookie) { - u32 total_bytes; + u64 total_bytes; u32 test_time; u8 result; diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 3349376a9087dc..46304069b3b75c 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -26,8 +26,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -253,7 +255,8 @@ static int batadv_tt_len(int changes_num) * * Return: local translation table size in bytes. */ -static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries) +static int batadv_tt_local_transmit_size(unsigned int num_vlan, + unsigned int num_entries) { int hdr_size; @@ -266,6 +269,25 @@ static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries) return hdr_size + batadv_tt_len(num_entries); } +/** + * batadv_tt_local_transmit_size_max() - get the maximum size of a full local table + * response + * @bat_priv: the bat priv with all the mesh interface information + * + * The full table response is sent as a single unicast TVLV packet. Its + * tvlv_len, which covers the TVLV header and the TT TVLV, is only 16 bit wide. + * This limits the response size even when packet_size_max is larger. + * + * Return: maximum size of a full local table response in bytes + */ +static int batadv_tt_local_transmit_size_max(struct batadv_priv *bat_priv) +{ + int tvlv_size_max = sizeof(struct batadv_unicast_tvlv_packet) + U16_MAX; + int packet_size_max = READ_ONCE(bat_priv->packet_size_max); + + return min(packet_size_max, tvlv_size_max); +} + /** * batadv_tt_local_reserve() - reserve room in the transmittable local table * @bat_priv: the bat priv with all the mesh interface information @@ -290,22 +312,23 @@ static int batadv_tt_local_transmit_size(u16 num_vlan, u16 num_entries) static bool batadv_tt_local_reserve(struct batadv_priv *bat_priv, u16 num_vlan, u16 num_entries, int *table_size) { - int packet_size_max = READ_ONCE(bat_priv->packet_size_max); + int size_max = batadv_tt_local_transmit_size_max(bat_priv); + unsigned int entries; + unsigned int vlans; scoped_guard(spinlock_bh, &bat_priv->tt.reserve_lock) { - bat_priv->tt.reserved_vlans += num_vlan; - bat_priv->tt.reserved_entries += num_entries; + vlans = bat_priv->tt.reserved_vlans + num_vlan; + entries = bat_priv->tt.reserved_entries + num_entries; - *table_size = batadv_tt_local_transmit_size(bat_priv->tt.reserved_vlans, - bat_priv->tt.reserved_entries); - if (*table_size <= packet_size_max) - return true; + *table_size = batadv_tt_local_transmit_size(vlans, entries); + if (*table_size > size_max) + return false; - bat_priv->tt.reserved_vlans -= num_vlan; - bat_priv->tt.reserved_entries -= num_entries; + bat_priv->tt.reserved_vlans = vlans; + bat_priv->tt.reserved_entries = entries; } - return false; + return true; } /** @@ -339,9 +362,10 @@ static bool batadv_tt_local_reserve_entry(struct batadv_priv *bat_priv, return true; net_ratelimited_function(batadv_info, bat_priv->mesh_iface, - "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", + "Local translation table size (%i) exceeds maximum table response size (%i); Ignoring new local tt entry: %pM\n", table_size, - READ_ONCE(bat_priv->packet_size_max), addr); + batadv_tt_local_transmit_size_max(bat_priv), + addr); return false; } @@ -374,8 +398,9 @@ bool batadv_tt_local_reserve_vlan(struct batadv_priv *bat_priv, return true; net_ratelimited_function(batadv_info, bat_priv->mesh_iface, - "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new VLAN: %d\n", - table_size, READ_ONCE(bat_priv->packet_size_max), + "Local translation table size (%i) exceeds maximum table response size (%i); Ignoring new VLAN: %d\n", + table_size, + batadv_tt_local_transmit_size_max(bat_priv), batadv_print_vid(vid)); return false; @@ -622,6 +647,9 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common) * @bat_priv: the bat priv with all the mesh interface information * @common: the TT entry involved in the event * @flags: flags of the TT entry combined with the event flags + * + * Only a single change per client is queued. It describes the latest state of + * the client and a new event therefore replaces an already queued one. */ static void __batadv_tt_local_event(struct batadv_priv *bat_priv, const struct batadv_tt_common_entry *common, @@ -631,7 +659,6 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv, struct batadv_tt_change_node *entry; struct batadv_tt_change_node *safe; bool del_op_requested; - bool del_op_entry; size_t changes; tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); @@ -643,9 +670,17 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv, ether_addr_copy(tt_change_node->change.addr, common->addr); tt_change_node->change.vid = htons(common->vid); - tt_change_node->change.flags = flags; del_op_requested = flags & BATADV_TT_CLIENT_DEL; + /* the ROAM flag is only meaningful for the receiver in combination + * with a DEL. An ADD with ROAM would be interpreted as a roaming + * advertisement + */ + if (!del_op_requested) + flags &= ~BATADV_TT_CLIENT_ROAM; + + tt_change_node->change.flags = flags; + /* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */ spin_lock_bh(&bat_priv->tt.changes_list_lock); changes = READ_ONCE(bat_priv->tt.local_changes); @@ -657,25 +692,12 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv, if (entry->change.vid != tt_change_node->change.vid) continue; - del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL; - if (del_op_requested != del_op_entry) { - /* DEL+ADD in the same orig interval have no effect and - * can be removed to avoid silly behaviour on the - * receiver side. The other way around (ADD+DEL) can - * happen in case of roaming of a client still in the - * NEW state. Roaming of NEW clients is now possible due - * to automatically recognition of "temporary" clients - */ - list_del(&entry->list); - kmem_cache_free(batadv_tt_change_cache, entry); - changes--; - } else { - /* this is a second add or del in the same originator - * interval. It could mean that flags have been changed - * (e.g. double add): update them - */ - entry->change.flags = flags; - } + /* the other nodes may know the client with different + * flags. A DEL+ADD must therefore still announce the + * current flags and an ADD+DEL must still remove the + * client. ADD+ADD and DEL+DEL only update the flags + */ + entry->change.flags = flags; kmem_cache_free(batadv_tt_change_cache, tt_change_node); goto update_changes; @@ -727,9 +749,9 @@ static u16 batadv_tt_entries(u16 tt_len) */ static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv) { + unsigned int tt_local_entries = 0; struct batadv_meshif_vlan *vlan; - u16 tt_local_entries = 0; - u16 num_vlan = 0; + unsigned int num_vlan = 0; rcu_read_lock(); hlist_for_each_entry_rcu(vlan, &bat_priv->meshif_vlan_list, list) { @@ -811,14 +833,21 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv, if (!tt_global) return; - /* Check whether it is a roaming, but don't do anything if the roaming - * process has already been handled + /* Handle newly roamed client - but not roamed back client. + * + * A client which roamed back must always be reclaimed from the + * originator(s) which sent the ROAMING_ADV. The global entry created by + * this ROAMING_ADV might still carry BATADV_TT_CLIENT_ROAM because the + * new originator did not yet announce the client. */ - scoped_guard(spinlock_bh, &tt_global->common.flags_lock) { - if (tt_global->common.flags & BATADV_TT_CLIENT_ROAM) - return; + if (!roamed_back) { + scoped_guard(spinlock_bh, &tt_global->common.flags_lock) { + /* Check whether it is a roaming, but don't do anything + * if the roaming process has already been handled. + */ + if (tt_global->common.flags & BATADV_TT_CLIENT_ROAM) + return; - if (!roamed_back) { /* The global entry has to be marked as ROAMING and has to be * kept for consistency purpose. * @@ -886,6 +915,7 @@ static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv, bool *roamed_back) { struct batadv_tt_common_entry *common = &tt_local->common; + bool readded = false; tt_local->last_seen = jiffies; @@ -900,8 +930,7 @@ static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv, * flag can be reset like it was never enqueued */ common->flags &= ~BATADV_TT_CLIENT_PENDING; - - return true; + readded = true; } if (common->flags & BATADV_TT_CLIENT_ROAM) { @@ -918,7 +947,7 @@ static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv, } } - return false; + return readded; } /** @@ -1319,22 +1348,24 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, * batadv_tt_tvlv_container_update() - update the translation table tvlv * container after local tt changes have been committed * @bat_priv: the bat priv with all the mesh interface information + * @changes_list: list of committed changes which will be consumed + * @tt_diff_entries_num: number of entries in @changes_list */ -static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) +static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv, + struct list_head *changes_list, + int tt_diff_entries_num) { struct batadv_tvlv_tt_change *tt_change; struct batadv_tt_change_node *entry; struct batadv_tvlv_tt_data *tt_data; struct batadv_tt_change_node *safe; int tt_diff_entries_count = 0; - int tt_diff_entries_num = 0; bool drop_changes = false; size_t tt_extra_len = 0; int tt_change_len = 0; int tt_diff_len; u16 tvlv_len; - tt_diff_entries_num = READ_ONCE(bat_priv->tt.local_changes); tt_diff_len = batadv_tt_len(tt_diff_entries_num); /* if we have too many changes for one packet don't send any @@ -1352,19 +1383,39 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data, &tt_change, &tt_diff_len); - if (!tvlv_len) + if (!tvlv_len) { + /* the changes are lost and the other nodes have to request the + * full table. Don't answer TT requests for the new TTVN with + * the stale changeset of the previous TTVN. Without changes, the + * TTVN was not incremented and the last changeset is still valid + */ + if (drop_changes || tt_diff_entries_num > 0) { + list_for_each_entry_safe(entry, safe, changes_list, + list) { + list_del(&entry->list); + kmem_cache_free(batadv_tt_change_cache, entry); + } + + spin_lock_bh(&bat_priv->tt.last_changeset_lock); + kfree(bat_priv->tt.last_changeset); + bat_priv->tt.last_changeset = NULL; + bat_priv->tt.last_changeset_len = 0; + spin_unlock_bh(&bat_priv->tt.last_changeset_lock); + } + + /* announce the already committed TTVN in the next OGM interval + * instead of waiting for BATADV_TT_OGM_APPEND_MAX idle rounds + */ + atomic_set(&bat_priv->tt.ogm_append_cnt, 0); return; + } tt_data->flags = BATADV_TT_OGM_DIFF; if (!drop_changes && tt_diff_len == 0) goto container_register; - spin_lock_bh(&bat_priv->tt.changes_list_lock); - WRITE_ONCE(bat_priv->tt.local_changes, 0); - - list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, - list) { + list_for_each_entry_safe(entry, safe, changes_list, list) { if (tt_diff_entries_count < tt_diff_entries_num) { memcpy(tt_change + tt_diff_entries_count, &entry->change, @@ -1374,7 +1425,6 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) list_del(&entry->list); kmem_cache_free(batadv_tt_change_cache, entry); } - spin_unlock_bh(&bat_priv->tt.changes_list_lock); tt_extra_len = batadv_tt_len(tt_diff_entries_num - tt_diff_entries_count); @@ -3342,8 +3392,12 @@ static bool batadv_tt_local_valid(void *entry_ptr, if (tt_flags & BATADV_TT_CLIENT_NEW) return false; + /* the entry is (still) announced. A ROAM flag of an entry which is + * pending to be removed must not be transmitted. Otherwise, the + * receiver would handle it like a roaming advertisement + */ if (flags) - *flags = tt_flags; + *flags = tt_flags & ~BATADV_TT_CLIENT_ROAM; return true; } @@ -3922,21 +3976,30 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv, u16 tt_num_changes, u8 ttvn) { int roams; + u8 flags; int i; for (i = 0; i < tt_num_changes; i++) { - if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) { - roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM; + flags = (tt_change + i)->flags; + + if (flags & BATADV_TT_CLIENT_DEL) { + roams = flags & BATADV_TT_CLIENT_ROAM; batadv_tt_global_del(bat_priv, orig_node, (tt_change + i)->addr, ntohs((tt_change + i)->vid), "tt removed by changes", roams); } else { + /* an announced client cannot have roamed away from + * orig_node. Only a ROAMING_ADV is allowed to add a + * global entry with the ROAM flag + */ + flags &= ~BATADV_TT_CLIENT_ROAM; + if (!batadv_tt_global_add(bat_priv, orig_node, (tt_change + i)->addr, ntohs((tt_change + i)->vid), - (tt_change + i)->flags, ttvn)) + flags, ttvn)) /* In case of problem while storing a * global_entry, we stop the updating * procedure without committing the @@ -4412,11 +4475,25 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv) */ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv) { + LIST_HEAD(changes_list); + int changes_num; + lockdep_assert_held(&bat_priv->tt.commit_lock); - if (READ_ONCE(bat_priv->tt.local_changes) == 0) { + /* atomically get the list of changes. The TTVN decision and the + * announced changeset must cover the same events. Events queued + * afterwards stay in the tt.changes_list for the next TT round + */ + spin_lock_bh(&bat_priv->tt.changes_list_lock); + list_splice_init(&bat_priv->tt.changes_list, &changes_list); + changes_num = READ_ONCE(bat_priv->tt.local_changes); + WRITE_ONCE(bat_priv->tt.local_changes, 0); + spin_unlock_bh(&bat_priv->tt.changes_list_lock); + + if (changes_num == 0) { if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt)) - batadv_tt_tvlv_container_update(bat_priv); + batadv_tt_tvlv_container_update(bat_priv, &changes_list, + changes_num); return; } @@ -4433,7 +4510,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv) /* reset the sending counter */ atomic_set(&bat_priv->tt.ogm_append_cnt, BATADV_TT_OGM_APPEND_MAX); - batadv_tt_tvlv_container_update(bat_priv); + batadv_tt_tvlv_container_update(bat_priv, &changes_list, changes_num); } /** @@ -4675,16 +4752,16 @@ void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface) struct batadv_priv *bat_priv = netdev_priv(mesh_iface); int timeout = BATADV_TT_LOCAL_TIMEOUT / 2; bool reduced = false; - int packet_size_max; int table_size; + int size_max; - packet_size_max = READ_ONCE(bat_priv->packet_size_max); + size_max = batadv_tt_local_transmit_size_max(bat_priv); spin_lock_bh(&bat_priv->tt.commit_lock); while (timeout) { table_size = batadv_tt_local_table_transmit_size(bat_priv); - if (packet_size_max >= table_size) + if (size_max >= table_size) break; batadv_tt_local_purge(bat_priv, timeout); @@ -4693,8 +4770,8 @@ void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface) timeout /= 2; reduced = true; net_ratelimited_function(batadv_info, mesh_iface, - "Forced to purge local tt entries to fit new maximum fragment MTU (%i)\n", - packet_size_max); + "Forced to purge local tt entries to fit new maximum table response size (%i)\n", + size_max); } /* commit these changes immediately, to avoid synchronization problem diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index c19caa84e6920a..b3e6dbb360dae8 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -2047,7 +2047,13 @@ struct batadv_forw_packet { /** @direct_link_flags: direct link flags for aggregated OGM packets */ DECLARE_BITMAP(direct_link_flags, BATADV_MAX_AGGREGATION_PACKETS); - /** @num_packets: counter for aggregated OGMv1 packets */ + /** + * @num_packets: counter for aggregated OGMv1 packets. Set to + * BATADV_MAX_AGGREGATION_PACKETS (independent of the real number of + * aggregated packets) by the send worker to prevent further + * aggregation while the packet is emitted. It must therefore not be + * used to iterate over the aggregated packets + */ u8 num_packets; /** @delayed_work: work queue callback item for packet sending */ diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 29da3fe2b95384..eebd73988bf66b 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -138,10 +138,10 @@ static void hci_conn_cleanup(struct hci_conn *conn) { struct hci_dev *hdev = conn->hdev; - if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags)) + if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, conn->flags)) hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type); - if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, conn->flags)) hci_remove_link_key(hdev, &conn->dst); hci_chan_list_flush(conn); @@ -327,8 +327,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos = 0; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size = 1; - cp.out_transport_unit_size = 1; + if (conn->codec.data_path) { + cp.in_transport_unit_size = 1; + cp.out_transport_unit_size = 1; + } break; case BT_CODEC_TRANSPARENT: @@ -353,8 +355,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos = 0; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size = 1; - cp.out_transport_unit_size = 1; + if (conn->codec.data_path) { + cp.in_transport_unit_size = 1; + cp.out_transport_unit_size = 1; + } break; case BT_CODEC_CVSD: @@ -384,8 +388,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data) cp.out_pcm_sample_payload_msb_pos = 0; cp.in_data_path = conn->codec.data_path; cp.out_data_path = conn->codec.data_path; - cp.in_transport_unit_size = 16; - cp.out_transport_unit_size = 16; + if (conn->codec.data_path) { + cp.in_transport_unit_size = 16; + cp.out_transport_unit_size = 16; + } break; default: goto unlock; @@ -685,7 +691,7 @@ static void hci_conn_idle(struct work_struct *work) hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp); } - if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, conn->flags)) { struct hci_cp_sniff_mode cp; cp.handle = cpu_to_le16(conn->handle); cp.max_interval = cpu_to_le16(hdev->sniff_max_interval); @@ -814,7 +820,7 @@ static int hci_le_terminate_big(struct hci_dev *hdev, struct hci_conn *conn) d->big = conn->iso_qos.bcast.big; d->bis = conn->iso_qos.bcast.bis; - d->big_term = test_and_clear_bit(HCI_CONN_BIG_CREATED, &conn->flags); + d->big_term = test_and_clear_bit(HCI_CONN_BIG_CREATED, conn->flags); ret = hci_cmd_sync_queue(hdev, terminate_big_sync, d, terminate_big_destroy); @@ -867,7 +873,7 @@ static int hci_le_big_terminate(struct hci_dev *hdev, struct hci_conn *conn) d->sync_handle = conn->sync_handle; if (conn->type == PA_LINK && - test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) { + test_and_clear_bit(HCI_CONN_PA_SYNC, conn->flags)) { hci_conn_hash_list_flag(hdev, find_bis, PA_LINK, HCI_CONN_PA_SYNC, d); @@ -877,7 +883,7 @@ static int hci_le_big_terminate(struct hci_dev *hdev, struct hci_conn *conn) d->count = 0; } - if (test_and_clear_bit(HCI_CONN_BIG_SYNC, &conn->flags)) { + if (test_and_clear_bit(HCI_CONN_BIG_SYNC, conn->flags)) { hci_conn_hash_list_flag(hdev, find_bis, BIS_LINK, HCI_CONN_BIG_SYNC, d); @@ -912,7 +918,7 @@ static void bis_cleanup(struct hci_conn *conn) bt_dev_dbg(hdev, "conn %p", conn); if (conn->role == HCI_ROLE_MASTER) { - if (!test_and_clear_bit(HCI_CONN_PER_ADV, &conn->flags)) + if (!test_and_clear_bit(HCI_CONN_PER_ADV, conn->flags)) return; /* Check if ISO connection is a BIS and terminate advertising @@ -1087,7 +1093,7 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, conn->sync_handle = HCI_SYNC_HANDLE_INVALID; conn->sid = HCI_SID_INVALID; - set_bit(HCI_CONN_POWER_SAVE, &conn->flags); + set_bit(HCI_CONN_POWER_SAVE, conn->flags); conn->disc_timeout = HCI_DISCONN_TIMEOUT; /* Set Default Authenticated payload timeout to 30s */ @@ -1217,8 +1223,8 @@ static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason) case BIS_LINK: case PA_LINK: if ((conn->state != BT_CONNECTED && - !test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) || - test_bit(HCI_CONN_BIG_CREATED, &conn->flags)) + !test_bit(HCI_CONN_CREATE_CIS, conn->flags)) || + test_bit(HCI_CONN_BIG_CREATED, conn->flags)) hci_conn_failed(conn, reason); break; } @@ -1234,8 +1240,8 @@ static void hci_conn_unlink(struct hci_conn *conn) struct hci_link *link, *t; conn->sec_level = BT_SECURITY_SDP; - clear_bit(HCI_CONN_ENCRYPT, &conn->flags); - clear_bit(HCI_CONN_AES_CCM, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT, conn->flags); + clear_bit(HCI_CONN_AES_CCM, conn->flags); /* mgmt_security_level_changed() reports the reset only if * this connection was actually reported to userspace as * connected (it checks HCI_CONN_MGMT_CONNECTED itself), so it @@ -1254,7 +1260,7 @@ static void hci_conn_unlink(struct hci_conn *conn) */ if (test_bit(HCI_UP, &hdev->flags)) mgmt_security_level_changed(conn); - clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + clear_bit(HCI_CONN_MGMT_CONNECTED, conn->flags); list_for_each_entry_safe(link, t, &conn->link_list, list) { struct hci_conn *child = link->conn; @@ -1458,8 +1464,8 @@ void hci_conn_failed(struct hci_conn *conn, u8 status) /* In case of BIG/PA sync failed, clear conn flags so that * the conns will be correctly cleaned up by ISO layer */ - test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags); - test_and_clear_bit(HCI_CONN_PA_SYNC_FAILED, &conn->flags); + test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, conn->flags); + test_and_clear_bit(HCI_CONN_PA_SYNC_FAILED, conn->flags); conn->state = BT_CLOSED; hci_connect_cfm(conn, status); @@ -1524,9 +1530,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, * to connect. */ conn = hci_conn_hash_lookup_le(hdev, dst, dst_type); - if (conn && !test_bit(HCI_CONN_SCANNING, &conn->flags)) { + if (conn && !test_bit(HCI_CONN_SCANNING, conn->flags)) return ERR_PTR(-EBUSY); - } /* Check if the destination address has been resolved by the controller * since if it did then the identity address shall be used. @@ -1614,8 +1619,9 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev, if (!params) return -ENOMEM; - /* If we created new params, mark them to be deleted in - * hci_connect_le_scan_cleanup. It's different case than + /* If we created new params, mark them to be deleted once the + * explicit connect is done, see le_conn_complete_evt() and + * hci_connect_le_scan_cleanup(). It's different case than * existing disabled params, those will stay after cleanup. */ params->auto_connect = HCI_AUTO_CONN_EXPLICIT; @@ -1797,7 +1803,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, } conn->state = BT_CONNECT; - set_bit(HCI_CONN_SCANNING, &conn->flags); + set_bit(HCI_CONN_SCANNING, conn->flags); conn->sec_level = BT_SECURITY_LOW; conn->pending_sec_level = sec_level; conn->conn_timeout = conn_timeout; @@ -1923,12 +1929,12 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, if (acl->state == BT_CONNECTED && (sco->state == BT_OPEN || sco->state == BT_CLOSED)) { - set_bit(HCI_CONN_POWER_SAVE, &acl->flags); + set_bit(HCI_CONN_POWER_SAVE, acl->flags); hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON); - if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->flags)) { + if (test_bit(HCI_CONN_MODE_CHANGE_PEND, acl->flags)) { /* defer SCO setup until mode change completed */ - set_bit(HCI_CONN_SCO_SETUP_PEND, &acl->flags); + set_bit(HCI_CONN_SCO_SETUP_PEND, acl->flags); return sco; } @@ -2220,7 +2226,7 @@ int hci_le_create_cis_pending(struct hci_dev *hdev) rcu_read_lock(); list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { - if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) { + if (test_bit(HCI_CONN_CREATE_CIS, conn->flags)) { rcu_read_unlock(); return -EBUSY; } @@ -2448,7 +2454,7 @@ static void bis_mark_per_adv(struct hci_conn *conn, void *data) d->bis != conn->iso_qos.bcast.bis) return; - set_bit(HCI_CONN_PER_ADV, &conn->flags); + set_bit(HCI_CONN_PER_ADV, conn->flags); } struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst, @@ -2568,7 +2574,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn) */ if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) { if (!hci_conn_sc_enabled(conn) || - !test_bit(HCI_CONN_AES_CCM, &conn->flags) || + !test_bit(HCI_CONN_AES_CCM, conn->flags) || conn->key_type != HCI_LK_AUTH_COMBINATION_P256) return 0; } @@ -2584,14 +2590,14 @@ int hci_conn_check_link_mode(struct hci_conn *conn) * not shortened) */ if (conn->sec_level == BT_SECURITY_FIPS && - !test_bit(HCI_CONN_AES_CCM, &conn->flags)) { + !test_bit(HCI_CONN_AES_CCM, conn->flags)) { bt_dev_err(conn->hdev, "Invalid security: Missing AES-CCM usage"); return 0; } if (hci_conn_ssp_enabled(conn) && - !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + !test_bit(HCI_CONN_ENCRYPT, conn->flags)) return 0; return 1; @@ -2607,7 +2613,7 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) if (sec_level > conn->sec_level) conn->pending_sec_level = sec_level; - else if (test_bit(HCI_CONN_AUTH, &conn->flags)) + else if (test_bit(HCI_CONN_AUTH, conn->flags)) return 1; /* Make sure we preserve an existing MITM requirement*/ @@ -2615,7 +2621,7 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) conn->auth_type = auth_type; - if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_AUTH_PEND, conn->flags)) { struct hci_cp_auth_requested cp; cp.handle = cpu_to_le16(conn->handle); @@ -2625,8 +2631,8 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) /* Set the ENCRYPT_PEND to trigger encryption after * authentication. */ - if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) - set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); + if (!test_bit(HCI_CONN_ENCRYPT, conn->flags)) + set_bit(HCI_CONN_ENCRYPT_PEND, conn->flags); } return 0; @@ -2637,7 +2643,7 @@ static void hci_conn_encrypt(struct hci_conn *conn) { BT_DBG("hcon %p", conn); - if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, conn->flags)) { struct hci_cp_set_conn_encrypt cp; cp.handle = cpu_to_le16(conn->handle); cp.encrypt = 0x01; @@ -2665,7 +2671,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type, return 1; /* For other security levels we need the link key. */ - if (!test_bit(HCI_CONN_AUTH, &conn->flags)) + if (!test_bit(HCI_CONN_AUTH, conn->flags)) goto auth; switch (conn->key_type) { @@ -2705,17 +2711,17 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type, } auth: - if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) + if (test_bit(HCI_CONN_ENCRYPT_PEND, conn->flags)) return 0; if (initiator) - set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); + set_bit(HCI_CONN_AUTH_INITIATOR, conn->flags); if (!hci_conn_auth(conn, sec_level, auth_type)) return 0; encrypt: - if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) { + if (test_bit(HCI_CONN_ENCRYPT, conn->flags)) { /* Ensure that the encryption key size has been read, * otherwise stall the upper layer responses. */ @@ -2758,7 +2764,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role) if (role == conn->role) return 1; - if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, conn->flags)) { struct hci_cp_switch_role cp; bacpy(&cp.bdaddr, &conn->dst); cp.role = role; @@ -2779,10 +2785,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active) if (conn->mode != HCI_CM_SNIFF) goto timer; - if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active) + if (!test_bit(HCI_CONN_POWER_SAVE, conn->flags) && !force_active) goto timer; - if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, conn->flags)) { struct hci_cp_exit_sniff_mode cp; cp.handle = cpu_to_le16(conn->handle); hci_send_cmd(hdev, HCI_OP_EXIT_SNIFF_MODE, sizeof(cp), &cp); @@ -2822,16 +2828,16 @@ static u32 get_link_mode(struct hci_conn *conn) if (conn->role == HCI_ROLE_MASTER) link_mode |= HCI_LM_MASTER; - if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + if (test_bit(HCI_CONN_ENCRYPT, conn->flags)) link_mode |= HCI_LM_ENCRYPT; - if (test_bit(HCI_CONN_AUTH, &conn->flags)) + if (test_bit(HCI_CONN_AUTH, conn->flags)) link_mode |= HCI_LM_AUTH; - if (test_bit(HCI_CONN_SECURE, &conn->flags)) + if (test_bit(HCI_CONN_SECURE, conn->flags)) link_mode |= HCI_LM_SECURE; - if (test_bit(HCI_CONN_FIPS, &conn->flags)) + if (test_bit(HCI_CONN_FIPS, conn->flags)) link_mode |= HCI_LM_FIPS; return link_mode; @@ -2945,7 +2951,7 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn) BT_DBG("%s hcon %p", hdev->name, conn); - if (test_bit(HCI_CONN_DROP, &conn->flags)) { + if (test_bit(HCI_CONN_DROP, conn->flags)) { BT_DBG("Refusing to create new hci_chan"); return NULL; } @@ -2975,7 +2981,7 @@ void hci_chan_del(struct hci_chan *chan) synchronize_rcu(); /* Prevent new hci_chan's to be created for this hci_conn */ - set_bit(HCI_CONN_DROP, &conn->flags); + set_bit(HCI_CONN_DROP, conn->flags); hci_conn_put(conn); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 209244fd93918e..c97aec3caba023 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1075,17 +1075,16 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) rcu_read_lock(); list_for_each_entry_rcu(k, &hdev->link_keys, list) { if (bacmp(bdaddr, &k->bdaddr) == 0) { - rcu_read_unlock(); - if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LINKKEY, k->val)) { bt_dev_warn_ratelimited(hdev, "Link key blocked for %pMR", &k->bdaddr); - return NULL; + k = NULL; } + rcu_read_unlock(); return k; } } @@ -1252,7 +1251,6 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, key = kzalloc_obj(*key); if (!key) return NULL; - list_add_rcu(&key->list, &hdev->link_keys); } BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); @@ -1276,6 +1274,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, else key->type = type; + if (!old_key) + list_add_rcu(&key->list, &hdev->link_keys); + if (persistent) *persistent = hci_persistent_key(hdev, conn, type, old_key_type); @@ -1297,7 +1298,6 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key = kzalloc_obj(*key); if (!key) return NULL; - list_add_rcu(&key->list, &hdev->long_term_keys); } bacpy(&key->bdaddr, bdaddr); @@ -1309,15 +1309,19 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key->enc_size = enc_size; key->type = type; + if (!old_key) + list_add_rcu(&key->list, &hdev->long_term_keys); + return key; } struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 val[16], bdaddr_t *rpa) { - struct smp_irk *irk; + struct smp_irk *irk, *old_irk; - irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); + old_irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); + irk = old_irk; if (!irk) { irk = kzalloc_obj(*irk); if (!irk) @@ -1326,12 +1330,14 @@ struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, bacpy(&irk->bdaddr, bdaddr); irk->addr_type = addr_type; - list_add_rcu(&irk->list, &hdev->identity_resolving_keys); } memcpy(irk->val, val, 16); bacpy(&irk->rpa, rpa); + if (!old_irk) + list_add_rcu(&irk->list, &hdev->identity_resolving_keys); + return irk; } @@ -1694,6 +1700,9 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, if (!adv) return ERR_PTR(-ENOMEM); + INIT_DELAYED_WORK(&adv->rpa_expired_cb, + adv_instance_rpa_expired); + adv->pending = true; adv->instance = instance; @@ -1730,8 +1739,6 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, else adv->duration = duration; - INIT_DELAYED_WORK(&adv->rpa_expired_cb, adv_instance_rpa_expired); - BT_DBG("%s for %dMR", hdev->name, instance); return adv; @@ -2897,8 +2904,14 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) { u8 dev_pkt_type; + /* Pairs with synchronize_rcu() in hci_dev_close_sync(), so rx_work is + * not queued once the workqueue is being drained. + */ + rcu_read_lock(); + if (!hdev || (!test_bit(HCI_UP, &hdev->flags) && !test_bit(HCI_INIT, &hdev->flags))) { + rcu_read_unlock(); kfree_skb(skb); return -ENXIO; } @@ -2934,6 +2947,7 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) case HCI_DRV_PKT: break; default: + rcu_read_unlock(); kfree_skb(skb); return -EINVAL; } @@ -2947,6 +2961,8 @@ int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) skb_queue_tail(&hdev->rx_q, skb); queue_work(hdev->workqueue, &hdev->rx_work); + rcu_read_unlock(); + return 0; } EXPORT_SYMBOL(hci_recv_frame); @@ -3159,7 +3175,8 @@ int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, EXPORT_SYMBOL(__hci_cmd_send); /* Get data from the previously sent command */ -static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode) +static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode, + size_t *len) { struct hci_command_hdr *hdr; @@ -3171,23 +3188,32 @@ static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode) if (hdr->opcode != cpu_to_le16(opcode)) return NULL; + if (len) + *len = skb->len - HCI_COMMAND_HDR_SIZE; + return skb->data + HCI_COMMAND_HDR_SIZE; } /* Get data from the previously sent command */ -void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) +void *hci_sent_cmd_data_len(struct hci_dev *hdev, __u16 opcode, size_t *len) { void *data; /* Check if opcode matches last sent command */ - data = hci_cmd_data(hdev->sent_cmd, opcode); + data = hci_cmd_data(hdev->sent_cmd, opcode, len); if (!data) /* Check if opcode matches last request */ - data = hci_cmd_data(hdev->req_skb, opcode); + data = hci_cmd_data(hdev->req_skb, opcode, len); return data; } +/* Get data from the previously sent command */ +void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) +{ + return hci_sent_cmd_data_len(hdev, opcode, NULL); +} + /* Get data from last received event */ void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1f80f2cf6b2c81..5e6b25eb50538c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -724,6 +724,8 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, goto done; } + clear_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->flags); + /* While unexpected, the read_enc_key_size command may fail. The most * secure approach is to then assume the key size is 0 to force a * disconnection. @@ -732,8 +734,8 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, bt_dev_err(hdev, "failed to read key size for handle %u", handle); conn->enc_key_size = 0; - clear_bit(HCI_CONN_ENCRYPT, &conn->flags); - clear_bit(HCI_CONN_AES_CCM, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT, conn->flags); + clear_bit(HCI_CONN_AES_CCM, conn->flags); /* Downgrade to reflect the connection no longer being * encrypted, instead of advertising a stale elevated * security level alongside MGMT_CONN_SEC_ENCRYPT_NONE. @@ -761,8 +763,8 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, * state at a later time. */ status = HCI_ERROR_AUTH_FAILURE; - clear_bit(HCI_CONN_ENCRYPT, &conn->flags); - clear_bit(HCI_CONN_AES_CCM, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT, conn->flags); + clear_bit(HCI_CONN_AES_CCM, conn->flags); /* Downgrade to reflect the connection no longer being * encrypted, instead of advertising a stale elevated * security level alongside MGMT_CONN_SEC_ENCRYPT_NONE. @@ -814,9 +816,7 @@ static u8 hci_cc_read_local_commands(struct hci_dev *hdev, void *data, if (rp->status) return rp->status; - if (hci_dev_test_flag(hdev, HCI_SETUP) || - hci_dev_test_flag(hdev, HCI_CONFIG)) - memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); + memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); return rp->status; } @@ -1817,6 +1817,8 @@ static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr, static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable) { + bool timeout_pending; + hci_dev_lock(hdev); switch (enable) { @@ -1846,10 +1848,18 @@ static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable) /* Cancel this timer so that we don't try to disable scanning * when it's already disabled. */ - cancel_delayed_work(&hdev->le_scan_disable); + timeout_pending = cancel_delayed_work(&hdev->le_scan_disable); hci_dev_clear_flag(hdev, HCI_LE_SCAN); + /* The scan of a discovery was disabled before its timeout, + * for example by a Stop Discovery that timed out and still + * completed, so nothing else would end the discovery. + */ + if (timeout_pending && + hdev->discovery.state == DISCOVERY_FINDING) + hci_discovery_set_state(hdev, DISCOVERY_STOPPED); + if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && hci_test_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY) && !test_bit(HCI_INQUIRY, &hdev->flags) && @@ -2595,10 +2605,10 @@ static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) if (!hci_outgoing_auth_needed(hdev, conn)) goto unlock; - if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_AUTH_PEND, conn->flags)) { struct hci_cp_auth_requested auth_cp; - set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); + set_bit(HCI_CONN_AUTH_INITIATOR, conn->flags); auth_cp.handle = __cpu_to_le16(conn->handle); hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, @@ -2738,9 +2748,9 @@ static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); if (conn) { - clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); + clear_bit(HCI_CONN_MODE_CHANGE_PEND, conn->flags); - if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, conn->flags)) hci_sco_setup(conn, status); } @@ -2765,9 +2775,9 @@ static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); if (conn) { - clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); + clear_bit(HCI_CONN_MODE_CHANGE_PEND, conn->flags); - if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, conn->flags)) hci_sco_setup(conn, status); } @@ -2824,10 +2834,10 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) * still needs it set to know whether to report the security level * reset, so it is consumed there instead of here. */ - mgmt_conn = test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + mgmt_conn = test_bit(HCI_CONN_MGMT_CONNECTED, conn->flags); if (conn->type == ACL_LINK) { - if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, conn->flags)) hci_remove_link_key(hdev, &conn->dst); } @@ -3078,7 +3088,7 @@ static void hci_cs_switch_role(struct hci_dev *hdev, u8 status) conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); if (conn) - clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); + clear_bit(HCI_CONN_RSWITCH_PEND, conn->flags); hci_dev_unlock(hdev); } @@ -3190,6 +3200,7 @@ static int hci_read_enc_key_size(struct hci_dev *hdev, struct hci_conn *conn) { struct hci_cp_read_enc_key_size cp; u8 *key_enc_size = hci_conn_key_enc_size(conn); + int err; if (!read_key_size_capable(hdev)) { conn->enc_key_size = HCI_LINK_KEY_SIZE; @@ -3211,7 +3222,14 @@ static int hci_read_enc_key_size(struct hci_dev *hdev, struct hci_conn *conn) else conn->enc_key_size = hdev->min_enc_key_size; - return hci_send_cmd(hdev, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp); + /* L2CAP holds incoming data back until the key size is known */ + set_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->flags); + + err = hci_send_cmd(hdev, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp); + if (err) + clear_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->flags); + + return err; } static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, @@ -3309,19 +3327,19 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, hci_conn_add_sysfs(conn); if (test_bit(HCI_AUTH, &hdev->flags)) - set_bit(HCI_CONN_AUTH, &conn->flags); + set_bit(HCI_CONN_AUTH, conn->flags); if (test_bit(HCI_ENCRYPT, &hdev->flags)) - set_bit(HCI_CONN_ENCRYPT, &conn->flags); + set_bit(HCI_CONN_ENCRYPT, conn->flags); /* "Link key request" completed ahead of "connect request" completes */ - if (ev->encr_mode == 1 && !test_bit(HCI_CONN_ENCRYPT, &conn->flags) && + if (ev->encr_mode == 1 && !test_bit(HCI_CONN_ENCRYPT, conn->flags) && ev->link_type == ACL_LINK) { struct link_key *key; key = hci_find_link_key(hdev, &ev->bdaddr); if (key) { - set_bit(HCI_CONN_ENCRYPT, &conn->flags); + set_bit(HCI_CONN_ENCRYPT, conn->flags); hci_read_enc_key_size(hdev, conn); hci_encrypt_cfm(conn, ev->status); } @@ -3525,9 +3543,9 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data, * still needs it set to know whether to report the security level * reset, so it is consumed there instead of here. */ - mgmt_connected = test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); + mgmt_connected = test_bit(HCI_CONN_MGMT_CONNECTED, conn->flags); - if (test_bit(HCI_CONN_AUTH_FAILURE, &conn->flags)) + if (test_bit(HCI_CONN_AUTH_FAILURE, conn->flags)) reason = MGMT_DEV_DISCONN_AUTH_FAILURE; else reason = hci_to_mgmt_reason(ev->reason); @@ -3536,7 +3554,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data, reason, mgmt_connected); if (conn->type == ACL_LINK) { - if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, conn->flags)) hci_remove_link_key(hdev, &conn->dst); hci_update_scan(hdev); @@ -3607,8 +3625,8 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data, goto unlock; if (!ev->status) { - clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); - set_bit(HCI_CONN_AUTH, &conn->flags); + clear_bit(HCI_CONN_AUTH_FAILURE, conn->flags); + set_bit(HCI_CONN_AUTH, conn->flags); /* Authentication alone does not imply encryption: for SSP * capable devices, encryption is only requested below, and * for legacy devices it is requested by a separate @@ -3621,12 +3639,12 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data, conn->sec_level = conn->pending_sec_level; } else { if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) - set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); + set_bit(HCI_CONN_AUTH_FAILURE, conn->flags); mgmt_auth_failed(conn, ev->status); } - clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); + clear_bit(HCI_CONN_AUTH_PEND, conn->flags); if (conn->state == BT_CONFIG) { if (!ev->status && hci_conn_ssp_enabled(conn)) { @@ -3648,7 +3666,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data, hci_conn_drop(conn); } - if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { + if (test_bit(HCI_CONN_ENCRYPT_PEND, conn->flags)) { if (!ev->status) { struct hci_cp_set_conn_encrypt cp; cp.handle = ev->handle; @@ -3656,7 +3674,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data, hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), &cp); } else { - clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT_PEND, conn->flags); hci_encrypt_cfm(conn, ev->status); } } @@ -3693,10 +3711,10 @@ static void hci_remote_name_evt(struct hci_dev *hdev, void *data, if (!hci_outgoing_auth_needed(hdev, conn)) goto unlock; - if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { + if (!test_and_set_bit(HCI_CONN_AUTH_PEND, conn->flags)) { struct hci_cp_auth_requested cp; - set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); + set_bit(HCI_CONN_AUTH_INITIATOR, conn->flags); cp.handle = __cpu_to_le16(conn->handle); hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); @@ -3723,17 +3741,17 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, if (!ev->status) { if (ev->encrypt) { /* Encryption implies authentication */ - set_bit(HCI_CONN_AUTH, &conn->flags); - set_bit(HCI_CONN_ENCRYPT, &conn->flags); + set_bit(HCI_CONN_AUTH, conn->flags); + set_bit(HCI_CONN_ENCRYPT, conn->flags); conn->sec_level = conn->pending_sec_level; /* P-256 authentication key implies FIPS */ if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256) - set_bit(HCI_CONN_FIPS, &conn->flags); + set_bit(HCI_CONN_FIPS, conn->flags); if ((conn->type == ACL_LINK && ev->encrypt == 0x02) || conn->type == LE_LINK) - set_bit(HCI_CONN_AES_CCM, &conn->flags); + set_bit(HCI_CONN_AES_CCM, conn->flags); /* For ACL links the encryption key size is still * validated below via hci_read_enc_key_size(). Its @@ -3745,8 +3763,8 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, if (conn->type != ACL_LINK) mgmt_security_level_changed(conn); } else { - clear_bit(HCI_CONN_ENCRYPT, &conn->flags); - clear_bit(HCI_CONN_AES_CCM, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT, conn->flags); + clear_bit(HCI_CONN_AES_CCM, conn->flags); /* Elevated security levels (MEDIUM and above) require * encryption, so downgrade to reflect the connection * no longer being encrypted before reporting, instead @@ -3767,7 +3785,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, hci_adv_instances_set_rpa_expired(hdev, true); } - clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT_PEND, conn->flags); /* Check link security requirements are met */ if (!hci_conn_check_link_mode(conn)) @@ -3775,7 +3793,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, if (ev->status && conn->state == BT_CONNECTED) { if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) - set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); + set_bit(HCI_CONN_AUTH_FAILURE, conn->flags); /* Notify upper layers so they can cleanup before * disconnecting. @@ -3813,8 +3831,8 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, * type can be either LE or ACL and controller must support LMP Ping. * Ensure for AES-CCM encryption as well. */ - if (test_bit(HCI_CONN_ENCRYPT, &conn->flags) && - test_bit(HCI_CONN_AES_CCM, &conn->flags) && + if (test_bit(HCI_CONN_ENCRYPT, conn->flags) && + test_bit(HCI_CONN_AES_CCM, conn->flags) && ((conn->type == ACL_LINK && lmp_ping_capable(hdev)) || (conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) { struct hci_cp_write_auth_payload_to cp; @@ -3846,9 +3864,9 @@ static void hci_change_link_key_complete_evt(struct hci_dev *hdev, void *data, conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); if (conn) { if (!ev->status) - set_bit(HCI_CONN_SECURE, &conn->flags); + set_bit(HCI_CONN_SECURE, conn->flags); - clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); + clear_bit(HCI_CONN_AUTH_PEND, conn->flags); hci_key_change_cfm(conn, ev->status); } @@ -3975,13 +3993,16 @@ static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data, struct hci_conn *conn; u8 status = rp->status; bool pending = false; + size_t len; int i; bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); - cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_CIG_PARAMS); + cp = hci_sent_cmd_data_len(hdev, HCI_OP_LE_SET_CIG_PARAMS, &len); if (!rp->status && - (!cp || rp->num_handles != cp->num_cis || + (!cp || len < sizeof(*cp) || + len < struct_size(cp, cis, cp->num_cis) || + rp->num_handles != cp->num_cis || rp->cig_id != cp->cig_id || skb->len < array_size(rp->num_handles, sizeof(*rp->handle)))) { bt_dev_err(hdev, "unexpected Set CIG Parameters response data"); @@ -4074,7 +4095,7 @@ static u8 hci_cc_le_setup_iso_path(struct hci_dev *hdev, void *data, hci_connect_cfm(conn, rp->status); /* Notify device connected in case it is a BIG Sync */ - if (!rp->status && test_bit(HCI_CONN_BIG_SYNC, &conn->flags)) + if (!rp->status && test_bit(HCI_CONN_BIG_SYNC, conn->flags)) mgmt_device_connected(hdev, conn, NULL, 0); break; @@ -4481,6 +4502,7 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) { struct hci_cp_le_create_cis *cp; bool pending = false; + size_t len; int i; bt_dev_dbg(hdev, "status 0x%2.2x", status); @@ -4488,10 +4510,14 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) if (!status) return; - cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CIS); + cp = hci_sent_cmd_data_len(hdev, HCI_OP_LE_CREATE_CIS, &len); if (!cp) return; + if (len < sizeof(*cp) || + len < struct_size(cp, cis, cp->num_cis)) + return; + hci_dev_lock(hdev); /* Remove connection if command failed */ @@ -4504,7 +4530,7 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) conn = hci_conn_hash_lookup_handle(hdev, handle); if (conn) { if (test_and_clear_bit(HCI_CONN_CREATE_CIS, - &conn->flags)) + conn->flags)) pending = true; conn->state = BT_CLOSED; hci_connect_cfm(conn, status); @@ -4625,7 +4651,7 @@ static void hci_role_change_evt(struct hci_dev *hdev, void *data, if (!ev->status) conn->role = ev->role; - clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); + clear_bit(HCI_CONN_RSWITCH_PEND, conn->flags); hci_role_switch_cfm(conn, ev->status, ev->role); } @@ -4737,12 +4763,12 @@ static void hci_mode_change_evt(struct hci_dev *hdev, void *data, conn->mode = ev->mode; if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, - &conn->flags)) { - assign_bit(HCI_CONN_POWER_SAVE, &conn->flags, + conn->flags)) { + assign_bit(HCI_CONN_POWER_SAVE, conn->flags, conn->mode == HCI_CM_ACTIVE); } - if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) + if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, conn->flags)) hci_sco_setup(conn, ev->status); } @@ -4770,7 +4796,7 @@ static void hci_pin_code_request_evt(struct hci_dev *hdev, void *data, } if (!hci_dev_test_flag(hdev, HCI_BONDABLE) && - !test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags)) { + !test_bit(HCI_CONN_AUTH_INITIATOR, conn->flags)) { hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(ev->bdaddr), &ev->bdaddr); } else if (hci_dev_test_flag(hdev, HCI_MGMT)) { @@ -4845,7 +4871,7 @@ static void hci_link_key_request_evt(struct hci_dev *hdev, void *data, conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); if (conn) { - clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); + clear_bit(HCI_CONN_NEW_LINK_KEY, conn->flags); if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 || key->type == HCI_LK_UNAUTH_COMBINATION_P256) && @@ -4908,7 +4934,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data, conn->disc_timeout = HCI_DISCONN_TIMEOUT; hci_conn_drop(conn); - set_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); + set_bit(HCI_CONN_NEW_LINK_KEY, conn->flags); conn_set_key(conn, ev->key_type, conn->pin_length); if (!hci_dev_test_flag(hdev, HCI_MGMT)) @@ -4939,7 +4965,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data, goto unlock; } - assign_bit(HCI_CONN_FLUSH_KEY, &conn->flags, !persistent); + assign_bit(HCI_CONN_FLUSH_KEY, conn->flags, !persistent); unlock: hci_dev_unlock(hdev); @@ -5117,7 +5143,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data, ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); if (ev->features[0] & LMP_HOST_SSP) { - set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); + set_bit(HCI_CONN_SSP_ENABLED, conn->flags); } else { /* It is mandatory by the Bluetooth specification that * Extended Inquiry Results are only used when Secure @@ -5127,17 +5153,17 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data, * To make these devices work, the internal SSP * enabled flag needs to be cleared if the remote host * features do not indicate SSP support */ - clear_bit(HCI_CONN_SSP_ENABLED, &conn->flags); + clear_bit(HCI_CONN_SSP_ENABLED, conn->flags); } if (ev->features[0] & LMP_HOST_SC) - set_bit(HCI_CONN_SC_ENABLED, &conn->flags); + set_bit(HCI_CONN_SC_ENABLED, conn->flags); } if (conn->state != BT_CONFIG) goto unlock; - if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { + if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, conn->flags)) { struct hci_cp_remote_name_req cp; memset(&cp, 0, sizeof(cp)); bacpy(&cp.bdaddr, &conn->dst); @@ -5373,7 +5399,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data, mgmt_security_level_changed(conn); } - clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); + clear_bit(HCI_CONN_ENCRYPT_PEND, conn->flags); if (ev->status && conn->state == BT_CONNECTED) { hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); @@ -5474,7 +5500,7 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, void *data, goto unlock; /* Assume remote supports SSP since it has triggered this event */ - set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); + set_bit(HCI_CONN_SSP_ENABLED, conn->flags); hci_conn_hold(conn); @@ -5485,7 +5511,7 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, void *data, * pairing or if the remote is not requesting bonding. */ if (hci_dev_test_flag(hdev, HCI_BONDABLE) || - test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags) || + test_bit(HCI_CONN_AUTH_INITIATOR, conn->flags) || (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { struct hci_cp_io_capability_reply cp; @@ -5595,7 +5621,7 @@ static void hci_user_confirm_request_evt(struct hci_dev *hdev, void *data, * local IO capability is not NoInputNoOutput, use JUST_WORKS * method (mgmt_user_confirm with confirm_hint set to 1). */ - if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && + if (!test_bit(HCI_CONN_AUTH_PEND, conn->flags) && conn->io_capability != HCI_IO_NO_INPUT_OUTPUT) { bt_dev_dbg(hdev, "Confirming auto-accept as acceptor"); confirm_hint = 1; @@ -5738,7 +5764,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev, void *data, * initiated the authentication. A traditional auth_complete * event gets always produced as initiator and is also mapped to * the mgmt_auth_failed event */ - if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status) + if (!test_bit(HCI_CONN_AUTH_PEND, conn->flags) && ev->status) mgmt_auth_failed(conn, ev->status); hci_conn_drop(conn); @@ -5984,7 +6010,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, goto unlock; /* Drop the connection if it has been aborted */ - if (test_bit(HCI_CONN_CANCEL, &conn->flags)) { + if (test_bit(HCI_CONN_CANCEL, conn->flags)) { hci_conn_drop(conn); goto unlock; } @@ -6041,6 +6067,28 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, hci_conn_put(params->conn); params->conn = NULL; } + + /* An explicit connect request is complete once connected, so + * clean it up here: hci_connect_le_scan_cleanup() no longer + * finds the params since they have just been removed from + * pend_le_conns. + */ + if (params->explicit_connect) { + params->explicit_connect = false; + + switch (params->auto_connect) { + case HCI_AUTO_CONN_EXPLICIT: + hci_conn_params_del(hdev, &conn->dst, + conn->dst_type); + break; + case HCI_AUTO_CONN_REPORT: + hci_pend_le_list_add(params, + &hdev->pend_le_reports); + break; + default: + break; + } + } } /* If we are central and have subrate parameters stored, queue a @@ -6101,8 +6149,8 @@ static void hci_le_pa_sync_lost_evt(struct hci_dev *hdev, void *data, /* Delete the pa sync connection */ conn = hci_conn_hash_lookup_pa_sync_handle(hdev, handle); if (conn) { - clear_bit(HCI_CONN_BIG_SYNC, &conn->flags); - clear_bit(HCI_CONN_PA_SYNC, &conn->flags); + clear_bit(HCI_CONN_BIG_SYNC, conn->flags); + clear_bit(HCI_CONN_PA_SYNC, conn->flags); hci_disconn_cfm(conn, HCI_ERROR_REMOTE_USER_TERM); hci_conn_del(conn); } @@ -6236,7 +6284,7 @@ static void hci_le_past_received_evt(struct hci_dev *hdev, void *data, pa_sync->sync_handle = le16_to_cpu(ev->sync_handle); if (ev->status) { - set_bit(HCI_CONN_PA_SYNC_FAILED, &pa_sync->flags); + set_bit(HCI_CONN_PA_SYNC_FAILED, pa_sync->flags); /* Notify iso layer */ hci_connect_cfm(pa_sync, ev->status); @@ -6758,7 +6806,7 @@ static void hci_le_pa_sync_established_evt(struct hci_dev *hdev, void *data, goto unlock; } - clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); + clear_bit(HCI_CONN_CREATE_PA_SYNC, conn->flags); conn->sync_handle = le16_to_cpu(ev->handle); conn->sid = HCI_SID_INVALID; @@ -6783,7 +6831,7 @@ static void hci_le_pa_sync_established_evt(struct hci_dev *hdev, void *data, pa_sync->sync_handle = le16_to_cpu(ev->handle); if (ev->status) { - set_bit(HCI_CONN_PA_SYNC_FAILED, &pa_sync->flags); + set_bit(HCI_CONN_PA_SYNC_FAILED, pa_sync->flags); /* Notify iso layer */ hci_connect_cfm(pa_sync, ev->status); @@ -6827,7 +6875,7 @@ static void hci_le_per_adv_report_evt(struct hci_dev *hdev, void *data, goto unlock; if (ev->data_status == LE_PA_DATA_COMPLETE && - !test_and_set_bit(HCI_CONN_PA_SYNC, &pa_sync->flags)) { + !test_and_set_bit(HCI_CONN_PA_SYNC, pa_sync->flags)) { /* Notify iso layer */ hci_connect_cfm(pa_sync, 0); @@ -6940,11 +6988,11 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, void *data, * using a distributed LTK. */ if (ltk->type == SMP_STK) { - set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); + set_bit(HCI_CONN_STK_ENCRYPT, conn->flags); list_del_rcu(<k->list); kfree_rcu(ltk, rcu); } else { - clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); + clear_bit(HCI_CONN_STK_ENCRYPT, conn->flags); } hci_dev_unlock(hdev); @@ -7140,7 +7188,7 @@ static void hci_le_cis_established_evt(struct hci_dev *hdev, void *data, qos = &conn->iso_qos; - pending = test_and_clear_bit(HCI_CONN_CREATE_CIS, &conn->flags); + pending = test_and_clear_bit(HCI_CONN_CREATE_CIS, conn->flags); /* BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 6, Part G * page 3075: @@ -7337,7 +7385,7 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data, } conn->state = BT_CONNECTED; - set_bit(HCI_CONN_BIG_CREATED, &conn->flags); + set_bit(HCI_CONN_BIG_CREATED, conn->flags); hci_debugfs_create_conn(conn); hci_conn_add_sysfs(conn); hci_iso_setup_path(conn); @@ -7382,7 +7430,7 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, goto unlock; } - clear_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); + clear_bit(HCI_CONN_CREATE_BIG_SYNC, conn->flags); conn->num_bis = 0; memset(conn->bis, 0, sizeof(conn->bis)); @@ -7405,7 +7453,7 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, if (ev->status != 0x42) /* Mark PA sync as established */ - set_bit(HCI_CONN_PA_SYNC, &bis->flags); + set_bit(HCI_CONN_PA_SYNC, bis->flags); bis->sync_handle = conn->sync_handle; bis->iso_qos.bcast.big = ev->handle; @@ -7418,7 +7466,7 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, if (!ev->status) { bis->state = BT_CONNECTED; - set_bit(HCI_CONN_BIG_SYNC, &bis->flags); + set_bit(HCI_CONN_BIG_SYNC, bis->flags); hci_debugfs_create_conn(bis); hci_conn_add_sysfs(bis); hci_iso_setup_path(bis); @@ -7436,7 +7484,7 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, if (!bis) continue; - set_bit(HCI_CONN_BIG_SYNC_FAILED, &bis->flags); + set_bit(HCI_CONN_BIG_SYNC_FAILED, bis->flags); hci_connect_cfm(bis, ev->status); } @@ -7466,13 +7514,13 @@ static void hci_le_big_sync_lost_evt(struct hci_dev *hdev, void *data, * it is consumed there instead of here. */ mgmt_conn = test_bit(HCI_CONN_MGMT_CONNECTED, - &bis->flags); + bis->flags); mgmt_device_disconnected(hdev, &bis->dst, bis->type, bis->dst_type, ev->reason, mgmt_conn); } - clear_bit(HCI_CONN_BIG_SYNC, &bis->flags); + clear_bit(HCI_CONN_BIG_SYNC, bis->flags); hci_disconn_cfm(bis, ev->reason); hci_conn_del(bis); } diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 03f706c1f81524..9213e3ef9f268e 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -376,8 +376,18 @@ static void le_scan_disable(struct work_struct *work) bt_dev_dbg(hdev, ""); hci_dev_lock(hdev); - if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) + if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) { + /* The scan of a discovery can be disabled while this work + * waits for the lock, for example by a Stop Discovery that + * timed out and still completed, so end the discovery as + * le_set_scan_enable_complete() does when it cancels this + * work. + */ + if (hdev->discovery.state == DISCOVERY_FINDING) + goto discov_stopped; + goto _return; + } status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL); if (status) { @@ -2448,15 +2458,17 @@ static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) { struct hci_cp_le_del_from_resolv_list cp; - struct bdaddr_list_with_irk *entry; + bool exists; if (!ll_privacy_capable(hdev)) return 0; /* Check if the IRK has been programmed */ - entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, - bdaddr_type); - if (!entry) + hci_dev_lock(hdev); + exists = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, + bdaddr, bdaddr_type); + hci_dev_unlock(hdev); + if (!exists) return 0; cp.bdaddr_type = bdaddr_type; @@ -2512,8 +2524,8 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, { struct hci_cp_le_add_to_resolv_list cp; struct smp_irk *irk; - struct bdaddr_list_with_irk *entry; struct hci_conn_params *p; + bool exists; if (!ll_privacy_capable(hdev)) return 0; @@ -2531,20 +2543,28 @@ static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, } else if (!(params->flags & HCI_CONN_FLAG_ADDRESS_RESOLUTION)) return 0; + rcu_read_lock(); + irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); - if (!irk) + if (!irk) { + rcu_read_unlock(); return 0; + } + + memcpy(cp.peer_irk, irk->val, 16); + + rcu_read_unlock(); /* Check if the IK has _not_ been programmed yet. */ - entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, - ¶ms->addr, - params->addr_type); - if (entry) + hci_dev_lock(hdev); + exists = hci_bdaddr_list_lookup_with_irk( + &hdev->le_resolv_list, ¶ms->addr, params->addr_type); + hci_dev_unlock(hdev); + if (exists) return 0; cp.bdaddr_type = params->addr_type; bacpy(&cp.bdaddr, ¶ms->addr); - memcpy(cp.peer_irk, irk->val, 16); /* Default privacy mode is always Network */ params->privacy_mode = HCI_NETWORK_PRIVACY; @@ -2733,7 +2753,7 @@ static int hci_pause_advertising_sync(struct hci_dev *hdev) static int hci_resume_advertising_sync(struct hci_dev *hdev) { struct adv_info *adv, *tmp; - int err; + int err = 0; /* If advertising has not been paused there is nothing to do. */ if (!hdev->advertising_paused) @@ -2766,13 +2786,19 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev) */ if (hci_dev_test_and_clear_flag(hdev, HCI_LE_ADV_0)) err = hci_enable_ext_advertising_sync(hdev, 0x00); - } else { + } else if (hdev->cur_adv_instance) { /* Schedule for most recent instance to be restarted and begin * the software rotation loop */ err = hci_schedule_adv_instance_sync(hdev, hdev->cur_adv_instance, true); + } else if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && + !hci_dev_test_flag(hdev, HCI_LE_ADV)) { + /* hci_schedule_adv_instance_sync() rejects instance 0x00 while + * HCI_ADVERTISING is set, so enable it directly. + */ + err = hci_start_adv_sync(hdev, 0x00); } hdev->advertising_paused = false; @@ -2879,6 +2905,31 @@ static struct conn_params *conn_params_copy(struct list_head *list, size_t *n) return p; } +static struct conn_params *le_accept_list_copy(struct hci_dev *hdev, + size_t *n) +{ + struct bdaddr_list *entry; + struct conn_params *params; + size_t i = 0; + + hci_dev_lock(hdev); + + *n = list_count_nodes(&hdev->le_accept_list); + params = kvzalloc_objs(struct conn_params, *n); + if (!params) + goto unlock; + + list_for_each_entry(entry, &hdev->le_accept_list, list) { + bacpy(¶ms[i].addr, &entry->bdaddr); + params[i].addr_type = entry->bdaddr_type; + i++; + } + +unlock: + hci_dev_unlock(hdev); + return params; +} + /* Clear LE Accept List */ static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) { @@ -2909,7 +2960,6 @@ static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) static u8 hci_update_accept_list_sync(struct hci_dev *hdev) { struct conn_params *params; - struct bdaddr_list *b, *t; u8 num_entries = 0; bool pend_conn, pend_report; u8 filter_policy; @@ -2974,20 +3024,27 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) * report. If not present in either list, then remove it from * the controller. */ - list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { + params = le_accept_list_copy(hdev, &n); + if (!params) { + err = -ENOMEM; + goto done; + } + + for (i = 0; i < n; i++) { rcu_read_lock(); - if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) { + if (hci_conn_hash_lookup_le(hdev, ¶ms[i].addr, + params[i].addr_type)) { rcu_read_unlock(); continue; } pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, - &b->bdaddr, - b->bdaddr_type); - pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, - &b->bdaddr, - b->bdaddr_type); + ¶ms[i].addr, + params[i].addr_type); + pend_report = hci_pend_le_action_lookup( + &hdev->pend_le_reports, ¶ms[i].addr, + params[i].addr_type); rcu_read_unlock(); @@ -2995,14 +3052,16 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) * remove it from the acceptlist. */ if (!pend_conn && !pend_report) { - hci_le_del_accept_list_sync(hdev, &b->bdaddr, - b->bdaddr_type); + hci_le_del_accept_list_sync(hdev, ¶ms[i].addr, + params[i].addr_type); continue; } num_entries++; } + kvfree(params); + /* Since all no longer valid accept list entries have been * removed, walk through the list of pending connections * and ensure that any new device gets programmed into @@ -3505,9 +3564,13 @@ int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) return hci_write_sc_support_sync(hdev, 0x01); } +static int hci_le_set_host_feature_sync(struct hci_dev *hdev, u16 bit, + u8 value); + int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) { struct hci_cp_write_le_host_supported cp; + int err; if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || !lmp_bredr_capable(hdev)) @@ -3525,8 +3588,16 @@ int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) cp.le = le; cp.simul = simul; - return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, + sizeof(cp), &cp, HCI_CMD_TIMEOUT); + if (err || !cis_capable(hdev)) + return err; + + /* The CIS host feature is set during init based on LE being enabled, + * which is not repeated when LE is enabled afterwards, e.g. while the + * controller is still auto powered on, so update it here. + */ + return hci_le_set_host_feature_sync(hdev, 32, iso_enabled(hdev)); } static int hci_powered_update_adv_sync(struct hci_dev *hdev) @@ -4828,6 +4899,9 @@ static int hci_le_set_def_rate_sync(struct hci_dev *hdev) struct hci_cp_le_set_def_rate cp; u16 interval_min = 0x000a; /* 1.25 ms */ u16 interval_max = 0x0078; /* 15 ms */ + u16 subrate_max = 0x0004; + u16 max_latency = 0x0000; + u32 supv_timeout; if (!le_sci_capable(hdev)) return 0; @@ -4852,10 +4926,31 @@ static int hci_le_set_def_rate_sync(struct hci_dev *hdev) cp.interval_min = cpu_to_le16(interval_min); cp.interval_max = cpu_to_le16(interval_max); cp.subrate_min = cpu_to_le16(0x0001); - cp.subrate_max = cpu_to_le16(0x0004); - cp.max_latency = cpu_to_le16(0x0000); + cp.subrate_max = cpu_to_le16(subrate_max); + cp.max_latency = cpu_to_le16(max_latency); cp.cont_num = cpu_to_le16(0x0001); - cp.supv_timeout = cpu_to_le16(0x000c); /* 120 ms */ + + /* HOGP v1.2 recommends a Supervision_Timeout greater than or equal to + * (1 + Max_Latency) x Subrate_Max x Connection_Interval_Max x 2, but + * the Core spec treats the equality as invalid: + * + * BLUETOOTH CORE SPECIFICATION Version 6.3 | Vol 4, Part E + * 7.8.158. LE Set Default Rate Parameters command + * + * If Connection_Interval_Max x Subrate_Max x (Max_Latency + 1) is + * greater than or equal to Supervision_Timeout x 40, the Controller + * shall return the error code Invalid HCI Command Parameters (0x12). + * + * So default to 2 s, 10x lower than the 20 s used for non-SCI + * connections while still well above the minimum required, but make + * sure it stays strictly above the minimum in case interval_max has + * been raised. + */ + supv_timeout = (u32)interval_max * subrate_max * (max_latency + 1); + supv_timeout = supv_timeout / 40 + 1; + supv_timeout = clamp_t(u32, max_t(u32, supv_timeout, 0x00c8), + 0x000a, 0x0c80); + cp.supv_timeout = cpu_to_le16(supv_timeout); /* The connection event length recommended in requests by a Peripheral * uses units of 125 us with a valid range of 0x0001 to 0x7CFF @@ -5637,6 +5732,11 @@ int hci_dev_close_sync(struct hci_dev *hdev) return err; } + /* Wait for hci_recv_frame() callers that still saw HCI_UP, so that + * none of them queues rx_work while the workqueue is drained below. + */ + synchronize_rcu(); + hci_leds_update_powered(hdev, false); /* Flush RX and TX works */ @@ -5830,11 +5930,15 @@ int hci_stop_discovery_sync(struct hci_dev *hdev) } if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { - cancel_delayed_work(&hdev->le_scan_disable); - err = hci_scan_disable_sync(hdev); if (err) return err; + + /* Only cancel the LE scan timeout once the scan is + * disabled, so that the discovery still ends if + * stopping it failed. + */ + cancel_delayed_work(&hdev->le_scan_disable); } } else { @@ -5913,11 +6017,11 @@ static int hci_le_connect_cancel_sync(struct hci_dev *hdev, /* Return reason if scanning since the connection shall probably be * cleanup directly. */ - if (test_bit(HCI_CONN_SCANNING, &conn->flags)) + if (test_bit(HCI_CONN_SCANNING, conn->flags)) return reason; if (conn->role == HCI_ROLE_SLAVE || - test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) + test_and_set_bit(HCI_CONN_CANCEL, conn->flags)) return 0; return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, @@ -5939,7 +6043,7 @@ static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn, * then an HCI_LE_CIS_Established event shall also be sent for * this CIS with the Status Operation Cancelled by Host (0x44). */ - if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) + if (test_bit(HCI_CONN_CREATE_CIS, conn->flags)) return hci_disconnect_sync(hdev, conn, reason); /* CIS with no Create CIS sent have nothing to cancel */ @@ -6310,6 +6414,7 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) u8 filter_policy = 0x00; /* Default is to enable duplicates filter */ u8 filter_dup = LE_SCAN_FILTER_DUP_ENABLE; + bool paused; int err; bt_dev_dbg(hdev, ""); @@ -6333,6 +6438,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) if (err) goto failed; + /* LE Set Random Address is disallowed while advertising is enabled. */ + paused = !hdev->advertising_paused; + err = hci_pause_advertising_sync(hdev); + if (err) + goto failed; + /* All active scans will be done with either a resolvable private * address (when privacy feature has been enabled) or non-resolvable * private address. @@ -6342,6 +6453,9 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) if (err < 0) own_addr_type = ADDR_LE_DEV_PUBLIC; + if (paused) + hci_resume_advertising_sync(hdev); + if (hci_is_adv_monitoring(hdev) || (hci_test_quirk(hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER) && hdev->discovery.result_filtering)) { @@ -6365,9 +6479,8 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) return err; failed: - /* Resume advertising if it was paused */ - if (ll_privacy_capable(hdev)) - hci_resume_advertising_sync(hdev); + /* No-op when advertising was not paused. */ + hci_resume_advertising_sync(hdev); /* Resume passive scanning */ hci_update_passive_scan_sync(hdev); @@ -6460,6 +6573,12 @@ static int hci_pause_discovery_sync(struct hci_dev *hdev) return 0; hci_discovery_set_state(hdev, DISCOVERY_STOPPING); + + /* Cancel the LE scan timeout first, so that it does not run while + * suspended if the scan cannot be disabled. + */ + cancel_delayed_work(&hdev->le_scan_disable); + err = hci_stop_discovery_sync(hdev); if (err) return err; @@ -6928,7 +7047,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) bt_dev_dbg(hdev, "conn %p", conn); - clear_bit(HCI_CONN_SCANNING, &conn->flags); + clear_bit(HCI_CONN_SCANNING, conn->flags); conn->state = BT_CONNECT; /* If requested to connect as peripheral use directed advertising */ @@ -6995,7 +7114,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) /* Mark create connection in flight so hci_cancel_connect_sync() can * cancel it while blocking on the connection complete event. */ - set_bit(HCI_CONN_CREATE, &conn->flags); + set_bit(HCI_CONN_CREATE, conn->flags); /* Send command LE Extended Create Connection if supported */ if (use_ext_conn(hdev)) { @@ -7032,7 +7151,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) conn->conn_timeout, NULL); done: - clear_bit(HCI_CONN_CREATE, &conn->flags); + clear_bit(HCI_CONN_CREATE, conn->flags); if (err == -ETIMEDOUT) hci_le_connect_cancel_sync(hdev, conn, 0x00); @@ -7079,7 +7198,7 @@ int hci_le_create_cis_sync(struct hci_dev *hdev) /* Wait until previous Create CIS has completed */ list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { - if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) + if (test_bit(HCI_CONN_CREATE_CIS, conn->flags)) goto done; } @@ -7115,7 +7234,7 @@ int hci_le_create_cis_sync(struct hci_dev *hdev) conn->iso_qos.ucast.cig != cig) continue; - set_bit(HCI_CONN_CREATE_CIS, &conn->flags); + set_bit(HCI_CONN_CREATE_CIS, conn->flags); cis->acl_handle = cpu_to_le16(conn->parent->handle); cis->cis_handle = cpu_to_le16(conn->handle); timeout = conn->conn_timeout; @@ -7318,14 +7437,14 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data) /* Mark create connection in flight so hci_cancel_connect_sync() can * cancel it while blocking on the connection complete event. */ - set_bit(HCI_CONN_CREATE, &conn->flags); + set_bit(HCI_CONN_CREATE, conn->flags); err = __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN, sizeof(cp), &cp, HCI_EV_CONN_COMPLETE, conn->conn_timeout, NULL); - clear_bit(HCI_CONN_CREATE, &conn->flags); + clear_bit(HCI_CONN_CREATE, conn->flags); return err; } @@ -7414,7 +7533,7 @@ static int hci_acl_cancel_create_conn_sync(struct hci_dev *hdev, mutex_lock(&hdev->cmd_sync_work_lock); /* In flight: this connection owns the pending request, cancel it. */ - if (test_bit(HCI_CONN_CREATE, &conn->flags)) { + if (test_bit(HCI_CONN_CREATE, conn->flags)) { hci_cmd_sync_cancel(hdev, ECANCELED); goto unlock; } @@ -7445,7 +7564,7 @@ static int hci_le_cancel_create_conn_sync(struct hci_dev *hdev, */ mutex_lock(&hdev->cmd_sync_work_lock); - if (test_bit(HCI_CONN_CREATE, &conn->flags)) { + if (test_bit(HCI_CONN_CREATE, conn->flags)) { hci_cmd_sync_cancel(hdev, ECANCELED); goto unlock; } @@ -7472,7 +7591,7 @@ static int hci_cis_cancel_create_conn_sync(struct hci_dev *hdev, */ mutex_lock(&hdev->cmd_sync_work_lock); - if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) + if (test_bit(HCI_CONN_CREATE_CIS, conn->flags)) hci_cmd_sync_cancel(hdev, ECANCELED); mutex_unlock(&hdev->cmd_sync_work_lock); @@ -7609,7 +7728,7 @@ static void create_pa_complete(struct hci_dev *hdev, void *data, int err) hci_dev_lock(hdev); if (hci_conn_valid(hdev, conn)) - clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); + clear_bit(HCI_CONN_CREATE_PA_SYNC, conn->flags); if (!err) goto unlock; @@ -7621,7 +7740,7 @@ static void create_pa_complete(struct hci_dev *hdev, void *data, int err) if (IS_ERR(pa_sync)) goto unlock; - set_bit(HCI_CONN_PA_SYNC_FAILED, &pa_sync->flags); + set_bit(HCI_CONN_PA_SYNC_FAILED, pa_sync->flags); /* Notify iso layer */ hci_connect_cfm(pa_sync, bt_status(err)); @@ -7694,7 +7813,7 @@ static int hci_le_pa_create_sync(struct hci_dev *hdev, void *data) * program the address in the allow list so PA advertisements can be * received. */ - set_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); + set_bit(HCI_CONN_CREATE_PA_SYNC, conn->flags); hci_update_passive_scan_sync(hdev); @@ -7797,7 +7916,7 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err) if (err == -ECANCELED) goto done; - clear_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); + clear_bit(HCI_CONN_CREATE_BIG_SYNC, conn->flags); done: hci_conn_put(conn); @@ -7814,7 +7933,7 @@ static int hci_le_big_create_sync(struct hci_dev *hdev, void *data) if (!hci_conn_valid(hdev, conn)) return -ECANCELED; - set_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); + set_bit(HCI_CONN_CREATE_BIG_SYNC, conn->flags); memset(cp, 0, sizeof(*cp)); cp->handle = qos->bcast.big; diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index c1fdd9846eeb01..06f1e7ba2cb1b4 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -912,7 +912,7 @@ static void iso_sock_disconn(struct sock *sk) struct sock *bis_sk; struct hci_conn *hcon = iso_pi(sk)->conn->hcon; - if (test_bit(HCI_CONN_BIG_CREATED, &hcon->flags)) { + if (test_bit(HCI_CONN_BIG_CREATED, hcon->flags)) { bis_sk = iso_get_sock_big(sk, &iso_pi(sk)->src, &iso_pi(sk)->dst, iso_pi(sk)->qos.bcast.big); @@ -957,8 +957,8 @@ static void __iso_sock_close(struct sock *sk) case BT_CONNECT2: if (iso_pi(sk)->conn->hcon && - (test_bit(HCI_CONN_PA_SYNC, &iso_pi(sk)->conn->hcon->flags) || - test_bit(HCI_CONN_PA_SYNC_FAILED, &iso_pi(sk)->conn->hcon->flags))) + (test_bit(HCI_CONN_PA_SYNC, iso_pi(sk)->conn->hcon->flags) || + test_bit(HCI_CONN_PA_SYNC_FAILED, iso_pi(sk)->conn->hcon->flags))) iso_sock_disconn(sk); else iso_chan_del(sk, ECONNRESET); @@ -2289,7 +2289,7 @@ static void iso_conn_ready(struct iso_conn *conn) hdev = hcon->hdev; - if (test_bit(HCI_CONN_BIG_SYNC, &hcon->flags)) { + if (test_bit(HCI_CONN_BIG_SYNC, hcon->flags)) { /* A BIS slave hcon is notified to the ISO layer * after the Command Complete for the LE Setup * ISO Data Path command is received. Get the @@ -2298,7 +2298,7 @@ static void iso_conn_ready(struct iso_conn *conn) parent = iso_get_sock(hdev, &hcon->src, &hcon->dst, BT_LISTEN, iso_match_big_hcon, hcon); - } else if (test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags)) { + } else if (test_bit(HCI_CONN_BIG_SYNC_FAILED, hcon->flags)) { ev = hci_recv_event_data(hcon->hdev, HCI_EVT_LE_BIG_SYNC_ESTABLISHED); @@ -2312,7 +2312,7 @@ static void iso_conn_ready(struct iso_conn *conn) &hcon->dst, BT_LISTEN, iso_match_big, ev); - } else if (test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) { + } else if (test_bit(HCI_CONN_PA_SYNC_FAILED, hcon->flags)) { ev2 = hci_recv_event_data(hcon->hdev, HCI_EV_LE_PA_SYNC_ESTABLISHED); if (ev2) @@ -2320,7 +2320,7 @@ static void iso_conn_ready(struct iso_conn *conn) &hcon->dst, BT_LISTEN, iso_match_sid, ev2); - } else if (test_bit(HCI_CONN_PA_SYNC, &hcon->flags)) { + } else if (test_bit(HCI_CONN_PA_SYNC, hcon->flags)) { ev3 = hci_recv_event_data(hcon->hdev, HCI_EV_LE_PER_ADV_REPORT); if (ev3) @@ -2376,7 +2376,7 @@ static void iso_conn_ready(struct iso_conn *conn) hcon->dst_type = le_addr_type(iso_pi(parent)->dst_type); } - if (test_bit(HCI_CONN_PA_SYNC, &hcon->flags)) { + if (test_bit(HCI_CONN_PA_SYNC, hcon->flags)) { iso_pi(sk)->qos = iso_pi(parent)->qos; hcon->iso_qos = iso_pi(sk)->qos; iso_pi(sk)->bc_sid = iso_pi(parent)->bc_sid; @@ -2676,8 +2676,8 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) * into the accept queue of the listening socket and wake up * userspace, to inform the user about the event. */ - if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags) || - test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) { + if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, hcon->flags) || + test_bit(HCI_CONN_PA_SYNC_FAILED, hcon->flags)) { struct iso_conn *conn; conn = iso_conn_add(hcon); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4dd56e0074fdaf..7dcb0586a10b2a 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -144,24 +144,12 @@ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn, return c; } -static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, - u8 ident) - __must_hold(&conn->lock) -{ - struct l2cap_chan *c; - - list_for_each_entry(c, &conn->chan_l, list) { - if (c->ident == ident) - return c; - } - return NULL; -} - /* Our connection request has been sent and is still outstanding */ static bool l2cap_chan_connect_pending(struct l2cap_chan *chan) { return chan->state == BT_CONNECT && - test_bit(CONF_CONNECT_PEND, &chan->conf_state); + (test_bit(CONF_CONNECT_PEND, &chan->conf_state) || + test_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags)); } /* Other channels may hold the same ident for a response they still have @@ -174,7 +162,7 @@ static struct l2cap_chan *__l2cap_get_connect_chan_by_ident(struct l2cap_conn *c struct l2cap_chan *c; list_for_each_entry(c, &conn->chan_l, list) { - if (c->ident == ident && l2cap_chan_connect_pending(c)) + if (l2cap_chan_connect_pending(c) && c->ident == ident) return c; } return NULL; @@ -1575,7 +1563,7 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon, if (chan->sec_level == BT_SECURITY_FIPS) min_key_size = 16; - return (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags) || + return (!test_bit(HCI_CONN_ENCRYPT, hcon->flags) || hcon->enc_key_size >= min_key_size); } @@ -3984,6 +3972,7 @@ void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan) l2cap_send_cmd(conn, chan->ident, L2CAP_LE_CONN_RSP, sizeof(rsp), &rsp); + chan->ident = 0; } static void l2cap_ecred_list_defer(struct l2cap_chan *chan, void *data) @@ -4480,11 +4469,11 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, lockdep_assert_held(&chan->conn->lock); - /* Only accept a response to a connection request we sent and that - * is still outstanding. A channel waiting in BT_CONNECT for security - * or the feature mask has not sent one yet. + /* Only accept a response matching a connection request we sent and + * that is still outstanding. A channel waiting in BT_CONNECT for + * security or the feature mask has not sent one yet. */ - if (!l2cap_chan_connect_pending(chan)) + if (!l2cap_chan_connect_pending(chan) || chan->ident != cmd->ident) goto done; switch (result) { @@ -5073,7 +5062,7 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn, BT_DBG("dcid 0x%4.4x mtu %u mps %u credits %u result 0x%2.2x", dcid, mtu, mps, credits, result); - chan = __l2cap_get_chan_by_ident(conn, cmd->ident); + chan = __l2cap_get_connect_chan_by_ident(conn, cmd->ident); if (!chan) return -EBADSLT; @@ -5323,10 +5312,10 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, __set_chan_timer(chan, chan->ops->get_sndtimeo(chan)); - chan->ident = cmd->ident; chan->mode = L2CAP_MODE_LE_FLOWCTL; if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { + chan->ident = cmd->ident; l2cap_state_change(chan, BT_CONNECT2); /* The following result value is actually not defined * for LE CoC but we use it to let the function know @@ -5562,10 +5551,10 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, __set_chan_timer(chan, chan->ops->get_sndtimeo(chan)); - chan->ident = cmd->ident; chan->mode = L2CAP_MODE_EXT_FLOWCTL; if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { + chan->ident = cmd->ident; l2cap_state_change(chan, BT_CONNECT2); defer = true; chan->ops->defer(chan); @@ -5621,9 +5610,10 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, struct l2cap_chan *orig; u16 dcid; - if (chan->ident != cmd->ident || + if (chan->state != BT_CONNECT || chan->mode != L2CAP_MODE_EXT_FLOWCTL || - chan->state == BT_CONNECTED) + !test_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags) || + chan->ident != cmd->ident) continue; l2cap_chan_hold(chan); @@ -5842,16 +5832,9 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn, BT_DBG("result 0x%4.4x", result); - if (!result) { - list_for_each_entry(chan, &conn->chan_l, list) { - if (chan->ident == cmd->ident) - chan->ident = 0; - } - return 0; - } - list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) { - if (chan->ident != cmd->ident) + /* Reconfiguration updates ident with only chan->lock held. */ + if (data_race(READ_ONCE(chan->ident)) != cmd->ident) continue; if (!l2cap_chan_hold_unless_zero(chan)) @@ -5860,7 +5843,15 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn, lockdep_assert_held(&chan->conn->lock); - l2cap_chan_del(chan, ECONNRESET); + if (chan->ident == cmd->ident && + test_and_clear_bit(FLAG_ECRED_RECONF_REQ_SENT, &chan->flags)) { + if (result) { + l2cap_chan_del(chan, ECONNRESET); + chan->ops->close(chan); + } else { + chan->ident = 0; + } + } l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -5875,26 +5866,35 @@ static inline int l2cap_le_command_rej(struct l2cap_conn *conn, __must_hold(&conn->lock) { struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data; - struct l2cap_chan *chan; + struct l2cap_chan *chan, *tmp; if (cmd_len < sizeof(*rej)) return -EPROTO; - chan = __l2cap_get_chan_by_ident(conn, cmd->ident); - if (!chan) - goto done; + list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) { + /* Reconfiguration updates ident with only chan->lock held. */ + if (data_race(READ_ONCE(chan->ident)) != cmd->ident) + continue; - chan = l2cap_chan_hold_unless_zero(chan); - if (!chan) - goto done; + if (!l2cap_chan_hold_unless_zero(chan)) + continue; - l2cap_chan_lock(chan); - lockdep_assert_held(&chan->conn->lock); - l2cap_chan_del(chan, ECONNREFUSED); - l2cap_chan_unlock(chan); - l2cap_chan_put(chan); + l2cap_chan_lock(chan); + lockdep_assert_held(&chan->conn->lock); + + if (chan->ident == cmd->ident && + ((chan->state == BT_CONNECT && + (test_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags) || + test_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags))) || + test_bit(FLAG_ECRED_RECONF_REQ_SENT, &chan->flags))) { + l2cap_chan_del(chan, ECONNREFUSED); + chan->ops->close(chan); + } + + l2cap_chan_unlock(chan); + l2cap_chan_put(chan); + } -done: return 0; } @@ -7389,7 +7389,11 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) u16 cid, len; __le16 psm; - if (hcon->state != BT_CONNECTED) { + /* Also hold data back while the encryption key size is read, as + * the security of the link, e.g. for SMP over BR/EDR, depends on it. + */ + if (hcon->state != BT_CONNECTED || + test_bit(HCI_CONN_ENC_KEY_SIZE_PEND, hcon->flags)) { BT_DBG("queueing pending rx skb"); skb_queue_tail(&conn->pending_rx, skb); return; @@ -7452,7 +7456,11 @@ static void process_pending_rx(struct work_struct *work) mutex_lock(&conn->lock); - while ((skb = skb_dequeue(&conn->pending_rx))) + /* l2cap_recv_frame() would queue it all again while the encryption + * key size is read, l2cap_security_cfm() schedules this once known. + */ + while (!test_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->hcon->flags) && + (skb = skb_dequeue(&conn->pending_rx))) l2cap_recv_frame(conn, skb); mutex_unlock(&conn->lock); @@ -7757,6 +7765,7 @@ static void l2cap_ecred_reconfigure(struct l2cap_chan *chan) pdu->scid[0] = cpu_to_le16(chan->scid); chan->ident = l2cap_get_ident(conn); + set_bit(FLAG_ECRED_RECONF_REQ_SENT, &chan->flags); l2cap_send_cmd(conn, chan->ident, L2CAP_ECRED_RECONF_REQ, struct_size(pdu, scid, 1), pdu); @@ -8041,6 +8050,10 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) } mutex_unlock(&conn->lock); + + /* Process data held back while the encryption key size was read */ + if (!skb_queue_empty(&conn->pending_rx)) + queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); } /* Append fragment into frame respecting the maximum len of rx_skb */ diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 7a2551ef7f50b8..e5c15c083c1acc 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1332,7 +1332,8 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, * available. This avoids resending large numbers of * frames. */ - if (test_bit(CONN_LOCAL_BUSY, &pi->chan->conn_state) && + if (sk->sk_state == BT_CONNECTED && + test_bit(CONN_LOCAL_BUSY, &pi->chan->conn_state) && atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf >> 1) l2cap_chan_busy(pi->chan, 0); diff --git a/net/bluetooth/leds.c b/net/bluetooth/leds.c index 6e349704efe471..072240d08853fa 100644 --- a/net/bluetooth/leds.c +++ b/net/bluetooth/leds.c @@ -59,7 +59,7 @@ static struct led_trigger *led_allocate_basic(struct hci_dev *hdev, { struct hci_basic_led_trigger *htrig; - htrig = devm_kzalloc(&hdev->dev, sizeof(*htrig), GFP_KERNEL); + htrig = devm_kzalloc_obj(&hdev->dev, *htrig); if (!htrig) return NULL; diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 3b9c82bd2f027e..b9262ec134a293 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -304,6 +304,8 @@ static u8 mgmt_errno_status(int err) return MGMT_STATUS_DISCONNECTED; case -ECANCELED: return MGMT_STATUS_CANCELLED; + case -ERFKILL: + return MGMT_STATUS_RFKILLED; } return MGMT_STATUS_FAILED; @@ -3241,7 +3243,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, /* Defer clearing up the connection parameters until closing to * give a chance of keeping them if a repairing happens. */ - set_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags); + set_bit(HCI_CONN_PARAM_REMOVAL_PEND, conn->flags); /* Disable auto-connection parameters if present */ params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); @@ -3416,7 +3418,7 @@ static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, i = 0; list_for_each_entry(c, &hdev->conn_hash.list, list) { - if (test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags)) + if (test_bit(HCI_CONN_MGMT_CONNECTED, c->flags)) i++; } @@ -3428,7 +3430,7 @@ static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, i = 0; list_for_each_entry(c, &hdev->conn_hash.list, list) { - if (!test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags)) + if (!test_bit(HCI_CONN_MGMT_CONNECTED, c->flags)) continue; bacpy(&rp->addr[i].bdaddr, &c->dst); rp->addr[i].type = link_to_bdaddr(c->type, c->dst_type); @@ -3628,7 +3630,7 @@ static int pairing_complete(struct mgmt_pending_cmd *cmd, u8 status) /* The device is paired so there is no need to remove * its connection parameters anymore. */ - clear_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags); + clear_bit(HCI_CONN_PARAM_REMOVAL_PEND, conn->flags); hci_conn_put(conn); @@ -6316,12 +6318,29 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) bt_dev_dbg(hdev, "err %d", err); + hci_dev_lock(hdev); + + /* Change the state before replying, so that a client acting on the + * reply sees it, and only while the discovery is still stopping, as + * Inquiry Cancel may already have stopped it and a new Start Discovery + * may have followed. Go back to DISCOVERY_FINDING when stopping failed + * while the inquiry or the active LE scan of the discovery is still + * running, so that it can be stopped again. + */ + if (hdev->discovery.state == DISCOVERY_STOPPING) { + if (err && (test_bit(HCI_INQUIRY, &hdev->flags) || + (hci_dev_test_flag(hdev, HCI_LE_SCAN) && + hdev->le_scan_type == LE_SCAN_ACTIVE))) + hci_discovery_set_state(hdev, DISCOVERY_FINDING); + else + hci_discovery_set_state(hdev, DISCOVERY_STOPPED); + } + + hci_dev_unlock(hdev); + mgmt_cmd_complete(cmd->sk, cmd->hdev->id, cmd->opcode, mgmt_status(err), cmd->param, 1); mgmt_pending_free(cmd); - - if (!err) - hci_discovery_set_state(hdev, DISCOVERY_STOPPED); } static int stop_discovery_sync(struct hci_dev *hdev, void *data) @@ -8173,7 +8192,11 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, hci_dev_lock(hdev); - if (param_count > 1) + /* A single entry may be an update for one device, so keep the other + * disabled parameters then, but clear them otherwise, including when + * no entries are loaded. + */ + if (param_count != 1) hci_conn_params_clear_disabled(hdev); for (i = 0; i < param_count; i++) { @@ -10128,7 +10151,7 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, u16 eir_len = 0; u32 flags = 0; - if (test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) + if (test_and_set_bit(HCI_CONN_MGMT_CONNECTED, conn->flags)) return; /* allocate buff for LE or BR/EDR adv */ @@ -10177,7 +10200,7 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, * since userspace did not know about them yet, so report it now. * Unencrypted connections have no change to report. */ - if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + if (test_bit(HCI_CONN_ENCRYPT, conn->flags)) mgmt_security_level_changed(conn); } @@ -10289,7 +10312,7 @@ void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status) * still needs it set to know whether to report the security level * reset, so it is consumed there instead of here. */ - if (test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { + if (test_bit(HCI_CONN_MGMT_CONNECTED, conn->flags)) { mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, hci_to_mgmt_reason(status), true); @@ -10930,7 +10953,7 @@ void mgmt_security_level_changed(struct hci_conn *conn) u8 *tlv_data; u8 tlv_len; - if (!test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) + if (!test_bit(HCI_CONN_MGMT_CONNECTED, conn->flags)) return; /* Only ACL, LE and BIS links are tracked as mgmt connections, so @@ -10943,7 +10966,7 @@ void mgmt_security_level_changed(struct hci_conn *conn) return; tlv_len = 2 * (sizeof(*tlv) + sizeof(__u8)); - ev = kzalloc_flex(*ev, tlv_data, tlv_len, GFP_KERNEL); + ev = kzalloc_flex(*ev, tlv_data, tlv_len); if (!ev) return; @@ -10961,9 +10984,9 @@ void mgmt_security_level_changed(struct hci_conn *conn) tlv = (void *)tlv_data; tlv->type = cpu_to_le16(MGMT_SEC_LEVEL_CHANGED_PARAM_ENC_TYPE); tlv->length = sizeof(__u8); - if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + if (!test_bit(HCI_CONN_ENCRYPT, conn->flags)) tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_NONE; - else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) + else if (test_bit(HCI_CONN_AES_CCM, conn->flags)) tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_AES_CCM; else tlv->value[0] = MGMT_CONN_SEC_ENCRYPT_E0; diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 5dac8b2eae42d5..b7015e37e1f1cc 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -984,12 +984,12 @@ static u8 smp_random(struct smp_chan *smp) smp_s1(smp->tk, smp->rrnd, smp->prnd, stk); - if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) + if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, hcon->flags)) return SMP_UNSPECIFIED; hci_le_start_enc(hcon, ediv, rand, stk, smp->enc_key_size); hcon->enc_key_size = smp->enc_key_size; - set_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags); + set_bit(HCI_CONN_STK_ENCRYPT, hcon->flags); } else { u8 stk[16], auth; __le64 rand = 0; @@ -1028,7 +1028,7 @@ static void smp_notify_keys(struct l2cap_conn *conn) persistent = false; else persistent = !test_bit(HCI_CONN_FLUSH_KEY, - &hcon->flags); + hcon->flags); } else { /* The LTKs, IRKs and CSRKs should be persistent only if * both sides had the bonding bit set in their @@ -1186,9 +1186,13 @@ static void sc_generate_ltk(struct smp_chan *smp) struct hci_conn *hcon = smp->conn->hcon; struct hci_dev *hdev = hcon->hdev; struct link_key *key; + int err; + + rcu_read_lock(); key = hci_find_link_key(hdev, &hcon->dst); if (!key) { + rcu_read_unlock(); bt_dev_err(hdev, "no Link Key found to generate LTK"); return; } @@ -1200,16 +1204,19 @@ static void sc_generate_ltk(struct smp_chan *smp) /* SALT = 0x000000000000000000000000746D7032 */ const u8 salt[16] = { 0x32, 0x70, 0x6d, 0x74 }; - if (smp_h7(key->val, salt, smp->tk)) - return; + err = smp_h7(key->val, salt, smp->tk); } else { /* From core spec. Spells out in ASCII as 'tmp2'. */ const u8 tmp2[4] = { 0x32, 0x70, 0x6d, 0x74 }; - if (smp_h6(key->val, tmp2, smp->tk)) - return; + err = smp_h6(key->val, tmp2, smp->tk); } + rcu_read_unlock(); + + if (err) + return; + if (smp_h6(smp->tk, brle, smp->tk)) return; @@ -1753,7 +1760,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) /* SMP over BR/EDR requires special treatment */ if (conn->hcon->type == ACL_LINK) { /* We must have a BR/EDR SC link */ - if (!test_bit(HCI_CONN_AES_CCM, &conn->hcon->flags) && + if (!test_bit(HCI_CONN_AES_CCM, conn->hcon->flags) && !hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) return SMP_CROSS_TRANSP_NOT_ALLOWED; @@ -2202,24 +2209,30 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level) { struct smp_ltk *key; struct hci_conn *hcon = conn->hcon; + bool ret = false; + + rcu_read_lock(); key = hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, hcon->role); if (!key) - return false; + goto unlock; if (smp_ltk_sec_level(key) < sec_level) - return false; + goto unlock; - if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) - return true; + ret = true; + if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, hcon->flags)) + goto unlock; hci_le_start_enc(hcon, key->ediv, key->rand, key->val, key->enc_size); hcon->enc_key_size = key->enc_size; /* We never store STKs for initiator role, so clear this flag */ - clear_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags); + clear_bit(HCI_CONN_STK_ENCRYPT, hcon->flags); - return true; +unlock: + rcu_read_unlock(); + return ret; } bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level, @@ -2235,7 +2248,7 @@ bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level, * don't have an LTK (e.g. because of key distribution bits). */ if (key_pref == SMP_USE_LTK && - test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) && + test_bit(HCI_CONN_STK_ENCRYPT, hcon->flags) && hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, hcon->role)) return false; @@ -3084,11 +3097,11 @@ static void bredr_pairing(struct l2cap_chan *chan) bt_dev_dbg(hdev, "chan %p", chan); /* Only new pairings are interesting */ - if (!test_bit(HCI_CONN_NEW_LINK_KEY, &hcon->flags)) + if (!test_bit(HCI_CONN_NEW_LINK_KEY, hcon->flags)) return; /* Don't bother if we're not encrypted */ - if (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) + if (!test_bit(HCI_CONN_ENCRYPT, hcon->flags)) return; /* Only initiator may initiate SMP over BR/EDR */ @@ -3100,7 +3113,7 @@ static void bredr_pairing(struct l2cap_chan *chan) return; /* BR/EDR must use Secure Connections for SMP */ - if (!test_bit(HCI_CONN_AES_CCM, &hcon->flags) && + if (!test_bit(HCI_CONN_AES_CCM, hcon->flags) && !hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) return; @@ -3149,7 +3162,7 @@ static void smp_resume_cb(struct l2cap_chan *chan) if (!smp) return; - if (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) + if (!test_bit(HCI_CONN_ENCRYPT, hcon->flags)) return; cancel_delayed_work(&smp->security_timer); @@ -3172,7 +3185,7 @@ static void smp_ready_cb(struct l2cap_chan *chan) */ conn->smp = chan; - if (hcon->type == ACL_LINK && test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) + if (hcon->type == ACL_LINK && test_bit(HCI_CONN_ENCRYPT, hcon->flags)) bredr_pairing(chan); } diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 3043a7393c29c2..d6c9dc62182ee4 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -1210,7 +1210,8 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, skb->ip_summed = CHECKSUM_COMPLETE; } - if (prog->type == BPF_PROG_TYPE_LWT_XMIT) { + if (prog->type == BPF_PROG_TYPE_LWT_IN || + prog->type == BPF_PROG_TYPE_LWT_XMIT) { if (!ipv6_mod_enabled()) { pr_warn_once("Please test this program with IPv6 enabled kernel\n"); ret = -EOPNOTSUPP; diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 2123344a56774d..f306cfbc16795c 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -279,6 +279,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, struct sk_buff *reply; struct ipv6hdr *pip6; int na_olen = 8; /* opt hdr + ETH_ALEN for target */ + int headroom; int ns_olen; u8 *daddr; bool dad; @@ -288,7 +289,8 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, if (!dev) return; - len = LL_RESERVED_SPACE(dev) + sizeof(struct ipv6hdr) + + headroom = LL_RESERVED_SPACE(dev); + len = headroom + sizeof(struct ipv6hdr) + sizeof(*na) + na_olen + dev->needed_tailroom; reply = alloc_skb(len, GFP_ATOMIC); @@ -297,7 +299,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, reply->protocol = htons(ETH_P_IPV6); reply->dev = dev; - skb_reserve(reply, LL_RESERVED_SPACE(dev)); + skb_reserve(reply, headroom); skb_push(reply, sizeof(struct ethhdr)); skb_set_mac_header(reply, 0); diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 2c05ebc1299d12..fb25ce3e5e646f 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -341,13 +341,13 @@ static void del_nbp(struct net_bridge_port *p) nbp_delete_promisc(p); + br_mrp_port_del(br, p); + br_cfm_port_del(br, p); + spin_lock_bh(&br->lock); br_stp_disable_port(p); spin_unlock_bh(&br->lock); - br_mrp_port_del(br, p); - br_cfm_port_del(br, p); - br_ifinfo_notify(RTM_DELLINK, NULL, p); list_del_rcu(&p->list); diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index c4e7e03e096900..6f6b574a359db5 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -256,7 +256,7 @@ static void br_vlan_rebuild_port_array(struct net_bridge_vlan *masterv, WARN_ON(!br_vlan_is_master(masterv)); if (count > BR_VLAN_PORT_ARRAY_THRESHOLD) - array = kvmalloc(struct_size(array, vlans, count), GFP_KERNEL); + array = kvmalloc_flex(*array, vlans, count); if (array) { struct net_bridge_vlan *pv; diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c index b5444335b86f2b..8c83dc05114ba7 100644 --- a/net/bridge/netfilter/nf_conntrack_bridge.c +++ b/net/bridge/netfilter/nf_conntrack_bridge.c @@ -358,7 +358,7 @@ nf_ct_bridge_refrag(struct sk_buff *skb, const struct nf_hook_state *state, nf_br_ip6_fragment(state->net, state->sk, skb, &data, output); break; default: - WARN_ON_ONCE(1); + DEBUG_NET_WARN_ON_ONCE(1); return NF_DROP; } diff --git a/net/can/af_can.c b/net/can/af_can.c index 34fe3b28d576f3..0f3051a61aab53 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -226,7 +226,7 @@ int can_send(struct sk_buff *skb, int loop) goto inval_skb; } - if (unlikely(skb->dev->type != ARPHRD_CAN)) { + if (unlikely(!can_get_ml_priv(skb->dev))) { err = -EPERM; goto inval_skb; } @@ -418,7 +418,7 @@ static struct hlist_head *can_rcv_list_find(canid_t *can_id, canid_t *mask, * @mask: CAN mask (see description) * @func: callback function on filter match * @data: returned parameter for callback function - * @ident: string for calling module identification + * @ino: inode number of sock (0 = unknown) * @sk: socket pointer (might be NULL) * * Description: @@ -443,7 +443,7 @@ static struct hlist_head *can_rcv_list_find(canid_t *can_id, canid_t *mask, */ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *), - void *data, char *ident, struct sock *sk) + void *data, u64 ino, struct sock *sk) { struct receiver *rcv; struct hlist_head *rcv_list; @@ -452,7 +452,7 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, /* insert new receiver (dev,canid,mask) -> (func,data) */ - if (dev && (dev->type != ARPHRD_CAN || !can_get_ml_priv(dev))) + if (dev && !can_get_ml_priv(dev)) return -ENODEV; if (dev && !net_eq(net, dev_net(dev))) @@ -462,9 +462,10 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, if (!rcv) return -ENOMEM; - spin_lock_bh(&net->can.rcvlists_lock); - dev_rcv_lists = can_dev_rcv_lists_find(net, dev); + + spin_lock_bh(&dev_rcv_lists->lock); + rcv_list = can_rcv_list_find(&can_id, &mask, dev_rcv_lists); rcv->can_id = can_id; @@ -472,12 +473,15 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, atomic_long_set(&rcv->matches, 0); rcv->func = func; rcv->data = data; - rcv->ident = ident; + rcv->ino = ino; rcv->sk = sk; hlist_add_head_rcu(&rcv->list, rcv_list); dev_rcv_lists->entries++; + spin_unlock_bh(&dev_rcv_lists->lock); + + spin_lock_bh(&net->can.rcvlists_lock); rcv_lists_stats->rcv_entries++; rcv_lists_stats->rcv_entries_max = max(rcv_lists_stats->rcv_entries_max, rcv_lists_stats->rcv_entries); @@ -509,6 +513,14 @@ static void can_rx_delete_receiver(struct rcu_head *rp) * * Description: * Removes subscription entry depending on given (subscription) values. + * The receive lists of a CAN device are protected by a per-device lock, + * so the subscription is found even when the device has been moved to + * another network namespace after can_rx_register(). The caller has to + * ensure that @dev stays valid, e.g. by holding a reference to @dev or + * RTNL. @net should be the namespace that has been used for + * can_rx_register(). It selects the 'any' CAN device lists for + * @dev == NULL and is otherwise only used for the receive list + * statistics, which become imprecise when another namespace is passed. */ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *), @@ -519,15 +531,13 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats; struct can_dev_rcv_lists *dev_rcv_lists; - if (dev && dev->type != ARPHRD_CAN) + if (dev && !can_get_ml_priv(dev)) return; - if (dev && !net_eq(net, dev_net(dev))) - return; + dev_rcv_lists = can_dev_rcv_lists_find(net, dev); - spin_lock_bh(&net->can.rcvlists_lock); + spin_lock_bh(&dev_rcv_lists->lock); - dev_rcv_lists = can_dev_rcv_lists_find(net, dev); rcv_list = can_rcv_list_find(&can_id, &mask, dev_rcv_lists); /* Search the receiver list for the item to delete. This should @@ -547,26 +557,26 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, * a warning here. */ if (!rcv) { + spin_unlock_bh(&dev_rcv_lists->lock); pr_warn("can: receive list entry not found for dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask); - goto out; + return; } hlist_del_rcu(&rcv->list); dev_rcv_lists->entries--; + spin_unlock_bh(&dev_rcv_lists->lock); + + spin_lock_bh(&net->can.rcvlists_lock); if (rcv_lists_stats->rcv_entries > 0) rcv_lists_stats->rcv_entries--; - - out: spin_unlock_bh(&net->can.rcvlists_lock); /* schedule the receiver item for deletion */ - if (rcv) { - if (rcv->sk) - sock_hold(rcv->sk); - call_rcu(&rcv->rcu, can_rx_delete_receiver); - } + if (rcv->sk) + sock_hold(rcv->sk); + call_rcu(&rcv->rcu, can_rx_delete_receiver); } EXPORT_SYMBOL(can_rx_unregister); @@ -684,8 +694,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, { struct can_skb_ext *csx = can_skb_ext_find(skb); - if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || - !csx || !can_is_can_skb(skb))) { + if (unlikely(!can_get_ml_priv(dev) || !csx || !can_is_can_skb(skb))) { pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n", dev->type, skb->len); @@ -710,8 +719,7 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, { struct can_skb_ext *csx = can_skb_ext_find(skb); - if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || - !csx || !can_is_canfd_skb(skb))) { + if (unlikely(!can_get_ml_priv(dev) || !csx || !can_is_canfd_skb(skb))) { pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n", dev->type, skb->len); @@ -736,8 +744,7 @@ static int canxl_rcv(struct sk_buff *skb, struct net_device *dev, { struct can_skb_ext *csx = can_skb_ext_find(skb); - if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || - !csx || !can_is_canxl_skb(skb))) { + if (unlikely(!can_get_ml_priv(dev) || !csx || !can_is_canxl_skb(skb))) { pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n", dev->type, skb->len); @@ -826,6 +833,7 @@ static int can_pernet_init(struct net *net) net->can.rx_alldev_list = kzalloc_obj(*net->can.rx_alldev_list); if (!net->can.rx_alldev_list) goto out; + spin_lock_init(&net->can.rx_alldev_list->lock); net->can.pkg_stats = kzalloc_obj(*net->can.pkg_stats); if (!net->can.pkg_stats) goto out_free_rx_alldev_list; diff --git a/net/can/af_can.h b/net/can/af_can.h index 87887014f5628e..6e593ed5db5f01 100644 --- a/net/can/af_can.h +++ b/net/can/af_can.h @@ -55,7 +55,7 @@ struct receiver { atomic_long_t matches; void (*func)(struct sk_buff *skb, void *data); void *data; - char *ident; + u64 ino; struct sock *sk; struct rcu_head rcu; }; diff --git a/net/can/bcm.c b/net/can/bcm.c index 3d637a1e0ac1a9..7bd2aa39777af4 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -220,9 +221,7 @@ static int bcm_proc_show(struct seq_file *m, void *v) struct bcm_sock *bo = bcm_sk(sk); struct bcm_op *op; - seq_printf(m, ">>> socket %pK", sk->sk_socket); - seq_printf(m, " / sk %pK", sk); - seq_printf(m, " / bo %pK", bo); + seq_printf(m, ">>> sock inode %s", bo->procname); seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs); seq_printf(m, " / bound %s", bcm_proc_getifname(net, ifname, bo->ifindex)); seq_printf(m, " <<<\n"); @@ -963,7 +962,7 @@ static void bcm_remove_op(struct bcm_op *op) static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op) { if (op->rx_reg_dev == dev) { - can_rx_unregister(dev_net(dev), dev, op->can_id, + can_rx_unregister(sock_net(op->sk), dev, op->can_id, REGMASK(op->can_id), bcm_rx_handler, op); /* mark as removed subscription */ @@ -989,21 +988,10 @@ static int bcm_delete_rx_op(struct list_head *ops, struct bcm_msg_head *mh, /* disable automatic timer on frame reception */ op->flags |= RX_NO_AUTOTIMER; - /* - * Don't care if we're bound or not (due to netdev - * problems) can_rx_unregister() is always a save - * thing to do here. - */ if (op->ifindex) { - /* - * Only remove subscriptions that had not - * been removed due to NETDEV_UNREGISTER - * in bcm_notifier() - * - * op->rx_reg_dev is a tracked reference taken - * when the subscription was registered, so it - * stays valid here even if a concurrent - * NETDEV_UNREGISTER already unlisted the dev. + /* Only remove subscriptions that had not been + * removed in bcm_notify(). op->rx_reg_dev keeps + * the device's receive lists accessible. */ if (op->rx_reg_dev) bcm_rx_unreg(op->rx_reg_dev, op); @@ -1536,7 +1524,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, op->can_id, REGMASK(op->can_id), bcm_rx_handler, op, - "bcm", sk); + sock_i_ino(sk), sk); /* keep a tracked reference so that a later * unregister can safely reach the device even @@ -1560,7 +1548,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, } else { err = can_rx_register(sock_net(sk), NULL, op->can_id, REGMASK(op->can_id), - bcm_rx_handler, op, "bcm", sk); + bcm_rx_handler, op, + sock_i_ino(sk), sk); } if (err) { @@ -1719,7 +1708,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) goto out_release; } - if (dev->type != ARPHRD_CAN) { + if (!can_get_ml_priv(dev)) { dev_put(dev); ret = -ENODEV; goto out_release; @@ -1867,7 +1856,7 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg, { struct net_device *dev = netdev_notifier_info_to_dev(ptr); - if (dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(dev)) return NOTIFY_DONE; if (msg != NETDEV_UNREGISTER && msg != NETDEV_DOWN) return NOTIFY_DONE; @@ -1935,6 +1924,7 @@ static int bcm_release(struct socket *sock) list_del(&bo->notifier); spin_unlock(&bcm_notifier_lock); + /* bcm_notify() can not access this socket anymore */ lock_sock(sk); #if IS_ENABLED(CONFIG_PROC_FS) @@ -1948,29 +1938,20 @@ static int bcm_release(struct socket *sock) bcm_remove_op(op); } - list_for_each_entry_safe(op, next, &bo->rx_ops, list) { - /* - * Don't care if we're bound or not (due to netdev problems) - * can_rx_unregister() is always a save thing to do here. - */ + list_for_each_entry(op, &bo->rx_ops, list) { if (op->ifindex) { - /* - * Only remove subscriptions that had not - * been removed due to NETDEV_UNREGISTER - * in bcm_notifier() - * - * op->rx_reg_dev is a tracked reference taken - * when the subscription was registered, so it - * stays valid here even if a concurrent - * NETDEV_UNREGISTER already unlisted the device. + /* Only remove subscriptions that had not been removed + * in bcm_notify(). op->rx_reg_dev keeps the device's + * receive lists accessible. */ if (op->rx_reg_dev) bcm_rx_unreg(op->rx_reg_dev, op); - } else + } else { can_rx_unregister(net, NULL, op->can_id, REGMASK(op->can_id), bcm_rx_handler, op); - + } + cond_resched(); } synchronize_rcu(); @@ -2024,7 +2005,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr_unsized *uaddr, int ret = -ENODEV; goto fail; } - if (dev->type != ARPHRD_CAN) { + if (!can_get_ml_priv(dev)) { dev_put(dev); ret = -ENODEV; goto fail; @@ -2040,8 +2021,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr_unsized *uaddr, int #if IS_ENABLED(CONFIG_PROC_FS) if (net->can.bcmproc_dir) { - /* unique socket address as filename */ - sprintf(bo->procname, "%llu", sock_i_ino(sk)); + /* use unique socket inode number as filename */ + snprintf(bo->procname, sizeof(bo->procname), + "%llu", sock_i_ino(sk)); bo->bcm_proc_read = proc_create_net_single(bo->procname, 0644, net->can.bcmproc_dir, bcm_proc_show, sk); diff --git a/net/can/gw.c b/net/can/gw.c index 5793cb2420ed3c..8a5327d8a00e8f 100644 --- a/net/can/gw.c +++ b/net/can/gw.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -579,7 +580,7 @@ static inline int cgw_register_filter(struct net *net, struct cgw_job *gwj) { return can_rx_register(net, gwj->src.dev, gwj->ccgw.filter.can_id, gwj->ccgw.filter.can_mask, can_can_gw_rcv, - gwj, "gw", NULL); + gwj, 0, NULL); } static inline void cgw_unregister_filter(struct net *net, struct cgw_job *gwj) @@ -612,7 +613,7 @@ static int cgw_notifier(struct notifier_block *nb, struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct net *net = dev_net(dev); - if (dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(dev)) return NOTIFY_DONE; if (msg == NETDEV_UNREGISTER) { @@ -1163,7 +1164,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh, if (!gwj->src.dev) goto out; - if (gwj->src.dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(gwj->src.dev)) goto out; gwj->dst.dev = __dev_get_by_index(net, gwj->ccgw.dst_idx); @@ -1171,7 +1172,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh, if (!gwj->dst.dev) goto out; - if (gwj->dst.dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(gwj->dst.dev)) goto out; /* is sending the skb back to the incoming interface intended? */ diff --git a/net/can/isotp.c b/net/can/isotp.c index f5dc9d04bd6862..7a90ba3f1cf1c4 100644 --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -755,6 +756,14 @@ static void isotp_rcv(struct sk_buff *skb, void *data) if (skb->len != so->ll.mtu) return; + /* check for correct CAN CC/FD frame content */ + if (so->ll.mtu == CAN_MTU) { + if (!can_is_can_skb(skb)) + return; + } else if (!can_is_canfd_skb(skb)) { + return; + } + cf = (struct canfd_frame *)skb->data; /* if enabled: check reception of my configured extended address */ @@ -1123,7 +1132,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) int off; int err; - if (!so->bound || READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN) + if (!READ_ONCE(so->bound) || READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN) return -EADDRNOTAVAIL; /* claim the socket under so->rx_lock: this serializes the claim @@ -1168,7 +1177,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) /* so->bound is only checked once above - a wakeup may have * unbound/rebound the socket meanwhile => recheck */ - if (!so->bound) { + if (!READ_ONCE(so->bound)) { err = -EADDRNOTAVAIL; goto err_out_drop; } @@ -1414,7 +1423,7 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK | MSG_CMSG_COMPAT)) return -EINVAL; - if (!so->bound) + if (!READ_ONCE(so->bound)) return -EADDRNOTAVAIL; skb = skb_recv_datagram(sk, flags, &ret); @@ -1488,11 +1497,11 @@ static int isotp_release(struct socket *sock) list_del(&so->notifier); spin_unlock(&isotp_notifier_lock); - rtnl_lock(); lock_sock(sk); /* remove current filters & unregister - * tracked reference so->dev is taken at bind() time with rtnl_lock + * the tracked reference so->dev keeps the device's receive lists + * accessible, even after a namespace change */ if (so->bound && so->dev) { if (isotp_register_rxid(so)) @@ -1507,11 +1516,9 @@ static int isotp_release(struct socket *sock) } so->ifindex = 0; - so->bound = 0; + WRITE_ONCE(so->bound, 0); so->dev = NULL; - rtnl_unlock(); - /* Always wait for a grace period before touching the timers below. * A concurrent NETDEV_UNREGISTER may have already unregistered our * filters and cleared so->bound in isotp_notify() without waiting @@ -1541,7 +1548,6 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l struct sock *sk = sock->sk; struct isotp_sock *so = isotp_sk(sk); struct net *net = sock_net(sk); - int ifindex; struct net_device *dev; canid_t tx_id = addr->can_addr.tp.tx_id; canid_t rx_id = addr->can_addr.tp.rx_id; @@ -1579,7 +1585,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l if (!addr->can_ifindex) return -ENODEV; - rtnl_lock(); + /* lock_sock() serializes the binding with isotp_notify() */ lock_sock(sk); if (so->bound) { @@ -1605,61 +1611,83 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l goto out; } - dev = dev_get_by_index(net, addr->can_ifindex); - if (!dev) { - err = -ENODEV; - goto out; - } - if (dev->type != ARPHRD_CAN) { + /* Publish the device inside the RCU section of the lookup: When it + * is unlisted concurrently, either isotp_notify() sees so->dev after + * synchronize_net() or the lookup fails. Check the device before + * publishing it. + */ + rcu_read_lock(); + dev = dev_get_by_index_rcu(net, addr->can_ifindex); + if (!dev || !can_get_ml_priv(dev)) err = -ENODEV; - goto out_put_dev; - } - if (READ_ONCE(dev->mtu) < so->ll.mtu) { + else if (READ_ONCE(dev->mtu) < so->ll.mtu) err = -EINVAL; - goto out_put_dev; + if (!err) { + dev_hold(dev); + WRITE_ONCE(so->dev, dev); } - if (!(dev->flags & IFF_UP)) - notify_enetdown = 1; - - ifindex = dev->ifindex; + rcu_read_unlock(); + if (err) + goto out; - if (isotp_register_rxid(so)) - can_rx_register(net, dev, rx_id, SINGLE_MASK(rx_id), - isotp_rcv, sk, "isotp", sk); + /* switch to new settings */ + so->ifindex = dev->ifindex; + so->rxid = rx_id; + so->txid = tx_id; /* no consecutive frame echo skb in flight */ WRITE_ONCE(so->cfecho, 0); - /* register for echo skb's */ - can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id), - isotp_rcv_echo, sk, "isotpe", sk); + /* register for echo skb's first (no echo traffic at this point) */ + err = can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id), + isotp_rcv_echo, sk, sock_i_ino(sk), sk); + if (err) + goto out_put_dev; - /* switch to new settings */ - so->ifindex = ifindex; - so->rxid = rx_id; - so->txid = tx_id; - so->bound = 1; + if (isotp_register_rxid(so)) { + err = can_rx_register(net, dev, rx_id, SINGLE_MASK(rx_id), + isotp_rcv, sk, sock_i_ino(sk), sk); + if (err) { + /* unregister echo skb subscription */ + can_rx_unregister(net, dev, tx_id, SINGLE_MASK(tx_id), + isotp_rcv_echo, sk); + goto out_put_dev; + } + } + + WRITE_ONCE(so->bound, 1); /* bind() ok -> hold a reference for so->dev so that isotp_release() * can safely reach the device later, even if a concurrent * NETDEV_UNREGISTER has already unlisted it by ifindex. */ - so->dev = dev; netdev_hold(so->dev, &so->dev_tracker, GFP_KERNEL); + /* Either isotp_notify() sees so->dev on NETDEV_DOWN or we see the + * cleared IFF_UP, pairs with isotp_notify() + */ + smp_mb(); + if (!(READ_ONCE(dev->flags) & IFF_UP)) + notify_enetdown = 1; + out_put_dev: - /* remove potential reference from dev_get_by_index() */ + /* revert so->ifindex and so->dev on failed bind() */ + if (err) { + so->ifindex = 0; + WRITE_ONCE(so->dev, NULL); + } + + /* remove reference from the device lookup */ dev_put(dev); out: - release_sock(sk); - rtnl_unlock(); - if (notify_enetdown) { sk->sk_err = ENETDOWN; if (!sock_flag(sk, SOCK_DEAD)) sk_error_report(sk); } + release_sock(sk); + return err; } @@ -1681,8 +1709,8 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer) return ISOTP_MIN_NAMELEN; } -static int isotp_setsockopt_locked(struct socket *sock, int level, int optname, - sockptr_t optval, unsigned int optlen) +static int isotp_setsockopt_locked(struct socket *sock, int optname, + const void *val) { struct sock *sk = sock->sk; struct isotp_sock *so = isotp_sk(sk); @@ -1693,11 +1721,7 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname, switch (optname) { case CAN_ISOTP_OPTS: - if (optlen != sizeof(struct can_isotp_options)) - return -EINVAL; - - if (copy_from_sockptr(&so->opt, optval, optlen)) - return -EFAULT; + memcpy(&so->opt, val, sizeof(so->opt)); /* no separate rx_ext_address is given => use ext_address */ if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR)) @@ -1722,55 +1746,37 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname, break; case CAN_ISOTP_RECV_FC: - if (optlen != sizeof(struct can_isotp_fc_options)) - return -EINVAL; - - if (copy_from_sockptr(&so->rxfc, optval, optlen)) - return -EFAULT; + memcpy(&so->rxfc, val, sizeof(so->rxfc)); break; case CAN_ISOTP_TX_STMIN: - if (optlen != sizeof(u32)) - return -EINVAL; - - if (copy_from_sockptr(&so->force_tx_stmin, optval, optlen)) - return -EFAULT; + so->force_tx_stmin = *(const u32 *)val; break; case CAN_ISOTP_RX_STMIN: - if (optlen != sizeof(u32)) - return -EINVAL; - - if (copy_from_sockptr(&so->force_rx_stmin, optval, optlen)) - return -EFAULT; + so->force_rx_stmin = *(const u32 *)val; break; - case CAN_ISOTP_LL_OPTS: - if (optlen == sizeof(struct can_isotp_ll_options)) { - struct can_isotp_ll_options ll; - - if (copy_from_sockptr(&ll, optval, optlen)) - return -EFAULT; + case CAN_ISOTP_LL_OPTS: { + const struct can_isotp_ll_options *ll = val; - /* check for correct ISO 11898-1 DLC data length */ - if (ll.tx_dl != padlen(ll.tx_dl)) - return -EINVAL; + /* check for correct ISO 11898-1 DLC data length */ + if (ll->tx_dl != padlen(ll->tx_dl)) + return -EINVAL; - if (ll.mtu != CAN_MTU && ll.mtu != CANFD_MTU) - return -EINVAL; + if (ll->mtu != CAN_MTU && ll->mtu != CANFD_MTU) + return -EINVAL; - if (ll.mtu == CAN_MTU && - (ll.tx_dl > CAN_MAX_DLEN || ll.tx_flags != 0)) - return -EINVAL; + if (ll->mtu == CAN_MTU && + (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0)) + return -EINVAL; - memcpy(&so->ll, &ll, sizeof(ll)); + memcpy(&so->ll, ll, sizeof(*ll)); - /* set ll_dl for tx path to similar place as for rx */ - so->tx.ll_dl = ll.tx_dl; - } else { - return -EINVAL; - } + /* set ll_dl for tx path to similar place as for rx */ + so->tx.ll_dl = ll->tx_dl; break; + } default: ret = -ENOPROTOOPT; @@ -1784,13 +1790,49 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; + union { + struct can_isotp_options opt; + struct can_isotp_fc_options rxfc; + struct can_isotp_ll_options ll; + u32 stmin; + } val; + unsigned int size; int ret; if (level != SOL_CAN_ISOTP) return -EINVAL; + /* copy the option values from user space before lock_sock() */ + switch (optname) { + case CAN_ISOTP_OPTS: + size = sizeof(val.opt); + break; + + case CAN_ISOTP_RECV_FC: + size = sizeof(val.rxfc); + break; + + case CAN_ISOTP_TX_STMIN: + case CAN_ISOTP_RX_STMIN: + size = sizeof(val.stmin); + break; + + case CAN_ISOTP_LL_OPTS: + size = sizeof(val.ll); + break; + + default: + return -ENOPROTOOPT; + } + + if (optlen != size) + return -EINVAL; + + if (copy_from_sockptr(&val, optval, size)) + return -EFAULT; + lock_sock(sk); - ret = isotp_setsockopt_locked(sock, level, optname, optval, optlen); + ret = isotp_setsockopt_locked(sock, optname, &val); release_sock(sk); return ret; } @@ -1855,12 +1897,21 @@ static void isotp_notify(struct isotp_sock *so, unsigned long msg, if (!net_eq(dev_net(dev), sock_net(sk))) return; - if (so->dev != dev) + if (msg == NETDEV_DOWN) + smp_mb(); /* pairs with isotp_bind(), see raw_notify() */ + + /* lockless fast path, see raw_notify() */ + if (READ_ONCE(so->dev) != dev) return; switch (msg) { case NETDEV_UNREGISTER: lock_sock(sk); + if (so->dev != dev) { + release_sock(sk); + break; + } + /* remove current filters & unregister */ if (so->bound) { if (isotp_register_rxid(so)) @@ -1875,16 +1926,19 @@ static void isotp_notify(struct isotp_sock *so, unsigned long msg, } so->ifindex = 0; - so->bound = 0; - so->dev = NULL; - release_sock(sk); + WRITE_ONCE(so->bound, 0); + WRITE_ONCE(so->dev, NULL); sk->sk_err = ENODEV; if (!sock_flag(sk, SOCK_DEAD)) sk_error_report(sk); + release_sock(sk); break; case NETDEV_DOWN: + if (!READ_ONCE(so->bound)) + break; + sk->sk_err = ENETDOWN; if (!sock_flag(sk, SOCK_DEAD)) sk_error_report(sk); @@ -1897,7 +1951,7 @@ static int isotp_notifier(struct notifier_block *nb, unsigned long msg, { struct net_device *dev = netdev_notifier_info_to_dev(ptr); - if (dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(dev)) return NOTIFY_DONE; if (msg != NETDEV_UNREGISTER && msg != NETDEV_DOWN) return NOTIFY_DONE; diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c index 5e5e6c228f2252..d9384cf0e356f7 100644 --- a/net/can/j1939/main.c +++ b/net/can/j1939/main.c @@ -184,7 +184,7 @@ static int j1939_can_rx_register(struct j1939_priv *priv) j1939_priv_get(priv); ret = can_rx_register(dev_net(ndev), ndev, J1939_CAN_ID, J1939_CAN_MASK, - j1939_can_recv, priv, "j1939", NULL); + j1939_can_recv, priv, 0, NULL); if (ret < 0) { j1939_priv_put(priv); return ret; diff --git a/net/can/proc.c b/net/can/proc.c index de4d05ae345977..b7496d2a37cd1e 100644 --- a/net/can/proc.c +++ b/net/can/proc.c @@ -76,16 +76,39 @@ static const char rx_list_name[][8] = { * af_can statistics stuff */ +static void can_reset_pkg_stats(struct can_pkg_stats *pkg_stats) +{ + atomic_long_set(&pkg_stats->rx_frames, 0); + atomic_long_set(&pkg_stats->tx_frames, 0); + atomic_long_set(&pkg_stats->matches, 0); + + pkg_stats->total_rx_rate = 0; + pkg_stats->total_tx_rate = 0; + pkg_stats->total_rx_match_ratio = 0; + + pkg_stats->current_rx_rate = 0; + pkg_stats->current_tx_rate = 0; + pkg_stats->current_rx_match_ratio = 0; + + pkg_stats->max_rx_rate = 0; + pkg_stats->max_tx_rate = 0; + pkg_stats->max_rx_match_ratio = 0; + + atomic_long_set(&pkg_stats->rx_frames_delta, 0); + atomic_long_set(&pkg_stats->tx_frames_delta, 0); + atomic_long_set(&pkg_stats->matches_delta, 0); +} + static void can_init_stats(struct net *net) { struct can_pkg_stats *pkg_stats = net->can.pkg_stats; struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats; /* - * This memset function is called from a timer context (when + * This stats reset is called from a timer context (when * can_stattimer is active which is the default) OR in a process * context (reading the proc_fs when can_stattimer is disabled). */ - memset(pkg_stats, 0, sizeof(struct can_pkg_stats)); + can_reset_pkg_stats(pkg_stats); pkg_stats->jiffies_init = jiffies; rcv_lists_stats->stats_reset++; @@ -121,29 +144,23 @@ void can_stat_update(struct timer_list *t) long rx_frames = atomic_long_read(&pkg_stats->rx_frames); long tx_frames = atomic_long_read(&pkg_stats->tx_frames); long matches = atomic_long_read(&pkg_stats->matches); - long rx_frames_delta = atomic_long_read(&pkg_stats->rx_frames_delta); - long tx_frames_delta = atomic_long_read(&pkg_stats->tx_frames_delta); - long matches_delta = atomic_long_read(&pkg_stats->matches_delta); + /* fetch and clear values for 'current rate' calculation */ + long rx_frames_delta = atomic_long_xchg(&pkg_stats->rx_frames_delta, 0); + long tx_frames_delta = atomic_long_xchg(&pkg_stats->tx_frames_delta, 0); + long matches_delta = atomic_long_xchg(&pkg_stats->matches_delta, 0); - /* restart counting in timer context on user request */ - if (user_reset) - can_init_stats(net); - - /* restart counting on jiffies overflow */ - if (j < pkg_stats->jiffies_init) - can_init_stats(net); - - /* prevent overflow in calc_rate() */ - if (rx_frames > (LONG_MAX / HZ)) - can_init_stats(net); - - /* prevent overflow in calc_rate() */ - if (tx_frames > (LONG_MAX / HZ)) - can_init_stats(net); - - /* matches overflow - very improbable */ - if (matches > (LONG_MAX / 100)) + /* + * Restart counting in timer context on user request, on jiffies + * overflow or to prevent overflows in calc_rate() and in the + * match ratio calculation. The local snapshots are stale after + * the reset, so skip the calculation for this interval. + */ + if (user_reset || j < pkg_stats->jiffies_init || + rx_frames > (LONG_MAX / HZ) || tx_frames > (LONG_MAX / HZ) || + matches > (LONG_MAX / 100)) { can_init_stats(net); + goto out; + } /* calc total values */ if (rx_frames) @@ -172,11 +189,7 @@ void can_stat_update(struct timer_list *t) if (pkg_stats->max_rx_match_ratio < pkg_stats->current_rx_match_ratio) pkg_stats->max_rx_match_ratio = pkg_stats->current_rx_match_ratio; - /* clear values for 'current rate' calculation */ - atomic_long_set(&pkg_stats->tx_frames_delta, 0); - atomic_long_set(&pkg_stats->rx_frames_delta, 0); - atomic_long_set(&pkg_stats->matches_delta, 0); - +out: /* restart timer (one second) */ mod_timer(&net->can.stattimer, round_jiffies(jiffies + HZ)); } @@ -191,26 +204,32 @@ static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list, struct receiver *r; hlist_for_each_entry_rcu(r, rx_list, list) { + char symcheck[4]; char *fmt = (r->can_id & CAN_EFF_FLAG)? - " %-5s %08x %08x %pK %pK %8ld %s\n" : - " %-5s %03x %08x %pK %pK %8ld %s\n"; + " %6s %08x %08x %8ld %10llu" : + " %6s %03x %08x %8ld %10llu"; seq_printf(m, fmt, DNAME(dev), r->can_id, r->mask, - r->func, r->data, atomic_long_read(&r->matches), - r->ident); + atomic_long_read(&r->matches), r->ino); + + /* %ps falls back to the raw text address when the symbol + * can not be resolved (KALLSYMS=n, stripped module symbols) + */ + snprintf(symcheck, sizeof(symcheck), "%ps", r->func); + if (strncmp(symcheck, "0x", 2)) + seq_printf(m, " %ps\n", r->func); + else + seq_puts(m, " (unknown)\n"); } } static void can_print_recv_banner(struct seq_file *m) { /* - * can1. 00000000 00000000 00000000 - * ....... 0 tp20 + * device can_id can_mask matches sock_inode function + * vcan0 000 00000000 0 43798 raw_rcv [can_raw] */ - if (IS_ENABLED(CONFIG_64BIT)) - seq_puts(m, " device can_id can_mask function userdata matches ident\n"); - else - seq_puts(m, " device can_id can_mask function userdata matches ident\n"); + seq_puts(m, " device can_id can_mask matches sock_inode function\n"); } static int can_stats_proc_show(struct seq_file *m, void *v) diff --git a/net/can/raw.c b/net/can/raw.c index 0acd4f6c6dd672..f14270b56f5219 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -85,6 +85,7 @@ struct raw_sock { struct sock sk; struct net_device *dev; netdevice_tracker dev_tracker; + struct net_device *bind_dev; /* hint for raw_notify(), no reference */ struct list_head notifier; int ifindex; unsigned int bound:1; @@ -224,9 +225,10 @@ static int raw_enable_filters(struct net *net, struct net_device *dev, int i; for (i = 0; i < count; i++) { + cond_resched(); err = can_rx_register(net, dev, filter[i].can_id, filter[i].can_mask, - raw_rcv, sk, "raw", sk); + raw_rcv, sk, sock_i_ino(sk), sk); if (err) { /* clean up successfully registered filters */ while (--i >= 0) @@ -247,7 +249,7 @@ static int raw_enable_errfilter(struct net *net, struct net_device *dev, if (err_mask) err = can_rx_register(net, dev, 0, err_mask | CAN_ERR_FLAG, - raw_rcv, sk, "raw", sk); + raw_rcv, sk, sock_i_ino(sk), sk); return err; } @@ -258,9 +260,11 @@ static void raw_disable_filters(struct net *net, struct net_device *dev, { int i; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { can_rx_unregister(net, dev, filter[i].can_id, filter[i].can_mask, raw_rcv, sk); + cond_resched(); + } } static inline void raw_disable_errfilter(struct net *net, @@ -305,16 +309,31 @@ static void raw_notify(struct raw_sock *ro, unsigned long msg, struct net_device *dev) { struct sock *sk = &ro->sk; + struct net_device *bind_dev; if (!net_eq(dev_net(dev), sock_net(sk))) return; - if (ro->dev != dev) + if (msg == NETDEV_DOWN) + smp_mb(); /* IFF_UP is cleared before, pairs with raw_bind() */ + + /* Lockless fast path, ro->bind_dev covers a concurrent bind(). + * Read it before ro->dev, pairs with smp_store_release() in + * raw_bind(). A stale ro->bind_dev only costs a lock_sock(). + */ + bind_dev = smp_load_acquire(&ro->bind_dev); + if (READ_ONCE(ro->dev) != dev && + (msg != NETDEV_UNREGISTER || bind_dev != dev)) return; switch (msg) { case NETDEV_UNREGISTER: lock_sock(sk); + if (ro->dev != dev) { + release_sock(sk); + break; + } + /* remove current filters & unregister */ if (ro->bound) { raw_disable_allfilters(dev_net(dev), dev, sk); @@ -326,13 +345,13 @@ static void raw_notify(struct raw_sock *ro, unsigned long msg, ro->ifindex = 0; ro->bound = 0; - ro->dev = NULL; + WRITE_ONCE(ro->dev, NULL); ro->count = 0; - release_sock(sk); sk->sk_err = ENODEV; if (!sock_flag(sk, SOCK_DEAD)) sk_error_report(sk); + release_sock(sk); break; case NETDEV_DOWN: @@ -348,7 +367,7 @@ static int raw_notifier(struct notifier_block *nb, unsigned long msg, { struct net_device *dev = netdev_notifier_info_to_dev(ptr); - if (dev->type != ARPHRD_CAN) + if (!can_get_ml_priv(dev)) return NOTIFY_DONE; if (msg != NETDEV_UNREGISTER && msg != NETDEV_DOWN) return NOTIFY_DONE; @@ -381,6 +400,7 @@ static int raw_init(struct sock *sk) ro->bound = 0; ro->ifindex = 0; ro->dev = NULL; + ro->bind_dev = NULL; /* set default filter to single entry dfilter */ ro->dfilter.can_id = 0; @@ -431,13 +451,15 @@ static int raw_release(struct socket *sock) list_del(&ro->notifier); spin_unlock(&raw_notifier_lock); - rtnl_lock(); lock_sock(sk); - /* remove current filters & unregister */ + /* remove current filters & unregister + * the tracked reference ro->dev keeps the device's receive lists + * accessible, even after a namespace change + */ if (ro->bound) { if (ro->dev) { - raw_disable_allfilters(dev_net(ro->dev), ro->dev, sk); + raw_disable_allfilters(net, ro->dev, sk); netdev_put(ro->dev, &ro->dev_tracker); } else { raw_disable_allfilters(net, NULL, sk); @@ -456,7 +478,6 @@ static int raw_release(struct socket *sock) sock->sk = NULL; release_sock(sk); - rtnl_unlock(); sock_prot_inuse_add(net, sk->sk_prot, -1); sock_put(sk); @@ -479,26 +500,34 @@ static int raw_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len if (addr->can_family != AF_CAN) return -EINVAL; - rtnl_lock(); + /* lock_sock() serializes the binding with raw_notify() */ lock_sock(sk); if (ro->bound && addr->can_ifindex == ro->ifindex) goto out; if (addr->can_ifindex) { - dev = dev_get_by_index(sock_net(sk), addr->can_ifindex); + /* Publish the device inside the RCU section of the lookup: + * When it is unlisted concurrently, either raw_notify() sees + * ro->bind_dev after synchronize_net() or the lookup fails. + */ + rcu_read_lock(); + dev = dev_get_by_index_rcu(sock_net(sk), addr->can_ifindex); + if (dev) { + dev_hold(dev); + /* pairs with smp_load_acquire() in raw_notify() */ + smp_store_release(&ro->bind_dev, dev); + } + rcu_read_unlock(); if (!dev) { err = -ENODEV; goto out; } - if (dev->type != ARPHRD_CAN) { + if (!can_get_ml_priv(dev)) { err = -ENODEV; goto out_put_dev; } - if (!(dev->flags & IFF_UP)) - notify_enetdown = 1; - ifindex = dev->ifindex; /* filters set by default/setsockopt */ @@ -517,7 +546,7 @@ static int raw_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len if (ro->bound) { /* unregister old filters */ if (ro->dev) { - raw_disable_allfilters(dev_net(ro->dev), + raw_disable_allfilters(sock_net(sk), ro->dev, sk); /* drop reference to old ro->dev */ netdev_put(ro->dev, &ro->dev_tracker); @@ -528,24 +557,32 @@ static int raw_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len ro->ifindex = ifindex; ro->bound = 1; /* bind() ok -> hold a reference for new ro->dev */ - ro->dev = dev; + WRITE_ONCE(ro->dev, dev); if (ro->dev) netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL); + + if (dev) { + /* Either raw_notify() sees ro->dev on NETDEV_DOWN or + * we see the cleared IFF_UP, pairs with raw_notify() + */ + smp_mb(); + if (!(READ_ONCE(dev->flags) & IFF_UP)) + notify_enetdown = 1; + } } out_put_dev: - /* remove potential reference from dev_get_by_index() */ + /* remove reference from the device lookup */ dev_put(dev); out: - release_sock(sk); - rtnl_unlock(); - if (notify_enetdown) { sk->sk_err = ENETDOWN; if (!sock_flag(sk, SOCK_DEAD)) sk_error_report(sk); } + release_sock(sk); + return err; } @@ -567,58 +604,36 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr, } static int raw_setsockopt_locked(struct socket *sock, int optname, - sockptr_t optval, unsigned int optlen) + const void *val, struct can_filter *filter, + int count) { struct sock *sk = sock->sk; struct raw_sock *ro = raw_sk(sk); - struct can_filter *filter = NULL; /* dyn. alloc'ed filters */ - struct can_filter sfilter; /* single filter */ struct net_device *dev = NULL; - can_err_mask_t err_mask = 0; - int count = 0; + can_err_mask_t err_mask; int flag; int err = 0; switch (optname) { case CAN_RAW_FILTER: - if (optlen % sizeof(struct can_filter) != 0) - return -EINVAL; - - if (optlen > CAN_RAW_FILTER_MAX * sizeof(struct can_filter)) - return -EINVAL; - - count = optlen / sizeof(struct can_filter); - - if (count > 1) { - /* filter does not fit into dfilter => alloc space */ - filter = memdup_sockptr(optval, optlen); - if (IS_ERR(filter)) - return PTR_ERR(filter); - } else if (count == 1) { - if (copy_from_sockptr(&sfilter, optval, sizeof(sfilter))) - return -EFAULT; - } - + /* @filter has been copied by raw_setsockopt(). It is linked + * to the socket on success and freed by the caller on error. + * + * The reg_state check is only a shortcut: On a concurrent + * unregistration or namespace change raw_notify() waits for + * lock_sock() and removes the filters set here. + */ dev = ro->dev; - if (ro->bound && dev && dev->reg_state != NETREG_REGISTERED) { - if (count > 1) - kfree(filter); + if (ro->bound && dev && + READ_ONCE(dev->reg_state) != NETREG_REGISTERED) return -ENODEV; - } if (ro->bound) { /* (try to) register the new filters */ - if (count == 1) - err = raw_enable_filters(sock_net(sk), dev, sk, - &sfilter, 1); - else - err = raw_enable_filters(sock_net(sk), dev, sk, - filter, count); - if (err) { - if (count > 1) - kfree(filter); + err = raw_enable_filters(sock_net(sk), dev, sk, filter, + count); + if (err) return err; - } /* remove old filter registrations */ raw_disable_filters(sock_net(sk), dev, sk, ro->filter, @@ -632,7 +647,7 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, /* link new filters to the socket */ if (count == 1) { /* copy filter data for single filter */ - ro->dfilter = sfilter; + ro->dfilter = *filter; filter = &ro->dfilter; } ro->filter = filter; @@ -640,16 +655,12 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, break; case CAN_RAW_ERR_FILTER: - if (optlen != sizeof(err_mask)) - return -EINVAL; - - if (copy_from_sockptr(&err_mask, optval, optlen)) - return -EFAULT; - - err_mask &= CAN_ERR_MASK; + err_mask = *(const can_err_mask_t *)val & CAN_ERR_MASK; + /* lockless shortcut, see CAN_RAW_FILTER */ dev = ro->dev; - if (ro->bound && dev && dev->reg_state != NETREG_REGISTERED) + if (ro->bound && dev && + READ_ONCE(dev->reg_state) != NETREG_REGISTERED) return -ENODEV; /* remove current error mask */ @@ -671,31 +682,15 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, break; case CAN_RAW_LOOPBACK: - if (optlen != sizeof(flag)) - return -EINVAL; - - if (copy_from_sockptr(&flag, optval, optlen)) - return -EFAULT; - - ro->loopback = !!flag; + ro->loopback = !!*(const int *)val; break; case CAN_RAW_RECV_OWN_MSGS: - if (optlen != sizeof(flag)) - return -EINVAL; - - if (copy_from_sockptr(&flag, optval, optlen)) - return -EFAULT; - - ro->recv_own_msgs = !!flag; + ro->recv_own_msgs = !!*(const int *)val; break; case CAN_RAW_FD_FRAMES: - if (optlen != sizeof(flag)) - return -EINVAL; - - if (copy_from_sockptr(&flag, optval, optlen)) - return -EFAULT; + flag = *(const int *)val; /* Enabling CAN XL includes CAN FD */ if (ro->xl_frames && !flag) @@ -705,13 +700,7 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, break; case CAN_RAW_XL_FRAMES: - if (optlen != sizeof(flag)) - return -EINVAL; - - if (copy_from_sockptr(&flag, optval, optlen)) - return -EFAULT; - - ro->xl_frames = !!flag; + ro->xl_frames = !!*(const int *)val; /* Enabling CAN XL includes CAN FD */ if (ro->xl_frames) @@ -719,11 +708,7 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, break; case CAN_RAW_XL_VCID_OPTS: - if (optlen != sizeof(ro->raw_vcid_opts)) - return -EINVAL; - - if (copy_from_sockptr(&ro->raw_vcid_opts, optval, optlen)) - return -EFAULT; + memcpy(&ro->raw_vcid_opts, val, sizeof(ro->raw_vcid_opts)); /* prepare 32 bit values for handling in hot path */ ro->tx_vcid_shifted = ro->raw_vcid_opts.tx_vcid << CANXL_VCID_OFFSET; @@ -732,13 +717,7 @@ static int raw_setsockopt_locked(struct socket *sock, int optname, break; case CAN_RAW_JOIN_FILTERS: - if (optlen != sizeof(flag)) - return -EINVAL; - - if (copy_from_sockptr(&flag, optval, optlen)) - return -EFAULT; - - ro->join_filters = !!flag; + ro->join_filters = !!*(const int *)val; break; default: @@ -751,18 +730,83 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen) { struct sock *sk = sock->sk; + struct can_filter *filter = NULL; /* dyn. alloc'ed filters */ + struct can_filter sfilter; /* single filter */ + union { + can_err_mask_t err_mask; + int flag; + struct can_raw_vcid_options vcid_opts; + } val; + unsigned int size = 0; + int count = 0; int err; if (level != SOL_CAN_RAW) return -EINVAL; - rtnl_lock(); + /* Copy the option values from user space before lock_sock(), so a + * stalled copy can not block raw_notify() waiting for lock_sock() + * under RTNL. + */ + switch (optname) { + case CAN_RAW_FILTER: + if (optlen % sizeof(struct can_filter) != 0) + return -EINVAL; + + if (optlen > CAN_RAW_FILTER_MAX * sizeof(struct can_filter)) + return -EINVAL; + + count = optlen / sizeof(struct can_filter); + + if (count > 1) { + /* filter does not fit into dfilter => alloc space */ + filter = memdup_sockptr(optval, optlen); + if (IS_ERR(filter)) + return PTR_ERR(filter); + } else if (count == 1) { + if (copy_from_sockptr(&sfilter, optval, sizeof(sfilter))) + return -EFAULT; + filter = &sfilter; + } + break; + + case CAN_RAW_ERR_FILTER: + size = sizeof(val.err_mask); + break; + + case CAN_RAW_XL_VCID_OPTS: + size = sizeof(val.vcid_opts); + break; + + case CAN_RAW_LOOPBACK: + case CAN_RAW_RECV_OWN_MSGS: + case CAN_RAW_FD_FRAMES: + case CAN_RAW_XL_FRAMES: + case CAN_RAW_JOIN_FILTERS: + size = sizeof(val.flag); + break; + + default: + return -ENOPROTOOPT; + } + + if (size) { + if (optlen != size) + return -EINVAL; + + if (copy_from_sockptr(&val, optval, size)) + return -EFAULT; + } + lock_sock(sk); - err = raw_setsockopt_locked(sock, optname, optval, optlen); + err = raw_setsockopt_locked(sock, optname, &val, filter, count); release_sock(sk); - rtnl_unlock(); + + /* on error free the filters allocated for CAN_RAW_FILTER above */ + if (err && count > 1) + kfree(filter); return err; } @@ -784,6 +828,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, switch (optname) { case CAN_RAW_FILTER: { + struct can_filter *filter = NULL; int err = 0; lock_sock(sk); @@ -798,15 +843,22 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, } else { if (len > fsize) len = fsize; - if (copy_to_iter(ro->filter, len, - &opt->iter_out) != len) - err = -EFAULT; + /* copy to user space after release_sock() */ + filter = kmemdup(ro->filter, len, GFP_KERNEL); + if (!filter) + err = -ENOMEM; } } else { len = 0; } release_sock(sk); + if (filter) { + if (copy_to_iter(filter, len, &opt->iter_out) != len) + err = -EFAULT; + kfree(filter); + } + if (!err) opt->optlen = len; return err; diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index e69a2249ddfbf6..619e61aeb2b409 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -287,7 +287,7 @@ static u32 *decode_array_32_alloc(void **p, void *end, u32 *plen) if (len) { u32 i; - a = kmalloc_array(len, sizeof(u32), GFP_NOIO); + a = kmalloc_objs(u32, len, GFP_NOIO); if (!a) { ret = -ENOMEM; goto fail; diff --git a/net/core/dev.c b/net/core/dev.c index 3ac700d37e596f..3c58db732761a6 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4207,6 +4207,18 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device if (unlikely(!skb)) goto out_null; + /* Only fraglist GSO, whose segments already carry valid checksums, + * can be handed to a device as CHECKSUM_UNNECESSARY. Any other GSO + * skb has no csum_start for the device to segment from. NONE means + * the same on transmit, but makes netif_needs_gso() send it to the + * GSO code, which turns TCP into CHECKSUM_PARTIAL for TSO and + * segments anything the device cannot offload in software. + */ + if (unlikely(skb->ip_summed == CHECKSUM_UNNECESSARY && + skb_is_gso(skb) && + !(skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST))) + skb->ip_summed = CHECKSUM_NONE; + features = netif_skb_features(skb); skb = validate_xmit_vlan(skb, features); if (unlikely(!skb)) @@ -4320,7 +4332,9 @@ static enum skb_drop_reason qdisc_pkt_len_segs_init(struct sk_buff *skb) if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) { const struct tcphdr *th; - if (!pskb_may_pull(skb, hdr_len + sizeof(struct tcphdr))) + /* A header in front of skb->data gives a negative offset. */ + if ((int)hdr_len < 0 || + !pskb_may_pull(skb, hdr_len + sizeof(struct tcphdr))) return SKB_DROP_REASON_SKB_BAD_GSO; th = (const struct tcphdr *)(skb->data + hdr_len); @@ -7073,16 +7087,22 @@ static void __skb_defer_free_flush(struct skb_defer_node *sdn, int budget) { struct llist_node *free_list; struct sk_buff *skb, *next; + long n = 0; if (llist_empty(&sdn->defer_list)) return; - atomic_long_set(&sdn->defer_count, 0); free_list = llist_del_all(&sdn->defer_list); llist_for_each_entry_safe(skb, next, free_list, ll_node) { prefetch(next); napi_consume_skb(skb, budget); + n++; } + /* Subtract exactly what was drained. Never store an absolute value: + * mixing one with the relative updates in skb_attempt_defer_free() + * lets the counter go negative, and it is read as unsigned there. + */ + atomic_long_sub(n, &sdn->defer_count); } void skb_defer_node_flush(struct skb_defer_node *sdn) @@ -7389,6 +7409,13 @@ static void napi_stop_kthread(struct napi_struct *napi) { unsigned long val, new; + /* Instance is disabled, we can immediately stop the kthread */ + if (test_bit(NAPI_STATE_DISABLED, &napi->state)) { + clear_bit(NAPI_STATE_THREADED, &napi->state); + clear_bit(NAPI_STATE_THREADED_BUSY_POLL, &napi->state); + goto stop; + } + /* Wait until the napi STATE_THREADED is unset. */ while (true) { val = READ_ONCE(napi->state); @@ -7419,6 +7446,7 @@ static void napi_stop_kthread(struct napi_struct *napi) msleep(20); } +stop: kthread_stop(napi->thread); napi->thread = NULL; } @@ -7814,6 +7842,7 @@ void netif_napi_add_weight_locked(struct net_device *dev, napi->list_owner = -1; set_bit(NAPI_STATE_SCHED, &napi->state); set_bit(NAPI_STATE_NPSVC, &napi->state); + set_bit(NAPI_STATE_DISABLED, &napi->state); netif_napi_dev_list_add(dev, napi); /* default settings from sysfs are applied to all NAPIs. any per-NAPI @@ -7850,7 +7879,8 @@ void napi_disable_locked(struct napi_struct *n) val = READ_ONCE(n->state); } - new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC; + new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC | + NAPIF_STATE_DISABLED; new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_THREADED_BUSY_POLL | NAPIF_STATE_PREFER_BUSY_POLL); @@ -7895,7 +7925,8 @@ void napi_enable_locked(struct napi_struct *n) do { BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)); - new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC); + new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC | + NAPIF_STATE_DISABLED); if (n->dev->threaded && n->thread) new |= NAPIF_STATE_THREADED; } while (!try_cmpxchg(&n->state, &val, new)); @@ -11082,6 +11113,14 @@ atomic_t dev_unreg_count = ATOMIC_INIT(0); static void net_set_todo(struct net_device *dev) { list_add_tail(&dev->todo_list, &net_todo_list); + atomic_inc(&dev_net(dev)->dev_unreg_pending); +} + +/* Paired with net_set_todo(). @net must not be used after this call. */ +static void net_unreg_done(struct net *net) +{ + if (atomic_dec_and_test(&net->dev_unreg_pending)) + wake_up(&netdev_unregistering_wq); } static netdev_features_t netdev_sync_upper_features(struct net_device *lower, @@ -11981,6 +12020,7 @@ void netdev_run_todo(void) if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { netdev_WARN(dev, "run_todo but not unregistering\n"); list_del(&dev->todo_list); + net_unreg_done(dev_net(dev)); continue; } @@ -11997,8 +12037,11 @@ void netdev_run_todo(void) cnt = 0; while (!list_empty(&list)) { + struct net *net; + dev = netdev_wait_allrefs_any(&list); list_del(&dev->todo_list); + net = dev_net(dev); /* paranoia */ BUG_ON(netdev_refcnt_read(dev) != 1); @@ -12019,6 +12062,8 @@ void netdev_run_todo(void) /* Free network device */ kobject_put(&dev->dev.kobj); + + net_unreg_done(net); } if (cnt && atomic_sub_and_test(cnt, &dev_unreg_count)) wake_up(&netdev_unregistering_wq); @@ -13467,6 +13512,17 @@ static void __net_exit default_device_exit_net(struct net *net) } } +static bool __net_exit netns_dev_unreg_pending(const struct list_head *net_list) +{ + struct net *net; + + list_for_each_entry(net, net_list, exit_list) { + if (atomic_read(&net->dev_unreg_pending)) + return true; + } + return false; +} + static void __net_exit default_device_exit_batch(struct list_head *net_list) { /* At exit all network devices most be removed from a network @@ -13508,6 +13564,16 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list) unregister_netdevice_many(&dev_kill_list); rtnl_unlock(); + /* Devices of these netns unregistered from another context + * (e.g. a veth whose peer was deleted) can still be waiting + * in netdev_run_todo() for their last references, while + * NETDEV_UNREGISTER is rebroadcast for them. Wait for them + * before pernet exit handlers tear down the state used by + * netdevice notifiers, and before the netns is freed. + * No new unregistration can start: all devices are unlisted. + */ + wait_event(netdev_unregistering_wq, !netns_dev_unreg_pending(net_list)); + rtnl_net_flush_workqueue(); } diff --git a/net/core/devmem.c b/net/core/devmem.c index 32fafbfa1359e3..b2bd4373a2ea10 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -289,9 +289,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, } } else { spin_lock_init(&binding->freelist_lock); - binding->freelist = kvmalloc_array(binding->area.num_niovs, - sizeof(binding->freelist[0]), - GFP_KERNEL); + binding->freelist = kvmalloc_objs(binding->freelist[0], + binding->area.num_niovs); if (!binding->freelist) { err = -ENOMEM; goto err_unmap; diff --git a/net/core/filter.c b/net/core/filter.c index 09c60a58c82abe..946b07a17fcecf 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -939,7 +939,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen) BUILD_BUG_ON(BPF_MEMWORDS > 16); - masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL); + masks = kmalloc_objs(*masks, flen); if (!masks) return -ENOMEM; @@ -2290,9 +2290,13 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb, static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, struct bpf_nh_params *nh) { - const struct ipv6hdr *ip6h = ipv6_hdr(skb); struct net *net = dev_net(dev); int err, ret = NET_XMIT_DROP; + const struct ipv6hdr *ip6h; + + if (unlikely(!pskb_may_pull(skb, sizeof(*ip6h)))) + goto out_drop; + ip6h = ipv6_hdr(skb); if (!nh) { struct dst_entry *dst; @@ -2399,9 +2403,13 @@ static int bpf_out_neigh_v4(struct net *net, struct sk_buff *skb, static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, struct bpf_nh_params *nh) { - const struct iphdr *ip4h = ip_hdr(skb); struct net *net = dev_net(dev); int err, ret = NET_XMIT_DROP; + const struct iphdr *ip4h; + + if (unlikely(!pskb_may_pull(skb, sizeof(*ip4h)))) + goto out_drop; + ip4h = ip_hdr(skb); if (!nh) { struct flowi4 fl4 = { @@ -2451,15 +2459,14 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, static int __bpf_redirect_neigh(struct sk_buff *skb, struct net_device *dev, struct bpf_nh_params *nh) { - struct ethhdr *ethh = eth_hdr(skb); - - if (unlikely(skb->mac_header >= skb->network_header)) + if (unlikely(skb_network_offset(skb) < ETH_HLEN || + !pskb_may_pull(skb, ETH_HLEN))) goto out; bpf_push_mac_rcsum(skb); - if (is_multicast_ether_addr(ethh->h_dest)) + if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) goto out; - skb_pull(skb, sizeof(*ethh)); + skb_pull(skb, ETH_HLEN); skb_unset_mac_header(skb); skb_reset_network_header(skb); @@ -3362,6 +3369,10 @@ static const struct bpf_func_proto bpf_skb_vlan_pop_proto = { static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len) { + /* The bytes in front of @off are moved with skb->data. */ + if (unlikely(off > skb->len || !pskb_may_pull(skb, off))) + return -ENOMEM; + /* Caller already did skb_cow() with meta_len+len as headroom, * so no need to do it here. */ @@ -3382,9 +3393,10 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) void *old_data; /* skb_ensure_writable() is not needed here, as we're - * already working on an uncloned skb. + * already working on an uncloned skb. The first test + * keeps off + len from wrapping. */ - if (unlikely(!pskb_may_pull(skb, off + len))) + if (unlikely(off > skb->len || !pskb_may_pull(skb, off + len))) return -ENOMEM; old_data = skb->data; @@ -3395,9 +3407,25 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) return 0; } +/* + * bpf_skb_net_hdr_push() inserts bytes at @off, bpf_skb_net_hdr_pop() removes + * bytes at @off. Both move the bytes in front of @off together with skb->data, + * and leave the rest of the packet where it is. Return true if the transport + * header is in the part that moves. A transport header that is equal to the + * network header stays equal to it. + */ +static bool bpf_skb_trans_hdr_moves(const struct sk_buff *skb, u32 off) +{ + if (skb->transport_header == skb->network_header) + return true; + + return skb_transport_header_was_set(skb) && + (u32)skb_transport_offset(skb) < off; +} + static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) { - bool trans_same = skb->transport_header == skb->network_header; + bool trans_moves = bpf_skb_trans_hdr_moves(skb, off); int ret; /* There's no need for __skb_push()/__skb_pull() pair to @@ -3408,8 +3436,8 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) if (likely(!ret)) { skb->mac_header -= len; skb->network_header -= len; - if (trans_same) - skb->transport_header = skb->network_header; + if (trans_moves) + skb->transport_header -= len; } return ret; @@ -3417,7 +3445,7 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) { - bool trans_same = skb->transport_header == skb->network_header; + bool trans_moves = bpf_skb_trans_hdr_moves(skb, off); int ret; /* Same here, __skb_push()/__skb_pull() pair not needed. */ @@ -3425,8 +3453,17 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) if (likely(!ret)) { skb->mac_header += len; skb->network_header += len; - if (trans_same) - skb->transport_header = skb->network_header; + if (trans_moves) { + skb->transport_header += len; + } else if (skb_transport_header_was_set(skb) && + skb_transport_offset(skb) < (int)off) { + /* It was in the removed bytes or before skb->data. */ + skb_set_transport_header(skb, off); + } + /* Do not leave the inner transport header in front of @off. */ + if (skb->encapsulation && + skb_inner_transport_offset(skb) < (int)off) + skb_set_inner_transport_header(skb, off); } return ret; @@ -3737,6 +3774,25 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff, return 0; } +/* + * Code that went by the inner transport header while skb->encapsulation was set + * goes by the transport header from now on. So take the inner one over, unless + * it is the smaller one, as it is if nobody has set it. Do not leave the result + * in front of @off, where the bytes were removed. + */ +static void bpf_skb_clear_encap(struct sk_buff *skb, u32 off) +{ + int thoff; + + if (!skb->encapsulation) + return; + + thoff = max(skb->inner_transport_header, skb->transport_header) - + skb_headroom(skb); + skb_set_transport_header(skb, max_t(int, thoff, off)); + skb->encapsulation = 0; +} + static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff, u64 flags) { @@ -3755,6 +3811,14 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff, return -ENOTSUPP; } + /* + * The MSS is raised by len_diff. It has 16 bits, and GSO_BY_FRAGS is + * not a size. + */ + if (skb_is_gso(skb) && !(flags & BPF_F_ADJ_ROOM_FIXED_GSO) && + skb_shinfo(skb)->gso_size + len_diff >= GSO_BY_FRAGS) + return -ENOTSUPP; + ret = skb_unclone(skb, GFP_ATOMIC); if (unlikely(ret < 0)) return ret; @@ -3810,8 +3874,7 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff, SKB_GSO_IPXIP4 | SKB_GSO_IPXIP6 | SKB_GSO_ESP))) - if (skb->encapsulation) - skb->encapsulation = 0; + bpf_skb_clear_encap(skb, off); } /* Header must be checked, and gso_segs recomputed. */ @@ -3819,10 +3882,9 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff, shinfo->gso_segs = 0; } else { /* For non-GSO packets, clear encapsulation if decap flags are set */ - if ((flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK | - BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK)) && - skb->encapsulation) - skb->encapsulation = 0; + if (flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK | + BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK)) + bpf_skb_clear_encap(skb, off); } return 0; @@ -5590,11 +5652,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, case TCP_BPF_IW: if (val <= 0 || tp->data_segs_out > tp->syn_data) return -EINVAL; - tcp_snd_cwnd_set(tp, val); + tcp_snd_cwnd_set(tp, min_t(u32, val, tp->snd_cwnd_clamp)); break; case TCP_BPF_SNDCWND_CLAMP: if (val <= 0) return -EINVAL; + val = min_t(u32, val, TCP_MAX_SND_CWND); tp->snd_cwnd_clamp = val; WRITE_ONCE(tp->snd_ssthresh, val); break; @@ -6125,7 +6188,7 @@ static int bpf_sock_ops_get_syn(struct bpf_sock_ops_kern *bpf_sock, * not be available. It has to resort to * saved_syn (if it is saved). */ - saved_syn = inet_reqsk(sk)->saved_syn; + saved_syn = rcu_dereference(inet_reqsk(sk)->saved_syn); else saved_syn = tcp_sk(sk)->saved_syn; @@ -6909,14 +6972,22 @@ static int bpf_push_seg6_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len int err; struct ipv6_sr_hdr *srh = (struct ipv6_sr_hdr *)hdr; + /* With ipv6.disable=1 the netns has no seg6 data and no IPv6 tables. */ + if (!ipv6_mod_enabled()) + return -EAFNOSUPPORT; + if (!seg6_validate_srh(srh, len, false)) return -EINVAL; + /* + * The encap mode names IPv6 as the inner protocol, and neither mode + * updates skb->protocol. + */ + if (skb->protocol != htons(ETH_P_IPV6)) + return -EBADMSG; + switch (type) { case BPF_LWT_ENCAP_SEG6_INLINE: - if (skb->protocol != htons(ETH_P_IPV6)) - return -EBADMSG; - err = seg6_do_srh_inline(skb, srh); break; case BPF_LWT_ENCAP_SEG6: @@ -7005,12 +7076,13 @@ BPF_CALL_4(bpf_lwt_seg6_store_bytes, struct sk_buff *, skb, u32, offset, this_cpu_ptr(&seg6_bpf_srh_states); struct ipv6_sr_hdr *srh = srh_state->srh; void *srh_tlvs, *srh_end, *ptr; - int srhoff = 0; + int srhoff; lockdep_assert_held(&srh_state->bh_lock); if (srh == NULL) return -EINVAL; + srhoff = (unsigned char *)srh - skb->data; srh_tlvs = (void *)((char *)srh + ((srh->first_segment + 1) << 4)); srh_end = (void *)((char *)srh + sizeof(*srh) + srh_state->hdrlen); @@ -7023,8 +7095,7 @@ BPF_CALL_4(bpf_lwt_seg6_store_bytes, struct sk_buff *, skb, u32, offset, if (unlikely(bpf_try_make_writable(skb, offset + len))) return -EFAULT; - if (ipv6_find_hdr(skb, &srhoff, IPPROTO_ROUTING, NULL, NULL) < 0) - return -EINVAL; + /* The head may have moved. */ srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); memcpy(skb->data + offset, from, len); @@ -7140,16 +7211,18 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, { struct seg6_bpf_srh_state *srh_state = this_cpu_ptr(&seg6_bpf_srh_states); + bool mac_set = skb_mac_header_was_set(skb); struct ipv6_sr_hdr *srh = srh_state->srh; void *srh_end, *srh_tlvs, *ptr; struct ipv6hdr *hdr; - int srhoff = 0; + int srhoff; int ret; lockdep_assert_held(&srh_state->bh_lock); if (unlikely(srh == NULL)) return -EINVAL; + srhoff = (unsigned char *)srh - skb->data; srh_tlvs = (void *)((unsigned char *)srh + sizeof(*srh) + ((srh->first_segment + 1) << 4)); srh_end = (void *)((unsigned char *)srh + sizeof(*srh) + @@ -7160,26 +7233,46 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, return -EFAULT; if (unlikely(len < 0 && (void *)((char *)ptr - len) > srh_end)) return -EFAULT; + /* The length field of the SRH has 8 bits, in units of 8 bytes. */ + if (unlikely(len > (U8_MAX << 3) - srh_state->hdrlen)) + return -EFAULT; + /* + * skb->data is the network header here. The MAC header is in front of + * it, so bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() do not move + * it with the other headers. + */ if (len > 0) { - ret = skb_cow_head(skb, len); + ret = skb_cow_head(skb, len + skb->mac_len); if (unlikely(ret < 0)) return ret; + /* The push can write over the MAC header, so move it first. */ + if (mac_set) + memmove(skb->data - len - skb->mac_len, + skb_mac_header(skb), skb->mac_len); ret = bpf_skb_net_hdr_push(skb, offset, len); } else { ret = bpf_skb_net_hdr_pop(skb, offset, -1 * len); + /* The pop has added -len to skb->mac_header. */ + if (likely(!ret) && mac_set) + memmove(skb->data - skb->mac_len, + skb_mac_header(skb) + len, skb->mac_len); } bpf_compute_data_pointers(skb); if (unlikely(ret < 0)) return ret; + if (mac_set) + skb_set_mac_header(skb, -skb->mac_len); + else + skb_unset_mac_header(skb); + hdr = (struct ipv6hdr *)skb->data; hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); - if (ipv6_find_hdr(skb, &srhoff, IPPROTO_ROUTING, NULL, NULL) < 0) - return -EINVAL; + /* The bytes in front of offset have moved together with skb->data. */ srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); srh_state->hdrlen += len; srh_state->valid = false; @@ -8022,7 +8115,7 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags) if (sk_unhashed(sk)) return -EOPNOTSUPP; if (sk_is_refcounted(sk) && - unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) return -ENOENT; skb_orphan(skb); diff --git a/net/core/gro.c b/net/core/gro.c index 1b033855a20db6..1241b23d66efaf 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -238,6 +238,14 @@ int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb) NAPI_GRO_CB(skb)->flush)) return -E2BIG; + /* Fraglist members keep their own headers. Their checksum can not + * be right both for a forwarded packet and for a decapsulated one, + * if remote checksum offload adjusted it. + */ + if (unlikely(skb->remcsum_offload)) + return -EINVAL; + + skb_gro_frag0_invalidate(skb); if (!pskb_may_pull(skb, skb_gro_offset(skb))) { NAPI_GRO_CB(skb)->flush = 1; return -ENOMEM; @@ -374,6 +382,7 @@ static void gro_list_prepare(const struct list_head *head, } diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev; + diffs |= p->protocol != skb->protocol; diffs |= p->vlan_all ^ skb->vlan_all; diffs |= skb_metadata_differs(p, skb); if (maclen == ETH_HLEN) @@ -413,7 +422,8 @@ static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) headlen = skb_headlen(skb); NAPI_GRO_CB(skb)->frag0 = skb->data; NAPI_GRO_CB(skb)->frag0_len = headlen; - if (headlen) + /* Shared fragments must be pulled into the linear head before parsing. */ + if (headlen || skb_has_shared_frag(skb)) return; pinfo = skb_shinfo(skb); @@ -450,12 +460,19 @@ static void gro_pull_from_frag0(struct sk_buff *skb, int grow) } } -static void gro_try_pull_from_frag0(struct sk_buff *skb) +static bool gro_try_pull_from_frag0(struct sk_buff *skb) { int grow = skb_gro_offset(skb) - skb_headlen(skb); - if (grow > 0) + if (grow <= 0) + return true; + + /* frag0 can only be used if no pull happened. */ + if (likely(NAPI_GRO_CB(skb)->frag0_len)) { gro_pull_from_frag0(skb, grow); + return true; + } + return pskb_may_pull(skb, skb_gro_offset(skb)); } static void gro_flush_oldest(struct gro_node *gro, struct list_head *head) @@ -557,13 +574,17 @@ static enum gro_result dev_gro_receive(struct gro_node *gro, if (NAPI_GRO_CB(skb)->flush) goto normal; + /* Must be called before setting NAPI_GRO_CB(skb)->{age|last}. + * A held packet must have its headers in the linear part. + */ + if (unlikely(!gro_try_pull_from_frag0(skb))) + goto normal; + if (unlikely(gro_list->count >= MAX_GRO_SKBS)) gro_flush_oldest(gro, &gro_list->list); else gro_list->count++; - /* Must be called before setting NAPI_GRO_CB(skb)->{age|last} */ - gro_try_pull_from_frag0(skb); NAPI_GRO_CB(skb)->age = jiffies; NAPI_GRO_CB(skb)->last = skb; if (!skb_is_gso(skb)) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index da49364ec63de7..72c86ff2a84724 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -85,6 +85,32 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_lwt_prog *lwt, return ret; } +/* + * skb->cb still describes the IP header that was the first one before the + * prog ran. The option offsets in IPCB(skb)->opt are wrong for a pushed + * header, and a header of the other family needs the other layout. iif + * stays: behind a VRF skb->skb_iif is the L3 master and not the port. + * bpf_lwt_push_encap() cannot do this, because bpf_prog_run_save_cb() can + * restore skb->cb after the prog. + */ +static void bpf_lwt_reset_cb(struct sk_buff *skb, __be16 proto) +{ + int iif; + + if (skb->protocol == proto) { + if (proto == htons(ETH_P_IP)) + memset(&IPCB(skb)->opt, 0, sizeof(IPCB(skb)->opt)); + } else if (skb->protocol == htons(ETH_P_IP)) { + iif = IP6CB(skb)->iif; + memset(IPCB(skb), 0, sizeof(*IPCB(skb))); + IPCB(skb)->iif = iif; + } else { + iif = IPCB(skb)->iif; + memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); + IP6CB(skb)->iif = iif; + } +} + static int bpf_lwt_input_reroute(struct sk_buff *skb) { enum skb_drop_reason reason; @@ -102,7 +128,7 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb) dev_put(dev); } else if (skb->protocol == htons(ETH_P_IPV6)) { skb_dst_drop(skb); - if (IS_ENABLED(CONFIG_IPV6)) { + if (ipv6_mod_enabled()) { ip6_route_input(skb); err = skb_dst(skb)->error; } else { @@ -124,6 +150,8 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb) static int bpf_input(struct sk_buff *skb) { struct dst_entry *dst = skb_dst(skb); + __be16 proto = skb->protocol; + unsigned int len = skb->len; struct bpf_lwt *bpf; int ret; @@ -132,8 +160,21 @@ static int bpf_input(struct sk_buff *skb) ret = run_lwt_bpf(skb, &bpf->in, dst, NO_REDIRECT); if (ret < 0) return ret; + /* An lwt_in prog can change the length only with a push. */ + if (skb->len != len) + bpf_lwt_reset_cb(skb, proto); if (ret == BPF_LWT_REROUTE) return bpf_lwt_input_reroute(skb); + /* + * orig_input() is for the old protocol only, see bpf_xmit(). + * It also needs a dst of the old family. BPF_LWT_ENCAP_SEG6 + * puts an IPv6 dst into the skb. + */ + if (skb->protocol != proto || + skb_dst(skb)->ops->family != dst->ops->family) { + kfree_skb(skb); + return -EINVAL; + } } if (unlikely(!dst->lwtstate->orig_input)) { @@ -304,13 +345,17 @@ static int bpf_xmit(struct sk_buff *skb) * made before LWT xmit. */ ret = xmit_check_headroom(skb, hroom); - if (unlikely(ret)) + if (unlikely(ret)) { + kfree_skb(skb); return ret; + } return LWTUNNEL_XMIT_CONTINUE; case BPF_REDIRECT: return LWTUNNEL_XMIT_DONE; case BPF_LWT_REROUTE: + /* An lwt_xmit prog can also write to the options. */ + bpf_lwt_reset_cb(skb, proto); return bpf_lwt_xmit_reroute(skb); default: return ret; @@ -649,6 +694,14 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress) if (ingress) skb_postpush_rcsum(skb, iph, len); skb_reset_network_header(skb); + /* + * The new header goes over the MAC header. On ingress move it first. + * On egress the packet gets a new one, so forget the old one. + */ + if (ingress) + skb_mac_header_rebuild(skb); + else + skb_unset_mac_header(skb); if (is_udp_tunnel) { size_t iph_sz = ipv4 ? iph->ihl * 4 : sizeof(struct ipv6hdr); diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 52c2bd44778a8e..217021eeab1310 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -270,14 +270,19 @@ static void ops_undo_single(struct pernet_operations *ops, /* should be called with nsid_lock held */ static int alloc_netid(struct net *net, struct net *peer, int reqid) { - int min = 0, max = 0; + int ret; + u32 id; if (reqid >= 0) { - min = reqid; - max = reqid + 1; + id = reqid; + ret = idr_alloc_u32(&net->netns_ids, peer, &id, id, + GFP_ATOMIC); + if (ret) + return ret; + return id; } - return idr_alloc(&net->netns_ids, peer, min, max, GFP_ATOMIC); + return idr_alloc(&net->netns_ids, peer, 0, 0, GFP_ATOMIC); } /* This function is used by idr_for_each(). If net is equal to peer, the @@ -437,7 +442,7 @@ static __net_init int setup_net(struct net *net) LIST_HEAD(net_exit_list); int error = 0; - net->net_cookie = ns_tree_gen_id(net); + net->net_cookie = to_ns_common(net)->ns_id; list_for_each_entry(ops, &pernet_list, list) { error = ops_init(ops, net); @@ -449,7 +454,7 @@ static __net_init int setup_net(struct net *net) up_write(&net_rwsem); /* Without CONFIG_NET_NS init_net isn't exposed as a namespace. */ if (IS_ENABLED(CONFIG_NET_NS)) - ns_tree_add_raw(net); + ns_tree_add(net); out: return error; @@ -639,10 +644,10 @@ static void unhash_nsid(struct net *last) * use for_each_net_rcu() or net_rwsem. */ for_each_net(tmp) { - int id = 0; + unsigned long id = 0; spin_lock(&tmp->nsid_lock); - while ((peer = idr_get_next(&tmp->netns_ids, &id))) { + while ((peer = idr_get_next_ul(&tmp->netns_ids, &id))) { int curr_id = id; id++; diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 48f67641172433..1ac1e327ac4c62 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -967,6 +967,7 @@ int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, skb_reserve(nskb, headroom); skb_copy_header(nskb, skb); + nskb->mac_len = skb->mac_len; skb_mark_for_recycle(nskb); err = skb_copy_bits(skb, 0, nskb->data, size); @@ -1495,6 +1496,10 @@ void napi_skb_free_stolen_head(struct sk_buff *skb) skb_orphan(skb); skb->slow_gro = 0; } + if (skb->fclone != SKB_FCLONE_UNAVAILABLE) { + kfree_skbmem(skb); + return; + } napi_skb_cache_put(skb); } @@ -1908,6 +1913,7 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, struct ubuf_info *uarg, struct net_devmem_dmabuf_binding *binding) { + unsigned int orig_truesize = skb->truesize; int err, orig_len = skb->len; if (uarg->ops->link_skb) { @@ -1928,12 +1934,18 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, err = __zerocopy_sg_from_iter(msg, sk, skb, &msg->msg_iter, len, binding); if (err == -EFAULT || (err == -EMSGSIZE && skb->len == orig_len)) { + u32 delta_truesize = skb->truesize - orig_truesize; struct sock *save_sk = skb->sk; /* Streams do not free skb on error. Reset to prev state. */ iov_iter_revert(&msg->msg_iter, skb->len - orig_len); skb->sk = sk; - ___pskb_trim(skb, orig_len); + if (!___pskb_trim(skb, orig_len)) { + skb->truesize -= delta_truesize; + sk_wmem_queued_add(sk, -delta_truesize); + if (!skb_zcopy_pure(skb)) + sk_mem_uncharge(sk, delta_truesize); + } skb->sk = save_sk; return err; } @@ -3281,7 +3293,7 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, .pages = pages, .partial = partial, .nr_pages_max = MAX_SKB_FRAGS, - .ops = &nosteal_pipe_buf_ops, + .ops = &default_pipe_buf_ops, .spd_release = sock_spd_release, }; int ret = 0; @@ -6263,7 +6275,7 @@ void kfree_skb_partial(struct sk_buff *skb, bool head_stolen) { if (head_stolen) { skb_release_head_state(skb); - kmem_cache_free(net_hotdata.skbuff_cache, skb); + kfree_skbmem(skb); } else { __kfree_skb(skb); } @@ -6379,6 +6391,31 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, } EXPORT_SYMBOL(skb_try_coalesce); +static void skb_ext_scrub(struct sk_buff *skb) +{ +#if IS_ENABLED(CONFIG_INET_PSP) + struct psp_skb_ext *pse = skb_ext_find(skb, SKB_EXT_PSP); + + if (pse) { + struct skb_ext *ext = skb->extensions; + struct psp_skb_ext tmp; + + /* Nothing else to scrub if PSP is the only extension in ext. */ + if (ext->chunks == SKB_EXT_CHUNKSIZEOF(*ext) + + skb_ext_type_len[SKB_EXT_PSP]) + return; + + tmp = *pse; + skb_ext_reset(skb); + pse = skb_ext_add(skb, SKB_EXT_PSP); + if (pse) + memcpy(pse, &tmp, sizeof(*pse)); + return; + } +#endif + skb_ext_reset(skb); +} + /** * skb_scrub_packet - scrub an skb * @@ -6390,7 +6427,8 @@ EXPORT_SYMBOL(skb_try_coalesce); * operations. * skb_scrub_packet can also be used to clean a skb before injecting it in * another namespace (@xnet == true). We have to clear all information in the - * skb that could impact namespace isolation. + * skb that could impact namespace isolation. Note that PSP skb extension is + * preserved across packet scrubbing by design. */ void skb_scrub_packet(struct sk_buff *skb, bool xnet) { @@ -6398,7 +6436,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet) skb->skb_iif = 0; skb->ignore_df = 0; skb_dst_drop(skb); - skb_ext_reset(skb); + skb_ext_scrub(skb); nf_reset_ct(skb); nf_reset_trace(skb); @@ -6858,7 +6896,7 @@ int skb_mpls_dec_ttl(struct sk_buff *skb) lse = be32_to_cpu(mpls_hdr(skb)->label_stack_entry); ttl = (lse & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT; - if (!--ttl) + if (!ttl || !--ttl) return -EINVAL; lse &= ~MPLS_LS_TTL_MASK; @@ -7499,8 +7537,14 @@ nodefer: kfree_skb_napi_cache(skb); defer_max = READ_ONCE(net_hotdata.sysctl_skb_defer_max); defer_count = atomic_long_inc_return(&sdn->defer_count); - if (defer_count >= defer_max) + if (defer_count > defer_max) { + /* Undo the reservation. An llist_add() does not release one -- + * the skb stays charged until a flush subtracts the batch that + * contains it -- so a rejected free must undo its own. + */ + atomic_long_dec(&sdn->defer_count); goto nodefer; + } llist_add(&skb->ll_node, &sdn->defer_list); @@ -7509,8 +7553,13 @@ nodefer: kfree_skb_napi_cache(skb); return; } - /* Send an IPI every time queue reaches half capacity. */ - kick = (defer_count - 1) == (defer_max >> 1); + /* Half capacity, plus the skb that fills the queue. Equality alone can + * be consumed early -- if the producer holding the kick value publishes + * first, its purge drains only that skb and the reservations published + * after it match nothing -- which would leave a full queue with nothing + * pending. + */ + kick = (defer_count - 1) == (defer_max >> 1) || defer_count == defer_max; /* Make sure to trigger NET_RX_SOFTIRQ on the remote CPU * if we are unlucky enough (this seems very unlikely). diff --git a/net/core/sock.c b/net/core/sock.c index e7405be8941f98..ad414878dc5ba8 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3333,7 +3333,7 @@ void __release_sock(struct sock *sk) spin_unlock_bh(&sk->sk_lock.slock); - while (1) { + do { next = skb->next; prefetch(next); DEBUG_NET_WARN_ON_ONCE(skb_dst_is_noref(skb)); @@ -3341,12 +3341,10 @@ void __release_sock(struct sock *sk) sk_backlog_rcv(sk, skb); skb = next; - if (!skb) - break; if (!(++nb & 15)) cond_resched(); - } + } while (skb); spin_lock_bh(&sk->sk_lock.slock); } @@ -3429,7 +3427,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) goto suppress_allocation; } - if (!allocated) + if (sk->sk_bypass_prot_mem) return 1; /* Under limit. */ @@ -3510,7 +3508,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) trace_sock_exceed_buf_limit(sk, prot, allocated, kind); - if (allocated) + if (!sk->sk_bypass_prot_mem) sk_memory_allocated_sub(sk, amt); if (charged) diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 057e2f3c0265ed..efe49551caba9e 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -152,11 +152,11 @@ static void sock_map_del_link(struct sock *sk, struct bpf_map *map = link->map; struct sk_psock_progs *progs = sock_map_progs(map); - if (psock->saved_data_ready && progs->stream_parser) + if (progs->stream_parser) strp_stop = true; - if (psock->saved_data_ready && progs->stream_verdict) + if (progs->stream_verdict) verdict_stop = true; - if (psock->saved_data_ready && progs->skb_verdict) + if (progs->skb_verdict) verdict_stop = true; list_del(&link->list); sk_psock_free_link(link); @@ -164,8 +164,11 @@ static void sock_map_del_link(struct sock *sk, } } spin_unlock_bh(&psock->link_lock); - if (strp_stop || verdict_stop) { - write_lock_bh(&sk->sk_callback_lock); + if (!strp_stop && !verdict_stop) + return; + + write_lock_bh(&sk->sk_callback_lock); + if (psock->saved_data_ready) { if (strp_stop) sk_psock_stop_strp(sk, psock); if (verdict_stop) @@ -173,8 +176,8 @@ static void sock_map_del_link(struct sock *sk, if (psock->psock_update_sk_prot) psock->psock_update_sk_prot(sk, psock, false); - write_unlock_bh(&sk->sk_callback_lock); } + write_unlock_bh(&sk->sk_callback_lock); } static void sock_map_unref(struct sock *sk, void *link_raw) @@ -202,7 +205,7 @@ static struct sk_psock *sock_map_psock_get_checked(struct sock *sk) rcu_read_lock(); psock = sk_psock(sk); if (psock) { - if (sk->sk_prot->close != sock_map_close) { + if (READ_ONCE(sk->sk_prot)->close != sock_map_close) { psock = ERR_PTR(-EBUSY); goto out; } @@ -284,6 +287,7 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk) } } + write_lock_bh(&sk->sk_callback_lock); if (msg_parser) psock_set_prog(&psock->progs.msg_parser, msg_parser); if (stream_parser) @@ -298,11 +302,11 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk) */ ret = sock_map_init_proto(sk, psock); if (ret < 0) { + write_unlock_bh(&sk->sk_callback_lock); sk_psock_put(sk, psock); goto out; } - write_lock_bh(&sk->sk_callback_lock); if (stream_parser && stream_verdict && !psock->saved_data_ready) { if (sk_is_tcp(sk)) ret = sk_psock_init_strp(sk, psock); @@ -536,7 +540,7 @@ static bool sock_map_redirect_allowed(const struct sock *sk) static bool sock_map_sk_is_suitable(const struct sock *sk) { - return !!sk->sk_prot->psock_update_sk_prot; + return !!READ_ONCE(sk->sk_prot)->psock_update_sk_prot; } static bool sock_map_sk_state_allowed(const struct sock *sk) diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c index 29948cb44b7d1a..b9e5648fa4c515 100644 --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -6,6 +6,7 @@ * selecting the socket index from the array of available sockets. */ +#include #include #include #include @@ -124,10 +125,10 @@ static int reuseport_sock_index(struct sock *sk, static void __reuseport_add_sock(struct sock *sk, struct sock_reuseport *reuse) { - reuse->socks[reuse->num_socks] = sk; + WRITE_ONCE(reuse->socks[reuse->num_socks], sk); /* paired with smp_rmb() in reuseport_(select|migrate)_sock() */ smp_wmb(); - reuse->num_socks++; + WRITE_ONCE(reuse->num_socks, reuse->num_socks + 1); reuseport_get_incoming_cpu(sk, reuse); } @@ -139,8 +140,8 @@ static bool __reuseport_detach_sock(struct sock *sk, if (i == -1) return false; - reuse->socks[i] = reuse->socks[reuse->num_socks - 1]; - reuse->num_socks--; + WRITE_ONCE(reuse->socks[i], reuse->socks[reuse->num_socks - 1]); + WRITE_ONCE(reuse->num_socks, reuse->num_socks - 1); reuseport_put_incoming_cpu(sk, reuse); return true; @@ -149,7 +150,7 @@ static bool __reuseport_detach_sock(struct sock *sk, static void __reuseport_add_closed_sock(struct sock *sk, struct sock_reuseport *reuse) { - reuse->socks[reuse->max_socks - reuse->num_closed_socks - 1] = sk; + WRITE_ONCE(reuse->socks[reuse->max_socks - reuse->num_closed_socks - 1], sk); /* paired with READ_ONCE() in inet_csk_bind_conflict() */ WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks + 1); reuseport_get_incoming_cpu(sk, reuse); @@ -163,7 +164,8 @@ static bool __reuseport_detach_closed_sock(struct sock *sk, if (i == -1) return false; - reuse->socks[i] = reuse->socks[reuse->max_socks - reuse->num_closed_socks]; + WRITE_ONCE(reuse->socks[i], + reuse->socks[reuse->max_socks - reuse->num_closed_socks]); /* paired with READ_ONCE() in inet_csk_bind_conflict() */ WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks - 1); reuseport_put_incoming_cpu(sk, reuse); @@ -521,7 +523,7 @@ static struct sock *run_bpf_filter(struct sock_reuseport *reuse, u16 socks, if (index >= socks) return NULL; - return reuse->socks[index]; + return READ_ONCE(reuse->socks[index]); } static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse, @@ -532,7 +534,7 @@ static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse, i = j = reciprocal_scale(hash, num_socks); do { - struct sock *sk = reuse->socks[i]; + struct sock *sk = READ_ONCE(reuse->socks[i]); if (sk->sk_state != TCP_ESTABLISHED) { /* Paired with WRITE_ONCE() in __reuseport_(get|put)_incoming_cpu(). */ @@ -691,6 +693,14 @@ int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog) if (!sk->sk_reuseport) return -EINVAL; + /* Do not put a shutdown()ed TCP listener back into the + * listening section of a reuseport group while it is in + * TCP_CLOSE: requests can still migrate to it. + */ + if (sk_is_tcp(sk) && + inet_csk(sk)->unhashed_state == TCP_LISTEN) + return -EINVAL; + err = reuseport_alloc(sk, false); if (err) return err; diff --git a/net/dsa/conduit.c b/net/dsa/conduit.c index 8398d72d7e4d36..1470885d5a5ee9 100644 --- a/net/dsa/conduit.c +++ b/net/dsa/conduit.c @@ -289,7 +289,7 @@ static int dsa_conduit_ethtool_setup(struct net_device *dev) if (netif_is_lag_master(dev)) return 0; - ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); + ops = devm_kzalloc_obj(ds->dev, *ops); if (!ops) return -ENOMEM; diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c index a3a2cc6480a0e8..945312b260e3a9 100644 --- a/net/ethtool/bitset.c +++ b/net/ethtool/bitset.c @@ -477,7 +477,7 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits, /* The bitmap size is only the size of the map part without * its mask part. */ - saved_bitmap = kcalloc(nwords, sizeof(u32), GFP_KERNEL); + saved_bitmap = kzalloc_objs(u32, nwords); if (!saved_bitmap) return -ENOMEM; memcpy(saved_bitmap, bitmap, nbytes); @@ -750,7 +750,7 @@ int ethnl_bitset_size(const unsigned long *val, const unsigned long *mask, if (nbits > ETHNL_SMALL_BITMAP_BITS) { unsigned int nwords = DIV_ROUND_UP(nbits, 32); - val32 = kmalloc_array(2 * nwords, sizeof(u32), GFP_KERNEL); + val32 = kmalloc_objs(u32, 2 * nwords); if (!val32) return -ENOMEM; mask32 = val32 + nwords; @@ -786,7 +786,7 @@ int ethnl_put_bitset(struct sk_buff *skb, int attrtype, if (nbits > ETHNL_SMALL_BITMAP_BITS) { unsigned int nwords = DIV_ROUND_UP(nbits, 32); - val32 = kmalloc_array(2 * nwords, sizeof(u32), GFP_KERNEL); + val32 = kmalloc_objs(u32, 2 * nwords); if (!val32) return -ENOMEM; mask32 = val32 + nwords; @@ -821,7 +821,7 @@ int ethnl_update_bitset(unsigned long *bitmap, unsigned int nbits, if (nbits > ETHNL_SMALL_BITMAP_BITS) { unsigned int dst_words = DIV_ROUND_UP(nbits, 32); - bitmap32 = kmalloc_array(dst_words, sizeof(u32), GFP_KERNEL); + bitmap32 = kmalloc_objs(u32, dst_words); if (!bitmap32) return -ENOMEM; } diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 27b0e2e275dca5..80b7930b3fe0d3 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -815,7 +815,7 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GSSET_INFO; - info_buf = kcalloc(n_bits, sizeof(u32), GFP_USER); + info_buf = kzalloc_objs(u32, n_bits, GFP_USER); if (!info_buf) return -ENOMEM; @@ -1333,7 +1333,7 @@ static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, if (user_size < rxfh.indir_size) return user_size == 0 ? 0 : -EINVAL; - rxfh.indir = kcalloc(rxfh.indir_size, sizeof(rxfh.indir[0]), GFP_USER); + rxfh.indir = kzalloc_objs(rxfh.indir[0], rxfh.indir_size, GFP_USER); if (!rxfh.indir) return -ENOMEM; @@ -1378,8 +1378,8 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, if (user_size != 0 && user_size != rxfh_dev.indir_size) return -EINVAL; - rxfh_dev.indir = kcalloc(rxfh_dev.indir_size, - sizeof(rxfh_dev.indir[0]), GFP_USER); + rxfh_dev.indir = kzalloc_objs(rxfh_dev.indir[0], rxfh_dev.indir_size, + GFP_USER); if (!rxfh_dev.indir) return -ENOMEM; @@ -2377,7 +2377,7 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr) return -EFAULT; test.len = test_len; - data = kcalloc(test_len, sizeof(u64), GFP_USER); + data = kzalloc_objs(u64, test_len, GFP_USER); if (!data) return -ENOMEM; diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 7677b0343abd4c..8822bae439f88d 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -629,7 +629,7 @@ static long inet_wait_for_connect(struct sock *sk, long timeo, int writebias) * TCP 'magic' in here. */ int __inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, - int addr_len, int flags, int is_sendmsg) + int addr_len, int flags, bool defer_connect) { struct sock *sk = sock->sk; int err; @@ -664,8 +664,10 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, err = -EISCONN; goto out; case SS_CONNECTING: - if (inet_test_bit(DEFER_CONNECT, sk)) - err = is_sendmsg ? -EINPROGRESS : -EISCONN; + if (defer_connect) + err = -EINPROGRESS; + else if (inet_test_bit(DEFER_CONNECT, sk)) + err = -EISCONN; else err = -EALREADY; /* Fall out of switch with err, set for this state */ @@ -752,7 +754,7 @@ int inet_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr, int err; lock_sock(sock->sk); - err = __inet_stream_connect(sock, uaddr, addr_len, flags, 0); + err = __inet_stream_connect(sock, uaddr, addr_len, flags, false); release_sock(sock->sk); return err; } diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 1aacbbeffbc647..ee0c72fbc87739 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -2004,15 +2004,24 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) if (!opt || opt->opt.cipso == 0) return 0; if (opt->opt.srr || opt->opt.rr || opt->opt.ts || opt->opt.router_alert) { + struct ip_options_rcu *old_opt = opt; u8 cipso_len; u8 cipso_off; unsigned char *cipso_ptr; int optlen_new; + /* ip_options_rcu must not be modified in place, use a copy */ + opt = kmemdup(opt, sizeof(*opt) + opt->opt.optlen, GFP_ATOMIC); + if (!opt) + return -ENOMEM; cipso_off = opt->opt.cipso - sizeof(struct iphdr); cipso_ptr = &opt->opt.__data[cipso_off]; cipso_len = cipso_ptr[1]; + optlen_new = cipso_v4_get_actual_opt_len(opt->opt.__data, + opt->opt.optlen); + optlen_new -= cipso_len; + if (opt->opt.srr > opt->opt.cipso) opt->opt.srr -= cipso_len; if (opt->opt.rr > opt->opt.cipso) @@ -2026,11 +2035,14 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) memmove(cipso_ptr, cipso_ptr + cipso_len, opt->opt.optlen - cipso_off - cipso_len); - optlen_new = cipso_v4_get_actual_opt_len(opt->opt.__data, - opt->opt.optlen); hdr_delta = opt->opt.optlen; opt->opt.optlen = (optlen_new + 3) & ~3; hdr_delta -= opt->opt.optlen; + + memset(&opt->opt.__data[optlen_new], IPOPT_END, + opt->opt.optlen - optlen_new); + rcu_assign_pointer(*opt_ptr, opt); + kfree_rcu(old_opt, rcu); } else { /* only the cipso option was present on the socket so we can * remove the entire option struct */ @@ -2050,7 +2062,7 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) * Removes the CIPSO option from a socket, if present. * */ -void cipso_v4_sock_delattr(struct sock *sk) +int cipso_v4_sock_delattr(struct sock *sk) { struct inet_sock *sk_inet; int hdr_delta; @@ -2063,6 +2075,7 @@ void cipso_v4_sock_delattr(struct sock *sk) sk_conn->icsk_ext_hdr_len -= hdr_delta; sk_conn->icsk_sync_mss(sk, sk_conn->icsk_pmtu_cookie); } + return (hdr_delta < 0) ? hdr_delta : 0; } /** @@ -2073,9 +2086,11 @@ void cipso_v4_sock_delattr(struct sock *sk) * Removes the CIPSO option from a request socket, if present. * */ -void cipso_v4_req_delattr(struct request_sock *req) +int cipso_v4_req_delattr(struct request_sock *req) { - cipso_v4_delopt(&inet_rsk(req)->ireq_opt); + int hdr_delta = cipso_v4_delopt(&inet_rsk(req)->ireq_opt); + + return (hdr_delta < 0) ? hdr_delta : 0; } /** diff --git a/net/ipv4/esp4_offload.c b/net/ipv4/esp4_offload.c index abd77162f5e75e..2309468cfc3d40 100644 --- a/net/ipv4/esp4_offload.c +++ b/net/ipv4/esp4_offload.c @@ -37,6 +37,7 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head, __be32 seq; __be32 spi; + skb_gro_frag0_invalidate(skb); if (!pskb_pull(skb, offset)) return NULL; diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index be1e40780ad7d4..394df1de1281a8 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -961,6 +962,8 @@ static struct key_vector *fib_find_node(struct trie *t, break; } + index = array_index_nospec(index, 1ul << n->bits); + /* keep searching until we find a perfect match leaf or NULL */ } while (IS_TNODE(n)); @@ -1467,6 +1470,8 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, if (IS_LEAF(n)) goto found; + index = array_index_nospec(index, 1ul << n->bits); + /* only record pn and cindex if we are going to be chopping * bits later. Otherwise we are just wasting cycles. */ @@ -1770,6 +1775,8 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key) if (cindex >> pn->bits) break; + cindex = array_index_nospec(cindex, 1ul << pn->bits); + /* descend into the next child */ n = get_child_rcu(pn, cindex++); if (!n) @@ -1791,6 +1798,8 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key) continue; } + cindex = array_index_nospec(cindex, 1ul << pn->bits); + /* grab the next available node */ n = get_child_rcu(pn, cindex++); if (!n) @@ -2437,7 +2446,10 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter) while (!IS_TRIE(pn)) { while (cindex < child_length(pn)) { - struct key_vector *n = get_child_rcu(pn, cindex++); + struct key_vector *n; + + cindex = array_index_nospec(cindex, child_length(pn)); + n = get_child_rcu(pn, cindex++); if (!n) continue; diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 076fdca44f5180..5c3c8f55d05704 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -364,6 +364,18 @@ static struct sk_buff *gue_gro_receive(struct sock *sk, default: goto out; } + + /* Match the encapsulation format and IP version. */ + list_for_each_entry(p, head, list) { + const struct iphdr *iph2; + + if (!NAPI_GRO_CB(p)->same_flow) + continue; + + iph2 = (const struct iphdr *)(p->data + off); + if (iph2->version != ((struct iphdr *)guehdr)->version) + NAPI_GRO_CB(p)->same_flow = 0; + } goto next_proto; default: goto out; diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 144fca158adcb0..52cde8782eebdd 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2463,6 +2463,8 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) iml->multi.imr_address.s_addr) continue; + /* The drop request may not resolve to the joined device. */ + in_dev = inetdev_by_index(net, iml->multi.imr_ifindex); (void) ip_mc_leave_src(sk, iml, in_dev); *imlp = iml->next_rcu; diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 93b306d91b6dc5..6c079929e06f69 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -683,7 +683,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg) newsk = req->sk; if (sk->sk_protocol == IPPROTO_TCP && - tcp_rsk(req)->tfo_listener) { + tcp_sk(newsk)->syn_fastopen_child) { spin_lock_bh(&queue->fastopenq.lock); if (tcp_rsk(req)->tfo_listener) { /* We are still waiting for the final ACK from 3WHS @@ -869,7 +869,7 @@ reqsk_alloc_noprof(const struct request_sock_ops *ops, struct sock *sk_listener, req_to_sk(req)->sk_prot = sk_listener->sk_prot; sk_node_init(&req_to_sk(req)->sk_node); sk_tx_queue_clear(req_to_sk(req)); - req->saved_syn = NULL; + RCU_INIT_POINTER(req->saved_syn, NULL); req->syncookie = 0; req->num_timeout = 0; req->num_retrans = 0; @@ -908,7 +908,7 @@ void __reqsk_free(struct request_sock *req) req->rsk_ops->destructor(req); if (req->rsk_listener) sock_put(req->rsk_listener); - kfree(req->saved_syn); + kfree_rcu(unrcu_pointer(req->saved_syn), rcu); kmem_cache_free(req->rsk_ops->slab, req); } @@ -979,7 +979,7 @@ static void reqsk_queue_migrated(struct request_sock_queue *queue, static void reqsk_migrate_reset(struct request_sock *req) { - req->saved_syn = NULL; + RCU_INIT_POINTER(req->saved_syn, NULL); #if IS_ENABLED(CONFIG_IPV6) inet_rsk(req)->ipv6_opt = NULL; inet_rsk(req)->pktopts = NULL; @@ -1061,8 +1061,8 @@ static void reqsk_timer_handler(struct timer_list *t) * hold another count to prevent use-after-free and * call reqsk_put() just before return. */ - refcount_set(&nreq->rsk_refcnt, 2 + 1); timer_setup(&nreq->rsk_timer, reqsk_timer_handler, TIMER_PINNED); + refcount_set_release(&nreq->rsk_refcnt, 2 + 1); reqsk_queue_migrated(&inet_csk(nsk)->icsk_accept_queue, req); req = nreq; @@ -1141,10 +1141,14 @@ static void reqsk_timer_handler(struct timer_list *t) */ if (nreq) { __NET_INC_STATS(net, LINUX_MIB_TCPMIGRATEREQFAILURE); + /* The timer was not armed, drop its reference here. */ + reqsk_put(nreq); no_ownership: reqsk_migrate_reset(nreq); reqsk_queue_removed(queue, nreq); - __reqsk_free(nreq); + /* Drop the temporary reference and the one reserved for ehash. */ + reqsk_put(nreq); + reqsk_put(nreq); } drop: @@ -1443,7 +1447,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child, goto child_put; } - refcount_set(&nreq->rsk_refcnt, 1); + refcount_set_release(&nreq->rsk_refcnt, 1); if (inet_csk_reqsk_queue_add(sk, nreq, child)) { __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQSUCCESS); reqsk_migrate_reset(req); @@ -1453,7 +1457,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child, __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQFAILURE); reqsk_migrate_reset(nreq); - __reqsk_free(nreq); + reqsk_put(nreq); } else if (inet_csk_reqsk_queue_add(sk, req, child)) { return child; } @@ -1496,7 +1500,7 @@ void inet_csk_listen_stop(struct sock *sk) if (nsk) { nreq = inet_reqsk_clone(req, nsk); if (nreq) { - refcount_set(&nreq->rsk_refcnt, 1); + refcount_set_release(&nreq->rsk_refcnt, 1); rcu_read_lock(); if (inet_csk_reqsk_queue_add(nsk, nreq, child)) { @@ -1508,7 +1512,7 @@ void inet_csk_listen_stop(struct sock *sk) __NET_INC_STATS(sock_net(nsk), LINUX_MIB_TCPMIGRATEREQFAILURE); reqsk_migrate_reset(nreq); - __reqsk_free(nreq); + reqsk_put(nreq); } rcu_read_unlock(); diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index c18da91c1f031e..f330d0a3982339 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -336,6 +337,7 @@ void inet_frag_queue_flush(struct inet_frag_queue *q, q->rb_fragments = RB_ROOT; q->fragments_tail = NULL; q->last_run_head = NULL; + q->truesize = 0; } EXPORT_SYMBOL(inet_frag_queue_flush); @@ -446,6 +448,9 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, if (last && !secpath_equal(last, skb)) return IPFRAG_MIXED_SECPATH; + if (skb->truesize > INET_FRAG_MAX_TRUESIZE - q->truesize) + return IPFRAG_TOOBIG; + /* An IP fragment is never a GSO packet, but an untrusted source * (virtio_net_hdr) may have attached GSO metadata to it. Do not let * that reach the reassembled skb, whose head keeps the first @@ -510,10 +515,48 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, if (offset) nf_reset_ct(skb); + q->truesize += skb->truesize; return IPFRAG_OK; } EXPORT_SYMBOL(inet_frag_queue_insert); +/* When a socket owned fragment completes a queue, the truesize of all + * other fragments is charged to its sk_wmem_alloc, although they were + * orphaned when queued and possibly sent by someone else. + * Bound this like ip_append_data() bounds the memory a socket can + * allocate (2 * sk_sndbuf), plus slack for fragments inflated by a + * refragmentation using a small MTU. Otherwise, several reassembled skbs + * alive at the same time can saturate sk_wmem_alloc, and leak the socket. + * + * Several queues can complete at the same time for the same socket, + * and some sockets (tun) use sk_sndbuf = INT_MAX. The charge is reserved + * with a cmpxchg() loop, a refcount_t has no helper for this. + */ +#define INET_FRAG_WMEM_SLACK SZ_4M + +static bool inet_frag_wmem_reserve(struct sock *sk, unsigned int charge) +{ + u64 limit = 2ULL * READ_ONCE(sk->sk_sndbuf) + INET_FRAG_WMEM_SLACK; + int old = refcount_read(&sk->sk_wmem_alloc); + + limit = min_t(u64, limit, INET_FRAG_MAX_TRUESIZE); + do { + if (old <= 0 || (u64)old + charge > limit) + return false; + } while (!atomic_try_cmpxchg(&sk->sk_wmem_alloc.refs, &old, + old + charge)); + + return true; +} + +static void inet_frag_wmem_adjust(struct sock *sk, int delta) +{ + if (delta >= 0) + refcount_add(delta, &sk->sk_wmem_alloc); + else + WARN_ON_ONCE(refcount_sub_and_test(-delta, &sk->sk_wmem_alloc)); +} + void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, struct sk_buff *parent) { @@ -525,6 +568,11 @@ void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, int delta; if (sk && is_skb_wmem(skb)) { + /* skb->truesize is already charged to sk, and is part of + * q->truesize. inet_frag_reasm_finish() settles the charge. + */ + if (!inet_frag_wmem_reserve(sk, q->truesize - skb->truesize)) + return NULL; /* TX: skb->sk might have been passed as argument to * dst->output and must remain valid until tx completes. * @@ -600,17 +648,18 @@ void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, out_restore_sk: if (orig_truesize) { - int ts_delta = head->truesize - orig_truesize; - /* if this reassembled skb is fragmented later, * fraglist skbs will get skb->sk assigned from head->sk, * and each frag skb will be released via sock_wfree. - * - * Update sk_wmem_alloc. */ head->sk = sk; head->destructor = destructor; - refcount_add(ts_delta, &sk->sk_wmem_alloc); + /* On failure, head stays in the queue and will be freed + * with the queue: only charge its truesize. + */ + if (!nextp) + inet_frag_wmem_adjust(sk, (int)head->truesize - + (int)q->truesize); } return nextp; @@ -621,7 +670,6 @@ void inet_frag_reasm_finish(struct inet_frag_queue *q, struct sk_buff *head, void *reasm_data, bool try_coalesce) { struct sock *sk = is_skb_wmem(head) ? head->sk : NULL; - const unsigned int head_truesize = head->truesize; struct sk_buff **nextp = reasm_data; struct rb_node *rbn; struct sk_buff *fp; @@ -686,8 +734,12 @@ void inet_frag_reasm_finish(struct inet_frag_queue *q, struct sk_buff *head, head->tstamp = q->stamp; head->tstamp_type = q->tstamp_type; + /* After inet_frag_reasm_prepare(), q->truesize is charged to sk. + * sum_truesize also includes what it added (skb_unclone() and + * frag_list clone). + */ if (sk) - refcount_add(sum_truesize - head_truesize, &sk->sk_wmem_alloc); + inet_frag_wmem_adjust(sk, sum_truesize - (int)q->truesize); } EXPORT_SYMBOL(inet_frag_reasm_finish); diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 5abcb0debb2702..860145d810ed49 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -550,10 +550,11 @@ struct sock *__inet_lookup_established(const struct net *net, if (sk->sk_hash != hash) continue; if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) { - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) goto out; - if (unlikely(!inet_match(net, sk, acookie, - ports, dif, sdif))) { + if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) || + !inet_match(net, sk, acookie, ports, dif, + sdif))) { sock_gen_put(sk); goto begin; } diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index a1d86026aefb0f..e256c55ce9f29f 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -143,7 +143,7 @@ void inet_twsk_hashdance_schedule(struct inet_timewait_sock *tw, * Also note that after this point, we lost our implicit reference * so we are not allowed to use tw anymore. */ - refcount_set(&tw->tw_refcnt, 3); + refcount_set_release(&tw->tw_refcnt, 3); /* Ensure tw_refcnt has been set before tw is published. * smp_wmb() provides the necessary memory barrier to enforce this @@ -330,7 +330,7 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo) if (check_net(sock_net(sk))) continue; - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) continue; if (check_net(sock_net(sk))) { diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 36105dd192823e..ef7fd61284a3fa 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -413,16 +413,19 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb, goto out_fail; } + /* Check the size on the first fragment, which will become the head: + * inet_frag_reasm_finish() must follow inet_frag_reasm_prepare(). + */ + len = ip_hdrlen(skb_rb_first(&qp->q.rb_fragments)) + qp->q.len; + err = -E2BIG; + if (len > 65535) + goto out_oversize; + /* Make the one we just received the head. */ reasm_data = inet_frag_reasm_prepare(&qp->q, skb, prev_tail); if (!reasm_data) goto out_nomem; - len = ip_hdrlen(skb) + qp->q.len; - err = -E2BIG; - if (len > 65535) - goto out_oversize; - inet_frag_reasm_finish(&qp->q, skb, reasm_data, ip_frag_coalesce_ok(qp)); diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 3396f177a18d09..d42d776af273e4 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1150,16 +1150,16 @@ static int __ip_append_data(struct sock *sk, */ skb->ip_summed = csummode; skb->csum = 0; - skb_reserve(skb, hh_len); + skb_reserve(skb, hh_len + exthdrlen); /* * Find where to start putting bytes. */ - data = skb_put(skb, fraglen + exthdrlen - pagedlen); - skb_set_network_header(skb, exthdrlen); + data = skb_put(skb, fraglen - pagedlen); + skb_reset_network_header(skb); skb->transport_header = (skb->network_header + fragheaderlen); - data += fragheaderlen + exthdrlen; + data += fragheaderlen; if (fraggap) { skb->csum = skb_copy_and_csum_bits( diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index e8f7d3b573d0f4..836f3f95b20c45 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -109,7 +109,8 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, struct net_device *dev, struct sk_buff *skb, struct mfc_cache *cache, int local); static int ipmr_cache_report(const struct mr_table *mrt, - struct sk_buff *pkt, vifi_t vifi, int assert); + struct sk_buff *pkt, vifi_t vifi, int assert, + bool nl_query); static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, int cmd); static void igmpmsg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt); @@ -563,7 +564,7 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) /* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */ ipmr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num), - IGMPMSG_WHOLEPKT); + IGMPMSG_WHOLEPKT, false); rcu_read_unlock(); kfree_skb(skb); @@ -781,23 +782,21 @@ static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c) WRITE_ONCE(mrt->cache_resolve_queue_len, mrt->cache_resolve_queue_len - 1); - while ((skb = skb_dequeue(&c->_c.mfc_un.unres.unresolved))) { - if (ip_hdr(skb)->version == 0) { - struct nlmsghdr *nlh = skb_pull(skb, - sizeof(struct iphdr)); - nlh->nlmsg_type = NLMSG_ERROR; - nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); - skb_trim(skb, nlh->nlmsg_len); - e = nlmsg_data(nlh); - e->error = -ETIMEDOUT; - memset(&e->msg, 0, sizeof(e->msg)); + while ((skb = skb_dequeue(&c->_c.mfc_un.unres.nl_queries))) { + struct nlmsghdr *nlh = skb_pull(skb, sizeof(struct iphdr)); - rtnl_unicast(skb, net, NETLINK_CB(skb).portid); - } else { - kfree_skb(skb); - } + nlh->nlmsg_type = NLMSG_ERROR; + nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); + skb_trim(skb, nlh->nlmsg_len); + e = nlmsg_data(nlh); + e->error = -ETIMEDOUT; + memset(&e->msg, 0, sizeof(e->msg)); + + rtnl_unicast(skb, net, NETLINK_CB(skb).portid); } + skb_queue_purge(&c->_c.mfc_un.unres.unresolved); + ipmr_cache_free(c); } @@ -1027,6 +1026,7 @@ static struct mfc_cache *ipmr_cache_alloc_unres(void) if (c) { skb_queue_head_init(&c->_c.mfc_un.unres.unresolved); + skb_queue_head_init(&c->_c.mfc_un.unres.nl_queries); c->_c.mfc_un.unres.expires = jiffies + 10 * HZ; } return c; @@ -1039,31 +1039,29 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, struct sk_buff *skb; struct nlmsgerr *e; - /* Play the pending entries through our router */ - while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { - if (ip_hdr(skb)->version == 0) { - struct nlmsghdr *nlh = skb_pull(skb, - sizeof(struct iphdr)); - - if (mr_fill_mroute(mrt, skb, &c->_c, - nlmsg_data(nlh)) > 0) { - nlh->nlmsg_len = skb_tail_pointer(skb) - - (u8 *)nlh; - } else { - nlh->nlmsg_type = NLMSG_ERROR; - nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); - skb_trim(skb, nlh->nlmsg_len); - e = nlmsg_data(nlh); - e->error = -EMSGSIZE; - memset(&e->msg, 0, sizeof(e->msg)); - } + /* Answer the pending netlink route queries */ + while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.nl_queries))) { + struct nlmsghdr *nlh = skb_pull(skb, sizeof(struct iphdr)); - rtnl_unicast(skb, net, NETLINK_CB(skb).portid); + if (mr_fill_mroute(mrt, skb, &c->_c, nlmsg_data(nlh)) > 0) { + nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh; } else { - rcu_read_lock(); - ip_mr_forward(net, mrt, skb->dev, skb, c, 0); - rcu_read_unlock(); + nlh->nlmsg_type = NLMSG_ERROR; + nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); + skb_trim(skb, nlh->nlmsg_len); + e = nlmsg_data(nlh); + e->error = -EMSGSIZE; + memset(&e->msg, 0, sizeof(e->msg)); } + + rtnl_unicast(skb, net, NETLINK_CB(skb).portid); + } + + /* Play the pending packets through our router */ + while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { + rcu_read_lock(); + ip_mr_forward(net, mrt, skb->dev, skb, c, 0); + rcu_read_unlock(); } } @@ -1072,7 +1070,8 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, * Called under rcu_read_lock(). */ static int ipmr_cache_report(const struct mr_table *mrt, - struct sk_buff *pkt, vifi_t vifi, int assert) + struct sk_buff *pkt, vifi_t vifi, int assert, + bool nl_query) { unsigned char pkt_cb[sizeof(pkt->cb)]; const int ihl = ip_hdrlen(pkt); @@ -1142,7 +1141,7 @@ static int ipmr_cache_report(const struct mr_table *mrt, memset(skb->cb, 0, sizeof(skb->cb)); /* Route queries from ipmr_get_route() carry NETLINK_CB, not IPCB. */ - if (ip_hdr(pkt)->version) { + if (!nl_query) { memcpy(pkt_cb, pkt->cb, sizeof(pkt_cb)); ipv4_pktinfo_prepare(mroute_sk, pkt, false); *PKTINFO_SKB_CB(skb) = *PKTINFO_SKB_CB(pkt); @@ -1165,7 +1164,8 @@ static int ipmr_cache_report(const struct mr_table *mrt, /* Queue a packet for resolution. It gets locked cache entry! */ /* Called under rcu_read_lock() */ static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, - struct sk_buff *skb, struct net_device *dev) + struct sk_buff *skb, struct net_device *dev, + bool nl_query) { struct net *net = read_pnet(&mrt->net); const struct iphdr *iph = ip_hdr(skb); @@ -1202,7 +1202,8 @@ static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, c->mfc_mcastgrp = iph->daddr; /* Reflect first query at mrouted. */ - err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE); + err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE, + nl_query); if (err < 0) goto err; @@ -1217,7 +1218,8 @@ static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, } /* See if we can append the packet */ - if (c->_c.mfc_un.unres.unresolved.qlen > 3) { + if (skb_queue_len(&c->_c.mfc_un.unres.unresolved) + + skb_queue_len(&c->_c.mfc_un.unres.nl_queries) > 3) { c = NULL; err = -ENOBUFS; goto err; @@ -1228,7 +1230,8 @@ static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, skb->skb_iif = dev->ifindex; } - skb_queue_tail(&c->_c.mfc_un.unres.unresolved, skb); + skb_queue_tail(nl_query ? &c->_c.mfc_un.unres.nl_queries : + &c->_c.mfc_un.unres.unresolved, skb); spin_unlock_bh(&mfc_unres_lock); return 0; @@ -1943,7 +1946,7 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt, WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); DEV_STATS_ADD(vif_dev, tx_bytes, skb->len); DEV_STATS_INC(vif_dev, tx_packets); - ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); + ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT, false); return -1; } @@ -2120,10 +2123,11 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, c->_c.mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { c->_c.mfc_un.res.last_assert = jiffies; - ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); + ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF, + false); if (READ_ONCE(mrt->mroute_do_wrvifwhole)) ipmr_cache_report(mrt, skb, true_vifi, - IGMPMSG_WRVIFWHOLE); + IGMPMSG_WRVIFWHOLE, false); } goto dont_forward; } @@ -2293,7 +2297,7 @@ int ip_mr_input(struct sk_buff *skb) vif = ipmr_find_vif(mrt, dev); if (vif >= 0) - return ipmr_cache_unresolved(mrt, vif, skb, dev); + return ipmr_cache_unresolved(mrt, vif, skb, dev, false); kfree_skb(skb); return -ENODEV; } @@ -2401,7 +2405,7 @@ int ip_mr_output(struct net *net, struct sock *sk, struct sk_buff *skb) if (!cache) { vif = ipmr_find_vif(mrt, dev); if (vif >= 0) - return ipmr_cache_unresolved(mrt, vif, skb, dev); + return ipmr_cache_unresolved(mrt, vif, skb, dev, false); goto mc_output; } @@ -2523,7 +2527,7 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb, iph->saddr = saddr; iph->daddr = daddr; iph->version = 0; - err = ipmr_cache_unresolved(mrt, vif, skb2, dev); + err = ipmr_cache_unresolved(mrt, vif, skb2, dev, true); rcu_read_unlock(); return err; } diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index cf747e1e17a363..7ff3d1f0ffd411 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -371,11 +371,12 @@ static int mark_source_chains(const struct xt_table_info *newinfo, e->counters.pcnt = pos; pos += size; } else { - int newpos = t->verdict; + int newpos; if (strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0 && - newpos >= 0) { + t->verdict >= 0) { + newpos = t->verdict; /* This a jump; chase it. */ if (!xt_find_jump_offset(offsets, newpos, newinfo->number)) diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c index 809441cedcedc7..b302bd77180a75 100644 --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c @@ -422,11 +422,12 @@ mark_source_chains(const struct xt_table_info *newinfo, e->counters.pcnt = pos; pos += size; } else { - int newpos = t->verdict; + int newpos; if (strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0 && - newpos >= 0) { + t->verdict >= 0) { + newpos = t->verdict; /* This a jump; chase it. */ if (!xt_find_jump_offset(offsets, newpos, newinfo->number)) diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c index 7cb33af671e260..4082fa184af8ba 100644 --- a/net/ipv4/netfilter/nf_reject_ipv4.c +++ b/net/ipv4/netfilter/nf_reject_ipv4.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -336,7 +337,18 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb, dev_queue_xmit(nskb); } else #endif + { + local_bh_disable(); + if (nf_dev_xmit_recursion()) { + local_bh_enable(); + goto free_nskb; + } + + nf_dev_xmit_recursion_inc(); ip_local_out(net, nskb->sk, nskb); + nf_dev_xmit_recursion_dec(); + local_bh_enable(); + } return; diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 9d01006d8189e1..f33a9dfc530992 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -182,18 +182,19 @@ static int raw_v4_input(struct net *net, struct sk_buff *skb, iph->saddr, iph->daddr, dif, sdif)) continue; - if (atomic_read(&sk->sk_rmem_alloc) >= - READ_ONCE(sk->sk_rcvbuf)) { - sk_drops_inc(sk); - continue; - } - delivered = 1; if ((iph->protocol != IPPROTO_ICMP || !icmp_filter(sk, skb)) && ip_mc_sf_allow(sk, iph->daddr, iph->saddr, skb->dev->ifindex, sdif)) { - struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC); + struct sk_buff *clone; + + if (atomic_read(&sk->sk_rmem_alloc) >= + READ_ONCE(sk->sk_rcvbuf)) { + sk_drops_inc(sk); + continue; + } + clone = skb_clone(skb, GFP_ATOMIC); /* Not releasing hash table! */ if (clone) raw_rcv(sk, clone); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 93b9f418952574..cd69242afab07e 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -573,6 +573,17 @@ static void ip_rt_build_flow_key(struct flowi4 *fl4, const struct sock *sk, static DEFINE_SPINLOCK(fnhe_lock); +/* Other CPUs may still be using @rt, so don't dst_dev_put() it. + * rt_flush_dev() handles it if its device is unregistered. + * Marking it dead makes ipv4_dst_check() fail for users that cached it. + */ +static void fnhe_retire_route(struct rtable *rt) +{ + WRITE_ONCE(rt->dst.obsolete, DST_OBSOLETE_DEAD); + rt_add_uncached_list(rt); + dst_release(&rt->dst); +} + static void fnhe_flush_routes(struct fib_nh_exception *fnhe) { struct rtable *rt; @@ -580,14 +591,12 @@ static void fnhe_flush_routes(struct fib_nh_exception *fnhe) rt = rcu_dereference(fnhe->fnhe_rth_input); if (rt) { RCU_INIT_POINTER(fnhe->fnhe_rth_input, NULL); - dst_dev_put(&rt->dst); - dst_release(&rt->dst); + fnhe_retire_route(rt); } rt = rcu_dereference(fnhe->fnhe_rth_output); if (rt) { RCU_INIT_POINTER(fnhe->fnhe_rth_output, NULL); - dst_dev_put(&rt->dst); - dst_release(&rt->dst); + fnhe_retire_route(rt); } } @@ -1505,10 +1514,8 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, if (do_cache) { dst_hold(&rt->dst); rcu_assign_pointer(*porig, rt); - if (orig) { - dst_dev_put(&orig->dst); - dst_release(&orig->dst); - } + if (orig) + fnhe_retire_route(orig); ret = true; } @@ -2494,6 +2501,8 @@ ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, if (unlikely(!rt_cache_route(nhc, rth))) rt_add_uncached_list(rth); + } else { + rt_add_uncached_list(rth); } skb_dst_set(skb, &rth->dst); reason = SKB_NOT_DROPPED_YET; diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 8c9691569e01af..4e0ff3b820627e 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -205,7 +205,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, NULL, &own_req, NULL); if (child) { - refcount_set(&req->rsk_refcnt, 1); + refcount_set_release(&req->rsk_refcnt, 1); sock_rps_save_rxhash(child, skb); if (rsk_drop_req(req)) { @@ -218,6 +218,8 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, bh_unlock_sock(child); sock_put(child); + reqsk_put(req); + return NULL; } __reqsk_free(req); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b9de7c302ba83a..832b25ddd3c2ea 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -456,7 +456,7 @@ void tcp_init_sock(struct sock *sk) * initialization of these values. */ tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; - tp->snd_cwnd_clamp = ~0; + tp->snd_cwnd_clamp = TCP_MAX_SND_CWND; tp->mss_cache = TCP_MSS_DEFAULT; tp->reordering = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering); @@ -1057,6 +1057,7 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, struct tcp_sock *tp = tcp_sk(sk); struct inet_sock *inet = inet_sk(sk); struct sockaddr *uaddr = msg->msg_name; + bool defer_connect = false; int err, flags; if (!(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & @@ -1076,6 +1077,9 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, tp->fastopen_req->uarg = uarg; if (inet_test_bit(DEFER_CONNECT, sk)) { + inet_clear_bit(DEFER_CONNECT, sk); + defer_connect = true; + err = tcp_connect(sk); /* Same failure procedure as in tcp_v4/6_connect */ if (err) { @@ -1086,14 +1090,13 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, } flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0; err = __inet_stream_connect(sk->sk_socket, (struct sockaddr_unsized *)uaddr, - msg->msg_namelen, flags, 1); + msg->msg_namelen, flags, defer_connect); /* fastopen_req could already be freed in __inet_stream_connect * if the connection times out or gets rst */ if (tp->fastopen_req) { *copied = tp->fastopen_req->copied; tcp_free_fastopen_req(tp); - inet_clear_bit(DEFER_CONNECT, sk); } return err; } @@ -3490,6 +3493,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->rx_opt.dsack = 0; tp->rx_opt.num_sacks = 0; tp->rcv_ooopack = 0; + tp->rcv_collapse_credit = 0; /* Clean up fastopen related fields */ @@ -4968,7 +4972,8 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, const void *saddr, const void *daddr, int family, int l3index, const __u8 *hash_location) { - return SKB_NOT_DROPPED_YET; + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); + return SKB_DROP_REASON_TCP_MD5UNEXPECTED; } #endif @@ -5148,6 +5153,8 @@ int tcp_abort(struct sock *sk, int err) /* Don't race with userspace socket closes such as tcp_close. */ lock_sock(sk); + inet_clear_bit(DEFER_CONNECT, sk); + /* Avoid closing the same socket twice. */ if (sk->sk_state == TCP_CLOSE) { if (!has_current_bpf_ctx()) @@ -5308,6 +5315,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_last_tsecr); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, pkts_acked_ewma); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_collapse_credit); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space); } diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 6dfe40322fb590..7f7eb3cc1c04c8 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -366,7 +366,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk, tcp_reset_xmit_timer(child, ICSK_TIME_RETRANS, req->timeout, false); - refcount_set(&req->rsk_refcnt, 2); + refcount_set_release(&req->rsk_refcnt, 2); sk_mark_napi_id_set(child, skb); @@ -545,6 +545,8 @@ bool tcp_fastopen_defer_connect(struct sock *sk, int *err) if (tp->fastopen_connect && !tp->fastopen_req) { if (tcp_fastopen_cookie_check(sk, &mss, &cookie)) { + WRITE_ONCE(tp->snd_una, tp->write_seq); + WRITE_ONCE(tp->snd_nxt, tp->write_seq); inet_set_bit(DEFER_CONNECT, sk); return true; } diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e1f2d9765f8101..a2074a1af42228 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -107,7 +107,8 @@ int sysctl_tcp_max_orphans __read_mostly = NR_FILE; #define FLAG_TS_PROGRESS 0x40000 /* Positive timestamp delta */ #define FLAG_ACKED (FLAG_DATA_ACKED|FLAG_SYN_ACKED) -#define FLAG_NOT_DUP (FLAG_DATA|FLAG_WIN_UPDATE|FLAG_ACKED) +#define FLAG_NOT_DUP (FLAG_DATA|FLAG_WIN_UPDATE|FLAG_ACKED| \ + FLAG_SND_UNA_ADVANCED) #define FLAG_CA_ALERT (FLAG_DATA_SACKED|FLAG_ECE|FLAG_DSACKING_ACK) #define FLAG_FORWARD_PROGRESS (FLAG_ACKED|FLAG_DATA_SACKED) @@ -3986,11 +3987,11 @@ static int tcp_ack_update_window(struct sock *sk, const struct sk_buff *skb, u32 nwin <<= tp->rx_opt.snd_wscale; if (tcp_may_update_window(tp, ack, ack_seq, nwin)) { - flag |= FLAG_WIN_UPDATE; tcp_update_wl(tp, ack_seq); if (tp->snd_wnd != nwin) { tp->snd_wnd = nwin; + flag |= FLAG_WIN_UPDATE; /* Note, it is the only place, where * fast path is recovered for sending TCP. @@ -4381,7 +4382,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) */ tcp_update_wl(tp, ack_seq); tcp_snd_una_update(tp, ack); - flag |= FLAG_WIN_UPDATE; NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPHPACKS); } else { @@ -5290,6 +5290,10 @@ static bool tcp_try_coalesce(struct sock *sk, if (!tcp_skb_can_collapse_rx(to, from)) return false; + /* Nothing follows a FIN. */ + if (unlikely(TCP_SKB_CB(to)->tcp_flags & TCPHDR_FIN)) + return false; + if (!skb_try_coalesce(to, from, fragstolen, &delta)) return false; @@ -5413,6 +5417,20 @@ static int tcp_try_rmem_schedule(struct sock *sk, const struct sk_buff *skb, return 0; } +/* Credit the memory added to the receive queues since @rmem was sampled + * toward the next allowed collapse. Saturate at sk_rcvbuf, not at the goal + * checked in tcp_prune_queue(): sk_rcvbuf (and the goal) can grow later, + * for instance in tcp_clamp_window(). + */ +static void tcp_collapse_credit_add(struct sock *sk, int rmem) +{ + struct tcp_sock *tp = tcp_sk(sk); + int delta = atomic_read(&sk->sk_rmem_alloc) - rmem; + + if (delta > 0 && tp->rcv_collapse_credit < (u32)sk->sk_rcvbuf) + tp->rcv_collapse_credit += delta; +} + static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) { struct tcp_sock *tp = tcp_sk(sk); @@ -5420,6 +5438,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) struct sk_buff *skb1; u32 seq, end_seq; bool fragstolen; + int rmem; tcp_save_lrcv_flowlabel(sk, skb); tcp_data_ecn_check(sk, skb); @@ -5430,6 +5449,8 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) tcp_drop_reason(sk, skb, SKB_DROP_REASON_PROTO_MEM); return; } + /* Sampled after tcp_try_rmem_schedule(), which can prune. */ + rmem = atomic_read(&sk->sk_rmem_alloc); tcp_measure_rcv_mss(sk, skb); /* Disable header prediction. */ @@ -5559,6 +5580,10 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) skb_condense(skb); skb_set_owner_r(skb, sk); } + /* Net growth: coalescing can charge nothing, and covered skbs + * were freed. + */ + tcp_collapse_credit_add(sk, rmem); /* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */ if (sk->sk_socket) tcp_rcvbuf_grow(sk, tp->rcvq_space.space); @@ -5567,8 +5592,9 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, bool *fragstolen) { - int eaten; + int rmem = atomic_read(&sk->sk_rmem_alloc); struct sk_buff *tail = skb_peek_tail(&sk->sk_receive_queue); + int eaten; bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb); @@ -5580,6 +5606,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, tcp_add_receive_queue(sk, skb); skb_set_owner_r(skb, sk); } + tcp_collapse_credit_add(sk, rmem); return eaten; } @@ -5878,6 +5905,10 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root, __skb_queue_before(list, skb, nskb); else __skb_queue_tail(&tmp, nskb); /* defer rbtree insertion */ + /* nskb is charged before the skbs it replaces are freed. + * Make sure sk->sk_forward_alloc can not become negative. + */ + sk_forced_mem_schedule(sk, nskb->truesize); skb_set_owner_r(nskb, sk); mptcp_skb_ext_move(nskb, skb); @@ -6052,18 +6083,28 @@ static int tcp_prune_queue(struct sock *sk, const struct sk_buff *in_skb) if (tcp_can_ingest(sk, in_skb)) return 0; - tcp_collapse_ofo_queue(sk); - if (!skb_queue_empty(&sk->sk_receive_queue)) - tcp_collapse(sk, &sk->sk_receive_queue, NULL, - skb_peek(&sk->sk_receive_queue), - NULL, - tp->copied_seq, tp->rcv_nxt); + /* Collapsing walks both queues and is expensive, and can free + * almost nothing. Require at least 1/8 of sk_rcvbuf of new memory + * in the receive queues since the previous collapse, otherwise + * a stream of segments could trigger one collapse per packet. + */ + if (tp->rcv_collapse_credit >= (u32)sk->sk_rcvbuf >> 3) { + tp->rcv_collapse_credit = 0; - if (tcp_can_ingest(sk, in_skb)) - return 0; + tcp_collapse_ofo_queue(sk); + if (!skb_queue_empty(&sk->sk_receive_queue)) + tcp_collapse(sk, &sk->sk_receive_queue, NULL, + skb_peek(&sk->sk_receive_queue), + NULL, + tp->copied_seq, tp->rcv_nxt); - /* Collapsing did not help, destructive actions follow. - * This must not ever occur. */ + if (tcp_can_ingest(sk, in_skb)) + return 0; + } + + /* Collapsing did not help (or was not allowed), + * destructive actions follow. + */ tcp_prune_ofo_queue(sk, in_skb); @@ -7248,6 +7289,15 @@ tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) goto discard; case TCP_SYN_SENT: + /* We sent nothing yet, so no segment belongs to this connection. + * Send no RST: it would be built from this socket, whose TCP-AO + * keys are not set up either. + */ + if (unlikely(inet_test_bit(DEFER_CONNECT, sk))) { + SKB_DR_SET(reason, NOT_SPECIFIED); + goto discard; + } + tp->rx_opt.saw_tstamp = 0; tcp_mstamp_refresh(tp); queued = tcp_rcv_synsent_state_process(sk, skb, th); @@ -7634,7 +7684,7 @@ static void tcp_reqsk_record_syn(const struct sock *sk, saved_syn->network_hdrlen = skb_network_header_len(skb); saved_syn->tcp_hdrlen = tcp_hdrlen(skb); memcpy(saved_syn->data, base, len); - req->saved_syn = saved_syn; + RCU_INIT_POINTER(req->saved_syn, saved_syn); } } } @@ -7821,7 +7871,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, if (!inet_csk_reqsk_queue_add(sk, req, fastopen_sk)) { bh_unlock_sock(fastopen_sk); sock_put(fastopen_sk); - goto drop_and_free; + /* tcp_disconnect() already dropped one reqsk ref. */ + reqsk_put(req); + goto drop; } READ_ONCE(sk->sk_data_ready)(sk); bh_unlock_sock(fastopen_sk); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a7f9242f1e4290..2fc92a7884fc80 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -541,7 +541,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) if (!(type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)) __NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS); } - if (sk->sk_state == TCP_CLOSE) + if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; if (static_branch_unlikely(&ip4_min_ttl)) { @@ -1957,6 +1957,8 @@ enum skb_drop_reason tcp_add_backlog(struct sock *sk, struct sk_buff *skb) ((TCP_SKB_CB(tail)->tcp_flags ^ TCP_SKB_CB(skb)->tcp_flags) & (TCPHDR_ECE | TCPHDR_CWR | TCPHDR_AE)) || + /* Nothing follows a FIN, see tcp_try_coalesce() */ + (TCP_SKB_CB(tail)->tcp_flags & TCPHDR_FIN) || !tcp_skb_can_collapse_rx(tail, skb) || thtail->doff != th->doff || memcmp(thtail + 1, th + 1, hdrlen - sizeof(*th)) || @@ -3549,6 +3551,7 @@ static int __net_init tcp_sk_init(struct net *net) static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) { + bool synced = false; struct net *net; /* make sure concurrent calls to tcp_sk_exit_batch from net_cleanup_work @@ -3563,9 +3566,27 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) tcp_twsk_purge(net_exit_list); + /* inet_twsk_kill() unhashes a twsk before it is done with ehash + * and bhash, and before it drops its tw_refcount reference, + * so tcp_twsk_purge() can miss it. Such callers run with BH + * disabled: wait for them before freeing a private ehash. + */ + list_for_each_entry(net, net_exit_list, exit_list) { + if (net->ipv4.tcp_death_row.hashinfo->pernet) { + synchronize_net(); + synced = true; + break; + } + } + list_for_each_entry(net, net_exit_list, exit_list) { inet_pernet_hashinfo_free(net->ipv4.tcp_death_row.hashinfo); - WARN_ON_ONCE(!refcount_dec_and_test(&net->ipv4.tcp_death_row.tw_refcount)); + /* Without a grace period, a concurrent inet_twsk_kill() might + * still hold a tw_refcount reference. Let it drop it: struct net + * is freed by a later cleanup_net(), after an RCU grace period. + */ + if (!refcount_dec_if_one(&net->ipv4.tcp_death_row.tw_refcount)) + WARN_ON_ONCE(synced); tcp_fastopen_ctx_destroy(net); } diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index d58f99c67d4dc0..ae551546422fe7 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -495,7 +495,8 @@ void tcp_init_metrics(struct sock *sk) } if (tcp_metric_locked(tm, TCP_METRIC_CWND)) - tp->snd_cwnd_clamp = tcp_metric_get(tm, TCP_METRIC_CWND); + tp->snd_cwnd_clamp = min(tcp_metric_get(tm, TCP_METRIC_CWND), + TCP_MAX_SND_CWND); val = READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ? 0 : tcp_metric_get(tm, TCP_METRIC_SSTHRESH); diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 0ddfd5af6e58f6..a05bb02e204c33 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -974,7 +974,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, tcp_reset(sk, skb); } if (!fastopen) { - bool unlinked = inet_csk_reqsk_queue_drop(sk, req); + bool unlinked = inet_csk_reqsk_queue_drop(req->rsk_listener, req); if (unlinked) __NET_INC_STATS(sock_net(sk), LINUX_MIB_EMBRYONICRSTS); diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 303d0102519ac1..2e5562f353f85d 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2850,8 +2850,11 @@ enum skb_drop_reason udp_v4_early_demux(struct sk_buff *skb) skb->destructor = sock_pfree; dst = rcu_dereference(sk->sk_rx_dst); - if (dst) + /* A dual-stack socket can cache an IPv6 dst. */ + if (dst && dst->ops->family == AF_INET) dst = dst_check(dst, 0); + else + dst = NULL; if (dst) { u32 itag = 0; diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index cf07c3c6611a22..b77ae2f00c626c 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -514,9 +514,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, } if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST) { - /* Detect modified geometry and pass those to skb_segment. */ + /* Detect modified geometry and pass those to skb_segment. + * SKB_GSO_UDP_L4 is used by both IPv4 and IPv6: also make sure + * the frag_list skbs still have the IP family we segment for, + * as their network headers are not rebuilt. + */ if ((skb_pagelen(gso_skb) - sizeof(*uh) == skb_shinfo(gso_skb)->gso_size) && - !(skb_shinfo(gso_skb)->gso_type & SKB_GSO_DODGY)) + !(skb_shinfo(gso_skb)->gso_type & SKB_GSO_DODGY) && + ip_hdr(skb_shinfo(gso_skb)->frag_list)->version == (is_ipv6 ? 6 : 4)) return __udp_gso_segment_list(gso_skb, features, is_ipv6); ret = __skb_linearize(gso_skb); @@ -743,6 +748,7 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head, pp = p; } else { if (NAPI_GRO_CB(skb)->is_flist) { + skb_gro_frag0_invalidate(skb); if (!pskb_may_pull(skb, skb_gro_offset(skb))) { NAPI_GRO_CB(skb)->flush = 1; return NULL; diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index a128fe85620d30..29581c94fdcf80 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -62,10 +62,10 @@ EXPORT_SYMBOL(udp_sock_create4); static bool sk_saddr_any(struct sock *sk) { #if IS_ENABLED(CONFIG_IPV6) - return ipv6_addr_any(&sk->sk_v6_rcv_saddr); -#else - return !sk->sk_rcv_saddr; + if (sk->sk_family == AF_INET6) + return ipv6_addr_any(&sk->sk_v6_rcv_saddr); #endif + return !sk->sk_rcv_saddr; } void setup_udp_tunnel_sock(struct net *net, struct sock *sk, diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c index 0ae67d537499a2..fffa3c4f456eee 100644 --- a/net/ipv4/xfrm4_output.c +++ b/net/ipv4/xfrm4_output.c @@ -38,9 +38,12 @@ int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) void xfrm4_local_error(struct sk_buff *skb, u32 mtu) { + struct sock *sk = skb_to_full_sk(skb); struct iphdr *hdr; + if (!sk) + return; + hdr = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb); - ip_local_error(skb->sk, EMSGSIZE, hdr->daddr, - inet_sk(skb->sk)->inet_dport, mtu); + ip_local_error(sk, EMSGSIZE, hdr->daddr, inet_sk(sk)->inet_dport, mtu); } diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index c8c0dd04982d9b..d9d13e78bf13ba 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1487,7 +1487,8 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; if (cfg.preferred_lft <= regen_advance + age) { cfg.preferred_lft = regen_advance + age + 1; - if (cfg.preferred_lft > cfg.valid_lft || + if (cfg.preferred_lft <= regen_advance + age || + cfg.preferred_lft > cfg.valid_lft || cfg.preferred_lft > if_public_preferred_lft) { in6_ifa_put(ifp); in6_dev_put(idev); diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index e399a42e30839a..4cd0ae9313b322 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -1219,7 +1219,7 @@ static int calipso_req_setattr(struct request_sock *req, if (IS_ERR(new)) return PTR_ERR(new); - txopts = ipv6_renew_options(sk, req_inet->ipv6_opt, IPV6_HOPOPTS, new); + txopts = ipv6_renew_options(NULL, req_inet->ipv6_opt, IPV6_HOPOPTS, new); kfree(new); @@ -1227,10 +1227,8 @@ static int calipso_req_setattr(struct request_sock *req, return PTR_ERR(txopts); txopts = xchg(&req_inet->ipv6_opt, txopts); - if (txopts) { - atomic_sub(txopts->tot_len, &sk->sk_omem_alloc); + if (txopts) txopt_put(txopts); - } return 0; } @@ -1260,14 +1258,12 @@ static void calipso_req_delattr(struct request_sock *req) if (calipso_opt_del(req_inet->ipv6_opt->hopopt, &new)) return; /* Nothing to do */ - txopts = ipv6_renew_options(sk, req_inet->ipv6_opt, IPV6_HOPOPTS, new); + txopts = ipv6_renew_options(NULL, req_inet->ipv6_opt, IPV6_HOPOPTS, new); if (!IS_ERR(txopts)) { txopts = xchg(&req_inet->ipv6_opt, txopts); - if (txopts) { - atomic_sub(txopts->tot_len, &sk->sk_omem_alloc); + if (txopts) txopt_put(txopts); - } } kfree(new); } diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 191c9733ff9fa1..ff7a7ffbf9833a 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -149,6 +149,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, __be32 fl6_flowlabel = 0; __be32 old_fl6_flowlabel; __be16 old_dport; + int old_bound_dev_if; int addr_type; int err; @@ -219,6 +220,8 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, goto out; } + old_bound_dev_if = sk->sk_bound_dev_if; + if (__ipv6_addr_needs_scope_id(addr_type)) { if (addr_len >= sizeof(struct sockaddr_in6) && usin->sin6_scope_id) { @@ -261,6 +264,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, sk->sk_v6_daddr = old_daddr; np->flow_label = old_fl6_flowlabel; inet->inet_dport = old_dport; + WRITE_ONCE(sk->sk_bound_dev_if, old_bound_dev_if); goto out; } diff --git a/net/ipv6/esp6_offload.c b/net/ipv6/esp6_offload.c index 22895521a57d09..ca947cb94fb785 100644 --- a/net/ipv6/esp6_offload.c +++ b/net/ipv6/esp6_offload.c @@ -64,6 +64,7 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head, if (NAPI_GRO_CB(skb)->proto == IPPROTO_UDP) encap_type = UDP_ENCAP_ESPINUDP; + skb_gro_frag0_invalidate(skb); if (!pskb_pull(skb, offset)) return NULL; diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 96c8402a27a549..ccc549de3c8a07 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -1281,7 +1281,7 @@ static void ipv6_renew_option(int renewtype, * not copied into the new set of options. * * The new set of options is allocated from the socket option memory - * buffer of @sk. + * buffer of @sk, or with kmalloc() if @sk is NULL. */ struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, @@ -1309,7 +1309,8 @@ ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, return NULL; tot_len += sizeof(*opt2); - opt2 = sock_kmalloc(sk, tot_len, GFP_ATOMIC); + opt2 = sk ? sock_kmalloc(sk, tot_len, GFP_ATOMIC) : + kmalloc(tot_len, GFP_ATOMIC); if (!opt2) return ERR_PTR(-ENOBUFS); diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c index 4a9748338cf400..764c694fb417a2 100644 --- a/net/ipv6/exthdrs_core.c +++ b/net/ipv6/exthdrs_core.c @@ -138,9 +138,6 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) int opttype = nh[offset]; int optlen; - if (opttype == type) - return offset; - switch (opttype) { case IPV6_TLV_PAD1: optlen = 1; @@ -153,6 +150,10 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) goto bad; break; } + /* Some callers read the option, so it must be in the header. */ + if (opttype == type) + return offset; + offset += optlen; len -= optlen; } diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index a95b0351824f32..d8203ebad88274 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -343,7 +343,12 @@ static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt if (likely(off >= 0)) { hao = (struct ipv6_destopt_hao *) (skb_network_header(skb) + off); - swap(iph->saddr, hao->addr); + /* + * The header can have moved or changed after + * ipv6_dest_hao() checked the length. + */ + if (hao->length == 16) + swap(iph->saddr, hao->addr); } } } diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index b111b51d69fc9b..1eea584d80df83 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -105,10 +105,12 @@ struct sock *__inet6_lookup_established(const struct net *net, continue; if (!inet6_match(net, sk, saddr, daddr, ports, dif, sdif)) continue; - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) goto out; - if (unlikely(!inet6_match(net, sk, saddr, daddr, ports, dif, sdif))) { + if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) || + !inet6_match(net, sk, saddr, daddr, ports, dif, + sdif))) { sock_gen_put(sk); goto begin; } diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index f7c69c9df4119c..e1d49897d6ab06 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -89,6 +89,40 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w) write_unlock_bh(&net->ipv6.fib6_walker_lock); } +/* @old is leaving the tree. Walkers resting on it continue from @new, or + * climb to the parent node when there is no @new. Called with tb6_lock + * held. + */ +static void fib6_walkers_replace_leaf(struct net *net, struct fib6_info *old, + struct fib6_info *new) +{ + struct fib6_walker *w; + + read_lock(&net->ipv6.fib6_walker_lock); + FOR_WALKERS(net, w) { + if (w->state == FWS_C && w->leaf == old) { + pr_debug("walker %p adjusted by unlink of %p\n", w, old); + w->leaf = new; + w->skip_in_node = 0; + if (!new) + w->state = FWS_U; + } + } + read_unlock(&net->ipv6.fib6_walker_lock); +} + +/* @rt is removed from its node: walkers resting on it continue from the + * next route of the node. + */ +static void fib6_walkers_skip_rt(struct net *net, struct fib6_info *rt) +{ + struct fib6_info *next; + + next = rcu_dereference_protected(rt->fib6_next, + lockdep_is_held(&rt->fib6_table->tb6_lock)); + fib6_walkers_replace_leaf(net, rt, next); +} + static int fib6_new_sernum(struct net *net) { int new, old = atomic_read(&net->ipv6.fib6_sernum); @@ -1312,6 +1346,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, rcu_assign_pointer(rt->fib6_node, fn); rt->fib6_next = iter->fib6_next; rcu_assign_pointer(*ins, rt); + fib6_walkers_replace_leaf(info->nl_net, iter, rt); if (!info->skip_notify) inet6_rt_notify(RTM_NEWROUTE, rt, info, NLM_F_REPLACE); if (!(fn->fn_flags & RTN_RTINFO)) { @@ -1333,6 +1368,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, if (iter->fib6_metric > rt->fib6_metric) break; if (rt6_qualify_for_ecmp(iter)) { + fib6_walkers_skip_rt(info->nl_net, iter); *ins = iter->fib6_next; iter->fib6_node = NULL; list_add(&iter->purge_link, purge_list); @@ -1967,7 +2003,6 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn, enum rt_del_reason del_reason) { struct fib6_info *leaf, *replace_rt = NULL; - struct fib6_walker *w; struct fib6_info *rt = rcu_dereference_protected(*rtp, lockdep_is_held(&table->tb6_lock)); struct net *net = info->nl_net; @@ -2018,18 +2053,7 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn, rt6_multipath_rebalance(next_sibling); } - /* Adjust walkers */ - read_lock(&net->ipv6.fib6_walker_lock); - FOR_WALKERS(net, w) { - if (w->state == FWS_C && w->leaf == rt) { - pr_debug("walker %p adjusted by delroute\n", w); - w->leaf = rcu_dereference_protected(rt->fib6_next, - lockdep_is_held(&table->tb6_lock)); - if (!w->leaf) - w->state = FWS_U; - } - } - read_unlock(&net->ipv6.fib6_walker_lock); + fib6_walkers_skip_rt(net, rt); /* If it was last route, call fib6_repair_tree() to: * 1. For root node, put back null_entry as how the table was created. diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 25fe0ba98b1a6a..cb648c8394310a 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1305,7 +1305,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow); * @sk: socket which provides the dst cache and route info * @fl6: flow to lookup * @final_dst: final destination address for ipsec lookup - * @connected: whether @sk is connected or not + * @connected: whether the flow can use and update the socket dst cache * * This function performs a route lookup on the given flow with the * possibility of using the cached route in the socket if it is valid. @@ -1322,11 +1322,14 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, const struct in6_addr *final_dst, bool connected) { - struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie); + struct dst_entry *dst; - dst = ip6_sk_dst_check(sk, dst, fl6); - if (dst) - return dst; + if (connected) { + dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie); + dst = ip6_sk_dst_check(sk, dst, fl6); + if (dst) + return dst; + } dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_dst); if (connected && !IS_ERR(dst)) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index af968a2c2a7847..dd0638d3c3f95a 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -827,19 +827,18 @@ static void ip6mr_destroy_unres(struct mr_table *mrt, struct mfc6_cache *c) WRITE_ONCE(mrt->cache_resolve_queue_len, mrt->cache_resolve_queue_len - 1); - while ((skb = skb_dequeue(&c->_c.mfc_un.unres.unresolved)) != NULL) { - if (ipv6_hdr(skb)->version == 0) { - struct nlmsghdr *nlh = skb_pull(skb, - sizeof(struct ipv6hdr)); - nlh->nlmsg_type = NLMSG_ERROR; - nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); - skb_trim(skb, nlh->nlmsg_len); - ((struct nlmsgerr *)nlmsg_data(nlh))->error = -ETIMEDOUT; - rtnl_unicast(skb, net, NETLINK_CB(skb).portid); - } else - kfree_skb(skb); + while ((skb = skb_dequeue(&c->_c.mfc_un.unres.nl_queries))) { + struct nlmsghdr *nlh = skb_pull(skb, sizeof(struct ipv6hdr)); + + nlh->nlmsg_type = NLMSG_ERROR; + nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); + skb_trim(skb, nlh->nlmsg_len); + ((struct nlmsgerr *)nlmsg_data(nlh))->error = -ETIMEDOUT; + rtnl_unicast(skb, net, NETLINK_CB(skb).portid); } + skb_queue_purge(&c->_c.mfc_un.unres.unresolved); + ip6mr_cache_free(c); } @@ -1047,6 +1046,7 @@ static struct mfc6_cache *ip6mr_cache_alloc_unres(void) if (!c) return NULL; skb_queue_head_init(&c->_c.mfc_un.unres.unresolved); + skb_queue_head_init(&c->_c.mfc_un.unres.nl_queries); c->_c.mfc_un.unres.expires = jiffies + 10 * HZ; return c; } @@ -1060,30 +1060,26 @@ static void ip6mr_cache_resolve(struct net *net, struct mr_table *mrt, { struct sk_buff *skb; - /* - * Play the pending entries through our router - */ + /* Answer the pending netlink route queries */ + while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.nl_queries))) { + struct nlmsghdr *nlh = skb_pull(skb, sizeof(struct ipv6hdr)); - while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { - if (ipv6_hdr(skb)->version == 0) { - struct nlmsghdr *nlh = skb_pull(skb, - sizeof(struct ipv6hdr)); - - if (mr_fill_mroute(mrt, skb, &c->_c, - nlmsg_data(nlh)) > 0) { - nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh; - } else { - nlh->nlmsg_type = NLMSG_ERROR; - nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); - skb_trim(skb, nlh->nlmsg_len); - ((struct nlmsgerr *)nlmsg_data(nlh))->error = -EMSGSIZE; - } - rtnl_unicast(skb, net, NETLINK_CB(skb).portid); + if (mr_fill_mroute(mrt, skb, &c->_c, nlmsg_data(nlh)) > 0) { + nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh; } else { - rcu_read_lock(); - ip6_mr_forward(net, mrt, skb->dev, skb, c); - rcu_read_unlock(); + nlh->nlmsg_type = NLMSG_ERROR; + nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); + skb_trim(skb, nlh->nlmsg_len); + ((struct nlmsgerr *)nlmsg_data(nlh))->error = -EMSGSIZE; } + rtnl_unicast(skb, net, NETLINK_CB(skb).portid); + } + + /* Play the pending packets through our router */ + while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { + rcu_read_lock(); + ip6_mr_forward(net, mrt, skb->dev, skb, c); + rcu_read_unlock(); } } @@ -1188,7 +1184,8 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, /* Queue a packet for resolution. It gets locked cache entry! */ static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi, - struct sk_buff *skb, struct net_device *dev) + struct sk_buff *skb, struct net_device *dev, + bool nl_query) { struct net *net = read_pnet(&mrt->net); struct mfc6_cache *c = NULL; @@ -1242,7 +1239,8 @@ static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi, } /* See if we can append the packet */ - if (c->_c.mfc_un.unres.unresolved.qlen > 3) { + if (skb_queue_len(&c->_c.mfc_un.unres.unresolved) + + skb_queue_len(&c->_c.mfc_un.unres.nl_queries) > 3) { c = NULL; err = -ENOBUFS; goto err; @@ -1254,7 +1252,8 @@ static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi, } skb_dst_drop(skb); - skb_queue_tail(&c->_c.mfc_un.unres.unresolved, skb); + skb_queue_tail(nl_query ? &c->_c.mfc_un.unres.nl_queries : + &c->_c.mfc_un.unres.unresolved, skb); spin_unlock_bh(&mfc_unres_lock); return 0; @@ -1623,12 +1622,20 @@ static void mroute_clean_tables(struct mr_table *mrt, int flags, } } -static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk) +static int ip6mr_sk_init(struct sock *sk) { - int err = 0; struct net *net = sock_net(sk); + struct mr_table *mrt; + int err = 0; rtnl_lock(); + mrt = __ip6mr_get_table(net, + raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); + if (!mrt) { + err = -ENOENT; + goto out_unlock; + } + spin_lock(&mrt_lock); if (rtnl_dereference(mrt->mroute_sk)) { err = -EADDRINUSE; @@ -1644,6 +1651,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk) NETCONFA_MC_FORWARDING, NETCONFA_IFINDEX_ALL, net->ipv6.devconf_all); +out_unlock: rtnl_unlock(); return err; @@ -1745,7 +1753,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval, if (optlen < sizeof(int)) return -EINVAL; - return ip6mr_sk_init(mrt, sk); + return ip6mr_sk_init(sk); case MRT6_DONE: return ip6mr_sk_done(sk); @@ -1872,16 +1880,21 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval, /* "pim6reg%u" should not exceed 16 bytes (IFNAMSIZ) */ if (v != RT_TABLE_DEFAULT && v >= 100000000) return -EINVAL; - if (sk == rcu_access_pointer(mrt->mroute_sk)) - return -EBUSY; - rtnl_lock(); ret = 0; - mrt = ip6mr_new_table(net, v); - if (IS_ERR(mrt)) - ret = PTR_ERR(mrt); - else - raw6_sk(sk)->ip6mr_table = v; + mrt = __ip6mr_get_table(net, + raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); + if (!mrt) { + ret = -ENOENT; + } else if (sk == rtnl_dereference(mrt->mroute_sk)) { + ret = -EBUSY; + } else { + mrt = ip6mr_new_table(net, v); + if (IS_ERR(mrt)) + ret = PTR_ERR(mrt); + else + raw6_sk(sk)->ip6mr_table = v; + } rtnl_unlock(); return ret; } @@ -2399,7 +2412,8 @@ int ip6_mr_input(struct sk_buff *skb) vif = ip6mr_find_vif(mrt, dev); if (vif >= 0) { - int err = ip6mr_cache_unresolved(mrt, vif, skb, dev); + int err = ip6mr_cache_unresolved(mrt, vif, skb, dev, + false); return err; } @@ -2451,7 +2465,7 @@ int ip6_mr_output(struct net *net, struct sock *sk, struct sk_buff *skb) if (!cache) { vif = ip6mr_find_vif(mrt, dev); if (vif >= 0) - return ip6mr_cache_unresolved(mrt, vif, skb, dev); + return ip6mr_cache_unresolved(mrt, vif, skb, dev, false); goto ip6_output; } @@ -2528,7 +2542,7 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, iph->saddr = rt->rt6i_src.addr; iph->daddr = rt->rt6i_dst.addr; - err = ip6mr_cache_unresolved(mrt, vif, skb2, dev); + err = ip6mr_cache_unresolved(mrt, vif, skb2, dev, true); rcu_read_unlock(); return err; diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c index 6a16a5bd0d910b..96156797241147 100644 --- a/net/ipv6/mip6.c +++ b/net/ipv6/mip6.c @@ -211,9 +211,16 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, if (likely(opt->dsthao)) { offset = ipv6_find_tlv(skb, opt->dsthao, IPV6_TLV_HAO); - if (likely(offset >= 0)) + if (likely(offset >= 0)) { hao = (struct ipv6_destopt_hao *) (skb_network_header(skb) + offset); + /* + * The header can have moved or changed after + * ipv6_dest_hao() checked the length. + */ + if (hao->length != 16) + hao = NULL; + } } stamp = skb_get_ktime(skb); diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 313c4aac377aa2..010baaa6066573 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -440,11 +440,12 @@ mark_source_chains(const struct xt_table_info *newinfo, e->counters.pcnt = pos; pos += size; } else { - int newpos = t->verdict; + int newpos; if (strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0 && - newpos >= 0) { + t->verdict >= 0) { + newpos = t->verdict; /* This a jump; chase it. */ if (!xt_find_jump_offset(offsets, newpos, newinfo->number)) diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index be72c4346f8b71..f25ff2a12a824a 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c @@ -330,11 +330,10 @@ static int nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *skb, if (unlikely(ecn == 0xff)) goto err; - reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail); - if (!reasm_data) - goto err; - - payload_len = -skb_network_offset(skb) - + /* Check the size on the first fragment, which will become the head: + * inet_frag_reasm_finish() must follow inet_frag_reasm_prepare(). + */ + payload_len = -skb_network_offset(skb_rb_first(&fq->q.rb_fragments)) - sizeof(struct ipv6hdr) + fq->q.len - sizeof(struct frag_hdr); if (payload_len > IPV6_MAXPLEN) { @@ -343,6 +342,10 @@ static int nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *skb, goto err; } + reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail); + if (!reasm_data) + goto err; + /* We have to remove fragment header from datagram and to relocate * header in order to calculate ICV correctly. */ skb_network_header(skb)[fq->nhoffset] = skb_transport_header(skb)[0]; diff --git a/net/ipv6/netfilter/nf_reject_ipv6.c b/net/ipv6/netfilter/nf_reject_ipv6.c index 5e08d8529cc889..7c94641845175c 100644 --- a/net/ipv6/netfilter/nf_reject_ipv6.c +++ b/net/ipv6/netfilter/nf_reject_ipv6.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -409,7 +410,19 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb, dev_queue_xmit(nskb); } else #endif + { + local_bh_disable(); + if (nf_dev_xmit_recursion()) { + local_bh_enable(); + kfree_skb(nskb); + return; + } + + nf_dev_xmit_recursion_inc(); ip6_local_out(net, sk, nskb); + nf_dev_xmit_recursion_dec(); + local_bh_enable(); + } } EXPORT_SYMBOL_GPL(nf_send_reset6); diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index b965258cf9e5f2..00d832c7cdae96 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -160,12 +160,6 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) inet6_iif(skb), inet6_sdif(skb))) continue; - if (atomic_read(&sk->sk_rmem_alloc) >= - READ_ONCE(sk->sk_rcvbuf)) { - sk_drops_inc(sk); - continue; - } - delivered = true; switch (nexthdr) { case IPPROTO_ICMPV6: @@ -197,8 +191,15 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) if (filtered < 0) break; if (filtered == 0) { - struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC); + struct sk_buff *clone; + if (atomic_read(&sk->sk_rmem_alloc) >= + READ_ONCE(sk->sk_rcvbuf)) { + sk_drops_inc(sk); + continue; + } + + clone = skb_clone(skb, GFP_ATOMIC); /* Not releasing hash table! */ if (clone) rawv6_rcv(sk, clone); @@ -654,6 +655,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length, if (unlikely(!skb)) return 0; + /* l3mdev_ip6_out() may have replaced the skb dst. */ + rt = dst_rt6_info(skb_dst(skb)); + /* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev * in the error path. Since skb has been freed, the dst could * have been queued for deletion. diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 8418ed9423f4bb..91a65fe6735003 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c @@ -275,16 +275,19 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb, if (unlikely(ecn == 0xff)) goto out_fail; - reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail); - if (!reasm_data) - goto out_oom; - - payload_len = -skb_network_offset(skb) - + /* Check the size on the first fragment, which will become the head: + * inet_frag_reasm_finish() must follow inet_frag_reasm_prepare(). + */ + payload_len = -skb_network_offset(skb_rb_first(&fq->q.rb_fragments)) - sizeof(struct ipv6hdr) + fq->q.len - sizeof(struct frag_hdr); if (payload_len > IPV6_MAXPLEN) goto out_oversize; + reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail); + if (!reasm_data) + goto out_oom; + /* We have to remove fragment header from datagram and to relocate * header in order to calculate ICV correctly. */ nhoff = fq->nhoffset; diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 616b86f89f6375..1b2dcc066e1982 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -179,12 +179,20 @@ void rt6_uncached_list_flush_dev(struct net_device *dev) list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_uncached) { struct inet6_dev *rt_idev = rt->rt6i_idev; struct net_device *rt_dev = rt->dst.dev; + struct fib6_info *from; + bool release_fib; + + rcu_read_lock(); + from = rcu_dereference(rt->from); + release_fib = from && from->fib6_destroying; + rcu_read_unlock(); if (rt_idev && (dev ? rt_idev->dev == dev : READ_ONCE(rt_idev->dev->reg_state) == NETREG_UNREGISTERED)) { rt->rt6i_idev = in6_dev_get(blackhole_netdev); in6_dev_put(rt_idev); + release_fib = true; } if (dev ? rt_dev == dev : @@ -193,6 +201,12 @@ void rt6_uncached_list_flush_dev(struct net_device *dev) netdev_ref_replace(rt_dev, blackhole_netdev, &rt->dst.dev_tracker, GFP_ATOMIC); + release_fib = true; + } + + if (release_fib) { + from = unrcu_pointer(xchg(&rt->from, NULL)); + fib6_info_release(from); } if (rt->dst.dev == blackhole_netdev && @@ -1151,6 +1165,12 @@ static void ip6_rt_init_dst(struct rt6_info *rt, const struct fib6_result *res) return; } + /* addrconf_ifdown() removed inet6_dev. The device can't do IPv6. */ + if (!rt->rt6i_idev) { + ip6_rt_init_dst_reject(rt, RTN_UNREACHABLE); + return; + } + rt->dst.error = 0; rt->dst.output = ip6_output; @@ -1186,10 +1206,10 @@ static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res) const struct net_device *dev = nh->fib_nh_dev; struct fib6_info *f6i = res->f6i; + rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; ip6_rt_init_dst(rt, res); rt->rt6i_dst = f6i->fib6_dst; - rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; rt->rt6i_flags = res->fib6_flags; if (nh->fib_nh_gw_family) { rt->rt6i_gateway = nh->fib_nh_gw6; @@ -3424,9 +3444,9 @@ static int ip6_route_check_nh(struct net *net, netdevice_tracker *dev_tracker, struct inet6_dev **idev) { + int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_IGNORE_LINKSTATE; const struct in6_addr *gw_addr = &cfg->fc_gateway; struct net_device *dev = _dev ? *_dev : NULL; - int flags = RT6_LOOKUP_F_IFACE; struct fib6_result res = {}; int err = -EHOSTUNREACH; @@ -3701,9 +3721,10 @@ void fib6_nh_release(struct fib6_nh *fib6_nh) { struct rt6_exception_bucket *bucket; + fib6_nh_release_dsts(fib6_nh); + rcu_read_lock(); - fib6_nh_flush_exceptions(fib6_nh, NULL); bucket = fib6_nh_get_excptn_bucket(fib6_nh, NULL); if (bucket) { rcu_assign_pointer(fib6_nh->rt6i_exception_bucket, NULL); @@ -3712,7 +3733,6 @@ void fib6_nh_release(struct fib6_nh *fib6_nh) rcu_read_unlock(); - fib6_nh_release_dsts(fib6_nh); free_percpu(fib6_nh->rt6i_pcpu); fib_nh_common_release(&fib6_nh->nh_common); @@ -3722,6 +3742,8 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh) { int cpu; + fib6_nh_flush_exceptions(fib6_nh, NULL); + if (!fib6_nh->rt6i_pcpu) return; diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 0d39a38a5dd299..3bc47c5614ff40 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,21 @@ static inline struct seg6_lwt *seg6_lwt_lwtunnel(struct lwtunnel_state *lwt) return (struct seg6_lwt *)lwt->data; } +static bool seg6_skb_has_lwtstate(struct sk_buff *skb) +{ + struct dst_entry *dst; + + if (unlikely(!skb_valid_dst(skb))) + return false; + + dst = skb_dst(skb); + if (unlikely(!dst->lwtstate || + dst->lwtstate->type != LWTUNNEL_ENCAP_SEG6)) + return false; + + return true; +} + static inline struct seg6_iptunnel_encap * seg6_encap_lwtunnel(struct lwtunnel_state *lwt) { @@ -622,6 +638,17 @@ static int seg6_input_core(struct net *net, struct sock *sk, return err; } +static int seg6_input_core_nf(struct net *net, struct sock *sk, + struct sk_buff *skb) +{ + if (unlikely(!seg6_skb_has_lwtstate(skb))) { + kfree_skb(skb); + return -EINVAL; + } + + return seg6_input_core(net, sk, skb); +} + static int seg6_input_nf(struct sk_buff *skb) { struct net_device *dev = skb_dst_dev(skb); @@ -630,10 +657,10 @@ static int seg6_input_nf(struct sk_buff *skb) switch (skb->protocol) { case htons(ETH_P_IP): return NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, net, NULL, - skb, NULL, dev, seg6_input_core); + skb, NULL, dev, seg6_input_core_nf); case htons(ETH_P_IPV6): return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, net, NULL, - skb, NULL, dev, seg6_input_core); + skb, NULL, dev, seg6_input_core_nf); } return -EINVAL; @@ -726,6 +753,17 @@ static int seg6_output_core(struct net *net, struct sock *sk, return err; } +static int seg6_output_core_nf(struct net *net, struct sock *sk, + struct sk_buff *skb) +{ + if (unlikely(!seg6_skb_has_lwtstate(skb))) { + kfree_skb(skb); + return -EINVAL; + } + + return seg6_output_core(net, sk, skb); +} + static int seg6_output_nf(struct net *net, struct sock *sk, struct sk_buff *skb) { struct net_device *dev = skb_dst_dev(skb); @@ -733,10 +771,10 @@ static int seg6_output_nf(struct net *net, struct sock *sk, struct sk_buff *skb) switch (skb->protocol) { case htons(ETH_P_IP): return NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING, net, sk, skb, - NULL, dev, seg6_output_core); + NULL, dev, seg6_output_core_nf); case htons(ETH_P_IPV6): return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, net, sk, skb, - NULL, dev, seg6_output_core); + NULL, dev, seg6_output_core_nf); } return -EINVAL; diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 0c3d1be7f1299e..82207da08dfdac 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifdef CONFIG_IPV6_SEG6_HMAC #include @@ -149,9 +150,7 @@ struct seg6_end_dt_info { int vrf_ifindex; int vrf_table; - /* tunneled packet family (IPv4 or IPv6). - * Protocol and header length are inferred from family. - */ + /* tunneled packet family (IPv4 or IPv6) */ u16 family; }; @@ -213,6 +212,21 @@ static struct seg6_local_lwt *seg6_local_lwtunnel(struct lwtunnel_state *lwt) return (struct seg6_local_lwt *)lwt->data; } +static bool seg6_local_skb_has_lwtstate(struct sk_buff *skb) +{ + struct dst_entry *dst; + + if (unlikely(!skb_valid_dst(skb))) + return false; + + dst = skb_dst(skb); + if (unlikely(!dst->lwtstate || + dst->lwtstate->type != LWTUNNEL_ENCAP_SEG6_LOCAL)) + return false; + + return true; +} + static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb) { struct ipv6_sr_hdr *srh; @@ -1028,6 +1042,17 @@ static int input_action_end_dx6_finish(struct net *net, struct sock *sk, return dst_input(skb); } +static int input_action_end_dx6_finish_nf(struct net *net, struct sock *sk, + struct sk_buff *skb) +{ + if (unlikely(!seg6_local_skb_has_lwtstate(skb))) { + kfree_skb(skb); + return -EINVAL; + } + + return input_action_end_dx6_finish(net, sk, skb); +} + /* decapsulate and forward to specified nexthop */ static int input_action_end_dx6(struct sk_buff *skb, struct seg6_local_lwt *slwt) @@ -1048,7 +1073,7 @@ static int input_action_end_dx6(struct sk_buff *skb, if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, dev_net(skb->dev), NULL, skb, skb->dev, - NULL, input_action_end_dx6_finish); + NULL, input_action_end_dx6_finish_nf); return input_action_end_dx6_finish(dev_net(skb->dev), NULL, skb); drop: @@ -1056,6 +1081,40 @@ static int input_action_end_dx6(struct sk_buff *skb, return -EINVAL; } +/* Validate the length of the IPv4 header at skb->data (which must point to + * the network header) and report that length, options included. + * Only the version, the header length and the presence of the whole header + * are checked. + * The length is written only when SKB_NOT_DROPPED_YET is returned. + * + * skb pointers may change: after this call, the caller must evaluate again + * any pointer into the packet data. + */ +static enum skb_drop_reason +seg6_validate_iphdr_len(struct sk_buff *skb, int *hdrlen) +{ + enum skb_drop_reason reason; + const struct iphdr *iph; + int len; + + reason = pskb_may_pull_reason(skb, sizeof(struct iphdr)); + if (reason) + return reason; + + iph = ip_hdr(skb); + if (iph->version != 4 || iph->ihl < 5) + return SKB_DROP_REASON_IP_INHDR; + + len = ip_hdrlen(skb); + + reason = pskb_may_pull_reason(skb, len); + if (reason) + return reason; + + *hdrlen = len; + return SKB_NOT_DROPPED_YET; +} + static int input_action_end_dx4_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { @@ -1082,27 +1141,42 @@ static int input_action_end_dx4_finish(struct net *net, struct sock *sk, return dst_input(skb); } +static int input_action_end_dx4_finish_nf(struct net *net, struct sock *sk, + struct sk_buff *skb) +{ + if (unlikely(!seg6_local_skb_has_lwtstate(skb))) { + kfree_skb(skb); + return -EINVAL; + } + + return input_action_end_dx4_finish(net, sk, skb); +} + static int input_action_end_dx4(struct sk_buff *skb, struct seg6_local_lwt *slwt) { + SKB_DR(reason); + int hdrlen; + if (!decap_and_validate(skb, IPPROTO_IPIP)) goto drop; - if (!pskb_may_pull(skb, sizeof(struct iphdr))) + reason = seg6_validate_iphdr_len(skb, &hdrlen); + if (reason) goto drop; skb->protocol = htons(ETH_P_IP); - skb_set_transport_header(skb, sizeof(struct iphdr)); + skb_set_transport_header(skb, hdrlen); nf_reset_ct(skb); if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, dev_net(skb->dev), NULL, skb, skb->dev, - NULL, input_action_end_dx4_finish); + NULL, input_action_end_dx4_finish_nf); return input_action_end_dx4_finish(dev_net(skb->dev), NULL, skb); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return -EINVAL; } @@ -1237,16 +1311,24 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, struct seg6_end_dt_info *info = &slwt->dt_info; struct net_device *vrf; __be16 protocol; + SKB_DR(reason); int hdrlen; vrf = end_dt_get_vrf_rcu(skb, info); if (unlikely(!vrf)) goto drop; + if (unlikely(info->family != AF_UNSPEC && info->family != family)) { + pr_warn_once("seg6local: SRv6 End.DT* family mismatch"); + goto drop; + } + switch (family) { case AF_INET: protocol = htons(ETH_P_IP); - hdrlen = sizeof(struct iphdr); + reason = seg6_validate_iphdr_len(skb, &hdrlen); + if (unlikely(reason)) + goto drop; break; case AF_INET6: protocol = htons(ETH_P_IPV6); @@ -1258,11 +1340,6 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, goto drop; } - if (unlikely(info->family != AF_UNSPEC && info->family != family)) { - pr_warn_once("seg6local: SRv6 End.DT* family mismatch"); - goto drop; - } - skb->protocol = protocol; skb_dst_drop(skb); @@ -1273,7 +1350,7 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, return end_dt_vrf_rcv(skb, family, vrf); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return ERR_PTR(-EINVAL); } @@ -1286,9 +1363,7 @@ static int input_action_end_dt4(struct sk_buff *skb, if (!decap_and_validate(skb, IPPROTO_IPIP)) goto drop; - if (!pskb_may_pull(skb, sizeof(struct iphdr))) - goto drop; - + /* end_dt_vrf_core() validates the inner IPv4 header length */ skb = end_dt_vrf_core(skb, slwt, AF_INET); if (!skb) /* packet has been processed and consumed by the VRF */ @@ -1741,6 +1816,17 @@ static int seg6_local_input_core(struct net *net, struct sock *sk, return rc; } +static int seg6_local_input_core_nf(struct net *net, struct sock *sk, + struct sk_buff *skb) +{ + if (unlikely(!seg6_local_skb_has_lwtstate(skb))) { + kfree_skb(skb); + return -EINVAL; + } + + return seg6_local_input_core(net, sk, skb); +} + static int seg6_local_input(struct sk_buff *skb) { if (skb->protocol != htons(ETH_P_IPV6)) { @@ -1751,7 +1837,7 @@ static int seg6_local_input(struct sk_buff *skb) if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_IN, dev_net(skb->dev), NULL, skb, skb->dev, NULL, - seg6_local_input_core); + seg6_local_input_core_nf); return seg6_local_input_core(dev_net(skb->dev), NULL, skb); } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index e006a30360eae1..5c7ed38f1f56a7 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -449,7 +449,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, if (sock_owned_by_user(sk) && type != ICMPV6_PKT_TOOBIG) __NET_INC_STATS(net, LINUX_MIB_LOCKDROPPEDICMPS); - if (sk->sk_state == TCP_CLOSE) + if (sk->sk_state == TCP_CLOSE || inet_test_bit(DEFER_CONNECT, sk)) goto out; if (static_branch_unlikely(&ip6_min_hopcount)) { @@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst, &ireq->ir_v6_rmt_addr); fl6->daddr = ireq->ir_v6_rmt_addr; - if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts) - fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts)); + if (inet6_test_bit(REPFLOW, sk)) + fl6->flowlabel = tcp_rsk(req)->syn_flowlabel; tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ? (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) | @@ -607,7 +607,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst, static void tcp_v6_reqsk_destructor(struct request_sock *req) { - kfree(inet_rsk(req)->ipv6_opt); + kfree_rcu(inet_rsk(req)->ipv6_opt, rcu); consume_skb(inet_rsk(req)->pktopts); } @@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req, ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; ireq->ir_rmt_addr = LOOPBACK4_IPV6; ireq->ir_loc_addr = LOOPBACK4_IPV6; + tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb)); /* So that link locals have meaning */ if ((!sk_listener->sk_bound_dev_if || l3_slave) && diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 59f9872c355211..9dcefa16252235 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1249,8 +1249,11 @@ void udp_v6_early_demux(struct sk_buff *skb) skb->destructor = sock_pfree; dst = rcu_dereference(sk->sk_rx_dst); - if (dst) + /* A dual-stack socket can cache an IPv4 dst. */ + if (dst && dst->ops->family == AF_INET6) dst = dst_check(dst, sk->sk_rx_dst_cookie); + else + dst = NULL; if (dst) { /* set noref for now. * any place which wants to hold dst has to call diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c index 5ba875798aa414..ce13fe3c85b522 100644 --- a/net/iucv/af_iucv.c +++ b/net/iucv/af_iucv.c @@ -2080,11 +2080,20 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev, int err = NET_RX_SUCCESS; char nullstring[8]; + skb = skb_share_check(skb, GFP_ATOMIC); + if (!skb) + return NET_RX_SUCCESS; + if (!pskb_may_pull(skb, sizeof(*trans_hdr))) { kfree_skb(skb); return NET_RX_SUCCESS; } + if (skb_cow(skb, ETH_HLEN)) { + kfree_skb(skb); + return NET_RX_SUCCESS; + } + trans_hdr = iucv_trans_hdr(skb); EBCASC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName)); EBCASC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID)); diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 7e042a3e648ce0..0cd3e38bf662fc 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -315,10 +315,19 @@ EXPORT_SYMBOL_GPL(l2tp_v2_session_get); struct l2tp_session *l2tp_session_get(const struct net *net, struct sock *sk, int pver, u32 tunnel_id, u32 session_id) { + struct l2tp_session *session; + if (pver == L2TP_HDR_VER_2) return l2tp_v2_session_get(net, tunnel_id, session_id); - else - return l2tp_v3_session_get(net, sk, session_id); + + /* l2tp_v3_session_get() doesn't check sk if the ID hasn't collided */ + session = l2tp_v3_session_get(net, sk, session_id); + if (session && session->tunnel->sock != sk) { + l2tp_session_put(session); + return NULL; + } + + return session; } EXPORT_SYMBOL_GPL(l2tp_session_get); diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index a4e1f33c037797..c31540ff42e0cd 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -550,6 +550,8 @@ static u32 ieee80211_get_rate_duration(struct ieee80211_hw *hw, group = HE_GROUP_IDX(streams, status->he_gi, bw); break; case RX_ENC_EHT: + if (status->eht.gi > NL80211_RATE_INFO_EHT_GI_3_2) + return 0; streams = status->nss; idx = status->rate_idx; group = EHT_GROUP_IDX(streams, status->eht.gi, bw); diff --git a/net/mac80211/ap.c b/net/mac80211/ap.c index fe255891c35f09..0827966980a482 100644 --- a/net/mac80211/ap.c +++ b/net/mac80211/ap.c @@ -66,7 +66,8 @@ ieee80211_rx_eml_op_mode_notif(struct ieee80211_sub_if_data *sdata, struct sta_info *sta; int opt_len = 0; - if (!ieee80211_vif_is_mld(&sdata->vif)) + if (!ieee80211_vif_is_mld(&sdata->vif) || + status->link_id == IEEE80211_LINK_UNSPECIFIED) return; /* eMLSR and eMLMR can't be enabled at the same time */ diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c index 1f3e0765a8ab2e..d19ae7fbcb6afb 100644 --- a/net/mac80211/driver-ops.c +++ b/net/mac80211/driver-ops.c @@ -659,12 +659,14 @@ int drv_sta_statistics(struct ieee80211_local *local, &sdata->vif, sta, sinfo); } else { - ret = -EAGAIN; + ret = 0; if (local->ops->sta_statistics_atomic) ret = local->ops->sta_statistics_atomic(&local->hw, &sdata->vif, sta, sinfo); + else if (local->ops->sta_statistics) + ret = -EAGAIN; } trace_drv_return_int(local, ret); @@ -684,6 +686,8 @@ int drv_link_sta_statistics(struct ieee80211_local *local, if (!check_sdata_in_driver(sdata)) return 0; + trace_drv_link_sta_statistics(local, sdata, link_sta); + if (locked) { might_sleep(); lockdep_assert_wiphy(local->hw.wiphy); @@ -696,16 +700,18 @@ int drv_link_sta_statistics(struct ieee80211_local *local, link_sta, link_sinfo); } else { - ret = -EAGAIN; + ret = 0; - if (local->ops->sta_statistics_atomic) + if (local->ops->link_sta_statistics_atomic) ret = local->ops->link_sta_statistics_atomic(&local->hw, &sdata->vif, link_sta, link_sinfo); + else if (local->ops->link_sta_statistics) + ret = -EAGAIN; } trace_drv_return_int(local, ret); - return 0; + return ret; } diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c index d74b66426349ab..69c462c71e9256 100644 --- a/net/mac80211/ibss.c +++ b/net/mac80211/ibss.c @@ -669,6 +669,10 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) ifibss->state = IEEE80211_IBSS_MLME_SEARCH; netif_carrier_off(sdata->dev); + + sdata->vif.bss_conf.csa_active = false; + ieee80211_vif_unblock_queues_csa(sdata); + if (!sta_info_flush(sdata, -1)) synchronize_net(); @@ -680,6 +684,7 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) spin_unlock_bh(&ifibss->incomplete_lock); sta_info_free(local, sta); + atomic_dec(&ifibss->incomplete_sta_count); spin_lock_bh(&ifibss->incomplete_lock); } spin_unlock_bh(&ifibss->incomplete_lock); @@ -1173,9 +1178,18 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, band = chanctx_conf->def.chan->band; rcu_read_unlock(); + if (!atomic_add_unless(&ifibss->incomplete_sta_count, 1, + IEEE80211_IBSS_MAX_STA_ENTRIES)) { + net_info_ratelimited("%s: No room for a new IBSS STA entry %pM\n", + sdata->name, addr); + return; + } + sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); - if (!sta) + if (!sta) { + atomic_dec(&ifibss->incomplete_sta_count); return; + } /* make sure mandatory rates are always added */ sband = local->hw.wiphy->bands[band]; @@ -1626,8 +1640,13 @@ void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) list_del(&sta->list); spin_unlock_bh(&ifibss->incomplete_lock); - ieee80211_ibss_finish_sta(sta); - rcu_read_unlock(); + if (sdata->local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { + sta_info_free(sdata->local, sta); + } else { + ieee80211_ibss_finish_sta(sta); + rcu_read_unlock(); + } + atomic_dec(&ifibss->incomplete_sta_count); spin_lock_bh(&ifibss->incomplete_lock); } spin_unlock_bh(&ifibss->incomplete_lock); diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 1a6cbbb5a17d83..7a64aef6890d63 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -693,6 +693,7 @@ struct ieee80211_if_ibss { spinlock_t incomplete_lock; struct list_head incomplete_stations; + atomic_t incomplete_sta_count; enum { IEEE80211_IBSS_MLME_SEARCH, @@ -707,6 +708,7 @@ struct ieee80211_if_ibss { * @wrkq_flags: OCB deferred task action * @incomplete_lock: delayed STA insertion lock * @incomplete_stations: list of STAs waiting for delayed insertion + * @incomplete_sta_count: pending entries and reserved allocations * @joined: indication if the interface is connected to an OCB network */ struct ieee80211_if_ocb { @@ -715,6 +717,7 @@ struct ieee80211_if_ocb { spinlock_t incomplete_lock; struct list_head incomplete_stations; + atomic_t incomplete_sta_count; bool joined; }; diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index d0b0a503b229ae..63a371c79183bf 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1712,8 +1712,11 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local, break; status = IEEE80211_SKB_RXCB(skb); - link_sta = wiphy_dereference(local->hw.wiphy, - sta->link[status->link_id]); + if (status->link_id == IEEE80211_LINK_UNSPECIFIED) + link_sta = &sta->deflink; + else + link_sta = wiphy_dereference(local->hw.wiphy, + sta->link[status->link_id]); if (link_sta) ieee80211_ht_handle_chanwidth_notif(local, sdata, sta, link_sta, chanwidth, diff --git a/net/mac80211/link.c b/net/mac80211/link.c index ce1c95b40cd9a6..f43c0dec8cc9f4 100644 --- a/net/mac80211/link.c +++ b/net/mac80211/link.c @@ -192,6 +192,7 @@ struct link_container { static void ieee80211_tear_down_links(struct ieee80211_sub_if_data *sdata, struct link_container **links, u16 mask) { + struct ieee80211_link_data *stop[IEEE80211_MLD_MAX_NUM_LINKS] = {}; struct ieee80211_link_data *link; LIST_HEAD(keys); unsigned int link_id; @@ -206,11 +207,16 @@ static void ieee80211_tear_down_links(struct ieee80211_sub_if_data *sdata, continue; ieee80211_remove_link_keys(link, &keys); ieee80211_link_debugfs_remove(link); - ieee80211_link_stop(link); + stop[link_id] = link; } + /* drain RCU readers before cancelling work they may queue */ synchronize_rcu(); + for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) + if (stop[link_id]) + ieee80211_link_stop(stop[link_id]); + ieee80211_free_key_list(sdata->local, &keys); } @@ -291,6 +297,7 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata, { u16 old_links = sdata->vif.valid_links; u16 old_active = sdata->vif.active_links; + u16 old_dormant = sdata->vif.dormant_links; unsigned long add = new_links & ~old_links; unsigned long rem = old_links & ~new_links; unsigned long sta_rem = rem; @@ -400,7 +407,9 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata, /* restore config */ memcpy(sdata->link, old_data, sizeof(old_data)); memcpy(sdata->vif.link_conf, old, sizeof(old)); - ieee80211_set_vif_links_bitmaps(sdata, old_links, dormant_links); + ieee80211_set_vif_links_bitmaps(sdata, old_links, old_dormant); + /* drain RCU readers before cancelling work they may queue */ + synchronize_rcu(); for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) { ieee80211_link_debugfs_remove(&links[link_id]->data); ieee80211_link_stop(&links[link_id]->data); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 6ec45a9f722145..b5efc6ccc98535 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -7872,15 +7872,15 @@ static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy, sdata->u.mgd.ttlm_info.switch_time = 0; } -static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, - struct ieee802_11_elems *elems, - u64 beacon_ts) +static bool ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, + struct ieee802_11_elems *elems, + u64 beacon_ts) { u8 i; int ret; if (!ieee80211_vif_is_mld(&sdata->vif)) - return; + return true; if (!elems->ttlm_num) { if (sdata->u.mgd.ttlm_info.switch_time) { @@ -7898,14 +7898,14 @@ static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, 0); if (ret) { sdata_info(sdata, "Failed setting valid/dormant links\n"); - return; + return true; } ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS); } memset(&sdata->u.mgd.ttlm_info, 0, sizeof(sdata->u.mgd.ttlm_info)); - return; + return true; } for (i = 0; i < elems->ttlm_num; i++) { @@ -7917,7 +7917,7 @@ static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, if (res) { __ieee80211_disconnect(sdata); - return; + return false; } if (ttlm_info.switch_time) { @@ -7942,7 +7942,7 @@ static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, * switch the AP will continue to announce it anyway. */ if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW) - return; + return true; delay_usec = ieee80211_tu_to_usec(delay); @@ -7961,9 +7961,11 @@ static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, wiphy_hrtimer_work_queue(sdata->local->hw.wiphy, &sdata->u.mgd.ttlm_work, us_to_ktime(delay_usec)); - return; + return true; } } + + return true; } static void @@ -8486,8 +8488,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link, elems->cisco_dtpc_elem); ieee80211_ml_reconfiguration(sdata, elems); - ieee80211_process_adv_ttlm(sdata, elems, - le64_to_cpu(mgmt->u.beacon.timestamp)); + if (!ieee80211_process_adv_ttlm(sdata, elems, + le64_to_cpu(mgmt->u.beacon.timestamp))) + goto free; apply: ieee80211_link_info_change_notify(sdata, link, changed); @@ -11894,10 +11897,12 @@ void ieee80211_sta_rx_queued_frame(struct ieee80211_sub_if_data *sdata, rx_status = (struct ieee80211_rx_status *) skb->cb; fc = le16_to_cpu(mgmt->frame_control); - link = sdata_dereference(sdata->link[rx_status->link_id], - sdata); - if (!link) - return; + if (rx_status->link_id != IEEE80211_LINK_UNSPECIFIED) { + link = sdata_dereference(sdata->link[rx_status->link_id], + sdata); + if (!link) + return; + } switch (fc & IEEE80211_FCTL_STYPE) { case IEEE80211_STYPE_BEACON: diff --git a/net/mac80211/ocb.c b/net/mac80211/ocb.c index e9bf4ba3e60b7b..90c43eec61e32e 100644 --- a/net/mac80211/ocb.c +++ b/net/mac80211/ocb.c @@ -70,9 +70,18 @@ void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata, band = chanctx_conf->def.chan->band; rcu_read_unlock(); + if (!atomic_add_unless(&ifocb->incomplete_sta_count, 1, + IEEE80211_OCB_MAX_STA_ENTRIES)) { + net_info_ratelimited("%s: No room for a new OCB STA entry %pM\n", + sdata->name, addr); + return; + } + sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); - if (!sta) + if (!sta) { + atomic_dec(&ifocb->incomplete_sta_count); return; + } /* Add only mandatory rates for now */ sband = local->hw.wiphy->bands[band]; @@ -139,8 +148,13 @@ void ieee80211_ocb_work(struct ieee80211_sub_if_data *sdata) list_del(&sta->list); spin_unlock_bh(&ifocb->incomplete_lock); - ieee80211_ocb_finish_sta(sta); - rcu_read_unlock(); + if (sdata->local->num_sta >= IEEE80211_OCB_MAX_STA_ENTRIES) { + sta_info_free(sdata->local, sta); + } else { + ieee80211_ocb_finish_sta(sta); + rcu_read_unlock(); + } + atomic_dec(&ifocb->incomplete_sta_count); spin_lock_bh(&ifocb->incomplete_lock); } spin_unlock_bh(&ifocb->incomplete_lock); @@ -224,6 +238,7 @@ int ieee80211_ocb_leave(struct ieee80211_sub_if_data *sdata) spin_unlock_bh(&ifocb->incomplete_lock); sta_info_free(local, sta); + atomic_dec(&ifocb->incomplete_sta_count); spin_lock_bh(&ifocb->incomplete_lock); } spin_unlock_bh(&ifocb->incomplete_lock); diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index ecee9348c70d4e..f8cfd04c0c6c33 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -2905,9 +2905,6 @@ ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata, if (!sta) return false; - if (skb_linearize(skb)) - return false; - tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]); if (tid_tx) { @@ -2918,6 +2915,10 @@ ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata, tid_tx->last_tx = jiffies; } + /* this function must not fail after this */ + if (skb_linearize(skb)) + return false; + ieee80211_aggr_check(sdata, sta, skb); if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen, @@ -4232,6 +4233,7 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, while ((skb = __skb_dequeue(frames))) { struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); + int link_id; /* * Most fields are valid across frames. However, @@ -4240,18 +4242,27 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, * and link_sta accordingly. */ rx->skb = skb; + link_id = status->link_id == IEEE80211_LINK_UNSPECIFIED ? -1 : status->link_id; if (ieee80211_vif_is_mld(&rx->sdata->vif) && - unlikely(rx->link_id != status->link_id)) { + unlikely(rx->link_id != link_id)) { + rx->link_id = link_id; + + if (link_id >= 0) + rx->link = rcu_dereference(rx->sdata->link[link_id]); + else + rx->link = &rx->sdata->deflink; + if (rx->sta) { - rx->link_sta = - rcu_dereference(rx->sta->link[rx->link_id]); + if (WARN_ON_ONCE(link_id < 0)) + rx->link_sta = NULL; + else + rx->link_sta = + rcu_dereference(rx->sta->link[link_id]); - /* Link got disabled, just use deflink */ + /* Link disabled or invalid, just use deflink */ if (!rx->link_sta) rx->link_sta = &rx->sta->deflink; } - rx->link_id = status->link_id; - rx->link = rcu_dereference(rx->sdata->link[status->link_id]); } if (WARN_ON_ONCE(!rx->link)) { @@ -5184,7 +5195,8 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, } status = IEEE80211_SKB_RXCB(skb); - status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + status->link_id = + rx->link_id < 0 ? IEEE80211_LINK_UNSPECIFIED : rx->link_id; ieee80211_rx_8023(rx, fast_rx, orig_len); @@ -5255,7 +5267,8 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, } status = IEEE80211_SKB_RXCB(rx->skb); - status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + status->link_id = + rx->link_id < 0 ? IEEE80211_LINK_UNSPECIFIED : rx->link_id; if (ieee80211_is_s1g_beacon(hdr->frame_control)) { ieee80211_invoke_rx_handlers(rx); @@ -5348,6 +5361,29 @@ static bool ieee80211_rx_valid_freq(int freq, struct ieee80211_link_data *link) return freq == conf->def.chan->center_freq; } +static struct ieee80211_link_data * +ieee80211_link_from_freq(struct ieee80211_sub_if_data *sdata, int freq) +{ + struct ieee80211_link_data *link; + + if (ieee80211_vif_is_mld(&sdata->vif)) { + struct ieee80211_chanctx_conf *conf; + + for_each_link_data_rcu(sdata, link) { + conf = rcu_dereference(link->conf->chanctx_conf); + if (!conf || !conf->def.chan) + continue; + + if (freq == conf->def.chan->center_freq) + return link; + } + + return &sdata->deflink; + } + + return &sdata->deflink; +} + /* * This is the actual Rx frames handler. as it belongs to Rx path it must * be called with rcu_read_lock protection. @@ -5508,6 +5544,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, list_for_each_entry_rcu(sdata, &local->interfaces, list) { struct ieee80211_link_data *link = NULL; + const u8 *addr = hdr->addr2; if (!ieee80211_sdata_running(sdata)) continue; @@ -5519,16 +5556,32 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, link_sta = NULL; link = NULL; + /* + * Switch to do the STA lookup using the non-transmitted BSSID + * for beacon frames from the transmitted BSSID. This ensures + * that the keys for beacon protection are available during + * later processing. + */ + if (ieee80211_is_beacon(fc) && + sdata->vif.type == NL80211_IFTYPE_STATION) { + link = ieee80211_link_from_freq(sdata, status->freq); + + if (link->conf->nontransmitted && + ether_addr_equal(addr, + link->conf->transmitter_bssid)) + addr = link->conf->bssid; + } + /* Try to resolve the station */ if (!ieee80211_vif_is_mld(&sdata->vif)) { - sta = sta_info_get_bss(sdata, hdr->addr2); + sta = sta_info_get_bss(sdata, addr); if (sta) { link_sta = &sta->deflink; link = &sdata->deflink; } } else { - link_sta = link_sta_info_get_bss(sdata, hdr->addr2); + link_sta = link_sta_info_get_bss(sdata, addr); if (link_sta) link = rcu_dereference(sdata->link[link_sta->link_id]); @@ -5555,26 +5608,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, } /* No station, try to resolve the link and RX */ - if (ieee80211_vif_is_mld(&sdata->vif)) { - struct ieee80211_chanctx_conf *conf; - bool found = false; - - for_each_link_data_rcu(sdata, link) { - conf = rcu_dereference(link->conf->chanctx_conf); - if (!conf || !conf->def.chan) - continue; - - if (status->freq == conf->def.chan->center_freq) { - found = true; - break; - } - } - - if (!found) - link = &sdata->deflink; - } else { - link = &sdata->deflink; - } + link = ieee80211_link_from_freq(sdata, status->freq); if (rx_data_pending) { ieee80211_prepare_and_rx_handle(&rx, skb, false); diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index 8a66d2e020f942..69eb991d9b5a43 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -214,8 +214,9 @@ ieee80211_bss_info_update(struct ieee80211_local *local, if (ieee80211_vif_is_mld(&scan_sdata->vif)) { s8 link_id = rx_status->link_id; - link_conf = - rcu_dereference(scan_sdata->vif.link_conf[link_id]); + if (link_id != IEEE80211_LINK_UNSPECIFIED) + link_conf = + rcu_dereference(scan_sdata->vif.link_conf[link_id]); } else { link_conf = &scan_sdata->vif.bss_conf; } diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c index 68bd64328937d6..8ae01c277fd265 100644 --- a/net/mac80211/tdls.c +++ b/net/mac80211/tdls.c @@ -2021,7 +2021,7 @@ void ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) { - struct ieee80211_tdls_data *tf = (void *)skb->data; + struct ieee80211_tdls_data *tf; struct wiphy *wiphy = sdata->local->hw.wiphy; lockdep_assert_wiphy(wiphy); @@ -2037,6 +2037,7 @@ ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata, * The packet/size was already validated by mac80211 Rx path, only look * at the action type. */ + tf = (void *)skb->data; switch (tf->action_code) { case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: ieee80211_process_tdls_channel_switch_req(sdata, skb); diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index e9b6a0415d6a94..6e70e2046d1a12 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -1164,6 +1164,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, struct sk_buff *purge_skb = NULL; if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { + info->flags |= IEEE80211_TX_CTL_AMPDU; reset_agg_timer = true; } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { /* @@ -1195,6 +1196,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, if (!tid_tx) { /* do nothing, let packet pass through */ } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { + info->flags |= IEEE80211_TX_CTL_AMPDU; reset_agg_timer = true; } else { queued = true; @@ -2589,6 +2591,12 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, /* remove the injection radiotap header */ skb_pull(skb, len_rthdr); + /* FCS removal may have shortened the 802.11 header. */ + hdrlen = max_t(int, hdrlen, + offsetofend(struct ieee80211_hdr, addr1)); + if (skb_headlen(skb) < hdrlen) + goto fail_rcu; + ieee80211_xmit(sdata, NULL, skb); rcu_read_unlock(); diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c index 8af5e2b3c8d12d..aa22c086071265 100644 --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -292,7 +292,7 @@ static int mctp_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, u8 type; int rc; - if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK)) + if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK | MSG_CMSG_COMPAT)) return -EOPNOTSUPP; skb = skb_recv_datagram(sk, flags, &rc); diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 64aa7a516a23ed..02e785a14b8a5c 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1122,9 +1122,9 @@ static void ack_update_msk(struct mptcp_sock *msk, struct sock *ssk, struct mptcp_options_received *mp_opt) { - u64 new_wnd_end, new_snd_una, snd_nxt = READ_ONCE(msk->snd_nxt); + u64 new_wnd_end, new_snd_una, old_snd_una; struct sock *sk = (struct sock *)msk; - u64 old_snd_una; + u64 snd_nxt; mptcp_data_lock(sk); @@ -1133,10 +1133,14 @@ static void ack_update_msk(struct mptcp_sock *msk, * more dangerous than missing an ack */ old_snd_una = msk->snd_una; + snd_nxt = READ_ONCE(msk->snd_nxt); new_snd_una = mptcp_expand_seq(old_snd_una, mp_opt->data_ack, mp_opt->ack64); - /* ACK for data not even sent yet? Ignore.*/ - if (unlikely(after64(new_snd_una, snd_nxt))) + /* The active-open state sync can defer the snd_nxt update. Do not + * accept an ACK against a reversed interval, or beyond snd_nxt. + */ + if (unlikely(before64(snd_nxt, old_snd_una) || + after64(new_snd_una, snd_nxt))) new_snd_una = old_snd_una; new_wnd_end = new_snd_una + tcp_sk(ssk)->snd_wnd; diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 1a775081323549..f7396628490e3c 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -906,6 +906,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, * old status is known (TCP_CLOSE). */ inet_sk_state_store(newsk, TCP_LISTEN); + sock_set_flag(newsk, SOCK_RCU_FREE); lock_sock(ssk); WRITE_ONCE(mptcp_subflow_ctx(ssk)->pm_listener, true); err = __inet_listen_sk(ssk, backlog); diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 7a22e9388e0e9a..8968db58083ef4 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1920,10 +1920,12 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, msg->msg_flags = saved_flags; release_sock(ssk); + inet_clear_bit(DEFER_CONNECT, sk); + /* do the blocking bits of inet_stream_connect outside the ssk socket lock */ if (ret == -EINPROGRESS && !(msg->msg_flags & MSG_DONTWAIT)) { ret = __inet_stream_connect(sk->sk_socket, msg->msg_name, - msg->msg_namelen, msg->msg_flags, 1); + msg->msg_namelen, msg->msg_flags, true); /* Keep the same behaviour of plain TCP: zero the copied bytes in * case of any error, except timeout or signal @@ -1941,7 +1943,6 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, sk->sk_socket->state = SS_UNCONNECTED; } } - inet_clear_bit(DEFER_CONNECT, sk); return ret; } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 78e886b202585f..00677fb3efcdc9 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -379,6 +379,10 @@ static void subflow_prep_synack(const struct sock *sk, struct request_sock *req, struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); struct inet_request_sock *ireq = inet_rsk(req); + /* MP_JOIN cannot use TFO, do not send a cookie in the SYN/ACK */ + if (foc && mptcp_subflow_rsk(req)->mp_join) + foc->len = -1; + /* clear tstamp_ok, as needed depending on cookie */ if (foc && foc->len > -1) ireq->tstamp_ok = 0; @@ -887,6 +891,13 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, fallback = true; } else if (subflow_req->mp_join) { + /* a SYN skb here comes from TFO, which MP_JOIN cannot use: just + * fall back to the regular path. + */ + if ((TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_ACK)) == + TCPHDR_SYN) + return NULL; + mptcp_get_options(skb, &mp_opt); if (!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK)) fallback = true; diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index 9c91872a2921f3..33921dc169e3d4 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -820,9 +820,8 @@ static int ncsi_rsp_handler_gc(struct ncsi_request *nr) nc->mac_filter.n_mc = rsp->mc_cnt; nc->mac_filter.n_mixed = rsp->mixed_cnt; - nc->vlan_filter.vids = kcalloc(rsp->vlan_cnt, - sizeof(*nc->vlan_filter.vids), - GFP_ATOMIC); + nc->vlan_filter.vids = kzalloc_objs(*nc->vlan_filter.vids, + rsp->vlan_cnt, GFP_ATOMIC); if (!nc->vlan_filter.vids) return -ENOMEM; /* Set VLAN filters active so they are cleared in the first diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c index 11cbdbaf561daf..2c1b47702da213 100644 --- a/net/netfilter/ipvs/ip_vs_app.c +++ b/net/netfilter/ipvs/ip_vs_app.c @@ -242,7 +242,7 @@ void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app) } list_del(&a->a_list); - kfree(a); + kfree_rcu(a, rcu_head); /* decrease the module use count */ ip_vs_use_count_dec(); diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index fd503f0efb5783..8a3c880fdb266e 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -2502,12 +2502,12 @@ static int __net_init __ip_vs_init(struct net *net) if (ip_vs_estimator_net_init(ipvs) < 0) goto estimator_fail; - if (ip_vs_control_net_init(ipvs) < 0) - goto control_fail; - if (ip_vs_protocol_net_init(ipvs) < 0) goto protocol_fail; + if (ip_vs_control_net_init(ipvs) < 0) + goto control_fail; + if (ip_vs_app_net_init(ipvs) < 0) goto app_fail; @@ -2527,10 +2527,10 @@ static int __net_init __ip_vs_init(struct net *net) conn_fail: ip_vs_app_net_cleanup(ipvs); app_fail: - ip_vs_protocol_net_cleanup(ipvs); -protocol_fail: ip_vs_control_net_cleanup(ipvs); control_fail: + ip_vs_protocol_net_cleanup(ipvs); +protocol_fail: ip_vs_estimator_net_cleanup(ipvs); estimator_fail: net->ipvs = NULL; @@ -2547,8 +2547,8 @@ static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list) ipvs = net_ipvs(net); ip_vs_conn_net_cleanup(ipvs); ip_vs_app_net_cleanup(ipvs); - ip_vs_protocol_net_cleanup(ipvs); ip_vs_control_net_cleanup(ipvs); + ip_vs_protocol_net_cleanup(ipvs); ip_vs_estimator_net_cleanup(ipvs); IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen); net->ipvs = NULL; diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c index 64bc440b1181f1..b05dc8858d094d 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c @@ -701,9 +701,9 @@ static int ct_sip_parse_transport(struct nf_conn *ct, const char *dptr, if (ct_sip_parse_param(ct, dptr, dataoff, datalen, "transport=", &matchoff, &matchlen)) { - if (!strncasecmp(dptr + matchoff, "TCP", strlen("TCP"))) + if (matchlen >= 3 && !strncasecmp(dptr + matchoff, "TCP", 3)) *proto = IPPROTO_TCP; - else if (!strncasecmp(dptr + matchoff, "UDP", strlen("UDP"))) + else if (matchlen >= 3 && !strncasecmp(dptr + matchoff, "UDP", 3)) *proto = IPPROTO_UDP; else return 0; diff --git a/net/netfilter/nf_dup_netdev.c b/net/netfilter/nf_dup_netdev.c index c6bd5c29bed66d..918716629c1556 100644 --- a/net/netfilter/nf_dup_netdev.c +++ b/net/netfilter/nf_dup_netdev.c @@ -12,6 +12,7 @@ #include #include #include +#include static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev, enum nf_dev_hooks hook) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 0d72dc8ae47a13..2aa2647ed9df06 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -544,6 +544,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct) switch (l4proto) { case IPPROTO_UDP: + case IPPROTO_GRE: new_timeout = NF_CT_DAY; break; case IPPROTO_TCP: diff --git a/net/netfilter/nf_nat_masquerade.c b/net/netfilter/nf_nat_masquerade.c index 4de6e0a517015b..c2a85bd84af131 100644 --- a/net/netfilter/nf_nat_masquerade.c +++ b/net/netfilter/nf_nat_masquerade.c @@ -62,8 +62,7 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum, nat->masq_index = out->ifindex; /* Transfer from original range. */ - memset(&newrange.min_addr, 0, sizeof(newrange.min_addr)); - memset(&newrange.max_addr, 0, sizeof(newrange.max_addr)); + memset(&newrange, 0, sizeof(newrange)); newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS; newrange.min_addr.ip = newsrc; newrange.max_addr.ip = newsrc; @@ -242,6 +241,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range, if (nat) nat->masq_index = out->ifindex; + memset(&newrange, 0, sizeof(newrange)); newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS; newrange.min_addr.in6 = src; newrange.max_addr.in6 = src; diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c index 166d05e994ac6c..bd603e3a99a59d 100644 --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c @@ -219,6 +219,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, *entry = (struct nf_queue_entry) { .skb = skb, .skb_dev = skb->dev, + .in_nf_duplicate = current->in_nf_duplicate, .state = *state, .hook_index = index, .size = sizeof(*entry) + route_key_size, diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 59ac623e6805f1..8b94b5e7dbdbd0 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -760,16 +760,6 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) if (trans == NULL) return -ENOMEM; - if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) { - flow = nft_flow_rule_create(ctx->net, rule); - if (IS_ERR(flow)) { - nft_trans_destroy(trans); - return PTR_ERR(flow); - } - - nft_trans_flow_rule(trans) = flow; - } - err = nf_tables_delrule_deactivate(ctx, rule); if (err < 0) { nft_trans_destroy(trans); @@ -777,6 +767,14 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) } nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_PREPARE); + if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) { + flow = nft_flow_rule_create(ctx->net, rule); + if (IS_ERR(flow)) + return PTR_ERR(flow); + + nft_trans_flow_rule(trans) = flow; + } + return 0; } @@ -4570,8 +4568,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info, err_destroy_flow_rule: nft_use_dec_restore(&chain->use); err_destroy_flow: - if (flow) - nft_flow_rule_destroy(flow); + nft_flow_rule_destroy(flow); err_release_rule: nft_rule_expr_deactivate(&ctx, rule, NFT_TRANS_PREPARE_ERROR); nf_tables_rule_destroy(&ctx, rule); diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c index 0ac3c26dfb3d16..48b9e58e0c44f1 100644 --- a/net/netfilter/nf_tables_offload.c +++ b/net/netfilter/nf_tables_offload.c @@ -148,6 +148,9 @@ void nft_flow_rule_destroy(struct nft_flow_rule *flow) struct flow_action_entry *entry; int i; + if (!flow) + return; + flow_action_for_each(i, entry, &flow->rule->action) { switch (entry->id) { case FLOW_ACTION_REDIRECT: diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 90d887546f7db1..a8aa7ad832c3f3 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -365,21 +366,30 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) const struct nf_hook_entry *hook_entry; const struct nf_hook_entries *hooks; struct sk_buff *skb = entry->skb; + bool old_in_nf_duplicate; const struct net *net; unsigned int i; int err; u8 pf; + DEBUG_NET_WARN_ONCE(current->in_nf_duplicate && + !entry->in_nf_duplicate, + "%s called with unexpected duplication guard", + __func__); + local_bh_disable(); + old_in_nf_duplicate = current->in_nf_duplicate; + net = entry->state.net; pf = entry->state.pf; + current->in_nf_duplicate = entry->in_nf_duplicate; hooks = nf_hook_entries_head(net, pf, entry->state.hook); i = entry->hook_index; if (!hooks || i >= hooks->num_hook_entries) { kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP); nf_queue_entry_free(entry); - return; + goto out; } hook_entry = &hooks->hooks[i]; @@ -402,9 +412,7 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) switch (verdict & NF_VERDICT_MASK) { case NF_ACCEPT: case NF_STOP: - local_bh_disable(); entry->state.okfn(entry->state.net, entry->state.sk, skb); - local_bh_enable(); break; case NF_QUEUE: err = nf_queue(skb, &entry->state, i, verdict); @@ -418,6 +426,9 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) } nf_queue_entry_free(entry); +out: + current->in_nf_duplicate = old_in_nf_duplicate; + local_bh_enable(); } /* return true if the entry has an unconfirmed conntrack attached that isn't owned by us diff --git a/net/netfilter/nft_fwd_netdev.c b/net/netfilter/nft_fwd_netdev.c index a48c2f765bbaad..7447da931a9576 100644 --- a/net/netfilter/nft_fwd_netdev.c +++ b/net/netfilter/nft_fwd_netdev.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/net/netfilter/nft_set_rbtree.c b/net/netfilter/nft_set_rbtree.c index fbe1750f1ca232..9d685899da7018 100644 --- a/net/netfilter/nft_set_rbtree.c +++ b/net/netfilter/nft_set_rbtree.c @@ -953,7 +953,8 @@ static void nft_rbtree_gc_queue(struct nft_set *set) } gc = nft_trans_gc_catchall_sync(gc); - nft_trans_gc_queue_sync_done(gc); + if (gc) + nft_trans_gc_queue_sync_done(gc); } static u64 nft_rbtree_privsize(const struct nlattr * const nla[], diff --git a/net/netfilter/xt_NETMAP.c b/net/netfilter/xt_NETMAP.c index 7da065a472e0ec..8bcb3f716d68aa 100644 --- a/net/netfilter/xt_NETMAP.c +++ b/net/netfilter/xt_NETMAP.c @@ -44,6 +44,7 @@ netmap_tg6(struct sk_buff *skb, const struct xt_action_param *par) netmask.ip6[i]; } + memset(&newrange, 0, sizeof(newrange)); newrange.flags = range->flags | NF_NAT_RANGE_MAP_IPS; newrange.min_addr = new_addr; newrange.max_addr = new_addr; @@ -91,8 +92,7 @@ netmap_tg4(struct sk_buff *skb, const struct xt_action_param *par) new_ip = ip_hdr(skb)->saddr & ~netmask; new_ip |= mr->range[0].min_ip & netmask; - memset(&newrange.min_addr, 0, sizeof(newrange.min_addr)); - memset(&newrange.max_addr, 0, sizeof(newrange.max_addr)); + memset(&newrange, 0, sizeof(newrange)); newrange.flags = mr->range[0].flags | NF_NAT_RANGE_MAP_IPS; newrange.min_addr.ip = new_ip; newrange.max_addr.ip = new_ip; diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 57ac455bc33178..f4b443ed42ba83 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -1077,7 +1077,7 @@ static void *dl_seq_start(struct seq_file *s, loff_t *pos) if (*pos >= htable->cfg.size) return NULL; - bucket = kmalloc(sizeof(unsigned int), GFP_ATOMIC); + bucket = kmalloc_obj(unsigned int, GFP_ATOMIC); if (!bucket) return ERR_PTR(-ENOMEM); diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c index 55f1f2d89952d0..00cccf003cff5e 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -650,14 +650,15 @@ static void __net_exit recent_proc_net_exit(struct net *net) /* recent_net_exit() is called before recent_mt_destroy(). Make sure * that the parent xt_recent proc entry is empty before trying to - * remove it. + * remove it. Use recent_mutex instead of recent_lock since + * remove_proc_entry() may sleep. */ - spin_lock_bh(&recent_lock); + mutex_lock(&recent_mutex); list_for_each_entry(t, &recent_net->tables, list) remove_proc_entry(t->name, recent_net->xt_recent); recent_net->xt_recent = NULL; - spin_unlock_bh(&recent_lock); + mutex_unlock(&recent_mutex); remove_proc_entry("xt_recent", net->proc_net); } diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index b080e666523f9c..a8e66c2ddf4951 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -185,16 +185,16 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, break; } } - doi_def->map.std->lvl.local = kcalloc(doi_def->map.std->lvl.local_size, - sizeof(u32), - GFP_KERNEL | __GFP_NOWARN); + doi_def->map.std->lvl.local = kzalloc_objs(u32, + doi_def->map.std->lvl.local_size, + GFP_KERNEL | __GFP_NOWARN); if (doi_def->map.std->lvl.local == NULL) { ret_val = -ENOMEM; goto add_std_failure; } - doi_def->map.std->lvl.cipso = kcalloc(doi_def->map.std->lvl.cipso_size, - sizeof(u32), - GFP_KERNEL | __GFP_NOWARN); + doi_def->map.std->lvl.cipso = kzalloc_objs(u32, + doi_def->map.std->lvl.cipso_size, + GFP_KERNEL | __GFP_NOWARN); if (doi_def->map.std->lvl.cipso == NULL) { ret_val = -ENOMEM; goto add_std_failure; @@ -260,18 +260,16 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, break; } } - doi_def->map.std->cat.local = kcalloc( - doi_def->map.std->cat.local_size, - sizeof(u32), - GFP_KERNEL | __GFP_NOWARN); + doi_def->map.std->cat.local = kzalloc_objs(u32, + doi_def->map.std->cat.local_size, + GFP_KERNEL | __GFP_NOWARN); if (doi_def->map.std->cat.local == NULL) { ret_val = -ENOMEM; goto add_std_failure; } - doi_def->map.std->cat.cipso = kcalloc( - doi_def->map.std->cat.cipso_size, - sizeof(u32), - GFP_KERNEL | __GFP_NOWARN); + doi_def->map.std->cat.cipso = kzalloc_objs(u32, + doi_def->map.std->cat.cipso_size, + GFP_KERNEL | __GFP_NOWARN); if (doi_def->map.std->cat.cipso == NULL) { ret_val = -ENOMEM; goto add_std_failure; diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index 3583fa63dd01fd..c0eddb6afef3c8 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -1045,18 +1045,18 @@ int netlbl_sock_setattr(struct sock *sk, * ensuring that @sk is locked. * */ -void netlbl_sock_delattr(struct sock *sk) +int netlbl_sock_delattr(struct sock *sk) { switch (sk->sk_family) { case AF_INET: - cipso_v4_sock_delattr(sk); - break; + return cipso_v4_sock_delattr(sk); #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: calipso_sock_delattr(sk); break; #endif /* IPv6 */ } + return 0; } /** @@ -1156,8 +1156,7 @@ int netlbl_conn_setattr(struct sock *sk, case NETLBL_NLTYPE_UNLABELED: /* just delete the protocols we support for right now * but we could remove other protocols if needed */ - netlbl_sock_delattr(sk); - ret_val = 0; + ret_val = netlbl_sock_delattr(sk); break; default: ret_val = -ENOENT; @@ -1185,8 +1184,7 @@ int netlbl_conn_setattr(struct sock *sk, case NETLBL_NLTYPE_UNLABELED: /* just delete the protocols we support for right now * but we could remove other protocols if needed */ - netlbl_sock_delattr(sk); - ret_val = 0; + ret_val = netlbl_sock_delattr(sk); break; default: ret_val = -ENOENT; @@ -1234,8 +1232,7 @@ int netlbl_req_setattr(struct request_sock *req, entry->cipso, secattr); break; case NETLBL_NLTYPE_UNLABELED: - netlbl_req_delattr(req); - ret_val = 0; + ret_val = netlbl_req_delattr(req); break; default: ret_val = -ENOENT; @@ -1255,8 +1252,7 @@ int netlbl_req_setattr(struct request_sock *req, entry->calipso, secattr); break; case NETLBL_NLTYPE_UNLABELED: - netlbl_req_delattr(req); - ret_val = 0; + ret_val = netlbl_req_delattr(req); break; default: ret_val = -ENOENT; @@ -1280,18 +1276,18 @@ int netlbl_req_setattr(struct request_sock *req, * Remove all the NetLabel labeling from @req. * */ -void netlbl_req_delattr(struct request_sock *req) +int netlbl_req_delattr(struct request_sock *req) { switch (req->rsk_ops->family) { case AF_INET: - cipso_v4_req_delattr(req); - break; + return cipso_v4_req_delattr(req); #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: calipso_req_delattr(req); break; #endif /* IPv6 */ } + return 0; } /** diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 1281c42a3456ae..69bb951b5fb8a9 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1047,8 +1047,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr_unsized *addr, netlink_insert(sk, nladdr->nl_pid) : netlink_autobind(sock); if (err) { + netlink_unlock_table(); netlink_undo_bind(BITS_PER_TYPE(u32), groups, sk); - goto unlock; + return err; } } diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c index b0ab4f5acbce88..02024c94237f36 100644 --- a/net/nfc/nci/rsp.c +++ b/net/nfc/nci/rsp.c @@ -230,9 +230,8 @@ static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, conn_info = ndev->rf_conn_info; if (!conn_info) { - conn_info = devm_kzalloc(&ndev->nfc_dev->dev, - sizeof(struct nci_conn_info), - GFP_KERNEL); + conn_info = devm_kzalloc_obj(&ndev->nfc_dev->dev, + struct nci_conn_info); if (!conn_info) { status = NCI_STATUS_REJECTED; goto exit; @@ -314,16 +313,14 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev, if (status == NCI_STATUS_OK) { rsp = (struct nci_core_conn_create_rsp *)skb->data; - conn_info = devm_kzalloc(&ndev->nfc_dev->dev, - sizeof(*conn_info), GFP_KERNEL); + conn_info = devm_kzalloc_obj(&ndev->nfc_dev->dev, *conn_info); if (!conn_info) { status = NCI_STATUS_REJECTED; goto exit; } - conn_info->dest_params = devm_kzalloc(&ndev->nfc_dev->dev, - sizeof(struct dest_spec_params), - GFP_KERNEL); + conn_info->dest_params = devm_kzalloc_obj(&ndev->nfc_dev->dev, + struct dest_spec_params); if (!conn_info->dest_params) { status = NCI_STATUS_REJECTED; goto free_conn_info; diff --git a/net/nfc/nci/spi.c b/net/nfc/nci/spi.c index 6a93533c480e65..b9c4120590f74a 100644 --- a/net/nfc/nci/spi.c +++ b/net/nfc/nci/spi.c @@ -127,7 +127,7 @@ struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, { struct nci_spi *nspi; - nspi = devm_kzalloc(&spi->dev, sizeof(struct nci_spi), GFP_KERNEL); + nspi = devm_kzalloc_obj(&spi->dev, struct nci_spi); if (!nspi) return NULL; diff --git a/net/nsh/nsh.c b/net/nsh/nsh.c index bfb7758063f315..dd4de50fc38c39 100644 --- a/net/nsh/nsh.c +++ b/net/nsh/nsh.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,12 @@ static struct sk_buff *nsh_gso_segment(struct sk_buff *skb, skb_reset_network_header(skb); + /* NSH can carry NSH (directly, or in an inner Ethernet frame): + * limit the recursion, as IPv4 and IPv6 do. + */ + if (unlikely(gso_recursion_inc_test(skb, IP_TUNNEL_RECURSION_LIMIT))) + goto out; + outer_proto = skb->protocol; outer_hlen = skb_mac_header_len(skb); mac_len = skb->mac_len; diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c index 1c4f3a0790443a..3734416b518d71 100644 --- a/net/openvswitch/flow.c +++ b/net/openvswitch/flow.c @@ -369,11 +369,28 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh, return; } + if (next_type == IPPROTO_FRAGMENT) { + struct frag_hdr _fh, *fh; + + fh = skb_header_pointer(skb, start, sizeof(_fh), &_fh); + if (!fh) + break; + /* Only the first fragment has the headers that follow. */ + if (fh->frag_off & htons(IP6_OFFSET)) + break; + start += sizeof(_fh); + next_type = fh->nexthdr; + continue; + } + hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr); if (!hp) break; + if (next_type == IPPROTO_AH) + start += ipv6_authlen(hp); + else + start += ipv6_optlen(hp); next_type = hp->nexthdr; - start += ipv6_optlen(hp); } } diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index cf6429f0947726..73222563fb7049 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2932,7 +2932,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) if (has_vnet_hdr) virtio_net_hdr_set_proto(skb, &vnet_hdr); - uarg = kmalloc(sizeof(*uarg), GFP_KERNEL); + uarg = kmalloc_obj(*uarg); if (unlikely(!uarg)) { if (likely(len_sum > 0)) err = len_sum; diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index e7b3647424b8f1..45cb8e8c36ca24 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -122,6 +122,7 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports); * @qrtr_tx_flow: xarray of qrtr_tx_flow, keyed by node << 32 | port * @qrtr_tx_lock: lock for qrtr_tx_flow inserts * @hello_sent: hello packet send successful + * @hello_rcvd: remote has sent a hello packet * @rx_queue: receive queue * @item: list item for broadcast list * @say_hello: delayed work for sending hello packet @@ -136,6 +137,7 @@ struct qrtr_node { struct mutex qrtr_tx_lock; /* for qrtr_tx_flow */ bool hello_sent; + bool hello_rcvd; struct sk_buff_head rx_queue; struct list_head item; @@ -541,6 +543,11 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) qrtr_node_assign(node, le32_to_cpu(pkt->server.node)); } + if (cb->type == QRTR_TYPE_HELLO) { + /* Pairs with smp_load_acquire() in qrtr_hello_work() */ + smp_store_release(&node->hello_rcvd, true); + } + if (cb->type == QRTR_TYPE_RESUME_TX) { qrtr_tx_resume(node, skb); } else { @@ -599,6 +606,8 @@ static void qrtr_hello_work(struct work_struct *work) struct qrtr_node *node; struct qrtr_sock *ctrl; struct sk_buff *skb; + bool hello_sent; + int rc = 0; node = container_of(to_delayed_work(work), struct qrtr_node, say_hello); @@ -609,17 +618,45 @@ static void qrtr_hello_work(struct work_struct *work) return; } - skb = qrtr_alloc_ctrl_packet(&pkt, GFP_KERNEL); - if (!skb) { - qrtr_port_put(ctrl); - schedule_delayed_work(&node->say_hello, msecs_to_jiffies(100)); - return; + mutex_lock(&node->ep_lock); + hello_sent = node->hello_sent; + mutex_unlock(&node->ep_lock); + + from.sq_node = qrtr_local_nid; + if (!hello_sent) { + skb = qrtr_alloc_ctrl_packet(&pkt, GFP_KERNEL); + if (!skb) + goto retry; + + pkt->cmd = cpu_to_le32(QRTR_TYPE_HELLO); + to.sq_node = node->nid; + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_HELLO, &from, &to)) + goto out; } + /* Pairs with smp_store_release() in qrtr_endpoint_post() */ + if (!smp_load_acquire(&node->hello_rcvd)) + goto out; + + skb = qrtr_alloc_ctrl_packet(&pkt, GFP_KERNEL); + if (!skb) + goto retry; + pkt->cmd = cpu_to_le32(QRTR_TYPE_HELLO); - from.sq_node = qrtr_local_nid; - to.sq_node = node->nid; - qrtr_node_enqueue(node, skb, QRTR_TYPE_HELLO, &from, &to); + to.sq_node = READ_ONCE(node->nid); + + mutex_lock(&node->ep_lock); + if (node->ep) + rc = qrtr_local_enqueue(NULL, skb, QRTR_TYPE_HELLO, &to, &from); + else + kfree_skb(skb); + mutex_unlock(&node->ep_lock); + if (!rc) + goto out; + +retry: + schedule_delayed_work(&node->say_hello, msecs_to_jiffies(100)); +out: qrtr_port_put(ctrl); } diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c index e9a4bb92ce76ff..1040c3c8cfd688 100644 --- a/net/qrtr/mhi.c +++ b/net/qrtr/mhi.c @@ -112,7 +112,7 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, struct qrtr_mhi_dev *qdev; int rc; - qdev = devm_kzalloc(&mhi_dev->dev, sizeof(*qdev), GFP_KERNEL); + qdev = devm_kzalloc_obj(&mhi_dev->dev, *qdev); if (!qdev) return -ENOMEM; diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c index c91bf030fbc7d9..8b30b8275a2d95 100644 --- a/net/qrtr/smd.c +++ b/net/qrtr/smd.c @@ -61,7 +61,7 @@ static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev) struct qrtr_smd_dev *qdev; int rc; - qdev = devm_kzalloc(&rpdev->dev, sizeof(*qdev), GFP_KERNEL); + qdev = devm_kzalloc_obj(&rpdev->dev, *qdev); if (!qdev) return -ENOMEM; diff --git a/net/rds/rdma.c b/net/rds/rdma.c index 078090d292fa31..71b57abb96c424 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -957,8 +957,11 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, } ret = rds_pin_pages(args->local_addr, 1, &page, 1); - if (ret != 1) + if (ret != 1) { + /* A failed pin can leave a stale page pointer. */ + page = NULL; goto err; + } ret = 0; sg_set_page(rm->atomic.op_sg, page, 8, offset_in_page(args->local_addr)); diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c index 9c5b695dba7c88..20cb432dfb85d0 100644 --- a/net/rfkill/rfkill-gpio.c +++ b/net/rfkill/rfkill-gpio.c @@ -102,7 +102,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev) if (dmi_check_system(rfkill_gpio_deny_table)) return -ENODEV; - rfkill = devm_kzalloc(&pdev->dev, sizeof(*rfkill), GFP_KERNEL); + rfkill = devm_kzalloc_obj(&pdev->dev, *rfkill); if (!rfkill) return -ENOMEM; diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c index 3946a9589bb8fc..5a527da0056613 100644 --- a/net/sched/act_ife.c +++ b/net/sched/act_ife.c @@ -50,8 +50,7 @@ int ife_encode_meta_u16(u16 metaval, void *skbdata, struct tcf_meta_info *mi) edata = *(u16 *)mi->metaval; else if (metaval) edata = metaval; - - if (!edata) /* will not encode */ + else return 0; edata = htons(edata); @@ -94,8 +93,7 @@ int ife_encode_meta_u32(u32 metaval, void *skbdata, struct tcf_meta_info *mi) edata = *(u32 *)mi->metaval; else if (metaval) edata = metaval; - - if (!edata) /* will not encode */ + else return 0; edata = htonl(edata); @@ -880,13 +878,16 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, * is an Ethernet header because the skb could've been redirected with mirred * from a non-Ethernet device. */ -static bool tcf_ife_is_eth_skb(const struct sk_buff *skb) +static bool tcf_ife_is_eth_skb(struct sk_buff *skb) { if (skb->dev->type != ARPHRD_ETHER && skb->dev->type != ARPHRD_LOOPBACK) return false; - return !skb_at_tc_ingress(skb) || skb->mac_len == ETH_HLEN; + if (skb_at_tc_ingress(skb)) + return skb->mac_len == ETH_HLEN; + + return pskb_may_pull(skb, ETH_HLEN); } TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb, diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c index e6c87a32950f9b..e0fcda26ff6219 100644 --- a/net/sched/sch_fq_codel.c +++ b/net/sched/sch_fq_codel.c @@ -542,7 +542,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt, err = -ENOMEM; goto init_failure; } - q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL); + q->backlogs = kvzalloc_objs(u32, q->flows_cnt); if (!q->backlogs) { err = -ENOMEM; goto alloc_failure; diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 3e8ee4a691c34e..d2e0d20f3ba1cd 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -96,9 +96,34 @@ static void qdisc_maybe_clear_missed(struct Qdisc *q, #define SKB_XOFF_MAGIC ((struct sk_buff *)1UL) +/* Re-cap a stale queue_mapping; an ONETXQUEUE qdisc pins q->dev_queue. */ +static u16 qdisc_cap_skb_tx_queue(struct Qdisc *q, struct sk_buff *skb) +{ + u16 queue = skb_get_queue_mapping(skb); + struct net_device *dev = qdisc_dev(q); + u16 capped; + + if (q->flags & TCQ_F_ONETXQUEUE) + capped = q->dev_queue - netdev_get_tx_queue(dev, 0); + else + capped = netdev_cap_txqueue(dev, queue); + + if (unlikely(capped != queue)) + skb_set_queue_mapping(skb, capped); + + return capped; +} + +static struct netdev_queue *skb_cap_tx_queue(struct Qdisc *q, + struct sk_buff *skb) +{ + return netdev_get_tx_queue(qdisc_dev(q), + qdisc_cap_skb_tx_queue(q, skb)); +} + static inline struct sk_buff *__skb_dequeue_bad_txq(struct Qdisc *q) { - const struct netdev_queue *txq = q->dev_queue; + const struct netdev_queue *txq; spinlock_t *lock = NULL; struct sk_buff *skb; @@ -110,7 +135,8 @@ static inline struct sk_buff *__skb_dequeue_bad_txq(struct Qdisc *q) skb = skb_peek(&q->skb_bad_txq); if (skb) { /* check the reason of requeuing without tx lock first */ - txq = skb_get_tx_queue(txq->dev, skb); + /* re-cap: real_num_tx_queues may have shrunk */ + txq = skb_cap_tx_queue(q, skb); if (!netif_xmit_frozen_or_stopped(txq)) { skb = __skb_dequeue(&q->skb_bad_txq); if (qdisc_is_percpu_stats(q)) { @@ -224,6 +250,8 @@ static void try_bulk_dequeue_skb(struct Qdisc *q, if (!nskb) break; + /* Every element of an ONETXQUEUE qdisc is pinned to q->dev_queue. */ + qdisc_cap_skb_tx_queue(q, nskb); bytelimit -= nskb->len; /* covers GSO len */ skb->next = nskb; skb = nskb; @@ -241,7 +269,6 @@ static void try_bulk_dequeue_skb_slow(struct Qdisc *q, struct sk_buff *skb, int *packets) { - int mapping = skb_get_queue_mapping(skb); struct sk_buff *nskb; int cnt = 0; @@ -249,7 +276,9 @@ static void try_bulk_dequeue_skb_slow(struct Qdisc *q, nskb = q->dequeue(q); if (!nskb) break; - if (unlikely(skb_get_queue_mapping(nskb) != mapping)) { + /* A tc BPF store may have changed the mapping; cap it. */ + if (unlikely(qdisc_cap_skb_tx_queue(q, nskb) != + skb_get_queue_mapping(skb))) { qdisc_enqueue_skb_bad_txq(q, nskb); break; } @@ -294,7 +323,7 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate, if (xfrm_offload(skb)) *validate = true; /* check the reason of requeuing without tx lock first */ - txq = skb_get_tx_queue(txq->dev, skb); + txq = skb_cap_tx_queue(q, skb); if (!netif_xmit_frozen_or_stopped(txq)) { skb = __skb_dequeue(&q->gso_skb); if (qdisc_is_percpu_stats(q)) { @@ -330,6 +359,8 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate, skb = q->dequeue(q); if (skb) { bulk: + /* cap the head; the bulk helpers cap every appended element */ + qdisc_cap_skb_tx_queue(q, skb); if (qdisc_may_bulk(q)) try_bulk_dequeue_skb(q, skb, txq, packets, budget); else diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c index 5dec1ed969adf7..fca20c50c97cd7 100644 --- a/net/sched/sch_hhf.c +++ b/net/sched/sch_hhf.c @@ -648,9 +648,7 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt, /* Initialize heavy-hitter filter arrays. */ for (i = 0; i < HHF_ARRAYS_CNT; i++) { - q->hhf_arrays[i] = kvcalloc(HHF_ARRAYS_LEN, - sizeof(u32), - GFP_KERNEL); + q->hhf_arrays[i] = kvzalloc_objs(u32, HHF_ARRAYS_LEN); if (!q->hhf_arrays[i]) { /* Note: hhf_destroy() will be called * by our caller. diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c index 6f3b7273cb160e..e900890e9c5445 100644 --- a/net/sched/sch_qfq.c +++ b/net/sched/sch_qfq.c @@ -517,11 +517,14 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, sch_tree_lock(sch); qfq_init_agg(q, new_agg, lmax, weight); } + if (existing && new_agg == cl->agg) + goto unlock; if (existing) qfq_deact_rm_from_agg(q, cl); else qdisc_class_hash_insert(&q->clhash, &cl->common); qfq_add_to_agg(q, new_agg, cl); +unlock: sch_tree_unlock(sch); qdisc_class_hash_grow(sch, &q->clhash); diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 86740f4e82f5fa..4f69ef3d847a6b 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -639,6 +639,11 @@ static int taprio_enqueue(struct sk_buff *skb, struct Qdisc *sch, int queue; queue = skb_get_queue_mapping(skb); + if (unlikely(queue >= qdisc_dev(sch)->real_num_tx_queues)) { + /* A tc BPF program may have stored an out-of-range mapping. */ + queue = netdev_cap_txqueue(qdisc_dev(sch), queue); + skb_set_queue_mapping(skb, queue); + } child = q->qdiscs[queue]; if (unlikely(child == &noop_qdisc)) diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index 70c948a26f809e..dc21cd9704a257 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c @@ -200,6 +200,8 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt, struct Qdisc *first; unsigned long flags; + skb_queue_head_init(&q->q); + if (dev->hard_header_len > m->dev->hard_header_len) return -EINVAL; @@ -211,9 +213,12 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt, return -EOPNOTSUPP; } - q->m = m; + if (dev_net(dev) != dev_net(m->dev)) { + NL_SET_ERR_MSG_MOD(extack, "teql master is in a different network namespace"); + return -EOPNOTSUPP; + } - skb_queue_head_init(&q->q); + q->m = m; raw_spin_lock_irqsave(&m->slaves_lock, flags); first = rcu_dereference_protected(m->slaves, lockdep_is_held(&m->slaves_lock)); diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index d64c3ae33298f7..15c2d87575a8a7 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -137,6 +137,7 @@ int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, size_t paylen) { struct sctp_errhdr err; + int chunklen, padlen; __u16 len; /* Cause code constants are now defined in network order. */ @@ -144,7 +145,13 @@ int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, len = sizeof(err) + paylen; err.length = htons(len); - if (skb_tailroom(chunk->skb) < len) + /* sctp_addto_chunk() pads the chunk up to a 4-byte boundary before + * appending the cause, so account for that padding here as well. + */ + chunklen = ntohs(chunk->chunk_hdr->length); + padlen = SCTP_PAD4(chunklen) - chunklen; + + if (skb_tailroom(chunk->skb) < padlen + len) return -ENOSPC; chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(err), &err); @@ -3153,9 +3160,12 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc, * packet MUST be deleted. */ if (af->is_any(&addr)) { - sctp_assoc_set_primary(asoc, asconf->transport); - sctp_assoc_del_nonprimary_peers(asoc, - asconf->transport); + peer = sctp_assoc_lookup_paddr(asoc, &asconf->source); + if (!peer) + return SCTP_ERROR_REQ_REFUSED; + sctp_assoc_set_primary(asoc, peer); + sctp_assoc_del_nonprimary_peers(asoc, peer); + asconf->transport = peer; return SCTP_ERROR_NO_ERROR; } @@ -3168,13 +3178,9 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc, if (!peer) return SCTP_ERROR_DNS_FAILED; - /* Don't free asconf->transport; a later wildcard DEL-IP - * parameter reuses it. - */ - if (peer == asconf->transport) - return SCTP_ERROR_REQ_REFUSED; - sctp_assoc_rm_peer(asoc, peer); + if (asconf->transport == peer) + asconf->transport = asoc->peer.primary_path; break; case SCTP_PARAM_SET_PRIMARY: /* ADDIP Section 4.2.4 diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index b2f609f177fb98..64519fd8f94335 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -1122,9 +1122,11 @@ enum sctp_disposition sctp_sf_send_reconf(struct net *net, return SCTP_DISPOSITION_DELETE_TCB; } - sctp_chunk_hold(asoc->strreset_chunk); - sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, - SCTP_CHUNK(asoc->strreset_chunk)); + if (!sctp_chunk_pending(asoc->strreset_chunk)) { + sctp_chunk_hold(asoc->strreset_chunk); + sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, + SCTP_CHUNK(asoc->strreset_chunk)); + } sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); return SCTP_DISPOSITION_CONSUME; @@ -6197,9 +6199,11 @@ enum sctp_disposition sctp_sf_t4_timer_expire( * chunk, it MUST be the same (including its serial number) as the last * ASCONF sent. */ - sctp_chunk_hold(asoc->addip_last_asconf); - sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, - SCTP_CHUNK(asoc->addip_last_asconf)); + if (!sctp_chunk_pending(asoc->addip_last_asconf)) { + sctp_chunk_hold(asoc->addip_last_asconf); + sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, + SCTP_CHUNK(asoc->addip_last_asconf)); + } /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different * destination is selected, then the RTO used will be that of the new diff --git a/net/sctp/socket.c b/net/sctp/socket.c index b5a57f61ee6d11..8e647737b2567d 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -809,7 +809,6 @@ static int sctp_send_asconf_del_ip(struct sock *sk, struct sctp_sockaddr_entry *saddr; int i; int retval = 0; - int stored = 0; chunk = NULL; sp = sctp_sk(sk); @@ -822,6 +821,7 @@ static int sctp_send_asconf_del_ip(struct sock *sk, __func__, sk, addrs, addrcnt); list_for_each_entry(asoc, &ep->asocs, asocs) { + int stored = 0; if (!asoc->peer.asconf_capable) continue; diff --git a/net/sctp/stream.c b/net/sctp/stream.c index e4354d58f20b91..30037d0ca160ec 100644 --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -326,7 +326,7 @@ int sctp_send_reset_streams(struct sctp_association *asoc, goto out; } - nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL); + nstr_list = kzalloc_objs(__be16, str_nums); if (!nstr_list) { retval = -ENOMEM; goto out; @@ -749,6 +749,7 @@ struct sctp_chunk *sctp_process_strreset_tsnreq( */ max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map); asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen); + asoc->stream.si->abort_pd(&asoc->ulpq, GFP_ATOMIC); /* G1: Compute an appropriate value for the Receiver's Next TSN -- the * TSN that the peer should use to send the next DATA chunk. The @@ -1028,6 +1029,7 @@ struct sctp_chunk *sctp_process_strreset_resp( LIST_HEAD(temp); asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn); + asoc->stream.si->abort_pd(&asoc->ulpq, GFP_ATOMIC); sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL, diff --git a/net/sctp/stream_interleave.c b/net/sctp/stream_interleave.c index 840f24045ae2e9..1113b3455369b9 100644 --- a/net/sctp/stream_interleave.c +++ b/net/sctp/stream_interleave.c @@ -1203,28 +1203,21 @@ static void sctp_report_fwdtsn(struct sctp_ulpq *ulpq, __u32 ftsn) sctp_ulpq_abort_pd(ulpq, GFP_ATOMIC); } -static void sctp_intl_reasm_flushtsn(struct sctp_ulpq *ulpq, __u32 ftsn) +static void sctp_intl_reasm_flush_mid(struct sk_buff_head *reasm, __u16 sid, + __u32 mid) { struct sk_buff *pos, *tmp; - skb_queue_walk_safe(&ulpq->reasm, pos, tmp) { + skb_queue_walk_safe(reasm, pos, tmp) { struct sctp_ulpevent *event = sctp_skb2event(pos); - __u32 tsn = event->tsn; - if (TSN_lte(tsn, ftsn)) { - __skb_unlink(pos, &ulpq->reasm); - sctp_ulpevent_free(event); - } - } - - skb_queue_walk_safe(&ulpq->reasm_uo, pos, tmp) { - struct sctp_ulpevent *event = sctp_skb2event(pos); - __u32 tsn = event->tsn; + if (event->stream < sid) + continue; + if (event->stream > sid || MID_lt(mid, event->mid)) + break; - if (TSN_lte(tsn, ftsn)) { - __skb_unlink(pos, &ulpq->reasm_uo); - sctp_ulpevent_free(event); - } + __skb_unlink(pos, reasm); + sctp_ulpevent_free(event); } } @@ -1232,11 +1225,6 @@ static void sctp_report_iftsn(struct sctp_ulpq *ulpq, __u32 ftsn) { /* Move the Cumulattive TSN Ack ahead. */ sctp_tsnmap_skip(&ulpq->asoc->peer.tsn_map, ftsn); - /* purge the fragmentation queue */ - sctp_intl_reasm_flushtsn(ulpq, ftsn); - /* abort only when it's for all data */ - if (ftsn == sctp_tsnmap_get_max_tsn_seen(&ulpq->asoc->peer.tsn_map)) - sctp_intl_abort_pd(ulpq, GFP_ATOMIC); } static void sctp_handle_fwdtsn(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk) @@ -1255,11 +1243,12 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid, struct sctp_stream *stream = &ulpq->asoc->stream; if (flags & SCTP_FTSN_U_BIT) { - if (sin->pd_mode_uo && MID_lt(sin->mid_uo, mid)) { + if (sin->pd_mode_uo && !MID_lt(mid, sin->mid_uo)) { sin->pd_mode_uo = 0; - sctp_intl_stream_abort_pd(ulpq, sid, mid, 0x1, + sctp_intl_stream_abort_pd(ulpq, sid, sin->mid_uo, 0x1, GFP_ATOMIC); } + sctp_intl_reasm_flush_mid(&ulpq->reasm_uo, sid, mid); return; } @@ -1268,9 +1257,10 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid, if (sin->pd_mode) { sin->pd_mode = 0; - sctp_intl_stream_abort_pd(ulpq, sid, mid, 0x0, GFP_ATOMIC); + sctp_intl_stream_abort_pd(ulpq, sid, sin->mid, 0x0, GFP_ATOMIC); } + sctp_intl_reasm_flush_mid(&ulpq->reasm, sid, mid); sctp_mid_skip(stream, in, sid, mid); sctp_intl_reap_ordered(ulpq, sid); diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index d10244af5bd299..bfc0c7e71a12b4 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -980,7 +980,7 @@ static int smc_connect_fallback(struct smc_sock *smc, int reason_code) smc_copy_sock_settings_to_clc(smc); smc->connect_nonblock = 0; if (smc->sk.sk_state == SMC_INIT) - smc->sk.sk_state = SMC_ACTIVE; + smp_store_release(&smc->sk.sk_state, SMC_ACTIVE); return 0; } @@ -1013,14 +1013,15 @@ static void smc_conn_abort(struct smc_sock *smc, int local_first) { struct smc_connection *conn = &smc->conn; struct smc_link_group *lgr = conn->lgr; - bool lgr_valid = false; - - if (smc_conn_lgr_valid(conn)) - lgr_valid = true; + bool lgr_valid = local_first && smc_conn_lgr_valid(conn); + if (lgr_valid) + smc_lgr_hold(lgr); /* lgr_put below */ smc_conn_free(conn); - if (local_first && lgr_valid) + if (lgr_valid) { smc_lgr_cleanup_early(lgr); + smc_lgr_put(lgr); + } } /* check if there is a rdma device available for this connection. */ @@ -1385,7 +1386,7 @@ static int smc_connect_rdma(struct smc_sock *smc, smc_copy_sock_settings_to_clc(smc); smc->connect_nonblock = 0; if (smc->sk.sk_state == SMC_INIT) - smc->sk.sk_state = SMC_ACTIVE; + smp_store_release(&smc->sk.sk_state, SMC_ACTIVE); return 0; connect_abort: @@ -1488,7 +1489,7 @@ static int smc_connect_ism(struct smc_sock *smc, smc_copy_sock_settings_to_clc(smc); smc->connect_nonblock = 0; if (smc->sk.sk_state == SMC_INIT) - smc->sk.sk_state = SMC_ACTIVE; + smp_store_release(&smc->sk.sk_state, SMC_ACTIVE); return 0; connect_abort: @@ -1957,7 +1958,7 @@ static void smc_listen_out_connected(struct smc_sock *new_smc) struct sock *newsmcsk = &new_smc->sk; if (newsmcsk->sk_state == SMC_INIT) - newsmcsk->sk_state = SMC_ACTIVE; + smp_store_release(&newsmcsk->sk_state, SMC_ACTIVE); smc_listen_out(new_smc); } @@ -1971,7 +1972,7 @@ static void smc_listen_out_err(struct smc_sock *new_smc) this_cpu_inc(net->smc.smc_stats->srv_hshake_err_cnt); if (newsmcsk->sk_state == SMC_INIT) sock_put(&new_smc->sk); /* passive closing */ - newsmcsk->sk_state = SMC_CLOSED; + smp_store_release(&newsmcsk->sk_state, SMC_CLOSED); smc_listen_out(new_smc); } diff --git a/net/smc/smc.h b/net/smc/smc.h index 427b6d63b9931b..36b243b34a9aeb 100644 --- a/net/smc/smc.h +++ b/net/smc/smc.h @@ -196,6 +196,7 @@ struct smc_connection { struct rb_node alert_node; struct smc_link_group *lgr; /* link group of connection */ struct smc_link *lnk; /* assigned SMC-R link */ + bool is_smcd; /* SMC-R or SMC-D connection */ u32 alert_token_local; /* unique conn. id */ u8 peer_rmbe_idx; /* from tcp handshake */ int peer_rmbe_size; /* size of peer rx buffer */ diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c index a8d4b4b65f2441..736abfbd2aafaa 100644 --- a/net/smc/smc_close.c +++ b/net/smc/smc_close.c @@ -155,6 +155,7 @@ void smc_close_active_abort(struct smc_sock *smc) if (sk->sk_state != SMC_PEERABORTWAIT) break; sk->sk_state = SMC_CLOSED; + sk->sk_prot->unhash(sk); smc_conn_free(&smc->conn); release_clcsock = true; sock_put(sk); /* passive closing */ @@ -166,6 +167,7 @@ void smc_close_active_abort(struct smc_sock *smc) if (sk->sk_state != SMC_PEERABORTWAIT) break; sk->sk_state = SMC_CLOSED; + sk->sk_prot->unhash(sk); smc_conn_free(&smc->conn); release_clcsock = true; break; @@ -370,6 +372,17 @@ static void smc_close_passive_work(struct work_struct *work) lock_sock(sk); old_state = sk->sk_state; + if (conn->freed) { + /* conn->freed is set under the socket lock, which is + * held here as well, so this cannot race with the free; the + * state machine and its postponed sock_put() are not owed + * anymore + */ + release_sock(sk); + sock_put(sk); /* sock_hold done by schedulers of close_work */ + return; + } + rxflags = &conn->local_rx_ctrl.conn_state_flags; if (rxflags->peer_conn_abort) { /* peer has not received all data */ @@ -437,6 +450,7 @@ static void smc_close_passive_work(struct work_struct *work) sk->sk_state_change(sk); if ((sk->sk_state == SMC_CLOSED) && (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) { + sk->sk_prot->unhash(sk); smc_conn_free(conn); if (smc->clcsock) release_clcsock = true; diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 6021322253e938..a3164201c14204 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -80,16 +80,21 @@ static void smc_ibdev_cnt_dec(struct smc_link *lnk) static void smc_lgr_schedule_free_work(struct smc_link_group *lgr) { + spinlock_t *lgr_lock; + /* client link group creation always follows the server link group * creation. For client use a somewhat higher removal delay time, * otherwise there is a risk of out-of-sync link groups. */ + smc_lgr_list_head(lgr, &lgr_lock); + spin_lock_bh(lgr_lock); if (!lgr->freeing) { mod_delayed_work(system_percpu_wq, &lgr->free_work, (!lgr->is_smcd && lgr->role == SMC_CLNT) ? SMC_LGR_FREE_DELAY_CLNT : SMC_LGR_FREE_DELAY_SERV); } + spin_unlock_bh(lgr_lock); } /* Register connection's alert token in our lookup structure. @@ -679,19 +684,34 @@ int smcd_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } -void smc_lgr_cleanup_early(struct smc_link_group *lgr) +/* Claim a link group for termination. Only one context can succeed: the + * lgr is removed from its list and marked freeing under lgr_lock. + * Returns false if @lgr is NULL or another context owns it. + */ +static bool smc_lgr_claim(struct smc_link_group *lgr) { spinlock_t *lgr_lock; if (!lgr) - return; - + return false; smc_lgr_list_head(lgr, &lgr_lock); spin_lock_bh(lgr_lock); + if (lgr->freeing || lgr->terminating || list_empty(&lgr->list)) { + spin_unlock_bh(lgr_lock); + return false; + } /* do not use this link group for new connections */ - if (!list_empty(&lgr->list)) - list_del_init(&lgr->list); + list_del_init(&lgr->list); + lgr->freeing = 1; spin_unlock_bh(lgr_lock); + return true; +} + +/* The caller must keep @lgr alive for the duration of the call. */ +void smc_lgr_cleanup_early(struct smc_link_group *lgr) +{ + if (!smc_lgr_claim(lgr)) + return; /* another context owns the termination */ __smc_lgr_terminate(lgr, true); } @@ -1281,10 +1301,12 @@ void smc_conn_free(struct smc_connection *conn) if (current_work() != &conn->abort_work) cancel_work_sync(&conn->abort_work); } - if (!list_empty(&lgr->list)) { + /* The handshake can retry another device or SMC version with this + * connection, so it must never stay registered in an lgr it left. + */ + if (!list_empty(&lgr->list)) smc_buf_unuse(conn, lgr); /* allow buffer reuse */ - smc_lgr_unregister_conn(conn); - } + smc_lgr_unregister_conn(conn); if (!lgr->conns_num) smc_lgr_schedule_free_work(lgr); @@ -1519,6 +1541,15 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft) { struct smc_sock *smc = container_of(conn, struct smc_sock, conn); + if (conn->freed) { + /* The connection was already freed, e.g. by a close or + * a handshake that fell back to TCP. Do not abort a socket + * that is no longer part of this link group. + */ + smc_lgr_unregister_conn(conn); + return; + } + if (conn->lgr->is_smcd && conn->lgr->peer_shutdown) conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; else @@ -1532,8 +1563,10 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft) tasklet_kill(&conn->rx_tsklet); else tasklet_unlock_wait(&conn->rx_tsklet); - if (smc_ism_support_dmb_nocopy(conn->lgr->smcd)) + if (smc_ism_support_dmb_nocopy(conn->lgr->smcd)) { + smc->sk.sk_prot->unhash(&smc->sk); smcd_buf_detach(conn); + } } else { smc_cdc_wait_pend_tx_wr(conn); } @@ -1564,12 +1597,20 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft) struct smc_connection *conn; struct smc_sock *smc; struct rb_node *node; + spinlock_t *lgr_lock; - if (lgr->terminating) + smc_lgr_list_head(lgr, &lgr_lock); + spin_lock_bh(lgr_lock); + if (lgr->terminating) { + spin_unlock_bh(lgr_lock); return; /* lgr already terminating */ - /* cancel free_work sync, will terminate when lgr->freeing is set */ - cancel_delayed_work(&lgr->free_work); + } lgr->terminating = 1; + spin_unlock_bh(lgr_lock); + /* The lgr is claimed, so no new free_work can be armed; wait for + * one that is already queued or running. + */ + cancel_delayed_work_sync(&lgr->free_work); /* kill remaining link group connections */ read_lock_bh(&lgr->conns_lock); @@ -1580,7 +1621,11 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft) sock_hold(&smc->sk); /* sock_put below */ read_unlock_bh(&lgr->conns_lock); lock_sock(&smc->sk); - smc_conn_kill(conn, soft); + /* The connection may have been re-registered in another + * link group by a retried handshake in the meantime. + */ + if (conn->lgr == lgr) + smc_conn_kill(conn, soft); release_sock(&smc->sk); sock_put(&smc->sk); /* sock_hold above */ read_lock_bh(&lgr->conns_lock); @@ -1594,17 +1639,8 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft) /* unlink link group and schedule termination */ void smc_lgr_terminate_sched(struct smc_link_group *lgr) { - spinlock_t *lgr_lock; - - smc_lgr_list_head(lgr, &lgr_lock); - spin_lock_bh(lgr_lock); - if (list_empty(&lgr->list) || lgr->terminating || lgr->freeing) { - spin_unlock_bh(lgr_lock); + if (!smc_lgr_claim(lgr)) return; /* lgr already terminating */ - } - list_del_init(&lgr->list); - lgr->freeing = 1; - spin_unlock_bh(lgr_lock); schedule_work(&lgr->terminate_work); } @@ -2053,6 +2089,10 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) goto out; } } + /* cache the connection type: smc_diag reads it after + * smc_conn_free() dropped the link group reference + */ + conn->is_smcd = conn->lgr->is_smcd; smc_lgr_hold(conn->lgr); /* lgr_put in smc_conn_free() */ if (!conn->lgr->is_smcd) smcr_link_hold(conn->lnk); /* link_put in smc_conn_free() */ diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h index 5c18f08a4c8a57..bff4c9e1779292 100644 --- a/net/smc/smc_core.h +++ b/net/smc/smc_core.h @@ -301,9 +301,9 @@ struct smc_link_group { struct delayed_work free_work; /* delayed freeing of an lgr */ struct work_struct terminate_work; /* abnormal lgr termination */ struct workqueue_struct *tx_wq; /* wq for conn. tx workers */ - u8 sync_err : 1; /* lgr no longer fits to peer */ - u8 terminating : 1;/* lgr is terminating */ - u8 freeing : 1; /* lgr is being freed */ + u8 sync_err; /* lgr no longer fits to peer */ + u8 terminating; /* lgr is terminating */ + u8 freeing; /* lgr is being freed */ refcount_t refcnt; /* lgr reference count */ bool is_smcd; /* SMC-R or SMC-D */ diff --git a/net/smc/smc_diag.c b/net/smc/smc_diag.c index bf0beaa23bdb63..15485a08d9a05a 100644 --- a/net/smc/smc_diag.c +++ b/net/smc/smc_diag.c @@ -87,10 +87,10 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, r = nlmsg_data(nlh); smc_diag_msg_common_fill(r, sk); - r->diag_state = sk->sk_state; + r->diag_state = smp_load_acquire(&sk->sk_state); if (smc->use_fallback) r->diag_mode = SMC_DIAG_MODE_FALLBACK_TCP; - else if (smc_conn_lgr_valid(&smc->conn) && smc->conn.lgr->is_smcd) + else if (smc->conn.is_smcd) r->diag_mode = SMC_DIAG_MODE_SMCD; else r->diag_mode = SMC_DIAG_MODE_SMCR; @@ -103,6 +103,10 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, if (nla_put(skb, SMC_DIAG_FALLBACK, sizeof(fallback), &fallback) < 0) goto errout; + if (r->diag_state == SMC_INIT || r->diag_state == SMC_CLOSED || + smc->use_fallback) + goto out; + if ((req->diag_ext & (1 << (SMC_DIAG_CONNINFO - 1))) && smc->conn.alert_token_local) { struct smc_connection *conn = &smc->conn; @@ -154,8 +158,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, .lnk[0].link_id = link->link_id, }; - memcpy(linfo.lnk[0].ibname, link->smcibdev->ibdev->name, - sizeof(link->smcibdev->ibdev->name)); + memcpy(linfo.lnk[0].ibname, link->ibname, sizeof(link->ibname)); smc_gid_be16_convert(linfo.lnk[0].gid, link->gid); smc_gid_be16_convert(linfo.lnk[0].peer_gid, link->peer_gid); @@ -185,6 +188,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, goto errout; } +out: nlmsg_end(skb, nlh); return 0; diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c index 197fddc6271f05..63c178c10bf1a2 100644 --- a/net/smc/smc_rx.c +++ b/net/smc/smc_rx.c @@ -286,6 +286,27 @@ int smc_rx_wait(struct smc_sock *smc, long *timeo, size_t peeked, return rc; } +/* Wait for the pipe to release the spliced data. Unlike smc_rx_wait() + * it does not end on shutdown or sk_err, the data is already in the + * RMB; smc_conn_kill() wakes it and the caller checks conn->killed. + */ +static void smc_rx_wait_splice(struct smc_sock *smc, long *timeo) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + struct smc_connection *conn = &smc->conn; + struct sock *sk = &smc->sk; + + sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); + add_wait_queue(sk_sleep(sk), &wait); + /* pairs with the smp_mb() in wq_has_sleeper(): the release drops + * splice_pending, then looks for a sleeper + */ + smp_mb(); + sk_wait_event(sk, timeo, !atomic_read(&conn->splice_pending), &wait); + remove_wait_queue(sk_sleep(sk), &wait); + sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); +} + static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len, int flags) { @@ -443,7 +464,23 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg, /* could be just 1 byte, even after waiting on data above */ readable = smc_rx_data_available(conn, peeked_bytes); splbytes = atomic_read(&conn->splice_pending); - if (!readable || (msg && splbytes)) { + if (msg && splbytes) { + /* a pipe holds bytes ahead of these; the copy path + * skips the timeout and signal checks + */ + if (!read_remaining) + break; + if (!timeo || signal_pending(current)) { + if (!read_done) + read_done = timeo ? + sock_intr_errno(timeo) : + -EAGAIN; + break; + } + smc_rx_wait_splice(smc, &timeo); + continue; + } + if (!readable) { if (splbytes) func = smc_rx_data_available_and_no_splice_pend; else diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c index 09dad48337f616..f58cf256f61abe 100644 --- a/net/smc/smc_sysctl.c +++ b/net/smc/smc_sysctl.c @@ -160,11 +160,9 @@ static const struct ctl_table smc_table[] = { { .procname = "limit_smc_hs", .data = &init_net.smc.limit_smc_hs, - .maxlen = sizeof(int), + .maxlen = sizeof(bool), .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, + .proc_handler = proc_dobool, }, { .procname = "smcr_max_send_wr", diff --git a/net/socket.c b/net/socket.c index 2e3b5737c481b7..08658a9b8065db 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2697,8 +2697,6 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys, flags &= ~MSG_INTERNAL_SENDMSG_FLAGS; msg_sys->msg_flags = flags; - if (sock->file->f_flags & O_NONBLOCK) - msg_sys->msg_flags |= MSG_DONTWAIT; /* * If this is sendmmsg() and current destination address is same as * previously succeeded address, omit asking LSM's decision. @@ -2762,6 +2760,9 @@ static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg, msg_sys->msg_name = &address; + if (sock->file->f_flags & O_NONBLOCK) + flags |= MSG_DONTWAIT; + err = sendmsg_copy_msghdr(msg_sys, msg, flags, &iov); if (err < 0) return err; @@ -2926,9 +2927,6 @@ static int ____sys_recvmsg(struct socket *sock, struct msghdr *msg_sys, /* We assume all kernel code knows the size of sockaddr_storage */ msg_sys->msg_namelen = 0; - if (sock->file->f_flags & O_NONBLOCK) - flags |= MSG_DONTWAIT; - if (unlikely(nosec)) err = sock_recvmsg_nosec(sock, msg_sys, flags); else @@ -2970,6 +2968,9 @@ static int ___sys_recvmsg(struct socket *sock, struct user_msghdr __user *msg, struct sockaddr __user *uaddr; ssize_t err; + if (sock->file->f_flags & O_NONBLOCK) + flags |= MSG_DONTWAIT; + err = recvmsg_copy_msghdr(msg_sys, msg, flags, &uaddr, &iov); if (err < 0) return err; diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 6cedc824cf8268..2f076b4bfd5403 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -653,6 +653,9 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, } args->servername = xprt->servername; args->nodename = clnt->cl_nodename; + args->xprtsec = clnt->cl_xprtsec; + if (!args->timeout) + args->timeout = clnt->cl_timeout; new = rpc_new_client(args, xps, xprt, clnt); if (IS_ERR(new)) @@ -901,29 +904,36 @@ void rpc_killall_tasks(struct rpc_clnt *clnt) } EXPORT_SYMBOL_GPL(rpc_killall_tasks); -/** - * rpc_cancel_tasks - try to cancel a set of RPC tasks - * @clnt: Pointer to RPC client - * @error: RPC task error value to set - * @fnmatch: Pointer to selector function - * @data: User data - * - * Uses @fnmatch to define a set of RPC tasks that are to be cancelled. - * The argument @error must be a negative error value. - */ -unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, - bool (*fnmatch)(const struct rpc_task *, - const void *), - const void *data) +struct rpc_cancel_disconnect_ctx { + bool (*fnmatch)(const struct rpc_task *task, const void *data); + const void *data; +}; + +static int rpc_mark_xprt_disconnect_on_release(struct rpc_clnt *clnt, + struct rpc_xprt *xprt, + void *arg) +{ + struct rpc_cancel_disconnect_ctx *ctx = arg; + + xprt_mark_matching_reqs_disconnect_on_release(xprt, clnt, + ctx->fnmatch, + ctx->data); + return 0; +} + +static unsigned long +__rpc_cancel_tasks(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data, + bool disconnect) { struct rpc_task *task; unsigned long count = 0; if (list_empty(&clnt->cl_tasks)) return 0; - /* - * Spin lock all_tasks to prevent changes... - */ + spin_lock(&clnt->cl_lock); list_for_each_entry(task, &clnt->cl_tasks, tk_task) { if (!RPC_IS_ACTIVATED(task)) @@ -934,10 +944,63 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, count++; } spin_unlock(&clnt->cl_lock); + + if (disconnect && count) { + struct rpc_cancel_disconnect_ctx ctx = { + .fnmatch = fnmatch, + .data = data, + }; + rpc_clnt_iterate_for_each_xprt(clnt, + rpc_mark_xprt_disconnect_on_release, + &ctx); + } return count; } + +/** + * rpc_cancel_tasks - try to cancel a set of RPC tasks + * @clnt: Pointer to RPC client + * @error: RPC task error value to set + * @fnmatch: Pointer to selector function + * @data: User data + * + * Uses @fnmatch to define a set of RPC tasks that are to be cancelled. + * The argument @error must be a negative error value. + */ +unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data) +{ + return __rpc_cancel_tasks(clnt, error, fnmatch, data, false); +} EXPORT_SYMBOL_GPL(rpc_cancel_tasks); +/** + * rpc_cancel_tasks_and_disconnect - cancel matching RPC tasks + * @clnt: Pointer to RPC client + * @error: RPC task error value to set + * @fnmatch: Pointer to selector function + * @data: User data + * + * Like rpc_cancel_tasks(), but after cancelling matching tasks, marks + * matching in-flight requests so that xprt_release() conditionally + * disconnects the connection generation on which each request was sent. + * + * @fnmatch is called while holding spinlocks and must not sleep. + * + * Returns the number of active tasks matched by @fnmatch. + */ +unsigned long +rpc_cancel_tasks_and_disconnect(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data) +{ + return __rpc_cancel_tasks(clnt, error, fnmatch, data, true); +} +EXPORT_SYMBOL_GPL(rpc_cancel_tasks_and_disconnect); + static int rpc_clnt_disconnect_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt, void *dummy) { @@ -1194,7 +1257,7 @@ void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt) (task->tk_flags & RPC_TASK_MOVEABLE))) return; xprt_release(task); - xprt_put(task->tk_xprt); + rpc_task_release_xprt(clnt, task->tk_xprt); } if (task->tk_flags & RPC_TASK_NO_ROUND_ROBIN) task->tk_xprt = rpc_task_get_first_xprt(clnt); @@ -2125,8 +2188,10 @@ call_bind_status(struct rpc_task *task) goto retry_timeout; case -ENETDOWN: case -ENETUNREACH: - if (task->tk_flags & RPC_TASK_NETUNREACH_FATAL) + if (task->tk_flags & RPC_TASK_NETUNREACH_FATAL) { + status = task->tk_status; break; + } fallthrough; case -ECONNREFUSED: /* connection problems */ case -ECONNRESET: @@ -2257,6 +2322,7 @@ call_connect_status(struct rpc_task *task) xprt_release(task); value = atomic_long_dec_return(&xprt->queuelen); + atomic_long_dec(&xps->xps_queuelen); if (value == 0) rpc_xprt_switch_remove_xprt(xps, saved, true); diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 9d349cfbc48312..f14cae29528044 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -191,6 +191,7 @@ rpc_close_pipes(struct dentry *dentry) cancel_delayed_work_sync(&pipe->queue_timeout); rpc_inode_setowner(inode, NULL); RPC_I(inode)->pipe = NULL; + wake_up(&RPC_I(inode)->waitq); inode_unlock(inode); } @@ -665,8 +666,8 @@ int rpc_mkpipe_dentry(struct dentry *parent, const char *name, rpci->private = private; rpci->pipe = pipe; rpc_inode_setowner(inode, private); - pipe->dentry = dentry; // borrowed d_make_persistent(dentry, inode); + pipe->dentry = dentry; // borrowed fsnotify_create(dir, dentry); simple_done_creating(dentry); return 0; diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h index e3c6e3b63f0ba6..11b9e5cead8e27 100644 --- a/net/sunrpc/sunrpc.h +++ b/net/sunrpc/sunrpc.h @@ -38,9 +38,17 @@ static inline int sock_is_loopback(struct sock *sk) struct svc_serv; struct svc_rqst; +struct rpc_clnt; +struct rpc_task; +struct rpc_xprt; int rpc_clients_notifier_register(void); void rpc_clients_notifier_unregister(void); void auth_domain_cleanup(void); void svc_sock_update_bufs(struct svc_serv *serv); enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp); +void xprt_mark_matching_reqs_disconnect_on_release(struct rpc_xprt *xprt, + const struct rpc_clnt *clnt, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data); #endif /* _NET_SUNRPC_SUNRPC_H */ diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 7e23af94a719f1..fda91c6e3fd25f 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -109,10 +109,10 @@ module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, static int svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools) { - m->to_pool = kcalloc(maxpools, sizeof(unsigned int), GFP_KERNEL); + m->to_pool = kzalloc_objs(unsigned int, maxpools); if (!m->to_pool) goto fail; - m->pool_to = kcalloc(maxpools, sizeof(unsigned int), GFP_KERNEL); + m->pool_to = kzalloc_objs(unsigned int, maxpools); if (!m->pool_to) goto fail_free; diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index a68fe44d1f6259..1380d094640171 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -633,7 +633,7 @@ int sunrpc_nl_unix_gid_get_reqs_dumpit(struct sk_buff *skb, return 0; items = kzalloc_objs(*items, cnt); - seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL); + seqnos = kzalloc_objs(*seqnos, cnt); if (!items || !seqnos) { ret = -ENOMEM; goto out_alloc; @@ -1336,7 +1336,7 @@ int sunrpc_nl_ip_map_get_reqs_dumpit(struct sk_buff *skb, return 0; items = kzalloc_objs(*items, cnt); - seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL); + seqnos = kzalloc_objs(*seqnos, cnt); if (!items || !seqnos) { ret = -ENOMEM; goto out_alloc; diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 48a3618cbb29f4..c110806989c5d8 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -812,6 +812,17 @@ xprt_request_retransmit_after_disconnect(struct rpc_task *task) !xprt_connected(xprt); } +static void xprt_conditional_disconnect_locked(struct rpc_xprt *xprt, + unsigned int cookie) + __must_hold(&xprt->transport_lock) +{ + if (cookie != xprt->connect_cookie) + return; + if (test_bit(XPRT_CLOSING, &xprt->state)) + return; + xprt_schedule_autoclose_locked(xprt); +} + /** * xprt_conditional_disconnect - force a transport to disconnect * @xprt: transport to disconnect @@ -827,12 +838,7 @@ void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie) { /* Don't race with the test_bit() in xprt_clear_locked() */ spin_lock(&xprt->transport_lock); - if (cookie != xprt->connect_cookie) - goto out; - if (test_bit(XPRT_CLOSING, &xprt->state)) - goto out; - xprt_schedule_autoclose_locked(xprt); -out: + xprt_conditional_disconnect_locked(xprt, cookie); spin_unlock(&xprt->transport_lock); } @@ -1434,6 +1440,79 @@ xprt_request_dequeue_transmit(struct rpc_task *task) spin_unlock(&xprt->queue_lock); } +static bool +xprt_request_matches(const struct rpc_rqst *req, + const struct rpc_clnt *clnt, + bool (*fnmatch)(const struct rpc_task *, const void *), + const void *data) +{ + const struct rpc_task *task = req->rq_task; + + return task && task->tk_client == clnt && fnmatch(task, data); +} + +static void +xprt_request_mark_disconnect_on_release(struct rpc_xprt *xprt, + struct rpc_rqst *req) + __must_hold(&xprt->queue_lock) +{ + spin_lock(&xprt->transport_lock); + req->rq_disconnect_on_release = true; + spin_unlock(&xprt->transport_lock); +} + +/** + * xprt_mark_matching_reqs_disconnect_on_release - mark matching in-flight + * requests for connection-generation + * teardown at release + * @xprt: transport whose queues to walk + * @clnt: RPC client whose requests are eligible + * @fnmatch: selector called with the request's owning rpc_task + * @data: caller data forwarded to @fnmatch + * + * @fnmatch must not sleep and must be safe to call while xprt->queue_lock + * is held. + * + * Walks the transmit queue (including per-owner rq_xmit2 chains) and the + * receive tree under xprt->queue_lock and marks each matching rpc_rqst so + * that xprt_release() will conditionally disconnect the transport against + * that request's rq_connect_cookie. Requests remain eligible for marking + * while they are present on a transport queue. The marker is set under + * xprt->transport_lock, nested inside xprt->queue_lock, and xprt_release() + * consumes it with xprt->transport_lock held after removing queue membership. + * + * The @clnt qualification preserves the selection domain of + * rpc_cancel_tasks(). An rpc_xprt may be shared by multiple rpc_clnt + * instances, so requests belonging to other clients must not be marked. + */ +void +xprt_mark_matching_reqs_disconnect_on_release(struct rpc_xprt *xprt, + const struct rpc_clnt *clnt, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data) +{ + struct rpc_rqst *req, *pos; + struct rb_node *n; + + spin_lock(&xprt->queue_lock); + list_for_each_entry(req, &xprt->xmit_queue, rq_xmit) { + if (xprt_request_matches(req, clnt, fnmatch, data)) + xprt_request_mark_disconnect_on_release(xprt, req); + list_for_each_entry(pos, &req->rq_xmit2, rq_xmit2) { + if (xprt_request_matches(pos, clnt, fnmatch, data)) + xprt_request_mark_disconnect_on_release(xprt, + pos); + } + } + for (n = rb_first(&xprt->recv_queue); n; n = rb_next(n)) { + req = rb_entry(n, struct rpc_rqst, rq_recv); + if (xprt_request_matches(req, clnt, fnmatch, data)) + xprt_request_mark_disconnect_on_release(xprt, req); + } + spin_unlock(&xprt->queue_lock); +} + /** * xprt_request_dequeue_xprt - remove a task from the transmit+receive queue * @task: pointer to rpc_task @@ -1915,6 +1994,7 @@ xprt_request_init(struct rpc_task *task) req->rq_rcv_buf.bvec = NULL; req->rq_release_snd_buf = NULL; req->rq_seqno_count = 0; + req->rq_disconnect_on_release = false; xprt_init_majortimeo(task, req, task->tk_client->cl_timeout); trace_xprt_reserve(req); @@ -1991,6 +2071,20 @@ void xprt_release(struct rpc_task *task) xprt = req->rq_xprt; xprt_request_dequeue_xprt(task); spin_lock(&xprt->transport_lock); + if (unlikely(req->rq_disconnect_on_release)) { + req->rq_disconnect_on_release = false; + /* + * Dequeue may skip queue_lock. Pair with the fully ordered + * test_and_clear_bit(RPC_TASK_NEED_XMIT) in + * xprt_request_dequeue_transmit_locked() to order the runstate + * check before reading the sender's rq_ntrans and + * rq_connect_cookie updates. + */ + smp_rmb(); + if (req->rq_ntrans > 0) + xprt_conditional_disconnect_locked(xprt, + req->rq_connect_cookie); + } xprt->ops->release_xprt(xprt, task); if (xprt->ops->release_request) xprt->ops->release_request(task); @@ -2020,6 +2114,7 @@ xprt_init_bc_request(struct rpc_rqst *req, struct rpc_task *task, task->tk_rqstp = req; req->rq_task = task; xprt_init_connect_cookie(req, req->rq_xprt); + req->rq_disconnect_on_release = false; /* * Set up the xdr_buf length. * This also indicates that the buffer is XDR encoded already. diff --git a/net/sunrpc/xprtrdma/frwr_ops.c b/net/sunrpc/xprtrdma/frwr_ops.c index e83cef19e6569a..97034a3b5141d7 100644 --- a/net/sunrpc/xprtrdma/frwr_ops.c +++ b/net/sunrpc/xprtrdma/frwr_ops.c @@ -27,13 +27,17 @@ /* Transport recovery * - * frwr_map and frwr_unmap_* cannot run at the same time the transport - * connect worker is running. The connect worker holds the transport - * send lock, just as ->send_request does. This prevents frwr_map and - * the connect worker from running concurrently. When a connection is - * closed, the Receive completion queue is drained before the allowing - * the connect worker to get control. This prevents frwr_unmap and the - * connect worker from running concurrently. + * frwr_map() is serialized with the connect worker by the transport + * send lock. + * + * frwr_unmap_async() runs from Receive completion processing. + * rpcrdma_xprt_drain() drains the Receive Queue before the Send Queue, + * so asynchronous LOCAL_INV Work Requests are submitted before Send + * Queue drain. + * + * frwr_unmap_sync() runs after the transport send lock is released. + * rx_unmap_rwsem orders its LOCAL_INV submission before disconnect + * drains the QP. * * When the underlying transport disconnects, MRs that are in flight * are flushed and are likely unusable. Thus all MRs are destroyed. @@ -139,7 +143,6 @@ int frwr_mr_init(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr *mr) mr->mr_ibmr = frmr; mr->mr_device = NULL; INIT_LIST_HEAD(&mr->mr_list); - init_completion(&mr->mr_linv_done); frwr_cid_init(ep, mr); sg_init_table(sg, depth); @@ -539,40 +542,60 @@ static void frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) * @cq: completion queue * @wc: WCE for a completed LocalInv WR * - * Awaken anyone waiting for an MR to finish being fenced. + * Wake frwr_unmap_sync() after the final LOCAL_INV completion. */ static void frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) { struct ib_cqe *cqe = wc->wr_cqe; struct rpcrdma_mr *mr = container_of(cqe, struct rpcrdma_mr, mr_cqe); + struct rpcrdma_req *req = mr->mr_req; /* WARNING: Only wr_cqe and status are reliable at this point */ trace_xprtrdma_wc_li_wake(wc, &mr->mr_cid); frwr_mr_done(wc, mr); - complete(&mr->mr_linv_done); + complete(&req->rl_linv_done); rpcrdma_flush_disconnect(cq->cq_context, wc); } /** - * frwr_unmap_sync - invalidate memory regions that were registered for @req + * frwr_unmap_sync - synchronously invalidate MRs registered for @req * @r_xprt: controlling transport instance - * @req: rpcrdma_req with a non-empty list of MRs to process + * @req: request whose registered MRs are to be invalidated * - * Sleeps until it is safe for the host CPU to access the previously mapped - * memory regions. This guarantees that registered MRs are properly fenced - * from the server before the RPC consumer accesses the data in them. It - * also ensures proper Send flow control: waking the next RPC waits until - * this RPC has relinquished all its Send Queue entries. + * If @req still owns registered MRs after synchronizing with transport + * disconnect, post a chain of LOCAL_INV Work Requests and wait for the + * final completion. On successful completion, this fences the mapped + * regions from remote access and preserves Send Queue flow control. + * + * A concurrent disconnect can reset @req while this function waits for + * the read side. In that case the MRs have already been released and no + * LOCAL_INV Work Requests are posted. + * + * Context: Process context. Takes and releases + * @r_xprt->rx_unmap_rwsem for read. May sleep. */ void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) { struct ib_send_wr *first, **prev, *last; - struct rpcrdma_ep *ep = r_xprt->rx_ep; const struct ib_send_wr *bad_wr; + struct rpcrdma_ep *ep; struct rpcrdma_mr *mr; int rc; + /* serialize against rpcrdma_xprt_disconnect() */ + down_read(&r_xprt->rx_unmap_rwsem); + + /* + * Disconnect can reset this request while we wait for the read side. + * Recheck rl_registered in case rx_ep now refers to a new connection. + */ + ep = r_xprt->rx_ep; + if (!ep || list_empty(&req->rl_registered)) { + up_read(&r_xprt->rx_unmap_rwsem); + return; + } + /* ORDER: Invalidate all of the MRs first * * Chain the LOCAL_INV Work Requests and post them with @@ -599,37 +622,35 @@ void frwr_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) prev = &last->next; } while ((mr = rpcrdma_mr_pop(&req->rl_registered))); - mr = container_of(last, struct rpcrdma_mr, mr_invwr); - /* Strong send queue ordering guarantees that when the * last WR in the chain completes, all WRs in the chain * are complete. */ last->wr_cqe->done = frwr_wc_localinv_wake; - reinit_completion(&mr->mr_linv_done); + reinit_completion(&req->rl_linv_done); - /* Transport disconnect drains the receive CQ before it - * replaces the QP. The RPC reply handler won't call us - * unless re_id->qp is a valid pointer. + /* + * The read side prevents disconnect from draining this QP until the + * LOCAL_INV chain has been submitted. */ bad_wr = NULL; rc = ib_post_send(ep->re_id->qp, first, &bad_wr); + if (rc) { + /* On error, the MRs get destroyed once the QP has drained. */ + trace_xprtrdma_post_linv_err(req, rc); + + /* Force a connection loss to ensure complete recovery. + */ + rpcrdma_force_disconnect(ep); + } + up_read(&r_xprt->rx_unmap_rwsem); /* The final LOCAL_INV WR in the chain is supposed to * do the wake. If it was never posted, the wake will * not happen, so don't wait in that case. */ if (bad_wr != first) - wait_for_completion(&mr->mr_linv_done); - if (!rc) - return; - - /* On error, the MRs get destroyed once the QP has drained. */ - trace_xprtrdma_post_linv_err(req, rc); - - /* Force a connection loss to ensure complete recovery. - */ - rpcrdma_force_disconnect(ep); + wait_for_completion(&req->rl_linv_done); } /** diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index d4e6746d8ecd3e..e38637c2ec787d 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -364,6 +364,8 @@ xprt_setup_rdma(struct xprt_create *args) INIT_DELAYED_WORK(&new_xprt->rx_connect_worker, xprt_rdma_connect_worker); + init_rwsem(&new_xprt->rx_unmap_rwsem); + xprt->max_payload = RPCRDMA_MAX_DATA_SEGS << PAGE_SHIFT; return xprt; diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 54957295a6310c..620afff79effa3 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -572,20 +572,24 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt) * rpcrdma_xprt_disconnect - Disconnect underlying transport * @r_xprt: controlling transport instance * - * Caller serializes. Either the transport send lock is held, - * or we're being called to destroy the transport. + * Context: Caller serializes. Either the transport send lock is held, + * or the transport is being destroyed. Takes and releases + * @r_xprt->rx_unmap_rwsem for write. May sleep. * * On return, @r_xprt is completely divested of all hardware * resources and prepared for the next ->connect operation. */ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt) { - struct rpcrdma_ep *ep = r_xprt->rx_ep; + struct rpcrdma_ep *ep; struct rdma_cm_id *id; int rc; + down_write(&r_xprt->rx_unmap_rwsem); + + ep = r_xprt->rx_ep; if (!ep) - return; + goto out_unlock; /* Prevent teardown-generated events from requesting another close. */ atomic_xchg(&ep->re_force_disconnect, 1); @@ -604,6 +608,9 @@ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt) rdma_destroy_id(id); r_xprt->rx_ep = NULL; + +out_unlock: + up_write(&r_xprt->rx_unmap_rwsem); } /* Fixed-size circular FIFO queue. This implementation is wait-free and @@ -927,6 +934,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, INIT_LIST_HEAD(&req->rl_free_mrs); INIT_LIST_HEAD(&req->rl_registered); + init_completion(&req->rl_linv_done); spin_lock(&buffer->rb_lock); list_add(&req->rl_all, &buffer->rb_allreqs); spin_unlock(&buffer->rb_lock); diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index 4cbc941e4a3eba..b3016e1eb17236 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -46,6 +46,7 @@ #include /* spinlock_t, etc */ #include /* atomic_t, etc */ #include /* struct kref */ +#include /* struct rw_semaphore */ #include /* struct work_struct */ #include @@ -249,7 +250,6 @@ struct rpcrdma_mr { int mr_nents; enum dma_data_direction mr_dir; struct ib_cqe mr_cqe; - struct completion mr_linv_done; union { struct ib_reg_wr mr_regwr; struct ib_send_wr mr_invwr; @@ -348,6 +348,7 @@ struct rpcrdma_req { struct list_head rl_free_mrs; struct list_head rl_registered; + struct completion rl_linv_done; }; static inline struct rpcrdma_req * @@ -449,6 +450,13 @@ struct rpcrdma_xprt { struct delayed_work rx_connect_worker; struct rpc_timeout rx_timeout; struct rpcrdma_stats rx_stats; + + /* + * Orders frwr_unmap_sync()'s LOCAL_INV submission ahead of the + * QP drain. Disconnect holds the write side across the drain + * and resource teardown. + */ + struct rw_semaphore rx_unmap_rwsem; }; #define rpcx_to_rdmax(x) container_of(x, struct rpcrdma_xprt, rx_xprt) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 027b37de694b23..173e3b0fd7a3b4 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -3501,7 +3501,7 @@ static struct rpc_xprt *xs_setup_tcp_tls(struct xprt_create *args) transport = container_of(xprt, struct sock_xprt, xprt); xprt->prot = IPPROTO_TCP; - xprt->xprt_class = &xs_tcp_transport; + xprt->xprt_class = &xs_tcp_tls_transport; xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; xprt->bind_timeout = XS_BIND_TO; diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 774f68d1a2b380..bad8a513d91ce9 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -287,17 +287,50 @@ static int tipc_enable_bearer(struct net *net, const char *name, bearer_id = MAX_BEARERS; i = MAX_BEARERS; while (i-- != 0) { + struct net_device *dev; + b = rtnl_dereference(tn->bearer_list[i]); if (!b) { bearer_id = i; continue; } if (!strcmp(name, b->name)) { +duplicate: errstr = "already enabled"; NL_SET_ERR_MSG(extack, "Already enabled"); goto rejected; } + /* udp media can be used together with any media */ + if (b->media->type_id == TIPC_MEDIA_TYPE_UDP || + m->type_id == TIPC_MEDIA_TYPE_UDP) + goto priority; + + dev = __dev_get_by_name(net, b_names.if_name); + + if (!dev) { + res = -ENODEV; + errstr = "no device for the media"; + NL_SET_ERR_MSG(extack, "No device for the media"); + goto rejected; + } + + if (rtnl_dereference(b->media_ptr) == dev) { + char *dev_name = strchr((const char *)b->name, ':') + 1; + + /* Not allow altname of occupied device */ + if (strcmp(dev_name, b_names.if_name) && + b->media->type_id == m->type_id) + goto duplicate; + + /* Not allow eth and ib to attach to the same device */ + errstr = "same dev for different media"; + NL_SET_ERR_MSG(extack, + "Same dev for different media"); + goto rejected; + } + +priority: if (b->priority == prio && (++with_this_prio > 2)) { pr_warn("Bearer <%s>: already 2 bearers with priority %u\n", @@ -546,9 +579,22 @@ int tipc_bearer_mtu(struct net *net, u32 bearer_id) return mtu; } +/* tipc_bearer_mtu_floor - smallest bearer MTU, excluding the media + * encapsulation header, that leaves room for a fragment header plus a + * full message header after the link MSS reductions (see tipc_link_mss()) + */ +u32 tipc_bearer_mtu_floor(void) +{ +#ifdef CONFIG_TIPC_CRYPTO + return TIPC_MIN_BEARER_MTU + EMSG_OVERHEAD; +#else + return TIPC_MIN_BEARER_MTU; +#endif +} + int tipc_bearer_min_mtu(struct net *net, u32 bearer_id) { - int mtu = TIPC_MIN_BEARER_MTU; + int mtu = tipc_bearer_mtu_floor(); struct tipc_bearer *b; rcu_read_lock(); @@ -1164,7 +1210,7 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) } #ifdef CONFIG_TIPC_MEDIA_UDP if (nla_get_u32(props[TIPC_NLA_PROP_MTU]) < - b->encap_hlen + TIPC_MIN_BEARER_MTU) { + b->encap_hlen + tipc_bearer_mtu_floor()) { NL_SET_ERR_MSG(info->extack, "MTU value is out-of-range"); return -EINVAL; diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index f9bfcc9a776522..72abfcac90cb71 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -60,8 +60,10 @@ #define TIPC_MEDIA_TYPE_IB 2 #define TIPC_MEDIA_TYPE_UDP 3 -/* Minimum bearer MTU */ -#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE) +/* Minimum bearer MTU, not counting the crypto overhead, see + * tipc_bearer_mtu_floor() + */ +#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + 2 * INT_H_SIZE) /* Maximum bearer MTU * @@ -241,6 +243,7 @@ void tipc_bearer_cleanup(void); void tipc_bearer_stop(struct net *net); int tipc_bearer_mtu(struct net *net, u32 bearer_id); int tipc_bearer_min_mtu(struct net *net, u32 bearer_id); +u32 tipc_bearer_mtu_floor(void); bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id); void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id, struct sk_buff *skb, @@ -265,7 +268,7 @@ static inline void tipc_loopback_trace(struct net *net, /* check if device MTU is usable for tipc bearers */ static inline bool tipc_mtu_bad(struct net_device *dev) { - if (dev->mtu >= TIPC_MIN_BEARER_MTU && + if (dev->mtu >= tipc_bearer_mtu_floor() && dev->mtu <= TIPC_MAX_BEARER_MTU) return false; netdev_warn(dev, "MTU not usable for tipc bearer\n"); diff --git a/net/tipc/udp_media.h b/net/tipc/udp_media.h index e7455cc73e16c0..030e00ad1629f5 100644 --- a/net/tipc/udp_media.h +++ b/net/tipc/udp_media.h @@ -48,7 +48,7 @@ int tipc_udp_nl_dump_remoteip(struct sk_buff *skb, struct netlink_callback *cb); /* check if configured MTU is too low for tipc headers */ static inline bool tipc_udp_mtu_bad(u32 mtu) { - if (mtu >= (TIPC_MIN_BEARER_MTU + sizeof(struct iphdr) + + if (mtu >= (tipc_bearer_mtu_floor() + sizeof(struct iphdr) + sizeof(struct udphdr))) return false; diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 771e02bff51999..226e0f176fdc8a 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -436,7 +436,8 @@ int tls_tx_records(struct sock *sk, int flags) /* Tx all ready records */ list_for_each_entry_safe(rec, tmp, &ctx->tx_list, list) { - if (READ_ONCE(rec->tx_ready)) { + /* Pairs with smp_store_release() in tls_encrypt_done() */ + if (smp_load_acquire(&rec->tx_ready)) { if (flags == -1) tx_flags = rec->tx_flags; else @@ -504,8 +505,14 @@ static void tls_encrypt_done(void *data, int err) if (rec) { struct tls_rec *first_rec; - /* Mark the record as ready for transmission */ - smp_store_mb(rec->tx_ready, true); + /* Mark the record as ready for transmission. Pairs with + * smp_load_acquire() in tls_tx_records(): the sge + * offset/length update above must be visible before tx_ready. + */ + smp_store_release(&rec->tx_ready, true); + + /* Order the tx_ready store before the tx_list head check */ + smp_mb(); /* If received record is at head of tx_list, schedule tx */ first_rec = list_first_entry(&ctx->tx_list, @@ -1146,6 +1153,7 @@ tls_rx_rec_wait(struct sock *sk, bool nonblock, bool released, bool has_copied) if (!timeo) return -EAGAIN; + ctx->empty_run = 0; released = true; add_wait_queue(sk_sleep(sk), &wait); sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); @@ -1565,6 +1573,7 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg, struct tls_decrypt_arg *darg) { struct tls_context *tls_ctx = tls_get_ctx(sk); + struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx); struct tls_prot_info *prot = &tls_ctx->prot_info; struct strp_msg *rxm; int err; @@ -1582,6 +1591,19 @@ static int tls_rx_one_record(struct sock *sk, struct msghdr *msg, rxm->full_len -= prot->overhead_size; tls_advance_record_sn(sk, prot, &tls_ctx->rx); + /* A peer may send empty data records, e.g. as cover traffic, but + * a burst of them traps the reader in the kernel. Treat more than + * 128 in a row, without the reader sleeping or returning to the + * caller in between, as a protocol violation. Stop the strparser + * before the next record gets parsed, so the reader finds the + * error in tls_rx_rec_wait(). + */ + if (rxm->full_len || + tls_msg(darg->skb)->control != TLS_RECORD_TYPE_DATA) + ctx->empty_run = 0; + else if (unlikely(++ctx->empty_run > 128)) + tls_strp_abort_strp(&ctx->strp, -EBADMSG); + return tls_check_pending_rekey(sk, tls_ctx, darg->skb); } @@ -1761,6 +1783,7 @@ static int tls_rx_reader_acquire(struct sock *sk, struct tls_sw_context_rx *ctx, } WRITE_ONCE(ctx->reader_present, 1); + ctx->empty_run = 0; return 0; } @@ -1874,9 +1897,11 @@ int tls_sw_recvmsg(struct sock *sk, tlm->control == TLS_RECORD_TYPE_DATA) darg.zc = true; - /* Do not use async mode if record is non-data */ + /* Do not use async mode if record is non-data or empty, + * recv_end would report an error after empty records as EOF. + */ if (tlm->control == TLS_RECORD_TYPE_DATA) - darg.async = ctx->async_capable; + darg.async = ctx->async_capable && to_decrypt; else darg.async = false; @@ -1918,7 +1943,10 @@ int tls_sw_recvmsg(struct sock *sk, DEBUG_NET_WARN_ON_ONCE(darg.skb == ctx->strp.anchor); - if (async) { + /* Consume empty records, even when peeking, so that + * they cannot pile up on rx_list. + */ + if (async && chunk) { /* TLS 1.2-only, to_decrypt must be text len */ chunk = min_t(int, to_decrypt, len); async_copy_bytes += chunk; @@ -1939,7 +1967,7 @@ int tls_sw_recvmsg(struct sock *sk, if (err < 0) goto put_on_rx_list_err; - if (is_peek) { + if (is_peek && chunk) { peeked += chunk; goto put_on_rx_list; } @@ -2023,32 +2051,40 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, if (err) goto splice_read_end; - if (!skb_queue_empty(&ctx->rx_list)) { - skb = __skb_dequeue(&ctx->rx_list); - } else { - struct tls_decrypt_arg darg; + for (;;) { + if (!skb_queue_empty(&ctx->rx_list)) { + skb = __skb_dequeue(&ctx->rx_list); + } else { + struct tls_decrypt_arg darg; - err = tls_rx_rec_wait(sk, nonblock, true, false); - if (err <= 0) - goto splice_read_end; + err = tls_rx_rec_wait(sk, nonblock, true, false); + if (err <= 0) + goto splice_read_end; - memset(&darg.inargs, 0, sizeof(darg.inargs)); + memset(&darg.inargs, 0, sizeof(darg.inargs)); - err = tls_rx_one_record(sk, NULL, &darg); - if (err < 0) - goto splice_read_end; + err = tls_rx_one_record(sk, NULL, &darg); + if (err < 0) + goto splice_read_end; - tls_rx_rec_done(ctx); - skb = darg.skb; - } + tls_rx_rec_done(ctx); + skb = darg.skb; + } - rxm = strp_msg(skb); - tlm = tls_msg(skb); + rxm = strp_msg(skb); + tlm = tls_msg(skb); - /* splice does not support reading control messages */ - if (tlm->control != TLS_RECORD_TYPE_DATA) { - err = -EINVAL; - goto splice_requeue; + /* splice does not support reading control messages */ + if (tlm->control != TLS_RECORD_TYPE_DATA) { + err = -EINVAL; + goto splice_requeue; + } + + /* Splicing zero bytes would read as EOF */ + if (rxm->full_len) + break; + + consume_skb(skb); } chunk = min_t(unsigned int, rxm->full_len, len); @@ -2594,7 +2630,8 @@ int tls_set_sw_offload(struct sock *sk, int tx, } } - ctx->push_pending_record = tls_sw_push_pending_record; + if (tx) + ctx->push_pending_record = tls_sw_push_pending_record; /* setkey is the last operation that could fail during a * rekey. if it succeeds, we can start modifying the diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 98fcfd7301f6b2..f847cf1fbeafec 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1750,6 +1750,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr_unsized *uad newu = unix_sk(newsk); otheru = unix_sk(other); newu->listener = other; + newu->recvmsg_inq = READ_ONCE(otheru->recvmsg_inq); newu->scm_rights_notrunc = READ_ONCE(otheru->scm_rights_notrunc); RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq); diff --git a/net/unix/garbage.c b/net/unix/garbage.c index da774f56ca648b..fbeabfb0db34e8 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c @@ -78,9 +78,9 @@ struct unix_vertex { struct list_head edges; struct list_head entry; struct list_head scc_entry; - unsigned long out_degree; - unsigned long index; - unsigned long scc_index; + u64 out_degree; + u64 index; + u64 scc_index; }; struct unix_edge { @@ -148,8 +148,8 @@ enum unix_vertex_index { UNIX_VERTEX_INDEX_START, }; -static unsigned long unix_vertex_unvisited_index = UNIX_VERTEX_INDEX_MARK1; -static unsigned long unix_vertex_max_scc_index = UNIX_VERTEX_INDEX_START; +static u64 unix_vertex_unvisited_index = UNIX_VERTEX_INDEX_MARK1; +static u64 unix_vertex_max_scc_index = UNIX_VERTEX_INDEX_START; static void unix_add_edge(struct scm_fp_list *fpl, struct unix_edge *edge) { @@ -329,9 +329,6 @@ void unix_peek_fpl(struct scm_fp_list *fpl) if (!fpl || !fpl->count_unix) return; - if (!READ_ONCE(gc_in_progress)) - return; - /* Invalidate the final refcnt check in unix_vertex_dead(). */ spin_lock(&unix_peek_lock); raw_write_seqcount_barrier(&unix_peek_seq); @@ -372,7 +369,7 @@ static bool unix_vertex_dead(struct unix_vertex *vertex) } static LIST_HEAD(unix_visited_vertices); -static unsigned long unix_vertex_grouped_index = UNIX_VERTEX_INDEX_MARK2; +static u64 unix_vertex_grouped_index = UNIX_VERTEX_INDEX_MARK2; static bool unix_scc_dead(struct list_head *scc) { @@ -450,14 +447,14 @@ static bool unix_scc_cyclic(struct list_head *scc) return false; } -static unsigned long __unix_walk_scc(struct unix_vertex *vertex, - unsigned long *last_index, - struct sk_buff_head *hitlist) +static u64 __unix_walk_scc(struct unix_vertex *vertex, + u64 *last_index, + struct sk_buff_head *hitlist) { - unsigned long cyclic_sccs = 0; LIST_HEAD(vertex_stack); struct unix_edge *edge; LIST_HEAD(edge_stack); + u64 cyclic_sccs = 0; next_vertex: /* Push vertex to vertex_stack and mark it as on-stack @@ -553,12 +550,12 @@ static unsigned long __unix_walk_scc(struct unix_vertex *vertex, return cyclic_sccs; } -static unsigned long unix_graph_cyclic_sccs; +static u64 unix_graph_cyclic_sccs; static void unix_walk_scc(struct sk_buff_head *hitlist) { - unsigned long last_index = UNIX_VERTEX_INDEX_START; - unsigned long cyclic_sccs = 0; + u64 last_index = UNIX_VERTEX_INDEX_START; + u64 cyclic_sccs = 0; unix_vertex_max_scc_index = UNIX_VERTEX_INDEX_START; @@ -582,7 +579,7 @@ static void unix_walk_scc(struct sk_buff_head *hitlist) static void unix_walk_scc_fast(struct sk_buff_head *hitlist) { - unsigned long cyclic_sccs = unix_graph_cyclic_sccs; + u64 cyclic_sccs = unix_graph_cyclic_sccs; while (!list_empty(&unix_unvisited_vertices)) { struct unix_vertex *vertex; diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index d0508887a2fbac..1d7d53542724f3 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -2156,7 +2156,8 @@ static int vsock_connectible_setsockopt(struct socket *sock, optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD); if (err) break; - if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC && + if (tv.tv_sec >= 0 && tv.tv_usec >= 0 && + tv.tv_usec < USEC_PER_SEC && tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) { vsk->connect_timeout = tv.tv_sec * HZ + DIV_ROUND_UP((unsigned long)tv.tv_usec, (USEC_PER_SEC / HZ)); diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c index 855b15971c359f..551eabe690144d 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -697,6 +697,9 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk) struct hvsock *hvs = vsk->trans; s64 ret; + if (!hvs->chan) + return 0; + if (hvs->recv_data_len > 0) return hvs->recv_data_len; diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 4f9aa9c4c3aa59..cf63bc99f3cc7f 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -714,8 +714,10 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock) atomic_set(&vsock->queued_replies, 0); ret = virtio_find_vqs(vdev, VSOCK_VQ_MAX, vsock->vqs, vqs_info, NULL); - if (ret < 0) + if (ret < 0) { + memset(vsock->vqs, 0, sizeof(vsock->vqs)); return ret; + } virtio_vsock_update_guest_cid(vsock); @@ -776,11 +778,19 @@ static void virtio_vsock_vqs_del(struct virtio_vsock *vsock) vsock->event_run = false; mutex_unlock(&vsock->event_lock); + virtio_vsock_skb_queue_purge(&vsock->send_pkt_queue); + /* Flush all device writes and interrupts, device will not use any * more buffers. */ virtio_reset_device(vdev); + /* After a failed restore no virtqueues are live, and a second + * del_vqs() would free virtio-mmio's IRQ again (a WARN in free_irq()). + */ + if (!vsock->vqs[VSOCK_VQ_RX]) + return; + mutex_lock(&vsock->rx_lock); while ((skb = virtqueue_detach_unused_buf(vsock->vqs[VSOCK_VQ_RX]))) kfree_skb(skb); @@ -791,10 +801,10 @@ static void virtio_vsock_vqs_del(struct virtio_vsock *vsock) kfree_skb(skb); mutex_unlock(&vsock->tx_lock); - virtio_vsock_skb_queue_purge(&vsock->send_pkt_queue); - /* Delete virtqueues and flush outstanding callbacks if any */ vdev->config->del_vqs(vdev); + + memset(vsock->vqs, 0, sizeof(vsock->vqs)); } static int virtio_vsock_probe(struct virtio_device *vdev) diff --git a/net/wireless/core.c b/net/wireless/core.c index f4153c24959973..4e39db0c595cd0 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -328,8 +328,7 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev, * schedule on allocation failure. */ if (sched->n_channels) { - chandefs = kcalloc(sched->n_channels, sizeof(*chandefs), - GFP_KERNEL); + chandefs = kzalloc_objs(*chandefs, sched->n_channels); if (!chandefs) return -ENOMEM; @@ -1944,7 +1943,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, return NOTIFY_DONE; } - wireless_nlevent_flush(); + wireless_nlevent_flush(dev_net(dev)); return NOTIFY_OK; } diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 80ca9031d29cb7..b7c67ea7c540c2 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -1170,7 +1170,7 @@ void cfg80211_dfs_channels_update_work(struct work_struct *work) n_chans += wiphy->bands[bandid]->n_channels; } - expired = kvcalloc(n_chans, sizeof(*expired), GFP_KERNEL); + expired = kvzalloc_objs(*expired, n_chans); if (!expired) { /* hmm - retry later */ queue_delayed_work(cfg80211_wq, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index d790e204aee364..e7dd32880598fd 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -4679,9 +4679,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) return -EOPNOTSUPP; if (rdev->wiphy.n_radio) { - old_radio_rts_threshold = kcalloc(rdev->wiphy.n_radio, - sizeof(u32), - GFP_KERNEL); + old_radio_rts_threshold = kzalloc_objs(u32, + rdev->wiphy.n_radio); if (!old_radio_rts_threshold) return -ENOMEM; } @@ -9029,10 +9028,8 @@ static int nl80211_dump_station(struct sk_buff *skb, /* this fails if the wdev is being removed */ wdev = __nl80211_lock_held_wdev(rdev, netns, wdev); - if (IS_ERR(wdev)) { - err = PTR_ERR(wdev); - goto out_err; - } + if (IS_ERR(wdev)) + return PTR_ERR(wdev); /* try again locked now */ locked = true; @@ -18297,8 +18294,7 @@ nl80211_parse_non_evac_channel(struct cfg80211_registered_device *rdev, struct cfg80211_chan_def *chandef) { struct nlattr **channel_parsed __free(kfree) = - kcalloc(NL80211_ATTR_MAX + 1, sizeof(*channel_parsed), - GFP_KERNEL); + kzalloc_objs(*channel_parsed, NL80211_ATTR_MAX + 1); int ret; if (!channel_parsed) @@ -18333,8 +18329,7 @@ static int nl80211_nan_set_non_evac_channels(struct sk_buff *skb, n_channels++; struct cfg80211_nan_non_evac_channels *channels __free(kfree) = - kzalloc(struct_size(channels, chandefs, n_channels), - GFP_KERNEL); + kzalloc_flex(*channels, chandefs, n_channels); if (!channels) return -ENOMEM; diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 50f50e768f014c..5cd3880ee3841d 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -680,6 +680,9 @@ static bool valid_rule(const u8 *data, unsigned int size, u16 rule_ptr) /* mandatory fields */ if (rule->len < offsetofend(struct fwdb_rule, max_bw)) return false; + /* the rule must lie entirely within the database */ + if ((u8 *)rule + rule->len > data + size) + return false; if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) { u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; struct fwdb_wmm_rule *wmm; diff --git a/net/wireless/scan.c b/net/wireless/scan.c index ac56338f0f432a..1c50a16c0e9bea 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2453,6 +2453,7 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy, if (cfg80211_add_nontrans_list(data->source_bss, &res->pub)) { if (__cfg80211_unlink_bss(rdev, res)) { rdev->bss_generation++; + bss_ref_put(rdev, res); res = NULL; } } @@ -2592,7 +2593,7 @@ cfg80211_parse_mbssid_data(struct wiphy *wiphy, if (elem->data[0] < 1 || (int)elem->data[0] > 8) continue; for_each_element(sub, elem->data + 1, elem->datalen - 1) { - u8 profile_len; + size_t profile_len; if (sub->id != 0 || sub->datalen < 4) { /* not a valid BSS profile */ diff --git a/net/wireless/util.c b/net/wireless/util.c index 59912f4a93c88e..ebb1f6ec7efccd 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -863,12 +863,12 @@ __ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen, return frame; } -static u16 +static unsigned int ieee80211_amsdu_subframe_length(void *field, u8 mesh_flags, u8 hdr_type) { __le16 *field_le = field; __be16 *field_be = field; - u16 len; + unsigned int len; if (hdr_type >= 2) len = le16_to_cpu(*field_le); @@ -890,7 +890,7 @@ bool ieee80211_is_valid_amsdu(struct sk_buff *skb, u8 mesh_hdr) __be16 len; u8 mesh_flags; } hdr; - u16 len; + unsigned int len; if (sizeof(hdr) > remaining) return false; diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c index db77912b3994bc..f09c589ff94cdf 100644 --- a/net/wireless/wext-core.c +++ b/net/wireless/wext-core.c @@ -342,32 +342,28 @@ static const int compat_event_type_size[] = { /* IW event code */ -void wireless_nlevent_flush(void) +void wireless_nlevent_flush(struct net *net) { struct sk_buff *skb; - struct net *net; - down_read(&net_rwsem); - for_each_net(net) { - while ((skb = skb_dequeue(&net->wext_nlevents))) - rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, - GFP_KERNEL); - } - up_read(&net_rwsem); + while ((skb = skb_dequeue(&net->wext_nlevents))) + rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); } EXPORT_SYMBOL_GPL(wireless_nlevent_flush); static int wext_netdev_notifier_call(struct notifier_block *nb, unsigned long state, void *ptr) { + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + /* - * When a netdev changes state in any way, flush all pending messages - * to avoid them going out in a strange order, e.g. RTM_NEWLINK after - * RTM_DELLINK, or with IFF_UP after without IFF_UP during dev_close() - * or similar - all of which could otherwise happen due to delays from - * schedule_work(). + * When a netdev changes state in any way, flush all pending messages in + * its network namespace to avoid them going out in a strange order, + * e.g. RTM_NEWLINK after RTM_DELLINK, or with IFF_UP after without + * IFF_UP during dev_close() or similar - all of which could otherwise + * happen due to delays from schedule_work(). */ - wireless_nlevent_flush(); + wireless_nlevent_flush(dev_net(dev)); return NOTIFY_OK; } @@ -410,7 +406,12 @@ subsys_initcall(wireless_nlevent_init); /* Process events generated by the wireless layer or the driver. */ static void wireless_nlevent_process(struct work_struct *work) { - wireless_nlevent_flush(); + struct net *net; + + down_read(&net_rwsem); + for_each_net(net) + wireless_nlevent_flush(net); + up_read(&net_rwsem); } static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process); diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 781ba46eb15257..f22f9a2cdbbeae 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -241,6 +241,7 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len) goto err; } + xdp_buff_clear_frags_flag(xdp); __xsk_rcv_zc_safe(xs, xskb, len, contd); xskb_list = &xskb->pool->xskb_list; list_for_each_entry_safe(pos, tmp, xskb_list, list_node) { @@ -1011,14 +1012,6 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, skb->csum_start = hr + csum_start; skb->csum_offset = csum_offset; skb->ip_summed = CHECKSUM_PARTIAL; - - if (unlikely(pool->tx_sw_csum)) { - int err; - - err = skb_checksum_help(skb); - if (err) - return err; - } } if (flags & XDP_TXMD_FLAGS_LAUNCH_TIME) @@ -1030,6 +1023,15 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, return 0; } +static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool) +{ + if (unlikely(pool->tx_sw_csum && + skb->ip_summed == CHECKSUM_PARTIAL)) + return skb_checksum_help(skb); + + return 0; +} + static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs, struct xdp_desc *desc) { @@ -1277,6 +1279,12 @@ static int __xsk_generic_xmit(struct sock *sk) continue; } + err = xsk_skb_sw_csum(skb, xs->pool); + if (unlikely(err)) { + xsk_drop_skb(skb); + goto out; + } + err = __dev_direct_xmit(skb, xs->queue_id); if (err == NETDEV_TX_BUSY) { /* Tell user-space to retry the send */ diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 7750d2ec4ee246..5ec092f7cb6f7a 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -629,7 +629,7 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool) xskb->xdp.data = xskb->xdp.data_hard_start + XDP_PACKET_HEADROOM; xskb->xdp.data_meta = xskb->xdp.data; - xskb->xdp.flags = 0; + xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS; if (pool->dev) xp_dma_sync_for_device(pool, xskb->dma, pool->frame_len); diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c index 3e72b9f067b9be..4052ae5bbb2ea5 100644 --- a/net/xfrm/espintcp.c +++ b/net/xfrm/espintcp.c @@ -434,7 +434,9 @@ static void espintcp_destruct(struct sock *sk) bool tcp_is_ulp_esp(struct sock *sk) { - return sk->sk_prot == &espintcp_prot || sk->sk_prot == &espintcp6_prot; + const struct proto *prot = READ_ONCE(sk->sk_prot); + + return prot == &espintcp_prot || prot == &espintcp6_prot; } EXPORT_SYMBOL_GPL(tcp_is_ulp_esp); @@ -466,34 +468,41 @@ static int espintcp_init_sk(struct sock *sk) __sk_dst_reset(sk); - strp_check_rcv(&ctx->strp); skb_queue_head_init(&ctx->ike_queue); skb_queue_head_init(&ctx->out_queue); + INIT_WORK(&ctx->work, espintcp_tx_work); + + ctx->saved_data_ready = sk->sk_data_ready; + ctx->saved_write_space = sk->sk_write_space; + ctx->saved_destruct = sk->sk_destruct; + + /* avoid using task_frag */ + sk->sk_allocation = GFP_ATOMIC; + sk->sk_use_task_frag = false; + + rcu_assign_pointer(icsk->icsk_ulp_data, ctx); + + /* pairs with smp_rmb() in espintcp_getctx() */ + smp_wmb(); + + WRITE_ONCE(sk->sk_data_ready, espintcp_data_ready); + WRITE_ONCE(sk->sk_write_space, espintcp_write_space); + sk->sk_destruct = espintcp_destruct; if (sk->sk_family == AF_INET) { - sk->sk_prot = &espintcp_prot; - sk->sk_socket->ops = &espintcp_ops; + WRITE_ONCE(sk->sk_prot, &espintcp_prot); + WRITE_ONCE(sk->sk_socket->ops, &espintcp_ops); } else { mutex_lock(&tcpv6_prot_mutex); if (!espintcp6_prot.recvmsg) build_protos(&espintcp6_prot, &espintcp6_ops, sk->sk_prot, sk->sk_socket->ops); mutex_unlock(&tcpv6_prot_mutex); - sk->sk_prot = &espintcp6_prot; - sk->sk_socket->ops = &espintcp6_ops; + WRITE_ONCE(sk->sk_prot, &espintcp6_prot); + WRITE_ONCE(sk->sk_socket->ops, &espintcp6_ops); } - ctx->saved_data_ready = sk->sk_data_ready; - ctx->saved_write_space = sk->sk_write_space; - ctx->saved_destruct = sk->sk_destruct; - sk->sk_data_ready = espintcp_data_ready; - sk->sk_write_space = espintcp_write_space; - sk->sk_destruct = espintcp_destruct; - rcu_assign_pointer(icsk->icsk_ulp_data, ctx); - INIT_WORK(&ctx->work, espintcp_tx_work); - /* avoid using task_frag */ - sk->sk_allocation = GFP_ATOMIC; - sk->sk_use_task_frag = false; + strp_check_rcv(&ctx->strp); return 0; diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c index 688306bf62c5ae..9835fbe63ccb83 100644 --- a/net/xfrm/xfrm_interface_core.c +++ b/net/xfrm/xfrm_interface_core.c @@ -531,8 +531,13 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) memset(&fl, 0, sizeof(fl)); + if (!pskb_inet_may_pull(skb)) + goto tx_err; + switch (skb->protocol) { case htons(ETH_P_IPV6): + if (ipv6_hdr(skb)->version != 6) + goto tx_err; memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6); if (!dst) { @@ -548,6 +553,9 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) } break; case htons(ETH_P_IP): + if (ip_hdr(skb)->version != 4 || ip_hdr(skb)->ihl < 5 || + !pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4)) + goto tx_err; memset(IPCB(skb), 0, sizeof(*IPCB(skb))); xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET); if (!dst) { diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 103cf7c5dbfb94..0313a43aa8a977 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -1182,6 +1182,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data, /* this should not happen from the above code */ XFRM_INC_STATS(net, LINUX_MIB_XFRMINIPTFSERROR); +done: if (first_skb && first_iplen && !defer && !first_skb_partial) { /* first_skb is queued b/c !defer and not partial */ if (pskb_trim(first_skb, first_iplen)) { @@ -1198,7 +1199,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data, if (xfrm_input(skb, 0, 0, -2)) kfree_skb(skb); } -done: + skb = skbseq->root_skb; skb_abort_seq_read(skbseq); diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 9ea60c7717ff8b..cea6842e6454da 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1575,9 +1575,6 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) struct xfrm_policy *delpol; struct hlist_head *chain; - /* Sanitize mark before store */ - policy->mark.v &= policy->mark.m; - spin_lock_bh(&net->xfrm.xfrm_policy_lock); chain = policy_hash_bysel(net, &policy->selector, policy->family, dir); if (chain) @@ -2157,6 +2154,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, struct xfrm_pol_inexact_bin *bin; struct xfrm_policy *pol, *ret; struct hlist_head *chain; + unsigned int inexact_sequence; unsigned int sequence; int err; @@ -2191,12 +2189,18 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, goto skip_inexact; bin = xfrm_policy_inexact_lookup_rcu(net, type, family, dir, if_id); - if (!bin || !xfrm_policy_find_inexact_candidates(&cand, bin, saddr, - daddr)) + if (!bin) + goto skip_inexact; + + inexact_sequence = read_seqcount_begin(&bin->count); + if (!xfrm_policy_find_inexact_candidates(&cand, bin, saddr, daddr)) goto skip_inexact; pol = xfrm_policy_eval_candidates(&cand, ret, fl, type, family, if_id); + if (read_seqcount_retry(&bin->count, inexact_sequence)) + goto retry; + if (pol) { ret = pol; if (IS_ERR(pol)) diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c index dbdf8a39dffee7..9394953247ab93 100644 --- a/net/xfrm/xfrm_replay.c +++ b/net/xfrm/xfrm_replay.c @@ -40,7 +40,7 @@ static void xfrm_replay_notify_esn(struct xfrm_state *x, int event); void xfrm_replay_notify(struct xfrm_state *x, int event) { - struct km_event c; + struct km_event c = {}; /* we send notify messages in case * 1. we updated on of the sequence numbers, and the seqno difference * is at least x->replay_maxdiff, in this case we also update the @@ -304,7 +304,7 @@ static void xfrm_replay_advance_bmp(struct xfrm_state *x, __be32 net_seq) static void xfrm_replay_notify_bmp(struct xfrm_state *x, int event) { - struct km_event c; + struct km_event c = {}; struct xfrm_replay_state_esn *replay_esn = x->replay_esn; struct xfrm_replay_state_esn *preplay_esn = x->preplay_esn; @@ -356,7 +356,7 @@ static void xfrm_replay_notify_bmp(struct xfrm_state *x, int event) static void xfrm_replay_notify_esn(struct xfrm_state *x, int event) { u32 seq_diff, oseq_diff; - struct km_event c; + struct km_event c = {}; struct xfrm_replay_state_esn *replay_esn = x->replay_esn; struct xfrm_replay_state_esn *preplay_esn = x->preplay_esn; diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index e45aa1ed5b9659..0555e5d796ede4 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -1177,11 +1177,19 @@ static struct xfrm_state *__xfrm_state_lookup_all(const struct xfrm_hash_state_p return NULL; } -static struct xfrm_state *__xfrm_state_lookup(const struct xfrm_hash_state_ptrs *state_ptrs, - u32 mark, - const xfrm_address_t *daddr, - __be32 spi, u8 proto, - unsigned short family) +static bool xfrm_state_mark_matches(const struct xfrm_state *x, u32 mark, u32 mask, bool exact) +{ + if (exact) + return x->mark.v == mark && x->mark.m == mask; + return (mark & x->mark.m) == x->mark.v; +} + +static struct xfrm_state * +__xfrm_state_lookup(const struct xfrm_hash_state_ptrs *state_ptrs, + u32 mark, u32 mask, bool exact, + const xfrm_address_t *daddr, + __be32 spi, u8 proto, + unsigned short family) { unsigned int h = __xfrm_spi_hash(daddr, spi, proto, family, state_ptrs->hmask); struct xfrm_state *x; @@ -1193,7 +1201,7 @@ static struct xfrm_state *__xfrm_state_lookup(const struct xfrm_hash_state_ptrs !xfrm_addr_equal(&x->id.daddr, daddr, family)) continue; - if ((mark & x->mark.m) != x->mark.v) + if (!xfrm_state_mark_matches(x, mark, mask, exact)) continue; if (!xfrm_state_hold_rcu(x)) continue; @@ -1203,6 +1211,17 @@ static struct xfrm_state *__xfrm_state_lookup(const struct xfrm_hash_state_ptrs return NULL; } +static struct xfrm_state * +__xfrm_state_lookup_exact(const struct xfrm_hash_state_ptrs *state_ptrs, + const struct xfrm_mark *mark, + const xfrm_address_t *daddr, + __be32 spi, u8 proto, + unsigned short family) +{ + return __xfrm_state_lookup(state_ptrs, mark->v, mark->m, true, + daddr, spi, proto, family); +} + struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, const xfrm_address_t *daddr, __be32 spi, u8 proto, @@ -1233,7 +1252,7 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, xfrm_hash_ptrs_get(net, &state_ptrs); - x = __xfrm_state_lookup(&state_ptrs, mark, daddr, spi, proto, family); + x = __xfrm_state_lookup(&state_ptrs, mark, 0, false, daddr, spi, proto, family); if (x) { spin_lock(&net->xfrm.xfrm_state_lock); if (x->km.state != XFRM_STATE_VALID) { @@ -1283,7 +1302,7 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(const struct xfrm_hash_stat return NULL; } -static inline struct xfrm_state * +static struct xfrm_state * __xfrm_state_locate(struct xfrm_state *x, int use_spi, int family) { struct xfrm_hash_state_ptrs state_ptrs; @@ -1293,7 +1312,7 @@ __xfrm_state_locate(struct xfrm_state *x, int use_spi, int family) xfrm_hash_ptrs_get(net, &state_ptrs); if (use_spi) - return __xfrm_state_lookup(&state_ptrs, mark, &x->id.daddr, + return __xfrm_state_lookup(&state_ptrs, mark, 0, false, &x->id.daddr, x->id.spi, x->id.proto, family); else return __xfrm_state_lookup_byaddr(&state_ptrs, mark, @@ -1732,9 +1751,6 @@ static void __xfrm_state_insert(struct xfrm_state *x) list_add(&x->km.all, &net->xfrm.state_all); - /* Sanitize mark before store */ - x->mark.v &= x->mark.m; - h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr, x->props.reqid, x->props.family); XFRM_STATE_INSERT(bydst, &x->bydst, @@ -2186,10 +2202,12 @@ int xfrm_state_migrate_install(const struct xfrm_state *x, struct netlink_ext_ack *extack) { if (m->new_family == m->old_family && - xfrm_addr_equal(&x->id.daddr, &m->new_daddr, m->new_family)) { + xfrm_addr_equal(&x->id.daddr, &m->new_daddr, m->new_family) && + xc->mark.v == x->mark.v && xc->mark.m == x->mark.m) { /* - * Care is needed when the destination address of the state is - * to be updated as it is a part of triplet. + * Care is needed when the destination address or mark of the + * state is to be updated, as they are part of the lookup + * triplet. */ xfrm_state_insert(xc); } else { @@ -2383,7 +2401,7 @@ xfrm_state_lookup(struct net *net, u32 mark, const xfrm_address_t *daddr, __be32 rcu_read_lock(); xfrm_hash_ptrs_get(net, &state_ptrs); - x = __xfrm_state_lookup(&state_ptrs, mark, daddr, spi, proto, family); + x = __xfrm_state_lookup(&state_ptrs, mark, 0, false, daddr, spi, proto, family); rcu_read_unlock(); return x; } @@ -2407,6 +2425,55 @@ xfrm_state_lookup_byaddr(struct net *net, u32 mark, } EXPORT_SYMBOL(xfrm_state_lookup_byaddr); +struct xfrm_state * +xfrm_state_lookup_exact(struct net *net, const struct xfrm_mark *mark, + const xfrm_address_t *daddr, __be32 spi, + u8 proto, unsigned short family) +{ + struct xfrm_hash_state_ptrs state_ptrs; + struct xfrm_state *x; + + rcu_read_lock(); + xfrm_hash_ptrs_get(net, &state_ptrs); + + x = __xfrm_state_lookup_exact(&state_ptrs, mark, daddr, spi, proto, family); + rcu_read_unlock(); + return x; +} +EXPORT_SYMBOL(xfrm_state_lookup_exact); + +/* True if some OTHER state at this tuple would wildcard-match "mark". + * Used by MIGRATE_STATE, which must exclude the state being migrated. + */ +bool xfrm_state_mark_collides(struct net *net, u32 mark, + const xfrm_address_t *daddr, __be32 spi, + u8 proto, unsigned short family, + const struct xfrm_state *self) +{ + struct xfrm_hash_state_ptrs state_ptrs; + unsigned int h; + struct xfrm_state *x; + bool collides = false; + + rcu_read_lock(); + xfrm_hash_ptrs_get(net, &state_ptrs); + h = __xfrm_spi_hash(daddr, spi, proto, family, state_ptrs.hmask); + + hlist_for_each_entry_rcu(x, state_ptrs.byspi + h, byspi) { + if (x != self && x->props.family == family && + x->id.spi == spi && x->id.proto == proto && + xfrm_addr_equal(&x->id.daddr, daddr, family) && + (mark & x->mark.m) == x->mark.v) { + collides = true; + break; + } + } + rcu_read_unlock(); + + return collides; +} +EXPORT_SYMBOL(xfrm_state_mark_collides); + struct xfrm_state * xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, u8 mode, u32 reqid, u32 if_id, u32 pcpu_num, u8 proto, const xfrm_address_t *daddr, @@ -3317,7 +3384,7 @@ int xfrm_init_state(struct xfrm_state *x, struct netlink_ext_ack *extack) if (err) return err; - err = xfrm_init_replay(x, NULL); + err = xfrm_init_replay(x, extack); if (err) return err; diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index a2587c7e796b4e..a5fbe38839c492 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -314,6 +314,22 @@ static int verify_selector_prefixlen(u16 family, } } +static int verify_mark(struct nlattr **attrs, struct netlink_ext_ack *extack) +{ + const struct xfrm_mark *m; + + if (!attrs[XFRMA_MARK]) + return 0; + + m = nla_data(attrs[XFRMA_MARK]); + if ((m->v & m->m) != m->v) { + NL_SET_ERR_MSG(extack, "Invalid mark value/mask combination"); + return -EINVAL; + } + + return 0; +} + static int verify_newsa_info(struct xfrm_usersa_info *p, struct nlattr **attrs, struct netlink_ext_ack *extack) @@ -333,6 +349,10 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, if (err) goto out; + err = verify_mark(attrs, extack); + if (err) + goto out; + err = -EINVAL; switch (p->id.proto) { case IPPROTO_AH: @@ -1089,11 +1109,12 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net, struct xfrm_state *x = NULL; struct xfrm_mark m; int err; - u32 mark = xfrm_mark_get(attrs, &m); + + xfrm_mark_get(attrs, &m); if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) { err = -ESRCH; - x = xfrm_state_lookup(net, mark, &p->daddr, p->spi, p->proto, p->family); + x = xfrm_state_lookup_exact(net, &m, &p->daddr, p->spi, p->proto, p->family); } else { xfrm_address_t *saddr = NULL; @@ -1104,7 +1125,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net, } err = -ESRCH; - x = xfrm_state_lookup_byaddr(net, mark, + x = xfrm_state_lookup_byaddr(net, m.v & m.m, &p->daddr, saddr, p->proto, p->family); } @@ -1896,6 +1917,9 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, x = NULL; + err = verify_mark(attrs, extack); + if (err) + goto out_noput; mark = xfrm_mark_get(attrs, &m); if (attrs[XFRMA_IF_ID]) @@ -2284,6 +2308,9 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) return err; err = verify_sec_ctx_len(attrs, extack); + if (err) + return err; + err = verify_mark(attrs, extack); if (err) return err; @@ -2795,14 +2822,13 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, struct sk_buff *r_skb; int err; struct km_event c; - u32 mark; struct xfrm_mark m; struct xfrm_aevent_id *p = nlmsg_data(nlh); struct xfrm_usersa_id *id = &p->sa_id; - mark = xfrm_mark_get(attrs, &m); + xfrm_mark_get(attrs, &m); - x = xfrm_state_lookup(net, mark, &id->daddr, id->spi, id->proto, id->family); + x = xfrm_state_lookup_exact(net, &m, &id->daddr, id->spi, id->proto, id->family); if (x == NULL) return -ESRCH; @@ -2843,7 +2869,6 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, struct xfrm_state *x; struct km_event c; int err = -EINVAL; - u32 mark = 0; struct xfrm_mark m; struct xfrm_aevent_id *p = nlmsg_data(nlh); struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; @@ -2863,9 +2888,10 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } - mark = xfrm_mark_get(attrs, &m); + xfrm_mark_get(attrs, &m); - x = xfrm_state_lookup(net, mark, &p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family); + x = xfrm_state_lookup_exact(net, &m, &p->sa_id.daddr, p->sa_id.spi, + p->sa_id.proto, p->sa_id.family); if (x == NULL) return -ESRCH; @@ -2999,9 +3025,10 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, struct xfrm_user_expire *ue = nlmsg_data(nlh); struct xfrm_usersa_info *p = &ue->state; struct xfrm_mark m; - u32 mark = xfrm_mark_get(attrs, &m); - x = xfrm_state_lookup(net, mark, &p->id.daddr, p->id.spi, p->id.proto, p->family); + xfrm_mark_get(attrs, &m); + + x = xfrm_state_lookup_exact(net, &m, &p->id.daddr, p->id.spi, p->id.proto, p->family); err = -ENOENT; if (x == NULL) @@ -3370,11 +3397,15 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } + err = verify_mark(attrs, extack); + if (err) + return err; + copy_from_user_migrate_state(&m, um); - x = xfrm_state_lookup(net, m.old_mark.v & m.old_mark.m, - &um->id.daddr, um->id.spi, - um->id.proto, um->id.family); + x = xfrm_state_lookup_exact(net, &m.old_mark, + &um->id.daddr, um->id.spi, + um->id.proto, um->id.family); if (!x) { NL_SET_ERR_MSG(extack, "Can not find state"); return -ESRCH; @@ -3445,15 +3476,14 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh, x->nat_keepalive_interval); if (m.new_family != um->id.family || - !xfrm_addr_equal(&m.new_daddr, &um->id.daddr, um->id.family)) { - u32 new_mark_key = m.new_mark ? m.new_mark->v & m.new_mark->m : - m.old_mark.v & m.old_mark.m; - struct xfrm_state *x_new; - - x_new = xfrm_state_lookup(net, new_mark_key, &m.new_daddr, - um->id.spi, um->id.proto, m.new_family); - if (x_new) { - xfrm_state_put(x_new); + !xfrm_addr_equal(&m.new_daddr, &um->id.daddr, um->id.family) || + (m.new_mark && (m.new_mark->v != x->mark.v || + m.new_mark->m != x->mark.m))) { + const struct xfrm_mark *new_mark = m.new_mark ? m.new_mark : &x->mark; + + if (xfrm_state_mark_collides(net, new_mark->v & new_mark->m, + &m.new_daddr, um->id.spi, + um->id.proto, m.new_family, x)) { NL_SET_ERR_MSG(extack, "New SA tuple already occupied"); err = -EEXIST; goto out; @@ -3478,6 +3508,7 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh, __xfrm_state_delete(x); spin_unlock_bh(&x->lock); + xfrm_state_hold(xc); err = xfrm_state_migrate_install(x, xc, &m, extack); if (err < 0) { /* @@ -3485,6 +3516,7 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh, * free under xfrm_cfg_mutex. Both SAs are gone if it does; * restoring x would risk SN/IV reuse. */ + xfrm_state_put(xc); goto out; } @@ -3503,10 +3535,13 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh, err = 0; } + xfrm_state_put(xc); out: xfrm_state_put(x); return err; out_xc: + if (m.xuo) + xfrm_dev_state_delete(xc); xc->km.state = XFRM_STATE_DEAD; xfrm_state_put(xc); xfrm_state_put(x); diff --git a/rust/Makefile b/rust/Makefile index 0ac9ab28cc2b50..0165626decbe7e 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -514,13 +514,20 @@ endif bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__ # `--rust-target` points to our minimum supported Rust version. +# +# `bindgen` 0.73 emits the blob of some opaque types as a +# `__BindgenOpaqueArray[]` newtype, which the custom derives do not +# reach. Derive `Zeroable` for those wrappers, so that a struct embedding such +# an opaque type (e.g. `spinlock_t` with lockdep) is still `Zeroable`. The +# pattern also matches the unformatted output used when `rustfmt` is missing. quiet_cmd_bindgen = BINDGEN $@ cmd_bindgen = \ $(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.85 \ --use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \ --no-debug '.*' --enable-function-attribute-detection \ -o $@ -- $(bindgen_c_flags_final) -DMODULE \ - $(bindgen_target_cflags) $(bindgen_target_extra) + $(bindgen_target_cflags) $(bindgen_target_extra); \ + sed -Ei 's/pub struct __BindgenOpaqueArray[0-9]* *< *T *> *\( *pub T *\) *;/$(pound)[derive(pin_init::Zeroable)] &/g' $@ $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \ $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters) diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index b75d692846a25e..f31671129c9842 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -696,8 +696,8 @@ struct PolicyCpu<'a>(&'a mut Policy); impl<'a> PolicyCpu<'a> { fn from_cpu(cpu: CpuId) -> Result { // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU. - let ptr = - NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?; + let ptr = unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }; + let ptr = NonNull::new(ptr).ok_or(ENODEV)?; Ok(Self( // SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is diff --git a/rust/kernel/io/resource.rs b/rust/kernel/io/resource.rs index 758ce62b3cce33..29771355cfcefc 100644 --- a/rust/kernel/io/resource.rs +++ b/rust/kernel/io/resource.rs @@ -164,7 +164,7 @@ impl Resource { // SAFETY: Safe as per the invariants of `Resource`. let flags = unsafe { (*inner).flags }; - Flags(flags) + Flags::from_raw(flags) } } diff --git a/samples/Kconfig b/samples/Kconfig index 00eed83c07dfcb..744d991ea62004 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -71,7 +71,7 @@ config SAMPLE_KOBJECT config SAMPLE_KPROBES tristate "Build kprobes examples -- loadable modules only" - depends on KPROBES && m + depends on KPROBES && EVENT_TRACING && m help This build several kprobes example modules. @@ -88,7 +88,7 @@ config SAMPLE_HW_BREAKPOINT config SAMPLE_FPROBE tristate "Build fprobe examples -- loadable modules only" - depends on FPROBE && m + depends on FPROBE && EVENT_TRACING && m help This builds a fprobe example module. This module has an option 'symbol'. You can specify a probed symbol or symbols separated with ','. diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c index bfe98ce826f3ac..3b94839b3199a0 100644 --- a/samples/fprobe/fprobe_example.c +++ b/samples/fprobe/fprobe_example.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Here's a sample kernel module showing the use of fprobe to dump a - * stack trace and selected registers when kernel_clone() is called. + * stack trace and function entry/exit when kernel_clone() is called. * - * For more information on theory of operation of kprobes, see - * Documentation/trace/kprobes.rst + * For more information on theory of operation of fprobe, see + * Documentation/trace/fprobe.rst * - * You will see the trace data in /var/log/messages and on the console + * You will see the trace data in /sys/kernel/tracing/trace * whenever kernel_clone() is invoked to create a new process. */ @@ -15,10 +15,9 @@ #include #include #include -#include #include +#include -#define BACKTRACE_DEPTH 16 #define MAX_SYMBOL_LEN 4096 static struct fprobe sample_probe; static unsigned long nhit; @@ -35,34 +34,14 @@ static bool stackdump = true; module_param(stackdump, bool, 0644); MODULE_PARM_DESC(stackdump, "Enable stackdump."); -static bool use_trace = false; -module_param(use_trace, bool, 0644); -MODULE_PARM_DESC(use_trace, "Use trace_printk instead of printk. This is only for debugging."); - -static void show_backtrace(void) -{ - unsigned long stacks[BACKTRACE_DEPTH]; - unsigned int len; - - len = stack_trace_save(stacks, BACKTRACE_DEPTH, 2); - stack_trace_print(stacks, len, 24); -} - static int sample_entry_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *data) { - if (use_trace) - /* - * This is just an example, no kernel code should call - * trace_printk() except when actively debugging. - */ - trace_printk("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); - else - pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); + trace_printk("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); nhit++; if (stackdump) - show_backtrace(); + trace_dump_stack(0); return 0; } @@ -72,19 +51,11 @@ static void sample_exit_handler(struct fprobe *fp, unsigned long ip, { unsigned long rip = ret_ip; - if (use_trace) - /* - * This is just an example, no kernel code should call - * trace_printk() except when actively debugging. - */ - trace_printk("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", - (void *)ip, (void *)ip, (void *)rip, (void *)rip); - else - pr_info("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", - (void *)ip, (void *)ip, (void *)rip, (void *)rip); + trace_printk("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", + (void *)ip, (void *)ip, (void *)rip, (void *)rip); nhit++; if (stackdump) - show_backtrace(); + trace_dump_stack(0); } static int __init fprobe_init(void) diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c index 53ec6c8b8c40d0..0f516a2b04be04 100644 --- a/samples/kprobes/kprobe_example.c +++ b/samples/kprobes/kprobe_example.c @@ -6,7 +6,7 @@ * For more information on theory of operation of kprobes, see * Documentation/trace/kprobes.rst * - * You will see the trace data in /var/log/messages and on the console + * You will see the trace data in /sys/kernel/tracing/trace * whenever kernel_clone() is invoked to create a new process. */ @@ -15,6 +15,7 @@ #include #include #include +#include static char symbol[KSYM_NAME_LEN] = "kernel_clone"; module_param_string(symbol, symbol, KSYM_NAME_LEN, 0644); @@ -28,39 +29,39 @@ static struct kprobe kp = { static int __kprobes handler_pre(struct kprobe *p, struct pt_regs *regs) { #ifdef CONFIG_X86 - pr_info("<%s> p->addr = 0x%p, ip = %lx, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->ip, regs->flags); + trace_printk("<%s> p->addr = 0x%p, ip = %lx, flags = 0x%lx\n", + p->symbol_name, p->addr, regs->ip, regs->flags); #endif #ifdef CONFIG_PPC - pr_info("<%s> p->addr = 0x%p, nip = 0x%lx, msr = 0x%lx\n", - p->symbol_name, p->addr, regs->nip, regs->msr); + trace_printk("<%s> p->addr = 0x%p, nip = 0x%lx, msr = 0x%lx\n", + p->symbol_name, p->addr, regs->nip, regs->msr); #endif #ifdef CONFIG_MIPS - pr_info("<%s> p->addr = 0x%p, epc = 0x%lx, status = 0x%lx\n", - p->symbol_name, p->addr, regs->cp0_epc, regs->cp0_status); + trace_printk("<%s> p->addr = 0x%p, epc = 0x%lx, status = 0x%lx\n", + p->symbol_name, p->addr, regs->cp0_epc, regs->cp0_status); #endif #ifdef CONFIG_ARM64 - pr_info("<%s> p->addr = 0x%p, pc = 0x%lx, pstate = 0x%lx\n", - p->symbol_name, p->addr, (long)regs->pc, (long)regs->pstate); + trace_printk("<%s> p->addr = 0x%p, pc = 0x%lx, pstate = 0x%lx\n", + p->symbol_name, p->addr, (long)regs->pc, (long)regs->pstate); #endif #ifdef CONFIG_ARM - pr_info("<%s> p->addr = 0x%p, pc = 0x%lx, cpsr = 0x%lx\n", - p->symbol_name, p->addr, (long)regs->ARM_pc, (long)regs->ARM_cpsr); + trace_printk("<%s> p->addr = 0x%p, pc = 0x%lx, cpsr = 0x%lx\n", + p->symbol_name, p->addr, (long)regs->ARM_pc, (long)regs->ARM_cpsr); #endif #ifdef CONFIG_RISCV - pr_info("<%s> p->addr = 0x%p, pc = 0x%lx, status = 0x%lx\n", - p->symbol_name, p->addr, regs->epc, regs->status); + trace_printk("<%s> p->addr = 0x%p, pc = 0x%lx, status = 0x%lx\n", + p->symbol_name, p->addr, regs->epc, regs->status); #endif #ifdef CONFIG_S390 - pr_info("<%s> p->addr, 0x%p, ip = 0x%lx, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->psw.addr, regs->flags); + trace_printk("<%s> p->addr = 0x%p, ip = 0x%lx, flags = 0x%lx\n", + p->symbol_name, p->addr, regs->psw.addr, regs->flags); #endif #ifdef CONFIG_LOONGARCH - pr_info("<%s> p->addr = 0x%p, era = 0x%lx, estat = 0x%lx\n", - p->symbol_name, p->addr, regs->csr_era, regs->csr_estat); + trace_printk("<%s> p->addr = 0x%p, era = 0x%lx, estat = 0x%lx\n", + p->symbol_name, p->addr, regs->csr_era, regs->csr_estat); #endif - /* A dump_stack() here will give a stack backtrace */ + /* A trace_dump_stack(0) here will give a stack backtrace */ return 0; } @@ -69,36 +70,36 @@ static void __kprobes handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) { #ifdef CONFIG_X86 - pr_info("<%s> p->addr = 0x%p, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->flags); + trace_printk("<%s> p->addr = 0x%p, flags = 0x%lx\n", + p->symbol_name, p->addr, regs->flags); #endif #ifdef CONFIG_PPC - pr_info("<%s> p->addr = 0x%p, msr = 0x%lx\n", - p->symbol_name, p->addr, regs->msr); + trace_printk("<%s> p->addr = 0x%p, msr = 0x%lx\n", + p->symbol_name, p->addr, regs->msr); #endif #ifdef CONFIG_MIPS - pr_info("<%s> p->addr = 0x%p, status = 0x%lx\n", - p->symbol_name, p->addr, regs->cp0_status); + trace_printk("<%s> p->addr = 0x%p, status = 0x%lx\n", + p->symbol_name, p->addr, regs->cp0_status); #endif #ifdef CONFIG_ARM64 - pr_info("<%s> p->addr = 0x%p, pstate = 0x%lx\n", - p->symbol_name, p->addr, (long)regs->pstate); + trace_printk("<%s> p->addr = 0x%p, pstate = 0x%lx\n", + p->symbol_name, p->addr, (long)regs->pstate); #endif #ifdef CONFIG_ARM - pr_info("<%s> p->addr = 0x%p, cpsr = 0x%lx\n", - p->symbol_name, p->addr, (long)regs->ARM_cpsr); + trace_printk("<%s> p->addr = 0x%p, cpsr = 0x%lx\n", + p->symbol_name, p->addr, (long)regs->ARM_cpsr); #endif #ifdef CONFIG_RISCV - pr_info("<%s> p->addr = 0x%p, status = 0x%lx\n", - p->symbol_name, p->addr, regs->status); + trace_printk("<%s> p->addr = 0x%p, status = 0x%lx\n", + p->symbol_name, p->addr, regs->status); #endif #ifdef CONFIG_S390 - pr_info("<%s> p->addr, 0x%p, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->flags); + trace_printk("<%s> p->addr = 0x%p, flags = 0x%lx\n", + p->symbol_name, p->addr, regs->flags); #endif #ifdef CONFIG_LOONGARCH - pr_info("<%s> p->addr = 0x%p, estat = 0x%lx\n", - p->symbol_name, p->addr, regs->csr_estat); + trace_printk("<%s> p->addr = 0x%p, estat = 0x%lx\n", + p->symbol_name, p->addr, regs->csr_estat); #endif } diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c index 65d6dcafd742e8..9dd5cf9a7432be 100644 --- a/samples/kprobes/kretprobe_example.c +++ b/samples/kprobes/kretprobe_example.c @@ -14,9 +14,8 @@ * Documentation/trace/kprobes.rst * * Build and insert the kernel module as done in the kprobe example. - * You will see the trace data in /var/log/messages and on the console - * whenever the probed function returns. (Some messages may be suppressed - * if syslogd is configured to eliminate duplicate messages.) + * You will see the trace data in /sys/kernel/tracing/trace + * whenever the probed function returns. */ #include @@ -24,6 +23,7 @@ #include #include #include +#include static char func_name[KSYM_NAME_LEN] = "kernel_clone"; module_param_string(func, func_name, KSYM_NAME_LEN, 0644); @@ -63,8 +63,8 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) now = ktime_get(); delta = ktime_to_ns(ktime_sub(now, data->entry_stamp)); - pr_info("%s returned %lu and took %lld ns to execute\n", - func_name, retval, (long long)delta); + trace_printk("%s returned %lu and took %lld ns to execute\n", + func_name, retval, (long long)delta); return 0; } NOKPROBE_SYMBOL(ret_handler); diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 57a3aba6ffc237..32c18df237f1b6 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -13,7 +13,7 @@ endif ifdef CLANG_AUTOFDO_PROFILE CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions - RUSTFLAGS_AUTOFDO_CLANG += -Zprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -Zfunction-sections=y + RUSTFLAGS_AUTOFDO_CLANG += $(if $(call rustc-min-version,110000),-Cprofile-sample-use,-Zprofile-sample-use)=$(CLANG_AUTOFDO_PROFILE) -Zfunction-sections=y RUSTFLAGS_AUTOFDO_CLANG += -Cllvm-args=-split-machine-functions endif diff --git a/scripts/coccinelle/api/devm_kmalloc_objs.cocci b/scripts/coccinelle/api/devm_kmalloc_objs.cocci new file mode 100644 index 00000000000000..322f79a2d9654d --- /dev/null +++ b/scripts/coccinelle/api/devm_kmalloc_objs.cocci @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use devm_kmalloc_obj family of macros for allocations +/// +// Confidence: High +// Options: --include-headers-for-types --all-includes --include-headers --keep-comments + +virtual patch + +@initialize:python@ +@@ +import sys + +def alloc_array(name): + func = "FAILED_RENAME" + if name == "devm_kmalloc_array": + func = "devm_kmalloc_objs" + elif name == "devm_kvmalloc_array": + func = "devm_kvmalloc_objs" + elif name == "devm_kcalloc": + func = "devm_kzalloc_objs" + elif name == "devm_kvcalloc": + func = "devm_kvzalloc_objs" + else: + print(f"Unknown transform for {name}", file=sys.stderr) + return func + +// This excludes anything that is assigning to or from integral types or +// string literals. Everything else gets the sizeof() extracted for the +// kmalloc_obj() type/var argument. sizeof(void *) is also excluded because +// it will need case-by-case double-checking to make sure the right type is +// being assigned. +@direct depends on patch && !(file in "tools") && !(file in "samples")@ +typedef u8, u16, u32, u64; +typedef __u8, __u16, __u32, __u64; +typedef uint8_t, uint16_t, uint32_t, uint64_t; +typedef uchar, ushort, uint, ulong; +typedef __le16, __le32, __le64; +typedef __be16, __be32, __be64; +typedef wchar_t; +type INTEGRAL = {u8,__u8,uint8_t,char,unsigned char,uchar,wchar_t, + u16,__u16,uint16_t,unsigned short,ushort, + u32,__u32,uint32_t,unsigned int,uint, + u64,__u64,uint64_t,unsigned long,ulong, + __le16,__le32,__le64,__be16,__be32,__be64}; +char [] STRING; +INTEGRAL *BYTES; +INTEGRAL **BYTES_PTRS; +type TYPE; +expression VAR; +expression GFP; +expression COUNT; +expression FLEX; +expression E; +expression DEV; +identifier ALLOC =~ "^devm_kv?[mz]alloc$"; +fresh identifier ALLOC_OBJ = ALLOC ## "_obj"; +fresh identifier ALLOC_FLEX = ALLOC ## "_flex"; +identifier ALLOC_ARRAY = {devm_kmalloc_array,devm_kvmalloc_array,devm_kcalloc,devm_kvcalloc}; +fresh identifier ALLOC_OBJS = script:python(ALLOC_ARRAY) { alloc_array(ALLOC_ARRAY) }; +@@ + +( +- VAR = ALLOC(DEV,(sizeof(*VAR)), GFP) ++ VAR = ALLOC_OBJ(DEV,*VAR, GFP) +| + ALLOC(DEV,(\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), GFP) +| + BYTES = ALLOC(DEV,(sizeof(E)), GFP) +| + BYTES = ALLOC(DEV,(sizeof(TYPE)), GFP) +| + BYTES_PTRS = ALLOC(DEV,(sizeof(E)), GFP) +| + BYTES_PTRS = ALLOC(DEV,(sizeof(TYPE)), GFP) +| + ALLOC(DEV,(sizeof(void *)), GFP) +| +- ALLOC(DEV,(sizeof(E)), GFP) ++ ALLOC_OBJ(DEV, E, GFP) +| +- ALLOC(DEV,(sizeof(TYPE)), GFP) ++ ALLOC_OBJ(DEV,TYPE, GFP) +| + ALLOC_ARRAY(DEV,COUNT, (\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), GFP) +| + BYTES = ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) +| + BYTES = ALLOC_ARRAY(DEV,COUNT, (sizeof(TYPE)), GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, COUNT, (sizeof(TYPE)), GFP) +| + ALLOC_ARRAY(DEV, (\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), COUNT, GFP) +| + BYTES = ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) +| + BYTES = ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) +| + ALLOC_ARRAY(DEV, COUNT, (sizeof(void *)), GFP) +| + ALLOC_ARRAY(DEV, (sizeof(void *)), COUNT, GFP) +| +- ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) ++ ALLOC_OBJS(DEV, E, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, COUNT, (sizeof(TYPE)), GFP) ++ ALLOC_OBJS(DEV, TYPE, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) ++ ALLOC_OBJS(DEV, E, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) ++ ALLOC_OBJS(DEV, TYPE, COUNT, GFP) +| +- ALLOC(DEV, struct_size(VAR, FLEX, COUNT), GFP) ++ ALLOC_FLEX(DEV, *VAR, FLEX, COUNT, GFP) +| +- ALLOC(DEV, struct_size_t(TYPE, FLEX, COUNT), GFP) ++ ALLOC_FLEX(DEV, TYPE, FLEX, COUNT, GFP) +) + +@drop_gfp_kernel depends on patch && !(file in "tools") && !(file in "samples")@ +identifier ALLOC = {devm_kmalloc_obj,devm_kmalloc_objs,devm_kmalloc_flex, + devm_kzalloc_obj,devm_kzalloc_objs,devm_kzalloc_flex, + devm_kvmalloc_obj,devm_kvmalloc_objs,devm_kvmalloc_flex, + devm_kvzalloc_obj,devm_kvzalloc_objs,devm_kvzalloc_flex}; +@@ + + ALLOC(... +- , GFP_KERNEL + ) diff --git a/scripts/coccinelle/api/kmalloc_objs.cocci b/scripts/coccinelle/api/kmalloc_objs.cocci index 0a98ddf03eca48..e47604f7a1a656 100644 --- a/scripts/coccinelle/api/kmalloc_objs.cocci +++ b/scripts/coccinelle/api/kmalloc_objs.cocci @@ -20,6 +20,10 @@ def alloc_array(name): func = "kzalloc_objs" elif name == "kvcalloc": func = "kvzalloc_objs" + elif name == "devm_kmalloc_array": + func = "devm_kmalloc_objs" + elif name == "devm_kcalloc": + func = "devm_kzalloc_objs" else: print(f"Unknown transform for {name}", file=sys.stderr) return func @@ -42,6 +46,15 @@ def alloc_array(name): // Everything else gets the sizeof() extracted for the kmalloc_obj() // type/var argument. // +// The device-managed allocators differ from the plain ones only by taking +// the managing "struct device *" as a leading argument, so rather than +// repeating every pattern for them, the leading arguments are captured in +// an "expression list" metavariable and replayed on the replacement side. +// ARGS is empty for the plain allocators, in which case Coccinelle drops +// the separating comma as well. Note that there is no devm_kvmalloc +// family, and that the devm array helpers only exist as +// (dev, count, size, gfp). +// // The first matching alternative below wins, so the exclusions must come // before the more general conversions. @direct depends on patch && !(file in "tools") && !(file in "samples")@ @@ -81,150 +94,155 @@ expression GFP; expression COUNT; expression FLEX; expression E; -identifier ALLOC =~ "^kv?[mz]alloc$"; +expression list ARGS; +identifier ALLOC = {kmalloc,kzalloc,kvmalloc,kvzalloc, + devm_kmalloc,devm_kzalloc}; fresh identifier ALLOC_OBJ = ALLOC ## "_obj"; fresh identifier ALLOC_FLEX = ALLOC ## "_flex"; -identifier ALLOC_ARRAY = {kmalloc_array,kvmalloc_array,kcalloc,kvcalloc}; +identifier ALLOC_ARRAY = {kmalloc_array,kvmalloc_array,kcalloc,kvcalloc, + devm_kmalloc_array,devm_kcalloc}; fresh identifier ALLOC_OBJS = script:python(ALLOC_ARRAY) { alloc_array(ALLOC_ARRAY) }; @@ ( // Convert a single object sized by its target: p = kmalloc(sizeof(*p), gfp) -- VAR = ALLOC((sizeof(*VAR)), GFP) -+ VAR = ALLOC_OBJ(*VAR, GFP) +- VAR = ALLOC(ARGS, (sizeof(*VAR)), GFP) ++ VAR = ALLOC_OBJ(ARGS, *VAR, GFP) | // Exclude byte buffers and integral pointers: kmalloc(sizeof(u8), gfp), // kmalloc(sizeof("str"), gfp), kmalloc(sizeof(char *), gfp) - ALLOC((\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC(ARGS, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), GFP) | // Exclude anything assigned to a byte pointer: // u8 *buf = kmalloc(sizeof(*hdr), gfp) - BYTES = ALLOC((\(sizeof(E)\|sizeof(TYPE)\)), GFP) + BYTES = ALLOC(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Convert a multi-byte type to a pointer to it: // u32 *p = kmalloc(sizeof(u32), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC((sizeof(MULTIBYTE_TYPES)), GFP) -+ ALLOC_OBJ(MULTIBYTE_TYPES, GFP) +- ALLOC(ARGS, (sizeof(MULTIBYTE_TYPES)), GFP) ++ ALLOC_OBJ(ARGS, MULTIBYTE_TYPES, GFP) | // Same by expression: u32 *p = kmalloc(sizeof(p[0]), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC((sizeof(MULTIBYTE)), GFP) -+ ALLOC_OBJ(MULTIBYTE, GFP) +- ALLOC(ARGS, (sizeof(MULTIBYTE)), GFP) ++ ALLOC_OBJ(ARGS, MULTIBYTE, GFP) | // Exclude other multi-byte sizes, e.g. to pointers to arrays: s16 (*p)[2] = ... - ALLOC((\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) + ALLOC(ARGS, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) | // Exclude anything else assigned to a multi-byte pointer: // u32 *p = kmalloc(sizeof(*hdr), gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC((\(sizeof(E)\|sizeof(TYPE)\)), GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Exclude void pointers, to be checked by hand: kmalloc(sizeof(void *), gfp) - ALLOC((sizeof(void *)), GFP) + ALLOC(ARGS, (sizeof(void *)), GFP) | // Convert any other expression: p = kmalloc(sizeof(s->item), gfp) -- ALLOC((sizeof(E)), GFP) -+ ALLOC_OBJ(E, GFP) +- ALLOC(ARGS, (sizeof(E)), GFP) ++ ALLOC_OBJ(ARGS, E, GFP) | // Convert any other type: p = kmalloc(sizeof(struct item), gfp) -- ALLOC((sizeof(TYPE)), GFP) -+ ALLOC_OBJ(TYPE, GFP) +- ALLOC(ARGS, (sizeof(TYPE)), GFP) ++ ALLOC_OBJ(ARGS, TYPE, GFP) | // The same, for arrays allocated as (count, size): // Exclude byte buffers and integral pointers: kcalloc(n, sizeof(u8), gfp), // kcalloc(n, sizeof(char *), gfp) - ALLOC_ARRAY(COUNT, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), GFP) | // Exclude arrays assigned to a byte pointer: // u8 *buf = kcalloc(n, sizeof(*hdr), gfp) - BYTES = ALLOC_ARRAY(COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) + BYTES = ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Convert a multi-byte array to a pointer to it: // u32 *p = kcalloc(n, sizeof(u32), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY(COUNT, (sizeof(MULTIBYTE_TYPES)), GFP) -+ ALLOC_OBJS(MULTIBYTE_TYPES, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(MULTIBYTE_TYPES)), GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE_TYPES, COUNT, GFP) | // Same by expression: u32 *p = kcalloc(n, sizeof(*p), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY(COUNT, (sizeof(MULTIBYTE)), GFP) -+ ALLOC_OBJS(MULTIBYTE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(MULTIBYTE)), GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE, COUNT, GFP) | // Exclude other multi-byte arrays: // s16 (*pairs)[2] = kcalloc(n, sizeof(s16), gfp) - ALLOC_ARRAY(COUNT, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) + ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) | // Exclude other arrays assigned to a multi-byte pointer: // u32 *p = kcalloc(n, sizeof(*hdr), gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Exclude arrays of void pointers: kcalloc(n, sizeof(void *), gfp) - ALLOC_ARRAY(COUNT, (sizeof(void *)), GFP) + ALLOC_ARRAY(ARGS, COUNT, (sizeof(void *)), GFP) | // Convert any other expression: p = kcalloc(n, sizeof(*p), gfp) -- ALLOC_ARRAY(COUNT, (sizeof(E)), GFP) -+ ALLOC_OBJS(E, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(E)), GFP) ++ ALLOC_OBJS(ARGS, E, COUNT, GFP) | // Convert any other type: p = kcalloc(n, sizeof(struct item), gfp) -- ALLOC_ARRAY(COUNT, (sizeof(TYPE)), GFP) -+ ALLOC_OBJS(TYPE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(TYPE)), GFP) ++ ALLOC_OBJS(ARGS, TYPE, COUNT, GFP) | // The same, for arrays allocated as (size, count): // Exclude byte buffers and integral pointers: kcalloc(sizeof(u8), n, gfp), // kcalloc(sizeof(char *), n, gfp) - ALLOC_ARRAY((\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC_ARRAY(ARGS, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), COUNT, GFP) | // Exclude arrays assigned to a byte pointer: // u8 *buf = kcalloc(sizeof(*hdr), n, gfp) - BYTES = ALLOC_ARRAY((\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) + BYTES = ALLOC_ARRAY(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) | // Convert a multi-byte array to a pointer to it: // u32 *p = kcalloc(sizeof(u32), n, gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY((sizeof(MULTIBYTE_TYPES)), COUNT, GFP) -+ ALLOC_OBJS(MULTIBYTE_TYPES, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(MULTIBYTE_TYPES)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE_TYPES, COUNT, GFP) | // Same by expression: u32 *p = kcalloc(sizeof(*p), n, gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY((sizeof(MULTIBYTE)), COUNT, GFP) -+ ALLOC_OBJS(MULTIBYTE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(MULTIBYTE)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE, COUNT, GFP) | // Exclude other multi-byte arrays: // s16 (*pairs)[2] = kcalloc(sizeof(s16), n, gfp) - ALLOC_ARRAY((\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), COUNT, GFP) + ALLOC_ARRAY(ARGS, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), COUNT, GFP) | // Exclude other arrays assigned to a multi-byte pointer: // u32 *p = kcalloc(sizeof(*hdr), n, gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY((\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) | // Exclude arrays of void pointers: kcalloc(sizeof(void *), n, gfp) - ALLOC_ARRAY((sizeof(void *)), COUNT, GFP) + ALLOC_ARRAY(ARGS, (sizeof(void *)), COUNT, GFP) | // Convert any other expression: p = kcalloc(sizeof(*p), n, gfp) -- ALLOC_ARRAY((sizeof(E)), COUNT, GFP) -+ ALLOC_OBJS(E, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(E)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, E, COUNT, GFP) | // Convert any other type: p = kcalloc(sizeof(struct item), n, gfp) -- ALLOC_ARRAY((sizeof(TYPE)), COUNT, GFP) -+ ALLOC_OBJS(TYPE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(TYPE)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, TYPE, COUNT, GFP) | // Convert flexible array structures: p = kmalloc(struct_size(p, data, n), gfp) -- ALLOC(struct_size(VAR, FLEX, COUNT), GFP) -+ ALLOC_FLEX(*VAR, FLEX, COUNT, GFP) +- ALLOC(ARGS, struct_size(VAR, FLEX, COUNT), GFP) ++ ALLOC_FLEX(ARGS, *VAR, FLEX, COUNT, GFP) | // Same by type: kmalloc(struct_size_t(struct item, data, n), gfp) -- ALLOC(struct_size_t(TYPE, FLEX, COUNT), GFP) -+ ALLOC_FLEX(TYPE, FLEX, COUNT, GFP) +- ALLOC(ARGS, struct_size_t(TYPE, FLEX, COUNT), GFP) ++ ALLOC_FLEX(ARGS, TYPE, FLEX, COUNT, GFP) ) @drop_gfp_kernel depends on patch && !(file in "tools") && !(file in "samples")@ identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex, kzalloc_obj,kzalloc_objs,kzalloc_flex, kvmalloc_obj,kvmalloc_objs,kvmalloc_flex, - kvzalloc_obj,kvzalloc_objs,kvzalloc_flex}; + kvzalloc_obj,kvzalloc_objs,kvzalloc_flex, + devm_kmalloc_obj,devm_kmalloc_objs,devm_kmalloc_flex, + devm_kzalloc_obj,devm_kzalloc_objs,devm_kzalloc_flex}; @@ ALLOC(... diff --git a/scripts/coccinelle/free/cleanup-free.cocci b/scripts/coccinelle/free/cleanup-free.cocci new file mode 100644 index 00000000000000..2aba766b5bbb1b --- /dev/null +++ b/scripts/coccinelle/free/cleanup-free.cocci @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Find __cleanup(kfree) +/// Using __cleanup(kfree) will pass the stack address of the annotated +/// local variable to kfree, causing an invalid free. +/// I.e., `T v __cleanup(kfree);` --> `kfree(&v);` +/// Such usage is impossible to be correct. +/// +// Confidence: High +// Copyright: (C) 2026 Ella Ma +// Options: --no-includes --include-headers + +virtual report +virtual org + +// Suggesting using __free for the functions with a DEFINE_FREE definition. +// Update this list when new DEFINE_FREE definitions are added. +@free@ +attribute name __cleanup; +symbol kfree, kfree_sensitive, kvfree, kvfree_atomic, free_percpu; +type T; +identifier v, n; +position p; +@@ + +( + T v __cleanup@p( +( + n +& +( + kfree \| kfree_sensitive \| kvfree \| kvfree_atomic \| free_percpu +) +) + ); +| + T v __cleanup@p( +( + n +& +( + kfree \| kfree_sensitive \| kvfree \| kvfree_atomic \| free_percpu +) +) + ) = ...; +) + +@script:python depends on report@ +p << free.p; +n << free.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}; declare the variable using __free({n}) to cause the pointee to be freed" +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << free.p; +n << free.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}; declare the variable using __free({n}) to cause the pointee to be freed" +coccilib.org.print_todo(p[0], msg) + + +// Reporting __cleanup usage for the functions without a DEFINE_FREE definition. +// The following list only contains frequently used functions. Supplement it if +// necessary. +@cleanup@ +attribute name __cleanup; +symbol vfree, vfree_atomic, kfree_const; +type T; +identifier v, n; +position p; +@@ + +( + T v __cleanup@p( +( + n +& +( + vfree \| vfree_atomic \| kfree_const +) +) + ); +| + T v __cleanup@p( +( + n +& +( + vfree \| vfree_atomic \| kfree_const +) +) + ) = ...; +) + +@script:python depends on report@ +p << cleanup.p; +n << cleanup.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}" +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << cleanup.p; +n << cleanup.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}" +coccilib.org.print_todo(p[0], msg) diff --git a/scripts/coccinelle/misc/array_end.cocci b/scripts/coccinelle/misc/array_end.cocci new file mode 100644 index 00000000000000..2f0bbc4ce17d5d --- /dev/null +++ b/scripts/coccinelle/misc/array_end.cocci @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use ARRAY_END instead of an expression derived from ARRAY_SIZE +// +// Confidence: High +// Copyright: 2026, Alejandro Colomar +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@depends on context disable zero_multiple_format@ +type T; +T[] a; +expression b; +@@ +( +* a + ARRAY_SIZE(a) +| +* &a[0] + ARRAY_SIZE(a) +| +* &a[ARRAY_SIZE(a)] +| +* &a[ARRAY_SIZE(a) - b] +) + +@depends on patch disable zero_multiple_format@ +type T; +T[] a; +expression b; +@@ +( +- (a + ARRAY_SIZE(a)) ++ ARRAY_END(a) +| +- (&a[0] + ARRAY_SIZE(a)) ++ ARRAY_END(a) +| +- (&a[ARRAY_SIZE(a)]) ++ ARRAY_END(a) +| +- (&a[ARRAY_SIZE(a) - b]) ++ ARRAY_END(a) - b +) + +@r depends on org || report disable zero_multiple_format@ +type T; +T[] a; +expression b; +position p; +@@ +( + a@p + ARRAY_SIZE(a) +| + &a[0]@p + ARRAY_SIZE(a) +| + &a[ARRAY_SIZE(a)]@p +| + &a[ARRAY_SIZE(a)@p - b] +) + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING should use ARRAY_END") + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING: opportunity for ARRAY_END") diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c index 35dfa3b451f390..24fbce2e4322ea 100644 --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c @@ -785,7 +785,7 @@ static int unpack_tagsets(struct aa_ext *e, struct aa_tags_struct *tags) if (!aa_unpack_array(e, "sets", &size)) goto fail_reset; - sets = kcalloc(size, sizeof(u32), GFP_KERNEL); + sets = kzalloc_objs(u32, size); if (!sets) { error = -ENOMEM; goto fail_reset; diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c index e07092ea301ac1..63f0245e6f74d5 100644 --- a/security/keys/encrypted-keys/encrypted.c +++ b/security/keys/encrypted-keys/encrypted.c @@ -648,8 +648,7 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, if (ret < 0) return ERR_PTR(ret); - epayload = kzalloc_flex(*epayload, payload_data, payload_totallen, - GFP_KERNEL); + epayload = kzalloc_flex(*epayload, payload_data, payload_totallen); if (!epayload) return ERR_PTR(-ENOMEM); diff --git a/security/keys/key.c b/security/keys/key.c index 6ebb8691551fe1..3f1f0fc137109a 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -245,6 +245,8 @@ struct key *key_alloc(struct key_type *type, const char *desc, } desclen = strlen(desc); + if (desclen >= KEY_MAX_DESC_SIZE) + goto error; quotalen = desclen + 1 + type->def_datalen; /* get hold of the key tracking for this user */ @@ -829,6 +831,7 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, key_ref_t key_ref; int ret; struct key_restriction *restrict_link = NULL; + size_t desclen; /* look up the key type to see if it's one of the registered kernel * types */ @@ -869,7 +872,12 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, if (!index_key.description) goto error_free_prep; } - index_key.desc_len = strlen(index_key.description); + desclen = strlen(index_key.description); + if (desclen >= KEY_MAX_DESC_SIZE) { + key_ref = ERR_PTR(-EINVAL); + goto error_free_prep; + } + index_key.desc_len = desclen; key_set_index_key(&index_key); ret = __key_link_lock(keyring, &index_key); @@ -1093,9 +1101,12 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen) if (ret < 0) return ret; + down_write(&key->sem); + /* attempt to update it if supported */ + ret = -EOPNOTSUPP; if (!key->type->update) - return -EOPNOTSUPP; + goto out; memset(&prep, 0, sizeof(prep)); prep.data = payload; @@ -1105,11 +1116,9 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen) if (key->type->preparse) { ret = key->type->preparse(&prep); if (ret < 0) - goto error; + goto out_free_preparse; } - down_write(&key->sem); - ret = key->type->update(key, &prep); if (ret == 0) { /* Updating a negative key positively instantiates it */ @@ -1117,11 +1126,12 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen) notify_key(key, NOTIFY_KEY_UPDATED, 0); } - up_write(&key->sem); - -error: +out_free_preparse: if (key->type->preparse) key->type->free_preparse(&prep); + +out: + up_write(&key->sem); return ret; } EXPORT_SYMBOL(key_update); diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c index 36ffba0ebba600..d6b10fd67627b2 100644 --- a/security/keys/keyctl.c +++ b/security/keys/keyctl.c @@ -24,8 +24,6 @@ #include #include "internal.h" -#define KEY_MAX_DESC_SIZE 4096 - static const unsigned char keyrings_capabilities[2] = { [0] = (KEYCTL_CAPS0_CAPABILITIES | (IS_ENABLED(CONFIG_PERSISTENT_KEYRINGS) ? KEYCTL_CAPS0_PERSISTENT_KEYRINGS : 0) | diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c index 15b6bf6399b590..e7121523b9c9ac 100644 --- a/security/keys/keyctl_pkey.c +++ b/security/keys/keyctl_pkey.c @@ -129,45 +129,77 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par if (ret < 0) return ret; + down_read(¶ms->key->sem); + + if (!params->key->type->asym_query) { + ret = -EOPNOTSUPP; + goto out_up_key_sem; + } + ret = params->key->type->asym_query(params, &info); if (ret < 0) - return ret; + goto out_up_key_sem; switch (op) { case KEYCTL_PKEY_ENCRYPT: if (uparams.in_len > info.max_dec_size || - uparams.out_len > info.max_enc_size) - return -EINVAL; + uparams.out_len > info.max_enc_size) { + ret = -EINVAL; + goto out_up_key_sem; + } params->out_len = info.max_enc_size; break; case KEYCTL_PKEY_DECRYPT: if (uparams.in_len > info.max_enc_size || - uparams.out_len > info.max_dec_size) - return -EINVAL; + uparams.out_len > info.max_dec_size) { + ret = -EINVAL; + goto out_up_key_sem; + } params->out_len = info.max_dec_size; break; case KEYCTL_PKEY_SIGN: if (uparams.in_len > info.max_data_size || - uparams.out_len > info.max_sig_size) - return -EINVAL; + uparams.out_len > info.max_sig_size) { + ret = -EINVAL; + goto out_up_key_sem; + } params->out_len = info.max_sig_size; break; case KEYCTL_PKEY_VERIFY: if (uparams.in_len > info.max_data_size || - uparams.in2_len > info.max_sig_size) - return -EINVAL; + uparams.in2_len > info.max_sig_size) { + ret = -EINVAL; + goto out_up_key_sem; + } params->out_len = info.max_sig_size; break; default: - return -EOPNOTSUPP; + ret = -EOPNOTSUPP; + goto out_up_key_sem; } params->in_len = uparams.in_len; - return 0; + + switch (op) { + case KEYCTL_PKEY_VERIFY: + if (!params->key->type->asym_verify_signature) + ret = -EOPNOTSUPP; + break; + case KEYCTL_PKEY_ENCRYPT: + case KEYCTL_PKEY_DECRYPT: + case KEYCTL_PKEY_SIGN: + if (!params->key->type->asym_eds_op) + ret = -EOPNOTSUPP; + break; + } + +out_up_key_sem: + up_read(¶ms->key->sem); + return ret; } /* @@ -185,7 +217,16 @@ long keyctl_pkey_query(key_serial_t id, if (ret < 0) goto error; + down_read(¶ms.key->sem); + if (!params.key->type->asym_query) { + ret = -EOPNOTSUPP; + goto out_up_key_sem; + } + ret = params.key->type->asym_query(¶ms, &res); + +out_up_key_sem: + up_read(¶ms.key->sem); if (ret < 0) goto error; @@ -230,10 +271,6 @@ long keyctl_pkey_e_d_s(int op, if (ret < 0) goto error_params; - ret = -EOPNOTSUPP; - if (!params.key->type->asym_eds_op) - goto error_params; - switch (op) { case KEYCTL_PKEY_ENCRYPT: params.op = kernel_pkey_encrypt; @@ -260,7 +297,16 @@ long keyctl_pkey_e_d_s(int op, if (!out) goto error_in; + down_read(¶ms.key->sem); + if (!params.key->type->asym_eds_op) { + ret = -EOPNOTSUPP; + goto out_up_key_sem; + } + ret = params.key->type->asym_eds_op(¶ms, in, out); + +out_up_key_sem: + up_read(¶ms.key->sem); if (ret < 0) goto error_out; @@ -305,31 +351,37 @@ long keyctl_pkey_verify(const struct keyctl_pkey_params __user *_params, ret = keyctl_pkey_params_get_2(_params, _info, KEYCTL_PKEY_VERIFY, ¶ms); if (ret < 0) - goto error_params; - - ret = -EOPNOTSUPP; - if (!params.key->type->asym_verify_signature) - goto error_params; + goto out_free_params; in = memdup_user(_in, params.in_len); if (IS_ERR(in)) { ret = PTR_ERR(in); - goto error_params; + goto out_free_params; } in2 = memdup_user(_in2, params.in2_len); if (IS_ERR(in2)) { ret = PTR_ERR(in2); - goto error_in; + goto out_free_in; } params.op = kernel_pkey_verify; + down_read(¶ms.key->sem); + if (!params.key->type->asym_verify_signature) { + ret = -EOPNOTSUPP; + goto out_up_key_sem; + } + ret = params.key->type->asym_verify_signature(¶ms, in, in2); +out_up_key_sem: + up_read(¶ms.key->sem); kfree(in2); -error_in: + +out_free_in: kfree(in); -error_params: + +out_free_params: keyctl_pkey_params_free(¶ms); return ret; } diff --git a/security/keys/keyring.c b/security/keys/keyring.c index 7143f3079d200f..357f5636081055 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c @@ -598,6 +598,12 @@ static int keyring_search_iterator(const void *object, void *iterator_data) return 0; } + /* A key the caller did not ask for must not decide the result. */ + if (!ctx->match_data.cmp(key, &ctx->match_data)) { + kleave(" = 0 [!match]"); + return 0; + } + /* skip invalidated, revoked and expired keys */ if (ctx->flags & KEYRING_SEARCH_DO_STATE_CHECK) { time64_t expiry = READ_ONCE(key->expiry); @@ -617,12 +623,6 @@ static int keyring_search_iterator(const void *object, void *iterator_data) } } - /* keys that don't match */ - if (!ctx->match_data.cmp(key, &ctx->match_data)) { - kleave(" = 0 [!match]"); - return 0; - } - /* key must have search permissions */ if (!(ctx->flags & KEYRING_SEARCH_NO_CHECK_PERM) && key_task_permission(make_key_ref(key, ctx->possessed), @@ -957,7 +957,6 @@ key_ref_t keyring_search(key_ref_t keyring, struct keyring_search_context ctx = { .index_key.type = type, .index_key.description = description, - .index_key.desc_len = strlen(description), .cred = current_cred(), .match_data.cmp = key_default_cmp, .match_data.raw_data = description, @@ -965,8 +964,14 @@ key_ref_t keyring_search(key_ref_t keyring, .flags = KEYRING_SEARCH_DO_STATE_CHECK, }; key_ref_t key; + size_t desclen; int ret; + desclen = strlen(description); + if (desclen >= KEY_MAX_DESC_SIZE) + return ERR_PTR(-EINVAL); + ctx.index_key.desc_len = desclen; + if (recurse) ctx.flags |= KEYRING_SEARCH_RECURSE; if (type->match_preparse) { @@ -1501,9 +1506,15 @@ static int __key_unlink_begin(struct key *keyring, struct key *key, struct assoc_array_edit **_edit) { struct assoc_array_edit *edit; + const void *object; BUG_ON(*_edit != NULL); + object = assoc_array_find(&keyring->keys, &keyring_assoc_array_ops, + &key->index_key); + if (!object || keyring_ptr_to_key(object) != key) + return -ENOENT; + edit = assoc_array_delete(&keyring->keys, &keyring_assoc_array_ops, &key->index_key); if (IS_ERR(edit)) diff --git a/security/keys/request_key.c b/security/keys/request_key.c index e6ba2d0543990d..22cd66a44da562 100644 --- a/security/keys/request_key.c +++ b/security/keys/request_key.c @@ -584,7 +584,6 @@ struct key *request_key_and_link(struct key_type *type, .index_key.type = type, .index_key.domain_tag = domain_tag, .index_key.description = description, - .index_key.desc_len = strlen(description), .cred = current_cred(), .match_data.cmp = key_default_cmp, .match_data.raw_data = description, @@ -595,8 +594,14 @@ struct key *request_key_and_link(struct key_type *type, }; struct key *key; key_ref_t key_ref; + size_t desclen; int ret; + desclen = strlen(description); + if (desclen >= KEY_MAX_DESC_SIZE) + return ERR_PTR(-EINVAL); + ctx.index_key.desc_len = desclen; + kenter("%s,%s,%p,%zu,%p,%p,%lx", ctx.index_key.type->name, ctx.index_key.description, callout_info, callout_len, aux, dest_keyring, flags); @@ -787,7 +792,6 @@ struct key *request_key_rcu(struct key_type *type, .index_key.type = type, .index_key.domain_tag = domain_tag, .index_key.description = description, - .index_key.desc_len = strlen(description), .cred = current_cred(), .match_data.cmp = key_default_cmp, .match_data.raw_data = description, @@ -797,6 +801,12 @@ struct key *request_key_rcu(struct key_type *type, }; struct key *key; key_ref_t key_ref; + size_t desclen; + + desclen = strlen(description); + if (desclen >= KEY_MAX_DESC_SIZE) + return ERR_PTR(-EINVAL); + ctx.index_key.desc_len = desclen; kenter("%s,%s", type->name, description); diff --git a/security/landlock/ns.c b/security/landlock/ns.c index cd44c927f83ae8..06d9784746fe9e 100644 --- a/security/landlock/ns.c +++ b/security/landlock/ns.c @@ -94,7 +94,8 @@ static const struct access_masks ns_permission = { * Shared check for namespace_init (creation via clone(2), unshare(2), * open_tree(2), or fsmount(2)) and namespace_install (use via setns(2)): denies * when the namespace type is not in the domain's allowed set. At allocation - * time @ns->ns_id is still zero and is logged as such. + * time @ns->ns_id is already set even though the namespace is not reachable + * from user space yet. * * Return: 0 if allowed, -EPERM if denied. */ diff --git a/security/security.c b/security/security.c index f6583d50739592..4727b8347fc4e2 100644 --- a/security/security.c +++ b/security/security.c @@ -1358,8 +1358,9 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, if (initxattrs) { /* Allocate +1 as terminator. */ - new_xattrs = kcalloc(blob_sizes.lbs_xattr_count + 1, - sizeof(*new_xattrs), GFP_NOFS); + new_xattrs = kzalloc_objs(*new_xattrs, + blob_sizes.lbs_xattr_count + 1, + GFP_NOFS); if (!new_xattrs) return -ENOMEM; } diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 6168dd5f91c227..9950f89dfaa230 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3894,8 +3894,7 @@ static int selinux_backing_file_alloc(struct file *backing_file, * mappings would have to be serialized. Size it dynamically: erofs * inode sharing adds a backing file without bumping s_stack_depth. */ - bfsec->layers = kmalloc_array(ubfsec->layer_count + 1, - sizeof(*bfsec->layers), GFP_KERNEL); + bfsec->layers = kmalloc_objs(*bfsec->layers, ubfsec->layer_count + 1); if (!bfsec->layers) return -ENOMEM; diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index d51dfe89231229..24b11d1891d856 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -557,9 +557,10 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk, * is set to AF_UNSPEC, if that is what is happening we want to reset * the socket */ if (addr->sa_family == AF_UNSPEC) { - netlbl_sock_delattr(sk); + rc = netlbl_sock_delattr(sk); + if (rc) + return rc; sksec->nlbl_state = NLBL_REQSKB; - rc = 0; return rc; } secattr = selinux_netlbl_sock_genattr(sk); diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index da77ad769c838c..0a08e57288e2a5 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3311,7 +3311,7 @@ int security_get_classes(struct selinux_policy *policy, rc = -ENOMEM; *nclasses = policydb->p_classes.nprim; - *classes = kcalloc(*nclasses, sizeof(**classes), GFP_ATOMIC); + *classes = kzalloc_objs(**classes, *nclasses, GFP_ATOMIC); if (!*classes) goto out; @@ -3375,7 +3375,7 @@ int security_get_permissions(struct selinux_policy *policy, rc = -ENOMEM; *nperms = match->permissions.nprim; - *perms = kcalloc(*nperms, sizeof(**perms), GFP_ATOMIC); + *perms = kzalloc_objs(**perms, *nperms, GFP_ATOMIC); if (!*perms) goto out; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 28a8e12603cecc..3a4a33568297b8 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -2656,22 +2656,26 @@ static int smack_netlbl_add(struct sock *sk) * * Remove the outbound smack value from a socket */ -static void smack_netlbl_delete(struct sock *sk) +static int smack_netlbl_delete(struct sock *sk) { struct socket_smack *ssp = smack_sock(sk); + int rc; /* * Take the label off the socket if one is set. */ if (ssp->smk_state != SMK_NETLBL_LABELED) - return; + return 0; local_bh_disable(); bh_lock_sock_nested(sk); - netlbl_sock_delattr(sk); + rc = netlbl_sock_delattr(sk); bh_unlock_sock(sk); local_bh_enable(); + if (rc) + return rc; ssp->smk_state = SMK_NETLBL_UNLABELED; + return 0; } /** @@ -2711,7 +2715,7 @@ static int smk_ipv4_check(struct sock *sk, struct sockaddr_in *sap) * Clear the socket netlabel if it's set. */ if (!rc) - smack_netlbl_delete(sk); + rc = smack_netlbl_delete(sk); } rcu_read_unlock(); @@ -4548,7 +4552,7 @@ static int smack_inet_conn_request(const struct sock *sk, struct sk_buff *skb, if (hskp == NULL) rc = netlbl_req_setattr(req, &ssp->smk_out->smk_netlabel); else - netlbl_req_delattr(req); + rc = netlbl_req_delattr(req); return rc; } diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index 5e5e0f78f26d50..8b58d0bd044c82 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -796,8 +796,8 @@ snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) return -EFAULT; retval = stream->ops->set_metadata(stream, &metadata); - stream->metadata_set = true; - + if (!retval) + stream->metadata_set = true; return retval; } @@ -1124,6 +1124,9 @@ static void snd_compr_task_free(struct snd_compr_task_runtime *task) kfree(task); } +static void snd_compr_task_free_one(struct snd_compr_stream *stream, + struct snd_compr_task_runtime *task); + static u64 snd_compr_seqno_next(struct snd_compr_stream *stream) { u64 seqno = ++stream->runtime->task_seqno; @@ -1132,7 +1135,9 @@ static u64 snd_compr_seqno_next(struct snd_compr_stream *stream) return seqno; } -static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_task *utask) +static int snd_compr_task_new(struct snd_compr_stream *stream, + struct snd_compr_task *utask, + struct snd_compr_task_runtime **runtime_task) { struct snd_compr_task_runtime *task; int retval, fd_i, fd_o; @@ -1169,12 +1174,11 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_ /* keep dmabuf reference until freed with task free ioctl */ get_dma_buf(task->input); get_dma_buf(task->output); - fd_install(fd_i, task->input->file); - fd_install(fd_o, task->output->file); utask->input_fd = fd_i; utask->output_fd = fd_o; list_add_tail(&task->list, &stream->runtime->tasks); stream->runtime->total_tasks++; + *runtime_task = task; return 0; free_driver_task: stream->ops->task_free(stream, task); @@ -1185,6 +1189,7 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_ static int snd_compr_task_create(struct snd_compr_stream *stream, unsigned long arg) { + struct snd_compr_task_runtime *runtime_task; int retval; if (stream->runtime->state != SNDRV_PCM_STATE_SETUP) @@ -1194,11 +1199,24 @@ static int snd_compr_task_create(struct snd_compr_stream *stream, unsigned long memdup_user((void __user *)arg, sizeof(*task)); if (IS_ERR(task)) return PTR_ERR(task); - retval = snd_compr_task_new(stream, task); - if (retval >= 0) - if (copy_to_user((void __user *)arg, task, sizeof(*task))) - retval = -EFAULT; - return retval; + retval = snd_compr_task_new(stream, task, &runtime_task); + if (retval < 0) + return retval; + + if (copy_to_user((void __user *)arg, task, sizeof(*task))) { + put_unused_fd(task->input_fd); + put_unused_fd(task->output_fd); + + dma_buf_put(runtime_task->input); + dma_buf_put(runtime_task->output); + snd_compr_task_free_one(stream, runtime_task); + return -EFAULT; + } + + fd_install(task->input_fd, runtime_task->input->file); + fd_install(task->output_fd, runtime_task->output->file); + + return 0; } static int snd_compr_task_start_prepare(struct snd_compr_task_runtime *task, diff --git a/sound/core/init.c b/sound/core/init.c index ee660dc4098b0f..2c4635666b02a3 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -385,6 +385,9 @@ struct snd_card *snd_card_ref(int idx) { struct snd_card *card; + if (WARN_ON(idx < 0 || idx >= SNDRV_CARDS)) + return NULL; + guard(mutex)(&snd_card_mutex); card = snd_cards[idx]; if (card) @@ -396,6 +399,9 @@ EXPORT_SYMBOL_GPL(snd_card_ref); /* return non-zero if a card is already locked */ int snd_card_locked(int card) { + if (WARN_ON(card < 0 || card >= SNDRV_CARDS)) + return 0; + guard(mutex)(&snd_card_mutex); return test_bit(card, snd_cards_lock); } diff --git a/sound/core/jack.c b/sound/core/jack.c index af2dc2cfbe1973..c35a9239052712 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c @@ -487,6 +487,7 @@ static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const cha jack_kctl->kctl = kctl; jack_kctl->mask_bits = mask; + INIT_LIST_HEAD(&jack_kctl->list); kctl->private_data = jack_kctl; kctl->private_free = snd_jack_kctl_private_free; @@ -555,13 +556,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, } jack = kzalloc_obj(struct snd_jack); - if (jack == NULL) - return -ENOMEM; + if (!jack) { + err = -ENOMEM; + goto fail_kctl; + } jack->id = kstrdup(id, GFP_KERNEL); if (jack->id == NULL) { - kfree(jack); - return -ENOMEM; + err = -ENOMEM; + goto fail_jack; } #ifdef CONFIG_SND_JACK_INPUT_DEV @@ -607,8 +610,13 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, #ifdef CONFIG_SND_JACK_INPUT_DEV input_free_device(jack->input_dev); #endif +fail_jack: kfree(jack->id); kfree(jack); +fail_kctl: + if (jack_kctl) + snd_ctl_remove(card, jack_kctl->kctl); + return err; } EXPORT_SYMBOL(snd_jack_new); diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c index 3118bb14231cec..5986e9b84ac0a2 100644 --- a/sound/core/memalloc.c +++ b/sound/core/memalloc.c @@ -725,7 +725,7 @@ static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size) size = PAGE_ALIGN(size); sgbuf->count = size >> PAGE_SHIFT; sgbuf->pages = kvzalloc_objs(*sgbuf->pages, sgbuf->count); - sgbuf->npages = kvcalloc(sgbuf->count, sizeof(*sgbuf->npages), GFP_KERNEL); + sgbuf->npages = kvzalloc_objs(*sgbuf->npages, sgbuf->count); if (!sgbuf->pages || !sgbuf->npages) goto error; diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index de17a132a6a55c..2beca295801d89 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c @@ -1182,7 +1182,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry, slot->assigned->index == idx && !strcmp(slot->assigned->name, str)) /* not changed */ break; - tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); + tbl = kmalloc_obj(*tbl); if (!tbl) break; tbl->oss_id = ch; diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c index 2d99df900f76dc..2fc52fe2cb52ee 100644 --- a/sound/core/oss/pcm_oss.c +++ b/sound/core/oss/pcm_oss.c @@ -1073,19 +1073,21 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream) goto failure; } - runtime->oss.params = 0; runtime->oss.prepare = 1; runtime->oss.buffer_used = 0; err = snd_pcm_runtime_buffer_set_silence(runtime); if (err < 0) goto failure; + runtime->oss.params = 0; runtime->oss.period_frames = snd_pcm_alsa_frames(substream, oss_period_size); err = 0; failure: - if (err) + if (err) { + runtime->oss.params = 1; snd_pcm_oss_release_buffers(substream); + } kfree(sw_params); kfree(params); kfree(sparams); diff --git a/sound/core/oss/pcm_plugin.c b/sound/core/oss/pcm_plugin.c index 3de71377999367..c5b3c67345eebf 100644 --- a/sound/core/oss/pcm_plugin.c +++ b/sound/core/oss/pcm_plugin.c @@ -48,12 +48,12 @@ static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t if (width < 0) return width; size = array3_size(frames, format->channels, width); - /* check for too large period size once again */ - if (size > 1024 * 1024) - return -ENOMEM; if (snd_BUG_ON(size % 8)) return -ENXIO; size /= 8; + /* check for too large period size once again */ + if (size > 1024 * 1024) + return -ENOMEM; if (plugin->buf_frames < frames) { kvfree(plugin->buf); plugin->buf = kvzalloc(size, GFP_KERNEL); diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 3549f0b8ffd2d5..da285358eb6550 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1084,16 +1084,26 @@ static int snd_pcm_dev_register(struct snd_device *device) err = snd_register_device(devtype, pcm->card, pcm->device, &snd_pcm_f_ops[cidx], pcm, pcm->streams[cidx].dev); - if (err < 0) { - list_del_init(&pcm->list); - return err; - } + if (err < 0) + goto error; for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) snd_pcm_timer_init(substream); } pcm_call_notify(pcm, n_register); + return 0; + +error: + while (--cidx >= 0) { + if (!pcm->streams[cidx].substream) + continue; + snd_unregister_device(pcm->streams[cidx].dev); + for (substream = pcm->streams[cidx].substream; substream; + substream = substream->next) + snd_pcm_timer_done(substream); + } + list_del_init(&pcm->list); return err; } diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 41feb5312ffece..0f53dca6811bbc 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -154,6 +154,7 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) struct dma_async_tx_descriptor *desc; enum dma_transfer_direction direction; unsigned long flags = DMA_CTRL_ACK; + int ret; direction = snd_pcm_substream_to_dma_direction(substream); @@ -171,6 +172,9 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) dmaengine_desc_set_callback(desc, dmaengine_pcm_dma_complete, NULL, substream); prtd->cookie = dmaengine_submit(desc); + ret = dma_submit_error(prtd->cookie); + if (ret) + return ret; return 0; } diff --git a/sound/core/pcm_drm_eld.c b/sound/core/pcm_drm_eld.c index 1941ee52006397..556e5a43710d02 100644 --- a/sound/core/pcm_drm_eld.c +++ b/sound/core/pcm_drm_eld.c @@ -362,8 +362,10 @@ int snd_parse_eld(struct device *dev, struct snd_parsed_hdmi_eld *e, } else if (ELD_FIXED_BYTES + mnl > size) { dev_info(dev, "HDMI: out of range MNL %d\n", mnl); goto out_fail; - } else - strscpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1); + } else { + memcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl); + e->monitor_name[mnl] = '\0'; + } for (i = 0; i < e->sad_count; i++) { if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) { diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index bb16738bb59195..65c7472ef22eb5 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -966,7 +966,7 @@ static int snd_interval_ratden(struct snd_interval *i, if (num > rats[k].num_max) continue; if (num < rats[k].num_min) - num = rats[k].num_max; + num = rats[k].num_min; else { unsigned int r; r = (num - rats[k].num_min) % rats[k].num_step; diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 92372bde6fb66b..da2b789962c213 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1127,7 +1127,13 @@ int snd_pcm_status64(struct snd_pcm_substream *substream, status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; if (snd_pcm_running(substream)) { - snd_pcm_update_hw_ptr(substream); + if (snd_pcm_update_hw_ptr(substream) < 0) { + /* update_hw_ptr may have put us in xrun state, update state */ + status->state = runtime->state; + status->suspended_state = runtime->suspended_state; + status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; + status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; + } if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp_sec = runtime->status->tstamp.tv_sec; status->tstamp_nsec = diff --git a/sound/core/seq/seq_ump_convert.c b/sound/core/seq/seq_ump_convert.c index 62bdef6dca58c9..b42a7ffbf31eaa 100644 --- a/sound/core/seq/seq_ump_convert.c +++ b/sound/core/seq/seq_ump_convert.c @@ -380,6 +380,10 @@ static int cvt_ump_midi1_to_midi2(struct snd_seq_client *dest, switch (midi1->note.status) { case UMP_MSG_STATUS_NOTE_ON: case UMP_MSG_STATUS_NOTE_OFF: + /* MIDI 2.0 doesn't treat a note-on with 0 velocity as note-off */ + if (midi1->note.status == UMP_MSG_STATUS_NOTE_ON && + !midi1->note.velocity) + midi2->note.status = UMP_MSG_STATUS_NOTE_OFF; midi2->note.note = midi1->note.note; midi2->note.velocity = upscale_7_to_16bit(midi1->note.velocity); break; @@ -453,6 +457,10 @@ static int cvt_ump_midi2_to_midi1(struct snd_seq_client *dest, case UMP_MSG_STATUS_NOTE_OFF: midi1->note.note = midi2->note.note; midi1->note.velocity = downscale_16_to_7bit(midi2->note.velocity); + /* a note-on with 0 velocity would be a note-off in MIDI 1.0 */ + if (midi2->note.status == UMP_MSG_STATUS_NOTE_ON && + !midi1->note.velocity) + midi1->note.velocity = 1; break; case UMP_MSG_STATUS_POLY_PRESSURE: midi1->paf.note = midi2->paf.note; @@ -630,7 +638,7 @@ static int note_ev_to_ump_midi1(const struct snd_seq_event *event, union snd_ump_midi1_msg *data, unsigned char status) { - if (!event->data.note.velocity) + if (status == UMP_MSG_STATUS_NOTE_ON && !event->data.note.velocity) status = UMP_MSG_STATUS_NOTE_OFF; data->note.status = status; data->note.channel = event->data.note.channel & 0x0f; diff --git a/sound/core/timer.c b/sound/core/timer.c index 905176bf6948d7..f977eea64f31e3 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -1802,7 +1802,7 @@ static int snd_timer_user_tselect(struct file *file, struct snd_timer_user *tu; struct snd_timer_select tselect; char str[32]; - int err = 0; + int err; tu = file->private_data; if (tu->timeri) { @@ -1810,18 +1810,15 @@ static int snd_timer_user_tselect(struct file *file, snd_timer_instance_free(tu->timeri); tu->timeri = NULL; } - if (copy_from_user(&tselect, _tselect, sizeof(tselect))) { - err = -EFAULT; - goto __err; - } - sprintf(str, "application %i", current->pid); + if (copy_from_user(&tselect, _tselect, sizeof(tselect))) + return -EFAULT; + + scnprintf(str, sizeof(str), "application %i", current->pid); if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE) tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION; tu->timeri = snd_timer_instance_new(str); - if (!tu->timeri) { - err = -ENOMEM; - goto __err; - } + if (!tu->timeri) + return -ENOMEM; tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST; tu->timeri->callback = tu->tread @@ -1836,7 +1833,6 @@ static int snd_timer_user_tselect(struct file *file, tu->timeri = NULL; } - __err: return err; } diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig index 6debd8e95cb7a5..4d875d0f5a17b9 100644 --- a/sound/drivers/Kconfig +++ b/sound/drivers/Kconfig @@ -55,7 +55,10 @@ config SND_PCSP If you don't have a sound card in your computer, you can include a driver for the PC speaker which allows it to act like a primitive sound card. - This driver also replaces the pcspkr driver for beeps. + This driver also replaces the pcspkr driver for beeps. If the + pcspkr driver (INPUT_PCSPKR) is enabled too, only pcspkr is loaded + automatically. To use this driver instead, prevent pcspkr from + loading, and load this driver explicitly. You can compile this as a module which will be called snd-pcsp. diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c index 66bee8a2ce343b..98685e6158cc03 100644 --- a/sound/drivers/pcmtest.c +++ b/sound/drivers/pcmtest.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,8 @@ #define MAX_PATTERN_LEN 4096 +#define MAX_VOLUME 100 + static int index = -1; static char *id = "pcmtest"; static bool enable = true; @@ -65,6 +68,8 @@ static bool inject_hwpars_err; static bool inject_prepare_err; static bool inject_trigger_err; static bool inject_open_err; +static bool inject_ctl_no_event; +static bool inject_ctl_spurious_event; static short fill_mode = FILL_MODE_PAT; @@ -109,11 +114,17 @@ module_param(inject_trigger_err, bool, 0600); MODULE_PARM_DESC(inject_trigger_err, "Inject EINVAL error in the 'trigger' callback"); module_param(inject_open_err, bool, 0600); MODULE_PARM_DESC(inject_open_err, "Inject EBUSY error in the 'open' callback"); +module_param(inject_ctl_no_event, bool, 0600); +MODULE_PARM_DESC(inject_ctl_no_event, "Report no change from the control 'put' callback"); +module_param(inject_ctl_spurious_event, bool, 0600); +MODULE_PARM_DESC(inject_ctl_spurious_event, "Always report a change from the control 'put' callback"); struct pcmtst { struct snd_pcm *pcm; struct snd_card *card; struct platform_device *pdev; + spinlock_t mixer_lock; /* protects volume[] */ + long volume[2]; }; struct pcmtst_buf_iter { @@ -544,6 +555,58 @@ static const struct snd_pcm_ops snd_pcmtst_capture_ops = { .pointer = snd_pcmtst_pcm_pointer, }; +static int snd_pcmtst_volume_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = MAX_VOLUME; + return 0; +} + +static int snd_pcmtst_volume_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct pcmtst *pcmtst = snd_kcontrol_chip(kcontrol); + + guard(spinlock_irq)(&pcmtst->mixer_lock); + ucontrol->value.integer.value[0] = pcmtst->volume[0]; + ucontrol->value.integer.value[1] = pcmtst->volume[1]; + return 0; +} + +static int snd_pcmtst_volume_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct pcmtst *pcmtst = snd_kcontrol_chip(kcontrol); + long left = ucontrol->value.integer.value[0]; + long right = ucontrol->value.integer.value[1]; + bool changed; + + if (left < 0 || left > MAX_VOLUME || right < 0 || right > MAX_VOLUME) + return -EINVAL; + + guard(spinlock_irq)(&pcmtst->mixer_lock); + changed = pcmtst->volume[0] != left || pcmtst->volume[1] != right; + pcmtst->volume[0] = left; + pcmtst->volume[1] = right; + + if (inject_ctl_no_event) + return 0; + if (inject_ctl_spurious_event) + return 1; + return changed; +} + +static const struct snd_kcontrol_new snd_pcmtst_volume = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Test Playback Volume", + .info = snd_pcmtst_volume_info, + .get = snd_pcmtst_volume_get, + .put = snd_pcmtst_volume_put, +}; + static int snd_pcmtst_new_pcm(struct pcmtst *pcmtst) { struct snd_pcm *pcm; @@ -582,11 +645,16 @@ static int pcmtst_probe(struct platform_device *pdev) pcmtst = card->private_data; pcmtst->card = card; pcmtst->pdev = pdev; + spin_lock_init(&pcmtst->mixer_lock); err = snd_pcmtst_new_pcm(pcmtst); if (err < 0) return err; + err = snd_ctl_add(card, snd_ctl_new1(&snd_pcmtst_volume, pcmtst)); + if (err < 0) + return err; + strscpy(card->driver, "PCM-TEST Driver"); strscpy(card->shortname, "PCM-Test"); strscpy(card->longname, "PCM-Test virtual driver"); diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c index ff6bb375c90014..d7d28ec2250b6b 100644 --- a/sound/drivers/pcsp/pcsp.c +++ b/sound/drivers/pcsp/pcsp.c @@ -22,7 +22,14 @@ MODULE_AUTHOR("Stas Sergeev "); MODULE_DESCRIPTION("PC-Speaker driver"); MODULE_LICENSE("GPL"); +/* + * The input driver pcspkr binds to the same platform device and has the same + * driver name, so only one of the two can be loaded. If pcspkr is available, + * let it handle the beeps, and leave loading this driver to the user. + */ +#if !IS_ENABLED(CONFIG_INPUT_PCSPKR) MODULE_ALIAS("platform:pcspkr"); +#endif static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c index cc9c325df910b8..8f8bcbcdc87961 100644 --- a/sound/drivers/serial-u16550.c +++ b/sound/drivers/serial-u16550.c @@ -746,7 +746,7 @@ static int snd_uart16550_create(struct snd_card *card, int err; - uart = devm_kzalloc(card->dev, sizeof(*uart), GFP_KERNEL); + uart = devm_kzalloc_obj(card->dev, *uart); if (!uart) return -ENOMEM; uart->adaptor = adaptor; diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c index 376a9a17547956..4ca5e04214382c 100644 --- a/sound/firewire/bebob/bebob_maudio.c +++ b/sound/firewire/bebob/bebob_maudio.c @@ -112,7 +112,7 @@ int snd_bebob_maudio_load_firmware(struct fw_unit *unit) return -ENXIO; } - cues = kmalloc_array(3, sizeof(*cues), GFP_KERNEL); + cues = kmalloc_objs(*cues, 3); if (!cues) return -ENOMEM; @@ -260,8 +260,7 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814) struct special_params *params; int err; - params = devm_kzalloc(&bebob->card->card_dev, - sizeof(struct special_params), GFP_KERNEL); + params = devm_kzalloc_obj(&bebob->card->card_dev, struct special_params); if (!params) return -ENOMEM; diff --git a/sound/firewire/dice/dice-transaction.c b/sound/firewire/dice/dice-transaction.c index a3f7dfa990a4e5..a8099108776dce 100644 --- a/sound/firewire/dice/dice-transaction.c +++ b/sound/firewire/dice/dice-transaction.c @@ -275,8 +275,7 @@ static int get_subaddrs(struct snd_dice *dice) unsigned int i; int err; - pointers = kmalloc_array(ARRAY_SIZE(min_values), sizeof(__be32), - GFP_KERNEL); + pointers = kmalloc_objs(__be32, ARRAY_SIZE(min_values)); if (pointers == NULL) return -ENOMEM; diff --git a/sound/firewire/fireface/ff-protocol-former.c b/sound/firewire/fireface/ff-protocol-former.c index 0907d0a2296f65..d3c354a207307f 100644 --- a/sound/firewire/fireface/ff-protocol-former.c +++ b/sound/firewire/fireface/ff-protocol-former.c @@ -95,7 +95,7 @@ static int former_switch_fetching_mode(struct snd_ff *ff, bool enable) for (i = 0; i < SND_FF_STREAM_MODE_COUNT; ++i) count = max(count, ff->spec->pcm_playback_channels[i]); - reg = kcalloc(count, sizeof(__le32), GFP_KERNEL); + reg = kzalloc_objs(__le32, count); if (!reg) return -ENOMEM; diff --git a/sound/firewire/motu/motu-command-dsp-message-parser.c b/sound/firewire/motu/motu-command-dsp-message-parser.c index c6440e6e360b7f..8caeb1019dfc29 100644 --- a/sound/firewire/motu/motu-command-dsp-message-parser.c +++ b/sound/firewire/motu/motu-command-dsp-message-parser.c @@ -37,7 +37,7 @@ int snd_motu_command_dsp_message_parser_new(struct snd_motu *motu) { struct msg_parser *parser; - parser = devm_kzalloc(&motu->card->card_dev, sizeof(*parser), GFP_KERNEL); + parser = devm_kzalloc_obj(&motu->card->card_dev, *parser); if (!parser) return -ENOMEM; spin_lock_init(&parser->lock); diff --git a/sound/firewire/motu/motu-register-dsp-message-parser.c b/sound/firewire/motu/motu-register-dsp-message-parser.c index 4ec23e6880d913..3541d540b8c930 100644 --- a/sound/firewire/motu/motu-register-dsp-message-parser.c +++ b/sound/firewire/motu/motu-register-dsp-message-parser.c @@ -101,7 +101,7 @@ struct msg_parser { int snd_motu_register_dsp_message_parser_new(struct snd_motu *motu) { struct msg_parser *parser; - parser = devm_kzalloc(&motu->card->card_dev, sizeof(*parser), GFP_KERNEL); + parser = devm_kzalloc_obj(&motu->card->card_dev, *parser); if (!parser) return -ENOMEM; spin_lock_init(&parser->lock); diff --git a/sound/firewire/motu/motu-stream.c b/sound/firewire/motu/motu-stream.c index e5f21360cfb79e..a8e67d12ff2c57 100644 --- a/sound/firewire/motu/motu-stream.c +++ b/sound/firewire/motu/motu-stream.c @@ -186,8 +186,8 @@ int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate, } motu->cache.size = motu->tx_stream.syt_interval * frames_per_buffer; - motu->cache.event_offsets = kcalloc(motu->cache.size, sizeof(*motu->cache.event_offsets), - GFP_KERNEL); + motu->cache.event_offsets = kzalloc_objs(*motu->cache.event_offsets, + motu->cache.size); if (!motu->cache.event_offsets) { fw_iso_resources_free(&motu->tx_resources); fw_iso_resources_free(&motu->rx_resources); diff --git a/sound/firewire/oxfw/oxfw-scs1x.c b/sound/firewire/oxfw/oxfw-scs1x.c index 21412a3ca9f4c4..9a6e572af4fc20 100644 --- a/sound/firewire/oxfw/oxfw-scs1x.c +++ b/sound/firewire/oxfw/oxfw-scs1x.c @@ -371,8 +371,7 @@ int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw) struct fw_scs1x *scs; int err; - scs = devm_kzalloc(&oxfw->card->card_dev, sizeof(struct fw_scs1x), - GFP_KERNEL); + scs = devm_kzalloc_obj(&oxfw->card->card_dev, struct fw_scs1x); if (!scs) return -ENOMEM; scs->fw_dev = fw_parent_device(oxfw->unit); diff --git a/sound/firewire/oxfw/oxfw-spkr.c b/sound/firewire/oxfw/oxfw-spkr.c index f2767fb1965ca7..1bf19310f3a076 100644 --- a/sound/firewire/oxfw/oxfw-spkr.c +++ b/sound/firewire/oxfw/oxfw-spkr.c @@ -270,8 +270,7 @@ int snd_oxfw_add_spkr(struct snd_oxfw *oxfw, bool is_lacie) unsigned int i, first_ch; int err; - spkr = devm_kzalloc(&oxfw->card->card_dev, sizeof(struct fw_spkr), - GFP_KERNEL); + spkr = devm_kzalloc_obj(&oxfw->card->card_dev, struct fw_spkr); if (!spkr) return -ENOMEM; oxfw->spec = spkr; diff --git a/sound/hda/codecs/ca0132.c b/sound/hda/codecs/ca0132.c index b3e768be8a6956..b7c97a0793bc6f 100644 --- a/sound/hda/codecs/ca0132.c +++ b/sound/hda/codecs/ca0132.c @@ -1062,6 +1062,7 @@ enum dsp_download_state { */ #define AE5_STRIP_MAX_LEDS 100 +#define AE5_ONCARD_LEDS 5 struct ca0132_spec { struct hda_gen_spec gen; @@ -1167,10 +1168,11 @@ struct ca0132_spec { bool use_alt_controls; #if IS_ENABLED(CONFIG_SND_HDA_DSP_LOADER) - /* AE-5 WS2812 strip control */ + /* AE-5 WS2812 strip and on-card LED control */ struct mutex ae5_strip_mutex; u32 ae5_strip_cur_colors[AE5_STRIP_MAX_LEDS]; int ae5_strip_cur_num_leds; + u8 ae5_oncard_cur_colors[AE5_ONCARD_LEDS * 3]; #endif }; @@ -8421,8 +8423,6 @@ static int ae5_strip_send_frame(struct hda_codec *codec, const u32 *grb_colors, u32 ser_base[4], ser_clk[4], ser_out[4]; } saved; __le32 *dst; - int word_idx = 0; - int frame_words; int led, w, i; int retries = 20; /* ~100ms max */ @@ -8470,38 +8470,25 @@ static int ae5_strip_send_frame(struct hda_codec *codec, const u32 *grb_colors, usleep_range(5000, 10000); } - /* 1. Populate the 32KB DMA buffer with repeating WS2812 frames + reset gaps */ + /* 1. Populate the 32KB DMA buffer: 1 WS2812 frame + reset gap, rest zero */ memset(dmab.area, 0, AE5_STRIP_DMA_SIZE); dst = (__le32 *)dmab.area; - /* Words per frame: preamble + (num_leds * words_per_led) + reset gap */ - frame_words = AE5_STRIP_PREAMBLE_WORDS + (num_leds * AE5_STRIP_WORDS_PER_LED) + - AE5_STRIP_RESET_GAP_WORDS; + /* Preamble per Windows CtxHda FUN_00042944 */ + for (w = 0; w < AE5_STRIP_PREAMBLE_WORDS; w++) + *dst++ = 0; - while (word_idx + frame_words <= AE5_STRIP_TOTAL_WORDS) { - /* Preamble per Windows CtxHda FUN_00042944 */ - for (w = 0; w < AE5_STRIP_PREAMBLE_WORDS; w++) { - *dst++ = 0; - word_idx++; - } - /* LEDs */ - for (led = 0; led < num_leds; led++) { - ae5_strip_encode_24(grb_colors[led], enc_words); - for (w = 0; w < AE5_STRIP_WORDS_PER_LED; w++) { - *dst++ = cpu_to_le32(enc_words[w]); - word_idx++; - } - } - /* Zero reset gap (> 1.8 ms; WS2812 requires > 50 us low) */ - for (w = 0; w < AE5_STRIP_RESET_GAP_WORDS; w++) { - *dst++ = 0; - word_idx++; - } + /* LEDs */ + for (led = 0; led < num_leds; led++) { + ae5_strip_encode_24(grb_colors[led], enc_words); + for (w = 0; w < AE5_STRIP_WORDS_PER_LED; w++) + *dst++ = cpu_to_le32(enc_words[w]); } - while (word_idx < AE5_STRIP_TOTAL_WORDS) { + + /* Zero reset gap (> 1.8 ms; WS2812 requires > 50 us low) */ + for (w = 0; w < AE5_STRIP_RESET_GAP_WORDS; w++) *dst++ = 0; - word_idx++; - } + /* Ensure DMA buffer writes are committed before triggering the HDA stream */ wmb(); @@ -8572,12 +8559,13 @@ static int ae5_strip_send_frame(struct hda_codec *codec, const u32 *grb_colors, /* 3. Trigger stream transmission on HDA link */ snd_hdac_dsp_trigger(hstr, true); /* - * WS2812 latches on the >50us reset gap after one frame. The 32KB buffer holds ~64 - * repeating frame+reset cycles; at ~1.4ms/frame a 15ms run transmits ~10 complete - * cycles - more than enough to latch reliably. Keep it short so rapid sysfs writes - * (OpenRGB effects/theme changes) are not serialized behind a 1s blocking sleep. + * WS2812 latches on the >50us reset gap after the frame. At 44.1kHz stereo + * (88.2k words/s), a 100-LED frame + reset gap is 488 words (~5.5ms); a 10-LED + * strip is 128 words (~1.5ms). Sleeping 8-10ms guarantees the entire frame and + * latch reset have completed. The remainder of the 32KB buffer is zero-filled, + * so stopping the stream during the trailing zeros never truncates an active LED. */ - usleep_range(15000, 20000); + usleep_range(8000, 10000); snd_hdac_dsp_trigger(hstr, false); codec_dbg(codec, "AE5 strip: trigger complete\n"); @@ -8704,6 +8692,90 @@ static int ae5_strip_num_leds_put(struct snd_kcontrol *kcontrol, return 1; } +static void ae5_oncard_write_bit(struct ca0132_spec *spec, bool bit) +{ + writew(bit ? 0x102 : 0x002, spec->mem_base + 0x320); + writew(0x103, spec->mem_base + 0x320); + writew(0x003, spec->mem_base + 0x320); +} + +/* + * Caller must hold spec->ae5_strip_mutex. + */ +static void ae5_oncard_send_frame(struct hda_codec *codec, const u8 *rgb_colors) +{ + struct ca0132_spec *spec = codec->spec; + int i, bit; + + if (!spec || !spec->mem_base) + return; + + lockdep_assert_held(&spec->ae5_strip_mutex); + CLASS(snd_hda_power_pm, pm)(codec); + + /* Start frame: 32 zeroes */ + for (i = 0; i < 32; i++) + ae5_oncard_write_bit(spec, false); + + /* 5 APA102 LEDs: 8-bit brightness (0xFF), Blue, Green, Red */ + for (i = 0; i < AE5_ONCARD_LEDS; i++) { + u8 r = rgb_colors[i * 3 + 0]; + u8 g = rgb_colors[i * 3 + 1]; + u8 b = rgb_colors[i * 3 + 2]; + u32 val = 0xff000000 | ((u32)b << 16) | ((u32)g << 8) | (u32)r; + + for (bit = 31; bit >= 0; bit--) + ae5_oncard_write_bit(spec, (val >> bit) & 1); + } + + /* End frame: 32 ones */ + for (i = 0; i < 32; i++) + ae5_oncard_write_bit(spec, true); + + /* Return GPIO pins 2 (data) and 3 (clock) to idle low */ + ca0113_mmio_gpio_set(codec, 2, false); + ca0113_mmio_gpio_set(codec, 3, false); +} + +static int ae5_oncard_ctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; + uinfo->count = AE5_ONCARD_LEDS * 3; + return 0; +} + +static int ae5_oncard_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct ca0132_spec *spec = codec->spec; + + guard(mutex)(&spec->ae5_strip_mutex); + memcpy(ucontrol->value.bytes.data, spec->ae5_oncard_cur_colors, + AE5_ONCARD_LEDS * 3); + return 0; +} + +static int ae5_oncard_ctl_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct ca0132_spec *spec = codec->spec; + bool change; + + guard(mutex)(&spec->ae5_strip_mutex); + change = memcmp(spec->ae5_oncard_cur_colors, ucontrol->value.bytes.data, + AE5_ONCARD_LEDS * 3) != 0; + if (!change) + return 0; + + memcpy(spec->ae5_oncard_cur_colors, ucontrol->value.bytes.data, + AE5_ONCARD_LEDS * 3); + ae5_oncard_send_frame(codec, spec->ae5_oncard_cur_colors); + return 1; +} + static const struct snd_kcontrol_new ae5_strip_ctls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_CARD, @@ -8723,6 +8795,15 @@ static const struct snd_kcontrol_new ae5_strip_ctls[] = { .get = ae5_strip_num_leds_get, .put = ae5_strip_num_leds_put, }, + { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .name = "AE-5 On-Card LEDs", + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .info = ae5_oncard_ctl_info, + .get = ae5_oncard_ctl_get, + .put = ae5_oncard_ctl_put, + }, }; static int ae5_add_strip_controls(struct hda_codec *codec) diff --git a/sound/hda/codecs/cirrus/cs420x.c b/sound/hda/codecs/cirrus/cs420x.c index 6cba01228c2712..85c2ecf46d3834 100644 --- a/sound/hda/codecs/cirrus/cs420x.c +++ b/sound/hda/codecs/cirrus/cs420x.c @@ -571,7 +571,6 @@ static const struct hda_model_fixup cs4208_models[] = { static const struct hda_quirk cs4208_fixup_tbl[] = { SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO), - SND_PCI_QUIRK(0x8086, 0x7270, "MacBookAir 7,2", CS4208_MAC_AUTO), {} /* terminator */ }; @@ -584,7 +583,6 @@ static const struct hda_quirk cs4208_mac_fixup_tbl[] = { SND_PCI_QUIRK(0x106b, 0x7800, "MacPro 6,1", CS4208_MACMINI), SND_PCI_QUIRK(0x106b, 0x7b00, "MacBookPro 12,1", CS4208_MBP11), SND_PCI_QUIRK(0x106b, 0x7f00, "iMac 16,1", CS4208_MBP11), - SND_PCI_QUIRK(0x8086, 0x7270, "MacBookAir 7,2", CS4208_MBA6), {} /* terminator */ }; diff --git a/sound/hda/codecs/conexant.c b/sound/hda/codecs/conexant.c index 88651a36dd3372..5b5250043a502c 100644 --- a/sound/hda/codecs/conexant.c +++ b/sound/hda/codecs/conexant.c @@ -289,6 +289,7 @@ enum { CXT_FIXUP_HEADPHONE_MIC_PIN, CXT_FIXUP_HEADPHONE_MIC, CXT_FIXUP_GPIO1, + CXT_FIXUP_GPIO2, CXT_FIXUP_ASPIRE_DMIC, CXT_FIXUP_THINKPAD_ACPI, CXT_FIXUP_LENOVO_XPAD_ACPI, @@ -973,7 +974,6 @@ static const struct hda_fixup cxt_fixups[] = { { 0x1a, 0x05d71030 }, { } }, - .chain_id = CXT_FIXUP_STEREO_DMIC, }, [CXT_FIXUP_INC_MIC_BOOST] = { .type = HDA_FIXUP_FUNC, @@ -1001,6 +1001,15 @@ static const struct hda_fixup cxt_fixups[] = { { } }, }, + [CXT_FIXUP_GPIO2] = { + .type = HDA_FIXUP_VERBS, + .v.verbs = (const struct hda_verb[]) { + { 0x01, AC_VERB_SET_GPIO_MASK, 0x02 }, + { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02 }, + { 0x01, AC_VERB_SET_GPIO_DATA, 0x02 }, + { } + }, + }, [CXT_FIXUP_ASPIRE_DMIC] = { .type = HDA_FIXUP_FUNC, .v.func = cxt_fixup_stereo_dmic, @@ -1223,6 +1232,8 @@ static const struct hda_quirk cxt5066_fixups[] = { SND_PCI_QUIRK(0x14f1, 0x0252, "MBX-Z60MR100", CXT_FIXUP_HP_A_U), SND_PCI_QUIRK(0x14f1, 0x0265, "SWS JS201D", CXT_PINCFG_SWS_JS201D), SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO), + SND_PCI_QUIRK(0x1558, 0xa600, "Acer TravelLite TL05-41M", + CXT_FIXUP_GPIO2), SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), diff --git a/sound/hda/codecs/generic.c b/sound/hda/codecs/generic.c index 12e40c382c16ae..50b9b05fac594d 100644 --- a/sound/hda/codecs/generic.c +++ b/sound/hda/codecs/generic.c @@ -3913,7 +3913,7 @@ static int create_mute_led_cdev(struct hda_codec *codec, int idx = micmute ? LED_AUDIO_MICMUTE : LED_AUDIO_MUTE; int err; - cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL); + cdev = devm_kzalloc_obj(&codec->core.dev, *cdev); if (!cdev) return -ENOMEM; diff --git a/sound/hda/codecs/realtek/alc269.c b/sound/hda/codecs/realtek/alc269.c index 06f8728f6dbe76..9bca07c2c99ac8 100644 --- a/sound/hda/codecs/realtek/alc269.c +++ b/sound/hda/codecs/realtek/alc269.c @@ -4542,7 +4542,6 @@ enum { ALC256_FIXUP_HONOR_DRA_XX_HEADSET_MODE, ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX, ALC287_FIXUP_ACER_MICMUTE_LED, - ALC236_FIXUP_DELL_HP_POP_NOISE, ALC274_FIXUP_HP_89E9_GPIO, ALC274_FIXUP_HP_VERBS, ALC287_FIXUP_AW88399_I2C_2, @@ -6432,7 +6431,6 @@ static const struct hda_fixup alc269_fixups[] = { { 0x1e, 0x411111f0 }, { } }, - .chain_id = ALC269_FIXUP_DMIC, }, [ALC269_FIXUP_CZC_TMI] = { .type = HDA_FIXUP_PINS, @@ -6450,7 +6448,6 @@ static const struct hda_fixup alc269_fixups[] = { { 0x20, 0x8000ffff }, { } }, - .chain_id = ALC269_FIXUP_DMIC, }, [ALC269_FIXUP_CZC_L101] = { .type = HDA_FIXUP_PINS, @@ -6468,7 +6465,6 @@ static const struct hda_fixup alc269_fixups[] = { { 0x1e, 0x411111f0 }, { } }, - .chain_id = ALC269_FIXUP_DMIC, }, [ALC269_FIXUP_LEMOTE_A1802] = { .type = HDA_FIXUP_PINS, @@ -6486,7 +6482,6 @@ static const struct hda_fixup alc269_fixups[] = { { 0x21, 0x03214020 }, { } }, - .chain_id = ALC269_FIXUP_DMIC, }, [ALC269_FIXUP_LEMOTE_A190X] = { .type = HDA_FIXUP_PINS, @@ -6498,7 +6493,6 @@ static const struct hda_fixup alc269_fixups[] = { { 0x1b, 0x0201401f }, /* front lineout */ { } }, - .chain_id = ALC269_FIXUP_DMIC, }, [ALC256_FIXUP_INTEL_NUC8_RUGGED] = { .type = HDA_FIXUP_PINS, @@ -7408,12 +7402,6 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC2XX_FIXUP_HEADSET_MIC, }, - [ALC236_FIXUP_DELL_HP_POP_NOISE] = { - .type = HDA_FIXUP_FUNC, - .v.func = alc285_fixup_invalidate_dacs, - .chained = true, - .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE - }, [ALC274_FIXUP_HP_89E9_GPIO] = { .type = HDA_FIXUP_FUNC, .v.func = alc274_fixup_hp_89e9_amp, @@ -7550,9 +7538,10 @@ static const struct hda_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x1025, 0x166c, "Acer Predator PH16-71", ALC2XX_FIXUP_HEADSET_MIC), SND_PCI_QUIRK(0x1025, 0x1679, "Acer Nitro 16 AN16-41", ALC2XX_FIXUP_HEADSET_MIC), SND_PCI_QUIRK(0x1025, 0x169a, "Acer Swift SFG16", ALC256_FIXUP_ACER_SFG16_MICMUTE_LED), + SND_PCI_QUIRK(0x1025, 0x170f, "Acer Predator PHN16-71", ALC2XX_FIXUP_HEADSET_MIC), SND_PCI_QUIRK(0x1025, 0x171e, "Acer Nitro ANV15-51", ALC245_FIXUP_ACER_MICMUTE_LED), SND_PCI_QUIRK(0x1025, 0x172c, "Acer Nitro ANV16-41", ALC2XX_FIXUP_HEADSET_MIC), - SND_PCI_QUIRK(0x1025, 0x1731, "Acer Predator PHN16-72", ALC2XX_FIXUP_HEADSET_MIC), + SND_PCI_QUIRK(0x1025, 0x1731, "Acer Predator PHN16-72", ALC245_FIXUP_ACER_MICMUTE_LED), SND_PCI_QUIRK(0x1025, 0x173a, "Acer Swift SFG14-73", ALC245_FIXUP_ACER_MICMUTE_LED), SND_PCI_QUIRK(0x1025, 0x173b, "Acer Swift SFG16-72", ALC245_FIXUP_ACER_MICMUTE_LED), SND_PCI_QUIRK(0x1025, 0x1758, "Acer Nitro ANV15-41", ALC245_FIXUP_ACER_MICMUTE_LED), @@ -7651,12 +7640,12 @@ static const struct hda_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x1028, 0x0cc3, "Dell Oasis 14 Low Weight MTL-U", ALC289_FIXUP_DELL_CS35L41_SPI_2), SND_PCI_QUIRK(0x1028, 0x0cc4, "Dell Oasis 16 MTL-H/U", ALC289_FIXUP_DELL_CS35L41_SPI_2), SND_PCI_QUIRK(0x1028, 0x0cc5, "Dell Oasis 14", ALC289_FIXUP_RTK_AMP_DUAL_SPK), - SND_PCI_QUIRK(0x1028, 0x0d56, "Dell Pro Tower QCT1255", ALC236_FIXUP_DELL_HP_POP_NOISE), - SND_PCI_QUIRK(0x1028, 0x0d58, "Dell Pro Micro QCM1255", ALC236_FIXUP_DELL_HP_POP_NOISE), - SND_PCI_QUIRK(0x1028, 0x0d5a, "Dell Pro Slim QCS1255", ALC236_FIXUP_DELL_HP_POP_NOISE), - SND_PCI_QUIRK(0x1028, 0x0e6b, "Dell Pro Tower QCT1255", ALC236_FIXUP_DELL_HP_POP_NOISE), - SND_PCI_QUIRK(0x1028, 0x0e6c, "Dell Pro Slim QCS1255", ALC236_FIXUP_DELL_HP_POP_NOISE), - SND_PCI_QUIRK(0x1028, 0x0e6d, "Dell Pro Micro QCM1255", ALC236_FIXUP_DELL_HP_POP_NOISE), + SND_PCI_QUIRK(0x1028, 0x0d56, "Dell Pro Tower QCT1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), + SND_PCI_QUIRK(0x1028, 0x0d58, "Dell Pro Micro QCM1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), + SND_PCI_QUIRK(0x1028, 0x0d5a, "Dell Pro Slim QCS1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), + SND_PCI_QUIRK(0x1028, 0x0e6b, "Dell Pro Tower QCT1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), + SND_PCI_QUIRK(0x1028, 0x0e6c, "Dell Pro Slim QCS1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), + SND_PCI_QUIRK(0x1028, 0x0e6d, "Dell Pro Micro QCM1255", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE), SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), @@ -7870,6 +7859,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x103c, 0x89da, "HP Spectre x360 14t-ea100", ALC245_FIXUP_HP_SPECTRE_X360_EU0XXX), SND_PCI_QUIRK(0x103c, 0x89e7, "HP Elite x2 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x89f6, "HP Pavilion 15-eg2xxx", ALC287_FIXUP_HP_GPIO_LED), + SND_PCI_QUIRK(0x103c, 0x89fa, "HP Pavilion Aero Laptop 13-be1xxx", ALC287_FIXUP_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8a05, "HP Dragonfly Folio G3 2-in-1", ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio G3 2-in-1", ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8a0e, "HP Pavilion Laptop 15-eh2xxx", ALC287_FIXUP_HP_GPIO_LED), @@ -8612,6 +8602,10 @@ static const struct hda_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x17aa, 0x38b5, "Legion Slim 7 16IRH8", ALC287_FIXUP_CS35L41_I2C_2), SND_PCI_QUIRK(0x17aa, 0x38b6, "Legion Slim 7 16APH8", ALC287_FIXUP_CS35L41_I2C_2), SND_PCI_QUIRK(0x17aa, 0x38b7, "Legion Slim 7 16APH8", ALC287_FIXUP_CS35L41_I2C_2), + /* Lenovo V14 G2 ITL has PCI SSID 17aa:380e and codec SSID 17aa:38b7, which + * falls back to the Legion Slim 7 16APH8 entry above; this must come after it + */ + HDA_CODEC_QUIRK(0x17aa, 0x38b7, "Lenovo V14 G2 ITL", ALC269_FIXUP_LENOVO_XPAD_ACPI), SND_PCI_QUIRK(0x17aa, 0x38b8, "Yoga S780-14.5 proX AMD YC Dual", ALC287_FIXUP_TAS2781_I2C), SND_PCI_QUIRK(0x17aa, 0x38b9, "Yoga S780-14.5 proX AMD LX Dual", ALC287_FIXUP_TAS2781_I2C), SND_PCI_QUIRK(0x17aa, 0x38ba, "Yoga S780-14.5 Air AMD quad YC", ALC287_FIXUP_TAS2781_I2C), diff --git a/sound/hda/codecs/realtek/alc662.c b/sound/hda/codecs/realtek/alc662.c index a0efd4596c8807..6a65ec772e9b75 100644 --- a/sound/hda/codecs/realtek/alc662.c +++ b/sound/hda/codecs/realtek/alc662.c @@ -629,7 +629,6 @@ static const struct hda_fixup alc662_fixups[] = { [ALC668_FIXUP_ASUS_Nx51_HEADSET_MODE] = { .type = HDA_FIXUP_FUNC, .v.func = alc_fixup_headset_mode_alc668, - .chain_id = ALC662_FIXUP_BASS_CHMAP }, [ALC668_FIXUP_ASUS_Nx51] = { .type = HDA_FIXUP_PINS, diff --git a/sound/hda/codecs/realtek/alc882.c b/sound/hda/codecs/realtek/alc882.c index 800c3d6f5134bf..cf8d3c48eb8aad 100644 --- a/sound/hda/codecs/realtek/alc882.c +++ b/sound/hda/codecs/realtek/alc882.c @@ -50,6 +50,7 @@ enum { ALC889_FIXUP_MP41_VREF, ALC882_FIXUP_INV_DMIC, ALC882_FIXUP_NO_PRIMARY_HP, + ALC898_FIXUP_DELL_XPS8940_MIC, ALC887_FIXUP_ASUS_BASS, ALC887_FIXUP_BASS_CHMAP, ALC1220_FIXUP_GB_DUAL_CODECS, @@ -507,6 +508,13 @@ static const struct hda_fixup alc882_fixups[] = { .type = HDA_FIXUP_FUNC, .v.func = alc882_fixup_no_primary_hp, }, + [ALC898_FIXUP_DELL_XPS8940_MIC] = { + .type = HDA_FIXUP_PINS, + .v.pins = (const struct hda_pintbl[]) { + { 0x19, 0x02a19130 }, /* headset mic, no separate jack detect */ + {} + }, + }, [ALC887_FIXUP_ASUS_BASS] = { .type = HDA_FIXUP_PINS, .v.pins = (const struct hda_pintbl[]) { @@ -610,6 +618,8 @@ static const struct hda_quirk alc882_fixup_tbl[] = { SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE), SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G), SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), + SND_PCI_QUIRK(0x1028, 0x09c5, "Dell XPS 8940", + ALC898_FIXUP_DELL_XPS8940_MIC), SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), diff --git a/sound/hda/codecs/side-codecs/aw88399_hda.c b/sound/hda/codecs/side-codecs/aw88399_hda.c index 3ff9db9c43d146..81ee8a3987fd6b 100644 --- a/sound/hda/codecs/side-codecs/aw88399_hda.c +++ b/sound/hda/codecs/side-codecs/aw88399_hda.c @@ -112,7 +112,7 @@ static int aw88399_hda_init(struct aw88399_hda *aw88399) struct aw88399 *core; int ret; - core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); + core = devm_kzalloc_obj(dev, *core); if (!core) return -ENOMEM; @@ -228,7 +228,7 @@ int aw88399_hda_probe(struct device *dev, struct regmap *regmap) struct aw88399_hda *aw88399; int ret; - aw88399 = devm_kzalloc(dev, sizeof(*aw88399), GFP_KERNEL); + aw88399 = devm_kzalloc_obj(dev, *aw88399); if (!aw88399) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/cirrus_scodec_test.c b/sound/hda/codecs/side-codecs/cirrus_scodec_test.c index 50527c5fa37415..078c876e93e280 100644 --- a/sound/hda/codecs/side-codecs/cirrus_scodec_test.c +++ b/sound/hda/codecs/side-codecs/cirrus_scodec_test.c @@ -101,7 +101,7 @@ static int cirrus_scodec_test_gpio_probe(struct faux_device *fdev) struct cirrus_scodec_test_gpio *gpio_priv; int ret; - gpio_priv = devm_kzalloc(&fdev->dev, sizeof(*gpio_priv), GFP_KERNEL); + gpio_priv = devm_kzalloc_obj(&fdev->dev, *gpio_priv); if (!gpio_priv) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c index 23582f23a88008..919630c1101887 100644 --- a/sound/hda/codecs/side-codecs/cs35l41_hda.c +++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c @@ -1944,7 +1944,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i if (IS_ERR(regmap)) return PTR_ERR(regmap); - cs35l41 = devm_kzalloc(dev, sizeof(*cs35l41), GFP_KERNEL); + cs35l41 = devm_kzalloc_obj(dev, *cs35l41); if (!cs35l41) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda_property.c b/sound/hda/codecs/side-codecs/cs35l41_hda_property.c index 95843205828543..a2e6b302482075 100644 --- a/sound/hda/codecs/side-codecs/cs35l41_hda_property.c +++ b/sound/hda/codecs/side-codecs/cs35l41_hda_property.c @@ -85,9 +85,17 @@ static const struct cs35l41_config cs35l41_config_table[] = { { "103C8C51", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, { "103C8CDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, { "103C8CDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 }, - { "103C8E13", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, - { "103C8E60", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, - { "103C8F07", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 }, + { "103C8E11", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E12", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E13", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E3A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E3B", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E60", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E61", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E62", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8E75", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, + { "103C8F07", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 }, + { "103C8F57", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, { "104312AF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 }, { "10431433", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, { "10431463", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, @@ -189,16 +197,17 @@ static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev /* must include termination entry */ num_entries++; - gpio_mapping = devm_kcalloc(physdev, num_entries, sizeof(struct acpi_gpio_mapping), - GFP_KERNEL); + gpio_mapping = devm_kzalloc_objs(physdev, struct acpi_gpio_mapping, + num_entries); if (!gpio_mapping) goto err; if (reset_gpio >= 0) { gpio_mapping[reset_index].name = "reset-gpios"; - reset_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params), - GFP_KERNEL); + reset_gpio_params = devm_kzalloc_objs(physdev, + struct acpi_gpio_params, + num_amps); if (!reset_gpio_params) goto err; @@ -211,8 +220,9 @@ static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev if (spkid_gpio >= 0) { gpio_mapping[spkid_index].name = "spk-id-gpios"; - spkid_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params), - GFP_KERNEL); + spkid_gpio_params = devm_kzalloc_objs(physdev, + struct acpi_gpio_params, + num_amps); if (!spkid_gpio_params) goto err; @@ -226,7 +236,8 @@ static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev if ((cs_gpio_index >= 0) && (num_amps == 2)) { gpio_mapping[csgpio_index].name = "cs-gpios"; /* only one GPIO CS is supported without using _DSD, obtained using index 0 */ - cs_gpio_params = devm_kzalloc(physdev, sizeof(struct acpi_gpio_params), GFP_KERNEL); + cs_gpio_params = devm_kzalloc_obj(physdev, + struct acpi_gpio_params); if (!cs_gpio_params) goto err; @@ -544,9 +555,17 @@ static const struct cs35l41_prop_model cs35l41_prop_model_table[] = { { "CSC3551", "103C8C6A", hp_i2c_int_2amp_dual_spkid }, { "CSC3551", "103C8CDD", generic_dsd_config }, { "CSC3551", "103C8CDE", generic_dsd_config }, + { "CSC3551", "103C8E11", generic_dsd_config }, + { "CSC3551", "103C8E12", generic_dsd_config }, { "CSC3551", "103C8E13", generic_dsd_config }, + { "CSC3551", "103C8E3A", generic_dsd_config }, + { "CSC3551", "103C8E3B", generic_dsd_config }, { "CSC3551", "103C8E60", generic_dsd_config }, + { "CSC3551", "103C8E61", generic_dsd_config }, + { "CSC3551", "103C8E62", generic_dsd_config }, + { "CSC3551", "103C8E75", generic_dsd_config }, { "CSC3551", "103C8F07", generic_dsd_config }, + { "CSC3551", "103C8F57", generic_dsd_config }, { "CSC3551", "104312AF", generic_dsd_config }, { "CSC3551", "10431433", generic_dsd_config }, { "CSC3551", "10431463", generic_dsd_config }, diff --git a/sound/hda/codecs/side-codecs/cs35l56_hda_i2c.c b/sound/hda/codecs/side-codecs/cs35l56_hda_i2c.c index e2f51612a73d27..20ecc7a689462b 100644 --- a/sound/hda/codecs/side-codecs/cs35l56_hda_i2c.c +++ b/sound/hda/codecs/side-codecs/cs35l56_hda_i2c.c @@ -17,7 +17,7 @@ static int cs35l56_hda_i2c_probe(struct i2c_client *clt) struct cs35l56_hda *cs35l56; int ret; - cs35l56 = devm_kzalloc(&clt->dev, sizeof(*cs35l56), GFP_KERNEL); + cs35l56 = devm_kzalloc_obj(&clt->dev, *cs35l56); if (!cs35l56) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/cs35l56_hda_spi.c b/sound/hda/codecs/side-codecs/cs35l56_hda_spi.c index f802c83c57b4ef..6195ad1fd64e46 100644 --- a/sound/hda/codecs/side-codecs/cs35l56_hda_spi.c +++ b/sound/hda/codecs/side-codecs/cs35l56_hda_spi.c @@ -17,7 +17,7 @@ static int cs35l56_hda_spi_probe(struct spi_device *spi) struct cs35l56_hda *cs35l56; int ret; - cs35l56 = devm_kzalloc(&spi->dev, sizeof(*cs35l56), GFP_KERNEL); + cs35l56 = devm_kzalloc_obj(&spi->dev, *cs35l56); if (!cs35l56) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/hda_component.c b/sound/hda/codecs/side-codecs/hda_component.c index 8a2a200600a727..7ea4c98a1f31c4 100644 --- a/sound/hda/codecs/side-codecs/hda_component.c +++ b/sound/hda/codecs/side-codecs/hda_component.c @@ -165,7 +165,7 @@ int hda_component_manager_init(struct hda_codec *cdc, mutex_init(&parent->mutex); for (i = 0; i < count; i++) { - sm = devm_kmalloc(dev, sizeof(*sm), GFP_KERNEL); + sm = devm_kmalloc_obj(dev, *sm); if (!sm) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c b/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c index 0c8faa583baac6..52b2a9540c372f 100644 --- a/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +++ b/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c @@ -609,11 +609,11 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt) const char *device_name; int ret; - tas_hda = devm_kzalloc(&clt->dev, sizeof(*tas_hda), GFP_KERNEL); + tas_hda = devm_kzalloc_obj(&clt->dev, *tas_hda); if (!tas_hda) return -ENOMEM; - hda_priv = devm_kzalloc(&clt->dev, sizeof(*hda_priv), GFP_KERNEL); + hda_priv = devm_kzalloc_obj(&clt->dev, *hda_priv); if (!hda_priv) return -ENOMEM; diff --git a/sound/hda/codecs/side-codecs/tas2781_hda_spi.c b/sound/hda/codecs/side-codecs/tas2781_hda_spi.c index f3ba7132d2b874..0951a950d585b7 100644 --- a/sound/hda/codecs/side-codecs/tas2781_hda_spi.c +++ b/sound/hda/codecs/side-codecs/tas2781_hda_spi.c @@ -772,18 +772,18 @@ static int tas2781_hda_spi_probe(struct spi_device *spi) const char *device_name; int ret = 0; - tas_hda = devm_kzalloc(&spi->dev, sizeof(*tas_hda), GFP_KERNEL); + tas_hda = devm_kzalloc_obj(&spi->dev, *tas_hda); if (!tas_hda) return -ENOMEM; - hda_priv = devm_kzalloc(&spi->dev, sizeof(*hda_priv), GFP_KERNEL); + hda_priv = devm_kzalloc_obj(&spi->dev, *hda_priv); if (!hda_priv) return -ENOMEM; tas_hda->hda_priv = hda_priv; spi->max_speed_hz = TAS2781_SPI_MAX_FREQ; - tas_priv = devm_kzalloc(&spi->dev, sizeof(*tas_priv), GFP_KERNEL); + tas_priv = devm_kzalloc_obj(&spi->dev, *tas_priv); if (!tas_priv) return -ENOMEM; tas_priv->dev = &spi->dev; diff --git a/sound/hda/common/sysfs.c b/sound/hda/common/sysfs.c index ac08ee6f9c10e0..ca255f23381abd 100644 --- a/sound/hda/common/sysfs.c +++ b/sound/hda/common/sysfs.c @@ -512,11 +512,12 @@ static inline int strmatch(const char *a, const char *b) static void parse_codec_mode(char *buf, struct hda_bus *bus, struct hda_codec **codecp) { - int vendorid, subid, caddr; + long long vendorid, subid; + int caddr; struct hda_codec *codec; *codecp = NULL; - if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { + if (sscanf(buf, "%lli %lli %i", &vendorid, &subid, &caddr) == 3) { list_for_each_codec(codec, bus) { if ((vendorid <= 0 || codec->core.vendor_id == vendorid) && (subid <= 0 || codec->core.subsystem_id == subid) && diff --git a/sound/hda/controllers/acpi.c b/sound/hda/controllers/acpi.c index 87e5f3f14a2b92..bad32a5c1ae924 100644 --- a/sound/hda/controllers/acpi.c +++ b/sound/hda/controllers/acpi.c @@ -210,7 +210,7 @@ static int hda_acpi_probe(struct platform_device *pdev) struct hda_acpi *hda; int err; - hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL); + hda = devm_kzalloc_obj(&pdev->dev, *hda); if (!hda) return -ENOMEM; @@ -219,8 +219,7 @@ static int hda_acpi_probe(struct platform_device *pdev) /* Fall back to defaults if the table didn't have a *struct hda_data */ if (!hda->data) - hda->data = devm_kzalloc(&pdev->dev, sizeof(*hda->data), - GFP_KERNEL); + hda->data = devm_kzalloc_obj(&pdev->dev, *hda->data); if (!hda->data) return -ENOMEM; diff --git a/sound/hda/controllers/cix-ipbloq.c b/sound/hda/controllers/cix-ipbloq.c index c193dc1428c24d..c07098fc13403c 100644 --- a/sound/hda/controllers/cix-ipbloq.c +++ b/sound/hda/controllers/cix-ipbloq.c @@ -239,7 +239,7 @@ static int cix_ipbloq_hda_probe(struct platform_device *pdev) struct azx *chip; int err; - hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL); + hda = devm_kzalloc_obj(&pdev->dev, *hda); if (!hda) return -ENOMEM; hda->dev = &pdev->dev; diff --git a/sound/hda/controllers/intel.c b/sound/hda/controllers/intel.c index 0a62723b345496..5a7dd69955d4f0 100644 --- a/sound/hda/controllers/intel.c +++ b/sound/hda/controllers/intel.c @@ -1801,7 +1801,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, if (err < 0) return err; - hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL); + hda = devm_kzalloc_obj(&pci->dev, *hda); if (!hda) return -ENOMEM; diff --git a/sound/hda/controllers/tegra.c b/sound/hda/controllers/tegra.c index d601aa3db8b414..a765307c08f958 100644 --- a/sound/hda/controllers/tegra.c +++ b/sound/hda/controllers/tegra.c @@ -518,7 +518,7 @@ static int hda_tegra_probe(struct platform_device *pdev) struct hda_tegra *hda; int err; - hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL); + hda = devm_kzalloc_obj(&pdev->dev, *hda); if (!hda) return -ENOMEM; hda->dev = &pdev->dev; diff --git a/sound/isa/sb/emu8000.c b/sound/isa/sb/emu8000.c index 12c296ee34ecf7..72d77d0d170140 100644 --- a/sound/isa/sb/emu8000.c +++ b/sound/isa/sb/emu8000.c @@ -1046,7 +1046,7 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, if (seq_ports <= 0) return 0; - hw = devm_kzalloc(card->dev, sizeof(*hw), GFP_KERNEL); + hw = devm_kzalloc_obj(card->dev, *hw); if (hw == NULL) return -ENOMEM; spin_lock_init(&hw->reg_lock); diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c index f2848559e6da23..dd2d10a77f9816 100644 --- a/sound/isa/sb/sb_common.c +++ b/sound/isa/sb/sb_common.c @@ -179,7 +179,7 @@ int snd_sbdsp_create(struct snd_card *card, if (snd_BUG_ON(!r_chip)) return -EINVAL; *r_chip = NULL; - chip = devm_kzalloc(card->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(card->dev, *chip); if (!chip) return -ENOMEM; spin_lock_init(&chip->reg_lock); diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c index 6cf88625bbc341..5fa9c43d3d67e7 100644 --- a/sound/isa/wss/wss_lib.c +++ b/sound/isa/wss/wss_lib.c @@ -1663,7 +1663,7 @@ static int snd_wss_new(struct snd_card *card, struct snd_wss *chip; *rchip = NULL; - chip = devm_kzalloc(card->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(card->dev, *chip); if (chip == NULL) return -ENOMEM; chip->hardware = hardware; diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig index 6366f72b366793..9c192d51ff4456 100644 --- a/sound/pci/Kconfig +++ b/sound/pci/Kconfig @@ -141,6 +141,7 @@ config SND_AU8830 config SND_AW2 tristate "Emagic Audiowerk 2" + select SND_PCM help Say Y here to include support for Emagic Audiowerk 2 soundcards. diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c index 797a5f09cade15..8f7e1716f2eaf5 100644 --- a/sound/pci/cs46xx/cs46xx_lib.c +++ b/sound/pci/cs46xx/cs46xx_lib.c @@ -3901,10 +3901,8 @@ int snd_cs46xx_create(struct snd_card *card, snd_cs46xx_proc_init(card, chip); #ifdef CONFIG_PM_SLEEP - chip->saved_regs = devm_kmalloc_array(&pci->dev, - ARRAY_SIZE(saved_regs), - sizeof(*chip->saved_regs), - GFP_KERNEL); + chip->saved_regs = devm_kmalloc_objs(&pci->dev, *chip->saved_regs, + ARRAY_SIZE(saved_regs)); if (!chip->saved_regs) return -ENOMEM; #endif diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c index d49866d9961e60..ddac6cecc8eb2c 100644 --- a/sound/pci/emu10k1/emufx.c +++ b/sound/pci/emu10k1/emufx.c @@ -2474,7 +2474,7 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un emu->support_tlv = 1; return put_user(SNDRV_EMU10K1_VERSION, (int __user *)argp); case SNDRV_EMU10K1_IOCTL_INFO: - info = kzalloc_obj(*info, GFP_KERNEL); + info = kzalloc_obj(*info); if (!info) return -ENOMEM; snd_emu10k1_fx8010_info(emu, info); diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 2114f9f16a3460..bdb825f539bd04 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c @@ -2545,8 +2545,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, chip->is_omnibook = 1; chip->num_substreams = NR_DSPS; - chip->substreams = devm_kcalloc(&pci->dev, chip->num_substreams, - sizeof(struct m3_dma), GFP_KERNEL); + chip->substreams = devm_kzalloc_objs(&pci->dev, struct m3_dma, + chip->num_substreams); if (!chip->substreams) return -ENOMEM; diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 135761278556c7..125afafeccc9af 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6530,7 +6530,7 @@ static int snd_hdspm_create(struct snd_card *card, dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n", sizeof(*hdspm->mixer)); - hdspm->mixer = devm_kzalloc(&pci->dev, sizeof(*hdspm->mixer), GFP_KERNEL); + hdspm->mixer = devm_kzalloc_obj(&pci->dev, *hdspm->mixer); if (!hdspm->mixer) return -ENOMEM; diff --git a/sound/soc/adi/axi-i2s.c b/sound/soc/adi/axi-i2s.c index 41f89384f8fd74..2c4035ff6c2d2d 100644 --- a/sound/soc/adi/axi-i2s.c +++ b/sound/soc/adi/axi-i2s.c @@ -191,7 +191,7 @@ static int axi_i2s_probe(struct platform_device *pdev) void __iomem *base; int ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/adi/axi-spdif.c b/sound/soc/adi/axi-spdif.c index 5581134201a36a..faa1fc7cb973ff 100644 --- a/sound/soc/adi/axi-spdif.c +++ b/sound/soc/adi/axi-spdif.c @@ -184,7 +184,7 @@ static int axi_spdif_probe(struct platform_device *pdev) void __iomem *base; int ret; - spdif = devm_kzalloc(&pdev->dev, sizeof(*spdif), GFP_KERNEL); + spdif = devm_kzalloc_obj(&pdev->dev, *spdif); if (!spdif) return -ENOMEM; diff --git a/sound/soc/amd/acp-config.c b/sound/soc/amd/acp-config.c index 3d4c8526cfe299..8bd194daedbf1c 100644 --- a/sound/soc/amd/acp-config.c +++ b/sound/soc/amd/acp-config.c @@ -65,6 +65,13 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "83HN"), }, }, + { + /* Lenovo Legion 5 15AGP11 (ACP 7.0) */ + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_NAME, "83Q6"), + }, + }, { .matches = { DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC"), @@ -140,6 +147,34 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Dell 14S DS14265"), }, }, + { + /* ASUS ROG Xbox Ally X20 (Strix Point, ACP 7.0) */ + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_BOARD_NAME, "RC74XA"), + }, + }, + { + /* LG gram 15 15Z95U (ACP 7.2) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"), + DMI_MATCH(DMI_PRODUCT_NAME, "15Z95U"), + }, + }, + { + /* LG gram 16 16Z95U (ACP 7.2) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"), + DMI_MATCH(DMI_PRODUCT_NAME, "16Z95U"), + }, + }, + { + /* LG gram 16 16U55U (ACP 7.2) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"), + DMI_MATCH(DMI_PRODUCT_NAME, "16U55U"), + }, + }, {} }; @@ -237,6 +272,20 @@ static const struct config_entry config_table[] = { {} }, }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "NBM-WXX9"), + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), + }, + }, + {} + }, + }, { .flags = FLAG_AMD_LEGACY, .device = ACP_PCI_DEV_ID, diff --git a/sound/soc/amd/acp-da7219-max98357a.c b/sound/soc/amd/acp-da7219-max98357a.c index 1ac729a58bb45c..cf39f6151394ee 100644 --- a/sound/soc/amd/acp-da7219-max98357a.c +++ b/sound/soc/amd/acp-da7219-max98357a.c @@ -787,8 +787,7 @@ static int cz_probe(struct platform_device *pdev) } } - machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), - GFP_KERNEL); + machine = devm_kzalloc_obj(&pdev->dev, struct acp_platform_info); if (!machine) return -ENOMEM; card->dev = &pdev->dev; diff --git a/sound/soc/amd/acp-es8336.c b/sound/soc/amd/acp-es8336.c index 0cb0ee76191d03..f56fd3ae3482af 100644 --- a/sound/soc/amd/acp-es8336.c +++ b/sound/soc/amd/acp-es8336.c @@ -269,7 +269,7 @@ static int st_es8336_probe(struct platform_device *pdev) struct snd_soc_card *card; struct acp_platform_info *machine; - machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), GFP_KERNEL); + machine = devm_kzalloc_obj(&pdev->dev, struct acp_platform_info); if (!machine) return -ENOMEM; diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c index ee75737202dc61..4d1ffee33b0e06 100644 --- a/sound/soc/amd/acp-pcm-dma.c +++ b/sound/soc/amd/acp-pcm-dma.c @@ -1264,8 +1264,7 @@ static int acp_audio_probe(struct platform_device *pdev) return -ENODEV; } - audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data), - GFP_KERNEL); + audio_drv_data = devm_kzalloc_obj(&pdev->dev, struct audio_drv_data); if (!audio_drv_data) return -ENOMEM; diff --git a/sound/soc/amd/acp/Kconfig b/sound/soc/amd/acp/Kconfig index a62bf0fb1efccc..1b492a9ab58237 100644 --- a/sound/soc/amd/acp/Kconfig +++ b/sound/soc/amd/acp/Kconfig @@ -15,7 +15,7 @@ config SND_SOC_AMD_ACP_COMMON config SND_SOC_ACPI_AMD_MATCH tristate - select SND_SOC_ACPI if ACPI + select SND_SOC_ACPI config SND_SOC_ACPI_AMD_SDCA_QUIRKS bool "AMD ACPI SDCA quirks" diff --git a/sound/soc/amd/acp/Makefile b/sound/soc/amd/acp/Makefile index 42e2bd34da0608..91bbbeef5b8ad1 100644 --- a/sound/soc/amd/acp/Makefile +++ b/sound/soc/amd/acp/Makefile @@ -23,7 +23,8 @@ snd-acp70-y := acp70.o snd-acp-mach-y := acp-mach-common.o snd-acp-legacy-mach-y := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o snd-acp-sof-mach-y := acp-sof-mach.o -snd-soc-acpi-amd-match-y := amd-acp63-acpi-match.o amd-acp70-acpi-match.o amd-acp7x-acpi-match.o +snd-soc-acpi-amd-match-y := amd-acp63-acpi-match.o amd-acp70-acpi-match.o amd-acp7x-acpi-match.o \ + amd-sof-function-topology-lib.o snd-soc-acpi-amd-match-$(CONFIG_SND_SOC_ACPI_AMD_SDCA_QUIRKS) += soc-acpi-amd-sdca-quirks.o snd-acp-sdw-mach-y := acp-sdw-mach-common.o snd-acp-sdw-sof-mach-y += acp-sdw-sof-mach.o diff --git a/sound/soc/amd/acp/acp-legacy-common.c b/sound/soc/amd/acp/acp-legacy-common.c index 4e477c48d4bdd1..9c0528a7dfc0f3 100644 --- a/sound/soc/amd/acp/acp-legacy-common.c +++ b/sound/soc/amd/acp/acp-legacy-common.c @@ -154,7 +154,10 @@ static void set_acp_pdm_ring_buffer(struct snd_pcm_substream *substream, period_bytes = frames_to_bytes(runtime, runtime->period_size); pdm_size = frames_to_bytes(runtime, runtime->buffer_size); - physical_addr = stream->reg_offset + MEM_WINDOW_START; + if (chip->acp_rev >= ACP70_PCI_ID) + physical_addr = ACP7x_DMIC_MEM_WINDOW_START; + else + physical_addr = stream->reg_offset + MEM_WINDOW_START; /* Init ACP PDM Ring buffer */ writel(physical_addr, chip->base + ACP_WOV_RX_RINGBUFADDR); diff --git a/sound/soc/amd/acp/acp-legacy-mach.c b/sound/soc/amd/acp/acp-legacy-mach.c index 235d6cc83fa989..731608c4c0bc2c 100644 --- a/sound/soc/amd/acp/acp-legacy-mach.c +++ b/sound/soc/amd/acp/acp-legacy-mach.c @@ -133,7 +133,7 @@ static int acp_asoc_probe(struct platform_device *pdev) goto out; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) { ret = -ENOMEM; goto out; diff --git a/sound/soc/amd/acp/acp-mach-common.c b/sound/soc/amd/acp/acp-mach-common.c index 01a0aaa6024660..529f792e27c3c8 100644 --- a/sound/soc/amd/acp/acp-mach-common.c +++ b/sound/soc/amd/acp/acp-mach-common.c @@ -1415,7 +1415,7 @@ int acp_sofdsp_dai_links_create(struct snd_soc_card *card) if (drv_data->dmic_cpu_id) num_links++; - links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, num_links); if (!links) return -ENOMEM; @@ -1623,7 +1623,7 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) if (drv_data->dmic_cpu_id) num_links++; - links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, num_links); if (!links) return -ENOMEM; diff --git a/sound/soc/amd/acp/acp-pci.c b/sound/soc/amd/acp/acp-pci.c index 98771323eace28..aca6f44af1d15b 100644 --- a/sound/soc/amd/acp/acp-pci.c +++ b/sound/soc/amd/acp/acp-pci.c @@ -63,7 +63,7 @@ static int create_acp_platform_devs(struct pci_dev *pci, struct acp_chip_info *c parent = &pci->dev; if (chip->is_i2s_config || chip->is_pdm_dev) { - chip->res = devm_kzalloc(&pci->dev, sizeof(struct resource), GFP_KERNEL); + chip->res = devm_kzalloc_obj(&pci->dev, struct resource); if (!chip->res) { ret = -ENOMEM; goto err; @@ -114,7 +114,7 @@ static int acp_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id if (flag != FLAG_AMD_LEGACY && flag != FLAG_AMD_LEGACY_ONLY_DMIC) return -ENODEV; - chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&pci->dev, *chip); if (!chip) return -ENOMEM; diff --git a/sound/soc/amd/acp/acp-sdw-legacy-mach.c b/sound/soc/amd/acp/acp-sdw-legacy-mach.c index bd03789c784954..5dbcefc47dd37f 100644 --- a/sound/soc/amd/acp/acp-sdw-legacy-mach.c +++ b/sound/soc/amd/acp/acp-sdw-legacy-mach.c @@ -249,15 +249,15 @@ static int create_sdw_dailink(struct snd_soc_card *card, if (!name) return -ENOMEM; - cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL); + cpus = devm_kzalloc_objs(dev, *cpus, num_cpus); if (!cpus) return -ENOMEM; - codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); + codecs = devm_kzalloc_objs(dev, *codecs, num_codecs); if (!codecs) return -ENOMEM; - codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL); + codec_maps = devm_kzalloc_objs(dev, *codec_maps, num_codecs); if (!codec_maps) return -ENOMEM; @@ -331,8 +331,8 @@ static int create_sdw_dailinks(struct snd_soc_card *card, int i; int ret; - sdw_platform_component = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + sdw_platform_component = devm_kzalloc_obj(dev, + struct snd_soc_dai_link_component); if (!sdw_platform_component) return -ENOMEM; @@ -376,11 +376,11 @@ static int create_dmic_dailinks(struct snd_soc_card *card, struct snd_soc_dai_link_component *pdm_platform; int ret; - pdm_cpu = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); + pdm_cpu = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!pdm_cpu) return -ENOMEM; - pdm_platform = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); + pdm_platform = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!pdm_platform) return -ENOMEM; @@ -446,7 +446,7 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) if (!soc_ends) return -ENOMEM; - soc_aux = devm_kcalloc(dev, num_aux, sizeof(*soc_aux), GFP_KERNEL); + soc_aux = devm_kzalloc_objs(dev, *soc_aux, num_aux); if (!soc_aux) return -ENOMEM; @@ -486,13 +486,13 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num); - codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL); + codec_conf = devm_kzalloc_objs(dev, *codec_conf, num_confs); if (!codec_conf) return -ENOMEM; /* allocate BE dailinks */ num_links = sdw_be_num + dmic_num; - dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); + dai_links = devm_kzalloc_objs(dev, *dai_links, num_links); if (!dai_links) return -ENOMEM; @@ -537,13 +537,13 @@ static int mc_probe(struct platform_device *pdev) int amp_num = 0, i; int ret; - amd_ctx = devm_kzalloc(&pdev->dev, sizeof(*amd_ctx), GFP_KERNEL); + amd_ctx = devm_kzalloc_obj(&pdev->dev, *amd_ctx); if (!amd_ctx) return -ENOMEM; amd_ctx->acp_rev = mach->mach_params.subsystem_rev; amd_ctx->max_sdw_links = ACP63_SDW_MAX_LINKS; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; ctx->codec_info_list_count = asoc_sdw_get_codec_info_list_count(); diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c index 1d7487c8726575..4fb600a7356b6e 100644 --- a/sound/soc/amd/acp/acp-sdw-sof-mach.c +++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c @@ -47,6 +47,54 @@ static const struct dmi_system_id sof_sdw_quirk_table[] = { }, .driver_data = (void *)RT711_JD2, }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0EF1"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0EF2"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0EF3"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0EF4"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0F12"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0F13"), + }, + .driver_data = (void *)(ASOC_SDW_CODEC_SPKR), + }, {} }; @@ -173,15 +221,15 @@ static int create_sdw_dailink(struct snd_soc_card *card, if (!name) return -ENOMEM; - cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL); + cpus = devm_kzalloc_objs(dev, *cpus, num_cpus); if (!cpus) return -ENOMEM; - codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); + codecs = devm_kzalloc_objs(dev, *codecs, num_codecs); if (!codecs) return -ENOMEM; - codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL); + codec_maps = devm_kzalloc_objs(dev, *codec_maps, num_codecs); if (!codec_maps) return -ENOMEM; @@ -340,7 +388,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) if (!sof_ends) return -ENOMEM; - sof_aux = devm_kcalloc(dev, num_aux, sizeof(*sof_aux), GFP_KERNEL); + sof_aux = devm_kzalloc_objs(dev, *sof_aux, num_aux); if (!sof_aux) return -ENOMEM; @@ -350,6 +398,9 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) sdw_be_num = ret; + /* the dai_type in the DAI link name selects the function topologies */ + ctx->append_dai_type = true; + /* enable dmic */ if (sof_sdw_quirk & ASOC_SDW_ACP_DMIC || mach_params->dmic_num || amd_ctx->pdm_sel) { @@ -361,13 +412,13 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num); - codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL); + codec_conf = devm_kzalloc_objs(dev, *codec_conf, num_confs); if (!codec_conf) return -ENOMEM; /* allocate BE dailinks */ num_links = sdw_be_num + dmic_num; - dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); + dai_links = devm_kzalloc_objs(dev, *dai_links, num_links); if (!dai_links) return -ENOMEM; @@ -409,7 +460,7 @@ static int mc_probe(struct platform_device *pdev) int amp_num = 0, i, dmic_num; int ret; - amd_ctx = devm_kzalloc(&pdev->dev, sizeof(*amd_ctx), GFP_KERNEL); + amd_ctx = devm_kzalloc_obj(&pdev->dev, *amd_ctx); if (!amd_ctx) return -ENOMEM; @@ -427,7 +478,7 @@ static int mc_probe(struct platform_device *pdev) pdm_pdata = mach->pdata; amd_ctx->pdm_sel = pdm_pdata->pdm_sel; } - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; ctx->codec_info_list_count = asoc_sdw_get_codec_info_list_count(); diff --git a/sound/soc/amd/acp/acp-sof-mach.c b/sound/soc/amd/acp/acp-sof-mach.c index 8874151e159ab2..1e80294ce32311 100644 --- a/sound/soc/amd/acp/acp-sof-mach.c +++ b/sound/soc/amd/acp/acp-sof-mach.c @@ -98,7 +98,7 @@ static int acp_sof_probe(struct platform_device *pdev) if (!pdev->id_entry) return -EINVAL; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c b/sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c index eb0e9a6af6ef10..d0ba8418252b9d 100644 --- a/sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c +++ b/sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "../acp-mach.h" @@ -60,6 +61,8 @@ static const struct snd_pcm_hw_constraint_list constraints_channels = { #define ES83xx_12288_KHZ_MCLK_FREQ (48000 * 256) #define ES83xx_48_MHZ_MCLK_FREQ (48000 * 1000) +#define ES83XX_AMP_ON_DELAY_MS 50 + static int acp3x_es83xx_headphone_power_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w, @@ -114,7 +117,7 @@ static struct snd_soc_jack_pin es83xx_jack_pins[] = { }; static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = { - SND_SOC_DAPM_SPK("Speaker", NULL), + SND_SOC_DAPM_SPK("Speaker", acp3x_es83xx_speaker_power_event), SND_SOC_DAPM_HP("Headphone", NULL), SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_MIC("Internal Mic", NULL), @@ -122,9 +125,6 @@ static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = { SND_SOC_DAPM_SUPPLY("Headphone Power", SND_SOC_NOPM, 0, 0, acp3x_es83xx_headphone_power_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), - SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0, - acp3x_es83xx_speaker_power_event, - SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), }; static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = { @@ -138,7 +138,6 @@ static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = { */ {"Speaker", NULL, "HPOL"}, {"Speaker", NULL, "HPOR"}, - {"Speaker", NULL, "Speaker Power"}, }; @@ -186,10 +185,13 @@ static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w, struct acp3x_es83xx_private *priv = get_mach_priv(card); dev_dbg(priv->codec_dev, "speaker power event: %d\n", event); - if (SND_SOC_DAPM_EVENT_ON(event)) + if (SND_SOC_DAPM_EVENT_ON(event)) { + /* Let the codec output settle before enabling the amplifier */ + msleep(ES83XX_AMP_ON_DELAY_MS); priv->speaker_on = true; - else + } else { priv->speaker_on = false; + } gpiod_set_value_cansleep(priv->gpio_speakers, priv->speaker_on); gpiod_set_value_cansleep(priv->gpio_headphone, priv->headphone_on); @@ -364,6 +366,14 @@ static const struct dmi_system_id acp3x_es83xx_dmi_table[] = { }, .driver_data = (void *)(ES83XX_ENABLE_DMIC|ES83XX_48_MHZ_MCLK), }, + { + .matches = { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "NBM-WXX9"), + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), + }, + .driver_data = (void *)(ES83XX_ENABLE_DMIC|ES83XX_48_MHZ_MCLK), + }, { .matches = { DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), @@ -441,7 +451,7 @@ static int acp3x_es83xx_probe(struct snd_soc_card *card) return -EPROBE_DEFER; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) { put_device(codec_dev); return -ENOMEM; diff --git a/sound/soc/amd/acp/amd-acp70-acpi-match.c b/sound/soc/amd/acp/amd-acp70-acpi-match.c index c2f0479301ebd5..b1278dad8e20f5 100644 --- a/sound/soc/amd/acp/amd-acp70-acpi-match.c +++ b/sound/soc/amd/acp/amd-acp70-acpi-match.c @@ -583,6 +583,78 @@ static const struct snd_soc_acpi_link_adr acp70_rt722_l0_rt1320_l1[] = { {} }; +static const struct snd_soc_acpi_endpoint rt713_jack_dmic_endpoints[] = { + /* Jack Endpoint (AIF1) */ + { + .num = 0, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, + /* DMIC Endpoint (AIF3, SmartMic function) */ + { + .num = 1, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, +}; + +static const struct snd_soc_acpi_adr_device rt713_vb_0_single_adr[] = { + { + .adr = 0x000030025D071301ull, + .num_endpoints = ARRAY_SIZE(rt713_jack_dmic_endpoints), + .endpoints = rt713_jack_dmic_endpoints, + .name_prefix = "rt713" + } +}; + +static const struct snd_soc_acpi_adr_device rt713_0_single_adr[] = { + { + .adr = 0x000030025D071301ull, + .num_endpoints = 1, + .endpoints = &single_endpoint, + .name_prefix = "rt713" + } +}; + +static const struct snd_soc_acpi_adr_device rt1320_1_u1_single_adr[] = { + { + .adr = 0x000131025D132001ull, + .num_endpoints = 1, + .endpoints = &single_endpoint, + .name_prefix = "rt1320-1" + } +}; + +static const struct snd_soc_acpi_link_adr acp70_rt713_vb_l0_rt1320_l1u1[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(rt713_vb_0_single_adr), + .adr_d = rt713_vb_0_single_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(rt1320_1_u1_single_adr), + .adr_d = rt1320_1_u1_single_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp70_rt713_l0_rt1320_l1u1[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(rt713_0_single_adr), + .adr_d = rt713_0_single_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(rt1320_1_u1_single_adr), + .adr_d = rt1320_1_u1_single_adr, + }, + {} +}; + static const struct snd_soc_acpi_adr_device tas2783_2_adr[] = { { /* left */ @@ -739,6 +811,45 @@ static const struct snd_soc_acpi_link_adr acp70_tas2783x2_l0u9c_rt712_vb_l1u0[] {} }; +static const struct snd_soc_acpi_adr_device tas2783x2_l0u8b_adr[] = { + { + .adr = 0x0000380102000001ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "tas2783-1", + }, + { + .adr = 0x00003B0102000001ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "tas2783-2", + }, +}; + +static const struct snd_soc_acpi_adr_device rt721_l1u0_jack_dmic_adr[] = { + { + .adr = 0x000130025D072101ull, + .num_endpoints = ARRAY_SIZE(jack_dmic_endpoints), + .endpoints = jack_dmic_endpoints, + .name_prefix = "rt721", + } +}; + +/* ASUS ROG Xbox Ally X20 (RC74XA) */ +static const struct snd_soc_acpi_link_adr acp70_tas2783x2_l0u8b_rt721_l1u0[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(tas2783x2_l0u8b_adr), + .adr_d = tas2783x2_l0u8b_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(rt721_l1u0_jack_dmic_adr), + .adr_d = rt721_l1u0_jack_dmic_adr, + }, + {} +}; + static const struct snd_soc_acpi_endpoint rt721_endpoints[] = { { /* Jack Playback/Capture Endpoint (AIF1) */ .num = 0, @@ -820,6 +931,17 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp70_sdw_machines[] = { .links = acp70_rt722_l0_rt1320_l1, .drv_name = "amd_sdw", }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp70_rt713_vb_l0_rt1320_l1u1, + .machine_check = snd_soc_acpi_amd_sdca_is_device_rt712_vb, + .drv_name = "amd_sdw", + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp70_rt713_l0_rt1320_l1u1, + .drv_name = "amd_sdw", + }, { .link_mask = BIT(0) | BIT(1), .links = acp70_4_in_1_sdca, @@ -906,6 +1028,11 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp70_sdw_machines[] = { .links = acp70_rt721_l1u0_tas2783x2_l1u8b, .drv_name = "amd_sdw", }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp70_tas2783x2_l0u8b_rt721_l1u0, + .drv_name = "amd_sdw", + }, { .link_mask = BIT(1), .links = acp70_rt721_only, diff --git a/sound/soc/amd/acp/amd-acp7x-acpi-match.c b/sound/soc/amd/acp/amd-acp7x-acpi-match.c index bf11ceb7478b52..b71060c9ecb016 100644 --- a/sound/soc/amd/acp/amd-acp7x-acpi-match.c +++ b/sound/soc/amd/acp/amd-acp7x-acpi-match.c @@ -8,6 +8,7 @@ #include #include "../mach-config.h" +#include "amd-sof-function-topology-lib.h" static const struct snd_soc_acpi_endpoint single_endpoint = { .num = 0, @@ -16,6 +17,34 @@ static const struct snd_soc_acpi_endpoint single_endpoint = { .group_id = 0 }; +static const struct snd_soc_acpi_endpoint spk_l_endpoint = { + .num = 0, + .aggregated = 1, + .group_position = 0, + .group_id = 1 +}; + +static const struct snd_soc_acpi_endpoint spk_r_endpoint = { + .num = 0, + .aggregated = 1, + .group_position = 1, + .group_id = 1 +}; + +static const struct snd_soc_acpi_endpoint spk_2_endpoint = { + .num = 0, + .aggregated = 1, + .group_position = 2, + .group_id = 1 +}; + +static const struct snd_soc_acpi_endpoint spk_3_endpoint = { + .num = 0, + .aggregated = 1, + .group_position = 3, + .group_id = 1 +}; + static const struct snd_soc_acpi_endpoint jack_dmic_endpoints[] = { /* Jack Endpoint */ { @@ -148,6 +177,336 @@ static const struct snd_soc_acpi_link_adr acp7x_rt721_l0_rt1320_l3[] = { {} }; +static const struct snd_soc_acpi_endpoint cs42l43_endpoints[] = { + { /* Jack Playback Endpoint */ + .num = 0, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, + { /* DMIC Capture Endpoint */ + .num = 1, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, + { /* Jack Capture Endpoint */ + .num = 2, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, + { /* Speaker Playback Endpoint */ + .num = 3, + .aggregated = 0, + .group_position = 0, + .group_id = 0, + }, +}; + +static const struct snd_soc_acpi_adr_device cs35l56x4_l1u3210_adr[] = { + { + .adr = 0x00013301FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00013201FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, + { + .adr = 0x00013101FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_2_endpoint, + .name_prefix = "AMP3" + }, + { + .adr = 0x00013001FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_3_endpoint, + .name_prefix = "AMP4" + }, +}; + +static const struct snd_soc_acpi_adr_device cs35l63x2_l0u01_adr[] = { + { + .adr = 0x00003001FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00003101FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, +}; + +static const struct snd_soc_acpi_adr_device cs35l63x2_l1u01_adr[] = { + { + .adr = 0x00013001FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00013101FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, +}; + +static const struct snd_soc_acpi_adr_device cs35l63x2_l1u13_adr[] = { + { + .adr = 0x00013101FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00013301FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, +}; + +static const struct snd_soc_acpi_adr_device cs35l63x4_l0u0246_adr[] = { + { + .adr = 0x00003001FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00003201FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, + { + .adr = 0x00003401FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_2_endpoint, + .name_prefix = "AMP3" + }, + { + .adr = 0x00003601FA356301ull, + .num_endpoints = 1, + .endpoints = &spk_3_endpoint, + .name_prefix = "AMP4" + }, +}; + +static const struct snd_soc_acpi_adr_device cs42l43_l0u0_adr[] = { + { + .adr = 0x00003001FA424301ull, + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints), + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l43" + } +}; + +static const struct snd_soc_acpi_adr_device cs42l43_l0u1_adr[] = { + { + .adr = 0x00003101FA424301ull, + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints), + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l43" + } +}; + +static const struct snd_soc_acpi_adr_device cs42l43b_l0u1_adr[] = { + { + .adr = 0x00003101FA2A3B01ull, + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints), + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l43" + } +}; + +static const struct snd_soc_acpi_adr_device cs42l43_l1u0_cs35l56x4_l1u0123_adr[] = { + { + .adr = 0x00013001FA424301ull, + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints), + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l43" + }, + { + .adr = 0x00013001FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_l_endpoint, + .name_prefix = "AMP1" + }, + { + .adr = 0x00013101FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_r_endpoint, + .name_prefix = "AMP2" + }, + { + .adr = 0x00013201FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_2_endpoint, + .name_prefix = "AMP3" + }, + { + .adr = 0x00013301FA355601ull, + .num_endpoints = 1, + .endpoints = &spk_3_endpoint, + .name_prefix = "AMP4" + }, +}; + +static const struct snd_soc_acpi_adr_device cs42l45_l0u0_adr[] = { + { + .adr = 0x00003001FA424501ull, + /* Re-use endpoints, but cs42l45 has no speaker */ + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints) - 1, + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l45" + } +}; + +static const struct snd_soc_acpi_adr_device cs42l45_l1u0_adr[] = { + { + .adr = 0x00013001FA424501ull, + /* Re-use endpoints, but cs42l45 has no speaker */ + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints) - 1, + .endpoints = cs42l43_endpoints, + .name_prefix = "cs42l45" + } +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs35l56x4_l1u3210[] = { + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs35l56x4_l1u3210_adr), + .adr_d = cs35l56x4_l1u3210_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l43_l0u1[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l43_l0u1_adr), + .adr_d = cs42l43_l0u1_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l43b_l0u1[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l43b_l0u1_adr), + .adr_d = cs42l43b_l0u1_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l43_l0u0_cs35l56x4_l1u3210[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l43_l0u0_adr), + .adr_d = cs42l43_l0u0_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs35l56x4_l1u3210_adr), + .adr_d = cs35l56x4_l1u3210_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l43_l1u0_cs35l56x4_l1u0123[] = { + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs42l43_l1u0_cs35l56x4_l1u0123_adr), + .adr_d = cs42l43_l1u0_cs35l56x4_l1u0123_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l0u0[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l45_l0u0_adr), + .adr_d = cs42l45_l0u0_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l0u0_cs35l63x2_l1u01[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l45_l0u0_adr), + .adr_d = cs42l45_l0u0_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs35l63x2_l1u01_adr), + .adr_d = cs35l63x2_l1u01_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l0u0_cs35l63x2_l1u13[] = { + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs42l45_l0u0_adr), + .adr_d = cs42l45_l0u0_adr, + }, + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs35l63x2_l1u13_adr), + .adr_d = cs35l63x2_l1u13_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l1u0[] = { + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs42l45_l1u0_adr), + .adr_d = cs42l45_l1u0_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l1u0_cs35l63x2_l0u01[] = { + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs42l45_l1u0_adr), + .adr_d = cs42l45_l1u0_adr, + }, + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs35l63x2_l0u01_adr), + .adr_d = cs35l63x2_l0u01_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr acp7x_cs42l45_l1u0_cs35l63x4_l0u0246[] = { + { + .mask = BIT(1), + .num_adr = ARRAY_SIZE(cs42l45_l1u0_adr), + .adr_d = cs42l45_l1u0_adr, + }, + { + .mask = BIT(0), + .num_adr = ARRAY_SIZE(cs35l63x4_l0u0246_adr), + .adr_d = cs35l63x4_l0u0246_adr, + }, + {} +}; + struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7b_sof_sdw_machines[] = { { .link_mask = BIT(0) | BIT(3), @@ -155,6 +514,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7b_sof_sdw_machines[] = { .drv_name = "amd_sof_sdw", .sof_tplg_filename = "sof-acp7b-rt721-l0-rt1320-l3.tplg", .fw_filename = "sof-acp7b.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, }, {}, }; @@ -167,6 +527,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7f_sof_sdw_machines[] = { .drv_name = "amd_sof_sdw", .sof_tplg_filename = "sof-acp7f-rt721-l0-rt1320-l3.tplg", .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, }, { .link_mask = BIT(0) | BIT(1), @@ -174,6 +535,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7f_sof_sdw_machines[] = { .drv_name = "amd_sof_sdw", .sof_tplg_filename = "sof-acp7f-rt721-l0-rt1320-l1.tplg", .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, }, { .link_mask = BIT(0), @@ -181,6 +543,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7f_sof_sdw_machines[] = { .drv_name = "amd_sof_sdw", .sof_tplg_filename = "sof-acp7f-rt721-l0.tplg", .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, }, { .link_mask = BIT(0), @@ -188,6 +551,95 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp7f_sof_sdw_machines[] = { .drv_name = "amd_sof_sdw", .sof_tplg_filename = "sof-acp7f-rt722-l0.tplg", .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp7x_cs42l43_l0u0_cs35l56x4_l1u3210, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l43-l0u0-cs35l56x4-l1u3210.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp7x_cs42l45_l1u0_cs35l63x4_l0u0246, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l1u0-cs35l63x4-l0u0246.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp7x_cs42l45_l0u0_cs35l63x2_l1u01, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l0u0-cs35l63x2-l1u01.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp7x_cs42l45_l0u0_cs35l63x2_l1u13, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l0u0-cs35l63x2-l1u13.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0) | BIT(1), + .links = acp7x_cs42l45_l1u0_cs35l63x2_l0u01, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l1u0-cs35l63x2-l0u01.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(1), + .links = acp7x_cs42l43_l1u0_cs35l56x4_l1u0123, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l43-l1u0-cs35l56x4-l1u0123.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(1), + .links = acp7x_cs35l56x4_l1u3210, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs35l56x4-l1u3210.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0), + .links = acp7x_cs42l43_l0u1, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l43-l0u1.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0), + .links = acp7x_cs42l43b_l0u1, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l43b-l0u1.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(0), + .links = acp7x_cs42l45_l0u0, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l0u0.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, + }, + { + .link_mask = BIT(1), + .links = acp7x_cs42l45_l1u0, + .drv_name = "amd_sof_sdw", + .sof_tplg_filename = "sof-acp7f-cs42l45-l1u0.tplg", + .fw_filename = "sof-acp7f.ri", + .get_function_tplg_files = amd_sof_sdw_get_tplg_files, }, {}, }; diff --git a/sound/soc/amd/acp/amd-sof-function-topology-lib.c b/sound/soc/amd/acp/amd-sof-function-topology-lib.c new file mode 100644 index 00000000000000..477ecdf769968e --- /dev/null +++ b/sound/soc/amd/acp/amd-sof-function-topology-lib.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright(c) 2026 Advanced Micro Devices, Inc. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "amd-sof-function-topology-lib.h" + +#define SOF_AMD_SDW_MAX_LINKS 4 + +static int get_sdw_link_num(struct device *dev, struct snd_soc_dai_link *dai_link, + unsigned int *link_num) +{ + if (sscanf(dai_link->name, "SDW%u", link_num) != 1 || + *link_num >= SOF_AMD_SDW_MAX_LINKS) { + dev_err(dev, "Can't get SDW link from dai_link->name %s\n", dai_link->name); + return -EINVAL; + } + + return 0; +} + +int amd_sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach, + const char *prefix, const char ***tplg_files, bool best_effort) +{ + struct snd_soc_dai_link *dai_link; + char platform[SND_SOC_ACPI_SOF_PLATFORM_NAME_MAX]; + unsigned long tplg_mask = 0; + int tplg_num = 0; + char *tplg_file; + int tplg_bit; + int tplg_dev; + int ret; + int i; + + /* ACP SoundWire and PDM DAI configuration is platform dependent */ + ret = snd_soc_acpi_sof_get_platform_name(card->dev, mach, platform); + if (ret < 0) + return ret; + + /* + * ACP SoundWire DAI index and stream names in the topologies are + * specific to the SoundWire link, so the link number is part of the + * SoundWire function names. + */ + for_each_card_prelinks(card, i, dai_link) { + unsigned int link_num = 0; + const char *tplg_dev_name; + + dev_dbg(card->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id); + if (strstr(dai_link->name, "SimpleJack")) { + ret = get_sdw_link_num(card->dev, dai_link, &link_num); + if (ret) { + if (best_effort) + continue; + return ret; + } + + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_JACK; + tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL, "jack-l%u", link_num); + if (!tplg_dev_name) + return -ENOMEM; + } else if (strstr(dai_link->name, "SmartAmp")) { + ret = get_sdw_link_num(card->dev, dai_link, &link_num); + if (ret) { + if (best_effort) + continue; + return ret; + } + + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_AMP; + tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL, "%damp-l%u", + dai_link->num_cpus, link_num); + if (!tplg_dev_name) + return -ENOMEM; + } else if (strstr(dai_link->name, "SmartMic")) { + ret = get_sdw_link_num(card->dev, dai_link, &link_num); + if (ret) { + if (best_effort) + continue; + return ret; + } + + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_MIC; + tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL, "mic-l%u", link_num); + if (!tplg_dev_name) + return -ENOMEM; + } else if (strstr(dai_link->name, "dmic")) { + /* ACP PDM DMIC is always stereo */ + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_ACP_DMIC; + tplg_dev_name = "dmic-2ch"; + } else { + /* The dai link is not supported by separated tplg yet */ + dev_dbg(card->dev, + "dai_link %s is not supported by separated tplg yet\n", + dai_link->name); + if (best_effort) + continue; + + return 0; + } + + /* the same function on different links needs its own topology */ + tplg_bit = (tplg_dev - SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_JACK) * + SOF_AMD_SDW_MAX_LINKS + link_num; + if (tplg_mask & BIT(tplg_bit)) + continue; + + tplg_file = snd_soc_acpi_sof_get_tplg_filename(card->dev, prefix, + platform, tplg_dev_name, + dai_link->id, tplg_dev); + if (!tplg_file) + return -ENOMEM; + + /* Check presence of sub-topologies */ + if (!snd_soc_tplg_files_exist(card->dev, tplg_file)) { + devm_kfree(card->dev, tplg_file); + if (best_effort) + continue; + + return 0; + } + + tplg_mask |= BIT(tplg_bit); + + (*tplg_files)[tplg_num] = tplg_file; + tplg_num++; + } + + dev_dbg(card->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num); + + return tplg_num; +} diff --git a/sound/soc/amd/acp/amd-sof-function-topology-lib.h b/sound/soc/amd/acp/amd-sof-function-topology-lib.h new file mode 100644 index 00000000000000..cea49aa9c20028 --- /dev/null +++ b/sound/soc/amd/acp/amd-sof-function-topology-lib.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * amd-sof-function-topology-lib.h - get-tplg-files ops + * + * Copyright(c) 2026 Advanced Micro Devices, Inc. + */ + +#ifndef __AMD_SOF_FUNCTION_TOPOLOGY_LIB_H +#define __AMD_SOF_FUNCTION_TOPOLOGY_LIB_H + +#include + +struct snd_soc_acpi_mach; +struct snd_soc_card; + +int amd_sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach, + const char *prefix, const char ***tplg_files, bool best_effort); + +#endif diff --git a/sound/soc/amd/acp3x-rt5682-max9836.c b/sound/soc/amd/acp3x-rt5682-max9836.c index 4affb00bdc9597..60e29a1cd7e0ce 100644 --- a/sound/soc/amd/acp3x-rt5682-max9836.c +++ b/sound/soc/amd/acp3x-rt5682-max9836.c @@ -509,7 +509,7 @@ static int acp3x_probe(struct platform_device *pdev) if (!card) return -ENODEV; - machine = devm_kzalloc(&pdev->dev, sizeof(*machine), GFP_KERNEL); + machine = devm_kzalloc_obj(&pdev->dev, *machine); if (!machine) return -ENOMEM; diff --git a/sound/soc/amd/acp7x/pci-acp7x.c b/sound/soc/amd/acp7x/pci-acp7x.c index d29a149cf17515..0db749cd9fabc1 100644 --- a/sound/soc/amd/acp7x/pci-acp7x.c +++ b/sound/soc/amd/acp7x/pci-acp7x.c @@ -19,8 +19,7 @@ static int acp_hw_init_ops(struct acp7x_dev_data *adata, struct pci_dev *pci) { - adata->hw_ops = devm_kzalloc(&pci->dev, sizeof(struct acp_hw_ops), - GFP_KERNEL); + adata->hw_ops = devm_kzalloc_obj(&pci->dev, struct acp_hw_ops); if (!adata->hw_ops) return -ENOMEM; @@ -67,8 +66,7 @@ static int snd_acp7x_probe(struct pci_dev *pci, dev_err(&pci->dev, "pci_request_regions failed\n"); goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp7x_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp7x_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; diff --git a/sound/soc/amd/ps/pci-ps.c b/sound/soc/amd/ps/pci-ps.c index b604db4942dd68..cf009e25307e31 100644 --- a/sound/soc/amd/ps/pci-ps.c +++ b/sound/soc/amd/ps/pci-ps.c @@ -26,16 +26,20 @@ static void handle_acp70_sdw_wake_event(struct acp63_dev_data *adata) struct amd_sdw_manager *amd_manager; if (adata->acp70_sdw0_wake_event) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); - if (amd_manager) - pm_request_resume(amd_manager->dev); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); + if (amd_manager) + pm_request_resume(amd_manager->dev); + } adata->acp70_sdw0_wake_event = 0; } if (adata->acp70_sdw1_wake_event) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); - if (amd_manager) - pm_request_resume(amd_manager->dev); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); + if (amd_manager) + pm_request_resume(amd_manager->dev); + } adata->acp70_sdw1_wake_event = 0; } } @@ -209,18 +213,22 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) ext_intr_stat = readl(adata->acp63_base + ACP_EXTERNAL_INTR_STAT); if (ext_intr_stat & ACP_SDW0_STAT) { writel(ACP_SDW0_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT); - amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); - if (amd_manager) - schedule_work(&amd_manager->amd_sdw_irq_thread); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); + if (amd_manager) + schedule_work(&amd_manager->amd_sdw_irq_thread); + } irq_flag = 1; } ext_intr_stat1 = readl(adata->acp63_base + ACP_EXTERNAL_INTR_STAT1); if (ext_intr_stat1 & ACP_SDW1_STAT) { writel(ACP_SDW1_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT1); - amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); - if (amd_manager) - schedule_work(&amd_manager->amd_sdw_irq_thread); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); + if (amd_manager) + schedule_work(&amd_manager->amd_sdw_irq_thread); + } irq_flag = 1; } @@ -480,7 +488,7 @@ static int create_acp63_platform_devs(struct pci_dev *pci, struct acp63_dev_data parent = &pci->dev; if (adata->is_sdw_dev || adata->is_pdm_dev) { - adata->res = devm_kzalloc(&pci->dev, sizeof(struct resource), GFP_KERNEL); + adata->res = devm_kzalloc_obj(&pci->dev, struct resource); if (!adata->res) { ret = -ENOMEM; goto de_init; @@ -550,8 +558,7 @@ static int create_acp63_platform_devs(struct pci_dev *pci, struct acp63_dev_data static int acp_hw_init_ops(struct acp63_dev_data *adata, struct pci_dev *pci) { - adata->hw_ops = devm_kzalloc(&pci->dev, sizeof(struct acp_hw_ops), - GFP_KERNEL); + adata->hw_ops = devm_kzalloc_obj(&pci->dev, struct acp_hw_ops); if (!adata->hw_ops) return -ENOMEM; @@ -607,8 +614,7 @@ static int snd_acp63_probe(struct pci_dev *pci, dev_err(&pci->dev, "pci_request_regions failed\n"); goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp63_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp63_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; diff --git a/sound/soc/amd/ps/ps-pdm-dma.c b/sound/soc/amd/ps/ps-pdm-dma.c index 12c341e89bce66..359ca10b9ba49e 100644 --- a/sound/soc/amd/ps/ps-pdm-dma.c +++ b/sound/soc/amd/ps/ps-pdm-dma.c @@ -377,7 +377,7 @@ static int acp63_pdm_audio_probe(struct platform_device *pdev) return -ENODEV; } - adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, *adata); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/ps/ps-sdw-dma.c b/sound/soc/amd/ps/ps-sdw-dma.c index c2640985f54cbf..6c510e6d9a18b4 100644 --- a/sound/soc/amd/ps/ps-sdw-dma.c +++ b/sound/soc/amd/ps/ps-sdw-dma.c @@ -661,7 +661,7 @@ static int acp63_sdw_platform_probe(struct platform_device *pdev) return -ENODEV; } - sdw_data = devm_kzalloc(&pdev->dev, sizeof(*sdw_data), GFP_KERNEL); + sdw_data = devm_kzalloc_obj(&pdev->dev, *sdw_data); if (!sdw_data) return -ENOMEM; diff --git a/sound/soc/amd/raven/acp3x-i2s.c b/sound/soc/amd/raven/acp3x-i2s.c index b0147e88ba54cc..4a0b48cf9f15a6 100644 --- a/sound/soc/amd/raven/acp3x-i2s.c +++ b/sound/soc/amd/raven/acp3x-i2s.c @@ -296,8 +296,7 @@ static int acp3x_dai_probe(struct platform_device *pdev) struct i2s_dev_data *adata; int ret; - adata = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, struct i2s_dev_data); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/raven/acp3x-pcm-dma.c b/sound/soc/amd/raven/acp3x-pcm-dma.c index 0862a431b2d148..700c0ca20e181f 100644 --- a/sound/soc/amd/raven/acp3x-pcm-dma.c +++ b/sound/soc/amd/raven/acp3x-pcm-dma.c @@ -393,7 +393,7 @@ static int acp3x_audio_probe(struct platform_device *pdev) return -ENODEV; } - adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, *adata); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/raven/pci-acp3x.c b/sound/soc/amd/raven/pci-acp3x.c index a013a607b3d470..76a717e5db3aba 100644 --- a/sound/soc/amd/raven/pci-acp3x.c +++ b/sound/soc/amd/raven/pci-acp3x.c @@ -148,8 +148,7 @@ static int snd_acp3x_probe(struct pci_dev *pci, goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp3x_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp3x_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; diff --git a/sound/soc/amd/renoir/acp3x-pdm-dma.c b/sound/soc/amd/renoir/acp3x-pdm-dma.c index 89dc60849c06f0..bea1208f1702ac 100644 --- a/sound/soc/amd/renoir/acp3x-pdm-dma.c +++ b/sound/soc/amd/renoir/acp3x-pdm-dma.c @@ -405,7 +405,7 @@ static int acp_pdm_audio_probe(struct platform_device *pdev) return -ENODEV; } - adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, *adata); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/renoir/rn-pci-acp3x.c b/sound/soc/amd/renoir/rn-pci-acp3x.c index b3812b70f5f984..d8b418b69ed907 100644 --- a/sound/soc/amd/renoir/rn-pci-acp3x.c +++ b/sound/soc/amd/renoir/rn-pci-acp3x.c @@ -236,8 +236,7 @@ static int snd_rn_acp_probe(struct pci_dev *pci, goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; diff --git a/sound/soc/amd/vangogh/acp5x-i2s.c b/sound/soc/amd/vangogh/acp5x-i2s.c index dbfb87e2fe9294..81678e654a686d 100644 --- a/sound/soc/amd/vangogh/acp5x-i2s.c +++ b/sound/soc/amd/vangogh/acp5x-i2s.c @@ -383,8 +383,7 @@ static int acp5x_dai_probe(struct platform_device *pdev) struct i2s_dev_data *adata; int ret; - adata = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, struct i2s_dev_data); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c index 5454de24fbcc7e..8dcb5814d022bc 100644 --- a/sound/soc/amd/vangogh/acp5x-mach.c +++ b/sound/soc/amd/vangogh/acp5x-mach.c @@ -457,7 +457,7 @@ static int acp5x_probe(struct platform_device *pdev) if (!dmi_id || !dmi_id->driver_data) return -ENODEV; - machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL); + machine = devm_kzalloc_obj(dev, *machine); if (!machine) return -ENOMEM; diff --git a/sound/soc/amd/vangogh/acp5x-pcm-dma.c b/sound/soc/amd/vangogh/acp5x-pcm-dma.c index 72050fa2de8046..8b09e66610b528 100644 --- a/sound/soc/amd/vangogh/acp5x-pcm-dma.c +++ b/sound/soc/amd/vangogh/acp5x-pcm-dma.c @@ -385,7 +385,7 @@ static int acp5x_audio_probe(struct platform_device *pdev) return -ENODEV; } - adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, *adata); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/vangogh/pci-acp5x.c b/sound/soc/amd/vangogh/pci-acp5x.c index af56ff09f02a99..645120a00b0c68 100644 --- a/sound/soc/amd/vangogh/pci-acp5x.c +++ b/sound/soc/amd/vangogh/pci-acp5x.c @@ -154,8 +154,7 @@ static int snd_acp5x_probe(struct pci_dev *pci, goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp5x_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp5x_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; diff --git a/sound/soc/amd/yc/acp6x-mach.c b/sound/soc/amd/yc/acp6x-mach.c index 7ab48e3629be8b..f636b5ba5b0720 100644 --- a/sound/soc/amd/yc/acp6x-mach.c +++ b/sound/soc/amd/yc/acp6x-mach.c @@ -409,6 +409,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Nitro ANV15-41"), } }, + { + .driver_data = &acp6x_card, + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "RB"), + DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN16-41"), + } + }, { .driver_data = &acp6x_card, .matches = { @@ -955,6 +962,20 @@ static const struct dmi_system_id yc_acp_quirk_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "HP 255R 15.6 inch G10 Notebook PC"), } }, + { + .driver_data = &acp6x_card, + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "TUF Gaming A16 FA607NUQ"), + } + }, + { + .driver_data = &acp6x_card, + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "GIGABYTE"), + DMI_MATCH(DMI_PRODUCT_NAME, "GIGABYTE EAGLE 9MJ"), + } + }, {} }; @@ -986,7 +1007,7 @@ static int acp6x_probe(struct platform_device *pdev) if (!ACPI_FAILURE(ret)) { wov_en = dmic_status; if (!wov_en) - return -ENODEV; + goto check_dmi_entry; } else { /* Incase of ACPI method read failure then jump to check_dmi_entry */ goto check_dmi_entry; diff --git a/sound/soc/amd/yc/acp6x-pdm-dma.c b/sound/soc/amd/yc/acp6x-pdm-dma.c index cba2509faaa1c8..3f8c73a1f182f2 100644 --- a/sound/soc/amd/yc/acp6x-pdm-dma.c +++ b/sound/soc/amd/yc/acp6x-pdm-dma.c @@ -370,7 +370,7 @@ static int acp6x_pdm_audio_probe(struct platform_device *pdev) return -ENODEV; } - adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL); + adata = devm_kzalloc_obj(&pdev->dev, *adata); if (!adata) return -ENOMEM; diff --git a/sound/soc/amd/yc/pci-acp6x.c b/sound/soc/amd/yc/pci-acp6x.c index bacbfc55c598b0..baf2baeb995247 100644 --- a/sound/soc/amd/yc/pci-acp6x.c +++ b/sound/soc/amd/yc/pci-acp6x.c @@ -180,8 +180,7 @@ static int snd_acp6x_probe(struct pci_dev *pci, goto disable_pci; } - adata = devm_kzalloc(&pci->dev, sizeof(struct acp6x_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(&pci->dev, struct acp6x_dev_data); if (!adata) { ret = -ENOMEM; goto release_regions; @@ -221,9 +220,7 @@ static int snd_acp6x_probe(struct pci_dev *pci, } fallthrough; default: - adata->res = devm_kzalloc(&pci->dev, - sizeof(struct resource), - GFP_KERNEL); + adata->res = devm_kzalloc_obj(&pci->dev, struct resource); if (!adata->res) { ret = -ENOMEM; goto de_init; diff --git a/sound/soc/apple/mca.c b/sound/soc/apple/mca.c index 26022a42a95ecc..38bd799c4e0867 100644 --- a/sound/soc/apple/mca.c +++ b/sound/soc/apple/mca.c @@ -53,6 +53,8 @@ #define SYNCGEN_STATUS_EN BIT(0) #define REG_SYNCGEN_MCLK_SEL 0x104 #define SYNCGEN_MCLK_SEL GENMASK(3, 0) +#define SYNCGEN_MCLK_FE_CLK(n) ((n) + 1) +#define SYNCGEN_MCLK_BE_CLK(n) ((n) + 7) #define REG_SYNCGEN_HI_PERIOD 0x108 #define REG_SYNCGEN_LO_PERIOD 0x10c @@ -313,7 +315,8 @@ static int mca_fe_enable_clocks(struct mca_cluster *cl) return -EINVAL; } - writel_relaxed(cl->no + 1, cl->base + REG_SYNCGEN_MCLK_SEL); + writel_relaxed(SYNCGEN_MCLK_FE_CLK(cl->no), + cl->base + REG_SYNCGEN_MCLK_SEL); mca_modify(cl, REG_SYNCGEN_STATUS, SYNCGEN_STATUS_EN, SYNCGEN_STATUS_EN); mca_modify(cl, REG_STATUS, STATUS_MCLK_EN, STATUS_MCLK_EN); @@ -390,7 +393,7 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream, /* Turn on the cluster power domain if not already in use */ if (!cl->syncgen_in_use) { - int port = ffs(mca_fe_get_portmask(substream)); + int port = ffs(mca_fe_get_portmask(substream)) - 1; cl->pd_link = device_link_add(mca->dev, cl->pd_dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME | @@ -401,7 +404,8 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream, return -EINVAL; } - mca_modify(cl, REG_SYNCGEN_MCLK_SEL, SYNCGEN_MCLK_SEL, BIT(port)); + mca_modify(cl, REG_SYNCGEN_MCLK_SEL, SYNCGEN_MCLK_SEL, + SYNCGEN_MCLK_BE_CLK(port)); mca_modify(cl, REG_SYNCGEN_STATUS, SYNCGEN_STATUS_EN, SYNCGEN_STATUS_EN); } @@ -940,7 +944,7 @@ static int mca_set_runtime_hwparams(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct dma_chan *chan) { - struct device *dma_dev = chan->device->dev; + struct device *dma_dev = dmaengine_get_dma_device(chan); struct snd_dmaengine_dai_dma_data dma_data = {}; int ret; @@ -1123,7 +1127,7 @@ static int mca_pcm_new(struct snd_soc_component *component, cl->dma_chans[i] = chan; snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV_IRAM, - chan->device->dev, 512 * 1024 * 6, + dmaengine_get_dma_device(chan), 512 * 1024 * 6, SIZE_MAX); } @@ -1182,8 +1186,7 @@ static int apple_mca_probe(struct platform_device *pdev) return -EINVAL; nclusters = (resource_size(res) - CLUSTER_STRIDE) / CLUSTER_STRIDE + 1; - mca = devm_kzalloc(&pdev->dev, struct_size(mca, clusters, nclusters), - GFP_KERNEL); + mca = devm_kzalloc_flex(&pdev->dev, *mca, clusters, nclusters); if (!mca) return -ENOMEM; mca->dev = &pdev->dev; diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c index 6693bdcbb8f582..746e6bbbf4237b 100644 --- a/sound/soc/atmel/atmel-classd.c +++ b/sound/soc/atmel/atmel-classd.c @@ -58,7 +58,7 @@ static struct atmel_classd_pdata *atmel_classd_dt_init(struct device *dev) return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -473,7 +473,7 @@ static int atmel_classd_asoc_card_init(struct device *dev, struct atmel_classd *dd = snd_soc_card_get_drvdata(card); struct snd_soc_dai_link_component *comp; - dai_link = devm_kzalloc(dev, sizeof(*dai_link), GFP_KERNEL); + dai_link = devm_kzalloc_obj(dev, *dai_link); if (!dai_link) return -ENOMEM; @@ -536,7 +536,7 @@ static int atmel_classd_probe(struct platform_device *pdev) return PTR_ERR(pdata); } - dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, *dd); if (!dd) return -ENOMEM; @@ -592,7 +592,7 @@ static int atmel_classd_probe(struct platform_device *pdev) } /* register sound card */ - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) { ret = -ENOMEM; goto unregister_codec; diff --git a/sound/soc/atmel/atmel-i2s.c b/sound/soc/atmel/atmel-i2s.c index e1d8af0562341e..4c7d26b6892481 100644 --- a/sound/soc/atmel/atmel-i2s.c +++ b/sound/soc/atmel/atmel-i2s.c @@ -329,7 +329,7 @@ static int atmel_i2s_hw_params(struct snd_pcm_substream *substream, int ret; mr_mask = ATMEL_I2SC_MR_FORMAT_MASK | ATMEL_I2SC_MR_MODE_MASK | - ATMEL_I2SC_MR_DATALENGTH_MASK; + ATMEL_I2SC_MR_DATALENGTH_MASK | ATMEL_I2SC_MR_IWS; if (is_playback) mr_mask |= ATMEL_I2SC_MR_TXMONO; else @@ -631,7 +631,7 @@ static int atmel_i2s_probe(struct platform_device *pdev) unsigned int version; /* Get memory for driver data. */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; @@ -650,21 +650,16 @@ static int atmel_i2s_probe(struct platform_device *pdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - /* Request IRQ. */ + /* Get the IRQ. */ irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; - err = devm_request_irq(&pdev->dev, irq, atmel_i2s_interrupt, 0, - dev_name(&pdev->dev), dev); - if (err) - return err; - - /* Get the peripheral clock. */ - dev->pclk = devm_clk_get(&pdev->dev, "pclk"); + /* Get and enable the peripheral clock. */ + dev->pclk = devm_clk_get_enabled(&pdev->dev, "pclk"); if (IS_ERR(dev->pclk)) return dev_err_probe(&pdev->dev, PTR_ERR(dev->pclk), - "failed to get the peripheral clock\n"); + "failed to get/enable the peripheral clock\n"); /* Get audio clock to generate the I2S Master Clock (I2S_MCK) */ dev->gclk = devm_clk_get_optional(&pdev->dev, "gclk"); @@ -675,6 +670,15 @@ static int atmel_i2s_probe(struct platform_device *pdev) dev->regmap = regmap; platform_set_drvdata(pdev, dev); + /* + * Request IRQ after initializing dev->regmap and enabling pclk, + * so devres frees the IRQ before disabling pclk. + */ + err = devm_request_irq(&pdev->dev, irq, atmel_i2s_interrupt, 0, + dev_name(&pdev->dev), dev); + if (err) + return err; + /* Do hardware specific settings to initialize I2S_MCK generator */ if (dev->caps && dev->caps->mck_init) { err = dev->caps->mck_init(dev, np); @@ -682,11 +686,6 @@ static int atmel_i2s_probe(struct platform_device *pdev) return err; } - /* Enable the peripheral clock. */ - err = clk_prepare_enable(dev->pclk); - if (err) - return err; - /* Get IP version. */ regmap_read(dev->regmap, ATMEL_I2SC_VERSION, &version); dev_info(&pdev->dev, "hw version: %#x\n", version); @@ -698,10 +697,8 @@ static int atmel_i2s_probe(struct platform_device *pdev) err = devm_snd_soc_register_component(&pdev->dev, &atmel_i2s_component, &atmel_i2s_dai, 1); - if (err) { - clk_disable_unprepare(dev->pclk); + if (err) return err; - } /* Prepare DMA config. */ dev->playback.addr = (dma_addr_t)mem->start + ATMEL_I2SC_THR; @@ -712,28 +709,18 @@ static int atmel_i2s_probe(struct platform_device *pdev) if (of_property_match_string(np, "dma-names", "rx-tx") == 0) pcm_flags |= SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX; err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, pcm_flags); - if (err) { - clk_disable_unprepare(dev->pclk); + if (err) return err; - } return 0; } -static void atmel_i2s_remove(struct platform_device *pdev) -{ - struct atmel_i2s_dev *dev = platform_get_drvdata(pdev); - - clk_disable_unprepare(dev->pclk); -} - static struct platform_driver atmel_i2s_driver = { .driver = { .name = "atmel_i2s", .of_match_table = atmel_i2s_dt_ids, }, .probe = atmel_i2s_probe, - .remove = atmel_i2s_remove, }; module_platform_driver(atmel_i2s_driver); diff --git a/sound/soc/atmel/atmel-pdmic.c b/sound/soc/atmel/atmel-pdmic.c index 4dfc7e5ca8ff9f..892bd7e3bcab0f 100644 --- a/sound/soc/atmel/atmel-pdmic.c +++ b/sound/soc/atmel/atmel-pdmic.c @@ -57,7 +57,7 @@ static struct atmel_pdmic_pdata *atmel_pdmic_dt_init(struct device *dev) return ERR_PTR(-EINVAL); } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -492,11 +492,11 @@ static int atmel_pdmic_asoc_card_init(struct device *dev, struct atmel_pdmic *dd = snd_soc_card_get_drvdata(card); struct snd_soc_dai_link_component *comp; - dai_link = devm_kzalloc(dev, sizeof(*dai_link), GFP_KERNEL); + dai_link = devm_kzalloc_obj(dev, *dai_link); if (!dai_link) return -ENOMEM; - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc_obj(dev, *comp); if (!comp) return -ENOMEM; @@ -581,7 +581,7 @@ static int atmel_pdmic_probe(struct platform_device *pdev) if (IS_ERR(pdata)) return PTR_ERR(pdata); - dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, *dd); if (!dd) return -ENOMEM; @@ -661,7 +661,7 @@ static int atmel_pdmic_probe(struct platform_device *pdev) } /* register sound card */ - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) { ret = -ENOMEM; goto unregister_codec; diff --git a/sound/soc/atmel/mchp-i2s-mcc.c b/sound/soc/atmel/mchp-i2s-mcc.c index a832dee73ac781..cb0f3e55b05d69 100644 --- a/sound/soc/atmel/mchp-i2s-mcc.c +++ b/sound/soc/atmel/mchp-i2s-mcc.c @@ -1042,7 +1042,7 @@ static int mchp_i2s_mcc_probe(struct platform_device *pdev) int irq; int err; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c index a6a9b5e6cd95ec..039b2eba0d9de5 100644 --- a/sound/soc/atmel/mchp-pdmc.c +++ b/sound/soc/atmel/mchp-pdmc.c @@ -1022,7 +1022,7 @@ static int mchp_pdmc_probe(struct platform_device *pdev) int irq; int ret; - dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL); + dd = devm_kzalloc_obj(dev, *dd); if (!dd) return -ENOMEM; diff --git a/sound/soc/atmel/mchp-spdifrx.c b/sound/soc/atmel/mchp-spdifrx.c index 2c47aabdca95d9..63089ac3ebdc97 100644 --- a/sound/soc/atmel/mchp-spdifrx.c +++ b/sound/soc/atmel/mchp-spdifrx.c @@ -1090,7 +1090,7 @@ static int mchp_spdifrx_probe(struct platform_device *pdev) u32 vers; /* Get memory for driver data. */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c index 245c0352c1417c..fc635ed6856e15 100644 --- a/sound/soc/atmel/mchp-spdiftx.c +++ b/sound/soc/atmel/mchp-spdiftx.c @@ -789,7 +789,7 @@ static int mchp_spdiftx_probe(struct platform_device *pdev) int err; /* Get memory for driver data. */ - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/atmel/mikroe-proto.c b/sound/soc/atmel/mikroe-proto.c index 8341a6e0649307..93c6a93b22be46 100644 --- a/sound/soc/atmel/mikroe-proto.c +++ b/sound/soc/atmel/mikroe-proto.c @@ -81,7 +81,7 @@ static int snd_proto_probe(struct platform_device *pdev) if (ret) return ret; - dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(&pdev->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/atmel/sam9x5_wm8731.c b/sound/soc/atmel/sam9x5_wm8731.c index a603e4a57d5025..9d168f408faba8 100644 --- a/sound/soc/atmel/sam9x5_wm8731.c +++ b/sound/soc/atmel/sam9x5_wm8731.c @@ -84,9 +84,9 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) return -EINVAL; } - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); + priv = devm_kzalloc_obj(&pdev->dev, *priv); + dai = devm_kzalloc_obj(&pdev->dev, *dai); comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL); if (!dai || !card || !priv || !comp) { ret = -ENOMEM; diff --git a/sound/soc/atmel/tse850-pcm5142.c b/sound/soc/atmel/tse850-pcm5142.c index 0b4927d07f25c8..169dd33ffc252d 100644 --- a/sound/soc/atmel/tse850-pcm5142.c +++ b/sound/soc/atmel/tse850-pcm5142.c @@ -349,7 +349,7 @@ static int tse850_probe(struct platform_device *pdev) struct tse850_priv *tse850; int ret; - tse850 = devm_kzalloc(dev, sizeof(*tse850), GFP_KERNEL); + tse850 = devm_kzalloc_obj(dev, *tse850); if (!tse850) return -ENOMEM; diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c index f8ab936250dc0e..308b7f6d8c441c 100644 --- a/sound/soc/au1x/ac97c.c +++ b/sound/soc/au1x/ac97c.c @@ -233,7 +233,7 @@ static int au1xac97c_drvprobe(struct platform_device *pdev) struct resource *iores, *dmares; struct au1xpsc_audio_data *ctx; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c index 3d10d64604727e..2aba135a433b8e 100644 --- a/sound/soc/au1x/dbdma2.c +++ b/sound/soc/au1x/dbdma2.c @@ -326,9 +326,7 @@ static int au1xpsc_pcm_drvprobe(struct platform_device *pdev) { struct au1xpsc_audio_dmadata *dmadata; - dmadata = devm_kcalloc(&pdev->dev, - 2, sizeof(struct au1xpsc_audio_dmadata), - GFP_KERNEL); + dmadata = devm_kzalloc_objs(&pdev->dev, struct au1xpsc_audio_dmadata, 2); if (!dmadata) return -ENOMEM; diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c index 026d9f36db1066..55044b9d09ff12 100644 --- a/sound/soc/au1x/dma.c +++ b/sound/soc/au1x/dma.c @@ -303,7 +303,7 @@ static int alchemy_pcm_drvprobe(struct platform_device *pdev) { struct alchemy_pcm_ctx *ctx; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c index 0e9c7eef9ee848..1afb3571a784d2 100644 --- a/sound/soc/au1x/i2sc.c +++ b/sound/soc/au1x/i2sc.c @@ -247,7 +247,7 @@ static int au1xi2s_drvprobe(struct platform_device *pdev) struct resource *iores, *dmares; struct au1xpsc_audio_data *ctx; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c index 0f9d8088311676..b2836f7eb9b447 100644 --- a/sound/soc/au1x/psc-ac97.c +++ b/sound/soc/au1x/psc-ac97.c @@ -365,8 +365,7 @@ static int au1xpsc_ac97_drvprobe(struct platform_device *pdev) unsigned long sel; struct au1xpsc_audio_data *wd; - wd = devm_kzalloc(&pdev->dev, sizeof(struct au1xpsc_audio_data), - GFP_KERNEL); + wd = devm_kzalloc_obj(&pdev->dev, struct au1xpsc_audio_data); if (!wd) return -ENOMEM; diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c index 72aa5177147f78..9f676c0ea75ef9 100644 --- a/sound/soc/au1x/psc-i2s.c +++ b/sound/soc/au1x/psc-i2s.c @@ -307,8 +307,7 @@ static int au1xpsc_i2s_drvprobe(struct platform_device *pdev) unsigned long sel; struct au1xpsc_audio_data *wd; - wd = devm_kzalloc(&pdev->dev, sizeof(struct au1xpsc_audio_data), - GFP_KERNEL); + wd = devm_kzalloc_obj(&pdev->dev, struct au1xpsc_audio_data); if (!wd) return -ENOMEM; diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c index 2089778282541a..8702f1d062dfed 100644 --- a/sound/soc/bcm/bcm2835-i2s.c +++ b/sound/soc/bcm/bcm2835-i2s.c @@ -846,8 +846,7 @@ static int bcm2835_i2s_probe(struct platform_device *pdev) const __be32 *addr; dma_addr_t dma_base; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), - GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/bcm/bcm63xx-i2s-whistler.c b/sound/soc/bcm/bcm63xx-i2s-whistler.c index 14d111fe29d83c..247b5408c7ab72 100644 --- a/sound/soc/bcm/bcm63xx-i2s-whistler.c +++ b/sound/soc/bcm/bcm63xx-i2s-whistler.c @@ -229,7 +229,7 @@ static int bcm63xx_i2s_dev_probe(struct platform_device *pdev) struct regmap *regmap_i2s; struct clk *i2s_clk; - i2s_priv = devm_kzalloc(&pdev->dev, sizeof(*i2s_priv), GFP_KERNEL); + i2s_priv = devm_kzalloc_obj(&pdev->dev, *i2s_priv); if (!i2s_priv) return -ENOMEM; diff --git a/sound/soc/bcm/cygnus-ssp.c b/sound/soc/bcm/cygnus-ssp.c index 753021789a522a..3ef34daccd8099 100644 --- a/sound/soc/bcm/cygnus-ssp.c +++ b/sound/soc/bcm/cygnus-ssp.c @@ -1310,7 +1310,7 @@ static int cygnus_ssp_probe(struct platform_device *pdev) int node_count; int active_port_count; - cygaud = devm_kzalloc(dev, sizeof(struct cygnus_audio), GFP_KERNEL); + cygaud = devm_kzalloc_obj(dev, struct cygnus_audio); if (!cygaud) return -ENOMEM; diff --git a/sound/soc/cirrus/ep93xx-i2s.c b/sound/soc/cirrus/ep93xx-i2s.c index 8195ed7c6dd69a..97816fb7536804 100644 --- a/sound/soc/cirrus/ep93xx-i2s.c +++ b/sound/soc/cirrus/ep93xx-i2s.c @@ -452,7 +452,7 @@ static int ep93xx_i2s_probe(struct platform_device *pdev) struct ep93xx_i2s_info *info; int err; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c index 7596227fbccfc9..7f3c198510d473 100644 --- a/sound/soc/codecs/88pm860x-codec.c +++ b/sound/soc/codecs/88pm860x-codec.c @@ -1361,8 +1361,7 @@ static int pm860x_codec_probe(struct platform_device *pdev) struct resource *res; int i, ret; - pm860x = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_priv), - GFP_KERNEL); + pm860x = devm_kzalloc_obj(&pdev->dev, struct pm860x_priv); if (pm860x == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 3e379a8d5b1c82..6239de3afa5a47 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -128,6 +128,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_ES7134 imply SND_SOC_ES7202 imply SND_SOC_ES7241 + imply SND_SOC_FM34NE_DSP imply SND_SOC_FRAMER imply SND_SOC_FS210X imply SND_SOC_GTM601 @@ -173,6 +174,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_MT6358 imply SND_SOC_MT6359 imply SND_SOC_MT6660 + imply SND_SOC_NAU8310 imply SND_SOC_NAU8315 imply SND_SOC_NAU8325 imply SND_SOC_NAU8360 @@ -285,6 +287,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_TAS6424 imply SND_SOC_TAS675X imply SND_SOC_TDA7419 + imply SND_SOC_TFA9865 imply SND_SOC_TFA9879 imply SND_SOC_TFA989X imply SND_SOC_TLV320ADC3XXX @@ -1349,6 +1352,17 @@ config SND_SOC_ES9356 select REGMAP_SOUNDWIRE select REGMAP_SOUNDWIRE_MBQ +config SND_SOC_FM34NE_DSP + tristate "DSP FM34NE driver" + depends on I2C && GPIOLIB + help + Say Y here if you want to add support for Fortemedia FM34NE DSP + mainly used in ASUS T20/T30 Transformers for input noise + processing. + + To compile this driver as a module, choose M here: the module + will be called snd-soc-fm34ne-dsp. + config SND_SOC_FRAMER tristate "Framer codec" depends on GENERIC_FRAMER @@ -1989,6 +2003,7 @@ config SND_SOC_RT712_SDCA_DMIC_SDW config SND_SOC_RT721_SDCA_SDW tristate "Realtek RT721 SDCA Codec - SDW" depends on SOUNDWIRE + depends on SND_SOC_SDCA select REGMAP_SOUNDWIRE select REGMAP_SOUNDWIRE_MBQ @@ -2332,6 +2347,19 @@ config SND_SOC_TDA7419 depends on I2C select REGMAP_I2C +config SND_SOC_TFA9865 + tristate "NXP/Goodix TFA9865 amplifier" + depends on I2C + select REGMAP_I2C + help + Enable support for the NXP (now Goodix) TFA9865 mono class-D + speaker amplifier with boost converter. The amplifier has no DSP, + speaker protection is left to the host. The driver supports the + B0 revision of the chip with 32-bit I2S slots. + + To compile this driver as a module, choose M here: the module + will be called snd-soc-tfa9865. + config SND_SOC_TFA9879 tristate "NXP Semiconductors TFA9879 amplifier" depends on I2C @@ -2922,6 +2950,19 @@ config SND_SOC_MT6660 Select N if you don't have MT6660 on board. Select M to build this as module. +config SND_SOC_NAU8310 + tristate "Nuvoton Technology Corporation NAU83G10/G20 Mono Boosted Amplifier" + depends on I2C + select FW_LOADER + help + The NAU83G10 (boosted) and NAU83G20 are mono Class-D amplifiers + featuring integrated DSP and I/V sense. They use real-time voltage + and current feedback for speaker excursion control to protect the + speaker and enhance sound quality. + Additionally, the NAU83G10 includes a built-in boost converter + that can step up a battery supply (VBAT, minimum 2.9V) to deliver + an output voltage of up to 12V based on the peak signal. + config SND_SOC_NAU8315 tristate "Nuvoton Technology Corporation NAU8315 CODEC" @@ -2985,28 +3026,24 @@ config SND_SOC_LPASS_MACRO_COMMON config SND_SOC_LPASS_WSA_MACRO depends on COMMON_CLK - depends on PM_CLK select REGMAP_MMIO select SND_SOC_LPASS_MACRO_COMMON tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)" config SND_SOC_LPASS_VA_MACRO depends on COMMON_CLK - depends on PM_CLK select REGMAP_MMIO select SND_SOC_LPASS_MACRO_COMMON tristate "Qualcomm VA Macro in LPASS(Low Power Audio SubSystem)" config SND_SOC_LPASS_RX_MACRO depends on COMMON_CLK - depends on PM_CLK select REGMAP_MMIO select SND_SOC_LPASS_MACRO_COMMON tristate "Qualcomm RX Macro in LPASS(Low Power Audio SubSystem)" config SND_SOC_LPASS_TX_MACRO depends on COMMON_CLK - depends on PM_CLK select REGMAP_MMIO select SND_SOC_LPASS_MACRO_COMMON tristate "Qualcomm TX Macro in LPASS(Low Power Audio SubSystem)" diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 2a56fad9073a3c..459a2aa463f3dc 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -143,6 +143,7 @@ snd-soc-es8375-y := es8375.o snd-soc-es8389-y := es8389.o snd-soc-es9039q2m-y := es9039q2m.o snd-soc-es9356-y := es9356.o +snd-soc-fm34ne-dsp-y := fm34ne-dsp.o snd-soc-framer-y := framer-codec.o snd-soc-fs-amp-lib-y := fs-amp-lib.o snd-soc-fs210x-y := fs210x.o @@ -198,6 +199,7 @@ snd-soc-mt6358-y := mt6358.o snd-soc-mt6359-y := mt6359.o snd-soc-mt6359-accdet-y := mt6359-accdet.o snd-soc-mt6660-y := mt6660.o +snd-soc-nau8310-y := nau8310.o nau8310-dsp.o snd-soc-nau8315-y := nau8315.o snd-soc-nau8325-y := nau8325.o snd-soc-nau8360-y := nau8360.o nau8360-dsp.o @@ -335,6 +337,7 @@ snd-soc-tas2781-comlib-i2c-y := tas2781-comlib-i2c.o snd-soc-tas2781-fmwlib-y := tas2781-fmwlib.o snd-soc-tas2781-i2c-y := tas2781-i2c.o snd-soc-tas2783-sdw-y := tas2783-sdw.o +snd-soc-tfa9865-y := tfa9865.o snd-soc-tfa9879-y := tfa9879.o snd-soc-tfa989x-y := tfa989x.o snd-soc-tlv320adc3xxx-y := tlv320adc3xxx.o @@ -592,6 +595,7 @@ obj-$(CONFIG_SND_SOC_ES8375) += snd-soc-es8375.o obj-$(CONFIG_SND_SOC_ES8389) += snd-soc-es8389.o obj-$(CONFIG_SND_SOC_ES9039Q2M) += snd-soc-es9039q2m.o obj-$(CONFIG_SND_SOC_ES9356) += snd-soc-es9356.o +obj-$(CONFIG_SND_SOC_FM34NE_DSP) += snd-soc-fm34ne-dsp.o obj-$(CONFIG_SND_SOC_FRAMER) += snd-soc-framer.o obj-$(CONFIG_SND_SOC_FS_AMP_LIB)+= snd-soc-fs-amp-lib.o obj-$(CONFIG_SND_SOC_FS210X) += snd-soc-fs210x.o @@ -642,6 +646,7 @@ obj-$(CONFIG_SND_SOC_MT6358) += snd-soc-mt6358.o obj-$(CONFIG_SND_SOC_MT6359) += snd-soc-mt6359.o obj-$(CONFIG_SND_SOC_MT6359_ACCDET) += mt6359-accdet.o obj-$(CONFIG_SND_SOC_MT6660) += snd-soc-mt6660.o +obj-$(CONFIG_SND_SOC_NAU8310) += snd-soc-nau8310.o obj-$(CONFIG_SND_SOC_NAU8315) += snd-soc-nau8315.o obj-$(CONFIG_SND_SOC_NAU8325) += snd-soc-nau8325.o obj-$(CONFIG_SND_SOC_NAU8360) += snd-soc-nau8360.o @@ -784,6 +789,7 @@ obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o obj-$(CONFIG_SND_SOC_TAS675X) += snd-soc-tas675x.o obj-$(CONFIG_SND_SOC_TDA7419) += snd-soc-tda7419.o obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o +obj-$(CONFIG_SND_SOC_TFA9865) += snd-soc-tfa9865.o obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o obj-$(CONFIG_SND_SOC_TFA989X) += snd-soc-tfa989x.o obj-$(CONFIG_SND_SOC_TLV320ADC3XXX) += snd-soc-tlv320adc3xxx.o diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c index 3e3ff9bfe00d1b..7df683bc75f865 100644 --- a/sound/soc/codecs/ab8500-codec.c +++ b/sound/soc/codecs/ab8500-codec.c @@ -955,6 +955,12 @@ static DECLARE_TLV_DB_SCALE(dax_dig_gain_tlv, -6300, 100, 1); static DECLARE_TLV_DB_SCALE(hs_ear_dig_gain_tlv, -100, 100, 1); /* -1dB = Mute */ +/* AB8505 v1 handsfree output gain: -3 dB to 12 dB in 1 dB steps. */ +static DECLARE_TLV_DB_SCALE(ab8505_hf_v1_gain_tlv, -300, 100, 0); + +/* AB8505 v2 handsfree output gain: mute, then -3 dB to 20 dB. */ +static DECLARE_TLV_DB_SCALE(ab8505_hf_v2_gain_tlv, -400, 100, 1); + static const DECLARE_TLV_DB_RANGE(hs_gain_tlv, 0, 3, TLV_DB_SCALE_ITEM(-3200, 400, 0), 4, 15, TLV_DB_SCALE_ITEM(-1800, 200, 0) @@ -1519,6 +1525,18 @@ static struct snd_kcontrol_new ab8500_ctrls[] = { AB8500_SIDFIRADR, AB8500_SIDFIRADR_FIRSIDSET, 0), }; +static const struct snd_kcontrol_new ab8505_v1_ctrls[] = { + SOC_DOUBLE_TLV("HF Digital Volume", AB8505_HFGAINCTRL_V1, + AB8505_HFGAINCTRL_V1_HFL, AB8505_HFGAINCTRL_V1_HFR, + AB8505_HFGAINCTRL_V1_MAX, 1, ab8505_hf_v1_gain_tlv), +}; + +static const struct snd_kcontrol_new ab8505_v2_ctrls[] = { + SOC_DOUBLE_R_TLV("HF Digital Volume", + AB8505_HFLGAINCTRL_V2, AB8505_HFRGAINCTRL_V2, + 0, AB8505_HFGAINCTRL_V2_MAX, 1, ab8505_hf_v2_gain_tlv), +}; + /* * Extended interface for codec-driver */ @@ -2081,6 +2099,18 @@ static int ab8500_codec_probe(struct snd_soc_component *component) ARRAY_SIZE(ab8500_dmic_dapm_routes)); if (status) return status; + } else if (is_ab8505_1p0_or_earlier(ab8500)) { + status = snd_soc_add_component_controls(component, + ab8505_v1_ctrls, + ARRAY_SIZE(ab8505_v1_ctrls)); + if (status) + return status; + } else if (is_ab8505(ab8500)) { + status = snd_soc_add_component_controls(component, + ab8505_v2_ctrls, + ARRAY_SIZE(ab8505_v2_ctrls)); + if (status) + return status; } status = ab8500_audio_init_audioblock(component); @@ -2132,8 +2162,7 @@ static int ab8500_codec_driver_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s: Enter.\n", __func__); /* Create driver private-data struct */ - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_codec_drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct ab8500_codec_drvdata); if (!drvdata) return -ENOMEM; dev_set_drvdata(&pdev->dev, drvdata); diff --git a/sound/soc/codecs/ab8500-codec.h b/sound/soc/codecs/ab8500-codec.h index 2a6f6409f1f85a..9ffcb50a991d13 100644 --- a/sound/soc/codecs/ab8500-codec.h +++ b/sound/soc/codecs/ab8500-codec.h @@ -142,6 +142,13 @@ #define AB8500_FIFOCONF6 0x6E #define AB8500_AUDREV 0x6F +/* AB8505 v1 audio bank registers */ +#define AB8505_HFGAINCTRL_V1 0x78 + +/* AB8505 v2 and later audio bank registers */ +#define AB8505_HFLGAINCTRL_V2 0x80 +#define AB8505_HFRGAINCTRL_V2 0x81 + #define AB8500_FIRST_REG AB8500_POWERUP #define AB8500_LAST_REG AB8500_AUDREV #define AB8500_CACHEREGNUM (AB8500_LAST_REG + 1) @@ -150,6 +157,14 @@ #define AB8500_MASK_SLOT(slot) ((slot & 1) ? 0xF0 : 0x0F) #define AB8500_MASK_NONE 0x00 +/* AB8505_HFGAINCTRL_V1 */ +#define AB8505_HFGAINCTRL_V1_HFL 4 +#define AB8505_HFGAINCTRL_V1_HFR 0 +#define AB8505_HFGAINCTRL_V1_MAX 0x0F + +/* AB8505_HFLGAINCTRL_V2, AB8505_HFRGAINCTRL_V2 */ +#define AB8505_HFGAINCTRL_V2_MAX 0x18 + /* AB8500_POWERUP */ #define AB8500_POWERUP_POWERUP 7 #define AB8500_POWERUP_ENANA 3 diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c index dbea83bd49b69b..c524abb456ba0f 100644 --- a/sound/soc/codecs/ad1836.c +++ b/sound/soc/codecs/ad1836.c @@ -372,8 +372,7 @@ static int ad1836_spi_probe(struct spi_device *spi) struct ad1836_priv *ad1836; int ret; - ad1836 = devm_kzalloc(&spi->dev, sizeof(struct ad1836_priv), - GFP_KERNEL); + ad1836 = devm_kzalloc_obj(&spi->dev, struct ad1836_priv); if (ad1836 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c index 9841c779b17529..1c97ebbfb4ba9e 100644 --- a/sound/soc/codecs/ad193x.c +++ b/sound/soc/codecs/ad193x.c @@ -548,7 +548,7 @@ int ad193x_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - ad193x = devm_kzalloc(dev, sizeof(*ad193x), GFP_KERNEL); + ad193x = devm_kzalloc_obj(dev, *ad193x); if (ad193x == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/adau1372.c b/sound/soc/codecs/adau1372.c index 25d7b38c28ad82..4c77de53aa3623 100644 --- a/sound/soc/codecs/adau1372.c +++ b/sound/soc/codecs/adau1372.c @@ -953,7 +953,7 @@ int adau1372_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - adau1372 = devm_kzalloc(dev, sizeof(*adau1372), GFP_KERNEL); + adau1372 = devm_kzalloc_obj(dev, *adau1372); if (!adau1372) return -ENOMEM; diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c index aa7d3a4b9f5885..47998a7e7730a4 100644 --- a/sound/soc/codecs/adau1373.c +++ b/sound/soc/codecs/adau1373.c @@ -1568,7 +1568,7 @@ static int adau1373_i2c_probe(struct i2c_client *client) struct gpio_desc *gpiod; int ret; - adau1373 = devm_kzalloc(&client->dev, sizeof(*adau1373), GFP_KERNEL); + adau1373 = devm_kzalloc_obj(&client->dev, *adau1373); if (!adau1373) return -ENOMEM; diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index 4afbf46ffaa397..6cc89aa802d535 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -798,7 +798,7 @@ static int adau1701_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret, i; - adau1701 = devm_kzalloc(dev, sizeof(*adau1701), GFP_KERNEL); + adau1701 = devm_kzalloc_obj(dev, *adau1701); if (!adau1701) return -ENOMEM; diff --git a/sound/soc/codecs/adau17x1.c b/sound/soc/codecs/adau17x1.c index 207189cfd3a6cc..22349685707b26 100644 --- a/sound/soc/codecs/adau17x1.c +++ b/sound/soc/codecs/adau17x1.c @@ -1066,7 +1066,7 @@ int adau17x1_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - adau = devm_kzalloc(dev, sizeof(*adau), GFP_KERNEL); + adau = devm_kzalloc_obj(dev, *adau); if (!adau) return -ENOMEM; diff --git a/sound/soc/codecs/adau1977.c b/sound/soc/codecs/adau1977.c index b9d98539342167..93c90019c3f9cf 100644 --- a/sound/soc/codecs/adau1977.c +++ b/sound/soc/codecs/adau1977.c @@ -919,7 +919,7 @@ int adau1977_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - adau1977 = devm_kzalloc(dev, sizeof(*adau1977), GFP_KERNEL); + adau1977 = devm_kzalloc_obj(dev, *adau1977); if (adau1977 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/adau7002.c b/sound/soc/codecs/adau7002.c index c9134e1de0b25b..97f54bca1539e7 100644 --- a/sound/soc/codecs/adau7002.c +++ b/sound/soc/codecs/adau7002.c @@ -41,8 +41,7 @@ static int adau7002_component_probe(struct snd_soc_component *component) { struct adau7002_priv *adau7002; - adau7002 = devm_kzalloc(component->dev, sizeof(*adau7002), - GFP_KERNEL); + adau7002 = devm_kzalloc_obj(component->dev, *adau7002); if (!adau7002) return -ENOMEM; diff --git a/sound/soc/codecs/adau7118.c b/sound/soc/codecs/adau7118.c index 9749299bc7f2a7..befd6f632af9ba 100644 --- a/sound/soc/codecs/adau7118.c +++ b/sound/soc/codecs/adau7118.c @@ -446,7 +446,7 @@ static struct snd_soc_dai_driver adau7118_dai = { .channels_max = 8, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_S24_LE | - SNDRV_PCM_FMTBIT_S24_3LE, + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE, .rates = SNDRV_PCM_RATE_CONTINUOUS, .rate_min = 4000, .rate_max = 192000, @@ -546,7 +546,7 @@ int adau7118_probe(struct device *dev, struct regmap *map, bool hw_mode) struct adau7118_data *st; int ret; - st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + st = devm_kzalloc_obj(dev, *st); if (!st) return -ENOMEM; diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c index e97c72ac9b2b24..0f3fb682a2c2d1 100644 --- a/sound/soc/codecs/adav80x.c +++ b/sound/soc/codecs/adav80x.c @@ -859,7 +859,7 @@ int adav80x_bus_probe(struct device *dev, struct regmap *regmap) if (IS_ERR(regmap)) return PTR_ERR(regmap); - adav80x = devm_kzalloc(dev, sizeof(*adav80x), GFP_KERNEL); + adav80x = devm_kzalloc_obj(dev, *adav80x); if (!adav80x) return -ENOMEM; diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c index 5ebc3afccccf63..e23b40e6ed9351 100644 --- a/sound/soc/codecs/ak4104.c +++ b/sound/soc/codecs/ak4104.c @@ -280,8 +280,7 @@ static int ak4104_spi_probe(struct spi_device *spi) if (ret < 0) return ret; - ak4104 = devm_kzalloc(&spi->dev, sizeof(struct ak4104_private), - GFP_KERNEL); + ak4104 = devm_kzalloc_obj(&spi->dev, struct ak4104_private); if (ak4104 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ak4118.c b/sound/soc/codecs/ak4118.c index 2b96b82d4e40ab..3f960256876b74 100644 --- a/sound/soc/codecs/ak4118.c +++ b/sound/soc/codecs/ak4118.c @@ -359,8 +359,7 @@ static int ak4118_i2c_probe(struct i2c_client *i2c) struct ak4118_priv *ak4118; int ret; - ak4118 = devm_kzalloc(&i2c->dev, sizeof(struct ak4118_priv), - GFP_KERNEL); + ak4118 = devm_kzalloc_obj(&i2c->dev, struct ak4118_priv); if (ak4118 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ak4375.c b/sound/soc/codecs/ak4375.c index 452559d8c97bf2..2395d95d9ee29e 100644 --- a/sound/soc/codecs/ak4375.c +++ b/sound/soc/codecs/ak4375.c @@ -460,7 +460,14 @@ static int ak4375_runtime_resume(struct device *dev) regcache_cache_only(ak4375->regmap, false); regcache_mark_dirty(ak4375->regmap); - return regcache_sync(ak4375->regmap); + ret = regcache_sync(ak4375->regmap); + if (ret) { + regcache_cache_only(ak4375->regmap, true); + ak4375_power_off(ak4375); + return ret; + } + + return 0; } static const struct snd_soc_component_driver soc_codec_dev_ak4375 = { @@ -501,7 +508,7 @@ static int ak4375_i2c_probe(struct i2c_client *i2c) unsigned int deviceid; int ret, i; - ak4375 = devm_kzalloc(&i2c->dev, sizeof(*ak4375), GFP_KERNEL); + ak4375 = devm_kzalloc_obj(&i2c->dev, *ak4375); if (!ak4375) return -ENOMEM; @@ -536,19 +543,19 @@ static int ak4375_i2c_probe(struct i2c_client *i2c) regcache_cache_bypass(ak4375->regmap, true); ret = regmap_read(ak4375->regmap, AK4375_15_AUDIO_IF_FORMAT, &deviceid); + regcache_cache_bypass(ak4375->regmap, false); if (ret < 0) { dev_err(ak4375->dev, "unable to read DEVICEID!\n"); - return ret; + goto err_power_off; } - regcache_cache_bypass(ak4375->regmap, false); - deviceid = (deviceid & DEVICEID_MASK) >> 5; + ret = -EINVAL; switch (deviceid) { case DEVICEID_AK4331: dev_err(ak4375->dev, "found untested AK4331\n"); - return -EINVAL; + goto err_power_off; case DEVICEID_AK4375: dev_dbg(ak4375->dev, "found AK4375\n"); break; @@ -557,13 +564,13 @@ static int ak4375_i2c_probe(struct i2c_client *i2c) break; case DEVICEID_AK4376A: dev_err(ak4375->dev, "found unsupported AK4376/A!\n"); - return -EINVAL; + goto err_power_off; case DEVICEID_AK4377: dev_err(ak4375->dev, "found unsupported AK4377!\n"); - return -EINVAL; + goto err_power_off; default: dev_err(ak4375->dev, "unrecognized DEVICEID!\n"); - return -EINVAL; + goto err_power_off; } pm_runtime_set_active(ak4375->dev); @@ -573,10 +580,17 @@ static int ak4375_i2c_probe(struct i2c_client *i2c) drvdata->dai_drv, 1); if (ret < 0) { dev_err(ak4375->dev, "Failed to register CODEC: %d\n", ret); + pm_runtime_disable(ak4375->dev); + ak4375_power_off(ak4375); + pm_runtime_set_suspended(ak4375->dev); return ret; } return 0; + +err_power_off: + ak4375_power_off(ak4375); + return ret; } static void ak4375_i2c_remove(struct i2c_client *i2c) diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c index a74be99e877ddb..11b5e4cc11f873 100644 --- a/sound/soc/codecs/ak4458.c +++ b/sound/soc/codecs/ak4458.c @@ -747,7 +747,7 @@ static int ak4458_i2c_probe(struct i2c_client *i2c) struct ak4458_priv *ak4458; int ret, i; - ak4458 = devm_kzalloc(&i2c->dev, sizeof(*ak4458), GFP_KERNEL); + ak4458 = devm_kzalloc_obj(&i2c->dev, *ak4458); if (!ak4458) return -ENOMEM; diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index 6cabad4c9f74c4..66ca753e765174 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c @@ -415,8 +415,7 @@ static int ak4535_i2c_probe(struct i2c_client *i2c) struct ak4535_priv *ak4535; int ret; - ak4535 = devm_kzalloc(&i2c->dev, sizeof(struct ak4535_priv), - GFP_KERNEL); + ak4535 = devm_kzalloc_obj(&i2c->dev, struct ak4535_priv); if (ak4535 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ak4613.c b/sound/soc/codecs/ak4613.c index be5306d07d406c..ea0d8880e01ad5 100644 --- a/sound/soc/codecs/ak4613.c +++ b/sound/soc/codecs/ak4613.c @@ -807,7 +807,15 @@ static int ak4613_resume(struct snd_soc_component *component) return regcache_sync(regmap); } +static void ak4613_remove(struct snd_soc_component *component) +{ + struct ak4613_priv *priv = snd_soc_component_get_drvdata(component); + + cancel_work_sync(&priv->dummy_write_work); +} + static const struct snd_soc_component_driver soc_component_dev_ak4613 = { + .remove = ak4613_remove, .suspend = ak4613_suspend, .resume = ak4613_resume, .set_bias_level = ak4613_set_bias_level, @@ -880,7 +888,7 @@ static int ak4613_i2c_probe(struct i2c_client *i2c) if (!regmap_cfg) return -EINVAL; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/ak4619.c b/sound/soc/codecs/ak4619.c index bae8e8b6a43016..890830d79aea42 100644 --- a/sound/soc/codecs/ak4619.c +++ b/sound/soc/codecs/ak4619.c @@ -889,7 +889,7 @@ static int ak4619_i2c_probe(struct i2c_client *i2c) struct ak4619_priv *ak4619; int ret; - ak4619 = devm_kzalloc(dev, sizeof(*ak4619), GFP_KERNEL); + ak4619 = devm_kzalloc_obj(dev, *ak4619); if (!ak4619) return -ENOMEM; diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c index a0de45660b001a..b099fd7c9eb218 100644 --- a/sound/soc/codecs/ak4642.c +++ b/sound/soc/codecs/ak4642.c @@ -650,7 +650,7 @@ static int ak4642_i2c_probe(struct i2c_client *i2c) if (!drvdata) return dev_err_probe(dev, -EINVAL, "Unknown device type\n"); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/ak5386.c b/sound/soc/codecs/ak5386.c index 933ca90b7e2878..e025b8e06961b7 100644 --- a/sound/soc/codecs/ak5386.c +++ b/sound/soc/codecs/ak5386.c @@ -169,7 +169,7 @@ static int ak5386_probe(struct platform_device *pdev) struct ak5386_priv *priv; int ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/ak5558.c b/sound/soc/codecs/ak5558.c index 0c9cdf9a53bb49..f4b3cb6f3c00fc 100644 --- a/sound/soc/codecs/ak5558.c +++ b/sound/soc/codecs/ak5558.c @@ -439,7 +439,7 @@ static int ak5558_i2c_probe(struct i2c_client *i2c) int dev_id; int i; - ak5558 = devm_kzalloc(&i2c->dev, sizeof(*ak5558), GFP_KERNEL); + ak5558 = devm_kzalloc_obj(&i2c->dev, *ak5558); if (!ak5558) return -ENOMEM; diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c index 96bb1d59277292..87eccca3aee7a2 100644 --- a/sound/soc/codecs/alc5623.c +++ b/sound/soc/codecs/alc5623.c @@ -997,8 +997,7 @@ static int alc5623_i2c_probe(struct i2c_client *client) int ret; u32 val32; - alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv), - GFP_KERNEL); + alc5623 = devm_kzalloc_obj(&client->dev, struct alc5623_priv); if (alc5623 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c index a5e95f3fc2474e..d179be43c33b8a 100644 --- a/sound/soc/codecs/alc5632.c +++ b/sound/soc/codecs/alc5632.c @@ -1123,8 +1123,7 @@ static int alc5632_i2c_probe(struct i2c_client *client) unsigned int vid1, vid2; unsigned int matched_id; - alc5632 = devm_kzalloc(&client->dev, - sizeof(struct alc5632_priv), GFP_KERNEL); + alc5632 = devm_kzalloc_obj(&client->dev, struct alc5632_priv); if (alc5632 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/arizona-jack.c b/sound/soc/codecs/arizona-jack.c index 6587d46a186705..db60ea1aaec8a6 100644 --- a/sound/soc/codecs/arizona-jack.c +++ b/sound/soc/codecs/arizona-jack.c @@ -1150,7 +1150,7 @@ static int arizona_extcon_get_micd_configs(struct device *dev, if (nconfs <= 0) return 0; - vals = kcalloc(nconfs, sizeof(u32), GFP_KERNEL); + vals = kzalloc_objs(u32, nconfs); if (!vals) return -ENOMEM; @@ -1159,8 +1159,7 @@ static int arizona_extcon_get_micd_configs(struct device *dev, goto out; nconfs /= entries_per_config; - micd_configs = devm_kcalloc(dev, nconfs, sizeof(*micd_configs), - GFP_KERNEL); + micd_configs = devm_kzalloc_objs(dev, *micd_configs, nconfs); if (!micd_configs) { ret = -ENOMEM; goto out; diff --git a/sound/soc/codecs/audio-iio-aux.c b/sound/soc/codecs/audio-iio-aux.c index eef0af63e3d617..82dbba56ec6107 100644 --- a/sound/soc/codecs/audio-iio-aux.c +++ b/sound/soc/codecs/audio-iio-aux.c @@ -237,7 +237,7 @@ static int audio_iio_aux_probe(struct platform_device *pdev) if (count < 0) return dev_err_probe(dev, count, "failed to count io-channel-names\n"); - iio_aux = devm_kzalloc(dev, struct_size(iio_aux, chans, count), GFP_KERNEL); + iio_aux = devm_kzalloc_flex(dev, *iio_aux, chans, count); if (!iio_aux) return -ENOMEM; @@ -245,9 +245,8 @@ static int audio_iio_aux_probe(struct platform_device *pdev) iio_aux->num_chans = count; - const char **names __free(kfree) = kcalloc(iio_aux->num_chans, - sizeof(*names), - GFP_KERNEL); + const char **names __free(kfree) = kzalloc_objs(*names, + iio_aux->num_chans); if (!names) return -ENOMEM; diff --git a/sound/soc/codecs/aw8738.c b/sound/soc/codecs/aw8738.c index 0fe8af16031906..5f931d3a0d5bde 100644 --- a/sound/soc/codecs/aw8738.c +++ b/sound/soc/codecs/aw8738.c @@ -64,7 +64,7 @@ static int aw8738_probe(struct platform_device *pdev) struct aw8738_priv *aw; int ret; - aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL); + aw = devm_kzalloc_obj(dev, *aw); if (!aw) return -ENOMEM; platform_set_drvdata(pdev, aw); diff --git a/sound/soc/codecs/aw87390.c b/sound/soc/codecs/aw87390.c index 5555c45dffcceb..56fc403670d0e6 100644 --- a/sound/soc/codecs/aw87390.c +++ b/sound/soc/codecs/aw87390.c @@ -261,8 +261,8 @@ static int aw87390_request_firmware_file(struct aw87390 *aw87390) dev_dbg(aw87390->aw_pa->dev, "loaded %s - size: %zu\n", AW87390_ACF_FILE, cont ? cont->size : 0); - aw87390->aw_cfg = devm_kzalloc(aw87390->aw_pa->dev, - struct_size(aw87390->aw_cfg, data, cont->size), GFP_KERNEL); + aw87390->aw_cfg = devm_kzalloc_flex(aw87390->aw_pa->dev, + *aw87390->aw_cfg, data, cont->size); if (!aw87390->aw_cfg) return -ENOMEM; @@ -488,7 +488,7 @@ static int aw87390_init(struct aw87390 *aw87390, struct i2c_client *i2c, struct unsigned int chip_id; int ret; - aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); + aw_dev = devm_kzalloc_obj(&i2c->dev, *aw_dev); if (!aw_dev) return -ENOMEM; @@ -540,7 +540,7 @@ static int aw87390_i2c_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return dev_err_probe(&i2c->dev, -ENXIO, "check_functionality failed\n"); - aw87390 = devm_kzalloc(&i2c->dev, sizeof(*aw87390), GFP_KERNEL); + aw87390 = devm_kzalloc_obj(&i2c->dev, *aw87390); if (!aw87390) return -ENOMEM; diff --git a/sound/soc/codecs/aw88081.c b/sound/soc/codecs/aw88081.c index 3247ba5c71b833..3bb59ca701fa70 100644 --- a/sound/soc/codecs/aw88081.c +++ b/sound/soc/codecs/aw88081.c @@ -1080,7 +1080,7 @@ static int aw88081_init(struct aw88081 *aw88081, struct i2c_client *i2c, struct return -ENXIO; } - aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); + aw_dev = devm_kzalloc_obj(&i2c->dev, *aw_dev); if (!aw_dev) return -ENOMEM; @@ -1146,7 +1146,8 @@ static int aw88081_request_firmware_file(struct aw88081 *aw88081) dev_dbg(aw88081->aw_pa->dev, "loaded %s - size: %zu\n", AW88081_ACF_FILE, cont ? cont->size : 0); - aw_cfg = devm_kzalloc(aw88081->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL); + aw_cfg = devm_kzalloc_flex(aw88081->aw_pa->dev, *aw_cfg, data, + cont->size); if (!aw_cfg) return -ENOMEM; @@ -1251,7 +1252,7 @@ static int aw88081_i2c_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return dev_err_probe(&i2c->dev, -ENXIO, "check_functionality failed"); - aw88081 = devm_kzalloc(&i2c->dev, sizeof(*aw88081), GFP_KERNEL); + aw88081 = devm_kzalloc_obj(&i2c->dev, *aw88081); if (!aw88081) return -ENOMEM; diff --git a/sound/soc/codecs/aw88166.c b/sound/soc/codecs/aw88166.c index d2a138211c596f..a520c9089425ca 100644 --- a/sound/soc/codecs/aw88166.c +++ b/sound/soc/codecs/aw88166.c @@ -1588,8 +1588,8 @@ static int aw88166_request_firmware_file(struct aw88166 *aw88166) dev_dbg(aw88166->aw_pa->dev, "loaded %s - size: %zu\n", fw_name, cont ? cont->size : 0); - aw88166->aw_cfg = devm_kzalloc(aw88166->aw_pa->dev, - struct_size(aw88166->aw_cfg, data, cont->size), GFP_KERNEL); + aw88166->aw_cfg = devm_kzalloc_flex(aw88166->aw_pa->dev, + *aw88166->aw_cfg, data, cont->size); if (!aw88166->aw_cfg) return -ENOMEM; @@ -1731,7 +1731,7 @@ static int aw88166_init(struct aw88166 *aw88166, struct i2c_client *i2c, struct return ret; } - aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); + aw_dev = devm_kzalloc_obj(&i2c->dev, *aw_dev); if (!aw_dev) return -ENOMEM; aw88166->aw_pa = aw_dev; @@ -1765,7 +1765,7 @@ static int aw88166_i2c_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return dev_err_probe(&i2c->dev, -ENXIO, "check_functionality failed\n"); - aw88166 = devm_kzalloc(&i2c->dev, sizeof(*aw88166), GFP_KERNEL); + aw88166 = devm_kzalloc_obj(&i2c->dev, *aw88166); if (!aw88166) return -ENOMEM; diff --git a/sound/soc/codecs/aw88261.c b/sound/soc/codecs/aw88261.c index 7303dc9eb4e037..e14df93e67f7ad 100644 --- a/sound/soc/codecs/aw88261.c +++ b/sound/soc/codecs/aw88261.c @@ -1197,7 +1197,8 @@ static int aw88261_request_firmware_file(struct aw88261 *aw88261) dev_info(aw88261->aw_pa->dev, "loaded %s - size: %zu\n", fw_name, cont ? cont->size : 0); - aw_cfg = devm_kzalloc(aw88261->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL); + aw_cfg = devm_kzalloc_flex(aw88261->aw_pa->dev, *aw_cfg, data, + cont->size); if (!aw_cfg) return -ENOMEM; @@ -1290,7 +1291,7 @@ static int aw88261_init(struct aw88261 *aw88261, struct i2c_client *i2c, struct dev_info(&i2c->dev, "chip id = %x\n", chip_id); - aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); + aw_dev = devm_kzalloc_obj(&i2c->dev, *aw_dev); if (!aw_dev) return -ENOMEM; @@ -1320,7 +1321,7 @@ static int aw88261_i2c_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return dev_err_probe(&i2c->dev, -ENXIO, "check_functionality failed"); - aw88261 = devm_kzalloc(&i2c->dev, sizeof(*aw88261), GFP_KERNEL); + aw88261 = devm_kzalloc_obj(&i2c->dev, *aw88261); if (!aw88261) return -ENOMEM; diff --git a/sound/soc/codecs/aw88395/aw88395.c b/sound/soc/codecs/aw88395/aw88395.c index 2f4108624d1393..751908bf9291b3 100644 --- a/sound/soc/codecs/aw88395/aw88395.c +++ b/sound/soc/codecs/aw88395/aw88395.c @@ -435,8 +435,7 @@ static const struct snd_soc_component_driver soc_codec_dev_aw88395 = { static struct aw88395 *aw88395_malloc_init(struct i2c_client *i2c) { - struct aw88395 *aw88395 = devm_kzalloc(&i2c->dev, - sizeof(struct aw88395), GFP_KERNEL); + struct aw88395 *aw88395 = devm_kzalloc_obj(&i2c->dev, struct aw88395); if (!aw88395) return NULL; @@ -472,7 +471,8 @@ static int aw88395_request_firmware_file(struct aw88395 *aw88395) dev_info(aw88395->aw_pa->dev, "loaded %s - size: %zu\n", AW88395_ACF_FILE, cont ? cont->size : 0); - aw_cfg = devm_kzalloc(aw88395->aw_pa->dev, struct_size(aw_cfg, data, cont->size), GFP_KERNEL); + aw_cfg = devm_kzalloc_flex(aw88395->aw_pa->dev, *aw_cfg, data, + cont->size); if (!aw_cfg) return -ENOMEM; diff --git a/sound/soc/codecs/aw88395/aw88395_device.c b/sound/soc/codecs/aw88395/aw88395_device.c index 12d42d27560db1..3ae418c8b34e10 100644 --- a/sound/soc/codecs/aw88395/aw88395_device.c +++ b/sound/soc/codecs/aw88395/aw88395_device.c @@ -1674,7 +1674,7 @@ int aw88395_init(struct aw_device **aw_dev, struct i2c_client *i2c, struct regma if (*aw_dev) { dev_info(&i2c->dev, "it should be initialized here.\n"); } else { - *aw_dev = devm_kzalloc(&i2c->dev, sizeof(struct aw_device), GFP_KERNEL); + *aw_dev = devm_kzalloc_obj(&i2c->dev, struct aw_device); if (!(*aw_dev)) return -ENOMEM; } diff --git a/sound/soc/codecs/aw88395/aw88395_lib.c b/sound/soc/codecs/aw88395/aw88395_lib.c index 056adbcd1ce890..7d0cbd3574f1c6 100644 --- a/sound/soc/codecs/aw88395/aw88395_lib.c +++ b/sound/soc/codecs/aw88395/aw88395_lib.c @@ -579,9 +579,9 @@ static int aw_dev_cfg_get_reg_valid_prof(struct aw_device *aw_dev, return -EPERM; } - prof_info->prof_desc = devm_kcalloc(aw_dev->dev, - prof_info->count, sizeof(struct aw_prof_desc), - GFP_KERNEL); + prof_info->prof_desc = devm_kzalloc_objs(aw_dev->dev, + struct aw_prof_desc, + prof_info->count); if (!prof_info->prof_desc) return -ENOMEM; @@ -630,9 +630,9 @@ static int aw_dev_cfg_get_multiple_valid_prof(struct aw_device *aw_dev, return -EPERM; } - prof_info->prof_desc = devm_kcalloc(aw_dev->dev, - prof_info->count, sizeof(struct aw_prof_desc), - GFP_KERNEL); + prof_info->prof_desc = devm_kzalloc_objs(aw_dev->dev, + struct aw_prof_desc, + prof_info->count); if (!prof_info->prof_desc) return -ENOMEM; @@ -965,9 +965,9 @@ static int aw_dev_load_cfg_by_hdr_v1(struct aw_device *aw_dev, return ret; } - prof_info->prof_desc = devm_kcalloc(aw_dev->dev, - prof_info->count, sizeof(struct aw_prof_desc), - GFP_KERNEL); + prof_info->prof_desc = devm_kzalloc_objs(aw_dev->dev, + struct aw_prof_desc, + prof_info->count); if (!prof_info->prof_desc) return -ENOMEM; diff --git a/sound/soc/codecs/aw88399-lib.c b/sound/soc/codecs/aw88399-lib.c index b08baacad87b5e..f2e2c88f5ec0a7 100644 --- a/sound/soc/codecs/aw88399-lib.c +++ b/sound/soc/codecs/aw88399-lib.c @@ -1300,8 +1300,8 @@ int aw88399_request_firmware_file(struct aw88399 *aw88399, const char *fw_name) dev_dbg(aw88399->aw_pa->dev, "loaded %s - size: %zu\n", fw_name, cont ? cont->size : 0); - aw88399->aw_cfg = devm_kzalloc(aw88399->aw_pa->dev, - struct_size(aw88399->aw_cfg, data, cont->size), GFP_KERNEL); + aw88399->aw_cfg = devm_kzalloc_flex(aw88399->aw_pa->dev, + *aw88399->aw_cfg, data, cont->size); if (!aw88399->aw_cfg) return -ENOMEM; @@ -1376,7 +1376,7 @@ int aw88399_init(struct aw88399 *aw88399, struct i2c_client *i2c, struct regmap } dev_dbg(&i2c->dev, "chip id = %x\n", chip_id); - aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); + aw_dev = devm_kzalloc_obj(&i2c->dev, *aw_dev); if (!aw_dev) return -ENOMEM; aw88399->aw_pa = aw_dev; diff --git a/sound/soc/codecs/aw88399.c b/sound/soc/codecs/aw88399.c index c398f66a526255..1275ac601bcb00 100644 --- a/sound/soc/codecs/aw88399.c +++ b/sound/soc/codecs/aw88399.c @@ -760,7 +760,7 @@ static int aw88399_i2c_probe(struct i2c_client *i2c) if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) return dev_err_probe(&i2c->dev, -ENXIO, "check_functionality failed"); - aw88399 = devm_kzalloc(&i2c->dev, sizeof(*aw88399), GFP_KERNEL); + aw88399 = devm_kzalloc_obj(&i2c->dev, *aw88399); if (!aw88399) return -ENOMEM; diff --git a/sound/soc/codecs/bd28623.c b/sound/soc/codecs/bd28623.c index 07e7bd79c8b07c..2c454de1bfdae1 100644 --- a/sound/soc/codecs/bd28623.c +++ b/sound/soc/codecs/bd28623.c @@ -182,7 +182,7 @@ static int bd28623_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int i, ret; - bd = devm_kzalloc(&pdev->dev, sizeof(struct bd28623_priv), GFP_KERNEL); + bd = devm_kzalloc_obj(&pdev->dev, struct bd28623_priv); if (!bd) return -ENOMEM; diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c index 0e7c05f5bab607..6a11fcea6e6ec5 100644 --- a/sound/soc/codecs/cpcap.c +++ b/sound/soc/codecs/cpcap.c @@ -1763,7 +1763,7 @@ static int cpcap_codec_probe(struct platform_device *pdev) platform_device_set_of_node(pdev, codec_node); - cpcap = devm_kzalloc(&pdev->dev, sizeof(*cpcap), GFP_KERNEL); + cpcap = devm_kzalloc_obj(&pdev->dev, *cpcap); if (!cpcap) return -ENOMEM; diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c index 1148e37e29ceef..b6f7016a324a8c 100644 --- a/sound/soc/codecs/cros_ec_codec.c +++ b/sound/soc/codecs/cros_ec_codec.c @@ -971,7 +971,7 @@ static int cros_ec_codec_platform_probe(struct platform_device *pdev) const __be32 *regaddr_p; #endif - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c index 8288fb6d50be13..bb2d1046cd7f27 100644 --- a/sound/soc/codecs/cs35l32.c +++ b/sound/soc/codecs/cs35l32.c @@ -352,7 +352,7 @@ static int cs35l32_i2c_probe(struct i2c_client *i2c_client) int ret, i, devid; unsigned int reg; - cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l32), GFP_KERNEL); + cs35l32 = devm_kzalloc_obj(&i2c_client->dev, *cs35l32); if (!cs35l32) return -ENOMEM; @@ -368,8 +368,7 @@ static int cs35l32_i2c_probe(struct i2c_client *i2c_client) if (pdata) { cs35l32->pdata = *pdata; } else { - pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c_client->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l33.c b/sound/soc/codecs/cs35l33.c index b8c19f17570197..40a3a7449a66de 100644 --- a/sound/soc/codecs/cs35l33.c +++ b/sound/soc/codecs/cs35l33.c @@ -1130,8 +1130,7 @@ static int cs35l33_i2c_probe(struct i2c_client *i2c_client) int ret, devid, i; unsigned int reg; - cs35l33 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l33_private), - GFP_KERNEL); + cs35l33 = devm_kzalloc_obj(&i2c_client->dev, struct cs35l33_private); if (!cs35l33) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l34.c b/sound/soc/codecs/cs35l34.c index a72be629a31e55..26ac3c2d6e9c13 100644 --- a/sound/soc/codecs/cs35l34.c +++ b/sound/soc/codecs/cs35l34.c @@ -980,7 +980,7 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client) int ret; unsigned int reg; - cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l34), GFP_KERNEL); + cs35l34 = devm_kzalloc_obj(&i2c_client->dev, *cs35l34); if (!cs35l34) return -ENOMEM; @@ -1016,8 +1016,7 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client) if (pdata) { cs35l34->pdata = *pdata; } else { - pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c_client->dev, *pdata); if (!pdata) { ret = -ENOMEM; goto err_regulator; diff --git a/sound/soc/codecs/cs35l35.c b/sound/soc/codecs/cs35l35.c index 302d838f4c440f..33b6bca407232b 100644 --- a/sound/soc/codecs/cs35l35.c +++ b/sound/soc/codecs/cs35l35.c @@ -1478,7 +1478,7 @@ static int cs35l35_i2c_probe(struct i2c_client *i2c_client) int ret; unsigned int reg; - cs35l35 = devm_kzalloc(dev, sizeof(struct cs35l35_private), GFP_KERNEL); + cs35l35 = devm_kzalloc_obj(dev, struct cs35l35_private); if (!cs35l35) return -ENOMEM; @@ -1507,8 +1507,7 @@ static int cs35l35_i2c_probe(struct i2c_client *i2c_client) if (pdata) { cs35l35->pdata = *pdata; } else { - pdata = devm_kzalloc(dev, sizeof(struct cs35l35_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct cs35l35_platform_data); if (!pdata) return -ENOMEM; if (i2c_client->dev.of_node) { diff --git a/sound/soc/codecs/cs35l36.c b/sound/soc/codecs/cs35l36.c index 266b95397873a4..207fdb60a4cec4 100644 --- a/sound/soc/codecs/cs35l36.c +++ b/sound/soc/codecs/cs35l36.c @@ -1754,7 +1754,7 @@ static int cs35l36_i2c_probe(struct i2c_client *i2c_client) int ret, irq_pol, chip_irq_pol, i; u32 reg_id, reg_revid, l37_id_reg; - cs35l36 = devm_kzalloc(dev, sizeof(struct cs35l36_private), GFP_KERNEL); + cs35l36 = devm_kzalloc_obj(dev, struct cs35l36_private); if (!cs35l36) return -ENOMEM; @@ -1782,8 +1782,7 @@ static int cs35l36_i2c_probe(struct i2c_client *i2c_client) if (pdata) { cs35l36->pdata = *pdata; } else { - pdata = devm_kzalloc(dev, sizeof(struct cs35l36_platform_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, struct cs35l36_platform_data); if (!pdata) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l41-i2c.c b/sound/soc/codecs/cs35l41-i2c.c index 23f59f3025bdca..4b19b3063ca48b 100644 --- a/sound/soc/codecs/cs35l41-i2c.c +++ b/sound/soc/codecs/cs35l41-i2c.c @@ -36,7 +36,7 @@ static int cs35l41_i2c_probe(struct i2c_client *client) struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(dev); const struct regmap_config *regmap_config = &cs35l41_regmap_i2c; - cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL); + cs35l41 = devm_kzalloc_obj(dev, struct cs35l41_private); if (!cs35l41) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c index 973713626ebd43..9e6bed22fbdb5d 100644 --- a/sound/soc/codecs/cs35l41-lib.c +++ b/sound/soc/codecs/cs35l41-lib.c @@ -823,7 +823,7 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap) u32 otp_val, otp_id_reg; u32 *otp_mem; - otp_mem = kmalloc_array(CS35L41_OTP_SIZE_WORDS, sizeof(*otp_mem), GFP_KERNEL); + otp_mem = kmalloc_objs(*otp_mem, CS35L41_OTP_SIZE_WORDS); if (!otp_mem) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l41-spi.c b/sound/soc/codecs/cs35l41-spi.c index f9b6bf7bea9c97..b1be6844128776 100644 --- a/sound/soc/codecs/cs35l41-spi.c +++ b/sound/soc/codecs/cs35l41-spi.c @@ -34,7 +34,7 @@ static int cs35l41_spi_probe(struct spi_device *spi) struct cs35l41_private *cs35l41; int ret; - cs35l41 = devm_kzalloc(&spi->dev, sizeof(struct cs35l41_private), GFP_KERNEL); + cs35l41 = devm_kzalloc_obj(&spi->dev, struct cs35l41_private); if (!cs35l41) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l45-i2c.c b/sound/soc/codecs/cs35l45-i2c.c index 3eba61e107a558..24d9697f77883b 100644 --- a/sound/soc/codecs/cs35l45-i2c.c +++ b/sound/soc/codecs/cs35l45-i2c.c @@ -19,7 +19,7 @@ static int cs35l45_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; int ret; - cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL); + cs35l45 = devm_kzalloc_obj(dev, struct cs35l45_private); if (!cs35l45) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l45-spi.c b/sound/soc/codecs/cs35l45-spi.c index 5f91472c3fd291..76f46dc5ab2c7f 100644 --- a/sound/soc/codecs/cs35l45-spi.c +++ b/sound/soc/codecs/cs35l45-spi.c @@ -19,7 +19,7 @@ static int cs35l45_spi_probe(struct spi_device *spi) struct device *dev = &spi->dev; int ret; - cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL); + cs35l45 = devm_kzalloc_obj(dev, struct cs35l45_private); if (cs35l45 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l45-tables.c b/sound/soc/codecs/cs35l45-tables.c index 554c8121a74f25..599415812bf50b 100644 --- a/sound/soc/codecs/cs35l45-tables.c +++ b/sound/soc/codecs/cs35l45-tables.c @@ -54,6 +54,18 @@ static const struct reg_default cs35l45_defaults[] = { { CS35L45_SYNC_TX_RX_ENABLES, 0x00000200 }, { CS35L45_SYNC_SW_TX_ID, 0x00000000 }, { CS35L45_BOOST_LPMODE_CFG, 0x00000002 }, + { CS35L45_BST_BPE_INST_THLD, 0x5A46321E }, + { CS35L45_BST_BPE_INST_ILIM, 0x3C140C04 }, + { CS35L45_BST_BPE_INST_ATK_RATE, 0x06060600 }, + { CS35L45_BST_BPE_INST_HOLD_TIME, 0x02020202 }, + { CS35L45_BST_BPE_INST_RLS_RATE, 0x06060606 }, + { CS35L45_BST_BPE_MISC_CONFIG, 0x00008000 }, + { CS35L45_BST_BPE_IL_LIM_THLD, 0x0006022C }, + { CS35L45_BST_BPE_IL_LIM_DLY, 0x0000040C }, + { CS35L45_BST_BPE_IL_LIM_ATK_RATE, 0x00000000 }, + { CS35L45_BST_BPE_IL_LIM_RLS_RATE, 0x00000000 }, + { CS35L45_BST_BPE_OUT_ATK_RATE, 0x00000002 }, + { CS35L45_BST_BPE_OUT_RLS_RATE, 0x00000002 }, { CS35L45_ASP_ENABLES1, 0x00000000 }, { CS35L45_ASP_CONTROL1, 0x00000028 }, { CS35L45_ASP_CONTROL2, 0x18180200 }, @@ -77,6 +89,12 @@ static const struct reg_default cs35l45_defaults[] = { { CS35L45_DSP1RX6_INPUT, 0x00000028 }, { CS35L45_DSP1RX7_INPUT, 0x0000003A }, { CS35L45_DSP1RX8_INPUT, 0x00000028 }, + { CS35L45_BPE_INST_THLD, 0x5A46321E }, + { CS35L45_BPE_INST_ATTN, 0x060C1218 }, + { CS35L45_BPE_INST_ATK_RATE, 0x06060606 }, + { CS35L45_BPE_INST_HOLD_TIME, 0x02020202 }, + { CS35L45_BPE_INST_RLS_RATE, 0x05050505 }, + { CS35L45_BPE_MISC_CONFIG, 0x0000005A }, { CS35L45_LDPM_CONFIG, 0x00003636 }, { CS35L45_AMP_PCM_CONTROL, 0x00100000 }, { CS35L45_AMP_GAIN, 0x00002300 }, @@ -137,6 +155,18 @@ static bool cs35l45_readable_reg(struct device *dev, unsigned int reg) case CS35L45_WKI2C_CTL: case CS35L45_PWRMGT_STS: case CS35L45_REFCLK_INPUT: + case CS35L45_BST_BPE_INST_THLD: + case CS35L45_BST_BPE_INST_ILIM: + case CS35L45_BST_BPE_INST_ATK_RATE: + case CS35L45_BST_BPE_INST_HOLD_TIME: + case CS35L45_BST_BPE_INST_RLS_RATE: + case CS35L45_BST_BPE_MISC_CONFIG: + case CS35L45_BST_BPE_IL_LIM_THLD: + case CS35L45_BST_BPE_IL_LIM_DLY: + case CS35L45_BST_BPE_IL_LIM_ATK_RATE: + case CS35L45_BST_BPE_IL_LIM_RLS_RATE: + case CS35L45_BST_BPE_OUT_ATK_RATE: + case CS35L45_BST_BPE_OUT_RLS_RATE: case CS35L45_GLOBAL_SAMPLE_RATE: case CS35L45_SYNC_TX_RX_ENABLES: case CS35L45_SYNC_SW_TX_ID: @@ -164,6 +194,12 @@ static bool cs35l45_readable_reg(struct device *dev, unsigned int reg) case CS35L45_DSP1RX6_INPUT: case CS35L45_DSP1RX7_INPUT: case CS35L45_DSP1RX8_INPUT: + case CS35L45_BPE_INST_THLD: + case CS35L45_BPE_INST_ATTN: + case CS35L45_BPE_INST_ATK_RATE: + case CS35L45_BPE_INST_HOLD_TIME: + case CS35L45_BPE_INST_RLS_RATE: + case CS35L45_BPE_MISC_CONFIG: case CS35L45_HVLV_CONFIG: case CS35L45_LDPM_CONFIG: case CS35L45_AMP_PCM_CONTROL: @@ -392,3 +428,62 @@ int cs35l45_get_ldpm_delay(u32 delay_ms) return -EINVAL; } EXPORT_SYMBOL_NS_GPL(cs35l45_get_ldpm_delay, "SND_SOC_CS35L45"); + +static const u32 cs35l45_bpe_hold_times_us[] = { + 0, 250, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000, 500000, 1000000, 2500000, + 5000000, 10000000, +}; + +int cs35l45_bpe_pack_hold_times(u32 *hold_times, u32 *packed_code) +{ + int i, j; + + for (i = 0; i < CS35L45_BPE_NUM_LEVELS; i++) { + for (j = 0; j < ARRAY_SIZE(cs35l45_bpe_hold_times_us); j++) + if (hold_times[i] == cs35l45_bpe_hold_times_us[j]) + break; + + if (j == ARRAY_SIZE(cs35l45_bpe_hold_times_us)) + return -EINVAL; + + *packed_code |= CS35L45_BPE_PACK_CODE(j, i); + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cs35l45_bpe_pack_hold_times, "SND_SOC_CS35L45"); + +static const char * const cs35l45_bpe_attenuation_props[] = { + [BPE_MODE_LOGARITHMIC] = "cirrus,amplifier-bpe-attenuation-levels-db", + [BPE_MODE_LINEAR_VOLTAGE] = "cirrus,amplifier-bpe-attenuation-levels-microvolt", + [BPE_MODE_LINEAR_POWER] = "cirrus,amplifier-bpe-attenuation-levels-microwatt", +}; + +const char *cs35l45_bpe_get_attn_prop(const enum bpe_modes mode) +{ + return cs35l45_bpe_attenuation_props[mode]; +} +EXPORT_SYMBOL_NS_GPL(cs35l45_bpe_get_attn_prop, "SND_SOC_CS35L45"); + +static const u32 cs35l45_bst_bpe_hold_times_us[] = { + 0, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, +}; + +int cs35l45_bst_bpe_pack_hold_times(const u32 *hold_times, u32 *packed_code) +{ + int i, j; + + for (i = 0; i < CS35L45_BST_BPE_NUM_LEVELS; i++) { + for (j = 0; j < ARRAY_SIZE(cs35l45_bst_bpe_hold_times_us); j++) + if (hold_times[i] == cs35l45_bst_bpe_hold_times_us[j]) + break; + + if (j == ARRAY_SIZE(cs35l45_bst_bpe_hold_times_us)) + return -EINVAL; + + *packed_code |= CS35L45_BST_BPE_PACK_CODE(j, i); + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cs35l45_bst_bpe_pack_hold_times, "SND_SOC_CS35L45"); diff --git a/sound/soc/codecs/cs35l45.c b/sound/soc/codecs/cs35l45.c index 064ee612f05ef8..602d9828eb6bf3 100644 --- a/sound/soc/codecs/cs35l45.c +++ b/sound/soc/codecs/cs35l45.c @@ -1148,6 +1148,599 @@ static void cs35l45_apply_sync_property_config(struct cs35l45_private *cs35l45) CS35L45_SYNC_SW_TXID_MASK, val); } +static int cs35l45_bpe_read_array(struct cs35l45_private *cs35l45, const char *property, + u32 *values, size_t count) +{ + int num_values, ret; + + if (!device_property_present(cs35l45->dev, property)) + return dev_err_probe(cs35l45->dev, -EINVAL, "Missing %s\n", property); + + num_values = device_property_count_u32(cs35l45->dev, property); + if (num_values < 0) + return dev_err_probe(cs35l45->dev, num_values, "Failed to count %s\n", property); + + if (num_values != count) + return dev_err_probe(cs35l45->dev, -EINVAL, "%s must contain exactly %zu values\n", + property, count); + + ret = device_property_read_u32_array(cs35l45->dev, property, values, count); + if (ret) + return dev_err_probe(cs35l45->dev, ret, "Failed to read %s\n", property); + + return 0; +} + +static int cs35l45_bpe_set_rls_rate(struct cs35l45_private *cs35l45) +{ + u32 values[CS35L45_BPE_NUM_LEVELS]; + u32 packed = 0; + int i, ret; + + ret = cs35l45_bpe_read_array(cs35l45, "cirrus,amplifier-bpe-release-rates", values, + ARRAY_SIZE(values)); + if (ret) + return ret; + + for (i = 0; i < CS35L45_BPE_NUM_LEVELS; i++) { + if (values[i] > CS35L45_BPE_INST_RLS_RATE_MAX) { + dev_err(cs35l45->dev, "invalid ABPE release rate at level %d\n", + NUM_BPE_MODE - i); + return -EINVAL; + } + + packed |= CS35L45_BPE_PACK_CODE(values[i], i); + } + + return regmap_write(cs35l45->regmap, CS35L45_BPE_INST_RLS_RATE, packed); +} + +static int cs35l45_bpe_set_hold_times(struct cs35l45_private *cs35l45) +{ + u32 values[CS35L45_BPE_NUM_LEVELS]; + u32 packed = 0; + int ret; + + ret = cs35l45_bpe_read_array(cs35l45, "cirrus,amplifier-bpe-hold-times-us", values, + ARRAY_SIZE(values)); + if (ret) + return ret; + + ret = cs35l45_bpe_pack_hold_times(values, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BPE_INST_HOLD_TIME, packed); +} + +static int cs35l45_bpe_set_atk_rate(struct cs35l45_private *cs35l45) +{ + u32 values[CS35L45_BPE_NUM_LEVELS]; + u32 packed = 0; + int i, ret; + + ret = cs35l45_bpe_read_array(cs35l45, "cirrus,amplifier-bpe-attack-rates", values, + ARRAY_SIZE(values)); + if (ret) + return ret; + + for (i = 0; i < CS35L45_BPE_NUM_LEVELS; i++) { + if (values[i] > CS35L45_BPE_INST_ATK_RATE_MAX) { + dev_err(cs35l45->dev, "invalid ABPE attack rate at level %d\n", + NUM_BPE_MODE - i); + return -EINVAL; + } + + packed |= CS35L45_BPE_PACK_CODE(values[i], i); + } + + return regmap_write(cs35l45->regmap, CS35L45_BPE_INST_ATK_RATE, packed); +} + +static int cs35l45_bpe_set_attn(struct cs35l45_private *cs35l45, const enum bpe_modes mode) +{ + u32 values[CS35L45_BPE_NUM_LEVELS]; + const char *prop_name; + u32 code, packed = 0; + int i, ret; + + prop_name = cs35l45_bpe_get_attn_prop(mode); + ret = cs35l45_bpe_read_array(cs35l45, prop_name, values, ARRAY_SIZE(values)); + if (ret) + return ret; + + for (i = 0; i < CS35L45_BPE_NUM_LEVELS; i++) { + switch (mode) { + case BPE_MODE_LOGARITHMIC: + if (values[i] > CS35L45_BPE_INST_ATTN_LOG_MAX_DB) + return -EINVAL; + code = values[i] * 2; + break; + case BPE_MODE_LINEAR_VOLTAGE: + if (!in_range(values[i], CS35L45_BPE_INST_ATTN_VOLT_MIN_UV, + CS35L45_BPE_INST_ATTN_VOLT_LEN_UV)) + return -EINVAL; + code = (CS35L45_BPE_INST_ATTN_VOLT_MAX_UV - values[i]) / + CS35L45_BPE_INST_ATTN_STEP; + break; + case BPE_MODE_LINEAR_POWER: + if (!in_range(values[i], CS35L45_BPE_INST_ATTN_POWER_MIN_UW, + CS35L45_BPE_INST_ATTN_POWER_LEN_UW)) + return -EINVAL; + code = (CS35L45_BPE_INST_ATTN_POWER_MAX_UW - values[i]) / + CS35L45_BPE_INST_ATTN_STEP; + break; + default: + return -EINVAL; + } + + packed |= CS35L45_BPE_PACK_CODE(code, i); + } + + return regmap_write(cs35l45->regmap, CS35L45_BPE_INST_ATTN, packed); +} + +static int cs35l45_bpe_set_thld(struct cs35l45_private *cs35l45) +{ + u32 values[CS35L45_BPE_NUM_LEVELS]; + u32 code, packed = 0; + int i, ret; + + ret = cs35l45_bpe_read_array(cs35l45, "cirrus,amplifier-bpe-thresholds-microvolt", values, + ARRAY_SIZE(values)); + if (ret) + return ret; + + for (i = 0; i < CS35L45_BPE_NUM_LEVELS; i++) { + if (!in_range(values[i], CS35L45_BPE_INST_THLD_MIN_UV, + CS35L45_BPE_INST_THLD_LEN_UV)) { + dev_err(cs35l45->dev, "invalid ABPE threshold at level %d\n", + NUM_BPE_MODE - i); + return -EINVAL; + } + + code = (values[i] - CS35L45_BPE_INST_THLD_MIN_UV) / CS35L45_BPE_INST_THLD_STEP_UV; + packed |= CS35L45_BPE_PACK_CODE(code, i); + } + + return regmap_write(cs35l45->regmap, CS35L45_BPE_INST_THLD, packed); +} + +static int cs35l45_bpe_set_mode(struct cs35l45_private *cs35l45, enum bpe_modes *mode) +{ + const char *prop; + int i, ret; + + ret = device_property_read_u32(cs35l45->dev, "cirrus,amplifier-bpe-response-mode", + (u32 *)mode); + if (ret || *mode >= NUM_BPE_MODE) { + dev_err(cs35l45->dev, "invalid ABPE response mode\n"); + return -EINVAL; + } + + for (i = 0; i < NUM_BPE_MODE; i++) { + prop = cs35l45_bpe_get_attn_prop(i); + + if (i != *mode && device_property_present(cs35l45->dev, prop)) { + dev_err(cs35l45->dev, "ABPE attenuation property does not match mode\n"); + return -EINVAL; + } + } + + return regmap_update_bits(cs35l45->regmap, CS35L45_BPE_MISC_CONFIG, + CS35L45_BPE_MODE_SEL_MASK, + FIELD_PREP(CS35L45_BPE_MODE_SEL_MASK, *mode)); +} + +static int cs35l45_apply_abpe_config(struct cs35l45_private *cs35l45) +{ + enum bpe_modes mode; + int ret; + + if (!device_property_read_bool(cs35l45->dev, "cirrus,amplifier-bpe-enable")) + return 0; + + ret = cs35l45_bpe_set_mode(cs35l45, &mode); + if (ret) + return ret; + + ret = cs35l45_bpe_set_thld(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bpe_set_attn(cs35l45, mode); + if (ret) + return ret; + + ret = cs35l45_bpe_set_atk_rate(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bpe_set_hold_times(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bpe_set_rls_rate(cs35l45); + if (ret) + return ret; + + return regmap_set_bits(cs35l45->regmap, CS35L45_BLOCK_ENABLES2, CS35L45_ABPE_EN_MASK); +} + +static int cs35l45_bst_bpe_pack_array(struct cs35l45_private *cs35l45, const char *property, + size_t count, unsigned int first_lane, u32 min, u32 max, + u32 step, u32 *packed) +{ + u32 code, values[CS35L45_BST_BPE_NUM_LEVELS]; + unsigned int i; + int ret; + + if (!step || (first_lane + count) > ARRAY_SIZE(values)) + return -EINVAL; + + ret = cs35l45_bpe_read_array(cs35l45, property, values, count); + if (ret < 0) + return ret; + + for (i = 0; i < count; i++) { + if (values[i] < min || values[i] > max) + return dev_err_probe(cs35l45->dev, -EINVAL, + "Invalid %s value %u at index %u\n", + property, values[i], i); + + code = (values[i] - min) / step; + + *packed |= CS35L45_BST_BPE_PACK_CODE(code, first_lane + i); + } + + return 0; +} + +static int cs35l45_bst_bpe_pack_scalar(struct cs35l45_private *cs35l45, const char *property, + u32 field_mask, unsigned int shift, u32 min, u32 max, + u32 step, u32 *packed) +{ + u32 value, code; + int ret; + + if (!device_property_present(cs35l45->dev, property)) + return -EINVAL; + + ret = device_property_read_u32(cs35l45->dev, property, &value); + if (ret) + return dev_err_probe(cs35l45->dev, ret, "Failed to read %s\n", property); + + if (!step || value < min || value > max) + return dev_err_probe(cs35l45->dev, -EINVAL, "Invalid %s value %u\n", + property, value); + + code = (value - min) / step; + if (code > field_mask >> shift) + return dev_err_probe(cs35l45->dev, -EINVAL, + "%s value %u does not fit its field\n", property, value); + + *packed |= code << shift; + + return 0; +} + +static int cs35l45_bst_bpe_set_inst_thld(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-battery-thresholds-microvolt", + CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS, 0, + CS35L45_BST_BPE_INST_THLD_MIN_UV, + CS35L45_BST_BPE_INST_THLD_MAX_UV, + CS35L45_BST_BPE_INST_THLD_STEP_UV, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_INST_THLD, packed); +} + +static int cs35l45_bst_bpe_set_inst_ilim(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-battery-limits-microamp", + CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS, 0, + CS35L45_BST_BPE_INST_ILIM_MIN_UA, + CS35L45_BST_BPE_INST_ILIM_MAX_UA, + CS35L45_BST_BPE_INST_ILIM_STEP_UA, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_INST_ILIM, packed); +} + +static int cs35l45_bst_bpe_set_inst_atk_rate(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-battery-attack-rates", + CS35L45_BST_BPE_NUM_VOLTAGE_ATTACK_LEVELS, 1, 0, + CS35L45_BST_BPE_ATTACK_RATE_3P90625MA_PER_US, 1, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_INST_ATK_RATE, packed); +} + +static int cs35l45_bst_bpe_set_inst_hold_time(struct cs35l45_private *cs35l45) +{ + u32 values[CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS]; + u32 packed = 0; + int ret; + + ret = cs35l45_bpe_read_array(cs35l45, "cirrus,boost-bpe-battery-hold-times-us", values, + ARRAY_SIZE(values)); + if (ret < 0) + return ret; + + ret = cs35l45_bst_bpe_pack_hold_times(values, &packed); + if (ret) + return dev_err_probe(cs35l45->dev, ret, "Invalid Boost BPE hold time\n"); + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_INST_HOLD_TIME, packed); +} + +static int cs35l45_bst_bpe_set_inst_rls_rate(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-battery-release-rates", + CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS, 0, 0, + CS35L45_BST_BPE_RELEASE_RATE_0P001907MA_PER_US, 1, + &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_INST_RLS_RATE, packed); +} + +static int cs35l45_bst_bpe_set_out_atk_rate(struct cs35l45_private *cs35l45) +{ + u32 value; + int ret; + + ret = device_property_read_u32(cs35l45->dev, "cirrus,boost-bpe-output-attack-rate", + &value); + if (ret) + return ret; + + if (value > CS35L45_BST_BPE_ATTACK_RATE_3P90625MA_PER_US) + return -EINVAL; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_OUT_ATK_RATE, value); +} + +static int cs35l45_bst_bpe_set_out_rls_rate(struct cs35l45_private *cs35l45) +{ + u32 value; + int ret; + + ret = device_property_read_u32(cs35l45->dev, "cirrus,boost-bpe-output-release-rate", + &value); + if (ret) + return ret; + + if (value > CS35L45_BST_BPE_RELEASE_RATE_0P001907MA_PER_US) + return -EINVAL; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_OUT_RLS_RATE, value); +} + +static int cs35l45_bst_bpe_set_il_lim_thld(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_scalar(cs35l45, "cirrus,boost-bpe-inductor-threshold-microamp", + CS35L45_BST_BPE_IL_LIM1_THLD_MASK, + CS35L45_BST_BPE_IL_LIM1_THLD_SHIFT, + CS35L45_BST_BPE_IL_LIM_THLD_MIN_UA, + CS35L45_BST_BPE_IL_LIM_THLD_MAX_UA, + CS35L45_BST_BPE_IL_LIM_THLD_STEP_UA, &packed); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, + "cirrus,boost-bpe-inductor-threshold-deltas-microamp", + CS35L45_BST_BPE_NUM_CURRENT_LEVELS, 1, + CS35L45_BST_BPE_IL_LIM_THLD_DEL_MIN_UA, + CS35L45_BST_BPE_IL_LIM_THLD_DEL_MAX_UA, + CS35L45_BST_BPE_IL_LIM_THLD_DEL_STEP_UA, &packed); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_pack_scalar(cs35l45, + "cirrus,boost-bpe-inductor-threshold-hysteresis-microamp", + CS35L45_BST_BPE_IL_LIM_THLD_HYST_MASK, + CS35L45_BST_BPE_IL_LIM_THLD_HYST_SHIFT, + CS35L45_BST_BPE_IL_LIM_THLD_HYST_MIN_UA, + CS35L45_BST_BPE_IL_LIM_THLD_HYST_MAX_UA, + CS35L45_BST_BPE_IL_LIM_THLD_HYST_STEP_UA, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_IL_LIM_THLD, packed); +} + +static int cs35l45_bst_bpe_set_il_lim_dly(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_scalar(cs35l45, "cirrus,boost-bpe-inductor-delay-hysteresis-us", + CS35L45_BST_BPE_IL_LIM_DLY_HYST_MASK, + CS35L45_BST_BPE_IL_LIM_DLY_HYST_SHIFT, + CS35L45_BST_BPE_IL_LIM_DLY_HYST_MIN_US, + CS35L45_BST_BPE_IL_LIM_DLY_HYST_MAX_US, + CS35L45_BST_BPE_IL_LIM_DLY_HYST_STEP_US, &packed); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-inductor-delays-ms", + CS35L45_BST_BPE_NUM_CURRENT_LEVELS, 0, + CS35L45_BST_BPE_IL_LIM_DLY_MIN_MS, + CS35L45_BST_BPE_IL_LIM_DLY_MAX_MS, + CS35L45_BST_BPE_IL_LIM_DLY_STEP_MS, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_IL_LIM_DLY, packed); +} + +static int cs35l45_bst_bpe_set_il_lim_atk_rate(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-inductor-attack-rates", + CS35L45_BST_BPE_NUM_CURRENT_LEVELS, 0, 0, + CS35L45_BST_BPE_ATTACK_RATE_3P90625MA_PER_US, 1, &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_IL_LIM_ATK_RATE, packed); +} + +static int cs35l45_bst_bpe_set_il_lim_rls_rate(struct cs35l45_private *cs35l45) +{ + u32 packed = 0; + int ret; + + ret = cs35l45_bst_bpe_pack_array(cs35l45, "cirrus,boost-bpe-inductor-release-rates", + CS35L45_BST_BPE_NUM_CURRENT_LEVELS, 0, 0, + CS35L45_BST_BPE_RELEASE_RATE_0P001907MA_PER_US, 1, + &packed); + if (ret) + return ret; + + return regmap_write(cs35l45->regmap, CS35L45_BST_BPE_IL_LIM_RLS_RATE, packed); +} + +static int cs35l45_bst_bpe_set_mode(struct cs35l45_private *cs35l45, u32 *output_mode) +{ + u32 release_mode, mask, packed; + int ret; + + ret = device_property_read_u32(cs35l45->dev, "cirrus,boost-bpe-output-operating-mode", + output_mode); + if (ret) + return dev_err_probe(cs35l45->dev, ret, "Failed to read boost BPE op mode\n"); + + if ((*output_mode != CS35L45_BST_BPE_OUTPUT_MODE_BOTH) && + (*output_mode != CS35L45_BST_BPE_OUTPUT_MODE_VOLTAGE_ONLY)) + return dev_err_probe(cs35l45->dev, -EINVAL, "Invalid boost BPE op mode found\n"); + + mask = CS35L45_BST_BPE_OUT_OPMODE_SEL_MASK; + packed = FIELD_PREP(CS35L45_BST_BPE_OUT_OPMODE_SEL_MASK, *output_mode); + + if (*output_mode == CS35L45_BST_BPE_OUTPUT_MODE_BOTH) { + ret = device_property_read_u32(cs35l45->dev, + "cirrus,boost-bpe-inductor-release-mode", + &release_mode); + if (ret) + return dev_err_probe(cs35l45->dev, ret, + "Failed to read inductor response release mode\n"); + + if ((release_mode != CS35L45_BST_BPE_IL_RELEASE_MODE_INSTANT) && + (release_mode != CS35L45_BST_BPE_IL_RELEASE_MODE_COUNTER)) + return dev_err_probe(cs35l45->dev, -EINVAL, + "Invalid boost BPE inductor current release mode\n"); + + mask |= CS35L45_BST_BPE_IL_LIM_MODE_MASK; + packed |= FIELD_PREP(CS35L45_BST_BPE_IL_LIM_MODE_MASK, release_mode); + } + + return regmap_update_bits(cs35l45->regmap, CS35L45_BST_BPE_MISC_CONFIG, mask, packed); +} + +static int cs35l45_bst_bpe_set_il_lim_limiter(struct cs35l45_private *cs35l45) +{ + int ret; + + ret = cs35l45_bst_bpe_set_il_lim_thld(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_il_lim_dly(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_il_lim_atk_rate(cs35l45); + if (ret) + return ret; + + return cs35l45_bst_bpe_set_il_lim_rls_rate(cs35l45); +} + +static int cs35l45_bst_bpe_set_inst_limiter(struct cs35l45_private *cs35l45) +{ + int ret; + + ret = cs35l45_bst_bpe_set_inst_thld(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_inst_ilim(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_inst_atk_rate(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_inst_hold_time(cs35l45); + if (ret) + return ret; + + return cs35l45_bst_bpe_set_inst_rls_rate(cs35l45); +} + +static int cs35l45_apply_boost_bpe_config(struct cs35l45_private *cs35l45) +{ + u32 output_mode; + int ret; + + if (!device_property_read_bool(cs35l45->dev, "cirrus,boost-bpe-enable")) + return 0; + + ret = cs35l45_bst_bpe_set_mode(cs35l45, &output_mode); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_inst_limiter(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_out_atk_rate(cs35l45); + if (ret) + return ret; + + ret = cs35l45_bst_bpe_set_out_rls_rate(cs35l45); + if (ret) + return ret; + + if (output_mode == CS35L45_BST_BPE_OUTPUT_MODE_BOTH) { + ret = cs35l45_bst_bpe_set_il_lim_limiter(cs35l45); + if (ret) + return ret; + } + + ret = regmap_set_bits(cs35l45->regmap, CS35L45_BLOCK_ENABLES2, CS35L45_BBPE_EN_MASK); + if (ret) + return dev_err_probe(cs35l45->dev, ret, "Failed to enable Boost BPE\n"); + + return 0; +} + static int cs35l45_apply_ldpm_config(struct cs35l45_private *cs35l45) { char prop_name[CS35L45_LDPM_PROP_NAME_MAX]; @@ -1299,10 +1892,18 @@ static int cs35l45_apply_property_config(struct cs35l45_private *cs35l45) val << CS35L45_ASP_DOUT_HIZ_CTRL_SHIFT); } + ret = cs35l45_apply_boost_bpe_config(cs35l45); + if (ret < 0) + return ret; + ret = cs35l45_apply_ldpm_config(cs35l45); if (ret < 0) return ret; + ret = cs35l45_apply_abpe_config(cs35l45); + if (ret < 0) + return ret; + return 0; } diff --git a/sound/soc/codecs/cs35l45.h b/sound/soc/codecs/cs35l45.h index 5014c765adcb09..8c94a7f42c650c 100644 --- a/sound/soc/codecs/cs35l45.h +++ b/sound/soc/codecs/cs35l45.h @@ -41,6 +41,18 @@ #define CS35L45_BOOST_LPMODE_CFG 0x00003810 #define CS35L45_BOOST_DCM_CFG 0x0000380C #define CS35L45_BOOST_OV_CFG 0x0000382C +#define CS35L45_BST_BPE_INST_THLD 0x00003C00 +#define CS35L45_BST_BPE_INST_ILIM 0x00003C04 +#define CS35L45_BST_BPE_INST_ATK_RATE 0x00003C0C +#define CS35L45_BST_BPE_INST_HOLD_TIME 0x00003C10 +#define CS35L45_BST_BPE_INST_RLS_RATE 0x00003C14 +#define CS35L45_BST_BPE_MISC_CONFIG 0x00003C20 +#define CS35L45_BST_BPE_IL_LIM_THLD 0x00003C24 +#define CS35L45_BST_BPE_IL_LIM_DLY 0x00003C28 +#define CS35L45_BST_BPE_IL_LIM_ATK_RATE 0x00003C2C +#define CS35L45_BST_BPE_IL_LIM_RLS_RATE 0x00003C30 +#define CS35L45_BST_BPE_OUT_ATK_RATE 0x00003C34 +#define CS35L45_BST_BPE_OUT_RLS_RATE 0x00003C38 #define CS35L45_ASP_ENABLES1 0x00004800 #define CS35L45_ASP_CONTROL1 0x00004804 #define CS35L45_ASP_CONTROL2 0x00004808 @@ -64,6 +76,12 @@ #define CS35L45_DSP1RX6_INPUT 0x00004C54 #define CS35L45_DSP1RX7_INPUT 0x00004C58 #define CS35L45_DSP1RX8_INPUT 0x00004C5C +#define CS35L45_BPE_INST_THLD 0x00006064 +#define CS35L45_BPE_INST_ATTN 0x00006068 +#define CS35L45_BPE_INST_ATK_RATE 0x00006074 +#define CS35L45_BPE_INST_HOLD_TIME 0x00006080 +#define CS35L45_BPE_INST_RLS_RATE 0x00006084 +#define CS35L45_BPE_MISC_CONFIG 0x00006090 #define CS35L45_HVLV_CONFIG 0x00006400 #define CS35L45_LDPM_CONFIG 0x00006404 #define CS35L45_AMP_PCM_CONTROL 0x00007000 @@ -185,14 +203,46 @@ #define CS35L45_BST_ENABLE 0x02 /* BLOCK_ENABLES2 */ +#define CS35L45_BBPE_EN_SHIFT 13 +#define CS35L45_BBPE_EN_MASK BIT(13) #define CS35L45_ASP_EN_SHIFT 27 #define CS35L45_AMP_DRE_EN_SHIFT 20 #define CS35L45_AMP_DRE_EN_MASK BIT(20) +#define CS35L45_ABPE_EN_MASK BIT(12) #define CS35L45_SYNC_EN_SHIFT 8 #define CS35L45_SYNC_EN_MASK BIT(8) #define CS35L45_MEM_RDY_SHIFT 1 #define CS35L45_MEM_RDY_MASK BIT(1) +/* BPE_INST_THLD */ +#define CS35L45_BPE_INST_THLD_MIN_UV 2300000 +#define CS35L45_BPE_INST_THLD_MAX_UV 4500000 +#define CS35L45_BPE_INST_THLD_LEN_UV (CS35L45_BPE_INST_THLD_MAX_UV - \ + CS35L45_BPE_INST_THLD_MIN_UV + 1) +#define CS35L45_BPE_INST_THLD_STEP_UV 10000 + +/* BPE_INST_ATTN */ +#define CS35L45_BPE_INST_ATTN_LOG_MAX_DB 15 +#define CS35L45_BPE_INST_ATTN_LOG_SCALE 2 +#define CS35L45_BPE_INST_ATTN_VOLT_MIN_UV 187500 +#define CS35L45_BPE_INST_ATTN_VOLT_MAX_UV 1000000 +#define CS35L45_BPE_INST_ATTN_VOLT_LEN_UV (CS35L45_BPE_INST_ATTN_VOLT_MAX_UV - \ + CS35L45_BPE_INST_ATTN_VOLT_MIN_UV + 1) +#define CS35L45_BPE_INST_ATTN_POWER_MIN_UW 31250 +#define CS35L45_BPE_INST_ATTN_POWER_MAX_UW 1000000 +#define CS35L45_BPE_INST_ATTN_POWER_LEN_UW (CS35L45_BPE_INST_ATTN_POWER_MAX_UW - \ + CS35L45_BPE_INST_ATTN_POWER_MIN_UW + 1) +#define CS35L45_BPE_INST_ATTN_STEP 31250 + +/* BPE_INST_ATK_RATE */ +#define CS35L45_BPE_INST_ATK_RATE_MAX 8 + +/* BPE_INST_RLS_RATE */ +#define CS35L45_BPE_INST_RLS_RATE_MAX 14 + +/* BPE_MISC_CONFIG */ +#define CS35L45_BPE_MODE_SEL_MASK GENMASK(5, 4) + /* ERROR_RELEASE */ #define CS35L45_GLOBAL_ERR_RLS_MASK BIT(11) @@ -246,6 +296,126 @@ /* BOOST_LPMODE_CFG */ #define CS35L45_BST_LPMODE_SEL GENMASK(1, 0) +/* BST_BPE_INST_THLD */ +#define CS35L45_BST_BPE_INST_L3_THLD_SHIFT 24 +#define CS35L45_BST_BPE_INST_L3_THLD_MASK GENMASK(31, 24) +#define CS35L45_BST_BPE_INST_L2_THLD_SHIFT 16 +#define CS35L45_BST_BPE_INST_L2_THLD_MASK GENMASK(23, 16) +#define CS35L45_BST_BPE_INST_L1_THLD_SHIFT 8 +#define CS35L45_BST_BPE_INST_L1_THLD_MASK GENMASK(15, 8) +#define CS35L45_BST_BPE_INST_L0_THLD_SHIFT 0 +#define CS35L45_BST_BPE_INST_L0_THLD_MASK GENMASK(7, 0) + +#define CS35L45_BST_BPE_INST_THLD_MIN_UV 2300000 +#define CS35L45_BST_BPE_INST_THLD_MAX_UV 4500000 +#define CS35L45_BST_BPE_INST_THLD_STEP_UV 10000 + +/* BST_BPE_INST_ILIM */ +#define CS35L45_BST_BPE_INST_L4_ILIM_SHIFT 24 +#define CS35L45_BST_BPE_INST_L4_ILIM_MASK GENMASK(30, 24) +#define CS35L45_BST_BPE_INST_L3_ILIM_SHIFT 16 +#define CS35L45_BST_BPE_INST_L3_ILIM_MASK GENMASK(22, 16) +#define CS35L45_BST_BPE_INST_L2_ILIM_SHIFT 8 +#define CS35L45_BST_BPE_INST_L2_ILIM_MASK GENMASK(14, 8) +#define CS35L45_BST_BPE_INST_L1_ILIM_SHIFT 0 +#define CS35L45_BST_BPE_INST_L1_ILIM_MASK GENMASK(6, 0) + +#define CS35L45_BST_BPE_INST_ILIM_MIN_UA 250000 +#define CS35L45_BST_BPE_INST_ILIM_MAX_UA 4625000 +#define CS35L45_BST_BPE_INST_ILIM_STEP_UA 62500 + +/* BST_BPE_INST_ATK_RATE */ +#define CS35L45_BST_BPE_INST_L3_ATK_RATE_SHIFT 24 +#define CS35L45_BST_BPE_INST_L3_ATK_RATE_MASK GENMASK(26, 24) +#define CS35L45_BST_BPE_INST_L2_ATK_RATE_SHIFT 16 +#define CS35L45_BST_BPE_INST_L2_ATK_RATE_MASK GENMASK(18, 16) +#define CS35L45_BST_BPE_INST_L1_ATK_RATE_SHIFT 8 +#define CS35L45_BST_BPE_INST_L1_ATK_RATE_MASK GENMASK(10, 8) + +/* BST_BPE_INST_HOLD_TIME */ +#define CS35L45_BST_BPE_INST_L3_HOLD_TIME_SHIFT 24 +#define CS35L45_BST_BPE_INST_L3_HOLD_TIME_MASK GENMASK(27, 24) +#define CS35L45_BST_BPE_INST_L2_HOLD_TIME_SHIFT 16 +#define CS35L45_BST_BPE_INST_L2_HOLD_TIME_MASK GENMASK(19, 16) +#define CS35L45_BST_BPE_INST_L1_HOLD_TIME_SHIFT 8 +#define CS35L45_BST_BPE_INST_L1_HOLD_TIME_MASK GENMASK(11, 8) +#define CS35L45_BST_BPE_INST_L0_HOLD_TIME_SHIFT 0 +#define CS35L45_BST_BPE_INST_L0_HOLD_TIME_MASK GENMASK(3, 0) + +/* BST_BPE_INST_RLS_RATE */ +#define CS35L45_BST_BPE_INST_L3_RLS_RATE_SHIFT 24 +#define CS35L45_BST_BPE_INST_L3_RLS_RATE_MASK GENMASK(28, 24) +#define CS35L45_BST_BPE_INST_L2_RLS_RATE_SHIFT 16 +#define CS35L45_BST_BPE_INST_L2_RLS_RATE_MASK GENMASK(20, 16) +#define CS35L45_BST_BPE_INST_L1_RLS_RATE_SHIFT 8 +#define CS35L45_BST_BPE_INST_L1_RLS_RATE_MASK GENMASK(12, 8) +#define CS35L45_BST_BPE_INST_L0_RLS_RATE_SHIFT 0 +#define CS35L45_BST_BPE_INST_L0_RLS_RATE_MASK GENMASK(4, 0) + +/* BST_BPE_MISC_CONFIG */ +#define CS35L45_BST_BPE_IL_LIM_MODE_SHIFT 15 +#define CS35L45_BST_BPE_IL_LIM_MODE_MASK BIT(15) +#define CS35L45_BST_BPE_OUT_OPMODE_SEL_SHIFT 12 +#define CS35L45_BST_BPE_OUT_OPMODE_SEL_MASK GENMASK(13, 12) + +/* BST_BPE_IL_LIM_THLD */ +#define CS35L45_BST_BPE_IL_LIM_THLD_HYST_SHIFT 24 +#define CS35L45_BST_BPE_IL_LIM_THLD_HYST_MASK GENMASK(28, 24) +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL2_SHIFT 16 +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL2_MASK GENMASK(23, 16) +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL1_SHIFT 8 +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL1_MASK GENMASK(15, 8) +#define CS35L45_BST_BPE_IL_LIM1_THLD_SHIFT 0 +#define CS35L45_BST_BPE_IL_LIM1_THLD_MASK GENMASK(7, 0) + +#define CS35L45_BST_BPE_IL_LIM_THLD_MIN_UA 250000 +#define CS35L45_BST_BPE_IL_LIM_THLD_MAX_UA 4000000 +#define CS35L45_BST_BPE_IL_LIM_THLD_STEP_UA 62500 + +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL_MIN_UA 0 +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL_MAX_UA 3750000 +#define CS35L45_BST_BPE_IL_LIM_THLD_DEL_STEP_UA 62500 + +#define CS35L45_BST_BPE_IL_LIM_THLD_HYST_MIN_UA 0 +#define CS35L45_BST_BPE_IL_LIM_THLD_HYST_MAX_UA 968750 +#define CS35L45_BST_BPE_IL_LIM_THLD_HYST_STEP_UA 31250 + +/* BST_BPE_IL_LIM_DLY */ +#define CS35L45_BST_BPE_IL_LIM_DLY_HYST_SHIFT 16 +#define CS35L45_BST_BPE_IL_LIM_DLY_HYST_MASK GENMASK(20, 16) +#define CS35L45_BST_BPE_IL_LIM2_DLY_SHIFT 8 +#define CS35L45_BST_BPE_IL_LIM2_DLY_MASK GENMASK(15, 8) +#define CS35L45_BST_BPE_IL_LIM1_DLY_SHIFT 0 +#define CS35L45_BST_BPE_IL_LIM1_DLY_MASK GENMASK(7, 0) + +#define CS35L45_BST_BPE_IL_LIM_DLY_HYST_MIN_US 0 +#define CS35L45_BST_BPE_IL_LIM_DLY_HYST_MAX_US 992 +#define CS35L45_BST_BPE_IL_LIM_DLY_HYST_STEP_US 32 + +#define CS35L45_BST_BPE_IL_LIM_DLY_MIN_MS 0 +#define CS35L45_BST_BPE_IL_LIM_DLY_MAX_MS 100 +#define CS35L45_BST_BPE_IL_LIM_DLY_STEP_MS 1 + +/* BST_BPE_IL_LIM_ATK_RATE */ +#define CS35L45_BST_BPE_IL_LIM2_ATK_RATE_SHIFT 8 +#define CS35L45_BST_BPE_IL_LIM2_ATK_RATE_MASK GENMASK(10, 8) +#define CS35L45_BST_BPE_IL_LIM1_ATK_RATE_SHIFT 0 +#define CS35L45_BST_BPE_IL_LIM1_ATK_RATE_MASK GENMASK(2, 0) + +/* BST_BPE_IL_LIM_RLS_RATE */ +#define CS35L45_BST_BPE_IL_LIM2_RLS_RATE_SHIFT 8 +#define CS35L45_BST_BPE_IL_LIM2_RLS_RATE_MASK GENMASK(12, 8) +#define CS35L45_BST_BPE_IL_LIM1_RLS_RATE_SHIFT 0 +#define CS35L45_BST_BPE_IL_LIM1_RLS_RATE_MASK GENMASK(4, 0) + +/* BST_BPE_OUT_ATK_RATE */ +#define CS35L45_BST_BPE_OUT_ATK_RATE_SHIFT 0 +#define CS35L45_BST_BPE_OUT_ATK_RATE_MASK GENMASK(2, 0) + +/* BST_BPE_OUT_RLS_RATE */ +#define CS35L45_BST_BPE_OUT_RLS_RATE_SHIFT 0 +#define CS35L45_BST_BPE_OUT_RLS_RATE_MASK GENMASK(4, 0) + /* ASP_ENABLES_1 */ #define CS35L45_ASP_RX2_EN_SHIFT 17 #define CS35L45_ASP_RX1_EN_SHIFT 16 @@ -474,6 +644,13 @@ enum ldpm_groups { NUM_LDPM_GROUP, }; +enum bpe_modes { + BPE_MODE_LOGARITHMIC, + BPE_MODE_LINEAR_VOLTAGE, + BPE_MODE_LINEAR_POWER, + NUM_BPE_MODE, +}; + #define CS35L45_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ SNDRV_PCM_FMTBIT_S24_3LE| \ SNDRV_PCM_FMTBIT_S24_LE) @@ -485,6 +662,19 @@ enum ldpm_groups { #define CS35L45_LDPM_PROP_NAME_MAX 37 +#define CS35L45_BPE_NUM_LEVELS 4 + +#define CS35L45_BPE_PACK_CODE(_code, _idx) (_code << (24 - (8 * _idx))) + +#define CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS 4 +#define CS35L45_BST_BPE_NUM_VOLTAGE_ATTACK_LEVELS 3 +#define CS35L45_BST_BPE_NUM_CURRENT_LEVELS 2 +#define CS35L45_BST_BPE_NUM_LEVELS CS35L45_BST_BPE_NUM_VOLTAGE_LEVELS +#define CS35L45_BST_BPE_NUM_HOLD_TIMES 12 + +/* Boost BPE levels use ascending byte lanes; some arrays start at lane 1. */ +#define CS35L45_BST_BPE_PACK_CODE(_code, _idx) ((_code) << (8 * (_idx))) + /* * IRQs */ @@ -561,6 +751,9 @@ int cs35l45_apply_patch(struct cs35l45_private *cs35l45); int cs35l45_get_clk_freq_id(unsigned int freq); int cs35l45_get_ldpm_pcm_thld(int pcm_thld_db); int cs35l45_get_ldpm_delay(u32 delay_ms); +int cs35l45_bpe_pack_hold_times(u32 *hold_times, u32 *packed_code); +int cs35l45_bst_bpe_pack_hold_times(const u32 *hold_times, u32 *packed_code); +const char *cs35l45_bpe_get_attn_prop(const enum bpe_modes mode); int cs35l45_probe(struct cs35l45_private *cs35l45); void cs35l45_remove(struct cs35l45_private *cs35l45); diff --git a/sound/soc/codecs/cs35l56-i2c.c b/sound/soc/codecs/cs35l56-i2c.c index 5e69ddbe342a1d..0fcba61321ec1a 100644 --- a/sound/soc/codecs/cs35l56-i2c.c +++ b/sound/soc/codecs/cs35l56-i2c.c @@ -23,7 +23,7 @@ static int cs35l56_i2c_probe(struct i2c_client *client) const struct regmap_config *regmap_config; int ret; - cs35l56 = devm_kzalloc(dev, sizeof(struct cs35l56_private), GFP_KERNEL); + cs35l56 = devm_kzalloc_obj(dev, struct cs35l56_private); if (!cs35l56) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l56-sdw.c b/sound/soc/codecs/cs35l56-sdw.c index a49ad69644b5a1..770a5fcd843ff6 100644 --- a/sound/soc/codecs/cs35l56-sdw.c +++ b/sound/soc/codecs/cs35l56-sdw.c @@ -269,7 +269,7 @@ static int cs35l56_sdw_read_prop(struct sdw_slave *peripheral) if (ret == 0) prop->clk_stop_mode1 = !!clock_stop_1; - ports = devm_kcalloc(cs35l56->base.dev, 3, sizeof(*ports), GFP_KERNEL); + ports = devm_kzalloc_objs(cs35l56->base.dev, *ports, 3); if (!ports) return -ENOMEM; @@ -428,7 +428,7 @@ static int cs35l56_sdw_probe(struct sdw_slave *peripheral, const struct sdw_devi const struct regmap_config *regmap_config; int ret; - cs35l56 = devm_kzalloc(dev, sizeof(*cs35l56), GFP_KERNEL); + cs35l56 = devm_kzalloc_obj(dev, *cs35l56); if (!cs35l56) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l56-shared-test.c b/sound/soc/codecs/cs35l56-shared-test.c index 34bb3d44b51f10..4088a09495c2e4 100644 --- a/sound/soc/codecs/cs35l56-shared-test.c +++ b/sound/soc/codecs/cs35l56-shared-test.c @@ -31,6 +31,8 @@ struct cs35l56_shared_test_priv { struct regmap *registers; const struct regmap_config *regmap_config; unsigned int reg_offset; + bool hw_written; + bool asp_written; struct cs35l56_base *cs35l56_base; u8 applied_pad_pull_state[CS35L56_MAX_GPIO]; }; @@ -91,7 +93,7 @@ static int cs35l56_shared_test_mock_gpio_probe(struct faux_device *fdev) struct device *dev = &fdev->dev; int ret; - gpio_priv = devm_kzalloc(dev, sizeof(*gpio_priv), GFP_KERNEL); + gpio_priv = devm_kzalloc_obj(dev, *gpio_priv); if (!gpio_priv) return -ENOMEM; @@ -664,6 +666,145 @@ static void cs35l56_shared_test_regmap_defaults_readable(struct kunit *test) } } +static int cs35l56_shared_test_regmap_read_illegal(void *context, unsigned int reg, + unsigned int *val) +{ + kunit_fail_current_test("Unexpected regmap reg_read\n"); + + return -EPERM; +} + +static int cs35l56_shared_test_regmap_write_detect_asp_writes(void *context, unsigned int reg, + unsigned int val) +{ + struct cs35l56_shared_test_priv *priv = context; + + priv->hw_written = true; + reg -= priv->reg_offset; + + /* + * Check for writes to ASP config registers. Check the entire ASP address + * space, not only registers defined in cs35l56.h. + */ + if (reg >= 0x4800 && reg <= 0x48ff) + priv->asp_written = true; + + return 0; +} + +static const struct regmap_bus cs35l56_shared_test_asp_write_regmap_bus = { + .reg_read = cs35l56_shared_test_regmap_read_illegal, + .reg_write = cs35l56_shared_test_regmap_write_detect_asp_writes, +}; + +/* + * If cs35l56_set_asp_defaults() was not called the ASP config address space must + * not be written by a regcache_sync(). + */ +static void cs35l56_shared_test_regcache_sync_omits_asp_config(struct kunit *test) +{ + struct cs35l56_shared_test_priv *priv = test->priv; + struct regmap *regmap; + + /* Use the driver defaults and detect hardware writes to the ASP registers. */ + regmap = regmap_init(&priv->amp_dev->dev, &cs35l56_shared_test_asp_write_regmap_bus, + priv, priv->regmap_config); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, regmap); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, regmap_exit_wrapper, regmap)); + + /* Dirty the cache without modifying the ASP registers. */ + regcache_cache_only(regmap, true); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_1, 0)); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_2, 0)); + regcache_cache_only(regmap, false); + + KUNIT_ASSERT_EQ(test, false, priv->asp_written); + KUNIT_ASSERT_EQ(test, false, priv->hw_written); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(regmap)); + KUNIT_EXPECT_EQ(test, false, priv->asp_written); + KUNIT_EXPECT_EQ(test, true, priv->hw_written); + + priv->asp_written = false; + priv->hw_written = false; + regcache_cache_only(regmap, true); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_1, 0xffffffff)); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_2, 0xffffffff)); + regcache_cache_only(regmap, false); + + regcache_mark_dirty(regmap); + KUNIT_ASSERT_EQ(test, false, priv->asp_written); + KUNIT_ASSERT_EQ(test, false, priv->hw_written); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(regmap)); + KUNIT_EXPECT_EQ(test, false, priv->asp_written); + KUNIT_EXPECT_EQ(test, true, priv->hw_written); +} + +/* + * If cs35l56_set_asp_defaults() was called the ASP config registers must be + * written by a regcache_sync(). + */ +static void cs35l56_shared_test_regcache_sync_includes_asp_config(struct kunit *test) +{ + struct cs35l56_shared_test_priv *priv = test->priv; + struct regmap *regmap; + + /* Use the driver defaults and detect hardware writes to the ASP registers. */ + regmap = regmap_init(&priv->amp_dev->dev, &cs35l56_shared_test_asp_write_regmap_bus, + priv, priv->regmap_config); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, regmap); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, regmap_exit_wrapper, regmap)); + + priv->cs35l56_base->regmap = regmap; + KUNIT_ASSERT_EQ(test, 0, cs35l56_set_asp_defaults(priv->cs35l56_base)); + /* Ignore writes from applying defaults so only sync writes are detected. */ + priv->asp_written = false; + + /* Dirty the cache without modifying the ASP registers. */ + regcache_cache_only(regmap, true); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_1, 0)); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_2, 0)); + regcache_cache_only(regmap, false); + + KUNIT_ASSERT_EQ(test, false, priv->asp_written); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(regmap)); + KUNIT_ASSERT_EQ(test, true, priv->asp_written); + + priv->asp_written = false; + regcache_cache_only(regmap, true); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_1, 0xffffffff)); + KUNIT_ASSERT_EQ(test, 0, regmap_write(regmap, CS35L56_IRQ1_MASK_2, 0xffffffff)); + regcache_cache_only(regmap, false); + + regcache_mark_dirty(regmap); + KUNIT_ASSERT_EQ(test, false, priv->asp_written); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(regmap)); + KUNIT_ASSERT_EQ(test, true, priv->asp_written); +} + +/* + * cs35l56_set_asp_defaults() can be called while in cache-only and in that + * state does not write to hardware. + */ +static void cs35l56_shared_test_set_asp_defaults_cache_only(struct kunit *test) +{ + struct cs35l56_shared_test_priv *priv = test->priv; + struct regmap *regmap; + + regmap = regmap_init(&priv->amp_dev->dev, &cs35l56_shared_test_asp_write_regmap_bus, + priv, priv->regmap_config); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, regmap); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, regmap_exit_wrapper, regmap)); + + priv->cs35l56_base->regmap = regmap; + regcache_cache_only(regmap, true); + KUNIT_ASSERT_EQ(test, false, priv->hw_written); + KUNIT_ASSERT_EQ(test, 0, cs35l56_set_asp_defaults(priv->cs35l56_base)); + KUNIT_ASSERT_EQ(test, false, priv->hw_written); +} + static int cs35l56_shared_test_case_regmap_init(struct kunit *test, const struct regmap_config *regmap_config) { @@ -917,6 +1058,9 @@ static struct kunit_case cs35l56_shared_test_cases[] = { KUNIT_CASE(cs35l56_shared_test_sorted_regmap_defaults), KUNIT_CASE(cs35l56_shared_test_regmap_defaults_not_volatile), KUNIT_CASE(cs35l56_shared_test_regmap_defaults_readable), + KUNIT_CASE(cs35l56_shared_test_regcache_sync_omits_asp_config), + KUNIT_CASE(cs35l56_shared_test_regcache_sync_includes_asp_config), + KUNIT_CASE(cs35l56_shared_test_set_asp_defaults_cache_only), { } }; diff --git a/sound/soc/codecs/cs35l56-shared.c b/sound/soc/codecs/cs35l56-shared.c index b37f65cd4d336a..4d76f177792723 100644 --- a/sound/soc/codecs/cs35l56-shared.c +++ b/sound/soc/codecs/cs35l56-shared.c @@ -34,23 +34,19 @@ static const struct reg_sequence cs35l56_asp_patch[] = { { CS35L56_ASP1_ENABLES1, 0x00000000 }, { CS35L56_ASP1_CONTROL1, 0x00000028 }, { CS35L56_ASP1_CONTROL2, 0x18180200 }, - { CS35L56_ASP1_CONTROL3, 0x00000002 }, + { CS35L56_ASP1_CONTROL3, 0x00000003 }, { CS35L56_ASP1_FRAME_CONTROL1, 0x03020100 }, { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, }; -int cs35l56_set_asp_patch(struct cs35l56_base *cs35l56_base) +int cs35l56_set_asp_defaults(struct cs35l56_base *cs35l56_base) { - return regmap_register_patch(cs35l56_base->regmap, cs35l56_asp_patch, - ARRAY_SIZE(cs35l56_asp_patch)); + return regmap_multi_reg_write(cs35l56_base->regmap, cs35l56_asp_patch, + ARRAY_SIZE(cs35l56_asp_patch)); } -EXPORT_SYMBOL_NS_GPL(cs35l56_set_asp_patch, "SND_SOC_CS35L56_SHARED"); +EXPORT_SYMBOL_NS_GPL(cs35l56_set_asp_defaults, "SND_SOC_CS35L56_SHARED"); static const struct reg_sequence cs35l56_patch[] = { /* @@ -109,18 +105,6 @@ int cs35l56_set_patch(struct cs35l56_base *cs35l56_base) EXPORT_SYMBOL_NS_GPL(cs35l56_set_patch, "SND_SOC_CS35L56_SHARED"); static const struct reg_default cs35l56_reg_defaults[] = { - { CS35L56_ASP1_ENABLES1, 0x00000000 }, - { CS35L56_ASP1_CONTROL1, 0x00000028 }, - { CS35L56_ASP1_CONTROL2, 0x18180200 }, - { CS35L56_ASP1_CONTROL3, 0x00000002 }, - { CS35L56_ASP1_FRAME_CONTROL1, 0x03020100 }, - { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, - { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, - { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, { CS35L56_SWIRE_DP3_CH1_INPUT, 0x00000018 }, { CS35L56_SWIRE_DP3_CH2_INPUT, 0x00000019 }, { CS35L56_SWIRE_DP3_CH3_INPUT, 0x00000029 }, @@ -137,18 +121,6 @@ static const struct reg_default cs35l56_reg_defaults[] = { }; static const struct reg_default cs35l63_reg_defaults[] = { - { CS35L56_ASP1_ENABLES1, 0x00000000 }, - { CS35L56_ASP1_CONTROL1, 0x00000028 }, - { CS35L56_ASP1_CONTROL2, 0x18180200 }, - { CS35L56_ASP1_CONTROL3, 0x00000002 }, - { CS35L56_ASP1_FRAME_CONTROL1, 0x03020100 }, - { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, - { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, - { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, { CS35L56_SWIRE_DP3_CH1_INPUT, 0x00000018 }, { CS35L56_SWIRE_DP3_CH2_INPUT, 0x00000019 }, { CS35L56_SWIRE_DP3_CH3_INPUT, 0x00000029 }, diff --git a/sound/soc/codecs/cs35l56-spi.c b/sound/soc/codecs/cs35l56-spi.c index 21b18da9e73d1d..9be173184a9d78 100644 --- a/sound/soc/codecs/cs35l56-spi.c +++ b/sound/soc/codecs/cs35l56-spi.c @@ -20,7 +20,7 @@ static int cs35l56_spi_probe(struct spi_device *spi) struct cs35l56_private *cs35l56; int ret; - cs35l56 = devm_kzalloc(&spi->dev, sizeof(struct cs35l56_private), GFP_KERNEL); + cs35l56 = devm_kzalloc_obj(&spi->dev, struct cs35l56_private); if (!cs35l56) return -ENOMEM; diff --git a/sound/soc/codecs/cs35l56-test.c b/sound/soc/codecs/cs35l56-test.c index 124fe5e7550081..b422d19ba0b216 100644 --- a/sound/soc/codecs/cs35l56-test.c +++ b/sound/soc/codecs/cs35l56-test.c @@ -5,6 +5,7 @@ // Copyright (C) 2026 Cirrus Logic, Inc. and // Cirrus Logic International Semiconductor Ltd. +#include #include #include #include @@ -16,10 +17,16 @@ #include #include #include +#include +#include +#include +#include #include #include +#include #include #include +#include #include "cs35l56.h" KUNIT_DEFINE_ACTION_WRAPPER(faux_device_destroy_wrapper, faux_device_destroy, @@ -37,20 +44,41 @@ KUNIT_DEFINE_ACTION_WRAPPER(device_remove_software_node_wrapper, device_remove_software_node, struct device *) +KUNIT_DEFINE_ACTION_WRAPPER(cs35l56_remove_wrapper, cs35l56_remove, + struct cs35l56_private *) + +KUNIT_DEFINE_ACTION_WRAPPER(snd_soc_unregister_card_wrapper, snd_soc_unregister_card, + struct snd_soc_card *) + struct cs35l56_test_priv { struct faux_device *amp_dev; struct cs35l56_private *cs35l56_priv; + const struct regmap_config *regmap_config; + struct regmap *registers; const char *ssidexv2; bool read_onchip_spkid_called; bool configure_onchip_spkid_pads_called; + + bool asp_config_regs_written; + bool asp_mixer_regs_written; }; struct cs35l56_test_param { u8 type; u8 rev; + u16 feid; + u8 fev; + u32 function_type; + bool omit_feid; + bool omit_fev; + bool has_ssid; + int speaker_id; + const char *system_name; + int ret; + s32 spkid_gpios[4]; s32 spkid_pulls[4]; }; @@ -67,6 +95,231 @@ static const struct software_node *cs35l56_test_dev_and_af01_node_group[] = { NULL }; +/* Some mocked registers need default values for driver init to work */ +static const struct reg_default cs35l56_test_mock_reg_defaults[] = { + { CS35L56_OTPID, 0x00000003 }, + { CS35L56_IRQ1_STATUS, 0x00000000 }, + { CS35L56_IRQ1_MASK_1, 0x83ffffff }, + { CS35L56_IRQ1_MASK_8, 0xfc000fff }, + { CS35L56_DSP_VIRTUAL1_MBOX_1, 0x00000000 }, + { CS35L56_DIE_STS1, 0x00000000 }, + { CS35L56_DIE_STS2, 0x00000000 }, + { CS35L56_DSP_RESTRICT_STS1, 0x00000000 }, + { CS35L56_OTP_MEM_53, 0x00000000 }, + { CS35L56_OTP_MEM_54, 0x00000000 }, + { CS35L56_OTP_MEM_55, 0x00000000 }, + { CS35L56_DSP1_FW_VER, 0x00040710 }, + { CS35L63_PROTECTION_STATUS, 0x00000000 }, + { CS35L56_PROTECTION_STATUS, 0x00000000 }, +}; + +/* Trap the entire ASP address space, not only particular registers */ +static const struct range cs35l56_test_asp_config_registers_range = { + .start = 0x4800, + .end = 0x48ff, +}; + +static const struct range cs35l56_test_asp_mixer_registers_range = { + .start = CS35L56_ASP1TX1_INPUT, + .end = CS35L56_ASP1TX4_INPUT, +}; + +static int cs35l56_test_mock_registers_read(void *context, + const void *reg_buf, size_t reg_size, + void *val_buf, size_t val_size) +{ + struct kunit *test = context; + struct cs35l56_test_priv *priv = test->priv; + u8 *buf = val_buf; + unsigned int reg = get_unaligned_be32(reg_buf); + unsigned int val; + size_t i; + int ret; + + /* Don't use KUNIT_ASSERT, it would abort without releasing the regmap lock */ + if ((reg_size != sizeof(u32)) || (val_size % sizeof(u32))) { + kunit_fail_current_test("Illegal reg read args\n"); + return -EINVAL; + } + + if (priv->regmap_config) + reg -= priv->regmap_config->reg_base; + + switch (reg) { + case CS35L56_DSP_VIRTUAL1_MBOX_1: + /* MBOX must return 0 to indicate that the value was written */ + put_unaligned_be32(0, val_buf); + return 0; + case CS35L56_DSP1_HALO_STATE: + case CS35L63_DSP1_HALO_STATE: + case CS35L56_B2_DSP1_HALO_STATE: + /* Driver zeros this and we must simulate the firmware rewriting it */ + put_unaligned_be32(CS35L56_HALO_STATE_BOOT_DONE, buf); + return 0; + default: + break; + } + + for (i = 0; i < val_size; i += sizeof(u32), reg += sizeof(u32)) { + ret = regmap_read(priv->registers, reg, &val); + if (ret) + return ret; + + put_unaligned_be32(val, buf + i); + } + + return 0; +} + +static int cs35l56_test_mock_registers_write(void *context, const void *data, size_t count) +{ + struct kunit *test = context; + struct cs35l56_test_priv *priv = test->priv; + struct range addr_range; + unsigned int reg, val; + const u8 *buf = data; + size_t i; + int ret; + + /* Don't use KUNIT_ASSERT, it would abort without releasing the regmap lock */ + if ((count < 2 * sizeof(u32)) || (count % sizeof(u32))) { + kunit_fail_current_test("Illegal reg write args\n"); + return -EINVAL; + } + + reg = get_unaligned_be32(buf); + buf += sizeof(u32); + count -= sizeof(u32); + if (priv->regmap_config) + reg -= priv->regmap_config->reg_base; + + addr_range = DEFINE_RANGE(reg, reg + count - 1); + if (range_overlaps(&addr_range, &cs35l56_test_asp_config_registers_range)) + priv->asp_config_regs_written = true; + + if (range_overlaps(&addr_range, &cs35l56_test_asp_mixer_registers_range)) + priv->asp_mixer_regs_written = true; + + for (i = 0; i < count; i += sizeof(u32)) { + val = get_unaligned_be32(buf + i); + ret = regmap_write(priv->registers, reg + i, val); + if (ret) + return ret; + } + + return 0; +} + +static const struct regmap_bus cs35l56_test_mock_registers_regmap_bus = { + /* Always in cache-only so no handlers needed */ +}; + +static const struct regmap_config cs35l56_test_mock_registers_regmap_config = { + .name = "cs35l56_mock_registers", + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .max_register = CS35L56_DSP1_PMEM_5114, + .cache_type = REGCACHE_MAPLE, + .reg_defaults = cs35l56_test_mock_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(cs35l56_test_mock_reg_defaults), + .reg_format_endian = REGMAP_ENDIAN_BIG, + .val_format_endian = REGMAP_ENDIAN_BIG, +}; + +static const struct regmap_bus cs35l56_test_mock_registers_client_regmap_bus = { + .read = cs35l56_test_mock_registers_read, + .write = cs35l56_test_mock_registers_write, +}; + +/* Populate simulated register ranges with dummy values */ +static void cs35l56_test_fill_register_range(struct kunit *test, + const struct range *reg_range, + unsigned int fill_value) +{ + struct cs35l56_test_priv *priv = test->priv; + unsigned int addr; + + for (addr = reg_range->start; addr <= reg_range->end; addr += 4) + KUNIT_ASSERT_EQ(test, 0, regmap_write(priv->registers, addr, fill_value)); +} + +/* Simulated device registers using a mock bus backed by a cache-only regmap */ +static void cs35l56_test_create_mock_device_registers(struct kunit *test) +{ + struct cs35l56_test_priv *priv = test->priv; + struct cs35l56_private *cs35l56 = priv->cs35l56_priv; + unsigned int devid = 0x35a00 | cs35l56->base.type; + + priv->registers = devm_regmap_init(cs35l56->base.dev, + &cs35l56_test_mock_registers_regmap_bus, + test, &cs35l56_test_mock_registers_regmap_config); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->registers); + regcache_cache_only(priv->registers, true); + + switch (cs35l56->base.type) { + case 0x54: + case 0x56: + case 0x57: + break; + default: + devid <<= 4; + break; + } + KUNIT_ASSERT_EQ(test, 0, regmap_write(priv->registers, CS35L56_DEVID, devid)); + KUNIT_ASSERT_EQ(test, 0, regmap_write(priv->registers, CS35L56_REVID, cs35l56->base.rev)); + + cs35l56_test_fill_register_range(test, &cs35l56_test_asp_config_registers_range, 0); + cs35l56_test_fill_register_range(test, &cs35l56_test_asp_mixer_registers_range, 0); +} + +/* + * Not all systems supply dummy regulators for missing regulators, and + * this behaviour is a system-level decision, not a KConfig symbol we can + * depend on. So we have to provide our own dummy regulators. + */ +static const struct regulator_ops cs35l56_test_mock_regulator_ops; +static const struct regulator_desc cs35l56_test_mock_regulator_desc = { + .name = "cs35l56_test_regulators", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &cs35l56_test_mock_regulator_ops, +}; + +static struct regulator_consumer_supply cs35l56_test_mock_supplies[] = { + REGULATOR_SUPPLY("VDD_P", NULL), + REGULATOR_SUPPLY("VDD_IO", NULL), + REGULATOR_SUPPLY("VDD_A", NULL), + REGULATOR_SUPPLY("VDD_B", NULL), + REGULATOR_SUPPLY("VDD_AMP", NULL), +}; + +static const struct regulator_init_data cs35l56_test_mock_init_data = { + .constraints.always_on = 1, + .num_consumer_supplies = ARRAY_SIZE(cs35l56_test_mock_supplies), + .consumer_supplies = cs35l56_test_mock_supplies, +}; + +static void cs35l56_test_create_mock_supplies(struct kunit *test) +{ + struct cs35l56_test_priv *priv = test->priv; + struct regulator_config config = { }; + int i; + + if (!IS_ENABLED(CONFIG_REGULATOR)) + return; + + config.dev = &priv->amp_dev->dev; + config.init_data = &cs35l56_test_mock_init_data; + for (i = 0; i < ARRAY_SIZE(cs35l56_test_mock_supplies); i++) + cs35l56_test_mock_supplies[i].dev_name = dev_name(config.dev); + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, + devm_regulator_register(config.dev, + &cs35l56_test_mock_regulator_desc, + &config)); +} + static const char *cs35l56_test_devm_get_vendor_specific_variant_id_none(struct device *dev, int ssid_vendor, int ssid_device) @@ -100,6 +353,24 @@ static void cs35l56_test_system_name_from_ssid_and_spkid(struct kunit *test) KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, "12b4a7c8-spkid1"); } +static void cs35l56_test_system_name_with_feid_fev(struct kunit *test) +{ + const struct cs35l56_test_param *param = test->param_value; + struct cs35l56_test_priv *priv = test->priv; + struct cs35l56_private *cs35l56 = priv->cs35l56_priv; + + cs35l56->speaker_id = param->speaker_id; + if (param->has_ssid) + snd_soc_card_set_pci_ssid(cs35l56->component->card, 0x12b4, 0xa7c8); + + KUNIT_EXPECT_EQ(test, cs35l56_get_firmware_uid(cs35l56), 0); + KUNIT_EXPECT_EQ(test, cs35l56_set_fw_name(cs35l56->component), param->ret); + if (param->system_name) + KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, param->system_name); + else + KUNIT_EXPECT_NULL(test, cs35l56->dsp.system_name); +} + static void cs35l56_test_system_name_from_property(struct kunit *test) { struct cs35l56_test_priv *priv = test->priv; @@ -442,6 +713,68 @@ static void cs35l56_test_parse_xu_onchip_spkid(struct kunit *test) } } +static void cs35l56_test_parse_disco_feid_fev(struct kunit *test) +{ + static const char * const control_names[] = { + "mipi-sdca-control-0x5-subproperties", + "mipi-sdca-control-0x9-subproperties", + "mipi-sdca-control-0xA-subproperties", + }; + const struct cs35l56_test_param *param = test->param_value; + struct cs35l56_test_priv *priv = test->priv; + struct cs35l56_private *cs35l56 = priv->cs35l56_priv; + struct { + struct software_node nodes[ARRAY_SIZE(control_names)]; + struct property_entry props[ARRAY_SIZE(control_names)][2]; + } *disco; + int ret; + + disco = kunit_kzalloc(test, sizeof(*disco), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, disco); + + disco->props[0][0] = PROPERTY_ENTRY_U32("mipi-sdca-control-dc-value", + param->function_type); + disco->props[1][0] = PROPERTY_ENTRY_U16("mipi-sdca-control-dc-value", param->feid); + disco->props[2][0] = PROPERTY_ENTRY_U8("mipi-sdca-control-dc-value", param->fev); + ret = kunit_software_node_register_node_group(test, + cs35l56_test_dev_and_af01_node_group); + KUNIT_ASSERT_EQ(test, ret, 0); + + disco->nodes[0] = SOFTWARE_NODE(control_names[0], disco->props[0], + &cs35l56_test_af01_sw_node); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, + kunit_software_node_register(test, &disco->nodes[0])); + + if (!param->omit_feid) { + disco->nodes[1] = SOFTWARE_NODE(control_names[1], disco->props[1], + &cs35l56_test_af01_sw_node); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, + kunit_software_node_register(test, &disco->nodes[1])); + } + + if (!param->omit_fev) { + disco->nodes[2] = SOFTWARE_NODE(control_names[2], disco->props[2], + &cs35l56_test_af01_sw_node); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, + kunit_software_node_register(test, &disco->nodes[2])); + } + + KUNIT_ASSERT_EQ(test, + kunit_device_add_software_node(test, cs35l56->base.dev, + &cs35l56_test_dev_sw_node), + 0); + + cs35l56->feid = 0; + cs35l56->fev = 0; + + KUNIT_EXPECT_EQ(test, cs35l56_process_xu_properties(cs35l56), 0); + + KUNIT_EXPECT_EQ(test, cs35l56->feid, + param->function_type == SDCA_FUNCTION_TYPE_SMART_AMP ? param->feid : 0); + KUNIT_EXPECT_EQ(test, cs35l56->fev, + param->function_type == SDCA_FUNCTION_TYPE_SMART_AMP ? param->fev : 0); +} + static int cs35l56_test_dummy_read_onchip_spkid(struct cs35l56_base *cs35l56_base) { struct kunit *test = kunit_get_current_test(); @@ -519,6 +852,83 @@ static void cs35l56_test_set_fw_name_preserves_spkid_without_onchip_gpios(struct KUNIT_EXPECT_EQ(test, cs35l56->speaker_id, 15); } +static void cs35l56_test_dummy_dsp_work(struct work_struct *work) +{ +} + +/* + * Probing the component must not access the ASP1 registers. The driver does + * not necessarily own them. + */ +static void cs35l56_test_component_probe_omits_asp(struct kunit *test) +{ + struct cs35l56_test_priv *priv = test->priv; + struct cs35l56_private *cs35l56 = priv->cs35l56_priv; + struct snd_soc_card *card = cs35l56->component->card; + struct snd_soc_aux_dev *aux; + struct faux_device *card_dev; + + cs35l56_test_create_mock_supplies(test); + cs35l56_test_create_mock_device_registers(test); + + KUNIT_ASSERT_NOT_NULL(test, priv->regmap_config); + cs35l56->base.regmap = devm_regmap_init(cs35l56->base.dev, + &cs35l56_test_mock_registers_client_regmap_bus, + test, priv->regmap_config); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cs35l56->base.regmap); + + KUNIT_ASSERT_EQ(test, 0, cs35l56_common_probe(cs35l56, 0)); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, cs35l56_remove_wrapper, cs35l56)); + + /* Prevent real dsp_work */ + INIT_WORK(&cs35l56->dsp_work, cs35l56_test_dummy_dsp_work); + + /* Simulate first attachment and re-attachment after the soft reset. */ + regcache_cache_only(cs35l56->base.regmap, false); + KUNIT_ASSERT_EQ(test, 0, cs35l56_init(cs35l56)); + KUNIT_ASSERT_EQ(test, 0, cs35l56_init(cs35l56)); + KUNIT_ASSERT_TRUE(test, cs35l56->base.init_done); + flush_work(&cs35l56->component_register_work); + KUNIT_ASSERT_TRUE(test, cs35l56->component_registered); + + card_dev = faux_device_create("cs35l56_test_card", NULL, NULL); + KUNIT_ASSERT_NOT_NULL(test, card_dev); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, faux_device_destroy_wrapper, card_dev)); + + /* Bind as an auxiliary component so the ASP DAI is never probed. */ + aux = kunit_kzalloc(test, sizeof(*aux), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, aux); + aux->dlc.name = dev_name(cs35l56->base.dev); + card->name = "cs35l56-test"; + card->dev = &card_dev->dev; + card->owner = THIS_MODULE; + card->aux_dev = aux; + card->num_aux_devs = 1; + KUNIT_ASSERT_EQ(test, 0, snd_soc_register_card(card)); + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, snd_soc_unregister_card_wrapper, card)); + KUNIT_ASSERT_TRUE(test, card->instantiated); + + /* + * Flush cache to ensure there aren't cached values for the ASP registers. + * The first case without regcache_mark_dirty() tests flushing when + * hardware registers have not reset, and requires a dummy write to + * the cache to make it dirty. + */ + regcache_cache_only(cs35l56->base.regmap, true); + KUNIT_ASSERT_EQ(test, 0, regmap_write(cs35l56->base.regmap, + CS35L56_DSP_VIRTUAL1_MBOX_1, 0)); + regcache_cache_only(cs35l56->base.regmap, false); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(cs35l56->base.regmap)); + regcache_mark_dirty(cs35l56->base.regmap); + KUNIT_ASSERT_EQ(test, 0, regcache_sync(cs35l56->base.regmap)); + + KUNIT_EXPECT_FALSE(test, priv->asp_config_regs_written); + KUNIT_EXPECT_FALSE(test, priv->asp_mixer_regs_written); +} + static int cs35l56_test_case_init_common(struct kunit *test) { struct cs35l56_test_priv *priv; @@ -533,6 +943,11 @@ static int cs35l56_test_case_init_common(struct kunit *test) test->priv = priv; + /* Construct minimal set of driver structs */ + priv->cs35l56_priv = kunit_kzalloc(test, sizeof(*priv->cs35l56_priv), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, priv->cs35l56_priv); + cs35l56 = priv->cs35l56_priv; + /* Create dummy amp driver dev */ priv->amp_dev = faux_device_create("cs35l56_test_drv", NULL, NULL); KUNIT_ASSERT_NOT_NULL(test, priv->amp_dev); @@ -540,11 +955,6 @@ static int cs35l56_test_case_init_common(struct kunit *test) kunit_add_action_or_reset(test, faux_device_destroy_wrapper, priv->amp_dev)); - - /* Construct minimal set of driver structs */ - priv->cs35l56_priv = kunit_kzalloc(test, sizeof(*priv->cs35l56_priv), GFP_KERNEL); - KUNIT_ASSERT_NOT_NULL(test, priv->cs35l56_priv); - cs35l56 = priv->cs35l56_priv; cs35l56->base.dev = &priv->amp_dev->dev; cs35l56->component = kunit_kzalloc(test, sizeof(*cs35l56->component), GFP_KERNEL); @@ -559,6 +969,19 @@ static int cs35l56_test_case_init_common(struct kunit *test) if (param) { cs35l56->base.type = param->type; cs35l56->base.rev = param->rev; + cs35l56->feid = param->feid; + cs35l56->fev = param->fev; + + switch (param->type) { + case 0x54: + case 0x56: + case 0x57: + priv->regmap_config = &cs35l56_regmap_i2c; + break; + default: + priv->regmap_config = &cs35l63_regmap_i2c; + break; + } } return 0; @@ -587,6 +1010,125 @@ static int cs35l56_test_case_init_soundwire(struct kunit *test) return 0; } +static void cs35l56_test_system_name_param_desc(const struct cs35l56_test_param *param, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "feid: %04x fev: %02x ssid: %d spkid: %d", + param->feid, param->fev, param->has_ssid, param->speaker_id); +} + +static const struct cs35l56_test_param cs35l56_test_system_name_feid_fev_cases[] = { + /* FEID == 0 retains legacy naming and ignores FEV */ + { .feid = 0, .fev = 0, .speaker_id = -1, }, + { .feid = 0, .fev = 0, .speaker_id = 1, }, + { .feid = 0, .fev = 0xff, .has_ssid = true, .speaker_id = -1, + .system_name = "12b4a7c8", }, + { .feid = 0, .fev = 0xff, .has_ssid = true, .speaker_id = 1, + .system_name = "12b4a7c8-spkid1", }, + { .feid = 0, .fev = 0xff, .speaker_id = -1, }, + { .feid = 0, .fev = 0xff, .speaker_id = 1, }, + + /* Nonzero FEID < 0x8000 includes SSID and FEV */ + { .feid = 1, .fev = 0, .has_ssid = true, .speaker_id = -1, + .system_name = "12b4a7c8-f1v0", }, + { .feid = 1, .fev = 0, .has_ssid = true, .speaker_id = 1, + .system_name = "12b4a7c8-f1v0-spkid1", }, + { .feid = 0x1234, .fev = 0xab, .has_ssid = true, .speaker_id = -1, + .system_name = "12b4a7c8-f1234vab", }, + { .feid = 0x1234, .fev = 0xab, .has_ssid = true, .speaker_id = 1, + .system_name = "12b4a7c8-f1234vab-spkid1", }, + { .feid = 0x7fff, .fev = 0xff, .has_ssid = true, .speaker_id = -1, + .system_name = "12b4a7c8-f7fffvff", }, + { .feid = 0x7fff, .fev = 0xff, .has_ssid = true, .speaker_id = 1, + .system_name = "12b4a7c8-f7fffvff-spkid1", }, + + /* Nonzero FEID < 0x8000 missing SSID should not return error (fallback is allowed) */ + { .feid = 1, .fev = 0, .speaker_id = -1, .ret = 0, }, + { .feid = 1, .fev = 0, .speaker_id = 1, .ret = 0, }, + { .feid = 0x1234, .fev = 0xab, .speaker_id = -1, .ret = 0, }, + { .feid = 0x1234, .fev = 0xab, .speaker_id = 1, .ret = 0, }, + { .feid = 0x7fff, .fev = 0xff, .speaker_id = -1, .ret = 0, }, + { .feid = 0x7fff, .fev = 0xff, .speaker_id = 1, .ret = 0, }, + + /* FEID >= 0x8000 does not use an SSID */ + { .feid = 0x8000, .fev = 0, .speaker_id = -1, + .system_name = "f8000v0", }, + { .feid = 0x8000, .fev = 0, .speaker_id = 1, + .system_name = "f8000v0-spkid1", }, + { .feid = 0x8000, .fev = 0, .has_ssid = true, .speaker_id = -1, + .system_name = "f8000v0", }, + { .feid = 0x8000, .fev = 0, .has_ssid = true, .speaker_id = 1, + .system_name = "f8000v0-spkid1", }, + { .feid = 0xabcd, .fev = 0xab, .speaker_id = -1, + .system_name = "fabcdvab", }, + { .feid = 0xabcd, .fev = 0xab, .speaker_id = 1, + .system_name = "fabcdvab-spkid1", }, + { .feid = 0xabcd, .fev = 0xab, .has_ssid = true, .speaker_id = -1, + .system_name = "fabcdvab", }, + { .feid = 0xabcd, .fev = 0xab, .has_ssid = true, .speaker_id = 1, + .system_name = "fabcdvab-spkid1", }, + { .feid = 0xffff, .fev = 0xff, .speaker_id = -1, + .system_name = "fffffvff", }, + { .feid = 0xffff, .fev = 0xff, .speaker_id = 1, + .system_name = "fffffvff-spkid1", }, + { .feid = 0xffff, .fev = 0xff, .has_ssid = true, .speaker_id = -1, + .system_name = "fffffvff", }, + { .feid = 0xffff, .fev = 0xff, .has_ssid = true, .speaker_id = 1, + .system_name = "fffffvff-spkid1", }, +}; +KUNIT_ARRAY_PARAM(cs35l56_test_system_name_feid_fev, + cs35l56_test_system_name_feid_fev_cases, + cs35l56_test_system_name_param_desc); + +static void cs35l56_test_feid_fev_param_desc(const struct cs35l56_test_param *param, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "feid: %04x fev: %02x", + param->feid, param->fev); +} + +static const struct cs35l56_test_param cs35l56_test_property_feid_fev_cases[] = { + { .feid = 0, .fev = 0, }, + { .feid = 0, .fev = 0xff, }, + { .feid = 1, .fev = 0, }, + { .feid = 0x7fff, .fev = 0xff, }, + { .feid = 0x8000, .fev = 0, }, + { .feid = 0xffff, .fev = 0xff, }, +}; +KUNIT_ARRAY_PARAM(cs35l56_test_property_feid_fev, + cs35l56_test_property_feid_fev_cases, + cs35l56_test_feid_fev_param_desc); + +static void cs35l56_test_disco_feid_fev_param_desc(const struct cs35l56_test_param *param, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "function_type: %#x feid: %#x%s fev: %#x%s", + param->function_type, param->feid, param->omit_feid ? "(omitted)" : "", + param->fev, param->omit_fev ? "(omitted)" : ""); +} + +static const struct cs35l56_test_param cs35l56_test_disco_feid_fev_cases[] = { + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0, .fev = 0, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0, .fev = 0xff, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 1, .fev = 0, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0x1234, .fev = 0xab, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0x7fff, .fev = 0xff, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0x8000, .fev = 0, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0xffff, .fev = 0xff, }, + + /* Either or both can be absent*/ + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .omit_feid = true, .fev = 0xab, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .feid = 0x1234, .omit_fev = true, }, + { .function_type = SDCA_FUNCTION_TYPE_SMART_AMP, .omit_feid = true, .omit_fev = true, }, + + /* Other types of node are ignored */ + { .function_type = SDCA_FUNCTION_TYPE_SMART_MIC, .feid = 0xffff, .fev = 0xff, }, +}; + +KUNIT_ARRAY_PARAM(cs35l56_test_disco_feid_fev, + cs35l56_test_disco_feid_fev_cases, + cs35l56_test_disco_feid_fev_param_desc); + static void cs35l56_test_gpio_param_desc(const struct cs35l56_test_param *param, char *desc) { DECLARE_SEQ_BUF(gpios, 1 + (2 * ARRAY_SIZE(param->spkid_gpios))); @@ -669,8 +1211,12 @@ KUNIT_ARRAY_PARAM(cs35l56_test_type_rev_all, cs35l56_test_type_rev_all_param_cas static struct kunit_case cs35l56_test_cases_soundwire[] = { KUNIT_CASE(cs35l56_test_system_name_from_ssid), KUNIT_CASE(cs35l56_test_system_name_from_ssid_and_spkid), - KUNIT_CASE(cs35l56_test_system_name_from_property), - KUNIT_CASE(cs35l56_test_system_name_from_property_and_spkid), + KUNIT_CASE_PARAM(cs35l56_test_system_name_with_feid_fev, + cs35l56_test_system_name_feid_fev_gen_params), + KUNIT_CASE_PARAM(cs35l56_test_system_name_from_property, + cs35l56_test_property_feid_fev_gen_params), + KUNIT_CASE_PARAM(cs35l56_test_system_name_from_property_and_spkid, + cs35l56_test_property_feid_fev_gen_params), KUNIT_CASE(cs35l56_test_l56_b0_suffix_sdw), KUNIT_CASE_PARAM(cs35l56_test_suffix_sdw, cs35l56_test_type_rev_ex_b0_gen_params), KUNIT_CASE_PARAM(cs35l56_test_ssidexv2_suffix_sdw, @@ -679,10 +1225,14 @@ static struct kunit_case cs35l56_test_cases_soundwire[] = { KUNIT_CASE_PARAM(cs35l56_test_parse_xu_onchip_spkid, cs35l56_test_onchip_spkid_gen_params), + KUNIT_CASE_PARAM(cs35l56_test_parse_disco_feid_fev, + cs35l56_test_disco_feid_fev_gen_params), KUNIT_CASE(cs35l56_test_set_fw_name_reads_onchip_spkid), KUNIT_CASE(cs35l56_test_set_fw_name_preserves_spkid_with_onchip_gpios), KUNIT_CASE(cs35l56_test_set_fw_name_preserves_spkid_without_onchip_gpios), + KUNIT_CASE_PARAM(cs35l56_test_component_probe_omits_asp, + cs35l56_test_type_rev_all_gen_params), { } /* terminator */ }; @@ -690,8 +1240,10 @@ static struct kunit_case cs35l56_test_cases_soundwire[] = { static struct kunit_case cs35l56_test_cases_not_soundwire[] = { KUNIT_CASE(cs35l56_test_system_name_from_ssid), KUNIT_CASE(cs35l56_test_system_name_from_ssid_and_spkid), - KUNIT_CASE(cs35l56_test_system_name_from_property), - KUNIT_CASE(cs35l56_test_system_name_from_property_and_spkid), + KUNIT_CASE_PARAM(cs35l56_test_system_name_from_property, + cs35l56_test_property_feid_fev_gen_params), + KUNIT_CASE_PARAM(cs35l56_test_system_name_from_property_and_spkid, + cs35l56_test_property_feid_fev_gen_params), KUNIT_CASE_PARAM(cs35l56_test_suffix_i2cspi, cs35l56_test_type_rev_all_gen_params), KUNIT_CASE_PARAM(cs35l56_test_ssidexv2_suffix_i2cspi, cs35l56_test_type_rev_all_gen_params), @@ -721,6 +1273,7 @@ kunit_test_suites( ); MODULE_IMPORT_NS("SND_SOC_CS_AMP_LIB"); +MODULE_IMPORT_NS("SND_SOC_CS35L56_CORE"); MODULE_IMPORT_NS("SND_SOC_CS35L56_SHARED"); MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); MODULE_DESCRIPTION("KUnit test for Cirrus Logic cs35l56 codec driver"); diff --git a/sound/soc/codecs/cs35l56.c b/sound/soc/codecs/cs35l56.c index a4d25c28794132..30835dc5600643 100644 --- a/sound/soc/codecs/cs35l56.c +++ b/sound/soc/codecs/cs35l56.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -178,41 +181,91 @@ static const struct snd_kcontrol_new cs35l63_controls[] = { SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE), }; +static int cs35l56_asp_tx_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kcontrol); + struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); + struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component); + struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; + + snd_soc_dapm_mutex_lock(dapm); + ucontrol->value.enumerated.item[0] = + snd_soc_enum_val_to_item(e, cs35l56->asp_tx_input[e->shift_l]); + snd_soc_dapm_mutex_unlock(dapm); + + return 0; +} + +static int cs35l56_asp_tx_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kcontrol); + struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); + struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component); + struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; + unsigned int item = ucontrol->value.enumerated.item[0]; + unsigned int val; + bool change = false; + + if (item >= e->items) + return -EINVAL; + + val = snd_soc_enum_item_to_val(e, item); + + snd_soc_dapm_mutex_lock(dapm); + if (cs35l56->asp_tx_input[e->shift_l] != val) + change = true; + + cs35l56->asp_tx_input[e->shift_l] = val; + snd_soc_dapm_mutex_unlock(dapm); + + if (change) + snd_soc_dapm_mux_update_power(dapm, kcontrol, item, e, NULL); + + return change; +} + +/* The shift field of each virtual enum holds the ASP TX channel index. */ static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx1_enum, - CS35L56_ASP1TX1_INPUT, + SND_SOC_NOPM, 0, CS35L56_ASP_TXn_SRC_MASK, cs35l56_tx_input_texts, cs35l56_tx_input_values); static const struct snd_kcontrol_new asp1_tx1_mux = - SOC_DAPM_ENUM("ASP1TX1 SRC", cs35l56_asp1tx1_enum); + SOC_DAPM_ENUM_EXT("ASP1TX1 SRC", cs35l56_asp1tx1_enum, + cs35l56_asp_tx_get, cs35l56_asp_tx_put); static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx2_enum, - CS35L56_ASP1TX2_INPUT, - 0, CS35L56_ASP_TXn_SRC_MASK, + SND_SOC_NOPM, + 1, CS35L56_ASP_TXn_SRC_MASK, cs35l56_tx_input_texts, cs35l56_tx_input_values); static const struct snd_kcontrol_new asp1_tx2_mux = - SOC_DAPM_ENUM("ASP1TX2 SRC", cs35l56_asp1tx2_enum); + SOC_DAPM_ENUM_EXT("ASP1TX2 SRC", cs35l56_asp1tx2_enum, + cs35l56_asp_tx_get, cs35l56_asp_tx_put); static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx3_enum, - CS35L56_ASP1TX3_INPUT, - 0, CS35L56_ASP_TXn_SRC_MASK, + SND_SOC_NOPM, + 2, CS35L56_ASP_TXn_SRC_MASK, cs35l56_tx_input_texts, cs35l56_tx_input_values); static const struct snd_kcontrol_new asp1_tx3_mux = - SOC_DAPM_ENUM("ASP1TX3 SRC", cs35l56_asp1tx3_enum); + SOC_DAPM_ENUM_EXT("ASP1TX3 SRC", cs35l56_asp1tx3_enum, + cs35l56_asp_tx_get, cs35l56_asp_tx_put); static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx4_enum, - CS35L56_ASP1TX4_INPUT, - 0, CS35L56_ASP_TXn_SRC_MASK, + SND_SOC_NOPM, + 3, CS35L56_ASP_TXn_SRC_MASK, cs35l56_tx_input_texts, cs35l56_tx_input_values); static const struct snd_kcontrol_new asp1_tx4_mux = - SOC_DAPM_ENUM("ASP1TX4 SRC", cs35l56_asp1tx4_enum); + SOC_DAPM_ENUM_EXT("ASP1TX4 SRC", cs35l56_asp1tx4_enum, + cs35l56_asp_tx_get, cs35l56_asp_tx_put); static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_sdw1tx1_enum, CS35L56_SWIRE_DP3_CH1_INPUT, @@ -282,6 +335,40 @@ static int cs35l56_play_event(struct snd_soc_dapm_widget *w, } } +static int cs35l56_asp_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component); + + return regmap_assign_bits(cs35l56->base.regmap, CS35L56_ASP1_ENABLES1, + BIT(w->shift), + SND_SOC_DAPM_EVENT_ON(event)); +} + +static int cs35l56_asp_tx_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component); + int ret; + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + ret = regmap_write(cs35l56->base.regmap, + CS35L56_ASP1TX1_INPUT + (4 * w->shift), + cs35l56->asp_tx_input[w->shift]); + if (ret) + return ret; + + break; + default: + break; + } + + return cs35l56_asp_event(w, kcontrol, event); +} + static const struct snd_soc_dapm_widget cs35l56_dapm_widgets[] = { SND_SOC_DAPM_REGULATOR_SUPPLY("VDD_B", 0, 0), SND_SOC_DAPM_REGULATOR_SUPPLY("VDD_AMP", 0, 0), @@ -295,18 +382,25 @@ static const struct snd_soc_dapm_widget cs35l56_dapm_widgets[] = { SND_SOC_DAPM_PGA_E("DSP1", SND_SOC_NOPM, 0, 0, NULL, 0, cs35l56_dsp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), - SND_SOC_DAPM_AIF_IN("ASP1RX1", NULL, 0, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_RX1_EN_SHIFT, 0), - SND_SOC_DAPM_AIF_IN("ASP1RX2", NULL, 1, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_RX2_EN_SHIFT, 0), - SND_SOC_DAPM_AIF_OUT("ASP1TX1", NULL, 0, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_TX1_EN_SHIFT, 0), - SND_SOC_DAPM_AIF_OUT("ASP1TX2", NULL, 1, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_TX2_EN_SHIFT, 0), - SND_SOC_DAPM_AIF_OUT("ASP1TX3", NULL, 2, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_TX3_EN_SHIFT, 0), - SND_SOC_DAPM_AIF_OUT("ASP1TX4", NULL, 3, CS35L56_ASP1_ENABLES1, - CS35L56_ASP_TX4_EN_SHIFT, 0), + /* Avoid reading ASP1_ENABLES1 when DAPM initializes the widgets. */ + SND_SOC_DAPM_AIF_IN_E("ASP1RX1", NULL, 0, SND_SOC_NOPM, + CS35L56_ASP_RX1_EN_SHIFT, 0, + cs35l56_asp_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_AIF_IN_E("ASP1RX2", NULL, 1, SND_SOC_NOPM, + CS35L56_ASP_RX2_EN_SHIFT, 0, + cs35l56_asp_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_AIF_OUT_E("ASP1TX1", NULL, 0, SND_SOC_NOPM, + CS35L56_ASP_TX1_EN_SHIFT, 0, + cs35l56_asp_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_AIF_OUT_E("ASP1TX2", NULL, 1, SND_SOC_NOPM, + CS35L56_ASP_TX2_EN_SHIFT, 0, + cs35l56_asp_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_AIF_OUT_E("ASP1TX3", NULL, 2, SND_SOC_NOPM, + CS35L56_ASP_TX3_EN_SHIFT, 0, + cs35l56_asp_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_AIF_OUT_E("ASP1TX4", NULL, 3, SND_SOC_NOPM, + CS35L56_ASP_TX4_EN_SHIFT, 0, + cs35l56_asp_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), SND_SOC_DAPM_MUX("ASP1 TX1 Source", SND_SOC_NOPM, 0, 0, &asp1_tx1_mux), SND_SOC_DAPM_MUX("ASP1 TX2 Source", SND_SOC_NOPM, 0, 0, &asp1_tx2_mux), @@ -409,7 +503,7 @@ static int cs35l56_asp_dai_probe(struct snd_soc_dai *codec_dai) { struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(codec_dai->component); - return cs35l56_set_asp_patch(&cs35l56->base); + return cs35l56_set_asp_defaults(&cs35l56->base); } static int cs35l56_asp_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) @@ -1387,6 +1481,9 @@ VISIBLE_IF_KUNIT int cs35l56_set_fw_name(struct snd_soc_component *component) { struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component); unsigned short vendor, device; + char ssid[9] = ""; + char fe[10] = ""; + const char *separator = ""; int ret; if ((cs35l56->speaker_id < 0) && cs35l56->base.num_onchip_spkid_gpios) { @@ -1406,20 +1503,38 @@ VISIBLE_IF_KUNIT int cs35l56_set_fw_name(struct snd_soc_component *component) cs35l56->speaker_id = ret; } - if (!cs35l56->dsp.system_name && - (snd_soc_card_get_pci_ssid(component->card, &vendor, &device) == 0)) { + if (!cs35l56->dsp.system_name) { + if (cs35l56->feid < 0x8000) { + if (snd_soc_card_get_pci_ssid(component->card, &vendor, &device) == 0) { + snprintf(ssid, sizeof(ssid), "%04x%04x", vendor, device); + separator = "-"; + } else if (cs35l56->feid) { + dev_err(cs35l56->base.dev, "SSID required but not available\n"); + + /* Don't return error: allow falling back to default firmware */ + return 0; + } else { + return 0; + } + } + + if (cs35l56->feid) { + snprintf(fe, sizeof(fe), "%sf%xv%x", separator, + cs35l56->feid, cs35l56->fev); + } + /* Append a speaker qualifier if there is a speaker ID */ if (cs35l56->speaker_id >= 0) { cs35l56->dsp.system_name = devm_kasprintf(cs35l56->base.dev, GFP_KERNEL, - "%04x%04x-spkid%d", - vendor, device, + "%s%s-spkid%d", + ssid, fe, cs35l56->speaker_id); } else { cs35l56->dsp.system_name = devm_kasprintf(cs35l56->base.dev, GFP_KERNEL, - "%04x%04x", - vendor, device); + "%s%s", + ssid, fe); } if (!cs35l56->dsp.system_name) return -ENOMEM; @@ -1438,6 +1553,8 @@ static int _cs35l56_component_probe(struct snd_soc_component *component) BUILD_BUG_ON(ARRAY_SIZE(cs35l56_tx_input_texts) != ARRAY_SIZE(cs35l56_tx_input_values)); + memset(&cs35l56->asp_tx_input, 0, sizeof(cs35l56->asp_tx_input)); + cs35l56->dsp.part = kasprintf(GFP_KERNEL, "cs35l%02x", cs35l56->base.type); if (!cs35l56->dsp.part) return -ENOMEM; @@ -1868,31 +1985,128 @@ static int cs35l56_process_xu_onchip_speaker_id(struct cs35l56_private *cs35l56, return 0; } +static int cs35l56_read_subproperty_control_dc(struct cs35l56_private *cs35l56, + struct fwnode_handle *node, + const char *subname, + int width) +{ + static const char * const control_dc_value_prop_name = "mipi-sdca-control-dc-value"; + u8 val8 = 0; + u16 val16 = 0; + u32 val32; + int ret; + + struct fwnode_handle *subnode __free(fwnode_handle) = + fwnode_get_named_child_node(node, subname); + if (!subnode) + return -EINVAL; + + switch (width) { + case 8: + ret = fwnode_property_read_u8(subnode, control_dc_value_prop_name, &val8); + val32 = val8; + break; + case 16: + ret = fwnode_property_read_u16(subnode, control_dc_value_prop_name, &val16); + val32 = val16; + break; + default: + ret = fwnode_property_read_u32(subnode, control_dc_value_prop_name, &val32); + break; + } + + if (ret == -EINVAL) + return ret; + + if (ret < 0) { + dev_warn(cs35l56->base.dev, "Failed to get dc-value for %s: %d\n", + subname, ret); + return ret; + } + + /* None of the values we need are this big */ + if (overflows_type(val32, int)) + return -EINVAL; + + return (int)val32; +} + +static int cs35l56_process_feid_fev(struct cs35l56_private *cs35l56, + struct fwnode_handle *node) +{ + int ret; + + /* Either property overrides default of 0. This matches Windows behavior */ + ret = cs35l56_read_subproperty_control_dc(cs35l56, node, + "mipi-sdca-control-0x9-subproperties", + 16); + if (ret >= 0) { + cs35l56->feid = (u16)ret; + dev_dbg(cs35l56->base.dev, "FEID=%#x\n", cs35l56->feid); + } else if (ret != -EINVAL) { + return ret; + } + + ret = cs35l56_read_subproperty_control_dc(cs35l56, node, + "mipi-sdca-control-0xA-subproperties", + 8); + if (ret >= 0) { + cs35l56->fev = (u8)ret; + dev_dbg(cs35l56->base.dev, "FEV=%#x\n", cs35l56->fev); + } else if (ret != -EINVAL) { + return ret; + } + + return 0; +} + +static int cs35l56_process_disco_control5(struct cs35l56_private *cs35l56, + struct fwnode_handle *node) +{ + int ret; + + /* + * Don't fail probe because of a malformed property. + * It might be a property we are not interested in anyway. + */ + ret = cs35l56_read_subproperty_control_dc(cs35l56, node, + "mipi-sdca-control-0x5-subproperties", + 32); + if (ret < 0) + return 0; + + if (ret != SDCA_FUNCTION_TYPE_SMART_AMP) + return 0; + + return cs35l56_process_feid_fev(cs35l56, node); +} + VISIBLE_IF_KUNIT int cs35l56_process_xu_properties(struct cs35l56_private *cs35l56) { - struct fwnode_handle *ext_node = NULL; - struct fwnode_handle *link; int ret; if (!cs35l56->sdw_peripheral) return 0; - fwnode_for_each_child_node(dev_fwnode(cs35l56->base.dev), link) { - ext_node = fwnode_get_named_child_node(link, - "mipi-sdca-function-expansion-subproperties"); - if (ext_node) { - fwnode_handle_put(link); - break; - } - } + fwnode_for_each_child_node_scoped(dev_fwnode(cs35l56->base.dev), link) { + ret = cs35l56_process_disco_control5(cs35l56, link); + if (ret) + return ret; - if (!ext_node) - return 0; + if (!cs35l56->base.num_onchip_spkid_gpios) { + struct fwnode_handle *ext_node __free(fwnode_handle) = + fwnode_get_named_child_node(link, + "mipi-sdca-function-expansion-subproperties"); - ret = cs35l56_process_xu_onchip_speaker_id(cs35l56, ext_node); - fwnode_handle_put(ext_node); + if (ext_node) { + ret = cs35l56_process_xu_onchip_speaker_id(cs35l56, ext_node); + if (ret) + return ret; + } + } + } - return ret; + return 0; } EXPORT_SYMBOL_IF_KUNIT(cs35l56_process_xu_properties); @@ -2249,12 +2463,6 @@ int cs35l56_init(struct cs35l56_private *cs35l56) /* Registers could be dirty after soft reset or SoundWire enumeration */ regcache_sync(cs35l56->base.regmap); - /* Set ASP1 DOUT to high-impedance when it is not transmitting audio data. */ - ret = regmap_set_bits(cs35l56->base.regmap, CS35L56_ASP1_CONTROL3, - CS35L56_ASP1_DOUT_HIZ_CTRL_MASK); - if (ret) - return dev_err_probe(cs35l56->base.dev, ret, "Failed to write ASP1_CONTROL3\n"); - cs35l56->needs_wait_for_fw_idle = cs35l56_needs_wait_for_firmware_timer_expiry(&cs35l56->base); diff --git a/sound/soc/codecs/cs35l56.h b/sound/soc/codecs/cs35l56.h index b46f410f0e0938..c70283fb4986a9 100644 --- a/sound/soc/codecs/cs35l56.h +++ b/sound/soc/codecs/cs35l56.h @@ -49,6 +49,7 @@ struct cs35l56_private { int speaker_id; u32 rx_mask; u32 tx_mask; + u8 asp_tx_input[4]; u8 asp_slot_width; u8 asp_slot_count; bool tdm_mode; @@ -56,6 +57,9 @@ struct cs35l56_private { u8 sdw_link_num; u8 sdw_unique_id; + u16 feid; + u8 fev; + u8 ambient_ctl_value; }; diff --git a/sound/soc/codecs/cs40l50-codec.c b/sound/soc/codecs/cs40l50-codec.c index 698aa59194f4bf..bae3a56684c30e 100644 --- a/sound/soc/codecs/cs40l50-codec.c +++ b/sound/soc/codecs/cs40l50-codec.c @@ -285,7 +285,7 @@ static int cs40l50_codec_driver_probe(struct platform_device *pdev) struct cs40l50 *cs40l50 = dev_get_drvdata(pdev->dev.parent); struct cs40l50_codec *codec; - codec = devm_kzalloc(&pdev->dev, sizeof(*codec), GFP_KERNEL); + codec = devm_kzalloc_obj(&pdev->dev, *codec); if (!codec) return -ENOMEM; diff --git a/sound/soc/codecs/cs4234.c b/sound/soc/codecs/cs4234.c index a6ead1ee370812..64a19ae220ab58 100644 --- a/sound/soc/codecs/cs4234.c +++ b/sound/soc/codecs/cs4234.c @@ -749,7 +749,7 @@ static int cs4234_i2c_probe(struct i2c_client *i2c_client) uint8_t ids[3]; int ret = 0, i; - cs4234 = devm_kzalloc(dev, sizeof(*cs4234), GFP_KERNEL); + cs4234 = devm_kzalloc_obj(dev, *cs4234); if (!cs4234) return -ENOMEM; i2c_set_clientdata(i2c_client, cs4234); diff --git a/sound/soc/codecs/cs4265.c b/sound/soc/codecs/cs4265.c index 97e32e6ccb8434..50a31770f893f2 100644 --- a/sound/soc/codecs/cs4265.c +++ b/sound/soc/codecs/cs4265.c @@ -586,8 +586,7 @@ static int cs4265_i2c_probe(struct i2c_client *i2c_client) unsigned int devid = 0; unsigned int reg; - cs4265 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4265_private), - GFP_KERNEL); + cs4265 = devm_kzalloc_obj(&i2c_client->dev, struct cs4265_private); if (cs4265 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index aa3bbb95194514..d1fe69670a7ecf 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -673,8 +673,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client) unsigned int val; int ret, i; - cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), - GFP_KERNEL); + cs4270 = devm_kzalloc_obj(&i2c_client->dev, struct cs4270_private); if (!cs4270) return -ENOMEM; diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c index 398d8c24a9ce2b..06f1dd251aa137 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c @@ -672,7 +672,7 @@ static int cs4271_common_probe(struct device *dev, struct cs4271_private *cs4271; int i, ret; - cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL); + cs4271 = devm_kzalloc_obj(dev, *cs4271); if (!cs4271) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l42-i2c.c b/sound/soc/codecs/cs42l42-i2c.c index c0942f28723be7..6210fa0f3e4b07 100644 --- a/sound/soc/codecs/cs42l42-i2c.c +++ b/sound/soc/codecs/cs42l42-i2c.c @@ -20,7 +20,7 @@ static int cs42l42_i2c_probe(struct i2c_client *i2c_client) struct regmap *regmap; int ret; - cs42l42 = devm_kzalloc(dev, sizeof(*cs42l42), GFP_KERNEL); + cs42l42 = devm_kzalloc_obj(dev, *cs42l42); if (!cs42l42) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l42-sdw.c b/sound/soc/codecs/cs42l42-sdw.c index b61ca74dcf0b62..58adba2cd43103 100644 --- a/sound/soc/codecs/cs42l42-sdw.c +++ b/sound/soc/codecs/cs42l42-sdw.c @@ -312,7 +312,7 @@ static int cs42l42_sdw_read_prop(struct sdw_slave *peripheral) struct sdw_slave_prop *prop = &peripheral->prop; struct sdw_dpn_prop *ports; - ports = devm_kcalloc(cs42l42->dev, 2, sizeof(*ports), GFP_KERNEL); + ports = devm_kzalloc_objs(cs42l42->dev, *ports, 2); if (!ports) return -ENOMEM; @@ -528,7 +528,7 @@ static int cs42l42_sdw_probe(struct sdw_slave *peripheral, const struct sdw_devi struct regmap *regmap; int irq, ret; - cs42l42 = devm_kzalloc(dev, sizeof(*cs42l42), GFP_KERNEL); + cs42l42 = devm_kzalloc_obj(dev, *cs42l42); if (!cs42l42) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l43-jack.c b/sound/soc/codecs/cs42l43-jack.c index a2555dd9229e31..b3f89c712ed934 100644 --- a/sound/soc/codecs/cs42l43-jack.c +++ b/sound/soc/codecs/cs42l43-jack.c @@ -324,6 +324,11 @@ irqreturn_t cs42l43_bias_detect_clamp(int irq, void *data) #define CS42L43_JACK_BUTTONS (SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | \ SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5) +#define CS42L43_TYPE_CTIA 0x0 +#define CS42L43_TYPE_OMTP 0x1 +#define CS42L43_TYPE_3POLE 0x2 +#define CS42L43_TYPE_OPEN 0x3 + static inline bool cs42l43_jack_present(struct cs42l43_codec *priv) { struct cs42l43 *cs42l43 = priv->core; @@ -502,9 +507,11 @@ static const struct reg_sequence cs42l43_4pole_patch[] = { { 0x4000, 0x00000000 }, }; -static void cs42l43_start_load_detect(struct cs42l43_codec *priv, bool mic) +static void cs42l43_start_load_detect(struct cs42l43_codec *priv, int type) { struct cs42l43 *cs42l43 = priv->core; + const struct reg_sequence *patch; + int size; dev_dbg(priv->dev, "Start load detect\n"); @@ -526,14 +533,36 @@ static void cs42l43_start_load_detect(struct cs42l43_codec *priv, bool mic) dev_err(priv->dev, "Load detect HP power down timed out\n"); } - if (mic) - regmap_multi_reg_write_bypassed(cs42l43->regmap, - cs42l43_4pole_patch, - ARRAY_SIZE(cs42l43_4pole_patch)); - else - regmap_multi_reg_write_bypassed(cs42l43->regmap, - cs42l43_3pole_patch, - ARRAY_SIZE(cs42l43_3pole_patch)); + switch (cs42l43->variant_id) { + case CS42L43_DEVID_VAL: + switch (type) { + case CS42L43_TYPE_3POLE: + case CS42L43_TYPE_OPEN: + patch = cs42l43_3pole_patch; + size = ARRAY_SIZE(cs42l43_3pole_patch); + break; + default: + patch = cs42l43_4pole_patch; + size = ARRAY_SIZE(cs42l43_4pole_patch); + break; + } + break; + default: + patch = cs42l43_4pole_patch; + size = ARRAY_SIZE(cs42l43_4pole_patch); + + switch (type) { + case CS42L43_TYPE_OMTP: + regmap_write(cs42l43->regmap, CS42L43B_LOAD_DET_SEL, 0x89); + break; + default: + regmap_write(cs42l43->regmap, CS42L43B_LOAD_DET_SEL, 0x98); + break; + } + break; + } + + regmap_multi_reg_write_bypassed(cs42l43->regmap, patch, size); regmap_update_bits(cs42l43->regmap, CS42L43_BLOCK_EN3, CS42L43_ADC1_EN_MASK | CS42L43_ADC2_EN_MASK, 0); @@ -586,6 +615,14 @@ static void cs42l43_stop_load_detect(struct cs42l43_codec *priv) CS42L43_ADC1_EN_MASK | CS42L43_ADC2_EN_MASK, priv->adc_ena); + switch (cs42l43->variant_id) { + case CS42L43_DEVID_VAL: + break; + default: + regmap_write(cs42l43->regmap, CS42L43B_LOAD_DET_SEL, 0x0); + break; + } + if (priv->hp_ena && !priv->hp_ilimited) { unsigned long time_left; @@ -605,7 +642,7 @@ static void cs42l43_stop_load_detect(struct cs42l43_codec *priv) snd_soc_dapm_mutex_unlock(snd_soc_component_to_dapm(priv->component)); } -static int cs42l43_run_load_detect(struct cs42l43_codec *priv, bool mic) +static int cs42l43_run_load_detect(struct cs42l43_codec *priv, int type) { struct cs42l43 *cs42l43 = priv->core; unsigned int val = 0; @@ -613,7 +650,7 @@ static int cs42l43_run_load_detect(struct cs42l43_codec *priv, bool mic) reinit_completion(&priv->load_detect); - cs42l43_start_load_detect(priv, mic); + cs42l43_start_load_detect(priv, type); time_left = wait_for_completion_timeout(&priv->load_detect, msecs_to_jiffies(CS42L43_LOAD_TIMEOUT_MS)); cs42l43_stop_load_detect(priv); @@ -629,23 +666,25 @@ static int cs42l43_run_load_detect(struct cs42l43_codec *priv, bool mic) if (!cs42l43_jack_present(priv)) return -ENODEV; - if (mic) { + switch (type) { + case CS42L43_TYPE_3POLE: + case CS42L43_TYPE_OPEN: + switch (val & CS42L43_AMP3_RES_DET_MASK) { + case 0x0: // < 22 Ohm impedance + case 0x1: // < 150 Ohm impedance + case 0x2: // < 1000 Ohm impedance + return CS42L43_JACK_HEADPHONE; + case 0x3: // > 1000 Ohm impedance + return CS42L43_JACK_LINEOUT; + default: + return -EINVAL; + } + default: cs42l43_start_hs_bias(priv, false); cs42l43_start_button_detect(priv); return CS42L43_JACK_HEADSET; } - - switch (val & CS42L43_AMP3_RES_DET_MASK) { - case 0x0: // < 22 Ohm impedance - case 0x1: // < 150 Ohm impedance - case 0x2: // < 1000 Ohm impedance - return CS42L43_JACK_HEADPHONE; - case 0x3: // > 1000 Ohm impedance - return CS42L43_JACK_LINEOUT; - default: - return -EINVAL; - } } static int cs42l43_run_type_detect(struct cs42l43_codec *priv) @@ -686,18 +725,12 @@ static int cs42l43_run_type_detect(struct cs42l43_codec *priv) if (!cs42l43_jack_present(priv)) return -ENODEV; - switch (type & CS42L43_HSDET_TYPE_STS_MASK) { - case 0x0: // CTIA - case 0x1: // OMTP - case 0x4: - return cs42l43_run_load_detect(priv, true); - case 0x2: // 3-pole - return cs42l43_run_load_detect(priv, false); - case 0x3: // Open-circuit + type &= CS42L43_HSDET_TYPE_STS_MASK; + + if (type == CS42L43_TYPE_OPEN) return CS42L43_JACK_EXTENSION; - default: - return -EINVAL; - } + else + return cs42l43_run_load_detect(priv, type); } void cs42l43_clear_jack(struct cs42l43_codec *priv) diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c index f31f448484d65e..84c5d9ef6bc41f 100644 --- a/sound/soc/codecs/cs42l43.c +++ b/sound/soc/codecs/cs42l43.c @@ -2814,7 +2814,7 @@ static int cs42l43_codec_probe(struct platform_device *pdev) unsigned int val; int i, ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c index 4b964c71339827..a0d872f14a5435 100644 --- a/sound/soc/codecs/cs42l51.c +++ b/sound/soc/codecs/cs42l51.c @@ -723,8 +723,7 @@ int cs42l51_probe(struct device *dev, struct regmap *regmap) if (IS_ERR(regmap)) return PTR_ERR(regmap); - cs42l51 = devm_kzalloc(dev, sizeof(struct cs42l51_private), - GFP_KERNEL); + cs42l51 = devm_kzalloc_obj(dev, struct cs42l51_private); if (!cs42l51) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c index 1d3334886402a8..1a9e512f4da7c9 100644 --- a/sound/soc/codecs/cs42l52.c +++ b/sound/soc/codecs/cs42l52.c @@ -1132,7 +1132,7 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client) unsigned int reg; u32 val32; - cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l52), GFP_KERNEL); + cs42l52 = devm_kzalloc_obj(&i2c_client->dev, *cs42l52); if (cs42l52 == NULL) return -ENOMEM; cs42l52->dev = &i2c_client->dev; @@ -1144,7 +1144,7 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client) return ret; } - pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c_client->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c index ecce51985a11ca..b4a85e7fdd7013 100644 --- a/sound/soc/codecs/cs42l56.c +++ b/sound/soc/codecs/cs42l56.c @@ -1225,7 +1225,7 @@ static int cs42l56_i2c_probe(struct i2c_client *i2c_client) unsigned int alpha_rev, metal_rev; unsigned int reg; - cs42l56 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l56), GFP_KERNEL); + cs42l56 = devm_kzalloc_obj(&i2c_client->dev, *cs42l56); if (cs42l56 == NULL) return -ENOMEM; cs42l56->dev = &i2c_client->dev; diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c index 72c4213ed74bf5..a54d55a221afa2 100644 --- a/sound/soc/codecs/cs42l73.c +++ b/sound/soc/codecs/cs42l73.c @@ -1296,7 +1296,7 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client) unsigned int reg; u32 val32; - cs42l73 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l73), GFP_KERNEL); + cs42l73 = devm_kzalloc_obj(&i2c_client->dev, *cs42l73); if (!cs42l73) return -ENOMEM; @@ -1307,7 +1307,7 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client) return ret; } - pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c_client->dev, *pdata); if (!pdata) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l83-i2c.c b/sound/soc/codecs/cs42l83-i2c.c index 53a7fe1ab3ddd7..3d52f42bf9913e 100644 --- a/sound/soc/codecs/cs42l83-i2c.c +++ b/sound/soc/codecs/cs42l83-i2c.c @@ -171,7 +171,7 @@ static int cs42l83_i2c_probe(struct i2c_client *i2c_client) struct regmap *regmap; int ret; - cs42l83 = devm_kzalloc(dev, sizeof(*cs42l83), GFP_KERNEL); + cs42l83 = devm_kzalloc_obj(dev, *cs42l83); if (!cs42l83) return -ENOMEM; diff --git a/sound/soc/codecs/cs42l84.c b/sound/soc/codecs/cs42l84.c index 77015590368b64..45f6390dbd0547 100644 --- a/sound/soc/codecs/cs42l84.c +++ b/sound/soc/codecs/cs42l84.c @@ -988,8 +988,7 @@ static int cs42l84_i2c_probe(struct i2c_client *i2c_client) int ret, devid; unsigned int reg; - cs42l84 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l84_private), - GFP_KERNEL); + cs42l84 = devm_kzalloc_obj(&i2c_client->dev, struct cs42l84_private); if (!cs42l84) return -ENOMEM; diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c index fb9f4aff6bd84a..797bb67eafcaf0 100644 --- a/sound/soc/codecs/cs42xx8.c +++ b/sound/soc/codecs/cs42xx8.c @@ -551,7 +551,7 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driv return ret; } - cs42xx8 = devm_kzalloc(dev, sizeof(*cs42xx8), GFP_KERNEL); + cs42xx8 = devm_kzalloc_obj(dev, *cs42xx8); if (cs42xx8 == NULL) return -ENOMEM; @@ -671,6 +671,7 @@ static int cs42xx8_runtime_resume(struct device *dev) return 0; err_bulk: + regcache_cache_only(cs42xx8->regmap, true); regulator_bulk_disable(ARRAY_SIZE(cs42xx8->supplies), cs42xx8->supplies); err_clk: diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c index 7fb23522f081cc..13a5d9245f0d26 100644 --- a/sound/soc/codecs/cs43130.c +++ b/sound/soc/codecs/cs43130.c @@ -651,9 +651,16 @@ static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk, return -EINVAL; } - frm_size = bitwidth_sclk * params_channels(params); - loc_ch1 = 0; - loc_ch2 = bitwidth_sclk * (params_channels(params) - 1); + if (cs43130->dais[dai_id].slots) { + /* The layout set with set_tdm_slot() */ + frm_size = bitwidth_sclk * cs43130->dais[dai_id].slots; + loc_ch1 = cs43130->dais[dai_id].slot_loc[0]; + loc_ch2 = cs43130->dais[dai_id].slot_loc[1]; + } else { + frm_size = bitwidth_sclk * params_channels(params); + loc_ch1 = 0; + loc_ch2 = bitwidth_sclk * (params_channels(params) - 1); + } frm_data = frm_delay & CS43130_SP_FSD_MASK; frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK; @@ -960,18 +967,24 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, break; } - if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBP_CFP) - /* Calculate SCLK in master mode if unassigned */ - sclk = params_rate(params) * bitwidth_dai * - params_channels(params); + if (cs43130->dais[dai->id].slot_width) { + /* The slot width set with set_tdm_slot() */ + bitwidth_sclk = cs43130->dais[dai->id].slot_width; + } else { + if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBP_CFP) + /* Calculate SCLK in master mode if unassigned */ + sclk = params_rate(params) * bitwidth_dai * + params_channels(params); + + if (!sclk) { + /* at this point, SCLK must be set */ + dev_err(cs43130->dev, "SCLK freq is not set\n"); + return -EINVAL; + } - if (!sclk) { - /* at this point, SCLK must be set */ - dev_err(cs43130->dev, "SCLK freq is not set\n"); - return -EINVAL; + bitwidth_sclk = (sclk / params_rate(params)) / + params_channels(params); } - - bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params); if (bitwidth_sclk < bitwidth_dai) { dev_err(cs43130->dev, "Format not supported: SCLK freq is too low\n"); return -EINVAL; @@ -1624,6 +1637,42 @@ static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai, return 0; } +/* + * Sets the frame layout directly, which then takes precedence over the one + * derived from the set_sysclk() frequency: generic sound cards pass MCLK to + * set_sysclk(), not SCLK. The PCM DAI only plays, so it receives: the two + * channels go to the first and second slots set in rx_mask (both to the same + * slot for one), and tx_mask is not used. Frames are 16 to 64 bits, the sizes + * the serial port clock tables cover. Zero slots go back to the derived layout. + */ +static int cs43130_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, + unsigned int rx_mask, int slots, int slot_width) +{ + struct snd_soc_component *component = dai->component; + struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); + struct cs43130_dai *cs_dai = &cs43130->dais[dai->id]; + unsigned int frm_size = slots * slot_width; + + if (!slots) { + cs_dai->slots = 0; + cs_dai->slot_width = 0; + return 0; + } + if (slots < 0 || slot_width < 16 || slot_width > 32 || + frm_size > 64 || frm_size % 16) + return -EINVAL; + if (!rx_mask || hweight32(rx_mask) > 2 || rx_mask >= BIT(slots)) + return -EINVAL; + + cs_dai->slot_loc[0] = __ffs(rx_mask) * slot_width; + rx_mask &= rx_mask - 1; + cs_dai->slot_loc[1] = rx_mask ? __ffs(rx_mask) * slot_width : + cs_dai->slot_loc[0]; + cs_dai->slots = slots; + cs_dai->slot_width = slot_width; + return 0; +} + static const u64 cs43130_selectable_formats = SND_SOC_POSSIBLE_DAIFMT_I2S | SND_SOC_POSSIBLE_DAIFMT_LEFT_J | @@ -1640,6 +1689,7 @@ static const struct snd_soc_dai_ops cs43130_pcm_ops = { .hw_free = cs43130_hw_free, .set_sysclk = cs43130_set_sysclk, .set_fmt = cs43130_pcm_set_fmt, + .set_tdm_slot = cs43130_set_tdm_slot, .auto_selectable_formats = &cs43130_selectable_formats, .num_auto_selectable_formats = 1, }; @@ -2428,7 +2478,6 @@ static const struct snd_soc_component_driver soc_component_dev_cs43130_digital = .set_sysclk = cs43130_component_set_sysclk, .set_pll = cs43130_set_pll, .idle_bias_on = 1, - .use_pmdown_time = 1, .endianness = 1, /* Don't take into account the ending analog widgets and routes */ .dapm_widgets = hp_widgets, @@ -2444,7 +2493,6 @@ static const struct snd_soc_component_driver soc_component_dev_cs43130_analog = .set_sysclk = cs43130_component_set_sysclk, .set_pll = cs43130_set_pll, .idle_bias_on = 1, - .use_pmdown_time = 1, .endianness = 1, .dapm_widgets = hp_widgets, .num_dapm_widgets = ARRAY_SIZE(hp_widgets), @@ -2528,7 +2576,7 @@ static int cs43130_i2c_probe(struct i2c_client *client) unsigned int reg; int i, devid; - cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL); + cs43130 = devm_kzalloc_obj(&client->dev, *cs43130); if (!cs43130) return -ENOMEM; diff --git a/sound/soc/codecs/cs43130.h b/sound/soc/codecs/cs43130.h index b0dba903403f37..d94ce32e9571e2 100644 --- a/sound/soc/codecs/cs43130.h +++ b/sound/soc/codecs/cs43130.h @@ -495,6 +495,9 @@ static const char *const cs43130_supply_names[CS43130_NUM_SUPPLIES] = { struct cs43130_dai { unsigned int sclk; + unsigned int slots; + unsigned int slot_width; + u8 slot_loc[2]; unsigned int dai_format; unsigned int dai_mode; unsigned int dai_invert; diff --git a/sound/soc/codecs/cs4341.c b/sound/soc/codecs/cs4341.c index be0ab0b128cdf7..a4347976866a32 100644 --- a/sound/soc/codecs/cs4341.c +++ b/sound/soc/codecs/cs4341.c @@ -246,7 +246,7 @@ static int cs4341_i2c_probe(struct i2c_client *i2c) { struct cs4341_priv *cs4341; - cs4341 = devm_kzalloc(&i2c->dev, sizeof(*cs4341), GFP_KERNEL); + cs4341 = devm_kzalloc_obj(&i2c->dev, *cs4341); if (!cs4341) return -ENOMEM; @@ -292,7 +292,7 @@ static int cs4341_spi_probe(struct spi_device *spi) struct cs4341_priv *cs4341; int ret; - cs4341 = devm_kzalloc(&spi->dev, sizeof(*cs4341), GFP_KERNEL); + cs4341 = devm_kzalloc_obj(&spi->dev, *cs4341); if (!cs4341) return -ENOMEM; diff --git a/sound/soc/codecs/cs4349.c b/sound/soc/codecs/cs4349.c index 28320951e30902..b56fb4a57c1253 100644 --- a/sound/soc/codecs/cs4349.c +++ b/sound/soc/codecs/cs4349.c @@ -289,7 +289,7 @@ static int cs4349_i2c_probe(struct i2c_client *client) struct cs4349_private *cs4349; int ret; - cs4349 = devm_kzalloc(&client->dev, sizeof(*cs4349), GFP_KERNEL); + cs4349 = devm_kzalloc_obj(&client->dev, *cs4349); if (!cs4349) return -ENOMEM; diff --git a/sound/soc/codecs/cs47l15.c b/sound/soc/codecs/cs47l15.c index 2f30dd83470954..3991374247168d 100644 --- a/sound/soc/codecs/cs47l15.c +++ b/sound/soc/codecs/cs47l15.c @@ -1374,8 +1374,7 @@ static int cs47l15_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - cs47l15 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l15), - GFP_KERNEL); + cs47l15 = devm_kzalloc_obj(&pdev->dev, struct cs47l15); if (!cs47l15) return -ENOMEM; diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c index 5100b1aac90220..fa2d01ead30bb8 100644 --- a/sound/soc/codecs/cs47l24.c +++ b/sound/soc/codecs/cs47l24.c @@ -1217,8 +1217,7 @@ static int cs47l24_probe(struct platform_device *pdev) BUILD_BUG_ON(ARRAY_SIZE(cs47l24_dai) > ARIZONA_MAX_DAI); - cs47l24 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l24_priv), - GFP_KERNEL); + cs47l24 = devm_kzalloc_obj(&pdev->dev, struct cs47l24_priv); if (!cs47l24) return -ENOMEM; diff --git a/sound/soc/codecs/cs47l35.c b/sound/soc/codecs/cs47l35.c index e77ac7bc846655..46d8a6a7922b4f 100644 --- a/sound/soc/codecs/cs47l35.c +++ b/sound/soc/codecs/cs47l35.c @@ -1658,7 +1658,7 @@ static int cs47l35_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - cs47l35 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l35), GFP_KERNEL); + cs47l35 = devm_kzalloc_obj(&pdev->dev, struct cs47l35); if (!cs47l35) return -ENOMEM; platform_set_drvdata(pdev, cs47l35); diff --git a/sound/soc/codecs/cs47l85.c b/sound/soc/codecs/cs47l85.c index 9ee60616c04c33..46ed6beedfca14 100644 --- a/sound/soc/codecs/cs47l85.c +++ b/sound/soc/codecs/cs47l85.c @@ -2602,8 +2602,7 @@ static int cs47l85_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - cs47l85 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l85), - GFP_KERNEL); + cs47l85 = devm_kzalloc_obj(&pdev->dev, struct cs47l85); if (!cs47l85) return -ENOMEM; diff --git a/sound/soc/codecs/cs47l90.c b/sound/soc/codecs/cs47l90.c index 6ce603bfd5004d..8a381fd3083c7f 100644 --- a/sound/soc/codecs/cs47l90.c +++ b/sound/soc/codecs/cs47l90.c @@ -2517,8 +2517,7 @@ static int cs47l90_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - cs47l90 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l90), - GFP_KERNEL); + cs47l90 = devm_kzalloc_obj(&pdev->dev, struct cs47l90); if (!cs47l90) return -ENOMEM; diff --git a/sound/soc/codecs/cs47l92.c b/sound/soc/codecs/cs47l92.c index 07bc303d9797a9..d4013a2e919c0f 100644 --- a/sound/soc/codecs/cs47l92.c +++ b/sound/soc/codecs/cs47l92.c @@ -1982,7 +1982,7 @@ static int cs47l92_probe(struct platform_device *pdev) return -EPROBE_DEFER; } - cs47l92 = devm_kzalloc(&pdev->dev, sizeof(struct cs47l92), GFP_KERNEL); + cs47l92 = devm_kzalloc_obj(&pdev->dev, struct cs47l92); if (!cs47l92) return -ENOMEM; diff --git a/sound/soc/codecs/cs48l32.c b/sound/soc/codecs/cs48l32.c index c11fc1a588c4e8..b6974df7595d2f 100644 --- a/sound/soc/codecs/cs48l32.c +++ b/sound/soc/codecs/cs48l32.c @@ -1352,7 +1352,7 @@ static irqreturn_t cs48l32_irq(int irq, void *data) ret = regmap_read(regmap, CS48L32_IRQ1_STATUS, &eint_pending); if (ret) { dev_warn(cs48l32_codec->core.dev, "Read IRQ1_STATUS failed: %d\n", ret); - return IRQ_NONE; + goto out; } if ((eint_pending & CS48L32_IRQ1_STS_MASK) == 0) goto out; @@ -1360,7 +1360,7 @@ static irqreturn_t cs48l32_irq(int irq, void *data) ret = regmap_multi_reg_read(regmap, eint1_regs, reg_vals, ARRAY_SIZE(reg_vals)); if (ret) { dev_warn(cs48l32_codec->core.dev, "Read IRQ regs failed: %d\n", ret); - return IRQ_NONE; + goto out; } for (i = 0; i < ARRAY_SIZE(reg_vals); i += 2) { @@ -3910,7 +3910,7 @@ static int cs48l32_spi_probe(struct spi_device *spi) unsigned int hwid, rev, otp_rev; int i, ret; - cs48l32_codec = devm_kzalloc(&spi->dev, sizeof(*cs48l32_codec), GFP_KERNEL); + cs48l32_codec = devm_kzalloc_obj(&spi->dev, *cs48l32_codec); if (!cs48l32_codec) return -ENOMEM; diff --git a/sound/soc/codecs/cs48l32.h b/sound/soc/codecs/cs48l32.h index c1b4e13feae41b..c8875b5e2603a3 100644 --- a/sound/soc/codecs/cs48l32.h +++ b/sound/soc/codecs/cs48l32.h @@ -395,9 +395,5 @@ struct cs48l32_codec { int cs48l32_apply_patch(struct cs48l32 *cs48l32); int cs48l32_create_regmap(struct spi_device *spi, struct cs48l32 *cs48l32); -int cs48l32_enable_asp1_pins(struct cs48l32_codec *cs48l32_codec); -int cs48l32_enable_asp2_pins(struct cs48l32_codec *cs48l32_codec); -int cs48l32_micvdd_voltage_index(u32 voltage); -int cs48l32_micbias1_voltage_index(u32 voltage); #endif diff --git a/sound/soc/codecs/cs530x-i2c.c b/sound/soc/codecs/cs530x-i2c.c index 98cb61dd88c1fa..ee5786704909f7 100644 --- a/sound/soc/codecs/cs530x-i2c.c +++ b/sound/soc/codecs/cs530x-i2c.c @@ -55,7 +55,7 @@ static int cs530x_i2c_probe(struct i2c_client *client) { struct cs530x_priv *cs530x; - cs530x = devm_kzalloc(&client->dev, sizeof(*cs530x), GFP_KERNEL); + cs530x = devm_kzalloc_obj(&client->dev, *cs530x); if (!cs530x) return -ENOMEM; diff --git a/sound/soc/codecs/cs530x-spi.c b/sound/soc/codecs/cs530x-spi.c index dbf1e7bbec19ca..2f6784b60b244f 100644 --- a/sound/soc/codecs/cs530x-spi.c +++ b/sound/soc/codecs/cs530x-spi.c @@ -56,7 +56,7 @@ static int cs530x_spi_probe(struct spi_device *spi) struct device *dev = &spi->dev; int ret; - cs530x = devm_kzalloc(dev, sizeof(struct cs530x_priv), GFP_KERNEL); + cs530x = devm_kzalloc_obj(dev, struct cs530x_priv); if (cs530x == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/cs53l30.c b/sound/soc/codecs/cs53l30.c index c9c682a312c33f..895282c575fd26 100644 --- a/sound/soc/codecs/cs53l30.c +++ b/sound/soc/codecs/cs53l30.c @@ -916,7 +916,7 @@ static int cs53l30_i2c_probe(struct i2c_client *client) int ret = 0, i, devid; u8 val; - cs53l30 = devm_kzalloc(dev, sizeof(*cs53l30), GFP_KERNEL); + cs53l30 = devm_kzalloc_obj(dev, *cs53l30); if (!cs53l30) return -ENOMEM; diff --git a/sound/soc/codecs/cx2072x.c b/sound/soc/codecs/cx2072x.c index 5b9e9520ae0100..ee6abe6eddca28 100644 --- a/sound/soc/codecs/cx2072x.c +++ b/sound/soc/codecs/cx2072x.c @@ -1643,8 +1643,7 @@ static int cx2072x_i2c_probe(struct i2c_client *i2c) unsigned int ven_id, rev_id; int ret; - cx2072x = devm_kzalloc(&i2c->dev, sizeof(struct cx2072x_priv), - GFP_KERNEL); + cx2072x = devm_kzalloc_obj(&i2c->dev, struct cx2072x_priv); if (!cx2072x) return -ENOMEM; diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c index 40d759938edcc2..a1b9720bf36a30 100644 --- a/sound/soc/codecs/da7210.c +++ b/sound/soc/codecs/da7210.c @@ -1217,8 +1217,7 @@ static int da7210_i2c_probe(struct i2c_client *i2c) struct da7210_priv *da7210; int ret; - da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv), - GFP_KERNEL); + da7210 = devm_kzalloc_obj(&i2c->dev, struct da7210_priv); if (!da7210) return -ENOMEM; @@ -1304,8 +1303,7 @@ static int da7210_spi_probe(struct spi_device *spi) struct da7210_priv *da7210; int ret; - da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv), - GFP_KERNEL); + da7210 = devm_kzalloc_obj(&spi->dev, struct da7210_priv); if (!da7210) return -ENOMEM; diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c index 4990feaa8259c9..b08e8ab6b42186 100644 --- a/sound/soc/codecs/da7213.c +++ b/sound/soc/codecs/da7213.c @@ -1930,7 +1930,7 @@ static struct da7213_platform_data const char *fw_str; u32 fw_val32; - pdata = devm_kzalloc(component->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(component->dev, *pdata); if (!pdata) return NULL; @@ -2179,7 +2179,7 @@ static int da7213_i2c_probe(struct i2c_client *i2c) struct da7213_priv *da7213; int i, ret; - da7213 = devm_kzalloc(&i2c->dev, sizeof(*da7213), GFP_KERNEL); + da7213 = devm_kzalloc_obj(&i2c->dev, *da7213); if (!da7213) return -ENOMEM; diff --git a/sound/soc/codecs/da7218.c b/sound/soc/codecs/da7218.c index a538b3dd1635bc..b333e842eec185 100644 --- a/sound/soc/codecs/da7218.c +++ b/sound/soc/codecs/da7218.c @@ -2452,7 +2452,7 @@ static struct da7218_pdata *da7218_of_to_pdata(struct device *dev, const char *of_str; u32 of_val32; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -2520,8 +2520,7 @@ static struct da7218_pdata *da7218_of_to_pdata(struct device *dev, if (!hpldet_np) return pdata; - hpldet_pdata = devm_kzalloc(dev, sizeof(*hpldet_pdata), - GFP_KERNEL); + hpldet_pdata = devm_kzalloc_obj(dev, *hpldet_pdata); if (!hpldet_pdata) { of_node_put(hpldet_np); return pdata; @@ -3240,7 +3239,7 @@ static int da7218_i2c_probe(struct i2c_client *i2c) struct da7218_priv *da7218; int i, ret; - da7218 = devm_kzalloc(&i2c->dev, sizeof(*da7218), GFP_KERNEL); + da7218 = devm_kzalloc_obj(&i2c->dev, *da7218); if (!da7218) return -ENOMEM; diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index 0b3b108aaeee52..cdb42b5706c55d 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -670,7 +670,7 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct device *dev) if (!aad_np) return NULL; - aad_pdata = devm_kzalloc(dev, sizeof(*aad_pdata), GFP_KERNEL); + aad_pdata = devm_kzalloc_obj(dev, *aad_pdata); if (!aad_pdata) { fwnode_handle_put(aad_np); return NULL; @@ -1062,7 +1062,7 @@ int da7219_aad_probe(struct i2c_client *i2c) struct device *dev = &i2c->dev; struct da7219_aad_priv *da7219_aad; - da7219_aad = devm_kzalloc(dev, sizeof(*da7219_aad), GFP_KERNEL); + da7219_aad = devm_kzalloc_obj(dev, *da7219_aad); if (!da7219_aad) return -ENOMEM; diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 673285c3213b29..e79bafd4ee246f 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -1758,7 +1758,7 @@ static struct da7219_pdata *da7219_fw_to_pdata(struct device *dev) const char *of_str; u32 of_val32; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return NULL; @@ -2667,8 +2667,7 @@ static int da7219_i2c_probe(struct i2c_client *i2c) struct da7219_priv *da7219; int ret; - da7219 = devm_kzalloc(dev, sizeof(struct da7219_priv), - GFP_KERNEL); + da7219 = devm_kzalloc_obj(dev, struct da7219_priv); if (!da7219) return -ENOMEM; diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c index e417c7ada23715..62f93fd9083dab 100644 --- a/sound/soc/codecs/da732x.c +++ b/sound/soc/codecs/da732x.c @@ -1529,8 +1529,7 @@ static int da732x_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret; - da732x = devm_kzalloc(&i2c->dev, sizeof(struct da732x_priv), - GFP_KERNEL); + da732x = devm_kzalloc_obj(&i2c->dev, struct da732x_priv); if (!da732x) return -ENOMEM; diff --git a/sound/soc/codecs/da9055.c b/sound/soc/codecs/da9055.c index faff1535ab12af..ff9c50b66b231b 100644 --- a/sound/soc/codecs/da9055.c +++ b/sound/soc/codecs/da9055.c @@ -1487,8 +1487,7 @@ static int da9055_i2c_probe(struct i2c_client *i2c) struct da9055_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret; - da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055_priv), - GFP_KERNEL); + da9055 = devm_kzalloc_obj(&i2c->dev, struct da9055_priv); if (!da9055) return -ENOMEM; diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index cbed11136935ac..449e48b52ba38c 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -108,7 +108,7 @@ static int dmic_component_probe(struct snd_soc_component *component) { struct dmic *dmic; - dmic = devm_kzalloc(component->dev, sizeof(*dmic), GFP_KERNEL); + dmic = devm_kzalloc_obj(component->dev, *dmic); if (!dmic) return -ENOMEM; @@ -179,7 +179,7 @@ static int dmic_dev_probe(struct platform_device *pdev) if (chans < 1 || chans > 8) return -EINVAL; - dai_drv = devm_kzalloc(&pdev->dev, sizeof(*dai_drv), GFP_KERNEL); + dai_drv = devm_kzalloc_obj(&pdev->dev, *dai_drv); if (!dai_drv) return -ENOMEM; diff --git a/sound/soc/codecs/es7134.c b/sound/soc/codecs/es7134.c index e3e6142ca0288c..f381a42ec42397 100644 --- a/sound/soc/codecs/es7134.c +++ b/sound/soc/codecs/es7134.c @@ -281,7 +281,7 @@ static int es7134_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct es7134_data *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/codecs/es7241.c b/sound/soc/codecs/es7241.c index a0bd5386387d48..76dc2461dd60f6 100644 --- a/sound/soc/codecs/es7241.c +++ b/sound/soc/codecs/es7241.c @@ -262,7 +262,7 @@ static int es7241_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct es7241_data *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/codecs/es8311.c b/sound/soc/codecs/es8311.c index ddbbfc2443b36b..0d7cf5fce59c78 100644 --- a/sound/soc/codecs/es8311.c +++ b/sound/soc/codecs/es8311.c @@ -950,7 +950,7 @@ static int es8311_i2c_probe(struct i2c_client *i2c_client) struct device *dev = &i2c_client->dev; - es8311 = devm_kzalloc(dev, sizeof(*es8311), GFP_KERNEL); + es8311 = devm_kzalloc_obj(dev, *es8311); if (es8311 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c index ded36a43065a07..470c503010fc1c 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -616,7 +616,7 @@ static void es8316_enable_micbias_for_mic_gnd_short_detect( snd_soc_dapm_sync_unlocked(dapm); snd_soc_dapm_mutex_unlock(dapm); - msleep(20); + msleep(100); } static void es8316_disable_micbias_for_mic_gnd_short_detect( @@ -866,8 +866,7 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client) struct es8316_priv *es8316; int ret; - es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), - GFP_KERNEL); + es8316 = devm_kzalloc_obj(&i2c_client->dev, struct es8316_priv); if (es8316 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/es8323.c b/sound/soc/codecs/es8323.c index 6a8d3902af2399..4cd9ddc4841257 100644 --- a/sound/soc/codecs/es8323.c +++ b/sound/soc/codecs/es8323.c @@ -772,7 +772,7 @@ static int es8323_i2c_probe(struct i2c_client *i2c_client) struct es8323_priv *es8323; struct device *dev = &i2c_client->dev; - es8323 = devm_kzalloc(dev, sizeof(*es8323), GFP_KERNEL); + es8323 = devm_kzalloc_obj(dev, *es8323); if (!es8323) return -ENOMEM; diff --git a/sound/soc/codecs/es8326.c b/sound/soc/codecs/es8326.c index a1b93f6fafd929..23e6f2c888ff4b 100644 --- a/sound/soc/codecs/es8326.c +++ b/sound/soc/codecs/es8326.c @@ -542,7 +542,7 @@ static const struct _coeff_div coeff_div_v3[] = { {256, 8000, 2048000, 0x60, 0x00, 0x31, 0x35, 0x08, 0x19, 0x1F, 0x7F}, {256, 16000, 4096000, 0x20, 0x00, 0x01, 0x35, 0x08, 0x19, 0x1F, 0x3F}, {256, 44100, 11289600, 0xE0, 0x01, 0x01, 0x2D, 0x48, 0x08, 0x1F, 0x1F}, - {256, 48000, 12288000, 0xE0, 0x01, 0x01, 0x2D, 0x48, 0x08, 0x1F, 0x1F}, + {256, 48000, 12288000, 0x01, 0x00, 0x10, 0x2D, 0x2A, 0x2A, 0x1F, 0x1F}, {288, 8000, 2304000, 0x20, 0x00, 0x01, 0x35, 0x8A, 0x1B, 0x23, 0x47}, {384, 8000, 3072000, 0x60, 0x02, 0x05, 0x75, 0x8A, 0x1B, 0x1F, 0x7F}, {384, 16000, 6144000, 0x20, 0x02, 0x03, 0x35, 0x8A, 0x1B, 0x1F, 0x3F}, @@ -785,7 +785,7 @@ static int es8326_mute(struct snd_soc_dai *dai, int mute, int direction) } queue_delayed_work(system_dfl_wq, &es8326->capture_pop_work, - msecs_to_jiffies(40)); + msecs_to_jiffies(100)); } } return 0; @@ -1155,7 +1155,7 @@ static int es8326_calibrate(struct snd_soc_component *component) regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, ES8326_HP_OFF); regmap_read(es8326->regmap, ES8326_CSM_MUTE_STA, ®); if ((reg & 0xf0) != 0x40) - msleep(50); + msleep(200); regmap_write(es8326->regmap, ES8326_HP_CAL, 0xd4); msleep(200); @@ -1256,6 +1256,8 @@ static void es8326_init(struct snd_soc_component *component) regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x73, 0x10); regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); } + regmap_update_bits(es8326->regmap, ES8326_ADC_HPFS1, 0x0f, 0x04); + regmap_update_bits(es8326->regmap, ES8326_ADC_HPFS2, 0x0f, 0x04); msleep(200); regmap_write(es8326->regmap, ES8326_INT_SOURCE, ES8326_INT_SRC_PIN9); @@ -1427,7 +1429,7 @@ static int es8326_i2c_probe(struct i2c_client *i2c) struct es8326_priv *es8326; int ret; - es8326 = devm_kzalloc(&i2c->dev, sizeof(struct es8326_priv), GFP_KERNEL); + es8326 = devm_kzalloc_obj(&i2c->dev, struct es8326_priv); if (!es8326) return -ENOMEM; diff --git a/sound/soc/codecs/es8328.c b/sound/soc/codecs/es8328.c index 95ffbe3f3a3587..554e0bd94d91aa 100644 --- a/sound/soc/codecs/es8328.c +++ b/sound/soc/codecs/es8328.c @@ -1082,7 +1082,7 @@ int es8328_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - es8328 = devm_kzalloc(dev, sizeof(*es8328), GFP_KERNEL); + es8328 = devm_kzalloc_obj(dev, *es8328); if (es8328 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/es8375.c b/sound/soc/codecs/es8375.c index 501a3eda5a89b1..7bb6c8d3a77889 100644 --- a/sound/soc/codecs/es8375.c +++ b/sound/soc/codecs/es8375.c @@ -708,7 +708,7 @@ static int es8375_i2c_probe(struct i2c_client *i2c_client) int ret; unsigned int val; - es8375 = devm_kzalloc(&i2c_client->dev, sizeof(*es8375), GFP_KERNEL); + es8375 = devm_kzalloc_obj(&i2c_client->dev, *es8375); if (!es8375) return -ENOMEM; diff --git a/sound/soc/codecs/es8389.c b/sound/soc/codecs/es8389.c index 2d60f753657ebc..1a8e56506fe3ac 100644 --- a/sound/soc/codecs/es8389.c +++ b/sound/soc/codecs/es8389.c @@ -1162,7 +1162,7 @@ static int es8389_i2c_probe(struct i2c_client *i2c_client) struct es8389_private *es8389; int ret, i; - es8389 = devm_kzalloc(&i2c_client->dev, sizeof(*es8389), GFP_KERNEL); + es8389 = devm_kzalloc_obj(&i2c_client->dev, *es8389); if (es8389 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/es9039q2m.c b/sound/soc/codecs/es9039q2m.c index bf206bf95ffdfd..2679d3c63cfc8c 100644 --- a/sound/soc/codecs/es9039q2m.c +++ b/sound/soc/codecs/es9039q2m.c @@ -1648,6 +1648,18 @@ static int es9039q2m_component_probe(struct snd_soc_component *component) if (ret) return ret; + /* + * Turn the DAC clock on. It is set at power-up, but suspend clears it + * and only resume sets it again, and a reset while asleep skips the + * resume without resetting this part. It then comes back gated: the + * stream runs, the part automutes, and the analogue output is silent + * until power is removed. + */ + ret = regmap_update_bits(priv->regmap, ES9039_SYS_MODE, + ES9039_ENABLE_DAC_CLK, ES9039_ENABLE_DAC_CLK); + if (ret) + return ret; + /* * Enable the datapath. SYSTEM_CONFIG[1] is clear at reset, so in * software mode nothing turns the DAC on at power-up: the analogue @@ -1925,7 +1937,7 @@ static int es9039q2m_i2c_probe(struct i2c_client *i2c) unsigned int id; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/es9356.c b/sound/soc/codecs/es9356.c index 277d0ae5666123..74c8978b534790 100644 --- a/sound/soc/codecs/es9356.c +++ b/sound/soc/codecs/es9356.c @@ -73,8 +73,8 @@ static int es9356_sdw_component_probe(struct snd_soc_component *component) } static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -9600, 12, 0); -static const DECLARE_TLV_DB_SCALE(amic_gain_tlv, 0, 3, 0); -static const DECLARE_TLV_DB_SCALE(dmic_gain_tlv, 0, 6, 0); +static const DECLARE_TLV_DB_SCALE(amic_gain_tlv, 0, 300, 0); +static const DECLARE_TLV_DB_SCALE(dmic_gain_tlv, 0, 600, 0); static const struct snd_kcontrol_new es9356_sdca_controls[] = { SDCA_SINGLE_Q78_TLV("FU41 Left Playback Volume", @@ -971,9 +971,8 @@ static int es9356_sdw_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(3) | BIT(4); nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -989,9 +988,8 @@ static int es9356_sdw_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -1092,7 +1090,7 @@ static int es9356_sdca_init(struct device *dev, struct regmap *regmap, struct sd struct es9356_sdw_priv *es9356; int ret; - es9356 = devm_kzalloc(dev, sizeof(*es9356), GFP_KERNEL); + es9356 = devm_kzalloc_obj(dev, *es9356); if (!es9356) return -ENOMEM; diff --git a/sound/soc/codecs/fm34ne-dsp.c b/sound/soc/codecs/fm34ne-dsp.c new file mode 100644 index 00000000000000..d506900eb8c43d --- /dev/null +++ b/sound/soc/codecs/fm34ne-dsp.c @@ -0,0 +1,388 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fm34ne-dsp.h" + +struct fm34ne_dsp { + struct i2c_client *client; + + struct gpio_desc *bypass_gpio; + struct gpio_desc *reset_gpio; + + struct clk *dap_mclk; + struct regulator *vdd_supply; + struct mutex lock; /* prevent simultaneous parameter writing */ + + const struct fm34ne_dsp_info *info; +}; + +static int fm34ne_dsp_set_config(struct fm34ne_dsp *dsp, enum dsp_state state) +{ + struct device *dev = &dsp->client->dev; + int ret; + + mutex_lock(&dsp->lock); + + gpiod_set_value_cansleep(dsp->bypass_gpio, 1); + msleep(20); + + switch (state) { + case FM34NE_NS_ENABLE: + ret = i2c_master_send(dsp->client, dsp->info->enable_parameter, + dsp->info->enable_parameter_length); + if (ret < 0) { + dev_err(dev, "Failed to set DSP enable %d\n", ret); + goto exit; + } + + ret = i2c_master_send(dsp->client, dsp->info->enable_noise_suppression, + dsp->info->enable_ns_length); + if (ret < 0) { + dev_err(dev, "Failed to enable DSP noise suppression %d\n", ret); + goto exit; + } + + break; + + case FM34NE_NS_DISABLE: + ret = i2c_master_send(dsp->client, dsp->info->enable_parameter, + dsp->info->enable_parameter_length); + if (ret < 0) { + dev_err(dev, "Failed to set DSP enable with %d\n", ret); + goto exit; + } + + ret = i2c_master_send(dsp->client, dsp->info->disable_noise_suppression, + dsp->info->disable_ns_length); + if (ret < 0) { + dev_err(dev, "Failed to disable DSP noise suppression with %d\n", ret); + goto exit; + } + + break; + + case FM34NE_BYPASS: + default: + ret = i2c_master_send(dsp->client, bypass_parameter, sizeof(bypass_parameter)); + if (ret < 0) { + dev_err(dev, "Failed to set DSP bypass with %d\n", ret); + goto exit; + } + + break; + } + +exit: + gpiod_set_value_cansleep(dsp->bypass_gpio, 0); + mutex_unlock(&dsp->lock); + + if (ret < 0) + return ret; + + return 0; +} + +static int fm34ne_dsp_ext_state_control(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component); + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + return fm34ne_dsp_set_config(dsp, FM34NE_BYPASS); + + default: + WARN(1, "Unexpected event"); + return -EINVAL; + } +} + +static int fm34ne_dsp_int_state_control(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component); + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + return fm34ne_dsp_set_config(dsp, FM34NE_NS_ENABLE); + + case SND_SOC_DAPM_PRE_PMD: + return fm34ne_dsp_set_config(dsp, FM34NE_NS_DISABLE); + + default: + WARN(1, "Unexpected event"); + return -EINVAL; + } +} + +static const struct snd_soc_dapm_widget fm34ne_dsp_dapm_widgets[] = { + SND_SOC_DAPM_INPUT("DSP DMIC"), + SND_SOC_DAPM_INPUT("DSP AMIC"), + + SND_SOC_DAPM_OUT_DRV_E("DSP Processing Engine INT", SND_SOC_NOPM, + 0, 0, NULL, 0, fm34ne_dsp_int_state_control, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_OUT_DRV_E("DSP Processing Engine EXT", SND_SOC_NOPM, + 0, 0, NULL, 0, fm34ne_dsp_ext_state_control, + SND_SOC_DAPM_POST_PMU), + + SND_SOC_DAPM_OUTPUT("DSP Digital Mic"), + SND_SOC_DAPM_OUTPUT("DSP Analog Mic"), +}; + +static const struct snd_soc_dapm_route fm34ne_dsp_dapm_routes[] = { + { "DSP Processing Engine INT", NULL, "DSP DMIC" }, + { "DSP Processing Engine EXT", NULL, "DSP AMIC" }, + { "DSP Digital Mic", NULL, "DSP Processing Engine INT" }, + { "DSP Analog Mic", NULL, "DSP Processing Engine EXT" }, +}; + +static int fm34ne_dsp_enable_hw(struct fm34ne_dsp *dsp) +{ + struct device *dev = &dsp->client->dev; + int ret; + + ret = clk_prepare_enable(dsp->dap_mclk); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable the DSP MCLK\n"); + + ret = regulator_enable(dsp->vdd_supply); + if (ret) { + clk_disable_unprepare(dsp->dap_mclk); + return dev_err_probe(dev, ret, "Failed to enable power supply\n"); + } + + /* Perform chip reset */ + gpiod_set_value_cansleep(dsp->reset_gpio, 1); + msleep(20); + gpiod_set_value_cansleep(dsp->reset_gpio, 0); + msleep(100); + + return 0; +} + +static void fm34ne_dsp_disable_hw(struct fm34ne_dsp *dsp) +{ + gpiod_set_value_cansleep(dsp->bypass_gpio, 0); + gpiod_set_value_cansleep(dsp->reset_gpio, 1); + + regulator_disable(dsp->vdd_supply); + clk_disable_unprepare(dsp->dap_mclk); +} + +static int fm34ne_dsp_probe(struct snd_soc_component *component) +{ + struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component); + int ret; + + ret = fm34ne_dsp_enable_hw(dsp); + if (ret) + return ret; + + gpiod_set_value_cansleep(dsp->bypass_gpio, 1); + msleep(20); + + ret = i2c_smbus_write_byte(dsp->client, FM34NE_BUF_ADDR); + if (ret < 0) { + dev_err(&dsp->client->dev, "Initial write failed, aborting\n"); + msleep(50); + goto exit; + } + + ret = i2c_master_send(dsp->client, dsp->info->input_parameter, + dsp->info->input_parameter_length); + if (ret < 0) + goto exit; + + msleep(100); + gpiod_set_value_cansleep(dsp->bypass_gpio, 0); + + /* Init DSP to bypass mode */ + ret = fm34ne_dsp_set_config(dsp, FM34NE_BYPASS); + if (ret < 0) + goto exit; + + return 0; + +exit: + fm34ne_dsp_disable_hw(dsp); + + return ret; +} + +static void fm34ne_dsp_remove(struct snd_soc_component *component) +{ + struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component); + + fm34ne_dsp_disable_hw(dsp); +} + +static const struct snd_soc_component_driver soc_component_fm34ne_dsp = { + .name = "fm34ne-dsp", + .probe = fm34ne_dsp_probe, + .remove = fm34ne_dsp_remove, + .dapm_widgets = fm34ne_dsp_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(fm34ne_dsp_dapm_widgets), + .dapm_routes = fm34ne_dsp_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(fm34ne_dsp_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, +}; + +static int fm34ne_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct fm34ne_dsp *dsp; + + dsp = devm_kzalloc(dev, sizeof(*dsp), GFP_KERNEL); + if (!dsp) + return -ENOMEM; + + i2c_set_clientdata(client, dsp); + dsp->client = client; + + dsp->info = device_get_match_data(dev); + if (!dsp->info) + return -ENODEV; + + dev_info(&dsp->client->dev, "%s detected\n", dsp->info->model); + + dsp->dap_mclk = devm_clk_get_optional(dev, NULL); + if (IS_ERR(dsp->dap_mclk)) + return dev_err_probe(dev, PTR_ERR(dsp->dap_mclk), + "Can't retrieve DSP mclk\n"); + + dsp->vdd_supply = devm_regulator_get(dev, "vdd"); + if (IS_ERR(dsp->vdd_supply)) + return dev_err_probe(dev, PTR_ERR(dsp->vdd_supply), + "Failed to get vdd regulator\n"); + + dsp->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(dsp->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(dsp->reset_gpio), + "Failed to get reset GPIO\n"); + + /* + * Bypass gpio is used to set audio into bypass mode in relation to dsp + * to be able to program it. Once programming is done, bypass gpio has + * to be set to low to return dsp into audio processing. + */ + dsp->bypass_gpio = devm_gpiod_get(dev, "bypass", GPIOD_OUT_LOW); + if (IS_ERR(dsp->bypass_gpio)) + return dev_err_probe(dev, PTR_ERR(dsp->bypass_gpio), + "Failed to get bypass GPIO\n"); + + mutex_init(&dsp->lock); + + return devm_snd_soc_register_component(dev, &soc_component_fm34ne_dsp, + NULL, 0); +} + +static const struct fm34ne_dsp_info tf101_dsp_info = { + .model = "ASUS Eee Pad Transformer TF101", + .enable_parameter = enable_parameter, + .enable_parameter_length = sizeof(enable_parameter), + .input_parameter = tf101_input_parameter, + .input_parameter_length = sizeof(tf101_input_parameter), + .enable_noise_suppression = tf101_enable_ns, + .enable_ns_length = sizeof(tf101_enable_ns), + .disable_noise_suppression = tf101_disable_ns, + .disable_ns_length = sizeof(tf101_disable_ns), +}; + +static const struct fm34ne_dsp_info sl101_dsp_info = { + .model = "ASUS Eee Pad Slider SL101", + .enable_parameter = sl101_enable_parameter, + .enable_parameter_length = sizeof(sl101_enable_parameter), + .input_parameter = sl101_input_parameter, + .input_parameter_length = sizeof(sl101_input_parameter), + .enable_noise_suppression = tf101_enable_ns, + .enable_ns_length = sizeof(tf101_enable_ns), + .disable_noise_suppression = tf101_disable_ns, + .disable_ns_length = sizeof(tf101_disable_ns), +}; + +static const struct fm34ne_dsp_info tf201_dsp_info = { + .model = "ASUS Transformer Prime TF201", + .enable_parameter = enable_parameter, + .enable_parameter_length = sizeof(enable_parameter), + .input_parameter = tf201_input_parameter, + .input_parameter_length = sizeof(tf201_input_parameter), + .enable_noise_suppression = tf201_enable_ns, + .enable_ns_length = sizeof(tf201_enable_ns), + .disable_noise_suppression = tf101_disable_ns, + .disable_ns_length = sizeof(tf101_disable_ns), +}; + +static const struct fm34ne_dsp_info tf300t_dsp_info = { + .model = "ASUS Transformer PAD TF300T", + .enable_parameter = enable_parameter, + .enable_parameter_length = sizeof(enable_parameter), + .input_parameter = tf300t_input_parameter, + .input_parameter_length = sizeof(tf300t_input_parameter), + .enable_noise_suppression = tf201_enable_ns, + .enable_ns_length = sizeof(tf201_enable_ns), + .disable_noise_suppression = tf101_disable_ns, + .disable_ns_length = sizeof(tf101_disable_ns), +}; + +static const struct fm34ne_dsp_info tf700t_dsp_info = { + .model = "ASUS Transformer Infinity TF700T", + .enable_parameter = enable_parameter, + .enable_parameter_length = sizeof(enable_parameter), + .input_parameter = tf700t_input_parameter, + .input_parameter_length = sizeof(tf700t_input_parameter), + .enable_noise_suppression = tf700t_enable_ns, + .enable_ns_length = sizeof(tf700t_enable_ns), + .disable_noise_suppression = tf700t_disable_ns, + .disable_ns_length = sizeof(tf700t_disable_ns), +}; + +static const struct fm34ne_dsp_info chagall_dsp_info = { + .model = "Pegatron Chagall", + .enable_parameter = enable_parameter, + .enable_parameter_length = sizeof(enable_parameter), + .input_parameter = tf300t_input_parameter, + .input_parameter_length = sizeof(tf300t_input_parameter), + .enable_noise_suppression = tf201_enable_ns, + .enable_ns_length = sizeof(tf201_enable_ns), + .disable_noise_suppression = tf101_disable_ns, + .disable_ns_length = sizeof(tf101_disable_ns), +}; + +static const struct of_device_id fm34ne_dsp_match_ids[] = { + { .compatible = "asus,sl101-dsp", .data = &sl101_dsp_info }, + { .compatible = "asus,tf101-dsp", .data = &tf101_dsp_info }, + { .compatible = "asus,tf201-dsp", .data = &tf201_dsp_info }, + { .compatible = "asus,tf300t-dsp", .data = &tf300t_dsp_info }, + { .compatible = "asus,tf700t-dsp", .data = &tf700t_dsp_info }, + { .compatible = "pegatron,chagall-dsp", .data = &chagall_dsp_info }, + { } +}; +MODULE_DEVICE_TABLE(of, fm34ne_dsp_match_ids); + +static struct i2c_driver fm34ne_dsp_driver = { + .driver = { + .name = "fm34ne-dsp", + .of_match_table = fm34ne_dsp_match_ids, + }, + .probe = fm34ne_probe, +}; +module_i2c_driver(fm34ne_dsp_driver); + +MODULE_AUTHOR("Svyatoslav Ryhel "); +MODULE_DESCRIPTION("Fortemedia FM34NE DSP driver"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/fm34ne-dsp.h b/sound/soc/codecs/fm34ne-dsp.h new file mode 100644 index 00000000000000..f63cbbe754538d --- /dev/null +++ b/sound/soc/codecs/fm34ne-dsp.h @@ -0,0 +1,1030 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __DSP_FM34NE_H__ +#define __DSP_FM34NE_H__ + +#define FM34NE_BUF_ADDR 0xc0 + +enum dsp_state { + FM34NE_BYPASS, + FM34NE_NS_ENABLE, + FM34NE_NS_DISABLE, + FM34NE_MAX, +}; + +struct fm34ne_dsp_info { + const char *model; + + const u8 *enable_parameter; + unsigned int enable_parameter_length; + + const u8 *input_parameter; + unsigned int input_parameter_length; + + const u8 *enable_noise_suppression; + unsigned int enable_ns_length; + + const u8 *disable_noise_suppression; + unsigned int disable_ns_length; +}; + +static const u8 bypass_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x04 +}; + +static const u8 enable_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x00 +}; + +static const u8 sl101_enable_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x0e, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x00 +}; + +static const u8 tf101_enable_ns[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10 +}; + +static const u8 tf201_enable_ns[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x01 +}; + +static const u8 tf700t_enable_ns[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x08, 0x00 +}; + +static const u8 tf101_disable_ns[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x00, 0x10 +}; + +static const u8 tf700t_disable_ns[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x00, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x15, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x7f, 0xff, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x10, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x84, 0x00, 0x03 +}; + +static const u8 sl101_input_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x68, 0x64, 0x04, + 0xfc, 0xf3, 0x0d, 0x10, 0x00, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x01, 0x82, 0x30, 0x50, + 0xfc, 0xf3, 0x0d, 0x10, 0x02, 0x27, 0x90, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x03, 0x19, 0x00, 0xa0, + 0xfc, 0xf3, 0x0d, 0x10, 0x04, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x05, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x06, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x07, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x08, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x09, 0x19, 0x01, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0a, 0x27, 0x90, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0b, 0x19, 0x01, 0x10, + 0xfc, 0xf3, 0x0d, 0x10, 0x0c, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x0d, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0e, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0f, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x10, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x11, 0x82, 0x2d, 0x20, + 0xfc, 0xf3, 0x0d, 0x10, 0x12, 0x27, 0x98, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x13, 0x19, 0x01, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x14, 0x80, 0x50, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x15, 0x90, 0x50, 0x3a, + 0xfc, 0xf3, 0x0d, 0x10, 0x16, 0x80, 0x50, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x17, 0x90, 0x50, 0x4f, + 0xfc, 0xf3, 0x0d, 0x10, 0x18, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x19, 0x19, 0x00, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1a, 0x80, 0x00, 0xac, + 0xfc, 0xf3, 0x0d, 0x10, 0x1b, 0x26, 0x7c, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x1d, 0x19, 0x1d, 0x82, + 0xfc, 0xf3, 0x0d, 0x10, 0x1e, 0x19, 0x1c, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x1f, 0x80, 0x53, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x20, 0x93, 0xe2, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x21, 0x80, 0x4f, 0xba, + 0xfc, 0xf3, 0x0d, 0x10, 0x22, 0x22, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x23, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x24, 0x18, 0x2f, 0xd0, + 0xfc, 0xf3, 0x0d, 0x10, 0x25, 0x94, 0x4f, 0xb6, + 0xfc, 0xf3, 0x0d, 0x10, 0x26, 0x80, 0x4f, 0x6a, + 0xfc, 0xf3, 0x0d, 0x10, 0x27, 0x26, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x28, 0x18, 0x2f, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x29, 0x18, 0x2b, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x2a, 0x95, 0x62, 0x06, + 0xfc, 0xf3, 0x0d, 0x10, 0x2b, 0x95, 0x61, 0x46, + 0xfc, 0xf3, 0x0d, 0x10, 0x2c, 0x40, 0xfa, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x2d, 0x40, 0xe5, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x2e, 0x82, 0x30, 0x14, + 0xfc, 0xf3, 0x0d, 0x10, 0x2f, 0x27, 0x00, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x30, 0x22, 0x78, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x31, 0x83, 0xfd, 0x44, + 0xfc, 0xf3, 0x0d, 0x10, 0x32, 0x26, 0xe2, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x33, 0x19, 0x03, 0x90, + 0xfc, 0xf3, 0x0d, 0x10, 0x34, 0x93, 0xfd, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x35, 0x83, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x36, 0x23, 0xa2, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x37, 0x93, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x38, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x39, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3a, 0x18, 0x3f, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3b, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3c, 0x19, 0x6c, 0xa4, + 0xfc, 0xf3, 0x0d, 0x10, 0x3d, 0x19, 0x66, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3e, 0x80, 0x79, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x3f, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x40, 0x27, 0x97, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x41, 0x19, 0x04, 0x40, + 0xfc, 0xf3, 0x0d, 0x10, 0x42, 0x94, 0x7b, 0xd6, + 0xfc, 0xf3, 0x0d, 0x10, 0x43, 0x80, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x44, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x45, 0x18, 0x48, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x46, 0x38, 0x00, 0x87, + 0xfc, 0xf3, 0x0d, 0x10, 0x47, 0x09, 0x00, 0x1b, + 0xfc, 0xf3, 0x0d, 0x10, 0x48, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x49, 0x18, 0x2d, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4a, 0x18, 0x21, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4b, 0x88, 0x4f, 0x47, + 0xfc, 0xf3, 0x0d, 0x10, 0x4c, 0x82, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x4d, 0x22, 0x62, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4e, 0x26, 0x62, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4f, 0x19, 0x05, 0x25, + 0xfc, 0xf3, 0x0d, 0x10, 0x50, 0x3b, 0xff, 0xc7, + 0xfc, 0xf3, 0x0d, 0x10, 0x51, 0x19, 0x05, 0x3f, + 0xfc, 0xf3, 0x0d, 0x10, 0x52, 0x0d, 0x01, 0xa6, + 0xfc, 0xf3, 0x0d, 0x10, 0x53, 0x92, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x54, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x55, 0x18, 0x23, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x56, 0x96, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x57, 0x96, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x58, 0x9a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x59, 0x9a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x5a, 0x96, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x5b, 0x38, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x5c, 0x83, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x5d, 0x3b, 0x20, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x5e, 0x36, 0x2b, 0x01, + 0xfc, 0xf3, 0x0d, 0x10, 0x5f, 0x36, 0x2b, 0x60, + 0xfc, 0xf3, 0x0d, 0x10, 0x60, 0x1c, 0x72, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x61, 0x93, 0xff, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x62, 0x93, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x63, 0x86, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x64, 0x86, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x65, 0x8a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x66, 0x8a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x67, 0x86, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x68, 0x0d, 0x08, 0x28, + 0xfc, 0xf3, 0x0d, 0x10, 0x69, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x6a, 0x18, 0x24, 0x0f, + 0xfc, 0xf3, 0x68, 0x64, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa0, 0x90, 0x05, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb0, 0x50, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa1, 0x91, 0xcb, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb1, 0x50, 0x1a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa2, 0x82, 0xf3, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb2, 0x02, 0xf5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa3, 0x82, 0xb5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb3, 0x50, 0x1f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa4, 0x83, 0xf4, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb4, 0x50, 0x2a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa5, 0x96, 0x66, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb5, 0x50, 0x3b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa6, 0x84, 0x8c, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb6, 0x50, 0x3e, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa7, 0xc4, 0x8c, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb7, 0x50, 0x3e, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa8, 0x82, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb8, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa9, 0xc2, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb9, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaa, 0xc2, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xba, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xab, 0x82, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbb, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xac, 0x82, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbc, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xad, 0xc2, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbd, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xae, 0x82, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbe, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaf, 0xc2, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbf, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x22, 0xf8, 0x80, 0x05, + 0xfc, 0xf3, 0x3b, 0x22, 0xc8, 0x00, 0x09, + 0xfc, 0xf3, 0x3b, 0x22, 0xee, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf9, 0x08, 0x5f, + 0xfc, 0xf3, 0x3b, 0x22, 0xfa, 0x24, 0x81, + 0xfc, 0xf3, 0x3b, 0x23, 0x05, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x01, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x09, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0d, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x0e, 0x20, + 0xfc, 0xf3, 0x3b, 0x22, 0xf2, 0x00, 0x44, + 0xfc, 0xf3, 0x3b, 0x22, 0xf6, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xc6, 0x00, 0x31, + 0xfc, 0xf3, 0x3b, 0x22, 0xc7, 0x00, 0x50, + 0xfc, 0xf3, 0x3b, 0x22, 0xd2, 0x82, 0x94, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x2f, 0x01, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x39, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x06, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x3c, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x33, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xb3, 0x00, 0x05, + 0xfc, 0xf3, 0x3b, 0x23, 0xb4, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x70, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xd2, 0x00, 0x32, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00 +}; + +static const u8 tf101_input_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x68, 0x64, 0x04, + 0xfc, 0xf3, 0x0d, 0x10, 0x00, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x01, 0x82, 0x30, 0x50, + 0xfc, 0xf3, 0x0d, 0x10, 0x02, 0x27, 0x90, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x03, 0x19, 0x00, 0xa0, + 0xfc, 0xf3, 0x0d, 0x10, 0x04, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x05, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x06, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x07, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x08, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x09, 0x19, 0x01, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0a, 0x27, 0x90, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0b, 0x19, 0x01, 0x10, + 0xfc, 0xf3, 0x0d, 0x10, 0x0c, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x0d, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0e, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0f, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x10, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x11, 0x82, 0x2d, 0x20, + 0xfc, 0xf3, 0x0d, 0x10, 0x12, 0x27, 0x98, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x13, 0x19, 0x01, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x14, 0x80, 0x50, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x15, 0x90, 0x50, 0x3a, + 0xfc, 0xf3, 0x0d, 0x10, 0x16, 0x80, 0x50, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x17, 0x90, 0x50, 0x4f, + 0xfc, 0xf3, 0x0d, 0x10, 0x18, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x19, 0x19, 0x00, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1a, 0x80, 0x00, 0xac, + 0xfc, 0xf3, 0x0d, 0x10, 0x1b, 0x26, 0x7c, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x1d, 0x19, 0x1d, 0x82, + 0xfc, 0xf3, 0x0d, 0x10, 0x1e, 0x19, 0x1c, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x1f, 0x80, 0x53, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x20, 0x93, 0xe2, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x21, 0x80, 0x4f, 0xba, + 0xfc, 0xf3, 0x0d, 0x10, 0x22, 0x22, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x23, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x24, 0x18, 0x2f, 0xd0, + 0xfc, 0xf3, 0x0d, 0x10, 0x25, 0x94, 0x4f, 0xb6, + 0xfc, 0xf3, 0x0d, 0x10, 0x26, 0x80, 0x4f, 0x6a, + 0xfc, 0xf3, 0x0d, 0x10, 0x27, 0x26, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x28, 0x18, 0x2f, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x29, 0x18, 0x2b, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x2a, 0x95, 0x62, 0x06, + 0xfc, 0xf3, 0x0d, 0x10, 0x2b, 0x95, 0x61, 0x46, + 0xfc, 0xf3, 0x0d, 0x10, 0x2c, 0x40, 0xfa, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x2d, 0x40, 0xe5, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x2e, 0x82, 0x30, 0x14, + 0xfc, 0xf3, 0x0d, 0x10, 0x2f, 0x27, 0x00, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x30, 0x22, 0x78, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x31, 0x83, 0xfd, 0x44, + 0xfc, 0xf3, 0x0d, 0x10, 0x32, 0x26, 0xe2, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x33, 0x19, 0x03, 0x90, + 0xfc, 0xf3, 0x0d, 0x10, 0x34, 0x93, 0xfd, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x35, 0x83, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x36, 0x23, 0xa2, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x37, 0x93, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x38, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x39, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3a, 0x18, 0x3f, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3b, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3c, 0x19, 0x6c, 0xa4, + 0xfc, 0xf3, 0x0d, 0x10, 0x3d, 0x19, 0x66, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3e, 0x80, 0x79, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x3f, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x40, 0x27, 0x97, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x41, 0x19, 0x04, 0x40, + 0xfc, 0xf3, 0x0d, 0x10, 0x42, 0x94, 0x7b, 0xd6, + 0xfc, 0xf3, 0x0d, 0x10, 0x43, 0x80, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x44, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x45, 0x18, 0x48, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x46, 0x38, 0x00, 0x87, + 0xfc, 0xf3, 0x0d, 0x10, 0x47, 0x09, 0x00, 0x1b, + 0xfc, 0xf3, 0x0d, 0x10, 0x48, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x49, 0x18, 0x2d, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4a, 0x18, 0x21, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4b, 0x88, 0x4f, 0x47, + 0xfc, 0xf3, 0x0d, 0x10, 0x4c, 0x82, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x4d, 0x22, 0x62, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4e, 0x26, 0x62, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4f, 0x19, 0x05, 0x25, + 0xfc, 0xf3, 0x0d, 0x10, 0x50, 0x3b, 0xff, 0xc7, + 0xfc, 0xf3, 0x0d, 0x10, 0x51, 0x19, 0x05, 0x3f, + 0xfc, 0xf3, 0x0d, 0x10, 0x52, 0x0d, 0x01, 0xa6, + 0xfc, 0xf3, 0x0d, 0x10, 0x53, 0x92, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x54, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x55, 0x18, 0x23, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x56, 0x96, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x57, 0x96, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x58, 0x9a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x59, 0x9a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x5a, 0x96, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x5b, 0x38, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x5c, 0x83, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x5d, 0x3b, 0x20, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x5e, 0x36, 0x2b, 0x01, + 0xfc, 0xf3, 0x0d, 0x10, 0x5f, 0x36, 0x2b, 0x60, + 0xfc, 0xf3, 0x0d, 0x10, 0x60, 0x1c, 0x72, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x61, 0x93, 0xff, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x62, 0x93, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x63, 0x86, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x64, 0x86, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x65, 0x8a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x66, 0x8a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x67, 0x86, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x68, 0x0d, 0x08, 0x28, + 0xfc, 0xf3, 0x0d, 0x10, 0x69, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x6a, 0x18, 0x24, 0x0f, + 0xfc, 0xf3, 0x68, 0x64, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa0, 0x90, 0x05, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb0, 0x50, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa1, 0x91, 0xcb, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb1, 0x50, 0x1a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa2, 0x82, 0xf3, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb2, 0x02, 0xf5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa3, 0x82, 0xb5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb3, 0x50, 0x1f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa4, 0x83, 0xf4, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb4, 0x50, 0x2a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa5, 0x96, 0x66, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb5, 0x50, 0x3b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa6, 0x84, 0x8c, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb6, 0x50, 0x3e, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa7, 0xc4, 0x8c, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb7, 0x50, 0x3e, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa8, 0x82, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb8, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa9, 0xc2, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb9, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaa, 0xc2, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xba, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xab, 0x82, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbb, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xac, 0x82, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbc, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xad, 0xc2, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbd, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xae, 0x82, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbe, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaf, 0xc2, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbf, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x22, 0xf8, 0x80, 0x05, + 0xfc, 0xf3, 0x3b, 0x22, 0xc8, 0x00, 0x09, + 0xfc, 0xf3, 0x3b, 0x22, 0xee, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf9, 0x08, 0x5f, + 0xfc, 0xf3, 0x3b, 0x22, 0xfa, 0x24, 0x81, + 0xfc, 0xf3, 0x3b, 0x23, 0x05, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x01, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x09, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0d, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x0e, 0x20, + 0xfc, 0xf3, 0x3b, 0x22, 0xf2, 0x00, 0x44, + 0xfc, 0xf3, 0x3b, 0x22, 0xf6, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xc6, 0x00, 0x31, + 0xfc, 0xf3, 0x3b, 0x22, 0xc7, 0x00, 0x50, + 0xfc, 0xf3, 0x3b, 0x22, 0xd2, 0x82, 0x94, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x2f, 0x01, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x39, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x06, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x3c, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x20, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x33, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xb3, 0x00, 0x0a, + 0xfc, 0xf3, 0x3b, 0x23, 0xb4, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x70, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xd2, 0x00, 0x32, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00 +}; + +static const u8 tf201_input_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x68, 0x64, 0x04, + 0xfc, 0xf3, 0x0d, 0x10, 0x00, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x01, 0x82, 0x30, 0x50, + 0xfc, 0xf3, 0x0d, 0x10, 0x02, 0x27, 0x90, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x03, 0x19, 0x00, 0xa0, + 0xfc, 0xf3, 0x0d, 0x10, 0x04, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x05, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x06, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x07, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x08, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x09, 0x19, 0x01, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0a, 0x27, 0x90, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0b, 0x19, 0x01, 0x10, + 0xfc, 0xf3, 0x0d, 0x10, 0x0c, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x0d, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0e, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0f, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x10, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x11, 0x82, 0x2d, 0x20, + 0xfc, 0xf3, 0x0d, 0x10, 0x12, 0x27, 0x98, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x13, 0x19, 0x01, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x14, 0x80, 0x50, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x15, 0x90, 0x50, 0x3a, + 0xfc, 0xf3, 0x0d, 0x10, 0x16, 0x80, 0x50, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x17, 0x90, 0x50, 0x4f, + 0xfc, 0xf3, 0x0d, 0x10, 0x18, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x19, 0x19, 0x00, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1a, 0x80, 0x00, 0xac, + 0xfc, 0xf3, 0x0d, 0x10, 0x1b, 0x26, 0x7c, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x1d, 0x19, 0x1d, 0x82, + 0xfc, 0xf3, 0x0d, 0x10, 0x1e, 0x19, 0x1c, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x1f, 0x80, 0x53, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x20, 0x93, 0xe2, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x21, 0x80, 0x4f, 0xba, + 0xfc, 0xf3, 0x0d, 0x10, 0x22, 0x22, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x23, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x24, 0x18, 0x2f, 0xd0, + 0xfc, 0xf3, 0x0d, 0x10, 0x25, 0x94, 0x4f, 0xb6, + 0xfc, 0xf3, 0x0d, 0x10, 0x26, 0x80, 0x4f, 0x6a, + 0xfc, 0xf3, 0x0d, 0x10, 0x27, 0x26, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x28, 0x18, 0x2f, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x29, 0x18, 0x2b, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x2a, 0x95, 0x62, 0x06, + 0xfc, 0xf3, 0x0d, 0x10, 0x2b, 0x95, 0x61, 0x46, + 0xfc, 0xf3, 0x0d, 0x10, 0x2c, 0x40, 0xfa, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x2d, 0x40, 0xe5, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x2e, 0x82, 0x30, 0x14, + 0xfc, 0xf3, 0x0d, 0x10, 0x2f, 0x27, 0x00, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x30, 0x22, 0x78, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x31, 0x83, 0xfd, 0x44, + 0xfc, 0xf3, 0x0d, 0x10, 0x32, 0x26, 0xe2, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x33, 0x19, 0x03, 0x90, + 0xfc, 0xf3, 0x0d, 0x10, 0x34, 0x93, 0xfd, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x35, 0x83, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x36, 0x23, 0xa2, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x37, 0x93, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x38, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x39, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3a, 0x18, 0x3f, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3b, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3c, 0x19, 0x6c, 0xa4, + 0xfc, 0xf3, 0x0d, 0x10, 0x3d, 0x19, 0x66, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3e, 0x80, 0x79, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x3f, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x40, 0x27, 0x97, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x41, 0x19, 0x04, 0x40, + 0xfc, 0xf3, 0x0d, 0x10, 0x42, 0x94, 0x7b, 0xd6, + 0xfc, 0xf3, 0x0d, 0x10, 0x43, 0x80, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x44, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x45, 0x18, 0x48, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x46, 0x38, 0x00, 0x87, + 0xfc, 0xf3, 0x0d, 0x10, 0x47, 0x09, 0x00, 0x1b, + 0xfc, 0xf3, 0x0d, 0x10, 0x48, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x49, 0x18, 0x2d, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4a, 0x18, 0x21, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4b, 0x88, 0x4f, 0x47, + 0xfc, 0xf3, 0x0d, 0x10, 0x4c, 0x82, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x4d, 0x22, 0x62, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4e, 0x26, 0x62, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4f, 0x19, 0x05, 0x25, + 0xfc, 0xf3, 0x0d, 0x10, 0x50, 0x3b, 0xff, 0xc7, + 0xfc, 0xf3, 0x0d, 0x10, 0x51, 0x19, 0x05, 0x3f, + 0xfc, 0xf3, 0x0d, 0x10, 0x52, 0x0d, 0x01, 0xa6, + 0xfc, 0xf3, 0x0d, 0x10, 0x53, 0x92, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x54, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x55, 0x18, 0x23, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x56, 0x96, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x57, 0x96, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x58, 0x9a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x59, 0x9a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x5a, 0x96, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x5b, 0x38, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x5c, 0x83, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x5d, 0x3b, 0x20, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x5e, 0x36, 0x2b, 0x01, + 0xfc, 0xf3, 0x0d, 0x10, 0x5f, 0x36, 0x2b, 0x60, + 0xfc, 0xf3, 0x0d, 0x10, 0x60, 0x1c, 0x72, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x61, 0x93, 0xff, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x62, 0x93, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x63, 0x86, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x64, 0x86, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x65, 0x8a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x66, 0x8a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x67, 0x86, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x68, 0x0d, 0x08, 0x28, + 0xfc, 0xf3, 0x0d, 0x10, 0x69, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x6a, 0x18, 0x24, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6b, 0x83, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x6c, 0x23, 0x8a, 0xbf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6d, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6e, 0x27, 0x97, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6f, 0x23, 0xaa, 0x91, + 0xfc, 0xf3, 0x0d, 0x10, 0x70, 0x93, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x71, 0x83, 0x80, 0x30, + 0xfc, 0xf3, 0x0d, 0x10, 0x72, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x73, 0x18, 0x3e, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x74, 0x80, 0x7a, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x75, 0x19, 0x07, 0xe2, + 0xfc, 0xf3, 0x0d, 0x10, 0x76, 0x23, 0x3e, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x77, 0x0d, 0x00, 0xea, + 0xfc, 0xf3, 0x0d, 0x10, 0x78, 0x80, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x79, 0x38, 0x7e, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x7a, 0x1c, 0x76, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x7b, 0x90, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x7c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7d, 0x19, 0x75, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x7e, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7f, 0x19, 0x75, 0x9f, + 0xfc, 0xf3, 0x68, 0x64, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa0, 0x91, 0xcb, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb0, 0x50, 0x1a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa1, 0x82, 0xf3, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb1, 0x02, 0xf5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa2, 0x82, 0xb5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb2, 0x50, 0x1f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa3, 0x83, 0xf4, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb3, 0x50, 0x2a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa4, 0x96, 0x66, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb4, 0x50, 0x3b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa5, 0x82, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb5, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa6, 0xc2, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb6, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa7, 0xc2, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb7, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa8, 0x82, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb8, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa9, 0x82, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb9, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaa, 0xc2, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xba, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xab, 0x82, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbb, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xac, 0xc2, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbc, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xad, 0x83, 0xe8, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbd, 0x50, 0x6b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xae, 0x97, 0x58, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbe, 0x50, 0x74, + 0xfc, 0xf3, 0x3b, 0x22, 0xf8, 0x80, 0x05, + 0xfc, 0xf3, 0x3b, 0x22, 0xc8, 0x00, 0x29, + 0xfc, 0xf3, 0x3b, 0x22, 0xee, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf9, 0x08, 0x5f, + 0xfc, 0xf3, 0x3b, 0x22, 0xfa, 0x24, 0x81, + 0xfc, 0xf3, 0x3b, 0x23, 0x05, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x01, 0x00, 0x02, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x09, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0d, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf2, 0x00, 0x44, + 0xfc, 0xf3, 0x3b, 0x22, 0xf6, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xc6, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x22, 0xc7, 0x00, 0x08, + 0xfc, 0xf3, 0x3b, 0x22, 0xd2, 0x8a, 0x94, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x04, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x2f, 0x01, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x39, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x06, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x3c, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x20, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x33, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xb3, 0x00, 0x0a, + 0xfc, 0xf3, 0x3b, 0x23, 0xb4, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x70, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xd2, 0x00, 0x32, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00 +}; + +static const u8 tf300t_input_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x68, 0x64, 0x04, + 0xfc, 0xf3, 0x0d, 0x10, 0x00, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x01, 0x82, 0x30, 0x50, + 0xfc, 0xf3, 0x0d, 0x10, 0x02, 0x27, 0x90, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x03, 0x19, 0x00, 0xa0, + 0xfc, 0xf3, 0x0d, 0x10, 0x04, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x05, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x06, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x07, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x08, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x09, 0x19, 0x01, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0a, 0x27, 0x90, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0b, 0x19, 0x01, 0x10, + 0xfc, 0xf3, 0x0d, 0x10, 0x0c, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x0d, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0e, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0f, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x10, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x11, 0x82, 0x2d, 0x20, + 0xfc, 0xf3, 0x0d, 0x10, 0x12, 0x27, 0x98, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x13, 0x19, 0x01, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x14, 0x80, 0x50, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x15, 0x90, 0x50, 0x3a, + 0xfc, 0xf3, 0x0d, 0x10, 0x16, 0x80, 0x50, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x17, 0x90, 0x50, 0x4f, + 0xfc, 0xf3, 0x0d, 0x10, 0x18, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x19, 0x19, 0x00, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1a, 0x80, 0x00, 0xac, + 0xfc, 0xf3, 0x0d, 0x10, 0x1b, 0x26, 0x7c, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x1d, 0x19, 0x1d, 0x82, + 0xfc, 0xf3, 0x0d, 0x10, 0x1e, 0x19, 0x1c, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x1f, 0x80, 0x53, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x20, 0x93, 0xe2, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x21, 0x80, 0x4f, 0xba, + 0xfc, 0xf3, 0x0d, 0x10, 0x22, 0x22, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x23, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x24, 0x18, 0x2f, 0xd0, + 0xfc, 0xf3, 0x0d, 0x10, 0x25, 0x94, 0x4f, 0xb6, + 0xfc, 0xf3, 0x0d, 0x10, 0x26, 0x80, 0x4f, 0x6a, + 0xfc, 0xf3, 0x0d, 0x10, 0x27, 0x26, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x28, 0x18, 0x2f, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x29, 0x18, 0x2b, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x2a, 0x95, 0x62, 0x06, + 0xfc, 0xf3, 0x0d, 0x10, 0x2b, 0x95, 0x61, 0x46, + 0xfc, 0xf3, 0x0d, 0x10, 0x2c, 0x40, 0xfa, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x2d, 0x40, 0xe5, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x2e, 0x82, 0x30, 0x14, + 0xfc, 0xf3, 0x0d, 0x10, 0x2f, 0x27, 0x00, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x30, 0x22, 0x78, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x31, 0x83, 0xfd, 0x44, + 0xfc, 0xf3, 0x0d, 0x10, 0x32, 0x26, 0xe2, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x33, 0x19, 0x03, 0x90, + 0xfc, 0xf3, 0x0d, 0x10, 0x34, 0x93, 0xfd, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x35, 0x83, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x36, 0x23, 0xa2, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x37, 0x93, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x38, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x39, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3a, 0x18, 0x3f, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3b, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3c, 0x19, 0x6c, 0xa4, + 0xfc, 0xf3, 0x0d, 0x10, 0x3d, 0x19, 0x66, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3e, 0x80, 0x79, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x3f, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x40, 0x27, 0x97, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x41, 0x19, 0x04, 0x40, + 0xfc, 0xf3, 0x0d, 0x10, 0x42, 0x94, 0x7b, 0xd6, + 0xfc, 0xf3, 0x0d, 0x10, 0x43, 0x80, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x44, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x45, 0x18, 0x48, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x46, 0x38, 0x00, 0x87, + 0xfc, 0xf3, 0x0d, 0x10, 0x47, 0x09, 0x00, 0x1b, + 0xfc, 0xf3, 0x0d, 0x10, 0x48, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x49, 0x18, 0x2d, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4a, 0x18, 0x21, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4b, 0x88, 0x4f, 0x47, + 0xfc, 0xf3, 0x0d, 0x10, 0x4c, 0x82, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x4d, 0x22, 0x62, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4e, 0x26, 0x62, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4f, 0x19, 0x05, 0x25, + 0xfc, 0xf3, 0x0d, 0x10, 0x50, 0x3b, 0xff, 0xc7, + 0xfc, 0xf3, 0x0d, 0x10, 0x51, 0x19, 0x05, 0x3f, + 0xfc, 0xf3, 0x0d, 0x10, 0x52, 0x0d, 0x01, 0xa6, + 0xfc, 0xf3, 0x0d, 0x10, 0x53, 0x92, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x54, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x55, 0x18, 0x23, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x56, 0x96, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x57, 0x96, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x58, 0x9a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x59, 0x9a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x5a, 0x96, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x5b, 0x38, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x5c, 0x83, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x5d, 0x3b, 0x20, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x5e, 0x36, 0x2b, 0x01, + 0xfc, 0xf3, 0x0d, 0x10, 0x5f, 0x36, 0x2b, 0x60, + 0xfc, 0xf3, 0x0d, 0x10, 0x60, 0x1c, 0x72, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x61, 0x93, 0xff, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x62, 0x93, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x63, 0x86, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x64, 0x86, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x65, 0x8a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x66, 0x8a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x67, 0x86, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x68, 0x0d, 0x08, 0x28, + 0xfc, 0xf3, 0x0d, 0x10, 0x69, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x6a, 0x18, 0x24, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6b, 0x83, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x6c, 0x23, 0x8a, 0xbf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6d, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6e, 0x27, 0x97, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6f, 0x23, 0xaa, 0x91, + 0xfc, 0xf3, 0x0d, 0x10, 0x70, 0x93, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x71, 0x83, 0x80, 0x30, + 0xfc, 0xf3, 0x0d, 0x10, 0x72, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x73, 0x18, 0x3e, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x74, 0x80, 0x7a, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x75, 0x19, 0x07, 0xe2, + 0xfc, 0xf3, 0x0d, 0x10, 0x76, 0x23, 0x3e, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x77, 0x0d, 0x00, 0xea, + 0xfc, 0xf3, 0x0d, 0x10, 0x78, 0x80, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x79, 0x38, 0x7e, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x7a, 0x1c, 0x76, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x7b, 0x90, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x7c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7d, 0x19, 0x75, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x7e, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7f, 0x19, 0x75, 0x9f, + 0xfc, 0xf3, 0x68, 0x64, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa0, 0x91, 0xcb, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb0, 0x50, 0x1a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa1, 0x82, 0xf3, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb1, 0x02, 0xf5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa2, 0x82, 0xb5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb2, 0x50, 0x1f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa3, 0x83, 0xf4, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb3, 0x50, 0x2a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa4, 0x96, 0x66, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb4, 0x50, 0x3b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa5, 0x82, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb5, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa6, 0xc2, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb6, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa7, 0xc2, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb7, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa8, 0x82, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb8, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa9, 0x82, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb9, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaa, 0xc2, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xba, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xab, 0x82, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbb, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xac, 0xc2, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbc, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xad, 0x83, 0xe8, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbd, 0x50, 0x6b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xae, 0x97, 0x58, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbe, 0x50, 0x74, + 0xfc, 0xf3, 0x3b, 0x22, 0xf8, 0x80, 0x05, + 0xfc, 0xf3, 0x3b, 0x22, 0xc8, 0x00, 0x29, + 0xfc, 0xf3, 0x3b, 0x22, 0xee, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf9, 0x08, 0x5f, + 0xfc, 0xf3, 0x3b, 0x22, 0xfa, 0x24, 0x81, + 0xfc, 0xf3, 0x3b, 0x23, 0x05, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x01, 0x00, 0x02, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x09, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0d, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x0e, 0x20, + 0xfc, 0xf3, 0x3b, 0x22, 0xf2, 0x00, 0x44, + 0xfc, 0xf3, 0x3b, 0x22, 0xf6, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xc6, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x22, 0xc7, 0x00, 0x08, + 0xfc, 0xf3, 0x3b, 0x22, 0xd2, 0x8a, 0x94, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x04, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x2f, 0x01, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x39, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x06, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x3c, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x20, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x33, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xb3, 0x00, 0x0a, + 0xfc, 0xf3, 0x3b, 0x23, 0xb4, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x70, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xd2, 0x00, 0x32, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00 +}; + +static const u8 tf700t_input_parameter[] = { + FM34NE_BUF_ADDR, + 0xfc, 0xf3, 0x68, 0x64, 0x04, + 0xfc, 0xf3, 0x0d, 0x10, 0x00, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x01, 0x82, 0x30, 0x50, + 0xfc, 0xf3, 0x0d, 0x10, 0x02, 0x27, 0x90, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x03, 0x19, 0x00, 0xa0, + 0xfc, 0xf3, 0x0d, 0x10, 0x04, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x05, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x06, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x07, 0x1c, 0x5a, 0xaf, + 0xfc, 0xf3, 0x0d, 0x10, 0x08, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x09, 0x19, 0x01, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0a, 0x27, 0x90, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x0b, 0x19, 0x01, 0x10, + 0xfc, 0xf3, 0x0d, 0x10, 0x0c, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x0d, 0x90, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0e, 0x80, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x0f, 0x1c, 0x58, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x10, 0x90, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x11, 0x82, 0x2d, 0x20, + 0xfc, 0xf3, 0x0d, 0x10, 0x12, 0x27, 0x98, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x13, 0x19, 0x01, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x14, 0x80, 0x50, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x15, 0x90, 0x50, 0x3a, + 0xfc, 0xf3, 0x0d, 0x10, 0x16, 0x80, 0x50, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x17, 0x90, 0x50, 0x4f, + 0xfc, 0xf3, 0x0d, 0x10, 0x18, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x19, 0x19, 0x00, 0x6f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1a, 0x80, 0x00, 0xac, + 0xfc, 0xf3, 0x0d, 0x10, 0x1b, 0x26, 0x7c, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x1c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x1d, 0x19, 0x1d, 0x82, + 0xfc, 0xf3, 0x0d, 0x10, 0x1e, 0x19, 0x1c, 0xef, + 0xfc, 0xf3, 0x0d, 0x10, 0x1f, 0x80, 0x53, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x20, 0x93, 0xe2, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x21, 0x80, 0x4f, 0xba, + 0xfc, 0xf3, 0x0d, 0x10, 0x22, 0x22, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x23, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x24, 0x18, 0x2f, 0xd0, + 0xfc, 0xf3, 0x0d, 0x10, 0x25, 0x94, 0x4f, 0xb6, + 0xfc, 0xf3, 0x0d, 0x10, 0x26, 0x80, 0x4f, 0x6a, + 0xfc, 0xf3, 0x0d, 0x10, 0x27, 0x26, 0x7a, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x28, 0x18, 0x2f, 0x80, + 0xfc, 0xf3, 0x0d, 0x10, 0x29, 0x18, 0x2b, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x2a, 0x95, 0x62, 0x06, + 0xfc, 0xf3, 0x0d, 0x10, 0x2b, 0x95, 0x61, 0x46, + 0xfc, 0xf3, 0x0d, 0x10, 0x2c, 0x40, 0xfa, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x2d, 0x40, 0xe5, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x2e, 0x82, 0x30, 0x14, + 0xfc, 0xf3, 0x0d, 0x10, 0x2f, 0x27, 0x00, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x30, 0x22, 0x78, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x31, 0x83, 0xfd, 0x44, + 0xfc, 0xf3, 0x0d, 0x10, 0x32, 0x26, 0xe2, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x33, 0x19, 0x03, 0x90, + 0xfc, 0xf3, 0x0d, 0x10, 0x34, 0x93, 0xfd, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x35, 0x83, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x36, 0x23, 0xa2, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x37, 0x93, 0xfd, 0x5a, + 0xfc, 0xf3, 0x0d, 0x10, 0x38, 0x00, 0x00, 0x00, + 0xfc, 0xf3, 0x0d, 0x10, 0x39, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3a, 0x18, 0x3f, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3b, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x3c, 0x19, 0x6c, 0xa4, + 0xfc, 0xf3, 0x0d, 0x10, 0x3d, 0x19, 0x66, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x3e, 0x80, 0x79, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x3f, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x40, 0x27, 0x97, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x41, 0x19, 0x04, 0x40, + 0xfc, 0xf3, 0x0d, 0x10, 0x42, 0x94, 0x7b, 0xd6, + 0xfc, 0xf3, 0x0d, 0x10, 0x43, 0x80, 0x00, 0x1a, + 0xfc, 0xf3, 0x0d, 0x10, 0x44, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x45, 0x18, 0x48, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x46, 0x38, 0x00, 0x87, + 0xfc, 0xf3, 0x0d, 0x10, 0x47, 0x09, 0x00, 0x1b, + 0xfc, 0xf3, 0x0d, 0x10, 0x48, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x49, 0x18, 0x2d, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4a, 0x18, 0x21, 0x5f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4b, 0x88, 0x4f, 0x47, + 0xfc, 0xf3, 0x0d, 0x10, 0x4c, 0x82, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x4d, 0x22, 0x62, 0x1f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4e, 0x26, 0x62, 0x7f, + 0xfc, 0xf3, 0x0d, 0x10, 0x4f, 0x19, 0x05, 0x25, + 0xfc, 0xf3, 0x0d, 0x10, 0x50, 0x3b, 0xff, 0xc7, + 0xfc, 0xf3, 0x0d, 0x10, 0x51, 0x19, 0x05, 0x3f, + 0xfc, 0xf3, 0x0d, 0x10, 0x52, 0x0d, 0x01, 0xa6, + 0xfc, 0xf3, 0x0d, 0x10, 0x53, 0x92, 0x2a, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x54, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x55, 0x18, 0x23, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x56, 0x96, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x57, 0x96, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x58, 0x9a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x59, 0x9a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x5a, 0x96, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x5b, 0x38, 0x00, 0x0a, + 0xfc, 0xf3, 0x0d, 0x10, 0x5c, 0x83, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x5d, 0x3b, 0x20, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x5e, 0x36, 0x2b, 0x01, + 0xfc, 0xf3, 0x0d, 0x10, 0x5f, 0x36, 0x2b, 0x60, + 0xfc, 0xf3, 0x0d, 0x10, 0x60, 0x1c, 0x72, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x61, 0x93, 0xff, 0x9a, + 0xfc, 0xf3, 0x0d, 0x10, 0x62, 0x93, 0xff, 0xaa, + 0xfc, 0xf3, 0x0d, 0x10, 0x63, 0x86, 0x2a, 0xa1, + 0xfc, 0xf3, 0x0d, 0x10, 0x64, 0x86, 0x2a, 0xb0, + 0xfc, 0xf3, 0x0d, 0x10, 0x65, 0x8a, 0x2a, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x66, 0x8a, 0x2a, 0xd7, + 0xfc, 0xf3, 0x0d, 0x10, 0x67, 0x86, 0x2a, 0xe8, + 0xfc, 0xf3, 0x0d, 0x10, 0x68, 0x0d, 0x08, 0x28, + 0xfc, 0xf3, 0x0d, 0x10, 0x69, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x6a, 0x18, 0x24, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6b, 0x83, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x6c, 0x23, 0x8a, 0xbf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6d, 0x82, 0x2d, 0x2f, + 0xfc, 0xf3, 0x0d, 0x10, 0x6e, 0x27, 0x97, 0xdf, + 0xfc, 0xf3, 0x0d, 0x10, 0x6f, 0x23, 0xaa, 0x91, + 0xfc, 0xf3, 0x0d, 0x10, 0x70, 0x93, 0xfc, 0xfa, + 0xfc, 0xf3, 0x0d, 0x10, 0x71, 0x83, 0x80, 0x30, + 0xfc, 0xf3, 0x0d, 0x10, 0x72, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x73, 0x18, 0x3e, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x74, 0x80, 0x7a, 0x4a, + 0xfc, 0xf3, 0x0d, 0x10, 0x75, 0x19, 0x07, 0xe2, + 0xfc, 0xf3, 0x0d, 0x10, 0x76, 0x23, 0x3e, 0x0f, + 0xfc, 0xf3, 0x0d, 0x10, 0x77, 0x0d, 0x00, 0xea, + 0xfc, 0xf3, 0x0d, 0x10, 0x78, 0x80, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x79, 0x38, 0x7e, 0x02, + 0xfc, 0xf3, 0x0d, 0x10, 0x7a, 0x1c, 0x76, 0x9f, + 0xfc, 0xf3, 0x0d, 0x10, 0x7b, 0x90, 0x7b, 0xca, + 0xfc, 0xf3, 0x0d, 0x10, 0x7c, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7d, 0x19, 0x75, 0xcf, + 0xfc, 0xf3, 0x0d, 0x10, 0x7e, 0x34, 0x00, 0x0e, + 0xfc, 0xf3, 0x0d, 0x10, 0x7f, 0x19, 0x75, 0x9f, + 0xfc, 0xf3, 0x68, 0x64, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa0, 0x91, 0xcb, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb0, 0x50, 0x1a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa1, 0x82, 0xf3, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb1, 0x02, 0xf5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa2, 0x82, 0xb5, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb2, 0x50, 0x1f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa3, 0x83, 0xf4, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb3, 0x50, 0x2a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa4, 0x96, 0x66, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb4, 0x50, 0x3b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa5, 0x82, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb5, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa6, 0xc2, 0xcc, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb6, 0x50, 0x46, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa7, 0xc2, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb7, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa8, 0x82, 0x10, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb8, 0x50, 0x4a, + 0xfc, 0xf3, 0x3b, 0x3f, 0xa9, 0x82, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xb9, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xaa, 0xc2, 0x31, + 0xfc, 0xf3, 0x3b, 0x3f, 0xba, 0x50, 0x4b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xab, 0x82, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbb, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xac, 0xc2, 0x3f, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbc, 0x50, 0x56, + 0xfc, 0xf3, 0x3b, 0x3f, 0xad, 0x83, 0xe8, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbd, 0x50, 0x6b, + 0xfc, 0xf3, 0x3b, 0x3f, 0xae, 0x97, 0x58, + 0xfc, 0xf3, 0x3b, 0x3f, 0xbe, 0x50, 0x74, + 0xfc, 0xf3, 0x3b, 0x22, 0xf8, 0x80, 0x05, + 0xfc, 0xf3, 0x3b, 0x22, 0xc8, 0x00, 0x29, + 0xfc, 0xf3, 0x3b, 0x22, 0xee, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xf9, 0x08, 0x5f, + 0xfc, 0xf3, 0x3b, 0x22, 0xfa, 0x24, 0x81, + 0xfc, 0xf3, 0x3b, 0x23, 0x05, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x01, 0x00, 0x02, + 0xfc, 0xf3, 0x3b, 0x23, 0x07, 0xf0, 0xf0, + 0xfc, 0xf3, 0x3b, 0x23, 0x09, 0x08, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0d, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x0c, 0x0e, 0x20, + 0xfc, 0xf3, 0x3b, 0x22, 0xf2, 0x00, 0x44, + 0xfc, 0xf3, 0x3b, 0x22, 0xf6, 0x00, 0x00, + 0xfc, 0xf3, 0x3b, 0x22, 0xc6, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x22, 0xc7, 0x00, 0x08, + 0xfc, 0xf3, 0x3b, 0x22, 0xd2, 0x8a, 0x94, + 0xfc, 0xf3, 0x3b, 0x23, 0x03, 0x00, 0x01, + 0xfc, 0xf3, 0x3b, 0x23, 0x00, 0x00, 0x04, + 0xfc, 0xf3, 0x3b, 0x23, 0x04, 0x23, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x2f, 0x01, 0x10, + 0xfc, 0xf3, 0x3b, 0x23, 0x39, 0x00, 0x06, + 0xfc, 0xf3, 0x3b, 0x23, 0xcf, 0x01, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xd0, 0x06, 0x20, + 0xfc, 0xf3, 0x3b, 0x23, 0xd5, 0x3c, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x6e, 0x20, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x33, 0x02, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0xb3, 0x00, 0x0a, + 0xfc, 0xf3, 0x3b, 0x23, 0xb4, 0x00, 0x02, + 0xfc, 0xf3, 0x3b, 0x23, 0x70, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x91, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x92, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x93, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x94, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x23, 0x95, 0x40, 0x00, + 0xfc, 0xf3, 0x3b, 0x3f, 0xd2, 0x00, 0x32, + 0xfc, 0xf3, 0x3b, 0x22, 0xfb, 0x00, 0x00 +}; +#endif diff --git a/sound/soc/codecs/framer-codec.c b/sound/soc/codecs/framer-codec.c index a87a78390172d0..7d9a78d6f75e07 100644 --- a/sound/soc/codecs/framer-codec.c +++ b/sound/soc/codecs/framer-codec.c @@ -381,7 +381,7 @@ static int framer_codec_probe(struct platform_device *pdev) { struct framer_codec *framer; - framer = devm_kzalloc(&pdev->dev, sizeof(*framer), GFP_KERNEL); + framer = devm_kzalloc_obj(&pdev->dev, *framer); if (!framer) return -ENOMEM; diff --git a/sound/soc/codecs/fs-amp-lib.c b/sound/soc/codecs/fs-amp-lib.c index a562c72fc52476..1f0816e495c959 100644 --- a/sound/soc/codecs/fs-amp-lib.c +++ b/sound/soc/codecs/fs-amp-lib.c @@ -111,7 +111,7 @@ static int fs_parse_scene_tables(struct fs_amp_lib *amp_lib) if (count <= 0) return -EFAULT; - scene = devm_kcalloc(amp_lib->dev, count, sizeof(*scene), GFP_KERNEL); + scene = devm_kzalloc_objs(amp_lib->dev, *scene, count); if (!scene) return -ENOMEM; diff --git a/sound/soc/codecs/fs210x.c b/sound/soc/codecs/fs210x.c index 316f3fe80d931f..534b5e36bc1e9b 100644 --- a/sound/soc/codecs/fs210x.c +++ b/sound/soc/codecs/fs210x.c @@ -1489,7 +1489,7 @@ static int fs210x_i2c_probe(struct i2c_client *client) struct fs210x_priv *fs210x; int ret; - fs210x = devm_kzalloc(&client->dev, sizeof(*fs210x), GFP_KERNEL); + fs210x = devm_kzalloc_obj(&client->dev, *fs210x); if (!fs210x) return -ENOMEM; diff --git a/sound/soc/codecs/hda.c b/sound/soc/codecs/hda.c index c481ef2dd789c0..e0056adf1e6b55 100644 --- a/sound/soc/codecs/hda.c +++ b/sound/soc/codecs/hda.c @@ -21,7 +21,7 @@ static int hda_codec_create_dais(struct hda_codec *codec, int pcm_count, struct hda_pcm *pcm; int i; - drvs = devm_kcalloc(dev, pcm_count, sizeof(*drvs), GFP_KERNEL); + drvs = devm_kzalloc_objs(dev, *drvs, pcm_count); if (!drvs) return -ENOMEM; @@ -357,7 +357,7 @@ static int hda_hdev_attach(struct hdac_device *hdev) return -ENODEV; } - comp_drv = devm_kzalloc(&hdev->dev, sizeof(*comp_drv), GFP_KERNEL); + comp_drv = devm_kzalloc_obj(&hdev->dev, *comp_drv); if (!comp_drv) return -ENOMEM; diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c index 48eb95973b7a39..de1481ce2487ba 100644 --- a/sound/soc/codecs/hdac_hda.c +++ b/sound/soc/codecs/hdac_hda.c @@ -646,7 +646,7 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev) struct hdac_ext_link *hlink; int ret; - hda_pvt = devm_kzalloc(&hdev->dev, sizeof(*hda_pvt), GFP_KERNEL); + hda_pvt = devm_kzalloc_obj(&hdev->dev, *hda_pvt); if (!hda_pvt) return -ENOMEM; diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index b3f677e7ddc962..f7922ffaad9730 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c @@ -981,11 +981,11 @@ static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev, int i = 0; int num_items = hdmi->num_cvt + 1; - kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL); + kc = devm_kzalloc_obj(&hdev->dev, *kc); if (!kc) return -ENOMEM; - se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL); + se = devm_kzalloc_obj(&hdev->dev, *se); if (!se) return -ENOMEM; @@ -1213,7 +1213,7 @@ static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid) struct hdac_hdmi_cvt *cvt; char name[NAME_SIZE]; - cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL); + cvt = devm_kzalloc_obj(&hdev->dev, *cvt); if (!cvt) return -ENOMEM; @@ -1354,7 +1354,7 @@ static int hdac_hdmi_add_ports(struct hdac_device *hdev, * implemented. */ - ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL); + ports = devm_kzalloc_objs(&hdev->dev, *ports, max_ports); if (!ports) return -ENOMEM; @@ -1374,7 +1374,7 @@ static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid) struct hdac_hdmi_pin *pin; int ret; - pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL); + pin = devm_kzalloc_obj(&hdev->dev, *pin); if (!pin) return -ENOMEM; @@ -1862,7 +1862,7 @@ static int hdac_hdmi_dev_probe(struct hdac_device *hdev) snd_hdac_ext_bus_link_get(hdev->bus, hlink); - hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL); + hdmi_priv = devm_kzalloc_obj(&hdev->dev, *hdmi_priv); if (hdmi_priv == NULL) { snd_hdac_ext_bus_link_put(hdev->bus, hlink); return -ENOMEM; diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index 0e1e532dfc6340..bc59da295370c4 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -925,7 +925,7 @@ static int hdmi_dai_probe(struct snd_soc_dai *dai) return ret; } - daifmt = devm_kzalloc(dai->dev, sizeof(*daifmt), GFP_KERNEL); + daifmt = devm_kzalloc_obj(dai->dev, *daifmt); if (!daifmt) return -ENOMEM; @@ -1148,7 +1148,7 @@ static int hdmi_codec_probe(struct platform_device *pdev) return -EINVAL; } - hcp = devm_kzalloc(dev, sizeof(*hcp), GFP_KERNEL); + hcp = devm_kzalloc_obj(dev, *hcp); if (!hcp) return -ENOMEM; @@ -1160,7 +1160,7 @@ static int hdmi_codec_probe(struct platform_device *pdev) if (ret < 0) return ret; - daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL); + daidrv = devm_kzalloc_objs(dev, *daidrv, dai_count); if (!daidrv) return -ENOMEM; diff --git a/sound/soc/codecs/idt821034.c b/sound/soc/codecs/idt821034.c index 387f17b5f7b328..bcbcf615cf407b 100644 --- a/sound/soc/codecs/idt821034.c +++ b/sound/soc/codecs/idt821034.c @@ -1103,7 +1103,7 @@ static int idt821034_spi_probe(struct spi_device *spi) if (ret < 0) return ret; - idt821034 = devm_kzalloc(&spi->dev, sizeof(*idt821034), GFP_KERNEL); + idt821034 = devm_kzalloc_obj(&spi->dev, *idt821034); if (!idt821034) return -ENOMEM; diff --git a/sound/soc/codecs/inno_rk3036.c b/sound/soc/codecs/inno_rk3036.c index aaf03f22815078..3e5383862ed174 100644 --- a/sound/soc/codecs/inno_rk3036.c +++ b/sound/soc/codecs/inno_rk3036.c @@ -418,7 +418,7 @@ static int rk3036_codec_platform_probe(struct platform_device *pdev) struct regmap *grf; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/jz4725b.c b/sound/soc/codecs/jz4725b.c index 8a7d26a08c03bc..33a120298f947b 100644 --- a/sound/soc/codecs/jz4725b.c +++ b/sound/soc/codecs/jz4725b.c @@ -610,7 +610,7 @@ static int jz4725b_codec_probe(struct platform_device *pdev) struct clk *clk; int ret; - icdc = devm_kzalloc(dev, sizeof(*icdc), GFP_KERNEL); + icdc = devm_kzalloc_obj(dev, *icdc); if (!icdc) return -ENOMEM; diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c index d3d801d850a16e..90d63408652f82 100644 --- a/sound/soc/codecs/jz4740.c +++ b/sound/soc/codecs/jz4740.c @@ -311,8 +311,7 @@ static int jz4740_codec_probe(struct platform_device *pdev) struct jz4740_codec *jz4740_codec; void __iomem *base; - jz4740_codec = devm_kzalloc(&pdev->dev, sizeof(*jz4740_codec), - GFP_KERNEL); + jz4740_codec = devm_kzalloc_obj(&pdev->dev, *jz4740_codec); if (!jz4740_codec) return -ENOMEM; diff --git a/sound/soc/codecs/jz4760.c b/sound/soc/codecs/jz4760.c index 6846ace0641517..3c34ff635d3c6e 100644 --- a/sound/soc/codecs/jz4760.c +++ b/sound/soc/codecs/jz4760.c @@ -808,7 +808,7 @@ static int jz4760_codec_probe(struct platform_device *pdev) struct clk *clk; int ret; - codec = devm_kzalloc(dev, sizeof(*codec), GFP_KERNEL); + codec = devm_kzalloc_obj(dev, *codec); if (!codec) return -ENOMEM; diff --git a/sound/soc/codecs/jz4770.c b/sound/soc/codecs/jz4770.c index be1ecdcc737b31..19a8a8d4106b24 100644 --- a/sound/soc/codecs/jz4770.c +++ b/sound/soc/codecs/jz4770.c @@ -855,7 +855,7 @@ static int jz4770_codec_probe(struct platform_device *pdev) struct clk *clk; int ret; - codec = devm_kzalloc(dev, sizeof(*codec), GFP_KERNEL); + codec = devm_kzalloc_obj(dev, *codec); if (!codec) return -ENOMEM; diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c index 991555bec712af..dad72e2eaf9a0f 100644 --- a/sound/soc/codecs/lm49453.c +++ b/sound/soc/codecs/lm49453.c @@ -813,7 +813,7 @@ static const struct snd_soc_dapm_route lm49453_audio_map[] = { { "HPR Mixer", "DMIC1L Switch", "DMIC1 Left" }, { "HPR Mixer", "DMIC1R Switch", "DMIC1 Right" }, { "HPR Mixer", "DMIC2L Switch", "DMIC2 Left" }, - { "HPR Mixer", "DMIC2L Switch", "DMIC2 Right" }, + { "HPR Mixer", "DMIC2R Switch", "DMIC2 Right" }, { "HPR Mixer", "Sidetone Switch", "Sidetone" }, { "HPR DAC", NULL, "HPR Mixer" }, @@ -1432,8 +1432,7 @@ static int lm49453_i2c_probe(struct i2c_client *i2c) struct lm49453_priv *lm49453; int ret = 0; - lm49453 = devm_kzalloc(&i2c->dev, sizeof(struct lm49453_priv), - GFP_KERNEL); + lm49453 = devm_kzalloc_obj(&i2c->dev, struct lm49453_priv); if (lm49453 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/lochnagar-sc.c b/sound/soc/codecs/lochnagar-sc.c index dadb4a6c287fbe..3ba9a2c0ac118e 100644 --- a/sound/soc/codecs/lochnagar-sc.c +++ b/sound/soc/codecs/lochnagar-sc.c @@ -233,7 +233,7 @@ static int lochnagar_sc_probe(struct platform_device *pdev) struct lochnagar_sc_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/lpass-macro-common.c b/sound/soc/codecs/lpass-macro-common.c index 7e59616ed7bc7a..7f3c43763c97fb 100644 --- a/sound/soc/codecs/lpass-macro-common.c +++ b/sound/soc/codecs/lpass-macro-common.c @@ -23,7 +23,7 @@ struct lpass_macro *lpass_macro_pds_init(struct device *dev) if (!of_property_present(dev->of_node, "power-domains")) return NULL; - l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL); + l_pds = devm_kzalloc_obj(dev, *l_pds); if (!l_pds) return ERR_PTR(-ENOMEM); diff --git a/sound/soc/codecs/lpass-rx-macro.c b/sound/soc/codecs/lpass-rx-macro.c index c59c746fb63842..5253ad4381888b 100644 --- a/sound/soc/codecs/lpass-rx-macro.c +++ b/sound/soc/codecs/lpass-rx-macro.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -670,6 +669,53 @@ struct rx_macro { }; #define to_rx_macro(_hw) container_of(_hw, struct rx_macro, hw) +static void rx_macro_disable_clocks(struct rx_macro *rx) +{ + clk_disable_unprepare(rx->fsgen); + clk_disable_unprepare(rx->npl); + clk_disable_unprepare(rx->mclk); + clk_disable_unprepare(rx->dcodec); + clk_disable_unprepare(rx->macro); +} + +static int rx_macro_enable_clocks(struct rx_macro *rx) +{ + int ret; + + ret = clk_prepare_enable(rx->macro); + if (ret) + return ret; + + ret = clk_prepare_enable(rx->dcodec); + if (ret) + goto err_dcodec; + + ret = clk_prepare_enable(rx->mclk); + if (ret) + goto err_mclk; + + ret = clk_prepare_enable(rx->npl); + if (ret) + goto err_npl; + + ret = clk_prepare_enable(rx->fsgen); + if (ret) + goto err_fsgen; + + return 0; + +err_fsgen: + clk_disable_unprepare(rx->npl); +err_npl: + clk_disable_unprepare(rx->mclk); +err_mclk: + clk_disable_unprepare(rx->dcodec); +err_dcodec: + clk_disable_unprepare(rx->macro); + + return ret; +} + struct wcd_iir_filter_ctl { unsigned int iir_idx; unsigned int band_idx; @@ -3776,7 +3822,7 @@ static int rx_macro_probe(struct platform_device *pdev) flags = (kernel_ulong_t)device_get_match_data(dev); - rx = devm_kzalloc(dev, sizeof(*rx), GFP_KERNEL); + rx = devm_kzalloc_obj(dev, *rx); if (!rx) return -ENOMEM; @@ -3880,14 +3926,6 @@ static int rx_macro_probe(struct platform_device *pdev) if (ret) return ret; - ret = devm_pm_clk_create(dev); - if (ret) - return ret; - - ret = of_pm_clk_add_clks(dev); - if (ret < 0) - return ret; - pm_runtime_set_autosuspend_delay(dev, 100); pm_runtime_use_autosuspend(dev); ret = devm_pm_runtime_enable(dev); @@ -3959,16 +3997,9 @@ MODULE_DEVICE_TABLE(of, rx_macro_dt_match); static int rx_macro_runtime_suspend(struct device *dev) { struct rx_macro *rx = dev_get_drvdata(dev); - int ret; regcache_cache_only(rx->regmap, true); - - ret = pm_clk_suspend(dev); - if (ret) { - regcache_cache_only(rx->regmap, false); - return ret; - } - + rx_macro_disable_clocks(rx); regcache_mark_dirty(rx->regmap); return 0; @@ -3979,7 +4010,7 @@ static int rx_macro_runtime_resume(struct device *dev) struct rx_macro *rx = dev_get_drvdata(dev); int ret; - ret = pm_clk_resume(dev); + ret = rx_macro_enable_clocks(rx); if (ret) { regcache_cache_only(rx->regmap, true); regcache_mark_dirty(rx->regmap); @@ -3991,16 +4022,15 @@ static int rx_macro_runtime_resume(struct device *dev) if (ret) { regcache_cache_only(rx->regmap, true); regcache_mark_dirty(rx->regmap); - pm_clk_suspend(dev); + rx_macro_disable_clocks(rx); return ret; } return 0; } -static const struct dev_pm_ops rx_macro_pm_ops = { - RUNTIME_PM_OPS(rx_macro_runtime_suspend, rx_macro_runtime_resume, NULL) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(rx_macro_pm_ops, rx_macro_runtime_suspend, + rx_macro_runtime_resume, NULL); static struct platform_driver rx_macro_driver = { .driver = { diff --git a/sound/soc/codecs/lpass-tx-macro.c b/sound/soc/codecs/lpass-tx-macro.c index 6deaaabe43afa4..6f2af4907cb84d 100644 --- a/sound/soc/codecs/lpass-tx-macro.c +++ b/sound/soc/codecs/lpass-tx-macro.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -289,6 +288,53 @@ struct tx_macro { }; #define to_tx_macro(_hw) container_of(_hw, struct tx_macro, hw) +static void tx_macro_disable_clocks(struct tx_macro *tx) +{ + clk_disable_unprepare(tx->fsgen); + clk_disable_unprepare(tx->npl); + clk_disable_unprepare(tx->mclk); + clk_disable_unprepare(tx->dcodec); + clk_disable_unprepare(tx->macro); +} + +static int tx_macro_enable_clocks(struct tx_macro *tx) +{ + int ret; + + ret = clk_prepare_enable(tx->macro); + if (ret) + return ret; + + ret = clk_prepare_enable(tx->dcodec); + if (ret) + goto err_dcodec; + + ret = clk_prepare_enable(tx->mclk); + if (ret) + goto err_mclk; + + ret = clk_prepare_enable(tx->npl); + if (ret) + goto err_npl; + + ret = clk_prepare_enable(tx->fsgen); + if (ret) + goto err_fsgen; + + return 0; + +err_fsgen: + clk_disable_unprepare(tx->npl); +err_npl: + clk_disable_unprepare(tx->mclk); +err_mclk: + clk_disable_unprepare(tx->dcodec); +err_dcodec: + clk_disable_unprepare(tx->macro); + + return ret; +} + static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400); static struct reg_default tx_defaults[] = { @@ -2252,7 +2298,7 @@ static int tx_macro_probe(struct platform_device *pdev) void __iomem *base; int ret, reg; - tx = devm_kzalloc(dev, sizeof(*tx), GFP_KERNEL); + tx = devm_kzalloc_obj(dev, *tx); if (!tx) return -ENOMEM; @@ -2328,14 +2374,6 @@ static int tx_macro_probe(struct platform_device *pdev) if (ret) goto err; - ret = devm_pm_clk_create(dev); - if (ret) - goto err; - - ret = of_pm_clk_add_clks(dev); - if (ret < 0) - goto err; - pm_runtime_set_autosuspend_delay(dev, 100); pm_runtime_use_autosuspend(dev); ret = devm_pm_runtime_enable(dev); @@ -2346,7 +2384,6 @@ static int tx_macro_probe(struct platform_device *pdev) if (ret < 0) goto err; - /* reset soundwire block */ if (tx->data->flags & LPASS_MACRO_FLAG_RESET_SWR) regmap_update_bits(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, @@ -2395,16 +2432,9 @@ static void tx_macro_remove(struct platform_device *pdev) static int tx_macro_runtime_suspend(struct device *dev) { struct tx_macro *tx = dev_get_drvdata(dev); - int ret; regcache_cache_only(tx->regmap, true); - - ret = pm_clk_suspend(dev); - if (ret) { - regcache_cache_only(tx->regmap, false); - return ret; - } - + tx_macro_disable_clocks(tx); regcache_mark_dirty(tx->regmap); return 0; @@ -2415,7 +2445,7 @@ static int tx_macro_runtime_resume(struct device *dev) struct tx_macro *tx = dev_get_drvdata(dev); int ret; - ret = pm_clk_resume(dev); + ret = tx_macro_enable_clocks(tx); if (ret) { regcache_cache_only(tx->regmap, true); regcache_mark_dirty(tx->regmap); @@ -2427,16 +2457,15 @@ static int tx_macro_runtime_resume(struct device *dev) if (ret) { regcache_cache_only(tx->regmap, true); regcache_mark_dirty(tx->regmap); - pm_clk_suspend(dev); + tx_macro_disable_clocks(tx); return ret; } return 0; } -static const struct dev_pm_ops tx_macro_pm_ops = { - RUNTIME_PM_OPS(tx_macro_runtime_suspend, tx_macro_runtime_resume, NULL) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(tx_macro_pm_ops, tx_macro_runtime_suspend, + tx_macro_runtime_resume, NULL); static const struct tx_macro_data lpass_ver_9 = { .flags = LPASS_MACRO_FLAG_HAS_NPL_CLOCK | diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c index 03d6434a4a126c..af8308eacb0baa 100644 --- a/sound/soc/codecs/lpass-va-macro.c +++ b/sound/soc/codecs/lpass-va-macro.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -260,6 +259,46 @@ static const struct va_macro_data sm8550_va_data = { .has_npl_clk = false, }; +static void va_macro_disable_clocks(struct va_macro *va) +{ + clk_disable_unprepare(va->npl); + clk_disable_unprepare(va->mclk); + clk_disable_unprepare(va->dcodec); + clk_disable_unprepare(va->macro); +} + +static int va_macro_enable_clocks(struct va_macro *va) +{ + int ret; + + ret = clk_prepare_enable(va->macro); + if (ret) + return ret; + + ret = clk_prepare_enable(va->dcodec); + if (ret) + goto err_dcodec; + + ret = clk_prepare_enable(va->mclk); + if (ret) + goto err_mclk; + + ret = clk_prepare_enable(va->npl); + if (ret) + goto err_npl; + + return 0; + +err_npl: + clk_disable_unprepare(va->mclk); +err_mclk: + clk_disable_unprepare(va->dcodec); +err_dcodec: + clk_disable_unprepare(va->macro); + + return ret; +} + static bool va_is_volatile_register(struct device *dev, unsigned int reg) { switch (reg) { @@ -1551,7 +1590,7 @@ static int va_macro_probe(struct platform_device *pdev) int ret; int rpm_ret; - va = devm_kzalloc(dev, sizeof(*va), GFP_KERNEL); + va = devm_kzalloc_obj(dev, *va); if (!va) return -ENOMEM; @@ -1621,14 +1660,6 @@ static int va_macro_probe(struct platform_device *pdev) goto err; } - ret = devm_pm_clk_create(dev); - if (ret) - goto err; - - ret = of_pm_clk_add_clks(dev); - if (ret < 0) - goto err; - pm_runtime_set_autosuspend_delay(dev, 100); pm_runtime_use_autosuspend(dev); ret = devm_pm_runtime_enable(dev); @@ -1719,16 +1750,9 @@ static void va_macro_remove(struct platform_device *pdev) static int va_macro_runtime_suspend(struct device *dev) { struct va_macro *va = dev_get_drvdata(dev); - int ret; regcache_cache_only(va->regmap, true); - - ret = pm_clk_suspend(dev); - if (ret) { - regcache_cache_only(va->regmap, false); - return ret; - } - + va_macro_disable_clocks(va); regcache_mark_dirty(va->regmap); return 0; @@ -1737,9 +1761,9 @@ static int va_macro_runtime_suspend(struct device *dev) static int va_macro_runtime_resume(struct device *dev) { struct va_macro *va = dev_get_drvdata(dev); - int ret, sret; + int ret; - ret = pm_clk_resume(dev); + ret = va_macro_enable_clocks(va); if (ret) { regcache_cache_only(va->regmap, true); regcache_mark_dirty(va->regmap); @@ -1752,21 +1776,15 @@ static int va_macro_runtime_resume(struct device *dev) if (ret) { regcache_cache_only(va->regmap, true); regcache_mark_dirty(va->regmap); - sret = pm_clk_suspend(dev); - if (sret) - dev_err(va->dev, - "failed to suspend clocks after regcache sync failure: %d\n", - sret); + va_macro_disable_clocks(va); return ret; } return 0; } - -static const struct dev_pm_ops va_macro_pm_ops = { - RUNTIME_PM_OPS(va_macro_runtime_suspend, va_macro_runtime_resume, NULL) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(va_macro_pm_ops, va_macro_runtime_suspend, + va_macro_runtime_resume, NULL); static const struct of_device_id va_macro_dt_match[] = { { .compatible = "qcom,sc7280-lpass-va-macro", .data = &sc7280_va_data }, diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c index 899c8bee4645fc..2b63954f783b35 100644 --- a/sound/soc/codecs/lpass-wsa-macro.c +++ b/sound/soc/codecs/lpass-wsa-macro.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -424,6 +423,53 @@ struct wsa_macro { }; #define to_wsa_macro(_hw) container_of(_hw, struct wsa_macro, hw) +static void wsa_macro_disable_clocks(struct wsa_macro *wsa) +{ + clk_disable_unprepare(wsa->fsgen); + clk_disable_unprepare(wsa->npl); + clk_disable_unprepare(wsa->mclk); + clk_disable_unprepare(wsa->dcodec); + clk_disable_unprepare(wsa->macro); +} + +static int wsa_macro_enable_clocks(struct wsa_macro *wsa) +{ + int ret; + + ret = clk_prepare_enable(wsa->macro); + if (ret) + return ret; + + ret = clk_prepare_enable(wsa->dcodec); + if (ret) + goto err_dcodec; + + ret = clk_prepare_enable(wsa->mclk); + if (ret) + goto err_mclk; + + ret = clk_prepare_enable(wsa->npl); + if (ret) + goto err_npl; + + ret = clk_prepare_enable(wsa->fsgen); + if (ret) + goto err_fsgen; + + return 0; + +err_fsgen: + clk_disable_unprepare(wsa->npl); +err_npl: + clk_disable_unprepare(wsa->mclk); +err_mclk: + clk_disable_unprepare(wsa->dcodec); +err_dcodec: + clk_disable_unprepare(wsa->macro); + + return ret; +} + static const struct wsa_reg_layout wsa_codec_v2_1 = { .rx_intx_1_mix_inp0_sel_mask = GENMASK(2, 0), .rx_intx_1_mix_inp1_sel_mask = GENMASK(5, 3), @@ -2697,7 +2743,7 @@ static int wsa_macro_probe(struct platform_device *pdev) flags = (kernel_ulong_t)device_get_match_data(dev); - wsa = devm_kzalloc(dev, sizeof(*wsa), GFP_KERNEL); + wsa = devm_kzalloc_obj(dev, *wsa); if (!wsa) return -ENOMEM; @@ -2794,14 +2840,6 @@ static int wsa_macro_probe(struct platform_device *pdev) if (ret) return ret; - ret = devm_pm_clk_create(dev); - if (ret) - return ret; - - ret = of_pm_clk_add_clks(dev); - if (ret < 0) - return ret; - pm_runtime_set_autosuspend_delay(dev, 100); pm_runtime_use_autosuspend(dev); ret = devm_pm_runtime_enable(dev); @@ -2847,16 +2885,9 @@ static int wsa_macro_probe(struct platform_device *pdev) static int wsa_macro_runtime_suspend(struct device *dev) { struct wsa_macro *wsa = dev_get_drvdata(dev); - int ret; regcache_cache_only(wsa->regmap, true); - - ret = pm_clk_suspend(dev); - if (ret) { - regcache_cache_only(wsa->regmap, false); - return ret; - } - + wsa_macro_disable_clocks(wsa); regcache_mark_dirty(wsa->regmap); return 0; @@ -2865,9 +2896,9 @@ static int wsa_macro_runtime_suspend(struct device *dev) static int wsa_macro_runtime_resume(struct device *dev) { struct wsa_macro *wsa = dev_get_drvdata(dev); - int ret, sret; + int ret; - ret = pm_clk_resume(dev); + ret = wsa_macro_enable_clocks(wsa); if (ret) { regcache_cache_only(wsa->regmap, true); regcache_mark_dirty(wsa->regmap); @@ -2879,20 +2910,15 @@ static int wsa_macro_runtime_resume(struct device *dev) if (ret) { regcache_cache_only(wsa->regmap, true); regcache_mark_dirty(wsa->regmap); - sret = pm_clk_suspend(dev); - if (sret) - dev_err(dev, - "failed to suspend clocks after regcache sync failure: %d\n", - sret); + wsa_macro_disable_clocks(wsa); return ret; } return 0; } -static const struct dev_pm_ops wsa_macro_pm_ops = { - RUNTIME_PM_OPS(wsa_macro_runtime_suspend, wsa_macro_runtime_resume, NULL) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(wsa_macro_pm_ops, wsa_macro_runtime_suspend, + wsa_macro_runtime_resume, NULL); static const struct of_device_id wsa_macro_dt_match[] = { { diff --git a/sound/soc/codecs/max9759.c b/sound/soc/codecs/max9759.c index 9760543f2922e6..1934bfe03b3ad8 100644 --- a/sound/soc/codecs/max9759.c +++ b/sound/soc/codecs/max9759.c @@ -142,7 +142,7 @@ static int max9759_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct max9759 *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/max9768.c b/sound/soc/codecs/max9768.c index 8621d9bdb9fd65..706bb6f62cc25b 100644 --- a/sound/soc/codecs/max9768.c +++ b/sound/soc/codecs/max9768.c @@ -179,7 +179,7 @@ static int max9768_i2c_probe(struct i2c_client *client) struct max9768 *max9768; struct max9768_pdata *pdata = client->dev.platform_data; - max9768 = devm_kzalloc(&client->dev, sizeof(*max9768), GFP_KERNEL); + max9768 = devm_kzalloc_obj(&client->dev, *max9768); if (!max9768) return -ENOMEM; diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c index 1dd7881c84aa3a..fa6f1055822ca7 100644 --- a/sound/soc/codecs/max98088.c +++ b/sound/soc/codecs/max98088.c @@ -1744,8 +1744,7 @@ static int max98088_i2c_probe(struct i2c_client *i2c) { struct max98088_priv *max98088; - max98088 = devm_kzalloc(&i2c->dev, sizeof(struct max98088_priv), - GFP_KERNEL); + max98088 = devm_kzalloc_obj(&i2c->dev, struct max98088_priv); if (max98088 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index 4bb5478f4642f9..3ed513f6d81cd6 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -743,14 +743,6 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w, else val = (val & M98090_MIC_PA2EN_MASK) >> M98090_MIC_PA2EN_SHIFT; - if (val >= 1) { - if (w->reg == M98090_REG_MIC1_INPUT_LEVEL) { - max98090->pa1en = val - 1; /* Update for volatile */ - } else { - max98090->pa2en = val - 1; /* Update for volatile */ - } - } - switch (event) { case SND_SOC_DAPM_POST_PMU: /* If turning on, set to most recently selected volume */ @@ -759,6 +751,14 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w, else val = max98090->pa2en + 1; break; + case SND_SOC_DAPM_PRE_PMD: + if (val >= 1) { + if (w->reg == M98090_REG_MIC1_INPUT_LEVEL) + max98090->pa1en = val - 1; + else + max98090->pa2en = val - 1; + } + return 0; case SND_SOC_DAPM_POST_PMD: /* If turning off, turn off */ val = 0; @@ -1121,11 +1121,13 @@ static const struct snd_soc_dapm_widget max98090_dapm_widgets[] = { SND_SOC_DAPM_PGA_E("MIC1 Input", M98090_REG_MIC1_INPUT_LEVEL, M98090_MIC_PA1EN_SHIFT, 0, NULL, 0, max98090_micinput_event, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | + SND_SOC_DAPM_POST_PMD), SND_SOC_DAPM_PGA_E("MIC2 Input", M98090_REG_MIC2_INPUT_LEVEL, M98090_MIC_PA2EN_SHIFT, 0, NULL, 0, max98090_micinput_event, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | + SND_SOC_DAPM_POST_PMD), SND_SOC_DAPM_MIXER("LINEA Mixer", SND_SOC_NOPM, 0, 0, &max98090_linea_mixer_controls[0], @@ -2607,8 +2609,7 @@ static int max98090_i2c_probe(struct i2c_client *i2c) pr_debug("max98090_i2c_probe\n"); - max98090 = devm_kzalloc(&i2c->dev, sizeof(struct max98090_priv), - GFP_KERNEL); + max98090 = devm_kzalloc_obj(&i2c->dev, struct max98090_priv); if (max98090 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c index c827fd47a5b0e2..0d0e0d434ecf06 100644 --- a/sound/soc/codecs/max98095.c +++ b/sound/soc/codecs/max98095.c @@ -2134,8 +2134,7 @@ static int max98095_i2c_probe(struct i2c_client *i2c) struct max98095_priv *max98095; int ret; - max98095 = devm_kzalloc(&i2c->dev, sizeof(struct max98095_priv), - GFP_KERNEL); + max98095 = devm_kzalloc_obj(&i2c->dev, struct max98095_priv); if (max98095 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index b0f8043fb9e285..0510d47d50eb6f 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -124,7 +124,7 @@ static int max98357a_platform_probe(struct platform_device *pdev) struct max98357a_priv *max98357a; int ret; - max98357a = devm_kzalloc(&pdev->dev, sizeof(*max98357a), GFP_KERNEL); + max98357a = devm_kzalloc_obj(&pdev->dev, *max98357a); if (!max98357a) return -ENOMEM; diff --git a/sound/soc/codecs/max98363.c b/sound/soc/codecs/max98363.c index 4a6d7b163acf13..87755234a86522 100644 --- a/sound/soc/codecs/max98363.c +++ b/sound/soc/codecs/max98363.c @@ -130,9 +130,8 @@ static int max98363_read_prop(struct sdw_slave *slave) prop->clock_reg_supported = true; nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -386,7 +385,7 @@ static int max98363_init(struct sdw_slave *slave, struct regmap *regmap) struct device *dev = &slave->dev; /* Allocate and assign private driver data structure */ - max98363 = devm_kzalloc(dev, sizeof(*max98363), GFP_KERNEL); + max98363 = devm_kzalloc_obj(dev, *max98363); if (!max98363) return -ENOMEM; diff --git a/sound/soc/codecs/max98371.c b/sound/soc/codecs/max98371.c index 72bcdb0d1289e1..2711e833fa33fd 100644 --- a/sound/soc/codecs/max98371.c +++ b/sound/soc/codecs/max98371.c @@ -376,8 +376,7 @@ static int max98371_i2c_probe(struct i2c_client *i2c) struct max98371_priv *max98371; int ret, reg; - max98371 = devm_kzalloc(&i2c->dev, - sizeof(*max98371), GFP_KERNEL); + max98371 = devm_kzalloc_obj(&i2c->dev, *max98371); if (!max98371) return -ENOMEM; diff --git a/sound/soc/codecs/max98373-i2c.c b/sound/soc/codecs/max98373-i2c.c index 4e52282ace7f75..c7c728f7983e26 100644 --- a/sound/soc/codecs/max98373-i2c.c +++ b/sound/soc/codecs/max98373-i2c.c @@ -534,7 +534,7 @@ static int max98373_i2c_probe(struct i2c_client *i2c) int i; struct max98373_priv *max98373 = NULL; - max98373 = devm_kzalloc(&i2c->dev, sizeof(*max98373), GFP_KERNEL); + max98373 = devm_kzalloc_obj(&i2c->dev, *max98373); if (!max98373) { ret = -ENOMEM; @@ -558,9 +558,8 @@ static int max98373_i2c_probe(struct i2c_client *i2c) } max98373->cache_num = ARRAY_SIZE(max98373_i2c_cache_reg); - max98373->cache = devm_kcalloc(&i2c->dev, max98373->cache_num, - sizeof(*max98373->cache), - GFP_KERNEL); + max98373->cache = devm_kzalloc_objs(&i2c->dev, *max98373->cache, + max98373->cache_num); if (!max98373->cache) { ret = -ENOMEM; return ret; diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c index 638ef343813bde..331bbaf8d12e06 100644 --- a/sound/soc/codecs/max98373-sdw.c +++ b/sound/soc/codecs/max98373-sdw.c @@ -310,9 +310,8 @@ static int max98373_read_prop(struct sdw_slave *slave) prop->clk_stop_timeout = 20; nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -329,9 +328,8 @@ static int max98373_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -729,7 +727,7 @@ static int max98373_init(struct sdw_slave *slave, struct regmap *regmap) struct device *dev = &slave->dev; /* Allocate and assign private driver data structure */ - max98373 = devm_kzalloc(dev, sizeof(*max98373), GFP_KERNEL); + max98373 = devm_kzalloc_obj(dev, *max98373); if (!max98373) return -ENOMEM; @@ -740,9 +738,8 @@ static int max98373_init(struct sdw_slave *slave, struct regmap *regmap) regcache_cache_only(max98373->regmap, true); max98373->cache_num = ARRAY_SIZE(max98373_sdw_cache_reg); - max98373->cache = devm_kcalloc(dev, max98373->cache_num, - sizeof(*max98373->cache), - GFP_KERNEL); + max98373->cache = devm_kzalloc_objs(dev, *max98373->cache, + max98373->cache_num); if (!max98373->cache) return -ENOMEM; diff --git a/sound/soc/codecs/max98388.c b/sound/soc/codecs/max98388.c index a653e0a21899d9..7d465939423f52 100644 --- a/sound/soc/codecs/max98388.c +++ b/sound/soc/codecs/max98388.c @@ -942,7 +942,7 @@ static int max98388_i2c_probe(struct i2c_client *i2c) struct max98388_priv *max98388 = NULL; - max98388 = devm_kzalloc(&i2c->dev, sizeof(*max98388), GFP_KERNEL); + max98388 = devm_kzalloc_obj(&i2c->dev, *max98388); if (!max98388) return -ENOMEM; diff --git a/sound/soc/codecs/max98390.c b/sound/soc/codecs/max98390.c index b87cca2a5b437b..537134bc641441 100644 --- a/sound/soc/codecs/max98390.c +++ b/sound/soc/codecs/max98390.c @@ -1033,7 +1033,7 @@ static int max98390_i2c_probe(struct i2c_client *i2c) return -ENXIO; } - max98390 = devm_kzalloc(&i2c->dev, sizeof(*max98390), GFP_KERNEL); + max98390 = devm_kzalloc_obj(&i2c->dev, *max98390); if (!max98390) { ret = -ENOMEM; return ret; diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index 935319fee41bab..e8bbfc2667dd1b 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -1763,7 +1763,7 @@ static int max98396_i2c_probe(struct i2c_client *i2c) struct max98396_priv *max98396 = NULL; int i, ret, reg; - max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL); + max98396 = devm_kzalloc_obj(&i2c->dev, *max98396); if (!max98396) { ret = -ENOMEM; diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c index c229b732121fee..d9b881dfdab851 100644 --- a/sound/soc/codecs/max9850.c +++ b/sound/soc/codecs/max9850.c @@ -315,8 +315,7 @@ static int max9850_i2c_probe(struct i2c_client *i2c) struct max9850_priv *max9850; int ret; - max9850 = devm_kzalloc(&i2c->dev, sizeof(struct max9850_priv), - GFP_KERNEL); + max9850 = devm_kzalloc_obj(&i2c->dev, struct max9850_priv); if (max9850 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/max98504.c b/sound/soc/codecs/max98504.c index 8b2620eaf9b0a5..0cd1d26b1e9bc4 100644 --- a/sound/soc/codecs/max98504.c +++ b/sound/soc/codecs/max98504.c @@ -314,7 +314,7 @@ static int max98504_i2c_probe(struct i2c_client *client) struct max98504_priv *max98504; int i, ret; - max98504 = devm_kzalloc(dev, sizeof(*max98504), GFP_KERNEL); + max98504 = devm_kzalloc_obj(dev, *max98504); if (!max98504) return -ENOMEM; diff --git a/sound/soc/codecs/max98520.c b/sound/soc/codecs/max98520.c index 57759d85907bed..56e559db88de9d 100644 --- a/sound/soc/codecs/max98520.c +++ b/sound/soc/codecs/max98520.c @@ -697,7 +697,7 @@ static int max98520_i2c_probe(struct i2c_client *i2c) return -ENXIO; } - max98520 = devm_kzalloc(&i2c->dev, sizeof(*max98520), GFP_KERNEL); + max98520 = devm_kzalloc_obj(&i2c->dev, *max98520); if (!max98520) return -ENOMEM; diff --git a/sound/soc/codecs/max9860.c b/sound/soc/codecs/max9860.c index 35265c2502fe0c..f05f26d477c7d6 100644 --- a/sound/soc/codecs/max9860.c +++ b/sound/soc/codecs/max9860.c @@ -621,7 +621,7 @@ static int max9860_probe(struct i2c_client *i2c) int i; int intr; - max9860 = devm_kzalloc(dev, sizeof(struct max9860_priv), GFP_KERNEL); + max9860 = devm_kzalloc_obj(dev, struct max9860_priv); if (!max9860) return -ENOMEM; @@ -630,13 +630,6 @@ static int max9860_probe(struct i2c_client *i2c) return dev_err_probe(dev, PTR_ERR(max9860->dvddio), "Failed to get DVDDIO supply\n"); - max9860->dvddio_nb.notifier_call = max9860_dvddio_event; - - ret = devm_regulator_register_notifier(max9860->dvddio, - &max9860->dvddio_nb); - if (ret) - dev_err(dev, "Failed to register DVDDIO notifier: %d\n", ret); - ret = regulator_enable(max9860->dvddio); if (ret != 0) { dev_err(dev, "Failed to enable DVDDIO: %d\n", ret); @@ -649,6 +642,13 @@ static int max9860_probe(struct i2c_client *i2c) goto err_regulator; } + max9860->dvddio_nb.notifier_call = max9860_dvddio_event; + + ret = devm_regulator_register_notifier(max9860->dvddio, + &max9860->dvddio_nb); + if (ret) + dev_err(dev, "Failed to register DVDDIO notifier: %d\n", ret); + dev_set_drvdata(dev, max9860); /* diff --git a/sound/soc/codecs/max9867.c b/sound/soc/codecs/max9867.c index f2214e3a19ce3f..1e99fbd8aca201 100644 --- a/sound/soc/codecs/max9867.c +++ b/sound/soc/codecs/max9867.c @@ -667,7 +667,7 @@ static int max9867_i2c_probe(struct i2c_client *i2c) struct max9867_priv *max9867; int ret, reg; - max9867 = devm_kzalloc(&i2c->dev, sizeof(*max9867), GFP_KERNEL); + max9867 = devm_kzalloc_obj(&i2c->dev, *max9867); if (!max9867) return -ENOMEM; diff --git a/sound/soc/codecs/max98925.c b/sound/soc/codecs/max98925.c index fe43ef99a0cba2..fa22b2e4ed821c 100644 --- a/sound/soc/codecs/max98925.c +++ b/sound/soc/codecs/max98925.c @@ -571,8 +571,7 @@ static int max98925_i2c_probe(struct i2c_client *i2c) u32 value; struct max98925_priv *max98925; - max98925 = devm_kzalloc(&i2c->dev, - sizeof(*max98925), GFP_KERNEL); + max98925 = devm_kzalloc_obj(&i2c->dev, *max98925); if (!max98925) return -ENOMEM; diff --git a/sound/soc/codecs/max98926.c b/sound/soc/codecs/max98926.c index 5b590a1f00de6f..14613e85e1470a 100644 --- a/sound/soc/codecs/max98926.c +++ b/sound/soc/codecs/max98926.c @@ -523,8 +523,7 @@ static int max98926_i2c_probe(struct i2c_client *i2c) u32 value; struct max98926_priv *max98926; - max98926 = devm_kzalloc(&i2c->dev, - sizeof(*max98926), GFP_KERNEL); + max98926 = devm_kzalloc_obj(&i2c->dev, *max98926); if (!max98926) return -ENOMEM; diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index 285c9d1ea72140..5a753500c556c8 100644 --- a/sound/soc/codecs/max98927.c +++ b/sound/soc/codecs/max98927.c @@ -818,7 +818,7 @@ static int max98927_i2c_probe(struct i2c_client *i2c) int reg = 0; struct max98927_priv *max98927 = NULL; - max98927 = devm_kzalloc(&i2c->dev, sizeof(*max98927), GFP_KERNEL); + max98927 = devm_kzalloc_obj(&i2c->dev, *max98927); if (!max98927) { ret = -ENOMEM; return ret; diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c index a6231a12a9b092..48c7e1f62ea2a0 100644 --- a/sound/soc/codecs/mc13783.c +++ b/sound/soc/codecs/mc13783.c @@ -748,7 +748,7 @@ static int __init mc13783_codec_probe(struct platform_device *pdev) struct device_node *np; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c index a94a3f9b8f9046..7ee730b3a5dfd2 100644 --- a/sound/soc/codecs/ml26124.c +++ b/sound/soc/codecs/ml26124.c @@ -563,7 +563,7 @@ static int ml26124_i2c_probe(struct i2c_client *i2c) struct ml26124_priv *priv; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c index 87f8a47cc293f0..b7ce8e9447de5e 100644 --- a/sound/soc/codecs/msm8916-wcd-analog.c +++ b/sound/soc/codecs/msm8916-wcd-analog.c @@ -1319,7 +1319,7 @@ static int pm8916_wcd_analog_spmi_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret, i, irq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c index cfadea2aa1f7e8..cffb7315ac2cc6 100644 --- a/sound/soc/codecs/msm8916-wcd-digital.c +++ b/sound/soc/codecs/msm8916-wcd-digital.c @@ -1171,7 +1171,7 @@ static int msm8916_wcd_digital_probe(struct platform_device *pdev) struct regmap *digital_map; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/mt6351.c b/sound/soc/codecs/mt6351.c index 3be0491a2588c0..7628c0420609f3 100644 --- a/sound/soc/codecs/mt6351.c +++ b/sound/soc/codecs/mt6351.c @@ -1451,9 +1451,7 @@ static int mt6351_codec_driver_probe(struct platform_device *pdev) { struct mt6351_priv *priv; - priv = devm_kzalloc(&pdev->dev, - sizeof(struct mt6351_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct mt6351_priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/mt6357.c b/sound/soc/codecs/mt6357.c index 3b07087e1cab0c..a08799f99437fa 100644 --- a/sound/soc/codecs/mt6357.c +++ b/sound/soc/codecs/mt6357.c @@ -1808,7 +1808,7 @@ static int mt6357_platform_driver_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "Failed to enable vaud28 regulator\n"); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/mt6358.c b/sound/soc/codecs/mt6358.c index ed8cbc63fa77e6..42b131dc51074d 100644 --- a/sound/soc/codecs/mt6358.c +++ b/sound/soc/codecs/mt6358.c @@ -2381,9 +2381,7 @@ static int mt6358_platform_driver_probe(struct platform_device *pdev) struct mt6358_priv *priv; struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent); - priv = devm_kzalloc(&pdev->dev, - sizeof(struct mt6358_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct mt6358_priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/mt6359-accdet.c b/sound/soc/codecs/mt6359-accdet.c index 54ec1c6bd64b48..2ffff272487d02 100644 --- a/sound/soc/codecs/mt6359-accdet.c +++ b/sound/soc/codecs/mt6359-accdet.c @@ -931,19 +931,16 @@ static int mt6359_accdet_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s(), dev name %s\n", __func__, dev_name(&pdev->dev)); - priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet), - GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct mt6359_accdet); if (!priv) return -ENOMEM; - priv->data = devm_kzalloc(&pdev->dev, sizeof(struct dts_data), - GFP_KERNEL); + priv->data = devm_kzalloc_obj(&pdev->dev, struct dts_data); if (!priv->data) return -ENOMEM; - priv->data->pwm_deb = devm_kzalloc(&pdev->dev, - sizeof(struct pwm_deb_settings), - GFP_KERNEL); + priv->data->pwm_deb = devm_kzalloc_obj(&pdev->dev, + struct pwm_deb_settings); if (!priv->data->pwm_deb) return -ENOMEM; diff --git a/sound/soc/codecs/mt6359.c b/sound/soc/codecs/mt6359.c index c51eae602ca04b..dc1b2e9634b1f0 100644 --- a/sound/soc/codecs/mt6359.c +++ b/sound/soc/codecs/mt6359.c @@ -2921,7 +2921,7 @@ static int mt6359_platform_driver_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s(), dev name %s\n", __func__, dev_name(&pdev->dev)); - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/mt6660.c b/sound/soc/codecs/mt6660.c index 21741afc80ef12..0d77e7ddc04807 100644 --- a/sound/soc/codecs/mt6660.c +++ b/sound/soc/codecs/mt6660.c @@ -462,7 +462,7 @@ static int mt6660_i2c_probe(struct i2c_client *client) int ret; dev_dbg(&client->dev, "%s\n", __func__); - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(&client->dev, *chip); if (!chip) return -ENOMEM; chip->i2c = client; diff --git a/sound/soc/codecs/nau8310-dsp.c b/sound/soc/codecs/nau8310-dsp.c new file mode 100644 index 00000000000000..7b4c95c6186225 --- /dev/null +++ b/sound/soc/codecs/nau8310-dsp.c @@ -0,0 +1,678 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// The NAU83G10/20 Boosted Mono Class-D Amplifier with DSP and I/V-sense driver. +// +// Copyright 2026 Nuvoton Technology Crop. +// Author: John Hsu +// David Lin +// Neo Chang + +#include +#include +#include +#include +#include +#include +#include + +#include "nau8310-dsp.h" +#include "nau8310.h" + +#define NAU8310_DSP_IDLE_RETRY 10 + +static int nau8310_dsp_set_kcs_setup(struct snd_soc_component *component); + +#define NAU_DSP_CMD(_id, _msg, _setup, _reply) \ + [_id] = { \ + .cmd_id = _id, \ + .msg_param = _msg, \ + .setup_data = _setup, \ + .reply_data = _reply, \ + } + +#define NAU_DSP_CMD_ID(_id) \ + [_id] = { \ + .cmd_id = _id, \ + } + +/* + * Preamble Fragment Masks: + * FIELD | BITS | SHIFT | MASK | DETAILS + * ----------------|--------|-------|------|--------------------------------- + * length high | [31:24]| 24 | 0xff | Upper 8 bits of total length (LEN[9:2]) + * cmd_id | [23:18]| 18 | 0x3f | Command identifier (6 bits) + * length low | [17:16]| 16 | 0x03 | Lower 2 bits of total length (LEN[1:0]) + * preamble magic | [15:0] | 0 |0xffff| Preamble signature (0xB2A1) + */ +#define NAU8310_HOST_LEN_HIGH_MASK GENMASK(31, 24) +#define NAU8310_HOST_CMD_ID_MASK GENMASK(23, 18) +#define NAU8310_HOST_LEN_LOW_MASK GENMASK(17, 16) +#define NAU8310_HOST_PREAMBLE_MASK GENMASK(15, 0) + +/* + * Payload Fragment Masks: + * FIELD | BITS | SHIFT | MASK | DETAILS + * ----------------|--------|-------|------|--------------------------------- + * param_size | [31:16]| 16 |0xffff| Size of parameter data (16 bits) + * param_offset | [15:0] | 0 |0xffff| Starting offset (16 bits) + */ +#define NAU8310_HOST_PARAM_SIZE_MASK GENMASK(31, 16) +#define NAU8310_HOST_PARAM_OFFSET_MASK GENMASK(15, 0) + +/* + * Trailing Fragment Masks: + * FIELD | BITS | SHIFT | MASK | DETAILS + * ----------------|--------|-------|------|--------------------------------- + * length high | [15:14]| 14 | 0x03 | Upper 2 bits of total length + * padding | [13:12]| 12 | 0x03 | Padding bytes count + * length low | [7:0] | 0 | 0xff | Lower 8 bits of total length + * Note: Reassembled length = (length_high << 8) | length_low (Total 10 bits) + */ +#define NAU8310_TRAIL_LEN_LOW_MASK GENMASK(7, 0) +#define NAU8310_TRAIL_PAD_MASK GENMASK(13, 12) +#define NAU8310_TRAIL_LEN_HIGH_MASK GENMASK(15, 14) + +/* + * Reply Preamble Masks: + * FIELD | BITS | SHIFT | MASK | DETAILS + * ----------------|--------|-------|------|--------------------------------- + * length high | [31:24]| 24 | 0xff | Upper 8 bits of total length + * reply_id | [23:18]| 18 | 0x3f | Reply identifier (6 bits) + * length low | [17:16]| 16 | 0x03 | Lower 2 bits of total length + * Note: Reassembled length = (length_high << 2) | length_low (Total 10 bits) + */ +#define NAU8310_REPLY_LEN_HIGH_MASK GENMASK(31, 24) +#define NAU8310_REPLY_ID_MASK GENMASK(23, 18) +#define NAU8310_REPLY_LEN_LOW_MASK GENMASK(17, 16) + +static const struct nau8310_cmd_info nau8310_dsp_cmd_table[] = { + /* { cmd_id, msg_param, setup_data, reply_data} */ + NAU_DSP_CMD(NAU8310_DSP_CMD_GET_COUNTER, 0, 0, 1), + NAU_DSP_CMD(NAU8310_DSP_CMD_GET_FRAME_STATUS, 0, 0, 1), + NAU_DSP_CMD(NAU8310_DSP_CMD_GET_REVISION, 0, 0, 1), + NAU_DSP_CMD(NAU8310_DSP_CMD_GET_KCS_RSLTS, 1, 0, 1), + NAU_DSP_CMD(NAU8310_DSP_CMD_GET_KCS_SETUP, 1, 0, 1), + NAU_DSP_CMD(NAU8310_DSP_CMD_SET_KCS_SETUP, 1, 1, 0), + NAU_DSP_CMD_ID(NAU8310_DSP_CMD_CLK_STOP), + NAU_DSP_CMD_ID(NAU8310_DSP_CMD_CLK_RESTART), +}; + +static const char *const dsp_cmd_table[] = { + [NAU8310_DSP_CMD_GET_COUNTER] = "GET_COUNTER", + [NAU8310_DSP_CMD_GET_FRAME_STATUS] = "GET_FRAME_STATUS", + [NAU8310_DSP_CMD_GET_REVISION] = "GET_REVISION", + [NAU8310_DSP_CMD_GET_KCS_RSLTS] = "GET_KCS_RSLTS", + [NAU8310_DSP_CMD_GET_KCS_SETUP] = "GET_KCS_SETUP", + [NAU8310_DSP_CMD_SET_KCS_SETUP] = "SET_KCS_SETUP", + [NAU8310_DSP_CMD_CLK_STOP] = "CLK_STOP", + [NAU8310_DSP_CMD_CLK_RESTART] = "CLK_RESTART", +}; + +static int nau8310_dsp_idle(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + unsigned int idle_pattern, timeout = NAU8310_DSP_IDLE_RETRY * USEC_PER_MSEC; + int ret = 0; + + ret = regmap_read_poll_timeout(regmap, + NAU8310_RF000_DSP_COMM, idle_pattern, + idle_pattern == NAU8310_DSP_COMM_IDLE_WORD, USEC_PER_MSEC, timeout); + if (ret) { + dev_err(nau8310->dev, "Timeout waiting for DSP idle state: %d", ret); + nau8310_software_reset(regmap); + } + + return ret; +} + +/* + * nau8310_pack_preamble - Pack DSP preamble fragment + * @cmd_id: Command ID for the DSP message + * @frag_len: Total length of the message fragments + * + * Return: 32-bit packed payload in Little Endian format. + */ +static inline u32 nau8310_pack_preamble(u8 cmd_id, u16 frag_len) +{ + return FIELD_PREP(NAU8310_HOST_PREAMBLE_MASK, NAU8310_DSP_COMM_PREAMBLE) | + FIELD_PREP(NAU8310_HOST_CMD_ID_MASK, cmd_id) | + FIELD_PREP(NAU8310_HOST_LEN_LOW_MASK, frag_len) | + FIELD_PREP(NAU8310_HOST_LEN_HIGH_MASK, frag_len >> 2); +} + +/* + * nau8310_pack_param - Pack DSP parameter fragment + * @param_offset: Starting offset of the parameter data + * @param_size: Size of the parameter data in bytes + * + * Return: 32-bit packed payload in Little Endian format. + */ +static inline u32 nau8310_pack_param(u16 param_offset, u16 param_size) +{ + return FIELD_PREP(NAU8310_HOST_PARAM_OFFSET_MASK, param_offset) | + FIELD_PREP(NAU8310_HOST_PARAM_SIZE_MASK, param_size); +} + +/* + * nau8310_pack_trailing - Pack DSP trailing fragment + * @frag_cnt: Current fragment count + * @padding: Number of padding bytes added to the final data fragment + * + * Return: 32-bit packed payload in Little Endian format. + */ +static inline u32 nau8310_pack_trailing(u16 frag_cnt, u8 padding) +{ + return FIELD_PREP(NAU8310_TRAIL_LEN_LOW_MASK, frag_cnt) | + FIELD_PREP(NAU8310_TRAIL_PAD_MASK, padding) | + FIELD_PREP(NAU8310_TRAIL_LEN_HIGH_MASK, frag_cnt >> 8); +} + +static void nau8310_send_data_payload(struct snd_soc_component *cp, + unsigned short dsp_addr, const void *param_data, int param_size, + int *frag_cnt, int *padding) +{ + const u8 *data = (const u8 *)param_data; + u32 payload = 0; + int i, data_size = 0; + + for (i = 0; i < param_size; i++) { + payload |= (u32)data[i] << (data_size * 8); + data_size++; + + if (data_size == NAU8310_DSP_DATA_BYTE) { + snd_soc_component_write(cp, dsp_addr, payload); + + data_size = 0; + payload = 0; + (*frag_cnt)++; + } + } + + if (data_size > 0) { + *padding = NAU8310_DSP_DATA_BYTE - data_size; + snd_soc_component_write(cp, dsp_addr, payload); + (*frag_cnt)++; + } +} + +static int nau8310_message_to_dsp(struct snd_soc_component *cp, + const struct nau8310_cmd_info *cmd_info, int frag_len, + int param_offset, int param_size, void *param_data) +{ + unsigned int payload; + int ret, padding = 0, frag_cnt = 0; + + ret = nau8310_dsp_idle(cp); + if (ret) + return ret; + + /* sending preamble fragment */ + payload = nau8310_pack_preamble(cmd_info->cmd_id, frag_len); + snd_soc_component_write(cp, NAU8310_RF000_DSP_COMM, payload); + + if (!cmd_info->msg_param) + return 0; + + /* sending payload + padding */ + payload = nau8310_pack_param(param_offset, param_size); + snd_soc_component_write(cp, NAU8310_RF000_DSP_COMM, payload); + frag_cnt++; + + if (cmd_info->setup_data) + nau8310_send_data_payload(cp, NAU8310_RF000_DSP_COMM, param_data, + param_size, &frag_cnt, &padding); + + /* sending trailing fragment */ + frag_cnt++; + payload = nau8310_pack_trailing(frag_cnt, padding); + snd_soc_component_write(cp, NAU8310_RF000_DSP_COMM, payload); + + if (frag_cnt != frag_len) { + dev_err(cp->dev, "message error (CMD_ID 0x%x, LEN 0x%x) !!!", + cmd_info->cmd_id, frag_cnt); + return -EPROTO; + } + + return 0; +} + +static int nau8310_dsp_replied(struct nau8310 *nau8310, int *length) +{ + unsigned int reply_preamble; + int ret, reply_id; + + ret = regmap_read_poll_timeout(nau8310->regmap, + NAU8310_RF000_DSP_COMM, reply_preamble, + (reply_preamble & 0xffff) == NAU8310_DSP_COMM_PREAMBLE, + USEC_PER_MSEC, NAU8310_DSP_IDLE_RETRY * USEC_PER_MSEC); + if (ret) { + dev_err(nau8310->dev, "timeout for reply preamble: %d", ret); + return ret; + } + + *length = FIELD_GET(NAU8310_REPLY_LEN_LOW_MASK, reply_preamble); + *length |= FIELD_GET(NAU8310_REPLY_LEN_HIGH_MASK, reply_preamble) << 2; + reply_id = FIELD_GET(NAU8310_REPLY_ID_MASK, reply_preamble); + + return (reply_id != NAU8310_DSP_REPLY_OK) ? -reply_id : 0; +} + +static int nau8310_validate_trailing(struct snd_soc_component *cp, + int frag_len, int pad_len_exp) +{ + int ret, len_pos, pad_len; + unsigned int payload; + struct device *dev = cp->dev; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + + /* reading trailing fragment */ + ret = regmap_read(nau8310->regmap, NAU8310_RF000_DSP_COMM, &payload); + if (ret) { + dev_err(dev, "failed to read trailing fragment"); + return ret; + } + + len_pos = FIELD_GET(NAU8310_TRAIL_LEN_LOW_MASK, payload); + len_pos |= FIELD_GET(NAU8310_TRAIL_LEN_HIGH_MASK, payload) << 8; + + if (len_pos != frag_len) { + dev_err(dev, "LEN_POST %02X, expect %02X", len_pos, frag_len); + return -EPROTO; + } + + pad_len = FIELD_GET(NAU8310_TRAIL_PAD_MASK, payload); + if (pad_len != pad_len_exp) { + dev_err(dev, "PAD_LEN %02X, expect %02X", pad_len, pad_len_exp); + return -EPROTO; + } + + return 0; +} + +static int nau8310_read_data_payload(struct snd_soc_component *cp, + int frag_len, bool msg_param, + void *data, int data_size, int *data_count) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct device *dev = cp->dev; + unsigned int payload; + u32 *data_buf = data; + int i, j, ret; + + *data_count = (msg_param) ? data_size : 0; + for (i = 0; i < frag_len - 1; i++) { + ret = regmap_read(nau8310->regmap, NAU8310_RF000_DSP_COMM, &payload); + if (ret) { + dev_err(dev, "failed to read payload of dsp"); + return ret; + } + + if (!msg_param) { + *data_buf++ = payload; + break; + } + + if (*data_count >= NAU8310_DSP_DATA_BYTE) { + *data_buf++ = payload; + *data_count -= NAU8310_DSP_DATA_BYTE; + } else if (*data_count > 0) { + for (j = 0; j < *data_count; j++) + ((u8 *)data_buf)[j] = (payload >> (j * 8)) & 0xff; + + *data_count = 0; + } + + if (*data_count == 0) + break; + } + + return 0; +} + +static int nau8310_reply_from_dsp(struct snd_soc_component *cp, + const struct nau8310_cmd_info *cmd_info, int data_size, + void *data) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct device *dev = cp->dev; + int ret, frag_len, pad_len_exp, data_count = 0; + + ret = nau8310_dsp_replied(nau8310, &frag_len); + if (ret) + return ret; + if (!frag_len || !cmd_info->reply_data) + return 0; + if (!data || frag_len == 1) + return -EINVAL; + + ret = nau8310_read_data_payload(cp, frag_len, + cmd_info->msg_param, data, data_size, &data_count); + if (ret) + return ret; + + /* check the reply length same as request */ + if (data_count && (cmd_info->cmd_id == NAU8310_DSP_CMD_GET_KCS_RSLTS || + cmd_info->cmd_id == NAU8310_DSP_CMD_GET_KCS_SETUP)) + dev_warn(dev, "payload_len %d, expected %d", + data_size - data_count, data_size); + + pad_len_exp = cmd_info->msg_param ? + (frag_len - 1) * NAU8310_DSP_DATA_BYTE - (data_size - data_count) : 0; + return nau8310_validate_trailing(cp, frag_len, pad_len_exp); +} + +/* + * nau8310_send_dsp_command - Send command to DSP + * + * @cp: component to register + * @cmd_id: DSP supported command ID + * @kcs_setup: KCS setup structure + * + * The communication protocol is a Master-Slave type protocol + * where the host processor is the master and DSP is the slave. + * The Master initiates the communication and can either write or + * read back from the slave. + * Transactions from the Master are called "Messages", + * and read-back data from the Slave is called a "Reply". + * + * The function sends command to DSP according to the command ID. + * These commands include getting the information of DSP, + * getting or setting KCS configuration, or making DSP control. + */ +static int nau8310_send_dsp_command(struct snd_soc_component *cp, int cmd_id, + struct nau8310_kcs_setup *kcs_setup) +{ + const struct nau8310_cmd_info *cmd_info; + int ret = 0, frag_len = 0; + + cmd_info = &nau8310_dsp_cmd_table[cmd_id]; + if ((cmd_info->msg_param && !kcs_setup->set_len) || + (cmd_info->setup_data && !kcs_setup->set_kcs_data) || + (cmd_info->reply_data && !kcs_setup->get_data)) + return -EFAULT; + + /* + * Read up to 1kB data because the LEN field to request data is 10-bits + * long; and not beyond 3kB offset. + */ + if (cmd_id == NAU8310_DSP_CMD_GET_KCS_SETUP && + (kcs_setup->set_len > NAU8310_DSP_KCS_DAT_LEN_MAX || + kcs_setup->set_kcs_offset > NAU8310_DSP_KCS_OFFSET_MAX)) + return -ERANGE; + + /* + * one fragment for offset and size parameters + * one fragment for a postamble fragment + */ + if (cmd_info->msg_param) + frag_len += 2; + + /* fragments for KCS setup writen */ + if (cmd_info->setup_data) + frag_len += DIV_ROUND_UP(kcs_setup->set_len, NAU8310_DSP_DATA_BYTE); + + ret = nau8310_message_to_dsp(cp, cmd_info, frag_len, + kcs_setup->set_kcs_offset, kcs_setup->set_len, + kcs_setup->set_kcs_data); + if (ret) + return ret; + + return nau8310_reply_from_dsp(cp, cmd_info, kcs_setup->get_len, + kcs_setup->get_data); +} + +static inline int nau8310_dsp_exec_command(struct snd_soc_component *cp, int cmd_id, + int offset, int set_len, void *set_data, int get_len, void *get_data) +{ + struct nau8310_kcs_setup kcs_setup = { + .set_kcs_offset = offset, + .set_len = set_len, + .set_kcs_data = set_data, + .get_len = get_len, + .get_data = get_data, + }; + + return nau8310_send_dsp_command(cp, cmd_id, &kcs_setup); +} + +/* + * nau8310_dsp_kcs_setup - Send KCS setup command to DSP + * + * @cp: component to register + * @offset: address offset relative to KCS start + * @size: size of data writen to KCS + * @data: data writen to KCS setup + * + * The function sends KCS setup command to DSP for + * setting KCS configuration. The maximum size that you can transfer into + * the DSP is 96 bytes. Therefore, the driver has to split the data into + * 96 bytes chucks, if the setup configuration over the threshold. + */ +static int nau8310_dsp_kcs_setup(struct snd_soc_component *cp, int offset, int size, + const void *data) +{ + u8 *data_buf = (u8 *)data; + unsigned int kcs_rst = 0; + int retries = 0, ret, data_len, data_rem, addr_offset; + + /* Limit full load of KCS_SETUP data and not beyond 3kB offset. */ + if (!data || size > NAU8310_DSP_KCS_DAT_LEN_MAX || + offset > NAU8310_DSP_KCS_OFFSET_MAX) + return -EINVAL; + + /* sending fragments for KCS setup */ + addr_offset = offset; + data_rem = size; + + while (data_rem) { + data_len = min(data_rem, NAU8310_DSP_KCS_TX_MAX); + + ret = nau8310_dsp_exec_command(cp, NAU8310_DSP_CMD_SET_KCS_SETUP, + addr_offset, data_len, (void *)data_buf, 0, &kcs_rst); + if (ret) { + if (retries++ < NAU8310_DSP_RETRY_MAX) + continue; + return ret; + } + + data_buf += (u8)data_len; + addr_offset += data_len; + data_rem -= data_len; + + /* checking KCS result */ + ret = nau8310_dsp_exec_command(cp, NAU8310_DSP_CMD_GET_KCS_RSLTS, + 0, NAU8310_DSP_DATA_BYTE, NULL, NAU8310_DSP_DATA_BYTE, &kcs_rst); + if (ret) + return ret; + if (kcs_rst != NAU8310_DSP_KCS_RSLTS_SUCCESS) + return -EINVAL; + } + + return 0; +} + +static int nau8310_dsp_snd_soc_dapm_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kcontrol); + struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(component); + struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; + unsigned int mask = (1 << fls(mc->max)) - 1; + unsigned int val; + + snd_soc_dapm_mutex_lock(dapm); + if (snd_soc_dapm_get_bias_level(dapm) > SND_SOC_BIAS_STANDBY) { + dev_warn_ratelimited(nau8310->dev, "changing path is not allowed during playback"); + snd_soc_dapm_mutex_unlock(dapm); + return -EBUSY; + } + + val = (ucontrol->value.integer.value[0] & mask); + + if (val == NAU8310_DAC_SRC_DSP && !nau8310->load_fw_done) { + dev_warn_ratelimited(nau8310->dev, "Cannot enable DSP: Firmware not ready or disabled"); + snd_soc_dapm_mutex_unlock(dapm); + return -EBUSY; + } + snd_soc_dapm_mutex_unlock(dapm); + + mutex_lock(&nau8310->lock); + regmap_update_bits(nau8310->regmap, NAU8310_R04_ENA_CTRL, + NAU8310_DSP_SEL_OSC, val == NAU8310_DAC_SRC_DSP ? NAU8310_DSP_SEL_OSC : 0); + mutex_unlock(&nau8310->lock); + + return snd_soc_dapm_put_volsw(kcontrol, ucontrol); +} + +#define NAU8310_DSP_SOC_DAPM_SINGLE(xname, reg, shift, mask, invert) \ + SOC_SINGLE_EXT(xname, reg, shift, mask, invert, \ + snd_soc_dapm_get_volsw, nau8310_dsp_snd_soc_dapm_put) + +static const struct snd_kcontrol_new nau8310_dacdat_select_dsp = + NAU8310_DSP_SOC_DAPM_SINGLE("Switch", NAU8310_R1A_DSP_CORE_CTRL2, + NAU8310_DAC_SEL_DSP_SFT, 1, 0); + +static int nau8310_dsp_clock_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(w->dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + int ret = 0; + + mutex_lock(&nau8310->lock); + + if (SND_SOC_DAPM_EVENT_ON(event)) { + ret = nau8310_dsp_exec_command(cp, NAU8310_DSP_CMD_CLK_RESTART, + 0, 0, NULL, 0, NULL); + if (ret) + dev_err(cp->dev, "Send DSP command %s fail (%d)", + dsp_cmd_table[NAU8310_DSP_CMD_CLK_RESTART], ret); + } else { + ret = nau8310_dsp_exec_command(cp, NAU8310_DSP_CMD_CLK_STOP, + 0, 0, NULL, 0, NULL); + if (ret) + dev_err(cp->dev, "Send DSP command %s fail (%d)", + dsp_cmd_table[NAU8310_DSP_CMD_CLK_STOP], ret); + } + + mutex_unlock(&nau8310->lock); + + return ret; +} + +static const struct snd_soc_dapm_widget nau8310_dsp_dapm_widgets[] = { + SND_SOC_DAPM_PGA("DSP", SND_SOC_NOPM, 0, 0, NULL, 0), + SND_SOC_DAPM_SWITCH("DAC data from DSP", SND_SOC_NOPM, + 0, 0, &nau8310_dacdat_select_dsp), + SND_SOC_DAPM_SUPPLY("DSP Clock", SND_SOC_NOPM, 0, 0, + nau8310_dsp_clock_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), +}; + +static const struct snd_soc_dapm_route nau8310_dsp_dapm_routes[] = { + { "DSP", NULL, "Capture Sense" }, + { "DAC data from DSP", "Switch", "DSP" }, + { "DAC", NULL, "DAC data from DSP" }, + { "DSP", NULL, "DSP Clock" }, +}; + +static int nau8310_dsp_set_kcs_setup(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct nau8310_kcs_setup kcs_setup_comp = {0}; + struct nau8310_kcs_setup *kcs_setup = &kcs_setup_comp; + struct device *dev = cp->dev; + const struct firmware *fw; + int ret, status = 0, buf_off, buf_len; + + dev_dbg(dev, "Send DSP command %s", + dsp_cmd_table[NAU8310_DSP_CMD_GET_FRAME_STATUS]); + + kcs_setup->get_len = kcs_setup->set_len = sizeof(status); + kcs_setup->get_data = (void *)&status; + + ret = nau8310_send_dsp_command(cp, NAU8310_DSP_CMD_GET_FRAME_STATUS, kcs_setup); + if (ret) { + dev_err(dev, "Send DSP command %s fail (%d)", + dsp_cmd_table[NAU8310_DSP_CMD_GET_FRAME_STATUS], ret); + goto err; + } + + if (!(status & NAU8310_DSP_ALGO_OK)) { + dev_err(dev, "Algorithm of DSP is not ready, status %x", status); + ret = -EIO; + goto err; + } + + dev_dbg(dev, "DSP is ready to load firmware %s, status %x", nau8310->dsp_firmware, status); + + dev_dbg(dev, "Request firmware and wait until finish."); + ret = request_firmware(&fw, nau8310->dsp_firmware, dev); + if (ret) { + dev_err(dev, "Failed to load firmware (%d)", ret); + goto err; + } + + buf_off = 0; + buf_len = nau8310->kcs_setup_size = fw->size; + dev_dbg(dev, "Send DSP command %s (OFF %d, LEN %d)", + dsp_cmd_table[NAU8310_DSP_CMD_SET_KCS_SETUP], buf_off, buf_len); + ret = nau8310_dsp_kcs_setup(cp, buf_off, buf_len, fw->data); + if (ret) { + dev_err(dev, "Send DSP command %s fail (%d)", + dsp_cmd_table[NAU8310_DSP_CMD_SET_KCS_SETUP], ret); + goto err_loaded; + } + + release_firmware(fw); + nau8310->load_fw_done = true; + + return 0; + +err_loaded: + if (fw) + release_firmware(fw); +err: + nau8310->load_fw_done = false; + return ret; +} + +int nau8310_dsp_init(struct snd_soc_component *cp) +{ + struct regmap *regmap = cp->regmap; + + nau8310_software_reset(regmap); + + /* wait for the power ready */ + msleep(120); + + regmap_update_bits(regmap, NAU8310_R1A_DSP_CORE_CTRL2, + NAU8310_DSP_RUNSTALL, 0); + + return nau8310_dsp_set_kcs_setup(cp); +} + +int nau8310_dsp_setup_controls(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct snd_soc_dapm_context *dapm = nau8310->dapm; + int ret; + + ret = snd_soc_dapm_new_controls(dapm, nau8310_dsp_dapm_widgets, + ARRAY_SIZE(nau8310_dsp_dapm_widgets)); + if (ret) { + dev_err(cp->dev, "Add DSP widget fail (%d)", ret); + return ret; + } + + ret = snd_soc_dapm_add_routes(dapm, nau8310_dsp_dapm_routes, + ARRAY_SIZE(nau8310_dsp_dapm_routes)); + if (ret) { + dev_err(cp->dev, "Add DSP route fail (%d)", ret); + return ret; + } + + return 0; +} diff --git a/sound/soc/codecs/nau8310-dsp.h b/sound/soc/codecs/nau8310-dsp.h new file mode 100644 index 00000000000000..2e3cbbc9c077a3 --- /dev/null +++ b/sound/soc/codecs/nau8310-dsp.h @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// The NAU83G10/20 Boosted Mono Class-D Amplifier with DSP and I/V-sense driver. +// +// Copyright 2026 Nuvoton Technology Crop. +// Author: John Hsu +// David Lin +// Neo Chang + +#ifndef __NAU8310_DSP_H__ +#define __NAU8310_DSP_H__ + +#define NAU8310_DSP_COMM_IDLE_WORD 0xf4f3f2f1 +#define NAU8310_DSP_COMM_PREAMBLE 0xb2a1 +#define NAU8310_DSP_DATA_BYTE 4 +#define NAU8310_DSP_DATA_LEN (NAU8310_DSP_DATA_BYTE << 3) +/* max bytes of data to transfer into DSP each time during the KCS setup */ +#define NAU8310_DSP_KCS_TX_MAX 96 +#define NAU8310_DSP_RETRY_MAX 3 +#define NAU8310_DSP_KCS_DAT_LEN_BITS 10 +#define NAU8310_DSP_KCS_DAT_LEN_MAX 1024 +#define NAU8310_DSP_KCS_OFFSET_MAX 3072 +#define NAU8310_DSP_KCS_RSLTS_SUCCESS 0x10 + +/* FRAME_STATUS (0x9) */ +#define NAU8310_DSP_SNS_OVF_SFT 31 +#define NAU8310_DSP_SNS_OVF (0x1 << NAU8310_DSP_SNS_OVF_SFT) +#define NAU8310_DSP_AUD_UVF_SFT 30 +#define NAU8310_DSP_AUD_UVF (0x1 << NAU8310_DSP_AUD_UVF_SFT) +#define NAU8310_DSP_AUD_OVF_SFT 29 +#define NAU8310_DSP_AUD_OVF (0x1 << NAU8310_DSP_AUD_OVF_SFT) +#define NAU8310_DSP_ALC_STS_SFT 28 +#define NAU8310_DSP_ALC_STS (0x1 << NAU8310_DSP_ALC_STS_SFT) +#define NAU8310_DSP_CLK_STOP_SFT 25 +#define NAU8310_DSP_CLK_STOP (0x1 << NAU8310_DSP_CLK_STOP_SFT) +#define NAU8310_DSP_OCP_OTP_SFT 24 +#define NAU8310_DSP_OCP_OTP (0x1 << NAU8310_DSP_OCP_OTP_SFT) +#define NAU8310_DSP_UVLO_SFT 22 +#define NAU8310_DSP_UVLO (0x1 << NAU8310_DSP_UVLO_SFT) +#define NAU8310_DSP_OVP_SFT 21 +#define NAU8310_DSP_OVP (0x1 << NAU8310_DSP_OVP_SFT) +#define NAU8310_DSP_APWR_DWN_SFT 20 +#define NAU8310_DSP_APWR_DWN (0x1 << NAU8310_DSP_APWR_DWN_SFT) +#define NAU8310_DSP_SNSR_RATE_SFT 12 +#define NAU8310_DSP_SNSR_RATE_MASK (0xff << NAU8310_DSP_SNSR_RATE_SFT) +#define NAU8310_DSP_AUD_RATE_SFT 4 +#define NAU8310_DSP_AUD_RATE_MASK (0xff << NAU8310_DSP_AUD_RATE_SFT) +#define NAU8310_DSP_FEED_TRU_SFT 1 +#define NAU8310_DSP_FEED_TRU (0x1 << NAU8310_DSP_FEED_TRU_SFT) +#define NAU8310_DSP_ALGO_OK 0x1 + +#define NAU8310_DSP_FIRMDIR "Nuvoton/" +#define NAU8310_DSP_FIRMWARE NAU8310_DSP_FIRMDIR"NAU83G10.kcs.bin" +#define NAU8310_DSP_FWHDR_SIZE 8 +#define NAU8310_DSP_FWHDR_SIREV 4 +#define NAU8310_DSP_FW_KCS_DATA NAU8310_DSP_FWHDR_SIZE + +enum { + NAU8310_DSP_REPLY_OK, + NAU8310_DSP_REPLY_MSG_INTEGRETY_ERR, + NAU8310_DSP_REPLY_EXECUTION_ERR, + NAU8310_DSP_REPLY_COMMAND_DOESNT_EXISTS_ERR, + NAU8310_DSP_REPLY_UNKNOWN_ERR, + NAU8310_DSP_REPLY_MSG_TOO_LONG, +}; + +enum { + NAU8310_DSP_CMD_GET_COUNTER = 0x1, + NAU8310_DSP_CMD_GET_FRAME_STATUS = 0x9, + NAU8310_DSP_CMD_GET_REVISION = 0xa, + NAU8310_DSP_CMD_GET_KCS_RSLTS = 0x4, + NAU8310_DSP_CMD_GET_KCS_SETUP = 0x6, + NAU8310_DSP_CMD_SET_KCS_SETUP = 0x7, + NAU8310_DSP_CMD_CLK_STOP = 0xb, + NAU8310_DSP_CMD_CLK_RESTART = 0xc, +}; + +/** + * struct nau8310_cmd_info - DSP command information structure + * @cmd_id: The command identification number + * @msg_param: Message parameters including offset, size, and data + * @setup_data: Setup data for write-only operations + * @reply_data: Reply data received from the DSP + */ +struct nau8310_cmd_info { + int cmd_id; + bool msg_param; + bool setup_data; + bool reply_data; +}; + +/** + * struct nau8310_kcs_setup - KCS setup configuration structure + * @set_len: Length of data written in bytes + * @set_kcs_offset: Address offset relative to the start of KCS + * @set_kcs_data: Pointer to the data written to KCS + * @get_len: Length of data from the reply in bytes + * @get_data: Pointer to the buffer for reply data + */ +struct nau8310_kcs_setup { + int set_len; + int set_kcs_offset; + void *set_kcs_data; + int get_len; + void *get_data; +}; + +int nau8310_dsp_init(struct snd_soc_component *component); +int nau8310_dsp_setup_controls(struct snd_soc_component *component); + +#endif /* __NAU8310_DSP_H__ */ diff --git a/sound/soc/codecs/nau8310.c b/sound/soc/codecs/nau8310.c new file mode 100644 index 00000000000000..257b538f6b1455 --- /dev/null +++ b/sound/soc/codecs/nau8310.c @@ -0,0 +1,2068 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// The NAU83G10/20 Boosted Mono Class-D Amplifier with DSP and I/V-sense driver. +// +// Copyright 2026 Nuvoton Technology Crop. +// Author: John Hsu +// David Lin +// Neo Chang + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nau8310-dsp.h" +#include "nau8310.h" + +/* Range of Master Clock MCLK (Hz) */ +#define MASTER_CLK_MIN 2048000 +#define MASTER_CLK_MAX 49152000 +/* DSP Clock (Hz) */ +#define DSP_CLK_MIN_MULTI_VALUE 2000 +#define DSP_CLK_MAX 102400000 +#define DSP_MCLK_HI_SPEED 12288000 + +#define NAU8310_DEFAULT_FS 48000 +#define NAU8310_SCLK_MULT 256 + +static const unsigned int nau8310_tx_slot_map[NAU8310_TDM_MAX_SLOTS] = { + NAU8310_ADC_V_SEL_SLOT0, + NAU8310_ADC_I_SEL_SLOT1, + NAU8310_ADC_V_SEL_SLOT2, + NAU8310_ADC_I_SEL_SLOT3, + NAU8310_ADC_V_SEL_SLOT4, + NAU8310_ADC_I_SEL_SLOT5, + NAU8310_ADC_V_SEL_SLOT6, + NAU8310_ADC_I_SEL_SLOT7 +}; + +static const unsigned int nau8310_rx_slot_map[NAU8310_TDM_MAX_SLOTS] = { + NAU8310_DAC_SEL_SLOT0, + NAU8310_DAC_SEL_SLOT1, + NAU8310_DAC_SEL_SLOT2, + NAU8310_DAC_SEL_SLOT3, + NAU8310_DAC_SEL_SLOT4, + NAU8310_DAC_SEL_SLOT5, + NAU8310_DAC_SEL_SLOT6, + NAU8310_DAC_SEL_SLOT7, +}; + +static const struct nau8310_src_attr dsp_src_mult[] = { + /* param : power of 2 */ + { 0, 0x3 }, + { 1, 0x2 }, + { 2, 0x1 }, + { 3, 0x0 }, + { 4, 0x4 }, +}; + +/* scaling for MCLK source */ +#define CLK_PROC_BYPASS (-1) + +static const struct nau8310_src_attr mclk_n1_div[] = { + { 3, 0x2 }, + { 1, 0x0 }, + { 2, 0x1 }, +}; + +static const struct nau8310_src_attr mclk_n2_div[] = { + /* param : power of 2 */ + { 0, 0x0 }, + { 1, 0x1 }, + { 2, 0x2 }, + { 3, 0x3 }, +}; + +static const struct nau8310_src_attr mclk_src_mult[] = { + /* param : power of 2 */ + { 0, 0x1 }, + { 1, 0x2 }, + { 2, 0x3 }, + { 3, 0x4 }, + { 4, 0x5 }, +}; + +/* Sample Rate and MCLK_SRC selections */ +static const struct nau8310_srate_attr target_srate_table[] = { + /* { FS, range, max, { MCLK source }, adc_div} */ + { 48000, 2, true, { 12288000, 19200000, 24000000 }, 0x1 }, + { 16000, 1, false, { 4096000, 6400000, 8000000 }, 0x0 }, + { 8000, 0, false, { 2048000, 3200000, 4000000 }, 0x0 }, + { 44100, 2, true, { 11289600, 17640000, 22050000 }, 0x1 }, + { 64000, 3, false, { 16384000, 25600000, 32000000 }, 0x1 }, + { 96000, 3, true, { 24576000, 38400000, 48000000 }, (-1) }, + { 12000, 0, true, { 3072000, 4800000, 6000000 }, 0x0 }, + { 24000, 1, true, { 6144000, 9600000, 12000000 }, 0x2 }, + { 32000, 2, false, { 8192000, 12800000, 16000000 }, 0x2 }, +}; + +/* the maximum frequency of CLK_ADC and CLK_DAC */ +#define CLK_DA_AD_MAX 6144000 + +/* over sampling rate */ +static const struct nau8310_osr_attr osr_dac_sel[] = { + { 64, 2 }, /* OSR 64, SRC 1/4 */ + { 256, 0 }, /* OSR 256, SRC 1 */ + { 128, 1 }, /* OSR 128, SRC 1/2 */ + { 0, 0 }, + { 32, 3 }, /* OSR 32, SRC 1/8 */ +}; + +static const struct nau8310_osr_attr osr_adc_sel[] = { + { 32, 2 }, /* OSR 32, SRC 1/8 */ + { 64, 1 }, /* OSR 64, SRC 1/4 */ + { 128, 0 }, /* OSR 128, SRC 1/2 */ +}; + +/* + * For a typical 48kHz frame sync I2S signal on DSP case, the ADC sampling rate + * must be 12kHz. So the specfied OSR to SRC divider is need to divide by 4. + */ +static const struct nau8310_osr_attr osr_adc_dsp_sel[] = { + { 0, 0 }, /* no such case */ + { 64, 3 }, /* OSR 64, SRC 1/16 */ + { 128, 2 }, /* OSR 128, SRC 1/8 */ +}; + +static const struct reg_default nau8310_reg_defaults[] = { + { NAU8310_R02_I2C_ADDR, 0x0000 }, + { NAU8310_R03_CLK_CTRL, 0x0000 }, + { NAU8310_R04_ENA_CTRL, 0x0000 }, + { NAU8310_R05_INTERRUPT_CTRL, 0x007f }, + { NAU8310_R06_INT_CLR_STATUS, 0x0000 }, + { NAU8310_R07_SAR_CTRL1, 0x00b4 }, + { NAU8310_R08_GPIO124_CTRL, 0x0102 }, + { NAU8310_R09_GPIOOUT, 0x0000 }, + { NAU8310_R0A_IO_CTRL, 0x0000 }, + { NAU8310_R0B_I2S_PCM_CTRL0, 0x0000 }, + { NAU8310_R0C_TDM_CTRL, 0x0c00 }, + { NAU8310_R0D_I2S_PCM_CTRL1, 0x000a }, + { NAU8310_R0E_I2S_PCM_CTRL2, 0x8010 }, + { NAU8310_R0F_LEFT_TIME_SLOT, 0x0000 }, + { NAU8310_R10_RIGHT_TIME_SLOT, 0x0000 }, + { NAU8310_R12_HPF_CTRL, 0x0010 }, + { NAU8310_R13_MUTE_CTRL, 0x00cf }, + { NAU8310_R14_ADC_VOL_CTRL, 0x0000 }, + { NAU8310_R15_INT_COE, 0xa41f }, + { NAU8310_R16_DEC_COE, 0xb7cd }, + { NAU8310_R17_BOOST_CTRL1, 0x3f00 }, + { NAU8310_R18_BOOST_CTRL2, 0x0000 }, + { NAU8310_R19_DSP_CORE_CTRL1, 0x0000 }, + { NAU8310_R1A_DSP_CORE_CTRL2, 0x0000 }, + { NAU8310_R28_ADC_RATE, 0x0002 }, + { NAU8310_R29_DAC_CTRL1, 0x0081 }, + { NAU8310_R2A_DAC_CTRL2, 0x0000 }, + { NAU8310_R2C_ALC_CTRL1, 0x2000 }, + { NAU8310_R2D_ALC_CTRL2, 0x8400 }, + { NAU8310_R2E_ALC_CTRL3, 0x0000 }, + { NAU8310_R2F_ALC_CTRL4, 0x00bf }, + { NAU8310_R30_TEMP_COMP_CTRL, 0x7df4 }, + { NAU8310_R31_UVLO_CTRL0, 0x0000 }, + { NAU8310_R32_UVLO_CTRL1, 0x0000 }, + { NAU8310_R33_LPF_CTRL, 0x7380 }, + { NAU8310_R40_CLK_DET_CTRL, 0xa801 }, + { NAU8310_R55_MISC_CTRL, 0x0000 }, + { NAU8310_R60_BIAS_ADJ, 0x0000 }, + { NAU8310_R61_ANALOG_CONTROL_1, 0x0000 }, + { NAU8310_R62_ANALOG_CONTROL_2, 0x0000 }, + { NAU8310_R63_ANALOG_CONTROL_3, 0x0000 }, + { NAU8310_R64_ANALOG_CONTROL_4, 0x0000 }, + { NAU8310_R65_ANALOG_CONTROL_5, 0x0000 }, + { NAU8310_R66_ANALOG_CONTROL_6, 0x0000 }, + { NAU8310_R68_ANALOG_CONTROL_7, 0x0000 }, + { NAU8310_R69_CLIP_CTRL, 0x0000 }, + { NAU8310_R6B_ANALOG_CONTROL_8, 0x0000 }, + { NAU8310_R6C_ANALOG_CONTROL_9, 0x0000 }, + { NAU8310_R71_ANALOG_ADC_1, 0x0011 }, + { NAU8310_R72_ANALOG_ADC_2, 0x0020 }, + { NAU8310_R73_RDAC, 0x0008 }, + { NAU8310_R76_BOOST, 0x0000 }, + { NAU8310_R77_FEPGA, 0x0000 }, + { NAU8310_R7F_POWER_UP_CONTROL, 0x0000 }, + { NAU8310_R80_BIQ0_COE_1, 0x0800 }, + { NAU8310_R81_BIQ0_COE_2, 0x0000 }, + { NAU8310_R82_BIQ0_COE_3, 0x0000 }, + { NAU8310_R83_BIQ0_COE_4, 0x0000 }, + { NAU8310_R84_BIQ0_COE_5, 0x0000 }, + { NAU8310_R85_BIQ0_COE_6, 0x0000 }, + { NAU8310_R86_BIQ0_COE_7, 0x0000 }, + { NAU8310_R87_BIQ0_COE_8, 0x0000 }, + { NAU8310_R88_BIQ0_COE_9, 0x0000 }, + { NAU8310_R89_BIQ0_COE_10, 0x0000 }, + { NAU8310_R8A_BIQ1_COE_1, 0x0000 }, + { NAU8310_R8B_BIQ1_COE_2, 0x0000 }, + { NAU8310_R8C_BIQ1_COE_3, 0x0000 }, + { NAU8310_R8D_BIQ1_COE_4, 0x0000 }, + { NAU8310_R8E_BIQ1_COE_5, 0x0000 }, + { NAU8310_R8F_BIQ1_COE_6, 0x0000 }, + { NAU8310_R90_BIQ1_COE_7, 0x0000 }, + { NAU8310_R91_BIQ1_COE_8, 0x0000 }, + { NAU8310_R92_BIQ1_COE_9, 0x0000 }, + { NAU8310_R93_BIQ1_COE_10, 0x0000 }, + { NAU8310_R94_BIQ2_COE_1, 0x0000 }, + { NAU8310_R95_BIQ2_COE_2, 0x0000 }, + { NAU8310_R96_BIQ2_COE_3, 0x0000 }, + { NAU8310_R97_BIQ2_COE_4, 0x0000 }, + { NAU8310_R98_BIQ2_COE_5, 0x0000 }, + { NAU8310_R99_BIQ2_COE_6, 0x0000 }, + { NAU8310_R9A_BIQ2_COE_7, 0x0000 }, + { NAU8310_R9B_BIQ2_COE_8, 0x0000 }, + { NAU8310_R9C_BIQ2_COE_9, 0x0000 }, + { NAU8310_R9D_BIQ2_COE_10, 0x0000 }, + { NAU8310_RF000_DSP_COMM, 0x0000 }, +}; + +static bool nau8310_readable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case NAU8310_R03_CLK_CTRL ... NAU8310_R10_RIGHT_TIME_SLOT: + case NAU8310_R12_HPF_CTRL ... NAU8310_R2A_DAC_CTRL2: + case NAU8310_R2C_ALC_CTRL1 ... NAU8310_R33_LPF_CTRL: + case NAU8310_R40_CLK_DET_CTRL: + case NAU8310_R46_I2C_DEVICE_ID: + case NAU8310_R4A_ANALOG_READ: + case NAU8310_R55_MISC_CTRL: + case NAU8310_R60_BIAS_ADJ ... NAU8310_R66_ANALOG_CONTROL_6: + case NAU8310_R68_ANALOG_CONTROL_7 ... NAU8310_R69_CLIP_CTRL: + case NAU8310_R6B_ANALOG_CONTROL_8 ... NAU8310_R6C_ANALOG_CONTROL_9: + case NAU8310_R71_ANALOG_ADC_1 ... NAU8310_R73_RDAC: + case NAU8310_R76_BOOST ... NAU8310_R77_FEPGA: + case NAU8310_R7F_POWER_UP_CONTROL ... NAU8310_R9D_BIQ2_COE_10: + case NAU8310_RF000_DSP_COMM: + return true; + default: + return false; + } + +} + +static bool nau8310_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case NAU8310_R00_HARDWARE_RST ... NAU8310_R10_RIGHT_TIME_SLOT: + case NAU8310_R12_HPF_CTRL ... NAU8310_R1A_DSP_CORE_CTRL2: + case NAU8310_R28_ADC_RATE ... NAU8310_R2A_DAC_CTRL2: + case NAU8310_R2C_ALC_CTRL1 ... NAU8310_R33_LPF_CTRL: + case NAU8310_R40_CLK_DET_CTRL: + case NAU8310_R55_MISC_CTRL: + case NAU8310_R60_BIAS_ADJ ... NAU8310_R66_ANALOG_CONTROL_6: + case NAU8310_R68_ANALOG_CONTROL_7 ... NAU8310_R69_CLIP_CTRL: + case NAU8310_R6B_ANALOG_CONTROL_8 ... NAU8310_R6C_ANALOG_CONTROL_9: + case NAU8310_R71_ANALOG_ADC_1 ... NAU8310_R73_RDAC: + case NAU8310_R76_BOOST ... NAU8310_R77_FEPGA: + case NAU8310_R7F_POWER_UP_CONTROL ... NAU8310_R9D_BIQ2_COE_10: + case NAU8310_RF000_DSP_COMM: + return true; + default: + return false; + } +} + +static bool nau8310_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case NAU8310_R00_HARDWARE_RST ... NAU8310_R01_SOFTWARE_RST: + case NAU8310_R06_INT_CLR_STATUS: + case NAU8310_R1B_CLK_DOUBLER_O ... NAU8310_R27_DSP_STATUS_2: + case NAU8310_R46_I2C_DEVICE_ID: + case NAU8310_R4A_ANALOG_READ: + case NAU8310_RF000_DSP_COMM: + return true; + default: + return false; + } +} + +static int nau8310_clkdet_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; + struct snd_soc_component *cp = snd_kcontrol_chip(kcontrol); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + unsigned int max = mc->max, min = mc->min, val; + unsigned int mask = (1 << fls(max)) - 1; + + val = ((ucontrol->value.integer.value[0] + min) & mask); + + if (nau8310->clock_detection == val) + return 0; + + nau8310->clock_detection = val; + + if (nau8310->clock_detection) + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_CLKPWRUP_DIS, 0); + else + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_CLKPWRUP_DIS, NAU8310_CLKPWRUP_DIS); + + return 1; +} + +static int nau8310_clkdet_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *cp = snd_kcontrol_chip(kcontrol); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + + ucontrol->value.integer.value[0] = nau8310->clock_detection; + + return 0; +} + +static int nau8310_biq_coeff_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *cp = snd_kcontrol_chip(kcontrol); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct soc_bytes_ext *params = (void *)kcontrol->private_value; + int i, reg_val; + __be16 *val = (__be16 *)ucontrol->value.bytes.data; + + for (i = 0; i < params->max / sizeof(u16); i++) { + regmap_read(nau8310->regmap, NAU8310_R80_BIQ0_COE_1 + i, ®_val); + /* + * conversion of 16-bit integers between native CPU format + * and big endian format + */ + *(val + i) = cpu_to_be16(reg_val); + } + + return 0; +} + +static int nau8310_biq_coeff_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *cp = snd_kcontrol_chip(kcontrol); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct soc_bytes_ext *params = (void *)kcontrol->private_value; + __be16 *data = NULL; + int i; + + data = kmemdup(ucontrol->value.bytes.data, params->max, GFP_KERNEL); + if (!data) + return -ENOMEM; + + for (i = 0; i < params->max / sizeof(u16); i++) { + /* + * conversion of 16-bit integers between native CPU format + * and big endian format + */ + regmap_write(nau8310->regmap, NAU8310_R80_BIQ0_COE_1 + i, be16_to_cpu(*(data + i))); + } + kfree(data); + + return 0; +} + +static const char * const nau8310_adc_decimation[] = { "32", "64", "128" }; + +static const struct soc_enum nau8310_adc_decimation_enum = + SOC_ENUM_SINGLE(NAU8310_R28_ADC_RATE, NAU8310_ADC_SYNC_DOWN_SFT, + ARRAY_SIZE(nau8310_adc_decimation), nau8310_adc_decimation); + +static const char * const nau8310_dac_oversampl[] = { + "64", "256", "128", "32" }; + +static const unsigned int nau8310_dac_oversampl_val[] = { 0x0, 0x1, 0x2, 0x4 }; + +static const struct soc_enum nau8310_dac_oversampl_enum = + SOC_VALUE_ENUM_SINGLE(NAU8310_R29_DAC_CTRL1, NAU8310_DAC_OVERSAMPLE_SFT, 0x7, + ARRAY_SIZE(nau8310_dac_oversampl), nau8310_dac_oversampl, + nau8310_dac_oversampl_val); + +static const char * const nau8310_i2s_channel[] = { "Right", "Left"}; + +static const struct soc_enum nau8310_aec_channel_sel_enum = + SOC_ENUM_SINGLE(NAU8310_R0B_I2S_PCM_CTRL0, NAU8310_AEC_CH_SEL_SFT, + ARRAY_SIZE(nau8310_i2s_channel), nau8310_i2s_channel); + +static const char * const nau8310_source[] = { "DSP", "Raw Data"}; + +static const struct soc_enum nau8310_aec_source_sel_enum = + SOC_ENUM_SINGLE(NAU8310_R0B_I2S_PCM_CTRL0, NAU8310_AEC_SRC_SEL_SFT, + ARRAY_SIZE(nau8310_source), nau8310_source); + +static const char * const nau8310_adc_alcgain_slot[] = { "Disable", "Slot 0", + "Slot 1", "Slot 2", "Slot 3", "Slot 4", "Slot 5", "Slot 6", "Slot 7" }; + +static const unsigned int nau8310_adc_alcgain_val[] = { + 0x0, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf }; + +static const struct soc_enum nau8310_adc_alcgain_sel_enum = + SOC_VALUE_ENUM_SINGLE(NAU8310_R0C_TDM_CTRL, NAU8310_ADC_ALC_SEL_SFT, + 0xf, ARRAY_SIZE(nau8310_adc_alcgain_slot), + nau8310_adc_alcgain_slot, nau8310_adc_alcgain_val); + +static const char * const nau8310_ivsense_format[] = { "signed", "unsigned" }; + +static const struct soc_enum nau8310_ivsense_format_enum = + SOC_ENUM_SINGLE(NAU8310_R28_ADC_RATE, NAU8310_UNSIGN_IV_SFT, + ARRAY_SIZE(nau8310_ivsense_format), nau8310_ivsense_format); + +/* LB/LM is referred to low battery/limiter mode. */ +static const char * const nau8310_limiter_mode[] = { + "LM with Clip Detection", + "LBLM with Clip Detection", + "LM with Pre-Programmed Limit Level", + "LBLM with Pre-Programmed Limit Level", + "LBLM with Pre-Programmed VBAT Ratio Limit Level" }; + +static const struct soc_enum nau8310_limiter_mode_enum = + SOC_ENUM_SINGLE(NAU8310_R2E_ALC_CTRL3, NAU8310_LIM_MDE_SFT, + ARRAY_SIZE(nau8310_limiter_mode), nau8310_limiter_mode); + +static const DECLARE_TLV_DB_MINMAX(adc_vol_tlv, 0, 2412); +static const DECLARE_TLV_DB_MINMAX(pga_gain_tlv, 0, 1600); + +static const struct snd_kcontrol_new nau8310_snd_controls[] = { + SOC_ENUM("ADC Decimation Rate", nau8310_adc_decimation_enum), + SOC_ENUM("DAC Oversampling Rate", nau8310_dac_oversampl_enum), + SND_SOC_BYTES_EXT("BIQ Coefficients", 60, + nau8310_biq_coeff_get, nau8310_biq_coeff_put), + + SOC_SINGLE_TLV("ADC Left Channel Volume", + NAU8310_R14_ADC_VOL_CTRL, NAU8310_ADC_GAIN_L_SFT, + NAU8310_ADC_GAIN_L_MAX, 0, adc_vol_tlv), + SOC_SINGLE_TLV("ADC Right Channel Volume", + NAU8310_R14_ADC_VOL_CTRL, NAU8310_ADC_GAIN_R_SFT, + NAU8310_ADC_GAIN_R_MAX, 0, adc_vol_tlv), + SOC_SINGLE_TLV("PGA Volume", NAU8310_R7F_POWER_UP_CONTROL, + NAU8310_PGA_GAIN_SFT, NAU8310_PGA_GAIN_MAX, 0, pga_gain_tlv), + + /* Boost Control Target Value Limit. 0.19 V per step. */ + SOC_SINGLE("Boost Target Limit", NAU8310_R17_BOOST_CTRL1, + NAU8310_BSTLIMIT_SFT, NAU8310_BSTLIMIT_MAX, 0), + /* + * Boost Margin Value between Boost Target Voltage and + * Peak Output Level. 0.19 V per step. + */ + SOC_SINGLE("Boost Margin", NAU8310_R17_BOOST_CTRL1, + NAU8310_BSTMARGIN_SFT, NAU8310_BSTMARGIN_MAX, 0), + + SOC_ENUM("AEC Channel", nau8310_aec_channel_sel_enum), + SOC_ENUM("AEC Source", nau8310_aec_source_sel_enum), + SOC_ENUM("ADC ALC Gain Channel Source", nau8310_adc_alcgain_sel_enum), + SOC_SINGLE("PingPong Mode Switch", NAU8310_R0C_TDM_CTRL, + NAU8310_PINGPONG_SFT, 1, 0), + SOC_ENUM("IV Sense Format", nau8310_ivsense_format_enum), + + SOC_SINGLE_EXT("Clock Detection Switch", SND_SOC_NOPM, 0, 1, 0, + nau8310_clkdet_get, nau8310_clkdet_put), + + SOC_SINGLE("AEC Enable Switch", NAU8310_R0B_I2S_PCM_CTRL0, + NAU8310_AEC_MODE_SFT, 1, 0), + SOC_SINGLE("ALC Max Gain", NAU8310_R2C_ALC_CTRL1, + NAU8310_ALC_MAXGAIN_SFT, NAU8310_ALC_MAXGAIN_MAX, 0), + SOC_SINGLE("ALC Min Gain", NAU8310_R2C_ALC_CTRL1, + NAU8310_ALC_MINGAIN_SFT, NAU8310_ALC_MINGAIN_MAX, 0), + SOC_SINGLE("ALC Decay Timer", NAU8310_R2D_ALC_CTRL2, + NAU8310_ALC_DCY_SFT, NAU8310_ALC_DCY_MAX, 0), + SOC_SINGLE("ALC Attack Timer", NAU8310_R2D_ALC_CTRL2, + NAU8310_ALC_ATK_SFT, NAU8310_ALC_ATK_MAX, 0), + SOC_SINGLE("ALC Hold Time", NAU8310_R2D_ALC_CTRL2, + NAU8310_ALC_HLD_SFT, NAU8310_ALC_HLD_MAX, 0), + SOC_SINGLE("ALC Target Level", NAU8310_R2D_ALC_CTRL2, + NAU8310_ALC_LVL_SFT, NAU8310_ALC_LVL_MAX, 0), + SOC_SINGLE("ALC Enable Switch", NAU8310_R2E_ALC_CTRL3, + NAU8310_ALC_EN_SFT, 1, 0), + SOC_ENUM("Limiter Mode Selection", nau8310_limiter_mode_enum), + SOC_SINGLE("Low Battery Limiter Threshold", NAU8310_R2E_ALC_CTRL3, + NAU8310_VBAT_THLD_SFT, NAU8310_VBAT_THLD_MAX, 0), + SOC_SINGLE("Auto Attenuation Enable Switch", NAU8310_R2E_ALC_CTRL3, + NAU8310_AUTOATT_EN_SFT, 1, 0), + SOC_SINGLE("BCLK IO Driver Stronger Switch", NAU8310_R0A_IO_CTRL, + NAU8310_BCLK_DS_SFT, 1, 0), + SOC_SINGLE("LRC IO Driver Stronger Switch", NAU8310_R0A_IO_CTRL, + NAU8310_LRC_DS_SFT, 1, 0), + SOC_SINGLE("ADCDAT IO Driver Stronger Switch", NAU8310_R0A_IO_CTRL, + NAU8310_ADCDAT_DS_SFT, 1, 0), + + SOC_SINGLE("Low Output Noise in Receiver Mode Switch", + NAU8310_R64_ANALOG_CONTROL_4, NAU8310_RECV_MODE_SFT, 1, 0), + + SOC_SINGLE("VBAT Peak Current Limit", + NAU8310_R6B_ANALOG_CONTROL_8, + NAU8310_VBAT_PCL_SFT, NAU8310_VBAT_PCL_MAX, 0), + SOC_SINGLE("VBAT Comparator Threshold", + NAU8310_R6B_ANALOG_CONTROL_8, + NAU8310_VBAT_THD_SFT, NAU8310_VBAT_THD_MAX, 0), + + SOC_SINGLE("ISense PGA Supply Current Trim", + NAU8310_R77_FEPGA, NAU8310_CURR_TRIM_SFT, NAU8310_CURR_TRIM_MAX, 0), +}; + +static const struct snd_kcontrol_new nau8310_alc_gain_select = + SOC_DAPM_SINGLE("Switch", NAU8310_R2C_ALC_CTRL1, + NAU8310_ALC_GAIN_SEL_SFT, 1, 0); + +static int nau8310_clock_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(w->dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + mutex_lock(&nau8310->lock); + /* Switch the clock source of DSP to MCLK. */ + regmap_update_bits(nau8310->regmap, NAU8310_R04_ENA_CTRL, + NAU8310_DSP_SEL_OSC, 0); + mutex_unlock(&nau8310->lock); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int nau8310_powerup_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(w->dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + + if (nau8310->clock_detection) + return 0; + + if (SND_SOC_DAPM_EVENT_ON(event)) + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_PWRUP_DFT, NAU8310_PWRUP_DFT); + else if (SND_SOC_DAPM_EVENT_OFF(event)) + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_PWRUP_DFT, 0); + + return 0; +} + +static int nau8310_adc_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(w->dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + regmap_update_bits(regmap, NAU8310_R0E_I2S_PCM_CTRL2, + NAU8310_I2S_ADCDAT_OE_MASK, NAU8310_I2S_ADCDAT_OE_EN); + break; + case SND_SOC_DAPM_POST_PMD: + regmap_update_bits(regmap, NAU8310_R0E_I2S_PCM_CTRL2, + NAU8310_I2S_ADCDAT_OE_MASK, NAU8310_I2S_ADCDAT_OE_DIS); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int nau8310_dac_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(w->dapm); + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + + /* Soft mute to prevent the pop noise */ + switch (event) { + case SND_SOC_DAPM_POST_PMU: + regmap_update_bits(regmap, NAU8310_R13_MUTE_CTRL, + NAU8310_SOFT_MUTE, 0); + msleep(30); + regmap_update_bits(regmap, NAU8310_R0E_I2S_PCM_CTRL2, + NAU8310_I2S_TRISTATE, 0); + break; + case SND_SOC_DAPM_PRE_PMD: + regmap_update_bits(regmap, NAU8310_R0E_I2S_PCM_CTRL2, + NAU8310_I2S_TRISTATE, NAU8310_I2S_TRISTATE); + regmap_update_bits(regmap, NAU8310_R13_MUTE_CTRL, + NAU8310_SOFT_MUTE, NAU8310_SOFT_MUTE); + msleep(30); + break; + default: + return -EINVAL; + } + + return 0; +} + +static inline bool nau8310_dsp_active(struct snd_soc_component *cp) +{ + return (snd_soc_component_read(cp, NAU8310_R1A_DSP_CORE_CTRL2) & + NAU8310_DAC_SEL_DSP_OUT); +} + +static const struct snd_soc_dapm_widget nau8310_dapm_widgets[] = { + SND_SOC_DAPM_SUPPLY("Clock", SND_SOC_NOPM, 0, 0, + nau8310_clock_event, SND_SOC_DAPM_PRE_PMU), + SND_SOC_DAPM_SUPPLY("PowerUp", SND_SOC_NOPM, 0, 0, + nau8310_powerup_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), + + SND_SOC_DAPM_SWITCH("ALC gain selection mode", SND_SOC_NOPM, + 0, 0, &nau8310_alc_gain_select), + + SND_SOC_DAPM_SIGGEN("Sense"), + + SND_SOC_DAPM_PGA("SAR", NAU8310_R07_SAR_CTRL1, NAU8310_SAR_ENA_SFT, 0, NULL, 0), + SND_SOC_DAPM_PGA("ADC_I", NAU8310_R04_ENA_CTRL, NAU8310_ADCEN_I_SFT, 0, NULL, 0), + SND_SOC_DAPM_PGA("ADC_V", NAU8310_R04_ENA_CTRL, NAU8310_ADCEN_V_SFT, 0, NULL, 0), + SND_SOC_DAPM_PGA("Capture Sense", SND_SOC_NOPM, 0, 0, NULL, 0), + + SND_SOC_DAPM_ADC_E("ADC_OUT", "Capture", SND_SOC_NOPM, 0, 0, + nau8310_adc_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), + + SND_SOC_DAPM_AIF_IN("AIFRX", "Playback", 0, SND_SOC_NOPM, 0, 0), + + SND_SOC_DAPM_DAC_E("DAC", NULL, NAU8310_R04_ENA_CTRL, NAU8310_DAC_CH_EN_SFT, 0, + nau8310_dac_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + + SND_SOC_DAPM_OUTPUT("Speaker"), +}; + +static const struct snd_soc_dapm_route nau8310_dapm_routes[] = { + { "SAR", NULL, "Sense" }, + { "ADC_I", NULL, "Sense" }, + { "ADC_V", NULL, "Sense" }, + { "Capture Sense", NULL, "SAR" }, + { "Capture Sense", NULL, "ADC_I" }, + { "Capture Sense", NULL, "ADC_V" }, + + { "ALC gain selection mode", "Switch", "Capture Sense" }, + { "ADC_OUT", NULL, "Capture Sense" }, + + { "AIFRX", NULL, "Clock" }, + { "DAC", NULL, "PowerUp" }, + { "DAC", NULL, "ALC gain selection mode" }, + { "DAC", NULL, "AIFRX" }, + { "Speaker", NULL, "DAC" }, +}; + +static int nau8310_clock_apply(struct nau8310 *nau8310, + const struct nau8310_srate_attr *srate_table, + int n1_sel, int mclk_mult_sel, int n2_sel, int dsp_mult_sel) +{ + struct regmap *regmap = nau8310->regmap; + int mult_sel; + unsigned int ctrl_val = 0; + + static const unsigned int mclkx_val[] = { + /* multiplier 4x, i.e. 2^2 */ + [2] = NAU8310_MCLK4XEN, + /* multiplier 8x, i.e. 2^3 */ + [3] = NAU8310_MCLK8XEN | NAU8310_MCLK4XEN, + /* multiplier 16x, i.e. 2^4 */ + [4] = NAU8310_MCLK16XEN | NAU8310_MCLK8XEN | NAU8310_MCLK4XEN, + }; + + if (dsp_mult_sel < 0 || dsp_mult_sel >= ARRAY_SIZE(dsp_src_mult) || + n2_sel < 0 || n2_sel >= ARRAY_SIZE(mclk_n2_div) || + n1_sel < 0 || n1_sel >= ARRAY_SIZE(mclk_n1_div)) { + dev_err(nau8310->dev, "The fs %d isn't support in DSP.", srate_table->fs); + return -EINVAL; + } + + if (mclk_mult_sel != CLK_PROC_BYPASS) { + ctrl_val |= mclk_src_mult[mclk_mult_sel].val << NAU8310_MCLK_SEL_SFT; + mult_sel = (mclk_mult_sel > dsp_mult_sel ? mclk_mult_sel : dsp_mult_sel); + } else + mult_sel = dsp_mult_sel; + + if (mult_sel < 2 || mult_sel > 4) + return -EINVAL; + + if (srate_table->adc_div >= 0) { + regmap_update_bits(regmap, NAU8310_R03_CLK_CTRL, + NAU8310_CLK_ADC_DIV2 | NAU8310_CLK_ADC_DIV4, + srate_table->adc_div << NAU8310_CLK_ADC_DIV4_SFT); + } + + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_SRATE_MASK | NAU8310_DIV_MAX | NAU8310_ALT_SRATE_EN, + (srate_table->range << NAU8310_SRATE_SFT) | + (srate_table->max ? NAU8310_DIV_MAX : 0) | + (srate_table->fs == 44100 ? NAU8310_ALT_SRATE_EN : 0)); + + regmap_update_bits(regmap, NAU8310_R03_CLK_CTRL, + NAU8310_MCLK_SRC_MASK, mclk_n2_div[n2_sel].val); + + ctrl_val |= (dsp_src_mult[dsp_mult_sel].val << NAU8310_CLK_DSP_SRC_SFT) | + (mclk_n1_div[n1_sel].val << NAU8310_CLK_MUL_SRC_SFT); + regmap_update_bits(regmap, NAU8310_R04_ENA_CTRL, + NAU8310_CLK_DSP_SRC_MASK | NAU8310_CLK_MUL_SRC_MASK | + NAU8310_MCLK_SEL_MASK, ctrl_val); + + regmap_update_bits(regmap, NAU8310_R68_ANALOG_CONTROL_7, + NAU8310_MCLKX_MASK, mclkx_val[mult_sel]); + + return 0; +} + +static int nau8310_calc_dsp_clk(int mclk, int fs, int mult_param, int n1_param) +{ + int dsp_clk = (mclk << mult_param) / n1_param; + + if (dsp_clk >= (fs * DSP_CLK_MIN_MULTI_VALUE) && dsp_clk <= DSP_CLK_MAX) + return dsp_clk; + + return 0; +} + +static int nau8310_clkdsp_choose(int fs, int mclk, int *n1_sel, + bool n1_try, int *dsp_n1_sel, int *dsp_mult_sel) +{ + int i, j, dsp_n1, mult_sel, dsp_clk, dsp_clk_max = 0; + + if (n1_sel) { + dsp_n1 = *n1_sel; + for (j = 0; j < ARRAY_SIZE(dsp_src_mult); j++) { + dsp_clk = nau8310_calc_dsp_clk(mclk, fs, dsp_src_mult[j].param, + mclk_n1_div[dsp_n1].param); + if (!dsp_clk) + continue; + if (dsp_clk_max < dsp_clk) { + dsp_clk_max = dsp_clk; + mult_sel = j; + } + } + if (!dsp_clk_max) + goto proc_err; + if (!n1_try) { + *dsp_n1_sel = dsp_n1; + *dsp_mult_sel = mult_sel; + } + } else { + dsp_n1 = -1; + if (mclk >= DSP_MCLK_HI_SPEED) { + /* get max N1 when MCLK over 12.288MHz */ + for (i = 0; i < ARRAY_SIZE(mclk_n1_div); i++) + for (j = 0; j < ARRAY_SIZE(dsp_src_mult); j++) { + dsp_clk = nau8310_calc_dsp_clk(mclk, fs, + dsp_src_mult[j].param, mclk_n1_div[i].param); + if (!dsp_clk) + continue; + if ((dsp_clk_max < dsp_clk || i > dsp_n1)) { + dsp_clk_max = dsp_clk; + dsp_n1 = i; + mult_sel = j; + } + } + if (!dsp_clk_max) + goto proc_err; + } else { + for (i = 0; i < ARRAY_SIZE(mclk_n1_div); i++) { + for (j = 0; j < ARRAY_SIZE(dsp_src_mult); j++) { + dsp_clk = nau8310_calc_dsp_clk(mclk, fs, + dsp_src_mult[j].param, mclk_n1_div[i].param); + if (dsp_clk) { + dsp_n1 = i; + mult_sel = j; + break; + } + } + if (dsp_n1 >= 0) + break; + } + if (dsp_n1 < 0) + goto proc_err; + } + *dsp_n1_sel = dsp_n1; + *dsp_mult_sel = mult_sel; + } + + return 0; + +proc_err: + return -EINVAL; +} + +static inline int get_osrate_val(const struct nau8310_osr_attr *arr, size_t arr_size, int osr) +{ + if (osr >= arr_size) + return -EINVAL; + + return arr[osr].osr; +} + +static int nau8310_clock_check(struct nau8310 *nau8310, int stream, int fs, int osr) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(nau8310->dapm); + int osrate = 0; + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) + osrate = get_osrate_val(osr_dac_sel, ARRAY_SIZE(osr_dac_sel), osr); + else { + if (nau8310_dsp_active(cp)) + osrate = get_osrate_val(osr_adc_dsp_sel, + ARRAY_SIZE(osr_adc_dsp_sel), osr); + else + osrate = get_osrate_val(osr_adc_sel, + ARRAY_SIZE(osr_adc_sel), osr); + } + + if (osrate <= 0) + return -EINVAL; + + if (fs * osrate > CLK_DA_AD_MAX) { + dev_err(nau8310->dev, "exceed the maximum frequency of CLK_ADC or CLK_DAC"); + return -EINVAL; + } + + return 0; +} + +static int nau8310_osr_apply(struct nau8310 *nau8310, int fs) +{ + struct snd_soc_component *cp = snd_soc_dapm_to_component(nau8310->dapm); + struct regmap *regmap = nau8310->regmap; + unsigned int dac_osr, adc_osr; + unsigned int dac_src, adc_src; + + /* + * CLK_DAC or CLK_ADC = OSR * FS + * DAC or ADC clock frequency is defined as Over Sampling Rate (OSR) + * multiplied by the audio sample rate (Fs). Note that the OSR and Fs + * values must be selected such that the maximum frequency is less + * than 6.144 MHz. + */ + regmap_read(regmap, NAU8310_R29_DAC_CTRL1, &dac_osr); + dac_osr &= NAU8310_DAC_OVERSAMPLE_MASK; + if (nau8310_clock_check(nau8310, SNDRV_PCM_STREAM_PLAYBACK, fs, dac_osr)) + return -EINVAL; + + regmap_read(regmap, NAU8310_R28_ADC_RATE, &adc_osr); + adc_osr &= NAU8310_ADC_SYNC_DOWN_MASK; + if (nau8310_clock_check(nau8310, SNDRV_PCM_STREAM_CAPTURE, fs, adc_osr)) + return -EINVAL; + + dac_src = osr_dac_sel[dac_osr].clk_src << NAU8310_CLK_DAC_SRC_SFT; + adc_src = (nau8310_dsp_active(cp)) ? + (osr_adc_dsp_sel[adc_osr].clk_src << NAU8310_CLK_ADC_SRC_SFT) : + (osr_adc_sel[adc_osr].clk_src << NAU8310_CLK_ADC_SRC_SFT); + regmap_update_bits(regmap, NAU8310_R03_CLK_CTRL, + NAU8310_CLK_DAC_SRC_MASK | NAU8310_CLK_ADC_SRC_MASK, dac_src | adc_src); + + return 0; +} + +static int nau8310_match_mclk_ratio(const struct nau8310_srate_attr *srate_table, + int mclk_src) +{ + if (srate_table->mclk_src[NAU8310_MCLK_FS_RATIO_256] == mclk_src) + return NAU8310_MCLK_FS_RATIO_256; + + if (srate_table->mclk_src[NAU8310_MCLK_FS_RATIO_400] == mclk_src) + return NAU8310_MCLK_FS_RATIO_400; + + if (srate_table->mclk_src[NAU8310_MCLK_FS_RATIO_500] == mclk_src) + return NAU8310_MCLK_FS_RATIO_500; + + return NAU8310_MCLK_FS_RATIO_NUM; +} + +static int nau8310_clksrc_n2(const struct nau8310_srate_attr *srate_table, + int mclk, int *n2_sel) +{ + int i, mclk_src, ratio = NAU8310_MCLK_FS_RATIO_NUM; + + for (i = 0; i < ARRAY_SIZE(mclk_n2_div); i++) { + mclk_src = mclk >> mclk_n2_div[i].param; + ratio = nau8310_match_mclk_ratio(srate_table, mclk_src); + if (ratio != NAU8310_MCLK_FS_RATIO_NUM) { + *n2_sel = i; + break; + } + } + + return ratio; +} + +static const struct nau8310_srate_attr *target_srate_attribute(int srate) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(target_srate_table); i++) + if (target_srate_table[i].fs == srate) + break; + + if (i == ARRAY_SIZE(target_srate_table)) + return NULL; + + return &target_srate_table[i]; +} + +static int nau8310_clock_process(struct nau8310 *nau8310, int fs, int mclk) +{ + const struct nau8310_srate_attr *srate_table; + int i, j, calc_mclk, mclk_max, ratio, ratio_sel, n2_max, ret; + int n1_sel = CLK_PROC_BYPASS, mult_sel, n2_sel, dsp_mult_sel; + + /* select sampling rate and MCLK_SRC */ + srate_table = target_srate_attribute(fs); + if (!srate_table) + goto proc_err; + + /* + * First check clock from MCLK directly, decide N2 for MCLK_SRC. + * If not good, consider 1/N1 and Multiplier. + */ + ratio = nau8310_clksrc_n2(srate_table, mclk, &n2_sel); + if (ratio != NAU8310_MCLK_FS_RATIO_NUM) { + n1_sel = CLK_PROC_BYPASS; + mult_sel = CLK_PROC_BYPASS; + ret = nau8310_clkdsp_choose(fs, mclk, NULL, false, + &n1_sel, &dsp_mult_sel); + if (ret) + goto proc_err; + goto proc_done; + } + /* Get MCLK_SRC through 1/N, Multiplier, and then 1/N2. */ + mclk_max = 0; + for (i = 0; i < ARRAY_SIZE(mclk_n1_div); i++) { + for (j = 0; j < ARRAY_SIZE(mclk_src_mult); j++) { + calc_mclk = mclk << mclk_src_mult[j].param; + calc_mclk = calc_mclk / mclk_n1_div[i].param; + ratio = nau8310_clksrc_n2(srate_table, calc_mclk, &n2_sel); + if (ratio != NAU8310_MCLK_FS_RATIO_NUM && + (mclk_max < calc_mclk || i > n1_sel)) { + ret = nau8310_clkdsp_choose(fs, mclk, &i, true, + &n1_sel, &dsp_mult_sel); + if (ret) + break; + mclk_max = calc_mclk; + n2_max = n2_sel; + n1_sel = i; + mult_sel = j; + ratio_sel = ratio; + } + } + } + if (mclk_max) { + n2_sel = n2_max; + ratio = ratio_sel; + nau8310_clkdsp_choose(fs, mclk, &n1_sel, false, &n1_sel, &dsp_mult_sel); + goto proc_done; + } + +proc_err: + dev_err(nau8310->dev, "The MCLK %d is invalid. It can't get MCLK_SRC of 256/400/500 FS (%d).", + mclk, fs); + return -EINVAL; +proc_done: + dev_dbg(nau8310->dev, "FS %dHz, DSP_CLK %uHz, range 0x%x, %s, (n1,mu,n2,dmu):(%d,%d,%d,%d), MCLK_SRC %uHz (%d)", + fs, (mclk << dsp_src_mult[dsp_mult_sel].param) / mclk_n1_div[n1_sel].param, + srate_table->range, + srate_table->max ? "MAX" : "MIN", + n1_sel == CLK_PROC_BYPASS ? CLK_PROC_BYPASS : mclk_n1_div[n1_sel].param, + mult_sel == CLK_PROC_BYPASS ? + CLK_PROC_BYPASS : 1 << mclk_src_mult[mult_sel].param, + 1 << mclk_n2_div[n2_sel].param, + 1 << dsp_src_mult[dsp_mult_sel].param, + srate_table->mclk_src[ratio], + srate_table->mclk_src[ratio] / fs); + + return nau8310_clock_apply(nau8310, srate_table, n1_sel, mult_sel, + n2_sel, dsp_mult_sel); +} + +static int nau8310_clock_config(struct nau8310 *nau8310, int fs, int mclk) +{ + int ret; + + if (!fs || !mclk) + return -EINVAL; + + ret = nau8310_clock_process(nau8310, fs, mclk); + if (ret) + return ret; + + ret = nau8310_osr_apply(nau8310, fs); + if (ret) + return ret; + + return 0; +} + +static int nau8310_switch_internal_osc(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + int ret; + + /* For internal Ring OSC, the default fs apply to 48kHz */ + ret = nau8310_clock_config(nau8310, NAU8310_DEFAULT_FS, + NAU8310_DEFAULT_FS * NAU8310_SCLK_MULT); + if (ret) + return ret; + + /* Switch clock source to OSC before MCLK off if DSP is enabled. */ + regmap_update_bits(nau8310->regmap, NAU8310_R04_ENA_CTRL, + NAU8310_DSP_OSC_EN | NAU8310_DSP_SEL_OSC, + NAU8310_DSP_OSC_EN | NAU8310_DSP_SEL_OSC); + + return 0; +} + +static int nau8310_set_sysclk(struct snd_soc_component *cp, + int clk_id, int source, unsigned int freq, int dir) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + int ret; + + switch (clk_id) { + case NAU8310_CLK_ID_MCLK: + if (freq < MASTER_CLK_MIN || freq > MASTER_CLK_MAX) { + dev_err(nau8310->dev, + "Exceed the range of input clocks, MCLK %dHz", freq); + return -EINVAL; + } + nau8310->mclk = freq; + break; + + case NAU8310_CLK_ID_INT: + ret = nau8310_switch_internal_osc(cp); + if (ret) + return ret; + break; + } + + dev_dbg(nau8310->dev, "%s, MCLK %dHz", __func__, nau8310->mclk); + + return 0; +} + +static int nau8310_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) +{ + struct snd_soc_component *cp = dai->component; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + unsigned int val_len = 0; + int fs, ret; + + fs = params_rate(params); + if (nau8310_dsp_active(cp) && fs != NAU8310_DEFAULT_FS) { + dev_err(nau8310->dev, + "For ROM Code revision 00, DSP only run at 48kHz."); + return -EINVAL; + } + ret = nau8310_clock_config(nau8310, fs, nau8310->mclk); + if (ret) + return -EINVAL; + + switch (params_width(params)) { + case 16: + val_len |= NAU8310_I2S_DL_16; + break; + case 20: + val_len |= NAU8310_I2S_DL_20; + break; + case 24: + val_len |= NAU8310_I2S_DL_24; + break; + case 32: + val_len |= NAU8310_I2S_DL_32; + break; + default: + return -EINVAL; + } + + regmap_update_bits(nau8310->regmap, NAU8310_R0D_I2S_PCM_CTRL1, + NAU8310_I2S_DL_MASK, val_len); + + return 0; +} + +static int nau8310_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) +{ + struct snd_soc_component *cp = dai->component; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + unsigned int ctrl1_val = 0, ctrl2_val = 0; + + switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { + case SND_SOC_DAIFMT_CBP_CFP: + ctrl2_val |= NAU8310_I2S_MS_MASTER; + break; + case SND_SOC_DAIFMT_CBC_CFC: + break; + default: + return -EINVAL; + } + + switch (fmt & SND_SOC_DAIFMT_INV_MASK) { + case SND_SOC_DAIFMT_NB_NF: + break; + case SND_SOC_DAIFMT_IB_NF: + ctrl1_val |= NAU8310_I2S_BP_INV; + break; + default: + return -EINVAL; + } + + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + ctrl1_val |= NAU8310_I2S_DF_I2S; + break; + case SND_SOC_DAIFMT_LEFT_J: + ctrl1_val |= NAU8310_I2S_DF_LEFT; + break; + case SND_SOC_DAIFMT_RIGHT_J: + ctrl1_val |= NAU8310_I2S_DF_RIGHT; + break; + case SND_SOC_DAIFMT_DSP_A: + ctrl1_val |= NAU8310_I2S_DF_PCM_AB; + break; + case SND_SOC_DAIFMT_DSP_B: + ctrl1_val |= NAU8310_I2S_DF_PCM_AB; + ctrl1_val |= NAU8310_I2S_PCMB_EN; + break; + default: + return -EINVAL; + } + + regmap_update_bits(regmap, NAU8310_R0D_I2S_PCM_CTRL1, + NAU8310_I2S_DF_MASK | NAU8310_I2S_BP_MASK | + NAU8310_I2S_PCMB_EN, ctrl1_val); + regmap_update_bits(regmap, NAU8310_R0E_I2S_PCM_CTRL2, + NAU8310_I2S_MS_MASK, ctrl2_val); + return 0; +} + +/* TDM slot masks for Voltage (even slots) and Current (odd slots) */ +#define ADC_V_SEL_MASK 0x55 +#define ADC_I_SEL_MASK 0xAA + +static int nau8310_validate_tx_slots(struct device *dev, unsigned int tx_mask, + unsigned int *ctrl_val) +{ + int v_slot = -1, i_slot = -1; + int i; + + if (!tx_mask) + return 0; + + if (hweight32(tx_mask & ADC_V_SEL_MASK) > 1 || + hweight32(tx_mask & ADC_I_SEL_MASK) > 1) { + dev_err(dev, "Only 1 ADC Current and 1 ADC Voltage slot supported (0x%x).\n", + tx_mask); + return -EINVAL; + } + + for (i = 0; i < NAU8310_TDM_MAX_SLOTS; i++) { + if (v_slot >= 0 && i_slot >= 0) + break; + + if (!(tx_mask & BIT(i))) + continue; + + if (i % 2) { + if (i_slot < 0) { + *ctrl_val |= nau8310_tx_slot_map[i]; + i_slot = i; + dev_dbg(dev, "NAU8310_ADC_I_SEL_SLOT%d\n", i); + } + } else { + if (v_slot < 0) { + *ctrl_val |= nau8310_tx_slot_map[i]; + v_slot = i; + dev_dbg(dev, "NAU8310_ADC_V_SEL_SLOT%d\n", i); + } + } + } + + return 0; +} + +static int nau8310_validate_rx_slots(struct device *dev, unsigned int rx_mask, + unsigned int *ctrl0_val) +{ + int dac_slot = -1; + int i; + + if (!rx_mask) + return 0; + + if (hweight32(rx_mask) > 1) { + dev_err(dev, "Only 1 DAC Channel slot supported (0x%x).\n", rx_mask); + return -EINVAL; + } + + for (i = 0; i < NAU8310_TDM_MAX_SLOTS; i++) { + if (!(rx_mask & BIT(i))) + continue; + + *ctrl0_val |= nau8310_rx_slot_map[i]; + dac_slot = i; + dev_dbg(dev, "NAU8310_DAC_SEL_SLOT%d\n", i); + break; + } + + if (dac_slot < 0) { + dev_err(dev, "Failed to assign any DAC Channel Source from mask 0x%x\n", rx_mask); + return -EINVAL; + } + + return 0; +} + +static int nau8310_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, + unsigned int rx_mask, int slots, int slot_width) +{ + struct snd_soc_component *cp = dai->component; + struct device *dev = cp->dev; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + unsigned int ctrl0_val = 0, ctrl_val = 0; + int ret = 0; + + if (!slots || !slot_width || (!tx_mask && !rx_mask)) { + regmap_update_bits(regmap, NAU8310_R0C_TDM_CTRL, NAU8310_TDM_EN, 0); + return ret; + } + + if (slots > NAU8310_TDM_MAX_SLOTS) + return -EINVAL; + + if (slot_width != 16 && slot_width != 24 && slot_width != 32) { + dev_err(dev, "Invalid TDM channel length: %d", slot_width); + return -EINVAL; + } + + ret = nau8310_validate_tx_slots(dev, tx_mask, &ctrl_val); + if (ret < 0) + return ret; + + ret = nau8310_validate_rx_slots(dev, rx_mask, &ctrl0_val); + if (ret < 0) + return ret; + + ctrl_val |= NAU8310_TDM_EN; + + dev_dbg(dev, "%s: tx_mask: 0x%08X, rx_mask: 0x%08X, ADC slots: 0x%08X, DAC slots: 0x%08X", + __func__, tx_mask, rx_mask, ctrl_val, ctrl0_val); + + regmap_update_bits(regmap, NAU8310_R0C_TDM_CTRL, + NAU8310_TDM_EN | NAU8310_TDM_OFFSET_EN | + NAU8310_ADC_I_SEL_MASK | NAU8310_ADC_V_SEL_MASK, ctrl_val); + regmap_update_bits(regmap, NAU8310_R0B_I2S_PCM_CTRL0, + NAU8310_DAC_SEL_MASK, ctrl0_val); + + return ret; +} + +static int nau8310_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_component *cp = dai->component; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + + flush_work(&nau8310->load_fw_work); + + if (nau8310_dsp_active(cp) && !nau8310->load_fw_done) { + dev_warn(nau8310->dev, "DSP firmware is not ready yet!"); + return -EBUSY; + } + + if (nau8310_dsp_active(cp) && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + snd_soc_dapm_enable_pin(nau8310->dapm, "Sense"); + + return 0; +} + +static void nau8310_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_component *cp = dai->component; + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + + if (nau8310_dsp_active(cp) && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + snd_soc_dapm_disable_pin(nau8310->dapm, "Sense"); + snd_soc_dapm_sync(nau8310->dapm); + } +} + +static void nau8310_reset_chip(struct regmap *regmap) +{ + regmap_write(regmap, NAU8310_R00_HARDWARE_RST, 0x0001); + regmap_write(regmap, NAU8310_R00_HARDWARE_RST, 0x0000); +} + +void nau8310_software_reset(struct regmap *regmap) +{ + regmap_write(regmap, NAU8310_R01_SOFTWARE_RST, 0x0000); + regmap_write(regmap, NAU8310_R01_SOFTWARE_RST, 0x0000); +} + +static int nau8310_dsp_fw_load(struct nau8310 *nau8310) +{ + int ret = 0; + struct snd_soc_component *cp = snd_soc_dapm_to_component(nau8310->dapm); + + snd_soc_component_set_sysclk(cp, NAU8310_CLK_ID_INT, 0, 0, + SND_SOC_CLOCK_IN); + + regmap_update_bits(nau8310->regmap, NAU8310_R68_ANALOG_CONTROL_7, + NAU8310_MU_HALF_RANGE_EN, NAU8310_MU_HALF_RANGE_EN); + + nau8310->load_fw_done = false; + schedule_work(&nau8310->load_fw_work); + + return ret; +} + +static void nau8310_load_fw_work(struct work_struct *work) +{ + struct nau8310 *nau8310 = container_of(work, struct nau8310, load_fw_work); + struct regmap *regmap = nau8310->regmap; + struct snd_soc_component *cp = snd_soc_dapm_to_component(nau8310->dapm); + int ret; + + mutex_lock(&nau8310->lock); + ret = nau8310_dsp_init(cp); + mutex_unlock(&nau8310->lock); + if (ret) { + dev_err(nau8310->dev, "Failed to initialize DSP: %d", ret); + goto err; + } + + return; + +err: + + regmap_update_bits(regmap, + NAU8310_R1A_DSP_CORE_CTRL2, NAU8310_DSP_RUNSTALL, NAU8310_DSP_RUNSTALL); + + /* Switch the clock source of DSP to MCLK. */ + regmap_update_bits(regmap, NAU8310_R04_ENA_CTRL, NAU8310_DSP_SEL_OSC, 0); +} + +static int nau8310_codec_probe(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(cp); + int ret = 0; + + nau8310->dapm = dapm; + /* default disable Sense signal after booting */ + snd_soc_dapm_disable_pin(nau8310->dapm, "Sense"); + snd_soc_dapm_sync(nau8310->dapm); + + /* Loading DSP firmware */ + ret = nau8310_dsp_fw_load(nau8310); + if (ret) { + dev_err(nau8310->dev, "Loading DSP firmware failed(%d)", ret); + goto err; + } + + ret = nau8310_dsp_setup_controls(cp); + if (ret) { + dev_err(nau8310->dev, "DSP setup controls failed(%d)", ret); + goto err; + } + +err: + return ret; +} + +static int __maybe_unused nau8310_suspend(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + + cancel_work_sync(&nau8310->load_fw_work); + + if (nau8310_dsp_active(cp)) + regmap_update_bits(regmap, NAU8310_R04_ENA_CTRL, + NAU8310_DSP_SEL_OSC, NAU8310_DSP_SEL_OSC); + + regcache_cache_only(regmap, true); + regcache_mark_dirty(regmap); + + return 0; +} + +static int __maybe_unused nau8310_resume(struct snd_soc_component *cp) +{ + struct nau8310 *nau8310 = snd_soc_component_get_drvdata(cp); + struct regmap *regmap = nau8310->regmap; + int ret = 0; + + regcache_cache_only(regmap, false); + ret = regcache_sync(regmap); + if (ret) + return ret; + + ret = nau8310_dsp_fw_load(nau8310); + if (ret) + dev_err(nau8310->dev, "Loading DSP firmware failed(%d)", ret); + + return ret; +} + +static const struct snd_soc_component_driver soc_comp_dev_nau8310 = { + .probe = nau8310_codec_probe, + .set_sysclk = nau8310_set_sysclk, + .suspend = nau8310_suspend, + .resume = nau8310_resume, + .controls = nau8310_snd_controls, + .num_controls = ARRAY_SIZE(nau8310_snd_controls), + .dapm_widgets = nau8310_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(nau8310_dapm_widgets), + .dapm_routes = nau8310_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(nau8310_dapm_routes), + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, +}; + +static const struct snd_soc_dai_ops nau8310_dai_ops = { + .startup = nau8310_startup, + .hw_params = nau8310_hw_params, + .shutdown = nau8310_shutdown, + .set_fmt = nau8310_set_fmt, + .set_tdm_slot = nau8310_set_tdm_slot, +}; + +#define NAU8310_RATES SNDRV_PCM_RATE_8000_96000 +#define NAU8310_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE \ + | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) + +static struct snd_soc_dai_driver nau8310_dai = { + .name = NAU8310_CODEC_DAI, + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = 8, + .rates = NAU8310_RATES, + .formats = NAU8310_FORMATS, + }, + .capture = { + .stream_name = "Capture", + .channels_min = 1, + .channels_max = 8, + .rates = NAU8310_RATES, + .formats = NAU8310_FORMATS, + }, + .ops = &nau8310_dai_ops, + .symmetric_rate = 1, +}; + +static int nau8310_reg_write(void *context, unsigned int reg, unsigned int value) +{ + struct i2c_client *client = context; + struct nau8310 *nau8310 = i2c_get_clientdata(client); + int ret, count = 0; + + put_unaligned_be16(reg, &nau8310->i2c_write_buf[count]); + count += 2; + if (reg == NAU8310_RF000_DSP_COMM) { + /* format for DSP, 4 bytes value and native */ + put_unaligned_le32(value, &nau8310->i2c_write_buf[count]); + count += 4; + } else { + /* format for Codec, 2 bytes value and endian big */ + put_unaligned_be16(value, &nau8310->i2c_write_buf[count]); + count += 2; + } + + ret = i2c_master_send(client, nau8310->i2c_write_buf, count); + + if (ret == count) + return 0; + if (ret < 0) + return ret; + + return -EIO; +} + +static int nau8310_reg_read(void *context, unsigned int reg, unsigned int *value) +{ + struct i2c_client *client = context; + struct nau8310 *nau8310 = i2c_get_clientdata(client); + struct i2c_msg xfer[2]; + int ret; + + put_unaligned_be16(reg, &nau8310->i2c_read_reg); + xfer[0].addr = client->addr; + xfer[0].len = 2; + xfer[0].buf = nau8310->i2c_read_reg; + xfer[0].flags = 0; + + xfer[1].addr = client->addr; + xfer[1].len = (reg == NAU8310_RF000_DSP_COMM ? 4 : 2); + xfer[1].buf = nau8310->i2c_read_buf; + xfer[1].flags = I2C_M_RD; + + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); + if (ret < 0) + return ret; + if (ret != ARRAY_SIZE(xfer)) + return -EIO; + + if (reg == NAU8310_RF000_DSP_COMM) + *value = get_unaligned_le32(nau8310->i2c_read_buf); + else + *value = get_unaligned_be16(nau8310->i2c_read_buf); + + return 0; +} + +static const struct regmap_config nau8310_regmap_config = { + .reg_bits = NAU8310_REG_ADDR_LEN, + .val_bits = NAU8310_REG_DATA_LEN, + + .max_register = NAU8310_REG_MAX, + .readable_reg = nau8310_readable_reg, + .writeable_reg = nau8310_writeable_reg, + .volatile_reg = nau8310_volatile_reg, + .reg_read = nau8310_reg_read, + .reg_write = nau8310_reg_write, + + .cache_type = REGCACHE_MAPLE, + .reg_defaults = nau8310_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(nau8310_reg_defaults), +}; + +static void nau8310_set_vref_impedance(struct nau8310 *nau8310) +{ + struct regmap *regmap = nau8310->regmap; + struct device *dev = nau8310->dev; + unsigned int vid_sel = 2; + + switch (nau8310->vref_impedance_ohms) { + case 0: + vid_sel = 0; + break; + case 25000: + vid_sel = 1; + break; + case 125000: + vid_sel = 2; + break; + case 2500: + vid_sel = 3; + break; + default: + dev_warn(dev, "Invalid vref-impedance-ohms %d\n", + nau8310->vref_impedance_ohms); + } + + regmap_update_bits(regmap, NAU8310_R60_BIAS_ADJ, + NAU8310_BIAS_VMID_SEL_MASK, vid_sel << NAU8310_BIAS_VMID_SEL_SFT); +} + +static void nau8310_set_dac_vref(struct nau8310 *nau8310) +{ + struct regmap *regmap = nau8310->regmap; + struct device *dev = nau8310->dev; + unsigned int vref_sel = 1; + + switch (nau8310->dac_vref_microvolt) { + case 1800000: + vref_sel = 0; + break; + case 2700000: + vref_sel = 1; + break; + case 2880000: + vref_sel = 2; + break; + case 3060000: + vref_sel = 3; + break; + default: + dev_warn(dev, "Invalid dac-vref-microvolt: %d\n", + nau8310->dac_vref_microvolt); + } + + regmap_update_bits(regmap, NAU8310_R73_RDAC, + NAU8310_DACVREFSEL_MASK, vref_sel << NAU8310_DACVREFSEL_SFT); +} + +static void nau8310_set_sar_ctrl(struct nau8310 *nau8310) +{ + struct regmap *regmap = nau8310->regmap; + struct device *dev = nau8310->dev; + unsigned int val_voltage = 0, val_compare = 0, val_sampling = 0; + + switch (nau8310->sar_voltage_microvolt) { + case 1800000: + val_voltage = 1; + break; + case 1980000: + val_voltage = 2; + break; + case 2160000: + val_voltage = 3; + break; + case 2340000: + val_voltage = 4; + break; + case 2520000: + val_voltage = 5; + break; + case 2772000: + val_voltage = 6; + break; + case 5616000: + val_voltage = 7; + break; + default: + dev_err(dev, "Invalid sar-voltage-microvolt: %d\n", + nau8310->sar_voltage_microvolt); + } + + switch (nau8310->sar_compare_time_ns) { + case 500: + val_compare = 0; + break; + case 1000: + val_compare = 1; + break; + case 2000: + val_compare = 2; + break; + case 4000: + val_compare = 3; + break; + default: + dev_err(dev, "Invalid sar-compare-time-ns: %d\n", + nau8310->sar_compare_time_ns); + } + + switch (nau8310->sar_sampling_time_us) { + case 2: + val_sampling = 0; + break; + case 4: + val_sampling = 1; + break; + case 8: + val_sampling = 2; + break; + case 16: + val_sampling = 3; + break; + default: + dev_err(dev, "Invalid sar-sampling-time-us: %d\n", + nau8310->sar_sampling_time_us); + } + + regmap_update_bits(regmap, NAU8310_R07_SAR_CTRL1, + NAU8310_SAR_TRACKING_GAIN_MASK | + NAU8310_SAR_COMPARE_TIME_MASK | + NAU8310_SAR_SAMPLING_TIME_MASK, + (val_voltage << NAU8310_SAR_TRACKING_GAIN_SFT) | + (val_compare << NAU8310_SAR_COMPARE_TIME_SFT) | + (val_sampling << NAU8310_SAR_SAMPLING_TIME_SFT)); +} + +static void nau8310_set_boost_ctrl(struct nau8310 *nau8310) +{ + struct regmap *regmap = nau8310->regmap; + struct device *dev = nau8310->dev; + unsigned int val_delay = 0; + + switch (nau8310->boost_delay_ms) { + case 0: + val_delay = 0; + break; + case 1: + val_delay = 1; + break; + case 2: + val_delay = 2; + break; + case 4: + val_delay = 3; + break; + case 8: + val_delay = 4; + break; + case 16: + val_delay = 5; + break; + case 32: + val_delay = 6; + break; + case 64: + val_delay = 7; + break; + case 128: + val_delay = 8; + break; + default: + dev_err(dev, "Invalid boost-delay-ms: %d\n", + nau8310->boost_delay_ms); + } + + regmap_update_bits(regmap, NAU8310_R18_BOOST_CTRL2, NAU8310_TC_EN | + NAU8310_BSTHOLD_MASK | NAU8310_BSTSTEPTIME_MASK | + NAU8310_BSTDELAY_MASK, (nau8310->temp_compensation << NAU8310_TC_SFT) | + (0xf << NAU8310_BSTHOLD_SFT) | + (0x7 << NAU8310_BSTSTEPTIME_SFT) | val_delay); +} + +static void nau8310_init_regs(struct nau8310 *nau8310) +{ + struct regmap *regmap = nau8310->regmap; + unsigned int clk_det = 0, ana_ctrl = 0; + + /* Latch IIC LSB value */ + regmap_write(regmap, NAU8310_R02_I2C_ADDR, 0x0001); + /* Block MCLK */ + regmap_update_bits(regmap, NAU8310_R04_ENA_CTRL, + NAU8310_MCLK_SEL_MASK, 0x7 << NAU8310_MCLK_SEL_SFT); + /* stall DSP */ + regmap_update_bits(regmap, NAU8310_R1A_DSP_CORE_CTRL2, + NAU8310_DSP_RUNSTALL, NAU8310_DSP_RUNSTALL); + /* Default ADCI from slot1, ADCV from slot 0. */ + regmap_update_bits(regmap, NAU8310_R0C_TDM_CTRL, + NAU8310_ADC_I_SEL_MASK | NAU8310_ADC_V_SEL_MASK, + (0x4 << NAU8310_ADC_I_SEL_SFT) | 0x4); + /* Set I-sense digital gain to +10.25dB */ + regmap_update_bits(regmap, NAU8310_R14_ADC_VOL_CTRL, + NAU8310_ADC_GAIN_L_MASK | NAU8310_ADC_GAIN_R_MASK, + (0x1 << NAU8310_ADC_GAIN_L_SFT) | 0x62); + /* PGA in Class A Mode */ + regmap_update_bits(regmap, NAU8310_R76_BOOST, + NAU8310_STG2_SEL_CLASSA, NAU8310_STG2_SEL_CLASSA); + /* + * Set I-sense PGA Bias Current to minimum, + * Disable PGA Common Mode Lock. + */ + regmap_update_bits(regmap, NAU8310_R77_FEPGA, + NAU8310_CURR_TRIM_MASK | NAU8310_CMLCK_ENB, + (0x7 << NAU8310_CURR_TRIM_SFT) | NAU8310_CMLCK_ENB); + /* Set I-sense PGA to +12dB gain */ + regmap_update_bits(regmap, NAU8310_R7F_POWER_UP_CONTROL, + NAU8310_PGA_GAIN_MASK, 0x3 << NAU8310_PGA_GAIN_SFT); + /* + * Normal I2S Audio data w/o SAR ADC data. + * Default oversampling/decimations settings are unusable + * (audible hiss). Set it to something better. + */ + regmap_update_bits(regmap, NAU8310_R28_ADC_RATE, + NAU8310_I2S_MODE | NAU8310_ADC_SYNC_DOWN_MASK, + (nau8310->normal_iis_data << NAU8310_I2S_MODE_SFT) | + NAU8310_ADC_SYNC_DOWN_64); + regmap_update_bits(regmap, NAU8310_R29_DAC_CTRL1, + NAU8310_DAC_OVERSAMPLE_MASK, NAU8310_DAC_OVERSAMPLE_64); + /* Enable auto attenuation for better output signal */ + regmap_update_bits(regmap, NAU8310_R2E_ALC_CTRL3, + NAU8310_AUTOATT_EN, NAU8310_AUTOATT_EN); + /* Set ALC parameters */ + regmap_update_bits(regmap, NAU8310_R2C_ALC_CTRL1, + NAU8310_ALC_MAXGAIN_MASK, 0x7 << NAU8310_ALC_MAXGAIN_SFT); + regmap_update_bits(regmap, NAU8310_R2D_ALC_CTRL2, + NAU8310_ALC_DCY_MASK | NAU8310_ALC_ATK_MASK | + NAU8310_ALC_HLD_MASK, (0x5 << NAU8310_ALC_DCY_SFT) | + (0x3 << NAU8310_ALC_ATK_SFT) | (0x5 << NAU8310_ALC_HLD_SFT)); + regmap_update_bits(regmap, NAU8310_R2E_ALC_CTRL3, + NAU8310_LIM_MDE_MASK | NAU8310_VBAT_THLD_MASK, + (0x3 << NAU8310_LIM_MDE_SFT) | (0x18 << NAU8310_VBAT_THLD_SFT)); + + if (!nau8310->clock_detection) + clk_det |= NAU8310_CLKPWRUP_DIS; + if (nau8310->clock_det_data) + clk_det |= NAU8310_APWRUP_EN; + regmap_update_bits(regmap, NAU8310_R40_CLK_DET_CTRL, + NAU8310_CLKPWRUP_DIS | NAU8310_PWRUP_DFT | NAU8310_APWRUP_EN, clk_det); + + /* Boost Target Limit and Margin */ + regmap_update_bits(regmap, NAU8310_R17_BOOST_CTRL1, + NAU8310_BSTLIMIT_MASK | NAU8310_BSTMARGIN_MASK, + (nau8310->boost_target_limit << NAU8310_BSTLIMIT_SFT) | + nau8310->boost_target_margin); + /* Temperature compensation */ + regmap_update_bits(regmap, NAU8310_R30_TEMP_COMP_CTRL, + NAU8310_TEMP_COMP_ACT2_MASK, 0); + /* Low pass filter control */ + regmap_update_bits(regmap, NAU8310_R33_LPF_CTRL, + NAU8310_LPF_IN1_EN | NAU8310_LPF_IN1_TC_MASK | + NAU8310_LPF_IN2_EN | NAU8310_LPF_IN2_TC_MASK, + NAU8310_LPF_IN1_EN | (0x7 << NAU8310_LPF_IN1_TC_SFT) | + NAU8310_LPF_IN2_EN | (0x7 << NAU8310_LPF_IN2_TC_SFT)); + /* Set Boost Attack/Decay, Hold Time and TC EN */ + nau8310_set_boost_ctrl(nau8310); + /* DAC Reference Voltage Setting */ + nau8310_set_dac_vref(nau8310); + /* DAC Reference Voltage Decoupling Capacitors. */ + regmap_update_bits(regmap, NAU8310_R63_ANALOG_CONTROL_3, + NAU8310_DACREFCAP_MASK, 0x3 << NAU8310_DACREFCAP_SFT); + /* Auto-Att Min Gain 12dB, Class-D P&N Driver Slew Rate +75%. */ + regmap_update_bits(regmap, NAU8310_R64_ANALOG_CONTROL_4, + NAU8310_AUTOATTMIN_MASK | NAU8310_CLASSD_SLEWN_MASK | + NAU8310_CLASSD_SLEWP_MASK | NAU8310_CLASSD_SHORTP_MASK | + NAU8310_CLASSD_SHORTN_MASK, + NAU8310_CLASSD_SHORTP_100UP | NAU8310_AUTOATTMIN_12DB | + NAU8310_CLASSD_SLEWP_75UP | NAU8310_CLASSD_SLEWN_75UP); + /* + * Bias Current, Monitor Vboost drops below VBAT, + * Non-Overlapping-Time Control. + */ + regmap_update_bits(regmap, NAU8310_R65_ANALOG_CONTROL_5, + NAU8310_BSTINDR_MASK | NAU8310_BSTCURGEN_MASK | + NAU8310_BSTMONEN | NAU8310_BSTCLKPULSE_MASK, + (0x4 << NAU8310_BSTINDR_SFT) | NAU8310_BSTMONEN | + (0xd << NAU8310_BSTCURGEN_SFT) | 0x2); + /* Slew Rate Adjust, Bias Current. */ + regmap_update_bits(regmap, NAU8310_R66_ANALOG_CONTROL_6, + NAU8310_BSTSLEWPOFF_MASK | NAU8310_BSTSLEWPON_MASK | + NAU8310_BSTSLEWNON_MASK | NAU8310_BSTSLEWNOFF_MASK | + NAU8310_BSTIPDR_MASK, (0x3 << NAU8310_BSTSLEWPOFF_SFT) | + (0x2 << NAU8310_BSTSLEWPON_SFT) | (0x2 << NAU8310_BSTSLEWNON_SFT) | + (0x1 << NAU8310_BSTSLEWNOFF_SFT) | 0x4); + + if (nau8310->silicon_id == NAU8310_REG_SI_REV_G10) + /* Peak Current 4A, Low Voltage 2.8V */ + ana_ctrl = (0x11 << NAU8310_VBAT_PCL_SFT) | (0xf << NAU8310_VBAT_THD_SFT); + else if (nau8310->silicon_id == NAU8310_REG_SI_REV_G20) + /* Peak Current 1A, Low Voltage 3.6V */ + ana_ctrl = (0x7 << NAU8310_VBAT_THD_SFT); + + regmap_update_bits(regmap, NAU8310_R6B_ANALOG_CONTROL_8, + NAU8310_VBAT_PCL_MASK | NAU8310_VBAT_THD_MASK, ana_ctrl); + + /* current limiting for low VBAT level */ + regmap_update_bits(regmap, NAU8310_R6C_ANALOG_CONTROL_9, + NAU8310_VBAT_CURLMT_MASK, 0xf); + /* VMID Tieoff (VMID Resistor Selection) */ + nau8310_set_vref_impedance(nau8310); + /* VREF Bandgap buffer ON, I/V Sense Ref Buffer Setting -1.5dB. */ + regmap_update_bits(regmap, NAU8310_R68_ANALOG_CONTROL_7, + NAU8310_ADCGAIN_MASK | NAU8310_VREFBG_EN, + (0x3 << NAU8310_ADCGAIN_SFT) | NAU8310_VREFBG_EN); + nau8310_software_reset(regmap); + /* + * Enable VMID, BIAS, DAC, DCA CLOCK, ADC, Voltage/Current Amps, + * ADC Resetb gated by 'PowerUp' Signal. + */ + regmap_update_bits(regmap, NAU8310_R61_ANALOG_CONTROL_1, + NAU8310_ISEN_MASK | NAU8310_ADCRSTEN_MASK | + NAU8310_VSEN_MASK | NAU8310_ADCEN_MASK | + NAU8310_DACCLKEN_MASK | NAU8310_DACEN_MASK | + NAU8310_BIASEN_MASK | NAU8310_VMIDEN_MASK, + (0x1 << NAU8310_ISEN_SFT) | (0x1 << NAU8310_ADCRSTEN_SFT) | + (0x1 << NAU8310_VSEN_SFT) | (0x1 << NAU8310_ADCEN_SFT) | + (0x1 << NAU8310_DACCLKEN_SFT) | (0x1 << NAU8310_DACEN_SFT) | + (0x1 << NAU8310_BIASEN_SFT) | 0x1); + /* + * Enable Boost Converter, VMID Fast, Class-D gated by + * 'PowerUp' Signal + */ + regmap_update_bits(regmap, NAU8310_R62_ANALOG_CONTROL_2, + NAU8310_CLASSDEN_MASK | NAU8310_PDVMDFST_MASK | + NAU8310_BSTEN_MASK, (0x1 << NAU8310_CLASSDEN_SFT) | + (0x1 << NAU8310_PDVMDFST_SFT) | nau8310->boost_convert_mode); + nau8310_set_sar_ctrl(nau8310); +} + +static void nau8310_print_device_properties(struct nau8310 *nau8310) +{ + struct device *dev = nau8310->dev; + + dev_dbg(dev, "vref-impedance-ohms: %d", nau8310->vref_impedance_ohms); + dev_dbg(dev, "dac-vref-microvolt: %d", nau8310->dac_vref_microvolt); + dev_dbg(dev, "sar-voltage-microvolt: %d", nau8310->sar_voltage_microvolt); + dev_dbg(dev, "sar-compare-time-ns: %d", nau8310->sar_compare_time_ns); + dev_dbg(dev, "sar-sampling-time-us: %d", nau8310->sar_sampling_time_us); + dev_dbg(dev, "clock-det-disable: %d", nau8310->clock_detection); + dev_dbg(dev, "clock-det-data: %d", nau8310->clock_det_data); + dev_dbg(dev, "temp-compensation: %d", nau8310->temp_compensation); + dev_dbg(dev, "boost-delay-ms: %d", nau8310->boost_delay_ms); + dev_dbg(dev, "boost-convert-mode: %d", nau8310->boost_convert_mode); + dev_dbg(dev, "boost-target-limit: %x", nau8310->boost_target_limit); + dev_dbg(dev, "boost-target-margin: %x", nau8310->boost_target_margin); + dev_dbg(dev, "normal-iis-data: %d", nau8310->normal_iis_data); + dev_dbg(dev, "dsp-firmware: %s", nau8310->dsp_firmware); +} + +static int nau8310_read_device_properties(struct nau8310 *nau8310) +{ + const char *def_fws = NAU8310_DSP_FIRMWARE; + struct device *dev = nau8310->dev; + const char *firmware_names = NULL; + int ret; + u32 val; + + ret = device_property_read_u32(dev, "nuvoton,vref-impedance-ohms", + &nau8310->vref_impedance_ohms); + if (ret) + nau8310->vref_impedance_ohms = 125000; + + ret = device_property_read_u32(dev, "nuvoton,dac_vref_microvolt", + &nau8310->dac_vref_microvolt); + if (ret) + nau8310->dac_vref_microvolt = 2700000; + + ret = device_property_read_u32(dev, "nuvoton,sar-voltage-microvolt", + &nau8310->sar_voltage_microvolt); + if (ret) + nau8310->sar_voltage_microvolt = 1800000; + + ret = device_property_read_u32(dev, "nuvoton,sar-compare-time-ns", + &nau8310->sar_compare_time_ns); + if (ret) + nau8310->sar_compare_time_ns = 1000; + + ret = device_property_read_u32(dev, "nuvoton,sar-sampling-time-us", + &nau8310->sar_sampling_time_us); + if (ret) + nau8310->sar_sampling_time_us = 4; + + nau8310->clock_detection = + !device_property_read_bool(dev, "nuvoton,clock-detection-disable"); + nau8310->clock_det_data = + device_property_read_bool(dev, "nuvoton,clock-det-data"); + nau8310->temp_compensation = + device_property_read_bool(dev, "nuvoton,temp-compensation"); + if (nau8310->silicon_id == NAU8310_REG_SI_REV_G10) { + ret = device_property_read_u32(dev, "nuvoton,boost-delay-ms", + &nau8310->boost_delay_ms); + if (ret) + nau8310->boost_delay_ms = 128; + + ret = device_property_read_u32(dev, "nuvoton,boost-convert-mode", + &nau8310->boost_convert_mode); + if (ret) + nau8310->boost_convert_mode = 0; + + ret = device_property_read_u32(dev, "nuvoton,boost-target-limit-microvolt", + &val); + if (ret) + nau8310->boost_target_limit = 0x32; + else + nau8310->boost_target_limit = val / 190000; + + ret = device_property_read_u32(dev, "nuvoton,boost-target-margin-microvolt", + &val); + if (ret) + nau8310->boost_target_margin = 0x2; + else + nau8310->boost_target_margin = val / 190000; + } + nau8310->normal_iis_data = + device_property_read_bool(dev, "nuvoton,normal-iis-data"); + + ret = device_property_read_string(dev, "firmware-name", + &firmware_names); + + if (ret) { + nau8310->dsp_firmware = devm_kstrdup(dev, def_fws, GFP_KERNEL); + + if (!nau8310->dsp_firmware) + return -ENOMEM; + } else { + nau8310->dsp_firmware = devm_kasprintf(dev, GFP_KERNEL, + NAU8310_DSP_FIRMDIR "%s", firmware_names); + + if (!nau8310->dsp_firmware) + return -ENOMEM; + } + + return 0; +} + +static int nau8310_i2c_probe(struct i2c_client *i2c) +{ + struct device *dev = &i2c->dev; + struct nau8310 *nau8310; + int ret, value, dev_id; + + nau8310 = devm_kzalloc(dev, sizeof(*nau8310), GFP_KERNEL); + if (!nau8310) + return -ENOMEM; + + i2c_set_clientdata(i2c, nau8310); + mutex_init(&nau8310->lock); + + nau8310->regmap = devm_regmap_init(dev, NULL, i2c, &nau8310_regmap_config); + if (IS_ERR(nau8310->regmap)) + return PTR_ERR(nau8310->regmap); + + ret = devm_work_autocancel(dev, &nau8310->load_fw_work, nau8310_load_fw_work); + if (ret) + return ret; + + nau8310->dev = dev; + + nau8310_reset_chip(nau8310->regmap); + ret = regmap_read(nau8310->regmap, NAU8310_R46_I2C_DEVICE_ID, &value); + if (ret) { + dev_err(dev, "Failed to read NAU8310/20 device id: %d", ret); + return ret; + } + + dev_id = (int)(uintptr_t)i2c_get_match_data(i2c); + nau8310->silicon_id = value & NAU8310_REG_SI_REV_MASK; + + if (dev_id != nau8310->silicon_id) { + dev_warn(dev, "Device Tree ID (0x%x) does not match hardware ID (0x%x)\n", + dev_id, nau8310->silicon_id); + } + ret = nau8310_read_device_properties(nau8310); + if (ret) + return ret; + + nau8310_print_device_properties(nau8310); + nau8310_init_regs(nau8310); + + return devm_snd_soc_register_component(dev, &soc_comp_dev_nau8310, + &nau8310_dai, 1); +} + +static const struct i2c_device_id nau8310_i2c_ids[] = { + { .name = "nau8310", .driver_data = (kernel_ulong_t)NAU8310_REG_SI_REV_G10 }, + { .name = "nau8320", .driver_data = (kernel_ulong_t)NAU8310_REG_SI_REV_G20 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, nau8310_i2c_ids); + +static const struct of_device_id nau8310_of_ids[] = { + { .compatible = "nuvoton,nau8310", .data = (void *)NAU8310_REG_SI_REV_G10 }, + { .compatible = "nuvoton,nau8320", .data = (void *)NAU8310_REG_SI_REV_G20 }, + {} +}; +MODULE_DEVICE_TABLE(of, nau8310_of_ids); + +static const struct acpi_device_id nau8310_acpi_match[] = { + { .id = "NVTN2000" }, + { .id = "NVTN2001" }, + {} +}; +MODULE_DEVICE_TABLE(acpi, nau8310_acpi_match); + +static struct i2c_driver nau8310_i2c_driver = { + .driver = { + .name = "nau8310", + .of_match_table = nau8310_of_ids, + .acpi_match_table = nau8310_acpi_match, + }, + .probe = nau8310_i2c_probe, + .id_table = nau8310_i2c_ids, +}; +module_i2c_driver(nau8310_i2c_driver); + +MODULE_DESCRIPTION("ASoC NAU83G10/20 Boosted Mono Class-D Amplifier with DSP and I/V-sense driver"); +MODULE_AUTHOR("John Hsu "); +MODULE_AUTHOR("David Lin "); +MODULE_AUTHOR("Neo Chang "); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/nau8310.h b/sound/soc/codecs/nau8310.h new file mode 100644 index 00000000000000..496b9a3c01f69b --- /dev/null +++ b/sound/soc/codecs/nau8310.h @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// The NAU83G10/20 Boosted Mono Class-D Amplifier with DSP and I/V-sense driver. +// +// Copyright 2026 Nuvoton Technology Crop. +// Author: John Hsu +// David Lin +// Neo Chang + +#ifndef __NAU8310_H__ +#define __NAU8310_H__ + +#define NAU8310_R00_HARDWARE_RST 0x00 +#define NAU8310_R01_SOFTWARE_RST 0x01 +#define NAU8310_R02_I2C_ADDR 0x02 +#define NAU8310_R03_CLK_CTRL 0x03 +#define NAU8310_R04_ENA_CTRL 0x04 +#define NAU8310_R05_INTERRUPT_CTRL 0x05 +#define NAU8310_R06_INT_CLR_STATUS 0x06 +#define NAU8310_R07_SAR_CTRL1 0x07 +#define NAU8310_R08_GPIO124_CTRL 0x08 +#define NAU8310_R09_GPIOOUT 0x09 +#define NAU8310_R0A_IO_CTRL 0x0a +#define NAU8310_R0B_I2S_PCM_CTRL0 0x0b +#define NAU8310_R0C_TDM_CTRL 0x0c +#define NAU8310_R0D_I2S_PCM_CTRL1 0x0d +#define NAU8310_R0E_I2S_PCM_CTRL2 0x0e +#define NAU8310_R0F_LEFT_TIME_SLOT 0x0f +#define NAU8310_R10_RIGHT_TIME_SLOT 0x10 +#define NAU8310_R12_HPF_CTRL 0x12 +#define NAU8310_R13_MUTE_CTRL 0x13 +#define NAU8310_R14_ADC_VOL_CTRL 0x14 +#define NAU8310_R15_INT_COE 0x15 +#define NAU8310_R16_DEC_COE 0x16 +#define NAU8310_R17_BOOST_CTRL1 0x17 +#define NAU8310_R18_BOOST_CTRL2 0x18 +#define NAU8310_R19_DSP_CORE_CTRL1 0x19 +#define NAU8310_R1A_DSP_CORE_CTRL2 0x1a +#define NAU8310_R1B_CLK_DOUBLER_O 0x1b +#define NAU8310_R1C_BOOST_CTRL_O 0x1c +#define NAU8310_R1D_GENERAL_STATUS0 0x1d +#define NAU8310_R1E_GENERAL_STATUS1 0x1e +#define NAU8310_R1F_GENERAL_STATUS2 0x1f +#define NAU8310_R20_SAR_ADC_OUT_01 0x20 +#define NAU8310_R21_SAR_ADC_OUT_23 0x21 +#define NAU8310_R22_ALC_READOUT1 0x22 +#define NAU8310_R23_ALC_READOUT2 0x23 +#define NAU8310_R24_ALC_READOUT3 0x24 +#define NAU8310_R25_DSP_STATUS_0 0x25 +#define NAU8310_R26_DSP_STATUS_1 0x26 +#define NAU8310_R27_DSP_STATUS_2 0x27 +#define NAU8310_R28_ADC_RATE 0x28 +#define NAU8310_R29_DAC_CTRL1 0x29 +#define NAU8310_R2A_DAC_CTRL2 0x2a +#define NAU8310_R2C_ALC_CTRL1 0x2c +#define NAU8310_R2D_ALC_CTRL2 0x2d +#define NAU8310_R2E_ALC_CTRL3 0x2e +#define NAU8310_R2F_ALC_CTRL4 0x2f +#define NAU8310_R30_TEMP_COMP_CTRL 0x30 +#define NAU8310_R31_UVLO_CTRL0 0x31 +#define NAU8310_R32_UVLO_CTRL1 0x32 +#define NAU8310_R33_LPF_CTRL 0x33 +#define NAU8310_R40_CLK_DET_CTRL 0x40 +#define NAU8310_R46_I2C_DEVICE_ID 0x46 +#define NAU8310_R4A_ANALOG_READ 0x4a +#define NAU8310_R55_MISC_CTRL 0x55 +#define NAU8310_R60_BIAS_ADJ 0x60 +#define NAU8310_R61_ANALOG_CONTROL_1 0x61 +#define NAU8310_R62_ANALOG_CONTROL_2 0x62 +#define NAU8310_R63_ANALOG_CONTROL_3 0x63 +#define NAU8310_R64_ANALOG_CONTROL_4 0x64 +#define NAU8310_R65_ANALOG_CONTROL_5 0x65 +#define NAU8310_R66_ANALOG_CONTROL_6 0x66 +#define NAU8310_R68_ANALOG_CONTROL_7 0x68 +#define NAU8310_R69_CLIP_CTRL 0x69 +#define NAU8310_R6B_ANALOG_CONTROL_8 0x6b +#define NAU8310_R6C_ANALOG_CONTROL_9 0x6c +#define NAU8310_R71_ANALOG_ADC_1 0x71 +#define NAU8310_R72_ANALOG_ADC_2 0x72 +#define NAU8310_R73_RDAC 0x73 +#define NAU8310_R76_BOOST 0x76 +#define NAU8310_R77_FEPGA 0x77 +#define NAU8310_R7F_POWER_UP_CONTROL 0x7f +#define NAU8310_R80_BIQ0_COE_1 0x80 +#define NAU8310_R81_BIQ0_COE_2 0x81 +#define NAU8310_R82_BIQ0_COE_3 0x82 +#define NAU8310_R83_BIQ0_COE_4 0x83 +#define NAU8310_R84_BIQ0_COE_5 0x84 +#define NAU8310_R85_BIQ0_COE_6 0x85 +#define NAU8310_R86_BIQ0_COE_7 0x86 +#define NAU8310_R87_BIQ0_COE_8 0x87 +#define NAU8310_R88_BIQ0_COE_9 0x88 +#define NAU8310_R89_BIQ0_COE_10 0x89 +#define NAU8310_R8A_BIQ1_COE_1 0x8a +#define NAU8310_R8B_BIQ1_COE_2 0x8b +#define NAU8310_R8C_BIQ1_COE_3 0x8c +#define NAU8310_R8D_BIQ1_COE_4 0x8d +#define NAU8310_R8E_BIQ1_COE_5 0x8e +#define NAU8310_R8F_BIQ1_COE_6 0x8f +#define NAU8310_R90_BIQ1_COE_7 0x90 +#define NAU8310_R91_BIQ1_COE_8 0x91 +#define NAU8310_R92_BIQ1_COE_9 0x92 +#define NAU8310_R93_BIQ1_COE_10 0x93 +#define NAU8310_R94_BIQ2_COE_1 0x94 +#define NAU8310_R95_BIQ2_COE_2 0x95 +#define NAU8310_R96_BIQ2_COE_3 0x96 +#define NAU8310_R97_BIQ2_COE_4 0x97 +#define NAU8310_R98_BIQ2_COE_5 0x98 +#define NAU8310_R99_BIQ2_COE_6 0x99 +#define NAU8310_R9A_BIQ2_COE_7 0x9a +#define NAU8310_R9B_BIQ2_COE_8 0x9b +#define NAU8310_R9C_BIQ2_COE_9 0x9c +#define NAU8310_R9D_BIQ2_COE_10 0x9d +#define NAU8310_RF000_DSP_COMM 0xf000 +#define NAU8310_REG_MAX NAU8310_RF000_DSP_COMM +/* 16-bit control register address, and 16-bits control register data */ +#define NAU8310_REG_ADDR_LEN 16 +#define NAU8310_REG_DATA_LEN 16 + + +/* CLK_CTRL (0x03) */ +#define NAU8310_CLK_ADC_DIV2_SFT 12 +#define NAU8310_CLK_ADC_DIV2 (0x1 << NAU8310_CLK_ADC_DIV2_SFT) +#define NAU8310_CLK_ADC_DIV4_SFT 11 +#define NAU8310_CLK_ADC_DIV4 (0x1 << NAU8310_CLK_ADC_DIV4_SFT) +#define NAU8310_CLK_ADC_SRC_SFT 6 +#define NAU8310_CLK_ADC_SRC_MASK (0x3 << NAU8310_CLK_ADC_SRC_SFT) +#define NAU8310_CLK_DAC_SRC_SFT 4 +#define NAU8310_CLK_DAC_SRC_MASK (0x3 << NAU8310_CLK_DAC_SRC_SFT) +#define NAU8310_MCLK_SRC_MASK 0x7 + +/* ENA_CTRL (0x04) */ +#define NAU8310_DSP_OSC_SFT 14 +#define NAU8310_DSP_OSC_EN (0x1 << NAU8310_DSP_OSC_SFT) +#define NAU8310_DSP_SEL_OSC_SFT 13 +#define NAU8310_DSP_SEL_OSC (0x1 << NAU8310_DSP_SEL_OSC_SFT) +#define NAU8310_MCLK_SEL_SFT 8 +#define NAU8310_MCLK_SEL_MASK (0x7 << NAU8310_MCLK_SEL_SFT) +#define NAU8310_CLK_MUL_SRC_SFT 6 +#define NAU8310_CLK_MUL_SRC_MASK (0x3 << NAU8310_CLK_MUL_SRC_SFT) +#define NAU8310_CLK_DSP_SRC_SFT 3 +#define NAU8310_CLK_DSP_SRC_MASK (0x7 << NAU8310_CLK_DSP_SRC_SFT) +#define NAU8310_DAC_CH_EN_SFT 2 +#define NAU8310_DAC_CH_EN (0x1 << NAU8310_DAC_CH_EN_SFT) +#define NAU8310_ADCEN_I_SFT 1 +#define NAU8310_ADCEN_I (0x1 << NAU8310_ADCEN_I_SFT) +#define NAU8310_ADCEN_V_SFT 0 +#define NAU8310_ADCEN_V (0x1 << NAU8310_ADCEN_V_SFT) + +/* INTERRUPT_CTRL (0x05) */ +#define NAU8310_WD_INT_MASK_SFT 14 +#define NAU8310_WD_INT_MASK (0x1 << NAU8310_WD_INT_MASK_SFT) +#define NAU8310_DSP2I2C_INT_MASK_SFT 13 +#define NAU8310_DSP2I2C_INT_MASK (0x1 << NAU8310_DSP2I2C_INT_MASK_SFT) +#define NAU8310_ARP_DWN_INT_MASK_SFT 12 +#define NAU8310_ARP_DWN_INT_MASK (0x1 << NAU8310_ARP_DWN_INT_MASK_SFT) +#define NAU8310_CLIP_INT_MASK_SFT 11 +#define NAU8310_CLIP_INT_MASK (0x1 << NAU8310_CLIP_INT_MASK_SFT) +#define NAU8310_LVD_INT_MASK_SFT 10 +#define NAU8310_LVD_INT_MASK (0x1 << NAU8310_LVD_INT_MASK_SFT) +#define NAU8310_OVP_INT_MASK_SFT 9 +#define NAU8310_OVP_INT_MASK (0x1 << NAU8310_OVP_INT_MASK_SFT) +#define NAU8310_PWR_INT_DIS_SFT 8 +#define NAU8310_PWR_INT_DIS (0x1 << NAU8310_PWR_INT_DIS_SFT) +#define NAU8310_WD_INT_DIS_SFT 6 +#define NAU8310_WD_INT_DIS (0x1 << NAU8310_WD_INT_DIS_SFT) +#define NAU8310_DSP2I2C_INT_DIS_SFT 5 +#define NAU8310_DSP2I2C_INT_DIS (0x1 << NAU8310_DSP2I2C_INT_DIS_SFT) +#define NAU8310_ARP_DWN_INT_DIS_SFT 4 +#define NAU8310_ARP_DWN_INT_DIS (0x1 << NAU8310_ARP_DWN_INT_DIS_SFT) +#define NAU8310_CLIP_INT_DIS_SFT 3 +#define NAU8310_CLIP_INT_DIS (0x1 << NAU8310_CLIP_INT_DIS_SFT) +#define NAU8310_LVD_INT_DIS_SFT 2 +#define NAU8310_LVD_INT_DIS (0x1 << NAU8310_LVD_INT_DIS_SFT) +#define NAU8310_OVP_INT_DIS_SFT 1 +#define NAU8310_OVP_INT_DIS (0x1 << NAU8310_OVP_INT_DIS_SFT) +#define NAU8310_PWR_INT_MASK 0x1 + +/* INT_CLR_STATUS (0x06) */ +#define NAU8310_INT_STATUS_MASK 0x7ff +#define NAU8310_INT_STATUS_WD (0x1 << 6) +#define NAU8310_INT_STATUS_DSP2I2C (0x1 << 5) +#define NAU8310_INT_STATUS_ARP_DWN (0x1 << 4) +#define NAU8310_INT_STATUS_CLIP (0x1 << 3) +#define NAU8310_INT_STATUS_LVD (0x1 << 2) +#define NAU8310_INT_STATUS_OVP (0x1 << 1) +#define NAU8310_INT_STATUS_PWR 0x1 + +/* SAR_CTRL1 (0x07) */ +#define NAU8310_SAR_TRACKING_GAIN_SFT 11 +#define NAU8310_SAR_TRACKING_GAIN_MASK (0x7 << NAU8310_SAR_TRACKING_GAIN_SFT) +#define NAU8310_SAR_COMPARE_TIME_SFT 5 +#define NAU8310_SAR_COMPARE_TIME_MASK (0x3 << NAU8310_SAR_COMPARE_TIME_SFT) +#define NAU8310_SAR_SAMPLING_TIME_SFT 2 +#define NAU8310_SAR_SAMPLING_TIME_MASK (0x3 << NAU8310_SAR_SAMPLING_TIME_SFT) +#define NAU8310_SAR_ENA_SFT 0 +#define NAU8310_SAR_ENA_EN (0x1 << NAU8310_SAR_ENA_SFT) + +/* IO_CTRL (0x0a) */ +#define NAU8310_IRQ_PL_SFT 15 +#define NAU8310_IRQ_PL_ACT_HIGH (0x1 << NAU8310_IRQ_PL_SFT) +#define NAU8310_IRQ_DS_SFT 12 +#define NAU8310_IRQ_DS_HIGH (0x1 << NAU8310_IRQ_DS_SFT) +#define NAU8310_IRQ_OUTPUT_SFT 11 +#define NAU8310_IRQ_OUTPUT_EN (0x1 << NAU8310_IRQ_OUTPUT_SFT) +#define NAU8310_BCLK_DS_SFT 2 +#define NAU8310_BCLK_DS_EN (0x1 << NAU8310_BCLK_DS_SFT) +#define NAU8310_LRC_DS_SFT 1 +#define NAU8310_LRC_DS_EN (0x1 << NAU8310_LRC_DS_SFT) +#define NAU8310_ADCDAT_DS_SFT 0 +#define NAU8310_ADCDAT_DS_EN 0x1 + +/* I2S_PCM_CTRL0 (0x0b) */ +#define NAU8310_ALC_MODE_SFT 15 +#define NAU8310_ALC_MODE (0x1 << NAU8310_ALC_MODE_SFT) +#define NAU8310_ALC_SEND_ON_LOC_SFT 14 +#define NAU8310_ALC_SEND_ON_LOC (0x1 << NAU8310_ALC_SEND_ON_LOC_SFT) +#define NAU8310_DAC_SEL_SFT 10 +#define NAU8310_DAC_SEL_MASK (0x7 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT0 0 +#define NAU8310_DAC_SEL_SLOT1 (0x1 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT2 (0x2 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT3 (0x3 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT4 (0x4 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT5 (0x5 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT6 (0x6 << NAU8310_DAC_SEL_SFT) +#define NAU8310_DAC_SEL_SLOT7 (0x7 << NAU8310_DAC_SEL_SFT) +#define NAU8310_AEC_CH_SEL_SFT 2 +#define NAU8310_AEC_CH_SEL_RIGHT (0x0 << NAU8310_AEC_CH_SEL_SFT) +#define NAU8310_AEC_CH_SEL_LEFT (0x1 << NAU8310_AEC_CH_SEL_SFT) +#define NAU8310_AEC_SRC_SEL_SFT 1 +#define NAU8310_AEC_SRC_SEL_DSP (0x0 << NAU8310_AEC_SRC_SEL_SFT) +#define NAU8310_AEC_SRC_SEL_DAC (0x1 << NAU8310_AEC_SRC_SEL_SFT) +#define NAU8310_AEC_MODE_SFT 0 +#define NAU8310_AEC_MODE_IV (0x0 << NAU8310_AEC_MODE_SFT) +#define NAU8310_AEC_MODE_AEC (0x1 << NAU8310_AEC_MODE_SFT) + +/* TDM_CTRL (0x0c) */ +#define NAU8310_TDM_SFT 15 +#define NAU8310_TDM_EN (0x1 << NAU8310_TDM_SFT) +#define NAU8310_TDM_OFFSET_SFT 14 +#define NAU8310_TDM_OFFSET_EN (0x1 << NAU8310_TDM_OFFSET_SFT) +#define NAU8310_PINGPONG_SFT 13 +#define NAU8310_PINGPONG_EN (0x1 << NAU8310_PINGPONG_SFT) +#define NAU8310_ADC_ALC_SEL_SFT 6 +#define NAU8310_ADC_ALC_SEL_MASK (0xf << NAU8310_ADC_ALC_SEL_SFT) +#define NAU8310_ADC_I_SEL_SFT 3 +#define NAU8310_ADC_I_SEL_MASK (0x7 << NAU8310_ADC_I_SEL_SFT) +#define NAU8310_ADC_I_SEL_DIS 0 +#define NAU8310_ADC_I_SEL_SLOT1 (0x4 << NAU8310_ADC_I_SEL_SFT) +#define NAU8310_ADC_I_SEL_SLOT3 (0x5 << NAU8310_ADC_I_SEL_SFT) +#define NAU8310_ADC_I_SEL_SLOT5 (0x6 << NAU8310_ADC_I_SEL_SFT) +#define NAU8310_ADC_I_SEL_SLOT7 (0x7 << NAU8310_ADC_I_SEL_SFT) +#define NAU8310_ADC_V_SEL_SFT 0 +#define NAU8310_ADC_V_SEL_MASK 0x7 +#define NAU8310_ADC_V_SEL_DIS 0 +#define NAU8310_ADC_V_SEL_SLOT0 0x4 +#define NAU8310_ADC_V_SEL_SLOT2 0x5 +#define NAU8310_ADC_V_SEL_SLOT4 0x6 +#define NAU8310_ADC_V_SEL_SLOT6 0x7 + +/* I2S_PCM_CTRL1 (0x0d) */ +#define NAU8310_I2S_BP_SFT 7 +#define NAU8310_I2S_BP_MASK (0x1 << NAU8310_I2S_BP_SFT) +#define NAU8310_I2S_BP_INV (0x1 << NAU8310_I2S_BP_SFT) +#define NAU8310_I2S_PCMB_SFT 6 +#define NAU8310_I2S_PCMB_EN (0x1 << NAU8310_I2S_PCMB_SFT) +#define NAU8310_I2S_DL_SFT 2 +#define NAU8310_I2S_DL_MASK (0x3 << NAU8310_I2S_DL_SFT) +#define NAU8310_I2S_DL_16 (0x0 << NAU8310_I2S_DL_SFT) +#define NAU8310_I2S_DL_20 (0x1 << NAU8310_I2S_DL_SFT) +#define NAU8310_I2S_DL_24 (0x2 << NAU8310_I2S_DL_SFT) +#define NAU8310_I2S_DL_32 (0x3 << NAU8310_I2S_DL_SFT) +#define NAU8310_I2S_DF_MASK 0x3 +#define NAU8310_I2S_DF_RIGHT 0x0 +#define NAU8310_I2S_DF_LEFT 0x1 +#define NAU8310_I2S_DF_I2S 0x2 +#define NAU8310_I2S_DF_PCM_AB 0x3 + +/* I2S_PCM_CTRL2 (0x0e) */ +#define NAU8310_I2S_TRISTATE_SFT 15 +#define NAU8310_I2S_TRISTATE (1 << NAU8310_I2S_TRISTATE_SFT) +#define NAU8310_I2S_LRC_DIV_SFT 12 +#define NAU8310_I2S_LRC_DIV_MASK (0x3 << NAU8310_I2S_LRC_DIV_SFT) +#define NAU8310_I2S_ADCDAT_OE_SFT 4 +#define NAU8310_I2S_ADCDAT_OE_MASK (1 << NAU8310_I2S_ADCDAT_OE_SFT) +#define NAU8310_I2S_ADCDAT_OE_EN (0 << NAU8310_I2S_ADCDAT_OE_SFT) +#define NAU8310_I2S_ADCDAT_OE_DIS (1 << NAU8310_I2S_ADCDAT_OE_SFT) +#define NAU8310_I2S_MS_SFT 3 +#define NAU8310_I2S_MS_MASK (0x1 << NAU8310_I2S_MS_SFT) +#define NAU8310_I2S_MS_MASTER (0x1 << NAU8310_I2S_MS_SFT) +#define NAU8310_I2S_BLK_DIV_MASK 0x7 + +/* MUTE_CTRL (0x13) */ +#define NAU8310_SOFT_MUTE_SFT 15 +#define NAU8310_SOFT_MUTE (0x1 << NAU8310_SOFT_MUTE_SFT) +#define NAU8310_DAC_ZE_SFT 8 +#define NAU8310_DAC_ZE_EN (0x1 << NAU8310_DAC_ZE_SFT) +#define NAU8310_DAC_VOL_SFT 0 +#define NAU8310_DAC_VOL_MAX 0xff + +/* ADC_VOL_CTRL (0x14) */ +#define NAU8310_ADC_GAIN_L_SFT 8 +#define NAU8310_ADC_GAIN_L_MAX 0xc1 +#define NAU8310_ADC_GAIN_L_MASK (0xff << NAU8310_ADC_GAIN_L_SFT) +#define NAU8310_ADC_GAIN_R_SFT 0 +#define NAU8310_ADC_GAIN_R_MAX 0xc1 +#define NAU8310_ADC_GAIN_R_MASK 0xff + +/* BOOST_CTRL1 (0x17) */ +#define NAU8310_BSTLIMIT_SFT 8 +#define NAU8310_BSTLIMIT_MAX 0x3f +#define NAU8310_BSTLIMIT_MASK (0x3f << NAU8310_BSTLIMIT_SFT) +#define NAU8310_BSTMARGIN_SFT 0 +#define NAU8310_BSTMARGIN_MAX 0x3f +#define NAU8310_BSTMARGIN_MASK 0x3f + +/* BOOST_CTRL2 (0x18) */ +#define NAU8310_TC_SFT 15 +#define NAU8310_TC_EN (0x1 << NAU8310_TC_SFT) +#define NAU8310_BSTHOLD_SFT 7 +#define NAU8310_BSTHOLD_MASK (0xf << NAU8310_BSTHOLD_SFT) +#define NAU8310_BSTSTEPTIME_SFT 4 +#define NAU8310_BSTSTEPTIME_MASK (0x7 << NAU8310_BSTSTEPTIME_SFT) +#define NAU8310_BSTDELAY_MASK 0xf + +/* DSP_CORE_CTRL2 (0x1a) */ +#define NAU8310_DAC_SEL_DSP_SFT 5 +#define NAU8310_DAC_SEL_DSP_OUT (0x1 << NAU8310_DAC_SEL_DSP_SFT) +#define NAU8310_DSP_RUNSTALL_SFT 4 +#define NAU8310_DSP_RUNSTALL (0x1 << NAU8310_DSP_RUNSTALL_SFT) + +/* ADC_RATE (0x28) */ +#define NAU8310_I2S_MODE_SFT 15 +#define NAU8310_I2S_MODE (0x1 << NAU8310_I2S_MODE_SFT) +#define NAU8310_UNSIGN_IV_SFT 8 +#define NAU8310_UNSIGN_IV (0x1 << NAU8310_UNSIGN_IV_SFT) +#define NAU8310_ADC_SYNC_DOWN_SFT 0 +#define NAU8310_ADC_SYNC_DOWN_MASK 0x3 +#define NAU8310_ADC_SYNC_DOWN_32 0 +#define NAU8310_ADC_SYNC_DOWN_64 1 +#define NAU8310_ADC_SYNC_DOWN_128 2 + +/* DAC_CTRL1 (0x29) */ +#define NAU8310_DAC_OVERSAMPLE_SFT 0 +#define NAU8310_DAC_OVERSAMPLE_MASK 0x7 +#define NAU8310_DAC_OVERSAMPLE_64 0 +#define NAU8310_DAC_OVERSAMPLE_256 1 +#define NAU8310_DAC_OVERSAMPLE_128 2 +#define NAU8310_DAC_OVERSAMPLE_32 4 + +/* ALC_CTRL1 (0x2c) */ +#define NAU8310_ALC_MAXGAIN_SFT 5 +#define NAU8310_ALC_MAXGAIN_MAX 0x7 +#define NAU8310_ALC_MAXGAIN_MASK (0x7 << NAU8310_ALC_MAXGAIN_SFT) +#define NAU8310_ALC_MINGAIN_SFT 1 +#define NAU8310_ALC_MINGAIN_MAX 4 +#define NAU8310_ALC_MINGAIN_MASK (0x7 << NAU8310_ALC_MINGAIN_SFT) +#define NAU8310_ALC_GAIN_SEL_SFT 0 +#define NAU8310_ALC_GAIN_SEL_MODE 1 + +/* ALC_CTRL2 (0x2d) */ +#define NAU8310_ALC_DCY_SFT 12 +#define NAU8310_ALC_DCY_MAX 0xb +#define NAU8310_ALC_DCY_MASK (0xf << NAU8310_ALC_DCY_SFT) +#define NAU8310_ALC_ATK_SFT 8 +#define NAU8310_ALC_ATK_MAX 0xb +#define NAU8310_ALC_ATK_MASK (0xf << NAU8310_ALC_ATK_SFT) +#define NAU8310_ALC_HLD_SFT 4 +#define NAU8310_ALC_HLD_MAX 0xa +#define NAU8310_ALC_HLD_MASK (0xf << NAU8310_ALC_HLD_SFT) +#define NAU8310_ALC_LVL_SFT 0 +#define NAU8310_ALC_LVL_MAX 0xf +#define NAU8310_ALC_LVL_MASK 0xf + +/* ALC_CTRL3 (0x2e) */ +#define NAU8310_ALC_EN_SFT 15 +#define NAU8310_ALC_EN (0x1 << NAU8310_ALC_EN_SFT) +#define NAU8310_LIM_MDE_SFT 12 +#define NAU8310_LIM_MDE_MASK (0x7 << NAU8310_LIM_MDE_SFT) +#define NAU8310_VBAT_THLD_SFT 5 +#define NAU8310_VBAT_THLD_MAX 0x1f +#define NAU8310_VBAT_THLD_MASK (0x1f << NAU8310_VBAT_THLD_SFT) +#define NAU8310_AUTOATT_EN_SFT 4 +#define NAU8310_AUTOATT_EN (0x1 << NAU8310_AUTOATT_EN_SFT) + +/* TEMP_COMP_CTRL (0x30) */ +#define NAU8310_TEMP_COMP_ACT2_MASK 0xff + +/* LPF_CTRL (0x33) */ +#define NAU8310_LPF_IN1_EN_SFT 15 +#define NAU8310_LPF_IN1_EN (0x1 << NAU8310_LPF_IN1_EN_SFT) +#define NAU8310_LPF_IN1_TC_SFT 11 +#define NAU8310_LPF_IN1_TC_MASK (0xf << NAU8310_LPF_IN1_TC_SFT) +#define NAU8310_LPF_IN2_EN_SFT 10 +#define NAU8310_LPF_IN2_EN (0x1 << NAU8310_LPF_IN2_EN_SFT) +#define NAU8310_LPF_IN2_TC_SFT 6 +#define NAU8310_LPF_IN2_TC_MASK (0xf << NAU8310_LPF_IN2_TC_SFT) + +/* CLK_DET_CTRL (0x40) */ +#define NAU8310_APWRUP_SFT 15 +#define NAU8310_APWRUP_EN (0x1 << NAU8310_APWRUP_SFT) +#define NAU8310_CLKPWRUP_SFT 14 +#define NAU8310_CLKPWRUP_DIS (0x1 << NAU8310_CLKPWRUP_SFT) +#define NAU8310_PWRUP_DFT_SFT 13 +#define NAU8310_PWRUP_DFT (0x1 << NAU8310_PWRUP_DFT_SFT) +#define NAU8310_SRATE_SFT 10 +#define NAU8310_SRATE_MASK (0x7 << NAU8310_SRATE_SFT) +#define NAU8310_ALT_SRATE_SFT 9 +#define NAU8310_ALT_SRATE_EN (0x1 << NAU8310_ALT_SRATE_SFT) +#define NAU8310_DIV_MAX 0x1 + +/* I2C_DEVICE_ID (0x46) */ +#define NAU8310_I2C_DEVICE_ID_SFT 8 +#define NAU8310_I2C_DEVICE_ID_MASK (0x7f << NAU8310_I2C_DEVICE_ID_SFT) +#define NAU8310_REG_SI_REV_MASK 0xff +#define NAU8310_REG_SI_REV_G10 0xe1 +#define NAU8310_REG_SI_REV_G20 0x61 + +/* BIAS_ADJ (0x60) */ +#define NAU8310_BIAS_VMID_SEL_SFT 4 +#define NAU8310_BIAS_VMID_SEL_MASK (0x3 << NAU8310_BIAS_VMID_SEL_SFT) + +/* ANALOG_CONTROL_1 (0x61) */ +#define NAU8310_ISEN_SFT 14 +#define NAU8310_ISEN_MASK (0x3 << NAU8310_ISEN_SFT) +#define NAU8310_ADCRSTEN_SFT 12 +#define NAU8310_ADCRSTEN_MASK (0x3 << NAU8310_ADCRSTEN_SFT) +#define NAU8310_VSEN_SFT 10 +#define NAU8310_VSEN_MASK (0x3 << NAU8310_VSEN_SFT) +#define NAU8310_ADCEN_SFT 8 +#define NAU8310_ADCEN_MASK (0x3 << NAU8310_ADCEN_SFT) +#define NAU8310_DACCLKEN_SFT 6 +#define NAU8310_DACCLKEN_MASK (0x3 << NAU8310_DACCLKEN_SFT) +#define NAU8310_DACEN_SFT 4 +#define NAU8310_DACEN_MASK (0x3 << NAU8310_DACEN_SFT) +#define NAU8310_BIASEN_SFT 2 +#define NAU8310_BIASEN_MASK (0x3 << NAU8310_BIASEN_SFT) +#define NAU8310_VMIDEN_MASK 0x3 + +/* ANALOG_CONTROL_2 (0x62) */ +#define NAU8310_CLASSDEN_SFT 4 +#define NAU8310_CLASSDEN_MASK (0x3 << NAU8310_CLASSDEN_SFT) +#define NAU8310_PDVMDFST_SFT 2 +#define NAU8310_PDVMDFST_MASK (0x3 << NAU8310_PDVMDFST_SFT) +#define NAU8310_BSTEN_MASK 0x3 + +/* ANALOG_CONTROL_3 (0x63) */ +#define NAU8310_DACREFCAP_SFT 4 +#define NAU8310_DACREFCAP_MASK (0x3 << NAU8310_DACREFCAP_SFT) + +/* ANALOG_CONTROL_4 (0x64) */ +#define NAU8310_RECV_MODE_SFT 15 +#define NAU8310_RECV_MODE (0x1 << NAU8310_RECV_MODE_SFT) +#define NAU8310_AUTOATTMIN_SFT 14 +#define NAU8310_AUTOATTMIN_MASK (0x1 << NAU8310_AUTOATTMIN_SFT) +#define NAU8310_AUTOATTMIN_12DB (0x0 << NAU8310_AUTOATTMIN_SFT) +#define NAU8310_AUTOATTMIN_0DB (0x1 << NAU8310_AUTOATTMIN_SFT) +#define NAU8310_CLASSD_SHORTP_SFT 10 +#define NAU8310_CLASSD_SHORTP_MASK (0xf << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTP_NOMINAL (0x0 << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTP_33UP (0x1 << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTP_100UP (0x3 << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTP_22DOWN (0x8 << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTP_33DOWN (0xc << NAU8310_CLASSD_SHORTP_SFT) +#define NAU8310_CLASSD_SHORTN_SFT 6 +#define NAU8310_CLASSD_SHORTN_MASK (0xf << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SHORTN_NOMINAL (0x0 << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SHORTN_33UP (0x1 << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SHORTN_100UP (0x3 << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SHORTN_22DOWN (0x8 << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SHORTN_33DOWN (0xc << NAU8310_CLASSD_SHORTN_SFT) +#define NAU8310_CLASSD_SLEWP_SFT 3 +#define NAU8310_CLASSD_SLEWP_MASK (0x7 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_NOMINAL (0x0 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_25UP (0x1 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_50UP (0x2 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_75UP (0x3 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_OFF (0x4 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_75DOWN (0x5 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_50DOWN (0x6 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWP_25DOWN (0x7 << NAU8310_CLASSD_SLEWP_SFT) +#define NAU8310_CLASSD_SLEWN_SFT 0 +#define NAU8310_CLASSD_SLEWN_MASK 0x7 +#define NAU8310_CLASSD_SLEWN_NOMINAL 0x0 +#define NAU8310_CLASSD_SLEWN_25UP 0x1 +#define NAU8310_CLASSD_SLEWN_50UP 0x2 +#define NAU8310_CLASSD_SLEWN_75UP 0x3 +#define NAU8310_CLASSD_SLEWN_OFF 0x4 +#define NAU8310_CLASSD_SLEWN_75DOWN 0x5 +#define NAU8310_CLASSD_SLEWN_50DOWN 0x6 +#define NAU8310_CLASSD_SLEWN_25DOWN 0x7 + +/* ANALOG_CONTROL_5 (0x65) */ +#define NAU8310_BSTINDR_SFT 12 +#define NAU8310_BSTINDR_MASK (0x7 << NAU8310_BSTINDR_SFT) +#define NAU8310_BSTCURGEN_SFT 8 +#define NAU8310_BSTCURGEN_MASK (0xf << NAU8310_BSTCURGEN_SFT) +#define NAU8310_BSTMONEN_SFT 7 +#define NAU8310_BSTMONEN (0x1 << NAU8310_BSTMONEN_SFT) +#define NAU8310_BSTNOVPN_SFT 3 +#define NAU8310_BSTNOVPN_MASK (0x3 << NAU8310_BSTNOVPN_SFT) +#define NAU8310_BSTCLKPULSE_MASK 0x3 + +/* ANALOG_CONTROL_6 (0x66) */ +#define NAU8310_BSTRADJ_SFT 12 +#define NAU8310_BSTRADJ_MASK (0x7 << NAU8310_BSTRADJ_SFT) +#define NAU8310_BSTSLEWPOFF_SFT 10 +#define NAU8310_BSTSLEWPOFF_MASK (0x3 << NAU8310_BSTSLEWPOFF_SFT) +#define NAU8310_BSTSLEWPON_SFT 8 +#define NAU8310_BSTSLEWPON_MASK (0x3 << NAU8310_BSTSLEWPON_SFT) +#define NAU8310_BSTSLEWNON_SFT 6 +#define NAU8310_BSTSLEWNON_MASK (0x3 << NAU8310_BSTSLEWNON_SFT) +#define NAU8310_BSTSLEWNOFF_SFT 4 +#define NAU8310_BSTSLEWNOFF_MASK (0x3 << NAU8310_BSTSLEWNOFF_SFT) +#define NAU8310_BSTIPDR_MASK 0x7 + +/* ANALOG_CONTROL_7 (0x68) */ +#define NAU8310_ADCGAIN_SFT 9 +#define NAU8310_ADCGAIN_MASK (0x3 << NAU8310_ADCGAIN_SFT) +#define NAU8310_VREFBG_SFT 6 +#define NAU8310_VREFBG_EN (0x1 << NAU8310_VREFBG_SFT) +#define NAU8310_MU_HALF_RANGE_SFT 3 +#define NAU8310_MU_HALF_RANGE_EN (0x1 << NAU8310_MU_HALF_RANGE_SFT) +#define NAU8310_MCLKX_MASK 0x7 +#define NAU8310_MCLK16XEN 0x4 +#define NAU8310_MCLK8XEN 0x2 +#define NAU8310_MCLK4XEN 0x1 + +/* ANALOG_CONTROL_8 (0x6b) */ +#define NAU8310_VBAT_PCL_SFT 11 +#define NAU8310_VBAT_PCL_MAX 0x1f +#define NAU8310_VBAT_PCL_MASK (0x1f << NAU8310_VBAT_PCL_SFT) +#define NAU8310_VBAT_THD_SFT 4 +#define NAU8310_VBAT_THD_MAX 0xf +#define NAU8310_VBAT_THD_MASK (0xf << NAU8310_VBAT_THD_SFT) + +/* ANALOG_CONTROL_9 (0x6c) */ +#define NAU8310_VBAT_CURLMT_MASK 0x1f + +/* RDAC (0x73) */ +#define NAU8310_DACVREFSEL_SFT 2 +#define NAU8310_DACVREFSEL_MASK (0x3 << NAU8310_DACVREFSEL_SFT) + +/* BOOST (0x76) */ +#define NAU8310_STG2_SEL_SFT 14 +#define NAU8310_STG2_SEL_CLASSA (0x1 << NAU8310_STG2_SEL_SFT) + +/* FEPGA (0x77) */ +#define NAU8310_CURR_TRIM_SFT 8 +#define NAU8310_CURR_TRIM_MAX 0x7 +#define NAU8310_CURR_TRIM_MASK (0x7 << NAU8310_CURR_TRIM_SFT) +#define NAU8310_CMLCK_ENB_SFT 7 +#define NAU8310_CMLCK_ENB (0x1 << NAU8310_CMLCK_ENB_SFT) + +/* POWER_UP_CONTROL (0x7f) */ +#define NAU8310_PGA_GAIN_SFT 4 +#define NAU8310_PGA_GAIN_MAX 0x4 +#define NAU8310_PGA_GAIN_MASK (0x7 << NAU8310_PGA_GAIN_SFT) + +#define NAU8310_TDM_MAX_SLOTS 8 + +#define NAU8310_I2C_REG_LEN 2 +#define NAU8310_I2C_RXBUF_LEN 4 +#define NAU8310_I2C_TXBUF_LEN 6 +#define NAU8310_CODEC_DAI "nau8310-hifi" + +/* DAC Source Path*/ +enum { + NAU8310_DAC_SRC_BYPASS = 0, + NAU8310_DAC_SRC_DSP, +}; + +enum { + NAU8310_CLK_ID_MCLK, + NAU8310_CLK_ID_INT, +}; + +struct nau8310 { + struct device *dev; + struct regmap *regmap; + struct mutex lock; + struct snd_soc_dapm_context *dapm; + char silicon_id; + int mclk; + int vref_impedance_ohms; + int dac_vref_microvolt; + int sar_voltage_microvolt; + int sar_compare_time_ns; + int sar_sampling_time_us; + int clock_detection; + int clock_det_data; + int temp_compensation; + int boost_delay_ms; + int boost_convert_mode; + int boost_target_limit; + int boost_target_margin; + int normal_iis_data; + int kcs_setup_size; + bool load_fw_done; + u8 i2c_read_reg[NAU8310_I2C_REG_LEN] ____cacheline_aligned; + u8 i2c_read_buf[NAU8310_I2C_RXBUF_LEN] ____cacheline_aligned; + u8 i2c_write_buf[NAU8310_I2C_TXBUF_LEN] ____cacheline_aligned; + struct work_struct load_fw_work; + const char *dsp_firmware; +}; + +struct nau8310_src_attr { + int param; + unsigned int val; +}; + +enum { + NAU8310_MCLK_FS_RATIO_256, + NAU8310_MCLK_FS_RATIO_400, + NAU8310_MCLK_FS_RATIO_500, + NAU8310_MCLK_FS_RATIO_NUM, +}; + +struct nau8310_srate_attr { + int fs; + int range; + bool max; + unsigned int mclk_src[NAU8310_MCLK_FS_RATIO_NUM]; + int adc_div; +}; + +struct nau8310_osr_attr { + unsigned int osr; + unsigned int clk_src; +}; + +void nau8310_software_reset(struct regmap *regmap); + +#endif /* __NAU8310_H__ */ diff --git a/sound/soc/codecs/nau8315.c b/sound/soc/codecs/nau8315.c index 9ac2048ff0b000..a4f4ea23222c1e 100644 --- a/sound/soc/codecs/nau8315.c +++ b/sound/soc/codecs/nau8315.c @@ -117,7 +117,7 @@ static int nau8315_platform_probe(struct platform_device *pdev) { struct nau8315_priv *nau8315; - nau8315 = devm_kzalloc(&pdev->dev, sizeof(*nau8315), GFP_KERNEL); + nau8315 = devm_kzalloc_obj(&pdev->dev, *nau8315); if (!nau8315) return -ENOMEM; diff --git a/sound/soc/codecs/nau8325.c b/sound/soc/codecs/nau8325.c index 5ccf4c1105671c..016336b34596fc 100644 --- a/sound/soc/codecs/nau8325.c +++ b/sound/soc/codecs/nau8325.c @@ -863,7 +863,7 @@ static int nau8325_i2c_probe(struct i2c_client *i2c) int ret, value; if (!nau8325) { - nau8325 = devm_kzalloc(dev, sizeof(*nau8325), GFP_KERNEL); + nau8325 = devm_kzalloc_obj(dev, *nau8325); if (!nau8325) { ret = -ENOMEM; goto err; diff --git a/sound/soc/codecs/nau8360.c b/sound/soc/codecs/nau8360.c index f0942739d7abff..91256902729cf6 100644 --- a/sound/soc/codecs/nau8360.c +++ b/sound/soc/codecs/nau8360.c @@ -2227,7 +2227,7 @@ static int nau8360_i2c_probe(struct i2c_client *i2c) int num_total_regs; int ret, value; - nau8360 = devm_kzalloc(dev, sizeof(*nau8360), GFP_KERNEL); + nau8360 = devm_kzalloc_obj(dev, *nau8360); if (!nau8360) return -ENOMEM; diff --git a/sound/soc/codecs/nau8540.c b/sound/soc/codecs/nau8540.c index 09e7f31a904dde..dc6338085cf552 100644 --- a/sound/soc/codecs/nau8540.c +++ b/sound/soc/codecs/nau8540.c @@ -959,7 +959,7 @@ static int nau8540_i2c_probe(struct i2c_client *i2c) int ret, value; if (!nau8540) { - nau8540 = devm_kzalloc(dev, sizeof(*nau8540), GFP_KERNEL); + nau8540 = devm_kzalloc_obj(dev, *nau8540); if (!nau8540) return -ENOMEM; } diff --git a/sound/soc/codecs/nau8810.c b/sound/soc/codecs/nau8810.c index eb3e93380678c4..e18439c2b0e138 100644 --- a/sound/soc/codecs/nau8810.c +++ b/sound/soc/codecs/nau8810.c @@ -890,7 +890,7 @@ static int nau8810_i2c_probe(struct i2c_client *i2c) struct nau8810 *nau8810 = dev_get_platdata(dev); if (!nau8810) { - nau8810 = devm_kzalloc(dev, sizeof(*nau8810), GFP_KERNEL); + nau8810 = devm_kzalloc_obj(dev, *nau8810); if (!nau8810) return -ENOMEM; } diff --git a/sound/soc/codecs/nau8821.c b/sound/soc/codecs/nau8821.c index bfe922ae5efe39..7f1394983ee649 100644 --- a/sound/soc/codecs/nau8821.c +++ b/sound/soc/codecs/nau8821.c @@ -1957,7 +1957,7 @@ static int nau8821_i2c_probe(struct i2c_client *i2c) int ret, value; if (!nau8821) { - nau8821 = devm_kzalloc(dev, sizeof(*nau8821), GFP_KERNEL); + nau8821 = devm_kzalloc_obj(dev, *nau8821); if (!nau8821) return -ENOMEM; nau8821_read_device_properties(dev, nau8821); diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c index d91a0bed202527..17b8ee0ab22c33 100644 --- a/sound/soc/codecs/nau8822.c +++ b/sound/soc/codecs/nau8822.c @@ -1192,7 +1192,7 @@ static int nau8822_i2c_probe(struct i2c_client *i2c) int ret, i; if (!nau8822) { - nau8822 = devm_kzalloc(dev, sizeof(*nau8822), GFP_KERNEL); + nau8822 = devm_kzalloc_obj(dev, *nau8822); if (nau8822 == NULL) return -ENOMEM; } diff --git a/sound/soc/codecs/nau8824.c b/sound/soc/codecs/nau8824.c index f1d4ec0133edb2..45a06069056de0 100644 --- a/sound/soc/codecs/nau8824.c +++ b/sound/soc/codecs/nau8824.c @@ -2011,7 +2011,7 @@ static int nau8824_i2c_probe(struct i2c_client *i2c) int ret, value; if (!nau8824) { - nau8824 = devm_kzalloc(dev, sizeof(*nau8824), GFP_KERNEL); + nau8824 = devm_kzalloc_obj(dev, *nau8824); if (!nau8824) return -ENOMEM; ret = nau8824_read_device_properties(dev, nau8824); diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c index 3daa6d9a92b10d..03768e099e0e09 100644 --- a/sound/soc/codecs/nau8825.c +++ b/sound/soc/codecs/nau8825.c @@ -2902,7 +2902,7 @@ static int nau8825_i2c_probe(struct i2c_client *i2c) int ret, value; if (!nau8825) { - nau8825 = devm_kzalloc(dev, sizeof(*nau8825), GFP_KERNEL); + nau8825 = devm_kzalloc_obj(dev, *nau8825); if (!nau8825) return -ENOMEM; ret = nau8825_read_device_properties(dev, nau8825); diff --git a/sound/soc/codecs/ntp8835.c b/sound/soc/codecs/ntp8835.c index 2be713e99eaba4..fc2130fe767766 100644 --- a/sound/soc/codecs/ntp8835.c +++ b/sound/soc/codecs/ntp8835.c @@ -433,7 +433,7 @@ static int ntp8835_i2c_probe(struct i2c_client *i2c) struct regmap *regmap; int ret; - ntp8835 = devm_kzalloc(&i2c->dev, sizeof(*ntp8835), GFP_KERNEL); + ntp8835 = devm_kzalloc_obj(&i2c->dev, *ntp8835); if (!ntp8835) return -ENOMEM; diff --git a/sound/soc/codecs/ntp8918.c b/sound/soc/codecs/ntp8918.c index e851cfcca7c011..0845c8edf87ece 100644 --- a/sound/soc/codecs/ntp8918.c +++ b/sound/soc/codecs/ntp8918.c @@ -355,7 +355,7 @@ static int ntp8918_i2c_probe(struct i2c_client *i2c) int ret; struct regmap *regmap; - ntp8918 = devm_kzalloc(&i2c->dev, sizeof(*ntp8918), GFP_KERNEL); + ntp8918 = devm_kzalloc_obj(&i2c->dev, *ntp8918); if (!ntp8918) return -ENOMEM; diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c index 6002da3a56669f..2aae372389ad69 100644 --- a/sound/soc/codecs/pcm1681.c +++ b/sound/soc/codecs/pcm1681.c @@ -348,7 +348,7 @@ static int pcm1681_i2c_probe(struct i2c_client *client) int ret; struct pcm1681_private *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pcm1754.c b/sound/soc/codecs/pcm1754.c index bb15da1c24aa22..3d0708b7566c72 100644 --- a/sound/soc/codecs/pcm1754.c +++ b/sound/soc/codecs/pcm1754.c @@ -143,7 +143,7 @@ static int pcm1754_probe(struct platform_device *pdev) if (!dai_drv) return -ENOMEM; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pcm1789.c b/sound/soc/codecs/pcm1789.c index f06e353743aaa9..2d7cd829f7d3cb 100644 --- a/sound/soc/codecs/pcm1789.c +++ b/sound/soc/codecs/pcm1789.c @@ -242,8 +242,7 @@ int pcm1789_common_init(struct device *dev, struct regmap *regmap) { struct pcm1789_private *pcm1789; - pcm1789 = devm_kzalloc(dev, sizeof(struct pcm1789_private), - GFP_KERNEL); + pcm1789 = devm_kzalloc_obj(dev, struct pcm1789_private); if (!pcm1789) return -ENOMEM; diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c index cb70927872aa04..c9c4cebf92ccfa 100644 --- a/sound/soc/codecs/pcm179x.c +++ b/sound/soc/codecs/pcm179x.c @@ -219,8 +219,7 @@ int pcm179x_common_init(struct device *dev, struct regmap *regmap) { struct pcm179x_private *pcm179x; - pcm179x = devm_kzalloc(dev, sizeof(struct pcm179x_private), - GFP_KERNEL); + pcm179x = devm_kzalloc_obj(dev, struct pcm179x_private); if (!pcm179x) return -ENOMEM; diff --git a/sound/soc/codecs/pcm186x.c b/sound/soc/codecs/pcm186x.c index 461ec74e875212..9b0d953c033775 100644 --- a/sound/soc/codecs/pcm186x.c +++ b/sound/soc/codecs/pcm186x.c @@ -650,7 +650,7 @@ int pcm186x_probe(struct device *dev, enum pcm186x_type type, int irq, struct pcm186x_priv *priv; int i, ret; - priv = devm_kzalloc(dev, sizeof(struct pcm186x_priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct pcm186x_priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c index d3d2e7f40170c8..c6d4d300bef672 100644 --- a/sound/soc/codecs/pcm3008.c +++ b/sound/soc/codecs/pcm3008.c @@ -114,7 +114,7 @@ static int pcm3008_codec_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct pcm3008 *pcm; - pcm = devm_kzalloc(dev, sizeof(*pcm), GFP_KERNEL); + pcm = devm_kzalloc_obj(dev, *pcm); if (!pcm) return -ENOMEM; platform_set_drvdata(pdev, pcm); diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c index 3816b25a8ead79..0d7ce3c35624fd 100644 --- a/sound/soc/codecs/pcm3060-i2c.c +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -14,7 +14,7 @@ static int pcm3060_i2c_probe(struct i2c_client *i2c) { struct pcm3060_priv *priv; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pcm3060-spi.c b/sound/soc/codecs/pcm3060-spi.c index 6095841f2f56f6..e9d04892bbd85f 100644 --- a/sound/soc/codecs/pcm3060-spi.c +++ b/sound/soc/codecs/pcm3060-spi.c @@ -14,7 +14,7 @@ static int pcm3060_spi_probe(struct spi_device *spi) { struct pcm3060_priv *priv; - priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&spi->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index 1b96835600b45b..0d7b677837b7a6 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -34,7 +34,6 @@ struct pcm3060_priv { }; int pcm3060_probe(struct device *dev); -int pcm3060_remove(struct device *dev); /* registers */ diff --git a/sound/soc/codecs/pcm3168a.c b/sound/soc/codecs/pcm3168a.c index c1a263216ea6d8..f64e57b8401e20 100644 --- a/sound/soc/codecs/pcm3168a.c +++ b/sound/soc/codecs/pcm3168a.c @@ -718,7 +718,7 @@ int pcm3168a_probe(struct device *dev, struct regmap *regmap) struct pcm3168a_priv *pcm3168a; int ret, i; - pcm3168a = devm_kzalloc(dev, sizeof(*pcm3168a), GFP_KERNEL); + pcm3168a = devm_kzalloc_obj(dev, *pcm3168a); if (pcm3168a == NULL) return -ENOMEM; @@ -797,6 +797,7 @@ int pcm3168a_probe(struct device *dev, struct regmap *regmap) ARRAY_SIZE(pcm3168a->dai_drv)); if (ret) { dev_err(dev, "failed to register component: %d\n", ret); + pm_runtime_disable(dev); goto err_regulator; } diff --git a/sound/soc/codecs/pcm5102a.c b/sound/soc/codecs/pcm5102a.c index ed1e29e54ef8b4..9db9a0d40a0b7b 100644 --- a/sound/soc/codecs/pcm5102a.c +++ b/sound/soc/codecs/pcm5102a.c @@ -40,7 +40,7 @@ static int pcm5102a_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct pcm5102a_priv *pcm5102a; - pcm5102a = devm_kzalloc(dev, sizeof(*pcm5102a), GFP_KERNEL); + pcm5102a = devm_kzalloc_obj(dev, *pcm5102a); if (!pcm5102a) return -ENOMEM; diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 24194a8ec1a9f7..f6f07de133c478 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -31,6 +32,7 @@ static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = { struct pcm512x_priv { struct regmap *regmap; + struct gpio_desc *mute_gpio; struct clk *sclk; struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES]; struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES]; @@ -601,12 +603,11 @@ static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream, SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); - constraints_no_pll = devm_kzalloc(dev, sizeof(*constraints_no_pll), - GFP_KERNEL); + constraints_no_pll = devm_kzalloc_obj(dev, *constraints_no_pll); if (!constraints_no_pll) return -ENOMEM; constraints_no_pll->nrats = 1; - rats_no_pll = devm_kzalloc(dev, sizeof(*rats_no_pll), GFP_KERNEL); + rats_no_pll = devm_kzalloc_obj(dev, *rats_no_pll); if (!rats_no_pll) return -ENOMEM; constraints_no_pll->rats = rats_no_pll; @@ -1464,6 +1465,7 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction) guard(mutex)(&pcm512x->mutex); if (mute) { + gpiod_set_value_cansleep(pcm512x->mute_gpio, 1); pcm512x->mute |= 0x1; ret = regmap_update_bits(pcm512x->regmap, PCM512x_MUTE, PCM512x_RQML | PCM512x_RQMR, @@ -1487,6 +1489,8 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction) return ret; } + gpiod_set_value_cansleep(pcm512x->mute_gpio, 0); + regmap_read_poll_timeout(pcm512x->regmap, PCM512x_ANALOG_MUTE_DET, mute_det, @@ -1574,7 +1578,7 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap) struct pcm512x_priv *pcm512x; int i, ret; - pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL); + pcm512x = devm_kzalloc_obj(dev, struct pcm512x_priv); if (!pcm512x) return -ENOMEM; @@ -1582,6 +1586,10 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap) dev_set_drvdata(dev, pcm512x); pcm512x->regmap = regmap; + pcm512x->mute_gpio = devm_gpiod_get_optional(dev, "mute", GPIOD_OUT_HIGH); + if (IS_ERR(pcm512x->mute_gpio)) + return dev_err_probe(dev, PTR_ERR(pcm512x->mute_gpio), + "Failed to get mute GPIO\n"); for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) pcm512x->supplies[i].supply = pcm512x_supply_names[i]; diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c index db70a33d14b8dd..5c129b5c7814dd 100644 --- a/sound/soc/codecs/pcm6240.c +++ b/sound/soc/codecs/pcm6240.c @@ -1346,8 +1346,8 @@ static int pcmdev_gain_ctrl_add(struct pcmdevice_priv *pcm_dev, return 0; } - pcmdev_controls = devm_kcalloc(pcm_dev->dev, nr_chn, - sizeof(struct snd_kcontrol_new), GFP_KERNEL); + pcmdev_controls = devm_kzalloc_objs(pcm_dev->dev, + struct snd_kcontrol_new, nr_chn); if (!pcmdev_controls) return -ENOMEM; @@ -1407,8 +1407,7 @@ static int pcmdev_profile_ctrl_add(struct pcmdevice_priv *pcm_dev) char *name; int ret; - pcmdev_ctrl = devm_kzalloc(pcm_dev->dev, - sizeof(struct snd_kcontrol_new), GFP_KERNEL); + pcmdev_ctrl = devm_kzalloc_obj(pcm_dev->dev, struct snd_kcontrol_new); if (!pcmdev_ctrl) return -ENOMEM; @@ -2044,7 +2043,7 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c) unsigned int dev_addrs[PCMDEVICE_MAX_I2C_DEVICES]; int ret = 0, i = 0, ndev = 0; - pcm_dev = devm_kzalloc(&i2c->dev, sizeof(*pcm_dev), GFP_KERNEL); + pcm_dev = devm_kzalloc_obj(&i2c->dev, *pcm_dev); if (!pcm_dev) return -ENOMEM; diff --git a/sound/soc/codecs/peb2466.c b/sound/soc/codecs/peb2466.c index f1ded68c2d7563..c9b8a459c7950a 100644 --- a/sound/soc/codecs/peb2466.c +++ b/sound/soc/codecs/peb2466.c @@ -1959,7 +1959,7 @@ static int peb2466_spi_probe(struct spi_device *spi) if (ret < 0) return ret; - peb2466 = devm_kzalloc(&spi->dev, sizeof(*peb2466), GFP_KERNEL); + peb2466 = devm_kzalloc_obj(&spi->dev, *peb2466); if (!peb2466) return -ENOMEM; diff --git a/sound/soc/codecs/pm4125-sdw.c b/sound/soc/codecs/pm4125-sdw.c index 182ff396301a58..c279bf0a88b11d 100644 --- a/sound/soc/codecs/pm4125-sdw.c +++ b/sound/soc/codecs/pm4125-sdw.c @@ -353,7 +353,7 @@ static int pm4125_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) int master_ch_mask_size = 0; int ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/pm4125.c b/sound/soc/codecs/pm4125.c index 674a2fbc4edae7..22fada77b2740a 100644 --- a/sound/soc/codecs/pm4125.c +++ b/sound/soc/codecs/pm4125.c @@ -1650,7 +1650,7 @@ static int pm4125_probe(struct platform_device *pdev) struct wcd_mbhc_config *cfg; int ret; - pm4125 = devm_kzalloc(dev, sizeof(*pm4125), GFP_KERNEL); + pm4125 = devm_kzalloc_obj(dev, *pm4125); if (!pm4125) return -ENOMEM; diff --git a/sound/soc/codecs/pm4125.h b/sound/soc/codecs/pm4125.h index 25fd3106f44f4b..f2946b70c68d2a 100644 --- a/sound/soc/codecs/pm4125.h +++ b/sound/soc/codecs/pm4125.h @@ -221,26 +221,10 @@ struct pm4125_sdw_priv { }; #if IS_ENABLED(CONFIG_SND_SOC_PM4125_SDW) -int pm4125_sdw_free(struct pm4125_sdw_priv *pm4125, struct snd_pcm_substream *substream, - struct snd_soc_dai *dai); -int pm4125_sdw_set_sdw_stream(struct pm4125_sdw_priv *pm4125, struct snd_soc_dai *dai, void *stream, - int direction); int pm4125_sdw_hw_params(struct pm4125_sdw_priv *pm4125, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); #else -static inline int pm4125_sdw_free(struct pm4125_sdw_priv *pm4125, - struct snd_pcm_substream *substream, struct snd_soc_dai *dai) -{ - return -EOPNOTSUPP; -} - -static inline int pm4125_sdw_set_sdw_stream(struct pm4125_sdw_priv *pm4125, - struct snd_soc_dai *dai, void *stream, int direction) -{ - return -EOPNOTSUPP; -} - static inline int pm4125_sdw_hw_params(struct pm4125_sdw_priv *pm4125, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) diff --git a/sound/soc/codecs/rk3308_codec.c b/sound/soc/codecs/rk3308_codec.c index a3d41cd8150d05..9cb327f5155d67 100644 --- a/sound/soc/codecs/rk3308_codec.c +++ b/sound/soc/codecs/rk3308_codec.c @@ -1012,7 +1012,7 @@ static int rk3308_codec_platform_probe(struct platform_device *pdev) void __iomem *base; int err; - rk3308 = devm_kzalloc(&pdev->dev, sizeof(*rk3308), GFP_KERNEL); + rk3308 = devm_kzalloc_obj(&pdev->dev, *rk3308); if (!rk3308) return -ENOMEM; diff --git a/sound/soc/codecs/rk3328_codec.c b/sound/soc/codecs/rk3328_codec.c index c2798ee9405938..cc2e70a3a5594e 100644 --- a/sound/soc/codecs/rk3328_codec.c +++ b/sound/soc/codecs/rk3328_codec.c @@ -435,7 +435,7 @@ static int rk3328_platform_probe(struct platform_device *pdev) struct regmap *grf; void __iomem *base; - rk3328 = devm_kzalloc(&pdev->dev, sizeof(*rk3328), GFP_KERNEL); + rk3328 = devm_kzalloc_obj(&pdev->dev, *rk3328); if (!rk3328) return -ENOMEM; diff --git a/sound/soc/codecs/rk817_codec.c b/sound/soc/codecs/rk817_codec.c index 3c9957b008810d..2c0fe1dfd842c6 100644 --- a/sound/soc/codecs/rk817_codec.c +++ b/sound/soc/codecs/rk817_codec.c @@ -475,9 +475,7 @@ static int rk817_platform_probe(struct platform_device *pdev) struct rk817_codec_priv *rk817_codec_data; int ret; - rk817_codec_data = devm_kzalloc(&pdev->dev, - sizeof(struct rk817_codec_priv), - GFP_KERNEL); + rk817_codec_data = devm_kzalloc_obj(&pdev->dev, struct rk817_codec_priv); if (!rk817_codec_data) return -ENOMEM; diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c index dda38e6e56b6d5..a46c6bc3019bcf 100644 --- a/sound/soc/codecs/rt1011.c +++ b/sound/soc/codecs/rt1011.c @@ -2053,16 +2053,14 @@ static int rt1011_probe(struct snd_soc_component *component) schedule_work(&rt1011->cali_work); rt1011->i2s_ref = 0; - rt1011->bq_drc_params = kcalloc(RT1011_ADVMODE_NUM, - sizeof(struct rt1011_bq_drc_params *), - GFP_KERNEL); + rt1011->bq_drc_params = kzalloc_objs(struct rt1011_bq_drc_params *, + RT1011_ADVMODE_NUM); if (!rt1011->bq_drc_params) return -ENOMEM; for (i = 0; i < RT1011_ADVMODE_NUM; i++) { - rt1011->bq_drc_params[i] = kcalloc(RT1011_BQ_DRC_NUM, - sizeof(struct rt1011_bq_drc_params), - GFP_KERNEL); + rt1011->bq_drc_params[i] = kzalloc_objs(struct rt1011_bq_drc_params, + RT1011_BQ_DRC_NUM); if (!rt1011->bq_drc_params[i]) goto err; } @@ -2454,8 +2452,7 @@ static int rt1011_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt1011 = devm_kzalloc(&i2c->dev, sizeof(struct rt1011_priv), - GFP_KERNEL); + rt1011 = devm_kzalloc_obj(&i2c->dev, struct rt1011_priv); if (!rt1011) return -ENOMEM; diff --git a/sound/soc/codecs/rt1015.c b/sound/soc/codecs/rt1015.c index 5d6be7cc67b44d..8de8c6eb8b0e9d 100644 --- a/sound/soc/codecs/rt1015.c +++ b/sound/soc/codecs/rt1015.c @@ -1187,7 +1187,7 @@ static int rt1015_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt1015 = devm_kzalloc(&i2c->dev, sizeof(*rt1015), GFP_KERNEL); + rt1015 = devm_kzalloc_obj(&i2c->dev, *rt1015); if (!rt1015) return -ENOMEM; diff --git a/sound/soc/codecs/rt1015p.c b/sound/soc/codecs/rt1015p.c index 44e7fe3c32da56..3bd48b7c8b59cf 100644 --- a/sound/soc/codecs/rt1015p.c +++ b/sound/soc/codecs/rt1015p.c @@ -106,7 +106,7 @@ static int rt1015p_platform_probe(struct platform_device *pdev) { struct rt1015p_priv *rt1015p; - rt1015p = devm_kzalloc(&pdev->dev, sizeof(*rt1015p), GFP_KERNEL); + rt1015p = devm_kzalloc_obj(&pdev->dev, *rt1015p); if (!rt1015p) return -ENOMEM; diff --git a/sound/soc/codecs/rt1016.c b/sound/soc/codecs/rt1016.c index 1e97d9ffa3528f..fc92e6f29168cb 100644 --- a/sound/soc/codecs/rt1016.c +++ b/sound/soc/codecs/rt1016.c @@ -643,8 +643,7 @@ static int rt1016_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt1016 = devm_kzalloc(&i2c->dev, sizeof(struct rt1016_priv), - GFP_KERNEL); + rt1016 = devm_kzalloc_obj(&i2c->dev, struct rt1016_priv); if (rt1016 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt1017-sdca-sdw.c b/sound/soc/codecs/rt1017-sdca-sdw.c index 01cc2511a7d073..78ad4a56686529 100644 --- a/sound/soc/codecs/rt1017-sdca-sdw.c +++ b/sound/soc/codecs/rt1017-sdca-sdw.c @@ -276,8 +276,8 @@ static int rt1017_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(1); /* BITMAP: 00000010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -294,8 +294,8 @@ static int rt1017_sdca_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -693,7 +693,7 @@ static int rt1017_sdca_init(struct device *dev, struct regmap *regmap, struct rt1017_sdca_priv *rt1017; int ret; - rt1017 = devm_kzalloc(dev, sizeof(*rt1017), GFP_KERNEL); + rt1017 = devm_kzalloc_obj(dev, *rt1017); if (!rt1017) return -ENOMEM; diff --git a/sound/soc/codecs/rt1019.c b/sound/soc/codecs/rt1019.c index 3998abccd93a86..56605a018c0cd4 100644 --- a/sound/soc/codecs/rt1019.c +++ b/sound/soc/codecs/rt1019.c @@ -575,8 +575,7 @@ static int rt1019_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val, val2, dev_id; - rt1019 = devm_kzalloc(&i2c->dev, sizeof(struct rt1019_priv), - GFP_KERNEL); + rt1019 = devm_kzalloc_obj(&i2c->dev, struct rt1019_priv); if (!rt1019) return -ENOMEM; diff --git a/sound/soc/codecs/rt1305.c b/sound/soc/codecs/rt1305.c index 0130ff9f050d27..d219e5442ab956 100644 --- a/sound/soc/codecs/rt1305.c +++ b/sound/soc/codecs/rt1305.c @@ -1128,8 +1128,7 @@ static int rt1305_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt1305 = devm_kzalloc(&i2c->dev, sizeof(struct rt1305_priv), - GFP_KERNEL); + rt1305 = devm_kzalloc_obj(&i2c->dev, struct rt1305_priv); if (rt1305 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c index 2f30497498c7e6..e8c85877b25d42 100644 --- a/sound/soc/codecs/rt1308-sdw.c +++ b/sound/soc/codecs/rt1308-sdw.c @@ -138,9 +138,8 @@ static int rt1308_read_prop(struct sdw_slave *slave) /* for sink */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -681,7 +680,7 @@ static int rt1308_sdw_init(struct device *dev, struct regmap *regmap, struct rt1308_sdw_priv *rt1308; int ret; - rt1308 = devm_kzalloc(dev, sizeof(*rt1308), GFP_KERNEL); + rt1308 = devm_kzalloc_obj(dev, *rt1308); if (!rt1308) return -ENOMEM; diff --git a/sound/soc/codecs/rt1308.c b/sound/soc/codecs/rt1308.c index 3d4aadb91206d7..dd6665d477d6aa 100644 --- a/sound/soc/codecs/rt1308.c +++ b/sound/soc/codecs/rt1308.c @@ -825,8 +825,7 @@ static int rt1308_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt1308 = devm_kzalloc(&i2c->dev, sizeof(struct rt1308_priv), - GFP_KERNEL); + rt1308 = devm_kzalloc_obj(&i2c->dev, struct rt1308_priv); if (rt1308 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt1316-sdw.c b/sound/soc/codecs/rt1316-sdw.c index 2ef47a82c984b5..1e33b6d38226ff 100644 --- a/sound/soc/codecs/rt1316-sdw.c +++ b/sound/soc/codecs/rt1316-sdw.c @@ -211,8 +211,8 @@ static int rt1316_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x2; /* BITMAP: 00000010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -229,8 +229,8 @@ static int rt1316_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -658,7 +658,7 @@ static int rt1316_sdw_init(struct device *dev, struct regmap *regmap, struct rt1316_sdw_priv *rt1316; int ret; - rt1316 = devm_kzalloc(dev, sizeof(*rt1316), GFP_KERNEL); + rt1316 = devm_kzalloc_obj(dev, *rt1316); if (!rt1316) return -ENOMEM; diff --git a/sound/soc/codecs/rt1318-sdw.c b/sound/soc/codecs/rt1318-sdw.c index f9ba1626981750..f2b98eb16d636b 100644 --- a/sound/soc/codecs/rt1318-sdw.c +++ b/sound/soc/codecs/rt1318-sdw.c @@ -361,8 +361,8 @@ static int rt1318_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(1); nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -379,8 +379,8 @@ static int rt1318_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -725,7 +725,7 @@ static int rt1318_sdw_init(struct device *dev, struct regmap *regmap, struct rt1318_sdw_priv *rt1318; int ret; - rt1318 = devm_kzalloc(dev, sizeof(*rt1318), GFP_KERNEL); + rt1318 = devm_kzalloc_obj(dev, *rt1318); if (!rt1318) return -ENOMEM; diff --git a/sound/soc/codecs/rt1318.c b/sound/soc/codecs/rt1318.c index 5c80957b0f0151..4f90c5a0ebde62 100644 --- a/sound/soc/codecs/rt1318.c +++ b/sound/soc/codecs/rt1318.c @@ -1304,8 +1304,7 @@ static int rt1318_i2c_probe(struct i2c_client *i2c) struct rt1318_priv *rt1318; int ret, val, val2, dev_id; - rt1318 = devm_kzalloc(&i2c->dev, sizeof(struct rt1318_priv), - GFP_KERNEL); + rt1318 = devm_kzalloc_obj(&i2c->dev, struct rt1318_priv); if (!rt1318) return -ENOMEM; diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c index fa89db09665149..19079212ba6c04 100644 --- a/sound/soc/codecs/rt1320-sdw.c +++ b/sound/soc/codecs/rt1320-sdw.c @@ -578,6 +578,48 @@ static const struct reg_sequence rt1321_va1_blind_write[] = { }; static const struct reg_sequence rt1321_va2_blind_write[] = { + { 0x0000c570, 0x0a }, + { 0x0000d486, 0x80 }, + { 0x0000c040, 0x00 }, + { 0x0000c041, 0x00 }, + { 0x0000c042, 0x00 }, + { 0x0000c043, 0x00 }, + { 0x0000c044, 0xe0 }, + { 0x0000c045, 0x00 }, + { 0x0000c046, 0x00 }, + { 0x0000c054, 0x53 }, + { 0x0000c057, 0x55 }, + { 0x0000c081, 0xca }, + { 0x0000c5c3, 0x02 }, + { 0x0000c5fb, 0x02 }, + { 0x0000c600, 0x04 }, + { 0x0000c601, 0x83 }, + { 0x0000c604, 0x30 }, + { 0x0000c609, 0x42 }, + { 0x0000ce44, 0x0c }, + { 0x0000ce1a, 0x88 }, + { 0x0000cf02, 0x00 }, + { 0x0000d470, 0x00 }, + { 0x0000d471, 0x00 }, + { 0x0000d487, 0x03 }, + { 0x0000d540, 0x00 }, + { 0x0000d73c, 0x00 }, + { 0x0000d73d, 0x00 }, + { 0x0000d73e, 0x00 }, + { 0x0000d73f, 0x00 }, + { 0x0000de00, 0x2f }, + { 0x0000de02, 0x0e }, + { 0x0000de03, 0x01 }, + { 0x0000de04, 0x00 }, + { 0x0000de05, 0x00 }, + { 0x0000c019, 0x00 }, + { 0x0000c01a, 0x01 }, + { 0x0000c01b, 0xfc }, + { 0x0000c500, 0x00 }, + { 0x0000c680, 0x80 }, + { 0x0000c681, 0x08 }, + { 0x0000c500, 0x01 }, + { 0x0000c003, 0x20 }, { 0x0000c003, 0xf0 }, { 0x0000c01b, 0xfc }, { 0x0000c5c3, 0xf2 }, @@ -595,7 +637,7 @@ static const struct reg_sequence rt1321_va2_blind_write[] = { { 0x0000c5c8, 0x03 }, { 0x0000c5d3, 0x08 }, { 0x0000c5d2, 0x0a }, - { 0x0000c5d1, 0x49 }, + { 0x0000c5d1, 0x46 }, { 0x0000c5d0, 0x0f }, { 0x0000c580, 0x10 }, { 0x0000c581, 0x32 }, @@ -657,19 +699,24 @@ static const struct reg_sequence rt1321_va2_blind_write[] = { { 0x0000f082, 0xff }, { 0x0000f081, 0xff }, { 0x0000f080, 0xff }, + { 0x20003000, 0x00 }, + { 0x20003001, 0x10 }, + { 0x20005800, 0x00 }, + { 0x20009000, 0x00 }, { 0x20003003, 0x3f }, + { 0x20009003, 0x3f }, { 0x20005818, 0x81 }, { 0x20009018, 0x81 }, { 0x2000301c, 0x81 }, { 0x0000c003, 0xc0 }, - { 0x0000c047, 0x80 }, { 0x0000d541, 0x80 }, { 0x0000d487, 0x0b }, { 0x0000d487, 0x3b }, { 0x0000d486, 0xc3 }, { 0x0000d470, 0x89 }, { 0x0000d471, 0x3a }, - { 0x0000d472, 0x3d }, + { 0x0000d472, 0x7d }, + { 0x0000d473, 0x01 }, { 0x0000d474, 0x11 }, { 0x0000d475, 0x32 }, { 0x0000d476, 0x64 }, @@ -681,101 +728,34 @@ static const struct reg_sequence rt1321_va2_blind_write[] = { { 0x10008001, 0x80 }, { 0x10008002, 0x00 }, { 0x10008003, 0x00 }, + { 0x0000d73c, 0xb7 }, + { 0x0000d73d, 0xd7 }, + { 0x0000d73e, 0x00 }, + { 0x0000d73f, 0x10 }, { 0x1000cd56, 0x00 }, + { 0x0000d541, 0x40 }, { 0x0000d486, 0x43 }, - { 0x3fc2dfc3, 0x00 }, - { 0x3fc2dfc2, 0x00 }, + { 0x3fc2dfc0, 0x0b }, { 0x3fc2dfc1, 0x00 }, - { 0x3fc2dfc0, 0x03 }, - { 0x3fc2dfc7, 0x00 }, - { 0x3fc2dfc6, 0x00 }, - { 0x3fc2dfc5, 0x00 }, + { 0x3fc2dfc2, 0x00 }, + { 0x3fc2dfc3, 0x00 }, { 0x3fc2dfc4, 0x01 }, - { 0x3fc2dfa3, 0x00 }, - { 0x3fc2dfa2, 0x00 }, - { 0x3fc2dfa1, 0x00 }, + { 0x3fc2dfc5, 0x00 }, + { 0x3fc2dfc6, 0x00 }, + { 0x3fc2dfc7, 0x00 }, + { 0x3fc2dfcc, 0x00 }, + { 0x3fc2dfcd, 0x00 }, + { 0x3fc2dfce, 0x54 }, + { 0x3fc2dfcf, 0x05 }, { 0x3fc2dfa0, 0x00 }, - { 0x3fc2df80, 0x10 }, - { 0x3fc2df81, 0x20 }, - { 0x3fc2df82, 0x00 }, - { 0x3fc2df83, 0x00 }, - { 0x3fc2df84, 0x50 }, - { 0x3fc2df85, 0x19 }, - { 0x3fc2df86, 0x00 }, - { 0x3fc2df87, 0x00 }, - { 0x3fc2df88, 0x52 }, - { 0x3fc2df89, 0x23 }, - { 0x3fc2df8a, 0x00 }, - { 0x3fc2df8b, 0x00 }, - { 0x3fc2df8c, 0xe0 }, - { 0x3fc2df8d, 0x2e }, - { 0x3fc2df8e, 0x00 }, - { 0x3fc2df8f, 0x00 }, - { 0x3fc2df90, 0xe0 }, - { 0x3fc2df91, 0x2e }, - { 0x3fc2df92, 0x00 }, - { 0x3fc2df93, 0x00 }, - { 0x3fc2df94, 0x01 }, - { 0x3fc2df95, 0x08 }, - { 0x3fc2df96, 0x00 }, - { 0x3fc2df97, 0x00 }, - { 0x3fc2df40, 0x80 }, - { 0x3fc2df41, 0xbb }, - { 0x3fc2df42, 0x00 }, - { 0x3fc2df43, 0x00 }, - { 0x3fc2df44, 0xc0 }, - { 0x3fc2df45, 0x99 }, - { 0x3fc2df46, 0x01 }, - { 0x3fc2df47, 0x00 }, - { 0x3fc2df48, 0x00 }, - { 0x3fc2df49, 0x00 }, - { 0x3fc2df4a, 0x00 }, - { 0x3fc2df4b, 0x00 }, - { 0x3fc2df4c, 0x00 }, - { 0x3fc2df4d, 0x00 }, - { 0x3fc2df4e, 0x00 }, - { 0x3fc2df4f, 0x00 }, - { 0x3fc2df50, 0x01 }, - { 0x3fc2df51, 0x00 }, - { 0x3fc2df52, 0x00 }, - { 0x3fc2df53, 0x00 }, - { 0x3fc2df54, 0x01 }, - { 0x3fc2df55, 0x00 }, - { 0x3fc2df56, 0x00 }, - { 0x3fc2df57, 0x00 }, - { 0x3fc2df58, 0x00 }, - { 0x3fc2df59, 0x00 }, - { 0x3fc2df5a, 0x00 }, - { 0x3fc2df5b, 0x00 }, - { 0x3fc2df5c, 0x01 }, - { 0x3fc2df5d, 0x00 }, - { 0x3fc2df5e, 0x00 }, - { 0x3fc2df5f, 0x00 }, - { 0x3fc2df60, 0x00 }, - { 0x3fc2df61, 0x00 }, - { 0x3fc2df62, 0x00 }, - { 0x3fc2df63, 0x00 }, - { 0x3fc2df64, 0x00 }, - { 0x3fc2df65, 0x00 }, - { 0x3fc2df66, 0x00 }, - { 0x3fc2df67, 0x10 }, - { 0x3fc2df68, 0x01 }, - { 0x3fc2df69, 0x00 }, - { 0x3fc2df6a, 0x00 }, - { 0x3fc2df6b, 0x00 }, - { 0x3fc2df6c, 0x01 }, - { 0x3fc2df6d, 0x00 }, - { 0x3fc2df6e, 0x00 }, - { 0x3fc2df6f, 0x00 }, - { 0x3fc2df70, 0x04 }, - { 0x3fc2df71, 0x00 }, - { 0x3fc2df72, 0x00 }, - { 0x3fc2df73, 0x00 }, - { 0x3fc2df74, 0x01 }, - { 0x3fc2df75, 0x00 }, - { 0x3fc2df76, 0x00 }, - { 0x3fc2df77, 0x00 }, - { 0x1000db00, 0x04 }, + { 0x3fc2dfa1, 0x00 }, + { 0x3fc2dfa2, 0x00 }, + { 0x3fc2dfa3, 0x00 }, + { 0x3fc2dfd0, 0x00 }, + { 0x3fc2dfd1, 0x00 }, + { 0x3fc2dfd2, 0x00 }, + { 0x3fc2dfd3, 0x00 }, + { 0x1000db00, 0x07 }, { 0x1000db01, 0x00 }, { 0x1000db02, 0x10 }, { 0x1000db03, 0x00 }, @@ -796,14 +776,48 @@ static const struct reg_sequence rt1321_va2_blind_write[] = { { 0x1000db12, 0x00 }, { 0x1000db13, 0x00 }, { 0x1000db14, 0x09 }, + { 0x1000db15, 0x00 }, + { 0x1000db16, 0x0f }, + { 0x1000db17, 0x00 }, + { 0x1000db18, 0x00 }, + { 0x1000db19, 0x80 }, + { 0x1000db1a, 0x21 }, + { 0x1000db1b, 0xfa }, + { 0x1000db1c, 0x00 }, + { 0x1000db1d, 0x00 }, + { 0x1000db1e, 0x06 }, + { 0x1000db1f, 0x23 }, + { 0x1000db20, 0xfa }, + { 0x1000db21, 0x00 }, + { 0x1000db22, 0x00 }, + { 0x1000db23, 0x0e }, { 0x0000d540, 0x21 }, + { 0x0000c570, 0x08 }, { 0x0000d714, 0x17 }, - { 0x0000dd0b, 0x0d }, - { 0x0000dd0a, 0xff }, - { 0x0000dd09, 0x0d }, + { 0x0000c5fb, 0x52 }, + { 0x0000c5c3, 0xf2 }, + { 0x0000c5c8, 0x03 }, { 0x0000dd08, 0xff }, - { 0x0000c5fb, 0x12 }, + { 0x0000dd09, 0x0d }, + { 0x0000dd0a, 0xff }, + { 0x0000dd0b, 0x0d }, { 0x0000c570, 0x08 }, + { 0x0000d471, 0x3b }, + { 0x0000db00, 0x00 }, + { 0x0000db01, 0x00 }, + { 0x0000db02, 0x73 }, + { 0x0000db03, 0x00 }, + { 0x0000db04, 0x00 }, + { 0x0000db05, 0x00 }, + { 0x0000db06, 0x00 }, + { 0x0000db07, 0x00 }, + { 0x0000db08, 0x7f }, + { 0x0000db09, 0x00 }, + { 0x0000db1a, 0x00 }, + { 0x0000db1b, 0x00 }, + { 0x0000db19, 0x00 }, + { 0x0000c04c, 0xe2 }, + { 0x0000c068, 0x35 }, }; static const struct reg_default rt1320_reg_defaults[] = { @@ -904,7 +918,7 @@ static bool rt1320_readable_register(struct device *dev, unsigned int reg) case 0x20009000 ... 0x2000900f: case 0x20009018: case 0x20009040 ... 0x20009059: - case 0x3fc000c0 ... 0x3fc2dfc8: + case 0x3fc000c0 ... 0x3fc2dfcb: case 0x3fe00000 ... 0x3fe36fff: /* 0x40801508/0x40801809/0x4080180a/0x40801909/0x4080190a */ case SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_PDE11, RT1320_SDCA_CTL_REQ_POWER_STATE, 0): @@ -1013,9 +1027,9 @@ static bool rt1320_volatile_register(struct device *dev, unsigned int reg) case 0x3fc2ab80 ... 0x3fc2ac4c: case 0x3fc2b780: case 0x3fc2bf80 ... 0x3fc2bf83: - case 0x3fc2bfc0 ... 0x3fc2bfc8: + case 0x3fc2bfc0 ... 0x3fc2bfcb: case 0x3fc2d300 ... 0x3fc2d3cc: - case 0x3fc2dfc0 ... 0x3fc2dfc8: + case 0x3fc2dfc0 ... 0x3fc2dfcb: case 0x3fe2e000 ... 0x3fe2e003: case SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_PDE11, RT1320_SDCA_CTL_ACTUAL_POWER_STATE, 0): case SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT0, RT1320_SDCA_CTL_FUNC_STATUS, 0): @@ -1094,8 +1108,8 @@ static int rt1320_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(1); nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -1112,8 +1126,8 @@ static int rt1320_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -1128,7 +1142,7 @@ static int rt1320_read_prop(struct sdw_slave *slave) j++; } - prop->dp0_prop = devm_kzalloc(&slave->dev, sizeof(*prop->dp0_prop), GFP_KERNEL); + prop->dp0_prop = devm_kzalloc_obj(&slave->dev, *prop->dp0_prop); if (!prop->dp0_prop) return -ENOMEM; @@ -1270,7 +1284,9 @@ static void rt1320_pr_read(struct rt1320_sdw_priv *rt1320, unsigned int reg, uns static int rt1320_check_fw_ready(struct rt1320_sdw_priv *rt1320) { struct device *dev = &rt1320->sdw_slave->dev; - unsigned int tmp, retry = 0; + bool is_va2 = rt1320->dev_id == RT1321_DEV_ID && + rt1320->version_id == RT1321_VA2; + unsigned int tmp, retry = 0, i; unsigned int cmd_addr; switch (rt1320->dev_id) { @@ -1289,8 +1305,16 @@ static int rt1320_check_fw_ready(struct rt1320_sdw_priv *rt1320) /* check the value of cmd_addr becomes to zero */ while (retry < 500) { regmap_read(rt1320->regmap, cmd_addr, &tmp); - if (tmp == 0) + if (tmp == RT1320_FW_READY) break; + + if (is_va2 && tmp > RT1320_GET_POOLSIZE) { + dev_warn(dev, "%s: invalid cmd id 0x%x, clear the command area\n", + __func__, tmp); + for (i = 0; i < RT1320_FW_CMD_HDR_SIZE; i++) + regmap_write(rt1320->regmap, RT1321_FW_PARAM_ADDR + i, 0x00); + return 0; + } usleep_range(1000, 1100); retry++; } @@ -1338,21 +1362,24 @@ static int rt1320_dspfw_status(struct rt1320_sdw_priv *rt1320) return 0; } -static int rt1320_check_power_state_ready(struct rt1320_sdw_priv *rt1320, enum rt1320_power_state ps) +static int rt1320_poll_power_state(struct rt1320_sdw_priv *rt1320, + enum rt1320_power_state ps, + unsigned int retries, + unsigned int sleep_us) { struct device *dev = &rt1320->sdw_slave->dev; unsigned int retry = 0, tmp; pm_runtime_mark_last_busy(dev); - while (retry < 200) { + while (retry < retries) { regmap_read(rt1320->regmap, RT1320_POWER_STATE, &tmp); dev_dbg(dev, "%s, RT1320_POWER_STATE=0x%x\n", __func__, tmp); if (tmp >= ps) break; - usleep_range(1000, 1500); + usleep_range(sleep_us, sleep_us + sleep_us / 2); retry++; } - if (retry == 200) { + if (retry == retries) { dev_warn(dev, "%s FW Power State is NOT ready!", __func__); return -ETIMEDOUT; } @@ -1360,6 +1387,13 @@ static int rt1320_check_power_state_ready(struct rt1320_sdw_priv *rt1320, enum r return 0; } +static int rt1320_check_power_state_ready(struct rt1320_sdw_priv *rt1320, + enum rt1320_power_state ps) +{ + return rt1320_poll_power_state(rt1320, ps, RT1320_PS_RETRY, + RT1320_PS_SLEEP_US); +} + static int rt1320_process_fw_param(struct rt1320_sdw_priv *rt1320, unsigned char *buf, unsigned int buf_size) { struct device *dev = &rt1320->sdw_slave->dev; @@ -1456,38 +1490,56 @@ static int rt1320_fw_param_protocol(struct rt1320_sdw_priv *rt1320, enum rt1320_ return ret; } -static void rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320) +static int rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320) { struct device *dev = &rt1320->sdw_slave->dev; - struct rt1320_datafixpoint r0_data[2]; + struct rt1320_datafixpoint r0_data[2] = {}; + FwPara_Get_HwSwGain hwswgain = {}; unsigned short l_advancegain, r_advancegain; - FwPara_Get_HwSwGain audDriverDataHwSwGain = {0}; - unsigned int HwAdvGain = 0; + bool is_va2 = rt1320->dev_id == RT1321_DEV_ID && + rt1320->version_id == RT1321_VA2; + unsigned int reg_c5fb = 0, reg_c570 = 0; int ret; - /* Get new hardware advance gain by ID 1300 */ - ret = rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 1300, - &audDriverDataHwSwGain, sizeof(audDriverDataHwSwGain)); - if (ret == 0) { - HwAdvGain = audDriverDataHwSwGain.HwAdvGain; - dev_dbg(dev, "%s, HwAdvGain=%d\n", __func__, HwAdvGain); - dev_dbg(dev, "%s, HwBasGain=%d\n", __func__, audDriverDataHwSwGain.HwBasGain); - dev_dbg(dev, "%s, SwAdvGain=%d\n", __func__, audDriverDataHwSwGain.SwAdvGain); - dev_dbg(dev, "%s, SwBasGain=%d\n", __func__, audDriverDataHwSwGain.SwBasGain); - } else { - dev_dbg(dev, "%s: param 1300 not supported, ret=%d\n", __func__, ret); + if (is_va2) { + regmap_read(rt1320->regmap, 0xc5fb, ®_c5fb); + regmap_read(rt1320->regmap, 0xc570, ®_c570); + regmap_write(rt1320->regmap, 0xc5fb, 0x00); + regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x00); + regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0x00); + + ret = rt1320_poll_power_state(rt1320, RT1320_K_R0_STATE, + RT1320_PS_RETRY, + RT1321_VA2_PS_SLEEP_US); + if (ret < 0) + goto _restore_; + + regmap_write(rt1320->regmap, 0xc570, 0x0b); + regmap_write(rt1320->regmap, 0xc5c4, 0x12); } /* Get advance gain/r0 */ - rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 6, &r0_data[0], sizeof(struct rt1320_datafixpoint)); - rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 7, &r0_data[1], sizeof(struct rt1320_datafixpoint)); + rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 6, &r0_data[0], sizeof(r0_data[0])); + rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 7, &r0_data[1], sizeof(r0_data[1])); - if (HwAdvGain != 0) { - l_advancegain = HwAdvGain & 0xffff; - r_advancegain = (HwAdvGain >> 16) & 0xffff; + if (is_va2) { + /* VA2: the advance gain comes from the AFX1 header */ + l_advancegain = rt1320->l_adv_gain; + r_advancegain = rt1320->r_adv_gain; } else { - l_advancegain = r0_data[0].advancegain; - r_advancegain = r0_data[1].advancegain; + /* Get new hardware advance gain by ID 1300 */ + ret = rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 1300, + &hwswgain, sizeof(hwswgain)); + if (ret < 0) + dev_dbg(dev, "%s: get param 1300 failed, ret=%d\n", __func__, ret); + + if (hwswgain.HwAdvGain) { + l_advancegain = hwswgain.HwAdvGain & 0xffff; + r_advancegain = hwswgain.HwAdvGain >> 16; + } else { + l_advancegain = r0_data[0].advancegain; + r_advancegain = r0_data[1].advancegain; + } } dev_dbg(dev, "%s, LR advanceGain=0x%x 0x%x\n", __func__, l_advancegain, r_advancegain); @@ -1498,8 +1550,8 @@ static void rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320) r0_data[1].r0 = rt1320->r0_r_reg; dev_dbg(dev, "%s, write LR r0=%d, %d\n", __func__, r0_data[0].r0, r0_data[1].r0); - rt1320_fw_param_protocol(rt1320, RT1320_SET_PARAM, 6, &r0_data[0], sizeof(struct rt1320_datafixpoint)); - rt1320_fw_param_protocol(rt1320, RT1320_SET_PARAM, 7, &r0_data[1], sizeof(struct rt1320_datafixpoint)); + rt1320_fw_param_protocol(rt1320, RT1320_SET_PARAM, 6, &r0_data[0], sizeof(r0_data[0])); + rt1320_fw_param_protocol(rt1320, RT1320_SET_PARAM, 7, &r0_data[1], sizeof(r0_data[1])); ret = rt1320_check_fw_ready(rt1320); if (ret < 0) dev_err(dev, "%s: Failed to set FW param 6,7!\n", __func__); @@ -1511,6 +1563,18 @@ static void rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320) regmap_write(rt1320->regmap, 0xdd08, (r_advancegain & 0xff)); dev_dbg(dev, "%s, set Advance mode gain\n", __func__); } + +_restore_: + if (is_va2) { + regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0xe0); + regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x80); + regmap_update_bits(rt1320->regmap, 0xd53b, 0x40, 0x40); + regmap_write(rt1320->regmap, 0xc570, reg_c570); + regmap_write(rt1320->regmap, 0xc5fb, reg_c5fb); + regmap_write(rt1320->regmap, 0xc5c4, 0x10); + } + + return ret; } static int rt1320_invrs_load(struct rt1320_sdw_priv *rt1320) @@ -1628,6 +1692,8 @@ static void rt1320_calibrate(struct rt1320_sdw_priv *rt1320) unsigned short l_advancegain, r_advancegain; unsigned int delay_s = 7; /* delay seconds for the calibration */ int dspfw_status; + bool is_va2 = rt1320->dev_id == RT1321_DEV_ID && + rt1320->version_id == RT1321_VA2; if (!rt1320->component) return; @@ -1660,6 +1726,29 @@ static void rt1320_calibrate(struct rt1320_sdw_priv *rt1320) goto _finish_; } + if (is_va2) { + /* Switch to TV mode */ + regmap_write(rt1320->regmap, 0xc5fb, 0x00); + regmap_write(rt1320->regmap, 0xcd00, 0xc5); + /* disable phase sync */ + regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x00); + /* through SRC */ + regmap_write(rt1320->regmap, 0xc5c4, 0x12); + regmap_write(rt1320->regmap, 0xc570, 0x0b); + + /* disable silence detection */ + regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0x00); + dev_dbg(dev, "%s, disable silence detection\n", __func__); + + ret = rt1320_poll_power_state(rt1320, RT1320_K_R0_STATE, + RT1320_PS_RETRY, + RT1321_VA2_PS_SLEEP_US); + if (ret < 0) { + dev_dbg(dev, "%s, check class D status before k r0\n", __func__); + goto _finish_; + } + } + /* fine tune pilot tone output */ ret = rt1320_pilot_tone_output(rt1320); if (ret < 0) { @@ -1667,18 +1756,23 @@ static void rt1320_calibrate(struct rt1320_sdw_priv *rt1320) goto _finish_; } - if (rt1320->dev_id == RT1321_DEV_ID) { - regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x00); - regmap_write(rt1320->regmap, 0xc5c4, 0x12); - } + if (is_va2) { + /* RsRatio should restore into DSP FW when FW was ready */ + rt1320_invrs_load(rt1320); + } else { + if (rt1320->dev_id == RT1321_DEV_ID) { + regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x00); + regmap_write(rt1320->regmap, 0xc5c4, 0x12); + } - regmap_write(rt1320->regmap, 0xc5fb, 0x00); - regmap_write(rt1320->regmap, 0xc570, 0x0b); - regmap_write(rt1320->regmap, 0xcd00, 0xc5); + regmap_write(rt1320->regmap, 0xc5fb, 0x00); + regmap_write(rt1320->regmap, 0xc570, 0x0b); + regmap_write(rt1320->regmap, 0xcd00, 0xc5); - /* disable silence detection */ - regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0x00); - dev_dbg(dev, "%s, disable silence detection\n", __func__); + /* disable silence detection */ + regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0x00); + dev_dbg(dev, "%s, disable silence detection\n", __func__); + } ret = rt1320_check_power_state_ready(rt1320, RT1320_K_R0_STATE); if (ret < 0) { @@ -1715,26 +1809,27 @@ static void rt1320_calibrate(struct rt1320_sdw_priv *rt1320) dev_dbg(dev, "%s, LR advanceGain=0x%x, 0x%x\n", __func__, l_advancegain, r_advancegain); dev_dbg(dev, "%s, LR invrs=0x%x, 0x%x\n", __func__, audfixpoint[0].invrs, audfixpoint[1].invrs); - /* enable silence detection */ - regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0xe0); - dev_dbg(dev, "%s, enable silence detection\n", __func__); - - regmap_write(rt1320->regmap, 0xc5fb, reg_c5fb); - regmap_write(rt1320->regmap, 0xc570, reg_c570); - regmap_write(rt1320->regmap, 0xcd00, reg_cd00); - rt1320->r0_l_reg = l_re[4]; rt1320->r0_r_reg = r_re[4]; rt1320->cali_done = true; rt1320_calc_r0(rt1320); _finish_: + regmap_update_bits(rt1320->regmap, 0xc044, 0xe0, 0xe0); + regmap_write(rt1320->regmap, 0xc5fb, reg_c5fb); + regmap_write(rt1320->regmap, 0xc570, reg_c570); + regmap_write(rt1320->regmap, 0xcd00, reg_cd00); + regmap_write(rt1320->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, RT1320_SDCA_CTL_REQ_POWER_STATE, 0), 0x03); rt1320_pde_transition_delay(rt1320, FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, 0x03); if (rt1320->dev_id == RT1321_DEV_ID) { regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x80); + if (is_va2) { + regmap_update_bits(rt1320->regmap, 0xd53b, 0x40, 0x40); + regmap_write(rt1320->regmap, 0xc570, reg_c570); + } regmap_write(rt1320->regmap, 0xc5c4, 0x10); } @@ -1766,8 +1861,8 @@ static int rt1320_r0_cali_put(struct snd_kcontrol *kcontrol, if (!rt1320->hw_init) return 0; - ret = pm_runtime_resume(component->dev); - if (ret < 0 && ret != -EACCES) + ret = pm_runtime_resume_and_get(component->dev); + if (ret < 0) return ret; rt1320->cali_done = false; @@ -1778,6 +1873,9 @@ static int rt1320_r0_cali_put(struct snd_kcontrol *kcontrol, } snd_soc_dapm_mutex_unlock(dapm); + pm_runtime_mark_last_busy(component->dev); + pm_runtime_put_autosuspend(component->dev); + return 0; } @@ -1804,10 +1902,8 @@ static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320) max_addr = 0x10007fff; break; case RT1321_DEV_ID: - if (rt1320->version_id == RT1321_VA2) - return; - - filename = RT1321_VA_MCU_PATCH; + filename = (rt1320->version_id != RT1321_VA2) ? RT1321_VA_MCU_PATCH : + RT1321_VA2_MCU_PATCH; min_addr = 0x10008000; max_addr = 0x10008fff; break; @@ -2088,6 +2184,8 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320) regmap_update_bits(rt1320->regmap, 0x2000301c, 0x01, 0x01); /* Phase sync enable */ regmap_update_bits(rt1320->regmap, 0xc047, 0x80, 0x80); + if (rt1320->version_id == RT1321_VA2) + regmap_update_bits(rt1320->regmap, 0xd53b, 0x40, 0x40); break; } @@ -2102,6 +2200,40 @@ static int rt1320_rae_load(struct rt1320_sdw_priv *rt1320) return ret; } +static void rt1320_companion_mode_set(struct rt1320_sdw_priv *rt1320) +{ + regmap_write(rt1320->regmap, 0xc04c, rt1320->comp_mode_en ? 0x54 : 0xe2); + regmap_write(rt1320->regmap, 0xc068, 0x35); +} + +static void rt1320_companion_mode_patch(struct rt1320_sdw_priv *rt1320, + bool patch_ver) +{ + struct device *dev = &rt1320->sdw_slave->dev; + unsigned int val; + + if (!patch_ver) + return; + + regmap_read(rt1320->regmap, 0x3fc2dfc3, &val); + rt1320->comp_mode_en = !!(val & 0x80); + dev_dbg(dev, "%s: val:%x, comp_mode_en:%d\n", __func__, + val, rt1320->comp_mode_en); + + if (rt1320->comp_mode_en) { + regmap_write(rt1320->regmap, 0xd472, 0xfd); + regmap_write(rt1320->regmap, 0x3fc2dfc3, 0x80); + regmap_write(rt1320->regmap, 0x3fc2dfc0, 0x0b); + regmap_write(rt1320->regmap, 0x3fc2dfce, 0x54); + regmap_write(rt1320->regmap, 0x3fc2dfcf, 0x05); + } else { + regmap_write(rt1320->regmap, 0xc5d0, 0x0f); + regmap_write(rt1320->regmap, 0x3fc2dfc0, 0x0b); + regmap_update_bits(rt1320->regmap, 0x3fc2dfc3, 0x80, 0x00); + } + rt1320_companion_mode_set(rt1320); +} + static void rt1320_dspfw_load_code(struct rt1320_sdw_priv *rt1320) { struct rt1320_imageinfo { @@ -2120,10 +2252,12 @@ struct rt1320_dspfwheader { unsigned int val, i, fw_offset; struct rt1320_dspfwheader *fwheader; struct rt1320_imageinfo *ptr_img; - struct sdw_bpt_section sec[10]; + struct sdw_bpt_section sec[16]; const struct firmware *fw __free(firmware) = NULL; unsigned char *fw_data; bool dev_fw_match = false; + bool is_va2 = rt1320->dev_id == RT1321_DEV_ID && + rt1320->version_id == RT1321_VA2; static const char hdr_sig[] = "AFX"; unsigned int hdr_size = 0; const char *dmi_vendor, *dmi_product, *dmi_sku; @@ -2193,10 +2327,25 @@ struct rt1320_dspfwheader { /* The binary file has a header of 64 bytes */ if (memcmp(fw_data, hdr_sig, sizeof(hdr_sig)) == 0) - hdr_size = 64; + hdr_size = RT1320_AFX_HDR_SIZE; else hdr_size = 0; + if (hdr_size && ptr_img->addr == RT1321_AFX1_ADDR) { + dev_dbg(dev, "%s, AFX1 hdr[0x%x]=0x%08x (%*ph)\n", __func__, + RT1320_AFX_HDR_INFO_OFFSET, + get_unaligned_le32(fw_data + RT1320_AFX_HDR_INFO_OFFSET), + 4, fw_data + RT1320_AFX_HDR_INFO_OFFSET); + + rt1320->l_adv_gain = fw_data[RT1320_AFX_HDR_INFO_OFFSET] | + (fw_data[RT1320_AFX_HDR_INFO_OFFSET + 1] << 8); + rt1320->r_adv_gain = fw_data[RT1320_AFX_HDR_INFO_OFFSET + 2] | + (fw_data[RT1320_AFX_HDR_INFO_OFFSET + 3] << 8); + + dev_dbg(dev, "%s, l_adv_gain=0x%04x, r_adv_gain=0x%04x\n", __func__, + rt1320->l_adv_gain, rt1320->r_adv_gain); + } + sec[i].addr = ptr_img->addr; sec[i].len = ptr_img->size - hdr_size; sec[i].buf = fw_data + hdr_size; @@ -2288,7 +2437,7 @@ struct rt1320_dspfwheader { regmap_write(rt1320->regmap, 0x3fc2dfc8, 0x00); /* enable handshake */ regmap_write(rt1320->regmap, 0x3fc2dfc4, 0x00); - regmap_write(rt1320->regmap, 0xd470, 0xad); + regmap_write(rt1320->regmap, 0xd470, 0x8d); /* minimum phase settings */ regmap_write(rt1320->regmap, 0xc5c4, 0x10); regmap_write(rt1320->regmap, 0x20003003, 0x31); @@ -2298,12 +2447,16 @@ struct rt1320_dspfwheader { break; } + /* companion mode patch */ + rt1320_companion_mode_patch(rt1320, is_va2); + /* enable DSP FW */ regmap_write(rt1320->regmap, 0xc081, 0xfc); regmap_update_bits(rt1320->regmap, 0xf01e, 0x1, 0x0); /* RsRatio should restore into DSP FW when FW was ready */ - rt1320_invrs_load(rt1320); + if (!is_va2) + rt1320_invrs_load(rt1320); /* DSP clock switches to PLL */ regmap_write(rt1320->regmap, 0xc081, 0xfc); @@ -2590,6 +2743,10 @@ static int rt1320_pde23_event(struct snd_soc_dapm_widget *w, unsigned char ps0 = 0x0, ps3 = 0x3; switch (event) { + case SND_SOC_DAPM_PRE_PMU: + if (rt1320->dev_id == RT1321_DEV_ID && rt1320->version_id == RT1321_VA2) + rt1320_companion_mode_set(rt1320); + break; case SND_SOC_DAPM_POST_PMU: regmap_write(rt1320->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, @@ -2925,7 +3082,7 @@ static int rt1320_r0_load(struct rt1320_sdw_priv *rt1320) goto _timeout_; } - rt1320_set_advancemode(rt1320); + ret = rt1320_set_advancemode(rt1320); _timeout_: regmap_write(rt1320->regmap, @@ -2962,8 +3119,8 @@ static int rt1320_r0_load_mode_put(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[1] == 0) return -EINVAL; - ret = pm_runtime_resume(component->dev); - if (ret < 0 && ret != -EACCES) + ret = pm_runtime_resume_and_get(component->dev); + if (ret < 0) return ret; snd_soc_dapm_mutex_lock(dapm); @@ -2975,6 +3132,9 @@ static int rt1320_r0_load_mode_put(struct snd_kcontrol *kcontrol, } snd_soc_dapm_mutex_unlock(dapm); + pm_runtime_mark_last_busy(component->dev); + pm_runtime_put_autosuspend(component->dev); + return 0; } @@ -3018,7 +3178,7 @@ static int rt1320_dspfw_load_put(struct snd_kcontrol *kcontrol, return 0; ret = pm_runtime_resume_and_get(component->dev); - if (ret < 0 && ret != -EACCES) + if (ret < 0) return ret; if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF && @@ -3054,8 +3214,8 @@ static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol, if (!rt1320->hw_init) return 0; - ret = pm_runtime_resume(component->dev); - if (ret < 0 && ret != -EACCES) + ret = pm_runtime_resume_and_get(component->dev); + if (ret < 0) return ret; if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF && @@ -3065,6 +3225,9 @@ static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol, if (!ucontrol->value.integer.value[0]) rt1320->rae_update_done = false; + pm_runtime_mark_last_busy(component->dev); + pm_runtime_put_autosuspend(component->dev); + return 0; } @@ -3078,8 +3241,8 @@ static int rt1320_brown_out_put(struct snd_kcontrol *kcontrol, if (!rt1320->hw_init) return 0; - ret = pm_runtime_resume(component->dev); - if (ret < 0 && ret != -EACCES) + ret = pm_runtime_resume_and_get(component->dev); + if (ret < 0) return ret; if (rt1320->brown_out != ucontrol->value.integer.value[0]) { @@ -3092,6 +3255,8 @@ static int rt1320_brown_out_put(struct snd_kcontrol *kcontrol, else regmap_write(rt1320->regmap, 0xdb03, 0xf0); + pm_runtime_mark_last_busy(component->dev); + pm_runtime_put_autosuspend(component->dev); return changed; } @@ -3129,8 +3294,8 @@ static int rt1320_r0_temperature_put(struct snd_kcontrol *kcontrol, if (!rt1320->hw_init) return 0; - ret = pm_runtime_resume(component->dev); - if (ret < 0 && ret != -EACCES) + ret = pm_runtime_resume_and_get(component->dev); + if (ret < 0) return ret; snd_soc_dapm_mutex_lock(dapm); @@ -3139,6 +3304,9 @@ static int rt1320_r0_temperature_put(struct snd_kcontrol *kcontrol, rt1320_t0_load(rt1320, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1]); snd_soc_dapm_mutex_unlock(dapm); + pm_runtime_mark_last_busy(component->dev); + pm_runtime_put_autosuspend(component->dev); + return 0; } @@ -3189,7 +3357,7 @@ static const struct snd_soc_dapm_widget rt1320_dapm_widgets[] = { SND_SOC_DAPM_PGA("FU21", SND_SOC_NOPM, 0, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("PDE 23", SND_SOC_NOPM, 0, 0, rt1320_pde23_event, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), SND_SOC_DAPM_SUPPLY("PDE 11", SND_SOC_NOPM, 0, 0, rt1320_pde11_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), SND_SOC_DAPM_ADC("FU 113", NULL, SND_SOC_NOPM, 0, 0), @@ -3535,7 +3703,7 @@ static int rt1320_sdw_init(struct device *dev, struct regmap *regmap, struct rt1320_sdw_priv *rt1320; int ret; - rt1320 = devm_kzalloc(dev, sizeof(*rt1320), GFP_KERNEL); + rt1320 = devm_kzalloc_obj(dev, *rt1320); if (!rt1320) return -ENOMEM; diff --git a/sound/soc/codecs/rt1320-sdw.h b/sound/soc/codecs/rt1320-sdw.h index df9ccdf92d361c..99f8ba6462a41d 100644 --- a/sound/soc/codecs/rt1320-sdw.h +++ b/sound/soc/codecs/rt1320-sdw.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "../../../drivers/soundwire/bus.h" @@ -84,6 +85,11 @@ #define RT1320_SDCA_RATE_96000HZ 0x0b #define RT1320_SDCA_RATE_192000HZ 0x0d +/* DSP FW info */ +#define RT1320_AFX_HDR_SIZE 64 +#define RT1320_AFX_HDR_INFO_OFFSET 0x20 +#define RT1321_AFX1_ADDR 0x3fc2a300 + enum { RT1320_AIF1, RT1320_AIF2, @@ -109,6 +115,7 @@ enum rt1321_version_id { #define RT1320_VAB_MCU_PATCH "realtek/rt1320/rt1320-patch-code-vab.bin" #define RT1320_VC_MCU_PATCH "realtek/rt1320/rt1320-patch-code-vc.bin" #define RT1321_VA_MCU_PATCH "realtek/rt1320/rt1321-patch-code-va.bin" +#define RT1321_VA2_MCU_PATCH "realtek/rt1320/rt1321-patch-code-va2.bin" #define RT1320_FW_PARAM_ADDR 0x3fc2ab80 #define RT1320_CMD_ID 0x3fc2ab81 @@ -120,6 +127,9 @@ enum rt1321_version_id { #define RT1321_CMD_PARAM_ADDR 0x3fc2d310 #define RT1321_DSPFW_STATUS_ADDR 0x3fc2dfc4 +/* moudleid + commandtype + reserved1 + commandlength */ +#define RT1320_FW_CMD_HDR_SIZE 8 + /* FW parameter id 6, 7 */ struct rt1320_datafixpoint { int silencedetect; @@ -168,6 +178,11 @@ enum rt1320_power_state { RT1320_K_R0_STATE = 0x1b, }; +/* polling of RT1320_POWER_STATE */ +#define RT1320_PS_RETRY 200 +#define RT1320_PS_SLEEP_US 1000 +#define RT1321_VA2_PS_SLEEP_US 10000 + enum rt1320_rw_type { RT1320_BRA_WRITE = 0, RT1320_BRA_READ = 1, @@ -207,6 +222,8 @@ struct rt1320_sdw_priv { bool rae_update_done; struct work_struct load_dspfw_work; struct sdw_bpt_msg bra_msg; + unsigned short l_adv_gain, r_adv_gain; + bool comp_mode_en; }; #endif /* __RT1320_SDW_H__ */ diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c index 5c67b1d210b27e..202a3ee822d7f8 100644 --- a/sound/soc/codecs/rt274.c +++ b/sound/soc/codecs/rt274.c @@ -1129,8 +1129,7 @@ static int rt274_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt274 = devm_kzalloc(&i2c->dev, sizeof(*rt274), - GFP_KERNEL); + rt274 = devm_kzalloc_obj(&i2c->dev, *rt274); if (rt274 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c index c60e81ba87f33d..b6d409e79b1072 100644 --- a/sound/soc/codecs/rt286.c +++ b/sound/soc/codecs/rt286.c @@ -1146,8 +1146,7 @@ static int rt286_i2c_probe(struct i2c_client *i2c) struct rt286_priv *rt286; int i, ret, vendor_id; - rt286 = devm_kzalloc(&i2c->dev, sizeof(*rt286), - GFP_KERNEL); + rt286 = devm_kzalloc_obj(&i2c->dev, *rt286); if (NULL == rt286) return -ENOMEM; diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c index 72407fec0f345b..a879bb15c17135 100644 --- a/sound/soc/codecs/rt298.c +++ b/sound/soc/codecs/rt298.c @@ -1193,8 +1193,7 @@ static int rt298_i2c_probe(struct i2c_client *i2c) const struct acpi_device_id *acpiid; int i, ret; - rt298 = devm_kzalloc(&i2c->dev, sizeof(*rt298), - GFP_KERNEL); + rt298 = devm_kzalloc_obj(&i2c->dev, *rt298); if (NULL == rt298) return -ENOMEM; diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index a33fbc9fb04729..90ac9a81ce035c 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1261,8 +1261,7 @@ static int rt5514_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val = ~0; - rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), - GFP_KERNEL); + rt5514 = devm_kzalloc_obj(&i2c->dev, struct rt5514_priv); if (rt5514 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt5575.c b/sound/soc/codecs/rt5575.c index 5c3e60eaa6a495..0fcdf85fb50273 100644 --- a/sound/soc/codecs/rt5575.c +++ b/sound/soc/codecs/rt5575.c @@ -281,7 +281,7 @@ static int rt5575_i2c_probe(struct i2c_client *i2c) int ret, val, boot; struct device *dev = &i2c->dev; - rt5575 = devm_kzalloc(dev, sizeof(struct rt5575_priv), GFP_KERNEL); + rt5575 = devm_kzalloc_obj(dev, struct rt5575_priv); if (!rt5575) return -ENOMEM; diff --git a/sound/soc/codecs/rt5616.c b/sound/soc/codecs/rt5616.c index af6299baea7c88..92383879e2d66c 100644 --- a/sound/soc/codecs/rt5616.c +++ b/sound/soc/codecs/rt5616.c @@ -1344,8 +1344,7 @@ static int rt5616_i2c_probe(struct i2c_client *i2c) unsigned int val; int ret; - rt5616 = devm_kzalloc(&i2c->dev, sizeof(struct rt5616_priv), - GFP_KERNEL); + rt5616 = devm_kzalloc_obj(&i2c->dev, struct rt5616_priv); if (!rt5616) return -ENOMEM; diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c index d523d6d3a25418..9e951ff3fbd3d4 100644 --- a/sound/soc/codecs/rt5631.c +++ b/sound/soc/codecs/rt5631.c @@ -1726,8 +1726,7 @@ static int rt5631_i2c_probe(struct i2c_client *i2c) struct rt5631_priv *rt5631; int ret; - rt5631 = devm_kzalloc(&i2c->dev, sizeof(struct rt5631_priv), - GFP_KERNEL); + rt5631 = devm_kzalloc_obj(&i2c->dev, struct rt5631_priv); if (NULL == rt5631) return -ENOMEM; diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c index 8b592370d1294a..77d63bb18ae868 100644 --- a/sound/soc/codecs/rt5640.c +++ b/sound/soc/codecs/rt5640.c @@ -3031,9 +3031,7 @@ static int rt5640_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5640 = devm_kzalloc(&i2c->dev, - sizeof(struct rt5640_priv), - GFP_KERNEL); + rt5640 = devm_kzalloc_obj(&i2c->dev, struct rt5640_priv); if (NULL == rt5640) return -ENOMEM; i2c_set_clientdata(i2c, rt5640); diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 5e0fc69576c03b..e14b66d3118da9 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3488,8 +3488,8 @@ static int rt5645_probe(struct snd_soc_component *component) if (rt5645->pdata.long_name) component->card->long_name = rt5645->pdata.long_name; - rt5645->eq_param = kcalloc(RT5645_HWEQ_NUM, - sizeof(struct rt5645_eq_param_s), GFP_KERNEL); + rt5645->eq_param = kzalloc_objs(struct rt5645_eq_param_s, + RT5645_HWEQ_NUM); if (!rt5645->eq_param) return -ENOMEM; @@ -4023,8 +4023,7 @@ static int rt5645_i2c_probe(struct i2c_client *i2c) unsigned int val; struct regmap *regmap; - rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), - GFP_KERNEL); + rt5645 = devm_kzalloc_obj(&i2c->dev, struct rt5645_priv); if (rt5645 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c index b911757376f5c7..1115a1b14d1dc3 100644 --- a/sound/soc/codecs/rt5651.c +++ b/sound/soc/codecs/rt5651.c @@ -2227,8 +2227,7 @@ static int rt5651_i2c_probe(struct i2c_client *i2c) int ret; int err; - rt5651 = devm_kzalloc(&i2c->dev, sizeof(*rt5651), - GFP_KERNEL); + rt5651 = devm_kzalloc_obj(&i2c->dev, *rt5651); if (NULL == rt5651) return -ENOMEM; diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c index 68f7d5673e1900..a1da6d30ea1154 100644 --- a/sound/soc/codecs/rt5659.c +++ b/sound/soc/codecs/rt5659.c @@ -3660,6 +3660,21 @@ static int rt5659_set_bias_level(struct snd_soc_component *component, return 0; } +static void rt5659_disable_irq_and_cancel_work(struct rt5659_priv *rt5659) +{ + if (rt5659->irq_acquired && !rt5659->irq_disabled) { + disable_irq(rt5659->i2c->irq); + rt5659->irq_disabled = true; + } + if (rt5659->jack_detect_work_inited) + cancel_delayed_work_sync(&rt5659->jack_detect_work); +} + +static void rt5659_i2c_disable_irq_and_cancel_work(void *data) +{ + rt5659_disable_irq_and_cancel_work(data); +} + static int rt5659_probe(struct snd_soc_component *component) { struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); @@ -3667,8 +3682,10 @@ static int rt5659_probe(struct snd_soc_component *component) rt5659->component = component; + regcache_sync(rt5659->regmap); + if (rt5659->irq_disabled) { - enable_irq(to_i2c_client(component->dev)->irq); + enable_irq(rt5659->i2c->irq); rt5659->irq_disabled = false; } @@ -3689,17 +3706,28 @@ static int rt5659_probe(struct snd_soc_component *component) static void rt5659_remove(struct snd_soc_component *component) { struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); - struct i2c_client *i2c = to_i2c_client(component->dev); - if (rt5659->irq_acquired) { - disable_irq(i2c->irq); - rt5659->irq_disabled = true; + rt5659_disable_irq_and_cancel_work(rt5659); + + if (rt5659->jack_type && rt5659->pdata.jd_src == RT5659_JD3) + rt5659_headset_detect(component, 0); + + rt5659->hs_jack = NULL; + rt5659->jack_type = 0; + rt5659->hda_hp_plugged = false; + rt5659->hda_mic_plugged = false; + + if (rt5659->pdata.jd_src == RT5659_JD_HDA_HEADER) { + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1, + 0x10, 0x10); + regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2, + 0x2, 0x0); } - if (rt5659->jack_detect_work_inited) - cancel_delayed_work_sync(&rt5659->jack_detect_work); + rt5659->component = NULL; regmap_write(rt5659->regmap, RT5659_RESET, 0); + regcache_mark_dirty(rt5659->regmap); } #ifdef CONFIG_PM @@ -4119,8 +4147,7 @@ static int rt5659_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5659 = devm_kzalloc(&i2c->dev, sizeof(struct rt5659_priv), - GFP_KERNEL); + rt5659 = devm_kzalloc_obj(&i2c->dev, struct rt5659_priv); if (rt5659 == NULL) return -ENOMEM; @@ -4328,6 +4355,13 @@ static int rt5659_i2c_probe(struct i2c_client *i2c) RT5659_GP1_PIN_MASK, RT5659_GP1_PIN_IRQ); } + rt5659->i2c = i2c; + ret = devm_add_action_or_reset(&i2c->dev, + rt5659_i2c_disable_irq_and_cancel_work, + rt5659); + if (ret) + return ret; + return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5659, rt5659_dai, ARRAY_SIZE(rt5659_dai)); @@ -4337,6 +4371,7 @@ static void rt5659_i2c_shutdown(struct i2c_client *client) { struct rt5659_priv *rt5659 = i2c_get_clientdata(client); + rt5659_disable_irq_and_cancel_work(rt5659); regmap_write(rt5659->regmap, RT5659_RESET, 0); } diff --git a/sound/soc/codecs/rt5659.h b/sound/soc/codecs/rt5659.h index e10b3844501b9c..1118e6ab1887d4 100644 --- a/sound/soc/codecs/rt5659.h +++ b/sound/soc/codecs/rt5659.h @@ -1793,6 +1793,7 @@ struct rt5659_priv { struct snd_soc_component *component; struct rt5659_platform_data pdata; struct regmap *regmap; + struct i2c_client *i2c; struct gpio_desc *gpiod_ldo1_en; struct gpio_desc *gpiod_reset; struct snd_soc_jack *hs_jack; diff --git a/sound/soc/codecs/rt5660.c b/sound/soc/codecs/rt5660.c index 2a3ecac12c07ca..bbc7a4580fc1c2 100644 --- a/sound/soc/codecs/rt5660.c +++ b/sound/soc/codecs/rt5660.c @@ -1276,8 +1276,7 @@ static int rt5660_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5660 = devm_kzalloc(&i2c->dev, sizeof(struct rt5660_priv), - GFP_KERNEL); + rt5660 = devm_kzalloc_obj(&i2c->dev, struct rt5660_priv); if (rt5660 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c index bd6a8e98bf4444..5e95ab2666594e 100644 --- a/sound/soc/codecs/rt5663.c +++ b/sound/soc/codecs/rt5663.c @@ -3520,6 +3520,16 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev) return 0; } +static void rt5663_stop_jack_work(struct rt5663_priv *rt5663) +{ + if (rt5663->irq) + free_irq(rt5663->irq, rt5663); + + /* Jack detection can queue unplug work. */ + disable_delayed_work_sync(&rt5663->jack_detect_work); + disable_delayed_work_sync(&rt5663->jd_unplug_work); +} + static int rt5663_i2c_probe(struct i2c_client *i2c) { struct rt5663_platform_data *pdata = dev_get_platdata(&i2c->dev); @@ -3528,8 +3538,7 @@ static int rt5663_i2c_probe(struct i2c_client *i2c) unsigned int val; struct regmap *regmap; - rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv), - GFP_KERNEL); + rt5663 = devm_kzalloc_obj(&i2c->dev, struct rt5663_priv); if (rt5663 == NULL) return -ENOMEM; @@ -3725,19 +3734,13 @@ static int rt5663_i2c_probe(struct i2c_client *i2c) rt5663_dai, ARRAY_SIZE(rt5663_dai)); if (ret) - goto err_enable; + goto err_jack_work; return 0; - - /* - * Error after enabling regulators should goto err_enable - * to disable regulators. - */ +err_jack_work: + rt5663_stop_jack_work(rt5663); err_enable: - if (i2c->irq) - free_irq(i2c->irq, rt5663); - regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies); return ret; } @@ -3746,8 +3749,7 @@ static void rt5663_i2c_remove(struct i2c_client *i2c) { struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c); - if (i2c->irq) - free_irq(i2c->irq, rt5663); + rt5663_stop_jack_work(rt5663); regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies); } diff --git a/sound/soc/codecs/rt5665.c b/sound/soc/codecs/rt5665.c index 62b21092e352bb..27744497033ab9 100644 --- a/sound/soc/codecs/rt5665.c +++ b/sound/soc/codecs/rt5665.c @@ -1194,19 +1194,13 @@ static void rt5665_jack_detect_handler(struct work_struct *work) container_of(work, struct rt5665_priv, jack_detect_work.work); int val, btn_type; - while (!rt5665->component) { - pr_debug("%s codec = null\n", __func__); - usleep_range(10000, 15000); - } - - while (!snd_soc_card_is_instantiated(rt5665->component->card)) { - pr_debug("%s\n", __func__); - usleep_range(10000, 15000); - } - - while (!rt5665->calibration_done) { - pr_debug("%s calibration not ready\n", __func__); - usleep_range(10000, 15000); + if (!rt5665->component || + !snd_soc_card_is_instantiated(rt5665->component->card) || + !rt5665->calibration_done) { + /* card not instantiated or calibration pending, try later */ + mod_delayed_work(system_power_efficient_wq, + &rt5665->jack_detect_work, msecs_to_jiffies(15)); + return; } guard(mutex)(&rt5665->calibrate_mutex); @@ -4652,9 +4646,12 @@ static void rt5665_calibrate_handler(struct work_struct *work) struct rt5665_priv *rt5665 = container_of(work, struct rt5665_priv, calibrate_work.work); - while (!snd_soc_card_is_instantiated(rt5665->component->card)) { - pr_debug("%s\n", __func__); - usleep_range(10000, 15000); + if (!rt5665->component || + !snd_soc_card_is_instantiated(rt5665->component->card)) { + /* card not instantiated yet, try later */ + mod_delayed_work(system_power_efficient_wq, + &rt5665->calibrate_work, msecs_to_jiffies(15)); + return; } rt5665_calibrate(rt5665); @@ -4667,8 +4664,7 @@ static int rt5665_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5665 = devm_kzalloc(&i2c->dev, sizeof(struct rt5665_priv), - GFP_KERNEL); + rt5665 = devm_kzalloc_obj(&i2c->dev, struct rt5665_priv); if (rt5665 == NULL) return -ENOMEM; @@ -4837,9 +4833,20 @@ static void rt5665_i2c_shutdown(struct i2c_client *client) { struct rt5665_priv *rt5665 = i2c_get_clientdata(client); + if (client->irq) + disable_irq(client->irq); + cancel_delayed_work_sync(&rt5665->jack_detect_work); + cancel_delayed_work_sync(&rt5665->jd_check_work); + cancel_delayed_work_sync(&rt5665->calibrate_work); + regmap_write(rt5665->regmap, RT5665_RESET, 0); } +static void rt5665_i2c_remove(struct i2c_client *client) +{ + rt5665_i2c_shutdown(client); +} + #ifdef CONFIG_OF static const struct of_device_id rt5665_of_match[] = { {.compatible = "realtek,rt5665"}, @@ -4865,6 +4872,7 @@ static struct i2c_driver rt5665_i2c_driver = { .acpi_match_table = ACPI_PTR(rt5665_acpi_match), }, .probe = rt5665_i2c_probe, + .remove = rt5665_i2c_remove, .shutdown = rt5665_i2c_shutdown, .id_table = rt5665_i2c_id, }; diff --git a/sound/soc/codecs/rt5668.c b/sound/soc/codecs/rt5668.c index 29d70802a046a0..ad6b1268e08ddd 100644 --- a/sound/soc/codecs/rt5668.c +++ b/sound/soc/codecs/rt5668.c @@ -45,6 +45,7 @@ struct rt5668_priv { struct rt5668_platform_data pdata; struct gpio_desc *ldo1_en; struct regmap *regmap; + struct i2c_client *i2c; struct snd_soc_jack *hs_jack; struct regulator_bulk_data supplies[RT5668_NUM_SUPPLIES]; struct delayed_work jack_detect_work; @@ -2213,14 +2214,28 @@ static int rt5668_set_bias_level(struct snd_soc_component *component, return 0; } +static void rt5668_i2c_disable_irq_and_cancel_work(void *data) +{ + struct rt5668_priv *rt5668 = data; + + if (rt5668->irq_acquired && !rt5668->irq_disabled) { + disable_irq(rt5668->i2c->irq); + rt5668->irq_disabled = true; + } + cancel_delayed_work_sync(&rt5668->jack_detect_work); + cancel_delayed_work_sync(&rt5668->jd_check_work); +} + static int rt5668_probe(struct snd_soc_component *component) { struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); rt5668->component = component; + regcache_sync(rt5668->regmap); + if (rt5668->irq_disabled) { - enable_irq(to_i2c_client(component->dev)->irq); + enable_irq(rt5668->i2c->irq); rt5668->irq_disabled = false; } @@ -2230,17 +2245,18 @@ static int rt5668_probe(struct snd_soc_component *component) static void rt5668_remove(struct snd_soc_component *component) { struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); - struct i2c_client *i2c = to_i2c_client(component->dev); - if (rt5668->irq_acquired) { - disable_irq(i2c->irq); - rt5668->irq_disabled = true; - } + rt5668_i2c_disable_irq_and_cancel_work(rt5668); - cancel_delayed_work_sync(&rt5668->jack_detect_work); - cancel_delayed_work_sync(&rt5668->jd_check_work); + if (rt5668->jack_type) + rt5668_headset_detect(component, 0); + + rt5668->hs_jack = NULL; + rt5668->jack_type = 0; + rt5668->component = NULL; rt5668_reset(rt5668->regmap); + regcache_mark_dirty(rt5668->regmap); } #ifdef CONFIG_PM @@ -2447,8 +2463,7 @@ static int rt5668_i2c_probe(struct i2c_client *i2c) int i, ret; unsigned int val; - rt5668 = devm_kzalloc(&i2c->dev, sizeof(struct rt5668_priv), - GFP_KERNEL); + rt5668 = devm_kzalloc_obj(&i2c->dev, struct rt5668_priv); if (rt5668 == NULL) return -ENOMEM; @@ -2507,6 +2522,8 @@ static int rt5668_i2c_probe(struct i2c_client *i2c) rt5668_reset(rt5668->regmap); + mutex_init(&rt5668->calibrate_mutex); + rt5668_calibrate(rt5668); regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0000); @@ -2564,8 +2581,6 @@ static int rt5668_i2c_probe(struct i2c_client *i2c) INIT_DELAYED_WORK(&rt5668->jd_check_work, rt5668_jd_check_handler); - mutex_init(&rt5668->calibrate_mutex); - if (i2c->irq) { ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, rt5668_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING @@ -2576,6 +2591,13 @@ static int rt5668_i2c_probe(struct i2c_client *i2c) rt5668->irq_acquired = true; } + rt5668->i2c = i2c; + ret = devm_add_action_or_reset(&i2c->dev, + rt5668_i2c_disable_irq_and_cancel_work, + rt5668); + if (ret) + return ret; + return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5668, rt5668_dai, ARRAY_SIZE(rt5668_dai)); } @@ -2584,6 +2606,8 @@ static void rt5668_i2c_shutdown(struct i2c_client *client) { struct rt5668_priv *rt5668 = i2c_get_clientdata(client); + rt5668_i2c_disable_irq_and_cancel_work(rt5668); + rt5668_reset(rt5668->regmap); } diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c index 62d4e7cea5af35..c34e7c590c859b 100644 --- a/sound/soc/codecs/rt5670.c +++ b/sound/soc/codecs/rt5670.c @@ -3066,9 +3066,7 @@ static int rt5670_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5670 = devm_kzalloc(&i2c->dev, - sizeof(struct rt5670_priv), - GFP_KERNEL); + rt5670 = devm_kzalloc_obj(&i2c->dev, struct rt5670_priv); if (NULL == rt5670) return -ENOMEM; diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 91316537d68ee8..847d2f4c23a820 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -5585,8 +5585,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c) int ret; unsigned int val; - rt5677 = devm_kzalloc(&i2c->dev, sizeof(struct rt5677_priv), - GFP_KERNEL); + rt5677 = devm_kzalloc_obj(&i2c->dev, struct rt5677_priv); if (rt5677 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c index 286cf0d17968a1..db820cd9acba54 100644 --- a/sound/soc/codecs/rt5682-i2c.c +++ b/sound/soc/codecs/rt5682-i2c.c @@ -123,8 +123,7 @@ static int rt5682_i2c_probe(struct i2c_client *i2c) int i, ret; unsigned int val; - rt5682 = devm_kzalloc(&i2c->dev, sizeof(struct rt5682_priv), - GFP_KERNEL); + rt5682 = devm_kzalloc_obj(&i2c->dev, struct rt5682_priv); if (!rt5682) return -ENOMEM; @@ -300,8 +299,8 @@ static void rt5682_i2c_shutdown(struct i2c_client *client) struct rt5682_priv *rt5682 = i2c_get_clientdata(client); disable_irq(client->irq); - cancel_delayed_work_sync(&rt5682->jack_detect_work); - cancel_delayed_work_sync(&rt5682->jd_check_work); + disable_delayed_work_sync(&rt5682->jack_detect_work); + disable_delayed_work_sync(&rt5682->jd_check_work); rt5682_reset(rt5682); } diff --git a/sound/soc/codecs/rt5682-sdw.c b/sound/soc/codecs/rt5682-sdw.c index 5f2897c58ad7d6..ffcdce4d7b921c 100644 --- a/sound/soc/codecs/rt5682-sdw.c +++ b/sound/soc/codecs/rt5682-sdw.c @@ -301,7 +301,7 @@ static int rt5682_sdw_init(struct device *dev, struct regmap *regmap, struct rt5682_priv *rt5682; int ret; - rt5682 = devm_kzalloc(dev, sizeof(*rt5682), GFP_KERNEL); + rt5682 = devm_kzalloc_obj(dev, *rt5682); if (!rt5682) return -ENOMEM; @@ -557,9 +557,8 @@ static int rt5682_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x2; /* BITMAP: 00000010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -576,9 +575,8 @@ static int rt5682_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt5682.h b/sound/soc/codecs/rt5682.h index 74356cd7fb45d8..5516a7e220407c 100644 --- a/sound/soc/codecs/rt5682.h +++ b/sound/soc/codecs/rt5682.h @@ -1482,7 +1482,6 @@ void rt5682_jack_detect_handler(struct work_struct *work); bool rt5682_volatile_register(struct device *dev, unsigned int reg); bool rt5682_readable_register(struct device *dev, unsigned int reg); -int rt5682_register_component(struct device *dev); void rt5682_calibrate(struct rt5682_priv *rt5682); void rt5682_reset(struct rt5682_priv *rt5682); int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev); diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c index 0c669833df7c15..60f4ccd982ee21 100644 --- a/sound/soc/codecs/rt5682s.c +++ b/sound/soc/codecs/rt5682s.c @@ -3137,7 +3137,7 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c) int i, ret; unsigned int val; - rt5682s = devm_kzalloc(&i2c->dev, sizeof(struct rt5682s_priv), GFP_KERNEL); + rt5682s = devm_kzalloc_obj(&i2c->dev, struct rt5682s_priv); if (!rt5682s) return -ENOMEM; diff --git a/sound/soc/codecs/rt700-sdw.c b/sound/soc/codecs/rt700-sdw.c index 3ba0cc37acd940..48c098ab123369 100644 --- a/sound/soc/codecs/rt700-sdw.c +++ b/sound/soc/codecs/rt700-sdw.c @@ -348,9 +348,8 @@ static int rt700_read_prop(struct sdw_slave *slave) prop->sink_ports = 0xA; /* BITMAP: 00001010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -367,9 +366,8 @@ static int rt700_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt700.c b/sound/soc/codecs/rt700.c index 21523d0a5f08fc..31fb62f6273b03 100644 --- a/sound/soc/codecs/rt700.c +++ b/sound/soc/codecs/rt700.c @@ -1090,7 +1090,7 @@ int rt700_init(struct device *dev, struct regmap *sdw_regmap, struct rt700_priv *rt700; int ret; - rt700 = devm_kzalloc(dev, sizeof(*rt700), GFP_KERNEL); + rt700 = devm_kzalloc_obj(dev, *rt700); if (!rt700) return -ENOMEM; diff --git a/sound/soc/codecs/rt700.h b/sound/soc/codecs/rt700.h index 491774d207de0e..10d5b6fdb93783 100644 --- a/sound/soc/codecs/rt700.h +++ b/sound/soc/codecs/rt700.h @@ -8,8 +8,6 @@ #ifndef __RT700_H__ #define __RT700_H__ -extern const struct dev_pm_ops rt700_runtime_pm; - struct rt700_priv { struct snd_soc_component *component; struct regmap *regmap; @@ -166,6 +164,5 @@ int rt700_io_init(struct device *dev, struct sdw_slave *slave); int rt700_init(struct device *dev, struct regmap *sdw_regmap, struct regmap *regmap, struct sdw_slave *slave); -int rt700_jack_detect(struct rt700_priv *rt700, bool *hp, bool *mic); int rt700_clock_config(struct device *dev); #endif /* __RT700_H__ */ diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index f74b193c720d4f..bb8bd42d31c3a3 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -191,8 +191,8 @@ static int rt711_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x8; /* BITMAP: 00001000 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -209,8 +209,8 @@ static int rt711_sdca_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -225,8 +225,7 @@ static int rt711_sdca_read_prop(struct sdw_slave *slave) j++; } - prop->dp0_prop = devm_kzalloc(&slave->dev, sizeof(*prop->dp0_prop), - GFP_KERNEL); + prop->dp0_prop = devm_kzalloc_obj(&slave->dev, *prop->dp0_prop); if (!prop->dp0_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt711-sdca.c b/sound/soc/codecs/rt711-sdca.c index f6c8377c51ab56..54a3fd0a4e8dff 100644 --- a/sound/soc/codecs/rt711-sdca.c +++ b/sound/soc/codecs/rt711-sdca.c @@ -1485,7 +1485,7 @@ int rt711_sdca_init(struct device *dev, struct regmap *regmap, struct rt711_sdca_priv *rt711; int ret; - rt711 = devm_kzalloc(dev, sizeof(*rt711), GFP_KERNEL); + rt711 = devm_kzalloc_obj(dev, *rt711); if (!rt711) return -ENOMEM; diff --git a/sound/soc/codecs/rt711-sdca.h b/sound/soc/codecs/rt711-sdca.h index 15263dcb0314ac..710da3bef8bfb1 100644 --- a/sound/soc/codecs/rt711-sdca.h +++ b/sound/soc/codecs/rt711-sdca.h @@ -240,5 +240,4 @@ int rt711_sdca_io_init(struct device *dev, struct sdw_slave *slave); int rt711_sdca_init(struct device *dev, struct regmap *regmap, struct regmap *mbq_regmap, struct sdw_slave *slave); -int rt711_sdca_jack_detect(struct rt711_sdca_priv *rt711, bool *hp, bool *mic); #endif /* __RT711_SDCA_H__ */ diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index 798d181d5c9020..006c09b8883ac9 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -355,9 +355,8 @@ static int rt711_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x8; /* BITMAP: 00001000 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -374,9 +373,8 @@ static int rt711_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt711.c b/sound/soc/codecs/rt711.c index 3e49c3d0f25b46..c22375d36b185b 100644 --- a/sound/soc/codecs/rt711.c +++ b/sound/soc/codecs/rt711.c @@ -1172,7 +1172,7 @@ int rt711_init(struct device *dev, struct regmap *sdw_regmap, struct rt711_priv *rt711; int ret; - rt711 = devm_kzalloc(dev, sizeof(*rt711), GFP_KERNEL); + rt711 = devm_kzalloc_obj(dev, *rt711); if (!rt711) return -ENOMEM; diff --git a/sound/soc/codecs/rt711.h b/sound/soc/codecs/rt711.h index 491e357191f9d8..a82920f7db661a 100644 --- a/sound/soc/codecs/rt711.h +++ b/sound/soc/codecs/rt711.h @@ -8,8 +8,6 @@ #ifndef __RT711_H__ #define __RT711_H__ -extern const struct dev_pm_ops rt711_runtime_pm; - struct rt711_priv { struct regmap *regmap; struct regmap *sdw_regmap; @@ -246,6 +244,5 @@ int rt711_io_init(struct device *dev, struct sdw_slave *slave); int rt711_init(struct device *dev, struct regmap *sdw_regmap, struct regmap *regmap, struct sdw_slave *slave); -int rt711_jack_detect(struct rt711_priv *rt711, bool *hp, bool *mic); int rt711_clock_config(struct device *dev); #endif /* __RT711_H__ */ diff --git a/sound/soc/codecs/rt712-sdca-dmic.c b/sound/soc/codecs/rt712-sdca-dmic.c index 882390890738e2..a3ebbd65d3fe56 100644 --- a/sound/soc/codecs/rt712-sdca-dmic.c +++ b/sound/soc/codecs/rt712-sdca-dmic.c @@ -750,7 +750,7 @@ static int rt712_sdca_dmic_init(struct device *dev, struct regmap *regmap, struct rt712_sdca_dmic_priv *rt712; int ret; - rt712 = devm_kzalloc(dev, sizeof(*rt712), GFP_KERNEL); + rt712 = devm_kzalloc_obj(dev, *rt712); if (!rt712) return -ENOMEM; @@ -837,8 +837,8 @@ static int rt712_sdca_dmic_read_prop(struct sdw_slave *slave) prop->sink_ports = 0; nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt712-sdca-sdw.c b/sound/soc/codecs/rt712-sdca-sdw.c index 0f0447d1a05ba1..c0385644cd2211 100644 --- a/sound/soc/codecs/rt712-sdca-sdw.c +++ b/sound/soc/codecs/rt712-sdca-sdw.c @@ -216,8 +216,8 @@ static int rt712_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(3) | BIT(1); /* BITMAP: 00001010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -234,8 +234,8 @@ static int rt712_sdca_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt712-sdca.c b/sound/soc/codecs/rt712-sdca.c index 08e08ec96bc503..d15b1563b9ca61 100644 --- a/sound/soc/codecs/rt712-sdca.c +++ b/sound/soc/codecs/rt712-sdca.c @@ -1852,7 +1852,7 @@ int rt712_sdca_init(struct device *dev, struct regmap *regmap, struct rt712_sdca_priv *rt712; int ret; - rt712 = devm_kzalloc(dev, sizeof(*rt712), GFP_KERNEL); + rt712 = devm_kzalloc_obj(dev, *rt712); if (!rt712) return -ENOMEM; diff --git a/sound/soc/codecs/rt712-sdca.h b/sound/soc/codecs/rt712-sdca.h index 7e6ee21c8a172d..80c50bf2dc900d 100644 --- a/sound/soc/codecs/rt712-sdca.h +++ b/sound/soc/codecs/rt712-sdca.h @@ -282,5 +282,4 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave); int rt712_sdca_init(struct device *dev, struct regmap *regmap, struct regmap *mbq_regmap, struct sdw_slave *slave); -int rt712_sdca_jack_detect(struct rt712_sdca_priv *rt712, bool *hp, bool *mic); #endif /* __RT712_H__ */ diff --git a/sound/soc/codecs/rt715-sdca-sdw.c b/sound/soc/codecs/rt715-sdca-sdw.c index 1b183b21a4b8ce..49926c6d420de4 100644 --- a/sound/soc/codecs/rt715-sdca-sdw.c +++ b/sound/soc/codecs/rt715-sdca-sdw.c @@ -146,9 +146,8 @@ static int rt715_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x0; /* BITMAP: 00000000 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt715-sdca.c b/sound/soc/codecs/rt715-sdca.c index b6a7a807a42866..15f6a97044d9a2 100644 --- a/sound/soc/codecs/rt715-sdca.c +++ b/sound/soc/codecs/rt715-sdca.c @@ -961,7 +961,7 @@ int rt715_sdca_init(struct device *dev, struct regmap *mbq_regmap, struct rt715_sdca_priv *rt715; int ret; - rt715 = devm_kzalloc(dev, sizeof(*rt715), GFP_KERNEL); + rt715 = devm_kzalloc_obj(dev, *rt715); if (!rt715) return -ENOMEM; diff --git a/sound/soc/codecs/rt715-sdw.c b/sound/soc/codecs/rt715-sdw.c index f5ec348a9628c1..83a101fa1ded62 100644 --- a/sound/soc/codecs/rt715-sdw.c +++ b/sound/soc/codecs/rt715-sdw.c @@ -406,9 +406,8 @@ static int rt715_read_prop(struct sdw_slave *slave) prop->sink_ports = 0x0; /* BITMAP: 00000000 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt715.c b/sound/soc/codecs/rt715.c index 0881826de2f16b..2a52ce3618de44 100644 --- a/sound/soc/codecs/rt715.c +++ b/sound/soc/codecs/rt715.c @@ -1013,7 +1013,7 @@ int rt715_init(struct device *dev, struct regmap *sdw_regmap, struct rt715_priv *rt715; int ret; - rt715 = devm_kzalloc(dev, sizeof(*rt715), GFP_KERNEL); + rt715 = devm_kzalloc_obj(dev, *rt715); if (!rt715) return -ENOMEM; diff --git a/sound/soc/codecs/rt721-sdca-sdw.c b/sound/soc/codecs/rt721-sdca-sdw.c index 0c78799793bda8..9e2bfb40880502 100644 --- a/sound/soc/codecs/rt721-sdca-sdw.c +++ b/sound/soc/codecs/rt721-sdca-sdw.c @@ -39,6 +39,14 @@ static bool rt721_sdca_readable_register(struct device *dev, unsigned int reg) RT721_SDCA_CTL_HIDTX_CURRENT_OWNER, 0) ... SDW_SDCA_CTL(FUNC_NUM_HID, RT721_SDCA_ENT_HID01, RT721_SDCA_CTL_HIDTX_MESSAGE_LENGTH, 0): case RT721_BUF_ADDR_HID1 ... RT721_BUF_ADDR_HID2: + case SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE41, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): case SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT0, RT721_SDCA_CTL_FUNC_STATUS, 0): return true; @@ -64,6 +72,14 @@ static bool rt721_sdca_volatile_register(struct device *dev, unsigned int reg) RT721_SDCA_CTL_HIDTX_CURRENT_OWNER, 0) ... SDW_SDCA_CTL(FUNC_NUM_HID, RT721_SDCA_ENT_HID01, RT721_SDCA_CTL_HIDTX_MESSAGE_LENGTH, 0): case RT721_BUF_ADDR_HID1 ... RT721_BUF_ADDR_HID2: + case SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): + case SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE41, + RT721_SDCA_CTL_ACTUAL_POWER_STATE, 0): case SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT0, RT721_SDCA_CTL_FUNC_STATUS, 0): return true; @@ -279,8 +295,8 @@ static int rt721_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(3) | BIT(1); /* BITMAP: 00001010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -297,8 +313,8 @@ static int rt721_sdca_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -593,3 +609,4 @@ module_sdw_driver(rt721_sdca_sdw_driver); MODULE_DESCRIPTION("ASoC RT721 SDCA SDW driver"); MODULE_AUTHOR("Jack Yu "); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("SND_SOC_SDCA"); diff --git a/sound/soc/codecs/rt721-sdca.c b/sound/soc/codecs/rt721-sdca.c index 82ef8245474cb3..8bca6b55397702 100644 --- a/sound/soc/codecs/rt721-sdca.c +++ b/sound/soc/codecs/rt721-sdca.c @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include #include @@ -1493,6 +1496,32 @@ static int rt721_sdca_fu36_event(struct snd_soc_dapm_widget *w, return 0; } +/* The DisCo tables give the jack function PDEs up to 500 ms for PS3 to PS0 */ +static const struct sdca_pde_delay rt721_jack_pde_delays[] = { + { .from_ps = SDCA_PDE_PS3, .to_ps = SDCA_PDE_PS0, .us = 500000 }, +}; + +/* REQUESTED_PS only starts the transition, so wait for ACTUAL_PS to reach PS0 */ +static void rt721_sdca_pde_wait_ps0(struct rt721_sdca_priv *rt721, + unsigned char func, unsigned char entity) +{ + const struct sdca_pde_delay *delays = NULL; + int num_delays = 0; + int ret; + + if (func == FUNC_NUM_JACK_CODEC) { + delays = rt721_jack_pde_delays; + num_delays = ARRAY_SIZE(rt721_jack_pde_delays); + } + + ret = sdca_asoc_pde_poll_actual_ps(rt721->regmap, func, entity, + SDCA_PDE_PS3, SDCA_PDE_PS0, + delays, num_delays); + if (ret) + dev_warn(&rt721->slave->dev, "PDE 0x%x did not reach PS0: %d\n", + entity, ret); +} + static int rt721_sdca_pde47_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { @@ -1506,6 +1535,7 @@ static int rt721_sdca_pde47_event(struct snd_soc_dapm_widget *w, regmap_write(rt721->regmap, SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40, RT721_SDCA_CTL_REQ_POWER_STATE, 0), ps0); + rt721_sdca_pde_wait_ps0(rt721, FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40); break; case SND_SOC_DAPM_PRE_PMD: regmap_write(rt721->regmap, @@ -1529,6 +1559,7 @@ static int rt721_sdca_pde41_event(struct snd_soc_dapm_widget *w, regmap_write(rt721->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE41, RT721_SDCA_CTL_REQ_POWER_STATE, 0), ps0); + rt721_sdca_pde_wait_ps0(rt721, FUNC_NUM_AMP, RT721_SDCA_ENT_PDE41); break; case SND_SOC_DAPM_PRE_PMD: regmap_write(rt721->regmap, @@ -1552,6 +1583,7 @@ static int rt721_sdca_pde11_event(struct snd_soc_dapm_widget *w, regmap_write(rt721->regmap, SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A, RT721_SDCA_CTL_REQ_POWER_STATE, 0), ps0); + rt721_sdca_pde_wait_ps0(rt721, FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A); break; case SND_SOC_DAPM_PRE_PMD: regmap_write(rt721->regmap, @@ -1575,6 +1607,7 @@ static int rt721_sdca_pde34_event(struct snd_soc_dapm_widget *w, regmap_write(rt721->regmap, SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12, RT721_SDCA_CTL_REQ_POWER_STATE, 0), ps0); + rt721_sdca_pde_wait_ps0(rt721, FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12); break; case SND_SOC_DAPM_PRE_PMD: regmap_write(rt721->regmap, @@ -1948,7 +1981,7 @@ int rt721_sdca_init(struct device *dev, struct regmap *regmap, { struct rt721_sdca_priv *rt721; - rt721 = devm_kzalloc(dev, sizeof(*rt721), GFP_KERNEL); + rt721 = devm_kzalloc_obj(dev, *rt721); if (!rt721) return -ENOMEM; diff --git a/sound/soc/codecs/rt721-sdca.h b/sound/soc/codecs/rt721-sdca.h index cc3bce0ba51786..2ae68ce3fde281 100644 --- a/sound/soc/codecs/rt721-sdca.h +++ b/sound/soc/codecs/rt721-sdca.h @@ -260,6 +260,7 @@ struct rt721_sdca_dmic_kctrl_priv { #define RT721_SDCA_CTL_XUV 0x34 #define RT721_SDCA_CTL_FU_CH_GAIN 0x0b #define RT721_SDCA_CTL_FUNC_STATUS 0x10 +#define RT721_SDCA_CTL_ACTUAL_POWER_STATE 0x10 /* RT721 SDCA channel */ #define CH_L 0x01 diff --git a/sound/soc/codecs/rt722-sdca-sdw.c b/sound/soc/codecs/rt722-sdca-sdw.c index 078255fbe1fc3c..5c17426bc2fc55 100644 --- a/sound/soc/codecs/rt722-sdca-sdw.c +++ b/sound/soc/codecs/rt722-sdca-sdw.c @@ -304,8 +304,8 @@ static int rt722_sdca_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(3) | BIT(1); /* BITMAP: 00001010 */ nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -322,8 +322,8 @@ static int rt722_sdca_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; diff --git a/sound/soc/codecs/rt722-sdca.c b/sound/soc/codecs/rt722-sdca.c index 2d47420c0505b1..7f087bff48ef57 100644 --- a/sound/soc/codecs/rt722-sdca.c +++ b/sound/soc/codecs/rt722-sdca.c @@ -1631,7 +1631,7 @@ int rt722_sdca_init(struct device *dev, struct regmap *regmap, struct sdw_slave { struct rt722_sdca_priv *rt722; - rt722 = devm_kzalloc(dev, sizeof(*rt722), GFP_KERNEL); + rt722 = devm_kzalloc_obj(dev, *rt722); if (!rt722) return -ENOMEM; diff --git a/sound/soc/codecs/rt722-sdca.h b/sound/soc/codecs/rt722-sdca.h index dd245ae9bd445b..105aa9bc570693 100644 --- a/sound/soc/codecs/rt722-sdca.h +++ b/sound/soc/codecs/rt722-sdca.h @@ -275,5 +275,4 @@ int rt722_sdca_index_write(struct rt722_sdca_priv *rt722, int rt722_sdca_index_read(struct rt722_sdca_priv *rt722, unsigned int nid, unsigned int reg, unsigned int *value); -int rt722_sdca_jack_detect(struct rt722_sdca_priv *rt722, bool *hp, bool *mic); #endif /* __RT722_H__ */ diff --git a/sound/soc/codecs/rt766-sdca.c b/sound/soc/codecs/rt766-sdca.c index 2e891b99dc2721..547c55e307ab85 100644 --- a/sound/soc/codecs/rt766-sdca.c +++ b/sound/soc/codecs/rt766-sdca.c @@ -1153,7 +1153,7 @@ int rt766_sdca_init(struct device *dev, struct regmap *regmap, struct sdw_slave int ret; int i; - rt766 = devm_kzalloc(dev, sizeof(*rt766), GFP_KERNEL); + rt766 = devm_kzalloc_obj(dev, *rt766); if (!rt766) return -ENOMEM; @@ -1196,7 +1196,7 @@ int rt766_sdca_init(struct device *dev, struct regmap *regmap, struct sdw_slave /* get SDCA function data */ dev_dbg(dev, "SDCA functions found: %d", slave->sdca_data.num_functions); for (i = 0; i < slave->sdca_data.num_functions; i++) { - func_data_ptr = devm_kzalloc(dev, sizeof(*func_data_ptr), GFP_KERNEL); + func_data_ptr = devm_kzalloc_obj(dev, *func_data_ptr); if (!func_data_ptr) { dev_err(dev, "Failed to allocate memory for function data\n"); ret = -ENOMEM; diff --git a/sound/soc/codecs/rt9120.c b/sound/soc/codecs/rt9120.c index 1445e823c4ff03..5dc34034dd1d35 100644 --- a/sound/soc/codecs/rt9120.c +++ b/sound/soc/codecs/rt9120.c @@ -528,7 +528,7 @@ static int rt9120_probe(struct i2c_client *i2c) struct regulator *dvdd_supply; int dvdd_supply_volt, ret; - data = devm_kzalloc(&i2c->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&i2c->dev, *data); if (!data) return -ENOMEM; @@ -588,9 +588,13 @@ static int rt9120_probe(struct i2c_client *i2c) pm_runtime_mark_last_busy(&i2c->dev); pm_runtime_enable(&i2c->dev); - return devm_snd_soc_register_component(&i2c->dev, - &rt9120_component_driver, - &rt9120_dai, 1); + ret = devm_snd_soc_register_component(&i2c->dev, + &rt9120_component_driver, + &rt9120_dai, 1); + if (ret) + pm_runtime_disable(&i2c->dev); + + return ret; } static void rt9120_remove(struct i2c_client *i2c) diff --git a/sound/soc/codecs/rt9123.c b/sound/soc/codecs/rt9123.c index 251bad450ec8a6..f71742f8e5e74d 100644 --- a/sound/soc/codecs/rt9123.c +++ b/sound/soc/codecs/rt9123.c @@ -395,7 +395,7 @@ static int rt9123_i2c_probe(struct i2c_client *i2c) u16 venid; int ret; - rt9123 = devm_kzalloc(dev, sizeof(*rt9123), GFP_KERNEL); + rt9123 = devm_kzalloc_obj(dev, *rt9123); if (!rt9123) return -ENOMEM; diff --git a/sound/soc/codecs/rt9123p.c b/sound/soc/codecs/rt9123p.c index 584fcb78cd3f0f..b4cde65318069b 100644 --- a/sound/soc/codecs/rt9123p.c +++ b/sound/soc/codecs/rt9123p.c @@ -120,7 +120,7 @@ static int rt9123p_platform_probe(struct platform_device *pdev) struct rt9123p_priv *rt9123p; int ret; - rt9123p = devm_kzalloc(dev, sizeof(*rt9123p), GFP_KERNEL); + rt9123p = devm_kzalloc_obj(dev, *rt9123p); if (!rt9123p) return -ENOMEM; diff --git a/sound/soc/codecs/rtq9124.c b/sound/soc/codecs/rtq9124.c index cc1c68752fde4a..19ccca4738d052 100644 --- a/sound/soc/codecs/rtq9124.c +++ b/sound/soc/codecs/rtq9124.c @@ -442,7 +442,7 @@ static int rtq9124_probe(struct i2c_client *i2c) struct regmap *regmap; int ret; - rtq9124 = devm_kzalloc(dev, sizeof(*rtq9124), GFP_KERNEL); + rtq9124 = devm_kzalloc_obj(dev, *rtq9124); if (!rtq9124) return -ENOMEM; diff --git a/sound/soc/codecs/rtq9128.c b/sound/soc/codecs/rtq9128.c index 9567e90c0b62a3..a6d4a81ff1813c 100644 --- a/sound/soc/codecs/rtq9128.c +++ b/sound/soc/codecs/rtq9128.c @@ -778,7 +778,7 @@ static int rtq9128_probe(struct i2c_client *i2c) const struct snd_soc_component_driver *comp_drv; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/codecs/sdw-mockup.c b/sound/soc/codecs/sdw-mockup.c index 93f3fd1882a595..ff6917502138a3 100644 --- a/sound/soc/codecs/sdw-mockup.c +++ b/sound/soc/codecs/sdw-mockup.c @@ -151,9 +151,8 @@ static int sdw_mockup_read_prop(struct sdw_slave *slave) prop->sink_ports = BIT(1); nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), - GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; @@ -169,9 +168,8 @@ static int sdw_mockup_read_prop(struct sdw_slave *slave) /* do this again for sink now */ nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), - GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; @@ -219,7 +217,7 @@ static int sdw_mockup_sdw_probe(struct sdw_slave *slave, struct sdw_mockup_priv *sdw_mockup; int ret; - sdw_mockup = devm_kzalloc(dev, sizeof(*sdw_mockup), GFP_KERNEL); + sdw_mockup = devm_kzalloc_obj(dev, *sdw_mockup); if (!sdw_mockup) return -ENOMEM; diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index 97bea75ed24f00..c4f6c60bc5b54b 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c @@ -1597,7 +1597,7 @@ static int sgtl5000_i2c_probe(struct i2c_client *client) u32 value; u16 ana_pwr; - sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL); + sgtl5000 = devm_kzalloc_obj(&client->dev, *sgtl5000); if (!sgtl5000) return -ENOMEM; diff --git a/sound/soc/codecs/sigmadsp.c b/sound/soc/codecs/sigmadsp.c index 4ecbbac9325882..24a463ed053a2d 100644 --- a/sound/soc/codecs/sigmadsp.c +++ b/sound/soc/codecs/sigmadsp.c @@ -299,7 +299,7 @@ static int sigma_fw_load_samplerates(struct sigmadsp *sigmadsp, if (sigmadsp->rate_constraints.count) return -EINVAL; - rates = kcalloc(num_rates, sizeof(*rates), GFP_KERNEL); + rates = kzalloc_objs(*rates, num_rates); if (!rates) return -ENOMEM; diff --git a/sound/soc/codecs/simple-amplifier.c b/sound/soc/codecs/simple-amplifier.c index 07c040355c377b..0df04c6cf3865f 100644 --- a/sound/soc/codecs/simple-amplifier.c +++ b/sound/soc/codecs/simple-amplifier.c @@ -682,9 +682,8 @@ static int simple_amp_parse_ranges(struct device *dev, if (ranges->nb_ranges > max_gpio_val + 1) return -EINVAL; - ranges->tab_ranges = devm_kcalloc(dev, ranges->nb_ranges, - sizeof(*ranges->tab_ranges), - GFP_KERNEL); + ranges->tab_ranges = devm_kzalloc_objs(dev, *ranges->tab_ranges, + ranges->nb_ranges); if (!ranges->tab_ranges) return -ENOMEM; @@ -798,9 +797,8 @@ static int simple_amp_parse_labels(struct device *dev, if (labels->nb_labels > (1 << multi->gpios->ndescs)) return -EINVAL; - labels->tab_labels = devm_kcalloc(dev, labels->nb_labels, - sizeof(*labels->tab_labels), - GFP_KERNEL); + labels->tab_labels = devm_kzalloc_objs(dev, *labels->tab_labels, + labels->nb_labels); if (!labels->tab_labels) return -ENOMEM; @@ -863,7 +861,7 @@ static int simple_amp_probe(struct platform_device *pdev) struct simple_amp *simple_amp; int ret; - simple_amp = devm_kzalloc(dev, sizeof(*simple_amp), GFP_KERNEL); + simple_amp = devm_kzalloc_obj(dev, *simple_amp); if (!simple_amp) return -ENOMEM; platform_set_drvdata(pdev, simple_amp); diff --git a/sound/soc/codecs/simple-mux.c b/sound/soc/codecs/simple-mux.c index c2f906a3f074ce..2a2722dbc3a38a 100644 --- a/sound/soc/codecs/simple-mux.c +++ b/sound/soc/codecs/simple-mux.c @@ -124,7 +124,7 @@ static int simple_mux_probe(struct platform_device *pdev) struct simple_mux *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/sma1303.c b/sound/soc/codecs/sma1303.c index 0bff325597143e..5768e7639031a6 100644 --- a/sound/soc/codecs/sma1303.c +++ b/sound/soc/codecs/sma1303.c @@ -1683,8 +1683,7 @@ static int sma1303_i2c_probe(struct i2c_client *client) int ret, i = 0; unsigned int device_info, status, otp_stat; - sma1303 = devm_kzalloc(&client->dev, - sizeof(struct sma1303_priv), GFP_KERNEL); + sma1303 = devm_kzalloc_obj(&client->dev, struct sma1303_priv); if (!sma1303) return -ENOMEM; sma1303->dev = &client->dev; diff --git a/sound/soc/codecs/sma1307.c b/sound/soc/codecs/sma1307.c index 57f34f2c5efb87..8b6ba2d3d83517 100644 --- a/sound/soc/codecs/sma1307.c +++ b/sound/soc/codecs/sma1307.c @@ -1956,8 +1956,7 @@ static int sma1307_i2c_probe(struct i2c_client *client) int ret = 0; unsigned int device_info; - sma1307 = devm_kzalloc(&client->dev, - sizeof(*sma1307), GFP_KERNEL); + sma1307 = devm_kzalloc_obj(&client->dev, *sma1307); if (!sma1307) return -ENOMEM; diff --git a/sound/soc/codecs/sn624x-sdca-sdw.c b/sound/soc/codecs/sn624x-sdca-sdw.c index 65ea90e440008e..af6c0e7769b1e9 100644 --- a/sound/soc/codecs/sn624x-sdca-sdw.c +++ b/sound/soc/codecs/sn624x-sdca-sdw.c @@ -738,7 +738,7 @@ static int sn624x_parse_sdca_functions(struct sn624x_sdca_priv *sn624x) if (!is_jack && !is_mic && !is_amp) continue; - fn = devm_kzalloc(dev, sizeof(*fn), GFP_KERNEL); + fn = devm_kzalloc_obj(dev, *fn); if (!fn) return -ENOMEM; @@ -1259,8 +1259,8 @@ static int sn624x_sdca_read_prop(struct sdw_slave *slave) BIT(SN624X_PORT_SPEAKER_PLAYBACK); nval = hweight32(prop->source_ports); - prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->src_dpn_prop), GFP_KERNEL); + prop->src_dpn_prop = devm_kzalloc_objs(&slave->dev, *prop->src_dpn_prop, + nval); if (!prop->src_dpn_prop) return -ENOMEM; i = 0; @@ -1274,8 +1274,8 @@ static int sn624x_sdca_read_prop(struct sdw_slave *slave) i++; } nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), GFP_KERNEL); + prop->sink_dpn_prop = devm_kzalloc_objs(&slave->dev, + *prop->sink_dpn_prop, nval); if (!prop->sink_dpn_prop) return -ENOMEM; j = 0; @@ -1693,7 +1693,7 @@ int sn624x_sdca_init(struct device *dev, struct regmap *regmap, struct sn624x_sdca_priv *sn624x; int ret; - sn624x = devm_kzalloc(dev, sizeof(*sn624x), GFP_KERNEL); + sn624x = devm_kzalloc_obj(dev, *sn624x); if (!sn624x) return -ENOMEM; @@ -1769,6 +1769,8 @@ static void sn624x_sdca_sdw_remove(struct sdw_slave *slave) static const struct sdw_device_id sn624x_sdca_id[] = { SDW_SLAVE_ENTRY_EXT(0x0496, 0x6242, 0x3, 0x1, 0), SDW_SLAVE_ENTRY_EXT(0x0496, 0x6244, 0x3, 0x1, 0), + /* SN6245 is register-compatible with SN6244 (jack/amp/dmic). */ + SDW_SLAVE_ENTRY_EXT(0x0496, 0x6245, 0x3, 0x1, 0), SDW_SLAVE_ENTRY_EXT(0x0496, 0x6247, 0x3, 0x1, 0), { } }; diff --git a/sound/soc/codecs/src4xxx.c b/sound/soc/codecs/src4xxx.c index 6e187c930372ff..373e5d86768c89 100644 --- a/sound/soc/codecs/src4xxx.c +++ b/sound/soc/codecs/src4xxx.c @@ -429,7 +429,7 @@ int src4xxx_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(regmap)) return PTR_ERR(regmap); - src4xxx = devm_kzalloc(dev, sizeof(*src4xxx), GFP_KERNEL); + src4xxx = devm_kzalloc_obj(dev, *src4xxx); if (!src4xxx) return -ENOMEM; diff --git a/sound/soc/codecs/ssm2305.c b/sound/soc/codecs/ssm2305.c index 1d022643c307f5..c7162307849431 100644 --- a/sound/soc/codecs/ssm2305.c +++ b/sound/soc/codecs/ssm2305.c @@ -59,7 +59,7 @@ static int ssm2305_probe(struct platform_device *pdev) struct ssm2305 *priv; /* Allocate the private data */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/ssm2518.c b/sound/soc/codecs/ssm2518.c index 32e81b31479d14..16d26baa440fa6 100644 --- a/sound/soc/codecs/ssm2518.c +++ b/sound/soc/codecs/ssm2518.c @@ -752,7 +752,7 @@ static int ssm2518_i2c_probe(struct i2c_client *i2c) struct ssm2518 *ssm2518; int ret; - ssm2518 = devm_kzalloc(&i2c->dev, sizeof(*ssm2518), GFP_KERNEL); + ssm2518 = devm_kzalloc_obj(&i2c->dev, *ssm2518); if (ssm2518 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index 92df44f869155e..10fda1f99ed7bd 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c @@ -689,7 +689,7 @@ int ssm2602_probe(struct device *dev, enum ssm2602_type type, if (IS_ERR(regmap)) return PTR_ERR(regmap); - ssm2602 = devm_kzalloc(dev, sizeof(*ssm2602), GFP_KERNEL); + ssm2602 = devm_kzalloc_obj(dev, *ssm2602); if (ssm2602 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/ssm3515.c b/sound/soc/codecs/ssm3515.c index f71509237fca4d..8dafcaf30446df 100644 --- a/sound/soc/codecs/ssm3515.c +++ b/sound/soc/codecs/ssm3515.c @@ -413,7 +413,7 @@ static int ssm3515_i2c_probe(struct i2c_client *client) struct ssm3515_data *data; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/codecs/ssm4567.c b/sound/soc/codecs/ssm4567.c index 181047b38d3df8..2628e291a97062 100644 --- a/sound/soc/codecs/ssm4567.c +++ b/sound/soc/codecs/ssm4567.c @@ -462,7 +462,7 @@ static int ssm4567_i2c_probe(struct i2c_client *i2c) struct ssm4567 *ssm4567; int ret; - ssm4567 = devm_kzalloc(&i2c->dev, sizeof(*ssm4567), GFP_KERNEL); + ssm4567 = devm_kzalloc_obj(&i2c->dev, *ssm4567); if (ssm4567 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c index 773a9b203456b4..0d65912ecd1041 100644 --- a/sound/soc/codecs/sta32x.c +++ b/sound/soc/codecs/sta32x.c @@ -1099,7 +1099,7 @@ static int sta32x_probe_dt(struct device *dev, struct sta32x_priv *sta32x) struct sta32x_platform_data *pdata; u32 tmp; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -1151,8 +1151,7 @@ static int sta32x_i2c_probe(struct i2c_client *i2c) struct sta32x_priv *sta32x; int ret, i; - sta32x = devm_kzalloc(&i2c->dev, sizeof(struct sta32x_priv), - GFP_KERNEL); + sta32x = devm_kzalloc_obj(&i2c->dev, struct sta32x_priv); if (!sta32x) return -ENOMEM; diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c index acf5dc61839868..a0afc199abe126 100644 --- a/sound/soc/codecs/sta350.c +++ b/sound/soc/codecs/sta350.c @@ -1099,7 +1099,7 @@ static int sta350_probe_dt(struct device *dev, struct sta350_priv *sta350) u32 tmp; u8 tmp8; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -1188,7 +1188,7 @@ static int sta350_i2c_probe(struct i2c_client *i2c) struct sta350_priv *sta350; int ret, i; - sta350 = devm_kzalloc(dev, sizeof(struct sta350_priv), GFP_KERNEL); + sta350 = devm_kzalloc_obj(dev, struct sta350_priv); if (!sta350) return -ENOMEM; diff --git a/sound/soc/codecs/sta529.c b/sound/soc/codecs/sta529.c index 0faf439ffee9b9..d89a49ea9b9f6f 100644 --- a/sound/soc/codecs/sta529.c +++ b/sound/soc/codecs/sta529.c @@ -346,7 +346,7 @@ static int sta529_i2c_probe(struct i2c_client *i2c) struct sta529 *sta529; int ret; - sta529 = devm_kzalloc(&i2c->dev, sizeof(struct sta529), GFP_KERNEL); + sta529 = devm_kzalloc_obj(&i2c->dev, struct sta529); if (!sta529) return -ENOMEM; diff --git a/sound/soc/codecs/sti-sas.c b/sound/soc/codecs/sti-sas.c index b7eaf4795d8ba5..f9f0b681118fcb 100644 --- a/sound/soc/codecs/sti-sas.c +++ b/sound/soc/codecs/sti-sas.c @@ -406,8 +406,7 @@ static int sti_sas_driver_probe(struct platform_device *pdev) const struct of_device_id *of_id; /* Allocate device structure */ - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct sti_sas_data), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct sti_sas_data); if (!drvdata) return -ENOMEM; diff --git a/sound/soc/codecs/tac5xx2-sdw.c b/sound/soc/codecs/tac5xx2-sdw.c index a5f654cde69fc4..43584bebdafeef 100644 --- a/sound/soc/codecs/tac5xx2-sdw.c +++ b/sound/soc/codecs/tac5xx2-sdw.c @@ -1441,8 +1441,7 @@ static s32 tac_init(struct tac5xx2_prv *tac_dev) return -EINVAL; } - component_driver = devm_kzalloc(tac_dev->dev, sizeof(*component_driver), - GFP_KERNEL); + component_driver = devm_kzalloc_obj(tac_dev->dev, *component_driver); if (!component_driver) return -ENOMEM; @@ -1934,7 +1933,7 @@ static s32 tac_sdw_probe(struct sdw_slave *peripheral, struct regmap *regmap; int ret, i; - tac_dev = devm_kzalloc(dev, sizeof(*tac_dev), GFP_KERNEL); + tac_dev = devm_kzalloc_obj(dev, *tac_dev); if (!tac_dev) return dev_err_probe(dev, -ENOMEM, "Failed devm_kzalloc"); @@ -1968,8 +1967,7 @@ static s32 tac_sdw_probe(struct sdw_slave *peripheral, continue; } - function_data = devm_kzalloc(dev, sizeof(*function_data), - GFP_KERNEL); + function_data = devm_kzalloc_obj(dev, *function_data); if (!function_data) return dev_err_probe(dev, -ENOMEM, "failed to allocate %s function data", diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c index beb5654ac4b418..7fda383043ed50 100644 --- a/sound/soc/codecs/tas2552.c +++ b/sound/soc/codecs/tas2552.c @@ -714,7 +714,7 @@ static int tas2552_probe(struct i2c_client *client) int i; dev = &client->dev; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (data == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/tas2562.c b/sound/soc/codecs/tas2562.c index 1fe17b0895fcd6..038e89bc708ef0 100644 --- a/sound/soc/codecs/tas2562.c +++ b/sound/soc/codecs/tas2562.c @@ -751,7 +751,7 @@ static int tas2562_probe(struct i2c_client *client) struct tas2562_data *data; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c index 6654100ac91d15..17b993883185c0 100644 --- a/sound/soc/codecs/tas2764.c +++ b/sound/soc/codecs/tas2764.c @@ -998,8 +998,7 @@ static int tas2764_i2c_probe(struct i2c_client *client) struct tas2764_priv *tas2764; int result; - tas2764 = devm_kzalloc(&client->dev, sizeof(struct tas2764_priv), - GFP_KERNEL); + tas2764 = devm_kzalloc_obj(&client->dev, struct tas2764_priv); if (!tas2764) return -ENOMEM; diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c index b9cf43f43ddae7..96c4e3daffd930 100644 --- a/sound/soc/codecs/tas2770.c +++ b/sound/soc/codecs/tas2770.c @@ -923,8 +923,7 @@ static int tas2770_i2c_probe(struct i2c_client *client) struct tas2770_priv *tas2770; int result; - tas2770 = devm_kzalloc(&client->dev, sizeof(struct tas2770_priv), - GFP_KERNEL); + tas2770 = devm_kzalloc_obj(&client->dev, struct tas2770_priv); if (!tas2770) return -ENOMEM; diff --git a/sound/soc/codecs/tas2780.c b/sound/soc/codecs/tas2780.c index 991d0c0efee2df..ca6beb41375c8f 100644 --- a/sound/soc/codecs/tas2780.c +++ b/sound/soc/codecs/tas2780.c @@ -600,8 +600,7 @@ static int tas2780_i2c_probe(struct i2c_client *client) struct tas2780_priv *tas2780; int result; - tas2780 = devm_kzalloc(&client->dev, sizeof(struct tas2780_priv), - GFP_KERNEL); + tas2780 = devm_kzalloc_obj(&client->dev, struct tas2780_priv); if (!tas2780) return -ENOMEM; tas2780->dev = &client->dev; diff --git a/sound/soc/codecs/tas2781-comlib-i2c.c b/sound/soc/codecs/tas2781-comlib-i2c.c index 46777be765efb7..9b37627a16af75 100644 --- a/sound/soc/codecs/tas2781-comlib-i2c.c +++ b/sound/soc/codecs/tas2781-comlib-i2c.c @@ -147,7 +147,7 @@ struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c) { struct tasdevice_priv *tas_priv; - tas_priv = devm_kzalloc(&i2c->dev, sizeof(*tas_priv), GFP_KERNEL); + tas_priv = devm_kzalloc_obj(&i2c->dev, *tas_priv); if (!tas_priv) return NULL; tas_priv->dev = &i2c->dev; diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c index f309a57337b004..527d5e0ab906fd 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -2564,7 +2564,7 @@ static int tas2781_cali_preproc(struct tasdevice_priv *priv, int i) int re_org, re_cal, corrected_sin_gn, pg_id; unsigned char r0_deflt[4]; - spec = devm_kzalloc(priv->dev, sizeof(*spec), GFP_KERNEL); + spec = devm_kzalloc_obj(priv->dev, *spec); if (spec == NULL) return -ENOMEM; priv->tasdevice[i].cali_specific = spec; @@ -2579,7 +2579,7 @@ static int tas2781_cali_preproc(struct tasdevice_priv *priv, int i) */ re_org = r0_deflt[0] << 8 | r0_deflt[1]; re_cal = data[k + 1] << 8 | data[k + 2]; - if (re_org > re_cal) { + if (re_cal && re_org > re_cal) { rc = tasdevice_dev_read(priv, i, TAS2781_PG_REG, &pg_id); if (rc < 0) { diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c index 995bfd52f5fcff..e44a1d460c703d 100644 --- a/sound/soc/codecs/tas2781-i2c.c +++ b/sound/soc/codecs/tas2781-i2c.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1237,8 +1238,8 @@ static int tasdevice_create_control(struct tasdevice_priv *tas_priv) int ret; char *name; - prof_ctrls = devm_kcalloc(tas_priv->dev, nr_controls, - sizeof(prof_ctrls[0]), GFP_KERNEL); + prof_ctrls = devm_kzalloc_objs(tas_priv->dev, prof_ctrls[0], + nr_controls); if (!prof_ctrls) { ret = -ENOMEM; goto out; @@ -1269,8 +1270,8 @@ static int tasdevice_create_control(struct tasdevice_priv *tas_priv) case TAS2573: case TAS2574: case TAS2781: - prof_ctrls = devm_kcalloc(tas_priv->dev, nr_controls, - sizeof(prof_ctrls[0]), GFP_KERNEL); + prof_ctrls = devm_kzalloc_objs(tas_priv->dev, prof_ctrls[0], + nr_controls); if (!prof_ctrls) { ret = -ENOMEM; goto out; @@ -1399,8 +1400,7 @@ static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) /* Alloc kcontrol via devm_kzalloc, which don't manually * free the kcontrol */ - dsp_ctrls = devm_kcalloc(tas_priv->dev, nr_controls, - sizeof(dsp_ctrls[0]), GFP_KERNEL); + dsp_ctrls = devm_kzalloc_objs(tas_priv->dev, dsp_ctrls[0], nr_controls); if (!dsp_ctrls) return -ENOMEM; @@ -1514,8 +1514,7 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv struct soc_bytes_ext *ext_cali_start; char *cali_start_name; - ext_cali_start = devm_kzalloc(priv->dev, - sizeof(*ext_cali_start), GFP_KERNEL); + ext_cali_start = devm_kzalloc_obj(priv->dev, *ext_cali_start); if (!ext_cali_start) return -ENOMEM; @@ -1545,37 +1544,62 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv return 0; } -static int tas2573_re_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) +/* + * Common helper: shared by all controls that read a group of registers and + * pack the results into a report. + */ +static int tas2573_status_get_common(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, const struct tasdev_reg_map *map) { struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol); struct tasdevice_priv *priv = snd_soc_component_get_drvdata(comp); unsigned char *dst = ucontrol->value.bytes.data; struct soc_bytes_ext *bytes_ext = - (struct soc_bytes_ext *) kcontrol->private_value; + (struct soc_bytes_ext *)kcontrol->private_value; + unsigned int j, k, val; unsigned int i = 0; - unsigned int j; int rc; - guard(mutex)(&priv->codec_lock); + /* Report header: max size and 'r' marker */ dst[i++] = bytes_ext->max; dst[i++] = 'r'; - dst[i++] = TASDEVICE_BOOK_ID(TAS2573_RE_OUT); - dst[i++] = TASDEVICE_PAGE_ID(TAS2573_RE_OUT); - dst[i++] = TASDEVICE_PAGE_REG(TAS2573_RE_OUT); - + /* Emit book/page/reg triplets for every register in the map */ + for (j = 0; j < map->nregs; j++) { + dst[i++] = TASDEVICE_BOOK_ID(map->regs[j]); + dst[i++] = TASDEVICE_PAGE_ID(map->regs[j]); + dst[i++] = TASDEVICE_PAGE_REG(map->regs[j]); + } dst[i++] = 'D'; + guard(mutex)(&priv->codec_lock); + + /* + * Read each channel: first register via single read, the rest + * via bulk read (4 bytes each). + */ for (j = 0; j < priv->ndev; j++) { dst[i++] = j; + dst[i++] = 0; + dst[i++] = 0; + dst[i++] = 0; - rc = tasdevice_dev_bulk_read(priv, j, TAS2573_RE_OUT, - &dst[i], 4); + rc = tasdevice_dev_read(priv, j, map->regs[0], &val); if (rc < 0) - dev_err(priv->dev, "chn %d bulk_rd err = %d\n", j, rc); + dev_err(priv->dev, + "chn %d %s[0] rd err = %d\n", + j, map->tag, rc); + else + dst[i++] = val; - i += 4; + for (k = 1; k < map->nregs; k++, i += 4) { + rc = tasdevice_dev_bulk_read(priv, j, map->regs[k], + &dst[i], 4); + if (rc < 0) + dev_err(priv->dev, + "chn %d %s[%u] bulk_rd err = %d\n", + j, map->tag, k, rc); + } } return 0; @@ -1653,8 +1677,7 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv struct soc_bytes_ext *ext_cali_start; char *cali_start_name; - ext_cali_start = devm_kzalloc(priv->dev, - sizeof(*ext_cali_start), GFP_KERNEL); + ext_cali_start = devm_kzalloc_obj(priv->dev, *ext_cali_start); if (!ext_cali_start) return -ENOMEM; @@ -1684,7 +1707,15 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv return 0; } -static int create_tas2573_cali_re_ktrl(struct tasdevice_priv +/* Realtime sp data control */ +static int tas2573_rt_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + return tas2573_status_get_common(kcontrol, ucontrol, + &tas2573_rt_data_map); +} + +static int create_tas2573_rt_spk_data_ktrl(struct tasdevice_priv *priv, struct snd_kcontrol_new *cali_ctrl) { struct soc_bytes_ext *ext_cali_start; @@ -1696,26 +1727,28 @@ static int create_tas2573_cali_re_ktrl(struct tasdevice_priv return -ENOMEM; cali_start_name = devm_kstrdup(priv->dev, - "Real-time Speaker Impedance", GFP_KERNEL); + "Real-time Speaker Protection Data", GFP_KERNEL); if (!cali_start_name) return -ENOMEM; /* - * package structure for tas2573 real-time spk impedance: + * package structure for tas2573 real-time spk protection data: * Pkg len (1 byte) * Reg id (1 byte, constant 'r') - * book, page, register for fct status (total 3 bytes) + * 7 groups of book, page, register for real-time spk_data + * (21 bytes) * Data Start Flag (1 byte, constant 'D') * for (i = 0; i < Device-Sum; i++) { * Device #i index_info (1 byte) - * Sine gain for Device #i (4 bytes) + * real-time spk data for Device #i (28 bytes) * } */ - ext_cali_start->max = 6 + priv->ndev * 5; + ext_cali_start->max = tas2573_rt_data_map.nregs * 3 + 3 + + priv->ndev * (tas2573_rt_data_map.nregs * 4 + 1); cali_ctrl->name = cali_start_name; cali_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER; cali_ctrl->info = snd_soc_bytes_info_ext; cali_ctrl->put = NULL; - cali_ctrl->get = tas2573_re_get; + cali_ctrl->get = tas2573_rt_get; cali_ctrl->private_value = (unsigned long)ext_cali_start; return 0; @@ -1820,13 +1853,11 @@ static int tasdevice_create_cali_ctrls(struct tasdevice_priv *priv) * Alloc kcontrol via devm_kzalloc(), which don't manually * free the kcontrol. */ - cali_ctrls = devm_kcalloc(priv->dev, nctrls, - sizeof(cali_ctrls[0]), GFP_KERNEL); + cali_ctrls = devm_kzalloc_objs(priv->dev, cali_ctrls[0], nctrls); if (!cali_ctrls) return -ENOMEM; - ext_cali_data = devm_kzalloc(priv->dev, sizeof(*ext_cali_data), - GFP_KERNEL); + ext_cali_data = devm_kzalloc_obj(priv->dev, *ext_cali_data); if (!ext_cali_data) return -ENOMEM; @@ -1874,7 +1905,7 @@ static int tasdevice_create_cali_ctrls(struct tasdevice_priv *priv) if (rc != 0) return rc; i++; - rc = create_tas2573_cali_re_ktrl(priv, &cali_ctrls[i]); + rc = create_tas2573_rt_spk_data_ktrl(priv, &cali_ctrls[i]); if (rc != 0) return rc; i++; diff --git a/sound/soc/codecs/tas2783-sdw.c b/sound/soc/codecs/tas2783-sdw.c index a57230e01f7553..08b37e7b3a9e42 100644 --- a/sound/soc/codecs/tas2783-sdw.c +++ b/sound/soc/codecs/tas2783-sdw.c @@ -46,6 +46,8 @@ #define TAS2783_PROBE_TIMEOUT 5000 #define TAS2783_CALI_GUID EFI_GUID(0x1f52d2a1, 0xbb3a, 0x457d, 0xbc, \ 0x09, 0x43, 0xa3, 0xf4, 0x31, 0x0a, 0x92) +#define TAS2783_SPKID_GUID EFI_GUID(0xaa61eaaf, 0x6e83, 0x7523, 0xb0, \ + 0xd0, 0x7d, 0xf7, 0x4b, 0xb2, 0x4a, 0x81) static const u32 tas2783_cali_reg[] = { TAS2783_CAL_R0, @@ -102,8 +104,13 @@ struct tas2783_prv { wait_queue_head_t fw_wait; bool fw_dl_task_done; bool fw_dl_success; - /* use fallback fw name */ - bool fw_use_fallback; + /* the file for the firmware name being tried is missing */ + bool fw_missing; +#if IS_ENABLED(CONFIG_PCI) + /* UEFI speaker ID */ + u32 spk_id; + bool spk_id_valid; +#endif }; static const struct reg_default tas2783_reg_default[] = { @@ -757,19 +764,11 @@ static void tas2783_fw_ready(const struct firmware *fmw, void *context) goto out; } - /* firmware binary not found*/ + /* firmware binary not found, tas_io_init() tries the next name */ if (!fmw || !fmw->data) { - if (!tas_dev->fw_use_fallback) { - tas_dev->fw_use_fallback = true; - dev_info(tas_dev->dev, - "Failed to read preferred fw binary: %s, attempting fallback binary load\n", - tas_dev->rca_binaryname); - } else { - dev_err(tas_dev->dev, - "Failed to read fallback fw binary %s\n", - tas_dev->rca_binaryname); - } - + tas_dev->fw_missing = true; + dev_info(tas_dev->dev, "Failed to read fw binary %s\n", + tas_dev->rca_binaryname); ret = -EINVAL; goto out; } @@ -1092,10 +1091,10 @@ static s32 tas_init(struct tas2783_prv *tas_dev) s32 ret; dev_set_drvdata(tas_dev->dev, tas_dev); - ret = devm_snd_soc_register_component(tas_dev->dev, - &soc_codec_driver_tasdevice, - tas_dai_driver, - ARRAY_SIZE(tas_dai_driver)); + ret = snd_soc_register_component(tas_dev->dev, + &soc_codec_driver_tasdevice, + tas_dai_driver, + ARRAY_SIZE(tas_dai_driver)); if (ret) { dev_err(tas_dev->dev, "%s: codec register error:%d.\n", __func__, ret); @@ -1156,42 +1155,79 @@ static const struct dev_pm_ops tas2783_sdca_pm = { RUNTIME_PM_OPS(tas2783_sdca_dev_suspend, tas2783_sdca_dev_resume, NULL) }; -static void tas_generate_fw_name(struct sdw_slave *slave, char *name, size_t size) +#if IS_ENABLED(CONFIG_PCI) +/* BIOS speaker ID that selects the SSID-SPKID-LINK-UID firmware name */ +static int tas2783_get_spk_id(u32 *spk_id) +{ + efi_guid_t guid = TAS2783_SPKID_GUID; + unsigned long size = sizeof(*spk_id); + efi_status_t status; + + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) + return -ENOENT; + + status = efi.get_variable(L"SPEAKER_ID", &guid, NULL, &size, spk_id); + if (status != EFI_SUCCESS || size != sizeof(*spk_id)) + return -ENOENT; + + return 0; +} +#endif + +/* + * Firmware names in the order they are tried: SSID-SPKID-LINK-0xUID when the + * BIOS has a speaker ID, then SSID-LINK-0xUID and SSID-LINK-UID. + */ +static bool tas_generate_fw_name(struct sdw_slave *slave, unsigned int idx, + char *name, size_t size) { struct sdw_bus *bus = slave->bus; u8 unique_id = slave->id.unique_id; - bool pci_found = false; #if IS_ENABLED(CONFIG_PCI) - struct device *dev = &slave->dev; struct tas2783_prv *tas_dev = dev_get_drvdata(&slave->dev); - struct pci_dev *pci = NULL; - const char *fw_uid_prefix = tas_dev->fw_use_fallback ? "" : "0x"; - - for (; dev; dev = dev->parent) { - if (dev->bus == &pci_bus_type) { - pci = to_pci_dev(dev); - scnprintf(name, size, "%04X-%1X-%s%1X.bin", - pci->subsystem_device, bus->link_id, - fw_uid_prefix, unique_id); - pci_found = true; - break; + struct device *dev; + + for (dev = &slave->dev; dev; dev = dev->parent) { + u16 ssid; + + if (dev->bus != &pci_bus_type) + continue; + + ssid = to_pci_dev(dev)->subsystem_device; + if (!tas_dev->spk_id_valid) + idx++; + + switch (idx) { + case 0: + scnprintf(name, size, "%04X-%X-%1X-0x%1X.bin", ssid, + tas_dev->spk_id, bus->link_id, unique_id); + return true; + case 1: + scnprintf(name, size, "%04X-%1X-0x%1X.bin", ssid, + bus->link_id, unique_id); + return true; + case 2: + scnprintf(name, size, "%04X-%1X-%1X.bin", ssid, + bus->link_id, unique_id); + return true; + default: + return false; } } #endif - if (!pci_found) - scnprintf(name, size, "tas2783-%1X-%1X.bin", - bus->link_id, unique_id); + if (idx) + return false; + + scnprintf(name, size, "tas2783-%1X-%1X.bin", bus->link_id, unique_id); + return true; } -static s32 tas_fw_load(struct tas2783_prv *tas_dev, struct sdw_slave *slave) +static s32 tas_fw_load(struct tas2783_prv *tas_dev) { s32 ret; u8 unique_id = tas_dev->sdw_peripheral->id.unique_id; - tas_generate_fw_name(slave, tas_dev->rca_binaryname, - sizeof(tas_dev->rca_binaryname)); - tas_dev->fw_dl_task_done = false; ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT, tas_dev->rca_binaryname, tas_dev->dev, @@ -1216,6 +1252,7 @@ static s32 tas_fw_load(struct tas2783_prv *tas_dev, struct sdw_slave *slave) static s32 tas_io_init(struct device *dev, struct sdw_slave *slave) { struct tas2783_prv *tas_dev = dev_get_drvdata(dev); + unsigned int i; s32 ret; if (tas_dev->hw_init) @@ -1230,10 +1267,15 @@ static s32 tas_io_init(struct device *dev, struct sdw_slave *slave) } usleep_range(2000, 2200); - tas_dev->fw_use_fallback = false; - ret = tas_fw_load(tas_dev, slave); - if (!ret && tas_dev->fw_use_fallback) - ret = tas_fw_load(tas_dev, slave); + for (i = 0; tas_generate_fw_name(slave, i, tas_dev->rca_binaryname, + sizeof(tas_dev->rca_binaryname)); i++) { + tas_dev->fw_missing = false; + ret = tas_fw_load(tas_dev); + if (ret || !tas_dev->fw_missing) + break; + } + if (tas_dev->fw_missing) + dev_err(dev, "no firmware binary found\n"); if (!ret) { if (tas_dev->sa_func_data) @@ -1383,7 +1425,7 @@ static s32 tas_sdw_probe(struct sdw_slave *peripheral, return dev_err_probe(dev, ret, "slave property read failed"); - tas_dev = devm_kzalloc(dev, sizeof(*tas_dev), GFP_KERNEL); + tas_dev = devm_kzalloc_obj(dev, *tas_dev); if (!tas_dev) return dev_err_probe(dev, -ENOMEM, "Failed devm_kzalloc"); @@ -1405,8 +1447,7 @@ static s32 tas_sdw_probe(struct sdw_slave *peripheral, if (i >= 0 && i < peripheral->sdca_data.num_functions) { /* Allocate memory for function data */ - function_data = devm_kzalloc(dev, sizeof(*function_data), - GFP_KERNEL); + function_data = devm_kzalloc_obj(dev, *function_data); if (!function_data) return dev_err_probe(dev, -ENOMEM, "failed to parse sdca functions"); @@ -1427,6 +1468,9 @@ static s32 tas_sdw_probe(struct sdw_slave *peripheral, tas_dev->fw_version = 0; mutex_init(&tas_dev->calib_lock); mutex_init(&tas_dev->pde_lock); +#if IS_ENABLED(CONFIG_PCI) + tas_dev->spk_id_valid = !tas2783_get_spk_id(&tas_dev->spk_id); +#endif init_waitqueue_head(&tas_dev->fw_wait); dev_set_drvdata(dev, tas_dev); @@ -1448,8 +1492,8 @@ static void tas_sdw_remove(struct sdw_slave *peripheral) { struct tas2783_prv *tas_dev = dev_get_drvdata(&peripheral->dev); - pm_runtime_disable(tas_dev->dev); tas_remove(tas_dev); + pm_runtime_disable(tas_dev->dev); mutex_destroy(&tas_dev->calib_lock); mutex_destroy(&tas_dev->pde_lock); dev_set_drvdata(&peripheral->dev, NULL); diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c index 1ab82ef1c41d21..91ecb5977a79a3 100644 --- a/sound/soc/codecs/tas5086.c +++ b/sound/soc/codecs/tas5086.c @@ -923,7 +923,7 @@ static int tas5086_i2c_probe(struct i2c_client *i2c) struct device *dev = &i2c->dev; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/tas571x.c b/sound/soc/codecs/tas571x.c index 5e2560347461cd..d6c5a8874cd8e7 100644 --- a/sound/soc/codecs/tas571x.c +++ b/sound/soc/codecs/tas571x.c @@ -956,7 +956,7 @@ static int tas571x_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; i2c_set_clientdata(client, priv); diff --git a/sound/soc/codecs/tas5720.c b/sound/soc/codecs/tas5720.c index 2539a097e743af..e4528b9a4494c0 100644 --- a/sound/soc/codecs/tas5720.c +++ b/sound/soc/codecs/tas5720.c @@ -740,7 +740,7 @@ static int tas5720_probe(struct i2c_client *client) int ret; int i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/codecs/tas5805m.c b/sound/soc/codecs/tas5805m.c index d32796a6fa7528..39b219867e6724 100644 --- a/sound/soc/codecs/tas5805m.c +++ b/sound/soc/codecs/tas5805m.c @@ -466,7 +466,7 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c) return ret; } - tas5805m = devm_kzalloc(dev, sizeof(*tas5805m), GFP_KERNEL); + tas5805m = devm_kzalloc_obj(dev, *tas5805m); if (!tas5805m) return -ENOMEM; diff --git a/sound/soc/codecs/tas6424.c b/sound/soc/codecs/tas6424.c index 2718183e864c37..5e42e0e3f1944c 100644 --- a/sound/soc/codecs/tas6424.c +++ b/sound/soc/codecs/tas6424.c @@ -698,7 +698,7 @@ static int tas6424_i2c_probe(struct i2c_client *client) int ret; int i; - tas6424 = devm_kzalloc(dev, sizeof(*tas6424), GFP_KERNEL); + tas6424 = devm_kzalloc_obj(dev, *tas6424); if (!tas6424) return -ENOMEM; dev_set_drvdata(dev, tas6424); diff --git a/sound/soc/codecs/tas675x.c b/sound/soc/codecs/tas675x.c index 82eeaceb1dacf0..e8bceecb03861b 100644 --- a/sound/soc/codecs/tas675x.c +++ b/sound/soc/codecs/tas675x.c @@ -2035,7 +2035,7 @@ static int tas675x_i2c_probe(struct i2c_client *client) u32 val; int i, ret; - tas = devm_kzalloc(&client->dev, sizeof(*tas), GFP_KERNEL); + tas = devm_kzalloc_obj(&client->dev, *tas); if (!tas) return -ENOMEM; diff --git a/sound/soc/codecs/tda7419.c b/sound/soc/codecs/tda7419.c index 7ddea2fbe2d28b..9e47dcfe68ceae 100644 --- a/sound/soc/codecs/tda7419.c +++ b/sound/soc/codecs/tda7419.c @@ -576,9 +576,7 @@ static int tda7419_probe(struct i2c_client *i2c) struct tda7419_data *tda7419; int i, ret; - tda7419 = devm_kzalloc(&i2c->dev, - sizeof(struct tda7419_data), - GFP_KERNEL); + tda7419 = devm_kzalloc_obj(&i2c->dev, struct tda7419_data); if (tda7419 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/tfa9865.c b/sound/soc/codecs/tfa9865.c new file mode 100644 index 00000000000000..ca1a458e6f6517 --- /dev/null +++ b/sound/soc/codecs/tfa9865.c @@ -0,0 +1,400 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for the NXP TFA9865 mono class-D speaker amplifier + * + * The TFA9865 has no DSP of its own, speaker protection (if any) is done by + * the host. Register definitions and the initialization sequence are taken + * from the NXP tfa98xx kernel driver: + * Copyright (C) 2014-2020 NXP Semiconductors, All Rights Reserved. + * + * Copyright (c) 2026 Venkat Yadlapati + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TFA9865_SYS_CTRL0 0x00 +#define TFA9865_SYS_CTRL0_PWDN 0 /* power down */ +#define TFA9865_SYS_CTRL0_I2CR BIT(1) /* register reset, self clearing */ +#define TFA9865_SYS_CTRL0_AMPE 3 /* enable amplifier */ +#define TFA9865_SYS_CTRL0_DCA 4 /* enable boost converter */ +#define TFA9865_SYS_CTRL1 0x01 +#define TFA9865_SYS_CTRL1_MANSCONF BIT(2) /* I2C configuration done */ +#define TFA9865_SYS_CTRL2 0x02 +#define TFA9865_SYS_CTRL2_AUDFS GENMASK(3, 0) /* sample rate */ +#define TFA9865_REVISIONNUMBER 0x03 +#define TFA9865_REVISIONNUMBER_REV GENMASK(7, 0) +#define TFA9865_REVISIONNUMBER_FAM GENMASK(15, 8) +#define TFA9865_CLK_GATING_CTRL 0x04 +#define TFA9865_CLK_GATING_CTRL_MANAOOSC BIT(6) /* oscillator off in power down */ +#define TFA9865_DEVICE_INFO 0x06 +#define TFA9865_DEVICE_INFO_DEVREV GENMASK(15, 8) +#define TFA9865_HIDE_UNHIDE_KEY 0x0f +#define TFA9865_STATUS_FLAGS2 0x12 +#define TFA9865_STATUS_FLAGS2_MANSTATE GENMASK(3, 0) /* device manager state */ +#define TFA9865_TDM_CFG1 0x21 +#define TFA9865_TDM_CFG1_TDMSPKS 8 /* slot for the amplifier input */ +#define TFA9865_TDM_GAIN 0x5f +#define TFA9865_TDM_GAIN_TDMSPKG 5 /* input attenuation */ +#define TFA9865_TDM_GAIN_TDMSPKG_MAX 31 +#define TFA9865_KEY1 0xa0 +#define TFA9865_KEY2 0xa1 +#define TFA9865_KEY1_SEED 0xfb + +#define TFA9865_FAMILY 0x98 +#define TFA9865_REVISION 0x66 + +#define TFA9865_MANSTATE_POWERDOWN 0 +#define TFA9865_MANSTATE_WAIT_SRC 1 + +struct tfa9865 { + struct regmap *regmap; + struct gpio_desc *reset_gpiod; + /* Protects powered and unmuted */ + struct mutex lock; + bool powered; + bool unmuted; +}; + +/* + * The amplifier is enabled only while the output path is powered and the + * stream is unmuted. Enabling it before the I2S clocks run makes it pop. + */ +static int tfa9865_update_ampe(struct tfa9865 *tfa9865) +{ + bool on = tfa9865->powered && tfa9865->unmuted; + + return regmap_update_bits(tfa9865->regmap, TFA9865_SYS_CTRL0, + BIT(TFA9865_SYS_CTRL0_AMPE), + on ? BIT(TFA9865_SYS_CTRL0_AMPE) : 0); +} + +static int tfa9865_ampe_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + struct tfa9865 *tfa9865 = snd_soc_component_get_drvdata(component); + + guard(mutex)(&tfa9865->lock); + tfa9865->powered = SND_SOC_DAPM_EVENT_ON(event); + + return tfa9865_update_ampe(tfa9865); +} + +static bool tfa9865_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case TFA9865_SYS_CTRL0: /* I2CR clears itself */ + case TFA9865_HIDE_UNHIDE_KEY: + case 0x10 ... 0x15: /* status and interrupt flags */ + case TFA9865_KEY1: + case TFA9865_KEY2: + case TFA9865_KEY1_SEED: + return true; + default: + return false; + } +} + +static const struct regmap_config tfa9865_regmap = { + .reg_bits = 8, + .val_bits = 16, + .max_register = 0xff, + + .volatile_reg = tfa9865_volatile_reg, + .cache_type = REGCACHE_MAPLE, +}; + +static const char * const tdmspks_text[] = { "Left", "Right" }; +static SOC_ENUM_SINGLE_DECL(tdmspks_enum, TFA9865_TDM_CFG1, TFA9865_TDM_CFG1_TDMSPKS, + tdmspks_text); +static const struct snd_kcontrol_new tdmspks_mux = SOC_DAPM_ENUM("Amp Input", tdmspks_enum); +static const struct snd_kcontrol_new amp_switch = SOC_DAPM_SINGLE_VIRT("Switch", 1); + +static const struct snd_kcontrol_new tfa9865_controls[] = { + /* The input attenuation has no documented scale, larger is quieter */ + SOC_SINGLE("Playback Volume", TFA9865_TDM_GAIN, TFA9865_TDM_GAIN_TDMSPKG, + TFA9865_TDM_GAIN_TDMSPKG_MAX, 1), +}; + +static const struct snd_soc_dapm_widget tfa9865_dapm_widgets[] = { + SND_SOC_DAPM_OUTPUT("OUT"), + SND_SOC_DAPM_SUPPLY("POWER", TFA9865_SYS_CTRL0, TFA9865_SYS_CTRL0_PWDN, 1, NULL, 0), + SND_SOC_DAPM_SUPPLY("BOOST", TFA9865_SYS_CTRL0, TFA9865_SYS_CTRL0_DCA, 0, NULL, 0), + SND_SOC_DAPM_OUT_DRV_E("AMPE", SND_SOC_NOPM, 0, 0, NULL, 0, tfa9865_ampe_event, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_SWITCH("Amp", SND_SOC_NOPM, 0, 0, &_switch), + + SND_SOC_DAPM_MUX("Amp Input", SND_SOC_NOPM, 0, 0, &tdmspks_mux), + SND_SOC_DAPM_AIF_IN("AIFINL", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_IN("AIFINR", "HiFi Playback", 1, SND_SOC_NOPM, 0, 0), +}; + +static const struct snd_soc_dapm_route tfa9865_dapm_routes[] = { + {"OUT", NULL, "AMPE"}, + {"AMPE", NULL, "POWER"}, + {"AMPE", NULL, "BOOST"}, + {"AMPE", NULL, "Amp"}, + {"Amp", "Switch", "Amp Input"}, + {"Amp Input", "Left", "AIFINL"}, + {"Amp Input", "Right", "AIFINR"}, +}; + +static const struct snd_soc_component_driver tfa9865_component = { + .controls = tfa9865_controls, + .num_controls = ARRAY_SIZE(tfa9865_controls), + .dapm_widgets = tfa9865_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(tfa9865_dapm_widgets), + .dapm_routes = tfa9865_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(tfa9865_dapm_routes), + .use_pmdown_time = 1, + .endianness = 1, +}; + +static const unsigned int tfa9865_rates[] = { + 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 +}; + +static int tfa9865_find_sample_rate(unsigned int rate) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tfa9865_rates); i++) + if (tfa9865_rates[i] == rate) + return i; + + return -EINVAL; +} + +static int tfa9865_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct snd_soc_component *component = dai->component; + int sr; + + /* Only the 32-bit I2S slots configured at reset are supported */ + if (params_physical_width(params) != 32) { + dev_err(component->dev, "unsupported slot width: %d\n", + params_physical_width(params)); + return -EINVAL; + } + + sr = tfa9865_find_sample_rate(params_rate(params)); + if (sr < 0) { + dev_err(component->dev, "unsupported sample rate: %d\n", + params_rate(params)); + return sr; + } + + return snd_soc_component_update_bits(component, TFA9865_SYS_CTRL2, + TFA9865_SYS_CTRL2_AUDFS, + FIELD_PREP(TFA9865_SYS_CTRL2_AUDFS, sr)); +} + +static int tfa9865_mute_stream(struct snd_soc_dai *dai, int mute, int stream) +{ + struct tfa9865 *tfa9865 = snd_soc_component_get_drvdata(dai->component); + + guard(mutex)(&tfa9865->lock); + tfa9865->unmuted = !mute; + + return tfa9865_update_ampe(tfa9865); +} + +static const struct snd_soc_dai_ops tfa9865_dai_ops = { + .hw_params = tfa9865_hw_params, + .mute_stream = tfa9865_mute_stream, + .no_capture_mute = 1, +}; + +static struct snd_soc_dai_driver tfa9865_dai = { + .name = "tfa9865-hifi", + .playback = { + .stream_name = "HiFi Playback", + .formats = SNDRV_PCM_FMTBIT_S32_LE, + .rates = SNDRV_PCM_RATE_8000_48000, + .rate_min = 8000, + .rate_max = 48000, + .channels_min = 1, + .channels_max = 2, + }, + .ops = &tfa9865_dai_ops, +}; + +static int tfa9865_wait_manstate(struct tfa9865 *tfa9865, unsigned int state) +{ + unsigned int val; + + return regmap_read_poll_timeout(tfa9865->regmap, TFA9865_STATUS_FLAGS2, val, + FIELD_GET(TFA9865_STATUS_FLAGS2_MANSTATE, val) == state, + 1000, 50000); +} + +static const struct reg_sequence tfa9865_b0_init[] = { + /* "generated code" version 2 for TFA9865 B0 from the NXP driver */ + { 0x00, 0xf241 }, + { 0x02, 0x0c28 }, + { 0x08, 0x009a }, + { 0x50, 0xc000 }, + { 0x54, 0x10e0 }, + { 0x5a, 0x5f5e }, + { 0x5b, 0x74e2 }, + { 0x5c, 0xb02b }, + { 0x5f, 0x00a0 }, + { 0x62, 0x06c4 }, + { 0x63, 0x80d4 }, + { 0x65, 0x0c58 }, + { 0x67, 0x006e }, + { 0x68, 0x0820 }, + { 0x69, 0x0119 }, + { 0x74, 0x6028 }, + { 0x75, 0x1daa }, + { 0x78, 0x0001 }, + { 0x7c, 0x10f2 }, + { 0xdd, 0x01b6 }, +}; + +static int tfa9865_init(struct tfa9865 *tfa9865) +{ + struct regmap *regmap = tfa9865->regmap; + unsigned int seed; + int ret; + + /* + * Start from the register defaults, also when the device stayed + * powered (no reset GPIO, driver rebind). This clears MANSCONF, so + * the device manager waits in WAIT_SRC below. + */ + ret = regmap_write(regmap, TFA9865_SYS_CTRL0, TFA9865_SYS_CTRL0_I2CR); + if (ret) + return ret; + usleep_range(1000, 2000); + + /* The reset changed every register, forget what was read before */ + regcache_drop_region(regmap, 0, tfa9865_regmap.max_register); + + /* Leave power down to make the protected registers accessible */ + regmap_clear_bits(regmap, TFA9865_SYS_CTRL0, BIT(TFA9865_SYS_CTRL0_PWDN)); + regmap_clear_bits(regmap, TFA9865_CLK_GATING_CTRL, TFA9865_CLK_GATING_CTRL_MANAOOSC); + ret = tfa9865_wait_manstate(tfa9865, TFA9865_MANSTATE_WAIT_SRC); + if (ret) + return ret; + + /* Unlock key 1 and key 2 */ + regmap_write(regmap, TFA9865_HIDE_UNHIDE_KEY, 0x5a6b); + ret = regmap_read(regmap, TFA9865_KEY1_SEED, &seed); + if (ret) + return ret; + regmap_write(regmap, TFA9865_KEY1, seed ^ 0x005a); + regmap_write(regmap, TFA9865_KEY2, 0x005a); + + ret = regmap_multi_reg_write(regmap, tfa9865_b0_init, ARRAY_SIZE(tfa9865_b0_init)); + + /* Lock the keys again */ + regmap_write(regmap, TFA9865_KEY2, 0); + regmap_write(regmap, TFA9865_KEY1, 0); + regmap_write(regmap, TFA9865_HIDE_UNHIDE_KEY, 0); + if (ret) + return ret; + + /* Go back to power down with the oscillator off */ + regmap_set_bits(regmap, TFA9865_SYS_CTRL0, BIT(TFA9865_SYS_CTRL0_PWDN)); + ret = tfa9865_wait_manstate(tfa9865, TFA9865_MANSTATE_POWERDOWN); + if (ret) + return ret; + regmap_set_bits(regmap, TFA9865_CLK_GATING_CTRL, TFA9865_CLK_GATING_CTRL_MANAOOSC); + + /* Input attenuation used by the vendor configuration */ + regmap_update_bits(regmap, TFA9865_TDM_GAIN, + TFA9865_TDM_GAIN_TDMSPKG_MAX << TFA9865_TDM_GAIN_TDMSPKG, + 5 << TFA9865_TDM_GAIN_TDMSPKG); + + /* Configuration done, let the device manager start on power up */ + return regmap_set_bits(regmap, TFA9865_SYS_CTRL1, TFA9865_SYS_CTRL1_MANSCONF); +} + +static int tfa9865_i2c_probe(struct i2c_client *i2c) +{ + struct device *dev = &i2c->dev; + struct tfa9865 *tfa9865; + unsigned int val, devrev; + int ret; + + tfa9865 = devm_kzalloc(dev, sizeof(*tfa9865), GFP_KERNEL); + if (!tfa9865) + return -ENOMEM; + + i2c_set_clientdata(i2c, tfa9865); + + ret = devm_mutex_init(dev, &tfa9865->lock); + if (ret) + return ret; + + ret = devm_regulator_get_enable_optional(dev, "vddd"); + if (ret && ret != -ENODEV) + return dev_err_probe(dev, ret, "failed to enable vddd supply\n"); + + tfa9865->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(tfa9865->reset_gpiod)) + return dev_err_probe(dev, PTR_ERR(tfa9865->reset_gpiod), + "failed to get reset gpio\n"); + if (tfa9865->reset_gpiod) { + usleep_range(1000, 2000); + gpiod_set_value_cansleep(tfa9865->reset_gpiod, 0); + usleep_range(1000, 2000); + } + + tfa9865->regmap = devm_regmap_init_i2c(i2c, &tfa9865_regmap); + if (IS_ERR(tfa9865->regmap)) + return PTR_ERR(tfa9865->regmap); + + ret = regmap_read(tfa9865->regmap, TFA9865_REVISIONNUMBER, &val); + if (ret) + return dev_err_probe(dev, ret, "failed to read revision number\n"); + + if (FIELD_GET(TFA9865_REVISIONNUMBER_FAM, val) != TFA9865_FAMILY || + FIELD_GET(TFA9865_REVISIONNUMBER_REV, val) != TFA9865_REVISION) + return dev_err_probe(dev, -ENODEV, "unknown revision number %#x\n", val); + + ret = regmap_read(tfa9865->regmap, TFA9865_DEVICE_INFO, &val); + if (ret) + return ret; + + /* Only the B0 init sequence is known */ + devrev = FIELD_GET(TFA9865_DEVICE_INFO_DEVREV, val); + if (((devrev >> 2) & 0x3) != 1 || (devrev & 0xf0)) + return dev_err_probe(dev, -ENODEV, "unsupported device revision %#x\n", devrev); + + ret = tfa9865_init(tfa9865); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize\n"); + + return devm_snd_soc_register_component(dev, &tfa9865_component, &tfa9865_dai, 1); +} + +static const struct of_device_id tfa9865_of_match[] = { + { .compatible = "nxp,tfa9865" }, + { } +}; +MODULE_DEVICE_TABLE(of, tfa9865_of_match); + +static struct i2c_driver tfa9865_i2c_driver = { + .driver = { + .name = "tfa9865", + .of_match_table = tfa9865_of_match, + }, + .probe = tfa9865_i2c_probe, +}; +module_i2c_driver(tfa9865_i2c_driver); + +MODULE_DESCRIPTION("ASoC NXP TFA9865 speaker amplifier driver"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/tfa9879.c b/sound/soc/codecs/tfa9879.c index 51910373176873..70b306d8679e75 100644 --- a/sound/soc/codecs/tfa9879.c +++ b/sound/soc/codecs/tfa9879.c @@ -285,7 +285,7 @@ static int tfa9879_i2c_probe(struct i2c_client *i2c) struct tfa9879_priv *tfa9879; int i; - tfa9879 = devm_kzalloc(&i2c->dev, sizeof(*tfa9879), GFP_KERNEL); + tfa9879 = devm_kzalloc_obj(&i2c->dev, *tfa9879); if (!tfa9879) return -ENOMEM; diff --git a/sound/soc/codecs/tfa989x.c b/sound/soc/codecs/tfa989x.c index 885b3ea19c2c4d..98172e57de0323 100644 --- a/sound/soc/codecs/tfa989x.c +++ b/sound/soc/codecs/tfa989x.c @@ -338,7 +338,7 @@ static int tfa989x_i2c_probe(struct i2c_client *i2c) return -ENODEV; } - tfa989x = devm_kzalloc(dev, sizeof(*tfa989x), GFP_KERNEL); + tfa989x = devm_kzalloc_obj(dev, *tfa989x); if (!tfa989x) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320adc3xxx.c b/sound/soc/codecs/tlv320adc3xxx.c index 79f4abc245dda6..74051795dbe5a6 100644 --- a/sound/soc/codecs/tlv320adc3xxx.c +++ b/sound/soc/codecs/tlv320adc3xxx.c @@ -1417,7 +1417,7 @@ static int adc3xxx_i2c_probe(struct i2c_client *i2c) struct adc3xxx *adc3xxx = NULL; int ret; - adc3xxx = devm_kzalloc(dev, sizeof(struct adc3xxx), GFP_KERNEL); + adc3xxx = devm_kzalloc_obj(dev, struct adc3xxx); if (!adc3xxx) return -ENOMEM; adc3xxx->dev = dev; diff --git a/sound/soc/codecs/tlv320adcx140.c b/sound/soc/codecs/tlv320adcx140.c index 511d691923f2da..ba1013b40fbf40 100644 --- a/sound/soc/codecs/tlv320adcx140.c +++ b/sound/soc/codecs/tlv320adcx140.c @@ -1276,7 +1276,7 @@ static int adcx140_i2c_probe(struct i2c_client *i2c) struct adcx140_priv *adcx140; int ret; - adcx140 = devm_kzalloc(&i2c->dev, sizeof(*adcx140), GFP_KERNEL); + adcx140 = devm_kzalloc_obj(&i2c->dev, *adcx140); if (!adcx140) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index f31ffa189580d1..cbfd9930a0e8fe 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c @@ -604,7 +604,7 @@ int tlv320aic23_probe(struct device *dev, struct regmap *regmap) if (IS_ERR(regmap)) return PTR_ERR(regmap); - aic23 = devm_kzalloc(dev, sizeof(struct aic23), GFP_KERNEL); + aic23 = devm_kzalloc_obj(dev, struct aic23); if (aic23 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c index 7dcc960a0b9e2a..85434b9c319208 100644 --- a/sound/soc/codecs/tlv320aic26.c +++ b/sound/soc/codecs/tlv320aic26.c @@ -364,7 +364,7 @@ static int aic26_spi_probe(struct spi_device *spi) dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); /* Allocate driver data */ - aic26 = devm_kzalloc(&spi->dev, sizeof *aic26, GFP_KERNEL); + aic26 = devm_kzalloc_obj(&spi->dev, *aic26); if (!aic26) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c index e0a8db435d6a8f..c9fd93e264689e 100644 --- a/sound/soc/codecs/tlv320aic31xx.c +++ b/sound/soc/codecs/tlv320aic31xx.c @@ -1732,7 +1732,7 @@ static int aic31xx_i2c_probe(struct i2c_client *i2c) unsigned int micbias_value = MICBIAS_2_0V; int i, ret; - aic31xx = devm_kzalloc(&i2c->dev, sizeof(*aic31xx), GFP_KERNEL); + aic31xx = devm_kzalloc_obj(&i2c->dev, *aic31xx); if (!aic31xx) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320aic32x4-clk.c b/sound/soc/codecs/tlv320aic32x4-clk.c index 27d186c72315e9..9ab794de823fdf 100644 --- a/sound/soc/codecs/tlv320aic32x4-clk.c +++ b/sound/soc/codecs/tlv320aic32x4-clk.c @@ -467,7 +467,7 @@ static struct clk *aic32x4_register_clk(struct device *dev, init.num_parents = desc->num_parents; init.flags = 0; - priv = devm_kzalloc(dev, sizeof(struct clk_aic32x4), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, struct clk_aic32x4); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c index 2ee4a9d2abf278..875d934bb5c8d5 100644 --- a/sound/soc/codecs/tlv320aic32x4.c +++ b/sound/soc/codecs/tlv320aic32x4.c @@ -1299,7 +1299,7 @@ int aic32x4_probe(struct device *dev, struct regmap *regmap, struct device_node *np = dev->of_node; int ret; - aic32x4 = devm_kzalloc(dev, sizeof(struct aic32x4_priv), GFP_KERNEL); + aic32x4 = devm_kzalloc_obj(dev, struct aic32x4_priv); if (!aic32x4) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index be83111accaa08..032f32097131f1 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c @@ -1765,7 +1765,7 @@ int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver int ret, i; u32 value; - aic3x = devm_kzalloc(dev, sizeof(struct aic3x_priv), GFP_KERNEL); + aic3x = devm_kzalloc_obj(dev, struct aic3x_priv); if (!aic3x) return -ENOMEM; @@ -1779,7 +1779,7 @@ int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver dev_set_drvdata(dev, aic3x); if (np) { - ai3x_setup = devm_kzalloc(dev, sizeof(*ai3x_setup), GFP_KERNEL); + ai3x_setup = devm_kzalloc_obj(dev, *ai3x_setup); if (!ai3x_setup) return -ENOMEM; diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index b91ab42882d1da..75bda2cc8c71c0 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c @@ -1471,8 +1471,8 @@ static int dac33_i2c_probe(struct i2c_client *client) struct tlv320dac33_priv *dac33; int ret, i; - dac33 = devm_kzalloc(&client->dev, struct_size(dac33, reg_cache, ARRAY_SIZE(dac33_reg)), - GFP_KERNEL); + dac33 = devm_kzalloc_flex(&client->dev, *dac33, reg_cache, + ARRAY_SIZE(dac33_reg)); if (dac33 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c index 38cc000891eaca..ac9ef8fd67d7f7 100644 --- a/sound/soc/codecs/tpa6130a2.c +++ b/sound/soc/codecs/tpa6130a2.c @@ -215,7 +215,7 @@ static int tpa6130a2_probe(struct i2c_client *client) dev = &client->dev; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&client->dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c index 39284e4d420ef2..dfd16ac19469fc 100644 --- a/sound/soc/codecs/ts3a227e.c +++ b/sound/soc/codecs/ts3a227e.c @@ -354,7 +354,7 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c) int ret; unsigned int acc_reg; - ts3a227e = devm_kzalloc(&i2c->dev, sizeof(*ts3a227e), GFP_KERNEL); + ts3a227e = devm_kzalloc_obj(&i2c->dev, *ts3a227e); if (ts3a227e == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/tscs42xx.c b/sound/soc/codecs/tscs42xx.c index 02082ef790b40c..993233b0fd1e80 100644 --- a/sound/soc/codecs/tscs42xx.c +++ b/sound/soc/codecs/tscs42xx.c @@ -1389,7 +1389,7 @@ static int tscs42xx_i2c_probe(struct i2c_client *i2c) int src; int ret; - tscs42xx = devm_kzalloc(&i2c->dev, sizeof(*tscs42xx), GFP_KERNEL); + tscs42xx = devm_kzalloc_obj(&i2c->dev, *tscs42xx); if (!tscs42xx) { ret = -ENOMEM; dev_err(&i2c->dev, diff --git a/sound/soc/codecs/tscs454.c b/sound/soc/codecs/tscs454.c index e772dd39a849c3..494170746a1aaa 100644 --- a/sound/soc/codecs/tscs454.c +++ b/sound/soc/codecs/tscs454.c @@ -3395,7 +3395,7 @@ static int tscs454_i2c_probe(struct i2c_client *i2c) int src; int ret; - tscs454 = devm_kzalloc(&i2c->dev, sizeof(*tscs454), GFP_KERNEL); + tscs454 = devm_kzalloc_obj(&i2c->dev, *tscs454); if (!tscs454) return -ENOMEM; diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 9541c8a5a24e81..7fed99b9b2ffed 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -2194,7 +2194,7 @@ static int twl4030_codec_probe(struct platform_device *pdev) struct twl4030_priv *twl4030; int ret; - twl4030 = devm_kzalloc(&pdev->dev, sizeof(*twl4030), GFP_KERNEL); + twl4030 = devm_kzalloc_obj(&pdev->dev, *twl4030); if (!twl4030) return -ENOMEM; diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c index 826bde1a9ba46b..aab3273f2ecce2 100644 --- a/sound/soc/codecs/twl6040.c +++ b/sound/soc/codecs/twl6040.c @@ -1100,7 +1100,7 @@ static int twl6040_probe(struct snd_soc_component *component) struct platform_device *pdev = to_platform_device(component->dev); int ret = 0; - priv = devm_kzalloc(component->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(component->dev, *priv); if (priv == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/uda1334.c b/sound/soc/codecs/uda1334.c index 7ae6afdba38b4c..37a3b1edc90de0 100644 --- a/sound/soc/codecs/uda1334.c +++ b/sound/soc/codecs/uda1334.c @@ -254,8 +254,7 @@ static int uda1334_codec_probe(struct platform_device *pdev) struct uda1334_priv *uda1334; int ret; - uda1334 = devm_kzalloc(&pdev->dev, sizeof(struct uda1334_priv), - GFP_KERNEL); + uda1334 = devm_kzalloc_obj(&pdev->dev, struct uda1334_priv); if (!uda1334) return -ENOMEM; diff --git a/sound/soc/codecs/uda1342.c b/sound/soc/codecs/uda1342.c index 63d087590ac994..b9031a8846200c 100644 --- a/sound/soc/codecs/uda1342.c +++ b/sound/soc/codecs/uda1342.c @@ -287,7 +287,7 @@ static int uda1342_i2c_probe(struct i2c_client *i2c) { struct uda1342_priv *uda1342; - uda1342 = devm_kzalloc(&i2c->dev, sizeof(*uda1342), GFP_KERNEL); + uda1342 = devm_kzalloc_obj(&i2c->dev, *uda1342); if (!uda1342) return -ENOMEM; diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index 02adc534dfb06e..d2a64740d5df5a 100644 --- a/sound/soc/codecs/uda1380.c +++ b/sound/soc/codecs/uda1380.c @@ -778,9 +778,8 @@ static int uda1380_i2c_probe(struct i2c_client *i2c) struct uda1380_priv *uda1380; int ret; - uda1380 = devm_kzalloc(&i2c->dev, - struct_size(uda1380, reg_cache, ARRAY_SIZE(uda1380_reg)), - GFP_KERNEL); + uda1380 = devm_kzalloc_flex(&i2c->dev, *uda1380, reg_cache, + ARRAY_SIZE(uda1380_reg)); if (uda1380 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c index fd40c1686d66a1..6bd7cf1f2ffed3 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.c +++ b/sound/soc/codecs/wcd-mbhc-v2.c @@ -1623,7 +1623,7 @@ void wcd_mbhc_deinit(struct wcd_mbhc *mbhc) free_irq(mbhc->intr_ids->mbhc_sw_intr, mbhc); mutex_lock(&mbhc->lock); - wcd_cancel_hs_detect_plug(mbhc, &mbhc->correct_plug_swch); + wcd_mbhc_cancel_pending_work(mbhc); cancel_work_sync(&mbhc->mbhc_plug_detect_work); mutex_unlock(&mbhc->lock); diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c index a98d1fd789251a..add23335cf8264 100644 --- a/sound/soc/codecs/wcd9335.c +++ b/sound/soc/codecs/wcd9335.c @@ -1733,7 +1733,7 @@ static int wcd9335_slim_set_hw_params(struct wcd9335_codec *wcd, cfg->port_mask |= BIT(ch->port); } - cfg->chs = kcalloc(cfg->ch_count, sizeof(unsigned int), GFP_KERNEL); + cfg->chs = kzalloc_objs(unsigned int, cfg->ch_count); if (!cfg->chs) return -ENOMEM; @@ -5078,7 +5078,7 @@ static int wcd9335_slim_probe(struct slim_device *slim) struct wcd9335_codec *wcd; int ret; - wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); + wcd = devm_kzalloc_obj(dev, *wcd); if (!wcd) return -ENOMEM; @@ -5136,7 +5136,6 @@ static int wcd9335_slim_status(struct slim_device *sdev, wcd->regmap = regmap_init_slimbus(sdev, &wcd9335_regmap_config); if (IS_ERR(wcd->regmap)) { - put_device(&wcd->slim_ifc_dev->dev); return dev_err_probe(dev, PTR_ERR(wcd->regmap), "Failed to allocate slim register map\n"); } @@ -5144,7 +5143,6 @@ static int wcd9335_slim_status(struct slim_device *sdev, wcd->if_regmap = regmap_init_slimbus(wcd->slim_ifc_dev, &wcd9335_ifc_regmap_config); if (IS_ERR(wcd->if_regmap)) { - put_device(&wcd->slim_ifc_dev->dev); return dev_err_probe(dev, PTR_ERR(wcd->if_regmap), "Failed to allocate ifc register map\n"); } @@ -5152,13 +5150,11 @@ static int wcd9335_slim_status(struct slim_device *sdev, ret = wcd9335_bring_up(wcd); if (ret) { dev_err(dev, "Failed to bringup WCD9335\n"); - put_device(&wcd->slim_ifc_dev->dev); return ret; } ret = wcd9335_irq_init(wcd); if (ret) { - put_device(&wcd->slim_ifc_dev->dev); return ret; } diff --git a/sound/soc/codecs/wcd934x.c b/sound/soc/codecs/wcd934x.c index 0ed24cca088f83..f274b24c58a75e 100644 --- a/sound/soc/codecs/wcd934x.c +++ b/sound/soc/codecs/wcd934x.c @@ -1706,7 +1706,7 @@ static int wcd934x_slim_set_hw_params(struct wcd934x_codec *wcd, cfg->port_mask |= BIT(ch->port); } - cfg->chs = kcalloc(cfg->ch_count, sizeof(unsigned int), GFP_KERNEL); + cfg->chs = kzalloc_objs(unsigned int, cfg->ch_count); if (!cfg->chs) return -ENOMEM; @@ -2995,6 +2995,12 @@ static int wcd934x_comp_probe(struct snd_soc_component *component) /* Default HPH Mode to Class-H Low HiFi */ wcd->hph_mode = CLS_H_LOHIFI; + /* + * The digital core drops register writes while MCLK is off, but the + * regmap cache still records them. Keep MCLK running so the init + * sequence below and later mixer/DAPM writes actually reach the codec. + */ + __wcd934x_cdc_mclk_enable(wcd, true); wcd934x_comp_init(component); for (i = 0; i < NUM_CODEC_DAIS; i++) @@ -5839,7 +5845,7 @@ static int wcd934x_codec_probe(struct platform_device *pdev) struct wcd934x_codec *wcd; int ret, irq; - wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); + wcd = devm_kzalloc_obj(dev, *wcd); if (!wcd) return -ENOMEM; diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-sdca.c index 7c15f885390ce8..efbbeb3dc721aa 100644 --- a/sound/soc/codecs/wcd9378-sdca.c +++ b/sound/soc/codecs/wcd9378-sdca.c @@ -892,7 +892,7 @@ int wcd9378_sdca_read_prop(struct sdw_slave *slave) /* Sink ports: DP6 (HPH audio), DP7 (HPH envelope), DP8 (optimisation RX). */ prop->sink_ports = BIT(6) | BIT(7) | BIT(8); - src = devm_kcalloc(dev, 2, sizeof(*src), GFP_KERNEL); + src = devm_kzalloc_objs(dev, *src, 2); if (!src) return -ENOMEM; @@ -912,7 +912,7 @@ int wcd9378_sdca_read_prop(struct sdw_slave *slave) prop->src_dpn_prop = src; - sink = devm_kcalloc(dev, 3, sizeof(*sink), GFP_KERNEL); + sink = devm_kzalloc_objs(dev, *sink, 3); if (!sink) return -ENOMEM; @@ -987,7 +987,7 @@ int wcd9378_sdca_probe(struct sdw_slave *slave, if (!device_property_read_bool(dev, "qcom,sdca-compliant")) return -ENODEV; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c index 1ad75c226060ec..57549518767ce9 100644 --- a/sound/soc/codecs/wcd937x-sdw.c +++ b/sound/soc/codecs/wcd937x-sdw.c @@ -970,7 +970,7 @@ static int wcd9370_probe(struct sdw_slave *pdev, int master_ch_mask_size = 0; int ret, i; - wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); + wcd = devm_kzalloc_obj(dev, *wcd); if (!wcd) return -ENOMEM; diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c index 9d5d1df41c365d..6e03b714fa389a 100644 --- a/sound/soc/codecs/wcd937x.c +++ b/sound/soc/codecs/wcd937x.c @@ -3049,7 +3049,7 @@ static int wcd937x_probe(struct platform_device *pdev) #endif /* CONFIG_TYPEC */ int ret; - wcd937x = devm_kzalloc(dev, sizeof(*wcd937x), GFP_KERNEL); + wcd937x = devm_kzalloc_obj(dev, *wcd937x); if (!wcd937x) return -ENOMEM; diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h index 3d0ba3cc0ee614..af217eae493e39 100644 --- a/sound/soc/codecs/wcd937x.h +++ b/sound/soc/codecs/wcd937x.h @@ -526,32 +526,12 @@ struct wcd937x_sdw_priv { }; #if IS_ENABLED(CONFIG_SND_SOC_WCD937X_SDW) -int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, - struct snd_pcm_substream *substream, - struct snd_soc_dai *dai); -int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, - struct snd_soc_dai *dai, - void *stream, int direction); int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); #else -static inline int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, - struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - return -EOPNOTSUPP; -} - -static inline int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, - struct snd_soc_dai *dai, - void *stream, int direction) -{ - return -EOPNOTSUPP; -} - static inline int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c index e5ad368418a2ca..d61ab5a6b05968 100644 --- a/sound/soc/codecs/wcd938x-sdw.c +++ b/sound/soc/codecs/wcd938x-sdw.c @@ -1156,7 +1156,7 @@ static int wcd9380_probe(struct sdw_slave *pdev, struct wcd938x_sdw_priv *wcd; int ret; - wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); + wcd = devm_kzalloc_obj(dev, *wcd); if (!wcd) return -ENOMEM; diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index 9a9ea37ecab36a..1c4833584b5ef9 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -3476,8 +3476,7 @@ static int wcd938x_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv), - GFP_KERNEL); + wcd938x = devm_kzalloc_obj(dev, struct wcd938x_priv); if (!wcd938x) return -ENOMEM; diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c index 69b9b08118f0e8..495761e96bdd2f 100644 --- a/sound/soc/codecs/wcd939x-sdw.c +++ b/sound/soc/codecs/wcd939x-sdw.c @@ -1341,7 +1341,7 @@ static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) struct wcd939x_sdw_priv *wcd; int ret; - wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); + wcd = devm_kzalloc_obj(dev, *wcd); if (!wcd) return -ENOMEM; diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c index b0b09468f98a63..1a45d3f066735d 100644 --- a/sound/soc/codecs/wcd939x.c +++ b/sound/soc/codecs/wcd939x.c @@ -3551,8 +3551,7 @@ static int wcd939x_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - wcd939x = devm_kzalloc(dev, sizeof(struct wcd939x_priv), - GFP_KERNEL); + wcd939x = devm_kzalloc_obj(dev, struct wcd939x_priv); if (!wcd939x) return -ENOMEM; diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c index c44abffe9b5651..26ec2df66a80ee 100644 --- a/sound/soc/codecs/wm0010.c +++ b/sound/soc/codecs/wm0010.c @@ -837,8 +837,7 @@ static int wm0010_spi_probe(struct spi_device *spi) int irq; struct wm0010_priv *wm0010; - wm0010 = devm_kzalloc(&spi->dev, sizeof(*wm0010), - GFP_KERNEL); + wm0010 = devm_kzalloc_obj(&spi->dev, *wm0010); if (!wm0010) return -ENOMEM; diff --git a/sound/soc/codecs/wm1250-ev1.c b/sound/soc/codecs/wm1250-ev1.c index 5c1b00acb5bf86..bce1487e0f233b 100644 --- a/sound/soc/codecs/wm1250-ev1.c +++ b/sound/soc/codecs/wm1250-ev1.c @@ -133,7 +133,7 @@ static int wm1250_ev1_pdata(struct i2c_client *i2c) if (!pdata) return 0; - wm1250 = devm_kzalloc(&i2c->dev, sizeof(*wm1250), GFP_KERNEL); + wm1250 = devm_kzalloc_obj(&i2c->dev, *wm1250); if (!wm1250) return -ENOMEM; diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c index 41c8cfb346c669..f01fbc6e6ea0de 100644 --- a/sound/soc/codecs/wm2000.c +++ b/sound/soc/codecs/wm2000.c @@ -801,7 +801,7 @@ static int wm2000_i2c_probe(struct i2c_client *i2c) unsigned int reg; u16 id; - wm2000 = devm_kzalloc(&i2c->dev, sizeof(*wm2000), GFP_KERNEL); + wm2000 = devm_kzalloc_obj(&i2c->dev, *wm2000); if (!wm2000) return -ENOMEM; diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c index 692e933dba7535..e07966ebc84c6e 100644 --- a/sound/soc/codecs/wm2200.c +++ b/sound/soc/codecs/wm2200.c @@ -2196,8 +2196,7 @@ static int wm2200_i2c_probe(struct i2c_client *i2c) int ret, i; int val; - wm2200 = devm_kzalloc(&i2c->dev, sizeof(struct wm2200_priv), - GFP_KERNEL); + wm2200 = devm_kzalloc_obj(&i2c->dev, struct wm2200_priv); if (wm2200 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c index cdee1561d5968b..05e3f8a6bf99cd 100644 --- a/sound/soc/codecs/wm5100.c +++ b/sound/soc/codecs/wm5100.c @@ -2413,8 +2413,7 @@ static int wm5100_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret, i, irq_flags; - wm5100 = devm_kzalloc(&i2c->dev, sizeof(struct wm5100_priv), - GFP_KERNEL); + wm5100 = devm_kzalloc_obj(&i2c->dev, struct wm5100_priv); if (wm5100 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c index 74b775b95bfdb1..762e81979cb8d4 100644 --- a/sound/soc/codecs/wm5102.c +++ b/sound/soc/codecs/wm5102.c @@ -2035,8 +2035,7 @@ static int wm5102_probe(struct platform_device *pdev) struct wm5102_priv *wm5102; int i, ret; - wm5102 = devm_kzalloc(&pdev->dev, sizeof(struct wm5102_priv), - GFP_KERNEL); + wm5102 = devm_kzalloc_obj(&pdev->dev, struct wm5102_priv); if (wm5102 == NULL) return -ENOMEM; platform_set_drvdata(pdev, wm5102); diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c index 7a311c869bd312..faa85d88a489bc 100644 --- a/sound/soc/codecs/wm5110.c +++ b/sound/soc/codecs/wm5110.c @@ -2397,8 +2397,7 @@ static int wm5110_probe(struct platform_device *pdev) struct wm5110_priv *wm5110; int i, ret; - wm5110 = devm_kzalloc(&pdev->dev, sizeof(struct wm5110_priv), - GFP_KERNEL); + wm5110 = devm_kzalloc_obj(&pdev->dev, struct wm5110_priv); if (wm5110 == NULL) return -ENOMEM; platform_set_drvdata(pdev, wm5110); diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c index 0e7c8a5fae726c..aaa7edab04872c 100644 --- a/sound/soc/codecs/wm8350.c +++ b/sound/soc/codecs/wm8350.c @@ -1492,8 +1492,7 @@ static int wm8350_component_probe(struct snd_soc_component *component) return -EINVAL; } - priv = devm_kzalloc(component->dev, sizeof(struct wm8350_data), - GFP_KERNEL); + priv = devm_kzalloc_obj(component->dev, struct wm8350_data); if (priv == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c index 83e2d72a4a76b5..30072990726462 100644 --- a/sound/soc/codecs/wm8400.c +++ b/sound/soc/codecs/wm8400.c @@ -1275,8 +1275,7 @@ static int wm8400_component_probe(struct snd_soc_component *component) int ret; u16 reg; - priv = devm_kzalloc(component->dev, sizeof(struct wm8400_priv), - GFP_KERNEL); + priv = devm_kzalloc_obj(component->dev, struct wm8400_priv); if (priv == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c index 2d48bfffcebe86..8f9177ed1a5df8 100644 --- a/sound/soc/codecs/wm8510.c +++ b/sound/soc/codecs/wm8510.c @@ -630,8 +630,7 @@ static int wm8510_spi_probe(struct spi_device *spi) struct wm8510_priv *wm8510; int ret; - wm8510 = devm_kzalloc(&spi->dev, sizeof(struct wm8510_priv), - GFP_KERNEL); + wm8510 = devm_kzalloc_obj(&spi->dev, struct wm8510_priv); if (wm8510 == NULL) return -ENOMEM; @@ -662,8 +661,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c) struct wm8510_priv *wm8510; int ret; - wm8510 = devm_kzalloc(&i2c->dev, sizeof(struct wm8510_priv), - GFP_KERNEL); + wm8510 = devm_kzalloc_obj(&i2c->dev, struct wm8510_priv); if (wm8510 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c index 9972d6599002c4..610282765d570b 100644 --- a/sound/soc/codecs/wm8523.c +++ b/sound/soc/codecs/wm8523.c @@ -461,8 +461,7 @@ static int wm8523_i2c_probe(struct i2c_client *i2c) unsigned int val; int ret, i; - wm8523 = devm_kzalloc(&i2c->dev, sizeof(struct wm8523_priv), - GFP_KERNEL); + wm8523 = devm_kzalloc_obj(&i2c->dev, struct wm8523_priv); if (wm8523 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8524.c b/sound/soc/codecs/wm8524.c index 8d0565b103cdbc..e2a5debc838549 100644 --- a/sound/soc/codecs/wm8524.c +++ b/sound/soc/codecs/wm8524.c @@ -250,8 +250,7 @@ static int wm8524_codec_probe(struct platform_device *pdev) struct wm8524_priv *wm8524; int ret; - wm8524 = devm_kzalloc(&pdev->dev, sizeof(struct wm8524_priv), - GFP_KERNEL); + wm8524 = devm_kzalloc_obj(&pdev->dev, struct wm8524_priv); if (wm8524 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c index cee80da8f753f6..4df9b6620b5857 100644 --- a/sound/soc/codecs/wm8580.c +++ b/sound/soc/codecs/wm8580.c @@ -1025,8 +1025,7 @@ static int wm8580_i2c_probe(struct i2c_client *i2c) struct wm8580_priv *wm8580; int ret, i; - wm8580 = devm_kzalloc(&i2c->dev, sizeof(struct wm8580_priv), - GFP_KERNEL); + wm8580 = devm_kzalloc_obj(&i2c->dev, struct wm8580_priv); if (wm8580 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c index 390af15a749a1f..eb515a8277c0f9 100644 --- a/sound/soc/codecs/wm8711.c +++ b/sound/soc/codecs/wm8711.c @@ -417,8 +417,7 @@ static int wm8711_spi_probe(struct spi_device *spi) struct wm8711_priv *wm8711; int ret; - wm8711 = devm_kzalloc(&spi->dev, sizeof(struct wm8711_priv), - GFP_KERNEL); + wm8711 = devm_kzalloc_obj(&spi->dev, struct wm8711_priv); if (wm8711 == NULL) return -ENOMEM; @@ -449,8 +448,7 @@ static int wm8711_i2c_probe(struct i2c_client *client) struct wm8711_priv *wm8711; int ret; - wm8711 = devm_kzalloc(&client->dev, sizeof(struct wm8711_priv), - GFP_KERNEL); + wm8711 = devm_kzalloc_obj(&client->dev, struct wm8711_priv); if (wm8711 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c index 7af5ce0fffe05f..5ede2164374ce1 100644 --- a/sound/soc/codecs/wm8728.c +++ b/sound/soc/codecs/wm8728.c @@ -254,8 +254,7 @@ static int wm8728_spi_probe(struct spi_device *spi) struct wm8728_priv *wm8728; int ret; - wm8728 = devm_kzalloc(&spi->dev, sizeof(struct wm8728_priv), - GFP_KERNEL); + wm8728 = devm_kzalloc_obj(&spi->dev, struct wm8728_priv); if (wm8728 == NULL) return -ENOMEM; @@ -286,8 +285,7 @@ static int wm8728_i2c_probe(struct i2c_client *i2c) struct wm8728_priv *wm8728; int ret; - wm8728 = devm_kzalloc(&i2c->dev, sizeof(struct wm8728_priv), - GFP_KERNEL); + wm8728 = devm_kzalloc_obj(&i2c->dev, struct wm8728_priv); if (wm8728 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8731-i2c.c b/sound/soc/codecs/wm8731-i2c.c index f44f4d3d9394e8..52c32611504670 100644 --- a/sound/soc/codecs/wm8731-i2c.c +++ b/sound/soc/codecs/wm8731-i2c.c @@ -27,8 +27,7 @@ static int wm8731_i2c_probe(struct i2c_client *i2c) struct wm8731_priv *wm8731; int ret; - wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), - GFP_KERNEL); + wm8731 = devm_kzalloc_obj(&i2c->dev, struct wm8731_priv); if (wm8731 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8731-spi.c b/sound/soc/codecs/wm8731-spi.c index 29e58e1e6b79d9..fe18eac20b4341 100644 --- a/sound/soc/codecs/wm8731-spi.c +++ b/sound/soc/codecs/wm8731-spi.c @@ -26,7 +26,7 @@ static int wm8731_spi_probe(struct spi_device *spi) struct wm8731_priv *wm8731; int ret; - wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); + wm8731 = devm_kzalloc_obj(&spi->dev, *wm8731); if (wm8731 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c index 7f59dc6c74c0a4..10489c557f8315 100644 --- a/sound/soc/codecs/wm8737.c +++ b/sound/soc/codecs/wm8737.c @@ -622,8 +622,7 @@ static int wm8737_i2c_probe(struct i2c_client *i2c) struct wm8737_priv *wm8737; int ret, i; - wm8737 = devm_kzalloc(&i2c->dev, sizeof(struct wm8737_priv), - GFP_KERNEL); + wm8737 = devm_kzalloc_obj(&i2c->dev, struct wm8737_priv); if (wm8737 == NULL) return -ENOMEM; @@ -672,8 +671,7 @@ static int wm8737_spi_probe(struct spi_device *spi) struct wm8737_priv *wm8737; int ret, i; - wm8737 = devm_kzalloc(&spi->dev, sizeof(struct wm8737_priv), - GFP_KERNEL); + wm8737 = devm_kzalloc_obj(&spi->dev, struct wm8737_priv); if (wm8737 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index e49adc9808b4f7..3fb02447f0f51e 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c @@ -582,8 +582,7 @@ static int wm8741_i2c_probe(struct i2c_client *i2c) struct wm8741_priv *wm8741; int ret, i; - wm8741 = devm_kzalloc(&i2c->dev, sizeof(struct wm8741_priv), - GFP_KERNEL); + wm8741 = devm_kzalloc_obj(&i2c->dev, struct wm8741_priv); if (wm8741 == NULL) return -ENOMEM; @@ -640,8 +639,7 @@ static int wm8741_spi_probe(struct spi_device *spi) struct wm8741_priv *wm8741; int ret, i; - wm8741 = devm_kzalloc(&spi->dev, sizeof(struct wm8741_priv), - GFP_KERNEL); + wm8741 = devm_kzalloc_obj(&spi->dev, struct wm8741_priv); if (wm8741 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index e87b7d5e94e201..439763e3944ebb 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c @@ -759,8 +759,7 @@ static int wm8750_spi_probe(struct spi_device *spi) struct regmap *regmap; int ret; - wm8750 = devm_kzalloc(&spi->dev, sizeof(struct wm8750_priv), - GFP_KERNEL); + wm8750 = devm_kzalloc_obj(&spi->dev, struct wm8750_priv); if (wm8750 == NULL) return -ENOMEM; @@ -799,8 +798,7 @@ static int wm8750_i2c_probe(struct i2c_client *i2c) struct regmap *regmap; int ret; - wm8750 = devm_kzalloc(&i2c->dev, sizeof(struct wm8750_priv), - GFP_KERNEL); + wm8750 = devm_kzalloc_obj(&i2c->dev, struct wm8750_priv); if (wm8750 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index cbdf1e6aea5bb2..86b0477c738b15 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c @@ -1538,8 +1538,7 @@ static int wm8753_spi_probe(struct spi_device *spi) struct wm8753_priv *wm8753; int ret; - wm8753 = devm_kzalloc(&spi->dev, sizeof(struct wm8753_priv), - GFP_KERNEL); + wm8753 = devm_kzalloc_obj(&spi->dev, struct wm8753_priv); if (wm8753 == NULL) return -ENOMEM; @@ -1576,8 +1575,7 @@ static int wm8753_i2c_probe(struct i2c_client *i2c) struct wm8753_priv *wm8753; int ret; - wm8753 = devm_kzalloc(&i2c->dev, sizeof(struct wm8753_priv), - GFP_KERNEL); + wm8753 = devm_kzalloc_obj(&i2c->dev, struct wm8753_priv); if (wm8753 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c index 1e485d2fe21a68..6bc725547b242b 100644 --- a/sound/soc/codecs/wm8770.c +++ b/sound/soc/codecs/wm8770.c @@ -653,8 +653,7 @@ static int wm8770_spi_probe(struct spi_device *spi) struct wm8770_priv *wm8770; int ret, i; - wm8770 = devm_kzalloc(&spi->dev, sizeof(struct wm8770_priv), - GFP_KERNEL); + wm8770 = devm_kzalloc_obj(&spi->dev, struct wm8770_priv); if (!wm8770) return -ENOMEM; diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c index c633fe824356dc..8fcc720859a613 100644 --- a/sound/soc/codecs/wm8776.c +++ b/sound/soc/codecs/wm8776.c @@ -475,8 +475,7 @@ static int wm8776_spi_probe(struct spi_device *spi) struct wm8776_priv *wm8776; int ret; - wm8776 = devm_kzalloc(&spi->dev, sizeof(struct wm8776_priv), - GFP_KERNEL); + wm8776 = devm_kzalloc_obj(&spi->dev, struct wm8776_priv); if (wm8776 == NULL) return -ENOMEM; @@ -507,8 +506,7 @@ static int wm8776_i2c_probe(struct i2c_client *i2c) struct wm8776_priv *wm8776; int ret; - wm8776 = devm_kzalloc(&i2c->dev, sizeof(struct wm8776_priv), - GFP_KERNEL); + wm8776 = devm_kzalloc_obj(&i2c->dev, struct wm8776_priv); if (wm8776 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8782.c b/sound/soc/codecs/wm8782.c index cbf0c823c0226f..4df5835fc5168f 100644 --- a/sound/soc/codecs/wm8782.c +++ b/sound/soc/codecs/wm8782.c @@ -133,7 +133,7 @@ static int wm8782_probe(struct platform_device *pdev) struct wm8782_priv *priv; int ret, i, fsampen; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c index 2fc9634fe51f1d..d02911395d0409 100644 --- a/sound/soc/codecs/wm8804.c +++ b/sound/soc/codecs/wm8804.c @@ -579,7 +579,7 @@ int wm8804_probe(struct device *dev, struct regmap *regmap) unsigned int id1, id2; int i, ret; - wm8804 = devm_kzalloc(dev, sizeof(*wm8804), GFP_KERNEL); + wm8804 = devm_kzalloc_obj(dev, *wm8804); if (!wm8804) return -ENOMEM; diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index dcda7a7be0b10c..cb75b2387c7009 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c @@ -1256,8 +1256,7 @@ static int wm8900_spi_probe(struct spi_device *spi) struct wm8900_priv *wm8900; int ret; - wm8900 = devm_kzalloc(&spi->dev, sizeof(struct wm8900_priv), - GFP_KERNEL); + wm8900 = devm_kzalloc_obj(&spi->dev, struct wm8900_priv); if (wm8900 == NULL) return -ENOMEM; @@ -1287,8 +1286,7 @@ static int wm8900_i2c_probe(struct i2c_client *i2c) struct wm8900_priv *wm8900; int ret; - wm8900 = devm_kzalloc(&i2c->dev, sizeof(struct wm8900_priv), - GFP_KERNEL); + wm8900 = devm_kzalloc_obj(&i2c->dev, struct wm8900_priv); if (wm8900 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index 9dbc295b08890f..065499f33d217a 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c @@ -2021,7 +2021,7 @@ static int wm8903_i2c_probe(struct i2c_client *i2c) unsigned int val, irq_pol; int ret, i; - wm8903 = devm_kzalloc(&i2c->dev, sizeof(*wm8903), GFP_KERNEL); + wm8903 = devm_kzalloc_obj(&i2c->dev, *wm8903); if (wm8903 == NULL) return -ENOMEM; @@ -2042,8 +2042,7 @@ static int wm8903_i2c_probe(struct i2c_client *i2c) if (pdata) { wm8903->pdata = pdata; } else { - wm8903->pdata = devm_kzalloc(&i2c->dev, sizeof(*wm8903->pdata), - GFP_KERNEL); + wm8903->pdata = devm_kzalloc_obj(&i2c->dev, *wm8903->pdata); if (!wm8903->pdata) return -ENOMEM; diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c index efa1085449278a..ce93195942b432 100644 --- a/sound/soc/codecs/wm8904.c +++ b/sound/soc/codecs/wm8904.c @@ -2217,9 +2217,8 @@ static void wm8904_handle_pdata(struct snd_soc_component *component) wm8904_get_drc_enum, wm8904_put_drc_enum); /* We need an array of texts for the enum API */ - wm8904->drc_texts = kmalloc_array(pdata->num_drc_cfgs, - sizeof(*wm8904->drc_texts), - GFP_KERNEL); + wm8904->drc_texts = kmalloc_objs(*wm8904->drc_texts, + pdata->num_drc_cfgs); if (!wm8904->drc_texts) return; @@ -2462,7 +2461,7 @@ static int wm8904_set_pdata_from_of(struct i2c_client *i2c, struct wm8904_pdata *pdata; int ret, i; - pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&i2c->dev, *pdata); if (!pdata) return -ENOMEM; @@ -2502,8 +2501,7 @@ static int wm8904_i2c_probe(struct i2c_client *i2c) unsigned int val; int ret, i; - wm8904 = devm_kzalloc(&i2c->dev, sizeof(struct wm8904_priv), - GFP_KERNEL); + wm8904 = devm_kzalloc_obj(&i2c->dev, struct wm8904_priv); if (wm8904 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index 012556215d1260..43d08d3bd4a1b4 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -846,8 +846,7 @@ static int wm8940_i2c_probe(struct i2c_client *i2c) struct wm8940_priv *wm8940; int ret; - wm8940 = devm_kzalloc(&i2c->dev, sizeof(struct wm8940_priv), - GFP_KERNEL); + wm8940 = devm_kzalloc_obj(&i2c->dev, struct wm8940_priv); if (wm8940 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c index 70daf9e6433b2e..3189402a100335 100644 --- a/sound/soc/codecs/wm8955.c +++ b/sound/soc/codecs/wm8955.c @@ -982,8 +982,7 @@ static int wm8955_i2c_probe(struct i2c_client *i2c) struct wm8955_priv *wm8955; int i, ret; - wm8955 = devm_kzalloc(&i2c->dev, sizeof(struct wm8955_priv), - GFP_KERNEL); + wm8955 = devm_kzalloc_obj(&i2c->dev, struct wm8955_priv); if (wm8955 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c index b26c36ca824997..f6fb67e9ea0a51 100644 --- a/sound/soc/codecs/wm8958-dsp2.c +++ b/sound/soc/codecs/wm8958-dsp2.c @@ -927,9 +927,8 @@ void wm8958_dsp2_init(struct snd_soc_component *component) }; /* We need an array of texts for the enum API */ - wm8994->mbc_texts = kmalloc_array(pdata->num_mbc_cfgs, - sizeof(*wm8994->mbc_texts), - GFP_KERNEL); + wm8994->mbc_texts = kmalloc_objs(*wm8994->mbc_texts, + pdata->num_mbc_cfgs); if (!wm8994->mbc_texts) return; @@ -953,9 +952,8 @@ void wm8958_dsp2_init(struct snd_soc_component *component) }; /* We need an array of texts for the enum API */ - wm8994->vss_texts = kmalloc_array(pdata->num_vss_cfgs, - sizeof(*wm8994->vss_texts), - GFP_KERNEL); + wm8994->vss_texts = kmalloc_objs(*wm8994->vss_texts, + pdata->num_vss_cfgs); if (!wm8994->vss_texts) return; @@ -980,9 +978,8 @@ void wm8958_dsp2_init(struct snd_soc_component *component) }; /* We need an array of texts for the enum API */ - wm8994->vss_hpf_texts = kmalloc_array(pdata->num_vss_hpf_cfgs, - sizeof(*wm8994->vss_hpf_texts), - GFP_KERNEL); + wm8994->vss_hpf_texts = kmalloc_objs(*wm8994->vss_hpf_texts, + pdata->num_vss_hpf_cfgs); if (!wm8994->vss_hpf_texts) return; @@ -1008,9 +1005,8 @@ void wm8958_dsp2_init(struct snd_soc_component *component) }; /* We need an array of texts for the enum API */ - wm8994->enh_eq_texts = kmalloc_array(pdata->num_enh_eq_cfgs, - sizeof(*wm8994->enh_eq_texts), - GFP_KERNEL); + wm8994->enh_eq_texts = kmalloc_objs(*wm8994->enh_eq_texts, + pdata->num_enh_eq_cfgs); if (!wm8994->enh_eq_texts) return; diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 093530ae872b7d..7c24c992ffbeac 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -1446,8 +1446,7 @@ static int wm8960_i2c_probe(struct i2c_client *i2c) int ret; u8 val; - wm8960 = devm_kzalloc(&i2c->dev, sizeof(struct wm8960_priv), - GFP_KERNEL); + wm8960 = devm_kzalloc_obj(&i2c->dev, struct wm8960_priv); if (wm8960 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c index 55ccac7286c960..13716035a6e9ee 100644 --- a/sound/soc/codecs/wm8961.c +++ b/sound/soc/codecs/wm8961.c @@ -935,8 +935,7 @@ static int wm8961_i2c_probe(struct i2c_client *i2c) unsigned int val; int ret; - wm8961 = devm_kzalloc(&i2c->dev, sizeof(struct wm8961_priv), - GFP_KERNEL); + wm8961 = devm_kzalloc_obj(&i2c->dev, struct wm8961_priv); if (wm8961 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c index 31c9080cd81400..1832685aca40df 100644 --- a/sound/soc/codecs/wm8962.c +++ b/sound/soc/codecs/wm8962.c @@ -3127,7 +3127,7 @@ static void wm8962_mic_work(struct work_struct *work) /* Don't report a microphone if it's shorted right after * plugging in, as this may be a TRS plug in a TRRS socket. */ - if (!(wm8962->mic_status & WM8962_MICDET_STS)) + if (!(wm8962->mic_status & SND_JACK_MICROPHONE)) status = 0; } @@ -3248,22 +3248,28 @@ static int wm8962_mic_detect(struct snd_soc_component *component, struct snd_soc { struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component); struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); - int irq_mask, enable; + int mic_irq_mask = WM8962_MICD_EINT | WM8962_MICSCD_EINT; + + snd_soc_component_update_bits(component, WM8962_INTERRUPT_STATUS_2_MASK, + mic_irq_mask, mic_irq_mask); + if (pm_runtime_get_if_active(component->dev) > 0) { + snd_soc_component_update_bits(component, WM8962_ADDITIONAL_CONTROL_4, + WM8962_MICDET_ENA, 0); + pm_runtime_put(component->dev); + } + if (wm8962->irq) + synchronize_irq(wm8962->irq); + cancel_delayed_work_sync(&wm8962->mic_work); wm8962->jack = jack; if (jack) { - irq_mask = 0; - enable = WM8962_MICDET_ENA; - } else { - irq_mask = WM8962_MICD_EINT | WM8962_MICSCD_EINT; - enable = 0; + snd_soc_component_update_bits(component, + WM8962_INTERRUPT_STATUS_2_MASK, + mic_irq_mask, 0); + snd_soc_component_update_bits(component, WM8962_ADDITIONAL_CONTROL_4, + WM8962_MICDET_ENA, WM8962_MICDET_ENA); } - snd_soc_component_update_bits(component, WM8962_INTERRUPT_STATUS_2_MASK, - WM8962_MICD_EINT | WM8962_MICSCD_EINT, irq_mask); - snd_soc_component_update_bits(component, WM8962_ADDITIONAL_CONTROL_4, - WM8962_MICDET_ENA, enable); - /* Send an initial empty report */ snd_soc_jack_report(wm8962->jack, 0, SND_JACK_MICROPHONE | SND_JACK_BTN_0); @@ -3592,9 +3598,7 @@ static int wm8962_probe(struct snd_soc_component *component) static void wm8962_remove(struct snd_soc_component *component) { - struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component); - - cancel_delayed_work_sync(&wm8962->mic_work); + wm8962_mic_detect(component, NULL); wm8962_free_gpio(component); wm8962_free_beep(component); @@ -3671,7 +3675,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret, i, irq_pol, trigger; - wm8962 = devm_kzalloc(&i2c->dev, sizeof(*wm8962), GFP_KERNEL); + wm8962 = devm_kzalloc_obj(&i2c->dev, *wm8962); if (wm8962 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index 388ee05d45206d..865a5d7903c008 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c @@ -689,8 +689,7 @@ static int wm8971_i2c_probe(struct i2c_client *i2c) { struct wm8971_priv *wm8971; - wm8971 = devm_kzalloc(&i2c->dev, sizeof(struct wm8971_priv), - GFP_KERNEL); + wm8971 = devm_kzalloc_obj(&i2c->dev, struct wm8971_priv); if (wm8971 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c index 5e1737d455b1c0..0c5aab627ba18e 100644 --- a/sound/soc/codecs/wm8974.c +++ b/sound/soc/codecs/wm8974.c @@ -712,7 +712,7 @@ static int wm8974_i2c_probe(struct i2c_client *i2c) struct regmap *regmap; int ret; - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&i2c->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c index f5d3f26cc21790..a1c1b076bdf612 100644 --- a/sound/soc/codecs/wm8978.c +++ b/sound/soc/codecs/wm8978.c @@ -1062,8 +1062,7 @@ static int wm8978_i2c_probe(struct i2c_client *i2c) struct wm8978_priv *wm8978; int ret; - wm8978 = devm_kzalloc(&i2c->dev, sizeof(struct wm8978_priv), - GFP_KERNEL); + wm8978 = devm_kzalloc_obj(&i2c->dev, struct wm8978_priv); if (wm8978 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c index d4b0f8e141cda9..336772f0676c15 100644 --- a/sound/soc/codecs/wm8983.c +++ b/sound/soc/codecs/wm8983.c @@ -1020,7 +1020,7 @@ static int wm8983_spi_probe(struct spi_device *spi) struct wm8983_priv *wm8983; int ret; - wm8983 = devm_kzalloc(&spi->dev, sizeof *wm8983, GFP_KERNEL); + wm8983 = devm_kzalloc_obj(&spi->dev, *wm8983); if (!wm8983) return -ENOMEM; @@ -1052,7 +1052,7 @@ static int wm8983_i2c_probe(struct i2c_client *i2c) struct wm8983_priv *wm8983; int ret; - wm8983 = devm_kzalloc(&i2c->dev, sizeof *wm8983, GFP_KERNEL); + wm8983 = devm_kzalloc_obj(&i2c->dev, *wm8983); if (!wm8983) return -ENOMEM; diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c index 9264374bb8e4fb..44476126dced4a 100644 --- a/sound/soc/codecs/wm8985.c +++ b/sound/soc/codecs/wm8985.c @@ -1162,7 +1162,7 @@ static int wm8985_spi_probe(struct spi_device *spi) struct wm8985_priv *wm8985; int ret; - wm8985 = devm_kzalloc(&spi->dev, sizeof *wm8985, GFP_KERNEL); + wm8985 = devm_kzalloc_obj(&spi->dev, *wm8985); if (!wm8985) return -ENOMEM; @@ -1202,7 +1202,7 @@ static int wm8985_i2c_probe(struct i2c_client *i2c) struct wm8985_priv *wm8985; int ret; - wm8985 = devm_kzalloc(&i2c->dev, sizeof *wm8985, GFP_KERNEL); + wm8985 = devm_kzalloc_obj(&i2c->dev, *wm8985); if (!wm8985) return -ENOMEM; diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c index 6f97c9aa453aa0..9835a78cd89458 100644 --- a/sound/soc/codecs/wm8988.c +++ b/sound/soc/codecs/wm8988.c @@ -857,8 +857,7 @@ static int wm8988_spi_probe(struct spi_device *spi) struct wm8988_priv *wm8988; int ret; - wm8988 = devm_kzalloc(&spi->dev, sizeof(struct wm8988_priv), - GFP_KERNEL); + wm8988 = devm_kzalloc_obj(&spi->dev, struct wm8988_priv); if (wm8988 == NULL) return -ENOMEM; @@ -890,8 +889,7 @@ static int wm8988_i2c_probe(struct i2c_client *i2c) struct wm8988_priv *wm8988; int ret; - wm8988 = devm_kzalloc(&i2c->dev, sizeof(struct wm8988_priv), - GFP_KERNEL); + wm8988 = devm_kzalloc_obj(&i2c->dev, struct wm8988_priv); if (wm8988 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index a5e032a3f9f651..1e108fa8365efd 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c @@ -1236,8 +1236,7 @@ static int wm8990_i2c_probe(struct i2c_client *i2c) struct wm8990_priv *wm8990; int ret; - wm8990 = devm_kzalloc(&i2c->dev, sizeof(struct wm8990_priv), - GFP_KERNEL); + wm8990 = devm_kzalloc_obj(&i2c->dev, struct wm8990_priv); if (wm8990 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c index 553022bcd66662..e1b0b448746047 100644 --- a/sound/soc/codecs/wm8991.c +++ b/sound/soc/codecs/wm8991.c @@ -1272,7 +1272,7 @@ static int wm8991_i2c_probe(struct i2c_client *i2c) unsigned int val; int ret; - wm8991 = devm_kzalloc(&i2c->dev, sizeof(*wm8991), GFP_KERNEL); + wm8991 = devm_kzalloc_obj(&i2c->dev, *wm8991); if (!wm8991) return -ENOMEM; diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c index 934fa41a53cfac..fbadbb33b6079d 100644 --- a/sound/soc/codecs/wm8993.c +++ b/sound/soc/codecs/wm8993.c @@ -1650,8 +1650,7 @@ static int wm8993_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret, i; - wm8993 = devm_kzalloc(&i2c->dev, sizeof(struct wm8993_priv), - GFP_KERNEL); + wm8993 = devm_kzalloc_obj(&i2c->dev, struct wm8993_priv); if (wm8993 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index 2556b09e4a2206..fcaeff208eb7d6 100644 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c @@ -4664,6 +4664,14 @@ static void wm8994_component_remove(struct snd_soc_component *component) release_firmware(wm8994->mbc_vss); release_firmware(wm8994->enh_eq); kfree(wm8994->retune_mobile_texts); + kfree(wm8994->mbc_texts); + kfree(wm8994->vss_texts); + kfree(wm8994->vss_hpf_texts); + kfree(wm8994->enh_eq_texts); + wm8994->mbc_texts = NULL; + wm8994->vss_texts = NULL; + wm8994->vss_hpf_texts = NULL; + wm8994->enh_eq_texts = NULL; } static int wm8994_set_jack(struct snd_soc_component *component, @@ -4700,8 +4708,7 @@ static int wm8994_probe(struct platform_device *pdev) struct wm8994_priv *wm8994; int ret; - wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv), - GFP_KERNEL); + wm8994 = devm_kzalloc_obj(&pdev->dev, struct wm8994_priv); if (wm8994 == NULL) return -ENOMEM; platform_set_drvdata(pdev, wm8994); diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c index 7f01d203e0588c..b18d82389d7061 100644 --- a/sound/soc/codecs/wm8995.c +++ b/sound/soc/codecs/wm8995.c @@ -2228,7 +2228,7 @@ static int wm8995_spi_probe(struct spi_device *spi) struct wm8995_priv *wm8995; int ret; - wm8995 = devm_kzalloc(&spi->dev, sizeof(*wm8995), GFP_KERNEL); + wm8995 = devm_kzalloc_obj(&spi->dev, *wm8995); if (!wm8995) return -ENOMEM; @@ -2265,7 +2265,7 @@ static int wm8995_i2c_probe(struct i2c_client *i2c) struct wm8995_priv *wm8995; int ret; - wm8995 = devm_kzalloc(&i2c->dev, sizeof(*wm8995), GFP_KERNEL); + wm8995 = devm_kzalloc_obj(&i2c->dev, *wm8995); if (!wm8995) return -ENOMEM; diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c index 9d8fb4ee431295..19e581cc08c012 100644 --- a/sound/soc/codecs/wm8996.c +++ b/sound/soc/codecs/wm8996.c @@ -2770,8 +2770,7 @@ static int wm8996_i2c_probe(struct i2c_client *i2c) int ret, i; unsigned int reg; - wm8996 = devm_kzalloc(&i2c->dev, sizeof(struct wm8996_priv), - GFP_KERNEL); + wm8996 = devm_kzalloc_obj(&i2c->dev, struct wm8996_priv); if (wm8996 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c index 83106523385a5a..f041dfc905a427 100644 --- a/sound/soc/codecs/wm8997.c +++ b/sound/soc/codecs/wm8997.c @@ -1113,8 +1113,7 @@ static int wm8997_probe(struct platform_device *pdev) struct wm8997_priv *wm8997; int i, ret; - wm8997 = devm_kzalloc(&pdev->dev, sizeof(struct wm8997_priv), - GFP_KERNEL); + wm8997 = devm_kzalloc_obj(&pdev->dev, struct wm8997_priv); if (wm8997 == NULL) return -ENOMEM; platform_set_drvdata(pdev, wm8997); diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c index 8e6f03d00c715a..1158e9ca40a132 100644 --- a/sound/soc/codecs/wm8998.c +++ b/sound/soc/codecs/wm8998.c @@ -1340,8 +1340,7 @@ static int wm8998_probe(struct platform_device *pdev) struct wm8998_priv *wm8998; int i, ret; - wm8998 = devm_kzalloc(&pdev->dev, sizeof(struct wm8998_priv), - GFP_KERNEL); + wm8998 = devm_kzalloc_obj(&pdev->dev, struct wm8998_priv); if (!wm8998) return -ENOMEM; platform_set_drvdata(pdev, wm8998); diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c index 824e9c6b5f3e64..63fe87d30ff847 100644 --- a/sound/soc/codecs/wm9081.c +++ b/sound/soc/codecs/wm9081.c @@ -1323,8 +1323,7 @@ static int wm9081_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret; - wm9081 = devm_kzalloc(&i2c->dev, sizeof(struct wm9081_priv), - GFP_KERNEL); + wm9081 = devm_kzalloc_obj(&i2c->dev, struct wm9081_priv); if (wm9081 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c index 8fc24b19313de1..6ab47b08e73cc3 100644 --- a/sound/soc/codecs/wm9090.c +++ b/sound/soc/codecs/wm9090.c @@ -566,7 +566,7 @@ static int wm9090_i2c_probe(struct i2c_client *i2c) unsigned int reg; int ret; - wm9090 = devm_kzalloc(&i2c->dev, sizeof(*wm9090), GFP_KERNEL); + wm9090 = devm_kzalloc_obj(&i2c->dev, *wm9090); if (!wm9090) return -ENOMEM; diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c index 5c6aebe29cf132..b4ec66ea8d39f1 100644 --- a/sound/soc/codecs/wm9705.c +++ b/sound/soc/codecs/wm9705.c @@ -374,7 +374,7 @@ static int wm9705_probe(struct platform_device *pdev) { struct wm9705_priv *wm9705; - wm9705 = devm_kzalloc(&pdev->dev, sizeof(*wm9705), GFP_KERNEL); + wm9705 = devm_kzalloc_obj(&pdev->dev, *wm9705); if (wm9705 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 3105b2e0556f37..fcca8f5cc98c2e 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -694,7 +694,7 @@ static int wm9712_probe(struct platform_device *pdev) { struct wm9712_priv *wm9712; - wm9712 = devm_kzalloc(&pdev->dev, sizeof(*wm9712), GFP_KERNEL); + wm9712 = devm_kzalloc_obj(&pdev->dev, *wm9712); if (wm9712 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index 3cffdfbbf9ddaa..838565c15e1b35 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c @@ -1272,7 +1272,7 @@ static int wm9713_probe(struct platform_device *pdev) { struct wm9713_priv *wm9713; - wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL); + wm9713 = devm_kzalloc_obj(&pdev->dev, *wm9713); if (wm9713 == NULL) return -ENOMEM; diff --git a/sound/soc/codecs/wm_adsp_fw_find_test.c b/sound/soc/codecs/wm_adsp_fw_find_test.c index ae686dc4fa94b7..2a44b2670fa942 100644 --- a/sound/soc/codecs/wm_adsp_fw_find_test.c +++ b/sound/soc/codecs/wm_adsp_fw_find_test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "wm_adsp.h" @@ -104,14 +105,15 @@ static void wm_adsp_fw_find_test_pick_file(struct kunit *test) struct wm_adsp_fw_find_test *priv = test->priv; const struct wm_adsp_fw_find_test_params *params = test->param_value; struct wm_adsp *dsp = &priv->dsp; + struct seq_buf sb; int i, ret; /* Concatenate string of dir content for error messages */ + seq_buf_init_append(&sb, priv->searched_fw_files, + sizeof(priv->searched_fw_files)); for (i = 0; params->dir_files[i]; i++) { - strlcat(priv->searched_fw_files, params->dir_files[i], - sizeof(priv->searched_fw_files)); - strlcat(priv->searched_fw_files, ";", - sizeof(priv->searched_fw_files)); + seq_buf_puts(&sb, params->dir_files[i]); + seq_buf_puts(&sb, ";"); } dsp->cs_dsp.name = params->dsp_name; @@ -160,6 +162,7 @@ static int wm_adsp_fw_find_test_firmware_request_stub(const struct firmware **fi struct kunit *test = kunit_get_current_test(); const struct wm_adsp_fw_find_test_params *params = test->param_value; struct wm_adsp_fw_find_test *priv = test->priv; + struct seq_buf sb; /* * Searches are accumulated as a single string of space-separated names. @@ -168,10 +171,12 @@ static int wm_adsp_fw_find_test_firmware_request_stub(const struct firmware **fi * a simple KUNIT_EXPECT_STREQ(), which avoids the risk of bugs in a * more complex custom comparison. */ + seq_buf_init_append(&sb, priv->searched_fw_files, + sizeof(priv->searched_fw_files)); if (priv->searched_fw_files[0] != '\0') - strlcat(priv->searched_fw_files, " ", sizeof(priv->searched_fw_files)); + seq_buf_puts(&sb, " "); - strlcat(priv->searched_fw_files, filename, sizeof(priv->searched_fw_files)); + seq_buf_puts(&sb, filename); /* Non-parameterized test? */ if (!params) diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c index 7b77e97253856c..92e97664c760cb 100644 --- a/sound/soc/codecs/wm_hubs.c +++ b/sound/soc/codecs/wm_hubs.c @@ -178,7 +178,7 @@ static void wm_hubs_dcs_cache_set(struct snd_soc_component *component, u16 dcs_c if (hubs->no_cache_dac_hp_direct) return; - cache = devm_kzalloc(component->dev, sizeof(*cache), GFP_KERNEL); + cache = devm_kzalloc_obj(component->dev, *cache); if (!cache) return; diff --git a/sound/soc/codecs/wsa881x.c b/sound/soc/codecs/wsa881x.c index 4f3e6bc29c7ecc..f6cba55288e000 100644 --- a/sound/soc/codecs/wsa881x.c +++ b/sound/soc/codecs/wsa881x.c @@ -1111,7 +1111,7 @@ static int wsa881x_probe(struct sdw_slave *pdev, struct wsa881x_priv *wsa881x; struct device *dev = &pdev->dev; - wsa881x = devm_kzalloc(dev, sizeof(*wsa881x), GFP_KERNEL); + wsa881x = devm_kzalloc_obj(dev, *wsa881x); if (!wsa881x) return -ENOMEM; diff --git a/sound/soc/codecs/wsa883x.c b/sound/soc/codecs/wsa883x.c index 17d8babc6123b9..64391d654a08bd 100644 --- a/sound/soc/codecs/wsa883x.c +++ b/sound/soc/codecs/wsa883x.c @@ -1602,7 +1602,7 @@ static int wsa883x_probe(struct sdw_slave *pdev, struct device *dev = &pdev->dev; int ret; - wsa883x = devm_kzalloc(dev, sizeof(*wsa883x), GFP_KERNEL); + wsa883x = devm_kzalloc_obj(dev, *wsa883x); if (!wsa883x) return -ENOMEM; diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c index acf32af5aae3e7..f58ce92c46d40f 100644 --- a/sound/soc/codecs/wsa884x.c +++ b/sound/soc/codecs/wsa884x.c @@ -2047,7 +2047,7 @@ static int wsa884x_probe(struct sdw_slave *pdev, unsigned int i; int ret; - wsa884x = devm_kzalloc(dev, sizeof(*wsa884x), GFP_KERNEL); + wsa884x = devm_kzalloc_obj(dev, *wsa884x); if (!wsa884x) return -ENOMEM; diff --git a/sound/soc/codecs/wsa885x.c b/sound/soc/codecs/wsa885x.c index 5ffbf9e89fd935..2582b4945a9bd7 100644 --- a/sound/soc/codecs/wsa885x.c +++ b/sound/soc/codecs/wsa885x.c @@ -1448,7 +1448,7 @@ static int wsa885x_probe(struct i2c_client *client) int ret; struct device *dev = &client->dev; - wsa885x = devm_kzalloc(dev, sizeof(*wsa885x), GFP_KERNEL); + wsa885x = devm_kzalloc_obj(dev, *wsa885x); if (!wsa885x) return -ENOMEM; diff --git a/sound/soc/codecs/zl38060.c b/sound/soc/codecs/zl38060.c index b7062860cca15e..02757ae2b58b27 100644 --- a/sound/soc/codecs/zl38060.c +++ b/sound/soc/codecs/zl38060.c @@ -572,7 +572,7 @@ static int zl38_spi_probe(struct spi_device *spi) usleep_range(3000, 10000); } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/dwc/dwc-i2s.c b/sound/soc/dwc/dwc-i2s.c index dbda943cfaf35a..8e4f0ed92d098f 100644 --- a/sound/soc/dwc/dwc-i2s.c +++ b/sound/soc/dwc/dwc-i2s.c @@ -331,7 +331,10 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream, } } else { u32 bitclk = config->sample_rate * - config->data_width * 2; + config->data_width * 2; + if (dev->tdm_slots) + bitclk = config->sample_rate * + config->data_width * dev->tdm_slots; ret = clk_set_rate(dev->clk, bitclk); if (ret) { @@ -387,29 +390,19 @@ static int dw_i2s_trigger(struct snd_pcm_substream *substream, static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) { struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); - int ret = 0; switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { case SND_SOC_DAIFMT_BC_FC: - if (dev->capability & DW_I2S_SLAVE) - ret = 0; - else - ret = -EINVAL; + if (!(dev->capability & DW_I2S_SLAVE)) + return -EINVAL; break; case SND_SOC_DAIFMT_BP_FP: - if (dev->capability & DW_I2S_MASTER) - ret = 0; - else - ret = -EINVAL; - break; - case SND_SOC_DAIFMT_BC_FP: - case SND_SOC_DAIFMT_BP_FC: - ret = -EINVAL; + if (!(dev->capability & DW_I2S_MASTER)) + return -EINVAL; break; default: dev_dbg(dev->dev, "dwc : Invalid clock provider format\n"); - ret = -EINVAL; - break; + return -EINVAL; } switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { @@ -424,11 +417,11 @@ static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) dev->frame_offset = 0; break; default: - dev_err(dev->dev, "DAI format unsupported"); + dev_err(dev->dev, "DAI format unsupported\n"); return -EINVAL; } - return ret; + return 0; } static int dw_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, unsigned int tx_mask, @@ -612,7 +605,7 @@ static int dw_configure_dai(struct dw_i2s_dev *dev, idx = 1; dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM; dw_i2s_dai->playback.channels_max = - 1 << (COMP1_TX_CHANNELS(comp1) + 1); + 2 * (COMP1_TX_CHANNELS(comp1) + 1); dw_i2s_dai->playback.formats = formats[idx]; dw_i2s_dai->playback.rates = rates; } @@ -626,7 +619,7 @@ static int dw_configure_dai(struct dw_i2s_dev *dev, idx = 1; dw_i2s_dai->capture.channels_min = MIN_CHANNEL_NUM; dw_i2s_dai->capture.channels_max = - 1 << (COMP1_RX_CHANNELS(comp1) + 1); + 2 * (COMP1_RX_CHANNELS(comp1) + 1); dw_i2s_dai->capture.formats = formats[idx]; dw_i2s_dai->capture.rates = rates; } @@ -671,14 +664,14 @@ static int dw_configure_dai_by_pd(struct dw_i2s_dev *dev, idx2 = COMP1_TX_WORDSIZE_0(comp1); dev->play_dma_data.dt.addr = res->start + I2S_TXDMA; dev->play_dma_data.dt.fifo_size = dev->fifo_th * 2 * - (fifo_width[idx2]) >> 8; + fifo_width[idx2] / 8; dev->play_dma_data.dt.maxburst = 16; } if (COMP1_RX_ENABLED(comp1)) { idx2 = COMP2_RX_WORDSIZE_0(comp2); dev->capture_dma_data.dt.addr = res->start + I2S_RXDMA; dev->capture_dma_data.dt.fifo_size = dev->fifo_th * 2 * - (fifo_width[idx2] >> 8); + fifo_width[idx2] / 8; dev->capture_dma_data.dt.maxburst = 16; } } else { @@ -718,7 +711,7 @@ static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev, dev->capability |= DWC_I2S_PLAY; dev->play_dma_data.dt.addr = res->start + I2S_TXDMA; dev->play_dma_data.dt.fifo_size = fifo_depth * - (fifo_width[idx2]) >> 8; + fifo_width[idx2] / 8; dev->play_dma_data.dt.maxburst = 16; } if (COMP1_RX_ENABLED(comp1)) { @@ -727,7 +720,7 @@ static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev, dev->capability |= DWC_I2S_RECORD; dev->capture_dma_data.dt.addr = res->start + I2S_RXDMA; dev->capture_dma_data.dt.fifo_size = fifo_depth * - (fifo_width[idx2] >> 8); + fifo_width[idx2] / 8; dev->capture_dma_data.dt.maxburst = 16; } @@ -759,7 +752,7 @@ static int jh7110_i2s_crg_master_init(struct dw_i2s_dev *dev) ret = clk_bulk_get(dev->dev, ARRAY_SIZE(clks), clks); if (ret) - return dev_err_probe(dev->dev, ret, "failed to get i2s clocks\n"); + return ret; mclk = clks[0].clk; mclk_ext = clks[1].clk; @@ -837,7 +830,7 @@ static int jh7110_i2s_crg_slave_init(struct dw_i2s_dev *dev) ret = clk_bulk_get(dev->dev, ARRAY_SIZE(clks), clks); if (ret) - return dev_err_probe(dev->dev, ret, "failed to get i2s clocks\n"); + return ret; mclk = clks[0].clk; mclk_ext = clks[1].clk; @@ -933,11 +926,11 @@ static int dw_i2s_probe(struct platform_device *pdev) if (!pdata) pdata = dev_get_platdata(&pdev->dev); - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; - dw_i2s_dai = devm_kzalloc(&pdev->dev, sizeof(*dw_i2s_dai), GFP_KERNEL); + dw_i2s_dai = devm_kzalloc_obj(&pdev->dev, *dw_i2s_dai); if (!dw_i2s_dai) return -ENOMEM; @@ -968,15 +961,15 @@ static int dw_i2s_probe(struct platform_device *pdev) } irq = platform_get_irq_optional(pdev, 0); - if (irq == -EPROBE_DEFER) - return irq; + if (irq < 0 && irq != -ENXIO) { + ret = dev_err_probe(&pdev->dev, irq, "failed to get IRQ\n"); + goto err_assert_reset; + } if (irq > 0) { ret = devm_request_irq(&pdev->dev, irq, i2s_irq_handler, 0, pdev->name, dev); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request irq\n"); + if (ret < 0) goto err_assert_reset; - } } dev->i2s_reg_comp1 = I2S_COMP_PARAM_1; @@ -1017,10 +1010,8 @@ static int dw_i2s_probe(struct platform_device *pdev) dev_set_drvdata(&pdev->dev, dev); ret = devm_snd_soc_register_component(&pdev->dev, &dw_i2s_component, dw_i2s_dai, 1); - if (ret != 0) { - dev_err(&pdev->dev, "not able to register dai\n"); + if (ret) goto err_assert_reset; - } if (!pdata || dev->is_jh7110) { if (irq >= 0) { diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c index 310ee4c282a1c2..c2a112506d7012 100644 --- a/sound/soc/fsl/fsl-asoc-card.c +++ b/sound/soc/fsl/fsl-asoc-card.c @@ -1094,7 +1094,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev) u32 width; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -1141,7 +1141,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev) * "DPCM Link Back-End": 1 cpus, 2 codecs * totally 10 components */ - dlc = devm_kcalloc(&pdev->dev, 10, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_objs(&pdev->dev, *dlc, 10); if (!dlc) { ret = -ENOMEM; goto asrc_fail; @@ -1378,6 +1378,8 @@ static int fsl_asoc_card_probe(struct platform_device *pdev) } asrc_fail: + if (asrc_pdev) + put_device(&asrc_pdev->dev); of_node_put(asrc_np); of_node_put(codec_np[0]); of_node_put(codec_np[1]); diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index faf348dd582d39..b1dadec221fc97 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -1258,6 +1258,20 @@ static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair) static int fsl_asrc_runtime_resume(struct device *dev); static int fsl_asrc_runtime_suspend(struct device *dev); +/* devm action: runtime suspend the device if it is not runtime suspended yet */ +static void fsl_asrc_runtime_suspend_action(void *data) +{ + struct device *dev = data; + + if (!pm_runtime_status_suspended(dev)) + fsl_asrc_runtime_suspend(dev); +} + +static void fsl_asrc_m2m_exit_action(void *data) +{ + fsl_asrc_m2m_exit(data); +} + static int fsl_asrc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -1271,11 +1285,11 @@ static int fsl_asrc_probe(struct platform_device *pdev) char tmp[16]; u32 width; - asrc = devm_kzalloc(&pdev->dev, sizeof(*asrc), GFP_KERNEL); + asrc = devm_kzalloc_obj(&pdev->dev, *asrc); if (!asrc) return -ENOMEM; - asrc_priv = devm_kzalloc(&pdev->dev, sizeof(*asrc_priv), GFP_KERNEL); + asrc_priv = devm_kzalloc_obj(&pdev->dev, *asrc_priv); if (!asrc_priv) return -ENOMEM; @@ -1299,36 +1313,29 @@ static int fsl_asrc_probe(struct platform_device *pdev) if (irq < 0) return irq; - ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0, - dev_name(&pdev->dev), asrc); - if (ret) { - dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret); - return ret; - } - asrc->mem_clk = devm_clk_get(&pdev->dev, "mem"); - if (IS_ERR(asrc->mem_clk)) { - dev_err(&pdev->dev, "failed to get mem clock\n"); - return PTR_ERR(asrc->mem_clk); - } + if (IS_ERR(asrc->mem_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(asrc->mem_clk), + "failed to get mem clock\n"); asrc->ipg_clk = devm_clk_get(&pdev->dev, "ipg"); - if (IS_ERR(asrc->ipg_clk)) { - dev_err(&pdev->dev, "failed to get ipg clock\n"); - return PTR_ERR(asrc->ipg_clk); - } + if (IS_ERR(asrc->ipg_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(asrc->ipg_clk), + "failed to get ipg clock\n"); asrc->spba_clk = devm_clk_get(&pdev->dev, "spba"); - if (IS_ERR(asrc->spba_clk)) + if (IS_ERR(asrc->spba_clk)) { + if (PTR_ERR(asrc->spba_clk) == -EPROBE_DEFER) + return -EPROBE_DEFER; dev_warn(&pdev->dev, "failed to get spba clock\n"); + } for (i = 0; i < ASRC_CLK_MAX_NUM; i++) { sprintf(tmp, "asrck_%x", i); asrc_priv->asrck_clk[i] = devm_clk_get(&pdev->dev, tmp); - if (IS_ERR(asrc_priv->asrck_clk[i])) { - dev_err(&pdev->dev, "failed to get %s clock\n", tmp); - return PTR_ERR(asrc_priv->asrck_clk[i]); - } + if (IS_ERR(asrc_priv->asrck_clk[i])) + return dev_err_probe(&pdev->dev, PTR_ERR(asrc_priv->asrck_clk[i]), + "failed to get %s clock\n", tmp); } asrc_priv->soc = of_device_get_match_data(&pdev->dev); @@ -1420,59 +1427,64 @@ static int fsl_asrc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, asrc); spin_lock_init(&asrc->lock); - pm_runtime_enable(&pdev->dev); + + /* + * Ensure the device is suspended after the IRQ and component + * have been released. + */ + ret = devm_add_action(&pdev->dev, fsl_asrc_runtime_suspend_action, + &pdev->dev); + if (ret) + return ret; + + ret = devm_pm_runtime_enable(&pdev->dev); + if (ret) + return ret; if (!pm_runtime_enabled(&pdev->dev)) { ret = fsl_asrc_runtime_resume(&pdev->dev); - if (ret) - goto err_pm_disable; + if (ret) { + devm_remove_action(&pdev->dev, + fsl_asrc_runtime_suspend_action, + &pdev->dev); + return ret; + } } ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) - goto err_pm_get_sync; + return ret; ret = fsl_asrc_init(asrc); if (ret) { dev_err(&pdev->dev, "failed to init asrc %d\n", ret); - goto err_pm_get_sync; + pm_runtime_put_noidle(&pdev->dev); + return ret; + } + + /* Request the IRQ only once the device is initialized */ + ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0, + dev_name(&pdev->dev), asrc); + if (ret) { + pm_runtime_put_noidle(&pdev->dev); + return ret; } ret = pm_runtime_put_sync(&pdev->dev); if (ret < 0 && ret != -ENOSYS) - goto err_pm_get_sync; + return ret; ret = devm_snd_soc_register_component(&pdev->dev, &fsl_asrc_component, fsl_asrc_dai, ARRAY_SIZE(fsl_asrc_dai)); - if (ret) { - dev_err(&pdev->dev, "failed to register ASoC DAI\n"); - goto err_pm_get_sync; - } + if (ret) + return ret; ret = fsl_asrc_m2m_init(asrc); if (ret) { dev_err(&pdev->dev, "failed to init m2m device %d\n", ret); - goto err_pm_get_sync; + return ret; } - return 0; - -err_pm_get_sync: - if (!pm_runtime_status_suspended(&pdev->dev)) - fsl_asrc_runtime_suspend(&pdev->dev); -err_pm_disable: - pm_runtime_disable(&pdev->dev); - return ret; -} - -static void fsl_asrc_remove(struct platform_device *pdev) -{ - struct fsl_asrc *asrc = dev_get_drvdata(&pdev->dev); - - fsl_asrc_m2m_exit(asrc); - - pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - fsl_asrc_runtime_suspend(&pdev->dev); + return devm_add_action_or_reset(&pdev->dev, fsl_asrc_m2m_exit_action, asrc); } static int fsl_asrc_runtime_resume(struct device *dev) @@ -1634,7 +1646,6 @@ MODULE_DEVICE_TABLE(of, fsl_asrc_ids); static struct platform_driver fsl_asrc_driver = { .probe = fsl_asrc_probe, - .remove = fsl_asrc_remove, .driver = { .name = "fsl-asrc", .of_match_table = fsl_asrc_ids, diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c index e5b7b283c16b7b..57f131c383758d 100644 --- a/sound/soc/fsl/fsl_asrc_dma.c +++ b/sound/soc/fsl/fsl_asrc_dma.c @@ -261,7 +261,7 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, pair->dma_data.priority = tmp_data->priority; dma_release_channel(tmp_chan); - of_dma_node = pair->dma_chan[!dir]->device->dev->of_node; + of_dma_node = dmaengine_get_provider_device(pair->dma_chan[!dir])->of_node; pair->dma_chan[dir] = __dma_request_channel(&mask, filter, &pair->dma_data, of_dma_node); @@ -526,7 +526,7 @@ static int fsl_asrc_dma_pcm_new(struct snd_soc_component *component, ret = snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, - chan->device->dev, + dmaengine_get_dma_device(chan), FSL_ASRC_DMABUF_SIZE); dma_release_channel(chan); diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c index 796a78124765f4..e78e137fbb574b 100644 --- a/sound/soc/fsl/fsl_asrc_m2m.c +++ b/sound/soc/fsl/fsl_asrc_m2m.c @@ -701,7 +701,7 @@ int fsl_asrc_m2m_init(struct fsl_asrc *asrc) asrc->card = card; - compr = devm_kzalloc(dev, sizeof(*compr), GFP_KERNEL); + compr = devm_kzalloc_obj(dev, *compr); if (!compr) { ret = -ENOMEM; goto err; diff --git a/sound/soc/fsl/fsl_aud2htx.c b/sound/soc/fsl/fsl_aud2htx.c index 8f2aa8f7d4e8ef..06b25ced91bc2b 100644 --- a/sound/soc/fsl/fsl_aud2htx.c +++ b/sound/soc/fsl/fsl_aud2htx.c @@ -189,7 +189,7 @@ static int fsl_aud2htx_probe(struct platform_device *pdev) void __iomem *regs; int ret, irq; - aud2htx = devm_kzalloc(&pdev->dev, sizeof(*aud2htx), GFP_KERNEL); + aud2htx = devm_kzalloc_obj(&pdev->dev, *aud2htx); if (!aud2htx) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c index d4140e170edf84..bac2c7d0fe68ac 100644 --- a/sound/soc/fsl/fsl_audmix.c +++ b/sound/soc/fsl/fsl_audmix.c @@ -464,7 +464,7 @@ static int fsl_audmix_probe(struct platform_device *pdev) void __iomem *regs; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c index b1b341132dd6d5..876b35120fcc54 100644 --- a/sound/soc/fsl/fsl_dma.c +++ b/sound/soc/fsl/fsl_dma.c @@ -835,7 +835,7 @@ static int fsl_soc_dma_probe(struct platform_device *pdev) if (irq < 0) return irq; - dma = devm_kzalloc(&pdev->dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(&pdev->dev, *dma); if (!dma) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c index 5d715bc0735729..5c5002537951ee 100644 --- a/sound/soc/fsl/fsl_easrc.c +++ b/sound/soc/fsl/fsl_easrc.c @@ -2211,11 +2211,11 @@ static int fsl_easrc_probe(struct platform_device *pdev) u32 asrc_fmt = 0; int ret, irq; - easrc = devm_kzalloc(dev, sizeof(*easrc), GFP_KERNEL); + easrc = devm_kzalloc_obj(dev, *easrc); if (!easrc) return -ENOMEM; - easrc_priv = devm_kzalloc(dev, sizeof(*easrc_priv), GFP_KERNEL); + easrc_priv = devm_kzalloc_obj(dev, *easrc_priv); if (!easrc_priv) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index 83a996377135c7..a19073cdd1cffc 100644 --- a/sound/soc/fsl/fsl_esai.c +++ b/sound/soc/fsl/fsl_esai.c @@ -955,7 +955,7 @@ static int fsl_esai_probe(struct platform_device *pdev) void __iomem *regs; int irq, ret; - esai_priv = devm_kzalloc(&pdev->dev, sizeof(*esai_priv), GFP_KERNEL); + esai_priv = devm_kzalloc_obj(&pdev->dev, *esai_priv); if (!esai_priv) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_micfil.c b/sound/soc/fsl/fsl_micfil.c index 5d8f0f76ab46fa..588b3b8b68c5f8 100644 --- a/sound/soc/fsl/fsl_micfil.c +++ b/sound/soc/fsl/fsl_micfil.c @@ -1510,7 +1510,7 @@ static int fsl_micfil_probe(struct platform_device *pdev) void __iomem *regs; int ret, i; - micfil = devm_kzalloc(&pdev->dev, sizeof(*micfil), GFP_KERNEL); + micfil = devm_kzalloc_obj(&pdev->dev, *micfil); if (!micfil) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_mqs.c b/sound/soc/fsl/fsl_mqs.c index 5b00488253bbb3..fd4a5f4a56bed8 100644 --- a/sound/soc/fsl/fsl_mqs.c +++ b/sound/soc/fsl/fsl_mqs.c @@ -243,7 +243,7 @@ static int fsl_mqs_probe(struct platform_device *pdev) void __iomem *regs; int ret; - mqs_priv = devm_kzalloc(&pdev->dev, sizeof(*mqs_priv), GFP_KERNEL); + mqs_priv = devm_kzalloc_obj(&pdev->dev, *mqs_priv); if (!mqs_priv) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c index f27934cf49da0f..bc1afa37137b4e 100644 --- a/sound/soc/fsl/fsl_qmc_audio.c +++ b/sound/soc/fsl/fsl_qmc_audio.c @@ -781,8 +781,8 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_audio, struct device_node * return dev_err_probe(qmc_audio->dev, -EINVAL, "dai %d no QMC channel defined\n", qmc_dai->id); - qmc_dai->qmc_chans = devm_kcalloc(qmc_audio->dev, count, sizeof(*qmc_dai->qmc_chans), - GFP_KERNEL); + qmc_dai->qmc_chans = devm_kzalloc_objs(qmc_audio->dev, + *qmc_dai->qmc_chans, count); if (!qmc_dai->qmc_chans) return -ENOMEM; @@ -908,7 +908,7 @@ static int qmc_audio_probe(struct platform_device *pdev) unsigned int i; int ret; - qmc_audio = devm_kzalloc(&pdev->dev, sizeof(*qmc_audio), GFP_KERNEL); + qmc_audio = devm_kzalloc_obj(&pdev->dev, *qmc_audio); if (!qmc_audio) return -ENOMEM; @@ -916,15 +916,15 @@ static int qmc_audio_probe(struct platform_device *pdev) qmc_audio->num_dais = of_get_available_child_count(np); if (qmc_audio->num_dais) { - qmc_audio->dais = devm_kcalloc(&pdev->dev, qmc_audio->num_dais, - sizeof(*qmc_audio->dais), - GFP_KERNEL); + qmc_audio->dais = devm_kzalloc_objs(&pdev->dev, + *qmc_audio->dais, + qmc_audio->num_dais); if (!qmc_audio->dais) return -ENOMEM; - qmc_audio->dai_drivers = devm_kcalloc(&pdev->dev, qmc_audio->num_dais, - sizeof(*qmc_audio->dai_drivers), - GFP_KERNEL); + qmc_audio->dai_drivers = devm_kzalloc_objs(&pdev->dev, + *qmc_audio->dai_drivers, + qmc_audio->num_dais); if (!qmc_audio->dai_drivers) return -ENOMEM; } diff --git a/sound/soc/fsl/fsl_rpmsg.c b/sound/soc/fsl/fsl_rpmsg.c index 5708b3a9878dc0..7782c1e5d4e86b 100644 --- a/sound/soc/fsl/fsl_rpmsg.c +++ b/sound/soc/fsl/fsl_rpmsg.c @@ -201,12 +201,12 @@ static int fsl_rpmsg_probe(struct platform_device *pdev) struct fsl_rpmsg *rpmsg; int ret; - dai_drv = devm_kzalloc(&pdev->dev, sizeof(struct snd_soc_dai_driver), GFP_KERNEL); + dai_drv = devm_kzalloc_obj(&pdev->dev, struct snd_soc_dai_driver); if (!dai_drv) return -ENOMEM; memcpy(dai_drv, &fsl_rpmsg_dai, sizeof(fsl_rpmsg_dai)); - rpmsg = devm_kzalloc(&pdev->dev, sizeof(struct fsl_rpmsg), GFP_KERNEL); + rpmsg = devm_kzalloc_obj(&pdev->dev, struct fsl_rpmsg); if (!rpmsg) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c index 430e896d064e3b..606ec72596083a 100644 --- a/sound/soc/fsl/fsl_sai.c +++ b/sound/soc/fsl/fsl_sai.c @@ -1410,7 +1410,7 @@ static int fsl_sai_check_version(struct device *dev) return 0; } -static int fsl_sai_reset_hw(struct device *dev) +static void fsl_sai_reset_hw(struct device *dev) { struct fsl_sai *sai = dev_get_drvdata(dev); unsigned char ofs = sai->soc_data->reg_offset; @@ -1421,18 +1421,12 @@ static int fsl_sai_reset_hw(struct device *dev) * Bootloader may leave SAI running causing interrupt storm. */ ret = regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), 0); - if (ret) { + if (ret) dev_err(dev, "Failed to clear TCSR: %d\n", ret); - return ret; - } ret = regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), 0); - if (ret) { + if (ret) dev_err(dev, "Failed to clear RCSR: %d\n", ret); - return ret; - } - - return 0; } /* @@ -1485,7 +1479,7 @@ static int fsl_sai_read_dlcfg(struct fsl_sai *sai) num_cfg = elems / 3; /* Add one more for default value */ - cfg = devm_kcalloc(&pdev->dev, num_cfg + 1, sizeof(*cfg), GFP_KERNEL); + cfg = devm_kzalloc_objs(&pdev->dev, *cfg, num_cfg + 1); if (!cfg) return -ENOMEM; @@ -1561,7 +1555,7 @@ static int fsl_sai_probe(struct platform_device *pdev) u32 dmas[4]; u32 val; - sai = devm_kzalloc(dev, sizeof(*sai), GFP_KERNEL); + sai = devm_kzalloc_obj(dev, *sai); if (!sai) return -ENOMEM; @@ -1627,8 +1621,10 @@ static int fsl_sai_probe(struct platform_device *pdev) /* read dataline mask for rx and tx*/ ret = fsl_sai_read_dlcfg(sai); - if (ret < 0) + if (ret < 0) { + dev_err(dev, "failed to read dlcfg %d\n", ret); return ret; + } irq = platform_get_irq(pdev, 0); if (irq < 0) diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c index ad1206ed98828e..d0ec2153bb2906 100644 --- a/sound/soc/fsl/fsl_spdif.c +++ b/sound/soc/fsl/fsl_spdif.c @@ -1534,7 +1534,7 @@ static int fsl_spdif_probe(struct platform_device *pdev) int irq, ret, i; char tmp[16]; - spdif_priv = devm_kzalloc(&pdev->dev, sizeof(*spdif_priv), GFP_KERNEL); + spdif_priv = devm_kzalloc_obj(&pdev->dev, *spdif_priv); if (!spdif_priv) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index dc022976c9823a..0a10ab6ad8c773 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -1508,7 +1508,7 @@ static int fsl_ssi_probe(struct platform_device *pdev) void __iomem *iomem; int ret = 0; - ssi = devm_kzalloc(dev, sizeof(*ssi), GFP_KERNEL); + ssi = devm_kzalloc_obj(dev, *ssi); if (!ssi) return -ENOMEM; diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c index 29929dfcce2a69..4c703157a25bac 100644 --- a/sound/soc/fsl/fsl_xcvr.c +++ b/sound/soc/fsl/fsl_xcvr.c @@ -1621,7 +1621,7 @@ static int fsl_xcvr_probe(struct platform_device *pdev) void __iomem *regs; int ret; - xcvr = devm_kzalloc(dev, sizeof(*xcvr), GFP_KERNEL); + xcvr = devm_kzalloc_obj(dev, *xcvr); if (!xcvr) return -ENOMEM; diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c index b55dfbdb450262..35d4d1a0be092d 100644 --- a/sound/soc/fsl/imx-audio-rpmsg.c +++ b/sound/soc/fsl/imx-audio-rpmsg.c @@ -79,7 +79,7 @@ static int imx_audio_rpmsg_probe(struct rpmsg_device *rpdev) dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", rpdev->src, rpdev->dst); - data = devm_kzalloc(&rpdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&rpdev->dev, *data); if (!data) return -ENOMEM; @@ -92,7 +92,7 @@ static int imx_audio_rpmsg_probe(struct rpmsg_device *rpdev) NULL, 0); if (IS_ERR(data->rpmsg_pdev)) { dev_err(&rpdev->dev, "failed to register rpmsg platform.\n"); - ret = PTR_ERR(data->rpmsg_pdev); + return PTR_ERR(data->rpmsg_pdev); } data->card_pdev = platform_device_register_data(&rpdev->dev, @@ -103,9 +103,12 @@ static int imx_audio_rpmsg_probe(struct rpmsg_device *rpdev) if (IS_ERR(data->card_pdev)) { dev_err(&rpdev->dev, "failed to register rpmsg card.\n"); ret = PTR_ERR(data->card_pdev); + platform_device_unregister(data->rpmsg_pdev); + data->rpmsg_pdev = NULL; + return ret; } - return ret; + return 0; } static void imx_audio_rpmsg_remove(struct rpmsg_device *rpdev) diff --git a/sound/soc/fsl/imx-audmix.c b/sound/soc/fsl/imx-audmix.c index dac5d4ddacd6ef..2372cd26ee4716 100644 --- a/sound/soc/fsl/imx-audmix.c +++ b/sound/soc/fsl/imx-audmix.c @@ -162,28 +162,28 @@ static int imx_audmix_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; num_dai += 1; priv->num_dai = 2 * num_dai; - priv->dai = devm_kcalloc(&pdev->dev, priv->num_dai, - sizeof(struct snd_soc_dai_link), GFP_KERNEL); + priv->dai = devm_kzalloc_objs(&pdev->dev, struct snd_soc_dai_link, + priv->num_dai); if (!priv->dai) return -ENOMEM; priv->num_dai_conf = num_dai; - priv->dai_conf = devm_kcalloc(&pdev->dev, priv->num_dai_conf, - sizeof(struct snd_soc_codec_conf), - GFP_KERNEL); + priv->dai_conf = devm_kzalloc_objs(&pdev->dev, + struct snd_soc_codec_conf, + priv->num_dai_conf); if (!priv->dai_conf) return -ENOMEM; priv->num_dapm_routes = num_dai; - priv->dapm_routes = devm_kcalloc(&pdev->dev, priv->num_dapm_routes, - sizeof(struct snd_soc_dapm_route), - GFP_KERNEL); + priv->dapm_routes = devm_kzalloc_objs(&pdev->dev, + struct snd_soc_dapm_route, + priv->num_dapm_routes); if (!priv->dapm_routes) return -ENOMEM; @@ -191,7 +191,7 @@ static int imx_audmix_probe(struct platform_device *pdev) struct snd_soc_dai_link_component *dlc; /* for CPU x 2 */ - dlc = devm_kcalloc(&pdev->dev, 2, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_objs(&pdev->dev, *dlc, 2); if (!dlc) return -ENOMEM; diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c index d46f43ab66cf62..edd5f99c8463b4 100644 --- a/sound/soc/fsl/imx-audmux.c +++ b/sound/soc/fsl/imx-audmux.c @@ -305,7 +305,7 @@ static int imx_audmux_probe(struct platform_device *pdev) return -EINVAL; } - regcache = devm_kcalloc(&pdev->dev, reg_max, sizeof(u32), GFP_KERNEL); + regcache = devm_kzalloc_objs(&pdev->dev, u32, reg_max); if (!regcache) return -ENOMEM; diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c index e3cb1438e837ba..1f59b7e8892a5e 100644 --- a/sound/soc/fsl/imx-card.c +++ b/sound/soc/fsl/imx-card.c @@ -570,11 +570,11 @@ static int imx_card_parse_of(struct imx_card_data *data) num_links = of_get_child_count(dev->of_node); /* Allocate the DAI link array */ - card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL); + card->dai_link = devm_kzalloc_objs(dev, *link, num_links); if (!card->dai_link) return -ENOMEM; - data->link_data = devm_kcalloc(dev, num_links, sizeof(*link_data), GFP_KERNEL); + data->link_data = devm_kzalloc_objs(dev, *link_data, num_links); if (!data->link_data) return -ENOMEM; @@ -769,11 +769,11 @@ static int imx_card_probe(struct platform_device *pdev) struct imx_card_data *data; int ret, i; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) return -ENOMEM; - plat_data = devm_kzalloc(&pdev->dev, sizeof(*plat_data), GFP_KERNEL); + plat_data = devm_kzalloc_obj(&pdev->dev, *plat_data); if (!plat_data) return -ENOMEM; @@ -788,9 +788,9 @@ static int imx_card_probe(struct platform_device *pdev) return ret; data->num_dapm_routes = plat_data->num_codecs + 1; - data->dapm_routes = devm_kcalloc(&pdev->dev, data->num_dapm_routes, - sizeof(struct snd_soc_dapm_route), - GFP_KERNEL); + data->dapm_routes = devm_kzalloc_objs(&pdev->dev, + struct snd_soc_dapm_route, + data->num_dapm_routes); if (!data->dapm_routes) return -ENOMEM; diff --git a/sound/soc/fsl/imx-es8328.c b/sound/soc/fsl/imx-es8328.c index 3ef92f6dfc6bb1..c1f5b008851968 100644 --- a/sound/soc/fsl/imx-es8328.c +++ b/sound/soc/fsl/imx-es8328.c @@ -158,7 +158,7 @@ static int imx_es8328_probe(struct platform_device *pdev) goto fail; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) { ret = -ENOMEM; goto put_device; diff --git a/sound/soc/fsl/imx-hdmi.c b/sound/soc/fsl/imx-hdmi.c index 1115189cc6400a..59bbab22d5d413 100644 --- a/sound/soc/fsl/imx-hdmi.c +++ b/sound/soc/fsl/imx-hdmi.c @@ -116,7 +116,7 @@ static int imx_hdmi_probe(struct platform_device *pdev) goto fail; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) { ret = -ENOMEM; goto fail; diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c index 4fa208d6a03221..3c9ca1d4c4a2ed 100644 --- a/sound/soc/fsl/imx-pcm-dma.c +++ b/sound/soc/fsl/imx-pcm-dma.c @@ -38,8 +38,7 @@ int imx_pcm_dma_init(struct platform_device *pdev) { struct snd_dmaengine_pcm_config *config; - config = devm_kzalloc(&pdev->dev, - sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL); + config = devm_kzalloc_obj(&pdev->dev, struct snd_dmaengine_pcm_config); if (!config) return -ENOMEM; *config = imx_dmaengine_pcm_config; diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c index 6a0174d6c78df4..6852f49a18adcd 100644 --- a/sound/soc/fsl/imx-pcm-rpmsg.c +++ b/sound/soc/fsl/imx-pcm-rpmsg.c @@ -698,7 +698,7 @@ static int imx_rpmsg_pcm_probe(struct platform_device *pdev) struct rpmsg_info *info; int ret, i; - info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; diff --git a/sound/soc/fsl/imx-rpmsg.c b/sound/soc/fsl/imx-rpmsg.c index 5f1af258caf2d1..f6a2633bb812d2 100644 --- a/sound/soc/fsl/imx-rpmsg.c +++ b/sound/soc/fsl/imx-rpmsg.c @@ -158,7 +158,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev) if (!dlc) return -ENOMEM; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) { ret = -ENOMEM; goto fail; diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c index ac568210b4e649..fa9f610bb377b1 100644 --- a/sound/soc/fsl/imx-sgtl5000.c +++ b/sound/soc/fsl/imx-sgtl5000.c @@ -117,7 +117,7 @@ static int imx_sgtl5000_probe(struct platform_device *pdev) goto fail; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(&pdev->dev, *data); if (!data) { ret = -ENOMEM; goto put_device; diff --git a/sound/soc/fsl/lpc3xxx-i2s.c b/sound/soc/fsl/lpc3xxx-i2s.c index c65c17dfa17474..67bbc69dc2d22f 100644 --- a/sound/soc/fsl/lpc3xxx-i2s.c +++ b/sound/soc/fsl/lpc3xxx-i2s.c @@ -82,8 +82,7 @@ static int lpc3xxx_i2s_startup(struct snd_pcm_substream *substream, struct snd_s if (flag & i2s_info_p->streams_in_use) { dev_warn(dev, "I2S channel is busy\n"); - ret = -EBUSY; - return ret; + return -EBUSY; } if (i2s_info_p->streams_in_use == 0) { @@ -199,12 +198,12 @@ static int lpc3xxx_i2s_hw_params(struct snd_pcm_substream *substream, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { regmap_write(regs, LPC3XXX_REG_I2S_DMA1, - LPC3XXX_I2S_DMA1_TX_EN | LPC3XXX_I2S_DMA0_TX_DEPTH(4)); + LPC3XXX_I2S_DMA1_TX_EN | LPC3XXX_I2S_DMA1_TX_DEPTH(4)); regmap_write(regs, LPC3XXX_REG_I2S_TX_RATE, (clkx << 8) | clky); regmap_write(regs, LPC3XXX_REG_I2S_DAO, tmp); } else { regmap_write(regs, LPC3XXX_REG_I2S_DMA0, - LPC3XXX_I2S_DMA0_RX_EN | LPC3XXX_I2S_DMA1_RX_DEPTH(4)); + LPC3XXX_I2S_DMA0_RX_EN | LPC3XXX_I2S_DMA0_RX_DEPTH(4)); regmap_write(regs, LPC3XXX_REG_I2S_RX_RATE, (clkx << 8) | clky); regmap_write(regs, LPC3XXX_REG_I2S_DAI, tmp); } @@ -306,7 +305,7 @@ static int lpc32xx_i2s_probe(struct platform_device *pdev) void __iomem *iomem; int ret; - i2s_info_p = devm_kzalloc(dev, sizeof(*i2s_info_p), GFP_KERNEL); + i2s_info_p = devm_kzalloc_obj(dev, *i2s_info_p); if (!i2s_info_p) return -ENOMEM; @@ -320,7 +319,7 @@ static int lpc32xx_i2s_probe(struct platform_device *pdev) i2s_info_p->regs = devm_regmap_init_mmio(dev, iomem, &lpc32xx_i2s_regconfig); if (IS_ERR(i2s_info_p->regs)) return dev_err_probe(dev, PTR_ERR(i2s_info_p->regs), - "failed to init register map: %pe\n", i2s_info_p->regs); + "failed to init register map\n"); i2s_info_p->clk = devm_clk_get(dev, NULL); if (IS_ERR(i2s_info_p->clk)) diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c index 8327fff3e1b5d2..bfd3576673a033 100644 --- a/sound/soc/fsl/mpc5200_dma.c +++ b/sound/soc/fsl/mpc5200_dma.c @@ -329,7 +329,7 @@ int mpc5200_audio_dma_create(struct platform_device *op) return irq; /* Allocate and initialize the driver private data */ - psc_dma = devm_kzalloc(&op->dev, sizeof(*psc_dma), GFP_KERNEL); + psc_dma = devm_kzalloc_obj(&op->dev, *psc_dma); if (!psc_dma) return -ENOMEM; diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c index 64d9f7e3461121..d66094554c187e 100644 --- a/sound/soc/fsl/pcm030-audio-fabric.c +++ b/sound/soc/fsl/pcm030-audio-fabric.c @@ -68,8 +68,7 @@ static int pcm030_fabric_probe(struct platform_device *op) if (!of_machine_is_compatible("phytec,pcm030")) return -ENODEV; - pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data), - GFP_KERNEL); + pdata = devm_kzalloc_obj(&op->dev, struct pcm030_audio_data); if (!pdata) return -ENOMEM; diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 127c2e6b308e09..1362f895cc615f 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -621,7 +621,7 @@ static int graph_probe(struct platform_device *pdev) struct snd_soc_card *card; /* Allocate the private data and the DAI link array */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/generic/audio-graph-card2-custom-sample.c b/sound/soc/generic/audio-graph-card2-custom-sample.c index 14b21267524046..9dbc22a5549df4 100644 --- a/sound/soc/generic/audio-graph-card2-custom-sample.c +++ b/sound/soc/generic/audio-graph-card2-custom-sample.c @@ -144,7 +144,7 @@ static int custom_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - custom_priv = devm_kzalloc(dev, sizeof(*custom_priv), GFP_KERNEL); + custom_priv = devm_kzalloc_obj(dev, *custom_priv); if (!custom_priv) return -ENOMEM; diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c index f20301c3a4412b..245a822c33586a 100644 --- a/sound/soc/generic/audio-graph-card2.c +++ b/sound/soc/generic/audio-graph-card2.c @@ -559,9 +559,10 @@ static int graph_parse_node_multi_nm(struct simple_util_priv *priv, struct device_node *mcodec_ep_n __free(device_node) = of_graph_get_remote_endpoint(mcpu_ep_n); struct device_node *mcodec_port __free(device_node) = ep_to_port(mcodec_ep_n); + struct device_node *ports __free(device_node) = port_to_ports(mcodec_port); ret = -EINVAL; - if (mcodec_ports != port_to_ports(mcodec_port)) + if (mcodec_ports != ports) break; for_each_of_graph_port(mcodec_ports, mcodec_port_i) { @@ -609,8 +610,9 @@ static int graph_parse_node_multi(struct simple_util_priv *priv, dai_link->num_cpus > 1 && dai_link->num_codecs > 1 && dai_link->num_cpus != dai_link->num_codecs) { - dai_link->ch_maps = devm_kcalloc(dev, nm_max, - sizeof(struct snd_soc_dai_link_ch_map), GFP_KERNEL); + dai_link->ch_maps = devm_kzalloc_objs(dev, + struct snd_soc_dai_link_ch_map, + nm_max); if (!dai_link->ch_maps) goto multi_err; } @@ -1004,7 +1006,7 @@ int audio_graph2_link_c2c(struct simple_util_priv *priv, struct device *dev = simple_priv_to_dev(priv); struct snd_soc_pcm_stream *c2c_conf; - c2c_conf = devm_kzalloc(dev, sizeof(*c2c_conf), GFP_KERNEL); + c2c_conf = devm_kzalloc_obj(dev, *c2c_conf); if (!c2c_conf) { /* * Clang doesn't allow to use "goto end" before calling __free(), @@ -1116,7 +1118,7 @@ static int graph_counter(struct device_node *lnk) * ignore first lnk part */ if (graph_lnk_is_multi(lnk)) { - struct device_node *ports = port_to_ports(lnk); + struct device_node *ports __free(device_node) = port_to_ports(lnk); /* * CPU/Codec = N:M case has many endpoints. @@ -1388,7 +1390,7 @@ static int graph_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; /* Allocate the private data and the DAI link array */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index de27163eeb0b21..2316ab3e79f18a 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -164,7 +164,7 @@ int simple_util_parse_tdm_width_map(struct simple_util_priv *priv, struct device } ret = -ENOMEM; - dai->tdm_width_map = devm_kcalloc(dev, n, sizeof(*dai->tdm_width_map), GFP_KERNEL); + dai->tdm_width_map = devm_kzalloc_objs(dev, *dai->tdm_width_map, n); if (!dai->tdm_width_map) return simple_ret(priv, ret); /* see NOTE */ @@ -674,7 +674,7 @@ static int simple_init_for_codec2codec(struct simple_util_priv *priv, } ret = -ENOMEM; - c2c_params = devm_kzalloc(rtd->dev, sizeof(*c2c_params), GFP_KERNEL); + c2c_params = devm_kzalloc_obj(rtd->dev, *c2c_params); if (!c2c_params) goto end; @@ -855,8 +855,7 @@ int simple_util_init_aux_jacks(struct snd_soc_card *card, char *prefix) if (num < 1) return 0; - priv->aux_jacks = devm_kcalloc(card->dev, num, - sizeof(struct snd_soc_jack), GFP_KERNEL); + priv->aux_jacks = devm_kzalloc_objs(card->dev, struct snd_soc_jack, num); if (!priv->aux_jacks) return simple_ret(priv, -ENOMEM); @@ -900,8 +899,8 @@ int simple_util_init_priv(struct simple_util_priv *priv, struct snd_soc_codec_conf *cconf = NULL; int i, dai_num = 0, dlc_num = 0, cnf_num = 0; - dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); - dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); + dai_props = devm_kzalloc_objs(dev, *dai_props, li->link); + dai_link = devm_kzalloc_objs(dev, *dai_link, li->link); if (!dai_props || !dai_link) return -ENOMEM; @@ -919,13 +918,13 @@ int simple_util_init_priv(struct simple_util_priv *priv, cnf_num += li->num[i].codecs; } - dais = devm_kcalloc(dev, dai_num, sizeof(*dais), GFP_KERNEL); - dlcs = devm_kcalloc(dev, dlc_num, sizeof(*dlcs), GFP_KERNEL); + dais = devm_kzalloc_objs(dev, *dais, dai_num); + dlcs = devm_kzalloc_objs(dev, *dlcs, dlc_num); if (!dais || !dlcs) return -ENOMEM; if (cnf_num) { - cconf = devm_kcalloc(dev, cnf_num, sizeof(*cconf), GFP_KERNEL); + cconf = devm_kzalloc_objs(dev, *cconf, cnf_num); if (!cconf) return -ENOMEM; } diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index b2fc91b8ab812d..a033ab6e23776d 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -756,7 +756,7 @@ static int simple_probe(struct platform_device *pdev) struct snd_soc_card *card; /* Allocate the private data and the DAI link array */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/generic/test-component.c b/sound/soc/generic/test-component.c index 6f9f498c4c5c15..87d0f0cc12e1a3 100644 --- a/sound/soc/generic/test-component.c +++ b/sound/soc/generic/test-component.c @@ -538,10 +538,10 @@ static int test_driver_probe(struct platform_device *pdev) return -EINVAL; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - cdriv = devm_kzalloc(dev, sizeof(*cdriv), GFP_KERNEL); - ddriv = devm_kcalloc(dev, num, sizeof(*ddriv), GFP_KERNEL); - dname = devm_kcalloc(dev, num, sizeof(*dname), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); + cdriv = devm_kzalloc_obj(dev, *cdriv); + ddriv = devm_kzalloc_objs(dev, *ddriv, num); + dname = devm_kzalloc_objs(dev, *dname, num); if (!priv || !cdriv || !ddriv || !dname || !adata) return -EINVAL; diff --git a/sound/soc/google/chv3-i2s.c b/sound/soc/google/chv3-i2s.c index 102f931da357ac..4bb03cc75de264 100644 --- a/sound/soc/google/chv3-i2s.c +++ b/sound/soc/google/chv3-i2s.c @@ -284,7 +284,7 @@ static int chv3_i2s_probe(struct platform_device *pdev) int res; int irq; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/hisilicon/hi6210-i2s.c b/sound/soc/hisilicon/hi6210-i2s.c index 7cede2689ed94b..554f44cd0d9af5 100644 --- a/sound/soc/hisilicon/hi6210-i2s.c +++ b/sound/soc/hisilicon/hi6210-i2s.c @@ -550,7 +550,7 @@ static int hi6210_i2s_probe(struct platform_device *pdev) struct resource *res; int ret; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/img/img-i2s-in.c b/sound/soc/img/img-i2s-in.c index 0c136dca186c4e..f52456be010b35 100644 --- a/sound/soc/img/img-i2s-in.c +++ b/sound/soc/img/img-i2s-in.c @@ -436,7 +436,7 @@ static int img_i2s_in_probe(struct platform_device *pdev) unsigned int max_i2s_chan_pow_2; struct device *dev = &pdev->dev; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; @@ -515,8 +515,8 @@ static int img_i2s_in_probe(struct platform_device *pdev) pm_runtime_put(&pdev->dev); - i2s->suspend_ch_ctl = devm_kcalloc(dev, - i2s->max_i2s_chan, sizeof(*i2s->suspend_ch_ctl), GFP_KERNEL); + i2s->suspend_ch_ctl = devm_kzalloc_objs(dev, *i2s->suspend_ch_ctl, + i2s->max_i2s_chan); if (!i2s->suspend_ch_ctl) { ret = -ENOMEM; goto err_suspend; diff --git a/sound/soc/img/img-i2s-out.c b/sound/soc/img/img-i2s-out.c index 2aa8182d561d2f..8531b8cbae2996 100644 --- a/sound/soc/img/img-i2s-out.c +++ b/sound/soc/img/img-i2s-out.c @@ -443,7 +443,7 @@ static int img_i2s_out_probe(struct platform_device *pdev) u32 reg; struct device *dev = &pdev->dev; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; @@ -482,8 +482,8 @@ static int img_i2s_out_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(i2s->clk_ref), "Failed to acquire clock 'ref'\n"); - i2s->suspend_ch_ctl = devm_kcalloc(dev, - i2s->max_i2s_chan, sizeof(*i2s->suspend_ch_ctl), GFP_KERNEL); + i2s->suspend_ch_ctl = devm_kzalloc_objs(dev, *i2s->suspend_ch_ctl, + i2s->max_i2s_chan); if (!i2s->suspend_ch_ctl) return -ENOMEM; diff --git a/sound/soc/img/img-parallel-out.c b/sound/soc/img/img-parallel-out.c index 89270913ab3523..344d900dc0bf43 100644 --- a/sound/soc/img/img-parallel-out.c +++ b/sound/soc/img/img-parallel-out.c @@ -219,7 +219,7 @@ static int img_prl_out_probe(struct platform_device *pdev) int ret; struct device *dev = &pdev->dev; - prl = devm_kzalloc(&pdev->dev, sizeof(*prl), GFP_KERNEL); + prl = devm_kzalloc_obj(&pdev->dev, *prl); if (!prl) return -ENOMEM; diff --git a/sound/soc/img/img-spdif-in.c b/sound/soc/img/img-spdif-in.c index d60eb1da4ecdc2..fb7e9e0f3fdcc9 100644 --- a/sound/soc/img/img-spdif-in.c +++ b/sound/soc/img/img-spdif-in.c @@ -689,7 +689,7 @@ static int img_spdif_in_probe(struct platform_device *pdev) u32 reg; struct device *dev = &pdev->dev; - spdif = devm_kzalloc(&pdev->dev, sizeof(*spdif), GFP_KERNEL); + spdif = devm_kzalloc_obj(&pdev->dev, *spdif); if (!spdif) return -ENOMEM; diff --git a/sound/soc/img/img-spdif-out.c b/sound/soc/img/img-spdif-out.c index d93b3a135d7910..9190aa17e502dc 100644 --- a/sound/soc/img/img-spdif-out.c +++ b/sound/soc/img/img-spdif-out.c @@ -320,7 +320,7 @@ static int img_spdif_out_probe(struct platform_device *pdev) int ret; struct device *dev = &pdev->dev; - spdif = devm_kzalloc(&pdev->dev, sizeof(*spdif), GFP_KERNEL); + spdif = devm_kzalloc_obj(&pdev->dev, *spdif); if (!spdif) return -ENOMEM; diff --git a/sound/soc/img/pistachio-internal-dac.c b/sound/soc/img/pistachio-internal-dac.c index ec4f891295c931..19fe71be482dbb 100644 --- a/sound/soc/img/pistachio-internal-dac.c +++ b/sound/soc/img/pistachio-internal-dac.c @@ -147,7 +147,7 @@ static int pistachio_internal_dac_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; u32 reg; - dac = devm_kzalloc(dev, sizeof(*dac), GFP_KERNEL); + dac = devm_kzalloc_obj(dev, *dac); if (!dac) return -ENOMEM; diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig index 63367364916ae0..8244920e1e26ea 100644 --- a/sound/soc/intel/Kconfig +++ b/sound/soc/intel/Kconfig @@ -72,7 +72,7 @@ if SND_SOC_INTEL_SST_TOPLEVEL || SND_SOC_SOF_INTEL_TOPLEVEL config SND_SOC_ACPI_INTEL_MATCH tristate - select SND_SOC_ACPI if ACPI + select SND_SOC_ACPI select SND_SOC_ACPI_INTEL_SDCA_QUIRKS # this option controls the compilation of ACPI matching tables and # helpers and is not meant to be selected by the user. @@ -87,6 +87,7 @@ config SND_SOC_INTEL_KEEMBAY tristate "Keembay Platforms" depends on ARCH_KEEMBAY || COMPILE_TEST depends on COMMON_CLK + select BITREVERSE select SND_DMAENGINE_PCM select SND_SOC_GENERIC_DMAENGINE_PCM help diff --git a/sound/soc/intel/atom/sst-atom-controls.c b/sound/soc/intel/atom/sst-atom-controls.c index 82df398237da25..bac54c6211266b 100644 --- a/sound/soc/intel/atom/sst-atom-controls.c +++ b/sound/soc/intel/atom/sst-atom-controls.c @@ -1383,7 +1383,7 @@ static int sst_fill_module_list(struct snd_kcontrol *kctl, struct sst_ids *ids = w->priv; int ret = 0; - module = devm_kzalloc(c->dev, sizeof(*module), GFP_KERNEL); + module = devm_kzalloc_obj(c->dev, *module); if (!module) return -ENOMEM; diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c index 58681e007abf97..8c0e4c1d0c0c13 100644 --- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c +++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c @@ -709,12 +709,12 @@ static int sst_platform_probe(struct platform_device *pdev) int ret; struct sst_platform_data *pdata; - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&pdev->dev, *drv); if (drv == NULL) { return -ENOMEM; } - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(&pdev->dev, *pdata); if (pdata == NULL) { return -ENOMEM; } diff --git a/sound/soc/intel/atom/sst/sst.c b/sound/soc/intel/atom/sst/sst.c index d9d695ed7cfbae..c6f9e706be53f9 100644 --- a/sound/soc/intel/atom/sst/sst.c +++ b/sound/soc/intel/atom/sst/sst.c @@ -230,7 +230,7 @@ static void sst_init_locks(struct intel_sst_drv *ctx) int sst_alloc_drv_context(struct intel_sst_drv **ctx, struct device *dev, unsigned short dev_id) { - *ctx = devm_kzalloc(dev, sizeof(struct intel_sst_drv), GFP_KERNEL); + *ctx = devm_kzalloc_obj(dev, struct intel_sst_drv); if (!(*ctx)) return -ENOMEM; @@ -324,8 +324,7 @@ int sst_context_init(struct intel_sst_drv *ctx) /* default intr are unmasked so set this as masked */ sst_shim_write64(ctx->shim, SST_IMRX, 0xFFFF0038); - ctx->qos = devm_kzalloc(ctx->dev, - sizeof(struct pm_qos_request), GFP_KERNEL); + ctx->qos = devm_kzalloc_obj(ctx->dev, struct pm_qos_request); if (!ctx->qos) { ret = -ENOMEM; goto do_free_mem; diff --git a/sound/soc/intel/atom/sst/sst.h b/sound/soc/intel/atom/sst/sst.h index e24d9dad7ef63f..4c759ba377ae18 100644 --- a/sound/soc/intel/atom/sst/sst.h +++ b/sound/soc/intel/atom/sst/sst.h @@ -439,8 +439,6 @@ int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int str_id); int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id); int sst_send_byte_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, struct snd_sst_bytes_v2 *bytes); -int sst_set_stream_param(int str_id, struct snd_sst_params *str_param); -int sst_set_metadata(int str_id, char *params); int sst_get_stream(struct intel_sst_drv *ctx, struct snd_sst_params *str_param); int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx, @@ -453,9 +451,7 @@ int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *sst_drv_ctx); void intel_sst_clear_intr_mrfld(struct intel_sst_drv *sst_drv_ctx); int sst_load_fw(struct intel_sst_drv *sst_drv_ctx); -int sst_load_library(struct snd_sst_lib_download *lib, u8 ops); void sst_post_download_mrfld(struct intel_sst_drv *ctx); -int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx); void sst_memcpy_free_resources(struct intel_sst_drv *sst_drv_ctx); int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx, @@ -463,13 +459,9 @@ int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx, int sst_create_ipc_msg(struct ipc_post **arg, bool large); int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id); void sst_clean_stream(struct stream_info *stream); -int intel_sst_register_compress(struct intel_sst_drv *sst); -int intel_sst_remove_compress(struct intel_sst_drv *sst); -int sst_send_sync_msg(int ipc, int str_id); int sst_get_num_channel(struct snd_sst_params *str_param); int sst_get_sfreq(struct snd_sst_params *str_param); int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params); -void sst_restore_fw_context(void); struct sst_block *sst_create_block(struct intel_sst_drv *ctx, u32 msg_id, u32 drv_id); int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large, @@ -478,9 +470,7 @@ int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large, int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed); int sst_wake_up_block(struct intel_sst_drv *ctx, int result, u32 drv_id, u32 ipc, void *data, u32 size); -int sst_request_firmware_async(struct intel_sst_drv *ctx); int sst_driver_ops(struct intel_sst_drv *sst); -struct sst_platform_info *sst_get_acpi_driver_data(const char *hid); void sst_firmware_load_cb(const struct firmware *fw, void *context); int sst_prepare_and_post_msg(struct intel_sst_drv *sst, int task_id, int ipc_msg, int cmd_id, int pipe_id, diff --git a/sound/soc/intel/avs/avs.h b/sound/soc/intel/avs/avs.h index b4f9d66d55ad71..9bec903acbfd0c 100644 --- a/sound/soc/intel/avs/avs.h +++ b/sound/soc/intel/avs/avs.h @@ -357,8 +357,6 @@ int avs_register_component(struct device *dev, const char *name, int avs_register_all_boards(struct avs_dev *adev); void avs_unregister_all_boards(struct avs_dev *adev); -int avs_parse_sched_cfg(struct avs_dev *adev, const char *buf, size_t len); - /* Filesystems integration */ extern const struct attribute_group *avs_attr_groups[]; diff --git a/sound/soc/intel/avs/board_selection.c b/sound/soc/intel/avs/board_selection.c index dd0e7cd5a7dd7e..556c13eab8a65d 100644 --- a/sound/soc/intel/avs/board_selection.c +++ b/sound/soc/intel/avs/board_selection.c @@ -423,7 +423,7 @@ static struct platform_device *avs_register_board_pdata(struct avs_dev *adev, co { struct avs_mach_pdata *pdata; - pdata = devm_kzalloc(adev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(adev->dev, *pdata); if (!pdata) return ERR_PTR(-ENOMEM); @@ -482,7 +482,7 @@ static int avs_register_i2s_test_board(struct avs_dev *adev, int ssp_port, int t struct platform_device *pdev; unsigned long *tdms; - tdms = devm_kcalloc(adev->dev, ssp_port + 1, sizeof(*tdms), GFP_KERNEL); + tdms = devm_kzalloc_objs(adev->dev, *tdms, ssp_port + 1); mach.tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL, AVS_STRING_FMT("i2s", "-test-tplg.bin", ssp_port, tdm_slot)); diff --git a/sound/soc/intel/avs/boards/Kconfig b/sound/soc/intel/avs/boards/Kconfig index 82f50207bb2ff0..770267bf9c1e40 100644 --- a/sound/soc/intel/avs/boards/Kconfig +++ b/sound/soc/intel/avs/boards/Kconfig @@ -23,7 +23,7 @@ config SND_SOC_INTEL_AVS_MACH_DA7219 If unsure select "N". config SND_SOC_INTEL_AVS_MACH_DMIC - tristate "DMIC generic board" + tristate "generic DMIC board" select SND_SOC_DMIC help This adds support for AVS with Digital Mic array configuration. @@ -41,7 +41,7 @@ config SND_SOC_INTEL_AVS_MACH_ES8336 If unsure select "N". config SND_SOC_INTEL_AVS_MACH_HDAUDIO - tristate "HD-Audio generic board" + tristate "generic HD-Audio board" select SND_SOC_HDA help This adds support for AVS with HDAudio codec configuration. @@ -49,7 +49,7 @@ config SND_SOC_INTEL_AVS_MACH_HDAUDIO If unsure select "N". config SND_SOC_INTEL_AVS_MACH_I2S_TEST - tristate "I2S test board" + tristate "test I2S board" help This adds support for I2S test-board which can be used to verify transfer over I2S interface with SSP loopback scenarios. diff --git a/sound/soc/intel/avs/boards/da7219.c b/sound/soc/intel/avs/boards/da7219.c index b7bdd8a690cf14..970b94084cb534 100644 --- a/sound/soc/intel/avs/boards/da7219.c +++ b/sound/soc/intel/avs/boards/da7219.c @@ -170,15 +170,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -230,8 +230,8 @@ static int avs_da7219_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/dmic.c b/sound/soc/intel/avs/boards/dmic.c index 8d36bc7ddf1664..e09f91fec0cc0e 100644 --- a/sound/soc/intel/avs/boards/dmic.c +++ b/sound/soc/intel/avs/boards/dmic.c @@ -30,12 +30,12 @@ static int avs_create_dai_links(struct device *dev, const char *codec_name, struct snd_soc_dai_link *dl; const int num_dl = 2; - dl = devm_kcalloc(dev, num_dl, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_objs(dev, *dl, num_dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->codecs) return -ENOMEM; @@ -78,7 +78,7 @@ static int avs_dmic_probe(struct platform_device *pdev) mach = dev_get_platdata(dev); pdata = mach->pdata; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/es8336.c b/sound/soc/intel/avs/boards/es8336.c index 36c13db3a27223..e6d5aaaf1f60fc 100644 --- a/sound/soc/intel/avs/boards/es8336.c +++ b/sound/soc/intel/avs/boards/es8336.c @@ -203,15 +203,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -279,8 +279,8 @@ static int avs_es8336_probe(struct platform_device *pdev) return ret; } - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); + card = devm_kzalloc_obj(dev, *card); if (!data || !card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/hdaudio.c b/sound/soc/intel/avs/boards/hdaudio.c index c1d2d0082b14bd..e0347b5fc9abdf 100644 --- a/sound/soc/intel/avs/boards/hdaudio.c +++ b/sound/soc/intel/avs/boards/hdaudio.c @@ -40,8 +40,8 @@ static int avs_create_dai_links(struct device *dev, struct hda_codec *codec, int const char *cname = dev_name(&codec->core.dev); int i; - dl = devm_kcalloc(dev, pcm_count, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_objs(dev, *dl, pcm_count); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; @@ -61,8 +61,8 @@ static int avs_create_dai_links(struct device *dev, struct hda_codec *codec, int dl[i].ignore_pmdown_time = 1; dl[i].ops = &avs_link_ops; - dl[i].codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); - dl[i].cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); + dl[i].codecs = devm_kzalloc_obj(dev, *dl->codecs); + dl[i].cpus = devm_kzalloc_obj(dev, *dl->cpus); if (!dl[i].codecs || !dl[i].cpus) return -ENOMEM; @@ -203,8 +203,8 @@ static int avs_hdaudio_probe(struct platform_device *pdev) if (!binder) return -ENOMEM; - binder->platforms = devm_kzalloc(dev, sizeof(*binder->platforms), GFP_KERNEL); - binder->codecs = devm_kzalloc(dev, sizeof(*binder->codecs), GFP_KERNEL); + binder->platforms = devm_kzalloc_obj(dev, *binder->platforms); + binder->codecs = devm_kzalloc_obj(dev, *binder->codecs); if (!binder->platforms || !binder->codecs) return -ENOMEM; @@ -217,7 +217,7 @@ static int avs_hdaudio_probe(struct platform_device *pdev) binder->codecs->dai_name = "codec-probing-DAI"; binder->num_codecs = 1; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/i2s_test.c b/sound/soc/intel/avs/boards/i2s_test.c index 787d781ba1d987..643a308ff9ec80 100644 --- a/sound/soc/intel/avs/boards/i2s_test.c +++ b/sound/soc/intel/avs/boards/i2s_test.c @@ -20,14 +20,14 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); if (!dl->name || !dl->cpus) return -ENOMEM; @@ -75,7 +75,7 @@ static int avs_i2s_test_probe(struct platform_device *pdev) } tdm_slot = avs_mach_ssp_tdm(mach, ssp_port); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/max98357a.c b/sound/soc/intel/avs/boards/max98357a.c index 389a50923d3bea..00d277e76432ce 100644 --- a/sound/soc/intel/avs/boards/max98357a.c +++ b/sound/soc/intel/avs/boards/max98357a.c @@ -52,15 +52,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -110,7 +110,7 @@ static int avs_max98357a_probe(struct platform_device *pdev) return ret; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/max98373.c b/sound/soc/intel/avs/boards/max98373.c index b8231f71d3d627..260ef1e0977bbb 100644 --- a/sound/soc/intel/avs/boards/max98373.c +++ b/sound/soc/intel/avs/boards/max98373.c @@ -101,15 +101,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_objs(dev, *dl->codecs, 2); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -163,7 +163,7 @@ static int avs_max98373_probe(struct platform_device *pdev) return ret; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/max98927.c b/sound/soc/intel/avs/boards/max98927.c index d657e7da1cc093..9069114cb66dad 100644 --- a/sound/soc/intel/avs/boards/max98927.c +++ b/sound/soc/intel/avs/boards/max98927.c @@ -98,15 +98,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_objs(dev, *dl->codecs, 2); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -160,7 +160,7 @@ static int avs_max98927_probe(struct platform_device *pdev) return ret; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/nau8825.c b/sound/soc/intel/avs/boards/nau8825.c index d7ea08bb27cd9d..9e74bf70211a2f 100644 --- a/sound/soc/intel/avs/boards/nau8825.c +++ b/sound/soc/intel/avs/boards/nau8825.c @@ -177,15 +177,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -263,8 +263,8 @@ static int avs_nau8825_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/pcm3168a.c b/sound/soc/intel/avs/boards/pcm3168a.c index 9d415fd0499a29..894655f3d31333 100644 --- a/sound/soc/intel/avs/boards/pcm3168a.c +++ b/sound/soc/intel/avs/boards/pcm3168a.c @@ -67,8 +67,8 @@ static int avs_create_dai_links(struct device *dev, struct snd_soc_dai_link **li struct snd_soc_dai_link *dl; const int num_dl = 2; - dl = devm_kcalloc(dev, num_dl, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_objs(dev, *dl, num_dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; @@ -106,7 +106,7 @@ static int avs_pcm3168a_probe(struct platform_device *pdev) mach = dev_get_platdata(dev); pdata = mach->pdata; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/avs/boards/probe.c b/sound/soc/intel/avs/boards/probe.c index 4053d14289b954..ffd6ff76f9a542 100644 --- a/sound/soc/intel/avs/boards/probe.c +++ b/sound/soc/intel/avs/boards/probe.c @@ -14,12 +14,12 @@ static int avs_create_dai_links(struct device *dev, struct snd_soc_dai_link **li { struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); if (!dl) return -ENOMEM; - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->platforms = devm_kzalloc(dev, sizeof(*dl->platforms), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->platforms = devm_kzalloc_obj(dev, *dl->platforms); if (!dl->cpus || !dl->platforms) return -ENOMEM; @@ -43,7 +43,7 @@ static int avs_probe_mb_probe(struct platform_device *pdev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; @@ -61,9 +61,7 @@ static int avs_probe_mb_probe(struct platform_device *pdev) } static const struct platform_device_id avs_probe_mb_driver_ids[] = { - { - .name = "avs_probe_mb", - }, + { .name = "avs_probe_mb" }, { } }; MODULE_DEVICE_TABLE(platform, avs_probe_mb_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt274.c b/sound/soc/intel/avs/boards/rt274.c index 289f1230851f4c..a28f107a552141 100644 --- a/sound/soc/intel/avs/boards/rt274.c +++ b/sound/soc/intel/avs/boards/rt274.c @@ -153,15 +153,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -228,8 +228,8 @@ static int avs_rt274_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; @@ -258,9 +258,7 @@ static int avs_rt274_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt274_driver_ids[] = { - { - .name = "avs_rt274", - }, + { .name = "avs_rt274" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt274_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt286.c b/sound/soc/intel/avs/boards/rt286.c index 9364d60cfcc7ab..ef1721bab2ca45 100644 --- a/sound/soc/intel/avs/boards/rt286.c +++ b/sound/soc/intel/avs/boards/rt286.c @@ -121,15 +121,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -198,8 +198,8 @@ static int avs_rt286_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; @@ -228,9 +228,7 @@ static int avs_rt286_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt286_driver_ids[] = { - { - .name = "avs_rt286", - }, + { .name = "avs_rt286" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt286_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt298.c b/sound/soc/intel/avs/boards/rt298.c index 5d3b3cdc9564dc..3b5ee7021ee315 100644 --- a/sound/soc/intel/avs/boards/rt298.c +++ b/sound/soc/intel/avs/boards/rt298.c @@ -138,15 +138,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -217,8 +217,8 @@ static int avs_rt298_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; @@ -247,9 +247,7 @@ static int avs_rt298_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt298_driver_ids[] = { - { - .name = "avs_rt298", - }, + { .name = "avs_rt298" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt298_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt5514.c b/sound/soc/intel/avs/boards/rt5514.c index e448bc9fa5ad1b..189f27708fe322 100644 --- a/sound/soc/intel/avs/boards/rt5514.c +++ b/sound/soc/intel/avs/boards/rt5514.c @@ -91,15 +91,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -151,7 +151,7 @@ static int avs_rt5514_probe(struct platform_device *pdev) return ret; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; @@ -175,9 +175,7 @@ static int avs_rt5514_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt5514_driver_ids[] = { - { - .name = "avs_rt5514", - }, + { .name = "avs_rt5514" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt5514_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt5640.c b/sound/soc/intel/avs/boards/rt5640.c index c4e33d71e82fc1..a425a597c9ca7c 100644 --- a/sound/soc/intel/avs/boards/rt5640.c +++ b/sound/soc/intel/avs/boards/rt5640.c @@ -144,15 +144,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, uid--; /* 0-based indexing. */ } - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -218,8 +218,8 @@ static int avs_rt5640_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; @@ -249,9 +249,7 @@ static int avs_rt5640_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt5640_driver_ids[] = { - { - .name = "avs_rt5640", - }, + { .name = "avs_rt5640" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt5640_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt5663.c b/sound/soc/intel/avs/boards/rt5663.c index aadbd3f2a1b267..afa560d942d1cf 100644 --- a/sound/soc/intel/avs/boards/rt5663.c +++ b/sound/soc/intel/avs/boards/rt5663.c @@ -140,15 +140,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -216,8 +216,8 @@ static int avs_rt5663_probe(struct platform_device *pdev) return ret; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); + card = devm_kzalloc_obj(dev, *card); if (!priv || !card) return -ENOMEM; @@ -246,9 +246,7 @@ static int avs_rt5663_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt5663_driver_ids[] = { - { - .name = "avs_rt5663", - }, + { .name = "avs_rt5663" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt5663_driver_ids); diff --git a/sound/soc/intel/avs/boards/rt5682.c b/sound/soc/intel/avs/boards/rt5682.c index d33699cca59533..bd2507855d9643 100644 --- a/sound/soc/intel/avs/boards/rt5682.c +++ b/sound/soc/intel/avs/boards/rt5682.c @@ -210,15 +210,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_obj(dev, *dl->codecs); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -292,8 +292,8 @@ static int avs_rt5682_probe(struct platform_device *pdev) return ret; } - jack = devm_kzalloc(dev, sizeof(*jack), GFP_KERNEL); - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + jack = devm_kzalloc_obj(dev, *jack); + card = devm_kzalloc_obj(dev, *card); if (!jack || !card) return -ENOMEM; @@ -322,9 +322,7 @@ static int avs_rt5682_probe(struct platform_device *pdev) } static const struct platform_device_id avs_rt5682_driver_ids[] = { - { - .name = "avs_rt5682", - }, + { .name = "avs_rt5682" }, { } }; MODULE_DEVICE_TABLE(platform, avs_rt5682_driver_ids); diff --git a/sound/soc/intel/avs/boards/ssm4567.c b/sound/soc/intel/avs/boards/ssm4567.c index d7c9bff375565d..900a965c974651 100644 --- a/sound/soc/intel/avs/boards/ssm4567.c +++ b/sound/soc/intel/avs/boards/ssm4567.c @@ -87,15 +87,15 @@ static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, struct snd_soc_dai_link_component *platform; struct snd_soc_dai_link *dl; - dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + dl = devm_kzalloc_obj(dev, *dl); + platform = devm_kzalloc_obj(dev, *platform); if (!dl || !platform) return -ENOMEM; dl->name = devm_kasprintf(dev, GFP_KERNEL, AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); - dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); - dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL); + dl->cpus = devm_kzalloc_obj(dev, *dl->cpus); + dl->codecs = devm_kzalloc_objs(dev, *dl->codecs, 2); if (!dl->name || !dl->cpus || !dl->codecs) return -ENOMEM; @@ -149,7 +149,7 @@ static int avs_ssm4567_probe(struct platform_device *pdev) return ret; } - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; @@ -177,9 +177,7 @@ static int avs_ssm4567_probe(struct platform_device *pdev) } static const struct platform_device_id avs_ssm4567_driver_ids[] = { - { - .name = "avs_ssm4567", - }, + { .name = "avs_ssm4567" }, { } }; MODULE_DEVICE_TABLE(platform, avs_ssm4567_driver_ids); diff --git a/sound/soc/intel/avs/core.c b/sound/soc/intel/avs/core.c index 611ae9f034d4da..8ff7c616a9d16d 100644 --- a/sound/soc/intel/avs/core.c +++ b/sound/soc/intel/avs/core.c @@ -395,7 +395,7 @@ static int avs_bus_init(struct avs_dev *adev, struct pci_dev *pci, const struct struct device *dev = &pci->dev; int ret; - ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL); + ipc = devm_kzalloc_obj(dev, *ipc); if (!ipc) return -ENOMEM; @@ -456,7 +456,7 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) if (ret < 0) return ret; - adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); + adev = devm_kzalloc_obj(dev, *adev); if (!adev) return -ENOMEM; bus = &adev->base.core; @@ -913,14 +913,14 @@ static const struct avs_spec fcl_desc = { }; static const struct pci_device_id avs_ids[] = { - { PCI_DEVICE_DATA(INTEL, HDA_SKL_LP, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_SKL, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_KBL_LP, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_KBL, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_KBL_H, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_CML_S, &skl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_APL, &apl_desc) }, - { PCI_DEVICE_DATA(INTEL, HDA_GLK, &apl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_SKL_LP, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_SKL, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_KBL_LP, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_KBL, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_KBL_H, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_CML_S, &skl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_APL, &apl_desc) }, + { PCI_DEVICE_DATA(INTEL, HDA_GLK, &apl_desc) }, { PCI_DEVICE_DATA(INTEL, HDA_CNL_LP, &cnl_desc) }, { PCI_DEVICE_DATA(INTEL, HDA_CNL_H, &cnl_desc) }, { PCI_DEVICE_DATA(INTEL, HDA_CML_LP, &cnl_desc) }, diff --git a/sound/soc/intel/avs/ipc.c b/sound/soc/intel/avs/ipc.c index 5010b0f5be4782..0747899c81a7b9 100644 --- a/sound/soc/intel/avs/ipc.c +++ b/sound/soc/intel/avs/ipc.c @@ -393,6 +393,7 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request struct avs_ipc_msg *reply, int timeout, const char *name) { struct avs_ipc *ipc = adev->ipc; + bool copy_reply = true; int ret; guard(mutex)(&ipc->msg_mutex); @@ -413,10 +414,11 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request /* Same treatment as on exception, just stack_dump=0. */ avs_dsp_exception_caught(adev, &msg); } - return ret; + copy_reply = false; + } else { + ret = ipc->rx.rsp.status; } - ret = ipc->rx.rsp.status; /* * If IPC channel is blocked e.g.: due to ongoing recovery, * -EPERM error code is expected and thus it's not an actual error. @@ -430,7 +432,7 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request dev_err(adev->dev, "%s (0x%08x 0x%08x) failed: %d\n", name, request->glb.primary, request->glb.ext.val, ret); - if (reply) { + if (copy_reply && reply) { reply->header = ipc->rx.header; reply->size = ipc->rx.size; if (reply->data && ipc->rx.size) diff --git a/sound/soc/intel/avs/loader.c b/sound/soc/intel/avs/loader.c index bebdc79ec88e67..607e7cb262278e 100644 --- a/sound/soc/intel/avs/loader.c +++ b/sound/soc/intel/avs/loader.c @@ -269,7 +269,7 @@ int avs_cldma_transfer_modules(struct avs_dev *adev, bool load, return 0; } - mod_ids = kcalloc(num_mods, sizeof(u16), GFP_KERNEL); + mod_ids = kzalloc_objs(u16, num_mods); if (!mod_ids) return -ENOMEM; @@ -704,10 +704,10 @@ static int avs_dsp_alloc_resources(struct avs_dev *adev) adev->hw_cfg.i2s_caps.ctrl_count = link->slcount; } - adev->core_refs = devm_kcalloc(adev->dev, adev->hw_cfg.dsp_cores, - sizeof(*adev->core_refs), GFP_KERNEL); - adev->lib_names = devm_kcalloc(adev->dev, adev->fw_cfg.max_libs_count, - sizeof(*adev->lib_names), GFP_KERNEL); + adev->core_refs = devm_kzalloc_objs(adev->dev, *adev->core_refs, + adev->hw_cfg.dsp_cores); + adev->lib_names = devm_kzalloc_objs(adev->dev, *adev->lib_names, + adev->fw_cfg.max_libs_count); if (!adev->core_refs || !adev->lib_names) return -ENOMEM; diff --git a/sound/soc/intel/avs/messages.h b/sound/soc/intel/avs/messages.h index 55c04b0142aecc..f8407b917c00d7 100644 --- a/sound/soc/intel/avs/messages.h +++ b/sound/soc/intel/avs/messages.h @@ -502,8 +502,8 @@ enum avs_hw_cfg_params { }; enum avs_iface_version { - AVS_AVS_VER_1_5 = 0x10005, - AVS_AVS_VER_1_8 = 0x10008, + AVS_IFACE_VER_1_5 = 0x10005, + AVS_IFACE_VER_1_8 = 0x10008, }; enum avs_i2s_version { diff --git a/sound/soc/intel/avs/path.c b/sound/soc/intel/avs/path.c index a8a2b348433808..e9595eefc416d1 100644 --- a/sound/soc/intel/avs/path.c +++ b/sound/soc/intel/avs/path.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "avs.h" #include "control.h" #include "path.h" @@ -178,9 +179,9 @@ int avs_path_set_constraint(struct avs_dev *adev, struct avs_tplg_path_template list_for_each_entry(path_template, &template->path_list, node) i++; - rlist = kcalloc(i, sizeof(*rlist), GFP_KERNEL); - clist = kcalloc(i, sizeof(*clist), GFP_KERNEL); - slist = kcalloc(i, sizeof(*slist), GFP_KERNEL); + rlist = kzalloc_objs(*rlist, i); + clist = kzalloc_objs(*clist, i); + slist = kzalloc_objs(*slist, i); if (!rlist || !clist || !slist) return -ENOMEM; @@ -320,7 +321,9 @@ avs_nhlt_config_or_default(struct avs_dev *adev, struct avs_tplg_module *t) fmt->num_channels, fmt->sampling_freq, fmt->valid_bit_depth, fmt->bit_depth); if (!fmtcfg) { - dev_warn(adev->dev, "Endpoint format configuration not found.\n"); + dev_dbg(adev->dev, "%s endpoint format configuration %d/%d/%d/%d not found\n", + snd_pcm_direction_name(dir), fmt->num_channels, + fmt->valid_bit_depth, fmt->bit_depth, fmt->sampling_freq); return ERR_PTR(-ENOENT); } @@ -1187,18 +1190,11 @@ static struct avs_path *avs_path_create_unlocked(struct avs_dev *adev, u32 dma_i static void avs_condpath_free(struct avs_dev *adev, struct avs_path *path) { - int ret; - list_del(&path->source_node); list_del(&path->sink_node); - ret = avs_path_reset(path); - if (ret < 0) - dev_err(adev->dev, "reset condpath failed: %d\n", ret); - - ret = avs_path_unbind(path); - if (ret < 0) - dev_err(adev->dev, "unbind condpath failed: %d\n", ret); + avs_path_reset(path); + avs_path_unbind(path); avs_path_free_unlocked(path); } @@ -1373,6 +1369,13 @@ static int avs_path_bind_prepare(struct avs_dev *adev, return 0; } +static const char *avs_path_name(struct avs_path *path) +{ + struct snd_soc_dapm_widget *w = path->template->owner->w; + + return w ? w->name : "(condpath)"; +} + int avs_path_bind(struct avs_path *path) { struct avs_path_pipeline *ppl; @@ -1397,7 +1400,8 @@ int avs_path_bind(struct avs_path *path) sink->instance_id, binding->sink_pin, binding->source_pin); if (ret) { - dev_err(adev->dev, "bind path failed: %d\n", ret); + dev_err(adev->dev, "bind path %s failed: %d\n", + avs_path_name(path), ret); return AVS_IPC_RET(ret); } } @@ -1426,7 +1430,8 @@ int avs_path_unbind(struct avs_path *path) sink->instance_id, binding->sink_pin, binding->source_pin); if (ret) { - dev_err(adev->dev, "unbind path failed: %d\n", ret); + dev_err(adev->dev, "unbind path %s failed: %d\n", + avs_path_name(path), ret); return AVS_IPC_RET(ret); } } @@ -1448,7 +1453,7 @@ int avs_path_reset(struct avs_path *path) ret = avs_ipc_set_pipeline_state(adev, ppl->instance_id, AVS_PPL_STATE_RESET); if (ret) { - dev_err(adev->dev, "reset path failed: %d\n", ret); + dev_err(adev->dev, "reset path %s failed: %d\n", avs_path_name(path), ret); path->state = AVS_PPL_STATE_INVALID; return AVS_IPC_RET(ret); } @@ -1507,7 +1512,7 @@ int avs_path_pause(struct avs_path *path) ret = avs_ipc_set_pipeline_state(adev, ppl->instance_id, AVS_PPL_STATE_PAUSED); if (ret) { - dev_err(adev->dev, "pause path failed: %d\n", ret); + dev_err(adev->dev, "pause path %s failed: %d\n", avs_path_name(path), ret); path->state = AVS_PPL_STATE_INVALID; return AVS_IPC_RET(ret); } @@ -1575,7 +1580,7 @@ int avs_path_run(struct avs_path *path, int trigger) ret = avs_ipc_set_pipeline_state(adev, ppl->instance_id, AVS_PPL_STATE_RUNNING); if (ret) { - dev_err(adev->dev, "run path failed: %d\n", ret); + dev_err(adev->dev, "run path %s failed: %d\n", avs_path_name(path), ret); path->state = AVS_PPL_STATE_INVALID; return AVS_IPC_RET(ret); } diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c index f17bbc2ba63ddd..1e6f276798115e 100644 --- a/sound/soc/intel/avs/pcm.c +++ b/sound/soc/intel/avs/pcm.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include "avs.h" #include "path.h" @@ -166,9 +165,9 @@ static void avs_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc } static int avs_dai_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *fe_hw_params, - struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai, - int dma_id) + struct snd_pcm_hw_params *fe_params, + struct snd_pcm_hw_params *be_params, + struct snd_soc_dai *dai, int dma_id) { struct avs_dma_data *data; struct avs_path *path; @@ -179,16 +178,16 @@ static int avs_dai_hw_params(struct snd_pcm_substream *substream, dev_dbg(dai->dev, "%s FE hw_params str %p rtd %p", __func__, substream, substream->runtime); dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n", - params_rate(fe_hw_params), params_channels(fe_hw_params), - params_width(fe_hw_params), params_physical_width(fe_hw_params)); + params_rate(fe_params), params_channels(fe_params), + params_width(fe_params), params_physical_width(fe_params)); dev_dbg(dai->dev, "%s BE hw_params str %p rtd %p", __func__, substream, substream->runtime); dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n", - params_rate(be_hw_params), params_channels(be_hw_params), - params_width(be_hw_params), params_physical_width(be_hw_params)); + params_rate(be_params), params_channels(be_params), + params_width(be_params), params_physical_width(be_params)); - path = avs_path_create(data->adev, dma_id, data->template, fe_hw_params, be_hw_params); + path = avs_path_create(data->adev, dma_id, data->template, fe_params, be_params); if (IS_ERR(path)) { ret = PTR_ERR(path); dev_err(dai->dev, "create path failed: %d\n", ret); @@ -200,10 +199,10 @@ static int avs_dai_hw_params(struct snd_pcm_substream *substream, } static int avs_dai_be_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai, - int dma_id) + struct snd_pcm_hw_params *be_params, + struct snd_soc_dai *dai, int dma_id) { - struct snd_pcm_hw_params *fe_hw_params = NULL; + struct snd_pcm_hw_params *fe_params = NULL; struct snd_soc_pcm_runtime *fe, *be; struct snd_soc_dpcm *dpcm; @@ -211,10 +210,10 @@ static int avs_dai_be_hw_params(struct snd_pcm_substream *substream, /* dpcm_fe_dai_open() guarantees the list is not empty at this point. */ for_each_dpcm_fe(be, substream->stream, dpcm) { fe = dpcm->fe; - fe_hw_params = &fe->dpcm[substream->stream].hw_params; + fe_params = &fe->dpcm[substream->stream].hw_params; } - return avs_dai_hw_params(substream, fe_hw_params, be_hw_params, dai, dma_id); + return avs_dai_hw_params(substream, fe_params, be_params, dai, dma_id); } static int avs_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) @@ -227,19 +226,14 @@ static int avs_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_d return 0; ret = avs_path_reset(data->path); - if (ret < 0) { - dev_err(dai->dev, "reset path failed: %d\n", ret); + if (ret < 0) return ret; - } - ret = avs_path_pause(data->path); - if (ret < 0) - dev_err(dai->dev, "pause path failed: %d\n", ret); - return ret; + return avs_path_pause(data->path); } static int avs_dai_nonhda_be_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) + struct snd_pcm_hw_params *be_params, struct snd_soc_dai *dai) { struct avs_dma_data *data; @@ -248,7 +242,7 @@ static int avs_dai_nonhda_be_hw_params(struct snd_pcm_substream *substream, return 0; /* Actual port-id comes from topology. */ - return avs_dai_be_hw_params(substream, hw_params, dai, 0); + return avs_dai_be_hw_params(substream, be_params, dai, 0); } static int avs_dai_nonhda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) @@ -271,7 +265,7 @@ static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cm { struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct avs_dma_data *data; - int ret = 0; + int ret2, ret = 0; data = snd_soc_dai_get_dma_data(dai, substream); @@ -283,14 +277,10 @@ static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cm case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: ret = avs_path_pause(data->path); - if (ret < 0) { - dev_err(dai->dev, "pause BE path failed: %d\n", ret); + if (ret < 0) break; - } ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); - if (ret < 0) - dev_err(dai->dev, "run BE path failed: %d\n", ret); break; case SNDRV_PCM_TRIGGER_SUSPEND: @@ -300,12 +290,10 @@ static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cm case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: ret = avs_path_pause(data->path); - if (ret < 0) - dev_err(dai->dev, "pause BE path failed: %d\n", ret); - ret = avs_path_reset(data->path); - if (ret < 0) - dev_err(dai->dev, "reset BE path failed: %d\n", ret); + ret2 = avs_path_reset(data->path); + if (ret2 && !ret) + ret = ret2; break; default: @@ -412,7 +400,7 @@ static void avs_dai_althda_be_shutdown(struct snd_pcm_substream *substream, stru } static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) + struct snd_pcm_hw_params *be_params, struct snd_soc_dai *dai) { struct avs_dma_data *data; @@ -420,7 +408,7 @@ static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream, if (data->path) return 0; - return avs_dai_be_hw_params(substream, hw_params, dai, + return avs_dai_be_hw_params(substream, be_params, dai, hdac_stream(data->link_stream)->stream_tag - 1); } @@ -492,7 +480,7 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd, { struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct avs_dma_data *data; - int ret = 0; + int ret2, ret = 0; dev_dbg(dai->dev, "entry %s cmd=%d\n", __func__, cmd); @@ -508,14 +496,10 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd, snd_hdac_ext_stream_start(data->link_stream); ret = avs_path_pause(data->path); - if (ret < 0) { - dev_err(dai->dev, "pause BE path failed: %d\n", ret); + if (ret < 0) break; - } ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); - if (ret < 0) - dev_err(dai->dev, "run BE path failed: %d\n", ret); break; case SNDRV_PCM_TRIGGER_SUSPEND: @@ -525,14 +509,12 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: ret = avs_path_pause(data->path); - if (ret < 0) - dev_err(dai->dev, "pause BE path failed: %d\n", ret); snd_hdac_ext_stream_clear(data->link_stream); - ret = avs_path_reset(data->path); - if (ret < 0) - dev_err(dai->dev, "reset BE path failed: %d\n", ret); + ret2 = avs_path_reset(data->path); + if (ret2 && !ret) + ret = ret2; break; default: @@ -660,9 +642,9 @@ static void avs_dai_fe_shutdown(struct snd_pcm_substream *substream, struct snd_ } static int avs_dai_fe_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) + struct snd_pcm_hw_params *fe_params, struct snd_soc_dai *dai) { - struct snd_pcm_hw_params *be_hw_params = NULL; + struct snd_pcm_hw_params *be_params = NULL; struct snd_soc_pcm_runtime *fe, *be; struct snd_soc_dpcm *dpcm; struct avs_dma_data *data; @@ -683,19 +665,17 @@ static int avs_dai_fe_hw_params(struct snd_pcm_substream *substream, /* dpcm_fe_dai_open() guarantees the list is not empty at this point. */ for_each_dpcm_be(fe, substream->stream, dpcm) { be = dpcm->be; - be_hw_params = &be->dpcm[substream->stream].hw_params; + be_params = &be->dpcm[substream->stream].hw_params; } - ret = avs_dai_hw_params(substream, hw_params, be_hw_params, dai, + ret = avs_dai_hw_params(substream, fe_params, be_params, dai, hdac_stream(host_stream)->stream_tag - 1); if (ret) goto create_err; ret = avs_path_bind(data->path); - if (ret < 0) { - dev_err(dai->dev, "bind FE <-> BE failed: %d\n", ret); + if (ret < 0) goto bind_err; - } return 0; @@ -723,11 +703,9 @@ static int __avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_ host_stream = data->host_stream; ret = avs_path_unbind(data->path); - if (ret < 0) - dev_err(dai->dev, "unbind FE <-> BE failed: %d\n", ret); - avs_path_free(data->path); data->path = NULL; + snd_hdac_stream_cleanup(hdac_stream(host_stream)); hdac_stream(host_stream)->prepared = false; @@ -868,7 +846,7 @@ static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, stru struct hdac_ext_stream *host_stream; struct hdac_bus *bus; unsigned long flags; - int ret = 0; + int ret2, ret = 0; data = snd_soc_dai_get_dma_data(dai, substream); host_stream = data->host_stream; @@ -890,15 +868,10 @@ static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, stru snd_hdac_stream_wait_drsm(hdac_stream(host_stream)); ret = avs_path_pause(data->path); - if (ret < 0) { - dev_err(dai->dev, "pause FE path failed: %d\n", ret); + if (ret < 0) break; - } ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); - if (ret < 0) - dev_err(dai->dev, "run FE path failed: %d\n", ret); - break; case SNDRV_PCM_TRIGGER_SUSPEND: @@ -908,16 +881,14 @@ static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, stru case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: ret = avs_path_pause(data->path); - if (ret < 0) - dev_err(dai->dev, "pause FE path failed: %d\n", ret); spin_lock_irqsave(&bus->reg_lock, flags); avs_hda_stream_stop(bus, host_stream); spin_unlock_irqrestore(&bus->reg_lock, flags); - ret = avs_path_reset(data->path); - if (ret < 0) - dev_err(dai->dev, "reset FE path failed: %d\n", ret); + ret2 = avs_path_reset(data->path); + if (ret2 && !ret) + ret = ret2; break; default: @@ -1397,7 +1368,7 @@ int avs_register_component(struct device *dev, const char *name, struct avs_soc_component *acomp; const char *comp_name; - acomp = devm_kzalloc(dev, sizeof(*acomp), GFP_KERNEL); + acomp = devm_kzalloc_obj(dev, *acomp); if (!acomp) return -ENOMEM; @@ -1507,7 +1478,7 @@ int avs_register_i2s_component(struct avs_dev *adev, const char *name, unsigned for_each_set_bit(i, &port_mask, ssp_count) cpu_count += hweight_long(tdms[i]); - cpus = devm_kcalloc(adev->dev, cpu_count, sizeof(*cpus), GFP_KERNEL); + cpus = devm_kzalloc_objs(adev->dev, *cpus, cpu_count); if (!cpus) return -ENOMEM; @@ -1627,8 +1598,7 @@ static int avs_component_hda_probe(struct snd_soc_component *component) if (!pcm_count) return -EINVAL; - dais = devm_kcalloc(component->dev, pcm_count, sizeof(*dais), - GFP_KERNEL); + dais = devm_kzalloc_objs(component->dev, *dais, pcm_count); if (!dais) return -ENOMEM; diff --git a/sound/soc/intel/avs/registers.h b/sound/soc/intel/avs/registers.h index 97767882ffa15b..c80207652fabe5 100644 --- a/sound/soc/intel/avs/registers.h +++ b/sound/soc/intel/avs/registers.h @@ -50,9 +50,9 @@ #define SKL_ADSP_REG_HIPCIE (SKL_ADSP_IPC_BASE + 0x0C) #define SKL_ADSP_REG_HIPCCTL (SKL_ADSP_IPC_BASE + 0x10) +#define SKL_ADSP_HIPCT_BUSY BIT(31) #define SKL_ADSP_HIPCI_BUSY BIT(31) #define SKL_ADSP_HIPCIE_DONE BIT(30) -#define SKL_ADSP_HIPCT_BUSY BIT(31) /* CNL Intel HD Audio Inter-Processor Communication Registers */ #define CNL_ADSP_IPC_BASE 0xC0 diff --git a/sound/soc/intel/avs/topology.c b/sound/soc/intel/avs/topology.c index e81401bb6dbd08..273b104c19b7cb 100644 --- a/sound/soc/intel/avs/topology.c +++ b/sound/soc/intel/avs/topology.c @@ -268,8 +268,11 @@ static int avs_parse_word_tokens(struct snd_soc_component *comp, void *object, continue; ret = parsers[j].parse(comp, tuple, object, parsers[j].offset); - if (ret) + if (ret) { + dev_err(comp->dev, "parsing token %d failed: %d\n", + parsers[j].token, ret); return ret; + } } } @@ -353,8 +356,8 @@ AVS_DEFINE_PTR_PARSER(binding, struct avs_tplg_binding, bindings); AVS_DEFINE_PTR_PARSER(init_config, struct avs_tplg_init_config, init_configs); AVS_DEFINE_PTR_PARSER(nhlt_config, struct avs_tplg_nhlt_config, nhlt_configs); -static int -parse_audio_format_bitfield(struct snd_soc_component *comp, void *elem, void *object, u32 offset) +static int avs_parse_audio_format_bitfield(struct snd_soc_component *comp, + void *elem, void *object, u32 offset) { struct snd_soc_tplg_vendor_value_elem *velem = elem; struct avs_audio_format *audio_format = object; @@ -396,8 +399,8 @@ static int avs_ssp_sprint(char *buf, size_t size, const char *fmt, int port, int return snprintf(buf, size, "%s", fmt); } -static int parse_link_formatted_string(struct snd_soc_component *comp, void *elem, - void *object, u32 offset) +static int avs_parse_link_formatted_string(struct snd_soc_component *comp, + void *elem, void *object, u32 offset) { struct snd_soc_tplg_vendor_string_elem *tuple = elem; struct snd_soc_acpi_mach *mach = dev_get_platdata(comp->card->dev); @@ -430,7 +433,7 @@ static int avs_parse_nhlt_config_size(struct snd_soc_component *comp, void *elem u32 size; size = le32_to_cpu(tuple->value); - *blob = devm_kzalloc(comp->card->dev, struct_size(*blob, capabilities, size), GFP_KERNEL); + *blob = devm_kzalloc_flex(comp->card->dev, **blob, capabilities, size); if (!*blob) return -ENOMEM; @@ -575,19 +578,19 @@ static const struct avs_tplg_token_parser audio_format_parsers[] = { .token = AVS_TKN_AFMT_NUM_CHANNELS_U32, .type = SND_SOC_TPLG_TUPLE_TYPE_WORD, .offset = AVS_TKN_AFMT_NUM_CHANNELS_U32, - .parse = parse_audio_format_bitfield, + .parse = avs_parse_audio_format_bitfield, }, { .token = AVS_TKN_AFMT_VALID_BIT_DEPTH_U32, .type = SND_SOC_TPLG_TUPLE_TYPE_WORD, .offset = AVS_TKN_AFMT_VALID_BIT_DEPTH_U32, - .parse = parse_audio_format_bitfield, + .parse = avs_parse_audio_format_bitfield, }, { .token = AVS_TKN_AFMT_SAMPLE_TYPE_U32, .type = SND_SOC_TPLG_TUPLE_TYPE_WORD, .offset = AVS_TKN_AFMT_SAMPLE_TYPE_U32, - .parse = parse_audio_format_bitfield, + .parse = avs_parse_audio_format_bitfield, }, }; @@ -984,7 +987,7 @@ static int avs_tplg_parse_modcfg_ext(struct snd_soc_component *comp, if (!num_pins) return -EINVAL; - pins = devm_kcalloc(comp->card->dev, num_pins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(comp->card->dev, *pins, num_pins); if (!pins) return -ENOMEM; @@ -1093,7 +1096,7 @@ static const struct avs_tplg_token_parser binding_parsers[] = { .token = AVS_TKN_BINDING_TARGET_TPLG_NAME_STRING, .type = SND_SOC_TPLG_TUPLE_TYPE_STRING, .offset = offsetof(struct avs_tplg_binding, target_tplg_name), - .parse = parse_link_formatted_string, + .parse = avs_parse_link_formatted_string, }, { .token = AVS_TKN_BINDING_TARGET_PATH_TMPL_ID_U32, @@ -1229,7 +1232,8 @@ static int avs_tplg_module_init_configs(struct snd_soc_component *comp, if (!module->num_init_configs) return -EINVAL; - cfgs = devm_kcalloc(comp->card->dev, module->num_init_configs, sizeof(*cfgs), GFP_KERNEL); + cfgs = devm_kzalloc_objs(comp->card->dev, *cfgs, + module->num_init_configs); if (!cfgs) return -ENOMEM; @@ -1255,7 +1259,7 @@ avs_tplg_module_create(struct snd_soc_component *comp, struct avs_tplg_pipeline if (ret) return ERR_PTR(ret); - module = devm_kzalloc(comp->card->dev, sizeof(*module), GFP_KERNEL); + module = devm_kzalloc_obj(comp->card->dev, *module); if (!module) return ERR_PTR(-ENOMEM); @@ -1318,7 +1322,7 @@ avs_tplg_pipeline_create(struct snd_soc_component *comp, struct avs_tplg_path *o u32 modblk_size, offset; int ret; - pipeline = devm_kzalloc(comp->card->dev, sizeof(*pipeline), GFP_KERNEL); + pipeline = devm_kzalloc_obj(comp->card->dev, *pipeline); if (!pipeline) return ERR_PTR(-ENOMEM); @@ -1355,8 +1359,9 @@ avs_tplg_pipeline_create(struct snd_soc_component *comp, struct avs_tplg_path *o modblk_size = block_size; } else { - pipeline->bindings = devm_kcalloc(comp->card->dev, pipeline->num_bindings, - sizeof(*pipeline->bindings), GFP_KERNEL); + pipeline->bindings = devm_kzalloc_objs(comp->card->dev, + *pipeline->bindings, + pipeline->num_bindings); if (!pipeline->bindings) return ERR_PTR(-ENOMEM); @@ -1448,7 +1453,7 @@ avs_tplg_path_create(struct snd_soc_component *comp, struct avs_tplg_path_templa u32 offset; int ret; - path = devm_kzalloc(comp->card->dev, sizeof(*path), GFP_KERNEL); + path = devm_kzalloc_obj(comp->card->dev, *path); if (!path) return ERR_PTR(-ENOMEM); @@ -1591,7 +1596,7 @@ avs_tplg_path_template_create(struct snd_soc_component *comp, struct avs_tplg *o struct avs_tplg_path_template *template; int ret; - template = devm_kzalloc(comp->card->dev, sizeof(*template), GFP_KERNEL); + template = devm_kzalloc_obj(comp->card->dev, *template); if (!template) return ERR_PTR(-ENOMEM); @@ -1817,7 +1822,7 @@ static int avs_route_load(struct snd_soc_component *comp, int index, int ssp_port, tdm_slot; char *buf; - /* See parse_link_formatted_string() for dynamic naming when(s). */ + /* See avs_parse_link_formatted_string() for dynamic naming when(s). */ if (!avs_mach_singular_ssp(mach)) return 0; ssp_port = avs_mach_ssp_port(mach); @@ -1875,7 +1880,7 @@ static int avs_widget_load(struct snd_soc_component *comp, int index, goto static_name; ssp_port = avs_mach_ssp_port(mach); - /* See parse_link_formatted_string() for dynamic naming when(s). */ + /* See avs_parse_link_formatted_string() for dynamic naming when(s). */ if (avs_mach_singular_tdm(mach, ssp_port)) { /* size is based on possible %d -> SSP:TDM, where SSP and TDM < 16 + '\0' */ size_t size = strlen(dw->name) + 3; @@ -1961,7 +1966,7 @@ static const struct avs_tplg_token_parser manifest_parsers[] = { .token = AVS_TKN_MANIFEST_NAME_STRING, .type = SND_SOC_TPLG_TUPLE_TYPE_STRING, .offset = offsetof(struct avs_tplg, name), - .parse = parse_link_formatted_string, + .parse = avs_parse_link_formatted_string, }, { .token = AVS_TKN_MANIFEST_VERSION_U32, @@ -2187,7 +2192,7 @@ avs_control_load(struct snd_soc_component *comp, int index, struct snd_kcontrol_ tuples = tmc->priv.array; block_size = le32_to_cpu(tmc->priv.size); - ctl_data = devm_kzalloc(comp->card->dev, sizeof(*ctl_data), GFP_KERNEL); + ctl_data = devm_kzalloc_obj(comp->card->dev, *ctl_data); if (!ctl_data) return -ENOMEM; @@ -2223,7 +2228,7 @@ struct avs_tplg *avs_tplg_new(struct snd_soc_component *comp) { struct avs_tplg *tplg; - tplg = devm_kzalloc(comp->card->dev, sizeof(*tplg), GFP_KERNEL); + tplg = devm_kzalloc_obj(comp->card->dev, *tplg); if (!tplg) return NULL; diff --git a/sound/soc/intel/boards/bdw-rt5650.c b/sound/soc/intel/boards/bdw-rt5650.c index d25a7188f603f1..1937cff25049f6 100644 --- a/sound/soc/intel/boards/bdw-rt5650.c +++ b/sound/soc/intel/boards/bdw-rt5650.c @@ -291,8 +291,7 @@ static int bdw_rt5650_probe(struct platform_device *pdev) bdw_rt5650_card.dev = &pdev->dev; /* Allocate driver private struct */ - bdw_rt5650 = devm_kzalloc(&pdev->dev, sizeof(struct bdw_rt5650_priv), - GFP_KERNEL); + bdw_rt5650 = devm_kzalloc_obj(&pdev->dev, struct bdw_rt5650_priv); if (!bdw_rt5650) return -ENOMEM; diff --git a/sound/soc/intel/boards/bdw-rt5677.c b/sound/soc/intel/boards/bdw-rt5677.c index 408d20ed8cee89..7bffc579edb2f6 100644 --- a/sound/soc/intel/boards/bdw-rt5677.c +++ b/sound/soc/intel/boards/bdw-rt5677.c @@ -417,8 +417,7 @@ static int bdw_rt5677_probe(struct platform_device *pdev) bdw_rt5677_card.dev = &pdev->dev; /* Allocate driver private struct */ - bdw_rt5677 = devm_kzalloc(&pdev->dev, sizeof(struct bdw_rt5677_priv), - GFP_KERNEL); + bdw_rt5677 = devm_kzalloc_obj(&pdev->dev, struct bdw_rt5677_priv); if (!bdw_rt5677) return -ENOMEM; @@ -447,7 +446,7 @@ static struct platform_driver bdw_rt5677_audio = { .probe = bdw_rt5677_probe, .driver = { .name = "bdw-rt5677", - .pm = &snd_soc_pm_ops + .pm = &snd_soc_pm_ops, }, }; diff --git a/sound/soc/intel/boards/bdw_rt286.c b/sound/soc/intel/boards/bdw_rt286.c index 523ade9f31ab7f..f890e02bf9cc21 100644 --- a/sound/soc/intel/boards/bdw_rt286.c +++ b/sound/soc/intel/boards/bdw_rt286.c @@ -247,7 +247,7 @@ static struct platform_driver bdw_rt286_driver = { .probe = bdw_rt286_probe, .driver = { .name = "bdw_rt286", - .pm = &snd_soc_pm_ops + .pm = &snd_soc_pm_ops, }, }; diff --git a/sound/soc/intel/boards/bytcht_es8316.c b/sound/soc/intel/boards/bytcht_es8316.c index 4d8d1d176a49f3..dff8c25e5c147e 100644 --- a/sound/soc/intel/boards/bytcht_es8316.c +++ b/sound/soc/intel/boards/bytcht_es8316.c @@ -576,7 +576,7 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) int i; int ret = 0; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c index 6f0e53f784b673..623d98f382ae25 100644 --- a/sound/soc/intel/boards/bytcr_rt5640.c +++ b/sound/soc/intel/boards/bytcr_rt5640.c @@ -1715,7 +1715,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) int i, aif; is_bytcr = false; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c index fbfaf0b351c9f6..a307053fcfaccb 100644 --- a/sound/soc/intel/boards/bytcr_rt5651.c +++ b/sound/soc/intel/boards/bytcr_rt5651.c @@ -931,7 +931,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) int dai_index = 0; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/intel/boards/bytcr_wm5102.c b/sound/soc/intel/boards/bytcr_wm5102.c index 4aa0cf49b03359..9bccaccd6a7b5d 100644 --- a/sound/soc/intel/boards/bytcr_wm5102.c +++ b/sound/soc/intel/boards/bytcr_wm5102.c @@ -531,7 +531,7 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev) bool sof_parent; int i, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c index ad45b79d3e4b88..0a4d3e3c5e90eb 100644 --- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c +++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c @@ -532,7 +532,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) const char *platform_name; bool sof_parent; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; diff --git a/sound/soc/intel/boards/cht_bsw_nau8824.c b/sound/soc/intel/boards/cht_bsw_nau8824.c index 4afb292d4f13a7..bd244557a16041 100644 --- a/sound/soc/intel/boards/cht_bsw_nau8824.c +++ b/sound/soc/intel/boards/cht_bsw_nau8824.c @@ -248,7 +248,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) bool sof_parent; int ret_val; - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&pdev->dev, *drv); if (!drv) return -ENOMEM; snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c index 4f20928a3604a8..0fd879a5bbb0a3 100644 --- a/sound/soc/intel/boards/cht_bsw_rt5645.c +++ b/sound/soc/intel/boards/cht_bsw_rt5645.c @@ -537,7 +537,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) int i; const char *mclk_name; - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&pdev->dev, *drv); if (!drv) return -ENOMEM; diff --git a/sound/soc/intel/boards/cht_bsw_rt5672.c b/sound/soc/intel/boards/cht_bsw_rt5672.c index eddb179eaa210a..9a38e77cf59d45 100644 --- a/sound/soc/intel/boards/cht_bsw_rt5672.c +++ b/sound/soc/intel/boards/cht_bsw_rt5672.c @@ -452,7 +452,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev) int dai_index = 0; int i; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; diff --git a/sound/soc/intel/boards/cht_rt5677.c b/sound/soc/intel/boards/cht_rt5677.c index 0f5e169fe96fa7..48b56304689688 100644 --- a/sound/soc/intel/boards/cht_rt5677.c +++ b/sound/soc/intel/boards/cht_rt5677.c @@ -336,7 +336,7 @@ static int cht_rt5677_headset_init(struct snd_soc_component *component) int jack_type; int ret; - jack = devm_kzalloc(card->dev, sizeof(*jack), GFP_KERNEL); + jack = devm_kzalloc_obj(card->dev, *jack); if (!jack) return -ENOMEM; @@ -531,7 +531,7 @@ static int snd_cht_rt5677_probe(struct platform_device *pdev) int ret; int i; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/intel/boards/ehl_rt5660.c b/sound/soc/intel/boards/ehl_rt5660.c index 7de39bc1e7639d..28b10d0b6f8b7d 100644 --- a/sound/soc/intel/boards/ehl_rt5660.c +++ b/sound/soc/intel/boards/ehl_rt5660.c @@ -75,7 +75,7 @@ static int hdmi_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0); struct sof_hdmi_pcm *pcm; - pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); + pcm = devm_kzalloc_obj(rtd->card->dev, *pcm); if (!pcm) return -ENOMEM; @@ -274,7 +274,7 @@ static int snd_ehl_rt5660_probe(struct platform_device *pdev) card->dev = &pdev->dev; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; INIT_LIST_HEAD(&ctx->hdmi_pcm_list); diff --git a/sound/soc/intel/boards/skl_hda_dsp_generic.c b/sound/soc/intel/boards/skl_hda_dsp_generic.c index 08e5e22de9da43..faa7d1cf7b9726 100644 --- a/sound/soc/intel/boards/skl_hda_dsp_generic.c +++ b/sound/soc/intel/boards/skl_hda_dsp_generic.c @@ -107,7 +107,7 @@ static int skl_hda_audio_probe(struct platform_device *pdev) unsigned long board_quirk = skl_hda_get_board_quirk(&mach->mach_params); int ret; - card = devm_kzalloc(&pdev->dev, sizeof(struct snd_soc_card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, struct snd_soc_card); if (!card) return -ENOMEM; diff --git a/sound/soc/intel/boards/sof_board_helpers.c b/sound/soc/intel/boards/sof_board_helpers.c index f741a1e142bee1..671d85cae8434d 100644 --- a/sound/soc/intel/boards/sof_board_helpers.c +++ b/sound/soc/intel/boards/sof_board_helpers.c @@ -192,8 +192,7 @@ static int set_ssp_codec_link(struct device *dev, struct snd_soc_dai_link *link, return -ENOMEM; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -229,8 +228,7 @@ static int set_dmic_link(struct device *dev, struct snd_soc_dai_link *link, struct snd_soc_dai_link_component *cpus; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -287,8 +285,7 @@ static int set_idisp_hdmi_link(struct device *dev, struct snd_soc_dai_link *link return -ENOMEM; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -301,9 +298,8 @@ static int set_idisp_hdmi_link(struct device *dev, struct snd_soc_dai_link *link /* codecs */ if (idisp_codec) { - codecs = devm_kzalloc(dev, - sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + codecs = devm_kzalloc_obj(dev, + struct snd_soc_dai_link_component); if (!codecs) return -ENOMEM; @@ -346,8 +342,7 @@ static int set_ssp_amp_link(struct device *dev, struct snd_soc_dai_link *link, return -ENOMEM; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -384,8 +379,7 @@ static int set_bt_offload_link(struct device *dev, struct snd_soc_dai_link *link return -ENOMEM; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -423,8 +417,7 @@ static int set_hdmi_in_link(struct device *dev, struct snd_soc_dai_link *link, return -ENOMEM; /* cpus */ - cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + cpus = devm_kzalloc_obj(dev, struct snd_soc_dai_link_component); if (!cpus) return -ENOMEM; @@ -547,8 +540,7 @@ int sof_intel_board_set_dai_link(struct device *dev, struct snd_soc_card *card, num_links = calculate_num_links(ctx); - links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), - GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, num_links); if (!links) return -ENOMEM; @@ -742,7 +734,7 @@ sof_intel_board_get_ctx(struct device *dev, unsigned long board_quirk) dev_dbg(dev, "create ctx, board_quirk 0x%lx\n", board_quirk); - ctx = devm_kzalloc(dev, sizeof(struct sof_card_private), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, struct sof_card_private); if (!ctx) return NULL; diff --git a/sound/soc/intel/boards/sof_es8336.c b/sound/soc/intel/boards/sof_es8336.c index d40f10c6ae54a7..d86e4aa940ecf8 100644 --- a/sound/soc/intel/boards/sof_es8336.c +++ b/sound/soc/intel/boards/sof_es8336.c @@ -255,7 +255,7 @@ static int sof_hdmi_init(struct snd_soc_pcm_runtime *runtime) struct snd_soc_dai *dai = snd_soc_rtd_to_codec(runtime, 0); struct sof_hdmi_pcm *pcm; - pcm = devm_kzalloc(runtime->card->dev, sizeof(*pcm), GFP_KERNEL); + pcm = devm_kzalloc_obj(runtime->card->dev, *pcm); if (!pcm) return -ENOMEM; @@ -453,10 +453,10 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, int id = 0; int i; - links = devm_kcalloc(dev, sof_es8336_card.num_links, - sizeof(struct snd_soc_dai_link), GFP_KERNEL); - cpus = devm_kcalloc(dev, sof_es8336_card.num_links, - sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, + sof_es8336_card.num_links); + cpus = devm_kzalloc_objs(dev, struct snd_soc_dai_link_component, + sof_es8336_card.num_links); if (!links || !cpus) goto devm_err; @@ -522,10 +522,9 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, /* HDMI */ if (hdmi_num > 0) { - idisp_components = devm_kcalloc(dev, - hdmi_num, - sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + idisp_components = devm_kzalloc_objs(dev, + struct snd_soc_dai_link_component, + hdmi_num); if (!idisp_components) goto devm_err; } @@ -622,7 +621,7 @@ static int sof_es8336_probe(struct platform_device *pdev) int hdmi_num = 3; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/intel/boards/sof_pcm512x.c b/sound/soc/intel/boards/sof_pcm512x.c index 359559b6175b2d..13ec19c3707ba9 100644 --- a/sound/soc/intel/boards/sof_pcm512x.c +++ b/sound/soc/intel/boards/sof_pcm512x.c @@ -74,7 +74,7 @@ static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0); struct sof_hdmi_pcm *pcm; - pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); + pcm = devm_kzalloc_obj(rtd->card->dev, *pcm); if (!pcm) return -ENOMEM; @@ -227,10 +227,10 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, struct snd_soc_dai_link *links; int i, id = 0; - links = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links, - sizeof(struct snd_soc_dai_link), GFP_KERNEL); - cpus = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links, - sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, + sof_audio_card_pcm512x.num_links); + cpus = devm_kzalloc_objs(dev, struct snd_soc_dai_link_component, + sof_audio_card_pcm512x.num_links); if (!links || !cpus) goto devm_err; @@ -301,9 +301,9 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, /* HDMI */ if (hdmi_num > 0) { - idisp_components = devm_kcalloc(dev, hdmi_num, - sizeof(struct snd_soc_dai_link_component), - GFP_KERNEL); + idisp_components = devm_kzalloc_objs(dev, + struct snd_soc_dai_link_component, + hdmi_num); if (!idisp_components) goto devm_err; } @@ -359,7 +359,7 @@ static int sof_audio_probe(struct platform_device *pdev) int dmic_be_num, hdmi_num; int ret, ssp_codec; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index 5a4620faa9514f..d67ebbf064451e 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -139,6 +139,16 @@ static const struct dmi_system_id sof_sdw_quirk_table[] = { .driver_data = (void *)(SOF_SDW_TGL_HDMI | RT711_JD2), }, + { + /* Dell Latitude 9420 */ + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A5B") + }, + .driver_data = (void *)(SOF_SDW_TGL_HDMI | + RT711_JD2), + }, { /* Dell XPS 9710 */ .callback = sof_sdw_quirk_cb, @@ -975,19 +985,19 @@ static int create_sdw_dailink(struct snd_soc_card *card, if (!name) return -ENOMEM; - cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL); + cpus = devm_kzalloc_objs(dev, *cpus, num_cpus); if (!cpus) return -ENOMEM; - codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); + codecs = devm_kzalloc_objs(dev, *codecs, num_codecs); if (!codecs) return -ENOMEM; - platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + platform = devm_kzalloc_obj(dev, *platform); if (!platform) return -ENOMEM; - codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL); + codec_maps = devm_kzalloc_objs(dev, *codec_maps, num_codecs); if (!codec_maps) return -ENOMEM; @@ -1301,7 +1311,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) goto err_dai; } - sof_aux = devm_kcalloc(dev, num_aux, sizeof(*sof_aux), GFP_KERNEL); + sof_aux = devm_kzalloc_objs(dev, *sof_aux, num_aux); if (!sof_aux) { ret = -ENOMEM; goto err_dai; @@ -1355,7 +1365,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) sdw_be_num, ssp_num, dmic_num, intel_ctx->hdmi.idisp_codec ? hdmi_num : 0, bt_num); - codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL); + codec_conf = devm_kzalloc_objs(dev, *codec_conf, num_confs); if (!codec_conf) { ret = -ENOMEM; goto err_end; @@ -1367,7 +1377,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) * and functional SOF topologies to support echo reference. */ num_links = sdw_be_num + ssp_num + dmic_num + hdmi_num + bt_num + 1; - dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); + dai_links = devm_kzalloc_objs(dev, *dai_links, num_links); if (!dai_links) { ret = -ENOMEM; goto err_end; @@ -1474,11 +1484,11 @@ static int mc_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Entry\n"); - intel_ctx = devm_kzalloc(&pdev->dev, sizeof(*intel_ctx), GFP_KERNEL); + intel_ctx = devm_kzalloc_obj(&pdev->dev, *intel_ctx); if (!intel_ctx) return -ENOMEM; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/intel/boards/sof_wm8804.c b/sound/soc/intel/boards/sof_wm8804.c index 51922347409f0d..17bcfd7306eb0e 100644 --- a/sound/soc/intel/boards/sof_wm8804.c +++ b/sound/soc/intel/boards/sof_wm8804.c @@ -212,7 +212,7 @@ static int sof_wm8804_probe(struct platform_device *pdev) int ret; int i; - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(&pdev->dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/intel/catpt/device.c b/sound/soc/intel/catpt/device.c index e36eea8b5408bf..a78ae2294052c2 100644 --- a/sound/soc/intel/catpt/device.c +++ b/sound/soc/intel/catpt/device.c @@ -230,7 +230,7 @@ static int catpt_acpi_probe(struct platform_device *pdev) return -ENODEV; } - cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL); + cdev = devm_kzalloc_obj(dev, *cdev); if (!cdev) return -ENOMEM; diff --git a/sound/soc/intel/catpt/dsp.c b/sound/soc/intel/catpt/dsp.c index 960344991b11f6..13886083809c30 100644 --- a/sound/soc/intel/catpt/dsp.c +++ b/sound/soc/intel/catpt/dsp.c @@ -117,7 +117,7 @@ int catpt_dmac_probe(struct catpt_dev *cdev) struct dw_dma_chip *dmac; int ret; - dmac = devm_kzalloc(cdev->dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(cdev->dev, *dmac); if (!dmac) return -ENOMEM; diff --git a/sound/soc/intel/common/soc-acpi-intel-arl-match.c b/sound/soc/intel/common/soc-acpi-intel-arl-match.c index 1d5f6677bfd87c..bddeb1225e5df9 100644 --- a/sound/soc/intel/common/soc-acpi-intel-arl-match.c +++ b/sound/soc/intel/common/soc-acpi-intel-arl-match.c @@ -603,8 +603,9 @@ EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_arl_machines); /* * Senary SN624x on Arrow Lake: one multi-function device on link 0. - * Separate mach entries per part ID (adr_d[] is AND, not OR). Amp endpoint - * is aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from + * Separate mach entries per part ID (adr_d[] is AND, not OR). ADR version + * nibble 0x3 matches the silicon SoundWire version. Amp endpoint is + * aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from * find_acpi_adr_device(). */ static const struct snd_soc_acpi_endpoint sn624x_endpoints[] = { @@ -651,11 +652,13 @@ static const struct snd_soc_acpi_link_adr _sym[] = { \ {} \ } -SN624X_ARL_SINGLE_ADR(sn6242_single_adr, 0x0000000496624201ull); -SN624X_ARL_SINGLE_ADR(sn6244_single_adr, 0x0000000496624401ull); +SN624X_ARL_SINGLE_ADR(sn6242_single_adr, 0x0000300496624201ull); +SN624X_ARL_SINGLE_ADR(sn6244_single_adr, 0x0000300496624401ull); +SN624X_ARL_SINGLE_ADR(sn6245_single_adr, 0x0000300496624501ull); SN624X_ARL_LINK(arl_link_sn6242, sn6242_single_adr); SN624X_ARL_LINK(arl_link_sn6244, sn6244_single_adr); +SN624X_ARL_LINK(arl_link_sn6245, sn6245_single_adr); struct snd_soc_acpi_mach snd_soc_acpi_intel_arl_sdw_machines[] = { { @@ -779,6 +782,13 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_arl_sdw_machines[] = { .sof_tplg_filename = "sof-arl-dummy.tplg", .get_function_tplg_files = sof_sdw_get_tplg_files, }, + { + .link_mask = BIT(0), + .links = arl_link_sn6245, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-arl-dummy.tplg", + .get_function_tplg_files = sof_sdw_get_tplg_files, + }, {}, }; EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_arl_sdw_machines); diff --git a/sound/soc/intel/common/soc-acpi-intel-lnl-match.c b/sound/soc/intel/common/soc-acpi-intel-lnl-match.c index a9fef394f176f0..ef021771e5f559 100644 --- a/sound/soc/intel/common/soc-acpi-intel-lnl-match.c +++ b/sound/soc/intel/common/soc-acpi-intel-lnl-match.c @@ -688,8 +688,9 @@ static const struct snd_soc_acpi_link_adr lnl_sdw_rt712_vb_l2_rt1320_l1[] = { /* * Senary SN624x on Lunar Lake: one multi-function device on link 0. - * Separate mach entries per part ID (adr_d[] is AND, not OR). Amp endpoint - * is aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from + * Separate mach entries per part ID (adr_d[] is AND, not OR). ADR version + * nibble 0x3 matches the silicon SoundWire version. Amp endpoint is + * aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from * find_acpi_adr_device(). */ static const struct snd_soc_acpi_endpoint sn624x_endpoints[] = { @@ -736,11 +737,13 @@ static const struct snd_soc_acpi_link_adr _sym[] = { \ {} \ } -SN624X_LNL_SINGLE_ADR(sn6242_single_adr, 0x0000000496624201ull); -SN624X_LNL_SINGLE_ADR(sn6244_single_adr, 0x0000000496624401ull); +SN624X_LNL_SINGLE_ADR(sn6242_single_adr, 0x0000300496624201ull); +SN624X_LNL_SINGLE_ADR(sn6244_single_adr, 0x0000300496624401ull); +SN624X_LNL_SINGLE_ADR(sn6245_single_adr, 0x0000300496624501ull); SN624X_LNL_LINK(lnl_link_sn6242, sn6242_single_adr); SN624X_LNL_LINK(lnl_link_sn6244, sn6244_single_adr); +SN624X_LNL_LINK(lnl_link_sn6245, sn6245_single_adr); /* this table is used when there is no I2S codec present */ struct snd_soc_acpi_mach snd_soc_acpi_intel_lnl_sdw_machines[] = { @@ -877,6 +880,13 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_lnl_sdw_machines[] = { .sof_tplg_filename = "sof-lnl-dummy.tplg", .get_function_tplg_files = sof_sdw_get_tplg_files, }, + { + .link_mask = BIT(0), + .links = lnl_link_sn6245, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-lnl-dummy.tplg", + .get_function_tplg_files = sof_sdw_get_tplg_files, + }, {}, }; EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_lnl_sdw_machines); diff --git a/sound/soc/intel/common/soc-acpi-intel-mtl-match.c b/sound/soc/intel/common/soc-acpi-intel-mtl-match.c index 704b4e0d205e24..1b4483c7b3c99a 100644 --- a/sound/soc/intel/common/soc-acpi-intel-mtl-match.c +++ b/sound/soc/intel/common/soc-acpi-intel-mtl-match.c @@ -1299,8 +1299,9 @@ static const struct snd_soc_acpi_link_adr mtl_cs35l63_x2_link1_link3_fb[] = { /* * Senary SN624x on Meteor Lake: one multi-function device on link 0. - * Separate mach entries per part ID (adr_d[] is AND, not OR). Amp endpoint - * is aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from + * Separate mach entries per part ID (adr_d[] is AND, not OR). ADR version + * nibble 0x3 matches the silicon SoundWire version. Amp endpoint is + * aggregated like the generic SOC_SDW_DAI_TYPE_AMP shape from * find_acpi_adr_device(). */ static const struct snd_soc_acpi_endpoint sn624x_endpoints[] = { @@ -1347,11 +1348,13 @@ static const struct snd_soc_acpi_link_adr _sym[] = { \ {} \ } -SN624X_MTL_SINGLE_ADR(sn6242_single_adr, 0x0000000496624201ull); -SN624X_MTL_SINGLE_ADR(sn6244_single_adr, 0x0000000496624401ull); +SN624X_MTL_SINGLE_ADR(sn6242_single_adr, 0x0000300496624201ull); +SN624X_MTL_SINGLE_ADR(sn6244_single_adr, 0x0000300496624401ull); +SN624X_MTL_SINGLE_ADR(sn6245_single_adr, 0x0000300496624501ull); SN624X_MTL_LINK(mtl_link_sn6242, sn6242_single_adr); SN624X_MTL_LINK(mtl_link_sn6244, sn6244_single_adr); +SN624X_MTL_LINK(mtl_link_sn6245, sn6245_single_adr); struct snd_soc_acpi_mach snd_soc_acpi_intel_mtl_sdw_machines[] = { /* mockup tests need to be first */ @@ -1574,6 +1577,13 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_mtl_sdw_machines[] = { .sof_tplg_filename = "sof-mtl-dummy.tplg", .get_function_tplg_files = sof_sdw_get_tplg_files, }, + { + .link_mask = BIT(0), + .links = mtl_link_sn6245, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-dummy.tplg", + .get_function_tplg_files = sof_sdw_get_tplg_files, + }, {}, }; EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_mtl_sdw_machines); diff --git a/sound/soc/intel/common/soc-acpi-intel-ptl-match.c b/sound/soc/intel/common/soc-acpi-intel-ptl-match.c index a5896796a5270f..467709def08bc4 100644 --- a/sound/soc/intel/common/soc-acpi-intel-ptl-match.c +++ b/sound/soc/intel/common/soc-acpi-intel-ptl-match.c @@ -495,10 +495,12 @@ static const struct snd_soc_acpi_link_adr _sym[] = { \ SN624X_PTL_SINGLE_ADR(sn6242_single_adr, 0x0003300496624201ull); SN624X_PTL_SINGLE_ADR(sn6244_single_adr, 0x0003300496624401ull); +SN624X_PTL_SINGLE_ADR(sn6245_single_adr, 0x0003300496624501ull); SN624X_PTL_SINGLE_ADR(sn6247_single_adr, 0x0003300496624701ull); SN624X_PTL_LINK(ptl_link_sn6242, sn6242_single_adr); SN624X_PTL_LINK(ptl_link_sn6244, sn6244_single_adr); +SN624X_PTL_LINK(ptl_link_sn6245, sn6245_single_adr); SN624X_PTL_LINK(ptl_link_sn6247, sn6247_single_adr); struct snd_soc_acpi_mach snd_soc_acpi_intel_ptl_sdw_machines[] = { @@ -609,6 +611,13 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_ptl_sdw_machines[] = { .sof_tplg_filename = "sof-ptl-dummy.tplg", .get_function_tplg_files = sof_sdw_get_tplg_files, }, + { + .link_mask = BIT(3), + .links = ptl_link_sn6245, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-ptl-dummy.tplg", + .get_function_tplg_files = sof_sdw_get_tplg_files, + }, { .link_mask = BIT(3), .links = ptl_link_sn6247, diff --git a/sound/soc/intel/common/sof-function-topology-lib.c b/sound/soc/intel/common/sof-function-topology-lib.c index 57e089f8e721dc..aa36b9961977c5 100644 --- a/sound/soc/intel/common/sof-function-topology-lib.c +++ b/sound/soc/intel/common/sof-function-topology-lib.c @@ -8,92 +8,15 @@ #include #include -#include #include #include +#include #include "sof-function-topology-lib.h" -enum tplg_device_id { - TPLG_DEVICE_SDCA_JACK, - TPLG_DEVICE_SDCA_AMP, - TPLG_DEVICE_SDCA_MIC, - TPLG_DEVICE_INTEL_PCH_DMIC, - TPLG_DEVICE_HDMI, - TPLG_DEVICE_SSP_JACK, - TPLG_DEVICE_SSP_AMP, - TPLG_DEVICE_SSP_BT, - TPLG_DEVICE_SSP_HDMI_IN, - TPLG_DEVICE_LOOPBACK_VIRTUAL, - TPLG_DEVICE_MAX -}; - -#define SDCA_DEVICE_MASK (BIT(TPLG_DEVICE_SDCA_JACK) | BIT(TPLG_DEVICE_SDCA_AMP) | \ - BIT(TPLG_DEVICE_SDCA_MIC)) - -#define SOF_INTEL_PLATFORM_NAME_MAX 4 - -static int get_platform_name(struct snd_soc_card *card, - const struct snd_soc_acpi_mach *mach, char *platform) -{ - int ret; - - ret = sscanf(mach->sof_tplg_filename, "sof-%3s-*.tplg", platform); - if (ret != 1) { - dev_err(card->dev, "Invalid platform name of tplg %s\n", - mach->sof_tplg_filename); - return -EINVAL; - } - - return 0; -} - -static bool tplg_files_exist(struct device *dev, const char *tplg_files) -{ - const struct firmware *fw; - int ret; - - ret = firmware_request_nowarn(&fw, tplg_files, dev); - if (!ret) { - release_firmware(fw); - return true; - } +#define SDCA_DEVICE_MASK (BIT(SND_SOC_ACPI_TPLG_DEVICE_SDCA_JACK) | \ + BIT(SND_SOC_ACPI_TPLG_DEVICE_SDCA_AMP) | \ + BIT(SND_SOC_ACPI_TPLG_DEVICE_SDCA_MIC)) - dev_warn(dev, - "Failed to open topology file: %s, you might need to\n", - tplg_files); - dev_warn(dev, - "download it from https://github.com/thesofproject/sof-bin/\n"); - return false; -} - -static char *get_tplg_filename(struct device *dev, const char *prefix, - const char *platform, const char *tplg_dev_name, - int dai_link_id, int tplg_dev) -{ - char *filename = NULL; - - /* - * The tplg file naming rule is sof---id.tplg - * where is required for functions that depend on NHLT blobs (e.g. DMIC/SSP) - * as the nhlt blob is platform dependent. - */ - switch (tplg_dev) { - case TPLG_DEVICE_INTEL_PCH_DMIC: - case TPLG_DEVICE_SSP_JACK: - case TPLG_DEVICE_SSP_AMP: - case TPLG_DEVICE_SSP_BT: - case TPLG_DEVICE_SSP_HDMI_IN: - filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-%s-id%d.tplg", - prefix, platform, tplg_dev_name, dai_link_id); - break; - default: - filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-id%d.tplg", - prefix, tplg_dev_name, dai_link_id); - break; - } - - return filename; -} static int get_dmic_tplg_dev(struct device *dev, int dmic_num, int *tplg_dev, char **tplg_dev_name) @@ -111,7 +34,7 @@ static int get_dmic_tplg_dev(struct device *dev, int dmic_num, dmic_num); return -EINVAL; } - *tplg_dev = TPLG_DEVICE_INTEL_PCH_DMIC; + *tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_PCH_DMIC; return 0; } @@ -131,16 +54,16 @@ static int get_ssp_tplg_dev(struct device *dev, struct snd_soc_dai_link *dai_lin * machine drivers */ if (dai_link->id == 0) { - *tplg_dev = TPLG_DEVICE_SSP_JACK; + *tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SSP_JACK; *tplg_dev_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-jack", ssp_port); } else { - *tplg_dev = TPLG_DEVICE_SSP_AMP; + *tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SSP_AMP; *tplg_dev_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-amp", ssp_port); } } else if (strstr(dai_link->name, "BT")) { - *tplg_dev = TPLG_DEVICE_SSP_BT; + *tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SSP_BT; *tplg_dev_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-bt", ssp_port); } else if (strstr(dai_link->name, "HDMI")) { @@ -149,7 +72,7 @@ static int get_ssp_tplg_dev(struct device *dev, struct snd_soc_dai_link *dai_lin if (hweight16(*hdmi_in_mask) != 2) return -EINVAL; - *tplg_dev = TPLG_DEVICE_SSP_HDMI_IN; + *tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SSP_HDMI_IN; *tplg_dev_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%x-hdmiin", *hdmi_in_mask); } else { @@ -173,7 +96,7 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ */ struct snd_soc_acpi_mach_params mach_params = card_mach->mach_params; struct snd_soc_dai_link *dai_link; - char platform[SOF_INTEL_PLATFORM_NAME_MAX]; + char platform[SND_SOC_ACPI_SOF_PLATFORM_NAME_MAX]; unsigned long tplg_mask = 0; u16 hdmi_in_mask = 0; int tplg_num = 0; @@ -182,7 +105,7 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ int ret; int i; - ret = get_platform_name(card, mach, platform); + ret = snd_soc_acpi_sof_get_platform_name(card->dev, mach, platform); if (ret < 0) return ret; @@ -191,30 +114,30 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ dev_dbg(card->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id); if (strstr(dai_link->name, "SimpleJack")) { - tplg_dev = TPLG_DEVICE_SDCA_JACK; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SDCA_JACK; tplg_dev_name = "sdca-jack"; } else if (strstr(dai_link->name, "SmartAmp")) { - tplg_dev = TPLG_DEVICE_SDCA_AMP; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SDCA_AMP; tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL, "sdca-%damp", dai_link->num_cpus); if (!tplg_dev_name) return -ENOMEM; } else if (strstr(dai_link->name, "SmartMic")) { - tplg_dev = TPLG_DEVICE_SDCA_MIC; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_SDCA_MIC; tplg_dev_name = "sdca-mic"; } else if (strstr(dai_link->name, "dmic")) { if (get_dmic_tplg_dev(card->dev, mach_params.dmic_num, &tplg_dev, &tplg_dev_name) < 0) continue; } else if (strstr(dai_link->name, "iDisp")) { - tplg_dev = TPLG_DEVICE_HDMI; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_HDMI; tplg_dev_name = "hdmi-pcm5"; } else if (strstr(dai_link->name, "SSP")) { if (get_ssp_tplg_dev(card->dev, dai_link, &hdmi_in_mask, &tplg_dev, &tplg_dev_name) < 0) continue; } else if (strstr(dai_link->name, "Loopback_Virtual")) { - tplg_dev = TPLG_DEVICE_LOOPBACK_VIRTUAL; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_LOOPBACK_VIRTUAL; /* * Mark the LOOPBACK_VIRTUAL device but no need to create the * LOOPBACK_VIRTUAL topology. Just to avoid the dai_link is not supported @@ -235,13 +158,14 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ if (tplg_mask & BIT(tplg_dev)) continue; - tplg_file = get_tplg_filename(card->dev, prefix, platform, tplg_dev_name, - dai_link->id, tplg_dev); + tplg_file = snd_soc_acpi_sof_get_tplg_filename(card->dev, prefix, + platform, tplg_dev_name, + dai_link->id, tplg_dev); if (!tplg_file) return -ENOMEM; /* Check presence of sub-topologies */ - if (!tplg_files_exist(card->dev, tplg_file)) { + if (!snd_soc_tplg_files_exist(card->dev, tplg_file)) { devm_kfree(card->dev, tplg_file); if (best_effort) continue; @@ -266,7 +190,7 @@ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ { struct snd_soc_acpi_mach_params mach_params = mach->mach_params; struct snd_soc_dai_link *dai_link; - char platform[SOF_INTEL_PLATFORM_NAME_MAX]; + char platform[SND_SOC_ACPI_SOF_PLATFORM_NAME_MAX]; unsigned long tplg_mask = 0; u16 hdmi_in_mask = 0; int tplg_num = 0; @@ -275,7 +199,7 @@ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ int ret; int i; - ret = get_platform_name(card, mach, platform); + ret = snd_soc_acpi_sof_get_platform_name(card->dev, mach, platform); if (ret < 0) return ret; @@ -292,7 +216,7 @@ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ &tplg_dev, &tplg_dev_name) < 0) continue; } else if (strstr(dai_link->name, "iDisp")) { - tplg_dev = TPLG_DEVICE_HDMI; + tplg_dev = SND_SOC_ACPI_TPLG_DEVICE_HDMI; tplg_dev_name = "hdmi-pcm5"; } else { /* The dai link is not supported by separated tplg yet */ @@ -307,13 +231,14 @@ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ if (tplg_mask & BIT(tplg_dev)) continue; - tplg_file = get_tplg_filename(card->dev, prefix, platform, tplg_dev_name, - dai_link->id, tplg_dev); + tplg_file = snd_soc_acpi_sof_get_tplg_filename(card->dev, prefix, + platform, tplg_dev_name, + dai_link->id, tplg_dev); if (!tplg_file) return -ENOMEM; /* Check presence of sub-topologies */ - if (!tplg_files_exist(card->dev, tplg_file)) { + if (!snd_soc_tplg_files_exist(card->dev, tplg_file)) { devm_kfree(card->dev, tplg_file); if (best_effort) continue; diff --git a/sound/soc/intel/keembay/kmb_platform.c b/sound/soc/intel/keembay/kmb_platform.c index 48f132f0187883..1ca8ef95d41e71 100644 --- a/sound/soc/intel/keembay/kmb_platform.c +++ b/sound/soc/intel/keembay/kmb_platform.c @@ -826,7 +826,7 @@ static int kmb_plat_dai_probe(struct platform_device *pdev) int ret, irq; u32 comp1_reg; - kmb_i2s = devm_kzalloc(dev, sizeof(*kmb_i2s), GFP_KERNEL); + kmb_i2s = devm_kzalloc_obj(dev, *kmb_i2s); if (!kmb_i2s) return -ENOMEM; diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c index 5f2a26e3c933a1..ea996d7cd8e076 100644 --- a/sound/soc/jz4740/jz4740-i2s.c +++ b/sound/soc/jz4740/jz4740-i2s.c @@ -579,7 +579,7 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c index c26326b82c1987..665065b50bb648 100644 --- a/sound/soc/kirkwood/kirkwood-i2s.c +++ b/sound/soc/kirkwood/kirkwood-i2s.c @@ -652,7 +652,7 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int err; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/loongson/loongson1_ac97.c b/sound/soc/loongson/loongson1_ac97.c index 84901900ad43f6..8d8f9e1fdf8658 100644 --- a/sound/soc/loongson/loongson1_ac97.c +++ b/sound/soc/loongson/loongson1_ac97.c @@ -293,7 +293,7 @@ static int ls1x_ac97_probe(struct platform_device *pdev) struct resource *res; int ret; - ac97 = devm_kzalloc(dev, sizeof(struct ls1x_ac97), GFP_KERNEL); + ac97 = devm_kzalloc_obj(dev, struct ls1x_ac97); if (!ac97) return -ENOMEM; ls1x_ac97 = ac97; diff --git a/sound/soc/loongson/loongson_card.c b/sound/soc/loongson/loongson_card.c index 9f390727846298..b06b596047b88f 100644 --- a/sound/soc/loongson/loongson_card.c +++ b/sound/soc/loongson/loongson_card.c @@ -297,7 +297,7 @@ static int loongson_asoc_card_probe(struct platform_device *pdev) struct snd_soc_card *card; int ret; - ls_priv = devm_kzalloc(dev, sizeof(*ls_priv), GFP_KERNEL); + ls_priv = devm_kzalloc_obj(dev, *ls_priv); if (!ls_priv) return -ENOMEM; diff --git a/sound/soc/loongson/loongson_i2s_pci.c b/sound/soc/loongson/loongson_i2s_pci.c index f5b560465706f2..b26584445eb429 100644 --- a/sound/soc/loongson/loongson_i2s_pci.c +++ b/sound/soc/loongson/loongson_i2s_pci.c @@ -33,7 +33,7 @@ static int loongson_i2s_pci_probe(struct pci_dev *pdev, return -ENODEV; } - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/loongson/loongson_i2s_plat.c b/sound/soc/loongson/loongson_i2s_plat.c index 82d95c6644ef08..1b12b325b87cd1 100644 --- a/sound/soc/loongson/loongson_i2s_plat.c +++ b/sound/soc/loongson/loongson_i2s_plat.c @@ -71,7 +71,7 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev) struct clk *i2s_clk; int ret; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/mediatek/an7581/an7581-afe-pcm.c b/sound/soc/mediatek/an7581/an7581-afe-pcm.c index d47edb63045224..1b12655ab42aa9 100644 --- a/sound/soc/mediatek/an7581/an7581-afe-pcm.c +++ b/sound/soc/mediatek/an7581/an7581-afe-pcm.c @@ -345,7 +345,7 @@ static int an7581_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -377,25 +377,22 @@ static int an7581_afe_pcm_dev_probe(struct platform_device *pdev) int i, irq_id, ret; void __iomem *base; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; afe->irqs_size = AN7581_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; afe->memif_size = AN7581_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; diff --git a/sound/soc/mediatek/an7581/an7581-dai-etdm.c b/sound/soc/mediatek/an7581/an7581-dai-etdm.c index 7fbfd8fe18362b..bd6b37635ff059 100644 --- a/sound/soc/mediatek/an7581/an7581-dai-etdm.c +++ b/sound/soc/mediatek/an7581/an7581-dai-etdm.c @@ -317,8 +317,7 @@ static int mtk_dai_etdm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) struct mtk_dai_etdm_priv *etdm_data; void *priv_data; - priv_data = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_etdm_priv), - GFP_KERNEL); + priv_data = devm_kzalloc_obj(afe->dev, struct mtk_dai_etdm_priv); if (!priv_data) return -ENOMEM; @@ -415,7 +414,7 @@ int an7581_dai_etdm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c index ec99bc4a5d5ee0..54d760a0b9e345 100644 --- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c +++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c @@ -332,8 +332,8 @@ int mtk_afe_suspend(struct snd_soc_component *component) if (!afe->reg_back_up) afe->reg_back_up = - devm_kcalloc(dev, afe->reg_back_up_list_num, - sizeof(unsigned int), GFP_KERNEL); + devm_kzalloc_objs(dev, unsigned int, + afe->reg_back_up_list_num); if (afe->reg_back_up) { for (i = 0; i < afe->reg_back_up_list_num; i++) diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c index 477284e12396d8..7dd93d42ccde62 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c @@ -27,10 +27,9 @@ int mtk_afe_combine_sub_dai(struct mtk_base_afe *afe) /* combine sub_dais */ afe->num_dai_drivers = num_dai_drivers; - afe->dai_drivers = devm_kcalloc(afe->dev, - num_dai_drivers, - sizeof(struct snd_soc_dai_driver), - GFP_KERNEL); + afe->dai_drivers = devm_kzalloc_objs(afe->dev, + struct snd_soc_dai_driver, + num_dai_drivers); if (!afe->dai_drivers) return -ENOMEM; diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c index 85cfc602dfd38a..19329dd7c0d75d 100644 --- a/sound/soc/mediatek/common/mtk-btcvsd.c +++ b/sound/soc/mediatek/common/mtk-btcvsd.c @@ -1268,18 +1268,18 @@ static int mtk_btcvsd_snd_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; /* init btcvsd private data */ - btcvsd = devm_kzalloc(dev, sizeof(*btcvsd), GFP_KERNEL); + btcvsd = devm_kzalloc_obj(dev, *btcvsd); if (!btcvsd) return -ENOMEM; platform_set_drvdata(pdev, btcvsd); btcvsd->dev = dev; /* init tx/rx */ - btcvsd->rx = devm_kzalloc(btcvsd->dev, sizeof(*btcvsd->rx), GFP_KERNEL); + btcvsd->rx = devm_kzalloc_obj(btcvsd->dev, *btcvsd->rx); if (!btcvsd->rx) return -ENOMEM; - btcvsd->tx = devm_kzalloc(btcvsd->dev, sizeof(*btcvsd->tx), GFP_KERNEL); + btcvsd->tx = devm_kzalloc_obj(btcvsd->dev, *btcvsd->tx); if (!btcvsd->tx) return -ENOMEM; diff --git a/sound/soc/mediatek/common/mtk-dsp-sof-common.c b/sound/soc/mediatek/common/mtk-dsp-sof-common.c index adefbed5bbe728..9610f5430e7581 100644 --- a/sound/soc/mediatek/common/mtk-dsp-sof-common.c +++ b/sound/soc/mediatek/common/mtk-dsp-sof-common.c @@ -164,9 +164,8 @@ int mtk_sof_card_late_probe(struct snd_soc_card *card) /* 2. overwrite all BE fixups, and backup the existing fixup */ for_each_card_prelinks(card, i, dai_link) { if (dai_link->be_hw_params_fixup) { - mtk_dai_link = devm_kzalloc(card->dev, - sizeof(*mtk_dai_link), - GFP_KERNEL); + mtk_dai_link = devm_kzalloc_obj(card->dev, + *mtk_dai_link); if (!mtk_dai_link) return -ENOMEM; @@ -243,7 +242,7 @@ int mtk_sof_dailink_parse_of(struct device *dev, struct snd_soc_card *card, return -EINVAL; } - parsed_dai_link = devm_kcalloc(dev, num_links, sizeof(*parsed_dai_link), GFP_KERNEL); + parsed_dai_link = devm_kzalloc_objs(dev, *parsed_dai_link, num_links); if (!parsed_dai_link) return -ENOMEM; diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c index a84f4ab4488b77..d0a7dd619feb37 100644 --- a/sound/soc/mediatek/common/mtk-soundcard-driver.c +++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c @@ -209,7 +209,7 @@ static int mtk_soundcard_set_topology_name(struct device *dev, { struct mtk_soundcard_name *saved; - saved = devm_kzalloc(dev, sizeof(*saved), GFP_KERNEL); + saved = devm_kzalloc_obj(dev, *saved); if (!saved) return -ENOMEM; @@ -271,14 +271,14 @@ int mtk_soundcard_common_probe(struct platform_device *pdev) return ret; } - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL); + soc_card_data = devm_kzalloc_obj(&pdev->dev, *soc_card_data); if (!soc_card_data) return -ENOMEM; soc_card_data->card_data = pdata->card_data; - jacks = devm_kcalloc(card->dev, soc_card_data->card_data->num_jacks, - sizeof(*jacks), GFP_KERNEL); + jacks = devm_kzalloc_objs(card->dev, *jacks, + soc_card_data->card_data->num_jacks); if (!jacks) return -ENOMEM; diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c index 3c5a76591ea7dc..5b0677a00fd507 100644 --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c @@ -1599,14 +1599,13 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) struct device *dev; int i, irq_id, ret; - afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(&pdev->dev, *afe); if (!afe) return -ENOMEM; soc = of_device_get_match_data(&pdev->dev); - afe_priv = devm_kzalloc(&pdev->dev, - struct_size(afe_priv, i2s_path, soc->i2s_num), - GFP_KERNEL); + afe_priv = devm_kzalloc_flex(&pdev->dev, *afe_priv, i2s_path, + soc->i2s_num); if (!afe_priv) return -ENOMEM; @@ -1620,11 +1619,6 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) if (irq_id < 0) return irq_id; - ret = devm_request_irq(dev, irq_id, mt2701_asys_isr, - IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); - if (ret) - return ret; - afe->regmap = syscon_node_to_regmap(dev->parent->of_node); if (IS_ERR(afe->regmap)) { dev_err(dev, "could not get regmap from parent\n"); @@ -1635,8 +1629,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) /* memif initialize */ afe->memif_size = MT2701_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -1647,8 +1640,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) /* irq initialize */ afe->irqs_size = MT2701_IRQ_ASYS_END; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -1684,15 +1676,22 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) if (!pm_runtime_enabled(dev)) { ret = mt2701_afe_runtime_resume(dev); if (ret) - goto err_pm_disable; + return ret; } - pm_runtime_get_sync(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + goto err_pm_disable; + + ret = devm_request_irq(dev, irq_id, mt2701_asys_isr, + IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); + if (ret) + goto err_platform; ret = devm_snd_soc_register_component(&pdev->dev, &mtk_afe_pcm_platform, NULL, 0); if (ret) { dev_warn(dev, "err_platform\n"); - goto err_platform; + goto err_free_irq; } ret = devm_snd_soc_register_component(&pdev->dev, @@ -1701,21 +1700,28 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) ARRAY_SIZE(mt2701_afe_pcm_dais)); if (ret) { dev_warn(dev, "err_dai_component\n"); - goto err_platform; + goto err_free_irq; } return 0; +err_free_irq: + devm_free_irq(dev, irq_id, afe); err_platform: pm_runtime_put_sync(dev); err_pm_disable: pm_runtime_disable(dev); + if (!pm_runtime_status_suspended(dev)) + mt2701_afe_runtime_suspend(dev); return ret; } static void mt2701_afe_pcm_dev_remove(struct platform_device *pdev) { + struct mtk_base_afe *afe = platform_get_drvdata(pdev); + + devm_free_irq(&pdev->dev, platform_get_irq_byname(pdev, "asys"), afe); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c b/sound/soc/mediatek/mt2701/mt2701-cs42448.c index af833a8daa2a8e..ff7a1bac848cb5 100644 --- a/sound/soc/mediatek/mt2701/mt2701-cs42448.c +++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c @@ -321,8 +321,7 @@ static int mt2701_cs42448_machine_probe(struct platform_device *pdev) struct device_node *platform_node, *codec_node, *codec_node_bt_mrg; struct device *dev = &pdev->dev; struct mt2701_cs42448_private *priv = - devm_kzalloc(dev, sizeof(struct mt2701_cs42448_private), - GFP_KERNEL); + devm_kzalloc_obj(dev, struct mt2701_cs42448_private); struct snd_soc_dai_link *dai_link; if (!priv) diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-clk.c b/sound/soc/mediatek/mt6797/mt6797-afe-clk.c index 2326496f8b2736..bd128df16e0217 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-clk.c +++ b/sound/soc/mediatek/mt6797/mt6797-afe-clk.c @@ -36,8 +36,7 @@ int mt6797_init_clock(struct mtk_base_afe *afe) struct mt6797_afe_private *afe_priv = afe->platform_priv; int i; - afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c index dfe67727fe473a..2069c340ca39a0 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c +++ b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c @@ -708,7 +708,7 @@ static int mt6797_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -739,12 +739,11 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) struct device *dev; int i, irq_id, ret; - afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(&pdev->dev, *afe); if (!afe) return -ENOMEM; - afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(&pdev->dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -769,8 +768,7 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT6797_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -783,8 +781,7 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) /* irq initialize */ afe->irqs_size = MT6797_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; diff --git a/sound/soc/mediatek/mt6797/mt6797-dai-adda.c b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c index 78f3ad758c120c..cc64ee8eda2d15 100644 --- a/sound/soc/mediatek/mt6797/mt6797-dai-adda.c +++ b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c @@ -306,7 +306,7 @@ int mt6797_dai_adda_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt6797/mt6797-dai-hostless.c b/sound/soc/mediatek/mt6797/mt6797-dai-hostless.c index ed23e6a53b086f..d7f4c19244089f 100644 --- a/sound/soc/mediatek/mt6797/mt6797-dai-hostless.c +++ b/sound/soc/mediatek/mt6797/mt6797-dai-hostless.c @@ -102,7 +102,7 @@ int mt6797_dai_hostless_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt6797/mt6797-dai-pcm.c b/sound/soc/mediatek/mt6797/mt6797-dai-pcm.c index 8a309b0734f75e..3539f8a1bf959e 100644 --- a/sound/soc/mediatek/mt6797/mt6797-dai-pcm.c +++ b/sound/soc/mediatek/mt6797/mt6797-dai-pcm.c @@ -302,7 +302,7 @@ int mt6797_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c b/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c index e7ecb2761b4dd8..062ec7fb04e26a 100644 --- a/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c +++ b/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c @@ -323,8 +323,7 @@ static int mt7986_init_clock(struct mtk_base_afe *afe) struct mt7986_afe_private *afe_priv = afe->platform_priv; int ret, i; - afe_priv->clks = devm_kcalloc(afe->dev, CLK_NUM, - sizeof(*afe_priv->clks), GFP_KERNEL); + afe_priv->clks = devm_kzalloc_objs(afe->dev, *afe_priv->clks, CLK_NUM); if (!afe_priv->clks) return -ENOMEM; afe_priv->num_clks = CLK_NUM; @@ -433,7 +432,7 @@ static int mt7986_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -463,13 +462,12 @@ static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev) struct device *dev; int i, irq_id, ret; - afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(&pdev->dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(&pdev->dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -505,8 +503,7 @@ static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT7986_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -519,8 +516,7 @@ static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev) /* irq initialize */ afe->irqs_size = MT7986_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; diff --git a/sound/soc/mediatek/mt7986/mt7986-dai-etdm.c b/sound/soc/mediatek/mt7986/mt7986-dai-etdm.c index 49f5b2bf565f0d..39606682839d30 100644 --- a/sound/soc/mediatek/mt7986/mt7986-dai-etdm.c +++ b/sound/soc/mediatek/mt7986/mt7986-dai-etdm.c @@ -304,8 +304,7 @@ static int mtk_dai_etdm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return -EINVAL; } - priv_data = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_etdm_priv), - GFP_KERNEL); + priv_data = devm_kzalloc_obj(afe->dev, struct mtk_dai_etdm_priv); if (!priv_data) return -ENOMEM; @@ -408,7 +407,7 @@ int mt7986_dai_etdm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c index c95699f841910e..8694e823a88879 100644 --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c @@ -1059,11 +1059,11 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); afe_priv = afe->platform_priv; if (!afe_priv) return -ENOMEM; @@ -1096,14 +1096,12 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev) /* memif % irq initialize*/ afe->memif_size = MT8173_AFE_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, - sizeof(*afe->memif), GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; afe->irqs_size = MT8173_AFE_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, - sizeof(*afe->irqs), GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -1133,8 +1131,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev) afe->runtime_resume = mt8173_afe_runtime_resume; afe->runtime_suspend = mt8173_afe_runtime_suspend; - ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, - NULL, 0); + ret = snd_soc_register_component(dev, &mtk_afe_pcm_platform, NULL, 0); if (ret) goto err_pm_disable; @@ -1142,7 +1139,7 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev) mt8173_afe_pcm_dais, ARRAY_SIZE(mt8173_afe_pcm_dais)); if (ret) - goto err_pm_disable; + goto err_cleanup_components; ret = snd_soc_register_component(dev, &mt8173_afe_hdmi_dai_component, mt8173_afe_hdmi_dais, diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-clk.c b/sound/soc/mediatek/mt8183/mt8183-afe-clk.c index 40f9afcdaa16b8..8b98a277068816 100644 --- a/sound/soc/mediatek/mt8183/mt8183-afe-clk.c +++ b/sound/soc/mediatek/mt8183/mt8183-afe-clk.c @@ -94,8 +94,7 @@ int mt8183_init_clock(struct mtk_base_afe *afe) struct mt8183_afe_private *afe_priv = afe->platform_priv; int i; - afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c index d8938542b82811..978fb4ac475930 100644 --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c @@ -740,7 +740,7 @@ static int mt8183_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -778,12 +778,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -851,8 +851,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT8183_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) { ret = -ENOMEM; goto err_pm_disable; @@ -871,8 +870,7 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ /* irq initialize */ afe->irqs_size = MT8183_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) { ret = -ENOMEM; goto err_pm_disable; diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c index aa3d1a588479bb..fdcfd7cf8759c9 100644 --- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c +++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c @@ -822,7 +822,7 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev) goto put_hdmi_codec; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { ret = -ENOMEM; goto put_hdmi_codec; diff --git a/sound/soc/mediatek/mt8183/mt8183-dai-adda.c b/sound/soc/mediatek/mt8183/mt8183-dai-adda.c index 1f55d9e342ba40..f7ab18f80e1873 100644 --- a/sound/soc/mediatek/mt8183/mt8183-dai-adda.c +++ b/sound/soc/mediatek/mt8183/mt8183-dai-adda.c @@ -407,7 +407,7 @@ int mt8183_dai_adda_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-dai-hostless.c b/sound/soc/mediatek/mt8183/mt8183-dai-hostless.c index 1667ad352d34f1..4d72a43c4f7612 100644 --- a/sound/soc/mediatek/mt8183/mt8183-dai-hostless.c +++ b/sound/soc/mediatek/mt8183/mt8183-dai-hostless.c @@ -102,7 +102,7 @@ int mt8183_dai_hostless_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-dai-i2s.c b/sound/soc/mediatek/mt8183/mt8183-dai-i2s.c index 3709100a886591..2e60921d572bc0 100644 --- a/sound/soc/mediatek/mt8183/mt8183-dai-i2s.c +++ b/sound/soc/mediatek/mt8183/mt8183-dai-i2s.c @@ -1018,9 +1018,7 @@ static int mt8183_dai_i2s_set_priv(struct mtk_base_afe *afe) int i; for (i = 0; i < DAI_I2S_NUM; i++) { - i2s_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_afe_i2s_priv), - GFP_KERNEL); + i2s_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_i2s_priv); if (!i2s_priv) return -ENOMEM; @@ -1037,7 +1035,7 @@ int mt8183_dai_i2s_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-dai-pcm.c b/sound/soc/mediatek/mt8183/mt8183-dai-pcm.c index 4e25287fc0e4d2..5049411e8f794a 100644 --- a/sound/soc/mediatek/mt8183/mt8183-dai-pcm.c +++ b/sound/soc/mediatek/mt8183/mt8183-dai-pcm.c @@ -301,7 +301,7 @@ int mt8183_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-dai-tdm.c b/sound/soc/mediatek/mt8183/mt8183-dai-tdm.c index 0d69cf4404073e..594ca12c4f5a55 100644 --- a/sound/soc/mediatek/mt8183/mt8183-dai-tdm.c +++ b/sound/soc/mediatek/mt8183/mt8183-dai-tdm.c @@ -720,7 +720,7 @@ int mt8183_dai_tdm_register(struct mtk_base_afe *afe) struct mtk_afe_tdm_priv *tdm_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -734,8 +734,7 @@ int mt8183_dai_tdm_register(struct mtk_base_afe *afe) dai->dapm_routes = mtk_dai_tdm_routes; dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_tdm_routes); - tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), - GFP_KERNEL); + tdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_tdm_priv); if (!tdm_priv) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c index dea7ad167a4978..e46f832cd60c16 100644 --- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c +++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c @@ -803,7 +803,7 @@ mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev) card->num_aux_devs = 1; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) { ret = -ENOMEM; goto out; diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c index 62b008b7caca25..c4c0b5543c8dbb 100644 --- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c +++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c @@ -577,8 +577,7 @@ int mt8186_init_clock(struct mtk_base_afe *afe) mt8186_audsys_clk_register(afe); - afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-common.h b/sound/soc/mediatek/mt8186/mt8186-afe-common.h index d592585209955a..d03e59ca7d65a2 100644 --- a/sound/soc/mediatek/mt8186/mt8186-afe-common.h +++ b/sound/soc/mediatek/mt8186/mt8186-afe-common.h @@ -139,6 +139,7 @@ struct mtk_base_irq_data; struct clk; struct mt8186_afe_private { + int irq_id; struct clk **clk; struct clk_lookup **lookup; struct regmap *topckgen; diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c index 2f50f78a6f8cf7..d435392e963112 100644 --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c @@ -2786,7 +2786,7 @@ static int mt8186_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -2828,12 +2828,12 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -2858,7 +2858,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_32bit_supported = 0; afe->memif_size = MT8186_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -2872,8 +2872,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) /* init irq */ afe->irqs_size = MT8186_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -2885,16 +2884,7 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) irq_id = platform_get_irq(pdev, 0); if (irq_id < 0) return irq_id; - - ret = devm_request_irq(dev, irq_id, mt8186_afe_irq_handler, - IRQF_TRIGGER_NONE, - "Afe_ISR_Handle", (void *)afe); - if (ret) - return ret; - - ret = enable_irq_wake(irq_id); - if (ret < 0) - return dev_err_probe(dev, ret, "enable_irq_wake %d\n", irq_id); + afe_priv->irq_id = irq_id; /* init sub_dais */ INIT_LIST_HEAD(&afe->sub_dais); @@ -2947,6 +2937,18 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) afe->runtime_resume = mt8186_afe_runtime_resume; afe->runtime_suspend = mt8186_afe_runtime_suspend; + ret = devm_request_irq(dev, irq_id, mt8186_afe_irq_handler, + IRQF_TRIGGER_NONE, + "Afe_ISR_Handle", afe); + if (ret) + goto err_pm_disable; + + ret = enable_irq_wake(irq_id); + if (ret < 0) { + dev_err_probe(dev, ret, "enable_irq_wake %d\n", irq_id); + goto err_free_irq; + } + /* register platform */ dev_dbg(dev, "%s(), devm_snd_soc_register_component\n", __func__); @@ -2955,13 +2957,13 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) afe->dai_drivers, afe->num_dai_drivers); if (ret) - goto err_pm_disable; + goto err_disable_irq_wake; ret = pm_runtime_put_sync(dev); if (ret) { pm_runtime_get_noresume(dev); dev_err(dev, "failed to suspend device: %d\n", ret); - goto err_pm_disable; + goto err_disable_irq_wake; } afe_priv->pm_runtime_bypass_reg_ctl = false; @@ -2970,6 +2972,10 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) return 0; +err_disable_irq_wake: + disable_irq_wake(irq_id); +err_free_irq: + devm_free_irq(dev, irq_id, afe); err_pm_disable: pm_runtime_put_noidle(dev); pm_runtime_set_suspended(dev); @@ -2977,6 +2983,16 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev) return ret; } +static void mt8186_afe_pcm_dev_remove(struct platform_device *pdev) +{ + struct mtk_base_afe *afe = platform_get_drvdata(pdev); + struct mt8186_afe_private *afe_priv = afe->platform_priv; + int irq_id = afe_priv->irq_id; + + disable_irq_wake(irq_id); + devm_free_irq(&pdev->dev, irq_id, afe); +} + static const struct of_device_id mt8186_afe_pcm_dt_match[] = { { .compatible = "mediatek,mt8186-sound", }, {}, @@ -2995,6 +3011,7 @@ static struct platform_driver mt8186_afe_pcm_driver = { .pm = pm_ptr(&mt8186_afe_pm_ops), }, .probe = mt8186_afe_pcm_dev_probe, + .remove = mt8186_afe_pcm_dev_remove, }; module_platform_driver(mt8186_afe_pcm_driver); diff --git a/sound/soc/mediatek/mt8186/mt8186-audsys-clk.c b/sound/soc/mediatek/mt8186/mt8186-audsys-clk.c index 642f4fb55ca637..8af815ac2fb854 100644 --- a/sound/soc/mediatek/mt8186/mt8186-audsys-clk.c +++ b/sound/soc/mediatek/mt8186/mt8186-audsys-clk.c @@ -114,9 +114,8 @@ int mt8186_audsys_clk_register(struct mtk_base_afe *afe) struct clk_lookup *cl; int i; - afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK, - sizeof(*afe_priv->lookup), - GFP_KERNEL); + afe_priv->lookup = devm_kzalloc_objs(afe->dev, *afe_priv->lookup, + CLK_AUD_NR_CLK); if (!afe_priv->lookup) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-adda.c b/sound/soc/mediatek/mt8186/mt8186-dai-adda.c index e74174ae8873c2..15bedc21c1fe44 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-adda.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-adda.c @@ -746,7 +746,7 @@ int mt8186_dai_adda_register(struct mtk_base_afe *afe) struct mt8186_afe_private *afe_priv = afe->platform_priv; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-hostless.c b/sound/soc/mediatek/mt8186/mt8186-dai-hostless.c index bf0d83840cf4d1..c7de6d1b312199 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-hostless.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-hostless.c @@ -282,7 +282,7 @@ int mt8186_dai_hostless_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c b/sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c index 75cb30790b1b1f..dd82591ac9ac81 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-hw-gain.c @@ -217,7 +217,7 @@ int mt8186_dai_hw_gain_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-i2s.c b/sound/soc/mediatek/mt8186/mt8186-dai-i2s.c index f890e9173a076f..cf2b076e89d372 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-i2s.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-i2s.c @@ -1206,7 +1206,7 @@ int mt8186_dai_i2s_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-pcm.c b/sound/soc/mediatek/mt8186/mt8186-dai-pcm.c index a50aa294960b13..7d1bf3c50f194f 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-pcm.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-pcm.c @@ -376,8 +376,7 @@ static struct mtk_afe_pcm_priv *init_pcm_priv_data(struct mtk_base_afe *afe) { struct mtk_afe_pcm_priv *pcm_priv; - pcm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_pcm_priv), - GFP_KERNEL); + pcm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_pcm_priv); if (!pcm_priv) return NULL; @@ -395,7 +394,7 @@ int mt8186_dai_pcm_register(struct mtk_base_afe *afe) struct mtk_afe_pcm_priv *pcm_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-src.c b/sound/soc/mediatek/mt8186/mt8186-dai-src.c index e475f4591aef51..c60c7e6dbfab29 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-src.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-src.c @@ -666,7 +666,7 @@ int mt8186_dai_src_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-dai-tdm.c b/sound/soc/mediatek/mt8186/mt8186-dai-tdm.c index 7a8890d7122f25..147a8b1a73bcd3 100644 --- a/sound/soc/mediatek/mt8186/mt8186-dai-tdm.c +++ b/sound/soc/mediatek/mt8186/mt8186-dai-tdm.c @@ -599,8 +599,7 @@ static struct mtk_afe_tdm_priv *init_tdm_priv_data(struct mtk_base_afe *afe) { struct mtk_afe_tdm_priv *tdm_priv; - tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), - GFP_KERNEL); + tdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_tdm_priv); if (!tdm_priv) return NULL; @@ -617,7 +616,7 @@ int mt8186_dai_tdm_register(struct mtk_base_afe *afe) struct mtk_afe_tdm_priv *tdm_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366.c b/sound/soc/mediatek/mt8186/mt8186-mt6366.c index b68f474b63f420..540063bcada9e4 100644 --- a/sound/soc/mediatek/mt8186/mt8186-mt6366.c +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366.c @@ -1214,7 +1214,7 @@ static int mt8186_mt6366_soc_card_probe(struct mtk_soc_card_data *soc_card_data, struct device *dev = card->dev; int i, ret; - mach_priv = devm_kzalloc(dev, sizeof(*mach_priv), GFP_KERNEL); + mach_priv = devm_kzalloc_obj(dev, *mach_priv); if (!mach_priv) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-afe-clk.c b/sound/soc/mediatek/mt8188/mt8188-afe-clk.c index 8b6dca22c8edf5..5b3022d7f253a1 100644 --- a/sound/soc/mediatek/mt8188/mt8188-afe-clk.c +++ b/sound/soc/mediatek/mt8188/mt8188-afe-clk.c @@ -422,8 +422,7 @@ int mt8188_afe_init_clock(struct mtk_base_afe *afe) } afe_priv->clk = - devm_kcalloc(afe->dev, MT8188_CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + devm_kzalloc_objs(afe->dev, *afe_priv->clk, MT8188_CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-afe-pcm.c b/sound/soc/mediatek/mt8188/mt8188-afe-pcm.c index d9c82cd8869eea..c1697c7212cbce 100644 --- a/sound/soc/mediatek/mt8188/mt8188-afe-pcm.c +++ b/sound/soc/mediatek/mt8188/mt8188-afe-pcm.c @@ -3069,9 +3069,8 @@ static int init_memif_priv_data(struct mtk_base_afe *afe) int i; for (i = MT8188_AFE_MEMIF_START; i < MT8188_AFE_MEMIF_END; i++) { - memif_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_memif_priv), - GFP_KERNEL); + memif_priv = devm_kzalloc_obj(afe->dev, + struct mtk_dai_memif_priv); if (!memif_priv) return -ENOMEM; @@ -3085,7 +3084,7 @@ static int mt8188_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -3221,12 +3220,11 @@ static int mt8188_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(&pdev->dev, *afe); if (!afe) return -ENOMEM; - afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(&pdev->dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -3279,8 +3277,7 @@ static int mt8188_afe_pcm_dev_probe(struct platform_device *pdev) /* irq initialize */ afe->irqs_size = MT8188_AFE_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -3289,8 +3286,7 @@ static int mt8188_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT8188_AFE_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -3306,11 +3302,6 @@ static int mt8188_afe_pcm_dev_probe(struct platform_device *pdev) if (irq_id < 0) return irq_id; - ret = devm_request_irq(dev, irq_id, mt8188_afe_irq_handler, - IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); - if (ret) - return ret; - /* init sub_dais */ INIT_LIST_HEAD(&afe->sub_dais); @@ -3362,6 +3353,11 @@ static int mt8188_afe_pcm_dev_probe(struct platform_device *pdev) goto err_pm_put; } + ret = devm_request_irq(dev, irq_id, mt8188_afe_irq_handler, + IRQF_TRIGGER_NONE, "asys-isr", afe); + if (ret) + goto err_pm_put; + /* register component */ ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, afe->dai_drivers, afe->num_dai_drivers); diff --git a/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c b/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c index 9f3b3a777577c9..0f6296bfe79f85 100644 --- a/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c +++ b/sound/soc/mediatek/mt8188/mt8188-audsys-clk.c @@ -172,9 +172,8 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) struct clk_lookup *cl; int i, ret; - afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK, - sizeof(*afe_priv->lookup), - GFP_KERNEL); + afe_priv->lookup = devm_kzalloc_objs(afe->dev, *afe_priv->lookup, + CLK_AUD_NR_CLK); if (!afe_priv->lookup) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c index 395f4ab972f81c..1ea05ce73999f4 100644 --- a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c +++ b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c @@ -473,9 +473,7 @@ static int init_adda_priv_data(struct mtk_base_afe *afe) int i; for (i = 0; i < ARRAY_SIZE(adda_dai_list); i++) { - adda_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_adda_priv), - GFP_KERNEL); + adda_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_adda_priv); if (!adda_priv) return -ENOMEM; @@ -489,7 +487,7 @@ int mt8188_dai_adda_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-dmic.c b/sound/soc/mediatek/mt8188/mt8188-dai-dmic.c index 7ac847a5925ca6..6e2ce472aaa790 100644 --- a/sound/soc/mediatek/mt8188/mt8188-dai-dmic.c +++ b/sound/soc/mediatek/mt8188/mt8188-dai-dmic.c @@ -645,8 +645,7 @@ static int init_dmic_priv_data(struct mtk_base_afe *afe) struct mt8188_afe_private *afe_priv = afe->platform_priv; struct mtk_dai_dmic_priv *dmic_priv; - dmic_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_dmic_priv), - GFP_KERNEL); + dmic_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_dmic_priv); if (!dmic_priv) return -ENOMEM; @@ -658,7 +657,7 @@ int mt8188_dai_dmic_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c index 4dfaa761f9f736..7c9f8c6cc090f6 100644 --- a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c +++ b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c @@ -2672,9 +2672,7 @@ static int init_etdm_priv_data(struct mtk_base_afe *afe) int i; for (i = MT8188_AFE_IO_ETDM_START; i < MT8188_AFE_IO_ETDM_END; i++) { - etdm_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_etdm_priv), - GFP_KERNEL); + etdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_etdm_priv); if (!etdm_priv) return -ENOMEM; @@ -2692,7 +2690,7 @@ int mt8188_dai_etdm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-pcm.c b/sound/soc/mediatek/mt8188/mt8188-dai-pcm.c index 8ca7cc75e21dc8..f7a1de4c541d25 100644 --- a/sound/soc/mediatek/mt8188/mt8188-dai-pcm.c +++ b/sound/soc/mediatek/mt8188/mt8188-dai-pcm.c @@ -337,8 +337,7 @@ static int init_pcmif_priv_data(struct mtk_base_afe *afe) struct mt8188_afe_private *afe_priv = afe->platform_priv; struct mtk_dai_pcmif_priv *pcmif_priv; - pcmif_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_pcmif_priv), - GFP_KERNEL); + pcmif_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_pcmif_priv); if (!pcmif_priv) return -ENOMEM; @@ -350,7 +349,7 @@ int mt8188_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-clk.c b/sound/soc/mediatek/mt8189/mt8189-afe-clk.c index 594c214fa69762..6fb9f861385ed6 100644 --- a/sound/soc/mediatek/mt8189/mt8189-afe-clk.c +++ b/sound/soc/mediatek/mt8189/mt8189-afe-clk.c @@ -786,8 +786,8 @@ int mt8189_init_clock(struct mtk_base_afe *afe) int ret; int i; - afe_priv->clk = devm_kcalloc(afe->dev, MT8189_CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, + MT8189_CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-common.h b/sound/soc/mediatek/mt8189/mt8189-afe-common.h index 910d90d3d1468c..de715c92add5f4 100644 --- a/sound/soc/mediatek/mt8189/mt8189-afe-common.h +++ b/sound/soc/mediatek/mt8189/mt8189-afe-common.h @@ -202,6 +202,7 @@ enum { struct clk; struct mt8189_afe_private { + int irq_id; struct clk **clk; struct regmap *pmic_regmap; diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c index eefa96b701a5e9..5386a50d20641f 100644 --- a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c +++ b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c @@ -2414,7 +2414,7 @@ static int mt8189_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -2460,14 +2460,13 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) dev_warn(dev, "failed to assign memory region: %d\n", ret); - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -2487,8 +2486,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) /* IPM2.0 no need banding */ afe->memif_32bit_supported = 1; afe->memif_size = MT8189_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -2503,8 +2501,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) /* init irq */ afe->irqs_size = MT8189_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -2516,12 +2513,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) irq_id = platform_get_irq(pdev, 0); if (irq_id < 0) return irq_id; - - ret = devm_request_irq(dev, irq_id, mt8189_afe_irq_handler, - IRQF_TRIGGER_NONE, - "Afe_ISR_Handle", afe); - if (ret) - return ret; + afe_priv->irq_id = irq_id; /* init sub_dais */ INIT_LIST_HEAD(&afe->sub_dais); @@ -2576,6 +2568,12 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) goto err_pm_put; } + ret = devm_request_irq(dev, irq_id, mt8189_afe_irq_handler, + IRQF_TRIGGER_NONE, + "Afe_ISR_Handle", afe); + if (ret) + goto err_pm_put; + regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg); regmap_write(afe->regmap, AFE_IRQ_MCU_EN, 0xffffffff); regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg); @@ -2603,8 +2601,11 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) static void mt8189_afe_pcm_dev_remove(struct platform_device *pdev) { struct mtk_base_afe *afe = platform_get_drvdata(pdev); + struct mt8189_afe_private *afe_priv = afe->platform_priv; struct device *dev = &pdev->dev; + devm_free_irq(dev, afe_priv->irq_id, afe); + if (!pm_runtime_status_suspended(dev)) mt8189_afe_runtime_suspend(dev); diff --git a/sound/soc/mediatek/mt8189/mt8189-dai-adda.c b/sound/soc/mediatek/mt8189/mt8189-dai-adda.c index 5c41a638620434..70bedcdef17919 100644 --- a/sound/soc/mediatek/mt8189/mt8189-dai-adda.c +++ b/sound/soc/mediatek/mt8189/mt8189-dai-adda.c @@ -1180,9 +1180,7 @@ static int init_adda_priv_data(struct mtk_base_afe *afe) }; for (int i = 0; i < ARRAY_SIZE(adda_dai_list); i++) { - adda_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_afe_adda_priv), - GFP_KERNEL); + adda_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_adda_priv); if (!adda_priv) return -ENOMEM; @@ -1203,7 +1201,7 @@ int mt8189_dai_adda_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-dai-i2s.c b/sound/soc/mediatek/mt8189/mt8189-dai-i2s.c index c9e80ef42f6088..4744b76f317216 100644 --- a/sound/soc/mediatek/mt8189/mt8189-dai-i2s.c +++ b/sound/soc/mediatek/mt8189/mt8189-dai-i2s.c @@ -1441,7 +1441,7 @@ int mt8189_dai_i2s_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-dai-pcm.c b/sound/soc/mediatek/mt8189/mt8189-dai-pcm.c index 21317c0413e5c7..ee259ec773db30 100644 --- a/sound/soc/mediatek/mt8189/mt8189-dai-pcm.c +++ b/sound/soc/mediatek/mt8189/mt8189-dai-pcm.c @@ -315,7 +315,7 @@ int mt8189_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-dai-tdm.c b/sound/soc/mediatek/mt8189/mt8189-dai-tdm.c index e113c52fe06a96..dab930ab864641 100644 --- a/sound/soc/mediatek/mt8189/mt8189-dai-tdm.c +++ b/sound/soc/mediatek/mt8189/mt8189-dai-tdm.c @@ -627,8 +627,7 @@ static struct mtk_afe_tdm_priv *init_tdm_priv_data(struct mtk_base_afe *afe, { struct mtk_afe_tdm_priv *tdm_priv; - tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), - GFP_KERNEL); + tdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_tdm_priv); if (!tdm_priv) return NULL; @@ -649,7 +648,7 @@ int mt8189_dai_tdm_register(struct mtk_base_afe *afe) struct mtk_afe_tdm_priv *tdm_priv, *tdm_dptx_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8189/mt8189-nau8825.c b/sound/soc/mediatek/mt8189/mt8189-nau8825.c index 5d652d0cf01e25..b551477cef51ea 100644 --- a/sound/soc/mediatek/mt8189/mt8189-nau8825.c +++ b/sound/soc/mediatek/mt8189/mt8189-nau8825.c @@ -74,14 +74,14 @@ enum mt8189_jacks { static struct snd_soc_jack_pin mt8189_dp_jack_pins[] = { { .pin = "DP", - .mask = SND_JACK_LINEOUT, + .mask = SND_JACK_AVOUT, }, }; static struct snd_soc_jack_pin mt8189_hdmi_jack_pins[] = { { .pin = "HDMI", - .mask = SND_JACK_LINEOUT, + .mask = SND_JACK_AVOUT, }, }; @@ -369,7 +369,7 @@ static int mt8189_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; int ret; - ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT, + ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_AVOUT, jack, mt8189_dp_jack_pins, ARRAY_SIZE(mt8189_dp_jack_pins)); if (ret) { @@ -394,7 +394,7 @@ static int mt8189_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; int ret; - ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, + ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", SND_JACK_AVOUT, jack, mt8189_hdmi_jack_pins, ARRAY_SIZE(mt8189_hdmi_jack_pins)); if (ret) { diff --git a/sound/soc/mediatek/mt8192/mt8192-afe-clk.c b/sound/soc/mediatek/mt8192/mt8192-afe-clk.c index c6ca4fe7fb1939..583ea4c4833289 100644 --- a/sound/soc/mediatek/mt8192/mt8192-afe-clk.c +++ b/sound/soc/mediatek/mt8192/mt8192-afe-clk.c @@ -666,8 +666,7 @@ int mt8192_init_clock(struct mtk_base_afe *afe) struct device_node *of_node = afe->dev->of_node; int i = 0; - afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8192/mt8192-afe-common.h b/sound/soc/mediatek/mt8192/mt8192-afe-common.h index ad461dcb6ee1a9..cd5630f2661556 100644 --- a/sound/soc/mediatek/mt8192/mt8192-afe-common.h +++ b/sound/soc/mediatek/mt8192/mt8192-afe-common.h @@ -154,8 +154,6 @@ struct mt8192_afe_private { int mt8192_dai_adda_register(struct mtk_base_afe *afe); int mt8192_dai_i2s_register(struct mtk_base_afe *afe); -int mt8192_dai_hw_gain_register(struct mtk_base_afe *afe); -int mt8192_dai_src_register(struct mtk_base_afe *afe); int mt8192_dai_pcm_register(struct mtk_base_afe *afe); int mt8192_dai_tdm_register(struct mtk_base_afe *afe); diff --git a/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c b/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c index 45addf9f37901c..d8d75b0b8bdcfa 100644 --- a/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c +++ b/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c @@ -2134,7 +2134,7 @@ static int mt8192_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -2171,13 +2171,12 @@ static int mt8192_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; afe_priv = afe->platform_priv; @@ -2238,8 +2237,7 @@ static int mt8192_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT8192_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -2253,8 +2251,7 @@ static int mt8192_afe_pcm_dev_probe(struct platform_device *pdev) /* init irq */ afe->irqs_size = MT8192_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8192/mt8192-dai-adda.c b/sound/soc/mediatek/mt8192/mt8192-dai-adda.c index c5c726a6e4230d..d4074e9142b541 100644 --- a/sound/soc/mediatek/mt8192/mt8192-dai-adda.c +++ b/sound/soc/mediatek/mt8192/mt8192-dai-adda.c @@ -1359,7 +1359,7 @@ int mt8192_dai_adda_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; struct mt8192_afe_private *afe_priv = afe->platform_priv; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8192/mt8192-dai-i2s.c b/sound/soc/mediatek/mt8192/mt8192-dai-i2s.c index 5608b534af0d96..179816830e1f2b 100644 --- a/sound/soc/mediatek/mt8192/mt8192-dai-i2s.c +++ b/sound/soc/mediatek/mt8192/mt8192-dai-i2s.c @@ -2084,7 +2084,7 @@ int mt8192_dai_i2s_register(struct mtk_base_afe *afe) dev_dbg(afe->dev, "%s()\n", __func__); - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8192/mt8192-dai-pcm.c b/sound/soc/mediatek/mt8192/mt8192-dai-pcm.c index 2847a2e747be27..1084c16a88bc3e 100644 --- a/sound/soc/mediatek/mt8192/mt8192-dai-pcm.c +++ b/sound/soc/mediatek/mt8192/mt8192-dai-pcm.c @@ -394,7 +394,7 @@ int mt8192_dai_pcm_register(struct mtk_base_afe *afe) dev_info(afe->dev, "%s()\n", __func__); - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8192/mt8192-dai-tdm.c b/sound/soc/mediatek/mt8192/mt8192-dai-tdm.c index 36fa0f32ed1cb4..8867389b2f7f26 100644 --- a/sound/soc/mediatek/mt8192/mt8192-dai-tdm.c +++ b/sound/soc/mediatek/mt8192/mt8192-dai-tdm.c @@ -743,8 +743,7 @@ static struct mtk_afe_tdm_priv *init_tdm_priv_data(struct mtk_base_afe *afe) { struct mtk_afe_tdm_priv *tdm_priv; - tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), - GFP_KERNEL); + tdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_tdm_priv); if (!tdm_priv) return NULL; @@ -762,7 +761,7 @@ int mt8192_dai_tdm_register(struct mtk_base_afe *afe) struct mtk_afe_tdm_priv *tdm_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-afe-clk.c b/sound/soc/mediatek/mt8195/mt8195-afe-clk.c index 44cddc2b1564bb..54827ffe5c43d3 100644 --- a/sound/soc/mediatek/mt8195/mt8195-afe-clk.c +++ b/sound/soc/mediatek/mt8195/mt8195-afe-clk.c @@ -390,8 +390,7 @@ int mt8195_afe_init_clock(struct mtk_base_afe *afe) mt8195_audsys_clk_register(afe); afe_priv->clk = - devm_kcalloc(afe->dev, MT8195_CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + devm_kzalloc_objs(afe->dev, *afe_priv->clk, MT8195_CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-afe-common.h b/sound/soc/mediatek/mt8195/mt8195-afe-common.h index f93f439e2bd94c..905f29673d3e90 100644 --- a/sound/soc/mediatek/mt8195/mt8195-afe-common.h +++ b/sound/soc/mediatek/mt8195/mt8195-afe-common.h @@ -123,6 +123,7 @@ struct mtkaif_param { struct clk; struct mt8195_afe_private { + int irq_id; struct clk **clk; struct clk_lookup **lookup; struct regmap *topckgen; diff --git a/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c b/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c index 13e5bc02fac542..5cb2b781c0d15a 100644 --- a/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +++ b/sound/soc/mediatek/mt8195/mt8195-afe-pcm.c @@ -2999,9 +2999,8 @@ static int init_memif_priv_data(struct mtk_base_afe *afe) int i; for (i = MT8195_AFE_MEMIF_START; i < MT8195_AFE_MEMIF_END; i++) { - memif_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_memif_priv), - GFP_KERNEL); + memif_priv = devm_kzalloc_obj(afe->dev, + struct mtk_dai_memif_priv); if (!memif_priv) return -ENOMEM; @@ -3015,7 +3014,7 @@ static int mt8195_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -3071,12 +3070,11 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) return ret; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -3107,8 +3105,7 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) /* irq initialize */ afe->irqs_size = MT8195_AFE_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -3117,8 +3114,7 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) /* init memif */ afe->memif_size = MT8195_AFE_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -3133,11 +3129,7 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) irq_id = platform_get_irq(pdev, 0); if (irq_id < 0) return irq_id; - - ret = devm_request_irq(dev, irq_id, mt8195_afe_irq_handler, - IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); - if (ret) - return ret; + afe_priv->irq_id = irq_id; /* init sub_dais */ INIT_LIST_HEAD(&afe->sub_dais); @@ -3192,6 +3184,11 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) goto err_pm_put; } + ret = devm_request_irq(dev, irq_id, mt8195_afe_irq_handler, + IRQF_TRIGGER_NONE, "asys-isr", afe); + if (ret) + goto err_pm_put; + /* register component */ ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, afe->dai_drivers, afe->num_dai_drivers); @@ -3223,6 +3220,11 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev) static void mt8195_afe_pcm_dev_remove(struct platform_device *pdev) { + struct mtk_base_afe *afe = platform_get_drvdata(pdev); + struct mt8195_afe_private *afe_priv = afe->platform_priv; + + devm_free_irq(&pdev->dev, afe_priv->irq_id, afe); + if (!pm_runtime_status_suspended(&pdev->dev)) mt8195_afe_runtime_suspend(&pdev->dev); } diff --git a/sound/soc/mediatek/mt8195/mt8195-audsys-clk.c b/sound/soc/mediatek/mt8195/mt8195-audsys-clk.c index e6fefc3204434c..5343ecc5685333 100644 --- a/sound/soc/mediatek/mt8195/mt8195-audsys-clk.c +++ b/sound/soc/mediatek/mt8195/mt8195-audsys-clk.c @@ -178,9 +178,8 @@ int mt8195_audsys_clk_register(struct mtk_base_afe *afe) struct clk_lookup *cl; int i; - afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK, - sizeof(*afe_priv->lookup), - GFP_KERNEL); + afe_priv->lookup = devm_kzalloc_objs(afe->dev, *afe_priv->lookup, + CLK_AUD_NR_CLK); if (!afe_priv->lookup) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-dai-adda.c b/sound/soc/mediatek/mt8195/mt8195-dai-adda.c index 8a58a142064d88..ce12520850c70f 100644 --- a/sound/soc/mediatek/mt8195/mt8195-dai-adda.c +++ b/sound/soc/mediatek/mt8195/mt8195-dai-adda.c @@ -716,9 +716,7 @@ static int init_adda_priv_data(struct mtk_base_afe *afe) int i; for (i = 0; i < ARRAY_SIZE(adda_dai_list); i++) { - adda_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_adda_priv), - GFP_KERNEL); + adda_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_adda_priv); if (!adda_priv) return -ENOMEM; @@ -732,7 +730,7 @@ int mt8195_dai_adda_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c b/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c index 8fa830a575029b..1806ddc467084a 100644 --- a/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +++ b/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c @@ -2355,6 +2355,32 @@ static void mtk_dai_hdmitx_dptx_shutdown(struct snd_pcm_substream *substream, mt8195_afe_disable_clk(afe, afe_priv->clk[cg_id]); } +static int mtk_dai_etdm3_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); + struct mt8195_afe_private *afe_priv = afe->platform_priv; + int cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); + + if (cg_id < 0) + return -EINVAL; + + return mt8195_afe_enable_clk(afe, afe_priv->clk[cg_id]); +} + +static void mtk_dai_etdm3_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); + struct mt8195_afe_private *afe_priv = afe->platform_priv; + int cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); + + if (cg_id < 0) + return; + + mt8195_afe_disable_clk(afe, afe_priv->clk[cg_id]); +} + static unsigned int mtk_dai_get_dptx_ch_en(unsigned int channel) { switch (channel) { @@ -2541,8 +2567,8 @@ static const struct snd_soc_dai_ops mtk_dai_hdmitx_dptx_ops = { static const struct snd_soc_dai_ops mtk_dai_hdmitx_dptx_ops2 = { .probe = mtk_dai_etdm_probe, - .startup = mtk_dai_hdmitx_dptx_startup, - .shutdown = mtk_dai_hdmitx_dptx_shutdown, + .startup = mtk_dai_etdm3_startup, + .shutdown = mtk_dai_etdm3_shutdown, .hw_params = mtk_dai_hdmitx_dptx_hw_params, .trigger = mtk_dai_hdmitx_dptx_trigger, .set_sysclk = mtk_dai_hdmitx_dptx_set_sysclk, @@ -2763,9 +2789,7 @@ static int init_etdm_priv_data(struct mtk_base_afe *afe) int i; for (i = MT8195_AFE_IO_ETDM_START; i < MT8195_AFE_IO_ETDM_END; i++) { - etdm_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_dai_etdm_priv), - GFP_KERNEL); + etdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_etdm_priv); if (!etdm_priv) return -ENOMEM; @@ -2783,7 +2807,7 @@ int mt8195_dai_etdm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c b/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c index cdc16057d50e2f..113b7d073240da 100644 --- a/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c +++ b/sound/soc/mediatek/mt8195/mt8195-dai-pcm.c @@ -338,8 +338,7 @@ static int init_pcmif_priv_data(struct mtk_base_afe *afe) struct mt8195_afe_private *afe_priv = afe->platform_priv; struct mtk_dai_pcmif_priv *pcmif_priv; - pcmif_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_pcmif_priv), - GFP_KERNEL); + pcmif_priv = devm_kzalloc_obj(afe->dev, struct mtk_dai_pcmif_priv); if (!pcmif_priv) return -ENOMEM; @@ -351,7 +350,7 @@ int mt8195_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8195/mt8195-mt6359.c b/sound/soc/mediatek/mt8195/mt8195-mt6359.c index fc293ca715023d..0040787df22fd9 100644 --- a/sound/soc/mediatek/mt8195/mt8195-mt6359.c +++ b/sound/soc/mediatek/mt8195/mt8195-mt6359.c @@ -1381,7 +1381,7 @@ static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, u8 codec_init = 0; int i; - mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); + mach_priv = devm_kzalloc_obj(card->dev, *mach_priv); if (!mach_priv) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-clk.c b/sound/soc/mediatek/mt8196/mt8196-afe-clk.c index 91a05ea6b8b6a1..f7099880b3b35b 100644 --- a/sound/soc/mediatek/mt8196/mt8196-afe-clk.c +++ b/sound/soc/mediatek/mt8196/mt8196-afe-clk.c @@ -611,8 +611,8 @@ int mt8196_init_clock(struct mtk_base_afe *afe) struct mt8196_afe_private *afe_priv = afe->platform_priv; int i; - afe_priv->clk = devm_kcalloc(afe->dev, MT8196_CLK_NUM, sizeof(*afe_priv->clk), - GFP_KERNEL); + afe_priv->clk = devm_kzalloc_objs(afe->dev, *afe_priv->clk, + MT8196_CLK_NUM); if (!afe_priv->clk) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-common.h b/sound/soc/mediatek/mt8196/mt8196-afe-common.h index 4951a6f32abbf3..62c505980bba9b 100644 --- a/sound/soc/mediatek/mt8196/mt8196-afe-common.h +++ b/sound/soc/mediatek/mt8196/mt8196-afe-common.h @@ -186,6 +186,7 @@ struct clk; struct mtk_base_afe; struct mt8196_afe_private { + int irq_id; struct clk **clk; /* dai */ void *dai_priv[MT8196_DAI_NUM]; @@ -199,7 +200,5 @@ struct mt8196_afe_private { int mt8196_dai_adda_register(struct mtk_base_afe *afe); int mt8196_dai_i2s_register(struct mtk_base_afe *afe); int mt8196_dai_tdm_register(struct mtk_base_afe *afe); -int mt8196_dai_set_priv(struct mtk_base_afe *afe, int id, - int priv_size, const void *priv_data); #endif diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c index f69ea22cfabbfc..d0fe5d5f648d62 100644 --- a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c +++ b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c @@ -2302,7 +2302,7 @@ static int mt8196_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -2346,14 +2346,13 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) if (ret) dev_err(dev, "failed to assign memory region: %d\n", ret); - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -2374,8 +2373,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) /* IPM2.0 no need banding */ afe->memif_32bit_supported = 1; afe->memif_size = MT8196_MEMIF_NUM; - afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), - GFP_KERNEL); + afe->memif = devm_kzalloc_objs(dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; @@ -2390,8 +2388,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) /* init irq */ afe->irqs_size = MT8196_IRQ_NUM; - afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), - GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; @@ -2403,12 +2400,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) irq_id = platform_get_irq(pdev, 0); if (irq_id < 0) return irq_id; - - ret = devm_request_irq(dev, irq_id, mt8196_afe_irq_handler, - IRQF_TRIGGER_NONE, - "Afe_ISR_Handle", afe); - if (ret) - return ret; + afe_priv->irq_id = irq_id; /* init sub_dais */ INIT_LIST_HEAD(&afe->sub_dais); @@ -2463,6 +2455,12 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) goto err_pm_put; } + ret = devm_request_irq(dev, irq_id, mt8196_afe_irq_handler, + IRQF_TRIGGER_NONE, + "Afe_ISR_Handle", afe); + if (ret) + goto err_pm_put; + regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg); regmap_write(afe->regmap, AFE_IRQ_MCU_EN, 0xffffffff); regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &tmp_reg); @@ -2490,8 +2488,11 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev) static void mt8196_afe_pcm_dev_remove(struct platform_device *pdev) { struct mtk_base_afe *afe = platform_get_drvdata(pdev); + struct mt8196_afe_private *afe_priv = afe->platform_priv; struct device *dev = &pdev->dev; + devm_free_irq(dev, afe_priv->irq_id, afe); + if (!pm_runtime_status_suspended(dev)) mt8196_afe_runtime_suspend(dev); diff --git a/sound/soc/mediatek/mt8196/mt8196-dai-adda.c b/sound/soc/mediatek/mt8196/mt8196-dai-adda.c index 9a91db4e79ae83..4046202c1deeb2 100644 --- a/sound/soc/mediatek/mt8196/mt8196-dai-adda.c +++ b/sound/soc/mediatek/mt8196/mt8196-dai-adda.c @@ -800,9 +800,7 @@ static int init_adda_priv_data(struct mtk_base_afe *afe) int i; for (i = 0; i < ARRAY_SIZE(adda_dai_list); i++) { - adda_priv = devm_kzalloc(afe->dev, - sizeof(struct mtk_afe_adda_priv), - GFP_KERNEL); + adda_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_adda_priv); if (!adda_priv) return -ENOMEM; @@ -823,7 +821,7 @@ int mt8196_dai_adda_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8196/mt8196-dai-i2s.c b/sound/soc/mediatek/mt8196/mt8196-dai-i2s.c index adebf75629beda..74c244101dfbf9 100644 --- a/sound/soc/mediatek/mt8196/mt8196-dai-i2s.c +++ b/sound/soc/mediatek/mt8196/mt8196-dai-i2s.c @@ -2588,7 +2588,7 @@ int mt8196_dai_i2s_register(struct mtk_base_afe *afe) struct mtk_base_afe_dai *dai; int ret; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8196/mt8196-dai-tdm.c b/sound/soc/mediatek/mt8196/mt8196-dai-tdm.c index 44bd08f5c1fbe5..5cbb029c07077e 100644 --- a/sound/soc/mediatek/mt8196/mt8196-dai-tdm.c +++ b/sound/soc/mediatek/mt8196/mt8196-dai-tdm.c @@ -626,8 +626,7 @@ static struct mtk_afe_tdm_priv *init_tdm_priv_data(struct mtk_base_afe *afe, { struct mtk_afe_tdm_priv *tdm_priv; - tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), - GFP_KERNEL); + tdm_priv = devm_kzalloc_obj(afe->dev, struct mtk_afe_tdm_priv); if (!tdm_priv) return NULL; @@ -648,7 +647,7 @@ int mt8196_dai_tdm_register(struct mtk_base_afe *afe) struct mtk_afe_tdm_priv *tdm_priv, *tdm_dptx_priv; struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-common.h b/sound/soc/mediatek/mt8365/mt8365-afe-common.h index 731406e15ac744..f908e57fe7a198 100644 --- a/sound/soc/mediatek/mt8365/mt8365-afe-common.h +++ b/sound/soc/mediatek/mt8365/mt8365-afe-common.h @@ -443,6 +443,4 @@ int mt8365_dai_dmic_register(struct mtk_base_afe *afe); int mt8365_dai_pcm_register(struct mtk_base_afe *afe); -int mt8365_dai_tdm_register(struct mtk_base_afe *afe); - #endif diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c index 314235557fdf80..7e5c9ffb83147a 100644 --- a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c +++ b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c @@ -1979,8 +1979,8 @@ static int mt8365_afe_suspend(struct device *dev) if (!afe->reg_back_up) { afe->reg_back_up = - devm_kcalloc(dev, afe->reg_back_up_list_num, - sizeof(unsigned int), GFP_KERNEL); + devm_kzalloc_objs(dev, unsigned int, + afe->reg_back_up_list_num); if (!afe->reg_back_up) { mt8365_afe_disable_main_clk(afe); return -ENOMEM; @@ -2072,7 +2072,7 @@ static int mt8365_dai_memif_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; @@ -2106,13 +2106,12 @@ static int mt8365_afe_pcm_dev_probe(struct platform_device *pdev) unsigned int irq_id; struct resource *res; - afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(&pdev->dev, *afe); if (!afe) return -ENOMEM; platform_set_drvdata(pdev, afe); - afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), - GFP_KERNEL); + afe->platform_priv = devm_kzalloc_obj(&pdev->dev, *afe_priv); if (!afe->platform_priv) return -ENOMEM; @@ -2147,14 +2146,12 @@ static int mt8365_afe_pcm_dev_probe(struct platform_device *pdev) /* memif % irq initialize*/ afe->memif_size = MT8365_AFE_MEMIF_NUM; - afe->memif = devm_kcalloc(afe->dev, afe->memif_size, - sizeof(*afe->memif), GFP_KERNEL); + afe->memif = devm_kzalloc_objs(afe->dev, *afe->memif, afe->memif_size); if (!afe->memif) return -ENOMEM; afe->irqs_size = MT8365_AFE_IRQ_NUM; - afe->irqs = devm_kcalloc(afe->dev, afe->irqs_size, - sizeof(*afe->irqs), GFP_KERNEL); + afe->irqs = devm_kzalloc_objs(afe->dev, *afe->irqs, afe->irqs_size); if (!afe->irqs) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-adda.c b/sound/soc/mediatek/mt8365/mt8365-dai-adda.c index d8eda9e17eb844..a0dbd1d7bd8d10 100644 --- a/sound/soc/mediatek/mt8365/mt8365-dai-adda.c +++ b/sound/soc/mediatek/mt8365/mt8365-dai-adda.c @@ -291,7 +291,7 @@ int mt8365_dai_adda_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; list_add(&dai->list, &afe->sub_dais); diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-dmic.c b/sound/soc/mediatek/mt8365/mt8365-dai-dmic.c index 0bac143b48bfb3..7f247cbfc64c3a 100644 --- a/sound/soc/mediatek/mt8365/mt8365-dai-dmic.c +++ b/sound/soc/mediatek/mt8365/mt8365-dai-dmic.c @@ -270,7 +270,7 @@ static int init_dmic_priv_data(struct mtk_base_afe *afe) unsigned int temps[4]; int ret; - dmic_priv = devm_kzalloc(afe->dev, sizeof(*dmic_priv), GFP_KERNEL); + dmic_priv = devm_kzalloc_obj(afe->dev, *dmic_priv); if (!dmic_priv) return -ENOMEM; @@ -293,7 +293,7 @@ int mt8365_dai_dmic_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c index 2e678f4aa4b1fb..0ca90a3a5941df 100644 --- a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c +++ b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c @@ -824,7 +824,7 @@ int mt8365_dai_i2s_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-pcm.c b/sound/soc/mediatek/mt8365/mt8365-dai-pcm.c index 0ec114a566ad10..65ecf678c5303e 100644 --- a/sound/soc/mediatek/mt8365/mt8365-dai-pcm.c +++ b/sound/soc/mediatek/mt8365/mt8365-dai-pcm.c @@ -265,8 +265,7 @@ static int init_pcmif_priv_data(struct mtk_base_afe *afe) struct mt8365_afe_private *afe_priv = afe->platform_priv; struct mt8365_pcm_intf_data *pcmif_priv; - pcmif_priv = devm_kzalloc(afe->dev, sizeof(struct mt8365_pcm_intf_data), - GFP_KERNEL); + pcmif_priv = devm_kzalloc_obj(afe->dev, struct mt8365_pcm_intf_data); if (!pcmif_priv) return -ENOMEM; @@ -278,7 +277,7 @@ int mt8365_dai_pcm_register(struct mtk_base_afe *afe) { struct mtk_base_afe_dai *dai; - dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(afe->dev, *dai); if (!dai) return -ENOMEM; diff --git a/sound/soc/mediatek/mt8365/mt8365-mt6357.c b/sound/soc/mediatek/mt8365/mt8365-mt6357.c index dceee837c67d88..d8efbfd229e05f 100644 --- a/sound/soc/mediatek/mt8365/mt8365-mt6357.c +++ b/sound/soc/mediatek/mt8365/mt8365-mt6357.c @@ -301,8 +301,7 @@ static int mt8365_mt6357_dev_probe(struct mtk_soc_card_data *soc_card_data, bool if (ret) goto err; - mach_priv = devm_kzalloc(dev, sizeof(*mach_priv), - GFP_KERNEL); + mach_priv = devm_kzalloc_obj(dev, *mach_priv); if (!mach_priv) return -ENOMEM; soc_card_data->mach_priv = mach_priv; diff --git a/sound/soc/meson/Kconfig b/sound/soc/meson/Kconfig index d9a730994a2a2a..adfcca6eb49499 100644 --- a/sound/soc/meson/Kconfig +++ b/sound/soc/meson/Kconfig @@ -2,16 +2,30 @@ menu "Amlogic" depends on ARCH_MESON || (COMPILE_TEST && COMMON_CLK) +config SND_MESON_GX_FORMATTER + tristate + select REGMAP_MMIO + config SND_MESON_AIU tristate "Amlogic AIU" + select REGMAP_MMIO select SND_MESON_CODEC_GLUE select SND_PCM_IEC958 + select SND_MESON_GX_FORMATTER imply SND_SOC_MESON_T9015 imply SND_SOC_HDMI_CODEC if DRM_MESON_DW_HDMI help Select Y or M to add support for the Audio output subsystem found in the Amlogic Meson8, Meson8b and GX SoC families +config SND_MESON_AUDIN + tristate "Amlogic AUDIN" + select REGMAP_MMIO + select SND_MESON_GX_FORMATTER + help + Select Y or M to add support for the audio input subsystem found + in the Amlogic GX SoC family. Currently only I2S input is supported. + config SND_MESON_AXG_FIFO tristate select REGMAP_MMIO @@ -75,6 +89,7 @@ config SND_MESON_AXG_SOUND_CARD config SND_MESON_AXG_SPDIFOUT tristate "Amlogic AXG SPDIF Output Support" + select REGMAP_MMIO select SND_PCM_IEC958 imply SND_SOC_SPDIF imply COMMON_CLK_AXG_AUDIO @@ -84,6 +99,7 @@ config SND_MESON_AXG_SPDIFOUT config SND_MESON_AXG_SPDIFIN tristate "Amlogic AXG SPDIF Input Support" + select REGMAP_MMIO imply SND_SOC_SPDIF help Select Y or M to add support for SPDIF input embedded @@ -91,6 +107,7 @@ config SND_MESON_AXG_SPDIFIN config SND_MESON_AXG_PDM tristate "Amlogic AXG PDM Input Support" + select REGMAP_MMIO imply SND_SOC_DMIC imply COMMON_CLK_AXG_AUDIO help @@ -108,6 +125,7 @@ config SND_MESON_GX_SOUND_CARD tristate "Amlogic GX Sound Card Support" select SND_MESON_CARD_UTILS imply SND_MESON_AIU + imply SND_MESON_AUDIN help Select Y or M to add support for the GXBB/GXL SoC sound card diff --git a/sound/soc/meson/Makefile b/sound/soc/meson/Makefile index f9ec0ebb01f048..4af75df0d19b0e 100644 --- a/sound/soc/meson/Makefile +++ b/sound/soc/meson/Makefile @@ -4,12 +4,15 @@ snd-soc-meson-aiu-y := aiu.o snd-soc-meson-aiu-y += aiu-acodec-ctrl.o snd-soc-meson-aiu-y += aiu-codec-ctrl.o snd-soc-meson-aiu-y += aiu-encoder-i2s.o -snd-soc-meson-aiu-y += gx-formatter.o snd-soc-meson-aiu-y += aiu-formatter-i2s.o snd-soc-meson-aiu-y += aiu-encoder-spdif.o snd-soc-meson-aiu-y += aiu-fifo.o snd-soc-meson-aiu-y += aiu-fifo-i2s.o snd-soc-meson-aiu-y += aiu-fifo-spdif.o +snd-soc-meson-gx-formatter-y := gx-formatter.o +snd-soc-meson-audin-y := audin.o +snd-soc-meson-audin-y += audin-formatter-i2s.o +snd-soc-meson-audin-y += audin-fifo.o snd-soc-meson-axg-fifo-y := axg-fifo.o snd-soc-meson-axg-frddr-y := axg-frddr.o snd-soc-meson-axg-toddr-y := axg-toddr.o @@ -29,6 +32,8 @@ snd-soc-meson-g12a-tohdmitx-y := g12a-tohdmitx.o snd-soc-meson-t9015-y := t9015.o obj-$(CONFIG_SND_MESON_AIU) += snd-soc-meson-aiu.o +obj-$(CONFIG_SND_MESON_GX_FORMATTER) += snd-soc-meson-gx-formatter.o +obj-$(CONFIG_SND_MESON_AUDIN) += snd-soc-meson-audin.o obj-$(CONFIG_SND_MESON_AXG_FIFO) += snd-soc-meson-axg-fifo.o obj-$(CONFIG_SND_MESON_AXG_FRDDR) += snd-soc-meson-axg-frddr.o obj-$(CONFIG_SND_MESON_AXG_TODDR) += snd-soc-meson-axg-toddr.o diff --git a/sound/soc/meson/aiu-encoder-i2s.c b/sound/soc/meson/aiu-encoder-i2s.c index 58dce9f08c9dcb..70ea39c77b3253 100644 --- a/sound/soc/meson/aiu-encoder-i2s.c +++ b/sound/soc/meson/aiu-encoder-i2s.c @@ -219,16 +219,14 @@ static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct gx_stream *ts = snd_soc_dai_get_dma_data(dai, substream); + struct gx_stream *other = snd_soc_dai_dma_data_get(dai, !substream->stream); struct snd_soc_component *component = dai->component; - /* - * If this is the last substream being closed then disable the i2s - * clock divider. - */ - if (snd_soc_dai_active(dai) <= 1) - aiu_encoder_i2s_divider_enable(component, 0); - if (ts->clk_enabled) { + /* Disable the clk divider only if also the other stream is not using it */ + if (!other || !other->clk_enabled) + aiu_encoder_i2s_divider_enable(component, false); + clk_disable_unprepare(ts->iface->mclk); ts->clk_enabled = false; } diff --git a/sound/soc/meson/aiu-fifo-i2s.c b/sound/soc/meson/aiu-fifo-i2s.c index eccbc16b293ade..8f785241585df2 100644 --- a/sound/soc/meson/aiu-fifo-i2s.c +++ b/sound/soc/meson/aiu-fifo-i2s.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -48,14 +49,22 @@ static int aiu_fifo_i2s_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { struct snd_soc_component *component = dai->component; + unsigned int val; + int ret; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - snd_soc_component_write(component, AIU_RST_SOFT, - AIU_RST_SOFT_I2S_FAST); - snd_soc_component_read(component, AIU_I2S_SYNC); + ret = regmap_write(component->regmap, AIU_RST_SOFT, AIU_RST_SOFT_I2S_FAST); + if (ret < 0) + return snd_soc_ret(component->dev, ret, + "Failed to write register on trigger"); + + ret = regmap_read(component->regmap, AIU_I2S_SYNC, &val); + if (ret < 0) + return snd_soc_ret(component->dev, ret, + "Failed to read register on trigger"); break; } diff --git a/sound/soc/meson/aiu-fifo-spdif.c b/sound/soc/meson/aiu-fifo-spdif.c index a9861c5d663745..297834bce1c7a8 100644 --- a/sound/soc/meson/aiu-fifo-spdif.c +++ b/sound/soc/meson/aiu-fifo-spdif.c @@ -69,15 +69,21 @@ static int fifo_spdif_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - snd_soc_component_write(component, AIU_RST_SOFT, - AIU_RST_SOFT_958_FAST); + ret = regmap_write(component->regmap, AIU_RST_SOFT, AIU_RST_SOFT_958_FAST); + if (ret < 0) + return snd_soc_ret(component->dev, ret, + "Failed to write register on trigger"); + fifo_spdif_dcu_enable(component, true); break; case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: - snd_soc_component_write(component, AIU_RST_SOFT, - AIU_RST_SOFT_958_FAST); + ret = regmap_write(component->regmap, AIU_RST_SOFT, AIU_RST_SOFT_958_FAST); + if (ret < 0) + return snd_soc_ret(component->dev, ret, + "Failed to write register on trigger"); + fifo_spdif_dcu_enable(component, false); break; default: diff --git a/sound/soc/meson/aiu-fifo.c b/sound/soc/meson/aiu-fifo.c index 8b54f9681d00c1..edb47095c059d4 100644 --- a/sound/soc/meson/aiu-fifo.c +++ b/sound/soc/meson/aiu-fifo.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,7 @@ snd_pcm_uframes_t aiu_fifo_pointer(struct snd_soc_component *component, struct snd_pcm_runtime *runtime = substream->runtime; unsigned int addr; - addr = snd_soc_component_read(component, fifo->mem_offset + AIU_MEM_RD); + regmap_read(component->regmap, fifo->mem_offset + AIU_MEM_RD, &addr); return bytes_to_frames(runtime, addr - (unsigned int)runtime->dma_addr); } diff --git a/sound/soc/meson/aiu.c b/sound/soc/meson/aiu.c index 535fbf7c163941..7be288cbdec619 100644 --- a/sound/soc/meson/aiu.c +++ b/sound/soc/meson/aiu.c @@ -153,6 +153,13 @@ static struct snd_soc_dai_driver aiu_cpu_dai_drv[] = { .rates = SNDRV_PCM_RATE_8000_192000, .formats = AIU_FORMATS, }, + .capture = { + .stream_name = "I2S Encoder Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_8000_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, .ops = &aiu_encoder_i2s_dai_ops, .symmetric_rate = 1, }, @@ -195,7 +202,7 @@ static int aiu_clk_bulk_get(struct device *dev, struct clk_bulk_data *clks; int i, ret; - clks = devm_kcalloc(dev, num, sizeof(*clks), GFP_KERNEL); + clks = devm_kzalloc_objs(dev, *clks, num); if (!clks) return -ENOMEM; @@ -260,7 +267,7 @@ static int aiu_probe(struct platform_device *pdev) struct aiu *aiu; int ret; - aiu = devm_kzalloc(dev, sizeof(*aiu), GFP_KERNEL); + aiu = devm_kzalloc_obj(dev, *aiu); if (!aiu) return -ENOMEM; diff --git a/sound/soc/meson/audin-fifo.c b/sound/soc/meson/audin-fifo.c new file mode 100644 index 00000000000000..5b254c90c71007 --- /dev/null +++ b/sound/soc/meson/audin-fifo.c @@ -0,0 +1,392 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2026 BayLibre, SAS. +// Author: Valerio Setti + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "audin.h" + +/* FIFO registers */ +#define AUDIN_FIFO_START 0x00 +#define AUDIN_FIFO_END 0x04 +#define AUDIN_FIFO_PTR 0x08 + +/* FIFOx_CTRL1 registers and bits */ +#define AUDIN_FIFO_CTRL1 0x18 +#define AUDIN_FIFO_CTRL1_DIN_BYTE_NUM_MASK GENMASK(3, 2) +#define AUDIN_FIFO_CTRL1_DIN_POS_01_MASK GENMASK(1, 0) + +/* When the FIFO is full the data is bulk transferred to memory. */ +#define AUDIN_FIFO_LANE_SIZE 8 /* bytes */ +#define AUDIN_FIFO_I2S_BLOCK (AUDIN_FIFO_LANE_SIZE * 32) /* 256 bytes */ + +static const struct snd_pcm_hardware audin_fifo_pcm_hw = { + .info = (SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_PAUSE), + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .rate_min = 5512, + .rate_max = 192000, + .channels_min = 2, + .channels_max = 2, + /* + * The FIFO only moves data to the memory once it is full, so its pointer + * progresses one block at a time. + */ + .period_bytes_min = 2 * AUDIN_FIFO_I2S_BLOCK, + .period_bytes_max = UINT_MAX, /* Bounded by buffer_bytes_max */ + .periods_min = 2, + .periods_max = UINT_MAX, + /* + * It's 1 MB. There is no physical constraint for this; it's only meant to + * provide some decently large buffer size where to store incoming data + * and fit various period_bytes requests. + */ + .buffer_bytes_max = 4096 * AUDIN_FIFO_I2S_BLOCK, +}; + +struct audin_fifo_dai_data { + /* + * The AUDIN peripheral has an IRQ to signal when data is received, but + * it cannot grant a periodic behavior. The reason is that the register + * which holds the address which triggers the IRQ must be updated + * continuously. This creates a risk of overflow if for any reason the + * ISR execution is delayed. Using a periodic timer is therefore simpler + * and more reliable. + */ + struct hrtimer polling_timer; + struct snd_soc_dai *dai; + struct snd_pcm_substream *substream; + unsigned int period_bytes; + unsigned int byte_rate; + unsigned int last_pos; /* Position inside the allocated read buffer. */ + bool running; +}; + +static unsigned int audin_fifo_pos(struct snd_soc_dai *dai, + struct snd_pcm_runtime *runtime) +{ + unsigned int ptr = lower_32_bits(runtime->dma_addr); + + regmap_read(dai->component->regmap, dai->driver->base + AUDIN_FIFO_PTR, &ptr); + + return ptr - lower_32_bits(runtime->dma_addr); +} + +static ktime_t audin_fifo_bytes_to_ns(struct audin_fifo_dai_data *data, + unsigned int bytes) +{ + return div_u64((u64)bytes * NSEC_PER_SEC, data->byte_rate); +} + +static int audin_fifo_dai_trigger(struct snd_pcm_substream *substream, int cmd, + struct snd_soc_dai *dai) +{ + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai); + struct snd_soc_component *component = dai->component; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_EN, + AUDIN_FIFO_CTRL_EN); + WRITE_ONCE(data->running, true); + hrtimer_start(&data->polling_timer, + audin_fifo_bytes_to_ns(data, data->period_bytes), + HRTIMER_MODE_REL_SOFT); + break; + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_STOP: + WRITE_ONCE(data->running, false); + /* + * PCM stream lock is held here so we cannot call hrtimer_cancel() + * which might block if timer's callback is running. Timer is + * properly stopped in sync_stop() and shutdown() callbacks. + */ + hrtimer_try_to_cancel(&data->polling_timer); + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_EN, 0); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int audin_fifo_dai_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai); + struct snd_soc_component *component = dai->component; + struct snd_pcm_runtime *runtime = substream->runtime; + dma_addr_t dma_end = runtime->dma_addr + runtime->dma_bytes - AUDIN_FIFO_LANE_SIZE; + unsigned int val; + + data->last_pos = 0; + + /* + * Setup memory boundaries. + * Note: DMA has a 32-bit mask, so it's OK to take lower 32 bits. + */ + snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_START, + lower_32_bits(runtime->dma_addr)); + snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_PTR, + lower_32_bits(runtime->dma_addr)); + snd_soc_component_write(component, dai->driver->base + AUDIN_FIFO_END, + lower_32_bits(dma_end)); + + /* Load new addresses (both LOAD and UG are self-clearing). */ + val = AUDIN_FIFO_CTRL_LOAD | AUDIN_FIFO_CTRL_UG; + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, val, val); + + /* Reset (RST is self-clearing). */ + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_RST, + AUDIN_FIFO_CTRL_RST); + + return 0; +} + +static int audin_fifo_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct snd_soc_component *component = dai->component; + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai); + unsigned int val; + + /* + * The I2S input decoder passes 24 bits of left-justified data + * but for the time being we only support 16 bit formatted samples + * which means that we drop the LSB. + */ + val = FIELD_PREP(AUDIN_FIFO_CTRL1_DIN_POS_01_MASK, 1); + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL1, + AUDIN_FIFO_CTRL1_DIN_POS_01_MASK, + val); + + /* Set sample size to 2 bytes (16 bit) */ + val = FIELD_PREP(AUDIN_FIFO_CTRL1_DIN_BYTE_NUM_MASK, 1); + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL1, + AUDIN_FIFO_CTRL1_DIN_BYTE_NUM_MASK, + val); + + /* + * This is a bit counterintuitive. Even though the platform has a single + * pin for I2S input which would mean that we can only support 2 + * channels, doing so would cause samples to be stored in a weird way + * into the FIFO: all the samples from the 1st channel on the 1st half + * of the FIFO, then samples from the 2nd channel in the other half. Of + * course extra work would be required to properly interleave them + * before returning to the userspace. + * Setting a single channel mode instead solves the problem: samples + * from 1st and 2nd channel are stored interleaved and sequentially in + * the FIFO. + */ + val = FIELD_PREP(AUDIN_FIFO_CTRL_CHAN_MASK, 1); + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_CHAN_MASK, val); + + /* + * FIFO is filled line by line and each of them is 8 bytes. The + * problem is that each line is filled starting from the end, + * so we need to properly reorder them before moving to the + * RAM. This is the value required to properly re-order samples stored + * in 16 bit format. + */ + val = FIELD_PREP(AUDIN_FIFO_CTRL_ENDIAN_MASK, 6); + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_ENDIAN_MASK, val); + + /* Used by the polling timer to convert a byte count into a delay. */ + data->period_bytes = params_period_bytes(params); + data->byte_rate = params_rate(params) * params_channels(params) * + params_physical_width(params) / BITS_PER_BYTE; + + data->substream = substream; + + return 0; +} + +static int audin_fifo_dai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + int ret; + + snd_soc_set_runtime_hwparams(substream, &audin_fifo_pcm_hw); + + ret = snd_pcm_hw_constraint_step(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, + AUDIN_FIFO_I2S_BLOCK); + if (ret < 0) { + dev_err(dai->dev, "Failed to set constraint on buffer_bytes %d\n", ret); + return ret; + } + + ret = snd_pcm_hw_constraint_step(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, + AUDIN_FIFO_I2S_BLOCK); + if (ret < 0) { + dev_err(dai->dev, "Failed to set constraint on period_bytes %d\n", ret); + return ret; + } + + return 0; +} + +static void audin_fifo_dai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai); + + hrtimer_cancel(&data->polling_timer); +} + +static int audin_fifo_dai_pcm_new(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_dai *dai) +{ + int ret; + + ret = dma_coerce_mask_and_coherent(dai->dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(dai->dev, "Failed to set DMA mask %d\n", ret); + return ret; + } + + ret = snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, + dai->dev, + audin_fifo_pcm_hw.buffer_bytes_max, + audin_fifo_pcm_hw.buffer_bytes_max); + if (ret) { + dev_err(dai->dev, "Failed to set PCM managed buffer %d\n", ret); + return ret; + } + + return 0; +} + +static enum hrtimer_restart audin_fifo_timer_cb(struct hrtimer *timer) +{ + struct audin_fifo_dai_data *data = + container_of(timer, struct audin_fifo_dai_data, polling_timer); + struct snd_pcm_substream *substream = data->substream; + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned int curr_pos; + unsigned int delta, elapsed_periods_bytes, extra_bytes, sleep_bytes; + + /* + * Take the stream lock to prevent userspace from issuing a quick + * PAUSE_PUSH -> PAUSE_RELEASE transition while we're running this + * callback. Doing so would cause "hrtimer_forward_now()" to be called + * (see below) while the timer is already enqueued. + */ + guard(pcm_stream_lock_irqsave)(substream); + + /* Stopped, or a trigger already re-armed the timer while we waited. */ + if (!READ_ONCE(data->running) || hrtimer_is_queued(timer)) + return HRTIMER_NORESTART; + + curr_pos = audin_fifo_pos(data->dai, runtime); + delta = (curr_pos >= data->last_pos) ? + curr_pos - data->last_pos : + (runtime->dma_bytes - data->last_pos) + curr_pos; + extra_bytes = delta % data->period_bytes; + elapsed_periods_bytes = delta - extra_bytes; + + /* Report only when the period is completed. */ + if (delta >= data->period_bytes) { + data->last_pos = data->last_pos + elapsed_periods_bytes; + if (data->last_pos >= runtime->dma_bytes) + data->last_pos %= runtime->dma_bytes; + snd_pcm_period_elapsed_under_stream_lock(substream); + } + + /* Reporting the period might stop the stream on XRUN. */ + if (!READ_ONCE(data->running)) + return HRTIMER_NORESTART; + + /* Sleep until the period is completed. */ + sleep_bytes = round_up(data->period_bytes - extra_bytes, AUDIN_FIFO_I2S_BLOCK); + hrtimer_forward_now(timer, audin_fifo_bytes_to_ns(data, sleep_bytes)); + + return HRTIMER_RESTART; +} + +static int audin_fifo_dai_probe(struct snd_soc_dai *dai) +{ + struct audin_fifo_dai_data *data; + + data = kzalloc_obj(*data); + if (!data) + return -ENOMEM; + + data->dai = dai; + + hrtimer_setup(&data->polling_timer, audin_fifo_timer_cb, CLOCK_MONOTONIC, + HRTIMER_MODE_REL_SOFT); + + snd_soc_dai_dma_data_set_capture(dai, data); + + return 0; +} + +static int audin_fifo_dai_remove(struct snd_soc_dai *dai) +{ + kfree(snd_soc_dai_dma_data_get_capture(dai)); + + return 0; +} + +const struct snd_soc_dai_ops audin_fifo_dai_ops = { + .trigger = audin_fifo_dai_trigger, + .prepare = audin_fifo_dai_prepare, + .hw_params = audin_fifo_dai_hw_params, + .startup = audin_fifo_dai_startup, + .shutdown = audin_fifo_dai_shutdown, + .pcm_new = audin_fifo_dai_pcm_new, + .probe = audin_fifo_dai_probe, + .remove = audin_fifo_dai_remove, +}; + +snd_pcm_uframes_t audin_fifo_component_pointer(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); + + return bytes_to_frames(runtime, audin_fifo_pos(dai, runtime)); +} + +/* + * sync_stop() is called before hw_params(), hw_free(), suspend(), prepare(). + * Cancelling the hrtimer here ensures the timer is really stopped even in + * case the stream is run->stop->prepare->start. + */ +int audin_fifo_sync_stop(struct snd_soc_component *component, struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai); + + hrtimer_cancel(&data->polling_timer); + WRITE_ONCE(data->running, false); + + return 0; +} diff --git a/sound/soc/meson/audin-formatter-i2s.c b/sound/soc/meson/audin-formatter-i2s.c new file mode 100644 index 00000000000000..8bbb5cdb52dc83 --- /dev/null +++ b/sound/soc/meson/audin-formatter-i2s.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2026 BayLibre, SAS. +// Author: Valerio Setti + +#include +#include +#include +#include + +#include "audin.h" +#include "gx-formatter.h" + +/* I2SIN_CTRL register and bits */ +#define AUDIN_I2SIN_CTRL 0x40 +#define AUDIN_I2SIN_CTRL_I2SIN_DIR BIT(0) +#define AUDIN_I2SIN_CTRL_I2SIN_CLK_SEL BIT(1) +#define AUDIN_I2SIN_CTRL_I2SIN_LRCLK_SEL BIT(2) +#define AUDIN_I2SIN_CTRL_I2SIN_BCLK_INV BIT(3) +#define AUDIN_I2SIN_CTRL_I2SIN_LRCLK_SKEW_MASK GENMASK(6, 4) +#define AUDIN_I2SIN_CTRL_I2SIN_LRCLK_INV BIT(7) +#define AUDIN_I2SIN_CTRL_I2SIN_SIZE_MASK GENMASK(9, 8) +#define AUDIN_I2SIN_CTRL_I2SIN_CHAN_EN_MASK GENMASK(13, 10) +#define AUDIN_I2SIN_CTRL_I2SIN_EN BIT(15) + +static struct snd_soc_dai * +audin_formatter_i2s_get_be(struct snd_soc_dapm_widget *w) +{ + struct snd_soc_dapm_path *p; + struct snd_soc_dai *be; + + snd_soc_dapm_widget_for_each_source_path(w, p) { + if (!p->connect) + continue; + + if (p->source->id == snd_soc_dapm_dai_out) + return (struct snd_soc_dai *)p->source->priv; + + be = audin_formatter_i2s_get_be(p->source); + if (be) + return be; + } + + return NULL; +} + +static struct gx_stream * +audin_formatter_i2s_get_stream(struct snd_soc_dapm_widget *w) +{ + struct snd_soc_dai *be = audin_formatter_i2s_get_be(w); + + if (!be) + return NULL; + + return snd_soc_dai_dma_data_get_capture(be); +} + +static void audin_formatter_i2s_enable(struct regmap *map) +{ + regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_EN, + AUDIN_I2SIN_CTRL_I2SIN_EN); +} + +static void audin_formatter_i2s_disable(struct regmap *map) +{ + regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_EN, 0); +} + +static int audin_formatter_i2s_prepare(struct regmap *map, + const struct gx_formatter_hw *quirks, + struct gx_stream *ts) +{ + unsigned int val; + int ret; + + /* + * I2S decoder always outputs 24 bits to the FIFO according to the + * manual. The only thing we can change through + * AUDIN_I2SIN_CTRL_I2SIN_SIZE_MASK is the following: + * - 0 -> output[23:0] = {original[23:8],8’d0} + * - 1 -> output[23:0] = {original[23:6],6’d0} + * - 2 -> output[23:0] = {original[23:4],4’d0} + * - 3 -> output[23:0] = {original[23:0]} + * + * We use 3 here and, in case of 16 bit format, we filter unnecessary + * bytes at FIFO stage. + * Note: data is left-justified, so in case of 16 bits samples, this + * means that the LSB is to be discarded at FIFO level and the + * relevant part is in bits [23:8]. + */ + val = FIELD_PREP(AUDIN_I2SIN_CTRL_I2SIN_SIZE_MASK, 3); + ret = regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_SIZE_MASK, val); + if (ret) + return ret; + + /* + * The manual claims that this platform supports up to 4 streams + * (8 channels), but currently only 1 stream (2 channels) has been + * tested and it's supported. + */ + val = FIELD_PREP(AUDIN_I2SIN_CTRL_I2SIN_CHAN_EN_MASK, 1); + ret = regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_CHAN_EN_MASK, val); + if (ret) + return ret; + + /* + * Use clocks from AIU and not from the pads since we only want to + * support master mode. + */ + val = AUDIN_I2SIN_CTRL_I2SIN_CLK_SEL | + AUDIN_I2SIN_CTRL_I2SIN_LRCLK_SEL | + AUDIN_I2SIN_CTRL_I2SIN_DIR; + ret = regmap_update_bits(map, AUDIN_I2SIN_CTRL, val, val); + if (ret) + return ret; + + switch (ts->iface->fmt & SND_SOC_DAIFMT_INV_MASK) { + case SND_SOC_DAIFMT_IB_NF: + val = AUDIN_I2SIN_CTRL_I2SIN_BCLK_INV; + break; + case SND_SOC_DAIFMT_NB_IF: + val = AUDIN_I2SIN_CTRL_I2SIN_LRCLK_INV; + break; + case SND_SOC_DAIFMT_IB_IF: + val = AUDIN_I2SIN_CTRL_I2SIN_BCLK_INV | AUDIN_I2SIN_CTRL_I2SIN_LRCLK_INV; + break; + case SND_SOC_DAIFMT_NB_NF: + val = 0; + break; + default: + return -EINVAL; + } + + ret = regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_LRCLK_INV | + AUDIN_I2SIN_CTRL_I2SIN_BCLK_INV, val); + if (ret) + return ret; + + switch (ts->iface->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + val = 1; + break; + case SND_SOC_DAIFMT_LEFT_J: + val = 0; + break; + default: + return -EINVAL; + } + + val = FIELD_PREP(AUDIN_I2SIN_CTRL_I2SIN_LRCLK_SKEW_MASK, val); + ret = regmap_update_bits(map, AUDIN_I2SIN_CTRL, + AUDIN_I2SIN_CTRL_I2SIN_LRCLK_SKEW_MASK, + val); + if (ret) + return ret; + + return 0; +} + +static const struct gx_formatter_ops audin_formatter_i2s_ops = { + .get_stream = audin_formatter_i2s_get_stream, + .prepare = audin_formatter_i2s_prepare, + .enable = audin_formatter_i2s_enable, + .disable = audin_formatter_i2s_disable, +}; + +const struct gx_formatter_driver audin_formatter_i2s_drv = { + .ops = &audin_formatter_i2s_ops, +}; diff --git a/sound/soc/meson/audin.c b/sound/soc/meson/audin.c new file mode 100644 index 00000000000000..808e7d4fd31a25 --- /dev/null +++ b/sound/soc/meson/audin.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2026 BayLibre, SAS. +// Author: Valerio Setti + +#include +#include +#include +#include +#include +#include + +#include "audin.h" +#include "gx-formatter.h" + +#define AUDIN_FIFO0_BASE 0x80 +#define AUDIN_FIFO1_BASE 0xCC +#define AUDIN_FIFO2_BASE 0x114 + +static const char * const audin_fifo_input_sel_texts[] = { + "SPDIF", "I2S", "PCM", "HDMI", "Demodulator" +}; + +static SOC_ENUM_SINGLE_DECL(audin_fifo0_input_sel_enum, AUDIN_FIFO0_BASE + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_DIN_SEL_OFF, + audin_fifo_input_sel_texts); +static SOC_ENUM_SINGLE_DECL(audin_fifo1_input_sel_enum, AUDIN_FIFO1_BASE + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_DIN_SEL_OFF, + audin_fifo_input_sel_texts); +static SOC_ENUM_SINGLE_DECL(audin_fifo2_input_sel_enum, AUDIN_FIFO2_BASE + AUDIN_FIFO_CTRL, + AUDIN_FIFO_CTRL_DIN_SEL_OFF, + audin_fifo_input_sel_texts); + +static const struct snd_kcontrol_new audin_fifo0_input_sel_mux = + SOC_DAPM_ENUM("FIFO0 Input Source", audin_fifo0_input_sel_enum); +static const struct snd_kcontrol_new audin_fifo1_input_sel_mux = + SOC_DAPM_ENUM("FIFO1 Input Source", audin_fifo1_input_sel_enum); +static const struct snd_kcontrol_new audin_fifo2_input_sel_mux = + SOC_DAPM_ENUM("FIFO2 Input Source", audin_fifo2_input_sel_enum); + +#define AUDIN_WIDGET_I2S_FORMATTER 0 + +static struct snd_soc_dapm_widget audin_dapm_widgets[] = { + [AUDIN_WIDGET_I2S_FORMATTER] = + SND_SOC_DAPM_PGA_E("I2S Formatter", SND_SOC_NOPM, 0, 0, NULL, 0, + gx_formatter_event, + (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD)), + SND_SOC_DAPM_MUX("FIFO0 SRC SEL", SND_SOC_NOPM, 0, 0, + &audin_fifo0_input_sel_mux), + SND_SOC_DAPM_MUX("FIFO1 SRC SEL", SND_SOC_NOPM, 0, 0, + &audin_fifo1_input_sel_mux), + SND_SOC_DAPM_MUX("FIFO2 SRC SEL", SND_SOC_NOPM, 0, 0, + &audin_fifo2_input_sel_mux), +}; + +static const struct snd_soc_dapm_route audin_dapm_routes[] = { + { "FIFO0 SRC SEL", "I2S", "I2S Formatter" }, + { "FIFO0 Capture", NULL, "FIFO0 SRC SEL" }, + { "FIFO1 SRC SEL", "I2S", "I2S Formatter" }, + { "FIFO1 Capture", NULL, "FIFO1 SRC SEL" }, + { "FIFO2 SRC SEL", "I2S", "I2S Formatter" }, + { "FIFO2 Capture", NULL, "FIFO2 SRC SEL" }, +}; + +static struct snd_soc_dai_driver audin_dai_drv[] = { + { + .name = "FIFO0", + .base = AUDIN_FIFO0_BASE, + .capture = { + .stream_name = "FIFO0 Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 5512, + .rate_max = 192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .ops = &audin_fifo_dai_ops, + }, + { + .name = "FIFO1", + .base = AUDIN_FIFO1_BASE, + .capture = { + .stream_name = "FIFO1 Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 5512, + .rate_max = 192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .ops = &audin_fifo_dai_ops, + }, + { + .name = "FIFO2", + .base = AUDIN_FIFO2_BASE, + .capture = { + .stream_name = "FIFO2 Capture", + .channels_min = 2, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 5512, + .rate_max = 192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + .ops = &audin_fifo_dai_ops, + }, +}; + +static const struct snd_soc_component_driver audin_component = { + .dapm_widgets = audin_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(audin_dapm_widgets), + .dapm_routes = audin_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(audin_dapm_routes), + .pointer = audin_fifo_component_pointer, + .sync_stop = audin_fifo_sync_stop, +}; + +static const struct regmap_config audin_regmap_cfg = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .max_register = 0x148, +}; + +static int audin_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + void __iomem *mmio; + struct regmap *regmap; + struct clk *clk; + int ret; + + ret = device_reset(dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to reset device\n"); + + mmio = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(mmio)) + return dev_err_probe(dev, PTR_ERR(mmio), "Failed to ioremap memory\n"); + + regmap = devm_regmap_init_mmio(dev, mmio, &audin_regmap_cfg); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "Failed to init regmap\n"); + + clk = devm_clk_get_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n"); + + ret = gx_formatter_create(dev, &audin_dapm_widgets[AUDIN_WIDGET_I2S_FORMATTER], + &audin_formatter_i2s_drv, regmap); + if (ret) + return dev_err_probe(dev, ret, "Failed to allocate formatter\n"); + + ret = devm_snd_soc_register_component(dev, &audin_component, + audin_dai_drv, ARRAY_SIZE(audin_dai_drv)); + if (ret) { + gx_formatter_free(&audin_dapm_widgets[AUDIN_WIDGET_I2S_FORMATTER]); + return dev_err_probe(dev, ret, "Failed to register component\n"); + } + + return 0; +} + +static void audin_remove(struct platform_device *pdev) +{ + gx_formatter_free(&audin_dapm_widgets[AUDIN_WIDGET_I2S_FORMATTER]); +} + +static const struct of_device_id audin_of_match[] = { + { .compatible = "amlogic,gxbb-audin" }, + { } +}; +MODULE_DEVICE_TABLE(of, audin_of_match); + +static struct platform_driver audin_driver = { + .driver = { + .name = "gx-audin", + .of_match_table = audin_of_match, + }, + .probe = audin_probe, + .remove = audin_remove, +}; +module_platform_driver(audin_driver); + +MODULE_DESCRIPTION("Meson GX AUDIN driver"); +MODULE_AUTHOR("Valerio Setti "); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/meson/audin.h b/sound/soc/meson/audin.h new file mode 100644 index 00000000000000..7f3b58a780c01b --- /dev/null +++ b/sound/soc/meson/audin.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ +/* + * Copyright (c) 2026 BayLibre, SAS. + * Author: Valerio Setti + */ + +#ifndef _MESON_AUDIN_H +#define _MESON_AUDIN_H + +#include "gx-formatter.h" + +/* FIFOx CTRL registers and bits */ +#define AUDIN_FIFO_CTRL 0x14 +#define AUDIN_FIFO_CTRL_EN BIT(0) +#define AUDIN_FIFO_CTRL_RST BIT(1) +#define AUDIN_FIFO_CTRL_LOAD BIT(2) +#define AUDIN_FIFO_CTRL_DIN_SEL_OFF 3 +#define AUDIN_FIFO_CTRL_ENDIAN_MASK GENMASK(10, 8) +#define AUDIN_FIFO_CTRL_CHAN_MASK GENMASK(14, 11) +#define AUDIN_FIFO_CTRL_UG BIT(15) + +extern const struct gx_formatter_driver audin_formatter_i2s_drv; + +extern const struct snd_soc_dai_ops audin_fifo_dai_ops; +extern snd_pcm_uframes_t audin_fifo_component_pointer(struct snd_soc_component *component, + struct snd_pcm_substream *substream); +extern int audin_fifo_sync_stop(struct snd_soc_component *component, + struct snd_pcm_substream *substream); + +#endif diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c index c36f727af4ba0b..540dd51fd898a8 100644 --- a/sound/soc/meson/axg-card.c +++ b/sound/soc/meson/axg-card.c @@ -122,7 +122,7 @@ static int axg_card_add_tdm_loopback(struct snd_soc_card *card, if (!lb->name) return -ENOMEM; - dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_obj(dev, *dlc); if (!dlc) return -ENOMEM; @@ -164,10 +164,8 @@ static int axg_card_parse_cpu_tdm_slots(struct snd_soc_card *card, u32 tx, rx; int i; - be->tx_mask = devm_kcalloc(dev, AXG_TDM_NUM_LANES, - sizeof(*be->tx_mask), GFP_KERNEL); - be->rx_mask = devm_kcalloc(dev, AXG_TDM_NUM_LANES, - sizeof(*be->rx_mask), GFP_KERNEL); + be->tx_mask = devm_kzalloc_objs(dev, *be->tx_mask, AXG_TDM_NUM_LANES); + be->rx_mask = devm_kzalloc_objs(dev, *be->rx_mask, AXG_TDM_NUM_LANES); if (!be->tx_mask || !be->rx_mask) return -ENOMEM; @@ -226,8 +224,7 @@ static int axg_card_parse_codecs_masks(struct snd_soc_card *card, struct axg_dai_link_tdm_mask *codec_mask; struct device *dev = card->dev; - codec_mask = devm_kcalloc(dev, link->num_codecs, - sizeof(*codec_mask), GFP_KERNEL); + codec_mask = devm_kzalloc_objs(dev, *codec_mask, link->num_codecs); if (!codec_mask) return -ENOMEM; @@ -256,7 +253,7 @@ static int axg_card_parse_tdm(struct snd_soc_card *card, int ret; /* Allocate tdm link parameters */ - be = devm_kzalloc(dev, sizeof(*be), GFP_KERNEL); + be = devm_kzalloc_obj(dev, *be); if (!be) return -ENOMEM; priv->link_data[*index] = be; @@ -317,7 +314,7 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np, struct device *dev = card->dev; int ret; - cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL); + cpu = devm_kzalloc_obj(dev, *cpu); if (!cpu) return -ENOMEM; diff --git a/sound/soc/meson/axg-fifo.c b/sound/soc/meson/axg-fifo.c index edf43b7fb5cf5e..0191cfeb2ddb0f 100644 --- a/sound/soc/meson/axg-fifo.c +++ b/sound/soc/meson/axg-fifo.c @@ -338,7 +338,7 @@ int axg_fifo_probe(struct platform_device *pdev) return -ENODEV; } - fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); + fifo = devm_kzalloc_obj(dev, *fifo); if (!fifo) return -ENOMEM; platform_set_drvdata(pdev, fifo); diff --git a/sound/soc/meson/axg-pdm.c b/sound/soc/meson/axg-pdm.c index d59050914d3cc9..7e54bbb05b3af8 100644 --- a/sound/soc/meson/axg-pdm.c +++ b/sound/soc/meson/axg-pdm.c @@ -589,7 +589,7 @@ static int axg_pdm_probe(struct platform_device *pdev) struct axg_pdm *priv; void __iomem *regs; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/meson/axg-spdifin.c b/sound/soc/meson/axg-spdifin.c index e721f579321ec2..b9c3c6ff59abd7 100644 --- a/sound/soc/meson/axg-spdifin.c +++ b/sound/soc/meson/axg-spdifin.c @@ -410,7 +410,7 @@ axg_spdifin_get_dai_drv(struct device *dev, struct axg_spdifin *priv) struct snd_soc_dai_driver *drv; int i; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return ERR_PTR(-ENOMEM); @@ -441,7 +441,7 @@ static int axg_spdifin_probe(struct platform_device *pdev) struct snd_soc_dai_driver *dai_drv; void __iomem *regs; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/meson/axg-spdifout.c b/sound/soc/meson/axg-spdifout.c index 84868fe574e0aa..e2374ea16ffc6e 100644 --- a/sound/soc/meson/axg-spdifout.c +++ b/sound/soc/meson/axg-spdifout.c @@ -405,7 +405,7 @@ static int axg_spdifout_probe(struct platform_device *pdev) struct axg_spdifout *priv; void __iomem *regs; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/meson/axg-tdm-formatter.c b/sound/soc/meson/axg-tdm-formatter.c index a6ba401104d522..744c08f419527a 100644 --- a/sound/soc/meson/axg-tdm-formatter.c +++ b/sound/soc/meson/axg-tdm-formatter.c @@ -270,7 +270,7 @@ int axg_tdm_formatter_probe(struct platform_device *pdev) return -ENODEV; } - formatter = devm_kzalloc(dev, sizeof(*formatter), GFP_KERNEL); + formatter = devm_kzalloc_obj(dev, *formatter); if (!formatter) return -ENOMEM; platform_set_drvdata(pdev, formatter); diff --git a/sound/soc/meson/axg-tdm-interface.c b/sound/soc/meson/axg-tdm-interface.c index d5287d78f53b87..9617bad0b57259 100644 --- a/sound/soc/meson/axg-tdm-interface.c +++ b/sound/soc/meson/axg-tdm-interface.c @@ -530,7 +530,7 @@ static int axg_tdm_iface_probe(struct platform_device *pdev) struct snd_soc_dai_driver *dai_drv; struct axg_tdm_iface *iface; - iface = devm_kzalloc(dev, sizeof(*iface), GFP_KERNEL); + iface = devm_kzalloc_obj(dev, *iface); if (!iface) return -ENOMEM; platform_set_drvdata(pdev, iface); diff --git a/sound/soc/meson/g12a-toacodec.c b/sound/soc/meson/g12a-toacodec.c index 21941ee552c5ce..b3d74419e56ecb 100644 --- a/sound/soc/meson/g12a-toacodec.c +++ b/sound/soc/meson/g12a-toacodec.c @@ -304,7 +304,7 @@ static int g12a_toacodec_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/meson/gx-card.c b/sound/soc/meson/gx-card.c index 932be0a0930639..c99cc7adb92b98 100644 --- a/sound/soc/meson/gx-card.c +++ b/sound/soc/meson/gx-card.c @@ -51,7 +51,7 @@ static int gx_card_parse_i2s(struct snd_soc_card *card, struct device *dev = card->dev; /* Allocate i2s link parameters */ - be = devm_kzalloc(dev, sizeof(*be), GFP_KERNEL); + be = devm_kzalloc_obj(dev, *be); if (!be) return -ENOMEM; priv->link_data[*index] = be; @@ -66,10 +66,10 @@ static int gx_card_parse_i2s(struct snd_soc_card *card, } static int gx_card_cpu_identify(struct snd_soc_dai_link_component *c, - char *match) + const char *compatible_match, const char *dai_match) { - if (of_device_is_compatible(c->of_node, DT_PREFIX "aiu")) { - if (strstr(c->dai_name, match)) + if (of_device_is_compatible(c->of_node, compatible_match)) { + if (strstr(c->dai_name, dai_match)) return 1; } @@ -85,7 +85,7 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, struct device *dev = card->dev; int ret; - cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL); + cpu = devm_kzalloc_obj(dev, *cpu); if (!cpu) return -ENOMEM; @@ -96,21 +96,23 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, if (ret) return ret; - if (gx_card_cpu_identify(dai_link->cpus, "FIFO")) - return meson_card_set_fe_link(card, dai_link, np, true); + if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "aiu", "FIFO")) + return meson_card_set_fe_link(card, dai_link, np, true); + if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "gxbb-audin", "FIFO")) + return meson_card_set_fe_link(card, dai_link, np, false); ret = meson_card_set_be_link(card, dai_link, np); if (ret) return ret; /* Or apply codec to codec params if necessary */ - if (gx_card_cpu_identify(dai_link->cpus, "CODEC CTRL")) { + if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "aiu", "CODEC CTRL")) { dai_link->c2c_params = &codec_params; dai_link->num_c2c_params = 1; } else { dai_link->no_pcm = 1; /* Check if the cpu is the i2s encoder and parse i2s data */ - if (gx_card_cpu_identify(dai_link->cpus, "I2S Encoder")) + if (gx_card_cpu_identify(dai_link->cpus, DT_PREFIX "aiu", "I2S Encoder")) ret = gx_card_parse_i2s(card, np, index); } diff --git a/sound/soc/meson/gx-formatter.c b/sound/soc/meson/gx-formatter.c index 2d3218cce42642..0deda54332753f 100644 --- a/sound/soc/meson/gx-formatter.c +++ b/sound/soc/meson/gx-formatter.c @@ -22,6 +22,8 @@ static int gx_formatter_enable(struct gx_formatter *formatter) { int ret; + lockdep_assert_held(&formatter->stream->lock); + /* Do nothing if the formatter is already enabled */ if (formatter->enabled) return 0; @@ -46,6 +48,8 @@ static int gx_formatter_enable(struct gx_formatter *formatter) static void gx_formatter_disable(struct gx_formatter *formatter) { + lockdep_assert_held(&formatter->stream->lock); + /* Do nothing if the formatter is already disabled */ if (!formatter->enabled) return; @@ -61,7 +65,7 @@ static int gx_formatter_attach(struct gx_formatter *formatter) struct gx_stream *ts = formatter->stream; int ret = 0; - mutex_lock(&ts->lock); + spin_lock_irq(&ts->lock); /* Catch up if the stream is already running when we attach */ if (ts->ready) { @@ -74,7 +78,7 @@ static int gx_formatter_attach(struct gx_formatter *formatter) list_add_tail(&formatter->list, &ts->formatter_list); out: - mutex_unlock(&ts->lock); + spin_unlock_irq(&ts->lock); return ret; } @@ -85,11 +89,10 @@ static void gx_formatter_detach(struct gx_formatter *formatter) if (!ts) return; - mutex_lock(&ts->lock); + spin_lock_irq(&ts->lock); list_del(&formatter->list); - mutex_unlock(&ts->lock); - gx_formatter_disable(formatter); + spin_unlock_irq(&ts->lock); } static int gx_formatter_power_up(struct gx_formatter *formatter, @@ -167,7 +170,7 @@ int gx_formatter_probe(struct platform_device *pdev) return -ENODEV; } - formatter = devm_kzalloc(dev, sizeof(*formatter), GFP_KERNEL); + formatter = devm_kzalloc_obj(dev, *formatter); if (!formatter) return -ENOMEM; platform_set_drvdata(pdev, formatter); @@ -196,7 +199,7 @@ int gx_formatter_create(struct device *dev, { struct gx_formatter *formatter; - formatter = devm_kzalloc(dev, sizeof(*formatter), GFP_KERNEL); + formatter = devm_kzalloc_obj(dev, *formatter); if (!formatter) return -ENOMEM; @@ -212,9 +215,10 @@ EXPORT_SYMBOL_GPL(gx_formatter_create); int gx_stream_start(struct gx_stream *ts) { struct gx_formatter *formatter; + unsigned long irq_flags; int ret = 0; - mutex_lock(&ts->lock); + spin_lock_irqsave(&ts->lock, irq_flags); /* Start all the formatters attached to the stream */ list_for_each_entry(formatter, &ts->formatter_list, list) { @@ -228,7 +232,7 @@ int gx_stream_start(struct gx_stream *ts) ts->ready = true; out: - mutex_unlock(&ts->lock); + spin_unlock_irqrestore(&ts->lock, irq_flags); return ret; } EXPORT_SYMBOL_GPL(gx_stream_start); @@ -236,8 +240,9 @@ EXPORT_SYMBOL_GPL(gx_stream_start); void gx_stream_stop(struct gx_stream *ts) { struct gx_formatter *formatter; + unsigned long irq_flags; - mutex_lock(&ts->lock); + spin_lock_irqsave(&ts->lock, irq_flags); ts->ready = false; /* Stop all the formatters attached to the stream */ @@ -245,7 +250,7 @@ void gx_stream_stop(struct gx_stream *ts) gx_formatter_disable(formatter); } - mutex_unlock(&ts->lock); + spin_unlock_irqrestore(&ts->lock, irq_flags); } EXPORT_SYMBOL_GPL(gx_stream_stop); @@ -256,7 +261,7 @@ struct gx_stream *gx_stream_alloc(struct gx_iface *iface) ts = kzalloc_obj(*ts); if (ts) { INIT_LIST_HEAD(&ts->formatter_list); - mutex_init(&ts->lock); + spin_lock_init(&ts->lock); ts->iface = iface; } @@ -272,7 +277,6 @@ void gx_stream_free(struct gx_stream *ts) * are removing the TDM DAI. It should not be possible */ WARN_ON(!list_empty(&ts->formatter_list)); - mutex_destroy(&ts->lock); kfree(ts); } EXPORT_SYMBOL_GPL(gx_stream_free); diff --git a/sound/soc/meson/gx-formatter.h b/sound/soc/meson/gx-formatter.h index b90b1814d79b49..9f5a1720481e24 100644 --- a/sound/soc/meson/gx-formatter.h +++ b/sound/soc/meson/gx-formatter.h @@ -20,6 +20,10 @@ struct gx_formatter_hw { struct gx_formatter_ops { struct gx_stream *(*get_stream)(struct snd_soc_dapm_widget *w); + /* + * Following functions are called with gx_stream->lock held and local + * IRQs disabled so they must not sleep. + */ void (*enable)(struct regmap *map); void (*disable)(struct regmap *map); int (*prepare)(struct regmap *map, diff --git a/sound/soc/meson/gx-interface.h b/sound/soc/meson/gx-interface.h index 2a6207e393e816..a6a5cc9e7af08b 100644 --- a/sound/soc/meson/gx-interface.h +++ b/sound/soc/meson/gx-interface.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -24,7 +25,7 @@ struct gx_iface { struct gx_stream { struct gx_iface *iface; struct list_head formatter_list; - struct mutex lock; + spinlock_t lock; unsigned int channels; unsigned int width; unsigned int physical_width; diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c index 24332f29047ad6..607112e219a01e 100644 --- a/sound/soc/meson/meson-card-utils.c +++ b/sound/soc/meson/meson-card-utils.c @@ -144,7 +144,7 @@ int meson_card_set_be_link(struct snd_soc_card *card, return -EINVAL; } - codec = devm_kcalloc(dev, num_codecs, sizeof(*codec), GFP_KERNEL); + codec = devm_kzalloc_objs(dev, *codec, num_codecs); if (!codec) return -ENOMEM; @@ -272,7 +272,7 @@ int meson_card_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/meson/t9015.c b/sound/soc/meson/t9015.c index 68b5323ca9c897..8665dc82a113a7 100644 --- a/sound/soc/meson/t9015.c +++ b/sound/soc/meson/t9015.c @@ -257,7 +257,7 @@ static int t9015_probe(struct platform_device *pdev) struct clk *pclk; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index e46896ac9669c5..abdead349a4d08 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -796,7 +796,7 @@ static int mxs_saif_probe(struct platform_device *pdev) int irq, ret; struct device_node *master; - saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); + saif = devm_kzalloc_obj(&pdev->dev, *saif); if (!saif) return -ENOMEM; diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c index eee15a6cf50815..2fd43bb3d89800 100644 --- a/sound/soc/pxa/mmp-sspa.c +++ b/sound/soc/pxa/mmp-sspa.c @@ -480,8 +480,7 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev) struct sspa_priv *sspa; int ret; - sspa = devm_kzalloc(&pdev->dev, - sizeof(struct sspa_priv), GFP_KERNEL); + sspa = devm_kzalloc_obj(&pdev->dev, struct sspa_priv); if (!sspa) return -ENOMEM; diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c index 9a98246ad19ce4..53682c9f2ccc71 100644 --- a/sound/soc/pxa/pxa-ssp.c +++ b/sound/soc/pxa/pxa-ssp.c @@ -772,6 +772,7 @@ static int pxa_ssp_probe(struct snd_soc_dai *dai) priv->extclk = devm_clk_get_optional(dev, "extclk"); if (IS_ERR(priv->extclk)) { ret = PTR_ERR(priv->extclk); + pxa_ssp_free(priv->ssp); goto err_priv; } } else { diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c index 3023cf180a7556..c12b699f975241 100644 --- a/sound/soc/qcom/apq8016_sbc.c +++ b/sound/soc/qcom/apq8016_sbc.c @@ -296,7 +296,7 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev) if (!add_ops) return -EINVAL; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c index cfd6438dbcb300..9a7cdf02f88354 100644 --- a/sound/soc/qcom/apq8096.c +++ b/sound/soc/qcom/apq8096.c @@ -108,7 +108,7 @@ static int apq8096_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index 83b745f617a86a..af5cacddf67dff 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -226,7 +226,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card) num_links = of_get_available_child_count(dev->of_node); /* Allocate the DAI link array */ - card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL); + card->dai_link = devm_kzalloc_objs(dev, *link, num_links); if (!card->dai_link) return -ENOMEM; @@ -234,7 +234,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card) link = card->dai_link; for_each_available_child_of_node_scoped(dev->of_node, np) { - dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_objs(dev, *dlc, 2); if (!dlc) return -ENOMEM; @@ -335,7 +335,11 @@ static struct snd_soc_jack_pin qcom_headset_jack_pins[] = { }, { .pin = "Headphone Jack", - .mask = SND_JACK_HEADPHONE, + /* + * WCD MBHC reports loads above linein_th (5 kOhm) as LINEOUT, + * e.g. active speakers; treat them like headphones for routing. + */ + .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT, }, }; diff --git a/sound/soc/qcom/lpass-apq8016.c b/sound/soc/qcom/lpass-apq8016.c index b8f23414eb7770..d07ef2bb382afd 100644 --- a/sound/soc/qcom/lpass-apq8016.c +++ b/sound/soc/qcom/lpass-apq8016.c @@ -162,8 +162,8 @@ static int apq8016_lpass_init(struct platform_device *pdev) int ret, i; - drvdata->clks = devm_kcalloc(dev, variant->num_clks, - sizeof(*drvdata->clks), GFP_KERNEL); + drvdata->clks = devm_kzalloc_objs(dev, *drvdata->clks, + variant->num_clks); if (!drvdata->clks) return -ENOMEM; drvdata->num_clks = variant->num_clks; diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c index ee187eeb739203..81eebfabcc9f1b 100644 --- a/sound/soc/qcom/lpass-cpu.c +++ b/sound/soc/qcom/lpass-cpu.c @@ -605,7 +605,7 @@ static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) struct lpass_hdmitx_dmactl *tx_dmactl; int rval; - tx_ctl = devm_kzalloc(dev, sizeof(*tx_ctl), GFP_KERNEL); + tx_ctl = devm_kzalloc_obj(dev, *tx_ctl); if (!tx_ctl) return -ENOMEM; @@ -616,7 +616,7 @@ static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) QCOM_REGMAP_FIELD_ALLOC(dev, map, v->legacy_en, legacy_en); drvdata->hdmitx_legacy_en = legacy_en; - vbit_ctl = devm_kzalloc(dev, sizeof(*vbit_ctl), GFP_KERNEL); + vbit_ctl = devm_kzalloc_obj(dev, *vbit_ctl); if (!vbit_ctl) return -ENOMEM; @@ -628,7 +628,7 @@ static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) QCOM_REGMAP_FIELD_ALLOC(dev, map, v->calc_en, tx_parity); drvdata->hdmitx_parity_calc_en = tx_parity; - meta_ctl = devm_kzalloc(dev, sizeof(*meta_ctl), GFP_KERNEL); + meta_ctl = devm_kzalloc_obj(dev, *meta_ctl); if (!meta_ctl) return -ENOMEM; @@ -637,7 +637,7 @@ static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) return rval; drvdata->meta_ctl = meta_ctl; - sstream_ctl = devm_kzalloc(dev, sizeof(*sstream_ctl), GFP_KERNEL); + sstream_ctl = devm_kzalloc_obj(dev, *sstream_ctl); if (!sstream_ctl) return -ENOMEM; @@ -654,7 +654,7 @@ static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) QCOM_REGMAP_FIELD_ALLOC(dev, map, v->lsb_bits, ch_lsb); drvdata->hdmitx_ch_lsb[i] = ch_lsb; - tx_dmactl = devm_kzalloc(dev, sizeof(*tx_dmactl), GFP_KERNEL); + tx_dmactl = devm_kzalloc_obj(dev, *tx_dmactl); if (!tx_dmactl) return -ENOMEM; @@ -1094,7 +1094,7 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev) return -EBUSY; } - drvdata = devm_kzalloc(dev, sizeof(struct lpass_data), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, struct lpass_data); if (!drvdata) return -ENOMEM; platform_set_drvdata(pdev, drvdata); @@ -1219,8 +1219,7 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev) } /* Allocation for i2sctl regmap fields */ - drvdata->i2sctl = devm_kzalloc(&pdev->dev, sizeof(struct lpaif_i2sctl), - GFP_KERNEL); + drvdata->i2sctl = devm_kzalloc_obj(&pdev->dev, struct lpaif_i2sctl); if (!drvdata->i2sctl) return -ENOMEM; diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c index e162627d6f86e5..dad4becf7579e0 100644 --- a/sound/soc/qcom/lpass-platform.c +++ b/sound/soc/qcom/lpass-platform.c @@ -105,11 +105,11 @@ static int lpass_platform_alloc_rxtx_dmactl_fields(struct device *dev, struct lpaif_dmactl *rd_dmactl, *wr_dmactl; int rval; - rd_dmactl = devm_kzalloc(dev, sizeof(*rd_dmactl), GFP_KERNEL); + rd_dmactl = devm_kzalloc_obj(dev, *rd_dmactl); if (!rd_dmactl) return -ENOMEM; - wr_dmactl = devm_kzalloc(dev, sizeof(*wr_dmactl), GFP_KERNEL); + wr_dmactl = devm_kzalloc_obj(dev, *wr_dmactl); if (!wr_dmactl) return -ENOMEM; @@ -132,7 +132,7 @@ static int lpass_platform_alloc_va_dmactl_fields(struct device *dev, const struct lpass_variant *v = drvdata->variant; struct lpaif_dmactl *wr_dmactl; - wr_dmactl = devm_kzalloc(dev, sizeof(*wr_dmactl), GFP_KERNEL); + wr_dmactl = devm_kzalloc_obj(dev, *wr_dmactl); if (!wr_dmactl) return -ENOMEM; @@ -150,13 +150,11 @@ static int lpass_platform_alloc_dmactl_fields(struct device *dev, struct lpaif_dmactl *rd_dmactl, *wr_dmactl; int rval; - drvdata->rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl), - GFP_KERNEL); + drvdata->rd_dmactl = devm_kzalloc_obj(dev, struct lpaif_dmactl); if (drvdata->rd_dmactl == NULL) return -ENOMEM; - drvdata->wr_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl), - GFP_KERNEL); + drvdata->wr_dmactl = devm_kzalloc_obj(dev, struct lpaif_dmactl); if (drvdata->wr_dmactl == NULL) return -ENOMEM; @@ -179,7 +177,7 @@ static int lpass_platform_alloc_hdmidmactl_fields(struct device *dev, const struct lpass_variant *v = drvdata->variant; struct lpaif_dmactl *rd_dmactl; - rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl), GFP_KERNEL); + rd_dmactl = devm_kzalloc_obj(dev, struct lpaif_dmactl); if (rd_dmactl == NULL) return -ENOMEM; diff --git a/sound/soc/qcom/lpass-sc7180.c b/sound/soc/qcom/lpass-sc7180.c index 7c6a9b0fda891b..e623aee744994f 100644 --- a/sound/soc/qcom/lpass-sc7180.c +++ b/sound/soc/qcom/lpass-sc7180.c @@ -127,8 +127,8 @@ static int sc7180_lpass_init(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret, i; - drvdata->clks = devm_kcalloc(dev, variant->num_clks, - sizeof(*drvdata->clks), GFP_KERNEL); + drvdata->clks = devm_kzalloc_objs(dev, *drvdata->clks, + variant->num_clks); if (!drvdata->clks) return -ENOMEM; diff --git a/sound/soc/qcom/lpass-sc7280.c b/sound/soc/qcom/lpass-sc7280.c index 817c824f91791d..ffcfc0e2a51554 100644 --- a/sound/soc/qcom/lpass-sc7280.c +++ b/sound/soc/qcom/lpass-sc7280.c @@ -200,8 +200,8 @@ static int sc7280_lpass_init(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret, i; - drvdata->clks = devm_kcalloc(dev, variant->num_clks, - sizeof(*drvdata->clks), GFP_KERNEL); + drvdata->clks = devm_kzalloc_objs(dev, *drvdata->clks, + variant->num_clks); if (!drvdata->clks) return -ENOMEM; diff --git a/sound/soc/qcom/qaif-cpu.c b/sound/soc/qcom/qaif-cpu.c index d34b8df83f94f6..c1909e7da628d8 100644 --- a/sound/soc/qcom/qaif-cpu.c +++ b/sound/soc/qcom/qaif-cpu.c @@ -771,7 +771,7 @@ int asoc_qcom_qaif_cpu_platform_probe(struct platform_device *pdev) const struct of_device_id *match; int ret, i, dai_id, idx; - drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(dev, *drvdata); if (!drvdata) return dev_err_probe(dev, -ENOMEM, "Failed to allocate driver data\n"); platform_set_drvdata(pdev, drvdata); @@ -836,8 +836,8 @@ int asoc_qcom_qaif_cpu_platform_probe(struct platform_device *pdev) } drvdata->num_clks = variant->num_clks; - drvdata->clks = devm_kcalloc(dev, drvdata->num_clks, - sizeof(*drvdata->clks), GFP_KERNEL); + drvdata->clks = devm_kzalloc_objs(dev, *drvdata->clks, + drvdata->num_clks); if (!drvdata->clks) return dev_err_probe(dev, -ENOMEM, "Failed to allocate clocks\n"); diff --git a/sound/soc/qcom/qaif-platform.c b/sound/soc/qcom/qaif-platform.c index facba3be2d8eac..b13083911ab0a5 100644 --- a/sound/soc/qcom/qaif-platform.c +++ b/sound/soc/qcom/qaif-platform.c @@ -228,7 +228,7 @@ static int qaif_platform_pcmops_open(struct snd_soc_component *component, return dma_reg_idx; } - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = kzalloc_obj(*data); if (!data) return -ENOMEM; runtime->private_data = data; diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index d2dc5d37bccf89..aa1f4e29676474 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -1216,7 +1216,12 @@ static int audioreach_pcm_set_media_format(struct q6apm_graph *graph, media_cfg->interleaved = module->interleave_type; media_cfg->num_channels = mcfg->num_channels; media_cfg->q_factor = mcfg->bit_width - 1; - media_cfg->bits_per_sample = mcfg->bit_width; + /* + * bit_width is the number of valid bits in a sample, bits_per_sample + * the size of the container it is stored in. S24_LE keeps 24 valid + * bits in a 32-bit container, so it is 24/32, not packed 24/24. + */ + media_cfg->bits_per_sample = mcfg->bit_width == 24 ? 32 : mcfg->bit_width; /* Convert the physical mapping to a logical mapping of the channels */ for (i = 0, j = 0; i < AR_PCM_MAX_NUM_CHANNEL && j < mcfg->num_channels; i++) { if (!mcfg->channel_map[i]) @@ -1308,7 +1313,8 @@ static int audioreach_shmem_set_media_format(struct q6apm_graph *graph, cfg->sample_rate = mcfg->sample_rate; cfg->bit_width = mcfg->bit_width; cfg->alignment = PCM_LSB_ALIGNED; - cfg->bits_per_sample = mcfg->bit_width; + /* S24_LE: 24 valid bits in a 32-bit container, see above */ + cfg->bits_per_sample = mcfg->bit_width == 24 ? 32 : mcfg->bit_width; cfg->q_factor = mcfg->bit_width - 1; cfg->endianness = PCM_LITTLE_ENDIAN; cfg->num_channels = mcfg->num_channels; diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h index 587f14ce71d234..0a50b933773826 100644 --- a/sound/soc/qcom/qdsp6/audioreach.h +++ b/sound/soc/qcom/qdsp6/audioreach.h @@ -1047,7 +1047,6 @@ int audioreach_compr_set_param(struct q6apm_graph *graph, int audioreach_setup_push_pull(struct q6apm_graph *graph, phys_addr_t bphys, phys_addr_t pphys, uint32_t mem_map_handle, uint32_t pos_buf_mem_map_handle, uint32_t size); -int audioreach_map_memory_position_buffer(struct q6apm_graph *graph, unsigned int dir); int audioreach_shmem_register_event(struct q6apm_graph *graph, int bytes, int num_levels); #endif /* __AUDIOREACH_H__ */ diff --git a/sound/soc/qcom/qdsp6/q6adm.c b/sound/soc/qcom/qdsp6/q6adm.c index db0ae71f29831f..235bcbcb1af5c1 100644 --- a/sound/soc/qcom/qdsp6/q6adm.c +++ b/sound/soc/qcom/qdsp6/q6adm.c @@ -570,7 +570,7 @@ static int q6adm_probe(struct apr_device *adev) struct device *dev = &adev->dev; struct q6adm *adm; - adm = devm_kzalloc(dev, sizeof(*adm), GFP_KERNEL); + adm = devm_kzalloc_obj(dev, *adm); if (!adm) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c index 920345609d2c83..ddcae0c382fe33 100644 --- a/sound/soc/qcom/qdsp6/q6afe-dai.c +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c @@ -1162,7 +1162,7 @@ static int q6afe_dai_dev_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int num_dais; - dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL); + dai_data = devm_kzalloc_obj(dev, *dai_data); if (!dai_data) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index 9ac51c304ead01..4f7b706c77b5dc 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -1861,7 +1861,7 @@ struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id) return ERR_PTR(-EINVAL); } - port = kzalloc_obj(*port, GFP_KERNEL); + port = kzalloc_obj(*port); if (!port) return ERR_PTR(-ENOMEM); @@ -1971,7 +1971,7 @@ static int q6afe_probe(struct apr_device *adev) struct q6afe *afe; struct device *dev = &adev->dev; - afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); + afe = devm_kzalloc_obj(dev, *afe); if (!afe) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c index 94af3b79c61dc1..afa4bb095e09fc 100644 --- a/sound/soc/qcom/qdsp6/q6apm-dai.c +++ b/sound/soc/qcom/qdsp6/q6apm-dai.c @@ -999,6 +999,9 @@ static int q6apm_dai_compr_set_params(struct snd_soc_component *component, if (!pdata) return -EINVAL; + if (runtime->buffer_size > prtd->dma_buffer.bytes) + return -EINVAL; + prtd->periods = runtime->fragments; prtd->pcm_count = runtime->fragment_size; prtd->pcm_size = runtime->fragments * runtime->fragment_size; @@ -1202,7 +1205,7 @@ static int q6apm_dai_probe(struct platform_device *pdev) struct of_phandle_args args; int rc; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; @@ -1212,8 +1215,10 @@ static int q6apm_dai_probe(struct platform_device *pdev) rc = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); if (rc < 0) pdata->sid = -1; - else + else { pdata->sid = args.args[0] & SID_MASK_DEFAULT; + of_node_put(args.np); + } if (apm && apm->gdev && apm->gdev->domain_id == GPR_DOMAIN_ID_MODEM) { diff --git a/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c index 9f6d17f80de357..c63622629f1515 100644 --- a/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c +++ b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c @@ -528,7 +528,7 @@ static int q6apm_lpass_dai_dev_probe(struct platform_device *pdev) int num_dais; int ret; - dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL); + dai_data = devm_kzalloc_obj(dev, *dai_data); if (!dai_data) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c index 8e3314a2738c08..4cb597d737b169 100644 --- a/sound/soc/qcom/qdsp6/q6apm.c +++ b/sound/soc/qcom/qdsp6/q6apm.c @@ -886,7 +886,7 @@ static int apm_probe(gpr_device_t *gdev) struct q6apm *apm; int ret; - apm = devm_kzalloc(dev, sizeof(*apm), GFP_KERNEL); + apm = devm_kzalloc_obj(dev, *apm); if (!apm) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c index 4261c3048c3688..3840669867351a 100644 --- a/sound/soc/qcom/qdsp6/q6asm-dai.c +++ b/sound/soc/qcom/qdsp6/q6asm-dai.c @@ -243,6 +243,9 @@ static int q6asm_dai_prepare(struct snd_soc_component *component, prtd->state = Q6ASM_STREAM_STOPPED; } + /* ALSA resets appl_ptr for every prepare, including xrun recovery. */ + prtd->queue_ptr = 0; + ret = q6asm_map_memory_regions(substream->stream, prtd->audio_client, prtd->phys, (prtd->pcm_size / prtd->periods), @@ -897,6 +900,9 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, return -EINVAL; } + if (runtime->buffer_size > prtd->dma_buffer.bytes) + return -EINVAL; + prtd->periods = runtime->fragments; prtd->pcm_count = runtime->fragment_size; prtd->pcm_size = runtime->fragments * runtime->fragment_size; @@ -1262,8 +1268,7 @@ static int of_q6asm_parse_dai_data(struct device *dev, return -EINVAL; } - pdata->dais = devm_kcalloc(dev, pdata->num_dais, sizeof(*dai_drv), - GFP_KERNEL); + pdata->dais = devm_kzalloc_objs(dev, *dai_drv, pdata->num_dais); if (!pdata->dais) return -ENOMEM; @@ -1303,15 +1308,17 @@ static int q6asm_dai_probe(struct platform_device *pdev) struct q6asm_dai_data *pdata; int rc; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (!pdata) return -ENOMEM; rc = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); if (rc < 0) pdata->sid = -1; - else + else { pdata->sid = args.args[0] & SID_MASK_DEFAULT; + of_node_put(args.np); + } dev_set_drvdata(dev, pdata); diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c index de0bd8fd08eeb8..d042132caf0343 100644 --- a/sound/soc/qcom/qdsp6/q6asm.c +++ b/sound/soc/qcom/qdsp6/q6asm.c @@ -514,6 +514,8 @@ int q6asm_map_memory_regions(unsigned int dir, struct audio_client *ac, ac->port[dir].buf = buf; + ac->port[dir].dsp_buf = 0; + atomic_set(&ac->port[dir].hw_ptr, 0); buf[0].phys = phys; buf[0].size = period_sz; @@ -1650,7 +1652,7 @@ static int q6asm_probe(struct apr_device *adev) struct device *dev = &adev->dev; struct q6asm *q6asm; - q6asm = devm_kzalloc(dev, sizeof(*q6asm), GFP_KERNEL); + q6asm = devm_kzalloc_obj(dev, *q6asm); if (!q6asm) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-clocks.c b/sound/soc/qcom/qdsp6/q6dsp-lpass-clocks.c index ab7d20580638bc..c3628f90fdb212 100644 --- a/sound/soc/qcom/qdsp6/q6dsp-lpass-clocks.c +++ b/sound/soc/qcom/qdsp6/q6dsp-lpass-clocks.c @@ -134,7 +134,7 @@ int q6dsp_clock_dev_probe(struct platform_device *pdev) const struct q6dsp_clk_desc *desc; int i, ret; - cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL); + cc = devm_kzalloc_obj(dev, *cc); if (!cc) return -ENOMEM; @@ -146,6 +146,12 @@ int q6dsp_clock_dev_probe(struct platform_device *pdev) cc->dev = dev; q6dsp_clks = desc->clks; + /* + * The clk ops look up cc through the driver data, so set it before + * any of the clocks can be prepared. + */ + dev_set_drvdata(dev, cc); + for (i = 0; i < desc->num_clks; i++) { unsigned int id = q6dsp_clks[i].clk_id; struct clk_init_data init = { @@ -153,7 +159,7 @@ int q6dsp_clock_dev_probe(struct platform_device *pdev) }; struct q6dsp_clk *clk; - clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL); + clk = devm_kzalloc_obj(dev, *clk); if (!clk) return -ENOMEM; @@ -174,12 +180,6 @@ int q6dsp_clock_dev_probe(struct platform_device *pdev) return ret; } - ret = devm_of_clk_add_hw_provider(dev, q6dsp_of_clk_hw_get, cc); - if (ret) - return ret; - - dev_set_drvdata(dev, cc); - - return 0; + return devm_of_clk_add_hw_provider(dev, q6dsp_of_clk_hw_get, cc); } EXPORT_SYMBOL_GPL(q6dsp_clock_dev_probe); diff --git a/sound/soc/qcom/qdsp6/q6prm.c b/sound/soc/qcom/qdsp6/q6prm.c index 5c927ebd81f411..73b5a96e831191 100644 --- a/sound/soc/qcom/qdsp6/q6prm.c +++ b/sound/soc/qcom/qdsp6/q6prm.c @@ -217,7 +217,7 @@ static int prm_probe(gpr_device_t *gdev) struct device *dev = &gdev->dev; struct q6prm *cc; - cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL); + cc = devm_kzalloc_obj(dev, *cc); if (!cc) return -ENOMEM; diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 5e051a23868a7f..bf1d42780b70f9 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -375,7 +375,7 @@ static int q6usb_dai_dev_probe(struct platform_device *pdev) struct of_phandle_args args; int ret; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -387,8 +387,10 @@ static int q6usb_dai_dev_probe(struct platform_device *pdev) } ret = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); - if (!ret) + if (!ret) { data->priv.sid = args.args[0] & Q6_USB_SID_MASK; + of_node_put(args.np); + } ret = devm_mutex_init(dev, &data->mutex); if (ret < 0) diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c index 612d8f03e6e98e..aa2ab2b058d0fc 100644 --- a/sound/soc/qcom/qdsp6/topology.c +++ b/sound/soc/qcom/qdsp6/topology.c @@ -1240,7 +1240,9 @@ static void audioreach_connect_sub_graphs(struct q6apm *apm, info->dst_mod_inst_id = m2->module_instance_id; info->dst_mod_ip_port_id = 2; - } else { + } else if (info->src_mod_inst_id == m1->module_instance_id && + info->dst_mod_inst_id == m2->module_instance_id) { + /* only drop the link this control made, not another FE's */ info->src_mod_inst_id = 0; info->src_mod_op_port_id = 0; info->dst_mod_inst_id = 0; diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c index bc5a1888347931..3b34e11d5dc677 100644 --- a/sound/soc/qcom/sc7180.c +++ b/sound/soc/qcom/sc7180.c @@ -500,7 +500,7 @@ static int sc7180_snd_platform_probe(struct platform_device *pdev) bool qdsp = false, no_headphone = false; /* Allocate the private data */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/qcom/sc7280.c b/sound/soc/qcom/sc7280.c index d3d8a6e83268b3..b17285bf66feaa 100644 --- a/sound/soc/qcom/sc7280.c +++ b/sound/soc/qcom/sc7280.c @@ -349,7 +349,7 @@ static int sc7280_snd_platform_probe(struct platform_device *pdev) struct snd_soc_dai_link *link; int ret, i; - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c index 8cc75a7ad866dc..ac4dfb2c2182ca 100644 --- a/sound/soc/qcom/sc8280xp.c +++ b/sound/soc/qcom/sc8280xp.c @@ -93,6 +93,7 @@ struct qcom_snd_soc_common { bool codec_sysclk_set; bool mi2s_mclk_enable; bool mi2s_bclk_enable; + bool mi2s_32bit; bool wcd_jack; const struct sc8280xp_dai_data *dai_data; size_t num_dai_data; @@ -292,6 +293,7 @@ static int sc8280xp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card); struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); struct snd_interval *channels = hw_param_interval(params, @@ -329,6 +331,15 @@ static int sc8280xp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, case TX_CODEC_DMA_TX_3: channels->min = 1; break; + case PRIMARY_MI2S_RX ... QUATERNARY_MI2S_TX: + case QUINARY_MI2S_RX ... QUINARY_MI2S_TX: + case SENARY_MI2S_RX ... SENARY_MI2S_TX: + case LPI_MI2S_RX_0 ... LPI_MI2S_TX_4: + if (data->priv->mi2s_32bit) { + snd_mask_none(fmt); + snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE); + } + break; default: break; } @@ -549,12 +560,12 @@ static int sc8280xp_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; /* Allocate the private data */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; @@ -582,6 +593,14 @@ static int sc8280xp_platform_probe(struct platform_device *pdev) return devm_snd_soc_register_card(dev, card); } +static const struct qcom_snd_soc_common motorola_vantage_priv_data = { + .driver_name = "molokai", + .dapm_widgets = sc8280xp_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(sc8280xp_dapm_widgets), + .mi2s_bclk_enable = true, + .mi2s_32bit = true, +}; + static struct qcom_snd_soc_common ayaneo_ps2_priv_data = { .driver_name = "ayaneo-ps2", .dapm_widgets = sc8280xp_dapm_widgets, @@ -752,6 +771,7 @@ static const struct qcom_snd_soc_common sm8750_priv_data = { static const struct of_device_id snd_sc8280xp_dt_match[] = { { .compatible = "ayaneo,pocket-s2-sndcard", .data = &ayaneo_ps2_priv_data }, + { .compatible = "motorola,vantage-sndcard", .data = &motorola_vantage_priv_data }, { .compatible = "qcom,eliza-sndcard", .data = &eliza_priv_data }, { .compatible = "qcom,hawi-sndcard", .data = &hawi_priv_data }, { .compatible = "qcom,kaanapali-sndcard", .data = &kaanapali_priv_data }, diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c index 85951397cb2b11..0fa2fa6201e2b1 100644 --- a/sound/soc/qcom/sdm845.c +++ b/sound/soc/qcom/sdm845.c @@ -582,12 +582,12 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; /* Allocate the private data */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index d776a17f1fd3b5..d0015e5f525761 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -200,13 +200,13 @@ static int sm8250_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; card->owner = THIS_MODULE; /* Allocate the private data */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/qcom/storm.c b/sound/soc/qcom/storm.c index 6a42876ce6250e..3bca122fd712fb 100644 --- a/sound/soc/qcom/storm.c +++ b/sound/soc/qcom/storm.c @@ -91,7 +91,7 @@ static int storm_platform_probe(struct platform_device *pdev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(&pdev->dev, *card); if (!card) return -ENOMEM; diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c index c81df41ace8839..c927672eaede71 100644 --- a/sound/soc/qcom/x1e80100.c +++ b/sound/soc/qcom/x1e80100.c @@ -68,6 +68,23 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd) return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); } +static void x1e80100_snd_exit(struct snd_soc_pcm_runtime *rtd) +{ + struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + + switch (cpu_dai->id) { + case DISPLAY_PORT_RX_0: + case DISPLAY_PORT_RX_1 ... DISPLAY_PORT_RX_7: + return; + default: + break; + } + + qcom_snd_headset_jack_cleanup(rtd); + data->jack_setup = false; +} + static int x1e80100_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { @@ -172,6 +189,7 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card) for_each_card_prelinks(card, i, link) { if (link->no_pcm == 1) { link->init = x1e80100_snd_init; + link->exit = x1e80100_snd_exit; link->be_hw_params_fixup = x1e80100_be_hw_params_fixup; link->ops = &x1e80100_be_ops; } @@ -185,11 +203,11 @@ static int x1e80100_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; /* Allocate the private data */ - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc_obj(dev, *data); if (!data) return -ENOMEM; diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c index fa21cf47befffd..35c3bc456dc11d 100644 --- a/sound/soc/renesas/fsi.c +++ b/sound/soc/renesas/fsi.c @@ -2022,7 +2022,7 @@ static int fsi_probe(struct platform_device *pdev) if (irq < 0) return irq; - master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); + master = devm_kzalloc_obj(&pdev->dev, *master); if (!master) return -ENOMEM; diff --git a/sound/soc/renesas/rcar/adg.c b/sound/soc/renesas/rcar/adg.c index 2a74d89ba39df9..f0605daf6a217f 100644 --- a/sound/soc/renesas/rcar/adg.c +++ b/sound/soc/renesas/rcar/adg.c @@ -930,7 +930,7 @@ int rsnd_adg_probe(struct rsnd_priv *priv) struct device *dev = rsnd_priv_to_dev(priv); int ret; - adg = devm_kzalloc(dev, sizeof(*adg), GFP_KERNEL); + adg = devm_kzalloc_obj(dev, *adg); if (!adg) return -ENOMEM; diff --git a/sound/soc/renesas/rcar/cmd.c b/sound/soc/renesas/rcar/cmd.c index 13beef3897978e..e840afb9ab9f87 100644 --- a/sound/soc/renesas/rcar/cmd.c +++ b/sound/soc/renesas/rcar/cmd.c @@ -162,7 +162,7 @@ int rsnd_cmd_probe(struct rsnd_priv *priv) if (!nr) return 0; - cmd = devm_kcalloc(dev, nr, sizeof(*cmd), GFP_KERNEL); + cmd = devm_kzalloc_objs(dev, *cmd, nr); if (!cmd) return -ENOMEM; diff --git a/sound/soc/renesas/rcar/core.c b/sound/soc/renesas/rcar/core.c index b7954746e9533c..d42abd2fc76635 100644 --- a/sound/soc/renesas/rcar/core.c +++ b/sound/soc/renesas/rcar/core.c @@ -1140,6 +1140,8 @@ static void rsnd_parse_connect_graph(struct rsnd_priv *priv, return; remote_node = of_graph_get_remote_port_parent(endpoint); + if (!remote_node) + return; /* HDMI0 */ if (strstr(remote_node->full_name, "hdmi@fead0000")) { @@ -1595,8 +1597,8 @@ static int rsnd_dai_probe(struct rsnd_priv *priv) if (!nr) return 0; - rdrv = devm_kcalloc(dev, nr, sizeof(*rdrv), GFP_KERNEL); - rdai = devm_kcalloc(dev, nr, sizeof(*rdai), GFP_KERNEL); + rdrv = devm_kzalloc_objs(dev, *rdrv, nr); + rdai = devm_kzalloc_objs(dev, *rdai, nr); if (!rdrv || !rdai) return -ENOMEM; @@ -2062,7 +2064,7 @@ static int rsnd_probe(struct platform_device *pdev) /* * init priv data */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENODEV; diff --git a/sound/soc/renesas/rcar/ctu.c b/sound/soc/renesas/rcar/ctu.c index 7db0fb3612bc0c..6e636f6c3abbca 100644 --- a/sound/soc/renesas/rcar/ctu.c +++ b/sound/soc/renesas/rcar/ctu.c @@ -330,7 +330,7 @@ int rsnd_ctu_probe(struct rsnd_priv *priv) goto rsnd_ctu_probe_done; } - ctu = devm_kcalloc(dev, nr, sizeof(*ctu), GFP_KERNEL); + ctu = devm_kzalloc_objs(dev, *ctu, nr); if (!ctu) { ret = -ENOMEM; goto rsnd_ctu_probe_done; diff --git a/sound/soc/renesas/rcar/dma.c b/sound/soc/renesas/rcar/dma.c index 793dd4adbe5c64..cb59a1c6f45e7f 100644 --- a/sound/soc/renesas/rcar/dma.c +++ b/sound/soc/renesas/rcar/dma.c @@ -246,7 +246,7 @@ static int rsnd_dmaen_attach(struct rsnd_dai_stream *io, * see * rsnd_preallocate_pages() */ - io->dmac_dev = chan->device->dev; + io->dmac_dev = dmaengine_get_dma_device(chan); dma_release_channel(chan); @@ -791,6 +791,7 @@ static void rsnd_dma_of_path(struct rsnd_mod *this, struct rsnd_mod *mod_start, *mod_end; struct rsnd_priv *priv = rsnd_mod_to_priv(this); struct device *dev = rsnd_priv_to_dev(priv); + struct device_node *ssiu_np; int nr, i, idx; /* @@ -803,13 +804,15 @@ static void rsnd_dma_of_path(struct rsnd_mod *this, * rsnd_ssiu_dma_req() * rsnd_ssi_dma_req() */ - if (rsnd_ssiu_of_node(priv)) { + ssiu_np = rsnd_ssiu_of_node(priv); + if (ssiu_np) { struct rsnd_mod *ssiu = rsnd_io_to_mod_ssiu(io); /* use SSIU */ ssi = ssiu; if (this == rsnd_io_to_mod_ssi(io)) this = ssiu; + of_node_put(ssiu_np); } else { /* keep compatible, use SSI */ ssi = rsnd_io_to_mod_ssi(io); @@ -932,7 +935,7 @@ static int rsnd_dma_alloc(struct rsnd_dai_stream *io, struct rsnd_mod *mod, type = RSND_MOD_AUDMA; } - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); + dma = devm_kzalloc_obj(dev, *dma); if (!dma) return -ENOMEM; @@ -989,7 +992,7 @@ int rsnd_dma_probe(struct rsnd_priv *priv) /* * for Gen2 or later */ - dmac = devm_kzalloc(dev, sizeof(*dmac), GFP_KERNEL); + dmac = devm_kzalloc_obj(dev, *dmac); if (!dmac) { dev_err(dev, "dma allocate failed\n"); return 0; /* it will be PIO mode */ diff --git a/sound/soc/renesas/rcar/dvc.c b/sound/soc/renesas/rcar/dvc.c index 7601dfb0810a72..2c8ce1c316f566 100644 --- a/sound/soc/renesas/rcar/dvc.c +++ b/sound/soc/renesas/rcar/dvc.c @@ -338,7 +338,7 @@ int rsnd_dvc_probe(struct rsnd_priv *priv) goto rsnd_dvc_probe_done; } - dvc = devm_kcalloc(dev, nr, sizeof(*dvc), GFP_KERNEL); + dvc = devm_kzalloc_objs(dev, *dvc, nr); if (!dvc) { ret = -ENOMEM; goto rsnd_dvc_probe_done; diff --git a/sound/soc/renesas/rcar/gen.c b/sound/soc/renesas/rcar/gen.c index 05d5f656fb01c0..f6d5044fd24047 100644 --- a/sound/soc/renesas/rcar/gen.c +++ b/sound/soc/renesas/rcar/gen.c @@ -651,7 +651,7 @@ int rsnd_gen_probe(struct rsnd_priv *priv) struct rsnd_gen *gen; int ret; - gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL); + gen = devm_kzalloc_obj(dev, *gen); if (!gen) return -ENOMEM; diff --git a/sound/soc/renesas/rcar/mix.c b/sound/soc/renesas/rcar/mix.c index c4da4c4bedb34e..94141d28ab4aba 100644 --- a/sound/soc/renesas/rcar/mix.c +++ b/sound/soc/renesas/rcar/mix.c @@ -302,7 +302,7 @@ int rsnd_mix_probe(struct rsnd_priv *priv) goto rsnd_mix_probe_done; } - mix = devm_kcalloc(dev, nr, sizeof(*mix), GFP_KERNEL); + mix = devm_kzalloc_objs(dev, *mix, nr); if (!mix) { ret = -ENOMEM; goto rsnd_mix_probe_done; diff --git a/sound/soc/renesas/rcar/msiof.c b/sound/soc/renesas/rcar/msiof.c index 11a6f22ec0adb3..42049a9a2349de 100644 --- a/sound/soc/renesas/rcar/msiof.c +++ b/sound/soc/renesas/rcar/msiof.c @@ -567,7 +567,7 @@ static int msiof_probe(struct platform_device *pdev) if (irq <= 0) return irq; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/renesas/rcar/rsnd.h b/sound/soc/renesas/rcar/rsnd.h index b480085fb0e7c1..5494a16542d5d4 100644 --- a/sound/soc/renesas/rcar/rsnd.h +++ b/sound/soc/renesas/rcar/rsnd.h @@ -613,9 +613,6 @@ int rsnd_dai_connect(struct rsnd_mod *mod, * R-Car Gen1/Gen2 */ int rsnd_gen_probe(struct rsnd_priv *priv); -void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, - struct rsnd_mod *mod, - enum rsnd_reg reg); phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id); #ifdef CONFIG_DEBUG_FS void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id); @@ -849,8 +846,6 @@ unsigned int rsnd_ssi_clk_query(struct rsnd_dai *rdai, /* * R-Car SSIU */ -int rsnd_ssiu_attach(struct rsnd_dai_stream *io, - struct rsnd_mod *mod); int rsnd_ssiu_probe(struct rsnd_priv *priv); void rsnd_ssiu_remove(struct rsnd_priv *priv); void rsnd_ssiu_suspend(struct rsnd_priv *priv); diff --git a/sound/soc/renesas/rcar/src.c b/sound/soc/renesas/rcar/src.c index 2cdb39e898af02..f7f4c35bd96917 100644 --- a/sound/soc/renesas/rcar/src.c +++ b/sound/soc/renesas/rcar/src.c @@ -736,13 +736,13 @@ int rsnd_src_probe(struct rsnd_priv *priv) goto rsnd_src_probe_done; } - src_ctrl = devm_kzalloc(dev, sizeof(*src_ctrl), GFP_KERNEL); + src_ctrl = devm_kzalloc_obj(dev, *src_ctrl); if (!src_ctrl) { ret = -ENOMEM; goto rsnd_src_probe_done; } - src = devm_kcalloc(dev, nr, sizeof(*src), GFP_KERNEL); + src = devm_kzalloc_objs(dev, *src, nr); if (!src) { ret = -ENOMEM; goto rsnd_src_probe_done; diff --git a/sound/soc/renesas/rcar/ssi.c b/sound/soc/renesas/rcar/ssi.c index 2fa76a07998279..cf87a8ee2405fd 100644 --- a/sound/soc/renesas/rcar/ssi.c +++ b/sound/soc/renesas/rcar/ssi.c @@ -1175,7 +1175,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv) goto rsnd_ssi_probe_done; } - ssi = devm_kcalloc(dev, nr, sizeof(*ssi), GFP_KERNEL); + ssi = devm_kzalloc_objs(dev, *ssi, nr); if (!ssi) { ret = -ENOMEM; goto rsnd_ssi_probe_done; diff --git a/sound/soc/renesas/rcar/ssiu.c b/sound/soc/renesas/rcar/ssiu.c index 2a8593a5d4a60c..58c01d2f01dfcb 100644 --- a/sound/soc/renesas/rcar/ssiu.c +++ b/sound/soc/renesas/rcar/ssiu.c @@ -540,11 +540,11 @@ int rsnd_ssiu_probe(struct rsnd_priv *priv) if (!nr) return -EINVAL; - ssiu = devm_kcalloc(dev, nr, sizeof(*ssiu), GFP_KERNEL); + ssiu = devm_kzalloc_objs(dev, *ssiu, nr); if (!ssiu) return -ENOMEM; - ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc_obj(dev, *ctrl); if (!ctrl) return -ENOMEM; diff --git a/sound/soc/renesas/rz-ssi.c b/sound/soc/renesas/rz-ssi.c index 9a0781bb072d2b..b9ce2a8c4885c1 100644 --- a/sound/soc/renesas/rz-ssi.c +++ b/sound/soc/renesas/rz-ssi.c @@ -1023,7 +1023,7 @@ static int rz_ssi_probe(struct platform_device *pdev) struct resource *res; int ret; - ssi = devm_kzalloc(dev, sizeof(*ssi), GFP_KERNEL); + ssi = devm_kzalloc_obj(dev, *ssi); if (!ssi) return -ENOMEM; @@ -1062,7 +1062,7 @@ static int rz_ssi_probe(struct platform_device *pdev) struct snd_dmaengine_pcm_config *config; unsigned int flags = 0; - config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(dev, *config); if (!config) return -ENOMEM; diff --git a/sound/soc/renesas/siu_dai.c b/sound/soc/renesas/siu_dai.c index fff6ef870f0db8..a8a24bd74116d3 100644 --- a/sound/soc/renesas/siu_dai.c +++ b/sound/soc/renesas/siu_dai.c @@ -725,7 +725,7 @@ static int siu_probe(struct platform_device *pdev) struct siu_info *info; int ret; - info = devm_kmalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + info = devm_kmalloc_obj(&pdev->dev, *info); if (!info) return -ENOMEM; siu_i2s_data = info; diff --git a/sound/soc/rockchip/rk3288_hdmi_analog.c b/sound/soc/rockchip/rk3288_hdmi_analog.c index 9bb02d41d90136..c6b0218a6b6ae7 100644 --- a/sound/soc/rockchip/rk3288_hdmi_analog.c +++ b/sound/soc/rockchip/rk3288_hdmi_analog.c @@ -172,8 +172,7 @@ static int snd_rk_mc_probe(struct platform_device *pdev) struct rk_drvdata *machine; struct of_phandle_args args; - machine = devm_kzalloc(&pdev->dev, sizeof(struct rk_drvdata), - GFP_KERNEL); + machine = devm_kzalloc_obj(&pdev->dev, struct rk_drvdata); if (!machine) return -ENOMEM; diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c index d4a0daabfb4271..0ace657c41c054 100644 --- a/sound/soc/rockchip/rk3399_gru_sound.c +++ b/sound/soc/rockchip/rk3399_gru_sound.c @@ -515,16 +515,15 @@ static int rockchip_sound_of_parse_dais(struct device *dev, int i, index; int num_routes; - card->dai_link = devm_kcalloc(dev, ARRAY_SIZE(rockchip_dais), - sizeof(*card->dai_link), GFP_KERNEL); + card->dai_link = devm_kzalloc_objs(dev, *card->dai_link, + ARRAY_SIZE(rockchip_dais)); if (!card->dai_link) return -ENOMEM; num_routes = 0; for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++) num_routes += rockchip_routes[i].num_routes; - routes = devm_kcalloc(dev, num_routes, sizeof(*routes), - GFP_KERNEL); + routes = devm_kzalloc_objs(dev, *routes, num_routes); if (!routes) return -ENOMEM; card->dapm_routes = routes; @@ -540,12 +539,16 @@ static int rockchip_sound_of_parse_dais(struct device *dev, if (!np_codec) break; - if (!of_device_is_available(np_codec)) + if (!of_device_is_available(np_codec)) { + of_node_put(np_codec); continue; + } index = rockchip_sound_codec_node_match(np_codec); - if (index < 0) + if (index < 0) { + of_node_put(np_codec); continue; + } switch (index) { case DAILINK_CDNDP: diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c index 0a67632e68ede8..32f10b1d0d2252 100644 --- a/sound/soc/rockchip/rockchip_i2s.c +++ b/sound/soc/rockchip/rockchip_i2s.c @@ -765,7 +765,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/rockchip/rockchip_i2s_tdm.c b/sound/soc/rockchip/rockchip_i2s_tdm.c index 983319a538b111..023d603d27e782 100644 --- a/sound/soc/rockchip/rockchip_i2s_tdm.c +++ b/sound/soc/rockchip/rockchip_i2s_tdm.c @@ -243,6 +243,21 @@ static void rockchip_snd_xfer_clear(struct rk_i2s_tdm_dev *i2s_tdm, regmap_read(i2s_tdm->regmap, I2S_CLR, &val); retry--; if (!retry) { + /* + * In consumer mode the clear only completes while the + * provider runs the bit clock, which it may have + * stopped, e.g. an HDMI receiver whose source sends + * no audio. Resetting the controller while the clear + * is pending can leave it unable to transfer data + * until the next reboot, so leave the clear pending. + * rockchip_i2s_tdm_prepare() waits for it to complete + * before the next start. + */ + if (!i2s_tdm->is_master_mode) { + dev_dbg(i2s_tdm->dev, + "clear pending, no bit clock\n"); + break; + } dev_warn(i2s_tdm->dev, "clear failed, reset %s%s\n", tx ? "tx" : "", rx ? "rx" : ""); if (rx && tx) @@ -781,6 +796,37 @@ static int rockchip_i2s_tdm_trigger(struct snd_pcm_substream *substream, return 0; } +static int rockchip_i2s_tdm_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct rk_i2s_tdm_dev *i2s_tdm = to_info(dai); + unsigned int clr, val; + int ret; + + if (i2s_tdm->clk_trcm) + clr = I2S_CLR_TXC | I2S_CLR_RXC; + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) + clr = I2S_CLR_RXC; + else + clr = I2S_CLR_TXC; + + /* + * A clear left pending by rockchip_snd_xfer_clear() completes once + * the provider runs the bit clock again, usually within a few ms + * of its own hw_params. Wait for it rather than starting the + * transfer while it is pending, and fail if the clock does not + * come back. + */ + ret = regmap_read_poll_timeout(i2s_tdm->regmap, I2S_CLR, val, + !(val & clr), 1000, 100000); + if (ret) + dev_err_ratelimited(i2s_tdm->dev, + "clear still pending (%#x), no bit clock?\n", + val); + + return ret; +} + static int rockchip_i2s_tdm_dai_probe(struct snd_soc_dai *dai) { struct rk_i2s_tdm_dev *i2s_tdm = snd_soc_dai_get_drvdata(dai); @@ -840,6 +886,7 @@ static const u64 rockchip_dai_selectable_formats = static const struct snd_soc_dai_ops rockchip_i2s_tdm_dai_ops = { .probe = rockchip_i2s_tdm_dai_probe, .hw_params = rockchip_i2s_tdm_hw_params, + .prepare = rockchip_i2s_tdm_prepare, .set_bclk_ratio = rockchip_i2s_tdm_set_bclk_ratio, .set_fmt = rockchip_i2s_tdm_set_fmt, .set_sysclk = rockchip_i2s_tdm_set_sysclk, @@ -926,6 +973,7 @@ static const struct reg_default rockchip_i2s_tdm_reg_defaults[] = { {0x08, 0x00001f1f}, {0x10, 0x001f0000}, {0x14, 0x01f00000}, + {0x1c, 0x00000000}, {0x30, 0x00003eff}, {0x34, 0x00003eff}, {0x38, 0x00000707}, @@ -1247,7 +1295,7 @@ static int rockchip_i2s_tdm_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s_tdm = devm_kzalloc(&pdev->dev, sizeof(*i2s_tdm), GFP_KERNEL); + i2s_tdm = devm_kzalloc_obj(&pdev->dev, *i2s_tdm); if (!i2s_tdm) return -ENOMEM; @@ -1371,13 +1419,18 @@ static int rockchip_i2s_tdm_probe(struct platform_device *pdev) if (i2s_tdm->soc_data && i2s_tdm->soc_data->init) i2s_tdm->soc_data->init(&pdev->dev, res->start); - ret = devm_snd_soc_register_component(&pdev->dev, - &rockchip_i2s_tdm_component, - i2s_tdm->dai, 1); + /* + * Register the PCM before the DAI: adding the DAI component can bind a + * waiting card right away, and the card must find the PCM component + * then or its DAI link ends up without one. + */ + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); if (ret) goto err_suspend; - ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); + ret = devm_snd_soc_register_component(&pdev->dev, + &rockchip_i2s_tdm_component, + i2s_tdm->dai, 1); if (ret) goto err_suspend; diff --git a/sound/soc/rockchip/rockchip_pdm.c b/sound/soc/rockchip/rockchip_pdm.c index 0720748c7c8dd6..a0a89f5bddd99c 100644 --- a/sound/soc/rockchip/rockchip_pdm.c +++ b/sound/soc/rockchip/rockchip_pdm.c @@ -586,7 +586,7 @@ static int rockchip_pdm_probe(struct platform_device *pdev) void __iomem *regs; int ret; - pdm = devm_kzalloc(&pdev->dev, sizeof(*pdm), GFP_KERNEL); + pdm = devm_kzalloc_obj(&pdev->dev, *pdm); if (!pdm) return -ENOMEM; diff --git a/sound/soc/rockchip/rockchip_sai.c b/sound/soc/rockchip/rockchip_sai.c index dab96df8bf9635..b625d69f76c814 100644 --- a/sound/soc/rockchip/rockchip_sai.c +++ b/sound/soc/rockchip/rockchip_sai.c @@ -1409,7 +1409,7 @@ static int rockchip_sai_probe(struct platform_device *pdev) void __iomem *regs; int ret, irq; - sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); + sai = devm_kzalloc_obj(&pdev->dev, *sai); if (!sai) return -ENOMEM; diff --git a/sound/soc/rockchip/rockchip_spdif.c b/sound/soc/rockchip/rockchip_spdif.c index 2d53efd5dd2e3b..969cc95410d284 100644 --- a/sound/soc/rockchip/rockchip_spdif.c +++ b/sound/soc/rockchip/rockchip_spdif.c @@ -354,7 +354,7 @@ static int rk_spdif_probe(struct platform_device *pdev) regmap_write(grf, RK3288_GRF_SOC_CON2, BIT(1) << 16); } - spdif = devm_kzalloc(&pdev->dev, sizeof(*spdif), GFP_KERNEL); + spdif = devm_kzalloc_obj(&pdev->dev, *spdif); if (!spdif) return -ENOMEM; diff --git a/sound/soc/samsung/aries_wm8994.c b/sound/soc/samsung/aries_wm8994.c index 1a5b53f47571e2..4f383f977fb8b8 100644 --- a/sound/soc/samsung/aries_wm8994.c +++ b/sound/soc/samsung/aries_wm8994.c @@ -549,7 +549,7 @@ static int aries_audio_probe(struct platform_device *pdev) card->dev = dev; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/samsung/dmaengine.c b/sound/soc/samsung/dmaengine.c index 2802789a323e5a..26badd429d94b1 100644 --- a/sound/soc/samsung/dmaengine.c +++ b/sound/soc/samsung/dmaengine.c @@ -20,7 +20,7 @@ int samsung_asoc_dma_platform_register(struct device *dev, dma_filter_fn filter, { struct snd_dmaengine_pcm_config *pcm_conf; - pcm_conf = devm_kzalloc(dev, sizeof(*pcm_conf), GFP_KERNEL); + pcm_conf = devm_kzalloc_obj(dev, *pcm_conf); if (!pcm_conf) return -ENOMEM; diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c index 442e70b107dac5..8a938d0d79f94d 100644 --- a/sound/soc/samsung/i2s.c +++ b/sound/soc/samsung/i2s.c @@ -1166,13 +1166,12 @@ static int i2s_alloc_dais(struct samsung_i2s_priv *priv, struct snd_soc_dai_driver *dai_drv; int i; - priv->dai = devm_kcalloc(&priv->pdev->dev, num_dais, - sizeof(struct i2s_dai), GFP_KERNEL); + priv->dai = devm_kzalloc_objs(&priv->pdev->dev, struct i2s_dai, + num_dais); if (!priv->dai) return -ENOMEM; - priv->dai_drv = devm_kcalloc(&priv->pdev->dev, num_dais, - sizeof(*dai_drv), GFP_KERNEL); + priv->dai_drv = devm_kzalloc_objs(&priv->pdev->dev, *dai_drv, num_dais); if (!priv->dai_drv) return -ENOMEM; @@ -1365,8 +1364,8 @@ static int i2s_create_secondary_device(struct samsung_i2s_priv *priv) ret = device_attach(&pdev_sec->dev); if (ret <= 0) { - platform_device_unregister(priv->pdev_sec); dev_info(&pdev_sec->dev, "device_attach() failed\n"); + platform_device_unregister(pdev_sec); return ret; } @@ -1405,7 +1404,7 @@ static int samsung_i2s_probe(struct platform_device *pdev) i2s_dai_data = (struct samsung_i2s_dai_data *)id->driver_data; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/samsung/midas_wm1811.c b/sound/soc/samsung/midas_wm1811.c index 9f27f4cad124c5..872bb7af9e6ec6 100644 --- a/sound/soc/samsung/midas_wm1811.c +++ b/sound/soc/samsung/midas_wm1811.c @@ -587,7 +587,7 @@ static int midas_probe(struct platform_device *pdev) struct midas_priv *priv; int ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/samsung/odroid.c b/sound/soc/samsung/odroid.c index 5c5ecbea5331e1..1ca87f16887ac3 100644 --- a/sound/soc/samsung/odroid.c +++ b/sound/soc/samsung/odroid.c @@ -194,7 +194,7 @@ static int odroid_audio_probe(struct platform_device *pdev) struct snd_soc_dai_link *link, *codec_link; int num_pcms, ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c index ad99c153e9f8c7..9b73c2e62296ac 100644 --- a/sound/soc/samsung/snow.c +++ b/sound/soc/samsung/snow.c @@ -130,7 +130,7 @@ static int snow_probe(struct platform_device *pdev) struct snow_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/samsung/tm2_wm5110.c b/sound/soc/samsung/tm2_wm5110.c index f4912826dfd4db..076c8bfc119ce2 100644 --- a/sound/soc/samsung/tm2_wm5110.c +++ b/sound/soc/samsung/tm2_wm5110.c @@ -504,7 +504,7 @@ static int tm2_probe(struct platform_device *pdev) struct snd_soc_dai_link *dai_link; int num_codecs, ret, i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c index ccc579f878ff1e..aaa84156f20a84 100644 --- a/sound/soc/sdca/sdca_asoc.c +++ b/sound/soc/sdca/sdca_asoc.c @@ -13,11 +13,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -217,19 +219,19 @@ static int entity_early_parse_ge(struct device *dev, if (!control_name) return -ENOMEM; - kctl = devm_kzalloc(dev, sizeof(*kctl), GFP_KERNEL); + kctl = devm_kzalloc_obj(dev, *kctl); if (!kctl) return -ENOMEM; - soc_enum = devm_kzalloc(dev, sizeof(*soc_enum), GFP_KERNEL); + soc_enum = devm_kzalloc_obj(dev, *soc_enum); if (!soc_enum) return -ENOMEM; - texts = devm_kcalloc(dev, range->rows + 3, sizeof(*texts), GFP_KERNEL); + texts = devm_kzalloc_objs(dev, *texts, range->rows + 3); if (!texts) return -ENOMEM; - values = devm_kcalloc(dev, range->rows + 3, sizeof(*values), GFP_KERNEL); + values = devm_kzalloc_objs(dev, *values, range->rows + 3); if (!values) return -ENOMEM; @@ -587,15 +589,15 @@ static int entity_parse_su_class(struct device *dev, const char **texts; int i; - kctl = devm_kzalloc(dev, sizeof(*kctl), GFP_KERNEL); + kctl = devm_kzalloc_obj(dev, *kctl); if (!kctl) return -ENOMEM; - soc_enum = devm_kzalloc(dev, sizeof(*soc_enum), GFP_KERNEL); + soc_enum = devm_kzalloc_obj(dev, *soc_enum); if (!soc_enum) return -ENOMEM; - texts = devm_kcalloc(dev, entity->num_sources + 1, sizeof(*texts), GFP_KERNEL); + texts = devm_kzalloc_objs(dev, *texts, entity->num_sources + 1); if (!texts) return -ENOMEM; @@ -677,7 +679,7 @@ static int entity_parse_mu(struct device *dev, dev_warn(dev, "%s: unexpected access layer: %x\n", entity->label, control->layers); - kctl = devm_kcalloc(dev, entity->num_sources, sizeof(*kctl), GFP_KERNEL); + kctl = devm_kzalloc_objs(dev, *kctl, entity->num_sources); if (!kctl) return -ENOMEM; @@ -690,7 +692,7 @@ static int entity_parse_mu(struct device *dev, if (!control_name) return -ENOMEM; - mc = devm_kzalloc(dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(dev, *mc); if (!mc) return -ENOMEM; @@ -946,7 +948,7 @@ static int control_limit_kctl(struct device *dev, min = sign_extend32(min, control->nbits - 1); max = sign_extend32(max, control->nbits - 1); - tlv = devm_kcalloc(dev, 4, sizeof(*tlv), GFP_KERNEL); + tlv = devm_kzalloc_objs(dev, *tlv, 4); if (!tlv) return -ENOMEM; @@ -1034,7 +1036,7 @@ static int populate_control(struct device *dev, if (!control_name) return -ENOMEM; - mc = devm_kzalloc(dev, sizeof(*mc), GFP_KERNEL); + mc = devm_kzalloc_obj(dev, *mc); if (!mc) return -ENOMEM; @@ -1392,19 +1394,19 @@ int sdca_asoc_populate_component(struct device *dev, if (ret) return ret; - widgets = devm_kcalloc(dev, num_widgets, sizeof(*widgets), GFP_KERNEL); + widgets = devm_kzalloc_objs(dev, *widgets, num_widgets); if (!widgets) return -ENOMEM; - routes = devm_kcalloc(dev, num_routes, sizeof(*routes), GFP_KERNEL); + routes = devm_kzalloc_objs(dev, *routes, num_routes); if (!routes) return -ENOMEM; - controls = devm_kcalloc(dev, num_controls, sizeof(*controls), GFP_KERNEL); + controls = devm_kzalloc_objs(dev, *controls, num_controls); if (!controls) return -ENOMEM; - dais = devm_kcalloc(dev, num_dais, sizeof(*dais), GFP_KERNEL); + dais = devm_kzalloc_objs(dev, *dais, num_dais); if (!dais) return -ENOMEM; @@ -1434,39 +1436,55 @@ int sdca_asoc_populate_component(struct device *dev, } EXPORT_SYMBOL_NS(sdca_asoc_populate_component, "SND_SOC_SDCA"); +struct sdca_asoc_constraints { + struct snd_pcm_hw_constraint_list channels; + u64 width; +}; + /** - * sdca_asoc_set_constraints - constrain channels available on a DAI - * @dev: Pointer to the device, used for error messages. - * @regmap: Pointer to the Function register map. - * @function: Pointer to the Function information. - * @substream: Pointer to the PCM substream. + * sdca_asoc_alloc_constraints - allocate a constraint structure on the DAI * @dai: Pointer to the ASoC DAI. * - * Typically called from startup(). + * Typically called from DAI probe(). * * Return: Returns zero on success, and a negative error code on failure. */ -int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap, - struct sdca_function_data *function, - struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) +int sdca_asoc_alloc_constraints(struct snd_soc_dai *dai) { - static const unsigned int channel_list[] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - }; - struct sdca_entity *entity = &function->entities[dai->id]; - struct snd_pcm_hw_constraint_list *constraint; - struct sdca_control_range *range; - struct sdca_control *control; - unsigned int channel_mask = 0; - int i, ret; + struct sdca_asoc_constraints *constraints; - static_assert(ARRAY_SIZE(channel_list) == SDCA_MAX_CHANNEL_COUNT); - static_assert(sizeof(channel_mask) * BITS_PER_BYTE >= SDCA_MAX_CHANNEL_COUNT); + constraints = kzalloc_obj(*constraints); + if (!constraints) + return -ENOMEM; - if (entity->type != SDCA_ENTITY_TYPE_IT) - return 0; + snd_soc_dai_set_priv(dai, constraints); + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_alloc_constraints, "SND_SOC_SDCA"); + +/** + * sdca_asoc_free_constraints - free constraint allocations + * @dai: Pointer to the ASoC DAI. + * + * Typically called from DAI remove(). + * + * Return: Returns zero on success, and a negative error code on failure. + */ +int sdca_asoc_free_constraints(struct snd_soc_dai *dai) +{ + kfree(snd_soc_dai_to_priv(dai)); + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_free_constraints, "SND_SOC_SDCA"); + +static int get_cluster_mask(struct device *dev, struct sdca_function_data *function, + struct sdca_entity *entity, unsigned int *ch_mask) +{ + struct sdca_control_range *range; + struct sdca_control *control; + int i; control = sdca_selector_find_control(dev, entity, SDCA_CTL_IT_CLUSTERINDEX); if (!control) @@ -1476,6 +1494,8 @@ int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap, if (!range) return -EINVAL; + *ch_mask = 0; + for (i = 0; i < range->rows; i++) { int clusterid = sdca_range(range, SDCA_CLUSTER_CLUSTERID, i); struct sdca_cluster *cluster; @@ -1484,50 +1504,176 @@ int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap, if (!cluster) return -ENODEV; - channel_mask |= (1 << (cluster->num_channels - 1)); + *ch_mask |= BIT(cluster->num_channels - 1); } - dev_dbg(dev, "%s: set channel constraint mask: %#x\n", - entity->label, channel_mask); + return 0; +} - constraint = kzalloc_obj(*constraint); - if (!constraint) - return -ENOMEM; +static u64 get_word_mask(unsigned int width) +{ + switch (width) { + case 8: + return SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8; + case 16: + return SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE; + case 18: + return SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE | + SNDRV_PCM_FMTBIT_S18_3BE | SNDRV_PCM_FMTBIT_U18_3BE; + case 20: + return SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_U20_LE | + SNDRV_PCM_FMTBIT_S20_BE | SNDRV_PCM_FMTBIT_U20_BE | + SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | + SNDRV_PCM_FMTBIT_S20_3BE | SNDRV_PCM_FMTBIT_U20_3BE; + case 24: + return SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE | + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE | + SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_U24_3BE; + case 32: + return SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE | + SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE; + default: + return 0; + } +} - constraint->count = ARRAY_SIZE(channel_list); - constraint->list = channel_list; - constraint->mask = channel_mask; +static int get_port_masks(struct sdw_slave *sdw, unsigned int port, + struct snd_pcm_substream *substream, + u64 *word_mask, unsigned int *ch_mask) +{ + struct sdw_dpn_prop *prop; + unsigned int nprop; + int i, j; - ret = snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - constraint); - if (ret) { - dev_err(dev, "%s: failed to add constraint: %d\n", entity->label, ret); - kfree(constraint); - return ret; + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + prop = sdw->prop.sink_dpn_prop; + nprop = hweight32(sdw->prop.sink_ports); + } else { + prop = sdw->prop.src_dpn_prop; + nprop = hweight32(sdw->prop.source_ports); } - snd_soc_dai_set_priv(dai, constraint); + *word_mask = 0; + *ch_mask = 0; - return 0; + for (i = 0; i < nprop; i++) { + if (prop[i].num != port) + continue; + + if (prop[i].num_words) { + for (j = 0; j < prop[i].num_words; j++) + *word_mask |= get_word_mask(prop[i].words[j]); + } else { + unsigned int max = prop[i].max_word; + + if (!max || max > 32) + max = 32; + + for (j = MAX(1, prop[i].min_word); j <= max; j++) + *word_mask |= get_word_mask(j); + } + + /* Only handle the number of channels for constraints. */ + if (prop[i].num_ch_combinations) { + for (j = 0; j < prop[i].num_ch_combinations; j++) + *ch_mask |= BIT(hweight32(prop[i].ch_combinations[j]) - 1); + } else if (prop[i].num_channels) { + *ch_mask = GENMASK(prop[i].num_channels - 1, 0); + } else { + *ch_mask = GENMASK(prop[i].max_ch - prop[i].min_ch, 0); + } + + return 0; + } + + return -ENODEV; } -EXPORT_SYMBOL_NS(sdca_asoc_set_constraints, "SND_SOC_SDCA"); /** - * sdca_asoc_free_constraints - free constraint allocations + * sdca_asoc_set_constraints - constrain channels available on a DAI + * @dev: Pointer to the device, used for error messages. + * @sdw: Pointer to the SoundWire peripheral device. + * @regmap: Pointer to the Function register map. + * @function: Pointer to the Function information. * @substream: Pointer to the PCM substream. * @dai: Pointer to the ASoC DAI. * - * Typically called from shutdown(). + * Typically called from startup(). + * + * Return: Returns zero on success, and a negative error code on failure. */ -void sdca_asoc_free_constraints(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) +int sdca_asoc_set_constraints(struct device *dev, struct sdw_slave *sdw, + struct regmap *regmap, + struct sdca_function_data *function, + struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) { - struct snd_pcm_hw_constraint_list *constraint = snd_soc_dai_to_priv(dai); + static const unsigned int channel_list[] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + }; + struct sdca_asoc_constraints *constraints = snd_soc_dai_to_priv(dai); + struct sdca_entity *entity = &function->entities[dai->id]; + unsigned int port_ch_mask, cluster_ch_mask; + int port; + int ret; - kfree(constraint); + static_assert(ARRAY_SIZE(channel_list) == SDCA_MAX_CHANNEL_COUNT); + static_assert(sizeof(cluster_ch_mask) * BITS_PER_BYTE >= SDCA_MAX_CHANNEL_COUNT); + + /* FIXME: Currently only a single unshared port is supported */ + port = sdca_asoc_get_port(dev, regmap, function, dai); + if (port < 0) + return port; + + ret = get_port_masks(sdw, port, substream, &constraints->width, &port_ch_mask); + if (ret < 0) { + dev_err(dev, "%s: no properties for port %d\n", entity->label, port); + return ret; + } + + /* FIXME: OTs should inherit cluster information */ + if (entity->type == SDCA_ENTITY_TYPE_IT) { + ret = get_cluster_mask(dev, function, entity, &cluster_ch_mask); + if (ret) + return ret; + } else { + cluster_ch_mask = UINT_MAX; + } + + constraints->channels.count = ARRAY_SIZE(channel_list); + constraints->channels.list = channel_list; + constraints->channels.mask = cluster_ch_mask & port_ch_mask; + + if (!constraints->channels.mask || !constraints->width) { + dev_err(dev, "%s: no valid constraint masks channel: %#x,%#x width: %#llx\n", + entity->label, cluster_ch_mask, port_ch_mask, constraints->width); + return -EINVAL; + } + + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + &constraints->channels); + if (ret) { + dev_err(dev, "%s: failed to add channel constraint: %d\n", + entity->label, ret); + return ret; + } + + ret = snd_pcm_hw_constraint_mask64(substream->runtime, + SNDRV_PCM_HW_PARAM_FORMAT, + constraints->width); + if (ret) { + dev_err(dev, "%s: failed to add bit width constraint: %d\n", + entity->label, ret); + return ret; + } + + return 0; } -EXPORT_SYMBOL_NS(sdca_asoc_free_constraints, "SND_SOC_SDCA"); +EXPORT_SYMBOL_NS(sdca_asoc_set_constraints, "SND_SOC_SDCA"); /** * sdca_asoc_get_port - return SoundWire port for a DAI diff --git a/sound/soc/sdca/sdca_class.c b/sound/soc/sdca/sdca_class.c index ee61c983dc574b..7676c96243492d 100644 --- a/sound/soc/sdca/sdca_class.c +++ b/sound/soc/sdca/sdca_class.c @@ -217,7 +217,7 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id * bare sdca_class_drv here and stash it in drvdata for the * built-in PM ops to fetch. */ - drv = devm_kzalloc(&sdw->dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(&sdw->dev, *drv); if (!drv) return -ENOMEM; diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c index 13b70f0f0dbf7e..1f0b5954a948cd 100644 --- a/sound/soc/sdca/sdca_class_function.c +++ b/sound/soc/sdca/sdca_class_function.c @@ -121,8 +121,9 @@ static int class_function_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct class_function_drv *drv = snd_soc_component_get_drvdata(dai->component); + struct sdw_slave *sdw = dev_to_sdw_dev(drv->dev->parent); - return sdca_asoc_set_constraints(drv->dev, drv->regmap, drv->function, + return sdca_asoc_set_constraints(drv->dev, sdw, drv->regmap, drv->function, substream, dai); } @@ -184,8 +185,9 @@ static int class_function_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stre } static const struct snd_soc_dai_ops class_function_sdw_ops = { + .probe = sdca_asoc_alloc_constraints, + .remove = sdca_asoc_free_constraints, .startup = class_function_startup, - .shutdown = sdca_asoc_free_constraints, .set_stream = class_function_sdw_set_stream, .hw_params = class_function_sdw_add_peripheral, .hw_free = class_function_sdw_remove_peripheral, @@ -340,7 +342,7 @@ static int class_function_probe(struct auxiliary_device *auxdev, int num_dais; int ret; - drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc_obj(dev, *drv); if (!drv) return -ENOMEM; @@ -378,7 +380,7 @@ static int class_function_probe(struct auxiliary_device *auxdev, if (ndefaults < 0) return ndefaults; - defaults = devm_kcalloc(dev, ndefaults, sizeof(*defaults), GFP_KERNEL); + defaults = devm_kzalloc_objs(dev, *defaults, ndefaults); if (!defaults) return -ENOMEM; diff --git a/sound/soc/sdca/sdca_functions.c b/sound/soc/sdca/sdca_functions.c index 1eb6418e132dcb..122a1dd9dc3614 100644 --- a/sound/soc/sdca/sdca_functions.c +++ b/sound/soc/sdca/sdca_functions.c @@ -240,7 +240,7 @@ static int find_sdca_init_table(struct device *dev, num_init_writes /= sizeof(*raw); - init_write = devm_kcalloc(dev, num_init_writes, sizeof(*init_write), GFP_KERNEL); + init_write = devm_kzalloc_objs(dev, *init_write, num_init_writes); if (!init_write) return -ENOMEM; @@ -851,7 +851,7 @@ static int find_sdca_control_range(struct device *dev, { u8 *range_list; int num_range; - u16 *limits; + __le16 *limits; int i; num_range = fwnode_property_count_u8(control_node, "mipi-sdca-control-range"); @@ -869,7 +869,7 @@ static int find_sdca_control_range(struct device *dev, fwnode_property_read_u8_array(control_node, "mipi-sdca-control-range", range_list, num_range); - limits = (u16 *)range_list; + limits = (__le16 *)range_list; range->cols = le16_to_cpu(limits[0]); range->rows = le16_to_cpu(limits[1]); @@ -880,7 +880,7 @@ static int find_sdca_control_range(struct device *dev, return -EINVAL; for (i = 0; i < num_range; i++) - range->data[i] = le32_to_cpu(range->data[i]); + le32_to_cpus(&range->data[i]); return 0; } @@ -988,8 +988,8 @@ static int find_sdca_entity_control(struct device *dev, struct sdca_entity *enti return ret; } - control->values = devm_kcalloc(dev, hweight64(control->cn_list), - sizeof(*control->values), GFP_KERNEL); + control->values = devm_kzalloc_objs(dev, *control->values, + hweight64(control->cn_list)); if (!control->values) return -ENOMEM; @@ -1085,7 +1085,7 @@ static int find_sdca_entity_controls(struct device *dev, } num_controls = hweight64(control_list); - controls = devm_kcalloc(dev, num_controls, sizeof(*controls), GFP_KERNEL); + controls = devm_kzalloc_objs(dev, *controls, num_controls); if (!controls) return -ENOMEM; @@ -1259,7 +1259,7 @@ static int find_sdca_entity_pde(struct device *dev, num_delays /= mult_delay; - delays = devm_kcalloc(dev, num_delays, sizeof(*delays), GFP_KERNEL); + delays = devm_kzalloc_objs(dev, *delays, num_delays); if (!delays) return -ENOMEM; @@ -1324,8 +1324,7 @@ static int find_sdca_entity_ge(struct device *dev, group->num_modes = *affected_list; affected_iter = affected_list + 1; - group->modes = devm_kcalloc(dev, group->num_modes, sizeof(*group->modes), - GFP_KERNEL); + group->modes = devm_kzalloc_objs(dev, *group->modes, group->num_modes); if (!group->modes) return -ENOMEM; @@ -1344,8 +1343,8 @@ static int find_sdca_entity_ge(struct device *dev, if (affected_iter > affected_list + num_affected) goto bad_list; - mode->controls = devm_kcalloc(dev, mode->num_controls, - sizeof(*mode->controls), GFP_KERNEL); + mode->controls = devm_kzalloc_objs(dev, *mode->controls, + mode->num_controls); if (!mode->controls) return -ENOMEM; @@ -1386,8 +1385,8 @@ static int find_sdca_entity_hide(struct device *dev, return num_reports; } else if (num_reports > 0) { hide->num_hidtx_ids = num_reports; - hide->hidtx_ids = devm_kcalloc(dev, hide->num_hidtx_ids, - sizeof(*hide->hidtx_ids), GFP_KERNEL); + hide->hidtx_ids = devm_kzalloc_objs(dev, *hide->hidtx_ids, + hide->num_hidtx_ids); if (!hide->hidtx_ids) return -ENOMEM; @@ -1404,8 +1403,8 @@ static int find_sdca_entity_hide(struct device *dev, return num_reports; } else if (num_reports > 0) { hide->num_hidrx_ids = num_reports; - hide->hidrx_ids = devm_kcalloc(dev, hide->num_hidrx_ids, - sizeof(*hide->hidrx_ids), GFP_KERNEL); + hide->hidrx_ids = devm_kzalloc_objs(dev, *hide->hidrx_ids, + hide->num_hidrx_ids); if (!hide->hidrx_ids) return -ENOMEM; @@ -1547,7 +1546,7 @@ static int find_sdca_entities(struct device *dev, struct fwnode_handle *function } /* Add 1 to make space for Entity 0 */ - entities = devm_kcalloc(dev, num_entities + 1, sizeof(*entities), GFP_KERNEL); + entities = devm_kzalloc_objs(dev, *entities, num_entities + 1); if (!entities) return -ENOMEM; @@ -1710,7 +1709,7 @@ static int find_sdca_entity_connection_pde(struct device *dev, return -EINVAL; } - managed = devm_kcalloc(dev, num_managed, sizeof(*managed), GFP_KERNEL); + managed = devm_kzalloc_objs(dev, *managed, num_managed); if (!managed) return -ENOMEM; @@ -1827,7 +1826,7 @@ static int find_sdca_entity_connection(struct device *dev, } num_pins = hweight64(pin_list); - pins = devm_kcalloc(dev, num_pins, sizeof(*pins), GFP_KERNEL); + pins = devm_kzalloc_objs(dev, *pins, num_pins); if (!pins) return -ENOMEM; @@ -1977,7 +1976,7 @@ static int find_sdca_cluster_channels(struct device *dev, return -EINVAL; } - channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL); + channels = devm_kzalloc_objs(dev, *channels, num_channels); if (!channels) return -ENOMEM; @@ -2027,7 +2026,7 @@ static int find_sdca_clusters(struct device *dev, return -EINVAL; } - clusters = devm_kcalloc(dev, num_clusters, sizeof(*clusters), GFP_KERNEL); + clusters = devm_kzalloc_objs(dev, *clusters, num_clusters); if (!clusters) return -ENOMEM; @@ -2098,7 +2097,7 @@ static int find_sdca_filesets(struct device *dev, struct fwnode_handle *function fwnode_property_read_u32_array(function_node, "mipi-sdca-file-set-id-list", filesets_list, num_sets); - sets = devm_kcalloc(dev, num_sets, sizeof(*sets), GFP_KERNEL); + sets = devm_kzalloc_objs(dev, *sets, num_sets); if (!sets) return -ENOMEM; @@ -2123,8 +2122,8 @@ static int find_sdca_filesets(struct device *dev, struct fwnode_handle *function dev_dbg(dev, "fileset: %#x\n", filesets_list[i]); - files = devm_kcalloc(dev, num_entries / mult_fileset, - sizeof(*files), GFP_KERNEL); + files = devm_kzalloc_objs(dev, *files, + num_entries / mult_fileset); if (!files) return -ENOMEM; diff --git a/sound/soc/sdca/sdca_interrupts.c b/sound/soc/sdca/sdca_interrupts.c index 7aebc721a847f5..2c3f160939690e 100644 --- a/sound/soc/sdca/sdca_interrupts.c +++ b/sound/soc/sdca/sdca_interrupts.c @@ -642,7 +642,7 @@ struct sdca_interrupt_info *devm_sdca_irq_allocate(struct device *sdev, struct sdca_interrupt_info *info; int ret, i; - info = devm_kzalloc(sdev, sizeof(*info), GFP_KERNEL); + info = devm_kzalloc_obj(sdev, *info); if (!info) return ERR_PTR(-ENOMEM); diff --git a/sound/soc/sdw_utils/soc_sdw_senary_dmic.c b/sound/soc/sdw_utils/soc_sdw_senary_dmic.c index 7481706561f9bc..725f4658ec9c7d 100644 --- a/sound/soc/sdw_utils/soc_sdw_senary_dmic.c +++ b/sound/soc/sdw_utils/soc_sdw_senary_dmic.c @@ -15,6 +15,10 @@ static const struct snd_soc_dapm_route senary_dmic_map[] = { { "sn624x DMIC", NULL, "Dmic" }, }; +static const struct snd_soc_dapm_route senary_dmic_map_bare[] = { + { "DMIC", NULL, "Dmic" }, +}; + int asoc_sdw_senary_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai) { struct snd_soc_card *card = rtd->card; @@ -25,14 +29,21 @@ int asoc_sdw_senary_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_so component = dai->component; - ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map, - ARRAY_SIZE(senary_dmic_map)); + if (component->name_prefix) { + ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map, + ARRAY_SIZE(senary_dmic_map)); + mic_name = devm_kstrdup(card->dev, component->name_prefix, GFP_KERNEL); + } else { + dev_warn(card->dev, "sn624x dmic: component %s has no name_prefix\n", + component->name); + ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map_bare, + ARRAY_SIZE(senary_dmic_map_bare)); + mic_name = devm_kstrdup(card->dev, "sn624x", GFP_KERNEL); + } if (ret) { dev_err(card->dev, "senary dmic map addition failed: %d\n", ret); return ret; } - - mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s", component->name_prefix); if (!mic_name) return -ENOMEM; diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c index 5c2cd75307c9e2..0adde845a3dd05 100644 --- a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c +++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c @@ -18,6 +18,10 @@ static const struct snd_soc_dapm_route sn624x_spk_map[] = { { "Speaker", NULL, "sn624x SPK" }, }; +static const struct snd_soc_dapm_route sn624x_spk_map_bare[] = { + { "Speaker", NULL, "SPK" }, +}; + /* Structure to map codec names to respective route arrays and sizes */ struct codec_route_map { const char *codec_name; @@ -45,16 +49,30 @@ int asoc_sdw_senary_sdca_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct sn struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); int ret; - /* Match by DAI name prefix (e.g. sn624x-sdca-aif2). */ const struct codec_route_map *route_map = get_codec_route_map(dai->name); + const struct snd_soc_dapm_route *routes; + size_t nroutes; if (!route_map) { dev_err(rtd->dev, "failed to get codec name and route map\n"); return -EINVAL; } - /* Add routes */ - ret = snd_soc_dapm_add_routes(dapm, route_map->route_map, route_map->route_size); + /* + * No name_prefix means the codec widgets were created as "SPK", + * not "sn624x SPK". DAI name is still sn624x-sdca-aif2. + */ + if (!dai->component->name_prefix) { + dev_warn(rtd->dev, "sn624x spk: component %s has no name_prefix\n", + dai->component->name); + routes = sn624x_spk_map_bare; + nroutes = ARRAY_SIZE(sn624x_spk_map_bare); + } else { + routes = route_map->route_map; + nroutes = route_map->route_size; + } + + ret = snd_soc_dapm_add_routes(dapm, routes, nroutes); if (ret) dev_err(rtd->dev, "failed to add rt sdca spk map: %d\n", ret); diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c index 1dab6f99877df1..c61c1f16065b4f 100644 --- a/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c +++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c @@ -57,6 +57,12 @@ static const struct snd_soc_dapm_route senary_sdca_jack_map[] = { { "sn624x MIC2", NULL, "Headset Mic" }, }; +/* Widget names stay bare when codec_conf did not apply a name_prefix. */ +static const struct snd_soc_dapm_route senary_sdca_jack_map_bare[] = { + { "Headphone", NULL, "HP" }, + { "MIC2", NULL, "Headset Mic" }, +}; + static struct snd_soc_jack_pin senary_sdca_jack_pins[] = { { .pin = "Headphone", @@ -68,10 +74,6 @@ static struct snd_soc_jack_pin senary_sdca_jack_pins[] = { }, }; -static const char * const need_sdca_suffix[] = { - "sn624x" -}; - int asoc_sdw_senary_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai) { struct snd_soc_card *card = rtd->card; @@ -79,38 +81,41 @@ int asoc_sdw_senary_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct s struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); struct snd_soc_component *component; struct snd_soc_jack *jack; + const struct snd_soc_dapm_route *routes = senary_sdca_jack_map; + const char *prefix; + int nroutes = ARRAY_SIZE(senary_sdca_jack_map); int ret; - int i; component = dai->component; + prefix = component->name_prefix; + /* + * codec_conf should set name_prefix to "sn624x" before DAPM widgets + * are created. If that match fails, name_prefix is NULL: strstr() + * oopses, and the widgets keep the bare names from the codec driver. + */ + if (!prefix) { + dev_warn(card->dev, + "sn624x jack: component %s has no name_prefix\n", + component->name); + prefix = "sn624x"; + routes = senary_sdca_jack_map_bare; + nroutes = ARRAY_SIZE(senary_sdca_jack_map_bare); + } else if (!strstr(prefix, "sn624x")) { + dev_err(card->dev, "%s is not supported\n", prefix); + return -EINVAL; + } + card->components = devm_kasprintf(card->dev, GFP_KERNEL, - "%s hs:%s", - card->components, component->name_prefix); + "%s hs:%s-sdca", + card->components, prefix); if (!card->components) return -ENOMEM; - for (i = 0; i < ARRAY_SIZE(need_sdca_suffix); i++) { - if (!strstr(component->name_prefix, need_sdca_suffix[i])) - continue; - - card->components = devm_kasprintf(card->dev, GFP_KERNEL, - "%s-sdca", card->components); - if (!card->components) - return -ENOMEM; - - ret = snd_soc_dapm_add_routes(dapm, senary_sdca_jack_map, - ARRAY_SIZE(senary_sdca_jack_map)); - if (ret) { - dev_err(card->dev, - "senary sdca jack map addition failed: %d\n", ret); - return ret; - } - break; - } - - if (i == ARRAY_SIZE(need_sdca_suffix)) { - dev_err(card->dev, "%s is not supported\n", component->name_prefix); - return -EINVAL; + ret = snd_soc_dapm_add_routes(dapm, routes, nroutes); + if (ret) { + dev_err(card->dev, "senary sdca jack map addition failed: %d\n", + ret); + return ret; } ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c index 7a19de75f32b53..b6acf7616d147f 100644 --- a/sound/soc/sdw_utils/soc_sdw_utils.c +++ b/sound/soc/sdw_utils/soc_sdw_utils.c @@ -1492,8 +1492,9 @@ struct asoc_sdw_codec_info codec_info_list[] = { .dai_num = 1, }, /* - * Senary SN6242/6244/6247: same SDCA jack/amp/mic topology; only part_id - * differs. name_prefix stays "sn624x" for UCM/DAI naming. + * Senary SN6242/6244/6245/6247: same SDCA jack/amp/mic topology; only + * part_id differs. SN6245 is register-compatible with SN6244. + * name_prefix stays "sn624x" for UCM/DAI naming. */ { .vendor_id = 0x0496, @@ -1546,6 +1547,57 @@ struct asoc_sdw_codec_info codec_info_list[] = { }, .dai_num = 3, }, + { + .vendor_id = 0x0496, + .part_id = 0x6245, + .name_prefix = "sn624x", + .ignore_internal_dmic = true, + .dais = { + { + .direction = {true, true}, + .dai_name = "sn624x-sdca-aif", + .dai_type = SOC_SDW_DAI_TYPE_JACK, + .dailink = {SOC_SDW_JACK_OUT_DAI_ID, SOC_SDW_JACK_IN_DAI_ID}, + .init = asoc_sdw_senary_sdca_jack_init, + .exit = asoc_sdw_senary_sdca_jack_exit, + .rtd_init = asoc_sdw_senary_sdca_jack_rtd_init, + .controls = generic_jack_controls, + .num_controls = ARRAY_SIZE(generic_jack_controls), + .widgets = generic_jack_widgets, + .num_widgets = ARRAY_SIZE(generic_jack_widgets), + }, + { + .direction = {true, false}, + .dai_name = "sn624x-sdca-aif2", + .component_name = "sn624x", + .dai_type = SOC_SDW_DAI_TYPE_AMP, + .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID}, + .init = asoc_sdw_senary_amp_init, + .exit = asoc_sdw_senary_amp_exit, + .rtd_init = asoc_sdw_senary_sdca_spk_rtd_init, + .controls = generic_spk_controls, + .num_controls = ARRAY_SIZE(generic_spk_controls), + .widgets = generic_spk_widgets, + .num_widgets = ARRAY_SIZE(generic_spk_widgets), + .quirk = SOC_SDW_CODEC_SPKR, + .quirk_exclude = true, + }, + { + .direction = {false, true}, + .dai_name = "sn624x-sdca-aif3", + .dai_type = SOC_SDW_DAI_TYPE_MIC, + .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID}, + .rtd_init = asoc_sdw_senary_dmic_rtd_init, + .widgets = sn624x_dmic_widgets, + .num_widgets = ARRAY_SIZE(sn624x_dmic_widgets), + .controls = sn624x_dmic_controls, + .num_controls = ARRAY_SIZE(sn624x_dmic_controls), + .quirk = SOC_SDW_CODEC_MIC, + .quirk_exclude = true, + }, + }, + .dai_num = 3, + }, { .vendor_id = 0x0496, .part_id = 0x6247, @@ -2199,7 +2251,7 @@ int asoc_sdw_init_simple_dai_link(struct device *dev, struct snd_soc_dai_link *d struct snd_soc_dai_link_component *dlc; /* Allocate three DLCs one for the CPU, one for platform and one for the CODEC */ - dlc = devm_kcalloc(dev, 3, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_objs(dev, *dlc, 3); if (!dlc || !name || !cpu_dai_name || !platform_comp_name || !codec_name || !codec_dai_name) return -ENOMEM; diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c index 9d38b38d88df74..8d2e66885c3f13 100644 --- a/sound/soc/soc-ac97.c +++ b/sound/soc/soc-ac97.c @@ -135,7 +135,7 @@ static int snd_soc_ac97_init_gpio(struct snd_ac97 *ac97, struct snd_ac97_gpio_priv *gpio_priv; int ret; - gpio_priv = devm_kzalloc(component->dev, sizeof(*gpio_priv), GFP_KERNEL); + gpio_priv = devm_kzalloc_obj(component->dev, *gpio_priv); if (!gpio_priv) return -ENOMEM; ac97->gpio_priv = gpio_priv; diff --git a/sound/soc/soc-acpi.c b/sound/soc/soc-acpi.c index 270f9777942f02..a344d497aa874c 100644 --- a/sound/soc/soc-acpi.c +++ b/sound/soc/soc-acpi.c @@ -4,10 +4,12 @@ // // Copyright (c) 2013-15, Intel Corporation. +#include #include #include #include +#if IS_ENABLED(CONFIG_ACPI) static bool snd_soc_acpi_id_present(struct snd_soc_acpi_mach *machine) { const struct snd_soc_acpi_codecs *comp_ids = machine->comp_ids; @@ -124,6 +126,7 @@ struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg) return mach; } EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list); +#endif /* CONFIG_ACPI */ #define SDW_CODEC_ADR_MASK(_adr) ((_adr) & (SDW_DISCO_LINK_ID_MASK | SDW_VERSION_MASK | \ SDW_MFG_ID_MASK | SDW_PART_ID_MASK)) @@ -200,5 +203,57 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev, } EXPORT_SYMBOL_GPL(snd_soc_acpi_sdw_link_slaves_found); +int snd_soc_acpi_sof_get_platform_name(struct device *dev, + const struct snd_soc_acpi_mach *mach, char *platform) +{ + int ret; + + /* platform must hold at least SND_SOC_ACPI_SOF_PLATFORM_NAME_MAX bytes */ + ret = sscanf(mach->sof_tplg_filename, "sof-%7[^-]-*.tplg", platform); + if (ret != 1) { + dev_err(dev, "Invalid platform name of tplg %s\n", + mach->sof_tplg_filename); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_acpi_sof_get_platform_name); + +char *snd_soc_acpi_sof_get_tplg_filename(struct device *dev, const char *prefix, + const char *platform, const char *tplg_dev_name, + int dai_link_id, + enum snd_soc_acpi_tplg_device_id tplg_dev) +{ + char *filename = NULL; + + /* + * The tplg file naming rule is sof---id.tplg + * where is required for functions that depend on NHLT blobs (e.g. DMIC/SSP) + * as the nhlt blob is platform dependent. + */ + switch (tplg_dev) { + case SND_SOC_ACPI_TPLG_DEVICE_PCH_DMIC: + case SND_SOC_ACPI_TPLG_DEVICE_SSP_JACK: + case SND_SOC_ACPI_TPLG_DEVICE_SSP_AMP: + case SND_SOC_ACPI_TPLG_DEVICE_SSP_BT: + case SND_SOC_ACPI_TPLG_DEVICE_SSP_HDMI_IN: + case SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_JACK: + case SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_AMP: + case SND_SOC_ACPI_TPLG_DEVICE_ACP_SDW_MIC: + case SND_SOC_ACPI_TPLG_DEVICE_ACP_DMIC: + filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-%s-id%d.tplg", + prefix, platform, tplg_dev_name, dai_link_id); + break; + default: + filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-id%d.tplg", + prefix, tplg_dev_name, dai_link_id); + break; + } + + return filename; +} +EXPORT_SYMBOL_GPL(snd_soc_acpi_sof_get_tplg_filename); + MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("ALSA SoC ACPI module"); diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index a941ed0908c667..afaaac45459476 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -774,12 +774,11 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd) else direction = SND_COMPRESS_CAPTURE; - compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL); + compr = devm_kzalloc_obj(rtd->card->dev, *compr); if (!compr) return -ENOMEM; - compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), - GFP_KERNEL); + compr->ops = devm_kzalloc_obj(rtd->card->dev, soc_compr_ops); if (!compr->ops) return -ENOMEM; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ac72d9357840ac..7dfd79b4ca3e56 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -361,16 +361,18 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( /* * for rtd */ - rtd = devm_kzalloc(dev, - struct_size(rtd, components, - dai_link->num_cpus + - dai_link->num_codecs + - dai_link->num_platforms), - GFP_KERNEL); + rtd = devm_kzalloc_flex(dev, *rtd, components, + dai_link->num_cpus + dai_link->num_codecs + dai_link->num_platforms); if (!rtd) { device_unregister(dev); return NULL; } + /* + * devm_kzalloc_flex() presets the __counted_by() counter to the + * allocated size when the compiler has __builtin_counted_by_ref(), + * but snd_soc_rtd_add_component() expects it to start from zero. + */ + rtd->num_components = 0; rtd->dev = dev; INIT_LIST_HEAD(&rtd->list); @@ -389,9 +391,8 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( /* * for rtd->dais */ - rtd->dais = devm_kcalloc(dev, dai_link->num_cpus + dai_link->num_codecs, - sizeof(struct snd_soc_dai *), - GFP_KERNEL); + rtd->dais = devm_kzalloc_objs(dev, struct snd_soc_dai *, + dai_link->num_cpus + dai_link->num_codecs); if (!rtd->dais) goto free_rtd; @@ -594,7 +595,7 @@ EXPORT_SYMBOL_GPL(snd_soc_resume); struct of_phandle_args *snd_soc_copy_dai_args(struct device *dev, const struct of_phandle_args *args) { - struct of_phandle_args *ret = devm_kzalloc(dev, sizeof(*ret), GFP_KERNEL); + struct of_phandle_args *ret = devm_kzalloc_obj(dev, *ret); if (!ret) return NULL; @@ -1473,7 +1474,7 @@ struct snd_soc_component *snd_soc_component_new(struct device *dev, const char * { struct snd_soc_component *component; - component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL); + component = devm_kzalloc_obj(dev, *component); if (!component) return ERR_PTR(-ENOMEM); @@ -1653,8 +1654,7 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, num_widgets /= 2; - widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), - GFP_KERNEL); + widgets = devm_kzalloc_objs(card->dev, *widgets, num_widgets); if (!widgets) { dev_err(card->dev, "ASoC: Could not allocate memory for widgets\n"); @@ -1718,8 +1718,7 @@ int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop) if (!of_property_present(dev->of_node, prop)) return 0; - strings = devm_kcalloc(dev, nb_controls_max, - sizeof(*strings), GFP_KERNEL); + strings = devm_kzalloc_objs(dev, *strings, nb_controls_max); if (!strings) return -ENOMEM; @@ -1730,8 +1729,7 @@ int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop) nb_controls = (unsigned int)ret; - controls = devm_kcalloc(dev, nb_controls, - sizeof(*controls), GFP_KERNEL); + controls = devm_kzalloc_objs(dev, *controls, nb_controls); if (!controls) return -ENOMEM; @@ -1882,8 +1880,7 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, } num_routes /= 2; - routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes), - GFP_KERNEL); + routes = devm_kzalloc_objs(card->dev, *routes, num_routes); if (!routes) { dev_err(card->dev, "ASoC: Could not allocate DAPM route table\n"); @@ -1931,7 +1928,7 @@ int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname) return num; } - aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL); + aux = devm_kzalloc_objs(card->dev, *aux, num); if (!aux) return -ENOMEM; card->aux_dev = aux; @@ -2369,7 +2366,7 @@ static int __snd_soc_of_get_dai_link_component_alloc( dev_err(dev, "Bad phandle in 'sound-dai'\n"); return num; } - component = devm_kcalloc(dev, num, sizeof(*component), GFP_KERNEL); + component = devm_kzalloc_objs(dev, *component, num); if (!component) return -ENOMEM; @@ -2395,6 +2392,18 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) } EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs); +/* dai_name belongs to the component, which can unbind before the card. */ +static int snd_soc_of_dup_dai_name(struct device *dev, + struct snd_soc_dai_link_component *dlc) +{ + if (!dlc->dai_name) + return 0; + + dlc->dai_name = devm_kstrdup_const(dev, dlc->dai_name, GFP_KERNEL); + + return dlc->dai_name ? 0 : -ENOMEM; +} + /* * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree * @dev: Card device @@ -2424,6 +2433,8 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev, /* Parse the list */ for_each_link_codecs(dai_link, index, component) { ret = snd_soc_of_get_dlc(of_node, NULL, component, index); + if (!ret) + ret = snd_soc_of_dup_dai_name(dev, component); if (ret) goto err; } @@ -2479,6 +2490,8 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev, /* Parse the list */ for_each_link_cpus(dai_link, index, component) { ret = snd_soc_of_get_dlc(of_node, NULL, component, index); + if (!ret) + ret = snd_soc_of_dup_dai_name(dev, component); if (ret) goto err; } diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c index d124b6afb1b8d6..9e34f34eac3d8a 100644 --- a/sound/soc/soc-dai.c +++ b/sound/soc/soc-dai.c @@ -1235,7 +1235,7 @@ struct snd_soc_dai *snd_soc_dai_register(struct snd_soc_component *component, lockdep_assert_held(&client_mutex); - dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL); + dai = devm_kzalloc_obj(dev, *dai); if (dai == NULL) return NULL; diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index eff6103cb21b83..3ef13d2b1f5e9c 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -193,7 +193,7 @@ static void dapm_pop_dbg(struct device *dev, const char *fmt, ...) struct snd_soc_dapm_context *snd_soc_dapm_alloc(struct device *dev) { - return devm_kzalloc(dev, sizeof(struct snd_soc_dapm_context), GFP_KERNEL); + return devm_kzalloc_obj(dev, struct snd_soc_dapm_context); } struct device *snd_soc_dapm_to_dev(struct snd_soc_dapm_context *dapm) diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index d750dc44981d9d..c7523bae45af76 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -389,6 +389,9 @@ static int dmaengine_pcm_request_chan_of(struct dmaengine_pcm *pcm, name = dmaengine_pcm_dma_channel_names[i]; if (config->chan_names[i]) name = config->chan_names[i]; + else if (config->dma_dev) + /* Default names refer to the dma_dev's own channels */ + continue; chan = dma_request_chan(dev, name); if (IS_ERR(chan)) { /* diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 35cbe29d227589..7e53e84292205c 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -650,7 +650,7 @@ static int soc_tplg_control_dmixer_create(struct soc_tplg *tplg, struct snd_kcon if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) return -EINVAL; - sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL); + sm = devm_kzalloc_obj(tplg->dev, *sm); if (!sm) return -ENOMEM; @@ -746,9 +746,9 @@ static int soc_tplg_denum_create_values(struct soc_tplg *tplg, struct soc_enum * if (le32_to_cpu(ec->items) > SND_SOC_TPLG_NUM_TEXTS) return -EINVAL; - se->dobj.control.dvalues = devm_kcalloc(tplg->dev, le32_to_cpu(ec->items), - sizeof(*se->dobj.control.dvalues), - GFP_KERNEL); + se->dobj.control.dvalues = devm_kzalloc_objs(tplg->dev, + *se->dobj.control.dvalues, + le32_to_cpu(ec->items)); if (!se->dobj.control.dvalues) return -ENOMEM; @@ -774,7 +774,7 @@ static int soc_tplg_control_denum_create(struct soc_tplg *tplg, struct snd_kcont if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) return -EINVAL; - se = devm_kzalloc(tplg->dev, sizeof(*se), GFP_KERNEL); + se = devm_kzalloc_obj(tplg->dev, *se); if (!se) return -ENOMEM; @@ -843,7 +843,7 @@ static int soc_tplg_control_dbytes_create(struct soc_tplg *tplg, struct snd_kcon if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) return -EINVAL; - sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL); + sbe = devm_kzalloc_obj(tplg->dev, *sbe); if (!sbe) return -ENOMEM; @@ -1048,7 +1048,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, le32_to_cpu(hdr->index)); for (i = 0; i < count; i++) { - route = devm_kzalloc(tplg->dev, sizeof(*route), GFP_KERNEL); + route = devm_kzalloc_obj(tplg->dev, *route); if (!route) return -ENOMEM; elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos; @@ -1159,14 +1159,14 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg, } template.num_kcontrols = le32_to_cpu(w->num_kcontrols); - kc = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(*kc), GFP_KERNEL); + kc = devm_kzalloc_objs(tplg->dev, *kc, le32_to_cpu(w->num_kcontrols)); if (!kc) { ret = -ENOMEM; goto hdr_err; } - kcontrol_type = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(unsigned int), - GFP_KERNEL); + kcontrol_type = devm_kzalloc_objs(tplg->dev, unsigned int, + le32_to_cpu(w->num_kcontrols)); if (!kcontrol_type) { ret = -ENOMEM; goto hdr_err; @@ -1391,7 +1391,7 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg, struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(tplg->comp); int ret; - dai_drv = devm_kzalloc(tplg->dev, sizeof(struct snd_soc_dai_driver), GFP_KERNEL); + dai_drv = devm_kzalloc_obj(tplg->dev, struct snd_soc_dai_driver); if (dai_drv == NULL) return -ENOMEM; @@ -2245,3 +2245,19 @@ int snd_soc_tplg_component_remove(struct snd_soc_component *comp) return !list_empty(&comp->dobj_list); } EXPORT_SYMBOL_GPL(snd_soc_tplg_component_remove); + +bool snd_soc_tplg_files_exist(struct device *dev, const char *tplg_files) +{ + const struct firmware *fw; + int ret; + + ret = firmware_request_nowarn(&fw, tplg_files, dev); + if (!ret) { + release_firmware(fw); + return true; + } + + dev_warn(dev, "Failed to open topology file: %s\n", tplg_files); + return false; +} +EXPORT_SYMBOL_GPL(snd_soc_tplg_files_exist); diff --git a/sound/soc/sof/amd/acp-common.c b/sound/soc/sof/amd/acp-common.c index 3bb1de8c03762f..8bd45932a110c7 100644 --- a/sound/soc/sof/amd/acp-common.c +++ b/sound/soc/sof/amd/acp-common.c @@ -164,9 +164,8 @@ static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev * mach->mach_params.platform = dev_name(sdev->dev); if (acp_data->pdm_sel) { - pdm_pdata = devm_kzalloc(sdev->dev, - sizeof(*pdm_pdata), - GFP_KERNEL); + pdm_pdata = devm_kzalloc_obj(sdev->dev, + *pdm_pdata); if (!pdm_pdata) return NULL; pdm_pdata->pdm_sel = acp_data->pdm_sel; @@ -216,7 +215,7 @@ struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev) mach->mach_params.subsystem_rev = acp_data->pci_rev; if (acp_data->pdm_sel) { - pdm_pdata = devm_kzalloc(sdev->dev, sizeof(*pdm_pdata), GFP_KERNEL); + pdm_pdata = devm_kzalloc_obj(sdev->dev, *pdm_pdata); if (!pdm_pdata) return NULL; pdm_pdata->pdm_sel = acp_data->pdm_sel; diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c index 120dde4ab7773b..0d208df621e295 100644 --- a/sound/soc/sof/amd/acp.c +++ b/sound/soc/sof/amd/acp.c @@ -478,16 +478,20 @@ static void amd_sof_handle_acp70_sdw_wake_event(struct acp_dev_data *adata) struct amd_sdw_manager *amd_manager; if (adata->acp70_sdw0_wake_event) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); - if (amd_manager) - pm_request_resume(amd_manager->dev); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); + if (amd_manager) + pm_request_resume(amd_manager->dev); + } adata->acp70_sdw0_wake_event = 0; } if (adata->acp70_sdw1_wake_event) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); - if (amd_manager) - pm_request_resume(amd_manager->dev); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); + if (amd_manager) + pm_request_resume(amd_manager->dev); + } adata->acp70_sdw1_wake_event = 0; } } @@ -579,10 +583,12 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id) val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, desc->ext_intr_stat); if (val & ACP_SDW0_IRQ_MASK) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_stat, ACP_SDW0_IRQ_MASK); - if (amd_manager) - schedule_work(&amd_manager->amd_sdw_irq_thread); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); + if (amd_manager) + schedule_work(&amd_manager->amd_sdw_irq_thread); + } irq_flag = 1; } @@ -608,11 +614,13 @@ static irqreturn_t acp_irq_handler(int irq, void *dev_id) if (desc->ext_intr_stat1) { val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, desc->ext_intr_stat1); if (val & ACP_SDW1_IRQ_MASK) { - amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); snd_sof_dsp_write(sdev, ACP_DSP_BAR, desc->ext_intr_stat1, ACP_SDW1_IRQ_MASK); - if (amd_manager) - schedule_work(&amd_manager->amd_sdw_irq_thread); + if (adata->sdw) { + amd_manager = dev_get_drvdata(&adata->sdw->pdev[1]->dev); + if (amd_manager) + schedule_work(&amd_manager->amd_sdw_irq_thread); + } irq_flag = 1; } switch (adata->pci_rev) { @@ -1212,6 +1220,27 @@ static int amd_sof_sdw_exit(struct snd_sof_dev *sdev) } #endif +/* + * The PSP validates the signed DSP firmware, so it must be signed with the + * scheme the platform firmware uses: images for the alternative scheme are + * named with an "_l" suffix before the extension, the default ones have none. + */ +static int amd_sof_acp_get_fw_suffix(struct snd_sof_dev *sdev, const char **suffix) +{ + u32 val; + int ret; + + ret = amd_smn_read(0, MP0_C2PMSG_63_REG, &val); + if (ret) { + dev_err(sdev->dev, "PSP firmware signing type read failed (err %d)\n", ret); + return ret; + } + + *suffix = (val & MP0_C2PMSG_63_FW_SIGN_ALT) ? "_l" : ""; + + return 0; +} + int amd_sof_acp_probe(struct snd_sof_dev *sdev) { struct pci_dev *pci = to_pci_dev(sdev->dev); @@ -1226,8 +1255,7 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev) dev_err(sdev->dev, "no such device supported, chip id:%x\n", pci->device); return -EIO; } - adata = devm_kzalloc(sdev->dev, sizeof(struct acp_dev_data), - GFP_KERNEL); + adata = devm_kzalloc_obj(sdev->dev, struct acp_dev_data); if (!adata) return -ENOMEM; @@ -1365,7 +1393,7 @@ int amd_sof_acp7x_probe(struct snd_sof_dev *sdev) dev_err(sdev->dev, "no such device supported, chip id:%x\n", pci->device); return -EIO; } - adata = devm_kzalloc(sdev->dev, sizeof(struct acp_dev_data), GFP_KERNEL); + adata = devm_kzalloc_obj(sdev->dev, struct acp_dev_data); if (!adata) return -ENOMEM; @@ -1447,8 +1475,14 @@ int amd_sof_acp7x_probe(struct snd_sof_dev *sdev) sdev->debug_box.size = BOX_SIZE_1024; if (adata->acp_sof_signed_firmware_image) { + const char *fw_suffix; + + ret = amd_sof_acp_get_fw_suffix(sdev, &fw_suffix); + if (ret) + goto free_ipc_irq; + adata->fw_code_bin = devm_kasprintf(sdev->dev, GFP_KERNEL, - "sof-%s-code.bin", chip->name); + "sof-%s-code%s.bin", chip->name, fw_suffix); if (!adata->fw_code_bin) { ret = -ENOMEM; goto free_ipc_irq; diff --git a/sound/soc/sof/amd/acp.h b/sound/soc/sof/amd/acp.h index aaf934461e721e..649e8facf4e994 100644 --- a/sound/soc/sof/amd/acp.h +++ b/sound/soc/sof/amd/acp.h @@ -97,6 +97,8 @@ #define ACP_EXT_INTR_ERROR_STAT 0x20000000 #define MP0_C2PMSG_114_REG 0x3810AC8 #define MP0_C2PMSG_73_REG 0x3810A24 +#define MP0_C2PMSG_63_REG 0x38109FC +#define MP0_C2PMSG_63_FW_SIGN_ALT BIT(6) #define MBOX_ACP_SHA_DMA_COMMAND 0x70000 #define MBOX_ACP_IRAM_DRAM_FENCE_COMMAND 0x80000 #define MBOX_DELAY_US 1000 diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 1f38fe03e49395..ee01991c00a66f 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -248,7 +248,7 @@ static int sof_machine_check(struct snd_sof_dev *sdev) nocodec: /* select nocodec mode */ dev_warn(sdev->dev, "Using nocodec machine driver\n"); - mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL); + mach = devm_kzalloc_obj(sdev->dev, *mach); if (!mach) return -ENOMEM; @@ -653,7 +653,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data) struct snd_sof_dev *sdev; int ret; - sdev = devm_kzalloc(dev, sizeof(*sdev), GFP_KERNEL); + sdev = devm_kzalloc_obj(dev, *sdev); if (!sdev) return -ENOMEM; diff --git a/sound/soc/sof/debug.c b/sound/soc/sof/debug.c index 9801c875dd7018..48728902df7a28 100644 --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -121,7 +121,7 @@ static int snd_sof_debugfs_io_item(struct snd_sof_dev *sdev, if (!sdev) return -EINVAL; - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return -ENOMEM; @@ -177,7 +177,7 @@ int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev, if (!sdev) return -EINVAL; - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return -ENOMEM; @@ -297,7 +297,7 @@ int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev) { struct snd_sof_dfsentry *dfse; - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return -ENOMEM; diff --git a/sound/soc/sof/imx/imx-common.c b/sound/soc/sof/imx/imx-common.c index 436fe49246ba80..0d113955b432e6 100644 --- a/sound/soc/sof/imx/imx-common.c +++ b/sound/soc/sof/imx/imx-common.c @@ -349,7 +349,7 @@ static int imx_probe(struct snd_sof_dev *sdev) pdev = to_platform_device(sdev->dev); - common = devm_kzalloc(sdev->dev, sizeof(*common), GFP_KERNEL); + common = devm_kzalloc_obj(sdev->dev, *common); if (!common) return -ENOMEM; diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c index 0820724dbb3491..5cd3f44c90d2bb 100644 --- a/sound/soc/sof/imx/imx8.c +++ b/sound/soc/sof/imx/imx8.c @@ -181,7 +181,7 @@ static int imx8m_probe(struct snd_sof_dev *sdev) common = sdev->pdata->hw_pdata; - chip = devm_kzalloc(sdev->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(sdev->dev, *chip); if (!chip) return -ENOMEM; diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index 7a8875a885ab34..60134d34b0528a 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -809,7 +809,7 @@ void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) struct sof_ipc4_fw_data *ipc4_data = sdev->private; struct snd_ipc4_nhlt *entry; - entry = devm_kzalloc(sdev->dev, sizeof(*entry), GFP_KERNEL); + entry = devm_kzalloc_obj(sdev->dev, *entry); if (!entry) return; diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index bdd4831e050ce1..e2da0d4d1a5f0b 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -995,8 +995,7 @@ int hda_dsp_stream_init(struct snd_sof_dev *sdev) for (i = 0; i < num_total; i++) { struct sof_intel_hda_stream *hda_stream; - hda_stream = devm_kzalloc(sdev->dev, sizeof(*hda_stream), - GFP_KERNEL); + hda_stream = devm_kzalloc_obj(sdev->dev, *hda_stream); if (!hda_stream) return -ENOMEM; diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index 45e968fb19104b..b223ce08d45194 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -788,7 +788,7 @@ int hda_dsp_probe_early(struct snd_sof_dev *sdev) sdev->num_cores = chip->cores_num; - hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc_obj(sdev->dev, *hdev); if (!hdev) return -ENOMEM; sdev->pdata->hw_pdata = hdev; @@ -1179,7 +1179,7 @@ static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev, link->mask = BIT(sdw_device->bus->link_id); /* index is 0 based, we need allocate index + 1 for the array size */ if (!index) - adr_dev = devm_kzalloc(dev, sizeof(*adr_dev), GFP_KERNEL); + adr_dev = devm_kzalloc_obj(dev, *adr_dev); else adr_dev = devm_krealloc(dev, (struct snd_soc_acpi_adr_device *)link->adr_d, (index + 1) * sizeof(*adr_dev), GFP_KERNEL); @@ -1197,8 +1197,8 @@ static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev, if (sdw_device->id.part_id != codec_info_list[i].part_id) continue; - endpoints = devm_kcalloc(dev, codec_info_list[i].dai_num, - sizeof(struct snd_soc_acpi_endpoint), GFP_KERNEL); + endpoints = devm_kzalloc_objs(dev, struct snd_soc_acpi_endpoint, + codec_info_list[i].dai_num); if (!endpoints) return NULL; @@ -1409,7 +1409,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev return NULL; /* Create default SDW mach */ - mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL); + mach = devm_kzalloc_obj(sdev->dev, *mach); if (!mach) return NULL; @@ -1419,7 +1419,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev link_num = hweight32(link_mask); /* An empty adr_link is needed to terminate the adr_link loop */ - links = devm_kcalloc(sdev->dev, link_num + 1, sizeof(*links), GFP_KERNEL); + links = devm_kzalloc_objs(sdev->dev, *links, link_num + 1); if (!links) return NULL; diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index bc11519427649f..4b984361ecee1d 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -758,7 +758,6 @@ int hda_dsp_ipc_get_mailbox_offset(struct snd_sof_dev *sdev); int hda_dsp_ipc_get_window_offset(struct snd_sof_dev *sdev, u32 id); irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context); -int hda_dsp_ipc_cmd_done(struct snd_sof_dev *sdev, int dir); void hda_dsp_get_state(struct snd_sof_dev *sdev, const char *level); void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, const char *level, diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index e6d8894b8ef60c..8c6c1f71d7cc44 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -148,7 +148,7 @@ struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev) struct snd_sof_ipc_msg *msg; const struct sof_ipc_ops *ops; - ipc = devm_kzalloc(sdev->dev, sizeof(*ipc), GFP_KERNEL); + ipc = devm_kzalloc_obj(sdev->dev, *ipc); if (!ipc) return NULL; diff --git a/sound/soc/sof/ipc3-control.c b/sound/soc/sof/ipc3-control.c index d1697401b1da0d..b1d00a2a860ab5 100644 --- a/sound/soc/sof/ipc3-control.c +++ b/sound/soc/sof/ipc3-control.c @@ -743,7 +743,7 @@ sof_ipc3_set_up_volume_table(struct snd_sof_control *scontrol, int tlv[SOF_TLV_I int i; /* init the volume table */ - scontrol->volume_table = kcalloc(size, sizeof(u32), GFP_KERNEL); + scontrol->volume_table = kzalloc_objs(u32, size); if (!scontrol->volume_table) return -ENOMEM; diff --git a/sound/soc/sof/ipc3-dtrace.c b/sound/soc/sof/ipc3-dtrace.c index e8c998c09dc30f..71a3ae19a5bbb1 100644 --- a/sound/soc/sof/ipc3-dtrace.c +++ b/sound/soc/sof/ipc3-dtrace.c @@ -232,7 +232,7 @@ static int debugfs_create_trace_filter(struct snd_sof_dev *sdev) { struct snd_sof_dfsentry *dfse; - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return -ENOMEM; @@ -409,7 +409,7 @@ static int debugfs_create_dtrace(struct snd_sof_dev *sdev) if (ret < 0) dev_warn(sdev->dev, "failed to create filter debugfs file: %d", ret); - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return -ENOMEM; @@ -506,7 +506,7 @@ static int ipc3_dtrace_init(struct snd_sof_dev *sdev) return -EBUSY; } - priv = devm_kzalloc(sdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(sdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sof/ipc4-compress.c b/sound/soc/sof/ipc4-compress.c index 97a4ec7519055e..780f99fb73d4c0 100644 --- a/sound/soc/sof/ipc4-compress.c +++ b/sound/soc/sof/ipc4-compress.c @@ -474,7 +474,7 @@ static int sof_ipc4_compr_set_params(struct snd_soc_component *component, goto free_list; } - compr_data = kzalloc(sizeof(*compr_data), GFP_KERNEL); + compr_data = kzalloc_obj(*compr_data); if (!compr_data) { ret = -ENOMEM; goto free_list; diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c index 8d86d32a16caea..e29c8d89284af7 100644 --- a/sound/soc/sof/ipc4-control.c +++ b/sound/soc/sof/ipc4-control.c @@ -1003,7 +1003,7 @@ sof_ipc4_set_up_volume_table(struct snd_sof_control *scontrol, int tlv[SOF_TLV_I int i; /* init the volume table */ - scontrol->volume_table = kcalloc(size, sizeof(u32), GFP_KERNEL); + scontrol->volume_table = kzalloc_objs(u32, size); if (!scontrol->volume_table) return -ENOMEM; diff --git a/sound/soc/sof/ipc4-loader.c b/sound/soc/sof/ipc4-loader.c index 1da51f7490e579..a043fe1c1766a2 100644 --- a/sound/soc/sof/ipc4-loader.c +++ b/sound/soc/sof/ipc4-loader.c @@ -88,8 +88,8 @@ static ssize_t sof_ipc4_fw_parse_ext_man(struct snd_sof_dev *sdev, sdev->fw_version.build = fw_header->build_version; } - fw_lib->modules = devm_kmalloc_array(sdev->dev, fw_header->num_module_entries, - sizeof(*fw_module), GFP_KERNEL); + fw_lib->modules = devm_kmalloc_objs(sdev->dev, *fw_module, + fw_header->num_module_entries); if (!fw_lib->modules) return -ENOMEM; @@ -150,9 +150,9 @@ static size_t sof_ipc4_fw_parse_basefw_ext_man(struct snd_sof_dev *sdev) int ret; if (sdev->dsp_test_mode_enabled) - fw_lib = devm_kzalloc(sdev->dev, sizeof(*fw_lib), GFP_KERNEL); + fw_lib = devm_kzalloc_obj(sdev->dev, *fw_lib); else - fw_lib = devm_kzalloc(sdev->dev, sizeof(*fw_lib), GFP_KERNEL); + fw_lib = devm_kzalloc_obj(sdev->dev, *fw_lib); if (!fw_lib) return -ENOMEM; @@ -191,7 +191,7 @@ static int sof_ipc4_load_library(struct snd_sof_dev *sdev, unsigned long lib_id, return -EOPNOTSUPP; } - fw_lib = devm_kzalloc(sdev->dev, sizeof(*fw_lib), GFP_KERNEL); + fw_lib = devm_kzalloc_obj(sdev->dev, *fw_lib); if (!fw_lib) return -ENOMEM; diff --git a/sound/soc/sof/ipc4-mtrace.c b/sound/soc/sof/ipc4-mtrace.c index 667dda3f043978..4eaa6e110a08ce 100644 --- a/sound/soc/sof/ipc4-mtrace.c +++ b/sound/soc/sof/ipc4-mtrace.c @@ -530,8 +530,7 @@ static int ipc4_mtrace_init(struct snd_sof_dev *sdev) return 0; } - priv = devm_kzalloc(sdev->dev, struct_size(priv, cores, sdev->num_cores), - GFP_KERNEL); + priv = devm_kzalloc_flex(sdev->dev, *priv, cores, sdev->num_cores); if (!priv) return -ENOMEM; diff --git a/sound/soc/sof/ipc4-telemetry.c b/sound/soc/sof/ipc4-telemetry.c index ddc3bc494ffefe..66f45954cb9125 100644 --- a/sound/soc/sof/ipc4-telemetry.c +++ b/sound/soc/sof/ipc4-telemetry.c @@ -80,7 +80,7 @@ void sof_ipc4_create_exception_debugfs_node(struct snd_sof_dev *sdev) { struct snd_sof_dfsentry *dfse; - dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL); + dfse = devm_kzalloc_obj(sdev->dev, *dfse); if (!dfse) return; diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c index 4e72a1a93d34aa..a8f7088da7924e 100644 --- a/sound/soc/sof/ipc4-topology.c +++ b/sound/soc/sof/ipc4-topology.c @@ -1319,7 +1319,7 @@ static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget) ret = sof_ipc4_widget_setup_msg(swidget, &process->msg); if (ret) - goto err; + goto free_available_fmt; /* parse process init module payload config type from module info */ fw_module = swidget->module_info; @@ -4186,7 +4186,7 @@ static int sof_ipc4_parse_manifest(struct snd_soc_component *scomp, int index, switch (le32_to_cpu(manifest_tlv->type)) { case SOF_MANIFEST_DATA_TYPE_NHLT: /* Get the nhlt from topology manifest */ - tplg_nhlt = devm_kzalloc(sdev->dev, sizeof(*tplg_nhlt), GFP_KERNEL); + tplg_nhlt = devm_kzalloc_obj(sdev->dev, *tplg_nhlt); if (!tplg_nhlt) return -ENOMEM; diff --git a/sound/soc/sof/mediatek/mt8186/mt8186-clk.c b/sound/soc/sof/mediatek/mt8186/mt8186-clk.c index cb2ab5884b8c08..4b82637fc582b3 100644 --- a/sound/soc/sof/mediatek/mt8186/mt8186-clk.c +++ b/sound/soc/sof/mediatek/mt8186/mt8186-clk.c @@ -27,7 +27,7 @@ int mt8186_adsp_init_clock(struct snd_sof_dev *sdev) struct device *dev = sdev->dev; int i; - priv->clk = devm_kcalloc(dev, ADSP_CLK_MAX, sizeof(*priv->clk), GFP_KERNEL); + priv->clk = devm_kzalloc_objs(dev, *priv->clk, ADSP_CLK_MAX); if (!priv->clk) return -ENOMEM; diff --git a/sound/soc/sof/mediatek/mt8186/mt8186.c b/sound/soc/sof/mediatek/mt8186/mt8186.c index a5ccee87e684e3..5d3b8bf766d5d9 100644 --- a/sound/soc/sof/mediatek/mt8186/mt8186.c +++ b/sound/soc/sof/mediatek/mt8186/mt8186.c @@ -188,7 +188,7 @@ static int mt8186_dsp_probe(struct snd_sof_dev *sdev) struct adsp_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -196,7 +196,7 @@ static int mt8186_dsp_probe(struct snd_sof_dev *sdev) priv->dev = sdev->dev; priv->sdev = sdev; - priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); + priv->adsp = devm_kzalloc_obj(&pdev->dev, struct mtk_adsp_chip_info); if (!priv->adsp) return -ENOMEM; diff --git a/sound/soc/sof/mediatek/mt8195/mt8195-clk.c b/sound/soc/sof/mediatek/mt8195/mt8195-clk.c index 03b9ee2fa712ee..beadec62eaf609 100644 --- a/sound/soc/sof/mediatek/mt8195/mt8195-clk.c +++ b/sound/soc/sof/mediatek/mt8195/mt8195-clk.c @@ -29,7 +29,7 @@ int mt8195_adsp_init_clock(struct snd_sof_dev *sdev) struct adsp_priv *priv = sdev->pdata->hw_pdata; int i; - priv->clk = devm_kcalloc(dev, ADSP_CLK_MAX, sizeof(*priv->clk), GFP_KERNEL); + priv->clk = devm_kzalloc_objs(dev, *priv->clk, ADSP_CLK_MAX); if (!priv->clk) return -ENOMEM; diff --git a/sound/soc/sof/mediatek/mt8195/mt8195.c b/sound/soc/sof/mediatek/mt8195/mt8195.c index cb30ea04ca580f..7dc0f8084bbf12 100644 --- a/sound/soc/sof/mediatek/mt8195/mt8195.c +++ b/sound/soc/sof/mediatek/mt8195/mt8195.c @@ -178,7 +178,7 @@ static int mt8195_dsp_probe(struct snd_sof_dev *sdev) struct adsp_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -186,7 +186,7 @@ static int mt8195_dsp_probe(struct snd_sof_dev *sdev) priv->dev = sdev->dev; priv->sdev = sdev; - priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); + priv->adsp = devm_kzalloc_obj(&pdev->dev, struct mtk_adsp_chip_info); if (!priv->adsp) return -ENOMEM; diff --git a/sound/soc/sof/nocodec.c b/sound/soc/sof/nocodec.c index 34744f8ae34a7a..ab0cd0a24d75ee 100644 --- a/sound/soc/sof/nocodec.c +++ b/sound/soc/sof/nocodec.c @@ -32,7 +32,7 @@ static int sof_nocodec_bes_setup(struct device *dev, /* set up BE dai_links */ for (i = 0; i < link_num; i++) { - dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc_objs(dev, *dlc, 2); if (!dlc) return -ENOMEM; @@ -75,7 +75,7 @@ static int sof_nocodec_setup(struct device *dev, struct snd_soc_acpi_mach *mach) struct snd_soc_dai_link *links; /* create dummy BE dai_links */ - links = devm_kcalloc(dev, num_dai_drivers, sizeof(struct snd_soc_dai_link), GFP_KERNEL); + links = devm_kzalloc_objs(dev, struct snd_soc_dai_link, num_dai_drivers); if (!links) return -ENOMEM; diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h index 19605de680a319..eb2d0bc59ae05a 100644 --- a/sound/soc/sof/ops.h +++ b/sound/soc/sof/ops.h @@ -727,9 +727,5 @@ bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar, void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar, u32 offset, u32 mask, u32 value); -int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset, - u32 mask, u32 target, u32 timeout_ms, - u32 interval_us); - void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset, bool non_recoverable); #endif diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 68bf1b57093e4d..f84aa3ec303935 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -62,7 +62,7 @@ int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc dev_dbg(dev, "ACPI DSP detected"); - sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); + sof_pdata = devm_kzalloc_obj(dev, *sof_pdata); if (!sof_pdata) return -ENOMEM; diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 10b41ab18b7990..4809e6dce82d60 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -593,8 +593,6 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, unsigned int size); int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data, unsigned int size); -void snd_sof_control_notify(struct snd_sof_dev *sdev, - struct sof_ipc_ctrl_data *cdata); /* * Topology. @@ -603,13 +601,6 @@ void snd_sof_control_notify(struct snd_sof_dev *sdev, */ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file); -/* - * Stream IPC - */ -int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp, - struct snd_sof_pcm *spcm, int direction, - struct sof_ipc_stream_posn *posn); - struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp, const char *name); struct snd_sof_widget * @@ -706,8 +697,6 @@ int sof_widget_list_prepare(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir); void sof_widget_list_unprepare(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir); int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir); -int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev, - struct snd_sof_pcm *spcm); int sof_pcm_free_all_streams(struct snd_sof_dev *sdev); int get_token_u32(void *elem, void *object, u32 offset); int get_token_u16(void *elem, void *object, u32 offset); diff --git a/sound/soc/sof/sof-client-ipc-flood-test.c b/sound/soc/sof/sof-client-ipc-flood-test.c index 2396cc35489a34..0e8a0262b795ac 100644 --- a/sound/soc/sof/sof-client-ipc-flood-test.c +++ b/sound/soc/sof/sof-client-ipc-flood-test.c @@ -290,7 +290,7 @@ static int sof_ipc_flood_probe(struct auxiliary_device *auxdev, struct sof_ipc_flood_priv *priv; /* allocate memory for client data */ - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sof/sof-client-ipc-kernel-injector.c b/sound/soc/sof/sof-client-ipc-kernel-injector.c index 02d0d97ad1a02e..b5bca9258f4251 100644 --- a/sound/soc/sof/sof-client-ipc-kernel-injector.c +++ b/sound/soc/sof/sof-client-ipc-kernel-injector.c @@ -98,7 +98,7 @@ static int sof_msg_inject_probe(struct auxiliary_device *auxdev, size_t alloc_size; /* allocate memory for client data */ - priv = devm_kzalloc(&auxdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&auxdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sof/sof-client-ipc-msg-injector.c b/sound/soc/sof/sof-client-ipc-msg-injector.c index 932ab459c07900..c98307cf7eeee6 100644 --- a/sound/soc/sof/sof-client-ipc-msg-injector.c +++ b/sound/soc/sof/sof-client-ipc-msg-injector.c @@ -261,7 +261,7 @@ static int sof_msg_inject_probe(struct auxiliary_device *auxdev, size_t alloc_size; /* allocate memory for client data */ - priv = devm_kzalloc(&auxdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&auxdev->dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sof/sof-client-probes-ipc4.c b/sound/soc/sof/sof-client-probes-ipc4.c index c547ea61fb3d12..6a7dcfdf7b8e79 100644 --- a/sound/soc/sof/sof-client-probes-ipc4.c +++ b/sound/soc/sof/sof-client-probes-ipc4.c @@ -383,8 +383,7 @@ static int ipc4_probes_points_remove(struct sof_client_dev *cdev, if (!mentry) return -ENODEV; - probe_point_ids = kcalloc(num_buffer_id, sizeof(*probe_point_ids), - GFP_KERNEL); + probe_point_ids = kzalloc_objs(*probe_point_ids, num_buffer_id); if (!probe_point_ids) return -ENOMEM; diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c index 124f5550815927..286486945abd4f 100644 --- a/sound/soc/sof/sof-client-probes.c +++ b/sound/soc/sof/sof-client-probes.c @@ -461,7 +461,7 @@ static int sof_probes_client_probe(struct auxiliary_device *auxdev, return -ENODEV; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; @@ -510,8 +510,8 @@ static int sof_probes_client_probe(struct auxiliary_device *auxdev, priv->dfs_points = debugfs_create_file("probe_points_available", 0644, dfsroot, cdev, &sof_probes_available_points_fops); - links = devm_kcalloc(dev, SOF_PROBES_NUM_DAI_LINKS, sizeof(*links), GFP_KERNEL); - cpus = devm_kcalloc(dev, SOF_PROBES_NUM_DAI_LINKS, sizeof(*cpus), GFP_KERNEL); + links = devm_kzalloc_objs(dev, *links, SOF_PROBES_NUM_DAI_LINKS); + cpus = devm_kzalloc_objs(dev, *cpus, SOF_PROBES_NUM_DAI_LINKS); if (!links || !cpus) { debugfs_remove(priv->dfs_points); debugfs_remove(priv->dfs_points_remove); diff --git a/sound/soc/sof/sof-of-dev.c b/sound/soc/sof/sof-of-dev.c index 3ccfcfb142b7ae..7a7be615e1d98a 100644 --- a/sound/soc/sof/sof-of-dev.c +++ b/sound/soc/sof/sof-of-dev.c @@ -55,7 +55,7 @@ int sof_of_probe(struct platform_device *pdev) dev_info(&pdev->dev, "DT DSP detected"); - sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); + sof_pdata = devm_kzalloc_obj(dev, *sof_pdata); if (!sof_pdata) return -ENOMEM; diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index c50249aadea90a..12c7ff389ba090 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -208,7 +208,7 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) return -ENODEV; } - sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); + sof_pdata = devm_kzalloc_obj(dev, *sof_pdata); if (!sof_pdata) return -ENOMEM; diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 750916b57def74..4dcacafb9cdb4c 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -2519,8 +2519,7 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file) int i; const char **tplg_files __free(kfree) = - kcalloc(scomp->card->num_links, sizeof(*tplg_files), - GFP_KERNEL); + kzalloc_objs(*tplg_files, scomp->card->num_links); if (!tplg_files) return -ENOMEM; diff --git a/sound/soc/sophgo/cv1800b-sound-adc.c b/sound/soc/sophgo/cv1800b-sound-adc.c index bd93e261bdd1d2..5ad4ff52e2c8d8 100644 --- a/sound/soc/sophgo/cv1800b-sound-adc.c +++ b/sound/soc/sophgo/cv1800b-sound-adc.c @@ -288,7 +288,7 @@ static int cv1800b_adc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct cv1800b_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sophgo/cv1800b-sound-dac.c b/sound/soc/sophgo/cv1800b-sound-dac.c index 135322bcf6ad16..014a37d971f13c 100644 --- a/sound/soc/sophgo/cv1800b-sound-dac.c +++ b/sound/soc/sophgo/cv1800b-sound-dac.c @@ -173,7 +173,7 @@ static int cv1800b_dac_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct cv1800b_priv *priv; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/sophgo/cv1800b-tdm.c b/sound/soc/sophgo/cv1800b-tdm.c index 4badb6e3e08bae..a70b7281b0159e 100644 --- a/sound/soc/sophgo/cv1800b-tdm.c +++ b/sound/soc/sophgo/cv1800b-tdm.c @@ -638,7 +638,7 @@ static int cv1800b_i2s_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c index 28a7627692532d..6e68decd0c27f4 100644 --- a/sound/soc/spacemit/k1_i2s.c +++ b/sound/soc/spacemit/k1_i2s.c @@ -425,7 +425,7 @@ static int spacemit_i2s_probe(struct platform_device *pdev) struct clk *clk; int ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/spear/spdif_in.c b/sound/soc/spear/spdif_in.c index dd1e176193afd2..5d4c908ca4d0a0 100644 --- a/sound/soc/spear/spdif_in.c +++ b/sound/soc/spear/spdif_in.c @@ -212,7 +212,7 @@ static int spdif_in_probe(struct platform_device *pdev) if (!res_fifo) return -EINVAL; - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/sound/soc/spear/spdif_out.c b/sound/soc/spear/spdif_out.c index 01dc2cef744801..bddd49fc7b327f 100644 --- a/sound/soc/spear/spdif_out.c +++ b/sound/soc/spear/spdif_out.c @@ -282,7 +282,7 @@ static int spdif_out_probe(struct platform_device *pdev) struct resource *res; int ret; - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/sound/soc/sprd/sprd-mcdt.c b/sound/soc/sprd/sprd-mcdt.c index d9a7bbd6c0b688..289e95ce15ab82 100644 --- a/sound/soc/sprd/sprd-mcdt.c +++ b/sound/soc/sprd/sprd-mcdt.c @@ -913,7 +913,7 @@ static int sprd_mcdt_probe(struct platform_device *pdev) struct resource *res; int ret, irq; - mcdt = devm_kzalloc(&pdev->dev, sizeof(*mcdt), GFP_KERNEL); + mcdt = devm_kzalloc_obj(&pdev->dev, *mcdt); if (!mcdt) return -ENOMEM; diff --git a/sound/soc/sprd/sprd-pcm-compress.c b/sound/soc/sprd/sprd-pcm-compress.c index a810c9c8a0b5b1..e9ef50f183375e 100644 --- a/sound/soc/sprd/sprd-pcm-compress.c +++ b/sound/soc/sprd/sprd-pcm-compress.c @@ -342,7 +342,7 @@ static int sprd_platform_compr_open(struct snd_soc_component *component, if (ret) return ret; - stream = devm_kzalloc(dev, sizeof(*stream), GFP_KERNEL); + stream = devm_kzalloc_obj(dev, *stream); if (!stream) return -ENOMEM; diff --git a/sound/soc/sprd/sprd-pcm-dma.c b/sound/soc/sprd/sprd-pcm-dma.c index 968901ae4c335e..ba0784efa91005 100644 --- a/sound/soc/sprd/sprd-pcm-dma.c +++ b/sound/soc/sprd/sprd-pcm-dma.c @@ -74,7 +74,7 @@ static int sprd_pcm_open(struct snd_soc_component *component, if (ret < 0) return ret; - dma_private = devm_kzalloc(dev, sizeof(*dma_private), GFP_KERNEL); + dma_private = devm_kzalloc_obj(dev, *dma_private); if (!dma_private) return -ENOMEM; @@ -219,7 +219,7 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component, sg_num = totsize / period; dma_private->dma_addr_offset = totsize / channels; - sg = devm_kcalloc(component->dev, sg_num, sizeof(*sg), GFP_KERNEL); + sg = devm_kzalloc_objs(component->dev, *sg, sg_num); if (!sg) { ret = -ENOMEM; goto sg_err; diff --git a/sound/soc/starfive/jh7110_pwmdac.c b/sound/soc/starfive/jh7110_pwmdac.c index 5953c3a4e37320..329932b1997c88 100644 --- a/sound/soc/starfive/jh7110_pwmdac.c +++ b/sound/soc/starfive/jh7110_pwmdac.c @@ -446,7 +446,7 @@ static int jh7110_pwmdac_probe(struct platform_device *pdev) struct resource *res; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, *dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/starfive/jh7110_tdm.c b/sound/soc/starfive/jh7110_tdm.c index f7522bfbe8e685..44971cf99446c7 100644 --- a/sound/soc/starfive/jh7110_tdm.c +++ b/sound/soc/starfive/jh7110_tdm.c @@ -576,7 +576,7 @@ static int jh7110_tdm_probe(struct platform_device *pdev) struct jh7110_tdm_dev *tdm; int ret; - tdm = devm_kzalloc(&pdev->dev, sizeof(*tdm), GFP_KERNEL); + tdm = devm_kzalloc_obj(&pdev->dev, *tdm); if (!tdm) return -ENOMEM; diff --git a/sound/soc/sti/sti_uniperif.c b/sound/soc/sti/sti_uniperif.c index a7956e5a4ee5d1..3fbd9fee94acab 100644 --- a/sound/soc/sti/sti_uniperif.c +++ b/sound/soc/sti/sti_uniperif.c @@ -405,7 +405,7 @@ static int sti_uniperiph_cpu_dai_of(struct device_node *node, } dev_data = (struct sti_uniperiph_dev_data *)of_id->data; - uni = devm_kzalloc(dev, sizeof(*uni), GFP_KERNEL); + uni = devm_kzalloc_obj(dev, *uni); if (!uni) return -ENOMEM; @@ -468,10 +468,10 @@ static int sti_uniperiph_probe(struct platform_device *pdev) int ret; /* Allocate the private data and the CPU_DAI array */ - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; - priv->dai = devm_kzalloc(&pdev->dev, sizeof(*priv->dai), GFP_KERNEL); + priv->dai = devm_kzalloc_obj(&pdev->dev, *priv->dai); if (!priv->dai) return -ENOMEM; diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c index 018f775f36bb8b..083dc4c2627487 100644 --- a/sound/soc/stm/stm32_adfsdm.c +++ b/sound/soc/stm/stm32_adfsdm.c @@ -326,7 +326,7 @@ static int stm32_adfsdm_probe(struct platform_device *pdev) struct stm32_adfsdm_priv *priv; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, *priv); if (!priv) return -ENOMEM; @@ -357,9 +357,7 @@ static int stm32_adfsdm_probe(struct platform_device *pdev) return ret; } - ret = devm_snd_soc_register_component(&pdev->dev, - &stm32_adfsdm_soc_platform, - NULL, 0); + ret = snd_soc_register_component(&pdev->dev, &stm32_adfsdm_soc_platform, NULL, 0); if (ret < 0) return ret; diff --git a/sound/soc/stm/stm32_i2s.c b/sound/soc/stm/stm32_i2s.c index 22196f789ae4a4..79465be82cb8b4 100644 --- a/sound/soc/stm/stm32_i2s.c +++ b/sound/soc/stm/stm32_i2s.c @@ -545,7 +545,7 @@ static int stm32_i2s_add_mclk_provider(struct stm32_i2s_data *i2s) char *mclk_name, *p, *s = (char *)pname; int ret, i = 0; - mclk = devm_kzalloc(dev, sizeof(*mclk), GFP_KERNEL); + mclk = devm_kzalloc_obj(dev, *mclk); if (!mclk) return -ENOMEM; @@ -1147,8 +1147,7 @@ static int stm32_i2s_dais_init(struct platform_device *pdev, { struct snd_soc_dai_driver *dai_ptr; - dai_ptr = devm_kzalloc(&pdev->dev, sizeof(struct snd_soc_dai_driver), - GFP_KERNEL); + dai_ptr = devm_kzalloc_obj(&pdev->dev, struct snd_soc_dai_driver); if (!dai_ptr) return -ENOMEM; @@ -1269,7 +1268,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) u32 val; int irq, ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/stm/stm32_sai.c b/sound/soc/stm/stm32_sai.c index 00cf24ceca2d4a..c5d092d07b8240 100644 --- a/sound/soc/stm/stm32_sai.c +++ b/sound/soc/stm/stm32_sai.c @@ -183,7 +183,7 @@ static int stm32_sai_probe(struct platform_device *pdev) u32 val; int ret; - sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); + sai = devm_kzalloc_obj(&pdev->dev, *sai); if (!sai) return -ENOMEM; diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index d00377efe3f99f..5d88507b4d0f0f 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -571,7 +571,7 @@ static int stm32_sai_add_mclk_provider(struct stm32_sai_sub_data *sai) char *mclk_name, *p, *s = (char *)pname; int ret, i = 0; - mclk = devm_kzalloc(dev, sizeof(*mclk), GFP_KERNEL); + mclk = devm_kzalloc_obj(dev, *mclk); if (!mclk) return -ENOMEM; @@ -1675,7 +1675,7 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) const struct snd_dmaengine_pcm_config *conf = &stm32_sai_pcm_config; int ret; - sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); + sai = devm_kzalloc_obj(&pdev->dev, *sai); if (!sai) return -ENOMEM; diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c index 44467a25fb69a4..f6f7d4aaa94dae 100644 --- a/sound/soc/stm/stm32_spdifrx.c +++ b/sound/soc/stm/stm32_spdifrx.c @@ -401,8 +401,7 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev, return dev_err_probe(dev, PTR_ERR(spdifrx->ctrl_chan), "dma_request_chan error\n"); - spdifrx->dmab = devm_kzalloc(dev, sizeof(struct snd_dma_buffer), - GFP_KERNEL); + spdifrx->dmab = devm_kzalloc_obj(dev, struct snd_dma_buffer); if (!spdifrx->dmab) return -ENOMEM; @@ -424,10 +423,8 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev, ret = dmaengine_slave_config(spdifrx->ctrl_chan, &spdifrx->slave_config); - if (ret < 0) { + if (ret < 0) dev_err(dev, "dmaengine_slave_config returned error %d\n", ret); - spdifrx->ctrl_chan = NULL; - } return ret; }; @@ -945,7 +942,7 @@ static int stm32_spdifrx_probe(struct platform_device *pdev) u32 ver, idr; int ret; - spdifrx = devm_kzalloc(&pdev->dev, sizeof(*spdifrx), GFP_KERNEL); + spdifrx = devm_kzalloc_obj(&pdev->dev, *spdifrx); if (!spdifrx) return -ENOMEM; diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c index ff56700a9fe9cc..9d5bc3d7b4dfab 100644 --- a/sound/soc/sunxi/sun4i-codec.c +++ b/sound/soc/sunxi/sun4i-codec.c @@ -1631,8 +1631,7 @@ static int sun4i_codec_machine_init(struct snd_soc_pcm_runtime *rtd) static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev, int *num_links) { - struct snd_soc_dai_link *link = devm_kzalloc(dev, sizeof(*link), - GFP_KERNEL); + struct snd_soc_dai_link *link = devm_kzalloc_obj(dev, *link); struct snd_soc_dai_link_component *dlc = devm_kzalloc(dev, 3 * sizeof(*dlc), GFP_KERNEL); if (!link || !dlc) @@ -1694,7 +1693,7 @@ static struct snd_soc_card *sun4i_codec_create_card(struct device *dev) { struct snd_soc_card *card; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -1727,7 +1726,7 @@ static struct snd_soc_card *sun6i_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -1773,7 +1772,7 @@ static struct snd_soc_card *sun8i_a23_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -1812,7 +1811,7 @@ static struct snd_soc_card *sun8i_h3_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -1851,7 +1850,7 @@ static struct snd_soc_card *sun8i_v3s_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -2000,7 +1999,7 @@ static struct snd_soc_card *sun50i_h616_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -2058,7 +2057,7 @@ static struct snd_soc_card *suniv_codec_create_card(struct device *dev) struct snd_soc_card *card; int ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return ERR_PTR(-ENOMEM); @@ -2299,7 +2298,7 @@ static int sun4i_codec_probe(struct platform_device *pdev) void __iomem *base; int ret; - scodec = devm_kzalloc(&pdev->dev, sizeof(*scodec), GFP_KERNEL); + scodec = devm_kzalloc_obj(&pdev->dev, *scodec); if (!scodec) return -ENOMEM; diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c index 43e6ea2563fe4a..83ed04b7216e1d 100644 --- a/sound/soc/sunxi/sun4i-i2s.c +++ b/sound/soc/sunxi/sun4i-i2s.c @@ -1543,7 +1543,7 @@ static int sun4i_i2s_probe(struct platform_device *pdev) void __iomem *regs; int irq, ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; platform_set_drvdata(pdev, i2s); diff --git a/sound/soc/sunxi/sun4i-spdif.c b/sound/soc/sunxi/sun4i-spdif.c index 747ecd43dd2665..346d08445514fd 100644 --- a/sound/soc/sunxi/sun4i-spdif.c +++ b/sound/soc/sunxi/sun4i-spdif.c @@ -667,7 +667,7 @@ static int sun4i_spdif_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Entered %s\n", __func__); - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/sound/soc/sunxi/sun50i-dmic.c b/sound/soc/sunxi/sun50i-dmic.c index be61990415b01c..e8d8e32143ffbf 100644 --- a/sound/soc/sunxi/sun50i-dmic.c +++ b/sound/soc/sunxi/sun50i-dmic.c @@ -378,7 +378,7 @@ static int sun50i_dmic_probe(struct platform_device *pdev) int ret; void __iomem *base; - host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); + host = devm_kzalloc_obj(&pdev->dev, *host); if (!host) return -ENOMEM; diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index 2e4a205e4e5655..d71ae68e0cc1bb 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -259,6 +259,7 @@ static int sun8i_codec_runtime_resume(struct device *dev) ret = regcache_sync(scodec->regmap); if (ret) { dev_err(dev, "Failed to sync regmap cache\n"); + clk_disable_unprepare(scodec->clk_bus); return ret; } @@ -1621,7 +1622,7 @@ static int sun8i_codec_probe(struct platform_device *pdev) void __iomem *base; int ret; - scodec = devm_kzalloc(&pdev->dev, sizeof(*scodec), GFP_KERNEL); + scodec = devm_kzalloc_obj(&pdev->dev, *scodec); if (!scodec) return -ENOMEM; diff --git a/sound/soc/tegra/tegra186_asrc.c b/sound/soc/tegra/tegra186_asrc.c index d8ae5d997615f3..07ad7b3b860451 100644 --- a/sound/soc/tegra/tegra186_asrc.c +++ b/sound/soc/tegra/tegra186_asrc.c @@ -19,6 +19,9 @@ #include "tegra186_asrc.h" #include "tegra_cif.h" +#define TEGRA186_ASRC_RATIO_PERCENT_SCALE 100 +#define TEGRA186_ASRC_RATIO_UNLOCK_THRESHOLD_PERCENT 20 + #define ASRC_STREAM_SOURCE_SELECT(id) \ (TEGRA186_ASRC_CFG + ((id) * TEGRA186_ASRC_STREAM_STRIDE)) @@ -65,13 +68,133 @@ static const struct reg_default tegra186_asrc_reg_defaults[] = { { TEGRA186_ASRC_CYA, 0x0}, }; -static void tegra186_asrc_lock_stream(struct tegra186_asrc *asrc, - unsigned int id) +static int tegra186_asrc_set_stream_lock(struct tegra186_asrc *asrc, + unsigned int id, bool lock) { - regmap_write(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_LOCK_STATUS, - id), - 1); + return regmap_write(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_LOCK_STATUS, + id), + lock); +} + +static int tegra186_asrc_write_ratio_pair(struct tegra186_asrc *asrc, + unsigned int id, + unsigned int int_part, + unsigned int frac_part) +{ + int ret; + + ret = regmap_write(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, id), + int_part); + if (ret) + return ret; + + return regmap_write(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, id), + frac_part); +} + +static int tegra186_asrc_read_ratio_pair(struct tegra186_asrc *asrc, + unsigned int id, unsigned int *int_part, + unsigned int *frac_part) +{ + int ret; + + ret = regmap_read(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, id), + int_part); + if (ret) + return ret; + + return regmap_read(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, id), + frac_part); +} + +static void tegra186_asrc_cache_ratio(struct tegra186_asrc *asrc, + unsigned int id, unsigned int int_part, + unsigned int frac_part) +{ + asrc->lane[id].int_part = int_part; + asrc->lane[id].frac_part = frac_part; + asrc->lane[id].ratio_valid = true; +} + +static int tegra186_asrc_apply_ratio(struct tegra186_asrc *asrc, + unsigned int id, unsigned int int_part, + unsigned int frac_part, bool unlock) +{ + unsigned int old_int_part, old_frac_part, old_lock; + int ret, restore_ret; + + ret = tegra186_asrc_read_ratio_pair(asrc, id, &old_int_part, + &old_frac_part); + if (ret) + return ret; + + ret = regmap_read(asrc->regmap, + ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_LOCK_STATUS, id), + &old_lock); + if (ret) + return ret; + + if (unlock) { + ret = tegra186_asrc_set_stream_lock(asrc, id, false); + if (ret) + return ret; + } + + ret = tegra186_asrc_write_ratio_pair(asrc, id, int_part, frac_part); + if (ret) + goto restore_ratio; + + ret = tegra186_asrc_set_stream_lock(asrc, id, true); + if (!ret) + return 0; + +restore_ratio: + restore_ret = tegra186_asrc_write_ratio_pair(asrc, id, + old_int_part, + old_frac_part); + if (!restore_ret) { + if (old_lock) + restore_ret = tegra186_asrc_set_stream_lock(asrc, id, + true); + else + restore_ret = tegra186_asrc_set_stream_lock(asrc, id, + false); + } + + return ret ?: restore_ret; +} + +static int tegra186_asrc_apply_cached_ratio(struct tegra186_asrc *asrc, + unsigned int id) +{ + int ret; + + ret = tegra186_asrc_apply_ratio(asrc, id, asrc->lane[id].int_part, + asrc->lane[id].frac_part, + !asrc->lane[id].ratio_valid); + if (!ret) + asrc->lane[id].ratio_valid = true; + + return ret; +} + +static bool tegra186_asrc_need_unlock(u64 old_ratio, u64 new_ratio) +{ + u64 ratio_diff; + + if (!old_ratio || !new_ratio) + return false; + + ratio_diff = (old_ratio > new_ratio) ? + (old_ratio - new_ratio) : (new_ratio - old_ratio); + + return ((ratio_diff * TEGRA186_ASRC_RATIO_PERCENT_SCALE) > + (old_ratio * TEGRA186_ASRC_RATIO_UNLOCK_THRESHOLD_PERCENT)); } static int tegra186_asrc_runtime_suspend(struct device *dev) @@ -87,7 +210,7 @@ static int tegra186_asrc_runtime_suspend(struct device *dev) static int tegra186_asrc_runtime_resume(struct device *dev) { struct tegra186_asrc *asrc = dev_get_drvdata(dev); - int id; + int id, ret, first_err = 0; regcache_cache_only(asrc->regmap, false); @@ -103,25 +226,23 @@ static int tegra186_asrc_runtime_resume(struct device *dev) regcache_sync(asrc->regmap); + mutex_lock(&asrc->ratio_lock); for (id = 0; id < TEGRA186_ASRC_STREAM_MAX; id++) { if (asrc->lane[id].ratio_source != TEGRA186_ASRC_RATIO_SOURCE_SW) continue; - regmap_write(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, - id), - asrc->lane[id].int_part); - - regmap_write(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, - id), - asrc->lane[id].frac_part); - - tegra186_asrc_lock_stream(asrc, id); + ret = tegra186_asrc_apply_cached_ratio(asrc, id); + if (ret) { + dev_err(dev, "Failed to restore ratio for lane %d: %d\n", + id, ret); + if (!first_err) + first_err = ret; + } } + mutex_unlock(&asrc->ratio_lock); - return 0; + return first_err; } static int tegra186_asrc_set_audio_cif(struct tegra186_asrc *asrc, @@ -186,7 +307,7 @@ static int tegra186_asrc_out_hw_params(struct snd_pcm_substream *substream, { struct device *dev = dai->dev; struct tegra186_asrc *asrc = snd_soc_dai_get_drvdata(dai); - int ret, id = dai->id - 7; + int ret = 0, id = dai->id - 7; /* Set output threshold */ regmap_write(asrc->regmap, @@ -217,20 +338,22 @@ static int tegra186_asrc_out_hw_params(struct snd_pcm_substream *substream, TEGRA186_ASRC_STREAM_DEFAULT_HW_COMP_BIAS_VALUE); } + mutex_lock(&asrc->ratio_lock); + /* Set lock */ regmap_update_bits(asrc->regmap, ASRC_STREAM_REG(TEGRA186_ASRC_CFG, id), 1, asrc->lane[id].ratio_source); if (asrc->lane[id].ratio_source == TEGRA186_ASRC_RATIO_SOURCE_SW) { - regmap_write(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, id), - asrc->lane[id].int_part); - regmap_write(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, id), - asrc->lane[id].frac_part); - tegra186_asrc_lock_stream(asrc, id); + ret = tegra186_asrc_apply_cached_ratio(asrc, id); + if (ret) + dev_err(dev, "Can't apply cached ratio for ASRC stream %d: %d\n", + id, ret); } + mutex_unlock(&asrc->ratio_lock); + if (ret) + return ret; return ret; } @@ -257,112 +380,193 @@ static int tegra186_asrc_put_ratio_source(struct snd_kcontrol *kcontrol, struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); struct tegra186_asrc *asrc = snd_soc_component_get_drvdata(cmpnt); unsigned int id = asrc_private->reg / TEGRA186_ASRC_STREAM_STRIDE; + unsigned int new_source = ucontrol->value.enumerated.item[0]; + unsigned int old_source, int_part = 0, frac_part = 0; bool change = false; + int pm_ret, ret; - asrc->lane[id].ratio_source = ucontrol->value.enumerated.item[0]; - - regmap_update_bits_check(asrc->regmap, asrc_private->reg, - TEGRA186_ASRC_STREAM_RATIO_TYPE_MASK, - asrc->lane[id].ratio_source, - &change); - - return change ? 1 : 0; -} - -static int tegra186_asrc_get_ratio_int(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct soc_mixer_control *asrc_private = - (struct soc_mixer_control *)kcontrol->private_value; - struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); - struct tegra186_asrc *asrc = snd_soc_component_get_drvdata(cmpnt); - unsigned int id = asrc_private->reg / TEGRA186_ASRC_STREAM_STRIDE; - - regmap_read(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, id), - &asrc->lane[id].int_part); + mutex_lock(&asrc->ratio_lock); - ucontrol->value.integer.value[0] = asrc->lane[id].int_part; + old_source = asrc->lane[id].ratio_source; - return 0; -} + pm_ret = pm_runtime_get_if_active(cmpnt->dev); + if (pm_ret < 0) { + mutex_unlock(&asrc->ratio_lock); + return pm_ret; + } -static int tegra186_asrc_put_ratio_int(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct soc_mixer_control *asrc_private = - (struct soc_mixer_control *)kcontrol->private_value; - struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); - struct tegra186_asrc *asrc = snd_soc_component_get_drvdata(cmpnt); - unsigned int id = asrc_private->reg / TEGRA186_ASRC_STREAM_STRIDE; - bool change = false; + if (old_source == TEGRA186_ASRC_RATIO_SOURCE_ARAD && + new_source == TEGRA186_ASRC_RATIO_SOURCE_SW) { + if (pm_ret > 0) { + ret = tegra186_asrc_read_ratio_pair(asrc, id, + &int_part, + &frac_part); + if (ret) { + pm_runtime_put(cmpnt->dev); + asrc->lane[id].ratio_valid = false; + mutex_unlock(&asrc->ratio_lock); + return ret; + } + } else { + asrc->lane[id].ratio_valid = false; + } + } - if (asrc->lane[id].ratio_source == TEGRA186_ASRC_RATIO_SOURCE_ARAD) { - dev_err(cmpnt->dev, - "Lane %d ratio source is ARAD, invalid SW update\n", - id); - return -EINVAL; + ret = regmap_update_bits_check(asrc->regmap, asrc_private->reg, + TEGRA186_ASRC_STREAM_RATIO_TYPE_MASK, + new_source, &change); + if (ret) { + if (pm_ret > 0) + pm_runtime_put(cmpnt->dev); + mutex_unlock(&asrc->ratio_lock); + return ret; } - asrc->lane[id].int_part = ucontrol->value.integer.value[0]; + asrc->lane[id].ratio_source = new_source; + if (old_source == TEGRA186_ASRC_RATIO_SOURCE_ARAD && + new_source == TEGRA186_ASRC_RATIO_SOURCE_SW && pm_ret > 0) + tegra186_asrc_cache_ratio(asrc, id, int_part, frac_part); - regmap_update_bits_check(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, - id), - TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, - asrc->lane[id].int_part, &change); + if (pm_ret > 0) + pm_runtime_put(cmpnt->dev); - tegra186_asrc_lock_stream(asrc, id); + mutex_unlock(&asrc->ratio_lock); return change ? 1 : 0; } -static int tegra186_asrc_get_ratio_frac(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) +static int tegra186_asrc_get_ratio(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { struct soc_mreg_control *asrc_private = (struct soc_mreg_control *)kcontrol->private_value; struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); struct tegra186_asrc *asrc = snd_soc_component_get_drvdata(cmpnt); - unsigned int id = asrc_private->regbase / TEGRA186_ASRC_STREAM_STRIDE; + unsigned int id = asrc_private->regbase; + unsigned int int_part, frac_part; + int ret; + + mutex_lock(&asrc->ratio_lock); + + int_part = asrc->lane[id].int_part; + frac_part = asrc->lane[id].frac_part; + + if (asrc->lane[id].ratio_source != TEGRA186_ASRC_RATIO_SOURCE_ARAD) + goto done; - regmap_read(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, id), - &asrc->lane[id].frac_part); + ret = pm_runtime_get_if_active(cmpnt->dev); + if (ret < 0) { + mutex_unlock(&asrc->ratio_lock); + return ret; + } + + if (ret > 0) { + ret = tegra186_asrc_read_ratio_pair(asrc, id, &int_part, + &frac_part); + if (ret) { + pm_runtime_put(cmpnt->dev); + mutex_unlock(&asrc->ratio_lock); + return ret; + } + pm_runtime_put(cmpnt->dev); + asrc->lane[id].int_part = int_part; + asrc->lane[id].frac_part = frac_part; + } - ucontrol->value.integer.value[0] = asrc->lane[id].frac_part; +done: + mutex_unlock(&asrc->ratio_lock); + + ucontrol->value.integer.value[0] = int_part; + ucontrol->value.integer.value[1] = frac_part; return 0; } -static int tegra186_asrc_put_ratio_frac(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) +static int tegra186_asrc_put_ratio(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { struct soc_mreg_control *asrc_private = (struct soc_mreg_control *)kcontrol->private_value; struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); struct tegra186_asrc *asrc = snd_soc_component_get_drvdata(cmpnt); - unsigned int id = asrc_private->regbase / TEGRA186_ASRC_STREAM_STRIDE; - bool change = false; + unsigned int id = asrc_private->regbase; + unsigned int int_part, frac_part; + u64 old_ratio, new_ratio; + long int_val = ucontrol->value.integer.value[0]; + long frac_val = ucontrol->value.integer.value[1]; + bool change = false, unlock = false; + int ret = 0, pm_ret; + + if (int_val < 0 || int_val > TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK) + return -EINVAL; + + if (frac_val < 0 || frac_val > TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK) + return -EINVAL; + + int_part = int_val; + frac_part = frac_val; + + mutex_lock(&asrc->ratio_lock); if (asrc->lane[id].ratio_source == TEGRA186_ASRC_RATIO_SOURCE_ARAD) { dev_err(cmpnt->dev, "Lane %d ratio source is ARAD, invalid SW update\n", id); - return -EINVAL; + ret = -EINVAL; + goto out_unlock; } - asrc->lane[id].frac_part = ucontrol->value.integer.value[0]; + old_ratio = ((u64)asrc->lane[id].int_part << 32) | + asrc->lane[id].frac_part; + new_ratio = ((u64)int_part << 32) | frac_part; - regmap_update_bits_check(asrc->regmap, - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, - id), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - asrc->lane[id].frac_part, &change); + if (!new_ratio) { + ret = -EINVAL; + goto out_unlock; + } - tegra186_asrc_lock_stream(asrc, id); + change = old_ratio != new_ratio; + if (!change) + goto out_unlock; - return change ? 1 : 0; + unlock = !asrc->lane[id].ratio_valid || + tegra186_asrc_need_unlock(old_ratio, new_ratio); + + pm_ret = pm_runtime_get_if_active(cmpnt->dev); + if (pm_ret < 0) { + ret = pm_ret; + goto out_unlock; + } + + if (!pm_ret) { + asrc->lane[id].int_part = int_part; + asrc->lane[id].frac_part = frac_part; + ret = 1; + goto out_unlock; + } + + ret = regmap_read(asrc->regmap, ASRC_STREAM_REG(TEGRA186_ASRC_STATUS, id), + &pm_ret); + if (ret) + goto out_pm_put; + + if (!(pm_ret & TEGRA186_ASRC_STREAM_EN)) { + asrc->lane[id].int_part = int_part; + asrc->lane[id].frac_part = frac_part; + ret = 1; + goto out_pm_put; + } + + ret = tegra186_asrc_apply_ratio(asrc, id, int_part, frac_part, unlock); + if (!ret) + tegra186_asrc_cache_ratio(asrc, id, int_part, frac_part); + +out_pm_put: + pm_runtime_put(cmpnt->dev); +out_unlock: + mutex_unlock(&asrc->ratio_lock); + + return ret ?: change; } static int tegra186_asrc_get_hwcomp_disable(struct snd_kcontrol *kcontrol, @@ -651,99 +855,63 @@ ASRC_SOURCE_DECL(src_select4, 3); ASRC_SOURCE_DECL(src_select5, 4); ASRC_SOURCE_DECL(src_select6, 5); -#define SOC_SINGLE_EXT_FRAC(xname, xregbase, xmax, xget, xput) \ +static int tegra186_asrc_ratio_param_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct soc_mreg_control *mc = + (struct soc_mreg_control *)kcontrol->private_value; + + /* + * ALSA exposes one range for all values in an integer array. The + * fractional part needs the full 32-bit range; the integer part is + * validated against the hardware field width in the put callback. + */ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = mc->min; + uinfo->value.integer.max = mc->max; + + return 0; +} + +#define SOC_SINGLE_EXT_ARRAY(xname, xregbase, xmax, xget, xput) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = (xname), \ - .info = snd_soc_info_xr_sx, \ + .info = tegra186_asrc_ratio_param_info, \ .get = xget, \ .put = xput, \ \ .private_value = (unsigned long)&(struct soc_mreg_control) \ { \ .regbase = xregbase, \ - .regcount = 1, \ + .regcount = 2, \ .nbits = 32, \ .invert = 0, \ .min = 0, \ - .max = xmax \ + .max = (xmax) \ } \ } static const struct snd_kcontrol_new tegra186_asrc_controls[] = { - /* Controls for integer part of ratio */ - SOC_SINGLE_EXT("Ratio1 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 0), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - SOC_SINGLE_EXT("Ratio2 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 1), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - SOC_SINGLE_EXT("Ratio3 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 2), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - SOC_SINGLE_EXT("Ratio4 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 3), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - SOC_SINGLE_EXT("Ratio5 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 4), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - SOC_SINGLE_EXT("Ratio6 Integer Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_INT_PART, 5), - 0, TEGRA186_ASRC_STREAM_RATIO_INT_PART_MASK, 0, - tegra186_asrc_get_ratio_int, - tegra186_asrc_put_ratio_int), - - /* Controls for fractional part of ratio */ - SOC_SINGLE_EXT_FRAC("Ratio1 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 0), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), - - SOC_SINGLE_EXT_FRAC("Ratio2 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 1), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), - - SOC_SINGLE_EXT_FRAC("Ratio3 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 2), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), - - SOC_SINGLE_EXT_FRAC("Ratio4 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 3), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), - - SOC_SINGLE_EXT_FRAC("Ratio5 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 4), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), - - SOC_SINGLE_EXT_FRAC("Ratio6 Fractional Part", - ASRC_STREAM_REG(TEGRA186_ASRC_RATIO_FRAC_PART, 5), - TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, - tegra186_asrc_get_ratio_frac, - tegra186_asrc_put_ratio_frac), + /* Controls for ASRC */ + SOC_SINGLE_EXT_ARRAY("Ratio1", 0, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), + + SOC_SINGLE_EXT_ARRAY("Ratio2", 1, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), + + SOC_SINGLE_EXT_ARRAY("Ratio3", 2, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), + + SOC_SINGLE_EXT_ARRAY("Ratio4", 3, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), + + SOC_SINGLE_EXT_ARRAY("Ratio5", 4, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), + + SOC_SINGLE_EXT_ARRAY("Ratio6", 5, TEGRA186_ASRC_STREAM_RATIO_FRAC_PART_MASK, + tegra186_asrc_get_ratio, tegra186_asrc_put_ratio), /* Source of ratio provider */ SOC_ENUM_EXT("Ratio1 Source", src_select1, @@ -976,7 +1144,7 @@ static int tegra186_asrc_platform_probe(struct platform_device *pdev) unsigned int i; int err; - asrc = devm_kzalloc(dev, sizeof(*asrc), GFP_KERNEL); + asrc = devm_kzalloc_obj(dev, *asrc); if (!asrc) return -ENOMEM; @@ -1004,6 +1172,7 @@ static int tegra186_asrc_platform_probe(struct platform_device *pdev) asrc->lane[i].ratio_source = TEGRA186_ASRC_RATIO_SOURCE_SW; asrc->lane[i].int_part = 1; asrc->lane[i].frac_part = 0; + asrc->lane[i].ratio_valid = true; asrc->lane[i].hwcomp_disable = 0; asrc->lane[i].input_thresh = TEGRA186_ASRC_STREAM_DEFAULT_INPUT_HW_COMP_THRESH_CFG; @@ -1011,6 +1180,8 @@ static int tegra186_asrc_platform_probe(struct platform_device *pdev) TEGRA186_ASRC_STREAM_DEFAULT_OUTPUT_HW_COMP_THRESH_CFG; } + mutex_init(&asrc->ratio_lock); + err = devm_snd_soc_register_component(dev, &tegra186_asrc_cmpnt, tegra186_asrc_dais, ARRAY_SIZE(tegra186_asrc_dais)); diff --git a/sound/soc/tegra/tegra186_asrc.h b/sound/soc/tegra/tegra186_asrc.h index 0c98e26d5e725b..dabfd2e2c904be 100644 --- a/sound/soc/tegra/tegra186_asrc.h +++ b/sound/soc/tegra/tegra186_asrc.h @@ -7,6 +7,8 @@ #ifndef __TEGRA186_ASRC_H__ #define __TEGRA186_ASRC_H__ +#include + /* ASRC stream related offset */ #define TEGRA186_ASRC_CFG 0x0 #define TEGRA186_ASRC_RATIO_INT_PART 0x4 @@ -97,6 +99,7 @@ struct tegra186_asrc_lane { unsigned int int_part; unsigned int frac_part; + bool ratio_valid; unsigned int ratio_source; unsigned int hwcomp_disable; unsigned int input_thresh; @@ -111,6 +114,8 @@ struct tegra186_asrc { const struct tegra_asrc_soc_data *soc_data; struct tegra186_asrc_lane lane[TEGRA186_ASRC_STREAM_MAX]; struct regmap *regmap; + /* Serializes ratio source, cache, and paired register updates. */ + struct mutex ratio_lock; }; #endif diff --git a/sound/soc/tegra/tegra186_dspk.c b/sound/soc/tegra/tegra186_dspk.c index 0d3807b231f325..8896f4f937f6ce 100644 --- a/sound/soc/tegra/tegra186_dspk.c +++ b/sound/soc/tegra/tegra186_dspk.c @@ -483,7 +483,7 @@ static int tegra186_dspk_platform_probe(struct platform_device *pdev) void __iomem *regs; int err; - dspk = devm_kzalloc(dev, sizeof(*dspk), GFP_KERNEL); + dspk = devm_kzalloc_obj(dev, *dspk); if (!dspk) return -ENOMEM; diff --git a/sound/soc/tegra/tegra20_ac97.c b/sound/soc/tegra/tegra20_ac97.c index 0df1fc64f532f0..e48157d8e092c8 100644 --- a/sound/soc/tegra/tegra20_ac97.c +++ b/sound/soc/tegra/tegra20_ac97.c @@ -305,8 +305,7 @@ static int tegra20_ac97_platform_probe(struct platform_device *pdev) void __iomem *regs; int ret = 0; - ac97 = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_ac97), - GFP_KERNEL); + ac97 = devm_kzalloc_obj(&pdev->dev, struct tegra20_ac97); if (!ac97) { ret = -ENOMEM; goto err; diff --git a/sound/soc/tegra/tegra20_das.c b/sound/soc/tegra/tegra20_das.c index ea8bc9bcfa6734..0fdd65d1cac3b2 100644 --- a/sound/soc/tegra/tegra20_das.c +++ b/sound/soc/tegra/tegra20_das.c @@ -157,7 +157,7 @@ static int tegra20_das_probe(struct platform_device *pdev) void __iomem *regs; struct tegra20_das *das; - das = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_das), GFP_KERNEL); + das = devm_kzalloc_obj(&pdev->dev, struct tegra20_das); if (!das) return -ENOMEM; diff --git a/sound/soc/tegra/tegra20_i2s.c b/sound/soc/tegra/tegra20_i2s.c index b31f9477cb2eb0..2978c9d6f48396 100644 --- a/sound/soc/tegra/tegra20_i2s.c +++ b/sound/soc/tegra/tegra20_i2s.c @@ -413,7 +413,7 @@ static int tegra20_i2s_platform_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, struct tegra20_i2s); if (!i2s) { ret = -ENOMEM; goto err; diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c index 5eefcf149ae37d..b6cb41ef57bcc0 100644 --- a/sound/soc/tegra/tegra20_spdif.c +++ b/sound/soc/tegra/tegra20_spdif.c @@ -346,8 +346,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev) void __iomem *regs; int ret; - spdif = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_spdif), - GFP_KERNEL); + spdif = devm_kzalloc_obj(&pdev->dev, struct tegra20_spdif); if (!spdif) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_admaif.c b/sound/soc/tegra/tegra210_admaif.c index 87e898cc35e424..73be3a67db859f 100644 --- a/sound/soc/tegra/tegra210_admaif.c +++ b/sound/soc/tegra/tegra210_admaif.c @@ -1003,14 +1003,14 @@ static int tegra_admaif_probe(struct platform_device *pdev) for (i = 0; i < ADMAIF_PATHS; i++) { admaif->mono_to_stereo[i] = - devm_kcalloc(&pdev->dev, admaif->soc_data->num_ch, - sizeof(unsigned int), GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, unsigned int, + admaif->soc_data->num_ch); if (!admaif->mono_to_stereo[i]) return -ENOMEM; admaif->stereo_to_mono[i] = - devm_kcalloc(&pdev->dev, admaif->soc_data->num_ch, - sizeof(unsigned int), GFP_KERNEL); + devm_kzalloc_objs(&pdev->dev, unsigned int, + admaif->soc_data->num_ch); if (!admaif->stereo_to_mono[i]) return -ENOMEM; } diff --git a/sound/soc/tegra/tegra210_adx.c b/sound/soc/tegra/tegra210_adx.c index f2adf1c6e37e7e..9b2d9f1db5118b 100644 --- a/sound/soc/tegra/tegra210_adx.c +++ b/sound/soc/tegra/tegra210_adx.c @@ -677,9 +677,8 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev) int err, i; soc_data = of_device_get_match_data(dev); - adx = devm_kzalloc(dev, - struct_size(adx, map, soc_data->ram_depth * TEGRA_ADX_SLOTS_PER_WORD), - GFP_KERNEL); + adx = devm_kzalloc_flex(dev, *adx, map, + soc_data->ram_depth * TEGRA_ADX_SLOTS_PER_WORD); if (!adx) return -ENOMEM; @@ -699,8 +698,8 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev) regcache_cache_only(adx->regmap, true); - adx->byte_mask = devm_kcalloc(dev, soc_data->byte_mask_size, - sizeof(*adx->byte_mask), GFP_KERNEL); + adx->byte_mask = devm_kzalloc_objs(dev, *adx->byte_mask, + soc_data->byte_mask_size); if (!adx->byte_mask) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_ahub.c b/sound/soc/tegra/tegra210_ahub.c index efc8f338866828..3deaa599f53ae5 100644 --- a/sound/soc/tegra/tegra210_ahub.c +++ b/sound/soc/tegra/tegra210_ahub.c @@ -466,6 +466,67 @@ static struct snd_soc_dai_driver tegra264_ahub_dais[] = { DAI(OPE1 TX), }; +static struct snd_soc_dai_driver tegra268_ahub_dais[] = { + DAI(ADMAIF1), + DAI(ADMAIF2), + DAI(ADMAIF3), + DAI(ADMAIF4), + DAI(ADMAIF5), + /* XBAR <-> I2S <-> Codec */ + DAI(I2S1), + DAI(I2S2), + DAI(I2S3), + DAI(I2S4), + DAI(I2S5), + /* MVC */ + DAI(MVC1 RX), + DAI(MVC1 TX), + DAI(MVC2 RX), + DAI(MVC2 TX), + /* XBAR -> AMX(4:1) -> XBAR */ + DAI(AMX1 RX1), + DAI(AMX1 RX2), + DAI(AMX1 RX3), + DAI(AMX1 RX4), + DAI(AMX1), + /* XBAR -> ADX(1:4) -> XBAR */ + DAI(ADX1), + DAI(ADX1 TX1), + DAI(ADX1 TX2), + DAI(ADX1 TX3), + DAI(ADX1 TX4), + /* XBAR -> MIXER1(10:5) -> XBAR */ + DAI(MIXER1 RX1), + DAI(MIXER1 RX2), + DAI(MIXER1 RX3), + DAI(MIXER1 RX4), + DAI(MIXER1 RX5), + DAI(MIXER1 RX6), + DAI(MIXER1 RX7), + DAI(MIXER1 RX8), + DAI(MIXER1 RX9), + DAI(MIXER1 RX10), + DAI(MIXER1 TX1), + DAI(MIXER1 TX2), + DAI(MIXER1 TX3), + DAI(MIXER1 TX4), + DAI(MIXER1 TX5), + /* XBAR -> ASRC -> XBAR */ + DAI(ASRC1 RX1), + DAI(ASRC1 TX1), + DAI(ASRC1 RX2), + DAI(ASRC1 TX2), + DAI(ASRC1 RX3), + DAI(ASRC1 TX3), + DAI(ASRC1 RX4), + DAI(ASRC1 TX4), + DAI(ASRC1 RX5), + DAI(ASRC1 TX5), + DAI(ASRC1 RX6), + DAI(ASRC1 TX6), + DAI(ASRC1 RX7), +}; + static const char * const tegra210_ahub_mux_texts[] = { "None", "ADMAIF1", @@ -919,6 +980,77 @@ static const unsigned int tegra264_ahub_mux_values[] = { MUX_VALUE(4, 22), }; +static const char * const tegra268_ahub_mux_texts[] = { + "None", + "ADMAIF1", + "ADMAIF2", + "ADMAIF3", + "ADMAIF4", + "ADMAIF5", + "I2S1", + "I2S2", + "I2S3", + "I2S4", + "I2S5", + "MIXER1 TX1", + "MIXER1 TX2", + "MIXER1 TX3", + "MIXER1 TX4", + "MIXER1 TX5", + "MVC1", + "MVC2", + "AMX1", + "ADX1 TX1", + "ADX1 TX2", + "ADX1 TX3", + "ADX1 TX4", + "ASRC1 TX1", + "ASRC1 TX2", + "ASRC1 TX3", + "ASRC1 TX4", + "ASRC1 TX5", + "ASRC1 TX6", +}; + +static const unsigned int tegra268_ahub_mux_values[] = { + 0, + /* ADMAIF */ + MUX_VALUE(0, 0), + MUX_VALUE(0, 1), + MUX_VALUE(0, 2), + MUX_VALUE(0, 3), + MUX_VALUE(0, 4), + /* I2S */ + MUX_VALUE(0, 16), + MUX_VALUE(0, 17), + MUX_VALUE(0, 18), + MUX_VALUE(0, 19), + MUX_VALUE(0, 20), + /* MIXER */ + MUX_VALUE(1, 0), + MUX_VALUE(1, 1), + MUX_VALUE(1, 2), + MUX_VALUE(1, 3), + MUX_VALUE(1, 4), + /* MVC */ + MUX_VALUE(2, 8), + MUX_VALUE(2, 9), + /* AMX */ + MUX_VALUE(1, 8), + /* ADX */ + MUX_VALUE(2, 24), + MUX_VALUE(2, 25), + MUX_VALUE(2, 26), + MUX_VALUE(2, 27), + /* ASRC */ + MUX_VALUE(3, 24), + MUX_VALUE(3, 25), + MUX_VALUE(3, 26), + MUX_VALUE(3, 27), + MUX_VALUE(3, 28), + MUX_VALUE(3, 29), +}; + /* Controls for t210 */ MUX_ENUM_CTRL_DECL(t210_admaif1_tx, 0x00); MUX_ENUM_CTRL_DECL(t210_admaif2_tx, 0x01); @@ -1170,6 +1302,42 @@ MUX_ENUM_CTRL_DECL_264(t264_amx64_tx, 0x87); MUX_ENUM_CTRL_DECL_264(t264_adx5_tx, 0x88); MUX_ENUM_CTRL_DECL_264(t264_adx6_tx, 0x89); +/* Controls for t268 */ +MUX_ENUM_CTRL_DECL_268(t268_admaif1_tx, 0x00); +MUX_ENUM_CTRL_DECL_268(t268_admaif2_tx, 0x01); +MUX_ENUM_CTRL_DECL_268(t268_admaif3_tx, 0x02); +MUX_ENUM_CTRL_DECL_268(t268_admaif4_tx, 0x03); +MUX_ENUM_CTRL_DECL_268(t268_admaif5_tx, 0x04); +MUX_ENUM_CTRL_DECL_268(t268_i2s1_tx, 0x10); +MUX_ENUM_CTRL_DECL_268(t268_i2s2_tx, 0x11); +MUX_ENUM_CTRL_DECL_268(t268_i2s3_tx, 0x12); +MUX_ENUM_CTRL_DECL_268(t268_i2s4_tx, 0x13); +MUX_ENUM_CTRL_DECL_268(t268_i2s5_tx, 0x14); +MUX_ENUM_CTRL_DECL_268(t268_mixer11_tx, 0x20); +MUX_ENUM_CTRL_DECL_268(t268_mixer12_tx, 0x21); +MUX_ENUM_CTRL_DECL_268(t268_mixer13_tx, 0x22); +MUX_ENUM_CTRL_DECL_268(t268_mixer14_tx, 0x23); +MUX_ENUM_CTRL_DECL_268(t268_mixer15_tx, 0x24); +MUX_ENUM_CTRL_DECL_268(t268_mixer16_tx, 0x25); +MUX_ENUM_CTRL_DECL_268(t268_mixer17_tx, 0x26); +MUX_ENUM_CTRL_DECL_268(t268_mixer18_tx, 0x27); +MUX_ENUM_CTRL_DECL_268(t268_mixer19_tx, 0x28); +MUX_ENUM_CTRL_DECL_268(t268_mixer110_tx, 0x29); +MUX_ENUM_CTRL_DECL_268(t268_mvc1_tx, 0x44); +MUX_ENUM_CTRL_DECL_268(t268_mvc2_tx, 0x45); +MUX_ENUM_CTRL_DECL_268(t268_amx11_tx, 0x48); +MUX_ENUM_CTRL_DECL_268(t268_amx12_tx, 0x49); +MUX_ENUM_CTRL_DECL_268(t268_amx13_tx, 0x4a); +MUX_ENUM_CTRL_DECL_268(t268_amx14_tx, 0x4b); +MUX_ENUM_CTRL_DECL_268(t268_adx1_tx, 0x58); +MUX_ENUM_CTRL_DECL_268(t268_asrc11_tx, 0x64); +MUX_ENUM_CTRL_DECL_268(t268_asrc12_tx, 0x65); +MUX_ENUM_CTRL_DECL_268(t268_asrc13_tx, 0x66); +MUX_ENUM_CTRL_DECL_268(t268_asrc14_tx, 0x67); +MUX_ENUM_CTRL_DECL_268(t268_asrc15_tx, 0x68); +MUX_ENUM_CTRL_DECL_268(t268_asrc16_tx, 0x69); +MUX_ENUM_CTRL_DECL_268(t268_asrc17_tx, 0x6a); + static const struct snd_soc_dapm_widget tegra210_ahub_widgets[] = { WIDGETS("ADMAIF1", t210_admaif1_tx), WIDGETS("ADMAIF2", t210_admaif2_tx), @@ -1595,6 +1763,59 @@ static const struct snd_soc_dapm_widget tegra264_ahub_widgets[] = { WIDGETS("OPE1", t264_ope1_tx), }; +static const struct snd_soc_dapm_widget tegra268_ahub_widgets[] = { + WIDGETS("ADMAIF1", t268_admaif1_tx), + WIDGETS("ADMAIF2", t268_admaif2_tx), + WIDGETS("ADMAIF3", t268_admaif3_tx), + WIDGETS("ADMAIF4", t268_admaif4_tx), + WIDGETS("ADMAIF5", t268_admaif5_tx), + WIDGETS("I2S1", t268_i2s1_tx), + WIDGETS("I2S2", t268_i2s2_tx), + WIDGETS("I2S3", t268_i2s3_tx), + WIDGETS("I2S4", t268_i2s4_tx), + WIDGETS("I2S5", t268_i2s5_tx), + WIDGETS("MVC1", t268_mvc1_tx), + WIDGETS("MVC2", t268_mvc2_tx), + WIDGETS("AMX1 RX1", t268_amx11_tx), + WIDGETS("AMX1 RX2", t268_amx12_tx), + WIDGETS("AMX1 RX3", t268_amx13_tx), + WIDGETS("AMX1 RX4", t268_amx14_tx), + TX_WIDGETS("AMX1"), + WIDGETS("ADX1", t268_adx1_tx), + TX_WIDGETS("ADX1 TX1"), + TX_WIDGETS("ADX1 TX2"), + TX_WIDGETS("ADX1 TX3"), + TX_WIDGETS("ADX1 TX4"), + WIDGETS("MIXER1 RX1", t268_mixer11_tx), + WIDGETS("MIXER1 RX2", t268_mixer12_tx), + WIDGETS("MIXER1 RX3", t268_mixer13_tx), + WIDGETS("MIXER1 RX4", t268_mixer14_tx), + WIDGETS("MIXER1 RX5", t268_mixer15_tx), + WIDGETS("MIXER1 RX6", t268_mixer16_tx), + WIDGETS("MIXER1 RX7", t268_mixer17_tx), + WIDGETS("MIXER1 RX8", t268_mixer18_tx), + WIDGETS("MIXER1 RX9", t268_mixer19_tx), + WIDGETS("MIXER1 RX10", t268_mixer110_tx), + TX_WIDGETS("MIXER1 TX1"), + TX_WIDGETS("MIXER1 TX2"), + TX_WIDGETS("MIXER1 TX3"), + TX_WIDGETS("MIXER1 TX4"), + TX_WIDGETS("MIXER1 TX5"), + WIDGETS("ASRC1 RX1", t268_asrc11_tx), + WIDGETS("ASRC1 RX2", t268_asrc12_tx), + WIDGETS("ASRC1 RX3", t268_asrc13_tx), + WIDGETS("ASRC1 RX4", t268_asrc14_tx), + WIDGETS("ASRC1 RX5", t268_asrc15_tx), + WIDGETS("ASRC1 RX6", t268_asrc16_tx), + WIDGETS("ASRC1 RX7", t268_asrc17_tx), + TX_WIDGETS("ASRC1 TX1"), + TX_WIDGETS("ASRC1 TX2"), + TX_WIDGETS("ASRC1 TX3"), + TX_WIDGETS("ASRC1 TX4"), + TX_WIDGETS("ASRC1 TX5"), + TX_WIDGETS("ASRC1 TX6"), +}; + #define TEGRA_COMMON_MUX_ROUTES(name) \ { name " XBAR-TX", NULL, name " Mux" }, \ { name " Mux", "ADMAIF1", "ADMAIF1 XBAR-RX" }, \ @@ -1725,6 +1946,37 @@ static const struct snd_soc_dapm_widget tegra264_ahub_widgets[] = { { name " Mux", "ASRC1 TX5", "ASRC1 TX5 XBAR-RX" }, \ { name " Mux", "ASRC1 TX6", "ASRC1 TX6 XBAR-RX" }, +#define TEGRA268_MUX_ROUTES(name) \ + { name " XBAR-TX", NULL, name " Mux" }, \ + { name " Mux", "ADMAIF1", "ADMAIF1 XBAR-RX" }, \ + { name " Mux", "ADMAIF2", "ADMAIF2 XBAR-RX" }, \ + { name " Mux", "ADMAIF3", "ADMAIF3 XBAR-RX" }, \ + { name " Mux", "ADMAIF4", "ADMAIF4 XBAR-RX" }, \ + { name " Mux", "ADMAIF5", "ADMAIF5 XBAR-RX" }, \ + { name " Mux", "I2S1", "I2S1 XBAR-RX" }, \ + { name " Mux", "I2S2", "I2S2 XBAR-RX" }, \ + { name " Mux", "I2S3", "I2S3 XBAR-RX" }, \ + { name " Mux", "I2S4", "I2S4 XBAR-RX" }, \ + { name " Mux", "I2S5", "I2S5 XBAR-RX" }, \ + { name " Mux", "MVC1", "MVC1 XBAR-RX" }, \ + { name " Mux", "MVC2", "MVC2 XBAR-RX" }, \ + { name " Mux", "AMX1", "AMX1 XBAR-RX" }, \ + { name " Mux", "ADX1 TX1", "ADX1 TX1 XBAR-RX" }, \ + { name " Mux", "ADX1 TX2", "ADX1 TX2 XBAR-RX" }, \ + { name " Mux", "ADX1 TX3", "ADX1 TX3 XBAR-RX" }, \ + { name " Mux", "ADX1 TX4", "ADX1 TX4 XBAR-RX" }, \ + { name " Mux", "MIXER1 TX1", "MIXER1 TX1 XBAR-RX" }, \ + { name " Mux", "MIXER1 TX2", "MIXER1 TX2 XBAR-RX" }, \ + { name " Mux", "MIXER1 TX3", "MIXER1 TX3 XBAR-RX" }, \ + { name " Mux", "MIXER1 TX4", "MIXER1 TX4 XBAR-RX" }, \ + { name " Mux", "MIXER1 TX5", "MIXER1 TX5 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX1", "ASRC1 TX1 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX2", "ASRC1 TX2 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX3", "ASRC1 TX3 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX4", "ASRC1 TX4 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX5", "ASRC1 TX5 XBAR-RX" }, \ + { name " Mux", "ASRC1 TX6", "ASRC1 TX6 XBAR-RX" }, + #define TEGRA210_MUX_ROUTES(name) \ TEGRA_COMMON_MUX_ROUTES(name) \ TEGRA210_ONLY_MUX_ROUTES(name) @@ -2025,6 +2277,48 @@ static const struct snd_soc_dapm_route tegra264_ahub_routes[] = { TEGRA264_MUX_ROUTES("OPE1") }; +static const struct snd_soc_dapm_route tegra268_ahub_routes[] = { + TEGRA_FE_ROUTES("ADMAIF1") + TEGRA_FE_ROUTES("ADMAIF2") + TEGRA_FE_ROUTES("ADMAIF3") + TEGRA_FE_ROUTES("ADMAIF4") + TEGRA_FE_ROUTES("ADMAIF5") + TEGRA268_MUX_ROUTES("ADMAIF1") + TEGRA268_MUX_ROUTES("ADMAIF2") + TEGRA268_MUX_ROUTES("ADMAIF3") + TEGRA268_MUX_ROUTES("ADMAIF4") + TEGRA268_MUX_ROUTES("ADMAIF5") + TEGRA268_MUX_ROUTES("I2S1") + TEGRA268_MUX_ROUTES("I2S2") + TEGRA268_MUX_ROUTES("I2S3") + TEGRA268_MUX_ROUTES("I2S4") + TEGRA268_MUX_ROUTES("I2S5") + TEGRA268_MUX_ROUTES("MVC1") + TEGRA268_MUX_ROUTES("MVC2") + TEGRA268_MUX_ROUTES("AMX1 RX1") + TEGRA268_MUX_ROUTES("AMX1 RX2") + TEGRA268_MUX_ROUTES("AMX1 RX3") + TEGRA268_MUX_ROUTES("AMX1 RX4") + TEGRA268_MUX_ROUTES("ADX1") + TEGRA268_MUX_ROUTES("MIXER1 RX1") + TEGRA268_MUX_ROUTES("MIXER1 RX2") + TEGRA268_MUX_ROUTES("MIXER1 RX3") + TEGRA268_MUX_ROUTES("MIXER1 RX4") + TEGRA268_MUX_ROUTES("MIXER1 RX5") + TEGRA268_MUX_ROUTES("MIXER1 RX6") + TEGRA268_MUX_ROUTES("MIXER1 RX7") + TEGRA268_MUX_ROUTES("MIXER1 RX8") + TEGRA268_MUX_ROUTES("MIXER1 RX9") + TEGRA268_MUX_ROUTES("MIXER1 RX10") + TEGRA268_MUX_ROUTES("ASRC1 RX1") + TEGRA268_MUX_ROUTES("ASRC1 RX2") + TEGRA268_MUX_ROUTES("ASRC1 RX3") + TEGRA268_MUX_ROUTES("ASRC1 RX4") + TEGRA268_MUX_ROUTES("ASRC1 RX5") + TEGRA268_MUX_ROUTES("ASRC1 RX6") + TEGRA268_MUX_ROUTES("ASRC1 RX7") +}; + static const struct snd_soc_component_driver tegra210_ahub_component = { .dapm_widgets = tegra210_ahub_widgets, .num_dapm_widgets = ARRAY_SIZE(tegra210_ahub_widgets), @@ -2053,6 +2347,13 @@ static const struct snd_soc_component_driver tegra264_ahub_component = { .num_dapm_routes = ARRAY_SIZE(tegra264_ahub_routes), }; +static const struct snd_soc_component_driver tegra268_ahub_component = { + .dapm_widgets = tegra268_ahub_widgets, + .num_dapm_widgets = ARRAY_SIZE(tegra268_ahub_widgets), + .dapm_routes = tegra268_ahub_routes, + .num_dapm_routes = ARRAY_SIZE(tegra268_ahub_routes), +}; + static bool tegra210_ahub_wr_reg(struct device *dev, unsigned int reg) { int part; @@ -2131,6 +2432,28 @@ static bool tegra264_ahub_wr_reg(struct device *dev, unsigned int reg) return false; } +static bool tegra268_ahub_wr_reg(struct device *dev, unsigned int reg) +{ + int part; + + for (part = 0; part < TEGRA268_XBAR_UPDATE_MAX_REG; part++) { + switch (reg & ~(part << 12)) { + case TEGRA264_AXBAR_ADMAIF_RX1 ... TEGRA268_AXBAR_ADMAIF_RX5: + case TEGRA268_AXBAR_I2S1_RX1 ... TEGRA268_AXBAR_I2S5_RX1: + case TEGRA264_AXBAR_MIXER1_RX1 ... TEGRA264_AXBAR_MIXER1_RX10: + case TEGRA264_AXBAR_MVC1_RX1 ... TEGRA264_AXBAR_MVC2_RX1: + case TEGRA264_AXBAR_AMX1_RX1 ... TEGRA268_AXBAR_AMX1_RX4: + case TEGRA264_AXBAR_ADX1_RX1: + case TEGRA268_AXBAR_ASRC1_RX1 ... TEGRA264_AXBAR_ASRC1_RX7: + return true; + default: + break; + } + } + + return false; +} + static const struct regmap_config tegra210_ahub_regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -2161,6 +2484,16 @@ static const struct regmap_config tegra264_ahub_regmap_config = { .cache_type = REGCACHE_FLAT, }; +static const struct regmap_config tegra268_ahub_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .writeable_reg = tegra268_ahub_wr_reg, + .max_register = TEGRA268_MAX_REGISTER_ADDR, + .reg_default_cb = regmap_default_zero_cb, + .cache_type = REGCACHE_FLAT, +}; + static const struct tegra_ahub_soc_data soc_data_tegra210 = { .cmpnt_drv = &tegra210_ahub_component, .dai_drv = tegra210_ahub_dais, @@ -2214,11 +2547,25 @@ static const struct tegra_ahub_soc_data soc_data_tegra264 = { .xbar_part_size = TEGRA264_XBAR_PART1_RX, }; +static const struct tegra_ahub_soc_data soc_data_tegra268 = { + .cmpnt_drv = &tegra268_ahub_component, + .dai_drv = tegra268_ahub_dais, + .num_dais = ARRAY_SIZE(tegra268_ahub_dais), + .regmap_config = &tegra268_ahub_regmap_config, + .mask[0] = TEGRA268_XBAR_REG_MASK_0, + .mask[1] = TEGRA268_XBAR_REG_MASK_1, + .mask[2] = TEGRA268_XBAR_REG_MASK_2, + .mask[3] = TEGRA268_XBAR_REG_MASK_3, + .reg_count = TEGRA268_XBAR_UPDATE_MAX_REG, + .xbar_part_size = TEGRA264_XBAR_PART1_RX, +}; + static const struct of_device_id tegra_ahub_of_match[] = { { .compatible = "nvidia,tegra210-ahub", .data = &soc_data_tegra210 }, { .compatible = "nvidia,tegra186-ahub", .data = &soc_data_tegra186 }, { .compatible = "nvidia,tegra234-ahub", .data = &soc_data_tegra234 }, { .compatible = "nvidia,tegra264-ahub", .data = &soc_data_tegra264 }, + { .compatible = "nvidia,tegra268-ahub", .data = &soc_data_tegra268 }, {}, }; MODULE_DEVICE_TABLE(of, tegra_ahub_of_match); @@ -2258,7 +2605,7 @@ static int tegra_ahub_probe(struct platform_device *pdev) void __iomem *regs; int err; - ahub = devm_kzalloc(&pdev->dev, sizeof(*ahub), GFP_KERNEL); + ahub = devm_kzalloc_obj(&pdev->dev, *ahub); if (!ahub) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_ahub.h b/sound/soc/tegra/tegra210_ahub.h index acbe640dd3b572..b69d494e463e47 100644 --- a/sound/soc/tegra/tegra210_ahub.h +++ b/sound/soc/tegra/tegra210_ahub.h @@ -57,8 +57,26 @@ #define TEGRA264_AXBAR_ADMAIF_RX21 0x1d0 #define TEGRA264_AXBAR_ADX6_RX1 0x224 +/* Tegra268 specific */ +#define TEGRA268_XBAR_REG_MASK_0 0x1f001f +#define TEGRA268_XBAR_REG_MASK_1 0x11f +#define TEGRA268_XBAR_REG_MASK_2 0xf000300 +#define TEGRA268_XBAR_REG_MASK_3 0x3f000000 +#define TEGRA268_XBAR_UPDATE_MAX_REG 4 + +#define TEGRA268_AXBAR_ADMAIF_RX5 0x10 +#define TEGRA268_AXBAR_I2S1_RX1 0x40 +#define TEGRA268_AXBAR_I2S5_RX1 0x50 +#define TEGRA268_AXBAR_AMX1_RX4 0x12c +#define TEGRA268_AXBAR_ASRC1_RX1 0x190 +#define TEGRA268_AXBAR_ASRC1_RX7 0x1a8 +#define TEGRA268_XBAR_AUDIO_RX_COUNT ((TEGRA268_AXBAR_ASRC1_RX7 / 4) + 1) + #define TEGRA_XBAR_UPDATE_MAX_REG (TEGRA264_XBAR_UPDATE_MAX_REG) +#define TEGRA268_MAX_REGISTER_ADDR (TEGRA264_XBAR_PART3_RX + \ + (TEGRA210_XBAR_RX_STRIDE * (TEGRA268_XBAR_AUDIO_RX_COUNT - 1))) + #define TEGRA264_MAX_REGISTER_ADDR (TEGRA264_XBAR_PART4_RX + \ (TEGRA210_XBAR_RX_STRIDE * (TEGRA264_XBAR_AUDIO_RX_COUNT - 1))) @@ -147,6 +165,15 @@ tegra_ahub_get_value_enum, \ tegra_ahub_put_value_enum) +#define MUX_ENUM_CTRL_DECL_268(ename, id) \ + SOC_VALUE_ENUM_WIDE_DECL(ename##_enum, MUX_REG(id), 0, \ + tegra268_ahub_mux_texts, \ + tegra268_ahub_mux_values); \ + static const struct snd_kcontrol_new ename##_control = \ + SOC_DAPM_ENUM_EXT("Route", ename##_enum, \ + tegra_ahub_get_value_enum, \ + tegra_ahub_put_value_enum) + #define WIDGETS(sname, ename) \ SND_SOC_DAPM_AIF_IN(sname " XBAR-RX", NULL, 0, SND_SOC_NOPM, 0, 0), \ SND_SOC_DAPM_AIF_OUT(sname " XBAR-TX", NULL, 0, SND_SOC_NOPM, 0, 0), \ diff --git a/sound/soc/tegra/tegra210_amx.c b/sound/soc/tegra/tegra210_amx.c index 6a67ce6128b4fe..2288656a327879 100644 --- a/sound/soc/tegra/tegra210_amx.c +++ b/sound/soc/tegra/tegra210_amx.c @@ -726,7 +726,7 @@ static int tegra210_amx_platform_probe(struct platform_device *pdev) void __iomem *regs; int err, i; - amx = devm_kzalloc(dev, sizeof(*amx), GFP_KERNEL); + amx = devm_kzalloc_obj(dev, *amx); if (!amx) return -ENOMEM; @@ -746,14 +746,13 @@ static int tegra210_amx_platform_probe(struct platform_device *pdev) regcache_cache_only(amx->regmap, true); - amx->map = devm_kcalloc(dev, - amx->soc_data->ram_depth * TEGRA_AMX_SLOTS_PER_WORD, - sizeof(*amx->map), GFP_KERNEL); + amx->map = devm_kzalloc_objs(dev, *amx->map, + amx->soc_data->ram_depth * TEGRA_AMX_SLOTS_PER_WORD); if (!amx->map) return -ENOMEM; - amx->byte_mask = devm_kcalloc(dev, amx->soc_data->byte_mask_size, - sizeof(*amx->byte_mask), GFP_KERNEL); + amx->byte_mask = devm_kzalloc_objs(dev, *amx->byte_mask, + amx->soc_data->byte_mask_size); if (!amx->byte_mask) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_dmic.c b/sound/soc/tegra/tegra210_dmic.c index 6098ad056ba940..3123057abfe86b 100644 --- a/sound/soc/tegra/tegra210_dmic.c +++ b/sound/soc/tegra/tegra210_dmic.c @@ -493,7 +493,7 @@ static int tegra210_dmic_probe(struct platform_device *pdev) void __iomem *regs; int err; - dmic = devm_kzalloc(dev, sizeof(*dmic), GFP_KERNEL); + dmic = devm_kzalloc_obj(dev, *dmic); if (!dmic) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_i2s.c b/sound/soc/tegra/tegra210_i2s.c index f2cfe3b5ccceca..72e3cb0ab3c095 100644 --- a/sound/soc/tegra/tegra210_i2s.c +++ b/sound/soc/tegra/tegra210_i2s.c @@ -1084,7 +1084,7 @@ static int tegra210_i2s_probe(struct platform_device *pdev) void __iomem *regs; int err, id; - i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_mixer.c b/sound/soc/tegra/tegra210_mixer.c index 96259a6cbc59b2..1c19c8c354665d 100644 --- a/sound/soc/tegra/tegra210_mixer.c +++ b/sound/soc/tegra/tegra210_mixer.c @@ -899,7 +899,7 @@ static int tegra210_mixer_platform_probe(struct platform_device *pdev) void __iomem *regs; int err, i; - mixer = devm_kzalloc(dev, sizeof(*mixer), GFP_KERNEL); + mixer = devm_kzalloc_obj(dev, *mixer); if (!mixer) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_mvc.c b/sound/soc/tegra/tegra210_mvc.c index ac04350107c450..a3f8aeb94cef4b 100644 --- a/sound/soc/tegra/tegra210_mvc.c +++ b/sound/soc/tegra/tegra210_mvc.c @@ -718,7 +718,7 @@ static int tegra210_mvc_platform_probe(struct platform_device *pdev) void __iomem *regs; int err; - mvc = devm_kzalloc(dev, sizeof(*mvc), GFP_KERNEL); + mvc = devm_kzalloc_obj(dev, *mvc); if (!mvc) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_ope.c b/sound/soc/tegra/tegra210_ope.c index 30a54b1222d9bb..fe7ce939aae07c 100644 --- a/sound/soc/tegra/tegra210_ope.c +++ b/sound/soc/tegra/tegra210_ope.c @@ -307,7 +307,7 @@ static int tegra210_ope_probe(struct platform_device *pdev) void __iomem *regs; int err; - ope = devm_kzalloc(dev, sizeof(*ope), GFP_KERNEL); + ope = devm_kzalloc_obj(dev, *ope); if (!ope) return -ENOMEM; diff --git a/sound/soc/tegra/tegra210_sfc.c b/sound/soc/tegra/tegra210_sfc.c index a4b96445f1da50..d86cb227663034 100644 --- a/sound/soc/tegra/tegra210_sfc.c +++ b/sound/soc/tegra/tegra210_sfc.c @@ -3586,7 +3586,7 @@ static int tegra210_sfc_platform_probe(struct platform_device *pdev) void __iomem *regs; int err; - sfc = devm_kzalloc(dev, sizeof(*sfc), GFP_KERNEL); + sfc = devm_kzalloc_obj(dev, *sfc); if (!sfc) return -ENOMEM; diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c index ee68f28852c426..ab6970c008d278 100644 --- a/sound/soc/tegra/tegra30_ahub.c +++ b/sound/soc/tegra/tegra30_ahub.c @@ -522,8 +522,7 @@ static int tegra30_ahub_probe(struct platform_device *pdev) if (!soc_data) return -EINVAL; - ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub), - GFP_KERNEL); + ahub = devm_kzalloc_obj(&pdev->dev, struct tegra30_ahub); if (!ahub) return -ENOMEM; dev_set_drvdata(&pdev->dev, ahub); @@ -595,6 +594,7 @@ static int tegra30_ahub_probe(struct platform_device *pdev) static void tegra30_ahub_remove(struct platform_device *pdev) { + of_platform_depopulate(&pdev->dev); pm_runtime_disable(&pdev->dev); ahub = NULL; diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c index 69acff73f68ade..e5e648d00621ba 100644 --- a/sound/soc/tegra/tegra30_i2s.c +++ b/sound/soc/tegra/tegra30_i2s.c @@ -422,7 +422,7 @@ static int tegra30_i2s_platform_probe(struct platform_device *pdev) void __iomem *regs; int ret; - i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, struct tegra30_i2s); if (!i2s) { ret = -ENOMEM; goto err; diff --git a/sound/soc/tegra/tegra_asoc_machine.c b/sound/soc/tegra/tegra_asoc_machine.c index e2d0e5947339da..c4e62e2b7fd073 100644 --- a/sound/soc/tegra/tegra_asoc_machine.c +++ b/sound/soc/tegra/tegra_asoc_machine.c @@ -455,7 +455,7 @@ int tegra_asoc_machine_probe(struct platform_device *pdev) struct gpio_desc *gpiod; int err; - machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL); + machine = devm_kzalloc_obj(dev, *machine); if (!machine) return -ENOMEM; diff --git a/sound/soc/tegra/tegra_audio_graph_card.c b/sound/soc/tegra/tegra_audio_graph_card.c index b93a61db9ed0b0..5cd3e30be94b36 100644 --- a/sound/soc/tegra/tegra_audio_graph_card.c +++ b/sound/soc/tegra/tegra_audio_graph_card.c @@ -199,7 +199,7 @@ static int tegra_audio_graph_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct snd_soc_card *card; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc_obj(dev, *priv); if (!priv) return -ENOMEM; diff --git a/sound/soc/tegra/tegra_isomgr_bw.c b/sound/soc/tegra/tegra_isomgr_bw.c index 1c007f870759a7..bc6782638ced7b 100644 --- a/sound/soc/tegra/tegra_isomgr_bw.c +++ b/sound/soc/tegra/tegra_isomgr_bw.c @@ -82,7 +82,7 @@ int tegra_isomgr_adma_register(struct device *dev) struct tegra_adma_isomgr *adma_isomgr; int i; - adma_isomgr = devm_kzalloc(dev, sizeof(struct tegra_adma_isomgr), GFP_KERNEL); + adma_isomgr = devm_kzalloc_obj(dev, struct tegra_adma_isomgr); if (!adma_isomgr) return -ENOMEM; diff --git a/sound/soc/tegra/tegra_wm8962.c b/sound/soc/tegra/tegra_wm8962.c index 1ace9261a0f33e..25544d68040954 100644 --- a/sound/soc/tegra/tegra_wm8962.c +++ b/sound/soc/tegra/tegra_wm8962.c @@ -97,18 +97,6 @@ static int tegra_wm8962_init(struct snd_soc_pcm_runtime *rtd) return 0; } -static int tegra_wm8962_remove(struct snd_soc_card *card) -{ - struct snd_soc_dai_link *link = &card->dai_link[0]; - struct snd_soc_pcm_runtime *rtd = snd_soc_get_pcm_runtime(card, link); - struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); - struct snd_soc_component *component = codec_dai->component; - - snd_soc_component_set_jack(component, NULL, NULL); - - return 0; -} - SND_SOC_DAILINK_DEFS(wm8962_hifi, DAILINK_COMP_ARRAY(COMP_EMPTY()), DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8962")), @@ -129,7 +117,6 @@ static struct snd_soc_card snd_soc_tegra_wm8962 = { .owner = THIS_MODULE, .dai_link = &tegra_wm8962_dai, .num_links = 1, - .remove = tegra_wm8962_remove, .fully_routed = true, }; diff --git a/sound/soc/ti/davinci-evm.c b/sound/soc/ti/davinci-evm.c index 3156d87a3a1203..c1c2cd51d6f64a 100644 --- a/sound/soc/ti/davinci-evm.c +++ b/sound/soc/ti/davinci-evm.c @@ -215,7 +215,7 @@ static int davinci_evm_probe(struct platform_device *pdev) mclk = NULL; } - drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, *drvdata); if (!drvdata) { ret = -ENOMEM; goto err_put; diff --git a/sound/soc/ti/davinci-i2s.c b/sound/soc/ti/davinci-i2s.c index 3614f614117d39..287e4c0ea7e928 100644 --- a/sound/soc/ti/davinci-i2s.c +++ b/sound/soc/ti/davinci-i2s.c @@ -813,8 +813,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) if (IS_ERR(io_base)) return PTR_ERR(io_base); - dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcbsp_dev), - GFP_KERNEL); + dev = devm_kzalloc_obj(&pdev->dev, struct davinci_mcbsp_dev); if (!dev) return -ENOMEM; diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c index 481d1042ddb6d1..9333d7d3aa37b0 100644 --- a/sound/soc/ti/davinci-mcasp.c +++ b/sound/soc/ti/davinci-mcasp.c @@ -2452,9 +2452,8 @@ static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp, mcasp->num_serializer = pdata->num_serializer; #ifdef CONFIG_PM - mcasp->context.xrsr_regs = devm_kcalloc(&pdev->dev, - mcasp->num_serializer, sizeof(u32), - GFP_KERNEL); + mcasp->context.xrsr_regs = devm_kzalloc_objs(&pdev->dev, u32, + mcasp->num_serializer); if (!mcasp->context.xrsr_regs) return -ENOMEM; #endif @@ -2477,6 +2476,7 @@ static const char *sdma_prefix = "ti,omap"; static int davinci_mcasp_get_dma_type(struct davinci_mcasp *mcasp) { struct dma_chan *chan; + struct device *dma_dev; const char *tmp; int ret = PCM_EDMA; @@ -2488,13 +2488,10 @@ static int davinci_mcasp_get_dma_type(struct davinci_mcasp *mcasp) if (IS_ERR(chan)) return dev_err_probe(mcasp->dev, PTR_ERR(chan), "Can't verify DMA configuration\n"); - if (WARN_ON(!chan->device || !chan->device->dev)) { - dma_release_channel(chan); - return -EINVAL; - } - if (chan->device->dev->of_node) - ret = of_property_read_string(chan->device->dev->of_node, + dma_dev = dmaengine_get_provider_device(chan); + if (dma_dev->of_node) + ret = of_property_read_string(dma_dev->of_node, "compatible", &tmp); else dev_dbg(mcasp->dev, "DMA controller has no of-node\n"); @@ -2710,8 +2707,7 @@ static int davinci_mcasp_register_component(struct davinci_mcasp *mcasp, &davinci_mcasp_component, &davinci_mcasp_dai[mcasp->op_mode], 1); - dais = devm_kcalloc(&pdev->dev, mcasp->num_dais, sizeof(*dais), - GFP_KERNEL); + dais = devm_kzalloc_objs(&pdev->dev, *dais, mcasp->num_dais); if (!dais) return -ENOMEM; @@ -2760,8 +2756,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev) return -EINVAL; } - mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp), - GFP_KERNEL); + mcasp = devm_kzalloc_obj(&pdev->dev, struct davinci_mcasp); if (!mcasp) return -ENOMEM; @@ -2902,16 +2897,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev) * bytes. */ mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list = - devm_kcalloc(mcasp->dev, - 32 + mcasp->num_serializer - 1, - sizeof(unsigned int), - GFP_KERNEL); + devm_kzalloc_objs(mcasp->dev, unsigned int, + 32 + mcasp->num_serializer - 1); mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list = - devm_kcalloc(mcasp->dev, - 32 + mcasp->num_serializer - 1, - sizeof(unsigned int), - GFP_KERNEL); + devm_kzalloc_objs(mcasp->dev, unsigned int, + 32 + mcasp->num_serializer - 1); if (!mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list || !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list) { diff --git a/sound/soc/ti/edma-pcm.c b/sound/soc/ti/edma-pcm.c index 634b040b65f0ca..8133c665b933c1 100644 --- a/sound/soc/ti/edma-pcm.c +++ b/sound/soc/ti/edma-pcm.c @@ -45,7 +45,7 @@ int edma_pcm_platform_register(struct device *dev) return devm_snd_dmaengine_pcm_register(dev, &edma_dmaengine_pcm_config, 0); - config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(dev, *config); if (!config) return -ENOMEM; diff --git a/sound/soc/ti/j721e-evm.c b/sound/soc/ti/j721e-evm.c index 600897a3e1c5c5..78d73dbed65351 100644 --- a/sound/soc/ti/j721e-evm.c +++ b/sound/soc/ti/j721e-evm.c @@ -646,8 +646,7 @@ static int j721e_soc_probe_cpb(struct j721e_priv *priv, int *link_idx, * Link 2: McASP10 <- pcm3168a_1 ADC */ comp_count = 6; - compnent = devm_kcalloc(priv->dev, comp_count, sizeof(*compnent), - GFP_KERNEL); + compnent = devm_kzalloc_objs(priv->dev, *compnent, comp_count); if (!compnent) { ret = -ENOMEM; goto put_codec_node; @@ -760,8 +759,7 @@ static int j721e_soc_probe_ivi(struct j721e_priv *priv, int *link_idx, * \ pcm3168a_b ADC */ comp_count = 8; - compnent = devm_kcalloc(priv->dev, comp_count, sizeof(*compnent), - GFP_KERNEL); + compnent = devm_kzalloc_objs(priv->dev, *compnent, comp_count); if (!compnent) { ret = -ENOMEM; goto put_codecb_node; @@ -850,8 +848,7 @@ static int j721e_soc_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(&pdev->dev, - struct_size(priv, dai_links, match->num_links), GFP_KERNEL); + priv = devm_kzalloc_flex(&pdev->dev, *priv, dai_links, match->num_links); if (!priv) return -ENOMEM; diff --git a/sound/soc/ti/omap-abe-twl6040.c b/sound/soc/ti/omap-abe-twl6040.c index 05239ccc1f415c..8004dd428b08ac 100644 --- a/sound/soc/ti/omap-abe-twl6040.c +++ b/sound/soc/ti/omap-abe-twl6040.c @@ -222,7 +222,7 @@ static int omap_abe_probe(struct platform_device *pdev) return -ENODEV; } - priv = devm_kzalloc(&pdev->dev, sizeof(struct abe_twl6040), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct abe_twl6040); if (priv == NULL) return -ENOMEM; diff --git a/sound/soc/ti/omap-dmic.c b/sound/soc/ti/omap-dmic.c index c8d791f05ae41c..dc54162f2d6bed 100644 --- a/sound/soc/ti/omap-dmic.c +++ b/sound/soc/ti/omap-dmic.c @@ -454,7 +454,7 @@ static int asoc_dmic_probe(struct platform_device *pdev) struct resource *res; int ret; - dmic = devm_kzalloc(&pdev->dev, sizeof(struct omap_dmic), GFP_KERNEL); + dmic = devm_kzalloc_obj(&pdev->dev, struct omap_dmic); if (!dmic) return -ENOMEM; diff --git a/sound/soc/ti/omap-hdmi.c b/sound/soc/ti/omap-hdmi.c index 2cabd4cc5b0bda..33536bf7c06301 100644 --- a/sound/soc/ti/omap-hdmi.c +++ b/sound/soc/ti/omap-hdmi.c @@ -346,7 +346,7 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev) return -EINVAL; } - ad = devm_kzalloc(dev, sizeof(*ad), GFP_KERNEL); + ad = devm_kzalloc_obj(dev, *ad); if (!ad) return -ENOMEM; ad->dssdev = ha->dev; @@ -375,14 +375,14 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev) if (ret) return ret; - card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); + card = devm_kzalloc_obj(dev, *card); if (!card) return -ENOMEM; card->name = "HDMI"; card->owner = THIS_MODULE; card->dai_link = - devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL); + devm_kzalloc_obj(dev, *(card->dai_link)); if (!card->dai_link) return -ENOMEM; diff --git a/sound/soc/ti/omap-mcbsp-st.c b/sound/soc/ti/omap-mcbsp-st.c index b762d5d3e33b6e..7c0c23296ec423 100644 --- a/sound/soc/ti/omap-mcbsp-st.c +++ b/sound/soc/ti/omap-mcbsp-st.c @@ -332,7 +332,7 @@ int omap_mcbsp_st_init(struct platform_device *pdev) if (!res) return 0; - st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL); + st_data = devm_kzalloc_obj(mcbsp->dev, *mcbsp->st_data); if (!st_data) return -ENOMEM; diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c index 889e357b64d080..6e0c7d7359f49a 100644 --- a/sound/soc/ti/omap-mcbsp.c +++ b/sound/soc/ti/omap-mcbsp.c @@ -1389,7 +1389,7 @@ static int asoc_mcbsp_probe(struct platform_device *pdev) dev_err(&pdev->dev, "missing platform data.\n"); return -EINVAL; } - mcbsp = devm_kzalloc(&pdev->dev, sizeof(struct omap_mcbsp), GFP_KERNEL); + mcbsp = devm_kzalloc_obj(&pdev->dev, struct omap_mcbsp); if (!mcbsp) return -ENOMEM; diff --git a/sound/soc/ti/omap-mcpdm.c b/sound/soc/ti/omap-mcpdm.c index 5698d2f26973a1..85892f8730cb9f 100644 --- a/sound/soc/ti/omap-mcpdm.c +++ b/sound/soc/ti/omap-mcpdm.c @@ -540,7 +540,7 @@ static int asoc_mcpdm_probe(struct platform_device *pdev) struct resource *res; int ret; - mcpdm = devm_kzalloc(&pdev->dev, sizeof(struct omap_mcpdm), GFP_KERNEL); + mcpdm = devm_kzalloc_obj(&pdev->dev, struct omap_mcpdm); if (!mcpdm) return -ENOMEM; diff --git a/sound/soc/ti/omap-twl4030.c b/sound/soc/ti/omap-twl4030.c index a3ab52b2b64e2c..b52466dacbcf63 100644 --- a/sound/soc/ti/omap-twl4030.c +++ b/sound/soc/ti/omap-twl4030.c @@ -212,7 +212,7 @@ static int omap_twl4030_probe(struct platform_device *pdev) card->dev = &pdev->dev; - priv = devm_kzalloc(&pdev->dev, sizeof(struct omap_twl4030), GFP_KERNEL); + priv = devm_kzalloc_obj(&pdev->dev, struct omap_twl4030); if (priv == NULL) return -ENOMEM; diff --git a/sound/soc/ti/rx51.c b/sound/soc/ti/rx51.c index b4b26cb0cac517..7a626c11fa98c5 100644 --- a/sound/soc/ti/rx51.c +++ b/sound/soc/ti/rx51.c @@ -410,7 +410,7 @@ static int rx51_soc_probe(struct platform_device *pdev) rx51_codec_conf[1].dlc.of_node = dai_node; } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc_obj(dev, *pdata); if (pdata == NULL) return -ENOMEM; diff --git a/sound/soc/ti/sdma-pcm.c b/sound/soc/ti/sdma-pcm.c index 9e7691103f0530..98474dd6dd66b3 100644 --- a/sound/soc/ti/sdma-pcm.c +++ b/sound/soc/ti/sdma-pcm.c @@ -44,7 +44,7 @@ int sdma_pcm_platform_register(struct device *dev, return devm_snd_dmaengine_pcm_register(dev, &sdma_dmaengine_pcm_config, 0); - config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); + config = devm_kzalloc_obj(dev, *config); if (!config) return -ENOMEM; diff --git a/sound/soc/uniphier/aio-cpu.c b/sound/soc/uniphier/aio-cpu.c index b263526f19905a..1d65d9f3b39ee3 100644 --- a/sound/soc/uniphier/aio-cpu.c +++ b/sound/soc/uniphier/aio-cpu.c @@ -738,7 +738,7 @@ int uniphier_aio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret, i, j; - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc_obj(dev, *chip); if (!chip) return -ENOMEM; @@ -764,9 +764,7 @@ int uniphier_aio_probe(struct platform_device *pdev) chip->num_aios = chip->chip_spec->num_dais; chip->num_wup_aios = chip->num_aios; - chip->aios = devm_kcalloc(dev, - chip->num_aios, sizeof(struct uniphier_aio), - GFP_KERNEL); + chip->aios = devm_kzalloc_objs(dev, struct uniphier_aio, chip->num_aios); if (!chip->aios) return -ENOMEM; diff --git a/sound/soc/uniphier/evea.c b/sound/soc/uniphier/evea.c index 7def3e7e061943..d5f29737b945ff 100644 --- a/sound/soc/uniphier/evea.c +++ b/sound/soc/uniphier/evea.c @@ -453,7 +453,7 @@ static int evea_probe(struct platform_device *pdev) void __iomem *preg; int ret; - evea = devm_kzalloc(&pdev->dev, sizeof(struct evea_priv), GFP_KERNEL); + evea = devm_kzalloc_obj(&pdev->dev, struct evea_priv); if (!evea) return -ENOMEM; diff --git a/sound/soc/ux500/ux500_msp_dai.c b/sound/soc/ux500/ux500_msp_dai.c index c135a77766ca43..a8ad64e919360c 100644 --- a/sound/soc/ux500/ux500_msp_dai.c +++ b/sound/soc/ux500/ux500_msp_dai.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -350,21 +349,13 @@ static int ux500_msp_dai_startup(struct snd_pcm_substream *substream, dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id, snd_pcm_stream_str(substream)); - /* Enable regulator */ - ret = regulator_enable(drvdata->reg_vape); - if (ret != 0) { - dev_err(drvdata->msp->dev, - "%s: Failed to enable regulator!\n", __func__); - return ret; - } - /* Prepare and enable clocks */ dev_dbg(dai->dev, "%s: Enabling MSP-clocks.\n", __func__); ret = clk_prepare_enable(drvdata->pclk); if (ret) { dev_err(drvdata->msp->dev, "%s: Failed to prepare/enable pclk!\n", __func__); - goto err_pclk; + return ret; } ret = clk_prepare_enable(drvdata->clk); @@ -377,15 +368,12 @@ static int ux500_msp_dai_startup(struct snd_pcm_substream *substream, return ret; err_clk: clk_disable_unprepare(drvdata->pclk); -err_pclk: - regulator_disable(drvdata->reg_vape); return ret; } static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - int ret; struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); unsigned int configured = is_playback ? PLAYBACK_CONFIGURED : @@ -408,13 +396,6 @@ static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream, /* Disable and unprepare clocks */ clk_disable_unprepare(drvdata->clk); clk_disable_unprepare(drvdata->pclk); - - /* Disable regulator */ - ret = regulator_disable(drvdata->reg_vape); - if (ret < 0) - dev_err(dai->dev, - "%s: ERROR: Failed to disable regulator (%d)!\n", - __func__, ret); } static int ux500_msp_dai_prepare(struct snd_pcm_substream *substream, @@ -621,15 +602,11 @@ static int ux500_msp_dai_of_probe(struct snd_soc_dai *dai) struct snd_dmaengine_dai_dma_data *playback_dma_data; struct snd_dmaengine_dai_dma_data *capture_dma_data; - playback_dma_data = devm_kzalloc(dai->dev, - sizeof(*playback_dma_data), - GFP_KERNEL); + playback_dma_data = devm_kzalloc_obj(dai->dev, *playback_dma_data); if (!playback_dma_data) return -ENOMEM; - capture_dma_data = devm_kzalloc(dai->dev, - sizeof(*capture_dma_data), - GFP_KERNEL); + capture_dma_data = devm_kzalloc_obj(dai->dev, *capture_dma_data); if (!capture_dma_data) return -ENOMEM; @@ -689,9 +666,7 @@ static int ux500_msp_drv_probe(struct platform_device *pdev) struct reset_control *reset; int ret = 0; - drvdata = devm_kzalloc(&pdev->dev, - sizeof(struct ux500_msp_i2s_drvdata), - GFP_KERNEL); + drvdata = devm_kzalloc_obj(&pdev->dev, struct ux500_msp_i2s_drvdata); if (!drvdata) return -ENOMEM; @@ -701,14 +676,6 @@ static int ux500_msp_drv_probe(struct platform_device *pdev) drvdata->rx_mask = 0x01; drvdata->slot_width = 16; - drvdata->reg_vape = devm_regulator_get(&pdev->dev, "v-ape"); - if (IS_ERR(drvdata->reg_vape)) { - ret = PTR_ERR(drvdata->reg_vape); - dev_err(&pdev->dev, - "%s: ERROR: Failed to get Vape supply (%d)!\n", - __func__, ret); - return ret; - } drvdata->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); if (IS_ERR(drvdata->pclk)) { ret = PTR_ERR(drvdata->pclk); diff --git a/sound/soc/ux500/ux500_msp_dai.h b/sound/soc/ux500/ux500_msp_dai.h index aae582030d9594..7e63e8c0b5b445 100644 --- a/sound/soc/ux500/ux500_msp_dai.h +++ b/sound/soc/ux500/ux500_msp_dai.h @@ -34,7 +34,6 @@ enum ux500_msp_clock_id { struct ux500_msp_i2s_drvdata { struct ux500_msp *msp; - struct regulator *reg_vape; unsigned int fmt; unsigned int configured; unsigned int tx_mask; @@ -49,6 +48,4 @@ struct ux500_msp_i2s_drvdata { }; -int ux500_msp_dai_set_data_delay(struct snd_soc_dai *dai, int delay); - #endif diff --git a/sound/soc/ux500/ux500_msp_i2s.c b/sound/soc/ux500/ux500_msp_i2s.c index bd2cfc618290f6..978bb5e743bf00 100644 --- a/sound/soc/ux500/ux500_msp_i2s.c +++ b/sound/soc/ux500/ux500_msp_i2s.c @@ -738,7 +738,7 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev, struct resource *res; struct ux500_msp *msp; - *msp_p = devm_kzalloc(&pdev->dev, sizeof(struct ux500_msp), GFP_KERNEL); + *msp_p = devm_kzalloc_obj(&pdev->dev, struct ux500_msp); msp = *msp_p; if (!msp) return -ENOMEM; diff --git a/sound/soc/xilinx/xlnx_formatter_pcm.c b/sound/soc/xilinx/xlnx_formatter_pcm.c index 781508aef885bd..2699bef216b1fc 100644 --- a/sound/soc/xilinx/xlnx_formatter_pcm.c +++ b/sound/soc/xilinx/xlnx_formatter_pcm.c @@ -602,7 +602,7 @@ static int xlnx_formatter_pcm_probe(struct platform_device *pdev) if (IS_ERR(axi_clk)) return dev_err_probe(dev, PTR_ERR(axi_clk), "failed to get s_axi_lite_aclk"); - aud_drv_data = devm_kzalloc(dev, sizeof(*aud_drv_data), GFP_KERNEL); + aud_drv_data = devm_kzalloc_obj(dev, *aud_drv_data); if (!aud_drv_data) return -ENOMEM; diff --git a/sound/soc/xilinx/xlnx_i2s.c b/sound/soc/xilinx/xlnx_i2s.c index 2732581254979c..090d59c0781d9a 100644 --- a/sound/soc/xilinx/xlnx_i2s.c +++ b/sound/soc/xilinx/xlnx_i2s.c @@ -174,7 +174,7 @@ static int xlnx_i2s_probe(struct platform_device *pdev) u32 format; struct device *dev = &pdev->dev; - drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL); + drv_data = devm_kzalloc_obj(&pdev->dev, *drv_data); if (!drv_data) return -ENOMEM; diff --git a/sound/soc/xilinx/xlnx_spdif.c b/sound/soc/xilinx/xlnx_spdif.c index a70ca6beb646fa..9fdafd45c38125 100644 --- a/sound/soc/xilinx/xlnx_spdif.c +++ b/sound/soc/xilinx/xlnx_spdif.c @@ -242,7 +242,7 @@ static int xlnx_spdif_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc_obj(dev, *ctx); if (!ctx) return -ENOMEM; diff --git a/sound/soc/xtensa/xtfpga-i2s.c b/sound/soc/xtensa/xtfpga-i2s.c index e5e8b72fd817a7..15ebda17e578b9 100644 --- a/sound/soc/xtensa/xtfpga-i2s.c +++ b/sound/soc/xtensa/xtfpga-i2s.c @@ -538,7 +538,7 @@ static int xtfpga_i2s_probe(struct platform_device *pdev) struct xtfpga_i2s *i2s; int err, irq; - i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc_obj(&pdev->dev, *i2s); if (!i2s) return -ENOMEM; diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c index 634dc36f2eade6..d28465e916df24 100644 --- a/sound/usb/caiaq/device.c +++ b/sound/usb/caiaq/device.c @@ -600,14 +600,19 @@ static void snd_disconnect(struct usb_interface *intf) snd_card_disconnect(card); + /* + * Kill the EP1 URB before disconnecting the input device: its + * completion reports into cdev->input_dev, which input_disconnect() + * frees without clearing the pointer. + */ + usb_kill_urb(cdev->ep1_in_urb); + usb_kill_urb(cdev->midi_out_urb); + #ifdef CONFIG_SND_USB_CAIAQ_INPUT snd_usb_caiaq_input_disconnect(cdev); #endif snd_usb_caiaq_audio_disconnect(cdev); - usb_kill_urb(cdev->ep1_in_urb); - usb_kill_urb(cdev->midi_out_urb); - snd_card_free_when_closed(card); } diff --git a/sound/usb/format.c b/sound/usb/format.c index cf0da3ca3eaddc..e2219aeb977257 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -583,7 +583,7 @@ static int validate_sample_rate_table_v2v3(struct snd_usb_audio *chip, UAC2_AS_VAL_ALT_SETTINGS)) return 0; - table = kcalloc(fp->nr_rates, sizeof(*table), GFP_KERNEL); + table = kzalloc_objs(*table, fp->nr_rates); if (!table) return -ENOMEM; diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index c2f7b08607ac86..57a26492dd6147 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1337,6 +1337,12 @@ static void retire_capture_urb(struct snd_usb_substream *subs, "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); bytes = urb->iso_frame_desc[i].actual_length; + if (unlikely(bytes > urb->iso_frame_desc[i].length)) { + dev_warn_ratelimited(&subs->dev->dev, + "packet %d: actual_length %u exceeds length %u, dropping\n", + i, bytes, urb->iso_frame_desc[i].length); + continue; + } if (subs->stream_offset_adj > 0) { unsigned int adj = min(subs->stream_offset_adj, bytes); cp += adj; diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 5ee568e0454cb4..b7e17b14feb318 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1828,8 +1828,7 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) * Allocate playback pcm index array based on number of possible * playback paths within the UAC descriptors. */ - sdev->ppcm_idx = kcalloc(sdev->num_playback, sizeof(unsigned int), - GFP_KERNEL); + sdev->ppcm_idx = kzalloc_objs(unsigned int, sdev->num_playback); if (!sdev->ppcm_idx) goto unreg_xhci; diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index b6da5bcb15e400..56f32b3f873f1b 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -187,6 +187,40 @@ }, }, +/* + * Creative Technology, Ltd Live! Cam Chat HD [VF0790] + * Same audio interface layout as the VF0770 above. The 24-bit altsettings + * advertise the same wMaxPacketSize as their 16-bit counterparts, so only + * 3/4 of the frames fit into each packet and the audio is chopped. Only + * report the 16-bit 48kHz altsetting. + */ +{ + USB_AUDIO_DEVICE(0x041e, 0x4097), + QUIRK_DRIVER_INFO { + QUIRK_DATA_COMPOSITE { + { QUIRK_DATA_STANDARD_MIXER(2) }, + { + QUIRK_DATA_AUDIOFORMAT(3) { + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .channels = 2, + .fmt_bits = 16, + .iface = 3, + .altsetting = 4, + .altset_idx = 4, + .endpoint = 0x82, + .ep_attr = 0x05, + .rates = SNDRV_PCM_RATE_48000, + .rate_min = 48000, + .rate_max = 48000, + .nr_rates = 1, + .rate_table = (unsigned int[]) { 48000 }, + }, + }, + QUIRK_COMPOSITE_END + }, + }, +}, + /* * HP Wireless Audio * When not ignored, causes instability issues for some users, forcing them to diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 7c581e283903ff..a4eb0d0cdf4ba4 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -2558,6 +2558,10 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { QUIRK_FLAG_GENERIC_IMPLICIT_FB), DEVICE_FLG(0x0499, 0x1516, /* Yamaha ZG02 */ QUIRK_FLAG_GENERIC_IMPLICIT_FB), + DEVICE_FLG(0x0499, 0x1764, /* Yamaha MODX M, 5 stereo, MIDI 2.0 */ + QUIRK_FLAG_ALWAYS_SET_RATE), + DEVICE_FLG(0x0499, 0x1773, /* Yamaha MODX M, 5 stereo, MIDI 1.0 */ + QUIRK_FLAG_ALWAYS_SET_RATE), DEVICE_FLG(0x0499, 0x3108, /* Yamaha YIT-W12TX */ QUIRK_FLAG_GET_SAMPLE_RATE), DEVICE_FLG(0x04d8, 0xfeea, /* Benchmark DAC1 Pre */ @@ -2651,6 +2655,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { QUIRK_FLAG_CTL_MSG_DELAY_1M), DEVICE_FLG(0x0bda, 0x498a, /* Realtek Semiconductor Corp. */ QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE), + DEVICE_FLG(0x0bda, 0x8808, /* RYDZ Technology Piva AC20 */ + QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), DEVICE_FLG(0x0c45, 0x6340, /* Sonix HD USB Camera */ QUIRK_FLAG_GET_SAMPLE_RATE), DEVICE_FLG(0x0c45, 0x636b, /* Microdia JP001 USB Camera */ @@ -2833,6 +2839,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { QUIRK_FLAG_DSD_RAW), DEVICE_FLG(0x3302, 0x17c2, /* TTGK Technology USB-C Audio */ QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY), + DEVICE_FLG(0x3302, 0x39c3, /* NiceHCK Octave */ + QUIRK_FLAG_DSD_RAW), DEVICE_FLG(0x339b, 0x3a07, /* Synaptics HONOR USB-C HEADSET */ QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE), DEVICE_FLG(0x3443, 0x930d, /* NexiGo N930W 60fps Webcam */ diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h index 7b6deed17d4b1d..17edafdcc8905f 100644 --- a/sound/usb/usx2y/usbusx2y.h +++ b/sound/usb/usx2y/usbusx2y.h @@ -46,6 +46,7 @@ struct snd_usx2y_async_seq { struct snd_usx2y_urb_seq { int submitted; int len; + int pending; /* completions still to come */ struct urb *urb[] __counted_by(len); }; diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c index 798c9bb5386a2b..ef24c3ec690f55 100644 --- a/sound/usb/usx2y/usbusx2yaudio.c +++ b/sound/usb/usx2y/usbusx2yaudio.c @@ -84,7 +84,7 @@ static int usx2y_urb_capt_retire(struct snd_usx2y_substream *subs) subs->transfer_done += lens; /* update the pointer, call callback if necessary */ if (subs->transfer_done >= runtime->period_size) { - subs->transfer_done -= runtime->period_size; + subs->transfer_done %= runtime->period_size; snd_pcm_period_elapsed(subs->pcm_substream); } return 0; @@ -184,7 +184,7 @@ static void usx2y_urb_play_retire(struct snd_usx2y_substream *subs, struct urb * if (subs->hwptr_done >= runtime->buffer_size) subs->hwptr_done -= runtime->buffer_size; if (subs->transfer_done >= runtime->period_size) { - subs->transfer_done -= runtime->period_size; + subs->transfer_done %= runtime->period_size; snd_pcm_period_elapsed(subs->pcm_substream); } } @@ -672,7 +672,7 @@ static void i_usx2y_04int(struct urb *urb) if (urb->status) dev_err(&urb->dev->dev, "%s() urb->status=%i\n", __func__, urb->status); - if (!--usx2y->us04->len) + if (!--usx2y->us04->pending) wake_up(&usx2y->in04_wait_queue); } @@ -691,6 +691,7 @@ static int usx2y_rate_set(struct usx2ydev *usx2y, int rate) goto cleanup; } us->len = NOOF_SETRATE_URBS; + us->pending = NOOF_SETRATE_URBS; usbdata = kmalloc_objs(int, NOOF_SETRATE_URBS); if (!usbdata) { err = -ENOMEM; @@ -712,9 +713,9 @@ static int usx2y_rate_set(struct usx2ydev *usx2y, int rate) goto cleanup; us->submitted = 0; usx2y->us04 = us; - wait_event_timeout(usx2y->in04_wait_queue, !us->len, HZ); + wait_event_timeout(usx2y->in04_wait_queue, !us->pending, HZ); usx2y->us04 = NULL; - if (us->len) + if (us->pending) err = -ENODEV; cleanup: if (us) { diff --git a/sound/virtio/virtio_card.c b/sound/virtio/virtio_card.c index 6f35276416fedd..06eefe612f4d7d 100644 --- a/sound/virtio/virtio_card.c +++ b/sound/virtio/virtio_card.c @@ -305,7 +305,7 @@ static int virtsnd_probe(struct virtio_device *vdev) unsigned int i; int rc; - snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL); + snd = devm_kzalloc_obj(&vdev->dev, *snd); if (!snd) return -ENOMEM; diff --git a/sound/virtio/virtio_chmap.c b/sound/virtio/virtio_chmap.c index 5bc924933a59fb..847c8947a753c2 100644 --- a/sound/virtio/virtio_chmap.c +++ b/sound/virtio/virtio_chmap.c @@ -67,8 +67,7 @@ int virtsnd_chmap_parse_cfg(struct virtio_snd *snd) if (!snd->nchmaps) return 0; - snd->chmaps = devm_kcalloc(&vdev->dev, snd->nchmaps, - sizeof(*snd->chmaps), GFP_KERNEL); + snd->chmaps = devm_kzalloc_objs(&vdev->dev, *snd->chmaps, snd->nchmaps); if (!snd->chmaps) return -ENOMEM; @@ -155,9 +154,8 @@ int virtsnd_chmap_build_devs(struct virtio_snd *snd) if (!vs->nchmaps) continue; - vs->chmaps = devm_kcalloc(&vdev->dev, vs->nchmaps + 1, - sizeof(*vs->chmaps), - GFP_KERNEL); + vs->chmaps = devm_kzalloc_objs(&vdev->dev, *vs->chmaps, + vs->nchmaps + 1); if (!vs->chmaps) return -ENOMEM; diff --git a/sound/virtio/virtio_jack.c b/sound/virtio/virtio_jack.c index 68e40c7f5039e5..1565e07104a04d 100644 --- a/sound/virtio/virtio_jack.c +++ b/sound/virtio/virtio_jack.c @@ -139,8 +139,7 @@ int virtsnd_jack_parse_cfg(struct virtio_snd *snd) if (!snd->njacks) return 0; - snd->jacks = devm_kcalloc(&vdev->dev, snd->njacks, sizeof(*snd->jacks), - GFP_KERNEL); + snd->jacks = devm_kzalloc_objs(&vdev->dev, *snd->jacks, snd->njacks); if (!snd->jacks) return -ENOMEM; diff --git a/sound/virtio/virtio_kctl.c b/sound/virtio/virtio_kctl.c index 45f7b6a5b3080a..ed8031b91eab32 100644 --- a/sound/virtio/virtio_kctl.c +++ b/sound/virtio/virtio_kctl.c @@ -376,8 +376,7 @@ static int virtsnd_kctl_get_enum_items(struct virtio_snd *snd, unsigned int cid) if (!msg) return -ENOMEM; - kctl->items = devm_kcalloc(&vdev->dev, n, sizeof(*kctl->items), - GFP_KERNEL); + kctl->items = devm_kzalloc_objs(&vdev->dev, *kctl->items, n); if (!kctl->items) { virtsnd_ctl_msg_unref(msg); return -ENOMEM; @@ -412,13 +411,12 @@ int virtsnd_kctl_parse_cfg(struct virtio_snd *snd) if (!snd->nkctls) return 0; - snd->kctl_infos = devm_kcalloc(&vdev->dev, snd->nkctls, - sizeof(*snd->kctl_infos), GFP_KERNEL); + snd->kctl_infos = devm_kzalloc_objs(&vdev->dev, *snd->kctl_infos, + snd->nkctls); if (!snd->kctl_infos) return -ENOMEM; - snd->kctls = devm_kcalloc(&vdev->dev, snd->nkctls, sizeof(*snd->kctls), - GFP_KERNEL); + snd->kctls = devm_kzalloc_objs(&vdev->dev, *snd->kctls, snd->nkctls); if (!snd->kctls) return -ENOMEM; diff --git a/sound/virtio/virtio_pcm.c b/sound/virtio/virtio_pcm.c index be3893de40a559..ec2a0a883b2b7d 100644 --- a/sound/virtio/virtio_pcm.c +++ b/sound/virtio/virtio_pcm.c @@ -245,7 +245,7 @@ struct virtio_pcm *virtsnd_pcm_find_or_create(struct virtio_snd *snd, u32 nid) if (!IS_ERR(vpcm)) return vpcm; - vpcm = devm_kzalloc(&vdev->dev, sizeof(*vpcm), GFP_KERNEL); + vpcm = devm_kzalloc_obj(&vdev->dev, *vpcm); if (!vpcm) return ERR_PTR(-ENOMEM); @@ -335,8 +335,8 @@ int virtsnd_pcm_parse_cfg(struct virtio_snd *snd) if (!snd->nsubstreams) return 0; - snd->substreams = devm_kcalloc(&vdev->dev, snd->nsubstreams, - sizeof(*snd->substreams), GFP_KERNEL); + snd->substreams = devm_kzalloc_objs(&vdev->dev, *snd->substreams, + snd->nsubstreams); if (!snd->substreams) return -ENOMEM; @@ -449,9 +449,9 @@ int virtsnd_pcm_build_devs(struct virtio_snd *snd) continue; stream->substreams = - devm_kcalloc(&vdev->dev, stream->nsubstreams, - sizeof(*stream->substreams), - GFP_KERNEL); + devm_kzalloc_objs(&vdev->dev, + *stream->substreams, + stream->nsubstreams); if (!stream->substreams) return -ENOMEM; diff --git a/sound/xen/xen_snd_front.c b/sound/xen/xen_snd_front.c index c56d17479f05d1..4cb22d160fc7e2 100644 --- a/sound/xen/xen_snd_front.c +++ b/sound/xen/xen_snd_front.c @@ -294,8 +294,7 @@ static int xen_drv_probe(struct xenbus_device *xb_dev, { struct xen_snd_front_info *front_info; - front_info = devm_kzalloc(&xb_dev->dev, - sizeof(*front_info), GFP_KERNEL); + front_info = devm_kzalloc_obj(&xb_dev->dev, *front_info); if (!front_info) return -ENOMEM; diff --git a/sound/xen/xen_snd_front_alsa.c b/sound/xen/xen_snd_front_alsa.c index a6dd196f73d662..50e4990505d8ab 100644 --- a/sound/xen/xen_snd_front_alsa.c +++ b/sound/xen/xen_snd_front_alsa.c @@ -701,20 +701,18 @@ static int new_pcm_instance(struct xen_snd_front_card_info *card_info, if (instance_cfg->num_streams_pb) { pcm_instance_info->streams_pb = - devm_kcalloc(&card_info->card->card_dev, - instance_cfg->num_streams_pb, - sizeof(struct xen_snd_front_pcm_stream_info), - GFP_KERNEL); + devm_kzalloc_objs(&card_info->card->card_dev, + struct xen_snd_front_pcm_stream_info, + instance_cfg->num_streams_pb); if (!pcm_instance_info->streams_pb) return -ENOMEM; } if (instance_cfg->num_streams_cap) { pcm_instance_info->streams_cap = - devm_kcalloc(&card_info->card->card_dev, - instance_cfg->num_streams_cap, - sizeof(struct xen_snd_front_pcm_stream_info), - GFP_KERNEL); + devm_kzalloc_objs(&card_info->card->card_dev, + struct xen_snd_front_pcm_stream_info, + instance_cfg->num_streams_cap); if (!pcm_instance_info->streams_cap) return -ENOMEM; } @@ -784,9 +782,9 @@ int xen_snd_front_alsa_init(struct xen_snd_front_info *front_info) front_info->card_info = card_info; card_info->card = card; card_info->pcm_instances = - devm_kcalloc(dev, cfg->num_pcm_instances, - sizeof(struct xen_snd_front_pcm_instance_info), - GFP_KERNEL); + devm_kzalloc_objs(dev, + struct xen_snd_front_pcm_instance_info, + cfg->num_pcm_instances); if (!card_info->pcm_instances) { ret = -ENOMEM; goto fail; diff --git a/sound/xen/xen_snd_front_cfg.c b/sound/xen/xen_snd_front_cfg.c index 55ecf766ca6780..745e3dbf219ad1 100644 --- a/sound/xen/xen_snd_front_cfg.c +++ b/sound/xen/xen_snd_front_cfg.c @@ -435,10 +435,9 @@ static int cfg_device(struct xen_snd_front_info *front_info, if (pcm_instance->num_streams_pb) { pcm_instance->streams_pb = - devm_kcalloc(&front_info->xb_dev->dev, - pcm_instance->num_streams_pb, - sizeof(struct xen_front_cfg_stream), - GFP_KERNEL); + devm_kzalloc_objs(&front_info->xb_dev->dev, + struct xen_front_cfg_stream, + pcm_instance->num_streams_pb); if (!pcm_instance->streams_pb) { ret = -ENOMEM; goto fail; @@ -447,10 +446,9 @@ static int cfg_device(struct xen_snd_front_info *front_info, if (pcm_instance->num_streams_cap) { pcm_instance->streams_cap = - devm_kcalloc(&front_info->xb_dev->dev, - pcm_instance->num_streams_cap, - sizeof(struct xen_front_cfg_stream), - GFP_KERNEL); + devm_kzalloc_objs(&front_info->xb_dev->dev, + struct xen_front_cfg_stream, + pcm_instance->num_streams_cap); if (!pcm_instance->streams_cap) { ret = -ENOMEM; goto fail; @@ -501,9 +499,9 @@ int xen_snd_front_cfg_card(struct xen_snd_front_info *front_info, cfg_read_pcm_hw(xb_dev->nodename, NULL, &cfg->pcm_hw); cfg->pcm_instances = - devm_kcalloc(&front_info->xb_dev->dev, num_devices, - sizeof(struct xen_front_cfg_pcm_instance), - GFP_KERNEL); + devm_kzalloc_objs(&front_info->xb_dev->dev, + struct xen_front_cfg_pcm_instance, + num_devices); if (!cfg->pcm_instances) return -ENOMEM; diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 6f476e3c06b8c1..d3f840c5adce78 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -68,6 +68,23 @@ static int xbc_show_value(struct xbc_node *node, bool semicolon) return i; } +/* Match the conditions under which the compact formatter opens braces. */ +static bool xbc_node_needs_braces(struct xbc_node *node) +{ + struct xbc_node *child = xbc_node_get_child(node); + + if (child && xbc_node_is_value(child)) + child = xbc_node_get_next(child); + if (!child) + return false; + if (child->next) + return true; + + /* A single subkey with both a value and subkeys is not compacted. */ + child = xbc_node_get_child(child); + return child && xbc_node_is_value(child) && child->next; +} + static void xbc_show_compact_tree(void) { struct xbc_node *node, *cnode = NULL, *vnode; @@ -128,14 +145,12 @@ static void xbc_show_compact_tree(void) node = xbc_node_get_parent(node); if (!node) return; - if (!xbc_node_get_child(node)->next) + if (!depth || !xbc_node_needs_braces(node)) continue; - if (depth) { - depth--; - for (i = 0; i < depth; i++) - printf("\t"); - printf("}\n"); - } + depth--; + for (i = 0; i < depth; i++) + printf("\t"); + printf("}\n"); } node = xbc_node_get_next(node); } diff --git a/tools/bootconfig/samples/exp-good-mixed-kv1.bconf b/tools/bootconfig/samples/exp-good-mixed-kv1.bconf index 8346287d9251a3..0b8b2f59da31ee 100644 --- a/tools/bootconfig/samples/exp-good-mixed-kv1.bconf +++ b/tools/bootconfig/samples/exp-good-mixed-kv1.bconf @@ -1,2 +1,7 @@ key = "value"; key.subkey = "another-value"; +a { + b = "v"; + b.c = "w"; + z = "q"; +} diff --git a/tools/bootconfig/samples/good-mixed-kv1.bconf b/tools/bootconfig/samples/good-mixed-kv1.bconf index 1761547dd05cae..35442ee62b751e 100644 --- a/tools/bootconfig/samples/good-mixed-kv1.bconf +++ b/tools/bootconfig/samples/good-mixed-kv1.bconf @@ -1,3 +1,8 @@ # value -> subkey pattern key = value key.subkey = another-value + +# A valued parent with one subkey must not close its enclosing brace. +a.b = v +a.b.c = w +a.z = q diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh index 530ce7e28d634e..f584f7637e12a5 100755 --- a/tools/bootconfig/test-bootconfig.sh +++ b/tools/bootconfig/test-bootconfig.sh @@ -100,6 +100,16 @@ xpass $BOOTCONF -a $TEMPCONF $INITRD printf "badnode\n" >> $TEMPCONF xfail $BOOTCONF -a $TEMPCONF $INITRD +echo "Max key depth check" + +printf 'a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p = "value"\n' > $TEMPCONF +xpass $BOOTCONF -a $TEMPCONF $INITRD +$BOOTCONF -l $INITRD > $OUTFILE +xpass cmp $TEMPCONF $OUTFILE + +printf 'a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q = "value"\n' > $TEMPCONF +xfail $BOOTCONF -a $TEMPCONF $INITRD + echo "Max filesize check" # Max size is 32767 (including terminal byte) @@ -171,6 +181,24 @@ $BOOTCONF $INITRD > $OUTFILE xfail grep -q 'val[[:space:]]' $OUTFILE xpass grep -q 'val2[[:space:]]' $OUTFILE +echo "Remove unquoted trailing whitespace at end of file" +printf 'foo = val \t' > $TEMPCONF +$BOOTCONF -l $TEMPCONF > $OUTFILE +printf 'foo = "val"\n' > $TEMPCONF +xpass cmp $TEMPCONF $OUTFILE + +echo "Remove trailing whitespace from the last array value at end of file" +printf 'foo = first, last \t' > $TEMPCONF +$BOOTCONF -l $TEMPCONF > $OUTFILE +printf 'foo = "first", "last"\n' > $TEMPCONF +xpass cmp $TEMPCONF $OUTFILE + +echo "Keep quoted trailing whitespace at end of file" +printf 'foo = "val "' > $TEMPCONF +$BOOTCONF -l $TEMPCONF > $OUTFILE +printf 'foo = "val "\n' > $TEMPCONF +xpass cmp $TEMPCONF $OUTFILE + echo "Showing correct line:column of no closing brace" cat > $TEMPCONF << EOF foo { diff --git a/tools/include/io_uring/mini_liburing.h b/tools/include/io_uring/mini_liburing.h index 44be4446feda59..6afe7efb449785 100644 --- a/tools/include/io_uring/mini_liburing.h +++ b/tools/include/io_uring/mini_liburing.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -269,7 +270,7 @@ static inline void io_uring_prep_cmd(struct io_uring_sqe *sqe, int op, sqe->level = level; sqe->optname = optname; - sqe->optval = (unsigned long long)optval; + sqe->optval = (unsigned long long)(uintptr_t)optval; sqe->optlen = optlen; } diff --git a/tools/include/vdso/unaligned.h b/tools/include/vdso/unaligned.h index 9076483c9fbbd0..726fd15efc8260 100644 --- a/tools/include/vdso/unaligned.h +++ b/tools/include/vdso/unaligned.h @@ -4,6 +4,20 @@ #include +#ifdef CONFIG_VDSO_UNALIGNED_PACKED + +#define __get_unaligned_t(type, ptr) ({ \ + const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \ + __get_pptr->x; \ +}) + +#define __put_unaligned_t(type, val, ptr) do { \ + struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \ + __put_pptr->x = (val); \ +} while (0) + +#else /* !CONFIG_VDSO_UNALIGNED_PACKED */ + /** * __get_unaligned_t - read an unaligned value from memory. * @type: the type to load from the pointer. @@ -41,4 +55,6 @@ sizeof(__put_unaligned_val)); \ } while (0) +#endif /* CONFIG_VDSO_UNALIGNED_PACKED */ + #endif /* __VDSO_UNALIGNED_H */ diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index d2ff6f5d6d5b66..95c31803e7227e 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -2222,6 +2222,7 @@ struct btf_pipe { static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off) { + struct btf *base; long mapped_off; int off, err; @@ -2234,6 +2235,19 @@ static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off) return 0; } + /* + * btf__add_str() first looks the string up in the base BTFs of dst, + * which makes each of them modifiable and frees its raw data. If src + * shares a base with dst and the string lives in that base, the + * pointer taken below would be left dangling. So make the bases + * modifiable before the pointer is taken. + */ + for (base = p->dst->base_btf; base; base = base->base_btf) { + err = btf_ensure_modifiable(base); + if (err) + return err; + } + off = btf__add_str(p->dst, btf__str_by_offset(p->src, *str_off)); if (off < 0) return off; diff --git a/tools/testing/selftests/alsa/seq-ump-test.c b/tools/testing/selftests/alsa/seq-ump-test.c index d1eca920cfc8e1..55bb7ea5b02f9f 100644 --- a/tools/testing/selftests/alsa/seq-ump-test.c +++ b/tools/testing/selftests/alsa/seq-ump-test.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Test the conversion of MIDI 1.0 sequencer events to UMP. + * Test the sequencer conversion of MIDI 1.0 events to UMP, and of UMP + * packets between MIDI 1.0 and MIDI 2.0 clients. * - * A legacy client sends CC and CONTROL14 events to a UMP client, and the - * test checks the packets that the UMP client receives. The converter keeps - * its RPN/NRPN state per destination port and channel, so each test uses - * new clients. + * A client sends events to a UMP client, and the test checks the packets + * that the UMP client receives. The converter keeps its RPN/NRPN state + * per destination port and channel, so each test uses new clients. */ #include #include @@ -124,6 +124,48 @@ static int send_event(struct seq_client *src, struct seq_client *dst, return 0; } +static int send_note(struct seq_client *src, struct seq_client *dst, + int type, int ch, int note, int velocity) +{ + struct snd_seq_event ev; + + memset(&ev, 0, sizeof(ev)); + ev.type = type; + ev.flags = SNDRV_SEQ_TIME_STAMP_TICK | SNDRV_SEQ_EVENT_LENGTH_FIXED; + ev.queue = SNDRV_SEQ_QUEUE_DIRECT; + ev.source.client = src->id; + ev.source.port = src->port; + ev.dest.client = dst->id; + ev.dest.port = dst->port; + ev.data.note.channel = ch; + ev.data.note.note = note; + ev.data.note.velocity = velocity; + if (write(src->fd, &ev, sizeof(ev)) != sizeof(ev)) + return -errno; + return 0; +} + +/* send a UMP packet from a UMP client */ +static int send_ump(struct seq_client *src, struct seq_client *dst, + unsigned int w0, unsigned int w1) +{ + struct snd_seq_ump_event ev; + + memset(&ev, 0, sizeof(ev)); + ev.flags = SNDRV_SEQ_TIME_STAMP_TICK | SNDRV_SEQ_EVENT_LENGTH_FIXED | + SNDRV_SEQ_EVENT_UMP; + ev.queue = SNDRV_SEQ_QUEUE_DIRECT; + ev.source.client = src->id; + ev.source.port = src->port; + ev.dest.client = dst->id; + ev.dest.port = dst->port; + ev.ump[0] = w0; + ev.ump[1] = w1; + if (write(src->fd, &ev, sizeof(ev)) != sizeof(ev)) + return -errno; + return 0; +} + /* * Read what the UMP client received until it is quiet, and keep the * packets of message type @mt. Returns the number of packets kept. @@ -212,11 +254,11 @@ static int send_events(struct seq_client *src, struct seq_client *dst, ARRAY_SIZE(ev))); \ } while (0) -/* compare the RPN/NRPN packets received with the expected ones */ -#define EXPECT_PACKETS(...) do { \ +/* compare the packets of message type @mt with the expected ones */ +#define EXPECT_MT_PACKETS(mt, ...) do { \ const struct packet want[] = { __VA_ARGS__ }; \ struct packet got[MAX_PACKETS]; \ - int n = read_packets(&self->dst, 4, got); \ + int n = read_packets(&self->dst, mt, got); \ int i; \ \ ASSERT_EQ((int)ARRAY_SIZE(want), n); \ @@ -226,12 +268,22 @@ static int send_events(struct seq_client *src, struct seq_client *dst, } \ } while (0) +/* compare the MIDI 2.0 channel voice packets received */ +#define EXPECT_PACKETS(...) EXPECT_MT_PACKETS(4, __VA_ARGS__) + #define EXPECT_NO_PACKETS() do { \ struct packet got[MAX_PACKETS]; \ \ EXPECT_EQ(0, read_packets(&self->dst, 4, got)); \ } while (0) +#define SEND_NOTE(type, ch, note, velocity) \ + ASSERT_EQ(0, send_note(&self->src, &self->dst, \ + SNDRV_SEQ_EVENT_##type, ch, note, velocity)) + +#define SEND_UMP(w0, w1) \ + ASSERT_EQ(0, send_ump(&self->src, &self->dst, w0, w1)) + /* RPN 0/1 with Data Entry */ TEST_F(seq_ump, rpn) { @@ -416,6 +468,20 @@ TEST_F(seq_ump, c14_null_nrpn_keeps_rpn_number) EXPECT_PACKETS({ RPN(0, 0, 1), data14(0x10, 0) }); } +/* a note-on with zero velocity is a note-off */ +TEST_F(seq_ump, note_on_zero_velocity) +{ + SEND_NOTE(NOTEON, 1, 60, 0); + EXPECT_PACKETS({ 0x40813c00, 0 }); +} + +/* a key pressure of zero is a key pressure, not a note-off */ +TEST_F(seq_ump, key_pressure) +{ + SEND_NOTE(KEYPRESS, 2, 64, 0); + EXPECT_PACKETS({ 0x40a24000, 0 }); +} + /* a UMP MIDI 1.0 client gets the CCs as they are, RPN selection included */ TEST(midi1_passthrough) { @@ -449,4 +515,109 @@ TEST(midi1_passthrough) close_client(&dst); } +/* a pair of clients whose MIDI versions each test chooses */ +FIXTURE(seq_pair) { + struct seq_client src; + struct seq_client dst; +}; + +FIXTURE_SETUP(seq_pair) +{ + self->src.fd = -1; + self->dst.fd = -1; +} + +FIXTURE_TEARDOWN(seq_pair) +{ + close_client(&self->src); + close_client(&self->dst); +} + +static int open_pair(struct seq_client *dst, int dst_version, + struct seq_client *src, int src_version, int *skip) +{ + int err; + + err = open_client(dst, dst_version, CAP_IN, skip); + if (!err) + err = open_client(src, src_version, CAP_OUT, skip); + return err; +} + +/* to UMP MIDI 1.0, a key pressure of zero is a key pressure */ +TEST_F(seq_pair, midi1_key_pressure) +{ + int skip = 0; + int err; + + err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0, + &self->src, 0, &skip); + if (skip) + SKIP(return, "UMP sequencer client unavailable: %s", + strerror(-err)); + ASSERT_EQ(0, err); + + SEND_NOTE(KEYPRESS, 2, 64, 0x50); + SEND_NOTE(KEYPRESS, 2, 64, 0); + EXPECT_MT_PACKETS(2, { 0x20a24050, 0 }, { 0x20a24000, 0 }); +} + +/* to UMP MIDI 1.0, a note-on with zero velocity is a note-off */ +TEST_F(seq_pair, midi1_note_on_zero_velocity) +{ + int skip = 0; + int err; + + err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0, + &self->src, 0, &skip); + if (skip) + SKIP(return, "UMP sequencer client unavailable: %s", + strerror(-err)); + ASSERT_EQ(0, err); + + SEND_NOTE(NOTEON, 1, 60, 0); + EXPECT_MT_PACKETS(2, { 0x20813c00, 0 }); +} + +/* UMP MIDI 1.0 to MIDI 2.0: a note-on with zero velocity is a note-off */ +TEST_F(seq_pair, ump_midi1_to_midi2_note) +{ + int skip = 0; + int err; + + err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_2_0, + &self->src, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0, &skip); + if (skip) + SKIP(return, "UMP sequencer client unavailable: %s", + strerror(-err)); + ASSERT_EQ(0, err); + + SEND_UMP(0x20913c00, 0); + EXPECT_PACKETS({ 0x40813c00, 0 }); +} + +/* + * UMP MIDI 2.0 to MIDI 1.0: a note-on whose velocity scales down to zero + * stays a note-on with velocity 1, and a note-off stays a note-off + */ +TEST_F(seq_pair, ump_midi2_to_midi1_note) +{ + int skip = 0; + int err; + + err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0, + &self->src, SNDRV_SEQ_CLIENT_UMP_MIDI_2_0, &skip); + if (skip) + SKIP(return, "UMP sequencer client unavailable: %s", + strerror(-err)); + ASSERT_EQ(0, err); + + SEND_UMP(0x40913c00, 0xc8000000); + SEND_UMP(0x40913c00, 0x01000000); + SEND_UMP(0x40913c00, 0); + SEND_UMP(0x40813c00, 0); + EXPECT_MT_PACKETS(2, { 0x20913c64, 0 }, { 0x20913c01, 0 }, + { 0x20913c01, 0 }, { 0x20813c00, 0 }); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c index ea1fac95b461e5..017add229befe7 100644 --- a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c +++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c @@ -11,6 +11,7 @@ #define TEST_BITMAP_BITS (2 * BITS_PER_LONG_LONG) #define TEST_BITMAP_SYNC_SPINS BPF_MAX_LOOPS #define TEST_BITMAP_ITERS 10 * 1000 * 1000 +#define TEST_BITMAP_NSEC (50 * 1000 * 1000) static struct arena_bitmap __arena *bitmap; static volatile u64 started; @@ -129,6 +130,7 @@ static int bitmap_test_common_single(int parity) static int bitmap_test_common(int parity) { + u64 start; int ret; u32 i; @@ -138,6 +140,7 @@ static int bitmap_test_common(int parity) if (ret) return ret; + start = bpf_ktime_get_ns(); for (i = zero; i < TEST_BITMAP_ITERS && can_loop; i++) { ret = bitmap_test_common_single(parity); if (ret) @@ -147,6 +150,13 @@ static int bitmap_test_common(int parity) break; bitmap_test_reset_single(parity); + + /* + * Stop before the time slice of may_goto is used up. After that the + * bmp_*() functions can't retry a cmpxchg that fails. + */ + if (bpf_ktime_get_ns() - start > TEST_BITMAP_NSEC) + break; } return 0; diff --git a/tools/testing/selftests/bpf/prog_tests/arena_mmap.c b/tools/testing/selftests/bpf/prog_tests/arena_mmap.c new file mode 100644 index 00000000000000..f55d950720f1d0 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/arena_mmap.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#define ARENA_PAGES 8 + +/* err == 0: the range ends above TASK_SIZE. EINVAL or ENOMEM, this depends on the arch */ +static void test_refused(__u64 map_extra, __u64 addr, int pages, int flags, int err) +{ + LIBBPF_OPTS(bpf_map_create_opts, opts, + .map_flags = BPF_F_MMAPABLE, + .map_extra = map_extra); + void *area; + int fd; + + fd = bpf_map_create(BPF_MAP_TYPE_ARENA, "arena", 0, 0, ARENA_PAGES, &opts); + if (fd == -EOPNOTSUPP) { + test__skip(); + return; + } + /* No task can map this range, so the kernel can also refuse the map. */ + if (fd < 0 && map_extra) + return; + if (!ASSERT_GE(fd, 0, "bpf_map_create")) + return; + + area = mmap((void *)(unsigned long)addr, pages * getpagesize(), + PROT_READ | PROT_WRITE, MAP_SHARED | flags, fd, 0); + if (!ASSERT_EQ(area, MAP_FAILED, "mmap")) + munmap(area, pages * getpagesize()); + else if (err || errno != ENOMEM) + ASSERT_EQ(errno, err ?: EINVAL, "errno"); + close(fd); +} + +void serial_test_arena_mmap(void) +{ + __u64 page = getpagesize(), last = -(ARENA_PAGES * page); + + if (test__start_subtest("long")) + test_refused(0, 0, ARENA_PAGES + 1, 0, E2BIG); + if (test__start_subtest("address_0")) + test_refused(0, 0, ARENA_PAGES, MAP_FIXED, EINVAL); + if (test__start_subtest("crosses_4g")) + test_refused(0, (1ULL << 32) - page, ARENA_PAGES, MAP_FIXED, EINVAL); + if (test__start_subtest("crosses_4g_noreplace")) + test_refused(0, (1ULL << 32) - page, ARENA_PAGES, MAP_FIXED_NOREPLACE, EINVAL); + if (test__start_subtest("wraps")) + test_refused(0, -page, ARENA_PAGES, MAP_FIXED, 0); + if (test__start_subtest("map_extra_last_pages")) + test_refused(last, last, ARENA_PAGES, MAP_FIXED, 0); +} diff --git a/tools/testing/selftests/bpf/prog_tests/dynptr.c b/tools/testing/selftests/bpf/prog_tests/dynptr.c index 4396560365e88d..19f38215d9095a 100644 --- a/tools/testing/selftests/bpf/prog_tests/dynptr.c +++ b/tools/testing/selftests/bpf/prog_tests/dynptr.c @@ -22,6 +22,9 @@ static struct { {"test_dynptr_data", SETUP_SYSCALL_SLEEP}, {"test_dynptr_copy", SETUP_SYSCALL_SLEEP}, {"test_dynptr_copy_xdp", SETUP_XDP_PROG}, + {"test_dynptr_copy_xdp_overlap", SETUP_XDP_PROG}, + {"test_dynptr_copy_xdp_overlap_src_linear", SETUP_XDP_PROG}, + {"test_dynptr_copy_xdp_overlap_dst_frag", SETUP_XDP_PROG}, {"test_dynptr_memset_zero", SETUP_SYSCALL_SLEEP}, {"test_dynptr_memset_notzero", SETUP_SYSCALL_SLEEP}, {"test_dynptr_memset_zero_offset", SETUP_SYSCALL_SLEEP}, @@ -34,6 +37,7 @@ static struct { {"test_skb_readonly", SETUP_SKB_PROG}, {"test_dynptr_skb_data", SETUP_SKB_PROG}, {"test_dynptr_skb_slice_non_linear", SETUP_SKB_PROG_NONLINEAR}, + {"test_dynptr_skb_slice_rdwr_buffer", SETUP_SKB_PROG_NONLINEAR}, {"test_dynptr_skb_meta_data", SETUP_SKB_PROG}, {"test_dynptr_skb_meta_flags", SETUP_SKB_PROG}, {"test_adjust", SETUP_SYSCALL_SLEEP}, diff --git a/tools/testing/selftests/bpf/prog_tests/fentry_kprobe_shared.c b/tools/testing/selftests/bpf/prog_tests/fentry_kprobe_shared.c new file mode 100644 index 00000000000000..751aa49d61069c --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/fentry_kprobe_shared.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "fentry_kprobe_shared.skel.h" + +static void trigger(struct fentry_kprobe_shared *skel) +{ + LIBBPF_OPTS(bpf_test_run_opts, topts); + int err; + + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry1), &topts); + ASSERT_OK(err, "test_run"); +} + +/* + * With a kprobe next to the trampoline, the ftrace site of the function + * reaches the trampoline through the list of ftrace callbacks, and so does + * the site of a trampoline that is modified to add or remove a program. + * With the fexit program, the trampoline is entered by a jmp. + */ +void test_fentry_kprobe_shared(void) +{ + struct fentry_kprobe_shared *skel; + + skel = fentry_kprobe_shared__open_and_load(); + if (!ASSERT_OK_PTR(skel, "open_and_load")) + return; + skel->bss->pid = getpid(); + + skel->links.fentry1 = bpf_program__attach(skel->progs.fentry1); + if (!ASSERT_OK_PTR(skel->links.fentry1, "attach_fentry1")) + goto out; + skel->links.kprobe1 = bpf_program__attach(skel->progs.kprobe1); + if (!ASSERT_OK_PTR(skel->links.kprobe1, "attach_kprobe1")) + goto out; + trigger(skel); + ASSERT_EQ(skel->bss->fentry1_hits, 1, "fentry1_hits"); + ASSERT_EQ(skel->bss->kprobe_hits, 1, "kprobe_hits"); + + skel->links.fentry2 = bpf_program__attach(skel->progs.fentry2); + if (!ASSERT_OK_PTR(skel->links.fentry2, "attach_fentry2")) + goto out; + trigger(skel); + ASSERT_EQ(skel->bss->fentry1_hits, 2, "fentry1_hits"); + ASSERT_EQ(skel->bss->fentry2_hits, 1, "fentry2_hits"); + ASSERT_EQ(skel->bss->kprobe_hits, 2, "kprobe_hits"); + + skel->links.fexit1 = bpf_program__attach(skel->progs.fexit1); + if (!ASSERT_OK_PTR(skel->links.fexit1, "attach_fexit1")) + goto out; + trigger(skel); + ASSERT_EQ(skel->bss->fentry1_hits, 3, "fentry1_hits"); + ASSERT_EQ(skel->bss->fentry2_hits, 2, "fentry2_hits"); + ASSERT_EQ(skel->bss->fexit_hits, 1, "fexit_hits"); + ASSERT_EQ(skel->bss->kprobe_hits, 3, "kprobe_hits"); + + bpf_link__destroy(skel->links.kprobe1); + skel->links.kprobe1 = NULL; + trigger(skel); + ASSERT_EQ(skel->bss->fentry1_hits, 4, "fentry1_hits"); + ASSERT_EQ(skel->bss->fentry2_hits, 3, "fentry2_hits"); + ASSERT_EQ(skel->bss->fexit_hits, 2, "fexit_hits"); + ASSERT_EQ(skel->bss->kprobe_hits, 3, "kprobe_hits"); +out: + fentry_kprobe_shared__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/prog_tests/freplace_args.c b/tools/testing/selftests/bpf/prog_tests/freplace_args.c new file mode 100644 index 00000000000000..d1930af23fa06a --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/freplace_args.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "freplace_args.skel.h" +#include "freplace_args_tgt.skel.h" + +/* + * An extension must not expect more of its arguments than the callers of the + * function that it replaces provide. The progs are loaded and attached to each + * other. None of them runs. + */ +static const struct test { + const char *name; + const char *ext; /* prog of freplace_args.c */ + const char *tgt; /* prog of freplace_args_tgt.c */ + const char *func; /* function of tgt that ext is loaded for */ + const char *func2; /* function of tgt that ext is attached to */ + int bad_reg; /* argument that is refused, 0: none */ +} tests[] = { + { "same_nonnull", "ext_mem_nonnull", "tc_prog", "mem_nonnull" }, + { "same_trusted", "ext_task_trusted", "tc_prog", "task_trusted" }, + { "smaller_struct", "ext_mem_smaller", "tc_prog", "mem_smaller" }, + { "larger_struct", "ext_mem_larger", "tc_prog", "mem_larger", NULL, 1 }, + { "nullable_for_nonnull", "ext_mem", "tc_prog", "mem_nonnull" }, + { "nonnull_for_nullable", "ext_mem_nonnull", "tc_prog", "mem", NULL, 2 }, + { "trusted_for_mem", "ext_task_trusted", "tc_prog", "task_mem", NULL, 1 }, + { "arg_ctx_for_ctx_type", "ext_skb_ctx", "tc_prog", "skb_ctx" }, + { "mem_for_arg_ctx", "ext_tp_mem", "tp_prog", "tagged_ctx", NULL, 1 }, + { "attach_nullable_to_nonnull", "ext_mem", "tc_prog", "mem", "mem_nonnull" }, + { "attach_nonnull_to_nullable", "ext_mem_nonnull", "tc_prog", "mem_nonnull", "mem", 2 }, +}; + +static void run_test(struct freplace_args_tgt *tgt_skel, const struct test *t) +{ + struct bpf_program *ext, *tgt; + struct freplace_args *skel; + char log[4096], msg[128]; + struct bpf_link *link; + int err; + + skel = freplace_args__open(); + if (!ASSERT_OK_PTR(skel, "open")) + return; + + ext = bpf_object__find_program_by_name(skel->obj, t->ext); + tgt = bpf_object__find_program_by_name(tgt_skel->obj, t->tgt); + if (!ASSERT_OK_PTR(ext, "ext") || !ASSERT_OK_PTR(tgt, "tgt")) + goto out; + + log[0] = '\0'; + bpf_program__set_autoload(ext, true); + /* libbpf prints the log of a load that fails and must not */ + if (t->bad_reg && !t->func2) + bpf_program__set_log_buf(ext, log, sizeof(log)); + err = bpf_program__set_attach_target(ext, bpf_program__fd(tgt), t->func); + if (!ASSERT_OK(err, "set_attach_target")) + goto out; + + err = freplace_args__load(skel); + if (t->bad_reg && !t->func2) { + snprintf(msg, sizeof(msg), + "Extension program's argument in R%d is incompatible with original", + t->bad_reg); + if (ASSERT_ERR(err, "load")) + ASSERT_HAS_SUBSTR(log, msg, "log"); + goto out; + } + if (!ASSERT_OK(err, "load") || !t->func2) + goto out; + + link = bpf_program__attach_freplace(ext, bpf_program__fd(tgt), t->func2); + ASSERT_EQ(libbpf_get_error(link), t->bad_reg ? -EINVAL : 0, "attach"); + bpf_link__destroy(link); +out: + freplace_args__destroy(skel); +} + +void test_freplace_args(void) +{ + struct freplace_args_tgt *tgt_skel; + int i; + + tgt_skel = freplace_args_tgt__open_and_load(); + if (!ASSERT_OK_PTR(tgt_skel, "tgt_open_and_load")) + return; + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + if (test__start_subtest(tests[i].name)) + run_test(tgt_skel, &tests[i]); + } + + freplace_args_tgt__destroy(tgt_skel); +} \ No newline at end of file diff --git a/tools/testing/selftests/bpf/prog_tests/may_goto_far.c b/tools/testing/selftests/bpf/prog_tests/may_goto_far.c index 8d0ff30bd068cb..b6d262911a3ea3 100644 --- a/tools/testing/selftests/bpf/prog_tests/may_goto_far.c +++ b/tools/testing/selftests/bpf/prog_tests/may_goto_far.c @@ -34,8 +34,10 @@ static struct bpf_insn *fill(struct bpf_insn *insn, int cnt, int reg) * The prog returns 0 when may_goto jumps to its target and 2 when * it lands in one of 'r0 = r8' areas. There are no constants between * may_goto and its target to keep the distance when constants are blinded. + * + * With 'subprog' all of that is a subprog. */ -static void test_far(int off) +static void test_far(int off, bool subprog) { LIBBPF_OPTS(bpf_prog_load_opts, opts, .prog_flags = BPF_F_SLEEPABLE); LIBBPF_OPTS(bpf_test_run_opts, topts); @@ -50,6 +52,10 @@ static void test_far(int off) return; insn = insns; + if (subprog) { + *insn++ = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_CALL, 0, 1); + *insn++ = BPF_EXIT_INSN(); + } *insn++ = BPF_EMIT_CALL(BPF_FUNC_ktime_get_ns); *insn++ = BPF_MOV64_REG(BPF_REG_6, BPF_REG_0); *insn++ = BPF_ALU64_IMM(BPF_RSH, BPF_REG_6, 63); @@ -82,11 +88,19 @@ static void test_far(int off) void test_may_goto_far(void) { if (test__start_subtest("32762")) - test_far(32762); + test_far(32762, false); if (test__start_subtest("32767")) - test_far(32767); + test_far(32767, false); if (test__start_subtest("-32767")) - test_far(-32767); + test_far(-32767, false); if (test__start_subtest("-32768")) - test_far(-32768); + test_far(-32768, false); + if (test__start_subtest("subprog 1")) + test_far(1, true); + if (test__start_subtest("subprog 32767")) + test_far(32767, true); + if (test__start_subtest("subprog -6")) + test_far(-6, true); + if (test__start_subtest("subprog -32768")) + test_far(-32768, true); } diff --git a/tools/testing/selftests/bpf/prog_tests/timed_may_goto.c b/tools/testing/selftests/bpf/prog_tests/timed_may_goto.c new file mode 100644 index 00000000000000..3da3f33a2898b4 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/timed_may_goto.c @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include +#include +#include +#include "timed_may_goto.skel.h" +#include "timed_may_goto_user.skel.h" +#include "timed_may_goto_ext.skel.h" + +#define TRIES 4 + +static int run_tc(struct bpf_program *prog) +{ + LIBBPF_OPTS(bpf_test_run_opts, opts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); + + if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(prog), &opts), "test_run")) + return -1; + return opts.retval; +} + +static int run_syscall(struct bpf_program *prog) +{ + LIBBPF_OPTS(bpf_test_run_opts, opts); + + if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(prog), &opts), "test_run")) + return -1; + return opts.retval; +} + +static void wait_for(int *val, int expected, const char *name) +{ + int i; + + for (i = 0; i < 500 && *(volatile int *)val != expected; i++) + usleep(10000); + ASSERT_EQ(*val, expected, name); +} + +static void test_async(struct timed_may_goto_user *skel) +{ + ASSERT_EQ(run_syscall(skel->progs.async_after_timeout), 0, "async_after_timeout"); + wait_for(&skel->bss->timer_cnt, 1000, "timer_cnt"); + wait_for(&skel->bss->wq_cnt, 1000, "wq_cnt"); + wait_for(&skel->bss->tw_cnt, 1000, "tw_cnt"); + wait_for(&skel->bss->rcu_cnt, 1000, "rcu_cnt"); + wait_for(&skel->bss->rcu_trace_cnt, 1000, "rcu_trace_cnt"); +} + +static void test_timer_on_top(struct timed_may_goto_user *skel) +{ + int ms = run_syscall(skel->progs.spin_under_timer); + int ticks = skel->bss->ticks; + + /* stop the timer */ + skel->bss->ticks = 100; + ASSERT_GE(ms, 200, "ms"); + ASSERT_LE(ms, 500, "ms"); + /* control: the callback interrupted the prog, and its loop went on to the end */ + ASSERT_GE(ticks, 5, "ticks"); + ASSERT_LT(ticks, 100, "ticks"); +} + +static void test_freplace(struct timed_may_goto_user *skel) +{ + struct timed_may_goto_ext *ext; + + ASSERT_EQ(run_tc(skel->progs.freplace_target), 1, "not replaced"); + + ext = timed_may_goto_ext__open(); + if (!ASSERT_OK_PTR(ext, "ext_open")) + return; + bpf_program__set_attach_target(ext->progs.replacement, + bpf_program__fd(skel->progs.freplace_target), + "replaced_global"); + if (!ASSERT_OK(timed_may_goto_ext__load(ext), "ext_load") || + !ASSERT_OK(timed_may_goto_ext__attach(ext), "ext_attach")) + goto out; + ASSERT_EQ(run_tc(skel->progs.freplace_target), TRIES, "replaced"); +out: + timed_may_goto_ext__destroy(ext); + ASSERT_EQ(run_tc(skel->progs.freplace_target), 1, "not replaced"); +} + +/* What a prog leaves behind when its time is up doesn't matter for the next one on the cpu. */ +static void test_tail_call_and_throw(struct timed_may_goto_user *skel) +{ + int key = 0, fd = bpf_program__fd(skel->progs.tail_callee); + int map_fd = bpf_map__fd(skel->maps.jmp_table); + + if (!ASSERT_OK(bpf_map_update_elem(map_fd, &key, &fd, 0), "update")) + return; + + ASSERT_EQ(run_tc(skel->progs.normal_prog), 1, "normal_prog"); + ASSERT_EQ(run_tc(skel->progs.normal_prog), 1, "normal_prog"); + + ASSERT_EQ(run_tc(skel->progs.tail_call_in_subprog), 1, "tail_call_in_subprog"); + ASSERT_EQ(skel->bss->tail_callee_spun, 1, "tail_callee_spun"); + + ASSERT_EQ(run_tc(skel->progs.tail_call_after_timeout), 0, "tail_call_after_timeout"); + ASSERT_EQ(skel->bss->tail_callee_spun, 1, "tail_callee_spun"); + + ASSERT_EQ(run_tc(skel->progs.throw_after_timeout), 7, "throw_after_timeout"); + ASSERT_EQ(run_tc(skel->progs.throw_after_timeout), 7, "throw_after_timeout"); +} + +static void test_user_ringbuf(struct timed_may_goto_user *skel) +{ + struct user_ring_buffer *rb; + void *sample; + int i; + + rb = user_ring_buffer__new(bpf_map__fd(skel->maps.user_ringbuf), NULL); + if (!ASSERT_OK_PTR(rb, "user_ring_buffer__new")) + return; + for (i = 0; i < TRIES; i++) { + sample = user_ring_buffer__reserve(rb, 8); + if (!ASSERT_OK_PTR(sample, "reserve")) + goto out; + user_ring_buffer__submit(rb, sample); + } + /* The helper takes a sample out of the buffer for each call: all calls have to run. */ + ASSERT_EQ(run_syscall(skel->progs.drain), TRIES * 10 + 1, "drain"); +out: + user_ring_buffer__free(rb); +} + +static void test_priv_stack(struct timed_may_goto_user *skel) +{ + LIBBPF_OPTS(bpf_test_run_opts, opts); + int fd = bpf_program__fd(skel->progs.priv_stack); + struct bpf_link *link; + + link = bpf_program__attach(skel->progs.priv_stack); + if (!ASSERT_OK_PTR(link, "attach")) + return; + ASSERT_OK(bpf_prog_test_run_opts(fd, &opts), "test_run"); + ASSERT_EQ(skel->bss->priv_stack_spun, 1, "priv_stack_spun"); + ASSERT_EQ(skel->bss->priv_stack_cb_spun, 0, "priv_stack_cb_spun"); + bpf_link__destroy(link); +} + +/* + * Serial: most progs spin for 250 ms in an RCU read-side critical section, one after the other. + * That delays what other tests wait for. In parallel mode "mmap" gives up its wait for the end of + * a map. + */ +void serial_test_timed_may_goto(void) +{ + struct timed_may_goto_user *skel; + cpu_set_t old, new; + + /* The interpreter counts in each frame. */ + if (!is_jit_enabled()) { + test__skip(); + return; + } + + RUN_TESTS(timed_may_goto); + +#if !defined(__x86_64__) && !defined(__aarch64__) + return; +#endif + skel = timed_may_goto_user__open_and_load(); + if (!ASSERT_OK_PTR(skel, "open_and_load")) + return; + + /* Count and timestamp are per-cpu: all progs of a subtest run on one cpu. */ + if (!ASSERT_OK(sched_getaffinity(0, sizeof(old), &old), "getaffinity")) + goto out; + CPU_ZERO(&new); + CPU_SET(sched_getcpu(), &new); + if (!ASSERT_OK(sched_setaffinity(0, sizeof(new), &new), "setaffinity")) + goto out; + + if (test__start_subtest("async")) + test_async(skel); + if (test__start_subtest("timer_on_top")) + test_timer_on_top(skel); + if (test__start_subtest("freplace")) + test_freplace(skel); + if (test__start_subtest("tail_call_and_throw")) + test_tail_call_and_throw(skel); + if (test__start_subtest("user_ringbuf")) + test_user_ringbuf(skel); + if (test__start_subtest("priv_stack")) + test_priv_stack(skel); + + sched_setaffinity(0, sizeof(old), &old); +out: + timed_may_goto_user__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c index 3ab963458903d0..7a72bb96877965 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c @@ -18,12 +18,15 @@ #define TX_NAME "veTX" #define RX_NAME "veRX" -#define UDP_PAYLOAD_BYTES 4 +#define UDP_PAYLOAD_BYTES 32 + +#define MAX_SKB_FRAGS 17 /* minimum CONFIG_MAX_SKB_FRAGS */ +#define MAX_TX_DESCS (MAX_SKB_FRAGS + 1) #define UDP_SOURCE_PORT 1234 #define AF_XDP_CONSUMER_PORT 8080 -#define UMEM_NUM 16 +#define UMEM_NUM 64 #define UMEM_FRAME_SIZE XSK_UMEM__DEFAULT_FRAME_SIZE #define UMEM_SIZE (UMEM_FRAME_SIZE * UMEM_NUM) #define XDP_FLAGS XDP_FLAGS_DRV_MODE @@ -56,13 +59,13 @@ struct xsk { struct xsk_socket *socket; }; -static int open_xsk(int ifindex, struct xsk *xsk) +static int open_xsk(int ifindex, struct xsk *xsk, __u32 bind_flags) { int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; const struct xsk_socket_config socket_config = { .rx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, .tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, - .bind_flags = XDP_COPY, + .bind_flags = bind_flags, }; const struct xsk_umem_config umem_config = { .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, @@ -133,31 +136,35 @@ static void close_xsk(struct xsk *xsk) munmap(xsk->umem_area, UMEM_SIZE); } -static int generate_packet(struct xsk *xsk, __u16 dst_port) +static int generate_packet(struct xsk *xsk, __u16 dst_port, u32 num) { struct xsk_tx_metadata *meta; struct xdp_desc *tx_desc; struct udphdr *udph; struct ethhdr *eth; struct iphdr *iph; + u16 first_len; + u16 pkt_len; + u8 pkt[256]; + u32 offset; void *data; __u32 idx; + u32 addr; int ret; + u32 i; - ret = xsk_ring_prod__reserve(&xsk->tx, 1, &idx); - if (!ASSERT_EQ(ret, 1, "xsk_ring_prod__reserve")) + pkt_len = sizeof(*eth) + sizeof(*iph) + sizeof(*udph) + UDP_PAYLOAD_BYTES; + first_len = sizeof(*eth) + sizeof(*iph) + sizeof(*udph); + if (!num || num > MAX_TX_DESCS || + (num > 1 && pkt_len - first_len < num - 1)) return -1; - tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx); - tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE + sizeof(struct xsk_tx_metadata); - printf("%p: tx_desc[%u]->addr=%llx\n", xsk, idx, tx_desc->addr); - data = xsk_umem__get_data(xsk->umem_area, tx_desc->addr); - - meta = data - sizeof(struct xsk_tx_metadata); - memset(meta, 0, sizeof(*meta)); - meta->flags = XDP_TXMD_FLAGS_TIMESTAMP; + ret = xsk_ring_prod__reserve(&xsk->tx, num, &idx); + if (!ASSERT_EQ(ret, num, "xsk_ring_prod__reserve")) + return -1; - eth = data; + memset(pkt, 0, sizeof(pkt)); + eth = (void *)pkt; iph = (void *)(eth + 1); udph = (void *)(iph + 1); @@ -180,18 +187,43 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) udph->source = htons(UDP_SOURCE_PORT); udph->dest = htons(dst_port); udph->len = htons(sizeof(*udph) + UDP_PAYLOAD_BYTES); + memset(udph + 1, 0xAA, UDP_PAYLOAD_BYTES); udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, ntohs(udph->len), IPPROTO_UDP, 0); - memset(udph + 1, 0xAA, UDP_PAYLOAD_BYTES); - - meta->flags |= XDP_TXMD_FLAGS_CHECKSUM; - meta->request.csum_start = sizeof(*eth) + sizeof(*iph); - meta->request.csum_offset = offsetof(struct udphdr, check); + for (i = 0, offset = 0; i < num; i++) { + u32 len; + + if (num == 1) + len = pkt_len; + else if (!i) + len = first_len; + else if (i == num - 1) + len = pkt_len - offset; + else + len = (pkt_len - first_len) / (num - 1); + + addr = (idx + i) % (UMEM_NUM / 2) * UMEM_FRAME_SIZE; + tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i); + tx_desc->addr = addr + sizeof(*meta); + tx_desc->len = len; + tx_desc->options = i ? 0 : XDP_TX_METADATA; + if (i + 1 < num) + tx_desc->options |= XDP_PKT_CONTD; + printf("%p: tx_desc[%u]->addr=%llx\n", xsk, idx + i, tx_desc->addr); + data = xsk_umem__get_data(xsk->umem_area, tx_desc->addr); + if (!i) { + meta = data - sizeof(*meta); + memset(meta, 0, sizeof(*meta)); + meta->flags = XDP_TXMD_FLAGS_TIMESTAMP | XDP_TXMD_FLAGS_CHECKSUM; + meta->request.csum_start = sizeof(*eth) + sizeof(*iph); + meta->request.csum_offset = offsetof(struct udphdr, check); + } + memcpy(data, pkt + offset, len); + offset += len; + } - tx_desc->len = sizeof(*eth) + sizeof(*iph) + sizeof(*udph) + UDP_PAYLOAD_BYTES; - tx_desc->options |= XDP_TX_METADATA; - xsk_ring_prod__submit(&xsk->tx, 1); + xsk_ring_prod__submit(&xsk->tx, num); ret = sendto(xsk_socket__fd(xsk->socket), NULL, 0, MSG_DONTWAIT, NULL, 0); if (!ASSERT_GE(ret, 0, "sendto")) @@ -224,24 +256,27 @@ static int generate_packet_inet(void) return err; } -static void complete_tx(struct xsk *xsk) +static void complete_tx(struct xsk *xsk, u32 num) { struct xsk_tx_metadata *meta; __u64 addr; void *data; __u32 idx; - - if (ASSERT_EQ(xsk_ring_cons__peek(&xsk->comp, 1, &idx), 1, "xsk_ring_cons__peek")) { - addr = *xsk_ring_cons__comp_addr(&xsk->comp, idx); - - printf("%p: complete tx idx=%u addr=%llx\n", xsk, idx, addr); - - data = xsk_umem__get_data(xsk->umem_area, addr); - meta = data - sizeof(struct xsk_tx_metadata); - - ASSERT_NEQ(meta->completion.tx_timestamp, 0, "tx_timestamp"); - - xsk_ring_cons__release(&xsk->comp, 1); + __u32 i; + + if (ASSERT_EQ(xsk_ring_cons__peek(&xsk->comp, num, &idx), num, + "xsk_ring_cons__peek")) { + for (i = 0; i < num; i++) { + addr = *xsk_ring_cons__comp_addr(&xsk->comp, idx + i); + printf("%p: complete tx idx=%u addr=%llx\n", xsk, idx + i, addr); + + if (i == 0) { + data = xsk_umem__get_data(xsk->umem_area, addr); + meta = data - sizeof(*meta); + ASSERT_NEQ(meta->completion.tx_timestamp, 0, "tx_timestamp"); + } + } + xsk_ring_cons__release(&xsk->comp, num); } } @@ -325,7 +360,7 @@ static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp) ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type"); /* checksum offload */ - ASSERT_EQ(udph->check, htons(0x721c), "csum"); + ASSERT_EQ(udph->check, htons(0x1c8f), "csum"); done: xsk_ring_cons__release(&xsk->rx, 1); @@ -361,6 +396,7 @@ void test_xdp_metadata(void) int retries = 10; int rx_ifindex; int tx_ifindex; + unsigned int i; int sock_fd; int ret; @@ -398,7 +434,7 @@ void test_xdp_metadata(void) /* Setup separate AF_XDP for RX interface. */ - ret = open_xsk(rx_ifindex, &rx_xsk); + ret = open_xsk(rx_ifindex, &rx_xsk, XDP_COPY); if (!ASSERT_OK(ret, "open_xsk(RX_NAME)")) goto out; @@ -462,27 +498,28 @@ void test_xdp_metadata(void) /* Setup separate AF_XDP for TX interface nad send packet to the RX socket. */ tx_ifindex = if_nametoindex(TX_NAME); - ret = open_xsk(tx_ifindex, &tx_xsk); + ret = open_xsk(tx_ifindex, &tx_xsk, XDP_COPY | XDP_USE_SG); if (!ASSERT_OK(ret, "open_xsk(TX_NAME)")) goto out; - if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT), 0, - "generate AF_XDP_CONSUMER_PORT")) - goto out; + for (i = 1; i <= MAX_TX_DESCS; i++) { + if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT, i), 0, + "generate AF_XDP packet")) + goto out; - switch_ns_to_rx(&tok); - if (!ASSERT_OK_PTR(tok, "setns rx")) - goto out; + switch_ns_to_rx(&tok); + if (!ASSERT_OK_PTR(tok, "setns rx")) + goto out; - /* Verify packet sent from AF_XDP has proper metadata. */ - if (!ASSERT_GE(verify_xsk_metadata(&rx_xsk, true), 0, - "verify_xsk_metadata")) - goto out; + if (!ASSERT_GE(verify_xsk_metadata(&rx_xsk, true), 0, + "verify xsk metadata")) + goto out; - switch_ns_to_tx(&tok); - if (!ASSERT_OK_PTR(tok, "setns tx")) - goto out; - complete_tx(&tx_xsk); + switch_ns_to_tx(&tok); + if (!ASSERT_OK_PTR(tok, "setns tx")) + goto out; + complete_tx(&tx_xsk, i); + } /* Now check metadata of packet, generated with network stack */ if (!ASSERT_GE(generate_packet_inet(), 0, "generate UDP packet")) @@ -518,7 +555,7 @@ void test_xdp_metadata(void) goto out; /* Send packet to trigger . */ - if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT), 0, + if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT, 1), 0, "generate freplace packet")) goto out; diff --git a/tools/testing/selftests/bpf/progs/arena_htab.c b/tools/testing/selftests/bpf/progs/arena_htab.c index 81eaa94afeb01c..80cc14bb1c0f94 100644 --- a/tools/testing/selftests/bpf/progs/arena_htab.c +++ b/tools/testing/selftests/bpf/progs/arena_htab.c @@ -34,8 +34,6 @@ int arena_htab_llvm(void *ctx) cast_kern(htab); htab_init(htab); - cast_kern(arr); - /* first run. No old elems in the table */ for (i = zero; i < 100000 && can_loop; i++) { htab_update_elem(htab, i, i); diff --git a/tools/testing/selftests/bpf/progs/dynptr_fail.c b/tools/testing/selftests/bpf/progs/dynptr_fail.c index c2247b38c84983..3770ffdeaaaae5 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_fail.c +++ b/tools/testing/selftests/bpf/progs/dynptr_fail.c @@ -1277,6 +1277,270 @@ int skb_invalid_data_slice4(struct __sk_buff *skb) return SK_PASS; } +/* + * bpf_dynptr_slice() and bpf_dynptr_slice_rdwr() return the buffer when the data + * is not contiguous. For the verifier an access through the slice is not an access + * to the stack. Thus the buffer must not hold data that the verifier tracks: a + * store to the buffer invalidates the slice. fp-32: the dynptr, r7: the slice. + */ +#define SLICE_BUF_DYNPTR(new) \ + "r2 = 0;" \ + "r3 = r10;" \ + "r3 += -32;" \ + "call %[" #new "];" + +/* r3 is the buffer */ +#define SLICE_BUF_CALL(size) \ + "r1 = r10;" \ + "r1 += -32;" \ + "r2 = 0;" \ + "r4 = " #size ";" \ + "call %[slice];" + +#define SLICE_BUF_CHECK \ + "if r0 == 0 goto 9f;" \ + "r7 = r0;" + +#define SLICE_BUF_AT(off, size) \ + "r3 = r10;" \ + "r3 += -" #off ";" \ + SLICE_BUF_CALL(size) \ + SLICE_BUF_CHECK + +#define SLICE_BUF(off, size) SLICE_BUF_DYNPTR(bpf_dynptr_from_skb) SLICE_BUF_AT(off, size) + +struct file {}; +extern int bpf_dynptr_from_file(struct file *, __u32, struct bpf_dynptr *) __weak __ksym; + +/* clang makes no BTF for a kfunc that only asm calls */ +void __kfunc_btf_root(void) +{ + bpf_dynptr_from_file(0, 0, 0); +} + +/* Each prog ends with a load through the slice */ +#define SLICE_BUF_PROG(sec, kfunc, name, expect, ...) \ +SEC(sec) \ +expect \ +__naked int name(void) \ +{ \ + asm volatile (__VA_ARGS__ \ + "r0 = *(u8 *)(r7 + 0);" \ +"9:" \ + "r0 = 0;" \ + "exit;" \ + : \ + : __imm(bpf_dynptr_from_file), \ + __imm(bpf_dynptr_from_skb), \ + __imm(bpf_dynptr_from_skb_meta), \ + __imm(bpf_dynptr_from_xdp), \ + __imm(bpf_get_prandom_u32), \ + __imm(bpf_probe_read_kernel), \ + __imm_const(slice, kfunc) \ + : __clobber_all); \ +} +#define SLICE_BUF_TEST(...) SLICE_BUF_PROG("?tc", bpf_dynptr_slice_rdwr, __VA_ARGS__) + +/* Not in the line of SLICE_BUF_TEST(): the log of the verifier has a copy of that line */ +#define SLICE_BUF_INVALID __failure __msg("R7 invalid mem access 'scalar'") +#define SLICE_BUF_POINTER __failure __msg("invalid size of register spill") + +SLICE_BUF_TEST(slice_buf_first_byte, SLICE_BUF_INVALID, + SLICE_BUF(12, 4) + "*(u8 *)(r10 - 12) = 0;") + +SLICE_BUF_TEST(slice_buf_last_byte, SLICE_BUF_INVALID, + SLICE_BUF(12, 4) + "*(u8 *)(r10 - 9) = 0;") + +/* the store is at fp-16 or at fp-8 */ +SLICE_BUF_TEST(slice_buf_store_var_off, SLICE_BUF_INVALID, + SLICE_BUF(8, 8) + "call %[bpf_get_prandom_u32];" + "r0 &= 8;" + "r1 = r10;" + "r1 += -16;" + "r1 += r0;" + "*(u64 *)(r1 + 0) = 0;") + +/* the buffer is at fp-16 or at fp-8 */ +SLICE_BUF_TEST(slice_buf_var_off, SLICE_BUF_INVALID, + SLICE_BUF_DYNPTR(bpf_dynptr_from_skb) + "call %[bpf_get_prandom_u32];" + "r0 &= 8;" + "r3 = r10;" + "r3 += -16;" + "r3 += r0;" + SLICE_BUF_CALL(8) + SLICE_BUF_CHECK + "*(u64 *)(r10 - 8) = 0;") + +/* the slice is a pointer when it is stored to its buffer, and invalid after that */ +SLICE_BUF_TEST(slice_buf_narrow_spill, SLICE_BUF_POINTER, + SLICE_BUF(8, 8) + "*(u32 *)(r10 - 8) = r7;") + +/* the write to the buffer is the spill of the slice, not yet checked for NULL */ +SLICE_BUF_TEST(slice_buf_spilled_or_null, SLICE_BUF_INVALID, + SLICE_BUF_DYNPTR(bpf_dynptr_from_skb) + "r3 = r10;" + "r3 += -8;" + SLICE_BUF_CALL(8) + "*(u64 *)(r10 - 8) = r0;" + "r0 = *(u64 *)(r10 - 8);" + SLICE_BUF_CHECK) + +/* a slice that may be the buffer is the buffer of the next slice */ +SLICE_BUF_TEST(slice_buf_is_a_slice, SLICE_BUF_INVALID, + SLICE_BUF(8, 8) + "r3 = r7;" + SLICE_BUF_CALL(8) + SLICE_BUF_CHECK + "*(u64 *)(r10 - 8) = 0;") + +/* The paths differ only in the buffer. The safe one is first, the other must not be pruned. */ +SLICE_BUF_TEST(slice_buf_pruning, SLICE_BUF_INVALID __flag(BPF_F_TEST_STATE_FREQ), + SLICE_BUF_DYNPTR(bpf_dynptr_from_skb) + "call %[bpf_get_prandom_u32];" + "if r0 == 0 goto 1f;" + SLICE_BUF_AT(16, 8) + "goto 2f;" +"1:" + SLICE_BUF_AT(8, 8) +"2:" + "*(u64 *)(r10 - 8) = 0;") + +#define SLICE_BUF_FUNC(name, ...) \ +static __used __naked void name(void) \ +{ \ + asm volatile (__VA_ARGS__ \ + "exit;" \ + : \ + : __imm(bpf_dynptr_slice) \ + : __clobber_all); \ +} + +/* r1 is the dynptr of the caller. The buffer of the read-only slice is gone after the return. */ +SLICE_BUF_FUNC(slice_buf_in_callee, + "r2 = 0;" + "r3 = r10;" + "r3 += -8;" + "r4 = 8;" + "call %[bpf_dynptr_slice];") + +SLICE_BUF_TEST(slice_buf_frame_returned, SLICE_BUF_INVALID, + SLICE_BUF_DYNPTR(bpf_dynptr_from_skb) + "r1 = r10;" + "r1 += -32;" + "call slice_buf_in_callee;" + SLICE_BUF_CHECK) + +/* stores to fp-12 of this frame and to r1, a pointer to the stack of the caller */ +SLICE_BUF_FUNC(slice_buf_stores, + "*(u32 *)(r10 - 12) = 0;" + "*(u32 *)(r1 + 0) = 0;" + "r0 = 0;") + +SLICE_BUF_TEST(slice_buf_written_by_callee, SLICE_BUF_INVALID, + SLICE_BUF(12, 4) + "r1 = r10;" + "r1 += -12;" + "call slice_buf_stores;") + +/* r1 is the dynptr and r2 the buffer, both in the frame of the caller */ +SLICE_BUF_FUNC(slice_buf_of_caller, + "r3 = r2;" + "r2 = 0;" + "r4 = 4;" + "call %[bpf_dynptr_slice];") + +/* stores next to the buffer or to another frame, a return, calls that fill the buffer */ +SLICE_BUF_TEST(slice_buf_stays_valid, __success, + SLICE_BUF(12, 4) + "r8 = r7;" + "*(u8 *)(r10 - 13) = 0;" + "*(u8 *)(r10 - 8) = 0;" + "r1 = r10;" + "r1 += -16;" + "call slice_buf_stores;" + "r1 = r10;" + "r1 += -12;" + "r2 = 4;" + "r3 = 0;" + "call %[bpf_probe_read_kernel];" + "r1 = r10;" + "r1 += -32;" + "r2 = r10;" + "r2 += -12;" + "call slice_buf_of_caller;" + SLICE_BUF_CHECK + "*(u8 *)(r8 + 0) = 0;") + +/* the slice of a file dynptr is read-only, and it is always the buffer */ +SLICE_BUF_PROG("?lsm.s/file_open", bpf_dynptr_slice, slice_buf_file, SLICE_BUF_INVALID, + "r1 = *(u64 *)(r1 + 0);" + SLICE_BUF_DYNPTR(bpf_dynptr_from_file) + SLICE_BUF_AT(8, 8) + "*(u64 *)(r10 - 8) = 0;") + +SLICE_BUF_PROG("?xdp", bpf_dynptr_slice_rdwr, slice_buf_xdp, SLICE_BUF_INVALID, + SLICE_BUF_DYNPTR(bpf_dynptr_from_xdp) + SLICE_BUF_AT(8, 8) + "*(u64 *)(r10 - 8) = 0;") + +/* the metadata is contiguous: the slice is never the buffer */ +SLICE_BUF_TEST(slice_buf_skb_meta, __success, + SLICE_BUF_DYNPTR(bpf_dynptr_from_skb_meta) + SLICE_BUF_AT(8, 8) + "*(u64 *)(r10 - 8) = 0;") + +extern void bpf_local_irq_save(unsigned long *) __weak __ksym; + +/* a dynptr, an iterator or irq flags are made in the buffer */ +#define SLICE_BUF_SPECIAL(name, type, make) \ +SEC("?tc") \ +__failure __msg("invalid mem access 'scalar'") \ +int name(struct __sk_buff *skb) \ +{ \ + struct bpf_dynptr ptr; \ + type buf; \ + __u8 *p; \ + \ + bpf_dynptr_from_skb(skb, 0, &ptr); \ + p = bpf_dynptr_slice_rdwr(&ptr, 0, &buf, sizeof(buf)); \ + if (!p) \ + return 0; \ + make; \ + return *p; \ +} + +SLICE_BUF_SPECIAL(slice_buf_dynptr, struct bpf_dynptr, bpf_dynptr_from_skb(skb, 0, &buf)) +SLICE_BUF_SPECIAL(slice_buf_iter, struct bpf_iter_num, bpf_iter_num_new(&buf, 0, 1)) +SLICE_BUF_SPECIAL(slice_buf_irq_flag, unsigned long, bpf_local_irq_save(&buf)) + +/* The type of a dynptr argument of a global function is not known: the slice may be the buffer. */ +__noinline int slice_buf_global(struct bpf_dynptr *ptr) +{ + __u64 buf; + __u8 *p; + + p = bpf_dynptr_slice_rdwr(ptr, 0, &buf, sizeof(buf)); + if (!p) + return 0; + *(volatile __u64 *)&buf = 0; + return *p; +} + +SEC("?tc") +__failure __msg("invalid mem access 'scalar'") +int slice_buf_dynptr_arg(struct __sk_buff *skb) +{ + struct bpf_dynptr ptr; + + bpf_dynptr_from_skb(skb, 0, &ptr); + return slice_buf_global(&ptr); +} + /* Read-only skb data slice is invalidated on write to skb metadata */ SEC("?tc") __failure __msg("invalid mem access 'scalar'") diff --git a/tools/testing/selftests/bpf/progs/dynptr_success.c b/tools/testing/selftests/bpf/progs/dynptr_success.c index b668ebd61fc793..7949dd538569fb 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_success.c +++ b/tools/testing/selftests/bpf/progs/dynptr_success.c @@ -231,6 +231,40 @@ int test_dynptr_skb_slice_non_linear(struct __sk_buff *skb) return 1; } +/* + * The tcp header is not in the linear part: the slice is the buffer, and a store + * through the slice is seen in the buffer. As in the documentation, the stores + * come before the compare with the buffer: after it a compiler may use one + * pointer in place of the other. + */ +SEC("?tc") +int test_dynptr_skb_slice_rdwr_buffer(struct __sk_buff *skb) +{ + struct tcphdr buffer = {}, *tcp; + struct bpf_dynptr ptr; + + bpf_dynptr_from_skb(skb, 0, &ptr); + tcp = bpf_dynptr_slice_rdwr(&ptr, TEST_SKB_LINEAR_SIZE, &buffer, sizeof(buffer)); + if (!tcp) { + err = 1; + return 1; + } + + tcp->source = 0x1234; + if (buffer.source != 0x1234) { + err = 2; + return 1; + } + /* a read of the buffer does not invalidate the slice */ + tcp->dest = 0x5678; + if (tcp != &buffer) + err = 3; + else if (bpf_dynptr_write(&ptr, TEST_SKB_LINEAR_SIZE, &buffer, sizeof(buffer), 0)) + err = 4; + + return 1; +} + SEC("?tc") int test_dynptr_skb_meta_data(struct __sk_buff *skb) { @@ -759,6 +793,96 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp) return XDP_DROP; } +static __always_inline int fill_xdp(struct bpf_dynptr *ptr, __u32 start, __u32 n) +{ + __u8 b; + int i; + + bpf_for(i, 0, n) { + b = (start + i) % 251; + if (bpf_dynptr_write(ptr, start + i, &b, 1, 0)) + return 1; + } + return 0; +} + +static __always_inline int check_xdp(struct bpf_dynptr *ptr, __u32 at, __u32 n, __u32 from) +{ + __u8 b; + int i; + + bpf_for(i, 0, n) { + if (bpf_dynptr_read(&b, 1, ptr, at + i, 0)) + return 1; + if (b != (__u8)((from + i) % 251)) + return 1; + } + return 0; +} + +SEC("?xdp") +int test_dynptr_copy_xdp_overlap(struct xdp_md *xdp) +{ + void *data_end = (void *)(long)xdp->data_end; + void *data = (void *)(long)xdp->data; + __u32 off = data_end - data - 1000; + struct bpf_dynptr ptr; + + bpf_dynptr_from_xdp(xdp, 0, &ptr); + if (fill_xdp(&ptr, off, 1300)) { + err = 1; + return XDP_DROP; + } + err = bpf_dynptr_copy(&ptr, off + 100, &ptr, off, 1200); + if (err) + return XDP_DROP; + if (check_xdp(&ptr, off + 100, 1200, off)) + err = 2; + return XDP_DROP; +} + +SEC("?xdp") +int test_dynptr_copy_xdp_overlap_src_linear(struct xdp_md *xdp) +{ + void *data_end = (void *)(long)xdp->data_end; + void *data = (void *)(long)xdp->data; + __u32 lin = data_end - data; + struct bpf_dynptr ptr; + + bpf_dynptr_from_xdp(xdp, 0, &ptr); + if (fill_xdp(&ptr, lin - 64, 118)) { + err = 1; + return XDP_DROP; + } + err = bpf_dynptr_copy(&ptr, lin - 10, &ptr, lin - 64, 64); + if (err) + return XDP_DROP; + if (check_xdp(&ptr, lin - 10, 64, lin - 64)) + err = 2; + return XDP_DROP; +} + +SEC("?xdp") +int test_dynptr_copy_xdp_overlap_dst_frag(struct xdp_md *xdp) +{ + void *data_end = (void *)(long)xdp->data_end; + void *data = (void *)(long)xdp->data; + __u32 lin = data_end - data; + struct bpf_dynptr ptr; + + bpf_dynptr_from_xdp(xdp, 0, &ptr); + if (fill_xdp(&ptr, lin - 10, 84)) { + err = 1; + return XDP_DROP; + } + err = bpf_dynptr_copy(&ptr, lin + 10, &ptr, lin - 10, 64); + if (err) + return XDP_DROP; + if (check_xdp(&ptr, lin + 10, 64, lin - 10)) + err = 2; + return XDP_DROP; +} + char memset_zero_data[] = "data to be zeroed"; SEC("?tp/syscalls/sys_enter_nanosleep") diff --git a/tools/testing/selftests/bpf/progs/fentry_kprobe_shared.c b/tools/testing/selftests/bpf/progs/fentry_kprobe_shared.c new file mode 100644 index 00000000000000..3d16773aada897 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/fentry_kprobe_shared.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" +#include +#include + +char _license[] SEC("license") = "GPL"; + +int pid; +int fentry1_hits; +int fentry2_hits; +int fexit_hits; +int kprobe_hits; + +static bool from_test(int a) +{ + return (bpf_get_current_pid_tgid() >> 32) == pid && a == 1; +} + +SEC("fentry/bpf_fentry_test1") +int BPF_PROG(fentry1, int a) +{ + if (from_test(a)) + fentry1_hits++; + return 0; +} + +SEC("fentry/bpf_fentry_test1") +int BPF_PROG(fentry2, int a) +{ + if (from_test(a)) + fentry2_hits++; + return 0; +} + +SEC("fexit/bpf_fentry_test1") +int BPF_PROG(fexit1, int a, int ret) +{ + if (from_test(a) && ret == 2) + fexit_hits++; + return 0; +} + +SEC("kprobe/bpf_fentry_test1") +int BPF_KPROBE(kprobe1, int a) +{ + if (from_test(a)) + kprobe_hits++; + return 0; +} diff --git a/tools/testing/selftests/bpf/progs/freplace_args.c b/tools/testing/selftests/bpf/progs/freplace_args.c new file mode 100644 index 00000000000000..6e8f16bd5d8e0f --- /dev/null +++ b/tools/testing/selftests/bpf/progs/freplace_args.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +/* In freplace_args_tgt.c each of them has 16 bytes. */ +struct buf { __u64 v[2]; }; +struct larger { __u64 v[4]; }; +struct smaller { __u64 v[1]; }; +struct tp_ctx { __u64 v[2]; }; + +SEC("?freplace") +int ext_mem(int a, struct buf *p) +{ + return 0; +} + +SEC("?freplace") +int ext_mem_nonnull(int a, struct buf *p __arg_nonnull) +{ + return 0; +} + +SEC("?freplace") +int ext_mem_larger(struct larger *p) +{ + return 0; +} + +SEC("?freplace") +int ext_mem_smaller(struct smaller *p) +{ + return 0; +} + +SEC("?freplace") +int ext_task_trusted(struct task_struct *t __arg_trusted) +{ + return 0; +} + +SEC("?freplace") +int ext_skb_ctx(struct __sk_buff *skb __arg_ctx) +{ + return 0; +} + +SEC("?freplace") +int ext_tp_mem(struct tp_ctx *p) +{ + return 0; +} + +char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/progs/freplace_args_tgt.c b/tools/testing/selftests/bpf/progs/freplace_args_tgt.c new file mode 100644 index 00000000000000..4f1d1d3d289163 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/freplace_args_tgt.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +/* In freplace_args.c 'larger' has 32 bytes and 'smaller' has 8 bytes. */ +struct buf { __u64 v[2]; }; +struct larger { __u64 v[2]; }; +struct smaller { __u64 v[2]; }; +struct tp_ctx { __u64 v[2]; }; + +__weak int mem(int a, struct buf *p) +{ + return 0; +} + +__weak int mem_nonnull(int a, struct buf *p __arg_nonnull) +{ + return 0; +} + +__weak int mem_larger(struct larger *p) +{ + return 0; +} + +__weak int mem_smaller(struct smaller *p) +{ + return 0; +} + +/* No tag: memory of the size of the struct. */ +__weak int task_mem(struct task_struct *t) +{ + return 0; +} + +__weak int task_trusted(struct task_struct *t __arg_trusted) +{ + return 0; +} + +__weak int skb_ctx(struct __sk_buff *skb) +{ + return 0; +} + +SEC("tc") +int tc_prog(struct __sk_buff *skb) +{ + struct smaller smaller = {}; + struct larger larger = {}; + struct buf buf = {}; + + return mem(0, &buf) + mem_nonnull(0, &buf) + mem_larger(&larger) + mem_smaller(&smaller) + + task_mem(NULL) + task_trusted(bpf_get_current_task_btf()) + skb_ctx(skb); +} + +/* In a tracepoint prog the tag makes a context of any struct. */ +__weak int tagged_ctx(struct tp_ctx *ctx __arg_ctx) +{ + return 0; +} + +SEC("tracepoint") +int tp_prog(void *ctx) +{ + return tagged_ctx(ctx); +} + +char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/progs/timed_may_goto.c b/tools/testing/selftests/bpf/progs/timed_may_goto.c new file mode 100644 index 00000000000000..c1c48af808a99c --- /dev/null +++ b/tools/testing/selftests/bpf/progs/timed_may_goto.c @@ -0,0 +1,898 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * There is one time slice of may_goto for an invocation of a prog: one call from the kernel into + * the main prog, with the subprogs and sync callbacks that it reaches. + * + * Most tests call a function that spins until may_goto stops it, four times, each in a different + * way. Only the first call can spin. With a time slice for each call all four do. + */ +#include +#include +#include +#include "bpf_misc.h" +#include "bpf_experimental.h" + +char _license[] SEC("license") = "GPL"; + +#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && __clang_major__ >= 18 + +#define TRIES 4 + +int zero; + +/* Return 1 if the loop went on until the time was up. */ +static __always_inline int spin(void) +{ + __u64 t0 = bpf_ktime_get_ns(); + + while (can_loop) + ; + return bpf_ktime_get_ns() - t0 > 100 * 1000 * 1000; +} + +static __noinline int spins(void) +{ + return spin(); +} + +static __noinline int counts_to_1000(void) +{ + int i, cnt = zero; + + for (i = zero; i < 1000 && can_loop; i++) + cnt++; + return cnt; +} + +SEC("tc") +__description("timed may_goto: call") +__success __retval(1) +int call_subprog(void *ctx) +{ + int i, n = 0; + + for (i = 0; i < TRIES; i++) + n += spins(); + return n; +} + +SEC("tc") +__description("timed may_goto: a call after the time is up makes no iteration") +__success __retval(0) +int short_loop_after_timeout(void *ctx) +{ + spins(); + return counts_to_1000(); +} + +SEC("tc") +__description("timed may_goto: the loop of the main prog stops when the time is up in a subprog") +__success __retval(1) +int main_loop_after_timeout(void *ctx) +{ + int n = 0; + + while (can_loop && n < 2 * TRIES) + n += spins(); + return n; +} + +static __noinline int passes(int i) +{ + return spins() + i; +} + +SEC("tc") +__description("timed may_goto: call through a function without a loop") +__success __retval(1) +int call_through(void *ctx) +{ + int i, n = 0; + + for (i = 0; i < TRIES; i++) + n += passes(zero); + return n; +} + +__noinline int global_spins(void) +{ + return spin(); +} + +SEC("tc") +__description("timed may_goto: call of a global function") +__success __retval(1) +int call_global(void *ctx) +{ + int i, n = 0; + + for (i = 0; i < TRIES; i++) + n += global_spins(); + return n; +} + +SEC("tc") +__description("timed may_goto: callx") +__success __retval(1) +__naked void callx_subprog(void) +{ + asm volatile ( + "r6 = 0;" + "r7 = 0;" + "1:" + "r3 = %[spins] ll;" + "callx r3;" + "r6 += r0;" + "r7 += 1;" + "if r7 < 4 goto 1b;" + "r0 = r6;" + "exit;" + : + : __imm_addr(spins) + : __clobber_all); +} + +/* With a time slice for each call it gives up, so that the test fails and doesn't lock up. */ +static int loop_cb(__u64 i, int *spun) +{ + *spun += spin(); + return *spun > 2 * TRIES; +} + +SEC("tc") +__description("timed may_goto: bpf_loop() inlined") +__success __retval(1) +int loop_inlined(void *ctx) +{ + int spun = 0; + + bpf_loop(1 << 20, loop_cb, &spun, 0); + return spun; +} + +SEC("tc") +__description("timed may_goto: bpf_loop() not inlined") +__success __retval(1) +int loop_not_inlined(void *ctx) +{ + int spun = 0; + + bpf_loop(1 << 20, loop_cb, &spun, zero); + return spun; +} + +static int count_cb(__u64 i, int *calls) +{ + (*calls)++; + return 0; +} + +/* The time is up: the helper calls the callback one more time. It returns 1 in its first insns. */ +#define LOOP_ENDS(name, flags) \ +SEC("tc") \ +__description("timed may_goto: bpf_loop() " #name " ends when the time is up") \ +__success __retval(10) \ +int loop_ends_##name(void *ctx) \ +{ \ + int calls = 0; \ + \ + spins(); \ + return bpf_loop(1000, count_cb, &calls, flags) * 10 + calls; \ +} + +LOOP_ENDS(inlined, 0) +LOOP_ENDS(not_inlined, zero) + +struct nested { + __u64 t0; + int spun; +}; + +/* Without an end of bpf_loop(): give up, so that the test fails and doesn't lock up. */ +static int inner_cb(__u64 i, struct nested *n) +{ + if (!n->spun) + n->spun = spin(); + return (i & 1023) == 0 && bpf_ktime_get_ns() - n->t0 > 1000 * 1000 * 1000; +} + +static int outer_cb(__u64 i, struct nested *n) +{ + bpf_loop(1 << 23, inner_cb, n, 0); + return bpf_ktime_get_ns() - n->t0 > 1000 * 1000 * 1000; +} + +SEC("tc") +__description("timed may_goto: bpf_loop() in bpf_loop() ends when the time is up") +__success __retval(1) +int loop_in_loop(void *ctx) +{ + struct nested n = { .t0 = bpf_ktime_get_ns() }; + + bpf_loop(1 << 23, outer_cb, &n, 0); + return n.spun && bpf_ktime_get_ns() - n.t0 < 500 * 1000 * 1000; +} + +static __noinline int called_cb(__u64 i, int *calls) +{ + (*calls)++; + return 0; +} + +/* BPF code calls the callback too, so its return value has to be its own. bpf_loop() goes on. */ +SEC("tc") +__description("timed may_goto: bpf_loop() with a callback that is called as well") +__success __retval(45) +int loop_and_call(void *ctx) +{ + int calls = 0; + + spins(); + if (called_cb(zero, &calls)) + return 100; + return bpf_loop(TRIES, called_cb, &calls, 0) * 10 + calls; +} + +static int short_cb(__u64 i, __u64 *t0) +{ + int j; + + for (j = zero; j < 60000 && can_loop; j++) + ; + return (i & 1023) == 0 && bpf_ktime_get_ns() - *t0 > 1000 * 1000 * 1000; +} + +/* + * The main prog has no may_goto. Each call of the callback ends before it reads the clock. The + * iterations of all calls add up. + */ +SEC("tc") +__description("timed may_goto: bpf_loop() the callback makes 60000 iterations") +__success __retval(1) +int loop_short_cb(void *ctx) +{ + __u64 t0 = bpf_ktime_get_ns(); + + bpf_loop(1 << 20, short_cb, &t0, 0); + return bpf_ktime_get_ns() - t0 < 1000 * 1000 * 1000; +} + +/* spins() uses up the time. The loop that calls it ends at its next may_goto. */ +static __noinline int loops_around_spins(void) +{ + int n = zero; + + while (can_loop && n < 20000) { + if (n < 2 * TRIES) + spins(); + n++; + } + return n; +} + +SEC("tc") +__description("timed may_goto: a loop that is on the stack ends when the time is up") +__success __retval(1) +int rest_of_batch(void *ctx) +{ + return loops_around_spins(); +} + +static __noinline int one_iteration(void) +{ + int i, n = zero; + + for (i = zero; i < 1 && can_loop; i++) + n++; + return n; +} + +long calls_ok; + +static int call_one(__u64 i, __u64 *t0) +{ + if (!one_iteration()) + return 1; + calls_ok++; + /* With a time slice for each call: give up. */ + return (i & 1023) == 0 && bpf_ktime_get_ns() - *t0 > 1000 * 1000 * 1000; +} + +static int call_many(__u64 i, __u64 *t0) +{ + long before = calls_ok; + + bpf_loop(1 << 23, call_one, t0, 0); + return calls_ok - before != 1 << 23; +} + +/* + * The iterations of all calls count: the prog reads the clock in each 65535th call. The call that + * finds out that the time is up makes its iteration. + */ +SEC("tc") +__description("timed may_goto: 65535 calls that make one iteration read the clock") +__success __retval(1) +int clock_after_65535_calls(void *ctx) +{ + __u64 t0 = bpf_ktime_get_ns(); + + calls_ok = 0; + bpf_loop(1000, call_many, &t0, 0); + return calls_ok > 0 && calls_ok % 65535 == 0; +} + +#define MAP(name, map_type, flags) \ +struct { \ + __uint(type, map_type); \ + __uint(max_entries, TRIES); \ + __uint(map_flags, flags); \ + __type(key, int); \ + __type(value, int); \ +} name SEC(".maps") + +MAP(array, BPF_MAP_TYPE_ARRAY, 0); +MAP(hash, BPF_MAP_TYPE_HASH, 0); + +/* The first call uses up the time. The second call ends the loop of the helper. */ +static int elem_cb(void *map, int *key, int *val, int *spun) +{ + *spun += spin(); + return 0; +} + +#define FOR_EACH(name) \ +SEC("tc") \ +__description("timed may_goto: bpf_for_each_map_elem() " #name) \ +__success __retval(21) \ +int for_each_##name(void *ctx) \ +{ \ + int i, key, spun = 0; \ + \ + for (i = 0; i < TRIES; i++) { \ + key = i; \ + bpf_map_update_elem(&name, &key, &key, 0); \ + } \ + return bpf_for_each_map_elem(&name, elem_cb, &spun, 0) * 10 + spun; \ +} + +FOR_EACH(array) +FOR_EACH(hash) + +static long vma_cb(struct task_struct *task, struct vm_area_struct *vma, int *spun) +{ + *spun += spin(); + return 0; +} + +SEC("raw_tp") +__description("timed may_goto: bpf_find_vma()") +__success __retval(1) +int find_vma(void *ctx) +{ + struct task_struct *task = bpf_get_current_task_btf(); + __u64 addr = task->mm->arg_start; + int i, spun = 0; + + for (i = 0; i < TRIES; i++) + if (bpf_find_vma(task, addr, vma_cb, &spun, 0)) + return 100; + return spun; +} + +struct tree_node { + struct bpf_rb_node rb; + int key; +}; + +#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8))) +private(A) struct bpf_spin_lock lock; +private(A) struct bpf_rb_root root __contains(tree_node, rb); + +int less_spun, less_calls; + +static bool less(struct bpf_rb_node *a, const struct bpf_rb_node *b) +{ + long n = zero; + + /* no helpers under the lock */ + while (can_loop) + n++; + less_calls++; + less_spun += n > 1000 * 1000; + return container_of(a, struct tree_node, rb)->key < + container_of(b, struct tree_node, rb)->key; +} + +SEC("tc") +__description("timed may_goto: bpf_rbtree_add()") +__success __retval(1) +int rbtree_add(void *ctx) +{ + struct bpf_rb_node *rb; + struct tree_node *n; + int i; + + less_spun = less_calls = 0; + for (i = 0; i < TRIES; i++) { + n = bpf_obj_new(typeof(*n)); + if (!n) + return 100; + n->key = TRIES - i; + bpf_spin_lock(&lock); + bpf_rbtree_add(&root, &n->rb, less); + bpf_spin_unlock(&lock); + } + for (i = 0; i < TRIES; i++) { + bpf_spin_lock(&lock); + rb = bpf_rbtree_first(&root); + if (rb) + rb = bpf_rbtree_remove(&root, rb); + bpf_spin_unlock(&lock); + if (!rb) + return 101; + bpf_obj_drop(container_of(rb, struct tree_node, rb)); + } + if (less_calls < TRIES - 1) + return 102; + return less_spun; +} + +/* + * All registers are live at the may_goto, so it saves one of them in the stack. They are the same + * after 70000 iterations: the loop reads the clock. + */ +__naked __noinline __used +static long regs_across_may_goto(void) +{ + asm volatile ( + "r0 = 10;" + "r6 = 6;" + "r7 = 7;" + "r8 = 8;" + "r9 = 0;" + "1:" + "may_goto 2f;" + "r9 += 1;" + "if r9 < 70000 goto 1b;" + "2:" + "r0 += r1;" + "r0 += r2;" + "r0 += r3;" + "r0 += r4;" + "r0 += r5;" + "r0 += r6;" + "r0 += r7;" + "r0 += r8;" + "r0 += r9;" + "exit;" + ::: __clobber_all); +} + +SEC("tc") +__description("timed may_goto: registers across may_goto") +__success __retval(70046) +__naked void regs_across_may_goto_main(void) +{ + asm volatile ( + "r1 = 1;" + "r2 = 2;" + "r3 = 3;" + "r4 = 4;" + "r5 = 5;" + "call regs_across_may_goto;" + "exit;" + ::: __clobber_all); +} + +/* + * may_goto uses a register that is dead. In live_r0_rN() R0 - RN are live at the may_goto and the + * next one is not. The values come from memory, so the verifier doesn't know them. Return their sum + * and the number of iterations. + */ +__u64 vals[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; +__u64 zero64; + +#define LD0(b) "r0 = *(u64 *)(r" #b " + 0);" +#define LD1(b) LD0(b) "r1 = *(u64 *)(r" #b " + 8);" +#define LD2(b) LD1(b) "r2 = *(u64 *)(r" #b " + 16);" +#define LD3(b) LD2(b) "r3 = *(u64 *)(r" #b " + 24);" +#define LD4(b) LD3(b) "r4 = *(u64 *)(r" #b " + 32);" +#define LD5(b) LD4(b) "r5 = *(u64 *)(r" #b " + 40);" +#define LD6(b) LD5(b) "r6 = *(u64 *)(r" #b " + 48);" +#define LD7(b) LD6(b) "r7 = *(u64 *)(r" #b " + 56);" +#define LD8(b) LD7(b) "r8 = *(u64 *)(r" #b " + 64);" + +#define SUM0 +#define SUM1 SUM0 "r0 += r1;" +#define SUM2 SUM1 "r0 += r2;" +#define SUM3 SUM2 "r0 += r3;" +#define SUM4 SUM3 "r0 += r4;" +#define SUM5 SUM4 "r0 += r5;" +#define SUM6 SUM5 "r0 += r6;" +#define SUM7 SUM6 "r0 += r7;" +#define SUM8 SUM7 "r0 += r8;" + +/* The count of iterations is at r10 - 8. It begins with a number from memory too. */ +#define COUNT_INIT(t) \ + "r" #t " = %[zero64] ll;" \ + "r" #t " = *(u64 *)(r" #t " + 0);" \ + "*(u64 *)(r10 - 8) = r" #t ";" +#define COUNT_AND_LOOP(t) \ + "r" #t " = *(u64 *)(r10 - 8);" \ + "r" #t " += 1;" \ + "*(u64 *)(r10 - 8) = r" #t ";" \ + "if r" #t " < 70000 goto 1b;" +#define ADD_COUNT_AND_EXIT \ + "r1 = *(u64 *)(r10 - 8);" \ + "r0 += r1;" \ + "exit;" \ + : \ + : __imm_addr(vals), __imm_addr(zero64) \ + : __clobber_all + +#define LIVE_REGS(n, next) \ +__naked __noinline __used \ +static long live_r0_r##n(void) \ +{ \ + asm volatile ( \ + COUNT_INIT(next) \ + "r" #n " = %[vals] ll;" \ + LD##n(n) \ + "1:" \ + "may_goto 2f;" \ + COUNT_AND_LOOP(next) \ + "2:" \ + SUM##n \ + ADD_COUNT_AND_EXIT); \ +} + +LIVE_REGS(0, 1) +LIVE_REGS(1, 2) +LIVE_REGS(2, 3) +LIVE_REGS(3, 4) +LIVE_REGS(4, 5) +LIVE_REGS(5, 6) +LIVE_REGS(6, 7) +LIVE_REGS(7, 8) +LIVE_REGS(8, 9) + +/* R2 is read at the top of the loop only: it is live at the may_goto through the back edge. */ +__naked __noinline __used +static long live_back_edge(void) +{ + asm volatile ( + COUNT_INIT(3) + "r2 = %[vals] ll;" + LD2(2) + "1:" + "*(u64 *)(r10 - 16) = r2;" + "may_goto 2f;" + COUNT_AND_LOOP(3) + "2:" + "r0 += r1;" + "r2 = *(u64 *)(r10 - 16);" + "r0 += r2;" + ADD_COUNT_AND_EXIT); +} + +/* R2 is read only where the may_goto jumps to. */ +__naked __noinline __used +static long live_target(void) +{ + asm volatile ( + COUNT_INIT(3) + "r2 = %[vals] ll;" + LD2(2) + "1:" + "may_goto 2f;" + COUNT_AND_LOOP(3) + "goto 3f;" + "2:" + "r0 += r2;" + "3:" + "r0 += r1;" + ADD_COUNT_AND_EXIT); +} + +/* R2 is set in front of the may_goto in each iteration, and read only right behind it. */ +__naked __noinline __used +static long live_fall_through(void) +{ + asm volatile ( + COUNT_INIT(3) + "r1 = %[vals] ll;" + LD1(1) + "*(u64 *)(r10 - 16) = r0;" + "1:" + "r2 = %[vals] ll;" + "r2 = *(u64 *)(r2 + 16);" + "may_goto 2f;" + "*(u64 *)(r10 - 16) = r2;" + COUNT_AND_LOOP(3) + "2:" + "r0 += r1;" + "r2 = *(u64 *)(r10 - 16);" + "r0 += r2;" + ADD_COUNT_AND_EXIT); +} + +#define CALL_AND_ADD(f) "call " #f ";" "r6 += r0;" +#define CALL_ALL_LIVE \ + "r6 = 0;" \ + CALL_AND_ADD(live_r0_r0) \ + CALL_AND_ADD(live_r0_r1) \ + CALL_AND_ADD(live_r0_r2) \ + CALL_AND_ADD(live_r0_r3) \ + CALL_AND_ADD(live_r0_r4) \ + CALL_AND_ADD(live_r0_r5) \ + CALL_AND_ADD(live_r0_r6) \ + CALL_AND_ADD(live_r0_r7) \ + CALL_AND_ADD(live_r0_r8) \ + CALL_AND_ADD(live_back_edge) \ + CALL_AND_ADD(live_target) \ + CALL_AND_ADD(live_fall_through) \ + "r0 = r6;" \ + "exit;" + +/* + * The sums: 1 + 3 + 6 + 10 + 15 + 21 + 28 + 36 + 45 = 165. Then 6, 3 (the may_goto doesn't jump) + * and 6. 12 * 70000 iterations: each function reads the clock. + */ +SEC("tc") +__description("timed may_goto: may_goto takes a register that is dead") +__success __retval(840180) +__naked void dead_reg(void) +{ + asm volatile ( + CALL_ALL_LIVE + ::: __clobber_all); +} + +/* No iteration: 165, then 6, 6 (the may_goto jumps) and 4 (R2 isn't stored). */ +SEC("tc") +__description("timed may_goto: may_goto takes a register that is dead, the time is up") +__success __retval(181) +__naked void dead_reg_time_is_up(void) +{ + asm volatile ( + "call spins_on_may_goto;" + CALL_ALL_LIVE + ::: __clobber_all); +} + +/* + * The subprog uses up the time of the prog and returns. With a time slice for each call the caller + * calls it 65535 times before it reads the clock. + */ +__naked __noinline __used +static unsigned long spins_on_may_goto(void) +{ + asm volatile ( + "1:" + "may_goto 2f;" + "goto 1b;" + "2:" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + +/* The first may_goto of the function finds that the time is up */ +SEC("tc") +__description("timed may_goto: registers across may_goto when the time is up") +__success __retval(46) +__naked void regs_when_time_is_up(void) +{ + asm volatile ( + "call spins_on_may_goto;" + "r1 = 1;" + "r2 = 2;" + "r3 = 3;" + "r4 = 4;" + "r5 = 5;" + "call regs_across_may_goto;" + "exit;" + ::: __clobber_all); +} + +/* The first insn of the main prog is the target of a jump. It must not set the count again. */ +SEC("socket") +__description("timed may_goto: 9 insns") +__success __retval(1) +__naked void loop_calls_subprog_with_may_goto(void) +{ + asm volatile ( + "1:" + "call spins_on_may_goto;" + "may_goto 2f;" + "goto 1b;" + "2:" + "r0 = 1;" + "exit;" + ::: __clobber_all); +} + +/* + * These subprogs make 60000 iterations in each call. With a read of the clock after 65535 + * iterations of a call none of them reads it, and their caller does it after + * 65535 * 60000 * 60000 iterations. + */ +__naked __noinline __used +static unsigned long loops_60000(void) +{ + asm volatile ( + "r1 = 60000;" + "1:" + "may_goto 2f;" + "r1 += -1;" + "if r1 != 0 goto 1b;" + "2:" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + +__naked __noinline __used +static unsigned long calls_60000_times(void) +{ + asm volatile ( + "r6 = 60000;" + "1:" + "call loops_60000;" + "may_goto 2f;" + "r6 += -1;" + "if r6 != 0 goto 1b;" + "2:" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + +SEC("socket") +__description("timed may_goto: three levels of loops that end before they read the clock") +__success __retval(1) +__naked void three_levels_of_short_loops(void) +{ + asm volatile ( + "1:" + "call calls_60000_times;" + "may_goto 2f;" + "goto 1b;" + "2:" + "r0 = 1;" + "exit;" + ::: __clobber_all); +} + +/* The callee ends one iteration before it reads the clock. */ +__naked __noinline __used +static unsigned long loops_65534(void) +{ + asm volatile ( + "r1 = 65534;" + "1:" + "may_goto 2f;" + "r1 += -1;" + "if r1 != 0 goto 1b;" + "2:" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + +SEC("socket") +__description("timed may_goto: the subprog makes 65534 iterations") +__success __retval(1) +__naked void loop_calls_subprog_with_65534_iterations(void) +{ + asm volatile ( + "call %[bpf_ktime_get_ns];" + "r6 = r0;" + "1:" + "call loops_65534;" + "may_goto 2f;" + "goto 1b;" + "2:" + "call %[bpf_ktime_get_ns];" + "r0 -= r6;" + "r1 = r0;" + "r0 = 1;" + "if r1 < 1000000000 goto +1;" + "r0 = 0;" + "exit;" + : + : __imm(bpf_ktime_get_ns) + : __clobber_all); +} + +/* The subprog returns 16 bytes in R0 and R2. may_goto must not change them. */ +__naked __noinline __used +static unsigned __int128 returns_pair_after_may_goto(void) +{ + asm volatile ( + "r0 = 1;" + "r2 = 2;" + "1:" + "may_goto 2f;" + "goto 1b;" + "2:" + "exit;" + ::: __clobber_all); +} + +SEC("socket") +__description("timed may_goto: the subprog returns 16 bytes") +__success __retval(3) +__naked void subprog_with_may_goto_returns_pair(void) +{ + asm volatile ( + "call returns_pair_after_may_goto;" + "r0 += r2;" + "exit;" + ::: __clobber_all); +} + +/* Dead code doesn't count: a prog that has no may_goto left gets no insns. */ +__naked __noinline __used +static unsigned long may_goto_is_dead_code(void) +{ + asm volatile ( + "r0 = 0;" + "if r0 == 0 goto 2f;" + "1:" + "may_goto 2f;" + "goto 1b;" + "2:" + "exit;" + ::: __clobber_all); +} + +SEC("socket") +__description("timed may_goto: may_goto in dead code") +__success __retval(0) +__xlated("0: call pc+1") +__xlated("1: exit") +__xlated("2: r0 = 0") +__xlated("3: exit") +__naked void dead_may_goto(void) +{ + asm volatile ( + "call may_goto_is_dead_code;" + "exit;" + ::: __clobber_all); +} + +static __noinline int throws_after_spin(void) +{ + spin(); + bpf_throw(0); + return 0; +} + +__noinline int exception_cb_loops(u64 cookie) +{ + return counts_to_1000(); +} + +/* The exception callback belongs to the invocation that throws. */ +SEC("tc") +__description("timed may_goto: bpf_throw() the exception callback has a loop") +__exception_cb(exception_cb_loops) +__success __retval(0) +int throw_after_timeout(void *ctx) +{ + return throws_after_spin(); +} + +#else + +SEC("socket") +__description("timed may_goto: not supported dummy test") +__success +int dummy_test(void) +{ + return 0; +} + +#endif diff --git a/tools/testing/selftests/bpf/progs/timed_may_goto_ext.c b/tools/testing/selftests/bpf/progs/timed_may_goto_ext.c new file mode 100644 index 00000000000000..969ca58b6eedcc --- /dev/null +++ b/tools/testing/selftests/bpf/progs/timed_may_goto_ext.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "bpf_misc.h" +#include "bpf_experimental.h" + +char _license[] SEC("license") = "GPL"; + +static __noinline int spins(void) +{ + __u64 t0 = bpf_ktime_get_ns(); + + while (can_loop) + ; + return bpf_ktime_get_ns() - t0 > 100 * 1000 * 1000; +} + +/* Each call of an extension prog is an invocation: one of its two calls spins. */ +SEC("freplace") +int replacement(int i) +{ + return spins() + spins() + i; +} diff --git a/tools/testing/selftests/bpf/progs/timed_may_goto_user.c b/tools/testing/selftests/bpf/progs/timed_may_goto_user.c new file mode 100644 index 00000000000000..8b85815d45d25e --- /dev/null +++ b/tools/testing/selftests/bpf/progs/timed_may_goto_user.c @@ -0,0 +1,311 @@ +// SPDX-License-Identifier: GPL-2.0 +/* The tests of timed_may_goto.c that need help from user space. */ +#include +#include +#include +#include "bpf_misc.h" +#include "bpf_experimental.h" + +char _license[] SEC("license") = "GPL"; + +#define TRIES 4 +#define CLOCK_MONOTONIC 1 + +int zero; + +/* Return 1 if the loop went on until the time was up. */ +static __always_inline int spin(void) +{ + __u64 t0 = bpf_ktime_get_ns(); + + while (can_loop) + ; + return bpf_ktime_get_ns() - t0 > 100 * 1000 * 1000; +} + +static __noinline int spins(void) +{ + return spin(); +} + +static __noinline int counts_to_1000(void) +{ + int i, cnt = zero; + + for (i = zero; i < 1000 && can_loop; i++) + cnt++; + return cnt; +} + +/* Nothing special: the loops go on, then the time is up one time. */ +SEC("tc") +int normal_prog(void *ctx) +{ + int i, n = 0; + + if (counts_to_1000() != 1000) + return 100; + for (i = 0; i < TRIES; i++) + n += spins(); + return n; +} + +/* + * Async callbacks + */ +struct elem { + struct bpf_timer timer; + struct bpf_wq wq; + struct bpf_task_work tw; + struct bpf_rcu_head rcu; +}; + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 2); + __type(key, int); + __type(value, struct elem); +} async SEC(".maps"); + +int timer_cnt, wq_cnt, tw_cnt, rcu_cnt, rcu_trace_cnt; + +static int timer_cb(void *map, int *key, struct elem *e) +{ + timer_cnt = counts_to_1000(); + return 0; +} + +static int wq_cb(void *map, int *key, void *val) +{ + wq_cnt = counts_to_1000(); + return 0; +} + +static int tw_cb(struct bpf_map *map, void *key, void *val) +{ + tw_cnt = counts_to_1000(); + return 0; +} + +static int rcu_cb(struct bpf_map *map, void *key, void *val) +{ + rcu_cnt = counts_to_1000(); + return 0; +} + +static int rcu_trace_cb(struct bpf_map *map, void *key, void *val) +{ + rcu_trace_cnt = counts_to_1000(); + return 0; +} + +/* + * The time of this prog is up when it starts the callbacks. User space keeps the task on the cpu, + * so the callbacks find what it has left. Each call of a callback is an invocation of its own. + */ +SEC("syscall") +int async_after_timeout(void *ctx) +{ + struct task_struct *task = bpf_get_current_task_btf(); + struct elem *e, *e1; + int key = 0, key1 = 1; + + e = bpf_map_lookup_elem(&async, &key); + e1 = bpf_map_lookup_elem(&async, &key1); + if (!e || !e1) + return 100; + if (bpf_timer_init(&e->timer, &async, CLOCK_MONOTONIC) || + bpf_timer_set_callback(&e->timer, timer_cb)) + return 101; + if (bpf_wq_init(&e->wq, &async, 0) || bpf_wq_set_callback(&e->wq, wq_cb, 0)) + return 102; + if (!spins()) + return 103; + /* control: the time is up */ + if (counts_to_1000()) + return 109; + if (bpf_timer_start(&e->timer, 0, BPF_F_TIMER_CPU_PIN)) + return 104; + if (bpf_wq_start(&e->wq, 0)) + return 105; + if (bpf_task_work_schedule_resume(task, &e->tw, &async, tw_cb)) + return 106; + if (bpf_call_rcu(&e->rcu, &async, rcu_cb)) + return 107; + if (bpf_call_rcu_tasks_trace(&e1->rcu, &async, rcu_trace_cb)) + return 108; + return 0; +} + +int ticks; + +static int tick_cb(void *map, int *key, struct elem *e) +{ + if (counts_to_1000() != 1000) + ticks = 1000; + if (++ticks < 100) + bpf_timer_start(&e->timer, 20 * 1000 * 1000, BPF_F_TIMER_CPU_PIN); + return 0; +} + +/* + * A callback of the prog interrupts it, on the same cpu, each 20 ms. It has its own time. That + * doesn't give more time to the prog. Return how long the loop went on, in ms. + */ +SEC("syscall") +int spin_under_timer(void *ctx) +{ + struct elem *e; + int key = 1; + __u64 t0; + + e = bpf_map_lookup_elem(&async, &key); + if (!e) + return 0; + if (bpf_timer_init(&e->timer, &async, CLOCK_MONOTONIC) || + bpf_timer_set_callback(&e->timer, tick_cb) || + bpf_timer_start(&e->timer, 20 * 1000 * 1000, BPF_F_TIMER_CPU_PIN)) + return 0; + t0 = bpf_ktime_get_ns(); + while (can_loop) + ; + return (bpf_ktime_get_ns() - t0) / 1000000; +} + +/* + * Extension prog + */ +__noinline int replaced_global(int i) +{ + return spin() + i; +} + +SEC("tc") +int freplace_target(void *ctx) +{ + int i, n = 0; + + for (i = 0; i < TRIES; i++) + n += replaced_global(zero); + return n; +} + +/* + * Tail calls + */ +struct { + __uint(type, BPF_MAP_TYPE_PROG_ARRAY); + __uint(max_entries, 1); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(int)); +} jmp_table SEC(".maps"); + +int tail_callee_spun; + +SEC("tc") +int tail_callee(struct __sk_buff *skb) +{ + int i; + + tail_callee_spun = 0; + for (i = 0; i < TRIES; i++) + tail_callee_spun += spins(); + return 0; +} + +static __noinline int tail_calls(struct __sk_buff *skb) +{ + bpf_tail_call(skb, &jmp_table, 0); + return zero + 100; +} + +/* The target of the tail call is another prog. It returns to this function. */ +SEC("tc") +int tail_call_in_subprog(struct __sk_buff *skb) +{ + int i, n; + + n = tail_calls(skb); + if (counts_to_1000() != 1000) + return 101; + for (i = 0; i < TRIES; i++) + n += spins(); + return n; +} + +SEC("tc") +int tail_call_after_timeout(struct __sk_buff *skb) +{ + spins(); + bpf_tail_call(skb, &jmp_table, 0); + return 100; +} + +static __noinline int throws(void) +{ + spin(); + bpf_throw(7); + return 0; +} + +SEC("tc") +int throw_after_timeout(void *ctx) +{ + return throws(); +} + +/* + * bpf_user_ringbuf_drain() + */ +struct { + __uint(type, BPF_MAP_TYPE_USER_RINGBUF); + __uint(max_entries, 4096); +} user_ringbuf SEC(".maps"); + +static long drain_cb(struct bpf_dynptr *dynptr, int *spun) +{ + *spun += spin(); + return 0; +} + +SEC("syscall") +int drain(void *ctx) +{ + int spun = 0; + + return bpf_user_ringbuf_drain(&user_ringbuf, drain_cb, &spun, 0) * 10 + spun; +} + +/* + * A tracing prog with large frames: they are in a private stack. + */ +int priv_stack_spun, priv_stack_cb_spun; + +static __noinline int spins_with_stack(void) +{ + volatile char buf[128] = {}; + + return spin() + buf[zero & 127]; +} + +static int priv_stack_cb(__u64 i, int *spun) +{ + volatile char buf[128] = {}; + + *spun += spin() + buf[zero & 127]; + return 0; +} + +SEC("fentry/bpf_fentry_test1") +int BPF_PROG(priv_stack) +{ + volatile char buf[128] = {}; + int i, n = buf[zero & 127], spun = 0; + + for (i = 0; i < TRIES; i++) + n += spins_with_stack(); + bpf_loop(TRIES, priv_stack_cb, &spun, zero); + priv_stack_spun = n; + priv_stack_cb_spun = spun; + return 0; +} diff --git a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c index e0c389102db9f8..d908298b9fc796 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c +++ b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c @@ -903,26 +903,28 @@ __naked void unconditional_jump_to_fill(void) SEC("raw_tp") __arch_x86_64 __log_level(4) -__msg("subprog 0 (may_goto_interaction_x86_64) main {{.*}} stack 24") -/* may_goto counter at -24 */ -__xlated("0: *(u64 *)(r10 -24) =") -/* may_goto timestamp at -16 */ -__xlated("1: *(u64 *)(r10 -16) =") -__xlated("2: r1 = 1") +__msg("subprog 0 (may_goto_interaction_x86_64) main {{.*}} stack 8") +/* may_goto counter and timestamp */ +__xlated("0: r0 = ") +__xlated("2: r0 = &(void __percpu *)(r0)") __xlated("...") -__xlated("4: r0 = &(void __percpu *)(r0)") +__xlated("6: r1 = 1") +__xlated("...") +__xlated("8: r0 = &(void __percpu *)(r0)") __xlated("...") -/* may_goto expansion starts */ -__xlated("6: r12 = *(u64 *)(r10 -24)") -__xlated("7: if r12 == 0x0 goto pc+6") -__xlated("8: r12 -= 1") -__xlated("9: if r12 != 0x0 goto pc+2") -__xlated("10: r12 = -24") -__xlated("11: call unknown") -__xlated("12: *(u64 *)(r10 -24) = r12") +/* may_goto expansion starts, r0 and r1 are live */ +__xlated("10: r2 = ") +__xlated("12: r2 = &(void __percpu *)(r2)") +__xlated("13: r12 = *(u64 *)(r2 +0)") +__xlated("14: if r12 == 0x0 goto pc+6") +__xlated("15: r12 -= 1") +__xlated("16: if r12 != 0x0 goto pc+2") +__xlated("17: r12 = r2") +__xlated("18: call unknown") +__xlated("19: *(u64 *)(r2 +0) = r12") /* may_goto expansion ends */ -__xlated("13: *(u64 *)(r10 -8) = r1") -__xlated("14: exit") +__xlated("20: *(u64 *)(r10 -8) = r1") +__xlated("21: exit") __success __naked void may_goto_interaction_x86_64(void) { @@ -946,24 +948,26 @@ __arch_arm64 __arch_riscv64 __arch_loongarch __log_level(4) -__msg("subprog 0 (may_goto_interaction) main {{.*}} stack 24") -/* may_goto counter at -24 */ -__xlated("0: *(u64 *)(r10 -24) =") -/* may_goto timestamp at -16 */ -__xlated("1: *(u64 *)(r10 -16) =") -__xlated("2: r1 = 1") -__xlated("3: call bpf_get_smp_processor_id") -/* may_goto expansion starts */ -__xlated("4: r12 = *(u64 *)(r10 -24)") -__xlated("5: if r12 == 0x0 goto pc+6") -__xlated("6: r12 -= 1") -__xlated("7: if r12 != 0x0 goto pc+2") -__xlated("8: r12 = -24") -__xlated("9: call unknown") -__xlated("10: *(u64 *)(r10 -24) = r12") +__msg("subprog 0 (may_goto_interaction) main {{.*}} stack 8") +/* may_goto counter and timestamp */ +__xlated("0: r0 = ") +__xlated("2: r0 = &(void __percpu *)(r0)") +__xlated("...") +__xlated("6: r1 = 1") +__xlated("7: call bpf_get_smp_processor_id") +/* may_goto expansion starts, r0 and r1 are live */ +__xlated("8: r2 = ") +__xlated("10: r2 = &(void __percpu *)(r2)") +__xlated("11: r12 = *(u64 *)(r2 +0)") +__xlated("12: if r12 == 0x0 goto pc+6") +__xlated("13: r12 -= 1") +__xlated("14: if r12 != 0x0 goto pc+2") +__xlated("15: r12 = r2") +__xlated("16: call unknown") +__xlated("17: *(u64 *)(r2 +0) = r12") /* may_goto expansion ends */ -__xlated("11: *(u64 *)(r10 -8) = r1") -__xlated("12: exit") +__xlated("18: *(u64 *)(r10 -8) = r1") +__xlated("19: exit") __success __naked void may_goto_interaction(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_callx.c b/tools/testing/selftests/bpf/progs/verifier_callx.c index 7e59188d9fca96..a12bc421e75ceb 100644 --- a/tools/testing/selftests/bpf/progs/verifier_callx.c +++ b/tools/testing/selftests/bpf/progs/verifier_callx.c @@ -289,6 +289,26 @@ __naked void callx_callee_writes_caller_stack(void) : __clobber_all); } +/* callee can store a pointer that is not FP-derived over a pointer spilled by the caller */ +SEC("socket") +__success __log_level(2) +__msg("r0 = *(u64 *)(r10 -16) // fp-16=fp0-8|fp0+0") +__naked void callx_callee_can_overwrite_spilled_fp(void) +{ + asm volatile ( + "r1 = r10;" + "r1 += -8;" + "*(u64 *)(r10 - 16) = r1;" + "r2 = %[write42] ll;" + "callx r2;" + "r0 = *(u64 *)(r10 - 16);" + "r0 = 0;" + "exit;" + : + : __imm_addr(write42) + : __clobber_all); +} + SEC("socket") __failure __msg("R1 has type scalar, expected func") __naked void callx_scalar(void) diff --git a/tools/testing/selftests/bpf/progs/verifier_global_subprogs.c b/tools/testing/selftests/bpf/progs/verifier_global_subprogs.c index 574b26b5a7dfb3..5e8461b2167dcf 100644 --- a/tools/testing/selftests/bpf/progs/verifier_global_subprogs.c +++ b/tools/testing/selftests/bpf/progs/verifier_global_subprogs.c @@ -538,14 +538,15 @@ int return_from_void_global(struct __sk_buff *skb) int global_calls_loop(int x); -static __noinline int static_calls_global(int x) +static __noinline void static_calls_global(int x) { - return global_calls_loop(x); + global_calls_loop(x); } static __noinline int loop_cb_calls_static(u32 i, void *ctx) { - return static_calls_global(i); + static_calls_global(i); + return 0; } __noinline int global_calls_loop(int x) diff --git a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c index 1fbcc522830614..4dd98acc6436d4 100644 --- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c +++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c @@ -553,7 +553,11 @@ int cond_break5(const void *ctx) { int cnt1 = zero, cnt2; - for (;;) { + /* + * There is one time slice for all may_goto of the prog. When it's used up a function that + * is called after that makes no iteration. So this loop has an end. + */ + for (; cnt1 < 100;) { cond_break; cnt1++; } diff --git a/tools/testing/selftests/bpf/progs/verifier_live_stack.c b/tools/testing/selftests/bpf/progs/verifier_live_stack.c index 5f9b11a812604a..2ae5c60150dd30 100644 --- a/tools/testing/selftests/bpf/progs/verifier_live_stack.c +++ b/tools/testing/selftests/bpf/progs/verifier_live_stack.c @@ -1943,11 +1943,15 @@ static __used __naked void grandchild_deref(void) ::: __clobber_all); } +/* + * The callee gets a pointer to the frame that holds the spills. It can store a pointer + * that is not FP-derived over them: after the call each of them is "fp-N or not FP-derived". + */ SEC("socket") __log_level(2) __success -__msg("14: (79) r1 = *(u64 *)(r10 -8) // r6=fp0-8 r7=fp1-16 fp-8=fp1-16 fp-16=fp0-8") -__msg("15: (79) r0 = *(u64 *)(r1 +0) // r1=fp1-16 r6=fp0-8 r7=fp1-16 fp-8=fp1-16 fp-16=fp0-8") +__msg("14: (79) r1 = *(u64 *)(r10 -8) // r6=fp0-8 r7=fp1-16 fp-8=fp1-16|fp1+0 fp-16=fp0-8|fp0+0") +__msg("15: (79) r0 = *(u64 *)(r1 +0) // r1=fp1-16|fp1+0 r6=fp0-8 r7=fp1-16 fp-8=fp1-16|fp1+0") __msg("stack use/def subprog#1 mid_two_fp_threshold (d1,cs2):") __msg("14: (79) r1 = *(u64 *)(r10 -8) ; use: fp1-8") __msg("15: (79) r0 = *(u64 *)(r1 +0) ; use: fp1-16") @@ -1992,8 +1996,8 @@ static __used __naked void inner_nop_fptest(void) SEC("socket") __log_level(2) __success -__msg("13: (79) r1 = *(u64 *)(r10 -8) // r6=fp0-8 r7=fp1-16 fp-8=fp1-16 fp-16=fp0-8") -__msg("14: (79) r0 = *(u64 *)(r1 +0) // r1=fp1-16 r6=fp0-8 r7=fp1-16 fp-8=fp1-16 fp-16=fp0-8") +__msg("13: (79) r1 = *(u64 *)(r10 -8) // r6=fp0-8 r7=fp1-16 fp-8=fp1-16|fp1+0 fp-16=fp0-8|fp0+0") +__msg("14: (79) r0 = *(u64 *)(r1 +0) // r1=fp1-16|fp1+0 r6=fp0-8 r7=fp1-16 fp-8=fp1-16|fp1+0") __msg("stack use/def subprog#1 mid_one_fp_threshold (d1,cs2):") __msg("13: (79) r1 = *(u64 *)(r10 -8) ; use: fp1-8") __msg("14: (79) r0 = *(u64 *)(r1 +0) ; use: fp1-16") @@ -2565,6 +2569,189 @@ __naked void stack_or_non_stack_write(void) : __clobber_all); } +/* @insns start with fp-8 = 0 and r0 = pointer to map value */ +#define WITH_MAP_VALUE(insns) \ + asm volatile ( \ + "*(u64 *)(r10 - 8) = 0;" \ + "r1 = %[array_map_8b] ll;" \ + "r2 = r10;" \ + "r2 += -8;" \ + "call %[bpf_map_lookup_elem];" \ + "if r0 == 0 goto 9f;" \ + insns \ +"9:" \ + "exit;" \ + : \ + : __imm(bpf_map_lookup_elem), \ + __imm(bpf_loop), \ + __imm_addr(array_map_8b) \ + : __clobber_all) + +/* + * r1 and r2 are r10 or a pointer to map value, joined in both orders. The stores through them + * are not certain writes to fp-8 and fp-16: both slots are live before the stores. + */ +SEC("socket") +__success __log_level(2) +__msg("r1: fp0+0 + _ => fp0 ?") +__msg("r2: _ + fp0+0 => fp0 ?") +__naked void join_of_r10_and_map_value(void) +{ + WITH_MAP_VALUE( + "*(u64 *)(r10 - 16) = 0;" + "r1 = r10;" + "r2 = r0;" + "r2 += 16;" + "r3 = *(u64 *)(r0 + 0);" + "if r3 == 0 goto 1f;" + "r1 = r0;" + "r1 += 8;" + "r2 = r10;" +"1:" + "*(u64 *)(r1 - 8) = 42;" + "*(u64 *)(r2 - 16) = 42;" + "r0 = *(u64 *)(r10 - 8);" + "r1 = *(u64 *)(r10 - 16);"); +} + +/* The counter in fp-8 is the offset in the map value r9. The store through r8 can change it. */ +#define LOOP_WITH_STORE_THROUGH_R8 \ +"8:" \ + "r1 = *(u64 *)(r10 - 8);" \ + "r2 = r9;" \ + "r2 += r1;" \ + "r0 = *(u8 *)(r2 + 0);" \ + "r1 += 1;" \ + "*(u64 *)(r10 - 8) = r1;" \ + "*(u64 *)(r8 + 0) = 4096;" \ + "if r1 < 8 goto 8b;" + +/* + * r7 is r10 or a pointer to map value. The store through r7 is not a certain write to fp-16: + * fp-16 can still hold &fp[-8], and then the store through r8 changes the counter of the loop. + */ +SEC("socket") +__failure __msg("invalid access to map value, value_size=8 off=4096 size=1") +__naked void join_of_r10_and_map_value_hidden_store(void) +{ + WITH_MAP_VALUE( + "r9 = r0;" + "r7 = r10;" + "r1 = *(u64 *)(r9 + 0);" + "if r1 == 0 goto 1f;" + "r7 = r9;" + "r7 += 16;" +"1:" + "r1 = r10;" + "r1 += -8;" + "*(u64 *)(r10 - 16) = r1;" + "*(u64 *)(r7 - 16) = r9;" + "r8 = *(u64 *)(r10 - 16);" + LOOP_WITH_STORE_THROUGH_R8); +} + +/* ctx[1] = ctx[0]. ctx is the second param, as in a callback of bpf_loop(). */ +static __used __naked void copy_first_to_second(void) +{ + asm volatile ( + "r1 = *(u64 *)(r2 + 0);" + "*(u64 *)(r2 + 8) = r1;" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + +/* + * fp-16 holds &fp[-8]. The callee gets &fp[-24] and stores a pointer to map value to fp-16. + * The store through the filled pointer is not a certain write to fp-8: fp-8 is live before it. + */ +SEC("socket") +__success __retval(0) __log_level(2) +__msg("r1 = *(u64 *)(r10 -16) // fp-16=fp0-8|fp0+0") +__msg("*(u64 *)(r1 +0) = 42{{ +}}; may_def: fp0-8") +__naked void callee_overwrites_spilled_fp(void) +{ + WITH_MAP_VALUE( + "r1 = r10;" + "r1 += -8;" + "*(u64 *)(r10 - 16) = r1;" + "*(u64 *)(r10 - 24) = r0;" + "r2 = r10;" + "r2 += -24;" + "call copy_first_to_second;" + "r1 = *(u64 *)(r10 - 16);" + "*(u64 *)(r1 + 0) = 42;" + "r0 = *(u64 *)(r10 - 8);"); +} + +/* The same, but fp-16 holds a copy of r10, and the callee stores map value + 8 over it. */ +SEC("socket") +__success __retval(0) +__naked void callee_overwrites_spilled_r10(void) +{ + WITH_MAP_VALUE( + "*(u64 *)(r10 - 16) = r10;" + "r0 += 8;" + "*(u64 *)(r10 - 24) = r0;" + "r2 = r10;" + "r2 += -24;" + "call copy_first_to_second;" + "r1 = *(u64 *)(r10 - 16);" + "*(u64 *)(r1 - 8) = 42;" + "r0 = *(u64 *)(r10 - 8);"); +} + +/* The same, but the callee is a callback. */ +SEC("socket") +__success __retval(0) +__load_if_JITed() +__naked void callback_overwrites_spilled_fp(void) +{ + WITH_MAP_VALUE( + "r1 = r10;" + "r1 += -8;" + "*(u64 *)(r10 - 16) = r1;" + "*(u64 *)(r10 - 24) = r0;" + "r1 = 1;" + "r2 = copy_first_to_second ll;" + "r3 = r10;" + "r3 += -24;" + "r4 = 0;" + "call %[bpf_loop];" + "r1 = *(u64 *)(r10 - 16);" + "*(u64 *)(r1 + 0) = 42;" + "r0 = *(u64 *)(r10 - 8);"); +} + +/* + * fp-16 holds &fp[-8], fp-24 holds &fp[-16], and the callee stores a pointer to map value to fp-24. + * fp-16 is still known after the call, and the store through r7 is not a certain write to it: + * r8 is &fp[-8], and the store through r8 changes the counter of the loop. + */ +SEC("socket") +__failure __msg("invalid access to map value, value_size=8 off=4096 size=1") +__naked void callee_overwrites_spilled_fp_hidden_store(void) +{ + WITH_MAP_VALUE( + "r9 = r0;" + "r1 = r10;" + "r1 += -8;" + "*(u64 *)(r10 - 16) = r1;" + "r1 += -8;" + "*(u64 *)(r10 - 24) = r1;" + "*(u64 *)(r10 - 32) = r9;" + "r2 = r10;" + "r2 += -32;" + "call copy_first_to_second;" + /* the fill keeps fp-16 live over the call */ + "r1 = *(u64 *)(r10 - 16);" + "*(u64 *)(r10 - 16) = r1;" + "r7 = *(u64 *)(r10 - 24);" + "*(u64 *)(r7 + 0) = r9;" + "r8 = *(u64 *)(r10 - 16);" + LOOP_WITH_STORE_THROUGH_R8); +} + SEC("socket") __log_level(2) __flag(BPF_F_TEST_STATE_FREQ) diff --git a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c index faf9eec0a63ebc..20152a15ca360b 100644 --- a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c +++ b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c @@ -82,23 +82,31 @@ __naked void may_goto_batch_1(void) SEC("raw_tp") __description("may_goto batch with offsets 2/0") +__load_if_JITed() __arch_x86_64 __arch_s390x __arch_arm64 __arch_riscv64 __arch_loongarch -__xlated("0: *(u64 *)(r10 -16) = 65535") -__xlated("1: *(u64 *)(r10 -8) = 0") -__xlated("2: r12 = *(u64 *)(r10 -16)") -__xlated("3: if r12 == 0x0 goto pc+6") -__xlated("4: r12 -= 1") -__xlated("5: if r12 != 0x0 goto pc+2") -__xlated("6: r12 = -16") -__xlated("7: call unknown") -__xlated("8: *(u64 *)(r10 -16) = r12") -__xlated("9: r0 = 1") -__xlated("10: r0 = 2") -__xlated("11: exit") +/* the main prog sets count, timestamp, owner */ +__xlated("0: r0 = ") +__xlated("2: r0 = &(void __percpu *)(r0)") +__xlated("3: *(u64 *)(r0 +0) = 65535") +__xlated("4: *(u64 *)(r0 +8) = 0") +__xlated("5: *(u64 *)(r0 +16) = 0") +/* may_goto, r0 is dead */ +__xlated("6: r0 = ") +__xlated("8: r0 = &(void __percpu *)(r0)") +__xlated("9: r12 = *(u64 *)(r0 +0)") +__xlated("10: if r12 == 0x0 goto pc+6") +__xlated("11: r12 -= 1") +__xlated("12: if r12 != 0x0 goto pc+2") +__xlated("13: r12 = r0") +__xlated("14: call unknown") +__xlated("15: *(u64 *)(r0 +0) = r12") +__xlated("16: r0 = 1") +__xlated("17: r0 = 2") +__xlated("18: exit") __success __naked void may_goto_batch_2(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_private_stack.c b/tools/testing/selftests/bpf/progs/verifier_private_stack.c index 3d9994a52464e6..bbc09f516d9201 100644 --- a/tools/testing/selftests/bpf/progs/verifier_private_stack.c +++ b/tools/testing/selftests/bpf/progs/verifier_private_stack.c @@ -279,6 +279,105 @@ int private_stack_exception_sub_prog(void) return 0; } +/* + * Nothing attaches the two fentry progs above, so they are loaded, but never + * run. BPF_PROG_TEST_RUN does run a raw_tp prog. The default exception callback + * returns the cookie of bpf_throw(). + */ +SEC("raw_tp") +__description("Private stack, run, exception in main prog") +__success __retval(1) +__arch_x86_64 +__jited(" movq %rdi, -0x200(%r9)") +__jited(" movl $0x1, %edi") +__jited(" pushq %r9") +__jited("...") +__jited(" callq") +__naked void private_stack_run_exception_main_prog(void) +{ + asm volatile (" \ + r1 = 42; \ + *(u64 *)(r10 - 512) = r1; \ + r1 = 1; \ + call %[bpf_throw]; \ + r0 = 0; \ + exit; \ +" : + : __imm(bpf_throw) + : __clobber_all); +} + +__used +__naked static void subprog_throw(void) +{ + asm volatile (" \ + r1 = 2; \ + call %[bpf_throw]; \ + r0 = 0; \ + exit; \ +" : + : __imm(bpf_throw) + : __clobber_all); +} + +SEC("raw_tp") +__description("Private stack, run, exception in subprog") +__success __retval(2) +__arch_x86_64 +__jited(" movq %rdi, -0x200(%r9)") +__jited(" pushq %r9") +__jited("...") +__jited(" callq") +__jited(" popq %r9") +__naked void private_stack_run_exception_sub_prog(void) +{ + asm volatile (" \ + r1 = 42; \ + *(u64 *)(r10 - 512) = r1; \ + call subprog_throw; \ + r0 = 0; \ + exit; \ +" ::: __clobber_all); +} + +__used +__naked static void private_stack_subprog_throw(void) +{ + asm volatile (" \ + r1 = 42; \ + *(u64 *)(r10 - 512) = r1; \ + r1 = 3; \ + call %[bpf_throw]; \ + r0 = 0; \ + exit; \ +" : + : __imm(bpf_throw) + : __clobber_all); +} + +/* Only the frame of the main prog counts, and it has nothing pushed at the call */ +SEC("raw_tp") +__description("Private stack, run, exception in subprog, no private stack in main prog") +__success __retval(3) +__arch_x86_64 +__jited(" subq $0x8, %rsp") +__jited("...") +__jited("func #1") +__jited("...") +__jited(" movq %rdi, -0x200(%r9)") +__jited(" movl $0x3, %edi") +__jited(" pushq %r9") +__naked void no_private_stack_run_exception_sub_prog(void) +{ + asm volatile (" \ + r1 = 42; \ + *(u64 *)(r10 - 8) = r1; \ + call private_stack_subprog_throw; \ + r0 = 0; \ + exit; \ +" ::: __clobber_all); +} + int glob; __noinline static void subprog2(int *val) { diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c index fa01a616af9d1c..0be4fe8aadc78b 100644 --- a/tools/testing/selftests/bpf/progs/verifier_scev.c +++ b/tools/testing/selftests/bpf/progs/verifier_scev.c @@ -3936,4 +3936,186 @@ __naked void clamp_pkt_pointer_keeps_range_of_entry(void) : __clobber_all); } +/* + * r4 is 0, 8 .. 48, but its umax is 50. @bytes from r6 are in the packet: the range of r6 is + * @start + 50 + @bytes. + */ +#define PKT_PLUS_R4(start, bytes) \ + "r7 = *(u32 *)(r1 + %[data_end]);" \ + "r6 = *(u32 *)(r1 + %[data]);" \ + "r4 = *(u32 *)(r1 + %[mark]);" \ + "r4 &= 0x38;" \ + "if r4 > 50 goto 9f;" \ + "r6 += " #start ";" \ + "r6 += r4;" \ + "r5 = r6;" \ + "r5 += " #bytes ";" \ + "if r5 > r7 goto 9f;" + +#define PKT_IMMS \ + __imm_const(data, offsetof(struct __sk_buff, data)), \ + __imm_const(data_end, offsetof(struct __sk_buff, data_end)), \ + __imm_const(mark, offsetof(struct __sk_buff, mark)) + +/* + * r6 is 0..58 at the head, and 0..56 with the step of 8. The range must go from 58 to 56 too: + * in the second iteration no byte from r6 is in the packet. + */ +SEC("tc") +__failure __msg("invalid access to packet, off=56 size=2, R6(id=2,off=56,r=56)") +__naked void widen_pkt_pointer_step_lowers_umax(void) +{ + asm volatile ( + PKT_PLUS_R4(0, 8) + "r9 = 0;" +"1:" + "r0 = *(u16 *)(r6 + 0);" + "r6 += 8;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* The pointer goes down. 8 bytes from the first r6 are in the packet, not 10. */ +SEC("tc") +__failure __msg("invalid access to packet, off=120 size=2, R6(id=2,off=120,r=120)") +__naked void widen_pkt_pointer_step_lowers_umax_down(void) +{ + asm volatile ( + PKT_PLUS_R4(64, 8) + "r9 = 0;" +"1:" + "r0 = *(u16 *)(r6 + 8);" + "r6 += -8;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* + * r6 is -8..50 at the head, and -8..48 with the step of 8. Its umax is U64_MAX in the two cases. + * r5 is 0..56 and has the range of r6. In the first iteration no byte from r5 is in the packet. + */ +SEC("tc") +__failure __msg("invalid access to packet, off=56 size=2, R5(id=2,off=56,r=56)") +__naked void widen_pkt_pointer_negative_offset(void) +{ + asm volatile ( + PKT_PLUS_R4(0, 8) + "r9 = 0;" +"1:" + "r5 = r6;" + "r5 += 8;" + "r0 = *(u16 *)(r5 + 0);" + "r6 += -8;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* The access is in the second iteration only: the verifier gets to it after the clamp */ +SEC("tc") +__failure __msg("invalid access to packet, off=56 size=2, R6(id=3,off=56,r=56)") +__naked void clamp_pkt_pointer_step_lowers_umax(void) +{ + asm volatile ( + PKT_PLUS_R4(0, 8) + "r9 = 0;" + "w1 = 0;" + "*(u32 *)(r10 - 8) = r1;" +"1:" + "w1 = *(u32 *)(r10 - 8);" + "if w1 == 0 goto 2f;" + "r0 = *(u16 *)(r6 + 0);" +"2:" + "w1 = 1;" + "*(u32 *)(r10 - 8) = r1;" + "r6 += 8;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* r5 is r5 = r6 + 8 or r6 at the head. Here var_off lowers umax. No byte from r6 + 8 is valid. */ +SEC("tc") +__failure __msg("invalid access to packet, off=56 size=2, R5(id=2,off=56,r=56)") +__naked void union_pkt_pointer_var_off_lowers_umax(void) +{ + asm volatile ( + PKT_PLUS_R4(0, 8) + "r9 = 0;" +"1:" + "r0 = *(u16 *)(r5 + 0);" + "r5 = r6;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* 16 bytes from r6 are in the packet: two iterations read 8 bytes each */ +SEC("tc") +__success __retval(0) +__naked void widen_pkt_pointer_keeps_valid_bytes(void) +{ + asm volatile ( + PKT_PLUS_R4(0, 16) + "r9 = 0;" +"1:" + "r0 = *(u64 *)(r6 + 0);" + "r6 += 8;" + "r9 += 1;" + "if r9 < 2 goto 1b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + +/* + * r6 is beyond pkt_end in front of the loop and comes back into the packet. The mark is not for + * all iterations: the verifier must look at the two branches of the compare in the first pass. + */ +SEC("tc") +__success +__log_level(2) +__msg("widening r6 to 32..96 step 32") +__msg("6: R6=pkt(id=1,r=0,smin=umin=smin32=umin32=32,smax=umax=smax32=umax32=96") +__naked void widen_pkt_pointer_beyond_pkt_end(void) +{ + asm volatile ( + "r7 = *(u32 *)(r1 + %[data_end]);" + "r6 = *(u32 *)(r1 + %[data]);" + "r6 += 96;" + "if r6 > r7 goto 1f;" + "goto 9f;" +"1:" + "r9 = 0;" +"2:" + "if r6 > r7 goto 3f;" + "r0 = *(u8 *)(r6 - 1);" +"3:" + "r6 += -32;" + "r9 += 1;" + "if r9 < 3 goto 2b;" +"9:" + "r0 = 0;" + "exit;" + :: PKT_IMMS : __clobber_all); +} + char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c index 15a12497e07434..abf319cb851410 100644 --- a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c +++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c @@ -552,6 +552,121 @@ __naked void stack_arg_may_goto_in_caller(void) ); } +/* arg6 is an offset into the value of map_hash_8b. 0-7 are in bounds. */ +__naked __noinline __used +static long arg6_is_map_value_off(long a, long b, long c, long d, long e, long off) +{ + asm volatile ( + "r6 = *(u64 *)(r11 + 8);" + "r1 = 0;" + "*(u64 *)(r10 - 8) = r1;" + "r2 = r10;" + "r2 += -8;" + "r1 = %[map_hash_8b] ll;" + "call %[bpf_map_lookup_elem];" + "if r0 == 0 goto l0_%=;" + "r0 += r6;" + "r0 = *(u8 *)(r0 + 0);" + "l0_%=:" + "exit;" + : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b) + : __clobber_all + ); +} + +SEC("tc") +__description("stack_arg: a pruned state propagates precision of arg6") +__failure __msg("invalid access to map value") +__flag(BPF_F_TEST_STATE_FREQ) +__naked void stack_arg_precision_pruned_state(void) +{ + asm volatile ( + "call %[bpf_get_prandom_u32];" + "if r0 != 0 goto l0_%=;" + /* Path 1: arg6 = 0. It makes arg6 precise at l3. */ + "*(u64 *)(r11 - 8) = 0;" + "goto l3_%=;" + "l0_%=:" + "if r0 == 1 goto l1_%=;" + /* Path 2: arg6 = r6 = 0. Pruned at l3. It has to make r6 precise at l2. */ + "r6 = 0;" + "goto l2_%=;" + "l1_%=:" + /* Path 3: arg6 = r6 = 8. Out of bounds. */ + "r6 = 8;" + "l2_%=:" + "*(u64 *)(r11 - 8) = r6;" + "l3_%=:" + "r1 = 0;" + "r2 = 0;" + "r3 = 0;" + "r4 = 0;" + "r5 = 0;" + "call arg6_is_map_value_off;" + "exit;" + :: __imm(bpf_get_prandom_u32) + : __clobber_all + ); +} + +/* The same, but backtracking of r1 sees a store through r1 and marks all scalars precise. */ +__naked __noinline __used +static long arg6_is_map_value_off_fallback(long a, long b, long c, long d, long e, long off) +{ + asm volatile ( + "r6 = *(u64 *)(r11 + 8);" + "r1 = 0;" + "*(u64 *)(r10 - 8) = r1;" + "r2 = r10;" + "r2 += -8;" + "r1 = %[map_hash_8b] ll;" + "call %[bpf_map_lookup_elem];" + "if r0 == 0 goto l0_%=;" + "r1 = r0;" + "*(u8 *)(r1 + 0) = 0;" + "r1 -= r0;" + "r1 &= 0;" + "r1 += r6;" + "r0 += r1;" + "r0 = *(u8 *)(r0 + 0);" + "l0_%=:" + "exit;" + : + : __imm(bpf_map_lookup_elem), + __imm_addr(map_hash_8b) + : __clobber_all + ); +} + +SEC("tc") +__description("stack_arg: forcing all scalars precise covers arg6") +__failure __msg("invalid access to map value") +__flag(BPF_F_TEST_STATE_FREQ) +__naked void stack_arg_precision_fallback(void) +{ + asm volatile ( + "call %[bpf_get_prandom_u32];" + "if r0 != 0 goto l0_%=;" + "*(u64 *)(r11 - 8) = 0;" + "goto l1_%=;" + "l0_%=:" + /* Out of bounds. Must not be pruned at l1. */ + "*(u64 *)(r11 - 8) = 8;" + "l1_%=:" + "r1 = 0;" + "r2 = 0;" + "r3 = 0;" + "r4 = 0;" + "r5 = 0;" + "call arg6_is_map_value_off_fallback;" + "exit;" + :: __imm(bpf_get_prandom_u32) + : __clobber_all + ); +} + #else SEC("socket") diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index 83ef6c781af338..1397ec428c46f4 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -137,7 +137,8 @@ LAST_PRESENT_CPU=$(cat /sys/devices/system/cpu/present | sed -e "s/.*[,-]//") # If isolated CPUs have been reserved at boot time (as shown in # /sys/devices/system/cpu/isolated), these isolated CPUs should be outside of # CPUs 0-8 that will be used by this script for testing purpose. If not, some -# of the tests may fail incorrectly. +# of the tests may fail incorrectly. The first boot isolated CPU should be +# 10 or above. # # The current set of isolated CPUs (as shown in cpuset.cpus.isolated) should # be the same as the boot value. If not, wait a bit and retry again just in @@ -156,7 +157,7 @@ TEST_ISOLCPUS= [[ -n "$BOOT_ISOLCPUS" ]] && { FIRST_ISOLCPUS=$(echo $BOOT_ISOLCPUS | sed -e "s/[,-].*//") echo "Boot isolated CPUs: $BOOT_ISOLCPUS" - [[ $FIRST_ISOLCPUS -le 8 ]] && + [[ $FIRST_ISOLCPUS -le 9 ]] && skip_test "Boot isolated CPUs overlap CPUs to be tested" } @@ -433,6 +434,12 @@ TEST_MATRIX=( # cpuset.cpus is allowed, but those extra CPUs are ignored. " C2-3:P1 C3:P1 . . . C2-4 . . 0 A1:|A2:2-3 A1:P1|A2:P1" + # Clearing cpuset.cpus.exclusive of an invalid partition releases its + # exclusive CPUs, including those of its descendants, so a sibling + # can claim them. + " CX2-3:P1 . . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XB1:3 A1:P-1" + " CX2-3:P1 X3 . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XA2:|XB1:3 A1:P-1" + # A child cannot recover until its exclusive CPUs are available again. " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1" @@ -531,6 +538,31 @@ TEST_MATRIX=( " C1-4:P1 C3-4:P2 . . T:C4-6 . . . 0 A1:5-6|A2:4 A1:P1|A2:P2 4" " C1-4:P1 C1-2:P2 . . T:C4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # The extra CPUs gained by a child partition when its parent expands the + # exclusive CPUs have to be taken away from the parent. + " C2-6:X2-5:P1 CX4-6:P1 \ + . . X2-6 . . . 0 A1:2-3|A2:4-6|XA2:4-6 \ + A1:P1|A2:P1 ." + " C2-6:X2-5:P1 CX4-6:P2 \ + . . X2-6 . . . 0 A1:2-3|A2:4-6|XA2:4-6 \ + A1:P1|A2:P2 4-6" + + # Both expansion and contraction of parent's effective_xcpus will be + # correctly handled in child partition and the child can be invalidated + # if a populated parent could lose all its effective_cpus. + " C2-6:X2-5:P1 CX3,5-6:P2 \ + . . X4-6 . . . 0 A1:4|A2:5-6|XA2:5-6 \ + A1:P1|A2:P2 4-6|5-6" + " C2-6:X2-5:P1 CX3-6:P2 \ + . . T:X4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + + # Switch PRS state (root <=> isolated) will properly update cpuset.cpus.isolated + # even if child partitions are present. + " C1-6:P1 C3-6:P1 C5-6:P2 . . P2 . . 0 A1:1-2|A2:3-4|A3:5-6 \ + A1:P1|A2:P2|A3:P2 3-6" + " C1-6:P1 C3-6:P2 C5-6:P2 . . P1 . . 0 A1:1-2|A2:3-4|A3:5-6 \ + A1:P1|A2:P1|A3:P2 5-6" + # # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ -------- @@ -587,6 +619,7 @@ ISOLCPUS_TEST_MATRIX=( ) # Test matrix to be run when boot time nohz_full CPUs cover all CPUs except CPUs 0-7 +# This also means that CPU 8 is available and is a nohz_full CPU. NOHZ_FULL_TEST_MATRIX=( # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ -------- @@ -595,6 +628,10 @@ NOHZ_FULL_TEST_MATRIX=( " C2-7:P2 . . . C0-4 . . . 0 A1:0-4 A1:P2 0-4" " C1-7:P2 C5-7:P2 . . . . . C0:P2 0 A1:1-4|A2:5-7|B1:0 A1:P2|A2:P2|B1:P-2 1-7" + # An isolated child partition cannot grow to take over the last + # housekeeping CPU when its parent expands the exclusive CPUs. + " C0-8:X1-8:P1 CX0-8:P2 . . X0-7 . . . 0 A1:0-7|A2:0-7 A1:P1|A2:P-2 ." + " C0-8:X0-6:P1 CX0-8:P2 . . X2-8 . . . 0 A1:|A2:2-8 A1:P1|A2:P2 2-8" ) # @@ -670,6 +707,11 @@ REMOTE_TEST_MATRIX=( " C1-4:P1 C5-6 C1-2 . C5 . \ . P1 P1 . O5=0 . p1:3-4|p2:6|c11:1-2|c12:3-4|c21:6|c22:6 \ p1:P1|p2:P1|c11:P1" + # Expanding a remote partition should check top cpuset, not its member + # parent, for the no CPU left for tasks error. + " CX2-3:T . C2-3:X2:P1 . . . \ + . . X2-3 . . . p1:1,4-7|c11:2-3 \ + p1:P0|c11:P1" ) # diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/testing/selftests/drivers/net/hw/.gitignore index 46540468a7753f..911a9bfeaf41ed 100644 --- a/tools/testing/selftests/drivers/net/hw/.gitignore +++ b/tools/testing/selftests/drivers/net/hw/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only iou-zcrx ncdevmem +tls_hw_offload toeplitz diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 9b6b5d15f04d76..429cb545a4f0a2 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -47,6 +47,7 @@ TEST_PROGS = \ rss_drv.py \ rss_flow_label.py \ rss_input_xfrm.py \ + tls_hw_offload.py \ toeplitz.py \ tso.py \ userns_devmem.py \ @@ -81,6 +82,7 @@ YNL_GEN_FILES := \ $(COND_GEN_FILES) \ # end of YNL_GEN_FILES TEST_GEN_FILES += $(YNL_GEN_FILES) +TEST_GEN_FILES += tls_hw_offload TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c)) include ../../../lib.mk diff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config index c6c2b64bb71249..081155bf7847f2 100644 --- a/tools/testing/selftests/drivers/net/hw/config +++ b/tools/testing/selftests/drivers/net/hw/config @@ -22,6 +22,8 @@ CONFIG_NET_IPIP=y CONFIG_NETKIT=y CONFIG_NET_SCH_INGRESS=y CONFIG_SYNC_FILE=y +CONFIG_TLS=y +CONFIG_TLS_DEVICE=y CONFIG_UDMABUF=y CONFIG_USER_NS=y CONFIG_VLAN_8021Q=m diff --git a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.c b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.c new file mode 100644 index 00000000000000..5b3887f32b6897 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.c @@ -0,0 +1,908 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TLS Hardware Offload Two-Node Test + * + * Tests kTLS hardware offload between two physical nodes using + * hardcoded keys. Supports TLS 1.2 and AES-GCM-128/256. + * + * Both ends must run this helper: there is no handshake. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef SOL_TLS +#define SOL_TLS 282 +#endif + +#define TLS_RECORD_TYPE_HANDSHAKE 22 +#define TLS_RECORD_TYPE_ALERT 21 +#define TLS_RECORD_TYPE_DATA 23 + +#define MIN_BUF_SIZE 16 + +/* Initial key material */ +static struct tls12_crypto_info_aes_gcm_128 tls_info_key0_128 = { + .info = { + .version = TLS_1_2_VERSION, + .cipher_type = TLS_CIPHER_AES_GCM_128, + }, + .iv = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, + .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }, + .salt = { 0x01, 0x02, 0x03, 0x04 }, + .rec_seq = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +}; + +static struct tls12_crypto_info_aes_gcm_256 tls_info_key0_256 = { + .info = { + .version = TLS_1_2_VERSION, + .cipher_type = TLS_CIPHER_AES_GCM_256, + }, + .iv = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, + .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 }, + .salt = { 0x01, 0x02, 0x03, 0x04 }, + .rec_seq = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +}; + +static int test_record_type; +static int num_iterations = 100; +static int cipher_type = TLS_CIPHER_AES_GCM_128; +static int tls_version = TLS_1_2_VERSION; +static int server_port = 4433; +static char *server_ip; +/* Address family to force: AF_UNSPEC (any), AF_INET (-4), AF_INET6 (-6). */ +static int force_family = AF_UNSPEC; + +static int send_size = 16384; +static int random_size_max; +/* Per-iteration progress output (-V). Off by default: the + * harness runs the server in the background and captures its stdout in a + * pipe that is not drained until the server exits, so unbounded per-record + * chatter (thousands of lines for the large echo variants) would fill the + * pipe, block printf(), stall the echo loop and surface as a bogus recv + * timeout on the client. With -V off a run prints + * fixed setup/summary lines, comfortably inside a 64 KiB pipe. + */ +static int verbose; + +/* Upper bound on a helper's lifetime, enforced by SIGALRM. The harness + * waits for both helpers with the default 20s cmd()/bkg() timeout and + * cannot signal the one on the remote, so each must exit on its own first. + * A normal run takes a few seconds; the socket timeouts catch most stalls + * sooner and with a better error. + */ +#define HELPER_TIMEOUT_S 15 + +static const char *cipher_name(int cipher) +{ + switch (cipher) { + case TLS_CIPHER_AES_GCM_128: return "AES-GCM-128"; + case TLS_CIPHER_AES_GCM_256: return "AES-GCM-256"; + default: return "unknown"; + } +} + +static const char *version_name(int version) +{ + switch (version) { + case TLS_1_2_VERSION: return "TLS 1.2"; + default: return "unknown"; + } +} + +static int setup_tls_ulp(int fd) +{ + int ret; + + ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls")); + if (ret < 0) { + printf("SETUP ERROR: TCP_ULP failed: %s\n", strerror(errno)); + return -1; + } + return 0; +} + +/* Echo mode drives both directions from a single thread: the + * client pushes a whole payload with one blocking send() and only reads the + * echo afterwards, while the server blocks in send() mid-echo. If a payload + * exceeds the peer's receive window the two sides deadlock - client stuck in + * send(), server stuck echoing, neither draining the other. Size the socket + * buffers so a full payload always fits in the peer's window (the forward + * send() then completes without needing the peer to read concurrently); the + * send/recv timeouts armed by set_io_timeouts() turn any residual stall into a + * loud EAGAIN instead of a hang. + */ +static void configure_echo_socket(int fd, int payload) +{ + int want = payload; + + if (want < MIN_BUF_SIZE) + want = MIN_BUF_SIZE; + + /* SO_*BUFFORCE bypasses the rmem_max/wmem_max sysctl caps (needs + * CAP_NET_ADMIN); fall back to the best-effort, cap-limited option + * when unprivileged - the timeouts below still turn any resulting + * stall into a loud failure rather than a hang. + */ + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &want, sizeof(want)) < 0) + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &want, sizeof(want)); + if (setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &want, sizeof(want)) < 0) + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &want, sizeof(want)); +} + +/* Arm send/recv timeouts so any unexpected stall fails loudly with EAGAIN + * instead of running into HELPER_TIMEOUT_S. + */ +static void set_io_timeouts(int fd) +{ + struct timeval tv = { .tv_sec = 8, .tv_usec = 0 }; + + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); +} + +/* Send the whole buffer, looping over short counts. A blocking SOCK_STREAM + * send() may return fewer bytes than requested (e.g. when SO_SNDTIMEO fires + * after partial progress) without setting errno, so a short count is not an + * error - only a negative return is. + */ +static int send_all(int fd, const char *buf, ssize_t len) +{ + ssize_t sent = 0; + ssize_t ret; + + while (sent < len) { + ret = send(fd, buf + sent, len - sent, 0); + if (ret <= 0) { + /* 0 for a non-empty request would spin forever. */ + printf("FAIL: send failed: %s\n", + ret ? strerror(errno) : "no progress"); + return -1; + } + sent += ret; + } + return 0; +} + +static int recv_tls_message(int fd, char *buf, size_t buflen, int *record_type) +{ + char cmsg_buf[CMSG_SPACE(sizeof(unsigned char))]; + struct msghdr msg = {0}; + struct cmsghdr *cmsg; + struct iovec iov; + int ret; + + iov.iov_base = buf; + iov.iov_len = buflen; + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = cmsg_buf; + msg.msg_controllen = sizeof(cmsg_buf); + + ret = recvmsg(fd, &msg, 0); + if (ret <= 0) + return ret; + + cmsg = CMSG_FIRSTHDR(&msg); + if (cmsg && cmsg->cmsg_level == SOL_TLS && + cmsg->cmsg_type == TLS_GET_RECORD_TYPE) + *record_type = *((unsigned char *)CMSG_DATA(cmsg)); + + return ret; +} + +static int install_tls_key(int fd, int direction, int cipher) +{ + const char *dir = direction == TLS_TX ? "TX" : "RX"; + int ret; + + if (verbose) + printf("Installing TLS_%s %s...\n", dir, cipher_name(cipher)); + + if (cipher == TLS_CIPHER_AES_GCM_256) { + struct tls12_crypto_info_aes_gcm_256 key; + + memcpy(&key, &tls_info_key0_256, sizeof(key)); + key.info.version = tls_version; + ret = setsockopt(fd, SOL_TLS, direction, &key, sizeof(key)); + } else { + struct tls12_crypto_info_aes_gcm_128 key; + + memcpy(&key, &tls_info_key0_128, sizeof(key)); + key.info.version = tls_version; + ret = setsockopt(fd, SOL_TLS, direction, &key, sizeof(key)); + } + + if (ret < 0) { + printf("SETUP ERROR: TLS_%s %s failed: %s\n", + dir, cipher_name(cipher), strerror(errno)); + return -1; + } + printf("TLS_%s %s installed\n", dir, cipher_name(cipher)); + return 0; +} + +/* Open a TCP connection to server_ip:server_port, switch to the TLS + * ULP, and install initial TX/RX keys. Works over IPv4 or + * IPv6: getaddrinfo() resolves server_ip (honouring any -4/-6 forced + * family and %zone scope IDs in link-local addresses). Returns the fd on + * success, -1 on error (with the fd already closed). + */ +static int client_connect_tls(void) +{ + struct addrinfo hints = {0}, *res, *rp; + char port_str[16]; + int csk = -1; + int err = 0; + int ret; + + hints.ai_family = force_family; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + snprintf(port_str, sizeof(port_str), "%d", server_port); + + ret = getaddrinfo(server_ip, port_str, &hints, &res); + if (ret) { + printf("SETUP ERROR: getaddrinfo(%s): %s\n", server_ip, + gai_strerror(ret)); + return -1; + } + + printf("Connecting to %s:%d...\n", server_ip, server_port); + for (rp = res; rp; rp = rp->ai_next) { + csk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (csk < 0) { + err = errno; + continue; + } + if (connect(csk, rp->ai_addr, rp->ai_addrlen) == 0) + break; + err = errno; + close(csk); + csk = -1; + } + freeaddrinfo(res); + + if (csk < 0) { + printf("SETUP ERROR: connect to %s:%d failed: %s\n", + server_ip, server_port, strerror(err)); + return -1; + } + printf("Connected!\n"); + + if (setup_tls_ulp(csk) < 0) + goto err; + + if (install_tls_key(csk, TLS_TX, cipher_type) < 0 || + install_tls_key(csk, TLS_RX, cipher_type) < 0) + goto err; + + set_io_timeouts(csk); + configure_echo_socket(csk, random_size_max > 0 ? + random_size_max : send_size); + + return csk; +err: + close(csk); + return -1; +} + +/* Drain `len` echoed bytes from the server and verify they match the + * payload we just sent. + */ +static int client_recv_echo(int fd, const char *sent, char *echo_buf, + ssize_t len) +{ + ssize_t total = 0; + ssize_t n; + + while (total < len) { + n = recv(fd, echo_buf + total, len - total, 0); + if (n < 0) { + printf("FAIL: Echo recv failed: %s\n", strerror(errno)); + return -1; + } + if (n == 0) { + printf("FAIL: Connection closed during echo\n"); + return -1; + } + total += n; + } + + if (memcmp(sent, echo_buf, len) != 0) { + printf("FAIL: Echo data mismatch!\n"); + return -1; + } + if (verbose) + printf("Received echo %zd bytes (ok)\n", total); + return 0; +} + +static int do_client(void) +{ + char *buf = NULL, *echo_buf = NULL; + int max_size; + int csk = -1, i = 1; + int test_result = -1; + ssize_t n, total = 0; + + max_size = random_size_max > 0 ? random_size_max : send_size; + if (max_size < MIN_BUF_SIZE) + max_size = MIN_BUF_SIZE; + buf = malloc(max_size); + echo_buf = malloc(max_size); + if (!buf || !echo_buf) { + printf("SETUP ERROR: failed to allocate buffers\n"); + goto out; + } + + csk = client_connect_tls(); + if (csk < 0) + goto out; + + printf("TLS setup complete.\n"); + + if (random_size_max > 0) + printf("Sending %d messages of random size (1..%d bytes)...\n", + num_iterations, random_size_max); + else + printf("Sending %d messages of %d bytes...\n", + num_iterations, send_size); + + for (i = 1; i <= num_iterations; i++) { + int this_size; + int j; + + if (random_size_max > 0) + this_size = (rand() % random_size_max) + 1; + else + this_size = send_size; + + for (j = 0; j < this_size; j++) + buf[j] = rand() & 0xFF; + + if (send_all(csk, buf, this_size) < 0) + goto out; + n = this_size; + total += n; + + if (verbose) + printf("Sent %zd bytes (iteration %d)\n", n, i); + if (client_recv_echo(csk, buf, echo_buf, n) < 0) + goto out; + } + + test_result = 0; +out: + printf("Sent %d/%d iterations, %zd bytes\n", i - 1, num_iterations, + total); + if (csk >= 0) + close(csk); + free(buf); + free(echo_buf); + return test_result; +} + +/* Bind/listen on server_port, accept one client, switch to the TLS ULP + * and install initial keys. + * Returns the connected fd on success and writes the listener fd to + * *lsk_out so the caller can close it. Returns -1 on error, with all + * intermediate fds already closed and *lsk_out left at -1. + */ +static int server_accept_tls(int *lsk_out) +{ + struct addrinfo hints = {0}, *res, *rp; + int lsk = -1, csk, one = 1; + char port_str[16]; + int ret; + + *lsk_out = -1; + + /* AI_PASSIVE gives a wildcard bind address for the chosen family + * (0.0.0.0 / ::). The family is forced by -4/-6; when unspecified, + * bind the first entry that works. + */ + hints.ai_family = force_family; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + snprintf(port_str, sizeof(port_str), "%d", server_port); + + ret = getaddrinfo(NULL, port_str, &hints, &res); + if (ret) { + printf("SETUP ERROR: getaddrinfo(port %d): %s\n", server_port, + gai_strerror(ret)); + return -1; + } + + for (rp = res; rp; rp = rp->ai_next) { + lsk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (lsk < 0) + continue; + setsockopt(lsk, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + if (bind(lsk, rp->ai_addr, rp->ai_addrlen) == 0) + break; + close(lsk); + lsk = -1; + } + freeaddrinfo(res); + + if (lsk < 0) { + printf("SETUP ERROR: failed to bind port %d: %s\n", + server_port, strerror(errno)); + return -1; + } + + if (listen(lsk, 1) < 0) { + printf("SETUP ERROR: listen failed: %s\n", strerror(errno)); + close(lsk); + return -1; + } + + printf("Server listening on port %d\n", server_port); + printf("Waiting for client connection...\n"); + + /* Bound accept() so a client that never connects (a deploy or connect + * failure on the peer) does not block the server forever. accept() + * honours SO_RCVTIMEO on the listening socket; the client connects + * right after wait_port_listen(), so 10s is generous. + */ + { + struct timeval tv = { .tv_sec = 10, .tv_usec = 0 }; + + setsockopt(lsk, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + } + + csk = accept(lsk, NULL, NULL); + if (csk < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) + printf("SETUP ERROR: accept timed out, no client\n"); + else + printf("SETUP ERROR: accept failed: %s\n", + strerror(errno)); + close(lsk); + return -1; + } + printf("Client connected!\n"); + + if (setup_tls_ulp(csk) < 0) + goto err; + + if (install_tls_key(csk, TLS_TX, cipher_type) < 0 || + install_tls_key(csk, TLS_RX, cipher_type) < 0) + goto err; + + set_io_timeouts(csk); + configure_echo_socket(csk, random_size_max > 0 ? + random_size_max : send_size); + + *lsk_out = lsk; + return csk; +err: + close(csk); + close(lsk); + return -1; +} + +static int do_server(void) +{ + int lsk = -1, csk = -1; + ssize_t n, total = 0; + int test_result = -1; + int recv_count = 0; + char *buf = NULL; + int record_type = 0; + int buf_size; + + buf_size = send_size; + if (buf_size < MIN_BUF_SIZE) + buf_size = MIN_BUF_SIZE; + buf = malloc(buf_size); + if (!buf) { + printf("SETUP ERROR: failed to allocate buffer\n"); + goto out; + } + + csk = server_accept_tls(&lsk); + if (csk < 0) + goto out; + + printf("TLS %s setup complete. Receiving...\n", + cipher_name(cipher_type)); + + /* Echo everything back; the client verifies each echo. */ + while (1) { + record_type = 0; + n = recv_tls_message(csk, buf, buf_size, &record_type); + if (n == 0) { + printf("Connection closed by client\n"); + break; + } + if (n < 0) { + printf("FAIL: recv failed: %s\n", strerror(errno)); + goto out; + } + if (record_type != TLS_RECORD_TYPE_DATA) { + printf("FAIL: expected data record, got type %d\n", + record_type); + goto out; + } + + total += n; + recv_count++; + if (verbose) + printf("Received %zd bytes (total: %zd, count: %d)\n", + n, total, recv_count); + + if (send_all(csk, buf, n) < 0) + goto out; + if (verbose) + printf("Echoed %zd bytes back to client\n", n); + } + + test_result = 0; +out: + printf("Connection closed. Total received: %zd bytes in %d reads\n", + total, recv_count); + + if (csk >= 0) + close(csk); + if (lsk >= 0) + close(lsk); + free(buf); + return test_result; +} + +static int send_record_type(int fd) +{ + char control[CMSG_SPACE(sizeof(unsigned char))] = {}; + struct iovec iov = { .iov_base = "BBBB", .iov_len = 4 }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = control, + .msg_controllen = sizeof(control), + }; + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); + char ack[2]; + + if (send(fd, "AAAA", 4, MSG_MORE) != 4) { + printf("FAIL: send MSG_MORE failed: %s\n", strerror(errno)); + return -1; + } + cmsg->cmsg_level = SOL_TLS; + cmsg->cmsg_type = TLS_SET_RECORD_TYPE; + cmsg->cmsg_len = CMSG_LEN(sizeof(unsigned char)); + *CMSG_DATA(cmsg) = test_record_type; + if (sendmsg(fd, &msg, 0) != 4) { + printf("FAIL: sendmsg record type failed: %s\n", + strerror(errno)); + return -1; + } + return client_recv_echo(fd, "OK", ack, sizeof(ack)); +} + +static int expect_record(int fd, const char *data, unsigned char type) +{ + char control[CMSG_SPACE(sizeof(unsigned char))] = {}; + char buf[16]; + struct iovec iov = { .iov_base = buf, .iov_len = sizeof(buf) }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = control, + .msg_controllen = sizeof(control), + }; + struct cmsghdr *cmsg; + int ret; + + ret = recvmsg(fd, &msg, 0); + if (ret != 4 || memcmp(buf, data, 4) || + (msg.msg_flags & (MSG_CTRUNC | MSG_TRUNC)) || + !(msg.msg_flags & MSG_EOR)) { + printf("FAIL: expected record '%s', got %d bytes, flags %#x\n", + data, ret, msg.msg_flags); + return -1; + } + cmsg = CMSG_FIRSTHDR(&msg); + if (!cmsg || cmsg->cmsg_level != SOL_TLS || + cmsg->cmsg_type != TLS_GET_RECORD_TYPE || + cmsg->cmsg_len != CMSG_LEN(sizeof(unsigned char)) || + *CMSG_DATA(cmsg) != type) { + printf("FAIL: expected record type %u\n", type); + return -1; + } + return 0; +} + +static int recv_record_type(int fd) +{ + char buf[16]; + int ret; + + if (expect_record(fd, "AAAA", TLS_RECORD_TYPE_DATA) || + expect_record(fd, "BBBB", test_record_type) || + send_all(fd, "OK", 2)) + return -1; + ret = recv(fd, buf, sizeof(buf), 0); + if (ret) { + printf("FAIL: expected EOF after records, got %d\n", ret); + return -1; + } + return 0; +} + +static int test_pending_record(int is_server) +{ + char *buf = NULL, *echo_buf = NULL; + int lsk = -1, csk = -1; + int test_result = -1; + int i; + + buf = malloc(send_size); + echo_buf = malloc(send_size); + if (!buf || !echo_buf) { + printf("SETUP ERROR: failed to allocate buffers\n"); + goto out; + } + memset(buf, 0xa5, send_size); + + csk = is_server ? server_accept_tls(&lsk) : client_connect_tls(); + if (csk < 0) + goto out; + + /* Exercise the offload data path before the record-type transition. */ + for (i = 0; i < num_iterations; i++) { + if (!is_server && send_all(csk, buf, send_size) < 0) + goto out; + if (client_recv_echo(csk, buf, echo_buf, send_size) < 0) + goto out; + if (is_server && send_all(csk, buf, send_size) < 0) + goto out; + } + + test_result = is_server ? recv_record_type(csk) : send_record_type(csk); +out: + if (csk >= 0) + close(csk); + if (lsk >= 0) + close(lsk); + free(buf); + free(echo_buf); + return test_result; +} + +static int parse_int_arg(const char *arg, int min, int max, + const char *name, int *out) +{ + char *endp; + long val; + + errno = 0; + val = strtol(arg, &endp, 10); + if (errno || endp == arg || *endp != '\0' || val < min || val > max) { + if (max == INT_MAX) + printf("ERROR: Invalid %s '%s'. Must be >= %d.\n", + name, arg, min); + else + printf("ERROR: Invalid %s '%s'. Must be %d..%d.\n", + name, arg, min, max); + return -1; + } + *out = (int)val; + return 0; +} + +static int parse_cipher_option(const char *arg) +{ + if (strcmp(arg, "128") == 0) { + cipher_type = TLS_CIPHER_AES_GCM_128; + return 0; + } else if (strcmp(arg, "256") == 0) { + cipher_type = TLS_CIPHER_AES_GCM_256; + return 0; + } + printf("ERROR: Invalid cipher '%s'. Must be 128 or 256.\n", arg); + return -1; +} + +static int parse_version_option(const char *arg) +{ + if (strcmp(arg, "1.2") == 0) { + tls_version = TLS_1_2_VERSION; + return 0; + } + printf("ERROR: Invalid TLS version '%s'. Must be 1.2.\n", arg); + return -1; +} + +static void print_usage(const char *prog) +{ + printf("TLS Hardware Offload Two-Node Test\n\n"); + printf("Usage:\n"); + printf(" %s server [OPTIONS]\n", prog); + printf(" %s client -s [OPTIONS]\n", prog); + printf("\nOptions:\n"); + printf(" -s Server IPv4/IPv6 address (client, required)\n"); + printf(" -p Server port (default: 4433)\n"); + printf(" -4 Force IPv4 (default: auto/either)\n"); + printf(" -6 Force IPv6 (default: auto/either)\n"); + printf(" -b Send buffer size in bytes (default: 16384)\n"); + printf(" -r Use random send buffer sizes (1..)\n"); + printf(" -v TLS version: 1.2 (default: 1.2)\n"); + printf(" -c Cipher: 128 or 256 (default: 128)\n"); + printf(" -n Send/echo iterations (default: 100)\n"); + printf(" -t Record type test: 21=alert, 22=handshake\n"); + printf(" -V Verbose: log every iteration\n"); + printf(" -h Show this help message\n"); + printf("\nExample:\n"); + printf(" Node A: %s server\n", prog); + printf(" Node B: %s client -s 192.168.20.2\n", prog); + printf("\nIPv6 Example:\n"); + printf(" Node A: %s server -6\n", prog); + printf(" Node B: %s client -6 -s fd00::2\n", prog); +} + +int main(int argc, char *argv[]) +{ + int send_size_set = 0; + int is_server; + int opt; + + /* When the peer aborts a TLS connection (e.g. tls_err_abort() on a + * failed decrypt), a send() here would raise SIGPIPE and kill us by + * signal, so the harness sees only a bare non-zero exit with no + * "FAIL:" line. Ignore it and let send()/sendmsg() return EPIPE, which + * send_all()/send_record_type() report. + */ + signal(SIGPIPE, SIG_IGN); + + /* Line-buffer stdout so that output printed before a SIGALRM death + * is not lost in the stdio buffer. + */ + setvbuf(stdout, NULL, _IOLBF, 0); + alarm(HELPER_TIMEOUT_S); + + if (argc < 2 || + (strcmp(argv[1], "server") && strcmp(argv[1], "client"))) { + print_usage(argv[0]); + return 1; + } + is_server = !strcmp(argv[1], "server"); + + optind = 2; /* skip subcommand */ + while ((opt = getopt(argc, argv, "s:p:b:r:c:v:n:t:V46h")) != -1) { + switch (opt) { + case 's': + server_ip = optarg; + break; + case 'V': + verbose = 1; + break; + case '4': + if (force_family == AF_INET6) { + printf("ERROR: -4 and -6 are exclusive\n"); + return 1; + } + force_family = AF_INET; + break; + case '6': + if (force_family == AF_INET) { + printf("ERROR: -4 and -6 are exclusive\n"); + return 1; + } + force_family = AF_INET6; + break; + case 'p': + if (parse_int_arg(optarg, 1, 65535, "port", + &server_port) < 0) + return 1; + break; + case 'b': + if (parse_int_arg(optarg, 1, INT_MAX, "buffer size", + &send_size) < 0) + return 1; + send_size_set = 1; + break; + case 'r': + if (parse_int_arg(optarg, 1, INT_MAX, "random size", + &random_size_max) < 0) + return 1; + break; + case 'c': + if (parse_cipher_option(optarg) < 0) + return 1; + break; + case 'v': + if (parse_version_option(optarg) < 0) + return 1; + break; + case 't': + if (parse_int_arg(optarg, TLS_RECORD_TYPE_ALERT, + TLS_RECORD_TYPE_HANDSHAKE, + "record type", &test_record_type) < 0) + return 1; + break; + case 'n': + /* do_client() counts i = 1..num_iterations with an + * inclusive int bound, so INT_MAX itself would + * overflow the counter instead of terminating. + */ + if (parse_int_arg(optarg, 1, INT_MAX - 1, + "iteration count", + &num_iterations) < 0) + return 1; + break; + case 'h': + print_usage(argv[0]); + return 0; + default: + print_usage(argv[0]); + return 1; + } + } + + if (send_size_set && random_size_max > 0) { + printf("ERROR: -b and -r are mutually exclusive\n"); + return 1; + } + + if (test_record_type && random_size_max) { + printf("ERROR: -t cannot be combined with -r\n"); + return 1; + } + + if (is_server) { + if (server_ip) { + printf("warning: -s is ignored in server mode\n"); + server_ip = NULL; + } + if (random_size_max > 0) { + printf("warning: -r is ignored in server mode\n"); + random_size_max = 0; + } + } else { + if (!server_ip) { + printf("ERROR: Client requires -s option\n"); + return 1; + } + } + + printf("TLS Version: %s\n", version_name(tls_version)); + printf("Cipher: %s\n", cipher_name(cipher_type)); + printf("Address family: %s\n", + force_family == AF_INET ? "IPv4" : + force_family == AF_INET6 ? "IPv6" : "auto"); + if (random_size_max > 0) + printf("Buffer size: random (1..%d)\n", random_size_max); + else + printf("Buffer size: %d\n", send_size); + + srand(time(NULL)); + + if (test_record_type) + return test_pending_record(is_server) ? 1 : 0; + + if (is_server) + return do_server() ? 1 : 0; + + return do_client() ? 1 : 0; +} diff --git a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py new file mode 100755 index 00000000000000..e720ce65476108 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py @@ -0,0 +1,321 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Test kTLS hardware offload using a C helper binary.""" + +from collections import defaultdict + +from lib.py import ( + CmdExitFailure, + KsftNamedVariant, + KsftSkipEx, + NetDrvEpEnv, + bkg, + cmd, + ksft_eq, + ksft_exit, + ksft_ge, + ksft_pr, + ksft_run, + ksft_variants, + rand_port, + wait_port_listen, +) + +# `ethtool -S` counters on the DUT NIC, from the minimum set every TLS +# offload driver should report (Documentation/networking/tls-offload.rst, +# "Statistics"). Drivers expose varying subsets: mlx5 has all four, nfp +# both *_packets but no *_tls_ctx, cxgb4 and funeth only the two tx_ +# counters. Each counter is checked only when present. +# TlsTxDevice/TlsRxDevice in /proc/net/tls_stat only prove tls_dev_add() +# accepted the offload: +# - tx_tls_encrypted_packets counts TX packets passed to the device for +# encryption. Drivers bump it while building the descriptor, not on +# completion, so it shows the driver used the offload path, not that +# the NIC encrypted anything; a broken HW encrypt shows up instead as a +# peer TlsDecryptError or an echo mismatch. +# - rx_tls_decrypted_packets counts RX packets the NIC successfully +# decrypted. +# - Both *_packets count packets (mlx5 counts gso_segs), not records. +# - *_ctx increment once per tls_dev_add(). +# Missing NIC crypto counters remain optional. +HW_NIC_COUNTERS = { + 'Tx': {'crypto': 'tx_tls_encrypted_packets', 'ctx': 'tx_tls_ctx'}, + 'Rx': {'crypto': 'rx_tls_decrypted_packets', 'ctx': 'rx_tls_ctx'}, +} + + +def check_tls_support(cfg): + """Require kTLS on both hosts and at least one DUT HW direction.""" + # The tls module is autoloaded lazily on the first TCP_ULP="tls" + # setsockopt, so /proc/net/tls_stat (created from the module's pernet + # init) may not exist yet on a freshly booted host. Load the module + # explicitly before probing for it. Best effort only: with CONFIG_TLS=y + # (what the config fragment asks for) there is nothing to load, and + # modprobe may fail for reasons unrelated to kTLS (no modules.dep for a + # locally built kernel, no modprobe on a minimal rootfs). The + # /proc/net/tls_stat probe below is the authoritative check. Locally, + # cmd() runs without a shell, so a missing modprobe raises + # FileNotFoundError rather than returning a failed exit status. + try: + cmd("modprobe tls", fail=False) + except FileNotFoundError: + pass + cmd("modprobe tls", host=cfg.remote, fail=False) + try: + cmd("test -f /proc/net/tls_stat") + cmd("test -f /proc/net/tls_stat", host=cfg.remote) + except CmdExitFailure as e: + raise KsftSkipEx(f"kTLS not supported: {e}") from e + + try: + features = cmd(f"ethtool -k {cfg.ifname}").stdout + except CmdExitFailure as e: + raise KsftSkipEx(f"Cannot determine TLS HW offload support: {e}") from e + cfg.tls_hw_directions = { + direction for direction in ('Tx', 'Rx') + if f'tls-hw-{direction.lower()}-offload: on' in features + } + if not cfg.tls_hw_directions: + raise KsftSkipEx("Device has no enabled TLS HW offload direction") + + +def require_tls_setup(cfg): + """Deploy the helper and probe kTLS support once, on first use. + + This runs from within the test cases rather than main(): ksft_run() + turns KsftSkipEx into a SKIP result only for an exception raised by a + case, so a skip raised from main() would be reported as a failure. + The outcome is cached so later cases skip with the same reason. + """ + if cfg.tls_skip_reason: + raise KsftSkipEx(cfg.tls_skip_reason) + if cfg.bin_remote: + return + try: + check_tls_support(cfg) + except KsftSkipEx as e: + cfg.tls_skip_reason = str(e) + raise + cfg.bin_remote = cfg.remote.deploy(cfg.bin_local) + + +def read_tls_stats(host=None): + """Snapshot the per-netns TLS MIB from /proc/net/tls_stat as a dict.""" + # /proc/net/tls_stat exposes the per-netns TLS MIB (TLS_INC_STATS on + # sock_net(sk)). The test runs on a real NIC in the host namespace, so + # these counters are shared with anything else doing kTLS there. The + # strict before/after delta checks (zero error counters) assume no other + # kTLS activity in this namespace during a + # variant's window; concurrent kTLS users would perturb the deltas and + # cause spurious failures. Don't run other kTLS workloads alongside this + # test. + stats = defaultdict(int) + output = cmd("cat /proc/net/tls_stat", host=host) + for line in output.stdout.strip().split('\n'): + parts = line.split() + if len(parts) == 2: + stats[parts[0]] = int(parts[1]) + return stats + + +def read_nic_stats(cfg): + """Snapshot the DUT NIC's `ethtool -S` counters as a dict.""" + # Driver per-record TLS counters from `ethtool -S` on the DUT NIC. Same + # before/after-delta caveat as read_tls_stats(): these are device-wide, + # so concurrent kTLS traffic on this NIC would perturb the deltas. + stats = defaultdict(int) + output = cmd(f"ethtool -S {cfg.ifname}").stdout + for line in output.strip().split('\n'): + key, sep, val = line.partition(':') + if sep and val.strip().isdigit(): + stats[key.strip()] = int(val.strip()) + return stats + + +def stat_diff(before, after, key): + """Return the delta of counter `key` between two stat snapshots.""" + return after[key] - before[key] + + +def check_hw_crypto(cfg, nic_before, nic_after, hw_directions): + """Check DUT NIC offload-path packet counts and initial key installs.""" + for direction in hw_directions: + names = HW_NIC_COUNTERS[direction] + + key = names['crypto'] + if key in nic_after: + got = stat_diff(nic_before, nic_after, key) + ksft_ge(got, 1, + comment=f"DUT {direction}: NIC reported no TLS " + f"offload packets ({key}={got})") + else: + ksft_pr(f"NOTE: DUT {direction}: '{key}' not exposed by " + f"{cfg.ifname}, skipping NIC packet count check") + + key = names['ctx'] + if key not in nic_after: + ksft_pr(f"NOTE: DUT {direction}: '{key}' not exposed by " + f"{cfg.ifname}, skipping NIC context count check") + continue + ctx = stat_diff(nic_before, nic_after, key) + ksft_ge(ctx, 1, + comment=f"DUT {direction}: no HW context installed " + f"({key}={ctx})") + + +def check_path(before, after, direction, role, require_hw): + """Require HW for enabled DUT directions; otherwise HW or SW is fine.""" + dev = stat_diff(before, after, f'Tls{direction}Device') + sw = stat_diff(before, after, f'Tls{direction}Sw') + if require_hw: + ksft_ge(dev, 1, + comment=f"{role} {direction}: HW offload not engaged " + f"(Device={dev}, Sw={sw})") + else: + ksft_ge(dev + sw, 1, + comment=f"{role} {direction}: no TLS activity " + f"(Device={dev}, Sw={sw})") + + +def verify_tls_counters(stats_before, stats_after, is_dut, hw_directions=()): + """Verify TLS counters on one side of the connection. + + is_dut: True for the local DUT. + hw_directions: DUT directions with enabled HW offload; other directions + may use SW kTLS but still undergo activity and error checks. + """ + role = 'DUT' if is_dut else 'Peer' + + # Echo mode drives both directions on both sides. + for direction in ('Tx', 'Rx'): + check_path(stats_before, stats_after, direction, role, + require_hw=is_dut and direction in hw_directions) + + ksft_eq(stat_diff(stats_before, stats_after, 'TlsDecryptError'), 0, + comment=f"{role}: TlsDecryptError expected 0") + + +def run_tls_test(cfg, cipher="128", tls_version="1.2", + buffer_size=None, random_max=None, ipver="4", + record_type=None): + """Run the TLS offload test. + + The DUT runs the TLS client and the remote runs the echo server. + + ipver: '4' or '6' - IP version to run over. The C helper is forced to the + matching family with -4/-6 and connects to the peer's v4/v6 address. + Variants requesting '6' skip cleanly when the environment lacks IPv6 + connectivity (require_ipver()). + + The DUT (local) is the kernel under test; the remote is just a traffic + source/sink and may run any kernel without HW offload. Both sides run + kTLS because TLS is pairwise, but verify_tls_counters() requires HW + offload only in enabled DUT directions. The peer and the DUT's other + direction may use SW kTLS. + """ + require_tls_setup(cfg) + + cfg.require_ipver(ipver) + + # Echo exercises both directions, allowing SW in a direction without + # HW support. + hw_directions = tuple(d for d in ('Tx', 'Rx') if d in cfg.tls_hw_directions) + + if record_type and 'Tx' not in hw_directions: + raise KsftSkipEx("Record-type regression requires DUT TLS TX offload") + + port = rand_port() + send_size = random_max or buffer_size + + server_parts = [f"{cfg.bin_remote} server -p {port} -c {cipher}", + f"-v {tls_version}", f"-{ipver}"] + if send_size: + server_parts.append(f"-b {send_size}") + if record_type: + server_parts.append(f"-t {record_type}") + server_cmd = " ".join(server_parts) + + client_parts = [f"{cfg.bin_local} client -s {cfg.remote_addr_v[ipver]}", + f"-p {port} -c {cipher} -v {tls_version} -{ipver}"] + if random_max: + client_parts.append(f"-r {random_max}") + elif buffer_size: + client_parts.append(f"-b {buffer_size}") + if record_type: + client_parts.append(f"-t {record_type}") + client_cmd = " ".join(client_parts) + + stats_before_local = read_tls_stats() + stats_before_remote = read_tls_stats(host=cfg.remote) + nic_before = read_nic_stats(cfg) + + # The remote server runs under bkg(), whose stdout pipe is only drained + # once it exits, so the helper keeps its per-connection output small + # (see the note on verbose in tls_hw_offload.c); do not pass -V. + # + # Both helpers exit on their own within HELPER_TIMEOUT_S (see + # tls_hw_offload.c), so nothing outlives the variant even on failure. + with bkg(server_cmd, host=cfg.remote, exit_wait=True): + wait_port_listen(port, host=cfg.remote) + cmd(client_cmd) + + cfg.wait_hw_stats_settle() + stats_after_local = read_tls_stats() + stats_after_remote = read_tls_stats(host=cfg.remote) + nic_after = read_nic_stats(cfg) + + verify_tls_counters(stats_before_local, stats_after_local, is_dut=True, + hw_directions=hw_directions) + check_hw_crypto(cfg, nic_before, nic_after, hw_directions) + verify_tls_counters(stats_before_remote, stats_after_remote, is_dut=False) + + +# The cipher/version matrix runs over IPv4; the socket setup is the only +# IP-version-specific code path, so a single representative variant over +# IPv6 is enough to cover it (it skips cleanly without v6 connectivity). +# The suites below likewise stay on IPv4 to bound runtime. +@ksft_variants([ + KsftNamedVariant("tls12_aes128", "128", "1.2", "4"), + KsftNamedVariant("tls12_aes256", "256", "1.2", "4"), + KsftNamedVariant("tls12_aes128_ip6", "128", "1.2", "6"), +]) +def test_tls_offload(cfg, cipher, tls_version, ipver): + """Cipher/version matrix over the HW offload data path.""" + run_tls_test(cfg, cipher=cipher, tls_version=tls_version, ipver=ipver) + + +@ksft_variants([ + KsftNamedVariant("small_buf", 512), + KsftNamedVariant("large_buf", 2097152), + KsftNamedVariant("random_buf", None, 8192), +]) +def test_tls_offload_sizes(cfg, buffer_size=None, random_max=None): + """Echo-mode TLS 1.2 across a range of buffer sizes.""" + run_tls_test(cfg, cipher="128", tls_version="1.2", + buffer_size=buffer_size, random_max=random_max) + + +@ksft_variants([ + KsftNamedVariant("handshake", 22), + KsftNamedVariant("alert", 21), +]) +def test_tls_offload_record_type(cfg, record_type): + """RX setup must preserve the HW TX hook which flushes an open record.""" + run_tls_test(cfg, record_type=record_type) + + +def main() -> None: + """Set up the DUT/peer environment and run the offload test suites.""" + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + cfg.bin_local = cfg.test_dir / "tls_hw_offload" + cfg.bin_remote = None + cfg.tls_skip_reason = None + + ksft_run([test_tls_offload, test_tls_offload_sizes, + test_tls_offload_record_type], args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/drivers/net/ping.py b/tools/testing/selftests/drivers/net/ping.py index da3623c5e8a95d..a0de9a98d9068d 100755 --- a/tools/testing/selftests/drivers/net/ping.py +++ b/tools/testing/selftests/drivers/net/ping.py @@ -7,7 +7,7 @@ from lib.py import ksft_eq, KsftSkipEx, KsftFailEx from lib.py import EthtoolFamily, NetDrvEpEnv from lib.py import bkg, cmd, wait_port_listen, rand_port -from lib.py import defer, ethtool, ip +from lib.py import bpf_map_set, defer, ethtool, ip no_sleep=False @@ -75,16 +75,23 @@ def _set_xdp_generic_sb_on(cfg) -> None: if no_sleep != True: time.sleep(10) -def _set_xdp_generic_mb_on(cfg) -> None: - prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" +def _set_xdp_generic_mb_on(cfg, prog="xdp_dummy.bpf.o", on_attach=None) -> None: + prog = cfg.net_lib_dir / prog cmd(f"ip link set dev {cfg.remote_ifname} mtu 9000", shell=True, host=cfg.remote) defer(ip, f"link set dev {cfg.remote_ifname} mtu 1500", host=cfg.remote) ip("link set dev %s mtu 9000 xdpgeneric obj %s sec xdp.frags" % (cfg.ifname, prog)) defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdpgeneric off") + if on_attach: + on_attach() if no_sleep != True: time.sleep(10) +def _set_xdp_generic_cpumap_mb_on(cfg) -> None: + cfg.require_cmd("bpftool") + _set_xdp_generic_mb_on(cfg, "xdp_cpumap.bpf.o", + on_attach=lambda: bpf_map_set("map_cpumap", 0, 2048)) + def _set_xdp_native_sb_on(cfg) -> None: prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) @@ -192,6 +199,19 @@ def test_xdp_generic_mb(cfg, netnl) -> None: _test_v6(cfg) _test_tcp(cfg) +def test_xdp_generic_cpumap_mb(cfg, netnl) -> None: + """Redirect all packets to a cpumap from a generic xdp.frags program.""" + _schedule_checksum_reset(cfg, netnl) + _set_xdp_generic_cpumap_mb_on(cfg) + _set_offload_checksum(cfg, netnl, "off") + _test_v4(cfg) + _test_v6(cfg) + _test_tcp(cfg) + _set_offload_checksum(cfg, netnl, "on") + _test_v4(cfg) + _test_v6(cfg) + _test_tcp(cfg) + def test_xdp_native_sb(cfg, netnl) -> None: _schedule_checksum_reset(cfg, netnl) _set_xdp_native_sb_on(cfg) @@ -230,6 +250,7 @@ def main() -> None: test_default_v6, test_xdp_generic_sb, test_xdp_generic_mb, + test_xdp_generic_cpumap_mb, test_xdp_native_sb, test_xdp_native_mb, test_xdp_offload], diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py index 473500901879b0..c114d2245135bb 100755 --- a/tools/testing/selftests/drivers/net/psp.py +++ b/tools/testing/selftests/drivers/net/psp.py @@ -120,6 +120,26 @@ def _check_data_rx(cfg, exp_len): ksft_eq(read_len, exp_len) +def _recv_careful(s, target, timeout=2): + """Read exactly target bytes, tolerating short reads""" + data = b'' + end = time.monotonic() + timeout + while time.monotonic() < end: + try: + data += s.recv(target - len(data), socket.MSG_DONTWAIT) + if len(data) == target: + return data + except BlockingIOError: + time.sleep(0.001) + raise KsftFailEx(f"short read, got {len(data)} of {target} bytes") + + +def _req_echo(cfg, s): + """Ask the peer to echo, and check the reply arrives intact""" + _send_with_ack(cfg, b'data echo\0') + ksft_eq(_recv_careful(s, 5), b'echo\0') + + def _check_data_outq(s, exp_len, force_wait=False): outq = 0 for _ in range(10): @@ -478,6 +498,7 @@ def _data_basic_send(cfg, version, ipver): data_len = _send_careful(cfg, s, 100) _check_data_rx(cfg, data_len) + _req_echo(cfg, s) _close_psp_conn(cfg, s) @@ -726,6 +747,7 @@ def _data_basic_send_netkit_psp_assoc(cfg, version, ipver): data_len = _send_careful(cfg, sock, 100) _check_data_rx(cfg, data_len) + _req_echo(cfg, sock) _close_psp_conn(cfg, sock) diff --git a/tools/testing/selftests/fchmodat2/Makefile b/tools/testing/selftests/fchmodat2/Makefile index 4373cea79b7941..21f6b0b0cdc8f8 100644 --- a/tools/testing/selftests/fchmodat2/Makefile +++ b/tools/testing/selftests/fchmodat2/Makefile @@ -1,15 +1,23 @@ # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined $(KHDR_INCLUDES) +CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) + +TEST_GEN_PROGS := fchmodat2_test + +include ../lib.mk # gcc requires -static-libasan in order to ensure that Address Sanitizer's # library is the first one loaded. However, clang already statically links the # Address Sanitizer if -fsanitize is specified. Therefore, simply omit # -static-libasan for clang builds. +SANITIZER_CFLAGS := -fsanitize=address -fsanitize=undefined ifeq ($(LLVM),) - CFLAGS += -static-libasan + SANITIZER_CFLAGS += -static-libasan endif -TEST_GEN_PROGS := fchmodat2_test - -include ../lib.mk +# Build without the sanitizers when the toolchain cannot link them. +ifeq ($(shell echo 'int main(void) { return 0; }' | $(CC) $(CFLAGS) \ + $(SANITIZER_CFLAGS) $(LDFLAGS) -x c - -o /dev/null >/dev/null 2>&1 && \ + echo y),y) +CFLAGS += $(SANITIZER_CFLAGS) +endif diff --git a/tools/testing/selftests/filesystems/configfs/configfs_test.c b/tools/testing/selftests/filesystems/configfs/configfs_test.c index c6a1049e5852e5..94ae8f71030926 100644 --- a/tools/testing/selftests/filesystems/configfs/configfs_test.c +++ b/tools/testing/selftests/filesystems/configfs/configfs_test.c @@ -122,7 +122,7 @@ FIXTURE_SETUP(configfs) ASSERT_EQ(unshare(CLONE_NEWNS), 0); ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); - ASSERT_NE(mkdtemp(tmpl), NULL); + ASSERT_TRUE(mkdtemp(tmpl) != NULL); strcpy(self->mnt, tmpl); ASSERT_EQ(mount("configfs", self->mnt, "configfs", 0, NULL), 0); diff --git a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh index d61264d4795d7f..0712c8d23fd7ef 100755 --- a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh +++ b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh @@ -15,6 +15,8 @@ BASE_DIR="$(dirname $0)" TMP_DIR="$(mktemp -d /tmp/fat_tests_tmp.XXXXXX)" IMG_PATH="${TMP_DIR}/fat.img" MNT_PATH="${TMP_DIR}/mnt" +# Kselftest framework requirement - SKIP code is 4. +ksft_skip=4 cleanup() { @@ -23,6 +25,17 @@ cleanup() } trap cleanup SIGINT SIGTERM EXIT +check_prereqs() +{ + local msg="skip all tests:" + local uid=$(id -u) + + if [ $uid -ne 0 ]; then + echo $msg must be run as root >&2 + exit $ksft_skip + fi +} + create_loopback() { touch "${IMG_PATH}" @@ -73,6 +86,7 @@ unmount_image() sudo umount "${MNT_PATH}" &> /dev/null } +check_prereqs create_loopback mount_image rename_exchange_test diff --git a/tools/testing/selftests/filesystems/fscontext_ns/fscontext_ns_test.c b/tools/testing/selftests/filesystems/fscontext_ns/fscontext_ns_test.c index 0f30a3e6e197d7..535bf1f4e1a308 100644 --- a/tools/testing/selftests/filesystems/fscontext_ns/fscontext_ns_test.c +++ b/tools/testing/selftests/filesystems/fscontext_ns/fscontext_ns_test.c @@ -193,7 +193,7 @@ FIXTURE_VARIANT_ADD(fscontext_ns, binfmt_misc) { FIXTURE_VARIANT_ADD(fscontext_ns, overlay) { .fsname = "overlay", - .expected_errno = EIO, + .expected_errno = EINVAL, }; TEST_F(fscontext_ns, create_from_descendant_userns) diff --git a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c index 6381af6a40e305..6c95c275b16292 100644 --- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c @@ -337,18 +337,18 @@ TEST_F(fanotify, fsmount) fs = fsopen("tmpfs", 0); ASSERT_GE(fs, 0); - ret = fsconfig(fs, FSCONFIG_CMD_CREATE, 0, 0, 0); + ret = fsconfig(fs, FSCONFIG_CMD_CREATE, 0, 0, 0); ASSERT_EQ(ret, 0); - mnt = fsmount(fs, 0, 0); + mnt = fsmount(fs, 0, 0); ASSERT_GE(mnt, 0); - close(fs); + close(fs); ret = move_mount(mnt, "", AT_FDCWD, "/a", MOVE_MOUNT_F_EMPTY_PATH); ASSERT_EQ(ret, 0); - close(mnt); + close(mnt); mnts[1] = expect_notify_mask(_metadata, self, FAN_MNT_ATTACH); ASSERT_NE(mnts[0], mnts[1]); diff --git a/tools/testing/selftests/filesystems/openat2/Makefile b/tools/testing/selftests/filesystems/openat2/Makefile index d848aac96bded5..2f712dfcbf75c4 100644 --- a/tools/testing/selftests/filesystems/openat2/Makefile +++ b/tools/testing/selftests/filesystems/openat2/Makefile @@ -1,17 +1,25 @@ # SPDX-License-Identifier: GPL-2.0-or-later CFLAGS += $(KHDR_INCLUDES) -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined $(TOOLS_INCLUDES) +CFLAGS += -Wall -O2 -g $(TOOLS_INCLUDES) TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test emptypath_test +LOCAL_HDRS += helpers.h + +include ../../lib.mk + # gcc requires -static-libasan in order to ensure that Address Sanitizer's # library is the first one loaded. However, clang already statically links the # Address Sanitizer if -fsanitize is specified. Therefore, simply omit # -static-libasan for clang builds. +SANITIZER_CFLAGS := -fsanitize=address -fsanitize=undefined ifeq ($(LLVM),) - CFLAGS += -static-libasan + SANITIZER_CFLAGS += -static-libasan endif -LOCAL_HDRS += helpers.h - -include ../../lib.mk +# Build without the sanitizers when the toolchain cannot link them. +ifeq ($(shell echo 'int main(void) { return 0; }' | $(CC) $(CFLAGS) \ + $(SANITIZER_CFLAGS) $(LDFLAGS) -x c - -o /dev/null >/dev/null 2>&1 && \ + echo y),y) +CFLAGS += $(SANITIZER_CFLAGS) +endif diff --git a/tools/testing/selftests/filesystems/overlayfs/idmapped_mounts.c b/tools/testing/selftests/filesystems/overlayfs/idmapped_mounts.c index 44a75839f4ed4b..5df42cf3e68837 100644 --- a/tools/testing/selftests/filesystems/overlayfs/idmapped_mounts.c +++ b/tools/testing/selftests/filesystems/overlayfs/idmapped_mounts.c @@ -498,4 +498,49 @@ TEST_F(idmapped_overlay, nfs_export_handles) EXPECT_EQ(close(ovl), 0); } +/* With index=on, same-superblock lower layers must not use different idmaps. */ +TEST_F(idmapped_overlay, reject_same_sb_mixed_idmaps) +{ + char lower1[PATH_MAX], lower2[PATH_MAX]; + char upper[PATH_MAX], work[PATH_MAX]; + int fd_lower1, fd_lower2, fsfd; + + if (!ovl_supported()) + SKIP(return, "overlayfs not supported"); + + snprintf(lower1, sizeof(lower1), "%s/l", self->base); + snprintf(lower2, sizeof(lower2), "%s/l2", self->base); + snprintf(upper, sizeof(upper), "%s/u", self->base); + snprintf(work, sizeof(work), "%s/w", self->base); + ASSERT_EQ(mkdir(lower2, 0755), 0); + ASSERT_EQ(chown(lower2, ID_HOST, ID_HOST), 0); + + fd_lower1 = idmapped_layer_fd(lower1, ID_HOST, ID_NS, ID_RANGE); + ASSERT_GE(fd_lower1, 0); + fd_lower2 = sys_open_tree(AT_FDCWD, lower2, + OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); + ASSERT_GE(fd_lower2, 0); + fsfd = sys_fsopen("overlay", 0); + ASSERT_GE(fsfd, 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, + "source", "test", 0), 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, + "upperdir", upper, 0), 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, + "workdir", work, 0), 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, + "index", "on", 0), 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_FD, + "lowerdir+", NULL, fd_lower1), 0); + ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_FD, + "lowerdir+", NULL, fd_lower2), 0); + + errno = 0; + EXPECT_EQ(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), -1); + EXPECT_EQ(errno, EINVAL); + EXPECT_EQ(close(fd_lower1), 0); + EXPECT_EQ(close(fd_lower2), 0); + EXPECT_EQ(close(fsfd), 0); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c index b237a95ec9fb32..8133a5841ac08c 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c @@ -335,10 +335,10 @@ static void test_statmount_sb_basic(void) return; } - if (sm.sb_magic != sf.f_type) { + if (sm.sb_magic != (unsigned long)sf.f_type) { ksft_test_result_fail("unexpected sb magic: 0x%llx != 0x%lx\n", (unsigned long long) sm.sb_magic, - sf.f_type); + (unsigned long) sf.f_type); return; } diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c index e500905e4c078f..c9ef755ffaa725 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +++ b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c @@ -240,8 +240,9 @@ static int validate_external_listmount(pid_t pid, uint64_t child_nr_mounts) } if (nr_mounts != child_nr_mounts) { - ksft_print_msg("listmount results is %zi != %zi\n", nr_mounts, - child_nr_mounts); + ksft_print_msg("listmount results is %llu != %llu\n", + (unsigned long long)nr_mounts, + (unsigned long long)child_nr_mounts); return NSID_FAIL; } diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc index 384209968325e0..70751573e8de5a 100644 --- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc @@ -33,7 +33,7 @@ check_error 'f vfs_read ^$stack10000' # BAD_STACK_NUM check_error 'f vfs_read ^$arg10000' # BAD_ARG_NUM -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'f vfs_read $retval ^$arg1' # BAD_VAR fi check_error 'f vfs_read ^$none_var' # BAD_VAR @@ -100,7 +100,7 @@ if grep -q "" README; then check_error 'f vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'f vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'f vfs_read $arg* ^$arg*' # DOUBLE_ARGS -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'f vfs_read%return ^$arg*' # NOFENTRY_ARGS fi check_error 'f vfs_read ^hoge' # NO_BTFARG diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc index 03eb9e70b4381a..f8e18ea8c268f0 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc @@ -6,7 +6,7 @@ SYMBOL='init_once' # We skip this test on kernel where SYMBOL is unique or does not exist. -if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then +if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}\$" /proc/kallsyms)" -le '1' ]; then exit_unsupported fi diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc index b0e6b80ccb01fd..06efa67e01ff42 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc @@ -108,7 +108,7 @@ if grep -q "" README; then check_error 'p vfs_read args=^$arg*' # BAD_VAR_ARGS check_error 'p vfs_read +0(^$arg*)' # BAD_VAR_ARGS check_error 'p vfs_read $arg* ^$arg*' # DOUBLE_ARGS -if !grep -q 'kernel return probes support:' README; then +if ! grep -q 'kernel return probes support:' README; then check_error 'r vfs_read ^$arg*' # NOFENTRY_ARGS fi check_error 'p vfs_read+20 ^$arg*' # NOFENTRY_ARGS diff --git a/tools/testing/selftests/landlock/ns_test.c b/tools/testing/selftests/landlock/ns_test.c index f5d4b86edd3030..8f387fc47e2171 100644 --- a/tools/testing/selftests/landlock/ns_test.c +++ b/tools/testing/selftests/landlock/ns_test.c @@ -1899,8 +1899,9 @@ TEST(setns_inherited_fd) static int matches_log_ns_create(int audit_fd, __u64 ns_type) { + /* A denied creation logs the ID allocated for the new namespace. */ static const char log_template[] = REGEX_LANDLOCK_PREFIX - " blockers=namespace\\.use namespace_type=0x%x namespace_id=0$"; + " blockers=namespace\\.use namespace_type=0x%x namespace_id=[1-9][0-9]*$"; char log_match[sizeof(log_template) + 10]; int log_match_len; @@ -2538,7 +2539,9 @@ static void test_ns_trace_denial(struct __test_metadata *const _metadata, ASSERT_EQ(0, tracefs_extract_field( buf, REGEX_DENY_PERMISSION_NAMESPACE(TRACE_TASK), "namespace_id", field, sizeof(field))); - EXPECT_EQ(use_setns ? expected_ns_id : 0, strtoull(field, NULL, 10)); + EXPECT_STRNE("0", field); + if (use_setns) + EXPECT_EQ(expected_ns_id, strtoull(field, NULL, 10)); free(buf); } diff --git a/tools/testing/selftests/mm/khugepaged_race.c b/tools/testing/selftests/mm/khugepaged_race.c index abb0678522cd9f..1a27cb39745b8f 100644 --- a/tools/testing/selftests/mm/khugepaged_race.c +++ b/tools/testing/selftests/mm/khugepaged_race.c @@ -8,6 +8,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include diff --git a/tools/testing/selftests/mm/merge.c b/tools/testing/selftests/mm/merge.c index 7dd2933417c1d6..6def490186a9ce 100644 --- a/tools/testing/selftests/mm/merge.c +++ b/tools/testing/selftests/mm/merge.c @@ -22,9 +22,12 @@ FIXTURE(merge) struct procmap_fd procmap; }; +#define FAR_PAGES 30 +#define CARVEOUT_PAGES (3 * FAR_PAGES) + static char *map_carveout(unsigned int page_size) { - return mmap(NULL, 30 * page_size, PROT_NONE, + return mmap(NULL, CARVEOUT_PAGES * page_size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); } @@ -73,7 +76,7 @@ FIXTURE_SETUP(merge) FIXTURE_TEARDOWN(merge) { - ASSERT_EQ(munmap(self->carveout, 30 * self->page_size), 0); + ASSERT_EQ(munmap(self->carveout, CARVEOUT_PAGES * self->page_size), 0); /* May fail for parent of forked process. */ close_procmap(&self->procmap); /* @@ -115,7 +118,7 @@ FIXTURE_SETUP(merge_with_fork) FIXTURE_TEARDOWN(merge_with_fork) { - ASSERT_EQ(munmap(self->carveout, 30 * self->page_size), 0); + ASSERT_EQ(munmap(self->carveout, CARVEOUT_PAGES * self->page_size), 0); ASSERT_EQ(close_procmap(&self->procmap), 0); /* See above. */ prctl(PR_SET_MEMORY_MERGE, 0, 0, 0, 0); @@ -660,7 +663,7 @@ TEST_F(merge, mremap_unfaulted_to_faulted) /* Offset ptr2 further away. */ ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -721,7 +724,7 @@ TEST_F(merge, mremap_unfaulted_behind_faulted) /* Offset ptr2 further away. */ ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -785,12 +788,12 @@ TEST_F(merge, mremap_unfaulted_between_faulted) /* Offset ptr3 further away. */ ptr3 = sys_mremap(ptr3, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + page_size * 2000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + 2 * FAR_PAGES * page_size); ASSERT_NE(ptr3, MAP_FAILED); /* Offset ptr2 further away. */ ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -870,13 +873,13 @@ TEST_F(merge, mremap_unfaulted_between_faulted_unfaulted) /* Offset ptr3 further away. */ ptr3 = sys_mremap(ptr3, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + page_size * 2000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + 2 * FAR_PAGES * page_size); ASSERT_NE(ptr3, MAP_FAILED); /* Offset ptr2 further away. */ ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -1035,11 +1038,11 @@ TEST_F(merge, mremap_correct_placed_faulted) */ ptr3 = &ptr[10 * page_size]; ptr3 = sys_mremap(ptr3, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + page_size * 2000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + 2 * FAR_PAGES * page_size); ASSERT_NE(ptr3, MAP_FAILED); ptr2 = &ptr[5 * page_size]; ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -1075,7 +1078,7 @@ TEST_F(merge, mremap_correct_placed_faulted) * ptr2 \ ptr \ ptr3 */ ptr = sys_mremap(ptr, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr + FAR_PAGES * page_size); ASSERT_NE(ptr, MAP_FAILED); /* @@ -1110,7 +1113,7 @@ TEST_F(merge, mremap_correct_placed_faulted) * ptr2 \ ptr \ ptr3 */ ptr = sys_mremap(ptr, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr + FAR_PAGES * page_size); ASSERT_NE(ptr, MAP_FAILED); /* @@ -1168,7 +1171,7 @@ TEST_F(merge, mremap_correct_placed_faulted) * ptr ptr3 \ ptr2 */ ptr2 = sys_mremap(ptr2, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr2 + FAR_PAGES * page_size); ASSERT_NE(ptr2, MAP_FAILED); /* @@ -1203,7 +1206,7 @@ TEST_F(merge, mremap_correct_placed_faulted) * ptr \ ptr3 */ ptr3 = sys_mremap(ptr3, 5 * page_size, 5 * page_size, - MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + page_size * 1000); + MREMAP_MAYMOVE | MREMAP_FIXED, ptr3 + FAR_PAGES * page_size); ASSERT_NE(ptr3, MAP_FAILED); /* diff --git a/tools/testing/selftests/mount_setattr/Makefile b/tools/testing/selftests/mount_setattr/Makefile index 4d4f810cdf2c14..2e5b16fcdf10c2 100644 --- a/tools/testing/selftests/mount_setattr/Makefile +++ b/tools/testing/selftests/mount_setattr/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for mount selftests. -CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2 -pthread +CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2 -pthread -D_FILE_OFFSET_BITS=64 LOCAL_HDRS += ../filesystems/wrappers.h diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore index 21412510ac26b8..27761239d06998 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore @@ -21,6 +21,7 @@ log.txt msg_zerocopy netlink-dumps nettest +nsh_gso proc_net_pktgen psock_fanout psock_snd @@ -34,6 +35,7 @@ reuseport_bpf_numa reuseport_dualstack rxtimestamp sctp_hello +sctp_ifwdtsn sk_bind_sendto_listen sk_connect_zero_addr sk_so_peek_off diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 9180b9bec5155e..baea3e7f0f8f7e 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -76,6 +76,7 @@ TEST_PROGS := \ nk_qlease.py \ nl_netdev.py \ nl_nlctrl.py \ + nsh_gso.sh \ pmtu.sh \ protodown.sh \ psock_snd.sh \ @@ -90,6 +91,7 @@ TEST_PROGS := \ run_afpackettests \ run_netsocktests \ rxtimestamp.sh \ + sctp_ifwdtsn.sh \ sctp_vrf.sh \ skf_net_off.sh \ srv6_encap_lookup_l3vpn_test.sh \ @@ -156,6 +158,7 @@ TEST_GEN_FILES := \ ipv6_flowlabel \ msg_zerocopy \ nettest \ + nsh_gso \ psock_fanout \ psock_snd \ psock_tpacket \ @@ -163,6 +166,7 @@ TEST_GEN_FILES := \ reuseport_addr_any \ rxtimestamp \ sctp_hello \ + sctp_ifwdtsn \ skf_net_off \ so_netns_cookie \ so_rcv_listener \ diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c index 67a72b1a2f3d16..035ab54c1be5b6 100644 --- a/tools/testing/selftests/net/cmsg_sender.c +++ b/tools/testing/selftests/net/cmsg_sender.c @@ -34,6 +34,7 @@ enum { ERN_CMSG_RD, ERN_CMSG_RCV, ERN_SEND_MORE, + ERN_CONNECT, }; struct option_cmsg_u32 { @@ -48,6 +49,7 @@ struct options { unsigned int size; unsigned int num_pkt; bool msg_more; + bool connected; struct { unsigned int mark; unsigned int dontfrag; @@ -93,6 +95,7 @@ static void __attribute__((noreturn)) cs_usage(const char *bin) printf("Usage: %s [opts] \n", bin); printf("Options:\n" "\t\t-s Silent send() failures\n" + "\t\t-k Connect before sending\n" "\t\t-S send() size\n" "\t\t-4/-6 Force IPv4 / IPv6 only\n" "\t\t-p prot Socket protocol\n" @@ -121,8 +124,12 @@ static void cs_parse_args(int argc, char *argv[]) { int o; - while ((o = getopt(argc, argv, "46sS:p:P:m:M:n:d:tf:F:c:C:l:L:H:Q:")) != -1) { + while ((o = getopt(argc, argv, + "46ksS:p:P:m:M:n:d:tf:F:c:C:l:L:H:Q:")) != -1) { switch (o) { + case 'k': + opt.connected = true; + break; case 's': opt.silent_send = true; break; @@ -521,6 +528,12 @@ int main(int argc, char *argv[]) ca_set_sockopts(fd); + if (opt.connected && connect(fd, ai->ai_addr, ai->ai_addrlen)) { + fprintf(stderr, "Can't connect socket: %s\n", strerror(errno)); + err = ERN_CONNECT; + goto err_out; + } + if (clock_gettime(CLOCK_REALTIME, &time_start_real)) error(ERN_GETTIME, errno, "gettime REALTIME"); if (clock_gettime(CLOCK_MONOTONIC, &time_start_mono)) @@ -530,8 +543,10 @@ int main(int argc, char *argv[]) iov[0].iov_len = opt.size; memset(&msg, 0, sizeof(msg)); - msg.msg_name = ai->ai_addr; - msg.msg_namelen = ai->ai_addrlen; + if (!opt.connected) { + msg.msg_name = ai->ai_addr; + msg.msg_namelen = ai->ai_addrlen; + } msg.msg_iov = iov; msg.msg_iovlen = 1; diff --git a/tools/testing/selftests/net/cmsg_so_mark.sh b/tools/testing/selftests/net/cmsg_so_mark.sh index 772ad0cc263045..341abfc7ad8e00 100755 --- a/tools/testing/selftests/net/cmsg_so_mark.sh +++ b/tools/testing/selftests/net/cmsg_so_mark.sh @@ -68,6 +68,28 @@ for ovr in setsock cmsg both; do done done +# Reject an explicit zero mark while leaving the socket mark allowed. +ip -netns "$NS" rule add fwmark 0/0xffffffff lookup 300 || exit 1 +ip -6 -netns "$NS" rule add fwmark 0/0xffffffff lookup 300 || exit 1 + +# Check per-message marks after connect() has populated the route cache. +for i in 4 6; do + [ "$i" = 4 ] && TGT=$TGT4 || TGT=$TGT6 + + for p in u i r; do + for mark in "$((MARK + 1))" "$MARK" 0; do + expected=0 + if [ "$mark" -eq "$MARK" ] || [ "$mark" -eq 0 ]; then + expected=1 + fi + + ip netns exec "$NS" ./cmsg_sender -"$i" -p "$p" -k \ + -M "$((MARK + 1))" -m "$mark" -s "$TGT" 1234 + check_result "$?" "$expected" "IPv$i $p connected mark $mark" + done + done +done + # Summary if [ $BAD -ne 0 ]; then echo "FAIL - $BAD/$TOTAL cases failed" diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index d4416f8bdcfd1d..3e7ce41bd64ddb 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -99,6 +99,7 @@ CONFIG_NET_IPVTI=y CONFIG_NETKIT=y CONFIG_NET_L3_MASTER_DEV=y CONFIG_NET_NS=y +CONFIG_NET_NSH=m CONFIG_NET_PKTGEN=m CONFIG_NET_SCH_ETF=m CONFIG_NET_SCH_FQ=m diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh index 431d7bed76224d..adbec51917eb80 100755 --- a/tools/testing/selftests/net/fib_nexthops.sh +++ b/tools/testing/selftests/net/fib_nexthops.sh @@ -425,6 +425,14 @@ stop_ip_monitor() return $rc } +fdb_entry_aged() +{ + local mac=$1 + local dev=$2 + + ! $BRIDGE fdb get to $mac dev $dev self &> /dev/null +} + check_nexthop_fdb_support() { $IP nexthop help 2>&1 | grep -q fdb @@ -538,14 +546,18 @@ ipv6_fdb_grp_fcnal() log_test $? 0 "Fdb mac add with nexthop group and static state" run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic" - log_test $? 255 "Fdb mac add with nexthop group and dynamic state" + log_test $? 0 "Fdb mac add with nexthop group and dynamic state" + + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self dynamic extern_learn" + log_test $? 0 "Fdb mac add with nexthop group and extern_learn" - run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self" - run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic" - log_test $? 255 "Fdb mac replace with nexthop group and dynamic state" + run_cmd "$IP link set dev vx10 up type vxlan ageing 1" + run_cmd "$BRIDGE fdb add 02:02:00:00:00:18 dev vx10 dst 2001:db8:91::11 self dynamic" + slowwait 20 fdb_entry_aged 02:02:00:00:00:18 vx10 + log_test $? 0 "Fdb mac without nexthop group aged out" - run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic" - log_test $? 255 "Fdb mac append with nexthop group and dynamic state" + run_cmd "$BRIDGE fdb get to 02:02:00:00:00:16 dev vx10 self" + log_test $? 0 "Fdb mac with nexthop group not aged out" run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66" log_test $? 2 "Route add with fdb nexthop" @@ -688,14 +700,18 @@ ipv4_fdb_grp_fcnal() log_test $? 0 "Fdb mac add with nexthop group and static state" run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic" - log_test $? 255 "Fdb mac add with nexthop group and dynamic state" + log_test $? 0 "Fdb mac add with nexthop group and dynamic state" + + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self dynamic extern_learn" + log_test $? 0 "Fdb mac add with nexthop group and extern_learn" - run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self" - run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic" - log_test $? 255 "Fdb mac replace with nexthop group and dynamic state" + run_cmd "$IP link set dev vx10 up type vxlan ageing 1" + run_cmd "$BRIDGE fdb add 02:02:00:00:00:18 dev vx10 dst 10.0.0.3 self dynamic" + slowwait 20 fdb_entry_aged 02:02:00:00:00:18 vx10 + log_test $? 0 "Fdb mac without nexthop group aged out" - run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic" - log_test $? 255 "Fdb mac append with nexthop group and dynamic state" + run_cmd "$BRIDGE fdb get to 02:02:00:00:00:16 dev vx10 self" + log_test $? 0 "Fdb mac with nexthop group not aged out" run_cmd "$IP ro add 172.16.0.0/22 nhid 16" log_test $? 2 "Route add with fdb nexthop" diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index 7c47d7fe250d91..d7ac3c727f7041 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -406,10 +406,50 @@ fib_carrier_unicast_test() cleanup } +fib_carrier_gw_test() +{ + echo + echo "Gateway validation with carrier down" + + setup + + set -e + $NS_EXEC sysctl -qw net.ipv4.conf.dummy0.ignore_routes_with_linkdown=1 + $NS_EXEC sysctl -qw net.ipv6.conf.dummy0.ignore_routes_with_linkdown=1 + $IP link set dev dummy0 carrier off + sleep 1 + set +e + + $IP route add 203.0.113.0/25 via 198.51.100.2 dev dummy0 &> /dev/null + log_test $? 0 "IPv4 route in main table" + $IP -6 route add 2001:db8:10::/64 via 2001:db8:1::2 dev dummy0 &> /dev/null + log_test $? 0 "IPv6 route in main table" + + $IP route add 203.0.113.0/25 table 100 via 198.51.100.2 dev dummy0 &> /dev/null + log_test $? 0 "IPv4 route in non-main table" + $IP -6 route add 2001:db8:10::/64 table 100 via 2001:db8:1::2 dev dummy0 &> /dev/null + log_test $? 0 "IPv6 route in non-main table" + + $IP route add 203.0.113.128/25 table 100 via 198.51.100.2 &> /dev/null + log_test $? 0 "IPv4 route in non-main table without device" + $IP -6 route add 2001:db8:11::/64 table 100 via 2001:db8:1::2 &> /dev/null + log_test $? 0 "IPv6 route in non-main table without device" + + $IP route show table 100 203.0.113.0/25 | \ + grep -q "linkdown" + log_test $? 0 "IPv4 linkdown flag set" + $IP -6 route show table 100 2001:db8:10::/64 | \ + grep -q "linkdown" + log_test $? 0 "IPv6 linkdown flag set" + + cleanup +} + fib_carrier_test() { fib_carrier_local_test fib_carrier_unicast_test + fib_carrier_gw_test } fib_rp_filter_test() diff --git a/tools/testing/selftests/net/lib/xdp_cpumap.bpf.c b/tools/testing/selftests/net/lib/xdp_cpumap.bpf.c new file mode 100644 index 00000000000000..150352343114ec --- /dev/null +++ b/tools/testing/selftests/net/lib/xdp_cpumap.bpf.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +struct { + __uint(type, BPF_MAP_TYPE_CPUMAP); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u32); +} map_cpumap SEC(".maps"); + +SEC("xdp.frags") +int xdp_cpumap_prog_frags(struct xdp_md *ctx) +{ + return bpf_redirect_map(&map_cpumap, 0, XDP_DROP); +} + +char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/net/nsh_gso.c b/tools/testing/selftests/net/nsh_gso.c new file mode 100644 index 00000000000000..9acd3f7557239a --- /dev/null +++ b/tools/testing/selftests/net/nsh_gso.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Send one TCPv4 GSO packet encapsulated in a stack of NSH headers, + * through a packet socket with PACKET_VNET_HDR. + * + * Usage: nsh_gso + * + * The packet is made of 4 segments. The send() result is not checked: + * the caller looks at the device counters. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ETH_P_NSH +#define ETH_P_NSH 0x894F +#endif + +#define NSH_HLEN 8 /* base header + service path header */ +#define NSH_MD_TYPE2 2 /* no mandatory context header */ +#define NSH_NP_IPV4 1 +#define NSH_NP_NSH 4 + +#define GSO_SIZE 500 +#define NR_SEGS 4 + +struct nsh_base { + __be16 ver_flags_ttl_len; + __u8 mdtype; + __u8 np; + __be32 path_hdr; +}; + +int main(int argc, char **argv) +{ + unsigned int depth, hlen, len, i; + struct sockaddr_ll addr = {}; + struct virtio_net_hdr *vnet; + struct nsh_base *nsh; + struct ethhdr *eth; + struct tcphdr *tcp; + int fd, one = 1; + struct iphdr *ip; + char *buf; + + if (argc != 3) + error(1, 0, "usage: %s ", argv[0]); + + depth = strtoul(argv[2], NULL, 0); + hlen = sizeof(*eth) + depth * NSH_HLEN + sizeof(*ip) + sizeof(*tcp); + if (!depth || hlen > UINT16_MAX) + error(1, 0, "invalid depth %u", depth); + len = sizeof(*vnet) + hlen + NR_SEGS * GSO_SIZE; + + buf = calloc(1, len); + if (!buf) + error(1, errno, "calloc"); + + vnet = (void *)buf; + vnet->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; + vnet->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; + vnet->hdr_len = hlen; + vnet->gso_size = GSO_SIZE; + vnet->csum_start = hlen - sizeof(*tcp); + vnet->csum_offset = __builtin_offsetof(struct tcphdr, check); + + eth = (void *)(vnet + 1); + memset(eth->h_dest, 0xff, ETH_ALEN); + eth->h_source[0] = 0x02; + eth->h_proto = htons(ETH_P_NSH); + + nsh = (void *)(eth + 1); + for (i = 0; i < depth; i++, nsh++) { + /* version 0, ttl 63, length in 4 byte words */ + nsh->ver_flags_ttl_len = htons(63 << 6 | NSH_HLEN / 4); + nsh->mdtype = NSH_MD_TYPE2; + nsh->np = i == depth - 1 ? NSH_NP_IPV4 : NSH_NP_NSH; + nsh->path_hdr = htonl(1 << 8 | 255); + } + + ip = (void *)nsh; + ip->version = 4; + ip->ihl = 5; + ip->ttl = 64; + ip->protocol = IPPROTO_TCP; + ip->saddr = htonl(0xc0000201); /* 192.0.2.1 */ + ip->daddr = htonl(0xc0000202); /* 192.0.2.2 */ + + tcp = (void *)(ip + 1); + tcp->source = htons(1234); + tcp->dest = htons(5678); + tcp->doff = 5; + tcp->ack = 1; + + fd = socket(AF_PACKET, SOCK_RAW, 0); + if (fd < 0) + error(1, errno, "socket"); + if (setsockopt(fd, SOL_PACKET, PACKET_VNET_HDR, &one, sizeof(one))) + error(1, errno, "setsockopt PACKET_VNET_HDR"); + + addr.sll_family = AF_PACKET; + addr.sll_protocol = htons(ETH_P_NSH); + addr.sll_ifindex = if_nametoindex(argv[1]); + if (!addr.sll_ifindex) + error(1, errno, "if_nametoindex %s", argv[1]); + + /* A packet dropped at segmentation time is reported as an error, + * this is expected for deep stacks. + */ + sendto(fd, buf, len, 0, (void *)&addr, sizeof(addr)); + + close(fd); + free(buf); + return 0; +} diff --git a/tools/testing/selftests/net/nsh_gso.sh b/tools/testing/selftests/net/nsh_gso.sh new file mode 100755 index 00000000000000..d0746cf1d52890 --- /dev/null +++ b/tools/testing/selftests/net/nsh_gso.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Check software GSO of NSH packets: a TCP GSO packet behind a few NSH +# headers is segmented, and a deep stack of NSH headers is dropped +# instead of recursing in nsh_gso_segment() for each of them. + +source lib.sh + +NR_SEGS=4 +ret=0 + +cleanup() +{ + cleanup_ns $ns1 +} + +tx_packets() +{ + ip netns exec $ns1 cat /sys/class/net/dummy0/statistics/tx_packets +} + +# $1: number of NSH headers, $2: expected number of transmitted packets +check_nsh_gso() +{ + local depth=$1 + local expected=$2 + local before + local sent + + before=$(tx_packets) + ip netns exec $ns1 ./nsh_gso dummy0 $depth + sent=$(($(tx_packets) - before)) + + if [ $sent -eq $expected ]; then + echo "PASS: $depth NSH headers: $sent packets sent" + else + echo "FAIL: $depth NSH headers: $sent packets sent, expected $expected" + ret=1 + fi +} + +modprobe -q nsh +nsh_loaded=$? + +trap cleanup EXIT +setup_ns ns1 || exit $ksft_skip + +ip -netns $ns1 link add dummy0 type dummy +ip -netns $ns1 link set dummy0 up +# No IPv6 autoconf traffic on the device, to get stable counters. +ip netns exec $ns1 sysctl -qw net.ipv6.conf.dummy0.disable_ipv6=1 +# Force software segmentation in validate_xmit_skb(). +ip netns exec $ns1 ethtool -K dummy0 tso off >/dev/null || exit $ksft_skip + +before=$(tx_packets) +ip netns exec $ns1 ./nsh_gso dummy0 1 +if [ $(($(tx_packets) - before)) -eq 0 ] && [ $nsh_loaded -ne 0 ]; then + echo "SKIP: NSH GSO not available" + exit $ksft_skip +fi + +check_nsh_gso 1 $NR_SEGS +# The recursion limit is shared with the inner IPv4 header. +check_nsh_gso 4 $NR_SEGS +check_nsh_gso 5 0 +check_nsh_gso 64 0 +# The largest stack that fits in a 64KB header. +check_nsh_gso 8000 0 + +exit $ret diff --git a/tools/testing/selftests/net/packetdrill/tcp_bidir_fast_retransmit_nosack.pkt b/tools/testing/selftests/net/packetdrill/tcp_bidir_fast_retransmit_nosack.pkt new file mode 100644 index 00000000000000..5c66b7171d229a --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_bidir_fast_retransmit_nosack.pkt @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Verify that non-SACK connections properly detect duplicate acks when mixed +// with other data segments from peer. + +`./defaults.sh` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4 + +0...0 connect(4, ..., ...) = 0 + + // Three-way handshake, SACK not supported by peer + +0 > S 0:0(0) + +0 < S. 0:0(0) ack 1 win 65535 + +0 > . 1:1(0) ack 1 + + // Send 1000 bytes, peer acks everything + +0 send(4, ..., 1000, 0) = 1000 + +0 > P. 1:1001(1000) ack 1 + +0 < . 1:1(0) ack 1001 win 65535 + + // Send 4000 more bytes + +0 send(4, ..., 4000, 0) = 4000 + +0 > P. 1001:5001(4000) ack 1 + + // Receive first dup-ack (considering segment 1001-2001 was lost) + +0 < . 1:1(0) ack 1001 win 65535 + + // Receive unrelated data segment from peer and ack it + +0 < P. 1:11(10) ack 1001 win 65535 + +0 > . 5001:5001(0) ack 11 + + // Receive second dup-ack + +0 < . 11:11(0) ack 1001 win 65535 + + // Receive another data segment from peer and ack it + +0 < P. 11:21(10) ack 1001 win 65535 + +0 > . 5001:5001(0) ack 21 + + // Receive third dup-ack, which should trigger fast retransmit (without + // waiting for RTO) + +0 < . 21:21(0) ack 1001 win 65535 + +0 > . 1001:2001(1000) ack 21 diff --git a/tools/testing/selftests/net/packetdrill/tcp_fastopen_client_defer-connect.pkt b/tools/testing/selftests/net/packetdrill/tcp_fastopen_client_defer-connect.pkt new file mode 100644 index 00000000000000..e90df498d935bb --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_fastopen_client_defer-connect.pkt @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Test that a TCP_FASTOPEN_CONNECT socket in DEFER_CONNECT state +// ignores inbound TCP segments and ICMP errors before SYN is sent. +// +`./defaults.sh + ./set_sysctls.py /proc/sys/net/ipv4/tcp_timestamps=0` + +// Cache warmup: send a Fast Open cookie request + 0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 + +0 sendto(3, ..., 0, MSG_FASTOPEN, ..., ...) = -1 EINPROGRESS (Operation is now in progress) + +0 > S 0:0(0) + +0 < S. 123:123(0) ack 1 win 14600 + +0 > . 1:1(0) ack 1 + +0 close(3) = 0 + +0 > F. 1:1(0) ack 1 + +0 < F. 1:1(0) ack 2 win 92 + +0 > . 2:2(0) ack 2 + +// Test 1: Forged SYN during DEFER_CONNECT +// connect() + connect(AF_UNSPEC) to let packetdrill remember +// IP, ports, ISN to inject a forged SYN + +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 4 + +0 connect(4, ..., ...) = -1 EINPROGRESS (Operation is now in progress) + +0 > S 0:0(0) + +0 connect(4, AF_UNSPEC, ...) = 0 + +// set DEFER_CONNECT bit + +0 bind(4, ..., ...) = 0 + +0 setsockopt(4, SOL_TCP, TCP_FASTOPEN_CONNECT, [1], 4) = 0 + +0 connect(4, ..., ...) = 0 + +// Forged SYN should not be accepted + +0 < 8080 > 8080 S 0:0(0) win 14600 + +0 %{ assert tcpi_state == TCP_SYN_SENT, tcpi_state }% + + +0 sendto(4, ..., 500, 0, ..., ...) = 500 + +0 > S 0:500(500) + +0 < S. 5678:5678(0) ack 501 win 14600 + +0 > . 501:501(0) ack 1 + +0 %{ assert tcpi_state == TCP_ESTABLISHED, tcpi_state }% + +0 close(4) = 0 + +0 > F. 501:501(0) ack 1 + +0 < R. 1:1(0) ack 502 win 0 + +// Test 2: Forged ICMP error during DEFER_CONNECT + +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 5 + +0 setsockopt(5, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 bind(5, ..., ...) = 0 + +0 connect(5, ..., ...) = -1 EINPROGRESS (Operation is now in progress) + +0 > S 0:0(0) + +0 connect(5, AF_UNSPEC, ...) = 0 + +0 setsockopt(5, SOL_TCP, TCP_FASTOPEN_CONNECT, [1], 4) = 0 + +0 connect(5, ..., ...) = 0 + + +0 < icmp unreachable [3:3(0)] + +0 %{ assert tcpi_state == TCP_SYN_SENT, tcpi_state }% + +0 sendto(5, ..., 500, 0, ..., ...) = 500 + +0 close(5) = 0 + +`/tmp/sysctl_restore_${PPID}.sh` diff --git a/tools/testing/selftests/net/sctp_ifwdtsn.c b/tools/testing/selftests/net/sctp_ifwdtsn.c new file mode 100644 index 00000000000000..23ae508d8523cb --- /dev/null +++ b/tools/testing/selftests/net/sctp_ifwdtsn.c @@ -0,0 +1,699 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helper for sctp_ifwdtsn.sh: I-FORWARD-TSN handling with SCTP user message + * interleaving (RFC 8260) and partial reliability (RFC 3758). + * + * Runs both endpoints of one association: the server socket is created in + * the current network namespace, the client socket in the namespace given + * on the command line. The caller sets up the link and any nft rule that + * drops chunks. Messages sent by the client: + * + * big: 64KB on stream 0, reliable, fragmented into ~66 I-DATA chunks + * small: on stream 1, PR-SCTP "RTX" policy allowing one retransmission; + * the nft rule drops (part of) it, so it gets abandoned + * marker: short ordered message on stream 0 + * + * The reset_pending tests instead leave a partly received PR-SCTP message + * on each stream, the one on stream 1 in partial delivery, before the + * reset; the pdapi tests abandon two messages on stream 1, the first one + * in partial delivery. + * + * Usage: sctp_ifwdtsn + * Exit status: 0 pass, 1 fail, 4 skip. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kselftest.h" + +#ifndef SOL_SCTP +#define SOL_SCTP 132 +#endif + +#define SRV_ADDR "10.0.0.1" +#define CLI_ADDR "10.0.0.2" +#define SRV_PORT 5000 +#define BIG_LEN (64 * 1024) +#define BUF_LEN (BIG_LEN + 1024) +#define MAXSEG 1000 +#define TIMEOUT_MS 5000 +#define MARKER "marker" +#define UO_MARKER "uo-marker" +#define PD_LEN 20000 /* message in partial delivery on stream 1 */ + +struct test { + const char *name; + bool big_uo; /* send big unordered */ + int small_len; /* 0: don't send the small message */ + bool small_uo; /* send small unordered */ + int pd_point; /* server SCTP_PARTIAL_DELIVERY_POINT */ + bool expect_pd_abort; /* PD on stream 1 must be aborted */ + bool uo_marker; /* then send an unordered marker on 1 */ + bool reset; /* SSN/TSN association reset after big */ + int reset_pending; /* reset with data pending, requested by + * 1: the server, 2: the client + */ + bool pdapi; /* two messages skipped on stream 1 */ +}; + +static const struct test tests[] = { + { .name = "ordered", .small_len = 3000 }, + { .name = "unordered", .big_uo = true, .small_len = 3000 }, + { .name = "leading_edge", .small_len = 1000, .pd_point = 2000 }, + { .name = "leading_edge_nopd", .small_len = 1000 }, + { .name = "uo_pd", .small_len = 20000, .small_uo = true, + .pd_point = 2000, .expect_pd_abort = true, .uo_marker = true }, + { .name = "reset", .reset = true }, + { .name = "reset_pending_srv", .reset = true, .reset_pending = 1, + .pd_point = 3000, .expect_pd_abort = true }, + { .name = "reset_pending_cli", .reset = true, .reset_pending = 2, + .pd_point = 3000, .expect_pd_abort = true }, + { .name = "pdapi", .pdapi = true, .pd_point = 2000, + .expect_pd_abort = true }, + { .name = "pdapi_uo", .pdapi = true, .small_uo = true, .pd_point = 2000, + .expect_pd_abort = true }, +}; + +static const struct test *t; + +static void die(const char *what) +{ + fprintf(stderr, "%s: %s\n", what, strerror(errno)); + exit(KSFT_FAIL); +} + +static void setopt(int fd, int opt, const void *val, socklen_t len, + const char *name) +{ + if (setsockopt(fd, SOL_SCTP, opt, val, len) < 0) { + fprintf(stderr, "setsockopt(%s): %s\n", name, strerror(errno)); + /* Interleaving disabled, or option not supported. */ + exit(errno == EPERM || errno == ENOPROTOOPT ? + KSFT_SKIP : KSFT_FAIL); + } +} + +static void set_assoc_opt(int fd, int opt, unsigned int val, const char *name) +{ + struct sctp_assoc_value av = { + .assoc_id = SCTP_FUTURE_ASSOC, + .assoc_value = val, + }; + + setopt(fd, opt, &av, sizeof(av), name); +} + +static void subscribe(int fd, int type) +{ + struct sctp_event ev = { + .se_assoc_id = SCTP_FUTURE_ASSOC, + .se_type = type, + .se_on = 1, + }; + + setopt(fd, SCTP_EVENT, &ev, sizeof(ev), "SCTP_EVENT"); +} + +static int sctp_socket(void) +{ + struct sctp_initmsg im = { + .sinit_num_ostreams = 2, + .sinit_max_instreams = 2, + }; + struct sctp_paddrparams pp = { + .spp_assoc_id = SCTP_FUTURE_ASSOC, + .spp_flags = SPP_HB_DISABLE, + }; + struct sctp_rtoinfo rto = { + .srto_assoc_id = SCTP_FUTURE_ASSOC, + .srto_initial = 300, + .srto_min = 300, + .srto_max = 1000, + }; + int fd, val; + + fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (fd < 0) { + perror("socket"); + exit(errno == EPROTONOSUPPORT ? KSFT_SKIP : KSFT_FAIL); + } + val = 1; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); + + setopt(fd, SCTP_INITMSG, &im, sizeof(im), "SCTP_INITMSG"); + setopt(fd, SCTP_RTOINFO, &rto, sizeof(rto), "SCTP_RTOINFO"); + /* No HEARTBEATs: the nft rules only look at the first chunk of a + * packet, and a HEARTBEAT bundled in front of DATA would bypass them. + */ + setopt(fd, SCTP_PEER_ADDR_PARAMS, &pp, sizeof(pp), + "SCTP_PEER_ADDR_PARAMS"); + set_assoc_opt(fd, SCTP_PR_SUPPORTED, 1, "SCTP_PR_SUPPORTED"); + val = 2; + setopt(fd, SCTP_FRAGMENT_INTERLEAVE, &val, sizeof(val), + "SCTP_FRAGMENT_INTERLEAVE"); + set_assoc_opt(fd, SCTP_INTERLEAVING_SUPPORTED, 1, + "SCTP_INTERLEAVING_SUPPORTED"); + if (t->reset) { + set_assoc_opt(fd, SCTP_RECONFIG_SUPPORTED, 1, + "SCTP_RECONFIG_SUPPORTED"); + set_assoc_opt(fd, SCTP_ENABLE_STREAM_RESET, + SCTP_ENABLE_RESET_ASSOC_REQ, + "SCTP_ENABLE_STREAM_RESET"); + subscribe(fd, SCTP_ASSOC_RESET_EVENT); + } + val = 1; + setopt(fd, SCTP_RECVRCVINFO, &val, sizeof(val), "SCTP_RECVRCVINFO"); + + return fd; +} + +static void send_msg(int fd, int sid, bool uo, const void *buf, size_t len, + bool pr) +{ + union { + char buf[CMSG_SPACE(sizeof(struct sctp_sndinfo)) + + CMSG_SPACE(sizeof(struct sctp_prinfo))]; + struct cmsghdr align; + } cbuf = {}; + struct iovec iov = { .iov_base = (void *)buf, .iov_len = len }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = cbuf.buf, + .msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndinfo)), + }; + struct sctp_sndinfo *si; + struct sctp_prinfo *pi; + struct cmsghdr *cm; + + cm = CMSG_FIRSTHDR(&msg); + cm->cmsg_level = IPPROTO_SCTP; + cm->cmsg_type = SCTP_SNDINFO; + cm->cmsg_len = CMSG_LEN(sizeof(*si)); + si = (struct sctp_sndinfo *)CMSG_DATA(cm); + si->snd_sid = sid; + si->snd_flags = uo ? SCTP_UNORDERED : 0; + + if (pr) { + /* Abandon once the chunk would need a second retransmission: + * only a chunk that is lost again after being retransmitted + * qualifies, so abandonment does not depend on timing. + */ + msg.msg_controllen += CMSG_SPACE(sizeof(*pi)); + cm = CMSG_NXTHDR(&msg, cm); + cm->cmsg_level = IPPROTO_SCTP; + cm->cmsg_type = SCTP_PRINFO; + cm->cmsg_len = CMSG_LEN(sizeof(*pi)); + pi = (struct sctp_prinfo *)CMSG_DATA(cm); + pi->pr_policy = SCTP_PR_SCTP_RTX; + pi->pr_value = 1; + } + + if (sendmsg(fd, &msg, 0) != (ssize_t)len) + die("sendmsg"); +} + +static unsigned char pattern(size_t i) +{ + return (i * 7 + (i >> 8)) & 0xff; +} + +static long long now_ms(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1000LL + ts.tv_nsec / 1000000; +} + +/* Wait until the client has abandoned @n sent messages. */ +static bool wait_abandoned(int fd, unsigned int n) +{ + long long end = now_ms() + TIMEOUT_MS; + struct sctp_prstatus ps; + socklen_t len; + + while (now_ms() < end) { + memset(&ps, 0, sizeof(ps)); + ps.sprstat_policy = SCTP_PR_SCTP_RTX; + len = sizeof(ps); + if (getsockopt(fd, SOL_SCTP, SCTP_PR_ASSOC_STATUS, &ps, + &len) < 0) + die("SCTP_PR_ASSOC_STATUS"); + if (ps.sprstat_abandoned_sent >= n) + return true; + usleep(10000); + } + return false; +} + +/* Wait for a notification of @type on @fd, discarding anything else. */ +static bool wait_event(int fd, int type) +{ + long long end = now_ms() + TIMEOUT_MS; + union { + char data[256]; + union sctp_notification sn; + } buf; + + for (;;) { + struct pollfd pfd = { .fd = fd, .events = POLLIN }; + struct iovec iov = { buf.data, sizeof(buf.data) }; + struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 }; + union sctp_notification *sn = &buf.sn; + long long left = end - now_ms(); + + if (left <= 0 || poll(&pfd, 1, left) <= 0) + break; + if (recvmsg(fd, &msg, 0) <= 0) + break; + if (!(msg.msg_flags & MSG_NOTIFICATION) || + sn->sn_header.sn_type != type) + continue; + if (type == SCTP_ASSOC_RESET_EVENT && + sn->sn_assocreset_event.assocreset_flags & + (SCTP_ASSOC_RESET_DENIED | SCTP_ASSOC_RESET_FAILED)) { + printf("association reset denied or failed\n"); + return false; + } + return true; + } + return false; +} + +/* Request an SSN/TSN association reset. The sender refuses while it still + * has data queued or in flight, so retry until that has been acked. + */ +static void reset_assoc(int fd) +{ + long long end = now_ms() + TIMEOUT_MS; + sctp_assoc_t id = 0; + + while (setsockopt(fd, SOL_SCTP, SCTP_RESET_ASSOC, &id, sizeof(id))) { + if (errno != EAGAIN || now_ms() >= end) + die("SCTP_RESET_ASSOC"); + usleep(10000); + } +} + +/* Wait until all data sent on @fd has been acked. The receiver's + * cumulative TSN only moves past an abandoned message once it has + * processed the I-FORWARD-TSN for it. + */ +static bool wait_acked(int fd) +{ + long long end = now_ms() + TIMEOUT_MS; + struct sctp_status st; + socklen_t len; + + while (now_ms() < end) { + memset(&st, 0, sizeof(st)); + len = sizeof(st); + /* Fails once the association has been aborted. */ + if (getsockopt(fd, SOL_SCTP, SCTP_STATUS, &st, &len) < 0) + return false; + if (!st.sstat_unackdata) + return true; + usleep(10000); + } + return false; +} + +/* Bytes held by the server association (/proc/net/sctp/assocs RX_QUEUE). */ +static long assoc_rx_queue(void) +{ + /* 7 columns, TX_QUEUE, RX_QUEUE, UID, INODE, LPORT */ + const char *fmt = "%*s %*s %*s %*s %*s %*s %*s %*u %lu %*s %*s %d"; + unsigned long rxq; + char line[512]; + long ret = -1; + FILE *f; + int lport; + + f = fopen("/proc/net/sctp/assocs", "r"); + if (!f) + return -1; + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, fmt, &rxq, &lport) == 2 && lport == SRV_PORT) + ret = rxq; + } + fclose(f); + return ret; +} + +struct server_state { + unsigned char *buf[2]; /* message being received, per stream */ + size_t len[2]; + bool big, marker, uo_marker, reset_event; + int pd_aborts[2]; + unsigned int pd_seq[2]; /* pdapi_seq of the last abort */ + int errors; +}; + +static void check_msg(struct server_state *s, int sid) +{ + unsigned char *m = s->buf[sid]; + size_t len = s->len[sid]; + size_t i; + + s->len[sid] = 0; + if (sid == 0 && len == sizeof(MARKER) && !memcmp(m, MARKER, len)) { + s->marker = true; + return; + } + if (sid == 1 && len == sizeof(UO_MARKER) && + !memcmp(m, UO_MARKER, len)) { + s->uo_marker = true; + return; + } + if (sid == 0 && len == BIG_LEN) { + for (i = 0; i < BIG_LEN && m[i] == pattern(i); i++) + ; + if (i == BIG_LEN) { + s->big = true; + return; + } + printf("big message corrupted at offset %zu\n", i); + } else if (sid == 1 && len > sizeof(UO_MARKER) && + !memcmp(m + len - sizeof(UO_MARKER), UO_MARKER, + sizeof(UO_MARKER))) { + printf("unordered marker appended to the abandoned message\n"); + } else if (sid == 1 && t->small_len) { + printf("abandoned message delivered (%zu bytes)\n", len); + } else { + printf("unexpected %zu byte message on stream %d\n", len, sid); + } + s->errors++; +} + +/* Receive until @done(s) is true or the timeout expires. */ +static bool server_recv(int fd, struct server_state *s, + bool (*done)(const struct server_state *s)) +{ + long long end = now_ms() + TIMEOUT_MS; + static union { + char buf[CMSG_SPACE(sizeof(struct sctp_rcvinfo))]; + struct cmsghdr align; + } cbuf; + static union { + unsigned char data[BUF_LEN]; + union sctp_notification sn; + } buf; + + while (!done(s)) { + struct pollfd pfd = { .fd = fd, .events = POLLIN }; + struct iovec iov = { buf.data, sizeof(buf.data) }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = cbuf.buf, + .msg_controllen = sizeof(cbuf.buf), + }; + union sctp_notification *sn = &buf.sn; + struct sctp_rcvinfo *ri = NULL; + struct cmsghdr *cm; + long long left; + ssize_t n; + int sid; + + left = end - now_ms(); + if (left <= 0 || poll(&pfd, 1, left) <= 0) { + printf("timeout waiting for data\n"); + return false; + } + n = recvmsg(fd, &msg, 0); + if (n <= 0) { + printf("recvmsg: %s\n", n ? strerror(errno) : "EOF"); + return false; + } + + if (msg.msg_flags & MSG_NOTIFICATION) { + int type = sn->sn_header.sn_type; + + if (type == SCTP_PARTIAL_DELIVERY_EVENT) { + struct sctp_pdapi_event *pe = &sn->sn_pdapi_event; + + sid = pe->pdapi_stream; + if (sid > 1 || pe->pdapi_indication != + SCTP_PARTIAL_DELIVERY_ABORTED) { + printf("unexpected pdapi event %u on stream %d\n", + pe->pdapi_indication, sid); + return false; + } + s->pd_aborts[sid]++; + s->pd_seq[sid] = pe->pdapi_seq; + s->len[sid] = 0; + } else if (type == SCTP_ASSOC_RESET_EVENT) { + s->reset_event = true; + } + continue; + } + + for (cm = CMSG_FIRSTHDR(&msg); cm; cm = CMSG_NXTHDR(&msg, cm)) + if (cm->cmsg_level == IPPROTO_SCTP && + cm->cmsg_type == SCTP_RCVINFO) + ri = (struct sctp_rcvinfo *)CMSG_DATA(cm); + sid = ri ? ri->rcv_sid : 0; + if (sid > 1 || s->len[sid] + n > BUF_LEN) { + printf("unexpected data on stream %d\n", sid); + return false; + } + memcpy(s->buf[sid] + s->len[sid], buf.data, n); + s->len[sid] += n; + if (msg.msg_flags & MSG_EOR) + check_msg(s, sid); + } + return true; +} + +static bool got_reset(const struct server_state *s) +{ + return s->reset_event || s->errors; +} + +static bool got_big(const struct server_state *s) +{ + return s->big || s->errors; +} + +static bool got_all(const struct server_state *s) +{ + return ((s->big || t->pdapi) && s->marker && + (!t->uo_marker || s->uo_marker) && + (!t->expect_pd_abort || s->pd_aborts[1])) || s->errors; +} + +/* Let the nft rules that match the client address in set "hold" pass. */ +static bool release_hold(void) +{ + if (system("nft delete element ip sctp_test hold { " CLI_ADDR " }")) { + printf("failed to release the nft hold\n"); + return false; + } + return true; +} + +static int client_socket(const char *netns) +{ + int self, other, fd; + char path[256]; + + snprintf(path, sizeof(path), "/run/netns/%s", netns); + self = open("/proc/self/ns/net", O_RDONLY); + other = open(path, O_RDONLY); + if (self < 0 || other < 0) + die("open netns"); + if (setns(other, CLONE_NEWNET)) + die("setns"); + fd = sctp_socket(); + if (setns(self, CLONE_NEWNET)) + die("setns"); + close(other); + close(self); + return fd; +} + +int main(int argc, char **argv) +{ + struct sockaddr_in sa = { + .sin_family = AF_INET, + .sin_port = htons(SRV_PORT), + }; + struct server_state s = {}; + unsigned char *big, *small; + int lfd, sfd, cfd, i; + bool ok; + long rxq; + + if (argc != 3) { + fprintf(stderr, "usage: %s \n", argv[0]); + return KSFT_FAIL; + } + for (i = 0; i < (int)ARRAY_SIZE(tests); i++) + if (!strcmp(argv[2], tests[i].name)) + t = &tests[i]; + if (!t) { + fprintf(stderr, "unknown test %s\n", argv[2]); + return KSFT_FAIL; + } + inet_pton(AF_INET, SRV_ADDR, &sa.sin_addr); + + lfd = sctp_socket(); + if (t->pd_point) { + setopt(lfd, SCTP_PARTIAL_DELIVERY_POINT, &t->pd_point, + sizeof(t->pd_point), "SCTP_PARTIAL_DELIVERY_POINT"); + subscribe(lfd, SCTP_PARTIAL_DELIVERY_EVENT); + } + if (bind(lfd, (struct sockaddr *)&sa, sizeof(sa)) || listen(lfd, 1)) + die("bind/listen"); + + cfd = client_socket(argv[1]); + set_assoc_opt(cfd, SCTP_MAXSEG, MAXSEG, "SCTP_MAXSEG"); + /* Round robin, so that the small message is sent between fragments + * of the big one. + */ + set_assoc_opt(cfd, SCTP_STREAM_SCHEDULER, SCTP_SS_RR, + "SCTP_STREAM_SCHEDULER"); + if (t->pdapi) { + /* Send the marker right away. Held back by Nagle, it could + * go out bundled behind an I-FORWARD-TSN, and nft would + * drop both. + */ + i = 1; + setopt(cfd, SCTP_NODELAY, &i, sizeof(i), "SCTP_NODELAY"); + } + if (connect(cfd, (struct sockaddr *)&sa, sizeof(sa))) + die("connect"); + sfd = accept(lfd, NULL, NULL); + if (sfd < 0) + die("accept"); + + big = malloc(BIG_LEN); + small = malloc(PD_LEN); + s.buf[0] = malloc(BUF_LEN); + s.buf[1] = malloc(BUF_LEN); + if (!big || !small || !s.buf[0] || !s.buf[1]) + die("malloc"); + for (i = 0; i < BIG_LEN; i++) + big[i] = pattern(i); + memset(small, 's', PD_LEN); + + if (t->reset_pending) { + /* A message partly received on stream 0, not in partial + * delivery, and one in partial delivery on stream 1. Until + * the hold is released, nft drops a fragment of each and + * every I-FORWARD-TSN, so both are still pending on the + * server when the reset is done. + */ + send_msg(cfd, 0, false, small, 2500, true); + send_msg(cfd, 1, false, small, PD_LEN, true); + if (!wait_abandoned(cfd, 2)) { + printf("client: messages were not abandoned\n"); + return KSFT_FAIL; + } + reset_assoc(t->reset_pending == 1 ? sfd : cfd); + if (!wait_event(cfd, SCTP_ASSOC_RESET_EVENT)) { + printf("client: no association reset event\n"); + return KSFT_FAIL; + } + /* Once the server has seen the reset too, every packet the + * client sent before it has arrived. + */ + if (!server_recv(sfd, &s, got_reset) || s.errors || + !release_hold()) + return KSFT_FAIL; + /* MIDs start again from 0, so big reuses the MID of the + * message left on stream 0 and must not be mixed with it. + */ + send_msg(cfd, 0, false, big, BIG_LEN, false); + } else if (t->pdapi) { + /* Two messages on stream 1, the first one in partial + * delivery. nft drops a fragment of each and holds back + * I-FORWARD-TSNs until the marker, sent once both are + * abandoned, arrives. The client then sends one + * I-FORWARD-TSN naming both messages, below the marker's + * TSN. + */ + send_msg(cfd, 1, t->small_uo, small, PD_LEN, true); + send_msg(cfd, 1, t->small_uo, small, 3000, true); + if (!wait_abandoned(cfd, 2)) { + printf("client: messages were not abandoned\n"); + return KSFT_FAIL; + } + } else { + send_msg(cfd, 0, t->big_uo, big, BIG_LEN, false); + if (t->small_len) + send_msg(cfd, 1, t->small_uo, small, t->small_len, + true); + } + + if (t->reset && !t->reset_pending) { + ok = server_recv(sfd, &s, got_big); + if (ok) + reset_assoc(sfd); + /* Only send the marker once the reset is done. */ + if (ok && !wait_event(cfd, SCTP_ASSOC_RESET_EVENT)) { + printf("client: no association reset event\n"); + return KSFT_FAIL; + } + } + send_msg(cfd, 0, false, MARKER, sizeof(MARKER), false); + + if (t->small_len && !wait_abandoned(cfd, 1)) { + printf("client: small message was not abandoned\n"); + return KSFT_FAIL; + } + if (t->uo_marker) + send_msg(cfd, 1, true, UO_MARKER, sizeof(UO_MARKER), false); + + ok = server_recv(sfd, &s, got_all); + if (!wait_acked(cfd)) { + printf("client: data not acked\n"); + ok = false; + } + rxq = assoc_rx_queue(); + + if (!s.big && !t->pdapi) + printf("big message not delivered intact\n"); + if (!s.marker) + printf("marker not delivered\n"); + if (t->uo_marker && !s.uo_marker) + printf("unordered marker not delivered as its own message\n"); + if (s.pd_aborts[0] || (s.pd_aborts[1] && !t->expect_pd_abort)) { + printf("unexpected partial delivery abort\n"); + ok = false; + } + if (t->expect_pd_abort && !s.pd_aborts[1]) { + printf("partial delivery on stream 1 not aborted\n"); + ok = false; + } else if (t->expect_pd_abort && (s.pd_aborts[1] > 1 || s.pd_seq[1])) { + printf("%d partial delivery aborts, last for MID %u, expected one for MID 0\n", + s.pd_aborts[1], s.pd_seq[1]); + ok = false; + } + if (t->reset && !s.reset_event) { + printf("server: no association reset event\n"); + ok = false; + } + if (rxq < 0) { + printf("association is gone\n"); + ok = false; + } else if (rxq > 0) { + printf("%ld bytes left queued on the association\n", rxq); + ok = false; + } + + return ok && !s.errors ? KSFT_PASS : KSFT_FAIL; +} diff --git a/tools/testing/selftests/net/sctp_ifwdtsn.sh b/tools/testing/selftests/net/sctp_ifwdtsn.sh new file mode 100755 index 00000000000000..e745d67b3b7922 --- /dev/null +++ b/tools/testing/selftests/net/sctp_ifwdtsn.sh @@ -0,0 +1,233 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# SCTP I-FORWARD-TSN handling with user message interleaving (RFC 8260). +# +# TOPO: CLI_NS (veth, 10.0.0.2) <---> (veth, 10.0.0.1) SRV_NS +# +# A large reliable message on stream 0 is sent interleaved with a PR-SCTP +# message on stream 1 that an nft rule in SRV_NS drops, so the sender +# abandons it and sends an I-FORWARD-TSN. The netem delay keeps the sender +# window-limited, so the two messages' fragments interleave. Most of the +# checks are done by sctp_ifwdtsn, see there. + +source lib.sh + +ALL_TESTS=" + test_ordered + test_unordered + test_leading_edge + test_leading_edge_nopd + test_uo_pd + test_reset + test_reset_pending_srv + test_reset_pending_cli + test_pdapi + test_pdapi_uo +" + +# nft matches on the first chunk of a packet: chunk type at byte 12 of the +# SCTP header, flags at byte 13, I-DATA stream id at byte 20, MID at byte +# 24 and FSN at byte 28 (the PPID in a B fragment). SCTP_MAXSEG limits +# fragments to 1000 bytes and GSO is limited to the MTU, so no two +# full-size fragments share a packet. +NFT_SCTP="meta l4proto sctp" +NFT_CHUNK_IDATA="@th,96,8 64" +NFT_CHUNK_IFWDTSN="@th,96,8 194" +NFT_FLAG_B="@th,104,8 & 0x02 == 0x02" +NFT_FLAG_E="@th,104,8 & 0x01 == 0x01" +NFT_SID0="@th,160,16 0" +NFT_SID1="@th,160,16 1" +NFT_MID0="@th,192,32 0" +NFT_MID1="@th,192,32 1" +NFT_FSN5="@th,224,32 5" + +# Run a setup command. The config file enables everything used here, so a +# failure fails the test, with the command and its output as the reason. +setup_cmd() +{ + local out + + out=$("$@" 2>&1) && return + check_err 1 "$*: $out" + return 1 +} + +setup() +{ + if ! setup_ns CLI_NS SRV_NS; then + check_err 1 "setup_ns failed" + return 1 + fi + defer cleanup_all_ns + + setup_cmd ip -n "$SRV_NS" link add veth0 type veth peer name veth0 \ + netns "$CLI_NS" || return + setup_cmd ip -n "$SRV_NS" addr add 10.0.0.1/24 dev veth0 || return + setup_cmd ip -n "$CLI_NS" addr add 10.0.0.2/24 dev veth0 || return + for ns in "$SRV_NS" "$CLI_NS"; do + setup_cmd ip -n "$ns" link set veth0 gso_max_size 1500 up || + return + setup_cmd tc -n "$ns" qdisc add dev veth0 root netem \ + delay 50ms || return + setup_cmd ip netns exec "$ns" sysctl -wq \ + net.sctp.intl_enable=1 net.sctp.prsctp_enable=1 \ + net.sctp.reconf_enable=1 || return + done +} + +# $1: nft rules for the server's input hook (may be empty) +nft_rules() +{ + setup_cmd ip netns exec "$SRV_NS" nft -f - <<-EOF + table ip sctp_test { + set blk { + type ipv4_addr + flags dynamic + } + set hold { + type ipv4_addr + flags dynamic + elements = { 10.0.0.2 } + } + chain input { + type filter hook input priority 0; + $1 + } + } + EOF +} + +# $1: test name for sctp_ifwdtsn, $2: description, $3: nft rules (optional) +run_helper() +{ + RET=0 + retmsg= + if ! setup || { [ -n "$3" ] && ! nft_rules "$3"; }; then + log_test "$2" + return + fi + ip netns exec "$SRV_NS" ./sctp_ifwdtsn "$CLI_NS" "$1" + RET=$? + [ "$RET" -eq "$ksft_skip" ] || [ "$RET" -eq 0 ] || RET=$ksft_fail + log_test "$2" +} + +# Fragments of the abandoned message must not take fragments of a live +# message below the New Cumulative TSN with them, and the abandoned +# message's own received fragments must be freed. +test_ordered() +{ + run_helper ordered \ + "abandoned message does not purge ordered message" \ + "$NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 $NFT_FLAG_B drop" +} + +test_unordered() +{ + run_helper unordered \ + "abandoned message does not purge unordered message" \ + "$NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 $NFT_FLAG_B drop" +} + +# Drop the abandoned message and every packet after it until one starting +# with the I-FORWARD-TSN arrives, so that its New Cumulative TSN is the +# highest TSN received. This must not abort the partial delivery of the +# message on stream 0. +test_leading_edge() +{ + run_helper leading_edge \ + "I-FORWARD-TSN at the highest TSN is not a reset" " + $NFT_SCTP $NFT_CHUNK_IFWDTSN delete @blk { ip saddr } + $NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 add @blk { ip saddr } drop + $NFT_SCTP ip saddr @blk drop" +} + +# The same without partial delivery: the fragments of the message on +# stream 0 must not be freed. +test_leading_edge_nopd() +{ + run_helper leading_edge_nopd \ + "I-FORWARD-TSN at the highest TSN keeps other messages" " + $NFT_SCTP $NFT_CHUNK_IFWDTSN delete @blk { ip saddr } + $NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 add @blk { ip saddr } drop + $NFT_SCTP ip saddr @blk drop" +} + +# Abandon an unordered message during its partial delivery: the partial +# delivery must be aborted, and the next unordered message on the stream +# must not be appended to it. +test_uo_pd() +{ + run_helper uo_pd "abandoned unordered partial delivery is aborted" \ + "$NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 $NFT_FSN5 drop" +} + +# An SSN/TSN association reset with interleaving completes and leaves a +# working association. +test_reset() +{ + run_helper reset "association reset with interleaving" +} + +# Drop a fragment of the message on each stream and every +# I-FORWARD-TSN, so that both messages are left on the server when the +# reset is done. The reset must abort the partial delivery on stream 1 +# and free both. sctp_ifwdtsn releases the hold after the reset, before +# it sends a new message on stream 0 that reuses MID 0. +NFT_PENDING=" + $NFT_SCTP ip saddr @hold $NFT_CHUNK_IFWDTSN drop + $NFT_SCTP ip saddr @hold $NFT_CHUNK_IDATA $NFT_SID0 $NFT_FLAG_E drop + $NFT_SCTP ip saddr @hold $NFT_CHUNK_IDATA $NFT_SID1 $NFT_FSN5 drop" + +test_reset_pending_srv() +{ + run_helper reset_pending_srv \ + "association reset by the server frees pending data" \ + "$NFT_PENDING" +} + +test_reset_pending_cli() +{ + run_helper reset_pending_cli \ + "association reset by the client frees pending data" \ + "$NFT_PENDING" +} + +# Abandon two messages on a stream, the first one in partial delivery, +# and let one I-FORWARD-TSN below the highest TSN received skip both. The +# partial delivery abort must name the first message. I-FORWARD-TSNs are +# dropped until the marker on stream 0, sent once both messages are +# abandoned, arrives; any later one was sent after it. +NFT_PDAPI=" + $NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID0 delete @hold { ip saddr } + $NFT_SCTP ip saddr @hold $NFT_CHUNK_IFWDTSN drop + $NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 $NFT_MID0 $NFT_FSN5 drop + $NFT_SCTP $NFT_CHUNK_IDATA $NFT_SID1 $NFT_MID1 $NFT_FLAG_E drop" + +test_pdapi() +{ + run_helper pdapi "ordered partial delivery abort names its message" \ + "$NFT_PDAPI" +} + +test_pdapi_uo() +{ + run_helper pdapi_uo \ + "unordered partial delivery abort names its message" \ + "$NFT_PDAPI" +} + +require_command nft +require_command tc +modprobe -q sctp +if [ ! -d /proc/net/sctp ]; then + echo "SKIP: SCTP not available" + exit "$ksft_skip" +fi + +trap defer_scopes_cleanup EXIT + +tests_run + +exit "$EXIT_STATUS" diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c index c4203401c4bfc2..bd2797f9f619df 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -2580,6 +2580,42 @@ static const struct raw_rec id2_data_l0 = { }, }; +static void zero_len_sock_pair(struct __test_metadata *_metadata, + int *fd, int *cfd, bool *notls) +{ + struct tls_crypto_info_keys tls12; + int ret; + + tls_crypto_info_init(TLS_1_2_VERSION, TLS_CIPHER_AES_CCM_128, + &tls12, 0); + + ulp_sock_pair(_metadata, fd, cfd, notls); + if (*notls) + return; + + /* fd gets no keys, since these fixtures send raw records over it */ + ret = setsockopt(*cfd, SOL_TLS, TLS_RX, &tls12, tls12.len); + ASSERT_EQ(ret, 0); +} + +/* Send a variant's records and return the last one carrying payload */ +static const struct raw_rec * +zero_len_send_recs(struct __test_metadata *_metadata, int fd, + const struct raw_rec *const *recs) +{ + const struct raw_rec *payload = NULL; + int i; + + for (i = 0; i < 4 && recs[i]; i++) { + EXPECT_EQ(send(fd, recs[i]->cipher_data, recs[i]->cipher_len, 0), + recs[i]->cipher_len); + if (recs[i]->plain_len) + payload = recs[i]; + } + + return payload; +} + FIXTURE(zero_len) { int fd, cfd; @@ -2642,19 +2678,7 @@ FIXTURE_VARIANT_ADD(zero_len, data_0data_0data) FIXTURE_SETUP(zero_len) { - struct tls_crypto_info_keys tls12; - int ret; - - tls_crypto_info_init(TLS_1_2_VERSION, TLS_CIPHER_AES_CCM_128, - &tls12, 0); - - ulp_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); - if (self->notls) - return; - - /* Don't install keys on fd, we'll send raw records */ - ret = setsockopt(self->cfd, SOL_TLS, TLS_RX, &tls12, tls12.len); - ASSERT_EQ(ret, 0); + zero_len_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); } FIXTURE_TEARDOWN(zero_len) @@ -2670,10 +2694,10 @@ TEST_F(zero_len, test) int rec_off; int i; - for (i = 0; i < 4 && variant->recs[i]; i++) - EXPECT_EQ(send(self->fd, variant->recs[i]->cipher_data, - variant->recs[i]->cipher_len, 0), - variant->recs[i]->cipher_len); + if (self->notls) + SKIP(return, "no TLS support"); + + zero_len_send_recs(_metadata, self->fd, variant->recs); rec = &variant->recs[0]; rec_off = 0; @@ -2699,6 +2723,301 @@ TEST_F(zero_len, test) } }; +FIXTURE(zero_len_peek) +{ + int fd, cfd; + bool notls; +}; + +FIXTURE_VARIANT(zero_len_peek) +{ + const struct raw_rec *recs[4]; + ssize_t peek_ret; +}; + +FIXTURE_VARIANT_ADD(zero_len_peek, 0data_0data_data) +{ + .recs = { &id0_data_l0, &id1_data_l0, &id2_data_l11, }, + .peek_ret = 11, +}; + +FIXTURE_VARIANT_ADD(zero_len_peek, 0data_0data_0data) +{ + .recs = { &id0_data_l0, &id1_data_l0, &id2_data_l0, }, + .peek_ret = -EAGAIN, +}; + +FIXTURE_SETUP(zero_len_peek) +{ + zero_len_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); +} + +FIXTURE_TEARDOWN(zero_len_peek) +{ + close(self->fd); + close(self->cfd); +} + +/* Peeking past a run of empty data records must reach the payload + * behind them, and a run with no payload behind it must report EAGAIN + * and leave no record queued. + */ +TEST_F(zero_len_peek, test) +{ + struct pollfd pfd = { .fd = self->cfd, .events = POLLIN }; + const struct raw_rec *payload; + unsigned char buf[128]; + ssize_t ret; + + if (self->notls) + SKIP(return, "no TLS support"); + + payload = zero_len_send_recs(_metadata, self->fd, variant->recs); + + if (variant->peek_ret < 0) { + ret = recv(self->cfd, buf, sizeof(buf), + MSG_DONTWAIT | MSG_PEEK); + EXPECT_EQ(ret, -1); + EXPECT_EQ(errno, -variant->peek_ret); + + /* A record left on rx_list keeps the socket readable */ + EXPECT_EQ(poll(&pfd, 1, 0), 0); + return; + } + + ret = recv(self->cfd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK); + EXPECT_EQ(ret, variant->peek_ret); + if (ret == variant->peek_ret) + EXPECT_EQ(memcmp(buf, payload->plain_data, + variant->peek_ret), 0); + + ret = recv(self->cfd, buf, sizeof(buf), MSG_DONTWAIT); + EXPECT_EQ(ret, variant->peek_ret); + if (ret == variant->peek_ret) + EXPECT_EQ(memcmp(buf, payload->plain_data, + variant->peek_ret), 0); + + ret = recv(self->cfd, buf, sizeof(buf), MSG_DONTWAIT); + EXPECT_EQ(ret, -1); + EXPECT_EQ(errno, EAGAIN); +} + +FIXTURE(zero_len_splice) +{ + int fd, cfd; + bool notls; +}; + +FIXTURE_VARIANT(zero_len_splice) +{ + const struct raw_rec *recs[4]; + ssize_t splice_ret; +}; + +FIXTURE_VARIANT_ADD(zero_len_splice, 0data_data) +{ + .recs = { &id0_data_l0, &id1_data_l11, }, + .splice_ret = 11, +}; + +FIXTURE_VARIANT_ADD(zero_len_splice, 0data_0data_data) +{ + .recs = { &id0_data_l0, &id1_data_l0, &id2_data_l11, }, + .splice_ret = 11, +}; + +FIXTURE_VARIANT_ADD(zero_len_splice, 0data_0data_0data) +{ + .recs = { &id0_data_l0, &id1_data_l0, &id2_data_l0, }, + .splice_ret = -EAGAIN, +}; + +FIXTURE_VARIANT_ADD(zero_len_splice, 0data_0ctrl) +{ + .recs = { &id0_data_l0, &id1_ctrl_l0, }, + .splice_ret = -EINVAL, +}; + +FIXTURE_SETUP(zero_len_splice) +{ + zero_len_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); +} + +FIXTURE_TEARDOWN(zero_len_splice) +{ + close(self->fd); + close(self->cfd); +} + +/* Splicing must skip a run of empty data records to reach the payload + * behind it, since a zero-byte splice reads as EOF. Splice reports + * EAGAIN for a run with no payload behind it, and EINVAL for a control + * record behind the run. + */ +TEST_F(zero_len_splice, test) +{ + struct pollfd pfd = { .fd = self->cfd, .events = POLLIN }; + const struct raw_rec *payload; + unsigned char buf[128]; + ssize_t ret; + int p[2]; + + if (self->notls) + SKIP(return, "no TLS support"); + + ASSERT_GE(pipe(p), 0); + + payload = zero_len_send_recs(_metadata, self->fd, variant->recs); + + if (variant->splice_ret < 0) { + ret = splice(self->cfd, NULL, p[1], NULL, sizeof(buf), + SPLICE_F_NONBLOCK); + EXPECT_EQ(ret, -1); + EXPECT_EQ(errno, -variant->splice_ret); + } else { + /* ASSERT so a zero return stops the test before the read + * below blocks until the harness timeout. + */ + ASSERT_EQ(splice(self->cfd, NULL, p[1], NULL, sizeof(buf), + SPLICE_F_NONBLOCK), variant->splice_ret); + ret = read(p[0], buf, sizeof(buf)); + EXPECT_EQ(ret, variant->splice_ret); + if (ret == variant->splice_ret) + EXPECT_EQ(memcmp(buf, payload->plain_data, + variant->splice_ret), 0); + + /* The empty records were consumed, not left queued */ + EXPECT_EQ(poll(&pfd, 1, 0), 0); + } + + close(p[0]); + close(p[1]); +} + +FIXTURE(zero_len_run) +{ + int fd, cfd; + bool notls; +}; + +/* Before each of two reads, send n[i] empty records followed by a data + * record if data[i] is set. ret[i] is the result of the read. + */ +FIXTURE_VARIANT(zero_len_run) +{ + unsigned int n[2]; + bool data[2]; + int ret[2]; +}; + +FIXTURE_VARIANT_ADD(zero_len_run, 128) +{ + .n = { 128, 0, }, + .data = { true, false, }, + .ret = { 4, -EAGAIN, }, +}; + +/* More than 128 consecutive empty records break the connection */ +FIXTURE_VARIANT_ADD(zero_len_run, 129) +{ + .n = { 129, 0, }, + .data = { true, false, }, + .ret = { -EBADMSG, -EAGAIN, }, +}; + +/* The count starts over on every read */ +FIXTURE_VARIANT_ADD(zero_len_run, 128_128) +{ + .n = { 128, 128, }, + .data = { false, true, }, + .ret = { -EAGAIN, 4, }, +}; + +FIXTURE_SETUP(zero_len_run) +{ + struct tls_crypto_info_keys tls13; + int ret; + + tls_crypto_info_init(TLS_1_3_VERSION, TLS_CIPHER_AES_GCM_128, + &tls13, 0); + + ulp_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); + if (self->notls) + return; + + ret = setsockopt(self->fd, SOL_TLS, TLS_TX, &tls13, tls13.len); + ASSERT_EQ(ret, 0); + ret = setsockopt(self->cfd, SOL_TLS, TLS_RX, &tls13, tls13.len); + ASSERT_EQ(ret, 0); +} + +FIXTURE_TEARDOWN(zero_len_run) +{ + close(self->fd); + close(self->cfd); +} + +static void zero_len_run_send(struct __test_metadata *_metadata, int fd, + const FIXTURE_VARIANT(zero_len_run) *variant, + int i) +{ + /* kTLS cannot send an empty record. Send the data content type as + * the only byte of a record of type 0 instead, the receiver strips + * the 0 as padding and sees an empty data record. + */ + char data_type = 0x17; + unsigned int j; + + for (j = 0; j < variant->n[i]; j++) + ASSERT_EQ(tls_send_cmsg(fd, 0, &data_type, 1, 0), 1); + if (variant->data[i]) + ASSERT_EQ(send(fd, "data", 4, 0), 4); +} + +static void zero_len_run_expect(struct __test_metadata *_metadata, + ssize_t ret, int expected) +{ + EXPECT_EQ(ret, expected >= 0 ? expected : -1); + if (expected < 0) + EXPECT_EQ(errno, -expected); +} + +TEST_F(zero_len_run, recv) +{ + char buf[16]; + int i; + + if (self->notls) + SKIP(return, "no TLS support"); + + for (i = 0; i < 2; i++) { + zero_len_run_send(_metadata, self->fd, variant, i); + zero_len_run_expect(_metadata, + recv(self->cfd, buf, sizeof(buf), + MSG_DONTWAIT), + variant->ret[i]); + } +} + +TEST_F(zero_len_run, splice) +{ + int i, p[2]; + + if (self->notls) + SKIP(return, "no TLS support"); + + ASSERT_GE(pipe(p), 0); + for (i = 0; i < 2; i++) { + zero_len_run_send(_metadata, self->fd, variant, i); + zero_len_run_expect(_metadata, + splice(self->cfd, NULL, p[1], NULL, 16, + SPLICE_F_NONBLOCK), + variant->ret[i]); + } + close(p[0]); + close(p[1]); +} + FIXTURE(tls_err) { int fd, cfd; diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh index 17cfe412a2667c..64c2a5a59821df 100755 --- a/tools/testing/selftests/net/veth.sh +++ b/tools/testing/selftests/net/veth.sh @@ -41,13 +41,16 @@ create_ns() { ip -n $ns link set dev lo up done - ip link add name veth$SRC type veth peer name veth$DST + ip link add name "veth$SRC" "$@" type veth \ + peer name "veth$DST" "$@" || return 1 for ns in $SRC $DST; do ip link set dev veth$ns netns $BASE$ns up ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad done + + return 0 } __chk_flag() { @@ -130,6 +133,78 @@ chk_channels() { fi } +chk_carrier() ( + target=$1 + state=$2 + expected=$3 + carrier=0 + + # IFF_LOWER_UP is reported only for running interfaces. + [ "$state" = up ] || return 0 + + if ! link=$(ip -n "$BASE$target" -o link show dev "veth$target"); then + echo " fail - cannot read veth$target link state" + return 1 + fi + case "$link" in + *LOWER_UP*) carrier=1 ;; + esac + if [ "$carrier" -ne "$expected" ]; then + printf ' fail - veth%s carrier is %s, expected %s\n' \ + "$target" "$carrier" "$expected" + return 1 + fi +) + +# Keep per-case variables separate from the other tests. +chk_channels_carrier() ( + src_state=$1 + dst_state=$2 + expected=0 + err=0 + msg="carrier after channel change ($src_state/$dst_state)" + + if ! create_ns numtxqueues 2 numrxqueues 2; then + printf "%-60s" "$msg" + echo " skip - cannot create veth pair" + cleanup + return 0 + fi + + ip -n "$NS_SRC" link set dev "veth$SRC" "$src_state" || err=1 + ip -n "$NS_DST" link set dev "veth$DST" "$dst_state" || err=1 + [ "$src_state" = up ] && [ "$dst_state" = up ] && expected=1 + chk_carrier "$SRC" "$src_state" "$expected" || err=1 + chk_carrier "$DST" "$dst_state" "$expected" || err=1 + + for target in "$SRC" "$DST"; do + for count in 1 2; do + ip netns exec "$BASE$target" ethtool -L "veth$target" \ + rx "$count" tx "$count" || err=1 + chk_carrier "$SRC" "$src_state" "$expected" || err=1 + chk_carrier "$DST" "$dst_state" "$expected" || err=1 + done + + if ip netns exec "$BASE$target" ethtool -L "veth$target" \ + rx 3 tx 3 \ + >/dev/null 2>&1; then + echo " fail - out-of-range channel counts were accepted" + err=1 + fi + chk_carrier "$SRC" "$src_state" "$expected" || err=1 + chk_carrier "$DST" "$dst_state" "$expected" || err=1 + done + + cleanup + printf "%-60s" "$msg" + if [ "$err" -eq 0 ]; then + echo " ok " + else + echo " fail " + fi + return "$err" +) + chk_gro() { local msg="$1" local expected=$2 @@ -257,6 +332,10 @@ fi [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too" [ ! -f "$YNL" ] && echo "ynl cli not found, ndo-xmit tests will be skipped" +chk_channels_carrier up up || ret=1 +chk_channels_carrier up down || ret=1 +chk_channels_carrier down up || ret=1 + create_ns chk_gro_flag "default - gro flag" $SRC off chk_gro_flag " - peer gro flag" $DST off diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json index 0179c57104adbf..ab5d0881c0070c 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json @@ -90,12 +90,8 @@ "ets", "tbf" ], - "plugins": { - "requires": [ - "nsPlugin" - ] - }, "setup": [ + "$IP link add dev $DUMMY type dummy", "$TC qdisc add dev $DUMMY root handle 1: qfq", "$TC class add dev $DUMMY parent 1: classid 1:1 qfq weight 15 maxpkt 16384" ], @@ -104,7 +100,35 @@ "verifyCmd": "$TC -s -j qdisc ls dev $DUMMY parent 1:1", "matchJSON": [], "teardown": [ - "$TC qdisc del dev $DUMMY root handle 1:" + "$TC qdisc del dev $DUMMY root handle 1:", + "$IP link del dev $DUMMY" + ] + }, + { + "id": "6a06", + "name": "Reject TEQL attach from a different network namespace", + "category": [ + "qdisc", + "teql" + ], + "plugins": { + "requires": [ + "nsPlugin" + ] + }, + "setup": [], + "cmdUnderTest": "$TC qdisc add dev $DUMMY root handle 3: teql0", + "expExitCode": "2", + "verifyCmd": "$TC qdisc show dev $DUMMY", + "matchPattern": "qdisc teql0 3: root", + "matchCount": "0", + "teardown": [ + [ + "$TC qdisc del dev $DUMMY root handle 3:", + 0, + 1, + 2 + ] ] } ] diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index fc64b8f028332a..1a50d4695c9fa3 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)/usr/include +CFLAGS += -D_FILE_OFFSET_BITS=64 ifneq ($(WERROR),0) CFLAGS += -Werror endif diff --git a/tools/testing/selftests/ublk/batch.c b/tools/testing/selftests/ublk/batch.c index dfc81ee17d076f..625a9c32a80b17 100644 --- a/tools/testing/selftests/ublk/batch.c +++ b/tools/testing/selftests/ublk/batch.c @@ -376,10 +376,10 @@ static int __ublk_batch_queue_prep_io_cmds(struct ublk_thread *t, struct ublk_qu if (ublk_queue_use_auto_zc(q)) elem->buf_index = ublk_batch_io_buf_idx(t, q, i); else if (!ublk_queue_no_buf(q)) - elem->buf_addr = (__u64)io->buf_addr; + elem->buf_addr = (__u64)(uintptr_t)io->buf_addr; } - sqe->addr = (__u64)buf; + sqe->addr = (__u64)(uintptr_t)buf; sqe->len = t->commit_buf_elem_size * nr_elem; ublk_init_batch_cmd(t, q->q_id, sqe, UBLK_U_IO_PREP_IO_CMDS, @@ -473,7 +473,7 @@ static void __ublk_batch_commit_io_cmds(struct ublk_thread *t, ublk_io_alloc_sqes(t, &sqe, 1); buf_idx = cb->buf_idx; - sqe->addr = (__u64)cb->elem; + sqe->addr = (__u64)(uintptr_t)cb->elem; sqe->len = nr_elem * t->commit_buf_elem_size; /* commit isn't per-queue command */ diff --git a/tools/testing/selftests/ublk/ctrl.c b/tools/testing/selftests/ublk/ctrl.c index 53d54799f90976..5e0762cfc4eae9 100644 --- a/tools/testing/selftests/ublk/ctrl.c +++ b/tools/testing/selftests/ublk/ctrl.c @@ -204,7 +204,7 @@ int ublk_ctrl_get_params(struct ublk_dev *dev, struct ublk_ctrl_cmd_data data = { .cmd_op = UBLK_U_CMD_GET_PARAMS, .flags = CTRL_CMD_HAS_BUF, - .addr = (__u64)params, + .addr = (__u64)(uintptr_t)params, .len = sizeof(*params), }; diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c index 5a4ff689c1f7a3..115f25351d3090 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -148,7 +148,7 @@ static int ublk_ctrl_get_affinity(struct ublk_dev *ctrl_dev, cpu_set_t **ptr_buf for (i = 0; i < ctrl_dev->dev_info.nr_hw_queues; i++) { data.data[0] = i; data.len = sizeof(cpu_set_t); - data.addr = (__u64)&buf[i]; + data.addr = (__u64)(uintptr_t)&buf[i]; ret = __ublk_ctrl_cmd(ctrl_dev, &data); if (ret < 0) { diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h index f449129ea97a9c..dc4927d26296cb 100644 --- a/tools/testing/vma/include/dup.h +++ b/tools/testing/vma/include/dup.h @@ -366,6 +366,9 @@ enum { #define VMA_LOCKED_MASK mk_vma_flags(VMA_LOCKED_BIT, VMA_LOCKONFAULT_BIT) +/* These flags can be updated atomically via VMA/mmap read lock. */ +#define VMA_ATOMIC_SET_ALLOWED mk_vma_flags(VMA_MAYBE_GUARD_BIT) + #define RLIMIT_STACK 3 /* max stack size */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ @@ -895,22 +898,6 @@ static inline void vm_flags_reset(struct vm_area_struct *vma, vm_flags_init(vma, flags); } -static inline void vma_flags_reset_once(struct vm_area_struct *vma, - vma_flags_t *flags) -{ - const unsigned long word = flags->__vma_flags[0]; - - /* It is assumed only the first system word must be written once. */ - vma_flags_overwrite_word_once(&vma->flags, word); - /* The remainder can be copied normally. */ - if (NUM_VMA_FLAG_BITS > BITS_PER_LONG) { - unsigned long *dst = &vma->flags.__vma_flags[1]; - const unsigned long *src = &flags->__vma_flags[1]; - - bitmap_copy(dst, src, NUM_VMA_FLAG_BITS - BITS_PER_LONG); - } -} - static inline void vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags) { @@ -1037,27 +1024,24 @@ static __always_inline vma_flags_t vma_flags_diff_pair(const vma_flags_t *flags, return dst; } +/* + * Determine if flags and flags_other have precisely the same flags set, + * excluding atomic VMA flags. + */ static __always_inline bool vma_flags_same_pair(const vma_flags_t *flags, - const vma_flags_t *flags_other) + const vma_flags_t *flags_other) { - const unsigned long *bitmap = flags->__vma_flags; - const unsigned long *bitmap_other = flags_other->__vma_flags; + vma_flags_t diff = vma_flags_diff_pair(flags, flags_other); - return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); -} - -static __always_inline bool vma_flags_same_mask(const vma_flags_t *flags, - vma_flags_t flags_other) -{ - const unsigned long *bitmap = flags->__vma_flags; - const unsigned long *bitmap_other = flags_other.__vma_flags; + /* + * Atomic VMA flags may be set concurrently under the VMA read lock, so + * are disregarded for equality testing purposes. + */ + vma_flags_clear_mask(&diff, VMA_ATOMIC_SET_ALLOWED); - return bitmap_equal(bitmap, bitmap_other, NUM_VMA_FLAG_BITS); + return vma_flags_empty(&diff); } -#define vma_flags_same(flags, ...) \ - vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__)) - static __always_inline bool vma_test(const struct vm_area_struct *vma, vma_flag_t bit) { @@ -1106,6 +1090,36 @@ static __always_inline void vma_clear_flags_mask(struct vm_area_struct *vma, #define vma_clear_flags(vma, ...) \ vma_clear_flags_mask(vma, mk_vma_flags(__VA_ARGS__)) +/* + * Overwrite the VMA's flags with new ones, preserving atomic VMA flags in the + * process. The write is done once and once only. + */ +static inline void vma_overwrite_flags(struct vm_area_struct *vma, + vma_flags_t new_flags) +{ + vma_flags_t atomic; + + vma_assert_write_locked(vma); + + /* + * Preserve the VMA's atomic flags, which are kept stable by the VMA + * write lock. + */ + atomic = vma_flags_and_mask(&vma->flags, VMA_ATOMIC_SET_ALLOWED); + vma_flags_clear_mask(&new_flags, VMA_ATOMIC_SET_ALLOWED); + vma_flags_set_mask(&new_flags, atomic); + + /* It is assumed only the first system word must be written once. */ + vma_flags_overwrite_word_once(&vma->flags, new_flags.__vma_flags[0]); + /* The remainder can be copied normally. */ + if (NUM_VMA_FLAG_BITS > BITS_PER_LONG) { + unsigned long *dst = &vma->flags.__vma_flags[1]; + const unsigned long *src = &new_flags.__vma_flags[1]; + + bitmap_copy(dst, src, NUM_VMA_FLAG_BITS - BITS_PER_LONG); + } +} + static __always_inline bool vma_desc_test(const struct vm_area_desc *desc, vma_flag_t bit) { @@ -1198,7 +1212,7 @@ static inline void vma_assert_detached(struct vm_area_struct *vma) WARN_ON_ONCE(vma_is_attached(vma)); } -static inline void vma_assert_write_locked(struct vm_area_struct *); +static inline void vma_assert_write_locked(const struct vm_area_struct *); static inline void vma_mark_attached(struct vm_area_struct *vma) { vma_assert_write_locked(vma); @@ -1727,3 +1741,8 @@ static inline bool vma_flags_can_merge(const vma_flags_t *flags) */ return !vma_flags_is_hugetlb(flags); } + +static inline bool vma_can_merge(const struct vm_area_struct *vma) +{ + return vma_flags_can_merge(&vma->flags); +} diff --git a/tools/testing/vma/include/stubs.h b/tools/testing/vma/include/stubs.h index f786a585caf057..8d030a3ace8485 100644 --- a/tools/testing/vma/include/stubs.h +++ b/tools/testing/vma/include/stubs.h @@ -320,7 +320,7 @@ static inline void anon_vma_lock_write(struct anon_vma *anon_vma) { } -static inline void vma_assert_write_locked(struct vm_area_struct *vma) +static inline void vma_assert_write_locked(const struct vm_area_struct *vma) { } diff --git a/tools/testing/vma/shared.h b/tools/testing/vma/shared.h index 97cd7a679dc195..646edf367d7c44 100644 --- a/tools/testing/vma/shared.h +++ b/tools/testing/vma/shared.h @@ -51,17 +51,21 @@ __TO_SCALAR(__val1), __TO_SCALAR(__val2)); \ } while (0) -#define ASSERT_FLAGS_SAME_MASK(_flags, _flags_other) \ - ASSERT_TRUE(vma_flags_same_mask((_flags), (_flags_other))) +#define ASSERT_FLAGS_SAME_MASK(_flags, _flags_other) do { \ + const vma_flags_t __flags_other = (_flags_other); \ + ASSERT_TRUE(vma_flags_same_pair((_flags), &__flags_other)); \ + } while (0) -#define ASSERT_FLAGS_NOT_SAME_MASK(_flags, _flags_other) \ - ASSERT_FALSE(vma_flags_same_mask((_flags), (_flags_other))) +#define ASSERT_FLAGS_NOT_SAME_MASK(_flags, _flags_other) do { \ + const vma_flags_t __flags_other = (_flags_other); \ + ASSERT_FALSE(vma_flags_same_pair((_flags), &__flags_other)); \ + } while (0) #define ASSERT_FLAGS_SAME(_flags, ...) \ - ASSERT_TRUE(vma_flags_same(_flags, __VA_ARGS__)) + ASSERT_FLAGS_SAME_MASK(_flags, mk_vma_flags(__VA_ARGS__)) #define ASSERT_FLAGS_NOT_SAME(_flags, ...) \ - ASSERT_FALSE(vma_flags_same(_flags, __VA_ARGS__)) + ASSERT_FLAGS_NOT_SAME_MASK(_flags, mk_vma_flags(__VA_ARGS__)) #define ASSERT_FLAGS_EMPTY(_flags) \ ASSERT_TRUE(vma_flags_empty(_flags)) diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c index 84961b9ab5ffd5..2a5d7f7d2d6ce8 100644 --- a/tools/virtio/vringh_test.c +++ b/tools/virtio/vringh_test.c @@ -458,6 +458,8 @@ int main(int argc, char *argv[]) int err; unsigned i; void *ret; + struct vring_desc *ind; + char *data; bool (*getrange)(struct vringh *vrh, u64 addr, struct vringh_range *r); bool fast_vringh = false, parallel = false; @@ -755,6 +757,45 @@ int main(int argc, char *argv[]) vringh_iov_cleanup(&riov); } + /* + * Regression test: a top-level indirect descriptor whose NEXT + * points back to itself must be rejected with -ELOOP instead of + * looping forever. Use index 1 rather than 0 so that returning + * from the indirect table re-enters the same top-level descriptor. + */ + ind = __user_addr_max - USER_MEM/2; + data = __user_addr_max - USER_MEM/4; + + /* Fresh ring and host state; resets last_avail_idx to 0. */ + vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN); + vringh_init_user(&vrh, vdev.features, RINGSIZE, true, + vrh.vring.desc, vrh.vring.avail, vrh.vring.used); + + /* Single-entry indirect table pointing at valid data. */ + ind[0].addr = (unsigned long)data; + ind[0].len = 1; + ind[0].flags = 0; + + /* Top-level desc[1]: INDIRECT, and NEXT loops back to itself. */ + vrh.vring.desc[1].addr = (unsigned long)ind; + vrh.vring.desc[1].len = sizeof(*ind); + vrh.vring.desc[1].flags = VRING_DESC_F_INDIRECT | VRING_DESC_F_NEXT; + vrh.vring.desc[1].next = 1; + + /* Publish head 1 on the avail ring. */ + vrh.vring.avail->ring[0] = 1; + vrh.vring.avail->idx = 1; + + vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov)); + vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov)); + + err = vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head); + if (err != -ELOOP) + errx(1, "self-referential indirect: %i not -ELOOP", err); + + vringh_iov_cleanup(&riov); + vringh_iov_cleanup(&wiov); + /* Don't leak memory... */ vring_del_virtqueue(vq); free(__user_addr_min);