2020-06-24 01:05:48

by Gaurav Singh

[permalink] [raw]
Subject: [PATCH] [net/wan] cosa_init: check bounds before access

Check i < io bounds before accessing io[i].

Signed-off-by: Gaurav Singh <[email protected]>
---
drivers/net/wan/cosa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 5d6532ad6b78..8797adfa0ab0 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -363,7 +363,7 @@ static int __init cosa_init(void)
}
for (i=0; i<MAX_CARDS; i++)
cosa_cards[i].num = -1;
- for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
+ for (i=0; i < MAX_CARDS && io[i] != 0; i++)
cosa_probe(io[i], irq[i], dma[i]);
if (!nr_cards) {
pr_warn("no devices found\n");
--
2.17.1


2020-06-24 03:21:00

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] [net/wan] cosa_init: check bounds before access

From: Gaurav Singh <[email protected]>
Date: Tue, 23 Jun 2020 21:04:49 -0400

> Check i < io bounds before accessing io[i].
>
> Signed-off-by: Gaurav Singh <[email protected]>

The io[] array is intentionally zero terminated, there is no problem.