scst_debug: Preserve diagnostic severity and complete PDU rows

Checkpatch reports:
  MACRO_ARG_UNUSED: Argument 'log_flag' is not used in function-like macro
  LOGGING_CONTINUATION: Avoid logging continuation uses where feasible

Pass PRINT_LOG_FLAG's severity to debug_print_with_prefix() instead of
forcing KERN_INFO. Correct the adjacent PRINT/PRINTN comment about which
component supplies the level.

Replace six iSCSI pr_cont() sites with complete 16-byte hex/ASCII
records assembled in a bounded local buffer. Preserve byte
classification, four-byte separators and padding for short rows.
Unrelated output can still appear between rows but cannot split their
individual byte writes.

Emit explicit KERN_DEBUG headings and rows under TRACE_D_DUMP_PDU. An
enabled dump must not depend on the heading's pr_debug() callsite
setting. Use %zu for the BHS sizeof. No filtering or analyzer exception
is changed.
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:25 +03:00
parent bd20369798
commit 4d4d03171c
2 changed files with 33 additions and 47 deletions
+31 -42
View File
@@ -980,60 +980,49 @@ const struct file_operations ctr_fops = {
};
#ifdef CONFIG_SCST_DEBUG
static void iscsi_dump_char(int ch, unsigned char *text, int *pos)
static void iscsi_dump_buffer(const u8 *buf, int size)
{
int i = *pos;
while (size > 0) {
unsigned char text[16];
/* 16 hex bytes, three separators, text and terminators use 77 bytes. */
char line[80];
int count = min(size, 16);
int pos = 0;
int i;
if (ch < 0) {
while ((i % 16) != 0) {
pr_cont(" ");
text[i] = ' ';
i++;
if ((i % 16) == 0)
pr_cont(" | %.16s |\n", text);
else if ((i % 4) == 0)
pr_cont(" |");
for (i = 0; i < 16; i++) {
if (i < count) {
unsigned char ch = buf[i];
pos += scnprintf(line + pos, sizeof(line) - pos, " %02x", ch);
text[i] = (ch < 0x20 || (ch >= 0x80 && ch <= 0xa0)) ? ' ' : ch;
} else {
pos += scnprintf(line + pos, sizeof(line) - pos, " ");
text[i] = ' ';
}
if (i != 15 && (i + 1) % 4 == 0)
pos += scnprintf(line + pos, sizeof(line) - pos, " |");
}
i = 0;
goto out;
scnprintf(line + pos, sizeof(line) - pos, " | %.16s |", text);
PRINT(KERN_DEBUG, "%s", line);
buf += count;
size -= count;
}
text[i] = (ch < 0x20 || (ch >= 0x80 && ch <= 0xa0)) ? ' ' : ch;
pr_cont(" %02x", ch);
i++;
if ((i % 16) == 0) {
pr_cont(" | %.16s |\n", text);
i = 0;
} else if ((i % 4) == 0) {
pr_cont(" |");
}
out:
*pos = i;
}
void iscsi_dump_pdu(struct iscsi_pdu *pdu)
{
unsigned char text[16];
int pos = 0;
if (trace_flag & TRACE_D_DUMP_PDU) {
unsigned char *buf;
int i;
const u8 *buf = (const void *)&pdu->bhs;
buf = (void *)&pdu->bhs;
pr_debug("BHS: (%p,%zd)\n", buf, sizeof(pdu->bhs));
for (i = 0; i < (int)sizeof(pdu->bhs); i++)
iscsi_dump_char(*buf++, text, &pos);
iscsi_dump_char(-1, text, &pos);
PRINT(KERN_DEBUG, "BHS: (%p,%zu)", buf, sizeof(pdu->bhs));
iscsi_dump_buffer(buf, sizeof(pdu->bhs));
buf = (void *)pdu->ahs;
pr_debug("AHS: (%p,%d)\n", buf, pdu->ahssize);
for (i = 0; i < pdu->ahssize; i++)
iscsi_dump_char(*buf++, text, &pos);
iscsi_dump_char(-1, text, &pos);
buf = (const void *)pdu->ahs;
PRINT(KERN_DEBUG, "AHS: (%p,%d)", buf, pdu->ahssize);
iscsi_dump_buffer(buf, pdu->ahssize);
pr_debug("Data: (%d)\n", pdu->datasize);
PRINT(KERN_DEBUG, "Data: (%d)", pdu->datasize);
}
}
+2 -5
View File
@@ -108,10 +108,7 @@
#define TRACE_MINOR_AND_MGMT_DBG (TRACE_MINOR | TRACE_MGMT_DEBUG)
/*
* Note: in the next two printk() statements the KERN_CONT macro is only
* present to suppress a checkpatch warning (KERN_CONT is defined as "").
*/
/* The caller supplies the KERN_* level as log_flag. */
#define PRINT(log_flag, format, args...) \
printk(log_flag format "\n", ## args)
#define PRINTN(log_flag, format, args...) \
@@ -177,7 +174,7 @@ do { \
} while (0)
#define PRINT_LOG_FLAG(log_flag, format, args...) \
debug_print_with_prefix(trace_flag, KERN_INFO, __LOG_PREFIX, \
debug_print_with_prefix(trace_flag, log_flag, __LOG_PREFIX, \
__func__, __LINE__, format, ## args)
#define PRINT_WARNING(format, args...) \