Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Laurent Pinchart and committed by
Hans Verkuil
618882c9 0fd71553

+77 -59
+10 -6
Documentation/driver-api/media/v4l2-fh.rst
··· 1 1 .. SPDX-License-Identifier: GPL-2.0 2 2 3 - V4L2 File handlers 4 - ------------------ 3 + V4L2 File handles 4 + ----------------- 5 5 6 6 struct v4l2_fh provides a way to easily keep file handle specific 7 7 data that is used by the V4L2 framework. ··· 18 18 19 19 struct v4l2_fh is allocated as a part of the driver's own file handle 20 20 structure and ``file->private_data`` is set to it in the driver's ``open()`` 21 - function by the driver. 21 + function by the driver. The :c:type:`v4l2_fh` file handle can be retrieved 22 + from the :c:type:`file` using :c:func:`file_to_v4l2_fh`. Drivers must not 23 + access ``file->private_data`` directly. 22 24 23 25 In many cases the struct v4l2_fh will be embedded in a larger 24 26 structure. In that case you should call: ··· 65 63 66 64 int my_release(struct file *file) 67 65 { 68 - struct v4l2_fh *fh = file->private_data; 66 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 69 67 struct my_fh *my_fh = container_of(fh, struct my_fh, fh); 70 68 71 69 ... ··· 80 78 :c:func:`v4l2_fh_init <v4l2_fh_init>` 81 79 (:c:type:`fh <v4l2_fh>`, :c:type:`vdev <video_device>`) 82 80 83 - 84 81 - Initialise the file handle. This **MUST** be performed in the driver's 85 82 :c:type:`v4l2_file_operations`->open() handler. 86 - 87 83 88 84 :c:func:`v4l2_fh_add <v4l2_fh_add>` 89 85 (:c:type:`fh <v4l2_fh>`) ··· 101 101 - Uninitialise the file handle. After uninitialisation the :c:type:`v4l2_fh` 102 102 memory can be freed. 103 103 104 + :c:func:`file_to_v4l2_fh <file_to_v4l2_fh>` 105 + (struct file \*filp) 106 + 107 + - Retrieve the :c:type:`v4l2_fh` instance associated with a :c:type:`file`. 104 108 105 109 If struct v4l2_fh is not embedded, then you can use these helper functions: 106 110
+1 -1
Documentation/translations/zh_CN/video4linux/v4l2-framework.txt
··· 819 819 820 820 int my_release(struct file *file) 821 821 { 822 - struct v4l2_fh *fh = file->private_data; 822 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 823 823 struct my_fh *my_fh = container_of(fh, struct my_fh, fh); 824 824 825 825 ...
+1 -1
drivers/media/common/videobuf2/videobuf2-v4l2.c
··· 979 979 res = vb2_core_poll(q, file, wait); 980 980 981 981 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) { 982 - struct v4l2_fh *fh = file->private_data; 982 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 983 983 984 984 poll_wait(file, &fh->wait, wait); 985 985 if (v4l2_event_pending(fh))
+1 -1
drivers/media/pci/cx18/cx18-fileops.c
··· 678 678 679 679 int cx18_v4l2_close(struct file *filp) 680 680 { 681 - struct v4l2_fh *fh = filp->private_data; 681 + struct v4l2_fh *fh = file_to_v4l2_fh(filp); 682 682 struct cx18_open_id *id = fh2id(fh); 683 683 struct cx18 *cx = id->cx; 684 684 struct cx18_stream *s = &cx->streams[id->type];
+1 -1
drivers/media/pci/ivtv/ivtv-fileops.c
··· 877 877 878 878 int ivtv_v4l2_close(struct file *filp) 879 879 { 880 - struct v4l2_fh *fh = filp->private_data; 880 + struct v4l2_fh *fh = file_to_v4l2_fh(filp); 881 881 struct ivtv_open_id *id = fh2id(fh); 882 882 struct ivtv *itv = id->itv; 883 883 struct ivtv_stream *s = &itv->streams[id->type];
+1 -1
drivers/media/platform/allegro-dvt/allegro-core.c
··· 3483 3483 static int allegro_ioctl_streamon(struct file *file, void *priv, 3484 3484 enum v4l2_buf_type type) 3485 3485 { 3486 - struct v4l2_fh *fh = file->private_data; 3486 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 3487 3487 struct allegro_channel *channel = fh_to_channel(fh); 3488 3488 int err; 3489 3489
+1 -1
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
··· 588 588 589 589 static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 590 590 { 591 - struct v4l2_fh *fh = file->private_data; 591 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 592 592 struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv); 593 593 struct vb2_queue *vq; 594 594 struct vb2_buffer *vb;
+1 -1
drivers/media/platform/nvidia/tegra-vde/v4l2.c
··· 853 853 854 854 static int tegra_release(struct file *file) 855 855 { 856 - struct v4l2_fh *fh = file->private_data; 856 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 857 857 struct tegra_ctx *ctx = fh_to_tegra_ctx(fh); 858 858 struct tegra_vde *vde = ctx->vde; 859 859
+2 -2
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
··· 1604 1604 static int mxc_jpeg_decoder_cmd(struct file *file, void *priv, 1605 1605 struct v4l2_decoder_cmd *cmd) 1606 1606 { 1607 - struct v4l2_fh *fh = file->private_data; 1607 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1608 1608 struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(fh); 1609 1609 unsigned long flags; 1610 1610 int ret; ··· 1637 1637 static int mxc_jpeg_encoder_cmd(struct file *file, void *priv, 1638 1638 struct v4l2_encoder_cmd *cmd) 1639 1639 { 1640 - struct v4l2_fh *fh = file->private_data; 1640 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1641 1641 struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(fh); 1642 1642 unsigned long flags; 1643 1643 int ret;
+3 -3
drivers/media/platform/renesas/vsp1/vsp1_histo.c
··· 392 392 static int histo_v4l2_querycap(struct file *file, void *fh, 393 393 struct v4l2_capability *cap) 394 394 { 395 - struct v4l2_fh *vfh = file->private_data; 395 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 396 396 struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev); 397 397 398 398 cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING ··· 409 409 static int histo_v4l2_enum_format(struct file *file, void *fh, 410 410 struct v4l2_fmtdesc *f) 411 411 { 412 - struct v4l2_fh *vfh = file->private_data; 412 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 413 413 struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev); 414 414 415 415 if (f->index > 0 || f->type != histo->queue.type) ··· 423 423 static int histo_v4l2_get_format(struct file *file, void *fh, 424 424 struct v4l2_format *format) 425 425 { 426 - struct v4l2_fh *vfh = file->private_data; 426 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 427 427 struct vsp1_histogram *histo = vdev_to_histo(vfh->vdev); 428 428 struct v4l2_meta_format *meta = &format->fmt.meta; 429 429
+6 -6
drivers/media/platform/renesas/vsp1/vsp1_video.c
··· 896 896 static int 897 897 vsp1_video_querycap(struct file *file, void *fh, struct v4l2_capability *cap) 898 898 { 899 - struct v4l2_fh *vfh = file->private_data; 899 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 900 900 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 901 901 902 902 cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING ··· 912 912 static int vsp1_video_enum_format(struct file *file, void *fh, 913 913 struct v4l2_fmtdesc *f) 914 914 { 915 - struct v4l2_fh *vfh = file->private_data; 915 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 916 916 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 917 917 const struct vsp1_format_info *info; 918 918 ··· 933 933 static int 934 934 vsp1_video_get_format(struct file *file, void *fh, struct v4l2_format *format) 935 935 { 936 - struct v4l2_fh *vfh = file->private_data; 936 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 937 937 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 938 938 939 939 if (format->type != video->queue.type) ··· 949 949 static int 950 950 vsp1_video_try_format(struct file *file, void *fh, struct v4l2_format *format) 951 951 { 952 - struct v4l2_fh *vfh = file->private_data; 952 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 953 953 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 954 954 955 955 if (format->type != video->queue.type) ··· 961 961 static int 962 962 vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format) 963 963 { 964 - struct v4l2_fh *vfh = file->private_data; 964 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 965 965 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 966 966 const struct vsp1_format_info *info; 967 967 int ret; ··· 991 991 static int 992 992 vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) 993 993 { 994 - struct v4l2_fh *vfh = file->private_data; 994 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 995 995 struct vsp1_video *video = to_vsp1_video(vfh->vdev); 996 996 struct media_device *mdev = &video->vsp1->media_dev; 997 997 struct vsp1_pipeline *pipe;
+1 -1
drivers/media/platform/ti/omap3isp/ispvideo.c
··· 1348 1348 static int isp_video_release(struct file *file) 1349 1349 { 1350 1350 struct isp_video *video = video_drvdata(file); 1351 - struct v4l2_fh *vfh = file->private_data; 1351 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 1352 1352 struct isp_video_fh *handle = to_isp_video_fh(vfh); 1353 1353 1354 1354 /* Disable streaming and free the buffers queue resources. */
+5 -5
drivers/media/platform/xilinx/xilinx-dma.c
··· 469 469 static int 470 470 xvip_dma_querycap(struct file *file, void *fh, struct v4l2_capability *cap) 471 471 { 472 - struct v4l2_fh *vfh = file->private_data; 472 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 473 473 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); 474 474 475 475 cap->capabilities = dma->xdev->v4l2_caps | V4L2_CAP_STREAMING | ··· 491 491 static int 492 492 xvip_dma_enum_format(struct file *file, void *fh, struct v4l2_fmtdesc *f) 493 493 { 494 - struct v4l2_fh *vfh = file->private_data; 494 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 495 495 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); 496 496 497 497 if (f->index > 0) ··· 505 505 static int 506 506 xvip_dma_get_format(struct file *file, void *fh, struct v4l2_format *format) 507 507 { 508 - struct v4l2_fh *vfh = file->private_data; 508 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 509 509 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); 510 510 511 511 format->fmt.pix = dma->format; ··· 565 565 static int 566 566 xvip_dma_try_format(struct file *file, void *fh, struct v4l2_format *format) 567 567 { 568 - struct v4l2_fh *vfh = file->private_data; 568 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 569 569 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); 570 570 571 571 __xvip_dma_try_format(dma, &format->fmt.pix, NULL); ··· 575 575 static int 576 576 xvip_dma_set_format(struct file *file, void *fh, struct v4l2_format *format) 577 577 { 578 - struct v4l2_fh *vfh = file->private_data; 578 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 579 579 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); 580 580 const struct xvip_video_format *info; 581 581
+5 -5
drivers/media/usb/uvc/uvc_metadata.c
··· 26 26 static int uvc_meta_v4l2_querycap(struct file *file, void *fh, 27 27 struct v4l2_capability *cap) 28 28 { 29 - struct v4l2_fh *vfh = file->private_data; 29 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 30 30 struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); 31 31 struct uvc_video_chain *chain = stream->chain; 32 32 ··· 42 42 static int uvc_meta_v4l2_get_format(struct file *file, void *fh, 43 43 struct v4l2_format *format) 44 44 { 45 - struct v4l2_fh *vfh = file->private_data; 45 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 46 46 struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); 47 47 struct v4l2_meta_format *fmt = &format->fmt.meta; 48 48 ··· 60 60 static int uvc_meta_v4l2_try_format(struct file *file, void *fh, 61 61 struct v4l2_format *format) 62 62 { 63 - struct v4l2_fh *vfh = file->private_data; 63 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 64 64 struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); 65 65 struct uvc_device *dev = stream->dev; 66 66 struct v4l2_meta_format *fmt = &format->fmt.meta; ··· 86 86 static int uvc_meta_v4l2_set_format(struct file *file, void *fh, 87 87 struct v4l2_format *format) 88 88 { 89 - struct v4l2_fh *vfh = file->private_data; 89 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 90 90 struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); 91 91 struct v4l2_meta_format *fmt = &format->fmt.meta; 92 92 int ret; ··· 115 115 static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh, 116 116 struct v4l2_fmtdesc *fdesc) 117 117 { 118 - struct v4l2_fh *vfh = file->private_data; 118 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 119 119 struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); 120 120 struct uvc_device *dev = stream->dev; 121 121 u32 i = fdesc->index;
+2 -2
drivers/media/v4l2-core/v4l2-ctrls-api.c
··· 1253 1253 int v4l2_ctrl_log_status(struct file *file, void *fh) 1254 1254 { 1255 1255 struct video_device *vfd = video_devdata(file); 1256 - struct v4l2_fh *vfh = file->private_data; 1256 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 1257 1257 1258 1258 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev) 1259 1259 v4l2_ctrl_handler_log_status(vfh->ctrl_handler, ··· 1348 1348 */ 1349 1349 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) 1350 1350 { 1351 - struct v4l2_fh *fh = file->private_data; 1351 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1352 1352 1353 1353 poll_wait(file, &fh->wait, wait); 1354 1354 if (v4l2_event_pending(fh))
+1 -1
drivers/media/v4l2-core/v4l2-fh.c
··· 90 90 91 91 int v4l2_fh_release(struct file *filp) 92 92 { 93 - struct v4l2_fh *fh = filp->private_data; 93 + struct v4l2_fh *fh = file_to_v4l2_fh(filp); 94 94 95 95 if (fh) { 96 96 v4l2_fh_del(fh);
+17 -17
drivers/media/v4l2-core/v4l2-mem2mem.c
··· 971 971 rc = v4l2_m2m_poll_for_data(file, m2m_ctx, wait); 972 972 973 973 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) { 974 - struct v4l2_fh *fh = file->private_data; 974 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 975 975 976 976 poll_wait(file, &fh->wait, wait); 977 977 if (v4l2_event_pending(fh)) ··· 1004 1004 unsigned long len, unsigned long pgoff, 1005 1005 unsigned long flags) 1006 1006 { 1007 - struct v4l2_fh *fh = file->private_data; 1007 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1008 1008 unsigned long offset = pgoff << PAGE_SHIFT; 1009 1009 struct vb2_queue *vq; 1010 1010 ··· 1371 1371 int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv, 1372 1372 struct v4l2_requestbuffers *rb) 1373 1373 { 1374 - struct v4l2_fh *fh = file->private_data; 1374 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1375 1375 1376 1376 return v4l2_m2m_reqbufs(file, fh->m2m_ctx, rb); 1377 1377 } ··· 1380 1380 int v4l2_m2m_ioctl_create_bufs(struct file *file, void *priv, 1381 1381 struct v4l2_create_buffers *create) 1382 1382 { 1383 - struct v4l2_fh *fh = file->private_data; 1383 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1384 1384 1385 1385 return v4l2_m2m_create_bufs(file, fh->m2m_ctx, create); 1386 1386 } ··· 1389 1389 int v4l2_m2m_ioctl_remove_bufs(struct file *file, void *priv, 1390 1390 struct v4l2_remove_buffers *remove) 1391 1391 { 1392 - struct v4l2_fh *fh = file->private_data; 1392 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1393 1393 struct vb2_queue *q = v4l2_m2m_get_vq(fh->m2m_ctx, remove->type); 1394 1394 1395 1395 if (!q) ··· 1404 1404 int v4l2_m2m_ioctl_querybuf(struct file *file, void *priv, 1405 1405 struct v4l2_buffer *buf) 1406 1406 { 1407 - struct v4l2_fh *fh = file->private_data; 1407 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1408 1408 1409 1409 return v4l2_m2m_querybuf(file, fh->m2m_ctx, buf); 1410 1410 } ··· 1413 1413 int v4l2_m2m_ioctl_qbuf(struct file *file, void *priv, 1414 1414 struct v4l2_buffer *buf) 1415 1415 { 1416 - struct v4l2_fh *fh = file->private_data; 1416 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1417 1417 1418 1418 return v4l2_m2m_qbuf(file, fh->m2m_ctx, buf); 1419 1419 } ··· 1422 1422 int v4l2_m2m_ioctl_dqbuf(struct file *file, void *priv, 1423 1423 struct v4l2_buffer *buf) 1424 1424 { 1425 - struct v4l2_fh *fh = file->private_data; 1425 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1426 1426 1427 1427 return v4l2_m2m_dqbuf(file, fh->m2m_ctx, buf); 1428 1428 } ··· 1431 1431 int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *priv, 1432 1432 struct v4l2_buffer *buf) 1433 1433 { 1434 - struct v4l2_fh *fh = file->private_data; 1434 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1435 1435 1436 1436 return v4l2_m2m_prepare_buf(file, fh->m2m_ctx, buf); 1437 1437 } ··· 1440 1440 int v4l2_m2m_ioctl_expbuf(struct file *file, void *priv, 1441 1441 struct v4l2_exportbuffer *eb) 1442 1442 { 1443 - struct v4l2_fh *fh = file->private_data; 1443 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1444 1444 1445 1445 return v4l2_m2m_expbuf(file, fh->m2m_ctx, eb); 1446 1446 } ··· 1449 1449 int v4l2_m2m_ioctl_streamon(struct file *file, void *priv, 1450 1450 enum v4l2_buf_type type) 1451 1451 { 1452 - struct v4l2_fh *fh = file->private_data; 1452 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1453 1453 1454 1454 return v4l2_m2m_streamon(file, fh->m2m_ctx, type); 1455 1455 } ··· 1458 1458 int v4l2_m2m_ioctl_streamoff(struct file *file, void *priv, 1459 1459 enum v4l2_buf_type type) 1460 1460 { 1461 - struct v4l2_fh *fh = file->private_data; 1461 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1462 1462 1463 1463 return v4l2_m2m_streamoff(file, fh->m2m_ctx, type); 1464 1464 } ··· 1542 1542 int v4l2_m2m_ioctl_encoder_cmd(struct file *file, void *priv, 1543 1543 struct v4l2_encoder_cmd *ec) 1544 1544 { 1545 - struct v4l2_fh *fh = file->private_data; 1545 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1546 1546 1547 1547 return v4l2_m2m_encoder_cmd(file, fh->m2m_ctx, ec); 1548 1548 } ··· 1551 1551 int v4l2_m2m_ioctl_decoder_cmd(struct file *file, void *priv, 1552 1552 struct v4l2_decoder_cmd *dc) 1553 1553 { 1554 - struct v4l2_fh *fh = file->private_data; 1554 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1555 1555 1556 1556 return v4l2_m2m_decoder_cmd(file, fh->m2m_ctx, dc); 1557 1557 } ··· 1572 1572 int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file *file, void *priv, 1573 1573 struct v4l2_decoder_cmd *dc) 1574 1574 { 1575 - struct v4l2_fh *fh = file->private_data; 1575 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1576 1576 struct vb2_v4l2_buffer *out_vb, *cap_vb; 1577 1577 struct v4l2_m2m_dev *m2m_dev = fh->m2m_ctx->m2m_dev; 1578 1578 unsigned long flags; ··· 1617 1617 1618 1618 int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma) 1619 1619 { 1620 - struct v4l2_fh *fh = file->private_data; 1620 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1621 1621 1622 1622 return v4l2_m2m_mmap(file, fh->m2m_ctx, vma); 1623 1623 } ··· 1625 1625 1626 1626 __poll_t v4l2_m2m_fop_poll(struct file *file, poll_table *wait) 1627 1627 { 1628 - struct v4l2_fh *fh = file->private_data; 1628 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1629 1629 struct v4l2_m2m_ctx *m2m_ctx = fh->m2m_ctx; 1630 1630 __poll_t ret; 1631 1631
+4 -4
drivers/media/v4l2-core/v4l2-subdev.c
··· 122 122 { 123 123 struct video_device *vdev = video_devdata(file); 124 124 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); 125 - struct v4l2_fh *vfh = file->private_data; 125 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 126 126 struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); 127 127 128 128 if (sd->internal_ops && sd->internal_ops->close) ··· 612 612 { 613 613 struct video_device *vdev = video_devdata(file); 614 614 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); 615 - struct v4l2_fh *vfh = file->private_data; 615 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 616 616 struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); 617 617 bool ro_subdev = test_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags); 618 618 bool streams_subdev = sd->flags & V4L2_SUBDEV_FL_STREAMS; ··· 1135 1135 1136 1136 if (video_is_registered(vdev)) { 1137 1137 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); 1138 - struct v4l2_fh *vfh = file->private_data; 1138 + struct v4l2_fh *vfh = file_to_v4l2_fh(file); 1139 1139 struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); 1140 1140 struct v4l2_subdev_state *state; 1141 1141 ··· 1192 1192 { 1193 1193 struct video_device *vdev = video_devdata(file); 1194 1194 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); 1195 - struct v4l2_fh *fh = file->private_data; 1195 + struct v4l2_fh *fh = file_to_v4l2_fh(file); 1196 1196 1197 1197 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) 1198 1198 return EPOLLERR;
+14
include/media/v4l2-fh.h
··· 57 57 }; 58 58 59 59 /** 60 + * file_to_v4l2_fh - Return the v4l2_fh associated with a struct file 61 + * 62 + * @filp: pointer to &struct file 63 + * 64 + * This function should be used by drivers to retrieve the &struct v4l2_fh 65 + * instance pointer stored in the file private_data instead of accessing the 66 + * private_data field directly. 67 + */ 68 + static inline struct v4l2_fh *file_to_v4l2_fh(struct file *filp) 69 + { 70 + return filp->private_data; 71 + } 72 + 73 + /** 60 74 * v4l2_fh_init - Initialise the file handle. 61 75 * 62 76 * @fh: pointer to &struct v4l2_fh