x86: kdebugfs.c cleanup
PATCH 1/1 x86: kdebugfs.c cleanup
Subject: [PATCH] x86: kdebugfs.c cleanup
Impact: cleanup
--- arch/x86/kernel/kdebugfs.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-)
arch/x86/kernel/kdebugfs.c +23 -12
@@ -8,11 +8,11 @@*/ #include <linux/debugfs.h> #include <linux/uaccess.h> -#include <linux/stat.h> +#include <linux/module.h> #include <linux/init.h> +#include <linux/stat.h> #include <linux/io.h> #include <linux/mm.h> -#include <linux/module.h> #include <asm/setup.h>
@@ -26,9 +26,8 @@ struct setup_data_node {u32 len; }; -static ssize_t -setup_data_read (struct file *file,char __user *user_buf,size_t count, -loff_t *ppos) +static ssize_t setup_data_read (struct file *file,char __user *user_buf, +size_t count,loff_t *ppos) {struct setup_data_node *node = file->private_data;unsigned long remain;
@@ -39,20 +38,21 @@ setup_data_read(struct file *file, char __user *user_buf, size_t count,if (pos <0 )return -EINVAL ; +if (pos >= node->len)return 0 ;if (count > node->len - pos) count = node->len - pos; + pa = node->paddr +sizeof (struct setup_data ) + pos; pg =pfn_to_page ((pa + count -1 ) >>PAGE_SHIFT );if (PageHighMem (pg)) { p =ioremap_cache (pa, count);if (!p)return -ENXIO ; - }else { + }else p =__va (pa); - } 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,static int setup_data_open (struct inode *inode,struct file *file) { file->private_data = inode->i_private; +return 0 ; }static const struct file_operations fops_setup_data = { - .read = setup_data_read, - .open = setup_data_open, + .read = setup_data_read, + .open = setup_data_open, }; static int __init
@@ -92,16 +93,19 @@ create_setup_data_node(struct dentry *parent, int no, error = -ENOMEM ; goto err_return; } + type =debugfs_create_x32 ("type" ,S_IRUGO , d, &node->type);if (!type) { error = -ENOMEM ; goto err_dir; } + data =debugfs_create_file ("data" ,S_IRUGO , d, node, &fops_setup_data);if (!data) { error = -ENOMEM ; goto err_type; } +return 0 ; err_type:
@@ -135,6 +139,7 @@ static int __init create_setup_data_nodes(struct dentry *parent) error = -ENOMEM ; goto err_dir; } + pg =pfn_to_page ((pa_data+sizeof (*data)-1 ) >>PAGE_SHIFT );if (PageHighMem (pg)) { data =ioremap_cache (pa_data,sizeof (*data));
@@ -143,9 +148,8 @@ static int __init create_setup_data_nodes(struct dentry *parent) error = -ENXIO ; goto err_dir; } - }else { + }else data =__va (pa_data); - } node->paddr = pa_data; node->type = data->type;
@@ -155,10 +159,13 @@ static int __init create_setup_data_nodes(struct dentry *parent)if (PageHighMem (pg))iounmap (data); +if (error) goto err_dir; + no++; } +return 0 ; err_dir:
@@ -182,21 +189,25 @@ static int __init boot_params_kdebugfs_init(void) error = -ENOMEM ; goto err_return; } + version =debugfs_create_x16 ("version" ,S_IRUGO , dbp, &boot_params.hdr.version);if (!version) { error = -ENOMEM ; goto err_dir; } + data =debugfs_create_blob ("data" ,S_IRUGO , dbp, &boot_params_blob);if (!data) { error = -ENOMEM ; goto err_version; } + error =create_setup_data_nodes (dbp);if (error) goto err_data; +return 0 ; err_data:
@@ -208,7 +219,7 @@ err_dir: err_return: return error; } -#endif +#endif /* CONFIG_DEBUG_BOOT_PARAMS */ static int __init arch_kdebugfs_init (void ) {
Signature · 1 line
1.6.0.6
arch/x86/kernel/kdebugfs.c line 15
Quoted 10 lines
#include <
linux/debugfs.h>
#include <linux/uaccess.h>arch/x86/kernel/kdebugfs.c +2
-2-#include <linux/stat.h> +#include <linux/module.h> #include <linux/init.h> +#include <linux/stat.h> #include <linux/io.h> #include <linux/mm.h> -#include <linux/module.h>
Just curious about the rule to sort those includes, and why they need to be rearranged.
Quoted 2 lines
#include <
asm/setup.h>
Quoted 5 lines · Li Zefan
Quoted 5 lines
#include <
linux/debugfs.h>
#include <linux/uaccess.h>arch/x86/kernel/kdebugfs.c +1
-1-#include <linux/stat.h> +#include <linux/module.h> #include <linux/init.h>
Quoted 8 lines
arch/x86/kernel/kdebugfs.c line 15
Quoted 5 lines
arch/x86/kernel/kdebugfs.c +1
-1+#include <linux/stat.h> #include <linux/io.h> #include <linux/mm.h> -#include <linux/module.h> Just curious about the rule to sort those includes, and why they need to be rearranged.
Such includes (the 'reverse christmas tree'):
#include <linux/interrupt.h>
#include <linux/mmiotrace.h>
#include <linux/bootmem.h>
#include <linux/compiler.h>
#include <linux/highmem.h>
#include <linux/kprobes.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <linux/vt_kern.h>
#include <linux/signal.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/string.h>
#include <linux/module.h>
#include <linux/kdebug.h>
#include <linux/errno.h>
#include <linux/magic.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/mman.h>
#include <linux/tty.h>
#include <linux/smp.h>
#include <linux/mm.h>
#include <asm/kmemcheck.h>
#include <asm/tlbflush.h>
#include <asm/pgalloc.h>
#include <asm/segment.h>
#include <asm/system.h>
#include <asm/proto.h>
#include <asm/traps.h>
#include <asm/desc.h>
are used by x86 architecture code (and some other subsystems) to reduce the likelyhood of patch conflicts in commonly modified kernel files.
Without such ordering developers typically append to the existing list of include files when introducing a new header - creating an almost certain patch conflict. Via the above ordering, new headers get distributed roughly evenly amongst the full range - and thus the chance of patch conflicts is much smaller.
This way it also looks a bit more structured and bit less messy. It looks unprofessional and sloppy if a .c file starts with a big block of thrown-together include files.
Ingo