97ca47bcd0577ae04c18b850d1633785f93eeced
[openwrt/staging/adrian.git] /
1 From 9ecf10bfe3e501b10cc72d710a70150640a0b266 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 1 May 2020 16:54:20 +0100
4 Subject: [PATCH] staging: vc04_services: isp: Make all references to
5 bcm2835_isp_fmt const
6
7 The array of potential formats and their configuration should be const.
8 Rework all accesses so that this is possible.
9
10 The list of supported formats was taking a copy of entries from this table.
11 This is unnecessary, therefore allocate an array of pointers instead of
12 an array of entries.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 ---
16 .../bcm2835-isp/bcm2835-v4l2-isp.c | 34 ++++++++++---------
17 .../bcm2835-isp/bcm2835_isp_fmts.h | 2 +-
18 2 files changed, 19 insertions(+), 17 deletions(-)
19
20 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
21 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
22 @@ -67,7 +67,7 @@ struct bcm2835_isp_q_data {
23 unsigned int width;
24 unsigned int height;
25 unsigned int sizeimage;
26 - struct bcm2835_isp_fmt *fmt;
27 + const struct bcm2835_isp_fmt *fmt;
28 };
29
30 /*
31 @@ -232,11 +232,11 @@ struct bcm2835_isp_fmt *find_format_by_f
32 struct bcm2835_isp_node *node)
33 {
34 struct bcm2835_isp_fmt_list *fmts = &node->supported_fmts;
35 - struct bcm2835_isp_fmt *fmt;
36 + const struct bcm2835_isp_fmt *fmt;
37 unsigned int i;
38
39 for (i = 0; i < fmts->num_entries; i++) {
40 - fmt = &fmts->list[i];
41 + fmt = fmts->list[i];
42 if (fmt->fourcc == fourcc)
43 return fmt;
44 }
45 @@ -244,8 +244,9 @@ struct bcm2835_isp_fmt *find_format_by_f
46 return NULL;
47 }
48
49 -static struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
50 - struct bcm2835_isp_node *node)
51 +static const
52 +struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
53 + struct bcm2835_isp_node *node)
54 {
55 return find_format_by_fourcc(node_is_stats(node) ?
56 f->fmt.meta.dataformat :
57 @@ -666,19 +667,20 @@ static const struct vb2_ops bcm2835_isp_
58 .stop_streaming = bcm2835_isp_node_stop_streaming,
59 };
60
61 -static struct bcm2835_isp_fmt *get_default_format(struct bcm2835_isp_node *node)
62 +static const
63 +struct bcm2835_isp_fmt *get_default_format(struct bcm2835_isp_node *node)
64 {
65 - return &node->supported_fmts.list[0];
66 + return node->supported_fmts.list[0];
67 }
68
69 static inline unsigned int get_bytesperline(int width,
70 - struct bcm2835_isp_fmt *fmt)
71 + const struct bcm2835_isp_fmt *fmt)
72 {
73 return ALIGN((width * fmt->depth) >> 3, fmt->bytesperline_align);
74 }
75
76 static inline unsigned int get_sizeimage(int bpl, int width, int height,
77 - struct bcm2835_isp_fmt *fmt)
78 + const struct bcm2835_isp_fmt *fmt)
79 {
80 return (bpl * height * fmt->size_multiplier_x2) >> 1;
81 }
82 @@ -892,8 +894,8 @@ static int bcm2835_isp_node_enum_fmt(str
83
84 if (f->index < fmts->num_entries) {
85 /* Format found */
86 - f->pixelformat = fmts->list[f->index].fourcc;
87 - f->flags = fmts->list[f->index].flags;
88 + f->pixelformat = fmts->list[f->index]->fourcc;
89 + f->flags = fmts->list[f->index]->flags;
90 return 0;
91 }
92
93 @@ -905,7 +907,7 @@ static int bcm2835_isp_enum_framesizes(s
94 {
95 struct bcm2835_isp_node *node = video_drvdata(file);
96 struct bcm2835_isp_dev *dev = node_get_dev(node);
97 - struct bcm2835_isp_fmt *fmt;
98 + const struct bcm2835_isp_fmt *fmt;
99
100 if (node_is_stats(node) || fsize->index)
101 return -EINVAL;
102 @@ -933,7 +935,7 @@ static int bcm2835_isp_node_try_fmt(stru
103 struct v4l2_format *f)
104 {
105 struct bcm2835_isp_node *node = video_drvdata(file);
106 - struct bcm2835_isp_fmt *fmt;
107 + const struct bcm2835_isp_fmt *fmt;
108
109 if (f->type != node->queue.type)
110 return -EINVAL;
111 @@ -1113,7 +1115,7 @@ static const struct v4l2_ioctl_ops bcm28
112 static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node)
113 {
114 struct bcm2835_isp_dev *dev = node_get_dev(node);
115 - struct bcm2835_isp_fmt *list;
116 + struct bcm2835_isp_fmt const **list;
117 unsigned int i, j, num_encodings;
118 u32 fourccs[MAX_SUPPORTED_ENCODINGS];
119 u32 param_size = sizeof(fourccs);
120 @@ -1144,7 +1146,7 @@ static int bcm2835_isp_get_supported_fmt
121 * Any that aren't supported will waste a very small amount of memory.
122 */
123 list = devm_kzalloc(dev->dev,
124 - sizeof(struct bcm2835_isp_fmt) * num_encodings,
125 + sizeof(struct bcm2835_isp_fmt *) * num_encodings,
126 GFP_KERNEL);
127 if (!list)
128 return -ENOMEM;
129 @@ -1154,7 +1156,7 @@ static int bcm2835_isp_get_supported_fmt
130 const struct bcm2835_isp_fmt *fmt = get_fmt(fourccs[i]);
131
132 if (fmt) {
133 - list[j] = *fmt;
134 + list[j] = fmt;
135 j++;
136 }
137 }
138 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835_isp_fmts.h
139 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835_isp_fmts.h
140 @@ -26,7 +26,7 @@ struct bcm2835_isp_fmt {
141 };
142
143 struct bcm2835_isp_fmt_list {
144 - struct bcm2835_isp_fmt *list;
145 + struct bcm2835_isp_fmt const **list;
146 unsigned int num_entries;
147 };
148