]> www.infradead.org Git - users/hch/misc.git/commitdiff
media: s5p-mfc: Access v4l2_fh from file
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>
Sun, 10 Aug 2025 01:30:40 +0000 (04:30 +0300)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Wed, 13 Aug 2025 06:33:53 +0000 (08:33 +0200)
The v4l2_fh associated with an open file handle is now guaranteed
to be available in file->private_data, initialised by v4l2_fh_add().

Access the v4l2_fh, and from there the driver-specific structure,
from the file * in all ioctl handlers.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c

index a29228b4207f3e02d09043a9d418811febefbe94..58dc1768082c5d42e2d8791e1c4a78b8d4ff39e7 100644 (file)
@@ -767,11 +767,9 @@ struct mfc_control {
 #define s5p_mfc_hw_call(f, op, args...) \
        ((f && f->op) ? f->op(args) : (typeof(f->op(args)))(-ENODEV))
 
-#define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
-
 static inline struct s5p_mfc_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 s5p_mfc_ctx, fh);
 }
 
 #define ctrl_to_ctx(__ctrl) \
index aefa6da5c609621c896f1fa14fd53b75ca60eabc..606e1a7121b5fe1698724c613beb0e8e12411a69 100644 (file)
@@ -345,7 +345,7 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
 /* Get format */
 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        struct v4l2_pix_format_mplane *pix_mp;
 
        mfc_debug_enter();
@@ -442,7 +442,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
 static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
        struct s5p_mfc_dev *dev = video_drvdata(file);
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret = 0;
        struct v4l2_pix_format_mplane *pix_mp;
        const struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
@@ -598,7 +598,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
                                          struct v4l2_requestbuffers *reqbufs)
 {
        struct s5p_mfc_dev *dev = video_drvdata(file);
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (reqbufs->memory != V4L2_MEMORY_MMAP) {
                mfc_debug(2, "Only V4L2_MEMORY_MMAP is supported\n");
@@ -619,7 +619,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 static int vidioc_querybuf(struct file *file, void *priv,
                                                   struct v4l2_buffer *buf)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret;
        int i;
 
@@ -647,7 +647,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
 /* Queue a buffer */
 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (ctx->state == MFCINST_ERROR) {
                mfc_err("Call on QBUF after unrecoverable error\n");
@@ -666,7 +666,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
        const struct v4l2_event ev = {
                .type = V4L2_EVENT_EOS
        };
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret;
 
        if (ctx->state == MFCINST_ERROR) {
@@ -695,7 +695,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 static int vidioc_expbuf(struct file *file, void *priv,
        struct v4l2_exportbuffer *eb)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                return vb2_expbuf(&ctx->vq_src, eb);
@@ -708,7 +708,7 @@ static int vidioc_expbuf(struct file *file, void *priv,
 static int vidioc_streamon(struct file *file, void *priv,
                           enum v4l2_buf_type type)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret = -EINVAL;
 
        mfc_debug_enter();
@@ -724,7 +724,7 @@ static int vidioc_streamon(struct file *file, void *priv,
 static int vidioc_streamoff(struct file *file, void *priv,
                            enum v4l2_buf_type type)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                return vb2_streamoff(&ctx->vq_src, type);
@@ -801,7 +801,7 @@ static const struct v4l2_ctrl_ops s5p_mfc_dec_ctrl_ops = {
 static int vidioc_g_selection(struct file *file, void *priv,
                              struct v4l2_selection *s)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        struct s5p_mfc_dev *dev = ctx->dev;
        u32 left, right, top, bottom;
        u32 width, height;
@@ -856,7 +856,7 @@ static int vidioc_g_selection(struct file *file, void *priv,
 static int vidioc_decoder_cmd(struct file *file, void *priv,
                              struct v4l2_decoder_cmd *cmd)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        struct s5p_mfc_dev *dev = ctx->dev;
        struct s5p_mfc_buf *buf;
        unsigned long flags;
index 9b77dbd856e7935c186f52ac21162e7d8bb2a215..694b68788a953dcbb86d30978da07aa8bc122bc3 100644 (file)
@@ -1389,8 +1389,8 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
 
 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
        struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        mfc_debug(2, "f->type = %d ctx->state = %d\n", f->type, ctx->state);
        if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
@@ -1472,8 +1472,8 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
 
 static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        struct s5p_mfc_dev *dev = video_drvdata(file);
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
        struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
        int ret = 0;
 
@@ -1531,7 +1531,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
                                          struct v4l2_requestbuffers *reqbufs)
 {
        struct s5p_mfc_dev *dev = video_drvdata(file);
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret = 0;
 
        /* if memory is not mmp or userptr or dmabuf return error */
@@ -1601,7 +1601,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 static int vidioc_querybuf(struct file *file, void *priv,
                                                   struct v4l2_buffer *buf)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        int ret = 0;
 
        /* if memory is not mmp or userptr or dmabuf return error */
@@ -1636,7 +1636,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
 /* Queue a buffer */
 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (ctx->state == MFCINST_ERROR) {
                mfc_err("Call on QBUF after unrecoverable error\n");
@@ -1657,10 +1657,10 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 /* Dequeue a buffer */
 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 {
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        const struct v4l2_event ev = {
                .type = V4L2_EVENT_EOS
        };
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
        int ret;
 
        if (ctx->state == MFCINST_ERROR) {
@@ -1685,7 +1685,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 static int vidioc_expbuf(struct file *file, void *priv,
        struct v4l2_exportbuffer *eb)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                return vb2_expbuf(&ctx->vq_src, eb);
@@ -1698,7 +1698,7 @@ static int vidioc_expbuf(struct file *file, void *priv,
 static int vidioc_streamon(struct file *file, void *priv,
                           enum v4l2_buf_type type)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                return vb2_streamon(&ctx->vq_src, type);
@@ -1711,7 +1711,7 @@ static int vidioc_streamon(struct file *file, void *priv,
 static int vidioc_streamoff(struct file *file, void *priv,
                            enum v4l2_buf_type type)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
                return vb2_streamoff(&ctx->vq_src, type);
@@ -2284,7 +2284,7 @@ static const struct v4l2_ctrl_ops s5p_mfc_enc_ctrl_ops = {
 static int vidioc_s_parm(struct file *file, void *priv,
                         struct v4l2_streamparm *a)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                ctx->enc_params.rc_framerate_num =
@@ -2301,7 +2301,7 @@ static int vidioc_s_parm(struct file *file, void *priv,
 static int vidioc_g_parm(struct file *file, void *priv,
                         struct v4l2_streamparm *a)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
 
        if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
                a->parm.output.timeperframe.denominator =
@@ -2318,7 +2318,7 @@ static int vidioc_g_parm(struct file *file, void *priv,
 static int vidioc_encoder_cmd(struct file *file, void *priv,
                              struct v4l2_encoder_cmd *cmd)
 {
-       struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
+       struct s5p_mfc_ctx *ctx = file_to_ctx(file);
        struct s5p_mfc_dev *dev = ctx->dev;
        struct s5p_mfc_buf *buf;
        unsigned long flags;