OSDN Git Service

media: allegro: warn if response message has an unexpected size
authorMichael Tretter <m.tretter@pengutronix.de>
Mon, 16 Mar 2020 15:26:29 +0000 (16:26 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Fri, 20 Mar 2020 08:18:33 +0000 (09:18 +0100)
The driver uses structs to parse the responses from the VCU and expects
a certain size of the responses. However, the size and format of the
mails is not stable across firmware versions. Therefore, print a warning
if the size does not match the expected size to warn the user that
strange things might happen.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/allegro-dvt/allegro-core.c

index d8f0fe1..8321b1e 100644 (file)
@@ -1711,6 +1711,12 @@ allegro_handle_create_channel(struct allegro_dev *dev,
        struct allegro_channel *channel;
        int err = 0;
 
+       if (msg->header.length != sizeof(*msg) - sizeof(msg->header))
+               v4l2_warn(&dev->v4l2_dev,
+                         "received message has %d bytes, but expected %zu\n",
+                         msg->header.length,
+                         sizeof(*msg) - sizeof(msg->header));
+
        channel = allegro_find_channel_by_user_id(dev, msg->user_id);
        if (IS_ERR(channel)) {
                v4l2_warn(&dev->v4l2_dev,
@@ -1804,6 +1810,12 @@ allegro_handle_encode_frame(struct allegro_dev *dev,
 {
        struct allegro_channel *channel;
 
+       if (msg->header.length != sizeof(*msg) - sizeof(msg->header))
+               v4l2_warn(&dev->v4l2_dev,
+                         "received message has %d bytes, but expected %zu\n",
+                         msg->header.length,
+                         sizeof(*msg) - sizeof(msg->header));
+
        channel = allegro_find_channel_by_channel_id(dev, msg->channel_id);
        if (IS_ERR(channel)) {
                v4l2_err(&dev->v4l2_dev,