All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: davem@davemloft.net
Cc: julia.lawall@lip6.fr, netdev@vger.kernel.org,
	mugunthanvnm@ti.com, george.cherian@ti.com,
	Daniel Mack <zonque@gmail.com>
Subject: [PATCH 2/2] net: ethernet: cpsw: fix interrupt lookup logic in cpsw_probe()
Date: Tue,  2 Sep 2014 18:44:05 +0200	[thread overview]
Message-ID: <1409676245-13897-2-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1409676245-13897-1-git-send-email-zonque@gmail.com>

The code in cpsw_probe() currently iterates over the available
interrupt resources and requests each of them.  While doing so, it
keeps track of their indices through priv->irqs_table.

However, the code currently only remembers the last interrupt in
a resource, and will leak the others if there is more than one.
This can only happen for board-file driven platforms and not via DT,
however.

Also, there is currently no bounds check, while priv->irqs_table is a
fixed-size array. If we are passed more than 4 resources, we're in
trouble.

This patch introduces a bounds check and changes the way interrupt
indices are kept. Tested on a Beagle Bone Black board only.

Signed-off-by: Daniel Mack <zonque@gmail.com>
---
 drivers/net/ethernet/ti/cpsw.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index cdbbb58..e747e55 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2233,13 +2233,18 @@ static int cpsw_probe(struct platform_device *pdev)
 
 	while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) {
 		for (i = res->start; i <= res->end; i++) {
+			if (priv->num_irqs >= ARRAY_SIZE(priv->irqs_table)) {
+				ret = -EINVAL;
+				goto clean_irq_ret;
+			}
+
 			if (request_irq(i, cpsw_interrupt, 0,
 					dev_name(&pdev->dev), priv)) {
 				dev_err(priv->dev, "error attaching irq\n");
 				goto clean_irq_ret;
 			}
-			priv->irqs_table[k] = i;
-			priv->num_irqs = k + 1;
+			priv->irqs_table[priv->num_irqs] = i;
+			priv->num_irqs++;
 		}
 		k++;
 	}
-- 
2.1.0

  reply	other threads:[~2014-09-02 16:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-02 16:44 [PATCH 1/2] net: ethernet: cpsw: don't claim IRQs with devm_request_irq() Daniel Mack
2014-09-02 16:44 ` Daniel Mack [this message]
2014-09-03  7:28   ` [PATCH 2/2] net: ethernet: cpsw: fix interrupt lookup logic in cpsw_probe() Mugunthan V N
2014-09-03  7:30     ` Daniel Mack
2014-09-03  8:22       ` Mugunthan V N
2014-09-03  8:23         ` Daniel Mack
2014-09-03  7:27 ` [PATCH 1/2] net: ethernet: cpsw: don't claim IRQs with devm_request_irq() Mugunthan V N

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409676245-13897-2-git-send-email-zonque@gmail.com \
    --to=zonque@gmail.com \
    --cc=davem@davemloft.net \
    --cc=george.cherian@ti.com \
    --cc=julia.lawall@lip6.fr \
    --cc=mugunthanvnm@ti.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.