From 2c48b9c45579a9b5e3e74694eebf3d2451f3dbd3 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 9 Aug 2009 00:52:35 +0400 Subject: switch alloc_file() to passing struct path ... and have the caller grab both mnt and dentry; kill leak in infiniband, while we are at it. Signed-off-by: Al Viro --- drivers/infiniband/core/uverbs_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index aec0fbdfe7f0..5f284ffd430e 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -492,6 +492,7 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, int is_async, int *fd) { struct ib_uverbs_event_file *ev_file; + struct path path; struct file *filp; int ret; @@ -519,8 +520,10 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, * system call on a uverbs file, which will already have a * module reference. */ - filp = alloc_file(uverbs_event_mnt, dget(uverbs_event_mnt->mnt_root), - FMODE_READ, fops_get(&uverbs_event_fops)); + path.mnt = uverbs_event_mnt; + path.dentry = uverbs_event_mnt->mnt_root; + path_get(&path); + filp = alloc_file(&path, FMODE_READ, fops_get(&uverbs_event_fops)); if (!filp) { ret = -ENFILE; goto err_fd; @@ -531,6 +534,8 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, return filp; err_fd: + fops_put(&uverbs_event_fops); + path_put(&path); put_unused_fd(*fd); err: -- cgit v1.2.3 From 306bb73d12f13684ffcd735838c3e6f7515ab626 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 9 Aug 2009 01:58:52 +0400 Subject: fix the crap in dst/dcore * don't reinvent the wheels, please - open_bdev_exclusive() is there for purpose * both open_by_devnum() and open_bdev_exclusive() return ERR_PTR(...) upon error, not NULL Signed-off-by: Al Viro --- drivers/staging/dst/dcore.c | 46 +++++---------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) (limited to 'drivers') diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c index fd5bd0ea1e0d..c83ca7e3d048 100644 --- a/drivers/staging/dst/dcore.c +++ b/drivers/staging/dst/dcore.c @@ -403,7 +403,7 @@ static void dst_node_cleanup(struct dst_node *n) if (n->bdev) { sync_blockdev(n->bdev); - blkdev_put(n->bdev, FMODE_READ|FMODE_WRITE); + close_bdev_exclusive(n->bdev, FMODE_READ|FMODE_WRITE); } dst_state_lock(st); @@ -463,37 +463,6 @@ void dst_node_put(struct dst_node *n) } } -/* - * This function finds devices major/minor numbers for given pathname. - */ -static int dst_lookup_device(const char *path, dev_t *dev) -{ - int err; - struct nameidata nd; - struct inode *inode; - - err = path_lookup(path, LOOKUP_FOLLOW, &nd); - if (err) - return err; - - inode = nd.path.dentry->d_inode; - if (!inode) { - err = -ENOENT; - goto out; - } - - if (!S_ISBLK(inode->i_mode)) { - err = -ENOTBLK; - goto out; - } - - *dev = inode->i_rdev; - -out: - path_put(&nd.path); - return err; -} - /* * Setting up export device: lookup by the name, get its size * and setup listening socket, which will accept clients, which @@ -503,17 +472,12 @@ static int dst_setup_export(struct dst_node *n, struct dst_ctl *ctl, struct dst_export_ctl *le) { int err; - dev_t dev = 0; /* gcc likes to scream here */ snprintf(n->info->local, sizeof(n->info->local), "%s", le->device); - err = dst_lookup_device(le->device, &dev); - if (err) - return err; - - n->bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); - if (!n->bdev) - return -ENODEV; + n->bdev = open_bdev_exclusive(le->device, FMODE_READ|FMODE_WRITE, NULL); + if (IS_ERR(n->bdev)) + return PTR_ERR(n->bdev); if (n->size != 0) n->size = min_t(loff_t, n->bdev->bd_inode->i_size, n->size); @@ -528,7 +492,7 @@ static int dst_setup_export(struct dst_node *n, struct dst_ctl *ctl, return 0; err_out_cleanup: - blkdev_put(n->bdev, FMODE_READ|FMODE_WRITE); + close_bdev_exclusive(n->bdev, FMODE_READ|FMODE_WRITE); n->bdev = NULL; return err; -- cgit v1.2.3