]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
dmaengine: pl08x: Use kcalloc() instead of kzalloc()
authorErick Archer <erick.archer@outlook.com>
Sat, 30 Mar 2024 15:23:23 +0000 (16:23 +0100)
committerVinod Koul <vkoul@kernel.org>
Wed, 17 Apr 2024 17:13:17 +0000 (22:43 +0530)
This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1].

Here the multiplication is obviously safe because the "channels"
member can only be 8 or 2. This value is set when the "vendor_data"
structs are initialized.

static struct vendor_data vendor_pl080 = {
[...]
.channels = 8,
[...]
};

static struct vendor_data vendor_nomadik = {
[...]
.channels = 8,
[...]
};

static struct vendor_data vendor_pl080s = {
[...]
.channels = 8,
[...]
};

static struct vendor_data vendor_pl081 = {
[...]
.channels = 2,
[...]
};

However, using kcalloc() is more appropriate [1] and improves
readability. This patch has no effect on runtime behavior.

Link: https://github.com/KSPP/linux/issues/162
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Erick Archer <erick.archer@outlook.com>
Link: https://lore.kernel.org/r/AS8PR02MB72373D9261B3B166048A8E218B392@AS8PR02MB7237.eurprd02.prod.outlook.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/amba-pl08x.c

index fbf048f432bf8f16d5b97b88b4c02851367d9924..73a5cfb4da8a6de54ff7da245406b84997c97d5e 100644 (file)
@@ -2855,8 +2855,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
        }
 
        /* Initialize physical channels */
-       pl08x->phy_chans = kzalloc((vd->channels * sizeof(*pl08x->phy_chans)),
-                       GFP_KERNEL);
+       pl08x->phy_chans = kcalloc(vd->channels, sizeof(*pl08x->phy_chans),
+                                  GFP_KERNEL);
        if (!pl08x->phy_chans) {
                ret = -ENOMEM;
                goto out_no_phychans;