Skip to contentSkip to conversation

media: mali-c55: Avoid unaligned access of AEC histogram zone weights

PATCH New David Carlier 1 participant 1 message Jul 3

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

PATCH v2 1/1 media: mali-c55: Avoid unaligned access of AEC histogram zone weights

mali_c55_params_aexp_hist_weights() packs the 225 per-zone u8 weights into the ISP registers four at a time by casting the zone_weights array to u32 and dereferencing it. The array sits at offset 10 within the parameter block, so it is only 2-byte aligned and the cast performs an unaligned 32-bit read.

The Mali-C55 is only found on little-endian ARMv8 systems, where such an access does not fault, so this is not a functional bug. Copy the four bytes with memcpy() instead to avoid the unaligned access, which is a little more efficient and drops the open-coded pointer cast.

No functional change intended.

---
v2:
- Use memcpy() instead of get_unaligned_le32() to copy the weights.
- Drop the Fixes: tag and Cc: stable; this is a cleanup, not a functional fix (the IP is little-endian ARMv8 only, where the unaligned access does not fault). Reword the commit message accordingly.

 drivers/media/platform/arm/mali-c55/mali-c55-params.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/arm/mali-c55/mali-c55-params.c +3 -3
index de0e9d898..832d8f49b 100644
@@ -203,11 +203,11 @@ mali_c55_params_aexp_hist_weights(struct mali_c55 *mali_c55,
 	 * of overwriting other registers.
 	 */
 	for (unsigned int i = 0; i < 56; i++) {
-		val = ((u32 *)params->zone_weights)[i]
-			    & MALI_C55_AEXP_HIST_ZONE_WEIGHT_MASK;
+		memcpy(&val, &params->zone_weights[4 * i], 4);
 		addr = base + MALI_C55_AEXP_HIST_ZONE_WEIGHTS_OFFSET + (4 * i);
 
-		mali_c55_ctx_write(mali_c55, addr, val);
+		mali_c55_ctx_write(mali_c55, addr,
+				   val & MALI_C55_AEXP_HIST_ZONE_WEIGHT_MASK);
 	}
 
 	val = params->zone_weights[MALI_C55_MAX_ZONES - 1];
Signature · 1 line
2.53.0