Skip to content

Commit 1f65ea4

Browse files
Hans Verkuilmchehab
authored andcommitted
media: vivid: dev->bitmap_cap wasn't freed in all cases
Whenever the compose width/height values change, the dev->bitmap_cap vmalloc'ed array must be freed and dev->bitmap_cap set to NULL. This was done in some places, but not all. This is only an issue if overlay support is enabled and the bitmap clipping is used. Signed-off-by: Hans Verkuil <[email protected]> Fixes: ef834f7 ([media] vivid: add the video capture and output parts) Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent f8bcaf7 commit 1f65ea4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/media/test-drivers/vivid/vivid-vid-cap.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls)
453453
tpg_reset_source(&dev->tpg, dev->src_rect.width, dev->src_rect.height, dev->field_cap);
454454
dev->crop_cap = dev->src_rect;
455455
dev->crop_bounds_cap = dev->src_rect;
456+
if (dev->bitmap_cap &&
457+
(dev->compose_cap.width != dev->crop_cap.width ||
458+
dev->compose_cap.height != dev->crop_cap.height)) {
459+
vfree(dev->bitmap_cap);
460+
dev->bitmap_cap = NULL;
461+
}
456462
dev->compose_cap = dev->crop_cap;
457463
if (V4L2_FIELD_HAS_T_OR_B(dev->field_cap))
458464
dev->compose_cap.height /= 2;
@@ -913,6 +919,8 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
913919
struct vivid_dev *dev = video_drvdata(file);
914920
struct v4l2_rect *crop = &dev->crop_cap;
915921
struct v4l2_rect *compose = &dev->compose_cap;
922+
unsigned orig_compose_w = compose->width;
923+
unsigned orig_compose_h = compose->height;
916924
unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_cap) ? 2 : 1;
917925
int ret;
918926

@@ -1029,17 +1037,17 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
10291037
s->r.height /= factor;
10301038
}
10311039
v4l2_rect_map_inside(&s->r, &dev->fmt_cap_rect);
1032-
if (dev->bitmap_cap && (compose->width != s->r.width ||
1033-
compose->height != s->r.height)) {
1034-
vfree(dev->bitmap_cap);
1035-
dev->bitmap_cap = NULL;
1036-
}
10371040
*compose = s->r;
10381041
break;
10391042
default:
10401043
return -EINVAL;
10411044
}
10421045

1046+
if (dev->bitmap_cap && (compose->width != orig_compose_w ||
1047+
compose->height != orig_compose_h)) {
1048+
vfree(dev->bitmap_cap);
1049+
dev->bitmap_cap = NULL;
1050+
}
10431051
tpg_s_crop_compose(&dev->tpg, crop, compose);
10441052
return 0;
10451053
}

0 commit comments

Comments
 (0)