From patchwork Tue Dec 10 22:22:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 849589 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.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 731F91EE7B7 for ; Tue, 10 Dec 2024 22:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869353; cv=none; b=Fn5REw+pUN7Uw3Ox9bouN/TWof+rbzkX3SHM+oDsCgSXKWMzLskquyWzaRzyaLT5695Clk6fwTo493R2kO7ZBtqQdXI/cjm6oCTVPo2n3dIqyjL6t33y+k76T9IhCeprG5bSJJ6yCfJ/QInJfe/Z2auWpRHlSfO8nPvJMoqOjKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869353; c=relaxed/simple; bh=yv8i9nHRCz0vaaoDZJOFBzaD6vQsxKrtwXv9v5tS564=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HwRNxFPkiGfpb4AT1NvtxSukR6cCZkEznsccDm9fYXvZUh3IoUM0k5Sik07VrKrLDHPVgESASO4QfDoo5OeMy6KqnITOipbtkLvynY4qI1asEf1ncTOMpO0yC6/6/m0O17kBgyfOWLXaHYBLcW2E0MV9RaL+YJxj4hw6KAevue0= 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=V6VEKau2; arc=none smtp.client-ip=209.85.160.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="V6VEKau2" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4677675abd5so8384451cf.1 for ; Tue, 10 Dec 2024 14:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733869350; x=1734474150; 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=MjQrugQYBz6Mf6XUxcZGSynpVjt6TTGZxVran2d8wNY=; b=V6VEKau2JlEXpdNMX38GBleTMYLXS2qBISlYRzGRklwl82BCVU5rvMSgYG71sB56EI pccp02n4V6Ho7Ma9zjKsYo56JgwV2WpyfJbGz7QRrCqK0TkQsanwxSEL27jhWhOHsVrU R7VDptPY2IQROe32yrN558AsZ3hBFNj1kpOFc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733869350; x=1734474150; 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=MjQrugQYBz6Mf6XUxcZGSynpVjt6TTGZxVran2d8wNY=; b=FJOEiETO52j6MD4bAwdfXULm6wKCQQhT3sbeSa21hcYgux5pZapFAOYPQfgJUSH2aM EW3MW4jSMO24fB4G3Ot0EYdsYKZvmDrMTV55sUpaSfeBEE1t0sE94fRepqAZHvTqpxwP 2JMTSbWFybcJIg2MyletZDFsyeCehVxGGVeXM0KkMgawe8oSvrN0jufI7sWuNMTXiRDG W9V2EkI95katcjPWSVTHPVoZk+0ZwfQCx0IdxWbJH4swfUSHorssO5N7xTYGb0+3zQbu FoYKZblxbCrYJBZ7S9fxjlyFpfo1zMiXRyF7JZcGSOO1iY06xzPxRgK5P8mJEG0VC/YR Sg0g== X-Gm-Message-State: AOJu0YzrLq09YTbGvCnjSbagwBW5RCUSenpB699tS6PYC87Pf37pDGxf RzMOPk0cWKYs3oErNblPO9m8kx94+MuAp+fCi53XJ6bYQ/9g3yqpqL2IOIUfioC9dm1rimSeu7k = X-Gm-Gg: ASbGncuAWL7j2MRNxF0aOClPGMqTT9/aD7mXHoDmj4HM7uU1q0ibi32sFPJQZYCCR08 1ccSiTk2nbmMQX5FtQYnARyF6yAa8Hx6FQFjyJqUgv4u8EQkI81KhHJUzlvE/rW7cmMAHFqwrNF mYbA8/WEMPfViwOW5XhMci7hO0R+TYgReueHQY3mzAg8fOLDVqjrJB9zwGbcKnVQQ61/TinfOu0 pbxpKtNlVV/ddW80vUxghV6b2duPqj8mxfUixAuakz+PknqXzIhAF4iES0znMZFZXJDeOwYqTOB obxivRCvAwzxnEgjzI9NZJ9yhjF8 X-Google-Smtp-Source: AGHT+IHXwNu2FHsl5zNm8GOLrnsaIJdyyD8xiUqBMDSYEmUuoHOfVqx8K6rcdS/IDyFjgfPy+EAgKA== X-Received: by 2002:a05:622a:1187:b0:467:1e96:645f with SMTP id d75a77b69052e-467892ea223mr8140481cf.6.1733869350436; Tue, 10 Dec 2024 14:22:30 -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-467776034b0sm11232441cf.74.2024.12.10.14.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:22:29 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 22:22:22 +0000 Subject: [PATCH 1/3] media: uvcvideo: Return the number of processed controls Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-data-backup-v1-1-77141e439cc3@chromium.org> References: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> In-Reply-To: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@kernel.org X-Mailer: b4 0.13.0 If we let know our callers that we have not done anything, they will be able to optimize their decisions. Cc: stable@kernel.org Fixes: b4012002f3a3 ("[media] uvcvideo: Add support for control events") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4fe26e82e3d1..7e2fc97c9f43 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1810,9 +1810,14 @@ int uvc_ctrl_begin(struct uvc_video_chain *chain) return mutex_lock_interruptible(&chain->ctrl_mutex) ? -ERESTARTSYS : 0; } +/* + * Returns the number of uvc controls that have been correctly set, or a + * negative number if there has been an error. + */ static int uvc_ctrl_commit_entity(struct uvc_device *dev, struct uvc_entity *entity, int rollback, struct uvc_control **err_ctrl) { + unsigned int processed_ctrls = 0; struct uvc_control *ctrl; unsigned int i; int ret; @@ -1847,6 +1852,9 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, else ret = 0; + if (!ret) + processed_ctrls++; + if (rollback || ret < 0) memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), @@ -1861,7 +1869,7 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, } } - return 0; + return processed_ctrls; } static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *entity, @@ -1910,7 +1918,7 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); done: mutex_unlock(&chain->ctrl_mutex); - return ret; + return ret < 0 ? ret : 0; } int uvc_ctrl_get(struct uvc_video_chain *chain, From patchwork Tue Dec 10 22:22:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 848991 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (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 D30141F1905 for ; Tue, 10 Dec 2024 22:22:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869354; cv=none; b=iaYP3m78Rc9GI7aqXZ3wFfTQ+Hai3C/O7l86IAfQjIbpbeFOhbmrbbyPTbBMVcYELYM1dBsJ+JV6xonhbv1nhvTHlxdzKZdolypJcc41vpr0fkuufGQfizFH0Gd3SnsB9Y0/4W2T2JvC/Rduz3kl+BIR86x2NvLUPc7Tog6Dqp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869354; c=relaxed/simple; bh=K72388Mo46bPaPYonT5jJ6Lw47MWUey0RMwa7LB7+rA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HLixuU53hoJympBNQCQovIXFny5SJT81c4nMgMTBjmyDY9q0/RtHEftCP5GrkiCjoNshqAgcj5l69FPxMwBg+KQzpHPKyFE5/Jt4O0h+N++/8X/7nkyGeZU9zFcu+UJmTWjLASqAcntoKz+EYrgDTK4IicR3SD8bSCfQ66jnZ4w= 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=ZizVTI5a; arc=none smtp.client-ip=209.85.160.175 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="ZizVTI5a" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-4676859b911so20436191cf.2 for ; Tue, 10 Dec 2024 14:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733869352; x=1734474152; 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=tJLKxDvZkcys4CNhxAUoQwbKiFgypyACQZbRSa8Ir9s=; b=ZizVTI5a/DNfthesS7iIWDxpaRQfpXo4AiqT18JO7TPnDp+HCwawjlk9OvBgqhGxEb ie6ODoosk99RBcC6dh+MCvIMA7NLUYRKA++E647UOuJrn6/PsVFF5vGZGywKFDffHA9y NwIFfRFG9eJVrYFLWKSYZnjWVkaqJa02hONX4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733869352; x=1734474152; 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=tJLKxDvZkcys4CNhxAUoQwbKiFgypyACQZbRSa8Ir9s=; b=MJJcBYzOTHjhq0YUROS8CLizQ2iBI7B5pt2zLjs1JlkIJuOrpngNdFaajys3yOhw3y UGCm7imMsP5KrtGGf9WNZPrSIuHWVugBFmfU6jANzpG//Pi0iYMo9udHI91hrersT6DH OUAgwDuaZ8yZ9jy7SqJwV7M0eHoOYz6TxX26vlHVhcCT7+1sZS4ZhaCuX8b0XLBeP08c 24t4oTwHtHyLHQl4f1JIE6jdohXq47R5ZCxKtGC3J4kEDUgOXFoQMjmZWWmWMRNRf7Ta hSLwrl7/vQqbVW5/xObPD8TtlABffmLXCupOKyHRIBHW+2ksse18DeFfek6l8Phksu6q f6iQ== X-Gm-Message-State: AOJu0YxMOCJA3+KZo7GBNn/VkzzJeYy+GTKiuJ8+v4dK2CM5kbYZg6B1 CxqtH71rND5UG9NxiHQR7J7Sxew3PMhW90WXUjOr1xk99psNFUWCr62BaO9KFA== X-Gm-Gg: ASbGncvUI+L+yoalkhKo3zzM6iQjC3vFu++CIE70Zyn//BzKfWtBJhBWuBE0TOezmpq o7SNYFhjvMwonE49LMtf7hojcON1A2eG270T3qHY5DqOuWOVPd6xbcW2IFbn5gL5xR/lqZxAUYT 3SCeHPSZC4q43iLHIPiT1hWkc9xyRvlYOICYqx5jl7ypw9kQsRBBoLmtumDlys9FxnBIQz6tSO2 hFe0Dklm3B9vsAnj7Jp7+6wYAfbaGtWqI9B1ocBm+KPFEoBLHtzJMPECMWBKQ2U6YKuQdvCsoWt qMbvlJ1syvuLRKVCWz8AHSbQa7Fc X-Google-Smtp-Source: AGHT+IGwaoCAcWJN2GJxUO5RU2+RMPWc2ZQl9JG0CXgAkbSPwqLMrUX3CS7unfn384D0Zdx4YTo8rg== X-Received: by 2002:a05:622a:5448:b0:467:6833:e30c with SMTP id d75a77b69052e-46789309cdfmr11188201cf.30.1733869351829; Tue, 10 Dec 2024 14:22:31 -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-467776034b0sm11232441cf.74.2024.12.10.14.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:22:30 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 22:22:23 +0000 Subject: [PATCH 2/3] media: uvcvideo: Do not send events for not changed controls Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-data-backup-v1-2-77141e439cc3@chromium.org> References: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> In-Reply-To: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@kernel.org X-Mailer: b4 0.13.0 Only send events for controls that have actually changed. E.g.: We are changing entities A, B and C. If we get an error while we change B we do not continue setting C. But the current code sends an event also for C. Due to the fact that the controls are grouped by entities, and the user might group them in different orders, we cannot send the events at the end, but when we change an entity. Cc: stable@kernel.org Fixes: b4012002f3a3 ("[media] uvcvideo: Add support for control events") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 7e2fc97c9f43..9496ac970267 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1669,7 +1669,9 @@ static bool uvc_ctrl_xctrls_has_control(const struct v4l2_ext_control *xctrls, } static void uvc_ctrl_send_events(struct uvc_fh *handle, - const struct v4l2_ext_control *xctrls, unsigned int xctrls_count) + struct uvc_entity *entity, + const struct v4l2_ext_control *xctrls, + unsigned int xctrls_count) { struct uvc_control_mapping *mapping; struct uvc_control *ctrl; @@ -1680,6 +1682,9 @@ static void uvc_ctrl_send_events(struct uvc_fh *handle, for (i = 0; i < xctrls_count; ++i) { ctrl = uvc_find_control(handle->chain, xctrls[i].id, &mapping); + if (ctrl->entity != entity) + continue; + if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) /* Notification will be sent from an Interrupt event. */ continue; @@ -1911,11 +1916,12 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, uvc_ctrl_find_ctrl_idx(entity, ctrls, err_ctrl); goto done; + } else if (ret > 0 && !rollback) { + uvc_ctrl_send_events(handle, entity, + ctrls->controls, ctrls->count); } } - if (!rollback) - uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); done: mutex_unlock(&chain->ctrl_mutex); return ret < 0 ? ret : 0; From patchwork Tue Dec 10 22:22:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 849588 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 0F8F2211278 for ; Tue, 10 Dec 2024 22:22:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869356; cv=none; b=J/UKAIO3bJDUANmvpfuFLLYkJZinHyBoVhjBJYE4oTO4oTPKl9gAXGjHXciSqiiS72uWAabjSHUYR4qzmjlfMPR2A7wC58hghFJb+n7HRz/SYVXfMbWB1MUbzjFto5GWQpHSoy/MxQelIrStzJ4r2JbqxXuOulT2hi6dxGb0ZFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733869356; c=relaxed/simple; bh=D0ZexnELTKVfQSmyeA71ynoDvywobwhOrZ/0Katurbk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TOaPcd8kDzEvdOEEuaD9avTb2A4T3vDQk0CWla/wRxCYfrLwh/Oo7SDTYqMtq6chHOyqrvSECs8qVEZtxLDL/T4T5sdTZYNSOzfY8lhZbR5X08v42fOjS4m7U7fAiGZoeYUh1bV6g5J21MPJleOCiNYBsuWvTXKOtXAFz39z8uQ= 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=YAXYICRv; arc=none smtp.client-ip=209.85.160.180 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="YAXYICRv" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-46769b34cbfso35129761cf.0 for ; Tue, 10 Dec 2024 14:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733869354; x=1734474154; 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=kcafMw9Z0U3vF7FScCVFpDYTrMToPYmiLDGfXKQJyjY=; b=YAXYICRvgicHaSE72QRN8t/j9+S1e+f832n3k+6VXCMXRCYMWSzIl9vtDm2SxcV8sZ CjLym5feYxtUQ79KHOHXhzn97o7QSE/gYcx6evnlaywxy98llZrt8xNnAxwihLKUOXWI UTnzwDRmRs/ojbOWEqBTsCtbiNUONvaSYQWkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733869354; x=1734474154; 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=kcafMw9Z0U3vF7FScCVFpDYTrMToPYmiLDGfXKQJyjY=; b=H6UOt69cCVZ/d1cvVXY2MKce3xk2oEpswW0NdOgnZuDAT3zVvPCAitbGDV2pm0hoe3 QjS/+z6FI1fSpZniYicpdPLZxNpGbjaWFXv7t5NY8gi7n+jAQkCn29t9yF4oZLcs8C8R 8bLHSypjvVjM/zhn8Abo0PD8F8d/uy2z779u3dy2RskaqLDQxKPnwfG2TB1kbrmcvbOY Twj9zUwtPdI//bHbaZyCtcmDc0PV5kfyo12ZxEE5gnDoN5aidUGX9jg5/zGGcYpsR08Z /ujAcwZWYE7EyyOSD9/4+x5PWNf9XC4grGc1dBKBJFE9Ii1G8nZvCijX2Bc57bSnH/36 iPtg== X-Gm-Message-State: AOJu0YyU6gd1gJ5FMNamiiNOt1mGCSMJ9e1tRQV6UxfkikJy11cbNGp8 2PxbktLqtWGfp1Bctpt+ky+MQK2R78yoIZzSNscY93MlkXsEPSutblKfTJgSJA== X-Gm-Gg: ASbGncvh7v8kjrXmo8xZwKJoIRjodesvowNzfgf9g5L6FaBWiTZk8t1BeG6DzZaJwn8 zW37Ox1tTxQn9gWMWeXwrUm3Pxe1pV1p6OISFtrR6uAeQcBAiqJxXd5nYrgUQg8ASOqTzcwYgSY YyRalevaSb9WEq2Jbku8xEkcXYzc0jfXLIHNvoiNLmYWLvyrQdlFW+id8f5F/aYAcTMZ/wuNH43 xNGfQPVC0P6k50NmlNOKErOZcmsV7uyzmtZcArJmjRYPShmhHmpI70Fud3N4SzOj4hCdbNEyxLM nD5qp+AQ9mtbLimbfilve0ivq2rR X-Google-Smtp-Source: AGHT+IGo9/Hxonb35H4V5LFXpS6P8ognfkxmBy4lOIHwm8Bg86/UKY88TGsyICxmZNUCI03BbZfnNQ== X-Received: by 2002:a05:622a:1b16:b0:467:60a8:8a9d with SMTP id d75a77b69052e-467892932e9mr12907201cf.8.1733869353966; Tue, 10 Dec 2024 14:22:33 -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-467776034b0sm11232441cf.74.2024.12.10.14.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:22:32 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 22:22:24 +0000 Subject: [PATCH 3/3] media: uvcvideo: Rollback non processed entities on error Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-data-backup-v1-3-77141e439cc3@chromium.org> References: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> In-Reply-To: <20241210-uvc-data-backup-v1-0-77141e439cc3@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@kernel.org X-Mailer: b4 0.13.0 If we wail to commit an entity, we need to restore the UVC_CTRL_DATA_BACKUP for the other uncommitted entities. Otherwise the control cache and the device would be out of sync. Cc: stable@kernel.org Fixes: b4012002f3a3 ("[media] uvcvideo: Add support for control events") Reported-by: Hans de Goede Closes: https://lore.kernel.org/linux-media/fe845e04-9fde-46ee-9763-a6f00867929a@redhat.com/ Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 9496ac970267..93c355b53101 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1825,11 +1825,14 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, unsigned int processed_ctrls = 0; struct uvc_control *ctrl; unsigned int i; - int ret; + int ret = 0; if (entity == NULL) return 0; + if (err_ctrl) + *err_ctrl = NULL; + for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; if (!ctrl->initialized) @@ -1854,8 +1857,6 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, dev->intfnum, ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), ctrl->info.size); - else - ret = 0; if (!ret) processed_ctrls++; @@ -1868,12 +1869,19 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, ctrl->dirty = 0; if (ret < 0) { - if (err_ctrl) + if (err_ctrl && !*err_ctrl) *err_ctrl = ctrl; - return ret; + /* + * If we fail to set a control, we need to rollback + * the next ones. + */ + rollback = 1; } } + if (ret) + return ret; + return processed_ctrls; } @@ -1904,6 +1912,7 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, struct uvc_video_chain *chain = handle->chain; struct uvc_control *err_ctrl; struct uvc_entity *entity; + int ret_out = 0; int ret = 0; /* Find the control. */ @@ -1915,16 +1924,23 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls, err_ctrl); - goto done; + /* + * When we fail to commit an entity, we need to + * restore the UVC_CTRL_DATA_BACKUP for all the + * controls in the other entities, otherwise our cache + * and the hardware will be out of sync. + */ + rollback = 1; + + ret_out = ret; } else if (ret > 0 && !rollback) { uvc_ctrl_send_events(handle, entity, ctrls->controls, ctrls->count); } } -done: mutex_unlock(&chain->ctrl_mutex); - return ret < 0 ? ret : 0; + return ret_out; } int uvc_ctrl_get(struct uvc_video_chain *chain,