Add a sanity check for the number of the media request states equals the number of status strings for debug purposes. This necessitates a new entry in the request state enumeration, called NR_OF_MEDIA_REQUEST_STATE. Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> --- drivers/media/media-request.c | 2 ++ include/media/media-request.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c index 03e74d72241a0..ef4a436f220a3 100644 --- a/drivers/media/media-request.c +++ b/drivers/media/media-request.c @@ -28,6 +28,8 @@ static const char * const request_state[] = { static const char * media_request_state_str(enum media_request_state state) { + BUILD_BUG_ON(NR_OF_MEDIA_REQUEST_STATE != ARRAY_SIZE(request_state)); + if (WARN_ON(state >= ARRAY_SIZE(request_state))) return "invalid"; return request_state[state]; diff --git a/include/media/media-request.h b/include/media/media-request.h index 42cc6e7f6e532..7a2df18a069ce 100644 --- a/include/media/media-request.h +++ b/include/media/media-request.h @@ -31,6 +31,8 @@ * @MEDIA_REQUEST_STATE_UPDATING: The request is being updated, i.e. * request objects are being added, * modified or removed + * @NR_OF_MEDIA_REQUEST_STATE: The number of media request states, used + * internally for sanity check purposes */ enum media_request_state { MEDIA_REQUEST_STATE_IDLE, @@ -39,6 +41,7 @@ enum media_request_state { MEDIA_REQUEST_STATE_COMPLETE, MEDIA_REQUEST_STATE_CLEANING, MEDIA_REQUEST_STATE_UPDATING, + NR_OF_MEDIA_REQUEST_STATE, }; struct media_request_object; -- 2.11.0