Skip to content

Commit 390cd85

Browse files
x86: kdebugfs.c cleanup
Impact: cleanup Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
1 parent 271eb5c commit 390cd85

1 file changed

Lines changed: 36 additions & 46 deletions

File tree

‎arch/x86/kernel/kdebugfs.c‎

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99
#include <linux/debugfs.h>
1010
#include <linux/uaccess.h>
11-
#include <linux/stat.h>
11+
#include <linux/module.h>
1212
#include <linux/init.h>
13+
#include <linux/stat.h>
1314
#include <linux/io.h>
1415
#include <linux/mm.h>
15-
#include <linux/module.h>
1616

1717
#include <asm/setup.h>
1818

@@ -26,9 +26,8 @@ struct setup_data_node {
2626
u32 len;
2727
};
2828

29-
static ssize_t
30-
setup_data_read(struct file *file, char __user *user_buf, size_t count,
31-
loff_t *ppos)
29+
static ssize_t setup_data_read(struct file *file, char __user *user_buf,
30+
size_t count, loff_t *ppos)
3231
{
3332
struct setup_data_node *node = file->private_data;
3433
unsigned long remain;
@@ -39,20 +38,21 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count,
3938

4039
if (pos < 0)
4140
return -EINVAL;
41+
4242
if (pos >= node->len)
4343
return 0;
4444

4545
if (count > node->len - pos)
4646
count = node->len - pos;
47+
4748
pa = node->paddr + sizeof(struct setup_data) + pos;
4849
pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT);
4950
if (PageHighMem(pg)) {
5051
p = ioremap_cache(pa, count);
5152
if (!p)
5253
return -ENXIO;
53-
} else {
54+
} else
5455
p = __va(pa);
55-
}
5656

5757
remain = copy_to_user(user_buf, p, count);
5858

@@ -70,12 +70,13 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count,
7070
static int setup_data_open(struct inode *inode, struct file *file)
7171
{
7272
file->private_data = inode->i_private;
73+
7374
return 0;
7475
}
7576

7677
static const struct file_operations fops_setup_data = {
77-
.read = setup_data_read,
78-
.open = setup_data_open,
78+
.read = setup_data_read,
79+
.open = setup_data_open,
7980
};
8081

8182
static int __init
@@ -84,57 +85,50 @@ create_setup_data_node(struct dentry *parent, int no,
8485
{
8586
struct dentry *d, *type, *data;
8687
char buf[16];
87-
int error;
8888

8989
sprintf(buf, "%d", no);
9090
d = debugfs_create_dir(buf, parent);
91-
if (!d) {
92-
error = -ENOMEM;
93-
goto err_return;
94-
}
91+
if (!d)
92+
return -ENOMEM;
93+
9594
type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
96-
if (!type) {
97-
error = -ENOMEM;
95+
if (!type)
9896
goto err_dir;
99-
}
97+
10098
data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
101-
if (!data) {
102-
error = -ENOMEM;
99+
if (!data)
103100
goto err_type;
104-
}
101+
105102
return 0;
106103

107104
err_type:
108105
debugfs_remove(type);
109106
err_dir:
110107
debugfs_remove(d);
111-
err_return:
112-
return error;
108+
return -ENOMEM;
113109
}
114110

115111
static int __init create_setup_data_nodes(struct dentry *parent)
116112
{
117113
struct setup_data_node *node;
118114
struct setup_data *data;
119-
int error, no = 0;
115+
int error = -ENOMEM;
120116
struct dentry *d;
121117
struct page *pg;
122118
u64 pa_data;
119+
int no = 0;
123120

124121
d = debugfs_create_dir("setup_data", parent);
125-
if (!d) {
126-
error = -ENOMEM;
127-
goto err_return;
128-
}
122+
if (!d)
123+
return -ENOMEM;
129124

130125
pa_data = boot_params.hdr.setup_data;
131126

132127
while (pa_data) {
133128
node = kmalloc(sizeof(*node), GFP_KERNEL);
134-
if (!node) {
135-
error = -ENOMEM;
129+
if (!node)
136130
goto err_dir;
137-
}
131+
138132
pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
139133
if (PageHighMem(pg)) {
140134
data = ioremap_cache(pa_data, sizeof(*data));
@@ -143,9 +137,8 @@ static int __init create_setup_data_nodes(struct dentry *parent)
143137
error = -ENXIO;
144138
goto err_dir;
145139
}
146-
} else {
140+
} else
147141
data = __va(pa_data);
148-
}
149142

150143
node->paddr = pa_data;
151144
node->type = data->type;
@@ -159,11 +152,11 @@ static int __init create_setup_data_nodes(struct dentry *parent)
159152
goto err_dir;
160153
no++;
161154
}
155+
162156
return 0;
163157

164158
err_dir:
165159
debugfs_remove(d);
166-
err_return:
167160
return error;
168161
}
169162

@@ -175,28 +168,26 @@ static struct debugfs_blob_wrapper boot_params_blob = {
175168
static int __init boot_params_kdebugfs_init(void)
176169
{
177170
struct dentry *dbp, *version, *data;
178-
int error;
171+
int error = -ENOMEM;
179172

180173
dbp = debugfs_create_dir("boot_params", NULL);
181-
if (!dbp) {
182-
error = -ENOMEM;
183-
goto err_return;
184-
}
174+
if (!dbp)
175+
return -ENOMEM;
176+
185177
version = debugfs_create_x16("version", S_IRUGO, dbp,
186178
&boot_params.hdr.version);
187-
if (!version) {
188-
error = -ENOMEM;
179+
if (!version)
189180
goto err_dir;
190-
}
181+
191182
data = debugfs_create_blob("data", S_IRUGO, dbp,
192183
&boot_params_blob);
193-
if (!data) {
194-
error = -ENOMEM;
184+
if (!data)
195185
goto err_version;
196-
}
186+
197187
error = create_setup_data_nodes(dbp);
198188
if (error)
199189
goto err_data;
190+
200191
return 0;
201192

202193
err_data:
@@ -205,10 +196,9 @@ static int __init boot_params_kdebugfs_init(void)
205196
debugfs_remove(version);
206197
err_dir:
207198
debugfs_remove(dbp);
208-
err_return:
209199
return error;
210200
}
211-
#endif
201+
#endif /* CONFIG_DEBUG_BOOT_PARAMS */
212202

213203
static int __init arch_kdebugfs_init(void)
214204
{

0 commit comments

Comments
 (0)