Commit dbb563ec7b143323dd31520ab08c08394bc13381

Authored by Davidlohr Bueso
Committed by Greg Kroah-Hartman
1 parent 610a094ba3

ipc,shm: cleanup do_shmat pasta

commit f42569b1388b1408b574a5e93a23a663647d4181 upstream.

Clean up some of the messy do_shmat() spaghetti code, getting rid of
out_free and out_put_dentry labels.  This makes shortening the critical
region of this function in the next patch a little easier to do and read.

Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 12 additions and 14 deletions Side-by-side Diff

... ... @@ -1115,16 +1115,21 @@
1115 1115  
1116 1116 err = -ENOMEM;
1117 1117 sfd = kzalloc(sizeof(*sfd), GFP_KERNEL);
1118   - if (!sfd)
1119   - goto out_put_dentry;
  1118 + if (!sfd) {
  1119 + path_put(&path);
  1120 + goto out_nattch;
  1121 + }
1120 1122  
1121 1123 file = alloc_file(&path, f_mode,
1122 1124 is_file_hugepages(shp->shm_file) ?
1123 1125 &shm_file_operations_huge :
1124 1126 &shm_file_operations);
1125 1127 err = PTR_ERR(file);
1126   - if (IS_ERR(file))
1127   - goto out_free;
  1128 + if (IS_ERR(file)) {
  1129 + kfree(sfd);
  1130 + path_put(&path);
  1131 + goto out_nattch;
  1132 + }
1128 1133  
1129 1134 file->private_data = sfd;
1130 1135 file->f_mapping = shp->shm_file->f_mapping;
... ... @@ -1150,7 +1155,7 @@
1150 1155 addr > current->mm->start_stack - size - PAGE_SIZE * 5)
1151 1156 goto invalid;
1152 1157 }
1153   -
  1158 +
1154 1159 addr = do_mmap_pgoff(file, addr, size, prot, flags, 0, &populate);
1155 1160 *raddr = addr;
1156 1161 err = 0;
1157 1162  
... ... @@ -1174,19 +1179,12 @@
1174 1179 else
1175 1180 shm_unlock(shp);
1176 1181 up_write(&shm_ids(ns).rw_mutex);
1177   -
1178   -out:
1179 1182 return err;
1180 1183  
1181 1184 out_unlock:
1182 1185 shm_unlock(shp);
1183   - goto out;
1184   -
1185   -out_free:
1186   - kfree(sfd);
1187   -out_put_dentry:
1188   - path_put(&path);
1189   - goto out_nattch;
  1186 +out:
  1187 + return err;
1190 1188 }
1191 1189  
1192 1190 SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)