Module Name:    src
Committed By:   rkujawa
Date:           Tue Oct 15 10:27:55 UTC 2013

Modified Files:
        src/sys/dev/i2c: mcp980x.c

Log Message:
Simplify sysctl handling.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/mcp980x.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/dev/i2c/mcp980x.c
diff -u src/sys/dev/i2c/mcp980x.c:1.2 src/sys/dev/i2c/mcp980x.c:1.3
--- src/sys/dev/i2c/mcp980x.c:1.2	Tue Oct 15 10:18:49 2013
+++ src/sys/dev/i2c/mcp980x.c	Tue Oct 15 10:27:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcp980x.c,v 1.2 2013/10/15 10:18:49 rkujawa Exp $ */
+/*	$NetBSD: mcp980x.c,v 1.3 2013/10/15 10:27:55 rkujawa Exp $ */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcp980x.c,v 1.2 2013/10/15 10:18:49 rkujawa Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp980x.c,v 1.3 2013/10/15 10:27:55 rkujawa Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -308,25 +308,24 @@ sysctl_mcp980x_res(SYSCTLFN_ARGS)
 {
 	struct sysctlnode node = *rnode;
 	struct mcp980x_softc *sc = node.sysctl_data;
-	int newres;
+	int newres, err;
+
+	node.sysctl_data = &sc->sc_res;
+	if ((err = (sysctl_lookup(SYSCTLFN_CALL(&node)))) != 0) 
+		return err;
 
 	if (newp) {
-		node.sysctl_data = &sc->sc_res;
-		if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
-			newres = *(int *)node.sysctl_data;
-			if (newres > MCP980X_CONFIG_ADC_RES_12BIT)
-				return EINVAL;
-			sc->sc_res = (uint8_t) newres;
-			mcp980x_resolution_set(sc, sc->sc_res);
-			return 0;
-		} 
+		newres = *(int *)node.sysctl_data;
+		if (newres > MCP980X_CONFIG_ADC_RES_12BIT)
+			return EINVAL;
+		sc->sc_res = (uint8_t) newres;
+		mcp980x_resolution_set(sc, sc->sc_res);
+		return 0;
 	} else {
 		sc->sc_res = mcp980x_resolution_get(sc);
-		node.sysctl_data = &sc->sc_res;
 		node.sysctl_size = 4;
-		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
 	}
 
-	return EINVAL;
+	return err;
 }
 

Reply via email to