From nobody Thu Nov 21 21:32:54 2024 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 A1C181C07D5 for ; Mon, 18 Nov 2024 17:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731950220; cv=none; b=RkhNltrIDOT5j/7X7FtV1QSCPM9Z2IVFNbtdExp+FB7WITxShV3xWySIJh8ccEqYhQLM6evbmh+uUY57lxCu2usFDWp6b965ZUgPXn+R2FlOUsUo1IZGuPLw8hsvlYj6hef/66o3q00Vb9tLUsVjkjHAtFcGZ5Ek4HPyLAKeT2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731950220; c=relaxed/simple; bh=RCd8P7SWrd6FHi62rUrvFyQXQfEkY0e0c1mppU+Gugo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y/PfH1Esz7Ex1Ktz0pBDM/dz1VJvbor7jarCteRK9KzpPaM93b/THM/WCKA2ve0ZYxSODQCSfYdeqn4iKQTk9hmp8X5+3xYGuOR+theJA0n/uCQpjK+TmmOngh1/rY3dJPtJxYSHkisGoR/KHvYUkFNSzcepHdpvlsAz/5jwi54= 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=YiLfh2xF; arc=none smtp.client-ip=209.85.219.51 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="YiLfh2xF" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6d36f7cf765so22110026d6.0 for ; Mon, 18 Nov 2024 09:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731950217; x=1732555017; 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=gNFvjcIFE/tMdInr/XwnZIB54kAM691O9hqiQzfdv8o=; b=YiLfh2xFyjqkwSgE7Rsby9ATobVbrDPk0+cSYRzta+TZYPMEaGc6iis2RS3HR3ot2A Fee773bV/p1ioeH53EoflQRQHYAYH0WnrjO+9HHTyK+C2WAkRP+KmKAzKH65HJujlx5B eMcDrWSHu+zpAZbJU1Ik+T1dF6ZIb6vgg7iBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731950217; x=1732555017; 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=gNFvjcIFE/tMdInr/XwnZIB54kAM691O9hqiQzfdv8o=; b=dkLp3fh9/op9Sgp/8F9YEHO1KYx+uRmdh/5PPGp7+E09hRFQVeihgDkYtseKmFzhYT EM8fr+v+myUZCb79f5rp46FWBpSstwztJfVsusr/eFk5DnXzRFXezK4EBt8J1pbEIB0s DfT7rkglc2mppc1sMaYzLeeJ6pKP9/d2wG/TP1x5Fk2dhWFn0qQvZ0Nc3UPdnHXgIJ61 DdEXCfZN2W+TDoqmew9II5XUsLXa+uMeqzE+p1MqCvhoNV3qJKIbR5cebYUNdm/CsMhz VvXwDXDGIiuok2TE+dpcA5b5AbHe6HC8UdxGC0rfvJi+d707ZM0AXQEiuPPODWlsAX94 OYPA== X-Forwarded-Encrypted: i=1; AJvYcCUzjgcF4PAX9viWXPEYYLGndnIy4+TiWa0Fs7kX4ZiJzjDnVNMlA43ZWjaZ7kaH7rHIB70reJffKxWk42c=@vger.kernel.org X-Gm-Message-State: AOJu0YzYFFfGm1DtPJl8xvYqzD9XiVFi3OtBlWfHwHJXtfjxa7WtuSnJ rggTsW3anZ9wG9DsVTGlkrqiQKxp1tE5Mzlj4ZZJfTULB7m51M57ruo96IXhVQ== X-Google-Smtp-Source: AGHT+IGOkU43Z9UJjXQsK/gUo0QuSRiC01AYZTqd+ZFfoEVojsBB8wlaF8j84jOLMRBqVEuwdeRqmQ== X-Received: by 2002:a05:6214:5001:b0:6d4:85f:ccac with SMTP id 6a1803df08f44-6d4085fce05mr160427536d6.13.1731950217630; Mon, 18 Nov 2024 09:16:57 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d40dd733c3sm38255246d6.97.2024.11.18.09.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 09:16:56 -0800 (PST) From: Ricardo Ribalda Date: Mon, 18 Nov 2024 17:16:51 +0000 Subject: [PATCH v3 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: <20241118-uvc-readless-v3-1-d97c1a3084d0@chromium.org> References: <20241118-uvc-readless-v3-0-d97c1a3084d0@chromium.org> In-Reply-To: <20241118-uvc-readless-v3-0-d97c1a3084d0@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()") Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- drivers/media/usb/uvc/uvc_video.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_= video.c index cd9c29532fb0..e165850397a0 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -76,8 +76,22 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 = unit, =20 ret =3D __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size, UVC_CTRL_CONTROL_TIMEOUT); - if (likely(ret =3D=3D size)) + if (ret > 0) { + if (size =3D=3D ret) + return 0; + + /* + * In UVC the data is represented in little-endian by default. + * Some devices return shorter control packages that expected + * if the return value can fit in less bytes. + * Zero all the bytes that the device have not written. + */ + 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; + } =20 if (ret !=3D -EPIPE) { dev_err(&dev->udev->dev, --=20 2.47.0.338.g60cca15819-goog From nobody Thu Nov 21 21:32:54 2024 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 D00011C0DED for ; Mon, 18 Nov 2024 17:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731950221; cv=none; b=a/MpepQ1s0AsumneuDv36hMQZSriGmVWx7+32kBG8MDrDrIk8/KGRAxPH3x10v+WvISIBiP+D+fuu1EK46JMVUawPj6PfK3brFkufs9xOGDx/2hwVkOo2OkO6xVdV5K9uP0dZUzp2Xg2LQMw1Ot9RbqiHu6GmIoR5pG6eHn3Ot0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731950221; c=relaxed/simple; bh=A5tEeWedtG0Y+rutx5jNpOYlvPw69q2OPMca4sA4STQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DuQqBJDvIpPbBSrRI93fn1Woa/RkOfOSz6h63nmOes/en7PJ1g+C1nV/AgK2AhWj9TfzQLW9E4THEYuHM0xsaOyr9WRBNTHI+x/ZB6KcetS2sqfrxNSvaYAJnPZMcnGtRfGBKssaFNtJNyshbjoJjA/Uz8rQqUaVUCo3gJ+y9sE= 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=OE2MIzeM; arc=none smtp.client-ip=209.85.219.44 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="OE2MIzeM" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6d413def36cso22244516d6.3 for ; Mon, 18 Nov 2024 09:16:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731950218; x=1732555018; 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=nZ30sDfZ/stXUDJszdPegRDEKjQSfHFQOt3ymhmzQbY=; b=OE2MIzeMPum3EvO3y/9PueYnRDFwE/miApRewgduRymSNzo50c/q7QlpAjqOO9CRSv E/Pmef0Rv+sDN351xDbPKNQUR+iYduZL63OIT1PFByi8iM4PaBCXDV3MOfzIlesdB+XM 3AQWME8ZIUazUnDYKGGUJRgnKuGOy/7wPGVl8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731950218; x=1732555018; 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=nZ30sDfZ/stXUDJszdPegRDEKjQSfHFQOt3ymhmzQbY=; b=H58wMugTFaViKV523lHhJdS/vrdOa/iHFs8Fj3ITmX5Z0j+non460ak4rPQgr5kZzk QY4csu00FDU/QQy9jqsm/QfDrV9SF0XnmL9FEGY6BUYghprF0Oti6d9yPC2eMEZN/f1J qWo4CDL7nglY4fGCxHng/oCrsPRU67nP2lFu1tP9NnWr9wjI6ykYs/ujZhK1GVwKMlWy z9rGtQwWEwGS5vaI1aJG4ANVIr1MmigrDfGEtk+TQB5XKbU6Noiyg61oAJE7thuQxin2 m1pbLKkLFjuqZY+uAKOEh1QAd0np/Bf5hOT4Y6/Z64C5pZQEpKm0C5eyfpXk1lypDdkH qOMw== X-Forwarded-Encrypted: i=1; AJvYcCUa6sQ21qTCSsXVgbT+enLykd4CnsjM9V/zvsZE3AQ30NL8RXyGWMxFitfMkMqVLFUwxpMOjkEKW/jgLKY=@vger.kernel.org X-Gm-Message-State: AOJu0YwLJRENVWWPeCK6bsdiPp8sW8uciRBYt1J7gQc0C1MUTLfCOkLI IfHINkr86VF0Mi87t/HpofJSTY6W/NHRo333zvcUS5p2qai1/9hkTu9uY4n4ih+2i9gGqSfTJig = X-Google-Smtp-Source: AGHT+IGaNZV/qqJqHa4tiN/uf1zjGJjsroAU+mlkDujCrCE4+KZVeNFgCEheZGGSpyliMGY3+QOMAA== X-Received: by 2002:a05:6214:3387:b0:6d3:7f9c:9e51 with SMTP id 6a1803df08f44-6d3fb7ed418mr178431086d6.20.1731950218592; Mon, 18 Nov 2024 09:16:58 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d40dd733c3sm38255246d6.97.2024.11.18.09.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 09:16:58 -0800 (PST) From: Ricardo Ribalda Date: Mon, 18 Nov 2024 17:16:52 +0000 Subject: [PATCH v3 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: <20241118-uvc-readless-v3-2-d97c1a3084d0@chromium.org> References: <20241118-uvc-readless-v3-0-d97c1a3084d0@chromium.org> In-Reply-To: <20241118-uvc-readless-v3-0-d97c1a3084d0@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. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- 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 e165850397a0..0195394e10b5 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -110,8 +110,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