Skip to content

Commit 1de2412

Browse files
ebiedermLinus Torvalds
authored andcommitted
[PATCH] ncpfs: ensure we free wdog_pid on parse_option or fill_inode failure
This took a little refactoring but now errors are handled cleanly. When this code used pid_t values this wasn't necessary because you can't leak a pid_t. Thanks to Peter Vandrovec for spotting this. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: Peter Vandrovec <vandrove@vc.cvut.cz> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 2154227 commit 1de2412

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎fs/ncpfs/inode.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options)
327327
char *optarg;
328328
unsigned long optint;
329329
int version = 0;
330+
int ret;
330331

331332
data->flags = 0;
332333
data->int_flags = 0;
@@ -343,8 +344,9 @@ static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options)
343344
data->mounted_vol[0] = 0;
344345

345346
while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
346-
if (optval < 0)
347-
return optval;
347+
ret = optval;
348+
if (ret < 0)
349+
goto err;
348350
switch (optval) {
349351
case 'u':
350352
data->uid = optint;
@@ -380,18 +382,21 @@ static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options)
380382
data->info_fd = optint;
381383
break;
382384
case 'v':
383-
if (optint < NCP_MOUNT_VERSION_V4) {
384-
return -ECHRNG;
385-
}
386-
if (optint > NCP_MOUNT_VERSION_V5) {
387-
return -ECHRNG;
388-
}
385+
ret = -ECHRNG;
386+
if (optint < NCP_MOUNT_VERSION_V4)
387+
goto err;
388+
if (optint > NCP_MOUNT_VERSION_V5)
389+
goto err;
389390
version = optint;
390391
break;
391392

392393
}
393394
}
394395
return 0;
396+
err:
397+
put_pid(data->wdog_pid);
398+
data->wdog_pid = NULL;
399+
return ret;
395400
}
396401

397402
static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
@@ -409,6 +414,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
409414
#endif
410415
struct ncp_entry_info finfo;
411416

417+
data.wdog_pid = NULL;
412418
server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
413419
if (!server)
414420
return -ENOMEM;
@@ -679,6 +685,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
679685
*/
680686
fput(ncp_filp);
681687
out:
688+
put_pid(data.wdog_pid);
682689
sb->s_fs_info = NULL;
683690
kfree(server);
684691
return error;

0 commit comments

Comments
 (0)