diff mbox series

[v6,2/5] media: v4l2: Extend VIDIOC_ENUM_FMT to support MC-centric devices

Message ID 20200319004701.30416-3-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series v4l2-dev/ioctl: Add V4L2_CAP_IO_MC | expand

Commit Message

Laurent Pinchart March 19, 2020, 12:46 a.m. UTC
The VIDIOC_ENUM_FMT ioctl enumerates all formats supported by a video
node. For MC-centric devices, its behaviour has always been ill-defined,
with drivers implementing one of the following behaviours:

- No support for VIDIOC_ENUM_FMT at all
- Enumerating all formats supported by the video node, regardless of the
  configuration of the pipeline
- Enumerating formats supported by the video node for the active
  configuration of the connected subdevice

The first behaviour is obviously useless for applications. The second
behaviour provides the most information, but doesn't offer a way to find
what formats are compatible with a given pipeline configuration. The
third behaviour fixes that, but with the drawback that applications
can't enumerate all supported formats anymore, and have to modify the
active configuration of the pipeline to enumerate formats.

The situation is messy as none of the implemented behaviours are ideal,
and userspace can't predict what will happen as the behaviour is
driver-specific.

To fix this, let's extend the VIDIOC_ENUM_FMT with a missing capability:
enumerating pixel formats for a given media bus code. The media bus code
is passed through the v4l2_fmtdesc structure in a new mbus_code field
(repurposed from the reserved fields). With this capability in place,
applications can enumerate pixel formats for a given media bus code
without modifying the active configuration of the device.

The current behaviour of the ioctl is preserved when the new mbus_code
field is set to 0, ensuring compatibility with existing userspace. The
API extension is documented as mandatory for MC-centric devices (as
advertised through the V4L2_CAP_IO_MC capability), allowing applications
and compliance tools to easily determine the availability of the
VIDIOC_ENUM_FMT extension.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../media/uapi/v4l/vidioc-enum-fmt.rst        | 19 +++++++++++++++----
 drivers/media/v4l2-core/v4l2-ioctl.c          | 13 +++++++++++--
 include/uapi/linux/videodev2.h                |  3 ++-
 3 files changed, 28 insertions(+), 7 deletions(-)

Comments

kernel test robot March 19, 2020, 3:42 a.m. UTC | #1
Hi Laurent,

I love your patch! Perhaps something to improve:

[auto build test WARNING on v5.6-rc6]
[also build test WARNING on next-20200318]
[cannot apply to linuxtv-media/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Laurent-Pinchart/v4l2-dev-ioctl-Add-V4L2_CAP_IO_MC/20200319-084846
base:    fb33c6510d5595144d585aa194d377cf74d31911
config: x86_64-randconfig-s1-20200319 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-5) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/media/pci/ivtv/ivtv-ioctl.c: In function 'ivtv_enum_fmt_vid_cap':
>> drivers/media/pci/ivtv/ivtv-ioctl.c:925:3: warning: braces around scalar initializer
      { 0, 0, 0, 0 }
      ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:3: note: (near initialization for 'hm12.mbus_code')
>> drivers/media/pci/ivtv/ivtv-ioctl.c:925:8: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
           ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:8: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:11: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
              ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:11: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:14: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
                 ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:925:14: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:3: warning: braces around scalar initializer
      { 0, 0, 0, 0 }
      ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:3: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:8: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
           ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:8: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:11: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
              ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:11: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:14: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
                 ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:14: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c: In function 'ivtv_enum_fmt_vid_out':
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:3: warning: braces around scalar initializer
      { 0, 0, 0, 0 }
      ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:3: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:8: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
           ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:8: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:11: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
              ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:11: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:14: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
                 ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:14: note: (near initialization for 'hm12.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:3: warning: braces around scalar initializer
      { 0, 0, 0, 0 }
      ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:3: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:8: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
           ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:8: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:11: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
              ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:11: note: (near initialization for 'mpeg.mbus_code')
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:14: warning: excess elements in scalar initializer
      { 0, 0, 0, 0 }
                 ^
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:14: note: (near initialization for 'mpeg.mbus_code')

vim +925 drivers/media/pci/ivtv/ivtv-ioctl.c

1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  919  
3f038d80039f60 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  920  static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
3f038d80039f60 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  921  {
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  922  	static const struct v4l2_fmtdesc hm12 = {
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  923  		0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
368f080b6870e6 drivers/media/video/ivtv/ivtv-ioctl.c Ian Armstrong 2007-11-05  924  		"HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27 @925  		{ 0, 0, 0, 0 }
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  926  	};
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  927  	static const struct v4l2_fmtdesc mpeg = {
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  928  		0, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  929  		"MPEG", V4L2_PIX_FMT_MPEG,
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  930  		{ 0, 0, 0, 0 }
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  931  	};
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  932  	struct ivtv *itv = fh2id(fh)->itv;
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  933  	struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  934  
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  935  	if (fmt->index)
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  936  		return -EINVAL;
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  937  	if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  938  		*fmt = mpeg;
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  939  	else if (s->type == IVTV_ENC_STREAM_TYPE_YUV)
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  940  		*fmt = hm12;
bfd063cebb75d3 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  941  	else
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  942  		return -EINVAL;
3f038d80039f60 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  943  	return 0;
1a0adaf37c30e8 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  944  }
3f038d80039f60 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  945  

:::::: The code at line 925 was first introduced by commit
:::::: 1a0adaf37c30e89e44d1470ef604a930999a5826 V4L/DVB (5345): ivtv driver for Conexant cx23416/cx23415 MPEG encoder/decoder

:::::: TO: Hans Verkuil <hverkuil@xs4all.nl>
:::::: CC: Mauro Carvalho Chehab <mchehab@infradead.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot March 19, 2020, 3:52 a.m. UTC | #2
Hi Laurent,

I love your patch! Perhaps something to improve:

[auto build test WARNING on v5.6-rc6]
[also build test WARNING on next-20200318]
[cannot apply to linuxtv-media/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Laurent-Pinchart/v4l2-dev-ioctl-Add-V4L2_CAP_IO_MC/20200319-084846
base:    fb33c6510d5595144d585aa194d377cf74d31911
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=9.2.0 make.cross ARCH=parisc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/media//pci/cx18/cx18-ioctl.c: In function 'cx18_enum_fmt_vid_cap':
>> drivers/media//pci/cx18/cx18-ioctl.c:470:5: warning: braces around scalar initializer
     470 |     "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
         |     ^~~~~~~~~~~~~~~~~~
   drivers/media//pci/cx18/cx18-ioctl.c:470:5: note: (near initialization for 'formats[0].mbus_code')
>> drivers/media//pci/cx18/cx18-ioctl.c:470:49: warning: excess elements in scalar initializer
     470 |     "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
         |                                                 ^
   drivers/media//pci/cx18/cx18-ioctl.c:470:49: note: (near initialization for 'formats[0].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:470:52: warning: excess elements in scalar initializer
     470 |     "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
         |                                                    ^
   drivers/media//pci/cx18/cx18-ioctl.c:470:52: note: (near initialization for 'formats[0].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:470:55: warning: excess elements in scalar initializer
     470 |     "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
         |                                                       ^
   drivers/media//pci/cx18/cx18-ioctl.c:470:55: note: (near initialization for 'formats[0].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:473:5: warning: braces around scalar initializer
     473 |     "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
         |     ^~~~~~
   drivers/media//pci/cx18/cx18-ioctl.c:473:5: note: (near initialization for 'formats[1].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:473:37: warning: excess elements in scalar initializer
     473 |     "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
         |                                     ^
   drivers/media//pci/cx18/cx18-ioctl.c:473:37: note: (near initialization for 'formats[1].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:473:40: warning: excess elements in scalar initializer
     473 |     "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
         |                                        ^
   drivers/media//pci/cx18/cx18-ioctl.c:473:40: note: (near initialization for 'formats[1].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:473:43: warning: excess elements in scalar initializer
     473 |     "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
         |                                           ^
   drivers/media//pci/cx18/cx18-ioctl.c:473:43: note: (near initialization for 'formats[1].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:476:5: warning: braces around scalar initializer
     476 |     "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
         |     ^~~~~~~~~~~~
   drivers/media//pci/cx18/cx18-ioctl.c:476:5: note: (near initialization for 'formats[2].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:476:43: warning: excess elements in scalar initializer
     476 |     "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
         |                                           ^
   drivers/media//pci/cx18/cx18-ioctl.c:476:43: note: (near initialization for 'formats[2].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:476:46: warning: excess elements in scalar initializer
     476 |     "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
         |                                              ^
   drivers/media//pci/cx18/cx18-ioctl.c:476:46: note: (near initialization for 'formats[2].mbus_code')
   drivers/media//pci/cx18/cx18-ioctl.c:476:49: warning: excess elements in scalar initializer
     476 |     "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
         |                                                 ^
   drivers/media//pci/cx18/cx18-ioctl.c:476:49: note: (near initialization for 'formats[2].mbus_code')

vim +470 drivers/media//pci/cx18/cx18-ioctl.c

1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  464  
3b6fe58f0f1888 drivers/media/video/cx18/cx18-ioctl.c Andy Walls       2008-06-21  465  static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
3b6fe58f0f1888 drivers/media/video/cx18/cx18-ioctl.c Andy Walls       2008-06-21  466  					struct v4l2_fmtdesc *fmt)
3b6fe58f0f1888 drivers/media/video/cx18/cx18-ioctl.c Andy Walls       2008-06-21  467  {
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  468  	static const struct v4l2_fmtdesc formats[] = {
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  469  		{ 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03 @470  		  "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  471  		},
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  472  		{ 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  473  		  "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  474  		},
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  475  		{ 2, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  476  		  "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  477  		},
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  478  	};
1bf5842fe3b61d drivers/media/video/cx18/cx18-ioctl.c Simon Farnsworth 2011-05-03  479  
b7101de3fff596 drivers/media/video/cx18/cx18-ioctl.c Steven Toth      2011-04-06  480  	if (fmt->index > ARRAY_SIZE(formats) - 1)
1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  481  		return -EINVAL;
1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  482  	*fmt = formats[fmt->index];
1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  483  	return 0;
1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  484  }
1c1e45d17b663d drivers/media/video/cx18/cx18-ioctl.c Hans Verkuil     2008-04-28  485  

:::::: The code at line 470 was first introduced by commit
:::::: 1bf5842fe3b61d2dbbced96dbd27ad26fe93444a [media] cx18: Clean up mmap() support for raw YUV

:::::: TO: Simon Farnsworth <simon.farnsworth@onelan.co.uk>
:::::: CC: Mauro Carvalho Chehab <mchehab@redhat.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot March 19, 2020, 8:24 a.m. UTC | #3
Hi Laurent,

I love your patch! Perhaps something to improve:

[auto build test WARNING on v5.6-rc6]
[also build test WARNING on next-20200318]
[cannot apply to linuxtv-media/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Laurent-Pinchart/v4l2-dev-ioctl-Add-V4L2_CAP_IO_MC/20200319-084846
base:    fb33c6510d5595144d585aa194d377cf74d31911
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-181-g83789bbc-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> drivers/media/pci/ivtv/ivtv-ioctl.c:925:17: sparse: sparse: bogus scalar initializer
   drivers/media/pci/ivtv/ivtv-ioctl.c:930:17: sparse: sparse: bogus scalar initializer
   drivers/media/pci/ivtv/ivtv-ioctl.c:951:17: sparse: sparse: bogus scalar initializer
   drivers/media/pci/ivtv/ivtv-ioctl.c:956:17: sparse: sparse: bogus scalar initializer
--
>> drivers/media/pci/cx18/cx18-ioctl.c:470:58: sparse: sparse: bogus scalar initializer
   drivers/media/pci/cx18/cx18-ioctl.c:473:46: sparse: sparse: bogus scalar initializer
   drivers/media/pci/cx18/cx18-ioctl.c:476:52: sparse: sparse: bogus scalar initializer

vim +925 drivers/media/pci/ivtv/ivtv-ioctl.c

1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  919  
3f038d80039f60e drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  920  static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
3f038d80039f60e drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  921  {
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  922  	static const struct v4l2_fmtdesc hm12 = {
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  923  		0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
368f080b6870e65 drivers/media/video/ivtv/ivtv-ioctl.c Ian Armstrong 2007-11-05  924  		"HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27 @925  		{ 0, 0, 0, 0 }
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  926  	};
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  927  	static const struct v4l2_fmtdesc mpeg = {
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  928  		0, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  929  		"MPEG", V4L2_PIX_FMT_MPEG,
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  930  		{ 0, 0, 0, 0 }
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  931  	};
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  932  	struct ivtv *itv = fh2id(fh)->itv;
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  933  	struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  934  
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  935  	if (fmt->index)
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  936  		return -EINVAL;
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  937  	if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  938  		*fmt = mpeg;
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  939  	else if (s->type == IVTV_ENC_STREAM_TYPE_YUV)
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  940  		*fmt = hm12;
bfd063cebb75d33 drivers/media/pci/ivtv/ivtv-ioctl.c   Hans Verkuil  2012-10-01  941  	else
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  942  		return -EINVAL;
3f038d80039f60e drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  943  	return 0;
1a0adaf37c30e89 drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2007-04-27  944  }
3f038d80039f60e drivers/media/video/ivtv/ivtv-ioctl.c Hans Verkuil  2008-05-29  945  

:::::: The code at line 925 was first introduced by commit
:::::: 1a0adaf37c30e89e44d1470ef604a930999a5826 V4L/DVB (5345): ivtv driver for Conexant cx23416/cx23415 MPEG encoder/decoder

:::::: TO: Hans Verkuil <hverkuil@xs4all.nl>
:::::: CC: Mauro Carvalho Chehab <mchehab@infradead.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Sakari Ailus March 23, 2020, 10:03 a.m. UTC | #4
Hi Laurent,

On Thu, Mar 19, 2020 at 02:46:58AM +0200, Laurent Pinchart wrote:
> The VIDIOC_ENUM_FMT ioctl enumerates all formats supported by a video
> node. For MC-centric devices, its behaviour has always been ill-defined,
> with drivers implementing one of the following behaviours:
> 
> - No support for VIDIOC_ENUM_FMT at all
> - Enumerating all formats supported by the video node, regardless of the
>   configuration of the pipeline
> - Enumerating formats supported by the video node for the active
>   configuration of the connected subdevice
> 
> The first behaviour is obviously useless for applications. The second
> behaviour provides the most information, but doesn't offer a way to find
> what formats are compatible with a given pipeline configuration. The
> third behaviour fixes that, but with the drawback that applications
> can't enumerate all supported formats anymore, and have to modify the
> active configuration of the pipeline to enumerate formats.
> 
> The situation is messy as none of the implemented behaviours are ideal,
> and userspace can't predict what will happen as the behaviour is
> driver-specific.
> 
> To fix this, let's extend the VIDIOC_ENUM_FMT with a missing capability:
> enumerating pixel formats for a given media bus code. The media bus code
> is passed through the v4l2_fmtdesc structure in a new mbus_code field
> (repurposed from the reserved fields). With this capability in place,
> applications can enumerate pixel formats for a given media bus code
> without modifying the active configuration of the device.
> 
> The current behaviour of the ioctl is preserved when the new mbus_code
> field is set to 0, ensuring compatibility with existing userspace. The
> API extension is documented as mandatory for MC-centric devices (as
> advertised through the V4L2_CAP_IO_MC capability), allowing applications
> and compliance tools to easily determine the availability of the
> VIDIOC_ENUM_FMT extension.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

I'd address setting the reserved fields explicitly in a separate patch,
simply by removing them. As another field in the struct is assigned, the
memory is zeroed and explicit assignment is redundant.

> ---
>  .../media/uapi/v4l/vidioc-enum-fmt.rst        | 19 +++++++++++++++----
>  drivers/media/v4l2-core/v4l2-ioctl.c          | 13 +++++++++++--
>  include/uapi/linux/videodev2.h                |  3 ++-
>  3 files changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> index 8ca6ab701e4a..82792d8e910b 100644
> --- a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> +++ b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> @@ -48,10 +48,21 @@ one until ``EINVAL`` is returned. If applicable, drivers shall return
>  formats in preference order, where preferred formats are returned before
>  (that is, with lower ``index`` value) less-preferred formats.
>  
> -.. note::
> -
> -   After switching input or output the list of enumerated image
> -   formats may be different.
> +If the driver doesn't advertise the ``V4L2_CAP_IO_MC``
> +:ref:`device-capabilities <capability>`, applications shall initialize the
> +``mbus_code`` field to zero. Drivers shall enumerate all image formats supported
> +by the device. The enumerated formats may depend on the active input or output
> +of the device.
> +
> +If the driver advertises the ``V4L2_CAP_IO_MC`` :ref:`device-capabilities
> +<capability>`, applications may initialize the ``mbus_code`` to a valid
> +:ref:`v4l2_mbus_pixelcode <media bus format code>`. If the ``mbus_code` field
> +is not zero, drivers shall restrict enumeration to only the image formats that
> +can produce (for video output devices) or be produced from (for video capture
> +devices) that media bus code. Regardless of the value of the ``mbus_code``
> +field, the enumerated image formats shall not depend on the active
> +configuration of the video device or device pipeline. Enumeration shall
> +otherwise operate as previously described.
>  
>  
>  .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 3545a8adf844..b55603964abd 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -264,12 +264,13 @@ static void v4l_print_fmtdesc(const void *arg, bool write_only)
>  {
>  	const struct v4l2_fmtdesc *p = arg;
>  
> -	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
> +	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, mbus_code=0x%04x, description='%.*s'\n",
>  		p->index, prt_names(p->type, v4l2_type_names),
>  		p->flags, (p->pixelformat & 0xff),
>  		(p->pixelformat >>  8) & 0xff,
>  		(p->pixelformat >> 16) & 0xff,
>  		(p->pixelformat >> 24) & 0xff,
> +		p->mbus_code,
>  		(int)sizeof(p->description), p->description);
>  }
>  
> @@ -1467,12 +1468,20 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
>  	struct video_device *vdev = video_devdata(file);
>  	struct v4l2_fmtdesc *p = arg;
>  	int ret = check_fmt(file, p->type);
> +	u32 mbus_code;
>  	u32 cap_mask;
>  
>  	if (ret)
>  		return ret;
>  	ret = -EINVAL;
>  
> +	if (p->mbus_code && !(vdev->device_caps & V4L2_CAP_IO_MC))
> +		return -EINVAL;
> +
> +	mbus_code = p->mbus_code;
> +	CLEAR_AFTER_FIELD(p, type);
> +	p->mbus_code = mbus_code;
> +
>  	switch (p->type) {
>  	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
>  	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
> @@ -2752,7 +2761,7 @@ DEFINE_V4L_STUB_FUNC(dv_timings_cap)
>  
>  static const struct v4l2_ioctl_info v4l2_ioctls[] = {
>  	IOCTL_INFO(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
> -	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
> +	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, 0),
>  	IOCTL_INFO(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, 0),
>  	IOCTL_INFO(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
>  	IOCTL_INFO(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index c793263a3705..0ece960844a5 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -779,7 +779,8 @@ struct v4l2_fmtdesc {
>  	__u32               flags;
>  	__u8		    description[32];   /* Description string */
>  	__u32		    pixelformat;       /* Format fourcc      */
> -	__u32		    reserved[4];
> +	__u32		    mbus_code;		/* Media bus code    */
> +	__u32		    reserved[3];
>  };
>  
>  #define V4L2_FMT_FLAG_COMPRESSED		0x0001
Laurent Pinchart March 23, 2020, 10:07 a.m. UTC | #5
Hi Sakari,

On Mon, Mar 23, 2020 at 12:03:28PM +0200, Sakari Ailus wrote:
> On Thu, Mar 19, 2020 at 02:46:58AM +0200, Laurent Pinchart wrote:
> > The VIDIOC_ENUM_FMT ioctl enumerates all formats supported by a video
> > node. For MC-centric devices, its behaviour has always been ill-defined,
> > with drivers implementing one of the following behaviours:
> > 
> > - No support for VIDIOC_ENUM_FMT at all
> > - Enumerating all formats supported by the video node, regardless of the
> >   configuration of the pipeline
> > - Enumerating formats supported by the video node for the active
> >   configuration of the connected subdevice
> > 
> > The first behaviour is obviously useless for applications. The second
> > behaviour provides the most information, but doesn't offer a way to find
> > what formats are compatible with a given pipeline configuration. The
> > third behaviour fixes that, but with the drawback that applications
> > can't enumerate all supported formats anymore, and have to modify the
> > active configuration of the pipeline to enumerate formats.
> > 
> > The situation is messy as none of the implemented behaviours are ideal,
> > and userspace can't predict what will happen as the behaviour is
> > driver-specific.
> > 
> > To fix this, let's extend the VIDIOC_ENUM_FMT with a missing capability:
> > enumerating pixel formats for a given media bus code. The media bus code
> > is passed through the v4l2_fmtdesc structure in a new mbus_code field
> > (repurposed from the reserved fields). With this capability in place,
> > applications can enumerate pixel formats for a given media bus code
> > without modifying the active configuration of the device.
> > 
> > The current behaviour of the ioctl is preserved when the new mbus_code
> > field is set to 0, ensuring compatibility with existing userspace. The
> > API extension is documented as mandatory for MC-centric devices (as
> > advertised through the V4L2_CAP_IO_MC capability), allowing applications
> > and compliance tools to easily determine the availability of the
> > VIDIOC_ENUM_FMT extension.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> I'd address setting the reserved fields explicitly in a separate patch,
> simply by removing them. As another field in the struct is assigned, the
> memory is zeroed and explicit assignment is redundant.

I'm not sure to follow you, what code are you referring to ?

> > ---
> >  .../media/uapi/v4l/vidioc-enum-fmt.rst        | 19 +++++++++++++++----
> >  drivers/media/v4l2-core/v4l2-ioctl.c          | 13 +++++++++++--
> >  include/uapi/linux/videodev2.h                |  3 ++-
> >  3 files changed, 28 insertions(+), 7 deletions(-)
> > 
> > diff --git a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> > index 8ca6ab701e4a..82792d8e910b 100644
> > --- a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> > +++ b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
> > @@ -48,10 +48,21 @@ one until ``EINVAL`` is returned. If applicable, drivers shall return
> >  formats in preference order, where preferred formats are returned before
> >  (that is, with lower ``index`` value) less-preferred formats.
> >  
> > -.. note::
> > -
> > -   After switching input or output the list of enumerated image
> > -   formats may be different.
> > +If the driver doesn't advertise the ``V4L2_CAP_IO_MC``
> > +:ref:`device-capabilities <capability>`, applications shall initialize the
> > +``mbus_code`` field to zero. Drivers shall enumerate all image formats supported
> > +by the device. The enumerated formats may depend on the active input or output
> > +of the device.
> > +
> > +If the driver advertises the ``V4L2_CAP_IO_MC`` :ref:`device-capabilities
> > +<capability>`, applications may initialize the ``mbus_code`` to a valid
> > +:ref:`v4l2_mbus_pixelcode <media bus format code>`. If the ``mbus_code` field
> > +is not zero, drivers shall restrict enumeration to only the image formats that
> > +can produce (for video output devices) or be produced from (for video capture
> > +devices) that media bus code. Regardless of the value of the ``mbus_code``
> > +field, the enumerated image formats shall not depend on the active
> > +configuration of the video device or device pipeline. Enumeration shall
> > +otherwise operate as previously described.
> >  
> >  
> >  .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
> > diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> > index 3545a8adf844..b55603964abd 100644
> > --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> > +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> > @@ -264,12 +264,13 @@ static void v4l_print_fmtdesc(const void *arg, bool write_only)
> >  {
> >  	const struct v4l2_fmtdesc *p = arg;
> >  
> > -	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
> > +	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, mbus_code=0x%04x, description='%.*s'\n",
> >  		p->index, prt_names(p->type, v4l2_type_names),
> >  		p->flags, (p->pixelformat & 0xff),
> >  		(p->pixelformat >>  8) & 0xff,
> >  		(p->pixelformat >> 16) & 0xff,
> >  		(p->pixelformat >> 24) & 0xff,
> > +		p->mbus_code,
> >  		(int)sizeof(p->description), p->description);
> >  }
> >  
> > @@ -1467,12 +1468,20 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
> >  	struct video_device *vdev = video_devdata(file);
> >  	struct v4l2_fmtdesc *p = arg;
> >  	int ret = check_fmt(file, p->type);
> > +	u32 mbus_code;
> >  	u32 cap_mask;
> >  
> >  	if (ret)
> >  		return ret;
> >  	ret = -EINVAL;
> >  
> > +	if (p->mbus_code && !(vdev->device_caps & V4L2_CAP_IO_MC))
> > +		return -EINVAL;
> > +
> > +	mbus_code = p->mbus_code;
> > +	CLEAR_AFTER_FIELD(p, type);
> > +	p->mbus_code = mbus_code;
> > +
> >  	switch (p->type) {
> >  	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
> >  	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
> > @@ -2752,7 +2761,7 @@ DEFINE_V4L_STUB_FUNC(dv_timings_cap)
> >  
> >  static const struct v4l2_ioctl_info v4l2_ioctls[] = {
> >  	IOCTL_INFO(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
> > -	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
> > +	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, 0),
> >  	IOCTL_INFO(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, 0),
> >  	IOCTL_INFO(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
> >  	IOCTL_INFO(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
> > diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> > index c793263a3705..0ece960844a5 100644
> > --- a/include/uapi/linux/videodev2.h
> > +++ b/include/uapi/linux/videodev2.h
> > @@ -779,7 +779,8 @@ struct v4l2_fmtdesc {
> >  	__u32               flags;
> >  	__u8		    description[32];   /* Description string */
> >  	__u32		    pixelformat;       /* Format fourcc      */
> > -	__u32		    reserved[4];
> > +	__u32		    mbus_code;		/* Media bus code    */
> > +	__u32		    reserved[3];
> >  };
> >  
> >  #define V4L2_FMT_FLAG_COMPRESSED		0x0001
Sakari Ailus March 23, 2020, 10:12 a.m. UTC | #6
On Mon, Mar 23, 2020 at 12:07:27PM +0200, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Mon, Mar 23, 2020 at 12:03:28PM +0200, Sakari Ailus wrote:
> > On Thu, Mar 19, 2020 at 02:46:58AM +0200, Laurent Pinchart wrote:
> > > The VIDIOC_ENUM_FMT ioctl enumerates all formats supported by a video
> > > node. For MC-centric devices, its behaviour has always been ill-defined,
> > > with drivers implementing one of the following behaviours:
> > > 
> > > - No support for VIDIOC_ENUM_FMT at all
> > > - Enumerating all formats supported by the video node, regardless of the
> > >   configuration of the pipeline
> > > - Enumerating formats supported by the video node for the active
> > >   configuration of the connected subdevice
> > > 
> > > The first behaviour is obviously useless for applications. The second
> > > behaviour provides the most information, but doesn't offer a way to find
> > > what formats are compatible with a given pipeline configuration. The
> > > third behaviour fixes that, but with the drawback that applications
> > > can't enumerate all supported formats anymore, and have to modify the
> > > active configuration of the pipeline to enumerate formats.
> > > 
> > > The situation is messy as none of the implemented behaviours are ideal,
> > > and userspace can't predict what will happen as the behaviour is
> > > driver-specific.
> > > 
> > > To fix this, let's extend the VIDIOC_ENUM_FMT with a missing capability:
> > > enumerating pixel formats for a given media bus code. The media bus code
> > > is passed through the v4l2_fmtdesc structure in a new mbus_code field
> > > (repurposed from the reserved fields). With this capability in place,
> > > applications can enumerate pixel formats for a given media bus code
> > > without modifying the active configuration of the device.
> > > 
> > > The current behaviour of the ioctl is preserved when the new mbus_code
> > > field is set to 0, ensuring compatibility with existing userspace. The
> > > API extension is documented as mandatory for MC-centric devices (as
> > > advertised through the V4L2_CAP_IO_MC capability), allowing applications
> > > and compliance tools to easily determine the availability of the
> > > VIDIOC_ENUM_FMT extension.
> > > 
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > 
> > I'd address setting the reserved fields explicitly in a separate patch,
> > simply by removing them. As another field in the struct is assigned, the
> > memory is zeroed and explicit assignment is redundant.
> 
> I'm not sure to follow you, what code are you referring to ?

Have you seen the e-mails from the kbuild bot?
diff mbox series

Patch

diff --git a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
index 8ca6ab701e4a..82792d8e910b 100644
--- a/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
+++ b/Documentation/media/uapi/v4l/vidioc-enum-fmt.rst
@@ -48,10 +48,21 @@  one until ``EINVAL`` is returned. If applicable, drivers shall return
 formats in preference order, where preferred formats are returned before
 (that is, with lower ``index`` value) less-preferred formats.
 
-.. note::
-
-   After switching input or output the list of enumerated image
-   formats may be different.
+If the driver doesn't advertise the ``V4L2_CAP_IO_MC``
+:ref:`device-capabilities <capability>`, applications shall initialize the
+``mbus_code`` field to zero. Drivers shall enumerate all image formats supported
+by the device. The enumerated formats may depend on the active input or output
+of the device.
+
+If the driver advertises the ``V4L2_CAP_IO_MC`` :ref:`device-capabilities
+<capability>`, applications may initialize the ``mbus_code`` to a valid
+:ref:`v4l2_mbus_pixelcode <media bus format code>`. If the ``mbus_code` field
+is not zero, drivers shall restrict enumeration to only the image formats that
+can produce (for video output devices) or be produced from (for video capture
+devices) that media bus code. Regardless of the value of the ``mbus_code``
+field, the enumerated image formats shall not depend on the active
+configuration of the video device or device pipeline. Enumeration shall
+otherwise operate as previously described.
 
 
 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 3545a8adf844..b55603964abd 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -264,12 +264,13 @@  static void v4l_print_fmtdesc(const void *arg, bool write_only)
 {
 	const struct v4l2_fmtdesc *p = arg;
 
-	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
+	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, mbus_code=0x%04x, description='%.*s'\n",
 		p->index, prt_names(p->type, v4l2_type_names),
 		p->flags, (p->pixelformat & 0xff),
 		(p->pixelformat >>  8) & 0xff,
 		(p->pixelformat >> 16) & 0xff,
 		(p->pixelformat >> 24) & 0xff,
+		p->mbus_code,
 		(int)sizeof(p->description), p->description);
 }
 
@@ -1467,12 +1468,20 @@  static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
 	struct video_device *vdev = video_devdata(file);
 	struct v4l2_fmtdesc *p = arg;
 	int ret = check_fmt(file, p->type);
+	u32 mbus_code;
 	u32 cap_mask;
 
 	if (ret)
 		return ret;
 	ret = -EINVAL;
 
+	if (p->mbus_code && !(vdev->device_caps & V4L2_CAP_IO_MC))
+		return -EINVAL;
+
+	mbus_code = p->mbus_code;
+	CLEAR_AFTER_FIELD(p, type);
+	p->mbus_code = mbus_code;
+
 	switch (p->type) {
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
@@ -2752,7 +2761,7 @@  DEFINE_V4L_STUB_FUNC(dv_timings_cap)
 
 static const struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
+	IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, 0),
 	IOCTL_INFO(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, 0),
 	IOCTL_INFO(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index c793263a3705..0ece960844a5 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -779,7 +779,8 @@  struct v4l2_fmtdesc {
 	__u32               flags;
 	__u8		    description[32];   /* Description string */
 	__u32		    pixelformat;       /* Format fourcc      */
-	__u32		    reserved[4];
+	__u32		    mbus_code;		/* Media bus code    */
+	__u32		    reserved[3];
 };
 
 #define V4L2_FMT_FLAG_COMPRESSED		0x0001