bcm27xx: update 6.1 patches to latest version
[openwrt/staging/svanheule.git] / target / linux / bcm27xx / patches-6.1 / 950-1212-media-rp1-cfe-Improve-link-validation-for-metadata.patch
1 From e0f52ccfe1e383622fb30708acd38921e84fbff4 Mon Sep 17 00:00:00 2001
2 From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
3 Date: Tue, 3 Oct 2023 14:29:44 +0300
4 Subject: [PATCH] media: rp1: cfe: Improve link validation for metadata
5
6 Improve the link validation for metadata by:
7 - Allowing capture buffers that are larger than the incoming frame
8 (instead of requiring exact match).
9
10 - Instead of assuming that a metadata unit ("pixel") is 8 bits, use
11 find_format_by_code() to get the format and use the bit depth from
12 there. E.g. bit depth for RAW10 metadata will be 10 bits, when we
13 move to the upstream metadata formats.
14
15 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
16 ---
17 .../media/platform/raspberrypi/rp1_cfe/cfe.c | 32 +++++++++++++------
18 1 file changed, 22 insertions(+), 10 deletions(-)
19
20 --- a/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
21 +++ b/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
22 @@ -1715,17 +1715,29 @@ static int cfe_video_link_validate(struc
23 }
24 } else if (is_csi2_node(node) && is_meta_output_node(node)) {
25 struct v4l2_meta_format *meta_fmt = &node->meta_fmt.fmt.meta;
26 + const struct cfe_fmt *fmt;
27 + u32 source_size;
28
29 - if (source_fmt->width * source_fmt->height !=
30 - meta_fmt->buffersize ||
31 - source_fmt->code != MEDIA_BUS_FMT_SENSOR_DATA) {
32 - cfe_err("WARNING: Wrong metadata width/height/code %ux%u %08x (remote pad set to %ux%u %08x)\n",
33 - meta_fmt->buffersize, 1,
34 - MEDIA_BUS_FMT_SENSOR_DATA,
35 - source_fmt->width,
36 - source_fmt->height,
37 - source_fmt->code);
38 - /* TODO: this should throw an error eventually */
39 + fmt = find_format_by_code(source_fmt->code);
40 + if (!fmt || fmt->fourcc != meta_fmt->dataformat) {
41 + cfe_err("Metadata format mismatch!\n");
42 + ret = -EINVAL;
43 + goto out;
44 + }
45 +
46 + source_size = DIV_ROUND_UP(source_fmt->width * source_fmt->height * fmt->depth, 8);
47 +
48 + if (source_fmt->code != MEDIA_BUS_FMT_SENSOR_DATA) {
49 + cfe_err("Bad metadata mbus format\n");
50 + ret = -EINVAL;
51 + goto out;
52 + }
53 +
54 + if (source_size > meta_fmt->buffersize) {
55 + cfe_err("Metadata buffer too small: %u < %u\n",
56 + meta_fmt->buffersize, source_size);
57 + ret = -EINVAL;
58 + goto out;
59 }
60 }
61