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

media: mc: Check pad flag validity

Check the validity of pad flags on entity init. Exactly one of the flags
must be set.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Sakari Ailus and committed by
Hans Verkuil
deb866f9 4c812e33

+14 -1
+14 -1
drivers/media/mc/mc-entity.c
··· 197 197 struct media_device *mdev = entity->graph_obj.mdev; 198 198 struct media_pad *iter; 199 199 unsigned int i = 0; 200 + int ret = 0; 200 201 201 202 if (num_pads >= MEDIA_ENTITY_MAX_PADS) 202 203 return -E2BIG; ··· 211 210 media_entity_for_each_pad(entity, iter) { 212 211 iter->entity = entity; 213 212 iter->index = i++; 213 + 214 + if (hweight32(iter->flags & (MEDIA_PAD_FL_SINK | 215 + MEDIA_PAD_FL_SOURCE)) != 1) { 216 + ret = -EINVAL; 217 + break; 218 + } 219 + 214 220 if (mdev) 215 221 media_gobj_create(mdev, MEDIA_GRAPH_PAD, 216 222 &iter->graph_obj); 217 223 } 218 224 225 + if (ret && mdev) { 226 + media_entity_for_each_pad(entity, iter) 227 + media_gobj_destroy(&iter->graph_obj); 228 + } 229 + 219 230 if (mdev) 220 231 mutex_unlock(&mdev->graph_mutex); 221 232 222 - return 0; 233 + return ret; 223 234 } 224 235 EXPORT_SYMBOL_GPL(media_entity_pads_init); 225 236