Skip to contentSkip to conversation

staging: greybus: loopback_test: Fix open error path

PATCH In review sayli karnik 2 participants 2 messages Feb 20, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: greybus: loopback_test: Fix open error path

Change array index from the loop bound variable to loop index.
If a poll file fails to open for any intermediate device, all poll files with fds of devices from 0 upto that device must be closed in the open_poll_files() function. The current code only closes the poll file with the most recent fd allocated, and at times tries to close the same file multiple times.

Detected by coccinelle:

@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

---
v2:
Made the subject and changelog more concise

 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +1 -1
index 18d7a3d..2ee9a22 100644
@@ -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
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 19 lines · sayli karnik

Change array index from the loop bound variable to loop index.
If a poll file fails to open for any intermediate device, all poll files with fds of devices from 0 upto that device must be closed in the open_poll_files() function. The current code only closes the poll file with the most recent fd allocated, and at times tries to close the same file multiple times.

Detected by coccinelle:

@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Quoted 4 lines

---
v2:
Made the subject and changelog more concise

Thanks for the update.

Johan