Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 956a4025 authored by Mike Snitzer's avatar Mike Snitzer
Browse files

dm: fix sparse "unexpected unlock" warnings in ioctl code



Rename dm_get_live_table_for_ioctl to dm_grab_bdev_for_ioctl and have it
do the dm_{get,put}_live_table() rather than split those operations.

The dm_grab_bdev_for_ioctl() callers only care about the block_device
associated with a singleton DM device so there isn't any need to retain
a reference to the live DM table.  It is sufficient to:
1) dm_get_live_table()
2) bdgrab() the bdev associated with the singleton table's target
3) dm_put_live_table()
4) bdput() the bdev

Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 66482026
Loading
Loading
Loading
Loading
+29 −27
Original line number Diff line number Diff line
@@ -556,17 +556,17 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
	return dm_get_geometry(md, geo);
}

static int dm_get_live_table_for_ioctl(struct mapped_device *md,
static int dm_grab_bdev_for_ioctl(struct mapped_device *md,
				  struct block_device **bdev,
				       fmode_t *mode, int *srcu_idx)
				  fmode_t *mode)
{
	struct dm_target *tgt;
	struct dm_table *map;
	int r;
	int srcu_idx, r;

retry:
	r = -ENOTTY;
	map = dm_get_live_table(md, srcu_idx);
	map = dm_get_live_table(md, &srcu_idx);
	if (!map || !dm_table_get_size(map))
		goto out;

@@ -587,10 +587,12 @@ static int dm_get_live_table_for_ioctl(struct mapped_device *md,
	if (r < 0)
		goto out;

	bdgrab(*bdev);
	dm_put_live_table(md, srcu_idx);
	return r;

out:
	dm_put_live_table(md, *srcu_idx);
	dm_put_live_table(md, srcu_idx);
	if (r == -ENOTCONN && !fatal_signal_pending(current)) {
		msleep(10);
		goto retry;
@@ -602,9 +604,9 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
			unsigned int cmd, unsigned long arg)
{
	struct mapped_device *md = bdev->bd_disk->private_data;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -621,7 +623,7 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,

	r =  __blkdev_driver_ioctl(bdev, mode, cmd, arg);
out:
	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}

@@ -3557,9 +3559,9 @@ static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
	struct mapped_device *md = bdev->bd_disk->private_data;
	const struct pr_ops *ops;
	fmode_t mode;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -3569,7 +3571,7 @@ static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
	else
		r = -EOPNOTSUPP;

	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}

@@ -3579,9 +3581,9 @@ static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
	struct mapped_device *md = bdev->bd_disk->private_data;
	const struct pr_ops *ops;
	fmode_t mode;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -3591,7 +3593,7 @@ static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
	else
		r = -EOPNOTSUPP;

	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}

@@ -3600,9 +3602,9 @@ static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
	struct mapped_device *md = bdev->bd_disk->private_data;
	const struct pr_ops *ops;
	fmode_t mode;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -3612,7 +3614,7 @@ static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
	else
		r = -EOPNOTSUPP;

	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}

@@ -3622,9 +3624,9 @@ static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
	struct mapped_device *md = bdev->bd_disk->private_data;
	const struct pr_ops *ops;
	fmode_t mode;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -3634,7 +3636,7 @@ static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
	else
		r = -EOPNOTSUPP;

	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}

@@ -3643,9 +3645,9 @@ static int dm_pr_clear(struct block_device *bdev, u64 key)
	struct mapped_device *md = bdev->bd_disk->private_data;
	const struct pr_ops *ops;
	fmode_t mode;
	int srcu_idx, r;
	int r;

	r = dm_get_live_table_for_ioctl(md, &bdev, &mode, &srcu_idx);
	r = dm_grab_bdev_for_ioctl(md, &bdev, &mode);
	if (r < 0)
		return r;

@@ -3655,7 +3657,7 @@ static int dm_pr_clear(struct block_device *bdev, u64 key)
	else
		r = -EOPNOTSUPP;

	dm_put_live_table(md, srcu_idx);
	bdput(bdev);
	return r;
}