[PATCH 2/9] hotkey: fix key reading loop, it needs to loop more than once

Colin King colin.king at canonical.com
Wed Dec 16 00:51:38 UTC 2015


From: Colin Ian King <colin.king at canonical.com>

Static analysis from clang scan-build detected that the key
reading and hotkey checking loop was not iterating.  Clean up
the loop by removing do_test check and breaking out of the loop
only if a read failed or a KEY_ESC got read.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/hotkey/hotkey/hotkey.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c
index 28d3ef1..b53acf1 100644
--- a/src/hotkey/hotkey/hotkey.c
+++ b/src/hotkey/hotkey/hotkey.c
@@ -71,7 +71,6 @@ static int hotkey_test(fwts_framework *fw, char *dev, fwts_list *hotkeys)
 {
 	struct input_event ev;
 	char path[PATH_MAX];
-	int do_test = 1;
 	int fd;
 
 	snprintf(path, sizeof(path), "/dev/%s", dev);
@@ -89,21 +88,18 @@ static int hotkey_test(fwts_framework *fw, char *dev, fwts_list *hotkeys)
 		return FWTS_ERROR;
 	}
 
-	while (do_test) {
+	for (;;) {
 		ssize_t ret = read(fd, &ev, sizeof(ev));
 
-		if (ret < (ssize_t)sizeof(ev)) {
-			do_test = 0;
+		if (ret < (ssize_t)sizeof(ev))
 			break;
-		}
-
 		if ((ev.type == EV_KEY) &&
 		    (ev.code == KEY_ESC) &&
-		    (ev.value == 0))
-			do_test = 0;
-		else
+		    (ev.value == 0)) {
+			break;
+		} else {
 			hotkey_check_key(fw, &ev, hotkeys);
-		break;
+		}
 	}
 
 	if (ioctl(fd, EVIOCGRAB, (void*)0)) {	/* Release */
-- 
2.6.4




More information about the fwts-devel mailing list