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

Configure Feed

Select the types of activity you want to include in your feed.

media: dvb-core: dvb_vb2: drop wait_prepare/finish callbacks

Since commit 88785982a19d ("media: vb2: use lock if wait_prepare/finish
are NULL") it is no longer needed to set the wait_prepare/finish
vb2_ops callbacks as long as the lock field in vb2_queue is set.

Set the queue lock to &ctx->mutex, which makes it possible to drop
the wait_prepare/finish callbacks.

This simplifies the code and this is a step towards the goal of deleting
these callbacks.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
cbb5cd44 37fd4a03

+30 -36
+14 -1
drivers/media/dvb-core/dmxdev.c
··· 171 171 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE); 172 172 if (dmxdev->may_do_mmap) 173 173 dvb_vb2_init(&dmxdev->dvr_vb2_ctx, "dvr", 174 + &dmxdev->mutex, 174 175 file->f_flags & O_NONBLOCK); 175 176 dvbdev->readers--; 176 177 } ··· 816 815 dmxdev->may_do_mmap = 0; 817 816 #endif 818 817 818 + /* 819 + * The mutex passed to dvb_vb2_init is unlocked when a buffer 820 + * is in a blocking wait. However, dmxdevfilter has two mutexes: 821 + * dmxdevfilter->mutex and dmxdev->mutex. So this will not work. 822 + * The solution would be to support unlocking two mutexes in vb2, 823 + * but since this problem has been here since the beginning and 824 + * nobody ever complained, we leave it as-is rather than adding 825 + * that second mutex pointer to vb2. 826 + * 827 + * In the unlikely event that someone complains about this, then 828 + * this comment will hopefully help. 829 + */ 819 830 dvb_ringbuffer_init(&dmxdevfilter->buffer, NULL, 8192); 820 831 dvb_vb2_init(&dmxdevfilter->vb2_ctx, "demux_filter", 821 - file->f_flags & O_NONBLOCK); 832 + &dmxdevfilter->mutex, file->f_flags & O_NONBLOCK); 822 833 dmxdevfilter->type = DMXDEV_TYPE_NONE; 823 834 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); 824 835 timer_setup(&dmxdevfilter->timer, dvb_dmxdev_filter_timeout, 0);
+11 -29
drivers/media/dvb-core/dvb_vb2.c
··· 103 103 spin_unlock_irqrestore(&ctx->slock, flags); 104 104 } 105 105 106 - static void _dmxdev_lock(struct vb2_queue *vq) 107 - { 108 - struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq); 109 - 110 - mutex_lock(&ctx->mutex); 111 - dprintk(3, "[%s]\n", ctx->name); 112 - } 113 - 114 - static void _dmxdev_unlock(struct vb2_queue *vq) 115 - { 116 - struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq); 117 - 118 - if (mutex_is_locked(&ctx->mutex)) 119 - mutex_unlock(&ctx->mutex); 120 - dprintk(3, "[%s]\n", ctx->name); 121 - } 122 - 123 106 static const struct vb2_ops dvb_vb2_qops = { 124 107 .queue_setup = _queue_setup, 125 108 .buf_prepare = _buffer_prepare, 126 109 .buf_queue = _buffer_queue, 127 110 .start_streaming = _start_streaming, 128 111 .stop_streaming = _stop_streaming, 129 - .wait_prepare = _dmxdev_unlock, 130 - .wait_finish = _dmxdev_lock, 131 112 }; 132 113 133 114 static void _fill_dmx_buffer(struct vb2_buffer *vb, void *pb) ··· 139 158 }; 140 159 141 160 /* 142 - * Videobuf operations 161 + * vb2 operations 143 162 */ 144 - int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int nonblocking) 163 + int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, 164 + struct mutex *mutex, int nonblocking) 145 165 { 146 166 struct vb2_queue *q = &ctx->vb_q; 147 167 int ret; ··· 157 175 q->ops = &dvb_vb2_qops; 158 176 q->mem_ops = &vb2_vmalloc_memops; 159 177 q->buf_ops = &dvb_vb2_buf_ops; 160 - ret = vb2_core_queue_init(q); 161 - if (ret) { 162 - ctx->state = DVB_VB2_STATE_NONE; 163 - dprintk(1, "[%s] errno=%d\n", ctx->name, ret); 164 - return ret; 165 - } 166 - 167 - mutex_init(&ctx->mutex); 178 + q->lock = mutex; 168 179 spin_lock_init(&ctx->slock); 169 180 INIT_LIST_HEAD(&ctx->dvb_q); 170 181 171 182 strscpy(ctx->name, name, DVB_VB2_NAME_MAX); 172 183 ctx->nonblocking = nonblocking; 173 184 ctx->state = DVB_VB2_STATE_INIT; 185 + 186 + ret = vb2_core_queue_init(q); 187 + if (ret) { 188 + ctx->state = DVB_VB2_STATE_NONE; 189 + dprintk(1, "[%s] errno=%d\n", ctx->name, ret); 190 + return ret; 191 + } 174 192 175 193 dprintk(3, "[%s]\n", ctx->name); 176 194
+5 -6
include/media/dvb_vb2.h
··· 72 72 /** 73 73 * struct dvb_vb2_ctx - control struct for VB2 handler 74 74 * @vb_q: pointer to &struct vb2_queue with videobuf2 queue. 75 - * @mutex: mutex to serialize vb2 operations. Used by 76 - * vb2 core %wait_prepare and %wait_finish operations. 77 75 * @slock: spin lock used to protect buffer filling at dvb_vb2.c. 78 76 * @dvb_q: List of buffers that are not filled yet. 79 77 * @buf: Pointer to the buffer that are currently being filled. ··· 94 96 */ 95 97 struct dvb_vb2_ctx { 96 98 struct vb2_queue vb_q; 97 - struct mutex mutex; 98 99 spinlock_t slock; 99 100 struct list_head dvb_q; 100 101 struct dvb_buffer *buf; ··· 111 114 }; 112 115 113 116 #ifndef CONFIG_DVB_MMAP 114 - static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx, 115 - const char *name, int non_blocking) 117 + static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, 118 + struct mutex *mutex, int non_blocking) 116 119 { 117 120 return 0; 118 121 }; ··· 135 138 * 136 139 * @ctx: control struct for VB2 handler 137 140 * @name: name for the VB2 handler 141 + * @mutex: pointer to the mutex that serializes vb2 ioctls 138 142 * @non_blocking: 139 143 * if not zero, it means that the device is at non-blocking mode 140 144 */ 141 - int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int non_blocking); 145 + int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, 146 + struct mutex *mutex, int non_blocking); 142 147 143 148 /** 144 149 * dvb_vb2_release - Releases the VB2 handler allocated resources and