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

media: mc-entity.c: use WARN_ON, validate link pads

Use WARN_ON instead of BUG_ON.

Add two new WARN_ONs to verify that the source pad is really a source
and that the sink pad is really a sink.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: use ! instead of == NULL for source and sink]
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
a3fbc2e6 0c9d29eb

+8 -3
+8 -3
drivers/media/mc/mc-entity.c
··· 662 662 struct media_link *link; 663 663 struct media_link *backlink; 664 664 665 - BUG_ON(source == NULL || sink == NULL); 666 - BUG_ON(source_pad >= source->num_pads); 667 - BUG_ON(sink_pad >= sink->num_pads); 665 + if (WARN_ON(!source || !sink) || 666 + WARN_ON(source_pad >= source->num_pads) || 667 + WARN_ON(sink_pad >= sink->num_pads)) 668 + return -EINVAL; 669 + if (WARN_ON(!(source->pads[source_pad].flags & MEDIA_PAD_FL_SOURCE))) 670 + return -EINVAL; 671 + if (WARN_ON(!(sink->pads[sink_pad].flags & MEDIA_PAD_FL_SINK))) 672 + return -EINVAL; 668 673 669 674 link = media_add_link(&source->links); 670 675 if (link == NULL)