[PATCH v3 62/76] media: hantro: Access v4l2_fh from file->private_data

Nicolas Dufresne nicolas.dufresne at collabora.com
Mon Aug 11 07:36:43 PDT 2025


Le dimanche 10 août 2025 à 04:30 +0300, Laurent Pinchart a écrit :
> To prepare for the introduction of video_device_state as second argument
> of the v4l2_ioctl_ops handler, access the v4l2_fh from
> file->private_data instead of using void *priv.
> 
> The file->private_data is initialized to point to the v4l2_fh
> by the usage of v4l2_fh_init() in the v4l2_file_operations.open()
> handler.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas at ideasonboard.com>
> Reviewed-by: Paul Kocialkowski <paulk at sys-base.io>

Acked-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>


> ---
> Changes since v1:
> 
> - Update file-to-ctx macro due to removal of fh-to-ctx macro
> ---
>  drivers/media/platform/verisilicon/hantro.h   |  7 +-----
>  .../media/platform/verisilicon/hantro_v4l2.c  | 22 +++++++++----------
>  2 files changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/media/platform/verisilicon/hantro.h
> b/drivers/media/platform/verisilicon/hantro.h
> index 5b85c8a44706..e0fdc4535b2d 100644
> --- a/drivers/media/platform/verisilicon/hantro.h
> +++ b/drivers/media/platform/verisilicon/hantro.h
> @@ -382,14 +382,9 @@ extern int hantro_debug;
>  	pr_err("%s:%d: " fmt, __func__, __LINE__, ##args)
>  
>  /* Structure access helpers. */
> -static __always_inline struct hantro_ctx *fh_to_ctx(struct v4l2_fh *fh)
> -{
> -	return container_of(fh, struct hantro_ctx, fh);
> -}
> -
>  static __always_inline struct hantro_ctx *file_to_ctx(struct file *filp)
>  {
> -	return fh_to_ctx(file_to_v4l2_fh(filp));
> +	return container_of(file_to_v4l2_fh(filp), struct hantro_ctx, fh);
>  }
>  
>  /* Register accessors. */
> diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c
> b/drivers/media/platform/verisilicon/hantro_v4l2.c
> index 7c3515cf7d64..6bcd892e7bb4 100644
> --- a/drivers/media/platform/verisilicon/hantro_v4l2.c
> +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
> @@ -185,7 +185,7 @@ static int vidioc_querycap(struct file *file, void *priv,
>  static int vidioc_enum_framesizes(struct file *file, void *priv,
>  				  struct v4l2_frmsizeenum *fsize)
>  {
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  	const struct hantro_fmt *fmt;
>  
>  	fmt = hantro_find_format(ctx, fsize->pixel_format);
> @@ -217,7 +217,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
>  			   struct v4l2_fmtdesc *f, bool capture)
>  
>  {
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  	const struct hantro_fmt *fmt, *formats;
>  	unsigned int num_fmts, i, j = 0;
>  	bool skip_mode_none, enum_all_formats;
> @@ -297,7 +297,7 @@ static int vidioc_g_fmt_out_mplane(struct file *file, void
> *priv,
>  				   struct v4l2_format *f)
>  {
>  	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  
>  	vpu_debug(4, "f->type = %d\n", f->type);
>  
> @@ -310,7 +310,7 @@ static int vidioc_g_fmt_cap_mplane(struct file *file, void
> *priv,
>  				   struct v4l2_format *f)
>  {
>  	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  
>  	vpu_debug(4, "f->type = %d\n", f->type);
>  
> @@ -398,13 +398,13 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
>  static int vidioc_try_fmt_cap_mplane(struct file *file, void *priv,
>  				     struct v4l2_format *f)
>  {
> -	return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
> +	return hantro_try_fmt(file_to_ctx(file), &f->fmt.pix_mp, f->type);
>  }
>  
>  static int vidioc_try_fmt_out_mplane(struct file *file, void *priv,
>  				     struct v4l2_format *f)
>  {
> -	return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
> +	return hantro_try_fmt(file_to_ctx(file), &f->fmt.pix_mp, f->type);
>  }
>  
>  static void
> @@ -648,19 +648,19 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
>  static int
>  vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
>  {
> -	return hantro_set_fmt_out(fh_to_ctx(priv), &f->fmt.pix_mp,
> HANTRO_AUTO_POSTPROC);
> +	return hantro_set_fmt_out(file_to_ctx(file), &f->fmt.pix_mp,
> HANTRO_AUTO_POSTPROC);
>  }
>  
>  static int
>  vidioc_s_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f)
>  {
> -	return hantro_set_fmt_cap(fh_to_ctx(priv), &f->fmt.pix_mp);
> +	return hantro_set_fmt_cap(file_to_ctx(file), &f->fmt.pix_mp);
>  }
>  
>  static int vidioc_g_selection(struct file *file, void *priv,
>  			      struct v4l2_selection *sel)
>  {
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  
>  	/* Crop only supported on source. */
>  	if (!ctx->is_encoder ||
> @@ -691,7 +691,7 @@ static int vidioc_g_selection(struct file *file, void
> *priv,
>  static int vidioc_s_selection(struct file *file, void *priv,
>  			      struct v4l2_selection *sel)
>  {
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  	struct v4l2_rect *rect = &sel->r;
>  	struct vb2_queue *vq;
>  
> @@ -738,7 +738,7 @@ static const struct v4l2_event hantro_eos_event = {
>  static int vidioc_encoder_cmd(struct file *file, void *priv,
>  			      struct v4l2_encoder_cmd *ec)
>  {
> -	struct hantro_ctx *ctx = fh_to_ctx(priv);
> +	struct hantro_ctx *ctx = file_to_ctx(file);
>  	int ret;
>  
>  	ret = v4l2_m2m_ioctl_try_encoder_cmd(file, priv, ec);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-rockchip/attachments/20250811/a8a1968d/attachment-0001.sig>


More information about the Linux-rockchip mailing list