Commit 564b5c54 authored by Mike Snitzer's avatar Mike Snitzer

dm table: audit all dm_table_get_target() callers

All callers of dm_table_get_target() are expected to do proper bounds
checking on the index they pass.

Move dm_table_get_target() to dm-core.h to make it extra clear that only
DM core code should be using it. Switch it to be inlined while at it.

Standardize all DM core callers to use the same for loop pattern and
make associated variables as local as possible. Rename some variables
(e.g. s/table/t/ and s/tgt/ti/) along the way.
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent 2aec377a
...@@ -226,6 +226,13 @@ struct dm_table { ...@@ -226,6 +226,13 @@ struct dm_table {
#endif #endif
}; };
static inline struct dm_target *dm_table_get_target(struct dm_table *t,
unsigned int index)
{
BUG_ON(index >= t->num_targets);
return t->targets + index;
}
/* /*
* One of these is allocated per clone bio. * One of these is allocated per clone bio.
*/ */
......
...@@ -237,9 +237,6 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl ...@@ -237,9 +237,6 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
for (i = 0; i < num_targets; i++) { for (i = 0; i < num_targets; i++) {
struct dm_target *ti = dm_table_get_target(table, i); struct dm_target *ti = dm_table_get_target(table, i);
if (!ti)
goto error;
last_target_measured = 0; last_target_measured = 0;
/* /*
......
This diff is collapsed.
...@@ -275,11 +275,8 @@ static int device_not_zone_append_capable(struct dm_target *ti, ...@@ -275,11 +275,8 @@ static int device_not_zone_append_capable(struct dm_target *ti,
static bool dm_table_supports_zone_append(struct dm_table *t) static bool dm_table_supports_zone_append(struct dm_table *t)
{ {
struct dm_target *ti; for (unsigned int i = 0; i < t->num_targets; i++) {
unsigned int i; struct dm_target *ti = dm_table_get_target(t, i);
for (i = 0; i < t->num_targets; i++) {
ti = dm_table_get_target(t, i);
if (ti->emulate_zone_append) if (ti->emulate_zone_append)
return false; return false;
......
...@@ -411,7 +411,7 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) ...@@ -411,7 +411,7 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx, static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx,
struct block_device **bdev) struct block_device **bdev)
{ {
struct dm_target *tgt; struct dm_target *ti;
struct dm_table *map; struct dm_table *map;
int r; int r;
...@@ -425,14 +425,14 @@ static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx, ...@@ -425,14 +425,14 @@ static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx,
if (map->num_targets != 1) if (map->num_targets != 1)
return r; return r;
tgt = dm_table_get_target(map, 0); ti = dm_table_get_target(map, 0);
if (!tgt->type->prepare_ioctl) if (!ti->type->prepare_ioctl)
return r; return r;
if (dm_suspended_md(md)) if (dm_suspended_md(md))
return -EAGAIN; return -EAGAIN;
r = tgt->type->prepare_ioctl(tgt, bdev); r = ti->type->prepare_ioctl(ti, bdev);
if (r == -ENOTCONN && !fatal_signal_pending(current)) { if (r == -ENOTCONN && !fatal_signal_pending(current)) {
dm_put_live_table(md, *srcu_idx); dm_put_live_table(md, *srcu_idx);
msleep(10); msleep(10);
...@@ -1506,11 +1506,11 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci, ...@@ -1506,11 +1506,11 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
} }
static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti, static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
unsigned num_bios, unsigned *len) unsigned int num_bios, unsigned *len)
{ {
struct bio_list blist = BIO_EMPTY_LIST; struct bio_list blist = BIO_EMPTY_LIST;
struct bio *clone; struct bio *clone;
int ret = 0; unsigned int ret = 0;
switch (num_bios) { switch (num_bios) {
case 0: case 0:
...@@ -1538,8 +1538,7 @@ static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti, ...@@ -1538,8 +1538,7 @@ static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
static void __send_empty_flush(struct clone_info *ci) static void __send_empty_flush(struct clone_info *ci)
{ {
unsigned target_nr = 0; struct dm_table *t = ci->map;
struct dm_target *ti;
struct bio flush_bio; struct bio flush_bio;
/* /*
...@@ -1554,8 +1553,9 @@ static void __send_empty_flush(struct clone_info *ci) ...@@ -1554,8 +1553,9 @@ static void __send_empty_flush(struct clone_info *ci)
ci->sector_count = 0; ci->sector_count = 0;
ci->io->tio.clone.bi_iter.bi_size = 0; ci->io->tio.clone.bi_iter.bi_size = 0;
while ((ti = dm_table_get_target(ci->map, target_nr++))) { for (unsigned int i = 0; i < t->num_targets; i++) {
int bios; unsigned int bios;
struct dm_target *ti = dm_table_get_target(t, i);
atomic_add(ti->num_flush_bios, &ci->io->io_count); atomic_add(ti->num_flush_bios, &ci->io->io_count);
bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL); bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
...@@ -1575,7 +1575,7 @@ static void __send_changing_extent_only(struct clone_info *ci, struct dm_target ...@@ -1575,7 +1575,7 @@ static void __send_changing_extent_only(struct clone_info *ci, struct dm_target
unsigned num_bios) unsigned num_bios)
{ {
unsigned len; unsigned len;
int bios; unsigned int bios;
len = min_t(sector_t, ci->sector_count, len = min_t(sector_t, ci->sector_count,
max_io_len_target_boundary(ti, dm_target_offset(ti, ci->sector))); max_io_len_target_boundary(ti, dm_target_offset(ti, ci->sector)));
......
...@@ -53,7 +53,6 @@ struct dm_io; ...@@ -53,7 +53,6 @@ struct dm_io;
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
void dm_table_event_callback(struct dm_table *t, void dm_table_event_callback(struct dm_table *t,
void (*fn)(void *), void *context); void (*fn)(void *), void *context);
struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector); struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
bool dm_table_has_no_data_devices(struct dm_table *table); bool dm_table_has_no_data_devices(struct dm_table *table);
int dm_calculate_queue_limits(struct dm_table *table, int dm_calculate_queue_limits(struct dm_table *table,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment