iscsi-scstd: Share ARRAY_SIZE for userspace dispatch bounds

Coccinelle misc/array_size.cocci reports:

  iscsi-scst/usr/iscsi_adm.c:595:33-34: WARNING: Use ARRAY_SIZE

Move the existing iSNS ARRAY_SIZE helper to misc.h and use it for the
user-command dispatch table in iscsi-scst-adm. Both users already include
that header, so they can share the definition.

Preserve the size_t comparison, including rejection of negative operation
values, and the unsupported-operation path. The table index is used
only after the bounds check succeeds.
This commit is contained in:
Gleb Chesnokov
2026-10-20 18:02:29 +03:00
parent 3ce72d466d
commit 1cd19b309e
3 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -592,8 +592,8 @@ static int user_handle(int op, u32 set, u32 tid, char *params)
if (err)
goto out;
if ((op >= sizeof(user_handle_fn)/sizeof(user_handle_fn[0])) ||
((fn = user_handle_fn[op]) == NULL)) {
fn = op < ARRAY_SIZE(user_handle_fn) ? user_handle_fn[op] : NULL;
if (!fn) {
fprintf(stderr, "Unsupported\n");
goto out;
}
-1
View File
@@ -34,7 +34,6 @@
#include "isns_proto.h"
#include "misc.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BUFSIZE (1 << 18)
struct isns_io {
+2
View File
@@ -16,6 +16,8 @@
#ifndef MISC_H
#define MISC_H
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
struct __qelem {
struct __qelem *q_forw;
struct __qelem *q_back;