]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - lib/kobject_uevent.c
sis190: add cmos ram access code for the SiS19x/968 chipset pair
[linux-2.6-omap-h63xx.git] / lib / kobject_uevent.c
index 5ccda460262c2bb88dfa35820a214baad3feb536..5886147252d0d643598e408b63bf193aa49b5f34 100644 (file)
 #include <net/sock.h>
 
 
-/* the strings here must match the enum in include/linux/kobject.h */
-const char *kobject_actions[] = {
-       "add",
-       "remove",
-       "change",
-       "move",
-       "online",
-       "offline",
-};
-
-#if defined(CONFIG_HOTPLUG)
 u64 uevent_seqnum;
 char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
 static DEFINE_SPINLOCK(sequence_lock);
@@ -41,10 +30,54 @@ static DEFINE_SPINLOCK(sequence_lock);
 static struct sock *uevent_sock;
 #endif
 
+/* the strings here must match the enum in include/linux/kobject.h */
+static const char *kobject_actions[] = {
+       [KOBJ_ADD] =            "add",
+       [KOBJ_REMOVE] =         "remove",
+       [KOBJ_CHANGE] =         "change",
+       [KOBJ_MOVE] =           "move",
+       [KOBJ_ONLINE] =         "online",
+       [KOBJ_OFFLINE] =        "offline",
+};
+
+/**
+ * kobject_action_type - translate action string to numeric type
+ *
+ * @buf: buffer containing the action string, newline is ignored
+ * @len: length of buffer
+ * @type: pointer to the location to store the action type
+ *
+ * Returns 0 if the action string was recognized.
+ */
+int kobject_action_type(const char *buf, size_t count,
+                       enum kobject_action *type)
+{
+       enum kobject_action action;
+       int ret = -EINVAL;
+
+       if (count && buf[count-1] == '\n')
+               count--;
+
+       if (!count)
+               goto out;
+
+       for (action = 0; action < ARRAY_SIZE(kobject_actions); action++) {
+               if (strncmp(kobject_actions[action], buf, count) != 0)
+                       continue;
+               if (kobject_actions[action][count] != '\0')
+                       continue;
+               *type = action;
+               ret = 0;
+               break;
+       }
+out:
+       return ret;
+}
+
 /**
  * kobject_uevent_env - send an uevent with environmental data
  *
- * @action: action that is happening (usually KOBJ_MOVE)
+ * @action: action that is happening
  * @kobj: struct kobject that the action is happening to
  * @envp_ext: pointer to environmental data
  *
@@ -69,9 +102,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 
        /* search the kset we belong to */
        top_kobj = kobj;
-       while (!top_kobj->kset && top_kobj->parent) {
+       while (!top_kobj->kset && top_kobj->parent)
                top_kobj = top_kobj->parent;
-       }
+
        if (!top_kobj->kset) {
                pr_debug("kobject attempted to send uevent without kset!\n");
                return -EINVAL;
@@ -93,7 +126,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
        else
                subsystem = kobject_name(&kset->kobj);
        if (!subsystem) {
-               pr_debug("unset subsytem caused the event to drop!\n");
+               pr_debug("unset subsystem caused the event to drop!\n");
                return 0;
        }
 
@@ -204,7 +237,7 @@ EXPORT_SYMBOL_GPL(kobject_uevent_env);
 /**
  * kobject_uevent - notify userspace by ending an uevent
  *
- * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE)
+ * @action: action that is happening
  * @kobj: struct kobject that the action is happening to
  *
  * Returns 0 if kobject_uevent() is completed with success or the
@@ -270,5 +303,3 @@ static int __init kobject_uevent_init(void)
 
 postcore_initcall(kobject_uevent_init);
 #endif
-
-#endif /* CONFIG_HOTPLUG */