Skip to content

Commit

Permalink
media: v4l2: Make colorspace validity checks more future-proof
Browse files Browse the repository at this point in the history
The helper functions that test validity of colorspace-related fields
use the last value of the corresponding enums. This isn't very
future-proof, as there's a high chance someone adding a new value may
forget to update the helpers. Add new "LAST" entries to the enumerations
to improve this, and keep them private to the kernel.

Signed-off-by: Laurent Pinchart <[email protected]>
Acked-by: Sakari Ailus <[email protected]>
Reviewed-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
pinchartl authored and mchehab committed Jul 15, 2022
1 parent b0afed2 commit 718d215
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/media/v4l2-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,19 @@ static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf,
static inline bool v4l2_is_colorspace_valid(__u32 colorspace)
{
return colorspace > V4L2_COLORSPACE_DEFAULT &&
colorspace <= V4L2_COLORSPACE_DCI_P3;
colorspace < V4L2_COLORSPACE_LAST;
}

static inline bool v4l2_is_xfer_func_valid(__u32 xfer_func)
{
return xfer_func > V4L2_XFER_FUNC_DEFAULT &&
xfer_func <= V4L2_XFER_FUNC_SMPTE2084;
xfer_func < V4L2_XFER_FUNC_LAST;
}

static inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)
{
return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT &&
ycbcr_enc <= V4L2_YCBCR_ENC_SMPTE240M;
ycbcr_enc < V4L2_YCBCR_ENC_LAST;
}

static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc)
Expand Down
22 changes: 22 additions & 0 deletions include/uapi/linux/videodev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ enum v4l2_colorspace {

/* DCI-P3 colorspace, used by cinema projectors */
V4L2_COLORSPACE_DCI_P3 = 12,

#ifdef __KERNEL__
/*
* Largest supported colorspace value, assigned by the compiler, used
* by the framework to check for invalid values.
*/
V4L2_COLORSPACE_LAST,
#endif
};

/*
Expand Down Expand Up @@ -283,6 +291,13 @@ enum v4l2_xfer_func {
V4L2_XFER_FUNC_NONE = 5,
V4L2_XFER_FUNC_DCI_P3 = 6,
V4L2_XFER_FUNC_SMPTE2084 = 7,
#ifdef __KERNEL__
/*
* Largest supported transfer function value, assigned by the compiler,
* used by the framework to check for invalid values.
*/
V4L2_XFER_FUNC_LAST,
#endif
};

/*
Expand Down Expand Up @@ -343,6 +358,13 @@ enum v4l2_ycbcr_encoding {

/* SMPTE 240M -- Obsolete HDTV */
V4L2_YCBCR_ENC_SMPTE240M = 8,
#ifdef __KERNEL__
/*
* Largest supported encoding value, assigned by the compiler, used by
* the framework to check for invalid values.
*/
V4L2_YCBCR_ENC_LAST,
#endif
};

/*
Expand Down

0 comments on commit 718d215

Please sign in to comment.