[PATCH] media: tw5864: Reject video standards without capture support

From: Shuo Qin

Date: Wed Dec 02 2026 - 07:04:58 EST


The driver advertises V4L2_STD_ALL, but its format and frame-interval
handlers only support STD_NTSC, STD_PAL and STD_SECAM. For example,
VIDIOC_S_STD with V4L2_STD_PAL_N succeeds and stores STD_INVALID because
the conversion helper has no matching entry. A subsequent VIDIOC_G_FMT
then reaches the WARN in tw5864_fmt_vid_cap(). The extended standards
recognized by the conversion helper also lack complete capture support.

Advertise only the three standard bits that currently map to fully
handled capture modes. Validate the selected mode before changing the
input or programming the decoder, and return -EINVAL for unsupported
modes. Save the corresponding single V4L2 standard so G_STD reports the
mode actually selected from a mask.

Initialize the default standard before publishing the video node, so
early ioctls cannot observe or overwrite partially initialized state.

This completes input validation for the capture path; the older
frameinterval_get() warning changes did not prevent S_STD from accepting
an unsupported mode. Previously accepted but unimplemented modes are now
rejected at S_STD rather than failing later during capture queries.

Link: https://lore.kernel.org/all/20170227203252.3295528-1-arnd@xxxxxxxx/
Fixes: 34d1324edd31 ("[media] pci: Add tw5864 driver")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Shuo Qin <23159100078@xxxxxxxxxxxxxxxxx>
---
drivers/media/pci/tw5864/tw5864-video.c | 31 +++++++++++++++++--------
drivers/media/pci/tw5864/tw5864.h | 2 +-
2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/media/pci/tw5864/tw5864-video.c b/drivers/media/pci/tw5864/tw5864-video.c
index 0a08708e52b08283074db66611969312762182a8..1c7a81bbf60eb10efe109c4fbede723603a144f0 100644
--- a/drivers/media/pci/tw5864/tw5864-video.c
+++ b/drivers/media/pci/tw5864/tw5864-video.c
@@ -633,9 +633,20 @@ static int tw5864_s_std(struct file *file, void *priv, v4l2_std_id std)
struct tw5864_input *input = video_drvdata(file);
struct tw5864_dev *dev = input->root;

- input->v4l2_std = std;
- input->std = tw5864_from_v4l2_std(std);
- tw_indir_writeb(TW5864_INDIR_VIN_E(input->nr), input->std);
+ enum tw5864_vid_std tw_std = tw5864_from_v4l2_std(std);
+
+ switch (tw_std) {
+ case STD_NTSC:
+ case STD_PAL:
+ case STD_SECAM:
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ input->std = tw_std;
+ input->v4l2_std = tw5864_get_v4l2_std(tw_std);
+ tw_indir_writeb(TW5864_INDIR_VIN_E(input->nr), tw_std);
return 0;
}

@@ -1159,13 +1170,6 @@ static int tw5864_video_input_init(struct tw5864_input *input, int video_nr)
input->gop = GOP_SIZE;
input->frame_interval = 1;

- ret = video_register_device(&input->vdev, VFL_TYPE_VIDEO, video_nr);
- if (ret)
- goto free_v4l2_hdl;
-
- dev_info(&input->root->pci->dev, "Registered video device %s\n",
- video_device_node_name(&input->vdev));
-
/*
* Set default video standard. Doesn't matter which, the detected value
* will be found out by VIDIOC_QUERYSTD handler.
@@ -1177,6 +1181,13 @@ static int tw5864_video_input_init(struct tw5864_input *input, int video_nr)
/* to initiate auto format recognition */
tw_indir_writeb(TW5864_INDIR_VIN_F(video_nr), 0xff);

+ ret = video_register_device(&input->vdev, VFL_TYPE_VIDEO, video_nr);
+ if (ret)
+ goto free_v4l2_hdl;
+
+ dev_info(&input->root->pci->dev, "Registered video device %s\n",
+ video_device_node_name(&input->vdev));
+
return 0;

free_v4l2_hdl:
diff --git a/drivers/media/pci/tw5864/tw5864.h b/drivers/media/pci/tw5864/tw5864.h
index 2da5f4215fd90affb571c7de3feaae7959eff8d7..e9e65c0ba02143406b1ff5aa0c545855cdc83a26 100644
--- a/drivers/media/pci/tw5864/tw5864.h
+++ b/drivers/media/pci/tw5864/tw5864.h
@@ -24,7 +24,7 @@

#define PCI_DEVICE_ID_TECHWELL_5864 0x5864

-#define TW5864_NORMS V4L2_STD_ALL
+#define TW5864_NORMS (V4L2_STD_NTSC_M | V4L2_STD_PAL_B | V4L2_STD_SECAM_B)

/* ----------------------------------------------------------- */
/* card configuration */