Module Name:    src
Committed By:   christos
Date:           Sun Jan 22 17:19:32 UTC 2017

Modified Files:
        src/sys/arch/evbarm/gumstix: gxio.c

Log Message:
PR/51905: GXIO Expension boards arn't configured if GXIO_DEFAULT_EXPANSION
isn't defined. Fix a bunch of issues with the original code.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/evbarm/gumstix/gxio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbarm/gumstix/gxio.c
diff -u src/sys/arch/evbarm/gumstix/gxio.c:1.24 src/sys/arch/evbarm/gumstix/gxio.c:1.25
--- src/sys/arch/evbarm/gumstix/gxio.c:1.24	Fri Oct 28 15:00:48 2016
+++ src/sys/arch/evbarm/gumstix/gxio.c	Sun Jan 22 12:19:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gxio.c,v 1.24 2016/10/28 19:00:48 christos Exp $ */
+/*	$NetBSD: gxio.c,v 1.25 2017/01/22 17:19:32 christos Exp $ */
 /*
  * Copyright (C) 2005, 2006, 2007 WIDE Project and SOUM Corporation.
  * All rights reserved.
@@ -31,7 +31,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gxio.c,v 1.24 2016/10/28 19:00:48 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gxio.c,v 1.25 2017/01/22 17:19:32 christos Exp $");
 
 #include "opt_cputypes.h"
 #include "opt_gumstix.h"
@@ -88,7 +88,7 @@ CFATTACH_DECL_NEW(gxio, sizeof(struct gx
 #endif
 
 void gxio_config(void);
-void gxio_config_expansion(char *);
+void gxio_config_expansion(const char *);
 #if defined(GUMSTIX)
 static void basix_config(void);
 static void cfstix_config(void);
@@ -662,48 +662,54 @@ gxio_config(void)
 }
 #endif
 
-void
-gxio_config_expansion(char *expansion)
+static int
+gxio_find_default_expansion(void)
 {
-	int i, d, s;
-
-	if (expansion == NULL) {
-		printf("not specified 'expansion=' in the boot args.\n");
-		s = -1;
-	} else {
-		for (i = 0; gxioconflist[i].name != NULL; i++)
-			if (strncasecmp(gxioconflist[i].name, expansion,
-					strlen(gxioconflist[i].name) + 1) == 0)
-				break;
-		if (gxioconflist[i].name == NULL)
-			printf("unknown expansion specified: %s\n", expansion);
-		s = i;
-	}
 #ifdef GXIO_DEFAULT_EXPANSION
+	int i;
+
+	/* Find out the default expansion */
 	for (i = 0; gxioconflist[i].name != NULL; i++)
 		if (strncasecmp(gxioconflist[i].name, GXIO_DEFAULT_EXPANSION,
-					strlen(gxioconflist[i].name) + 1) == 0)
+		    strlen(gxioconflist[i].name) + 1) == 0)
 			break;
-	d = i;
+	return gxioconflist[i].name == NULL ? -1 : i;
 #else
-	d = -1;
+	return -1;
 #endif
+}
+
+void
+gxio_config_expansion(const char *expansion)
+{
+	int i, d;
+
+	d = gxio_find_default_expansion();
+
+	/* Print information about expansions */
 	printf("supported expansions:\n");
 	for (i = 0; gxioconflist[i].name != NULL; i++)
-		printf("  %s%s\n",
-		    gxioconflist[i].name,
+		printf("  %s%s\n", gxioconflist[i].name,
 		    i == d ? " (DEFAULT)" : "");
 
-	if (s < 0 || gxioconflist[i].name == NULL) {
-#ifdef GXIO_DEFAULT_EXPANSION
-		expansion = __UNCONST(GXIO_DEFAULT_EXPANSION);
-#else
-		return;
-#endif
+	
+	if (expansion == NULL) {
+		printf("not specified 'expansion=' in the boot args.\n");
+		i = -1;
+	} else {
+		for (i = 0; gxioconflist[i].name != NULL; i++)
+			if (strncasecmp(gxioconflist[i].name, expansion,
+			    strlen(gxioconflist[i].name) + 1) == 0)
+				break;
+		if (gxioconflist[i].name == NULL) {
+			printf("unknown expansion specified: %s\n", expansion);
+			i = -1;
+		}
 	}
 
+	/* Do some magic stuff for PEPPER */
 #if defined(PEPPER)
-	if (s < 0) {
+	if (i < 0) {
 		struct pepper_board_id {
 			unsigned int device_vendor;
 #define GUMSTIX_PEPPER          0x30000200	/* 1st gen */
@@ -730,10 +736,29 @@ gxio_config_expansion(char *expansion)
 	}
 #endif
 
-	printf("configure %s expansion (%s)\n",
-	    (s < 0 || gxioconflist[i].name == NULL) ? "default" : "specified",
-	    expansion);
-	gxioconflist[(s < 0 || gxioconflist[i].name == NULL) ? d : s].config();
+	/*
+	 * Now proceed to configure the default expansion if one was
+	 * specified (and found) or return.
+	 */
+	const char *toconfigure;
+	if (i < 0) {
+#ifdef GXIO_DEFAULT_EXPANSION
+		if (d == -1) {
+			printf("default expansion (%s) not found\n", 
+			    GXIO_DEFAULT_EXPANSION);
+			return;
+		}
+		expansion = GXIO_DEFAULT_EXPANSION;
+		i = d;
+		toconfigure = "default";
+#else
+		return;
+#endif
+	} else
+		toconfigure = "specified";
+
+	printf("configure %s expansion (%s)\n", toconfigure, expansion);
+	gxioconflist[i].config();
 }
 
 

Reply via email to