2018-08-15 15:13:14

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH] kdb: kdb_main: refactor code in kdb_md_line

Replace the whole switch statement with a for loop.
This makes the code much clear 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 <[email protected]>
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
kernel/debug/kdb/kdb_main.c | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 2ddfce8..4b896a6 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -1538,25 +1538,9 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
wc.word = word;
#define printable_char(c) \
({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
- switch (bytesperword) {
- case 8:
+ for (i = 0; i < bytesperword; i++)
*c++ = printable_char(*cp++);
- *c++ = printable_char(*cp++);
- *c++ = printable_char(*cp++);
- *c++ = printable_char(*cp++);
- addr += 4;
- case 4:
- *c++ = printable_char(*cp++);
- *c++ = printable_char(*cp++);
- addr += 2;
- case 2:
- *c++ = printable_char(*cp++);
- addr++;
- case 1:
- *c++ = printable_char(*cp++);
- addr++;
- break;
- }
+ addr += bytesperword;
#undef printable_char
}
}
--
2.7.4



2018-08-16 18:11:09

by Daniel Thompson

[permalink] [raw]
Subject: Re: [PATCH] kdb: kdb_main: refactor code in kdb_md_line

On Wed, Aug 15, 2018 at 10:06:16AM -0500, Gustavo A. R. Silva wrote:
> Replace the whole switch statement with a for loop.
> This makes the code much clear 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 <[email protected]>
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> kernel/debug/kdb/kdb_main.c | 20 ++------------------
> 1 file changed, 2 insertions(+), 18 deletions(-)
>
> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> index 2ddfce8..4b896a6 100644
> --- a/kernel/debug/kdb/kdb_main.c
> +++ b/kernel/debug/kdb/kdb_main.c
> @@ -1538,25 +1538,9 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
> wc.word = word;
> #define printable_char(c) \
> ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
> - switch (bytesperword) {
> - case 8:
> + for (i = 0; i < bytesperword; i++)

i already a control variable for the outer loop. It is not safe to reuse
it here.


Daniel.

> *c++ = printable_char(*cp++);
> - *c++ = printable_char(*cp++);
> - *c++ = printable_char(*cp++);
> - *c++ = printable_char(*cp++);
> - addr += 4;
> - case 4:
> - *c++ = printable_char(*cp++);
> - *c++ = printable_char(*cp++);
> - addr += 2;
> - case 2:
> - *c++ = printable_char(*cp++);
> - addr++;
> - case 1:
> - *c++ = printable_char(*cp++);
> - addr++;
> - break;
> - }
> + addr += bytesperword;
> #undef printable_char
> }
> }
> --
> 2.7.4
>

2018-08-16 19:18:52

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] kdb: kdb_main: refactor code in kdb_md_line



On 8/16/18 4:32 AM, Daniel Thompson wrote:

>> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
>> index 2ddfce8..4b896a6 100644
>> --- a/kernel/debug/kdb/kdb_main.c
>> +++ b/kernel/debug/kdb/kdb_main.c
>> @@ -1538,25 +1538,9 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
>> wc.word = word;
>> #define printable_char(c) \
>> ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
>> - switch (bytesperword) {
>> - case 8:
>> + for (i = 0; i < bytesperword; i++)
>
> i already a control variable for the outer loop. It is not safe to reuse
> it here.
>

Oh I see. I'll send v2 shortly.

Thanks
--
Gustavo