aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2016-08-05 16:07:55 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2016-08-05 16:52:12 +0200
commita6ad050d83d782e8ada7766f8c3b1d5768d007d2 (patch)
tree93a9833e6e6bba66ef211842300698bfaa6bec41
parent9d7ca2cfd8c5c13012768ef8e9b1f3a1339cd757 (diff)
vivid: don't return ERANGE if S_SELECTION hints don't workselection
The V4L2_SEL_FLAG_LE/GE flags are hints and should not result in an error. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
-rw-r--r--drivers/media/platform/vivid/vivid-vid-cap.c9
-rw-r--r--drivers/media/platform/vivid/vivid-vid-common.c33
-rw-r--r--drivers/media/platform/vivid/vivid-vid-common.h2
-rw-r--r--drivers/media/platform/vivid/vivid-vid-out.c9
4 files changed, 10 insertions, 43 deletions
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index d404a7ce33a4..1198cd4122c4 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -865,7 +865,6 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
struct v4l2_rect *crop = &dev->crop_cap;
struct v4l2_rect *compose = &dev->compose_cap;
unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_cap) ? 2 : 1;
- int ret;
if (!dev->has_crop_cap && !dev->has_compose_cap)
return -ENOTTY;
@@ -878,9 +877,7 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
case V4L2_SEL_TGT_CROP:
if (!dev->has_crop_cap)
return -EINVAL;
- ret = vivid_vid_adjust_sel(s->flags, &s->r);
- if (ret)
- return ret;
+ vivid_vid_adjust_sel(s->flags, &s->r);
v4l2_rect_set_min_size(&s->r, &vivid_min_rect);
v4l2_rect_set_max_size(&s->r, &dev->src_rect);
v4l2_rect_map_inside(&s->r, &dev->crop_bounds_cap);
@@ -938,9 +935,7 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
case V4L2_SEL_TGT_COMPOSE:
if (!dev->has_compose_cap)
return -EINVAL;
- ret = vivid_vid_adjust_sel(s->flags, &s->r);
- if (ret)
- return ret;
+ vivid_vid_adjust_sel(s->flags, &s->r);
v4l2_rect_set_min_size(&s->r, &vivid_min_rect);
v4l2_rect_set_max_size(&s->r, &dev->fmt_cap_rect);
if (dev->has_scaler_cap) {
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index fcda3ae4e6b0..471605d72184 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -653,34 +653,16 @@ int fmt_sp2mp_func(struct file *file, void *priv,
return ret;
}
-int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r)
+void vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r)
{
unsigned w = r->width;
unsigned h = r->height;
/* sanitize w and h in case someone passes ~0 as the value */
- w &= 0xffff;
- h &= 0xffff;
- if (!(flags & V4L2_SEL_FLAG_LE)) {
- w++;
- h++;
- if (w < 2)
- w = 2;
- if (h < 2)
- h = 2;
- }
- if (!(flags & V4L2_SEL_FLAG_GE)) {
- if (w > MAX_WIDTH)
- w = MAX_WIDTH;
- if (h > MAX_HEIGHT)
- h = MAX_HEIGHT;
- }
- w = w & ~1;
- h = h & ~1;
- if (w < 2 || h < 2)
- return -ERANGE;
- if (w > MAX_WIDTH || h > MAX_HEIGHT)
- return -ERANGE;
+ w &= 0xfffe;
+ h &= 0xfffe;
+ w = clamp_t(unsigned, w, 2, MAX_WIDTH);
+ h = clamp_t(unsigned, h, 2, MAX_HEIGHT);
if (r->top < 0)
r->top = 0;
if (r->left < 0)
@@ -692,13 +674,8 @@ int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r)
r->left = MAX_WIDTH - w;
if (r->top + h > MAX_HEIGHT)
r->top = MAX_HEIGHT - h;
- if ((flags & (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE)) ==
- (V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE) &&
- (r->width != w || r->height != h))
- return -ERANGE;
r->width = w;
r->height = h;
- return 0;
}
int vivid_enum_fmt_vid(struct file *file, void *priv,
diff --git a/drivers/media/platform/vivid/vivid-vid-common.h b/drivers/media/platform/vivid/vivid-vid-common.h
index 4b6175eab8a2..1c4680aa8c48 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.h
+++ b/drivers/media/platform/vivid/vivid-vid-common.h
@@ -37,7 +37,7 @@ const struct vivid_fmt *vivid_get_format(struct vivid_dev *dev, u32 pixelformat)
bool vivid_vid_can_loop(struct vivid_dev *dev);
void vivid_send_source_change(struct vivid_dev *dev, unsigned type);
-int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r);
+void vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r);
int vivid_enum_fmt_vid(struct file *file, void *priv, struct v4l2_fmtdesc *f);
int vidioc_enum_fmt_vid_mplane(struct file *file, void *priv, struct v4l2_fmtdesc *f);
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index dd609eea4753..0636a5e2cd0d 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -665,7 +665,6 @@ int vivid_vid_out_s_selection(struct file *file, void *fh, struct v4l2_selection
struct v4l2_rect *crop = &dev->crop_out;
struct v4l2_rect *compose = &dev->compose_out;
unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_out) ? 2 : 1;
- int ret;
if (!dev->has_crop_out && !dev->has_compose_out)
return -ENOTTY;
@@ -676,9 +675,7 @@ int vivid_vid_out_s_selection(struct file *file, void *fh, struct v4l2_selection
case V4L2_SEL_TGT_CROP:
if (!dev->has_crop_out)
return -EINVAL;
- ret = vivid_vid_adjust_sel(s->flags, &s->r);
- if (ret)
- return ret;
+ vivid_vid_adjust_sel(s->flags, &s->r);
v4l2_rect_set_min_size(&s->r, &vivid_min_rect);
v4l2_rect_set_max_size(&s->r, &dev->fmt_out_rect);
if (dev->has_scaler_out) {
@@ -723,9 +720,7 @@ int vivid_vid_out_s_selection(struct file *file, void *fh, struct v4l2_selection
case V4L2_SEL_TGT_COMPOSE:
if (!dev->has_compose_out)
return -EINVAL;
- ret = vivid_vid_adjust_sel(s->flags, &s->r);
- if (ret)
- return ret;
+ vivid_vid_adjust_sel(s->flags, &s->r);
v4l2_rect_set_min_size(&s->r, &vivid_min_rect);
v4l2_rect_set_max_size(&s->r, &dev->sink_rect);
v4l2_rect_map_inside(&s->r, &dev->compose_bounds_out);

Privacy Policy