From 007dce7252ef7be51a0227b9eafc1959489581f5 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 15:00:33 +0300 Subject: [PATCH] scst: Group private macro operands and evaluate lock arguments once Parenthesize expression operands in digest rounds, CDB groups and statistics bounds while preserving declaration/name fragments. Group the ARRAY_SIZE operand before indexing its first element. Replace the reservation lock assertion macro with an inline helper so its device argument is evaluated once. Retain the CONFIG_LOCKDEP guard and the no-op behavior without lockdep. Checkpatch reports MACRO_ARG_PRECEDENCE, COMPLEX_MACRO. One example: Macro argument 'dir' may be better as '(dir)' to avoid precedence issues Checkpatch reports ARRAY_SIZE: Prefer ARRAY_SIZE(x) Checkpatch reports MACRO_ARG_REUSE: Macro argument reuse 'dev' - possible side-effects? --- iscsi-scst/usr/md5.c | 9 +++++---- iscsi-scst/usr/sha1.c | 6 +++--- scst/src/scst_lib.c | 2 +- scst/src/scst_pres.c | 12 ++++-------- scst/src/scst_sysfs.c | 4 ++-- usr/stpgd/stpgd_main.c | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/iscsi-scst/usr/md5.c b/iscsi-scst/usr/md5.c index fcd7cdf2d..a99b040eb 100644 --- a/iscsi-scst/usr/md5.c +++ b/iscsi-scst/usr/md5.c @@ -17,14 +17,15 @@ #include "md5.h" /* MD5 Transforms */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) +#define F3(x, y, z) ((x) ^ (y) ^ (z)) +#define F4(x, y, z) ((y) ^ ((x) | ~(z))) /* Macro for applying transforms */ #define MD5STEP(f, w, x, y, z, i, k, s) \ - (w += f(x, y, z) + i + k, w = (w << s | w >> (32 - s)) + x) + ((w) += f(x, y, z) + (i) + (k), \ + (w) = ((w) << (s) | (w) >> (32 - (s))) + (x)) static void __md5_transform(u32 hash[MD5_DIGEST_WORDS], const u32 in[MD5_BLOCK_WORDS]) diff --git a/iscsi-scst/usr/sha1.c b/iscsi-scst/usr/sha1.c index e92dbac83..d7f15e1db 100644 --- a/iscsi-scst/usr/sha1.c +++ b/iscsi-scst/usr/sha1.c @@ -17,9 +17,9 @@ #include "sha1.h" /* SHA1 transforms */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) /* x ? y : z */ -#define F2(x, y, z) (x ^ y ^ z) /* XOR */ -#define F3(x, y, z) ((x & y) + (z & (x ^ y))) /* majority */ +#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) /* x ? y : z */ +#define F2(x, y, z) ((x) ^ (y) ^ (z)) /* XOR */ +#define F3(x, y, z) (((x) & (y)) + ((z) & ((x) ^ (y)))) /* majority */ /* SHA1 per-round constants */ #define K1 0x5A827999UL /* Rounds 0-19: sqrt(2) * 2^30 */ diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index ebd714ef1..e3069fe52 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -11316,7 +11316,7 @@ out: */ static const int scst_cdb_length[8] = { 6, 10, 10, 32, 16, 12, 0, 0 }; -#define SCST_CDB_GROUP(opcode) ((opcode >> 5) & 0x7) +#define SCST_CDB_GROUP(opcode) (((opcode) >> 5) & 0x7) #define SCST_GET_CDB_LEN(opcode) scst_cdb_length[SCST_CDB_GROUP(opcode)] static int get_cdb_info_len_10(struct scst_cmd *cmd, diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index a407c0f80..25e53cafa 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -68,17 +68,13 @@ #define FILE_BUFFER_SIZE 512 -#if defined(CONFIG_LOCKDEP) -#define scst_assert_pr_mutex_held(dev) \ -do { \ - if ((dev)->dev_list_entry.next && !list_empty(&(dev)->dev_list_entry)) \ - lockdep_assert_held(&(dev)->dev_pr_mutex); \ -} while (0) -#else static inline void scst_assert_pr_mutex_held(struct scst_device *dev) { -} +#if defined(CONFIG_LOCKDEP) + if (dev->dev_list_entry.next && !list_empty(&dev->dev_list_entry)) + lockdep_assert_held(&dev->dev_pr_mutex); #endif +} uint32_t scst_tid_size(const uint8_t *tid) { diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index e13034e56..20b048187 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -4835,7 +4835,7 @@ static ssize_t scst_sess_sysfs_##exported_name##_show(struct kobject *kobj, \ BUILD_BUG_ON(SCST_DATA_BIDI != 3); \ BUILD_BUG_ON(SCST_DATA_NONE != 4); \ \ - BUILD_BUG_ON(dir >= SCST_DATA_DIR_MAX); \ + BUILD_BUG_ON((dir) >= SCST_DATA_DIR_MAX); \ \ sess = container_of(kobj, struct scst_session, sess_kobj); \ v = sess->io_stats[dir].name; \ @@ -4851,7 +4851,7 @@ static ssize_t scst_sess_sysfs_##exported_name##_store(struct kobject *kobj, \ struct scst_session *sess; \ sess = container_of(kobj, struct scst_session, sess_kobj); \ spin_lock_irq(&sess->sess_list_lock); \ - BUILD_BUG_ON(dir >= SCST_DATA_DIR_MAX); \ + BUILD_BUG_ON((dir) >= SCST_DATA_DIR_MAX); \ sess->io_stats[dir].cmd_count = 0; \ sess->io_stats[dir].io_byte_count = 0; \ sess->io_stats[dir].unaligned_cmd_count = 0; \ diff --git a/usr/stpgd/stpgd_main.c b/usr/stpgd/stpgd_main.c index addd5e5cd..cf2b8d6af 100644 --- a/usr/stpgd/stpgd_main.c +++ b/usr/stpgd/stpgd_main.c @@ -51,7 +51,7 @@ char *app_name; unsigned long trace_flag = DEFAULT_LOG_FLAGS; #endif /* defined(DEBUG) || defined(TRACING) */ -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) bool log_daemon = true; int transition_timeout = DEFAULT_TRANSITION_TIME;