Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mux: mmio: Zero the allocated memory

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>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
88cf8a9a 678f946b

+5 -3
+5 -3
drivers/mux/mmio.c
··· 100 100 101 101 mux_mmio = mux_chip_priv(mux_chip); 102 102 103 - mux_mmio->fields = devm_kmalloc(dev, num_fields * sizeof(*mux_mmio->fields), GFP_KERNEL); 103 + mux_mmio->fields = devm_kcalloc(dev, num_fields, sizeof(*mux_mmio->fields), 104 + GFP_KERNEL); 104 105 if (!mux_mmio->fields) 105 106 return -ENOMEM; 106 107 107 - mux_mmio->hardware_states = devm_kmalloc(dev, num_fields * 108 - sizeof(*mux_mmio->hardware_states), GFP_KERNEL); 108 + mux_mmio->hardware_states = devm_kcalloc(dev, num_fields, 109 + sizeof(*mux_mmio->hardware_states), 110 + GFP_KERNEL); 109 111 if (!mux_mmio->hardware_states) 110 112 return -ENOMEM; 111 113