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

media: Replace file->private_data access with file_to_v4l2_fh()

Accessing file->private_data manually to retrieve the v4l2_fh pointer is
error-prone, as the field is a void * and will happily cast implicitly
to any pointer type.

Replace all remaining locations that read the v4l2_fh pointer directly
from file->private_data with usage of the file_to_v4l2_fh() function.
The change was generated manually.

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
8003313d 618882c9

+43 -38
+1 -1
drivers/media/pci/cx18/cx18-driver.h
··· 414 414 415 415 static inline struct cx18_open_id *file2id(struct file *file) 416 416 { 417 - return fh2id(file->private_data); 417 + return fh2id(file_to_v4l2_fh(file)); 418 418 } 419 419 420 420 /* forward declaration of struct defined in cx18-cards.h */
+1 -1
drivers/media/pci/cx18/cx18-fileops.c
··· 709 709 } 710 710 711 711 if (id->type == CX18_ENC_STREAM_TYPE_YUV && 712 - filp->private_data == vdev->queue->owner) { 712 + file_to_v4l2_fh(filp) == vdev->queue->owner) { 713 713 vb2_queue_release(vdev->queue); 714 714 vdev->queue->owner = NULL; 715 715 }
+2 -2
drivers/media/pci/saa7164/saa7164.h
··· 182 182 183 183 static inline struct saa7164_encoder_fh *to_saa7164_encoder_fh(struct file *filp) 184 184 { 185 - return container_of(filp->private_data, struct saa7164_encoder_fh, fh); 185 + return container_of(file_to_v4l2_fh(filp), struct saa7164_encoder_fh, fh); 186 186 } 187 187 188 188 struct saa7164_vbi_fh { ··· 193 193 194 194 static inline struct saa7164_vbi_fh *to_saa7164_vbi_fh(struct file *filp) 195 195 { 196 - return container_of(filp->private_data, struct saa7164_vbi_fh, fh); 196 + return container_of(file_to_v4l2_fh(filp), struct saa7164_vbi_fh, fh); 197 197 } 198 198 199 199 struct saa7164_histogram_bucket {
+1 -1
drivers/media/platform/amphion/vpu.h
··· 328 328 329 329 static inline struct vpu_inst *to_inst(struct file *filp) 330 330 { 331 - return container_of(filp->private_data, struct vpu_inst, fh); 331 + return container_of(file_to_v4l2_fh(filp), struct vpu_inst, fh); 332 332 } 333 333 334 334 #define ctrl_to_inst(ctrl) \
+1 -1
drivers/media/platform/imagination/e5010-jpeg-enc.h
··· 122 122 123 123 static inline struct e5010_context *to_e5010_context(struct file *filp) 124 124 { 125 - return container_of(filp->private_data, struct e5010_context, fh); 125 + return container_of(file_to_v4l2_fh(filp), struct e5010_context, fh); 126 126 } 127 127 128 128 /*
+1 -1
drivers/media/platform/nxp/dw100/dw100.c
··· 266 266 267 267 static inline struct dw100_ctx *dw100_file2ctx(struct file *file) 268 268 { 269 - return container_of(file->private_data, struct dw100_ctx, fh); 269 + return container_of(file_to_v4l2_fh(file), struct dw100_ctx, fh); 270 270 } 271 271 272 272 static struct dw100_q_data *dw100_get_q_data(struct dw100_ctx *ctx,
+1 -1
drivers/media/platform/nxp/imx-pxp.c
··· 248 248 249 249 static inline struct pxp_ctx *file2ctx(struct file *file) 250 250 { 251 - return container_of(file->private_data, struct pxp_ctx, fh); 251 + return container_of(file_to_v4l2_fh(file), struct pxp_ctx, fh); 252 252 } 253 253 254 254 static struct pxp_q_data *get_q_data(struct pxp_ctx *ctx,
+1 -1
drivers/media/platform/qcom/iris/iris_vidc.c
··· 69 69 70 70 static inline struct iris_inst *iris_get_inst(struct file *filp, void *fh) 71 71 { 72 - return container_of(filp->private_data, struct iris_inst, fh); 72 + return container_of(file_to_v4l2_fh(filp), struct iris_inst, fh); 73 73 } 74 74 75 75 static void iris_m2m_device_run(void *priv)
+1 -1
drivers/media/platform/qcom/venus/core.h
··· 535 535 536 536 static inline struct venus_inst *to_inst(struct file *filp) 537 537 { 538 - return container_of(filp->private_data, struct venus_inst, fh); 538 + return container_of(file_to_v4l2_fh(filp), struct venus_inst, fh); 539 539 } 540 540 541 541 static inline void *to_hfi_priv(struct venus_core *core)
+3 -3
drivers/media/platform/samsung/s3c-camif/camif-capture.c
··· 572 572 573 573 mutex_lock(&camif->lock); 574 574 575 - if (vp->owner == file->private_data) { 575 + if (vp->owner == file_to_v4l2_fh(file)) { 576 576 camif_stop_capture(vp); 577 577 vb2_queue_release(&vp->vb_queue); 578 578 vp->owner = NULL; ··· 595 595 __poll_t ret; 596 596 597 597 mutex_lock(&camif->lock); 598 - if (vp->owner && vp->owner != file->private_data) 598 + if (vp->owner && vp->owner != file_to_v4l2_fh(file)) 599 599 ret = EPOLLERR; 600 600 else 601 601 ret = vb2_poll(&vp->vb_queue, file, wait); ··· 609 609 struct camif_vp *vp = video_drvdata(file); 610 610 int ret; 611 611 612 - if (vp->owner && vp->owner != file->private_data) 612 + if (vp->owner && vp->owner != file_to_v4l2_fh(file)) 613 613 ret = -EBUSY; 614 614 else 615 615 ret = vb2_mmap(&vp->vb_queue, vma);
+1 -1
drivers/media/platform/sunxi/sun8i-di/sun8i-di.c
··· 309 309 310 310 static inline struct deinterlace_ctx *deinterlace_file2ctx(struct file *file) 311 311 { 312 - return container_of(file->private_data, struct deinterlace_ctx, fh); 312 + return container_of(file_to_v4l2_fh(file), struct deinterlace_ctx, fh); 313 313 } 314 314 315 315 static bool deinterlace_check_format(u32 pixelformat)
+1 -1
drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
··· 170 170 171 171 static inline struct rotate_ctx *rotate_file2ctx(struct file *file) 172 172 { 173 - return container_of(file->private_data, struct rotate_ctx, fh); 173 + return container_of(file_to_v4l2_fh(file), struct rotate_ctx, fh); 174 174 } 175 175 176 176 static void rotate_prepare_format(struct v4l2_pix_format *pix_fmt)
+1 -1
drivers/media/platform/ti/vpe/vpe.c
··· 424 424 425 425 static inline struct vpe_ctx *to_vpe_ctx(struct file *filp) 426 426 { 427 - return container_of(filp->private_data, struct vpe_ctx, fh); 427 + return container_of(file_to_v4l2_fh(filp), struct vpe_ctx, fh); 428 428 } 429 429 430 430 /*
+1 -1
drivers/media/test-drivers/vicodec/vicodec-core.c
··· 144 144 145 145 static inline struct vicodec_ctx *file2ctx(struct file *file) 146 146 { 147 - return container_of(file->private_data, struct vicodec_ctx, fh); 147 + return container_of(file_to_v4l2_fh(file), struct vicodec_ctx, fh); 148 148 } 149 149 150 150 static struct vicodec_q_data *get_q_data(struct vicodec_ctx *ctx,
+1 -1
drivers/media/test-drivers/vim2m.c
··· 236 236 237 237 static inline struct vim2m_ctx *file2ctx(struct file *file) 238 238 { 239 - return container_of(file->private_data, struct vim2m_ctx, fh); 239 + return container_of(file_to_v4l2_fh(file), struct vim2m_ctx, fh); 240 240 } 241 241 242 242 static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx,
+1 -1
drivers/media/test-drivers/visl/visl.h
··· 163 163 164 164 static inline struct visl_ctx *visl_file_to_ctx(struct file *file) 165 165 { 166 - return container_of(file->private_data, struct visl_ctx, fh); 166 + return container_of(file_to_v4l2_fh(file), struct visl_ctx, fh); 167 167 } 168 168 169 169 static inline struct visl_ctx *visl_v4l2fh_to_ctx(struct v4l2_fh *v4l2_fh)
+2 -2
drivers/media/test-drivers/vivid/vivid-core.c
··· 654 654 v4l2_info(&dev->v4l2_dev, "reconnect\n"); 655 655 vivid_reconnect(dev); 656 656 } 657 - if (file->private_data == dev->radio_rx_rds_owner) { 657 + if (file_to_v4l2_fh(file) == dev->radio_rx_rds_owner) { 658 658 dev->radio_rx_rds_last_block = 0; 659 659 dev->radio_rx_rds_owner = NULL; 660 660 } 661 - if (file->private_data == dev->radio_tx_rds_owner) { 661 + if (file_to_v4l2_fh(file) == dev->radio_tx_rds_owner) { 662 662 dev->radio_tx_rds_last_block = 0; 663 663 dev->radio_tx_rds_owner = NULL; 664 664 }
+2 -2
drivers/media/test-drivers/vivid/vivid-radio-rx.c
··· 42 42 if (mutex_lock_interruptible(&dev->mutex)) 43 43 return -ERESTARTSYS; 44 44 if (dev->radio_rx_rds_owner && 45 - file->private_data != dev->radio_rx_rds_owner) { 45 + file_to_v4l2_fh(file) != dev->radio_rx_rds_owner) { 46 46 mutex_unlock(&dev->mutex); 47 47 return -EBUSY; 48 48 } 49 49 if (dev->radio_rx_rds_owner == NULL) { 50 50 vivid_radio_rds_init(dev); 51 - dev->radio_rx_rds_owner = file->private_data; 51 + dev->radio_rx_rds_owner = file_to_v4l2_fh(file); 52 52 } 53 53 54 54 retry:
+2 -2
drivers/media/test-drivers/vivid/vivid-radio-tx.c
··· 39 39 if (mutex_lock_interruptible(&dev->mutex)) 40 40 return -ERESTARTSYS; 41 41 if (dev->radio_tx_rds_owner && 42 - file->private_data != dev->radio_tx_rds_owner) { 42 + file_to_v4l2_fh(file) != dev->radio_tx_rds_owner) { 43 43 mutex_unlock(&dev->mutex); 44 44 return -EBUSY; 45 45 } 46 - dev->radio_tx_rds_owner = file->private_data; 46 + dev->radio_tx_rds_owner = file_to_v4l2_fh(file); 47 47 48 48 retry: 49 49 timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time);
+6 -6
drivers/media/usb/hdpvr/hdpvr-video.c
··· 390 390 struct hdpvr_device *dev = video_drvdata(file); 391 391 392 392 mutex_lock(&dev->io_mutex); 393 - if (file->private_data == dev->owner) { 393 + if (file_to_v4l2_fh(file) == dev->owner) { 394 394 hdpvr_stop_streaming(dev); 395 395 dev->owner = NULL; 396 396 } ··· 426 426 mutex_unlock(&dev->io_mutex); 427 427 goto err; 428 428 } 429 - dev->owner = file->private_data; 429 + dev->owner = file_to_v4l2_fh(file); 430 430 print_buffer_status(); 431 431 } 432 432 mutex_unlock(&dev->io_mutex); ··· 541 541 "start_streaming failed\n"); 542 542 dev->status = STATUS_IDLE; 543 543 } else { 544 - dev->owner = filp->private_data; 544 + dev->owner = file_to_v4l2_fh(filp); 545 545 } 546 546 547 547 print_buffer_status(); ··· 1048 1048 1049 1049 switch (a->cmd) { 1050 1050 case V4L2_ENC_CMD_START: 1051 - if (dev->owner && filp->private_data != dev->owner) { 1051 + if (dev->owner && file_to_v4l2_fh(filp) != dev->owner) { 1052 1052 res = -EBUSY; 1053 1053 break; 1054 1054 } ··· 1056 1056 break; 1057 1057 res = hdpvr_start_streaming(dev); 1058 1058 if (!res) 1059 - dev->owner = filp->private_data; 1059 + dev->owner = file_to_v4l2_fh(filp); 1060 1060 else 1061 1061 dev->status = STATUS_IDLE; 1062 1062 break; 1063 1063 case V4L2_ENC_CMD_STOP: 1064 - if (dev->owner && filp->private_data != dev->owner) { 1064 + if (dev->owner && file_to_v4l2_fh(filp) != dev->owner) { 1065 1065 res = -EBUSY; 1066 1066 break; 1067 1067 }
+1 -1
drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
··· 48 48 49 49 static inline struct pvr2_v4l2_fh *to_pvr2_v4l2_fh(struct file *filp) 50 50 { 51 - return container_of(filp->private_data, struct pvr2_v4l2_fh, fh); 51 + return container_of(file_to_v4l2_fh(filp), struct pvr2_v4l2_fh, fh); 52 52 } 53 53 54 54 struct pvr2_v4l2 {
+1 -1
drivers/media/usb/uvc/uvcvideo.h
··· 639 639 640 640 static inline struct uvc_fh *to_uvc_fh(struct file *filp) 641 641 { 642 - return container_of(filp->private_data, struct uvc_fh, vfh); 642 + return container_of(file_to_v4l2_fh(filp), struct uvc_fh, vfh); 643 643 } 644 644 645 645 /* ------------------------------------------------------------------------
+1 -1
drivers/media/v4l2-core/v4l2-compat-ioctl32.c
··· 678 678 const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops; 679 679 680 680 if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags)) 681 - fh = file->private_data; 681 + fh = file_to_v4l2_fh(file); 682 682 683 683 if (fh && fh->ctrl_handler) 684 684 hdl = fh->ctrl_handler;
+2 -2
drivers/media/v4l2-core/v4l2-ioctl.c
··· 1197 1197 vfd = video_devdata(file); 1198 1198 if (!test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) 1199 1199 return -ENOTTY; 1200 - vfh = file->private_data; 1200 + vfh = file_to_v4l2_fh(file); 1201 1201 return v4l2_prio_change(vfd->prio, &vfh->prio, *p); 1202 1202 } 1203 1203 ··· 3084 3084 } 3085 3085 3086 3086 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) 3087 - vfh = file->private_data; 3087 + vfh = file_to_v4l2_fh(file); 3088 3088 3089 3089 /* 3090 3090 * We need to serialize streamon/off with queueing new requests.
+1 -1
drivers/staging/most/video/video.c
··· 54 54 55 55 static inline struct comp_fh *to_comp_fh(struct file *filp) 56 56 { 57 - return container_of(filp->private_data, struct comp_fh, fh); 57 + return container_of(file_to_v4l2_fh(filp), struct comp_fh, fh); 58 58 } 59 59 60 60 static LIST_HEAD(video_devices);
+5
drivers/usb/gadget/function/uvc.h
··· 196 196 #define to_uvc_file_handle(handle) \ 197 197 container_of(handle, struct uvc_file_handle, vfh) 198 198 199 + static inline struct uvc_file_handle *file_to_uvc_file_handle(struct file *filp) 200 + { 201 + return container_of(file_to_v4l2_fh(filp), struct uvc_file_handle, vfh); 202 + } 203 + 199 204 /* ------------------------------------------------------------------------ 200 205 * Functions 201 206 */
+1 -1
drivers/usb/gadget/function/uvc_v4l2.c
··· 685 685 { 686 686 struct video_device *vdev = video_devdata(file); 687 687 struct uvc_device *uvc = video_get_drvdata(vdev); 688 - struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); 688 + struct uvc_file_handle *handle = file_to_uvc_file_handle(file); 689 689 struct uvc_video *video = handle->device; 690 690 691 691 mutex_lock(&video->mutex);