From: Julien Grall Date: Wed, 26 May 2021 15:01:32 +0000 (+0100) Subject: xen/char: console: Use const whenever we point to literal strings X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~497 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b0a5b1735c704ec2055e52587a7c5b94370911c0;p=xen.git xen/char: console: Use const whenever we point to literal strings 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. The array should also not be modified at all and is only used by xenlog_update_val(). So take the opportunity to add an extra const and move the definition in the function. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Reviewed-by: Luca Fancellu --- diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 2358375170..7d0a603d03 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -168,10 +168,11 @@ 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 void xenlog_update_val(int lower, int upper, char *val) { + static const char * const lvl2opt[] = + { "none", "error", "warning", "info", "all" }; + snprintf(val, LOGLVL_VAL_SZ, "%s/%s", lvl2opt[lower], lvl2opt[upper]); } @@ -262,7 +263,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 ) {