selftests: ublk: fix ublk_find_tgt()

Bounds check for iterator variable `i` is missed, so add it and fix
ublk_find_tgt().

Cc: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250412023035.2649275-2-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Ming Lei 2025-04-12 10:30:17 +08:00 committed by Jens Axboe
parent 39e1605051
commit ec12009318
2 changed files with 3 additions and 2 deletions

View File

@ -14,13 +14,12 @@ static const struct ublk_tgt_ops *tgt_ops_list[] = {
static const struct ublk_tgt_ops *ublk_find_tgt(const char *name)
{
const struct ublk_tgt_ops *ops;
int i;
if (name == NULL)
return NULL;
for (i = 0; sizeof(tgt_ops_list) / sizeof(ops); i++)
for (i = 0; i < ARRAY_SIZE(tgt_ops_list); i++)
if (strcmp(tgt_ops_list[i]->name, name) == 0)
return tgt_ops_list[i];
return NULL;

View File

@ -30,6 +30,8 @@
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
/****************** part 1: libublk ********************/
#define CTRL_DEV "/dev/ublk-control"