tcp_ipv6: fix use of uninitialized memory
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / ksysfs.c
CommitLineData
1da177e4
LT
1/*
2 * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
3 * are not related to any other subsystem
4 *
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * This file is release under the GPLv2
8 *
9 */
10
1da177e4
LT
11#include <linux/kobject.h>
12#include <linux/string.h>
13#include <linux/sysfs.h>
14#include <linux/module.h>
15#include <linux/init.h>
c330dda9 16#include <linux/kexec.h>
5cb350ba 17#include <linux/sched.h>
1da177e4
LT
18
19#define KERNEL_ATTR_RO(_name) \
386f275f 20static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
1da177e4
LT
21
22#define KERNEL_ATTR_RW(_name) \
386f275f 23static struct kobj_attribute _name##_attr = \
1da177e4
LT
24 __ATTR(_name, 0644, _name##_show, _name##_store)
25
f125b561 26#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
0f76e5ac 27/* current uevent sequence number */
386f275f
KS
28static ssize_t uevent_seqnum_show(struct kobject *kobj,
29 struct kobj_attribute *attr, char *buf)
1da177e4 30{
386f275f 31 return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum);
1da177e4 32}
0f76e5ac
KS
33KERNEL_ATTR_RO(uevent_seqnum);
34
35/* uevent helper program, used during early boo */
386f275f
KS
36static ssize_t uevent_helper_show(struct kobject *kobj,
37 struct kobj_attribute *attr, char *buf)
0f76e5ac 38{
386f275f 39 return sprintf(buf, "%s\n", uevent_helper);
0f76e5ac 40}
386f275f
KS
41static ssize_t uevent_helper_store(struct kobject *kobj,
42 struct kobj_attribute *attr,
43 const char *buf, size_t count)
0f76e5ac 44{
312c004d 45 if (count+1 > UEVENT_HELPER_PATH_LEN)
0f76e5ac 46 return -ENOENT;
386f275f 47 memcpy(uevent_helper, buf, count);
312c004d
KS
48 uevent_helper[count] = '\0';
49 if (count && uevent_helper[count-1] == '\n')
50 uevent_helper[count-1] = '\0';
0f76e5ac
KS
51 return count;
52}
53KERNEL_ATTR_RW(uevent_helper);
1da177e4
LT
54#endif
55
c330dda9 56#ifdef CONFIG_KEXEC
386f275f
KS
57static ssize_t kexec_loaded_show(struct kobject *kobj,
58 struct kobj_attribute *attr, char *buf)
c330dda9 59{
386f275f 60 return sprintf(buf, "%d\n", !!kexec_image);
c330dda9
JM
61}
62KERNEL_ATTR_RO(kexec_loaded);
63
386f275f
KS
64static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
65 struct kobj_attribute *attr, char *buf)
c330dda9 66{
386f275f 67 return sprintf(buf, "%d\n", !!kexec_crash_image);
c330dda9
JM
68}
69KERNEL_ATTR_RO(kexec_crash_loaded);
fd59d231 70
386f275f
KS
71static ssize_t vmcoreinfo_show(struct kobject *kobj,
72 struct kobj_attribute *attr, char *buf)
fd59d231 73{
386f275f 74 return sprintf(buf, "%lx %x\n",
fd59d231 75 paddr_vmcoreinfo_note(),
d768281e 76 (unsigned int)vmcoreinfo_max_size);
fd59d231
KO
77}
78KERNEL_ATTR_RO(vmcoreinfo);
79
c330dda9
JM
80#endif /* CONFIG_KEXEC */
81
da1a679c
RM
82/*
83 * Make /sys/kernel/notes give the raw contents of our kernel .notes section.
84 */
0b1937ac
DH
85extern const void __start_notes __attribute__((weak));
86extern const void __stop_notes __attribute__((weak));
da1a679c
RM
87#define notes_size (&__stop_notes - &__start_notes)
88
89static ssize_t notes_read(struct kobject *kobj, struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
91{
92 memcpy(buf, &__start_notes + off, count);
93 return count;
94}
95
96static struct bin_attribute notes_attr = {
97 .attr = {
98 .name = "notes",
99 .mode = S_IRUGO,
100 },
101 .read = &notes_read,
102};
103
0ff21e46
GKH
104struct kobject *kernel_kobj;
105EXPORT_SYMBOL_GPL(kernel_kobj);
1da177e4
LT
106
107static struct attribute * kernel_attrs[] = {
f125b561 108#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
0f76e5ac
KS
109 &uevent_seqnum_attr.attr,
110 &uevent_helper_attr.attr,
c330dda9
JM
111#endif
112#ifdef CONFIG_KEXEC
113 &kexec_loaded_attr.attr,
114 &kexec_crash_loaded_attr.attr,
fd59d231 115 &vmcoreinfo_attr.attr,
1da177e4
LT
116#endif
117 NULL
118};
119
120static struct attribute_group kernel_attr_group = {
121 .attrs = kernel_attrs,
122};
123
124static int __init ksysfs_init(void)
125{
bd35b93d 126 int error;
1da177e4 127
0ff21e46
GKH
128 kernel_kobj = kobject_create_and_add("kernel", NULL);
129 if (!kernel_kobj) {
bd35b93d
GKH
130 error = -ENOMEM;
131 goto exit;
132 }
0ff21e46 133 error = sysfs_create_group(kernel_kobj, &kernel_attr_group);
bd35b93d
GKH
134 if (error)
135 goto kset_exit;
136
137 if (notes_size > 0) {
da1a679c 138 notes_attr.size = notes_size;
0ff21e46 139 error = sysfs_create_bin_file(kernel_kobj, &notes_attr);
bd35b93d
GKH
140 if (error)
141 goto group_exit;
da1a679c
RM
142 }
143
eb41d946
KS
144 /* create the /sys/kernel/uids/ directory */
145 error = uids_sysfs_init();
bd35b93d
GKH
146 if (error)
147 goto notes_exit;
148
149 return 0;
150
151notes_exit:
152 if (notes_size > 0)
0ff21e46 153 sysfs_remove_bin_file(kernel_kobj, &notes_attr);
bd35b93d 154group_exit:
0ff21e46 155 sysfs_remove_group(kernel_kobj, &kernel_attr_group);
bd35b93d 156kset_exit:
78a2d906 157 kobject_put(kernel_kobj);
bd35b93d 158exit:
1da177e4
LT
159 return error;
160}
161
162core_initcall(ksysfs_init);