Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp176711pxf; Wed, 24 Mar 2021 02:16:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzfV7+63eSQhscCv2dGBW8FYbenetmzFjCBe4I5Y41UzaTkkUnK1rJcBysxgTQmgPXbPiQ X-Received: by 2002:a17:906:bc81:: with SMTP id lv1mr2559443ejb.135.1616577397910; Wed, 24 Mar 2021 02:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616577397; cv=none; d=google.com; s=arc-20160816; b=q+IbMl3nx2hkc4J6aHseUWpwHs1WNxJEJDctW1XYYea+KMg8KOi0Gt0U/qmtEM8aEK gC/vvdimd923cJnsPg+Vot6cz10VxrtMJfagLwNKE0TskypniiAVRPaIPdX44ZYoN14/ lpSbXLixJ9KW85rBiUtvYmuW7ku3RdxaiMCbIo5JisSRKxJQTtiwWVaVZKd97JH30mn8 gjVc8ibNPUq/FS2kOy1g6RkHgQg2BH6phuF8knTUQcSQ5V6GLDzFUUF4ru88VhIw/yh3 5r0PzNBXpGPb2aU2RhIaG/5lA7L9Hi8GcT3q7fBllAXGFKimsjLMrqcK6d34nm7L6hyu z5Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Gko5DwdDrrjyuudztCK85u5fA9SOsiUHVh5WfDpFt8E=; b=ycKqwwdLrXv8ssMpj0FaXXMEYIZb03Ev3Lxm+h4L3vkxpMRY7P2z1KFk0dtsBT2JDL OUxjM2YAz2xKrvL92/uFQuKqdQAvtdgCmJ4hlKG7Ddevgji3eYJyuQ2sBjRdZyE2Hwjq Ha0hlghdrWzXi5c8k7UX66ApZq1TyQj1qs8hmVnOMtk8ABwkR3ygIBND6MYZZ1Zk7o4W 2JDjFpEU/4f2exoSCFEWoueATGAd7i/L4Hf2Ao+6I35a7idMauWLdwRNgnLUyHcTiIDI zoDGXn0TxXEpNN0kTyZFTCqeD/+e3ezNNN8SKRWLtecBw4rcAk5PBMRJxwmYRAedh726 C2yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QlJxkIRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ju25si1320225ejc.668.2021.03.24.02.16.14; Wed, 24 Mar 2021 02:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QlJxkIRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbhCXCBn (ORCPT + 99 others); Tue, 23 Mar 2021 22:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbhCXCBS (ORCPT ); Tue, 23 Mar 2021 22:01:18 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E083C061763 for ; Tue, 23 Mar 2021 19:01:18 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id x26so16201586pfn.0 for ; Tue, 23 Mar 2021 19:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Gko5DwdDrrjyuudztCK85u5fA9SOsiUHVh5WfDpFt8E=; b=QlJxkIRDjzXTY962t2mtJA7UVqpJYbvcjCSKEMSo/Q5mM60eQoKJHEXyROJMl7N+ES kEXL+d876OKQFmHIFECPqG2PQLhuC5OYGzBJvk5FNiIa6/eJBbCg1szxejz4xHCjoKaJ BI1VsVWLDZ/5tGIYFIMpjkewa0LZPtGwL3ZTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Gko5DwdDrrjyuudztCK85u5fA9SOsiUHVh5WfDpFt8E=; b=ZclJXwiObdZk+FRraaVBY99DvT+Xw/6X+RowtnjMRfiqoV1eOVCw++qxcSGKGdlIVs D4oBrJ84xtYkfTVJ9u/rdZF8bF9UbF/hZS86zyS/RZEf+E+cx4fQlKN/JRHDrwrk9cAm LAPb8bJcNuPfWMR5re/pxdI33sZEcmkSLAT/8CcOtZKa3mDDOx3gg3v8xZKmohVSAeaE GzBRW/8FcfCynN+AjsiBxCDKwtcDV+vwmvqHIAx52Lqzo1i2iJwRdXydsPHWhVwNM8Uj hW5k4oD6ENcZWsDGnIv+WVGXNT8xE8zGa1uI0oMZHi5o4t0195f+01zLiQP5jkL30sq7 cMVA== X-Gm-Message-State: AOAM532xlpPR06YqXGnVf6QVJ+bpRyh9fM9mf9QhYSIH3ZzGr/i1Gs8E 0pD/muSEPj0IdBi/7uWAqBzJgA== X-Received: by 2002:a63:f546:: with SMTP id e6mr954277pgk.299.1616551277775; Tue, 23 Mar 2021 19:01:17 -0700 (PDT) Received: from google.com ([2409:10:2e40:5100:bcf2:e05a:a993:9494]) by smtp.gmail.com with ESMTPSA id d2sm389013pjx.42.2021.03.23.19.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 19:01:17 -0700 (PDT) Date: Wed, 24 Mar 2021 11:01:12 +0900 From: Sergey Senozhatsky To: Ricardo Ribalda Cc: Sergey Senozhatsky , Laurent Pinchart , Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List Subject: Re: [PATCHv3 5/6] media: uvcvideo: add UVC 1.5 ROI control Message-ID: References: <20210319055342.127308-1-senozhatsky@chromium.org> <20210319055342.127308-6-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (21/03/23 17:16), Ricardo Ribalda wrote: [..] > > +static bool validate_roi_bounds(struct uvc_streaming *stream, > > + struct v4l2_selection *sel) > > +{ > > + if (sel->r.left > USHRT_MAX || > > + sel->r.top > USHRT_MAX || > > + (sel->r.width + sel->r.left) > USHRT_MAX || > > + (sel->r.height + sel->r.top) > USHRT_MAX || > > + !sel->r.width || !sel->r.height) > > + return false; > > + > > + if (sel->flags > V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY) > > + return false; > > Is it not allowed V4L2_SEL_FLAG_ROI_AUTO_IRIS | > V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY ? Good question. I don't know. Depends on what HIGHER_QUALITY can stand for (UVC doesn't specify). But overall it seems like features there are mutually exclusive. E.g. AUTO_FACE_DETECT and AUTO_DETECT_AND_TRACK. I think it'll be better to replace this with if (sel->flags > USHRT_MAX) return false; so that we don't let overflow happen and accidentally enable/disable some of the features. > > + > > + return true; > > +} > > + > > +static int uvc_ioctl_s_roi(struct file *file, void *fh, > > + struct v4l2_selection *sel) > > +{ > > + struct uvc_fh *handle = fh; > > + struct uvc_streaming *stream = handle->stream; > > + struct uvc_roi_rect *roi; > > + int ret; > > + > > + if (!validate_roi_bounds(stream, sel)) > > + return -E2BIG; > > Not sure if this is the correct approach or if we should convert the > value to the closest valid... Well, at this point we know that ROI rectangle dimensions are out of sane value range. I'd rather tell user-space about integer overflow. Looking for the closest ROI rectangle that suffice can be rather tricky. It may sounds like we can just use BOUNDARIES_MAX, but this is what Firmware D returns for GET_MAX ioctl(V4L2_SEL_TGT_ROI_BOUNDS_MAX) 0, 0, 65535, 65535 -ss