Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1210481pxx; Tue, 27 Oct 2020 10:46:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQGeHh3850+pak+IT5DH38syAAY99BjlVL0crL+iQgsICaYPzNA7ZDQ9o5Q2fGjchcQ1Ze X-Received: by 2002:aa7:dc42:: with SMTP id g2mr3469759edu.11.1603820811136; Tue, 27 Oct 2020 10:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603820811; cv=none; d=google.com; s=arc-20160816; b=HNwD/TsGq1UmpQ4NcSiXiPflQO9pnKGxDCCdCifMI/UkNzd9itLSfDjDilcFXifkBN qbFqZtTAfuzd9CwWwABP/KM3Sn6B5PmrdXpy8qh8s45Gqllefsq4vqGkgO5UH439sMZU MhnGnNpPLvrfi6K7sNJ/Xo3ETYTnNuyXETX2mRSy2OcisP9kwtws/BgF2KzO3cL8vQxI MLaqbFAZPayewVbhq8SQEZ1EihC5BhpOzacfaajyJM7SVaZsTF7p/6Wl2Iesr5yQK77f aKTMbUau7bXOySPcINLmICDZF0RbiE2t1NDIVpCLYsYV1TRiuSosPD1/BFvgxfb0yf9z MV/w== 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=NF3SCKFBQWQjNSo7UQCY0Raq9NWD7M+8nIaDiczWkr0=; b=Rf10wbsIBkl/gbQnPL9JgF/KkgoYZmik6lb+JGkbWcRVPvRmjHVehRKry9EeJRojOF xLE7aGbwpNsDYT7kF2XwcgYNurHF6XqoI1TDKgtdXpN/WGnzYiwGGgYu/37eIjkg/bme g9m09TefaTMNTBx/Yd0GKtyE8e9OrDUznuUHR4YRUNP8eetqgsqlxoL6+bOieOcGG2GC kJOT1W7R6uW3VZOCbPtCdAL22DWvNKSanIGbU+Bcxm9T834FnVQ1xK0IAHOA2pIZOz+W C6nKz+IOlWJlHOB8lYe0j9uCTtdx9LZEXp1gl+gQWal+iUlOZQ9rh1LSHwtT3Ar5+rLY nhAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r4eiGQ8M; 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 t13si1588033ejr.92.2020.10.27.10.46.27; Tue, 27 Oct 2020 10:46:51 -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=r4eiGQ8M; 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 S1784918AbgJ0O7m (ORCPT + 99 others); Tue, 27 Oct 2020 10:59:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762388AbgJ0OoR (ORCPT ); Tue, 27 Oct 2020 10:44:17 -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 7AD3B20773; Tue, 27 Oct 2020 14:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809856; bh=TPSg9F6aclc44MNfpeDtKYRLYQIcsA9t3mTkIqI3l/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4eiGQ8M4Nf2FuK2jmq5BobTKEa+CZ8bi6iRcaKx2Ddf0PYqmTy9xwOZt5BHyMnNi A79SraKVA38iDOInOGhHN5LZSdwwlO4PRrBGZs0+Lfy5y55mlMWhxmk+9s5BY/Mwj1 +LCJIVKGKH9OJhrv+yevI/7dwEDLovrIrQjbjPro= 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 5.4 342/408] media: uvcvideo: Ensure all probed info is returned to v4l2 Date: Tue, 27 Oct 2020 14:54:40 +0100 Message-Id: <20201027135510.891800132@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 0335e69b70abe..5e6f3153b5ff8 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -247,11 +247,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; if (uvc_format != NULL) -- 2.25.1