[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/2] xen/char: console: Use const whenever we point to literal strings


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <luca.fancellu@xxxxxxx>
  • Date: Tue, 18 May 2021 15:39:36 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SWeXAeQUtjtyw9RVs8UQWsQ4Zvnw+i9+BKnCk0yF7s0=; b=RQ8Qhnc5/7722vSeIHq1/V/KCCT5P/LXb8iMGGPflhQV/rOF/9bPLMkjHfwduVwIZJzKHhT991qtN6VlvQV3SqULMPwcTiUvCrsf4YpvorBpd/JU7wxveLFfQv6NBuVck2oLWlkHOXw8Jr5dZDmHC6UfgKA4g168I2uK8XPQuLgvbKjE5DDEpqnHVkl++af21RFJnqsLLnzpdw6AE9wpkZosExGE6dant2SzVvYW1yuQ6UMknhIEJQG1TRErYOqBkxeIUA6WwAShRtJCtQvOcGqHFc/AIkC+VEBemPvBo3zkpU+ufJ126mQJHCacKK9TGPt2cYXhITbCuUdbD9wBjA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EVG5oXjQz/4EXyy0BYTXzqwHvJhkza9QqwmD7Qc+S+49W6H8vofLJnu9PjKoZYilqEMp9BmdKQxF2yyCRo9ZY5yjSkRnkGv5lgOBTWZO+EVAw7o8zrQxUC2g+9TCqtfbN3IuTlWTVCGJJME72j+oNZAflYyzVPoYP+5gbgo4mLWpu5pJYzFIlw0pIhO3I57KDT6u7m73HveLGU8CrQpP1icj99JQH5dXyhEJo7/5lh1tq4UlN5qOtN9SvX3kizvdNycMNy4b8zNfzeksQ6wvvBN3KqKaVHXoJA8pdEYyZVDjSxI8xSOy8jCVbgxbKas2yLxmKGmh1xm8NwZ2IGIkgw==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Julien Grall <jgrall@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 18 May 2021 14:40:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;


> On 18 May 2021, at 15:01, Julien Grall <julien@xxxxxxx> wrote:
> 
> From: Julien Grall <jgrall@xxxxxxxxxx>
> 
> 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 <jgrall@xxxxxxxxxx>
> 
> ---
>    Changes in v2:
>        - The array content should never be modified
>        - Move lvl2opt in xenlog_update_val()
> ---
> xen/drivers/char/console.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index 23583751709c..7d0a603d0311 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 )
>     {
> -- 
> 2.17.1
> 

Hi Julien,

Seems good to me and very sensible.

Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>

Cheers,
Luca




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.