Skip to content

Commit 0227af3

Browse files
Akhilesh Patilaxboe
authored andcommitted
selftests: ublk: Use ARRAY_SIZE() macro to improve code
Use ARRAY_SIZE() macro while calculating size of an array to improve code readability and reduce potential sizing errors. Implement this suggestion given by spatch tool by running coccinelle script - scripts/coccinelle/misc/array_size.cocci Follow ARRAY_SIZE() macro usage pattern in ublk.c introduced by, commit ec12009 ("selftests: ublk: fix ublk_find_tgt()") wherever appropriate to maintain consistency. Signed-off-by: Akhilesh Patil <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/aKGihYui6/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 8f5845e commit 0227af3

File tree

1 file changed

+2
-2
lines changed
  • tools/testing/selftests/ublk

1 file changed

+2
-2
lines changed

tools/testing/selftests/ublk/kublk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ static int cmd_dev_get_features(void)
14001400

14011401
if (!((1ULL << i) & features))
14021402
continue;
1403-
if (i < sizeof(feat_map) / sizeof(feat_map[0]))
1403+
if (i < ARRAY_SIZE(feat_map))
14041404
feat = feat_map[i];
14051405
else
14061406
feat = "unknown";
@@ -1477,7 +1477,7 @@ static void __cmd_create_help(char *exe, bool recovery)
14771477
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
14781478
printf("\tdefault: nthreads=nr_queues");
14791479

1480-
for (i = 0; i < sizeof(tgt_ops_list) / sizeof(tgt_ops_list[0]); i++) {
1480+
for (i = 0; i < ARRAY_SIZE(tgt_ops_list); i++) {
14811481
const struct ublk_tgt_ops *ops = tgt_ops_list[i];
14821482

14831483
if (ops->usage)

0 commit comments

Comments
 (0)