OpenCloudOS-Kernel/drivers/media/dvb-core/dvb_vb2.c

443 lines
10 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
/*
* dvb-vb2.c - dvb-vb2
*
* Copyright (C) 2015 Samsung Electronics
*
* Author: jh1009.sung@samsung.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*/
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <media/dvbdev.h>
#include <media/dvb_vb2.h>
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
#define DVB_V2_MAX_SIZE (4096 * 188)
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
static int vb2_debug;
module_param(vb2_debug, int, 0644);
#define dprintk(level, fmt, arg...) \
do { \
if (vb2_debug >= level) \
pr_info("vb2: %s: " fmt, __func__, ## arg); \
} while (0)
static int _queue_setup(struct vb2_queue *vq,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], struct device *alloc_devs[])
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
ctx->buf_cnt = *nbuffers;
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
*nplanes = 1;
sizes[0] = ctx->buf_siz;
/*
* videobuf2-vmalloc allocator is context-less so no need to set
* alloc_ctxs array.
*/
dprintk(3, "[%s] count=%d, size=%d\n", ctx->name,
*nbuffers, sizes[0]);
return 0;
}
static int _buffer_prepare(struct vb2_buffer *vb)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
unsigned long size = ctx->buf_siz;
if (vb2_plane_size(vb, 0) < size) {
dprintk(1, "[%s] data will not fit into plane (%lu < %lu)\n",
ctx->name, vb2_plane_size(vb, 0), size);
return -EINVAL;
}
vb2_set_plane_payload(vb, 0, size);
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
static void _buffer_queue(struct vb2_buffer *vb)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct dvb_buffer *buf = container_of(vb, struct dvb_buffer, vb);
unsigned long flags = 0;
spin_lock_irqsave(&ctx->slock, flags);
list_add_tail(&buf->list, &ctx->dvb_q);
spin_unlock_irqrestore(&ctx->slock, flags);
dprintk(3, "[%s]\n", ctx->name);
}
static int _start_streaming(struct vb2_queue *vq, unsigned int count)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
dprintk(3, "[%s] count=%d\n", ctx->name, count);
return 0;
}
static void _stop_streaming(struct vb2_queue *vq)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
struct dvb_buffer *buf;
unsigned long flags = 0;
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
dprintk(3, "[%s]\n", ctx->name);
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
spin_lock_irqsave(&ctx->slock, flags);
while (!list_empty(&ctx->dvb_q)) {
buf = list_entry(ctx->dvb_q.next,
struct dvb_buffer, list);
vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
list_del(&buf->list);
}
spin_unlock_irqrestore(&ctx->slock, flags);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
}
static void _dmxdev_lock(struct vb2_queue *vq)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
mutex_lock(&ctx->mutex);
dprintk(3, "[%s]\n", ctx->name);
}
static void _dmxdev_unlock(struct vb2_queue *vq)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
if (mutex_is_locked(&ctx->mutex))
mutex_unlock(&ctx->mutex);
dprintk(3, "[%s]\n", ctx->name);
}
static const struct vb2_ops dvb_vb2_qops = {
.queue_setup = _queue_setup,
.buf_prepare = _buffer_prepare,
.buf_queue = _buffer_queue,
.start_streaming = _start_streaming,
.stop_streaming = _stop_streaming,
.wait_prepare = _dmxdev_unlock,
.wait_finish = _dmxdev_lock,
};
static void _fill_dmx_buffer(struct vb2_buffer *vb, void *pb)
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct dmx_buffer *b = pb;
b->index = vb->index;
b->length = vb->planes[0].length;
b->bytesused = vb->planes[0].bytesused;
b->offset = vb->planes[0].m.offset;
dprintk(3, "[%s]\n", ctx->name);
}
static int _fill_vb2_buffer(struct vb2_buffer *vb, struct vb2_plane *planes)
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
{
struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
planes[0].bytesused = 0;
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
static const struct vb2_buf_ops dvb_vb2_buf_ops = {
.fill_user_buffer = _fill_dmx_buffer,
.fill_vb2_buffer = _fill_vb2_buffer,
};
/*
* Videobuf operations
*/
int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int nonblocking)
{
struct vb2_queue *q = &ctx->vb_q;
int ret;
memset(ctx, 0, sizeof(struct dvb_vb2_ctx));
q->type = DVB_BUF_TYPE_CAPTURE;
/**capture type*/
q->is_output = 0;
/**only mmap is supported currently*/
q->io_modes = VB2_MMAP;
q->drv_priv = ctx;
q->buf_struct_size = sizeof(struct dvb_buffer);
q->min_buffers_needed = 1;
q->ops = &dvb_vb2_qops;
q->mem_ops = &vb2_vmalloc_memops;
q->buf_ops = &dvb_vb2_buf_ops;
q->num_buffers = 0;
ret = vb2_core_queue_init(q);
if (ret) {
ctx->state = DVB_VB2_STATE_NONE;
dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
return ret;
}
mutex_init(&ctx->mutex);
spin_lock_init(&ctx->slock);
INIT_LIST_HEAD(&ctx->dvb_q);
strscpy(ctx->name, name, DVB_VB2_NAME_MAX);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
ctx->nonblocking = nonblocking;
ctx->state = DVB_VB2_STATE_INIT;
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
int dvb_vb2_release(struct dvb_vb2_ctx *ctx)
{
struct vb2_queue *q = (struct vb2_queue *)&ctx->vb_q;
if (ctx->state & DVB_VB2_STATE_INIT)
vb2_core_queue_release(q);
ctx->state = DVB_VB2_STATE_NONE;
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx)
{
struct vb2_queue *q = &ctx->vb_q;
int ret;
ret = vb2_core_streamon(q, q->type);
if (ret) {
ctx->state = DVB_VB2_STATE_NONE;
dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
return ret;
}
ctx->state |= DVB_VB2_STATE_STREAMON;
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx)
{
struct vb2_queue *q = (struct vb2_queue *)&ctx->vb_q;
int ret;
ctx->state &= ~DVB_VB2_STATE_STREAMON;
ret = vb2_core_streamoff(q, q->type);
if (ret) {
ctx->state = DVB_VB2_STATE_NONE;
dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
return ret;
}
dprintk(3, "[%s]\n", ctx->name);
return 0;
}
int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx)
{
return (ctx->state & DVB_VB2_STATE_STREAMON);
}
int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
const unsigned char *src, int len,
enum dmx_buffer_flags *buffer_flags)
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
{
unsigned long flags = 0;
void *vbuf = NULL;
int todo = len;
unsigned char *psrc = (unsigned char *)src;
int ll = 0;
/*
* normal case: This func is called twice from demux driver
* one with valid src pointer, second time with NULL pointer
*/
if (!src || !len)
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
return 0;
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
spin_lock_irqsave(&ctx->slock, flags);
if (buffer_flags && *buffer_flags) {
ctx->flags |= *buffer_flags;
*buffer_flags = 0;
}
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
while (todo) {
if (!ctx->buf) {
if (list_empty(&ctx->dvb_q)) {
dprintk(3, "[%s] Buffer overflow!!!\n",
ctx->name);
break;
}
ctx->buf = list_entry(ctx->dvb_q.next,
struct dvb_buffer, list);
ctx->remain = vb2_plane_size(&ctx->buf->vb, 0);
ctx->offset = 0;
}
if (!dvb_vb2_is_streaming(ctx)) {
vb2_buffer_done(&ctx->buf->vb, VB2_BUF_STATE_ERROR);
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
list_del(&ctx->buf->list);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
ctx->buf = NULL;
break;
}
/* Fill buffer */
ll = min(todo, ctx->remain);
vbuf = vb2_plane_vaddr(&ctx->buf->vb, 0);
memcpy(vbuf + ctx->offset, psrc, ll);
todo -= ll;
psrc += ll;
ctx->remain -= ll;
ctx->offset += ll;
if (ctx->remain == 0) {
vb2_buffer_done(&ctx->buf->vb, VB2_BUF_STATE_DONE);
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
list_del(&ctx->buf->list);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
ctx->buf = NULL;
}
}
if (ctx->nonblocking && ctx->buf) {
vb2_set_plane_payload(&ctx->buf->vb, 0, ll);
vb2_buffer_done(&ctx->buf->vb, VB2_BUF_STATE_DONE);
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
list_del(&ctx->buf->list);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
ctx->buf = NULL;
}
media: dvb_vb2: fix a warning about streamoff logic The streamoff logic is causing those warnings: WARNING: CPU: 3 PID: 3382 at drivers/media/v4l2-core/videobuf2-core.c:1652 __vb2_queue_cancel+0x177/0x250 [videobuf2_core] Modules linked in: bnep fuse xt_CHECKSUM iptable_mangle tun ebtable_filter ebtables ip6table_filter ip6_tables xt_physdev br_netfilter bluetooth bridge rfkill ecdh_generic stp llc nf_log_ipv4 nf_log_common xt_LOG xt_conntrack ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c sunrpc vfat fat snd_hda_codec_hdmi rc_dib0700_nec i915 rc_pinnacle_pctv_hd em28xx_rc a8293 ts2020 m88ds3103 i2c_mux em28xx_dvb dib8000 dvb_usb_dib0700 dib0070 dib7000m dib0090 dvb_usb dvb_core uvcvideo snd_usb_audio videobuf2_v4l2 dib3000mc videobuf2_vmalloc videobuf2_memops dibx000_common videobuf2_core rc_core snd_usbmidi_lib snd_rawmidi em28xx tveeprom v4l2_common videodev media intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_intel kvm_intel snd_hda_codec kvm snd_hwdep snd_hda_core snd_seq irqbypass crct10dif_pclmul crc32_pclmul i2c_algo_bit ghash_clmulni_intel snd_seq_device drm_kms_helper snd_pcm intel_cstate intel_uncore snd_timer tpm_tis drm mei_wdt iTCO_wdt iTCO_vendor_support tpm_tis_core snd intel_rapl_perf mei_me mei tpm i2c_i801 soundcore lpc_ich video binfmt_misc hid_logitech_hidpp hid_logitech_dj e1000e crc32c_intel ptp pps_core analog gameport joydev CPU: 3 PID: 3382 Comm: lt-dvbv5-zap Not tainted 4.14.0+ #3 Hardware name: /D53427RKE, BIOS RKPPT10H.86A.0048.2017.0506.1545 05/06/2017 task: ffff94b93bbe1e40 task.stack: ffffb7a98320c000 RIP: 0010:__vb2_queue_cancel+0x177/0x250 [videobuf2_core] RSP: 0018:ffffb7a98320fd40 EFLAGS: 00010202 RAX: 0000000000000001 RBX: ffff94b92ff72428 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff94b92ff72428 RBP: ffffb7a98320fd68 R08: ffff94b92ff725d8 R09: ffffb7a98320fcc8 R10: ffff94b978003d98 R11: ffff94b92ff72428 R12: ffff94b92ff72428 R13: 0000000000000282 R14: ffff94b92059ae20 R15: dead000000000100 FS: 0000000000000000(0000) GS:ffff94b99e380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555953007d70 CR3: 000000012be09004 CR4: 00000000001606e0 Call Trace: vb2_core_streamoff+0x28/0x90 [videobuf2_core] dvb_vb2_stream_off+0xd1/0x150 [dvb_core] dvb_dvr_release+0x114/0x120 [dvb_core] __fput+0xdf/0x1e0 ____fput+0xe/0x10 task_work_run+0x94/0xc0 do_exit+0x2dc/0xba0 do_group_exit+0x47/0xb0 SyS_exit_group+0x14/0x20 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: 0033:0x7f775e931ed8 RSP: 002b:00007fff07019d68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000001d02690 RCX: 00007f775e931ed8 RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001 RBP: 00007fff0701a500 R08: 00000000000000e7 R09: ffffffffffffff70 R10: 00007f775e854dd8 R11: 0000000000000246 R12: 0000000000000000 R13: 00000000035fa000 R14: 000000000000000a R15: 000000000000000a Code: 00 00 04 74 1c 44 89 e8 49 83 c5 01 41 39 84 24 88 01 00 00 77 8a 5b 41 5c 41 5d 41 5e 41 5f 5d c3 48 89 df e8 bb fd ff ff eb da <0f> ff 41 8b b4 24 88 01 00 00 85 f6 74 34 bb 01 00 00 00 eb 10 There are actually two issues here: 1) list_del() should be called when changing the buffer state; 2) The logic with marks the buffers as done is at the wrong place. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-21 16:13:34 +08:00
spin_unlock_irqrestore(&ctx->slock, flags);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
if (todo)
dprintk(1, "[%s] %d bytes are dropped.\n", ctx->name, todo);
else
dprintk(3, "[%s]\n", ctx->name);
dprintk(3, "[%s] %d bytes are copied\n", ctx->name, len - todo);
return (len - todo);
}
int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req)
{
int ret;
/* Adjust size to a sane value */
if (req->size > DVB_V2_MAX_SIZE)
req->size = DVB_V2_MAX_SIZE;
/* FIXME: round req->size to a 188 or 204 multiple */
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
ctx->buf_siz = req->size;
ctx->buf_cnt = req->count;
ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, &req->count);
if (ret) {
ctx->state = DVB_VB2_STATE_NONE;
dprintk(1, "[%s] count=%d size=%d errno=%d\n", ctx->name,
ctx->buf_cnt, ctx->buf_siz, ret);
return ret;
}
ctx->state |= DVB_VB2_STATE_REQBUFS;
dprintk(3, "[%s] count=%d size=%d\n", ctx->name,
ctx->buf_cnt, ctx->buf_siz);
return 0;
}
int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
{
vb2_core_querybuf(&ctx->vb_q, b->index, b);
dprintk(3, "[%s] index=%d\n", ctx->name, b->index);
return 0;
}
int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp)
{
struct vb2_queue *q = &ctx->vb_q;
int ret;
ret = vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, exp->index,
0, exp->flags);
if (ret) {
dprintk(1, "[%s] index=%d errno=%d\n", ctx->name,
exp->index, ret);
return ret;
}
dprintk(3, "[%s] index=%d fd=%d\n", ctx->name, exp->index, exp->fd);
return 0;
}
int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
{
int ret;
ret = vb2_core_qbuf(&ctx->vb_q, b->index, b, NULL);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
if (ret) {
dprintk(1, "[%s] index=%d errno=%d\n", ctx->name,
b->index, ret);
return ret;
}
dprintk(5, "[%s] index=%d\n", ctx->name, b->index);
return 0;
}
int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b)
{
unsigned long flags;
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
int ret;
ret = vb2_core_dqbuf(&ctx->vb_q, &b->index, b, ctx->nonblocking);
if (ret) {
dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
return ret;
}
spin_lock_irqsave(&ctx->slock, flags);
b->count = ctx->count++;
b->flags = ctx->flags;
ctx->flags = 0;
spin_unlock_irqrestore(&ctx->slock, flags);
dprintk(5, "[%s] index=%d, count=%d, flags=%d\n",
ctx->name, b->index, ctx->count, b->flags);
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
return 0;
}
int dvb_vb2_mmap(struct dvb_vb2_ctx *ctx, struct vm_area_struct *vma)
{
int ret;
ret = vb2_mmap(&ctx->vb_q, vma);
if (ret) {
dprintk(1, "[%s] errno=%d\n", ctx->name, ret);
return ret;
}
dprintk(3, "[%s] ret=%d\n", ctx->name, ret);
return 0;
}
__poll_t dvb_vb2_poll(struct dvb_vb2_ctx *ctx, struct file *file,
poll_table *wait)
media: videobuf2: Add new uAPI for DVB streaming I/O Adds a new uAPI for DVB to use streaming I/O which is implemented based on videobuf2, using those new ioctls: - DMX_REQBUFS: Request kernel to allocate buffers which count and size are dedicated by user. - DMX_QUERYBUF: Get the buffer information like a memory offset which will mmap() and be shared with user-space. - DMX_EXPBUF: Just for testing whether buffer-exporting success or not. - DMX_QBUF: Pass the buffer to kernel-space. - DMX_DQBUF: Get back the buffer which may contain TS data. Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as seen at: https://patchwork.linuxtv.org/patch/31613/ https://patchwork.kernel.org/patch/7334301/ The original patch was written before merging VB2-core functionalities upstream. When such series was added, several adjustments were made, fixing some issues with V4L2, causing the original patch to be non-trivially rebased. After rebased, a few bugs in the patch were fixed. The patch was also enhanced it and polling functionality got added. The main changes over the original patch are: dvb_vb2_fill_buffer(): - Set the size of the outgoing buffer after while loop using vb2_set_plane_payload; - Added NULL check for source buffer as per normal convention of demux driver, this is called twice, first time with valid buffer second time with NULL pointer, if its not handled, it will result in crash - Restricted spinlock for only list_* operations dvb_vb2_init(): - Restricted q->io_modes to only VB2_MMAP as its the only supported mode dvb_vb2_release(): - Replaced the && in if condiion with &, because otherwise it was always getting satisfied. dvb_vb2_stream_off(): - Added list_del code for enqueud buffers upon stream off dvb_vb2_poll(): - Added this new function in order to support polling dvb_demux_poll() and dvb_dvr_poll() - dvb_vb2_poll() is now called from these functions - Ported this patch and latest videobuf2 to lower kernel versions and tested auto scan. Co-developed-by: Junghak Sung <jh1009.sung@samsung.com> [mchehab@s-opensource.com: checkpatch fixes] Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Satendra Singh Thakur <satendra.t@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-19 11:35:53 +08:00
{
dprintk(3, "[%s]\n", ctx->name);
return vb2_core_poll(&ctx->vb_q, file, wait);
}