staging: greybus: loopback_test: Change array index from loop bound to loop index
PATCH 1/1 staging: greybus: loopback_test: Change array index from loop bound to loop index
Change array index from the loop bound variable to loop index. The open_poll_files() functions attempts to open poll files of devices numbered from 0 to device_count. If the open() function inside it is unsuccessful for any intermediate device, all files with fds of devices from 0 upto that device must be closed and open_poll_files() should return -1. The current code only closes the poll file with the most recent fd allocated, and in most cases tries to close the same file multiple times.
Detected by coccinelle:
@@
expression arr,ex1,ex2;
@@
for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }
--- drivers/staging/greybus/tools/loopback_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +1 -1
@@ -674,7 +674,7 @@ static int open_poll_files(struct loopback_test *t) err:for (i =0 ; i < fds_idx; i++) -close (t->fds[fds_idx].fd); +close (t->fds[i].fd);return -1 ; }
Signature · 1 line
2.7.4
Johan Hovold
maintainer[+CC: greybus and staging lists]
Quoted 7 lines · sayli karnik
Change array index from the loop bound variable to loop index. The
open_poll_files()functions attempts to open poll files of devices numbered from 0 todevice_count. If theopen()function inside it is unsuccessful for any intermediate device, all files with fds of devices from 0 upto that device must be closed andopen_poll_files()should return -1. The current code only closes the poll file with the most recent fd allocated, and in most cases tries to close the same file multiple times.
Nice catch!
You forgot to CC the relevant mailings lists however (use scripts/get_maintainer.pl).
Also your patch summary is a bit too detailed, something like
staging: greybus: loopback_test: fix open error path
would be better.
Care to resend as a v2 with a shorter summary and lists on CC?
Quoted 23 lines
Detected by coccinelle:
@@
expression arr,ex1,ex2;
@@for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }Signed-off-by sayli karnik <[email protected]>--- drivers/staging/greybus/tools/loopback_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/greybus/tools/loopback_test.c +0
-0
drivers/staging/greybus/tools/loopback_test.c static int open_poll_files(struct loopback_test *t) · line 680
Quoted 8 lines
drivers/staging/greybus/tools/loopback_test.c +1
-1@@ -674,7 +674,7 @@ static int open_poll_files(struct loopback_test *t) err:for (i =0 ; i < fds_idx; i++) -close (t->fds[fds_idx].fd); +close (t->fds[i].fd);return -1 ; }
Thanks,
Johan
Quoted 11 lines · Johan Hovold
[+CC: greybus and staging lists]
Quoted 7 lines · sayli karnik
Change array index from the loop bound variable to loop index. The
open_poll_files()functions attempts to open poll files of devices numbered from 0 todevice_count. If theopen()function inside it is unsuccessful for any intermediate device, all files with fds of devices from 0 upto that device must be closed andopen_poll_files()should return -1. The current code only closes the poll file with the most recent fd allocated, and in most cases tries to close the same file multiple times.
Quoted 4 lines
Nice catch!
You forgot to CC the relevant mailings lists however (use
scripts/get_maintainer.pl).
Yes I'll do that!
Quoted 9 lines
Also your patch summary is a bit too detailed, something like
staging: greybus:
loopback_test: fix open error pathwould be better.
Care to resend as a v2 with a shorter summary and lists on CC?
Yes sure I'm sending a v2.
thanks,
sayli
Quoted 34 lines
Quoted 23 lines
Detected by coccinelle:
@@
expression arr,ex1,ex2;
@@for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }Signed-off-by sayli karnik <[email protected]>--- drivers/staging/greybus/tools/loopback_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/greybus/tools/loopback_test.c +0
-0drivers/staging/greybus/tools/loopback_test.c static int open_poll_files(struct loopback_test *t) · line 680
Quoted 8 lines
drivers/staging/greybus/tools/loopback_test.c +1
-1@@ -674,7 +674,7 @@ static int open_poll_files(struct loopback_test *t) err:for (i =0 ; i < fds_idx; i++) -close (t->fds[fds_idx].fd); +close (t->fds[i].fd);return -1 ; }Thanks,
Johan