Skip to content

Commit dd27dcd

Browse files
committed
of/device: merge of_device_uevent
Merge common code between powerpc and microblaze Signed-off-by: Grant Likely <grant.likely@secretlab.ca> CC: Michal Simek <monstr@monstr.eu> CC: Wolfram Sang <w.sang@pengutronix.de> CC: Stephen Rothwell <sfr@canb.auug.org.au> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: microblaze-uclinux@itee.uq.edu.au CC: linuxppc-dev@ozlabs.org
1 parent d3571c3 commit dd27dcd

6 files changed

Lines changed: 52 additions & 103 deletions

File tree

‎arch/microblaze/include/asm/of_device.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ extern struct of_device *of_device_alloc(struct device_node *np,
2222
const char *bus_id,
2323
struct device *parent);
2424

25-
extern int of_device_uevent(struct device *dev,
26-
struct kobj_uevent_env *env);
27-
2825
extern void of_device_make_bus_id(struct of_device *dev);
2926

3027
/* This is just here during the transition */

‎arch/microblaze/kernel/of_device.c‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,51 +62,3 @@ struct of_device *of_device_alloc(struct device_node *np,
6262
return dev;
6363
}
6464
EXPORT_SYMBOL(of_device_alloc);
65-
66-
int of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
67-
{
68-
struct of_device *ofdev;
69-
const char *compat;
70-
int seen = 0, cplen, sl;
71-
72-
if (!dev)
73-
return -ENODEV;
74-
75-
ofdev = to_of_device(dev);
76-
77-
if (add_uevent_var(env, "OF_NAME=%s", ofdev->dev.of_node->name))
78-
return -ENOMEM;
79-
80-
if (add_uevent_var(env, "OF_TYPE=%s", ofdev->dev.of_node->type))
81-
return -ENOMEM;
82-
83-
/* Since the compatible field can contain pretty much anything
84-
* it's not really legal to split it out with commas. We split it
85-
* up using a number of environment variables instead. */
86-
87-
compat = of_get_property(ofdev->dev.of_node, "compatible", &cplen);
88-
while (compat && *compat && cplen > 0) {
89-
if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat))
90-
return -ENOMEM;
91-
92-
sl = strlen(compat) + 1;
93-
compat += sl;
94-
cplen -= sl;
95-
seen++;
96-
}
97-
98-
if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen))
99-
return -ENOMEM;
100-
101-
/* modalias is trickier, we add it in 2 steps */
102-
if (add_uevent_var(env, "MODALIAS="))
103-
return -ENOMEM;
104-
sl = of_device_get_modalias(ofdev, &env->buf[env->buflen-1],
105-
sizeof(env->buf) - env->buflen);
106-
if (sl >= (sizeof(env->buf) - env->buflen))
107-
return -ENOMEM;
108-
env->buflen += sl;
109-
110-
return 0;
111-
}
112-
EXPORT_SYMBOL(of_device_uevent);

‎arch/powerpc/include/asm/of_device.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ extern struct of_device *of_device_alloc(struct device_node *np,
99
const char *bus_id,
1010
struct device *parent);
1111

12-
extern int of_device_uevent(struct device *dev,
13-
struct kobj_uevent_env *env);
14-
1512
#endif /* __KERNEL__ */
1613
#endif /* _ASM_POWERPC_OF_DEVICE_H */

‎arch/powerpc/kernel/of_device.c‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,52 +82,3 @@ struct of_device *of_device_alloc(struct device_node *np,
8282
return dev;
8383
}
8484
EXPORT_SYMBOL(of_device_alloc);
85-
86-
int of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
87-
{
88-
struct of_device *ofdev;
89-
const char *compat;
90-
int seen = 0, cplen, sl;
91-
92-
if (!dev)
93-
return -ENODEV;
94-
95-
ofdev = to_of_device(dev);
96-
97-
if (add_uevent_var(env, "OF_NAME=%s", ofdev->dev.of_node->name))
98-
return -ENOMEM;
99-
100-
if (add_uevent_var(env, "OF_TYPE=%s", ofdev->dev.of_node->type))
101-
return -ENOMEM;
102-
103-
/* Since the compatible field can contain pretty much anything
104-
* it's not really legal to split it out with commas. We split it
105-
* up using a number of environment variables instead. */
106-
107-
compat = of_get_property(ofdev->dev.of_node, "compatible", &cplen);
108-
while (compat && *compat && cplen > 0) {
109-
if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat))
110-
return -ENOMEM;
111-
112-
sl = strlen (compat) + 1;
113-
compat += sl;
114-
cplen -= sl;
115-
seen++;
116-
}
117-
118-
if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen))
119-
return -ENOMEM;
120-
121-
/* modalias is trickier, we add it in 2 steps */
122-
if (add_uevent_var(env, "MODALIAS="))
123-
return -ENOMEM;
124-
sl = of_device_get_modalias(ofdev, &env->buf[env->buflen-1],
125-
sizeof(env->buf) - env->buflen);
126-
if (sl >= (sizeof(env->buf) - env->buflen))
127-
return -ENOMEM;
128-
env->buflen += sl;
129-
130-
return 0;
131-
}
132-
EXPORT_SYMBOL(of_device_uevent);
133-
EXPORT_SYMBOL(of_device_get_modalias);

‎drivers/of/device.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,51 @@ ssize_t of_device_get_modalias(struct of_device *ofdev,
170170

171171
return tsize;
172172
}
173+
174+
/**
175+
* of_device_uevent - Display OF related uevent information
176+
*/
177+
int of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
178+
{
179+
const char *compat;
180+
int seen = 0, cplen, sl;
181+
182+
if ((!dev) || (!dev->of_node))
183+
return -ENODEV;
184+
185+
if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name))
186+
return -ENOMEM;
187+
188+
if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type))
189+
return -ENOMEM;
190+
191+
/* Since the compatible field can contain pretty much anything
192+
* it's not really legal to split it out with commas. We split it
193+
* up using a number of environment variables instead. */
194+
195+
compat = of_get_property(dev->of_node, "compatible", &cplen);
196+
while (compat && *compat && cplen > 0) {
197+
if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat))
198+
return -ENOMEM;
199+
200+
sl = strlen(compat) + 1;
201+
compat += sl;
202+
cplen -= sl;
203+
seen++;
204+
}
205+
206+
if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen))
207+
return -ENOMEM;
208+
209+
/* modalias is trickier, we add it in 2 steps */
210+
if (add_uevent_var(env, "MODALIAS="))
211+
return -ENOMEM;
212+
213+
sl = of_device_get_modalias(to_of_device(dev), &env->buf[env->buflen-1],
214+
sizeof(env->buf) - env->buflen);
215+
if (sl >= (sizeof(env->buf) - env->buflen))
216+
return -ENOMEM;
217+
env->buflen += sl;
218+
219+
return 0;
220+
}

‎include/linux/of_device.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ static inline void of_device_free(struct of_device *dev)
4444

4545
extern ssize_t of_device_get_modalias(struct of_device *ofdev,
4646
char *str, ssize_t len);
47+
48+
extern int of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
49+
50+
4751
#endif /* CONFIG_OF_DEVICE */
4852

4953
#endif /* _LINUX_OF_DEVICE_H */

0 commit comments

Comments
 (0)