]> err.no Git - linux-2.6/commitdiff
Driver core: exclude kobject_uevent.c for !CONFIG_HOTPLUG
authorKay Sievers <kay.sievers@vrfy.org>
Sun, 12 Aug 2007 18:43:55 +0000 (20:43 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 12 Oct 2007 21:51:06 +0000 (14:51 -0700)
Move uevent specific logic from the core into kobject_uevent.c, which
does no longer require to link the unused string array if hotplug
is not compiled in.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/core.c
include/linux/kobject.h
lib/Makefile
lib/kobject_uevent.c

index d487c032dc4ad0f8b5dfb3fc691a632fd8226d71..65de221e3bfa9d9bd60ab9afedb9826dc2eaf40e 100644 (file)
@@ -234,13 +234,11 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
 
        /* search the kset, the device belongs to */
        top_kobj = &dev->kobj;
-       if (!top_kobj->kset && top_kobj->parent) {
-               do {
-                       top_kobj = top_kobj->parent;
-               } while (!top_kobj->kset && top_kobj->parent);
-       }
+       while (!top_kobj->kset && top_kobj->parent)
+               top_kobj = top_kobj->parent;
        if (!top_kobj->kset)
                goto out;
+
        kset = top_kobj->kset;
        if (!kset->uevent_ops || !kset->uevent_ops->uevent)
                goto out;
@@ -270,17 +268,9 @@ out:
 static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
                            const char *buf, size_t count)
 {
-       size_t len = count;
        enum kobject_action action;
 
-       if (len && buf[len-1] == '\n')
-               len--;
-
-       for (action = 0; action < KOBJ_MAX; action++) {
-               if (strncmp(kobject_actions[action], buf, len) != 0)
-                       continue;
-               if (kobject_actions[action][len] != '\0')
-                       continue;
+       if (kobject_action_type(buf, count, &action) == 0) {
                kobject_uevent(&dev->kobj, action);
                goto out;
        }
index 56f5eaf10ea92afeb52477f79c2666ec775dcd7d..0777b3f57ae6f9b605ab6505cd202739c3ec252c 100644 (file)
@@ -58,9 +58,6 @@ enum kobject_action {
        KOBJ_MAX
 };
 
-/* The list of strings defining the valid kobject actions as specified above */
-extern const char *kobject_actions[];
-
 struct kobject {
        const char              * k_name;
        struct kref             kref;
@@ -241,6 +238,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 
 int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
        __attribute__((format (printf, 2, 3)));
+
+int kobject_action_type(const char *buf, size_t count,
+                       enum kobject_action *type);
 #else
 static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
 { return 0; }
@@ -251,6 +251,10 @@ static inline int kobject_uevent_env(struct kobject *kobj,
 
 static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
 { return 0; }
+
+static inline int kobject_action_type(const char *buf, size_t count,
+                       enum kobject_action *type)
+{ return -EINVAL; }
 #endif
 
 #endif /* __KERNEL__ */
index 4f3f3e2565017e4e37c88d7c6f11f4326695cdcc..6c4ea33bb2cb0f8ffe2e1010f29ec11c375d2ddf 100644 (file)
@@ -10,7 +10,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
 
-lib-y  += kobject.o kref.o kobject_uevent.o klist.o
+lib-y  += kobject.o kref.o klist.o
 
 obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
         bust_spinlocks.o hexdump.o kasprintf.o
@@ -20,6 +20,7 @@ CFLAGS_kobject.o += -DDEBUG
 CFLAGS_kobject_uevent.o += -DDEBUG
 endif
 
+lib-$(CONFIG_HOTPLUG) += kobject_uevent.o
 obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
 obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
 obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
index 5ccda460262c2bb88dfa35820a214baad3feb536..a8efb48dca5414a5f5c03b1d8d239e52f3d8f68b 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,6 +30,50 @@ 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
  *
@@ -270,5 +303,3 @@ static int __init kobject_uevent_init(void)
 
 postcore_initcall(kobject_uevent_init);
 #endif
-
-#endif /* CONFIG_HOTPLUG */