Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp165345pxx; Wed, 28 Oct 2020 01:18:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXyV15lVvBhyH8OgV0c5WMK+Ge3pC+NNfXHQTWZt8vP71l92dyqFUG3H/89ecB7QpY5gQQ X-Received: by 2002:a17:907:20b2:: with SMTP id pw18mr6192590ejb.159.1603873104569; Wed, 28 Oct 2020 01:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603873104; cv=none; d=google.com; s=arc-20160816; b=AWeTSBUkimdmH3Zl3zPZezNO2fp/VzjEywAzHRm0miZuRVwtDv0yVPHO6VavFxSRAg qK1+CXTu0YfT7NGhUMOiZXGzYeB1tUcQkpS9gvmctQPPovDG3nCzX16nJ/Ja+nLsXy92 v7rxFQSI5zdmcs3lj6WriaRSkvZtQpZ9qhwMSTXPEqaoE8REqdFwxcXACUeenKgV+8lc BKvA1h8PGzQZtS7P3cIqZDMNp9XlyE/ZHEhPSXgTx8xI3AeX0HxiXpqgSvCjjV09lP9V PCRPDr4vYDdOm/L6i/pEfZVrV5dfIIfBCoG0nZumXI69bib4KcsxVCZcw2I232ktTho3 dtRg== 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=IV7Qf0cMCO8k7+zO8JfKkry3J+Yr7pfmrjIzwuJecUE=; b=tYJAww/qeGOBaggN/Hsz8YuavEvIyrP4l4HhpQllggnm5sbGY5QE6EQrdZyzm2ptj9 a8UfQ4uBpWGJ2IEJ3ZvnPUmaggQKK4Y88N3mRJN9ahp+gCe/QrH+MxseRYPnHXDyAIGz tAo0ptiU+t+NUA+rVYVCfMy0goKK8HLQFao3ItSefOKLLDkJPIrNvfq5igYIrjp8fc6U GWxj0cL7KRxVQ3xqeDxgCsrhiYQMaLaTrUgf1OyptRgTbsmJO19bjqHNO6/Nmm/U519g ie6J6h01w3SomD8fx0I11EspQLn25msc6hKIU0O1L9kn06lp31NJliPoA0N1/Xl47c+Y 5RSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QtBgGs/R"; 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.18.02; Wed, 28 Oct 2020 01:18:24 -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="QtBgGs/R"; 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 S1753667AbgJ0OBY (ORCPT + 99 others); Tue, 27 Oct 2020 10:01:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:47692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753568AbgJ0OAP (ORCPT ); Tue, 27 Oct 2020 10:00:15 -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 21B0321D42; Tue, 27 Oct 2020 14:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807214; bh=JjFAo99wLYDWX9mwBwYWun0+eXHqmGfCOhVzOD6lR3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QtBgGs/RFE3hP92QR753yeWRLw+Ecm3h0DJgLlqBhnfOlCDepGw0hKWToDHSp7JJ/ ar4SbieebUc3SJ3hvcEiPRR7cwoEyx00uO50AOAj9221opmjKvOS+wz5th8Y3YlLQd 3Um8brp30RRhaz6m2Smw635qdLObLQlVcDAJHZNE= 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.4 084/112] media: uvcvideo: Ensure all probed info is returned to v4l2 Date: Tue, 27 Oct 2020 14:49:54 +0100 Message-Id: <20201027134904.516303348@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@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 0e7d16fe84d42..a0a544628053d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -242,11 +242,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 = format->bpp * frame->wWidth / 8; 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