Skip to contentSkip to conversation

media: Introduce video device state management

PATCH In review Jai Luthra 8 participants 38 messages Sep 19, 2025 – Mar 8

Subsystems (141)
lore
Share & tools
lore

Jai Luthra

author
#0 lore raw

v2 cover media: Introduce video device state management

Hi,

This patch series introduces state management for video devices.

Currently, V4L2 subdevices have a well-established state management system [1] that allows the framework to store the subdevice state at a central location.

Video devices however lack this, leading to inconsistent state handling across drivers and making it difficult to implement features like hardware multiplexing in complex media pipelines [2].

The series is composed of three parts:

- Core Infrastructure (PATCH 1-4)
Introduces the basic state structure, try state support, initialization callbacks, and driver helpers
- Framework Integration (PATCH 5-7)
Integrates state passing through the ioctl wrappers and driver implementations
- Driver Examples (PATCH 8-10)
Use the state to store formats in TI J721E CSI2RX and Rockchip RKISP1 drivers

This should also provide a foundation for drivers to extend or subclass the state structure with device-specific variables in future.

I have tested capture and format negotiation with the converted drivers on SK AM62A (j721e-csi2rx) and Debix Model A (rkisp1).

[1]: https://lore.kernel.org/linux-media/[email protected]/
[2]: https://lore.kernel.org/linux-media/20250724-multicontext-mainline-2025-v2-0-c9b316773486@ideasonboard.com/

---
Changes in v2:
- Drop RFC tag
- Rebase on top of latest media tree, that includes multiple changes by
Jacopo and Laurent, which removes all usage of passing v4l2_fh through
the opaque pointer in ioctl implementations, replacing it with a NULL
pointer
- Allocate the state dynamically, and free it when done with the device
or the filehandle
- Introduce an init_state callback so that drivers can initialize the
state after allocation
- Pass the video device state (as an explicitly typed pointer) to all
ioctl implemenation across all drivers
- Split the single patch introducing video device state into separate
patches each making a single logical change before the state is
actually passed to the drivers in PATCH 7
- In drivers, use a helper to access the current format from the state
- Move the queue busy check back to the drivers, as some codecs and VBI
devices may support changing formats, so the framework shouldn't
return -EBUSY
- Drop pixel format info and configuration storage from rkisp1 internal strucutre, and calculate them on the fly
- Fix other review comments from Sakari, Laurent and Jacopo, except
those around dropping the enum and using try_fmt hook to update only
the state, and s_fmt hook to update hardware registers
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jai Luthra (10):
media: v4l2-core: Introduce state management for video devices
media: v4l2-dev: Add support for try state
media: v4l2-dev: Add callback for initializing video device state
media: v4l2-dev: Add helpers to get current format from the state
media: v4l2-ioctl: Add video_device_state argument to v4l2 ioctl wrappers
media: Replace void * with video_device_state * in all driver ioctl implementations
media: v4l2-ioctl: Pass device state for G/S/TRY_FMT ioctls
media: ti: j721e-csi2rx: Use video_device_state
media: rkisp1: Use video_device_state
media: rkisp1: Calculate format information on demand

 drivers/input/rmi4/rmi_f54.c                       |  22 +-
 drivers/input/touchscreen/atmel_mxt_ts.c           |  23 +-
 drivers/input/touchscreen/sur40.c                  |  35 +-
 .../extron-da-hd-4k-plus/extron-da-hd-4k-plus.c    |  34 +-
 drivers/media/common/saa7146/saa7146_video.c       |  37 +-
 drivers/media/common/videobuf2/videobuf2-v4l2.c    |  30 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |  38 +-
 drivers/media/i2c/video-i2c.c                      |  39 ++-
 drivers/media/pci/bt8xx/bttv-driver.c              |  84 +++--
 drivers/media/pci/bt8xx/bttv-vbi.c                 |  11 +-
 drivers/media/pci/bt8xx/bttvp.h                    |   9 +-
 drivers/media/pci/cobalt/cobalt-v4l2.c             |  98 +++---
 drivers/media/pci/cx18/cx18-driver.c               |   9 +-
 drivers/media/pci/cx18/cx18-ioctl.c                | 114 +++---
 drivers/media/pci/cx18/cx18-ioctl.h                |   9 +-
 drivers/media/pci/cx23885/cx23885-417.c            |  53 +--
 drivers/media/pci/cx23885/cx23885-ioctl.c          |   8 +-
 drivers/media/pci/cx23885/cx23885-ioctl.h          |   9 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   5 +-
 drivers/media/pci/cx23885/cx23885-video.c          |  82 +++--
 drivers/media/pci/cx23885/cx23885.h                |   4 +-
 drivers/media/pci/cx25821/cx25821-video.c          |  57 ++-
 drivers/media/pci/cx88/cx88-blackbird.c            |  47 ++-
 drivers/media/pci/cx88/cx88-vbi.c                  |   2 +-
 drivers/media/pci/cx88/cx88-video.c                |  56 ++-
 drivers/media/pci/cx88/cx88.h                      |   2 +-
 drivers/media/pci/dt3155/dt3155.c                  |  25 +-
 drivers/media/pci/intel/ipu3/ipu3-cio2.c           |  29 +-
 drivers/media/pci/intel/ipu6/ipu6-isys-video.c     |  41 ++-
 drivers/media/pci/ivtv/ivtv-driver.c               |   8 +-
 drivers/media/pci/ivtv/ivtv-ioctl.c                | 225 ++++++++----
 drivers/media/pci/ivtv/ivtv-ioctl.h                |   6 +-
 drivers/media/pci/mgb4/mgb4_vin.c                  |  55 ++-
 drivers/media/pci/mgb4/mgb4_vout.c                 |  49 ++-
 drivers/media/pci/saa7134/saa7134-empress.c        |  12 +-
 drivers/media/pci/saa7134/saa7134-video.c          |  96 ++++--
 drivers/media/pci/saa7134/saa7134.h                |  38 +-
 drivers/media/pci/saa7146/hexium_gemini.c          |  10 +-
 drivers/media/pci/saa7146/hexium_orion.c           |  10 +-
 drivers/media/pci/saa7146/mxb.c                    |  46 ++-
 drivers/media/pci/saa7164/saa7164-encoder.c        |  39 ++-
 drivers/media/pci/saa7164/saa7164-vbi.c            |  27 +-
 drivers/media/pci/saa7164/saa7164.h                |   9 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |  46 ++-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |  32 +-
 drivers/media/pci/ttpci/budget-av.c                |  10 +-
 drivers/media/pci/tw5864/tw5864-video.c            |  49 ++-
 drivers/media/pci/tw68/tw68-video.c                |  43 ++-
 drivers/media/pci/tw686x/tw686x-video.c            |  53 ++-
 drivers/media/pci/zoran/zoran_driver.c             |  44 ++-
 drivers/media/platform/allegro-dvt/allegro-core.c  |  49 ++-
 .../media/platform/amlogic/c3/isp/c3-isp-capture.c |  18 +-
 .../media/platform/amlogic/c3/isp/c3-isp-params.c  |   9 +-
 .../media/platform/amlogic/c3/isp/c3-isp-stats.c   |   9 +-
 drivers/media/platform/amlogic/meson-ge2d/ge2d.c   |  36 +-
 drivers/media/platform/amphion/vdec.c              |  30 +-
 drivers/media/platform/amphion/venc.c              |  49 ++-
 drivers/media/platform/aspeed/aspeed-video.c       |  50 ++-
 drivers/media/platform/atmel/atmel-isi.c           |  36 +-
 drivers/media/platform/broadcom/bcm2835-unicam.c   |  33 +-
 .../media/platform/chips-media/coda/coda-common.c  |  69 ++--
 .../platform/chips-media/wave5/wave5-helper.c      |   2 +-
 .../platform/chips-media/wave5/wave5-helper.h      |   3 +-
 .../platform/chips-media/wave5/wave5-vpu-dec.c     |  54 ++-
 .../platform/chips-media/wave5/wave5-vpu-enc.c     |  62 +++-
 .../media/platform/imagination/e5010-jpeg-enc.c    |  34 +-
 drivers/media/platform/intel/pxa_camera.c          |  34 +-
 drivers/media/platform/m2m-deinterlace.c           |  34 +-
 drivers/media/platform/marvell/mcam-core.c         |  52 +--
 .../media/platform/mediatek/jpeg/mtk_jpeg_core.c   |  44 ++-
 drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c  |  34 +-
 .../media/platform/mediatek/mdp3/mtk-mdp3-m2m.c    |  25 +-
 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c       |  52 ++-
 .../mediatek/vcodec/encoder/mtk_vcodec_enc.c       |  50 ++-
 .../media/platform/microchip/microchip-isc-base.c  |  33 +-
 drivers/media/platform/nuvoton/npcm-video.c        |  43 ++-
 drivers/media/platform/nvidia/tegra-vde/v4l2.c     |  38 +-
 drivers/media/platform/nxp/dw100/dw100.c           |  35 +-
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c     |  52 ++-
 drivers/media/platform/nxp/imx-pxp.c               |  34 +-
 drivers/media/platform/nxp/imx7-media-csi.c        |  21 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |  15 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   |  18 +-
 drivers/media/platform/nxp/mx2_emmaprp.c           |  31 +-
 drivers/media/platform/qcom/camss/camss-video.c    |  27 +-
 drivers/media/platform/qcom/iris/iris_vidc.c       |  48 ++-
 drivers/media/platform/qcom/venus/vdec.c           |  29 +-
 drivers/media/platform/qcom/venus/venc.c           |  38 +-
 .../media/platform/raspberrypi/pisp_be/pisp_be.c   |  42 ++-
 drivers/media/platform/raspberrypi/rp1-cfe/cfe.c   |  40 ++-
 .../media/platform/renesas/rcar-vin/rcar-v4l2.c    |  21 +-
 drivers/media/platform/renesas/rcar_drif.c         |  30 +-
 drivers/media/platform/renesas/rcar_fdp1.c         |  18 +-
 drivers/media/platform/renesas/rcar_jpu.c          |  21 +-
 drivers/media/platform/renesas/renesas-ceu.c       |  36 +-
 .../media/platform/renesas/rzg2l-cru/rzg2l-video.c |  18 +-
 drivers/media/platform/renesas/sh_vou.c            |  41 ++-
 drivers/media/platform/renesas/vsp1/vsp1_histo.c   |   9 +-
 drivers/media/platform/renesas/vsp1/vsp1_video.c   |  18 +-
 drivers/media/platform/rockchip/rga/rga.c          |  24 +-
 .../platform/rockchip/rkisp1/rkisp1-capture.c      | 289 ++++++++--------
 .../media/platform/rockchip/rkisp1/rkisp1-common.h |  10 -
 .../media/platform/rockchip/rkisp1/rkisp1-params.c |  15 +-
 .../media/platform/rockchip/rkisp1/rkisp1-stats.c  |   9 +-
 drivers/media/platform/rockchip/rkvdec/rkvdec.c    |  34 +-
 .../media/platform/samsung/exynos-gsc/gsc-m2m.c    |  44 ++-
 .../platform/samsung/exynos4-is/fimc-capture.c     |  45 ++-
 .../platform/samsung/exynos4-is/fimc-isp-video.c   |  32 +-
 .../media/platform/samsung/exynos4-is/fimc-lite.c  |  36 +-
 .../media/platform/samsung/exynos4-is/fimc-m2m.c   |  21 +-
 .../platform/samsung/s3c-camif/camif-capture.c     |  54 ++-
 drivers/media/platform/samsung/s5p-g2d/g2d.c       |  26 +-
 .../media/platform/samsung/s5p-jpeg/jpeg-core.c    |  34 +-
 .../media/platform/samsung/s5p-mfc/s5p_mfc_dec.c   |  48 ++-
 .../media/platform/samsung/s5p-mfc/s5p_mfc_enc.c   |  51 ++-
 drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c   |  26 +-
 drivers/media/platform/st/sti/delta/delta-v4l2.c   |  44 ++-
 drivers/media/platform/st/sti/hva/hva-v4l2.c       |  46 ++-
 drivers/media/platform/st/stm32/dma2d/dma2d.c      |  18 +-
 drivers/media/platform/st/stm32/stm32-dcmi.c       |  42 ++-
 .../st/stm32/stm32-dcmipp/dcmipp-bytecap.c         |  20 +-
 .../media/platform/sunxi/sun4i-csi/sun4i_v4l2.c    |  25 +-
 .../platform/sunxi/sun6i-csi/sun6i_csi_capture.c   |  24 +-
 drivers/media/platform/sunxi/sun8i-di/sun8i-di.c   |  31 +-
 .../platform/sunxi/sun8i-rotate/sun8i_rotate.c     |  34 +-
 .../media/platform/synopsys/hdmirx/snps_hdmirx.c   |  47 ++-
 drivers/media/platform/ti/am437x/am437x-vpfe.c     |  52 ++-
 drivers/media/platform/ti/cal/cal-video.c          |  54 ++-
 drivers/media/platform/ti/davinci/vpif_capture.c   |  94 ++---
 drivers/media/platform/ti/davinci/vpif_display.c   |  58 ++--
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  | 127 +++----
 drivers/media/platform/ti/omap/omap_vout.c         |  49 ++-
 drivers/media/platform/ti/omap3isp/ispvideo.c      |  53 ++-
 drivers/media/platform/ti/vpe/vpe.c                |  25 +-
 drivers/media/platform/verisilicon/hantro_v4l2.c   |  47 ++-
 drivers/media/platform/via/via-camera.c            |  42 ++-
 drivers/media/platform/xilinx/xilinx-dma.c         |  15 +-
 drivers/media/radio/dsbr100.c                      |  15 +-
 drivers/media/radio/radio-cadet.c                  |  18 +-
 drivers/media/radio/radio-isa.c                    |  18 +-
 drivers/media/radio/radio-keene.c                  |  15 +-
 drivers/media/radio/radio-ma901.c                  |  15 +-
 drivers/media/radio/radio-miropcm20.c              |  15 +-
 drivers/media/radio/radio-mr800.c                  |  18 +-
 drivers/media/radio/radio-raremono.c               |  19 +-
 drivers/media/radio/radio-sf16fmi.c                |  15 +-
 drivers/media/radio/radio-si476x.c                 |  28 +-
 drivers/media/radio/radio-tea5764.c                |  15 +-
 drivers/media/radio/radio-tea5777.c                |  21 +-
 drivers/media/radio/radio-timb.c                   |  26 +-
 drivers/media/radio/si470x/radio-si470x-common.c   |  25 +-
 drivers/media/radio/si4713/radio-platform-si4713.c |  18 +-
 drivers/media/radio/si4713/radio-usb-si4713.c      |  15 +-
 drivers/media/radio/tea575x.c                      |  21 +-
 drivers/media/test-drivers/vicodec/vicodec-core.c  |  54 +--
 drivers/media/test-drivers/vim2m.c                 |  56 +--
 drivers/media/test-drivers/vimc/vimc-capture.c     |  20 +-
 drivers/media/test-drivers/visl/visl-video.c       |  34 +-
 drivers/media/test-drivers/vivid/vivid-core.c      | 203 ++++++-----
 drivers/media/test-drivers/vivid/vivid-meta-cap.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-cap.h  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-out.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-out.h  |   9 +-
 drivers/media/test-drivers/vivid/vivid-radio-rx.c  |  16 +-
 drivers/media/test-drivers/vivid/vivid-radio-rx.h  |  16 +-
 drivers/media/test-drivers/vivid/vivid-radio-tx.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-radio-tx.h  |   6 +-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c   |  30 +-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.h   |  30 +-
 drivers/media/test-drivers/vivid/vivid-touch-cap.c |  22 +-
 drivers/media/test-drivers/vivid/vivid-touch-cap.h |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-cap.c   |  26 +-
 drivers/media/test-drivers/vivid/vivid-vbi-cap.h   |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-out.c   |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-out.h   |  18 +-
 drivers/media/test-drivers/vivid/vivid-vid-cap.c   | 114 +++---
 drivers/media/test-drivers/vivid/vivid-vid-cap.h   | 117 +++++--
 .../media/test-drivers/vivid/vivid-vid-common.c    |  24 +-
 .../media/test-drivers/vivid/vivid-vid-common.h    |  34 +-
 drivers/media/test-drivers/vivid/vivid-vid-out.c   | 122 ++++---
 drivers/media/test-drivers/vivid/vivid-vid-out.h   |  95 +++--
 drivers/media/usb/airspy/airspy.c                  |  37 +-
 drivers/media/usb/au0828/au0828-video.c            |  74 ++--
 drivers/media/usb/cx231xx/cx231xx-417.c            |  28 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |  79 +++--
 drivers/media/usb/cx231xx/cx231xx.h                |  39 ++-
 drivers/media/usb/dvb-usb/cxusb-analog.c           |  48 ++-
 drivers/media/usb/em28xx/em28xx-video.c            |  87 +++--
 drivers/media/usb/go7007/go7007-v4l2.c             |  75 ++--
 drivers/media/usb/gspca/gspca.c                    |  51 ++-
 drivers/media/usb/hackrf/hackrf.c                  |  39 ++-
 drivers/media/usb/hdpvr/hdpvr-video.c              |  60 ++--
 drivers/media/usb/msi2500/msi2500.c                |  31 +-
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c           |  98 ++++--
 drivers/media/usb/pwc/pwc-v4l.c                    |  44 ++-
 drivers/media/usb/s2255/s2255drv.c                 |  55 ++-
 drivers/media/usb/stk1160/stk1160-v4l.c            |  40 ++-
 drivers/media/usb/usbtv/usbtv-video.c              |  24 +-
 drivers/media/usb/uvc/uvc_metadata.c               |  17 +-
 drivers/media/usb/uvc/uvc_v4l2.c                   |  59 +++-
 drivers/media/v4l2-core/v4l2-ctrls-api.c           |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 |  66 ++++
 drivers/media/v4l2-core/v4l2-fh.c                  |   6 +
 drivers/media/v4l2-core/v4l2-ioctl.c               | 381 +++++++++++----------
 drivers/media/v4l2-core/v4l2-mem2mem.c             |  56 +--
 drivers/staging/media/atomisp/pci/atomisp_ioctl.c  |  72 ++--
 drivers/staging/media/av7110/av7110_v4l.c          |  60 +++-
 .../media/deprecated/atmel/atmel-isc-base.c        |  33 +-
 drivers/staging/media/imx/imx-media-capture.c      |  53 ++-
 drivers/staging/media/imx/imx-media-csc-scaler.c   |  23 +-
 drivers/staging/media/ipu3/ipu3-v4l2.c             |  29 +-
 drivers/staging/media/ipu7/ipu7-isys-video.c       |  30 +-
 drivers/staging/media/meson/vdec/vdec.c            |  26 +-
 drivers/staging/media/starfive/camss/stf-video.c   |  18 +-
 drivers/staging/media/sunxi/cedrus/cedrus_video.c  |  29 +-
 .../media/sunxi/sun6i-isp/sun6i_isp_capture.c      |  24 +-
 .../media/sunxi/sun6i-isp/sun6i_isp_params.c       |   9 +-
 drivers/staging/media/tegra-video/vi.c             |  68 ++--
 drivers/staging/most/video/video.c                 |  39 ++-
 .../vc04_services/bcm2835-camera/bcm2835-camera.c  |  58 ++--
 drivers/usb/gadget/function/uvc_v4l2.c             |  50 ++-
 include/media/v4l2-ctrls.h                         |   5 +-
 include/media/v4l2-dev.h                           |  84 +++++
 include/media/v4l2-fh.h                            |   2 +
 include/media/v4l2-ioctl.h                         | 238 ++++++-------
 include/media/v4l2-mem2mem.h                       |  48 ++-
 include/media/videobuf2-v4l2.h                     |  33 +-
 227 files changed, 5946 insertions(+), 3322 deletions(-)

---
base-commit: 680fa38ea3a19131871a90bac05a610e6247d928
change-id: 20250703-vdev-state-0743baa0ad4b

Best regards,

Signature · 1 line
Jai Luthra <[email protected]>
author
#1 lore raw

PATCH v2 1/10 media: v4l2-core: Introduce state management for video devices

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+	struct video_device_state *state =
+		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	state->vdev = vdev;
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+	kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
 	spin_lock_init(&vdev->fh_lock);
 	INIT_LIST_HEAD(&vdev->fh_list);
 
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		vdev->state = __video_device_state_alloc(vdev);
+
 	/* Part 1: check device type */
 	switch (type) {
 	case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
 	clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_unlock(&videodev_lock);
 	v4l2_event_wake_all(vdev);
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		__video_device_state_free(vdev->state);
 	device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +40 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *	set by the core when the sub-devices device nodes are registered with
  *	v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *	handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *	indicates that the &struct video_device has state support.
+ *	The active video and metadata formats are stored in video_device.state,
+ *	and the try video and metadata formats are stored in v4l2_fh.state.
+ *	All new drivers should use it.
  */
 enum v4l2_video_device_flags {
 	V4L2_FL_REGISTERED		= 0,
 	V4L2_FL_USES_V4L2_FH		= 1,
 	V4L2_FL_QUIRK_INVERTED_CROP	= 2,
 	V4L2_FL_SUBDEV_RO_DEVNODE	= 3,
+	V4L2_FL_USES_STATE		= 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+	struct v4l2_format fmt;
+	struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *	 If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
 	struct vb2_queue *queue;
 
 	struct v4l2_prio_state *prio;
+	struct video_device_state *state;
 
 	/* device info */
 	char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
 	return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+	struct video_device_state *state =
+		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	state->vdev = vdev;
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+	kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
 	spin_lock_init(&vdev->fh_lock);
 	INIT_LIST_HEAD(&vdev->fh_list);
 
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		vdev->state = __video_device_state_alloc(vdev);
+
 	/* Part 1: check device type */
 	switch (type) {
 	case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
 	clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_unlock(&videodev_lock);
 	v4l2_event_wake_all(vdev);
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		__video_device_state_free(vdev->state);
 	device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *	set by the core when the sub-devices device nodes are registered with
  *	v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *	handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *	indicates that the &struct video_device has state support.
+ *	The active video and metadata formats are stored in video_device.state,
+ *	and the try video and metadata formats are stored in v4l2_fh.state.
+ *	All new drivers should use it.
  */
 enum v4l2_video_device_flags {
 	V4L2_FL_REGISTERED		= 0,
 	V4L2_FL_USES_V4L2_FH		= 1,
 	V4L2_FL_QUIRK_INVERTED_CROP	= 2,
 	V4L2_FL_SUBDEV_RO_DEVNODE	= 3,
+	V4L2_FL_USES_STATE		= 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+	struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.
2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.
4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+	struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *	 If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
 	struct vb2_queue *queue;
 
 	struct v4l2_prio_state *prio;
+	struct video_device_state *state;
 
 	/* device info */
 	char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
 	return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
#3 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Quoted 142 lines · Hans Verkuil

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+	struct video_device_state *state =
+		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	state->vdev = vdev;
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+	kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
 	spin_lock_init(&vdev->fh_lock);
 	INIT_LIST_HEAD(&vdev->fh_list);
 
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		vdev->state = __video_device_state_alloc(vdev);
+
 	/* Part 1: check device type */
 	switch (type) {
 	case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
 	clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_unlock(&videodev_lock);
 	v4l2_event_wake_all(vdev);
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		__video_device_state_free(vdev->state);
 	device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *	set by the core when the sub-devices device nodes are registered with
  *	v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *	handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *	indicates that the &struct video_device has state support.
+ *	The active video and metadata formats are stored in video_device.state,
+ *	and the try video and metadata formats are stored in v4l2_fh.state.
+ *	All new drivers should use it.
  */
 enum v4l2_video_device_flags {
 	V4L2_FL_REGISTERED		= 0,
 	V4L2_FL_USES_V4L2_FH		= 1,
 	V4L2_FL_QUIRK_INVERTED_CROP	= 2,
 	V4L2_FL_SUBDEV_RO_DEVNODE	= 3,
+	V4L2_FL_USES_STATE		= 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+	struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.
2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.
4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Quoted 7 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+	struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *	 If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
 	struct vb2_queue *queue;
 
 	struct v4l2_prio_state *prio;
+	struct video_device_state *state;
 
 	/* device info */
 	char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
 	return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
author
#4 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Hi Hans,

Thanks for the review.

Quoting Hans Verkuil (2025-09-22 13:30:05)

Quoted 131 lines · Hans Verkuil
Quoted 130 lines

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+    struct video_device_state *state =
+            kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+    if (!state)
+            return ERR_PTR(-ENOMEM);
+
+    state->vdev = vdev;
+
+    return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+    kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
     get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
     spin_lock_init(&vdev->fh_lock);
     INIT_LIST_HEAD(&vdev->fh_list);
 
+    /* state support */
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            vdev->state = __video_device_state_alloc(vdev);
+
     /* Part 1: check device type */
     switch (type) {
     case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
     clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
     mutex_unlock(&videodev_lock);
     v4l2_event_wake_all(vdev);
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            __video_device_state_free(vdev->state);
     device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *  set by the core when the sub-devices device nodes are registered with
  *  v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *  handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *  indicates that the &struct video_device has state support.
+ *  The active video and metadata formats are stored in video_device.state,
+ *  and the try video and metadata formats are stored in v4l2_fh.state.
+ *  All new drivers should use it.
  */
 enum v4l2_video_device_flags {
     V4L2_FL_REGISTERED              = 0,
     V4L2_FL_USES_V4L2_FH            = 1,
     V4L2_FL_QUIRK_INVERTED_CROP     = 2,
     V4L2_FL_SUBDEV_RO_DEVNODE       = 3,
+    V4L2_FL_USES_STATE              = 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
     int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+    struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

Quoted 3 lines
Quoted 3 lines

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.

Ah I see, so for M2M devices the formats are stored per-context, where the context is tied to the filehandle. In that case, I agree that storing the format state inside struct video_device would not work.

Quoted 3 lines
Quoted 3 lines

2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.

RPi CFE driver is one such case, where a single driver structure stores both metadata and video format. But if I understand correctly, it creates separate video device nodes for metadata and video capture, so it can be managed through a single v4l2_format.fmt union for each video device.

Are there any non-M2M drivers which allow more than one type of formats to be set on the same device node?

Quoted 5 lines
Quoted 5 lines

4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Yes, bcm2835-camera should be dropped hopefully in a couple more revisions of
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 8 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Sure, I think we can modify the existing state struct to store both capture and output formats, and keep it inside struct v4l2_fh for M2M devices.

This will definitely be confusing for driver developers, as currently the two example patches in this series access the state directly. So I will add framework helpers to access the correct state and format type, and document properly that it should never be accessed manually by drivers.

Quoted 5 lines

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Argh, naming is the hardest problem :-)
Do you have any suggestions?

I personally don't think video_device_state is a bad name, even if it is stored somewhere else for m2m devices, given it is still the "state" of the video device, even if it is not persistent across multiple file opens.

I was trying to avoid names with "context" in then, so it does not clash with Jacopo's work.

Quoted 64 lines

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+    struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *  This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *   If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
     struct vb2_queue *queue;
 
     struct v4l2_prio_state *prio;
+    struct video_device_state *state;
 
     /* device info */
     char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
     return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *

Thanks,
Jai

#5 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Hi Jai,

Thanks for your efforts! Could you include me in Cc: in the next iteration, please?

Quoted 28 lines · Jai Luthra

Hi Hans,

Thanks for the review.

Quoting Hans Verkuil (2025-09-22 13:30:05)

Quoted 23 lines · Hans Verkuil
Quoted 22 lines

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 17 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

Could you elaborate a bit on how (sub)device states and the future contexts will be related? Based on the description above, I imagine that at some point there will be a context data structure that contains all (sub) device states, and when a certain context becomes active, the states are passed and applied to the (sub)devices. But this is only my imagination here. It would be great to know the overall concept here.

Quoted 96 lines
Quoted 96 lines
Quoted 96 lines
Quoted 96 lines

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+    struct video_device_state *state =
+            kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+    if (!state)
+            return ERR_PTR(-ENOMEM);
+
+    state->vdev = vdev;
+
+    return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+    kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
     get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
     spin_lock_init(&vdev->fh_lock);
     INIT_LIST_HEAD(&vdev->fh_list);
 
+    /* state support */
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            vdev->state = __video_device_state_alloc(vdev);
+
     /* Part 1: check device type */
     switch (type) {
     case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
     clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
     mutex_unlock(&videodev_lock);
     v4l2_event_wake_all(vdev);
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            __video_device_state_free(vdev->state);
     device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *  set by the core when the sub-devices device nodes are registered with
  *  v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *  handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *  indicates that the &struct video_device has state support.
+ *  The active video and metadata formats are stored in video_device.state,
+ *  and the try video and metadata formats are stored in v4l2_fh.state.
+ *  All new drivers should use it.
  */
 enum v4l2_video_device_flags {
     V4L2_FL_REGISTERED              = 0,
     V4L2_FL_USES_V4L2_FH            = 1,
     V4L2_FL_QUIRK_INVERTED_CROP     = 2,
     V4L2_FL_SUBDEV_RO_DEVNODE       = 3,
+    V4L2_FL_USES_STATE              = 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
     int (*release) (struct file *);
 };
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/media/v4l2-dev.h struct v4l2_file_operations { · line 227

Quoted 5 lines
include/media/v4l2-dev.h +5 -0
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device

What else do you envisage to be included in the state?

Quoted 45 lines
Quoted 10 lines
Quoted 10 lines

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 3 lines
include/media/v4l2-dev.h +3 -0
+ */
+struct video_device_state {
+    struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.

Ah I see, so for M2M devices the formats are stored per-context, where the context is tied to the filehandle. In that case, I agree that storing the format state inside struct video_device would not work.

Quoted 3 lines
Quoted 3 lines

2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.

RPi CFE driver is one such case, where a single driver structure stores both metadata and video format. But if I understand correctly, it creates separate video device nodes for metadata and video capture, so it can be managed through a single v4l2_format.fmt union for each video device.

Are there any non-M2M drivers which allow more than one type of formats to be set on the same device node?

Quoted 5 lines
Quoted 5 lines

4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Yes, bcm2835-camera should be dropped hopefully in a couple more revisions of
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 8 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Quoted 7 lines

Sure, I think we can modify the existing state struct to store both capture and output formats, and keep it inside struct v4l2_fh for M2M devices.

This will definitely be confusing for driver developers, as currently the two example patches in this series access the state directly. So I will add framework helpers to access the correct state and format type, and document properly that it should never be accessed manually by drivers.

Would that be a similar approach as in v4l2_subdev_state?

Quoted 8 lines
Quoted 4 lines

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Argh, naming is the hardest problem :-)
Do you have any suggestions?

Quoted 6 lines

I personally don't think video_device_state is a bad name, even if it is stored somewhere else for m2m devices, given it is still the "state" of the video device, even if it is not persistent across multiple file opens.

I was trying to avoid names with "context" in then, so it does not clash with Jacopo's work.

It would be interesting how contexts (the new ones from Jacopo's series) are applied to mem2mem devices. And again, how the state introduced here is related to the (new) context.

Best regards,
Michael

Quoted 69 lines
Quoted 65 lines

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+    struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *  This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *   If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
     struct vb2_queue *queue;
 
     struct v4l2_prio_state *prio;
+    struct video_device_state *state;
 
     /* device info */
     char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
     return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *

Thanks,
Jai

maintainer
#6 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Hi Michael

Quoted 29 lines · Michael Riesch

Hi Jai,

Thanks for your efforts! Could you include me in Cc: in the next iteration, please?

Quoted 23 lines · Jai Luthra

Hi Hans,

Thanks for the review.

Quoting Hans Verkuil (2025-09-22 13:30:05)

Quoted 18 lines · Hans Verkuil
Quoted 17 lines

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 12 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

Could you elaborate a bit on how (sub)device states and the future

Sure
https://patchwork.linuxtv.org/project/linux-media/patch/20250724-multicontext-mainline-2025-v2-12-c9b316773486@ideasonboard.com/

Quoted 3 lines

contexts will be related? Based on the description above, I imagine that at some point there will be a context data structure that contains all (sub) device states, and when a certain context becomes active, the

Not all states, a single state.

There will be
1) One state per context
2) One state per open-file handle
3) One state per subdevice

If the driver supports contexts 1) will be used for active and 2) for try.

If the driver doesn't support contexts 3) will be used for activer and
2) for try.

It's a bit more complex than this as we also have a default context in the subdev to support drivers that are context-aware but are operated by context-unaware userspace.

Happy to discuss this more on the actual context series.

Quoted 254 lines

states are passed and applied to the (sub)devices. But this is only my imagination here. It would be great to know the overall concept here.

Quoted 96 lines
Quoted 96 lines
Quoted 96 lines
Quoted 96 lines

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+    struct video_device_state *state =
+            kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+    if (!state)
+            return ERR_PTR(-ENOMEM);
+
+    state->vdev = vdev;
+
+    return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+    kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
     get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
     spin_lock_init(&vdev->fh_lock);
     INIT_LIST_HEAD(&vdev->fh_list);
 
+    /* state support */
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            vdev->state = __video_device_state_alloc(vdev);
+
     /* Part 1: check device type */
     switch (type) {
     case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
     clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
     mutex_unlock(&videodev_lock);
     v4l2_event_wake_all(vdev);
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            __video_device_state_free(vdev->state);
     device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *  set by the core when the sub-devices device nodes are registered with
  *  v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *  handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *  indicates that the &struct video_device has state support.
+ *  The active video and metadata formats are stored in video_device.state,
+ *  and the try video and metadata formats are stored in v4l2_fh.state.
+ *  All new drivers should use it.
  */
 enum v4l2_video_device_flags {
     V4L2_FL_REGISTERED              = 0,
     V4L2_FL_USES_V4L2_FH            = 1,
     V4L2_FL_QUIRK_INVERTED_CROP     = 2,
     V4L2_FL_SUBDEV_RO_DEVNODE       = 3,
+    V4L2_FL_USES_STATE              = 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
     int (*release) (struct file *);
 };
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/media/v4l2-dev.h struct v4l2_file_operations { · line 227

Quoted 5 lines
include/media/v4l2-dev.h +5 -0
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device

What else do you envisage to be included in the state?

Quoted 45 lines
Quoted 10 lines
Quoted 10 lines

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 3 lines
include/media/v4l2-dev.h +3 -0
+ */
+struct video_device_state {
+    struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.

Ah I see, so for M2M devices the formats are stored per-context, where the context is tied to the filehandle. In that case, I agree that storing the format state inside struct video_device would not work.

Quoted 3 lines
Quoted 3 lines

2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.

RPi CFE driver is one such case, where a single driver structure stores both metadata and video format. But if I understand correctly, it creates separate video device nodes for metadata and video capture, so it can be managed through a single v4l2_format.fmt union for each video device.

Are there any non-M2M drivers which allow more than one type of formats to be set on the same device node?

Quoted 5 lines
Quoted 5 lines

4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Yes, bcm2835-camera should be dropped hopefully in a couple more revisions of
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 8 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Quoted 7 lines

Sure, I think we can modify the existing state struct to store both capture and output formats, and keep it inside struct v4l2_fh for M2M devices.

This will definitely be confusing for driver developers, as currently the two example patches in this series access the state directly. So I will add framework helpers to access the correct state and format type, and document properly that it should never be accessed manually by drivers.

Would that be a similar approach as in v4l2_subdev_state?

Quoted 8 lines
Quoted 4 lines

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Argh, naming is the hardest problem :-)
Do you have any suggestions?

Quoted 6 lines

I personally don't think video_device_state is a bad name, even if it is stored somewhere else for m2m devices, given it is still the "state" of the video device, even if it is not persistent across multiple file opens.

I was trying to avoid names with "context" in then, so it does not clash with Jacopo's work.

It would be interesting how contexts (the new ones from Jacopo's series) are applied to mem2mem devices. And again, how the state introduced here is related to the (new) context.

Best regards,
Michael

Quoted 69 lines
Quoted 65 lines

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+    struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *  This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *   If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
     struct vb2_queue *queue;
 
     struct v4l2_prio_state *prio;
+    struct video_device_state *state;
 
     /* device info */
     char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
     return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *

Thanks,
Jai

maintainer
#7 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

In reply to Jai Luthra

Hi Jai, Hans

Quoted 136 lines · Jai Luthra

Hi Hans,

Thanks for the review.

Quoting Hans Verkuil (2025-09-22 13:30:05)

Quoted 131 lines · Hans Verkuil
Quoted 130 lines

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+    struct video_device_state *state =
+            kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+    if (!state)
+            return ERR_PTR(-ENOMEM);
+
+    state->vdev = vdev;
+
+    return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+    kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
     get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
     spin_lock_init(&vdev->fh_lock);
     INIT_LIST_HEAD(&vdev->fh_list);
 
+    /* state support */
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            vdev->state = __video_device_state_alloc(vdev);
+
     /* Part 1: check device type */
     switch (type) {
     case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
     clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
     mutex_unlock(&videodev_lock);
     v4l2_event_wake_all(vdev);
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            __video_device_state_free(vdev->state);
     device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *  set by the core when the sub-devices device nodes are registered with
  *  v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *  handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *  indicates that the &struct video_device has state support.
+ *  The active video and metadata formats are stored in video_device.state,
+ *  and the try video and metadata formats are stored in v4l2_fh.state.
+ *  All new drivers should use it.
  */
 enum v4l2_video_device_flags {
     V4L2_FL_REGISTERED              = 0,
     V4L2_FL_USES_V4L2_FH            = 1,
     V4L2_FL_QUIRK_INVERTED_CROP     = 2,
     V4L2_FL_SUBDEV_RO_DEVNODE       = 3,
+    V4L2_FL_USES_STATE              = 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
     int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+    struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.

Ah I see, so for M2M devices the formats are stored per-context, where the context is tied to the filehandle. In that case, I agree that storing the format state inside struct video_device would not work.

The m2m frameworks stores in 'struct v4l2_m2m_ctx' two queue contexts, one for the output queue and one for capture queue. A v4l2_m2m_ctx is created every time the video device is open and the two queues initialized. Userspace opens the video device two (or more) times and one of the two contexts is used at a time depending on the buffer type userspace uses to initialize the device.

The right place where to store the 'state' seems to me to be 'struct v4l2_m2m_queue_ctx' and a set of helpers for m2m should be provided for drivers to be able to get the 'capture' or 'output' format, provided a v4l2_m2m_ctx to operate with and the buffer type in use.

I'm looking at the m2m driver I know the better (imx8-isi-m2m.c) and the conversion seems trivial there. The format information stored as ctx->queues.out.format/ctx->queues.cap.format could be moved to the framework and accessed with helpers by the driver. As soon as we allow drivers to sub-class the video device state (something I think we should do from the very beginning in this series) the whole 'struct mxc_isi_m2m_ctx_queue_data' type can be replaced and become 'struct mxc_isi_m2m_ctx_state'.

M2M drivers will not set V4L2_FL_USES_STATE so there won't be a state stored in the file handle or the video device for them, but we can indeed require m2m drivers to provide an 'init_state' operation like we do for regular video devices, where the state will be initialised. Only new drivers that provide such operation will have a centralized state.

Now, what do we gain here ? The current video_device_state stores a v4l2_format and a video_device *, and only the v4l2_format is relevant for the m2m framework [*]. However centralizing storage of the format in the framwork and allowing drivers to sub-class it would save some boilerplate indeed. I would be happy to try do this on imx8-isi-m2m.c to see how it will look like.

[*] I would be tempted to introduce a 'class' hierarchy such as:

        struct v4l2_device_state {
                struct v4l2_format fmt;
        }

        struct video_device_state {
                struct v4l2_device_state state;
                struct video_device *vdev;
        }

        struct m2m_context_state {
                struct v4l2_device_state state;
                struct v4l2_m2m_ctx *ctx;
        };

Helpers could shorten access to the state, and drivers can sub-class struct v4l2_device_state by making it a pointer here and delegating allocation and initialization of the state to drivers.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.

Quoted 8 lines

RPi CFE driver is one such case, where a single driver structure stores both metadata and video format. But if I understand correctly, it creates separate video device nodes for metadata and video capture, so it can be managed through a single v4l2_format.fmt union for each video device.

Are there any non-M2M drivers which allow more than one type of formats to be set on the same device node?

For non-m2m device I would consider the above a non-issue. As Jai said the rp1-cfe driver uses two instances of 'struct v4l2_format' to store the meta and capture formats, but they're not used at the same time. IOW the format information can be easily move to be per-video-device state.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines

4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Yes, bcm2835-camera should be dropped hopefully in a couple more revisions of
https://lore.kernel.org/all/[email protected]/

Quoted 4 lines
Quoted 4 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Sure, I think we can modify the existing state struct to store both capture and output formats, and keep it inside struct v4l2_fh for M2M devices.

I don't think we want to store multiple v4l2_formats (or members of the fmt union) in the state. You would need one for each member of the fmt union as you don't know which one the driver will use. I would keep trying to have a single v4l2_format per state and place the state in the right place so that only a single format is needed (see above for m2m).

Quoted 3 lines

This will definitely be confusing for driver developers, as currently the two example patches in this series access the state directly. So I will add

Argh, they shouldn't :)

Quoted 2 lines

framework helpers to access the correct state and format type, and document properly that it should never be accessed manually by drivers.

Thanks!

Quoted 9 lines
Quoted 6 lines

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Argh, naming is the hardest problem :-)
Do you have any suggestions?

What do you think about the above idea of subclassing a generic v4l2_device_state with video_device_state and m2m_context_state ?

Quoted 4 lines

I personally don't think video_device_state is a bad name, even if it is stored somewhere else for m2m devices, given it is still the "state" of the video device, even if it is not persistent across multiple file opens.

I think the problem is mostly due to the fact a video_device_state stores a video_device * which is not relevant for m2m..

Quoted 4 lines

I was trying to avoid names with "context" in then, so it does not clash with Jacopo's work.

Thanks ;)

Quoted 67 lines
Quoted 64 lines

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+    struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *  This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *   If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
     struct vb2_queue *queue;
 
     struct v4l2_prio_state *prio;
+    struct video_device_state *state;
 
     /* device info */
     char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
     return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *

Thanks,
Jai

#8 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

In reply to Jai Luthra
Quoted 148 lines · Jai Luthra

Hi Hans,

Thanks for the review.

Quoting Hans Verkuil (2025-09-22 13:30:05)

Quoted 131 lines · Hans Verkuil
Quoted 130 lines

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+    struct video_device_state *state =
+            kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+    if (!state)
+            return ERR_PTR(-ENOMEM);
+
+    state->vdev = vdev;
+
+    return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+    kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
     get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
     spin_lock_init(&vdev->fh_lock);
     INIT_LIST_HEAD(&vdev->fh_list);
 
+    /* state support */
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            vdev->state = __video_device_state_alloc(vdev);
+
     /* Part 1: check device type */
     switch (type) {
     case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
     clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
     mutex_unlock(&videodev_lock);
     v4l2_event_wake_all(vdev);
+    if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+            __video_device_state_free(vdev->state);
     device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *  set by the core when the sub-devices device nodes are registered with
  *  v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *  handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *  indicates that the &struct video_device has state support.
+ *  The active video and metadata formats are stored in video_device.state,
+ *  and the try video and metadata formats are stored in v4l2_fh.state.
+ *  All new drivers should use it.
  */
 enum v4l2_video_device_flags {
     V4L2_FL_REGISTERED              = 0,
     V4L2_FL_USES_V4L2_FH            = 1,
     V4L2_FL_QUIRK_INVERTED_CROP     = 2,
     V4L2_FL_SUBDEV_RO_DEVNODE       = 3,
+    V4L2_FL_USES_STATE              = 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
     int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+    struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

Quoted 3 lines
Quoted 3 lines

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.

Ah I see, so for M2M devices the formats are stored per-context, where the context is tied to the filehandle. In that case, I agree that storing the format state inside struct video_device would not work.

Quoted 3 lines
Quoted 3 lines

2) VBI devices can have both a raw and sliced VBI format (either capture or output)
3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.

Quoted 7 lines

RPi CFE driver is one such case, where a single driver structure stores both metadata and video format. But if I understand correctly, it creates separate video device nodes for metadata and video capture, so it can be managed through a single v4l2_format.fmt union for each video device.

Are there any non-M2M drivers which allow more than one type of formats to be set on the same device node?

I think this one does that:

drivers/media/pci/intel/ipu6/ipu6-isys-video.c

I think it can set both video and metadata formats, but it can only stream one type at a time. I'm not 100% certain of that, but that's what it looks like reading the code.

Quoted 33 lines
Quoted 6 lines
Quoted 6 lines

4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

Yes, bcm2835-camera should be dropped hopefully in a couple more revisions of
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 8 lines

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Sure, I think we can modify the existing state struct to store both capture and output formats, and keep it inside struct v4l2_fh for M2M devices.

This will definitely be confusing for driver developers, as currently the two example patches in this series access the state directly. So I will add framework helpers to access the correct state and format type, and document properly that it should never be accessed manually by drivers.

Quoted 5 lines

Follow-up: assuming we want to support M2M devices as well (I think we should), then consider renaming video_device_state since it isn't video_device specific, i.e. it can either live in video_device or in v4l2_fh, and in the latter case you'd have two instances: capture and output state.

Quoted 6 lines

Argh, naming is the hardest problem :-)
Do you have any suggestions?

I personally don't think video_device_state is a bad name, even if it is stored somewhere else for m2m devices, given it is still the "state" of the video device, even if it is not persistent across multiple file opens.

Perhaps just v4l2_state?

video_device_state refers to struct video_device, so that's not a good name.

Regards,

Hans

Quoted 71 lines

I was trying to avoid names with "context" in then, so it does not clash with Jacopo's work.

Quoted 64 lines

Regards,

Hans

Quoted 58 lines

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+    struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *  This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *   If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
     struct vb2_queue *queue;
 
     struct v4l2_prio_state *prio;
+    struct video_device_state *state;
 
     /* device info */
     char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
     return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *  This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *

Thanks,
Jai

#9 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

In reply to Hans Verkuil
Quoted 130 lines · Hans Verkuil

Hi Jai,

Apologies that I had no time to review v1, but I'll review v2 today.

Quoted 111 lines · Jai Luthra

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation. In the future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 27 +++++++++++++++++++++++++
 include/media/v4l2-dev.h           | 40 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +27 -0
index 10a126e50c1ca25b1bd0e9872571261acfc26b39..997255709448510fcd17b6de798a3df99cd7ea09 100644
@@ -163,6 +163,27 @@ void video_device_release_empty(struct video_device *vdev)
 }
 EXPORT_SYMBOL(video_device_release_empty);
 
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev)
+{
+	struct video_device_state *state =
+		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	state->vdev = vdev;
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(__video_device_state_alloc);
+
+void __video_device_state_free(struct video_device_state *state)
+{
+	kfree(state);
+}
+EXPORT_SYMBOL_GPL(__video_device_state_free);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
@@ -939,6 +960,10 @@ int __video_register_device(struct video_device *vdev,
 	spin_lock_init(&vdev->fh_lock);
 	INIT_LIST_HEAD(&vdev->fh_list);
 
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		vdev->state = __video_device_state_alloc(vdev);
+
 	/* Part 1: check device type */
 	switch (type) {
 	case VFL_TYPE_VIDEO:
@@ -1127,6 +1152,8 @@ void video_unregister_device(struct video_device *vdev)
 	clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_unlock(&videodev_lock);
 	v4l2_event_wake_all(vdev);
+	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
+		__video_device_state_free(vdev->state);
 	device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
include/media/v4l2-dev.h +6 -0
index a213c3398dcf60be8c531df87bf40c56b4ad772d..57e4691ef467aa2b0782dd4b8357bd0670643293 100644
@@ -89,12 +89,18 @@ struct dentry;
  *	set by the core when the sub-devices device nodes are registered with
  *	v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
  *	handler to restrict access to some ioctl calls.
+ * @V4L2_FL_USES_STATE:
+ *	indicates that the &struct video_device has state support.
+ *	The active video and metadata formats are stored in video_device.state,
+ *	and the try video and metadata formats are stored in v4l2_fh.state.
+ *	All new drivers should use it.
  */
 enum v4l2_video_device_flags {
 	V4L2_FL_REGISTERED		= 0,
 	V4L2_FL_USES_V4L2_FH		= 1,
 	V4L2_FL_QUIRK_INVERTED_CROP	= 2,
 	V4L2_FL_SUBDEV_RO_DEVNODE	= 3,
+	V4L2_FL_USES_STATE		= 4,
 };
 
 /* Priority helper functions */
@@ -214,6 +220,17 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);

include/media/v4l2-dev.h struct v4l2_file_operations { · line 230

Quoted 10 lines
include/media/v4l2-dev.h +8 -0
 };
 
+/**
+ * struct video_device_state - Used for storing video device state information.
+ *
+ * @fmt: Format of the capture stream
+ * @vdev: Pointer to video device
+ */
+struct video_device_state {
+	struct v4l2_format fmt;

While typically a video_device supports only a single video format type, that is not always the case. There are the following exceptions:

Quoted 4 lines

1) M2M devices have both a capture and output video format. However, for M2M devices the state is per-filehandle, so it shouldn't be stored in a video_device_state struct anyway.
2) VBI devices can have both a raw and sliced VBI format (either capture or output)

This is actually wrong. VBI devices are either in raw or in sliced VBI mode, you can't have both at the same time. So a single v4l2_format in the state is fine for this.

Regards,

Hans

Quoted 73 lines

3) AFAIK non-M2M video devices can have both a video and meta format. That may have changed, I'm not 100% certain about this.
4) video devices can also support an OVERLAY or OUTPUT_OVERLAY format (rare)

V4L2_CAP_VIDEO_OVERLAY is currently only used in drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c, so once that driver disappears we can drop video overlay support for capture devices.

2-4 are all quite rare, but 1 is very common. But for such devices the state wouldn't be in video_device anyway.

But it would be nice if the same struct can be used in both m2m devices and non-m2m devices. It's just stored either in struct v4l2_fh or struct video_device. It would give a lot of opportunities for creating helper functions to make the life for driver developers easier.

Regards,

Hans

Quoted 51 lines
include/media/v4l2-dev.h +26 -0
+	struct video_device *vdev;
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -238,6 +255,7 @@ struct v4l2_file_operations {
  * @queue: &struct vb2_queue associated with this device node. May be NULL.
  * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
  *	 If NULL, then v4l2_dev->prio will be used.
+ * @state: &struct video_device_state, holds the active state for the device.
  * @name: video device name
  * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
  * @vfl_dir: V4L receiver, transmitter or m2m
@@ -283,6 +301,7 @@ struct video_device {
 	struct vb2_queue *queue;
 
 	struct v4l2_prio_state *prio;
+	struct video_device_state *state;
 
 	/* device info */
 	char name[64];
@@ -546,6 +565,27 @@ static inline int video_is_registered(struct video_device *vdev)
 	return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
+/** __video_device_state_alloc - allocate video device state structure
+ *
+ * @vdev: pointer to struct video_device
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+struct video_device_state *
+__video_device_state_alloc(struct video_device *vdev);
+
+/** __video_device_state_free - free video device state structure
+ *
+ * @state: pointer to the state to be freed
+ *
+ * .. note::
+ *
+ *	This function is meant to be used only inside the V4L2 core.
+ */
+void __video_device_state_free(struct video_device_state *state);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
#10 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

In reply to Jai Luthra

Em Fri, 19 Sep 2025 15:25:53 +0530
Jai Luthra <[email protected]> escreveu:

Quoted 4 lines

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation.

I didn't look at the patch series yet, so I may be just jumping too fast here, but storing "try" attempts doesn't seem the right thing to do.

Btw, IMHO, the first patch on this series should be against documentation, where you would be describing not only the new feature with the supported states, but also the state machine transitions that are supported, preferably with some graphs.

So, before actually looking on any code changes, I'd like to see a clear description of this new feature, what it is proposing to address, how and what impacts (if any) this would bring to userspace.

The current diffstat:

 include/media/v4l2-ctrls.h                         |   5 +-
 include/media/v4l2-dev.h                           |  84 +++++
 include/media/v4l2-fh.h                            |   2 +
 include/media/v4l2-ioctl.h                         | 238 ++++++-------
 include/media/v4l2-mem2mem.h                       |  48 ++-
 include/media/videobuf2-v4l2.h                     |  33 +-

implies that this affects for now only Documentation/driver-api/media/...

Quoted 9 lines

In the
future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

Quoted 5 lines

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

... but when you mention "contexts", I'm assuming that you're aiming at either userspace API changes and/or behavoral changes that will affect uAPI as well.

Thanks,
Mauro

author
#11 lore raw

Re: [PATCH v2 01/10] media: v4l2-core: Introduce state management for video devices

Hi Mauro,

Quoting Mauro Carvalho Chehab (2025-09-24 15:45:45)

Quoted 23 lines

Em Fri, 19 Sep 2025 15:25:53 +0530
Jai Luthra <[email protected]> escreveu:

Quoted 4 lines

Similar to V4L2 subdev states, introduce state support for video devices to provide a centralized location for storing device state information. This includes the current (active) pixelformat used by the device and the temporary (try) pixelformat used during format negotiation.

I didn't look at the patch series yet, so I may be just jumping too fast here, but storing "try" attempts doesn't seem the right thing to do.

Btw, IMHO, the first patch on this series should be against documentation, where you would be describing not only the new feature with the supported states, but also the state machine transitions that are supported, preferably with some graphs.

So, before actually looking on any code changes, I'd like to see a clear description of this new feature, what it is proposing to address, how and what impacts (if any) this would bring to userspace.

The current diffstat:

Quoted 8 lines
 include/media/v4l2-ctrls.h                         |   5 +-
 include/media/v4l2-dev.h                           |  84 +++++
 include/media/v4l2-fh.h                            |   2 +
 include/media/v4l2-ioctl.h                         | 238 ++++++-------
 include/media/v4l2-mem2mem.h                       |  48 ++-
 include/media/videobuf2-v4l2.h                     |  33 +-

implies that this affects for now only Documentation/driver-api/media/...

There shouldn't be any change to userspace with this series. The state structure introduced here is only for internal use by the drivers, which currently store the applied formats in driver-specific structures.

In the next revision, I will add documentation in v4l2-dev.rst similar to how the subdev state is described in v4l2-subdev.rst.

Quoted 16 lines
Quoted 10 lines

In the
future, this may be extended or subclassed by device drivers to store their internal state variables.

Also introduce a flag for drivers that wish to use this state management. When set, the framework automatically allocates the state during device registration and stores a pointer to it within the video_device structure.

Quoted 5 lines

This change aligns video devices with V4L2 subdevices by storing hardware state in a common framework-allocated structure. This is the first step towards enabling the multiplexing of the underlying hardware by using different software "contexts", each represented by the combined state of all video devices and V4L2 subdevices in a complex media graph.

Quoted 3 lines

... but when you mention "contexts", I'm assuming that you're aiming at either userspace API changes and/or behavoral changes that will affect uAPI as well.

Yes, the userspace side changes are documented in Jacopo's series adding context support for media devices, for example:

https://lore.kernel.org/linux-media/20250724-multicontext-mainline-2025-v2-7-c9b316773486@ideasonboard.com/

Quoted 3 lines

Thanks,
Mauro

Thanks,
Jai

author
#12 lore raw

PATCH v2 2/10 media: v4l2-dev: Add support for try state

In reply to Jai Luthra

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c |  7 +++++--
 drivers/media/v4l2-core/v4l2-fh.c  |  6 ++++++
 include/media/v4l2-dev.h           | 17 ++++++++++++++++-
 include/media/v4l2-fh.h            |  2 ++
 4 files changed, 29 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +5 -2
index 997255709448510fcd17b6de798a3df99cd7ea09..26b6b2f37ca55ce981aa17a28a875dc3cf253d9b 100644
@@ -164,7 +164,8 @@ void video_device_release_empty(struct video_device *vdev)
 EXPORT_SYMBOL(video_device_release_empty);
 
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev)
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which)
 {
 	struct video_device_state *state =
 		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
@@ -172,6 +173,7 @@ __video_device_state_alloc(struct video_device *vdev)
 	if (!state)
 		return ERR_PTR(-ENOMEM);
 
+	state->which = which;
 	state->vdev = vdev;
 
 	return state;
@@ -962,7 +964,8 @@ int __video_register_device(struct video_device *vdev,
 
 	/* state support */
 	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
-		vdev->state = __video_device_state_alloc(vdev);
+		vdev->state = __video_device_state_alloc(vdev,
+							 VIDEO_DEVICE_STATE_ACTIVE);
 
 	/* Part 1: check device type */
 	switch (type) {
drivers/media/v4l2-core/v4l2-fh.c +6 -0
index df3ba9d4674bd25626cfcddc2d0cb28c233e3cc3..522acc0eb8401305c6893232d96d826669ab90d5 100644
@@ -38,6 +38,10 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 	INIT_LIST_HEAD(&fh->subscribed);
 	fh->sequence = -1;
 	mutex_init(&fh->subscribe_lock);
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		fh->state = __video_device_state_alloc(vdev,
+						       VIDEO_DEVICE_STATE_TRY);
 }
 EXPORT_SYMBOL_GPL(v4l2_fh_init);
 
@@ -84,6 +88,8 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
 {
 	if (fh->vdev == NULL)
 		return;
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		kfree(fh->state);
 	v4l_disable_media_source(fh->vdev);
 	v4l2_event_unsubscribe_all(fh);
 	mutex_destroy(&fh->subscribe_lock);
include/media/v4l2-dev.h +16 -1
index 57e4691ef467aa2b0782dd4b8357bd0670643293..5ca04a1674e0bf7016537e6fb461d790fc0a958f 100644
@@ -220,15 +220,28 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);
 };
 
+/**
+ * enum video_device_state_whence - Video device state type
+ *
+ * @VIDEO_DEVICE_STATE_TRY: from VIDIOC_TRY_xxx, for negotiation only
+ * @VIDEO_DEVICE_STATE_ACTIVE: from VIDIOC_S_xxx, applied to the device
+ */
+enum video_device_state_whence {
+	VIDEO_DEVICE_STATE_TRY = 0,
+	VIDEO_DEVICE_STATE_ACTIVE = 1,
+};
+
 /**
  * struct video_device_state - Used for storing video device state information.
  *
  * @fmt: Format of the capture stream
  * @vdev: Pointer to video device
+ * @which: State type (from enum video_device_state_whence)
  */
 struct video_device_state {
 	struct v4l2_format fmt;
 	struct video_device *vdev;
+	enum video_device_state_whence which;
 };
 
 /*
@@ -568,13 +581,15 @@ static inline int video_is_registered(struct video_device *vdev)
 /** __video_device_state_alloc - allocate video device state structure
  *
  * @vdev: pointer to struct video_device
+ * @which: type of video device state (from enum video_device_state_whence)
  *
  * .. note::
  *
  *	This function is meant to be used only inside the V4L2 core.
  */
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev);
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which);
 
 /** __video_device_state_free - free video device state structure
  *
include/media/v4l2-fh.h +2 -0
index aad4b3689d7ea191978f24ce24d24cd2e73636b6..55455704a98d0785d0a3418b8a43d7363b7c8aa2 100644
@@ -28,6 +28,7 @@ struct v4l2_ctrl_handler;
  * @vdev: pointer to &struct video_device
  * @ctrl_handler: pointer to &struct v4l2_ctrl_handler
  * @prio: priority of the file handler, as defined by &enum v4l2_priority
+ * @state: try state used for format negotiation on the video device
  *
  * @wait: event' s wait queue
  * @subscribe_lock: serialise changes to the subscribed list; guarantee that
@@ -44,6 +45,7 @@ struct v4l2_fh {
 	struct video_device	*vdev;
 	struct v4l2_ctrl_handler *ctrl_handler;
 	enum v4l2_priority	prio;
+	struct video_device_state *state;
 
 	/* Events */
 	wait_queue_head_t	wait;
Signature · 1 line
2.51.0
#13 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Quoted 9 lines · Jai Luthra

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Regards,

Hans

Quoted 146 lines

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c |  7 +++++--
 drivers/media/v4l2-core/v4l2-fh.c  |  6 ++++++
 include/media/v4l2-dev.h           | 17 ++++++++++++++++-
 include/media/v4l2-fh.h            |  2 ++
 4 files changed, 29 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +5 -2
index 997255709448510fcd17b6de798a3df99cd7ea09..26b6b2f37ca55ce981aa17a28a875dc3cf253d9b 100644
@@ -164,7 +164,8 @@ void video_device_release_empty(struct video_device *vdev)
 EXPORT_SYMBOL(video_device_release_empty);
 
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev)
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which)
 {
 	struct video_device_state *state =
 		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
@@ -172,6 +173,7 @@ __video_device_state_alloc(struct video_device *vdev)
 	if (!state)
 		return ERR_PTR(-ENOMEM);
 
+	state->which = which;
 	state->vdev = vdev;
 
 	return state;
@@ -962,7 +964,8 @@ int __video_register_device(struct video_device *vdev,
 
 	/* state support */
 	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
-		vdev->state = __video_device_state_alloc(vdev);
+		vdev->state = __video_device_state_alloc(vdev,
+							 VIDEO_DEVICE_STATE_ACTIVE);
 
 	/* Part 1: check device type */
 	switch (type) {
drivers/media/v4l2-core/v4l2-fh.c +6 -0
index df3ba9d4674bd25626cfcddc2d0cb28c233e3cc3..522acc0eb8401305c6893232d96d826669ab90d5 100644
@@ -38,6 +38,10 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 	INIT_LIST_HEAD(&fh->subscribed);
 	fh->sequence = -1;
 	mutex_init(&fh->subscribe_lock);
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		fh->state = __video_device_state_alloc(vdev,
+						       VIDEO_DEVICE_STATE_TRY);
 }
 EXPORT_SYMBOL_GPL(v4l2_fh_init);
 
@@ -84,6 +88,8 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
 {
 	if (fh->vdev == NULL)
 		return;
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		kfree(fh->state);
 	v4l_disable_media_source(fh->vdev);
 	v4l2_event_unsubscribe_all(fh);
 	mutex_destroy(&fh->subscribe_lock);
include/media/v4l2-dev.h +16 -1
index 57e4691ef467aa2b0782dd4b8357bd0670643293..5ca04a1674e0bf7016537e6fb461d790fc0a958f 100644
@@ -220,15 +220,28 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);
 };
 
+/**
+ * enum video_device_state_whence - Video device state type
+ *
+ * @VIDEO_DEVICE_STATE_TRY: from VIDIOC_TRY_xxx, for negotiation only
+ * @VIDEO_DEVICE_STATE_ACTIVE: from VIDIOC_S_xxx, applied to the device
+ */
+enum video_device_state_whence {
+	VIDEO_DEVICE_STATE_TRY = 0,
+	VIDEO_DEVICE_STATE_ACTIVE = 1,
+};
+
 /**
  * struct video_device_state - Used for storing video device state information.
  *
  * @fmt: Format of the capture stream
  * @vdev: Pointer to video device
+ * @which: State type (from enum video_device_state_whence)
  */
 struct video_device_state {
 	struct v4l2_format fmt;
 	struct video_device *vdev;
+	enum video_device_state_whence which;
 };
 
 /*
@@ -568,13 +581,15 @@ static inline int video_is_registered(struct video_device *vdev)
 /** __video_device_state_alloc - allocate video device state structure
  *
  * @vdev: pointer to struct video_device
+ * @which: type of video device state (from enum video_device_state_whence)
  *
  * .. note::
  *
  *	This function is meant to be used only inside the V4L2 core.
  */
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev);
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which);
 
 /** __video_device_state_free - free video device state structure
  *
include/media/v4l2-fh.h +2 -0
index aad4b3689d7ea191978f24ce24d24cd2e73636b6..55455704a98d0785d0a3418b8a43d7363b7c8aa2 100644
@@ -28,6 +28,7 @@ struct v4l2_ctrl_handler;
  * @vdev: pointer to &struct video_device
  * @ctrl_handler: pointer to &struct v4l2_ctrl_handler
  * @prio: priority of the file handler, as defined by &enum v4l2_priority
+ * @state: try state used for format negotiation on the video device
  *
  * @wait: event' s wait queue
  * @subscribe_lock: serialise changes to the subscribed list; guarantee that
@@ -44,6 +45,7 @@ struct v4l2_fh {
 	struct video_device	*vdev;
 	struct v4l2_ctrl_handler *ctrl_handler;
 	enum v4l2_priority	prio;
+	struct video_device_state *state;
 
 	/* Events */
 	wait_queue_head_t	wait;
#14 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Quoted 15 lines · Hans Verkuil
Quoted 9 lines · Jai Luthra

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

Quoted 5 lines

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Follow-up: if there are no plans to change/enhance the VIDIOC_TRY_FMT semantics, then I don't really see the point of this since there is no need to store this information.

Regards,

Hans

Quoted 153 lines

Regards,

Hans

Quoted 146 lines

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c |  7 +++++--
 drivers/media/v4l2-core/v4l2-fh.c  |  6 ++++++
 include/media/v4l2-dev.h           | 17 ++++++++++++++++-
 include/media/v4l2-fh.h            |  2 ++
 4 files changed, 29 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +5 -2
index 997255709448510fcd17b6de798a3df99cd7ea09..26b6b2f37ca55ce981aa17a28a875dc3cf253d9b 100644
@@ -164,7 +164,8 @@ void video_device_release_empty(struct video_device *vdev)
 EXPORT_SYMBOL(video_device_release_empty);
 
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev)
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which)
 {
 	struct video_device_state *state =
 		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
@@ -172,6 +173,7 @@ __video_device_state_alloc(struct video_device *vdev)
 	if (!state)
 		return ERR_PTR(-ENOMEM);
 
+	state->which = which;
 	state->vdev = vdev;
 
 	return state;
@@ -962,7 +964,8 @@ int __video_register_device(struct video_device *vdev,
 
 	/* state support */
 	if (test_bit(V4L2_FL_USES_STATE, &vdev->flags))
-		vdev->state = __video_device_state_alloc(vdev);
+		vdev->state = __video_device_state_alloc(vdev,
+							 VIDEO_DEVICE_STATE_ACTIVE);
 
 	/* Part 1: check device type */
 	switch (type) {
drivers/media/v4l2-core/v4l2-fh.c +6 -0
index df3ba9d4674bd25626cfcddc2d0cb28c233e3cc3..522acc0eb8401305c6893232d96d826669ab90d5 100644
@@ -38,6 +38,10 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 	INIT_LIST_HEAD(&fh->subscribed);
 	fh->sequence = -1;
 	mutex_init(&fh->subscribe_lock);
+	/* state support */
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		fh->state = __video_device_state_alloc(vdev,
+						       VIDEO_DEVICE_STATE_TRY);
 }
 EXPORT_SYMBOL_GPL(v4l2_fh_init);
 
@@ -84,6 +88,8 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
 {
 	if (fh->vdev == NULL)
 		return;
+	if (test_bit(V4L2_FL_USES_STATE, &fh->vdev->flags))
+		kfree(fh->state);
 	v4l_disable_media_source(fh->vdev);
 	v4l2_event_unsubscribe_all(fh);
 	mutex_destroy(&fh->subscribe_lock);
include/media/v4l2-dev.h +16 -1
index 57e4691ef467aa2b0782dd4b8357bd0670643293..5ca04a1674e0bf7016537e6fb461d790fc0a958f 100644
@@ -220,15 +220,28 @@ struct v4l2_file_operations {
 	int (*release) (struct file *);
 };
 
+/**
+ * enum video_device_state_whence - Video device state type
+ *
+ * @VIDEO_DEVICE_STATE_TRY: from VIDIOC_TRY_xxx, for negotiation only
+ * @VIDEO_DEVICE_STATE_ACTIVE: from VIDIOC_S_xxx, applied to the device
+ */
+enum video_device_state_whence {
+	VIDEO_DEVICE_STATE_TRY = 0,
+	VIDEO_DEVICE_STATE_ACTIVE = 1,
+};
+
 /**
  * struct video_device_state - Used for storing video device state information.
  *
  * @fmt: Format of the capture stream
  * @vdev: Pointer to video device
+ * @which: State type (from enum video_device_state_whence)
  */
 struct video_device_state {
 	struct v4l2_format fmt;
 	struct video_device *vdev;
+	enum video_device_state_whence which;
 };
 
 /*
@@ -568,13 +581,15 @@ static inline int video_is_registered(struct video_device *vdev)
 /** __video_device_state_alloc - allocate video device state structure
  *
  * @vdev: pointer to struct video_device
+ * @which: type of video device state (from enum video_device_state_whence)
  *
  * .. note::
  *
  *	This function is meant to be used only inside the V4L2 core.
  */
 struct video_device_state *
-__video_device_state_alloc(struct video_device *vdev);
+__video_device_state_alloc(struct video_device *vdev,
+			   enum video_device_state_whence which);
 
 /** __video_device_state_free - free video device state structure
  *
include/media/v4l2-fh.h +2 -0
index aad4b3689d7ea191978f24ce24d24cd2e73636b6..55455704a98d0785d0a3418b8a43d7363b7c8aa2 100644
@@ -28,6 +28,7 @@ struct v4l2_ctrl_handler;
  * @vdev: pointer to &struct video_device
  * @ctrl_handler: pointer to &struct v4l2_ctrl_handler
  * @prio: priority of the file handler, as defined by &enum v4l2_priority
+ * @state: try state used for format negotiation on the video device
  *
  * @wait: event' s wait queue
  * @subscribe_lock: serialise changes to the subscribed list; guarantee that
@@ -44,6 +45,7 @@ struct v4l2_fh {
 	struct video_device	*vdev;
 	struct v4l2_ctrl_handler *ctrl_handler;
 	enum v4l2_priority	prio;
+	struct video_device_state *state;
 
 	/* Events */
 	wait_queue_head_t	wait;
author
#15 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Hi Hans,

Quoting Hans Verkuil (2025-09-22 13:28:26)

Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Jai Luthra
Quoted 9 lines

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

Quoted 4 lines
Quoted 4 lines

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

Yes, the v4l2 format sent with VIDIOC_TRY_FMT is currently not stored by the drivers, but simply modified and returned back to userspace. From the userspace point of view, that should still work the same way with this series.

The drivers will get access to the correct state (active) for internal use through framework helpers (that will be introduced in next revision), so the try state doesn't have any real "use" today.

Quoted 9 lines
Quoted 5 lines

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Follow-up: if there are no plans to change/enhance the VIDIOC_TRY_FMT semantics, then I don't really see the point of this since there is no need to store this information.

There are no plans to change the userspace side of this. The main motivation to allocate and keep a try state in the framework is to simplify the driver implementation. A single function can serve as both s_fmt and try_fmt ioctl handler, and operate on the passed state argument without caring if it will be applied on the device or just for negotiation.

In future, drivers may subclass the state with their device specific data, so that nothing tied to the hardware state is stored in the driver structures directly, but I don't see why drivers will need to inspect TRY formats.

Quoted 10 lines

Regards,

Hans

Quoted 5 lines

Regards,

Hans

Thanks,
Jai

[snip]

#16 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Quoted 45 lines · Jai Luthra

Hi Hans,

Quoting Hans Verkuil (2025-09-22 13:28:26)

Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Jai Luthra
Quoted 9 lines

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

Quoted 4 lines
Quoted 4 lines

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

Yes, the v4l2 format sent with VIDIOC_TRY_FMT is currently not stored by the drivers, but simply modified and returned back to userspace. From the userspace point of view, that should still work the same way with this series.

The drivers will get access to the correct state (active) for internal use through framework helpers (that will be introduced in next revision), so the try state doesn't have any real "use" today.

Quoted 9 lines
Quoted 5 lines

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Follow-up: if there are no plans to change/enhance the VIDIOC_TRY_FMT semantics, then I don't really see the point of this since there is no need to store this information.

There are no plans to change the userspace side of this. The main motivation to allocate and keep a try state in the framework is to simplify the driver implementation. A single function can serve as both s_fmt and try_fmt ioctl handler, and operate on the passed state argument without caring if it will be applied on the device or just for negotiation.

Quoted 4 lines

In future, drivers may subclass the state with their device specific data, so that nothing tied to the hardware state is stored in the driver structures directly, but I don't see why drivers will need to inspect TRY formats.

I think having an unused try state is a bad idea and really confusing.

Especially because for subdevices the try state is actually used, so for normal devices you would automatically expect the same thing when you see a try state.

You should reconsider this approach.

Regards,

Hans

maintainer
#17 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Hi Hans

Quoted 46 lines · Hans Verkuil
Quoted 45 lines · Jai Luthra

Hi Hans,

Quoting Hans Verkuil (2025-09-22 13:28:26)

Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Jai Luthra
Quoted 9 lines

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

Quoted 4 lines
Quoted 4 lines

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

Yes, the v4l2 format sent with VIDIOC_TRY_FMT is currently not stored by the drivers, but simply modified and returned back to userspace. From the userspace point of view, that should still work the same way with this series.

The drivers will get access to the correct state (active) for internal use through framework helpers (that will be introduced in next revision), so the try state doesn't have any real "use" today.

Quoted 9 lines
Quoted 5 lines

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Follow-up: if there are no plans to change/enhance the VIDIOC_TRY_FMT semantics, then I don't really see the point of this since there is no need to store this information.

There are no plans to change the userspace side of this. The main motivation to allocate and keep a try state in the framework is to simplify the driver implementation. A single function can serve as both s_fmt and try_fmt ioctl handler, and operate on the passed state argument without caring if it will be applied on the device or just for negotiation.

Quoted 8 lines
Quoted 4 lines

In future, drivers may subclass the state with their device specific data, so that nothing tied to the hardware state is stored in the driver structures directly, but I don't see why drivers will need to inspect TRY formats.

I think having an unused try state is a bad idea and really confusing.

Especially because for subdevices the try state is actually used, so

I might have missed where. TRY formats on subdev sink pads influence TRY formats on the source pads, are there other usages I might be overlooking ?

Quoted 4 lines

for normal devices you would automatically expect the same thing when you see a try state.

You should reconsider this approach.

The 'try' state will be stored in the v4l2_fh and won't be accessible to userspace.

Drivers instead, might accumulate the result of multiple TRY_FMT calls into the state stored in the v4l2_fh incrementally. Is this a concern for you ?

I still think having a single implementation for s_fmt and try_fmt is a win for drivers, even if the try state are now effectively stored somewhere.

Thanks
j

Quoted 4 lines

Regards,

Hans

#18 lore raw

Re: [PATCH v2 02/10] media: v4l2-dev: Add support for try state

Quoted 54 lines · Jacopo Mondi

Hi Hans

Quoted 51 lines · Hans Verkuil
Quoted 49 lines · Jai Luthra

Hi Hans,

Quoting Hans Verkuil (2025-09-22 13:28:26)

Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Jai Luthra
Quoted 9 lines

Format negotiation performed via the TRY_FMT ioctl should only affect the temporary context of a specific filehandle, not the active state stored in the video device structure. To support this distinction, we need separate storage for try and active states.

Introduce an enum to distinguish between these two state types and store the try state in struct v4l2_fh instead of the video device structure. The try state is allocated during file handle initialization in v4l2_fh_init() and released in v4l2_fh_exit().

Quoted 4 lines
Quoted 4 lines

There is a major difference between TRY in video devices and TRY in subdev
devices: TRY for video devices is not persistent, i.e. it doesn't need to be stored anywhere since nobody will be using that information.

Yes, the v4l2 format sent with VIDIOC_TRY_FMT is currently not stored by the drivers, but simply modified and returned back to userspace. From the userspace point of view, that should still work the same way with this series.

The drivers will get access to the correct state (active) for internal use through framework helpers (that will be introduced in next revision), so the try state doesn't have any real "use" today.

Quoted 9 lines
Quoted 5 lines

If the plan is to change that in later patch series, then that should be very clearly stated. And I think I would need to know the details of those future plans before I can OK this.

So how is this try state intended to be used in the future?

Follow-up: if there are no plans to change/enhance the VIDIOC_TRY_FMT semantics, then I don't really see the point of this since there is no need to store this information.

There are no plans to change the userspace side of this. The main motivation to allocate and keep a try state in the framework is to simplify the driver implementation. A single function can serve as both s_fmt and try_fmt ioctl handler, and operate on the passed state argument without caring if it will be applied on the device or just for negotiation.

In future, drivers may subclass the state with their device specific data, so that nothing tied to the hardware state is stored in the driver structures directly, but I don't see why drivers will need to inspect TRY formats.

Quoted 7 lines
Quoted 3 lines

I think having an unused try state is a bad idea and really confusing.

Especially because for subdevices the try state is actually used, so

I might have missed where. TRY formats on subdev sink pads influence TRY formats on the source pads, are there other usages I might be overlooking ?

That's the main one. But also that the TRY format for a subdev filehandle is persistent, i.e. you can query it later.

For video devices this is not stored, i.e. there is no G_TRY_FMT equivalent. TRY_FMT takes the format, it validates it and returns it, but it is not stored anywhere.

Quoted 11 lines
Quoted 4 lines

for normal devices you would automatically expect the same thing when you see a try state.

You should reconsider this approach.

The 'try' state will be stored in the v4l2_fh and won't be accessible to userspace.

Drivers instead, might accumulate the result of multiple TRY_FMT calls into the state stored in the v4l2_fh incrementally. Is this a concern for you ?

Basically the try state would be a scratch state, it's not used for anything else. I think it is very confusing keeping it.

Quoted 4 lines

I still think having a single implementation for s_fmt and try_fmt is a win for drivers, even if the try state are now effectively stored somewhere.

In a properly written driver s_fmt will call try_fmt first to validate the given format, then use that format to actually program the hardware.

Unfortunately, a lot of drivers have duplicate format validation code for both try_fmt and s_fmt (hopefully, but not always, doing the same validation).

I think this is partially historic. When the vidioc_g/s/try_vid_cap etc. ops were introduced, drivers had to be converted as well. And if memory serves often drivers handled TRY and S_FMT in a single function, and that now had to be split up, so I suspect that in quite a few cases the code was simply duplicated.

It's a long time ago though, so I may be wrong about that.

Also, older drivers do not always support TRY_FMT. Although I'm not sure how many of such drivers remain.

Regards,

Hans

Quoted 8 lines

Thanks
j

Quoted 4 lines

Regards,

Hans

author
#19 lore raw

PATCH v2 3/10 media: v4l2-dev: Add callback for initializing video device state

In reply to Jai Luthra

Drivers may need to initialize the video device state with default values, such as setting a default pixelformat and resolution.

Introduce an optional callback that drivers can populate. The framework calls this callback during state allocation to allow driver-specific initialization.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 13 +++++++++++++
 include/media/v4l2-dev.h           | 11 +++++++++++
 2 files changed, 24 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +13 -0
index 26b6b2f37ca55ce981aa17a28a875dc3cf253d9b..dff23c6a0b56fb3d29e1c04e386bb445fa8773bb 100644
@@ -169,6 +169,7 @@ __video_device_state_alloc(struct video_device *vdev,
 {
 	struct video_device_state *state =
 		kzalloc(sizeof(struct video_device_state), GFP_KERNEL);
+	int ret;
 
 	if (!state)
 		return ERR_PTR(-ENOMEM);
@@ -176,7 +177,19 @@ __video_device_state_alloc(struct video_device *vdev,
 	state->which = which;
 	state->vdev = vdev;
 
+	if (vdev->vdev_ops && vdev->vdev_ops->init_state) {
+		ret = vdev->vdev_ops->init_state(state);
+
+		if (ret)
+			goto err;
+	}
+
 	return state;
+
+err:
+	kfree(state);
+
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(__video_device_state_alloc);
 
include/media/v4l2-dev.h +11 -0
index 5ca04a1674e0bf7016537e6fb461d790fc0a958f..d327be16f6def70554a7d92d10436a29384ae32a 100644
@@ -244,6 +244,15 @@ struct video_device_state {
 	enum video_device_state_whence which;
 };
 
+/**
+ * struct video_device_internal_ops - Callbacks for video device management.
+ *
+ * @init_state: pointer to a function that initializes the video device state.
+ */
+struct video_device_internal_ops {
+	int (*init_state)(struct video_device_state *state);
+};
+
 /*
  * Newer version of video_device, handled by videodev2.c
  *	This version moves redundant code from video device code to
@@ -284,6 +293,7 @@ struct video_device_state {
  *
  * @release: video device release() callback
  * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks
+ * @vdev_ops: pointer to &struct video_device_internal_ops
  *
  * @valid_ioctls: bitmap with the valid ioctls for this device
  * @lock: pointer to &struct mutex serialization lock
@@ -336,6 +346,7 @@ struct video_device {
 	/* callbacks */
 	void (*release)(struct video_device *vdev);
 	const struct v4l2_ioctl_ops *ioctl_ops;
+	const struct video_device_internal_ops *vdev_ops;
 	DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
 
 	struct mutex *lock;
Signature · 1 line
2.51.0
author
#20 lore raw

PATCH v2 4/10 media: v4l2-dev: Add helpers to get current format from the state

In reply to Jai Luthra

Add a helper function that drivers can call to retrieve the current v4l2_format stored in a video device state for internal use.

Additionally, provide a G_FMT ioctl implementation that drivers can use instead of writing their own when the format is stored in the active state.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 23 +++++++++++++++++++++++
 include/media/v4l2-dev.h           | 18 ++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +23 -0
index dff23c6a0b56fb3d29e1c04e386bb445fa8773bb..2606077538be0e83032c6ae8956c1d67da0d0c5d 100644
@@ -199,6 +199,29 @@ void __video_device_state_free(struct video_device_state *state)
 }
 EXPORT_SYMBOL_GPL(__video_device_state_free);
 
+struct v4l2_format *video_device_state_get_fmt(struct video_device_state *state)
+{
+	if (WARN_ON_ONCE(!state))
+		return NULL;
+
+	return &state->fmt;
+}
+EXPORT_SYMBOL_GPL(video_device_state_get_fmt);
+
+int video_device_g_fmt(struct file *file, void *priv, struct v4l2_format *fmt)
+{
+	struct video_device_state *state = priv;
+	struct v4l2_format *vfmt = video_device_state_get_fmt(state);
+
+	if (!vfmt)
+		return -EINVAL;
+
+	*fmt = *vfmt;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(video_device_g_fmt);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
include/media/v4l2-dev.h +18 -0
index d327be16f6def70554a7d92d10436a29384ae32a..b5312823fbff9c236d4394d48fa9a14412b17c68 100644
@@ -612,6 +612,24 @@ __video_device_state_alloc(struct video_device *vdev,
  */
 void __video_device_state_free(struct video_device_state *state);
 
+/**
+ * video_device_state_get_fmt - get current v4l2_format.
+ *
+ * @state: pointer to struct video_device_state
+ */
+struct v4l2_format *
+video_device_state_get_fmt(struct video_device_state *state);
+
+/**
+ * video_device_g_fmt - fill v4l2_format from the state.
+ *
+ * @file: pointer to struct file
+ * @state: pointer to struct video_device_state
+ * @format: pointer to struct v4l2_format
+ */
+int video_device_g_fmt(struct file *file, void *priv,
+		       struct v4l2_format *format);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
Signature · 1 line
2.51.0
#21 lore raw

Re: [PATCH v2 04/10] media: v4l2-dev: Add helpers to get current format from the state

Quoted 33 lines · Jai Luthra

Add a helper function that drivers can call to retrieve the current v4l2_format stored in a video device state for internal use.

Additionally, provide a G_FMT ioctl implementation that drivers can use instead of writing their own when the format is stored in the active state.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 23 +++++++++++++++++++++++
 include/media/v4l2-dev.h           | 18 ++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +3 -0
index dff23c6a0b56fb3d29e1c04e386bb445fa8773bb..2606077538be0e83032c6ae8956c1d67da0d0c5d 100644
@@ -199,6 +199,29 @@ void __video_device_state_free(struct video_device_state *state)
 }
 EXPORT_SYMBOL_GPL(__video_device_state_free);
 
+struct v4l2_format *video_device_state_get_fmt(struct video_device_state *state)
+{
+	if (WARN_ON_ONCE(!state))

drivers/media/v4l2-core/v4l2-dev.c void __video_device_state_free(struct video_device_state *state) · line 214

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+		return NULL;
+
+	return &state->fmt;
+}
+EXPORT_SYMBOL_GPL(video_device_state_get_fmt);
+
+int video_device_g_fmt(struct file *file, void *priv, struct v4l2_format *fmt)
+{
+	struct video_device_state *state = priv;
+	struct v4l2_format *vfmt = video_device_state_get_fmt(state);

Obviously, if multiple format types are stored in state (e.g. video capture and output), then this code needs to pick the right format based on fmt->type.

I would also suggest moving this to v4l2-common.c and renaming it to v4l2_g_fmt, consistent with other helpers there (v4l2_g/s_parm_cap).

Regards,

Hans

Quoted 43 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+
+	if (!vfmt)
+		return -EINVAL;
+
+	*fmt = *vfmt;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(video_device_g_fmt);
+
 static inline void video_get(struct video_device *vdev)
 {
 	get_device(&vdev->dev);
include/media/v4l2-dev.h +18 -0
index d327be16f6def70554a7d92d10436a29384ae32a..b5312823fbff9c236d4394d48fa9a14412b17c68 100644
@@ -612,6 +612,24 @@ __video_device_state_alloc(struct video_device *vdev,
  */
 void __video_device_state_free(struct video_device_state *state);
 
+/**
+ * video_device_state_get_fmt - get current v4l2_format.
+ *
+ * @state: pointer to struct video_device_state
+ */
+struct v4l2_format *
+video_device_state_get_fmt(struct video_device_state *state);
+
+/**
+ * video_device_g_fmt - fill v4l2_format from the state.
+ *
+ * @file: pointer to struct file
+ * @state: pointer to struct video_device_state
+ * @format: pointer to struct v4l2_format
+ */
+int video_device_g_fmt(struct file *file, void *priv,
+		       struct v4l2_format *format);
+
 /**
  * v4l2_debugfs_root - returns the dentry of the top-level "v4l2" debugfs dir
  *
author
#22 lore raw

Re: [PATCH v2 04/10] media: v4l2-dev: Add helpers to get current format from the state

Quoting Hans Verkuil (2025-09-22 13:36:59)

Quoted 48 lines · Jai Luthra
Quoted 33 lines

Add a helper function that drivers can call to retrieve the current v4l2_format stored in a video device state for internal use.

Additionally, provide a G_FMT ioctl implementation that drivers can use instead of writing their own when the format is stored in the active state.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-dev.c | 23 +++++++++++++++++++++++
 include/media/v4l2-dev.h           | 18 ++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/media/v4l2-core/v4l2-dev.c +3 -0
index dff23c6a0b56fb3d29e1c04e386bb445fa8773bb..2606077538be0e83032c6ae8956c1d67da0d0c5d 100644
@@ -199,6 +199,29 @@ void __video_device_state_free(struct video_device_state *state)
 }
 EXPORT_SYMBOL_GPL(__video_device_state_free);
 
+struct v4l2_format *video_device_state_get_fmt(struct video_device_state *state)
+{
+     if (WARN_ON_ONCE(!state))

drivers/media/v4l2-core/v4l2-dev.c void __video_device_state_free(struct video_device_state *state) · line 214

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+             return NULL;
+
+     return &state->fmt;
+}
+EXPORT_SYMBOL_GPL(video_device_state_get_fmt);
+
+int video_device_g_fmt(struct file *file, void *priv, struct v4l2_format *fmt)
+{
+     struct video_device_state *state = priv;
+     struct v4l2_format *vfmt = video_device_state_get_fmt(state);

Obviously, if multiple format types are stored in state (e.g. video capture and output), then this code needs to pick the right format based on fmt->type.

Quoted 2 lines

I would also suggest moving this to v4l2-common.c and renaming it to v4l2_g_fmt, consistent with other helpers there (v4l2_g/s_parm_cap).

Good catch, will fix in next revision.

Quoted 5 lines

Regards,

Hans

Quoted 10 lines

drivers/media/v4l2-core/v4l2-dev.c void __video_device_state_free(struct video_device_state *state) · line 224

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+
+     if (!vfmt)
+             return -EINVAL;
+
+     *fmt = *vfmt;
+
+     return 0;
+}
+EXPORT_SYMBOL_GPL(video_device_g_fmt);
+

Thanks,
Jai

[snip]

author
#23 lore raw

PATCH v2 5/10 media: v4l2-ioctl: Add video_device_state argument to v4l2 ioctl wrappers

In reply to Jai Luthra

Add a third argument to all v4l2 ioctl wrappers to pass struct video_device_state * directly, replacing the previous opaque pointer approach.

Currently, this argument is populated with NULL since existing driver hooks still expect a void *priv argument. This will be addressed in a subsequent patch.

Most changes to the ioctl wrappers were generated using the following Coccinelle semantic patch:

@ioctl@
identifier v4l2_ioctls;
identifier ioctl;
identifier fn;
identifier debug;
expression flags;
@@

struct v4l2_ioctl_info v4l2_ioctls[] = {
	...,
	IOCTL_INFO(ioctl, fn, debug, flags),
	...,
};

@depends on ioctl@
identifier ioctl.fn;
identifier ops;
identifier file;
identifier arg;
identifier handler;
expression list args;
@@
-int fn(const struct v4l2_ioctl_ops *ops, struct file *file, void *arg) +int fn(const struct v4l2_ioctl_ops *ops, struct file *file,
+ struct video_device_state *state, void *arg)

{
	<...
-	ops->handler(file, NULL, args)
+	ops->handler(file, state, args)
	...>
}

Manual changes were made to handle calls to v4l_[gs]_selection, update the v4l2_ioctl_info structure definition and macros, fix argument wrapping in some function definitions, and handle the common function pointer in v4l2_ioctl_info.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-ioctl.c | 360 ++++++++++++++++++-----------------
 1 file changed, 186 insertions(+), 174 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +186 -174
index 01cf52c3ea33e1a01e1b306036ba4e57ef5c95d0..644f06521673ff7ce5b194335d50f0e375ca7f51 100644
@@ -1090,7 +1090,7 @@ static void v4l_sanitize_format(struct v4l2_format *fmt)
 }
 
 static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_capability *cap = (struct v4l2_capability *)arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1103,7 +1103,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	media_set_bus_info(cap->bus_info, sizeof(cap->bus_info),
 			   vfd->dev_parent);
 
-	ret = ops->vidioc_querycap(file, NULL, cap);
+	ret = ops->vidioc_querycap(file, state, cap);
 
 	/*
 	 * Drivers must not change device_caps, so check for this and
@@ -1124,7 +1124,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1133,11 +1133,11 @@ static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_input(file, NULL, arg);
+	return ops->vidioc_g_input(file, state, arg);
 }
 
 static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1146,11 +1146,11 @@ static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_output(file, NULL, arg);
+	return ops->vidioc_g_output(file, state, arg);
 }
 
 static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -1162,22 +1162,22 @@ static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_input(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_input(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_s_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_output(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_output(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	u32 *p = arg;
@@ -1188,7 +1188,7 @@ static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	struct v4l2_fh *vfh;
@@ -1200,7 +1200,7 @@ static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_input *p = arg;
@@ -1222,11 +1222,11 @@ static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_input(file, NULL, p);
+	return ops->vidioc_enum_input(file, state, p);
 }
 
 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_output *p = arg;
@@ -1248,7 +1248,7 @@ static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_output(file, NULL, p);
+	return ops->vidioc_enum_output(file, state, p);
 }
 
 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
@@ -1588,7 +1588,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 }
 
 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vdev = video_devdata(file);
 	struct v4l2_fmtdesc *p = arg;
@@ -1618,12 +1618,12 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_overlay(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_overlay(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
@@ -1635,27 +1635,27 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_out))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_out))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_out))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_out(file, state, arg);
 		break;
 	}
 	if (ret == 0)
@@ -1679,7 +1679,7 @@ static void v4l_pix_format_touch(struct v4l2_pix_format *p)
 }
 
 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1695,50 +1695,50 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_g_fmt_vid_cap))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
 			v4l_pix_format_touch(&p->fmt.pix);
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-		return ops->vidioc_g_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-		return ops->vidioc_g_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_g_fmt_vid_out))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-		return ops->vidioc_g_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-		return ops->vidioc_g_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
-		return ops->vidioc_g_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
-		return ops->vidioc_g_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
-		return ops->vidioc_g_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
-		return ops->vidioc_g_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1758,7 +1758,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_s_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1771,7 +1771,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
 			break;
@@ -1779,22 +1779,22 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1805,7 +1805,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
 			break;
@@ -1813,43 +1813,43 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1866,7 +1866,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_try_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1879,7 +1879,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
 			break;
@@ -1887,22 +1887,22 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1913,7 +1913,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
 			break;
@@ -1921,55 +1921,55 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_streamon(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamon(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamon(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamoff(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamoff(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1977,14 +1977,14 @@ static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	err = ops->vidioc_g_tuner(file, NULL, p);
+	err = ops->vidioc_g_tuner(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1995,11 +1995,11 @@ static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return ret;
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_s_tuner(file, NULL, p);
+	return ops->vidioc_s_tuner(file, state, p);
 }
 
-static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2008,14 +2008,14 @@ static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	err = ops->vidioc_g_modulator(file, NULL, p);
+	err = ops->vidioc_g_modulator(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
-static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2023,11 +2023,11 @@ static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	return ops->vidioc_s_modulator(file, NULL, p);
+	return ops->vidioc_s_modulator(file, state, p);
 }
 
-static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency *p = arg;
@@ -2037,11 +2037,11 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
 	else
 		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_g_frequency(file, NULL, p);
+	return ops->vidioc_g_frequency(file, state, p);
 }
 
-static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_frequency *p = arg;
@@ -2060,11 +2060,11 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
 		if (type != p->type)
 			return -EINVAL;
 	}
-	return ops->vidioc_s_frequency(file, NULL, p);
+	return ops->vidioc_s_frequency(file, state, p);
 }
 
 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_standard *p = arg;
@@ -2073,7 +2073,7 @@ static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id id = *(v4l2_std_id *)arg, norm;
@@ -2087,11 +2087,11 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -EINVAL;
 
 	/* Calls the specific handler */
-	return ops->vidioc_s_std(file, NULL, norm);
+	return ops->vidioc_s_std(file, state, norm);
 }
 
 static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id *p = arg;
@@ -2109,11 +2109,12 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
 	 * their efforts to improve the standards detection.
 	 */
 	*p = vfd->tvnorms;
-	return ops->vidioc_querystd(file, NULL, arg);
+	return ops->vidioc_querystd(file, state, arg);
 }
 
 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_hw_freq_seek *p = arg;
@@ -2131,26 +2132,26 @@ static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
 		V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
 	if (p->type != type)
 		return -EINVAL;
-	return ops->vidioc_s_hw_freq_seek(file, NULL, p);
+	return ops->vidioc_s_hw_freq_seek(file, state, p);
 }
 
 static int v4l_s_fbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_framebuffer *p = arg;
 
 	p->base = NULL;
-	return ops->vidioc_s_fbuf(file, NULL, p);
+	return ops->vidioc_s_fbuf(file, state, p);
 }
 
 static int v4l_overlay(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_overlay(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_overlay(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_requestbuffers *p = arg;
@@ -2165,38 +2166,38 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		p->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	return ops->vidioc_reqbufs(file, NULL, p);
+	return ops->vidioc_reqbufs(file, state, p);
 }
 
 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_querybuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_querybuf(file, state, p);
 }
 
 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *arg)
+		    struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_qbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_qbuf(file, state, p);
 }
 
 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_dqbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_dqbuf(file, state, p);
 }
 
-static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_create_buffers *create = arg;
@@ -2213,7 +2214,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		create->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	ret = ops->vidioc_create_bufs(file, NULL, create);
+	ret = ops->vidioc_create_bufs(file, state, create);
 
 	if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
 	    create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -2222,28 +2223,28 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	return ret;
 }
 
-static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *b = arg;
 	int ret = check_fmt(file, b->type);
 
-	return ret ? ret : ops->vidioc_prepare_buf(file, NULL, b);
+	return ret ? ret : ops->vidioc_prepare_buf(file, state, b);
 }
 
-static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_remove_buffers *remove = arg;
 
 	if (ops->vidioc_remove_bufs)
-		return ops->vidioc_remove_bufs(file, NULL, remove);
+		return ops->vidioc_remove_bufs(file, state, remove);
 
 	return -ENOTTY;
 }
 
 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_streamparm *p = arg;
@@ -2253,20 +2254,20 @@ static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (ret)
 		return ret;
 	if (ops->vidioc_g_parm)
-		return ops->vidioc_g_parm(file, NULL, p);
+		return ops->vidioc_g_parm(file, state, p);
 	if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
 	    p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
 		return -EINVAL;
 	if (vfd->device_caps & V4L2_CAP_READWRITE)
 		p->parm.capture.readbuffers = 2;
-	ret = ops->vidioc_g_std(file, NULL, &std);
+	ret = ops->vidioc_g_std(file, state, &std);
 	if (ret == 0)
 		v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe);
 	return ret;
 }
 
 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_streamparm *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2286,11 +2287,11 @@ static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->parm.capture.extendedmode = 0;
 		p->parm.capture.capturemode &= V4L2_MODE_HIGHQUALITY;
 	}
-	return ops->vidioc_s_parm(file, NULL, p);
+	return ops->vidioc_s_parm(file, state, p);
 }
 
 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl qec = {};
@@ -2307,7 +2308,7 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	/* Simulate query_ext_ctr using query_ctrl. */
 	qec.id = p->id;
-	ret = ops->vidioc_query_ext_ctrl(file, NULL, &qec);
+	ret = ops->vidioc_query_ext_ctrl(file, state, &qec);
 	if (ret)
 		return ret;
 	v4l2_query_ext_ctrl_to_v4l2_queryctrl(p, &qec);
@@ -2315,7 +2316,8 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl *p = arg;
@@ -2326,12 +2328,12 @@ static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
 	if (vfd->ctrl_handler)
 		return v4l2_query_ext_ctrl(vfd->ctrl_handler, p);
 	if (ops->vidioc_query_ext_ctrl)
-		return ops->vidioc_query_ext_ctrl(file, NULL, p);
+		return ops->vidioc_query_ext_ctrl(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_querymenu *p = arg;
@@ -2342,12 +2344,12 @@ static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->ctrl_handler)
 		return v4l2_querymenu(vfd->ctrl_handler, p);
 	if (ops->vidioc_querymenu)
-		return ops->vidioc_querymenu(file, NULL, p);
+		return ops->vidioc_querymenu(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2368,7 +2370,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.id = p->id;
 	ctrl.value = p->value;
 	if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) {
-		int ret = ops->vidioc_g_ext_ctrls(file, NULL, &ctrls);
+		int ret = ops->vidioc_g_ext_ctrls(file, state, &ctrls);
 
 		if (ret == 0)
 			p->value = ctrl.value;
@@ -2378,7 +2380,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2401,13 +2403,13 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.value = p->value;
 	if (!check_ext_ctrls(&ctrls, VIDIOC_S_CTRL))
 		return -EINVAL;
-	ret = ops->vidioc_s_ext_ctrls(file, NULL, &ctrls);
+	ret = ops->vidioc_s_ext_ctrls(file, state, &ctrls);
 	p->value = ctrl.value;
 	return ret;
 }
 
-static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2423,11 +2425,11 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_g_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ?
-				ops->vidioc_g_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_g_ext_ctrls(file, state, p) : -EINVAL;
 }
 
-static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2443,11 +2445,12 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_s_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ?
-				ops->vidioc_s_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_s_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			     struct file *file, void *arg)
+			     struct file *file,
+			     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2463,7 +2466,7 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_try_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ?
-			ops->vidioc_try_ext_ctrls(file, NULL, p) : -EINVAL;
+			ops->vidioc_try_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 /*
@@ -2475,8 +2478,8 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  * restore it afterwards. This way applications can use either buffer
  * type and drivers don't need to check for both.
  */
-static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2486,13 +2489,13 @@ static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_g_selection(file, NULL, p);
+	ret = ops->vidioc_g_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
-static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2502,13 +2505,13 @@ static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_s_selection(file, NULL, p);
+	ret = ops->vidioc_s_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2529,7 +2532,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 
 	/* copying results to old structure on success */
 	if (!ret)
@@ -2538,7 +2541,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2559,11 +2562,11 @@ static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	return v4l_s_selection(ops, file, &s);
+	return v4l_s_selection(ops, file, state, &s);
 }
 
 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_cropcap *p = arg;
@@ -2587,7 +2590,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -ENOTTY;
 
 	if (ops->vidioc_g_pixelaspect)
-		ret = ops->vidioc_g_pixelaspect(file, NULL, s.type,
+		ret = ops->vidioc_g_pixelaspect(file, state, s.type,
 						&p->pixelaspect);
 
 	/*
@@ -2609,7 +2612,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS ?
 			V4L2_SEL_TGT_CROP_BOUNDS : V4L2_SEL_TGT_COMPOSE_BOUNDS;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->bounds = s.r;
@@ -2620,7 +2623,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	else
 		s.target = V4L2_SEL_TGT_CROP_DEFAULT;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->defrect = s.r;
@@ -2629,7 +2632,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -2637,7 +2640,7 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->v4l2_dev)
 		pr_info("%s: =================  START STATUS  =================\n",
 			vfd->v4l2_dev->name);
-	ret = ops->vidioc_log_status(file, NULL);
+	ret = ops->vidioc_log_status(file, state);
 	if (vfd->v4l2_dev)
 		pr_info("%s: ==================  END STATUS  ==================\n",
 			vfd->v4l2_dev->name);
@@ -2645,7 +2648,8 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct v4l2_dbg_register *p = arg;
@@ -2665,7 +2669,7 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_g_register(file, NULL, p);
+		return ops->vidioc_g_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2673,7 +2677,8 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	const struct v4l2_dbg_register *p = arg;
@@ -2693,7 +2698,7 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_s_register(file, NULL, p);
+		return ops->vidioc_s_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2701,7 +2706,8 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct video_device *vfd = video_devdata(file);
@@ -2717,7 +2723,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 			p->flags |= V4L2_CHIP_FL_READABLE;
 		strscpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
 		if (ops->vidioc_g_chip_info)
-			return ops->vidioc_g_chip_info(file, NULL, arg);
+			return ops->vidioc_g_chip_info(file, state, arg);
 		if (p->match.addr)
 			return -EINVAL;
 		return 0;
@@ -2744,7 +2750,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2752,7 +2758,8 @@ static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2760,7 +2767,8 @@ static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
-				 struct file *file, void *arg)
+				 struct file *file,
+				 struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2768,7 +2776,8 @@ static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
-				struct file *file, void *arg)
+				struct file *file,
+				struct video_device_state *state, void *arg)
 {
 	struct v4l2_sliced_vbi_cap *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2779,11 +2788,12 @@ static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
 	/* Clear up to type, everything after type is zeroed already */
 	memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
 
-	return ops->vidioc_g_sliced_vbi_cap(file, NULL, p);
+	return ops->vidioc_g_sliced_vbi_cap(file, state, p);
 }
 
 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency_band *p = arg;
@@ -2801,7 +2811,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 	}
 	if (ops->vidioc_enum_freq_bands) {
-		err = ops->vidioc_enum_freq_bands(file, NULL, p);
+		err = ops->vidioc_enum_freq_bands(file, state, p);
 		if (err != -ENOTTY)
 			return err;
 	}
@@ -2813,7 +2823,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_tuner(file, NULL, &t);
+		err = ops->vidioc_g_tuner(file, state, &t);
 		if (err)
 			return err;
 		p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2832,7 +2842,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_modulator(file, NULL, &m);
+		err = ops->vidioc_g_modulator(file, state, &m);
 		if (err)
 			return err;
 		p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2849,7 +2859,7 @@ struct v4l2_ioctl_info {
 	u32 flags;
 	const char * const name;
 	int (*func)(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *p);
+		    struct video_device_state *state, void *p);
 	void (*debug)(const void *arg, bool write_only);
 };
 
@@ -2870,7 +2880,9 @@ struct v4l2_ioctl_info {
 #define DEFINE_V4L_STUB_FUNC(_vidioc)				\
 	static int v4l_stub_ ## _vidioc(			\
 			const struct v4l2_ioctl_ops *ops,	\
-			struct file *file, void *p)		\
+			struct file *file,			\
+			struct video_device_state *state,	\
+			void *p)				\
 	{							\
 		return ops->vidioc_ ## _vidioc(file, NULL, p);	\
 	}
@@ -3126,7 +3138,7 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (info != &default_info) {
-		ret = info->func(ops, file, arg);
+		ret = info->func(ops, file, NULL, arg);
 	} else if (!ops->vidioc_default) {
 		ret = -ENOTTY;
 	} else {
Signature · 1 line
2.51.0
#24 lore raw

Re: [PATCH v2 05/10] media: v4l2-ioctl: Add video_device_state argument to v4l2 ioctl wrappers

Quoted 7 lines · Jai Luthra

Add a third argument to all v4l2 ioctl wrappers to pass struct video_device_state * directly, replacing the previous opaque pointer approach.

Currently, this argument is populated with NULL since existing driver hooks still expect a void *priv argument. This will be addressed in a subsequent patch.

There is one more occurrance of this in v4l2_compat_ioctl32.c in function ctrl_is_pointer() where vidioc_query_ext_ctrl is called.

Regards,

Hans

Quoted 1,249 lines

Most changes to the ioctl wrappers were generated using the following Coccinelle semantic patch:

@ioctl@
identifier v4l2_ioctls;
identifier ioctl;
identifier fn;
identifier debug;
expression flags;
@@

struct v4l2_ioctl_info v4l2_ioctls[] = {
	...,
	IOCTL_INFO(ioctl, fn, debug, flags),
	...,
};

@depends on ioctl@
identifier ioctl.fn;
identifier ops;
identifier file;
identifier arg;
identifier handler;
expression list args;
@@

(quoted diff) +2 -1
-int fn(const struct v4l2_ioctl_ops *ops, struct file *file, void *arg)
+int fn(const struct v4l2_ioctl_ops *ops, struct file *file,
+       struct video_device_state *state, void *arg)
{
	<...
(quoted diff) +1 -1
-	ops->handler(file, NULL, args)
+	ops->handler(file, state, args)
	...>
}

Manual changes were made to handle calls to v4l_[gs]_selection, update the v4l2_ioctl_info structure definition and macros, fix argument wrapping in some function definitions, and handle the common function pointer in v4l2_ioctl_info.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-ioctl.c | 360 ++++++++++++++++++-----------------
 1 file changed, 186 insertions(+), 174 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +186 -174
index 01cf52c3ea33e1a01e1b306036ba4e57ef5c95d0..644f06521673ff7ce5b194335d50f0e375ca7f51 100644
@@ -1090,7 +1090,7 @@ static void v4l_sanitize_format(struct v4l2_format *fmt)
 }
 
 static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_capability *cap = (struct v4l2_capability *)arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1103,7 +1103,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	media_set_bus_info(cap->bus_info, sizeof(cap->bus_info),
 			   vfd->dev_parent);
 
-	ret = ops->vidioc_querycap(file, NULL, cap);
+	ret = ops->vidioc_querycap(file, state, cap);
 
 	/*
 	 * Drivers must not change device_caps, so check for this and
@@ -1124,7 +1124,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1133,11 +1133,11 @@ static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_input(file, NULL, arg);
+	return ops->vidioc_g_input(file, state, arg);
 }
 
 static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1146,11 +1146,11 @@ static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_output(file, NULL, arg);
+	return ops->vidioc_g_output(file, state, arg);
 }
 
 static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -1162,22 +1162,22 @@ static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_input(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_input(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_s_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_output(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_output(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	u32 *p = arg;
@@ -1188,7 +1188,7 @@ static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	struct v4l2_fh *vfh;
@@ -1200,7 +1200,7 @@ static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_input *p = arg;
@@ -1222,11 +1222,11 @@ static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_input(file, NULL, p);
+	return ops->vidioc_enum_input(file, state, p);
 }
 
 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_output *p = arg;
@@ -1248,7 +1248,7 @@ static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_output(file, NULL, p);
+	return ops->vidioc_enum_output(file, state, p);
 }
 
 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
@@ -1588,7 +1588,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 }
 
 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vdev = video_devdata(file);
 	struct v4l2_fmtdesc *p = arg;
@@ -1618,12 +1618,12 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_overlay(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_overlay(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
@@ -1635,27 +1635,27 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_out))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_out))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_out))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_out(file, state, arg);
 		break;
 	}
 	if (ret == 0)
@@ -1679,7 +1679,7 @@ static void v4l_pix_format_touch(struct v4l2_pix_format *p)
 }
 
 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1695,50 +1695,50 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_g_fmt_vid_cap))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
 			v4l_pix_format_touch(&p->fmt.pix);
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-		return ops->vidioc_g_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-		return ops->vidioc_g_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_g_fmt_vid_out))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-		return ops->vidioc_g_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-		return ops->vidioc_g_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
-		return ops->vidioc_g_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
-		return ops->vidioc_g_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
-		return ops->vidioc_g_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
-		return ops->vidioc_g_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1758,7 +1758,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_s_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1771,7 +1771,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
 			break;
@@ -1779,22 +1779,22 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1805,7 +1805,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
 			break;
@@ -1813,43 +1813,43 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1866,7 +1866,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_try_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1879,7 +1879,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
 			break;
@@ -1887,22 +1887,22 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1913,7 +1913,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
 			break;
@@ -1921,55 +1921,55 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_streamon(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamon(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamon(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamoff(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamoff(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1977,14 +1977,14 @@ static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	err = ops->vidioc_g_tuner(file, NULL, p);
+	err = ops->vidioc_g_tuner(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1995,11 +1995,11 @@ static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return ret;
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_s_tuner(file, NULL, p);
+	return ops->vidioc_s_tuner(file, state, p);
 }
 
-static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2008,14 +2008,14 @@ static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	err = ops->vidioc_g_modulator(file, NULL, p);
+	err = ops->vidioc_g_modulator(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
-static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2023,11 +2023,11 @@ static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	return ops->vidioc_s_modulator(file, NULL, p);
+	return ops->vidioc_s_modulator(file, state, p);
 }
 
-static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency *p = arg;
@@ -2037,11 +2037,11 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
 	else
 		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_g_frequency(file, NULL, p);
+	return ops->vidioc_g_frequency(file, state, p);
 }
 
-static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_frequency *p = arg;
@@ -2060,11 +2060,11 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
 		if (type != p->type)
 			return -EINVAL;
 	}
-	return ops->vidioc_s_frequency(file, NULL, p);
+	return ops->vidioc_s_frequency(file, state, p);
 }
 
 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_standard *p = arg;
@@ -2073,7 +2073,7 @@ static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id id = *(v4l2_std_id *)arg, norm;
@@ -2087,11 +2087,11 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -EINVAL;
 
 	/* Calls the specific handler */
-	return ops->vidioc_s_std(file, NULL, norm);
+	return ops->vidioc_s_std(file, state, norm);
 }
 
 static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id *p = arg;
@@ -2109,11 +2109,12 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
 	 * their efforts to improve the standards detection.
 	 */
 	*p = vfd->tvnorms;
-	return ops->vidioc_querystd(file, NULL, arg);
+	return ops->vidioc_querystd(file, state, arg);
 }
 
 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_hw_freq_seek *p = arg;
@@ -2131,26 +2132,26 @@ static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
 		V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
 	if (p->type != type)
 		return -EINVAL;
-	return ops->vidioc_s_hw_freq_seek(file, NULL, p);
+	return ops->vidioc_s_hw_freq_seek(file, state, p);
 }
 
 static int v4l_s_fbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_framebuffer *p = arg;
 
 	p->base = NULL;
-	return ops->vidioc_s_fbuf(file, NULL, p);
+	return ops->vidioc_s_fbuf(file, state, p);
 }
 
 static int v4l_overlay(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_overlay(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_overlay(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_requestbuffers *p = arg;
@@ -2165,38 +2166,38 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		p->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	return ops->vidioc_reqbufs(file, NULL, p);
+	return ops->vidioc_reqbufs(file, state, p);
 }
 
 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_querybuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_querybuf(file, state, p);
 }
 
 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *arg)
+		    struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_qbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_qbuf(file, state, p);
 }
 
 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_dqbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_dqbuf(file, state, p);
 }
 
-static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_create_buffers *create = arg;
@@ -2213,7 +2214,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		create->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	ret = ops->vidioc_create_bufs(file, NULL, create);
+	ret = ops->vidioc_create_bufs(file, state, create);
 
 	if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
 	    create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -2222,28 +2223,28 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	return ret;
 }
 
-static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *b = arg;
 	int ret = check_fmt(file, b->type);
 
-	return ret ? ret : ops->vidioc_prepare_buf(file, NULL, b);
+	return ret ? ret : ops->vidioc_prepare_buf(file, state, b);
 }
 
-static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_remove_buffers *remove = arg;
 
 	if (ops->vidioc_remove_bufs)
-		return ops->vidioc_remove_bufs(file, NULL, remove);
+		return ops->vidioc_remove_bufs(file, state, remove);
 
 	return -ENOTTY;
 }
 
 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_streamparm *p = arg;
@@ -2253,20 +2254,20 @@ static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (ret)
 		return ret;
 	if (ops->vidioc_g_parm)
-		return ops->vidioc_g_parm(file, NULL, p);
+		return ops->vidioc_g_parm(file, state, p);
 	if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
 	    p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
 		return -EINVAL;
 	if (vfd->device_caps & V4L2_CAP_READWRITE)
 		p->parm.capture.readbuffers = 2;
-	ret = ops->vidioc_g_std(file, NULL, &std);
+	ret = ops->vidioc_g_std(file, state, &std);
 	if (ret == 0)
 		v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe);
 	return ret;
 }
 
 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_streamparm *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2286,11 +2287,11 @@ static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->parm.capture.extendedmode = 0;
 		p->parm.capture.capturemode &= V4L2_MODE_HIGHQUALITY;
 	}
-	return ops->vidioc_s_parm(file, NULL, p);
+	return ops->vidioc_s_parm(file, state, p);
 }
 
 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl qec = {};
@@ -2307,7 +2308,7 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	/* Simulate query_ext_ctr using query_ctrl. */
 	qec.id = p->id;
-	ret = ops->vidioc_query_ext_ctrl(file, NULL, &qec);
+	ret = ops->vidioc_query_ext_ctrl(file, state, &qec);
 	if (ret)
 		return ret;
 	v4l2_query_ext_ctrl_to_v4l2_queryctrl(p, &qec);
@@ -2315,7 +2316,8 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl *p = arg;
@@ -2326,12 +2328,12 @@ static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
 	if (vfd->ctrl_handler)
 		return v4l2_query_ext_ctrl(vfd->ctrl_handler, p);
 	if (ops->vidioc_query_ext_ctrl)
-		return ops->vidioc_query_ext_ctrl(file, NULL, p);
+		return ops->vidioc_query_ext_ctrl(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_querymenu *p = arg;
@@ -2342,12 +2344,12 @@ static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->ctrl_handler)
 		return v4l2_querymenu(vfd->ctrl_handler, p);
 	if (ops->vidioc_querymenu)
-		return ops->vidioc_querymenu(file, NULL, p);
+		return ops->vidioc_querymenu(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2368,7 +2370,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.id = p->id;
 	ctrl.value = p->value;
 	if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) {
-		int ret = ops->vidioc_g_ext_ctrls(file, NULL, &ctrls);
+		int ret = ops->vidioc_g_ext_ctrls(file, state, &ctrls);
 
 		if (ret == 0)
 			p->value = ctrl.value;
@@ -2378,7 +2380,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2401,13 +2403,13 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.value = p->value;
 	if (!check_ext_ctrls(&ctrls, VIDIOC_S_CTRL))
 		return -EINVAL;
-	ret = ops->vidioc_s_ext_ctrls(file, NULL, &ctrls);
+	ret = ops->vidioc_s_ext_ctrls(file, state, &ctrls);
 	p->value = ctrl.value;
 	return ret;
 }
 
-static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2423,11 +2425,11 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_g_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ?
-				ops->vidioc_g_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_g_ext_ctrls(file, state, p) : -EINVAL;
 }
 
-static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2443,11 +2445,12 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_s_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ?
-				ops->vidioc_s_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_s_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			     struct file *file, void *arg)
+			     struct file *file,
+			     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2463,7 +2466,7 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_try_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ?
-			ops->vidioc_try_ext_ctrls(file, NULL, p) : -EINVAL;
+			ops->vidioc_try_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 /*
@@ -2475,8 +2478,8 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  * restore it afterwards. This way applications can use either buffer
  * type and drivers don't need to check for both.
  */
-static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2486,13 +2489,13 @@ static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_g_selection(file, NULL, p);
+	ret = ops->vidioc_g_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
-static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2502,13 +2505,13 @@ static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_s_selection(file, NULL, p);
+	ret = ops->vidioc_s_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2529,7 +2532,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 
 	/* copying results to old structure on success */
 	if (!ret)
@@ -2538,7 +2541,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2559,11 +2562,11 @@ static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	return v4l_s_selection(ops, file, &s);
+	return v4l_s_selection(ops, file, state, &s);
 }
 
 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_cropcap *p = arg;
@@ -2587,7 +2590,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -ENOTTY;
 
 	if (ops->vidioc_g_pixelaspect)
-		ret = ops->vidioc_g_pixelaspect(file, NULL, s.type,
+		ret = ops->vidioc_g_pixelaspect(file, state, s.type,
 						&p->pixelaspect);
 
 	/*
@@ -2609,7 +2612,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS ?
 			V4L2_SEL_TGT_CROP_BOUNDS : V4L2_SEL_TGT_COMPOSE_BOUNDS;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->bounds = s.r;
@@ -2620,7 +2623,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	else
 		s.target = V4L2_SEL_TGT_CROP_DEFAULT;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->defrect = s.r;
@@ -2629,7 +2632,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -2637,7 +2640,7 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->v4l2_dev)
 		pr_info("%s: =================  START STATUS  =================\n",
 			vfd->v4l2_dev->name);
-	ret = ops->vidioc_log_status(file, NULL);
+	ret = ops->vidioc_log_status(file, state);
 	if (vfd->v4l2_dev)
 		pr_info("%s: ==================  END STATUS  ==================\n",
 			vfd->v4l2_dev->name);
@@ -2645,7 +2648,8 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct v4l2_dbg_register *p = arg;
@@ -2665,7 +2669,7 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_g_register(file, NULL, p);
+		return ops->vidioc_g_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2673,7 +2677,8 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	const struct v4l2_dbg_register *p = arg;
@@ -2693,7 +2698,7 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_s_register(file, NULL, p);
+		return ops->vidioc_s_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2701,7 +2706,8 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct video_device *vfd = video_devdata(file);
@@ -2717,7 +2723,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 			p->flags |= V4L2_CHIP_FL_READABLE;
 		strscpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
 		if (ops->vidioc_g_chip_info)
-			return ops->vidioc_g_chip_info(file, NULL, arg);
+			return ops->vidioc_g_chip_info(file, state, arg);
 		if (p->match.addr)
 			return -EINVAL;
 		return 0;
@@ -2744,7 +2750,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2752,7 +2758,8 @@ static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2760,7 +2767,8 @@ static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
-				 struct file *file, void *arg)
+				 struct file *file,
+				 struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2768,7 +2776,8 @@ static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
-				struct file *file, void *arg)
+				struct file *file,
+				struct video_device_state *state, void *arg)
 {
 	struct v4l2_sliced_vbi_cap *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2779,11 +2788,12 @@ static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
 	/* Clear up to type, everything after type is zeroed already */
 	memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
 
-	return ops->vidioc_g_sliced_vbi_cap(file, NULL, p);
+	return ops->vidioc_g_sliced_vbi_cap(file, state, p);
 }
 
 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency_band *p = arg;
@@ -2801,7 +2811,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 	}
 	if (ops->vidioc_enum_freq_bands) {
-		err = ops->vidioc_enum_freq_bands(file, NULL, p);
+		err = ops->vidioc_enum_freq_bands(file, state, p);
 		if (err != -ENOTTY)
 			return err;
 	}
@@ -2813,7 +2823,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_tuner(file, NULL, &t);
+		err = ops->vidioc_g_tuner(file, state, &t);
 		if (err)
 			return err;
 		p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2832,7 +2842,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_modulator(file, NULL, &m);
+		err = ops->vidioc_g_modulator(file, state, &m);
 		if (err)
 			return err;
 		p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2849,7 +2859,7 @@ struct v4l2_ioctl_info {
 	u32 flags;
 	const char * const name;
 	int (*func)(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *p);
+		    struct video_device_state *state, void *p);
 	void (*debug)(const void *arg, bool write_only);
 };
 
@@ -2870,7 +2880,9 @@ struct v4l2_ioctl_info {
 #define DEFINE_V4L_STUB_FUNC(_vidioc)				\
 	static int v4l_stub_ ## _vidioc(			\
 			const struct v4l2_ioctl_ops *ops,	\
-			struct file *file, void *p)		\
+			struct file *file,			\
+			struct video_device_state *state,	\
+			void *p)				\
 	{							\
 		return ops->vidioc_ ## _vidioc(file, NULL, p);	\
 	}
@@ -3126,7 +3138,7 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (info != &default_info) {
-		ret = info->func(ops, file, arg);
+		ret = info->func(ops, file, NULL, arg);
 	} else if (!ops->vidioc_default) {
 		ret = -ENOTTY;
 	} else {
#25 lore raw

Re: [PATCH v2 05/10] media: v4l2-ioctl: Add video_device_state argument to v4l2 ioctl wrappers

Quoted 11 lines · Hans Verkuil
Quoted 7 lines · Jai Luthra

Add a third argument to all v4l2 ioctl wrappers to pass struct video_device_state * directly, replacing the previous opaque pointer approach.

Currently, this argument is populated with NULL since existing driver hooks still expect a void *priv argument. This will be addressed in a subsequent patch.

There is one more occurrance of this in v4l2_compat_ioctl32.c in function ctrl_is_pointer() where vidioc_query_ext_ctrl is called.

Ignore this, this doesn't apply to this patch.

Quoted 1,256 lines

Regards,

Hans

Quoted 1,249 lines

Most changes to the ioctl wrappers were generated using the following Coccinelle semantic patch:

@ioctl@
identifier v4l2_ioctls;
identifier ioctl;
identifier fn;
identifier debug;
expression flags;
@@

struct v4l2_ioctl_info v4l2_ioctls[] = {
	...,
	IOCTL_INFO(ioctl, fn, debug, flags),
	...,
};

@depends on ioctl@
identifier ioctl.fn;
identifier ops;
identifier file;
identifier arg;
identifier handler;
expression list args;
@@

(quoted diff) +2 -1
-int fn(const struct v4l2_ioctl_ops *ops, struct file *file, void *arg)
+int fn(const struct v4l2_ioctl_ops *ops, struct file *file,
+       struct video_device_state *state, void *arg)
{
	<...
(quoted diff) +1 -1
-	ops->handler(file, NULL, args)
+	ops->handler(file, state, args)
	...>
}

Manual changes were made to handle calls to v4l_[gs]_selection, update the v4l2_ioctl_info structure definition and macros, fix argument wrapping in some function definitions, and handle the common function pointer in v4l2_ioctl_info.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-ioctl.c | 360 ++++++++++++++++++-----------------
 1 file changed, 186 insertions(+), 174 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +186 -174
index 01cf52c3ea33e1a01e1b306036ba4e57ef5c95d0..644f06521673ff7ce5b194335d50f0e375ca7f51 100644
@@ -1090,7 +1090,7 @@ static void v4l_sanitize_format(struct v4l2_format *fmt)
 }
 
 static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_capability *cap = (struct v4l2_capability *)arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1103,7 +1103,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	media_set_bus_info(cap->bus_info, sizeof(cap->bus_info),
 			   vfd->dev_parent);
 
-	ret = ops->vidioc_querycap(file, NULL, cap);
+	ret = ops->vidioc_querycap(file, state, cap);
 
 	/*
 	 * Drivers must not change device_caps, so check for this and
@@ -1124,7 +1124,7 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1133,11 +1133,11 @@ static int v4l_g_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_input(file, NULL, arg);
+	return ops->vidioc_g_input(file, state, arg);
 }
 
 static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
@@ -1146,11 +1146,11 @@ static int v4l_g_output(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_g_output(file, NULL, arg);
+	return ops->vidioc_g_output(file, state, arg);
 }
 
 static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -1162,22 +1162,22 @@ static int v4l_s_input(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_input(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_input(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_s_output(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 
 	if (vfd->device_caps & V4L2_CAP_IO_MC)
 		return  *(int *)arg ? -EINVAL : 0;
 
-	return ops->vidioc_s_output(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_s_output(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	u32 *p = arg;
@@ -1188,7 +1188,7 @@ static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd;
 	struct v4l2_fh *vfh;
@@ -1200,7 +1200,7 @@ static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_input *p = arg;
@@ -1222,11 +1222,11 @@ static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_input(file, NULL, p);
+	return ops->vidioc_enum_input(file, state, p);
 }
 
 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_output *p = arg;
@@ -1248,7 +1248,7 @@ static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return 0;
 	}
 
-	return ops->vidioc_enum_output(file, NULL, p);
+	return ops->vidioc_enum_output(file, state, p);
 }
 
 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
@@ -1588,7 +1588,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 }
 
 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vdev = video_devdata(file);
 	struct v4l2_fmtdesc *p = arg;
@@ -1618,12 +1618,12 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_overlay(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_overlay(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
@@ -1635,27 +1635,27 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 		if (unlikely(!ops->vidioc_enum_fmt_vid_out))
 			break;
-		ret = ops->vidioc_enum_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_vid_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_sdr_out))
 			break;
-		ret = ops->vidioc_enum_fmt_sdr_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_sdr_out(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_cap))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_cap(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_cap(file, state, arg);
 		break;
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_enum_fmt_meta_out))
 			break;
-		ret = ops->vidioc_enum_fmt_meta_out(file, NULL, arg);
+		ret = ops->vidioc_enum_fmt_meta_out(file, state, arg);
 		break;
 	}
 	if (ret == 0)
@@ -1679,7 +1679,7 @@ static void v4l_pix_format_touch(struct v4l2_pix_format *p)
 }
 
 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1695,50 +1695,50 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_g_fmt_vid_cap))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
 			v4l_pix_format_touch(&p->fmt.pix);
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-		return ops->vidioc_g_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-		return ops->vidioc_g_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-		return ops->vidioc_g_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_g_fmt_vid_out))
 			break;
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
-		ret = ops->vidioc_g_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_g_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-		return ops->vidioc_g_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-		return ops->vidioc_g_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_g_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-		return ops->vidioc_g_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
-		return ops->vidioc_g_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
-		return ops->vidioc_g_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
-		return ops->vidioc_g_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
-		return ops->vidioc_g_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_g_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1758,7 +1758,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_s_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1771,7 +1771,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
 			break;
@@ -1779,22 +1779,22 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_s_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_s_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1805,7 +1805,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_s_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
 			break;
@@ -1813,43 +1813,43 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_s_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_s_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_s_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_s_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_s_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_s_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_s_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_s_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_s_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_format *p = arg;
 	struct video_device *vfd = video_devdata(file);
@@ -1866,7 +1866,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		if (unlikely(!ops->vidioc_try_fmt_vid_cap))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_cap(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_cap(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		if (vfd->vfl_type == VFL_TYPE_TOUCH)
@@ -1879,7 +1879,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_cap_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_cap_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
 			break;
@@ -1887,22 +1887,22 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_cap(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out))
 			break;
 		memset_after(p, 0, fmt.pix);
-		ret = ops->vidioc_try_fmt_vid_out(file, NULL, arg);
+		ret = ops->vidioc_try_fmt_vid_out(file, state, arg);
 		/* just in case the driver zeroed it again */
 		p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
 		return ret;
@@ -1913,7 +1913,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
 			memset_after(&p->fmt.pix_mp.plane_fmt[i],
 				     0, bytesperline);
-		return ops->vidioc_try_fmt_vid_out_mplane(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_mplane(file, state, arg);
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
 		if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
 			break;
@@ -1921,55 +1921,55 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->fmt.win.clips = NULL;
 		p->fmt.win.clipcount = 0;
 		p->fmt.win.bitmap = NULL;
-		return ops->vidioc_try_fmt_vid_out_overlay(file, NULL, arg);
+		return ops->vidioc_try_fmt_vid_out_overlay(file, state, arg);
 	case V4L2_BUF_TYPE_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_vbi_out))
 			break;
 		memset_after(p, 0, fmt.vbi.flags);
-		return ops->vidioc_try_fmt_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
 			break;
 		memset_after(p, 0, fmt.sliced.io_size);
-		return ops->vidioc_try_fmt_sliced_vbi_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sliced_vbi_out(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_cap))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_cap(file, state, arg);
 	case V4L2_BUF_TYPE_SDR_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_sdr_out))
 			break;
 		memset_after(p, 0, fmt.sdr.buffersize);
-		return ops->vidioc_try_fmt_sdr_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_sdr_out(file, state, arg);
 	case V4L2_BUF_TYPE_META_CAPTURE:
 		if (unlikely(!ops->vidioc_try_fmt_meta_cap))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_cap(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_cap(file, state, arg);
 	case V4L2_BUF_TYPE_META_OUTPUT:
 		if (unlikely(!ops->vidioc_try_fmt_meta_out))
 			break;
 		memset_after(p, 0, fmt.meta);
-		return ops->vidioc_try_fmt_meta_out(file, NULL, arg);
+		return ops->vidioc_try_fmt_meta_out(file, state, arg);
 	}
 	return -EINVAL;
 }
 
 static int v4l_streamon(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamon(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamon(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_streamoff(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_streamoff(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1977,14 +1977,14 @@ static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	err = ops->vidioc_g_tuner(file, NULL, p);
+	err = ops->vidioc_g_tuner(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
@@ -1995,11 +1995,11 @@ static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return ret;
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_s_tuner(file, NULL, p);
+	return ops->vidioc_s_tuner(file, state, p);
 }
 
-static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2008,14 +2008,14 @@ static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	err = ops->vidioc_g_modulator(file, NULL, p);
+	err = ops->vidioc_g_modulator(file, state, p);
 	if (!err)
 		p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
 	return err;
 }
 
-static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_modulator *p = arg;
@@ -2023,11 +2023,11 @@ static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops,
 	if (vfd->vfl_type == VFL_TYPE_RADIO)
 		p->type = V4L2_TUNER_RADIO;
 
-	return ops->vidioc_s_modulator(file, NULL, p);
+	return ops->vidioc_s_modulator(file, state, p);
 }
 
-static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency *p = arg;
@@ -2037,11 +2037,11 @@ static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
 	else
 		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 				V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-	return ops->vidioc_g_frequency(file, NULL, p);
+	return ops->vidioc_g_frequency(file, state, p);
 }
 
-static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_frequency *p = arg;
@@ -2060,11 +2060,11 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
 		if (type != p->type)
 			return -EINVAL;
 	}
-	return ops->vidioc_s_frequency(file, NULL, p);
+	return ops->vidioc_s_frequency(file, state, p);
 }
 
 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_standard *p = arg;
@@ -2073,7 +2073,7 @@ static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id id = *(v4l2_std_id *)arg, norm;
@@ -2087,11 +2087,11 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -EINVAL;
 
 	/* Calls the specific handler */
-	return ops->vidioc_s_std(file, NULL, norm);
+	return ops->vidioc_s_std(file, state, norm);
 }
 
 static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id *p = arg;
@@ -2109,11 +2109,12 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops, struct file *file,
 	 * their efforts to improve the standards detection.
 	 */
 	*p = vfd->tvnorms;
-	return ops->vidioc_querystd(file, NULL, arg);
+	return ops->vidioc_querystd(file, state, arg);
 }
 
 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_hw_freq_seek *p = arg;
@@ -2131,26 +2132,26 @@ static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
 		V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
 	if (p->type != type)
 		return -EINVAL;
-	return ops->vidioc_s_hw_freq_seek(file, NULL, p);
+	return ops->vidioc_s_hw_freq_seek(file, state, p);
 }
 
 static int v4l_s_fbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_framebuffer *p = arg;
 
 	p->base = NULL;
-	return ops->vidioc_s_fbuf(file, NULL, p);
+	return ops->vidioc_s_fbuf(file, state, p);
 }
 
 static int v4l_overlay(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
-	return ops->vidioc_overlay(file, NULL, *(unsigned int *)arg);
+	return ops->vidioc_overlay(file, state, *(unsigned int *)arg);
 }
 
 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_requestbuffers *p = arg;
@@ -2165,38 +2166,38 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		p->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	return ops->vidioc_reqbufs(file, NULL, p);
+	return ops->vidioc_reqbufs(file, state, p);
 }
 
 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-			void *arg)
+			struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_querybuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_querybuf(file, state, p);
 }
 
 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *arg)
+		    struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_qbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_qbuf(file, state, p);
 }
 
 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, struct file *file,
-		     void *arg)
+		     struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *p = arg;
 	int ret = check_fmt(file, p->type);
 
-	return ret ? ret : ops->vidioc_dqbuf(file, NULL, p);
+	return ret ? ret : ops->vidioc_dqbuf(file, state, p);
 }
 
-static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_create_buffers *create = arg;
@@ -2213,7 +2214,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS))
 		create->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS;
 
-	ret = ops->vidioc_create_bufs(file, NULL, create);
+	ret = ops->vidioc_create_bufs(file, state, create);
 
 	if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
 	    create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -2222,28 +2223,28 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
 	return ret;
 }
 
-static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_buffer *b = arg;
 	int ret = check_fmt(file, b->type);
 
-	return ret ? ret : ops->vidioc_prepare_buf(file, NULL, b);
+	return ret ? ret : ops->vidioc_prepare_buf(file, state, b);
 }
 
-static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_remove_buffers *remove = arg;
 
 	if (ops->vidioc_remove_bufs)
-		return ops->vidioc_remove_bufs(file, NULL, remove);
+		return ops->vidioc_remove_bufs(file, state, remove);
 
 	return -ENOTTY;
 }
 
 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_streamparm *p = arg;
@@ -2253,20 +2254,20 @@ static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (ret)
 		return ret;
 	if (ops->vidioc_g_parm)
-		return ops->vidioc_g_parm(file, NULL, p);
+		return ops->vidioc_g_parm(file, state, p);
 	if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
 	    p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
 		return -EINVAL;
 	if (vfd->device_caps & V4L2_CAP_READWRITE)
 		p->parm.capture.readbuffers = 2;
-	ret = ops->vidioc_g_std(file, NULL, &std);
+	ret = ops->vidioc_g_std(file, state, &std);
 	if (ret == 0)
 		v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe);
 	return ret;
 }
 
 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct v4l2_streamparm *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2286,11 +2287,11 @@ static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, struct file *file,
 		p->parm.capture.extendedmode = 0;
 		p->parm.capture.capturemode &= V4L2_MODE_HIGHQUALITY;
 	}
-	return ops->vidioc_s_parm(file, NULL, p);
+	return ops->vidioc_s_parm(file, state, p);
 }
 
 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl qec = {};
@@ -2307,7 +2308,7 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 
 	/* Simulate query_ext_ctr using query_ctrl. */
 	qec.id = p->id;
-	ret = ops->vidioc_query_ext_ctrl(file, NULL, &qec);
+	ret = ops->vidioc_query_ext_ctrl(file, state, &qec);
 	if (ret)
 		return ret;
 	v4l2_query_ext_ctrl_to_v4l2_queryctrl(p, &qec);
@@ -2315,7 +2316,8 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_query_ext_ctrl *p = arg;
@@ -2326,12 +2328,12 @@ static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
 	if (vfd->ctrl_handler)
 		return v4l2_query_ext_ctrl(vfd->ctrl_handler, p);
 	if (ops->vidioc_query_ext_ctrl)
-		return ops->vidioc_query_ext_ctrl(file, NULL, p);
+		return ops->vidioc_query_ext_ctrl(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
-			 void *arg)
+			 struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_querymenu *p = arg;
@@ -2342,12 +2344,12 @@ static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->ctrl_handler)
 		return v4l2_querymenu(vfd->ctrl_handler, p);
 	if (ops->vidioc_querymenu)
-		return ops->vidioc_querymenu(file, NULL, p);
+		return ops->vidioc_querymenu(file, state, p);
 	return -ENOTTY;
 }
 
 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2368,7 +2370,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.id = p->id;
 	ctrl.value = p->value;
 	if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) {
-		int ret = ops->vidioc_g_ext_ctrls(file, NULL, &ctrls);
+		int ret = ops->vidioc_g_ext_ctrls(file, state, &ctrls);
 
 		if (ret == 0)
 			p->value = ctrl.value;
@@ -2378,7 +2380,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_control *p = arg;
@@ -2401,13 +2403,13 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, struct file *file,
 	ctrl.value = p->value;
 	if (!check_ext_ctrls(&ctrls, VIDIOC_S_CTRL))
 		return -EINVAL;
-	ret = ops->vidioc_s_ext_ctrls(file, NULL, &ctrls);
+	ret = ops->vidioc_s_ext_ctrls(file, state, &ctrls);
 	p->value = ctrl.value;
 	return ret;
 }
 
-static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2423,11 +2425,11 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_g_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ?
-				ops->vidioc_g_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_g_ext_ctrls(file, state, p) : -EINVAL;
 }
 
-static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2443,11 +2445,12 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_s_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ?
-				ops->vidioc_s_ext_ctrls(file, NULL, p) : -EINVAL;
+				ops->vidioc_s_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-			     struct file *file, void *arg)
+			     struct file *file,
+			     struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_ext_controls *p = arg;
@@ -2463,7 +2466,7 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 	if (ops->vidioc_try_ext_ctrls == NULL)
 		return -ENOTTY;
 	return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ?
-			ops->vidioc_try_ext_ctrls(file, NULL, p) : -EINVAL;
+			ops->vidioc_try_ext_ctrls(file, state, p) : -EINVAL;
 }
 
 /*
@@ -2475,8 +2478,8 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
  * restore it afterwards. This way applications can use either buffer
  * type and drivers don't need to check for both.
  */
-static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_g_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2486,13 +2489,13 @@ static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_g_selection(file, NULL, p);
+	ret = ops->vidioc_g_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
-static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
-			   struct file *file, void *arg)
+static int v4l_s_selection(const struct v4l2_ioctl_ops *ops, struct file *file,
+			   struct video_device_state *state, void *arg)
 {
 	struct v4l2_selection *p = arg;
 	u32 old_type = p->type;
@@ -2502,13 +2505,13 @@ static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
 		p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	ret = ops->vidioc_s_selection(file, NULL, p);
+	ret = ops->vidioc_s_selection(file, state, p);
 	p->type = old_type;
 	return ret;
 }
 
 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2529,7 +2532,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 
 	/* copying results to old structure on success */
 	if (!ret)
@@ -2538,7 +2541,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
-		      void *arg)
+		      struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_crop *p = arg;
@@ -2559,11 +2562,11 @@ static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE ?
 			V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE;
 
-	return v4l_s_selection(ops, file, &s);
+	return v4l_s_selection(ops, file, state, &s);
 }
 
 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_cropcap *p = arg;
@@ -2587,7 +2590,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		return -ENOTTY;
 
 	if (ops->vidioc_g_pixelaspect)
-		ret = ops->vidioc_g_pixelaspect(file, NULL, s.type,
+		ret = ops->vidioc_g_pixelaspect(file, state, s.type,
 						&p->pixelaspect);
 
 	/*
@@ -2609,7 +2612,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 		s.target = s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS ?
 			V4L2_SEL_TGT_CROP_BOUNDS : V4L2_SEL_TGT_COMPOSE_BOUNDS;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->bounds = s.r;
@@ -2620,7 +2623,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 	else
 		s.target = V4L2_SEL_TGT_CROP_DEFAULT;
 
-	ret = v4l_g_selection(ops, file, &s);
+	ret = v4l_g_selection(ops, file, state, &s);
 	if (ret)
 		return ret;
 	p->defrect = s.r;
@@ -2629,7 +2632,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
-			  void *arg)
+			  struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	int ret;
@@ -2637,7 +2640,7 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 	if (vfd->v4l2_dev)
 		pr_info("%s: =================  START STATUS  =================\n",
 			vfd->v4l2_dev->name);
-	ret = ops->vidioc_log_status(file, NULL);
+	ret = ops->vidioc_log_status(file, state);
 	if (vfd->v4l2_dev)
 		pr_info("%s: ==================  END STATUS  ==================\n",
 			vfd->v4l2_dev->name);
@@ -2645,7 +2648,8 @@ static int v4l_log_status(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct v4l2_dbg_register *p = arg;
@@ -2665,7 +2669,7 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_g_register(file, NULL, p);
+		return ops->vidioc_g_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2673,7 +2677,8 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
-			      struct file *file, void *arg)
+			      struct file *file,
+			      struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	const struct v4l2_dbg_register *p = arg;
@@ -2693,7 +2698,7 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 	}
 	if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
 	    (ops->vidioc_g_chip_info || p->match.addr == 0))
-		return ops->vidioc_s_register(file, NULL, p);
+		return ops->vidioc_s_register(file, state, p);
 	return -EINVAL;
 #else
 	return -ENOTTY;
@@ -2701,7 +2706,8 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	struct video_device *vfd = video_devdata(file);
@@ -2717,7 +2723,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 			p->flags |= V4L2_CHIP_FL_READABLE;
 		strscpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
 		if (ops->vidioc_g_chip_info)
-			return ops->vidioc_g_chip_info(file, NULL, arg);
+			return ops->vidioc_g_chip_info(file, state, arg);
 		if (p->match.addr)
 			return -EINVAL;
 		return 0;
@@ -2744,7 +2750,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
-		       void *arg)
+		       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2752,7 +2758,8 @@ static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, struct file *file,
 }
 
 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2760,7 +2767,8 @@ static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
-				 struct file *file, void *arg)
+				 struct file *file,
+				 struct video_device_state *state, void *arg)
 {
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
 
@@ -2768,7 +2776,8 @@ static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
 }
 
 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
-				struct file *file, void *arg)
+				struct file *file,
+				struct video_device_state *state, void *arg)
 {
 	struct v4l2_sliced_vbi_cap *p = arg;
 	int ret = check_fmt(file, p->type);
@@ -2779,11 +2788,12 @@ static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
 	/* Clear up to type, everything after type is zeroed already */
 	memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
 
-	return ops->vidioc_g_sliced_vbi_cap(file, NULL, p);
+	return ops->vidioc_g_sliced_vbi_cap(file, state, p);
 }
 
 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
-			       struct file *file, void *arg)
+			       struct file *file,
+			       struct video_device_state *state, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_frequency_band *p = arg;
@@ -2801,7 +2811,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 	}
 	if (ops->vidioc_enum_freq_bands) {
-		err = ops->vidioc_enum_freq_bands(file, NULL, p);
+		err = ops->vidioc_enum_freq_bands(file, state, p);
 		if (err != -ENOTTY)
 			return err;
 	}
@@ -2813,7 +2823,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_tuner(file, NULL, &t);
+		err = ops->vidioc_g_tuner(file, state, &t);
 		if (err)
 			return err;
 		p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2832,7 +2842,7 @@ static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
 			return -EINVAL;
 		if (p->index)
 			return -EINVAL;
-		err = ops->vidioc_g_modulator(file, NULL, &m);
+		err = ops->vidioc_g_modulator(file, state, &m);
 		if (err)
 			return err;
 		p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS;
@@ -2849,7 +2859,7 @@ struct v4l2_ioctl_info {
 	u32 flags;
 	const char * const name;
 	int (*func)(const struct v4l2_ioctl_ops *ops, struct file *file,
-		    void *p);
+		    struct video_device_state *state, void *p);
 	void (*debug)(const void *arg, bool write_only);
 };
 
@@ -2870,7 +2880,9 @@ struct v4l2_ioctl_info {
 #define DEFINE_V4L_STUB_FUNC(_vidioc)				\
 	static int v4l_stub_ ## _vidioc(			\
 			const struct v4l2_ioctl_ops *ops,	\
-			struct file *file, void *p)		\
+			struct file *file,			\
+			struct video_device_state *state,	\
+			void *p)				\
 	{							\
 		return ops->vidioc_ ## _vidioc(file, NULL, p);	\
 	}
@@ -3126,7 +3138,7 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (info != &default_info) {
-		ret = info->func(ops, file, arg);
+		ret = info->func(ops, file, NULL, arg);
 	} else if (!ops->vidioc_default) {
 		ret = -ENOTTY;
 	} else {
author
#26 lore raw

PATCH v2 6/10 media: Replace void * with video_device_state * in all driver ioctl implementations

In reply to Jai Luthra

Replace the opaque (and unused) pointer with a pointer to the video device state in all V4L2 driver ioctl implementations.

Most changes were automated using Coccinelle semantic patches for both drivers and framework helpers:

@ops@
identifier ops;
identifier vidioc_op;
identifier fn;
@@

struct v4l2_ioctl_ops ops = {
	...,
	.vidioc_op = fn,
	...,
};

// Rule 1 (like vidioc_log_status)
@depends on ops@
identifier ops.fn;
identifier filep;
identifier priv;
@@
int fn(struct file *filep,
- void *priv)
+ struct video_device_state *state)

{
	<...
-	priv
+	state
	...>
}

// Rule 2 (most ioctls)
@depends on ops@
identifier ops.fn;
identifier filep;
identifier priv;
identifier arg;
type T;
@@
int fn(struct file *filep,
- void *priv,
+ struct video_device_state *state,
T arg)

{
	<...
-	priv
+	state
	...>
}

// Rule 3 (like vidioc_g_pixelaspect)
@depends on ops@
identifier ops.fn;
identifier filep;
identifier priv;
identifier buf_type;
identifier arg;
type T1, T2;
@@
int fn(struct file *filep,
- void *priv,
+ struct video_device_state *state,

       T1 buf_type, T2 *arg)
{
	<...
-	priv
+	state
	...>
}

// Rule 4 (like vidioc_default)
@depends on ops@
identifier ops.fn;
identifier filep;
identifier priv;
identifier valid_prio;
identifier cmd;
identifier arg;
@@
long fn(struct file *filep,
- void *priv,
+ struct video_device_state *state,
bool valid_prio, unsigned int cmd, void *arg)

{
	<...
-	priv
+	state
	...>
}

Function signature updates in headers and edge cases where drivers call ioctl implementations internally were handled manually.

--
Cc: Dmitry Torokhov <[email protected]>
Cc: Nick Dyer <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Tomasz Figa <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Matt Ranostay <[email protected]>
Cc: Andy Walls <[email protected]>
Cc: Yong Zhi <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Bingbu Cao <[email protected]>
Cc: Dan Scally <[email protected]>
Cc: Tianshu Qiu <[email protected]>
Cc: Martin Tuma <[email protected]>
Cc: Bluecherry Maintainers <[email protected]>
Cc: Andrey Utkin <[email protected]>
Cc: Ismael Luceno <[email protected]>
Cc: Ezequiel Garcia <[email protected]>
Cc: Corentin Labbe <[email protected]>
Cc: Michael Tretter <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Keke Li <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc: Jerome Brunet <[email protected]>
Cc: Martin Blumenstingl <[email protected]>
Cc: Ming Qian <[email protected]>
Cc: Zhou Peng <[email protected]>
Cc: Eddie James <[email protected]>
Cc: Joel Stanley <[email protected]>
Cc: Andrew Jeffery <[email protected]>
Cc: Eugen Hristev <[email protected]>
Cc: Nicolas Ferre <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Claudiu Beznea <[email protected]>
Cc: Raspberry Pi Kernel Maintenance <[email protected]>
Cc: Florian Fainelli <[email protected]>
Cc: Broadcom internal kernel review list <[email protected]>
Cc: Ray Jui <[email protected]>
Cc: Scott Branden <[email protected]>
Cc: Philipp Zabel <[email protected]>
Cc: Nas Chung <[email protected]>
Cc: Jackson Lee <[email protected]>
Cc: Devarsh Thakkar <[email protected]>
Cc: Bin Liu <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Cc: Minghsiu Tsai <[email protected]>
Cc: Houlong Wei <[email protected]>
Cc: Andrew-CT Chen <[email protected]>
Cc: Tiffany Lin <[email protected]>
Cc: Yunfei Dong <[email protected]>
Cc: Joseph Liu <[email protected]>
Cc: Marvin Lin <[email protected]>
Cc: Dmitry Osipenko <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Jonathan Hunter <[email protected]>
Cc: Xavier Roumegue <[email protected]>
Cc: Mirela Rabulea <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Rui Miguel Silva <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Martin Kepplinger <[email protected]>
Cc: Purism Kernel Team <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Todor Tomov <[email protected]>
Cc: "Bryan O'Donoghue" <[email protected]>
Cc: Vladimir Zapolskiy <[email protected]>
Cc: Vikash Garodia <[email protected]>
Cc: Dikshita Agarwal <[email protected]>
Cc: Abhinav Kumar <[email protected]>
Cc: Jacopo Mondi <[email protected]>
Cc: Tomi Valkeinen <[email protected]>
Cc: "Niklas Söderlund" <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Magnus Damm <[email protected]>
Cc: Fabrizio Castro <[email protected]>
Cc: Kieran Bingham <[email protected]>
Cc: Nikita Yushchenko <[email protected]>
Cc: Jacob Chen <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: Dafna Hirschfeld <[email protected]>
Cc: Detlev Casanova <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Alim Akhtar <[email protected]>
Cc: Sylwester Nawrocki <[email protected]>
Cc: "Łukasz Stelmach" <[email protected]>
Cc: Andrzej Pietrasiewicz <[email protected]>
Cc: Jacek Anaszewski <[email protected]>
Cc: Andrzej Hajda <[email protected]>
Cc: Fabien Dessenne <[email protected]>
Cc: Hugues Fruchet <[email protected]>
Cc: Jean-Christophe Trotin <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: Alain Volmat <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Samuel Holland <[email protected]>
Cc: Yong Deng <[email protected]>
Cc: Paul Kocialkowski <[email protected]>
Cc: Shreeya Patel <[email protected]>
Cc: "Lad, Prabhakar" <[email protected]>
Cc: Yemike Abhilash Chandra <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: Nicolas Dufresne <[email protected]>
Cc: Benjamin Gaignard <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Alexey Klimov <[email protected]>
Cc: Eduardo Valentin <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Daniel Almeida <[email protected]>
Cc: Michael Krufky <[email protected]>
Cc: Mike Isely <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Steve Longerbeam <[email protected]>
Cc: Jack Zhu <[email protected]>
Cc: Changhuang Liang <[email protected]>
Cc: Sowjanya Komatineni <[email protected]>
Cc: Luca Ceresoli <[email protected]>
Cc: Parthiban Veerasooran <[email protected]>
Cc: Christian Gromm <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Plamen Atanasov <[email protected]>
Cc: Sean Young <[email protected]>
Cc: Ariel Otilibili <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>
Cc: Jiasheng Jiang <[email protected]>
Cc: Lad Prabhakar <[email protected]>
Cc: Tommaso Merciai <[email protected]>
Cc: Biju Das <[email protected]>
Cc: Daniel Scally <[email protected]>
Cc: Matthew Majewski <[email protected]>
Cc: Yunseong Kim <[email protected]>
Cc: Chen Ni <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Fabio Luongo <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Yang Yingliang <[email protected]>
Cc: Ludwig Disterhof <[email protected]>
Cc: Ma Ke <[email protected]>
Cc: "Everest K.C." <[email protected]>
Cc: Stefan Wahren <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: Michael Grzeschik <[email protected]>
Cc: Akash Kumar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/input/rmi4/rmi_f54.c                       |  22 +-
 drivers/input/touchscreen/atmel_mxt_ts.c           |  23 +-
 drivers/input/touchscreen/sur40.c                  |  35 ++-
 .../extron-da-hd-4k-plus/extron-da-hd-4k-plus.c    |  34 ++-
 drivers/media/common/saa7146/saa7146_video.c       |  37 +++-
 drivers/media/common/videobuf2/videobuf2-v4l2.c    |  30 ++-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |  38 ++--
 drivers/media/i2c/video-i2c.c                      |  39 ++--
 drivers/media/pci/bt8xx/bttv-driver.c              |  84 +++++---
 drivers/media/pci/bt8xx/bttv-vbi.c                 |  11 +-
 drivers/media/pci/bt8xx/bttvp.h                    |   9 +-
 drivers/media/pci/cobalt/cobalt-v4l2.c             |  98 +++++----
 drivers/media/pci/cx18/cx18-driver.c               |   9 +-
 drivers/media/pci/cx18/cx18-ioctl.c                | 114 ++++++----
 drivers/media/pci/cx18/cx18-ioctl.h                |   9 +-
 drivers/media/pci/cx23885/cx23885-417.c            |  53 +++--
 drivers/media/pci/cx23885/cx23885-ioctl.c          |   8 +-
 drivers/media/pci/cx23885/cx23885-ioctl.h          |   9 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   5 +-
 drivers/media/pci/cx23885/cx23885-video.c          |  82 ++++---
 drivers/media/pci/cx23885/cx23885.h                |   4 +-
 drivers/media/pci/cx25821/cx25821-video.c          |  57 +++--
 drivers/media/pci/cx88/cx88-blackbird.c            |  47 ++--
 drivers/media/pci/cx88/cx88-vbi.c                  |   2 +-
 drivers/media/pci/cx88/cx88-video.c                |  56 +++--
 drivers/media/pci/cx88/cx88.h                      |   2 +-
 drivers/media/pci/dt3155/dt3155.c                  |  25 ++-
 drivers/media/pci/intel/ipu3/ipu3-cio2.c           |  29 ++-
 drivers/media/pci/intel/ipu6/ipu6-isys-video.c     |  41 ++--
 drivers/media/pci/ivtv/ivtv-driver.c               |   8 +-
 drivers/media/pci/ivtv/ivtv-ioctl.c                | 225 +++++++++++++------
 drivers/media/pci/ivtv/ivtv-ioctl.h                |   6 +-
 drivers/media/pci/mgb4/mgb4_vin.c                  |  55 +++--
 drivers/media/pci/mgb4/mgb4_vout.c                 |  49 +++--
 drivers/media/pci/saa7134/saa7134-empress.c        |  12 +-
 drivers/media/pci/saa7134/saa7134-video.c          |  96 +++++----
 drivers/media/pci/saa7134/saa7134.h                |  38 ++--
 drivers/media/pci/saa7146/hexium_gemini.c          |  10 +-
 drivers/media/pci/saa7146/hexium_orion.c           |  10 +-
 drivers/media/pci/saa7146/mxb.c                    |  46 ++--
 drivers/media/pci/saa7164/saa7164-encoder.c        |  39 ++--
 drivers/media/pci/saa7164/saa7164-vbi.c            |  27 ++-
 drivers/media/pci/saa7164/saa7164.h                |   9 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |  46 ++--
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |  32 ++-
 drivers/media/pci/ttpci/budget-av.c                |  10 +-
 drivers/media/pci/tw5864/tw5864-video.c            |  49 +++--
 drivers/media/pci/tw68/tw68-video.c                |  43 ++--
 drivers/media/pci/tw686x/tw686x-video.c            |  53 +++--
 drivers/media/pci/zoran/zoran_driver.c             |  44 ++--
 drivers/media/platform/allegro-dvt/allegro-core.c  |  49 +++--
 .../media/platform/amlogic/c3/isp/c3-isp-capture.c |  18 +-
 .../media/platform/amlogic/c3/isp/c3-isp-params.c  |   9 +-
 .../media/platform/amlogic/c3/isp/c3-isp-stats.c   |   9 +-
 drivers/media/platform/amlogic/meson-ge2d/ge2d.c   |  36 +++-
 drivers/media/platform/amphion/vdec.c              |  30 ++-
 drivers/media/platform/amphion/venc.c              |  49 +++--
 drivers/media/platform/aspeed/aspeed-video.c       |  50 +++--
 drivers/media/platform/atmel/atmel-isi.c           |  36 ++--
 drivers/media/platform/broadcom/bcm2835-unicam.c   |  33 ++-
 .../media/platform/chips-media/coda/coda-common.c  |  69 +++---
 .../platform/chips-media/wave5/wave5-helper.c      |   2 +-
 .../platform/chips-media/wave5/wave5-helper.h      |   3 +-
 .../platform/chips-media/wave5/wave5-vpu-dec.c     |  54 +++--
 .../platform/chips-media/wave5/wave5-vpu-enc.c     |  62 ++++--
 .../media/platform/imagination/e5010-jpeg-enc.c    |  34 ++-
 drivers/media/platform/intel/pxa_camera.c          |  34 ++-
 drivers/media/platform/m2m-deinterlace.c           |  34 +--
 drivers/media/platform/marvell/mcam-core.c         |  52 +++--
 .../media/platform/mediatek/jpeg/mtk_jpeg_core.c   |  44 ++--
 drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c  |  34 +--
 .../media/platform/mediatek/mdp3/mtk-mdp3-m2m.c    |  25 ++-
 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c       |  52 +++--
 .../mediatek/vcodec/encoder/mtk_vcodec_enc.c       |  50 +++--
 .../media/platform/microchip/microchip-isc-base.c  |  33 ++-
 drivers/media/platform/nuvoton/npcm-video.c        |  43 ++--
 drivers/media/platform/nvidia/tegra-vde/v4l2.c     |  38 ++--
 drivers/media/platform/nxp/dw100/dw100.c           |  35 +--
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c     |  52 +++--
 drivers/media/platform/nxp/imx-pxp.c               |  34 +--
 drivers/media/platform/nxp/imx7-media-csi.c        |  21 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |  15 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   |  18 +-
 drivers/media/platform/nxp/mx2_emmaprp.c           |  31 ++-
 drivers/media/platform/qcom/camss/camss-video.c    |  27 ++-
 drivers/media/platform/qcom/iris/iris_vidc.c       |  48 +++--
 drivers/media/platform/qcom/venus/vdec.c           |  29 ++-
 drivers/media/platform/qcom/venus/venc.c           |  38 ++--
 .../media/platform/raspberrypi/pisp_be/pisp_be.c   |  42 ++--
 drivers/media/platform/raspberrypi/rp1-cfe/cfe.c   |  40 ++--
 .../media/platform/renesas/rcar-vin/rcar-v4l2.c    |  21 +-
 drivers/media/platform/renesas/rcar_drif.c         |  30 ++-
 drivers/media/platform/renesas/rcar_fdp1.c         |  18 +-
 drivers/media/platform/renesas/rcar_jpu.c          |  21 +-
 drivers/media/platform/renesas/renesas-ceu.c       |  36 ++--
 .../media/platform/renesas/rzg2l-cru/rzg2l-video.c |  18 +-
 drivers/media/platform/renesas/sh_vou.c            |  41 ++--
 drivers/media/platform/renesas/vsp1/vsp1_histo.c   |   9 +-
 drivers/media/platform/renesas/vsp1/vsp1_video.c   |  18 +-
 drivers/media/platform/rockchip/rga/rga.c          |  24 ++-
 .../platform/rockchip/rkisp1/rkisp1-capture.c      |  18 +-
 .../media/platform/rockchip/rkisp1/rkisp1-params.c |  15 +-
 .../media/platform/rockchip/rkisp1/rkisp1-stats.c  |   9 +-
 drivers/media/platform/rockchip/rkvdec/rkvdec.c    |  34 +--
 .../media/platform/samsung/exynos-gsc/gsc-m2m.c    |  44 ++--
 .../platform/samsung/exynos4-is/fimc-capture.c     |  45 ++--
 .../platform/samsung/exynos4-is/fimc-isp-video.c   |  32 +--
 .../media/platform/samsung/exynos4-is/fimc-lite.c  |  36 ++--
 .../media/platform/samsung/exynos4-is/fimc-m2m.c   |  21 +-
 .../platform/samsung/s3c-camif/camif-capture.c     |  54 +++--
 drivers/media/platform/samsung/s5p-g2d/g2d.c       |  26 ++-
 .../media/platform/samsung/s5p-jpeg/jpeg-core.c    |  34 +--
 .../media/platform/samsung/s5p-mfc/s5p_mfc_dec.c   |  48 +++--
 .../media/platform/samsung/s5p-mfc/s5p_mfc_enc.c   |  51 +++--
 drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c   |  26 ++-
 drivers/media/platform/st/sti/delta/delta-v4l2.c   |  44 ++--
 drivers/media/platform/st/sti/hva/hva-v4l2.c       |  46 ++--
 drivers/media/platform/st/stm32/dma2d/dma2d.c      |  18 +-
 drivers/media/platform/st/stm32/stm32-dcmi.c       |  42 ++--
 .../st/stm32/stm32-dcmipp/dcmipp-bytecap.c         |  20 +-
 .../media/platform/sunxi/sun4i-csi/sun4i_v4l2.c    |  25 ++-
 .../platform/sunxi/sun6i-csi/sun6i_csi_capture.c   |  24 ++-
 drivers/media/platform/sunxi/sun8i-di/sun8i-di.c   |  31 ++-
 .../platform/sunxi/sun8i-rotate/sun8i_rotate.c     |  34 +--
 .../media/platform/synopsys/hdmirx/snps_hdmirx.c   |  47 ++--
 drivers/media/platform/ti/am437x/am437x-vpfe.c     |  52 +++--
 drivers/media/platform/ti/cal/cal-video.c          |  54 +++--
 drivers/media/platform/ti/davinci/vpif_capture.c   |  94 ++++----
 drivers/media/platform/ti/davinci/vpif_display.c   |  58 +++--
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  |  20 +-
 drivers/media/platform/ti/omap/omap_vout.c         |  49 +++--
 drivers/media/platform/ti/omap3isp/ispvideo.c      |  53 +++--
 drivers/media/platform/ti/vpe/vpe.c                |  25 ++-
 drivers/media/platform/verisilicon/hantro_v4l2.c   |  47 ++--
 drivers/media/platform/via/via-camera.c            |  42 ++--
 drivers/media/platform/xilinx/xilinx-dma.c         |  15 +-
 drivers/media/radio/dsbr100.c                      |  15 +-
 drivers/media/radio/radio-cadet.c                  |  18 +-
 drivers/media/radio/radio-isa.c                    |  18 +-
 drivers/media/radio/radio-keene.c                  |  15 +-
 drivers/media/radio/radio-ma901.c                  |  15 +-
 drivers/media/radio/radio-miropcm20.c              |  15 +-
 drivers/media/radio/radio-mr800.c                  |  18 +-
 drivers/media/radio/radio-raremono.c               |  19 +-
 drivers/media/radio/radio-sf16fmi.c                |  15 +-
 drivers/media/radio/radio-si476x.c                 |  28 ++-
 drivers/media/radio/radio-tea5764.c                |  15 +-
 drivers/media/radio/radio-tea5777.c                |  21 +-
 drivers/media/radio/radio-timb.c                   |  26 ++-
 drivers/media/radio/si470x/radio-si470x-common.c   |  25 ++-
 drivers/media/radio/si4713/radio-platform-si4713.c |  18 +-
 drivers/media/radio/si4713/radio-usb-si4713.c      |  15 +-
 drivers/media/radio/tea575x.c                      |  21 +-
 drivers/media/test-drivers/vicodec/vicodec-core.c  |  54 +++--
 drivers/media/test-drivers/vim2m.c                 |  56 +++--
 drivers/media/test-drivers/vimc/vimc-capture.c     |  20 +-
 drivers/media/test-drivers/visl/visl-video.c       |  34 +--
 drivers/media/test-drivers/vivid/vivid-core.c      | 203 ++++++++++--------
 drivers/media/test-drivers/vivid/vivid-meta-cap.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-cap.h  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-out.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-meta-out.h  |   9 +-
 drivers/media/test-drivers/vivid/vivid-radio-rx.c  |  16 +-
 drivers/media/test-drivers/vivid/vivid-radio-rx.h  |  16 +-
 drivers/media/test-drivers/vivid/vivid-radio-tx.c  |   6 +-
 drivers/media/test-drivers/vivid/vivid-radio-tx.h  |   6 +-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c   |  30 ++-
 drivers/media/test-drivers/vivid/vivid-sdr-cap.h   |  30 ++-
 drivers/media/test-drivers/vivid/vivid-touch-cap.c |  22 +-
 drivers/media/test-drivers/vivid/vivid-touch-cap.h |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-cap.c   |  26 ++-
 drivers/media/test-drivers/vivid/vivid-vbi-cap.h   |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-out.c   |  22 +-
 drivers/media/test-drivers/vivid/vivid-vbi-out.h   |  18 +-
 drivers/media/test-drivers/vivid/vivid-vid-cap.c   | 114 ++++++----
 drivers/media/test-drivers/vivid/vivid-vid-cap.h   | 117 +++++++---
 .../media/test-drivers/vivid/vivid-vid-common.c    |  24 ++-
 .../media/test-drivers/vivid/vivid-vid-common.h    |  34 +--
 drivers/media/test-drivers/vivid/vivid-vid-out.c   | 122 ++++++-----
 drivers/media/test-drivers/vivid/vivid-vid-out.h   |  95 +++++---
 drivers/media/usb/airspy/airspy.c                  |  37 ++--
 drivers/media/usb/au0828/au0828-video.c            |  74 ++++---
 drivers/media/usb/cx231xx/cx231xx-417.c            |  28 ++-
 drivers/media/usb/cx231xx/cx231xx-video.c          |  79 ++++---
 drivers/media/usb/cx231xx/cx231xx.h                |  39 ++--
 drivers/media/usb/dvb-usb/cxusb-analog.c           |  48 +++--
 drivers/media/usb/em28xx/em28xx-video.c            |  87 +++++---
 drivers/media/usb/go7007/go7007-v4l2.c             |  75 ++++---
 drivers/media/usb/gspca/gspca.c                    |  51 +++--
 drivers/media/usb/hackrf/hackrf.c                  |  39 ++--
 drivers/media/usb/hdpvr/hdpvr-video.c              |  60 ++++--
 drivers/media/usb/msi2500/msi2500.c                |  31 ++-
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c           |  98 ++++++---
 drivers/media/usb/pwc/pwc-v4l.c                    |  44 ++--
 drivers/media/usb/s2255/s2255drv.c                 |  55 +++--
 drivers/media/usb/stk1160/stk1160-v4l.c            |  40 ++--
 drivers/media/usb/usbtv/usbtv-video.c              |  24 ++-
 drivers/media/usb/uvc/uvc_metadata.c               |  17 +-
 drivers/media/usb/uvc/uvc_v4l2.c                   |  59 +++--
 drivers/media/v4l2-core/v4l2-ctrls-api.c           |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 |   4 +-
 drivers/media/v4l2-core/v4l2-mem2mem.c             |  56 +++--
 drivers/staging/media/atomisp/pci/atomisp_ioctl.c  |  72 ++++---
 drivers/staging/media/av7110/av7110_v4l.c          |  60 ++++--
 .../media/deprecated/atmel/atmel-isc-base.c        |  33 ++-
 drivers/staging/media/imx/imx-media-capture.c      |  53 +++--
 drivers/staging/media/imx/imx-media-csc-scaler.c   |  23 +-
 drivers/staging/media/ipu3/ipu3-v4l2.c             |  29 ++-
 drivers/staging/media/ipu7/ipu7-isys-video.c       |  30 ++-
 drivers/staging/media/meson/vdec/vdec.c            |  26 ++-
 drivers/staging/media/starfive/camss/stf-video.c   |  18 +-
 drivers/staging/media/sunxi/cedrus/cedrus_video.c  |  29 ++-
 .../media/sunxi/sun6i-isp/sun6i_isp_capture.c      |  24 ++-
 .../media/sunxi/sun6i-isp/sun6i_isp_params.c       |   9 +-
 drivers/staging/media/tegra-video/vi.c             |  68 ++++--
 drivers/staging/most/video/video.c                 |  39 ++--
 .../vc04_services/bcm2835-camera/bcm2835-camera.c  |  58 +++--
 drivers/usb/gadget/function/uvc_v4l2.c             |  50 +++--
 include/media/v4l2-ctrls.h                         |   5 +-
 include/media/v4l2-dev.h                           |   2 +-
 include/media/v4l2-ioctl.h                         | 238 +++++++++++----------
 include/media/v4l2-mem2mem.h                       |  48 +++--
 include/media/videobuf2-v4l2.h                     |  33 +--
 223 files changed, 5392 insertions(+), 2955 deletions(-)
drivers/input/rmi4/rmi_f54.c +15 -7
index ac4041a69fcd3acf766ac8189ea0ecccb9b7ac93..b66b80d76833bfe56f04f70ce908307692632f48 100644
@@ -383,7 +383,8 @@ static const struct vb2_queue rmi_f54_queue = {
 	.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
 };
 
-static int rmi_f54_vidioc_querycap(struct file *file, void *priv,
+static int rmi_f54_vidioc_querycap(struct file *file,
+				   struct video_device_state *state,
 				   struct v4l2_capability *cap)
 {
 	struct f54_data *f54 = video_drvdata(file);
@@ -396,7 +397,8 @@ static int rmi_f54_vidioc_querycap(struct file *file, void *priv,
 	return 0;
 }
 
-static int rmi_f54_vidioc_enum_input(struct file *file, void *priv,
+static int rmi_f54_vidioc_enum_input(struct file *file,
+				     struct video_device_state *state,
 				     struct v4l2_input *i)
 {
 	struct f54_data *f54 = video_drvdata(file);
@@ -442,12 +444,15 @@ static int rmi_f54_set_input(struct f54_data *f54, unsigned int i)
 	return 0;
 }
 
-static int rmi_f54_vidioc_s_input(struct file *file, void *priv, unsigned int i)
+static int rmi_f54_vidioc_s_input(struct file *file,
+				  struct video_device_state *state,
+				  unsigned int i)
 {
 	return rmi_f54_set_input(video_drvdata(file), i);
 }
 
-static int rmi_f54_vidioc_g_input(struct file *file, void *priv,
+static int rmi_f54_vidioc_g_input(struct file *file,
+				  struct video_device_state *state,
 				  unsigned int *i)
 {
 	struct f54_data *f54 = video_drvdata(file);
@@ -457,7 +462,8 @@ static int rmi_f54_vidioc_g_input(struct file *file, void *priv,
 	return 0;
 }
 
-static int rmi_f54_vidioc_fmt(struct file *file, void *priv,
+static int rmi_f54_vidioc_fmt(struct file *file,
+			      struct video_device_state *state,
 			      struct v4l2_format *f)
 {
 	struct f54_data *f54 = video_drvdata(file);
@@ -467,7 +473,8 @@ static int rmi_f54_vidioc_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int rmi_f54_vidioc_enum_fmt(struct file *file, void *priv,
+static int rmi_f54_vidioc_enum_fmt(struct file *file,
+				   struct video_device_state *state,
 				   struct v4l2_fmtdesc *fmt)
 {
 	struct f54_data *f54 = video_drvdata(file);
@@ -483,7 +490,8 @@ static int rmi_f54_vidioc_enum_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int rmi_f54_vidioc_g_parm(struct file *file, void *fh,
+static int rmi_f54_vidioc_g_parm(struct file *file,
+				 struct video_device_state *state,
 				 struct v4l2_streamparm *a)
 {
 	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
drivers/input/touchscreen/atmel_mxt_ts.c +16 -7
index 322d5a3d40a0933f1e1c290e906258a874bcf4b2..255e2e7713e3371b56736ded22b66d7df9cf8f49 100644
@@ -2547,7 +2547,8 @@ static const struct vb2_queue mxt_queue = {
 	.min_queued_buffers = 1,
 };
 
-static int mxt_vidioc_querycap(struct file *file, void *priv,
+static int mxt_vidioc_querycap(struct file *file,
+			       struct video_device_state *state,
 				 struct v4l2_capability *cap)
 {
 	struct mxt_data *data = video_drvdata(file);
@@ -2559,7 +2560,8 @@ static int mxt_vidioc_querycap(struct file *file, void *priv,
 	return 0;
 }
 
-static int mxt_vidioc_enum_input(struct file *file, void *priv,
+static int mxt_vidioc_enum_input(struct file *file,
+				 struct video_device_state *state,
 				   struct v4l2_input *i)
 {
 	if (i->index >= MXT_V4L_INPUT_MAX)
@@ -2604,12 +2606,16 @@ static int mxt_set_input(struct mxt_data *data, unsigned int i)
 	return 0;
 }
 
-static int mxt_vidioc_s_input(struct file *file, void *priv, unsigned int i)
+static int mxt_vidioc_s_input(struct file *file,
+			      struct video_device_state *state,
+			      unsigned int i)
 {
 	return mxt_set_input(video_drvdata(file), i);
 }
 
-static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
+static int mxt_vidioc_g_input(struct file *file,
+			      struct video_device_state *state,
+			      unsigned int *i)
 {
 	struct mxt_data *data = video_drvdata(file);
 
@@ -2618,7 +2624,8 @@ static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 	return 0;
 }
 
-static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f)
+static int mxt_vidioc_fmt(struct file *file, struct video_device_state *state,
+			  struct v4l2_format *f)
 {
 	struct mxt_data *data = video_drvdata(file);
 
@@ -2628,7 +2635,8 @@ static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f)
 	return 0;
 }
 
-static int mxt_vidioc_enum_fmt(struct file *file, void *priv,
+static int mxt_vidioc_enum_fmt(struct file *file,
+			       struct video_device_state *state,
 				 struct v4l2_fmtdesc *fmt)
 {
 	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -2650,7 +2658,8 @@ static int mxt_vidioc_enum_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int mxt_vidioc_g_parm(struct file *file, void *fh,
+static int mxt_vidioc_g_parm(struct file *file,
+			     struct video_device_state *state,
 			     struct v4l2_streamparm *a)
 {
 	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
drivers/input/touchscreen/sur40.c +24 -11
index 7b3b10cbfcfc44eabd56a4a39551c44eed730de8..6bc51ad2cd0a47029aade52456003f3be90ec932 100644
@@ -935,7 +935,8 @@ static void sur40_stop_streaming(struct vb2_queue *vq)
 }
 
 /* V4L ioctl */
-static int sur40_vidioc_querycap(struct file *file, void *priv,
+static int sur40_vidioc_querycap(struct file *file,
+				 struct video_device_state *state,
 				 struct v4l2_capability *cap)
 {
 	struct sur40_state *sur40 = video_drvdata(file);
@@ -946,7 +947,8 @@ static int sur40_vidioc_querycap(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_enum_input(struct file *file, void *priv,
+static int sur40_vidioc_enum_input(struct file *file,
+				   struct video_device_state *state,
 				   struct v4l2_input *i)
 {
 	if (i->index != 0)
@@ -958,18 +960,23 @@ static int sur40_vidioc_enum_input(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_s_input(struct file *file, void *priv, unsigned int i)
+static int sur40_vidioc_s_input(struct file *file,
+				struct video_device_state *state,
+				unsigned int i)
 {
 	return (i == 0) ? 0 : -EINVAL;
 }
 
-static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
+static int sur40_vidioc_g_input(struct file *file,
+				struct video_device_state *state,
+				unsigned int *i)
 {
 	*i = 0;
 	return 0;
 }
 
-static int sur40_vidioc_try_fmt(struct file *file, void *priv,
+static int sur40_vidioc_try_fmt(struct file *file,
+				struct video_device_state *state,
 			    struct v4l2_format *f)
 {
 	switch (f->fmt.pix.pixelformat) {
@@ -985,7 +992,8 @@ static int sur40_vidioc_try_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_s_fmt(struct file *file, void *priv,
+static int sur40_vidioc_s_fmt(struct file *file,
+			      struct video_device_state *state,
 			    struct v4l2_format *f)
 {
 	struct sur40_state *sur40 = video_drvdata(file);
@@ -1004,7 +1012,8 @@ static int sur40_vidioc_s_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_g_fmt(struct file *file, void *priv,
+static int sur40_vidioc_g_fmt(struct file *file,
+			      struct video_device_state *state,
 			    struct v4l2_format *f)
 {
 	struct sur40_state *sur40 = video_drvdata(file);
@@ -1038,7 +1047,8 @@ static int sur40_s_ctrl(struct v4l2_ctrl *ctrl)
 	return 0;
 }
 
-static int sur40_ioctl_parm(struct file *file, void *priv,
+static int sur40_ioctl_parm(struct file *file,
+			    struct video_device_state *state,
 			    struct v4l2_streamparm *p)
 {
 	if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -1051,7 +1061,8 @@ static int sur40_ioctl_parm(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
+static int sur40_vidioc_enum_fmt(struct file *file,
+				 struct video_device_state *state,
 				 struct v4l2_fmtdesc *f)
 {
 	if (f->index >= ARRAY_SIZE(sur40_pix_format))
@@ -1062,7 +1073,8 @@ static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
+static int sur40_vidioc_enum_framesizes(struct file *file,
+					struct video_device_state *state,
 					struct v4l2_frmsizeenum *f)
 {
 	struct sur40_state *sur40 = video_drvdata(file);
@@ -1077,7 +1089,8 @@ static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
 	return 0;
 }
 
-static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv,
+static int sur40_vidioc_enum_frameintervals(struct file *file,
+					    struct video_device_state *state,
 					    struct v4l2_frmivalenum *f)
 {
 	struct sur40_state *sur40 = video_drvdata(file);
drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c +23 -11
index e2eff17952ab237b799f9892159254146319f4c7..ebefd5e5c747aa9646d7a45414a661d076cf1e4a 100644
@@ -1195,7 +1195,8 @@ static const struct cec_adap_ops extron_cec_adap_ops = {
 	.received = extron_received,
 };
 
-static int extron_querycap(struct file *file, void *priv,
+static int extron_querycap(struct file *file,
+			   struct video_device_state *state,
 			   struct v4l2_capability *cap)
 {
 	struct extron_port *port = video_drvdata(file);
@@ -1206,7 +1207,9 @@ static int extron_querycap(struct file *file, void *priv,
 	return 0;
 }
 
-static int extron_enum_input(struct file *file, void *priv, struct v4l2_input *inp)
+static int extron_enum_input(struct file *file,
+			     struct video_device_state *state,
+			     struct v4l2_input *inp)
 {
 	struct extron_port *port = video_drvdata(file);
 
@@ -1219,18 +1222,22 @@ static int extron_enum_input(struct file *file, void *priv, struct v4l2_input *i
 	return 0;
 }
 
-static int extron_g_input(struct file *file, void *priv, unsigned int *i)
+static int extron_g_input(struct file *file, struct video_device_state *state,
+			  unsigned int *i)
 {
 	*i = 0;
 	return 0;
 }
 
-static int extron_s_input(struct file *file, void *priv, unsigned int i)
+static int extron_s_input(struct file *file, struct video_device_state *state,
+			  unsigned int i)
 {
 	return i ? -EINVAL : 0;
 }
 
-static int extron_enum_output(struct file *file, void *priv, struct v4l2_output *out)
+static int extron_enum_output(struct file *file,
+			      struct video_device_state *state,
+			      struct v4l2_output *out)
 {
 	struct extron_port *port = video_drvdata(file);
 
@@ -1241,18 +1248,21 @@ static int extron_enum_output(struct file *file, void *priv, struct v4l2_output
 	return 0;
 }
 
-static int extron_g_output(struct file *file, void *priv, unsigned int *o)
+static int extron_g_output(struct file *file,
+			   struct video_device_state *state, unsigned int *o)
 {
 	*o = 0;
 	return 0;
 }
 
-static int extron_s_output(struct file *file, void *priv, unsigned int o)
+static int extron_s_output(struct file *file,
+			   struct video_device_state *state, unsigned int o)
 {
 	return o ? -EINVAL : 0;
 }
 
-static int extron_g_edid(struct file *file, void *priv,
+static int extron_g_edid(struct file *file,
+			 struct video_device_state *state,
 			 struct v4l2_edid *edid)
 {
 	struct extron_port *port = video_drvdata(file);
@@ -1280,7 +1290,8 @@ static int extron_g_edid(struct file *file, void *priv,
 	return 0;
 }
 
-static int extron_s_edid(struct file *file, void *priv, struct v4l2_edid *edid)
+static int extron_s_edid(struct file *file, struct video_device_state *state,
+			 struct v4l2_edid *edid)
 {
 	struct extron_port *port = video_drvdata(file);
 
@@ -1305,12 +1316,13 @@ static int extron_s_edid(struct file *file, void *priv, struct v4l2_edid *edid)
 	return extron_write_edid(port, edid->edid, edid->blocks);
 }
 
-static int extron_log_status(struct file *file, void *priv)
+static int extron_log_status(struct file *file,
+			     struct video_device_state *state)
 {
 	struct extron_port *port = video_drvdata(file);
 
 	extron_adap_status(port->adap, NULL);
-	return v4l2_ctrl_log_status(file, priv);
+	return v4l2_ctrl_log_status(file, state);
 }
 
 static const struct v4l2_ioctl_ops extron_ioctl_ops = {
drivers/media/common/saa7146/saa7146_video.c +26 -11
index 733e18001d0d418d32c517b80dee57130b379b07..768be0c6bfdeee70939fbe872a85e99fafe4cd25 100644
@@ -251,7 +251,9 @@ static void video_end(struct saa7146_dev *dev)
 	saa7146_res_free(dev, resource);
 }
 
-static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
+static int vidioc_querycap(struct file *file,
+			   struct video_device_state *state,
+			   struct v4l2_capability *cap)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 
@@ -264,7 +266,9 @@ static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *
 	return 0;
 }
 
-static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
+static int vidioc_enum_fmt_vid_cap(struct file *file,
+				   struct video_device_state *state,
+				   struct v4l2_fmtdesc *f)
 {
 	if (f->index >= ARRAY_SIZE(formats))
 		return -EINVAL;
@@ -323,7 +327,8 @@ int saa7146_s_ctrl(struct v4l2_ctrl *ctrl)
 	return 0;
 }
 
-static int vidioc_g_parm(struct file *file, void *fh,
+static int vidioc_g_parm(struct file *file,
+			 struct video_device_state *state,
 		struct v4l2_streamparm *parm)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
@@ -337,7 +342,9 @@ static int vidioc_g_parm(struct file *file, void *fh,
 	return 0;
 }
 
-static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
+static int vidioc_g_fmt_vid_cap(struct file *file,
+				struct video_device_state *state,
+				struct v4l2_format *f)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
@@ -346,7 +353,9 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
 	return 0;
 }
 
-static int vidioc_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f)
+static int vidioc_g_fmt_vbi_cap(struct file *file,
+				struct video_device_state *state,
+				struct v4l2_format *f)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
@@ -355,7 +364,9 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format
 	return 0;
 }
 
-static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
+static int vidioc_try_fmt_vid_cap(struct file *file,
+				  struct video_device_state *state,
+				  struct v4l2_format *f)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
@@ -364,7 +375,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
 	int maxw, maxh;
 	int calc_bpl;
 
-	DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh);
+	DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, state);
 
 	fmt = saa7146_format_by_fourcc(dev, f->fmt.pix.pixelformat);
 	if (NULL == fmt)
@@ -417,7 +428,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
 	return 0;
 }
 
-static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
+static int vidioc_s_fmt_vid_cap(struct file *file,
+				struct video_device_state *state,
+				struct v4l2_format *f)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
@@ -428,7 +441,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
 		DEB_EE("streaming capture is active\n");
 		return -EBUSY;
 	}
-	err = vidioc_try_fmt_vid_cap(file, fh, f);
+	err = vidioc_try_fmt_vid_cap(file, state, f);
 	if (0 != err)
 		return err;
 	switch (f->fmt.pix.field) {
@@ -445,7 +458,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
 	return 0;
 }
 
-static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
+static int vidioc_g_std(struct file *file, struct video_device_state *state,
+			v4l2_std_id *norm)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
@@ -454,7 +468,8 @@ static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
 	return 0;
 }
 
-static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id id)
+static int vidioc_s_std(struct file *file, struct video_device_state *state,
+			v4l2_std_id id)
 {
 	struct saa7146_dev *dev = video_drvdata(file);
 	struct saa7146_vv *vv = dev->vv_data;
drivers/media/common/videobuf2/videobuf2-v4l2.c +20 -10
index d911021c1bb0527777d2da18bef8f0562e32b460..01f0ee4f81d1c478e3ad80f30c97ceccb9e542d8 100644
@@ -996,7 +996,8 @@ EXPORT_SYMBOL_GPL(vb2_poll);
 
 /* vb2 ioctl helpers */
 
-int vb2_ioctl_remove_bufs(struct file *file, void *priv,
+int vb2_ioctl_remove_bufs(struct file *file,
+			  struct video_device_state *state,
 			  struct v4l2_remove_buffers *d)
 {
 	struct video_device *vdev = video_devdata(file);
@@ -1014,7 +1015,8 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv,
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_remove_bufs);
 
-int vb2_ioctl_reqbufs(struct file *file, void *priv,
+int vb2_ioctl_reqbufs(struct file *file,
+		      struct video_device_state *state,
 			  struct v4l2_requestbuffers *p)
 {
 	struct video_device *vdev = video_devdata(file);
@@ -1037,7 +1039,8 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv,
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_reqbufs);
 
-int vb2_ioctl_create_bufs(struct file *file, void *priv,
+int vb2_ioctl_create_bufs(struct file *file,
+			  struct video_device_state *state,
 			  struct v4l2_create_buffers *p)
 {
 	struct video_device *vdev = video_devdata(file);
@@ -1064,7 +1067,8 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_create_bufs);
 
-int vb2_ioctl_prepare_buf(struct file *file, void *priv,
+int vb2_ioctl_prepare_buf(struct file *file,
+			  struct video_device_state *state,
 			  struct v4l2_buffer *p)
 {
 	struct video_device *vdev = video_devdata(file);
@@ -1075,7 +1079,8 @@ int vb2_ioctl_prepare_buf(struct file *file, void *priv,
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
 
-int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
+int vb2_ioctl_querybuf(struct file *file, struct video_device_state *state,
+		       struct v4l2_buffer *p)
 {
 	struct video_device *vdev = video_devdata(file);
 
@@ -1084,7 +1089,8 @@ int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_querybuf);
 
-int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+int vb2_ioctl_qbuf(struct file *file, struct video_device_state *state,
+		   struct v4l2_buffer *p)
 {
 	struct video_device *vdev = video_devdata(file);
 
@@ -1094,7 +1100,8 @@ int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_qbuf);
 
-int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+int vb2_ioctl_dqbuf(struct file *file, struct video_device_state *state,
+		    struct v4l2_buffer *p)
 {
 	struct video_device *vdev = video_devdata(file);
 
@@ -1104,7 +1111,8 @@ int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
 
-int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
+int vb2_ioctl_streamon(struct file *file, struct video_device_state *state,
+		       enum v4l2_buf_type i)
 {
 	struct video_device *vdev = video_devdata(file);
 
@@ -1114,7 +1122,8 @@ int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
 
-int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
+int vb2_ioctl_streamoff(struct file *file, struct video_device_state *state,
+			enum v4l2_buf_type i)
 {
 	struct video_device *vdev = video_devdata(file);
 
@@ -1124,7 +1133,8 @@ int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
 
-int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p)
+int vb2_ioctl_expbuf(struct file *file, struct video_device_state *state,
+		     struct v4l2_exportbuffer *p)
 {
 	struct video_device *vdev = video_devdata(file);
 
drivers/media/dvb-frontends/rtl2832_sdr.c +20 -18
index 0357624968f1b542772d8cc751211c0bf28e19ab..986637c4bec7da0dc8a13ded8829e11b0f8a4415 100644
@@ -418,8 +418,8 @@ static void rtl2832_sdr_cleanup_queued_bufs(struct rtl2832_sdr_dev *dev)
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
 
-static int rtl2832_sdr_querycap(struct file *file, void *fh,
-		struct v4l2_capability *cap)
+static int rtl2832_sdr_querycap(struct file *file,
+				struct video_device_state *state, struct v4l2_capability *cap)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -949,8 +949,8 @@ static const struct vb2_ops rtl2832_sdr_vb2_ops = {
 	.stop_streaming         = rtl2832_sdr_stop_streaming,
 };
 
-static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
-		struct v4l2_tuner *v)
+static int rtl2832_sdr_g_tuner(struct file *file,
+			       struct video_device_state *state, struct v4l2_tuner *v)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -981,8 +981,8 @@ static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
 	return ret;
 }
 
-static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
-		const struct v4l2_tuner *v)
+static int rtl2832_sdr_s_tuner(struct file *file,
+			       struct video_device_state *state, const struct v4l2_tuner *v)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -1003,7 +1003,8 @@ static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
 	return ret;
 }
 
-static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
+static int rtl2832_sdr_enum_freq_bands(struct file *file,
+				       struct video_device_state *state,
 		struct v4l2_frequency_band *band)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
@@ -1034,8 +1035,8 @@ static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
 	return ret;
 }
 
-static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
-		struct v4l2_frequency *f)
+static int rtl2832_sdr_g_frequency(struct file *file,
+				   struct video_device_state *state, struct v4l2_frequency *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -1061,7 +1062,8 @@ static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
 	return ret;
 }
 
-static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
+static int rtl2832_sdr_s_frequency(struct file *file,
+				   struct video_device_state *state,
 		const struct v4l2_frequency *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
@@ -1105,8 +1107,8 @@ static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
 	return ret;
 }
 
-static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file, void *priv,
-		struct v4l2_fmtdesc *f)
+static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file,
+					struct video_device_state *state, struct v4l2_fmtdesc *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -1121,8 +1123,8 @@ static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, void *priv,
-		struct v4l2_format *f)
+static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file,
+				     struct video_device_state *state, struct v4l2_format *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -1135,8 +1137,8 @@ static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, void *priv,
-		struct v4l2_format *f)
+static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file,
+				     struct video_device_state *state, struct v4l2_format *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
@@ -1166,8 +1168,8 @@ static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int rtl2832_sdr_try_fmt_sdr_cap(struct file *file, void *priv,
-		struct v4l2_format *f)
+static int rtl2832_sdr_try_fmt_sdr_cap(struct file *file,
+				       struct video_device_state *state, struct v4l2_format *f)
 {
 	struct rtl2832_sdr_dev *dev = video_drvdata(file);
 	struct platform_device *pdev = dev->pdev;
drivers/media/i2c/video-i2c.c +26 -13
index 0dd991d70d538050731c0106533d6f0618853b1f..96c1b9e7db719602cada653257d77ee6e103d319 100644
@@ -558,7 +558,8 @@ static const struct vb2_ops video_i2c_video_qops = {
 	.stop_streaming		= stop_streaming,
 };
 
-static int video_i2c_querycap(struct file *file, void  *priv,
+static int video_i2c_querycap(struct file *file,
+			      struct video_device_state *state,
 				struct v4l2_capability *vcap)
 {
 	struct video_i2c_data *data = video_drvdata(file);
@@ -573,19 +574,24 @@ static int video_i2c_querycap(struct file *file, void  *priv,
 	return 0;
 }
 
-static int video_i2c_g_input(struct file *file, void *fh, unsigned int *inp)
+static int video_i2c_g_input(struct file *file,
+			     struct video_device_state *state,
+			     unsigned int *inp)
 {
 	*inp = 0;
 
 	return 0;
 }
 
-static int video_i2c_s_input(struct file *file, void *fh, unsigned int inp)
+static int video_i2c_s_input(struct file *file,
+			     struct video_device_state *state,
+			     unsigned int inp)
 {
 	return (inp > 0) ? -EINVAL : 0;
 }
 
-static int video_i2c_enum_input(struct file *file, void *fh,
+static int video_i2c_enum_input(struct file *file,
+				struct video_device_state *state,
 				  struct v4l2_input *vin)
 {
 	if (vin->index > 0)
@@ -598,7 +604,8 @@ static int video_i2c_enum_input(struct file *file, void *fh,
 	return 0;
 }
 
-static int video_i2c_enum_fmt_vid_cap(struct file *file, void *fh,
+static int video_i2c_enum_fmt_vid_cap(struct file *file,
+				      struct video_device_state *state,
 					struct v4l2_fmtdesc *fmt)
 {
 	struct video_i2c_data *data = video_drvdata(file);
@@ -613,7 +620,8 @@ static int video_i2c_enum_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static int video_i2c_enum_framesizes(struct file *file, void *fh,
+static int video_i2c_enum_framesizes(struct file *file,
+				     struct video_device_state *state,
 				       struct v4l2_frmsizeenum *fsize)
 {
 	const struct video_i2c_data *data = video_drvdata(file);
@@ -633,7 +641,8 @@ static int video_i2c_enum_framesizes(struct file *file, void *fh,
 	return 0;
 }
 
-static int video_i2c_enum_frameintervals(struct file *file, void *priv,
+static int video_i2c_enum_frameintervals(struct file *file,
+					 struct video_device_state *state,
 					   struct v4l2_frmivalenum *fe)
 {
 	const struct video_i2c_data *data = video_drvdata(file);
@@ -651,7 +660,8 @@ static int video_i2c_enum_frameintervals(struct file *file, void *priv,
 	return 0;
 }
 
-static int video_i2c_try_fmt_vid_cap(struct file *file, void *fh,
+static int video_i2c_try_fmt_vid_cap(struct file *file,
+				     struct video_device_state *state,
 				       struct v4l2_format *fmt)
 {
 	const struct video_i2c_data *data = video_drvdata(file);
@@ -670,7 +680,8 @@ static int video_i2c_try_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static int video_i2c_s_fmt_vid_cap(struct file *file, void *fh,
+static int video_i2c_s_fmt_vid_cap(struct file *file,
+				   struct video_device_state *state,
 				     struct v4l2_format *fmt)
 {
 	struct video_i2c_data *data = video_drvdata(file);
@@ -678,10 +689,11 @@ static int video_i2c_s_fmt_vid_cap(struct file *file, void *fh,
 	if (vb2_is_busy(&data->vb_vidq))
 		return -EBUSY;
 
-	return video_i2c_try_fmt_vid_cap(file, fh, fmt);
+	return video_i2c_try_fmt_vid_cap(file, state, fmt);
 }
 
-static int video_i2c_g_parm(struct file *filp, void *priv,
+static int video_i2c_g_parm(struct file *filp,
+			    struct video_device_state *state,
 			      struct v4l2_streamparm *parm)
 {
 	struct video_i2c_data *data = video_drvdata(filp);
@@ -696,7 +708,8 @@ static int video_i2c_g_parm(struct file *filp, void *priv,
 	return 0;
 }
 
-static int video_i2c_s_parm(struct file *filp, void *priv,
+static int video_i2c_s_parm(struct file *filp,
+			    struct video_device_state *state,
 			      struct v4l2_streamparm *parm)
 {
 	struct video_i2c_data *data = video_drvdata(filp);
@@ -709,7 +722,7 @@ static int video_i2c_s_parm(struct file *filp, void *priv,
 	}
 	data->frame_interval = data->chip->frame_intervals[i];
 
-	return video_i2c_g_parm(filp, priv, parm);
+	return video_i2c_g_parm(filp, state, parm);
 }
 
 static const struct v4l2_ioctl_ops video_i2c_ioctl_ops = {
drivers/media/pci/bt8xx/bttv-driver.c +56 -28

246 lines not on this page · raw message

drivers/media/pci/bt8xx/bttv-vbi.c +6 -5
index 0ca88a2400eefbbb6c61e292d5fe2cfef951c4d7..84bcf5b225a51d8a405f8a6fb08947e7a270d923 100644
@@ -241,7 +241,8 @@ static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm,
 	return 0;
 }
 
-int bttv_try_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
+int bttv_try_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+			 struct v4l2_format *frt)
 {
 	struct bttv *btv = video_drvdata(file);
 	const struct bttv_tvnorm *tvnorm;
@@ -257,8 +258,8 @@ int bttv_try_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
 	return try_fmt(&frt->fmt.vbi, tvnorm, crop_start);
 }
 
-
-int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
+int bttv_s_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+		       struct v4l2_format *frt)
 {
 	struct bttv *btv = video_drvdata(file);
 	const struct bttv_tvnorm *tvnorm;
@@ -300,8 +301,8 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
 	return rc;
 }
 
-
-int bttv_g_fmt_vbi_cap(struct file *file, void *priv, struct v4l2_format *frt)
+int bttv_g_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+		       struct v4l2_format *frt)
 {
 	const struct bttv_tvnorm *tvnorm;
 	struct bttv *btv = video_drvdata(file);
drivers/media/pci/bt8xx/bttvp.h +6 -3
index a534e63b9a37bc5fdb27cc5b558ae885c7186715..0849f2f43720f4537174c431b4246cdc02cd21ff 100644
@@ -227,9 +227,12 @@ int bttv_buffer_activate_vbi(struct bttv *btv,
 
 #define VBI_DEFLINES 16
 
-int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
-int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
-int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
+int bttv_try_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+			 struct v4l2_format *f);
+int bttv_g_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+		       struct v4l2_format *f);
+int bttv_s_fmt_vbi_cap(struct file *file, struct video_device_state *state,
+		       struct v4l2_format *f);
 
 /* ---------------------------------------------------------- */
 /* bttv-gpio.c */
drivers/media/pci/cobalt/cobalt-v4l2.c +59 -39

275 lines not on this page · raw message

drivers/media/pci/cx18/cx18-driver.c +3 -6
index b62fd12c93c1a37ea6c8d3d48871028d81b33485..475c5a5e2000987fc3d590eb57da1472d7ccbf4b 100644
@@ -1136,11 +1136,8 @@ int cx18_init_on_first_open(struct cx18 *cx)
 	int video_input;
 	int fw_retry_count = 3;
 	struct v4l2_frequency vf;
-	struct cx18_open_id fh;
 	v4l2_std_id std;
 
-	fh.cx = cx;
-
 	if (test_bit(CX18_F_I_FAILED, &cx->i_flags))
 		return -ENXIO;
 
@@ -1220,14 +1217,14 @@ int cx18_init_on_first_open(struct cx18 *cx)
 
 	video_input = cx->active_input;
 	cx->active_input++;	/* Force update of input */
-	cx18_s_input(NULL, &fh, video_input);
+	cx18_s_input(NULL, NULL, video_input);
 
 	/* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
 	   in one place. */
 	cx->std++;		/* Force full standard initialization */
 	std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
-	cx18_s_std(NULL, &fh, std);
-	cx18_s_frequency(NULL, &fh, &vf);
+	cx18_s_std(NULL, NULL, std);
+	cx18_s_frequency(NULL, NULL, &vf);
 	return 0;
 }
 
drivers/media/pci/cx18/cx18-ioctl.c +73 -41

330 lines not on this page · raw message

drivers/media/pci/cx18/cx18-ioctl.h +6 -3
index 97cd9f99e22d9676d427a7e9e12fb572a91b2a82..62c1238021d42419a0d0ef7b520d3e020b3b1f6e 100644
@@ -12,6 +12,9 @@ u16 cx18_service2vbi(int type);
 void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal);
 u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt);
 void cx18_set_funcs(struct video_device *vdev);
-int cx18_s_std(struct file *file, void *fh, v4l2_std_id std);
-int cx18_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf);
-int cx18_s_input(struct file *file, void *fh, unsigned int inp);
+int cx18_s_std(struct file *file, struct video_device_state *state,
+	       v4l2_std_id std);
+int cx18_s_frequency(struct file *file, struct video_device_state *state,
+		     const struct v4l2_frequency *vf);
+int cx18_s_input(struct file *file, struct video_device_state *state,
+		 unsigned int inp);
drivers/media/pci/cx23885/cx23885-417.c +33 -20

134 lines not on this page · raw message

drivers/media/pci/cx23885/cx23885-ioctl.c +4 -4
index a8ccad07cf50303895a14e29751b39a8c365fa17..e154b6777fddeefbac041a4e04c164574d65079b 100644
@@ -11,8 +11,8 @@
 #include "cx23885-ioctl.h"
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-int cx23885_g_chip_info(struct file *file, void *fh,
-			 struct v4l2_dbg_chip_info *chip)
+int cx23885_g_chip_info(struct file *file, struct video_device_state *state,
+			struct v4l2_dbg_chip_info *chip)
 {
 	struct cx23885_dev *dev = video_drvdata(file);
 
@@ -47,7 +47,7 @@ static int cx23417_g_register(struct cx23885_dev *dev,
 	return 0;
 }
 
-int cx23885_g_register(struct file *file, void *fh,
+int cx23885_g_register(struct file *file, struct video_device_state *state,
 		       struct v4l2_dbg_register *reg)
 {
 	struct cx23885_dev *dev = video_drvdata(file);
@@ -79,7 +79,7 @@ static int cx23417_s_register(struct cx23885_dev *dev,
 	return 0;
 }
 
-int cx23885_s_register(struct file *file, void *fh,
+int cx23885_s_register(struct file *file, struct video_device_state *state,
 		       const struct v4l2_dbg_register *reg)
 {
 	struct cx23885_dev *dev = video_drvdata(file);
drivers/media/pci/cx23885/cx23885-ioctl.h +4 -5
index 14bfe9e4ec264f38f19864ea34229c9c8a4e7ed0..89c7bfe0ec16d9fdb056f815add09c24cc41e846 100644
@@ -10,15 +10,14 @@
 #ifndef _CX23885_IOCTL_H_
 #define _CX23885_IOCTL_H_
 
-int cx23885_g_chip_info(struct file *file, void *fh,
-			 struct v4l2_dbg_chip_info *chip);
+int cx23885_g_chip_info(struct file *file, struct video_device_state *state,
+			struct v4l2_dbg_chip_info *chip);
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-int cx23885_g_register(struct file *file, void *fh,
+int cx23885_g_register(struct file *file, struct video_device_state *state,
 		       struct v4l2_dbg_register *reg);
 
-
-int cx23885_s_register(struct file *file, void *fh,
+int cx23885_s_register(struct file *file, struct video_device_state *state,
 		       const struct v4l2_dbg_register *reg);
 
 #endif
drivers/media/pci/cx23885/cx23885-vbi.c +2 -3
index 40817cc52fc1ee256be86319638d0d26116e51c0..049aa0d4359cf789ddf3955347d30a636da1c7e8 100644
@@ -32,9 +32,8 @@ MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
 #define VBI_NTSC_LINE_COUNT 12
 #define VBI_PAL_LINE_COUNT 18
 
-
-int cx23885_vbi_fmt(struct file *file, void *priv,
-	struct v4l2_format *f)
+int cx23885_vbi_fmt(struct file *file, struct video_device_state *state,
+		    struct v4l2_format *f)
 {
 	struct cx23885_dev *dev = video_drvdata(file);
 
drivers/media/pci/cx23885/cx23885-video.c +47 -35

207 lines not on this page · raw message

drivers/media/pci/cx23885/cx23885.h +2 -2
index 8ba1f306238cb3c136c1fbae8d29b581aeb566e5..9a0d50ac836953b3460d39d0dba3326e0ba9dfab 100644
@@ -585,8 +585,8 @@ int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm);
 
 /* ----------------------------------------------------------- */
 /* cx23885-vbi.c                                               */
-extern int cx23885_vbi_fmt(struct file *file, void *priv,
-	struct v4l2_format *f);
+int cx23885_vbi_fmt(struct file *file, struct video_device_state *state,
+		    struct v4l2_format *f);
 extern void cx23885_vbi_timeout(unsigned long data);
 extern const struct vb2_ops cx23885_vbi_qops;
 extern int cx23885_vbi_irq(struct cx23885_dev *dev, u32 status);
drivers/media/pci/cx25821/cx25821-video.c +39 -18

160 lines not on this page · raw message

drivers/media/pci/cx88/cx88-blackbird.c +31 -16

143 lines not on this page · raw message

drivers/media/pci/cx88/cx88-vbi.c +1 -1
index e3e379e6f6207b6ebf08327263d7087f5122d236..4d702acdfa75a8a95554d0b7f97d11bd7a9d25c3 100644
@@ -20,7 +20,7 @@ MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
 
 /* ------------------------------------------------------------------ */
 
-int cx8800_vbi_fmt(struct file *file, void *priv,
+int cx8800_vbi_fmt(struct file *file, struct video_device_state *state,
 		   struct v4l2_format *f)
 {
 	struct cx8800_dev *dev = video_drvdata(file);
drivers/media/pci/cx88/cx88-video.c +37 -19

168 lines not on this page · raw message

drivers/media/pci/cx88/cx88.h +1 -1
index 2ff3226a52ec4de3b5f4b9f85cca9b8ac489a01f..80d0665063c95a0655d654a7f5dc05f2fa3f531f 100644
@@ -656,7 +656,7 @@ int cx88_stop_audio_dma(struct cx88_core *core);
 /* cx88-vbi.c                                                  */
 
 /* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
-int cx8800_vbi_fmt(struct file *file, void *priv,
+int cx8800_vbi_fmt(struct file *file, struct video_device_state *state,
 		   struct v4l2_format *f);
 
 void cx8800_stop_vbi_dma(struct cx8800_dev *dev);
drivers/media/pci/dt3155/dt3155.c +17 -8
index 7bddcbba4cf1ba2998afbfe1e961ad89a303f1c2..de7944006438cfc50b1489d6de7a834c84a5b7bf 100644
@@ -285,7 +285,8 @@ static const struct v4l2_file_operations dt3155_fops = {
 	.poll = vb2_fop_poll
 };
 
-static int dt3155_querycap(struct file *filp, void *p,
+static int dt3155_querycap(struct file *filp,
+			   struct video_device_state *state,
 			   struct v4l2_capability *cap)
 {
 	strscpy(cap->driver, DT3155_NAME, sizeof(cap->driver));
@@ -294,7 +295,8 @@ static int dt3155_querycap(struct file *filp, void *p,
 }
 
 static int dt3155_enum_fmt_vid_cap(struct file *filp,
-				   void *p, struct v4l2_fmtdesc *f)
+				   struct video_device_state *state,
+				   struct v4l2_fmtdesc *f)
 {
 	if (f->index)
 		return -EINVAL;
@@ -302,7 +304,9 @@ static int dt3155_enum_fmt_vid_cap(struct file *filp,
 	return 0;
 }
 
-static int dt3155_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
+static int dt3155_fmt_vid_cap(struct file *filp,
+			      struct video_device_state *state,
+			      struct v4l2_format *f)
 {
 	struct dt3155_priv *pd = video_drvdata(filp);
 
@@ -316,7 +320,8 @@ static int dt3155_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f)
 	return 0;
 }
 
-static int dt3155_g_std(struct file *filp, void *p, v4l2_std_id *norm)
+static int dt3155_g_std(struct file *filp, struct video_device_state *state,
+			v4l2_std_id *norm)
 {
 	struct dt3155_priv *pd = video_drvdata(filp);
 
@@ -324,7 +329,8 @@ static int dt3155_g_std(struct file *filp, void *p, v4l2_std_id *norm)
 	return 0;
 }
 
-static int dt3155_s_std(struct file *filp, void *p, v4l2_std_id norm)
+static int dt3155_s_std(struct file *filp, struct video_device_state *state,
+			v4l2_std_id norm)
 {
 	struct dt3155_priv *pd = video_drvdata(filp);
 
@@ -345,7 +351,8 @@ static int dt3155_s_std(struct file *filp, void *p, v4l2_std_id norm)
 	return 0;
 }
 
-static int dt3155_enum_input(struct file *filp, void *p,
+static int dt3155_enum_input(struct file *filp,
+			     struct video_device_state *state,
 			     struct v4l2_input *input)
 {
 	if (input->index > 3)
@@ -361,7 +368,8 @@ static int dt3155_enum_input(struct file *filp, void *p,
 	return 0;
 }
 
-static int dt3155_g_input(struct file *filp, void *p, unsigned int *i)
+static int dt3155_g_input(struct file *filp, struct video_device_state *state,
+			  unsigned int *i)
 {
 	struct dt3155_priv *pd = video_drvdata(filp);
 
@@ -369,7 +377,8 @@ static int dt3155_g_input(struct file *filp, void *p, unsigned int *i)
 	return 0;
 }
 
-static int dt3155_s_input(struct file *filp, void *p, unsigned int i)
+static int dt3155_s_input(struct file *filp, struct video_device_state *state,
+			  unsigned int i)
 {
 	struct dt3155_priv *pd = video_drvdata(filp);
 
drivers/media/pci/intel/ipu3/ipu3-cio2.c +20 -9
index a87f105beb5e267fd450b8a36ef9b0e0ecafc598..0cf3f0ffc9375dd93305d1ecfeaea7c3c65407c6 100644
@@ -1062,7 +1062,8 @@ static const struct vb2_ops cio2_vb2_ops = {
 
 /**************** V4L2 interface ****************/
 
-static int cio2_v4l2_querycap(struct file *file, void *fh,
+static int cio2_v4l2_querycap(struct file *file,
+			      struct video_device_state *state,
 			      struct v4l2_capability *cap)
 {
 	strscpy(cap->driver, CIO2_NAME, sizeof(cap->driver));
@@ -1071,7 +1072,8 @@ static int cio2_v4l2_querycap(struct file *file, void *fh,
 	return 0;
 }
 
-static int cio2_v4l2_enum_fmt(struct file *file, void *fh,
+static int cio2_v4l2_enum_fmt(struct file *file,
+			      struct video_device_state *state,
 			      struct v4l2_fmtdesc *f)
 {
 	if (f->index >= ARRAY_SIZE(formats))
@@ -1083,7 +1085,9 @@ static int cio2_v4l2_enum_fmt(struct file *file, void *fh,
 }
 
 /* The format is validated in cio2_video_link_validate() */
-static int cio2_v4l2_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
+static int cio2_v4l2_g_fmt(struct file *file,
+			   struct video_device_state *state,
+			   struct v4l2_format *f)
 {
 	struct cio2_queue *q = file_to_cio2_queue(file);
 
@@ -1092,7 +1096,9 @@ static int cio2_v4l2_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 	return 0;
 }
 
-static int cio2_v4l2_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
+static int cio2_v4l2_try_fmt(struct file *file,
+			     struct video_device_state *state,
+			     struct v4l2_format *f)
 {
 	const struct ipu3_cio2_fmt *fmt;
 	struct v4l2_pix_format_mplane *mpix = &f->fmt.pix_mp;
@@ -1123,18 +1129,21 @@ static int cio2_v4l2_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
 	return 0;
 }
 
-static int cio2_v4l2_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
+static int cio2_v4l2_s_fmt(struct file *file,
+			   struct video_device_state *state,
+			   struct v4l2_format *f)
 {
 	struct cio2_queue *q = file_to_cio2_queue(file);
 
-	cio2_v4l2_try_fmt(file, fh, f);
+	cio2_v4l2_try_fmt(file, state, f);
 	q->format = f->fmt.pix_mp;
 
 	return 0;
 }
 
 static int
-cio2_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
+cio2_video_enum_input(struct file *file, struct video_device_state *state,
+		      struct v4l2_input *input)
 {
 	if (input->index > 0)
 		return -EINVAL;
@@ -1146,7 +1155,8 @@ cio2_video_enum_input(struct file *file, void *fh, struct v4l2_input *input)
 }
 
 static int
-cio2_video_g_input(struct file *file, void *fh, unsigned int *input)
+cio2_video_g_input(struct file *file, struct video_device_state *state,
+		   unsigned int *input)
 {
 	*input = 0;
 
@@ -1154,7 +1164,8 @@ cio2_video_g_input(struct file *file, void *fh, unsigned int *input)
 }
 
 static int
-cio2_video_s_input(struct file *file, void *fh, unsigned int input)
+cio2_video_s_input(struct file *file, struct video_device_state *state,
+		   unsigned int input)
 {
 	return input == 0 ? 0 : -EINVAL;
 }
drivers/media/pci/intel/ipu6/ipu6-isys-video.c +26 -15

123 lines not on this page · raw message

drivers/media/pci/ivtv/ivtv-driver.c +2 -6
index 72a8f76a41f45091fdd4fe0335ecb828d555eb9c..a2016cbdb896df066158a2f85db8c8964cb95328 100644
@@ -1249,13 +1249,9 @@ int ivtv_init_on_first_open(struct ivtv *itv)
 {
 	struct v4l2_frequency vf;
 	/* Needed to call ioctls later */
-	struct ivtv_open_id fh;
 	int fw_retry_count = 3;
 	int video_input;
 
-	fh.itv = itv;
-	fh.type = IVTV_ENC_STREAM_TYPE_MPG;
-
 	if (test_bit(IVTV_F_I_FAILED, &itv->i_flags))
 		return -ENXIO;
 
@@ -1297,13 +1293,13 @@ int ivtv_init_on_first_open(struct ivtv *itv)
 
 	video_input = itv->active_input;
 	itv->active_input++;	/* Force update of input */
-	ivtv_s_input(NULL, &fh, video_input);
+	ivtv_s_input(NULL, NULL, video_input);
 
 	/* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
 	   in one place. */
 	itv->std++;		/* Force full standard initialization */
 	itv->std_out = itv->std;
-	ivtv_s_frequency(NULL, &fh, &vf);
+	ivtv_s_frequency(NULL, NULL, &vf);
 
 	if (itv->card->v4l2_capabilities & V4L2_CAP_VIDEO_OUTPUT) {
 		/* Turn on the TV-out: ivtv_init_mpeg_decoder() initializes
drivers/media/pci/ivtv/ivtv-ioctl.c +156 -69

150 lines not on this page · raw message

drivers/media/pci/ivtv/ivtv-ioctl.h +4 -2
index 7f8c6f43d397f050a8116429db7a9a7accc0336b..59adcae0c2f39020b73f1100c0a6ae7051b528a8 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/mgb4/mgb4_vin.c +36 -19

55 lines not on this page · raw message

drivers/media/pci/mgb4/mgb4_vout.c +32 -17

49 lines not on this page · raw message

drivers/media/pci/saa7134/saa7134-empress.c +8 -4
index 8c4f70e4177d1836ad685be851df63b234674c40..03fbced7af3e6d012c8444e4241bd93c8c02b4ce 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7134/saa7134-video.c +58 -38

96 lines not on this page · raw message

drivers/media/pci/saa7134/saa7134.h +22 -16
index 9f27e3775c273e1b4738f022399d624b18f695cc..5775df2194d1d359b3496e29f23f42154420ab6e 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7146/hexium_gemini.c +7 -3
index 40b35098f3ead1d63378d05beb2ccddf3977a2da..cdbdfdf627362b202528e40efbd38008e464f4f9 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7146/hexium_orion.c +7 -3
index a2076728c6210e9d5442f51fbbc13a87371973e4..0075f0d2b962b46960f650256425ca7620c3a8a6 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7146/mxb.c +33 -13

46 lines not on this page · raw message

drivers/media/pci/saa7164/saa7164-encoder.c +24 -15
index 66d650b5f69af1eac9117b9c65ac7c39883f6f21..1a193a4c05a45f421f5666e47a46fde0b702f47b 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7164/saa7164-vbi.c +16 -11
index 57e4362c0d19d0d3a5f0be1ee58cd141fdf62462..74c71a61ab4db045db44a8283063337992bdf226 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/saa7164/saa7164.h +6 -3
index 94e987e7b5e5d4af8f3cdc7c148eb2b33b1076b9..612890fa19c1680b5327f54a8e943fd15899f7cf 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c +30 -16

46 lines not on this page · raw message

drivers/media/pci/solo6x10/solo6x10-v4l2.c +21 -11
index 35715b21dbdffc80de68990b88836700816e7cb6..7c0489c7b0d9f0c97e3386ccc2dcd96dcd3cad71 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/ttpci/budget-av.c +7 -3
index 69f5e810f9b54df5e3d69a5d06a5cefc12cef6a9..63505f445b67833015aa9aad8314e256d386ff30 100644

Lines of this file are not shown. View the raw message.

drivers/media/pci/tw5864/tw5864-video.c +32 -17

49 lines not on this page · raw message

drivers/media/pci/tw68/tw68-video.c +28 -15

43 lines not on this page · raw message

drivers/media/pci/tw686x/tw686x-video.c +34 -19

53 lines not on this page · raw message

drivers/media/pci/zoran/zoran_driver.c +29 -15

44 lines not on this page · raw message

drivers/media/platform/allegro-dvt/allegro-core.c +31 -18

49 lines not on this page · raw message

drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c +12 -6
index 11d85f5342f0f41f9f6f70c18344344e3f26dade..ca940876f11dd3e8c4160aacffda6c8fa3e81f98 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/amlogic/c3/isp/c3-isp-params.c +6 -3
index c80667dd766210d2b2e1ee60c8254a5814b9d81b..b67409f8a6f1d7dc2f500e361618725f8fb144be 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c +6 -3
index 8a5d7e1a30c952add138ffb4eb5c7ad36d54d233..1e5e5ae48445c7a7f6f668dc346a91eaa0553383 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/amlogic/meson-ge2d/ge2d.c +25 -11
index 5744853a40035e9973e605dd3ffec508641470f2..68d0cdd6bee0893c19087dc67aec972ccf88ddeb 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/amphion/vdec.c +19 -11
index 32eef2fd1f2a90243256709d2a6a1f7d62a6816a..3b41bbad02139cb376def8f8a650416ef98ffd79 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/amphion/venc.c +33 -16

49 lines not on this page · raw message

drivers/media/platform/aspeed/aspeed-video.c +34 -16

50 lines not on this page · raw message

drivers/media/platform/atmel/atmel-isi.c +24 -12
index a05a744cbb7569abff60ccf1a0825a9c3c52ed8a..7154cef73da0c23fdf3931938645cbcd135dc631 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/broadcom/bcm2835-unicam.c +22 -11
index f10064107d543caf867249d0566a0f42d6d8c4c6..e5cccad04b010bf9533035fb787824f4f606beed 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/chips-media/coda/coda-common.c +43 -26

69 lines not on this page · raw message

drivers/media/platform/chips-media/wave5/wave5-helper.c +1 -1
index f03ad9c0de2215794b2456c39652785fff236966..9916b2277926a1a815d5dbf7d6459e98212904c2 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/chips-media/wave5/wave5-helper.h +2 -1
index 976a402e426ff329490717925a08a76d777cbe3e..0bb27137781adcc8987c54196d16883b812cdf5e 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +39 -15

54 lines not on this page · raw message

drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +45 -17

62 lines not on this page · raw message

drivers/media/platform/imagination/e5010-jpeg-enc.c +23 -11
index c4e0097cb8b7fa310c2c5519d7af4e6e3b378915..840debba40334e7946a171568f6f2bbfcf448b80 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/intel/pxa_camera.c +23 -11
index bef1e7137f23f02ef0005058c59fb712ba467cea..aa397eccd31a732da54330bb761f1af219f75ed1 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/m2m-deinterlace.c +22 -12
index e07e57d4206baa5e7a467298cb240c3a2cd57cd8..b17d153e0440af996d490bd5468e68a019df9e30 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/marvell/mcam-core.c +30 -22

52 lines not on this page · raw message

drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +28 -16

44 lines not on this page · raw message

drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c +22 -12
index 03c07948dfdd07c6395c391ccad1788b08b1a867..3ca20364730e131fad4f4db54cea70a2ee2006c5 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c +16 -9
index 9ef956b565a791429a477dc96567453cb189d817..ce3806b382e34ac370099a35b30ace72f435866b 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +34 -18

52 lines not on this page · raw message

drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +33 -17

50 lines not on this page · raw message

drivers/media/platform/microchip/microchip-isc-base.c +22 -11
index a7cdc743fda71db0ffbf499cb4b9ca18c9e7abf2..9a1a01d231d561bd2f360f320b1b0438a46d36f9 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nuvoton/npcm-video.c +29 -14

43 lines not on this page · raw message

drivers/media/platform/nvidia/tegra-vde/v4l2.c +24 -14
index d94978ae2baf3394206ad7c3eb7a400aeee47cf7..7e96043f0a8043872c72f77cce0955622e0b8e0f 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/dw100/dw100.c +23 -12
index 97744c7b7c034cadfdd3f6d76165b4da85fa3d16..7f127f0dbe16227994998d355a22125d58e139c8 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +33 -19

52 lines not on this page · raw message

drivers/media/platform/nxp/imx-pxp.c +22 -12
index 6cc9b07ea53a002c2eda0fd6062096f5527ad62c..ed480a63eae071addfa14f510b867cea9d058396 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/imx7-media-csi.c +14 -7
index 34a92642bbfe7b7ce9c85fbaf346c6f595425cc9..44664c48d770601a8bed4a76a547ac377e336067 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +10 -5
index 00afcbfbdde4840145a2cec8acbafea604ce2f0e..d447b752d6f18d41602b22806a17c67366ae346b 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +12 -6
index 13682bf6e9f8895bb9eb1f92d5f74b0d5968544e..e8fafd15930564c0d81d579674c87ff38bc8edbb 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/nxp/mx2_emmaprp.c +20 -11
index 3aae8c0b690c0b1b0dd4f05a1c9184b089719a20..9fec60210a088110147246865fe9d844c7cb5d44 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/qcom/camss/camss-video.c +18 -9
index 831486e14754ab3a24b077e21be14ea3169220a4..e5315df8929da41c9c952adbb8f1465691a763e3 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/qcom/iris/iris_vidc.c +33 -15

48 lines not on this page · raw message

drivers/media/platform/qcom/venus/vdec.c +19 -10
index 55c27345b7d89bf400e216ed9aa59a871e501a44..4c440bf2f52bdd61909ea3e364eccb0865072feb 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/qcom/venus/venc.c +25 -13
index fba07557a3996a55fcd6a4f65376c418ec0c92a7..8fe86139a5d6e0b1e896a4bcd619aa450ca2fd27 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +27 -15

42 lines not on this page · raw message

drivers/media/platform/raspberrypi/rp1-cfe/cfe.c +26 -14
index 62dca76b468d1be4efa6fd4e68a89b9be0cc454b..9f4dd658ec2f1c55f61c686b84b9870666d8512f 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/rcar-vin/rcar-v4l2.c +14 -7
index 079dbaf016c25139e2ac82be63d8fce0d11fd208..5f5dc1c9904e65a23dadb181cafda7db178486e0 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/rcar_drif.c +20 -10
index 11bf47fb8266dc45df40cac003f039582251b945..79d3af9c7b0da9e9b59c4f3e8e5535c4e3f73b48 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/rcar_fdp1.c +12 -6
index e615c56083f13b183be5b44764f24894f7539838..ef8054dbd40c79f583f1d7795f954d816dc3696b 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/rcar_jpu.c +14 -7
index 46ea259a2bb9d3088a977f1140f48959fcde4518..244533a48878976fd850835c47add97b58827978 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/renesas-ceu.c +24 -12
index deed49d0fb10e0d7834a30293f6c1ede7055409a..b21cdc118dc70654cf8f87a1ad00228697aefe69 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +12 -6
index 162e2ace6931840ee052e1565587d021fc87307f..4f2e5a99c5cd142b21a2cf29a79dbf73463061b6 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/sh_vou.c +27 -14

41 lines not on this page · raw message

drivers/media/platform/renesas/vsp1/vsp1_histo.c +6 -3
index 390ea50f1595ad7702bec46e9b9f3e237c73a622..69091fa5a7cd46f23ccb4f50a55901b12b6e13cb 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/renesas/vsp1/vsp1_video.c +12 -6
index 75f9a1a85d558ff0afa2fdaf8c43a22ddbd694a8..9130f46e433a79c1ac2848fc347067f6c3f41c28 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/rockchip/rga/rga.c +16 -8
index 776046de979aa0ded6734216bf179c32ae8fe5a9..87d01ed5c3ddcf3d12b09021bd43c2cfc68f8eef 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -6
index 6dcefd144d5abe358323e37ac6133c6134ac636e..38541f482b2d0dcf23546a0b9f893fb8544bcc40 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/rockchip/rkisp1/rkisp1-params.c +10 -5
index f1585f8fa0f478304f74317fd9dd09199c94ec82..83dae25e3c10a0df437b5052ccae64221f460899 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c +6 -3
index d5fdb8f82dc78b0143f71d76f36817db389921b7..043f23ed9cbd12816f3355e54de830a1e7429aa9 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/rockchip/rkvdec/rkvdec.c +22 -12
index 9fa80ab3c62b7753e6c992aefd106ee99ed375e4..c87e206a65f0b33c10bf71b3d64c46bdb62ebd40 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/exynos-gsc/gsc-m2m.c +29 -15

44 lines not on this page · raw message

drivers/media/platform/samsung/exynos4-is/fimc-capture.c +29 -16

45 lines not on this page · raw message

drivers/media/platform/samsung/exynos4-is/fimc-isp-video.c +20 -12
index ad219ac1b95137a703ea709d12139cca6b2e2332..1a985a9b6c56e4f03977df277328961c62854703 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/exynos4-is/fimc-lite.c +23 -13
index 0ce293b0718b6a496b06275ebe778f118951d7bf..8b22b68b00b05f336c7881276363a594105b73cd 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/exynos4-is/fimc-m2m.c +14 -7
index 562c57f186c61546175b4f902f1da18fbb2f25fe..4efa54f1e7a671741b5c16c9a954af572150dfd8 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/s3c-camif/camif-capture.c +36 -18

54 lines not on this page · raw message

drivers/media/platform/samsung/s5p-g2d/g2d.c +17 -9
index ffb9bee6cb9d4759647925d791a13e1f0ce3f299..e7bf9bc50c3435ca190a194aef9bef0d1f5374c0 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c +22 -12
index 81792f7f8b1671dba2023f99b2779784d9a14b8c..5a5b24fd312c8f96b684e533b21cc4724f8f2a0b 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +31 -17

48 lines not on this page · raw message

drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c +33 -18

51 lines not on this page · raw message

drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c +17 -9
index 56169b70652d3aaf7c3c395a630a29023cbd9722..dc8305d5d445633dbd01d0a2d214bbd30e804334 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/st/sti/delta/delta-v4l2.c +29 -15

44 lines not on this page · raw message

drivers/media/platform/st/sti/hva/hva-v4l2.c +31 -15

46 lines not on this page · raw message

drivers/media/platform/st/stm32/dma2d/dma2d.c +12 -6
index 468c247ba3282c6f4d092985465cd3d0907b1c07..8bfe415eec7e06bb9ce680d6cd0732ba7046fd2b 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/st/stm32/stm32-dcmi.c +28 -14

42 lines not on this page · raw message

drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-bytecap.c +13 -7
index 1c1b6b48918ee26f245d4cf99086473c44e74123..1d6478e9123a21f530b90c3ba31a630717020ebb 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c +16 -9
index 744197b0fccb03d7e1ad634f00ff1566d57e735c..881345ddb4cb6d1c865698f4fc33b2968d86c297 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +16 -8
index 65879f4802c00cd1b65f02b6bf00f27a72d674ce..4bd9f9aa4349f98f1e56561a066cf3fd7dff129c 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/sunxi/sun8i-di/sun8i-di.c +20 -11
index eb519afb30ca10c6f4370626d0dce9e7183b28e5..ff1cf37395b9de6ef0973bd0372eb818eaf11692 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c +22 -12
index 89992feaab6082b438eec189c0de93568d09f911..41cf132993b9da9ca24061f99d5ed8b38c548b8f 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c +32 -15

47 lines not on this page · raw message

drivers/media/platform/ti/am437x/am437x-vpfe.c +34 -18

52 lines not on this page · raw message

drivers/media/platform/ti/cal/cal-video.c +37 -17

54 lines not on this page · raw message

drivers/media/platform/ti/davinci/vpif_capture.c +54 -40

94 lines not on this page · raw message

drivers/media/platform/ti/davinci/vpif_display.c +36 -22

58 lines not on this page · raw message

drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +13 -7
index b75aa363d1bf25f8c31b403c3aede0b31333c56b..ac9a87ee06b1090456508c87893ac0a265c93ae9 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/ti/omap/omap_vout.c +32 -17

49 lines not on this page · raw message

drivers/media/platform/ti/omap3isp/ispvideo.c +35 -18

53 lines not on this page · raw message

drivers/media/platform/ti/vpe/vpe.c +15 -10
index 6029d4e8e0bd34d60f1addb91a51bf5fd0709341..5f1865ecbb266e4beb4f0f7ba1a5b425c2703012 100644

Lines of this file are not shown. View the raw message.

drivers/media/platform/verisilicon/hantro_v4l2.c +30 -17

47 lines not on this page · raw message

drivers/media/platform/via/via-camera.c +24 -18

42 lines not on this page · raw message

drivers/media/platform/xilinx/xilinx-dma.c +10 -5
index fcfe0883aba5fb8bcf954ce4be956edb39e610cb..8102e09993e4a9ce5428a0a49ef01c8e5de223f6 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/dsbr100.c +10 -5
index 9a45cda0577993206c7e287ce03467713f16ee41..9978454af6a33e863e320a6c16497998a44a1dca 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-cadet.c +12 -6
index 5110754e1a31782b74d4c9dcbfa79642a532543a..842002098e8eeb960e7128310f41e86efe5ce943 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-isa.c +12 -6
index 1a144536ffa7580c8e8d96c149a68eb788c29346..32f483f12ce052ec8ccf870eb42fae661b5fff67 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-keene.c +10 -5
index f3b57f0cb1ec4064aa7e81b1c6425f937ca819de..168e1ff2a0ae64a5af57ceefd7e57491f1b347e1 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-ma901.c +10 -5
index 657c3dda6648a8ff3bf67630c7cc30d857367fe0..61b745a13fc29e03579a29bb7f2894513cf5e872 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-miropcm20.c +10 -5
index 67712ab3d564435c9e7c2c46d103ea7f8166c2ea..f9d5d35a775378a118fd4cc86838273baf8911ba 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-mr800.c +12 -6
index cb0437b4c331250863c9e08c58bf0f32fdad4362..368995ce53ae950cd14d5616ede7a3429cdfb9bd 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-raremono.c +12 -7
index f60775b005e1d1dcc63b9d095cfb5320c20888e1..54460ea13ed9e72ef4c0109be9e38fc8f1bed665 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-sf16fmi.c +10 -5
index 1fb88c2b916c4510e915b2cb478085134a9f09c3..048f7990a5d4c318b3f7416ec091f6045b8c7a10 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-si476x.c +19 -9
index 9980346cb5ea3897e515a0042cdb6c7b24334b01..9a5bb0259f28101cf3d0838ba6513968d7065762 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-tea5764.c +10 -5
index dd85b0b1bcd962d59acdbefb8c74e469914daf3f..a4f4837e896f50b7aa9c82aaa8a880620f5d3988 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-tea5777.c +14 -7
index fb9de7bbcd195e193d1c91661b0e8900bbefc9aa..5d2f0b182fc4891233168d92db3ea803d450e19a 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/radio-timb.c +15 -11
index a6069b106fd3048b2c730e9c45fd82f0b7302bfb..8d5e4eb0b964b56e2bac71bd626779d224638d9f 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/si470x/radio-si470x-common.c +15 -10
index af0a709100994c1c39a83ac6fcabefebf2783459..26d515903ea583a17476059567824b60a9bb2b69 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/si4713/radio-platform-si4713.c +12 -6
index 4132968110e3c54e86642bef480793ee06adb883..903e89336af47c03da9258d8ab82a7a8647f5494 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/si4713/radio-usb-si4713.c +10 -5
index 2cf36c8abddeacdb70f35feab8994245cc43d32f..d566d8b848db97d8a0e897dd276e6734ae3dbd54 100644

Lines of this file are not shown. View the raw message.

drivers/media/radio/tea575x.c +14 -7
index c37315226c427ac3e382055e0d3f8057d8ef6870..659f43bb1e8d9ae8e096c93e4165fa9e6b900ffb 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vicodec/vicodec-core.c +34 -20

54 lines not on this page · raw message

drivers/media/test-drivers/vim2m.c +36 -20

56 lines not on this page · raw message

drivers/media/test-drivers/vimc/vimc-capture.c +13 -7
index 7f6124025fc9dc9716251565c504bc33ad81b345..447a76a55e68e0cf79a3087164d602e493dce4cd 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/visl/visl-video.c +22 -12
index 8be505d8908c98bb50118dfa2f491d5ac68772ec..bcba5959432df24d4011c3be20c3acd226540991 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-core.c +119 -84

203 lines not on this page · raw message

drivers/media/test-drivers/vivid/vivid-meta-cap.c +4 -2
index c7aaecc0b5a24726639a253accfc50383a84e846..3206ccdeb377f54b76d8fde199aa6e4049ff8aae 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-meta-cap.h +4 -2
index 4670d00d1576df0e41a961ad5d5040d92787dfa1..c11758df76c3f86d0972b653ebbeefe4d8601d22 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-meta-out.c +4 -2
index 55e5e5dec2f2ab1bdc01a2d1d479a6f1eb758299..9b6b556c475f713e23098d9b62dce71945295dac 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-meta-out.h +6 -3
index 0c639b7c284276f4c5e5180b765dbc17d884927f..dc3594de999a052708fb35944565e939357ac36a 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-radio-rx.c +12 -4
index b5e3026f883ee69d48db552623d7961677eb91fd..7ff89e6488fcde1d8ff2a1a996a3ac8d2d0dca83 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-radio-rx.h +12 -4
index a2ae17c78ecee08d42cd3a8e8d30b01caec1bb99..30dcb534862b80d2447e089c31041406ae07e284 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-radio-tx.c +4 -2
index ada60722066eaceef1371d711e5bc408ff0fa6b3..a81b74b45a6441a43c0773326d2a39d4fc5544f7 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-radio-tx.h +4 -2
index 20cb6f1363ffd07805d1c7c86f6d4111ac5948a5..d2e636e20dac373058d04e72f41c7d3a0f0d6f9b 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-sdr-cap.c +20 -10
index 2664a593e8e1b5b03b0aec03169359c238cca205..0a8b78f423ba56425b917491bb1cfa256a558137 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-sdr-cap.h +21 -9
index 3d8eeabbfc1073e6aab1ce493442a4ae10b36369..55417622cf6c8bf2166abcb7c65e0a346e0ec5bb 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-touch-cap.c +15 -7
index 36a781fa17bc3daaf1d949a7f1c94ebb9aecb7c0..e246d7006913e959089d7bff84fbeb9f3eb3cb13 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-touch-cap.h +15 -7
index 07e514046ae80f1347aec00f1da1cdaa7acc4721..19dd5cb343fc67815d3c3b84d30ed99c634167a3 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vbi-cap.c +18 -8
index 791382a54b4f0a111cf32a4dca82e57a8c1c2da9..fa2fc5613fd8df12886a985da70dda65183b012e 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vbi-cap.h +16 -6
index ec2d200c9e0d3506abf12e198ff4c308fdf68f90..054a939863aad7d30be10ed13256583a4fe0227e 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vbi-out.c +14 -8
index 7b3ea96744bb04e37644bc288c5879ac2812fbb3..c7396b7c199bded792fc20a575db30f4a0b8a234 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vbi-out.h +13 -5
index a28e55519ade286066d38732ca6815786e18ff90..9759860f9bb1600c71b02314c12f6d54faf2425d 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vid-cap.c +74 -40

114 lines not on this page · raw message

drivers/media/test-drivers/vivid/vivid-vid-cap.h +82 -35

117 lines not on this page · raw message

drivers/media/test-drivers/vivid/vivid-vid-common.c +15 -9
index 786a1aa3b26b7058a025895ba1b1f4cf03940376..30b7c9d4ff7d7b33d09b5d99276c0cca4159e054 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vid-common.h +22 -12
index fb5878174dba4cc1ed65846f85bca4020cae09cc..00a2ab66eae0b97c4d1a0dc6565d49682e577c32 100644

Lines of this file are not shown. View the raw message.

drivers/media/test-drivers/vivid/vivid-vid-out.c +69 -53

122 lines not on this page · raw message

drivers/media/test-drivers/vivid/vivid-vid-out.h +67 -28

95 lines not on this page · raw message

drivers/media/usb/airspy/airspy.c +20 -17
index 08f0920cf6ca2f2f0fcc8e9a7b1632488d9af5f5..c91db6296c2327fdd6e16874c99c56470578511c 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/au0828/au0828-video.c +49 -25

74 lines not on this page · raw message

drivers/media/usb/cx231xx/cx231xx-417.c +18 -10
index c695a97e202b7134f66d9b1438ebabfcf5628def..183a46a46ba491956807024d3d611c8b15d4f7de 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/cx231xx/cx231xx-video.c +52 -27

79 lines not on this page · raw message

drivers/media/usb/cx231xx/cx231xx.h +22 -17
index 19f5036a78d7f42aebdfe164025477a68eadf1b7..0e92db0b0455333d831095946d0d791b2a017bae 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/dvb-usb/cxusb-analog.c +32 -16

48 lines not on this page · raw message

drivers/media/usb/em28xx/em28xx-video.c +58 -29

87 lines not on this page · raw message

drivers/media/usb/go7007/go7007-v4l2.c +49 -26

75 lines not on this page · raw message

drivers/media/usb/gspca/gspca.c +34 -17

51 lines not on this page · raw message

drivers/media/usb/hackrf/hackrf.c +24 -15
index 0b50de8775a38deb11c50da799c98b1a1ef14d0a..4b5a2f5f311c107ab6c67d946fd0c89b43ead5fa 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/hdpvr/hdpvr-video.c +39 -21

60 lines not on this page · raw message

drivers/media/usb/msi2500/msi2500.c +21 -10
index 33099f39146afd6f59e0bd6b316d8f9e1eaa6a64..6cae78276da10be75145f3772784f5bbcc22be36 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/pvrusb2/pvrusb2-v4l2.c +67 -31

98 lines not on this page · raw message

drivers/media/usb/pwc/pwc-v4l.c +30 -14

44 lines not on this page · raw message

drivers/media/usb/s2255/s2255drv.c +36 -19

55 lines not on this page · raw message

drivers/media/usb/stk1160/stk1160-v4l.c +26 -14
index 715ce1dcb304129d76d73ba327858da4e89396a4..4a9efc72b47e11a7c99ba7b16ad6fafec0efd3e8 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/usbtv/usbtv-video.c +16 -8
index de0328100a60dd7b4335e208fee4cd2864d5b99d..da256a4cf2481662c9df5f105f8649ed658558d1 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/uvc/uvc_metadata.c +11 -6
index c23b174965c379a1abbc51d42acacade80ff7e10..5c4f61054e8013a13c9062cfa9fe84319b051980 100644

Lines of this file are not shown. View the raw message.

drivers/media/usb/uvc/uvc_v4l2.c +40 -19

59 lines not on this page · raw message

drivers/media/v4l2-core/v4l2-ctrls-api.c +1 -1
index 0078a04c544590cc02988c7d041e66519432a8cf..9fe86526e38ffd131f2c5fb48bb61843a2543f8a 100644

Lines of this file are not shown. View the raw message.

drivers/media/v4l2-core/v4l2-dev.c +2 -2
index 2606077538be0e83032c6ae8956c1d67da0d0c5d..93bf8067eaf79b5b33363922434bd82591f19f83 100644

Lines of this file are not shown. View the raw message.

drivers/media/v4l2-core/v4l2-mem2mem.c +34 -22

56 lines not on this page · raw message

drivers/staging/media/atomisp/pci/atomisp_ioctl.c +47 -25

72 lines not on this page · raw message

drivers/staging/media/av7110/av7110_v4l.c +42 -18

60 lines not on this page · raw message

drivers/staging/media/deprecated/atmel/atmel-isc-base.c +22 -11
index fb9ee8547392b4ee768b39ce08f52488323bb6f9..5f7572cb8e0e2585c95df6f7eaf88f35da32153e 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/imx/imx-media-capture.c +36 -17

53 lines not on this page · raw message

drivers/staging/media/imx/imx-media-csc-scaler.c +15 -8
index 1869c5792ecb46682491ecbf33674c6044915261..38b7bae1ab23c6ab1e899ded8ff3f304a84421a1 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/ipu3/ipu3-v4l2.c +19 -10
index 2f6041d342f4296446db294ae054c6085d3e8500..e10bf683320c19e8e6a2ab30ab88536348c116bc 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/ipu7/ipu7-isys-video.c +19 -11
index 1a7c8a91fffb38d1a9b20f896a332a88d8060095..6e46df7a07b0143826c41d21dd3920088e70b3c6 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/meson/vdec/vdec.c +17 -9
index 49e497a32973b8df18c5143e0db68d0f7f42c36c..876e6fdb1fb308746fc58a7cf319bf70d39cfd1c 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/starfive/camss/stf-video.c +12 -6
index a0420eb6a0aa034fb0b1468951d84c8fe7bb1b56..b967a44039e05fb22cce3c87364965137ce7422c 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/sunxi/cedrus/cedrus_video.c +19 -10
index ad4ec349077547ea3428c7341f152d729d775bb2..a96473a966cbc1a2f669ad705fcf72220a92c37a 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +16 -8
index e7b99cee63d68bcb6d6e69cde9dd5c2de0d553f4..d64d0f77f632d65ff92bc0a4a587efacf2a4a5e9 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_params.c +6 -3
index 77c2d06c04362157c9cc3de801e8c576313e7da7..ed697fc56dd94fb7f79c0d07b55c8ea09b1eb8bc 100644

Lines of this file are not shown. View the raw message.

drivers/staging/media/tegra-video/vi.c +45 -23

68 lines not on this page · raw message

drivers/staging/most/video/video.c +24 -15
index 32f71d9a9cf78ad74aa8b9a53f40c1d52123df52..5bce5e4c566803c86c8b656427a75e91ca635405 100644

Lines of this file are not shown. View the raw message.

drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +38 -20

58 lines not on this page · raw message

drivers/usb/gadget/function/uvc_v4l2.c +33 -17

50 lines not on this page · raw message

include/media/v4l2-ctrls.h +3 -2
index 31fc1bee3797bfe532931889188c8f7a9dedad39..a5a781d04db9aa57fabbccf938fe8d38eb550a80 100644

Lines of this file are not shown. View the raw message.

include/media/v4l2-dev.h +1 -1
index b5312823fbff9c236d4394d48fa9a14412b17c68..e8696d1a5931c54ee07ef9e268cf635cf87e34f2 100644

Lines of this file are not shown. View the raw message.

include/media/v4l2-ioctl.h +120 -118

238 lines not on this page · raw message

include/media/v4l2-mem2mem.h +32 -16

48 lines not on this page · raw message

include/media/videobuf2-v4l2.h +21 -12
index 77ce8238ab303a6f90dfb89852e7e48555f55a92..0164f0f3e404a425533d7657944c26c2f6eae1da 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

#27 lore raw

Re: [PATCH v2 06/10] media: Replace void * with video_device_state * in all driver ioctl implementations

Hi Jai,

This patch is too large to be reasonably reviewable in its current form.

The stated change is conceptually simple: replace the opaque void *priv argument with struct video_device_state *state in V4L2 ioctl implementations. However, this single patch touches hundreds of files across drivers, helpers, framework code, staging code, and public headers. That makes it extremely difficult to validate correctness, spot exceptions, and reason about regressions from mailing list review alone.

A few issues stand out:

1. Patch granularity

This should not be one monolithic patch. At minimum it should be split into:

- core/framework changes
- helper conversions
- driver conversions by subsystem or directory class
- staging/test-driver conversions separately

Right now the size alone makes meaningful review and bisection much worse than it needs to be.

2. Mechanical conversion claim vs. manual exceptions

The changelog says most changes were automated with Coccinelle, while function signature updates in headers and edge cases were handled manually. That is exactly why this needs splitting. Mechanical treewide conversions are one thing; manual edge-case handling is where subtle semantic mistakes tend to hide.

3. API conversion proof is missing

If this is primarily a scripted transformation, the review should center on the semantic patch and on proving there are no remaining mismatches.

Please include:

- the Coccinelle script as a separate patch or in the cover letter
- a summary of what could not be converted automatically
- a treewide grep result showing there are no remaining ioctl prototypes using void *priv where
struct video_device_state *state is now required

4. Conversion consistency

Several call sites now rename the parameter to state but continue to use it only as a positional placeholder, which is fine mechanically, but the patch should avoid mixing semantic conversion with opportunistic cleanup. Formatting-only churn and spacing adjustments should be kept to the minimum necessary for the signature change.

5. Risk concentration

This patch touches both framework headers and many driver implementations in the same changeset. That amplifies the blast radius of any mistake and makes it harder to tell whether a reported regression belongs to the API change itself or to one of the driver-side edits.

6. Reviewability for maintainers

The CC list spans a large number of maintainers and mailing lists. That is appropriate for notification, but not a substitute for reviewable patch structure. Individual maintainers should not have to sift through a large treewide refactor to find the parts that affect their drivers.

Please respin this as a structured series with the mechanical transformation isolated from the framework changes and with a clear accounting of manual fixups and exceptions.

As it stands, I do not think this patch is reviewable in one piece.

Acked By : David Dull

maintainer
#28 lore raw

Re: [PATCH v2 06/10] media: Replace void * with video_device_state * in all driver ioctl implementations

Quoted 3 lines · David Dull

Hi Jai,

This patch is too large to be reasonably reviewable in its current form.

This review is too generated by LLMs to be actionable in its current form.

Quoted 77 lines

The stated change is conceptually simple: replace the opaque void *priv argument with struct video_device_state *state in V4L2 ioctl implementations. However, this single patch touches hundreds of files across drivers, helpers, framework code, staging code, and public headers. That makes it extremely difficult to validate correctness, spot exceptions, and reason about regressions from mailing list review alone.

A few issues stand out:

1. Patch granularity

This should not be one monolithic patch. At minimum it should be split into:

- core/framework changes
- helper conversions
- driver conversions by subsystem or directory class
- staging/test-driver conversions separately

Right now the size alone makes meaningful review and bisection much worse than it needs to be.

2. Mechanical conversion claim vs. manual exceptions

The changelog says most changes were automated with Coccinelle, while function signature updates in headers and edge cases were handled manually. That is exactly why this needs splitting. Mechanical treewide conversions are one thing; manual edge-case handling is where subtle semantic mistakes tend to hide.

3. API conversion proof is missing

If this is primarily a scripted transformation, the review should center on the semantic patch and on proving there are no remaining mismatches.

Please include:

- the Coccinelle script as a separate patch or in the cover letter
- a summary of what could not be converted automatically
- a treewide grep result showing there are no remaining ioctl prototypes using void *priv where
struct video_device_state *state is now required

4. Conversion consistency

Several call sites now rename the parameter to state but continue to use it only as a positional placeholder, which is fine mechanically, but the patch should avoid mixing semantic conversion with opportunistic cleanup. Formatting-only churn and spacing adjustments should be kept to the minimum necessary for the signature change.

5. Risk concentration

This patch touches both framework headers and many driver implementations in the same changeset. That amplifies the blast radius of any mistake and makes it harder to tell whether a reported regression belongs to the API change itself or to one of the driver-side edits.

6. Reviewability for maintainers

The CC list spans a large number of maintainers and mailing lists. That is appropriate for notification, but not a substitute for reviewable patch structure. Individual maintainers should not have to sift through a large treewide refactor to find the parts that affect their drivers.

Please respin this as a structured series with the mechanical transformation isolated from the framework changes and with a clear accounting of manual fixups and exceptions.

As it stands, I do not think this patch is reviewable in one piece.

Acked By : David Dull

Signature · 3 lines
Regards,

Laurent Pinchart
#29 lore raw

Re: [PATCH v2 06/10] media: Replace void * with video_device_state * in all driver ioctl implementations

In reply to Jai Luthra

Hi Jai,

This patch is too large to be reasonably reviewable in its current form.

The stated change is conceptually simple: replace the opaque void *priv argument with struct video_device_state *state in V4L2 ioctl implementations. However, this single patch touches hundreds of files across drivers, helpers, framework code, staging code, and public headers. That makes it extremely difficult to validate correctness, spot exceptions, and reason about regressions from mailing list review alone.

A few issues stand out:

1. Patch granularity

This should not be one monolithic patch. At minimum it should be split into:

- core/framework changes
- helper conversions
- driver conversions by subsystem or directory class
- staging/test-driver conversions separately

Right now the size alone makes meaningful review and bisection much worse than it needs to be.

2. Mechanical conversion claim vs. manual exceptions

The changelog says most changes were automated with Coccinelle, while function signature updates in headers and edge cases were handled manually. That is exactly why this needs splitting. Mechanical treewide conversions are one thing; manual edge-case handling is where subtle semantic mistakes tend to hide.

3. API conversion proof is missing

If this is primarily a scripted transformation, the review should center on the semantic patch and on proving there are no remaining mismatches.

Please include:

- the Coccinelle script as a separate patch or in the cover letter
- a summary of what could not be converted automatically
- a treewide grep result showing there are no remaining ioctl prototypes using void *priv where
struct video_device_state *state is now required

4. Conversion consistency

Several call sites now rename the parameter to state but continue to use it only as a positional placeholder, which is fine mechanically, but the patch should avoid mixing semantic conversion with opportunistic cleanup. Formatting-only churn and spacing adjustments should be kept to the minimum necessary for the signature change.

5. Risk concentration

This patch touches both framework headers and many driver implementations in the same changeset. That amplifies the blast radius of any mistake and makes it harder to tell whether a reported regression belongs to the API change itself or to one of the driver-side edits.

6. Reviewability for maintainers

The CC list spans a large number of maintainers and mailing lists. That is appropriate for notification, but not a substitute for reviewable patch structure. Individual maintainers should not have to sift through a large treewide refactor to find the parts that affect their drivers.

Please respin this as a structured series with the mechanical transformation isolated from the framework changes and with a clear accounting of manual fixups and exceptions.

As it stands, I do not think this patch is reviewable in one piece.

author
#30 lore raw

PATCH v2 7/10 media: v4l2-ioctl: Pass device state for G/S/TRY_FMT ioctls

In reply to Jai Luthra

Now that video device state is accepted as an argument in ioctl implementations across all video device drivers, populate that argument with the actual state data.

Pass the active state for G_FMT and S_FMT ioctls, and the try state for TRY_FMT ioctl to drivers that have opted to use device state for format storage.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/media/v4l2-core/v4l2-ioctl.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +21 -2
index 644f06521673ff7ce5b194335d50f0e375ca7f51..500fc20627c97ce70016f4524301835142b7bebd 100644
@@ -3070,6 +3070,21 @@ void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
 }
 EXPORT_SYMBOL(v4l_printk_ioctl);
 
+static struct video_device_state *
+video_device_get_state(struct video_device *vfd, struct v4l2_fh *vfh,
+		       unsigned int cmd)
+{
+	switch (cmd) {
+	default:
+		return NULL;
+	case VIDIOC_G_FMT:
+	case VIDIOC_S_FMT:
+		return vfd->state;
+	case VIDIOC_TRY_FMT:
+		return vfh->state;
+	}
+}
+
 static long __video_do_ioctl(struct file *file,
 		unsigned int cmd, void *arg)
 {
@@ -3078,6 +3093,7 @@ static long __video_do_ioctl(struct file *file,
 	struct mutex *lock; /* ioctl serialization mutex */
 	const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
 	bool write_only = false;
+	struct video_device_state *state = NULL;
 	struct v4l2_ioctl_info default_info;
 	const struct v4l2_ioctl_info *info;
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
@@ -3090,6 +3106,9 @@ static long __video_do_ioctl(struct file *file,
 		return ret;
 	}
 
+	if (test_bit(V4L2_FL_USES_STATE, &vfd->flags))
+		state = video_device_get_state(vfd, vfh, cmd);
+
 	/*
 	 * We need to serialize streamon/off with queueing new requests.
 	 * These ioctls may trigger the cancellation of a streaming
@@ -3138,11 +3157,11 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (info != &default_info) {
-		ret = info->func(ops, file, NULL, arg);
+		ret = info->func(ops, file, state, arg);
 	} else if (!ops->vidioc_default) {
 		ret = -ENOTTY;
 	} else {
-		ret = ops->vidioc_default(file, NULL,
+		ret = ops->vidioc_default(file, state,
 			v4l2_prio_check(vfd->prio, vfh->prio) >= 0,
 			cmd, arg);
 	}
Signature · 1 line
2.51.0
#31 lore raw

Re: [PATCH v2 07/10] media: v4l2-ioctl: Pass device state for G/S/TRY_FMT ioctls

Quoted 18 lines · Jai Luthra

Now that video device state is accepted as an argument in ioctl implementations across all video device drivers, populate that argument with the actual state data.

Pass the active state for G_FMT and S_FMT ioctls, and the try state for TRY_FMT ioctl to drivers that have opted to use device state for format storage.

--
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ricardo Ribalda <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Jai Luthra <[email protected]>
Cc: [email protected]
Cc: [email protected]

Quoted 3 lines
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

There is one more occurrence of this in v4l2_compat_ioctl32.c in function ctrl_is_pointer() where vidioc_query_ext_ctrl is called.

Regards,

Hans

Quoted 60 lines
drivers/media/v4l2-core/v4l2-ioctl.c +21 -2
index 644f06521673ff7ce5b194335d50f0e375ca7f51..500fc20627c97ce70016f4524301835142b7bebd 100644
@@ -3070,6 +3070,21 @@ void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
 }
 EXPORT_SYMBOL(v4l_printk_ioctl);
 
+static struct video_device_state *
+video_device_get_state(struct video_device *vfd, struct v4l2_fh *vfh,
+		       unsigned int cmd)
+{
+	switch (cmd) {
+	default:
+		return NULL;
+	case VIDIOC_G_FMT:
+	case VIDIOC_S_FMT:
+		return vfd->state;
+	case VIDIOC_TRY_FMT:
+		return vfh->state;
+	}
+}
+
 static long __video_do_ioctl(struct file *file,
 		unsigned int cmd, void *arg)
 {
@@ -3078,6 +3093,7 @@ static long __video_do_ioctl(struct file *file,
 	struct mutex *lock; /* ioctl serialization mutex */
 	const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
 	bool write_only = false;
+	struct video_device_state *state = NULL;
 	struct v4l2_ioctl_info default_info;
 	const struct v4l2_ioctl_info *info;
 	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
@@ -3090,6 +3106,9 @@ static long __video_do_ioctl(struct file *file,
 		return ret;
 	}
 
+	if (test_bit(V4L2_FL_USES_STATE, &vfd->flags))
+		state = video_device_get_state(vfd, vfh, cmd);
+
 	/*
 	 * We need to serialize streamon/off with queueing new requests.
 	 * These ioctls may trigger the cancellation of a streaming
@@ -3138,11 +3157,11 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (info != &default_info) {
-		ret = info->func(ops, file, NULL, arg);
+		ret = info->func(ops, file, state, arg);
 	} else if (!ops->vidioc_default) {
 		ret = -ENOTTY;
 	} else {
-		ret = ops->vidioc_default(file, NULL,
+		ret = ops->vidioc_default(file, state,
 			v4l2_prio_check(vfd->prio, vfh->prio) >= 0,
 			cmd, arg);
 	}
author
#32 lore raw

PATCH v2 8/10 media: ti: j721e-csi2rx: Use video_device_state

In reply to Jai Luthra

Use the newly introduced video_device_state to store the active V4L2 format for the video device.

This change allows using a single function for both .s_fmt and .try_fmt hooks, while leveraging the framework helper for the .g_fmt hook.

--
Cc: Jai Luthra <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  | 119 +++++++++++----------
 1 file changed, 62 insertions(+), 57 deletions(-)
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +62 -57
index ac9a87ee06b1090456508c87893ac0a265c93ae9..08557fc77851ec5897d5adc8011e2cd031267cf5 100644
@@ -17,6 +17,7 @@
 
 #include <media/cadence/cdns-csi2rx.h>
 #include <media/mipi-csi2.h>
+#include <media/v4l2-dev.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mc.h>
@@ -110,7 +111,6 @@ struct ti_csi2rx_dev {
 	struct v4l2_subdev		*source;
 	struct vb2_queue		vidq;
 	struct mutex			mutex; /* To serialize ioctls. */
-	struct v4l2_format		v_fmt;
 	struct ti_csi2rx_dma		dma;
 	u32				sequence;
 	u8				pix_per_clk;
@@ -308,22 +308,19 @@ static int ti_csi2rx_enum_fmt_vid_cap(struct file *file,
 	return 0;
 }
 
-static int ti_csi2rx_g_fmt_vid_cap(struct file *file,
-				   struct video_device_state *state,
-				   struct v4l2_format *f)
-{
-	struct ti_csi2rx_dev *csi = video_drvdata(file);
-
-	*f = csi->v_fmt;
-
-	return 0;
-}
-
-static int ti_csi2rx_try_fmt_vid_cap(struct file *file,
+static int ti_csi2rx_adj_fmt_vid_cap(struct file *file,
 				     struct video_device_state *state,
 				     struct v4l2_format *f)
 {
 	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_format *format;
+
+	if (state->which == VIDEO_DEVICE_STATE_ACTIVE) {
+		struct ti_csi2rx_dev *csi = video_drvdata(file);
+
+		if (vb2_is_busy(csi->vdev.queue))
+			return -EBUSY;
+	}
 
 	/*
 	 * Default to the first format if the requested pixel format code isn't
@@ -338,25 +335,8 @@ static int ti_csi2rx_try_fmt_vid_cap(struct file *file,
 
 	ti_csi2rx_fill_fmt(fmt, f);
 
-	return 0;
-}
-
-static int ti_csi2rx_s_fmt_vid_cap(struct file *file,
-				   struct video_device_state *state,
-				   struct v4l2_format *f)
-{
-	struct ti_csi2rx_dev *csi = video_drvdata(file);
-	struct vb2_queue *q = &csi->vidq;
-	int ret;
-
-	if (vb2_is_busy(q))
-		return -EBUSY;
-
-	ret = ti_csi2rx_try_fmt_vid_cap(file, state, f);
-	if (ret < 0)
-		return ret;
-
-	csi->v_fmt = *f;
+	format = video_device_state_get_fmt(state);
+	*format = *f;
 
 	return 0;
 }
@@ -390,12 +370,36 @@ static int ti_csi2rx_enum_framesizes(struct file *file,
 	return 0;
 }
 
+static int ti_csi2rx_vdev_init_state(struct video_device_state *state)
+{
+	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_pix_format *pix_fmt;
+
+	fmt = find_format_by_fourcc(V4L2_PIX_FMT_UYVY);
+	if (!fmt)
+		return -EINVAL;
+
+	state->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	pix_fmt = &state->fmt.fmt.pix;
+	pix_fmt->width = 640;
+	pix_fmt->height = 480;
+	pix_fmt->field = V4L2_FIELD_NONE;
+	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
+	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
+	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
+
+	ti_csi2rx_fill_fmt(fmt, &state->fmt);
+
+	return 0;
+}
+
 static const struct v4l2_ioctl_ops csi_ioctl_ops = {
 	.vidioc_querycap      = ti_csi2rx_querycap,
 	.vidioc_enum_fmt_vid_cap = ti_csi2rx_enum_fmt_vid_cap,
-	.vidioc_try_fmt_vid_cap = ti_csi2rx_try_fmt_vid_cap,
-	.vidioc_g_fmt_vid_cap = ti_csi2rx_g_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap = ti_csi2rx_s_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap = ti_csi2rx_adj_fmt_vid_cap,
+	.vidioc_g_fmt_vid_cap = video_device_g_fmt,
+	.vidioc_s_fmt_vid_cap = ti_csi2rx_adj_fmt_vid_cap,
 	.vidioc_enum_framesizes = ti_csi2rx_enum_framesizes,
 	.vidioc_reqbufs       = vb2_ioctl_reqbufs,
 	.vidioc_create_bufs   = vb2_ioctl_create_bufs,
@@ -418,6 +422,10 @@ static const struct v4l2_file_operations csi_fops = {
 	.mmap = vb2_fop_mmap,
 };
 
+static const struct video_device_internal_ops csi_vdev_ops = {
+	.init_state = ti_csi2rx_vdev_init_state,
+};
+
 static int csi_async_notifier_bound(struct v4l2_async_notifier *notifier,
 				    struct v4l2_subdev *subdev,
 				    struct v4l2_async_connection *asc)
@@ -518,9 +526,11 @@ static void ti_csi2rx_request_max_ppc(struct ti_csi2rx_dev *csi)
 static void ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi)
 {
 	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_format *format;
 	unsigned int reg;
 
-	fmt = find_format_by_fourcc(csi->v_fmt.fmt.pix.pixelformat);
+	format = video_device_state_get_fmt(csi->vdev.state);
+	fmt = find_format_by_fourcc(format->fmt.pix.pixelformat);
 
 	/* De-assert the pixel interface reset. */
 	reg = SHIM_CNTL_PIX_RST;
@@ -671,13 +681,21 @@ static void ti_csi2rx_dma_callback(void *param)
 	spin_unlock_irqrestore(&dma->lock, flags);
 }
 
+static u32 ti_csi2rx_sizeimage(struct ti_csi2rx_dev *csi)
+{
+	struct v4l2_format *format =
+		video_device_state_get_fmt(csi->vdev.state);
+
+	return format->fmt.pix.sizeimage;
+}
+
 static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi,
 			       struct ti_csi2rx_buffer *buf)
 {
-	unsigned long addr;
 	struct dma_async_tx_descriptor *desc;
-	size_t len = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned long addr;
 	dma_cookie_t cookie;
+	size_t len = ti_csi2rx_sizeimage(csi);
 	int ret = 0;
 
 	addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
@@ -754,7 +772,7 @@ static int ti_csi2rx_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
 				 struct device *alloc_devs[])
 {
 	struct ti_csi2rx_dev *csi = vb2_get_drv_priv(q);
-	unsigned int size = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned int size = ti_csi2rx_sizeimage(csi);
 
 	if (*nplanes) {
 		if (sizes[0] < size)
@@ -771,7 +789,7 @@ static int ti_csi2rx_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
 static int ti_csi2rx_buffer_prepare(struct vb2_buffer *vb)
 {
 	struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue);
-	unsigned long size = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned long size = ti_csi2rx_sizeimage(csi);
 
 	if (vb2_plane_size(vb, 0) < size) {
 		dev_err(csi->dev, "Data will not fit into plane\n");
@@ -951,7 +969,8 @@ static int ti_csi2rx_link_validate(struct media_link *link)
 	struct media_entity *entity = link->sink->entity;
 	struct video_device *vdev = media_entity_to_video_device(entity);
 	struct ti_csi2rx_dev *csi = container_of(vdev, struct ti_csi2rx_dev, vdev);
-	struct v4l2_pix_format *csi_fmt = &csi->v_fmt.fmt.pix;
+	struct v4l2_format *format = video_device_state_get_fmt(vdev->state);
+	struct v4l2_pix_format *csi_fmt = &format->fmt.pix;
 	struct v4l2_subdev_format source_fmt = {
 		.which	= V4L2_SUBDEV_FORMAT_ACTIVE,
 		.pad	= link->source->index,
@@ -1041,24 +1060,8 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 {
 	struct media_device *mdev = &csi->mdev;
 	struct video_device *vdev = &csi->vdev;
-	const struct ti_csi2rx_fmt *fmt;
-	struct v4l2_pix_format *pix_fmt = &csi->v_fmt.fmt.pix;
 	int ret;
 
-	fmt = find_format_by_fourcc(V4L2_PIX_FMT_UYVY);
-	if (!fmt)
-		return -EINVAL;
-
-	pix_fmt->width = 640;
-	pix_fmt->height = 480;
-	pix_fmt->field = V4L2_FIELD_NONE;
-	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
-	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
-	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
-	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
-
-	ti_csi2rx_fill_fmt(fmt, &csi->v_fmt);
-
 	mdev->dev = csi->dev;
 	mdev->hw_revision = 1;
 	strscpy(mdev->model, "TI-CSI2RX", sizeof(mdev->model));
@@ -1070,10 +1073,12 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 	vdev->vfl_dir = VFL_DIR_RX;
 	vdev->fops = &csi_fops;
 	vdev->ioctl_ops = &csi_ioctl_ops;
+	vdev->vdev_ops = &csi_vdev_ops;
 	vdev->release = video_device_release_empty;
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
 			    V4L2_CAP_IO_MC;
 	vdev->lock = &csi->mutex;
+	set_bit(V4L2_FL_USES_STATE, &vdev->flags);
 	video_set_drvdata(vdev, csi);
 
 	csi->pad.flags = MEDIA_PAD_FL_SINK;
Signature · 1 line
2.51.0
#33 lore raw

Re: [PATCH v2 08/10] media: ti: j721e-csi2rx: Use video_device_state

Quoted 5 lines · Jai Luthra

Use the newly introduced video_device_state to store the active V4L2 format for the video device.

This change allows using a single function for both .s_fmt and .try_fmt hooks, while leveraging the framework helper for the .g_fmt hook.

Rather than replying to 00/10, since that is CC-ed to a million people, I'll reply here.

For core framework changes like this I want to see it applied to the test-drivers as well. At minimum the vivid driver and, if we support this for M2M devices as well, either vim2m or vicodec.

The test-drivers are used in the media CI regression tests, so it is important that this is implemented in at least some of the test drivers.

Regards,

Hans

Quoted 246 lines

--
Cc: Jai Luthra <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  | 119 +++++++++++----------
 1 file changed, 62 insertions(+), 57 deletions(-)
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +62 -57
index ac9a87ee06b1090456508c87893ac0a265c93ae9..08557fc77851ec5897d5adc8011e2cd031267cf5 100644
@@ -17,6 +17,7 @@
 
 #include <media/cadence/cdns-csi2rx.h>
 #include <media/mipi-csi2.h>
+#include <media/v4l2-dev.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mc.h>
@@ -110,7 +111,6 @@ struct ti_csi2rx_dev {
 	struct v4l2_subdev		*source;
 	struct vb2_queue		vidq;
 	struct mutex			mutex; /* To serialize ioctls. */
-	struct v4l2_format		v_fmt;
 	struct ti_csi2rx_dma		dma;
 	u32				sequence;
 	u8				pix_per_clk;
@@ -308,22 +308,19 @@ static int ti_csi2rx_enum_fmt_vid_cap(struct file *file,
 	return 0;
 }
 
-static int ti_csi2rx_g_fmt_vid_cap(struct file *file,
-				   struct video_device_state *state,
-				   struct v4l2_format *f)
-{
-	struct ti_csi2rx_dev *csi = video_drvdata(file);
-
-	*f = csi->v_fmt;
-
-	return 0;
-}
-
-static int ti_csi2rx_try_fmt_vid_cap(struct file *file,
+static int ti_csi2rx_adj_fmt_vid_cap(struct file *file,
 				     struct video_device_state *state,
 				     struct v4l2_format *f)
 {
 	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_format *format;
+
+	if (state->which == VIDEO_DEVICE_STATE_ACTIVE) {
+		struct ti_csi2rx_dev *csi = video_drvdata(file);
+
+		if (vb2_is_busy(csi->vdev.queue))
+			return -EBUSY;
+	}
 
 	/*
 	 * Default to the first format if the requested pixel format code isn't
@@ -338,25 +335,8 @@ static int ti_csi2rx_try_fmt_vid_cap(struct file *file,
 
 	ti_csi2rx_fill_fmt(fmt, f);
 
-	return 0;
-}
-
-static int ti_csi2rx_s_fmt_vid_cap(struct file *file,
-				   struct video_device_state *state,
-				   struct v4l2_format *f)
-{
-	struct ti_csi2rx_dev *csi = video_drvdata(file);
-	struct vb2_queue *q = &csi->vidq;
-	int ret;
-
-	if (vb2_is_busy(q))
-		return -EBUSY;
-
-	ret = ti_csi2rx_try_fmt_vid_cap(file, state, f);
-	if (ret < 0)
-		return ret;
-
-	csi->v_fmt = *f;
+	format = video_device_state_get_fmt(state);
+	*format = *f;
 
 	return 0;
 }
@@ -390,12 +370,36 @@ static int ti_csi2rx_enum_framesizes(struct file *file,
 	return 0;
 }
 
+static int ti_csi2rx_vdev_init_state(struct video_device_state *state)
+{
+	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_pix_format *pix_fmt;
+
+	fmt = find_format_by_fourcc(V4L2_PIX_FMT_UYVY);
+	if (!fmt)
+		return -EINVAL;
+
+	state->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	pix_fmt = &state->fmt.fmt.pix;
+	pix_fmt->width = 640;
+	pix_fmt->height = 480;
+	pix_fmt->field = V4L2_FIELD_NONE;
+	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
+	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
+	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
+
+	ti_csi2rx_fill_fmt(fmt, &state->fmt);
+
+	return 0;
+}
+
 static const struct v4l2_ioctl_ops csi_ioctl_ops = {
 	.vidioc_querycap      = ti_csi2rx_querycap,
 	.vidioc_enum_fmt_vid_cap = ti_csi2rx_enum_fmt_vid_cap,
-	.vidioc_try_fmt_vid_cap = ti_csi2rx_try_fmt_vid_cap,
-	.vidioc_g_fmt_vid_cap = ti_csi2rx_g_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap = ti_csi2rx_s_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap = ti_csi2rx_adj_fmt_vid_cap,
+	.vidioc_g_fmt_vid_cap = video_device_g_fmt,
+	.vidioc_s_fmt_vid_cap = ti_csi2rx_adj_fmt_vid_cap,
 	.vidioc_enum_framesizes = ti_csi2rx_enum_framesizes,
 	.vidioc_reqbufs       = vb2_ioctl_reqbufs,
 	.vidioc_create_bufs   = vb2_ioctl_create_bufs,
@@ -418,6 +422,10 @@ static const struct v4l2_file_operations csi_fops = {
 	.mmap = vb2_fop_mmap,
 };
 
+static const struct video_device_internal_ops csi_vdev_ops = {
+	.init_state = ti_csi2rx_vdev_init_state,
+};
+
 static int csi_async_notifier_bound(struct v4l2_async_notifier *notifier,
 				    struct v4l2_subdev *subdev,
 				    struct v4l2_async_connection *asc)
@@ -518,9 +526,11 @@ static void ti_csi2rx_request_max_ppc(struct ti_csi2rx_dev *csi)
 static void ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi)
 {
 	const struct ti_csi2rx_fmt *fmt;
+	struct v4l2_format *format;
 	unsigned int reg;
 
-	fmt = find_format_by_fourcc(csi->v_fmt.fmt.pix.pixelformat);
+	format = video_device_state_get_fmt(csi->vdev.state);
+	fmt = find_format_by_fourcc(format->fmt.pix.pixelformat);
 
 	/* De-assert the pixel interface reset. */
 	reg = SHIM_CNTL_PIX_RST;
@@ -671,13 +681,21 @@ static void ti_csi2rx_dma_callback(void *param)
 	spin_unlock_irqrestore(&dma->lock, flags);
 }
 
+static u32 ti_csi2rx_sizeimage(struct ti_csi2rx_dev *csi)
+{
+	struct v4l2_format *format =
+		video_device_state_get_fmt(csi->vdev.state);
+
+	return format->fmt.pix.sizeimage;
+}
+
 static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi,
 			       struct ti_csi2rx_buffer *buf)
 {
-	unsigned long addr;
 	struct dma_async_tx_descriptor *desc;
-	size_t len = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned long addr;
 	dma_cookie_t cookie;
+	size_t len = ti_csi2rx_sizeimage(csi);
 	int ret = 0;
 
 	addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
@@ -754,7 +772,7 @@ static int ti_csi2rx_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
 				 struct device *alloc_devs[])
 {
 	struct ti_csi2rx_dev *csi = vb2_get_drv_priv(q);
-	unsigned int size = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned int size = ti_csi2rx_sizeimage(csi);
 
 	if (*nplanes) {
 		if (sizes[0] < size)
@@ -771,7 +789,7 @@ static int ti_csi2rx_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
 static int ti_csi2rx_buffer_prepare(struct vb2_buffer *vb)
 {
 	struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue);
-	unsigned long size = csi->v_fmt.fmt.pix.sizeimage;
+	unsigned long size = ti_csi2rx_sizeimage(csi);
 
 	if (vb2_plane_size(vb, 0) < size) {
 		dev_err(csi->dev, "Data will not fit into plane\n");
@@ -951,7 +969,8 @@ static int ti_csi2rx_link_validate(struct media_link *link)
 	struct media_entity *entity = link->sink->entity;
 	struct video_device *vdev = media_entity_to_video_device(entity);
 	struct ti_csi2rx_dev *csi = container_of(vdev, struct ti_csi2rx_dev, vdev);
-	struct v4l2_pix_format *csi_fmt = &csi->v_fmt.fmt.pix;
+	struct v4l2_format *format = video_device_state_get_fmt(vdev->state);
+	struct v4l2_pix_format *csi_fmt = &format->fmt.pix;
 	struct v4l2_subdev_format source_fmt = {
 		.which	= V4L2_SUBDEV_FORMAT_ACTIVE,
 		.pad	= link->source->index,
@@ -1041,24 +1060,8 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 {
 	struct media_device *mdev = &csi->mdev;
 	struct video_device *vdev = &csi->vdev;
-	const struct ti_csi2rx_fmt *fmt;
-	struct v4l2_pix_format *pix_fmt = &csi->v_fmt.fmt.pix;
 	int ret;
 
-	fmt = find_format_by_fourcc(V4L2_PIX_FMT_UYVY);
-	if (!fmt)
-		return -EINVAL;
-
-	pix_fmt->width = 640;
-	pix_fmt->height = 480;
-	pix_fmt->field = V4L2_FIELD_NONE;
-	pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
-	pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
-	pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE;
-	pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB;
-
-	ti_csi2rx_fill_fmt(fmt, &csi->v_fmt);
-
 	mdev->dev = csi->dev;
 	mdev->hw_revision = 1;
 	strscpy(mdev->model, "TI-CSI2RX", sizeof(mdev->model));
@@ -1070,10 +1073,12 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 	vdev->vfl_dir = VFL_DIR_RX;
 	vdev->fops = &csi_fops;
 	vdev->ioctl_ops = &csi_ioctl_ops;
+	vdev->vdev_ops = &csi_vdev_ops;
 	vdev->release = video_device_release_empty;
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
 			    V4L2_CAP_IO_MC;
 	vdev->lock = &csi->mutex;
+	set_bit(V4L2_FL_USES_STATE, &vdev->flags);
 	video_set_drvdata(vdev, csi);
 
 	csi->pad.flags = MEDIA_PAD_FL_SINK;
author
#34 lore raw

Re: [PATCH v2 08/10] media: ti: j721e-csi2rx: Use video_device_state

Quoting Hans Verkuil (2025-09-22 13:46:00)

Quoted 10 lines · Jai Luthra
Quoted 5 lines

Use the newly introduced video_device_state to store the active V4L2 format for the video device.

This change allows using a single function for both .s_fmt and .try_fmt hooks, while leveraging the framework helper for the .g_fmt hook.

Rather than replying to 00/10, since that is CC-ed to a million people, I'll reply here.

Quoted 6 lines

For core framework changes like this I want to see it applied to the test-drivers as well. At minimum the vivid driver and, if we support this for M2M devices as well, either vim2m or vicodec.

The test-drivers are used in the media CI regression tests, so it is important that this is implemented in at least some of the test drivers.

Sure, will add state support to vivid in the next revision.

I'm not very familiar with M2M though, and depends on what the series looks like, but I will give that an attempt.

Quoted 5 lines

Regards,

Hans

Thanks,
Jai

[snip]

author
#35 lore raw

PATCH v2 9/10 media: rkisp1: Use video_device_state

In reply to Jai Luthra

Use the newly introduced video_device_state to store the active V4L2 format for the video device.

Additionally, calculate stride on-demand instead of storing it in the driver context structure.

This change allows using a single function for both .s_fmt and .try_fmt hooks, while leveraging the framework helper for the .g_fmt hook.

--
Cc: Dafna Hirschfeld <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 .../platform/rockchip/rkisp1/rkisp1-capture.c      | 135 +++++++++++----------
 .../media/platform/rockchip/rkisp1/rkisp1-common.h |   4 -
 2 files changed, 70 insertions(+), 69 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +70 -65
index 38541f482b2d0dcf23546a0b9f893fb8544bcc40..81bf4ed8bccdb0873c910fa49b22ef72eab295eb 100644
@@ -482,7 +482,10 @@ static void rkisp1_irq_frame_end_enable(struct rkisp1_capture *cap)
 
 static void rkisp1_mp_config(struct rkisp1_capture *cap)
 {
-	const struct v4l2_pix_format_mplane *pixm = &cap->pix.fmt;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
+	u32 stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	u32 reg;
 
@@ -494,11 +497,11 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 		     rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR));
 
 	if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
-		rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_LLENGTH, cap->stride);
+		rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_LLENGTH, stride);
 		rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_WIDTH, pixm->width);
 		rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_HEIGHT, pixm->height);
 		rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_SIZE,
-			     cap->stride * pixm->height);
+			     stride * pixm->height);
 	}
 
 	rkisp1_irq_frame_end_enable(cap);
@@ -546,7 +549,10 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 
 static void rkisp1_sp_config(struct rkisp1_capture *cap)
 {
-	const struct v4l2_pix_format_mplane *pixm = &cap->pix.fmt;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
+	u32 stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	u32 mi_ctrl, reg;
 
@@ -557,11 +563,11 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
 	rkisp1_write(rkisp1, cap->config->mi.cr_size_init,
 		     rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR));
 
-	rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, cap->stride);
+	rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, stride);
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_WIDTH, pixm->width);
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_HEIGHT, pixm->height);
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_SIZE,
-		     cap->stride * pixm->height);
+		     stride * pixm->height);
 
 	rkisp1_irq_frame_end_enable(cap);
 
@@ -704,7 +710,9 @@ static const struct rkisp1_capture_ops rkisp1_capture_ops_sp = {
 
 static int rkisp1_dummy_buf_create(struct rkisp1_capture *cap)
 {
-	const struct v4l2_pix_format_mplane *pixm = &cap->pix.fmt;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
 	struct rkisp1_dummy_buffer *dummy_buf = &cap->buf.dummy;
 
 	dummy_buf->size = max3(rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_Y),
@@ -869,7 +877,9 @@ static int rkisp1_vb2_queue_setup(struct vb2_queue *queue,
 				  struct device *alloc_devs[])
 {
 	struct rkisp1_capture *cap = queue->drv_priv;
-	const struct v4l2_pix_format_mplane *pixm = &cap->pix.fmt;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
 	unsigned int i;
 
 	if (*num_planes) {
@@ -894,7 +904,9 @@ static int rkisp1_vb2_buf_init(struct vb2_buffer *vb)
 	struct rkisp1_buffer *ispbuf =
 		container_of(vbuf, struct rkisp1_buffer, vb);
 	struct rkisp1_capture *cap = vb->vb2_queue->drv_priv;
-	const struct v4l2_pix_format_mplane *pixm = &cap->pix.fmt;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
 	unsigned int i;
 
 	memset(ispbuf->buff_addr, 0, sizeof(ispbuf->buff_addr));
@@ -936,10 +948,13 @@ static void rkisp1_vb2_buf_queue(struct vb2_buffer *vb)
 static int rkisp1_vb2_buf_prepare(struct vb2_buffer *vb)
 {
 	struct rkisp1_capture *cap = vb->vb2_queue->drv_priv;
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
 	unsigned int i;
 
-	for (i = 0; i < cap->pix.fmt.num_planes; i++) {
-		unsigned long size = cap->pix.fmt.plane_fmt[i].sizeimage;
+	for (i = 0; i < pixm->num_planes; i++) {
+		unsigned long size = pixm->plane_fmt[i].sizeimage;
 
 		if (vb2_plane_size(vb, i) < size) {
 			dev_err(cap->rkisp1->dev,
@@ -1278,7 +1293,7 @@ rkisp1_find_fmt_cfg(const struct rkisp1_capture *cap, const u32 pixelfmt)
 	return NULL;
 }
 
-static void rkisp1_try_fmt(const struct rkisp1_capture *cap,
+static void rkisp1_adj_fmt(const struct rkisp1_capture *cap,
 			   struct v4l2_pix_format_mplane *pixm,
 			   const struct rkisp1_capture_fmt_cfg **fmt_cfg,
 			   const struct v4l2_format_info **fmt_info)
@@ -1317,23 +1332,23 @@ static void rkisp1_try_fmt(const struct rkisp1_capture *cap,
 		*fmt_info = info;
 }
 
-static void rkisp1_set_fmt(struct rkisp1_capture *cap,
-			   struct v4l2_pix_format_mplane *pixm)
-{
-	rkisp1_try_fmt(cap, pixm, &cap->pix.cfg, &cap->pix.info);
-
-	cap->pix.fmt = *pixm;
-	cap->stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
-}
-
-static int rkisp1_try_fmt_vid_cap_mplane(struct file *file,
+static int rkisp1_adj_fmt_vid_cap_mplane(struct file *file,
 					 struct video_device_state *state,
 					 struct v4l2_format *f)
 {
 	struct rkisp1_capture *cap = video_drvdata(file);
 
-	rkisp1_try_fmt(cap, &f->fmt.pix_mp, NULL, NULL);
+	if (state->which == VIDEO_DEVICE_STATE_ACTIVE) {
+		if (vb2_is_busy(cap->vnode.vdev.queue))
+			return -EBUSY;
 
+		rkisp1_adj_fmt(cap, &f->fmt.pix_mp, &cap->pix.cfg,
+			       &cap->pix.info);
+	} else {
+		rkisp1_adj_fmt(cap, &f->fmt.pix_mp, NULL, NULL);
+	}
+
+	state->fmt = *f;
 	return 0;
 }
 
@@ -1402,33 +1417,6 @@ static int rkisp1_enum_framesizes(struct file *file,
 	return 0;
 }
 
-static int rkisp1_s_fmt_vid_cap_mplane(struct file *file,
-				       struct video_device_state *state,
-				       struct v4l2_format *f)
-{
-	struct rkisp1_capture *cap = video_drvdata(file);
-	struct rkisp1_vdev_node *node =
-				rkisp1_vdev_to_node(&cap->vnode.vdev);
-
-	if (vb2_is_busy(&node->buf_queue))
-		return -EBUSY;
-
-	rkisp1_set_fmt(cap, &f->fmt.pix_mp);
-
-	return 0;
-}
-
-static int rkisp1_g_fmt_vid_cap_mplane(struct file *file,
-				       struct video_device_state *state,
-				       struct v4l2_format *f)
-{
-	struct rkisp1_capture *cap = video_drvdata(file);
-
-	f->fmt.pix_mp = cap->pix.fmt;
-
-	return 0;
-}
-
 static int
 rkisp1_querycap(struct file *file, struct video_device_state *state,
 		struct v4l2_capability *cap)
@@ -1450,9 +1438,9 @@ static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = {
 	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
 	.vidioc_streamon = vb2_ioctl_streamon,
 	.vidioc_streamoff = vb2_ioctl_streamoff,
-	.vidioc_try_fmt_vid_cap_mplane = rkisp1_try_fmt_vid_cap_mplane,
-	.vidioc_s_fmt_vid_cap_mplane = rkisp1_s_fmt_vid_cap_mplane,
-	.vidioc_g_fmt_vid_cap_mplane = rkisp1_g_fmt_vid_cap_mplane,
+	.vidioc_try_fmt_vid_cap_mplane = rkisp1_adj_fmt_vid_cap_mplane,
+	.vidioc_s_fmt_vid_cap_mplane = rkisp1_adj_fmt_vid_cap_mplane,
+	.vidioc_g_fmt_vid_cap_mplane = video_device_g_fmt,
 	.vidioc_enum_fmt_vid_cap = rkisp1_enum_fmt_vid_cap_mplane,
 	.vidioc_enum_framesizes = rkisp1_enum_framesizes,
 	.vidioc_querycap = rkisp1_querycap,
@@ -1460,6 +1448,25 @@ static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = {
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
+static int rkisp1_vdev_init_state(struct video_device_state *state)
+{
+	struct rkisp1_capture *cap = video_get_drvdata(state->vdev);
+	struct v4l2_pix_format_mplane *pixm = &state->fmt.fmt.pix_mp;
+
+	state->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+	pixm->pixelformat = V4L2_PIX_FMT_YUYV;
+	pixm->width = RKISP1_DEFAULT_WIDTH;
+	pixm->height = RKISP1_DEFAULT_HEIGHT;
+
+	rkisp1_adj_fmt(cap, pixm, &cap->pix.cfg, &cap->pix.info);
+
+	return 0;
+}
+
+static const struct video_device_internal_ops rkisp1_vdev_ops = {
+	.init_state = rkisp1_vdev_init_state,
+};
+
 static int rkisp1_capture_link_validate(struct media_link *link)
 {
 	struct video_device *vdev =
@@ -1467,8 +1474,11 @@ static int rkisp1_capture_link_validate(struct media_link *link)
 	struct v4l2_subdev *sd =
 		media_entity_to_v4l2_subdev(link->source->entity);
 	struct rkisp1_capture *cap = video_get_drvdata(vdev);
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
 	const struct rkisp1_capture_fmt_cfg *fmt =
-		rkisp1_find_fmt_cfg(cap, cap->pix.fmt.pixelformat);
+		rkisp1_find_fmt_cfg(cap, pixm->pixelformat);
 	struct v4l2_subdev_format sd_fmt = {
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 		.pad = link->source->index,
@@ -1479,16 +1489,16 @@ static int rkisp1_capture_link_validate(struct media_link *link)
 	if (ret)
 		return ret;
 
-	if (sd_fmt.format.height != cap->pix.fmt.height ||
-	    sd_fmt.format.width != cap->pix.fmt.width ||
+	if (sd_fmt.format.height != pixm->height ||
+	    sd_fmt.format.width != pixm->width ||
 	    sd_fmt.format.code != fmt->mbus) {
 		dev_dbg(cap->rkisp1->dev,
 			"link '%s':%u -> '%s':%u not valid: 0x%04x/%ux%u != 0x%04x/%ux%u\n",
 			link->source->entity->name, link->source->index,
 			link->sink->entity->name, link->sink->index,
 			sd_fmt.format.code, sd_fmt.format.width,
-			sd_fmt.format.height, fmt->mbus, cap->pix.fmt.width,
-			cap->pix.fmt.height);
+			sd_fmt.format.height, fmt->mbus, pixm->width,
+			pixm->height);
 		return -EPIPE;
 	}
 
@@ -1546,6 +1556,7 @@ static int rkisp1_register_capture(struct rkisp1_capture *cap)
 	mutex_init(&node->vlock);
 
 	vdev->ioctl_ops = &rkisp1_v4l2_ioctl_ops;
+	vdev->vdev_ops = &rkisp1_vdev_ops;
 	vdev->release = video_device_release_empty;
 	vdev->fops = &rkisp1_fops;
 	vdev->minor = -1;
@@ -1554,6 +1565,7 @@ static int rkisp1_register_capture(struct rkisp1_capture *cap)
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
 			    V4L2_CAP_STREAMING | V4L2_CAP_IO_MC;
 	vdev->entity.ops = &rkisp1_media_ops;
+	set_bit(V4L2_FL_USES_STATE, &vdev->flags);
 	video_set_drvdata(vdev, cap);
 	vdev->vfl_dir = VFL_DIR_RX;
 	node->pad.flags = MEDIA_PAD_FL_SINK;
@@ -1604,7 +1616,6 @@ static void
 rkisp1_capture_init(struct rkisp1_device *rkisp1, enum rkisp1_stream_id id)
 {
 	struct rkisp1_capture *cap = &rkisp1->capture_devs[id];
-	struct v4l2_pix_format_mplane pixm;
 
 	memset(cap, 0, sizeof(*cap));
 	cap->id = id;
@@ -1622,12 +1633,6 @@ rkisp1_capture_init(struct rkisp1_device *rkisp1, enum rkisp1_stream_id id)
 	}
 
 	cap->is_streaming = false;
-
-	memset(&pixm, 0, sizeof(pixm));
-	pixm.pixelformat = V4L2_PIX_FMT_YUYV;
-	pixm.width = RKISP1_DEFAULT_WIDTH;
-	pixm.height = RKISP1_DEFAULT_HEIGHT;
-	rkisp1_set_fmt(cap, &pixm);
 }
 
 int rkisp1_capture_devs_register(struct rkisp1_device *rkisp1)
drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +0 -4
index 6028ecdd23de6f69d53f77796252ee399a14436a..5731c4b368f8832c2b0748338cd0da2d0edf0a93 100644
@@ -309,7 +309,6 @@ struct rkisp1_device;
  *		  handler to stop the streaming by waiting on the 'done' wait queue.
  *		  If the irq handler is not called, the stream is stopped by the callback
  *		  after timeout.
- * @stride:       the line stride for the first plane, in pixel units
  * @buf.lock:	  lock to protect buf.queue
  * @buf.queue:	  queued buffer list
  * @buf.dummy:	  dummy space to store dropped data
@@ -319,7 +318,6 @@ struct rkisp1_device;
  * @buf.next:	  the buffer used for next frame
  * @pix.cfg:	  pixel configuration
  * @pix.info:	  a pointer to the v4l2_format_info of the pixel format
- * @pix.fmt:	  buffer format
  */
 struct rkisp1_capture {
 	struct rkisp1_vdev_node vnode;
@@ -330,7 +328,6 @@ struct rkisp1_capture {
 	bool is_streaming;
 	bool is_stopping;
 	wait_queue_head_t done;
-	unsigned int stride;
 	struct {
 		/* protects queue, curr and next */
 		spinlock_t lock;
@@ -342,7 +339,6 @@ struct rkisp1_capture {
 	struct {
 		const struct rkisp1_capture_fmt_cfg *cfg;
 		const struct v4l2_format_info *info;
-		struct v4l2_pix_format_mplane fmt;
 	} pix;
 };
 
Signature · 1 line
2.51.0
author
#36 lore raw

PATCH v2 10/10 media: rkisp1: Calculate format information on demand

In reply to Jai Luthra

Instead of storing format configuration and information as explicit state in the driver structure, calculate it on demand when needed using the format stored in the active video device state.

This change removes the pix member from rkisp1_capture structure and refactors the code to look up format configuration and v4l2_format_info at the point of use.

Additionally, grey format handling is moved from the next buffer setup path (which may be called in interrupt context) to the buffer initialization phase for simplicity.

---
Cc: Dafna Hirschfeld <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 .../platform/rockchip/rkisp1/rkisp1-capture.c      | 170 ++++++++++-----------
 .../media/platform/rockchip/rkisp1/rkisp1-common.h |   6 -
 2 files changed, 84 insertions(+), 92 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +84 -86
index 81bf4ed8bccdb0873c910fa49b22ef72eab295eb..2399fecc94dc4bf3a82fd1ae7fe8c746d015cdd8 100644
@@ -63,9 +63,12 @@ struct rkisp1_capture_fmt_cfg {
 };
 
 struct rkisp1_capture_ops {
-	void (*config)(struct rkisp1_capture *cap);
+	void (*config)(struct rkisp1_capture *cap,
+		       const struct rkisp1_capture_fmt_cfg *cfg,
+		       const struct v4l2_format_info *info);
 	void (*stop)(struct rkisp1_capture *cap);
-	void (*enable)(struct rkisp1_capture *cap);
+	void (*enable)(struct rkisp1_capture *cap,
+		       const struct v4l2_format_info *info);
 	void (*disable)(struct rkisp1_capture *cap);
 	void (*set_data_path)(struct rkisp1_capture *cap);
 	bool (*is_stopped)(struct rkisp1_capture *cap);
@@ -480,12 +483,30 @@ static void rkisp1_irq_frame_end_enable(struct rkisp1_capture *cap)
 	rkisp1_write(cap->rkisp1, RKISP1_CIF_MI_IMSC, mi_imsc);
 }
 
-static void rkisp1_mp_config(struct rkisp1_capture *cap)
+static const struct rkisp1_capture_fmt_cfg *
+rkisp1_find_fmt_cfg(const struct rkisp1_capture *cap, const u32 pixelfmt)
+{
+	bool yc_swap_support = rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE);
+	unsigned int i;
+
+	for (i = 0; i < cap->config->fmt_size; i++) {
+		const struct rkisp1_capture_fmt_cfg *fmt = &cap->config->fmts[i];
+
+		if (fmt->fourcc == pixelfmt &&
+		    (!fmt->yc_swap || yc_swap_support))
+			return &cap->config->fmts[i];
+	}
+	return NULL;
+}
+
+static void rkisp1_mp_config(struct rkisp1_capture *cap,
+			     const struct rkisp1_capture_fmt_cfg *cfg,
+			     const struct v4l2_format_info *info)
 {
 	const struct v4l2_format *format =
 		video_device_state_get_fmt(cap->vnode.vdev.state);
 	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
-	u32 stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
+	u32 stride = pixm->plane_fmt[0].bytesperline / info->bpp[0];
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	u32 reg;
 
@@ -507,9 +528,9 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 	rkisp1_irq_frame_end_enable(cap);
 
 	/* set uv swapping for semiplanar formats */
-	if (cap->pix.info->comp_planes == 2) {
+	if (info->comp_planes == 2) {
 		reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL);
-		if (cap->pix.cfg->uv_swap)
+		if (cfg->uv_swap)
 			reg |= RKISP1_CIF_MI_XTD_FMT_CTRL_MP_CB_CR_SWAP;
 		else
 			reg &= ~RKISP1_CIF_MI_XTD_FMT_CTRL_MP_CB_CR_SWAP;
@@ -523,7 +544,7 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 	 */
 	if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
 		reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT);
-		if (cap->pix.cfg->yc_swap || cap->pix.cfg->byte_swap)
+		if (cfg->yc_swap || cfg->byte_swap)
 			reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES;
 		else
 			reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES;
@@ -531,15 +552,14 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 		reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_LSB_ALIGNMENT;
 		rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg);
 
-		rkisp1_write(rkisp1, RKISP1_CIF_MI_INIT,
-			     cap->pix.cfg->output_format);
+		rkisp1_write(rkisp1, RKISP1_CIF_MI_INIT, cfg->output_format);
 	}
 
 	rkisp1_mi_config_ctrl(cap);
 
 	reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);
 	reg &= ~RKISP1_MI_CTRL_MP_FMT_MASK;
-	reg |= cap->pix.cfg->write_format;
+	reg |= cfg->write_format;
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_CTRL, reg);
 
 	reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);
@@ -547,12 +567,14 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_CTRL, reg);
 }
 
-static void rkisp1_sp_config(struct rkisp1_capture *cap)
+static void rkisp1_sp_config(struct rkisp1_capture *cap,
+			     const struct rkisp1_capture_fmt_cfg *cfg,
+			     const struct v4l2_format_info *info)
 {
 	const struct v4l2_format *format =
 		video_device_state_get_fmt(cap->vnode.vdev.state);
 	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
-	u32 stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
+	u32 stride = pixm->plane_fmt[0].bytesperline / info->bpp[0];
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	u32 mi_ctrl, reg;
 
@@ -572,9 +594,9 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
 	rkisp1_irq_frame_end_enable(cap);
 
 	/* set uv swapping for semiplanar formats */
-	if (cap->pix.info->comp_planes == 2) {
+	if (info->comp_planes == 2) {
 		reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL);
-		if (cap->pix.cfg->uv_swap)
+		if (cfg->uv_swap)
 			reg |= RKISP1_CIF_MI_XTD_FMT_CTRL_SP_CB_CR_SWAP;
 		else
 			reg &= ~RKISP1_CIF_MI_XTD_FMT_CTRL_SP_CB_CR_SWAP;
@@ -588,7 +610,7 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
 	 */
 	if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
 		reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT);
-		if (cap->pix.cfg->yc_swap)
+		if (cfg->yc_swap)
 			reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES;
 		else
 			reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES;
@@ -599,10 +621,8 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
 
 	mi_ctrl = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);
 	mi_ctrl &= ~RKISP1_MI_CTRL_SP_FMT_MASK;
-	mi_ctrl |= cap->pix.cfg->write_format |
-		   RKISP1_MI_CTRL_SP_INPUT_YUV422 |
-		   cap->pix.cfg->output_format |
-		   RKISP1_CIF_MI_SP_AUTOUPDATE_ENABLE;
+	mi_ctrl |= cfg->write_format | RKISP1_MI_CTRL_SP_INPUT_YUV422 |
+		   cfg->output_format | RKISP1_CIF_MI_SP_AUTOUPDATE_ENABLE;
 	rkisp1_write(rkisp1, RKISP1_CIF_MI_CTRL, mi_ctrl);
 }
 
@@ -623,14 +643,15 @@ static void rkisp1_sp_disable(struct rkisp1_capture *cap)
 	rkisp1_write(cap->rkisp1, RKISP1_CIF_MI_CTRL, mi_ctrl);
 }
 
-static void rkisp1_mp_enable(struct rkisp1_capture *cap)
+static void rkisp1_mp_enable(struct rkisp1_capture *cap,
+			     const struct v4l2_format_info *info)
 {
 	u32 mi_ctrl;
 
 	rkisp1_mp_disable(cap);
 
 	mi_ctrl = rkisp1_read(cap->rkisp1, RKISP1_CIF_MI_CTRL);
-	if (v4l2_is_format_bayer(cap->pix.info))
+	if (v4l2_is_format_bayer(info))
 		mi_ctrl |= RKISP1_CIF_MI_CTRL_RAW_ENABLE;
 	/* YUV */
 	else
@@ -639,7 +660,8 @@ static void rkisp1_mp_enable(struct rkisp1_capture *cap)
 	rkisp1_write(cap->rkisp1, RKISP1_CIF_MI_CTRL, mi_ctrl);
 }
 
-static void rkisp1_sp_enable(struct rkisp1_capture *cap)
+static void rkisp1_sp_enable(struct rkisp1_capture *cap,
+			     const struct v4l2_format_info *info)
 {
 	u32 mi_ctrl = rkisp1_read(cap->rkisp1, RKISP1_CIF_MI_CTRL);
 
@@ -755,26 +777,12 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
 
 		rkisp1_write(cap->rkisp1, cap->config->mi.y_base_ad_init,
 			     buff_addr[RKISP1_PLANE_Y] >> shift);
-		/*
-		 * In order to support grey format we capture
-		 * YUV422 planar format from the camera and
-		 * set the U and V planes to the dummy buffer
-		 */
-		if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
-			rkisp1_write(cap->rkisp1,
-				     cap->config->mi.cb_base_ad_init,
-				     cap->buf.dummy.dma_addr >> shift);
-			rkisp1_write(cap->rkisp1,
-				     cap->config->mi.cr_base_ad_init,
-				     cap->buf.dummy.dma_addr >> shift);
-		} else {
-			rkisp1_write(cap->rkisp1,
-				     cap->config->mi.cb_base_ad_init,
-				     buff_addr[RKISP1_PLANE_CB] >> shift);
-			rkisp1_write(cap->rkisp1,
-				     cap->config->mi.cr_base_ad_init,
-				     buff_addr[RKISP1_PLANE_CR] >> shift);
-		}
+		rkisp1_write(cap->rkisp1,
+			     cap->config->mi.cb_base_ad_init,
+			     buff_addr[RKISP1_PLANE_CB] >> shift);
+		rkisp1_write(cap->rkisp1,
+			     cap->config->mi.cr_base_ad_init,
+			     buff_addr[RKISP1_PLANE_CR] >> shift);
 	} else {
 		/*
 		 * Use the dummy space allocated by dma_alloc_coherent to
@@ -907,6 +915,10 @@ static int rkisp1_vb2_buf_init(struct vb2_buffer *vb)
 	const struct v4l2_format *format =
 		video_device_state_get_fmt(cap->vnode.vdev.state);
 	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
+	const struct rkisp1_capture_fmt_cfg *cfg =
+		rkisp1_find_fmt_cfg(cap, pixm->pixelformat);
+	const struct v4l2_format_info *info =
+		v4l2_format_info(pixm->pixelformat);
 	unsigned int i;
 
 	memset(ispbuf->buff_addr, 0, sizeof(ispbuf->buff_addr));
@@ -927,9 +939,19 @@ static int rkisp1_vb2_buf_init(struct vb2_buffer *vb)
 	 * uv swap can be supported for planar formats by switching
 	 * the address of cb and cr
 	 */
-	if (cap->pix.info->comp_planes == 3 && cap->pix.cfg->uv_swap)
+	if (info->comp_planes == 3 && cfg->uv_swap)
 		swap(ispbuf->buff_addr[RKISP1_PLANE_CR],
 		     ispbuf->buff_addr[RKISP1_PLANE_CB]);
+
+	/*
+	 * grey format can be supported by using dummy buffer for
+	 * the cb and cr planes
+	 */
+	if (cfg->fourcc == V4L2_PIX_FMT_GREY) {
+		ispbuf->buff_addr[RKISP1_PLANE_CB] = cap->buf.dummy.dma_addr;
+		ispbuf->buff_addr[RKISP1_PLANE_CR] = cap->buf.dummy.dma_addr;
+	}
+
 	return 0;
 }
 
@@ -1001,15 +1023,22 @@ static void rkisp1_cap_stream_enable(struct rkisp1_capture *cap)
 {
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	struct rkisp1_capture *other = &rkisp1->capture_devs[cap->id ^ 1];
+	const struct v4l2_format *format =
+		video_device_state_get_fmt(cap->vnode.vdev.state);
+	const struct v4l2_pix_format_mplane *pixm = &format->fmt.pix_mp;
+	const struct rkisp1_capture_fmt_cfg *cfg =
+		rkisp1_find_fmt_cfg(cap, pixm->pixelformat);
+	const struct v4l2_format_info *info =
+		v4l2_format_info(pixm->pixelformat);
 	bool has_self_path = rkisp1_has_feature(rkisp1, SELF_PATH);
 
 	cap->ops->set_data_path(cap);
-	cap->ops->config(cap);
+	cap->ops->config(cap, cfg, info);
 
 	/* Setup a buffer for the next frame */
 	spin_lock_irq(&cap->buf.lock);
 	rkisp1_set_next_buf(cap);
-	cap->ops->enable(cap);
+	cap->ops->enable(cap, info);
 
 	/*
 	 * It's safe to configure ACTIVE and SHADOW registers for the first
@@ -1224,9 +1253,8 @@ static const struct vb2_ops rkisp1_vb2_ops = {
  * IOCTLs operations
  */
 
-static const struct v4l2_format_info *
-rkisp1_fill_pixfmt(const struct rkisp1_capture *cap,
-		   struct v4l2_pix_format_mplane *pixm)
+static void rkisp1_fill_pixfmt(const struct rkisp1_capture *cap,
+			       struct v4l2_pix_format_mplane *pixm)
 {
 	struct v4l2_plane_pix_format *plane_y = &pixm->plane_fmt[0];
 	const struct v4l2_format_info *info;
@@ -1273,34 +1301,13 @@ rkisp1_fill_pixfmt(const struct rkisp1_capture *cap,
 	if (info->mem_planes == 1)
 		for (i = 1; i < info->comp_planes; i++)
 			plane_y->sizeimage += pixm->plane_fmt[i].sizeimage;
-
-	return info;
-}
-
-static const struct rkisp1_capture_fmt_cfg *
-rkisp1_find_fmt_cfg(const struct rkisp1_capture *cap, const u32 pixelfmt)
-{
-	bool yc_swap_support = rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE);
-	unsigned int i;
-
-	for (i = 0; i < cap->config->fmt_size; i++) {
-		const struct rkisp1_capture_fmt_cfg *fmt = &cap->config->fmts[i];
-
-		if (fmt->fourcc == pixelfmt &&
-		    (!fmt->yc_swap || yc_swap_support))
-			return &cap->config->fmts[i];
-	}
-	return NULL;
 }
 
 static void rkisp1_adj_fmt(const struct rkisp1_capture *cap,
-			   struct v4l2_pix_format_mplane *pixm,
-			   const struct rkisp1_capture_fmt_cfg **fmt_cfg,
-			   const struct v4l2_format_info **fmt_info)
+			   struct v4l2_pix_format_mplane *pixm)
 {
 	const struct rkisp1_capture_config *config = cap->config;
 	const struct rkisp1_capture_fmt_cfg *fmt;
-	const struct v4l2_format_info *info;
 	static const unsigned int max_widths[] = {
 		RKISP1_RSZ_MP_SRC_MAX_WIDTH, RKISP1_RSZ_SP_SRC_MAX_WIDTH
 	};
@@ -1324,12 +1331,7 @@ static void rkisp1_adj_fmt(const struct rkisp1_capture *cap,
 	pixm->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
 	pixm->quantization = V4L2_QUANTIZATION_DEFAULT;
 
-	info = rkisp1_fill_pixfmt(cap, pixm);
-
-	if (fmt_cfg)
-		*fmt_cfg = fmt;
-	if (fmt_info)
-		*fmt_info = info;
+	rkisp1_fill_pixfmt(cap, pixm);
 }
 
 static int rkisp1_adj_fmt_vid_cap_mplane(struct file *file,
@@ -1338,17 +1340,13 @@ static int rkisp1_adj_fmt_vid_cap_mplane(struct file *file,
 {
 	struct rkisp1_capture *cap = video_drvdata(file);
 
-	if (state->which == VIDEO_DEVICE_STATE_ACTIVE) {
-		if (vb2_is_busy(cap->vnode.vdev.queue))
-			return -EBUSY;
-
-		rkisp1_adj_fmt(cap, &f->fmt.pix_mp, &cap->pix.cfg,
-			       &cap->pix.info);
-	} else {
-		rkisp1_adj_fmt(cap, &f->fmt.pix_mp, NULL, NULL);
-	}
+	if (state->which == VIDEO_DEVICE_STATE_ACTIVE &&
+	    vb2_is_busy(cap->vnode.vdev.queue))
+		return -EBUSY;
 
+	rkisp1_adj_fmt(cap, &f->fmt.pix_mp);
 	state->fmt = *f;
+
 	return 0;
 }
 
@@ -1458,7 +1456,7 @@ static int rkisp1_vdev_init_state(struct video_device_state *state)
 	pixm->width = RKISP1_DEFAULT_WIDTH;
 	pixm->height = RKISP1_DEFAULT_HEIGHT;
 
-	rkisp1_adj_fmt(cap, pixm, &cap->pix.cfg, &cap->pix.info);
+	rkisp1_adj_fmt(cap, pixm);
 
 	return 0;
 }
drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +0 -6
index 5731c4b368f8832c2b0748338cd0da2d0edf0a93..daea11c55c9937d08f06efa2fddb307a8b5d767a 100644
@@ -316,8 +316,6 @@ struct rkisp1_device;
  * rkisp1 uses shadow registers, so it needs two buffers at a time
  * @buf.curr:	  the buffer used for current frame
  * @buf.next:	  the buffer used for next frame
- * @pix.cfg:	  pixel configuration
- * @pix.info:	  a pointer to the v4l2_format_info of the pixel format
  */
 struct rkisp1_capture {
 	struct rkisp1_vdev_node vnode;
@@ -336,10 +334,6 @@ struct rkisp1_capture {
 		struct rkisp1_buffer *curr;
 		struct rkisp1_buffer *next;
 	} buf;
-	struct {
-		const struct rkisp1_capture_fmt_cfg *cfg;
-		const struct v4l2_format_info *info;
-	} pix;
 };
 
 struct rkisp1_stats;
Signature · 1 line
2.51.0
#37 lore raw
In reply to Jai Luthra
Quoted 25 lines · Jai Luthra

Hi,

This patch series introduces state management for video devices.

Currently, V4L2 subdevices have a well-established state management system [1] that allows the framework to store the subdevice state at a central location.

Video devices however lack this, leading to inconsistent state handling across drivers and making it difficult to implement features like hardware multiplexing in complex media pipelines [2].

The series is composed of three parts:

- Core Infrastructure (PATCH 1-4)
Introduces the basic state structure, try state support, initialization callbacks, and driver helpers
- Framework Integration (PATCH 5-7)
Integrates state passing through the ioctl wrappers and driver implementations
- Driver Examples (PATCH 8-10)
Use the state to store formats in TI J721E CSI2RX and Rockchip RKISP1 drivers

Quoted 8 lines

This should also provide a foundation for drivers to extend or subclass the state structure with device-specific variables in future.

I have tested capture and format negotiation with the converted drivers on SK AM62A (j721e-csi2rx) and Debix Model A (rkisp1).

[1]: https://lore.kernel.org/linux-media/[email protected]/
[2]: https://lore.kernel.org/linux-media/20250724-multicontext-mainline-2025-v2-0-c9b316773486@ideasonboard.com/

When you add a Cc list., do it after the '---' (three minus signs) line, otherwise that huge unneeded noise will become part of the commit message.

Signature · 2 lines
With Best Regards,
Andy Shevchenko