|SUCCESS| pw159212 [PATCH v5 01/17] eal: use C library to parse filesystem table
0-day Robot
robot at bytheb.org
Tue Dec 16 17:11:57 CET 2025
Test-Label: 0day Robot - Claude SONNET
Test-Status: SUCCESS
http://dpdk.org/patch/159212
_AI Review Comments Available_
Git SHA: cd60dcd503
Author: Stephen Hemminger <stephen at networkplumber.org>
Subject: eal: use C library to parse filesystem table
This patch replaces custom string parsing of /proc/mounts with standard
C library routines getmntent_r() and related functions to parse the
filesystem mount table.
> 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 <stephen at networkplumber.org>
> Acked-by: Bruce Richardson <bruce.richardson at intel.com>
> ---
> lib/eal/linux/eal_hugepage_info.c | 58 ++++++++++---------------------
> 1 file changed, 18 insertions(+), 40 deletions(-)
>
> diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
> index d47a19c56a..7161b1a2fb 100644
> --- a/lib/eal/linux/eal_hugepage_info.c
> +++ b/lib/eal/linux/eal_hugepage_info.c
> @@ -13,6 +13,7 @@
> #include <inttypes.h>
> #include <unistd.h>
> #include <errno.h>
> +#include <mntent.h>
> #include <sys/mman.h>
> #include <sys/stat.h>
[ ... ]
> @@ -226,56 +217,43 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
> return -1;
> }
>
> - FILE *fd = fopen(proc_mounts, "r");
> - if (fd == NULL)
> + FILE *mounts = setmntent(proc_mounts, "r");
> + if (mounts == NULL)
> rte_panic("Cannot open %s\n", proc_mounts);
>
> if (default_size == 0)
> default_size = get_default_hp_size();
>
> - while (fgets(buf, sizeof(buf), fd)){
> + while (getmntent_r(mounts, &entry, buf, sizeof(buf))) {
Does this code check for ENOENT or ERANGE return values from
getmntent_r()? The function can return NULL but set errno to indicate
different types of failures, and partial reads might cause issues.
> const char *pagesz_str;
> - size_t mountpt_len = 0;
> -
> - if (rte_strsplit(buf, sizeof(buf), splitstr, _FIELDNAME_MAX,
> - split_tok) != _FIELDNAME_MAX) {
> - EAL_LOG(ERR, "Error parsing %s", proc_mounts);
> - break; /* return NULL */
> - }
> + uint64_t pagesz = default_size;
> + size_t mountpt_len;
>
> - if (strncmp(splitstr[FSTYPE], hugetlbfs_str, htlbfs_str_len) != 0)
> + if (strcmp(entry.mnt_type, "hugetlbfs") != 0)
> continue;
>
> - pagesz_str = strstr(splitstr[OPTIONS], pagesize_opt);
> + pagesz_str = strstr(entry.mnt_opts, pagesize_opt);
> + if (pagesz_str)
> + pagesz = rte_str_to_size(&pagesz_str[pagesize_opt_len]);
Could entry.mnt_opts be NULL? The mntent structure fields might not
always be populated, and strstr() would segfault on a NULL pointer.
Also, does rte_str_to_size() handle malformed input gracefully? If the
pagesize option exists but has invalid data, this could cause issues.
[ ... ]
More information about the test-report
mailing list