[PATCH] hpet: hpetcheck: fix a bug found by smatch

Colin King colin.king at canonical.com
Wed Jan 16 00:53:50 UTC 2013


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

smatch found a bug that needs fixing:

"hpet_check.c:88 hpet_parse_device_hpet() error:
we previously assumed 'tmp_item' could be null (see line 81)"

Re-work the HPET parsing so that we sanely handle tmp_item.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/hpet/hpet_check/hpet_check.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/hpet/hpet_check/hpet_check.c b/src/hpet/hpet_check/hpet_check.c
index 7709f88..8fe124a 100644
--- a/src/hpet/hpet_check/hpet_check.c
+++ b/src/hpet/hpet_check/hpet_check.c
@@ -70,29 +70,25 @@ static void hpet_parse_device_hpet(fwts_framework *fw,
 	const char *table, fwts_list_link *item)
 {
 	for (;item != NULL; item = item->next) {
-		char *str = fwts_text_list_text(item);
+		const char *str = fwts_text_list_text(item);
+
 		if ((strstr(str, "Name") != NULL) &&
-			(strstr(str, "ResourceTemplate") != NULL)) {
+		    (strstr(str, "ResourceTemplate") != NULL)) {
 			fwts_list_link *tmp_item = item->next;
 			for (; tmp_item != NULL; tmp_item = tmp_item->next) {
-				if (strstr(fwts_text_list_text(tmp_item),
-					"Memory32Fixed") != NULL) {
-					tmp_item = tmp_item->next;
-					if (tmp_item != NULL) {
-						hpet_parse_check_base(fw, table, tmp_item);
+				const char *str = fwts_text_list_text(tmp_item);
+
+				if (strstr(str, "Memory32Fixed") != NULL) {
+					/* Next line contains base address */
+					if (tmp_item->next != NULL) {
+						hpet_parse_check_base(fw, table, tmp_item->next);
 						return;
 					}
-				}
-				if (strstr(fwts_text_list_text(tmp_item),
-					"DWordMemory") != NULL) {
-					tmp_item = tmp_item->next;
-					if (tmp_item != NULL) {
-						tmp_item = tmp_item->next;
-						if (tmp_item != NULL) {
-							/* HPET section is found, get base */
-							hpet_parse_check_base(fw, table, tmp_item);
-							return;
-						}
+				} else if (strstr(str, "DWordMemory") != NULL) {
+					if (tmp_item->next != NULL &&		/* Granularity */
+					    tmp_item->next->next != NULL) {	/* Base address */
+						hpet_parse_check_base(fw, table, tmp_item->next->next);
+						return;
 					}
 				}
 			}
-- 
1.8.0




More information about the fwts-devel mailing list