From patchwork Tue Oct 8 15:00:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13826620 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.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 552A61E0DF9 for ; Tue, 8 Oct 2024 15:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399613; cv=none; b=YHsy/aTl7DynuvPeCugXdQkSbWyinnWpngSZ7R8+i8KSvYp6ypWKBUEQchyJRorZNULZx3xzwy47luX8RKDy/2cxRjHzAQ/SiwNuLKvBQ2TkEsIq4Bbcgri6XKZ7rBQzzS/OOMIpEZ5U/WDpQAR+4OWemkX0oLF5BQf9YlqeBDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399613; 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=L/s+60VYW6ejAZjI0Du8jPxsy8YIYiHGIAt5NnMxH2H9CU8DU3Yl+7uedBtTziLBU24mgc+H2vJaqypNmtHt0QOjGNlxuzYvBOAVZDwJvQ/eQJORrgwVmotgDzruDsiZLjID9dBrqHKLzZtDiexOL3DisvaihPsm0SNyWNmqTvc= 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.160.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="h30EQ2ah" Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-287148a44f3so2753295fac.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=Ur/1SheGf0Ep4nZK9F6QSrNjCkzumB5jkC9n03wBcIfiNwg1M8KDZKwhixjkqpY0P1 Q9gWVTDApAqB7MRbxvmgAb1Yky982dZmekiS/SJ0Z57HPZ2AI4pFuPlyzCQUybPLH5hO +ATBKto9MXxh7+HjN5n5WMHEMVArb81IvbBVt+A8qthSyXvZ34pok2TRwML82T77Lj0h 05AZLIYTsbgcljru5yzjrUiRemro8cB66XxoKatT2EWfPXOTjsHOAGaZNwdalwQSwuJ1 UhjFdkZBSaCAPnrICOYCf90ip32eZBXy1zjASOwhWojJi+4q1kGEfX2bw7W/oyFV/XFz L4Lg== X-Gm-Message-State: AOJu0YyO7OCAB12sECvEPBVhhfeYgBoTfaOx3JxMiRNKd0oUvNCEbGOs IwpDyuETEomqKaQ3T4YJvvCe2epm6qJdG2j7zNVaV+3HHJkbMSezkhYW56KvaA== 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-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, ret = __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size, UVC_CTRL_CONTROL_TIMEOUT); - if (likely(ret == size)) + if (ret > 0) { + if (size == 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 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", uvc_query_name(query), cs, unit, ret, size); - return ret < 0 ? ret : -EPIPE; + return ret ? ret : -EPIPE; } /* Reuse data[0] to request the error code. */ From patchwork Tue Oct 8 15:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13826621 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 A67751E0E1F for ; Tue, 8 Oct 2024 15:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399614; cv=none; b=KXS6o3TZj2JaDVCZjveJc9PS/rUPUY6laSQA4zxlFhIApqtBTd7UR0+DGQlT6PMJyjaB39DLan7yIFhPy5bJlAqqFAkp0xvp9wbCUU4ueTLqaF8Jmf+pdwQdCnNGFk80LRAnGsgesI+/+W1vMczR+IXSZ/wzXkcrRHtwpDdMbqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728399614; c=relaxed/simple; bh=pvyPWsToTZtRlgvmX7LMTSxDbnGxM8D+iYsUDPJR3zI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YymUB6kLyrz51MZsKN3SYRwGFUxwpnhNdxuvkHGyHwSEipP9EoKCO4viXz2NJVojfSHxbprbDeXSBuherbx7ddOxarCrwVIAxZjOeW5YujNRPLZlICXWRoDgUzXX27x5WwPhmU6yBjZelHOYI3tmwQhK0Q1YseheEbVTCUoHV8Y= 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=fcz2s1hy; arc=none smtp.client-ip=209.85.222.179 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="fcz2s1hy" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7a99fdf2e1aso796606385a.2 for ; Tue, 08 Oct 2024 08:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728399611; x=1729004411; 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=uCWa9i1F2c8oRuwsqOTxWxy2qXb4GIjxtma/YuRpfzQ=; b=fcz2s1hy66U4WVHN6J4+dFtg0LyAw46ZZ+oJgxpLstkeMnqTC937ed20jLqrYuud6z oHQowi57h7/V5kUtW4me9b4CMbqXmFNeMb1caUJ3l/6HGMOSiZY+1Tz9EBrWFaBpCCO8 0bFh5SMRVFDhfRohOk7yFKq4gUaaLcFu8lqWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728399611; x=1729004411; 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=uCWa9i1F2c8oRuwsqOTxWxy2qXb4GIjxtma/YuRpfzQ=; b=ISU4IJdKQEnwNPqkK3tozz2uOsW9xelw9ljcOogsa9Ug8rTBPuHLrxUGaTgZsvUkBq FwyjhllSRVHnxeB4iTO6ov5N+B8w1umYvA+N4BFswyAu7N3ASRZBPi+8+ouDj4aQS4we QuoR/zsXqxAhT2tkyJyFEJy5DeUIO40G/RhnYPCK5wNbdlpKsutIUYXCZcU6DxsFYCc2 t150bRCICSEUWcrDlH7cN97zoqNoeRwkdBfiQ8BnLRnZS9t8ITHdb9gTa6YNTEfyq2Bs Dmy05ynGoWRbHLoQ5TuoTRN6u16Nwr8VC7evKv5aZrWBq1tJBUYbcwmoyDCw9eZDGAOj PVbw== X-Gm-Message-State: AOJu0YyEh9w+cXCKs7xxoDaTL0x0C2qlht5GPZGfEV53B+A9lcfyal2E utS2I36EZCp/06hOuZZyN1h6jVCE7izTiunoIjQtrLK4fLZtjKSBpoo8zUSlug== X-Google-Smtp-Source: AGHT+IG5PsXIAlrZHuvZt4cgIpu7/vve2DpwC1FBFLl1/3rpAI6lcB69ZNNqDPmjs3XOrOpvCATW1Q== X-Received: by 2002:a05:620a:2952:b0:7ac:e869:b073 with SMTP id af79cd13be357-7ae6f49f5e8mr2806863885a.63.1728399611473; Tue, 08 Oct 2024 08:00:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 08:00:10 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 08 Oct 2024 15:00:08 +0000 Subject: [PATCH v2 2/2] media: uvcvideo: Add more logging to uvc_query_ctrl() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241008-uvc-readless-v2-2-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 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 --- drivers/media/usb/uvc/uvc_video.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index f125b3ba50f2..6efbfa609059 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -111,8 +111,12 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, error = *(u8 *)data; *(u8 *)data = tmp; - if (ret != 1) - return ret < 0 ? ret : -EPIPE; + if (ret != 1) { + dev_err(&dev->udev->dev, + "Failed to query (%s) UVC error code control %u on unit %u: %d (exp. 1).\n", + uvc_query_name(query), cs, unit, ret); + return ret ? ret : -EPIPE; + } uvc_dbg(dev, CONTROL, "Control error %u\n", error);