Skip to content

Commit ec12009

Browse files
Ming Leiaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 39e1605 commit ec12009

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tools/testing/selftests/ublk/kublk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ static const struct ublk_tgt_ops *tgt_ops_list[] = {
1414

1515
static const struct ublk_tgt_ops *ublk_find_tgt(const char *name)
1616
{
17-
const struct ublk_tgt_ops *ops;
1817
int i;
1918

2019
if (name == NULL)
2120
return NULL;
2221

23-
for (i = 0; sizeof(tgt_ops_list) / sizeof(ops); i++)
22+
for (i = 0; i < ARRAY_SIZE(tgt_ops_list); i++)
2423
if (strcmp(tgt_ops_list[i]->name, name) == 0)
2524
return tgt_ops_list[i];
2625
return NULL;

tools/testing/selftests/ublk/kublk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define min(a, b) ((a) < (b) ? (a) : (b))
3131
#endif
3232

33+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
34+
3335
/****************** part 1: libublk ********************/
3436

3537
#define CTRL_DEV "/dev/ublk-control"

0 commit comments

Comments
 (0)