From patchwork Wed Feb 14 10:36:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10218385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79489602CB for ; Wed, 14 Feb 2018 10:37:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D4DA289FD for ; Wed, 14 Feb 2018 10:37:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71DEE28D13; Wed, 14 Feb 2018 10:37:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24AA0289FD for ; Wed, 14 Feb 2018 10:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967196AbeBNKg6 (ORCPT ); Wed, 14 Feb 2018 05:36:58 -0500 Received: from bin-mail-out-06.binero.net ([195.74.38.229]:39109 "EHLO bin-vsp-out-01.atm.binero.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967159AbeBNKg5 (ORCPT ); Wed, 14 Feb 2018 05:36:57 -0500 X-Halon-ID: f2867e1f-1172-11e8-93cd-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id f2867e1f-1172-11e8-93cd-005056917a89; Wed, 14 Feb 2018 11:36:52 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Mauro Carvalho Chehab , Laurent Pinchart , Hans Verkuil , Sakari Ailus , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v2] videodev2.h: add helper to validate colorspace Date: Wed, 14 Feb 2018 11:36:43 +0100 Message-Id: <20180214103643.8245-1-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.16.1 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no way for drivers to validate a colorspace value, which could be provided by user-space by VIDIOC_S_FMT for example. Add a helper to validate that the colorspace value is part of enum v4l2_colorspace. Signed-off-by: Niklas Söderlund Acked-by: Sakari Ailus Reviewed-by: Laurent Pinchart Nacked-by: Hans Verkuil --- include/uapi/linux/videodev2.h | 4 ++++ 1 file changed, 4 insertions(+) Hi, I hope this is the correct header to add this helper to. I think it's since if it's in uapi not only can v4l2 drivers use it but tools like v4l-compliance gets access to it and can be updated to use this instead of the hard-coded check of just < 0xff as it was last time I checked. * Changes since v1 - Cast colorspace to u32 as suggested by Sakari and only check the upper boundary to address a potential issue brought up by Laurent if the data type tested is u32 which is not uncommon: enum.c:30:16: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits] return V4L2_COLORSPACE_IS_VALID(colorspace); diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 9827189651801e12..1f27c0f4187cbded 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -238,6 +238,10 @@ enum v4l2_colorspace { V4L2_COLORSPACE_DCI_P3 = 12, }; +/* Determine if a colorspace is defined in enum v4l2_colorspace */ +#define V4L2_COLORSPACE_IS_VALID(colorspace) \ + ((u32)(colorspace) <= V4L2_COLORSPACE_DCI_P3) + /* * Determine how COLORSPACE_DEFAULT should map to a proper colorspace. * This depends on whether this is a SDTV image (use SMPTE 170M), an