Commit c2b32e58 authored by Daniel Mack's avatar Daniel Mack Committed by David S. Miller

net: ethernet: cpsw: improve interrupt lookup logic in cpsw_probe()

Simplify the interrupt resource lookup code in cpsw_probe() by the
following:

 * Only look at the first member of the resource. As the driver only
   works for DT-enabled platforms anyway, a resource of type
   IORESOURCE_IRQ will only contain one single entry
   (res->start == res->end), so there is no need for the iteration.

 * Add a bounds check to avoid overflows if we are passed more than
   ARRAY_SIZE(priv->irqs_table) resources.

 * Assign 'ret' with the return value of devm_request_irq() so that
   cpsw_probe() returns the appropriate error code.

 * If devm_request_irq() fails, report the error code in the log
   message.
Signed-off-by: default avatarDaniel Mack <zonque@gmail.com>
Acked-by: default avatarMugunthan V N <mugunthanvnm@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent caa41527
...@@ -2232,18 +2232,24 @@ static int cpsw_probe(struct platform_device *pdev) ...@@ -2232,18 +2232,24 @@ static int cpsw_probe(struct platform_device *pdev)
} }
while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) { while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) {
for (i = res->start; i <= res->end; i++) { if (k >= ARRAY_SIZE(priv->irqs_table)) {
if (devm_request_irq(&pdev->dev, i, cpsw_interrupt, 0, ret = -EINVAL;
dev_name(&pdev->dev), priv)) {
dev_err(priv->dev, "error attaching irq\n");
goto clean_ale_ret; goto clean_ale_ret;
} }
priv->irqs_table[k] = i;
priv->num_irqs = k + 1; ret = devm_request_irq(&pdev->dev, res->start, cpsw_interrupt,
0, dev_name(&pdev->dev), priv);
if (ret < 0) {
dev_err(priv->dev, "error attaching irq (%d)\n", ret);
goto clean_ale_ret;
} }
priv->irqs_table[k] = res->start;
k++; k++;
} }
priv->num_irqs = k;
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
ndev->netdev_ops = &cpsw_netdev_ops; ndev->netdev_ops = &cpsw_netdev_ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment