# \[PATCH 3/6\] drivers/net/niu.c: adjust array index

- Subsystems: NETWORKING DRIVERS, THE REST
- Maintainers: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
- List: netdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/netdev/2011/07/3746185/t

## \[PATCH 3/6\] drivers/net/niu.c: adjust array index

- From: Julia Lawall \<hidden\>
- Date: 2011-07-28 12:47:05 
- Message: https://ratatoskr.run/netdev/2011/07/3746185.md

```text
From: Julia Lawall <redacted>

Convert array index from the loop bound to the loop index.

A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e1,e2,ar;
@@

for(e1 = 0; e1 < e2; e1++) { <...
  ar[
- e2
+ e1
  ]
  ...> }
// </smpl>

Signed-off-by: Julia Lawall <redacted>

---
Not tested.

 drivers/net/niu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/drivers/net/niu.c b/drivers/net/niu.c
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -9201,7 +9201,7 @@ static int __devinit niu_ldg_init(struct
 
 	first_chan = 0;
 	for (i = 0; i < port; i++)
-		first_chan += parent->rxchan_per_port[port];
+		first_chan += parent->rxchan_per_port[i];
 	num_chan = parent->rxchan_per_port[port];
 
 	for (i = first_chan; i < (first_chan + num_chan); i++) {
@@ -9217,7 +9217,7 @@ static int __devinit niu_ldg_init(struct
 
 	first_chan = 0;
 	for (i = 0; i < port; i++)
-		first_chan += parent->txchan_per_port[port];
+		first_chan += parent->txchan_per_port[i];
 	num_chan = parent->txchan_per_port[port];
 	for (i = first_chan; i < (first_chan + num_chan); i++) {
 		err = niu_ldg_assign_ldn(np, parent,
```

## Re: \[PATCH 3/6\] drivers/net/niu.c: adjust array index

- From: David Miller \<davem@davemloft.net\>
- Date: 2011-08-01 09:32:22 
- Message: https://ratatoskr.run/netdev/2011/08/3747370.md

```text
From: Julia Lawall <redacted>
Date: Thu, 28 Jul 2011 14:46:03 +0200

> From: Julia Lawall <redacted>
> 
> Convert array index from the loop bound to the loop index.
> 
> A simplified version of the semantic patch that fixes this problem is as
> follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e1,e2,ar;
> @@
> 
> for(e1 = 0; e1 < e2; e1++) { <...
>   ar[
> - e2
> + e1
>   ]
>   ...> }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <redacted>

Applied.
```
