From patchwork Mon Oct 24 11:30:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp476452wru; Mon, 24 Oct 2022 07:13:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UJFgVMFq6SFJAJrvQcajaaJAuGSGVxH3L7szZBBtKq9BHlu4yPYEXwSzpv41nrMjfoEZA X-Received: by 2002:a17:907:9807:b0:797:a5ba:1327 with SMTP id ji7-20020a170907980700b00797a5ba1327mr20338106ejc.274.1666620839190; Mon, 24 Oct 2022 07:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620839; cv=none; d=google.com; s=arc-20160816; b=jGdDXeytsBD9mwLYCCkbtp17wpnZX1SK75bZXJrVVDEuquz5xfdhOkTtjw837R1j7h bOj0rvpP6fhvyDRo1u9e41AbU56ij0bX7C8T3a1JC0n1BqKB0bhCK3xkK17ZZ+NCfWo+ WmMTrWnQvIVdqecJiW1twDEGGfu0g5yhddAKoPQZ00kGb1NkJPLEeGF1Fwt/Gph0fqJq MXMeAdeP4fesvWNMlsdmnCrfptGQKgBotvDigE2hc0BVBQN8shmz732aztfgfXlrLyXI qYuhQ/8NL3O94V9rNrfAxWinOfRedZBqD4WR7yKSEgUFXXy1b7h/d9j+NsYQ2gbM+CKu JuCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Op2YY2Z+ms/64lq/K15ri75SJCq88uQJFi40/pp/beA=; b=dfrLRoait6DFBylAtBO49mNTnQbsPuUWiL8PSibbN+J3gQm9X62uACzwsRvA87NTWr J8mXzupKkq3XKHUm9oWbLsLtOki+hcJ0oj3YCiagP1w8GKeJK9LEg+CBzbjdEAPCkT6A Q8WdrsRXws6u0Wtp8eh9q4BZSUQQNWJWDIhpEhJoTSNC2tn8YP/dsLOJ5e6V8BT6uhG9 FOomX2Fkb+IQY+gjnBqpPfOhOY1URnZhRtXnADsLFe0z0ZXpfS6FO639GS7ZVxKzkyFH q401VKy2JIN/JeySMxRCc0ITsTl1x+Mpvg3uWdMUnUsmi+1pAwoeRxjeMMFis2Pie9qD pqvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I96AqUsh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rs8-20020a170907036800b0078306c5c48asi22447638ejb.250.2022.10.24.07.13.35; Mon, 24 Oct 2022 07:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I96AqUsh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbiJXOB5 (ORCPT + 99 others); Mon, 24 Oct 2022 10:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236845AbiJXOAG (ORCPT ); Mon, 24 Oct 2022 10:00:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9AF08E9BB; Mon, 24 Oct 2022 05:47:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BDF2DB819D0; Mon, 24 Oct 2022 12:45:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20E27C433C1; Mon, 24 Oct 2022 12:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615536; bh=qk1x7FS+7/9XlMI7Pely4OH1lsNVEiXwS1ASEs8Kino=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I96AqUshqSpINYAxpWk+zgOVJP97T0gE2GlIoZNxPSJ73yv8AUWiQnV5AoxZivLkg tAesYV645rIA3KNhe+u5fWsZalG9OtfckHW+V71Yi9TAUvtGL9DiBf4t9Uj3p7EenQ m99FX9kZNyRsDEIvYMxodzjNZuZdvqpJz6AFNHlc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunke Cao , Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.15 288/530] media: uvcvideo: Use entity get_cur in uvc_ctrl_set Date: Mon, 24 Oct 2022 13:30:32 +0200 Message-Id: <20221024113058.096628238@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747578612840752098?= X-GMAIL-MSGID: =?utf-8?q?1747578612840752098?= From: Yunke Cao [ Upstream commit 5f36851c36b30f713f588ed2b60aa7b4512e2c76 ] Entity controls should get_cur using an entity-defined function instead of via a query. Fix this in uvc_ctrl_set. Fixes: 65900c581d01 ("media: uvcvideo: Allow entity-defined get_info and get_cur") Signed-off-by: Yunke Cao Reviewed-by: Ricardo Ribalda Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_ctrl.c | 83 ++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b3dde98499f4..5bb29fc49538 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -988,36 +988,56 @@ static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, return value; } -static int __uvc_ctrl_get(struct uvc_video_chain *chain, - struct uvc_control *ctrl, struct uvc_control_mapping *mapping, - s32 *value) +static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain, + struct uvc_control *ctrl) { + u8 *data; int ret; - if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) - return -EACCES; + if (ctrl->loaded) + return 0; - if (!ctrl->loaded) { - if (ctrl->entity->get_cur) { - ret = ctrl->entity->get_cur(chain->dev, - ctrl->entity, - ctrl->info.selector, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info.size); - } else { - ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, - ctrl->entity->id, - chain->dev->intfnum, - ctrl->info.selector, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info.size); - } - if (ret < 0) - return ret; + data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT); + if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) { + memset(data, 0, ctrl->info.size); ctrl->loaded = 1; + + return 0; } + if (ctrl->entity->get_cur) + ret = ctrl->entity->get_cur(chain->dev, ctrl->entity, + ctrl->info.selector, data, + ctrl->info.size); + else + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, + ctrl->entity->id, chain->dev->intfnum, + ctrl->info.selector, data, + ctrl->info.size); + + if (ret < 0) + return ret; + + ctrl->loaded = 1; + + return ret; +} + +static int __uvc_ctrl_get(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + s32 *value) +{ + int ret; + + if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) + return -EACCES; + + ret = __uvc_ctrl_load_cur(chain, ctrl); + if (ret < 0) + return ret; + *value = __uvc_ctrl_get_value(mapping, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); @@ -1667,21 +1687,10 @@ int uvc_ctrl_set(struct uvc_fh *handle, * needs to be loaded from the device to perform the read-modify-write * operation. */ - if (!ctrl->loaded && (ctrl->info.size * 8) != mapping->size) { - if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) { - memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - 0, ctrl->info.size); - } else { - ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, - ctrl->entity->id, chain->dev->intfnum, - ctrl->info.selector, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info.size); - if (ret < 0) - return ret; - } - - ctrl->loaded = 1; + if ((ctrl->info.size * 8) != mapping->size) { + ret = __uvc_ctrl_load_cur(chain, ctrl); + if (ret < 0) + return ret; } /* Backup the current value in case we need to rollback later. */