From nobody Thu Nov 21 20:20:06 2024 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DA6345BEC for ; Wed, 20 Nov 2024 15:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732116389; cv=none; b=nfdRTo94ixIYUIap+AZlQPuDucYNG549LITtQf6hxoMHiqjqlmNFXaBmD4n6hAfsLZuL8otWBrTcdkN/VOW0DxrRvPmFMMouGmFPou0AkZrKPgUAjuiOTqTZAIJDzRnwXFrkzTNuLE54X7a4B38g2629ZWEkm0d+VI0COEtzWQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732116389; c=relaxed/simple; bh=28TVCm8cQpV09q+k2GaQ8E5UnNRGHov9tfjPf83ZwiY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SgCk8gEkwrieUFeKd4w0WIBzihkCYn3yO64wq59Kql3qGAJmMfYs4xHtRezHJv/V2ucpc+9akIlRUGpAiF/HfQlMZKDKNeiDJEZO8vd/w1UTH5wuplHnX3czHdld5OvNsYYHOC2YPF4hwrMtvcD15DUKkzweT2WrfODoDV2Ft5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=U5u/ebRg; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U5u/ebRg" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b14443a71eso375321885a.1 for ; Wed, 20 Nov 2024 07:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732116386; x=1732721186; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Nf6P9DIRJxG3HHqSkmc5bDC2kbomtLiZlCyebQwPqCM=; b=U5u/ebRgFnVQX6SRR3Aj1ayyV9xBU2oWAFvFdSEPQ25dHMaX0MeUYZkAKCHIBL9QR/ 9GR4e1ObbBHBZGj/LMsgUAAXdr1DEmpJmZ+Tl43ClrAVXmsl0aML89pBxeNgdZTzjWDA XXI79BG03+mYzTGDJwFUM+Y1P12dLUjqIjjc4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732116386; x=1732721186; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nf6P9DIRJxG3HHqSkmc5bDC2kbomtLiZlCyebQwPqCM=; b=vpvX5muXTUXY/BlmYxAJS+XNURypHa1LBQDJutiyllKiJ5XnccHPdqHvT/LwhCI8lV xi9xoKHy72nbhod8sf3wD/YeVe4o6zdRgPcW4kew+4+2sjMnWtmms7DrlBGv+H2JoH/g VU5mSfFjYmi3ZPTbEWaMozsa8QQh+REdUbdv7ay71fA7/47tFUe78Bvy2/ckyJAuQQKj gvVJNKzn0Ji1JWIfTYtJtMZJH0SFkIzxojrqrf/4sgMgDy4Px22uFfVmb6T6ySwjWiOC iWSEJ+TP+0Ctyr78lT4Te/YLjErInprj5u5O3JW9/ysNYo6iIicowT0xxUhVAZLR7kgv x18A== X-Forwarded-Encrypted: i=1; AJvYcCXsoLWKTR7ujKREgfv7CIhLrR1fQDDECwPuX3xPDb+lCe5jVVgkhz+TqvRkQhgnxpjTqB2s5St/w2+hELo=@vger.kernel.org X-Gm-Message-State: AOJu0YwEv++hw2EpQzaGXuWSp7QuhNco5leMEPvvKYaQ57gXGXCvbE+I jID5q71U7SRxo3iI4xr+5EzPz9rGB9bLB8NuSclPoBheGj02VPla1TWOxzZN6g== X-Google-Smtp-Source: AGHT+IFyIx3n9LVvSDGLaLi6PI8d2RhkUZLVsQYek4SUEz4fUio+9uekQYCj+qGy8K8NAK6KGh5juA== X-Received: by 2002:a05:620a:2486:b0:7b1:4fab:4418 with SMTP id af79cd13be357-7b42ee8297dmr350405785a.49.1732116386367; Wed, 20 Nov 2024 07:26:26 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46467fd76e2sm11207321cf.12.2024.11.20.07.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 07:26:25 -0800 (PST) From: Ricardo Ribalda Date: Wed, 20 Nov 2024 15:26:19 +0000 Subject: [PATCH v4 1/2] media: uvcvideo: Support partial control reads Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241120-uvc-readless-v4-1-4672dbef3d46@chromium.org> References: <20241120-uvc-readless-v4-0-4672dbef3d46@chromium.org> In-Reply-To: <20241120-uvc-readless-v4-0-4672dbef3d46@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Sakari Ailus , stable@vger.kernel.org X-Mailer: b4 0.13.0 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 --- drivers/media/usb/uvc/uvc_video.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_= video.c index cd9c29532fb0..482c4ceceaac 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -79,6 +79,22 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 = unit, if (likely(ret =3D=3D size)) return 0; =20 + /* + * In UVC the data is usually represented in little-endian. + * Some devices return shorter USB control packets that expected if the + * returned value can fit in less bytes. Zero all the bytes that the + * device have not written. + * 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 !=3D 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 w= hen we expected %u.\n", + uvc_query_name(query), cs, unit, ret, size); + return 0; + } + if (ret !=3D -EPIPE) { dev_err(&dev->udev->dev, "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", --=20 2.47.0.338.g60cca15819-goog From nobody Thu Nov 21 20:20:06 2024 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F4141B5ED8 for ; Wed, 20 Nov 2024 15:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732116390; cv=none; b=oUBEaYMDbcphOFByzjVAMOOV2JIL7prNf+yL4QWem6gUBuMToJLocU95ln//IFG7YdpKQgY/OoZcqVcfBnP7LR5Mr2sYw0vxYduG0k6e8AE/xXAaVnFOD5gRM8i8QziomrQhL3X8ekD1muev2qO8nIIk2Y1Yc35/PhpVdZiKohc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732116390; c=relaxed/simple; bh=0/4FckMiSiHC8QtZcVOi7l51C08TGrth+2RVMZNClRY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P5atsc4zicZRR2MTSMF8oKYde1ZyK6UUqWYIEutz4udH5hVYxCeDoG0e1VXkQIa29oKSfYJqdldaCCChWS3E6czB0vNm8PImw/mWMnIwoaKPfj1AIgTd1lKjV5q3X9s4zV1uzn67/zbttCgvNd9IRT9sssuxsHrH6h38RkKei1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ENegmwnh; arc=none smtp.client-ip=209.85.160.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ENegmwnh" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-4609967ab7eso14725321cf.3 for ; Wed, 20 Nov 2024 07:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732116388; x=1732721188; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qumhdBhQMcwMSA8xBYQJzlSmgMMJFlVuWwTimH3pwtM=; b=ENegmwnh/wxL2CVDXS6NAHLd2aS7So4nyDddeckKu7JzBh+6c7JWu8sGeqtDiPBLot awye9PKknV1gcH0fPZCgqWE6L+GFUBg4VZ41MgB6PHZWG2phTmd9nR75BPFWMN1rv/M3 S54oAk2XyEr1aZb1MoFEvj+adz/232+qkNJfg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732116388; x=1732721188; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qumhdBhQMcwMSA8xBYQJzlSmgMMJFlVuWwTimH3pwtM=; b=PlWJwvOgcDLC0mHWa/9w58oOLBNATZylWsVVfkeEJPsZlAcoyc7USVCE9C77CJarIK rU+TJKJFGO/r5x04z1vvtPHxjM+sIMHGAIrslRe9DmpBkSxaTZ9aPx6KIyw/4J4A5A1T HY2TBtUXHdJqyF/kFHWLa22W6CzJwGlyr0RllcwLLXkMz3kCUqAy0aMfi06YzgAT0W6O J7IXyGBr9kCbYbI4zr/2X5DLt/mrdwJ17E7rUWwUTyy7XbSe/s+2Pv03cd+SLpha76Qf elLpKfAJh/bdxOQXwI8swbOfnFi9wfnunWQLlFRfWtmL/p1mQwnqRD44FjEcKUxs8IWf JYHg== X-Forwarded-Encrypted: i=1; AJvYcCWduWvax+EAsUlpak0MySwAhZeik4WC5VMUTw5Fzdgw84qKWOCRrY6YAmD6daoiHM9dwYBayPcCRIw2uQE=@vger.kernel.org X-Gm-Message-State: AOJu0YxpFiKMJrzX9Pwgqq9ZIOmKFytviiSqP7HcSloElWo8V6NNGjtW yJc98EfaJIPwEpCs+EfTaagbI9jWNvx5OBUi7m6CZk8p/b7LF3mgVGbteDgdiQ== X-Gm-Gg: ASbGncv4VrJHlojP1z2ggW3R1CqCByst9xRWOWmVRng4JsMc1YT1CaYJFAjGI0BJiPe c9U/oPzkBZEVQMB9wV4yKSHMreOTfNIJ/duuzzfR9XRvq5BCIhvquvsuWwlYQS8dda4XZ1AyVWE bnwADmdKe0mzNG6w3s9XabM8ydK5InpnOElgtZlYhM0pbsQq+SyedkzaAUDCuSl/f9M6fx1Hi0I qeNaC1qkugZ2+5Yb66BIavECIv5y6GfiW8IdcntIY/R/+Fm/6ztCK4PkeO+PnmQOdaGDiNubrTk +3o7woUZeQlv5m7yTAb/wwKh X-Google-Smtp-Source: AGHT+IHPlAn+PtW4S65lZD+sW4FNYiPUzxXoFq72G2Q0cDPAJTNnHqS5O488xNRnPKLEVvl1B5oT8g== X-Received: by 2002:a05:622a:c7:b0:461:2a3c:c1f with SMTP id d75a77b69052e-46479c353f4mr37026111cf.52.1732116387928; Wed, 20 Nov 2024 07:26:27 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46467fd76e2sm11207321cf.12.2024.11.20.07.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 07:26:27 -0800 (PST) From: Ricardo Ribalda Date: Wed, 20 Nov 2024 15:26:20 +0000 Subject: [PATCH v4 2/2] media: uvcvideo: Add more logging to uvc_query_ctrl() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241120-uvc-readless-v4-2-4672dbef3d46@chromium.org> References: <20241120-uvc-readless-v4-0-4672dbef3d46@chromium.org> In-Reply-To: <20241120-uvc-readless-v4-0-4672dbef3d46@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Sakari Ailus X-Mailer: b4 0.13.0 If we fail to query the ctrl error code there is no information on dmesg or in uvc_dbg. This makes difficult to debug the issue. Print a proper error message when we cannot retrieve the error code from the device. Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_= video.c index 482c4ceceaac..00d9e3420fb6 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -112,8 +112,12 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u= 8 unit, error =3D *(u8 *)data; *(u8 *)data =3D tmp; =20 - if (ret !=3D 1) + if (ret !=3D 1) { + dev_err_ratelimited(&dev->udev->dev, + "Failed to query (%s) UVC error code control %u on unit %u: %d (ex= p. 1).\n", + uvc_query_name(query), cs, unit, ret); return ret < 0 ? ret : -EPIPE; + } =20 uvc_dbg(dev, CONTROL, "Control error %u\n", error); =20 --=20 2.47.0.338.g60cca15819-goog