Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp12422lqp; Mon, 10 Jun 2024 16:11:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXS5ozWIjjIcOKG4s2vHST0QfCpfnvl2aqt6tck+JMa3byeT0w4iMwtRVW0SllqZ0ynBfqb2jgJJNyOnWoUUyB/mjmVfugNOf9eg6wBCA== X-Google-Smtp-Source: AGHT+IGSQ3eDatalTiotqivThTCUBqaP0o7YKM8GEIOU/VqumYgy/7D9x+MLuBxCqCR33QHGITaJ X-Received: by 2002:a17:906:68c5:b0:a6f:2d5c:5c8d with SMTP id a640c23a62f3a-a6f2d5c6342mr148544766b.30.1718061119102; Mon, 10 Jun 2024 16:11:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718061119; cv=pass; d=google.com; s=arc-20160816; b=gdtbQWfAoTcsoGdIl7g2pb5kncKEYlYx/pofrRjBCJKnX93asM6OYVFIKMARu2/mUW HuJI4bZuEtg+H0k7VRfRC3aDhatyJy3JS9krj3q/vIJ1ySsPUFrIrm9nBTvQiqt8/pYB JTyX6JYBI9BGGUCz7zm87lzHmD9Y/vf25tuW7hE/lkI8NMTTAYvYVwcMe388S2gVhozn grRVoUXFTa2KaIfXRDNsLt4soMt2JHcfPnWmZ/uYLv22OAHgyRWOYR6OhprqzBcN6w9W dNF0gTQPkWsuJdRtRexNzJjrPjC6RqL9ywMyDx7KFim4RYnasbTSkdwwxNlgbNSWEk70 YSoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=BOfU1pocYD2Scfhf5kButvETql9ENuAv9ka+WIo4LyM=; fh=TyCwPRcjm+ljVJIuY6QqO0aKPqXl9ruKaOJgJw24Hfw=; b=Bre762D7L5Cikem/09a5W4/rVpRJvC/wusw46wImbh0v3gREMLqQpPjdO+dBXKLyGk NOa9n7vvDrlWfVG0H+EPrAP+mIybSxvbfIGfEAXKgZfiKTHY7AhnKO5NK1lznY4duCI1 w0TCu2kxJtwLpC3EnnG3giDyiFQO9Q0KbPt3P5cQsSANof2ehyOwf2j8nISNTCk3YiIR nebRsVU5WQkKfxAEhN2iHKjdGJOXhktba72ZuaImrxxrg3zOCMY+3OKeJFqpoRFO0ama nf6BzRR17K/BQ8nqU8eN8d+aqOydQP1kWy71o4lAG03KJ78QzIWV+A00pDQr1+oaa4da 5xrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M7dQmIL4; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-209045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209045-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6ef8d6f7d4si312526566b.91.2024.06.10.16.11.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 16:11:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M7dQmIL4; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-209045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209045-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9CAE71F231AF for ; Mon, 10 Jun 2024 23:11:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D1291553B9; Mon, 10 Jun 2024 23:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="M7dQmIL4" Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 C09B71552ED for ; Mon, 10 Jun 2024 23:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718061005; cv=none; b=g9ADe7c5X705z6guvx1z5HATRT1geEmj2G89il4aCYCFy2fzIb2HplcqmeLyeGh5qmIW0WdRTpHHNVBv0vE85TomB+DlsxBhdamBm1eHZaSSQcpf07Vi4COmTnlW+EzsAz2JI3YgG9ga3inhp059yAfhZeA7dsXgrpJijxn4seE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718061005; c=relaxed/simple; bh=3YQ1MREPZcXZY8Rzdf2ucSaUl0qgCLccvMpvwcUdRxw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=USlT3NjOg2QCN6neKDc9CUXTK62dDtrdI7sz9murW7byG0+sspuL+gr+ixVBVWMN2Uumww11kOel5owxB/YqOav1B9aBQGD70oK4q7uhKn4+yYILhj8LjP2dzAEqfejipk2pZphLp5l3h24FN5QbDAOnUpPhS4/7RzgRyggjpq0= 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=M7dQmIL4; arc=none smtp.client-ip=209.85.161.41 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 Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5b9776123a3so2534303eaf.0 for ; Mon, 10 Jun 2024 16:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718061003; x=1718665803; 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=BOfU1pocYD2Scfhf5kButvETql9ENuAv9ka+WIo4LyM=; b=M7dQmIL40ddmTKpyo9O1PINEm/XLjvqsWwa6sqa437yr1uDbzKH0502VeC1sBoKrrC 45soHcL4ZS7jAi+ZYxxejaRiFsHMBAhCPVRTBOdqrlIBOFFpg2X2rsKckfmXNlcsmSHz sUq6qvMSu9DDYg2EIfg+MNmJb1qRV7ciX1Ce0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718061003; x=1718665803; 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=BOfU1pocYD2Scfhf5kButvETql9ENuAv9ka+WIo4LyM=; b=fh4Tu9/Dn2w24gUdc/b8X6pA7hQNznibWdcZ6/p8Y3L+5RpQLGccTrjsBQPoSTo76P DHUmjKF6GzO9E27JdSYI40KaIwfrT2FkGYkgTuStL6stM44sX86Gyvq8ZaFqd07c4t0x n70cX7wAdi3nt76roLFPUokgWC8BoxWcdmuBpmPcLW1kFcBGwKxI2vuiof5s5VBaVkYG TZdE1ADbQTOmJNJMA03dCm5s6prs6aTz8FYoK/zKhfUjyb839+nly1HMRq7GcZDoAoe6 gRiKzwAFWBmhUYPCdsspT/RPbQ7/tl0p5xQNv6aKU6Yym4g+waDP7qnoNUJ3ShmmCn8v Mhlw== X-Forwarded-Encrypted: i=1; AJvYcCXO8cv0mOKITlkSU7SNAd+yFU7QcfYKnBijCRkAeTw+ddXdz6voeciWi1JPvihj9Oscgv9O5MRaFTo1Id+WauRtKrgDy33us+IrW0Ct X-Gm-Message-State: AOJu0YwyccPwfbyBRIj0PlEq032UB8Gtdnhnh54cmhI0R3MeHxOadatR 3d7XT+NK1fkcPSirLMnvxjYsMl0/FgVDlx/ZnCT3674TMbkrGrukfXADrCIy3g== X-Received: by 2002:a05:6358:57a3:b0:19f:4553:5514 with SMTP id e5c5f4694b2df-19f45535aadmr801047355d.29.1718061002738; Mon, 10 Jun 2024 16:10:02 -0700 (PDT) Received: from denia.c.googlers.com (123.178.145.34.bc.googleusercontent.com. [34.145.178.123]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b06519d521sm35256946d6.65.2024.06.10.16.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 16:10:01 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 10 Jun 2024 23:09:58 +0000 Subject: [PATCH v2 7/7] media: uvcvideo: Replace get_mapping with filter_mapping 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: 7bit Message-Id: <20240610-billion-v2-7-38e861475f85@chromium.org> References: <20240610-billion-v2-0-38e861475f85@chromium.org> In-Reply-To: <20240610-billion-v2-0-38e861475f85@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.12.4 If the callback returns a mapping instead of adding it, the codeflow is more clean and we do not need a forward declaration of __uvc_ctrl_add_mapping_to_list(). Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 40 ++++++++++++++++++---------------------- drivers/media/usb/uvc/uvcvideo.h | 6 +++--- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 1c1710e3c486..4a13f2685d9e 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -495,11 +495,8 @@ static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }; -static int __uvc_ctrl_add_mapping_to_list(struct uvc_video_chain *chain, - struct uvc_control *ctrl, const struct uvc_control_mapping *mapping); - -static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, - struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) +static const struct uvc_control_mapping *uvc_ctrl_filter_plf_mapping + (struct uvc_video_chain *chain, struct uvc_control *ctrl) { const struct uvc_control_mapping *out_mapping = &uvc_ctrl_power_line_mapping_uvc11; @@ -509,7 +506,7 @@ static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, buf = kmalloc(sizeof(*buf), GFP_KERNEL); if (!buf) - return -ENOMEM; + return NULL; /* Save the default PLF value, so we can restore it. */ ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, @@ -517,7 +514,7 @@ static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, buf, sizeof(*buf)); /* If we cannot read the control skip it. */ if (ret) - return ret; + return NULL; init_val = *buf; /* If PLF value cannot be set to off, it is limited. */ @@ -526,8 +523,7 @@ static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, chain->dev->intfnum, ctrl->info.selector, buf, sizeof(*buf)); if (ret) - return __uvc_ctrl_add_mapping_to_list(chain, ctrl, - &uvc_ctrl_power_line_mapping_limited); + return &uvc_ctrl_power_line_mapping_limited; /* UVC 1.1 does not define auto, we can exit. */ if (chain->dev->uvc_version < 0x150) @@ -548,7 +544,7 @@ static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, chain->dev->intfnum, ctrl->info.selector, buf, sizeof(*buf)); - return __uvc_ctrl_add_mapping_to_list(chain, ctrl, out_mapping); + return out_mapping; } static const struct uvc_control_mapping uvc_ctrl_mappings[] = { @@ -843,7 +839,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { { .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, - .add_mapping = uvc_ctrl_add_plf_mapping, + .filter_mapping = uvc_ctrl_filter_plf_mapping, }, }; @@ -2411,8 +2407,9 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, /* * Add a control mapping to a given control. */ -static int __uvc_ctrl_add_mapping_to_list(struct uvc_video_chain *chain, - struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) +static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + const struct uvc_control_mapping *mapping) { struct uvc_control_mapping *map; unsigned int size; @@ -2485,14 +2482,6 @@ static int __uvc_ctrl_add_mapping_to_list(struct uvc_video_chain *chain, return -ENOMEM; } -static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, - struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) -{ - if (mapping && mapping->add_mapping) - return mapping->add_mapping(chain, ctrl, mapping); - return __uvc_ctrl_add_mapping_to_list(chain, ctrl, mapping); -} - int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, const struct uvc_control_mapping *mapping) { @@ -2681,7 +2670,14 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, /* Process common mappings. */ for (i = 0; i < ARRAY_SIZE(uvc_ctrl_mappings); ++i) { - const struct uvc_control_mapping *mapping = &uvc_ctrl_mappings[i]; + const struct uvc_control_mapping *mapping = NULL; + + /* Try to get a custom mapping from the device. */ + if (uvc_ctrl_mappings[i].filter_mapping) + mapping = uvc_ctrl_mappings[i].filter_mapping(chain, + ctrl); + if (!mapping) + mapping = &uvc_ctrl_mappings[i]; if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index ff9545dcf716..a9547795fe22 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -125,9 +125,9 @@ struct uvc_control_mapping { s32 master_manual; u32 slave_ids[2]; - int (*add_mapping)(struct uvc_video_chain *chain, - struct uvc_control *ctrl, - const struct uvc_control_mapping *mapping); + const struct uvc_control_mapping *(*filter_mapping) + (struct uvc_video_chain *chain, + struct uvc_control *ctrl); s32 (*get)(struct uvc_control_mapping *mapping, u8 query, const u8 *data); void (*set)(struct uvc_control_mapping *mapping, s32 value, -- 2.45.2.505.gda0bf45e8d-goog