media: vicodec: Disable (TRY_)DECODER_CMD for the stateless case
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>
Thu, 9 Nov 2023 20:16:37 +0000 (21:16 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 23 Nov 2023 12:41:31 +0000 (13:41 +0100)
The (TRY_)DECODER_CMD ioctls are only useful for stateful decoders and for
stateless decoders that support holding capture buffers (which is not the
case for this driver).

Disable them when registering the stateless decoder.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/test-drivers/vicodec/vicodec-core.c

index 69cbe2c094e149e4a4651786f410f66e4a6785b9..e13f5452b927b45414c433dcc0cfcd1577a85e33 100644 (file)
@@ -1240,6 +1240,12 @@ static int vicodec_decoder_cmd(struct file *file, void *fh,
        struct vicodec_ctx *ctx = file2ctx(file);
        int ret;
 
+       /*
+        * This ioctl should not be used with a stateless codec that doesn't
+        * support holding buffers and the associated flush command.
+        */
+       WARN_ON(ctx->is_stateless);
+
        ret = v4l2_m2m_ioctl_try_decoder_cmd(file, fh, dc);
        if (ret < 0)
                return ret;
@@ -2026,7 +2032,7 @@ static const struct v4l2_m2m_ops m2m_ops = {
 
 static int register_instance(struct vicodec_dev *dev,
                             struct vicodec_dev_instance *dev_instance,
-                            const char *name, bool is_enc)
+                            const char *name, bool is_enc, bool is_stateless)
 {
        struct video_device *vfd;
        int ret;
@@ -2046,10 +2052,11 @@ static int register_instance(struct vicodec_dev *dev,
        strscpy(vfd->name, name, sizeof(vfd->name));
        vfd->device_caps = V4L2_CAP_STREAMING |
                (multiplanar ? V4L2_CAP_VIDEO_M2M_MPLANE : V4L2_CAP_VIDEO_M2M);
-       if (is_enc) {
+       if (is_enc || is_stateless) {
                v4l2_disable_ioctl(vfd, VIDIOC_DECODER_CMD);
                v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
-       } else {
+       }
+       if (!is_enc) {
                v4l2_disable_ioctl(vfd, VIDIOC_ENCODER_CMD);
                v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
        }
@@ -2108,17 +2115,17 @@ static int vicodec_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, dev);
 
        ret = register_instance(dev, &dev->stateful_enc, "stateful-encoder",
-                               true);
+                               true, false);
        if (ret)
                goto unreg_dev;
 
        ret = register_instance(dev, &dev->stateful_dec, "stateful-decoder",
-                               false);
+                               false, false);
        if (ret)
                goto unreg_sf_enc;
 
        ret = register_instance(dev, &dev->stateless_dec, "stateless-decoder",
-                               false);
+                               false, true);
        if (ret)
                goto unreg_sf_dec;