From patchwork Fri Mar 26 09:58:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B00DC433E1 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D101261A51 for ; Fri, 26 Mar 2021 09:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbhCZJ6y (ORCPT ); Fri, 26 Mar 2021 05:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbhCZJ6q (ORCPT ); Fri, 26 Mar 2021 05:58:46 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 315EFC0613B3 for ; Fri, 26 Mar 2021 02:58:46 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id u21so7437935ejo.13 for ; Fri, 26 Mar 2021 02:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l9DqWBZVACDhYWKU2Yn/vht3Qo/OTKVi3IGrxQaKbjA=; b=R/aKZgXTHS/4xIEZdHeaHUgrSlfv2Dd9ROd6AzvFZEIHu0lXhaNx4QQnTd6BbMCQ9e 4KPC8iUUbLmXVJwh3563sZ4MqMKWdUxrcWAZpOQUNb7gK/0hnXoOOi05fGxEm/PBg9Cu QnPNZFh5aYiUY5q3glMpcnplZLVw5HNpyXwKw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l9DqWBZVACDhYWKU2Yn/vht3Qo/OTKVi3IGrxQaKbjA=; b=sWqIFOZ7KM1KoVqJ9u7+Onwh+WvuCcMdNYvkMf9JPiIBWUMPigltMUajdZWt6IaFny GyuIRbr5WgWMDBq9unAydcljflazqXyPOzyLYEhqoJkslGnR7yaxNyjL6IXbxPw7tSnb P2ih1zIkqTk8xe/Nt/hcAR3yAC0fIskSPoqR/FtnjORSqx6u7mnD/RdXNOpH67xSuDVr bNSGFcBdWurglW2LAjYfEMs9pu2qEStXd7AmBF+Bkgxv9p0nk32BdWcZ0gMqF8whFeDK eP2zLPbOYFm9kk/uTd2w+tjjlYgE2OQQrTQeLOwOTGUH81XV5aYWZkjnzglAkhgrJns+ 2tDg== X-Gm-Message-State: AOAM533u5IGB04FC4Nb4NHZE+U227tKfUNF9EvD1tMv2YbFYu4IpFbm8 CzBRrcQ0W9UtOWu0/sgf5r0acg== X-Google-Smtp-Source: ABdhPJzd+9FAWPd+RVI3IWGgXRQzmTyLDFI3R++xJeBQ34graIsOkacOfMN/0rjEW67Lz664ewsOaw== X-Received: by 2002:a17:906:86c6:: with SMTP id j6mr13747183ejy.197.1616752724800; Fri, 26 Mar 2021 02:58:44 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:44 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda , stable@vger.kernel.org Subject: [PATCH v9 01/22] media: v4l2-ioctl: Fix check_ext_ctrls Date: Fri, 26 Mar 2021 10:58:19 +0100 Message-Id: <20210326095840.364424-2-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Drivers that do not use the ctrl-framework use this function instead. Fix the following issues: - Do not check for multiple classes when getting the DEF_VAL. - Return -EINVAL for request_api calls - Default value cannot be changed, return EINVAL as soon as possible. - Return the right error_idx [If an error is found when validating the list of controls passed with VIDIOC_G_EXT_CTRLS, then error_idx shall be set to ctrls->count to indicate to userspace that no actual hardware was touched. It would have been much nicer of course if error_idx could point to the control index that failed the validation, but sadly that's not how the API was designed.] Fixes v4l2-compliance: Control ioctls (Input 0): warn: v4l2-test-controls.cpp(834): error_idx should be equal to count warn: v4l2-test-controls.cpp(855): error_idx should be equal to count fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL Buffer ioctls (Input 0): fail: v4l2-test-buffers.cpp(1994): ret != EINVAL && ret != EBADR && ret != ENOTTY test Requests: FAIL Cc: stable@vger.kernel.org Fixes: 6fa6f831f095 ("media: v4l2-ctrls: add core request support") Suggested-by: Hans Verkuil Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-ioctl.c | 60 ++++++++++++++++++---------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 31d1342e61e8..7b5ebdd329e8 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -908,7 +908,7 @@ static void v4l_print_default(const void *arg, bool write_only) pr_cont("driver-specific ioctl\n"); } -static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) +static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl) { __u32 i; @@ -917,23 +917,41 @@ static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) for (i = 0; i < c->count; i++) c->controls[i].reserved2[0] = 0; - /* V4L2_CID_PRIVATE_BASE cannot be used as control class - when using extended controls. - Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL - is it allowed for backwards compatibility. - */ - if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE) - return 0; - if (!c->which) - return 1; + switch (c->which) { + case V4L2_CID_PRIVATE_BASE: + /* + * V4L2_CID_PRIVATE_BASE cannot be used as control class + * when using extended controls. + * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL + * is it allowed for backwards compatibility. + */ + if (ioctl == VIDIOC_G_CTRL || ioctl == VIDIOC_S_CTRL) + return false; + break; + case V4L2_CTRL_WHICH_DEF_VAL: + /* Default value cannot be changed */ + if (ioctl == VIDIOC_S_EXT_CTRLS || + ioctl == VIDIOC_TRY_EXT_CTRLS) { + c->error_idx = c->count; + return false; + } + return true; + case V4L2_CTRL_WHICH_CUR_VAL: + return true; + case V4L2_CTRL_WHICH_REQUEST_VAL: + c->error_idx = c->count; + return false; + } + /* Check that all controls are from the same control class. */ for (i = 0; i < c->count; i++) { if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) { - c->error_idx = i; - return 0; + c->error_idx = ioctl == VIDIOC_TRY_EXT_CTRLS ? i : + c->count; + return false; } } - return 1; + return true; } static int check_fmt(struct file *file, enum v4l2_buf_type type) @@ -2229,7 +2247,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, ctrls.controls = &ctrl; ctrl.id = p->id; ctrl.value = p->value; - if (check_ext_ctrls(&ctrls, 1)) { + if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) { int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); if (ret == 0) @@ -2263,7 +2281,7 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, ctrls.controls = &ctrl; ctrl.id = p->id; ctrl.value = p->value; - if (check_ext_ctrls(&ctrls, 1)) + if (check_ext_ctrls(&ctrls, VIDIOC_S_CTRL)) return ops->vidioc_s_ext_ctrls(file, fh, &ctrls); return -EINVAL; } @@ -2285,8 +2303,8 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, vfd, vfd->v4l2_dev->mdev, p); if (ops->vidioc_g_ext_ctrls == NULL) return -ENOTTY; - return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) : - -EINVAL; + return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ? + ops->vidioc_g_ext_ctrls(file, fh, p) : -EINVAL; } static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, @@ -2306,8 +2324,8 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, vfd, vfd->v4l2_dev->mdev, p); if (ops->vidioc_s_ext_ctrls == NULL) return -ENOTTY; - return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) : - -EINVAL; + return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ? + ops->vidioc_s_ext_ctrls(file, fh, p) : -EINVAL; } static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, @@ -2327,8 +2345,8 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, vfd, vfd->v4l2_dev->mdev, p); if (ops->vidioc_try_ext_ctrls == NULL) return -ENOTTY; - return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) : - -EINVAL; + return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ? + ops->vidioc_try_ext_ctrls(file, fh, p) : -EINVAL; } /* From patchwork Fri Mar 26 09:58:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410410 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6B4FC433C1 for ; Fri, 26 Mar 2021 09:59:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 601B561A42 for ; Fri, 26 Mar 2021 09:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbhCZJ6y (ORCPT ); Fri, 26 Mar 2021 05:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbhCZJ6r (ORCPT ); Fri, 26 Mar 2021 05:58:47 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1322C0613B1 for ; Fri, 26 Mar 2021 02:58:46 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id kt15so7467328ejb.12 for ; Fri, 26 Mar 2021 02:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+8ftwX2VrGSkfTVVNvT7pPS6qh2Bu/od5mahErd+MM4=; b=kzTUDDX8a25F/i/c+v4G5fzlR44A/rmT2kECv9pBhJHo+lau9PUuofsQ+YlK4ppSnD O7kf1K88iSJYxmLPQACECAOQWQRGy5DKOZpShKgscx+Q1JM1Tn26K6mGR83xM9azjk7x +M8Ua7lcupbG0pFsxDfaby/8GVBJJmVkJHd3Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+8ftwX2VrGSkfTVVNvT7pPS6qh2Bu/od5mahErd+MM4=; b=RifQh1rHRzRYHoGycSZQsCWNY5evLT4U8ZBxGAMqrQdJzumsdaoqrZZVo61hCAgEZQ iH8DYn7f2vCPJtbm4LHdxZ7kqkxH06Srxy0Yh2HFea0tVgq46Vak79CxNPfoO7kYeGIj x9wZAXWWKBjpgJUR3Gm9S37Y3OlHIvcVR3v9BgnXOLfdgVMtC6c+iBWVfS4lriz9dYK1 4RKYN12EpQPdkZNn4gUDqMo7XtQ9Ip8heWwIVHiSi2CXFc4MoZQwpj/RHZJKAr4VL7Mo F2I0ESjt063Q4tMqRSjqbY8DdLgt+CvjzWO+ZnR2kPaAsMrjrTLG1d11vZn3YXPrf8Bk RLow== X-Gm-Message-State: AOAM533CeIidvquXnutrH+47Ap9uuG/jKFMvx69PEiIgYxJzhLmkzJol YE1SDB1nrFSu0vP3tv6q/4LZJA== X-Google-Smtp-Source: ABdhPJxGoKWw7ZjVZ6bZ6RrZ67SACtFy4QrZjH8SN9zyyybEjjVoNoGBNm2hmhTO8wgoPoLa61gvaw== X-Received: by 2002:a17:907:7699:: with SMTP id jv25mr13834135ejc.363.1616752725723; Fri, 26 Mar 2021 02:58:45 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:45 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda , Mike Isely Subject: [PATCH v9 02/22] media: pvrusb2: Do not check for V4L2_CTRL_WHICH_DEF_VAL Date: Fri, 26 Mar 2021 10:58:20 +0100 Message-Id: <20210326095840.364424-3-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The framework already checks for us if V4L2_CTRL_WHICH_DEF_VAL is written. Cc: Mike Isely Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c index 9657c1883311..c04ab7258d64 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c @@ -640,10 +640,6 @@ static int pvr2_s_ext_ctrls(struct file *file, void *priv, unsigned int idx; int ret; - /* Default value cannot be changed */ - if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL) - return -EINVAL; - ret = 0; for (idx = 0; idx < ctls->count; idx++) { ctrl = ctls->controls + idx; From patchwork Fri Mar 26 09:58:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31432C433E4 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ED0361A54 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbhCZJ6z (ORCPT ); Fri, 26 Mar 2021 05:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbhCZJ6s (ORCPT ); Fri, 26 Mar 2021 05:58:48 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37CFC0613AA for ; Fri, 26 Mar 2021 02:58:47 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id ce10so7500193ejb.6 for ; Fri, 26 Mar 2021 02:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wCOKiDe1D/0+aQGCLvfjrwWo1WTUNQYZ1NkzC83Pgoo=; b=Pzn0kWnChdk/UirORjmsRwsR+oJ22H1ym6wCOBwOu++2zuLyan8hiB3BM38xLIcXD7 kfJ3z0oxTVWSkbPp8wpEKYGBHbOn50EBn2CCzL60WxfweTpqONv4ClSJjcMrJExY26YZ eU8v4Z7E2TJDr0Q+YNdTSP1u781h+rFTqnCiY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wCOKiDe1D/0+aQGCLvfjrwWo1WTUNQYZ1NkzC83Pgoo=; b=Xlh5eTa574oQLCQRyTBvvAKBnbZapwQZaCk8YxUtGJ35UYP4YqJlzZ35AH772YON3U icdoWToJkXTm0x7orEx2tO5k2c4Bzllr8lEZ6We4itw2rJgnmJwbnKnZVStzNv84tMWD 48YMkXBkqSdQUMclWj2lwrfA4cvxPOSU+VpjUxFx/rCZDFOeMSTqLL2UA9EGFXelXGMt wEVAC8bzxoV4CJYUCyFAyWmiNF3iZ/5p2449euUluKbYbyaIa+RdVcgrU5CwoxJedEpL cWIWmAAFObNRljj69wUdaB/sJqfNh6nZ/f8PXYC1MX5CpbBeU/4okVCiXSybrx8uEFR9 g/xg== X-Gm-Message-State: AOAM533JfeKMpRBi6+zkJwR7ObMXqL6afNwkgf+px2c6r2jZvCXSCyHn b99SCHU9EqWvXdt06ZDsvHbtIM5CRrWNaTI1 X-Google-Smtp-Source: ABdhPJwkeqYZ51pGzh40eJyou6ovVfgFAaDwHlqI8RlKlXwyUrysWMigh+IRvGzHmwqbswfjgmSRag== X-Received: by 2002:a17:907:7664:: with SMTP id kk4mr14978013ejc.352.1616752726790; Fri, 26 Mar 2021 02:58:46 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:46 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 03/22] media: uvcvideo: Do not check for V4L2_CTRL_WHICH_DEF_VAL Date: Fri, 26 Mar 2021 10:58:21 +0100 Message-Id: <20210326095840.364424-4-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The framework already checks for us if V4L2_CTRL_WHICH_DEF_VAL is written. Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_v4l2.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 252136cc885c..47b0e3224205 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1089,10 +1089,6 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, unsigned int i; int ret; - /* Default value cannot be changed */ - if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) - return -EINVAL; - ret = uvc_ctrl_begin(chain); if (ret < 0) return ret; From patchwork Fri Mar 26 09:58:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8446BC433E9 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5732261A42 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbhCZJ6z (ORCPT ); Fri, 26 Mar 2021 05:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbhCZJ6t (ORCPT ); Fri, 26 Mar 2021 05:58:49 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF73C0613B1 for ; Fri, 26 Mar 2021 02:58:48 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id kt15so7467449ejb.12 for ; Fri, 26 Mar 2021 02:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kC71O7mgFntuzJoDSI8vq4wass7q97TNbxvCpydYjHA=; b=lnIbbFaFA1NeWxJwk96P8UeCjY14eS1euXdCbkNiVhfhjgQcwfWujSlmA4xPfft9YZ Gl0eOxR+d0lRqngQMghci8XytRROb3DZ9NU5AUzdMq7c15xefM502DxPuJ6fqrYkTD0Z 11TCLaFxNFjxWwysuGOQ2+EPgMPAK5iryvXGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kC71O7mgFntuzJoDSI8vq4wass7q97TNbxvCpydYjHA=; b=QUoxOZhTWAcjUDFKOjJE7LKZiZGX6deyI9B+Yc8PGZY8mmytx7HHa9t9wIfB10yDAV OcfpxI4lqMJPAOFVgIQCiSOqB1p+4jflVfuf8gKbzmnoPkPCTkT02RqfhC6ZnGNwmIb7 zN4BxFftQj0iB86EQcl5ZrrOKk1Ocglipxnn4JYRb1PyFPbMDAwWqY6yu1EccU2nlDx0 CGFYNcLiSBRqOfhjtKwQZ6DeWfFUqmi9rBsRa/l0AfA2NfWK2SskM5xa3ItZAM/tfB+2 3q6M52wKLu8wjbzd63USOJmo1aRqETwHn6TDMTPhAp5Om9EdVKVOy5GasM/ZZAGQYR0I TgKw== X-Gm-Message-State: AOAM530f+WzZ5cjFJO7shlojW1BcS4tek8nZLm09ifQIVXjwB02XqZQy irCHNASNvkja+25CJ0G0t/di+A== X-Google-Smtp-Source: ABdhPJycuvhnOM0hm++0vYD9gRyRidcx/FE2H1tfgUcXuuaXDHrFSGrOfpQegT1wmxAFxSZoau98Mg== X-Received: by 2002:a17:907:1614:: with SMTP id hb20mr14324510ejc.77.1616752727627; Fri, 26 Mar 2021 02:58:47 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:47 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 04/22] media: v4l2-ioctl: S_CTRL output the right value Date: Fri, 26 Mar 2021 10:58:22 +0100 Message-Id: <20210326095840.364424-5-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If the driver does not implement s_ctrl, but it does implement s_ext_ctrls, we convert the call. When that happens we have also to convert back the response from s_ext_ctrls. Fixes v4l2_compliance: Control ioctls (Input 0): fail: v4l2-test-controls.cpp(411): returned control value out of range fail: v4l2-test-controls.cpp(507): invalid control 00980900 test VIDIOC_G/S_CTRL: FAIL Fixes: 35ea11ff8471 ("V4L/DVB (8430): videodev: move some functions from v4l2-dev.h to v4l2-common.h or v4l2-ioctl.h") Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-ioctl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 7b5ebdd329e8..b8f73a48872b 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -2266,6 +2266,7 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; struct v4l2_ext_controls ctrls; struct v4l2_ext_control ctrl; + int ret; if (vfh && vfh->ctrl_handler) return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p); @@ -2281,9 +2282,11 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, ctrls.controls = &ctrl; ctrl.id = p->id; ctrl.value = p->value; - if (check_ext_ctrls(&ctrls, VIDIOC_S_CTRL)) - return ops->vidioc_s_ext_ctrls(file, fh, &ctrls); - return -EINVAL; + if (!check_ext_ctrls(&ctrls, VIDIOC_S_CTRL)) + return -EINVAL; + ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls); + p->value = ctrl.value; + return ret; } static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, From patchwork Fri Mar 26 09:58:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 824ADC433E5 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A85261A65 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbhCZJ65 (ORCPT ); Fri, 26 Mar 2021 05:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhCZJ6t (ORCPT ); Fri, 26 Mar 2021 05:58:49 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F83DC0613AA for ; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id u5so7499151ejn.8 for ; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Taa4kjTOMpLW/ZkeAqjF/jCqg+TUWX381LsGBXizrEs=; b=ZBlJ+2JRN/3p5bvEKSqG+fEdhMH5cWDqLs3/WLvlSk8xbuUX3mGsumV4OZH38Qw9EY 9YkJBJFiG4aYWrGKs4YDjqVhbIGg2aM+wOfnVW9K3+BfV8DL1GMiG8L3bsBlznxeXFOm zhgXlkmYXvOTYJMa5U3Lge8bZGZMnPVAuO/O8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Taa4kjTOMpLW/ZkeAqjF/jCqg+TUWX381LsGBXizrEs=; b=br2GHH+4hycxZ9A6yYFAMF+Y/aaWvE2DVbo2R9OUMXpIs5zORmN/iranBbSnAeTlIf wKa8G57aW1FUIHjm0mRE0PrFlwNMM1J89WNfN5JNi/cSsfe5JzVLjXcnYxEZ00hhPga2 +l7pO0hzKrOl6yR2reN1kY4cLkqo0683phFfO6nhz03OlFpYaGV9xWw9Wz+uHD9Jqaha FA+ZbLtIs5vq3aTpRn1kdFlHuKaRRRzqOmBj/VEoydWG93BSdRbJlAVTHe3gLxrDEFtv IQ5PJE5Lbfm4ckuezNt95rvhHX+QcfMdfRtn+7bSghar5xg2RxOn/iWl1qtI0wzS6ZAu QIAw== X-Gm-Message-State: AOAM531+6M7i5+jfYqnr01y4Fh+gDpKW5/9GUPJonqdxh2+1zWLbd18q r9ZNt0tuDpUC1OD3SrSJKJkLYA== X-Google-Smtp-Source: ABdhPJzXjmxn7vIeVWzcGgMBl8vzCaKq+gckf9a3EZKc1HMB3ShFF36o8c13RMnd27weOdcdDvmpeg== X-Received: by 2002:a17:906:7c4:: with SMTP id m4mr14454353ejc.63.1616752728189; Fri, 26 Mar 2021 02:58:48 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:47 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 05/22] media: uvcvideo: Remove s_ctrl and g_ctrl Date: Fri, 26 Mar 2021 10:58:23 +0100 Message-Id: <20210326095840.364424-6-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If we do not implement these callbacks the framework will call the ext_ctrl callbaks instead, which are a superset of this functions. Suggested-by: Hans Verkuil Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_v4l2.c | 56 -------------------------------- 1 file changed, 56 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 47b0e3224205..ac98869d5a05 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -983,60 +983,6 @@ static int uvc_ioctl_query_ext_ctrl(struct file *file, void *fh, return 0; } -static int uvc_ioctl_g_ctrl(struct file *file, void *fh, - struct v4l2_control *ctrl) -{ - struct uvc_fh *handle = fh; - struct uvc_video_chain *chain = handle->chain; - struct v4l2_ext_control xctrl; - int ret; - - memset(&xctrl, 0, sizeof(xctrl)); - xctrl.id = ctrl->id; - - ret = uvc_ctrl_begin(chain); - if (ret < 0) - return ret; - - ret = uvc_ctrl_get(chain, &xctrl); - uvc_ctrl_rollback(handle); - if (ret < 0) - return ret; - - ctrl->value = xctrl.value; - return 0; -} - -static int uvc_ioctl_s_ctrl(struct file *file, void *fh, - struct v4l2_control *ctrl) -{ - struct uvc_fh *handle = fh; - struct uvc_video_chain *chain = handle->chain; - struct v4l2_ext_control xctrl; - int ret; - - memset(&xctrl, 0, sizeof(xctrl)); - xctrl.id = ctrl->id; - xctrl.value = ctrl->value; - - ret = uvc_ctrl_begin(chain); - if (ret < 0) - return ret; - - ret = uvc_ctrl_set(handle, &xctrl); - if (ret < 0) { - uvc_ctrl_rollback(handle); - return ret; - } - - ret = uvc_ctrl_commit(handle, &xctrl, 1); - if (ret < 0) - return ret; - - ctrl->value = xctrl.value; - return 0; -} - static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *ctrls) { @@ -1522,8 +1468,6 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_s_input = uvc_ioctl_s_input, .vidioc_queryctrl = uvc_ioctl_queryctrl, .vidioc_query_ext_ctrl = uvc_ioctl_query_ext_ctrl, - .vidioc_g_ctrl = uvc_ioctl_g_ctrl, - .vidioc_s_ctrl = uvc_ioctl_s_ctrl, .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, From patchwork Fri Mar 26 09:58:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52789C433E3 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2855161A63 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230079AbhCZJ65 (ORCPT ); Fri, 26 Mar 2021 05:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbhCZJ6u (ORCPT ); Fri, 26 Mar 2021 05:58:50 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8975C0613B1 for ; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id jy13so7518496ejc.2 for ; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sX5ZXTl0P4YI78yELHKr5RIa2rVGe5IIa/a1u86MeK0=; b=C3zKwikreEbobcJYlkhl7EXTmjnXv1qJWapLCBcnIHftJ2cE26y/rzRjcRmngE0UqV KyUE3U9sPcFUJaEP1uF5jlN8yxB6s0Bco1IXelCQWzQSKerBBRMpKEnUfHhjti2x+uds yezZVcaYn7nuhgL0I9dtEr683/7cSzBRhKC9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sX5ZXTl0P4YI78yELHKr5RIa2rVGe5IIa/a1u86MeK0=; b=XkXaV7XwJN/vLbeZ3uX2i1RcTzKyTDN4h69aN/lkPeMtD/cEepfQ/eRNmUldjxlCsy NZ42/rP4JkFy+8JFbKwYlSDZduVm4Omq4GIVsCq1HfOFRedQMZ76y2ZGLjdq2Eem3XvV 1L6vKVmvPhnDKBxRvA3Nn3Dy+GScM1mDA//FD8QoZ1QZA177+UkepbBVDYTjf3KxQk1v co7HEaS/p52v3wo0FSPFzNBIF+xHO+ZlBNtao/jdJuD6Uxe3hnOjYXVASaqK5Nnv6i+o rajTr3FaLHV6h0KwFyHl0SmQOj92Oqc/oImV3fZTuYiU9aTOEO3lZsiDq3/sf+dqTJiO YUKw== X-Gm-Message-State: AOAM530djHjnTMlK8GgHjhm3bE2SKly0+Z179Ohtad+wUpsYb2JxE+hI LTbox9KX17FK5T+6ivGIAmjQwJ8Op9OyLz9D X-Google-Smtp-Source: ABdhPJzj0O+x72GDUq3FXP8ctBY0umAoElnc4EKZYhq8F7ujUO6ISNviA4E2wE6PdFxsC1ENnHWBGA== X-Received: by 2002:a17:906:37db:: with SMTP id o27mr14720627ejc.60.1616752728689; Fri, 26 Mar 2021 02:58:48 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:48 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 06/22] media: uvcvideo: Set capability in s_param Date: Fri, 26 Mar 2021 10:58:24 +0100 Message-Id: <20210326095840.364424-7-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Fixes v4l2-compliance: Format ioctls (Input 0): warn: v4l2-test-formats.cpp(1339): S_PARM is supported but doesn't report V4L2_CAP_TIMEPERFRAME fail: v4l2-test-formats.cpp(1241): node->has_frmintervals && !cap->capability Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index ac98869d5a05..1eeeb00280e4 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -472,10 +472,13 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, uvc_simplify_fraction(&timeperframe.numerator, &timeperframe.denominator, 8, 333); - if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { parm->parm.capture.timeperframe = timeperframe; - else + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + } else { parm->parm.output.timeperframe = timeperframe; + parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; + } return 0; } From patchwork Fri Mar 26 09:58:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410406 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C69C433E8 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 802EB601FB for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230107AbhCZJ66 (ORCPT ); Fri, 26 Mar 2021 05:58:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbhCZJ6v (ORCPT ); Fri, 26 Mar 2021 05:58:51 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91C6AC0613B3 for ; Fri, 26 Mar 2021 02:58:50 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id l4so7466160ejc.10 for ; Fri, 26 Mar 2021 02:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eGEbDdnxvr1xLVANMZdtzFwCYrSlkB/OUQV9O+h/O7Y=; b=WoGkUMRB+hZG5srLy5V1gTYT/x61xXlx/NBXfD/s9wOaoxjeD2Pe0PAuAqdL0gM5Rt rNja5S0G0sNG/8laO/dBbneKzk5vMMld6oocd+sT3sc0LVa8w7dQkio3bUL8B50vjewJ 7RcEVUg50rTqKnokvW2InkdJ8ze2zpv1lzgT0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eGEbDdnxvr1xLVANMZdtzFwCYrSlkB/OUQV9O+h/O7Y=; b=rwH4qaeK5a3a4q2CKF9Zjn4BZwq2OF/tH89Z4fJgXZDqx86lB2sEThmugjOJc0TOsp sVH9hgKQEPD62PO6qs7W/UaUSCvZQNCtv+D22XwRZD6ajzwjBk5I9XFjL1CGBt03VxI6 ZlLGjBUNptClVD2elIkR5bc7kDnkNl4cVNUjWaVMIeY7djQdeIRVR35wgyz49juudHss zM+bpk/ztjuBG+C+Q2WgUCNDs094I8SVwdpeVtH5KIyPJogLaWyjXvkT8wunMkedb2U6 y+sw6lXtAGVWuo1RT2PEmJqcnWgfiqUc+CH//4WBa6KOz2sCO06++2RyRha8eNf60iNi QlKw== X-Gm-Message-State: AOAM532cmN/P9sIjKqg2aTTZFEGNOa3/wU6qBz2UQx++vezYge+v9jfP ToDaiK2ZmEwdK3M/Oz+5pNFQnzm21ggA2l9j X-Google-Smtp-Source: ABdhPJzrYuEt7Xf+jITuCY5D2PraUBAdDMsrNkQ/v19ECHnYWGoQgGJPu1Fw7t1rzLRatuaoKRQCVQ== X-Received: by 2002:a17:906:3751:: with SMTP id e17mr14457691ejc.553.1616752729365; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:49 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 07/22] media: uvcvideo: Return -EIO for control errors Date: Fri, 26 Mar 2021 10:58:25 +0100 Message-Id: <20210326095840.364424-8-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The device is doing something unspected with the control. Either because the protocol is not properly implemented or there has been a HW error. Fixes v4l2-compliance: Control ioctls (Input 0): fail: v4l2-test-controls.cpp(448): s_ctrl returned an error (22) test VIDIOC_G/S_CTRL: FAIL fail: v4l2-test-controls.cpp(698): s_ext_ctrls returned an error (22) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index f2f565281e63..25fd8aa23529 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -112,6 +112,11 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, case 5: /* Invalid unit */ case 6: /* Invalid control */ case 7: /* Invalid Request */ + /* + * The firmware has not properly implemented + * the control or there has been a HW error. + */ + return -EIO; case 8: /* Invalid value within range */ return -EINVAL; default: /* reserved or unknown */ From patchwork Fri Mar 26 09:58:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEC20C433EA for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A222F61A57 for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbhCZJ7A (ORCPT ); Fri, 26 Mar 2021 05:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhCZJ6v (ORCPT ); Fri, 26 Mar 2021 05:58:51 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B135C0613B2 for ; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id u5so7499293ejn.8 for ; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PozJDrjBoFoiSACjiJTngE3Hc/EWz/RcQCo80H4qmY4=; b=B281Mtgj/j0RDsuT3O9weLX9L+2dGtyBfinH0McNTQFKKbJmnwab1zsesWdyWnS39O IWY4OXmGDJdA21vr+7JgA8qwj7Pi/Ek5idb4y6nFUuxNqFz/DHhfve+9rFP8jgU+c/Cz iAdCTQawixOdRhk19yy4Jex8oHMXV1Qxw8GG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PozJDrjBoFoiSACjiJTngE3Hc/EWz/RcQCo80H4qmY4=; b=WgtM5QfvIw3wUp8Xg0BSiTnifgbbuRGYOMXE8nw38KT3dG1zxrtl1JBygI6ZntWiS9 R09E3SiuOFcPPm3pWOjyXBWyfVLFvonwdtl99BSdMN4eKL+yYj3eFqPO3B8Vap9iVDqW Aji+uv/wLd/wxg5lYom0FWZHbPbe4YBwlUvX0L6/sYVNwrf1iGzD6MSwbrqnbAaKocap xAq8KD1AO2EL/s5qW2shTOgl7yDULtDG9M7QYLu192AEdexyXyZd1ijTMVSS76JARuKF 8pBkPmva+T0OJ9HP6uthNwG8gmlXzmy+utolEvpaB3OvnsYiDB5HNcO+ZwXPqt4tVIbD B3hw== X-Gm-Message-State: AOAM532tOxwMsAPZqVpM4FhwDiIuFzcv52MIVN5CrHS7HoWzFjZ7EY29 rR57YNIbZqYaouqJADbKXr6Z8w== X-Google-Smtp-Source: ABdhPJwT0KN4Lj8UbrvLefcoMXFzG3lleunanrdJSXgtyR35tF/EB94jE+6OOwImrcNnUiLxg0w0mw== X-Received: by 2002:a17:906:7c44:: with SMTP id g4mr14179083ejp.269.1616752729888; Fri, 26 Mar 2021 02:58:49 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:49 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 08/22] media: uvcvideo: refactor __uvc_ctrl_add_mapping Date: Fri, 26 Mar 2021 10:58:26 +0100 Message-Id: <20210326095840.364424-9-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Pass the chain instead of the device. We want to keep the reference to the chain that controls belong to. We need to delay the initialization of the controls after the chains have been initialized. This is a cleanup needed for the next patches. Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++---------- drivers/media/usb/uvc/uvc_driver.c | 8 +++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b3dde98499f4..b75da65115ef 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2057,7 +2057,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, /* * Add a control mapping to a given control. */ -static int __uvc_ctrl_add_mapping(struct uvc_device *dev, +static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) { struct uvc_control_mapping *map; @@ -2086,7 +2086,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_device *dev, map->set = uvc_set_le_value; list_add_tail(&map->list, &ctrl->info.mappings); - uvc_dbg(dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", + uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", map->name, ctrl->info.entity, ctrl->info.selector); return 0; @@ -2168,7 +2168,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, goto done; } - ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping); + ret = __uvc_ctrl_add_mapping(chain, ctrl, mapping); if (ret < 0) atomic_dec(&dev->nmappings); @@ -2244,7 +2244,8 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev, * Add control information and hardcoded stock control mappings to the given * device. */ -static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) +static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, + struct uvc_control *ctrl) { const struct uvc_control_info *info = uvc_ctrls; const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); @@ -2263,14 +2264,14 @@ static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) for (; info < iend; ++info) { if (uvc_entity_match_guid(ctrl->entity, info->entity) && ctrl->index == info->index) { - uvc_ctrl_add_info(dev, ctrl, info); + uvc_ctrl_add_info(chain->dev, ctrl, info); /* * Retrieve control flags from the device. Ignore errors * and work with default flag values from the uvc_ctrl * array when the device doesn't properly implement * GET_INFO on standard controls. */ - uvc_ctrl_get_flags(dev, ctrl, &ctrl->info); + uvc_ctrl_get_flags(chain->dev, ctrl, &ctrl->info); break; } } @@ -2281,22 +2282,20 @@ static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) for (; mapping < mend; ++mapping) { if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) - __uvc_ctrl_add_mapping(dev, ctrl, mapping); + __uvc_ctrl_add_mapping(chain, ctrl, mapping); } } /* * Initialize device controls. */ -int uvc_ctrl_init_device(struct uvc_device *dev) +static int uvc_ctrl_init_chain(struct uvc_video_chain *chain) { struct uvc_entity *entity; unsigned int i; - INIT_WORK(&dev->async_ctrl.work, uvc_ctrl_status_event_work); - /* Walk the entities list and instantiate controls */ - list_for_each_entry(entity, &dev->entities, list) { + list_for_each_entry(entity, &chain->entities, chain) { struct uvc_control *ctrl; unsigned int bControlSize = 0, ncontrols; u8 *bmControls = NULL; @@ -2316,7 +2315,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev) } /* Remove bogus/blacklisted controls */ - uvc_ctrl_prune_entity(dev, entity); + uvc_ctrl_prune_entity(chain->dev, entity); /* Count supported controls and allocate the controls array */ ncontrols = memweight(bmControls, bControlSize); @@ -2338,7 +2337,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev) ctrl->entity = entity; ctrl->index = i; - uvc_ctrl_init_ctrl(dev, ctrl); + uvc_ctrl_init_ctrl(chain, ctrl); ctrl++; } } @@ -2346,6 +2345,22 @@ int uvc_ctrl_init_device(struct uvc_device *dev) return 0; } +int uvc_ctrl_init_device(struct uvc_device *dev) +{ + struct uvc_video_chain *chain; + int ret; + + INIT_WORK(&dev->async_ctrl.work, uvc_ctrl_status_event_work); + + list_for_each_entry(chain, &dev->chains, list) { + ret = uvc_ctrl_init_chain(chain); + if (ret) + return ret; + } + + return 0; +} + /* * Cleanup device controls. */ diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 30ef2a3110f7..35873cf2773d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2423,14 +2423,14 @@ static int uvc_probe(struct usb_interface *intf, if (v4l2_device_register(&intf->dev, &dev->vdev) < 0) goto error; - /* Initialize controls. */ - if (uvc_ctrl_init_device(dev) < 0) - goto error; - /* Scan the device for video chains. */ if (uvc_scan_device(dev) < 0) goto error; + /* Initialize controls. */ + if (uvc_ctrl_init_device(dev) < 0) + goto error; + /* Register video device nodes. */ if (uvc_register_chains(dev) < 0) goto error; From patchwork Fri Mar 26 09:58:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0066CC433EB for ; Fri, 26 Mar 2021 09:59:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9D1E61A6B for ; Fri, 26 Mar 2021 09:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbhCZJ67 (ORCPT ); Fri, 26 Mar 2021 05:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbhCZJ6w (ORCPT ); Fri, 26 Mar 2021 05:58:52 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A15B6C0613B1 for ; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id u5so7499337ejn.8 for ; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O1A4VZLTAkFAtJoA6EHKhYhHyEF+7+9N2fiqT4Ue7J0=; b=abB9ysUyHvt5qB0GA+yjUH7owXjYLLsUlzLVZ7YhGfBkkJf2hatfRRDRnyIwi8dKar sRIXFsNmzioQMvw4nz3yAcMrcU+sTkQVVJce6nA8AHcUlloglFDR85cEFsee6r3Onp/v aa5um2xGctku2nxdqAQgs0POJRjs/p+FAjj7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O1A4VZLTAkFAtJoA6EHKhYhHyEF+7+9N2fiqT4Ue7J0=; b=cax9PwZod6DssabVGt30qPxOwBtH5Ejl2yWZQnVS4wHMNmyqIzG5opC8WvhBRwRSxE r8vz7peUe0Tu5zSHXPE9HLEiITQWDFvKZmk97AZZAa/2TjCe5G6inJFGyO6tGLDQ51iT I0I+hU54k7B0v71dQgVo+WLe9FRocPoqogLvWFsNUBHFYL/3S+8rp6pdZlvfmp8HWPAY veeUF3Uakq1uL1lgPYC1NVX0NTdnINb0ARHP3PgP/SIV6WWt2aBwc/kd/3yyIgw32f+6 eWaUr5wI9K3OeFC3afixWKl++sLoEWmeErkYOlmMnfeEA+TaBE1jTmxZZj66YqQ4MahK rYiQ== X-Gm-Message-State: AOAM530nSQo8vC2Es7cjaolhxrmP8vxj8+2MUZ1GKLpl6X9Vp/AuFpkw UEO3FVnFF+ba54BymcuqJOCBGQ== X-Google-Smtp-Source: ABdhPJwB5A3AxMdCDzew5P1Q7vYUxZlB2qEA6sIgAG+1gwDpnbcWjrAj/ceArE0/Wk+GVzkc0Y3T4g== X-Received: by 2002:a17:907:216d:: with SMTP id rl13mr13983479ejb.362.1616752730373; Fri, 26 Mar 2021 02:58:50 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:50 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 09/22] media: uvcvideo: Add support for V4L2_CTRL_TYPE_CTRL_CLASS Date: Fri, 26 Mar 2021 10:58:27 +0100 Message-Id: <20210326095840.364424-10-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Create all the class controls for the device defined controls. Fixes v4l2-compliance: Control ioctls (Input 0): fail: v4l2-test-controls.cpp(216): missing control class for class 00980000 fail: v4l2-test-controls.cpp(216): missing control tclass for class 009a0000 test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: FAIL Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 94 ++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 5 ++ 2 files changed, 99 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b75da65115ef..ba14733db757 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -357,6 +357,15 @@ static const struct uvc_control_info uvc_ctrls[] = { }, }; +static const struct uvc_control_class uvc_control_class[] = { + { + .id = V4L2_CID_CAMERA_CLASS, + }, + { + .id = V4L2_CID_USER_CLASS, + }, +}; + static const struct uvc_menu_info power_line_frequency_controls[] = { { 0, "Disabled" }, { 1, "50 Hz" }, @@ -1024,6 +1033,49 @@ static int __uvc_ctrl_get(struct uvc_video_chain *chain, return 0; } +static int __uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, + u32 found_id) +{ + bool find_next = req_id & V4L2_CTRL_FLAG_NEXT_CTRL; + unsigned int i; + + req_id &= V4L2_CTRL_ID_MASK; + + for (i = 0; i < ARRAY_SIZE(uvc_control_class); i++) { + if (!(chain->ctrl_class_bitmap & BIT(i))) + continue; + if (!find_next) { + if (uvc_control_class[i].id == req_id) + return i; + continue; + } + if (uvc_control_class[i].id > req_id && + uvc_control_class[i].id < found_id) + return i; + } + + return -ENODEV; +} + +static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, + u32 found_id, struct v4l2_queryctrl *v4l2_ctrl) +{ + int idx; + + idx = __uvc_query_v4l2_class(chain, req_id, found_id); + if (idx < 0) + return -ENODEV; + + memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); + v4l2_ctrl->id = uvc_control_class[idx].id; + strscpy(v4l2_ctrl->name, v4l2_ctrl_get_name(v4l2_ctrl->id), + sizeof(v4l2_ctrl->name)); + v4l2_ctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS; + v4l2_ctrl->flags = V4L2_CTRL_FLAG_WRITE_ONLY + | V4L2_CTRL_FLAG_READ_ONLY; + return 0; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1127,12 +1179,31 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, if (ret < 0) return -ERESTARTSYS; + /* Check if the ctrl is a know class */ + if (!(v4l2_ctrl->id & V4L2_CTRL_FLAG_NEXT_CTRL)) { + ret = uvc_query_v4l2_class(chain, v4l2_ctrl->id, 0, v4l2_ctrl); + if (!ret) + goto done; + } + ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping); if (ctrl == NULL) { ret = -EINVAL; goto done; } + /* + * If we're enumerating control with V4L2_CTRL_FLAG_NEXT_CTRL, check if + * a class should be inserted between the previous control and the one + * we have just found. + */ + if (v4l2_ctrl->id & V4L2_CTRL_FLAG_NEXT_CTRL) { + ret = uvc_query_v4l2_class(chain, v4l2_ctrl->id, mapping->id, + v4l2_ctrl); + if (!ret) + goto done; + } + ret = __uvc_query_v4l2_ctrl(chain, ctrl, mapping, v4l2_ctrl); done: mutex_unlock(&chain->ctrl_mutex); @@ -1426,6 +1497,11 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) if (ret < 0) return -ERESTARTSYS; + if (__uvc_query_v4l2_class(handle->chain, sev->id, 0) >= 0) { + ret = 0; + goto done; + } + ctrl = uvc_find_control(handle->chain, sev->id, &mapping); if (ctrl == NULL) { ret = -EINVAL; @@ -1459,7 +1535,10 @@ static void uvc_ctrl_del_event(struct v4l2_subscribed_event *sev) struct uvc_fh *handle = container_of(sev->fh, struct uvc_fh, vfh); mutex_lock(&handle->chain->ctrl_mutex); + if (__uvc_query_v4l2_class(handle->chain, sev->id, 0) >= 0) + goto done; list_del(&sev->node); +done: mutex_unlock(&handle->chain->ctrl_mutex); } @@ -1577,6 +1656,9 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, struct uvc_control *ctrl; struct uvc_control_mapping *mapping; + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >= 0) + return -EACCES; + ctrl = uvc_find_control(chain, xctrl->id, &mapping); if (ctrl == NULL) return -EINVAL; @@ -1596,6 +1678,9 @@ int uvc_ctrl_set(struct uvc_fh *handle, s32 max; int ret; + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >= 0) + return -EACCES; + ctrl = uvc_find_control(chain, xctrl->id, &mapping); if (ctrl == NULL) return -EINVAL; @@ -2062,6 +2147,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, { struct uvc_control_mapping *map; unsigned int size; + unsigned int i; /* Most mappings come from static kernel data and need to be duplicated. * Mappings that come from userspace will be unnecessarily duplicated, @@ -2085,6 +2171,14 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, if (map->set == NULL) map->set = uvc_set_le_value; + for (i = 0; i < ARRAY_SIZE(uvc_control_class); i++) { + if (V4L2_CTRL_ID2WHICH(uvc_control_class[i].id) == + V4L2_CTRL_ID2WHICH(map->id)) { + chain->ctrl_class_bitmap |= BIT(i); + break; + } + } + list_add_tail(&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", map->name, ctrl->info.entity, ctrl->info.selector); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 97df5ecd66c9..b81d3f65e52e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -262,6 +262,10 @@ struct uvc_control_mapping { u8 *data); }; +struct uvc_control_class { + u32 id; +}; + struct uvc_control { struct uvc_entity *entity; struct uvc_control_info info; @@ -475,6 +479,7 @@ struct uvc_video_chain { struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ + u8 ctrl_class_bitmap; /* Bitmap of valid classes */ }; struct uvc_stats_frame { From patchwork Fri Mar 26 09:58:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A5ECC433ED for ; Fri, 26 Mar 2021 09:59:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 198E561A5B for ; Fri, 26 Mar 2021 09:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230166AbhCZJ7A (ORCPT ); Fri, 26 Mar 2021 05:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhCZJ6w (ORCPT ); Fri, 26 Mar 2021 05:58:52 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A526C0613B1 for ; Fri, 26 Mar 2021 02:58:52 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id w18so5690586edc.0 for ; Fri, 26 Mar 2021 02:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=neLiXa2Mi6CDcIfMH5ROa7xzDK4SNK6Agg6TL5Pdv3o=; b=MNmPEK9lIQNgbpBYhPsqp2edjQg+xONrsRZIssar5j4aaFrDqaurTJfP1xgfLSK0WN 5y/10UcuCCAaLgzms8MSu1El17SUFkSZWcWHZ7IHI5Y9jf6ePA5IIBK//jFX/7TSJoMs Za58Cbu69jOLbFTSAH3gzY4Mu1n5pkfxBaTCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=neLiXa2Mi6CDcIfMH5ROa7xzDK4SNK6Agg6TL5Pdv3o=; b=B64NOYugpd3mWXjrWAqXdQoytoqB8FyeAzbN+NJ7YOJOnHv+vN0V/FTPPkeJkCEAiO G52zzwTAyY3ahh1CLObyf6C0hDCFz6XGUloG1AIPI9OicVHugZ1EulckycmRQWUgMpom DWqbAjcXEp1jwSYWUCGkfzlLVsm7D81TDpsDBf7AgiDlvN5vROsC7Eq4DV9gFyAXyBm9 6D+wt4Gg271Ag4SV9ZX1EeeljkAqwnyvlzxbO4HYwMfVQeD2N+o/s7vhDDFa6j3SgzEC BDecgka9G7p4eWYoCyRQKVg0V9knpIdaqoSw2JSu4mQirE1JfE6bi6meO0pyOjLdFvnw DygQ== X-Gm-Message-State: AOAM531Oz1bWjxl8c0Mm7XzocV/2HF6Kq95N0D4c9okspLbeZgDOfqJU a2OdCSCCyJVA0xKccdQyyvTLRw== X-Google-Smtp-Source: ABdhPJyY86L134zDeIC7L+s0ilnz4gVN2MQoMfUvKiVniAtbV8Gs0lxjGIPY6ZiLrM4Hi7NK2/vJqw== X-Received: by 2002:a50:ef0a:: with SMTP id m10mr13899340eds.261.1616752731083; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:50 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 10/22] media: uvcvideo: Use dev->name for querycap() Date: Fri, 26 Mar 2021 10:58:28 +0100 Message-Id: <20210326095840.364424-11-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use the device name for the card name instead of vdev->name. Signed-off-by: Hans Verkuil Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_metadata.c | 2 +- drivers/media/usb/uvc/uvc_v4l2.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c index b6279ad7ac84..82de7781f5b6 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -30,7 +30,7 @@ static int uvc_meta_v4l2_querycap(struct file *file, void *fh, struct uvc_video_chain *chain = stream->chain; strscpy(cap->driver, "uvcvideo", sizeof(cap->driver)); - strscpy(cap->card, vfh->vdev->name, sizeof(cap->card)); + strscpy(cap->card, stream->dev->name, sizeof(cap->card)); usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING | chain->caps; diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 1eeeb00280e4..9cdd30eff495 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -617,13 +617,12 @@ static int uvc_v4l2_release(struct file *file) static int uvc_ioctl_querycap(struct file *file, void *fh, struct v4l2_capability *cap) { - struct video_device *vdev = video_devdata(file); struct uvc_fh *handle = file->private_data; struct uvc_video_chain *chain = handle->chain; struct uvc_streaming *stream = handle->stream; strscpy(cap->driver, "uvcvideo", sizeof(cap->driver)); - strscpy(cap->card, vdev->name, sizeof(cap->card)); + strscpy(cap->card, handle->stream->dev->name, sizeof(cap->card)); usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING | chain->caps; From patchwork Fri Mar 26 09:58:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 873C0C433C1 for ; Fri, 26 Mar 2021 09:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5449261A42 for ; Fri, 26 Mar 2021 09:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbhCZJ70 (ORCPT ); Fri, 26 Mar 2021 05:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhCZJ6x (ORCPT ); Fri, 26 Mar 2021 05:58:53 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ED10C0613B1 for ; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id l18so5603190edc.9 for ; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NAt2Z25D9SYYUpw3Y+wmG0p1xTHdfyVY2RGY6L+Y0hI=; b=LrHEzGD9Ux0D8mtGSKfVkBZRLNoH2qNBpGR7qYHGhKS5Zme7q5MPI6ZZWz82JjhhAh gZQO9Xy2aAZzim5GW32rq0dkMWGU2yQaZrZMwv1wY6wGYsR7YHI1fymo68fRAwlmqKkM 1i3+XVDpkOTk6i2u3QBWFnVIH7B136LEHLoAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NAt2Z25D9SYYUpw3Y+wmG0p1xTHdfyVY2RGY6L+Y0hI=; b=JomOXlwFMyciDjiE0c+DIacG8Wj65e7jzlwQknn5HUTcQGSEvg2NFSEhJLmJRdL+Wq nHj3z7FJSCIgt5RdombfauLMjKZiu6U8KcOo8xZ3B5kRurzg1dznLddZWTSYf6d7z9d3 HO0Nhyzs80t3M6b4aa7FQ4HBWY+4RfBB5C+OjxnWURtN7rAw/BxOlA7aEFsjVzTiffls ptkZ3jPf4mv9cO++fl19GnJdwHM9dn5U6FkX3tdriDaBwAFdQSJQsnc+7VXm/e6UOfyF O+lttumykISq3kpnBPsz9Ik1R8Lt/2KIOJaKCfLxwT/xKnISYuaZv2jsjklpi/pPkN7p zkKg== X-Gm-Message-State: AOAM533hLO22TQRQVZC19MHN2td/DtEJ1gKBhGA1W/lyQaFxKLbBz5o+ OzMpsjjYFeHdN2gy/0JVzrcpX1C8WNwCW0SP X-Google-Smtp-Source: ABdhPJyeic7XYW8exgiEgegNfx0tIOIllkPhddEzh/cMFXSwk9DliC5yF5YdlkgGjxwf5ngG4nmi2A== X-Received: by 2002:aa7:c74a:: with SMTP id c10mr13749686eds.332.1616752731925; Fri, 26 Mar 2021 02:58:51 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:51 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 11/22] media: uvcvideo: Set unique vdev name based in type Date: Fri, 26 Mar 2021 10:58:29 +0100 Message-Id: <20210326095840.364424-12-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org All the entities must have a unique name. We can have a descriptive and unique name by appending the function and the entity->id. This is even resilent to multi chain devices. Fixes v4l2-compliance: Media Controller ioctls: fail: v4l2-test-media.cpp(205): v2_entity_names_set.find(key) != v2_entity_names_set.end() test MEDIA_IOC_G_TOPOLOGY: FAIL fail: v4l2-test-media.cpp(394): num_data_links != num_links test MEDIA_IOC_ENUM_ENTITIES/LINKS: FAIL Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_driver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 35873cf2773d..76ab6acecbc9 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2163,6 +2163,7 @@ int uvc_register_video_device(struct uvc_device *dev, const struct v4l2_ioctl_ops *ioctl_ops) { int ret; + const char *name; /* Initialize the video buffers queue. */ ret = uvc_queue_init(queue, type, !uvc_no_drop_param); @@ -2190,16 +2191,20 @@ int uvc_register_video_device(struct uvc_device *dev, case V4L2_BUF_TYPE_VIDEO_CAPTURE: default: vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + name = "Video Capture"; break; case V4L2_BUF_TYPE_VIDEO_OUTPUT: vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; + name = "Video Output"; break; case V4L2_BUF_TYPE_META_CAPTURE: vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING; + name = "Metadata"; break; } - strscpy(vdev->name, dev->name, sizeof(vdev->name)); + snprintf(vdev->name, sizeof(vdev->name), "%s %u", name, + stream->header.bTerminalLink); /* * Set the driver data before calling video_register_device, otherwise From patchwork Fri Mar 26 09:58:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4661DC433E0 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 023F061A45 for ; Fri, 26 Mar 2021 09:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbhCZJ73 (ORCPT ); Fri, 26 Mar 2021 05:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbhCZJ6y (ORCPT ); Fri, 26 Mar 2021 05:58:54 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D479FC0613AA for ; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id h13so5618294eds.5 for ; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WPoNB75fJwZV+y8PhAr8AbPUzITMD6gvcbvvfafRqw4=; b=d98UqYMXLh1GkS3X5Ql8jf2Aczve63UXC4yRrXWMAFlK5udcI8Wqr5ceV5yAw3xbQD G/abC/fdt3CAX5k/Ti85iqgCRhqPhF77mp56lGYkD7Si4mtlAE7bGanoiUtrtMpufIcO pZjQsY3PPZhDUThTpB0i/NwrDB98rQzpnnlCc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WPoNB75fJwZV+y8PhAr8AbPUzITMD6gvcbvvfafRqw4=; b=XDwnMJsVj9Vdrwr7l6x8xXO/jpchNc5VO5OJMGsvJtd+Dykk4S054Kx5VD8yBAh5VC OK7fXYGrdztXAqV/gPnMi9i6/DkunDnVAp/x6lSOtUOVz7Y88TSRkDqUP/oC75LcigLp fvPeFaf5eiOLErEci3K+g5qcGDzUYEkxgmK/VOVWpNIy0Z85z0JVklnFv32nBECg9xW9 SAuRFSuo+FRFfD/T+7Xyz7YafAR9O47/G20BCVpCul9b2Es8Lv3ky/AUTn1Po8COcu1K JZ93QrHOnx+iJlTxWsXYTFaL3+6F/zwBnVduu4wA4C5IqKeAwh4MFUuASYRVEh79rupp WLjg== X-Gm-Message-State: AOAM531NxilatQlLfiQmuVVpxHsVVSez+22SJNczqbVZXslUwde3tejG spdtq6OoT6/kmAQ+LSU555Karw== X-Google-Smtp-Source: ABdhPJx1/JwKWXs8e2CRjTdMucZluWeL5p4upcohqZa3Q2v31JS3h3uRlrc/K5+ofzsTIKVlmqX/+g== X-Received: by 2002:a05:6402:31e9:: with SMTP id dy9mr14210544edb.186.1616752732658; Fri, 26 Mar 2021 02:58:52 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:52 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 12/22] media: uvcvideo: Increase the size of UVC_METADATA_BUF_SIZE Date: Fri, 26 Mar 2021 10:58:30 +0100 Message-Id: <20210326095840.364424-13-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hans has discovered that in his test device, for the H264 format bytesused goes up to about 570, for YUYV it will actually go up to a bit over 5000 bytes, and for MJPG up to about 2706 bytes. We should also, according to V4L2_META_FMT_UVC docs, drop headers when the buffer is full. Credit-to: Hans Verkuil Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_video.c | 8 +++++--- drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 25fd8aa23529..ea2903dc3252 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1244,11 +1244,13 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream, if (!meta_buf || length == 2) return; + /* + * According to V4L2_META_FMT_UVC docs, we should drop headers when + * the buffer is full. + */ if (meta_buf->length - meta_buf->bytesused < - length + sizeof(meta->ns) + sizeof(meta->sof)) { - meta_buf->error = 1; + length + sizeof(meta->ns) + sizeof(meta->sof)) return; - } has_pts = mem[1] & UVC_STREAM_PTS; has_scr = mem[1] & UVC_STREAM_SCR; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index b81d3f65e52e..a26bbec8d37b 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -527,7 +527,7 @@ struct uvc_stats_stream { unsigned int max_sof; /* Maximum STC.SOF value */ }; -#define UVC_METADATA_BUF_SIZE 1024 +#define UVC_METADATA_BUF_SIZE 10240 /** * struct uvc_copy_op: Context structure to schedule asynchronous memcpy From patchwork Fri Mar 26 09:58:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D1ACC433E1 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5697561A5D for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbhCZJ7b (ORCPT ); Fri, 26 Mar 2021 05:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbhCZJ6z (ORCPT ); Fri, 26 Mar 2021 05:58:55 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE19C0613AA for ; Fri, 26 Mar 2021 02:58:54 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id b16so5619494eds.7 for ; Fri, 26 Mar 2021 02:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HubL0vo45WhTrZNY5PUAJh0oW0/xMBMWWshMaFUSDeQ=; b=lKxHsEbDWB2Eez4A5J36sY2hlMNFxPovzNs2DEIVDAE+oFOY1J9w9bjKmBaZyrquxO sZfSV5hSyOgMK4LTflM2lf42iXNbDnkffehRZxtlpcRK19Jl0a5YU1utyC73+QX5uHi+ xEDQjZhew6oFiKjZnBkNyXPS5tPrunTSHeXa4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HubL0vo45WhTrZNY5PUAJh0oW0/xMBMWWshMaFUSDeQ=; b=KLhEt0RdS6GbgJ4Qj1HpuwhYlrfwwqqE+64zDdPVN01xvBT9sXLgjxnUbKIb7tR/HU 90WucR3oJojguDbVlTUa9E4b3aM86qTLryIyxwMXkYxfDIKTC7avpaJrKdGaxl2FFzkS l1ioO3N5l9+yZ4Wz8FZTiwem9yZow3Fcyn82tJ/wdbRvraqpGNgDcvXx1rE6PEXwwNhW o53R5XkuKXz+VArN//3V1GSyaOKylPBsuIlRBVefISHP+pshLV/ci7Z/U5lgQrrkGiZ1 bb159DZ2TjFZ2SX41KBT3Wqw0HfPr0pqReFQyHf05Zs3ak2g95KPkenxth563MhItf64 w+Ow== X-Gm-Message-State: AOAM531agi+e3IL18qLES9Z6qihGCkkwY/r7iI0AaetXdwelVhLZWAzx KG5/4yxeHIRfJLGUtxDwq3ezqw== X-Google-Smtp-Source: ABdhPJyyuextvlGNj9i4slLK0a4zJUZIl+QbcLogg1s5adonBmT0PDV1Hw6zGPz4Ns6Jj3rJLbYEjA== X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr13710090edb.144.1616752733344; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:52 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda , Hans Verkuil Subject: [PATCH v9 13/22] media: uvcvideo: Use control names from framework Date: Fri, 26 Mar 2021 10:58:31 +0100 Message-Id: <20210326095840.364424-14-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The framework already contains a map of IDs to names, lets use it when possible. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil Suggested-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 57 ++++++++++++-------------------- drivers/media/usb/uvc/uvc_v4l2.c | 8 ++++- drivers/media/usb/uvc/uvcvideo.h | 2 +- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index ba14733db757..929e70dff11a 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -436,7 +436,6 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, static const struct uvc_control_mapping uvc_ctrl_mappings[] = { { .id = V4L2_CID_BRIGHTNESS, - .name = "Brightness", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_BRIGHTNESS_CONTROL, .size = 16, @@ -446,7 +445,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_CONTRAST, - .name = "Contrast", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_CONTRAST_CONTROL, .size = 16, @@ -456,7 +454,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_HUE, - .name = "Hue", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_HUE_CONTROL, .size = 16, @@ -468,7 +465,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_SATURATION, - .name = "Saturation", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_SATURATION_CONTROL, .size = 16, @@ -478,7 +474,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_SHARPNESS, - .name = "Sharpness", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_SHARPNESS_CONTROL, .size = 16, @@ -488,7 +483,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_GAMMA, - .name = "Gamma", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_GAMMA_CONTROL, .size = 16, @@ -498,7 +492,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_BACKLIGHT_COMPENSATION, - .name = "Backlight Compensation", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL, .size = 16, @@ -508,7 +501,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_GAIN, - .name = "Gain", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_GAIN_CONTROL, .size = 16, @@ -518,7 +510,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_POWER_LINE_FREQUENCY, - .name = "Power Line Frequency", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, .size = 2, @@ -530,7 +521,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_HUE_AUTO, - .name = "Hue, Auto", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_HUE_AUTO_CONTROL, .size = 1, @@ -541,7 +531,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_EXPOSURE_AUTO, - .name = "Exposure, Auto", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_AE_MODE_CONTROL, .size = 4, @@ -554,7 +543,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY, - .name = "Exposure, Auto Priority", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_AE_PRIORITY_CONTROL, .size = 1, @@ -564,7 +552,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_EXPOSURE_ABSOLUTE, - .name = "Exposure (Absolute)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, .size = 32, @@ -576,7 +563,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_AUTO_WHITE_BALANCE, - .name = "White Balance Temperature, Auto", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, .size = 1, @@ -587,7 +573,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, - .name = "White Balance Temperature", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL, .size = 16, @@ -599,7 +584,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_AUTO_WHITE_BALANCE, - .name = "White Balance Component, Auto", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, .size = 1, @@ -611,7 +595,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_BLUE_BALANCE, - .name = "White Balance Blue Component", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL, .size = 16, @@ -623,7 +606,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_RED_BALANCE, - .name = "White Balance Red Component", .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL, .size = 16, @@ -635,7 +617,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_FOCUS_ABSOLUTE, - .name = "Focus (absolute)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL, .size = 16, @@ -647,7 +628,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_FOCUS_AUTO, - .name = "Focus, Auto", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_FOCUS_AUTO_CONTROL, .size = 1, @@ -658,7 +638,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_IRIS_ABSOLUTE, - .name = "Iris, Absolute", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL, .size = 16, @@ -668,7 +647,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_IRIS_RELATIVE, - .name = "Iris, Relative", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_IRIS_RELATIVE_CONTROL, .size = 8, @@ -678,7 +656,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_ZOOM_ABSOLUTE, - .name = "Zoom, Absolute", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL, .size = 16, @@ -688,7 +665,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_ZOOM_CONTINUOUS, - .name = "Zoom, Continuous", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_ZOOM_RELATIVE_CONTROL, .size = 0, @@ -700,7 +676,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_PAN_ABSOLUTE, - .name = "Pan (Absolute)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL, .size = 32, @@ -710,7 +685,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_TILT_ABSOLUTE, - .name = "Tilt (Absolute)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL, .size = 32, @@ -720,7 +694,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_PAN_SPEED, - .name = "Pan (Speed)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_PANTILT_RELATIVE_CONTROL, .size = 16, @@ -732,7 +705,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_TILT_SPEED, - .name = "Tilt (Speed)", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_PANTILT_RELATIVE_CONTROL, .size = 16, @@ -744,7 +716,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_PRIVACY, - .name = "Privacy", .entity = UVC_GUID_UVC_CAMERA, .selector = UVC_CT_PRIVACY_CONTROL, .size = 1, @@ -754,7 +725,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, { .id = V4L2_CID_PRIVACY, - .name = "Privacy", .entity = UVC_GUID_EXT_GPIO_CONTROLLER, .selector = UVC_CT_PRIVACY_CONTROL, .size = 1, @@ -1076,6 +1046,20 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, return 0; } +static const char *uvc_map_get_name(const struct uvc_control_mapping *map) +{ + const char *name; + + if (map->name) + return map->name; + + name = v4l2_ctrl_get_name(map->id); + if (name) + return name; + + return "Unknown Control"; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1089,7 +1073,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); v4l2_ctrl->id = mapping->id; v4l2_ctrl->type = mapping->v4l2_type; - strscpy(v4l2_ctrl->name, mapping->name, sizeof(v4l2_ctrl->name)); + strscpy(v4l2_ctrl->name, uvc_map_get_name(mapping), + sizeof(v4l2_ctrl->name)); v4l2_ctrl->flags = 0; if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) @@ -2181,7 +2166,8 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, list_add_tail(&map->list, &ctrl->info.mappings); uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", - map->name, ctrl->info.entity, ctrl->info.selector); + uvc_map_get_name(map), ctrl->info.entity, + ctrl->info.selector); return 0; } @@ -2199,7 +2185,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, if (mapping->id & ~V4L2_CTRL_ID_MASK) { uvc_dbg(dev, CONTROL, "Can't add mapping '%s', control id 0x%08x is invalid\n", - mapping->name, mapping->id); + uvc_map_get_name(mapping), mapping->id); return -EINVAL; } @@ -2246,7 +2232,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, if (mapping->id == map->id) { uvc_dbg(dev, CONTROL, "Can't add mapping '%s', control id 0x%08x already exists\n", - mapping->name, mapping->id); + uvc_map_get_name(mapping), mapping->id); ret = -EEXIST; goto done; } @@ -2257,7 +2243,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, atomic_dec(&dev->nmappings); uvc_dbg(dev, CONTROL, "Can't add mapping '%s', maximum mappings count (%u) exceeded\n", - mapping->name, UVC_MAX_CONTROL_MAPPINGS); + uvc_map_get_name(mapping), UVC_MAX_CONTROL_MAPPINGS); ret = -ENOMEM; goto done; } @@ -2466,6 +2452,7 @@ static void uvc_ctrl_cleanup_mappings(struct uvc_device *dev, list_for_each_entry_safe(mapping, nm, &ctrl->info.mappings, list) { list_del(&mapping->list); kfree(mapping->menu_info); + kfree(mapping->name); kfree(mapping); } } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 9cdd30eff495..28ccaa8b9e42 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -40,7 +40,13 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, return -ENOMEM; map->id = xmap->id; - memcpy(map->name, xmap->name, sizeof(map->name)); + /* Non standard control id. */ + if (v4l2_ctrl_get_name(map->id) == NULL) { + map->name = kmemdup(xmap->name, sizeof(xmap->name), + GFP_KERNEL); + if (!map->name) + return -ENOMEM; + } memcpy(map->entity, xmap->entity, sizeof(map->entity)); map->selector = xmap->selector; map->size = xmap->size; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a26bbec8d37b..dc20021f7ee0 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -240,7 +240,7 @@ struct uvc_control_mapping { struct list_head ev_subs; u32 id; - u8 name[32]; + char *name; u8 entity[16]; u8 selector; From patchwork Fri Mar 26 09:58:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C56C4C433E2 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CEFA601FB for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbhCZJ7d (ORCPT ); Fri, 26 Mar 2021 05:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbhCZJ6z (ORCPT ); Fri, 26 Mar 2021 05:58:55 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14615C0613B3 for ; Fri, 26 Mar 2021 02:58:55 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id l18so5603274edc.9 for ; Fri, 26 Mar 2021 02:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UdKbcPL+qZ541Aq+8xy8G+4FUKyoooUhHHCi0e55XOM=; b=i6wzuJjbON/1aOWWRc47QAYMRZLyM6FDguvLfnuRNLk7Xlw4PyihscPUsEEYS/SwYp PrnoLwL9oNv8LmIGCJgjXqMNCLE0b8JsFTIDNKhocCS4PP49TDaA7EDkZKqIj/pMddcO vSs2kE/2V7+9b+/MR6K1iS5zRrItn2oQvLsuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UdKbcPL+qZ541Aq+8xy8G+4FUKyoooUhHHCi0e55XOM=; b=sRUrQCDd/O5YtBeY7v62lIM9tjooIYI302ajoeZjX51iH3nUekFEPcLaJOSE4Ylrn1 tLaSLHhC0w4xtnlbqhqvqW3GVEjzCZMF7fEUQWXZ15WT0ZCv8KWf29nTv8ojrS6M1C+P Lt6MDu/8LPs7ptGApvnyjE0B12LRWf98VYAWvu9C7Iie6Zv7ooryIQfwp+leTxM+IgXG a0F/h2jvLnFkB39VltXxFdcyl02teXbT5kszYXnmyxBQl1wTMbfklUjVerl7K98bzVoZ n1MbZ0+et74bLDzGaX19GMcCtUCleBV23/gm39WuxJ8AaCkAV7ovxwOE5I1sZ2AMIInF GH/w== X-Gm-Message-State: AOAM5323B3mpqFwaVgDkD6XlVCnx3kxvmcWPT28Q1/gwcbW2UNwklNxZ GaUs/Q41zo3FeUL0H3yMKHBz8A== X-Google-Smtp-Source: ABdhPJwetFNumiw38PnM33J5Tqc0EDjcEZnSuImGKrPPAaEjdWug5aNmgremseSSJb2qSyiPGaoAGQ== X-Received: by 2002:aa7:da04:: with SMTP id r4mr13995386eds.343.1616752733859; Fri, 26 Mar 2021 02:58:53 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:53 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 14/22] media: uvcvideo: Check controls flags before accessing them Date: Fri, 26 Mar 2021 10:58:32 +0100 Message-Id: <20210326095840.364424-15-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org We can figure out if reading/writing a set of controls can fail without accessing them by checking their flags. This way we can honor the API closer: If an error is found when validating the list of controls passed with VIDIOC_G_EXT_CTRLS, then error_idx shall be set to ctrls->count to indicate to userspace that no actual hardware was touched. Fixes v4l2-compliance: Control ioctls (Input 0): warn: v4l2-test-controls.cpp(765): g_ext_ctrls(0) invalid error_idx 0 fail: v4l2-test-controls.cpp(645): invalid error index write only control test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 22 ++++++++++++++++++ drivers/media/usb/uvc/uvc_v4l2.c | 39 ++++++++++++++++++++++++++++---- drivers/media/usb/uvc/uvcvideo.h | 2 ++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 929e70dff11a..24fd5afc4e4f 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1046,6 +1046,28 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, return 0; } +int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, + bool read) +{ + struct uvc_control_mapping *mapping; + struct uvc_control *ctrl; + + if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0) + return -EACCES; + + ctrl = uvc_find_control(chain, v4l2_id, &mapping); + if (!ctrl) + return -EINVAL; + + if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && read) + return -EACCES; + + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read) + return -EACCES; + + return 0; +} + static const char *uvc_map_get_name(const struct uvc_control_mapping *map) { const char *name; diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 28ccaa8b9e42..a3ee1dc003fc 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -991,6 +991,26 @@ static int uvc_ioctl_query_ext_ctrl(struct file *file, void *fh, return 0; } +static int uvc_ctrl_check_access(struct uvc_video_chain *chain, + struct v4l2_ext_controls *ctrls, + unsigned long ioctl) +{ + struct v4l2_ext_control *ctrl = ctrls->controls; + unsigned int i; + int ret = 0; + + for (i = 0; i < ctrls->count; ++ctrl, ++i) { + ret = uvc_ctrl_is_accessible(chain, ctrl->id, + ioctl == VIDIOC_G_EXT_CTRLS); + if (ret) + break; + } + + ctrls->error_idx = ioctl == VIDIOC_TRY_EXT_CTRLS ? i : ctrls->count; + + return ret; +} + static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *ctrls) { @@ -1000,6 +1020,10 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, unsigned int i; int ret; + ret = uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS); + if (ret < 0) + return ret; + if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) { for (i = 0; i < ctrls->count; ++ctrl, ++i) { struct v4l2_queryctrl qc = { .id = ctrl->id }; @@ -1036,13 +1060,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, struct v4l2_ext_controls *ctrls, - bool commit) + unsigned long ioctl) { struct v4l2_ext_control *ctrl = ctrls->controls; struct uvc_video_chain *chain = handle->chain; unsigned int i; int ret; + ret = uvc_ctrl_check_access(chain, ctrls, ioctl); + if (ret < 0) + return ret; + ret = uvc_ctrl_begin(chain); if (ret < 0) return ret; @@ -1051,14 +1079,15 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, ret = uvc_ctrl_set(handle, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); - ctrls->error_idx = commit ? ctrls->count : i; + ctrls->error_idx = ioctl == VIDIOC_S_EXT_CTRLS ? + ctrls->count : i; return ret; } } ctrls->error_idx = 0; - if (commit) + if (ioctl == VIDIOC_S_EXT_CTRLS) return uvc_ctrl_commit(handle, ctrls->controls, ctrls->count); else return uvc_ctrl_rollback(handle); @@ -1069,7 +1098,7 @@ static int uvc_ioctl_s_ext_ctrls(struct file *file, void *fh, { struct uvc_fh *handle = fh; - return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, true); + return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, VIDIOC_S_EXT_CTRLS); } static int uvc_ioctl_try_ext_ctrls(struct file *file, void *fh, @@ -1077,7 +1106,7 @@ static int uvc_ioctl_try_ext_ctrls(struct file *file, void *fh, { struct uvc_fh *handle = fh; - return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, false); + return uvc_ioctl_s_try_ext_ctrls(handle, ctrls, VIDIOC_TRY_EXT_CTRLS); } static int uvc_ioctl_querymenu(struct file *file, void *fh, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index dc20021f7ee0..9471c342a310 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -902,6 +902,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle) int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); +int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, + bool read); int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry); From patchwork Fri Mar 26 09:58:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E45EAC433E4 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD14C61A61 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbhCZJ7m (ORCPT ); Fri, 26 Mar 2021 05:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbhCZJ64 (ORCPT ); Fri, 26 Mar 2021 05:58:56 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D92C2C0613AA for ; Fri, 26 Mar 2021 02:58:55 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id bx7so5586024edb.12 for ; Fri, 26 Mar 2021 02:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nbGSHzgBOA+TWrNxbZ+DwhlrbLAE2vitiIte0uj+CJo=; b=SxtI6JYCIQaFo9YPDAkl6+qkbcRx2kNasDiqaZ0nUsMGRI9nT3ROfD5BgEkh99Gj0g oQAKhRFo7ZwXTF6H5EqtTeHtj+velcQz7tbDECPUG+y6izO9nwYUMGu7Op6Mt1iLx/3V pwpG5TNfBmFszRCSVn1CHthk6bBQvaLa5PCJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nbGSHzgBOA+TWrNxbZ+DwhlrbLAE2vitiIte0uj+CJo=; b=jMdtPW9e4JeleRdVqXgqQuzyWs/sp1RticDJ1lakHPVOFPWORIII6pG2OO5rdiYOCs xW0PMDx0D6T/yQR5YArBBHu8inYEedxG6j+yYzxFbHLWdKtPx2m0/vhxtGzOa2koXLrg 2RCyFzVycI4gC+fdRFB4p8kjsDnL/Nn5tD6F5vW8PLnM2GN7nURS759lQFRoEaNoQ7Ka PLc8gfkXLYOqXBJv3OQH3Kvc/iM/fQZrIokLeDx6y8L3qnsNyvZCdhwnSaxNYRwAXfo9 KpwsmAsTh7QVy3McEZQXWmMOTjAYGETbxDWmSyB2dOhKxEFrQ+45EenHkaZ8mG5xZmlW ljSw== X-Gm-Message-State: AOAM530t/3Lt9lRZC0fxky4IxicRD8A4hx/YVEJhBhpZsUIWAecVv6w6 PKjD+3TL9+on0AKMKRZ6AMz2HA== X-Google-Smtp-Source: ABdhPJyb9exjob5Y9wOqzFcbMRGw4RFJ3kQ/JP1VdqHDyZHHi1+bsv+iqT3rTykHR4GwzDckzJ87wQ== X-Received: by 2002:a05:6402:4241:: with SMTP id g1mr14137500edb.331.1616752734606; Fri, 26 Mar 2021 02:58:54 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:54 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 15/22] media: uvcvideo: Set error_idx during ctrl_commit errors Date: Fri, 26 Mar 2021 10:58:33 +0100 Message-Id: <20210326095840.364424-16-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If we have an error setting a control, return the affected control in the error_idx field. Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 42 ++++++++++++++++++++++++++------ drivers/media/usb/uvc/uvc_v4l2.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 10 +++----- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 24fd5afc4e4f..bcebf9d1a46f 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1586,7 +1586,7 @@ int uvc_ctrl_begin(struct uvc_video_chain *chain) } static int uvc_ctrl_commit_entity(struct uvc_device *dev, - struct uvc_entity *entity, int rollback) + struct uvc_entity *entity, int rollback, struct uvc_control **err_ctrl) { struct uvc_control *ctrl; unsigned int i; @@ -1628,31 +1628,59 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, ctrl->dirty = 0; - if (ret < 0) + if (ret < 0) { + if (err_ctrl) + *err_ctrl = ctrl; return ret; + } } return 0; } +static int uvc_ctrl_find_ctrlidx(struct uvc_entity *entity, + struct v4l2_ext_controls *ctrls, + struct uvc_control *uvc_control) +{ + struct uvc_control_mapping *mapping; + struct uvc_control *ctrl_found; + unsigned int i; + + if (!entity) + return ctrls->count; + + for (i = 0; i < ctrls->count; i++) { + __uvc_find_control(entity, ctrls->controls[i].id, &mapping, + &ctrl_found, 0); + if (uvc_control == ctrl_found) + return i; + } + + return ctrls->count; +} + int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, - const struct v4l2_ext_control *xctrls, - unsigned int xctrls_count) + struct v4l2_ext_controls *ctrls) { struct uvc_video_chain *chain = handle->chain; + struct uvc_control *err_ctrl; struct uvc_entity *entity; int ret = 0; /* Find the control. */ list_for_each_entry(entity, &chain->entities, chain) { - ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback); + ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback, + &err_ctrl); if (ret < 0) goto done; } if (!rollback) - uvc_ctrl_send_events(handle, xctrls, xctrls_count); + uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); done: + if (ret < 0 && ctrls) + ctrls->error_idx = uvc_ctrl_find_ctrlidx(entity, ctrls, + err_ctrl); mutex_unlock(&chain->ctrl_mutex); return ret; } @@ -2110,7 +2138,7 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) ctrl->dirty = 1; } - ret = uvc_ctrl_commit_entity(dev, entity, 0); + ret = uvc_ctrl_commit_entity(dev, entity, 0, NULL); if (ret < 0) return ret; } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index a3ee1dc003fc..8d8b12a4db34 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1088,7 +1088,7 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, ctrls->error_idx = 0; if (ioctl == VIDIOC_S_EXT_CTRLS) - return uvc_ctrl_commit(handle, ctrls->controls, ctrls->count); + return uvc_ctrl_commit(handle, ctrls); else return uvc_ctrl_rollback(handle); } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 9471c342a310..0313b30f0cea 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -887,17 +887,15 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, int uvc_ctrl_begin(struct uvc_video_chain *chain); int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, - const struct v4l2_ext_control *xctrls, - unsigned int xctrls_count); + struct v4l2_ext_controls *ctrls); static inline int uvc_ctrl_commit(struct uvc_fh *handle, - const struct v4l2_ext_control *xctrls, - unsigned int xctrls_count) + struct v4l2_ext_controls *ctrls) { - return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count); + return __uvc_ctrl_commit(handle, 0, ctrls); } static inline int uvc_ctrl_rollback(struct uvc_fh *handle) { - return __uvc_ctrl_commit(handle, 1, NULL, 0); + return __uvc_ctrl_commit(handle, 1, NULL); } int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); From patchwork Fri Mar 26 09:58:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9149C433E6 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCC1361A50 for ; Fri, 26 Mar 2021 09:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbhCZJ7m (ORCPT ); Fri, 26 Mar 2021 05:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbhCZJ65 (ORCPT ); Fri, 26 Mar 2021 05:58:57 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC67DC0613AA for ; Fri, 26 Mar 2021 02:58:56 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id dm8so5646103edb.2 for ; Fri, 26 Mar 2021 02:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zSZ2EkdJHOx24SFCkJIOCXa07CbkvnRSZh4lLvRcYLY=; b=ScXucLqVwqH9fks5pCW0qnVCPzgyW9j7Sxpq/MCIMyOChDgp6rPMgSRrkA1gS18YRn cPbUG+JpHx4kZ8TXxEAu+ASBdqHr0nfWvaYL5iar88FoSCVJv2xLwkhGxVVUS84rCwKl mt08Xbtxvrzt7IWFSV+SYIw3462pnBxnFHg2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zSZ2EkdJHOx24SFCkJIOCXa07CbkvnRSZh4lLvRcYLY=; b=IeAg1OQYCgvAU1bepPiKMns+Nyzzhc8gxg2+bFvP9sK/vuqtKc5qJLw/Ie1h1Q3RRA 3PBtDUTWPToeOVKG0YbkXTJyP88iYpRk2XDItYzlc1XW7u12c+Ep1SiNgXqx7fYKppcc Rhl7O+FP4z3nYHXJqri/p3NwldeUyJtG4BUvWrUeWoApkAXEH9nwSQM2olmWavbtYYUK mvI7ebWZpytpZ31dQphNUYx1ri2MeaqQhvvyZMf4XCMtZiU71GBGvUr+dICz8SkIQTQF mooS3nDSftwBrkEsxrq7ry+KN0ZpR2kks8o6qIBit34WGh8MogbaQZNMjtfIZP0D+aPA /AMQ== X-Gm-Message-State: AOAM530Pc95LlLN9z+HqWz/ElszBdoyOkEou7YoWKEOxNOOSoGKJqrvx ghcZZDdBrLqQ7P99lfteYQk4Pw== X-Google-Smtp-Source: ABdhPJzvwlhCTnCgWYNFzaiwu6HLMPX8onZCZwvZapgxXLffLK9dzMdv5yLYAE1SF5kZJoHA3PW2GA== X-Received: by 2002:aa7:d642:: with SMTP id v2mr14089314edr.257.1616752735626; Fri, 26 Mar 2021 02:58:55 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:54 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 16/22] media: uvcvideo: Return -EACCES to inactive controls Date: Fri, 26 Mar 2021 10:58:34 +0100 Message-Id: <20210326095840.364424-17-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If a control is inactive return -EACCES to let the userspace know that the value will not be applied automatically when the control is active again. Suggested-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_ctrl.c | 71 +++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index bcebf9d1a46f..d9d4add1e813 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1082,13 +1082,36 @@ static const char *uvc_map_get_name(const struct uvc_control_mapping *map) return "Unknown Control"; } +static bool uvc_ctrl_is_inactive(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping) +{ + struct uvc_control_mapping *master_map = NULL; + struct uvc_control *master_ctrl = NULL; + s32 val; + int ret; + + if (!mapping->master_id) + return false; + + __uvc_find_control(ctrl->entity, mapping->master_id, &master_map, + &master_ctrl, 0); + + if (!master_ctrl || !(master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + return false; + + ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + if (ret < 0 || val == mapping->master_manual) + return false; + + return true; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, struct v4l2_queryctrl *v4l2_ctrl) { - struct uvc_control_mapping *master_map = NULL; - struct uvc_control *master_ctrl = NULL; const struct uvc_menu_info *menu; unsigned int i; @@ -1104,18 +1127,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; - if (mapping->master_id) - __uvc_find_control(ctrl->entity, mapping->master_id, - &master_map, &master_ctrl, 0); - if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) { - s32 val; - int ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); - if (ret < 0) - return ret; - - if (val != mapping->master_manual) - v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; - } + if (uvc_ctrl_is_inactive(chain, ctrl, mapping)) + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; if (!ctrl->cached) { int ret = uvc_ctrl_populate_cache(chain, ctrl); @@ -1638,25 +1651,37 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, return 0; } -static int uvc_ctrl_find_ctrlidx(struct uvc_entity *entity, +static int uvc_ctrl_commit_error(struct uvc_video_chain *chain, + struct uvc_entity *entity, struct v4l2_ext_controls *ctrls, - struct uvc_control *uvc_control) + struct uvc_control *err_control, + int ret) { struct uvc_control_mapping *mapping; struct uvc_control *ctrl_found; unsigned int i; - if (!entity) - return ctrls->count; + if (!entity) { + ctrls->error_idx = ctrls->count; + return ret; + } for (i = 0; i < ctrls->count; i++) { __uvc_find_control(entity, ctrls->controls[i].id, &mapping, &ctrl_found, 0); - if (uvc_control == ctrl_found) - return i; + if (err_control == ctrl_found) + break; } + ctrls->error_idx = i; + + /* We could not find the control that failed. */ + if (i == ctrls->count) + return ret; - return ctrls->count; + if (uvc_ctrl_is_inactive(chain, err_control, mapping)) + return -EACCES; + + return ret; } int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, @@ -1679,8 +1704,8 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); done: if (ret < 0 && ctrls) - ctrls->error_idx = uvc_ctrl_find_ctrlidx(entity, ctrls, - err_ctrl); + ret = uvc_ctrl_commit_error(chain, entity, ctrls, err_ctrl, + ret); mutex_unlock(&chain->ctrl_mutex); return ret; } From patchwork Fri Mar 26 09:58:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410400 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 401EDC433E9 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1961561A50 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbhCZJ7n (ORCPT ); Fri, 26 Mar 2021 05:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbhCZJ65 (ORCPT ); Fri, 26 Mar 2021 05:58:57 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EC3C0613B1 for ; Fri, 26 Mar 2021 02:58:57 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id j3so5580147edp.11 for ; Fri, 26 Mar 2021 02:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U298rYjAJn0L1+zqib6+wctgA7KMqrT5dPHppU9NIJA=; b=ZwtnL7gYMd3BCd6nvE80yX4oFyZmkNnPycNW8ZMb2OHLJQhiGn69io0BHtvSEDofge X1bU18SrBQt+hc0jQUr4aVab4WeATFl/XmaoXs6EX87p4vaWj0wxTyn3YHGRcLsPDpLY NEjBLZBNp5EOHLDEDjLjYCJqfbV9dJDPL21DY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U298rYjAJn0L1+zqib6+wctgA7KMqrT5dPHppU9NIJA=; b=kw6S+g4bLhoIb7yzXcv9/OZu8jx0GisAhoGeOrJQ+jlfpSvlP/9atEo5qR+BKzYYW0 i/Ug2gaDwLptTO06c+5OwcGtTk7M+f00jjf/xvHAtKXj/oKyWY7d6my9JpNfWyOxk9MN NiIMrDKQ7bAl/OWcYZUTdwpFHlOxFSSGFdGqENQ5wptYw1nWcEJQ6mkEqQRwZmunILZt tmf3SI6V4AsKu5/HO1LN7PQzrMlILdnVo/sTtLWzG8Re3/6Uc0W51E/A/qKuhnO8GsIt ZImfKD32Dhl1MytDEUphKnz/HO9cFlJHq8fOqgWi5jY7Tw4Gt4FQlyBfAtNCaGyPIpJg CbRg== X-Gm-Message-State: AOAM530dp3Q8wJEANkybMk20dFcChbYjnQamWSf9Oy3uYhnOnZM4hOif xkj9OAEK13RjT7diWOSlKgCoEP+gOomiP4yw X-Google-Smtp-Source: ABdhPJzStos7JXr9MhMZG/mBlM5P25jaxM6iCVYVZbmBpuYaYUdFWD8Xfgc03hLuZShCs758SpOk1w== X-Received: by 2002:a05:6402:138f:: with SMTP id b15mr14026182edv.121.1616752736122; Fri, 26 Mar 2021 02:58:56 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:55 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 17/22] media: docs: Document the behaviour of uvcdriver Date: Fri, 26 Mar 2021 10:58:35 +0100 Message-Id: <20210326095840.364424-18-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The uvc driver relies on the camera firmware to keep the control states and therefore is not capable of changing an inactive control. Allow returning -EACESS in those cases. Signed-off-by: Ricardo Ribalda --- Documentation/userspace-api/media/v4l/vidioc-g-ctrl.rst | 5 +++++ Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ctrl.rst b/Documentation/userspace-api/media/v4l/vidioc-g-ctrl.rst index 4f1bed53fad5..8c0a203385c2 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ctrl.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ctrl.rst @@ -95,3 +95,8 @@ EBUSY EACCES Attempt to set a read-only control or to get a write-only control. + + Or if there is an attempt to set an inactive control and the driver is + not capable of keeping the new value until the control is active again. + This is the case for drivers that do not use the standard control + framework and rely purely on the hardware to keep the controls' state. diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst index b9c62affbb5a..bb7de7a25241 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst @@ -438,3 +438,8 @@ EACCES Or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` but the device does not support requests. + + Or if there is an attempt to set an inactive control and the driver is + not capable of keeping the new value until the control is active again. + This is the case for drivers that do not use the standard control + framework and rely purely on the hardware to keep the controls' state. From patchwork Fri Mar 26 09:58:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410402 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DE21C433E8 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 398BF61A42 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbhCZJ7o (ORCPT ); Fri, 26 Mar 2021 05:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbhCZJ66 (ORCPT ); Fri, 26 Mar 2021 05:58:58 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 452BCC0613B1 for ; Fri, 26 Mar 2021 02:58:58 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id e7so5592648edu.10 for ; Fri, 26 Mar 2021 02:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2y2043uffVR+Axz3IQVPi3Ysoys/BWtFNPbRtzf1kL0=; b=XgF63OA3iDsQinIPZBYEr8xo0HmgnBltM2VyBTZUJlrE7RvmQWTXVJ/bPDKAQgcbSr hMzMUxoBPWavwexaFLyLHvsj9kuOGk4t4tYOfFeBHZREj7an3p7wF3sDIXq0RZ72q5BK zWkAxBGo9khdo6tgVxlUUdVPNNA30QfR7Ynv4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2y2043uffVR+Axz3IQVPi3Ysoys/BWtFNPbRtzf1kL0=; b=cZ5yrCOA4nPv+Im2XxImGXCA1N1vGV2NMRa5ggCgv2lCZDLO5m8rEyUpzzyH1WBLKA LLcWXFQVLO75hVWwVZz/Q26jcP/ncK/Q518qfUNo1+5J9co+13EcdV9tnSpN2e4vTUmv OHgTTrAwpIl1qCcrjbsWZ7urvZqKnZechmG2Bhnq3Z5/Dl2H1M32HE4osjIPFLhvlaYd /c7AXgXL1QS+gn7humvuX3U51Au5b1uvoQFExKw+a/d0cOzERUY5IKWjJiFB3ZbEo12+ Pl+AFv1Pzb9r0yhCJnmPqhUPBLGe7Qiye1RCQiU221JusMRcVuaLsSzbIMbHt6ctgbXQ 7YZg== X-Gm-Message-State: AOAM533sc2o9YxhvyUknwYH6oauTjCnniflnkKxrMc92+E51GsyhOcPq tndfG6xf/GN/Z++Lfj5JSlwlCA== X-Google-Smtp-Source: ABdhPJxvjIQgrOmedo0HpCzfT7PVy74zFLNCDZ0n2a5fez8hs/en3vpCIMntNMC2y9Q/wN+2rK09uA== X-Received: by 2002:a50:fd15:: with SMTP id i21mr13534405eds.384.1616752737079; Fri, 26 Mar 2021 02:58:57 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:56 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v9 18/22] media: uvcvideo: Downgrade control error messages Date: Fri, 26 Mar 2021 10:58:36 +0100 Message-Id: <20210326095840.364424-19-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Convert the error into a debug message, so they are still valid for debugging but do not fill dmesg. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index ea2903dc3252..b63c073ec30e 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -76,7 +76,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, if (likely(ret == size)) return 0; - dev_err(&dev->udev->dev, + dev_dbg(&dev->udev->dev, "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", uvc_query_name(query), cs, unit, ret, size); From patchwork Fri Mar 26 09:58:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D8F4C433EC for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77C9F61A42 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230376AbhCZJ7u (ORCPT ); Fri, 26 Mar 2021 05:59:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbhCZJ67 (ORCPT ); Fri, 26 Mar 2021 05:58:59 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B1CBC0613B1 for ; Fri, 26 Mar 2021 02:58:59 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id o19so5634560edc.3 for ; Fri, 26 Mar 2021 02:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uCrEyotbYF7tjluvQkWSRucWwy5lZOwnlMYsosdr5+s=; b=KRXW799zU2MTkSiZwFPeS/NQnIfH+m9lYWRHp/dmwKY+tmOr2yVorJWeFyRXrK65Te CnldOEnO1NNXxfPRFjj0aGq/W9BnGpxTlaLBd2HPBlLowAt8bGqEVbHG6LfWKeMQeVhY 3ZJSd/EDfxdk7heSx/BtvGbxpys+b3clSZVGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uCrEyotbYF7tjluvQkWSRucWwy5lZOwnlMYsosdr5+s=; b=nz7hQ0fcNRpm5zM89k5jBUcmrACTNAJXe7vetK+mS8xO+sYwd1CZgQ+K3rAKt4WMio eikrQA4v+CKPr2WE+kQ/qaX51mq8kT933M8v/ADvz5QiM7GMTgAM/3a0/O8Knc6fZS7u xazIPBG2rwCYo25u7lkA0S9Ox4aOunpSevBpwTaIkfAkOhM0gIIOkBa9n9ZnEFJfIe3P haUyFo4aXXotZyOk5LDJGzw79aZmbMpCvFteeZX3py2GBTWmA+1RfIPrGfCvayKf4foU ukJlmp4rtuyq1hdeVqBjkEYgt9OQsCXPazy9LEaE9EVSne1q+fmePy7AqdN5xgt+aCj6 N2wg== X-Gm-Message-State: AOAM530J6F9yNL2A9QchQof4NtDpRlvq9yaedLx76xo7R1hcSs6SEnG+ aULQSIluwicpr4/MueksFZpyow== X-Google-Smtp-Source: ABdhPJwGZlffD5wb8dSneMODwCyR7usaPrHR/9r/bzx2a8jFZm4TQieAiVLvCyG4R0aFXP7Gv9tfsA== X-Received: by 2002:aa7:d74b:: with SMTP id a11mr13885736eds.92.1616752738024; Fri, 26 Mar 2021 02:58:58 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:57 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Hans Verkuil , Hans Verkuil Subject: [PATCH v9 19/22] uvcvideo: uvc_ctrl_is_accessible: check for INACTIVE Date: Fri, 26 Mar 2021 10:58:37 +0100 Message-Id: <20210326095840.364424-20-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Hans Verkuil Check for inactive controls in uvc_ctrl_is_accessible(). Use the new value for the master_id controls if present, otherwise use the existing value to determine if it is OK to set the control. Doing this here avoids attempting to set an inactive control, which will return an error from the USB device. Signed-off-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_ctrl.c | 28 +++++++++++++++++++++++++++- drivers/media/usb/uvc/uvc_v4l2.c | 4 ++-- drivers/media/usb/uvc/uvcvideo.h | 3 ++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index d9d4add1e813..6e7b904bc33d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1047,10 +1047,18 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, } int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, - bool read) + const struct v4l2_ext_controls *ctrls, + unsigned long ioctl) { + struct uvc_control_mapping *master_map = NULL; + struct uvc_control *master_ctrl = NULL; struct uvc_control_mapping *mapping; struct uvc_control *ctrl; + bool read = ioctl == VIDIOC_G_EXT_CTRLS; + bool try = ioctl == VIDIOC_TRY_EXT_CTRLS; + s32 val; + int ret; + int i; if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0) return -EACCES; @@ -1065,6 +1073,24 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read) return -EACCES; + if (read || try || !mapping->master_id) + return 0; + + for (i = ctrls->count - 1; i >= 0; i--) + if (ctrls->controls[i].id == mapping->master_id) + return ctrls->controls[i].value == + mapping->master_manual ? 0 : -EACCES; + + __uvc_find_control(ctrl->entity, mapping->master_id, &master_map, + &master_ctrl, 0); + + if (!master_ctrl || !(master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + return 0; + + ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + if (ret >= 0 && val != mapping->master_manual) + return -EACCES; + return 0; } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 8d8b12a4db34..0f4d893eff46 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1000,8 +1000,8 @@ static int uvc_ctrl_check_access(struct uvc_video_chain *chain, int ret = 0; for (i = 0; i < ctrls->count; ++ctrl, ++i) { - ret = uvc_ctrl_is_accessible(chain, ctrl->id, - ioctl == VIDIOC_G_EXT_CTRLS); + ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, + ioctl); if (ret) break; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 0313b30f0cea..20bc681315fb 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -901,7 +901,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle) int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, - bool read); + const struct v4l2_ext_controls *ctrls, + unsigned long ioctl); int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry); From patchwork Fri Mar 26 09:58:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AB61C433EA for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B72F61A50 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbhCZJ7r (ORCPT ); Fri, 26 Mar 2021 05:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbhCZJ7A (ORCPT ); Fri, 26 Mar 2021 05:59:00 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7BDEC0613B2 for ; Fri, 26 Mar 2021 02:58:59 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id j3so5580268edp.11 for ; Fri, 26 Mar 2021 02:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AsfUq8egj8BlQuh51pL/zTHndFh4URF1DvrGOxKo66o=; b=DAealO1uTP/4I6yw97+XqRu5ow7AcB7wdKoKXHCWIbaXmdr5U81We2MB575RVVtWMn H8DbmtWRhu9jf3UgAWSNeYdzR0rGHkT9UENIIEzOWU9P4rkHRM+ahXnEyIpg9jYrzlpc NBEUW9hdLBUhWidc43SlfjTGgLBxuOw534zNQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AsfUq8egj8BlQuh51pL/zTHndFh4URF1DvrGOxKo66o=; b=BnLBLyfNRM3wooUmGHUB+Oo76LmJtYktYC2YTw0wSRWKoTzMGhA9TRGQl/wrBKDMFJ KIqTM8uZJ50JTbkV0i6JznFYey/3YlWo1EN8WMzquPJpxQ2B/xZGL9dfl8L0IG+j6KBE AuC2EG2DLvHRa/AEDcZLsMh6BMUhB4n4Tc9LW0KqQxm/3TvppWpCLAijZWQYO5l7ToaP aE9FSW+4NMGnSNTYrmEEfUOeHU56rNw/BgIZkuzBENoiVNA2W6QrEdxuRLj1/jE4daLg sVwan3UvALlgyoj4+JsYQqc5h49ta0uigyQK0KdA8Xber3YuYNihDvvL36SQah8yCgCW xkeQ== X-Gm-Message-State: AOAM533Biljyd6Kq0+5eQ6L6GdnXvPML0bZezNP+8eLqbL85UR0IV3A0 owpyG4sbWzPYVEe1QkBcaVvzEQ== X-Google-Smtp-Source: ABdhPJw68cNvp2+qKDXKIUvnE5QBmHlpxA5HVxeMR/ep6ivHhqV1cbQHnf921Rlks8a68z5lIMIifw== X-Received: by 2002:a50:ef0a:: with SMTP id m10mr13899760eds.261.1616752738701; Fri, 26 Mar 2021 02:58:58 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:58 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Hans Verkuil Subject: [PATCH v9 20/22] uvcvideo: improve error handling in uvc_query_ctrl() Date: Fri, 26 Mar 2021 10:58:38 +0100 Message-Id: <20210326095840.364424-21-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Hans Verkuil - If __uvc_query_ctrl() failed with a non-EPIPE error, then report that with dev_err. If an error code is obtained, then report that with dev_dbg. - For error 2 (Wrong state) return -EACCES instead of -EILSEQ. EACCES is a much more appropriate error code. EILSEQ will return "Invalid or incomplete multibyte or wide character." in strerror(), which is a *very* confusing message. Signed-off-by: Hans Verkuil --- I have changed a bit the patch from the original version. drivers/media/usb/uvc/uvc_video.c | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index b63c073ec30e..1c3a94d91724 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -76,35 +76,31 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, if (likely(ret == size)) return 0; - dev_dbg(&dev->udev->dev, - "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", - uvc_query_name(query), cs, unit, ret, size); - - if (ret != -EPIPE) - return ret; + if (ret < 0 && ret != -EPIPE) + goto err; + // reuse data[0] for request the error code. tmp = *(u8 *)data; - ret = __uvc_query_ctrl(dev, UVC_GET_CUR, 0, intfnum, UVC_VC_REQUEST_ERROR_CODE_CONTROL, data, 1, UVC_CTRL_CONTROL_TIMEOUT); - error = *(u8 *)data; *(u8 *)data = tmp; - if (ret != 1) - return ret < 0 ? ret : -EPIPE; + if (ret != 1) { + ret = ret < 0 ? ret : -EPIPE; + goto err; + } - uvc_dbg(dev, CONTROL, "Control error %u\n", error); + dev_dbg(&dev->udev->dev, + "Failed to query (%s) UVC control %u on unit %u: got error %u.\n", + uvc_query_name(query), cs, unit, error); switch (error) { - case 0: - /* Cannot happen - we received a STALL */ - return -EPIPE; case 1: /* Not ready */ return -EBUSY; case 2: /* Wrong state */ - return -EILSEQ; + return -EACCES; case 3: /* Power */ return -EREMOTE; case 4: /* Out of range */ @@ -120,10 +116,18 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, case 8: /* Invalid value within range */ return -EINVAL; default: /* reserved or unknown */ - break; + dev_err(&dev->udev->dev, + "Failed to query (%s) UVC control %u on unit %u: got error %u.\n", + uvc_query_name(query), cs, unit, error); + return -EPIPE; } - return -EPIPE; +err: + dev_err(&dev->udev->dev, + "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", + uvc_query_name(query), cs, unit, ret, size); + + return ret; } static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, From patchwork Fri Mar 26 09:58:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 409814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF0F3C433F1 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4F9F61A42 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbhCZJ7v (ORCPT ); Fri, 26 Mar 2021 05:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbhCZJ7B (ORCPT ); Fri, 26 Mar 2021 05:59:01 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D4DBC0613B1 for ; Fri, 26 Mar 2021 02:59:00 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id z1so5617731edb.8 for ; Fri, 26 Mar 2021 02:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bONtZGsS4XqAKxeuy/H43uHE8WmZWjf3WVxgmtV5zE8=; b=W+Hm9SkjmsW0r45zVcLVwAM80sqfX6SfjfmMYq8EWW5OQf5aH5R+wL3veXe34hcJ29 QFIVN7Vp1P3ODMWodMitoNeSXTnKaVMGiICZqsy7FN900zkOsyRTxnQDqyZIoi0tZvb3 0T1V3yVIpWDhm2OAz12iHhJqJOuJYouV7Uyfw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bONtZGsS4XqAKxeuy/H43uHE8WmZWjf3WVxgmtV5zE8=; b=NNMFNuStLAfXCAKmaVL0ESQLueqP0H8YmOmWv75IsNGsyb6PxYgGRsDUclE1V8YIvb CbMCJJwyFXHMVLOuxWQ1GNmsuNEwqSOYn4gDwtabYIbfzFv6mUKKloZg1jCP0SGHZZ6Z hUFDPGLCE8P+v8holXdsMxVEUWTPGK+Xw7GG8lKeGTGOTlyP+Bc39Q8ttMt3UiUEtGn/ aYcOTmLsCFFgXZVwqbDr4/VY4g5r+IEVGUvUN1TXGU0LnuTQn71LYF/dw5uSGNR6pwEJ rH29AB3dKdiKU2a6dGaY+dldELHDhPuIhT2H7MuGE8QD1svToXAJ/fjNx/Dl1stf+agI Zouw== X-Gm-Message-State: AOAM533a2K5zYZN4v5K29bXp/lFcNpqzv6DALI2HdES2fvpvGBzl1pMp AtKWGYfUEwl2JK2waVDlBAGo1w== X-Google-Smtp-Source: ABdhPJwIbtASlZisUUvzHQbZuyZBqTk0Wn+fv19PofYh6AFM9f2DR2r4sbUNnDVTaw9CT+NleZJN8Q== X-Received: by 2002:aa7:c74a:: with SMTP id c10mr13750092eds.332.1616752739397; Fri, 26 Mar 2021 02:58:59 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:59 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Hans Verkuil Subject: [PATCH v9 21/22] uvcvideo: don't spam the log in uvc_ctrl_restore_values() Date: Fri, 26 Mar 2021 10:58:39 +0100 Message-Id: <20210326095840.364424-22-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Hans Verkuil Don't report the restored controls with dev_info, use dev_dbg instead. This prevents a lot of noise in the kernel log. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 6e7b904bc33d..df6c33932557 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2182,10 +2182,10 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) if (!ctrl->initialized || !ctrl->modified || (ctrl->info.flags & UVC_CTRL_FLAG_RESTORE) == 0) continue; - dev_info(&dev->udev->dev, - "restoring control %pUl/%u/%u\n", - ctrl->info.entity, ctrl->info.index, - ctrl->info.selector); + dev_dbg(&dev->udev->dev, + "restoring control %pUl/%u/%u\n", + ctrl->info.entity, ctrl->info.index, + ctrl->info.selector); ctrl->dirty = 1; } From patchwork Fri Mar 26 09:58:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 410399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05C98C433ED for ; Fri, 26 Mar 2021 10:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D918861A48 for ; Fri, 26 Mar 2021 10:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbhCZJ7x (ORCPT ); Fri, 26 Mar 2021 05:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbhCZJ7C (ORCPT ); Fri, 26 Mar 2021 05:59:02 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D1E0C0613B1 for ; Fri, 26 Mar 2021 02:59:01 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id x21so5631481eds.4 for ; Fri, 26 Mar 2021 02:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ce1sa5uWV/odUt24h9QtH7Ytlt4x3vZ7rql77kksng=; b=HCekXVlFYsVFvIjmVH6zKeckGr4e6TSrI5xltfslHR2xe/t6Zg6FSZi/RyJRDjzsu7 e4gKWGR/CcI7vuIW/e8PF2PHrK1bZTkLIgrGL53QXqJU9m+shCtjDnzFIAzbCCUkCEgT +lYY/dt3TN9vGG+l5E/9mVRSQhrZe5C8UD8Y4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ce1sa5uWV/odUt24h9QtH7Ytlt4x3vZ7rql77kksng=; b=OKMtU0Z9mMKQT7sQoLNhoNqFrQDHh6aSHqI6iNB6mgCJIy1f0sIyCh3JewX2FdnWvs jDeCFsnZIsggStYhzG9qXtr3Pn/Sxs/fI7v91A99bdpjQ4lQnHuXMZbFA+fu/l+04yAi 1F/qyimT+HssM1AKa5v6JrMkR8ajFsFnJbSIqRF8zJlF67vFflesy4BvoQG7Tn39k1tI qFhgqrHl1+BO+oc6Sp6s9qUjMjCzWh5OK7w0tm/IhlKSOklgWH+yzsj/vkBqqGt9VQqy DW5y6PW8z5dwX1Hjqe8qHswA15HviK3h32ilbaDUjyuGJSXT2Fii+caMPi6Z4moBkxBm Yutw== X-Gm-Message-State: AOAM533z/8RGVZsWordQjvcvT3T5f0mUIRLQ4bzTAYbm1jq6T9OzZEVD s7lZcB6jQx9wmmxgt/k1mW4fz3pM69PcbiDa X-Google-Smtp-Source: ABdhPJxhI6I0CDlrsElMzBzwTpUcS0o2cmeqMkx9bK19ncm9WMexueBnlA7lp5jLog11b2CV4CExLA== X-Received: by 2002:a05:6402:31e9:: with SMTP id dy9mr14210971edb.186.1616752740084; Fri, 26 Mar 2021 02:59:00 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id h13sm4036658edz.71.2021.03.26.02.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 02:58:59 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Hans Verkuil Subject: [PATCH v9 22/22] uvc: use vb2 ioctl and fop helpers Date: Fri, 26 Mar 2021 10:58:40 +0100 Message-Id: <20210326095840.364424-23-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210326095840.364424-1-ribalda@chromium.org> References: <20210326095840.364424-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Hans Verkuil When uvc was written the vb2 ioctl and file operation helpers didn't exist. This patch switches uvc over to those helpers, which removes a lot of boilerplate code and simplifies VIDIOC_G/S_PRIORITY handling and allows us to drop the 'privileges' scheme, since that's now handled inside the vb2 helpers. This makes it possible for uvc to pass the v4l2-compliance streaming tests. Signed-off-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_driver.c | 7 +- drivers/media/usb/uvc/uvc_metadata.c | 8 +- drivers/media/usb/uvc/uvc_queue.c | 143 ------------- drivers/media/usb/uvc/uvc_v4l2.c | 288 ++------------------------- drivers/media/usb/uvc/uvcvideo.h | 32 --- 5 files changed, 25 insertions(+), 453 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 76ab6acecbc9..1a38ea31e218 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1911,7 +1911,6 @@ static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev) INIT_LIST_HEAD(&chain->entities); mutex_init(&chain->ctrl_mutex); chain->dev = dev; - v4l2_prio_init(&chain->prio); return chain; } @@ -2181,7 +2180,7 @@ int uvc_register_video_device(struct uvc_device *dev, vdev->fops = fops; vdev->ioctl_ops = ioctl_ops; vdev->release = uvc_release; - vdev->prio = &stream->chain->prio; + vdev->queue = &queue->queue; if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT) vdev->vfl_dir = VFL_DIR_TX; else @@ -2546,8 +2545,8 @@ static int __uvc_resume(struct usb_interface *intf, int reset) if (stream->intf == intf) { ret = uvc_video_resume(stream, reset); if (ret < 0) - uvc_queue_streamoff(&stream->queue, - stream->queue.queue.type); + vb2_streamoff(&stream->queue.queue, + stream->queue.queue.type); return ret; } } diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c index 82de7781f5b6..d3aab22f91ce 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -96,7 +96,7 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *fh, */ mutex_lock(&stream->mutex); - if (uvc_queue_allocated(&stream->queue)) + if (vb2_is_busy(&stream->meta.queue.queue)) ret = -EBUSY; else stream->meta.format = fmt->dataformat; @@ -164,12 +164,6 @@ int uvc_meta_register(struct uvc_streaming *stream) stream->meta.format = V4L2_META_FMT_UVC; - /* - * The video interface queue uses manual locking and thus does not set - * the queue pointer. Set it manually here. - */ - vdev->queue = &queue->queue; - return uvc_register_video_device(dev, stream, vdev, queue, V4L2_BUF_TYPE_META_CAPTURE, &uvc_meta_fops, &uvc_meta_ioctl_ops); diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c index 21a907d32bb7..437e48b32480 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -247,153 +247,10 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, return 0; } -void uvc_queue_release(struct uvc_video_queue *queue) -{ - mutex_lock(&queue->mutex); - vb2_queue_release(&queue->queue); - mutex_unlock(&queue->mutex); -} - -/* ----------------------------------------------------------------------------- - * V4L2 queue operations - */ - -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_reqbufs(&queue->queue, rb); - mutex_unlock(&queue->mutex); - - return ret ? ret : rb->count; -} - -int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_querybuf(&queue->queue, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *cb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_create_bufs(&queue->queue, cb); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, struct v4l2_buffer *buf) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_qbuf(&queue->queue, mdev, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_expbuf(&queue->queue, exp); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, - int nonblocking) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_dqbuf(&queue->queue, buf, nonblocking); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_streamon(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type) -{ - int ret; - - mutex_lock(&queue->mutex); - ret = vb2_streamoff(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) -{ - return vb2_mmap(&queue->queue, vma); -} - -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff) -{ - return vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); -} -#endif - -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait) -{ - __poll_t ret; - - mutex_lock(&queue->mutex); - ret = vb2_poll(&queue->queue, file, wait); - mutex_unlock(&queue->mutex); - - return ret; -} - /* ----------------------------------------------------------------------------- * */ -/* - * Check if buffers have been allocated. - */ -int uvc_queue_allocated(struct uvc_video_queue *queue) -{ - int allocated; - - mutex_lock(&queue->mutex); - allocated = vb2_is_busy(&queue->queue); - mutex_unlock(&queue->mutex); - - return allocated; -} - /* * Cancel the video buffers queue. * diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 0f4d893eff46..e40db7ae18b1 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -352,17 +352,13 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream, return ret; mutex_lock(&stream->mutex); - - if (uvc_queue_allocated(&stream->queue)) { + if (vb2_is_busy(&stream->queue.queue)) { ret = -EBUSY; - goto done; + } else { + stream->ctrl = probe; + stream->cur_format = format; + stream->cur_frame = frame; } - - stream->ctrl = probe; - stream->cur_format = format; - stream->cur_frame = frame; - -done: mutex_unlock(&stream->mutex); return ret; } @@ -489,62 +485,6 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, return 0; } -/* ------------------------------------------------------------------------ - * Privilege management - */ - -/* - * Privilege management is the multiple-open implementation basis. The current - * implementation is completely transparent for the end-user and doesn't - * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls. - * Those ioctls enable finer control on the device (by making possible for a - * user to request exclusive access to a device), but are not mature yet. - * Switching to the V4L2 priority mechanism might be considered in the future - * if this situation changes. - * - * Each open instance of a UVC device can either be in a privileged or - * unprivileged state. Only a single instance can be in a privileged state at - * a given time. Trying to perform an operation that requires privileges will - * automatically acquire the required privileges if possible, or return -EBUSY - * otherwise. Privileges are dismissed when closing the instance or when - * freeing the video buffers using VIDIOC_REQBUFS. - * - * Operations that require privileges are: - * - * - VIDIOC_S_INPUT - * - VIDIOC_S_PARM - * - VIDIOC_S_FMT - * - VIDIOC_REQBUFS - */ -static int uvc_acquire_privileges(struct uvc_fh *handle) -{ - /* Always succeed if the handle is already privileged. */ - if (handle->state == UVC_HANDLE_ACTIVE) - return 0; - - /* Check if the device already has a privileged handle. */ - if (atomic_inc_return(&handle->stream->active) != 1) { - atomic_dec(&handle->stream->active); - return -EBUSY; - } - - handle->state = UVC_HANDLE_ACTIVE; - return 0; -} - -static void uvc_dismiss_privileges(struct uvc_fh *handle) -{ - if (handle->state == UVC_HANDLE_ACTIVE) - atomic_dec(&handle->stream->active); - - handle->state = UVC_HANDLE_PASSIVE; -} - -static int uvc_has_privileges(struct uvc_fh *handle) -{ - return handle->state == UVC_HANDLE_ACTIVE; -} - /* ------------------------------------------------------------------------ * V4L2 file operations */ @@ -587,7 +527,6 @@ static int uvc_v4l2_open(struct file *file) v4l2_fh_add(&handle->vfh); handle->chain = stream->chain; handle->stream = stream; - handle->state = UVC_HANDLE_PASSIVE; file->private_data = handle; return 0; @@ -600,15 +539,8 @@ static int uvc_v4l2_release(struct file *file) uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - /* Only free resources if this is a privileged handle. */ - if (uvc_has_privileges(handle)) - uvc_queue_release(&stream->queue); - /* Release the file handle. */ - uvc_dismiss_privileges(handle); - v4l2_fh_del(&handle->vfh); - v4l2_fh_exit(&handle->vfh); - kfree(handle); + vb2_fop_release(file); file->private_data = NULL; mutex_lock(&stream->dev->lock); @@ -701,11 +633,6 @@ static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh, { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; return uvc_v4l2_set_format(stream, fmt); } @@ -715,11 +642,6 @@ static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh, { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; return uvc_v4l2_set_format(stream, fmt); } @@ -744,124 +666,6 @@ static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh, return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); } -static int uvc_ioctl_reqbufs(struct file *file, void *fh, - struct v4l2_requestbuffers *rb) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - mutex_lock(&stream->mutex); - ret = uvc_request_buffers(&stream->queue, rb); - mutex_unlock(&stream->mutex); - if (ret < 0) - return ret; - - if (ret == 0) - uvc_dismiss_privileges(handle); - - return 0; -} - -static int uvc_ioctl_querybuf(struct file *file, void *fh, - struct v4l2_buffer *buf) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_query_buffer(&stream->queue, buf); -} - -static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_queue_buffer(&stream->queue, - stream->vdev.v4l2_dev->mdev, buf); -} - -static int uvc_ioctl_expbuf(struct file *file, void *fh, - struct v4l2_exportbuffer *exp) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_export_buffer(&stream->queue, exp); -} - -static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_dequeue_buffer(&stream->queue, buf, - file->f_flags & O_NONBLOCK); -} - -static int uvc_ioctl_create_bufs(struct file *file, void *fh, - struct v4l2_create_buffers *cb) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_create_buffers(&stream->queue, cb); -} - -static int uvc_ioctl_streamon(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - int ret; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - mutex_lock(&stream->mutex); - ret = uvc_queue_streamon(&stream->queue, type); - mutex_unlock(&stream->mutex); - - return ret; -} - -static int uvc_ioctl_streamoff(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - mutex_lock(&stream->mutex); - uvc_queue_streamoff(&stream->queue, type); - mutex_unlock(&stream->mutex); - - return 0; -} - static int uvc_ioctl_enum_input(struct file *file, void *fh, struct v4l2_input *input) { @@ -929,13 +733,12 @@ static int uvc_ioctl_g_input(struct file *file, void *fh, unsigned int *input) static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input) { struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; struct uvc_video_chain *chain = handle->chain; - int ret; u32 i; - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; + if (vb2_is_busy(&stream->queue.queue)) + return -EBUSY; if (chain->selector == NULL || (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { @@ -1166,11 +969,6 @@ static int uvc_ioctl_s_parm(struct file *file, void *fh, { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; return uvc_v4l2_set_streamparm(stream, parm); } @@ -1438,50 +1236,6 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, } #endif -static ssize_t uvc_v4l2_read(struct file *file, char __user *data, - size_t count, loff_t *ppos) -{ - struct uvc_fh *handle = file->private_data; - struct uvc_streaming *stream = handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s: not implemented\n", __func__); - return -EINVAL; -} - -static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct uvc_fh *handle = file->private_data; - struct uvc_streaming *stream = handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_mmap(&stream->queue, vma); -} - -static __poll_t uvc_v4l2_poll(struct file *file, poll_table *wait) -{ - struct uvc_fh *handle = file->private_data; - struct uvc_streaming *stream = handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_poll(&stream->queue, file, wait); -} - -#ifndef CONFIG_MMU -static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, - unsigned long addr, unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct uvc_fh *handle = file->private_data; - struct uvc_streaming *stream = handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_get_unmapped_area(&stream->queue, pgoff); -} -#endif - const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_querycap = uvc_ioctl_querycap, .vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt_vid_cap, @@ -1492,14 +1246,15 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt_vid_out, .vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt_vid_cap, .vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt_vid_out, - .vidioc_reqbufs = uvc_ioctl_reqbufs, - .vidioc_querybuf = uvc_ioctl_querybuf, - .vidioc_qbuf = uvc_ioctl_qbuf, - .vidioc_expbuf = uvc_ioctl_expbuf, - .vidioc_dqbuf = uvc_ioctl_dqbuf, - .vidioc_create_bufs = uvc_ioctl_create_bufs, - .vidioc_streamon = uvc_ioctl_streamon, - .vidioc_streamoff = uvc_ioctl_streamoff, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_enum_input = uvc_ioctl_enum_input, .vidioc_g_input = uvc_ioctl_g_input, .vidioc_s_input = uvc_ioctl_s_input, @@ -1527,11 +1282,10 @@ const struct v4l2_file_operations uvc_fops = { #ifdef CONFIG_COMPAT .compat_ioctl32 = uvc_v4l2_compat_ioctl32, #endif - .read = uvc_v4l2_read, - .mmap = uvc_v4l2_mmap, - .poll = uvc_v4l2_poll, + .mmap = vb2_fop_mmap, + .poll = vb2_fop_poll, #ifndef CONFIG_MMU - .get_unmapped_area = uvc_v4l2_get_unmapped_area, + .get_unmapped_area = vb2_fop_get_unmapped_area, #endif }; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 20bc681315fb..8849d7953767 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -477,7 +477,6 @@ struct uvc_video_chain { struct mutex ctrl_mutex; /* Protects ctrl.info */ - struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ u8 ctrl_class_bitmap; /* Bitmap of valid classes */ }; @@ -714,16 +713,10 @@ struct uvc_device { struct uvc_entity *gpio_unit; }; -enum uvc_handle_state { - UVC_HANDLE_PASSIVE = 0, - UVC_HANDLE_ACTIVE = 1, -}; - struct uvc_fh { struct v4l2_fh vfh; struct uvc_video_chain *chain; struct uvc_streaming *stream; - enum uvc_handle_state state; }; struct uvc_driver { @@ -788,36 +781,11 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); /* Video buffers queue management. */ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, int drop_corrupted); -void uvc_queue_release(struct uvc_video_queue *queue); -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb); -int uvc_query_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf); -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *v4l2_cb); -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, - struct v4l2_buffer *v4l2_buf); -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp); -int uvc_dequeue_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf, int nonblocking); -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type); -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type); void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf); struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue); void uvc_queue_buffer_release(struct uvc_buffer *buf); -int uvc_queue_mmap(struct uvc_video_queue *queue, - struct vm_area_struct *vma); -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait); -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff); -#endif -int uvc_queue_allocated(struct uvc_video_queue *queue); static inline int uvc_queue_streaming(struct uvc_video_queue *queue) { return vb2_is_streaming(&queue->queue);