diff mbox series

[04/14] xen/char: console: Use const whenever we point to literal strings

Message ID 20210405155713.29754-5-julien@xen.org (mailing list archive)
State New, archived
Headers show
Series Use const whether we point to literal strings (take 1) | expand

Commit Message

Julien Grall April 5, 2021, 3:57 p.m. UTC
From: Julien Grall <jgrall@amazon.com>

literal strings are not meant to be modified. So we should use const
char * rather than char * when we want to store a pointer to them.

Signed-off-by: Julien Grall <jgrall@amazon.com>
---
 xen/drivers/char/console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jan Beulich April 6, 2021, 8:10 a.m. UTC | #1
On 05.04.2021 17:57, Julien Grall wrote:
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -168,7 +168,7 @@ static int parse_guest_loglvl(const char *s);
>  static char xenlog_val[LOGLVL_VAL_SZ];
>  static char xenlog_guest_val[LOGLVL_VAL_SZ];
>  
> -static char *lvl2opt[] = { "none", "error", "warning", "info", "all" };
> +static const char *lvl2opt[] = { "none", "error", "warning", "info", "all" };

If you add any const here, then I think you should go to full way
and also add the second missing one. Then
Reviewed-by: Jan Beulich <jbeulich@suse.com>

Arguably the array should also be local to xenlog_update_val().

Jan
Julien Grall April 6, 2021, 6:27 p.m. UTC | #2
Hi Jan,

On 06/04/2021 09:10, Jan Beulich wrote:
> On 05.04.2021 17:57, Julien Grall wrote:
>> --- a/xen/drivers/char/console.c
>> +++ b/xen/drivers/char/console.c
>> @@ -168,7 +168,7 @@ static int parse_guest_loglvl(const char *s);
>>   static char xenlog_val[LOGLVL_VAL_SZ];
>>   static char xenlog_guest_val[LOGLVL_VAL_SZ];
>>   
>> -static char *lvl2opt[] = { "none", "error", "warning", "info", "all" };
>> +static const char *lvl2opt[] = { "none", "error", "warning", "info", "all" };
> 
> If you add any const here, then I think you should go to full way
> and also add the second missing one. Then
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> 
> Arguably the array should also be local to xenlog_update_val().

I will look at it and send a new version.

Cheers,
diff mbox series

Patch

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 23583751709c..72a7cd1c32c1 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -168,7 +168,7 @@  static int parse_guest_loglvl(const char *s);
 static char xenlog_val[LOGLVL_VAL_SZ];
 static char xenlog_guest_val[LOGLVL_VAL_SZ];
 
-static char *lvl2opt[] = { "none", "error", "warning", "info", "all" };
+static const char *lvl2opt[] = { "none", "error", "warning", "info", "all" };
 
 static void xenlog_update_val(int lower, int upper, char *val)
 {
@@ -262,7 +262,7 @@  static int parse_guest_loglvl(const char *s)
     return ret;
 }
 
-static char *loglvl_str(int lvl)
+static const char *loglvl_str(int lvl)
 {
     switch ( lvl )
     {