Skip to content

Commit 6c3505b

Browse files
6by9pelwell
authored andcommitted
staging: vc04_services: isp: Make all references to bcm2835_isp_fmt const
The array of potential formats and their configuration should be const. Rework all accesses so that this is possible. The list of supported formats was taking a copy of entries from this table. This is unnecessary, therefore allocate an array of pointers instead of an array of entries. Signed-off-by: Dave Stevenson <[email protected]>
1 parent 375920f commit 6c3505b

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct bcm2835_isp_q_data {
6767
unsigned int width;
6868
unsigned int height;
6969
unsigned int sizeimage;
70-
struct bcm2835_isp_fmt *fmt;
70+
const struct bcm2835_isp_fmt *fmt;
7171
};
7272

7373
/*
@@ -232,20 +232,21 @@ struct bcm2835_isp_fmt *find_format_by_fourcc(unsigned int fourcc,
232232
struct bcm2835_isp_node *node)
233233
{
234234
struct bcm2835_isp_fmt_list *fmts = &node->supported_fmts;
235-
struct bcm2835_isp_fmt *fmt;
235+
const struct bcm2835_isp_fmt *fmt;
236236
unsigned int i;
237237

238238
for (i = 0; i < fmts->num_entries; i++) {
239-
fmt = &fmts->list[i];
239+
fmt = fmts->list[i];
240240
if (fmt->fourcc == fourcc)
241241
return fmt;
242242
}
243243

244244
return NULL;
245245
}
246246

247-
static struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
248-
struct bcm2835_isp_node *node)
247+
static const
248+
struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
249+
struct bcm2835_isp_node *node)
249250
{
250251
return find_format_by_fourcc(node_is_stats(node) ?
251252
f->fmt.meta.dataformat :
@@ -666,19 +667,20 @@ static const struct vb2_ops bcm2835_isp_node_queue_ops = {
666667
.stop_streaming = bcm2835_isp_node_stop_streaming,
667668
};
668669

669-
static struct bcm2835_isp_fmt *get_default_format(struct bcm2835_isp_node *node)
670+
static const
671+
struct bcm2835_isp_fmt *get_default_format(struct bcm2835_isp_node *node)
670672
{
671-
return &node->supported_fmts.list[0];
673+
return node->supported_fmts.list[0];
672674
}
673675

674676
static inline unsigned int get_bytesperline(int width,
675-
struct bcm2835_isp_fmt *fmt)
677+
const struct bcm2835_isp_fmt *fmt)
676678
{
677679
return ALIGN((width * fmt->depth) >> 3, fmt->bytesperline_align);
678680
}
679681

680682
static inline unsigned int get_sizeimage(int bpl, int width, int height,
681-
struct bcm2835_isp_fmt *fmt)
683+
const struct bcm2835_isp_fmt *fmt)
682684
{
683685
return (bpl * height * fmt->size_multiplier_x2) >> 1;
684686
}
@@ -892,8 +894,8 @@ static int bcm2835_isp_node_enum_fmt(struct file *file, void *priv,
892894

893895
if (f->index < fmts->num_entries) {
894896
/* Format found */
895-
f->pixelformat = fmts->list[f->index].fourcc;
896-
f->flags = fmts->list[f->index].flags;
897+
f->pixelformat = fmts->list[f->index]->fourcc;
898+
f->flags = fmts->list[f->index]->flags;
897899
return 0;
898900
}
899901

@@ -905,7 +907,7 @@ static int bcm2835_isp_enum_framesizes(struct file *file, void *priv,
905907
{
906908
struct bcm2835_isp_node *node = video_drvdata(file);
907909
struct bcm2835_isp_dev *dev = node_get_dev(node);
908-
struct bcm2835_isp_fmt *fmt;
910+
const struct bcm2835_isp_fmt *fmt;
909911

910912
if (node_is_stats(node) || fsize->index)
911913
return -EINVAL;
@@ -933,7 +935,7 @@ static int bcm2835_isp_node_try_fmt(struct file *file, void *priv,
933935
struct v4l2_format *f)
934936
{
935937
struct bcm2835_isp_node *node = video_drvdata(file);
936-
struct bcm2835_isp_fmt *fmt;
938+
const struct bcm2835_isp_fmt *fmt;
937939

938940
if (f->type != node->queue.type)
939941
return -EINVAL;
@@ -1113,7 +1115,7 @@ static const struct v4l2_ioctl_ops bcm2835_isp_node_ioctl_ops = {
11131115
static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node)
11141116
{
11151117
struct bcm2835_isp_dev *dev = node_get_dev(node);
1116-
struct bcm2835_isp_fmt *list;
1118+
struct bcm2835_isp_fmt const **list;
11171119
unsigned int i, j, num_encodings;
11181120
u32 fourccs[MAX_SUPPORTED_ENCODINGS];
11191121
u32 param_size = sizeof(fourccs);
@@ -1144,7 +1146,7 @@ static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node)
11441146
* Any that aren't supported will waste a very small amount of memory.
11451147
*/
11461148
list = devm_kzalloc(dev->dev,
1147-
sizeof(struct bcm2835_isp_fmt) * num_encodings,
1149+
sizeof(struct bcm2835_isp_fmt *) * num_encodings,
11481150
GFP_KERNEL);
11491151
if (!list)
11501152
return -ENOMEM;
@@ -1154,7 +1156,7 @@ static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node)
11541156
const struct bcm2835_isp_fmt *fmt = get_fmt(fourccs[i]);
11551157

11561158
if (fmt) {
1157-
list[j] = *fmt;
1159+
list[j] = fmt;
11581160
j++;
11591161
}
11601162
}

drivers/staging/vc04_services/bcm2835-isp/bcm2835_isp_fmts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct bcm2835_isp_fmt {
2626
};
2727

2828
struct bcm2835_isp_fmt_list {
29-
struct bcm2835_isp_fmt *list;
29+
struct bcm2835_isp_fmt const **list;
3030
unsigned int num_entries;
3131
};
3232

0 commit comments

Comments
 (0)