treewide: Replace more open-coded allocation size multiplications
As done treewide earlier, this catches several more open-coded allocation size calculations that were added to the kernel during the merge window. This performs the following mechanical transformations using Coccinelle: kvmalloc(a * b, ...) -> kvmalloc_array(a, b, ...) kvzalloc(a * b, ...) -> kvcalloc(a, b, ...) devm_kzalloc(..., a * b, ...) -> devm_kcalloc(..., a, b, ...) Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
57361846b5
commit
329e098939
|
@ -1322,7 +1322,7 @@ static int qca_init_regulators(struct qca_power *qca,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
qca->vreg_bulk = devm_kzalloc(qca->dev, num_vregs *
|
qca->vreg_bulk = devm_kcalloc(qca->dev, num_vregs,
|
||||||
sizeof(struct regulator_bulk_data),
|
sizeof(struct regulator_bulk_data),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!qca->vreg_bulk)
|
if (!qca->vreg_bulk)
|
||||||
|
|
|
@ -1044,7 +1044,8 @@ static int safexcel_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
safexcel_configure(priv);
|
safexcel_configure(priv);
|
||||||
|
|
||||||
priv->ring = devm_kzalloc(dev, priv->config.rings * sizeof(*priv->ring),
|
priv->ring = devm_kcalloc(dev, priv->config.rings,
|
||||||
|
sizeof(*priv->ring),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!priv->ring) {
|
if (!priv->ring) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
@ -1063,8 +1064,9 @@ static int safexcel_probe(struct platform_device *pdev)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_reg_clk;
|
goto err_reg_clk;
|
||||||
|
|
||||||
priv->ring[i].rdr_req = devm_kzalloc(dev,
|
priv->ring[i].rdr_req = devm_kcalloc(dev,
|
||||||
sizeof(priv->ring[i].rdr_req) * EIP197_DEFAULT_RING_SIZE,
|
EIP197_DEFAULT_RING_SIZE,
|
||||||
|
sizeof(priv->ring[i].rdr_req),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!priv->ring[i].rdr_req) {
|
if (!priv->ring[i].rdr_req) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
|
|
@ -600,7 +600,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
mtk_crtc->layer_nr = mtk_ddp_comp_layer_nr(mtk_crtc->ddp_comp[0]);
|
mtk_crtc->layer_nr = mtk_ddp_comp_layer_nr(mtk_crtc->ddp_comp[0]);
|
||||||
mtk_crtc->planes = devm_kzalloc(dev, mtk_crtc->layer_nr *
|
mtk_crtc->planes = devm_kcalloc(dev, mtk_crtc->layer_nr,
|
||||||
sizeof(struct drm_plane),
|
sizeof(struct drm_plane),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
|
||||||
|
|
|
@ -153,8 +153,8 @@ int msm_dss_parse_clock(struct platform_device *pdev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp->clk_config = devm_kzalloc(&pdev->dev,
|
mp->clk_config = devm_kcalloc(&pdev->dev,
|
||||||
sizeof(struct dss_clk) * num_clk,
|
num_clk, sizeof(struct dss_clk),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!mp->clk_config)
|
if (!mp->clk_config)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
@ -908,7 +908,7 @@ static int npcm7xx_en_pwm_fan(struct device *dev,
|
||||||
if (fan_cnt < 1)
|
if (fan_cnt < 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
fan_ch = devm_kzalloc(dev, sizeof(*fan_ch) * fan_cnt, GFP_KERNEL);
|
fan_ch = devm_kcalloc(dev, fan_cnt, sizeof(*fan_ch), GFP_KERNEL);
|
||||||
if (!fan_ch)
|
if (!fan_ch)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -3462,7 +3462,8 @@ try_smaller_buffer:
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
ic->recalc_tags = kvmalloc((RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size, GFP_KERNEL);
|
ic->recalc_tags = kvmalloc_array(RECALC_SECTORS >> ic->sb->log2_sectors_per_block,
|
||||||
|
ic->tag_size, GFP_KERNEL);
|
||||||
if (!ic->recalc_tags) {
|
if (!ic->recalc_tags) {
|
||||||
ti->error = "Cannot allocate tags for recalculating";
|
ti->error = "Cannot allocate tags for recalculating";
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
|
|
|
@ -258,7 +258,7 @@ int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
|
||||||
if (!buf->urb)
|
if (!buf->urb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
buf->urb->sg = devm_kzalloc(dev->dev, nsgs * sizeof(*buf->urb->sg),
|
buf->urb->sg = devm_kcalloc(dev->dev, nsgs, sizeof(*buf->urb->sg),
|
||||||
gfp);
|
gfp);
|
||||||
if (!buf->urb->sg)
|
if (!buf->urb->sg)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -464,8 +464,8 @@ static int mt76u_alloc_rx(struct mt76_dev *dev)
|
||||||
int i, err, nsgs;
|
int i, err, nsgs;
|
||||||
|
|
||||||
spin_lock_init(&q->lock);
|
spin_lock_init(&q->lock);
|
||||||
q->entry = devm_kzalloc(dev->dev,
|
q->entry = devm_kcalloc(dev->dev,
|
||||||
MT_NUM_RX_ENTRIES * sizeof(*q->entry),
|
MT_NUM_RX_ENTRIES, sizeof(*q->entry),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!q->entry)
|
if (!q->entry)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -717,8 +717,8 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
|
||||||
INIT_LIST_HEAD(&q->swq);
|
INIT_LIST_HEAD(&q->swq);
|
||||||
q->hw_idx = q2hwq(i);
|
q->hw_idx = q2hwq(i);
|
||||||
|
|
||||||
q->entry = devm_kzalloc(dev->dev,
|
q->entry = devm_kcalloc(dev->dev,
|
||||||
MT_NUM_TX_ENTRIES * sizeof(*q->entry),
|
MT_NUM_TX_ENTRIES, sizeof(*q->entry),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!q->entry)
|
if (!q->entry)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
@ -180,11 +180,11 @@ int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
phy = devm_kzalloc(dev, sizeof(*phy) * phy_count, GFP_KERNEL);
|
phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL);
|
||||||
if (!phy)
|
if (!phy)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
link = devm_kzalloc(dev, sizeof(*link) * phy_count, GFP_KERNEL);
|
link = devm_kcalloc(dev, phy_count, sizeof(*link), GFP_KERNEL);
|
||||||
if (!link)
|
if (!link)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -868,8 +868,8 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport)
|
||||||
geni_se_init(&port->se, port->rx_wm, port->rx_rfr);
|
geni_se_init(&port->se, port->rx_wm, port->rx_rfr);
|
||||||
geni_se_select_mode(&port->se, port->xfer_mode);
|
geni_se_select_mode(&port->se, port->xfer_mode);
|
||||||
if (!uart_console(uport)) {
|
if (!uart_console(uport)) {
|
||||||
port->rx_fifo = devm_kzalloc(uport->dev,
|
port->rx_fifo = devm_kcalloc(uport->dev,
|
||||||
port->rx_fifo_depth * sizeof(u32), GFP_KERNEL);
|
port->rx_fifo_depth, sizeof(u32), GFP_KERNEL);
|
||||||
if (!port->rx_fifo)
|
if (!port->rx_fifo)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2644,7 +2644,7 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt,
|
||||||
for (i = 1; i <= CAKE_QUEUES; i++)
|
for (i = 1; i <= CAKE_QUEUES; i++)
|
||||||
quantum_div[i] = 65535 / i;
|
quantum_div[i] = 65535 / i;
|
||||||
|
|
||||||
q->tins = kvzalloc(CAKE_MAX_TINS * sizeof(struct cake_tin_data),
|
q->tins = kvcalloc(CAKE_MAX_TINS, sizeof(struct cake_tin_data),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!q->tins)
|
if (!q->tins)
|
||||||
goto nomem;
|
goto nomem;
|
||||||
|
|
Loading…
Reference in New Issue