[gcc(refs/vendors/ARM/heads/arm-perf-staging)] amdgcn: Check HSA return codes [PR94629]

Tamar Christina tnfchris@gcc.gnu.org
Fri Jul 17 14:53:17 GMT 2020


https://gcc.gnu.org/g:966de09be91c639d66d252c9ae6ab8da5ebfca18

commit 966de09be91c639d66d252c9ae6ab8da5ebfca18
Author: Andrew Stubbs <ams@codesourcery.com>
Date:   Mon Apr 20 15:25:31 2020 +0100

    amdgcn: Check HSA return codes [PR94629]
    
    Ensure that the returned status values are not ignored.  The old code was
    not broken, but this is both safer and satisfies static analysis.
    
    2020-04-23  Andrew Stubbs  <ams@codesourcery.com>
    
            PR other/94629
    
            libgomp/
            * plugin/plugin-gcn.c (init_hsa_context): Check return value from
            hsa_iterate_agents.
            (GOMP_OFFLOAD_init_device): Check return values from both calls to
            hsa_agent_iterate_regions.

Diff:
---
 libgomp/ChangeLog           | 9 +++++++++
 libgomp/plugin/plugin-gcn.c | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index c524abbbfb6..ee1764d4ae3 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,12 @@
+2020-04-23  Andrew Stubbs  <ams@codesourcery.com>
+
+	PR other/94629
+
+	* plugin/plugin-gcn.c (init_hsa_context): Check return value from
+	hsa_iterate_agents.
+	(GOMP_OFFLOAD_init_device): Check return values from both calls to
+	hsa_agent_iterate_regions.
+
 2020-04-20  Thomas Schwinge  <thomas@codesourcery.com>
 
 	PR middle-end/94635
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index dc72c90962c..4c6a4c03b6e 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -1508,6 +1508,8 @@ init_hsa_context (void)
     = GOMP_PLUGIN_malloc_cleared (hsa_context.agent_count
 				  * sizeof (struct agent_info));
   status = hsa_fns.hsa_iterate_agents_fn (assign_agent_ids, &agent_index);
+  if (status != HSA_STATUS_SUCCESS)
+    return hsa_error ("Scanning compute agents failed", status);
   if (agent_index != hsa_context.agent_count)
     {
       GOMP_PLUGIN_error ("Failed to assign IDs to all GCN agents");
@@ -3473,6 +3475,9 @@ GOMP_OFFLOAD_init_device (int n)
   status = hsa_fns.hsa_agent_iterate_regions_fn (agent->id,
 						 get_kernarg_memory_region,
 						 &agent->kernarg_region);
+  if (status != HSA_STATUS_SUCCESS
+      && status != HSA_STATUS_INFO_BREAK)
+    hsa_error ("Scanning memory regions failed", status);
   if (agent->kernarg_region.handle == (uint64_t) -1)
     {
       GOMP_PLUGIN_error ("Could not find suitable memory region for kernel "
@@ -3486,6 +3491,9 @@ GOMP_OFFLOAD_init_device (int n)
   status = hsa_fns.hsa_agent_iterate_regions_fn (agent->id,
 						 get_data_memory_region,
 						 &agent->data_region);
+  if (status != HSA_STATUS_SUCCESS
+      && status != HSA_STATUS_INFO_BREAK)
+    hsa_error ("Scanning memory regions failed", status);
   if (agent->data_region.handle == (uint64_t) -1)
     {
       GOMP_PLUGIN_error ("Could not find suitable memory region for device "


More information about the Gcc-cvs mailing list