]> www.infradead.org Git - users/hch/misc.git/commitdiff
media: pci: saa7164: Store v4l2_fh pointer in file->private_data
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Sun, 10 Aug 2025 01:29:43 +0000 (04:29 +0300)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Wed, 13 Aug 2025 06:33:20 +0000 (08:33 +0200)
Most V4L2 drivers store the v4l2_fh pointer in file->private_data. The
saa7164 instead stores the pointer to the driver-specific structure that
embeds the v4l2_fh. Switch to storing the v4l2_fh pointer itself to
standardize behaviour across drivers. This also prepares for future
refactoring that depends on v4l2_fh being stored in private_data.

This also fixes a bug in the vidioc_g_std() in saa7164-vbi.c that casts
the private_data void pointer to a saa7164_encoder_fh instead of a
saa7164_vbi_fh. The bug has no practical consequence as the two
structures are identical.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/pci/saa7164/saa7164-encoder.c
drivers/media/pci/saa7164/saa7164-vbi.c
drivers/media/pci/saa7164/saa7164.h

index bf73e9e83f52324ca494816f7d9fa2fae7de6774..296f50b6b8d38e0ab617f0990d8f697ba96b0016 100644 (file)
@@ -219,7 +219,7 @@ int saa7164_s_std(struct saa7164_port *port, v4l2_std_id id)
 
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_s_std(fh->port, id);
 }
@@ -232,7 +232,7 @@ int saa7164_g_std(struct saa7164_port *port, v4l2_std_id *id)
 
 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_g_std(fh->port, id);
 }
@@ -277,7 +277,7 @@ int saa7164_g_input(struct saa7164_port *port, unsigned int *i)
 
 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_g_input(fh->port, i);
 }
@@ -301,14 +301,14 @@ int saa7164_s_input(struct saa7164_port *port, unsigned int i)
 
 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_s_input(fh->port, i);
 }
 
 int saa7164_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_dev *dev = port->dev;
 
@@ -347,7 +347,7 @@ int saa7164_g_frequency(struct saa7164_port *port, struct v4l2_frequency *f)
 static int vidioc_g_frequency(struct file *file, void *priv,
        struct v4l2_frequency *f)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_g_frequency(fh->port, f);
 }
@@ -400,7 +400,7 @@ int saa7164_s_frequency(struct saa7164_port *port,
 static int vidioc_s_frequency(struct file *file, void *priv,
                              const struct v4l2_frequency *f)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
 
        return saa7164_s_frequency(fh->port, f);
 }
@@ -483,7 +483,7 @@ static int saa7164_s_ctrl(struct v4l2_ctrl *ctrl)
 static int vidioc_querycap(struct file *file, void  *priv,
        struct v4l2_capability *cap)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_dev *dev = port->dev;
 
@@ -510,7 +510,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
 static int vidioc_fmt_vid_cap(struct file *file, void *priv,
                                struct v4l2_format *f)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
 
        f->fmt.pix.pixelformat  = V4L2_PIX_FMT_MPEG;
@@ -726,14 +726,14 @@ static int fops_open(struct file *file)
        fh->port = port;
        v4l2_fh_init(&fh->fh, video_devdata(file));
        v4l2_fh_add(&fh->fh);
-       file->private_data = fh;
+       file->private_data = &fh->fh;
 
        return 0;
 }
 
 static int fops_release(struct file *file)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_dev *dev = port->dev;
 
@@ -787,7 +787,7 @@ saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
 static ssize_t fops_read(struct file *file, char __user *buffer,
        size_t count, loff_t *pos)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_user_buffer *ubuf = NULL;
        struct saa7164_dev *dev = port->dev;
@@ -893,8 +893,7 @@ err:
 static __poll_t fops_poll(struct file *file, poll_table *wait)
 {
        __poll_t req_events = poll_requested_events(wait);
-       struct saa7164_encoder_fh *fh =
-               (struct saa7164_encoder_fh *)file->private_data;
+       struct saa7164_encoder_fh *fh = to_saa7164_encoder_fh(file);
        struct saa7164_port *port = fh->port;
        __poll_t mask = v4l2_ctrl_poll(file, wait);
 
index ac958a5fca78e5094d7befd8c125fa4233bb6999..a7e398f304725c7fa5aa4cf1edf0deb0df059641 100644 (file)
@@ -144,28 +144,28 @@ static int saa7164_vbi_initialize(struct saa7164_port *port)
 /* -- V4L2 --------------------------------------------------------- */
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
 
        return saa7164_s_std(fh->port->enc_port, id);
 }
 
 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
 {
-       struct saa7164_encoder_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
 
        return saa7164_g_std(fh->port->enc_port, id);
 }
 
 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
 
        return saa7164_g_input(fh->port->enc_port, i);
 }
 
 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
 
        return saa7164_s_input(fh->port->enc_port, i);
 }
@@ -173,7 +173,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 static int vidioc_g_frequency(struct file *file, void *priv,
        struct v4l2_frequency *f)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
 
        return saa7164_g_frequency(fh->port->enc_port, f);
 }
@@ -181,7 +181,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
        const struct v4l2_frequency *f)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
        int ret = saa7164_s_frequency(fh->port->enc_port, f);
 
        if (ret == 0)
@@ -192,7 +192,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_querycap(struct file *file, void  *priv,
        struct v4l2_capability *cap)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_dev *dev = port->dev;
 
@@ -429,14 +429,14 @@ static int fops_open(struct file *file)
        fh->port = port;
        v4l2_fh_init(&fh->fh, video_devdata(file));
        v4l2_fh_add(&fh->fh);
-       file->private_data = fh;
+       file->private_data = &fh->fh;
 
        return 0;
 }
 
 static int fops_release(struct file *file)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_dev *dev = port->dev;
 
@@ -489,7 +489,7 @@ saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
 static ssize_t fops_read(struct file *file, char __user *buffer,
        size_t count, loff_t *pos)
 {
-       struct saa7164_vbi_fh *fh = file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
        struct saa7164_port *port = fh->port;
        struct saa7164_user_buffer *ubuf = NULL;
        struct saa7164_dev *dev = port->dev;
@@ -596,7 +596,7 @@ err:
 
 static __poll_t fops_poll(struct file *file, poll_table *wait)
 {
-       struct saa7164_vbi_fh *fh = (struct saa7164_vbi_fh *)file->private_data;
+       struct saa7164_vbi_fh *fh = to_saa7164_vbi_fh(file);
        struct saa7164_port *port = fh->port;
        __poll_t mask = 0;
 
index e1bac1fe19d3098792b2051b537857e3f13054d5..7b511f7f1cfc305a9ffe60722b9ebe093163787d 100644 (file)
@@ -180,12 +180,22 @@ struct saa7164_encoder_fh {
        atomic_t v4l_reading;
 };
 
+static inline struct saa7164_encoder_fh *to_saa7164_encoder_fh(struct file *filp)
+{
+       return container_of(filp->private_data, struct saa7164_encoder_fh, fh);
+}
+
 struct saa7164_vbi_fh {
        struct v4l2_fh fh;
        struct saa7164_port *port;
        atomic_t v4l_reading;
 };
 
+static inline struct saa7164_vbi_fh *to_saa7164_vbi_fh(struct file *filp)
+{
+       return container_of(filp->private_data, struct saa7164_vbi_fh, fh);
+}
+
 struct saa7164_histogram_bucket {
        u32 val;
        u32 count;