]> www.infradead.org Git - nvme.git/commitdiff
selftests: ublk: fix ublk_find_tgt()
authorMing Lei <ming.lei@redhat.com>
Sat, 12 Apr 2025 02:30:17 +0000 (10:30 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 17 Apr 2025 01:32:18 +0000 (19:32 -0600)
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>
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/kublk.h

index 91c282bc767449a418cce7fc816dc8e9fc732d6a..74cf70b2f28e516fff0e039ffb0d932271bce6e6 100644 (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;
index 760ff8ffb8107037a19a8fb7ab408818845e010d..73294f6e3e49f15fe641b64d0f48341d732a5b61 100644 (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"