summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSagar Ghuge <[email protected]>2018-09-05 21:05:21 -0700
committerLionel Landwerlin <[email protected]>2018-10-04 10:01:56 +0100
commitba3304e7641e5e91b44b14131b4714d0a18c6d58 (patch)
tree203884b4ff797ef0d7e9a2f3d190ecfcf205d6c3
parent2b34985d93e7914ead00227aa2842846df3c487f (diff)
intel/decoder: add gen_spec_init method
Initialize gen_spec instance properly when loading hardware xml description from specifc directory to avoid segmentation fault. v2: correct function definition (Lionel Landwerlin) Signed-off-by: Sagar Ghuge <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]>
-rw-r--r--src/intel/common/gen_decoder.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/intel/common/gen_decoder.c b/src/intel/common/gen_decoder.c
index c6c213fcd11..d4db8b89cc3 100644
--- a/src/intel/common/gen_decoder.c
+++ b/src/intel/common/gen_decoder.c
@@ -526,6 +526,30 @@ static uint32_t _hash_uint32(const void *key)
return (uint32_t) (uintptr_t) key;
}
+static struct gen_spec *
+gen_spec_init(void)
+{
+ struct gen_spec *spec;
+ spec = rzalloc(NULL, struct gen_spec);
+ if (spec == NULL)
+ return NULL;
+
+ spec->commands =
+ _mesa_hash_table_create(spec, _mesa_hash_string, _mesa_key_string_equal);
+ spec->structs =
+ _mesa_hash_table_create(spec, _mesa_hash_string, _mesa_key_string_equal);
+ spec->registers_by_name =
+ _mesa_hash_table_create(spec, _mesa_hash_string, _mesa_key_string_equal);
+ spec->registers_by_offset =
+ _mesa_hash_table_create(spec, _hash_uint32, _mesa_key_pointer_equal);
+ spec->enums =
+ _mesa_hash_table_create(spec, _mesa_hash_string, _mesa_key_string_equal);
+ spec->access_cache =
+ _mesa_hash_table_create(spec, _mesa_hash_string, _mesa_key_string_equal);
+
+ return spec;
+}
+
struct gen_spec *
gen_spec_load(const struct gen_device_info *devinfo)
{
@@ -560,21 +584,11 @@ gen_spec_load(const struct gen_device_info *devinfo)
XML_SetElementHandler(ctx.parser, start_element, end_element);
XML_SetCharacterDataHandler(ctx.parser, character_data);
- ctx.spec = rzalloc(NULL, struct gen_spec);
-
- ctx.spec->commands =
- _mesa_hash_table_create(ctx.spec, _mesa_hash_string, _mesa_key_string_equal);
- ctx.spec->structs =
- _mesa_hash_table_create(ctx.spec, _mesa_hash_string, _mesa_key_string_equal);
- ctx.spec->registers_by_name =
- _mesa_hash_table_create(ctx.spec, _mesa_hash_string, _mesa_key_string_equal);
- ctx.spec->registers_by_offset =
- _mesa_hash_table_create(ctx.spec, _hash_uint32, _mesa_key_pointer_equal);
- ctx.spec->enums =
- _mesa_hash_table_create(ctx.spec, _mesa_hash_string, _mesa_key_string_equal);
-
- ctx.spec->access_cache =
- _mesa_hash_table_create(ctx.spec, _mesa_hash_string, _mesa_key_string_equal);
+ ctx.spec = gen_spec_init();
+ if (ctx.spec == NULL) {
+ fprintf(stderr, "Failed to create gen_spec\n");
+ return NULL;
+ }
total_length = zlib_inflate(compress_genxmls,
sizeof(compress_genxmls),
@@ -636,7 +650,12 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo,
XML_SetElementHandler(ctx.parser, start_element, end_element);
XML_SetCharacterDataHandler(ctx.parser, character_data);
ctx.loc.filename = filename;
- ctx.spec = rzalloc(NULL, struct gen_spec);
+
+ ctx.spec = gen_spec_init();
+ if (ctx.spec == NULL) {
+ fprintf(stderr, "Failed to create gen_spec\n");
+ return NULL;
+ }
do {
buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);