diff options
author | Jaswinder Singh Rajput <jaswinderrajput@gmail.com> | 2009-03-21 07:25:45 -0400 |
---|---|---|
committer | Jaswinder Singh Rajput <jaswinderrajput@gmail.com> | 2009-03-21 07:25:45 -0400 |
commit | 390cd85c8ae4dc54ffba460a0e6575889170f56e (patch) | |
tree | f21c85379420b703907932fbd21ae683431950be /arch/x86/kernel/kdebugfs.c | |
parent | 271eb5c588e5d0a41eca6e118b6927af3f0f04b9 (diff) |
x86: kdebugfs.c cleanup
Impact: cleanup
Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
Diffstat (limited to 'arch/x86/kernel/kdebugfs.c')
-rw-r--r-- | arch/x86/kernel/kdebugfs.c | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c index ff7d3b0124f1..e444357375ce 100644 --- a/arch/x86/kernel/kdebugfs.c +++ b/arch/x86/kernel/kdebugfs.c | |||
@@ -8,11 +8,11 @@ | |||
8 | */ | 8 | */ |
9 | #include <linux/debugfs.h> | 9 | #include <linux/debugfs.h> |
10 | #include <linux/uaccess.h> | 10 | #include <linux/uaccess.h> |
11 | #include <linux/stat.h> | 11 | #include <linux/module.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/stat.h> | ||
13 | #include <linux/io.h> | 14 | #include <linux/io.h> |
14 | #include <linux/mm.h> | 15 | #include <linux/mm.h> |
15 | #include <linux/module.h> | ||
16 | 16 | ||
17 | #include <asm/setup.h> | 17 | #include <asm/setup.h> |
18 | 18 | ||
@@ -26,9 +26,8 @@ struct setup_data_node { | |||
26 | u32 len; | 26 | u32 len; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | static ssize_t | 29 | static ssize_t setup_data_read(struct file *file, char __user *user_buf, |
30 | setup_data_read(struct file *file, char __user *user_buf, size_t count, | 30 | size_t count, loff_t *ppos) |
31 | loff_t *ppos) | ||
32 | { | 31 | { |
33 | struct setup_data_node *node = file->private_data; | 32 | struct setup_data_node *node = file->private_data; |
34 | unsigned long remain; | 33 | unsigned long remain; |
@@ -39,20 +38,21 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count, | |||
39 | 38 | ||
40 | if (pos < 0) | 39 | if (pos < 0) |
41 | return -EINVAL; | 40 | return -EINVAL; |
41 | |||
42 | if (pos >= node->len) | 42 | if (pos >= node->len) |
43 | return 0; | 43 | return 0; |
44 | 44 | ||
45 | if (count > node->len - pos) | 45 | if (count > node->len - pos) |
46 | count = node->len - pos; | 46 | count = node->len - pos; |
47 | |||
47 | pa = node->paddr + sizeof(struct setup_data) + pos; | 48 | pa = node->paddr + sizeof(struct setup_data) + pos; |
48 | pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT); | 49 | pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT); |
49 | if (PageHighMem(pg)) { | 50 | if (PageHighMem(pg)) { |
50 | p = ioremap_cache(pa, count); | 51 | p = ioremap_cache(pa, count); |
51 | if (!p) | 52 | if (!p) |
52 | return -ENXIO; | 53 | return -ENXIO; |
53 | } else { | 54 | } else |
54 | p = __va(pa); | 55 | p = __va(pa); |
55 | } | ||
56 | 56 | ||
57 | remain = copy_to_user(user_buf, p, count); | 57 | remain = copy_to_user(user_buf, p, count); |
58 | 58 | ||
@@ -70,12 +70,13 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count, | |||
70 | static int setup_data_open(struct inode *inode, struct file *file) | 70 | static int setup_data_open(struct inode *inode, struct file *file) |
71 | { | 71 | { |
72 | file->private_data = inode->i_private; | 72 | file->private_data = inode->i_private; |
73 | |||
73 | return 0; | 74 | return 0; |
74 | } | 75 | } |
75 | 76 | ||
76 | static const struct file_operations fops_setup_data = { | 77 | static const struct file_operations fops_setup_data = { |
77 | .read = setup_data_read, | 78 | .read = setup_data_read, |
78 | .open = setup_data_open, | 79 | .open = setup_data_open, |
79 | }; | 80 | }; |
80 | 81 | ||
81 | static int __init | 82 | static int __init |
@@ -84,57 +85,50 @@ create_setup_data_node(struct dentry *parent, int no, | |||
84 | { | 85 | { |
85 | struct dentry *d, *type, *data; | 86 | struct dentry *d, *type, *data; |
86 | char buf[16]; | 87 | char buf[16]; |
87 | int error; | ||
88 | 88 | ||
89 | sprintf(buf, "%d", no); | 89 | sprintf(buf, "%d", no); |
90 | d = debugfs_create_dir(buf, parent); | 90 | d = debugfs_create_dir(buf, parent); |
91 | if (!d) { | 91 | if (!d) |
92 | error = -ENOMEM; | 92 | return -ENOMEM; |
93 | goto err_return; | 93 | |
94 | } | ||
95 | type = debugfs_create_x32("type", S_IRUGO, d, &node->type); | 94 | type = debugfs_create_x32("type", S_IRUGO, d, &node->type); |
96 | if (!type) { | 95 | if (!type) |
97 | error = -ENOMEM; | ||
98 | goto err_dir; | 96 | goto err_dir; |
99 | } | 97 | |
100 | data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); | 98 | data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); |
101 | if (!data) { | 99 | if (!data) |
102 | error = -ENOMEM; | ||
103 | goto err_type; | 100 | goto err_type; |
104 | } | 101 | |
105 | return 0; | 102 | return 0; |
106 | 103 | ||
107 | err_type: | 104 | err_type: |
108 | debugfs_remove(type); | 105 | debugfs_remove(type); |
109 | err_dir: | 106 | err_dir: |
110 | debugfs_remove(d); | 107 | debugfs_remove(d); |
111 | err_return: | 108 | return -ENOMEM; |
112 | return error; | ||
113 | } | 109 | } |
114 | 110 | ||
115 | static int __init create_setup_data_nodes(struct dentry *parent) | 111 | static int __init create_setup_data_nodes(struct dentry *parent) |
116 | { | 112 | { |
117 | struct setup_data_node *node; | 113 | struct setup_data_node *node; |
118 | struct setup_data *data; | 114 | struct setup_data *data; |
119 | int error, no = 0; | 115 | int error = -ENOMEM; |
120 | struct dentry *d; | 116 | struct dentry *d; |
121 | struct page *pg; | 117 | struct page *pg; |
122 | u64 pa_data; | 118 | u64 pa_data; |
119 | int no = 0; | ||
123 | 120 | ||
124 | d = debugfs_create_dir("setup_data", parent); | 121 | d = debugfs_create_dir("setup_data", parent); |
125 | if (!d) { | 122 | if (!d) |
126 | error = -ENOMEM; | 123 | return -ENOMEM; |
127 | goto err_return; | ||
128 | } | ||
129 | 124 | ||
130 | pa_data = boot_params.hdr.setup_data; | 125 | pa_data = boot_params.hdr.setup_data; |
131 | 126 | ||
132 | while (pa_data) { | 127 | while (pa_data) { |
133 | node = kmalloc(sizeof(*node), GFP_KERNEL); | 128 | node = kmalloc(sizeof(*node), GFP_KERNEL); |
134 | if (!node) { | 129 | if (!node) |
135 | error = -ENOMEM; | ||
136 | goto err_dir; | 130 | goto err_dir; |
137 | } | 131 | |
138 | pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT); | 132 | pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT); |
139 | if (PageHighMem(pg)) { | 133 | if (PageHighMem(pg)) { |
140 | data = ioremap_cache(pa_data, sizeof(*data)); | 134 | data = ioremap_cache(pa_data, sizeof(*data)); |
@@ -143,9 +137,8 @@ static int __init create_setup_data_nodes(struct dentry *parent) | |||
143 | error = -ENXIO; | 137 | error = -ENXIO; |
144 | goto err_dir; | 138 | goto err_dir; |
145 | } | 139 | } |
146 | } else { | 140 | } else |
147 | data = __va(pa_data); | 141 | data = __va(pa_data); |
148 | } | ||
149 | 142 | ||
150 | node->paddr = pa_data; | 143 | node->paddr = pa_data; |
151 | node->type = data->type; | 144 | node->type = data->type; |
@@ -159,11 +152,11 @@ static int __init create_setup_data_nodes(struct dentry *parent) | |||
159 | goto err_dir; | 152 | goto err_dir; |
160 | no++; | 153 | no++; |
161 | } | 154 | } |
155 | |||
162 | return 0; | 156 | return 0; |
163 | 157 | ||
164 | err_dir: | 158 | err_dir: |
165 | debugfs_remove(d); | 159 | debugfs_remove(d); |
166 | err_return: | ||
167 | return error; | 160 | return error; |
168 | } | 161 | } |
169 | 162 | ||
@@ -175,28 +168,26 @@ static struct debugfs_blob_wrapper boot_params_blob = { | |||
175 | static int __init boot_params_kdebugfs_init(void) | 168 | static int __init boot_params_kdebugfs_init(void) |
176 | { | 169 | { |
177 | struct dentry *dbp, *version, *data; | 170 | struct dentry *dbp, *version, *data; |
178 | int error; | 171 | int error = -ENOMEM; |
179 | 172 | ||
180 | dbp = debugfs_create_dir("boot_params", NULL); | 173 | dbp = debugfs_create_dir("boot_params", NULL); |
181 | if (!dbp) { | 174 | if (!dbp) |
182 | error = -ENOMEM; | 175 | return -ENOMEM; |
183 | goto err_return; | 176 | |
184 | } | ||
185 | version = debugfs_create_x16("version", S_IRUGO, dbp, | 177 | version = debugfs_create_x16("version", S_IRUGO, dbp, |
186 | &boot_params.hdr.version); | 178 | &boot_params.hdr.version); |
187 | if (!version) { | 179 | if (!version) |
188 | error = -ENOMEM; | ||
189 | goto err_dir; | 180 | goto err_dir; |
190 | } | 181 | |
191 | data = debugfs_create_blob("data", S_IRUGO, dbp, | 182 | data = debugfs_create_blob("data", S_IRUGO, dbp, |
192 | &boot_params_blob); | 183 | &boot_params_blob); |
193 | if (!data) { | 184 | if (!data) |
194 | error = -ENOMEM; | ||
195 | goto err_version; | 185 | goto err_version; |
196 | } | 186 | |
197 | error = create_setup_data_nodes(dbp); | 187 | error = create_setup_data_nodes(dbp); |
198 | if (error) | 188 | if (error) |
199 | goto err_data; | 189 | goto err_data; |
190 | |||
200 | return 0; | 191 | return 0; |
201 | 192 | ||
202 | err_data: | 193 | err_data: |
@@ -205,10 +196,9 @@ err_version: | |||
205 | debugfs_remove(version); | 196 | debugfs_remove(version); |
206 | err_dir: | 197 | err_dir: |
207 | debugfs_remove(dbp); | 198 | debugfs_remove(dbp); |
208 | err_return: | ||
209 | return error; | 199 | return error; |
210 | } | 200 | } |
211 | #endif | 201 | #endif /* CONFIG_DEBUG_BOOT_PARAMS */ |
212 | 202 | ||
213 | static int __init arch_kdebugfs_init(void) | 203 | static int __init arch_kdebugfs_init(void) |
214 | { | 204 | { |