Source-Changes-HG archive

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

[src/trunk]: src/sys/modules/example Revert most of previous:



details:   https://anonhg.NetBSD.org/src/rev/049cf1dc7600
branches:  trunk
changeset: 758200:049cf1dc7600
user:      jnemeth <jnemeth%NetBSD.org@localhost>
date:      Mon Oct 25 22:41:42 2010 +0000

description:
Revert most of previous:
- props being NULL is NOT an error and is a condition that all modules
  must be prepared to handle
- having this module bomb out for spurious reasons makes this module
  difficult to use for testing things
- keep comment update
- keep some KNF
- add a notice for the case when props is NULL

diffstat:

 sys/modules/example/example.c |  50 ++++++++++++++++++------------------------
 1 files changed, 22 insertions(+), 28 deletions(-)

diffs (98 lines):

diff -r d2a9e4eaa746 -r 049cf1dc7600 sys/modules/example/example.c
--- a/sys/modules/example/example.c     Mon Oct 25 20:35:36 2010 +0000
+++ b/sys/modules/example/example.c     Mon Oct 25 22:41:42 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: example.c,v 1.6 2010/06/22 18:30:20 rmind Exp $        */
+/*     $NetBSD: example.c,v 1.7 2010/10/25 22:41:42 jnemeth Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.6 2010/06/22 18:30:20 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: example.c,v 1.7 2010/10/25 22:41:42 jnemeth Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -41,59 +41,53 @@
 
 MODULE(MODULE_CLASS_MISC, example, NULL);
 
-static int
+static
+void
 handle_props(prop_dictionary_t props)
 {
        const char *msg;
        prop_string_t str;
 
-       if (props == NULL)
-               return EINVAL;
-
-       str = prop_dictionary_get(props, "msg");
-       if (str == NULL) {
+       if (props != NULL) {
+               str = prop_dictionary_get(props, "msg");
+       } else {
+               printf("No property dictionary was provided.\n");
+               str = NULL;
+       }
+       if (str == NULL)
                printf("The 'msg' property was not given.\n");
-               return EINVAL;
-       }
-
-       if (prop_object_type(str) != PROP_TYPE_STRING) {
+       else if (prop_object_type(str) != PROP_TYPE_STRING)
                printf("The 'msg' property is not a string.\n");
-               return EINVAL;
+       else {
+               msg = prop_string_cstring_nocopy(str);
+               if (msg == NULL)
+                       printf("Failed to process the 'msg' property.\n");
+               else
+                       printf("The 'msg' property is: %s\n", msg);
        }
-
-       msg = prop_string_cstring_nocopy(str);
-       if (msg == NULL) {
-               printf("Failed to process the 'msg' property.\n");
-       } else {
-               printf("The 'msg' property is: %s\n", msg);
-       }
-       return 0;
 }
 
 static int
 example_modcmd(modcmd_t cmd, void *arg)
 {
-       int error;
 
        switch (cmd) {
        case MODULE_CMD_INIT:
                printf("Example module loaded.\n");
-               error = handle_props(arg);
+               handle_props(arg);
                break;
 
        case MODULE_CMD_FINI:
                printf("Example module unloaded.\n");
-               error = 0;
                break;
 
        case MODULE_CMD_STAT:
                printf("Example module status queried.\n");
-               error = ENOTTY;
-               break;
+               return ENOTTY;
 
        default:
-               error = ENOTTY;
+               return ENOTTY;
        }
 
-       return error;
+       return 0;
 }



Home | Main Index | Thread Index | Old Index