aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/kobject_uevent.c57
2 files changed, 46 insertions, 14 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 4f3f3e256501..6c4ea33bb2cb 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -10,7 +10,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
10lib-$(CONFIG_MMU) += ioremap.o 10lib-$(CONFIG_MMU) += ioremap.o
11lib-$(CONFIG_SMP) += cpumask.o 11lib-$(CONFIG_SMP) += cpumask.o
12 12
13lib-y += kobject.o kref.o kobject_uevent.o klist.o 13lib-y += kobject.o kref.o klist.o
14 14
15obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 15obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
16 bust_spinlocks.o hexdump.o kasprintf.o 16 bust_spinlocks.o hexdump.o kasprintf.o
@@ -20,6 +20,7 @@ CFLAGS_kobject.o += -DDEBUG
20CFLAGS_kobject_uevent.o += -DDEBUG 20CFLAGS_kobject_uevent.o += -DDEBUG
21endif 21endif
22 22
23lib-$(CONFIG_HOTPLUG) += kobject_uevent.o
23obj-$(CONFIG_GENERIC_IOMAP) += iomap.o 24obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
24obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o 25obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
25obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o 26obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 5ccda460262c..a8efb48dca54 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -23,17 +23,6 @@
23#include <net/sock.h> 23#include <net/sock.h>
24 24
25 25
26/* the strings here must match the enum in include/linux/kobject.h */
27const char *kobject_actions[] = {
28 "add",
29 "remove",
30 "change",
31 "move",
32 "online",
33 "offline",
34};
35
36#if defined(CONFIG_HOTPLUG)
37u64 uevent_seqnum; 26u64 uevent_seqnum;
38char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 27char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
39static DEFINE_SPINLOCK(sequence_lock); 28static DEFINE_SPINLOCK(sequence_lock);
@@ -41,6 +30,50 @@ static DEFINE_SPINLOCK(sequence_lock);
41static struct sock *uevent_sock; 30static struct sock *uevent_sock;
42#endif 31#endif
43 32
33/* the strings here must match the enum in include/linux/kobject.h */
34static const char *kobject_actions[] = {
35 [KOBJ_ADD] = "add",
36 [KOBJ_REMOVE] = "remove",
37 [KOBJ_CHANGE] = "change",
38 [KOBJ_MOVE] = "move",
39 [KOBJ_ONLINE] = "online",
40 [KOBJ_OFFLINE] = "offline",
41};
42
43/**
44 * kobject_action_type - translate action string to numeric type
45 *
46 * @buf: buffer containing the action string, newline is ignored
47 * @len: length of buffer
48 * @type: pointer to the location to store the action type
49 *
50 * Returns 0 if the action string was recognized.
51 */
52int kobject_action_type(const char *buf, size_t count,
53 enum kobject_action *type)
54{
55 enum kobject_action action;
56 int ret = -EINVAL;
57
58 if (count && buf[count-1] == '\n')
59 count--;
60
61 if (!count)
62 goto out;
63
64 for (action = 0; action < ARRAY_SIZE(kobject_actions); action++) {
65 if (strncmp(kobject_actions[action], buf, count) != 0)
66 continue;
67 if (kobject_actions[action][count] != '\0')
68 continue;
69 *type = action;
70 ret = 0;
71 break;
72 }
73out:
74 return ret;
75}
76
44/** 77/**
45 * kobject_uevent_env - send an uevent with environmental data 78 * kobject_uevent_env - send an uevent with environmental data
46 * 79 *
@@ -270,5 +303,3 @@ static int __init kobject_uevent_init(void)
270 303
271postcore_initcall(kobject_uevent_init); 304postcore_initcall(kobject_uevent_init);
272#endif 305#endif
273
274#endif /* CONFIG_HOTPLUG */