On 04/19/2018 07:01 AM, Arnon Warshavsky wrote:
> replace panic calls with log and retrun value.
> 
> v4
> static size calculation function changed to return success/fail code
> in addition to filling  the size result.
> 

fyi - this patch doesn't apply on master branch without fuzz

> Signed-off-by: Arnon Warshavsky <ar...@qwilt.com>
> ---
>  lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 32 
> ++++++++++++++++---------
>  1 file changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c 
> b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> index fb4b667..debae32 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> @@ -145,8 +145,8 @@
>       return num_pages;
>  }
>  
> -static uint64_t
> -get_default_hp_size(void)
> +static int
> +get_default_hp_size(uint64_t *result)
>  {
>       const char proc_meminfo[] = "/proc/meminfo";
>       const char str_hugepagesz[] = "Hugepagesize:";
> @@ -155,8 +155,11 @@
>       unsigned long long size = 0;
>  
>       FILE *fd = fopen(proc_meminfo, "r");
> -     if (fd == NULL)
> -             rte_panic("Cannot open %s\n", proc_meminfo);
> +     if (fd == NULL) {
> +             RTE_LOG(CRIT, EAL, "%s(): Cannot open %s\n",
> +                             __func__, proc_meminfo);
> +             return -1;
> +     }
>       while(fgets(buffer, sizeof(buffer), fd)){
>               if (strncmp(buffer, str_hugepagesz, hugepagesz_len) == 0){
>                       size = rte_str_to_size(&buffer[hugepagesz_len]);
> @@ -164,9 +167,13 @@
>               }
>       }
>       fclose(fd);
> -     if (size == 0)
> -             rte_panic("Cannot get default hugepage size from %s\n", 
> proc_meminfo);
> -     return size;
> +     if (size == 0) {
> +             RTE_LOG(CRIT, EAL, "%s(): Cannot get default hugepage size from 
> %s\n",
> +                                              __func__, proc_meminfo);
> +             return -1;
> +     }
> +     *result = size;
> +     return 0;
>  }
>  
>  static const char *
> @@ -191,11 +198,14 @@
>       char *retval = NULL;
>  
>       FILE *fd = fopen(proc_mounts, "r");
> -     if (fd == NULL)
> -             rte_panic("Cannot open %s\n", proc_mounts);
> +     if (fd == NULL) {
> +             RTE_LOG(CRIT, EAL, "%s(): Cannot open %s\n",
> +                             __func__, proc_mounts);
> +             return NULL;
> +     }
>  
> -     if (default_size == 0)
> -             default_size = get_default_hp_size();
> +     if ((default_size == 0) && (get_default_hp_size(&default_size) != 0))
> +             return NULL;
>  
>       while (fgets(buf, sizeof(buf), fd)){
>               if (rte_strsplit(buf, sizeof(buf), splitstr, _FIELDNAME_MAX,
> 

Reply via email to