From 6253f0e78367d78273ef5c7cc9e0e7dc5e73c980 Mon Sep 17 00:00:00 2001 From: Pat Wood Date: Thu, 9 Jan 2020 17:58:36 -0500 Subject: [PATCH] kernel: free hdmi rx buffers on release hdmi rx buffers were being freed on the VIDIOC_STREAMOFF ioctl call this prevented the video stream from being turned on and off more than once and also resulted in memory leaks, as the buffers weren't freed if the user-space process crashed or was killed without calling VIDIOC_STREAMOFF. --- .../rtk_hdmirx/rtd129x/hdmirx_video_dev.c | 20 +++++++++++++------ .../rtk_hdmirx/rtd129x/hdmirx_video_dev.h | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.c b/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.c index 8c0b5648a2..8c14a320f7 100644 --- a/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.c +++ b/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.c @@ -408,16 +408,10 @@ static long v4l2_hdmi_do_ioctl(struct file *file, unsigned int cmd, void *arg) } case VIDIOC_STREAMOFF: { - struct vb2_queue *vq; - HDMIRX_INFO(" ioctl VIDIOC_STREAMOFF"); vb2_streamoff(&dev->vb_hdmidq, dev->vb_hdmidq.type); - /* Release queue */ - vq = &dev->vb_hdmidq; - vb2_queue_release(vq); - hdmi_timestamp_mode = 0; break; @@ -538,6 +532,20 @@ long v4l2_hdmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return ret; } +int compat_fop_release(struct file *file) +{ + struct v4l2_hdmi_dev *dev = video_drvdata(file); + struct vb2_queue *vq; + + HDMIRX_INFO("[%s]", __func__); + + /* Release queue */ + vq = &dev->vb_hdmidq; + vb2_queue_release(vq); + + return vb2_fop_release(file); +} + long compat_v4l2_hdmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret_val; diff --git a/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.h b/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.h index fb02242d57..c981aa124a 100644 --- a/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.h +++ b/linux-rtk/drivers/media/platform/rtk_hdmirx/rtd129x/hdmirx_video_dev.h @@ -17,6 +17,7 @@ long v4l2_hdmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg); long compat_v4l2_hdmi_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +int compat_fop_release(struct file *file); int v4l2_mipi_top_open(struct file *filp); struct compat_v4l2_plane { @@ -57,7 +58,7 @@ struct compat_v4l2_buffer { static const struct v4l2_file_operations hdmi_fops = { .owner = THIS_MODULE, .open = v4l2_mipi_top_open, - .release = vb2_fop_release, + .release = compat_fop_release, .read = vb2_fop_read, .poll = vb2_fop_poll, .unlocked_ioctl = v4l2_hdmi_ioctl, /* V4L2 ioctl handler */