On Sat, Nov 22, 2025 at 11:49:21AM -0800, Stephen Hemminger wrote:
> Rather than doing parsing of /proc/mounts with open coded string
> handling, use the standard C library routines.
> These exist in BSD and Linux.
> 
> It also avoids any possible issues with escaped strings etc
> which the library handles. See getmntent(3) man page.
> 
> Signed-off-by: Stephen Hemminger <[email protected]>
> ---
Acked-by: Bruce Richardson <[email protected]>


>  lib/eal/linux/eal_hugepage_info.c | 45 ++++++++++---------------------
>  1 file changed, 14 insertions(+), 31 deletions(-)
> 

<snip>  

> -             pagesz_str = strstr(splitstr[OPTIONS], pagesize_opt);
> +             pagesz_str = strstr(entry.mnt_opts, pagesize_opt);
>  
>               /* if no explicit page size, the default page size is compared 
> */
>               if (pagesz_str == NULL) {
>                       if (hugepage_sz != default_size)
>                               continue;
> -             }
> -             /* there is an explicit page size, so check it */
> -             else {
> +             } else {
> +                     /* there is an explicit page size, so check it */
>                       uint64_t pagesz = 
> rte_str_to_size(&pagesz_str[pagesize_opt_len]);
>                       if (pagesz != hugepage_sz)
>                               continue;

Since you are already changing this part, this if-else block can be
shortened down to avoid duplicating the continue check:

diff --git a/lib/eal/linux/eal_hugepage_info.c 
b/lib/eal/linux/eal_hugepage_info.c
index ecc0374204..0e54b35ce1 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -227,22 +227,16 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int 
len)
        while (getmntent_r(mounts, &entry, buf, sizeof(buf))) {
                const char *pagesz_str;
                size_t mountpt_len = 0;
+               uint64_t pagesz;
 
                if (strcmp(entry.mnt_type, "hugetlbfs") != 0)
                        continue;
 
                pagesz_str = strstr(entry.mnt_opts, pagesize_opt);
-
-               /* if no explicit page size, the default page size is compared 
*/
-               if (pagesz_str == NULL) {
-                       if (hugepage_sz != default_size)
-                               continue;
-               } else {
-                       /* there is an explicit page size, so check it */
-                       uint64_t pagesz = 
rte_str_to_size(&pagesz_str[pagesize_opt_len]);
-                       if (pagesz != hugepage_sz)
-                               continue;
-               }
+               pagesz = (pagesz_str == NULL) ? default_size :
+                               rte_str_to_size(&pagesz_str[pagesize_opt_len]);
+               if (pagesz != hugepage_sz)
+                       continue;
 
                /*
                 * If no --huge-dir option has been given, we're done.

Reply via email to