dmaengine: pl08x: Use kcalloc() instead of kzalloc()
PATCH 1/1 dmaengine: pl08x: Use kcalloc() instead of kzalloc()
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.
--- drivers/dma/amba-pl08x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/amba-pl08x.c +2 -2
@@ -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;
--
2.25.1
Quoted 31 lines · Erick Archer
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, [...] };
Quoted 6 lines
However, using
kcalloc()is more appropriate [1] and improves readability. This patch has no effect on runtime behavior.
Thanks!
Signature · 1 line
Gustavo
Quoted 22 lines
--- drivers/dma/amba-pl08x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/dma/amba-pl08x.c +2
-3@@ -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; --2.25.1