Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec...
[safe/jmp/linux-2.6] / fs / proc / kcore.c
index c6a5ec7..a44a789 100644 (file)
@@ -23,7 +23,6 @@
 #include <asm/io.h>
 #include <linux/list.h>
 #include <linux/ioport.h>
-#include <linux/mm.h>
 #include <linux/memory.h>
 #include <asm/sections.h>
 
@@ -107,6 +106,8 @@ static void free_kclist_ents(struct list_head *head)
  */
 static void __kcore_update_ram(struct list_head *list)
 {
+       int nphdr;
+       size_t size;
        struct kcore_list *tmp, *pos;
        LIST_HEAD(garbage);
 
@@ -121,6 +122,7 @@ static void __kcore_update_ram(struct list_head *list)
        } else
                list_splice(list, &garbage);
        kcore_need_update = 0;
+       proc_root_kcore->size = get_kcore_size(&nphdr, &size);
        write_unlock(&kclist_lock);
 
        free_kclist_ents(&garbage);
@@ -429,7 +431,8 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
        unsigned long start;
 
        read_lock(&kclist_lock);
-       proc_root_kcore->size = size = get_kcore_size(&nphdr, &elf_buflen);
+       size = get_kcore_size(&nphdr, &elf_buflen);
+
        if (buflen == 0 || *fpos >= size) {
                read_unlock(&kclist_lock);
                return 0;
@@ -542,6 +545,11 @@ static int open_kcore(struct inode *inode, struct file *filp)
                return -EPERM;
        if (kcore_need_update)
                kcore_update_ram();
+       if (i_size_read(inode) != proc_root_kcore->size) {
+               mutex_lock(&inode->i_mutex);
+               i_size_write(inode, proc_root_kcore->size);
+               mutex_unlock(&inode->i_mutex);
+       }
        return 0;
 }
 
@@ -606,6 +614,10 @@ static int __init proc_kcore_init(void)
 {
        proc_root_kcore = proc_create("kcore", S_IRUSR, NULL,
                                      &proc_kcore_operations);
+       if (!proc_root_kcore) {
+               printk(KERN_ERR "couldn't create /proc/kcore\n");
+               return 0; /* Always returns 0. */
+       }
        /* Store text area if it's special */
        proc_kcore_text_init();
        /* Store vmalloc area */
@@ -615,7 +627,6 @@ static int __init proc_kcore_init(void)
        /* Store direct-map area from physical memory map */
        kcore_update_ram();
        hotplug_memory_notifier(kcore_callback, 0);
-       /* Other special area, area-for-module etc is arch specific. */
 
        return 0;
 }