From nobody Wed Nov 27 18:37:55 2024 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 47B701E0E08 for ; Tue, 8 Oct 2024 15:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399614; cv=none; b=qkxVdKDR1jq/18etEfl3hXkSkhC+N6/yztIusgCsgA4I638ZnfYav5eHaZ6pzXc8f1TkPP1u2frvxCfjrx9HwdIIazcSoy678sxYjyTQ165/6iVk4oNg11u3qsy4CZEpSzkEHSMrNTRBu9xEJFrKrwPljY6+0/xK/dmWXyXBAJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399614; c=relaxed/simple; bh=SPz+2k6qAmFkLhvmwfbYfGq2M1+gsUFHn/p094yCMR0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=liDvLPNPy4cHEfByO9dQnEzGePF+mUiMgN0mYt1LHyEqR87jeaQ+iyiep5gU9uHNjT/YkVrUPTiw/uNaRTacWVW8swAXcmdh0G9cP9w91rH3dYKYJx5zjpF0ahpts+A+KtOC6oaINs39nXyt2fcLsyEBe3Vw/5p9eINbDfXbpS8= 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=h30EQ2ah; arc=none smtp.client-ip=209.85.161.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="h30EQ2ah" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5e7aec9e15fso2819540eaf.3 for ; Tue, 08 Oct 2024 08:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728399610; x=1729004410; 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=SAa0sba5ecosbF6x+jnpQXFs+AOj18qlbA6Xv2h7TnU=; b=h30EQ2ahLw+54EH38sF9TlXatAqH4bCNN+T+5yTCFkUTJfQerA1rWtzg3zX4YeULsD 5qiz1EABP4KjtnYX1t1Q9tCD1ARSQEG7lYZR2fzRZTVc1tORJ/syX2j6zg0ewXe3Rx3U nHXvrt4UK1vkz49EBYNz6qWwvMPHdOF37rHOU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728399610; x=1729004410; 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=SAa0sba5ecosbF6x+jnpQXFs+AOj18qlbA6Xv2h7TnU=; b=n7a7mBV/+T/+/nPHHvKd1BUWR279pTJIBnm29PGkbXNhr9C5uo6mxY7YZz6C4xEhLP PZDbAeyXvS1bQ2E7o2MGBRi3ucOODYbuAY0B3Wd7E1PQo/vskMqMouqhJJk/FNanxD42 S6UpoDa5L0znDu27quacfL2iJBhr7YHIeapmTgZ1q916vULDc97tr4ZXVGTgzqBVtq8K dRi5Ze3axzWNowVtN8JnW8CKUA7LbvmQEdc+oHNDSnaiKmmGV1uzUCdvVzlR0rAuwN7Q sVR4lQ6rHb/XRDsd7CKOP0DSQdNyTh8t/55e469DekKoZRAIPBlsL3eeOlcVd6R2rFjg sdXQ== X-Forwarded-Encrypted: i=1; AJvYcCWmJNftjV+aMjo/3MGkg0tgwMMBtstu8GaDH5i52fhbqPZyLGxvvxr95OMOOZnyYnz9x8ClccsCF9pE6WA=@vger.kernel.org X-Gm-Message-State: AOJu0YxJ01ECgg1aFdNhC0suyumdVKAGurXUiFer3Dh4AisdUavlDljB 4y/KseKowQ6eagaExBhauA1wNqT63k1ZXcEqVJZtbOLh9qo8LaXbeZ8totrEeg== X-Google-Smtp-Source: AGHT+IHmKW/4ultjLfqxbrApmxornUzzwKpZiSN5cJiIHI/1zpG807eLBH18zRwyjwVVZQWDr2bxiA== X-Received: by 2002:a05:6871:520b:b0:277:e6f6:b383 with SMTP id 586e51a60fabf-287c1e16773mr9823991fac.24.1728399610142; Tue, 08 Oct 2024 08:00:10 -0700 (PDT) Received: from denia.c.googlers.com (76.224.245.35.bc.googleusercontent.com. [35.245.224.76]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae75762a36sm360886085a.124.2024.10.08.08.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 08:00:09 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 08 Oct 2024 15:00:07 +0000 Subject: [PATCH v2 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: <20241008-uvc-readless-v2-1-04d9d51aee56@chromium.org> References: <20241008-uvc-readless-v2-0-04d9d51aee56@chromium.org> In-Reply-To: <20241008-uvc-readless-v2-0-04d9d51aee56@chromium.org> To: Laurent Pinchart , 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 --- drivers/media/usb/uvc/uvc_video.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_= video.c index cd9c29532fb0..f125b3ba50f2 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -76,14 +76,29 @@ 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 + * for GET_DEF/MAX/MIN 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(&dev->udev->dev, + "UVC non compliance: %s control %u on unit %u returned %d bytes when w= e expected %u.\n", + uvc_query_name(query), cs, unit, ret, size); return 0; + } =20 if (ret !=3D -EPIPE) { dev_err(&dev->udev->dev, "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", uvc_query_name(query), cs, unit, ret, size); - return ret < 0 ? ret : -EPIPE; + return ret ? ret : -EPIPE; } =20 /* Reuse data[0] to request the error code. */ --=20 2.47.0.rc0.187.ge670bccf7e-goog