linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PATCH 2.4.21 make open_exec() more readable
@ 2003-07-05 17:21 Walter Harms
  0 siblings, 0 replies; only message in thread
From: Walter Harms @ 2003-07-05 17:21 UTC (permalink / raw)
  To: kernel linux

Hi list,
i found open_exec() had several indent level. To much to be usefull.
To make it a bit more readable i changed it a bit (adding goto's
this time). The patch contains also cosmetic changes to 
kernel_read() and exec_mmap(). removing some tab's make it larger
that they are.
There are no fuctional changes intended !

Note: this time with diff -u :)

walter
--- fs/exec.c.org       2003-07-02 21:38:15.000000000 +0200
+++ fs/exec.c   2003-07-02 22:00:19.000000000 +0200
@@ -368,33 +368,44 @@
        struct file *file;
        int err = 0;
 
-       err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd);
-       file = ERR_PTR(err);
-       if (!err) {
-               inode = nd.dentry->d_inode;
-               file = ERR_PTR(-EACCES);
-               if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
-                   S_ISREG(inode->i_mode)) {
-                       int err = permission(inode, MAY_EXEC);
-                       if (!err && !(inode->i_mode & 0111))
-                               err = -EACCES;
+       err = path_lookup(name, LOOKUP_FOLLOW | LOOKUP_POSITIVE, &nd);
+       if (err)
+               return ERR_PTR(err);
+
+       inode = nd.dentry->d_inode;
+       file = ERR_PTR(-EACCES);
+
+       if (!S_ISREG(inode->i_mode))
+               goto error;
+
+       if (nd.mnt->mnt_flags & MNT_NOEXEC)
+               goto error;
+
+       err = permission(inode, MAY_EXEC);
+       if (err) 
+               goto error;
+       /* To check:
+          is this useless ?
+       */
+
+       if (!(inode->i_mode & 0111)) 
+               goto error;
+
+
+       file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
+       if (!IS_ERR(file)) {
+               err = deny_write_access(file);
+               if (err) {
+                       fput(file);
                        file = ERR_PTR(err);
-                       if (!err) {
-                               file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
-                               if (!IS_ERR(file)) {
-                                       err = deny_write_access(file);
-                                       if (err) {
-                                               fput(file);
-                                               file = ERR_PTR(err);
-                                       }
-                               }
-out:
-                               return file;
-                       }
                }
-               path_release(&nd);
        }
-       goto out;
+       return file;
+
+      error:
+       path_release(&nd);
+       return file;
+
 }
 
 int kernel_read(struct file *file, unsigned long offset,
@@ -404,20 +415,19 @@
        loff_t pos = offset;
        int result = -ENOSYS;
 
-       if (!file->f_op->read)
-               goto fail;
-       old_fs = get_fs();
-       set_fs(get_ds());
-       result = file->f_op->read(file, addr, count, &pos);
-       set_fs(old_fs);
-fail:
+       if (file->f_op->read) {
+               old_fs = get_fs();
+               set_fs(get_ds());
+               result = file->f_op->read(file, addr, count, &pos);
+               set_fs(old_fs);
+       }
        return result;
 }
 
 static int exec_mmap(void)
 {
        struct mm_struct * mm, * old_mm;
-
+       struct mm_struct *active_mm;
        old_mm = current->mm;
        if (old_mm && atomic_read(&old_mm->mm_users) == 1) {
                mm_release();
@@ -426,36 +436,37 @@
        }
 
        mm = mm_alloc();
-       if (mm) {
-               struct mm_struct *active_mm;
+       if (!mm) {
+               return -ENOMEM;
+       }
+
 
-               if (init_new_context(current, mm)) {
-                       mmdrop(mm);
-                       return -ENOMEM;
-               }
+       if (init_new_context(current, mm)) {
+               mmdrop(mm);
+               return -ENOMEM;
+       }
 
-               /* Add it to the list of mm's */
-               spin_lock(&mmlist_lock);
-               list_add(&mm->mmlist, &init_mm.mmlist);
-               mmlist_nr++;
-               spin_unlock(&mmlist_lock);
-
-               task_lock(current);
-               active_mm = current->active_mm;
-               current->mm = mm;
-               current->active_mm = mm;
-               task_unlock(current);
-               activate_mm(active_mm, mm);
-               mm_release();
-               if (old_mm) {
-                       if (active_mm != old_mm) BUG();
-                       mmput(old_mm);
-                       return 0;
-               }
-               mmdrop(active_mm);
+       /* Add it to the list of mm's */
+       spin_lock(&mmlist_lock);
+       list_add(&mm->mmlist, &init_mm.mmlist);
+       mmlist_nr++;
+       spin_unlock(&mmlist_lock);
+
+       task_lock(current);
+       active_mm = current->active_mm;
+       current->mm = mm;
+       current->active_mm = mm;
+       task_unlock(current);
+       activate_mm(active_mm, mm);
+       mm_release();
+       if (old_mm) {
+               if (active_mm != old_mm) BUG();
+               mmput(old_mm);
                return 0;
        }
-       return -ENOMEM;
+       mmdrop(active_mm);
+       return 0;
+
 }
 
 /*

-- 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-05 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-05 17:21 PATCH 2.4.21 make open_exec() more readable Walter Harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).