]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
media: Wrap file->private_data access with a helper function
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Sun, 10 Aug 2025 01:29:50 +0000 (04:29 +0300)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Wed, 13 Aug 2025 06:33:23 +0000 (08:33 +0200)
commit618882c92681de18e9bd99d2a88bb21c897283f3
tree06572425dc09a2ac4d133ed31cbfa419ab94bdba
parent0fd7155307bebb7daf946abae0ee8e50d20819ed
media: Wrap file->private_data access with a helper function

Accessing file->private_data manually to retrieve the v4l2_fh pointer is
error-prone, as the field is a void * and will happily convert
implicitly to any pointer type. To avoid direct access to
file->private_data, introduce a new inline function that retrieves the
v4l2_fh pointer, and use it to replace common access patterns through
the kernel.

Changes to drivers have been generated with the following coccinelle
semantic patch:

@@
struct file *filp;
identifier fh;
@@

-       struct v4l2_fh *fh = filp->private_data;
+       struct v4l2_fh *fh = file_to_v4l2_fh(filp);

Manual changes have been applied to Documentation/ to update the usage
patterns, and to include/media/v4l2-fh.h to add the new function.

While at it, fix a typo in the title of v4l2-fh.rst: the file describes
the "file handles" API, not "file handlers".

No functional change is intended, this only paves the way to remove
direct accesses to file->private_data and make V4L2 drivers safer.
Other accesses to the field will be addressed separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
19 files changed:
Documentation/driver-api/media/v4l2-fh.rst
Documentation/translations/zh_CN/video4linux/v4l2-framework.txt
drivers/media/common/videobuf2/videobuf2-v4l2.c
drivers/media/pci/cx18/cx18-fileops.c
drivers/media/pci/ivtv/ivtv-fileops.c
drivers/media/platform/allegro-dvt/allegro-core.c
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
drivers/media/platform/nvidia/tegra-vde/v4l2.c
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
drivers/media/platform/renesas/vsp1/vsp1_histo.c
drivers/media/platform/renesas/vsp1/vsp1_video.c
drivers/media/platform/ti/omap3isp/ispvideo.c
drivers/media/platform/xilinx/xilinx-dma.c
drivers/media/usb/uvc/uvc_metadata.c
drivers/media/v4l2-core/v4l2-ctrls-api.c
drivers/media/v4l2-core/v4l2-fh.c
drivers/media/v4l2-core/v4l2-mem2mem.c
drivers/media/v4l2-core/v4l2-subdev.c
include/media/v4l2-fh.h