Skip to contentSkip to conversation

media: venus: fix HFI parser payload size returns

PATCH In review Mohammed EL Kadiri 2 participants 5 messages Jun 10

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover media: venus: fix HFI parser payload size returns

Several parse functions return incorrect consumed sizes after the refactor in commit 9edaaa8e3e15. hfi_parser() uses these values to advance through the firmware response buffer, so incorrect sizes cause parser desynchronization.

parse_profile_level() has the correct pattern. These patches align the remaining functions to match it.

Compile-tested with arm64 cross-compiler (gcc 13.3).

Mohammed EL Kadiri (2):
media: venus: fix payload size returned by parse_caps() and
parse_alloc_mode()
media: venus: fix payload size calculation in parse_raw_formats()

 drivers/media/platform/qcom/venus/hfi_parser.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 media: venus: fix payload size returned by parse_caps() and parse_alloc_mode()

parse_caps() and parse_alloc_mode() return only the size of their fixed header fields, excluding the flexible array payload. hfi_parser() uses this return value to advance through the firmware response buffer, so underreporting causes parser desynchronization.

Return the full consumed size (header + entries), matching the correct pattern used by parse_profile_level().

Fixes 9edaaa8e3e15 ("media: venus: hfi_parser: refactor hfi packet parsing logic")
---
 drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_parser.c +2 -2
index 1b3db2caa99f..e2af4e9901ee 100644
@@ -85,7 +85,7 @@ parse_alloc_mode(struct venus_core *core, u32 codecs, u32 domain, void *data)
 		type++;
 	}
 
-	return sizeof(*mode);
+	return mode->num_entries * sizeof(u32) + sizeof(*mode);
 }
 
 static void fill_profile_level(struct hfi_plat_caps *cap, const void *data,
@@ -146,7 +146,7 @@ parse_caps(struct venus_core *core, u32 codecs, u32 domain, void *data)
 	for_each_codec(core->caps, ARRAY_SIZE(core->caps), codecs, domain,
 		       fill_caps, caps_arr, num_caps);
 
-	return sizeof(*caps);
+	return num_caps * sizeof(*cap) + sizeof(u32);
 }
 
 static void fill_raw_fmts(struct hfi_plat_caps *cap, const void *fmts,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] media: venus: fix payload size returned by parse_caps() and parse_alloc_mode()

Quoted 8 lines · Mohammed EL Kadiri

parse_caps() and parse_alloc_mode() return only the size of their fixed header fields, excluding the flexible array payload. hfi_parser() uses this return value to advance through the firmware response buffer, so underreporting causes parser desynchronization.

Return the full consumed size (header + entries), matching the correct pattern used by parse_profile_level().

Quoted 7 lines
Fixes 9edaaa8e3e15 ("media: venus: hfi_parser: refactor hfi packet parsing logic")
---
 drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#3 lore raw

PATCH 2/2 media: venus: fix payload size calculation in parse_raw_formats()

In reply to Mohammed EL Kadiri

The consumed size is computed after the loop using the num_planes value from the last iteration for all entries. When entries have different plane counts, this produces an incorrect total.

Accumulate the actual size during the loop instead.

Fixes 9edaaa8e3e15 ("media: venus: hfi_parser: refactor hfi packet parsing logic")
---
 drivers/media/platform/qcom/venus/hfi_parser.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/venus/hfi_parser.c +2 -3
index e2af4e9901ee..522bac7ba154 100644
@@ -171,7 +171,7 @@ parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
 	u32 entries = fmt->format_entries;
 	unsigned int i = 0;
 	u32 num_planes = 0;
-	u32 size;
+	u32 size = 2 * sizeof(u32);
 
 	while (entries) {
 		num_planes = pinfo->num_planes;
@@ -186,6 +186,7 @@ parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
 		if (pinfo->num_planes > MAX_PLANES)
 			break;
 
+		size += sizeof(*constr) * num_planes + 2 * sizeof(u32);
 		pinfo = (void *)pinfo + sizeof(*constr) * num_planes +
 			2 * sizeof(u32);
 		entries--;
@@ -193,8 +194,6 @@ parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
 
 	for_each_codec(core->caps, ARRAY_SIZE(core->caps), codecs, domain,
 		       fill_raw_fmts, rawfmts, i);
-	size = fmt->format_entries * (sizeof(*constr) * num_planes + 2 * sizeof(u32))
-		+ 2 * sizeof(u32);
 
 	return size;
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] media: venus: fix payload size calculation in parse_raw_formats()

Quoted 4 lines · Mohammed EL Kadiri

The consumed size is computed after the loop using the num_planes value from the last iteration for all entries. When entries have different plane counts, this produces an incorrect total.

Quoted 9 lines

Accumulate the actual size during the loop instead.

Fixes 9edaaa8e3e15 ("media: venus: hfi_parser: refactor hfi packet parsing logic")
---
 drivers/media/platform/qcom/venus/hfi_parser.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 2 lines
With best wishes
Dmitry