Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: Add missing mutex_unlock

Add a mutex_unlock missing on the error path. At other exists from the
function that return an error flag, the mutex is unlocked, so do the same
here.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression E1;
@@

* mutex_lock(E1,...);
<+... when != E1
if (...) {
... when != E1
* return ...;
}
...+>
* mutex_unlock(E1,...);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Julia Lawall and committed by
Al Viro
cc967be5 ea635c64

+9 -4
+9 -4
fs/pipe.c
··· 1169 1169 1170 1170 switch (cmd) { 1171 1171 case F_SETPIPE_SZ: 1172 - if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) 1173 - return -EINVAL; 1172 + if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) { 1173 + ret = -EINVAL; 1174 + goto out; 1175 + } 1174 1176 /* 1175 1177 * The pipe needs to be at least 2 pages large to 1176 1178 * guarantee POSIX behaviour. 1177 1179 */ 1178 - if (arg < 2) 1179 - return -EINVAL; 1180 + if (arg < 2) { 1181 + ret = -EINVAL; 1182 + goto out; 1183 + } 1180 1184 ret = pipe_set_size(pipe, arg); 1181 1185 break; 1182 1186 case F_GETPIPE_SZ: ··· 1191 1187 break; 1192 1188 } 1193 1189 1190 + out: 1194 1191 mutex_unlock(&pipe->inode->i_mutex); 1195 1192 return ret; 1196 1193 }