Skip to contentSkip to conversation

media: s5p-mfc: Corrected NV12M/NV21M plane-sizes

PATCH Superseded Aakarsh Jain 3 participants 3 messages Feb 27, 2025 – Feb 28, 2025 1 message not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20250226102749epcas5p35afe43774ad2917b846c921dc593a5ef@epcas5p3.samsung.com

#1 lore raw

PATCH v2 1/1 media: s5p-mfc: Corrected NV12M/NV21M plane-sizes

There is a possibility of getting page fault if the overall buffer size is not aligned to 256bytes. Since MFC does read operation only and it won't corrupt the data values even if it reads the extra bytes.
Corrected luma and chroma plane sizes for V4L2_PIX_FMT_NV12M and V4L2_PIX_FMT_NV21M pixel format.

---
changelog:
v1->v2
Patch link: https://patchwork.kernel.org/project/linux-media/patch/[email protected]/
Removed duplicate code and aligned luma and chroma size
to multiple of 256bytes as suggested by Hans.

 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +3 -2
index 73f7af674c01..0c636090d723 100644
@@ -549,8 +549,9 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
 		case V4L2_PIX_FMT_NV21M:
 			ctx->stride[0] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
 			ctx->stride[1] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
-			ctx->luma_size = ctx->stride[0] * ALIGN(ctx->img_height, 16);
-			ctx->chroma_size =  ctx->stride[0] * ALIGN(ctx->img_height / 2, 16);
+			ctx->luma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height, 16), 256);
+			ctx->chroma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height / 2, 16),
+					256);
 			break;
 		case V4L2_PIX_FMT_YUV420M:
 		case V4L2_PIX_FMT_YVU420M:
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#2 lore raw

Hi,

Le mercredi 26 février 2025 à 15:52 +0530, Aakarsh Jain a écrit :

Quoted 26 lines

There is a possibility of getting page fault if the overall buffer size is not aligned to 256bytes. Since MFC does read operation only and it won't corrupt the data values even if it reads the extra bytes.
Corrected luma and chroma plane sizes for V4L2_PIX_FMT_NV12M and V4L2_PIX_FMT_NV21M pixel format.

---
changelog:
v1->v2
Patch link: https://patchwork.kernel.org/project/linux-media/patch/[email protected]/
Removed duplicate code and aligned luma and chroma size
to multiple of 256bytes as suggested by Hans. drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +0 -0
index 73f7af674c01..0c636090d723 100644
@@ -549,8 +549,9 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)

  case V4L2_PIX_FMT_NV21M:
  ctx->stride[0] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6); ctx->stride[1] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);

drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx) · line 554

Quoted 5 lines
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +3 -2
-			ctx->luma_size = ctx->stride[0] * ALIGN(ctx->img_height, 16);
-			ctx->chroma_size =  ctx->stride[0] * ALIGN(ctx->img_height / 2, 16);
+			ctx->luma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height, 16), 256);
+			ctx->chroma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height / 2, 16),
+					256);

An eventual port to v4l2-common helpers instead of open coding this would be nice, though I see nothing wrong to report with this code, so:

regards,
Nicolas

Quoted 3 lines

  break;
  case V4L2_PIX_FMT_YUV420M:
  case V4L2_PIX_FMT_YVU420M:

maintainer Acked-by on v2 1/1
#3 lore raw
In reply to Aakarsh Jain
Quoted 9 lines · Aakarsh Jain

There is a possibility of getting page fault if the overall buffer size is not aligned to 256bytes. Since MFC does read operation only and it won't corrupt the data values even if it reads the extra bytes.
Corrected luma and chroma plane sizes for V4L2_PIX_FMT_NV12M and V4L2_PIX_FMT_NV21M pixel format.

Quoted 15 lines

---
changelog:
v1->v2
Patch link: https://patchwork.kernel.org/project/linux-media/patch/[email protected]/
Removed duplicate code and aligned luma and chroma size
to multiple of 256bytes as suggested by Hans.

  drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +0 -0
index 73f7af674c01..0c636090d723 100644
@@ -549,8 +549,9 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
  		case V4L2_PIX_FMT_NV21M:

drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx) · line 557

Quoted 10 lines
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +3 -2
  			ctx->stride[0] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
  			ctx->stride[1] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
-			ctx->luma_size = ctx->stride[0] * ALIGN(ctx->img_height, 16);
-			ctx->chroma_size =  ctx->stride[0] * ALIGN(ctx->img_height / 2, 16);
+			ctx->luma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height, 16), 256);
+			ctx->chroma_size = ALIGN(ctx->stride[0] * ALIGN(ctx->img_height / 2, 16),
+					256);
  			break;
  		case V4L2_PIX_FMT_YUV420M:
  		case V4L2_PIX_FMT_YVU420M:

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland