Skip to content

Commit 47f910f

Browse files
kbinghammchehab
authored andcommitted
[media] v4l: subdev: tolerate null in media_entity_to_v4l2_subdev
Return NULL, if a null entity is parsed for it's v4l2_subdev Currently, the callers of media_entity_to_v4l2_subdev() need to make sure that the subdev is non-NULL, for example, when it is obtained from media_entity_remote_pad(). As this is a recurring pattern, add the check at the macro in order to avoid additional checks at the callers. Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 7eb2bcb commit 47f910f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎include/media/v4l2-subdev.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,15 @@ struct v4l2_subdev {
826826
struct v4l2_subdev_platform_data *pdata;
827827
};
828828

829-
#define media_entity_to_v4l2_subdev(ent) \
830-
container_of(ent, struct v4l2_subdev, entity)
829+
#define media_entity_to_v4l2_subdev(ent) \
830+
({ \
831+
typeof(ent) __me_sd_ent = (ent); \
832+
\
833+
__me_sd_ent ? \
834+
container_of(__me_sd_ent, struct v4l2_subdev, entity) : \
835+
NULL; \
836+
})
837+
831838
#define vdev_to_v4l2_subdev(vdev) \
832839
((struct v4l2_subdev *)video_get_drvdata(vdev))
833840

0 commit comments

Comments
 (0)