dts: fix hugepage configuration bug

Message ID 20250114200038.193700-1-npratte@iol.unh.edu (mailing list archive)
State Accepted
Delegated to: Paul Szczepanek
Headers
Series dts: fix hugepage configuration bug |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation warning apply issues
ci/loongarch-compilation warning apply patch failure
ci/iol-testing warning apply patch failure
ci/github-robot: build success github build: passed

Commit Message

Nicholas Pratte Jan. 14, 2025, 8 p.m. UTC
The dts framework checks for total hugepages of a specific size on a
system without first checking if such hugepages are supported. This
results in unhelpful error messages, since attempting to grab
information from a file/directory that does not exist creates undefined
behavior. This quick reorientation of the code prevents this, and
allows for easier error assessment.

Signed-off-by: Nicholas Pratte <npratte@iol.unh.edu>
---
 dts/framework/testbed_model/linux_session.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Luca Vizzarro Jan. 15, 2025, 10:10 a.m. UTC | #1
Looks good.

Reviewed-by: Luca Vizzarro <luca.vizzarro@arm.com>
  

Patch

diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py
index bda2d448f7..e3732f0827 100644
--- a/dts/framework/testbed_model/linux_session.py
+++ b/dts/framework/testbed_model/linux_session.py
@@ -90,12 +90,12 @@  def setup_hugepages(self, number_of: int, hugepage_size: int, force_first_numa:
             ConfigurationError: If the given `hugepage_size` is not supported by the OS.
         """
         self._logger.info("Getting Hugepage information.")
-        hugepages_total = self._get_hugepages_total(hugepage_size)
         if (
             f"hugepages-{hugepage_size}kB"
             not in self.send_command("ls /sys/kernel/mm/hugepages").stdout
         ):
             raise ConfigurationError("hugepage size not supported by operating system")
+        hugepages_total = self._get_hugepages_total(hugepage_size)
         self._numa_nodes = self._get_numa_nodes()
 
         if force_first_numa or hugepages_total < number_of: