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

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>

authored by

Sakari Ailus and committed by
Hans Verkuil
7a8212f3 09ef9521

+9 -3
+9 -3
include/media/v4l2-dev.h
··· 313 313 * media_entity_to_video_device - Returns a &struct video_device from 314 314 * the &struct media_entity embedded on it. 315 315 * 316 - * @__entity: pointer to &struct media_entity 316 + * @__entity: pointer to &struct media_entity, may be NULL 317 317 */ 318 - #define media_entity_to_video_device(__entity) \ 319 - container_of(__entity, struct video_device, entity) 318 + #define media_entity_to_video_device(__entity) \ 319 + ({ \ 320 + typeof(__entity) __me_vdev_ent = __entity; \ 321 + \ 322 + __me_vdev_ent ? \ 323 + container_of(__me_vdev_ent, struct video_device, entity) : \ 324 + NULL; \ 325 + }) 320 326 321 327 /** 322 328 * to_video_device - Returns a &struct video_device from the