Skip to contentSkip to conversation

media: imagination: Fix value clamping in calculate_qp_tables()

PATCH RESEND In review Thorsten Blum 3 participants 4 messages Jul 27 – Sep 28

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

PATCH RESEND 1/1 media: imagination: Fix value clamping in calculate_qp_tables()

The local variable val was never clamped to 1 or 255 because the return value of clamp() was not used. Fix this by assigning the clamped value back to val.

Fixes a1e294045885 ("media: imagination: Add E5010 JPEG Encoder driver")
---
 drivers/media/platform/imagination/e5010-jpeg-enc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/imagination/e5010-jpeg-enc.c +2 -2
index 42ad9ee3993b..420cb8bfdb12 100644
@@ -175,12 +175,12 @@ static void calculate_qp_tables(struct e5010_context *ctx)
 		long long delta = v4l2_jpeg_ref_table_chroma_qt[i] * contrast + luminosity;
 		int val = (int)(v4l2_jpeg_ref_table_chroma_qt[i] + delta);
 
-		clamp(val, 1, 255);
+		val = clamp(val, 1, 255);
 		ctx->chroma_qp[i] = quality == -50 ? 1 : val;
 
 		delta = v4l2_jpeg_ref_table_luma_qt[i] * contrast + luminosity;
 		val = (int)(v4l2_jpeg_ref_table_luma_qt[i] + delta);
-		clamp(val, 1, 255);
+		val = clamp(val, 1, 255);
 		ctx->luma_qp[i] = quality == -50 ? 1 : val;
 	}
 
Reviewed-by on v1 1/1
#1 lore raw

Hi Thorsten,

Thank you for the fix.

Quoting Thorsten Blum (2026-07-27 15:17:30)

Quoted 6 lines

The local variable val was never clamped to 1 or 255 because the return value of clamp() was not used. Fix this by assigning the clamped value back to val.

Fixes a1e294045885 ("media: imagination: Add E5010 JPEG Encoder driver")

Thanks,
Jai

Quoted 24 lines
---
 drivers/media/platform/imagination/e5010-jpeg-enc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/imagination/e5010-jpeg-enc.c +2 -2
index 42ad9ee3993b..420cb8bfdb12 100644
@@ -175,12 +175,12 @@ static void calculate_qp_tables(struct e5010_context *ctx)
                long long delta = v4l2_jpeg_ref_table_chroma_qt[i] * contrast + luminosity;
                int val = (int)(v4l2_jpeg_ref_table_chroma_qt[i] + delta);
 
-               clamp(val, 1, 255);
+               val = clamp(val, 1, 255);
                ctx->chroma_qp[i] = quality == -50 ? 1 : val;
 
                delta = v4l2_jpeg_ref_table_luma_qt[i] * contrast + luminosity;
                val = (int)(v4l2_jpeg_ref_table_luma_qt[i] + delta);
-               clamp(val, 1, 255);
+               val = clamp(val, 1, 255);
                ctx->luma_qp[i] = quality == -50 ? 1 : val;
        }
 
#2 lore raw
Quoted 9 lines · Jai Luthra

Quoting Thorsten Blum (2026-07-27 15:17:30)

Quoted 6 lines

The local variable val was never clamped to 1 or 255 because the return value of clamp() was not used. Fix this by assigning the clamped value back to val.

Fixes a1e294045885 ("media: imagination: Add E5010 JPEG Encoder driver")

Thank you for the review.

Could someone please pick this up?

Thanks,
Thorsten

#3 lore raw

Le lundi 31 août 2026 à 10:13 +0200, Thorsten Blum a écrit :

Quoted 6 lines · Jai Luthra
Quoted 5 lines

Quoting Thorsten Blum (2026-07-27 15:17:30)

Quoted 4 lines

The local variable val was never clamped to 1 or 255 because the return value of clamp() was not used. Fix this by assigning the clamped value back to val.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes a1e294045885 ("media: imagination: Add E5010 JPEG Encoder driver")

Thank you for the review.

Could someone please pick this up?

Picked, ty

Nicolas

Quoted 3 lines

Thanks,
Thorsten