From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F289570805; Thu, 13 Feb 2025 15:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739460794; cv=none; b=pPnbZfCikY968jmJWd0twhdBj7v0d54Ne0rTwikxi7y+onaNxUOtbQ9JEt7tNWV/LOoblcOvujz00kc+nsEqCsukOP3uFAD+QndXeP8sBTGpxNhFZ99nMmgnbgKqJs4minjQBzKkoe+qZG2guSn2a6r6StjRmqMlOVyVvDDNx38= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739460794; c=relaxed/simple; bh=+l2eoyW5ajj3XqZ0YJSBEEJ4opVEAyyyGhP7Gu+oLh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dbl3pZF1lbM8wwG3YsQKJ3OKsIXMOnmkvzcOAM14G71z6Zcy4bh93tVWF5olcFUYBZ00oHGnDxEnJM0YodNhG1cL4G+5CxRiv8/xLuOuV7KdL5uD115TxN2fD0uMpjTAhJ23BDhzyjT/aWCwScgxj/BmvjqGg11g5Ge/8r8cKSQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IhDJDZfe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IhDJDZfe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0122CC4CED1; Thu, 13 Feb 2025 15:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739460793; bh=+l2eoyW5ajj3XqZ0YJSBEEJ4opVEAyyyGhP7Gu+oLh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IhDJDZfeWt4HiQaejSeOfQ4G04pxoz5sw2eUzmTJwrMuiYV+WQb9to92sI4BxlD55 UzFNHoc7iPQfyDWHuBhWbKlnRoeRvFaE7+H1pmXrZrg+peG4134+bYuZ//lYOXA0vI RdXTmBDhUxvRSQIcXvJXYSFTsyLT80f4g/K5wyOE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hans de Goede , Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 6.6 215/273] media: uvcvideo: Support partial control reads Date: Thu, 13 Feb 2025 15:29:47 +0100 Message-ID: <20250213142415.808763717@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142407.354217048@linuxfoundation.org> References: <20250213142407.354217048@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda commit f00ee2ca8da25ebccb8e19956d853c9055e2c8d0 upstream. Some cameras, like the ELMO MX-P3, do not return all the bytes requested from a control if it can fit in less bytes. Eg: Returning 0xab instead of 0x00ab. usb 3-9: Failed to query (GET_DEF) UVC control 3 on unit 2: 1 (exp. 2). Extend the returned value from the camera and return it. Cc: stable@vger.kernel.org Fixes: a763b9fb58be ("media: uvcvideo: Do not return positive errors in uvc_query_ctrl()") Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Link: https://lore.kernel.org/r/20241128-uvc-readless-v5-1-cf16ed282af8@chromium.org Signed-off-by: Hans de Goede Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -79,6 +79,27 @@ int uvc_query_ctrl(struct uvc_device *de if (likely(ret == size)) return 0; + /* + * Some devices return shorter USB control packets than expected if the + * returned value can fit in less bytes. Zero all the bytes that the + * device has not written. + * + * This quirk is applied to all controls, regardless of their data type. + * Most controls are little-endian integers, in which case the missing + * bytes become 0 MSBs. For other data types, a different heuristic + * could be implemented if a device is found needing it. + * + * We exclude UVC_GET_INFO from the quirk. UVC_GET_LEN does not need + * to be excluded because its size is always 1. + */ + if (ret > 0 && query != UVC_GET_INFO) { + memset(data + ret, 0, size - ret); + dev_warn_once(&dev->udev->dev, + "UVC non compliance: %s control %u on unit %u returned %d bytes when we expected %u.\n", + uvc_query_name(query), cs, unit, ret, size); + return 0; + } + if (ret != -EPIPE) { dev_err(&dev->udev->dev, "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n",