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

media: amphion: Use vb2_get_buffer() instead of directly access to buffers array

Use vb2_get_buffer() instead of direct access to the vb2_queue bufs array.
This allows us to change the type of the bufs in the future.
After each call to vb2_get_buffer() we need to be sure that we get
a valid pointer so check the return value of all of them.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
CC: Ming Qian <ming.qian@nxp.com>
CC: Zhou Peng <eagle.zhou@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Benjamin Gaignard and committed by
Mauro Carvalho Chehab
e03bcb28 da8fc26b

+18 -4
+18 -4
drivers/media/platform/amphion/vpu_dbg.c
··· 140 140 141 141 vq = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); 142 142 for (i = 0; i < vq->num_buffers; i++) { 143 - struct vb2_buffer *vb = vq->bufs[i]; 144 - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 143 + struct vb2_buffer *vb; 144 + struct vb2_v4l2_buffer *vbuf; 145 + 146 + vb = vb2_get_buffer(vq, i); 147 + if (!vb) 148 + continue; 145 149 146 150 if (vb->state == VB2_BUF_STATE_DEQUEUED) 147 151 continue; 152 + 153 + vbuf = to_vb2_v4l2_buffer(vb); 154 + 148 155 num = scnprintf(str, sizeof(str), 149 156 "output [%2d] state = %10s, %8s\n", 150 157 i, vb2_stat_name[vb->state], ··· 162 155 163 156 vq = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); 164 157 for (i = 0; i < vq->num_buffers; i++) { 165 - struct vb2_buffer *vb = vq->bufs[i]; 166 - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 158 + struct vb2_buffer *vb; 159 + struct vb2_v4l2_buffer *vbuf; 160 + 161 + vb = vb2_get_buffer(vq, i); 162 + if (!vb) 163 + continue; 167 164 168 165 if (vb->state == VB2_BUF_STATE_DEQUEUED) 169 166 continue; 167 + 168 + vbuf = to_vb2_v4l2_buffer(vb); 169 + 170 170 num = scnprintf(str, sizeof(str), 171 171 "capture[%2d] state = %10s, %8s\n", 172 172 i, vb2_stat_name[vb->state],