Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp181107pxx; Wed, 28 Oct 2020 01:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEyt6nbrB0MWPyk0cCTdeW7xA9Ki+9uxygb/8OogpJxN3r4BzbsX8P/OZ+/CTVNDFJDQ3n X-Received: by 2002:a50:cf45:: with SMTP id d5mr6432041edk.225.1603875208055; Wed, 28 Oct 2020 01:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603875208; cv=none; d=google.com; s=arc-20160816; b=ktM1P+gCfso1o439hFZ0WyKMu1YPJoLPl9wodJSAABV09AP5J2fltCIqOgVKe0b2eY P4yLH7ndWXstmnY+0DP21s/g1b6AVqc8yBBBRFnxpcvXLZDSXRaStaCNVNhW/wnnRe5z uZwzA9FcMfzGa7dmX4PPi/WEgbJZIY2hY75Y/SXf/Yvx33ze2UAeaZ/6GVH9JAKQBpfx AxZauv1Rt++30xlESdVO3QljRrM4BlQtWpcIjuG5VBCMM2brY4HjY1s4PMckzzMS4aDG hYVhWmr1vMLLg3OckcELZFheywRR3CrcLwqVAeU9Ji9olJBiiqQjpjKg+CZSMnsb0MKT k2mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vFRijBKYKP/QeHWDDeHZKwK+kgeSc6uSx0PY2KcLJKU=; b=Dj0CFcAqx+SL9RrEcBlEIRueMK6z/hCRwJCaO1RsjsE13spPW+Xf1bjfx8AsecC4BC yfViEbgYdQ3rrautc4KJ+0ZzvT2BuU8MTexP9RK/C7X0D5ZCDBnRtEv8hO3rvTltQg1l KlbdJQtL2CkgqzQxk9hvxN6EEi4uvuNnv/YSrcNYM1YZF+RV9dloz+uuA9veMr+LH0dV JCDqbwmd4V54vxpLEOXz9Jz1iIdytAtQxUQGtcFjvu6mY6N7bc5A09uoyq2GLK9gDXaf FlWuxHVWrCoSx6t4/69mbxhwFa07PJkcveVIVia9sE5uqw9C29yCxsK+EBFAhruLhKVf Yzcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y2FraASD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt10si1135660edb.503.2020.10.28.01.53.05; Wed, 28 Oct 2020 01:53:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y2FraASD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756482AbgJ0ONf (ORCPT + 99 others); Tue, 27 Oct 2020 10:13:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:56602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754933AbgJ0OHo (ORCPT ); Tue, 27 Oct 2020 10:07:44 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66ACA206D4; Tue, 27 Oct 2020 14:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807664; bh=63W6OqwjTEPrCBDyKkGZqgpiKh0yhLfSDAgaipfF8kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2FraASDtK3UArU+c9NHEDjLfjhqCNnwp6QRNPUgoIpBuoWrxyL3pjJJibhzqcKfV PLxlVGVuZatYeTNdF7+E+g8UDRByU6wQ9QJbSWo9awUVUrPWl7i5lIBLRsibm3U3L1 OpKrWiILkgMMcZ5yemSCaE2l2ikK2qrmg0biwNok= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adam Goode , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 105/139] media: uvcvideo: Ensure all probed info is returned to v4l2 Date: Tue, 27 Oct 2020 14:49:59 +0100 Message-Id: <20201027134907.124787049@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adam Goode [ Upstream commit 8a652a17e3c005dcdae31b6c8fdf14382a29cbbe ] bFrameIndex and bFormatIndex can be negotiated by the camera during probing, resulting in the camera choosing a different format than expected. v4l2 can already accommodate such changes, but the code was not updating the proper fields. Without such a change, v4l2 would potentially interpret the payload incorrectly, causing corrupted output. This was happening on the Elgato HD60 S+, which currently always renegotiates to format 1. As an aside, the Elgato firmware is buggy and should not be renegotating, but it is still a valid thing for the camera to do. Both macOS and Windows will properly probe and read uncorrupted images from this camera. With this change, both qv4l2 and chromium can now read uncorrupted video from the Elgato HD60 S+. [Add blank lines, remove periods at the of messages] Signed-off-by: Adam Goode Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 05eed4be25df2..5156c971c241c 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -257,11 +257,41 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream, if (ret < 0) goto done; + /* After the probe, update fmt with the values returned from + * negotiation with the device. + */ + for (i = 0; i < stream->nformats; ++i) { + if (probe->bFormatIndex == stream->format[i].index) { + format = &stream->format[i]; + break; + } + } + + if (i == stream->nformats) { + uvc_trace(UVC_TRACE_FORMAT, "Unknown bFormatIndex %u\n", + probe->bFormatIndex); + return -EINVAL; + } + + for (i = 0; i < format->nframes; ++i) { + if (probe->bFrameIndex == format->frame[i].bFrameIndex) { + frame = &format->frame[i]; + break; + } + } + + if (i == format->nframes) { + uvc_trace(UVC_TRACE_FORMAT, "Unknown bFrameIndex %u\n", + probe->bFrameIndex); + return -EINVAL; + } + fmt->fmt.pix.width = frame->wWidth; fmt->fmt.pix.height = frame->wHeight; fmt->fmt.pix.field = V4L2_FIELD_NONE; fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(format, frame); fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize; + fmt->fmt.pix.pixelformat = format->fcc; fmt->fmt.pix.colorspace = format->colorspace; fmt->fmt.pix.priv = 0; -- 2.25.1