aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-08-12 14:43:55 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:06 -0400
commit5c5daf657cb5f963a38413f2852279d7a3843144 (patch)
treeec314c25ca40528bd4625944a93846d1654c9cd9
parent07c015e7654821f2dda00dcf152c65b2afd46ac3 (diff)
Driver core: exclude kobject_uevent.c for !CONFIG_HOTPLUG
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>
-rw-r--r--drivers/base/core.c18
-rw-r--r--include/linux/kobject.h10
-rw-r--r--lib/Makefile3
-rw-r--r--lib/kobject_uevent.c57
4 files changed, 57 insertions, 31 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d487c032dc4a..65de221e3bfa 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -234,13 +234,11 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
234 234
235 /* search the kset, the device belongs to */ 235 /* search the kset, the device belongs to */
236 top_kobj = &dev->kobj; 236 top_kobj = &dev->kobj;
237 if (!top_kobj->kset && top_kobj->parent) { 237 while (!top_kobj->kset && top_kobj->parent)
238 do { 238 top_kobj = top_kobj->parent;
239 top_kobj = top_kobj->parent;
240 } while (!top_kobj->kset && top_kobj->parent);
241 }
242 if (!top_kobj->kset) 239 if (!top_kobj->kset)
243 goto out; 240 goto out;
241
244 kset = top_kobj->kset; 242 kset = top_kobj->kset;
245 if (!kset->uevent_ops || !kset->uevent_ops->uevent) 243 if (!kset->uevent_ops || !kset->uevent_ops->uevent)
246 goto out; 244 goto out;
@@ -270,17 +268,9 @@ out:
270static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, 268static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
271 const char *buf, size_t count) 269 const char *buf, size_t count)
272{ 270{
273 size_t len = count;
274 enum kobject_action action; 271 enum kobject_action action;
275 272
276 if (len && buf[len-1] == '\n') 273 if (kobject_action_type(buf, count, &action) == 0) {
277 len--;
278
279 for (action = 0; action < KOBJ_MAX; action++) {
280 if (strncmp(kobject_actions[action], buf, len) != 0)
281 continue;
282 if (kobject_actions[action][len] != '\0')
283 continue;
284 kobject_uevent(&dev->kobj, action); 274 kobject_uevent(&dev->kobj, action);
285 goto out; 275 goto out;
286 } 276 }
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 56f5eaf10ea9..0777b3f57ae6 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -58,9 +58,6 @@ enum kobject_action {
58 KOBJ_MAX 58 KOBJ_MAX
59}; 59};
60 60
61/* The list of strings defining the valid kobject actions as specified above */
62extern const char *kobject_actions[];
63
64struct kobject { 61struct kobject {
65 const char * k_name; 62 const char * k_name;
66 struct kref kref; 63 struct kref kref;
@@ -241,6 +238,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
241 238
242int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) 239int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
243 __attribute__((format (printf, 2, 3))); 240 __attribute__((format (printf, 2, 3)));
241
242int kobject_action_type(const char *buf, size_t count,
243 enum kobject_action *type);
244#else 244#else
245static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) 245static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
246{ return 0; } 246{ return 0; }
@@ -251,6 +251,10 @@ static inline int kobject_uevent_env(struct kobject *kobj,
251 251
252static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) 252static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
253{ return 0; } 253{ return 0; }
254
255static inline int kobject_action_type(const char *buf, size_t count,
256 enum kobject_action *type)
257{ return -EINVAL; }
254#endif 258#endif
255 259
256#endif /* __KERNEL__ */ 260#endif /* __KERNEL__ */
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 */