summaryrefslogtreecommitdiff
path: root/include/media
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2025-06-11 15:40:42 +0300
committerHans Verkuil <hverkuil@xs4all.nl>2025-07-10 11:32:23 +0200
commit7a8212f3bcfab753602599da644fb5bdeaf8ff2d (patch)
treeeef156a23dcccf2a8631c66d2e1cf1eecb6bbe63 /include/media
parent09ef95213880e32dc0e9612bae023e61c69b392e (diff)
media: v4l: Make media_entity_to_video_device() NULL-safe
Make media_entity_to_video_device(NULL) return NULL, instead of an invalid pointer value. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Diffstat (limited to 'include/media')
-rw-r--r--include/media/v4l2-dev.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 1b6222fab24e..a69801274800 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -313,10 +313,16 @@ struct video_device {
* media_entity_to_video_device - Returns a &struct video_device from
* the &struct media_entity embedded on it.
*
- * @__entity: pointer to &struct media_entity
- */
-#define media_entity_to_video_device(__entity) \
- container_of(__entity, struct video_device, entity)
+ * @__entity: pointer to &struct media_entity, may be NULL
+ */
+#define media_entity_to_video_device(__entity) \
+({ \
+ typeof(__entity) __me_vdev_ent = __entity; \
+ \
+ __me_vdev_ent ? \
+ container_of(__me_vdev_ent, struct video_device, entity) : \
+ NULL; \
+})
/**
* to_video_device - Returns a &struct video_device from the