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

[media] vb2: Don't WARN when v4l2_buffer.bytesused is 0 for multiplanar buffers

Commit f61bf13b6a07 ("[media] vb2: add allow_zero_bytesused flag to the
vb2_queue struct") added a WARN_ONCE to catch usage of a deprecated API
using a zero value for v4l2_buffer.bytesused.

However, the condition is checked incorrectly, as the v4L2_buffer
bytesused field is supposed to be ignored for multiplanar buffers. This
results in spurious warnings when using the multiplanar API.

Fix it by checking v4l2_buffer.bytesused for uniplanar buffers and
v4l2_plane.bytesused for multiplanar buffers.

Fixes: f61bf13b6a07 ("[media] vb2: add allow_zero_bytesused flag to the vb2_queue struct")

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Cc: stable@vger.kernel.org # for v4.0
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
77a3c6fd 6f32a8c9

+23 -10
+23 -10
drivers/media/v4l2-core/videobuf2-core.c
··· 1242 1242 } 1243 1243 EXPORT_SYMBOL_GPL(vb2_discard_done); 1244 1244 1245 + static void vb2_warn_zero_bytesused(struct vb2_buffer *vb) 1246 + { 1247 + static bool __check_once __read_mostly; 1248 + 1249 + if (__check_once) 1250 + return; 1251 + 1252 + __check_once = true; 1253 + __WARN(); 1254 + 1255 + pr_warn_once("use of bytesused == 0 is deprecated and will be removed in the future,\n"); 1256 + if (vb->vb2_queue->allow_zero_bytesused) 1257 + pr_warn_once("use VIDIOC_DECODER_CMD(V4L2_DEC_CMD_STOP) instead.\n"); 1258 + else 1259 + pr_warn_once("use the actual size instead.\n"); 1260 + } 1261 + 1245 1262 /** 1246 1263 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a 1247 1264 * v4l2_buffer by the userspace. The caller has already verified that struct ··· 1268 1251 struct v4l2_plane *v4l2_planes) 1269 1252 { 1270 1253 unsigned int plane; 1271 - 1272 - if (V4L2_TYPE_IS_OUTPUT(b->type)) { 1273 - if (WARN_ON_ONCE(b->bytesused == 0)) { 1274 - pr_warn_once("use of bytesused == 0 is deprecated and will be removed in the future,\n"); 1275 - if (vb->vb2_queue->allow_zero_bytesused) 1276 - pr_warn_once("use VIDIOC_DECODER_CMD(V4L2_DEC_CMD_STOP) instead.\n"); 1277 - else 1278 - pr_warn_once("use the actual size instead.\n"); 1279 - } 1280 - } 1281 1254 1282 1255 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { 1283 1256 if (b->memory == V4L2_MEMORY_USERPTR) { ··· 1309 1302 struct v4l2_plane *pdst = &v4l2_planes[plane]; 1310 1303 struct v4l2_plane *psrc = &b->m.planes[plane]; 1311 1304 1305 + if (psrc->bytesused == 0) 1306 + vb2_warn_zero_bytesused(vb); 1307 + 1312 1308 if (vb->vb2_queue->allow_zero_bytesused) 1313 1309 pdst->bytesused = psrc->bytesused; 1314 1310 else ··· 1346 1336 } 1347 1337 1348 1338 if (V4L2_TYPE_IS_OUTPUT(b->type)) { 1339 + if (b->bytesused == 0) 1340 + vb2_warn_zero_bytesused(vb); 1341 + 1349 1342 if (vb->vb2_queue->allow_zero_bytesused) 1350 1343 v4l2_planes[0].bytesused = b->bytesused; 1351 1344 else