]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mux: mmio: Zero the allocated memory
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Tue, 17 Mar 2026 15:20:30 +0000 (16:20 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Mar 2026 15:38:25 +0000 (16:38 +0100)
Zero the allocated memory in probe() for fields and hardware states
because:

1. The "hardware_states" array is not initialized in the probe, thus
   starting the device with uninitialized memory.  This not a bug,
   because pointed memory will be assigned in suspend callback, however
   it is a discouraged coding practice.
   The "fields" array is initialized shortly further in the probe().

2. Linux kernel convention for safer code encourages using zeroed
   allocations, as expressed in memory-allocation.rst document.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260317152029.274829-2-krzysztof.kozlowski@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mux/mmio.c

index 0611ef28bb69ab492976223a7b26582d9abdec8b..b61e590f2ac9e7b24e2408cea64660db1cf60ff5 100644 (file)
@@ -100,12 +100,14 @@ static int mux_mmio_probe(struct platform_device *pdev)
 
        mux_mmio = mux_chip_priv(mux_chip);
 
-       mux_mmio->fields = devm_kmalloc(dev, num_fields * sizeof(*mux_mmio->fields), GFP_KERNEL);
+       mux_mmio->fields = devm_kcalloc(dev, num_fields, sizeof(*mux_mmio->fields),
+                                       GFP_KERNEL);
        if (!mux_mmio->fields)
                return -ENOMEM;
 
-       mux_mmio->hardware_states = devm_kmalloc(dev, num_fields *
-                                                sizeof(*mux_mmio->hardware_states), GFP_KERNEL);
+       mux_mmio->hardware_states = devm_kcalloc(dev, num_fields,
+                                                sizeof(*mux_mmio->hardware_states),
+                                                GFP_KERNEL);
        if (!mux_mmio->hardware_states)
                return -ENOMEM;