* [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code
@ 2025-08-17 9:36 Akhilesh Patil
2025-08-18 2:13 ` Ming Lei
2025-08-18 17:18 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Akhilesh Patil @ 2025-08-17 9:36 UTC (permalink / raw)
To: ming.lei, shuah, axboe
Cc: linux-block, linux-kselftest, linux-kernel, akhileshpatilvnit
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 ec120093180b9 ("selftests: ublk: fix ublk_find_tgt()")
wherever appropriate to maintain consistency.
Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
Testing:
* build checked for testing/selftests/ublk
* tested by running
$ ./kublk --help
Which exercises the impacted code path.
tools/testing/selftests/ublk/kublk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index 95188065b2e9..6512dfbdbce3 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -1400,7 +1400,7 @@ static int cmd_dev_get_features(void)
if (!((1ULL << i) & features))
continue;
- if (i < sizeof(feat_map) / sizeof(feat_map[0]))
+ if (i < ARRAY_SIZE(feat_map))
feat = feat_map[i];
else
feat = "unknown";
@@ -1477,7 +1477,7 @@ static void __cmd_create_help(char *exe, bool recovery)
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
printf("\tdefault: nthreads=nr_queues");
- for (i = 0; i < sizeof(tgt_ops_list) / sizeof(tgt_ops_list[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(tgt_ops_list); i++) {
const struct ublk_tgt_ops *ops = tgt_ops_list[i];
if (ops->usage)
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code
2025-08-17 9:36 [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code Akhilesh Patil
@ 2025-08-18 2:13 ` Ming Lei
2025-08-18 17:18 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2025-08-18 2:13 UTC (permalink / raw)
To: Akhilesh Patil
Cc: shuah, axboe, linux-block, linux-kselftest, linux-kernel,
akhileshpatilvnit
On Sun, Aug 17, 2025 at 03:06:05PM +0530, Akhilesh Patil wrote:
> 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 ec120093180b9 ("selftests: ublk: fix ublk_find_tgt()")
> wherever appropriate to maintain consistency.
>
> Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
> ---
> Testing:
> * build checked for testing/selftests/ublk
> * tested by running
> $ ./kublk --help
> Which exercises the impacted code path.
Nice!
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code
2025-08-17 9:36 [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code Akhilesh Patil
2025-08-18 2:13 ` Ming Lei
@ 2025-08-18 17:18 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-08-18 17:18 UTC (permalink / raw)
To: ming.lei, shuah, Akhilesh Patil
Cc: linux-block, linux-kselftest, linux-kernel, akhileshpatilvnit
On Sun, 17 Aug 2025 15:06:05 +0530, Akhilesh Patil wrote:
> 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 ec120093180b9 ("selftests: ublk: fix ublk_find_tgt()")
> wherever appropriate to maintain consistency.
>
> [...]
Applied, thanks!
[1/1] selftests: ublk: Use ARRAY_SIZE() macro to improve code
commit: 0227af355b50c526bf83ca52d67aef5d102e9b07
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-18 17:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-17 9:36 [PATCH] selftests: ublk: Use ARRAY_SIZE() macro to improve code Akhilesh Patil
2025-08-18 2:13 ` Ming Lei
2025-08-18 17:18 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).