From patchwork Fri Jul 14 20:14:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 9841623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 781D1602BD for ; Fri, 14 Jul 2017 20:14:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69A12287C2 for ; Fri, 14 Jul 2017 20:14:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E3DE287C7; Fri, 14 Jul 2017 20:14:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF8E5287C2 for ; Fri, 14 Jul 2017 20:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751117AbdGNUOg (ORCPT ); Fri, 14 Jul 2017 16:14:36 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33470 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751112AbdGNUOe (ORCPT ); Fri, 14 Jul 2017 16:14:34 -0400 Received: by mail-wm0-f66.google.com with SMTP id j85so12565600wmj.0 for ; Fri, 14 Jul 2017 13:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5No5uV6RDF3I8j7uwgbsr3vMTsGSMWsxYCYbqQH77fU=; b=abiO5O1UgzgjKoCcarEfTGR44gOnWIODcAWzYt2K5NG4Hr3zuvOmBYpj2kc03uV7FC YtyWASfO7VJ8R+10/rFIGDFG8GRRnRRMdXeZsphhohyIXPJwPjPkptLotCzEFHZti9Zv mVpHSjs/p9mv3jNrldBvp4PZDg7R41Xb6GCNrofesqyWViATFJ7ybsYA6EEGGdZzDXZJ 7zi6QgD7AO6uKyG4+KlQfxst3Y5OlgjjaVy53MgV0Qf1gCBuKderyZy2mp9PJ6RX5MxU xhvUASgRvL6DBmDfvG69e5gc1yDfDMmItwZImi/FkW78Ukt3/SIMLfT95I+hM499Zxzt BAwQ== 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; bh=5No5uV6RDF3I8j7uwgbsr3vMTsGSMWsxYCYbqQH77fU=; b=LjUMQdklgu3J+QYuTUkHb+Yb9JLZtd/VvT4doz2sSPurfUE9gUO3CTaNZTqN6qr/LF 7dWzSNuVoVWoja+cFfJK5yk4alwS7KFzs/Hnpt4y60+9PLmR9U/BQFelmiqZmIBSsYai NnJoVnlYSWv8Dtmbwz14SGfQQelXOS1qmgVcIxzG9BLbHSRehYEq9zRBBcB/hTE5bgez estiKxIX5UZRQbqn32FXky4NOFx0kS+DA+2ppd/8UDM9cYGFKgWp+uYSCekd/hu+T5TJ 22emYOxzXwgapUXUwY3CT1zSm5Kl1ryOTfkFKnVRrk8P79MOH7FMVe39X9qsxFyCYrUO gtpg== X-Gm-Message-State: AIVw11272+tspj+tnQKuRV+V0vEu5tgoNCcPNv0Ow0wtDLR0hWF1XCal b0fC5R+Tx9iGoUNV X-Received: by 10.80.180.141 with SMTP id w13mr8153594edd.42.1500063273405; Fri, 14 Jul 2017 13:14:33 -0700 (PDT) Received: from ped.lan ([31.18.254.68]) by smtp.googlemail.com with ESMTPSA id b4sm5308912eda.34.2017.07.14.13.14.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 13:14:32 -0700 (PDT) From: Philipp Zabel To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel Subject: [PATCH 1/3] [media] uvcvideo: variable size controls Date: Fri, 14 Jul 2017 22:14:22 +0200 Message-Id: <20170714201424.23592-1-philipp.zabel@gmail.com> X-Mailer: git-send-email 2.13.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some USB webcam controllers have extension unit controls that report different lengths via GET_LEN, depending on internal state. Add a flag to mark these controls as variable length and issue GET_LEN before GET/SET_CUR transfers to verify the current length. Signed-off-by: Philipp Zabel --- drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++++++++++++- include/uapi/linux/uvcvideo.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index c2ee6e39fd0c..ce69e2c6937d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1597,7 +1597,7 @@ static void uvc_ctrl_fixup_xu_info(struct uvc_device *dev, struct usb_device_id id; u8 entity; u8 selector; - u8 flags; + u16 flags; }; static const struct uvc_ctrl_fixup fixups[] = { @@ -1799,6 +1799,30 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, goto done; } + if ((ctrl->info.flags & UVC_CTRL_FLAG_VARIABLE_LEN) && reqflags) { + data = kmalloc(2, GFP_KERNEL); + /* Check if the control length has changed */ + ret = uvc_query_ctrl(chain->dev, UVC_GET_LEN, xqry->unit, + chain->dev->intfnum, xqry->selector, data, + 2); + size = le16_to_cpup((__le16 *)data); + kfree(data); + if (ret < 0) { + uvc_trace(UVC_TRACE_CONTROL, + "GET_LEN failed on control %pUl/%u (%d).\n", + entity->extension.guidExtensionCode, + xqry->selector, ret); + goto done; + } + if (ctrl->info.size != size) { + uvc_trace(UVC_TRACE_CONTROL, + "XU control %pUl/%u queried: len %u -> %u\n", + entity->extension.guidExtensionCode, + xqry->selector, ctrl->info.size, size); + ctrl->info.size = size; + } + } + if (size != xqry->size) { ret = -ENOBUFS; goto done; diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h index 3b081862b9e8..0f0d63e79045 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -27,6 +27,8 @@ #define UVC_CTRL_FLAG_RESTORE (1 << 6) /* Control can be updated by the camera. */ #define UVC_CTRL_FLAG_AUTO_UPDATE (1 << 7) +/* Control can change LEN */ +#define UVC_CTRL_FLAG_VARIABLE_LEN (1 << 8) #define UVC_CTRL_FLAG_GET_RANGE \ (UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \