Skip to content

Commit 9eb62f0

Browse files
GustavoARSilvaDaniel Thompson
authored andcommitted
kdb: kdb_main: refactor code in kdb_md_line
Replace the whole switch statement with a for loop. This makes the code clearer and easy to read. This also addresses the following Coverity warnings: Addresses-Coverity-ID: 115090 ("Missing break in switch") Addresses-Coverity-ID: 115091 ("Missing break in switch") Addresses-Coverity-ID: 114700 ("Missing break in switch") Suggested-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> [daniel.thompson@linaro.org: Tiny grammar change in description] Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
1 parent c2b94c7 commit 9eb62f0

1 file changed

Lines changed: 3 additions & 18 deletions

File tree

‎kernel/debug/kdb/kdb_main.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
14931493
char cbuf[32];
14941494
char *c = cbuf;
14951495
int i;
1496+
int j;
14961497
unsigned long word;
14971498

14981499
memset(cbuf, '\0', sizeof(cbuf));
@@ -1538,25 +1539,9 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
15381539
wc.word = word;
15391540
#define printable_char(c) \
15401541
({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
1541-
switch (bytesperword) {
1542-
case 8:
1542+
for (j = 0; j < bytesperword; j++)
15431543
*c++ = printable_char(*cp++);
1544-
*c++ = printable_char(*cp++);
1545-
*c++ = printable_char(*cp++);
1546-
*c++ = printable_char(*cp++);
1547-
addr += 4;
1548-
case 4:
1549-
*c++ = printable_char(*cp++);
1550-
*c++ = printable_char(*cp++);
1551-
addr += 2;
1552-
case 2:
1553-
*c++ = printable_char(*cp++);
1554-
addr++;
1555-
case 1:
1556-
*c++ = printable_char(*cp++);
1557-
addr++;
1558-
break;
1559-
}
1544+
addr += bytesperword;
15601545
#undef printable_char
15611546
}
15621547
}

0 commit comments

Comments
 (0)