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?
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:25 +03:00
parent e4b0591754
commit 007dce7252
6 changed files with 16 additions and 19 deletions
+5 -4
View File
@@ -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])
+3 -3
View File
@@ -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 */
+1 -1
View File
@@ -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,
+4 -8
View File
@@ -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)
{
+2 -2
View File
@@ -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; \
+1 -1
View File
@@ -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;