Skip to contentSkip to conversation

media: stm32: dcmipp: pixelproc: Fix width limit for downsize block

PATCH In review Lin Huiyi 2 participants 2 messages Nov 29 – Dec 1

Subsystems (3)
lore
Share & tools
lore

Lin Huiyi

author
#0 lore raw

PATCH 1/1 media: stm32: dcmipp: pixelproc: Fix width limit for downsize block

The pixelproc subdev advertises a maximum width of DCMIPP_FRAME_MAX_WIDTH (4096), but the downsize block target size register DCMIPP_PxDSSZR stores the width in a 12-bit field (GENMASK(11,0)) which can hold at most 4095. Composing a full 4096-pixel wide stream therefore writes 4096 into the register, setting bit 12 outside of the HSIZE field and leaving the field itself at 0.

Clamp the pixelproc width to the largest value the field can represent (4095).

Fixes 239cf9e5fda1 ("media: stm32: dcmipp: pixelproc: addition of dcmipp-pixelproc subdev")
---
 .../platform/st/stm32/stm32-dcmipp/dcmipp-pixelproc.c     | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-pixelproc.c +7 -1
index 7d8e5f0863..779c898793 100644
@@ -455,8 +455,14 @@ dcmipp_pixelproc_adjust_fmt(struct dcmipp_pixelproc_device *pixelproc,
 	if (!vpix)
 		fmt->code = PIXELPROC_MEDIA_BUS_FMT_DEFAULT;
 
+	/*
+	 * The downsize target size register DCMIPP_PxDSSZR stores the
+	 * output width in a 12-bit field which can not hold
+	 * DCMIPP_FRAME_MAX_WIDTH, clamp the width to the largest value
+	 * the field can represent.
+	 */
 	fmt->width = clamp_t(u32, fmt->width, DCMIPP_FRAME_MIN_WIDTH,
-			     DCMIPP_FRAME_MAX_WIDTH);
+			     DCMIPP_PxDSSZR_HSIZE_MASK);
 	fmt->height = clamp_t(u32, fmt->height, DCMIPP_FRAME_MIN_HEIGHT,
 			      DCMIPP_FRAME_MAX_HEIGHT);
 
Signature · 1 line
2.56.1
#1 lore raw

Alain,

Can you review this? It sounds plausible, but someone with the datasheet should verify this.

Regards,

Hans

Quoted 37 lines · Lin Huiyi

The pixelproc subdev advertises a maximum width of DCMIPP_FRAME_MAX_WIDTH (4096), but the downsize block target size register DCMIPP_PxDSSZR stores the width in a 12-bit field (GENMASK(11,0)) which can hold at most 4095. Composing a full 4096-pixel wide stream therefore writes 4096 into the register, setting bit 12 outside of the HSIZE field and leaving the field itself at 0.

Clamp the pixelproc width to the largest value the field can represent (4095).

Fixes 239cf9e5fda1 ("media: stm32: dcmipp: pixelproc: addition of dcmipp-pixelproc subdev")
---
 .../platform/st/stm32/stm32-dcmipp/dcmipp-pixelproc.c     | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-pixelproc.c +7 -1
index 7d8e5f0863..779c898793 100644
@@ -455,8 +455,14 @@ dcmipp_pixelproc_adjust_fmt(struct dcmipp_pixelproc_device *pixelproc,
 	if (!vpix)
 		fmt->code = PIXELPROC_MEDIA_BUS_FMT_DEFAULT;
 
+	/*
+	 * The downsize target size register DCMIPP_PxDSSZR stores the
+	 * output width in a 12-bit field which can not hold
+	 * DCMIPP_FRAME_MAX_WIDTH, clamp the width to the largest value
+	 * the field can represent.
+	 */
 	fmt->width = clamp_t(u32, fmt->width, DCMIPP_FRAME_MIN_WIDTH,
-			     DCMIPP_FRAME_MAX_WIDTH);
+			     DCMIPP_PxDSSZR_HSIZE_MASK);
 	fmt->height = clamp_t(u32, fmt->height, DCMIPP_FRAME_MIN_HEIGHT,
 			      DCMIPP_FRAME_MAX_HEIGHT);