Re: [PATCH for v4.4 00/14] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Greg KH
On Wed, Feb 14, 2018 at 12:52:26PM +0100, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> This patch series fixes a number of bugs and culminates in the removal
> of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.
> 
> This was tested with a VM running 4.4, the vivid driver (since that
> emulates almost all V4L2 ioctls that need to pass through 
> v4l2-compat-ioctl32.c)
> and a 32-bit v4l2-compliance utility since that exercises almost all ioctls
> as well. Combined this gives good test coverage.
> 
> Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
> v4l2-compliance complained about. The purpose is to 1) make it easy to
> verify that the final patch didn't introduce errors by first eliminating
> errors caused by other known bugs, and 2) keep the final patch at least
> somewhat readable.

All now applied, many thanks for these.

greg k-h


Re: [PATCH for v4.9 00/13] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Greg KH
On Wed, Feb 14, 2018 at 12:48:17PM +0100, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> This patch series fixes a number of bugs and culminates in the removal
> of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.
> 
> This was tested with a VM running 4.9, the vivid driver (since that
> emulates almost all V4L2 ioctls that need to pass through 
> v4l2-compat-ioctl32.c)
> and a 32-bit v4l2-compliance utility since that exercises almost all ioctls
> as well. Combined this gives good test coverage.
> 
> Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
> v4l2-compliance complained about. The purpose is to 1) make it easy to
> verify that the final patch didn't introduce errors by first eliminating
> errors caused by other bugs, and 2) keep the final patch at least somewhat
> readable.

All now applied, thanks.

greg k-h


Re: [PATCH for v4.14 00/13] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Greg KH
On Wed, Feb 14, 2018 at 12:44:21PM +0100, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> This patch series fixes a number of bugs and culminates in the removal
> of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.
> 
> This was tested with a VM running 4.14, the vivid driver (since that
> emulates almost all V4L2 ioctls that need to pass through 
> v4l2-compat-ioctl32.c)
> and a 32-bit v4l2-compliance utility since that exercises almost all ioctls
> as well. Combined this gives good test coverage.
> 
> Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
> v4l2-compliance complained about. The purpose is to 1) make it easy to
> verify that the final patch didn't introduce errors by first eliminating
> errors caused by other bugs, and 2) keep the final patch at least somewhat
> readable.

All now queued up, thanks.

greg k-h


[PATCH v3 9/9] v4l: xilinx: dma: Get scaling and padding factor to calculate DMA params

2018-02-14 Thread Satish Kumar Nagireddy
Get multiplying factor to calculate bpp especially
in case of 10 bit formats.
Get multiplying factor to calculate padding width

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-dma.c | 29 ++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/xilinx/xilinx-dma.c 
b/drivers/media/platform/xilinx/xilinx-dma.c
index 664981b..3c2fd02 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -417,6 +417,7 @@ static void xvip_dma_buffer_queue(struct vb2_buffer *vb)
struct xvip_dma_buffer *buf = to_xvip_dma_buffer(vbuf);
struct dma_async_tx_descriptor *desc;
u32 flags, luma_size;
+   u32 padding_factor_nume, padding_factor_deno, bpl_nume, bpl_deno;
dma_addr_t addr = vb2_dma_contig_plane_dma_addr(vb, 0);

if (dma->queue.type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
@@ -442,8 +443,15 @@ static void xvip_dma_buffer_queue(struct vb2_buffer *vb)
struct v4l2_pix_format_mplane *pix_mp;

pix_mp = >format.fmt.pix_mp;
+   xvip_width_padding_factor(pix_mp->pixelformat,
+ _factor_nume,
+ _factor_deno);
+   xvip_bpl_scaling_factor(pix_mp->pixelformat, _nume,
+   _deno);
dma->xt.frame_size = dma->fmtinfo->num_planes;
-   dma->sgl[0].size = pix_mp->width * dma->fmtinfo->bpl_factor;
+   dma->sgl[0].size = (pix_mp->width * dma->fmtinfo->bpl_factor *
+   padding_factor_nume * bpl_nume) /
+   (padding_factor_deno * bpl_deno);
dma->sgl[0].icg = pix_mp->plane_fmt[0].bytesperline -
dma->sgl[0].size;
dma->xt.numf = pix_mp->height;
@@ -472,8 +480,15 @@ static void xvip_dma_buffer_queue(struct vb2_buffer *vb)
struct v4l2_pix_format *pix;

pix = >format.fmt.pix;
+   xvip_width_padding_factor(pix->pixelformat,
+ _factor_nume,
+ _factor_deno);
+   xvip_bpl_scaling_factor(pix->pixelformat, _nume,
+   _deno);
dma->xt.frame_size = dma->fmtinfo->num_planes;
-   dma->sgl[0].size = pix->width * dma->fmtinfo->bpl_factor;
+   dma->sgl[0].size = (pix->width * dma->fmtinfo->bpl_factor *
+   padding_factor_nume * bpl_nume) /
+   (padding_factor_deno * bpl_deno);
dma->sgl[0].icg = pix->bytesperline - dma->sgl[0].size;
dma->xt.numf = pix->height;
dma->sgl[0].dst_icg = dma->sgl[0].size;
@@ -682,6 +697,8 @@ __xvip_dma_try_format(struct xvip_dma *dma,
unsigned int align;
unsigned int bpl;
unsigned int i, hsub, vsub, plane_width, plane_height;
+   unsigned int padding_factor_nume, padding_factor_deno;
+   unsigned int bpl_nume, bpl_deno;

/* Retrieve format information and select the default format if the
 * requested format isn't supported.
@@ -694,6 +711,10 @@ __xvip_dma_try_format(struct xvip_dma *dma,
if (IS_ERR(info))
info = xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT);

+   xvip_width_padding_factor(info->fourcc, _factor_nume,
+ _factor_deno);
+   xvip_bpl_scaling_factor(info->fourcc, _nume, _deno);
+
/* The transfer alignment requirements are expressed in bytes. Compute
 * the minimum and maximum values, clamp the requested width and convert
 * it back to pixels.
@@ -737,7 +758,9 @@ __xvip_dma_try_format(struct xvip_dma *dma,
for (i = 0; i < info->num_planes; i++) {
plane_width = pix_mp->width / (i ? hsub : 1);
plane_height = pix_mp->height / (i ? vsub : 1);
-   min_bpl = plane_width * info->bpl_factor;
+   min_bpl = (plane_width * info->bpl_factor *
+  padding_factor_nume * bpl_nume) /
+  (padding_factor_deno * bpl_deno);
max_bpl = rounddown(XVIP_DMA_MAX_WIDTH,
dma->align);
bpl = pix_mp->plane_fmt[i].bytesperline;
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email 

[PATCH v3 4/9] media-bus: uapi: Add YCrCb 420 media bus format

2018-02-14 Thread Satish Kumar Nagireddy
From: Rohit Athavale 

This commit adds a YUV 420 media bus format. Currently, one
doesn't exist. VYYUYY8_1X24 does not describe the way the pixels are
sent over the bus, but is an approximation.

Signed-off-by: Satish Kumar Nagireddy 
---
 include/uapi/linux/media-bus-format.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/media-bus-format.h 
b/include/uapi/linux/media-bus-format.h
index 9e35117..ade7e9d 100644
--- a/include/uapi/linux/media-bus-format.h
+++ b/include/uapi/linux/media-bus-format.h
@@ -62,7 +62,7 @@
 #define MEDIA_BUS_FMT_RGB121212_1X36   0x1019
 #define MEDIA_BUS_FMT_RGB161616_1X48   0x101a

-/* YUV (including grey) - next is  0x202c */
+/* YUV (including grey) - next is  0x202d */
 #define MEDIA_BUS_FMT_Y8_1X8   0x2001
 #define MEDIA_BUS_FMT_UV8_1X8  0x2015
 #define MEDIA_BUS_FMT_UYVY8_1_5X8  0x2002
@@ -106,6 +106,7 @@
 #define MEDIA_BUS_FMT_YUV12_1X36   0x2029
 #define MEDIA_BUS_FMT_YUV16_1X48   0x202a
 #define MEDIA_BUS_FMT_UYYVYY16_0_5X48  0x202b
+#define MEDIA_BUS_FMT_VYYUYY8_1X24 0x202c

 /* Bayer - next is 0x3021 */
 #define MEDIA_BUS_FMT_SBGGR8_1X8   0x3001
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 6/9] v4l: xilinx: dma: Update video format descriptor

2018-02-14 Thread Satish Kumar Nagireddy
This patch updates video format descriptor to help information
viz., number of planes per color format and chroma sub sampling
factors.

This commit adds the various 8-bit and 10-bit that are supported
to the table queried by drivers.

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-vip.c | 18 ++
 drivers/media/platform/xilinx/xilinx-vip.h | 11 ++-
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/xilinx/xilinx-vip.c 
b/drivers/media/platform/xilinx/xilinx-vip.c
index d306f44..51b7ef6 100644
--- a/drivers/media/platform/xilinx/xilinx-vip.c
+++ b/drivers/media/platform/xilinx/xilinx-vip.c
@@ -27,22 +27,24 @@
  */

 static const struct xvip_video_format xvip_video_formats[] = {
+   { XVIP_VF_YUV_420, 10, NULL, MEDIA_BUS_FMT_VYYUYY8_1X24,
+ 1, 15, V4L2_PIX_FMT_XV15M, 2, 2, 1, 2, "4:2:0, 10-bit 2-plane 
non-cont" },
{ XVIP_VF_YUV_422, 8, NULL, MEDIA_BUS_FMT_UYVY8_1X16,
- 2, V4L2_PIX_FMT_YUYV, "4:2:2, packed, YUYV" },
+ 2, 16, V4L2_PIX_FMT_YUYV, 1, 1, 2, 1, "4:2:2, packed, YUYV" },
{ XVIP_VF_YUV_444, 8, NULL, MEDIA_BUS_FMT_VUY8_1X24,
- 3, V4L2_PIX_FMT_YUV444, "4:4:4, packed, YUYV" },
+ 3, 24, V4L2_PIX_FMT_VUY24, 1, 1, 1, 1, "4:4:4, packed, YUYV" },
{ XVIP_VF_RBG, 8, NULL, MEDIA_BUS_FMT_RBG888_1X24,
- 3, V4L2_PIX_FMT_RGB24, "24-bit RGB" },
+ 3, 24, V4L2_PIX_FMT_RGB24, 1, 1, 1, 1, "24-bit RGB" },
{ XVIP_VF_MONO_SENSOR, 8, "mono", MEDIA_BUS_FMT_Y8_1X8,
- 1, V4L2_PIX_FMT_GREY, "Greyscale 8-bit" },
+ 1, 8, V4L2_PIX_FMT_GREY, 1, 1, 1, 1, "Greyscale 8-bit" },
{ XVIP_VF_MONO_SENSOR, 8, "rggb", MEDIA_BUS_FMT_SRGGB8_1X8,
- 1, V4L2_PIX_FMT_SGRBG8, "Bayer 8-bit RGGB" },
+ 1, 8, V4L2_PIX_FMT_SGRBG8, 1, 1, 1, 1, "Bayer 8-bit RGGB" },
{ XVIP_VF_MONO_SENSOR, 8, "grbg", MEDIA_BUS_FMT_SGRBG8_1X8,
- 1, V4L2_PIX_FMT_SGRBG8, "Bayer 8-bit GRBG" },
+ 1, 8, V4L2_PIX_FMT_SGRBG8, 1, 1, 1, 1, "Bayer 8-bit GRBG" },
{ XVIP_VF_MONO_SENSOR, 8, "gbrg", MEDIA_BUS_FMT_SGBRG8_1X8,
- 1, V4L2_PIX_FMT_SGBRG8, "Bayer 8-bit GBRG" },
+ 1, 8, V4L2_PIX_FMT_SGBRG8, 1, 1, 1, 1, "Bayer 8-bit GBRG" },
{ XVIP_VF_MONO_SENSOR, 8, "bggr", MEDIA_BUS_FMT_SBGGR8_1X8,
- 1, V4L2_PIX_FMT_SBGGR8, "Bayer 8-bit BGGR" },
+ 1, 8, V4L2_PIX_FMT_SBGGR8, 1, 1, 1, 1, "Bayer 8-bit BGGR" },
 };

 /**
diff --git a/drivers/media/platform/xilinx/xilinx-vip.h 
b/drivers/media/platform/xilinx/xilinx-vip.h
index 42fee20..006dcf77 100644
--- a/drivers/media/platform/xilinx/xilinx-vip.h
+++ b/drivers/media/platform/xilinx/xilinx-vip.h
@@ -109,8 +109,12 @@ struct xvip_device {
  * @width: AXI4 format width in bits per component
  * @pattern: CFA pattern for Mono/Sensor formats
  * @code: media bus format code
- * @bpp: bytes per pixel (when stored in memory)
+ * @bpl_factor: Bytes per line factor
  * @fourcc: V4L2 pixel format FCC identifier
+ * @num_planes: number of planes w.r.t. color format
+ * @buffers: number of buffers per format
+ * @hsub: Horizontal sampling factor of Chroma
+ * @vsub: Vertical sampling factor of Chroma
  * @description: format description, suitable for userspace
  */
 struct xvip_video_format {
@@ -118,8 +122,13 @@ struct xvip_video_format {
unsigned int width;
const char *pattern;
unsigned int code;
+   unsigned int bpl_factor;
unsigned int bpp;
u32 fourcc;
+   u8 num_planes;
+   u8 buffers;
+   u8 hsub;
+   u8 vsub;
const char *description;
 };

--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 1/9] v4l: xilinx: dma: Remove colorspace check in xvip_dma_verify_format

2018-02-14 Thread Satish Kumar Nagireddy
From: Radhey Shyam Pandey 

In current implementation driver only checks the colorspace
between the last subdev in the pipeline and the connected video node,
the pipeline could be configured with wrong colorspace information
until the very end. It thus makes little sense to check the
colorspace only at the video node. So check can be dropped until
we find a better solution to carry colorspace information
through pipelines and to userspace.

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/xilinx/xilinx-dma.c 
b/drivers/media/platform/xilinx/xilinx-dma.c
index 522cdfd..cb20ada 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -75,8 +75,7 @@ static int xvip_dma_verify_format(struct xvip_dma *dma)

if (dma->fmtinfo->code != fmt.format.code ||
dma->format.height != fmt.format.height ||
-   dma->format.width != fmt.format.width ||
-   dma->format.colorspace != fmt.format.colorspace)
+   dma->format.width != fmt.format.width)
return -EINVAL;

return 0;
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 3/9] uapi: media: New fourcc codes needed by Xilinx Video IP

2018-02-14 Thread Satish Kumar Nagireddy
From: Jeffrey Mouroux 

The Xilinx Video Framebuffer DMA IP supports video memory formats
that are not represented in the current V4L2 fourcc library. This
patch adds those missing fourcc codes. This includes both new
8-bit and 10-bit pixel formats.

Signed-off-by: Satish Kumar Nagireddy 
---
 include/uapi/linux/videodev2.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 9827189..9fa4313c 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -509,7 +509,10 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_XBGR32  v4l2_fourcc('X', 'R', '2', '4') /* 32  
BGRX-8-8-8-8  */
 #define V4L2_PIX_FMT_RGB32   v4l2_fourcc('R', 'G', 'B', '4') /* 32  
RGB-8-8-8-8   */
 #define V4L2_PIX_FMT_ARGB32  v4l2_fourcc('B', 'A', '2', '4') /* 32  
ARGB-8-8-8-8  */
+#define V4L2_PIX_FMT_BGRA32  v4l2_fourcc('A', 'B', 'G', 'R') /* 32  
ABGR-8-8-8-8  */
 #define V4L2_PIX_FMT_XRGB32  v4l2_fourcc('B', 'X', '2', '4') /* 32  
XRGB-8-8-8-8  */
+#define V4L2_PIX_FMT_BGRX32  v4l2_fourcc('X', 'B', 'G', 'R') /* 32  
XBGR-8-8-8-8 */
+#define V4L2_PIX_FMT_XBGR30  v4l2_fourcc('R', 'X', '3', '0') /* 32  
XBGR-2-10-10-10 */

 /* Grey formats */
 #define V4L2_PIX_FMT_GREYv4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale  
   */
@@ -537,12 +540,16 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_VYUYv4l2_fourcc('V', 'Y', 'U', 'Y') /* 16  YUV 4:2:2  
   */
 #define V4L2_PIX_FMT_Y41Pv4l2_fourcc('Y', '4', '1', 'P') /* 12  YUV 4:1:1  
   */
 #define V4L2_PIX_FMT_YUV444  v4l2_fourcc('Y', '4', '4', '4') /* 16   
 */
+#define V4L2_PIX_FMT_XVUY32  v4l2_fourcc('X', 'V', '3', '2') /* 32  XVUY 
8:8:8:8 */
+#define V4L2_PIX_FMT_AVUY32  v4l2_fourcc('A', 'V', '3', '2') /* 32  AVUY 
8:8:8:8 */
+#define V4L2_PIX_FMT_VUY24   v4l2_fourcc('V', 'U', '2', '4') /* 24  VUY 8:8:8 
*/
 #define V4L2_PIX_FMT_YUV555  v4l2_fourcc('Y', 'U', 'V', 'O') /* 16  YUV-5-5-5  
   */
 #define V4L2_PIX_FMT_YUV565  v4l2_fourcc('Y', 'U', 'V', 'P') /* 16  YUV-5-6-5  
   */
 #define V4L2_PIX_FMT_YUV32   v4l2_fourcc('Y', 'U', 'V', '4') /* 32  
YUV-8-8-8-8   */
 #define V4L2_PIX_FMT_HI240   v4l2_fourcc('H', 'I', '2', '4') /*  8  8-bit 
color   */
 #define V4L2_PIX_FMT_HM12v4l2_fourcc('H', 'M', '1', '2') /*  8  YUV 4:2:0 
16x16 macroblocks */
 #define V4L2_PIX_FMT_M420v4l2_fourcc('M', '4', '2', '0') /* 12  YUV 4:2:0 
2 lines y, 1 line uv interleaved */
+#define V4L2_PIX_FMT_XVUY10  v4l2_fourcc('X', 'Y', '1', '0') /* 32  XVUY 
2-10-10-10 */

 /* two planes -- one Y, one Cr + Cb interleaved  */
 #define V4L2_PIX_FMT_NV12v4l2_fourcc('N', 'V', '1', '2') /* 12  Y/CbCr 
4:2:0  */
@@ -551,6 +558,8 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_NV61v4l2_fourcc('N', 'V', '6', '1') /* 16  Y/CrCb 
4:2:2  */
 #define V4L2_PIX_FMT_NV24v4l2_fourcc('N', 'V', '2', '4') /* 24  Y/CbCr 
4:4:4  */
 #define V4L2_PIX_FMT_NV42v4l2_fourcc('N', 'V', '4', '2') /* 24  Y/CrCb 
4:4:4  */
+#define V4L2_PIX_FMT_XV20v4l2_fourcc('X', 'V', '2', '0') /* 32  XY/UV 
4:2:2 10-bit */
+#define V4L2_PIX_FMT_XV15v4l2_fourcc('X', 'V', '1', '5') /* 32  XY/UV 
4:2:0 10-bit */

 /* two non contiguous planes - one Y, one Cr + Cb interleaved  */
 #define V4L2_PIX_FMT_NV12M   v4l2_fourcc('N', 'M', '1', '2') /* 12  Y/CbCr 
4:2:0  */
@@ -558,6 +567,8 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_NV16M   v4l2_fourcc('N', 'M', '1', '6') /* 16  Y/CbCr 
4:2:2  */
 #define V4L2_PIX_FMT_NV61M   v4l2_fourcc('N', 'M', '6', '1') /* 16  Y/CrCb 
4:2:2  */
 #define V4L2_PIX_FMT_NV12MT  v4l2_fourcc('T', 'M', '1', '2') /* 12  Y/CbCr 
4:2:0 64x32 macroblocks */
+#define V4L2_PIX_FMT_XV20M   v4l2_fourcc('X', 'M', '2', '0') /* 32  XY/UV 
4:2:2 10-bit */
+#define V4L2_PIX_FMT_XV15M   v4l2_fourcc('X', 'M', '1', '5') /* 32  XY/UV 
4:2:0 10-bit */
 #define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12  
Y/CbCr 4:2:0 16x16 macroblocks */

 /* three planes - Y Cb, Cr */
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 2/9] media: xilinx: vip: Add the pixel format for RGB24

2018-02-14 Thread Satish Kumar Nagireddy
From: Hyun Kwon 

The pixel format for RGB24 is missing, and the driver
always falls back to YUYV as no format descriptor matches
with RGB24 fourcc. The pixel format is added to RGB24
format descriptor so that user can use the format.

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-vip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/xilinx/xilinx-vip.c 
b/drivers/media/platform/xilinx/xilinx-vip.c
index 3112591..d306f44 100644
--- a/drivers/media/platform/xilinx/xilinx-vip.c
+++ b/drivers/media/platform/xilinx/xilinx-vip.c
@@ -32,7 +32,7 @@ static const struct xvip_video_format xvip_video_formats[] = {
{ XVIP_VF_YUV_444, 8, NULL, MEDIA_BUS_FMT_VUY8_1X24,
  3, V4L2_PIX_FMT_YUV444, "4:4:4, packed, YUYV" },
{ XVIP_VF_RBG, 8, NULL, MEDIA_BUS_FMT_RBG888_1X24,
- 3, 0, NULL },
+ 3, V4L2_PIX_FMT_RGB24, "24-bit RGB" },
{ XVIP_VF_MONO_SENSOR, 8, "mono", MEDIA_BUS_FMT_Y8_1X8,
  1, V4L2_PIX_FMT_GREY, "Greyscale 8-bit" },
{ XVIP_VF_MONO_SENSOR, 8, "rggb", MEDIA_BUS_FMT_SRGGB8_1X8,
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 8/9] v4l: xilinx: dma: Add scaling and padding factor functions

2018-02-14 Thread Satish Kumar Nagireddy
scaling_factor function returns multiplying factor to calculate
bytes per component based on color format.
For eg. scaling factor of YUV420 8 bit format is 1
so multiplying factor is 1 (8/8)
scaling factor of YUV420 10 bit format is 1.25 (10/8)

padding_factor function returns multiplying factor to calculate
actual width of video according to color format.
For eg. padding factor of YUV420 8 bit format: 8 bits per 1 component
no padding bits here, so multiplying factor is 1
padding factor of YUV422 10 bit format: 32 bits per 3 components
each component is 10 bit and the factor is 32/30

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-vip.c | 43 ++
 drivers/media/platform/xilinx/xilinx-vip.h |  2 ++
 2 files changed, 45 insertions(+)

diff --git a/drivers/media/platform/xilinx/xilinx-vip.c 
b/drivers/media/platform/xilinx/xilinx-vip.c
index 51b7ef6..7543b75 100644
--- a/drivers/media/platform/xilinx/xilinx-vip.c
+++ b/drivers/media/platform/xilinx/xilinx-vip.c
@@ -94,6 +94,49 @@ const struct xvip_video_format 
*xvip_get_format_by_fourcc(u32 fourcc)
 EXPORT_SYMBOL_GPL(xvip_get_format_by_fourcc);

 /**
+ * xvip_bpl_scaling_factor - Retrieve bpl scaling factor for a 4CC
+ * @fourcc: the format 4CC
+ *
+ * Return: Return numerator and denominator values by address
+ */
+void xvip_bpl_scaling_factor(u32 fourcc, u32 *numerator, u32 *denominator)
+{
+   switch (fourcc) {
+   case V4L2_PIX_FMT_XV15M:
+   *numerator = 10;
+   *denominator = 8;
+   break;
+   default:
+   *numerator   = 1;
+   *denominator = 1;
+   break;
+   }
+}
+EXPORT_SYMBOL_GPL(xvip_bpl_scaling_factor);
+
+/**
+ * xvip_width_padding_factor - Retrieve width's padding factor for a 4CC
+ * @fourcc: the format 4CC
+ *
+ * Return: Return numerator and denominator values by address
+ */
+void xvip_width_padding_factor(u32 fourcc, u32 *numerator, u32 *denominator)
+{
+   switch (fourcc) {
+   case V4L2_PIX_FMT_XV15M:
+   /* 32 bits are required per 30 bits of data */
+   *numerator = 32;
+   *denominator = 30;
+   break;
+   default:
+   *numerator   = 1;
+   *denominator = 1;
+   break;
+   }
+}
+EXPORT_SYMBOL_GPL(xvip_width_padding_factor);
+
+/**
  * xvip_of_get_format - Parse a device tree node and return format information
  * @node: the device tree node
  *
diff --git a/drivers/media/platform/xilinx/xilinx-vip.h 
b/drivers/media/platform/xilinx/xilinx-vip.h
index 006dcf77..26fada7 100644
--- a/drivers/media/platform/xilinx/xilinx-vip.h
+++ b/drivers/media/platform/xilinx/xilinx-vip.h
@@ -135,6 +135,8 @@ struct xvip_video_format {
 const struct xvip_video_format *xvip_get_format_by_code(unsigned int code);
 const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc);
 const struct xvip_video_format *xvip_of_get_format(struct device_node *node);
+void xvip_bpl_scaling_factor(u32 fourcc, u32 *numerator, u32 *denominator);
+void xvip_width_padding_factor(u32 fourcc, u32 *numerator, u32 *denominator);
 void xvip_set_format_size(struct v4l2_mbus_framefmt *format,
  const struct v4l2_subdev_format *fmt);
 int xvip_enum_mbus_code(struct v4l2_subdev *subdev,
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 7/9] v4l: xilinx: dma: Add multi-planar support

2018-02-14 Thread Satish Kumar Nagireddy
The current v4l driver supports single plane formats. This patch
will add support to handle multi-planar formats. Updated driver
capabilities to multi-planar, where it can handle both single and
multi-planar formats

Signed-off-by: Satish Kumar Nagireddy 
---
 drivers/media/platform/xilinx/xilinx-dma.c  | 341 +++-
 drivers/media/platform/xilinx/xilinx-dma.h  |   2 +-
 drivers/media/platform/xilinx/xilinx-vipp.c |  22 +-
 3 files changed, 307 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/xilinx/xilinx-dma.c 
b/drivers/media/platform/xilinx/xilinx-dma.c
index cb20ada..664981b 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -63,6 +63,7 @@ static int xvip_dma_verify_format(struct xvip_dma *dma)
struct v4l2_subdev_format fmt;
struct v4l2_subdev *subdev;
int ret;
+   int width, height;

subdev = xvip_dma_remote_subdev(>pad, );
if (subdev == NULL)
@@ -73,9 +74,18 @@ static int xvip_dma_verify_format(struct xvip_dma *dma)
if (ret < 0)
return ret == -ENOIOCTLCMD ? -EINVAL : ret;

-   if (dma->fmtinfo->code != fmt.format.code ||
-   dma->format.height != fmt.format.height ||
-   dma->format.width != fmt.format.width)
+   if (dma->fmtinfo->code != fmt.format.code)
+   return -EINVAL;
+
+   if (V4L2_TYPE_IS_MULTIPLANAR(dma->format.type)) {
+   width = dma->format.fmt.pix_mp.width;
+   height = dma->format.fmt.pix_mp.height;
+   } else {
+   width = dma->format.fmt.pix.width;
+   height = dma->format.fmt.pix.height;
+   }
+
+   if (width != fmt.format.width || height != fmt.format.height)
return -EINVAL;

return 0;
@@ -302,6 +312,8 @@ static void xvip_dma_complete(void *param)
 {
struct xvip_dma_buffer *buf = param;
struct xvip_dma *dma = buf->dma;
+   u8 num_planes, i;
+   int sizeimage;

spin_lock(>queued_lock);
list_del(>queue);
@@ -310,7 +322,28 @@ static void xvip_dma_complete(void *param)
buf->buf.field = V4L2_FIELD_NONE;
buf->buf.sequence = dma->sequence++;
buf->buf.vb2_buf.timestamp = ktime_get_ns();
-   vb2_set_plane_payload(>buf.vb2_buf, 0, dma->format.sizeimage);
+
+   if (V4L2_TYPE_IS_MULTIPLANAR(dma->format.type)) {
+   /* Handling contiguous data with mplanes */
+   if (dma->fmtinfo->buffers == 1) {
+   sizeimage =
+   dma->format.fmt.pix_mp.plane_fmt[0].sizeimage;
+   vb2_set_plane_payload(>buf.vb2_buf, 0, sizeimage);
+   } else {
+   /* Handling non-contiguous data with mplanes */
+   num_planes = dma->format.fmt.pix_mp.num_planes;
+   for (i = 0; i < num_planes; i++) {
+   sizeimage =
+dma->format.fmt.pix_mp.plane_fmt[i].sizeimage;
+   vb2_set_plane_payload(>buf.vb2_buf, i,
+ sizeimage);
+   }
+   }
+   } else {
+   sizeimage = dma->format.fmt.pix.sizeimage;
+   vb2_set_plane_payload(>buf.vb2_buf, 0, sizeimage);
+   }
+
vb2_buffer_done(>buf.vb2_buf, VB2_BUF_STATE_DONE);
 }

@@ -320,13 +353,48 @@ xvip_dma_queue_setup(struct vb2_queue *vq,
 unsigned int sizes[], struct device *alloc_devs[])
 {
struct xvip_dma *dma = vb2_get_drv_priv(vq);
+   u8 i;
+   int sizeimage;
+
+   /* Multi planar case: Make sure the image size is large enough */
+   if (V4L2_TYPE_IS_MULTIPLANAR(dma->format.type)) {
+   if (*nplanes) {
+   if (*nplanes != dma->format.fmt.pix_mp.num_planes)
+   return -EINVAL;
+
+   for (i = 0; i < *nplanes; i++) {
+sizeimage =
+ dma->format.fmt.pix_mp.plane_fmt[i].sizeimage;
+   if (sizes[i] < sizeimage)
+   return -EINVAL;
+   }
+   } else {
+   /* Handling contiguous data with mplanes */
+   if (dma->fmtinfo->buffers == 1) {
+   *nplanes = 1;
+   sizes[0] =
+ dma->format.fmt.pix_mp.plane_fmt[0].sizeimage;
+   return 0;
+   } else {
+   /* Handling non-contiguous data with mplanes */
+   *nplanes = dma->format.fmt.pix_mp.num_planes;
+   for (i = 0; i < *nplanes; i++) {
+sizeimage =
+ 

[PATCH v3 5/9] [media] Add documentation for YUV420 bus format

2018-02-14 Thread Satish Kumar Nagireddy
The code is MEDIA_BUS_FMT_VYYUYY8_1X24

Signed-off-by: Satish Kumar Nagireddy 
---
 Documentation/media/uapi/v4l/subdev-formats.rst | 34 +
 1 file changed, 34 insertions(+)

diff --git a/Documentation/media/uapi/v4l/subdev-formats.rst 
b/Documentation/media/uapi/v4l/subdev-formats.rst
index b1eea44..afff6d5 100644
--- a/Documentation/media/uapi/v4l/subdev-formats.rst
+++ b/Documentation/media/uapi/v4l/subdev-formats.rst
@@ -7283,6 +7283,40 @@ The following table list existing packed 48bit wide YUV 
formats.
   - y\ :sub:`1`
   - y\ :sub:`0`

+  - MEDIA_BUS_FMT_VYYUYY8_1X24
+  - 0x202c
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - v\ :sub:`3`
+  - v\ :sub:`2`
+  - v\ :sub:`1`
+  - v\ :sub:`0`
+  - y\ :sub:`7`
+  - y\ :sub:`6`
+  - y\ :sub:`5`
+  - y\ :sub:`4`
+  - y\ :sub:`3`
+  - y\ :sub:`2`
+  - y\ :sub:`1`
+  - y\ :sub:`0`
+  - u\ :sub:`3`
+  - u\ :sub:`2`
+  - u\ :sub:`1`
+  - u\ :sub:`0`
+  - y\ :sub:`7`
+  - y\ :sub:`6`
+  - y\ :sub:`5`
+  - y\ :sub:`4`
+  - y\ :sub:`3`
+  - y\ :sub:`2`
+  - y\ :sub:`1`
+  - y\ :sub:`0`

 .. raw:: latex

--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH v3 0/9] Add support for multi-planar formats and 10 bit formats

2018-02-14 Thread Satish Kumar Nagireddy
 The patches are for xilinx v4l. The patcheset enable support to handle 
multiplanar
 formats and 10 bit formats. The implemenation has handling of single plane 
formats
 too for backward compatibility of some existing applications.

 Some patches are included as dependencies and are intended to sync downstream 
with
 upstream as well.

Hyun Kwon (1):
  media: xilinx: vip: Add the pixel format for RGB24

Jeffrey Mouroux (1):
  uapi: media: New fourcc codes needed by Xilinx Video IP

Radhey Shyam Pandey (1):
  v4l: xilinx: dma: Remove colorspace check in xvip_dma_verify_format

Rohit Athavale (1):
  media-bus: uapi: Add YCrCb 420 media bus format

Satish Kumar Nagireddy (5):
  [media] Add documentation for YUV420 bus format
  v4l: xilinx: dma: Update video format descriptor
  v4l: xilinx: dma: Add multi-planar support
  v4l: xilinx: dma: Add scaling and padding factor functions
  v4l: xilinx: dma: Get scaling and padding factor to calculate DMA params

 drivers/media/platform/xilinx/xilinx-dma.c  | 365 
 drivers/media/platform/xilinx/xilinx-dma.h  |   2 +-
 drivers/media/platform/xilinx/xilinx-vip.c  |  61 -
 drivers/media/platform/xilinx/xilinx-vip.h  |  13 +-
 drivers/media/platform/xilinx/xilinx-vipp.c |  22 +-
 include/uapi/linux/media-bus-format.h   |   3 +-
 include/uapi/linux/videodev2.h  |  11 +
 7 files changed, 409 insertions(+), 68 deletions(-)

--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


cron job: media_tree daily build: ERRORS

2018-02-14 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Thu Feb 15 05:00:11 CET 2018
media-tree git hash:29422737017b866d4a51014cc7522fa3a99e8852
media_build git hash:   0e5cdef4c99fc927bcf7a216215a323ac85d1d3a
v4l-utils git hash: 30fc3b396ad1daada9234f9f93fc30950c3d5470
gcc version:i686-linux-gcc (GCC) 7.3.0
sparse version: v0.5.0-3994-g45eb2282
smatch version: v0.5.0-3994-g45eb2282
host hardware:  x86_64
host os:4.14.0-3-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-arm64: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.0.60-x86_64: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.98-i686: ERRORS
linux-3.2.98-x86_64: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-i686: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-i686: ERRORS
linux-3.9.2-x86_64: ERRORS
linux-3.10.1-i686: ERRORS
linux-3.10.1-x86_64: ERRORS
linux-3.11.1-i686: ERRORS
linux-3.11.1-x86_64: ERRORS
linux-3.12.67-i686: ERRORS
linux-3.12.67-x86_64: ERRORS
linux-3.13.11-i686: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.53-i686: WARNINGS
linux-3.16.53-x86_64: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.93-i686: WARNINGS
linux-3.18.93-x86_64: WARNINGS
linux-3.19-i686: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.49-i686: WARNINGS
linux-4.1.49-x86_64: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.115-i686: OK
linux-4.4.115-x86_64: OK
linux-4.5.7-i686: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-i686: OK
linux-4.7.5-x86_64: WARNINGS
linux-4.8-i686: OK
linux-4.8-x86_64: WARNINGS
linux-4.9.80-i686: OK
linux-4.9.80-x86_64: OK
linux-4.10.14-i686: OK
linux-4.10.14-x86_64: WARNINGS
linux-4.11-i686: OK
linux-4.11-x86_64: WARNINGS
linux-4.12.1-i686: OK
linux-4.12.1-x86_64: WARNINGS
linux-4.13-i686: OK
linux-4.13-x86_64: OK
linux-4.14.17-i686: OK
linux-4.14.17-x86_64: OK
linux-4.15.2-i686: OK
linux-4.15.2-x86_64: OK
linux-4.16-rc1-i686: OK
linux-4.16-rc1-x86_64: OK
apps: WARNINGS
spec-git: OK
sparse: WARNINGS
smatch: OK

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


[PATCH v11 1/8] v4l2-dv-timings: add v4l2_hdmi_colorimetry()

2018-02-14 Thread Tim Harvey
From: Hans Verkuil 

Add the v4l2_hdmi_colorimetry() function so we have a single function
that determines the colorspace, YCbCr encoding, quantization range and
transfer function from the InfoFrame data.

Cc: Randy Dunlap 
Signed-off-by: Hans Verkuil 
---
v9:
 - fix kernel-doc format (Randy)

 drivers/media/v4l2-core/v4l2-dv-timings.c | 141 ++
 include/media/v4l2-dv-timings.h   |  21 +
 2 files changed, 162 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c 
b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 930f9c5..5663d86 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 MODULE_AUTHOR("Hans Verkuil");
 MODULE_DESCRIPTION("V4L2 DV Timings Helper Functions");
@@ -814,3 +815,143 @@ struct v4l2_fract v4l2_calc_aspect_ratio(u8 
hor_landscape, u8 vert_portrait)
return aspect;
 }
 EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio);
+
+/** v4l2_hdmi_rx_colorimetry - determine HDMI colorimetry information
+ * based on various InfoFrames.
+ * @avi: the AVI InfoFrame
+ * @hdmi: the HDMI Vendor InfoFrame, may be NULL
+ * @height: the frame height
+ *
+ * Determines the HDMI colorimetry information, i.e. how the HDMI
+ * pixel color data should be interpreted.
+ *
+ * Note that some of the newer features (DCI-P3, HDR) are not yet
+ * implemented: the hdmi.h header needs to be updated to the HDMI 2.0
+ * and CTA-861-G standards.
+ */
+struct v4l2_hdmi_colorimetry
+v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi,
+const struct hdmi_vendor_infoframe *hdmi,
+unsigned int height)
+{
+   struct v4l2_hdmi_colorimetry c = {
+   V4L2_COLORSPACE_SRGB,
+   V4L2_YCBCR_ENC_DEFAULT,
+   V4L2_QUANTIZATION_FULL_RANGE,
+   V4L2_XFER_FUNC_SRGB
+   };
+   bool is_ce = avi->video_code || (hdmi && hdmi->vic);
+   bool is_sdtv = height <= 576;
+   bool default_is_lim_range_rgb = avi->video_code > 1;
+
+   switch (avi->colorspace) {
+   case HDMI_COLORSPACE_RGB:
+   /* RGB pixel encoding */
+   switch (avi->colorimetry) {
+   case HDMI_COLORIMETRY_EXTENDED:
+   switch (avi->extended_colorimetry) {
+   case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB:
+   c.colorspace = V4L2_COLORSPACE_ADOBERGB;
+   c.xfer_func = V4L2_XFER_FUNC_ADOBERGB;
+   break;
+   case HDMI_EXTENDED_COLORIMETRY_BT2020:
+   c.colorspace = V4L2_COLORSPACE_BT2020;
+   c.xfer_func = V4L2_XFER_FUNC_709;
+   break;
+   default:
+   break;
+   }
+   break;
+   default:
+   break;
+   }
+   switch (avi->quantization_range) {
+   case HDMI_QUANTIZATION_RANGE_LIMITED:
+   c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
+   break;
+   case HDMI_QUANTIZATION_RANGE_FULL:
+   break;
+   default:
+   if (default_is_lim_range_rgb)
+   c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
+   break;
+   }
+   break;
+
+   default:
+   /* YCbCr pixel encoding */
+   c.quantization = V4L2_QUANTIZATION_LIM_RANGE;
+   switch (avi->colorimetry) {
+   case HDMI_COLORIMETRY_NONE:
+   if (!is_ce)
+   break;
+   if (is_sdtv) {
+   c.colorspace = V4L2_COLORSPACE_SMPTE170M;
+   c.ycbcr_enc = V4L2_YCBCR_ENC_601;
+   } else {
+   c.colorspace = V4L2_COLORSPACE_REC709;
+   c.ycbcr_enc = V4L2_YCBCR_ENC_709;
+   }
+   c.xfer_func = V4L2_XFER_FUNC_709;
+   break;
+   case HDMI_COLORIMETRY_ITU_601:
+   c.colorspace = V4L2_COLORSPACE_SMPTE170M;
+   c.ycbcr_enc = V4L2_YCBCR_ENC_601;
+   c.xfer_func = V4L2_XFER_FUNC_709;
+   break;
+   case HDMI_COLORIMETRY_ITU_709:
+   c.colorspace = V4L2_COLORSPACE_REC709;
+   c.ycbcr_enc = V4L2_YCBCR_ENC_709;
+   c.xfer_func = V4L2_XFER_FUNC_709;
+   break;
+   case HDMI_COLORIMETRY_EXTENDED:
+   switch 

[PATCH v11 0/8] TDA1997x HDMI video reciver

2018-02-14 Thread Tim Harvey
This is a v4l2 subdev driver supporting the TDA1997x HDMI video receiver.

I've tested this on a Gateworks GW54xx/GW551x with an IMX6Q/IMX6DL which
uses the TDA19971 with 16bits connected to the IMX6 CSI and single-lane
I2S audio providing 2-channel audio.

For this configuration I've tested both 16bit YUV422 and 8bit
BT656 parallel video bus modes.

While the driver should support the TDA1993 I do not have one for testing.

Further potential development efforts include:
 - CEC support
 - HDCP support
 - TDA19972 support (2 inputs)

Media graphs can be found at http://dev.gateworks.com/docs/linux/media

See details below for configuration and compliance tests

History:
v11:
 - return -ERANGE from tda1997x_detect_std (Hans)
 - clean up tda1997x_g_input_status (Hans)
 - show detected timings on resolution change if debug enabled
 - fix unitialized ret var in tda1997x_query_dv_timings
 - update log status to show detected timings

v10:
 - removed unnecessary check for !timings in get/set/query dv timings (Hans)
 - dropped pointless s_stream handler (Hans)
 - remove need for detected_timings and always use set timings (Hans)

v9:
 - add digital video decoder video interface entity function

v8:
 - fix clearing pad for VIDIOC_DV_TIMIGNS_CAP
 - support full range of input modes based on timings_cap
 - add patch to fix clearing pad for VIDIOC_DV_TIMIGINGS
 - fix available formats for tda19971 bt656 bus width >12
 - fix set_format (compliance)
 - fixed get/set edid (compliance)
 - add init_cfg to setup default pad config (compliance)
 - added missing pad checks to get_dv_timings_cap/enum_dv_timings (compliance)
 - fix alignment of if statement and whitespace in comment (Hans)
 - move regs to tda1997x_regs.h to clean up (Hans)
 - add define and sanity check for num of mbus_codes (Hans)

v7:
 - fix interlaced mode
 - support no AVI infoframe (ie DVI) (Hans)
 - add support for multiple output formats (Hans)

v6:
 - tda1997x: fix return on regulator enablei in tda1997x_set_power() (Fabio)
 - tda1997x: fix colorspace handling (Hans)
 - bindings: added Robs's ack (Rob)
 - replace copyright with SPDX tag (Philippe)

v5:
 - added v4l2_hdmi_colorimetry() patch from Hans to series
 - bindings: added Sakari's ack
 - tda1997x: uppercase string constants
 - tda1997x: use v4l2_hdmi_rx_coloriemtry to fill format
 - tda1997x: fix V4L2_CID_DV_RX_RGB_RANGE
 - tda1997x: fix interlaced mode format
 - dts: remove leading 0 from unit address
 - dts: add newline between property list and child node
 - dts: added missing audmux in GW551x dts

v4:
 - move include/dt-bindings/media/tda1997x.h to bindings patch
 - clarify port node details in bindings
 - fix typos
 - fix default quant range for VGA
 - fix quant range handling and conv matrix
 - add additional standards and capabilities to timings_cap

v3:
 - fix typo in dt bindings
 - added dt bindings for GW551x
 - use V4L2_DV_BT_FRAME_WIDTH/HEIGHT macros
 - fixed missing break
 - use only hdmi_infoframe_log for infoframe logging
 - simplify tda1997x_s_stream error handling
 - add delayed work proc to handle hotplug enable/disable
 - fix set_edid (disable HPD before writing, enable after)
 - remove enabling edid by default
 - initialize timings
 - take quant range into account in colorspace conversion
 - remove vendor/product tracking (we provide this in log_status via
   infoframes)
 - add v4l_controls
 - add more detail to log_status
 - calculate vhref generator timings
 - timing detection fixes (rounding errors, hswidth errors)
 - rename configure_input/configure_conv functions

v2:
 - encorporate feedback into dt bindings
 - change audio dt bindings
 - implement dv timings enum/cap
 - remove deprecated g_mbus_config op
 - fix dv_query_timings
 - add EDID get/set handling
 - remove max-pixel-rate support
 - add audio codec DAI support
 - added media-ctl and v4l2-compliance details

v1:
 - initial RFC

Pipeline configuration:
$ media-ctl -e 'tda19971 2-0048'
/dev/v4l-subdev1
$ v4l2-ctl -d /dev/v4l-subdev1 --set-dv-bt-timings=query
BT timings set
$ media-ctl --get-v4l2 '"tda19971 2-0048":0'
[fmt:UYVY8_2X8/1280x720 field:none colorspace:srgb]

$ media-ctl --link "tda19971 2-0048":0 -> "ipu1_csi0_mux":1[1]
$ media-ctl --link "ipu1_csi0_mux":2 -> "ipu1_csi0":0[1]
$ media-ctl --link "ipu1_csi0":2 -> "ipu1_csi0 capture":0[1]
$ media-ctl --set-v4l2 'tda19971 2-0048':0[fmt:UYVY8_2X8/1280x720]
$ media-ctl --set-v4l2 'ipu1_csi0_mux':2[fmt:UYVY8_2X8/1280x720]
$ media-ctl --set-v4l2 'ipu1_csi0':0[fmt:UYVY8_2X8/1280x720]
$ gst-launch-1.0 v4l2src device=/dev/video4 ! 
video/x-raw,width=1280,height=720,format=UYVY ! jpegenc ! rtpjpegpay ! udpsink 
host=172.24.40.6 port=5000

$ media-ctl -d /dev/media0 -p
Media controller API version 4.15.0

Media device information

driver  imx-media
model   imx-media
serial  
bus info
hw revision 0x0
driver version  4.15.0

Device topology
- entity 1: adv7180 2-0020 (1 pad, 1 link)
   

[PATCH v11 2/8] media: v4l-ioctl: fix clearing pad for VIDIOC_DV_TIMIGNS_CAP

2018-02-14 Thread Tim Harvey
Signed-off-by: Tim Harvey 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 7961499..5f3670d 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2638,7 +2638,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 
INFO_FL_QUEUE),
IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, 
v4l_print_enum_dv_timings, INFO_FL_CLEAR(v4l2_enum_dv_timings, pad)),
IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, 
v4l_print_dv_timings, INFO_FL_ALWAYS_COPY),
-   IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, 
v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)),
+   IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, 
v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, pad)),
IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, 
v4l_print_freq_band, 0),
IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, 
v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)),
IOCTL_INFO_FNC(VIDIOC_QUERY_EXT_CTRL, v4l_query_ext_ctrl, 
v4l_print_query_ext_ctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_query_ext_ctrl, 
id)),
-- 
2.7.4



[PATCH v11 3/8] media: add digital video decoder video interface entity functions

2018-02-14 Thread Tim Harvey
Add a new media entity function definition for digital TV decoders:
MEDIA_ENT_F_DTV_DECODER

Signed-off-by: Tim Harvey 
---
 Documentation/media/uapi/mediactl/media-types.rst | 11 +++
 include/uapi/linux/media.h|  5 +
 2 files changed, 16 insertions(+)

diff --git a/Documentation/media/uapi/mediactl/media-types.rst 
b/Documentation/media/uapi/mediactl/media-types.rst
index 8d64b0c..195400e 100644
--- a/Documentation/media/uapi/mediactl/media-types.rst
+++ b/Documentation/media/uapi/mediactl/media-types.rst
@@ -321,6 +321,17 @@ Types and flags used to represent the media graph elements
  MIPI CSI-2, ...), and outputs them on its source pad to an output
  video bus of another type (eDP, MIPI CSI-2, parallel, ...).
 
+-  ..  row 31
+
+   ..  _MEDIA-ENT-F-DTV-DECODER:
+
+   -  ``MEDIA_ENT_F_DTV_DECODER``
+
+   -  Digital video decoder. The basic function of the video decoder is
+ to accept digital video from a wide variety of sources
+ and output it in some digital video standard, with appropriate
+ timing signals.
+
 ..  tabularcolumns:: |p{5.5cm}|p{12.0cm}|
 
 .. _media-entity-flag:
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index b9b9446..2f12328 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -110,6 +110,11 @@ struct media_device_info {
 #define MEDIA_ENT_F_VID_IF_BRIDGE  (MEDIA_ENT_F_BASE + 0x5002)
 
 /*
+ * Digital video decoder entities
+ */
+#define MEDIA_ENT_F_DTV_DECODER(MEDIA_ENT_F_BASE + 
0x6001)
+
+/*
  * Connectors
  */
 /* It is a responsibility of the entity drivers to add connectors and links */
-- 
2.7.4



[PATCH v11 8/8] ARM: dts: imx: Add TDA19971 HDMI Receiver to GW551x

2018-02-14 Thread Tim Harvey
Signed-off-by: Tim Harvey 
---
v5:
 - add missing audmux config

 arch/arm/boot/dts/imx6qdl-gw551x.dtsi | 138 ++
 1 file changed, 138 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-gw551x.dtsi 
b/arch/arm/boot/dts/imx6qdl-gw551x.dtsi
index 30d4662..749548a 100644
--- a/arch/arm/boot/dts/imx6qdl-gw551x.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-gw551x.dtsi
@@ -46,6 +46,8 @@
  */
 
 #include 
+#include 
+#include 
 
 / {
/* these are used by bootloader for disabling nodes */
@@ -98,6 +100,50 @@
regulator-min-microvolt = <500>;
regulator-max-microvolt = <500>;
};
+
+   sound-digital {
+   compatible = "simple-audio-card";
+   simple-audio-card,name = "tda1997x-audio";
+
+   simple-audio-card,dai-link@0 {
+   format = "i2s";
+
+   cpu {
+   sound-dai = <>;
+   };
+
+   codec {
+   bitclock-master;
+   frame-master;
+   sound-dai = <>;
+   };
+   };
+   };
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_audmux>; /* AUD5<->tda1997x */
+   status = "okay";
+
+   ssi1 {
+   fsl,audmux-port = <0>;
+   fsl,port-config = <
+   (IMX_AUDMUX_V2_PTCR_TFSDIR |
+   IMX_AUDMUX_V2_PTCR_TFSEL(4+8) | /* RXFS */
+   IMX_AUDMUX_V2_PTCR_TCLKDIR |
+   IMX_AUDMUX_V2_PTCR_TCSEL(4+8) | /* RXC */
+   IMX_AUDMUX_V2_PTCR_SYN)
+   IMX_AUDMUX_V2_PDCR_RXDSEL(4)
+   >;
+   };
+
+   aud5 {
+   fsl,audmux-port = <4>;
+   fsl,port-config = <
+   IMX_AUDMUX_V2_PTCR_SYN
+   IMX_AUDMUX_V2_PDCR_RXDSEL(0)>;
+   };
 };
 
  {
@@ -263,6 +309,60 @@
#gpio-cells = <2>;
};
 
+   tda1997x: tda1997x@48 {
+   compatible = "nxp,tda19971";
+   pinctrl-names = "default";
+   pinctrl-0 = <_tda1997x>;
+   reg = <0x48>;
+   interrupt-parent = <>;
+   interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
+   DOVDD-supply = <_3p3>;
+   AVDD-supply = <_1p8b>;
+   DVDD-supply = <_1p8a>;
+   #sound-dai-cells = <0>;
+   nxp,audout-format = "i2s";
+   nxp,audout-layout = <0>;
+   nxp,audout-width = <16>;
+   nxp,audout-mclk-fs = <128>;
+   /*
+* The 8bpp YUV422 semi-planar mode outputs CbCr[11:4]
+* and Y[11:4] across 16bits in the same cycle
+* which we map to VP[15:08]<->CSI_DATA[19:12]
+*/
+   nxp,vidout-portcfg =
+   /*G_Y_11_8<->VP[15:12]<->CSI_DATA[19:16]*/
+   < TDA1997X_VP24_V15_12 TDA1997X_G_Y_11_8 >,
+   /*G_Y_7_4<->VP[11:08]<->CSI_DATA[15:12]*/
+   < TDA1997X_VP24_V11_08 TDA1997X_G_Y_7_4 >,
+   /*R_CR_CBCR_11_8<->VP[07:04]<->CSI_DATA[11:08]*/
+   < TDA1997X_VP24_V07_04 TDA1997X_R_CR_CBCR_11_8 >,
+   /*R_CR_CBCR_7_4<->VP[03:00]<->CSI_DATA[07:04]*/
+   < TDA1997X_VP24_V03_00 TDA1997X_R_CR_CBCR_7_4 >;
+
+   port {
+   tda1997x_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<_csi0_mux_from_parallel_sensor>;
+   bus-width = <16>;
+   hsync-active = <1>;
+   vsync-active = <1>;
+   data-active = <1>;
+   };
+   };
+   };
+};
+
+_csi0_from_ipu1_csi0_mux {
+   bus-width = <16>;
+};
+
+_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <_to_ipu1_csi0_mux>;
+   bus-width = <16>;
+};
+
+_csi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_ipu1_csi0>;
 };
 
  {
@@ -320,6 +420,14 @@
 };
 
  {
+   pinctrl_audmux: audmuxgrp {
+   fsl,pins = <
+   MX6QDL_PAD_DISP0_DAT19__AUD5_RXD0x130b0
+   MX6QDL_PAD_DISP0_DAT14__AUD5_RXC0x130b0
+   MX6QDL_PAD_DISP0_DAT13__AUD5_RXFS   0x130b0
+   >;
+   };
+
pinctrl_flexcan1: flexcan1grp {
fsl,pins = <
MX6QDL_PAD_KEY_ROW2__FLEXCAN1_RX0x1b0b1
@@ -375,6 +483,30 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1_csi0grp {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04  0x1b0b0
+   

[PATCH v11 6/8] media: i2c: Add TDA1997x HDMI receiver driver

2018-02-14 Thread Tim Harvey
Add support for the TDA1997x HDMI receivers.

Cc: Hans Verkuil 
Signed-off-by: Tim Harvey 
---
v11:
 - return -ERANGE from tda1997x_detect_std (Hans)
 - clean up tda1997x_g_input_status (Hans)
 - show detected timings on resolution change if debug enabled
 - fix unitialized ret var in tda1997x_query_dv_timings
 - update log status to show detected timings

v10:
 - removed unnecessary check for !timings in get/set/query dv timings (Hans)
 - dropped pointless s_stream handler (Hans)
 - remove need for detected_timings and always use set timings (Hans)

v9:
 - remove redundant pad bounds check already in v4l2-subdev.c
 - assign entity function (Hans)
 - properly assign/check/free ctrl_handler (Hans)
 - fixed typo 'Rull Range' -> 'Full Range'
 - update csc after quant range change

v8:
 - fix available formats for tda19971 bt656 bus width >12
 - support full range of input modes based on timings_cap
 - fix set_format (compliance)
 - fixed get/set edid (compliance)
 - add init_cfg to setup default pad config (compliance)
 - added missing pad checks to get_dv_timings_cap/enum_dv_timings (compliance)
 - fix alignment of if statement and whitespace in comment (Hans)
 - move regs to tda1997x_regs.h to clean up (Hans)
 - add define and sanity check for num of mbus_codes (Hans)

v7:
 - fix interlaced mode
 - support no AVI infoframe (ie DVI) (Hans)
 - add support for multiple output formats (Hans)

v6:
 - fix return on regulator enablei in tda1997x_set_power()
 - replace copyright with SPDX tag
 - fix colorspace handling

v5:
 - uppercase string constants
 - use v4l2_hdmi_rx_coloriemtry to fill format
 - fix V4L2_CID_DV_RX_RGB_RANGE
 - fix interlaced mode format

v4:
 - move include/dt-bindings/media/tda1997x.h to bindings patch
 - fix typos
 - fix default quant range for VGA
 - fix quant range handling and conv matrix
 - add additional standards and capabilities to timings_cap

v3:
 - use V4L2_DV_BT_FRAME_WIDTH/HEIGHT macros
 - fixed missing break
 - use only hdmi_infoframe_log for infoframe logging
 - simplify tda1997x_s_stream error handling
 - add delayed work proc to handle hotplug enable/disable
 - fix set_edid (disable HPD before writing, enable after)
 - remove enabling edid by default
 - initialize timings
 - take quant range into account in colorspace conversion
 - remove vendor/product tracking (we provide this in log_status via infoframes)
 - add v4l_controls
 - add more detail to log_status
 - calculate vhref generator timings
 - timing detection fixes (rounding errors, hswidth errors)
 - rename configure_input/configure_conv functions

v2:
 - implement dv timings enum/cap
 - remove deprecated g_mbus_config op
 - fix dv_query_timings
 - add EDID get/set handling
 - remove max-pixel-rate support
 - add audio codec DAI support
 - change audio bindings

 drivers/media/i2c/Kconfig |9 +
 drivers/media/i2c/Makefile|1 +
 drivers/media/i2c/tda1997x.c  | 2822 +
 drivers/media/i2c/tda1997x_regs.h |  641 +
 include/media/i2c/tda1997x.h  |   42 +
 5 files changed, 3515 insertions(+)
 create mode 100644 drivers/media/i2c/tda1997x.c
 create mode 100644 drivers/media/i2c/tda1997x_regs.h
 create mode 100644 include/media/i2c/tda1997x.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index cb5d7ff..3522641 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -56,6 +56,15 @@ config VIDEO_TDA9840
  To compile this driver as a module, choose M here: the
  module will be called tda9840.
 
+config VIDEO_TDA1997X
+   tristate "NXP TDA1997x HDMI receiver"
+   depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
+   ---help---
+ V4L2 subdevice driver for the NXP TDA1997x HDMI receivers.
+
+ To compile this driver as a module, choose M here: the
+ module will be called tda1997x.
+
 config VIDEO_TEA6415C
tristate "Philips TEA6415C audio processor"
depends on I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 548a9ef..adfcae9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o
 obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
 obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o
 obj-$(CONFIG_VIDEO_TDA9840) += tda9840.o
+obj-$(CONFIG_VIDEO_TDA1997X) += tda1997x.o
 obj-$(CONFIG_VIDEO_TEA6415C) += tea6415c.o
 obj-$(CONFIG_VIDEO_TEA6420) += tea6420.o
 obj-$(CONFIG_VIDEO_SAA7110) += saa7110.o
diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c
new file mode 100644
index 000..ce6b694
--- /dev/null
+++ b/drivers/media/i2c/tda1997x.c
@@ -0,0 +1,2822 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 Gateworks Corporation
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 

[PATCH v11 7/8] ARM: dts: imx: Add TDA19971 HDMI Receiver to GW54xx

2018-02-14 Thread Tim Harvey
The GW54xx has a front-panel microHDMI connector routed to a TDA19971
which is connected the the IPU CSI when using IMX6Q.

Signed-off-by: Tim Harvey 
---
v5:
 - remove leading 0 from unit address
 - add newline between property list and child node

v4: no changes
v3: no changes

v2:
 - add HDMI audio input support

 arch/arm/boot/dts/imx6q-gw54xx.dts| 105 ++
 arch/arm/boot/dts/imx6qdl-gw54xx.dtsi |  29 +-
 2 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/imx6q-gw54xx.dts 
b/arch/arm/boot/dts/imx6q-gw54xx.dts
index 56e5b50..0477120 100644
--- a/arch/arm/boot/dts/imx6q-gw54xx.dts
+++ b/arch/arm/boot/dts/imx6q-gw54xx.dts
@@ -12,10 +12,30 @@
 /dts-v1/;
 #include "imx6q.dtsi"
 #include "imx6qdl-gw54xx.dtsi"
+#include 
 
 / {
model = "Gateworks Ventana i.MX6 Dual/Quad GW54XX";
compatible = "gw,imx6q-gw54xx", "gw,ventana", "fsl,imx6q";
+
+   sound-digital {
+   compatible = "simple-audio-card";
+   simple-audio-card,name = "tda1997x-audio";
+
+   simple-audio-card,dai-link@0 {
+   format = "i2s";
+
+   cpu {
+   sound-dai = <>;
+   };
+
+   codec {
+   bitclock-master;
+   frame-master;
+   sound-dai = <>;
+   };
+   };
+   };
 };
 
  {
@@ -35,6 +55,61 @@
};
};
};
+
+   tda1997x: codec@48 {
+   compatible = "nxp,tda19971";
+   pinctrl-names = "default";
+   pinctrl-0 = <_tda1997x>;
+   reg = <0x48>;
+   interrupt-parent = <>;
+   interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
+   DOVDD-supply = <_3p3v>;
+   AVDD-supply = <_reg>;
+   DVDD-supply = <_reg>;
+   #sound-dai-cells = <0>;
+   nxp,audout-format = "i2s";
+   nxp,audout-layout = <0>;
+   nxp,audout-width = <16>;
+   nxp,audout-mclk-fs = <128>;
+   /*
+* The 8bpp YUV422 semi-planar mode outputs CbCr[11:4]
+* and Y[11:4] across 16bits in the same cycle
+* which we map to VP[15:08]<->CSI_DATA[19:12]
+*/
+   nxp,vidout-portcfg =
+   /*G_Y_11_8<->VP[15:12]<->CSI_DATA[19:16]*/
+   < TDA1997X_VP24_V15_12 TDA1997X_G_Y_11_8 >,
+   /*G_Y_7_4<->VP[11:08]<->CSI_DATA[15:12]*/
+   < TDA1997X_VP24_V11_08 TDA1997X_G_Y_7_4 >,
+   /*R_CR_CBCR_11_8<->VP[07:04]<->CSI_DATA[11:08]*/
+   < TDA1997X_VP24_V07_04 TDA1997X_R_CR_CBCR_11_8 >,
+   /*R_CR_CBCR_7_4<->VP[03:00]<->CSI_DATA[07:04]*/
+   < TDA1997X_VP24_V03_00 TDA1997X_R_CR_CBCR_7_4 >;
+
+   port {
+   tda1997x_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<_csi0_mux_from_parallel_sensor>;
+   bus-width = <16>;
+   hsync-active = <1>;
+   vsync-active = <1>;
+   data-active = <1>;
+   };
+   };
+   };
+};
+
+_csi0_from_ipu1_csi0_mux {
+   bus-width = <16>;
+};
+
+_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <_to_ipu1_csi0_mux>;
+   bus-width = <16>;
+};
+
+_csi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_ipu1_csi0>;
 };
 
 _csi1_from_ipu2_csi1_mux {
@@ -63,6 +138,30 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1_csi0grp {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT5__IPU1_CSI0_DATA05  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT6__IPU1_CSI0_DATA06  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT7__IPU1_CSI0_DATA07  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT8__IPU1_CSI0_DATA08  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT9__IPU1_CSI0_DATA09  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT10__IPU1_CSI0_DATA10 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT11__IPU1_CSI0_DATA11 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15 0x1b0b0
+   MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16 0x1b0b0
+   

[PATCH v11 5/8] media: dt-bindings: Add bindings for TDA1997X

2018-02-14 Thread Tim Harvey
Acked-by: Rob Herring 
Acked-by: Sakari Ailus 
Signed-off-by: Tim Harvey 
---
v6:
 - replace copyright with SPDX tag
 - added Rob's ack

v5:
 - added Sakari's ack

v4:
 - move include/dt-bindings/media/tda1997x.h to bindings patch
 - clarify port node details

v3:
 - fix typo

v2:
 - add vendor prefix and remove _ from vidout-portcfg
 - remove _ from labels
 - remove max-pixel-rate property
 - describe and provide example for single output port
 - update to new audio port bindings

 .../devicetree/bindings/media/i2c/tda1997x.txt | 179 +
 include/dt-bindings/media/tda1997x.h   |  74 +
 2 files changed, 253 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/tda1997x.txt
 create mode 100644 include/dt-bindings/media/tda1997x.h

diff --git a/Documentation/devicetree/bindings/media/i2c/tda1997x.txt 
b/Documentation/devicetree/bindings/media/i2c/tda1997x.txt
new file mode 100644
index 000..9ab53c3
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/tda1997x.txt
@@ -0,0 +1,179 @@
+Device-Tree bindings for the NXP TDA1997x HDMI receiver
+
+The TDA19971/73 are HDMI video receivers.
+
+The TDA19971 Video port output pins can be used as follows:
+ - RGB 8bit per color (24 bits total): R[11:4] B[11:4] G[11:4]
+ - YUV444 8bit per color (24 bits total): Y[11:4] Cr[11:4] Cb[11:4]
+ - YUV422 semi-planar 8bit per component (16 bits total): Y[11:4] CbCr[11:4]
+ - YUV422 semi-planar 10bit per component (20 bits total): Y[11:2] CbCr[11:2]
+ - YUV422 semi-planar 12bit per component (24 bits total): - Y[11:0] CbCr[11:0]
+ - YUV422 BT656 8bit per component (8 bits total): YCbCr[11:4] (2-cycles)
+ - YUV422 BT656 10bit per component (10 bits total): YCbCr[11:2] (2-cycles)
+ - YUV422 BT656 12bit per component (12 bits total): YCbCr[11:0] (2-cycles)
+
+The TDA19973 Video port output pins can be used as follows:
+ - RGB 12bit per color (36 bits total): R[11:0] B[11:0] G[11:0]
+ - YUV444 12bit per color (36 bits total): Y[11:0] Cb[11:0] Cr[11:0]
+ - YUV422 semi-planar 12bit per component (24 bits total): Y[11:0] CbCr[11:0]
+ - YUV422 BT656 12bit per component (12 bits total): YCbCr[11:0] (2-cycles)
+
+The Video port output pins are mapped via 4-bit 'pin groups' allowing
+for a variety of connection possibilities including swapping pin order within
+pin groups. The video_portcfg device-tree property consists of register mapping
+pairs which map a chip-specific VP output register to a 4-bit pin group. If
+the pin group needs to be bit-swapped you can use the *_S pin-group defines.
+
+Required Properties:
+ - compatible  :
+  - "nxp,tda19971" for the TDA19971
+  - "nxp,tda19973" for the TDA19973
+ - reg : I2C slave address
+ - interrupts  : The interrupt number
+ - DOVDD-supply: Digital I/O supply
+ - DVDD-supply : Digital Core supply
+ - AVDD-supply : Analog supply
+ - nxp,vidout-portcfg  : array of pairs mapping VP output pins to pin groups.
+
+Optional Properties:
+ - nxp,audout-format   : DAI bus format: "i2s" or "spdif".
+ - nxp,audout-width: width of audio output data bus (1-4).
+ - nxp,audout-layout   : data layout (0=AP0 used, 1=AP0/AP1/AP2/AP3 used).
+ - nxp,audout-mclk-fs  : Multiplication factor between stream rate and codec
+ mclk.
+
+The port node shall contain one endpoint child node for its digital
+output video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Optional Endpoint Properties:
+  The following three properties are defined in video-interfaces.txt and
+  are valid for the output parallel bus endpoint:
+  - hsync-active: Horizontal synchronization polarity. Defaults to active high.
+  - vsync-active: Vertical synchronization polarity. Defaults to active high.
+  - data-active: Data polarity. Defaults to active high.
+
+Examples:
+ - VP[15:0] connected to IMX6 CSI_DATA[19:4] for 16bit YUV422
+   16bit I2S layout0 with a 128*fs clock (A_WS, AP0, A_CLK pins)
+   hdmi-receiver@48 {
+   compatible = "nxp,tda19971";
+   pinctrl-names = "default";
+   pinctrl-0 = <_tda1997x>;
+   reg = <0x48>;
+   interrupt-parent = <>;
+   interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
+   DOVDD-supply = <_3p3v>;
+   AVDD-supply = <_1p8v>;
+   DVDD-supply = <_1p8v>;
+   /* audio */
+   #sound-dai-cells = <0>;
+   nxp,audout-format = "i2s";
+   nxp,audout-layout = <0>;
+   nxp,audout-width = <16>;
+   nxp,audout-mclk-fs = <128>;
+   /*
+* The 8bpp YUV422 semi-planar mode outputs CbCr[11:4]
+* and Y[11:4] across 16bits in the same pixclk cycle.
+*/
+   nxp,vidout-portcfg =
+  

[PATCH v11 4/8] MAINTAINERS: add entry for NXP TDA1997x driver

2018-02-14 Thread Tim Harvey
Signed-off-by: Tim Harvey 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 845fc25..439b500 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13262,6 +13262,14 @@ T: git git://linuxtv.org/mkrufky/tuners.git
 S: Maintained
 F: drivers/media/tuners/tda18271*
 
+TDA1997x MEDIA DRIVER
+M: Tim Harvey 
+L: linux-media@vger.kernel.org
+W: https://linuxtv.org
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+S: Maintained
+F: drivers/media/i2c/tda1997x.*
+
 TDA827x MEDIA DRIVER
 M: Michael Krufky 
 L: linux-media@vger.kernel.org
-- 
2.7.4



Re: [PATCH] staging: media: reformat line to 80 chars or less

2018-02-14 Thread Steve Longerbeam

Hi Parthiban, please rename the commit title to

"media: imx: capture: reformat line to 80 chars or less"

Otherwise it is fine with me.

Steve


On 02/12/2018 04:05 AM, Parthiban Nallathambi wrote:

This is a cleanup patch to fix line length issue found
by checkpatch.pl script.

In this patch, line 144 have been wrapped.

Signed-off-by: Parthiban Nallathambi 
---
  drivers/staging/media/imx/imx-media-capture.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c 
b/drivers/staging/media/imx/imx-media-capture.c
index 576bdc7e9c42..0ccabe04b0e1 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -141,7 +141,8 @@ static int capture_enum_frameintervals(struct file *file, 
void *fh,
  
  	fie.code = cc->codes[0];
  
-	ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_interval, NULL, );

+   ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_interval,
+  NULL, );
if (ret)
return ret;
  




Re: [GIT PULL FOR v4.17] rc changes

2018-02-14 Thread Sean Young
Hi Mauro,

On Wed, Feb 14, 2018 at 04:44:48PM -0200, Mauro Carvalho Chehab wrote:
> Hi Sean,
> 
> Em Mon, 12 Feb 2018 20:03:18 +
> Sean Young  escreveu:
> 
> > Hi Mauro,
> > 
> > Just very minor changes this time (other stuff is not ready yet). I would
> > really appreciate if you could cast an extra critical eye on the commit 
> > "no need to check for transitions", just to be sure it is the right change.
> 
> Did you send all patches in separate? This is important to allow us
> to comment on an specific issue inside a patch...

All the patches were emailed to linux-media, some of them on the same day
as the pull request. Maybe I should wait longer. The patch below was sent
out on the 28th of January.

> >   media: rc: no need to check for transitions
> 
> I don't remember the exact reason for that, but, as far as I
> remember, on a few devices, a pulse (or space) event could be
> broken into two consecutive events of the same type, e. g.,
> a pulse with a 125 ms could be broken into two pulses, like
> one with 100 ms and the other with 25 ms.

If that is the case, then the IR decoders could not deal with this anyway.
For example, the first state transition rc6 is:

if (!eq_margin(ev.duration, RC6_PREFIX_PULSE, RC6_UNIT))

So if ev.duration is not the complete duration, then decoding will fail;
I tried to explain in the commit message that if this was the case, then
decoding would not work so the check was unnecessary.

> That's said, I'm not sure if the current implementation are
> adding the timings for both pulses into a single one.

That depends on whether the driver uses ir_raw_event_store() or
ir_raw_event_store_with_filter(). The latter exists precisely for this
reason.

> For now, I'll keep this patch out of the merge.

Ok. So in summary, I think:

1. Any driver which produces consequentive pulse events is broken
   and should be fixed;
2. The IR decoders cannot deal with consequentive pulses and the current
   prev_ev code does not help with this (possibly in very special
   cases).


Sean


Re: [PATCH] staging: imx-media-vdic: fix inconsistent IS_ERR and PTR_ERR

2018-02-14 Thread Gustavo A. R. Silva

Hi all,

I was just wondering about the status of this patch.

Thanks
--
Gustavo

On 01/24/2018 06:14 PM, Steve Longerbeam wrote:

Acked-by: Steve Longerbeam 


On 01/23/2018 04:43 PM, Gustavo A. R. Silva wrote:

Fix inconsistent IS_ERR and PTR_ERR in vdic_get_ipu_resources.
The proper pointer to be passed as argument is ch.

This issue was detected with the help of Coccinelle.

Fixes: 0b2e9e7947e7 ("media: staging/imx: remove confusing 
IS_ERR_OR_NULL usage")

Signed-off-by: Gustavo A. R. Silva 
---
  drivers/staging/media/imx/imx-media-vdic.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-vdic.c 
b/drivers/staging/media/imx/imx-media-vdic.c

index 433474d..ed35684 100644
--- a/drivers/staging/media/imx/imx-media-vdic.c
+++ b/drivers/staging/media/imx/imx-media-vdic.c
@@ -177,7 +177,7 @@ static int vdic_get_ipu_resources(struct vdic_priv 
*priv)

  priv->vdi_in_ch = ch;
  ch = ipu_idmac_get(priv->ipu, IPUV3_CHANNEL_MEM_VDI_NEXT);
-    if (IS_ERR(priv->vdi_in_ch_n)) {
+    if (IS_ERR(ch)) {
  err_chan = IPUV3_CHANNEL_MEM_VDI_NEXT;
  ret = PTR_ERR(ch);
  goto out_err_chan;






Re: [GIT PULL FOR v4.17] rc changes

2018-02-14 Thread Mauro Carvalho Chehab
Em Mon, 12 Feb 2018 20:03:18 +
Sean Young  escreveu:

>   media: rc: unnecessary use of do_div
> 
> From c52920c524d96db55b9b82440504a7ec40df0b32 Mon Sep 17 00:00:00 2001
> From: Sean Young 
> Date: Sun, 11 Feb 2018 17:23:14 +
> Subject: media: rc: unnecessary use of do_div
> Cc: Linux Media Mailing List ,
> Mauro Carvalho Chehab 
> 
> No need to use do_div() when the remainder is thrown away.

That's not true at all! We need do_div() every time we're dividing an u64
number, as otherwise, it will cause link errors when built with 32 bits.



Thanks,
Mauro


Re: [GIT PULL FOR v4.17] rc changes

2018-02-14 Thread Mauro Carvalho Chehab
Hi Sean,

Em Mon, 12 Feb 2018 20:03:18 +
Sean Young  escreveu:

> Hi Mauro,
> 
> Just very minor changes this time (other stuff is not ready yet). I would
> really appreciate if you could cast an extra critical eye on the commit 
> "no need to check for transitions", just to be sure it is the right change.

Did you send all patches in separate? This is important to allow us
to comment on an specific issue inside a patch...

>   media: rc: no need to check for transitions

I don't remember the exact reason for that, but, as far as I
remember, on a few devices, a pulse (or space) event could be
broken into two consecutive events of the same type, e. g.,
a pulse with a 125 ms could be broken into two pulses, like
one with 100 ms and the other with 25 ms.

That's said, I'm not sure if the current implementation are
adding the timings for both pulses into a single one.

For now, I'll keep this patch out of the merge.

Thanks,
Mauro


Assalamu`Alaikum.

2018-02-14 Thread Mohammad Ouattara
Dear Sir/Madam.

Assalamu`Alaikum.

I am Dr mohammad ouattara, I have  ($14.6 Million us dollars) to
transfer into your account,

I will send you more details about this deal and the procedures to
follow when I receive a positive response from you,

Have a great day,
Dr mohammad ouattara.


Re: [PATCH v4 16/18] scripts: kernel-doc: improve nested logic to handle multiple identifiers

2018-02-14 Thread Jani Nikula
On Wed, 14 Feb 2018, Mauro Carvalho Chehab  wrote:
> There is a simple fix, though. Make inline comments to accept a dot:
>
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
> index fee8952037b1..06d7f3f2c094 100755
> --- a/scripts/kernel-doc
> +++ b/scripts/kernel-doc
> @@ -363,7 +363,7 @@ my $doc_sect = $doc_com .
>  my $doc_content = $doc_com_body . '(.*)';
>  my $doc_block = $doc_com . 'DOC:\s*(.*)?';
>  my $doc_inline_start = '^\s*/\*\*\s*$';
> -my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
> +my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
>  my $doc_inline_end = '^\s*\*/\s*$';
>  my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
>  my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
>
> That requires a small change at the inline parameters, though:
>
> diff --git a/drivers/gpu/drm/i915/intel_dpio_phy.c 
> b/drivers/gpu/drm/i915/intel_dpio_phy.c
> index 76473e9836c6..c8e9e44e5981 100644
> --- a/drivers/gpu/drm/i915/intel_dpio_phy.c
> +++ b/drivers/gpu/drm/i915/intel_dpio_phy.c
> @@ -147,7 +147,7 @@ struct bxt_ddi_phy_info {
>*/
>   struct {
>   /**
> -  * @port: which port maps to this channel.
> +  * @channel.port: which port maps to this channel.
>*/
>   enum port port;
>   } channel[2];

Perhaps it would be slightly more elegant to be able to leave out
"channel." here and deduce that from the context... but the above
matches what you'd write in the higher level struct comment, and
produces the same output. It works and it's really simple. I like it.

Please submit this as a proper patch, with

Tested-by: Jani Nikula 

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center


Re: [PATCH 2/7] include/(uapi/)media: add SPDX license info

2018-02-14 Thread Hans Verkuil
On 14/02/18 19:12, Mauro Carvalho Chehab wrote:
> Em Wed,  7 Feb 2018 15:39:34 +0100
> Hans Verkuil  escreveu:
> 
>> From: Hans Verkuil 
>>
>> Replace the old license information with the corresponding SPDX
>> license for those headers that I authored.
>>
>> Signed-off-by: Hans Verkuil 
> 
> ...
> 
>> diff --git a/include/uapi/linux/cec.h b/include/uapi/linux/cec.h
>> index b51fbe1941a7..20fe091b7e96 100644
>> --- a/include/uapi/linux/cec.h
>> +++ b/include/uapi/linux/cec.h
>> @@ -3,35 +3,6 @@
>>   * cec - HDMI Consumer Electronics Control public header
>>   *
>>   * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights 
>> reserved.
>> - *
>> - * This program is free software; you may redistribute it and/or modify
>> - * it under the terms of the GNU General Public License as published by
>> - * the Free Software Foundation; version 2 of the License.
>> - *
>> - * Alternatively you can redistribute this file under the terms of the
>> - * BSD license as stated below:
>> - *
>> - * Redistribution and use in source and binary forms, with or without
>> - * modification, are permitted provided that the following conditions
>> - * are met:
>> - * 1. Redistributions of source code must retain the above copyright
>> - *notice, this list of conditions and the following disclaimer.
>> - * 2. Redistributions in binary form must reproduce the above copyright
>> - *notice, this list of conditions and the following disclaimer in
>> - *the documentation and/or other materials provided with the
>> - *distribution.
>> - * 3. The names of its contributors may not be used to endorse or promote
>> - *products derived from this software without specific prior written
>> - *permission.
>> - *
>> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>> - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
>> - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
>> - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
>> - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> - * SOFTWARE.
>>   */
> 
> You forgot to add an SPDX licence for this file.

There is one already. It appears that someone went through all the uapi
headers and added SPDX licenses. I just removed the now unnecessary boilerplate
text.

I admit, it's not clear from the diff :-) just two more context lines at
the start and you'd have seen it.

Regards,

Hans


Re: [PATCH 2/7] include/(uapi/)media: add SPDX license info

2018-02-14 Thread Mauro Carvalho Chehab
Em Wed,  7 Feb 2018 15:39:34 +0100
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> Replace the old license information with the corresponding SPDX
> license for those headers that I authored.
> 
> Signed-off-by: Hans Verkuil 

...

> diff --git a/include/uapi/linux/cec.h b/include/uapi/linux/cec.h
> index b51fbe1941a7..20fe091b7e96 100644
> --- a/include/uapi/linux/cec.h
> +++ b/include/uapi/linux/cec.h
> @@ -3,35 +3,6 @@
>   * cec - HDMI Consumer Electronics Control public header
>   *
>   * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights 
> reserved.
> - *
> - * This program is free software; you may redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; version 2 of the License.
> - *
> - * Alternatively you can redistribute this file under the terms of the
> - * BSD license as stated below:
> - *
> - * Redistribution and use in source and binary forms, with or without
> - * modification, are permitted provided that the following conditions
> - * are met:
> - * 1. Redistributions of source code must retain the above copyright
> - *notice, this list of conditions and the following disclaimer.
> - * 2. Redistributions in binary form must reproduce the above copyright
> - *notice, this list of conditions and the following disclaimer in
> - *the documentation and/or other materials provided with the
> - *distribution.
> - * 3. The names of its contributors may not be used to endorse or promote
> - *products derived from this software without specific prior written
> - *permission.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> - * SOFTWARE.
>   */

You forgot to add an SPDX licence for this file.

Thanks,
Mauro


Re: [PATCH v4 16/18] scripts: kernel-doc: improve nested logic to handle multiple identifiers

2018-02-14 Thread Mauro Carvalho Chehab
Em Wed, 14 Feb 2018 18:07:03 +0200
Jani Nikula  escreveu:

> On Mon, 18 Dec 2017, Mauro Carvalho Chehab  wrote:
> > It is possible to use nested structs like:
> >
> > struct {
> > struct {
> > void *arg1;
> > } st1, st2, *st3, st4;
> > };
> >
> > Handling it requires to split each parameter. Change the logic
> > to allow such definitions.
> >
> > In order to test the new nested logic, the following file
> > was used to test  
> 
> Hi Mauro, resurrecting an old thread...
> 
> So this was a great improvement to documenting nested structs. However,
> it looks like it only supports describing the nested structs at the top
> level comment, and fails for inline documentation comments.

True. I didn't consider inline comments when I wrote the patch.
We don't use inline doc tags at media. IMO, a single description block
on the top works better, but yeah, it would be very good if it would
support nested structs to also have inlined comments.

Yet, on a quick hack:

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index fee8952037b1..e2d5cadd8d0b 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1009,6 +1009,8 @@ sub dump_struct($$) {
$declaration_name = $2;
my $members = $3;
 
+print "members: $members\n";
+
# ignore members marked private:
$members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
$members =~ s/\/\*\s*private:.*//gosi;

produce:

$ scripts/kernel-doc -none drivers/gpu/drm/i915/intel_dpio_phy.c
members:  bool dual_channel; enum dpio_phy rcomp_phy; int reset_delay; 
u32 pwron_mask; struct { enum port port; }  channel[2]; 
drivers/gpu/drm/i915/intel_dpio_phy.c:154: warning: Function parameter 
or member 'channel.port' not described in 'bxt_ddi_phy_info'

So, dump_struct() already receives the struct sanitizes without any comments
inside.

There is a simple fix, though. Make inline comments to accept a dot:

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index fee8952037b1..06d7f3f2c094 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -363,7 +363,7 @@ my $doc_sect = $doc_com .
 my $doc_content = $doc_com_body . '(.*)';
 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
 my $doc_inline_start = '^\s*/\*\*\s*$';
-my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
+my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
 my $doc_inline_end = '^\s*\*/\s*$';
 my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
 my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';

That requires a small change at the inline parameters, though:

diff --git a/drivers/gpu/drm/i915/intel_dpio_phy.c 
b/drivers/gpu/drm/i915/intel_dpio_phy.c
index 76473e9836c6..c8e9e44e5981 100644
--- a/drivers/gpu/drm/i915/intel_dpio_phy.c
+++ b/drivers/gpu/drm/i915/intel_dpio_phy.c
@@ -147,7 +147,7 @@ struct bxt_ddi_phy_info {
 */
struct {
/**
-* @port: which port maps to this channel.
+* @channel.port: which port maps to this channel.
 */
enum port port;
} channel[2];

The alternative would be a way more complex: to teach the code with
starts at:

If ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {

About how to handle with inlined structs/enums at inlined comments.

Thanks,
Mauro


Re: [PATCHv2 2/9] media: convert g/s_parm to g/s_frame_interval in subdevs

2018-02-14 Thread Mauro Carvalho Chehab
Em Wed, 14 Feb 2018 18:16:55 +0100
Hans Verkuil  escreveu:

> On 14/02/18 18:02, Mauro Carvalho Chehab wrote:
> > Em Wed, 14 Feb 2018 17:34:17 +0100
> > Hans Verkuil  escreveu:
> >   
> >> On 14/02/18 17:03, Mauro Carvalho Chehab wrote:  
> >>> Em Mon, 22 Jan 2018 13:31:18 +0100
> >>> Hans Verkuil  escreveu:
> >>> 
>  From: Hans Verkuil 
> 
>  Convert all g/s_parm calls to g/s_frame_interval. This allows us
>  to remove the g/s_parm ops since those are a duplicate of
>  g/s_frame_interval.
> 
>  Signed-off-by: Hans Verkuil 
>  ---
>   drivers/media/i2c/mt9v011.c | 31 
>  +++-
>   drivers/media/i2c/ov6650.c  | 35 
>  +-
>   drivers/media/i2c/ov7670.c  | 24 +++
>   drivers/media/i2c/ov7740.c  | 31 
>  +++-
>   drivers/media/i2c/tvp514x.c | 39 
>  +
>   drivers/media/i2c/vs6624.c  | 29 +++---
>   drivers/media/platform/atmel/atmel-isc.c| 10 ++-
>   drivers/media/platform/atmel/atmel-isi.c| 12 ++--
>   drivers/media/platform/blackfin/bfin_capture.c  | 14 +++--
>   drivers/media/platform/marvell-ccic/mcam-core.c | 12 
>   drivers/media/platform/soc_camera/soc_camera.c  | 10 ---
>   drivers/media/platform/via-camera.c |  4 +--
>   drivers/media/usb/em28xx/em28xx-video.c | 36 
>  +++
>   13 files changed, 122 insertions(+), 165 deletions(-)
> 
>  diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
>  index 5e29064fae91..3e23c5b0de1f 100644
>  --- a/drivers/media/i2c/mt9v011.c
>  +++ b/drivers/media/i2c/mt9v011.c
>  @@ -364,33 +364,24 @@ static int mt9v011_set_fmt(struct v4l2_subdev *sd,
>   return 0;
>   }
>   
>  -static int mt9v011_g_parm(struct v4l2_subdev *sd, struct 
>  v4l2_streamparm *parms)
>  +static int mt9v011_g_frame_interval(struct v4l2_subdev *sd,
>  +struct v4l2_subdev_frame_interval 
>  *ival)
>   {
>  -struct v4l2_captureparm *cp = >parm.capture;
>  -
>  -if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
>  -return -EINVAL;
>  -
>  -memset(cp, 0, sizeof(struct v4l2_captureparm));
>  -cp->capability = V4L2_CAP_TIMEPERFRAME;
>  +memset(ival->reserved, 0, sizeof(ival->reserved));
> >>>
> >>> Hmm.. why to repeat memset everywhere? If the hole idea is to stop 
> >>> abusing,
> >>> the best would be to do, instead:
> >>
> >> g_frame_interval is called by bridge drivers through the subdev ops. So 
> >> that
> >> path doesn't go through subdev_do_ioctl(). So it doesn't help putting it in
> >> v4l2-subdev.c.  
> > 
> > True, but you could also do the same for v4l2 ioctl() handling logic.
> > 
> > That would mean just two places with memset() instead of repeating the same
> > pattern everywhere.
> >   
> >> That doesn't mean it shouldn't be there as well. I believe my MC patch 
> >> series
> >> actually adds the memset in subdev_do_ioctl.  
> 
> What could be done is that this patch 
> https://patchwork.linuxtv.org/patch/46955/
> is applied first. After that these memsets can be removed since internally we
> don't need to touch them.

Works for me.

> >>  
> >>>
> >>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
> >>> b/drivers/media/v4l2-core/v4l2-subdev.c
> >>> index c5639817db34..b18b418c080f 100644
> >>> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> >>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> >>> @@ -350,6 +350,7 @@ static long subdev_do_ioctl(struct file *file, 
> >>> unsigned int cmd, void *arg)
> >>>   if (fi->pad >= sd->entity.num_pads)
> >>>   return -EINVAL;
> >>>  
> >>> + memset(fi->reserved, 0, sizeof(ival->reserved));
> >>>   return v4l2_subdev_call(sd, video, g_frame_interval, arg);
> >>>   }
> >>>  
> >>> (same applies to s_frame_interval).
> >>>
> >>> 
>   calc_fps(sd,
>  - >timeperframe.numerator,
>  - >timeperframe.denominator);
>  + >interval.numerator,
>  + >interval.denominator);
>   
>   return 0;
>   }
>   
>  -static int mt9v011_s_parm(struct v4l2_subdev *sd, struct 
>  v4l2_streamparm *parms)
>  +static int mt9v011_s_frame_interval(struct v4l2_subdev *sd,
>  +struct v4l2_subdev_frame_interval 
>  *ival)
>   {
>  -struct v4l2_captureparm *cp = >parm.capture;
>  -struct v4l2_fract *tpf = >timeperframe;
> 

Re: [PATCHv2 2/9] media: convert g/s_parm to g/s_frame_interval in subdevs

2018-02-14 Thread Hans Verkuil
On 14/02/18 18:02, Mauro Carvalho Chehab wrote:
> Em Wed, 14 Feb 2018 17:34:17 +0100
> Hans Verkuil  escreveu:
> 
>> On 14/02/18 17:03, Mauro Carvalho Chehab wrote:
>>> Em Mon, 22 Jan 2018 13:31:18 +0100
>>> Hans Verkuil  escreveu:
>>>   
 From: Hans Verkuil 

 Convert all g/s_parm calls to g/s_frame_interval. This allows us
 to remove the g/s_parm ops since those are a duplicate of
 g/s_frame_interval.

 Signed-off-by: Hans Verkuil 
 ---
  drivers/media/i2c/mt9v011.c | 31 +++-
  drivers/media/i2c/ov6650.c  | 35 
 +-
  drivers/media/i2c/ov7670.c  | 24 +++
  drivers/media/i2c/ov7740.c  | 31 +++-
  drivers/media/i2c/tvp514x.c | 39 
 +
  drivers/media/i2c/vs6624.c  | 29 +++---
  drivers/media/platform/atmel/atmel-isc.c| 10 ++-
  drivers/media/platform/atmel/atmel-isi.c| 12 ++--
  drivers/media/platform/blackfin/bfin_capture.c  | 14 +++--
  drivers/media/platform/marvell-ccic/mcam-core.c | 12 
  drivers/media/platform/soc_camera/soc_camera.c  | 10 ---
  drivers/media/platform/via-camera.c |  4 +--
  drivers/media/usb/em28xx/em28xx-video.c | 36 
 +++
  13 files changed, 122 insertions(+), 165 deletions(-)

 diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
 index 5e29064fae91..3e23c5b0de1f 100644
 --- a/drivers/media/i2c/mt9v011.c
 +++ b/drivers/media/i2c/mt9v011.c
 @@ -364,33 +364,24 @@ static int mt9v011_set_fmt(struct v4l2_subdev *sd,
return 0;
  }
  
 -static int mt9v011_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
 *parms)
 +static int mt9v011_g_frame_interval(struct v4l2_subdev *sd,
 +  struct v4l2_subdev_frame_interval *ival)
  {
 -  struct v4l2_captureparm *cp = >parm.capture;
 -
 -  if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
 -  return -EINVAL;
 -
 -  memset(cp, 0, sizeof(struct v4l2_captureparm));
 -  cp->capability = V4L2_CAP_TIMEPERFRAME;
 +  memset(ival->reserved, 0, sizeof(ival->reserved));  
>>>
>>> Hmm.. why to repeat memset everywhere? If the hole idea is to stop abusing,
>>> the best would be to do, instead:  
>>
>> g_frame_interval is called by bridge drivers through the subdev ops. So that
>> path doesn't go through subdev_do_ioctl(). So it doesn't help putting it in
>> v4l2-subdev.c.
> 
> True, but you could also do the same for v4l2 ioctl() handling logic.
> 
> That would mean just two places with memset() instead of repeating the same
> pattern everywhere.
> 
>> That doesn't mean it shouldn't be there as well. I believe my MC patch series
>> actually adds the memset in subdev_do_ioctl.

What could be done is that this patch https://patchwork.linuxtv.org/patch/46955/
is applied first. After that these memsets can be removed since internally we
don't need to touch them.

>>
>>>
>>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
>>> b/drivers/media/v4l2-core/v4l2-subdev.c
>>> index c5639817db34..b18b418c080f 100644
>>> --- a/drivers/media/v4l2-core/v4l2-subdev.c
>>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
>>> @@ -350,6 +350,7 @@ static long subdev_do_ioctl(struct file *file, unsigned 
>>> int cmd, void *arg)
>>> if (fi->pad >= sd->entity.num_pads)
>>> return -EINVAL;
>>>  
>>> +   memset(fi->reserved, 0, sizeof(ival->reserved));
>>> return v4l2_subdev_call(sd, video, g_frame_interval, arg);
>>> }
>>>  
>>> (same applies to s_frame_interval).
>>>
>>>   
calc_fps(sd,
 -   >timeperframe.numerator,
 -   >timeperframe.denominator);
 +   >interval.numerator,
 +   >interval.denominator);
  
return 0;
  }
  
 -static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
 *parms)
 +static int mt9v011_s_frame_interval(struct v4l2_subdev *sd,
 +  struct v4l2_subdev_frame_interval *ival)
  {
 -  struct v4l2_captureparm *cp = >parm.capture;
 -  struct v4l2_fract *tpf = >timeperframe;
 +  struct v4l2_fract *tpf = >interval;
u16 speed;
  
 -  if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
 -  return -EINVAL;
 -  if (cp->extendedmode != 0)
 -  return -EINVAL;
 -  
>>>
>>> Hmm... why are you removing those sanity checks everywhere?
>>> The core doesn't do it.
>>>
>>> All the above comments also apply to the other files modified by
>>> this patch.  
>>
>> struct v4l2_subdev_frame_interval has neither type nor 

Re: [PATCHv2 2/9] media: convert g/s_parm to g/s_frame_interval in subdevs

2018-02-14 Thread Mauro Carvalho Chehab
Em Wed, 14 Feb 2018 17:34:17 +0100
Hans Verkuil  escreveu:

> On 14/02/18 17:03, Mauro Carvalho Chehab wrote:
> > Em Mon, 22 Jan 2018 13:31:18 +0100
> > Hans Verkuil  escreveu:
> >   
> >> From: Hans Verkuil 
> >>
> >> Convert all g/s_parm calls to g/s_frame_interval. This allows us
> >> to remove the g/s_parm ops since those are a duplicate of
> >> g/s_frame_interval.
> >>
> >> Signed-off-by: Hans Verkuil 
> >> ---
> >>  drivers/media/i2c/mt9v011.c | 31 +++-
> >>  drivers/media/i2c/ov6650.c  | 35 
> >> +-
> >>  drivers/media/i2c/ov7670.c  | 24 +++
> >>  drivers/media/i2c/ov7740.c  | 31 +++-
> >>  drivers/media/i2c/tvp514x.c | 39 
> >> +
> >>  drivers/media/i2c/vs6624.c  | 29 +++---
> >>  drivers/media/platform/atmel/atmel-isc.c| 10 ++-
> >>  drivers/media/platform/atmel/atmel-isi.c| 12 ++--
> >>  drivers/media/platform/blackfin/bfin_capture.c  | 14 +++--
> >>  drivers/media/platform/marvell-ccic/mcam-core.c | 12 
> >>  drivers/media/platform/soc_camera/soc_camera.c  | 10 ---
> >>  drivers/media/platform/via-camera.c |  4 +--
> >>  drivers/media/usb/em28xx/em28xx-video.c | 36 
> >> +++
> >>  13 files changed, 122 insertions(+), 165 deletions(-)
> >>
> >> diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
> >> index 5e29064fae91..3e23c5b0de1f 100644
> >> --- a/drivers/media/i2c/mt9v011.c
> >> +++ b/drivers/media/i2c/mt9v011.c
> >> @@ -364,33 +364,24 @@ static int mt9v011_set_fmt(struct v4l2_subdev *sd,
> >>return 0;
> >>  }
> >>  
> >> -static int mt9v011_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
> >> *parms)
> >> +static int mt9v011_g_frame_interval(struct v4l2_subdev *sd,
> >> +  struct v4l2_subdev_frame_interval *ival)
> >>  {
> >> -  struct v4l2_captureparm *cp = >parm.capture;
> >> -
> >> -  if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> >> -  return -EINVAL;
> >> -
> >> -  memset(cp, 0, sizeof(struct v4l2_captureparm));
> >> -  cp->capability = V4L2_CAP_TIMEPERFRAME;
> >> +  memset(ival->reserved, 0, sizeof(ival->reserved));  
> > 
> > Hmm.. why to repeat memset everywhere? If the hole idea is to stop abusing,
> > the best would be to do, instead:  
> 
> g_frame_interval is called by bridge drivers through the subdev ops. So that
> path doesn't go through subdev_do_ioctl(). So it doesn't help putting it in
> v4l2-subdev.c.

True, but you could also do the same for v4l2 ioctl() handling logic.

That would mean just two places with memset() instead of repeating the same
pattern everywhere.

> That doesn't mean it shouldn't be there as well. I believe my MC patch series
> actually adds the memset in subdev_do_ioctl.
> 
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
> > b/drivers/media/v4l2-core/v4l2-subdev.c
> > index c5639817db34..b18b418c080f 100644
> > --- a/drivers/media/v4l2-core/v4l2-subdev.c
> > +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> > @@ -350,6 +350,7 @@ static long subdev_do_ioctl(struct file *file, unsigned 
> > int cmd, void *arg)
> > if (fi->pad >= sd->entity.num_pads)
> > return -EINVAL;
> >  
> > +   memset(fi->reserved, 0, sizeof(ival->reserved));
> > return v4l2_subdev_call(sd, video, g_frame_interval, arg);
> > }
> >  
> > (same applies to s_frame_interval).
> > 
> >   
> >>calc_fps(sd,
> >> -   >timeperframe.numerator,
> >> -   >timeperframe.denominator);
> >> +   >interval.numerator,
> >> +   >interval.denominator);
> >>  
> >>return 0;
> >>  }
> >>  
> >> -static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
> >> *parms)
> >> +static int mt9v011_s_frame_interval(struct v4l2_subdev *sd,
> >> +  struct v4l2_subdev_frame_interval *ival)
> >>  {
> >> -  struct v4l2_captureparm *cp = >parm.capture;
> >> -  struct v4l2_fract *tpf = >timeperframe;
> >> +  struct v4l2_fract *tpf = >interval;
> >>u16 speed;
> >>  
> >> -  if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> >> -  return -EINVAL;
> >> -  if (cp->extendedmode != 0)
> >> -  return -EINVAL;
> >> -  
> > 
> > Hmm... why are you removing those sanity checks everywhere?
> > The core doesn't do it.
> > 
> > All the above comments also apply to the other files modified by
> > this patch.  
> 
> struct v4l2_subdev_frame_interval has neither type nor extendedmode.
> 
> The check for type is done in the v4l2_g/s_parm_cap helpers instead.

Well, the subdev handler at v4l2-subdev.c doesn't seem to be checking it.


> And extendedmode is always set to 0.
> 
> >   
> >> +  memset(ival->reserved, 0, 

Re: [PATCHv2 1/9] v4l2-common: create v4l2_g/s_parm_cap helpers

2018-02-14 Thread Hans Verkuil
On 14/02/18 17:35, Mauro Carvalho Chehab wrote:
> Em Wed, 14 Feb 2018 17:23:51 +0100
> Hans Verkuil  escreveu:
> 
>> On 14/02/18 16:50, Mauro Carvalho Chehab wrote:
>>> Em Mon, 22 Jan 2018 13:31:17 +0100
>>> Hans Verkuil  escreveu:
>>>   
 From: Hans Verkuil 

 Create helpers to handle VIDIOC_G/S_PARM by querying the
 g/s_frame_interval v4l2_subdev ops.

 Signed-off-by: Hans Verkuil 
 ---
  drivers/media/v4l2-core/v4l2-common.c | 48 
 +++
  include/media/v4l2-common.h   | 26 +++
  2 files changed, 74 insertions(+)

 diff --git a/drivers/media/v4l2-core/v4l2-common.c 
 b/drivers/media/v4l2-core/v4l2-common.c
 index 8650ad92b64d..96c1b31de9e3 100644
 --- a/drivers/media/v4l2-core/v4l2-common.c
 +++ b/drivers/media/v4l2-core/v4l2-common.c
 @@ -392,3 +392,51 @@ void v4l2_get_timestamp(struct timeval *tv)
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
  }
  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
 +
 +int v4l2_g_parm_cap(struct video_device *vdev,
 +  struct v4l2_subdev *sd, struct v4l2_streamparm *a)
 +{
 +  struct v4l2_subdev_frame_interval ival = { 0 };
 +  int ret;
 +
 +  if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
 +  a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
 +  return -EINVAL;
 +
 +  if (vdev->device_caps & V4L2_CAP_READWRITE)
 +  a->parm.capture.readbuffers = 2;  
>>>
>>> Hmm... why don't you also initialize readbuffers otherwise?  
>>
>> It's specifically for read(). If read() is not supported, then this
>> is meaningless and should just stay 0. v4l2-compliance checks for this.
> 
> Well, API states that:
> 
> "When an application requests zero buffers, drivers should just return the 
> current setting rather than the minimum or an error code."
> 
> So, something should zero it, if not used and type is capture or
> capture_mplane.

All fields after the type field are zeroed by the core in v4l2-ioctl.c:

IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, 
INFO_FL_CLEAR(v4l2_streamparm, type)),

> 
>> The 'readbuffers' field is completely outdated and once this is in
>> the next step is to see if we can come up with something better. I hate
>> G/S_PARM.
> 
> Yes, it is a weird ioctl, but I'm not yet convinced that we should
> increase API complexity by adding newer ioctls due to that.
> 
> Instead, I would just get rid of .g_parm/.s_parm callbacks, implementing
> a better kAPI, without bothering adding more complexity to uAPI.

I will probably do that as a second step anyway. We can discuss the pros and
cons of adding a new ioctl after that. I rather like the 
VIDIOC_SUBDEV_G/S_FRAME_INTERVAL
ioctls. Simple and to the point. It's really what you would expect as an
end-user.

Regards,

Hans


Re: [PATCHv2 1/9] v4l2-common: create v4l2_g/s_parm_cap helpers

2018-02-14 Thread Mauro Carvalho Chehab
Em Wed, 14 Feb 2018 17:23:51 +0100
Hans Verkuil  escreveu:

> On 14/02/18 16:50, Mauro Carvalho Chehab wrote:
> > Em Mon, 22 Jan 2018 13:31:17 +0100
> > Hans Verkuil  escreveu:
> >   
> >> From: Hans Verkuil 
> >>
> >> Create helpers to handle VIDIOC_G/S_PARM by querying the
> >> g/s_frame_interval v4l2_subdev ops.
> >>
> >> Signed-off-by: Hans Verkuil 
> >> ---
> >>  drivers/media/v4l2-core/v4l2-common.c | 48 
> >> +++
> >>  include/media/v4l2-common.h   | 26 +++
> >>  2 files changed, 74 insertions(+)
> >>
> >> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
> >> b/drivers/media/v4l2-core/v4l2-common.c
> >> index 8650ad92b64d..96c1b31de9e3 100644
> >> --- a/drivers/media/v4l2-core/v4l2-common.c
> >> +++ b/drivers/media/v4l2-core/v4l2-common.c
> >> @@ -392,3 +392,51 @@ void v4l2_get_timestamp(struct timeval *tv)
> >>tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
> >>  }
> >>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
> >> +
> >> +int v4l2_g_parm_cap(struct video_device *vdev,
> >> +  struct v4l2_subdev *sd, struct v4l2_streamparm *a)
> >> +{
> >> +  struct v4l2_subdev_frame_interval ival = { 0 };
> >> +  int ret;
> >> +
> >> +  if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
> >> +  a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> >> +  return -EINVAL;
> >> +
> >> +  if (vdev->device_caps & V4L2_CAP_READWRITE)
> >> +  a->parm.capture.readbuffers = 2;  
> > 
> > Hmm... why don't you also initialize readbuffers otherwise?  
> 
> It's specifically for read(). If read() is not supported, then this
> is meaningless and should just stay 0. v4l2-compliance checks for this.

Well, API states that:

"When an application requests zero buffers, drivers should just return the 
current setting rather than the minimum or an error code."

So, something should zero it, if not used and type is capture or
capture_mplane.

> The 'readbuffers' field is completely outdated and once this is in
> the next step is to see if we can come up with something better. I hate
> G/S_PARM.

Yes, it is a weird ioctl, but I'm not yet convinced that we should
increase API complexity by adding newer ioctls due to that.

Instead, I would just get rid of .g_parm/.s_parm callbacks, implementing
a better kAPI, without bothering adding more complexity to uAPI.

> 
> Regards,
> 
>   Hans
> 
> >   
> >> +  if (v4l2_subdev_has_op(sd, video, g_frame_interval))
> >> +  a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
> >> +  ret = v4l2_subdev_call(sd, video, g_frame_interval, );
> >> +  if (!ret)
> >> +  a->parm.capture.timeperframe = ival.interval;
> >> +  return ret;
> >> +}
> >> +EXPORT_SYMBOL_GPL(v4l2_g_parm_cap);
> >> +
> >> +int v4l2_s_parm_cap(struct video_device *vdev,
> >> +  struct v4l2_subdev *sd, struct v4l2_streamparm *a)
> >> +{
> >> +  struct v4l2_subdev_frame_interval ival = {
> >> +  .interval = a->parm.capture.timeperframe
> >> +  };
> >> +  int ret;
> >> +
> >> +  if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
> >> +  a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> >> +  return -EINVAL;
> >> +
> >> +  memset(>parm, 0, sizeof(a->parm));
> >> +  if (vdev->device_caps & V4L2_CAP_READWRITE)
> >> +  a->parm.capture.readbuffers = 2;
> >> +  else
> >> +  a->parm.capture.readbuffers = 0;
> >> +
> >> +  if (v4l2_subdev_has_op(sd, video, g_frame_interval))
> >> +  a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
> >> +  ret = v4l2_subdev_call(sd, video, s_frame_interval, );
> >> +  if (!ret)
> >> +  a->parm.capture.timeperframe = ival.interval;
> >> +  return ret;
> >> +}
> >> +EXPORT_SYMBOL_GPL(v4l2_s_parm_cap);
> >> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> >> index e0d95a7c5d48..f3aa1d728c0b 100644
> >> --- a/include/media/v4l2-common.h
> >> +++ b/include/media/v4l2-common.h
> >> @@ -341,4 +341,30 @@ v4l2_find_nearest_format(const struct 
> >> v4l2_frmsize_discrete *sizes,
> >>   */
> >>  void v4l2_get_timestamp(struct timeval *tv);
> >>  
> >> +/**
> >> + * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
> >> + *  calling the g_frame_interval op of the given subdev. It only works
> >> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
> >> + *  function name.
> >> + *
> >> + * @vdev: the struct video_device pointer. Used to determine the device 
> >> caps.
> >> + * @sd: the sub-device pointer.
> >> + * @a: the VIDIOC_G_PARM argument.
> >> + */
> >> +int v4l2_g_parm_cap(struct video_device *vdev,
> >> +  struct v4l2_subdev *sd, struct v4l2_streamparm *a);
> >> +
> >> +/**
> >> + * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
> >> + *  calling the s_frame_interval op of the given subdev. It only works
> >> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), 

Re: [PATCHv2 2/9] media: convert g/s_parm to g/s_frame_interval in subdevs

2018-02-14 Thread Hans Verkuil
On 14/02/18 17:03, Mauro Carvalho Chehab wrote:
> Em Mon, 22 Jan 2018 13:31:18 +0100
> Hans Verkuil  escreveu:
> 
>> From: Hans Verkuil 
>>
>> Convert all g/s_parm calls to g/s_frame_interval. This allows us
>> to remove the g/s_parm ops since those are a duplicate of
>> g/s_frame_interval.
>>
>> Signed-off-by: Hans Verkuil 
>> ---
>>  drivers/media/i2c/mt9v011.c | 31 +++-
>>  drivers/media/i2c/ov6650.c  | 35 +-
>>  drivers/media/i2c/ov7670.c  | 24 +++
>>  drivers/media/i2c/ov7740.c  | 31 +++-
>>  drivers/media/i2c/tvp514x.c | 39 
>> +
>>  drivers/media/i2c/vs6624.c  | 29 +++---
>>  drivers/media/platform/atmel/atmel-isc.c| 10 ++-
>>  drivers/media/platform/atmel/atmel-isi.c| 12 ++--
>>  drivers/media/platform/blackfin/bfin_capture.c  | 14 +++--
>>  drivers/media/platform/marvell-ccic/mcam-core.c | 12 
>>  drivers/media/platform/soc_camera/soc_camera.c  | 10 ---
>>  drivers/media/platform/via-camera.c |  4 +--
>>  drivers/media/usb/em28xx/em28xx-video.c | 36 +++
>>  13 files changed, 122 insertions(+), 165 deletions(-)
>>
>> diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
>> index 5e29064fae91..3e23c5b0de1f 100644
>> --- a/drivers/media/i2c/mt9v011.c
>> +++ b/drivers/media/i2c/mt9v011.c
>> @@ -364,33 +364,24 @@ static int mt9v011_set_fmt(struct v4l2_subdev *sd,
>>  return 0;
>>  }
>>  
>> -static int mt9v011_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
>> *parms)
>> +static int mt9v011_g_frame_interval(struct v4l2_subdev *sd,
>> +struct v4l2_subdev_frame_interval *ival)
>>  {
>> -struct v4l2_captureparm *cp = >parm.capture;
>> -
>> -if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
>> -return -EINVAL;
>> -
>> -memset(cp, 0, sizeof(struct v4l2_captureparm));
>> -cp->capability = V4L2_CAP_TIMEPERFRAME;
>> +memset(ival->reserved, 0, sizeof(ival->reserved));
> 
> Hmm.. why to repeat memset everywhere? If the hole idea is to stop abusing,
> the best would be to do, instead:

g_frame_interval is called by bridge drivers through the subdev ops. So that
path doesn't go through subdev_do_ioctl(). So it doesn't help putting it in
v4l2-subdev.c.

That doesn't mean it shouldn't be there as well. I believe my MC patch series
actually adds the memset in subdev_do_ioctl.

> 
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
> b/drivers/media/v4l2-core/v4l2-subdev.c
> index c5639817db34..b18b418c080f 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -350,6 +350,7 @@ static long subdev_do_ioctl(struct file *file, unsigned 
> int cmd, void *arg)
>   if (fi->pad >= sd->entity.num_pads)
>   return -EINVAL;
>  
> + memset(fi->reserved, 0, sizeof(ival->reserved));
>   return v4l2_subdev_call(sd, video, g_frame_interval, arg);
>   }
>  
> (same applies to s_frame_interval).
> 
> 
>>  calc_fps(sd,
>> - >timeperframe.numerator,
>> - >timeperframe.denominator);
>> + >interval.numerator,
>> + >interval.denominator);
>>  
>>  return 0;
>>  }
>>  
>> -static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
>> *parms)
>> +static int mt9v011_s_frame_interval(struct v4l2_subdev *sd,
>> +struct v4l2_subdev_frame_interval *ival)
>>  {
>> -struct v4l2_captureparm *cp = >parm.capture;
>> -struct v4l2_fract *tpf = >timeperframe;
>> +struct v4l2_fract *tpf = >interval;
>>  u16 speed;
>>  
>> -if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
>> -return -EINVAL;
>> -if (cp->extendedmode != 0)
>> -return -EINVAL;
>> -
> 
> Hmm... why are you removing those sanity checks everywhere?
> The core doesn't do it.
> 
> All the above comments also apply to the other files modified by
> this patch.

struct v4l2_subdev_frame_interval has neither type nor extendedmode.

The check for type is done in the v4l2_g/s_parm_cap helpers instead.
And extendedmode is always set to 0.

> 
>> +memset(ival->reserved, 0, sizeof(ival->reserved));
>>  speed = calc_speed(sd, tpf->numerator, tpf->denominator);
>>  
>>  mt9v011_write(sd, R0A_MT9V011_CLK_SPEED, speed);
>> @@ -469,8 +460,8 @@ static const struct v4l2_subdev_core_ops 
>> mt9v011_core_ops = {
>>  };
>>  
>>  static const struct v4l2_subdev_video_ops mt9v011_video_ops = {
>> -.g_parm = mt9v011_g_parm,
>> -.s_parm = mt9v011_s_parm,
>> +.g_frame_interval = mt9v011_g_frame_interval,
>> +.s_frame_interval = mt9v011_s_frame_interval,
>>  };
>>  
>>  static const 

Re: [PATCHv2 1/9] v4l2-common: create v4l2_g/s_parm_cap helpers

2018-02-14 Thread Hans Verkuil
On 14/02/18 16:50, Mauro Carvalho Chehab wrote:
> Em Mon, 22 Jan 2018 13:31:17 +0100
> Hans Verkuil  escreveu:
> 
>> From: Hans Verkuil 
>>
>> Create helpers to handle VIDIOC_G/S_PARM by querying the
>> g/s_frame_interval v4l2_subdev ops.
>>
>> Signed-off-by: Hans Verkuil 
>> ---
>>  drivers/media/v4l2-core/v4l2-common.c | 48 
>> +++
>>  include/media/v4l2-common.h   | 26 +++
>>  2 files changed, 74 insertions(+)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
>> b/drivers/media/v4l2-core/v4l2-common.c
>> index 8650ad92b64d..96c1b31de9e3 100644
>> --- a/drivers/media/v4l2-core/v4l2-common.c
>> +++ b/drivers/media/v4l2-core/v4l2-common.c
>> @@ -392,3 +392,51 @@ void v4l2_get_timestamp(struct timeval *tv)
>>  tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>>  }
>>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
>> +
>> +int v4l2_g_parm_cap(struct video_device *vdev,
>> +struct v4l2_subdev *sd, struct v4l2_streamparm *a)
>> +{
>> +struct v4l2_subdev_frame_interval ival = { 0 };
>> +int ret;
>> +
>> +if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
>> +a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
>> +return -EINVAL;
>> +
>> +if (vdev->device_caps & V4L2_CAP_READWRITE)
>> +a->parm.capture.readbuffers = 2;
> 
> Hmm... why don't you also initialize readbuffers otherwise?

It's specifically for read(). If read() is not supported, then this
is meaningless and should just stay 0. v4l2-compliance checks for this.

The 'readbuffers' field is completely outdated and once this is in
the next step is to see if we can come up with something better. I hate
G/S_PARM.

Regards,

Hans

> 
>> +if (v4l2_subdev_has_op(sd, video, g_frame_interval))
>> +a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
>> +ret = v4l2_subdev_call(sd, video, g_frame_interval, );
>> +if (!ret)
>> +a->parm.capture.timeperframe = ival.interval;
>> +return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(v4l2_g_parm_cap);
>> +
>> +int v4l2_s_parm_cap(struct video_device *vdev,
>> +struct v4l2_subdev *sd, struct v4l2_streamparm *a)
>> +{
>> +struct v4l2_subdev_frame_interval ival = {
>> +.interval = a->parm.capture.timeperframe
>> +};
>> +int ret;
>> +
>> +if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
>> +a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
>> +return -EINVAL;
>> +
>> +memset(>parm, 0, sizeof(a->parm));
>> +if (vdev->device_caps & V4L2_CAP_READWRITE)
>> +a->parm.capture.readbuffers = 2;
>> +else
>> +a->parm.capture.readbuffers = 0;
>> +
>> +if (v4l2_subdev_has_op(sd, video, g_frame_interval))
>> +a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
>> +ret = v4l2_subdev_call(sd, video, s_frame_interval, );
>> +if (!ret)
>> +a->parm.capture.timeperframe = ival.interval;
>> +return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(v4l2_s_parm_cap);
>> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
>> index e0d95a7c5d48..f3aa1d728c0b 100644
>> --- a/include/media/v4l2-common.h
>> +++ b/include/media/v4l2-common.h
>> @@ -341,4 +341,30 @@ v4l2_find_nearest_format(const struct 
>> v4l2_frmsize_discrete *sizes,
>>   */
>>  void v4l2_get_timestamp(struct timeval *tv);
>>  
>> +/**
>> + * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
>> + *  calling the g_frame_interval op of the given subdev. It only works
>> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
>> + *  function name.
>> + *
>> + * @vdev: the struct video_device pointer. Used to determine the device 
>> caps.
>> + * @sd: the sub-device pointer.
>> + * @a: the VIDIOC_G_PARM argument.
>> + */
>> +int v4l2_g_parm_cap(struct video_device *vdev,
>> +struct v4l2_subdev *sd, struct v4l2_streamparm *a);
>> +
>> +/**
>> + * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
>> + *  calling the s_frame_interval op of the given subdev. It only works
>> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
>> + *  function name.
>> + *
>> + * @vdev: the struct video_device pointer. Used to determine the device 
>> caps.
>> + * @sd: the sub-device pointer.
>> + * @a: the VIDIOC_S_PARM argument.
>> + */
>> +int v4l2_s_parm_cap(struct video_device *vdev,
>> +struct v4l2_subdev *sd, struct v4l2_streamparm *a);
>> +
>>  #endif /* V4L2_COMMON_H_ */
> 
> 
> 
> Thanks,
> Mauro
> 



Re: [PATCHv2 4/9] staging: atomisp: i2c: Disable non-preview configurations

2018-02-14 Thread Mauro Carvalho Chehab
Em Mon, 22 Jan 2018 13:31:20 +0100
Hans Verkuil  escreveu:

> From: Sakari Ailus 
> 
> Disable configurations for non-preview modes until configuration selection
> is improved.

Again, a poor description. It just repeats the subject.
A good subject/description should answer 3 questions:

what?
why?
how?

Anyway, looking at this patch's contents, it partially answers my
questions:

the previous patch do cause regressions at the code.

Ok, this is staging. So, we don't have very strict rules here,
but still causing regressions without providing a very good
reason why sucks.

I would also merge this with the previous one, in order to place all
regressions on a single patch.


> 
> Signed-off-by: Sakari Ailus 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/staging/media/atomisp/i2c/gc2235.h| 2 ++
>  drivers/staging/media/atomisp/i2c/ov2722.h| 2 ++
>  drivers/staging/media/atomisp/i2c/ov5693/ov5693.h | 2 ++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/drivers/staging/media/atomisp/i2c/gc2235.h 
> b/drivers/staging/media/atomisp/i2c/gc2235.h
> index 45a54fea5466..817c0068c1d3 100644
> --- a/drivers/staging/media/atomisp/i2c/gc2235.h
> +++ b/drivers/staging/media/atomisp/i2c/gc2235.h
> @@ -574,6 +574,7 @@ static struct gc2235_resolution gc2235_res_preview[] = {
>  };
>  #define N_RES_PREVIEW (ARRAY_SIZE(gc2235_res_preview))
>  
> +#if 0 /* Disable non-previes configurations for now */

typo (here and other cut-and-paste paces)
non-previes -> non-previews

also, please add a FIXME: or HACK: and describe the need for a fix
on atomisp TODO file.

>  static struct gc2235_resolution gc2235_res_still[] = {
>   {
>   .desc = "gc2235_1600_900_30fps",
> @@ -658,6 +659,7 @@ static struct gc2235_resolution gc2235_res_video[] = {
>  
>  };
>  #define N_RES_VIDEO (ARRAY_SIZE(gc2235_res_video))
> +#endif
>  
>  static struct gc2235_resolution *gc2235_res = gc2235_res_preview;
>  static unsigned long N_RES = N_RES_PREVIEW;
> diff --git a/drivers/staging/media/atomisp/i2c/ov2722.h 
> b/drivers/staging/media/atomisp/i2c/ov2722.h
> index d8a973d71699..f133439adfd5 100644
> --- a/drivers/staging/media/atomisp/i2c/ov2722.h
> +++ b/drivers/staging/media/atomisp/i2c/ov2722.h
> @@ -1148,6 +1148,7 @@ struct ov2722_resolution ov2722_res_preview[] = {
>  };
>  #define N_RES_PREVIEW (ARRAY_SIZE(ov2722_res_preview))
>  
> +#if 0 /* Disable non-previes configurations for now */
>  struct ov2722_resolution ov2722_res_still[] = {
>   {
>   .desc = "ov2722_480P_30fps",
> @@ -1250,6 +1251,7 @@ struct ov2722_resolution ov2722_res_video[] = {
>   },
>  };
>  #define N_RES_VIDEO (ARRAY_SIZE(ov2722_res_video))
> +#endif
>  
>  static struct ov2722_resolution *ov2722_res = ov2722_res_preview;
>  static unsigned long N_RES = N_RES_PREVIEW;
> diff --git a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h 
> b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h
> index 68cfcb4a6c3c..15a33dcd2d59 100644
> --- a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h
> +++ b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h
> @@ -1147,6 +1147,7 @@ struct ov5693_resolution ov5693_res_preview[] = {
>  };
>  #define N_RES_PREVIEW (ARRAY_SIZE(ov5693_res_preview))
>  
> +#if 0 /* Disable non-previes configurations for now */
>  struct ov5693_resolution ov5693_res_still[] = {
>   {
>   .desc = "ov5693_736x496_30fps",
> @@ -1364,6 +1365,7 @@ struct ov5693_resolution ov5693_res_video[] = {
>   },
>  };
>  #define N_RES_VIDEO (ARRAY_SIZE(ov5693_res_video))
> +#endif
>  
>  static struct ov5693_resolution *ov5693_res = ov5693_res_preview;
>  static unsigned long N_RES = N_RES_PREVIEW;



Thanks,
Mauro


Re: [PATCH v10 6/8] media: i2c: Add TDA1997x HDMI receiver driver

2018-02-14 Thread Hans Verkuil
On 14/02/18 16:46, Tim Harvey wrote:
> On Wed, Feb 14, 2018 at 6:08 AM, Hans Verkuil  wrote:
>> Hi Tim,
>>
>> On 12/02/18 23:27, Tim Harvey wrote:
>>> On Fri, Feb 9, 2018 at 12:08 AM, Hans Verkuil  wrote:
 Hi Tim,

 We're almost there. Two more comments:

 On 02/09/2018 07:32 AM, Tim Harvey wrote:
> +static int
> +tda1997x_detect_std(struct tda1997x_state *state,
> + struct v4l2_dv_timings *timings)
> +{
> + struct v4l2_subdev *sd = >sd;
> + u32 vper;
> + u16 hper;
> + u16 hsper;
> + int i;
> +
> + /*
> +  * Read the FMT registers
> +  *   REG_V_PER: Period of a frame (or two fields) in MCLK(27MHz) 
> cycles
> +  *   REG_H_PER: Period of a line in MCLK(27MHz) cycles
> +  *   REG_HS_WIDTH: Period of horiz sync pulse in MCLK(27MHz) cycles
> +  */
> + vper = io_read24(sd, REG_V_PER) & MASK_VPER;
> + hper = io_read16(sd, REG_H_PER) & MASK_HPER;
> + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH;
> + if (!vper || !hper || !hsper)
> + return -ENOLINK;

 See my comment for g_input_status below. This condition looks more like a
 ENOLCK.

 Or perhaps it should be:

 if (!vper && !hper && !hsper)
 return -ENOLINK;
 if (!vper || !hper || !hsper)
 return -ENOLCK;

 I would recommend that you test a bit with no signal and a bad signal 
 (perhaps
 one that uses a pixelclock that is too high for this device?).
>>>
>>> I can't figure out how to produce a signal that can't be locked onto
>>> with what I have available.
>>
>> Are you using a signal generator or just a laptop or something similar as the
>> source?
>>
>> Without a good signal generator it is tricky to test this. A very long HDMI
>> cable would likely do it. But for 1080p60 you probably need 20 meters or
>> more.
>>
> 
> I'm using a Marshall V-SG4K-HDI
> (http://www.lcdracks.com/racks/DLW/V-SG4K-HDI-signal-generator.php).
> It does support 'user defined timings' (see
> http://www.lcdracks.com/racks/pdf-pages/instruction_sheets/V-SG4K-HDI_Manual-web.pdf
> Timings Details Menu page) and it looks like the max pixel-clock is
> 300MHz so perhaps I can create a timing that can't be locked onto that
> way.

Yeah, that's what I usually do: try with a signal that's too high/too low.

> 
> The TDA19971 datasheet
> (http://tharvey/src/nxp/tda1997x/TDA19971-datasheet-rev3.pdf) says it
> supports:
> - All HDTV formats up to 1920x1080p at 50/60 Hz with support for
> reduced blanking
> - 3D formats including all primary formats up to 1920x1080p at 30 Hz
> Frame Packing and 1920x1080p at 60 Hz Side-by-Side and Top-and-Bottom
> - PC formats up to UXGA (1600x1200p at 60 Hz) and WUXGA (1920x1200p at 60 Hz)

The max pixelclock is probably around 170 MHz. So something above that should
do it.

> 
>>>
> 

> +static int
> +tda1997x_g_input_status(struct v4l2_subdev *sd, u32 *status)
> +{
> + struct tda1997x_state *state = to_state(sd);
> + u32 vper;
> + u16 hper;
> + u16 hsper;
> +
> + mutex_lock(>lock);
> + v4l2_dbg(1, debug, sd, "inputs:%d/%d\n",
> +  state->input_detect[0], state->input_detect[1]);
> + if (state->input_detect[0] || state->input_detect[1])

 I'm confused. This device has two HDMI inputs?

 Does 'detecting input' equate to 'I see a signal and I am locked'?
 I gather from the irq function that sets these values that it is closer
 to 'I see a signal' and that 'I am locked' is something you would test
 by looking at the vper/hper/hsper.
>>>
>>> The TDA19972 and/or TDA19973 has an A and B input but only a single
>>> output. I'm not entirely clear if/how to select between the two and I
>>> don't have proper documentation for the three chips.
>>>
>>> The TDA19971 which I have on my board only has 1 input which is
>>> reported as the 'A' input. I can likely nuke the stuff looking at the
>>> B input and/or put some qualifiers around it but I didn't want to
>>> remove code that was derived from some vendor code that might help
>>> support the other chips in the future. So I would rather like to leave
>>> the 'if A or B' stuff.
>>
>> OK. Can you add a comment somewhere in the driver about this?
>>
>> It sounds like it is similar to what the adv7604 has: several inputs but
>> only one is used for streaming. But the EDID is made available on both 
>> inputs.
>>
> 
> sure, I will comment about it. I believe that is the way the it works as well.
> 

> + *status = 0;
> + else {
> + vper = io_read24(sd, REG_V_PER) & MASK_VPER;
> + hper = io_read16(sd, REG_H_PER) & MASK_HPER;
> + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH;
> + 

Re: [PATCHv2 3/9] staging: atomisp: Kill subdev s_parm abuse

2018-02-14 Thread Mauro Carvalho Chehab
Sakari,

Em Mon, 22 Jan 2018 13:31:19 +0100
Hans Verkuil  escreveu:

> From: Sakari Ailus 
> 
> Remove sensor driver's interface that made use of use case specific
> knowledge of platform capabilities.

Could you better describe it? What s_param abuse?
What happens after this patch? It seems that atomISP relies on
gc0310_res. So, I would be expecting that a patch removing
s_param would be also adding/changing other parts of the code
accordingly, in order to get rid of that as a hole (or initialize
it somewhere else).

Regards,
Mauro

> 
> Signed-off-by: Sakari Ailus 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 26 -
>  drivers/staging/media/atomisp/i2c/atomisp-gc2235.c | 26 -
>  drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 29 -
>  drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 26 -
>  drivers/staging/media/atomisp/i2c/gc0310.h | 43 --
>  drivers/staging/media/atomisp/i2c/gc2235.h |  1 -
>  drivers/staging/media/atomisp/i2c/ov2680.h | 68 
> --
>  .../media/atomisp/i2c/ov5693/atomisp-ov5693.c  | 27 -
>  .../media/atomisp/pci/atomisp2/atomisp_cmd.c   |  9 +--
>  .../media/atomisp/pci/atomisp2/atomisp_subdev.c| 12 +---
>  10 files changed, 3 insertions(+), 264 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c 
> b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
> index 61b7598469eb..572c9127c24d 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
> @@ -1224,37 +1224,12 @@ static int gc0310_g_parm(struct v4l2_subdev *sd,
>   if (dev->fmt_idx >= 0 && dev->fmt_idx < N_RES) {
>   param->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
>   param->parm.capture.timeperframe.numerator = 1;
> - param->parm.capture.capturemode = dev->run_mode;
>   param->parm.capture.timeperframe.denominator =
>   gc0310_res[dev->fmt_idx].fps;
>   }
>   return 0;
>  }
>  
> -static int gc0310_s_parm(struct v4l2_subdev *sd,
> - struct v4l2_streamparm *param)
> -{
> - struct gc0310_device *dev = to_gc0310_sensor(sd);
> - dev->run_mode = param->parm.capture.capturemode;
> -
> - mutex_lock(>input_lock);
> - switch (dev->run_mode) {
> - case CI_MODE_VIDEO:
> - gc0310_res = gc0310_res_video;
> - N_RES = N_RES_VIDEO;
> - break;
> - case CI_MODE_STILL_CAPTURE:
> - gc0310_res = gc0310_res_still;
> - N_RES = N_RES_STILL;
> - break;
> - default:
> - gc0310_res = gc0310_res_preview;
> - N_RES = N_RES_PREVIEW;
> - }
> - mutex_unlock(>input_lock);
> - return 0;
> -}
> -
>  static int gc0310_g_frame_interval(struct v4l2_subdev *sd,
>  struct v4l2_subdev_frame_interval *interval)
>  {
> @@ -1314,7 +1289,6 @@ static const struct v4l2_subdev_sensor_ops 
> gc0310_sensor_ops = {
>  static const struct v4l2_subdev_video_ops gc0310_video_ops = {
>   .s_stream = gc0310_s_stream,
>   .g_parm = gc0310_g_parm,
> - .s_parm = gc0310_s_parm,
>   .g_frame_interval = gc0310_g_frame_interval,
>  };
>  
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c 
> b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
> index d8de46da64ae..2bc179f3afe5 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c
> @@ -964,37 +964,12 @@ static int gc2235_g_parm(struct v4l2_subdev *sd,
>   if (dev->fmt_idx >= 0 && dev->fmt_idx < N_RES) {
>   param->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
>   param->parm.capture.timeperframe.numerator = 1;
> - param->parm.capture.capturemode = dev->run_mode;
>   param->parm.capture.timeperframe.denominator =
>   gc2235_res[dev->fmt_idx].fps;
>   }
>   return 0;
>  }
>  
> -static int gc2235_s_parm(struct v4l2_subdev *sd,
> - struct v4l2_streamparm *param)
> -{
> - struct gc2235_device *dev = to_gc2235_sensor(sd);
> - dev->run_mode = param->parm.capture.capturemode;
> -
> - mutex_lock(>input_lock);
> - switch (dev->run_mode) {
> - case CI_MODE_VIDEO:
> - gc2235_res = gc2235_res_video;
> - N_RES = N_RES_VIDEO;
> - break;
> - case CI_MODE_STILL_CAPTURE:
> - gc2235_res = gc2235_res_still;
> - N_RES = N_RES_STILL;
> - break;
> - default:
> - gc2235_res = gc2235_res_preview;
> - N_RES = N_RES_PREVIEW;
> - }
> - mutex_unlock(>input_lock);
> - return 0;
> -}
> -
>  static int 

Re: [PATCH v4 16/18] scripts: kernel-doc: improve nested logic to handle multiple identifiers

2018-02-14 Thread Jani Nikula
On Mon, 18 Dec 2017, Mauro Carvalho Chehab  wrote:
> It is possible to use nested structs like:
>
> struct {
>   struct {
>   void *arg1;
>   } st1, st2, *st3, st4;
> };
>
> Handling it requires to split each parameter. Change the logic
> to allow such definitions.
>
> In order to test the new nested logic, the following file
> was used to test

Hi Mauro, resurrecting an old thread...

So this was a great improvement to documenting nested structs. However,
it looks like it only supports describing the nested structs at the top
level comment, and fails for inline documentation comments.

For example, in v4.16-rc1:

$ scripts/kernel-doc -none drivers/gpu/drm/i915/intel_dpio_phy.c
drivers/gpu/drm/i915/intel_dpio_phy.c:154: warning: Function parameter or 
member 'channel.port' not described in 'bxt_ddi_phy_info'

The struct in question is:

/**
 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
 */
struct bxt_ddi_phy_info {
/* [some members removed] */

/**
 * @channel: struct containing per channel information.
 */
struct {
/**
 * @port: which port maps to this channel.
 */
enum port port;
} channel[2];
};

Apparently the only way to currently do this is to add channel.port at
the top level:

/**
 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
 * @channel.port: which port maps to this channel.
 */

Which is less than perfect if you have everything else described
inline. :(

BR,
Jani.


>
> 
> struct foo { int a; }; /* Just to avoid errors if compiled */
>
> /**
>  * struct my_struct - a struct with nested unions and structs
>  * @arg1: first argument of anonymous union/anonymous struct
>  * @arg2: second argument of anonymous union/anonymous struct
>  * @arg1b: first argument of anonymous union/anonymous struct
>  * @arg2b: second argument of anonymous union/anonymous struct
>  * @arg3: third argument of anonymous union/anonymous struct
>  * @arg4: fourth argument of anonymous union/anonymous struct
>  * @bar.st1.arg1: first argument of struct st1 on union bar
>  * @bar.st1.arg2: second argument of struct st1 on union bar
>  * @bar.st1.bar1: bar1 at st1
>  * @bar.st1.bar2: bar2 at st1
>  * @bar.st2.arg1: first argument of struct st2 on union bar
>  * @bar.st2.arg2: second argument of struct st2 on union bar
>  * @bar.st3.arg2: second argument of struct st3 on union bar
>  * @f1: nested function on anonimous union/struct
>  * @bar.st2.f2: nested function on named union/struct
>  */
> struct my_struct {
>/* Anonymous union/struct*/
>union {
>   struct {
>   char arg1 : 1;
>   char arg2 : 3;
>   };
>struct {
>int arg1b;
>int arg2b;
>};
>struct {
>void *arg3;
>int arg4;
>int (*f1)(char foo, int bar);
>};
>};
>union {
>struct {
>int arg1;
>int arg2;
>  struct foo bar1, *bar2;
>} st1;   /* bar.st1 is undocumented, cause a warning */
>struct {
>void *arg1;  /* bar.st3.arg1 is undocumented, cause a warning */
>   int arg2;
>   int (*f2)(char foo, int bar); /* bar.st3.fn2 is undocumented, cause 
> a warning */
>} st2, st3, *st4;
>int (*f3)(char foo, int bar); /* f3 is undocumented, cause a warning */
>} bar;   /* bar is undocumented, cause a warning */
>
>/* private: */
>int undoc_privat;/* is undocumented but private, no warning */
>
>/* public: */
>int undoc_public;/* is undocumented, cause a warning */
> };
> 
>
> It produces the following warnings, as expected:
>
> test2.h:57: warning: Function parameter or member 'bar' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st1' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st2' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st3' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st3.arg1' not 
> described in 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st3.f2' not described 
> in 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st4' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st4.arg1' not 
> described in 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st4.arg2' not 
> described in 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.st4.f2' not described 
> in 'my_struct'
> test2.h:57: warning: Function parameter or member 'bar.f3' not described in 
> 'my_struct'
> test2.h:57: warning: Function parameter or member 'undoc_public' not 
> described in 'my_struct'
>
> Suggested-by: Markus Heiser 
> 

Re: [PATCHv2 2/9] media: convert g/s_parm to g/s_frame_interval in subdevs

2018-02-14 Thread Mauro Carvalho Chehab
Em Mon, 22 Jan 2018 13:31:18 +0100
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> Convert all g/s_parm calls to g/s_frame_interval. This allows us
> to remove the g/s_parm ops since those are a duplicate of
> g/s_frame_interval.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/i2c/mt9v011.c | 31 +++-
>  drivers/media/i2c/ov6650.c  | 35 +-
>  drivers/media/i2c/ov7670.c  | 24 +++
>  drivers/media/i2c/ov7740.c  | 31 +++-
>  drivers/media/i2c/tvp514x.c | 39 
> +
>  drivers/media/i2c/vs6624.c  | 29 +++---
>  drivers/media/platform/atmel/atmel-isc.c| 10 ++-
>  drivers/media/platform/atmel/atmel-isi.c| 12 ++--
>  drivers/media/platform/blackfin/bfin_capture.c  | 14 +++--
>  drivers/media/platform/marvell-ccic/mcam-core.c | 12 
>  drivers/media/platform/soc_camera/soc_camera.c  | 10 ---
>  drivers/media/platform/via-camera.c |  4 +--
>  drivers/media/usb/em28xx/em28xx-video.c | 36 +++
>  13 files changed, 122 insertions(+), 165 deletions(-)
> 
> diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
> index 5e29064fae91..3e23c5b0de1f 100644
> --- a/drivers/media/i2c/mt9v011.c
> +++ b/drivers/media/i2c/mt9v011.c
> @@ -364,33 +364,24 @@ static int mt9v011_set_fmt(struct v4l2_subdev *sd,
>   return 0;
>  }
>  
> -static int mt9v011_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
> *parms)
> +static int mt9v011_g_frame_interval(struct v4l2_subdev *sd,
> + struct v4l2_subdev_frame_interval *ival)
>  {
> - struct v4l2_captureparm *cp = >parm.capture;
> -
> - if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> - return -EINVAL;
> -
> - memset(cp, 0, sizeof(struct v4l2_captureparm));
> - cp->capability = V4L2_CAP_TIMEPERFRAME;
> + memset(ival->reserved, 0, sizeof(ival->reserved));

Hmm.. why to repeat memset everywhere? If the hole idea is to stop abusing,
the best would be to do, instead:

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index c5639817db34..b18b418c080f 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -350,6 +350,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int 
cmd, void *arg)
if (fi->pad >= sd->entity.num_pads)
return -EINVAL;
 
+   memset(fi->reserved, 0, sizeof(ival->reserved));
return v4l2_subdev_call(sd, video, g_frame_interval, arg);
}
 
(same applies to s_frame_interval).


>   calc_fps(sd,
> -  >timeperframe.numerator,
> -  >timeperframe.denominator);
> +  >interval.numerator,
> +  >interval.denominator);
>  
>   return 0;
>  }
>  
> -static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm 
> *parms)
> +static int mt9v011_s_frame_interval(struct v4l2_subdev *sd,
> + struct v4l2_subdev_frame_interval *ival)
>  {
> - struct v4l2_captureparm *cp = >parm.capture;
> - struct v4l2_fract *tpf = >timeperframe;
> + struct v4l2_fract *tpf = >interval;
>   u16 speed;
>  
> - if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> - return -EINVAL;
> - if (cp->extendedmode != 0)
> - return -EINVAL;
> -

Hmm... why are you removing those sanity checks everywhere?
The core doesn't do it.

All the above comments also apply to the other files modified by
this patch.

> + memset(ival->reserved, 0, sizeof(ival->reserved));
>   speed = calc_speed(sd, tpf->numerator, tpf->denominator);
>  
>   mt9v011_write(sd, R0A_MT9V011_CLK_SPEED, speed);
> @@ -469,8 +460,8 @@ static const struct v4l2_subdev_core_ops mt9v011_core_ops 
> = {
>  };
>  
>  static const struct v4l2_subdev_video_ops mt9v011_video_ops = {
> - .g_parm = mt9v011_g_parm,
> - .s_parm = mt9v011_s_parm,
> + .g_frame_interval = mt9v011_g_frame_interval,
> + .s_frame_interval = mt9v011_s_frame_interval,
>  };
>  
>  static const struct v4l2_subdev_pad_ops mt9v011_pad_ops = {
> diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
> index 8975d16b2b24..3f962dae7534 100644
> --- a/drivers/media/i2c/ov6650.c
> +++ b/drivers/media/i2c/ov6650.c
> @@ -201,7 +201,7 @@ struct ov6650 {
>   struct v4l2_rectrect;   /* sensor cropping window */
>   unsigned long   pclk_limit; /* from host */
>   unsigned long   pclk_max;   /* from resolution and format */
> - struct v4l2_fract   tpf;/* as requested with s_parm */
> + struct v4l2_fract   tpf;/* as 

Re: [PATCHv2 1/9] v4l2-common: create v4l2_g/s_parm_cap helpers

2018-02-14 Thread Mauro Carvalho Chehab
Em Mon, 22 Jan 2018 13:31:17 +0100
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> Create helpers to handle VIDIOC_G/S_PARM by querying the
> g/s_frame_interval v4l2_subdev ops.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/v4l2-core/v4l2-common.c | 48 
> +++
>  include/media/v4l2-common.h   | 26 +++
>  2 files changed, 74 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-common.c 
> b/drivers/media/v4l2-core/v4l2-common.c
> index 8650ad92b64d..96c1b31de9e3 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -392,3 +392,51 @@ void v4l2_get_timestamp(struct timeval *tv)
>   tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>  }
>  EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
> +
> +int v4l2_g_parm_cap(struct video_device *vdev,
> + struct v4l2_subdev *sd, struct v4l2_streamparm *a)
> +{
> + struct v4l2_subdev_frame_interval ival = { 0 };
> + int ret;
> +
> + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
> + a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> + return -EINVAL;
> +
> + if (vdev->device_caps & V4L2_CAP_READWRITE)
> + a->parm.capture.readbuffers = 2;

Hmm... why don't you also initialize readbuffers otherwise?

> + if (v4l2_subdev_has_op(sd, video, g_frame_interval))
> + a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
> + ret = v4l2_subdev_call(sd, video, g_frame_interval, );
> + if (!ret)
> + a->parm.capture.timeperframe = ival.interval;
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_g_parm_cap);
> +
> +int v4l2_s_parm_cap(struct video_device *vdev,
> + struct v4l2_subdev *sd, struct v4l2_streamparm *a)
> +{
> + struct v4l2_subdev_frame_interval ival = {
> + .interval = a->parm.capture.timeperframe
> + };
> + int ret;
> +
> + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
> + a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
> + return -EINVAL;
> +
> + memset(>parm, 0, sizeof(a->parm));
> + if (vdev->device_caps & V4L2_CAP_READWRITE)
> + a->parm.capture.readbuffers = 2;
> + else
> + a->parm.capture.readbuffers = 0;
> +
> + if (v4l2_subdev_has_op(sd, video, g_frame_interval))
> + a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
> + ret = v4l2_subdev_call(sd, video, s_frame_interval, );
> + if (!ret)
> + a->parm.capture.timeperframe = ival.interval;
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_s_parm_cap);
> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> index e0d95a7c5d48..f3aa1d728c0b 100644
> --- a/include/media/v4l2-common.h
> +++ b/include/media/v4l2-common.h
> @@ -341,4 +341,30 @@ v4l2_find_nearest_format(const struct 
> v4l2_frmsize_discrete *sizes,
>   */
>  void v4l2_get_timestamp(struct timeval *tv);
>  
> +/**
> + * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
> + *  calling the g_frame_interval op of the given subdev. It only works
> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
> + *  function name.
> + *
> + * @vdev: the struct video_device pointer. Used to determine the device caps.
> + * @sd: the sub-device pointer.
> + * @a: the VIDIOC_G_PARM argument.
> + */
> +int v4l2_g_parm_cap(struct video_device *vdev,
> + struct v4l2_subdev *sd, struct v4l2_streamparm *a);
> +
> +/**
> + * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
> + *  calling the s_frame_interval op of the given subdev. It only works
> + *  for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
> + *  function name.
> + *
> + * @vdev: the struct video_device pointer. Used to determine the device caps.
> + * @sd: the sub-device pointer.
> + * @a: the VIDIOC_S_PARM argument.
> + */
> +int v4l2_s_parm_cap(struct video_device *vdev,
> + struct v4l2_subdev *sd, struct v4l2_streamparm *a);
> +
>  #endif /* V4L2_COMMON_H_ */



Thanks,
Mauro


Re: [PATCH v10 6/8] media: i2c: Add TDA1997x HDMI receiver driver

2018-02-14 Thread Tim Harvey
On Wed, Feb 14, 2018 at 6:08 AM, Hans Verkuil  wrote:
> Hi Tim,
>
> On 12/02/18 23:27, Tim Harvey wrote:
>> On Fri, Feb 9, 2018 at 12:08 AM, Hans Verkuil  wrote:
>>> Hi Tim,
>>>
>>> We're almost there. Two more comments:
>>>
>>> On 02/09/2018 07:32 AM, Tim Harvey wrote:
 +static int
 +tda1997x_detect_std(struct tda1997x_state *state,
 + struct v4l2_dv_timings *timings)
 +{
 + struct v4l2_subdev *sd = >sd;
 + u32 vper;
 + u16 hper;
 + u16 hsper;
 + int i;
 +
 + /*
 +  * Read the FMT registers
 +  *   REG_V_PER: Period of a frame (or two fields) in MCLK(27MHz) 
 cycles
 +  *   REG_H_PER: Period of a line in MCLK(27MHz) cycles
 +  *   REG_HS_WIDTH: Period of horiz sync pulse in MCLK(27MHz) cycles
 +  */
 + vper = io_read24(sd, REG_V_PER) & MASK_VPER;
 + hper = io_read16(sd, REG_H_PER) & MASK_HPER;
 + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH;
 + if (!vper || !hper || !hsper)
 + return -ENOLINK;
>>>
>>> See my comment for g_input_status below. This condition looks more like a
>>> ENOLCK.
>>>
>>> Or perhaps it should be:
>>>
>>> if (!vper && !hper && !hsper)
>>> return -ENOLINK;
>>> if (!vper || !hper || !hsper)
>>> return -ENOLCK;
>>>
>>> I would recommend that you test a bit with no signal and a bad signal 
>>> (perhaps
>>> one that uses a pixelclock that is too high for this device?).
>>
>> I can't figure out how to produce a signal that can't be locked onto
>> with what I have available.
>
> Are you using a signal generator or just a laptop or something similar as the
> source?
>
> Without a good signal generator it is tricky to test this. A very long HDMI
> cable would likely do it. But for 1080p60 you probably need 20 meters or
> more.
>

I'm using a Marshall V-SG4K-HDI
(http://www.lcdracks.com/racks/DLW/V-SG4K-HDI-signal-generator.php).
It does support 'user defined timings' (see
http://www.lcdracks.com/racks/pdf-pages/instruction_sheets/V-SG4K-HDI_Manual-web.pdf
Timings Details Menu page) and it looks like the max pixel-clock is
300MHz so perhaps I can create a timing that can't be locked onto that
way.

The TDA19971 datasheet
(http://tharvey/src/nxp/tda1997x/TDA19971-datasheet-rev3.pdf) says it
supports:
- All HDTV formats up to 1920x1080p at 50/60 Hz with support for
reduced blanking
- 3D formats including all primary formats up to 1920x1080p at 30 Hz
Frame Packing and 1920x1080p at 60 Hz Side-by-Side and Top-and-Bottom
- PC formats up to UXGA (1600x1200p at 60 Hz) and WUXGA (1920x1200p at 60 Hz)

>>

>>>
 +static int
 +tda1997x_g_input_status(struct v4l2_subdev *sd, u32 *status)
 +{
 + struct tda1997x_state *state = to_state(sd);
 + u32 vper;
 + u16 hper;
 + u16 hsper;
 +
 + mutex_lock(>lock);
 + v4l2_dbg(1, debug, sd, "inputs:%d/%d\n",
 +  state->input_detect[0], state->input_detect[1]);
 + if (state->input_detect[0] || state->input_detect[1])
>>>
>>> I'm confused. This device has two HDMI inputs?
>>>
>>> Does 'detecting input' equate to 'I see a signal and I am locked'?
>>> I gather from the irq function that sets these values that it is closer
>>> to 'I see a signal' and that 'I am locked' is something you would test
>>> by looking at the vper/hper/hsper.
>>
>> The TDA19972 and/or TDA19973 has an A and B input but only a single
>> output. I'm not entirely clear if/how to select between the two and I
>> don't have proper documentation for the three chips.
>>
>> The TDA19971 which I have on my board only has 1 input which is
>> reported as the 'A' input. I can likely nuke the stuff looking at the
>> B input and/or put some qualifiers around it but I didn't want to
>> remove code that was derived from some vendor code that might help
>> support the other chips in the future. So I would rather like to leave
>> the 'if A or B' stuff.
>
> OK. Can you add a comment somewhere in the driver about this?
>
> It sounds like it is similar to what the adv7604 has: several inputs but
> only one is used for streaming. But the EDID is made available on both inputs.
>

sure, I will comment about it. I believe that is the way the it works as well.

>>>
 + *status = 0;
 + else {
 + vper = io_read24(sd, REG_V_PER) & MASK_VPER;
 + hper = io_read16(sd, REG_H_PER) & MASK_HPER;
 + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH;
 + v4l2_dbg(1, debug, sd, "timings:%d/%d/%d\n", vper, hper, 
 hsper);
 + if (!vper || !hper || !hsper)
 + *status |= V4L2_IN_ST_NO_SYNC;
 + else
 + *status |= V4L2_IN_ST_NO_SIGNAL;
>>>
>>> So if we have valid vper, hper and hsper, then there is no signal? That 
>>> 

Re: i.MX53 using imx-media to capture analog video through ADV7180

2018-02-14 Thread Fabio Estevam
[Adding Steve and Philipp in case they could provide some suggestions]

On Wed, Feb 14, 2018 at 1:21 PM, Matthew Starr  wrote:
> I have successfully modified device tree files in the mainline 4.15.1 kernel 
> to get a display product using the i.MX53 processor to initialize the 
> imx-media drivers.  I think up to this point they have only been tested on 
> i.MX6 processors.  I am using two ADV7180 analog capture chips, one per CSI 
> port, on this display product.
>
> I have everything initialize successfully at boot, but I am unable to get the 
> media-ctl command to link the ADV7180 devices to the CSI ports.  I used the 
> following website as guidance of how to setup the links between media devices:
> https://linuxtv.org/downloads/v4l-dvb-apis/v4l-drivers/imx.html
>
> When trying to link the ADV7180 chip to a CSI port, I use the following 
> command and get the result below:
>
> media-ctl -v -l "'adv7180 1-0021':0->'ipu1_csi0':0[1]"
>
> No link between "adv7180 1-0021":0 and "ipu1_csi0":0
> media_parse_setup_link: Unable to parse link
> Unable to parse link: Invalid argument (22)
>
> How do I get the ADV7180 and CSI port on the i.MX53 processor to link?
>
> The difference for the i.MX53 compared to the i.MX6 processor is that there 
> is only one IPU and no mipi support, so my device tree does not use any 
> video-mux or mux devices.  Could this have something to do with why I can't 
> link the ADV7180 to the CSI port?
>
> Here is the output of the "media-ctl -p -v" command:
>
> Opening media device /dev/media0
> Enumerating entities
> looking up device: 81:10
> looking up device: 81:11
> looking up device: 81:12
> looking up device: 81:4
> looking up device: 81:13
> looking up device: 81:5
> looking up device: 81:14
> looking up device: 81:15
> looking up device: 81:16
> looking up device: 81:17
> looking up device: 81:6
> looking up device: 81:18
> looking up device: 81:7
> looking up device: 81:19
> looking up device: 81:20
> looking up device: 81:8
> looking up device: 81:21
> looking up device: 81:9
> Found 18 entities
> Enumerating pads and links
> Media controller API version 4.15.1
>
> Media device information
> 
> driver  imx-media
> model   imx-media
> serial
> bus info
> hw revision 0x0
> driver version  4.15.1
>
> Device topology
> - entity 1: adv7180 1-0021 (1 pad, 0 link)
> type V4L2 subdev subtype Unknown flags 20004
> device node name /dev/v4l-subdev0
> pad0: Source
> [fmt:UYVY8_2X8/720x480 field:interlaced]
>
> - entity 3: adv7180 1-0020 (1 pad, 0 link)
> type V4L2 subdev subtype Unknown flags 20004
> device node name /dev/v4l-subdev1
> pad0: Source
> [fmt:UYVY8_2X8/720x480 field:interlaced]
>
> - entity 5: ipu1_csi1 (3 pads, 3 links)
> type V4L2 subdev subtype Unknown flags 0
> device node name /dev/v4l-subdev2
> pad0: Sink
> [fmt:UYVY8_2X8/640x480 field:none
>  crop.bounds:(0,0)/640x480
>  crop:(0,0)/640x480
>  compose.bounds:(0,0)/640x480
>  compose:(0,0)/640x480]
> pad1: Source
> [fmt:AYUV8_1X32/640x480 field:none]
> -> "ipu1_ic_prp":0 []
> -> "ipu1_vdic":0 []
> pad2: Source
> [fmt:AYUV8_1X32/640x480 field:none]
> -> "ipu1_csi1 capture":0 []
>
> - entity 9: ipu1_csi1 capture (1 pad, 1 link)
> type Node subtype V4L flags 0
> device node name /dev/video4
> pad0: Sink
> <- "ipu1_csi1":2 []
>
> - entity 15: ipu1_csi0 (3 pads, 3 links)
>  type V4L2 subdev subtype Unknown flags 0
>  device node name /dev/v4l-subdev3
> pad0: Sink
> [fmt:UYVY8_2X8/640x480 field:none
>  crop.bounds:(0,0)/640x480
>  crop:(0,0)/640x480
>  compose.bounds:(0,0)/640x480
>  compose:(0,0)/640x480]
> pad1: Source
> [fmt:AYUV8_1X32/640x480 field:none]
> -> "ipu1_ic_prp":0 []
> -> "ipu1_vdic":0 [ENABLED]
> pad2: Source
> [fmt:AYUV8_1X32/640x480 field:none]
> -> "ipu1_csi0 capture":0 []
>
> - entity 19: ipu1_csi0 capture (1 pad, 1 link)
>  type Node subtype V4L flags 0
>  device node name /dev/video5
> pad0: Sink
> <- "ipu1_csi0":2 []
>
> - entity 25: ipu1_ic_prp (3 pads, 5 links)
>  type V4L2 subdev subtype Unknown flags 0
>  device node name /dev/v4l-subdev4
> pad0: Sink
> [fmt:AYUV8_1X32/640x480 field:none]
> <- "ipu1_csi1":1 []
> <- "ipu1_csi0":1 []
> <- "ipu1_vdic":2 [ENABLED]
> pad1: Source
> 

i.MX53 using imx-media to capture analog video through ADV7180

2018-02-14 Thread Matthew Starr
I have successfully modified device tree files in the mainline 4.15.1 kernel to 
get a display product using the i.MX53 processor to initialize the imx-media 
drivers.  I think up to this point they have only been tested on i.MX6 
processors.  I am using two ADV7180 analog capture chips, one per CSI port, on 
this display product.

I have everything initialize successfully at boot, but I am unable to get the 
media-ctl command to link the ADV7180 devices to the CSI ports.  I used the 
following website as guidance of how to setup the links between media devices:
https://linuxtv.org/downloads/v4l-dvb-apis/v4l-drivers/imx.html

When trying to link the ADV7180 chip to a CSI port, I use the following command 
and get the result below:

media-ctl -v -l "'adv7180 1-0021':0->'ipu1_csi0':0[1]"

No link between "adv7180 1-0021":0 and "ipu1_csi0":0
media_parse_setup_link: Unable to parse link
Unable to parse link: Invalid argument (22)

How do I get the ADV7180 and CSI port on the i.MX53 processor to link?

The difference for the i.MX53 compared to the i.MX6 processor is that there is 
only one IPU and no mipi support, so my device tree does not use any video-mux 
or mux devices.  Could this have something to do with why I can't link the 
ADV7180 to the CSI port?   

Here is the output of the "media-ctl -p -v" command:

Opening media device /dev/media0
Enumerating entities
looking up device: 81:10
looking up device: 81:11
looking up device: 81:12
looking up device: 81:4
looking up device: 81:13
looking up device: 81:5
looking up device: 81:14
looking up device: 81:15
looking up device: 81:16
looking up device: 81:17
looking up device: 81:6
looking up device: 81:18
looking up device: 81:7
looking up device: 81:19
looking up device: 81:20
looking up device: 81:8
looking up device: 81:21
looking up device: 81:9
Found 18 entities
Enumerating pads and links
Media controller API version 4.15.1

Media device information

driver  imx-media
model   imx-media
serial  
bus info
hw revision 0x0
driver version  4.15.1

Device topology
- entity 1: adv7180 1-0021 (1 pad, 0 link)
type V4L2 subdev subtype Unknown flags 20004
device node name /dev/v4l-subdev0
pad0: Source
[fmt:UYVY8_2X8/720x480 field:interlaced]

- entity 3: adv7180 1-0020 (1 pad, 0 link)
type V4L2 subdev subtype Unknown flags 20004
device node name /dev/v4l-subdev1
pad0: Source
[fmt:UYVY8_2X8/720x480 field:interlaced]

- entity 5: ipu1_csi1 (3 pads, 3 links)
type V4L2 subdev subtype Unknown flags 0
device node name /dev/v4l-subdev2
pad0: Sink
[fmt:UYVY8_2X8/640x480 field:none
 crop.bounds:(0,0)/640x480
 crop:(0,0)/640x480
 compose.bounds:(0,0)/640x480
 compose:(0,0)/640x480]
pad1: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_ic_prp":0 []
-> "ipu1_vdic":0 []
pad2: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_csi1 capture":0 []

- entity 9: ipu1_csi1 capture (1 pad, 1 link)
type Node subtype V4L flags 0
device node name /dev/video4
pad0: Sink
<- "ipu1_csi1":2 []

- entity 15: ipu1_csi0 (3 pads, 3 links)
 type V4L2 subdev subtype Unknown flags 0
 device node name /dev/v4l-subdev3
pad0: Sink
[fmt:UYVY8_2X8/640x480 field:none
 crop.bounds:(0,0)/640x480
 crop:(0,0)/640x480
 compose.bounds:(0,0)/640x480
 compose:(0,0)/640x480]
pad1: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_ic_prp":0 []
-> "ipu1_vdic":0 [ENABLED]
pad2: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_csi0 capture":0 []

- entity 19: ipu1_csi0 capture (1 pad, 1 link)
 type Node subtype V4L flags 0
 device node name /dev/video5
pad0: Sink
<- "ipu1_csi0":2 []

- entity 25: ipu1_ic_prp (3 pads, 5 links)
 type V4L2 subdev subtype Unknown flags 0
 device node name /dev/v4l-subdev4
pad0: Sink
[fmt:AYUV8_1X32/640x480 field:none]
<- "ipu1_csi1":1 []
<- "ipu1_csi0":1 []
<- "ipu1_vdic":2 [ENABLED]
pad1: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_ic_prpenc":0 []
pad2: Source
[fmt:AYUV8_1X32/640x480 field:none]
-> "ipu1_ic_prpvf":0 [ENABLED]

- entity 29: ipu1_vdic (3 pads, 3 links)
 type V4L2 subdev subtype Unknown flags 0
 device node name /dev/v4l-subdev5
pad0: Sink

Re: [PATCH v2] videodev2.h: add helper to validate colorspace

2018-02-14 Thread Laurent Pinchart
Hi Niklas,

Thank you for the patch.

On Wednesday, 14 February 2018 12:36:43 EET Niklas Söderlund wrote:
> There is no way for drivers to validate a colorspace value, which could
> be provided by user-space by VIDIOC_S_FMT for example. Add a helper to
> validate that the colorspace value is part of enum v4l2_colorspace.
> 
> Signed-off-by: Niklas Söderlund 
> ---
>  include/uapi/linux/videodev2.h | 4 
>  1 file changed, 4 insertions(+)
> 
> Hi,
> 
> I hope this is the correct header to add this helper to. I think it's
> since if it's in uapi not only can v4l2 drivers use it but tools like
> v4l-compliance gets access to it and can be updated to use this instead
> of the hard-coded check of just < 0xff as it was last time I checked.
> 
> * Changes since v1
> - Cast colorspace to u32 as suggested by Sakari and only check the upper
>   boundary to address a potential issue brought up by Laurent if the
>   data type tested is u32 which is not uncommon:
> 
> enum.c:30:16: warning: comparison of unsigned expression >= 0 is always
> true [-Wtype-limits]
>   return V4L2_COLORSPACE_IS_VALID(colorspace);
> 
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 9827189651801e12..1f27c0f4187cbded 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -238,6 +238,10 @@ enum v4l2_colorspace {
>   V4L2_COLORSPACE_DCI_P3= 12,
>  };
> 
> +/* Determine if a colorspace is defined in enum v4l2_colorspace */
> +#define V4L2_COLORSPACE_IS_VALID(colorspace) \
> + ((u32)(colorspace) <= V4L2_COLORSPACE_DCI_P3)
> +

Casting to u32 has the added benefit that the colorspace expression is 
evaluated once only, I like that.

Reviewed-by: Laurent Pinchart 

>  /*
>   * Determine how COLORSPACE_DEFAULT should map to a proper colorspace.
>   * This depends on whether this is a SDTV image (use SMPTE 170M), an


-- 
Regards,

Laurent Pinchart



Re: [PATCH v7 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2018-02-14 Thread Laurent Pinchart
Hi Maxime,

On Wednesday, 14 February 2018 15:19:33 EET Maxime Ripard wrote:
> On Thu, Feb 08, 2018 at 08:17:19PM +0200, Laurent Pinchart wrote:
> >> +  /*
> >> +   * Create a static mapping between the CSI virtual channels
> >> +   * and the output stream.
> >> +   *
> >> +   * This should be enhanced, but v4l2 lacks the support for
> >> +   * changing that mapping dynamically.
> >> +   *
> >> +   * We also cannot enable and disable independant streams here,
> >> +   * hence the reference counting.
> >> +   */
> > 
> > If you start all streams in one go, will s_stream(1) be called multiple
> > times ? If not, you could possibly skip the whole reference counting and
> > avoid locking.
> 
> I guess that while we should expect the CSI-2 bus to be always
> enabled, the downstream camera interface could be shutdown
> independently, so I guess s_stream would be called each time one is
> brought up or brought down?

That's the idea. However, we don't have support for multiplexed streams in 
mainline yet, so there's no way it can be implemented today in your driver.

-- 
Regards,

Laurent Pinchart



Re: [PATCH v10 6/8] media: i2c: Add TDA1997x HDMI receiver driver

2018-02-14 Thread Hans Verkuil
Hi Tim,

On 12/02/18 23:27, Tim Harvey wrote:
> On Fri, Feb 9, 2018 at 12:08 AM, Hans Verkuil  wrote:
>> Hi Tim,
>>
>> We're almost there. Two more comments:
>>
>> On 02/09/2018 07:32 AM, Tim Harvey wrote:
>>> +static int
>>> +tda1997x_detect_std(struct tda1997x_state *state,
>>> + struct v4l2_dv_timings *timings)
>>> +{
>>> + struct v4l2_subdev *sd = >sd;
>>> + u32 vper;
>>> + u16 hper;
>>> + u16 hsper;
>>> + int i;
>>> +
>>> + /*
>>> +  * Read the FMT registers
>>> +  *   REG_V_PER: Period of a frame (or two fields) in MCLK(27MHz) 
>>> cycles
>>> +  *   REG_H_PER: Period of a line in MCLK(27MHz) cycles
>>> +  *   REG_HS_WIDTH: Period of horiz sync pulse in MCLK(27MHz) cycles
>>> +  */
>>> + vper = io_read24(sd, REG_V_PER) & MASK_VPER;
>>> + hper = io_read16(sd, REG_H_PER) & MASK_HPER;
>>> + hsper = io_read16(sd, REG_HS_WIDTH) & MASK_HSWIDTH;
>>> + if (!vper || !hper || !hsper)
>>> + return -ENOLINK;
>>
>> See my comment for g_input_status below. This condition looks more like a
>> ENOLCK.
>>
>> Or perhaps it should be:
>>
>> if (!vper && !hper && !hsper)
>> return -ENOLINK;
>> if (!vper || !hper || !hsper)
>> return -ENOLCK;
>>
>> I would recommend that you test a bit with no signal and a bad signal 
>> (perhaps
>> one that uses a pixelclock that is too high for this device?).
> 
> I can't figure out how to produce a signal that can't be locked onto
> with what I have available.

Are you using a signal generator or just a laptop or something similar as the
source?

Without a good signal generator it is tricky to test this. A very long HDMI
cable would likely do it. But for 1080p60 you probably need 20 meters or
more.

> 
>>
>>> + v4l2_dbg(1, debug, sd, "Signal Timings: %u/%u/%u\n", vper, hper, 
>>> hsper);
>>> +
>>> + for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) {
>>> + const struct v4l2_bt_timings *bt;
>>> + u32 lines, width, _hper, _hsper;
>>> + u32 vmin, vmax, hmin, hmax, hsmin, hsmax;
>>> + bool vmatch, hmatch, hsmatch;
>>> +
>>> + bt = _dv_timings_presets[i].bt;
>>> + width = V4L2_DV_BT_FRAME_WIDTH(bt);
>>> + lines = V4L2_DV_BT_FRAME_HEIGHT(bt);
>>> + _hper = (u32)bt->pixelclock / width;
>>> + if (bt->interlaced)
>>> + lines /= 2;
>>> + /* vper +/- 0.7% */
>>> + vmin = ((2700 / 1000) * 993) / _hper * lines;
>>> + vmax = ((2700 / 1000) * 1007) / _hper * lines;
>>> + /* hper +/- 1.0% */
>>> + hmin = ((2700 / 100) * 99) / _hper;
>>> + hmax = ((2700 / 100) * 101) / _hper;
>>> + /* hsper +/- 2 (take care to avoid 32bit overflow) */
>>> + _hsper = 27000 * bt->hsync / ((u32)bt->pixelclock/1000);
>>> + hsmin = _hsper - 2;
>>> + hsmax = _hsper + 2;
>>> +
>>> + /* vmatch matches the framerate */
>>> + vmatch = ((vper <= vmax) && (vper >= vmin)) ? 1 : 0;
>>> + /* hmatch matches the width */
>>> + hmatch = ((hper <= hmax) && (hper >= hmin)) ? 1 : 0;
>>> + /* hsmatch matches the hswidth */
>>> + hsmatch = ((hsper <= hsmax) && (hsper >= hsmin)) ? 1 : 0;
>>> + if (hmatch && vmatch && hsmatch) {
>>> + *timings = v4l2_dv_timings_presets[i];
>>> + v4l2_print_dv_timings(sd->name, "Detected format: ",
>>> +   timings, false);
>>> + return 0;
>>> + }
>>> + }
>>> +
>>> + v4l_err(state->client, "no resolution match for timings: %d/%d/%d\n",
>>> + vper, hper, hsper);
>>> + return -EINVAL;
>>> +}
>>
>> -EINVAL isn't the correct error code here. I would go for -ERANGE. It's not
>> perfect, but close enough.
>>
>> -EINVAL indicates that the user filled in wrong values, but that's not the
>> case here.
> 
> done
> 
>>
>>> +static int
>>> +tda1997x_g_input_status(struct v4l2_subdev *sd, u32 *status)
>>> +{
>>> + struct tda1997x_state *state = to_state(sd);
>>> + u32 vper;
>>> + u16 hper;
>>> + u16 hsper;
>>> +
>>> + mutex_lock(>lock);
>>> + v4l2_dbg(1, debug, sd, "inputs:%d/%d\n",
>>> +  state->input_detect[0], state->input_detect[1]);
>>> + if (state->input_detect[0] || state->input_detect[1])
>>
>> I'm confused. This device has two HDMI inputs?
>>
>> Does 'detecting input' equate to 'I see a signal and I am locked'?
>> I gather from the irq function that sets these values that it is closer
>> to 'I see a signal' and that 'I am locked' is something you would test
>> by looking at the vper/hper/hsper.
> 
> The TDA19972 and/or TDA19973 has an A and B input but only a single
> output. I'm not entirely clear if/how to select between the two and I

[PATCH 1/1] media: request: Add support for tagged request-based objects

2018-02-14 Thread Sakari Ailus
Allow binding objects to requests that can be later on fetched based on
that tag.

The intent is that the objects are bound at the time data is bound to a
request and later retrieved for validation (and finally applied) when the
request is queued. A tag can be any pointer, as long as it is unique to a
request.

Signed-off-by: Sakari Ailus 
---
Hi Alexandre,

Here's the patch. It's on top of your current set so if you remove entity
data support there may be some conflicts to resolve. It's only been
compile tested so far, but is rather simple. By providing a tag, the
caller may attach data objects to the request and they can be found later
on, by using the same tag, when the request is queued.

The drivers are still responsible for adding only objects they can support
with requests. The driver must also detach the data from the request, and
at the queue time, make sure that no objects that weren't accounted for
were added.

 drivers/media/media-request.c | 105 ++
 include/media/media-request.h |  75 ++
 2 files changed, 180 insertions(+)

diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
index 30a2323..c96b747 100644
--- a/drivers/media/media-request.c
+++ b/drivers/media/media-request.c
@@ -57,10 +57,115 @@ media_request_get_from_fd(int fd)
 }
 EXPORT_SYMBOL_GPL(media_request_get_from_fd);
 
+int media_request_data_attach(struct media_request *req, const void *tag,
+ void *data,
+ void (*release)(struct media_request *req,
+ const void *tag, void *data))
+{
+   struct media_request_data *req_data;
+
+   req_data = kzalloc(sizeof(*req_data), GFP_KERNEL);
+   if (!req_data)
+   return -ENOMEM;
+
+   req_data->req = req;
+   req_data->tag = tag;
+   req_data->data = data;
+   req_data->release = release;
+
+   mutex_lock(>lock);
+   list_add(_data->list, >data_list);
+   mutex_unlock(>lock);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(media_request_data_attach);
+
+struct media_request_data *__media_request_data_find(
+   struct media_request *req, const void *tag)
+{
+   struct media_request_data *req_data;
+
+   lockdep_assert_held(>lock);
+
+   list_for_each_entry(req_data, >data_list, list)
+   if (req_data->tag == tag)
+   return req_data;
+
+   return NULL;
+}
+EXPORT_SYMBOL_GPL(__media_request_data_find);
+
+void *media_request_data_find(struct media_request *req, const void *tag)
+{
+   struct media_request_data *req_data;
+   void *data;
+
+   mutex_lock(>lock);
+   req_data = __media_request_data_find(req, tag);
+   mutex_lock(>lock);
+
+   data = req_data ? req_data->data : NULL;
+
+   return data;
+}
+EXPORT_SYMBOL_GPL(media_request_data_find);
+
+void media_request_data_detach(struct media_request *req, const void *tag)
+{
+   struct media_request_data *req_data;
+
+   mutex_lock(>lock);
+
+   req_data = __media_request_data_find(req, tag);
+   if (WARN_ON(!req_data)) {
+   mutex_unlock(>lock);
+   return;
+   }
+
+   list_del(_data->list);
+
+   mutex_unlock(>lock);
+
+   if (req_data->release)
+   req_data->release(req_data->req, req_data->tag, req_data->data);
+
+   kfree(req_data);
+}
+EXPORT_SYMBOL_GPL(media_request_data_detach);
+
+static void __media_request_data_detach(struct media_request_data *req)
+{
+   struct media_request_data *req_data;
+
+   list_del(_data->list);
+
+   if (req_data->release)
+   req_data->release(req_data->req, req_data->tag, req_data->data);
+
+   kfree(req_data);
+}
+
+bool media_request_has_data(struct media_request *req)
+{
+   bool ret;
+
+   mutex_lock(>lock);
+   ret = list_empty(>data_list);
+   mutex_unlock(>lock);
+
+   return ret;
+}
+
 static void media_request_release(struct kref *kref)
 {
struct media_request *req =
container_of(kref, typeof(*req), kref);
+   struct media_request_data *req_data, *req_data_safe;
+
+   /* Last reference; no need to acquire the lock here. */
+   list_for_each_entry_safe(req_data, req_data_safe, >data_list, list)
+   __media_request_data_detach(req_data);
 
req->mgr->ops->req_free(req);
 }
diff --git a/include/media/media-request.h b/include/media/media-request.h
index 817df13..64b945d 100644
--- a/include/media/media-request.h
+++ b/include/media/media-request.h
@@ -36,12 +36,23 @@ enum media_request_state {
MEDIA_REQUEST_STATE_DELETED,
 };
 
+struct media_request_data {
+   struct media_request *req;
+   const void *tag;
+   struct list_head list;
+   void *data;
+   void (*release)(struct media_request *req,
+   const void *tag, void *data);
+};
+
 

Re: [PATCH v7 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2018-02-14 Thread Maxime Ripard
Hi Laurent,

On Thu, Feb 08, 2018 at 08:17:19PM +0200, Laurent Pinchart wrote:
> > +   /*
> > +* Create a static mapping between the CSI virtual channels
> > +* and the output stream.
> > +*
> > +* This should be enhanced, but v4l2 lacks the support for
> > +* changing that mapping dynamically.
> > +*
> > +* We also cannot enable and disable independant streams here,
> > +* hence the reference counting.
> > +*/
> 
> If you start all streams in one go, will s_stream(1) be called multiple times 
> ? If not, you could possibly skip the whole reference counting and avoid 
> locking.

I guess that while we should expect the CSI-2 bus to be always
enabled, the downstream camera interface could be shutdown
independently, so I guess s_stream would be called each time one is
brought up or brought down?

Maxime

-- 
Maxime Ripard, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com


signature.asc
Description: PGP signature


media: v4l: alsa: Associating V4L2 and ALSA devices coming from the same device (a webcam for example)

2018-02-14 Thread Carlos Rafael Giani
I have an application that allows for recording audio/video from input 
devices. I now want to add to it the ability to autodetect plugged-in 
USB webcams via udev. The problem is that audio and video are handled 
separately, by a video4linux and an ALSA device. The goal is to discover 
the ALSA device name and the Video4Linux device node that are associated 
(that is, belonging to the same camera input feed).


Surprisingly, there does not seem to be any interface in V4L2 for this, 
so I had to resort to looking at the udev properties. I came up with a 
very dirty hack that accomplishes what I want. I pasted it below.


This code relies on the ID_USB_INTERFACES property to associate the V4L2 
and ALSA devices, which may or may not be fragile. Furthermore, it 
traverses directories in /sys/ . I use libgudev here.


I now ask the mailing list if there is an easier way to do this. Note 
that I cannot rely on tools like the gst device monitor. It would also 
be preferable to not have to rely on specific udev rules, though I will 
add them if it is truly necessary.


Also, I found it difficult to get a meaningful label that I can present 
the user. The V4L2 properties produced fairly useless labels (something 
like "UVC camera (:)"). What produced the best results was the 
ID_MODEL_FROM_DATABASE - but this is a property of the ALSA devices.


So, anybody has a better idea how to accomplish this?


The hacky code:

    std::regex 
sndcard_regex(".*/sound/card[[:digit:]]+/controlC[[:digit:]]+$");

    std::regex pcmc_regex("pcmC([[:digit:]]+)D([[:digit:]]+)c");

    void process_added_device(GUdevDevice *p_added_device)
    {
        gchar const *bus_cstr = 
g_udev_device_get_property(p_added_device, "ID_BUS");

        if (g_strcmp0(bus_cstr, "usb") != 0)
            return;

        gchar const *path_cstr = 
g_udev_device_get_sysfs_path(p_added_device);
        gchar const *subsystem_cstr = 
g_udev_device_get_property(p_added_device, "SUBSYSTEM");
        gchar const *usb_interfaces_cstr = 
g_udev_device_get_property(p_added_device, "ID_USB_INTERFACES");


        std::string id = std::string("usbif_") + usb_interfaces_cstr;

        capture_device new_capture_device;
        new_capture_device.m_is_hdmi_device = false;
        new_capture_device.m_label = id; // initially use the ID as 
label, as fallback if no other label can be found

        new_capture_device.m_id = id;

        auto _view = m_entries.get < id_tag > ();
        auto iter = id_view.find(id);
        if (iter != id_view.end()) // check if an entry exists already; 
if so, retrieve it

        {
            new_capture_device = *iter;
            // remove the device from the boost multi-index container. 
we'll reinsert a modified version later.

            id_view.erase(iter);
        }

        if (g_strcmp0(subsystem_cstr, "video4linux") == 0)
        {
            gchar const *devnode_cstr = 
g_udev_device_get_device_file(p_added_device);

            new_capture_device.m_v4l2_device = devnode_cstr;
        }
        else if (g_strcmp0(subsystem_cstr, "sound") == 0)
        {
            gchar const *model_from_db = 
g_udev_device_get_property(p_added_device, "ID_MODEL_FROM_DATABASE");

            if (model_from_db != nullptr)
                new_capture_device.m_label = model_from_db;

            std::smatch base_match;
            std::string path_str = path_cstr;
            if (std::regex_match(path_str, base_match, sndcard_regex)) 
// check if this sound device path is one to an ALSA control device

            {
                boost::filesystem::path path = path_str;
                path = path.parent_path();
                boost::system::error_code ec;
                boost::filesystem::directory_iterator dir_iter(path, ec);
                if (ec)
                    return;

                // search the parent directory for a PCM capture device
                boost::filesystem::directory_iterator end_dir_iter;
                for (; dir_iter != end_dir_iter; ++dir_iter)
                {
                    std::smatch pcm_match;
                    if 
(std::regex_match(dir_iter->path().filename().string(), pcm_match, 
pcmc_regex))
                        new_capture_device.m_alsa_device = 
std::string("plughw:") + std::string(pcm_match[1]) + "," + 
std::string(pcm_match[2]);

                }
            }
        }

        id_view.emplace(new_capture_device);
    }



Re: exposing a large-ish calibration table through V4L2?

2018-02-14 Thread Hans Verkuil
On 14/02/18 13:27, Florian Echtler wrote:
> Hello Hans,
> 
> On 14.02.2018 13:13, Hans Verkuil wrote:
>>
>> On 14/02/18 13:09, Florian Echtler wrote:
>>>
>>> The internal device memory contains a table with two bytes for each sensor 
>>> pixel
>>> (i.e. 960x540x2 = 1036800 bytes) that basically provide individual black and
>>> white levels per-pixel that are used in preprocessing. The table can either 
>>> be
>>> set externally, or the sensor can be covered with a black/white surface and 
>>> a
>>> custom command triggers an internal calibration.
>>>
>>> AFAICT the usual V4L2 controls are unsuitable for this sort of data; do you 
>>> have
>>> any suggestions on how to approach this? Maybe something like a custom 
>>> IOCTL?
>>
>> So the table has a fixed size?
>> You can use array controls for that, a V4L2_CTRL_TYPE_U16 in a 
>> two-dimensional array
>> would do it.
> 
> Good to know, thanks.
> 
>> See https://hverkuil.home.xs4all.nl/spec/uapi/v4l/vidioc-queryctrl.html for 
>> more
>> information on how this works.
> 
> This means I have to implement QUERY_EXT_CTRL, G_EXT_CTRLS and S_EXT_CTRLS,
> correct? Will this work in parallel to the "regular" controls that use the
> control framework?

No, just use the control framework. You need to make a custom control that is
specific to your driver

So reserve a range for your driver in include/uapi/linux/v4l2-controls.h
(search for 'USER-class private control IDs'). Then you can define a control
ID. The next step is to configure the control:

static const struct v4l2_ctrl_config cal_table_control = {
.ops = _ctrl_ops,
.id = V4L2_CID_SUR40_CAL_TABLE,
.name = "Calibration Table",
.type = V4L2_CTRL_TYPE_U16,
.max = 0x,
.step = 1,
.def = 0,
.dims = { 960, 540 },
};

And register it with a control handler:

v4l2_ctrl_new_custom(hdl, _table_control, NULL);

See e.g. drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c and the DETECT_MD 
controls.

Regards,

Hans


[no subject]

2018-02-14 Thread Scott Tisdale
hi Linux https://goo.gl/jMp8sb   Scott Tisdale

Re: exposing a large-ish calibration table through V4L2?

2018-02-14 Thread Florian Echtler
Hello Hans,

On 14.02.2018 13:13, Hans Verkuil wrote:
> 
> On 14/02/18 13:09, Florian Echtler wrote:
>>
>> The internal device memory contains a table with two bytes for each sensor 
>> pixel
>> (i.e. 960x540x2 = 1036800 bytes) that basically provide individual black and
>> white levels per-pixel that are used in preprocessing. The table can either 
>> be
>> set externally, or the sensor can be covered with a black/white surface and a
>> custom command triggers an internal calibration.
>>
>> AFAICT the usual V4L2 controls are unsuitable for this sort of data; do you 
>> have
>> any suggestions on how to approach this? Maybe something like a custom IOCTL?
> 
> So the table has a fixed size?
> You can use array controls for that, a V4L2_CTRL_TYPE_U16 in a 
> two-dimensional array
> would do it.

Good to know, thanks.

> See https://hverkuil.home.xs4all.nl/spec/uapi/v4l/vidioc-queryctrl.html for 
> more
> information on how this works.

This means I have to implement QUERY_EXT_CTRL, G_EXT_CTRLS and S_EXT_CTRLS,
correct? Will this work in parallel to the "regular" controls that use the
control framework?

Best, Florian
-- 
SENT FROM MY DEC VT50 TERMINAL



signature.asc
Description: OpenPGP digital signature


Re: exposing a large-ish calibration table through V4L2?

2018-02-14 Thread Hans Verkuil
Hi Florian,

On 14/02/18 13:09, Florian Echtler wrote:
> Hello Hans,
> 
> I've picked up work on the sur40 driver again recently. There is one major
> feature left that is currently unsupported by the Linux driver, which is the
> hardware-based calibration.
> 
> The internal device memory contains a table with two bytes for each sensor 
> pixel
> (i.e. 960x540x2 = 1036800 bytes) that basically provide individual black and
> white levels per-pixel that are used in preprocessing. The table can either be
> set externally, or the sensor can be covered with a black/white surface and a
> custom command triggers an internal calibration.
> 
> AFAICT the usual V4L2 controls are unsuitable for this sort of data; do you 
> have
> any suggestions on how to approach this? Maybe something like a custom IOCTL?

So the table has a fixed size?

You can use array controls for that, a V4L2_CTRL_TYPE_U16 in a two-dimensional 
array
would do it.

See https://hverkuil.home.xs4all.nl/spec/uapi/v4l/vidioc-queryctrl.html for more
information on how this works.

Regards,

Hans


exposing a large-ish calibration table through V4L2?

2018-02-14 Thread Florian Echtler
Hello Hans,

I've picked up work on the sur40 driver again recently. There is one major
feature left that is currently unsupported by the Linux driver, which is the
hardware-based calibration.

The internal device memory contains a table with two bytes for each sensor pixel
(i.e. 960x540x2 = 1036800 bytes) that basically provide individual black and
white levels per-pixel that are used in preprocessing. The table can either be
set externally, or the sensor can be covered with a black/white surface and a
custom command triggers an internal calibration.

AFAICT the usual V4L2 controls are unsuitable for this sort of data; do you have
any suggestions on how to approach this? Maybe something like a custom IOCTL?

Best regards, Florian
-- 
SENT FROM MY DEC VT50 TERMINAL



signature.asc
Description: OpenPGP digital signature


[PATCH for v3.2 05/12] media: v4l2-compat-ioctl32.c: avoid sizeof(type)

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 333b1e9f96ce05f7498b581509bb30cde03018bf upstream.

Instead of doing sizeof(struct foo) use sizeof(*up). There even were
cases where 4 * sizeof(__u32) was used instead of sizeof(kp->reserved),
which is very dangerous when the size of the reserved array changes.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 65 +++
 1 file changed, 31 insertions(+), 34 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 4d0901573860..e2dee29eaaa5 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -47,7 +47,7 @@ struct v4l2_window32 {
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
get_user(kp->chromakey, >chromakey) ||
@@ -64,7 +64,7 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
if (get_user(p, >clips))
return -EFAULT;
uclips = compat_ptr(p);
-   kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
+   kclips = compat_alloc_user_space(n * sizeof(*kclips));
kp->clips = kclips;
while (--n >= 0) {
if (copy_in_user(>c, >c, 
sizeof(uclips->c)))
@@ -156,14 +156,14 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 
 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)))
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)))
return -EFAULT;
return __get_v4l2_format32(kp, up);
 }
 
 static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct 
v4l2_create_buffers32 __user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, 
format)))
return -EFAULT;
return __get_v4l2_format32(>format, >format);
@@ -204,7 +204,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 
 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
put_user(kp->type, >type))
return -EFAULT;
return __put_v4l2_format32(kp, up);
@@ -212,7 +212,7 @@ static int put_v4l2_format32(struct v4l2_format *kp, struct 
v4l2_format32 __user
 
 static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct 
v4l2_create_buffers32 __user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) 
||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, 
format.fmt)))
return -EFAULT;
return __put_v4l2_format32(>format, >format);
@@ -230,7 +230,7 @@ struct v4l2_standard32 {
 static int get_v4l2_standard32(struct v4l2_standard *kp, struct 
v4l2_standard32 __user *up)
 {
/* other fields are not set by the user, nor used by the driver */
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
get_user(kp->index, >index))
return -EFAULT;
return 0;
@@ -238,13 +238,13 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 
 static int put_v4l2_standard32(struct v4l2_standard *kp, struct 
v4l2_standard32 __user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
put_user(kp->index, >index) ||
copy_to_user(up->id, >id, sizeof(__u64)) ||
-   copy_to_user(up->name, kp->name, 24) ||
+   copy_to_user(up->name, kp->name, sizeof(up->name)) ||
copy_to_user(>frameperiod, >frameperiod, 
sizeof(kp->frameperiod)) ||
put_user(kp->framelines, >framelines) ||
-   copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
+   copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
return -EFAULT;
return 0;
 }
@@ -290,7 +290,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 
  

[PATCH for v3.2 01/12] media: v4l2-ioctl.c: don't copy back the result for -ENOTTY

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 181a4a2d5a0a7b43cab08a70710d727e7764ccdd upstream.

If the ioctl returned -ENOTTY, then don't bother copying
back the result as there is no point.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-ioctl.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 639abeee3392..bae5dd776d82 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -2308,8 +2308,10 @@ video_usercopy(struct file *file, unsigned int cmd, 
unsigned long arg,
 
/* Handles IOCTL */
err = func(file, cmd, parg);
-   if (err == -ENOIOCTLCMD)
-   err = -EINVAL;
+   if (err == -ENOTTY || err == -ENOIOCTLCMD) {
+   err = -ENOTTY;
+   goto out;
+   }
 
if (has_array_args) {
*kernel_ptr = user_ptr;
-- 
2.15.1



[PATCH for v3.2 02/12] media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 3ee6d040719ae09110e5cdf24d5386abe5d1b776 upstream.

The result of the VIDIOC_PREPARE_BUF ioctl was never copied back
to userspace since it was missing in the switch.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 2671959f01bb..9c4a7c7d3534 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -920,6 +920,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
err = put_v4l2_create32(, up);
break;
 
+   case VIDIOC_PREPARE_BUF:
case VIDIOC_QUERYBUF:
case VIDIOC_QBUF:
case VIDIOC_DQBUF:
-- 
2.15.1



[PATCH for v3.2 06/12] media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 8ed5a59dcb47a6f76034ee760b36e089f3e82529 upstream.

The struct v4l2_plane32 should set m.userptr as well. The same
happens in v4l2_buffer32 and v4l2-compliance tests for this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 30 ++
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index e2dee29eaaa5..7477feff92b1 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -293,16 +293,20 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 sizeof(up->data_offset)))
return -EFAULT;
 
-   if (memory == V4L2_MEMORY_USERPTR) {
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
+   if (copy_in_user(>m.mem_offset, >m.mem_offset,
+sizeof(up32->m.mem_offset)))
+   return -EFAULT;
+   break;
+   case V4L2_MEMORY_USERPTR:
if (get_user(p, >m.userptr))
return -EFAULT;
up_pln = compat_ptr(p);
if (put_user((unsigned long)up_pln, >m.userptr))
return -EFAULT;
-   } else {
-   if (copy_in_user(>m.mem_offset, >m.mem_offset,
-sizeof(up32->m.mem_offset)))
-   return -EFAULT;
+   break;
}
 
return 0;
@@ -311,17 +315,27 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
enum v4l2_memory memory)
 {
+   unsigned long p;
+
if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
copy_in_user(>data_offset, >data_offset,
 sizeof(up->data_offset)))
return -EFAULT;
 
-   /* For MMAP, driver might've set up the offset, so copy it back.
-* USERPTR stays the same (was userspace-provided), so no copying. */
-   if (memory == V4L2_MEMORY_MMAP)
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (copy_in_user(>m.mem_offset, >m.mem_offset,
 sizeof(up->m.mem_offset)))
return -EFAULT;
+   break;
+   case V4L2_MEMORY_USERPTR:
+   if (get_user(p, >m.userptr) ||
+   put_user((compat_ulong_t)ptr_to_compat((__force void *)p),
+>m.userptr))
+   return -EFAULT;
+   break;
+   }
 
return 0;
 }
-- 
2.15.1



[PATCH for v3.2 03/12] media: v4l2-compat-ioctl32.c: fix the indentation

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit b7b957d429f601d6d1942122b339474f31191d75 upstream.

The indentation of this source is all over the place. Fix this.
This patch only changes whitespace.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 198 +++---
 1 file changed, 99 insertions(+), 99 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 9c4a7c7d3534..e35142d9781b 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -48,11 +48,11 @@ struct v4l2_window32 {
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
-   copy_from_user(>w, >w, sizeof(up->w)) ||
-   get_user(kp->field, >field) ||
-   get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   copy_from_user(>w, >w, sizeof(up->w)) ||
+   get_user(kp->field, >field) ||
+   get_user(kp->chromakey, >chromakey) ||
+   get_user(kp->clipcount, >clipcount))
+   return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
if (kp->clipcount) {
@@ -82,10 +82,10 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
-   put_user(kp->field, >field) ||
-   put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   put_user(kp->field, >field) ||
+   put_user(kp->chromakey, >chromakey) ||
+   put_user(kp->clipcount, >clipcount))
+   return -EFAULT;
return 0;
 }
 
@@ -97,7 +97,7 @@ static inline int get_v4l2_pix_format(struct v4l2_pix_format 
*kp, struct v4l2_pi
 }
 
 static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -112,7 +112,7 @@ static inline int put_v4l2_pix_format(struct 
v4l2_pix_format *kp, struct v4l2_pi
 }
 
 static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -204,7 +204,7 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return 0;
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -249,7 +249,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return 0;
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -257,7 +257,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
-   put_user(kp->type, >type))
+   put_user(kp->type, >type))
return -EFAULT;
return __put_v4l2_format32(kp, up);
 }
@@ -266,7 +266,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers 
*kp, struct v4l2_create_
 {
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) 
||
copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, 
format.fmt)))
-   return -EFAULT;
+   return -EFAULT;
return __put_v4l2_format32(>format, >format);
 }
 
@@ -283,7 +283,7 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 {
/* other fields are not set by the user, nor used by the driver */
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
-   get_user(kp->index, >index))
+   

[PATCH for v3.2 04/12] media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 486c521510c44a04cd756a9267e7d1e271c8a4ba upstream.

These helper functions do not really help. Move the code to the
__get/put_v4l2_format32 functions.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 94 +++
 1 file changed, 21 insertions(+), 73 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index e35142d9781b..4d0901573860 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -89,64 +89,6 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
return 0;
 }
 
-static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
 struct v4l2_format32 {
enum v4l2_buf_type type;
union {
@@ -184,20 +126,23 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return get_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return copy_from_user(>fmt.pix, >fmt.pix,
+ sizeof(kp->fmt.pix)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-   return get_v4l2_pix_format_mplane(>fmt.pix_mp,
- >fmt.pix_mp);
+   return copy_from_user(>fmt.pix_mp, >fmt.pix_mp,
+ sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-   return get_v4l2_window32(>fmt.win, >fmt.win);
+   return get_v4l2_window32(>fmt.win, >fmt.win);
case V4L2_BUF_TYPE_VBI_CAPTURE:
case V4L2_BUF_TYPE_VBI_OUTPUT:
-   return get_v4l2_vbi_format(>fmt.vbi, >fmt.vbi);
+   return copy_from_user(>fmt.vbi, >fmt.vbi,
+ sizeof(kp->fmt.vbi)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-   return get_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
+   return copy_from_user(>fmt.sliced, >fmt.sliced,
+ sizeof(kp->fmt.sliced)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_PRIVATE:
if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
return -EFAULT;
@@ -229,20 +174,23 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return put_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return 

[PATCH for v3.2 12/12] media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit a1dfb4c48cc1e64eeb7800a27c66a6f7e88d075a upstream.

The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit
equivalent. It converts 32-bit data structures into its 64-bit
equivalents and needs to provide the data to the 64-bit ioctl in user
space memory which is commonly allocated using
compat_alloc_user_space().

However, due to how that function is implemented, it can only be called
a single time for every syscall invocation.

Supposedly to avoid this limitation, the existing code uses a mix of
memory from the kernel stack and memory allocated through
compat_alloc_user_space().

Under normal circumstances, this would not work, because the 64-bit
ioctl expects all pointers to point to user space memory. As a
workaround, set_fs(KERNEL_DS) is called to temporarily disable this
extra safety check and allow kernel pointers. However, this might
introduce a security vulnerability: The result of the 32-bit to 64-bit
conversion is writeable by user space because the output buffer has been
allocated via compat_alloc_user_space(). A malicious user space process
could then manipulate pointers inside this output buffer, and due to the
previous set_fs(KERNEL_DS) call, functions like get_user() or put_user()
no longer prevent kernel memory access.

The new approach is to pre-calculate the total amount of user space
memory that is needed, allocate it using compat_alloc_user_space() and
then divide up the allocated memory to accommodate all data structures
that need to be converted.

An alternative approach would have been to retain the union type karg
that they allocated on the kernel stack in do_video_ioctl(), copy all
data from user space into karg and then back to user space. However, we
decided against this approach because it does not align with other
compat syscall implementations. Instead, we tried to replicate the
get_user/put_user pairs as found in other places in the kernel:

if (get_user(clipcount, >clipcount) ||
put_user(clipcount, >clipcount)) return -EFAULT;

Notes from hans.verk...@cisco.com:

This patch was taken from:

https://github.com/LineageOS/android_kernel_samsung_apq8084/commit/97b733953c06e4f0398ade18850f0817778255f7

Clearly nobody could be bothered to upstream this patch or at minimum
tell us :-( We only heard about this a week ago.

This patch was rebased and cleaned up. Compared to the original I
also swapped the order of the convert_in_user arguments so that they
matched copy_in_user. It was hard to review otherwise. I also replaced
the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.

Fixes: 6b5a9492ca ("v4l: introduce string control support.")

Signed-off-by: Daniel Mentz 
Co-developed-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/Makefile  |   7 +-
 drivers/media/video/v4l2-compat-ioctl32.c | 738 +++---
 2 files changed, 481 insertions(+), 264 deletions(-)

diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 117f9c4b4cb9..aa1e164cfb87 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -13,12 +13,13 @@ omap2cam-objs   :=  omap24xxcam.o omap24xxcam-dma.o
 videodev-objs  :=  v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
v4l2-event.o v4l2-ctrls.o v4l2-subdev.o
 
+ifeq ($(CONFIG_COMPAT),y)
+  videodev-objs += v4l2-compat-ioctl32.o
+endif
+
 # V4L2 core modules
 
 obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-int-device.o
-ifeq ($(CONFIG_COMPAT),y)
-  obj-$(CONFIG_VIDEO_DEV) += v4l2-compat-ioctl32.o
-endif
 
 obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
 
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 7f0eeb8a4d3f..b4f19238c746 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -23,6 +23,14 @@
 
 #ifdef CONFIG_COMPAT
 
+/* Use the same argument order as copy_in_user */
+#define assign_in_user(to, from)   \
+({ \
+   typeof(*from) __assign_tmp; \
+   \
+   get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \
+})
+
 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long 
arg)
 {
long ret = -ENOIOCTLCMD;
@@ -36,12 +44,12 @@ static long native_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
 
 struct v4l2_clip32 {
struct v4l2_rectc;
-   compat_caddr_t  next;
+   compat_caddr_t  next;
 };
 
 struct v4l2_window32 {
struct v4l2_rectw;

[PATCH for v3.2 08/12] media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit 025a26fa14f8fd55d50ab284a30c016a5be953d0 upstream.

Commit b2787845fb91 ("V4L/DVB (5289): Add support for video output
overlays.") added the field global_alpha to struct v4l2_window but did
not update the compat layer accordingly. This change adds global_alpha
to struct v4l2_window32 and copies the value for global_alpha back and
forth.

Signed-off-by: Daniel Mentz 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 925271c25177..a7b71a256d56 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -46,6 +46,7 @@ struct v4l2_window32 {
compat_caddr_t  clips; /* actually struct v4l2_clip32 * */
__u32   clipcount;
compat_caddr_t  bitmap;
+   __u8global_alpha;
 };
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
@@ -54,7 +55,8 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
+   get_user(kp->clipcount, >clipcount) ||
+   get_user(kp->global_alpha, >global_alpha))
return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
@@ -87,7 +89,8 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
put_user(kp->field, >field) ||
put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
+   put_user(kp->clipcount, >clipcount) ||
+   put_user(kp->global_alpha, >global_alpha))
return -EFAULT;
return 0;
 }
-- 
2.15.1



[PATCH for v3.2 11/12] media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit d83a8243aaefe62ace433e4384a4f077bed86acb upstream.

Some ioctls need to copy back the result even if the ioctl returned
an error. However, don't do this for the error code -ENOTTY.
It makes no sense in that cases.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 44e8a8d15558..7f0eeb8a4d3f 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -872,6 +872,9 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
set_fs(old_fs);
}
 
+   if (err == -ENOTTY)
+   return err;
+
/* Special case: even after an error we need to put the
   results back for these ioctls since the error_idx will
   contain information on which control failed. */
-- 
2.15.1



[PATCH for v3.2 10/12] media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 169f24ca68bf0f247d111aef07af00dd3a02ae88 upstream.

There is nothing wrong with using an unknown buffer type. So
stop spamming the kernel log whenever this happens. The kernel
will just return -EINVAL to signal this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 6c3e15f7703e..44e8a8d15558 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -175,8 +175,6 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return -EFAULT;
return 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
@@ -223,8 +221,6 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return -EFAULT;
return 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
-- 
2.15.1



[PATCH for v3.2 07/12] media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit b8c601e8af2d08f733d74defa8465303391bb930 upstream.

ctrl_is_pointer just hardcoded two known string controls, but that
caused problems when using e.g. custom controls that use a pointer
for the payload.

Reimplement this function: it now finds the v4l2_ctrl (if the driver
uses the control framework) or it calls vidioc_query_ext_ctrl (if the
driver implements that directly).

In both cases it can now check if the control is a pointer control
or not.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 51 +++
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index 7477feff92b1..925271c25177 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -17,6 +17,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #ifdef CONFIG_COMPAT
 
@@ -568,24 +571,32 @@ struct v4l2_ext_control32 {
};
 } __attribute__ ((packed));
 
-/* The following function really belong in v4l2-common, but that causes
-   a circular dependency between modules. We need to think about this, but
-   for now this will do. */
-
-/* Return non-zero if this control is a pointer type. Currently only
-   type STRING is a pointer type. */
-static inline int ctrl_is_pointer(u32 id)
+/* Return true if this control is a pointer type. */
+static inline bool ctrl_is_pointer(struct file *file, u32 id)
 {
-   switch (id) {
-   case V4L2_CID_RDS_TX_PS_NAME:
-   case V4L2_CID_RDS_TX_RADIO_TEXT:
-   return 1;
-   default:
-   return 0;
+   struct video_device *vdev = video_devdata(file);
+   struct v4l2_fh *fh = NULL;
+   struct v4l2_ctrl_handler *hdl = NULL;
+
+   if (test_bit(V4L2_FL_USES_V4L2_FH, >flags))
+   fh = file->private_data;
+
+   if (fh && fh->ctrl_handler)
+   hdl = fh->ctrl_handler;
+   else if (vdev->ctrl_handler)
+   hdl = vdev->ctrl_handler;
+
+   if (hdl) {
+   struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, id);
+
+   return ctrl && ctrl->type == V4L2_CTRL_TYPE_STRING;
}
+   return false;
 }
 
-static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct 
v4l2_ext_controls32 __user *up)
+static int get_v4l2_ext_controls32(struct file *file,
+  struct v4l2_ext_controls *kp,
+  struct v4l2_ext_controls32 __user *up)
 {
struct v4l2_ext_control32 __user *ucontrols;
struct v4l2_ext_control __user *kcontrols;
@@ -613,7 +624,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
while (--n >= 0) {
if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
return -EFAULT;
-   if (ctrl_is_pointer(kcontrols->id)) {
+   if (ctrl_is_pointer(file, kcontrols->id)) {
void __user *s;
 
if (get_user(p, >string))
@@ -628,7 +639,9 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
return 0;
 }
 
-static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct 
v4l2_ext_controls32 __user *up)
+static int put_v4l2_ext_controls32(struct file *file,
+  struct v4l2_ext_controls *kp,
+  struct v4l2_ext_controls32 __user *up)
 {
struct v4l2_ext_control32 __user *ucontrols;
struct v4l2_ext_control __user *kcontrols = kp->controls;
@@ -656,7 +669,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
/* Do not modify the pointer when copying a pointer control.
   The contents of the pointer was changed, not the pointer
   itself. */
-   if (ctrl_is_pointer(kcontrols->id))
+   if (ctrl_is_pointer(file, kcontrols->id))
size -= sizeof(ucontrols->value64);
if (copy_in_user(ucontrols, kcontrols, size))
return -EFAULT;
@@ -819,7 +832,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
case VIDIOC_G_EXT_CTRLS:
case VIDIOC_S_EXT_CTRLS:
case VIDIOC_TRY_EXT_CTRLS:
-   err = get_v4l2_ext_controls32(, up);
+   err = get_v4l2_ext_controls32(file, , up);
compatible_arg = 0;
break;
case VIDIOC_DQEVENT:
@@ -846,7 +859,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
case VIDIOC_G_EXT_CTRLS:
case VIDIOC_S_EXT_CTRLS:

[PATCH for v3.2 09/12] media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit a751be5b142ef6bcbbb96d9899516f4d9c8d0ef4 upstream.

put_v4l2_window32() didn't copy back the clip list to userspace.
Drivers can update the clip rectangles, so this should be done.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/video/v4l2-compat-ioctl32.c | 59 +--
 1 file changed, 40 insertions(+), 19 deletions(-)

diff --git a/drivers/media/video/v4l2-compat-ioctl32.c 
b/drivers/media/video/v4l2-compat-ioctl32.c
index a7b71a256d56..6c3e15f7703e 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -51,6 +51,11 @@ struct v4l2_window32 {
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
+   struct v4l2_clip32 __user *uclips;
+   struct v4l2_clip __user *kclips;
+   compat_caddr_t p;
+   u32 n;
+
if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
@@ -60,38 +65,54 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
-   if (kp->clipcount) {
-   struct v4l2_clip32 __user *uclips;
-   struct v4l2_clip __user *kclips;
-   int n = kp->clipcount;
-   compat_caddr_t p;
+   if (!kp->clipcount) {
+   kp->clips = NULL;
+   return 0;
+   }
 
-   if (get_user(p, >clips))
+   n = kp->clipcount;
+   if (get_user(p, >clips))
+   return -EFAULT;
+   uclips = compat_ptr(p);
+   kclips = compat_alloc_user_space(n * sizeof(*kclips));
+   kp->clips = kclips;
+   while (n--) {
+   if (copy_in_user(>c, >c, sizeof(uclips->c)))
return -EFAULT;
-   uclips = compat_ptr(p);
-   kclips = compat_alloc_user_space(n * sizeof(*kclips));
-   kp->clips = kclips;
-   while (--n >= 0) {
-   if (copy_in_user(>c, >c, 
sizeof(uclips->c)))
-   return -EFAULT;
-   if (put_user(n ? kclips + 1 : NULL, >next))
-   return -EFAULT;
-   uclips += 1;
-   kclips += 1;
-   }
-   } else
-   kp->clips = NULL;
+   if (put_user(n ? kclips + 1 : NULL, >next))
+   return -EFAULT;
+   uclips++;
+   kclips++;
+   }
return 0;
 }
 
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
+   struct v4l2_clip __user *kclips = kp->clips;
+   struct v4l2_clip32 __user *uclips;
+   u32 n = kp->clipcount;
+   compat_caddr_t p;
+
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
put_user(kp->field, >field) ||
put_user(kp->chromakey, >chromakey) ||
put_user(kp->clipcount, >clipcount) ||
put_user(kp->global_alpha, >global_alpha))
return -EFAULT;
+
+   if (!kp->clipcount)
+   return 0;
+
+   if (get_user(p, >clips))
+   return -EFAULT;
+   uclips = compat_ptr(p);
+   while (n--) {
+   if (copy_in_user(>c, >c, sizeof(uclips->c)))
+   return -EFAULT;
+   uclips++;
+   kclips++;
+   }
return 0;
 }
 
-- 
2.15.1



[PATCH for v3.2 00/12] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

This patch series fixes a number of bugs and culminates in the removal
of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.

This was tested with a VM running 3.2, the vivi driver (a poor substitute for
the much improved vivid driver that's available in later kernels, but it's the
best I had) since that emulates the more common V4L2 ioctls that need to pass
through v4l2-compat-ioctl32.c) and the 32-bit v4l2-compliance + 32-bit v4l2-ctl
utilities that together exercised the most common ioctls.

Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
v4l2-compliance complained about. The purpose is to 1) make it easy to
verify that the final patch didn't introduce errors by first eliminating
errors caused by other known bugs, and 2) keep the final patch at least
somewhat readable.

Regards,

Hans

Daniel Mentz (2):
  media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha
  media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

Hans Verkuil (10):
  media: v4l2-ioctl.c: don't copy back the result for -ENOTTY
  media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF
  media: v4l2-compat-ioctl32.c: fix the indentation
  media: v4l2-compat-ioctl32.c: move 'helper' functions to
__get/put_v4l2_format32
  media: v4l2-compat-ioctl32.c: avoid sizeof(type)
  media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32
  media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
  media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
  media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
  media: v4l2-compat-ioctl32.c: don't copy back the result for certain
errors

 drivers/media/video/Makefile  |   7 +-
 drivers/media/video/v4l2-compat-ioctl32.c | 966 ++
 drivers/media/video/v4l2-ioctl.c  |   6 +-
 3 files changed, 597 insertions(+), 382 deletions(-)

-- 
2.15.1



[PATCH for v3.16 02/14] media: v4l2-ioctl.c: don't copy back the result for -ENOTTY

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 181a4a2d5a0a7b43cab08a70710d727e7764ccdd upstream.

If the ioctl returned -ENOTTY, then don't bother copying
back the result as there is no point.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 16bffd851bf9..e2f71def945a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2402,8 +2402,11 @@ video_usercopy(struct file *file, unsigned int cmd, 
unsigned long arg,
 
/* Handles IOCTL */
err = func(file, cmd, parg);
-   if (err == -ENOIOCTLCMD)
+   if (err == -ENOTTY || err == -ENOIOCTLCMD) {
err = -ENOTTY;
+   goto out;
+   }
+
if (err == 0) {
if (cmd == VIDIOC_DQBUF)
trace_v4l2_dqbuf(video_devdata(file)->minor, parg);
-- 
2.15.1



[PATCH for v3.16 04/14] media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 3ee6d040719ae09110e5cdf24d5386abe5d1b776 upstream.

The result of the VIDIOC_PREPARE_BUF ioctl was never copied back
to userspace since it was missing in the switch.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 0f747ba40b52..ebedf95a31ed 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -980,6 +980,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
err = put_v4l2_create32(, up);
break;
 
+   case VIDIOC_PREPARE_BUF:
case VIDIOC_QUERYBUF:
case VIDIOC_QBUF:
case VIDIOC_DQBUF:
-- 
2.15.1



[PATCH for v3.16 08/14] media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 8ed5a59dcb47a6f76034ee760b36e089f3e82529 upstream.

The struct v4l2_plane32 should set m.userptr as well. The same
happens in v4l2_buffer32 and v4l2-compliance tests for this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 47 ---
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index c9d9f23e660a..3a72a735a940 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -287,19 +287,24 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 sizeof(up->data_offset)))
return -EFAULT;
 
-   if (memory == V4L2_MEMORY_USERPTR) {
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
+   if (copy_in_user(>m.mem_offset, >m.mem_offset,
+sizeof(up32->m.mem_offset)))
+   return -EFAULT;
+   break;
+   case V4L2_MEMORY_USERPTR:
if (get_user(p, >m.userptr))
return -EFAULT;
up_pln = compat_ptr(p);
if (put_user((unsigned long)up_pln, >m.userptr))
return -EFAULT;
-   } else if (memory == V4L2_MEMORY_DMABUF) {
+   break;
+   case V4L2_MEMORY_DMABUF:
if (copy_in_user(>m.fd, >m.fd, sizeof(up32->m.fd)))
return -EFAULT;
-   } else {
-   if (copy_in_user(>m.mem_offset, >m.mem_offset,
-sizeof(up32->m.mem_offset)))
-   return -EFAULT;
+   break;
}
 
return 0;
@@ -308,22 +313,32 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
enum v4l2_memory memory)
 {
+   unsigned long p;
+
if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
copy_in_user(>data_offset, >data_offset,
 sizeof(up->data_offset)))
return -EFAULT;
 
-   /* For MMAP, driver might've set up the offset, so copy it back.
-* USERPTR stays the same (was userspace-provided), so no copying. */
-   if (memory == V4L2_MEMORY_MMAP)
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (copy_in_user(>m.mem_offset, >m.mem_offset,
 sizeof(up->m.mem_offset)))
return -EFAULT;
-   /* For DMABUF, driver might've set up the fd, so copy it back. */
-   if (memory == V4L2_MEMORY_DMABUF)
+   break;
+   case V4L2_MEMORY_USERPTR:
+   if (get_user(p, >m.userptr) ||
+   put_user((compat_ulong_t)ptr_to_compat((__force void *)p),
+>m.userptr))
+   return -EFAULT;
+   break;
+   case V4L2_MEMORY_DMABUF:
if (copy_in_user(>m.fd, >m.fd,
 sizeof(up->m.fd)))
return -EFAULT;
+   break;
+   }
 
return 0;
 }
@@ -384,6 +399,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct 
v4l2_buffer32 __user
} else {
switch (kp->memory) {
case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (get_user(kp->m.offset, >m.offset))
return -EFAULT;
break;
@@ -397,10 +413,6 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, 
struct v4l2_buffer32 __user
kp->m.userptr = (unsigned long)compat_ptr(tmp);
}
break;
-   case V4L2_MEMORY_OVERLAY:
-   if (get_user(kp->m.offset, >m.offset))
-   return -EFAULT;
-   break;
case V4L2_MEMORY_DMABUF:
if (get_user(kp->m.fd, >m.fd))
return -EFAULT;
@@ -457,6 +469,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct 
v4l2_buffer32 __user
} else {
switch (kp->memory) {
case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (put_user(kp->m.offset, >m.offset))
return -EFAULT;
break;
@@ -464,10 +477,6 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, 
struct v4l2_buffer32 __user
 

[PATCH for v3.16 05/14] media: v4l2-compat-ioctl32.c: fix the indentation

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit b7b957d429f601d6d1942122b339474f31191d75 upstream.

The indentation of this source is all over the place. Fix this.
This patch only changes whitespace.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 216 +-
 1 file changed, 108 insertions(+), 108 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index ebedf95a31ed..a3e62cf3acaa 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -48,11 +48,11 @@ struct v4l2_window32 {
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
-   copy_from_user(>w, >w, sizeof(up->w)) ||
-   get_user(kp->field, >field) ||
-   get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   copy_from_user(>w, >w, sizeof(up->w)) ||
+   get_user(kp->field, >field) ||
+   get_user(kp->chromakey, >chromakey) ||
+   get_user(kp->clipcount, >clipcount))
+   return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
if (kp->clipcount) {
@@ -82,10 +82,10 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
-   put_user(kp->field, >field) ||
-   put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   put_user(kp->field, >field) ||
+   put_user(kp->chromakey, >chromakey) ||
+   put_user(kp->clipcount, >clipcount))
+   return -EFAULT;
return 0;
 }
 
@@ -97,7 +97,7 @@ static inline int get_v4l2_pix_format(struct v4l2_pix_format 
*kp, struct v4l2_pi
 }
 
 static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -112,7 +112,7 @@ static inline int put_v4l2_pix_format(struct 
v4l2_pix_format *kp, struct v4l2_pi
 }
 
 static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -200,7 +200,7 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return get_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -241,7 +241,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return put_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -249,7 +249,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
-   put_user(kp->type, >type))
+   put_user(kp->type, >type))
return -EFAULT;
return __put_v4l2_format32(kp, up);
 }
@@ -258,7 +258,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers 
*kp, struct v4l2_create_
 {
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) 
||
copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, 
format.fmt)))
-   return -EFAULT;
+   return -EFAULT;
return __put_v4l2_format32(>format, >format);
 }
 
@@ -275,7 +275,7 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 {
/* other fields are not set by the user, nor used by the driver */
if 

[PATCH for v3.16 00/14] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

This patch series fixes a number of bugs and culminates in the removal
of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.

This was tested with a VM running 3.16, the vivi driver (a poor substitute for
the much improved vivid driver that's available in later kernels, but it's the
best I had) since that emulates the more common V4L2 ioctls that need to pass
through v4l2-compat-ioctl32.c) and the 32-bit v4l2-compliance + 32-bit v4l2-ctl
utilities that together exercised the most common ioctls.

Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
v4l2-compliance complained about. The purpose is to 1) make it easy to
verify that the final patch didn't introduce errors by first eliminating
errors caused by other known bugs, and 2) keep the final patch at least
somewhat readable.

While compiling the media drivers for 3.16 I also came across a bug
introduced in the 3.16 stable series that caused a compile error in the
adv7604 driver. That's fixed in the first patch. Call it a bonus patch :-)

Regards,

Hans

Daniel Mentz (2):
  media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha
  media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

Hans Verkuil (11):
  adv7604: use correct drive strength defines
  media: v4l2-ioctl.c: don't copy back the result for -ENOTTY
  media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF
  media: v4l2-compat-ioctl32.c: fix the indentation
  media: v4l2-compat-ioctl32.c: move 'helper' functions to
__get/put_v4l2_format32
  media: v4l2-compat-ioctl32.c: avoid sizeof(type)
  media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32
  media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
  media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
  media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
  media: v4l2-compat-ioctl32.c: don't copy back the result for certain
errors

Ricardo Ribalda (1):
  vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

 drivers/media/i2c/adv7604.c   |6 +-
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1030 +++--
 drivers/media/v4l2-core/v4l2-ioctl.c  |5 +-
 drivers/media/v4l2-core/videobuf2-core.c  |5 +
 4 files changed, 642 insertions(+), 404 deletions(-)

-- 
2.15.1



[PATCH for v3.16 06/14] media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 486c521510c44a04cd756a9267e7d1e271c8a4ba upstream.

These helper functions do not really help. Move the code to the
__get/put_v4l2_format32 functions.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 92 ++-
 1 file changed, 20 insertions(+), 72 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index a3e62cf3acaa..f76ed4ee7df9 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -89,64 +89,6 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
return 0;
 }
 
-static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
 struct v4l2_format32 {
__u32   type;   /* enum v4l2_buf_type */
union {
@@ -184,20 +126,23 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return get_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return copy_from_user(>fmt.pix, >fmt.pix,
+ sizeof(kp->fmt.pix)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-   return get_v4l2_pix_format_mplane(>fmt.pix_mp,
- >fmt.pix_mp);
+   return copy_from_user(>fmt.pix_mp, >fmt.pix_mp,
+ sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
return get_v4l2_window32(>fmt.win, >fmt.win);
case V4L2_BUF_TYPE_VBI_CAPTURE:
case V4L2_BUF_TYPE_VBI_OUTPUT:
-   return get_v4l2_vbi_format(>fmt.vbi, >fmt.vbi);
+   return copy_from_user(>fmt.vbi, >fmt.vbi,
+ sizeof(kp->fmt.vbi)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-   return get_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
+   return copy_from_user(>fmt.sliced, >fmt.sliced,
+ sizeof(kp->fmt.sliced)) ? -EFAULT : 0;
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
   kp->type);
@@ -225,20 +170,23 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return put_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return copy_to_user(>fmt.pix, >fmt.pix,
+ 

[PATCH for v3.16 10/14] media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit 025a26fa14f8fd55d50ab284a30c016a5be953d0 upstream.

Commit b2787845fb91 ("V4L/DVB (5289): Add support for video output
overlays.") added the field global_alpha to struct v4l2_window but did
not update the compat layer accordingly. This change adds global_alpha
to struct v4l2_window32 and copies the value for global_alpha back and
forth.

Signed-off-by: Daniel Mentz 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 69d772d1237d..de69afde9e86 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -45,6 +45,7 @@ struct v4l2_window32 {
compat_caddr_t  clips; /* actually struct v4l2_clip32 * */
__u32   clipcount;
compat_caddr_t  bitmap;
+   __u8global_alpha;
 };
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
@@ -53,7 +54,8 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
+   get_user(kp->clipcount, >clipcount) ||
+   get_user(kp->global_alpha, >global_alpha))
return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
@@ -86,7 +88,8 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
put_user(kp->field, >field) ||
put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
+   put_user(kp->clipcount, >clipcount) ||
+   put_user(kp->global_alpha, >global_alpha))
return -EFAULT;
return 0;
 }
-- 
2.15.1



[PATCH for v3.16 07/14] media: v4l2-compat-ioctl32.c: avoid sizeof(type)

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 333b1e9f96ce05f7498b581509bb30cde03018bf upstream.

Instead of doing sizeof(struct foo) use sizeof(*up). There even were
cases where 4 * sizeof(__u32) was used instead of sizeof(kp->reserved),
which is very dangerous when the size of the reserved array changes.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 73 +--
 1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index f76ed4ee7df9..c9d9f23e660a 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -47,7 +47,7 @@ struct v4l2_window32 {
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
get_user(kp->chromakey, >chromakey) ||
@@ -64,7 +64,7 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
if (get_user(p, >clips))
return -EFAULT;
uclips = compat_ptr(p);
-   kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
+   kclips = compat_alloc_user_space(n * sizeof(*kclips));
kp->clips = kclips;
while (--n >= 0) {
if (copy_in_user(>c, >c, 
sizeof(uclips->c)))
@@ -152,14 +152,14 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 
 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)))
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)))
return -EFAULT;
return __get_v4l2_format32(kp, up);
 }
 
 static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct 
v4l2_create_buffers32 __user *up)
 {
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, 
format)))
return -EFAULT;
return __get_v4l2_format32(>format, >format);
@@ -196,7 +196,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
 
 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 
__user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
put_user(kp->type, >type))
return -EFAULT;
return __put_v4l2_format32(kp, up);
@@ -204,7 +204,7 @@ static int put_v4l2_format32(struct v4l2_format *kp, struct 
v4l2_format32 __user
 
 static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct 
v4l2_create_buffers32 __user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) 
||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, 
format.fmt)))
return -EFAULT;
return __put_v4l2_format32(>format, >format);
@@ -222,7 +222,7 @@ struct v4l2_standard32 {
 static int get_v4l2_standard32(struct v4l2_standard *kp, struct 
v4l2_standard32 __user *up)
 {
/* other fields are not set by the user, nor used by the driver */
-   if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
+   if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
get_user(kp->index, >index))
return -EFAULT;
return 0;
@@ -230,13 +230,13 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 
 static int put_v4l2_standard32(struct v4l2_standard *kp, struct 
v4l2_standard32 __user *up)
 {
-   if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
+   if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
put_user(kp->index, >index) ||
put_user(kp->id, >id) ||
-   copy_to_user(up->name, kp->name, 24) ||
+   copy_to_user(up->name, kp->name, sizeof(up->name)) ||
copy_to_user(>frameperiod, >frameperiod, 
sizeof(kp->frameperiod)) ||
put_user(kp->framelines, >framelines) ||
-   copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
+   copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
return -EFAULT;
return 0;
 }
@@ -284,7 +284,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct 
v4l2_plane32 *up32,
 

[PATCH for v3.16 03/14] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2018-02-14 Thread Hans Verkuil
From: Ricardo Ribalda 

commit 3171cc2b4eb9831ab4df1d80d0410a945b8bc84e upstream.

According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x2004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch forces FLAG_DONE to 0 after calling DQBUF.

Reported-by: Dimitrios Katsaros 
Signed-off-by: Ricardo Ribalda Delgado 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index e63a7904bf5b..ee8b697972bb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2069,6 +2069,11 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, 
struct v4l2_buffer *b, bool n
dprintk(1, "dqbuf of buffer %d, with state %d\n",
vb->v4l2_buf.index, vb->state);
 
+   /*
+* After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+* cleared.
+*/
+   b->flags &= ~V4L2_BUF_FLAG_DONE;
return 0;
 }
 
-- 
2.15.1



[PATCH for v3.16 13/14] media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit d83a8243aaefe62ace433e4384a4f077bed86acb upstream.

Some ioctls need to copy back the result even if the ioctl returned
an error. However, don't do this for the error code -ENOTTY.
It makes no sense in that cases.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 2a03bd72cefc..64d1a2bddd5e 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -921,6 +921,9 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
set_fs(old_fs);
}
 
+   if (err == -ENOTTY)
+   return err;
+
/* Special case: even after an error we need to put the
   results back for these ioctls since the error_idx will
   contain information on which control failed. */
-- 
2.15.1



[PATCH for v3.16 12/14] media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 169f24ca68bf0f247d111aef07af00dd3a02ae88 upstream.

There is nothing wrong with using an unknown buffer type. So
stop spamming the kernel log whenever this happens. The kernel
will just return -EINVAL to signal this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index e7ebd20b6c6a..2a03bd72cefc 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -170,8 +170,6 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return copy_from_user(>fmt.sliced, >fmt.sliced,
  sizeof(kp->fmt.sliced)) ? -EFAULT : 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
@@ -214,8 +212,6 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return copy_to_user(>fmt.sliced, >fmt.sliced,
sizeof(kp->fmt.sliced)) ?  -EFAULT : 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
-- 
2.15.1



[PATCH for v3.16 11/14] media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit a751be5b142ef6bcbbb96d9899516f4d9c8d0ef4 upstream.

put_v4l2_window32() didn't copy back the clip list to userspace.
Drivers can update the clip rectangles, so this should be done.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 59 ++-
 1 file changed, 40 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index de69afde9e86..e7ebd20b6c6a 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -50,6 +50,11 @@ struct v4l2_window32 {
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
+   struct v4l2_clip32 __user *uclips;
+   struct v4l2_clip __user *kclips;
+   compat_caddr_t p;
+   u32 n;
+
if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
@@ -59,38 +64,54 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
-   if (kp->clipcount) {
-   struct v4l2_clip32 __user *uclips;
-   struct v4l2_clip __user *kclips;
-   int n = kp->clipcount;
-   compat_caddr_t p;
+   if (!kp->clipcount) {
+   kp->clips = NULL;
+   return 0;
+   }
 
-   if (get_user(p, >clips))
+   n = kp->clipcount;
+   if (get_user(p, >clips))
+   return -EFAULT;
+   uclips = compat_ptr(p);
+   kclips = compat_alloc_user_space(n * sizeof(*kclips));
+   kp->clips = kclips;
+   while (n--) {
+   if (copy_in_user(>c, >c, sizeof(uclips->c)))
return -EFAULT;
-   uclips = compat_ptr(p);
-   kclips = compat_alloc_user_space(n * sizeof(*kclips));
-   kp->clips = kclips;
-   while (--n >= 0) {
-   if (copy_in_user(>c, >c, 
sizeof(uclips->c)))
-   return -EFAULT;
-   if (put_user(n ? kclips + 1 : NULL, >next))
-   return -EFAULT;
-   uclips += 1;
-   kclips += 1;
-   }
-   } else
-   kp->clips = NULL;
+   if (put_user(n ? kclips + 1 : NULL, >next))
+   return -EFAULT;
+   uclips++;
+   kclips++;
+   }
return 0;
 }
 
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
+   struct v4l2_clip __user *kclips = kp->clips;
+   struct v4l2_clip32 __user *uclips;
+   u32 n = kp->clipcount;
+   compat_caddr_t p;
+
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
put_user(kp->field, >field) ||
put_user(kp->chromakey, >chromakey) ||
put_user(kp->clipcount, >clipcount) ||
put_user(kp->global_alpha, >global_alpha))
return -EFAULT;
+
+   if (!kp->clipcount)
+   return 0;
+
+   if (get_user(p, >clips))
+   return -EFAULT;
+   uclips = compat_ptr(p);
+   while (n--) {
+   if (copy_in_user(>c, >c, sizeof(uclips->c)))
+   return -EFAULT;
+   uclips++;
+   kclips++;
+   }
return 0;
 }
 
-- 
2.15.1



[PATCH for v3.16 14/14] media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit a1dfb4c48cc1e64eeb7800a27c66a6f7e88d075a upstream.

The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit
equivalent. It converts 32-bit data structures into its 64-bit
equivalents and needs to provide the data to the 64-bit ioctl in user
space memory which is commonly allocated using
compat_alloc_user_space().

However, due to how that function is implemented, it can only be called
a single time for every syscall invocation.

Supposedly to avoid this limitation, the existing code uses a mix of
memory from the kernel stack and memory allocated through
compat_alloc_user_space().

Under normal circumstances, this would not work, because the 64-bit
ioctl expects all pointers to point to user space memory. As a
workaround, set_fs(KERNEL_DS) is called to temporarily disable this
extra safety check and allow kernel pointers. However, this might
introduce a security vulnerability: The result of the 32-bit to 64-bit
conversion is writeable by user space because the output buffer has been
allocated via compat_alloc_user_space(). A malicious user space process
could then manipulate pointers inside this output buffer, and due to the
previous set_fs(KERNEL_DS) call, functions like get_user() or put_user()
no longer prevent kernel memory access.

The new approach is to pre-calculate the total amount of user space
memory that is needed, allocate it using compat_alloc_user_space() and
then divide up the allocated memory to accommodate all data structures
that need to be converted.

An alternative approach would have been to retain the union type karg
that they allocated on the kernel stack in do_video_ioctl(), copy all
data from user space into karg and then back to user space. However, we
decided against this approach because it does not align with other
compat syscall implementations. Instead, we tried to replicate the
get_user/put_user pairs as found in other places in the kernel:

if (get_user(clipcount, >clipcount) ||
put_user(clipcount, >clipcount)) return -EFAULT;

Notes from hans.verk...@cisco.com:

This patch was taken from:

https://github.com/LineageOS/android_kernel_samsung_apq8084/commit/97b733953c06e4f0398ade18850f0817778255f7

Clearly nobody could be bothered to upstream this patch or at minimum
tell us :-( We only heard about this a week ago.

This patch was rebased and cleaned up. Compared to the original I
also swapped the order of the convert_in_user arguments so that they
matched copy_in_user. It was hard to review otherwise. I also replaced
the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.

Fixes: 6b5a9492ca ("v4l: introduce string control support.")

Signed-off-by: Daniel Mentz 
Co-developed-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 780 +-
 1 file changed, 510 insertions(+), 270 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 64d1a2bddd5e..d35b67b37077 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -22,6 +22,14 @@
 #include 
 #include 
 
+/* Use the same argument order as copy_in_user */
+#define assign_in_user(to, from)   \
+({ \
+   typeof(*from) __assign_tmp; \
+   \
+   get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \
+})
+
 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long 
arg)
 {
long ret = -ENOIOCTLCMD;
@@ -35,12 +43,12 @@ static long native_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
 
 struct v4l2_clip32 {
struct v4l2_rectc;
-   compat_caddr_t  next;
+   compat_caddr_t  next;
 };
 
 struct v4l2_window32 {
struct v4l2_rectw;
-   __u32   field;  /* enum v4l2_field */
+   __u32   field;  /* enum v4l2_field */
__u32   chromakey;
compat_caddr_t  clips; /* actually struct v4l2_clip32 * */
__u32   clipcount;
@@ -48,37 +56,41 @@ struct v4l2_window32 {
__u8global_alpha;
 };
 
-static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
+static int get_v4l2_window32(struct v4l2_window __user *kp,
+struct v4l2_window32 __user *up,
+void __user *aux_buf, u32 aux_space)
 {
struct v4l2_clip32 __user *uclips;
struct v4l2_clip __user 

[PATCH for v3.16 09/14] media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit b8c601e8af2d08f733d74defa8465303391bb930 upstream.

ctrl_is_pointer just hardcoded two known string controls, but that
caused problems when using e.g. custom controls that use a pointer
for the payload.

Reimplement this function: it now finds the v4l2_ctrl (if the driver
uses the control framework) or it calls vidioc_query_ext_ctrl (if the
driver implements that directly).

In both cases it can now check if the control is a pointer control
or not.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 50 +--
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 3a72a735a940..69d772d1237d 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -18,6 +18,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long 
arg)
@@ -567,24 +569,32 @@ struct v4l2_ext_control32 {
};
 } __attribute__ ((packed));
 
-/* The following function really belong in v4l2-common, but that causes
-   a circular dependency between modules. We need to think about this, but
-   for now this will do. */
-
-/* Return non-zero if this control is a pointer type. Currently only
-   type STRING is a pointer type. */
-static inline int ctrl_is_pointer(u32 id)
+/* Return true if this control is a pointer type. */
+static inline bool ctrl_is_pointer(struct file *file, u32 id)
 {
-   switch (id) {
-   case V4L2_CID_RDS_TX_PS_NAME:
-   case V4L2_CID_RDS_TX_RADIO_TEXT:
-   return 1;
-   default:
-   return 0;
+   struct video_device *vdev = video_devdata(file);
+   struct v4l2_fh *fh = NULL;
+   struct v4l2_ctrl_handler *hdl = NULL;
+
+   if (test_bit(V4L2_FL_USES_V4L2_FH, >flags))
+   fh = file->private_data;
+
+   if (fh && fh->ctrl_handler)
+   hdl = fh->ctrl_handler;
+   else if (vdev->ctrl_handler)
+   hdl = vdev->ctrl_handler;
+
+   if (hdl) {
+   struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, id);
+
+   return ctrl && ctrl->type == V4L2_CTRL_TYPE_STRING;
}
+   return false;
 }
 
-static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct 
v4l2_ext_controls32 __user *up)
+static int get_v4l2_ext_controls32(struct file *file,
+  struct v4l2_ext_controls *kp,
+  struct v4l2_ext_controls32 __user *up)
 {
struct v4l2_ext_control32 __user *ucontrols;
struct v4l2_ext_control __user *kcontrols;
@@ -612,7 +622,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
while (--n >= 0) {
if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
return -EFAULT;
-   if (ctrl_is_pointer(kcontrols->id)) {
+   if (ctrl_is_pointer(file, kcontrols->id)) {
void __user *s;
 
if (get_user(p, >string))
@@ -627,7 +637,9 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
return 0;
 }
 
-static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct 
v4l2_ext_controls32 __user *up)
+static int put_v4l2_ext_controls32(struct file *file,
+  struct v4l2_ext_controls *kp,
+  struct v4l2_ext_controls32 __user *up)
 {
struct v4l2_ext_control32 __user *ucontrols;
struct v4l2_ext_control __user *kcontrols = kp->controls;
@@ -655,7 +667,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls 
*kp, struct v4l2_ext
/* Do not modify the pointer when copying a pointer control.
   The contents of the pointer was changed, not the pointer
   itself. */
-   if (ctrl_is_pointer(kcontrols->id))
+   if (ctrl_is_pointer(file, kcontrols->id))
size -= sizeof(ucontrols->value64);
if (copy_in_user(ucontrols, kcontrols, size))
return -EFAULT;
@@ -869,7 +881,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
case VIDIOC_G_EXT_CTRLS:
case VIDIOC_S_EXT_CTRLS:
case VIDIOC_TRY_EXT_CTRLS:
-   err = get_v4l2_ext_controls32(, up);
+   err = get_v4l2_ext_controls32(file, , up);
compatible_arg = 0;
break;
case VIDIOC_DQEVENT:
@@ -896,7 +908,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
 

[PATCH for v3.16 01/14] adv7604: use correct drive strength defines

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

The prefix is ADV7604_, not ADV76XX.

Fixes: f31b62e14a ("adv7604: add hdmi driver strength adjustment")

Signed-off-by: Hans Verkuil 
---
 drivers/media/i2c/adv7604.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index af8a99716de5..9e0e592f50ab 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -2735,9 +2735,9 @@ static int adv7604_parse_dt(struct adv7604_state *state)
state->pdata.alt_data_sat = 1;
state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0;
state->pdata.bus_order = ADV7604_BUS_ORDER_RGB;
-   state->pdata.dr_str_data = ADV76XX_DR_STR_MEDIUM_HIGH;
-   state->pdata.dr_str_clk = ADV76XX_DR_STR_MEDIUM_HIGH;
-   state->pdata.dr_str_sync = ADV76XX_DR_STR_MEDIUM_HIGH;
+   state->pdata.dr_str_data = ADV7604_DR_STR_MEDIUM_HIGH;
+   state->pdata.dr_str_clk = ADV7604_DR_STR_MEDIUM_HIGH;
+   state->pdata.dr_str_sync = ADV7604_DR_STR_MEDIUM_HIGH;
 
return 0;
 }
-- 
2.15.1



[PATCH for v4.1 02/14] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2018-02-14 Thread Hans Verkuil
From: Ricardo Ribalda 

commit 3171cc2b4eb9831ab4df1d80d0410a945b8bc84e upstream.

According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x2004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch forces FLAG_DONE to 0 after calling DQBUF.

Reported-by: Dimitrios Katsaros 
Signed-off-by: Ricardo Ribalda Delgado 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index fd9b252e2b34..079ee4ae9436 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2119,6 +2119,11 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, 
struct v4l2_buffer *b, bool n
dprintk(1, "dqbuf of buffer %d, with state %d\n",
vb->v4l2_buf.index, vb->state);
 
+   /*
+* After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+* cleared.
+*/
+   b->flags &= ~V4L2_BUF_FLAG_DONE;
return 0;
 }
 
-- 
2.15.1



[PATCH for v4.1 13/14] media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit d83a8243aaefe62ace433e4384a4f077bed86acb upstream.

Some ioctls need to copy back the result even if the ioctl returned
an error. However, don't do this for the error code -ENOTTY.
It makes no sense in that cases.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 8371bbbda383..3e1d3ed3561c 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -946,6 +946,9 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
set_fs(old_fs);
}
 
+   if (err == -ENOTTY)
+   return err;
+
/* Special case: even after an error we need to put the
   results back for these ioctls since the error_idx will
   contain information on which control failed. */
-- 
2.15.1



[PATCH for v4.1 05/14] media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 486c521510c44a04cd756a9267e7d1e271c8a4ba upstream.

These helper functions do not really help. Move the code to the
__get/put_v4l2_format32 functions.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 84 +--
 1 file changed, 16 insertions(+), 68 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index ba6aaea11e2f..2a116d671f92 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -89,64 +89,6 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
return 0;
 }
 
-static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct 
v4l2_pix_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-struct v4l2_pix_format_mplane 
__user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct 
v4l2_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
-static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format 
*kp, struct v4l2_sliced_vbi_format __user *up)
-{
-   if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
-   return -EFAULT;
-   return 0;
-}
-
 struct v4l2_format32 {
__u32   type;   /* enum v4l2_buf_type */
union {
@@ -184,20 +126,23 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return get_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return copy_from_user(>fmt.pix, >fmt.pix,
+ sizeof(kp->fmt.pix)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-   return get_v4l2_pix_format_mplane(>fmt.pix_mp,
- >fmt.pix_mp);
+   return copy_from_user(>fmt.pix_mp, >fmt.pix_mp,
+ sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
return get_v4l2_window32(>fmt.win, >fmt.win);
case V4L2_BUF_TYPE_VBI_CAPTURE:
case V4L2_BUF_TYPE_VBI_OUTPUT:
-   return get_v4l2_vbi_format(>fmt.vbi, >fmt.vbi);
+   return copy_from_user(>fmt.vbi, >fmt.vbi,
+ sizeof(kp->fmt.vbi)) ? -EFAULT : 0;
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-   return get_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
+   return copy_from_user(>fmt.sliced, >fmt.sliced,
+ sizeof(kp->fmt.sliced)) ? -EFAULT : 0;
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
   kp->type);
@@ -228,20 +173,23 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
switch (kp->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-   return put_v4l2_pix_format(>fmt.pix, >fmt.pix);
+   return copy_to_user(>fmt.pix, >fmt.pix,
+ 

[PATCH for v4.1 14/14] media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit a1dfb4c48cc1e64eeb7800a27c66a6f7e88d075a upstream.

The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit
equivalent. It converts 32-bit data structures into its 64-bit
equivalents and needs to provide the data to the 64-bit ioctl in user
space memory which is commonly allocated using
compat_alloc_user_space().

However, due to how that function is implemented, it can only be called
a single time for every syscall invocation.

Supposedly to avoid this limitation, the existing code uses a mix of
memory from the kernel stack and memory allocated through
compat_alloc_user_space().

Under normal circumstances, this would not work, because the 64-bit
ioctl expects all pointers to point to user space memory. As a
workaround, set_fs(KERNEL_DS) is called to temporarily disable this
extra safety check and allow kernel pointers. However, this might
introduce a security vulnerability: The result of the 32-bit to 64-bit
conversion is writeable by user space because the output buffer has been
allocated via compat_alloc_user_space(). A malicious user space process
could then manipulate pointers inside this output buffer, and due to the
previous set_fs(KERNEL_DS) call, functions like get_user() or put_user()
no longer prevent kernel memory access.

The new approach is to pre-calculate the total amount of user space
memory that is needed, allocate it using compat_alloc_user_space() and
then divide up the allocated memory to accommodate all data structures
that need to be converted.

An alternative approach would have been to retain the union type karg
that they allocated on the kernel stack in do_video_ioctl(), copy all
data from user space into karg and then back to user space. However, we
decided against this approach because it does not align with other
compat syscall implementations. Instead, we tried to replicate the
get_user/put_user pairs as found in other places in the kernel:

if (get_user(clipcount, >clipcount) ||
put_user(clipcount, >clipcount)) return -EFAULT;

Notes from hans.verk...@cisco.com:

This patch was taken from:

https://github.com/LineageOS/android_kernel_samsung_apq8084/commit/97b733953c06e4f0398ade18850f0817778255f7

Clearly nobody could be bothered to upstream this patch or at minimum
tell us :-( We only heard about this a week ago.

This patch was rebased and cleaned up. Compared to the original I
also swapped the order of the convert_in_user arguments so that they
matched copy_in_user. It was hard to review otherwise. I also replaced
the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.

Fixes: 6b5a9492ca ("v4l: introduce string control support.")

Signed-off-by: Daniel Mentz 
Co-developed-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 748 +-
 1 file changed, 485 insertions(+), 263 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 3e1d3ed3561c..e03aa0961360 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -22,6 +22,14 @@
 #include 
 #include 
 
+/* Use the same argument order as copy_in_user */
+#define assign_in_user(to, from)   \
+({ \
+   typeof(*from) __assign_tmp; \
+   \
+   get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \
+})
+
 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long 
arg)
 {
long ret = -ENOIOCTLCMD;
@@ -35,12 +43,12 @@ static long native_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
 
 struct v4l2_clip32 {
struct v4l2_rectc;
-   compat_caddr_t  next;
+   compat_caddr_t  next;
 };
 
 struct v4l2_window32 {
struct v4l2_rectw;
-   __u32   field;  /* enum v4l2_field */
+   __u32   field;  /* enum v4l2_field */
__u32   chromakey;
compat_caddr_t  clips; /* actually struct v4l2_clip32 * */
__u32   clipcount;
@@ -48,37 +56,41 @@ struct v4l2_window32 {
__u8global_alpha;
 };
 
-static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
+static int get_v4l2_window32(struct v4l2_window __user *kp,
+struct v4l2_window32 __user *up,
+void __user *aux_buf, u32 aux_space)
 {
struct v4l2_clip32 __user *uclips;
struct v4l2_clip __user 

[PATCH for v4.1 03/14] media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 3ee6d040719ae09110e5cdf24d5386abe5d1b776 upstream.

The result of the VIDIOC_PREPARE_BUF ioctl was never copied back
to userspace since it was missing in the switch.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 4f002d0bebb1..42d402948ea2 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -999,6 +999,7 @@ static long do_video_ioctl(struct file *file, unsigned int 
cmd, unsigned long ar
err = put_v4l2_create32(, up);
break;
 
+   case VIDIOC_PREPARE_BUF:
case VIDIOC_QUERYBUF:
case VIDIOC_QBUF:
case VIDIOC_DQBUF:
-- 
2.15.1



[PATCH for v4.1 01/14] media: v4l2-ioctl.c: don't copy back the result for -ENOTTY

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 181a4a2d5a0a7b43cab08a70710d727e7764ccdd upstream.

If the ioctl returned -ENOTTY, then don't bother copying
back the result as there is no point.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index aa407cb5f830..7004477e7ffc 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2552,8 +2552,11 @@ video_usercopy(struct file *file, unsigned int cmd, 
unsigned long arg,
 
/* Handles IOCTL */
err = func(file, cmd, parg);
-   if (err == -ENOIOCTLCMD)
+   if (err == -ENOTTY || err == -ENOIOCTLCMD) {
err = -ENOTTY;
+   goto out;
+   }
+
if (err == 0) {
if (cmd == VIDIOC_DQBUF)
trace_v4l2_dqbuf(video_devdata(file)->minor, parg);
-- 
2.15.1



[PATCH for v4.1 00/14] v4l2-compat-ioctl32.c: remove set_fs(KERNEL_DS)

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

This patch series fixes a number of bugs and culminates in the removal
of the set_fs(KERNEL_DS) call in v4l2-compat-ioctl32.c.

This was tested with a VM running 4.1, the vivid driver (since that
emulates almost all V4L2 ioctls that need to pass through v4l2-compat-ioctl32.c)
and a 32-bit v4l2-compliance utility since that exercises almost all ioctls
as well. Combined this gives good test coverage.

Most of the v4l2-compat-ioctl32.c do cleanups and fix subtle issues that
v4l2-compliance complained about. The purpose is to 1) make it easy to
verify that the final patch didn't introduce errors by first eliminating
errors caused by other known bugs, and 2) keep the final patch at least
somewhat readable.

Regards,

Hans

Daniel Mentz (2):
  media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha
  media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic

Hans Verkuil (11):
  media: v4l2-ioctl.c: don't copy back the result for -ENOTTY
  media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF
  media: v4l2-compat-ioctl32.c: fix the indentation
  media: v4l2-compat-ioctl32.c: move 'helper' functions to
__get/put_v4l2_format32
  media: v4l2-compat-ioctl32.c: avoid sizeof(type)
  media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32
  media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
  media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs
  media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
  media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
  media: v4l2-compat-ioctl32.c: don't copy back the result for certain
errors

Ricardo Ribalda Delgado (1):
  vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 1014 +++--
 drivers/media/v4l2-core/v4l2-ioctl.c  |5 +-
 drivers/media/v4l2-core/videobuf2-core.c  |5 +
 3 files changed, 625 insertions(+), 399 deletions(-)

-- 
2.15.1



[PATCH for v4.1 07/14] media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 8ed5a59dcb47a6f76034ee760b36e089f3e82529 upstream.

The struct v4l2_plane32 should set m.userptr as well. The same
happens in v4l2_buffer32 and v4l2-compliance tests for this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 47 ---
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 03d1d92a2a8e..25a61fc27a36 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -290,19 +290,24 @@ static int get_v4l2_plane32(struct v4l2_plane __user *up, 
struct v4l2_plane32 __
 sizeof(up->data_offset)))
return -EFAULT;
 
-   if (memory == V4L2_MEMORY_USERPTR) {
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
+   if (copy_in_user(>m.mem_offset, >m.mem_offset,
+sizeof(up32->m.mem_offset)))
+   return -EFAULT;
+   break;
+   case V4L2_MEMORY_USERPTR:
if (get_user(p, >m.userptr))
return -EFAULT;
up_pln = compat_ptr(p);
if (put_user((unsigned long)up_pln, >m.userptr))
return -EFAULT;
-   } else if (memory == V4L2_MEMORY_DMABUF) {
+   break;
+   case V4L2_MEMORY_DMABUF:
if (copy_in_user(>m.fd, >m.fd, sizeof(up32->m.fd)))
return -EFAULT;
-   } else {
-   if (copy_in_user(>m.mem_offset, >m.mem_offset,
-sizeof(up32->m.mem_offset)))
-   return -EFAULT;
+   break;
}
 
return 0;
@@ -311,22 +316,32 @@ static int get_v4l2_plane32(struct v4l2_plane __user *up, 
struct v4l2_plane32 __
 static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 
__user *up32,
enum v4l2_memory memory)
 {
+   unsigned long p;
+
if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
copy_in_user(>data_offset, >data_offset,
 sizeof(up->data_offset)))
return -EFAULT;
 
-   /* For MMAP, driver might've set up the offset, so copy it back.
-* USERPTR stays the same (was userspace-provided), so no copying. */
-   if (memory == V4L2_MEMORY_MMAP)
+   switch (memory) {
+   case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (copy_in_user(>m.mem_offset, >m.mem_offset,
 sizeof(up->m.mem_offset)))
return -EFAULT;
-   /* For DMABUF, driver might've set up the fd, so copy it back. */
-   if (memory == V4L2_MEMORY_DMABUF)
+   break;
+   case V4L2_MEMORY_USERPTR:
+   if (get_user(p, >m.userptr) ||
+   put_user((compat_ulong_t)ptr_to_compat((__force void *)p),
+>m.userptr))
+   return -EFAULT;
+   break;
+   case V4L2_MEMORY_DMABUF:
if (copy_in_user(>m.fd, >m.fd,
 sizeof(up->m.fd)))
return -EFAULT;
+   break;
+   }
 
return 0;
 }
@@ -386,6 +401,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct 
v4l2_buffer32 __user
} else {
switch (kp->memory) {
case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (get_user(kp->m.offset, >m.offset))
return -EFAULT;
break;
@@ -399,10 +415,6 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, 
struct v4l2_buffer32 __user
kp->m.userptr = (unsigned long)compat_ptr(tmp);
}
break;
-   case V4L2_MEMORY_OVERLAY:
-   if (get_user(kp->m.offset, >m.offset))
-   return -EFAULT;
-   break;
case V4L2_MEMORY_DMABUF:
if (get_user(kp->m.fd, >m.fd))
return -EFAULT;
@@ -459,6 +471,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct 
v4l2_buffer32 __user
} else {
switch (kp->memory) {
case V4L2_MEMORY_MMAP:
+   case V4L2_MEMORY_OVERLAY:
if (put_user(kp->m.offset, >m.offset))
return -EFAULT;
break;
@@ -466,10 +479,6 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, 
struct v4l2_buffer32 __user

[PATCH for v4.1 09/14] media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 273caa260035c03d89ad63d72d8cd3d9e5c5e3f1 upstream.

If the device is of type VFL_TYPE_SUBDEV then vdev->ioctl_ops
is NULL so the 'if (!ops->vidioc_query_ext_ctrl)' check would crash.
Add a test for !ops to the condition.

All sub-devices that have controls will use the control framework,
so they do not have an equivalent to ops->vidioc_query_ext_ctrl.
Returning false if ops is NULL is the correct thing to do here.

Fixes: b8c601e8af ("v4l2-compat-ioctl32.c: fix ctrl_is_pointer")

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Reported-by: Laurent Pinchart 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 52205d37f97f..626a3b345075 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -603,7 +603,7 @@ static inline bool ctrl_is_pointer(struct file *file, u32 
id)
return ctrl && ctrl->is_ptr;
}
 
-   if (!ops->vidioc_query_ext_ctrl)
+   if (!ops || !ops->vidioc_query_ext_ctrl)
return false;
 
return !ops->vidioc_query_ext_ctrl(file, fh, ) &&
-- 
2.15.1



[PATCH for v4.1 12/14] media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit 169f24ca68bf0f247d111aef07af00dd3a02ae88 upstream.

There is nothing wrong with using an unknown buffer type. So
stop spamming the kernel log whenever this happens. The kernel
will just return -EINVAL to signal this.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 25cf19193c13..8371bbbda383 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -170,8 +170,6 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return copy_from_user(>fmt.sliced, >fmt.sliced,
  sizeof(kp->fmt.sliced)) ? -EFAULT : 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
@@ -217,8 +215,6 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return copy_to_user(>fmt.sliced, >fmt.sliced,
sizeof(kp->fmt.sliced)) ?  -EFAULT : 0;
default:
-   printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-  kp->type);
return -EINVAL;
}
 }
-- 
2.15.1



[PATCH for v4.1 04/14] media: v4l2-compat-ioctl32.c: fix the indentation

2018-02-14 Thread Hans Verkuil
From: Hans Verkuil 

commit b7b957d429f601d6d1942122b339474f31191d75 upstream.

The indentation of this source is all over the place. Fix this.
This patch only changes whitespace.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 216 +-
 1 file changed, 108 insertions(+), 108 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 42d402948ea2..ba6aaea11e2f 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -48,11 +48,11 @@ struct v4l2_window32 {
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
-   copy_from_user(>w, >w, sizeof(up->w)) ||
-   get_user(kp->field, >field) ||
-   get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   copy_from_user(>w, >w, sizeof(up->w)) ||
+   get_user(kp->field, >field) ||
+   get_user(kp->chromakey, >chromakey) ||
+   get_user(kp->clipcount, >clipcount))
+   return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
if (kp->clipcount) {
@@ -82,10 +82,10 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
 {
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
-   put_user(kp->field, >field) ||
-   put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
-   return -EFAULT;
+   put_user(kp->field, >field) ||
+   put_user(kp->chromakey, >chromakey) ||
+   put_user(kp->clipcount, >clipcount))
+   return -EFAULT;
return 0;
 }
 
@@ -97,7 +97,7 @@ static inline int get_v4l2_pix_format(struct v4l2_pix_format 
*kp, struct v4l2_pi
 }
 
 static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -112,7 +112,7 @@ static inline int put_v4l2_pix_format(struct 
v4l2_pix_format *kp, struct v4l2_pi
 }
 
 static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
-   struct v4l2_pix_format_mplane __user *up)
+struct v4l2_pix_format_mplane 
__user *up)
 {
if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
return -EFAULT;
@@ -200,7 +200,7 @@ static int __get_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return get_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -244,7 +244,7 @@ static int __put_v4l2_format32(struct v4l2_format *kp, 
struct v4l2_format32 __us
return put_v4l2_sliced_vbi_format(>fmt.sliced, 
>fmt.sliced);
default:
printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type 
%d\n",
-   kp->type);
+  kp->type);
return -EINVAL;
}
 }
@@ -278,7 +278,7 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 {
/* other fields are not set by the user, nor used by the driver */
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
-   get_user(kp->index, >index))
+   get_user(kp->index, >index))
return -EFAULT;
return 0;
 }
@@ -286,13 +286,13 @@ static int get_v4l2_standard32(struct v4l2_standard *kp, 
struct v4l2_standard32
 static int put_v4l2_standard32(struct v4l2_standard *kp, struct 
v4l2_standard32 __user *up)
 {
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
-   put_user(kp->index, >index) ||
-   copy_to_user(up->id, >id, sizeof(__u64)) ||
-   copy_to_user(up->name, kp->name, 24) ||
-   copy_to_user(>frameperiod, >frameperiod, 
sizeof(kp->frameperiod)) ||
-   put_user(kp->framelines, >framelines) ||
-   copy_to_user(up->reserved, 

[PATCH for v4.1 10/14] media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha

2018-02-14 Thread Hans Verkuil
From: Daniel Mentz 

commit 025a26fa14f8fd55d50ab284a30c016a5be953d0 upstream.

Commit b2787845fb91 ("V4L/DVB (5289): Add support for video output
overlays.") added the field global_alpha to struct v4l2_window but did
not update the compat layer accordingly. This change adds global_alpha
to struct v4l2_window32 and copies the value for global_alpha back and
forth.

Signed-off-by: Daniel Mentz 
Signed-off-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 626a3b345075..88e4f5716387 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -45,6 +45,7 @@ struct v4l2_window32 {
compat_caddr_t  clips; /* actually struct v4l2_clip32 * */
__u32   clipcount;
compat_caddr_t  bitmap;
+   __u8global_alpha;
 };
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 
__user *up)
@@ -53,7 +54,8 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
copy_from_user(>w, >w, sizeof(up->w)) ||
get_user(kp->field, >field) ||
get_user(kp->chromakey, >chromakey) ||
-   get_user(kp->clipcount, >clipcount))
+   get_user(kp->clipcount, >clipcount) ||
+   get_user(kp->global_alpha, >global_alpha))
return -EFAULT;
if (kp->clipcount > 2048)
return -EINVAL;
@@ -86,7 +88,8 @@ static int put_v4l2_window32(struct v4l2_window *kp, struct 
v4l2_window32 __user
if (copy_to_user(>w, >w, sizeof(kp->w)) ||
put_user(kp->field, >field) ||
put_user(kp->chromakey, >chromakey) ||
-   put_user(kp->clipcount, >clipcount))
+   put_user(kp->clipcount, >clipcount) ||
+   put_user(kp->global_alpha, >global_alpha))
return -EFAULT;
return 0;
 }
-- 
2.15.1



  1   2   >