提交 390cd85c 编写于 作者: J Jaswinder Singh Rajput

x86: kdebugfs.c cleanup

Impact: cleanup
Signed-off-by: NJaswinder Singh Rajput <jaswinderrajput@gmail.com>
上级 271eb5c5
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
*/ */
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/stat.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/stat.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/module.h>
#include <asm/setup.h> #include <asm/setup.h>
...@@ -26,9 +26,8 @@ struct setup_data_node { ...@@ -26,9 +26,8 @@ struct setup_data_node {
u32 len; u32 len;
}; };
static ssize_t static ssize_t setup_data_read(struct file *file, char __user *user_buf,
setup_data_read(struct file *file, char __user *user_buf, size_t count, size_t count, loff_t *ppos)
loff_t *ppos)
{ {
struct setup_data_node *node = file->private_data; struct setup_data_node *node = file->private_data;
unsigned long remain; unsigned long remain;
...@@ -39,20 +38,21 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count, ...@@ -39,20 +38,21 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count,
if (pos < 0) if (pos < 0)
return -EINVAL; return -EINVAL;
if (pos >= node->len) if (pos >= node->len)
return 0; return 0;
if (count > node->len - pos) if (count > node->len - pos)
count = node->len - pos; count = node->len - pos;
pa = node->paddr + sizeof(struct setup_data) + pos; pa = node->paddr + sizeof(struct setup_data) + pos;
pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT); pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT);
if (PageHighMem(pg)) { if (PageHighMem(pg)) {
p = ioremap_cache(pa, count); p = ioremap_cache(pa, count);
if (!p) if (!p)
return -ENXIO; return -ENXIO;
} else { } else
p = __va(pa); p = __va(pa);
}
remain = copy_to_user(user_buf, p, count); remain = copy_to_user(user_buf, p, count);
...@@ -70,12 +70,13 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count, ...@@ -70,12 +70,13 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count,
static int setup_data_open(struct inode *inode, struct file *file) static int setup_data_open(struct inode *inode, struct file *file)
{ {
file->private_data = inode->i_private; file->private_data = inode->i_private;
return 0; return 0;
} }
static const struct file_operations fops_setup_data = { static const struct file_operations fops_setup_data = {
.read = setup_data_read, .read = setup_data_read,
.open = setup_data_open, .open = setup_data_open,
}; };
static int __init static int __init
...@@ -84,57 +85,50 @@ create_setup_data_node(struct dentry *parent, int no, ...@@ -84,57 +85,50 @@ create_setup_data_node(struct dentry *parent, int no,
{ {
struct dentry *d, *type, *data; struct dentry *d, *type, *data;
char buf[16]; char buf[16];
int error;
sprintf(buf, "%d", no); sprintf(buf, "%d", no);
d = debugfs_create_dir(buf, parent); d = debugfs_create_dir(buf, parent);
if (!d) { if (!d)
error = -ENOMEM; return -ENOMEM;
goto err_return;
}
type = debugfs_create_x32("type", S_IRUGO, d, &node->type); type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
if (!type) { if (!type)
error = -ENOMEM;
goto err_dir; goto err_dir;
}
data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
if (!data) { if (!data)
error = -ENOMEM;
goto err_type; goto err_type;
}
return 0; return 0;
err_type: err_type:
debugfs_remove(type); debugfs_remove(type);
err_dir: err_dir:
debugfs_remove(d); debugfs_remove(d);
err_return: return -ENOMEM;
return error;
} }
static int __init create_setup_data_nodes(struct dentry *parent) static int __init create_setup_data_nodes(struct dentry *parent)
{ {
struct setup_data_node *node; struct setup_data_node *node;
struct setup_data *data; struct setup_data *data;
int error, no = 0; int error = -ENOMEM;
struct dentry *d; struct dentry *d;
struct page *pg; struct page *pg;
u64 pa_data; u64 pa_data;
int no = 0;
d = debugfs_create_dir("setup_data", parent); d = debugfs_create_dir("setup_data", parent);
if (!d) { if (!d)
error = -ENOMEM; return -ENOMEM;
goto err_return;
}
pa_data = boot_params.hdr.setup_data; pa_data = boot_params.hdr.setup_data;
while (pa_data) { while (pa_data) {
node = kmalloc(sizeof(*node), GFP_KERNEL); node = kmalloc(sizeof(*node), GFP_KERNEL);
if (!node) { if (!node)
error = -ENOMEM;
goto err_dir; goto err_dir;
}
pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT); pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
if (PageHighMem(pg)) { if (PageHighMem(pg)) {
data = ioremap_cache(pa_data, sizeof(*data)); data = ioremap_cache(pa_data, sizeof(*data));
...@@ -143,9 +137,8 @@ static int __init create_setup_data_nodes(struct dentry *parent) ...@@ -143,9 +137,8 @@ static int __init create_setup_data_nodes(struct dentry *parent)
error = -ENXIO; error = -ENXIO;
goto err_dir; goto err_dir;
} }
} else { } else
data = __va(pa_data); data = __va(pa_data);
}
node->paddr = pa_data; node->paddr = pa_data;
node->type = data->type; node->type = data->type;
...@@ -159,11 +152,11 @@ static int __init create_setup_data_nodes(struct dentry *parent) ...@@ -159,11 +152,11 @@ static int __init create_setup_data_nodes(struct dentry *parent)
goto err_dir; goto err_dir;
no++; no++;
} }
return 0; return 0;
err_dir: err_dir:
debugfs_remove(d); debugfs_remove(d);
err_return:
return error; return error;
} }
...@@ -175,28 +168,26 @@ static struct debugfs_blob_wrapper boot_params_blob = { ...@@ -175,28 +168,26 @@ static struct debugfs_blob_wrapper boot_params_blob = {
static int __init boot_params_kdebugfs_init(void) static int __init boot_params_kdebugfs_init(void)
{ {
struct dentry *dbp, *version, *data; struct dentry *dbp, *version, *data;
int error; int error = -ENOMEM;
dbp = debugfs_create_dir("boot_params", NULL); dbp = debugfs_create_dir("boot_params", NULL);
if (!dbp) { if (!dbp)
error = -ENOMEM; return -ENOMEM;
goto err_return;
}
version = debugfs_create_x16("version", S_IRUGO, dbp, version = debugfs_create_x16("version", S_IRUGO, dbp,
&boot_params.hdr.version); &boot_params.hdr.version);
if (!version) { if (!version)
error = -ENOMEM;
goto err_dir; goto err_dir;
}
data = debugfs_create_blob("data", S_IRUGO, dbp, data = debugfs_create_blob("data", S_IRUGO, dbp,
&boot_params_blob); &boot_params_blob);
if (!data) { if (!data)
error = -ENOMEM;
goto err_version; goto err_version;
}
error = create_setup_data_nodes(dbp); error = create_setup_data_nodes(dbp);
if (error) if (error)
goto err_data; goto err_data;
return 0; return 0;
err_data: err_data:
...@@ -205,10 +196,9 @@ static int __init boot_params_kdebugfs_init(void) ...@@ -205,10 +196,9 @@ static int __init boot_params_kdebugfs_init(void)
debugfs_remove(version); debugfs_remove(version);
err_dir: err_dir:
debugfs_remove(dbp); debugfs_remove(dbp);
err_return:
return error; return error;
} }
#endif #endif /* CONFIG_DEBUG_BOOT_PARAMS */
static int __init arch_kdebugfs_init(void) static int __init arch_kdebugfs_init(void)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册