-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkobject.c
56 lines (44 loc) · 1.13 KB
/
kobject.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2021 John Sanpe <[email protected]>
*/
#include <kobject.h>
#include <string.h>
#include <sections.h>
#include <kmalloc.h>
#include <export.h>
state kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
{
const char *buff;
if (unlikely(kobj->name && !fmt))
return -ENOERR;
buff = vasprintf_const(fmt, args);
if (unlikely(!buff))
return -ENOMEM;
if (strchr(buff, '/')) {
char *replace;
if (!in_rodata_section(buff))
replace = (char *)buff;
else {
replace = strdup(buff);
kfree(buff);
}
strchreplace(replace, '!', '/');
buff = replace;
}
if (!in_rodata_section(kobj->name))
kfree(kobj->name);
kobj->name = buff;
return -ENOERR;
}
EXPORT_SYMBOL(kobject_set_name_vargs);
state kobject_set_name(struct kobject *kobj, const char *fmt, ...)
{
va_list args;
state retval;
va_start(args, fmt);
retval = kobject_set_name_vargs(kobj, fmt, args);
va_end(args);
return retval;
}
EXPORT_SYMBOL(kobject_set_name);