Re: [PATCH] v4l2: Support for multiple selections

2013-10-01 Thread Ricardo Ribalda Delgado
Hello Hans

I have just posted a new patch that only takes care of the core.

Thanks!

On Mon, Sep 30, 2013 at 2:11 PM, Hans Verkuil  wrote:
> On 09/30/2013 01:17 PM, Ricardo Ribalda Delgado wrote:
>> Hello Hans
>>
>> As allways thank you very much for your comments.
>>
>> On Mon, Sep 30, 2013 at 12:21 PM, Hans Verkuil  wrote:
>>> Hi Ricardo,
>>>
>>> Sorry for the delayed review, but I'm finally catching up with my backlog.
>>>
>>> I've got a number of comments regarding this patch. I'm ignoring the 
>>> platform
>>> driver patches for now until the core support is correct.
>>>
>>> On 09/16/2013 02:54 PM, Ricardo Ribalda Delgado wrote:
 From: Ricardo Ribalda 

 Extend v4l2 selection API to support multiple selection areas, this way
 sensors that support multiple readout areas can work with multiple areas
 of insterest.

 The struct v4l2_selection and v4l2_subdev_selection has been extented
 with a new field rectangles. If it is value is different than zero the
 pr array is used instead of the r field.

 A new structure v4l2_ext_rect has been defined, containing 4 reserved
 fields for future improvements, as suggested by Hans.

 A new function in v4l2-comon (v4l2_selection_flat_struct) is in charge
 of converting a pr pointer with one item to a flatten struct. This
 function is used in all the old drivers that dont support multiple
 selections.

 Signed-off-by: Ricardo Ribalda Delgado 
 ---
  drivers/media/platform/exynos-gsc/gsc-m2m.c  |  6 +++
  drivers/media/platform/exynos4-is/fimc-capture.c |  6 +++
  drivers/media/platform/exynos4-is/fimc-lite.c|  6 +++
  drivers/media/platform/s3c-camif/camif-capture.c |  6 +++
  drivers/media/platform/s5p-jpeg/jpeg-core.c  |  3 ++
  drivers/media/platform/s5p-tv/mixer_video.c  |  6 +++
  drivers/media/platform/soc_camera/soc_camera.c   |  6 +++
  drivers/media/v4l2-core/v4l2-common.c| 13 ++
  drivers/media/v4l2-core/v4l2-ioctl.c | 54 
 +---
  include/media/v4l2-common.h  |  2 +
  include/uapi/linux/v4l2-subdev.h | 10 -
  include/uapi/linux/videodev2.h   | 15 ++-
  12 files changed, 122 insertions(+), 11 deletions(-)

>>>
>>> 
>>>
 diff --git a/drivers/media/v4l2-core/v4l2-common.c 
 b/drivers/media/v4l2-core/v4l2-common.c
 index a95e5e2..cd20567 100644
 --- a/drivers/media/v4l2-core/v4l2-common.c
 +++ b/drivers/media/v4l2-core/v4l2-common.c
 @@ -886,3 +886,16 @@ void v4l2_get_timestamp(struct timeval *tv)
   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
  }
  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
 +
 +int v4l2_selection_flat_struct(struct v4l2_selection *s)
 +{
 + if (s->rectangles == 0)
 + return 0;
 +
 + if (s->rectangles != 1)
 + return -EINVAL;
 +
 + s->r = s->pr[0].r;
>>>
>>> This would overwrite the pr pointer. Not a good idea.
>>
>> That was exactly the point. The helper function convert the
>> multi_selection, ext_rect to the legacy struct. This way the drivers
>> needed almost no modification, just a call to the helper at the
>> beginning of the handler.
>
> That doesn't work: G and S_SELECTION are IOWR, so the driver can modify the
> rectangles and those will have to be passed back to userspace. So you cannot
> just change the contents of struct v4l2_selection.
>
>>
>> Otherwise we need your get_rect helper, and then a set_rect helper at
>> every exit.
>>
>> If you think this is the way, then lets do it. Right now there are not
>> too many drivers that supports selection, so it is right time to make
>> such a decisions.
>>
>>>
>>> I would make a helper function like this:
>>>
>>> int v4l2_selection_get_rect(struct v4l2_selection *s, struct v4l2_ext_rect 
>>> *r)
>>> {
>>> if (s->rectangles > 1)
>>> return -EINVAL;
>>> if (s->rectangles == 1) {
>>> *r = s->pr[0];
>>> return 0;
>>> }
>>> if (s->r.width < 0 || s->r.height < 0)
>>> return -EINVAL;
>>> r->left = s->r.left;
>>> r->top = s->r.top;
>>> r->width = s->r.width;
>>> r->height = s->r.height;
>>> memset(r->reserved, 0, sizeof(r->reserved));
>>> return 0;
>>> }
>>>
>>> See also my proposed v4l2_ext_rect definition below.
>>>
 + return 0;
 +}
 +EXPORT_SYMBOL_GPL(v4l2_selection_flat_struct);
 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
 b/drivers/media/v4l2-core/v4l2-ioctl.c
 index 68e6b5e..fe92f6b 100644
 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
 @@ -572,11 +572,22 @@ static void v4l_print_crop(const void *arg, bool 
 write_only)
  static void v4l_print_selection(const void *arg, bool write_only

Re: [PATCH] v4l2: Support for multiple selections

2013-09-30 Thread Hans Verkuil
On 09/30/2013 01:17 PM, Ricardo Ribalda Delgado wrote:
> Hello Hans
> 
> As allways thank you very much for your comments.
> 
> On Mon, Sep 30, 2013 at 12:21 PM, Hans Verkuil  wrote:
>> Hi Ricardo,
>>
>> Sorry for the delayed review, but I'm finally catching up with my backlog.
>>
>> I've got a number of comments regarding this patch. I'm ignoring the platform
>> driver patches for now until the core support is correct.
>>
>> On 09/16/2013 02:54 PM, Ricardo Ribalda Delgado wrote:
>>> From: Ricardo Ribalda 
>>>
>>> Extend v4l2 selection API to support multiple selection areas, this way
>>> sensors that support multiple readout areas can work with multiple areas
>>> of insterest.
>>>
>>> The struct v4l2_selection and v4l2_subdev_selection has been extented
>>> with a new field rectangles. If it is value is different than zero the
>>> pr array is used instead of the r field.
>>>
>>> A new structure v4l2_ext_rect has been defined, containing 4 reserved
>>> fields for future improvements, as suggested by Hans.
>>>
>>> A new function in v4l2-comon (v4l2_selection_flat_struct) is in charge
>>> of converting a pr pointer with one item to a flatten struct. This
>>> function is used in all the old drivers that dont support multiple
>>> selections.
>>>
>>> Signed-off-by: Ricardo Ribalda Delgado 
>>> ---
>>>  drivers/media/platform/exynos-gsc/gsc-m2m.c  |  6 +++
>>>  drivers/media/platform/exynos4-is/fimc-capture.c |  6 +++
>>>  drivers/media/platform/exynos4-is/fimc-lite.c|  6 +++
>>>  drivers/media/platform/s3c-camif/camif-capture.c |  6 +++
>>>  drivers/media/platform/s5p-jpeg/jpeg-core.c  |  3 ++
>>>  drivers/media/platform/s5p-tv/mixer_video.c  |  6 +++
>>>  drivers/media/platform/soc_camera/soc_camera.c   |  6 +++
>>>  drivers/media/v4l2-core/v4l2-common.c| 13 ++
>>>  drivers/media/v4l2-core/v4l2-ioctl.c | 54 
>>> +---
>>>  include/media/v4l2-common.h  |  2 +
>>>  include/uapi/linux/v4l2-subdev.h | 10 -
>>>  include/uapi/linux/videodev2.h   | 15 ++-
>>>  12 files changed, 122 insertions(+), 11 deletions(-)
>>>
>>
>> 
>>
>>> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
>>> b/drivers/media/v4l2-core/v4l2-common.c
>>> index a95e5e2..cd20567 100644
>>> --- a/drivers/media/v4l2-core/v4l2-common.c
>>> +++ b/drivers/media/v4l2-core/v4l2-common.c
>>> @@ -886,3 +886,16 @@ void v4l2_get_timestamp(struct timeval *tv)
>>>   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>>>  }
>>>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
>>> +
>>> +int v4l2_selection_flat_struct(struct v4l2_selection *s)
>>> +{
>>> + if (s->rectangles == 0)
>>> + return 0;
>>> +
>>> + if (s->rectangles != 1)
>>> + return -EINVAL;
>>> +
>>> + s->r = s->pr[0].r;
>>
>> This would overwrite the pr pointer. Not a good idea.
> 
> That was exactly the point. The helper function convert the
> multi_selection, ext_rect to the legacy struct. This way the drivers
> needed almost no modification, just a call to the helper at the
> beginning of the handler.

That doesn't work: G and S_SELECTION are IOWR, so the driver can modify the
rectangles and those will have to be passed back to userspace. So you cannot
just change the contents of struct v4l2_selection.

> 
> Otherwise we need your get_rect helper, and then a set_rect helper at
> every exit.
> 
> If you think this is the way, then lets do it. Right now there are not
> too many drivers that supports selection, so it is right time to make
> such a decisions.
> 
>>
>> I would make a helper function like this:
>>
>> int v4l2_selection_get_rect(struct v4l2_selection *s, struct v4l2_ext_rect 
>> *r)
>> {
>> if (s->rectangles > 1)
>> return -EINVAL;
>> if (s->rectangles == 1) {
>> *r = s->pr[0];
>> return 0;
>> }
>> if (s->r.width < 0 || s->r.height < 0)
>> return -EINVAL;
>> r->left = s->r.left;
>> r->top = s->r.top;
>> r->width = s->r.width;
>> r->height = s->r.height;
>> memset(r->reserved, 0, sizeof(r->reserved));
>> return 0;
>> }
>>
>> See also my proposed v4l2_ext_rect definition below.
>>
>>> + return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(v4l2_selection_flat_struct);
>>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
>>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>>> index 68e6b5e..fe92f6b 100644
>>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>>> @@ -572,11 +572,22 @@ static void v4l_print_crop(const void *arg, bool 
>>> write_only)
>>>  static void v4l_print_selection(const void *arg, bool write_only)
>>>  {
>>>   const struct v4l2_selection *p = arg;
>>> + int i;
>>>
>>> - pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
>>> - prt_names(p->type, v4l2_type_names),
>>> - p->target, p->flags,
>>> - p->r

Re: [PATCH] v4l2: Support for multiple selections

2013-09-30 Thread Ricardo Ribalda Delgado
Hello Hans

As allways thank you very much for your comments.

On Mon, Sep 30, 2013 at 12:21 PM, Hans Verkuil  wrote:
> Hi Ricardo,
>
> Sorry for the delayed review, but I'm finally catching up with my backlog.
>
> I've got a number of comments regarding this patch. I'm ignoring the platform
> driver patches for now until the core support is correct.
>
> On 09/16/2013 02:54 PM, Ricardo Ribalda Delgado wrote:
>> From: Ricardo Ribalda 
>>
>> Extend v4l2 selection API to support multiple selection areas, this way
>> sensors that support multiple readout areas can work with multiple areas
>> of insterest.
>>
>> The struct v4l2_selection and v4l2_subdev_selection has been extented
>> with a new field rectangles. If it is value is different than zero the
>> pr array is used instead of the r field.
>>
>> A new structure v4l2_ext_rect has been defined, containing 4 reserved
>> fields for future improvements, as suggested by Hans.
>>
>> A new function in v4l2-comon (v4l2_selection_flat_struct) is in charge
>> of converting a pr pointer with one item to a flatten struct. This
>> function is used in all the old drivers that dont support multiple
>> selections.
>>
>> Signed-off-by: Ricardo Ribalda Delgado 
>> ---
>>  drivers/media/platform/exynos-gsc/gsc-m2m.c  |  6 +++
>>  drivers/media/platform/exynos4-is/fimc-capture.c |  6 +++
>>  drivers/media/platform/exynos4-is/fimc-lite.c|  6 +++
>>  drivers/media/platform/s3c-camif/camif-capture.c |  6 +++
>>  drivers/media/platform/s5p-jpeg/jpeg-core.c  |  3 ++
>>  drivers/media/platform/s5p-tv/mixer_video.c  |  6 +++
>>  drivers/media/platform/soc_camera/soc_camera.c   |  6 +++
>>  drivers/media/v4l2-core/v4l2-common.c| 13 ++
>>  drivers/media/v4l2-core/v4l2-ioctl.c | 54 
>> +---
>>  include/media/v4l2-common.h  |  2 +
>>  include/uapi/linux/v4l2-subdev.h | 10 -
>>  include/uapi/linux/videodev2.h   | 15 ++-
>>  12 files changed, 122 insertions(+), 11 deletions(-)
>>
>
> 
>
>> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
>> b/drivers/media/v4l2-core/v4l2-common.c
>> index a95e5e2..cd20567 100644
>> --- a/drivers/media/v4l2-core/v4l2-common.c
>> +++ b/drivers/media/v4l2-core/v4l2-common.c
>> @@ -886,3 +886,16 @@ void v4l2_get_timestamp(struct timeval *tv)
>>   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>>  }
>>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
>> +
>> +int v4l2_selection_flat_struct(struct v4l2_selection *s)
>> +{
>> + if (s->rectangles == 0)
>> + return 0;
>> +
>> + if (s->rectangles != 1)
>> + return -EINVAL;
>> +
>> + s->r = s->pr[0].r;
>
> This would overwrite the pr pointer. Not a good idea.

That was exactly the point. The helper function convert the
multi_selection, ext_rect to the legacy struct. This way the drivers
needed almost no modification, just a call to the helper at the
beginning of the handler.

Otherwise we need your get_rect helper, and then a set_rect helper at
every exit.

If you think this is the way, then lets do it. Right now there are not
too many drivers that supports selection, so it is right time to make
such a decisions.

>
> I would make a helper function like this:
>
> int v4l2_selection_get_rect(struct v4l2_selection *s, struct v4l2_ext_rect *r)
> {
> if (s->rectangles > 1)
> return -EINVAL;
> if (s->rectangles == 1) {
> *r = s->pr[0];
> return 0;
> }
> if (s->r.width < 0 || s->r.height < 0)
> return -EINVAL;
> r->left = s->r.left;
> r->top = s->r.top;
> r->width = s->r.width;
> r->height = s->r.height;
> memset(r->reserved, 0, sizeof(r->reserved));
> return 0;
> }
>
> See also my proposed v4l2_ext_rect definition below.
>
>> + return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(v4l2_selection_flat_struct);
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index 68e6b5e..fe92f6b 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -572,11 +572,22 @@ static void v4l_print_crop(const void *arg, bool 
>> write_only)
>>  static void v4l_print_selection(const void *arg, bool write_only)
>>  {
>>   const struct v4l2_selection *p = arg;
>> + int i;
>>
>> - pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
>> - prt_names(p->type, v4l2_type_names),
>> - p->target, p->flags,
>> - p->r.width, p->r.height, p->r.left, p->r.top);
>> + if (p->rectangles == 0)
>> + pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, 
>> x,y=%d,%d\n",
>> + prt_names(p->type, v4l2_type_names),
>> + p->target, p->flags,
>> + p->r.width, p->r.height, p->r.left, p->r.top);
>> + else{
>> + pr_cont("type=%s, target=%d, flags=

Re: [PATCH] v4l2: Support for multiple selections

2013-09-30 Thread Hans Verkuil
Hi Ricardo,

Sorry for the delayed review, but I'm finally catching up with my backlog.

I've got a number of comments regarding this patch. I'm ignoring the platform
driver patches for now until the core support is correct.

On 09/16/2013 02:54 PM, Ricardo Ribalda Delgado wrote:
> From: Ricardo Ribalda 
> 
> Extend v4l2 selection API to support multiple selection areas, this way
> sensors that support multiple readout areas can work with multiple areas
> of insterest.
> 
> The struct v4l2_selection and v4l2_subdev_selection has been extented
> with a new field rectangles. If it is value is different than zero the
> pr array is used instead of the r field.
> 
> A new structure v4l2_ext_rect has been defined, containing 4 reserved
> fields for future improvements, as suggested by Hans.
> 
> A new function in v4l2-comon (v4l2_selection_flat_struct) is in charge
> of converting a pr pointer with one item to a flatten struct. This
> function is used in all the old drivers that dont support multiple
> selections.
> 
> Signed-off-by: Ricardo Ribalda Delgado 
> ---
>  drivers/media/platform/exynos-gsc/gsc-m2m.c  |  6 +++
>  drivers/media/platform/exynos4-is/fimc-capture.c |  6 +++
>  drivers/media/platform/exynos4-is/fimc-lite.c|  6 +++
>  drivers/media/platform/s3c-camif/camif-capture.c |  6 +++
>  drivers/media/platform/s5p-jpeg/jpeg-core.c  |  3 ++
>  drivers/media/platform/s5p-tv/mixer_video.c  |  6 +++
>  drivers/media/platform/soc_camera/soc_camera.c   |  6 +++
>  drivers/media/v4l2-core/v4l2-common.c| 13 ++
>  drivers/media/v4l2-core/v4l2-ioctl.c | 54 
> +---
>  include/media/v4l2-common.h  |  2 +
>  include/uapi/linux/v4l2-subdev.h | 10 -
>  include/uapi/linux/videodev2.h   | 15 ++-
>  12 files changed, 122 insertions(+), 11 deletions(-)
> 



> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
> b/drivers/media/v4l2-core/v4l2-common.c
> index a95e5e2..cd20567 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -886,3 +886,16 @@ void v4l2_get_timestamp(struct timeval *tv)
>   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>  }
>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
> +
> +int v4l2_selection_flat_struct(struct v4l2_selection *s)
> +{
> + if (s->rectangles == 0)
> + return 0;
> +
> + if (s->rectangles != 1)
> + return -EINVAL;
> +
> + s->r = s->pr[0].r;

This would overwrite the pr pointer. Not a good idea.

I would make a helper function like this:

int v4l2_selection_get_rect(struct v4l2_selection *s, struct v4l2_ext_rect *r)
{
if (s->rectangles > 1)
return -EINVAL;
if (s->rectangles == 1) {
*r = s->pr[0];
return 0;
}
if (s->r.width < 0 || s->r.height < 0)
return -EINVAL;
r->left = s->r.left;
r->top = s->r.top;
r->width = s->r.width;
r->height = s->r.height;
memset(r->reserved, 0, sizeof(r->reserved));
return 0;
}

See also my proposed v4l2_ext_rect definition below.

> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_selection_flat_struct);
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
> b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 68e6b5e..fe92f6b 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -572,11 +572,22 @@ static void v4l_print_crop(const void *arg, bool 
> write_only)
>  static void v4l_print_selection(const void *arg, bool write_only)
>  {
>   const struct v4l2_selection *p = arg;
> + int i;
>  
> - pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
> - prt_names(p->type, v4l2_type_names),
> - p->target, p->flags,
> - p->r.width, p->r.height, p->r.left, p->r.top);
> + if (p->rectangles == 0)
> + pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, 
> x,y=%d,%d\n",
> + prt_names(p->type, v4l2_type_names),
> + p->target, p->flags,
> + p->r.width, p->r.height, p->r.left, p->r.top);
> + else{
> + pr_cont("type=%s, target=%d, flags=0x%x rectangles=%d\n",
> + prt_names(p->type, v4l2_type_names),
> + p->target, p->flags, p->rectangles);
> + for (i = 0; i < p->rectangles; i++)
> + pr_cont("rectangle %d: wxh=%dx%d, x,y=%d,%d\n",
> + i, p->r.width, p->r.height,
> + p->r.left, p->r.top);
> + }
>  }
>  
>  static void v4l_print_jpegcompression(const void *arg, bool write_only)
> @@ -1645,6 +1656,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
>   struct v4l2_crop *p = arg;
>   struct v4l2_selection s = {
>   .type = p->type,
> + .rectangles = 0,

No need for this. In i

[PATCH] v4l2: Support for multiple selections

2013-09-16 Thread Ricardo Ribalda Delgado
From: Ricardo Ribalda 

Extend v4l2 selection API to support multiple selection areas, this way
sensors that support multiple readout areas can work with multiple areas
of insterest.

The struct v4l2_selection and v4l2_subdev_selection has been extented
with a new field rectangles. If it is value is different than zero the
pr array is used instead of the r field.

A new structure v4l2_ext_rect has been defined, containing 4 reserved
fields for future improvements, as suggested by Hans.

A new function in v4l2-comon (v4l2_selection_flat_struct) is in charge
of converting a pr pointer with one item to a flatten struct. This
function is used in all the old drivers that dont support multiple
selections.

Signed-off-by: Ricardo Ribalda Delgado 
---
 drivers/media/platform/exynos-gsc/gsc-m2m.c  |  6 +++
 drivers/media/platform/exynos4-is/fimc-capture.c |  6 +++
 drivers/media/platform/exynos4-is/fimc-lite.c|  6 +++
 drivers/media/platform/s3c-camif/camif-capture.c |  6 +++
 drivers/media/platform/s5p-jpeg/jpeg-core.c  |  3 ++
 drivers/media/platform/s5p-tv/mixer_video.c  |  6 +++
 drivers/media/platform/soc_camera/soc_camera.c   |  6 +++
 drivers/media/v4l2-core/v4l2-common.c| 13 ++
 drivers/media/v4l2-core/v4l2-ioctl.c | 54 +---
 include/media/v4l2-common.h  |  2 +
 include/uapi/linux/v4l2-subdev.h | 10 -
 include/uapi/linux/videodev2.h   | 15 ++-
 12 files changed, 122 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c 
b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 40a73f7..599a907 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -452,6 +452,9 @@ static int gsc_m2m_g_selection(struct file *file, void *fh,
(s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
frame = ctx_get_frame(ctx, s->type);
if (IS_ERR(frame))
return PTR_ERR(frame);
@@ -495,6 +498,9 @@ static int gsc_m2m_s_selection(struct file *file, void *fh,
(s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
ret = gsc_try_crop(ctx, &cr);
if (ret)
return ret;
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c 
b/drivers/media/platform/exynos4-is/fimc-capture.c
index fb27ff7..357ac81 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1283,6 +1283,9 @@ static int fimc_cap_g_selection(struct file *file, void 
*fh,
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
switch (s->target) {
case V4L2_SEL_TGT_COMPOSE_DEFAULT:
case V4L2_SEL_TGT_COMPOSE_BOUNDS:
@@ -1333,6 +1336,9 @@ static int fimc_cap_s_selection(struct file *file, void 
*fh,
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
if (s->target == V4L2_SEL_TGT_COMPOSE)
f = &ctx->d_frame;
else if (s->target == V4L2_SEL_TGT_CROP)
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c 
b/drivers/media/platform/exynos4-is/fimc-lite.c
index 08fbfed..b895318 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -915,6 +915,9 @@ static int fimc_lite_g_selection(struct file *file, void 
*fh,
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
switch (sel->target) {
case V4L2_SEL_TGT_COMPOSE_BOUNDS:
case V4L2_SEL_TGT_COMPOSE_DEFAULT:
@@ -944,6 +947,9 @@ static int fimc_lite_s_selection(struct file *file, void 
*fh,
sel->target != V4L2_SEL_TGT_COMPOSE)
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
fimc_lite_try_compose(fimc, &rect);
 
if ((sel->flags & V4L2_SEL_FLAG_LE) &&
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c 
b/drivers/media/platform/s3c-camif/camif-capture.c
index 40b298a..951dce4 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -1016,6 +1016,9 @@ static int s3c_camif_g_selection(struct file *file, void 
*priv,
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
 
+   if (v4l2_selection_flat_struct(s))
+   return -EINVAL;
+
switch (sel->target) {
case V4L2_SEL_TGT_COMPOS