提交 4e91672c 编写于 作者: J Johannes Weiner 提交者: Linus Torvalds

Replace obscure constructs in fs/block_dev.c

Replace some funky codepaths in fs/block_dev.c with cleaner versions of the
affected places.

[akpm@linux-foundation.org: fix return value]
Signed-off-by: NJohannes Weiner <hannes-kernel@saeurebad.de>
Cc: Bjorn Steinbrink <B.Steinbrink@gmx.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 948730b0
...@@ -872,7 +872,7 @@ static struct bd_holder *find_bd_holder(struct block_device *bdev, ...@@ -872,7 +872,7 @@ static struct bd_holder *find_bd_holder(struct block_device *bdev,
*/ */
static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo) static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
{ {
int ret; int err;
if (!bo) if (!bo)
return -EINVAL; return -EINVAL;
...@@ -880,15 +880,18 @@ static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo) ...@@ -880,15 +880,18 @@ static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
if (!bd_holder_grab_dirs(bdev, bo)) if (!bd_holder_grab_dirs(bdev, bo))
return -EBUSY; return -EBUSY;
ret = add_symlink(bo->sdir, bo->sdev); err = add_symlink(bo->sdir, bo->sdev);
if (ret == 0) { if (err)
ret = add_symlink(bo->hdir, bo->hdev); return err;
if (ret)
err = add_symlink(bo->hdir, bo->hdev);
if (err) {
del_symlink(bo->sdir, bo->sdev); del_symlink(bo->sdir, bo->sdev);
return err;
} }
if (ret == 0)
list_add_tail(&bo->list, &bdev->bd_holder_list); list_add_tail(&bo->list, &bdev->bd_holder_list);
return ret; return 0;
} }
/** /**
...@@ -946,7 +949,7 @@ static struct bd_holder *del_bd_holder(struct block_device *bdev, ...@@ -946,7 +949,7 @@ static struct bd_holder *del_bd_holder(struct block_device *bdev,
static int bd_claim_by_kobject(struct block_device *bdev, void *holder, static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
struct kobject *kobj) struct kobject *kobj)
{ {
int res; int err;
struct bd_holder *bo, *found; struct bd_holder *bo, *found;
if (!kobj) if (!kobj)
...@@ -957,21 +960,24 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder, ...@@ -957,21 +960,24 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
return -ENOMEM; return -ENOMEM;
mutex_lock(&bdev->bd_mutex); mutex_lock(&bdev->bd_mutex);
res = bd_claim(bdev, holder);
if (res == 0) { err = bd_claim(bdev, holder);
if (err)
goto out;
found = find_bd_holder(bdev, bo); found = find_bd_holder(bdev, bo);
if (found == NULL) { if (found)
res = add_bd_holder(bdev, bo); goto out;
if (res)
err = add_bd_holder(bdev, bo);
if (err)
bd_release(bdev); bd_release(bdev);
}
}
if (res || found) out:
if (err || found)
free_bd_holder(bo); free_bd_holder(bo);
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
return err;
return res;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册