Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

awin_sysconfig endian awareness fix



Hi!

This patch fixes panic when booting with FEX on A20 earmv7hfeb.
Ok to commit?

Kind regards,
-Tobias
Index: awin_sysconfig.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbarm/awin/awin_sysconfig.c,v
retrieving revision 1.2
diff -u -r1.2 awin_sysconfig.c
--- awin_sysconfig.c	25 Oct 2015 20:46:46 -0000	1.2
+++ awin_sysconfig.c	4 Mar 2016 15:58:14 -0000
@@ -118,25 +118,25 @@
 
 	memcpy(&head, &awin_sysconfig[0], sizeof(head));
 
-	for (n = 0, off = sizeof(head); n < head.count;
+	for (n = 0, off = sizeof(head); n < le32toh(head.count);
 	     n++, off += sizeof(main_key)) {
 		memcpy(&main_key, &awin_sysconfig[off], sizeof(main_key));
 		if (strcmp(key, main_key.name) == 0) {
 			break;
 		}
 	}
-	if (n == head.count) {
+	if (n == le32toh(head.count)) {
 		return false;
 	}
 
-	for (n = 0, off = main_key.offset << 2; n < main_key.count;
-	    n++, off += sizeof(sub_key)) {
+	for (n = 0, off = le32toh(main_key.offset) << 2;
+	    n < le32toh(main_key.count); n++, off += sizeof(sub_key)) {
 		memcpy(&sub_key, &awin_sysconfig[off], sizeof(sub_key));
 		if (strcmp(subkey, sub_key.name) == 0) {
 			break;
 		}
 	}
-	if (n == main_key.count) {
+	if (n == le32toh(main_key.count)) {
 		return false;
 	}
 
@@ -154,12 +154,12 @@
 	if (awin_sysconfig_parse(key, subkey, &value) == false)
 		return -1;
 
-	if (value.type != AWIN_SYSCONFIG_TYPE_SINGLE_WORD)
+	if (le16toh(value.type) != AWIN_SYSCONFIG_TYPE_SINGLE_WORD)
 		return -1;
 
-	memcpy(&ret, &awin_sysconfig[value.offset << 2], sizeof(ret));
+	memcpy(&ret, &awin_sysconfig[le32toh(value.offset) << 2], sizeof(ret));
 
-	return ret;
+	return le32toh(ret);
 }
 
 const char *
@@ -170,10 +170,10 @@
 	if (awin_sysconfig_parse(key, subkey, &value) == false)
 		return NULL;
 
-	if (value.type != AWIN_SYSCONFIG_TYPE_STRING)
+	if (le16toh(value.type) != AWIN_SYSCONFIG_TYPE_STRING)
 		return NULL;
 
-	return &awin_sysconfig[value.offset << 2];
+	return &awin_sysconfig[le32toh(value.offset) << 2];
 }
 
 const char *
@@ -186,14 +186,15 @@
 	if (awin_sysconfig_parse(key, subkey, &value) == false)
 		return NULL;
 
-	if (value.type != AWIN_SYSCONFIG_TYPE_GPIO)
+	if (le16toh(value.type) != AWIN_SYSCONFIG_TYPE_GPIO)
 		return NULL;
 	
-	memcpy(&gpio, &awin_sysconfig[(value.offset << 2) - 32], sizeof(gpio));
+	memcpy(&gpio, &awin_sysconfig[(le32toh(value.offset) << 2) - 32],
+	    sizeof(gpio));
 
 	snprintf(gpio_str, sizeof(gpio_str), "%cP%c%d",
-	    gpio.mul_sel == 0 ? '<' : '>',
-	    (gpio.port - 1) + 'A', gpio.port_num);
+	    le32toh(gpio.mul_sel) == 0 ? '<' : '>',
+	    (le32toh(gpio.port) - 1) + 'A', le32toh(gpio.port_num));
 
 	return gpio_str;
 }


Home | Main Index | Thread Index | Old Index