All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] media: mali-c55: Avoid unaligned access of AEC histogram zone weights
@ 2026-07-03 16:35 David Carlier
  0 siblings, 0 replies; only message in thread
From: David Carlier @ 2026-07-03 16:35 UTC (permalink / raw)
  To: dan.scally, jacopo.mondi, mchehab
  Cc: linux-media, linux-kernel, David Carlier

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.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
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(-)

diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-params.c b/drivers/media/platform/arm/mali-c55/mali-c55-params.c
index de0e9d898..832d8f49b 100644
--- a/drivers/media/platform/arm/mali-c55/mali-c55-params.c
+++ b/drivers/media/platform/arm/mali-c55/mali-c55-params.c
@@ -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];
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-03 16:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 16:35 [PATCH v2] media: mali-c55: Avoid unaligned access of AEC histogram zone weights David Carlier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.